@multiplier-labs/stepflow 0.3.4 → 0.3.6

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.
Files changed (99) hide show
  1. package/README.md +9 -0
  2. package/dist/{chunk-U3PCVK6O.js → chunk-D5HW7VEG.js} +4 -2
  3. package/dist/chunk-D5HW7VEG.js.map +1 -0
  4. package/dist/{chunk-5XJBAPXF.js → chunk-JUPZEBR3.js} +3 -1
  5. package/dist/{chunk-5XJBAPXF.js.map → chunk-JUPZEBR3.js.map} +1 -1
  6. package/dist/events/index.d.ts +2 -0
  7. package/dist/events/index.js +1 -1
  8. package/dist/index.js +2 -2
  9. package/dist/storage/index.js +1 -1
  10. package/package.json +23 -12
  11. package/.codekin/reports/code-review/2026-04-11_code-review-daily.md +0 -146
  12. package/.codekin/reports/code-review/2026-04-13_code-review-daily.md +0 -74
  13. package/.codekin/reports/comments/2026-04-04_comment-assessment.md +0 -179
  14. package/.codekin/reports/comments/2026-04-11_comment-assessment.md +0 -161
  15. package/.codekin/reports/comments/2026-04-14_comment-assessment.md +0 -34
  16. package/.codekin/reports/complexity/2026-04-03_complexity-report.md +0 -152
  17. package/.codekin/reports/complexity/2026-04-11_complexity-report.md +0 -152
  18. package/.codekin/reports/complexity/2026-04-14_complexity-report.md +0 -34
  19. package/.codekin/reports/dependencies/2026-04-04_dependency-health.md +0 -94
  20. package/.codekin/reports/dependencies/2026-04-11_dependency-health.md +0 -93
  21. package/.codekin/reports/docs-audit/2026-04-04_docs-audit.md +0 -10
  22. package/.codekin/reports/docs-audit/2026-04-11_docs-audit.md +0 -138
  23. package/.codekin/reports/docs-audit/2026-04-13_docs-audit.md +0 -121
  24. package/.codekin/reports/security/2026-04-03_security-audit.md +0 -208
  25. package/.codekin/reports/security/2026-04-11_security-audit.md +0 -297
  26. package/.github/CODEOWNERS +0 -15
  27. package/.github/dependabot.yml +0 -23
  28. package/.github/workflows/ci.yml +0 -38
  29. package/.github/workflows/publish.yml +0 -42
  30. package/.github/workflows/security.yml +0 -29
  31. package/CHANGELOG.md +0 -34
  32. package/SECURITY.md +0 -40
  33. package/dist/chunk-U3PCVK6O.js.map +0 -1
  34. package/docs/github-packages-setup.md +0 -97
  35. package/docs/stepflow-api-reference.md +0 -1663
  36. package/src/core/engine/concurrency.ts +0 -229
  37. package/src/core/engine/lifecycle.ts +0 -176
  38. package/src/core/engine.test.ts +0 -1435
  39. package/src/core/engine.ts +0 -598
  40. package/src/core/index.ts +0 -7
  41. package/src/core/orchestrator/persistence.ts +0 -165
  42. package/src/core/orchestrator/plan-resolution.ts +0 -140
  43. package/src/core/orchestrator/state-transitions.ts +0 -109
  44. package/src/core/orchestrator/step-runner.ts +0 -427
  45. package/src/core/orchestrator.ts +0 -252
  46. package/src/core/types.ts +0 -220
  47. package/src/events/index.ts +0 -8
  48. package/src/events/memory.test.ts +0 -107
  49. package/src/events/memory.ts +0 -92
  50. package/src/events/socketio.test.ts +0 -378
  51. package/src/events/socketio.ts +0 -262
  52. package/src/events/types.ts +0 -118
  53. package/src/events/webhook.test.ts +0 -949
  54. package/src/events/webhook.ts +0 -807
  55. package/src/index.ts +0 -270
  56. package/src/planning/evaluate-condition.test.ts +0 -153
  57. package/src/planning/evaluate-condition.ts +0 -105
  58. package/src/planning/index.ts +0 -55
  59. package/src/planning/planner.ts +0 -494
  60. package/src/planning/planning.test.ts +0 -727
  61. package/src/planning/registry.test.ts +0 -398
  62. package/src/planning/registry.ts +0 -283
  63. package/src/planning/types.ts +0 -566
  64. package/src/scheduler/cron.test.ts +0 -479
  65. package/src/scheduler/cron.ts +0 -438
  66. package/src/scheduler/index.ts +0 -8
  67. package/src/scheduler/postgres-persistence.ts +0 -530
  68. package/src/scheduler/sqlite-persistence.test.ts +0 -235
  69. package/src/scheduler/sqlite-persistence.ts +0 -286
  70. package/src/scheduler/types.ts +0 -73
  71. package/src/storage/index.ts +0 -27
  72. package/src/storage/memory.test.ts +0 -349
  73. package/src/storage/memory.ts +0 -227
  74. package/src/storage/postgres-core.ts +0 -550
  75. package/src/storage/postgres-migration.test.ts +0 -69
  76. package/src/storage/postgres-transaction-pagination.test.ts +0 -107
  77. package/src/storage/postgres.ts +0 -835
  78. package/src/storage/sqlite-core.ts +0 -151
  79. package/src/storage/sqlite.test.ts +0 -642
  80. package/src/storage/sqlite.ts +0 -717
  81. package/src/storage/types.ts +0 -343
  82. package/src/utils/errors.test.ts +0 -150
  83. package/src/utils/errors.ts +0 -161
  84. package/src/utils/id.ts +0 -21
  85. package/src/utils/index.ts +0 -10
  86. package/src/utils/logger.test.ts +0 -121
  87. package/src/utils/logger.ts +0 -96
  88. package/src/utils/pinned-fetch.test.ts +0 -84
  89. package/src/utils/pinned-fetch.ts +0 -118
  90. package/src/utils/postgres-deps.ts +0 -79
  91. package/src/utils/retry.test.ts +0 -177
  92. package/src/utils/retry.ts +0 -121
  93. package/src/utils/safe-json.test.ts +0 -166
  94. package/src/utils/safe-json.ts +0 -107
  95. package/src/utils/webhook-signature.test.ts +0 -111
  96. package/src/utils/webhook-signature.ts +0 -74
  97. package/tsconfig.json +0 -21
  98. package/tsup.config.ts +0 -14
  99. package/vitest.config.ts +0 -9
