@hexabot-ai/agentic 3.4.0-beta.2 → 3.5.0-beta.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/README.md +67 -15
- package/dist/cjs/action/abstract-action.js +13 -1
- package/dist/cjs/checkpoint.js +301 -0
- package/dist/cjs/context.js +11 -27
- package/dist/cjs/dsl.types.js +3 -0
- package/dist/cjs/errors.js +116 -9
- package/dist/cjs/index.js +15 -6
- package/dist/cjs/resume-payload.js +257 -0
- package/dist/cjs/runner-runtime-control.js +181 -306
- package/dist/cjs/step-executors/conditional-executor.js +27 -29
- package/dist/cjs/step-executors/loop-executor.js +53 -62
- package/dist/cjs/step-executors/parallel-executor.js +169 -102
- package/dist/cjs/step-executors/task-executor.js +180 -96
- package/dist/cjs/utils/clone.js +73 -0
- package/dist/cjs/workflow-fingerprint.js +138 -0
- package/dist/cjs/workflow-runner.js +220 -155
- package/dist/cjs/workflow.js +24 -12
- package/dist/esm/action/abstract-action.js +14 -2
- package/dist/esm/checkpoint.js +293 -0
- package/dist/esm/context.js +11 -27
- package/dist/esm/dsl.types.js +3 -0
- package/dist/esm/errors.js +105 -6
- package/dist/esm/index.js +3 -3
- package/dist/esm/resume-payload.js +250 -0
- package/dist/esm/runner-runtime-control.js +179 -303
- package/dist/esm/step-executors/conditional-executor.js +27 -29
- package/dist/esm/step-executors/loop-executor.js +53 -62
- package/dist/esm/step-executors/parallel-executor.js +165 -98
- package/dist/esm/step-executors/task-executor.js +181 -97
- package/dist/esm/utils/clone.js +67 -0
- package/dist/esm/workflow-fingerprint.js +134 -0
- package/dist/esm/workflow-runner.js +220 -155
- package/dist/esm/workflow.js +24 -12
- package/dist/types/action/abstract-action.d.ts.map +1 -1
- package/dist/types/action/action.types.d.ts +0 -14
- package/dist/types/action/action.types.d.ts.map +1 -1
- package/dist/types/checkpoint.d.ts +188 -0
- package/dist/types/checkpoint.d.ts.map +1 -0
- package/dist/types/context.d.ts +45 -11
- package/dist/types/context.d.ts.map +1 -1
- package/dist/types/dsl.types.d.ts.map +1 -1
- package/dist/types/errors.d.ts +77 -3
- package/dist/types/errors.d.ts.map +1 -1
- package/dist/types/index.d.ts +6 -7
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/resume-payload.d.ts +69 -0
- package/dist/types/resume-payload.d.ts.map +1 -0
- package/dist/types/runner-runtime-control.d.ts +63 -51
- package/dist/types/runner-runtime-control.d.ts.map +1 -1
- package/dist/types/step-executors/conditional-executor.d.ts +6 -3
- package/dist/types/step-executors/conditional-executor.d.ts.map +1 -1
- package/dist/types/step-executors/loop-executor.d.ts +6 -4
- package/dist/types/step-executors/loop-executor.d.ts.map +1 -1
- package/dist/types/step-executors/parallel-executor.d.ts +11 -3
- package/dist/types/step-executors/parallel-executor.d.ts.map +1 -1
- package/dist/types/step-executors/task-executor.d.ts +11 -4
- package/dist/types/step-executors/task-executor.d.ts.map +1 -1
- package/dist/types/step-executors/types.d.ts +21 -13
- package/dist/types/step-executors/types.d.ts.map +1 -1
- package/dist/types/utils/clone.d.ts +33 -0
- package/dist/types/utils/clone.d.ts.map +1 -0
- package/dist/types/workflow-event-emitter.d.ts +29 -5
- package/dist/types/workflow-event-emitter.d.ts.map +1 -1
- package/dist/types/workflow-fingerprint.d.ts +14 -0
- package/dist/types/workflow-fingerprint.d.ts.map +1 -0
- package/dist/types/workflow-runner.d.ts +83 -41
- package/dist/types/workflow-runner.d.ts.map +1 -1
- package/dist/types/workflow-types.d.ts +25 -54
- package/dist/types/workflow-types.d.ts.map +1 -1
- package/dist/types/workflow.d.ts +24 -9
- package/dist/types/workflow.d.ts.map +1 -1
- package/examples/defs-bindings-agent/bindings.ts +1 -1
- package/examples/defs-bindings-agent/workflow.ts +3 -2
- package/examples/full/actions/await-user-input.ts +3 -2
- package/examples/full/actions/call-llm.ts +18 -18
- package/examples/full/actions/create-ticket.ts +1 -2
- package/examples/full/actions/decision-router.ts +6 -2
- package/examples/full/actions/get-calendar-events.ts +1 -2
- package/examples/full/actions/get-user-profile.ts +1 -2
- package/examples/full/actions/query-memory.ts +1 -2
- package/examples/full/actions/search-web.ts +1 -2
- package/examples/full/actions/send-email.ts +3 -2
- package/examples/full/workflow.ts +3 -2
- package/examples/loop/actions/await-reply.ts +2 -7
- package/examples/loop/workflow.ts +4 -2
- package/examples/suspend-resume/actions/wait-for-user.ts +11 -9
- package/examples/suspend-resume/workflow.ts +51 -11
- package/package.json +3 -3
- package/src/__tests__/checkpoint.test.ts +2568 -0
- package/src/__tests__/resume-payload.test.ts +245 -0
- package/src/__tests__/runner-runtime-control.test.ts +265 -0
- package/src/__tests__/workflow-fingerprint.test.ts +165 -0
- package/src/__tests__/workflow-runner.test.ts +167 -144
- package/src/__tests__/workflow.test.ts +97 -6
- package/src/action/abstract-action.ts +21 -2
- package/src/action/action.types.ts +0 -12
- package/src/checkpoint.ts +561 -0
- package/src/context.ts +51 -41
- package/src/dsl.types.ts +3 -0
- package/src/errors.ts +161 -8
- package/src/index.ts +33 -14
- package/src/resume-payload.ts +326 -0
- package/src/runner-runtime-control.ts +222 -456
- package/src/step-executors/conditional-executor.test.ts +77 -46
- package/src/step-executors/conditional-executor.ts +47 -40
- package/src/step-executors/loop-executor.test.ts +106 -92
- package/src/step-executors/loop-executor.ts +84 -101
- package/src/step-executors/parallel-executor.test.ts +300 -89
- package/src/step-executors/parallel-executor.ts +243 -125
- package/src/step-executors/task-executor.test.ts +321 -51
- package/src/step-executors/task-executor.ts +232 -145
- package/src/step-executors/types.ts +23 -22
- package/src/utils/clone.ts +75 -0
- package/src/workflow-event-emitter.ts +32 -6
- package/src/workflow-fingerprint.ts +159 -0
- package/src/workflow-runner.ts +325 -209
- package/src/workflow-types.ts +25 -56
- package/src/workflow.ts +41 -34
- package/dist/cjs/step-executors/suspension-continuation.js +0 -27
- package/dist/cjs/suspension-rebuilder.js +0 -265
- package/dist/cjs/utils/deferred.js +0 -17
- package/dist/esm/step-executors/suspension-continuation.js +0 -24
- package/dist/esm/suspension-rebuilder.js +0 -260
- package/dist/esm/utils/deferred.js +0 -14
- package/dist/types/step-executors/suspension-continuation.d.ts +0 -10
- package/dist/types/step-executors/suspension-continuation.d.ts.map +0 -1
- package/dist/types/suspension-rebuilder.d.ts +0 -67
- package/dist/types/suspension-rebuilder.d.ts.map +0 -1
- package/dist/types/utils/deferred.d.ts +0 -7
- package/dist/types/utils/deferred.d.ts.map +0 -1
- package/src/__tests__/suspension-rebuilder.test.ts +0 -404
- package/src/step-executors/suspension-continuation.ts +0 -31
- package/src/suspension-rebuilder.ts +0 -446
- package/src/utils/deferred.ts +0 -23
package/src/context.ts
CHANGED
|
@@ -4,6 +4,9 @@
|
|
|
4
4
|
* Full terms: see LICENSE.md.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
+
import type { ZodType } from 'zod';
|
|
8
|
+
|
|
9
|
+
import { cloneRecord } from './utils/clone';
|
|
7
10
|
import type {
|
|
8
11
|
EventEmitterLike,
|
|
9
12
|
WorkflowEventEmitterLike,
|
|
@@ -15,7 +18,7 @@ import type {
|
|
|
15
18
|
* - running: set when `start` or `resume` begins executing steps.
|
|
16
19
|
* - suspended: an action awaited `workflow.suspend`; `resume` moves back to running.
|
|
17
20
|
* - finished: all steps completed and outputs were evaluated successfully.
|
|
18
|
-
* - failed: an uncaught error bubbled out of a step or
|
|
21
|
+
* - failed: an uncaught error bubbled out of a step or the output mapping.
|
|
19
22
|
*/
|
|
20
23
|
export enum EWorkflowRunStatus {
|
|
21
24
|
IDLE = 'idle',
|
|
@@ -54,10 +57,22 @@ export type ActionStatus =
|
|
|
54
57
|
| 'cancelled'
|
|
55
58
|
| 'skipped';
|
|
56
59
|
|
|
57
|
-
export interface SuspensionOptions {
|
|
60
|
+
export interface SuspensionOptions<T = unknown> {
|
|
58
61
|
key?: string;
|
|
59
62
|
reason?: string;
|
|
60
63
|
data?: unknown;
|
|
64
|
+
/**
|
|
65
|
+
* Schema the resume payload must match. It is stored on the wait as a
|
|
66
|
+
* relaxed JSON Schema, so hosts can refuse a bad payload before resuming,
|
|
67
|
+
* and the payload `suspend()` resolves with is parsed through it. A payload
|
|
68
|
+
* that fails it is refused and the wait stays open.
|
|
69
|
+
*
|
|
70
|
+
* The payload is parsed in its JSON form, as the checkpoint stores it: a
|
|
71
|
+
* `Date` arrives as its ISO string. `suspend()` throws when part of the
|
|
72
|
+
* schema is a type JSON cannot carry, such as `z.date()`; accept the JSON
|
|
73
|
+
* form instead, e.g. `z.coerce.date()` or `z.iso.datetime()`.
|
|
74
|
+
*/
|
|
75
|
+
accepts?: ZodType<T>;
|
|
61
76
|
}
|
|
62
77
|
|
|
63
78
|
export interface ActionSnapshot {
|
|
@@ -90,20 +105,22 @@ export interface WorkflowSnapshot {
|
|
|
90
105
|
}
|
|
91
106
|
|
|
92
107
|
export interface WorkflowRuntimeControl {
|
|
93
|
-
readonly status: WorkflowRunStatus;
|
|
94
|
-
readonly resumeData: unknown;
|
|
95
108
|
/**
|
|
96
109
|
* Suspends the currently running action and returns a promise that settles when the workflow resumes.
|
|
97
110
|
*
|
|
98
111
|
* @param options - Optional metadata describing why the suspension occurred.
|
|
99
|
-
* @returns Promise resolved with the
|
|
112
|
+
* @returns Promise resolved with the JSON copy of the payload the run was
|
|
113
|
+
* resumed with, or `undefined` when it was resumed without one; parsed
|
|
114
|
+
* through `options.accepts` when given. It rejects with a
|
|
115
|
+
* `WorkflowResumeRejectedError` when that payload fails `options.accepts`.
|
|
116
|
+
* @throws {TypeError} When `options.accepts` uses a type JSON cannot carry.
|
|
100
117
|
*/
|
|
101
|
-
suspend<T = unknown>(options?: SuspensionOptions): Promise<T>;
|
|
118
|
+
suspend<T = unknown>(options?: SuspensionOptions<T>): Promise<T>;
|
|
102
119
|
/**
|
|
103
120
|
* Reports whether the next {@link suspend} call in the currently running
|
|
104
|
-
* action already has a recorded resume result. This happens
|
|
105
|
-
*
|
|
106
|
-
*
|
|
121
|
+
* action already has a recorded resume result. This happens when a resumed
|
|
122
|
+
* step re-runs its action body from the top: `suspend()` calls it already
|
|
123
|
+
* made resolve immediately with their recorded payloads. Actions that
|
|
107
124
|
* perform side effects before suspending must skip those side effects when
|
|
108
125
|
* this returns `true`, otherwise they run once per resume.
|
|
109
126
|
*
|
|
@@ -111,8 +128,21 @@ export interface WorkflowRuntimeControl {
|
|
|
111
128
|
* @returns `true` when the upcoming suspension resolves from a recorded result.
|
|
112
129
|
*/
|
|
113
130
|
hasRecordedResult(key?: string): boolean;
|
|
114
|
-
|
|
115
|
-
|
|
131
|
+
/**
|
|
132
|
+
* Record where the running step's suspend cursor stands, before an action
|
|
133
|
+
* run starts its attempts.
|
|
134
|
+
*
|
|
135
|
+
* Suspend keys are positional within a body, so whoever retries a body
|
|
136
|
+
* must rewind the cursor before each attempt: the retry then reproduces the
|
|
137
|
+
* keys of the first attempt and resolves from the recorded results, instead
|
|
138
|
+
* of suspending on new ones. {@link AbstractAction} does this; an action
|
|
139
|
+
* with its own retry loop should too. The rewind point is where the run
|
|
140
|
+
* started, so an action run nested inside a body never rewinds the body.
|
|
141
|
+
*
|
|
142
|
+
* @returns A function rewinding the cursor to the recorded position. It
|
|
143
|
+
* does nothing once the step has ended.
|
|
144
|
+
*/
|
|
145
|
+
markSuspendCursor?(): () => void;
|
|
116
146
|
}
|
|
117
147
|
|
|
118
148
|
/**
|
|
@@ -146,7 +176,7 @@ export abstract class BaseWorkflowContext<
|
|
|
146
176
|
* Override to filter or reshape the exposed state.
|
|
147
177
|
*/
|
|
148
178
|
snapshot(): Record<string, unknown> {
|
|
149
|
-
return
|
|
179
|
+
return cloneRecord(this.state ?? {});
|
|
150
180
|
}
|
|
151
181
|
|
|
152
182
|
/**
|
|
@@ -163,6 +193,15 @@ export abstract class BaseWorkflowContext<
|
|
|
163
193
|
return this._workflowControl;
|
|
164
194
|
}
|
|
165
195
|
|
|
196
|
+
/**
|
|
197
|
+
* Reads the runtime control without throwing when none is attached.
|
|
198
|
+
*
|
|
199
|
+
* @returns The attached runtime control, or `undefined` outside a run.
|
|
200
|
+
*/
|
|
201
|
+
getWorkflowRuntime(): WorkflowRuntimeControl | undefined {
|
|
202
|
+
return this._workflowControl;
|
|
203
|
+
}
|
|
204
|
+
|
|
166
205
|
/**
|
|
167
206
|
* Attaches or detaches the runtime control object.
|
|
168
207
|
*
|
|
@@ -173,32 +212,3 @@ export abstract class BaseWorkflowContext<
|
|
|
173
212
|
this._workflowControl = control;
|
|
174
213
|
}
|
|
175
214
|
}
|
|
176
|
-
|
|
177
|
-
const safeCloneRecord = (
|
|
178
|
-
value: Record<string, unknown>,
|
|
179
|
-
): Record<string, unknown> => {
|
|
180
|
-
if (!value) {
|
|
181
|
-
return {};
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
if (typeof structuredClone === 'function') {
|
|
185
|
-
try {
|
|
186
|
-
return structuredClone(value) as Record<string, unknown>;
|
|
187
|
-
} catch {
|
|
188
|
-
// Fall through to JSON clone below.
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
try {
|
|
193
|
-
return JSON.parse(JSON.stringify(value)) as Record<string, unknown>;
|
|
194
|
-
} catch {
|
|
195
|
-
const shallow: Record<string, unknown> = {};
|
|
196
|
-
for (const [key, entry] of Object.entries(value)) {
|
|
197
|
-
if (typeof entry !== 'function') {
|
|
198
|
-
shallow[key] = entry;
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
return shallow;
|
|
203
|
-
}
|
|
204
|
-
};
|
package/src/dsl.types.ts
CHANGED
|
@@ -253,6 +253,9 @@ const ConditionalWhenSchema: z.ZodType<ConditionalBranch> = z.lazy(() =>
|
|
|
253
253
|
);
|
|
254
254
|
const ConditionalElseSchema: z.ZodType<ConditionalBranch> = z.lazy(() =>
|
|
255
255
|
z.strictObject({
|
|
256
|
+
// Refusing `condition` here keeps a `when` branch with a bad condition
|
|
257
|
+
// from also matching as an `else` branch, so its own issue is reported.
|
|
258
|
+
condition: z.never().optional(),
|
|
256
259
|
else: z.unknown().optional(),
|
|
257
260
|
steps: z.array(FlowStepSchema),
|
|
258
261
|
}),
|
package/src/errors.ts
CHANGED
|
@@ -11,18 +11,145 @@ export class WorkflowCancellationError extends Error {
|
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
/** Base class for every reason a suspended run cannot be resumed. */
|
|
15
|
+
export abstract class WorkflowResumeError extends Error {}
|
|
16
|
+
|
|
17
|
+
export type WorkflowCheckpointInvalidCode =
|
|
18
|
+
| 'missing'
|
|
19
|
+
| 'malformed'
|
|
20
|
+
| 'unsupported_version'
|
|
21
|
+
| 'structure';
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* The checkpoint cannot be used: nothing was persisted, its shape is wrong,
|
|
25
|
+
* its format version is unsupported, or its frames do not line up with the
|
|
26
|
+
* compiled flow they claim to describe.
|
|
27
|
+
*/
|
|
28
|
+
export class WorkflowCheckpointInvalidError extends WorkflowResumeError {
|
|
29
|
+
public readonly code: WorkflowCheckpointInvalidCode;
|
|
30
|
+
|
|
31
|
+
/** Location inside the checkpoint where validation failed, when known. */
|
|
32
|
+
public readonly path?: Array<string | number>;
|
|
33
|
+
|
|
34
|
+
/** Individual schema issues, for `malformed` checkpoints. */
|
|
35
|
+
public readonly issues?: string[];
|
|
36
|
+
|
|
37
|
+
constructor(
|
|
38
|
+
code: WorkflowCheckpointInvalidCode,
|
|
39
|
+
message: string,
|
|
40
|
+
options?: { path?: Array<string | number>; issues?: string[] },
|
|
41
|
+
) {
|
|
42
|
+
super(message);
|
|
43
|
+
this.name = 'WorkflowCheckpointInvalidError';
|
|
44
|
+
this.code = code;
|
|
45
|
+
this.path = options?.path;
|
|
46
|
+
this.issues = options?.issues;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* The compiled definition no longer matches the one the checkpoint was taken
|
|
52
|
+
* against, so its frames cannot be trusted to point at the same steps.
|
|
53
|
+
*/
|
|
54
|
+
export class WorkflowDefinitionDriftError extends WorkflowResumeError {
|
|
55
|
+
public readonly expected: string;
|
|
56
|
+
|
|
57
|
+
public readonly actual: string;
|
|
58
|
+
|
|
59
|
+
constructor(expected: string, actual: string) {
|
|
60
|
+
super(
|
|
61
|
+
'Workflow definition changed since this run was suspended ' +
|
|
62
|
+
`(checkpoint fingerprint ${expected}, current ${actual}).`,
|
|
63
|
+
);
|
|
64
|
+
this.name = 'WorkflowDefinitionDriftError';
|
|
65
|
+
this.expected = expected;
|
|
66
|
+
this.actual = actual;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Several waits are open and the resume did not say which one it satisfies. */
|
|
71
|
+
export class WorkflowWaitAmbiguousError extends WorkflowResumeError {
|
|
72
|
+
public readonly openWaitIds: string[];
|
|
73
|
+
|
|
74
|
+
constructor(openWaitIds: string[]) {
|
|
75
|
+
super(
|
|
76
|
+
`Workflow run is waiting on ${openWaitIds.length} suspensions; pass a ` +
|
|
77
|
+
`waitId to choose one (${openWaitIds.join(', ')}).`,
|
|
78
|
+
);
|
|
79
|
+
this.name = 'WorkflowWaitAmbiguousError';
|
|
80
|
+
this.openWaitIds = openWaitIds;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** The run is not waiting on the requested suspension. */
|
|
85
|
+
export class WorkflowWaitNotFoundError extends WorkflowResumeError {
|
|
86
|
+
public readonly waitId: string;
|
|
87
|
+
|
|
88
|
+
public readonly openWaitIds: string[];
|
|
89
|
+
|
|
90
|
+
constructor(waitId: string, openWaitIds: string[]) {
|
|
91
|
+
super(
|
|
92
|
+
`Workflow run is not waiting on "${waitId}"` +
|
|
93
|
+
(openWaitIds.length > 0
|
|
94
|
+
? ` (open waits: ${openWaitIds.join(', ')}).`
|
|
95
|
+
: ' (no open waits).'),
|
|
96
|
+
);
|
|
97
|
+
this.name = 'WorkflowWaitNotFoundError';
|
|
98
|
+
this.waitId = waitId;
|
|
99
|
+
this.openWaitIds = openWaitIds;
|
|
18
100
|
}
|
|
19
101
|
}
|
|
20
102
|
|
|
21
|
-
|
|
103
|
+
/**
|
|
104
|
+
* The resume payload was refused. The wait stays open under the same
|
|
105
|
+
* `waitId`, so it can be resumed again, and the run's checkpoint, snapshot
|
|
106
|
+
* and step log are left as they were. Events already emitted by
|
|
107
|
+
* a body that refused the payload stay emitted, and its side effects,
|
|
108
|
+
* including writes to context state, are not undone.
|
|
109
|
+
*
|
|
110
|
+
* The runtime raises it when a payload does not match the `accepts` schema of
|
|
111
|
+
* the wait. An action may throw it itself, after its `suspend()` call
|
|
112
|
+
* resolved, to refuse a payload for reasons a schema cannot express.
|
|
113
|
+
*/
|
|
114
|
+
export class WorkflowResumeRejectedError extends WorkflowResumeError {
|
|
115
|
+
/** Individual schema issues, when a schema refused the payload. */
|
|
116
|
+
public readonly issues?: string[];
|
|
117
|
+
|
|
118
|
+
constructor(message: string, options?: { issues?: string[] }) {
|
|
119
|
+
super(message);
|
|
120
|
+
this.name = 'WorkflowResumeRejectedError';
|
|
121
|
+
this.issues = options?.issues;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* A resumed action body did not replay the way it ran before it suspended,
|
|
127
|
+
* so the results recorded for it cannot be trusted.
|
|
128
|
+
*/
|
|
129
|
+
export class NonDeterministicWorkflowError extends Error {
|
|
130
|
+
constructor(message: string) {
|
|
131
|
+
super(message);
|
|
132
|
+
this.name = 'NonDeterministicWorkflowError';
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// Errors that cross into action code are also matched by name: an extension
|
|
137
|
+
// may import the other (CJS or ESM) build of this package, whose classes are
|
|
138
|
+
// distinct from these.
|
|
139
|
+
const isNamedError = (error: unknown, name: string): boolean =>
|
|
140
|
+
error instanceof Error && error.name === name;
|
|
141
|
+
|
|
142
|
+
export const isWorkflowResumeRejectedError = (
|
|
143
|
+
error: unknown,
|
|
144
|
+
): error is WorkflowResumeRejectedError =>
|
|
145
|
+
error instanceof WorkflowResumeRejectedError ||
|
|
146
|
+
isNamedError(error, 'WorkflowResumeRejectedError');
|
|
147
|
+
|
|
148
|
+
export const isNonDeterministicWorkflowError = (
|
|
22
149
|
error: unknown,
|
|
23
|
-
): error is
|
|
24
|
-
error instanceof
|
|
25
|
-
(error
|
|
150
|
+
): error is NonDeterministicWorkflowError =>
|
|
151
|
+
error instanceof NonDeterministicWorkflowError ||
|
|
152
|
+
isNamedError(error, 'NonDeterministicWorkflowError');
|
|
26
153
|
|
|
27
154
|
export const getAbortReason = (signal: AbortSignal): Error => {
|
|
28
155
|
if (signal.reason instanceof Error) {
|
|
@@ -41,3 +168,29 @@ export const throwIfAborted = (signal: AbortSignal): void => {
|
|
|
41
168
|
throw getAbortReason(signal);
|
|
42
169
|
}
|
|
43
170
|
};
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Create a controller that aborts along with a parent signal, so a child
|
|
174
|
+
* scope can be cancelled on its own without cancelling the parent.
|
|
175
|
+
*
|
|
176
|
+
* @param parent Signal whose abort propagates to the new controller.
|
|
177
|
+
* @returns The controller, and a function detaching it from `parent`.
|
|
178
|
+
*/
|
|
179
|
+
export const createLinkedAbortController = (
|
|
180
|
+
parent: AbortSignal,
|
|
181
|
+
): { controller: AbortController; unlink: () => void } => {
|
|
182
|
+
const controller = new AbortController();
|
|
183
|
+
if (parent.aborted) {
|
|
184
|
+
controller.abort(getAbortReason(parent));
|
|
185
|
+
|
|
186
|
+
return { controller, unlink: () => undefined };
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
const onAbort = () => controller.abort(getAbortReason(parent));
|
|
190
|
+
parent.addEventListener('abort', onAbort, { once: true });
|
|
191
|
+
|
|
192
|
+
return {
|
|
193
|
+
controller,
|
|
194
|
+
unlink: () => parent.removeEventListener('abort', onAbort),
|
|
195
|
+
};
|
|
196
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -13,7 +13,6 @@ export type { DefineActionParams } from './action/action';
|
|
|
13
13
|
export type {
|
|
14
14
|
Action,
|
|
15
15
|
ActionExecutionArgs,
|
|
16
|
-
ActionExecutionOutcome,
|
|
17
16
|
ActionMetadata,
|
|
18
17
|
Actions,
|
|
19
18
|
InferActionArgs,
|
|
@@ -22,7 +21,6 @@ export type {
|
|
|
22
21
|
InferActionInput,
|
|
23
22
|
InferActionOutput,
|
|
24
23
|
InferActionSettings,
|
|
25
|
-
SuspensionNotice,
|
|
26
24
|
} from './action/action.types';
|
|
27
25
|
|
|
28
26
|
export {
|
|
@@ -60,9 +58,8 @@ export {
|
|
|
60
58
|
WorkflowRunner,
|
|
61
59
|
type FlowStepPath,
|
|
62
60
|
type WorkflowCompileOptions,
|
|
63
|
-
type WorkflowResumeResult,
|
|
64
61
|
type WorkflowRunOptions,
|
|
65
|
-
type
|
|
62
|
+
type WorkflowRunResult,
|
|
66
63
|
} from './workflow';
|
|
67
64
|
|
|
68
65
|
export { StepType } from './workflow-event-emitter';
|
|
@@ -88,17 +85,43 @@ export type {
|
|
|
88
85
|
CompiledWorkflow,
|
|
89
86
|
EvaluationScope,
|
|
90
87
|
ExecutionState,
|
|
91
|
-
|
|
88
|
+
ResumeRejection,
|
|
92
89
|
RunnerResumeArgs,
|
|
93
90
|
RunnerStartArgs,
|
|
94
|
-
|
|
95
|
-
ResumeResult as WorkflowResumeOutcome,
|
|
96
|
-
StartResult as WorkflowStartOutcome,
|
|
91
|
+
SuspendedResult,
|
|
97
92
|
} from './workflow-types';
|
|
98
93
|
|
|
99
|
-
export {
|
|
94
|
+
export {
|
|
95
|
+
CHECKPOINT_VERSION,
|
|
96
|
+
collectWaits,
|
|
97
|
+
validateCheckpoint,
|
|
98
|
+
workflowCheckpointSchema,
|
|
99
|
+
type CheckpointValidationResult,
|
|
100
|
+
type ConditionalFrame,
|
|
101
|
+
type LoopFrame,
|
|
102
|
+
type ParallelBranchFrame,
|
|
103
|
+
type ParallelFrame,
|
|
104
|
+
type RecordedResult,
|
|
105
|
+
type SequenceFrame,
|
|
106
|
+
type StepFrame,
|
|
107
|
+
type TaskFrame,
|
|
108
|
+
type WaitInfo,
|
|
109
|
+
type WorkflowCheckpoint,
|
|
110
|
+
} from './checkpoint';
|
|
111
|
+
|
|
112
|
+
export { fingerprintWorkflow } from './workflow-fingerprint';
|
|
100
113
|
|
|
101
|
-
export {
|
|
114
|
+
export {
|
|
115
|
+
NonDeterministicWorkflowError,
|
|
116
|
+
WorkflowCancellationError,
|
|
117
|
+
WorkflowCheckpointInvalidError,
|
|
118
|
+
WorkflowDefinitionDriftError,
|
|
119
|
+
WorkflowResumeError,
|
|
120
|
+
WorkflowResumeRejectedError,
|
|
121
|
+
WorkflowWaitAmbiguousError,
|
|
122
|
+
WorkflowWaitNotFoundError,
|
|
123
|
+
type WorkflowCheckpointInvalidCode,
|
|
124
|
+
} from './errors';
|
|
102
125
|
|
|
103
126
|
export {
|
|
104
127
|
compileValue,
|
|
@@ -111,10 +134,6 @@ export {
|
|
|
111
134
|
type JsonataFunctionRegistry,
|
|
112
135
|
} from './workflow-values';
|
|
113
136
|
|
|
114
|
-
export { createDeferred } from './utils/deferred';
|
|
115
|
-
|
|
116
|
-
export type { Deferred } from './utils/deferred';
|
|
117
|
-
|
|
118
137
|
export {
|
|
119
138
|
assertSnakeCaseName,
|
|
120
139
|
isSnakeCaseName,
|