@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
|
@@ -4,17 +4,16 @@
|
|
|
4
4
|
* Full terms: see LICENSE.md.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
+
import type { LoopFrame } from '../checkpoint';
|
|
7
8
|
import type {
|
|
8
9
|
EvaluationScope,
|
|
9
10
|
ExecutionState,
|
|
10
11
|
ForEachLoopStep,
|
|
11
12
|
LoopStep,
|
|
12
|
-
Suspension,
|
|
13
13
|
WhileLoopStep,
|
|
14
14
|
} from '../workflow-types';
|
|
15
15
|
import { evaluateValue } from '../workflow-values';
|
|
16
16
|
|
|
17
|
-
import { wrapSuspensionContinuation } from './suspension-continuation';
|
|
18
17
|
import type { StepExecutorEnv } from './types';
|
|
19
18
|
|
|
20
19
|
type LoopScope = EvaluationScope;
|
|
@@ -26,21 +25,22 @@ type LoopScope = EvaluationScope;
|
|
|
26
25
|
* @param step The loop step configuration.
|
|
27
26
|
* @param state Mutable workflow execution state.
|
|
28
27
|
* @param path Path tokens locating this loop within the workflow.
|
|
29
|
-
* @param
|
|
30
|
-
*
|
|
28
|
+
* @param frame Frame returned when an iteration previously suspended; the
|
|
29
|
+
* loop resumes that iteration with the items and accumulator it recorded.
|
|
30
|
+
* @returns A frame if an iteration suspends, otherwise void.
|
|
31
31
|
*/
|
|
32
32
|
export async function executeLoop(
|
|
33
33
|
env: StepExecutorEnv,
|
|
34
34
|
step: LoopStep,
|
|
35
35
|
state: ExecutionState,
|
|
36
36
|
path: Array<number | string>,
|
|
37
|
-
|
|
38
|
-
): Promise<
|
|
37
|
+
frame?: LoopFrame,
|
|
38
|
+
): Promise<LoopFrame | void> {
|
|
39
39
|
if (step.loopType === 'for_each') {
|
|
40
|
-
return executeForEachLoop(env, step, state, path,
|
|
40
|
+
return executeForEachLoop(env, step, state, path, frame);
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
return executeWhileLoop(env, step, state, path,
|
|
43
|
+
return executeWhileLoop(env, step, state, path, frame);
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
async function executeForEachLoop(
|
|
@@ -48,64 +48,41 @@ async function executeForEachLoop(
|
|
|
48
48
|
step: ForEachLoopStep,
|
|
49
49
|
state: ExecutionState,
|
|
50
50
|
path: Array<number | string>,
|
|
51
|
-
|
|
52
|
-
): Promise<
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
let
|
|
63
|
-
|
|
64
|
-
for (let index = startIndex; index < iterable.length; index += 1) {
|
|
65
|
-
const item = iterable[index];
|
|
51
|
+
frame?: LoopFrame,
|
|
52
|
+
): Promise<LoopFrame | void> {
|
|
53
|
+
// The item list is resolved once, when the loop starts; a resumed loop
|
|
54
|
+
// keeps iterating over the same items even if `in` would now differ.
|
|
55
|
+
const items = frame
|
|
56
|
+
? (frame.items ?? [])
|
|
57
|
+
: await resolveItems(env, step, state);
|
|
58
|
+
let accumulator = frame
|
|
59
|
+
? frame.accumulator
|
|
60
|
+
: (step.accumulate?.initial ?? state.accumulator);
|
|
61
|
+
|
|
62
|
+
for (let index = frame?.index ?? 0; index < items.length; index += 1) {
|
|
63
|
+
const item = items[index];
|
|
66
64
|
const iterationState: ExecutionState = {
|
|
67
65
|
...state,
|
|
68
66
|
iteration: { item, index },
|
|
69
67
|
accumulator,
|
|
70
68
|
iterationStack: [...state.iterationStack, index],
|
|
71
69
|
};
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
accumulator
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
if (shouldStop) {
|
|
89
|
-
state.accumulator = accumulator;
|
|
90
|
-
if (step.accumulate && step.name) {
|
|
91
|
-
state.output[step.name] = { [step.accumulate.as]: accumulator };
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
return undefined;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
return executeForEachLoop(
|
|
98
|
-
env,
|
|
99
|
-
step,
|
|
100
|
-
{
|
|
101
|
-
...iterationState,
|
|
102
|
-
accumulator,
|
|
103
|
-
iterationStack: state.iterationStack,
|
|
104
|
-
},
|
|
105
|
-
path,
|
|
106
|
-
index + 1,
|
|
107
|
-
);
|
|
108
|
-
});
|
|
70
|
+
const child = await env.executeFlow(
|
|
71
|
+
step.steps,
|
|
72
|
+
iterationState,
|
|
73
|
+
[...path, index],
|
|
74
|
+
frame && index === frame.index ? frame.child : undefined,
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
if (child) {
|
|
78
|
+
return {
|
|
79
|
+
kind: 'loop',
|
|
80
|
+
stepId: step.id,
|
|
81
|
+
index,
|
|
82
|
+
items,
|
|
83
|
+
accumulator,
|
|
84
|
+
child,
|
|
85
|
+
};
|
|
109
86
|
}
|
|
110
87
|
|
|
111
88
|
const postScope = buildScope(
|
|
@@ -135,20 +112,28 @@ async function executeWhileLoop(
|
|
|
135
112
|
step: WhileLoopStep,
|
|
136
113
|
state: ExecutionState,
|
|
137
114
|
path: Array<number | string>,
|
|
138
|
-
|
|
139
|
-
): Promise<
|
|
140
|
-
let accumulator =
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
115
|
+
frame?: LoopFrame,
|
|
116
|
+
): Promise<LoopFrame | void> {
|
|
117
|
+
let accumulator = frame
|
|
118
|
+
? frame.accumulator
|
|
119
|
+
: (step.accumulate?.initial ?? state.accumulator);
|
|
120
|
+
|
|
121
|
+
for (let index = frame?.index ?? 0; ; index += 1) {
|
|
122
|
+
const resumedChild =
|
|
123
|
+
frame && index === frame.index ? frame.child : undefined;
|
|
124
|
+
|
|
125
|
+
// The guard of a resumed iteration already passed before it suspended.
|
|
126
|
+
if (!resumedChild) {
|
|
127
|
+
const conditionScope = buildScope(
|
|
128
|
+
env,
|
|
129
|
+
state,
|
|
130
|
+
{ item: undefined, index },
|
|
131
|
+
accumulator,
|
|
132
|
+
);
|
|
133
|
+
const shouldContinue = await evaluateValue(step.while, conditionScope);
|
|
134
|
+
if (!Boolean(shouldContinue)) {
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
152
137
|
}
|
|
153
138
|
|
|
154
139
|
const iterationState: ExecutionState = {
|
|
@@ -157,33 +142,15 @@ async function executeWhileLoop(
|
|
|
157
142
|
accumulator,
|
|
158
143
|
iterationStack: [...state.iterationStack, index],
|
|
159
144
|
};
|
|
160
|
-
const
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
iterationState,
|
|
170
|
-
{ item: undefined, index },
|
|
171
|
-
accumulator,
|
|
172
|
-
);
|
|
173
|
-
accumulator = await updateAccumulator(step, postScope, accumulator);
|
|
174
|
-
|
|
175
|
-
return executeWhileLoop(
|
|
176
|
-
env,
|
|
177
|
-
step,
|
|
178
|
-
{
|
|
179
|
-
...iterationState,
|
|
180
|
-
accumulator,
|
|
181
|
-
iterationStack: state.iterationStack,
|
|
182
|
-
},
|
|
183
|
-
path,
|
|
184
|
-
index + 1,
|
|
185
|
-
);
|
|
186
|
-
});
|
|
145
|
+
const child = await env.executeFlow(
|
|
146
|
+
step.steps,
|
|
147
|
+
iterationState,
|
|
148
|
+
[...path, index],
|
|
149
|
+
resumedChild,
|
|
150
|
+
);
|
|
151
|
+
|
|
152
|
+
if (child) {
|
|
153
|
+
return { kind: 'loop', stepId: step.id, index, accumulator, child };
|
|
187
154
|
}
|
|
188
155
|
|
|
189
156
|
const postScope = buildScope(
|
|
@@ -202,6 +169,22 @@ async function executeWhileLoop(
|
|
|
202
169
|
return undefined;
|
|
203
170
|
}
|
|
204
171
|
|
|
172
|
+
async function resolveItems(
|
|
173
|
+
env: StepExecutorEnv,
|
|
174
|
+
step: ForEachLoopStep,
|
|
175
|
+
state: ExecutionState,
|
|
176
|
+
): Promise<unknown[]> {
|
|
177
|
+
const items = await evaluateValue(step.forEach.in, {
|
|
178
|
+
input: state.input,
|
|
179
|
+
context: env.context.state,
|
|
180
|
+
output: state.output,
|
|
181
|
+
iteration: state.iteration,
|
|
182
|
+
accumulator: state.accumulator,
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
return Array.isArray(items) ? items : [];
|
|
186
|
+
}
|
|
187
|
+
|
|
205
188
|
function finalizeAccumulatorState(
|
|
206
189
|
step: LoopStep,
|
|
207
190
|
state: ExecutionState,
|