ai-workflows 2.1.3 → 2.3.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/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +8 -1
- package/README.md +2 -0
- package/dist/barrier.d.ts +6 -0
- package/dist/barrier.d.ts.map +1 -1
- package/dist/barrier.js +45 -7
- package/dist/barrier.js.map +1 -1
- package/dist/cascade-context.d.ts.map +1 -1
- package/dist/cascade-context.js +25 -25
- package/dist/cascade-context.js.map +1 -1
- package/dist/cascade-executor.d.ts.map +1 -1
- package/dist/cascade-executor.js +1 -1
- package/dist/cascade-executor.js.map +1 -1
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +23 -7
- package/dist/context.js.map +1 -1
- package/dist/cron-parser.d.ts +65 -0
- package/dist/cron-parser.d.ts.map +1 -0
- package/dist/cron-parser.js +294 -0
- package/dist/cron-parser.js.map +1 -0
- package/dist/cron-scheduler.d.ts +117 -0
- package/dist/cron-scheduler.d.ts.map +1 -0
- package/dist/cron-scheduler.js +176 -0
- package/dist/cron-scheduler.js.map +1 -0
- package/dist/database-context.d.ts +184 -0
- package/dist/database-context.d.ts.map +1 -0
- package/dist/database-context.js +428 -0
- package/dist/database-context.js.map +1 -0
- package/dist/digital-objects-adapter.d.ts +159 -0
- package/dist/digital-objects-adapter.d.ts.map +1 -0
- package/dist/digital-objects-adapter.js +229 -0
- package/dist/digital-objects-adapter.js.map +1 -0
- package/dist/durable-execution-cloudflare.d.ts +427 -0
- package/dist/durable-execution-cloudflare.d.ts.map +1 -0
- package/dist/durable-execution-cloudflare.js +510 -0
- package/dist/durable-execution-cloudflare.js.map +1 -0
- package/dist/durable-execution.d.ts +482 -0
- package/dist/durable-execution.d.ts.map +1 -0
- package/dist/durable-execution.js +594 -0
- package/dist/durable-execution.js.map +1 -0
- package/dist/durable-workflow.d.ts +176 -0
- package/dist/durable-workflow.d.ts.map +1 -0
- package/dist/durable-workflow.js +552 -0
- package/dist/durable-workflow.js.map +1 -0
- package/dist/graph/topological-sort.d.ts.map +1 -1
- package/dist/graph/topological-sort.js +5 -5
- package/dist/graph/topological-sort.js.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -1
- package/dist/logger.d.ts +101 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +115 -0
- package/dist/logger.js.map +1 -0
- package/dist/on.d.ts.map +1 -1
- package/dist/on.js +3 -3
- package/dist/on.js.map +1 -1
- package/dist/runtime.d.ts +169 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +275 -0
- package/dist/runtime.js.map +1 -0
- package/dist/send.d.ts.map +1 -1
- package/dist/send.js +4 -3
- package/dist/send.js.map +1 -1
- package/dist/telemetry.d.ts +150 -0
- package/dist/telemetry.d.ts.map +1 -0
- package/dist/telemetry.js +388 -0
- package/dist/telemetry.js.map +1 -0
- package/dist/timer-registry.d.ts +25 -0
- package/dist/timer-registry.d.ts.map +1 -1
- package/dist/timer-registry.js +42 -8
- package/dist/timer-registry.js.map +1 -1
- package/dist/types.d.ts +17 -6
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -1
- package/dist/types.js.map +1 -1
- package/dist/worker/durable-step.d.ts +481 -0
- package/dist/worker/durable-step.d.ts.map +1 -0
- package/dist/worker/durable-step.js +606 -0
- package/dist/worker/durable-step.js.map +1 -0
- package/dist/worker/index.d.ts +106 -0
- package/dist/worker/index.d.ts.map +1 -0
- package/dist/worker/index.js +124 -0
- package/dist/worker/index.js.map +1 -0
- package/dist/worker/state-adapter.d.ts +230 -0
- package/dist/worker/state-adapter.d.ts.map +1 -0
- package/dist/worker/state-adapter.js +409 -0
- package/dist/worker/state-adapter.js.map +1 -0
- package/dist/worker/topological-executor.d.ts +282 -0
- package/dist/worker/topological-executor.d.ts.map +1 -0
- package/dist/worker/topological-executor.js +396 -0
- package/dist/worker/topological-executor.js.map +1 -0
- package/dist/worker/workflow-builder.d.ts +286 -0
- package/dist/worker/workflow-builder.d.ts.map +1 -0
- package/dist/worker/workflow-builder.js +565 -0
- package/dist/worker/workflow-builder.js.map +1 -0
- package/dist/worker.d.ts +800 -0
- package/dist/worker.d.ts.map +1 -0
- package/dist/worker.js +2428 -0
- package/dist/worker.js.map +1 -0
- package/dist/workflow-builder.d.ts +287 -0
- package/dist/workflow-builder.d.ts.map +1 -0
- package/dist/workflow-builder.js +762 -0
- package/dist/workflow-builder.js.map +1 -0
- package/dist/workflow.d.ts +14 -30
- package/dist/workflow.d.ts.map +1 -1
- package/dist/workflow.js +132 -292
- package/dist/workflow.js.map +1 -1
- package/examples/01-ecommerce-order-pipeline.ts +358 -0
- package/examples/02-content-moderation-cascade.ts +454 -0
- package/examples/03-scheduled-reporting-dependencies.ts +479 -0
- package/examples/04-database-persistence.ts +518 -0
- package/examples/README.md +173 -0
- package/package.json +30 -13
- package/src/__tests__/digital-objects-adapter.test.ts +274 -0
- package/src/__tests__/durable-workflow.test.ts +297 -0
- package/src/barrier.ts +48 -7
- package/src/cascade-context.ts +36 -29
- package/src/cascade-executor.ts +3 -2
- package/src/context.ts +41 -12
- package/src/cron-parser.ts +347 -0
- package/src/cron-scheduler.ts +239 -0
- package/src/database-context.ts +658 -0
- package/src/digital-objects-adapter.ts +351 -0
- package/src/durable-execution-cloudflare.ts +855 -0
- package/src/durable-execution.ts +1042 -0
- package/src/durable-workflow.ts +717 -0
- package/src/graph/topological-sort.ts +6 -8
- package/src/index.ts +69 -0
- package/src/logger.ts +148 -0
- package/src/on.ts +8 -9
- package/src/runtime.ts +436 -0
- package/src/send.ts +4 -5
- package/src/telemetry.ts +577 -0
- package/src/timer-registry.ts +44 -10
- package/src/types.ts +32 -17
- package/src/worker/durable-step.ts +976 -0
- package/src/worker/index.ts +216 -0
- package/src/worker/state-adapter.ts +589 -0
- package/src/worker/topological-executor.ts +625 -0
- package/src/worker/workflow-builder.ts +871 -0
- package/src/worker.ts +2906 -0
- package/src/workflow-builder.ts +1068 -0
- package/src/workflow.ts +188 -351
- package/test/barrier-join.test.ts +32 -24
- package/test/cascade-executor.test.ts +9 -16
- package/test/cron-parser.test.ts +314 -0
- package/test/cron-scheduler.test.ts +291 -0
- package/test/database-context.test.ts +770 -0
- package/test/db-provider-adapter.test.ts +862 -0
- package/test/durable-execution-cloudflare.test.ts +606 -0
- package/test/durable-execution-in-process.test.ts +286 -0
- package/test/durable-execution.test.ts +247 -0
- package/test/e2e/workflow-scenarios.e2e.test.ts +1039 -0
- package/test/integration.test.ts +442 -0
- package/test/rpc-surface.test.ts +946 -0
- package/test/runtime.test.ts +262 -0
- package/test/schedule-timer-cleanup.test.ts +30 -21
- package/test/send-race-conditions.test.ts +30 -40
- package/test/worker/durable-cascade.test.ts +1117 -0
- package/test/worker/durable-step.test.ts +723 -0
- package/test/worker/topological-executor.test.ts +1240 -0
- package/test/worker/workflow-builder.test.ts +1067 -0
- package/test/worker.test.ts +608 -0
- package/test/workflow-builder.test.ts +1670 -0
- package/test/workflow-cron.test.ts +256 -0
- package/test/workflow-state-adapter.test.ts +923 -0
- package/test/workflow.test.ts +25 -22
- package/tsconfig.json +3 -1
- package/vitest.config.ts +38 -1
- package/vitest.workers.config.ts +44 -0
- package/wrangler.jsonc +22 -0
- package/.turbo/turbo-test.log +0 -169
- package/LICENSE +0 -21
- package/src/context.js +0 -83
- package/src/every.js +0 -267
- package/src/index.js +0 -71
- package/src/on.js +0 -79
- package/src/send.js +0 -111
- package/src/types.js +0 -4
- package/src/workflow.js +0 -455
- package/test/context.test.js +0 -116
- package/test/every.test.js +0 -282
- package/test/on.test.js +0 -80
- package/test/send.test.js +0 -89
- package/test/workflow.test.js +0 -224
- package/vitest.config.js +0 -7
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Worker module exports for ai-workflows
|
|
3
|
+
*
|
|
4
|
+
* This module provides Cloudflare Workers-specific functionality:
|
|
5
|
+
*
|
|
6
|
+
* - **DurableStep**: Wrapper for Cloudflare Workflows step semantics with
|
|
7
|
+
* durable execution, retries, sleep, and step metadata
|
|
8
|
+
*
|
|
9
|
+
* - **StepContext**: Context provided to step functions for additional
|
|
10
|
+
* operations like nested durable calls and sleep
|
|
11
|
+
*
|
|
12
|
+
* - **WorkflowBuilder**: Declarative DSL for building workflows with
|
|
13
|
+
* step definitions, dependencies, triggers, and schedules
|
|
14
|
+
*
|
|
15
|
+
* - **WorkflowService**: WorkerEntrypoint for RPC access to workflow
|
|
16
|
+
* functionality via service bindings
|
|
17
|
+
*
|
|
18
|
+
* - **WorkflowServiceCore**: Core RPC-enabled service for workflow
|
|
19
|
+
* creation, lifecycle, event emission, and state persistence
|
|
20
|
+
*
|
|
21
|
+
* - **WorkflowStateAdapter**: Persistent storage for workflow state using
|
|
22
|
+
* ai-database, with optimistic locking, checkpoints, and snapshots
|
|
23
|
+
*
|
|
24
|
+
* - **TopologicalExecutor**: Parallel step execution based on dependency graph.
|
|
25
|
+
* Executes steps in topological order, running independent steps concurrently.
|
|
26
|
+
*
|
|
27
|
+
* - **DurableGraph**: Higher-level API for building and executing workflow
|
|
28
|
+
* step graphs with durable semantics.
|
|
29
|
+
*
|
|
30
|
+
* - **Graph Utilities**: Re-exports from main package including topologicalSort,
|
|
31
|
+
* getExecutionLevels, DependencyGraph, and related types for convenience.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* import {
|
|
36
|
+
* DurableStep,
|
|
37
|
+
* WorkflowBuilder,
|
|
38
|
+
* WorkflowService,
|
|
39
|
+
* WorkflowServiceCore,
|
|
40
|
+
* WorkflowStateAdapter
|
|
41
|
+
* } from 'ai-workflows/worker'
|
|
42
|
+
*
|
|
43
|
+
* // Create a durable step
|
|
44
|
+
* const fetchData = new DurableStep('fetch-data', async (input: { url: string }) => {
|
|
45
|
+
* const response = await fetch(input.url)
|
|
46
|
+
* return response.json()
|
|
47
|
+
* })
|
|
48
|
+
*
|
|
49
|
+
* // Build a workflow
|
|
50
|
+
* const workflow = WorkflowBuilder.create('order-process')
|
|
51
|
+
* .step('validate', validateOrder)
|
|
52
|
+
* .step('charge', chargePayment).dependsOn('validate')
|
|
53
|
+
* .on('Order.placed').do('validate')
|
|
54
|
+
* .build()
|
|
55
|
+
*
|
|
56
|
+
* // Export WorkflowService as your worker entrypoint
|
|
57
|
+
* export { WorkflowService }
|
|
58
|
+
* ```
|
|
59
|
+
*
|
|
60
|
+
* @example State Persistence with WorkflowServiceCore
|
|
61
|
+
* ```typescript
|
|
62
|
+
* import { DB } from 'ai-database'
|
|
63
|
+
* import { WorkflowServiceCore } from 'ai-workflows/worker'
|
|
64
|
+
*
|
|
65
|
+
* // Create database and service with persistence
|
|
66
|
+
* const { db } = DB({ WorkflowState: { status: 'string' } })
|
|
67
|
+
* const service = new WorkflowServiceCore(db)
|
|
68
|
+
*
|
|
69
|
+
* // Create workflow and persist state
|
|
70
|
+
* const workflow = service.create('order-processor')
|
|
71
|
+
* await service.persistState(workflow.id, {
|
|
72
|
+
* workflowId: workflow.id,
|
|
73
|
+
* status: 'running',
|
|
74
|
+
* currentStep: 'validate-order',
|
|
75
|
+
* context: { orderId: 'order-123' }
|
|
76
|
+
* })
|
|
77
|
+
*
|
|
78
|
+
* // Save step checkpoint
|
|
79
|
+
* await service.saveCheckpoint(workflow.id, 'validate-order', {
|
|
80
|
+
* stepId: 'validate-order',
|
|
81
|
+
* status: 'completed',
|
|
82
|
+
* result: { valid: true },
|
|
83
|
+
* attempt: 1
|
|
84
|
+
* })
|
|
85
|
+
*
|
|
86
|
+
* // Query workflows by status
|
|
87
|
+
* const runningWorkflows = await service.queryByStatus('running')
|
|
88
|
+
*
|
|
89
|
+
* // Create snapshot before risky operation
|
|
90
|
+
* const snapshotId = await service.createSnapshot(workflow.id, 'before-payment')
|
|
91
|
+
*
|
|
92
|
+
* // Restore if something goes wrong
|
|
93
|
+
* await service.restoreSnapshot(workflow.id, snapshotId)
|
|
94
|
+
* ```
|
|
95
|
+
*
|
|
96
|
+
* @packageDocumentation
|
|
97
|
+
*/
|
|
98
|
+
|
|
99
|
+
// =============================================================================
|
|
100
|
+
// DurableStep - Durable function execution wrapper
|
|
101
|
+
// =============================================================================
|
|
102
|
+
|
|
103
|
+
export {
|
|
104
|
+
DurableStep,
|
|
105
|
+
StepContext,
|
|
106
|
+
type StepConfig,
|
|
107
|
+
type StepMetadata,
|
|
108
|
+
type RetryConfig,
|
|
109
|
+
type WorkflowStep,
|
|
110
|
+
type StepFunction,
|
|
111
|
+
} from './durable-step.js'
|
|
112
|
+
|
|
113
|
+
// =============================================================================
|
|
114
|
+
// WorkflowBuilder - Declarative workflow definition DSL
|
|
115
|
+
// =============================================================================
|
|
116
|
+
|
|
117
|
+
export {
|
|
118
|
+
WorkflowBuilder,
|
|
119
|
+
type WorkflowBuilderConfig,
|
|
120
|
+
type StepDefinition,
|
|
121
|
+
type StepChain,
|
|
122
|
+
type TriggerConfig,
|
|
123
|
+
type ScheduleConfig,
|
|
124
|
+
type BuiltWorkflow,
|
|
125
|
+
type ExecutionContext,
|
|
126
|
+
type EventTriggerChain,
|
|
127
|
+
type ScheduleTriggerChain,
|
|
128
|
+
type NumericScheduleChain,
|
|
129
|
+
type DependencyOptions,
|
|
130
|
+
} from './workflow-builder.js'
|
|
131
|
+
|
|
132
|
+
// =============================================================================
|
|
133
|
+
// WorkflowService - RPC-enabled workflow service
|
|
134
|
+
// =============================================================================
|
|
135
|
+
|
|
136
|
+
// Re-export from parent worker.ts for complete worker functionality
|
|
137
|
+
export {
|
|
138
|
+
WorkflowService,
|
|
139
|
+
WorkflowServiceCore,
|
|
140
|
+
WorkflowWorker,
|
|
141
|
+
TestWorkflow,
|
|
142
|
+
type Env,
|
|
143
|
+
type WorkflowInstanceInfo,
|
|
144
|
+
} from '../worker.js'
|
|
145
|
+
|
|
146
|
+
// =============================================================================
|
|
147
|
+
// WorkflowStateAdapter - Persistent workflow state storage
|
|
148
|
+
// =============================================================================
|
|
149
|
+
|
|
150
|
+
export {
|
|
151
|
+
WorkflowStateAdapter,
|
|
152
|
+
type PersistedWorkflowState,
|
|
153
|
+
type StepCheckpoint,
|
|
154
|
+
type WorkflowHistoryEntry as StateHistoryEntry,
|
|
155
|
+
type SnapshotInfo,
|
|
156
|
+
type DatabaseConnection,
|
|
157
|
+
} from './state-adapter.js'
|
|
158
|
+
|
|
159
|
+
// =============================================================================
|
|
160
|
+
// TopologicalExecutor & DurableGraph - Parallel step execution
|
|
161
|
+
// =============================================================================
|
|
162
|
+
|
|
163
|
+
export {
|
|
164
|
+
TopologicalExecutor,
|
|
165
|
+
DurableGraph,
|
|
166
|
+
createExecutor,
|
|
167
|
+
createGraph,
|
|
168
|
+
type StepExecutor,
|
|
169
|
+
type StepDefinition as GraphStepDefinition,
|
|
170
|
+
type ExecutionContext as GraphExecutionContext,
|
|
171
|
+
type ProgressCallback,
|
|
172
|
+
type ExecutionResult,
|
|
173
|
+
type ExecutorConfig,
|
|
174
|
+
} from './topological-executor.js'
|
|
175
|
+
|
|
176
|
+
// =============================================================================
|
|
177
|
+
// Graph Utilities - Re-export from main package for convenience
|
|
178
|
+
// =============================================================================
|
|
179
|
+
|
|
180
|
+
export {
|
|
181
|
+
topologicalSort,
|
|
182
|
+
topologicalSortKahn,
|
|
183
|
+
topologicalSortDFS,
|
|
184
|
+
getExecutionLevels,
|
|
185
|
+
CycleDetectedError,
|
|
186
|
+
MissingNodeError,
|
|
187
|
+
type SortableNode,
|
|
188
|
+
type ExecutionLevel,
|
|
189
|
+
type TopologicalSortOptions,
|
|
190
|
+
type TopologicalSortResult,
|
|
191
|
+
} from '../graph/topological-sort.js'
|
|
192
|
+
|
|
193
|
+
export {
|
|
194
|
+
DependencyGraph,
|
|
195
|
+
CircularDependencyError,
|
|
196
|
+
MissingDependencyError,
|
|
197
|
+
type GraphNode,
|
|
198
|
+
type ParallelGroup,
|
|
199
|
+
type GraphJSON,
|
|
200
|
+
type DependencyConfig,
|
|
201
|
+
type DependencyType,
|
|
202
|
+
} from '../dependency-graph.js'
|
|
203
|
+
|
|
204
|
+
// =============================================================================
|
|
205
|
+
// Types - Re-export commonly needed types from main package
|
|
206
|
+
// =============================================================================
|
|
207
|
+
|
|
208
|
+
export type {
|
|
209
|
+
WorkflowContext,
|
|
210
|
+
WorkflowState,
|
|
211
|
+
WorkflowHistoryEntry,
|
|
212
|
+
EventHandler,
|
|
213
|
+
ScheduleHandler,
|
|
214
|
+
ScheduleInterval,
|
|
215
|
+
ParsedEvent,
|
|
216
|
+
} from '../types.js'
|