openworkflow 0.3.0 → 0.4.1

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 (131) hide show
  1. package/README.md +54 -18
  2. package/dist/backend-sqlite/backend.d.ts +38 -0
  3. package/dist/backend-sqlite/backend.d.ts.map +1 -0
  4. package/dist/backend-sqlite/backend.js +628 -0
  5. package/dist/backend-sqlite/backend.js.map +1 -0
  6. package/dist/backend-sqlite/index.d.ts +2 -0
  7. package/dist/backend-sqlite/index.d.ts.map +1 -0
  8. package/dist/backend-sqlite/index.js +2 -0
  9. package/dist/backend-sqlite/index.js.map +1 -0
  10. package/dist/backend-sqlite/sqlite.d.ts +45 -0
  11. package/dist/backend-sqlite/sqlite.d.ts.map +1 -0
  12. package/dist/backend-sqlite/sqlite.js +229 -0
  13. package/dist/backend-sqlite/sqlite.js.map +1 -0
  14. package/dist/config/config.d.ts +102 -0
  15. package/dist/config/config.d.ts.map +1 -0
  16. package/dist/config/config.js +29 -0
  17. package/dist/config/config.js.map +1 -0
  18. package/dist/config/index.d.ts +3 -0
  19. package/dist/config/index.d.ts.map +1 -0
  20. package/dist/config/index.js +2 -0
  21. package/dist/config/index.js.map +1 -0
  22. package/dist/config.d.ts +28 -0
  23. package/dist/config.d.ts.map +1 -0
  24. package/dist/config.js +41 -0
  25. package/dist/config.js.map +1 -0
  26. package/dist/core/backend-test-suite.d.ts +22 -0
  27. package/dist/core/backend-test-suite.d.ts.map +1 -0
  28. package/dist/core/backend-test-suite.js +960 -0
  29. package/dist/core/backend-test-suite.js.map +1 -0
  30. package/dist/core/backend.d.ts +103 -0
  31. package/dist/core/backend.d.ts.map +1 -0
  32. package/dist/core/backend.js +2 -0
  33. package/dist/core/backend.js.map +1 -0
  34. package/dist/core/backend.testsuite.d.ts +21 -0
  35. package/dist/core/backend.testsuite.d.ts.map +1 -0
  36. package/dist/core/backend.testsuite.js +958 -0
  37. package/dist/core/backend.testsuite.js.map +1 -0
  38. package/dist/{duration.d.ts → core/duration.d.ts} +2 -1
  39. package/dist/core/duration.d.ts.map +1 -0
  40. package/dist/{duration.js → core/duration.js} +6 -5
  41. package/dist/core/duration.js.map +1 -0
  42. package/dist/core/duration.test.d.ts +2 -0
  43. package/dist/core/duration.test.d.ts.map +1 -0
  44. package/dist/core/duration.test.js +264 -0
  45. package/dist/core/duration.test.js.map +1 -0
  46. package/dist/core/json.d.ts +5 -0
  47. package/dist/core/json.d.ts.map +1 -0
  48. package/dist/core/json.js +2 -0
  49. package/dist/core/json.js.map +1 -0
  50. package/dist/core/result.d.ts +12 -0
  51. package/dist/core/result.d.ts.map +1 -0
  52. package/dist/core/result.js +7 -0
  53. package/dist/core/result.js.map +1 -0
  54. package/dist/core/result.test.d.ts +2 -0
  55. package/dist/core/result.test.d.ts.map +1 -0
  56. package/dist/core/result.test.js +11 -0
  57. package/dist/core/result.test.js.map +1 -0
  58. package/dist/core/retry.d.ts +16 -0
  59. package/dist/core/retry.d.ts.map +1 -0
  60. package/dist/{backend.js → core/retry.js} +1 -3
  61. package/dist/core/retry.js.map +1 -0
  62. package/dist/core/retry.test.d.ts +2 -0
  63. package/dist/core/retry.test.d.ts.map +1 -0
  64. package/dist/core/retry.test.js +36 -0
  65. package/dist/core/retry.test.js.map +1 -0
  66. package/dist/core/schema.d.ts +57 -0
  67. package/dist/core/schema.d.ts.map +1 -0
  68. package/dist/core/schema.js +2 -0
  69. package/dist/core/schema.js.map +1 -0
  70. package/dist/core/step.d.ts +120 -0
  71. package/dist/core/step.d.ts.map +1 -0
  72. package/dist/core/step.js +101 -0
  73. package/dist/core/step.js.map +1 -0
  74. package/dist/core/step.test.d.ts +2 -0
  75. package/dist/core/step.test.d.ts.map +1 -0
  76. package/dist/core/step.test.js +340 -0
  77. package/dist/core/step.test.js.map +1 -0
  78. package/dist/core/workflow.d.ts +108 -0
  79. package/dist/core/workflow.d.ts.map +1 -0
  80. package/dist/core/workflow.js +79 -0
  81. package/dist/core/workflow.js.map +1 -0
  82. package/dist/core/workflow.test.d.ts +2 -0
  83. package/dist/core/workflow.test.d.ts.map +1 -0
  84. package/dist/core/workflow.test.js +216 -0
  85. package/dist/core/workflow.test.js.map +1 -0
  86. package/dist/execution/execution.d.ts +91 -0
  87. package/dist/execution/execution.d.ts.map +1 -0
  88. package/dist/execution/execution.js +188 -0
  89. package/dist/execution/execution.js.map +1 -0
  90. package/dist/execution/execution.test.d.ts +2 -0
  91. package/dist/execution/execution.test.d.ts.map +1 -0
  92. package/dist/execution/execution.test.js +382 -0
  93. package/dist/execution/execution.test.js.map +1 -0
  94. package/dist/global.d.ts +62 -0
  95. package/dist/global.d.ts.map +1 -0
  96. package/dist/global.js +78 -0
  97. package/dist/global.js.map +1 -0
  98. package/dist/index.d.ts +9 -5
  99. package/dist/index.d.ts.map +1 -1
  100. package/dist/index.js +4 -3
  101. package/dist/index.js.map +1 -1
  102. package/dist/sdk/sdk.d.ts +182 -0
  103. package/dist/sdk/sdk.d.ts.map +1 -0
  104. package/dist/sdk/sdk.js +208 -0
  105. package/dist/sdk/sdk.js.map +1 -0
  106. package/dist/sdk/sdk.test.d.ts +2 -0
  107. package/dist/sdk/sdk.test.d.ts.map +1 -0
  108. package/dist/sdk/sdk.test.js +195 -0
  109. package/dist/sdk/sdk.test.js.map +1 -0
  110. package/dist/tsconfig.tsbuildinfo +1 -1
  111. package/dist/{worker.d.ts → worker/worker.d.ts} +4 -4
  112. package/dist/worker/worker.d.ts.map +1 -0
  113. package/dist/worker/worker.js +208 -0
  114. package/dist/worker/worker.js.map +1 -0
  115. package/dist/worker/worker.test.d.ts +2 -0
  116. package/dist/worker/worker.test.d.ts.map +1 -0
  117. package/dist/worker/worker.test.js +786 -0
  118. package/dist/worker/worker.test.js.map +1 -0
  119. package/package.json +9 -3
  120. package/dist/backend.d.ts +0 -159
  121. package/dist/backend.d.ts.map +0 -1
  122. package/dist/backend.js.map +0 -1
  123. package/dist/client.d.ts +0 -141
  124. package/dist/client.d.ts.map +0 -1
  125. package/dist/client.js +0 -135
  126. package/dist/client.js.map +0 -1
  127. package/dist/duration.d.ts.map +0 -1
  128. package/dist/duration.js.map +0 -1
  129. package/dist/worker.d.ts.map +0 -1
  130. package/dist/worker.js +0 -375
  131. package/dist/worker.js.map +0 -1
