@agent-compose/sdk 0.7.0 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +66 -39
- package/dist/agent/__tests__/runtime-json-schema.test.d.ts +10 -0
- package/dist/agent/agent-context.d.ts +21 -1
- package/dist/agent/agent-loop.d.ts +32 -1
- package/dist/agent/run-agent.d.ts +4 -0
- package/dist/client.d.ts +382 -534
- package/dist/directives.d.ts +112 -0
- package/dist/display.d.ts +258 -0
- package/dist/errors.d.ts +24 -1
- package/dist/index.d.ts +26 -14
- package/dist/index.js +3774 -1679
- package/dist/pause/wrappers.d.ts +31 -9
- package/dist/runtimes/_acp-client.d.ts +46 -1
- package/dist/runtimes/_cli-agent.d.ts +51 -4
- package/dist/runtimes/_jsonl-guard.d.ts +103 -0
- package/dist/runtimes/amp.d.ts +2 -2
- package/dist/runtimes/claude-code.d.ts +61 -0
- package/dist/runtimes/claude-code.test.d.ts +14 -0
- package/dist/runtimes/claude.d.ts +16 -0
- package/dist/runtimes/claude.test.d.ts +8 -0
- package/dist/runtimes/codex.d.ts +12 -3
- package/dist/runtimes/cursor.d.ts +2 -2
- package/dist/runtimes/droid.d.ts +2 -2
- package/dist/runtimes/jsonl-guard.test.d.ts +19 -0
- package/dist/runtimes/openai-desktop.js +3718 -1680
- package/dist/runtimes/opencode.d.ts +2 -2
- package/dist/runtimes/vercel.js +12 -1
- package/dist/sandbox/devbox.d.ts +42 -0
- package/dist/sandbox/exec-stream.d.ts +14 -0
- package/dist/sandbox/network-policy.d.ts +100 -0
- package/dist/sandbox/provider-def.d.ts +79 -0
- package/dist/sandbox/providers/desktop.d.ts +10 -0
- package/dist/sandbox/providers/e2b.d.ts +17 -0
- package/dist/sandbox/providers/local.d.ts +11 -0
- package/dist/sandbox/providers/vercel.d.ts +18 -0
- package/dist/sandbox/registry.d.ts +45 -0
- package/dist/sandbox/sizes.d.ts +68 -0
- package/dist/sandbox.d.ts +24 -299
- package/dist/step-invocation/__tests__/foreground-recovery.test.d.ts +1 -0
- package/dist/step-invocation/invoker.d.ts +10 -0
- package/dist/step-invocation/protocol.d.ts +5 -0
- package/dist/types/api-compliance.d.ts +71 -0
- package/dist/types/api-conversations.d.ts +523 -0
- package/dist/types/api-factory.d.ts +334 -0
- package/dist/types/api-projects.d.ts +131 -0
- package/dist/types/api-runs.d.ts +422 -0
- package/dist/types/api-scopes.d.ts +102 -0
- package/dist/types/conversation-stream.d.ts +191 -0
- package/dist/types/execution-context.d.ts +12 -2
- package/dist/types/protocol.d.ts +38 -1
- package/dist/types/sandbox-environment.d.ts +8 -5
- package/dist/types/sandbox.d.ts +74 -4
- package/dist/types/workflow-metadata.d.ts +41 -8
- package/dist/types/workflow-plan.d.ts +10 -0
- package/dist/types/workflow.d.ts +18 -205
- package/dist/utils/bundler.d.ts +68 -1
- package/dist/workflow-steps/index.d.ts +1 -1
- package/dist/workflow-steps/observability.d.ts +8 -1
- package/dist/workflow-steps/runner.d.ts +3 -3
- package/dist/workflow-steps/step.d.ts +15 -1
- package/dist/workflow-steps/types.d.ts +19 -5
- package/dist/workflow-steps/workflow.d.ts +29 -1
- package/dist/workflows/engine.d.ts +3 -2
- package/dist/workflows/invoke-child.d.ts +20 -2
- package/dist/workflows/invoke-child.test.d.ts +9 -0
- package/package.json +2 -2
- package/src/agent/agent-context.ts +186 -3
- package/src/agent/agent-loop.ts +40 -2
- package/src/agent/run-agent.ts +5 -0
- package/src/client.ts +1048 -625
- package/src/directives.ts +184 -0
- package/src/display.ts +834 -0
- package/src/errors.ts +39 -0
- package/src/index.ts +114 -12
- package/src/pause/wrappers.ts +44 -9
- package/src/runtimes/_acp-client.ts +72 -3
- package/src/runtimes/_cli-agent.ts +161 -36
- package/src/runtimes/_jsonl-guard.ts +219 -0
- package/src/runtimes/claude-code.ts +256 -0
- package/src/runtimes/claude.ts +32 -2
- package/src/runtimes/codex.ts +63 -3
- package/src/runtimes/openai-desktop.ts +59 -14
- package/src/sandbox/devbox.ts +48 -0
- package/src/sandbox/exec-stream.ts +48 -0
- package/src/sandbox/network-policy.ts +181 -0
- package/src/sandbox/provider-def.ts +94 -0
- package/src/sandbox/providers/desktop.ts +57 -0
- package/src/sandbox/providers/e2b.ts +354 -0
- package/src/sandbox/providers/local.ts +106 -0
- package/src/sandbox/providers/vercel.ts +331 -0
- package/src/sandbox/registry.ts +198 -0
- package/src/sandbox/sizes.ts +95 -0
- package/src/sandbox.ts +59 -1275
- package/src/step-invocation/invoker.ts +151 -28
- package/src/step-invocation/protocol.ts +8 -0
- package/src/types/api-compliance.ts +79 -0
- package/src/types/api-conversations.ts +547 -0
- package/src/types/api-factory.ts +368 -0
- package/src/types/api-projects.ts +140 -0
- package/src/types/api-runs.ts +459 -0
- package/src/types/api-scopes.ts +102 -0
- package/src/types/conversation-stream.ts +231 -0
- package/src/types/execution-context.ts +10 -2
- package/src/types/protocol.ts +41 -0
- package/src/types/sandbox-environment.ts +28 -9
- package/src/types/sandbox.ts +73 -4
- package/src/types/workflow-metadata.ts +44 -8
- package/src/types/workflow-plan.ts +11 -0
- package/src/types/workflow.ts +25 -292
- package/src/utils/bundler.ts +245 -8
- package/src/utils/errors.ts +16 -1
- package/src/workflow-steps/index.ts +1 -0
- package/src/workflow-steps/observability.ts +19 -8
- package/src/workflow-steps/runner.ts +4 -4
- package/src/workflow-steps/step.ts +49 -1
- package/src/workflow-steps/types.ts +20 -5
- package/src/workflow-steps/workflow.ts +29 -1
- package/src/workflows/engine.ts +3 -2
- package/src/workflows/invoke-child.ts +49 -13
package/src/types/workflow.ts
CHANGED
|
@@ -1,45 +1,33 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Workflow types —
|
|
2
|
+
* Workflow authoring types — `defineWorkflow` and the shared author-facing
|
|
3
|
+
* type surface.
|
|
3
4
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* and to any helper that takes a SandboxProvider (git utilities, file
|
|
11
|
-
* writers). Constructed once per run; reuse it.
|
|
5
|
+
* Workflows are STEP-FORM only: a builder of discrete, durable steps —
|
|
6
|
+
* `defineWorkflow({ id, input, output }).step(defineStep(...)).build()`.
|
|
7
|
+
* Every step is a replay checkpoint; pause/resume works at step
|
|
8
|
+
* granularity. The legacy run-form (`defineWorkflow({ run(ctx, sandbox)
|
|
9
|
+
* { … } })`) has been removed — passing a `run` key throws at
|
|
10
|
+
* definition time (i.e. at registration, loud and early).
|
|
12
11
|
*
|
|
13
12
|
* LLM agent loops live in `agent(opts)` (sdk/src/agent/run-agent.ts).
|
|
14
13
|
* Invoking other workflows uses `AgentComposeClient.invoke[AndWait](...)`.
|
|
15
14
|
*/
|
|
16
15
|
|
|
17
|
-
import { z } from "zod";
|
|
18
|
-
import type { SandboxNetworkPolicy } from "../sandbox.js";
|
|
19
|
-
import type { SandboxProvider } from "./sandbox.js";
|
|
20
16
|
import type { AgentLifecycleEvent } from "../agent/agent-loop.js";
|
|
21
|
-
import type { Processor } from "../processors/processor.js";
|
|
22
17
|
import { createStepWorkflow } from "../workflow-steps/workflow.js";
|
|
23
|
-
import type { StepWorkflowDefinition } from "../workflow-steps/workflow.js";
|
|
24
|
-
import type { Step, Workflow } from "../workflow-steps/types.js";
|
|
25
|
-
import { WORKFLOW_BRAND } from "../workflow-steps/types.js";
|
|
26
|
-
import type { BaseExecutionContext, WorkflowRun } from "./execution-context.js";
|
|
27
|
-
import { extractMetadata, type WorkflowMetadata, type ConnectorRequirements, type ConnectorOperationTag, type InvokePolicy } from "./workflow-metadata.js";
|
|
18
|
+
import type { StepWorkflowDefinition, WorkflowBuilder } from "../workflow-steps/workflow.js";
|
|
28
19
|
|
|
29
20
|
export type { WorkflowRun, InvokeChild, BaseExecutionContext } from "./execution-context.js";
|
|
30
21
|
// Re-export so consumers can keep importing `WorkflowMetadata` from
|
|
31
22
|
// `@agent-compose/sdk` — the canonical definition lives in
|
|
32
23
|
// `./workflow-metadata.js` to break a runtime import cycle with
|
|
33
24
|
// `workflow-steps/workflow.ts`.
|
|
34
|
-
export type { WorkflowMetadata } from "./workflow-metadata.js";
|
|
25
|
+
export type { WorkflowMetadata, SnapshotConfig, BootSnapshot, ReuseSnapshot, IOSchema, OutputSchema, SandboxResources } from "./workflow-metadata.js";
|
|
35
26
|
|
|
36
27
|
export interface AgentEventSink {
|
|
37
28
|
emit(event: AgentLifecycleEvent): void | Promise<void>;
|
|
38
29
|
}
|
|
39
30
|
|
|
40
|
-
import type { SnapshotConfig, BootSnapshot, ReuseSnapshot, IOSchema, OutputSchema, SandboxResources } from "./workflow-metadata.js";
|
|
41
|
-
export type { SnapshotConfig, BootSnapshot, ReuseSnapshot, IOSchema, OutputSchema, SandboxResources };
|
|
42
|
-
|
|
43
31
|
/** Turn/iteration budget for `agent(opts)`. Re-exported here so authors
|
|
44
32
|
* can type per-invoke budget overrides they pass as workflow input. */
|
|
45
33
|
export interface AgentBudget {
|
|
@@ -47,282 +35,27 @@ export interface AgentBudget {
|
|
|
47
35
|
maxIterations: number;
|
|
48
36
|
}
|
|
49
37
|
|
|
50
|
-
/** Context passed to a workflow function — facts + observability for this run. */
|
|
51
|
-
export interface WorkflowCtx<TInput extends Record<string, unknown> = Record<string, unknown>> extends Omit<BaseExecutionContext, "sandbox"> {
|
|
52
|
-
input?: TInput;
|
|
53
|
-
/** Persist key-value metadata on the run record (e.g. prUrl, planUrl). */
|
|
54
|
-
setMetadata: (data: Record<string, unknown>) => Promise<void>;
|
|
55
|
-
/**
|
|
56
|
-
* Durable named step (ADR-0012). Runs `fn` once and memoises its result to
|
|
57
|
-
* the sandbox state-dir; on a pause-resume re-entry the recorded value is
|
|
58
|
-
* returned and `fn` is NOT re-run (a duration-0 "restored" sub-step). Also
|
|
59
|
-
* emits substep_started / substep_completed / substep_failed lifecycle
|
|
60
|
-
* events with duration — use for long phases you want both durable and
|
|
61
|
-
* visible on the run's timeline (setup, external API calls, submit).
|
|
62
|
-
*
|
|
63
|
-
* Names must be unique within a step body (they key the memoise file).
|
|
64
|
-
* A body that pauses is never memoised — the resume re-runs it. For
|
|
65
|
-
* cross-process side effects (DB writes, emails) use `invokeChild`.
|
|
66
|
-
*/
|
|
67
|
-
step<T>(name: string, fn: () => Promise<T>): Promise<T>;
|
|
68
|
-
/** Pass to `agent({ events: ctx.agentEvents })` to stream agent lifecycle events. */
|
|
69
|
-
agentEvents: AgentEventSink;
|
|
70
|
-
/**
|
|
71
|
-
* Workflow-level processors registered via `defineWorkflow({ processors })`.
|
|
72
|
-
* Read-only here. Authors merge with agent-specific lists when calling
|
|
73
|
-
* `agent({ processors: [...ctx.processors, mySpecific] })`.
|
|
74
|
-
*
|
|
75
|
-
* Empty array when the workflow declared no processors.
|
|
76
|
-
*/
|
|
77
|
-
processors: readonly Processor[];
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/** A workflow is `async (ctx, sandbox) => TOutput`. */
|
|
81
|
-
export type WorkflowFn<
|
|
82
|
-
TOutput = unknown,
|
|
83
|
-
TInput extends Record<string, unknown> = Record<string, unknown>,
|
|
84
|
-
> = (ctx: WorkflowCtx<TInput>, sandbox: SandboxProvider) => Promise<TOutput>;
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Declare a workflow with server-side metadata.
|
|
88
|
-
* Use `export default defineWorkflow({ run, networkPolicy, ... })` to attach
|
|
89
|
-
* a runner network policy so the server brokers credentials for the workflow
|
|
90
|
-
* sandbox.
|
|
91
|
-
*
|
|
92
|
-
* Without defineWorkflow, a plain `export default async (ctx) => {...}` still
|
|
93
|
-
* works — the workflow just runs with secrets passed directly in env.
|
|
94
|
-
*/
|
|
95
|
-
export interface WorkflowDefinition<
|
|
96
|
-
TOutput = unknown,
|
|
97
|
-
TInput extends Record<string, unknown> = Record<string, unknown>,
|
|
98
|
-
> {
|
|
99
|
-
/** One-line, human-readable description of what this workflow does.
|
|
100
|
-
* Surfaced on the dashboard template tile + run page header. */
|
|
101
|
-
description?: string;
|
|
102
|
-
/** Zod schema for the workflow's `input`. When declared, the SDK
|
|
103
|
-
* bundler captures it as JSON-Schema-shaped `inputSchema` in
|
|
104
|
-
* template metadata, the dashboard playground renders a typed
|
|
105
|
-
* form, and the engine validates dispatched payloads against it
|
|
106
|
-
* at the step boundary. Omit to leave inputs as `unknown` (the
|
|
107
|
-
* legacy default — playground falls back to a freeform JSON
|
|
108
|
-
* textarea). */
|
|
109
|
-
input?: z.ZodType<TInput>;
|
|
110
|
-
/** Same as `input`, for the workflow's return value. Captured into
|
|
111
|
-
* `outputSchema` metadata and rendered in the IO panel. */
|
|
112
|
-
output?: z.ZodType<TOutput>;
|
|
113
|
-
/**
|
|
114
|
-
* @deprecated Legacy run-form. Prefer step-form — the
|
|
115
|
-
* `.step(defineStep(...))` builder — for per-step durability/replay and
|
|
116
|
-
* working pause. A run-form body compiles to one opaque step
|
|
117
|
-
* (`compileRunForm`), so any failure/resume re-runs the whole body.
|
|
118
|
-
*/
|
|
119
|
-
run: WorkflowFn<TOutput, TInput>;
|
|
120
|
-
/**
|
|
121
|
-
* All snapshot config — boot source plus capture mode.
|
|
122
|
-
*
|
|
123
|
-
* `snapshots.bootFrom`: the runner restores from this exact provider
|
|
124
|
-
* snapshot id at run start. Omit to boot a fresh sandbox.
|
|
125
|
-
*
|
|
126
|
-
* `snapshots.saveLatest`: `true` captures one snapshot after each
|
|
127
|
-
* successful step (latest-only — prior is freed).
|
|
128
|
-
* `{ saveLatest: true, retainSteps: true }` keeps every step's
|
|
129
|
-
* snapshot for fork / replay / time-travel.
|
|
130
|
-
*
|
|
131
|
-
* Snapshots are long-lived (never auto-expire). List + delete via
|
|
132
|
-
* `agentc snapshot list/delete`. Per-invocation
|
|
133
|
-
* `invoke({ snapshots })` overrides this default.
|
|
134
|
-
*/
|
|
135
|
-
snapshots?: SnapshotConfig;
|
|
136
|
-
/**
|
|
137
|
-
* Sandbox resources — machine SKU (`size`, a `SandboxSize` vCPU string:
|
|
138
|
-
* `2vcpu-4gb` | `4vcpu-8gb` | `8vcpu-16gb` | `32vcpu-64gb`) and `provider`
|
|
139
|
-
* (`vercel` | `e2b`). `size` maps to provider machine specs at create
|
|
140
|
-
* (Vercel: vCPUs, 2048 MB RAM per vCPU); E2B sizing is template-defined and
|
|
141
|
-
* ignores it. Optional; omit → smallest SKU on the default provider.
|
|
142
|
-
* Per-invocation `invoke({ size })` overrides the size.
|
|
143
|
-
*/
|
|
144
|
-
resources?: SandboxResources;
|
|
145
|
-
/**
|
|
146
|
-
* Outbound network policy for the runner sandbox.
|
|
147
|
-
* Use "*": [] to allow all traffic while still injecting headers for specific domains.
|
|
148
|
-
* Secret values are referenced as $VARIABLE and resolved from GCP at dispatch time.
|
|
149
|
-
* Vercel only — E2B ignores.
|
|
150
|
-
*
|
|
151
|
-
* @example
|
|
152
|
-
* networkPolicy: {
|
|
153
|
-
* allow: {
|
|
154
|
-
* "*": [],
|
|
155
|
-
* "api.github.com": [{ transform: [{ headers: { "Authorization": "basic:$GITHUB_TOKEN" } }] }],
|
|
156
|
-
* }
|
|
157
|
-
* }
|
|
158
|
-
*/
|
|
159
|
-
networkPolicy?: SandboxNetworkPolicy;
|
|
160
|
-
/**
|
|
161
|
-
* Workflow-level processor chain — runs around every `agent(...)` loop the
|
|
162
|
-
* workflow body launches, ahead of any agent-specific processors. Use for
|
|
163
|
-
* org-wide gating (deny destructive tools, require scopes). Authors merge
|
|
164
|
-
* with agent-specific lists via `[...ctx.processors, ...]`.
|
|
165
|
-
*/
|
|
166
|
-
processors?: readonly Processor[];
|
|
167
|
-
/**
|
|
168
|
-
* Optional placeholder env var values for secrets referenced in the network policy.
|
|
169
|
-
* By default, brokered secrets are removed from the runner env entirely — the real
|
|
170
|
-
* values are only ever present inside the Vercel firewall config, never in the VM.
|
|
171
|
-
* Only set this if a tool or SDK validates the env var format on startup before
|
|
172
|
-
* making any requests (e.g. some CLIs check that ANTHROPIC_API_KEY looks like a
|
|
173
|
-
* real key). The placeholder is a syntactically valid but non-functional stand-in.
|
|
174
|
-
*
|
|
175
|
-
* @example
|
|
176
|
-
* placeholders: {
|
|
177
|
-
* ANTHROPIC_API_KEY: `sk-ant-api03-${"a".repeat(95)}`,
|
|
178
|
-
* }
|
|
179
|
-
*/
|
|
180
|
-
placeholders?: Record<string, string>;
|
|
181
|
-
/**
|
|
182
|
-
* Connector requirements (ADR-0007). Declaring a provider makes the
|
|
183
|
-
* server resolve an authorized OAuth grant for the calling principal at
|
|
184
|
-
* dispatch time and inject a fresh access token at the network layer —
|
|
185
|
-
* workflow code talks to the provider API with plain fetch/SDKs and
|
|
186
|
-
* never holds the credential.
|
|
187
|
-
*
|
|
188
|
-
* @example
|
|
189
|
-
* connectors: { github: { scopes: ["repo"] } }
|
|
190
|
-
*/
|
|
191
|
-
connectors?: ConnectorRequirements;
|
|
192
|
-
/**
|
|
193
|
-
* Marks this workflow as a catalogue OPERATION of a connector — e.g.
|
|
194
|
-
* the `create-issue` operation of the `github` connector. Pair with
|
|
195
|
-
* `description` + `input`/`output` schemas so the operation is fully
|
|
196
|
-
* self-describing (MCP-tool-like) to humans and agents browsing the
|
|
197
|
-
* connector catalogue.
|
|
198
|
-
*
|
|
199
|
-
* @example
|
|
200
|
-
* connectorOperation: { provider: "github", operation: "create-issue" }
|
|
201
|
-
*/
|
|
202
|
-
connectorOperation?: ConnectorOperationTag;
|
|
203
|
-
/**
|
|
204
|
-
* Tier-1 invoke ACL (connector credential boundary). When this workflow
|
|
205
|
-
* declares `connectors` (it brokers a credential) AND an `invokePolicy`,
|
|
206
|
-
* the server evaluates the calling principal against the policy BEFORE
|
|
207
|
-
* binding any grant — a caller matching no clause is refused with HTTP
|
|
208
|
-
* 403. Has no effect on workflows that declare no connectors. Omit to
|
|
209
|
-
* leave the workflow invokable by the whole team.
|
|
210
|
-
*
|
|
211
|
-
* @example
|
|
212
|
-
* connectors: { github: { access: "read" } },
|
|
213
|
-
* invokePolicy: { users: "owner", workflows: ["nightly-orchestrator"] }
|
|
214
|
-
*/
|
|
215
|
-
invokePolicy?: InvokePolicy;
|
|
216
|
-
/**
|
|
217
|
-
* Internal — set by `defineSandboxEnvironment`, not by workflow authors.
|
|
218
|
-
* Marks the workflow as an environment build (base-env / agent-env) so the
|
|
219
|
-
* server skips mounting the shared factory drive for its runs (#13). See
|
|
220
|
-
* `WorkflowMetadata.environmentBuild`.
|
|
221
|
-
*/
|
|
222
|
-
environmentBuild?: boolean;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
38
|
/**
|
|
226
|
-
*
|
|
227
|
-
*
|
|
228
|
-
*
|
|
229
|
-
* `ctx.agentEvents` proxy directly to the underlying `StepContext` hooks,
|
|
230
|
-
* which the engine flushes to the run timeline exactly as the legacy
|
|
231
|
-
* full-mode runner did.
|
|
39
|
+
* Declare a workflow — the typed step builder. Multiple steps with
|
|
40
|
+
* explicit input/output schemas, durability + replay at every step
|
|
41
|
+
* boundary:
|
|
232
42
|
*
|
|
233
|
-
*
|
|
234
|
-
* `ctx.step("name", fn)` calls inside the body become sub-step events
|
|
235
|
-
* under that one step. Authors keep the same source; the dashboard sees
|
|
236
|
-
* the same timeline shape.
|
|
237
|
-
*/
|
|
238
|
-
// TODO: collapse run-form into pure sugar over step-form. Run-form
|
|
239
|
-
// already compiles to step-form-with-one-step here, so maintaining two
|
|
240
|
-
// authoring surfaces is API duplication that periodically drifts (see
|
|
241
|
-
// the input/output thread-through bug fixed on 2026-05-20: step-form
|
|
242
|
-
// preserved schemas, run-form silently stamped z.unknown()). Cleaner:
|
|
243
|
-
// turn `defineWorkflow({ run })` into a thin wrapper that calls the
|
|
244
|
-
// step builder with a synthesised `{name:"run", input, output, run}`
|
|
245
|
-
// step, then delete this function. Runtime stays identical.
|
|
246
|
-
function compileRunForm<TOutput, TInput extends Record<string, unknown>>(
|
|
247
|
-
def: WorkflowDefinition<TOutput, TInput>,
|
|
248
|
-
metadata: WorkflowMetadata,
|
|
249
|
-
): Workflow<TInput, TOutput> {
|
|
250
|
-
const unknownSchema = z.unknown() as z.ZodType<unknown>;
|
|
251
|
-
const inputSchema: z.ZodType<TInput> = def.input ?? (unknownSchema as z.ZodType<TInput>);
|
|
252
|
-
const outputSchema: z.ZodType<TOutput> = def.output ?? (unknownSchema as z.ZodType<TOutput>);
|
|
253
|
-
const step: Step<TInput, TOutput> = {
|
|
254
|
-
name: "run",
|
|
255
|
-
input: inputSchema,
|
|
256
|
-
output: outputSchema,
|
|
257
|
-
run: async (stepCtx) => {
|
|
258
|
-
// Proxy the legacy WorkflowCtx hooks to the step's collector-backed
|
|
259
|
-
// implementations. The engine harvests the snapshot after execute
|
|
260
|
-
// returns; nothing here is a no-op.
|
|
261
|
-
const workflowCtx: WorkflowCtx<TInput> = {
|
|
262
|
-
input: stepCtx.input,
|
|
263
|
-
run: stepCtx.run,
|
|
264
|
-
requestContext: stepCtx.requestContext,
|
|
265
|
-
invokeChild: stepCtx.invokeChild,
|
|
266
|
-
setMetadata: stepCtx.setMetadata,
|
|
267
|
-
step: stepCtx.step,
|
|
268
|
-
agentEvents: stepCtx.agentEvents,
|
|
269
|
-
pause: stepCtx.pause,
|
|
270
|
-
sleep: stepCtx.sleep,
|
|
271
|
-
waitForEvent: stepCtx.waitForEvent,
|
|
272
|
-
processors: metadata.processors ?? [],
|
|
273
|
-
};
|
|
274
|
-
const sandbox = stepCtx.sandbox;
|
|
275
|
-
if (!sandbox) throw new Error("legacy run-form workflow requires a sandbox in StepContext");
|
|
276
|
-
return def.run(workflowCtx, sandbox);
|
|
277
|
-
},
|
|
278
|
-
};
|
|
279
|
-
const workflow: Workflow<TInput, TOutput> = {
|
|
280
|
-
id: "@run-form",
|
|
281
|
-
input: inputSchema,
|
|
282
|
-
output: outputSchema,
|
|
283
|
-
steps: Object.freeze([step]),
|
|
284
|
-
metadata,
|
|
285
|
-
};
|
|
286
|
-
// Brand BEFORE freezing — defineProperty is the only way to set a
|
|
287
|
-
// non-enumerable key, and frozen objects refuse it.
|
|
288
|
-
Object.defineProperty(workflow, WORKFLOW_BRAND, { value: true, enumerable: false });
|
|
289
|
-
return Object.freeze(workflow);
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
/**
|
|
293
|
-
* Declare a workflow. Two forms; both return a `Workflow` whose
|
|
294
|
-
* `metadata` field carries the server-readable declarations.
|
|
43
|
+
* defineWorkflow({ id, input, output }).step(defineStep(...)).build()
|
|
295
44
|
*
|
|
296
|
-
*
|
|
297
|
-
*
|
|
298
|
-
*
|
|
299
|
-
* Step form — the typed builder. Multiple steps with explicit input/
|
|
300
|
-
* output schemas, durability + replay at every step boundary.
|
|
301
|
-
*
|
|
302
|
-
* Both forms produce the same downstream shape: the bundler reads
|
|
303
|
-
* `workflow.metadata.networkPolicy` / `placeholders` / etc.; the server
|
|
304
|
-
* stores the step plan; runner subprocesses execute one step at a time
|
|
305
|
-
* via the StepInvocation seam.
|
|
306
|
-
*/
|
|
307
|
-
/**
|
|
308
|
-
* @deprecated Run-form is legacy. Use the step-form overload —
|
|
309
|
-
* `defineWorkflow({ id, input, output }).step(defineStep(...)).build()` — for
|
|
310
|
-
* durable, replayable steps and working pause. Run-form compiles to a single
|
|
311
|
-
* opaque step (`compileRunForm`); there is no per-step replay.
|
|
45
|
+
* The bundler reads `workflow.metadata.networkPolicy` / `placeholders` /
|
|
46
|
+
* etc. off the built `Workflow`; the server stores the step plan; runner
|
|
47
|
+
* subprocesses execute one step at a time via the StepInvocation seam.
|
|
312
48
|
*/
|
|
313
|
-
export function defineWorkflow<
|
|
314
|
-
TOutput = unknown,
|
|
315
|
-
TInput extends Record<string, unknown> = Record<string, unknown>,
|
|
316
|
-
>(
|
|
317
|
-
def: WorkflowDefinition<TOutput, TInput>,
|
|
318
|
-
): Workflow<TInput, TOutput>;
|
|
319
49
|
export function defineWorkflow<TInput, TOutput>(
|
|
320
50
|
def: StepWorkflowDefinition<TInput, TOutput>,
|
|
321
|
-
):
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
51
|
+
): WorkflowBuilder<TInput, TInput> {
|
|
52
|
+
if ("run" in def) {
|
|
53
|
+
throw new Error(
|
|
54
|
+
"defineWorkflow: the legacy run-form (`defineWorkflow({ run(ctx, sandbox) { … } })`) has been removed. " +
|
|
55
|
+
"Author workflows in step-form — `defineWorkflow({ id, input, output }).step(defineStep(...)).build()` — " +
|
|
56
|
+
"or run /ac:generate-workflow to scaffold the current shape.",
|
|
57
|
+
);
|
|
58
|
+
}
|
|
326
59
|
return createStepWorkflow(def);
|
|
327
60
|
}
|
|
328
61
|
|