@github/copilot-sdk 1.0.14 → 1.0.15-preview.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 +116 -11
- package/dist/cjs/cliVersion.js +1 -1
- package/dist/cjs/client.js +24 -17
- package/dist/cjs/copilotRequestHandler.js +156 -20
- package/dist/cjs/extension.js +12 -1
- package/dist/cjs/generated/rpc.js +349 -8
- package/dist/cjs/index.js +9 -2
- package/dist/cjs/schema.js +40 -0
- package/dist/cjs/session.js +625 -3
- package/dist/cjs/workflow.js +134 -0
- package/dist/cliVersion.d.ts +1 -1
- package/dist/cliVersion.js +1 -1
- package/dist/client.d.ts +2 -0
- package/dist/client.js +22 -15
- package/dist/copilotRequestHandler.js +156 -20
- package/dist/extension.d.ts +22 -8
- package/dist/extension.js +13 -1
- package/dist/generated/rpc.d.ts +2824 -315
- package/dist/generated/rpc.js +349 -8
- package/dist/generated/session-events.d.ts +565 -2
- package/dist/index.d.ts +3 -1
- package/dist/index.js +5 -1
- package/dist/schema.d.ts +4 -0
- package/dist/schema.js +14 -0
- package/dist/session.d.ts +26 -3
- package/dist/session.js +630 -3
- package/dist/types.d.ts +37 -5
- package/dist/workflow.d.ts +364 -0
- package/dist/workflow.js +106 -0
- package/docs/extensions.md +1 -0
- package/docs/workflows.md +257 -0
- package/package.json +17 -14
package/dist/types.d.ts
CHANGED
|
@@ -4,14 +4,14 @@
|
|
|
4
4
|
import type { Canvas } from "./canvas.js";
|
|
5
5
|
import type { SessionFsProvider } from "./sessionFsProvider.js";
|
|
6
6
|
import type { CopilotRequestHandler } from "./copilotRequestHandler.js";
|
|
7
|
-
import type { AutoTier, PermissionRequest as GeneratedPermissionRequest, PermissionRequestedData as GeneratedPermissionRequestedData, PermissionRequestedEvent as GeneratedPermissionRequestedEvent, ReasoningSummary, SessionLimitsConfig, SessionEvent as GeneratedSessionEvent } from "./generated/session-events.js";
|
|
7
|
+
import type { AttachmentExtensionContext as GeneratedExtensionContextAttachment, AutoTier, PermissionRequest as GeneratedPermissionRequest, PermissionRequestedData as GeneratedPermissionRequestedData, PermissionRequestedEvent as GeneratedPermissionRequestedEvent, ReasoningSummary, SessionLimitsConfig, SessionEvent as GeneratedSessionEvent } from "./generated/session-events.js";
|
|
8
8
|
import type { CopilotSession } from "./session.js";
|
|
9
9
|
import type { FactoryJsonSchema, JsonValue } from "./factory.js";
|
|
10
|
-
import type { GitHubTokenAcquireRequest, GitHubTokenAcquireResult, GitHubTelemetryNotification, ModelBillingTokenPrices, OpenCanvasInstance, RemoteSessionMode, CurrentToolMetadata } from "./generated/rpc.js";
|
|
10
|
+
import type { ExtensionLaunchProviderHandler as GeneratedExtensionLaunchProvider, GitHubTokenAcquireRequest, GitHubTokenAcquireResult, GitHubTelemetryNotification, ModelBillingTokenPrices, OpenCanvasInstance, RemoteSessionMode, CurrentToolMetadata } from "./generated/rpc.js";
|
|
11
11
|
import type { ToolSet } from "./toolSet.js";
|
|
12
12
|
export type { RemoteSessionMode } from "./generated/rpc.js";
|
|
13
13
|
export type { CurrentToolMetadata } from "./generated/rpc.js";
|
|
14
|
-
export type { GitHubTokenAcquireReason, GitHubTokenAcquireResult, GitHubTelemetryNotification, GitHubTelemetryEvent, GitHubTelemetryClientInfo, } from "./generated/rpc.js";
|
|
14
|
+
export type { ExtensionLaunchProfile, ExtensionLaunchProviderResolveRequest, ExtensionLaunchProviderResolveResult, GitHubTokenAcquireReason, GitHubTokenAcquireResult, GitHubTelemetryNotification, GitHubTelemetryEvent, GitHubTelemetryClientInfo, } from "./generated/rpc.js";
|
|
15
15
|
/**
|
|
16
16
|
* Arguments passed to a session's {@link GitHubTokenProvider}.
|
|
17
17
|
*
|
|
@@ -282,6 +282,14 @@ export interface CopilotClientOptions {
|
|
|
282
282
|
* startup before any sessions can be created.
|
|
283
283
|
*/
|
|
284
284
|
builtinPluginDirectories?: readonly string[];
|
|
285
|
+
/**
|
|
286
|
+
* Connection-level extension launch profile provider.
|
|
287
|
+
* When set, the client registers the provider during startup before any
|
|
288
|
+
* session can be created.
|
|
289
|
+
*
|
|
290
|
+
* @experimental
|
|
291
|
+
*/
|
|
292
|
+
extensionLaunchProvider?: ExtensionLaunchProvider;
|
|
285
293
|
/**
|
|
286
294
|
* Log level for the Copilot runtime. When omitted, the runtime uses its
|
|
287
295
|
* own default (currently `"info"`).
|
|
@@ -409,6 +417,8 @@ export interface CopilotClientOptions {
|
|
|
409
417
|
*/
|
|
410
418
|
clientInfo?: CopilotClientInfo;
|
|
411
419
|
}
|
|
420
|
+
/** Resolves launch profiles for extension entrypoints discovered by the runtime. */
|
|
421
|
+
export type ExtensionLaunchProvider = GeneratedExtensionLaunchProvider;
|
|
412
422
|
/**
|
|
413
423
|
* Configuration for creating a session
|
|
414
424
|
*/
|
|
@@ -510,6 +520,13 @@ export interface ZodSchema<T = unknown> {
|
|
|
510
520
|
_output: T;
|
|
511
521
|
toJSONSchema(): Record<string, unknown>;
|
|
512
522
|
}
|
|
523
|
+
/**
|
|
524
|
+
* A Zod-compatible output schema that both describes and parses a typed result.
|
|
525
|
+
* TypeScript types are erased at runtime, so typed output requires a schema value.
|
|
526
|
+
*/
|
|
527
|
+
export interface ResponseSchema<T = unknown> extends ZodSchema<T> {
|
|
528
|
+
parse(value: unknown): T;
|
|
529
|
+
}
|
|
513
530
|
/**
|
|
514
531
|
* Tool definition. Parameters can be either:
|
|
515
532
|
* - A Zod schema (provides type inference for handler)
|
|
@@ -2740,6 +2757,8 @@ export interface ProviderModelConfig {
|
|
|
2740
2757
|
* Message provenance, independent of delivery mode.
|
|
2741
2758
|
*/
|
|
2742
2759
|
export type MessageSource = "user" | "system" | `agent-${string}`;
|
|
2760
|
+
/** Structured context contributed by an extension. */
|
|
2761
|
+
export type ExtensionContextAttachment = GeneratedExtensionContextAttachment;
|
|
2743
2762
|
export interface MessageOptions {
|
|
2744
2763
|
/**
|
|
2745
2764
|
* The prompt/message to send
|
|
@@ -2752,7 +2771,7 @@ export interface MessageOptions {
|
|
|
2752
2771
|
*/
|
|
2753
2772
|
source?: MessageSource;
|
|
2754
2773
|
/**
|
|
2755
|
-
* File, directory, selection, or
|
|
2774
|
+
* File, directory, selection, blob, or extension context attachments
|
|
2756
2775
|
*/
|
|
2757
2776
|
attachments?: Array<{
|
|
2758
2777
|
type: "file";
|
|
@@ -2782,7 +2801,7 @@ export interface MessageOptions {
|
|
|
2782
2801
|
data: string;
|
|
2783
2802
|
mimeType: string;
|
|
2784
2803
|
displayName?: string;
|
|
2785
|
-
}>;
|
|
2804
|
+
} | ExtensionContextAttachment>;
|
|
2786
2805
|
/**
|
|
2787
2806
|
* Message delivery mode
|
|
2788
2807
|
* - "enqueue": Add to queue (default)
|
|
@@ -2802,6 +2821,19 @@ export interface MessageOptions {
|
|
|
2802
2821
|
* If provided, this is shown in the timeline instead of `prompt`.
|
|
2803
2822
|
*/
|
|
2804
2823
|
displayPrompt?: string;
|
|
2824
|
+
/**
|
|
2825
|
+
* JSON Schema or a Zod schema for this run's output, including requests after tool calls.
|
|
2826
|
+
* Independent sends do not inherit it. Ordinary immediate steering retains the active
|
|
2827
|
+
* schema and origin, even when promoted to a follow-up after the model request finishes.
|
|
2828
|
+
* Specifying a schema with mode "immediate" is rejected, even while idle.
|
|
2829
|
+
* This is not a persisted session default and does not survive a context reset.
|
|
2830
|
+
*
|
|
2831
|
+
* sendAndWait still returns an assistant message event. For a typed result, pass a
|
|
2832
|
+
* Zod-compatible schema as sendAndWait's second argument instead.
|
|
2833
|
+
* Streaming events remain text and may include intermediate messages.
|
|
2834
|
+
* Use rpc.send's responseFormat for provider-specific name, description and strict options.
|
|
2835
|
+
*/
|
|
2836
|
+
responseSchema?: ZodSchema | Record<string, unknown>;
|
|
2805
2837
|
}
|
|
2806
2838
|
/**
|
|
2807
2839
|
* All possible event type strings from SessionEvent
|
|
@@ -0,0 +1,364 @@
|
|
|
1
|
+
import type { WorkflowGetRunProgressRequest, WorkflowListRunsRequest, WorkflowListRunsResult, WorkflowProgressPage, WorkflowRunDetail, WorkflowRunResult, WorkflowRunStatus, WorkflowRunSummary } from "./generated/rpc.js";
|
|
2
|
+
import type { ContextTier } from "./generated/session-events.js";
|
|
3
|
+
import type { CopilotSession } from "./session.js";
|
|
4
|
+
import type { JsonValue } from "./factory.js";
|
|
5
|
+
export type { WorkflowRunResult };
|
|
6
|
+
export type { WorkflowAgentSummary, WorkflowPhaseStatus, WorkflowPhaseObservation, WorkflowProgressLine, WorkflowProgressPage, WorkflowRunDetail, WorkflowRunStatus, WorkflowRunSummary, } from "./generated/rpc.js";
|
|
7
|
+
/**
|
|
8
|
+
* Options for paging durable workflow runs.
|
|
9
|
+
*
|
|
10
|
+
* @experimental Part of the experimental Dynamic Workflows surface and may
|
|
11
|
+
* change or be removed in future SDK or CLI releases.
|
|
12
|
+
*/
|
|
13
|
+
export type WorkflowListRunsOptions = WorkflowListRunsRequest;
|
|
14
|
+
/**
|
|
15
|
+
* A page of durable workflow runs and its paging metadata.
|
|
16
|
+
*
|
|
17
|
+
* @experimental Part of the experimental Dynamic Workflows surface and may
|
|
18
|
+
* change or be removed in future SDK or CLI releases.
|
|
19
|
+
*/
|
|
20
|
+
export type WorkflowRunsPage = WorkflowListRunsResult;
|
|
21
|
+
/**
|
|
22
|
+
* Whether a workflow run status is terminal.
|
|
23
|
+
*
|
|
24
|
+
* @experimental Part of the experimental Dynamic Workflows surface and may
|
|
25
|
+
* change or be removed in future SDK or CLI releases.
|
|
26
|
+
*/
|
|
27
|
+
export declare function isWorkflowRunTerminal(status: WorkflowRunStatus): boolean;
|
|
28
|
+
declare const workflowHandleBrand: unique symbol;
|
|
29
|
+
/**
|
|
30
|
+
* Conservative JSON shape language accepted by the Dynamic Workflows surface, for
|
|
31
|
+
* both structured workflow agent output and a workflow's declared `argsSchema`.
|
|
32
|
+
*
|
|
33
|
+
* This is a best-effort structural guard — used to decide whether a subagent's
|
|
34
|
+
* structured output should be accepted or retried, and whether a caller's
|
|
35
|
+
* workflow `args` match the declared shape — **not** a full JSON Schema
|
|
36
|
+
* validator. Only these keywords are honored: `type`, `required`, `enum`,
|
|
37
|
+
* `const`, recursive `properties`/`items`, and `anyOf`/`oneOf`/`allOf`. A `type`
|
|
38
|
+
* is one of `null`, `boolean`, `integer`, `number`, `string`, `array`, or
|
|
39
|
+
* `object`, or a non-empty array of those (for example `["object", "null"]`).
|
|
40
|
+
*
|
|
41
|
+
* Everything else is **ignored, not enforced**. In particular, string
|
|
42
|
+
* constraints (`pattern`, `minLength`, `maxLength`, `format`), numeric ranges
|
|
43
|
+
* (`minimum`, `maximum`), and `additionalProperties` do not reject
|
|
44
|
+
* non-conforming output. Boolean schemas are outside this accepted shape.
|
|
45
|
+
* `oneOf` is treated like `anyOf` (at least one branch must match) rather than
|
|
46
|
+
* strict exactly-one. Author schemas within this subset; do not rely on
|
|
47
|
+
* unsupported constraints for correctness.
|
|
48
|
+
*
|
|
49
|
+
* @experimental Part of the experimental Dynamic Workflows surface and may
|
|
50
|
+
* change or be removed in future SDK or CLI releases.
|
|
51
|
+
*/
|
|
52
|
+
export type WorkflowJsonSchema = {
|
|
53
|
+
[key: string]: JsonValue;
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Static resource ceilings declared by a workflow before it runs.
|
|
57
|
+
*
|
|
58
|
+
* @experimental Part of the experimental Dynamic Workflows surface and may
|
|
59
|
+
* change or be removed in future SDK or CLI releases.
|
|
60
|
+
*/
|
|
61
|
+
export interface WorkflowLimits {
|
|
62
|
+
/** Maximum number of workflow subagents that may run concurrently. Must be positive when present. */
|
|
63
|
+
maxConcurrentSubagents?: number;
|
|
64
|
+
/** Maximum total number of workflow subagents that may be spawned. Must be positive when present. */
|
|
65
|
+
maxTotalSubagents?: number;
|
|
66
|
+
/** Maximum AI credits consumed by workflow subagents and descendants. This post-paid ceiling is soft. */
|
|
67
|
+
maxAiCredits?: number;
|
|
68
|
+
/**
|
|
69
|
+
* Maximum accumulated active-execution time, in seconds. Active execution includes the entire extension body,
|
|
70
|
+
* subprocess waits, queued-agent waits, and sleeps. The limit is armed from the remaining headroom when a run
|
|
71
|
+
* resumes; time between attempts is not counted. Must be finite and positive when present.
|
|
72
|
+
*/
|
|
73
|
+
timeoutSeconds?: number;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Registration metadata for an extension-authored workflow.
|
|
77
|
+
*
|
|
78
|
+
* @experimental Part of the experimental Dynamic Workflows surface and may
|
|
79
|
+
* change or be removed in future SDK or CLI releases.
|
|
80
|
+
*/
|
|
81
|
+
export interface WorkflowMeta {
|
|
82
|
+
/** Stable workflow name used for invocation. */
|
|
83
|
+
name: string;
|
|
84
|
+
/** Human-readable workflow description. */
|
|
85
|
+
description: string;
|
|
86
|
+
/** Display metadata for the progress phases the workflow may report. */
|
|
87
|
+
phases: Array<{
|
|
88
|
+
title: string;
|
|
89
|
+
detail?: string;
|
|
90
|
+
}>;
|
|
91
|
+
/**
|
|
92
|
+
* Optional declared shape of the arguments this workflow expects as `ctx.args`.
|
|
93
|
+
*
|
|
94
|
+
* The runtime records and validates this schema when the workflow contribution
|
|
95
|
+
* is registered. Workflow bodies should still validate any semantic constraints
|
|
96
|
+
* they depend on because the public `session.workflow.run(...)` API forwards
|
|
97
|
+
* arguments directly.
|
|
98
|
+
*/
|
|
99
|
+
argsSchema?: WorkflowJsonSchema;
|
|
100
|
+
/** Optional resource ceilings presented before execution. */
|
|
101
|
+
limits?: WorkflowLimits;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Options for one workflow-scoped subagent call.
|
|
105
|
+
*
|
|
106
|
+
* @experimental Part of the experimental Dynamic Workflows surface and may
|
|
107
|
+
* change or be removed in future SDK or CLI releases.
|
|
108
|
+
*/
|
|
109
|
+
export interface WorkflowAgentOptions {
|
|
110
|
+
label?: string;
|
|
111
|
+
schema?: WorkflowJsonSchema;
|
|
112
|
+
model?: string;
|
|
113
|
+
reasoningEffort?: string;
|
|
114
|
+
contextTier?: ContextTier;
|
|
115
|
+
agent?: string;
|
|
116
|
+
}
|
|
117
|
+
export declare const WORKFLOW_AGENT_OPTION_KEYS: readonly ["label", "schema", "model", "reasoningEffort", "contextTier", "agent"];
|
|
118
|
+
/**
|
|
119
|
+
* Options for a durable workflow step.
|
|
120
|
+
*
|
|
121
|
+
* @experimental Part of the experimental Dynamic Workflows surface and may
|
|
122
|
+
* change or be removed in future SDK or CLI releases.
|
|
123
|
+
*/
|
|
124
|
+
export interface WorkflowStepOptions {
|
|
125
|
+
/** Skip the journal and always invoke the producer. */
|
|
126
|
+
volatile?: boolean;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Per-invocation workflow resource ceiling overrides.
|
|
130
|
+
*
|
|
131
|
+
* An omitted field preserves the existing/default ceiling, a number replaces
|
|
132
|
+
* it, and `null` explicitly makes that dimension unlimited.
|
|
133
|
+
*
|
|
134
|
+
* @experimental Part of the experimental Dynamic Workflows surface and may
|
|
135
|
+
* change or be removed in future SDK or CLI releases.
|
|
136
|
+
*/
|
|
137
|
+
export interface WorkflowLimitOverrides {
|
|
138
|
+
maxConcurrentSubagents?: number | null;
|
|
139
|
+
maxTotalSubagents?: number | null;
|
|
140
|
+
maxAiCredits?: number | null;
|
|
141
|
+
timeoutSeconds?: number | null;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* One stage in a per-item workflow pipeline.
|
|
145
|
+
*
|
|
146
|
+
* @experimental Part of the experimental Dynamic Workflows surface and may
|
|
147
|
+
* change or be removed in future SDK or CLI releases.
|
|
148
|
+
*/
|
|
149
|
+
export type WorkflowPipelineStage<TInput = unknown, TResult = unknown> = (previous: TInput, item: unknown, index: number) => Promise<TResult> | TResult;
|
|
150
|
+
/**
|
|
151
|
+
* Context passed to an extension-authored workflow body.
|
|
152
|
+
*
|
|
153
|
+
* @experimental Part of the experimental Dynamic Workflows surface and may
|
|
154
|
+
* change or be removed in future SDK or CLI releases.
|
|
155
|
+
*/
|
|
156
|
+
export interface WorkflowContext<TArgs extends JsonValue = JsonValue> {
|
|
157
|
+
/** Stable identifier for the current workflow run. */
|
|
158
|
+
readonly runId: string;
|
|
159
|
+
/** Spawn and await one workflow-scoped subagent. */
|
|
160
|
+
agent(prompt: string, options?: WorkflowAgentOptions): Promise<unknown>;
|
|
161
|
+
/** Memoize an arbitrary producer under a stable author-supplied key. */
|
|
162
|
+
step(key: string, producer: () => Promise<JsonValue> | JsonValue, options?: WorkflowStepOptions): Promise<JsonValue>;
|
|
163
|
+
/**
|
|
164
|
+
* Pause this run at a durable, one-shot checkpoint.
|
|
165
|
+
*
|
|
166
|
+
* The first attempt to reach a key pauses and aborts cooperatively. A
|
|
167
|
+
* resumed attempt returns from the same key and continues.
|
|
168
|
+
*/
|
|
169
|
+
pause(key: string): Promise<void>;
|
|
170
|
+
/**
|
|
171
|
+
* Run thunks concurrently and await all of them.
|
|
172
|
+
*
|
|
173
|
+
* A thunk that throws becomes `null` in the result array, so one failed
|
|
174
|
+
* item does not lose the rest. Cancellation and hard runtime failures
|
|
175
|
+
* (`ResponseError`, `ConnectionError`) are the exception: those propagate
|
|
176
|
+
* and reject the whole call, because they mean the run itself is in
|
|
177
|
+
* trouble rather than one item having failed.
|
|
178
|
+
*/
|
|
179
|
+
parallel<TResult>(thunks: Array<() => Promise<TResult> | TResult>): Promise<Array<TResult | null>>;
|
|
180
|
+
/**
|
|
181
|
+
* Run each item through every stage without barriers between stages.
|
|
182
|
+
*
|
|
183
|
+
* A stage that throws drops that item to `null` and skips its remaining
|
|
184
|
+
* stages. As with {@link WorkflowContext.parallel}, cancellation and hard
|
|
185
|
+
* runtime failures propagate instead of being recorded per item.
|
|
186
|
+
*/
|
|
187
|
+
pipeline(items: unknown[], ...stages: WorkflowPipelineStage[]): Promise<unknown[]>;
|
|
188
|
+
/** Start a named workflow progress phase. */
|
|
189
|
+
phase(title: string): void;
|
|
190
|
+
/** Emit a workflow progress line. */
|
|
191
|
+
log(message: string): void;
|
|
192
|
+
/** Reject because nested workflows are not supported. */
|
|
193
|
+
workflow(name: string, args?: JsonValue): Promise<JsonValue | void>;
|
|
194
|
+
/** Caller-supplied input, forwarded verbatim. */
|
|
195
|
+
args: TArgs;
|
|
196
|
+
/**
|
|
197
|
+
* The session instance returned by `joinSession`. It refuses calls that
|
|
198
|
+
* start, resume, or pause a workflow run.
|
|
199
|
+
*/
|
|
200
|
+
session: CopilotSession;
|
|
201
|
+
/** Cooperative cancellation signal for the current workflow run. */
|
|
202
|
+
signal: AbortSignal;
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Definition accepted by {@link defineWorkflow}.
|
|
206
|
+
*
|
|
207
|
+
* @experimental Part of the experimental Dynamic Workflows surface and may
|
|
208
|
+
* change or be removed in future SDK or CLI releases.
|
|
209
|
+
*/
|
|
210
|
+
export interface WorkflowDefinition<TArgs extends JsonValue = JsonValue, TResult extends JsonValue | void = JsonValue | void> {
|
|
211
|
+
meta: WorkflowMeta;
|
|
212
|
+
run(context: WorkflowContext<TArgs>): Promise<TResult>;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* A deeply immutable view of a value.
|
|
216
|
+
*
|
|
217
|
+
* `defineWorkflow` deep-freezes the metadata it stores, so the handle's view of
|
|
218
|
+
* it has to be readonly all the way down or `handle.meta.name = "..."` and
|
|
219
|
+
* `handle.meta.phases.push(...)` would compile and then throw at runtime.
|
|
220
|
+
*/
|
|
221
|
+
type DeepReadonly<T> = T extends (infer U)[] ? readonly DeepReadonly<U>[] : T extends object ? {
|
|
222
|
+
readonly [K in keyof T]: DeepReadonly<T[K]>;
|
|
223
|
+
} : T;
|
|
224
|
+
/**
|
|
225
|
+
* Opaque reusable reference to a defined workflow.
|
|
226
|
+
*
|
|
227
|
+
* @experimental Part of the experimental Dynamic Workflows surface and may
|
|
228
|
+
* change or be removed in future SDK or CLI releases.
|
|
229
|
+
*/
|
|
230
|
+
export interface WorkflowHandle<TArgs extends JsonValue = JsonValue, TResult extends JsonValue | void = JsonValue | void> {
|
|
231
|
+
readonly meta: DeepReadonly<WorkflowMeta>;
|
|
232
|
+
readonly [workflowHandleBrand]: {
|
|
233
|
+
readonly args: TArgs;
|
|
234
|
+
readonly result: TResult;
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Options for invoking a workflow.
|
|
239
|
+
*
|
|
240
|
+
* @experimental Part of the experimental Dynamic Workflows surface and may
|
|
241
|
+
* change or be removed in future SDK or CLI releases.
|
|
242
|
+
*/
|
|
243
|
+
export interface WorkflowRunOptions<TArgs extends JsonValue = JsonValue> {
|
|
244
|
+
/** Input surfaced as `context.args`. */
|
|
245
|
+
args?: TArgs;
|
|
246
|
+
/** Optional per-invocation resource ceiling overrides. */
|
|
247
|
+
limits?: WorkflowLimitOverrides;
|
|
248
|
+
/** Whether to notify the originating session when the workflow completes. */
|
|
249
|
+
notifyOnComplete?: boolean;
|
|
250
|
+
/** Whether to emit workflow phase names to the session transcript. */
|
|
251
|
+
logPhaseNames?: boolean;
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Options for resuming a workflow run by ID.
|
|
255
|
+
*
|
|
256
|
+
* @experimental Part of the experimental Dynamic Workflows surface and may
|
|
257
|
+
* change or be removed in future SDK or CLI releases.
|
|
258
|
+
*/
|
|
259
|
+
export interface WorkflowResumeOptions {
|
|
260
|
+
/** Optional per-invocation resource ceiling overrides. */
|
|
261
|
+
limits?: WorkflowLimitOverrides;
|
|
262
|
+
/** Whether to notify the originating session when the workflow completes. */
|
|
263
|
+
notifyOnComplete?: boolean;
|
|
264
|
+
/** Whether to emit workflow phase names to the session transcript. */
|
|
265
|
+
logPhaseNames?: boolean;
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Machine-readable pre-execution workflow resume failure.
|
|
269
|
+
*
|
|
270
|
+
* @experimental Part of the experimental Dynamic Workflows surface and may
|
|
271
|
+
* change or be removed in future SDK or CLI releases.
|
|
272
|
+
*/
|
|
273
|
+
export type WorkflowResumeErrorCode = "not_found" | "non_resumable" | "workflow_run_not_resumable" | "already_active" | "workflow_already_running" | "workflow_limits_invalid" | "workflow_session_disposed" | "workflow_storage_unavailable" | "workflow_storage_corrupt";
|
|
274
|
+
/**
|
|
275
|
+
* Friendly workflow API exposed on a session.
|
|
276
|
+
*
|
|
277
|
+
* @experimental Part of the experimental Dynamic Workflows surface and may
|
|
278
|
+
* change or be removed in future SDK or CLI releases.
|
|
279
|
+
*/
|
|
280
|
+
export interface SessionWorkflowApi {
|
|
281
|
+
/**
|
|
282
|
+
* Run a registered workflow and resolve with its run envelope.
|
|
283
|
+
*
|
|
284
|
+
* The envelope is returned for every outcome, including `error`, `halted`,
|
|
285
|
+
* `paused`, and `cancelled` — inspect `status` and read `result` only when
|
|
286
|
+
* the run completed. `paused` settles the current attempt, but the same
|
|
287
|
+
* durable run can later resume under its existing run ID. SDK-initiated
|
|
288
|
+
* runs do not request permission, so they have no declined outcome.
|
|
289
|
+
* Failures that occur before a run exists (such as an unknown workflow or
|
|
290
|
+
* attempting to start a run while the session is at its active top-level
|
|
291
|
+
* run limit) still reject.
|
|
292
|
+
*/
|
|
293
|
+
run(name: string, options?: WorkflowRunOptions): Promise<WorkflowRunResult>;
|
|
294
|
+
run<TArgs extends JsonValue>(workflow: WorkflowHandle<TArgs, JsonValue | void>, options?: WorkflowRunOptions<TArgs>): Promise<WorkflowRunResult>;
|
|
295
|
+
/**
|
|
296
|
+
* Resume a run from its persisted workflow name, arguments, journal, and accounting.
|
|
297
|
+
*
|
|
298
|
+
* Resolves with the run envelope like {@link SessionWorkflowApi.run}.
|
|
299
|
+
* SDK-initiated resumes do not request permission. A pre-execution failure
|
|
300
|
+
* with a documented resume code rejects with {@link WorkflowResumeError}.
|
|
301
|
+
*/
|
|
302
|
+
resume(runId: string, options?: WorkflowResumeOptions): Promise<WorkflowRunResult>;
|
|
303
|
+
/** Read the latest durable envelope for a workflow run. */
|
|
304
|
+
getRun(runId: string): Promise<WorkflowRunResult>;
|
|
305
|
+
/**
|
|
306
|
+
* Wait for the current attempt to settle and resolve with its envelope.
|
|
307
|
+
*
|
|
308
|
+
* Resolves as soon as the run reaches `completed`, `error`, `halted`,
|
|
309
|
+
* `paused`, or `cancelled`, and resolves immediately when the current
|
|
310
|
+
* attempt has already settled. A `paused` envelope is an attempt-level
|
|
311
|
+
* snapshot: resuming the same durable run can later change the envelope
|
|
312
|
+
* returned by {@link SessionWorkflowApi.getRun}.
|
|
313
|
+
*
|
|
314
|
+
* This watches the runtime's `factory.run_updated` compatibility event and
|
|
315
|
+
* periodically re-reads the durable envelope so a missed event cannot
|
|
316
|
+
* leave the wait hanging. Pass a `signal` to stop waiting; aborting rejects
|
|
317
|
+
* and has no effect on the run itself, which keeps executing. Use
|
|
318
|
+
* {@link SessionWorkflowApi.cancel} to actually stop it.
|
|
319
|
+
*/
|
|
320
|
+
waitForRun(runId: string, options?: {
|
|
321
|
+
signal?: AbortSignal;
|
|
322
|
+
}): Promise<WorkflowRunResult>;
|
|
323
|
+
/**
|
|
324
|
+
* List the newest default page of this session's durable workflow runs.
|
|
325
|
+
*
|
|
326
|
+
* This backwards-compatible overload returns only the runs array. Pass
|
|
327
|
+
* paging options to receive the full page, including its cursors and
|
|
328
|
+
* truncation metadata.
|
|
329
|
+
*/
|
|
330
|
+
listRuns(): Promise<WorkflowRunSummary[]>;
|
|
331
|
+
/**
|
|
332
|
+
* Page this session's durable workflow runs.
|
|
333
|
+
*
|
|
334
|
+
* `afterSeq` and `beforeSeq` are exclusive cursors. The result includes
|
|
335
|
+
* `oldestSeq`, `newestSeq`, `hasMoreNewer`, and `omittedOlder` so callers
|
|
336
|
+
* can continue paging without using the raw RPC client.
|
|
337
|
+
*/
|
|
338
|
+
listRuns(options: WorkflowListRunsOptions): Promise<WorkflowRunsPage>;
|
|
339
|
+
/** Read durable phases, direct agents, and the latest progress tail for a run. */
|
|
340
|
+
getRunDetail(runId: string): Promise<WorkflowRunDetail>;
|
|
341
|
+
/** Page durable progress forward, backward, or from the latest tail. */
|
|
342
|
+
getRunProgress(runId: string, options?: Omit<WorkflowGetRunProgressRequest, "runId">): Promise<WorkflowProgressPage>;
|
|
343
|
+
/** Pause a running workflow attempt and return its `paused` envelope. */
|
|
344
|
+
pause(runId: string): Promise<WorkflowRunResult>;
|
|
345
|
+
/** Cancel a workflow run and return its terminal envelope. */
|
|
346
|
+
cancel(runId: string): Promise<WorkflowRunResult>;
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* Error thrown when a workflow cannot be resumed before execution begins.
|
|
350
|
+
*
|
|
351
|
+
* @experimental Part of the experimental Dynamic Workflows surface and may
|
|
352
|
+
* change or be removed in future SDK or CLI releases.
|
|
353
|
+
*/
|
|
354
|
+
export declare class WorkflowResumeError extends Error {
|
|
355
|
+
readonly code: WorkflowResumeErrorCode;
|
|
356
|
+
constructor(code: WorkflowResumeErrorCode, message: string);
|
|
357
|
+
}
|
|
358
|
+
/**
|
|
359
|
+
* Defines an extension-authored workflow and returns an opaque registration handle.
|
|
360
|
+
*
|
|
361
|
+
* @experimental Part of the experimental Dynamic Workflows surface and may
|
|
362
|
+
* change or be removed in future SDK or CLI releases.
|
|
363
|
+
*/
|
|
364
|
+
export declare function defineWorkflow<TArgs extends JsonValue = JsonValue, TResult extends JsonValue | void = JsonValue | void>(definition: WorkflowDefinition<TArgs, TResult>): WorkflowHandle<TArgs, TResult>;
|
package/dist/workflow.js
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
const WORKFLOW_TERMINAL_STATUSES = /* @__PURE__ */ new Set([
|
|
2
|
+
"completed",
|
|
3
|
+
"halted",
|
|
4
|
+
"paused",
|
|
5
|
+
"cancelled",
|
|
6
|
+
"error"
|
|
7
|
+
]);
|
|
8
|
+
function isWorkflowRunTerminal(status) {
|
|
9
|
+
return WORKFLOW_TERMINAL_STATUSES.has(status);
|
|
10
|
+
}
|
|
11
|
+
const WORKFLOW_AGENT_OPTION_KEYS = [
|
|
12
|
+
"label",
|
|
13
|
+
"schema",
|
|
14
|
+
"model",
|
|
15
|
+
"reasoningEffort",
|
|
16
|
+
"contextTier",
|
|
17
|
+
"agent"
|
|
18
|
+
];
|
|
19
|
+
class WorkflowResumeError extends Error {
|
|
20
|
+
constructor(code, message) {
|
|
21
|
+
super(message);
|
|
22
|
+
this.code = code;
|
|
23
|
+
this.name = "WorkflowResumeError";
|
|
24
|
+
}
|
|
25
|
+
code;
|
|
26
|
+
}
|
|
27
|
+
const workflowHandles = /* @__PURE__ */ new WeakMap();
|
|
28
|
+
const MAX_WORKFLOW_TIMEOUT_SECONDS = 2147483647e-3;
|
|
29
|
+
const NANO_AIU_PER_AIU = 1e9;
|
|
30
|
+
function deepFreeze(value) {
|
|
31
|
+
if (value !== null && typeof value === "object" && !Object.isFrozen(value)) {
|
|
32
|
+
Object.freeze(value);
|
|
33
|
+
for (const nested of Object.values(value)) {
|
|
34
|
+
deepFreeze(nested);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return value;
|
|
38
|
+
}
|
|
39
|
+
function validateLimits(meta) {
|
|
40
|
+
const limits = meta.limits;
|
|
41
|
+
if (!limits) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
for (const field of ["maxConcurrentSubagents", "maxTotalSubagents"]) {
|
|
45
|
+
const value = limits[field];
|
|
46
|
+
if (value !== void 0 && (!Number.isInteger(value) || value <= 0)) {
|
|
47
|
+
throw new Error(`Workflow limit "${field}" must be a positive integer`);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (limits.timeoutSeconds !== void 0 && (!Number.isFinite(limits.timeoutSeconds) || limits.timeoutSeconds <= 0)) {
|
|
51
|
+
throw new Error(
|
|
52
|
+
'Workflow limit "timeoutSeconds" must be a positive, finite number of seconds'
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
if (limits.timeoutSeconds !== void 0 && limits.timeoutSeconds > MAX_WORKFLOW_TIMEOUT_SECONDS) {
|
|
56
|
+
throw new Error(
|
|
57
|
+
`Workflow limit "timeoutSeconds" must not exceed ${MAX_WORKFLOW_TIMEOUT_SECONDS} seconds`
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
if (limits.maxAiCredits !== void 0) {
|
|
61
|
+
const maxNanoAiu = Math.round(limits.maxAiCredits * NANO_AIU_PER_AIU);
|
|
62
|
+
if (!Number.isFinite(limits.maxAiCredits) || limits.maxAiCredits <= 0 || !Number.isSafeInteger(maxNanoAiu) || maxNanoAiu < 1) {
|
|
63
|
+
throw new Error(
|
|
64
|
+
'Workflow limit "maxAiCredits" must be a positive, finite number that rounds to a safe positive integer nano-AIU ceiling'
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
function validatePhases(meta) {
|
|
70
|
+
const titles = /* @__PURE__ */ new Set();
|
|
71
|
+
for (const phase of meta.phases) {
|
|
72
|
+
if (phase.title.trim().length === 0) {
|
|
73
|
+
throw new Error("Workflow phase titles must not be empty");
|
|
74
|
+
}
|
|
75
|
+
if (titles.has(phase.title)) {
|
|
76
|
+
throw new Error(`Workflow phase title "${phase.title}" is declared more than once`);
|
|
77
|
+
}
|
|
78
|
+
titles.add(phase.title);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
function defineWorkflow(definition) {
|
|
82
|
+
const meta = deepFreeze(structuredClone(definition.meta));
|
|
83
|
+
validateLimits(meta);
|
|
84
|
+
validatePhases(meta);
|
|
85
|
+
const stored = {
|
|
86
|
+
meta,
|
|
87
|
+
run: definition.run
|
|
88
|
+
};
|
|
89
|
+
const handle = Object.freeze({ meta });
|
|
90
|
+
workflowHandles.set(handle, stored);
|
|
91
|
+
return handle;
|
|
92
|
+
}
|
|
93
|
+
function getWorkflowDefinition(handle) {
|
|
94
|
+
const definition = workflowHandles.get(handle);
|
|
95
|
+
if (!definition) {
|
|
96
|
+
throw new Error("Invalid workflow handle");
|
|
97
|
+
}
|
|
98
|
+
return definition;
|
|
99
|
+
}
|
|
100
|
+
export {
|
|
101
|
+
WORKFLOW_AGENT_OPTION_KEYS,
|
|
102
|
+
WorkflowResumeError,
|
|
103
|
+
defineWorkflow,
|
|
104
|
+
getWorkflowDefinition,
|
|
105
|
+
isWorkflowRunTerminal
|
|
106
|
+
};
|
package/docs/extensions.md
CHANGED
|
@@ -77,5 +77,6 @@ An approved extension can pass a granted value to anything it starts, so ask onl
|
|
|
77
77
|
## Further Reading
|
|
78
78
|
|
|
79
79
|
- `examples.md` — Practical code examples for tools, hooks, events, and complete extensions
|
|
80
|
+
- `workflows.md` — Authoring, running, resuming, and observing Dynamic Workflows
|
|
80
81
|
- `factories.md`: Authoring, running, resuming, and observing Agent Factories
|
|
81
82
|
- `agent-author.md` — Step-by-step workflow for agents authoring extensions programmatically
|