package/dist/worker.js DELETED
@@ -1,375 +0,0 @@
1
- import { parseDuration } from "./duration.js";
2
- import { randomUUID } from "node:crypto";
3
- const DEFAULT_LEASE_DURATION_MS = 30 * 1000; // 30s
4
- const DEFAULT_POLL_INTERVAL_MS = 100; // 100ms
5
- const DEFAULT_CONCURRENCY = 1;
6
- /**
7
- * Signal thrown when a workflow needs to sleep. Contains the time when the
8
- * workflow should resume.
9
- */
10
- class SleepSignal extends Error {
11
- resumeAt;
12
- constructor(resumeAt) {
13
- super("SleepSignal");
14
- this.name = "SleepSignal";
15
- this.resumeAt = resumeAt;
16
- }
17
- }
18
- /**
19
- * Runs workflows by polling the backend, dispatching runs across a concurrency
20
- * pool, and heartbeating leases.
21
- */
22
- export class Worker {
23
- backend;
24
- workerIds;
25
- registeredWorkflows = new Map();
26
- activeExecutions = new Set();
27
- running = false;
28
- loopPromise = null;
29
- constructor(options) {
30
- this.backend = options.backend;
31
- const concurrency = Math.max(DEFAULT_CONCURRENCY, options.concurrency ?? DEFAULT_CONCURRENCY);
32
- // generate worker IDs for every concurrency slot
33
- this.workerIds = Array.from({ length: concurrency }, () => randomUUID());
34
- // register workflows
35
- for (const workflow of options.workflows) {
36
- this.registeredWorkflows.set(workflow.name, workflow);
37
- }
38
- }
39
- /**
40
- * Start the worker. It will begin polling for and executing workflows.
41
- */
42
- async start() {
43
- if (this.running)
44
- return;
45
- this.running = true;
46
- this.loopPromise = this.runLoop();
47
- await Promise.resolve();
48
- }
49
- /**
50
- * Stop the worker gracefully. Waits for all active workflow runs to complete
51
- * before returning.
52
- */
53
- async stop() {
54
- this.running = false;
55
- // wait for the poll loop to stop
56
- if (this.loopPromise)
57
- await this.loopPromise;
58
- // wait for all active executions to finish
59
- while (this.activeExecutions.size > 0)
60
- await sleep(100);
61
- }
62
- /**
63
- * Processes one round of work claims and execution. Exposed for testing.
64
- * Returns the number of workflow runs claimed.
65
- */
66
- async tick() {
67
- const availableSlots = this.concurrency - this.activeExecutions.size;
68
- if (availableSlots <= 0)
69
- return 0;
70
- // claim work for each available slot
71
- const claims = Array.from({ length: availableSlots }, (_, i) => {
72
- const availableWorkerId = this.workerIds[i % this.workerIds.length];
73
- return availableWorkerId
74
- ? this.claimAndProcessWorkflowRunInBackground(availableWorkerId)
75
- : Promise.resolve(null);
76
- });
77
- const claimed = await Promise.all(claims);
78
- return claimed.filter((run) => run !== null).length;
79
- }
80
- /**
81
- * Get the configured concurrency limit.
82
- */
83
- get concurrency() {
84
- return this.workerIds.length;
85
- }
86
- /*
87
- * Main run loop that continuously ticks while the worker is running.
88
- * Only sleeps when no work was claimed to avoid busy-waiting.
89
- */
90
- async runLoop() {
91
- while (this.running) {
92
- try {
93
- const claimedCount = await this.tick();
94
- // only sleep if we didn't claim any work
95
- if (claimedCount === 0) {
96
- await sleep(DEFAULT_POLL_INTERVAL_MS);
97
- }
98
- }
99
- catch (error) {
100
- console.error("Worker tick failed:", error);
101
- await sleep(DEFAULT_POLL_INTERVAL_MS);
102
- }
103
- }
104
- }
105
- /*
106
- * Cclaim and process a workflow run for the given worker ID. Do not await the
107
- * processing here to avoid blocking the caller.
108
- * Returns the claimed workflow run, or null if none was available.
109
- */
110
- async claimAndProcessWorkflowRunInBackground(workerId) {
111
- // claim workflow run
112
- const workflowRun = await this.backend.claimWorkflowRun({
113
- workerId,
114
- leaseDurationMs: DEFAULT_LEASE_DURATION_MS,
115
- });
116
- if (!workflowRun)
117
- return null;
118
- // find workflow definition
119
- const workflow = this.registeredWorkflows.get(workflowRun.workflowName);
120
- if (!workflow) {
121
- await this.backend.markWorkflowRunFailed({
122
- workflowRunId: workflowRun.id,
123
- workerId,
124
- error: {
125
- message: `Workflow "${workflowRun.workflowName}" is not registered`,
126
- },
127
- });
128
- return null;
129
- }
130
- // create execution and start processing *async* w/o blocking
131
- const execution = new WorkflowExecution({
132
- backend: this.backend,
133
- workflowRun,
134
- workerId,
135
- });
136
- this.activeExecutions.add(execution);
137
- this.processExecutionInBackground(execution, workflow)
138
- .catch(() => {
139
- // errors are already handled in processExecution
140
- })
141
- .finally(() => {
142
- execution.stopHeartbeat();
143
- this.activeExecutions.delete(execution);
144
- });
145
- return workflowRun;
146
- }
147
- /**
148
- * Process a workflow execution, handling heartbeats, step execution, and
149
- * marking success or failure.
150
- */
151
- async processExecutionInBackground(execution, workflow) {
152
- // start heartbeating
153
- execution.startHeartbeat();
154
- try {
155
- // load step history
156
- const attempts = await this.backend.listStepAttempts({
157
- workflowRunId: execution.workflowRun.id,
158
- });
159
- // mark any sleep steps as succeeded if their sleep duration has elapsed,
160
- // or rethrow SleepSignal if still sleeping
161
- for (let i = 0; i < attempts.length; i++) {
162
- const attempt = attempts[i];
163
- if (!attempt)
164
- continue;
165
- if (attempt.status === "running" &&
166
- attempt.kind === "sleep" &&
167
- attempt.context?.kind === "sleep") {
168
- const now = Date.now();
169
- const resumeAt = new Date(attempt.context.resumeAt);
170
- const resumeAtMs = resumeAt.getTime();
171
- if (now < resumeAtMs) {
172
- // sleep duration HAS NOT elapsed yet, throw signal to put workflow
173
- // back to sleep
174
- throw new SleepSignal(resumeAt);
175
- }
176
- // sleep duration HAS elapsed, mark the step as succeeded and continue
177
- const succeeded = await this.backend.markStepAttemptSucceeded({
178
- workflowRunId: execution.workflowRun.id,
179
- stepAttemptId: attempt.id,
180
- workerId: execution.workerId,
181
- output: null,
182
- });
183
- // update cache w/ succeeded attempt
184
- attempts[i] = succeeded;
185
- }
186
- }
187
- // create step executor
188
- const executor = new StepExecutor({
189
- backend: this.backend,
190
- workflowRunId: execution.workflowRun.id,
191
- workerId: execution.workerId,
192
- attempts,
193
- });
194
- // execute workflow
195
- const output = await workflow.fn({
196
- input: execution.workflowRun.input,
197
- step: executor,
198
- version: execution.workflowRun.version,
199
- });
200
- // mark success
201
- await this.backend.markWorkflowRunSucceeded({
202
- workflowRunId: execution.workflowRun.id,
203
- workerId: execution.workerId,
204
- output: (output ?? null),
205
- });
206
- }
207
- catch (error) {
208
- // handle sleep signal by setting workflow to sleeping status
209
- if (error instanceof SleepSignal) {
210
- await this.backend.sleepWorkflowRun({
211
- workflowRunId: execution.workflowRun.id,
212
- workerId: execution.workerId,
213
- availableAt: error.resumeAt,
214
- });
215
- return;
216
- }
217
- // mark failure
218
- await this.backend.markWorkflowRunFailed({
219
- workflowRunId: execution.workflowRun.id,
220
- workerId: execution.workerId,
221
- error: serializeError(error),
222
- });
223
- }
224
- }
225
- }
226
- /**
227
- * Tracks a claimed workflow run and maintains its heartbeat lease for the
228
- * worker.
229
- */
230
- class WorkflowExecution {
231
- backend;
232
- workflowRun;
233
- workerId;
234
- heartbeatTimer = null;
235
- constructor(options) {
236
- this.backend = options.backend;
237
- this.workflowRun = options.workflowRun;
238
- this.workerId = options.workerId;
239
- }
240
- /**
241
- * Start the heartbeat loop for this execution, heartbeating at half the lease
242
- * duration.
243
- */
244
- startHeartbeat() {
245
- const leaseDurationMs = DEFAULT_LEASE_DURATION_MS;
246
- const heartbeatIntervalMs = leaseDurationMs / 2;
247
- this.heartbeatTimer = setInterval(() => {
248
- this.backend
249
- .heartbeatWorkflowRun({
250
- workflowRunId: this.workflowRun.id,
251
- workerId: this.workerId,
252
- leaseDurationMs,
253
- })
254
- .catch((error) => {
255
- console.error("Heartbeat failed:", error);
256
- });
257
- }, heartbeatIntervalMs);
258
- }
259
- /**
260
- * Stop the heartbeat loop.
261
- */
262
- stopHeartbeat() {
263
- if (this.heartbeatTimer) {
264
- clearInterval(this.heartbeatTimer);
265
- this.heartbeatTimer = null;
266
- }
267
- }
268
- }
269
- /**
270
- * Replays prior step attempts and persists new ones while memoizing
271
- * deterministic step outputs.
272
- */
273
- class StepExecutor {
274
- backend;
275
- workflowRunId;
276
- workerId;
277
- successfulAttemptsByName = new Map();
278
- constructor(options) {
279
- this.backend = options.backend;
280
- this.workflowRunId = options.workflowRunId;
281
- this.workerId = options.workerId;
282
- // load successful attempts into history
283
- for (const attempt of options.attempts) {
284
- if (attempt.status === "succeeded") {
285
- this.successfulAttemptsByName.set(attempt.stepName, attempt);
286
- }
287
- }
288
- }
289
- async run(config, fn) {
290
- const { name } = config;
291
- // return cached result if available
292
- const existingAttempt = this.successfulAttemptsByName.get(name);
293
- if (existingAttempt) {
294
- return existingAttempt.output;
295
- }
296
- // not in cache, create new step attempt
297
- const attempt = await this.backend.createStepAttempt({
298
- workflowRunId: this.workflowRunId,
299
- workerId: this.workerId,
300
- stepName: name,
301
- kind: "function",
302
- config: {},
303
- context: null,
304
- });
305
- try {
306
- // execute step function
307
- const result = await fn();
308
- // convert undefined to null for JSON compatibility
309
- const output = (result ?? null);
310
- // mark success
311
- const savedAttempt = await this.backend.markStepAttemptSucceeded({
312
- workflowRunId: this.workflowRunId,
313
- stepAttemptId: attempt.id,
314
- workerId: this.workerId,
315
- output,
316
- });
317
- // cache result
318
- this.successfulAttemptsByName.set(name, savedAttempt);
319
- return savedAttempt.output;
320
- }
321
- catch (error) {
322
- // mark failure
323
- await this.backend.markStepAttemptFailed({
324
- workflowRunId: this.workflowRunId,
325
- stepAttemptId: attempt.id,
326
- workerId: this.workerId,
327
- error: serializeError(error),
328
- });
329
- throw error;
330
- }
331
- }
332
- async sleep(name, duration) {
333
- // return cached result if this sleep already completed
334
- const existingAttempt = this.successfulAttemptsByName.get(name);
335
- if (existingAttempt)
336
- return;
337
- // create new step attempt for the sleep
338
- const durationMs = parseDuration(duration);
339
- const resumeAt = new Date(Date.now() + durationMs);
340
- await this.backend.createStepAttempt({
341
- workflowRunId: this.workflowRunId,
342
- workerId: this.workerId,
343
- stepName: name,
344
- kind: "sleep",
345
- config: {},
346
- context: {
347
- kind: "sleep",
348
- resumeAt: resumeAt.toISOString(),
349
- },
350
- });
351
- // throw sleep signal to trigger postponement
352
- // we do not mark the step as succeeded here; it will be updated
353
- // when the workflow resumes
354
- throw new SleepSignal(resumeAt);
355
- }
356
- }
357
- /**
358
- * Serialize an error to a JSON-compatible format.
359
- */
360
- function serializeError(error) {
361
- if (error instanceof Error) {
362
- return {
363
- name: error.name,
364
- message: error.message,
365
- stack: error.stack ?? null,
366
- };
367
- }
368
- return {
369
- message: String(error),
370
- };
371
- }
372
- function sleep(ms) {
373
- return new Promise((resolve) => setTimeout(resolve, ms));
374
- }
375
- //# sourceMappingURL=worker.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"worker.js","sourceRoot":"","sources":["../worker.ts"],"names":[],"mappings":"AAYA,OAAO,EAAkB,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,MAAM,yBAAyB,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,MAAM;AACnD,MAAM,wBAAwB,GAAG,GAAG,CAAC,CAAC,QAAQ;AAC9C,MAAM,mBAAmB,GAAG,CAAC,CAAC;AAE9B;;;GAGG;AACH,MAAM,WAAY,SAAQ,KAAK;IACpB,QAAQ,CAAO;IAExB,YAAY,QAAc;QACxB,KAAK,CAAC,aAAa,CAAC,CAAC;QACrB,IAAI,CAAC,IAAI,GAAG,aAAa,CAAC;QAC1B,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;CACF;AAYD;;;GAGG;AACH,MAAM,OAAO,MAAM;IACA,OAAO,CAAU;IACjB,SAAS,CAAW;IACpB,mBAAmB,GAAG,IAAI,GAAG,EAG3C,CAAC;IACa,gBAAgB,GAAG,IAAI,GAAG,EAAqB,CAAC;IACzD,OAAO,GAAG,KAAK,CAAC;IAChB,WAAW,GAAyB,IAAI,CAAC;IAEjD,YAAY,OAAsB;QAChC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;QAE/B,MAAM,WAAW,GAAG,IAAI,CAAC,GAAG,CAC1B,mBAAmB,EACnB,OAAO,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