@hexabot-ai/agentic 3.2.3 → 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/validation-issue.js +10 -0
- package/dist/cjs/workflow-compiler.js +3 -2
- 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/validation-issue.js +6 -0
- package/dist/esm/workflow-compiler.js +3 -2
- 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/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/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.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/validation.test.ts +235 -17
- package/src/bindings/base-binding.ts +116 -62
- package/src/dsl.types.ts +225 -40
- package/src/index.ts +6 -0
- package/src/validation-issue.ts +38 -0
- package/src/workflow-compiler.ts +3 -2
- package/src/workflow.ts +3 -2
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
|
|
7
7
|
import { z, type ZodIssue } from 'zod';
|
|
8
8
|
|
|
9
|
+
import { type WorkflowValidationIssue } from '../validation-issue';
|
|
10
|
+
|
|
9
11
|
const TASK_KIND = 'task';
|
|
10
12
|
|
|
11
13
|
export type BindingKindSchema = z.ZodTypeAny;
|
|
@@ -87,7 +89,7 @@ export type ValidateAndResolveBindingsOptions = {
|
|
|
87
89
|
};
|
|
88
90
|
|
|
89
91
|
type BindingValidationResult = {
|
|
90
|
-
|
|
92
|
+
issues: WorkflowValidationIssue[];
|
|
91
93
|
resolvedDefs: ResolvedBindingDefs;
|
|
92
94
|
};
|
|
93
95
|
|
|
@@ -116,11 +118,26 @@ const hasBindingsConfigured = (workflow: BindingAwareWorkflowLike): boolean => {
|
|
|
116
118
|
|
|
117
119
|
return hasNonTaskDefs || hasNestedBindings;
|
|
118
120
|
};
|
|
119
|
-
const
|
|
120
|
-
|
|
121
|
+
const toBindingSettingsIssues = (
|
|
122
|
+
zodIssues: ZodIssue[],
|
|
123
|
+
defName: string,
|
|
124
|
+
): WorkflowValidationIssue[] =>
|
|
125
|
+
zodIssues.map((issue) => {
|
|
121
126
|
const path = issue.path.join('.') || '<root>';
|
|
122
127
|
|
|
123
|
-
return
|
|
128
|
+
return {
|
|
129
|
+
code: 'binding_settings',
|
|
130
|
+
message: `defs.${defName}.settings.${path}: ${issue.message}`,
|
|
131
|
+
path: [
|
|
132
|
+
'defs',
|
|
133
|
+
defName,
|
|
134
|
+
'settings',
|
|
135
|
+
...issue.path.filter(
|
|
136
|
+
(segment): segment is string | number =>
|
|
137
|
+
typeof segment === 'string' || typeof segment === 'number',
|
|
138
|
+
),
|
|
139
|
+
],
|
|
140
|
+
};
|
|
124
141
|
});
|
|
125
142
|
const collectDuplicateReferences = (refs: string[]): string[] => {
|
|
126
143
|
const seen = new Set<string>();
|
|
@@ -155,8 +172,10 @@ const collectBindingRefs = (
|
|
|
155
172
|
|
|
156
173
|
return refs;
|
|
157
174
|
};
|
|
158
|
-
const detectBindingCycles = (
|
|
159
|
-
|
|
175
|
+
const detectBindingCycles = (
|
|
176
|
+
defs: Record<string, DefLike>,
|
|
177
|
+
): WorkflowValidationIssue[] => {
|
|
178
|
+
const issues: WorkflowValidationIssue[] = [];
|
|
160
179
|
const reportedCycles = new Set<string>();
|
|
161
180
|
const states = new Map<string, 'visiting' | 'visited'>();
|
|
162
181
|
const stack: string[] = [];
|
|
@@ -178,9 +197,11 @@ const detectBindingCycles = (defs: Record<string, DefLike>): string[] => {
|
|
|
178
197
|
|
|
179
198
|
if (!reportedCycles.has(cycleKey)) {
|
|
180
199
|
reportedCycles.add(cycleKey);
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
200
|
+
issues.push({
|
|
201
|
+
code: 'binding_cycle',
|
|
202
|
+
message: `defs.${defName}.bindings: Circular binding reference detected (${cyclePath.join(' -> ')}).`,
|
|
203
|
+
path: ['defs', defName, 'bindings'],
|
|
204
|
+
});
|
|
184
205
|
}
|
|
185
206
|
|
|
186
207
|
return;
|
|
@@ -206,14 +227,23 @@ const detectBindingCycles = (defs: Record<string, DefLike>): string[] => {
|
|
|
206
227
|
visit(defName);
|
|
207
228
|
}
|
|
208
229
|
|
|
209
|
-
return
|
|
230
|
+
return issues;
|
|
210
231
|
};
|
|
232
|
+
const missingActionIssue = (
|
|
233
|
+
defName: string,
|
|
234
|
+
actionName: string,
|
|
235
|
+
): WorkflowValidationIssue => ({
|
|
236
|
+
code: 'missing_action',
|
|
237
|
+
message: `defs.${defName}.action: No action implementation provided for "${actionName}".`,
|
|
238
|
+
path: ['defs', defName, 'action'],
|
|
239
|
+
actionName,
|
|
240
|
+
});
|
|
211
241
|
const resolveSupportedBindingKinds = (
|
|
212
242
|
definition: DefLike,
|
|
213
243
|
defName: string,
|
|
214
244
|
kinds: BindingKindSchemas,
|
|
215
245
|
actions: Record<string, BindingValidationActionMetadata> | undefined,
|
|
216
|
-
|
|
246
|
+
issues: WorkflowValidationIssue[],
|
|
217
247
|
): readonly string[] | null => {
|
|
218
248
|
if (definition.action) {
|
|
219
249
|
if (!actions) {
|
|
@@ -222,9 +252,7 @@ const resolveSupportedBindingKinds = (
|
|
|
222
252
|
|
|
223
253
|
const action = actions[definition.action];
|
|
224
254
|
if (!action) {
|
|
225
|
-
|
|
226
|
-
`defs.${defName}.action: No action implementation provided for "${definition.action}".`,
|
|
227
|
-
);
|
|
255
|
+
issues.push(missingActionIssue(defName, definition.action));
|
|
228
256
|
|
|
229
257
|
return [];
|
|
230
258
|
}
|
|
@@ -243,7 +271,7 @@ export const validateAndResolveBindings = (
|
|
|
243
271
|
workflow: BindingAwareWorkflowLike,
|
|
244
272
|
options?: BindingKindSchemas | ValidateAndResolveBindingsOptions,
|
|
245
273
|
): BindingValidationResult => {
|
|
246
|
-
const
|
|
274
|
+
const issues: WorkflowValidationIssue[] = [];
|
|
247
275
|
const resolvedDefs: ResolvedBindingDefs = {};
|
|
248
276
|
const defs = workflow.defs ?? {};
|
|
249
277
|
const resolvedOptions = resolveValidationOptions(options);
|
|
@@ -254,17 +282,17 @@ export const validateAndResolveBindings = (
|
|
|
254
282
|
const parsedSettingsByDefName = new Map<string, unknown>();
|
|
255
283
|
|
|
256
284
|
if (hasBindingUsage && kindNames.length === 0) {
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
285
|
+
issues.push({
|
|
286
|
+
code: 'binding_registry_required',
|
|
287
|
+
message:
|
|
288
|
+
'Workflows that declare non-task defs or nested bindings require a non-empty "bindingKinds" registry.',
|
|
289
|
+
});
|
|
260
290
|
}
|
|
261
291
|
|
|
262
292
|
for (const [defName, defDefinition] of Object.entries(defs)) {
|
|
263
293
|
if (defDefinition.kind === TASK_KIND) {
|
|
264
294
|
if (defDefinition.action && actions && !actions[defDefinition.action]) {
|
|
265
|
-
|
|
266
|
-
`defs.${defName}.action: No action implementation provided for "${defDefinition.action}".`,
|
|
267
|
-
);
|
|
295
|
+
issues.push(missingActionIssue(defName, defDefinition.action));
|
|
268
296
|
}
|
|
269
297
|
continue;
|
|
270
298
|
}
|
|
@@ -272,38 +300,42 @@ export const validateAndResolveBindings = (
|
|
|
272
300
|
const kindDefinition = kinds[defDefinition.kind];
|
|
273
301
|
|
|
274
302
|
if (!kindDefinition) {
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
303
|
+
issues.push({
|
|
304
|
+
code: 'unknown_binding_kind',
|
|
305
|
+
message: `defs.${defName}.kind: Unknown binding kind "${defDefinition.kind}".`,
|
|
306
|
+
path: ['defs', defName, 'kind'],
|
|
307
|
+
bindingKind: defDefinition.kind,
|
|
308
|
+
});
|
|
278
309
|
continue;
|
|
279
310
|
}
|
|
280
311
|
|
|
281
312
|
const actionPolicy = kindDefinition.actionPolicy ?? 'optional';
|
|
282
313
|
if (actionPolicy === 'required' && !defDefinition.action) {
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
314
|
+
issues.push({
|
|
315
|
+
code: 'action_required',
|
|
316
|
+
message: `defs.${defName}.action: Binding kind "${defDefinition.kind}" requires an action.`,
|
|
317
|
+
path: ['defs', defName, 'action'],
|
|
318
|
+
bindingKind: defDefinition.kind,
|
|
319
|
+
});
|
|
286
320
|
}
|
|
287
321
|
if (actionPolicy === 'forbidden' && defDefinition.action) {
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
322
|
+
issues.push({
|
|
323
|
+
code: 'action_forbidden',
|
|
324
|
+
message: `defs.${defName}.action: Binding kind "${defDefinition.kind}" does not allow action declarations.`,
|
|
325
|
+
path: ['defs', defName, 'action'],
|
|
326
|
+
bindingKind: defDefinition.kind,
|
|
327
|
+
});
|
|
291
328
|
}
|
|
292
329
|
if (defDefinition.action && actions && !actions[defDefinition.action]) {
|
|
293
|
-
|
|
294
|
-
`defs.${defName}.action: No action implementation provided for "${defDefinition.action}".`,
|
|
295
|
-
);
|
|
330
|
+
issues.push(missingActionIssue(defName, defDefinition.action));
|
|
296
331
|
}
|
|
297
332
|
|
|
298
333
|
const { schema } = kindDefinition;
|
|
299
334
|
const parsedPayload = schema.safeParse(defDefinition.settings);
|
|
300
335
|
|
|
301
336
|
if (!parsedPayload.success) {
|
|
302
|
-
|
|
303
|
-
...
|
|
304
|
-
parsedPayload.error.issues,
|
|
305
|
-
`defs.${defName}.settings`,
|
|
306
|
-
),
|
|
337
|
+
issues.push(
|
|
338
|
+
...toBindingSettingsIssues(parsedPayload.error.issues, defName),
|
|
307
339
|
);
|
|
308
340
|
continue;
|
|
309
341
|
}
|
|
@@ -323,31 +355,41 @@ export const validateAndResolveBindings = (
|
|
|
323
355
|
defName,
|
|
324
356
|
kinds,
|
|
325
357
|
actions,
|
|
326
|
-
|
|
358
|
+
issues,
|
|
327
359
|
);
|
|
328
360
|
const shouldValidateSupportedKinds = Array.isArray(supportedKinds);
|
|
329
361
|
|
|
330
362
|
for (const [bindingKind, bindingRefs] of Object.entries(defBindings)) {
|
|
363
|
+
const bindingPath = ['defs', defName, 'bindings', bindingKind];
|
|
331
364
|
const kindDefinition = kinds[bindingKind];
|
|
332
365
|
|
|
333
366
|
if (!kindDefinition) {
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
367
|
+
issues.push({
|
|
368
|
+
code: 'unknown_binding_kind',
|
|
369
|
+
message: `defs.${defName}.bindings.${bindingKind}: Unknown binding kind "${bindingKind}".`,
|
|
370
|
+
path: bindingPath,
|
|
371
|
+
bindingKind,
|
|
372
|
+
});
|
|
337
373
|
continue;
|
|
338
374
|
}
|
|
339
375
|
|
|
340
376
|
const { multiple } = kindDefinition;
|
|
341
377
|
if (multiple && !Array.isArray(bindingRefs)) {
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
378
|
+
issues.push({
|
|
379
|
+
code: 'binding_ref',
|
|
380
|
+
message: `defs.${defName}.bindings.${bindingKind}: Expected an array of def references for binding kind "${bindingKind}".`,
|
|
381
|
+
path: bindingPath,
|
|
382
|
+
bindingKind,
|
|
383
|
+
});
|
|
345
384
|
continue;
|
|
346
385
|
}
|
|
347
386
|
if (!multiple && typeof bindingRefs !== 'string') {
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
387
|
+
issues.push({
|
|
388
|
+
code: 'binding_ref',
|
|
389
|
+
message: `defs.${defName}.bindings.${bindingKind}: Expected a single def reference string for binding kind "${bindingKind}".`,
|
|
390
|
+
path: bindingPath,
|
|
391
|
+
bindingKind,
|
|
392
|
+
});
|
|
351
393
|
continue;
|
|
352
394
|
}
|
|
353
395
|
|
|
@@ -358,39 +400,51 @@ export const validateAndResolveBindings = (
|
|
|
358
400
|
) {
|
|
359
401
|
const supportedKindsLabel =
|
|
360
402
|
supportedKinds.length > 0 ? supportedKinds.join(', ') : '<none>';
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
403
|
+
issues.push({
|
|
404
|
+
code: 'binding_unsupported',
|
|
405
|
+
message: `defs.${defName}.bindings.${bindingKind}: "${defDefinition.action ?? defDefinition.kind}" does not support binding kind "${bindingKind}". Supported binding kinds: ${supportedKindsLabel}.`,
|
|
406
|
+
path: bindingPath,
|
|
407
|
+
bindingKind,
|
|
408
|
+
});
|
|
364
409
|
}
|
|
365
410
|
|
|
366
411
|
const refs = toBindingRefs(bindingRefs);
|
|
367
412
|
const duplicateRefs = collectDuplicateReferences(refs);
|
|
368
413
|
if (duplicateRefs.length > 0) {
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
414
|
+
issues.push({
|
|
415
|
+
code: 'binding_ref',
|
|
416
|
+
message: `defs.${defName}.bindings.${bindingKind}: Duplicate def reference(s): ${duplicateRefs.join(', ')}`,
|
|
417
|
+
path: bindingPath,
|
|
418
|
+
bindingKind,
|
|
419
|
+
});
|
|
372
420
|
}
|
|
373
421
|
|
|
374
422
|
for (const ref of refs) {
|
|
375
423
|
const definition = defs[ref];
|
|
376
424
|
|
|
377
425
|
if (!definition) {
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
426
|
+
issues.push({
|
|
427
|
+
code: 'binding_ref',
|
|
428
|
+
message: `defs.${defName}.bindings.${bindingKind}: Unknown def reference "${ref}".`,
|
|
429
|
+
path: bindingPath,
|
|
430
|
+
bindingKind,
|
|
431
|
+
});
|
|
381
432
|
continue;
|
|
382
433
|
}
|
|
383
434
|
|
|
384
435
|
if (definition.kind !== bindingKind) {
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
436
|
+
issues.push({
|
|
437
|
+
code: 'binding_ref',
|
|
438
|
+
message: `defs.${defName}.bindings.${bindingKind}: Def "${ref}" has kind "${definition.kind}" and cannot be mounted as "${bindingKind}".`,
|
|
439
|
+
path: bindingPath,
|
|
440
|
+
bindingKind,
|
|
441
|
+
});
|
|
388
442
|
}
|
|
389
443
|
}
|
|
390
444
|
}
|
|
391
445
|
}
|
|
392
446
|
|
|
393
|
-
|
|
447
|
+
issues.push(...detectBindingCycles(defs));
|
|
394
448
|
|
|
395
449
|
const inProgress = new Set<string>();
|
|
396
450
|
const mountResolvedDef = (
|
|
@@ -447,7 +501,7 @@ export const validateAndResolveBindings = (
|
|
|
447
501
|
mountResolvedDef(defName);
|
|
448
502
|
}
|
|
449
503
|
|
|
450
|
-
return {
|
|
504
|
+
return { issues, resolvedDefs };
|
|
451
505
|
};
|
|
452
506
|
|
|
453
507
|
export const mountTaskBindings = (
|
package/src/dsl.types.ts
CHANGED
|
@@ -11,6 +11,8 @@ import { z } from 'zod';
|
|
|
11
11
|
import type { BindingKindSchemas } from './bindings/base-binding';
|
|
12
12
|
import { validateAndResolveBindings } from './bindings/base-binding';
|
|
13
13
|
import { SNAKE_CASE_REGEX } from './utils/naming';
|
|
14
|
+
import { type WorkflowValidationIssue } from './validation-issue';
|
|
15
|
+
import { mergeSettings } from './workflow-values';
|
|
14
16
|
|
|
15
17
|
export const ExpressionStringSchema = z
|
|
16
18
|
.string()
|
|
@@ -357,6 +359,8 @@ export type WorkflowDefinition = z.infer<typeof WorkflowDefinitionSchema>;
|
|
|
357
359
|
|
|
358
360
|
export type WorkflowValidationActionMetadata = {
|
|
359
361
|
supportedBindings?: readonly string[];
|
|
362
|
+
inputSchema?: z.ZodTypeAny;
|
|
363
|
+
settingSchema?: z.ZodTypeAny;
|
|
360
364
|
};
|
|
361
365
|
|
|
362
366
|
export type ValidateWorkflowOptions = {
|
|
@@ -366,37 +370,66 @@ export type ValidateWorkflowOptions = {
|
|
|
366
370
|
|
|
367
371
|
export type WorkflowValidationResult =
|
|
368
372
|
| { success: true; data: WorkflowDefinition }
|
|
369
|
-
| { success: false;
|
|
373
|
+
| { success: false; issues: WorkflowValidationIssue[] };
|
|
370
374
|
|
|
371
|
-
|
|
372
|
-
|
|
375
|
+
type TaskReference = {
|
|
376
|
+
taskId: string;
|
|
377
|
+
path: Array<string | number>;
|
|
378
|
+
};
|
|
379
|
+
|
|
380
|
+
const collectTaskReferences = (
|
|
381
|
+
steps: FlowStep[],
|
|
382
|
+
basePath: Array<string | number> = ['flow'],
|
|
383
|
+
): TaskReference[] => {
|
|
384
|
+
const refs: TaskReference[] = [];
|
|
385
|
+
|
|
386
|
+
steps.forEach((step, index) => {
|
|
387
|
+
const stepPath = [...basePath, index];
|
|
373
388
|
|
|
374
|
-
for (const step of steps) {
|
|
375
389
|
if ('do' in step) {
|
|
376
|
-
refs.push(step.do);
|
|
377
|
-
|
|
390
|
+
refs.push({ taskId: step.do, path: [...stepPath, 'do'] });
|
|
391
|
+
|
|
392
|
+
return;
|
|
378
393
|
}
|
|
379
394
|
|
|
380
395
|
if ('parallel' in step) {
|
|
381
|
-
refs.push(
|
|
382
|
-
|
|
396
|
+
refs.push(
|
|
397
|
+
...collectTaskReferences(step.parallel.steps, [
|
|
398
|
+
...stepPath,
|
|
399
|
+
'parallel',
|
|
400
|
+
'steps',
|
|
401
|
+
]),
|
|
402
|
+
);
|
|
403
|
+
|
|
404
|
+
return;
|
|
383
405
|
}
|
|
384
406
|
|
|
385
407
|
if ('conditional' in step) {
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
408
|
+
step.conditional.when.forEach((branch, branchIndex) => {
|
|
409
|
+
refs.push(
|
|
410
|
+
...collectTaskReferences(branch.steps, [
|
|
411
|
+
...stepPath,
|
|
412
|
+
'conditional',
|
|
413
|
+
'when',
|
|
414
|
+
branchIndex,
|
|
415
|
+
'steps',
|
|
416
|
+
]),
|
|
417
|
+
);
|
|
418
|
+
});
|
|
419
|
+
|
|
420
|
+
return;
|
|
394
421
|
}
|
|
395
422
|
|
|
396
423
|
if ('loop' in step) {
|
|
397
|
-
refs.push(
|
|
424
|
+
refs.push(
|
|
425
|
+
...collectTaskReferences(step.loop.steps, [
|
|
426
|
+
...stepPath,
|
|
427
|
+
'loop',
|
|
428
|
+
'steps',
|
|
429
|
+
]),
|
|
430
|
+
);
|
|
398
431
|
}
|
|
399
|
-
}
|
|
432
|
+
});
|
|
400
433
|
|
|
401
434
|
return refs;
|
|
402
435
|
};
|
|
@@ -414,12 +447,157 @@ export const extractTaskDefinitions = (defs: DefDefinitions): TaskDefinitions =>
|
|
|
414
447
|
return tasks;
|
|
415
448
|
}, {});
|
|
416
449
|
|
|
417
|
-
const
|
|
418
|
-
|
|
450
|
+
const EXECUTION_SETTING_KEYS = new Set(Object.keys(BaseSettingsSchema.shape));
|
|
451
|
+
const isExpressionString = (value: unknown): boolean =>
|
|
452
|
+
typeof value === 'string' && value.startsWith('=');
|
|
453
|
+
const toIssuePath = (path: readonly PropertyKey[]): Array<string | number> =>
|
|
454
|
+
path.filter(
|
|
455
|
+
(segment): segment is string | number =>
|
|
456
|
+
typeof segment === 'string' || typeof segment === 'number',
|
|
457
|
+
);
|
|
458
|
+
const getValueAtPath = (
|
|
459
|
+
value: unknown,
|
|
460
|
+
path: Array<string | number>,
|
|
461
|
+
): unknown => {
|
|
462
|
+
let current = value;
|
|
463
|
+
|
|
464
|
+
for (const segment of path) {
|
|
465
|
+
if (current === null || typeof current !== 'object') {
|
|
466
|
+
return undefined;
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
current = (current as Record<string | number, unknown>)[segment];
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
return current;
|
|
473
|
+
};
|
|
474
|
+
const extractActionSettings = (settings: unknown): Record<string, unknown> => {
|
|
475
|
+
if (!settings || typeof settings !== 'object' || Array.isArray(settings)) {
|
|
476
|
+
return {};
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
return Object.fromEntries(
|
|
480
|
+
Object.entries(settings).filter(
|
|
481
|
+
([key]) => !EXECUTION_SETTING_KEYS.has(key),
|
|
482
|
+
),
|
|
483
|
+
);
|
|
484
|
+
};
|
|
485
|
+
const toActionSchemaIssues = ({
|
|
486
|
+
actionName,
|
|
487
|
+
code,
|
|
488
|
+
payload,
|
|
489
|
+
schema,
|
|
490
|
+
section,
|
|
491
|
+
taskId,
|
|
492
|
+
}: {
|
|
493
|
+
actionName: string;
|
|
494
|
+
code: 'action_inputs' | 'action_settings';
|
|
495
|
+
payload: unknown;
|
|
496
|
+
schema: z.ZodTypeAny;
|
|
497
|
+
section: 'inputs' | 'settings';
|
|
498
|
+
taskId: string;
|
|
499
|
+
}): WorkflowValidationIssue[] => {
|
|
500
|
+
const result = schema.safeParse(payload);
|
|
501
|
+
|
|
502
|
+
if (result.success) {
|
|
503
|
+
return [];
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
return result.error.issues.flatMap<WorkflowValidationIssue>((issue) => {
|
|
507
|
+
const issuePath = toIssuePath(issue.path);
|
|
508
|
+
|
|
509
|
+
// Expressions are resolved immediately before action execution, so their
|
|
510
|
+
// eventual runtime type cannot be checked while validating the definition.
|
|
511
|
+
if (isExpressionString(getValueAtPath(payload, issuePath))) {
|
|
512
|
+
return [];
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
const path = ['defs', taskId, section, ...issuePath];
|
|
516
|
+
|
|
517
|
+
return [
|
|
518
|
+
{
|
|
519
|
+
actionName,
|
|
520
|
+
code,
|
|
521
|
+
message: `${path.join('.')}: ${issue.message}`,
|
|
522
|
+
path,
|
|
523
|
+
taskId,
|
|
524
|
+
},
|
|
525
|
+
];
|
|
526
|
+
});
|
|
527
|
+
};
|
|
528
|
+
const validateTaskActionSchemas = (
|
|
529
|
+
definition: WorkflowDefinition,
|
|
530
|
+
actions?: Record<string, WorkflowValidationActionMetadata>,
|
|
531
|
+
): WorkflowValidationIssue[] => {
|
|
532
|
+
if (!actions) {
|
|
533
|
+
return [];
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
const issues: WorkflowValidationIssue[] = [];
|
|
537
|
+
const taskDefinitions = extractTaskDefinitions(definition.defs);
|
|
538
|
+
|
|
539
|
+
for (const [taskId, task] of Object.entries(taskDefinitions)) {
|
|
540
|
+
const action = actions[task.action];
|
|
541
|
+
|
|
542
|
+
// Missing actions are reported by binding validation and have no schemas
|
|
543
|
+
// available for payload validation.
|
|
544
|
+
if (!action) {
|
|
545
|
+
continue;
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
if (action.inputSchema) {
|
|
549
|
+
issues.push(
|
|
550
|
+
...toActionSchemaIssues({
|
|
551
|
+
actionName: task.action,
|
|
552
|
+
code: 'action_inputs',
|
|
553
|
+
payload: task.inputs ?? {},
|
|
554
|
+
schema: action.inputSchema,
|
|
555
|
+
section: 'inputs',
|
|
556
|
+
taskId,
|
|
557
|
+
}),
|
|
558
|
+
);
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
if (action.settingSchema) {
|
|
562
|
+
const effectiveSettings = mergeSettings(
|
|
563
|
+
definition.defaults?.settings,
|
|
564
|
+
task.settings,
|
|
565
|
+
);
|
|
566
|
+
|
|
567
|
+
issues.push(
|
|
568
|
+
...toActionSchemaIssues({
|
|
569
|
+
actionName: task.action,
|
|
570
|
+
code: 'action_settings',
|
|
571
|
+
payload: extractActionSettings(effectiveSettings),
|
|
572
|
+
schema: action.settingSchema,
|
|
573
|
+
section: 'settings',
|
|
574
|
+
taskId,
|
|
575
|
+
}),
|
|
576
|
+
);
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
return issues;
|
|
581
|
+
};
|
|
582
|
+
const toSchemaIssues = (zodIssues: z.ZodIssue[]): WorkflowValidationIssue[] =>
|
|
583
|
+
zodIssues.map((issue) => {
|
|
419
584
|
const path = issue.path.join('.') || '<root>';
|
|
420
585
|
|
|
421
|
-
return
|
|
586
|
+
return {
|
|
587
|
+
code: 'schema',
|
|
588
|
+
message: `${path}: ${issue.message}`,
|
|
589
|
+
path: issue.path.filter(
|
|
590
|
+
(segment): segment is string | number =>
|
|
591
|
+
typeof segment === 'string' || typeof segment === 'number',
|
|
592
|
+
),
|
|
593
|
+
};
|
|
422
594
|
});
|
|
595
|
+
const invalidWorkflow = (
|
|
596
|
+
issues: WorkflowValidationIssue[],
|
|
597
|
+
): WorkflowValidationResult => ({
|
|
598
|
+
success: false,
|
|
599
|
+
issues,
|
|
600
|
+
});
|
|
423
601
|
|
|
424
602
|
export function validateWorkflow(
|
|
425
603
|
input: string | unknown,
|
|
@@ -434,30 +612,38 @@ export function validateWorkflow(
|
|
|
434
612
|
const message =
|
|
435
613
|
error instanceof Error ? error.message : 'Unknown YAML parse error';
|
|
436
614
|
|
|
437
|
-
return
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
615
|
+
return invalidWorkflow([
|
|
616
|
+
{ code: 'yaml_parse', message: 'Unable to parse workflow YAML' },
|
|
617
|
+
{ code: 'yaml_parse', message },
|
|
618
|
+
]);
|
|
441
619
|
}
|
|
442
620
|
}
|
|
443
621
|
|
|
444
622
|
const parsed = WorkflowDefinitionSchema.safeParse(candidate);
|
|
445
623
|
|
|
446
624
|
if (!parsed.success) {
|
|
447
|
-
return
|
|
625
|
+
return invalidWorkflow(toSchemaIssues(parsed.error.issues));
|
|
448
626
|
}
|
|
449
627
|
|
|
450
|
-
const
|
|
628
|
+
const issues: WorkflowValidationIssue[] = [];
|
|
451
629
|
const taskDefinitions = extractTaskDefinitions(parsed.data.defs);
|
|
452
|
-
const
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
630
|
+
const reportedMissingTasks = new Set<string>();
|
|
631
|
+
|
|
632
|
+
for (const { taskId, path } of collectTaskReferences(parsed.data.flow)) {
|
|
633
|
+
if (
|
|
634
|
+
Object.prototype.hasOwnProperty.call(taskDefinitions, taskId) ||
|
|
635
|
+
reportedMissingTasks.has(taskId)
|
|
636
|
+
) {
|
|
637
|
+
continue;
|
|
638
|
+
}
|
|
456
639
|
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
640
|
+
reportedMissingTasks.add(taskId);
|
|
641
|
+
issues.push({
|
|
642
|
+
code: 'unknown_task',
|
|
643
|
+
message: `Unknown task(s) referenced in flow: ${taskId}`,
|
|
644
|
+
path,
|
|
645
|
+
taskId,
|
|
646
|
+
});
|
|
461
647
|
}
|
|
462
648
|
|
|
463
649
|
const bindingValidation = validateAndResolveBindings(parsed.data, {
|
|
@@ -465,12 +651,11 @@ export function validateWorkflow(
|
|
|
465
651
|
actions: options?.actions,
|
|
466
652
|
});
|
|
467
653
|
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
}
|
|
654
|
+
issues.push(...bindingValidation.issues);
|
|
655
|
+
issues.push(...validateTaskActionSchemas(parsed.data, options?.actions));
|
|
471
656
|
|
|
472
|
-
if (
|
|
473
|
-
return
|
|
657
|
+
if (issues.length > 0) {
|
|
658
|
+
return invalidWorkflow(issues);
|
|
474
659
|
}
|
|
475
660
|
|
|
476
661
|
return { success: true, data: parsed.data };
|
package/src/index.ts
CHANGED