@ezghcloud/workflows 0.0.0 → 1.0.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.
Files changed (51) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +418 -1
  3. package/dist/client.d.ts +209 -0
  4. package/dist/client.js +259 -0
  5. package/dist/env.d.ts +2 -0
  6. package/dist/env.js +32 -0
  7. package/dist/index.d.ts +15 -0
  8. package/dist/index.js +7 -0
  9. package/dist/protocol/bytes.d.ts +8 -0
  10. package/dist/protocol/bytes.js +49 -0
  11. package/dist/protocol/callback.d.ts +6 -0
  12. package/dist/protocol/callback.js +31 -0
  13. package/dist/protocol/codec.d.ts +6 -0
  14. package/dist/protocol/codec.js +38 -0
  15. package/dist/protocol/derived.d.ts +5 -0
  16. package/dist/protocol/derived.js +41 -0
  17. package/dist/protocol/index.d.ts +14 -0
  18. package/dist/protocol/index.js +21 -0
  19. package/dist/protocol/public.d.ts +2 -0
  20. package/dist/protocol/public.js +1 -0
  21. package/dist/protocol/signature.d.ts +17 -0
  22. package/dist/protocol/signature.js +101 -0
  23. package/dist/protocol/stepid.d.ts +4 -0
  24. package/dist/protocol/stepid.js +9 -0
  25. package/dist/protocol/tokens.d.ts +2 -0
  26. package/dist/protocol/tokens.js +38 -0
  27. package/dist/protocol/types.d.ts +185 -0
  28. package/dist/protocol/types.js +1 -0
  29. package/dist/protocol/validate.d.ts +15 -0
  30. package/dist/protocol/validate.js +279 -0
  31. package/dist/queues.d.ts +47 -0
  32. package/dist/queues.js +126 -0
  33. package/dist/runtime/context.d.ts +82 -0
  34. package/dist/runtime/context.js +1 -0
  35. package/dist/runtime/errors.d.ts +49 -0
  36. package/dist/runtime/errors.js +160 -0
  37. package/dist/runtime/execution.d.ts +17 -0
  38. package/dist/runtime/execution.js +608 -0
  39. package/dist/runtime/invocation.d.ts +5 -0
  40. package/dist/runtime/invocation.js +47 -0
  41. package/dist/runtime/live.d.ts +23 -0
  42. package/dist/runtime/live.js +103 -0
  43. package/dist/runtime/workflow.d.ts +26 -0
  44. package/dist/runtime/workflow.js +49 -0
  45. package/dist/serve.d.ts +12 -0
  46. package/dist/serve.js +149 -0
  47. package/dist/version.d.ts +2 -0
  48. package/dist/version.js +2 -0
  49. package/dist/worker.d.ts +43 -0
  50. package/dist/worker.js +364 -0
  51. package/package.json +48 -4
