Skip to content
Myr

draft-steps.ts

This file

Path

apps/platform/src/workflows/draft-steps.ts

53 lines · 2.1 KiB · TypeScript

Last changed by

Close the code browser and drafting wave: its decisions in two ADRs, every rule it added held, and its leftovers folded inoscabrielbefore adoption009640c

History of this file

Take it

Merge branch 'build/910-draft-workflow'oscabrielbefore adoptiona0c8f4f

lines 1–2why, one step back
1/**
2 * One round of a proposal's draft, as steps of the `Answer` Workflow

Close the code browser and drafting wave: its decisions in two ADRs, every rule it added held, and its leftovers folded inoscabrielbefore adoption009640c

line 3why, one step back
3 * (ADR 0018): the program is `@repo/drafting/run`'s `runDraft`, shared with

Merge branch 'build/910-draft-workflow'oscabrielbefore adoptiona0c8f4f

lines 4–53why, one step back
4 * the in-process run, over the Workflow's `StepRunner`. Its steps are
5 * `context`, then `draft-<n>` and `rehearse-<n>` per attempt, then6 * `settle`, inside the instance `draft-<project>-<proposal>-r<round>`.7 *8 * The engine is handed a timeout with each of the run's steps9 * (`timedSteps`): a model call or a rehearsal on a cold Checker takes10 * minutes, and the other two steps are one Durable Object call each, well11 * inside the same bound.12 */13import type { RepoHost } from "@repo/artifacts/repo-host";14import type { Drafter } from "@repo/drafting/drafter";15import { runDraft } from "@repo/drafting/run";16import type { Projects } from "@repo/project/projects";17import type { WorkflowTimeoutDuration } from "cloudflare:workers";18import type { Effect, Schema } from "effect";1920import type { DraftParams } from "../answer-runs.ts";21import { StepRunner } from "./step.ts";22import type { WorkflowStepRetries, WorkflowSteps } from "./step.ts";2324/** How long one step of a draft's run may take before the engine fails it. */25export const DRAFT_STEP_TIMEOUT = "10 minutes";2627/**28 * The part of a Workflow's `WorkflowStep` a draft's run uses: `do`, with29 * retries and a timeout. A `WorkflowStep` is one, and so is anything that30 * takes `WorkflowSteps`' narrower config.31 */32export interface EngineSteps {33 readonly do: (34 name: string,35 config: {36 readonly retries?: WorkflowStepRetries;37 readonly timeout?: WorkflowTimeoutDuration;38 },39 body: () => Promise<Schema.Json>40 ) => Promise<Schema.Json>;41}4243/** The engine's steps, each handed the draft step timeout. */44export const timedSteps = (engine: EngineSteps): WorkflowSteps => ({45 do: (name, config, body) =>46 engine.do(name, { ...config, timeout: DRAFT_STEP_TIMEOUT }, body),47});4849/** One round of a draft, carried from its context to its settling. */50export const draftSteps = (51 params: DraftParams52): Effect.Effect<void, never, StepRunner | Projects | Drafter | RepoHost> =>53 StepRunner.use((runner) => runDraft(params, { step: runner.step }));