experimental-ash 0.22.2 → 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 +14 -0
- package/dist/docs/public/faqs.md +67 -0
- package/dist/docs/public/meta.json +1 -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-BLzYWh05.js → dev-authored-source-watcher-d_35Mp8T.js} +1 -1
- package/dist/src/chunks/{host-DREC8e8Z.js → host-tji7W0Nn.js} +2 -2
- package/dist/src/chunks/paths-YoCQlavu.js +89 -0
- package/dist/src/chunks/{prewarm-hz8p2jlZ.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/internal/application/package.js +1 -1
- 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 +2 -0
- package/dist/src/public/next/vercel-json.d.ts +1 -0
- package/dist/src/public/next/vercel-json.js +1 -0
- 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-C6sp4T2U.js +0 -88
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Server-only side-effect module that ensures `world.ts` is loaded so its
|
|
3
|
+
* module-load side effect — `globalThis[GetWorldFnKey] ??= getWorld` —
|
|
4
|
+
* fires in host bundles.
|
|
5
|
+
*
|
|
6
|
+
* # Why this exists
|
|
7
|
+
*
|
|
8
|
+
* `getWorldLazy()` in `./get-world-lazy.ts` checks the globalThis cache
|
|
9
|
+
* (populated by `world.ts`'s module-load side effect) before falling back
|
|
10
|
+
* to a runtime-built dynamic `import('./world.js')`. When a server route
|
|
11
|
+
* only consumes a single helper that goes through `getWorldLazy` — most
|
|
12
|
+
* commonly `start` from `workflow/api` — webpack/turbopack tree-shake the
|
|
13
|
+
* named import `{ getWorld } from './runtime/world.js'` out of
|
|
14
|
+
* `runtime.ts`, taking `world.ts`'s module evaluation with it. The
|
|
15
|
+
* globalThis registration never fires.
|
|
16
|
+
*
|
|
17
|
+
* `getWorldLazy` then falls through to its dynamic-import fallback, which
|
|
18
|
+
* itself fails: webpack inlines `get-world-lazy.js` into the bundled route
|
|
19
|
+
* file, so the relative specifier `./world.js` resolves against
|
|
20
|
+
* `/var/task/<app>/.next/server/app/<...>/route.js` — where no sibling
|
|
21
|
+
* `world.js` exists — and Node throws `MODULE_NOT_FOUND`. The symptom is a
|
|
22
|
+
* cold-start regression: the very first user request that goes through
|
|
23
|
+
* `start()` fails until some other code path (typically the queue-driven
|
|
24
|
+
* `/.well-known/workflow/v1/flow` route, which uses `getWorld` directly
|
|
25
|
+
* via `workflowEntrypoint`) has loaded `world.ts` and populated the
|
|
26
|
+
* cache.
|
|
27
|
+
*
|
|
28
|
+
* Importing this module for its side effect — exactly once, from the
|
|
29
|
+
* host-side `workflow/api` (`packages/workflow/src/api.ts`) — guarantees
|
|
30
|
+
* `world.ts` enters the bundle, the global is registered at module load,
|
|
31
|
+
* and `getWorldLazy()` short-circuits to the registered function on the
|
|
32
|
+
* first call.
|
|
33
|
+
*
|
|
34
|
+
* # Why a separate module instead of importing `./world.js` directly
|
|
35
|
+
*
|
|
36
|
+
* `world.ts` is internal to `@workflow/core` and not part of the public
|
|
37
|
+
* exports surface. Adding a dedicated public init entry (this file)
|
|
38
|
+
* keeps the side-effect intent obvious to anyone reading
|
|
39
|
+
* `packages/workflow/src/api.ts`, and lets the `workflow` export
|
|
40
|
+
* condition route to a stub for VM/step bundles (see below).
|
|
41
|
+
*
|
|
42
|
+
* # Why this doesn't break VM/step bundles
|
|
43
|
+
*
|
|
44
|
+
* The `@workflow/core/runtime/world-init` export resolves via the
|
|
45
|
+
* `workflow` condition to `./dist/workflow/world-init-stub.js`, an empty
|
|
46
|
+
* module. Esbuild runs the workflow VM and step bundlers with the
|
|
47
|
+
* `workflow` condition active, so they pick up the stub and never reach
|
|
48
|
+
* `world.ts`. Host bundlers (webpack, turbopack, Node.js) use the
|
|
49
|
+
* `default` (or `node`) condition and pick up this file, loading
|
|
50
|
+
* `world.ts` as intended. The split keeps `@workflow/world-vercel`,
|
|
51
|
+
* `@workflow/world-local`, `cbor-x`, and other server-only deps out of
|
|
52
|
+
* the workflow sandbox bundle.
|
|
53
|
+
*
|
|
54
|
+
* # Why we keep the `getWorldLazy` dynamic-import fallback
|
|
55
|
+
*
|
|
56
|
+
* The fallback remains in `./get-world-lazy.ts` as a defense-in-depth for
|
|
57
|
+
* environments we haven't accounted for (CJS test runners, scripts that
|
|
58
|
+
* import `start` without going through `workflow/api`, future bundlers
|
|
59
|
+
* with stricter tree-shaking). With this init module in place, the
|
|
60
|
+
* fallback should never fire in normal use — but if it does, the
|
|
61
|
+
* dynamic-import branch still resolves correctly when `world.js` is
|
|
62
|
+
* physically adjacent on disk (e.g., direct Node.js execution of
|
|
63
|
+
* unbundled source).
|
|
64
|
+
*
|
|
65
|
+
* # Maintenance notes
|
|
66
|
+
*
|
|
67
|
+
* If you add another `getWorldLazy()` consumer that's reachable from a
|
|
68
|
+
* host route without going through `workflow/api` (e.g., a new helper in
|
|
69
|
+
* `workflow/runtime`), make sure that entry also imports this module —
|
|
70
|
+
* or that it transitively reaches `world.ts` via a non-tree-shakeable
|
|
71
|
+
* path. Adding a regression test in `world-init.test.ts` is preferred to
|
|
72
|
+
* relying on careful manual tracing.
|
|
73
|
+
*/
|
|
74
|
+
import './world.js';
|
|
75
|
+
//# sourceMappingURL=world-init.d.ts.map
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { World } from '../_workflow-world.js';
|
|
2
|
+
/**
|
|
3
|
+
* Create a new world instance based on environment variables.
|
|
4
|
+
* WORKFLOW_TARGET_WORLD is used to determine the target world.
|
|
5
|
+
*
|
|
6
|
+
* Note: WORKFLOW_VERCEL_* env vars (PROJECT, TEAM, AUTH_TOKEN, etc.) are
|
|
7
|
+
* intentionally NOT read here. Those are for CLI/observability tooling only
|
|
8
|
+
* and should not affect runtime behavior. The Vercel runtime provides
|
|
9
|
+
* authentication via OIDC tokens and project context via system env vars
|
|
10
|
+
* (VERCEL_DEPLOYMENT_ID, VERCEL_PROJECT_ID). Tooling that needs these env
|
|
11
|
+
* vars should call createVercelWorld() directly with an explicit config and
|
|
12
|
+
* use setWorld() to inject the instance.
|
|
13
|
+
*/
|
|
14
|
+
export declare const createWorld: () => Promise<World>;
|
|
15
|
+
export type WorldHandlers = Pick<World, 'createQueueHandler' | 'specVersion'>;
|
|
16
|
+
/**
|
|
17
|
+
* Some functions from the world are needed at build time, but we do NOT want
|
|
18
|
+
* to cache the world in those instances for general use, since we don't have
|
|
19
|
+
* the correct environment variables set yet. This is a safe function to
|
|
20
|
+
* call at build time, that only gives access to non-environment-bound world
|
|
21
|
+
* functions. The only binding value should be the target world.
|
|
22
|
+
* Once we migrate to a file-based configuration (workflow.config.ts), we should
|
|
23
|
+
* be able to re-combine getWorld and getWorldHandlers into one singleton.
|
|
24
|
+
*/
|
|
25
|
+
export declare const getWorldHandlers: () => Promise<WorldHandlers>;
|
|
26
|
+
export declare const getWorld: () => Promise<World>;
|
|
27
|
+
/**
|
|
28
|
+
* Reset the cached world instance. This should be called when environment
|
|
29
|
+
* variables change and you need to reinitialize the world with new config.
|
|
30
|
+
*/
|
|
31
|
+
export declare const setWorld: (world: World | undefined) => void;
|
|
32
|
+
//# sourceMappingURL=world.d.ts.map
|
|
@@ -1,67 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
export type WorkflowRun
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
export
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
export
|
|
22
|
-
|
|
23
|
-
get(params?: Record<string, any>, options?: Record<string, any>): Promise<any>;
|
|
24
|
-
list(
|
|
25
|
-
params?: Record<string, any>,
|
|
26
|
-
): Promise<{ cursor?: string | null; data: any[]; hasMore?: boolean }>;
|
|
27
|
-
}
|
|
28
|
-
export interface WorkflowWorld {
|
|
29
|
-
readonly events: WorkflowWorldCollection;
|
|
30
|
-
readonly hooks: WorkflowWorldCollection;
|
|
31
|
-
readonly runs: WorkflowWorldCollection;
|
|
32
|
-
readonly steps: WorkflowWorldCollection;
|
|
33
|
-
}
|
|
34
|
-
export declare class Run<T = any> {
|
|
35
|
-
readonly runId: string;
|
|
36
|
-
readonly readable: ReadableStream<Uint8Array>;
|
|
37
|
-
readonly returnValue: Promise<T>;
|
|
38
|
-
readonly status: Promise<string>;
|
|
39
|
-
cancel(): Promise<void>;
|
|
40
|
-
getReadable(options?: WorkflowReadableStreamOptions): ReadableStream<Uint8Array>;
|
|
41
|
-
}
|
|
42
|
-
export declare class WorkflowSuspension extends Error {}
|
|
43
|
-
export declare function cancelRun(...args: unknown[]): Promise<unknown>;
|
|
44
|
-
export declare function createWorld(...args: unknown[]): Promise<unknown>;
|
|
45
|
-
export declare function getHookByToken(...args: unknown[]): Promise<unknown>;
|
|
46
|
-
export declare function getRun<T = unknown>(runId: string): Run<T>;
|
|
47
|
-
export declare function getWorld(): Promise<WorkflowWorld>;
|
|
48
|
-
export declare function getWorldHandlers(): Promise<any>;
|
|
49
|
-
export declare function healthCheck(...args: unknown[]): Promise<HealthCheckResult>;
|
|
50
|
-
export declare function listStreams(...args: unknown[]): Promise<unknown>;
|
|
51
|
-
export declare function readStream<T = unknown>(
|
|
52
|
-
...args: unknown[]
|
|
53
|
-
): Promise<WorkflowReadableStream<T>>;
|
|
54
|
-
export declare function recreateRunFromExisting(...args: unknown[]): Promise<unknown>;
|
|
55
|
-
export declare function reenqueueRun(...args: unknown[]): Promise<unknown>;
|
|
56
|
-
export declare function resumeHook<T = unknown>(token: string, value?: T): Promise<void>;
|
|
57
|
-
export declare function resumeWebhook<T = unknown>(token: string, value?: T): Promise<Response>;
|
|
58
|
-
export declare function setWorld(world: unknown): void;
|
|
59
|
-
export declare function start<T = any>(
|
|
60
|
-
workflow: unknown,
|
|
61
|
-
args?: unknown[],
|
|
62
|
-
options?: StartOptions,
|
|
63
|
-
): Promise<Run<T>>;
|
|
64
|
-
export declare function wakeUpRun(...args: unknown[]): Promise<unknown>;
|
|
65
|
-
export declare function workflowEntrypoint(
|
|
66
|
-
workflowCode: string,
|
|
67
|
-
): (req: Request) => Promise<Response>;
|
|
1
|
+
import { type Event, type WorkflowRun } from './_workflow-world.js';
|
|
2
|
+
export type { Event, WorkflowRun };
|
|
3
|
+
export { WorkflowSuspension } from './global.js';
|
|
4
|
+
export { type HealthCheckEndpoint, type HealthCheckOptions, type HealthCheckResult, healthCheck, } from './runtime/helpers.js';
|
|
5
|
+
export { getHookByToken, resumeHook, resumeWebhook, } from './runtime/resume-hook.js';
|
|
6
|
+
export { getRun, Run, type WorkflowReadableStream, type WorkflowReadableStreamOptions, } from './runtime/run.js';
|
|
7
|
+
export { cancelRun, listStreams, type ReadStreamOptions, type RecreateRunOptions, readStream, recreateRunFromExisting, reenqueueRun, type StopSleepOptions, type StopSleepResult, wakeUpRun, } from './runtime/runs.js';
|
|
8
|
+
export { type StartOptions, type StartOptionsBase, type StartOptionsWithDeploymentId, type StartOptionsWithoutDeploymentId, start, } from './runtime/start.js';
|
|
9
|
+
export { createWorld, getWorld, getWorldHandlers, setWorld, } from './runtime/world.js';
|
|
10
|
+
/**
|
|
11
|
+
* Creates a single route which handles workflow execution requests,
|
|
12
|
+
* executing steps inline when possible to reduce function invocations
|
|
13
|
+
* and queue overhead.
|
|
14
|
+
*
|
|
15
|
+
* The handler loops: replay workflow → execute step inline → replay → ...
|
|
16
|
+
* until the workflow completes, times out, or encounters non-step suspensions.
|
|
17
|
+
*
|
|
18
|
+
* @param workflowCode - The workflow bundle code containing all workflow functions
|
|
19
|
+
* @returns A function that can be used as a Vercel API route
|
|
20
|
+
*/
|
|
21
|
+
export declare function workflowEntrypoint(workflowCode: string): (req: Request) => Promise<Response>;
|
|
22
|
+
//# sourceMappingURL=runtime.d.ts.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A serializable value:
|
|
3
|
+
* Any valid JSON object is serializable
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* // any valid JSON object is serializable
|
|
9
|
+
* const anyJson: Serializable = { foo: "bar" };
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export type Serializable = string | number | boolean | null | undefined | Serializable[] | {
|
|
13
|
+
[key: string]: Serializable;
|
|
14
|
+
} | ArrayBuffer | bigint | BigInt64Array | BigUint64Array | Date | DOMException | Error | Float32Array | Float64Array | Headers | Int8Array | Int16Array | Int32Array | Map<Serializable, Serializable> | ReadableStream<Uint8Array> | RegExp | Response | Set<Serializable> | URL | URLSearchParams | Uint8Array | Uint8ClampedArray | Uint16Array | Uint32Array | WritableStream<Uint8Array> | AbortController | AbortSignal | ((...args: Serializable[]) => Promise<Serializable>);
|
|
15
|
+
//# sourceMappingURL=schemas.d.ts.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Client (external) mode serialization.
|
|
3
|
+
*
|
|
4
|
+
* Used when starting workflows from the client side (serializing workflow
|
|
5
|
+
* arguments) and when receiving workflow return values. Supports encryption.
|
|
6
|
+
*/
|
|
7
|
+
import type { CodecOptions } from './codec.js';
|
|
8
|
+
import { type CryptoKey } from './encryption.js';
|
|
9
|
+
/**
|
|
10
|
+
* Serialize a value from the client environment (e.g. workflow arguments).
|
|
11
|
+
*/
|
|
12
|
+
export declare function serialize(value: unknown, encryptionKey?: CryptoKey, options?: CodecOptions): Promise<Uint8Array | unknown>;
|
|
13
|
+
/**
|
|
14
|
+
* Deserialize a value for the client environment (e.g. workflow return value).
|
|
15
|
+
*/
|
|
16
|
+
export declare function deserialize(data: Uint8Array | unknown, encryptionKey?: CryptoKey, options?: CodecOptions): Promise<unknown>;
|
|
17
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Devalue codec implementation.
|
|
3
|
+
*
|
|
4
|
+
* Uses the `devalue` library for serialization. Handles custom types via
|
|
5
|
+
* reducers (serialize) and revivers (deserialize) which are composed
|
|
6
|
+
* internally based on the serialization mode.
|
|
7
|
+
*
|
|
8
|
+
* The reducer/reviver pattern is specific to devalue — other codecs
|
|
9
|
+
* (CBOR, JSON) would handle types differently (e.g. CBOR supports Date,
|
|
10
|
+
* typed arrays, Map, Set natively).
|
|
11
|
+
*/
|
|
12
|
+
import type { Codec } from './codec.js';
|
|
13
|
+
export declare const devalueCodec: Codec;
|
|
14
|
+
//# sourceMappingURL=codec-devalue.d.ts.map
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Codec interface for serialization formats.
|
|
3
|
+
*
|
|
4
|
+
* A codec handles the core serialize/deserialize logic for a specific
|
|
5
|
+
* wire format (devalue, CBOR, JSON, etc.). Each codec is responsible
|
|
6
|
+
* for handling all supported data types internally — the caller only
|
|
7
|
+
* specifies which serialization mode to use.
|
|
8
|
+
*
|
|
9
|
+
* - **devalue**: Uses custom reducers/revivers for Date, Error, Map, Set,
|
|
10
|
+
* typed arrays, class instances, etc.
|
|
11
|
+
* - **cbor**: Would handle Date, typed arrays, Map, Set natively via the
|
|
12
|
+
* CBOR type system. Class instances would still need custom handling.
|
|
13
|
+
* - **json**: Would only support standard JSON types (primitives, arrays,
|
|
14
|
+
* plain objects). No Date, Map, Set, typed arrays, etc.
|
|
15
|
+
*/
|
|
16
|
+
import type { FormatPrefix } from './types.js';
|
|
17
|
+
/**
|
|
18
|
+
* The serialization mode determines which types are supported and how
|
|
19
|
+
* they're handled. Different modes compose different sets of type handlers.
|
|
20
|
+
*
|
|
21
|
+
* - `workflow`: Runs inside the workflow VM. Includes class serialization,
|
|
22
|
+
* step function serialization. No stream handling.
|
|
23
|
+
* - `step`: Runs in the step handler (Node.js). Includes class serialization.
|
|
24
|
+
* No step function serialization. Stream handling at call sites.
|
|
25
|
+
* - `client`: Runs on the client side. Includes class serialization.
|
|
26
|
+
* No step function serialization. Stream handling at call sites.
|
|
27
|
+
*/
|
|
28
|
+
export type SerializationMode = 'workflow' | 'step' | 'client';
|
|
29
|
+
/**
|
|
30
|
+
* Options passed to codec serialize/deserialize to support VM-context
|
|
31
|
+
* serialization and mode-specific type handling.
|
|
32
|
+
*/
|
|
33
|
+
export interface CodecOptions {
|
|
34
|
+
/**
|
|
35
|
+
* The global object to use for `instanceof` checks and constructors.
|
|
36
|
+
* Defaults to `globalThis`. Must be set to the VM's global when
|
|
37
|
+
* serializing/deserializing data that crosses VM boundaries.
|
|
38
|
+
*/
|
|
39
|
+
global?: Record<string, any>;
|
|
40
|
+
/**
|
|
41
|
+
* Additional reducers to merge into the mode's default reducers.
|
|
42
|
+
* Used by dehydrate/hydrate functions that need stream handling
|
|
43
|
+
* or other mode-specific type reducers.
|
|
44
|
+
*/
|
|
45
|
+
extraReducers?: Record<string, (value: any) => any>;
|
|
46
|
+
/**
|
|
47
|
+
* Additional revivers to merge into the mode's default revivers.
|
|
48
|
+
* Used by dehydrate/hydrate functions that need stream handling
|
|
49
|
+
* or other mode-specific type revivers.
|
|
50
|
+
*/
|
|
51
|
+
extraRevivers?: Record<string, (value: any) => any>;
|
|
52
|
+
}
|
|
53
|
+
export interface Codec {
|
|
54
|
+
/** The 4-character format prefix identifier (e.g. "devl", "cbor", "json") */
|
|
55
|
+
readonly formatPrefix: FormatPrefix;
|
|
56
|
+
/**
|
|
57
|
+
* Serialize a value to bytes.
|
|
58
|
+
*
|
|
59
|
+
* The codec handles all supported types internally based on the mode.
|
|
60
|
+
*
|
|
61
|
+
* @param value - The value to serialize
|
|
62
|
+
* @param mode - The serialization mode
|
|
63
|
+
* @param options - Optional global, extra reducers/revivers
|
|
64
|
+
* @returns The serialized payload (without format prefix)
|
|
65
|
+
*/
|
|
66
|
+
serialize(value: unknown, mode: SerializationMode, options?: CodecOptions): Uint8Array;
|
|
67
|
+
/**
|
|
68
|
+
* Deserialize bytes back to a value.
|
|
69
|
+
*
|
|
70
|
+
* The codec handles all supported types internally based on the mode.
|
|
71
|
+
*
|
|
72
|
+
* @param data - The serialized payload (without format prefix)
|
|
73
|
+
* @param mode - The serialization mode
|
|
74
|
+
* @param options - Optional global, extra revivers
|
|
75
|
+
* @returns The deserialized value
|
|
76
|
+
*/
|
|
77
|
+
deserialize(data: Uint8Array, mode: SerializationMode, options?: CodecOptions): unknown;
|
|
78
|
+
/**
|
|
79
|
+
* Deserialize legacy (pre-format-prefix) data.
|
|
80
|
+
* Used for backwards compatibility with specVersion 1 runs that stored
|
|
81
|
+
* data as plain JSON arrays instead of binary.
|
|
82
|
+
*
|
|
83
|
+
* @param data - The legacy data
|
|
84
|
+
* @param mode - The serialization mode
|
|
85
|
+
* @param options - Optional global, extra revivers
|
|
86
|
+
* @returns The deserialized value
|
|
87
|
+
*/
|
|
88
|
+
deserializeLegacy?(data: unknown, mode: SerializationMode, options?: CodecOptions): unknown;
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=codec.d.ts.map
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Composable encryption layer for serialized data.
|
|
3
|
+
*
|
|
4
|
+
* Wraps/unwraps serialized payloads with AES-256-GCM encryption,
|
|
5
|
+
* using the format prefix system to mark encrypted data.
|
|
6
|
+
*/
|
|
7
|
+
import { type CryptoKey } from '../encryption.js';
|
|
8
|
+
export type { CryptoKey };
|
|
9
|
+
/**
|
|
10
|
+
* Encryption key parameter type. Accepts a resolved key, undefined (no encryption),
|
|
11
|
+
* or a promise that resolves to either.
|
|
12
|
+
*/
|
|
13
|
+
export type EncryptionKeyParam = CryptoKey | undefined | Promise<CryptoKey | undefined>;
|
|
14
|
+
/**
|
|
15
|
+
* Encrypt a format-prefixed payload if a key is provided.
|
|
16
|
+
* Wraps the data with the 'encr' format prefix.
|
|
17
|
+
*
|
|
18
|
+
* @param data - The format-prefixed serialized data
|
|
19
|
+
* @param key - Encryption key (undefined to skip encryption)
|
|
20
|
+
* @returns The encrypted data with 'encr' prefix, or the original data if no key
|
|
21
|
+
*/
|
|
22
|
+
export declare function encrypt(data: Uint8Array | unknown, key: CryptoKey | undefined): Promise<Uint8Array | unknown>;
|
|
23
|
+
/**
|
|
24
|
+
* Decrypt a format-prefixed payload if it's encrypted.
|
|
25
|
+
* Strips the 'encr' format prefix and decrypts the inner payload.
|
|
26
|
+
*
|
|
27
|
+
* @param data - The potentially encrypted data
|
|
28
|
+
* @param key - Encryption key (undefined to skip decryption)
|
|
29
|
+
* @returns The decrypted inner payload, or the original data if not encrypted
|
|
30
|
+
*/
|
|
31
|
+
export declare function decrypt(data: Uint8Array | unknown, key: CryptoKey | undefined): Promise<Uint8Array | unknown>;
|
|
32
|
+
//# sourceMappingURL=encryption.d.ts.map
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared error formatting utility for serialization failures.
|
|
3
|
+
*
|
|
4
|
+
* Used by the mode-specific serializers (workflow, step, client) to
|
|
5
|
+
* produce consistent error messages with devalue path information.
|
|
6
|
+
*
|
|
7
|
+
* Returns a `{ message, hint }` pair so callers can throw a
|
|
8
|
+
* `SerializationError(message, { hint, cause })` and have the hint flow
|
|
9
|
+
* through the standard friendly-errors framing instead of being baked
|
|
10
|
+
* into the message string.
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Format a serialization error with context about what failed.
|
|
14
|
+
* Extracts path, value, and reason from devalue's DevalueError when available.
|
|
15
|
+
* Logs the problematic value to the console for better debugging.
|
|
16
|
+
*/
|
|
17
|
+
export declare function formatSerializationError(context: string, error: unknown): {
|
|
18
|
+
message: string;
|
|
19
|
+
hint: string;
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Format prefix system for serialized payloads.
|
|
3
|
+
*
|
|
4
|
+
* All serialized payloads are prefixed with a 4-byte format identifier that
|
|
5
|
+
* allows the deserializer to determine how to decode the payload. This enables:
|
|
6
|
+
*
|
|
7
|
+
* 1. Self-describing payloads — the World layer is agnostic to serialization format
|
|
8
|
+
* 2. Gradual migration — old runs keep working, new runs can use new formats
|
|
9
|
+
* 3. Composability — encryption can wrap any format ("encr" wrapping "devl")
|
|
10
|
+
* 4. Debugging — raw data inspection immediately reveals the format
|
|
11
|
+
*
|
|
12
|
+
* Format: [4 bytes: format identifier][payload]
|
|
13
|
+
*
|
|
14
|
+
* The format prefix is open-ended — any 4-character [a-z0-9] string is valid.
|
|
15
|
+
* This allows new codecs to be added without modifying this module.
|
|
16
|
+
*/
|
|
17
|
+
import { type FormatPrefix } from './types.js';
|
|
18
|
+
/**
|
|
19
|
+
* Encode a payload with a format prefix.
|
|
20
|
+
*
|
|
21
|
+
* @param format - The format identifier (4 chars, [a-z0-9])
|
|
22
|
+
* @param payload - The serialized payload bytes
|
|
23
|
+
* @returns A new Uint8Array with format prefix prepended
|
|
24
|
+
*/
|
|
25
|
+
export declare function encodeWithFormatPrefix(format: FormatPrefix, payload: Uint8Array | unknown): Uint8Array | unknown;
|
|
26
|
+
/**
|
|
27
|
+
* Peek at the format prefix without consuming it.
|
|
28
|
+
*
|
|
29
|
+
* Returns the prefix if it's a valid format prefix ([a-z0-9]{4}),
|
|
30
|
+
* or null if the data is legacy/non-binary or doesn't start with a
|
|
31
|
+
* valid prefix.
|
|
32
|
+
*
|
|
33
|
+
* @param data - The format-prefixed data
|
|
34
|
+
* @returns The format prefix, or null
|
|
35
|
+
*/
|
|
36
|
+
export declare function peekFormatPrefix(data: Uint8Array | unknown): FormatPrefix | null;
|
|
37
|
+
/**
|
|
38
|
+
* Check if data is encrypted (has 'encr' format prefix).
|
|
39
|
+
*/
|
|
40
|
+
export declare function isEncrypted(data: Uint8Array | unknown): boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Decode a format-prefixed payload.
|
|
43
|
+
*
|
|
44
|
+
* Unlike the legacy implementation which only accepted known formats
|
|
45
|
+
* (`devl`, `encr`), this function accepts any valid format prefix
|
|
46
|
+
* (`[a-z0-9]{4}`). This is intentional for forward compatibility —
|
|
47
|
+
* new codecs (e.g. `cbor`) can be added without modifying this module.
|
|
48
|
+
* Callers are responsible for checking whether they support the returned
|
|
49
|
+
* format and throwing an appropriate error if not (e.g. "Unsupported
|
|
50
|
+
* serialization format").
|
|
51
|
+
*
|
|
52
|
+
* @param data - The format-prefixed data
|
|
53
|
+
* @returns An object with the format prefix and payload
|
|
54
|
+
* @throws Error if the data is too short or has an invalid prefix
|
|
55
|
+
*/
|
|
56
|
+
export declare function decodeFormatPrefix(data: Uint8Array | unknown): {
|
|
57
|
+
format: FormatPrefix;
|
|
58
|
+
payload: Uint8Array;
|
|
59
|
+
};
|
|
60
|
+
//# sourceMappingURL=format.d.ts.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Serialization module — public API.
|
|
3
|
+
*
|
|
4
|
+
* Re-exports the mode-specific serialize/deserialize functions and
|
|
5
|
+
* the codec/format/encryption abstractions.
|
|
6
|
+
*/
|
|
7
|
+
export type { FormatPrefix, SerializableSpecial, Reducers, Revivers, } from './types.js';
|
|
8
|
+
export { SerializationFormat, isFormatPrefix } from './types.js';
|
|
9
|
+
export type { Codec, SerializationMode } from './codec.js';
|
|
10
|
+
export { devalueCodec } from './codec-devalue.js';
|
|
11
|
+
export { encodeWithFormatPrefix, decodeFormatPrefix, peekFormatPrefix, isEncrypted, } from './format.js';
|
|
12
|
+
export { encrypt, decrypt, type CryptoKey, type EncryptionKeyParam, } from './encryption.js';
|
|
13
|
+
import * as workflow from './workflow.js';
|
|
14
|
+
import * as step from './step.js';
|
|
15
|
+
import * as client from './client.js';
|
|
16
|
+
export { workflow, step, client };
|
|
17
|
+
export { revive } from './reducers/common.js';
|
|
18
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reducers and revivers for custom class serialization.
|
|
3
|
+
*
|
|
4
|
+
* Handles:
|
|
5
|
+
* - Class: class constructors with a `classId` property
|
|
6
|
+
* - Instance: instances of classes with custom WORKFLOW_SERIALIZE/DESERIALIZE methods
|
|
7
|
+
*/
|
|
8
|
+
import type { Reducers, Revivers } from '../types.js';
|
|
9
|
+
export declare function getClassReducers(): Partial<Reducers>;
|
|
10
|
+
export declare function getClassRevivers(global?: Record<string, any>): Partial<Revivers>;
|
|
11
|
+
//# sourceMappingURL=class.d.ts.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Common reducers and revivers for types shared across all serialization modes.
|
|
3
|
+
*
|
|
4
|
+
* Handles: ArrayBuffer, BigInt, typed arrays, Date, Error, Headers, Map, Set,
|
|
5
|
+
* RegExp, Request, Response, URL, URLSearchParams.
|
|
6
|
+
*
|
|
7
|
+
* Note: Uses Node.js Buffer for base64 encoding/decoding. For environments
|
|
8
|
+
* without Buffer (e.g. QuickJS VM), a polyfill or alternative base64
|
|
9
|
+
* implementation will be needed.
|
|
10
|
+
*/
|
|
11
|
+
import type { Reducers, Revivers } from '../types.js';
|
|
12
|
+
declare function revive(str: string): any;
|
|
13
|
+
export declare function getCommonReducers(global?: Record<string, any>): Partial<Reducers>;
|
|
14
|
+
export declare function getCommonRevivers(global?: Record<string, any>): Partial<Revivers>;
|
|
15
|
+
export { revive };
|
|
16
|
+
//# sourceMappingURL=common.d.ts.map
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reducer and reviver for step function references.
|
|
3
|
+
*
|
|
4
|
+
* In workflow mode, step functions are replaced by the SWC plugin with
|
|
5
|
+
* proxies created by `globalThis[Symbol.for("WORKFLOW_USE_STEP")]("stepId")`.
|
|
6
|
+
* These proxies have a `.stepId` property and optionally a `.__closureVarsFn`
|
|
7
|
+
* for captured closure variables. They may additionally have `.__boundThis`
|
|
8
|
+
* (and rarely `.__boundArgs`) when the SWC plugin emitted
|
|
9
|
+
* `useStep(...).bind(this)` for a nested arrow step that lexically
|
|
10
|
+
* captured `this` (see `packages/swc-plugin-workflow/spec.md` → "Lexical
|
|
11
|
+
* `this` Capture in Nested Arrow Steps").
|
|
12
|
+
*
|
|
13
|
+
* The reducer serializes them as
|
|
14
|
+
* `{ stepId, closureVars?, boundThis?, boundArgs? }`.
|
|
15
|
+
* The reviver reconstructs them by calling WORKFLOW_USE_STEP and, when
|
|
16
|
+
* `boundThis` (or `boundArgs`) is present, re-binding the resulting
|
|
17
|
+
* proxy so the caller's captured `this` (and prefilled args) survive the
|
|
18
|
+
* round trip.
|
|
19
|
+
*/
|
|
20
|
+
import type { Reducers, Revivers } from '../types.js';
|
|
21
|
+
export declare function getStepFunctionReducer(): Partial<Reducers>;
|
|
22
|
+
/**
|
|
23
|
+
* Create the StepFunction reviver for workflow context.
|
|
24
|
+
*
|
|
25
|
+
* The reviver calls WORKFLOW_USE_STEP to create the step proxy,
|
|
26
|
+
* restoring the ability to call the step from workflow code. If the
|
|
27
|
+
* serialized payload includes `boundThis` (and optionally `boundArgs`),
|
|
28
|
+
* the reviver also re-binds the freshly-created proxy so a step proxy
|
|
29
|
+
* that was constructed with `.bind(this, …)` in the workflow bundle
|
|
30
|
+
* continues to carry that receiver and any prefilled arguments after
|
|
31
|
+
* being deserialized in another bundle (e.g. when passed as a step
|
|
32
|
+
* argument).
|
|
33
|
+
*/
|
|
34
|
+
export declare function getStepFunctionReviver(global?: Record<string, any>): Partial<Revivers>;
|
|
35
|
+
//# sourceMappingURL=step-function.d.ts.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Step mode serialization.
|
|
3
|
+
*
|
|
4
|
+
* Used by the step handler for serializing step return values and
|
|
5
|
+
* deserializing step arguments. Supports encryption as a composable layer.
|
|
6
|
+
*/
|
|
7
|
+
import type { CodecOptions } from './codec.js';
|
|
8
|
+
import { type CryptoKey } from './encryption.js';
|
|
9
|
+
/**
|
|
10
|
+
* Serialize a value from the step execution environment.
|
|
11
|
+
*/
|
|
12
|
+
export declare function serialize(value: unknown, encryptionKey?: CryptoKey, options?: CodecOptions): Promise<Uint8Array | unknown>;
|
|
13
|
+
/**
|
|
14
|
+
* Deserialize a value for the step execution environment.
|
|
15
|
+
*/
|
|
16
|
+
export declare function deserialize(data: Uint8Array | unknown, encryptionKey?: CryptoKey, options?: CodecOptions): Promise<unknown>;
|
|
17
|
+
//# sourceMappingURL=step.d.ts.map
|