@@ -1,566 +0,0 @@
1
- /**
2
- * Planning types for the workflow engine.
3
- * Enables dynamic workflow orchestration through recipes and plans.
4
- */
5
-
6
- import type { WorkflowKind, StepErrorStrategy, WorkflowStep } from '../core/types';
7
-
8
- // Re-export core types used in planning
9
- export type { WorkflowKind, StepErrorStrategy } from '../core/types';
10
-
11
- // ============================================================================
12
- // Recipe Types
13
- // ============================================================================
14
-
15
- /**
16
- * Comparison operators for recipe conditions.
17
- */
18
- export type ConditionOperator =
19
- | 'eq' // equals
20
- | 'neq' // not equals
21
- | 'gt' // greater than
22
- | 'gte' // greater than or equal
23
- | 'lt' // less than
24
- | 'lte' // less than or equal
25
- | 'contains' // string/array contains
26
- | 'matches' // regex match
27
- | 'exists' // field exists and is truthy
28
- | 'notExists'; // field does not exist or is falsy
29
-
30
- /**
31
- * A condition that determines when a recipe should be selected.
32
- * Conditions are evaluated against the workflow input.
33
- */
34
- export interface RecipeCondition {
35
- /** Input field to check (supports dot notation for nested fields) */
36
- field: string;
37
-
38
- /** Comparison operator */
39
- operator: ConditionOperator;
40
-
41
- /** Value to compare against (not required for exists/notExists) */
42
- value?: unknown;
43
- }
44
-
45
- /**
46
- * Default parameters for a recipe.
47
- */
48
- export interface RecipeDefaults {
49
- /** Workflow-level timeout in ms */
50
- timeout?: number;
51
-
52
- /** Default max retries for steps */
53
- maxRetries?: number;
54
-
55
- /** Base retry delay in ms */
56
- retryDelay?: number;
57
-
58
- /** Retry backoff multiplier */
59
- retryBackoff?: number;
60
-
61
- /** Default error strategy for steps */
62
- onError?: StepErrorStrategy;
63
- }
64
-
65
- /**
66
- * Reference to a step handler function.
67
- * The actual handler is resolved at plan execution time.
68
- */
69
- export interface StepHandlerRef {
70
- /** Unique handler identifier (e.g., 'handlers.loadDocument') */
71
- id: string;
72
-
73
- /** Human-readable description */
74
- description?: string;
75
- }
76
-
77
- /**
78
- * A step definition within a recipe.
79
- * Similar to WorkflowStep but uses handler references instead of functions.
80
- */
81
- export interface RecipeStep {
82
- /** Unique step identifier within the recipe */
83
- key: string;
84
-
85
- /** Human-readable step name */
86
- name: string;
87
-
88
- /** Reference to the step handler function */
89
- handlerRef: string;
90
-
91
- /** Step-specific configuration passed to the handler */
92
- config?: Record<string, unknown>;
93
-
94
- /** Error handling strategy */
95
- onError?: StepErrorStrategy;
96
-
97
- /** Maximum retry attempts */
98
- maxRetries?: number;
99
-
100
- /** Retry delay in ms */
101
- retryDelay?: number;
102
-
103
- /** Retry backoff multiplier */
104
- retryBackoff?: number;
105
-
106
- /** Step timeout in ms */
107
- timeout?: number;
108
-
109
- /**
110
- * Expression to evaluate for skipping (simple field reference).
111
- * If the referenced field is truthy, the step is skipped.
112
- * Example: 'input.skipValidation' or 'results.load.alreadyExists'
113
- */
114
- skipCondition?: string;
115
- }
116
-
117
- /**
118
- * A recipe is a reusable workflow configuration template.
119
- * Recipes define the steps to execute and conditions for selection.
120
- */
121
- export interface Recipe {
122
- /** Unique recipe identifier (e.g., 'summarize.comprehensive') */
123
- id: string;
124
-
125
- /** Human-readable name */
126
- name: string;
127
-
128
- /** Description of what this recipe does */
129
- description?: string;
130
-
131
- /** Target workflow type */
132
- workflowKind: WorkflowKind;
133
-
134
- /** Variant name (e.g., 'default', 'fast', 'thorough') */
135
- variant: string;
136
-
137
- /** Ordered list of steps to execute */
138
- steps: RecipeStep[];
139
-
140
- /** Default parameters for this recipe */
141
- defaults?: RecipeDefaults;
142
-
143
- /** Conditions for auto-selecting this recipe */
144
- conditions?: RecipeCondition[];
145
-
146
- /**
147
- * Selection priority. Semantics differ by context:
148
- * - {@link MemoryRecipeRegistry.getDefault}: lower number = higher precedence
149
- * (used as fallback when no 'default' variant exists).
150
- * - {@link RuleBasedPlanner.selectRecipe}: condition-based scoring (0-100) is
151
- * the primary selection axis; this value is only a tiebreaker where higher
152
- * numeric value wins.
153
- */
154
- priority?: number;
155
-
156
- /** Tags for categorization and filtering */
157
- tags?: string[];
158
- }
159
-
160
- // ============================================================================
161
- // Plan Types
162
- // ============================================================================
163
-
164
- /**
165
- * Types of modifications that can be made to a plan.
166
- */
167
- export type PlanModificationType =
168
- | 'add_step' // Add a new step
169
- | 'remove_step' // Remove an existing step
170
- | 'modify_step' // Modify step configuration
171
- | 'reorder_steps' // Change step order
172
- | 'set_default'; // Override a default parameter
173
-
174
- /**
175
- * A modification to apply to a recipe when generating a plan.
176
- */
177
- export interface PlanModification {
178
- /** Type of modification */
179
- type: PlanModificationType;
180
-
181
- /** Target step key (for step modifications) */
182
- stepKey?: string;
183
-
184
- /** New value or configuration */
185
- value: unknown;
186
-
187
- /** Human-readable reason for this modification */
188
- reason: string;
189
- }
190
-
191
- /**
192
- * A resolved step in a plan, ready for execution.
193
- */
194
- export interface PlannedStep {
195
- /** Unique step identifier */
196
- key: string;
197
-
198
- /** Human-readable step name */
199
- name: string;
200
-
201
- /** Reference to the step handler */
202
- handlerRef: string;
203
-
204
- /** Resolved configuration for this step */
205
- config: Record<string, unknown>;
206
-
207
- /** Error handling strategy */
208
- onError?: StepErrorStrategy;
209
-
210
- /** Maximum retry attempts */
211
- maxRetries?: number;
212
-
213
- /** Retry delay in ms */
214
- retryDelay?: number;
215
-
216
- /** Retry backoff multiplier */
217
- retryBackoff?: number;
218
-
219
- /** Step timeout in ms */
220
- timeout?: number;
221
-
222
- /** Skip condition expression */
223
- skipCondition?: string;
224
- }
225
-
226
- /**
227
- * A planned child workflow to spawn during execution.
228
- */
229
- export interface ChildWorkflowPlan {
230
- /** Workflow type to spawn */
231
- kind: WorkflowKind;
232
-
233
- /** Input for the child workflow */
234
- input: Record<string, unknown>;
235
-
236
- /** Whether to wait for the child to complete */
237
- waitFor?: boolean;
238
-
239
- /** Step key after which to spawn this workflow */
240
- afterStep?: string;
241
-
242
- /** Optional metadata for the child workflow */
243
- metadata?: Record<string, unknown>;
244
- }
245
-
246
- /**
247
- * Resource requirements estimated for a plan.
248
- */
249
- export interface ResourceEstimate {
250
- /** Estimated API calls */
251
- apiCalls?: number;
252
-
253
- /** Estimated LLM tokens */
254
- tokens?: number;
255
-
256
- /** Estimated duration in ms */
257
- duration?: number;
258
-
259
- /** Estimated memory usage in bytes */
260
- memory?: number;
261
- }
262
-
263
- /**
264
- * A plan is the output of planning - a concrete execution strategy.
265
- */
266
- export interface Plan {
267
- /** Unique plan identifier */
268
- id: string;
269
-
270
- /** Recipe this plan is based on */
271
- recipeId: string;
272
-
273
- /** Recipe variant used */
274
- variant: string;
275
-
276
- /** Modifications applied to the base recipe */
277
- modifications: PlanModification[];
278
-
279
- /** Final step sequence after modifications */
280
- steps: PlannedStep[];
281
-
282
- /** Child workflows to spawn */
283
- childWorkflows?: ChildWorkflowPlan[];
284
-
285
- /** Resolved default parameters */
286
- defaults: RecipeDefaults;
287
-
288
- /** Human-readable reasoning for plan decisions */
289
- reasoning?: string;
290
-
291
- /** Estimated resource requirements */
292
- resourceEstimate?: ResourceEstimate;
293
-
294
- /** When this plan was generated */
295
- createdAt: Date;
296
- }
297
-
298
- // ============================================================================
299
- // Planning Context Types
300
- // ============================================================================
301
-
302
- /**
303
- * Priority modes for planning.
304
- */
305
- export type PlanningPriority = 'speed' | 'quality' | 'cost' | 'balanced';
306
-
307
- /**
308
- * Constraints that limit planning and execution.
309
- */
310
- export interface PlanningConstraints {
311
- /** Maximum allowed duration in ms */
312
- maxDuration?: number;
313
-
314
- /** Maximum API calls allowed */
315
- maxApiCalls?: number;
316
-
317
- /** Maximum LLM tokens allowed */
318
- maxTokens?: number;
319
-
320
- /** Optimization priority */
321
- priority?: PlanningPriority;
322
- }
323
-
324
- /**
325
- * User-provided hints to guide planning.
326
- */
327
- export interface PlanningHints {
328
- /** Preferred recipe variant */
329
- preferredVariant?: string;
330
-
331
- /** Specific recipe to use (bypasses selection) */
332
- forceRecipeId?: string;
333
-
334
- /** Steps to skip */
335
- skipSteps?: string[];
336
-
337
- /** Steps to include (even if normally skipped) */
338
- includeSteps?: string[];
339
-
340
- /** Focus areas (domain-specific) */
341
- focusAreas?: string[];
342
-
343
- /** Additional configuration to merge */
344
- additionalConfig?: Record<string, unknown>;
345
- }
346
-
347
- /**
348
- * Context provided to the planner for decision-making.
349
- */
350
- export interface PlanningContext {
351
- /** Parent workflow run ID (if spawned as child) */
352
- parentRunId?: string;
353
-
354
- /** Domain-specific metadata */
355
- metadata?: Record<string, unknown>;
356
-
357
- /** Resource constraints */
358
- constraints?: PlanningConstraints;
359
-
360
- /** User-provided hints */
361
- hints?: PlanningHints;
362
- }
363
-
364
- // ============================================================================
365
- // Planner Interface
366
- // ============================================================================
367
-
368
- /**
369
- * Result of recipe selection.
370
- */
371
- export interface RecipeSelectionResult {
372
- /** Selected recipe */
373
- recipe: Recipe;
374
-
375
- /** Score indicating confidence (0-100) */
376
- score: number;
377
-
378
- /** Why this recipe was selected */
379
- reason: string;
380
- }
381
-
382
- /**
383
- * Validation result for a plan.
384
- */
385
- export interface PlanValidationResult {
386
- /** Whether the plan is valid */
387
- valid: boolean;
388
-
389
- /** Validation errors (if any) */
390
- errors: string[];
391
-
392
- /** Validation warnings */
393
- warnings: string[];
394
- }
395
-
396
- /**
397
- * Planner interface for generating execution plans.
398
- */
399
- export interface Planner {
400
- /**
401
- * Select the best recipe for a workflow and input.
402
- */
403
- selectRecipe(
404
- workflowKind: WorkflowKind,
405
- input: Record<string, unknown>,
406
- context?: PlanningContext
407
- ): Promise<RecipeSelectionResult>;
408
-
409
- /**
410
- * Generate a plan from a recipe and input.
411
- */
412
- generatePlan(
413
- recipe: Recipe,
414
- input: Record<string, unknown>,
415
- context?: PlanningContext
416
- ): Promise<Plan>;
417
-
418
- /**
419
- * Combined operation: select recipe and generate plan.
420
- */
421
- plan(
422
- workflowKind: WorkflowKind,
423
- input: Record<string, unknown>,
424
- context?: PlanningContext
425
- ): Promise<Plan>;
426
-
427
- /**
428
- * Validate a plan before execution.
429
- */
430
- validatePlan(plan: Plan): PlanValidationResult;
431
-
432
- /**
433
- * Estimate resources required for a plan.
434
- */
435
- estimateResources(plan: Plan): ResourceEstimate;
436
- }
437
-
438
- // ============================================================================
439
- // Step Handler Registry Types
440
- // ============================================================================
441
-
442
- /**
443
- * A registered step handler function.
444
- */
445
- export interface RegisteredStepHandler<TInput = Record<string, unknown>> {
446
- /** Unique handler identifier */
447
- id: string;
448
-
449
- /** Human-readable description */
450
- description?: string;
451
-
452
- /** The handler function */
453
- handler: WorkflowStep<TInput>['handler'];
454
-
455
- /** Tags for categorization */
456
- tags?: string[];
457
- }
458
-
459
- /**
460
- * Registry for step handlers.
461
- * Allows recipes to reference handlers by ID.
462
- */
463
- export interface StepHandlerRegistry {
464
- /**
465
- * Register a step handler.
466
- */
467
- register<TInput = Record<string, unknown>>(
468
- handler: RegisteredStepHandler<TInput>
469
- ): void;
470
-
471
- /**
472
- * Get a handler by ID.
473
- */
474
- get(id: string): RegisteredStepHandler | undefined;
475
-
476
- /**
477
- * Check if a handler exists.
478
- */
479
- has(id: string): boolean;
480
-
481
- /**
482
- * List all registered handlers.
483
- */
484
- list(): RegisteredStepHandler[];
485
-
486
- /**
487
- * List handlers by tag.
488
- */
489
- listByTag(tag: string): RegisteredStepHandler[];
490
- }
491
-
492
- // ============================================================================
493
- // Recipe Registry Types
494
- // ============================================================================
495
-
496
- /**
497
- * Options for querying recipes.
498
- */
499
- export interface RecipeQueryOptions {
500
- /** Filter by workflow kind */
501
- workflowKind?: WorkflowKind;
502
-
503
- /** Filter by variant */
504
- variant?: string;
505
-
506
- /** Filter by tags (any match) */
507
- tags?: string[];
508
-
509
- /** Only include recipes matching conditions */
510
- matchConditions?: Record<string, unknown>;
511
- }
512
-
513
- /**
514
- * Registry for recipes.
515
- */
516
- export interface RecipeRegistry {
517
- /**
518
- * Register a recipe.
519
- */
520
- register(recipe: Recipe): void;
521
-
522
- /**
523
- * Register multiple recipes.
524
- */
525
- registerAll(recipes: Recipe[]): void;
526
-
527
- /**
528
- * Get a recipe by ID.
529
- */
530
- get(recipeId: string): Recipe | undefined;
531
-
532
- /**
533
- * Check if a recipe exists.
534
- */
535
- has(recipeId: string): boolean;
536
-
537
- /**
538
- * Get all recipes for a workflow kind.
539
- */
540
- getByKind(workflowKind: WorkflowKind): Recipe[];
541
-
542
- /**
543
- * Get a specific variant for a workflow kind.
544
- */
545
- getVariant(workflowKind: WorkflowKind, variant: string): Recipe | undefined;
546
-
547
- /**
548
- * Get the default recipe for a workflow kind.
549
- */
550
- getDefault(workflowKind: WorkflowKind): Recipe | undefined;
551
-
552
- /**
553
- * List all available variants for a workflow kind.
554
- */
555
- listVariants(workflowKind: WorkflowKind): string[];
556
-
557
- /**
558
- * Query recipes with filters.
559
- */
560
- query(options: RecipeQueryOptions): Recipe[];
561
-
562
- /**
563
- * List all registered recipes.
564
- */
565
- list(): Recipe[];
566
- }