ai-workflows 2.0.2 → 2.1.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.
Files changed (98) hide show
  1. package/.turbo/turbo-build.log +4 -5
  2. package/.turbo/turbo-test.log +169 -0
  3. package/CHANGELOG.md +29 -0
  4. package/LICENSE +21 -0
  5. package/README.md +303 -184
  6. package/dist/barrier.d.ts +153 -0
  7. package/dist/barrier.d.ts.map +1 -0
  8. package/dist/barrier.js +339 -0
  9. package/dist/barrier.js.map +1 -0
  10. package/dist/cascade-context.d.ts +149 -0
  11. package/dist/cascade-context.d.ts.map +1 -0
  12. package/dist/cascade-context.js +324 -0
  13. package/dist/cascade-context.js.map +1 -0
  14. package/dist/cascade-executor.d.ts +196 -0
  15. package/dist/cascade-executor.d.ts.map +1 -0
  16. package/dist/cascade-executor.js +384 -0
  17. package/dist/cascade-executor.js.map +1 -0
  18. package/dist/context.d.ts.map +1 -1
  19. package/dist/context.js +4 -1
  20. package/dist/context.js.map +1 -1
  21. package/dist/dependency-graph.d.ts +157 -0
  22. package/dist/dependency-graph.d.ts.map +1 -0
  23. package/dist/dependency-graph.js +382 -0
  24. package/dist/dependency-graph.js.map +1 -0
  25. package/dist/every.d.ts +31 -2
  26. package/dist/every.d.ts.map +1 -1
  27. package/dist/every.js +63 -32
  28. package/dist/every.js.map +1 -1
  29. package/dist/graph/index.d.ts +8 -0
  30. package/dist/graph/index.d.ts.map +1 -0
  31. package/dist/graph/index.js +8 -0
  32. package/dist/graph/index.js.map +1 -0
  33. package/dist/graph/topological-sort.d.ts +121 -0
  34. package/dist/graph/topological-sort.d.ts.map +1 -0
  35. package/dist/graph/topological-sort.js +292 -0
  36. package/dist/graph/topological-sort.js.map +1 -0
  37. package/dist/index.d.ts +6 -1
  38. package/dist/index.d.ts.map +1 -1
  39. package/dist/index.js +10 -0
  40. package/dist/index.js.map +1 -1
  41. package/dist/on.d.ts +35 -10
  42. package/dist/on.d.ts.map +1 -1
  43. package/dist/on.js +52 -18
  44. package/dist/on.js.map +1 -1
  45. package/dist/send.d.ts +0 -5
  46. package/dist/send.d.ts.map +1 -1
  47. package/dist/send.js +1 -14
  48. package/dist/send.js.map +1 -1
  49. package/dist/timer-registry.d.ts +52 -0
  50. package/dist/timer-registry.d.ts.map +1 -0
  51. package/dist/timer-registry.js +120 -0
  52. package/dist/timer-registry.js.map +1 -0
  53. package/dist/types.d.ts +171 -9
  54. package/dist/types.d.ts.map +1 -1
  55. package/dist/types.js +17 -1
  56. package/dist/types.js.map +1 -1
  57. package/dist/workflow.d.ts.map +1 -1
  58. package/dist/workflow.js +22 -18
  59. package/dist/workflow.js.map +1 -1
  60. package/package.json +12 -16
  61. package/src/barrier.ts +466 -0
  62. package/src/cascade-context.ts +488 -0
  63. package/src/cascade-executor.ts +587 -0
  64. package/src/context.js +83 -0
  65. package/src/context.ts +12 -7
  66. package/src/dependency-graph.ts +518 -0
  67. package/src/every.js +267 -0
  68. package/src/every.ts +104 -35
  69. package/src/graph/index.ts +19 -0
  70. package/src/graph/topological-sort.ts +414 -0
  71. package/src/index.js +71 -0
  72. package/src/index.ts +78 -0
  73. package/src/on.js +79 -0
  74. package/src/on.ts +81 -25
  75. package/src/send.js +111 -0
  76. package/src/send.ts +1 -16
  77. package/src/timer-registry.ts +145 -0
  78. package/src/types.js +4 -0
  79. package/src/types.ts +218 -11
  80. package/src/workflow.js +455 -0
  81. package/src/workflow.ts +32 -23
  82. package/test/barrier-join.test.ts +434 -0
  83. package/test/barrier-unhandled-rejections.test.ts +359 -0
  84. package/test/cascade-context.test.ts +390 -0
  85. package/test/cascade-executor.test.ts +859 -0
  86. package/test/context.test.js +116 -0
  87. package/test/dependency-graph.test.ts +512 -0
  88. package/test/every.test.js +282 -0
  89. package/test/graph/topological-sort.test.ts +586 -0
  90. package/test/on.test.js +80 -0
  91. package/test/schedule-timer-cleanup.test.ts +344 -0
  92. package/test/send-race-conditions.test.ts +410 -0
  93. package/test/send.test.js +89 -0
  94. package/test/type-safety-every.test.ts +303 -0
  95. package/test/types-event-handler.test.ts +225 -0
  96. package/test/types-proxy-autocomplete.test.ts +345 -0
  97. package/test/workflow.test.js +224 -0
  98. package/vitest.config.js +7 -0