@@ -0,0 +1,38 @@
1
+ import { utf8 } from "./bytes.js";
2
+ export const MAX_OUTPUT_BYTES = 1_048_576;
3
+ // encodeValue passes a value through JSON exactly as the wire will, so a step's live result and
4
+ // its replayed result are the same value (design, "Return values are JSON").
5
+ export function encodeValue(v) {
6
+ if (v === undefined)
7
+ return null;
8
+ const text = JSON.stringify(v, (_key, value) => {
9
+ if (typeof value === "function" || typeof value === "symbol" || typeof value === "bigint")
10
+ throw new TypeError(`A ${typeof value} can't be a step result or workflow output; return JSON values`);
11
+ return value;
12
+ });
13
+ return text === undefined ? null : JSON.parse(text);
14
+ }
15
+ export function jsonByteLength(v) {
16
+ return utf8(JSON.stringify(v ?? null)).length;
17
+ }
18
+ const units = { ms: 1, s: 1000, m: 60_000, h: 3_600_000, d: 86_400_000 };
19
+ // parseDuration: milliseconds, or a string such as 500ms, 30s, 5m, 2h or 3d.
20
+ export function parseDuration(d) {
21
+ if (typeof d === "number") {
22
+ if (!Number.isFinite(d) || d < 0)
23
+ throw new TypeError("A duration is a non-negative number of milliseconds");
24
+ return Math.floor(d);
25
+ }
26
+ const m = typeof d === "string" ? /^(\d+)(ms|s|m|h|d)$/.exec(d.trim()) : null;
27
+ if (!m)
28
+ throw new TypeError(`"${String(d)}" isn't a duration: use 500ms, 30s, 5m, 2h or 3d`);
29
+ return Number(m[1]) * units[m[2]];
30
+ }
31
+ // backoff is the delay before attempt+1: min(maxMs, floor(initialMs * multiplier^(attempt-1))).
32
+ // Attempts count from 1 (internal/protocol RetryPolicy.Backoff).
33
+ export function backoff(p, attempt) {
34
+ const ms = Math.floor(p.initialMs * p.multiplier ** (Math.max(1, attempt) - 1));
35
+ if (!Number.isFinite(ms) || ms > p.maxMs)
36
+ return p.maxMs;
37
+ return Math.max(0, ms);
38
+ }
@@ -0,0 +1,5 @@
1
+ export declare function derivedRunId(domain: string, a: string, b: string): Promise<string>;
2
+ export declare function rfc3339Nano(t: string | Date): string;
3
+ export declare const childRunId: (parentRunId: string, stepId: string) => Promise<string>;
4
+ export declare const scheduledRunId: (scheduleId: string, scheduledTime: string | Date) => Promise<string>;
5
+ export declare const triggeredRunId: (scheduleId: string, idempotencyKey: string) => Promise<string>;
@@ -0,0 +1,41 @@
1
+ import { toHex, utf8 } from "./bytes.js";
2
+ // Derived run IDs (plan D2-8, protocol/vectors/derived-ids.json): a UUIDv8 from the first 16
3
+ // bytes of SHA-256(domain + "\0" + a + "\0" + b), with version 8, the RFC 4122 variant, and
4
+ // rand_a carrying the shard: big-endian uint16 of sum[16:18] mod 1024 (byte 6's low two bits and
5
+ // byte 7), as shardOf reads it.
6
+ export async function derivedRunId(domain, a, b) {
7
+ const sum = new Uint8Array(await crypto.subtle.digest("SHA-256", utf8(`${domain}\u0000${a}\u0000${b}`)));
8
+ const shard = ((sum[16] << 8) | sum[17]) % 1024;
9
+ const h = sum.slice(0, 16);
10
+ h[6] = 0x80 | ((shard >> 8) & 0x03);
11
+ h[7] = shard & 0xff;
12
+ h[8] = 0x80 | (h[8] & 0x3f);
13
+ const x = toHex(h);
14
+ return `${x.slice(0, 8)}-${x.slice(8, 12)}-${x.slice(12, 16)}-${x.slice(16, 20)}-${x.slice(20)}`;
15
+ }
16
+ // rfc3339Nano formats a time like Go's time.RFC3339Nano in UTC: fractional seconds without
17
+ // trailing zeros, and none at all for a whole second. A string keeps its sub-millisecond digits.
18
+ export function rfc3339Nano(t) {
19
+ let ms;
20
+ let frac = "";
21
+ if (typeof t === "string") {
22
+ const m = /^(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2})(?:\.(\d{1,9}))?(Z|[+-]\d{2}:\d{2})$/i.exec(t);
23
+ if (!m)
24
+ throw new TypeError(`Not an RFC 3339 time: "${t}"`);
25
+ ms = Date.parse(`${m[1]}${m[3]}`);
26
+ frac = m[2] ?? "";
27
+ }
28
+ else {
29
+ ms = t.getTime();
30
+ frac = String(((ms % 1000) + 1000) % 1000).padStart(3, "0");
31
+ ms -= ((ms % 1000) + 1000) % 1000;
32
+ }
33
+ if (Number.isNaN(ms))
34
+ throw new TypeError("Not a time");
35
+ const whole = new Date(ms).toISOString().slice(0, 19);
36
+ frac = frac.replace(/0+$/, "");
37
+ return `${whole}${frac ? `.${frac}` : ""}Z`;
38
+ }
39
+ export const childRunId = (parentRunId, stepId) => derivedRunId("workflows.child", parentRunId, stepId);
40
+ export const scheduledRunId = (scheduleId, scheduledTime) => derivedRunId("workflows.schedule", scheduleId, rfc3339Nano(scheduledTime));
41
+ export const triggeredRunId = (scheduleId, idempotencyKey) => derivedRunId("workflows.trigger", scheduleId, idempotencyKey);
@@ -0,0 +1,14 @@
1
+ import type { RetryPolicy } from "./types.ts";
2
+ export type * from "./types.ts";
3
+ export { MAX_OUTPUT_BYTES, backoff, encodeValue, jsonByteLength, parseDuration } from "./codec.ts";
4
+ export { MAX_SIGNATURE_AGE_SECONDS, MAX_SIGNATURES, SECRET_PREFIX, SIGNATURE_HEADER, SignatureError, decodeSecret, parseSignature, sign, verify, verifyParsed } from "./signature.ts";
5
+ export type { ParsedSignature } from "./signature.ts";
6
+ export { stepId, validRunKey, validStepIdOverride, validWorkflowName } from "./stepid.ts";
7
+ export { isInvocationToken, shardOf } from "./tokens.ts";
8
+ export declare const PROTOCOL_VERSION = "1.2";
9
+ export declare const PROTOCOL_VERSIONS: readonly string[];
10
+ export declare function supportsParallel(version: string): boolean;
11
+ export declare function supportsMessages(version: string): boolean;
12
+ export { callbackTokenHash, mintCallbackToken, parseCallbackToken } from "./callback.ts";
13
+ export { childRunId, derivedRunId, rfc3339Nano, scheduledRunId, triggeredRunId } from "./derived.ts";
14
+ export declare const DEFAULT_RETRY: Readonly<RetryPolicy>;
@@ -0,0 +1,21 @@
1
+ export { MAX_OUTPUT_BYTES, backoff, encodeValue, jsonByteLength, parseDuration } from "./codec.js";
2
+ export { MAX_SIGNATURE_AGE_SECONDS, MAX_SIGNATURES, SECRET_PREFIX, SIGNATURE_HEADER, SignatureError, decodeSecret, parseSignature, sign, verify, verifyParsed } from "./signature.js";
3
+ export { stepId, validRunKey, validStepIdOverride, validWorkflowName } from "./stepid.js";
4
+ export { isInvocationToken, shardOf } from "./tokens.js";
5
+ // The newest protocol version this SDK speaks, and every one it speaks (sync replies and pull polls
6
+ // declare them; the engine picks the newest it shares).
7
+ export const PROTOCOL_VERSION = "1.2";
8
+ export const PROTOCOL_VERSIONS = Object.freeze(["1.0", "1.1", "1.2"]);
9
+ // supportsParallel: protocol 1.1 and later plan parallel steps and allow callbacks and invoke.
10
+ export function supportsParallel(version) {
11
+ const [major, minor] = String(version).split(".").map(Number);
12
+ return major === 1 && (minor ?? 0) >= 1;
13
+ }
14
+ // supportsMessages: protocol 1.2 and later wait for queue messages (step.waitForMessage).
15
+ export function supportsMessages(version) {
16
+ const [major, minor] = String(version).split(".").map(Number);
17
+ return major === 1 && (minor ?? 0) >= 2;
18
+ }
19
+ export { callbackTokenHash, mintCallbackToken, parseCallbackToken } from "./callback.js";
20
+ export { childRunId, derivedRunId, rfc3339Nano, scheduledRunId, triggeredRunId } from "./derived.js";
21
+ export const DEFAULT_RETRY = Object.freeze({ maxAttempts: 5, initialMs: 1000, maxMs: 600_000, multiplier: 2 });
@@ -0,0 +1,2 @@
1
+ export type { Cancel, Checkpoint, Command, Endpoints, HeartbeatResponse, Invocation, InvocationResult, Journal, JournalEntry, PlannedStep, PollRequest, PollResponse, RetryPolicy, RunInfo, ScheduleInfo, SDKInfo, SyncReply, WireError, WorkflowInfo, } from "./types.ts";
2
+ export { SignatureError, decodeSecret, sign, verify } from "./signature.ts";
@@ -0,0 +1 @@
1
+ export { SignatureError, decodeSecret, sign, verify } from "./signature.js";
@@ -0,0 +1,17 @@
1
+ export declare const SIGNATURE_HEADER = "EZGH-Signature";
2
+ export declare const SECRET_PREFIX = "whsec_";
3
+ export declare const MAX_SIGNATURE_AGE_SECONDS = 300;
4
+ export declare class SignatureError extends Error {
5
+ readonly reason: "expired" | "invalid";
6
+ constructor(reason: "expired" | "invalid", message: string);
7
+ }
8
+ export declare function decodeSecret(secret: string): Uint8Array;
9
+ export declare function sign(secrets: Uint8Array[], t: Date, body: Uint8Array): Promise<string>;
10
+ export declare const MAX_SIGNATURES = 8;
11
+ export interface ParsedSignature {
12
+ t: number;
13
+ signatures: Uint8Array[];
14
+ }
15
+ export declare function parseSignature(header: string, now: Date): ParsedSignature;
16
+ export declare function verifyParsed(sig: ParsedSignature, secrets: Uint8Array[], body: Uint8Array): Promise<void>;
17
+ export declare function verify(header: string, secrets: Uint8Array[], body: Uint8Array, now: Date): Promise<void>;
@@ -0,0 +1,101 @@
1
+ import { concat, fromBase64url, fromHex, toHex, utf8 } from "./bytes.js";
2
+ export const SIGNATURE_HEADER = "EZGH-Signature";
3
+ export const SECRET_PREFIX = "whsec_";
4
+ export const MAX_SIGNATURE_AGE_SECONDS = 300;
5
+ export class SignatureError extends Error {
6
+ reason;
7
+ constructor(reason, message) {
8
+ super(message);
9
+ this.reason = reason;
10
+ this.name = "SignatureError";
11
+ }
12
+ }
13
+ const malformedSecret = "A signing secret is whsec_ and 43 base64url characters, as the API returned it";
14
+ // decodeSecret: "whsec_" + 43 base64url characters → the 32 HMAC key bytes (D22).
15
+ export function decodeSecret(secret) {
16
+ const s = typeof secret === "string" ? secret.trim() : "";
17
+ if (!s.startsWith(SECRET_PREFIX) || s.length !== SECRET_PREFIX.length + 43)
18
+ throw new TypeError(malformedSecret);
19
+ let b;
20
+ try {
21
+ b = fromBase64url(s.slice(SECRET_PREFIX.length));
22
+ }
23
+ catch {
24
+ throw new TypeError(malformedSecret);
25
+ }
26
+ if (b.length !== 32)
27
+ throw new TypeError(malformedSecret);
28
+ return b;
29
+ }
30
+ const key = (secret) => crypto.subtle.importKey("raw", new Uint8Array(secret), { name: "HMAC", hash: "SHA-256" }, false, ["sign"]);
31
+ const mac = async (secret, payload) => new Uint8Array(await crypto.subtle.sign("HMAC", await key(secret), payload));
32
+ // equal compares in constant time for equal lengths.
33
+ function equal(a, b) {
34
+ if (a.length !== b.length)
35
+ return false;
36
+ let d = 0;
37
+ for (let i = 0; i < a.length; i++)
38
+ d |= a[i] ^ b[i];
39
+ return d === 0;
40
+ }
41
+ // sign: EZGH-Signature: t=<unix seconds>,v1=<hex HMAC-SHA256(secret, "<t>." + body)>, one v1 per secret.
42
+ export async function sign(secrets, t, body) {
43
+ const ts = Math.floor(t.getTime() / 1000);
44
+ const payload = concat(utf8(`${ts}.`), body);
45
+ const parts = [`t=${ts}`];
46
+ for (const s of secrets)
47
+ parts.push(`v1=${toHex(await mac(s, payload))}`);
48
+ return parts.join(",");
49
+ }
50
+ export const MAX_SIGNATURES = 8;
51
+ // parseSignature checks the header's shape and timestamp without the body, so a request with a
52
+ // malformed or stale signature is refused before its body is read. It throws
53
+ // SignatureError("invalid") for a malformed header (or more than 8 v1 values) and
54
+ // SignatureError("expired") when t is more than 300 s from now either way.
55
+ export function parseSignature(header, now) {
56
+ if (typeof header !== "string" || header.length > 1024)
57
+ throw new SignatureError("invalid", "The EZGH-Signature header is missing or malformed");
58
+ let t;
59
+ const signatures = [];
60
+ for (const raw of header.split(",")) {
61
+ const part = raw.trim();
62
+ const i = part.indexOf("=");
63
+ if (i < 0)
64
+ throw new SignatureError("invalid", "The EZGH-Signature header is malformed");
65
+ const k = part.slice(0, i);
66
+ const v = part.slice(i + 1);
67
+ if (k === "t") {
68
+ if (!/^\d{1,12}$/.test(v))
69
+ throw new SignatureError("invalid", "The EZGH-Signature timestamp is malformed");
70
+ t = Number(v);
71
+ }
72
+ else if (k === "v1" && /^[0-9a-fA-F]{64}$/.test(v)) {
73
+ if (signatures.length === MAX_SIGNATURES)
74
+ throw new SignatureError("invalid", `The EZGH-Signature header has more than ${MAX_SIGNATURES} signatures`);
75
+ signatures.push(fromHex(v.toLowerCase()));
76
+ }
77
+ }
78
+ if (t === undefined || signatures.length === 0)
79
+ throw new SignatureError("invalid", "The EZGH-Signature header is missing or malformed");
80
+ if (Math.abs(now.getTime() / 1000 - t) > MAX_SIGNATURE_AGE_SECONDS)
81
+ throw new SignatureError("expired", "The EZGH-Signature timestamp is more than 5 minutes from now");
82
+ return { t, signatures };
83
+ }
84
+ // verifyParsed checks a parsed signature against the body: one HMAC per secret, each candidate
85
+ // compared in constant time.
86
+ export async function verifyParsed(sig, secrets, body) {
87
+ const payload = concat(utf8(`${sig.t}.`), body);
88
+ let ok = false;
89
+ for (const s of secrets) {
90
+ const want = await mac(s, payload);
91
+ for (const got of sig.signatures)
92
+ if (equal(want, got))
93
+ ok = true;
94
+ }
95
+ if (!ok)
96
+ throw new SignatureError("invalid", "The EZGH-Signature doesn't match any signing secret");
97
+ }
98
+ // verify = parseSignature then verifyParsed.
99
+ export async function verify(header, secrets, body, now) {
100
+ await verifyParsed(parseSignature(header, now), secrets, body);
101
+ }
@@ -0,0 +1,4 @@
1
+ export declare function stepId(name: string, occurrence: number): Promise<string>;
2
+ export declare const validStepIdOverride: (s: string) => boolean;
3
+ export declare const validWorkflowName: (s: string) => boolean;
4
+ export declare const validRunKey: (s: string) => boolean;
@@ -0,0 +1,9 @@
1
+ import { toHex, utf8 } from "./bytes.js";
2
+ // stepId: lowercase hex of the first 16 bytes of SHA-256(name + "\0" + decimal occurrence).
3
+ export async function stepId(name, occurrence) {
4
+ const d = new Uint8Array(await crypto.subtle.digest("SHA-256", utf8(`${name}\u0000${occurrence}`)));
5
+ return toHex(d.subarray(0, 16));
6
+ }
7
+ export const validStepIdOverride = (s) => typeof s === "string" && /^[A-Za-z0-9._:-]{1,128}$/.test(s);
8
+ export const validWorkflowName = (s) => typeof s === "string" && /^[A-Za-z0-9_-]{1,64}$/.test(s);
9
+ export const validRunKey = validStepIdOverride;
@@ -0,0 +1,2 @@
1
+ export declare function shardOf(runId: string): number | undefined;
2
+ export declare function isInvocationToken(s: string): boolean;
@@ -0,0 +1,38 @@
1
+ import { fromBase64url } from "./bytes.js";
2
+ const uuid = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
3
+ // shardOf reads the shard (0–1023) from a v7 or v8 run ID: rand_a holds 0b00 and the 10-bit
4
+ // shard. It returns undefined for anything else (internal/protocol ShardOf).
5
+ export function shardOf(runId) {
6
+ if (typeof runId !== "string" || !uuid.test(runId))
7
+ return undefined;
8
+ const hex = runId.replace(/-/g, "");
9
+ const b6 = parseInt(hex.slice(12, 14), 16);
10
+ const b7 = parseInt(hex.slice(14, 16), 16);
11
+ const b8 = parseInt(hex.slice(16, 18), 16);
12
+ const version = b6 >> 4;
13
+ if ((version !== 7 && version !== 8) || (b8 & 0xc0) !== 0x80 || (b6 & 0x0c) !== 0)
14
+ return undefined;
15
+ return ((b6 & 0x03) << 8) | b7;
16
+ }
17
+ // isInvocationToken: "<shard 3 hex>.<run UUID>.<invocation ID>.<43 base64url secret>", the shard
18
+ // being the run ID's (internal/protocol ParseInvocationToken). SDKs pass tokens through; they
19
+ // check the shape only to fail fast.
20
+ export function isInvocationToken(s) {
21
+ if (typeof s !== "string")
22
+ return false;
23
+ const parts = s.split(".");
24
+ if (parts.length !== 4)
25
+ return false;
26
+ const [shard, runId, invocationId, secret] = parts;
27
+ if (!/^[0-9a-f]{3}$/.test(shard) || !/^inv_[a-z2-7]{26}$/.test(invocationId))
28
+ return false;
29
+ const runShard = shardOf(runId);
30
+ if (runShard === undefined || runShard !== parseInt(shard, 16))
31
+ return false;
32
+ try {
33
+ return fromBase64url(secret).length === 32;
34
+ }
35
+ catch {
36
+ return false;
37
+ }
38
+ }
@@ -0,0 +1,185 @@
1
+ export interface RetryPolicy {
2
+ maxAttempts: number;
3
+ initialMs: number;
4
+ maxMs: number;
5
+ multiplier: number;
6
+ }
7
+ export interface WireError {
8
+ code: string;
9
+ name: string;
10
+ message: string;
11
+ data?: unknown;
12
+ stack?: string;
13
+ cause?: WireError;
14
+ }
15
+ export interface JournalEntry {
16
+ seq: number;
17
+ stepId: string;
18
+ name: string;
19
+ kind: "run" | "sleep" | "value" | "callback" | "invoke" | "message" | (string & {});
20
+ status: "running" | "retrying" | "completed" | "failed" | "cancelled" | "sleeping" | "waiting" | (string & {});
21
+ attempt: number;
22
+ output?: unknown;
23
+ outputRef?: string;
24
+ error?: WireError;
25
+ token?: string;
26
+ createdSeq?: number;
27
+ queueId?: string;
28
+ key?: string;
29
+ timedOut?: boolean;
30
+ }
31
+ export interface Journal {
32
+ complete: boolean;
33
+ entries: JournalEntry[];
34
+ }
35
+ export interface ScheduleInfo {
36
+ id: string;
37
+ scheduledTime: string;
38
+ }
39
+ export interface RunInfo {
40
+ id: string;
41
+ runKey?: string;
42
+ workflow: string;
43
+ input?: unknown;
44
+ inputRef?: string;
45
+ attempt: number;
46
+ startedAt: string;
47
+ schedule?: ScheduleInfo;
48
+ }
49
+ export interface Cancel {
50
+ requestedAt: string;
51
+ graceUntil: string;
52
+ }
53
+ export interface Endpoints {
54
+ live: string;
55
+ api?: string;
56
+ }
57
+ export interface Invocation {
58
+ protocolVersion: string;
59
+ kind: "orchestrate" | "step" | "sync";
60
+ invocationId: string;
61
+ token: string;
62
+ endpoints: Endpoints;
63
+ run?: RunInfo;
64
+ journal?: Journal;
65
+ targetStepId?: string;
66
+ deadline: string;
67
+ cancel: Cancel | null;
68
+ traceparent?: string;
69
+ }
70
+ export interface PlannedStep {
71
+ stepId: string;
72
+ name: string;
73
+ retry: RetryPolicy;
74
+ timeoutMs?: number;
75
+ }
76
+ export type Command = {
77
+ type: "stepStarted";
78
+ stepId: string;
79
+ name: string;
80
+ attempt: number;
81
+ retry: RetryPolicy;
82
+ timeoutMs?: number;
83
+ } | {
84
+ type: "stepCompleted";
85
+ stepId: string;
86
+ name: string;
87
+ output: unknown;
88
+ } | {
89
+ type: "stepFailed";
90
+ stepId: string;
91
+ name: string;
92
+ attempt: number;
93
+ error: WireError;
94
+ retryable: boolean;
95
+ retryAfterMs?: number;
96
+ } | {
97
+ type: "valueRecorded";
98
+ stepId: string;
99
+ name: string;
100
+ value: unknown;
101
+ } | {
102
+ type: "sleep";
103
+ stepId: string;
104
+ name: string;
105
+ until: string;
106
+ } | {
107
+ type: "callbackCreated";
108
+ stepId: string;
109
+ name: string;
110
+ token: string;
111
+ timeoutMs: number;
112
+ } | {
113
+ type: "waitForCallback";
114
+ stepId: string;
115
+ } | {
116
+ type: "invoke";
117
+ stepId: string;
118
+ name: string;
119
+ workflow: string;
120
+ input?: unknown;
121
+ } | {
122
+ type: "planParallel";
123
+ steps: PlannedStep[];
124
+ } | {
125
+ type: "messageWaitCreated";
126
+ stepId: string;
127
+ name: string;
128
+ queueId: string;
129
+ key: string;
130
+ timeoutMs: number;
131
+ } | {
132
+ type: "waitForMessage";
133
+ stepId: string;
134
+ } | {
135
+ type: "runCompleted";
136
+ output: unknown;
137
+ } | {
138
+ type: "runFailed";
139
+ error: WireError;
140
+ causeStepId?: string;
141
+ } | {
142
+ type: "workflowNotFound";
143
+ workflow: string;
144
+ };
145
+ export interface Checkpoint {
146
+ invocationId: string;
147
+ seq: number;
148
+ commands: Command[];
149
+ }
150
+ export interface SDKInfo {
151
+ name: string;
152
+ version: string;
153
+ }
154
+ export interface InvocationResult {
155
+ commands: Command[];
156
+ deployment?: string;
157
+ sdk: SDKInfo;
158
+ }
159
+ export interface WorkflowInfo {
160
+ name: string;
161
+ retry?: RetryPolicy;
162
+ timeoutMs?: number;
163
+ }
164
+ export interface SyncReply {
165
+ protocolVersions: string[];
166
+ sdk: SDKInfo;
167
+ maxInvocationSeconds: number;
168
+ workflows: WorkflowInfo[];
169
+ deployment?: string;
170
+ }
171
+ export interface PollRequest {
172
+ app: string;
173
+ queue: string;
174
+ maxTasks: number;
175
+ workerId: string;
176
+ protocolVersions: string[];
177
+ sdk: SDKInfo;
178
+ workflows?: WorkflowInfo[];
179
+ }
180
+ export interface PollResponse {
181
+ invocations: Invocation[];
182
+ }
183
+ export interface HeartbeatResponse {
184
+ cancel: Cancel | null;
185
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,15 @@
1
+ export declare const MAX_ERROR_DEPTH = 8;
2
+ export declare const MAX_PLANNED_STEPS = 1000;
3
+ export declare const UUID: RegExp;
4
+ export declare const MESSAGE_KEY: RegExp;
5
+ export declare const MIN_MESSAGE_TIMEOUT_MS = 1000;
6
+ export declare const MAX_MESSAGE_TIMEOUT_MS = 2592000000;
7
+ export declare class InvalidMessage extends Error {
8
+ name: string;
9
+ }
10
+ export declare function validateRetry(p: unknown): void;
11
+ export declare function validateError(e: unknown): void;
12
+ export declare function validateCommand(cmd: unknown): void;
13
+ export declare function validateCheckpoint(cp: unknown): void;
14
+ export declare function validateInvocationResult(r: unknown): void;
15
+ export declare function validatePollRequest(r: unknown): void;