experimental-ash 0.22.1 → 0.23.0
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/CHANGELOG.md +20 -0
- package/dist/docs/public/faqs.md +67 -0
- package/dist/docs/public/meta.json +1 -0
- package/dist/docs/public/sandbox.md +25 -0
- package/dist/docs/public/schedules.md +11 -0
- package/dist/docs/public/session-context.md +46 -89
- package/dist/docs/public/skills.md +13 -0
- package/dist/docs/public/subagents.md +12 -6
- package/dist/docs/public/tools.md +9 -13
- package/dist/docs/public/typescript-api.md +2 -2
- package/dist/src/chunks/{client-CKsU8Li3.js → client-nshDsWNF.js} +1 -1
- package/dist/src/chunks/{dev-authored-source-watcher-Bj0TDis0.js → dev-authored-source-watcher-d_35Mp8T.js} +1 -1
- package/dist/src/chunks/{host-BDf7A9G7.js → host-tji7W0Nn.js} +54 -11
- package/dist/src/chunks/paths-YoCQlavu.js +89 -0
- package/dist/src/chunks/{prewarm-xQtl6kAD.js → prewarm-6duWvvb5.js} +1 -1
- package/dist/src/cli/commands/info.js +1 -1
- package/dist/src/cli/dev/repl.js +2 -2
- package/dist/src/cli/run.js +1 -1
- package/dist/src/client/session.js +8 -0
- package/dist/src/client/types.d.ts +12 -1
- package/dist/src/compiled/.vendor-stamp.json +1 -1
- package/dist/src/compiled/@workflow/core/_ms.d.ts +4 -0
- package/dist/src/compiled/@workflow/core/_workflow-serde.d.ts +5 -0
- package/dist/src/compiled/@workflow/core/_workflow-utils.d.ts +8 -0
- package/dist/src/compiled/@workflow/core/_workflow-world.d.ts +59 -0
- package/dist/src/compiled/@workflow/core/capabilities.d.ts +45 -0
- package/dist/src/compiled/@workflow/core/capture-stack.d.ts +16 -0
- package/dist/src/compiled/@workflow/core/class-serialization.d.ts +31 -0
- package/dist/src/compiled/@workflow/core/classify-error.d.ts +19 -0
- package/dist/src/compiled/@workflow/core/context-errors.d.ts +27 -0
- package/dist/src/compiled/@workflow/core/context-violation-error.d.ts +97 -0
- package/dist/src/compiled/@workflow/core/create-hook.d.ts +179 -0
- package/dist/src/compiled/@workflow/core/define-hook.d.ts +68 -0
- package/dist/src/compiled/@workflow/core/describe-error.d.ts +70 -0
- package/dist/src/compiled/@workflow/core/encryption.d.ts +45 -0
- package/dist/src/compiled/@workflow/core/events-consumer.d.ts +64 -0
- package/dist/src/compiled/@workflow/core/flushable-stream.d.ts +82 -0
- package/dist/src/compiled/@workflow/core/global.d.ts +48 -0
- package/dist/src/compiled/@workflow/core/index.d.ts +19 -38
- package/dist/src/compiled/@workflow/core/log-format.d.ts +25 -0
- package/dist/src/compiled/@workflow/core/logger.d.ts +29 -0
- package/dist/src/compiled/@workflow/core/private.d.ts +59 -10
- package/dist/src/compiled/@workflow/core/runtime/constants.d.ts +4 -0
- package/dist/src/compiled/@workflow/core/runtime/get-port-lazy.d.ts +10 -0
- package/dist/src/compiled/@workflow/core/runtime/get-world-lazy.d.ts +32 -0
- package/dist/src/compiled/@workflow/core/runtime/helpers.d.ts +97 -0
- package/dist/src/compiled/@workflow/core/runtime/resume-hook.d.ts +77 -0
- package/dist/src/compiled/@workflow/core/runtime/run.d.ts +134 -0
- package/dist/src/compiled/@workflow/core/runtime/runs.d.ts +50 -0
- package/dist/src/compiled/@workflow/core/runtime/start.d.ts +59 -0
- package/dist/src/compiled/@workflow/core/runtime/step-executor.d.ts +40 -0
- package/dist/src/compiled/@workflow/core/runtime/step-handler.d.ts +2 -0
- package/dist/src/compiled/@workflow/core/runtime/suspension-handler.d.ts +42 -0
- package/dist/src/compiled/@workflow/core/runtime/world-init.d.ts +75 -0
- package/dist/src/compiled/@workflow/core/runtime/world.d.ts +32 -0
- package/dist/src/compiled/@workflow/core/runtime.d.ts +22 -67
- package/dist/src/compiled/@workflow/core/schemas.d.ts +15 -0
- package/dist/src/compiled/@workflow/core/serialization/client.d.ts +17 -0
- package/dist/src/compiled/@workflow/core/serialization/codec-devalue.d.ts +14 -0
- package/dist/src/compiled/@workflow/core/serialization/codec.d.ts +90 -0
- package/dist/src/compiled/@workflow/core/serialization/encryption.d.ts +32 -0
- package/dist/src/compiled/@workflow/core/serialization/errors.d.ts +21 -0
- package/dist/src/compiled/@workflow/core/serialization/format.d.ts +60 -0
- package/dist/src/compiled/@workflow/core/serialization/index.d.ts +18 -0
- package/dist/src/compiled/@workflow/core/serialization/reducers/class.d.ts +11 -0
- package/dist/src/compiled/@workflow/core/serialization/reducers/common.d.ts +16 -0
- package/dist/src/compiled/@workflow/core/serialization/reducers/step-function.d.ts +35 -0
- package/dist/src/compiled/@workflow/core/serialization/step.d.ts +17 -0
- package/dist/src/compiled/@workflow/core/serialization/types.d.ts +201 -0
- package/dist/src/compiled/@workflow/core/serialization/workflow.d.ts +29 -0
- package/dist/src/compiled/@workflow/core/serialization-format.d.ts +171 -0
- package/dist/src/compiled/@workflow/core/serialization.d.ts +329 -0
- package/dist/src/compiled/@workflow/core/sleep.d.ts +33 -0
- package/dist/src/compiled/@workflow/core/source-map.d.ts +10 -0
- package/dist/src/compiled/@workflow/core/step/context-storage.d.ts +13 -0
- package/dist/src/compiled/@workflow/core/step/get-closure-vars.d.ts +9 -0
- package/dist/src/compiled/@workflow/core/step/get-step-metadata.d.ts +42 -0
- package/dist/src/compiled/@workflow/core/step/get-workflow-metadata.d.ts +7 -0
- package/dist/src/compiled/@workflow/core/step/writable-stream.d.ts +22 -0
- package/dist/src/compiled/@workflow/core/step.d.ts +4 -0
- package/dist/src/compiled/@workflow/core/symbols.d.ts +20 -0
- package/dist/src/compiled/@workflow/core/telemetry/semantic-conventions.d.ts +283 -0
- package/dist/src/compiled/@workflow/core/telemetry.d.ts +53 -0
- package/dist/src/compiled/@workflow/core/types.d.ts +14 -0
- package/dist/src/compiled/@workflow/core/util.d.ts +40 -0
- package/dist/src/compiled/@workflow/core/version.d.ts +2 -0
- package/dist/src/compiled/@workflow/core/vm/index.d.ts +17 -0
- package/dist/src/compiled/@workflow/core/vm/uint8array-base64.d.ts +21 -0
- package/dist/src/compiled/@workflow/core/vm/uuid.d.ts +10 -0
- package/dist/src/compiled/@workflow/core/workflow/abort-controller.d.ts +65 -0
- package/dist/src/compiled/@workflow/core/workflow/create-hook.d.ts +7 -0
- package/dist/src/compiled/@workflow/core/workflow/define-hook.d.ts +10 -0
- package/dist/src/compiled/@workflow/core/workflow/get-workflow-metadata.d.ts +32 -0
- package/dist/src/compiled/@workflow/core/workflow/hook.d.ts +4 -0
- package/dist/src/compiled/@workflow/core/workflow/index.d.ts +11 -0
- package/dist/src/compiled/@workflow/core/workflow/sleep.d.ts +4 -0
- package/dist/src/compiled/@workflow/core/workflow/world-init-stub.d.ts +15 -0
- package/dist/src/compiled/@workflow/core/workflow/writable-stream.d.ts +3 -0
- package/dist/src/compiled/@workflow/core/workflow.d.ts +1 -38
- package/dist/src/evals/cli/eval.js +1 -1
- package/dist/src/execution/sandbox/bindings/vercel.d.ts +1 -1
- package/dist/src/execution/sandbox/bindings/vercel.js +38 -6
- package/dist/src/internal/application/package.js +1 -1
- package/dist/src/internal/nitro/host/build-application.js +14 -12
- package/dist/src/internal/workflow-bundle/ash-service-route-output.d.ts +4 -0
- package/dist/src/internal/workflow-bundle/ash-service-route-output.js +134 -0
- package/dist/src/internal/workflow-bundle/vercel-workflow-output.d.ts +3 -1
- package/dist/src/internal/workflow-bundle/vercel-workflow-output.js +8 -23
- package/dist/src/protocol/message.d.ts +6 -1
- package/dist/src/public/channels/ash.js +50 -3
- package/dist/src/public/context/index.d.ts +4 -7
- package/dist/src/public/context/index.js +4 -5
- package/dist/src/public/definitions/state.d.ts +33 -0
- package/dist/src/public/definitions/state.js +34 -0
- package/dist/src/public/next/index.d.ts +7 -0
- package/dist/src/public/next/index.js +9 -2
- package/dist/src/public/next/vercel-json.d.ts +1 -0
- package/dist/src/public/next/vercel-json.js +1 -0
- package/dist/src/public/sandbox/backends/vercel.d.ts +7 -0
- package/dist/src/public/sandbox/backends/vercel.js +7 -0
- package/dist/src/public/sandbox/vercel-sandbox.d.ts +14 -4
- package/dist/src/react/index.d.ts +1 -1
- package/dist/src/react/use-ash-agent.d.ts +8 -0
- package/dist/src/react/use-ash-agent.js +26 -4
- package/dist/src/services/dev-client.d.ts +4 -1
- package/dist/src/services/dev-client.js +1 -0
- package/package.json +1 -1
- package/dist/src/chunks/paths-DxgjK2PI.js +0 -88
|
@@ -185,6 +185,9 @@ function createHandleMessageBody(input) {
|
|
|
185
185
|
if (input.input.inputResponses !== undefined && input.input.inputResponses.length > 0) {
|
|
186
186
|
body.inputResponses = input.input.inputResponses;
|
|
187
187
|
}
|
|
188
|
+
if (input.input.clientContext !== undefined) {
|
|
189
|
+
body.clientContext = input.input.clientContext;
|
|
190
|
+
}
|
|
188
191
|
if (input.session.continuationToken !== undefined) {
|
|
189
192
|
body.continuationToken = input.session.continuationToken;
|
|
190
193
|
}
|
|
@@ -194,6 +197,11 @@ function createHandleMessageBody(input) {
|
|
|
194
197
|
if (input.session.continuationToken === undefined && body.message === undefined) {
|
|
195
198
|
return null;
|
|
196
199
|
}
|
|
200
|
+
if (input.session.continuationToken !== undefined &&
|
|
201
|
+
body.message === undefined &&
|
|
202
|
+
body.inputResponses === undefined) {
|
|
203
|
+
return null;
|
|
204
|
+
}
|
|
197
205
|
if ("continuationToken" in body && Object.keys(body).length === 1) {
|
|
198
206
|
return null;
|
|
199
207
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import type { UserContent } from "ai";
|
|
1
2
|
import type { HandleMessageStreamEvent } from "#protocol/message.js";
|
|
2
3
|
import type { InputResponse } from "#runtime/input/types.js";
|
|
4
|
+
import type { JsonObject } from "#shared/json.js";
|
|
3
5
|
/**
|
|
4
6
|
* Static credential value or per-request credential resolver.
|
|
5
7
|
*/
|
|
@@ -66,6 +68,15 @@ export interface SendMessageOptions {
|
|
|
66
68
|
* Input payload for {@link Session.send}.
|
|
67
69
|
*/
|
|
68
70
|
export interface SendTurnInput {
|
|
71
|
+
/**
|
|
72
|
+
* Ephemeral client/page context for the next model call only.
|
|
73
|
+
*
|
|
74
|
+
* Strings are rendered as user-role model context messages. Objects are
|
|
75
|
+
* JSON-serialized into one user-role model context message. Client context
|
|
76
|
+
* piggybacks on a message or HITL response; it does not dispatch a turn by
|
|
77
|
+
* itself and is never persisted to durable session history.
|
|
78
|
+
*/
|
|
79
|
+
readonly clientContext?: string | readonly string[] | JsonObject;
|
|
69
80
|
/**
|
|
70
81
|
* HITL responses resolving pending approvals or questions.
|
|
71
82
|
*/
|
|
@@ -73,7 +84,7 @@ export interface SendTurnInput {
|
|
|
73
84
|
/**
|
|
74
85
|
* Optional follow-up user message for the same turn.
|
|
75
86
|
*/
|
|
76
|
-
readonly message?: string;
|
|
87
|
+
readonly message?: string | UserContent;
|
|
77
88
|
}
|
|
78
89
|
/**
|
|
79
90
|
* Options for {@link ClientSession.openStream}.
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// Auto-generated stub for `@workflow/utils` types referenced by a vendored .d.ts.
|
|
2
|
+
// Emitted by scripts/vendor-compiled/@workflow/core.mjs.
|
|
3
|
+
|
|
4
|
+
export interface PromiseWithResolvers<T = unknown> {
|
|
5
|
+
promise: Promise<T>;
|
|
6
|
+
resolve(value: T | PromiseLike<T>): void;
|
|
7
|
+
reject(reason?: unknown): void;
|
|
8
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// Auto-generated stub for `@workflow/world` types referenced by a vendored .d.ts.
|
|
2
|
+
// Emitted by scripts/vendor-compiled/@workflow/core.mjs.
|
|
3
|
+
|
|
4
|
+
type JsonishRecord = Record<string, any>;
|
|
5
|
+
type PaginatedResponse<T> = { cursor?: string | null; data: T[]; hasMore?: boolean };
|
|
6
|
+
|
|
7
|
+
export interface Event extends JsonishRecord {
|
|
8
|
+
correlationId?: string | null;
|
|
9
|
+
eventType?: string;
|
|
10
|
+
}
|
|
11
|
+
export type HealthCheckPayload = JsonishRecord;
|
|
12
|
+
export interface Hook extends JsonishRecord {
|
|
13
|
+
hookId: string;
|
|
14
|
+
token: string;
|
|
15
|
+
}
|
|
16
|
+
export type ValidQueueName = string;
|
|
17
|
+
export interface WorkflowRun extends JsonishRecord {
|
|
18
|
+
runId: string;
|
|
19
|
+
status: WorkflowRunStatus;
|
|
20
|
+
}
|
|
21
|
+
export type WorkflowRunStatus = "pending" | "running" | "completed" | "failed" | "cancelled";
|
|
22
|
+
export interface World {
|
|
23
|
+
specVersion?: number;
|
|
24
|
+
createQueueHandler?: any;
|
|
25
|
+
queue(...args: any[]): Promise<void>;
|
|
26
|
+
runs: {
|
|
27
|
+
get(id: string, params?: JsonishRecord): Promise<WorkflowRun>;
|
|
28
|
+
list(params?: JsonishRecord): Promise<PaginatedResponse<WorkflowRun>>;
|
|
29
|
+
};
|
|
30
|
+
steps: {
|
|
31
|
+
get(runId: string, stepId: string, params?: JsonishRecord): Promise<any>;
|
|
32
|
+
list(params: JsonishRecord): Promise<PaginatedResponse<any>>;
|
|
33
|
+
};
|
|
34
|
+
events: {
|
|
35
|
+
create(...args: any[]): Promise<any>;
|
|
36
|
+
get(runId: string, eventId: string, params?: JsonishRecord): Promise<Event>;
|
|
37
|
+
list(params: JsonishRecord): Promise<PaginatedResponse<Event>>;
|
|
38
|
+
listByCorrelationId(params: JsonishRecord): Promise<PaginatedResponse<Event>>;
|
|
39
|
+
};
|
|
40
|
+
hooks: {
|
|
41
|
+
get(hookId: string, params?: JsonishRecord): Promise<Hook>;
|
|
42
|
+
getByToken(token: string, params?: JsonishRecord): Promise<Hook>;
|
|
43
|
+
list(params: JsonishRecord): Promise<PaginatedResponse<Hook>>;
|
|
44
|
+
};
|
|
45
|
+
streams: {
|
|
46
|
+
write(runId: string, name: string, chunk: string | Uint8Array): Promise<void>;
|
|
47
|
+
writeMulti?(runId: string, name: string, chunks: (string | Uint8Array)[]): Promise<void>;
|
|
48
|
+
close(runId: string, name: string): Promise<void>;
|
|
49
|
+
get(runId: string, name: string, startIndex?: number): Promise<ReadableStream<Uint8Array>>;
|
|
50
|
+
list(runId: string): Promise<string[]>;
|
|
51
|
+
getChunks(runId: string, name: string, options?: JsonishRecord): Promise<any>;
|
|
52
|
+
getInfo(runId: string, name: string): Promise<any>;
|
|
53
|
+
};
|
|
54
|
+
getEncryptionKeyForRun?(run: WorkflowRun): Promise<Uint8Array | undefined>;
|
|
55
|
+
getEncryptionKeyForRun?(runId: string, context?: JsonishRecord): Promise<Uint8Array | undefined>;
|
|
56
|
+
resolveLatestDeploymentId?(): Promise<string>;
|
|
57
|
+
start?(): Promise<void>;
|
|
58
|
+
close?(): Promise<void>;
|
|
59
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Capabilities table for workflow runs based on their `@workflow/core` version.
|
|
3
|
+
*
|
|
4
|
+
* When resuming a hook or webhook, the payload must be encoded in a format
|
|
5
|
+
* that the *target* workflow run's deployment can decode. This module provides
|
|
6
|
+
* a way to look up what serialization formats a given `@workflow/core` version
|
|
7
|
+
* supports, so that newer deployments can avoid encoding payloads in formats
|
|
8
|
+
* that older deployments don't understand (e.g., the `encr` encryption format).
|
|
9
|
+
*
|
|
10
|
+
* ## Adding a new format
|
|
11
|
+
*
|
|
12
|
+
* When a new serialization format is introduced:
|
|
13
|
+
* 1. Add the format constant to `SerializationFormat` in `serialization.ts`
|
|
14
|
+
* 2. Add an entry to `FORMAT_VERSION_TABLE` below with the minimum
|
|
15
|
+
* `@workflow/core` version that supports it
|
|
16
|
+
* 3. The `getRunCapabilities()` function will automatically include it
|
|
17
|
+
*
|
|
18
|
+
* ## History
|
|
19
|
+
*
|
|
20
|
+
* - `encr` (AES-256-GCM encryption): added in `4.2.0-beta.64`
|
|
21
|
+
* Commit: 7618ac36 "Wire AES-GCM encryption into serialization layer (#1251)"
|
|
22
|
+
* https://github.com/vercel/workflow/commit/7618ac36
|
|
23
|
+
*/
|
|
24
|
+
import { type SerializationFormatType } from './serialization.js';
|
|
25
|
+
/**
|
|
26
|
+
* Capabilities of a workflow run based on its `@workflow/core` version.
|
|
27
|
+
*/
|
|
28
|
+
export interface RunCapabilities {
|
|
29
|
+
/**
|
|
30
|
+
* The set of serialization format prefixes that the target run can decode.
|
|
31
|
+
* Use `supportedFormats.has(SerializationFormat.ENCRYPTED)` to check
|
|
32
|
+
* if encryption is supported, etc.
|
|
33
|
+
*/
|
|
34
|
+
supportedFormats: ReadonlySet<SerializationFormatType>;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Look up what serialization capabilities a workflow run supports based on
|
|
38
|
+
* its `@workflow/core` version string (from `executionContext.workflowCoreVersion`).
|
|
39
|
+
*
|
|
40
|
+
* When the version is `undefined`, not a string, or not a valid semver string
|
|
41
|
+
* (e.g. very old runs that predate the field, or corrupted metadata),
|
|
42
|
+
* we assume the most conservative capabilities (baseline formats only).
|
|
43
|
+
*/
|
|
44
|
+
export declare function getRunCapabilities(workflowCoreVersion: string | undefined): RunCapabilities;
|
|
45
|
+
//# sourceMappingURL=capabilities.d.ts.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* V8-only (Node, Bun, Chrome, Deno). Rewrites `err.stack` so the top frame is
|
|
3
|
+
* the caller of `stackStartFn` instead of the framework function that threw.
|
|
4
|
+
* Without this, terminal overlays (Next.js, Turbopack, VS Code) render the
|
|
5
|
+
* code frame at our `throw` site inside `@workflow/core`, which is useless
|
|
6
|
+
* to the user.
|
|
7
|
+
*
|
|
8
|
+
* No-op on engines that don't expose `Error.captureStackTrace` — the stack
|
|
9
|
+
* degrades gracefully to the default behavior.
|
|
10
|
+
*
|
|
11
|
+
* Kept in its own tiny module so callers that can't participate in the
|
|
12
|
+
* `context-errors.ts` ↔ `workflow/get-workflow-metadata.ts` import cycle can
|
|
13
|
+
* still pull in the helper without pulling in the full error classes.
|
|
14
|
+
*/
|
|
15
|
+
export declare function redirectStackToCaller(err: Error, stackStartFn: Function): void;
|
|
16
|
+
//# sourceMappingURL=capture-stack.d.ts.map
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Class serialization utilities.
|
|
3
|
+
*
|
|
4
|
+
* This module is separate from private.ts to avoid pulling in Node.js-only
|
|
5
|
+
* dependencies (like async_hooks via get-closure-vars.ts) when used in
|
|
6
|
+
* workflow bundles.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Register a class constructor for serialization.
|
|
10
|
+
* This allows class constructors to be deserialized by looking up the classId.
|
|
11
|
+
*
|
|
12
|
+
* Note: The SWC plugin now inlines equivalent registration logic as a
|
|
13
|
+
* self-contained IIFE (using the same globalThis Symbol-keyed registry),
|
|
14
|
+
* so this function is no longer imported by generated code. It is retained
|
|
15
|
+
* for programmatic use and testing.
|
|
16
|
+
*
|
|
17
|
+
* Also sets the `classId` property on the class so the serializer can find it
|
|
18
|
+
* when serializing instances (e.g., step return values).
|
|
19
|
+
*/
|
|
20
|
+
export declare function registerSerializationClass(classId: string, cls: Function): void;
|
|
21
|
+
/**
|
|
22
|
+
* Find a registered class constructor by ID (used during deserialization)
|
|
23
|
+
*
|
|
24
|
+
* @param classId - The class ID to look up
|
|
25
|
+
* @param global - The global object to check. This ensures workflow code running
|
|
26
|
+
* in a VM only accesses classes registered on the VM's global,
|
|
27
|
+
* matching production serverless behavior where workflow code
|
|
28
|
+
* runs in isolation.
|
|
29
|
+
*/
|
|
30
|
+
export declare function getSerializationClass(classId: string, global: Record<string, any>): Function | undefined;
|
|
31
|
+
//# sourceMappingURL=class-serialization.d.ts.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type RunErrorCode } from '#compiled/@workflow/errors/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Classify an error that caused a workflow run to fail.
|
|
4
|
+
*
|
|
5
|
+
* After the structural separation of infrastructure vs user code error
|
|
6
|
+
* handling, the only errors that reach the `run_failed` try/catch are:
|
|
7
|
+
* - User code errors (throws from workflow functions, propagated step failures)
|
|
8
|
+
* - WorkflowRuntimeError and subclasses (corrupted event log, missing
|
|
9
|
+
* timestamps, workflow/step not registered, etc.)
|
|
10
|
+
*
|
|
11
|
+
* Uses each subclass's `.is()` static (a name-based duck check) instead of
|
|
12
|
+
* a single `instanceof` check because workflows execute in a separate
|
|
13
|
+
* `vm` realm: the VM-context `WorkflowRuntimeError` and the host-context
|
|
14
|
+
* one are distinct classes, so `instanceof` returns `false` for any error
|
|
15
|
+
* thrown inside the workflow VM and we'd misclassify genuine runtime
|
|
16
|
+
* errors as user errors.
|
|
17
|
+
*/
|
|
18
|
+
export declare function classifyRunError(err: unknown): RunErrorCode;
|
|
19
|
+
//# sourceMappingURL=classify-error.d.ts.map
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { ContextViolationError, type DocsUrl, NotInStepContextError, NotInWorkflowContextError, NotInWorkflowOrStepContextError } from './context-violation-error.js';
|
|
2
|
+
export { ContextViolationError, NotInStepContextError, NotInWorkflowContextError, NotInWorkflowOrStepContextError, };
|
|
3
|
+
/**
|
|
4
|
+
* Thrown when an API that MUST NOT run inside a workflow function is called
|
|
5
|
+
* from one (e.g. `resumeHook()`, which would cause determinism issues).
|
|
6
|
+
* The message names the specific workflow that made the offending call.
|
|
7
|
+
*/
|
|
8
|
+
export declare class UnavailableInWorkflowContextError extends ContextViolationError {
|
|
9
|
+
name: string;
|
|
10
|
+
constructor(functionName: string, docsUrl: DocsUrl);
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Throw a {@link NotInWorkflowContextError} whose stack trace points at the
|
|
14
|
+
* user code that called `stackStartFn`, not at our framework internals.
|
|
15
|
+
*
|
|
16
|
+
* Prefer this over `throw new NotInWorkflowContextError(...)` so tooling
|
|
17
|
+
* (Next.js error overlay, VS Code terminal linkifier, Sentry, etc.) shows
|
|
18
|
+
* the user's call site as the relevant frame.
|
|
19
|
+
*/
|
|
20
|
+
export declare function throwNotInWorkflowContext(functionName: string, docsUrl: DocsUrl, stackStartFn: Function): never;
|
|
21
|
+
/** See {@link throwNotInWorkflowContext}. */
|
|
22
|
+
export declare function throwNotInStepContext(functionName: string, docsUrl: DocsUrl, stackStartFn: Function): never;
|
|
23
|
+
/** See {@link throwNotInWorkflowContext}. */
|
|
24
|
+
export declare function throwNotInWorkflowOrStepContext(functionName: string, docsUrl: DocsUrl, stackStartFn: Function): never;
|
|
25
|
+
/** See {@link throwNotInWorkflowContext}. */
|
|
26
|
+
export declare function throwUnavailableInWorkflowContext(functionName: string, docsUrl: DocsUrl, stackStartFn: Function): never;
|
|
27
|
+
//# sourceMappingURL=context-errors.d.ts.map
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A `docs:` line URL. The leading protocol is part of the type so call sites
|
|
3
|
+
* can't accidentally pass a protocol-relative or bare path.
|
|
4
|
+
*/
|
|
5
|
+
export type DocsUrl = `https://${string}`;
|
|
6
|
+
declare const INSPECT_CUSTOM: unique symbol;
|
|
7
|
+
/**
|
|
8
|
+
* Structured data for a framed error. The base class takes this and renders
|
|
9
|
+
* it to plain text (for `.message` / `.stack` / structured logs) or to an
|
|
10
|
+
* ANSI-framed string (for terminal display via `util.inspect` / `toString`).
|
|
11
|
+
*
|
|
12
|
+
* Keeping the pieces structured means we never have to strip ANSI back out
|
|
13
|
+
* once it's in the message — we just don't put it there in the first place.
|
|
14
|
+
*/
|
|
15
|
+
export interface FramedContent {
|
|
16
|
+
/** Headline. `{ code: 'foo()' }` segments render as backticked inline code. */
|
|
17
|
+
readonly title: readonly Segment[];
|
|
18
|
+
/** One framed branch per entry. The last uses `╰▶`, others use `├▶`. */
|
|
19
|
+
readonly details: readonly Detail[];
|
|
20
|
+
}
|
|
21
|
+
export type Segment = {
|
|
22
|
+
readonly text: string;
|
|
23
|
+
} | {
|
|
24
|
+
readonly code: string;
|
|
25
|
+
} | {
|
|
26
|
+
readonly dim: string;
|
|
27
|
+
};
|
|
28
|
+
export type Detail = {
|
|
29
|
+
readonly type: 'plain';
|
|
30
|
+
readonly segments: readonly Segment[];
|
|
31
|
+
} | {
|
|
32
|
+
readonly type: 'docs';
|
|
33
|
+
readonly url: DocsUrl;
|
|
34
|
+
};
|
|
35
|
+
export declare function renderPlain(c: FramedContent): string;
|
|
36
|
+
export declare function renderPretty(c: FramedContent): string;
|
|
37
|
+
/**
|
|
38
|
+
* Base class for structured context-violation errors.
|
|
39
|
+
*
|
|
40
|
+
* Design notes:
|
|
41
|
+
*
|
|
42
|
+
* - `.message` is **plain text** (no ANSI escape bytes). Structured logs,
|
|
43
|
+
* log drains, CBOR-serialized event data, and anything else that reads
|
|
44
|
+
* `err.message` / `err.stack` as a string gets clean output — no mojibake
|
|
45
|
+
* in JSON, no `\x1B[...m` noise in Vercel logs.
|
|
46
|
+
*
|
|
47
|
+
* - The ANSI-framed version is rendered **lazily** via `toString()` and
|
|
48
|
+
* `[util.inspect.custom]`. When the error is thrown and Node prints it
|
|
49
|
+
* via `util.inspect`, the user sees the colored, framed box. When it's
|
|
50
|
+
* attached to a structured log field, the consumer sees plain text.
|
|
51
|
+
*
|
|
52
|
+
* - `fatal = true` marks these as non-retryable. Calling `createHook()`
|
|
53
|
+
* from a step function will never succeed no matter how many retries —
|
|
54
|
+
* burning attempts just produces duplicated log output. The runtime's
|
|
55
|
+
* `FatalError.is(err)` gate recognizes any error with `fatal: true`.
|
|
56
|
+
*/
|
|
57
|
+
export declare abstract class ContextViolationError extends Error {
|
|
58
|
+
#private;
|
|
59
|
+
/** Non-retryable — see class doc. */
|
|
60
|
+
readonly fatal = true;
|
|
61
|
+
constructor(content: FramedContent);
|
|
62
|
+
/**
|
|
63
|
+
* `console.log(err)` and most Node internals route through `util.inspect`,
|
|
64
|
+
* which respects this symbol. Returning a custom string here means the
|
|
65
|
+
* thrown error prints as a pretty frame in the terminal while `.message`
|
|
66
|
+
* and `.stack` stay plain.
|
|
67
|
+
*/
|
|
68
|
+
[INSPECT_CUSTOM](): string;
|
|
69
|
+
toString(): string;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Thrown when an API that must run inside a workflow function is called
|
|
73
|
+
* from outside a workflow context (e.g. from a step function or from
|
|
74
|
+
* regular application code).
|
|
75
|
+
*/
|
|
76
|
+
export declare class NotInWorkflowContextError extends ContextViolationError {
|
|
77
|
+
name: string;
|
|
78
|
+
constructor(functionName: string, docsUrl: DocsUrl);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Thrown when an API that must run inside a step function is called from
|
|
82
|
+
* outside a step context.
|
|
83
|
+
*/
|
|
84
|
+
export declare class NotInStepContextError extends ContextViolationError {
|
|
85
|
+
name: string;
|
|
86
|
+
constructor(functionName: string, docsUrl: DocsUrl);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Thrown when an API that must run inside either a workflow or step function
|
|
90
|
+
* is called from regular application code.
|
|
91
|
+
*/
|
|
92
|
+
export declare class NotInWorkflowOrStepContextError extends ContextViolationError {
|
|
93
|
+
name: string;
|
|
94
|
+
constructor(functionName: string, docsUrl: DocsUrl);
|
|
95
|
+
}
|
|
96
|
+
export {};
|
|
97
|
+
//# sourceMappingURL=context-violation-error.d.ts.map
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import type { Serializable } from './schemas.js';
|
|
2
|
+
/**
|
|
3
|
+
* An object that can be awaited to receive a value.
|
|
4
|
+
*/
|
|
5
|
+
interface Thenable<T> {
|
|
6
|
+
then: Promise<T>['then'];
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* A `Request` that can be responded to within a workflow
|
|
10
|
+
* step function by calling the `respondWith()` method.
|
|
11
|
+
*/
|
|
12
|
+
export interface RequestWithResponse extends Request {
|
|
13
|
+
respondWith: (response: Response) => Promise<void>;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* A hook that can be awaited and/or iterated over to receive
|
|
17
|
+
* a value within a workflow from an external system.
|
|
18
|
+
*
|
|
19
|
+
* Hooks implement the TC39 Explicit Resource Management proposal,
|
|
20
|
+
* allowing them to be used with the `using` keyword for automatic disposal.
|
|
21
|
+
*/
|
|
22
|
+
export interface Hook<T = any> extends AsyncIterable<T>, Thenable<T> {
|
|
23
|
+
/**
|
|
24
|
+
* The token used to identify this hook.
|
|
25
|
+
*/
|
|
26
|
+
token: string;
|
|
27
|
+
/**
|
|
28
|
+
* Disposes the hook, releasing its token for reuse by other workflows.
|
|
29
|
+
*
|
|
30
|
+
* After calling `dispose()`, the hook will no longer receive any events.
|
|
31
|
+
* This is useful when you want to explicitly release a hook token before
|
|
32
|
+
* the workflow completes, allowing another workflow to register a hook
|
|
33
|
+
* with the same token.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```ts
|
|
37
|
+
* const hook = createHook<{ message: string }>({ token: 'my-token' });
|
|
38
|
+
*
|
|
39
|
+
* for await (const payload of hook) {
|
|
40
|
+
* if (payload.message === 'done') {
|
|
41
|
+
* hook.dispose(); // Release the token early
|
|
42
|
+
* break;
|
|
43
|
+
* }
|
|
44
|
+
* }
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
dispose(): void;
|
|
48
|
+
/**
|
|
49
|
+
* Implements the TC39 Explicit Resource Management proposal.
|
|
50
|
+
* Called automatically when using the `using` keyword.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```ts
|
|
54
|
+
* {
|
|
55
|
+
* using hook = createHook<{ message: string }>({ token: 'my-token' });
|
|
56
|
+
* const payload = await hook;
|
|
57
|
+
* // hook is automatically disposed when the block exits
|
|
58
|
+
* }
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
[Symbol.dispose](): void;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* A webhook that can be used to suspend and resume the workflow run
|
|
65
|
+
* upon receiving an HTTP request to the specified URL.
|
|
66
|
+
*
|
|
67
|
+
* @see {@link createWebhook}
|
|
68
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Request
|
|
69
|
+
*/
|
|
70
|
+
export interface Webhook<T extends Request> extends Hook<T> {
|
|
71
|
+
/**
|
|
72
|
+
* The URL that external systems can call to send data to the workflow.
|
|
73
|
+
*/
|
|
74
|
+
url: string;
|
|
75
|
+
}
|
|
76
|
+
export interface HookOptions {
|
|
77
|
+
/**
|
|
78
|
+
* Unique token that is used to associate with the hook.
|
|
79
|
+
*
|
|
80
|
+
* When specifying an explicit token, the token should be constructed
|
|
81
|
+
* with information that the dispatching side can reliably reconstruct
|
|
82
|
+
* the token with the information it has available.
|
|
83
|
+
*
|
|
84
|
+
* Deterministic tokens are intended for use with `createHook()` and
|
|
85
|
+
* server-side `resumeHook()` only. For webhooks (`createWebhook()`),
|
|
86
|
+
* tokens are always randomly generated to prevent unauthorized access
|
|
87
|
+
* to the public webhook endpoint.
|
|
88
|
+
*
|
|
89
|
+
* If not provided, a randomly generated token will be assigned.
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
*
|
|
93
|
+
* ```ts
|
|
94
|
+
* // Explicit token for a Slack bot (one workflow run per channel)
|
|
95
|
+
* const hook = createHook<SlackMessage>({
|
|
96
|
+
* token: `slack_webhook:${channelId}`,
|
|
97
|
+
* });
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
token?: string;
|
|
101
|
+
/**
|
|
102
|
+
* Additional user-defined data to include with the hook payload.
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
*
|
|
106
|
+
* ```ts
|
|
107
|
+
* const hook = createHook<{ name: string }>({
|
|
108
|
+
* metadata: {
|
|
109
|
+
* type: "cat",
|
|
110
|
+
* color: "orange",
|
|
111
|
+
* },
|
|
112
|
+
* });
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
115
|
+
metadata?: Serializable;
|
|
116
|
+
/**
|
|
117
|
+
* Whether this hook can be resumed via the public webhook endpoint.
|
|
118
|
+
*
|
|
119
|
+
* When `true`, the hook can be triggered by sending an HTTP request to the
|
|
120
|
+
* public `/.well-known/workflow/v1/webhook/{token}` URL. This is automatically
|
|
121
|
+
* set when using `createWebhook()`.
|
|
122
|
+
*
|
|
123
|
+
* When `false` (the default), the hook can only be resumed server-side
|
|
124
|
+
* via `resumeHook()`.
|
|
125
|
+
*
|
|
126
|
+
* @default false
|
|
127
|
+
*/
|
|
128
|
+
isWebhook?: boolean;
|
|
129
|
+
}
|
|
130
|
+
export interface WebhookOptions extends Omit<HookOptions, 'token' | 'isWebhook'> {
|
|
131
|
+
/**
|
|
132
|
+
* If set to a `Response` object, the webhook will automatically
|
|
133
|
+
* respond with the specified response.
|
|
134
|
+
*
|
|
135
|
+
* If set to `"manual"`, each individual request will need to
|
|
136
|
+
* be responded to manually from within the workflow by calling the
|
|
137
|
+
* `respondWith()` method.
|
|
138
|
+
*
|
|
139
|
+
* If not set then the webhook will automatically respond with
|
|
140
|
+
* a `202 Accepted` response.
|
|
141
|
+
*/
|
|
142
|
+
respondWith?: Response | 'manual';
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Creates a {@link Hook} that can be used to suspend and resume the workflow run with a payload.
|
|
146
|
+
*
|
|
147
|
+
* Hooks allow external systems to send arbitrary serializable data into a workflow.
|
|
148
|
+
*
|
|
149
|
+
* @param options - Configuration options for the hook.
|
|
150
|
+
* @returns A `Hook` that can be awaited to receive one or more payloads.
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
*
|
|
154
|
+
* ```ts
|
|
155
|
+
* export async function workflowWithHook() {
|
|
156
|
+
* "use workflow";
|
|
157
|
+
*
|
|
158
|
+
* const hook = createHook<{ message: string }>();
|
|
159
|
+
* console.log('Hook token:', hook.token);
|
|
160
|
+
*
|
|
161
|
+
* const payload = await hook;
|
|
162
|
+
* console.log('Received:', payload.message);
|
|
163
|
+
* }
|
|
164
|
+
* ```
|
|
165
|
+
*/
|
|
166
|
+
export declare function createHook<T = any>(options?: HookOptions): Hook<T>;
|
|
167
|
+
/**
|
|
168
|
+
* Creates a {@link Webhook} that can be used to suspend and resume the workflow
|
|
169
|
+
* run upon receiving an HTTP request to the specified URL.
|
|
170
|
+
*
|
|
171
|
+
* Webhooks will result in a {@link https://developer.mozilla.org/en-US/docs/Web/API/Request | Request} object
|
|
172
|
+
* that can be interacted with in workflow functions.
|
|
173
|
+
*/
|
|
174
|
+
export declare function createWebhook(options: WebhookOptions & {
|
|
175
|
+
respondWith: 'manual';
|
|
176
|
+
}): Webhook<RequestWithResponse>;
|
|
177
|
+
export declare function createWebhook(options?: WebhookOptions): Webhook<Request>;
|
|
178
|
+
export {};
|
|
179
|
+
//# sourceMappingURL=create-hook.d.ts.map
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { StandardSchemaV1 } from '#compiled/@standard-schema/spec/index.js';
|
|
2
|
+
import type { Hook as HookEntity } from './_workflow-world.js';
|
|
3
|
+
import type { Hook, HookOptions } from './create-hook.js';
|
|
4
|
+
/**
|
|
5
|
+
* A typed hook interface for type-safe hook creation and resumption.
|
|
6
|
+
*/
|
|
7
|
+
export interface TypedHook<TInput, TOutput> {
|
|
8
|
+
/**
|
|
9
|
+
* Creates a new hook with the defined output type.
|
|
10
|
+
*
|
|
11
|
+
* Note: This method is not available in runtime bundles. Use it from workflow contexts only.
|
|
12
|
+
*
|
|
13
|
+
* @param options - Optional hook configuration
|
|
14
|
+
* @returns A Hook that resolves to the defined output type
|
|
15
|
+
*/
|
|
16
|
+
create(options?: HookOptions): Hook<TOutput>;
|
|
17
|
+
/**
|
|
18
|
+
* Resumes a hook by sending a payload with the defined input type.
|
|
19
|
+
* This is a type-safe wrapper around the `resumeHook` runtime function.
|
|
20
|
+
*
|
|
21
|
+
* @param token - The unique token identifying the hook
|
|
22
|
+
* @param payload - The payload to send; if a `schema` is configured it is validated/transformed before resuming
|
|
23
|
+
* @returns Promise resolving to the hook entity
|
|
24
|
+
* @throws Error if the hook is not found or if there's an error during the process
|
|
25
|
+
*/
|
|
26
|
+
resume(token: string, payload: TInput): Promise<HookEntity>;
|
|
27
|
+
}
|
|
28
|
+
export declare namespace TypedHook {
|
|
29
|
+
/**
|
|
30
|
+
* Extracts the input type from a {@link TypedHook}
|
|
31
|
+
*/
|
|
32
|
+
type Input<T extends TypedHook<any, any>> = T extends TypedHook<infer I, any> ? I : never;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Defines a typed hook for type-safe hook creation and resumption.
|
|
36
|
+
*
|
|
37
|
+
* This helper provides type safety by allowing you to define the input and output types
|
|
38
|
+
* for the hook's payload, with optional validation and transformation via a schema.
|
|
39
|
+
*
|
|
40
|
+
* @param schema - Schema used to validate and transform the input payload before resuming
|
|
41
|
+
* @returns An object with `create` and `resume` functions pre-typed with the input and output types
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
*
|
|
45
|
+
* ```ts
|
|
46
|
+
* // Define a hook with a specific payload type
|
|
47
|
+
* const approvalHook = defineHook<{ approved: boolean; comment: string }>();
|
|
48
|
+
*
|
|
49
|
+
* // In a workflow
|
|
50
|
+
* export async function workflowWithApproval() {
|
|
51
|
+
* "use workflow";
|
|
52
|
+
*
|
|
53
|
+
* const hook = approvalHook.create();
|
|
54
|
+
* const result = await hook; // Fully typed as { approved: boolean; comment: string; }
|
|
55
|
+
* }
|
|
56
|
+
*
|
|
57
|
+
* // In an API route
|
|
58
|
+
* export async function POST(request: Request) {
|
|
59
|
+
* const { token, approved, comment } = await request.json();
|
|
60
|
+
* await approvalHook.resume(token, { approved, comment }); // Input type
|
|
61
|
+
* return Response.json({ success: true });
|
|
62
|
+
* }
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
export declare function defineHook<TInput, TOutput = TInput>({ schema, }?: {
|
|
66
|
+
schema?: StandardSchemaV1<TInput, TOutput>;
|
|
67
|
+
}): TypedHook<TInput, TOutput>;
|
|
68
|
+
//# sourceMappingURL=define-hook.d.ts.map
|