@@ -1,5 +1,4 @@
1
-
2
- 
3
- > ai-workflows@2.0.1 build /Users/nathanclevenger/projects/primitives.org.ai/packages/ai-workflows
4
- > tsc
5
-
1
+
2
+ > ai-workflows@2.1.3 build /Users/nathanclevenger/projects/primitives.org.ai/packages/ai-workflows
3
+ > tsc
4
+
@@ -0,0 +1,169 @@
1
+
2
+ > ai-workflows@2.1.1 test /Users/nathanclevenger/projects/primitives.org.ai/packages/ai-workflows
3
+ > vitest
4
+
5
+
6
+ DEV v2.1.9 /Users/nathanclevenger/projects/primitives.org.ai/packages/ai-workflows
7
+
8
+ ✓ test/context.test.ts (11 tests) 5ms
9
+ ✓ test/on.test.ts (8 tests) 3ms
10
+ ✓ test/every.test.ts (39 tests) 6ms
11
+ ✓ test/types-event-handler.test.ts (10 tests) 3ms
12
+ stdout | test/types-event-handler.test.ts > EventHandler generic order - TDD RED > Type inference consistency > should support EventHandler<void, InputType> for fire-and-forget handlers
13
+ Processing John (john@example.com)
14
+
15
+ ✓ test/cascade-context.test.ts (29 tests) 7ms
16
+ stdout | test/types-proxy-autocomplete.test.ts > OnProxy/EveryProxy autocomplete - TDD RED > $.send type safety > should type-check send call with data
17
+ [workflow] Welcome email sent
18
+ [workflow] Welcome email sent
19
+
20
+ ✓ test/types-proxy-autocomplete.test.ts (18 tests) 4ms
21
+ ✓ test/dependency-graph.test.ts (41 tests) 7ms
22
+ stdout | test/workflow.test.ts > Workflow - unified $ API > Workflow() > should deliver events to registered handlers
23
+ [workflow] Starting with 1 event handlers and 0 schedules
24
+
25
+ stdout | test/workflow.test.ts > Workflow - unified $ API > Workflow() > should allow chained event sending from handlers
26
+ [workflow] Starting with 2 event handlers and 0 schedules
27
+
28
+ stdout | test/workflow.test.ts > Workflow - unified $ API > Workflow() > should track events in state history
29
+ [workflow] Starting with 1 event handlers and 0 schedules
30
+
31
+ stdout | test/workflow.test.ts > Workflow - unified $ API > Workflow() > should trigger schedule handlers
32
+ [workflow] Starting with 0 event handlers and 1 schedules
33
+
34
+ stdout | test/workflow.test.ts > Workflow - unified $ API > Workflow() > should trigger schedule handlers
35
+ [workflow] Stopping
36
+
37
+ stdout | test/workflow.test.ts > Workflow - unified $ API > Workflow() > should stop schedule handlers on stop
38
+ [workflow] Starting with 0 event handlers and 1 schedules
39
+
40
+ stdout | test/workflow.test.ts > Workflow - unified $ API > Workflow() > should stop schedule handlers on stop
41
+ [workflow] Stopping
42
+
43
+ stdout | test/workflow.test.ts > Workflow - unified $ API > Workflow() > should support $.set and $.get for context data
44
+ [workflow] Starting with 2 event handlers and 0 schedules
45
+
46
+ (node:43941) PromiseRejectionHandledWarning: Promise rejection was handled asynchronously (rejection id: 2)
47
+ (Use `node --trace-warnings ...` to show where the warning was created)
48
+ ✓ test/workflow.test.ts (20 tests) 10ms
49
+ (node:43941) PromiseRejectionHandledWarning: Promise rejection was handled asynchronously (rejection id: 5)
50
+ (node:43941) PromiseRejectionHandledWarning: Promise rejection was handled asynchronously (rejection id: 6)
51
+ stderr | test/send.test.ts > send - event emission > send > should continue with other handlers if one throws
52
+ Error in handler for Customer.created: Error: Handler 1 failed
53
+ at /Users/nathanclevenger/projects/primitives.org.ai/packages/ai-workflows/test/send.test.ts:104:50
54
+ at file:///Users/nathanclevenger/projects/primitives.org.ai/node_modules/.pnpm/@vitest+runner@2.1.9/node_modules/@vitest/runner/dist/index.js:146:14
55
+ at file:///Users/nathanclevenger/projects/primitives.org.ai/node_modules/.pnpm/@vitest+runner@2.1.9/node_modules/@vitest/runner/dist/index.js:533:11
56
+ at runWithTimeout (file:///Users/nathanclevenger/projects/primitives.org.ai/node_modules/.pnpm/@vitest+runner@2.1.9/node_modules/@vitest/runner/dist/index.js:39:7)
57
+ at runTest (file:///Users/nathanclevenger/projects/primitives.org.ai/node_modules/.pnpm/@vitest+runner@2.1.9/node_modules/@vitest/runner/dist/index.js:1056:17)
58
+ at runSuite (file:///Users/nathanclevenger/projects/primitives.org.ai/node_modules/.pnpm/@vitest+runner@2.1.9/node_modules/@vitest/runner/dist/index.js:1205:15)
59
+ at runSuite (file:///Users/nathanclevenger/projects/primitives.org.ai/node_modules/.pnpm/@vitest+runner@2.1.9/node_modules/@vitest/runner/dist/index.js:1205:15)
60
+ at runSuite (file:///Users/nathanclevenger/projects/primitives.org.ai/node_modules/.pnpm/@vitest+runner@2.1.9/node_modules/@vitest/runner/dist/index.js:1205:15)
61
+ at runFiles (file:///Users/nathanclevenger/projects/primitives.org.ai/node_modules/.pnpm/@vitest+runner@2.1.9/node_modules/@vitest/runner/dist/index.js:1262:5)
62
+ at startTests (file:///Users/nathanclevenger/projects/primitives.org.ai/node_modules/.pnpm/@vitest+runner@2.1.9/node_modules/@vitest/runner/dist/index.js:1271:3)
63
+
64
+ ✓ test/send.test.ts (9 tests) 18ms
65
+ (node:43941) PromiseRejectionHandledWarning: Promise rejection was handled asynchronously (rejection id: 10)
66
+ ✓ test/barrier-join.test.ts (29 tests) 19ms
67
+
68
+ ⎯⎯⎯⎯⎯⎯ Unhandled Errors ⎯⎯⎯⎯⎯⎯
69
+
70
+ Vitest caught 4 unhandled errors during the test run.
71
+ This might cause false positive tests. Resolve unhandled errors to make sure your tests are not affected.
72
+
73
+ ⎯⎯⎯⎯ Unhandled Rejection ⎯⎯⎯⎯⎯
74
+ BarrierTimeoutError: Barrier timeout after 1000ms: 0/1 participants arrived
75
+ ❯ src/barrier.ts:302:16
76
+ 300| const timeoutPromise = new Promise<never>((_, reject) => {
77
+ 301| setTimeout(() => {
78
+ 302| reject(new BarrierTimeoutError(timeout, 0, promises.length))
79
+ | ^
80
+ 303| }, timeout)
81
+ 304| })
82
+ ❯ callTimer ../../node_modules/.pnpm/vitest@2.1.9_@types+node@24.10.1_lightningcss@1.30.2_terser@5.16.9/node_modules/vitest/dist/chunks/vi.DgezovHB.js:2300:25
83
+ ❯ doTickInner ../../node_modules/.pnpm/vitest@2.1.9_@types+node@24.10.1_lightningcss@1.30.2_terser@5.16.9/node_modules/vitest/dist/chunks/vi.DgezovHB.js:2886:30
84
+ ❯ doTick ../../node_modules/.pnpm/vitest@2.1.9_@types+node@24.10.1_lightningcss@1.30.2_terser@5.16.9/node_modules/vitest/dist/chunks/vi.DgezovHB.js:2967:21
85
+ ❯ Immediate.<anonymous> ../../node_modules/.pnpm/vitest@2.1.9_@types+node@24.10.1_lightningcss@1.30.2_terser@5.16.9/node_modules/vitest/dist/chunks/vi.DgezovHB.js:2987:30
86
+ ❯ processImmediate node:internal/timers:485:21
87
+
88
+ ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
89
+ Serialized Error: { timeout: 1000, arrived: +0 }
90
+ This error originated in "test/barrier-join.test.ts" test file. It doesn't mean the error was thrown inside the file itself, but while it was running.
91
+ The latest test that might've caused the error is "should support timeout option". It might mean one of the following:
92
+ - The error was thrown, while Vitest was running this test.
93
+ - If the error occurred after the test had been completed, this was the last documented test before it was thrown.
94
+
95
+ ⎯⎯⎯⎯ Unhandled Rejection ⎯⎯⎯⎯⎯
96
+ BarrierTimeoutError: Barrier timeout after 1000ms: 0/2 participants arrived
97
+ ❯ src/barrier.ts:397:18
98
+ 395| } else {
99
+ 396| resolved = true
100
+ 397| reject(new BarrierTimeoutError(timeout, completed.length, n))
101
+ | ^
102
+ 398| }
103
+ 399| }, timeout)
104
+ ❯ callTimer ../../node_modules/.pnpm/vitest@2.1.9_@types+node@24.10.1_lightningcss@1.30.2_terser@5.16.9/node_modules/vitest/dist/chunks/vi.DgezovHB.js:2300:25
105
+ ❯ doTickInner ../../node_modules/.pnpm/vitest@2.1.9_@types+node@24.10.1_lightningcss@1.30.2_terser@5.16.9/node_modules/vitest/dist/chunks/vi.DgezovHB.js:2886:30
106
+ ❯ doTick ../../node_modules/.pnpm/vitest@2.1.9_@types+node@24.10.1_lightningcss@1.30.2_terser@5.16.9/node_modules/vitest/dist/chunks/vi.DgezovHB.js:2967:21
107
+ ❯ Immediate.<anonymous> ../../node_modules/.pnpm/vitest@2.1.9_@types+node@24.10.1_lightningcss@1.30.2_terser@5.16.9/node_modules/vitest/dist/chunks/vi.DgezovHB.js:2987:30
108
+ ❯ processImmediate node:internal/timers:485:21
109
+
110
+ ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
111
+ Serialized Error: { timeout: 1000, arrived: +0 }
112
+ This error originated in "test/barrier-join.test.ts" test file. It doesn't mean the error was thrown inside the file itself, but while it was running.
113
+ The latest test that might've caused the error is "should support timeout". It might mean one of the following:
114
+ - The error was thrown, while Vitest was running this test.
115
+ - If the error occurred after the test had been completed, this was the last documented test before it was thrown.
116
+
117
+ ⎯⎯⎯⎯ Unhandled Rejection ⎯⎯⎯⎯⎯
118
+ BarrierTimeoutError: Barrier timeout after 1000ms: 1/3 participants arrived
119
+ ❯ src/barrier.ts:194:27
120
+ 192| this._timeoutId = setTimeout(() => {
121
+ 193| if (this._waitReject) {
122
+ 194| const error = new BarrierTimeoutError(
123
+ | ^
124
+ 195| this._options.timeout!,
125
+ 196| this._arrived.length,
126
+ ❯ callTimer ../../node_modules/.pnpm/vitest@2.1.9_@types+node@24.10.1_lightningcss@1.30.2_terser@5.16.9/node_modules/vitest/dist/chunks/vi.DgezovHB.js:2300:25
127
+ ❯ doTickInner ../../node_modules/.pnpm/vitest@2.1.9_@types+node@24.10.1_lightningcss@1.30.2_terser@5.16.9/node_modules/vitest/dist/chunks/vi.DgezovHB.js:2886:30
128
+ ❯ doTick ../../node_modules/.pnpm/vitest@2.1.9_@types+node@24.10.1_lightningcss@1.30.2_terser@5.16.9/node_modules/vitest/dist/chunks/vi.DgezovHB.js:2967:21
129
+ ❯ Immediate.<anonymous> ../../node_modules/.pnpm/vitest@2.1.9_@types+node@24.10.1_lightningcss@1.30.2_terser@5.16.9/node_modules/vitest/dist/chunks/vi.DgezovHB.js:2987:30
130
+ ❯ processImmediate node:internal/timers:485:21
131
+
132
+ ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
133
+ Serialized Error: { timeout: 1000, arrived: 1 }
134
+ This error originated in "test/barrier-join.test.ts" test file. It doesn't mean the error was thrown inside the file itself, but while it was running.
135
+ The latest test that might've caused the error is "should support timeout on wait()". It might mean one of the following:
136
+ - The error was thrown, while Vitest was running this test.
137
+ - If the error occurred after the test had been completed, this was the last documented test before it was thrown.
138
+
139
+ ⎯⎯⎯⎯ Unhandled Rejection ⎯⎯⎯⎯⎯
140
+ BarrierTimeoutError: Barrier timeout after 1000ms: 1/3 participants arrived
141
+ ❯ src/barrier.ts:194:27
142
+ 192| this._timeoutId = setTimeout(() => {
143
+ 193| if (this._waitReject) {
144
+ 194| const error = new BarrierTimeoutError(
145
+ | ^
146
+ 195| this._options.timeout!,
147
+ 196| this._arrived.length,
148
+ ❯ callTimer ../../node_modules/.pnpm/vitest@2.1.9_@types+node@24.10.1_lightningcss@1.30.2_terser@5.16.9/node_modules/vitest/dist/chunks/vi.DgezovHB.js:2300:25
149
+ ❯ doTickInner ../../node_modules/.pnpm/vitest@2.1.9_@types+node@24.10.1_lightningcss@1.30.2_terser@5.16.9/node_modules/vitest/dist/chunks/vi.DgezovHB.js:2886:30
150
+ ❯ doTick ../../node_modules/.pnpm/vitest@2.1.9_@types+node@24.10.1_lightningcss@1.30.2_terser@5.16.9/node_modules/vitest/dist/chunks/vi.DgezovHB.js:2967:21
151
+ ❯ Immediate.<anonymous> ../../node_modules/.pnpm/vitest@2.1.9_@types+node@24.10.1_lightningcss@1.30.2_terser@5.16.9/node_modules/vitest/dist/chunks/vi.DgezovHB.js:2987:30
152
+ ❯ processImmediate node:internal/timers:485:21
153
+
154
+ ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
155
+ Serialized Error: { timeout: 1000, arrived: 1 }
156
+ This error originated in "test/barrier-join.test.ts" test file. It doesn't mean the error was thrown inside the file itself, but while it was running.
157
+ The latest test that might've caused the error is "should include timeout details". It might mean one of the following:
158
+ - The error was thrown, while Vitest was running this test.
159
+ - If the error occurred after the test had been completed, this was the last documented test before it was thrown.
160
+ ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
161
+
162
+ Test Files 10 passed (10)
163
+ Tests 214 passed (214)
164
+ Errors 4 errors
165
+ Start at 06:45:30
166
+ Duration 357ms (transform 361ms, setup 0ms, collect 657ms, tests 83ms, environment 1ms, prepare 624ms)
167
+
168
+ FAIL Tests failed. Watching for file changes...
169
+ press h to show help, press q to quit
package/CHANGELOG.md CHANGED
@@ -1,5 +1,34 @@
1
1
  # ai-workflows
2
2
 
3
+ ## 2.1.3
4
+
5
+ ### Patch Changes
6
+
7
+ - Documentation and testing improvements
8
+ - Add deterministic AI testing suite with self-validating patterns
9
+ - Apply StoryBrand narrative to all package READMEs
10
+ - Update TESTING.md with four principles of deterministic AI testing
11
+ - Fix duplicate examples package name conflict
12
+
13
+ ## 2.1.1
14
+
15
+ ### Patch Changes
16
+
17
+ - 6beb531: Add TDD RED phase tests for type system unification
18
+ - ai-functions: Add tests for AIFunction<Output, Input> generic order flip
19
+ - ai-workflows: Add tests for EventHandler<TOutput, TInput> order and OnProxy/EveryProxy autocomplete
20
+ - ai-database: Existing package - no changes in this release
21
+ - @primitives/types: New shared types package with failing tests for RED phase
22
+
23
+ These tests document the expected behavior for the GREEN phase implementation where generic type parameters will be reordered to put Output first (matching Promise<T> convention).
24
+
25
+ ## 2.0.3
26
+
27
+ ### Patch Changes
28
+
29
+ - Updated dependencies
30
+ - rpc.do@0.2.0
31
+
3
32
  ## 2.0.2
4
33
 
5
34
  ## 2.0.1
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 .org.ai
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.