@hexabot-ai/agentic 3.2.2 → 3.2.4-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/dist/cjs/bindings/base-binding.js +98 -25
- package/dist/cjs/dsl.types.js +141 -34
- package/dist/cjs/index.js +3 -1
- package/dist/cjs/runner-runtime-control.js +12 -0
- package/dist/cjs/step-executors/parallel-executor.js +5 -0
- package/dist/cjs/validation-issue.js +10 -0
- package/dist/cjs/workflow-compiler.js +3 -2
- package/dist/cjs/workflow-values.js +9 -8
- package/dist/cjs/workflow.js +3 -2
- package/dist/esm/bindings/base-binding.js +98 -25
- package/dist/esm/dsl.types.js +141 -34
- package/dist/esm/index.js +1 -0
- package/dist/esm/runner-runtime-control.js +12 -0
- package/dist/esm/step-executors/parallel-executor.js +5 -0
- package/dist/esm/validation-issue.js +6 -0
- package/dist/esm/workflow-compiler.js +3 -2
- package/dist/esm/workflow-values.js +9 -8
- package/dist/esm/workflow.js +3 -2
- package/dist/types/bindings/base-binding.d.ts +2 -1
- package/dist/types/bindings/base-binding.d.ts.map +1 -1
- package/dist/types/context.d.ts +12 -0
- package/dist/types/context.d.ts.map +1 -1
- package/dist/types/dsl.types.d.ts +4 -1
- package/dist/types/dsl.types.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/runner-runtime-control.d.ts +1 -0
- package/dist/types/runner-runtime-control.d.ts.map +1 -1
- package/dist/types/validation-issue.d.ts +16 -0
- package/dist/types/validation-issue.d.ts.map +1 -0
- package/dist/types/workflow-compiler.d.ts.map +1 -1
- package/dist/types/workflow-types.d.ts +17 -2
- package/dist/types/workflow-types.d.ts.map +1 -1
- package/dist/types/workflow-values.d.ts +2 -8
- package/dist/types/workflow-values.d.ts.map +1 -1
- package/dist/types/workflow.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/validation.test.ts +235 -17
- package/src/__tests__/workflow-runner.test.ts +185 -0
- package/src/__tests__/workflow-values.test.ts +26 -0
- package/src/bindings/base-binding.ts +116 -62
- package/src/context.ts +12 -0
- package/src/dsl.types.ts +225 -40
- package/src/index.ts +6 -0
- package/src/runner-runtime-control.ts +15 -0
- package/src/step-executors/parallel-executor.ts +6 -0
- package/src/validation-issue.ts +38 -0
- package/src/workflow-compiler.ts +3 -2
- package/src/workflow-types.ts +34 -4
- package/src/workflow-values.ts +19 -20
- package/src/workflow.ts +3 -2
|
@@ -19,9 +19,18 @@ const hasBindingsConfigured = (workflow) => {
|
|
|
19
19
|
const hasNestedBindings = Object.values(defs).some((definition) => definition.bindings && Object.keys(definition.bindings).length > 0);
|
|
20
20
|
return hasNonTaskDefs || hasNestedBindings;
|
|
21
21
|
};
|
|
22
|
-
const
|
|
22
|
+
const toBindingSettingsIssues = (zodIssues, defName) => zodIssues.map((issue) => {
|
|
23
23
|
const path = issue.path.join('.') || '<root>';
|
|
24
|
-
return
|
|
24
|
+
return {
|
|
25
|
+
code: 'binding_settings',
|
|
26
|
+
message: `defs.${defName}.settings.${path}: ${issue.message}`,
|
|
27
|
+
path: [
|
|
28
|
+
'defs',
|
|
29
|
+
defName,
|
|
30
|
+
'settings',
|
|
31
|
+
...issue.path.filter((segment) => typeof segment === 'string' || typeof segment === 'number'),
|
|
32
|
+
],
|
|
33
|
+
};
|
|
25
34
|
});
|
|
26
35
|
const collectDuplicateReferences = (refs) => {
|
|
27
36
|
const seen = new Set();
|
|
@@ -49,7 +58,7 @@ const collectBindingRefs = (bindings) => {
|
|
|
49
58
|
return refs;
|
|
50
59
|
};
|
|
51
60
|
const detectBindingCycles = (defs) => {
|
|
52
|
-
const
|
|
61
|
+
const issues = [];
|
|
53
62
|
const reportedCycles = new Set();
|
|
54
63
|
const states = new Map();
|
|
55
64
|
const stack = [];
|
|
@@ -68,7 +77,11 @@ const detectBindingCycles = (defs) => {
|
|
|
68
77
|
const cycleKey = cyclePath.join('->');
|
|
69
78
|
if (!reportedCycles.has(cycleKey)) {
|
|
70
79
|
reportedCycles.add(cycleKey);
|
|
71
|
-
|
|
80
|
+
issues.push({
|
|
81
|
+
code: 'binding_cycle',
|
|
82
|
+
message: `defs.${defName}.bindings: Circular binding reference detected (${cyclePath.join(' -> ')}).`,
|
|
83
|
+
path: ['defs', defName, 'bindings'],
|
|
84
|
+
});
|
|
72
85
|
}
|
|
73
86
|
return;
|
|
74
87
|
}
|
|
@@ -87,16 +100,22 @@ const detectBindingCycles = (defs) => {
|
|
|
87
100
|
for (const defName of defNames) {
|
|
88
101
|
visit(defName);
|
|
89
102
|
}
|
|
90
|
-
return
|
|
103
|
+
return issues;
|
|
91
104
|
};
|
|
92
|
-
const
|
|
105
|
+
const missingActionIssue = (defName, actionName) => ({
|
|
106
|
+
code: 'missing_action',
|
|
107
|
+
message: `defs.${defName}.action: No action implementation provided for "${actionName}".`,
|
|
108
|
+
path: ['defs', defName, 'action'],
|
|
109
|
+
actionName,
|
|
110
|
+
});
|
|
111
|
+
const resolveSupportedBindingKinds = (definition, defName, kinds, actions, issues) => {
|
|
93
112
|
if (definition.action) {
|
|
94
113
|
if (!actions) {
|
|
95
114
|
return null;
|
|
96
115
|
}
|
|
97
116
|
const action = actions[definition.action];
|
|
98
117
|
if (!action) {
|
|
99
|
-
|
|
118
|
+
issues.push(missingActionIssue(defName, definition.action));
|
|
100
119
|
return [];
|
|
101
120
|
}
|
|
102
121
|
return action.supportedBindings ?? [];
|
|
@@ -107,7 +126,7 @@ const resolveSupportedBindingKinds = (definition, defName, kinds, actions, error
|
|
|
107
126
|
return kinds[definition.kind]?.supportedBindings ?? [];
|
|
108
127
|
};
|
|
109
128
|
export const validateAndResolveBindings = (workflow, options) => {
|
|
110
|
-
const
|
|
129
|
+
const issues = [];
|
|
111
130
|
const resolvedDefs = {};
|
|
112
131
|
const defs = workflow.defs ?? {};
|
|
113
132
|
const resolvedOptions = resolveValidationOptions(options);
|
|
@@ -117,34 +136,52 @@ export const validateAndResolveBindings = (workflow, options) => {
|
|
|
117
136
|
const hasBindingUsage = hasBindingsConfigured(workflow);
|
|
118
137
|
const parsedSettingsByDefName = new Map();
|
|
119
138
|
if (hasBindingUsage && kindNames.length === 0) {
|
|
120
|
-
|
|
139
|
+
issues.push({
|
|
140
|
+
code: 'binding_registry_required',
|
|
141
|
+
message: 'Workflows that declare non-task defs or nested bindings require a non-empty "bindingKinds" registry.',
|
|
142
|
+
});
|
|
121
143
|
}
|
|
122
144
|
for (const [defName, defDefinition] of Object.entries(defs)) {
|
|
123
145
|
if (defDefinition.kind === TASK_KIND) {
|
|
124
146
|
if (defDefinition.action && actions && !actions[defDefinition.action]) {
|
|
125
|
-
|
|
147
|
+
issues.push(missingActionIssue(defName, defDefinition.action));
|
|
126
148
|
}
|
|
127
149
|
continue;
|
|
128
150
|
}
|
|
129
151
|
const kindDefinition = kinds[defDefinition.kind];
|
|
130
152
|
if (!kindDefinition) {
|
|
131
|
-
|
|
153
|
+
issues.push({
|
|
154
|
+
code: 'unknown_binding_kind',
|
|
155
|
+
message: `defs.${defName}.kind: Unknown binding kind "${defDefinition.kind}".`,
|
|
156
|
+
path: ['defs', defName, 'kind'],
|
|
157
|
+
bindingKind: defDefinition.kind,
|
|
158
|
+
});
|
|
132
159
|
continue;
|
|
133
160
|
}
|
|
134
161
|
const actionPolicy = kindDefinition.actionPolicy ?? 'optional';
|
|
135
162
|
if (actionPolicy === 'required' && !defDefinition.action) {
|
|
136
|
-
|
|
163
|
+
issues.push({
|
|
164
|
+
code: 'action_required',
|
|
165
|
+
message: `defs.${defName}.action: Binding kind "${defDefinition.kind}" requires an action.`,
|
|
166
|
+
path: ['defs', defName, 'action'],
|
|
167
|
+
bindingKind: defDefinition.kind,
|
|
168
|
+
});
|
|
137
169
|
}
|
|
138
170
|
if (actionPolicy === 'forbidden' && defDefinition.action) {
|
|
139
|
-
|
|
171
|
+
issues.push({
|
|
172
|
+
code: 'action_forbidden',
|
|
173
|
+
message: `defs.${defName}.action: Binding kind "${defDefinition.kind}" does not allow action declarations.`,
|
|
174
|
+
path: ['defs', defName, 'action'],
|
|
175
|
+
bindingKind: defDefinition.kind,
|
|
176
|
+
});
|
|
140
177
|
}
|
|
141
178
|
if (defDefinition.action && actions && !actions[defDefinition.action]) {
|
|
142
|
-
|
|
179
|
+
issues.push(missingActionIssue(defName, defDefinition.action));
|
|
143
180
|
}
|
|
144
181
|
const { schema } = kindDefinition;
|
|
145
182
|
const parsedPayload = schema.safeParse(defDefinition.settings);
|
|
146
183
|
if (!parsedPayload.success) {
|
|
147
|
-
|
|
184
|
+
issues.push(...toBindingSettingsIssues(parsedPayload.error.issues, defName));
|
|
148
185
|
continue;
|
|
149
186
|
}
|
|
150
187
|
parsedSettingsByDefName.set(defName, parsedPayload.data);
|
|
@@ -154,47 +191,83 @@ export const validateAndResolveBindings = (workflow, options) => {
|
|
|
154
191
|
if (!defBindings) {
|
|
155
192
|
continue;
|
|
156
193
|
}
|
|
157
|
-
const supportedKinds = resolveSupportedBindingKinds(defDefinition, defName, kinds, actions,
|
|
194
|
+
const supportedKinds = resolveSupportedBindingKinds(defDefinition, defName, kinds, actions, issues);
|
|
158
195
|
const shouldValidateSupportedKinds = Array.isArray(supportedKinds);
|
|
159
196
|
for (const [bindingKind, bindingRefs] of Object.entries(defBindings)) {
|
|
197
|
+
const bindingPath = ['defs', defName, 'bindings', bindingKind];
|
|
160
198
|
const kindDefinition = kinds[bindingKind];
|
|
161
199
|
if (!kindDefinition) {
|
|
162
|
-
|
|
200
|
+
issues.push({
|
|
201
|
+
code: 'unknown_binding_kind',
|
|
202
|
+
message: `defs.${defName}.bindings.${bindingKind}: Unknown binding kind "${bindingKind}".`,
|
|
203
|
+
path: bindingPath,
|
|
204
|
+
bindingKind,
|
|
205
|
+
});
|
|
163
206
|
continue;
|
|
164
207
|
}
|
|
165
208
|
const { multiple } = kindDefinition;
|
|
166
209
|
if (multiple && !Array.isArray(bindingRefs)) {
|
|
167
|
-
|
|
210
|
+
issues.push({
|
|
211
|
+
code: 'binding_ref',
|
|
212
|
+
message: `defs.${defName}.bindings.${bindingKind}: Expected an array of def references for binding kind "${bindingKind}".`,
|
|
213
|
+
path: bindingPath,
|
|
214
|
+
bindingKind,
|
|
215
|
+
});
|
|
168
216
|
continue;
|
|
169
217
|
}
|
|
170
218
|
if (!multiple && typeof bindingRefs !== 'string') {
|
|
171
|
-
|
|
219
|
+
issues.push({
|
|
220
|
+
code: 'binding_ref',
|
|
221
|
+
message: `defs.${defName}.bindings.${bindingKind}: Expected a single def reference string for binding kind "${bindingKind}".`,
|
|
222
|
+
path: bindingPath,
|
|
223
|
+
bindingKind,
|
|
224
|
+
});
|
|
172
225
|
continue;
|
|
173
226
|
}
|
|
174
227
|
if (shouldValidateSupportedKinds &&
|
|
175
228
|
supportedKinds &&
|
|
176
229
|
!supportedKinds.includes(bindingKind)) {
|
|
177
230
|
const supportedKindsLabel = supportedKinds.length > 0 ? supportedKinds.join(', ') : '<none>';
|
|
178
|
-
|
|
231
|
+
issues.push({
|
|
232
|
+
code: 'binding_unsupported',
|
|
233
|
+
message: `defs.${defName}.bindings.${bindingKind}: "${defDefinition.action ?? defDefinition.kind}" does not support binding kind "${bindingKind}". Supported binding kinds: ${supportedKindsLabel}.`,
|
|
234
|
+
path: bindingPath,
|
|
235
|
+
bindingKind,
|
|
236
|
+
});
|
|
179
237
|
}
|
|
180
238
|
const refs = toBindingRefs(bindingRefs);
|
|
181
239
|
const duplicateRefs = collectDuplicateReferences(refs);
|
|
182
240
|
if (duplicateRefs.length > 0) {
|
|
183
|
-
|
|
241
|
+
issues.push({
|
|
242
|
+
code: 'binding_ref',
|
|
243
|
+
message: `defs.${defName}.bindings.${bindingKind}: Duplicate def reference(s): ${duplicateRefs.join(', ')}`,
|
|
244
|
+
path: bindingPath,
|
|
245
|
+
bindingKind,
|
|
246
|
+
});
|
|
184
247
|
}
|
|
185
248
|
for (const ref of refs) {
|
|
186
249
|
const definition = defs[ref];
|
|
187
250
|
if (!definition) {
|
|
188
|
-
|
|
251
|
+
issues.push({
|
|
252
|
+
code: 'binding_ref',
|
|
253
|
+
message: `defs.${defName}.bindings.${bindingKind}: Unknown def reference "${ref}".`,
|
|
254
|
+
path: bindingPath,
|
|
255
|
+
bindingKind,
|
|
256
|
+
});
|
|
189
257
|
continue;
|
|
190
258
|
}
|
|
191
259
|
if (definition.kind !== bindingKind) {
|
|
192
|
-
|
|
260
|
+
issues.push({
|
|
261
|
+
code: 'binding_ref',
|
|
262
|
+
message: `defs.${defName}.bindings.${bindingKind}: Def "${ref}" has kind "${definition.kind}" and cannot be mounted as "${bindingKind}".`,
|
|
263
|
+
path: bindingPath,
|
|
264
|
+
bindingKind,
|
|
265
|
+
});
|
|
193
266
|
}
|
|
194
267
|
}
|
|
195
268
|
}
|
|
196
269
|
}
|
|
197
|
-
|
|
270
|
+
issues.push(...detectBindingCycles(defs));
|
|
198
271
|
const inProgress = new Set();
|
|
199
272
|
const mountResolvedDef = (defName) => {
|
|
200
273
|
const existing = resolvedDefs[defName];
|
|
@@ -234,7 +307,7 @@ export const validateAndResolveBindings = (workflow, options) => {
|
|
|
234
307
|
}
|
|
235
308
|
mountResolvedDef(defName);
|
|
236
309
|
}
|
|
237
|
-
return {
|
|
310
|
+
return { issues, resolvedDefs };
|
|
238
311
|
};
|
|
239
312
|
export const mountTaskBindings = (taskBindings, resolvedDefs, bindingKinds, resolveDef) => {
|
|
240
313
|
if (!taskBindings) {
|
package/dist/esm/dsl.types.js
CHANGED
|
@@ -8,6 +8,7 @@ import { parse as parseYaml } from 'yaml';
|
|
|
8
8
|
import { z } from 'zod';
|
|
9
9
|
import { validateAndResolveBindings } from './bindings/base-binding';
|
|
10
10
|
import { SNAKE_CASE_REGEX } from './utils/naming';
|
|
11
|
+
import { mergeSettings } from './workflow-values';
|
|
11
12
|
export const ExpressionStringSchema = z
|
|
12
13
|
.string()
|
|
13
14
|
.regex(/^=/, 'Expression strings must start with "="')
|
|
@@ -232,32 +233,42 @@ export const WorkflowDefinitionSchema = z.strictObject({
|
|
|
232
233
|
flow: z.array(FlowStepSchema),
|
|
233
234
|
outputs: z.record(z.string(), ExpressionStringSchema),
|
|
234
235
|
});
|
|
235
|
-
const collectTaskReferences = (steps) => {
|
|
236
|
+
const collectTaskReferences = (steps, basePath = ['flow']) => {
|
|
236
237
|
const refs = [];
|
|
237
|
-
|
|
238
|
+
steps.forEach((step, index) => {
|
|
239
|
+
const stepPath = [...basePath, index];
|
|
238
240
|
if ('do' in step) {
|
|
239
|
-
refs.push(step.do);
|
|
240
|
-
|
|
241
|
+
refs.push({ taskId: step.do, path: [...stepPath, 'do'] });
|
|
242
|
+
return;
|
|
241
243
|
}
|
|
242
244
|
if ('parallel' in step) {
|
|
243
|
-
refs.push(...collectTaskReferences(step.parallel.steps
|
|
244
|
-
|
|
245
|
+
refs.push(...collectTaskReferences(step.parallel.steps, [
|
|
246
|
+
...stepPath,
|
|
247
|
+
'parallel',
|
|
248
|
+
'steps',
|
|
249
|
+
]));
|
|
250
|
+
return;
|
|
245
251
|
}
|
|
246
252
|
if ('conditional' in step) {
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
253
|
+
step.conditional.when.forEach((branch, branchIndex) => {
|
|
254
|
+
refs.push(...collectTaskReferences(branch.steps, [
|
|
255
|
+
...stepPath,
|
|
256
|
+
'conditional',
|
|
257
|
+
'when',
|
|
258
|
+
branchIndex,
|
|
259
|
+
'steps',
|
|
260
|
+
]));
|
|
261
|
+
});
|
|
262
|
+
return;
|
|
256
263
|
}
|
|
257
264
|
if ('loop' in step) {
|
|
258
|
-
refs.push(...collectTaskReferences(step.loop.steps
|
|
265
|
+
refs.push(...collectTaskReferences(step.loop.steps, [
|
|
266
|
+
...stepPath,
|
|
267
|
+
'loop',
|
|
268
|
+
'steps',
|
|
269
|
+
]));
|
|
259
270
|
}
|
|
260
|
-
}
|
|
271
|
+
});
|
|
261
272
|
return refs;
|
|
262
273
|
};
|
|
263
274
|
export const isTaskDefinition = (definition) => definition.kind === TASK_KIND;
|
|
@@ -267,9 +278,97 @@ export const extractTaskDefinitions = (defs) => Object.entries(defs).reduce((tas
|
|
|
267
278
|
}
|
|
268
279
|
return tasks;
|
|
269
280
|
}, {});
|
|
270
|
-
const
|
|
281
|
+
const EXECUTION_SETTING_KEYS = new Set(Object.keys(BaseSettingsSchema.shape));
|
|
282
|
+
const isExpressionString = (value) => typeof value === 'string' && value.startsWith('=');
|
|
283
|
+
const toIssuePath = (path) => path.filter((segment) => typeof segment === 'string' || typeof segment === 'number');
|
|
284
|
+
const getValueAtPath = (value, path) => {
|
|
285
|
+
let current = value;
|
|
286
|
+
for (const segment of path) {
|
|
287
|
+
if (current === null || typeof current !== 'object') {
|
|
288
|
+
return undefined;
|
|
289
|
+
}
|
|
290
|
+
current = current[segment];
|
|
291
|
+
}
|
|
292
|
+
return current;
|
|
293
|
+
};
|
|
294
|
+
const extractActionSettings = (settings) => {
|
|
295
|
+
if (!settings || typeof settings !== 'object' || Array.isArray(settings)) {
|
|
296
|
+
return {};
|
|
297
|
+
}
|
|
298
|
+
return Object.fromEntries(Object.entries(settings).filter(([key]) => !EXECUTION_SETTING_KEYS.has(key)));
|
|
299
|
+
};
|
|
300
|
+
const toActionSchemaIssues = ({ actionName, code, payload, schema, section, taskId, }) => {
|
|
301
|
+
const result = schema.safeParse(payload);
|
|
302
|
+
if (result.success) {
|
|
303
|
+
return [];
|
|
304
|
+
}
|
|
305
|
+
return result.error.issues.flatMap((issue) => {
|
|
306
|
+
const issuePath = toIssuePath(issue.path);
|
|
307
|
+
// Expressions are resolved immediately before action execution, so their
|
|
308
|
+
// eventual runtime type cannot be checked while validating the definition.
|
|
309
|
+
if (isExpressionString(getValueAtPath(payload, issuePath))) {
|
|
310
|
+
return [];
|
|
311
|
+
}
|
|
312
|
+
const path = ['defs', taskId, section, ...issuePath];
|
|
313
|
+
return [
|
|
314
|
+
{
|
|
315
|
+
actionName,
|
|
316
|
+
code,
|
|
317
|
+
message: `${path.join('.')}: ${issue.message}`,
|
|
318
|
+
path,
|
|
319
|
+
taskId,
|
|
320
|
+
},
|
|
321
|
+
];
|
|
322
|
+
});
|
|
323
|
+
};
|
|
324
|
+
const validateTaskActionSchemas = (definition, actions) => {
|
|
325
|
+
if (!actions) {
|
|
326
|
+
return [];
|
|
327
|
+
}
|
|
328
|
+
const issues = [];
|
|
329
|
+
const taskDefinitions = extractTaskDefinitions(definition.defs);
|
|
330
|
+
for (const [taskId, task] of Object.entries(taskDefinitions)) {
|
|
331
|
+
const action = actions[task.action];
|
|
332
|
+
// Missing actions are reported by binding validation and have no schemas
|
|
333
|
+
// available for payload validation.
|
|
334
|
+
if (!action) {
|
|
335
|
+
continue;
|
|
336
|
+
}
|
|
337
|
+
if (action.inputSchema) {
|
|
338
|
+
issues.push(...toActionSchemaIssues({
|
|
339
|
+
actionName: task.action,
|
|
340
|
+
code: 'action_inputs',
|
|
341
|
+
payload: task.inputs ?? {},
|
|
342
|
+
schema: action.inputSchema,
|
|
343
|
+
section: 'inputs',
|
|
344
|
+
taskId,
|
|
345
|
+
}));
|
|
346
|
+
}
|
|
347
|
+
if (action.settingSchema) {
|
|
348
|
+
const effectiveSettings = mergeSettings(definition.defaults?.settings, task.settings);
|
|
349
|
+
issues.push(...toActionSchemaIssues({
|
|
350
|
+
actionName: task.action,
|
|
351
|
+
code: 'action_settings',
|
|
352
|
+
payload: extractActionSettings(effectiveSettings),
|
|
353
|
+
schema: action.settingSchema,
|
|
354
|
+
section: 'settings',
|
|
355
|
+
taskId,
|
|
356
|
+
}));
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
return issues;
|
|
360
|
+
};
|
|
361
|
+
const toSchemaIssues = (zodIssues) => zodIssues.map((issue) => {
|
|
271
362
|
const path = issue.path.join('.') || '<root>';
|
|
272
|
-
return
|
|
363
|
+
return {
|
|
364
|
+
code: 'schema',
|
|
365
|
+
message: `${path}: ${issue.message}`,
|
|
366
|
+
path: issue.path.filter((segment) => typeof segment === 'string' || typeof segment === 'number'),
|
|
367
|
+
};
|
|
368
|
+
});
|
|
369
|
+
const invalidWorkflow = (issues) => ({
|
|
370
|
+
success: false,
|
|
371
|
+
issues,
|
|
273
372
|
});
|
|
274
373
|
export function validateWorkflow(input, options) {
|
|
275
374
|
let candidate = input;
|
|
@@ -279,32 +378,40 @@ export function validateWorkflow(input, options) {
|
|
|
279
378
|
}
|
|
280
379
|
catch (error) {
|
|
281
380
|
const message = error instanceof Error ? error.message : 'Unknown YAML parse error';
|
|
282
|
-
return
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
381
|
+
return invalidWorkflow([
|
|
382
|
+
{ code: 'yaml_parse', message: 'Unable to parse workflow YAML' },
|
|
383
|
+
{ code: 'yaml_parse', message },
|
|
384
|
+
]);
|
|
286
385
|
}
|
|
287
386
|
}
|
|
288
387
|
const parsed = WorkflowDefinitionSchema.safeParse(candidate);
|
|
289
388
|
if (!parsed.success) {
|
|
290
|
-
return
|
|
389
|
+
return invalidWorkflow(toSchemaIssues(parsed.error.issues));
|
|
291
390
|
}
|
|
292
|
-
const
|
|
391
|
+
const issues = [];
|
|
293
392
|
const taskDefinitions = extractTaskDefinitions(parsed.data.defs);
|
|
294
|
-
const
|
|
295
|
-
const
|
|
296
|
-
|
|
297
|
-
|
|
393
|
+
const reportedMissingTasks = new Set();
|
|
394
|
+
for (const { taskId, path } of collectTaskReferences(parsed.data.flow)) {
|
|
395
|
+
if (Object.prototype.hasOwnProperty.call(taskDefinitions, taskId) ||
|
|
396
|
+
reportedMissingTasks.has(taskId)) {
|
|
397
|
+
continue;
|
|
398
|
+
}
|
|
399
|
+
reportedMissingTasks.add(taskId);
|
|
400
|
+
issues.push({
|
|
401
|
+
code: 'unknown_task',
|
|
402
|
+
message: `Unknown task(s) referenced in flow: ${taskId}`,
|
|
403
|
+
path,
|
|
404
|
+
taskId,
|
|
405
|
+
});
|
|
298
406
|
}
|
|
299
407
|
const bindingValidation = validateAndResolveBindings(parsed.data, {
|
|
300
408
|
bindingKinds: options?.bindingKinds,
|
|
301
409
|
actions: options?.actions,
|
|
302
410
|
});
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
return { success: false, errors };
|
|
411
|
+
issues.push(...bindingValidation.issues);
|
|
412
|
+
issues.push(...validateTaskActionSchemas(parsed.data, options?.actions));
|
|
413
|
+
if (issues.length > 0) {
|
|
414
|
+
return invalidWorkflow(issues);
|
|
308
415
|
}
|
|
309
416
|
return { success: true, data: parsed.data };
|
|
310
417
|
}
|
package/dist/esm/index.js
CHANGED
|
@@ -7,6 +7,7 @@ export { AbstractAction } from './action/abstract-action';
|
|
|
7
7
|
export { defineAction } from './action/action';
|
|
8
8
|
export { BaseWorkflowContext, EWorkflowRunStatus, WORKFLOW_RUN_STATUSES, } from './context';
|
|
9
9
|
export * from './dsl.types';
|
|
10
|
+
export { issueMessages, } from './validation-issue';
|
|
10
11
|
export { compileWorkflow, Workflow, WorkflowEventEmitter, WorkflowRunner, } from './workflow';
|
|
11
12
|
export { StepType } from './workflow-event-emitter';
|
|
12
13
|
export { NonDeterministicWorkflowError } from './runner-runtime-control';
|
|
@@ -63,6 +63,18 @@ export class RunnerRuntimeControl {
|
|
|
63
63
|
this.enqueueSuspension(request);
|
|
64
64
|
return request.resume.promise;
|
|
65
65
|
}
|
|
66
|
+
hasRecordedResult(key) {
|
|
67
|
+
const currentStep = this.runner.getCurrentStep();
|
|
68
|
+
if (!currentStep) {
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
const execution = this.ensureStepExecution(currentStep.id);
|
|
72
|
+
const suspendKey = buildSuspendKey(execution.suspendCursor + 1, key);
|
|
73
|
+
if (execution.awaitResults.has(suspendKey)) {
|
|
74
|
+
return true;
|
|
75
|
+
}
|
|
76
|
+
return (this.primedResumeData.get(currentStep.id)?.length ?? 0) > 0;
|
|
77
|
+
}
|
|
66
78
|
resume(data) {
|
|
67
79
|
void this.runner.resume({ resumeData: data });
|
|
68
80
|
}
|
|
@@ -188,6 +188,11 @@ class ParallelWorkflowRuntimeControl {
|
|
|
188
188
|
suspend() {
|
|
189
189
|
return Promise.reject(new ParallelSuspensionError());
|
|
190
190
|
}
|
|
191
|
+
hasRecordedResult() {
|
|
192
|
+
// Suspension is not supported inside parallel blocks, so no resume
|
|
193
|
+
// result can ever be recorded for them.
|
|
194
|
+
return false;
|
|
195
|
+
}
|
|
191
196
|
resume(data) {
|
|
192
197
|
this.getParent().resume(data);
|
|
193
198
|
}
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
import { z } from 'zod';
|
|
7
7
|
import { mountTaskBindings, validateAndResolveBindings, } from './bindings/base-binding';
|
|
8
8
|
import { extractTaskDefinitions as extractTaskDefinitionsFromDefs } from './dsl.types';
|
|
9
|
+
import { issueMessages } from './validation-issue';
|
|
9
10
|
import { StepType } from './workflow-event-emitter';
|
|
10
11
|
import { compileValue, mergeSettings, } from './workflow-values';
|
|
11
12
|
/** Build a stable identifier for a step using its path and label. */
|
|
@@ -94,8 +95,8 @@ const compileTasks = (definition, options) => {
|
|
|
94
95
|
bindingKinds: options.bindingKinds,
|
|
95
96
|
actions: options.actions,
|
|
96
97
|
});
|
|
97
|
-
if (bindingValidation.
|
|
98
|
-
throw new Error(`Workflow bindings validation failed: ${bindingValidation.
|
|
98
|
+
if (bindingValidation.issues.length > 0) {
|
|
99
|
+
throw new Error(`Workflow bindings validation failed: ${issueMessages(bindingValidation.issues).join('; ')}`);
|
|
99
100
|
}
|
|
100
101
|
assertActionsBound(taskDefinitions, options.actions);
|
|
101
102
|
for (const [taskName, task] of Object.entries(taskDefinitions)) {
|
|
@@ -6,16 +6,16 @@
|
|
|
6
6
|
import jsonata from 'jsonata';
|
|
7
7
|
/** Basic object guard that rejects arrays and null. */
|
|
8
8
|
const isPlainObject = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
9
|
-
const resolveNestedExpressions = async (value, scope, seen = new WeakSet()) => {
|
|
9
|
+
const resolveNestedExpressions = async (value, scope, jsonataFunctions, seen = new WeakSet()) => {
|
|
10
10
|
if (typeof value === 'string' && value.startsWith('=')) {
|
|
11
|
-
return evaluateValue(compileValue(value), scope);
|
|
11
|
+
return evaluateValue(compileValue(value, { jsonataFunctions }), scope);
|
|
12
12
|
}
|
|
13
13
|
if (Array.isArray(value)) {
|
|
14
14
|
if (seen.has(value)) {
|
|
15
15
|
return value;
|
|
16
16
|
}
|
|
17
17
|
seen.add(value);
|
|
18
|
-
return Promise.all(value.map((entry) => resolveNestedExpressions(entry, scope, seen)));
|
|
18
|
+
return Promise.all(value.map((entry) => resolveNestedExpressions(entry, scope, jsonataFunctions, seen)));
|
|
19
19
|
}
|
|
20
20
|
if (isPlainObject(value)) {
|
|
21
21
|
if (seen.has(value)) {
|
|
@@ -24,7 +24,7 @@ const resolveNestedExpressions = async (value, scope, seen = new WeakSet()) => {
|
|
|
24
24
|
seen.add(value);
|
|
25
25
|
const entries = await Promise.all(Object.entries(value).map(async ([key, entry]) => [
|
|
26
26
|
key,
|
|
27
|
-
await resolveNestedExpressions(entry, scope, seen),
|
|
27
|
+
await resolveNestedExpressions(entry, scope, jsonataFunctions, seen),
|
|
28
28
|
]));
|
|
29
29
|
return Object.fromEntries(entries);
|
|
30
30
|
}
|
|
@@ -51,12 +51,13 @@ const registerJsonataFunctions = (expression, registry) => {
|
|
|
51
51
|
* Strings prefixed with `=` are treated as JSONata expressions; everything else is a literal.
|
|
52
52
|
*/
|
|
53
53
|
export const compileValue = (value, options) => {
|
|
54
|
+
const jsonataFunctions = options?.jsonataFunctions;
|
|
54
55
|
if (typeof value === 'string' && value.startsWith('=')) {
|
|
55
56
|
const expression = jsonata(value.slice(1));
|
|
56
|
-
registerJsonataFunctions(expression,
|
|
57
|
-
return { kind: 'expression', source: value, expression };
|
|
57
|
+
registerJsonataFunctions(expression, jsonataFunctions);
|
|
58
|
+
return { kind: 'expression', source: value, expression, jsonataFunctions };
|
|
58
59
|
}
|
|
59
|
-
return { kind: 'literal', value };
|
|
60
|
+
return { kind: 'literal', value, jsonataFunctions };
|
|
60
61
|
};
|
|
61
62
|
/**
|
|
62
63
|
* Evaluate a compiled value against the current workflow scope.
|
|
@@ -86,7 +87,7 @@ export const evaluateMapping = async (mapping, scope) => {
|
|
|
86
87
|
}
|
|
87
88
|
const entries = await Promise.all(Object.entries(mapping).map(async ([key, compiled]) => [
|
|
88
89
|
key,
|
|
89
|
-
await resolveNestedExpressions(await evaluateValue(compiled, scope), scope),
|
|
90
|
+
await resolveNestedExpressions(await evaluateValue(compiled, scope), scope, compiled.jsonataFunctions),
|
|
90
91
|
]));
|
|
91
92
|
const result = Object.fromEntries(entries);
|
|
92
93
|
return result;
|
package/dist/esm/workflow.js
CHANGED
|
@@ -7,6 +7,7 @@ import { stringify as stringifyYaml } from 'yaml';
|
|
|
7
7
|
import { EWorkflowRunStatus, } from './context';
|
|
8
8
|
import { TASK_KIND, WorkflowDefinitionSchema, validateWorkflow, } from './dsl.types';
|
|
9
9
|
import { safeRenameTaskInDefinition as renameTaskInDefinition } from './utils/workflow-definition';
|
|
10
|
+
import { issueMessages } from './validation-issue';
|
|
10
11
|
import { compileWorkflow, } from './workflow-compiler';
|
|
11
12
|
import { WorkflowRunner } from './workflow-runner';
|
|
12
13
|
export { compileWorkflow } from './workflow-compiler';
|
|
@@ -63,7 +64,7 @@ export class Workflow {
|
|
|
63
64
|
actions: options.actions,
|
|
64
65
|
});
|
|
65
66
|
if (!validation.success) {
|
|
66
|
-
throw new Error(`Workflow validation failed: ${validation.
|
|
67
|
+
throw new Error(`Workflow validation failed: ${issueMessages(validation.issues).join('; ')}`);
|
|
67
68
|
}
|
|
68
69
|
const compiled = compileWorkflow(validation.data, options);
|
|
69
70
|
return new Workflow(compiled);
|
|
@@ -78,7 +79,7 @@ export class Workflow {
|
|
|
78
79
|
actions: options.actions,
|
|
79
80
|
});
|
|
80
81
|
if (!validation.success) {
|
|
81
|
-
throw new Error(`Workflow validation failed: ${validation.
|
|
82
|
+
throw new Error(`Workflow validation failed: ${issueMessages(validation.issues).join('; ')}`);
|
|
82
83
|
}
|
|
83
84
|
const compiled = compileWorkflow(validation.data, options);
|
|
84
85
|
return new Workflow(compiled);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
+
import { type WorkflowValidationIssue } from '../validation-issue';
|
|
2
3
|
export type BindingKindSchema = z.ZodTypeAny;
|
|
3
4
|
export type BindingActionPolicy = 'forbidden' | 'optional' | 'required';
|
|
4
5
|
export type BindingValidationActionMetadata = {
|
|
@@ -43,7 +44,7 @@ export type ValidateAndResolveBindingsOptions = {
|
|
|
43
44
|
actions?: Record<string, BindingValidationActionMetadata>;
|
|
44
45
|
};
|
|
45
46
|
type BindingValidationResult = {
|
|
46
|
-
|
|
47
|
+
issues: WorkflowValidationIssue[];
|
|
47
48
|
resolvedDefs: ResolvedBindingDefs;
|
|
48
49
|
};
|
|
49
50
|
export declare const validateAndResolveBindings: (workflow: BindingAwareWorkflowLike, options?: BindingKindSchemas | ValidateAndResolveBindingsOptions) => BindingValidationResult;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-binding.d.ts","sourceRoot":"","sources":["../../../src/bindings/base-binding.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,CAAC,EAAiB,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"base-binding.d.ts","sourceRoot":"","sources":["../../../src/bindings/base-binding.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,CAAC,EAAiB,MAAM,KAAK,CAAC;AAEvC,OAAO,EAAE,KAAK,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AAInE,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,UAAU,CAAC;AAE7C,MAAM,MAAM,mBAAmB,GAAG,WAAW,GAAG,UAAU,GAAG,UAAU,CAAC;AAExE,MAAM,MAAM,+BAA+B,GAAG;IAC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