@defai.digital/workflow-engine 13.0.3

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.
@@ -0,0 +1,496 @@
1
+ /**
2
+ * Workflow Step Guard Implementation
3
+ *
4
+ * Enforces governance checks at workflow step boundaries.
5
+ *
6
+ * Invariants:
7
+ * - INV-WF-GUARD-001: Before guards run before step execution starts
8
+ * - INV-WF-GUARD-002: After guards run after step completes
9
+ * - INV-WF-GUARD-003: Block failures prevent step execution/continuation
10
+ * - INV-WF-GUARD-004: Guard results included in trace events
11
+ */
12
+ import { createStepGuardResult, createProgressEvent, } from '@defai.digital/contracts';
13
+ /**
14
+ * Default step guard engine configuration
15
+ */
16
+ export const DEFAULT_STEP_GUARD_ENGINE_CONFIG = {
17
+ enabled: true,
18
+ defaultOnFail: 'warn',
19
+ };
20
+ /**
21
+ * Step Guard Engine
22
+ *
23
+ * Manages step guards and executes them at appropriate times.
24
+ */
25
+ export class StepGuardEngine {
26
+ config;
27
+ gateRegistry;
28
+ policies = new Map();
29
+ onProgressEvent;
30
+ constructor(config = {}) {
31
+ this.config = { ...DEFAULT_STEP_GUARD_ENGINE_CONFIG, ...config };
32
+ this.gateRegistry = config.gateRegistry ?? createGateRegistry();
33
+ this.onProgressEvent = config.onProgressEvent;
34
+ // Register default gates
35
+ this.registerDefaultGates();
36
+ }
37
+ /**
38
+ * Register a guard policy
39
+ */
40
+ registerPolicy(policy) {
41
+ this.policies.set(policy.policyId, policy);
42
+ }
43
+ /**
44
+ * Remove a guard policy
45
+ */
46
+ removePolicy(policyId) {
47
+ return this.policies.delete(policyId);
48
+ }
49
+ /**
50
+ * Get all registered policies
51
+ */
52
+ getPolicies() {
53
+ return Array.from(this.policies.values());
54
+ }
55
+ /**
56
+ * Register a custom gate
57
+ */
58
+ registerGate(gateId, check) {
59
+ this.gateRegistry.register(gateId, check);
60
+ }
61
+ /**
62
+ * Run before guards for a step
63
+ * INV-WF-GUARD-001: Runs before step execution
64
+ */
65
+ async runBeforeGuards(context) {
66
+ return this.runGuards(context, 'before');
67
+ }
68
+ /**
69
+ * Run after guards for a step
70
+ * INV-WF-GUARD-002: Runs after step completes
71
+ */
72
+ async runAfterGuards(context) {
73
+ return this.runGuards(context, 'after');
74
+ }
75
+ /**
76
+ * Check if step should be blocked
77
+ * INV-WF-GUARD-003: Block failures prevent execution
78
+ */
79
+ shouldBlock(results) {
80
+ return results.some((r) => r.blocked);
81
+ }
82
+ /**
83
+ * Emit progress event
84
+ * INV-PROG-001, INV-PROG-002: Progress events emitted
85
+ */
86
+ emitProgress(executionId, agentId, stageIndex, stageTotal, stageName, stageType, status, options = {}) {
87
+ if (this.onProgressEvent) {
88
+ const event = createProgressEvent(executionId, agentId, stageIndex, stageTotal, stageName, stageType, status, options);
89
+ this.onProgressEvent(event);
90
+ }
91
+ }
92
+ /**
93
+ * Run guards at a position
94
+ */
95
+ async runGuards(context, position) {
96
+ if (!this.config.enabled) {
97
+ return [];
98
+ }
99
+ const results = [];
100
+ const applicablePolicies = this.getApplicablePolicies(context);
101
+ // Sort by priority (highest first)
102
+ // INV-POL-001: Priority ordering
103
+ applicablePolicies.sort((a, b) => b.priority - a.priority);
104
+ for (const policy of applicablePolicies) {
105
+ for (const guard of policy.guards) {
106
+ if (!guard.enabled)
107
+ continue;
108
+ if (guard.position !== position)
109
+ continue;
110
+ if (!this.matchesStep(guard.stepId, context.stepId))
111
+ continue;
112
+ const result = await this.runGuard(guard, context);
113
+ results.push(result);
114
+ }
115
+ }
116
+ return results;
117
+ }
118
+ /**
119
+ * Run a single guard
120
+ */
121
+ async runGuard(guard, context) {
122
+ const startTime = Date.now();
123
+ const gateResults = [];
124
+ // INV-GATE-001: Gates execute independently
125
+ for (const gateId of guard.gates) {
126
+ const gateFn = this.gateRegistry.get(gateId);
127
+ if (!gateFn) {
128
+ gateResults.push({
129
+ gateId,
130
+ status: 'WARN',
131
+ message: `Gate "${gateId}" not found`,
132
+ });
133
+ continue;
134
+ }
135
+ try {
136
+ const result = await gateFn(context);
137
+ gateResults.push(result);
138
+ }
139
+ catch (error) {
140
+ gateResults.push({
141
+ gateId,
142
+ status: 'FAIL',
143
+ message: error instanceof Error ? error.message : 'Gate check failed',
144
+ });
145
+ }
146
+ }
147
+ // Determine if should block
148
+ const hasFailure = gateResults.some((g) => g.status === 'FAIL');
149
+ const blocked = hasFailure && guard.onFail === 'block';
150
+ const result = createStepGuardResult(guard.guardId, context.stepId, guard.position, gateResults, blocked);
151
+ // Set duration
152
+ result.durationMs = Date.now() - startTime;
153
+ return result;
154
+ }
155
+ /**
156
+ * Get policies applicable to context
157
+ */
158
+ getApplicablePolicies(context) {
159
+ const applicable = [];
160
+ for (const policy of this.policies.values()) {
161
+ if (!policy.enabled)
162
+ continue;
163
+ if (!this.matchesPatterns(policy.agentPatterns, context.agentId))
164
+ continue;
165
+ if (policy.stepTypes && !policy.stepTypes.includes(context.stepType))
166
+ continue;
167
+ if (context.workflowId && !this.matchesPatterns(policy.workflowPatterns, context.workflowId))
168
+ continue;
169
+ applicable.push(policy);
170
+ }
171
+ return applicable;
172
+ }
173
+ /**
174
+ * Check if step ID matches pattern
175
+ */
176
+ matchesStep(pattern, stepId) {
177
+ if (pattern === '*')
178
+ return true;
179
+ return this.globMatch(pattern, stepId);
180
+ }
181
+ /**
182
+ * Check if any pattern matches value
183
+ */
184
+ matchesPatterns(patterns, value) {
185
+ return patterns.some((p) => p === '*' || this.globMatch(p, value));
186
+ }
187
+ /**
188
+ * Simple glob matching (* only)
189
+ */
190
+ globMatch(pattern, value) {
191
+ const regex = new RegExp('^' + pattern.split('*').map(this.escapeRegex).join('.*') + '$');
192
+ return regex.test(value);
193
+ }
194
+ /**
195
+ * Escape regex special characters
196
+ */
197
+ escapeRegex(str) {
198
+ return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
199
+ }
200
+ /**
201
+ * Register default gates
202
+ */
203
+ registerDefaultGates() {
204
+ // Validation gate - validates step configuration based on step type
205
+ this.gateRegistry.register('validation', async (context) => {
206
+ const config = context.stepConfig;
207
+ const errors = [];
208
+ const warnings = [];
209
+ // Only validate step config if it's provided
210
+ // When stepConfig is undefined, the step is assumed to be configured elsewhere
211
+ if (config !== undefined && Object.keys(config).length > 0) {
212
+ // Validate based on step type
213
+ switch (context.stepType) {
214
+ case 'prompt':
215
+ // Prompt steps require a prompt field
216
+ if (!config.prompt && !config.template) {
217
+ errors.push('Prompt step requires "prompt" or "template" in config');
218
+ }
219
+ break;
220
+ case 'tool':
221
+ // Tool steps require a tool name
222
+ if (!config.toolName && !config.tool) {
223
+ errors.push('Tool step requires "toolName" or "tool" in config');
224
+ }
225
+ break;
226
+ case 'conditional':
227
+ // Conditional steps require a condition
228
+ if (!config.condition && !config.when) {
229
+ errors.push('Conditional step requires "condition" or "when" in config');
230
+ }
231
+ break;
232
+ case 'loop':
233
+ // Loop steps require items or count
234
+ if (!config.items && !config.count && !config.until) {
235
+ errors.push('Loop step requires "items", "count", or "until" in config');
236
+ }
237
+ break;
238
+ case 'discuss':
239
+ // Discuss steps require a topic/prompt and providers
240
+ if (!config.prompt && !config.topic) {
241
+ errors.push('Discuss step requires "prompt" or "topic" in config');
242
+ }
243
+ break;
244
+ case 'delegate':
245
+ // Delegate steps require target agent
246
+ if (!config.agentId && !config.targetAgent) {
247
+ errors.push('Delegate step requires "agentId" or "targetAgent" in config');
248
+ }
249
+ break;
250
+ }
251
+ }
252
+ // Check step ID format (should be kebab-case) - warn but don't fail
253
+ if (!/^[a-z][a-z0-9-]*$/.test(context.stepId)) {
254
+ warnings.push(`Step ID "${context.stepId}" should be kebab-case (lowercase letters, numbers, hyphens)`);
255
+ }
256
+ if (errors.length > 0) {
257
+ return {
258
+ gateId: 'validation',
259
+ status: 'FAIL',
260
+ message: `Validation failed: ${errors.join('; ')}`,
261
+ details: { errors, warnings },
262
+ };
263
+ }
264
+ if (warnings.length > 0) {
265
+ return {
266
+ gateId: 'validation',
267
+ status: 'WARN',
268
+ message: `Validation passed with warnings: ${warnings.join('; ')}`,
269
+ details: { warnings },
270
+ };
271
+ }
272
+ return {
273
+ gateId: 'validation',
274
+ status: 'PASS',
275
+ message: 'Step configuration is valid',
276
+ details: { stepType: context.stepType },
277
+ };
278
+ });
279
+ // Capability gate - checks if infrastructure is available for step type
280
+ this.gateRegistry.register('capability', async (context) => {
281
+ const warnings = [];
282
+ // Check capabilities based on step type
283
+ switch (context.stepType) {
284
+ case 'prompt':
285
+ case 'discuss':
286
+ // These require LLM provider access
287
+ // In a full implementation, we'd check if providers are configured
288
+ break;
289
+ case 'tool':
290
+ // Check if the tool is available
291
+ const toolName = (context.stepConfig)?.toolName ??
292
+ (context.stepConfig)?.tool;
293
+ if (toolName && typeof toolName === 'string') {
294
+ // Could check tool registry here
295
+ // For now, warn if it's an unknown tool type
296
+ const knownTools = ['read', 'write', 'search', 'execute', 'fetch'];
297
+ if (!knownTools.includes(toolName.toLowerCase())) {
298
+ warnings.push(`Tool "${toolName}" may require custom executor`);
299
+ }
300
+ }
301
+ break;
302
+ case 'delegate':
303
+ // Delegation requires agent registry
304
+ const targetAgent = (context.stepConfig)?.agentId ??
305
+ (context.stepConfig)?.targetAgent;
306
+ if (!targetAgent) {
307
+ warnings.push('Delegate step has no target agent specified');
308
+ }
309
+ break;
310
+ }
311
+ if (warnings.length > 0) {
312
+ return {
313
+ gateId: 'capability',
314
+ status: 'WARN',
315
+ message: `Capability warnings: ${warnings.join('; ')}`,
316
+ details: { warnings, agentId: context.agentId },
317
+ };
318
+ }
319
+ return {
320
+ gateId: 'capability',
321
+ status: 'PASS',
322
+ message: `Agent ${context.agentId} has required capabilities for ${context.stepType} step`,
323
+ details: { stepType: context.stepType },
324
+ };
325
+ });
326
+ // Resource gate - checks resource limits and thresholds
327
+ this.gateRegistry.register('resource', async (context) => {
328
+ const issues = [];
329
+ // Check step limit thresholds
330
+ const MAX_STEPS_WARNING = 50;
331
+ const MAX_STEPS_LIMIT = 100;
332
+ if (context.totalSteps > MAX_STEPS_LIMIT) {
333
+ return {
334
+ gateId: 'resource',
335
+ status: 'FAIL',
336
+ message: `Workflow exceeds maximum step limit (${context.totalSteps} > ${MAX_STEPS_LIMIT})`,
337
+ details: {
338
+ totalSteps: context.totalSteps,
339
+ limit: MAX_STEPS_LIMIT,
340
+ },
341
+ };
342
+ }
343
+ if (context.totalSteps > MAX_STEPS_WARNING) {
344
+ issues.push(`Workflow has ${context.totalSteps} steps (warning threshold: ${MAX_STEPS_WARNING})`);
345
+ }
346
+ // Check if we're past the halfway point (useful for long workflows)
347
+ const progress = (context.stepIndex + 1) / context.totalSteps;
348
+ if (progress > 0.9 && context.totalSteps > 10) {
349
+ // Nearing completion - just informational
350
+ }
351
+ // Check for potential infinite loops (same step appearing in outputs)
352
+ const outputKeys = Object.keys(context.previousOutputs);
353
+ const currentStepOutputCount = outputKeys.filter(k => k.startsWith(context.stepId)).length;
354
+ if (currentStepOutputCount > 5) {
355
+ issues.push(`Step "${context.stepId}" has run ${currentStepOutputCount} times - possible loop`);
356
+ }
357
+ if (issues.length > 0) {
358
+ return {
359
+ gateId: 'resource',
360
+ status: 'WARN',
361
+ message: `Resource warnings: ${issues.join('; ')}`,
362
+ details: {
363
+ stepIndex: context.stepIndex,
364
+ totalSteps: context.totalSteps,
365
+ warnings: issues,
366
+ },
367
+ };
368
+ }
369
+ return {
370
+ gateId: 'resource',
371
+ status: 'PASS',
372
+ message: 'Resource limits not exceeded',
373
+ details: {
374
+ stepIndex: context.stepIndex,
375
+ totalSteps: context.totalSteps,
376
+ remainingSteps: context.totalSteps - context.stepIndex - 1,
377
+ },
378
+ };
379
+ });
380
+ // Progress gate - checks execution progress
381
+ this.gateRegistry.register('progress', async (context) => {
382
+ const progress = ((context.stepIndex + 1) / context.totalSteps) * 100;
383
+ return {
384
+ gateId: 'progress',
385
+ status: 'PASS',
386
+ message: `Execution at ${progress.toFixed(0)}%`,
387
+ details: {
388
+ stepIndex: context.stepIndex,
389
+ totalSteps: context.totalSteps,
390
+ percentComplete: progress,
391
+ },
392
+ };
393
+ });
394
+ }
395
+ }
396
+ // ============================================================================
397
+ // Gate Registry Implementation
398
+ // ============================================================================
399
+ /**
400
+ * Create a gate registry
401
+ */
402
+ export function createGateRegistry() {
403
+ const gates = new Map();
404
+ return {
405
+ register(gateId, check) {
406
+ gates.set(gateId, check);
407
+ },
408
+ get(gateId) {
409
+ return gates.get(gateId);
410
+ },
411
+ has(gateId) {
412
+ return gates.has(gateId);
413
+ },
414
+ list() {
415
+ return Array.from(gates.keys());
416
+ },
417
+ };
418
+ }
419
+ /**
420
+ * Create a step guard engine
421
+ */
422
+ export function createStepGuardEngine(config) {
423
+ return new StepGuardEngine(config);
424
+ }
425
+ // ============================================================================
426
+ // Progress Tracker
427
+ // ============================================================================
428
+ /**
429
+ * Progress tracker for workflow execution
430
+ *
431
+ * Tracks stage progress and emits events.
432
+ */
433
+ export class ProgressTracker {
434
+ executionId;
435
+ agentId;
436
+ sessionId;
437
+ totalSteps;
438
+ onEvent;
439
+ constructor(executionId, agentId, totalSteps, onEvent, sessionId) {
440
+ this.executionId = executionId;
441
+ this.agentId = agentId;
442
+ this.sessionId = sessionId;
443
+ this.totalSteps = totalSteps;
444
+ this.onEvent = onEvent;
445
+ }
446
+ /**
447
+ * Emit starting event
448
+ * INV-PROG-001: Every stage emits starting event
449
+ */
450
+ starting(stepIndex, stepId, stepType) {
451
+ this.emit(stepIndex, stepId, stepType, 'starting');
452
+ }
453
+ /**
454
+ * Emit completed event
455
+ * INV-PROG-002: Every stage emits terminal event
456
+ */
457
+ completed(stepIndex, stepId, stepType, durationMs) {
458
+ this.emit(stepIndex, stepId, stepType, 'completed', { durationMs });
459
+ }
460
+ /**
461
+ * Emit failed event
462
+ */
463
+ failed(stepIndex, stepId, stepType, error, durationMs) {
464
+ this.emit(stepIndex, stepId, stepType, 'failed', { durationMs, error });
465
+ }
466
+ /**
467
+ * Emit skipped event
468
+ */
469
+ skipped(stepIndex, stepId, stepType) {
470
+ this.emit(stepIndex, stepId, stepType, 'skipped');
471
+ }
472
+ /**
473
+ * Emit blocked event
474
+ */
475
+ blocked(stepIndex, stepId, stepType, guardResult) {
476
+ this.emit(stepIndex, stepId, stepType, 'blocked', { guardResult });
477
+ }
478
+ /**
479
+ * Emit event
480
+ */
481
+ emit(stepIndex, stepId, stepType, status, options = {}) {
482
+ const eventOptions = { ...options };
483
+ if (this.sessionId !== undefined) {
484
+ eventOptions.sessionId = this.sessionId;
485
+ }
486
+ const event = createProgressEvent(this.executionId, this.agentId, stepIndex, this.totalSteps, stepId, stepType, status, eventOptions);
487
+ this.onEvent(event);
488
+ }
489
+ }
490
+ /**
491
+ * Create a progress tracker
492
+ */
493
+ export function createProgressTracker(executionId, agentId, totalSteps, onEvent, sessionId) {
494
+ return new ProgressTracker(executionId, agentId, totalSteps, onEvent, sessionId);
495
+ }
496
+ //# sourceMappingURL=step-guard.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"step-guard.js","sourceRoot":"","sources":["../src/step-guard.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAaH,OAAO,EACL,qBAAqB,EACrB,mBAAmB,GACpB,MAAM,0BAA0B,CAAC;AA2ClC;;GAEG;AACH,MAAM,CAAC,MAAM,gCAAgC,GAA0B;IACrE,OAAO,EAAE,IAAI;IACb,aAAa,EAAE,MAAM;CACtB,CAAC;AAEF;;;;GAIG;AACH,MAAM,OAAO,eAAe;IACT,MAAM,CAAwB;IAC9B,YAAY,CAAe;IAC3B,QAAQ,GAAG,IAAI,GAAG,EAA2B,CAAC;IAC9C,eAAe,CAAoD;IAEpF,YAAY,SAAyC,EAAE;QACrD,IAAI,CAAC,MAAM,GAAG,EAAE,GAAG,gCAAgC,EAAE,GAAG,MAAM,EAAE,CAAC;QACjE,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC,YAAY,IAAI,kBAAkB,EAAE,CAAC;QAChE,IAAI,CAAC,eAAe,GAAG,MAAM,CAAC,eAAe,CAAC;QAE9C,yBAAyB;QACzB,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IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC;IACpD,CAAC;IAED;;OAEG;IACH,OAAO,CACL,SAAiB,EACjB,MAAc,EACd,QAAgB,EAChB,WAA4B;QAE5B,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,EAAE,WAAW,EAAE,CAAC,CAAC;IACrE,CAAC;IAED;;OAEG;IACK,IAAI,CACV,SAAiB,EACjB,MAAc,EACd,QAAgB,EAChB,MAA2B,EAC3B,UAII,EAAE;QAEN,MAAM,YAAY,GAKd,EAAE,GAAG,OAAO,EAAE,CAAC;QAEnB,IAAI,IAAI,CAAC,SAAS,KAAK,SAAS,EAAE,CAAC;YACjC,YAAY,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC;QAC1C,CAAC;QAED,MAAM,KAAK,GAAG,mBAAmB,CAC/B,IAAI,CAAC,WAAW,EAChB,IAAI,CAAC,OAAO,EACZ,SAAS,EACT,IAAI,CAAC,UAAU,EACf,MAAM,EACN,QAAQ,EACR,MAAM,EACN,YAAY,CACb,CAAC;QACF,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IACtB,CAAC;CACF;AAED;;GAEG;AACH,MAAM,UAAU,qBAAqB,CACnC,WAAmB,EACnB,OAAe,EACf,UAAkB,EAClB,OAA4C,EAC5C,SAAkB;IAElB,OAAO,IAAI,eAAe,CAAC,WAAW,EAAE,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC;AACnF,CAAC"}
@@ -0,0 +1,95 @@
1
+ import type { Workflow, WorkflowStep, RetryPolicy } from '@defai.digital/contracts';
2
+ /**
3
+ * Result of a step execution
4
+ */
5
+ export interface StepResult {
6
+ stepId: string;
7
+ success: boolean;
8
+ output?: unknown;
9
+ error?: StepError | undefined;
10
+ durationMs: number;
11
+ retryCount: number;
12
+ }
13
+ /**
14
+ * Error from step execution
15
+ */
16
+ export interface StepError {
17
+ code: string;
18
+ message: string;
19
+ retryable: boolean;
20
+ details?: Record<string, unknown> | undefined;
21
+ }
22
+ /**
23
+ * Result of a workflow execution
24
+ */
25
+ export interface WorkflowResult {
26
+ workflowId: string;
27
+ success: boolean;
28
+ stepResults: StepResult[];
29
+ output?: unknown;
30
+ error?: WorkflowError | undefined;
31
+ totalDurationMs: number;
32
+ }
33
+ /**
34
+ * Error from workflow execution
35
+ */
36
+ export interface WorkflowError {
37
+ code: string;
38
+ message: string;
39
+ failedStepId?: string | undefined;
40
+ details?: Record<string, unknown> | undefined;
41
+ }
42
+ /**
43
+ * Context passed to step executors
44
+ */
45
+ export interface StepContext {
46
+ workflowId: string;
47
+ stepIndex: number;
48
+ previousResults: StepResult[];
49
+ input?: unknown;
50
+ }
51
+ /**
52
+ * Function that executes a single step
53
+ */
54
+ export type StepExecutor = (step: WorkflowStep, context: StepContext) => Promise<StepResult>;
55
+ /**
56
+ * Configuration for the workflow runner
57
+ */
58
+ export interface WorkflowRunnerConfig {
59
+ /**
60
+ * Custom step executor (for dependency injection)
61
+ */
62
+ stepExecutor?: StepExecutor | undefined;
63
+ /**
64
+ * Default retry policy if step doesn't specify one
65
+ */
66
+ defaultRetryPolicy?: RetryPolicy | undefined;
67
+ /**
68
+ * Called before each step executes
69
+ */
70
+ onStepStart?: ((step: WorkflowStep, context: StepContext) => void) | undefined;
71
+ /**
72
+ * Called after each step completes
73
+ */
74
+ onStepComplete?: ((step: WorkflowStep, result: StepResult) => void) | undefined;
75
+ }
76
+ /**
77
+ * Validated and frozen workflow ready for execution
78
+ */
79
+ export interface PreparedWorkflow {
80
+ readonly workflow: Readonly<Workflow>;
81
+ readonly stepIds: ReadonlySet<string>;
82
+ }
83
+ /**
84
+ * Error codes for workflow engine
85
+ */
86
+ export declare const WorkflowErrorCodes: {
87
+ readonly VALIDATION_ERROR: "WORKFLOW_VALIDATION_ERROR";
88
+ readonly DUPLICATE_STEP_ID: "WORKFLOW_DUPLICATE_STEP_ID";
89
+ readonly STEP_EXECUTION_FAILED: "WORKFLOW_STEP_EXECUTION_FAILED";
90
+ readonly STEP_TIMEOUT: "WORKFLOW_STEP_TIMEOUT";
91
+ readonly MAX_RETRIES_EXCEEDED: "WORKFLOW_MAX_RETRIES_EXCEEDED";
92
+ readonly UNKNOWN_STEP_TYPE: "WORKFLOW_UNKNOWN_STEP_TYPE";
93
+ };
94
+ export type WorkflowErrorCode = (typeof WorkflowErrorCodes)[keyof typeof WorkflowErrorCodes];
95
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,QAAQ,EACR,YAAY,EACZ,WAAW,EACZ,MAAM,0BAA0B,CAAC;AAElC;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,SAAS,GAAG,SAAS,CAAC;IAC9B,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAAC;CAC/C;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,OAAO,CAAC;IACjB,WAAW,EAAE,UAAU,EAAE,CAAC;IAC1B,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,aAAa,GAAG,SAAS,CAAC;IAClC,eAAe,EAAE,MAAM,CAAC;CACzB;AAED;;GAEG;AACH,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AAM,OAAO,kBAAkB,CAAC,CAAC"}
package/dist/types.js ADDED
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Error codes for workflow engine
3
+ */
4
+ export const WorkflowErrorCodes = {
5
+ VALIDATION_ERROR: 'WORKFLOW_VALIDATION_ERROR',
6
+ DUPLICATE_STEP_ID: 'WORKFLOW_DUPLICATE_STEP_ID',
7
+ STEP_EXECUTION_FAILED: 'WORKFLOW_STEP_EXECUTION_FAILED',
8
+ STEP_TIMEOUT: 'WORKFLOW_STEP_TIMEOUT',
9
+ MAX_RETRIES_EXCEEDED: 'WORKFLOW_MAX_RETRIES_EXCEEDED',
10
+ UNKNOWN_STEP_TYPE: 'WORKFLOW_UNKNOWN_STEP_TYPE',
11
+ };
12
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAqGA;;GAEG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG;IAChC,gBAAgB,EAAE,2BAA2B;IAC7C,iBAAiB,EAAE,4BAA4B;IAC/C,qBAAqB,EAAE,gCAAgC;IACvD,YAAY,EAAE,uBAAuB;IACrC,oBAAoB,EAAE,+BAA+B;IACrD,iBAAiB,EAAE,4BAA4B;CACvC,CAAC"}
@@ -0,0 +1,29 @@
1
+ import { type Workflow } from '@defai.digital/contracts';
2
+ import type { PreparedWorkflow, StepResult } from './types.js';
3
+ /**
4
+ * Validation error for workflows
5
+ */
6
+ export declare class WorkflowValidationError extends Error {
7
+ readonly code: string;
8
+ readonly details?: Record<string, unknown> | undefined;
9
+ constructor(code: string, message: string, details?: Record<string, unknown> | undefined);
10
+ }
11
+ /**
12
+ * Validates a workflow definition and checks invariants
13
+ * INV-WF-003: Schema strictness - unknown fields rejected
14
+ * INV-WF-004: Step ID uniqueness
15
+ */
16
+ export declare function validateWorkflow(data: unknown): Workflow;
17
+ /**
18
+ * Prepares a workflow for execution by validating and freezing it
19
+ * INV-WF-003: Schema strictness
20
+ * INV-WF-004: Step ID uniqueness
21
+ * INV-WF-005: Immutable definition
22
+ */
23
+ export declare function prepareWorkflow(data: unknown): PreparedWorkflow;
24
+ /**
25
+ * Deep freezes a step result to ensure immutability
26
+ * This prevents subsequent steps from accidentally modifying previous results
27
+ */
28
+ export declare function deepFreezeStepResult(result: StepResult): Readonly<StepResult>;
29
+ //# sourceMappingURL=validation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../src/validation.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,QAAQ,EACd,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAG/D;;GAEG;AACH,qBAAa,uBAAwB,SAAQ,KAAK;aAE9B,IAAI,EAAE,MAAM;aAEZ,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;gBAFjC,IAAI,EAAE,MAAM,EAC5B,OAAO,EAAE,MAAM,EACC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,YAAA;CAKpD;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,OAAO,GAAG,QAAQ,CA6BxD;AAmBD;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,OAAO,GAAG,gBAAgB,CAa/D;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,UAAU,GAAG,QAAQ,CAAC,UAAU,CAAC,CAE7E"}