experimental-ash 0.22.2 → 0.24.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 +36 -0
- package/dist/docs/internals/hooks.md +13 -16
- package/dist/docs/internals/message-runtime.md +1 -1
- package/dist/docs/public/auth-and-route-protection.md +3 -3
- 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 +4 -4
- package/dist/src/channel/types.d.ts +10 -12
- 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-B4PaZGUr.js} +1 -1
- package/dist/src/chunks/host-DsW72Q-w.js +65 -0
- package/dist/src/chunks/paths-OknjaYR8.js +89 -0
- package/dist/src/chunks/prewarm-B4YblQ5m.js +6 -0
- 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 +3 -3
- 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 +20 -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 +51 -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/index.js +2 -2
- 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/package.json +1 -1
- package/dist/src/compiled/@workflow/core/private.d.ts +59 -10
- package/dist/src/compiled/@workflow/core/runtime/constants.d.ts +51 -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/replay-budget.d.ts +98 -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/runtime.js +27 -27
- 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 +215 -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 +337 -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 +36 -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/compiled/@workflow/core/workflow.js +1 -1
- package/dist/src/compiled/@workflow/errors/error-codes.d.ts +5 -1
- package/dist/src/compiled/@workflow/errors/index.d.ts +15 -1
- package/dist/src/compiled/@workflow/errors/index.js +1 -1
- package/dist/src/compiled/@workflow/errors/package.json +1 -1
- package/dist/src/compiled/_chunks/workflow/{context-errors-zbKocOyk.js → context-errors-Bbvvp-li.js} +2 -2
- package/dist/src/compiled/_chunks/workflow/{dist-0iNBqPYp.js → dist-C7wPwOI9.js} +2 -2
- package/dist/src/compiled/_chunks/workflow/{dist-D774SUM4.js → dist-C_oiE-l7.js} +1 -1
- package/dist/src/compiled/_chunks/workflow/resume-hook-C3VWUPii.js +12 -0
- package/dist/src/compiled/_chunks/workflow/sleep-QTkC1VFe.js +1 -0
- package/dist/src/compiled/_chunks/workflow/{symbols-D-4tVV8x.js → symbols-QezhMuLg.js} +1 -1
- package/dist/src/evals/cli/eval.js +1 -1
- package/dist/src/execution/await-authorization-orchestrator.d.ts +2 -1
- package/dist/src/execution/await-authorization-orchestrator.js +4 -0
- package/dist/src/execution/connection-auth-steps.d.ts +4 -0
- package/dist/src/execution/connection-auth-steps.js +9 -11
- package/dist/src/execution/node-step.d.ts +4 -5
- package/dist/src/execution/subagent-adapter.d.ts +0 -27
- package/dist/src/execution/subagent-adapter.js +2 -66
- package/dist/src/execution/subagent-hitl-proxy.d.ts +2 -2
- package/dist/src/execution/subagent-hitl-proxy.js +2 -2
- package/dist/src/execution/task-mode.d.ts +3 -3
- package/dist/src/execution/task-mode.js +3 -3
- package/dist/src/execution/turn-workflow.d.ts +41 -0
- package/dist/src/execution/turn-workflow.js +96 -0
- package/dist/src/execution/workflow-entry.js +77 -87
- package/dist/src/execution/workflow-errors.d.ts +14 -0
- package/dist/src/execution/workflow-errors.js +54 -0
- package/dist/src/execution/workflow-runtime.d.ts +34 -3
- package/dist/src/execution/workflow-runtime.js +52 -10
- package/dist/src/execution/workflow-steps.d.ts +27 -2
- package/dist/src/execution/workflow-steps.js +31 -26
- package/dist/src/harness/instrumentation-config.js +14 -7
- package/dist/src/harness/messages.d.ts +7 -7
- package/dist/src/harness/messages.js +4 -4
- package/dist/src/harness/runtime-actions.d.ts +4 -4
- package/dist/src/internal/application/package.js +1 -1
- package/dist/src/internal/workflow-bundle/workflow-builders.d.ts +1 -1
- package/dist/src/internal/workflow-bundle/workflow-builders.js +20 -8
- package/dist/src/internal/workflow-bundle/workflow-transformer.d.ts +13 -0
- package/dist/src/internal/workflow-bundle/workflow-transformer.js +10 -4
- 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 +4 -4
- package/dist/src/chunks/host-DREC8e8Z.js +0 -65
- package/dist/src/chunks/paths-C6sp4T2U.js +0 -88
- package/dist/src/chunks/prewarm-hz8p2jlZ.js +0 -6
- package/dist/src/compiled/_chunks/workflow/resume-hook-CL8Ed91K.js +0 -12
- package/dist/src/compiled/_chunks/workflow/sleep-Dn3i9nxI.js +0 -1
- package/dist/src/execution/continuous-entry.d.ts +0 -59
- package/dist/src/execution/continuous-entry.js +0 -487
- package/dist/src/execution/continuous-runtime.d.ts +0 -17
- package/dist/src/execution/continuous-runtime.js +0 -123
|
@@ -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
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared types for the serialization system.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* A format prefix is exactly 4 lowercase alphanumeric characters [a-z0-9].
|
|
6
|
+
*
|
|
7
|
+
* This is a branded string type — use `isFormatPrefix()` to validate
|
|
8
|
+
* at runtime. The `SerializationFormat` object provides well-known
|
|
9
|
+
* constants, but codecs may define additional prefixes.
|
|
10
|
+
*/
|
|
11
|
+
export type FormatPrefix = string & {
|
|
12
|
+
readonly __brand: 'FormatPrefix';
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Runtime type guard for format prefix strings.
|
|
16
|
+
*
|
|
17
|
+
* Validates that a string is exactly 4 characters of [a-z0-9].
|
|
18
|
+
*/
|
|
19
|
+
export declare function isFormatPrefix(value: string): value is FormatPrefix;
|
|
20
|
+
/**
|
|
21
|
+
* Well-known format prefix constants. Codecs may define additional ones.
|
|
22
|
+
*/
|
|
23
|
+
export declare const SerializationFormat: {
|
|
24
|
+
/** devalue stringify/parse with TextEncoder/TextDecoder */
|
|
25
|
+
readonly DEVALUE_V1: FormatPrefix;
|
|
26
|
+
/** Encrypted payload (inner payload has its own format prefix) */
|
|
27
|
+
readonly ENCRYPTED: FormatPrefix;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Types that need specialized handling when serialized/deserialized.
|
|
31
|
+
* If a type is added here, it MUST also be added to the `Serializable`
|
|
32
|
+
* type in `schemas.ts`.
|
|
33
|
+
*/
|
|
34
|
+
export interface SerializableSpecial {
|
|
35
|
+
ArrayBuffer: string;
|
|
36
|
+
BigInt: string;
|
|
37
|
+
BigInt64Array: string;
|
|
38
|
+
BigUint64Array: string;
|
|
39
|
+
Date: string;
|
|
40
|
+
DOMException: {
|
|
41
|
+
message: string;
|
|
42
|
+
name: string;
|
|
43
|
+
stack?: string;
|
|
44
|
+
cause?: unknown;
|
|
45
|
+
};
|
|
46
|
+
FatalError: {
|
|
47
|
+
message: string;
|
|
48
|
+
stack?: string;
|
|
49
|
+
cause?: unknown;
|
|
50
|
+
};
|
|
51
|
+
Float32Array: string;
|
|
52
|
+
Float64Array: string;
|
|
53
|
+
Error: {
|
|
54
|
+
name: string;
|
|
55
|
+
message: string;
|
|
56
|
+
stack?: string;
|
|
57
|
+
cause?: unknown;
|
|
58
|
+
};
|
|
59
|
+
EvalError: {
|
|
60
|
+
message: string;
|
|
61
|
+
stack?: string;
|
|
62
|
+
cause?: unknown;
|
|
63
|
+
};
|
|
64
|
+
Headers: [string, string][];
|
|
65
|
+
HookConflictError: {
|
|
66
|
+
message: string;
|
|
67
|
+
stack?: string;
|
|
68
|
+
cause?: unknown;
|
|
69
|
+
token: string;
|
|
70
|
+
conflictingRunId?: string;
|
|
71
|
+
};
|
|
72
|
+
Int8Array: string;
|
|
73
|
+
Int16Array: string;
|
|
74
|
+
Int32Array: string;
|
|
75
|
+
Map: [any, any][];
|
|
76
|
+
RangeError: {
|
|
77
|
+
message: string;
|
|
78
|
+
stack?: string;
|
|
79
|
+
cause?: unknown;
|
|
80
|
+
};
|
|
81
|
+
ReadableStream: {
|
|
82
|
+
name: string;
|
|
83
|
+
type?: 'bytes';
|
|
84
|
+
startIndex?: number;
|
|
85
|
+
} | {
|
|
86
|
+
bodyInit: any;
|
|
87
|
+
};
|
|
88
|
+
ReferenceError: {
|
|
89
|
+
message: string;
|
|
90
|
+
stack?: string;
|
|
91
|
+
cause?: unknown;
|
|
92
|
+
};
|
|
93
|
+
RegExp: {
|
|
94
|
+
source: string;
|
|
95
|
+
flags: string;
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* `retryAfter` is serialized as a numeric epoch timestamp rather than a
|
|
99
|
+
* `Date` to be realm-safe. The Date reducer uses `instanceof global.Date`,
|
|
100
|
+
* which fails for Dates from a different VM realm.
|
|
101
|
+
*/
|
|
102
|
+
RetryableError: {
|
|
103
|
+
message: string;
|
|
104
|
+
stack?: string;
|
|
105
|
+
cause?: unknown;
|
|
106
|
+
retryAfter: number;
|
|
107
|
+
};
|
|
108
|
+
Request: {
|
|
109
|
+
method: string;
|
|
110
|
+
url: string;
|
|
111
|
+
headers: Headers;
|
|
112
|
+
body: Request['body'];
|
|
113
|
+
duplex: Request['duplex'];
|
|
114
|
+
responseWritable?: WritableStream<Response>;
|
|
115
|
+
signal?: AbortSignal;
|
|
116
|
+
};
|
|
117
|
+
Response: {
|
|
118
|
+
type: Response['type'];
|
|
119
|
+
url: string;
|
|
120
|
+
status: number;
|
|
121
|
+
statusText: string;
|
|
122
|
+
headers: Headers;
|
|
123
|
+
body: Response['body'];
|
|
124
|
+
redirected: boolean;
|
|
125
|
+
};
|
|
126
|
+
Class: {
|
|
127
|
+
classId: string;
|
|
128
|
+
};
|
|
129
|
+
Instance: {
|
|
130
|
+
classId: string;
|
|
131
|
+
data: unknown;
|
|
132
|
+
};
|
|
133
|
+
Set: any[];
|
|
134
|
+
SyntaxError: {
|
|
135
|
+
message: string;
|
|
136
|
+
stack?: string;
|
|
137
|
+
cause?: unknown;
|
|
138
|
+
};
|
|
139
|
+
StepFunction: {
|
|
140
|
+
stepId: string;
|
|
141
|
+
closureVars?: Record<string, any>;
|
|
142
|
+
/**
|
|
143
|
+
* Captured lexical `this` for step proxies that were created via
|
|
144
|
+
* `useStep(...).bind(thisArg)` (the SWC plugin emits this for nested
|
|
145
|
+
* arrow steps that close over their enclosing function's `this`).
|
|
146
|
+
* The reviver re-binds the freshly-created proxy to this value so the
|
|
147
|
+
* binding survives serialization round-trips.
|
|
148
|
+
*/
|
|
149
|
+
boundThis?: unknown;
|
|
150
|
+
/**
|
|
151
|
+
* Prefilled arguments captured when the user (rather than the SWC
|
|
152
|
+
* plugin) called `useStep(...).bind(thisArg, x, y)`. The reviver
|
|
153
|
+
* re-applies these alongside `boundThis` so partial application
|
|
154
|
+
* survives serialization. The SWC plugin only ever emits
|
|
155
|
+
* `.bind(this)` with no extra args today; this slot exists so a
|
|
156
|
+
* hand-written `.bind(thisArg, x)` doesn't silently lose `x` after
|
|
157
|
+
* round-tripping through the reducer/reviver.
|
|
158
|
+
*/
|
|
159
|
+
boundArgs?: unknown[];
|
|
160
|
+
};
|
|
161
|
+
TypeError: {
|
|
162
|
+
message: string;
|
|
163
|
+
stack?: string;
|
|
164
|
+
cause?: unknown;
|
|
165
|
+
};
|
|
166
|
+
URIError: {
|
|
167
|
+
message: string;
|
|
168
|
+
stack?: string;
|
|
169
|
+
cause?: unknown;
|
|
170
|
+
};
|
|
171
|
+
URL: string;
|
|
172
|
+
WorkflowFunction: {
|
|
173
|
+
workflowId: string;
|
|
174
|
+
};
|
|
175
|
+
URLSearchParams: string;
|
|
176
|
+
Uint8Array: string;
|
|
177
|
+
Uint8ClampedArray: string;
|
|
178
|
+
Uint16Array: string;
|
|
179
|
+
Uint32Array: string;
|
|
180
|
+
AggregateError: {
|
|
181
|
+
message: string;
|
|
182
|
+
stack?: string;
|
|
183
|
+
cause?: unknown;
|
|
184
|
+
errors: unknown[];
|
|
185
|
+
};
|
|
186
|
+
WritableStream: {
|
|
187
|
+
name: string;
|
|
188
|
+
/**
|
|
189
|
+
* The runId of the workflow run that owns the underlying server
|
|
190
|
+
* stream. Present only when the writable was forwarded across a
|
|
191
|
+
* `start()` boundary (parent → child). When omitted, the writable
|
|
192
|
+
* belongs to the receiving run (the normal in-run case).
|
|
193
|
+
*/
|
|
194
|
+
runId?: string;
|
|
195
|
+
};
|
|
196
|
+
AbortController: {
|
|
197
|
+
streamName: string;
|
|
198
|
+
hookToken: string;
|
|
199
|
+
aborted: boolean;
|
|
200
|
+
reason?: unknown;
|
|
201
|
+
};
|
|
202
|
+
AbortSignal: {
|
|
203
|
+
streamName: string;
|
|
204
|
+
hookToken: string;
|
|
205
|
+
aborted: boolean;
|
|
206
|
+
reason?: unknown;
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
export type Reducers = {
|
|
210
|
+
[K in keyof SerializableSpecial]: (value: any) => SerializableSpecial[K] | false;
|
|
211
|
+
};
|
|
212
|
+
export type Revivers = {
|
|
213
|
+
[K in keyof SerializableSpecial]: (value: SerializableSpecial[K]) => any;
|
|
214
|
+
};
|
|
215
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Workflow mode serialization.
|
|
3
|
+
*
|
|
4
|
+
* Provides serialize/deserialize for use inside the workflow execution
|
|
5
|
+
* environment (QuickJS VM or Node.js vm). It is:
|
|
6
|
+
* - Synchronous (no async operations)
|
|
7
|
+
* - No encryption (encryption is handled outside the VM on the host side)
|
|
8
|
+
*
|
|
9
|
+
* Designed to be bundled into the workflow code by esbuild and executed
|
|
10
|
+
* inside the sandboxed VM.
|
|
11
|
+
*/
|
|
12
|
+
import type { CodecOptions } from './codec.js';
|
|
13
|
+
/**
|
|
14
|
+
* Serialize a value for storage/transmission from the workflow environment.
|
|
15
|
+
*
|
|
16
|
+
* @param value - The value to serialize
|
|
17
|
+
* @param options - Optional global, extra reducers/revivers for VM-context serialization
|
|
18
|
+
* @returns Format-prefixed serialized bytes
|
|
19
|
+
*/
|
|
20
|
+
export declare function serialize(value: unknown, options?: CodecOptions): Uint8Array;
|
|
21
|
+
/**
|
|
22
|
+
* Deserialize a value received in the workflow environment.
|
|
23
|
+
*
|
|
24
|
+
* @param data - Format-prefixed serialized bytes, or legacy data
|
|
25
|
+
* @param options - Optional global, extra revivers for VM-context deserialization
|
|
26
|
+
* @returns The deserialized value
|
|
27
|
+
*/
|
|
28
|
+
export declare function deserialize(data: Uint8Array | unknown, options?: CodecOptions): unknown;
|
|
29
|
+
//# sourceMappingURL=workflow.d.ts.map
|