@swirls/looms 0.0.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 (270) hide show
  1. package/LICENSE +190 -0
  2. package/README.md +9 -0
  3. package/dist/actor/cell.d.ts +27 -0
  4. package/dist/actor/cell.js +41 -0
  5. package/dist/actor/host.d.ts +27 -0
  6. package/dist/actor/host.js +82 -0
  7. package/dist/actor/index.d.ts +3 -0
  8. package/dist/actor/index.js +3 -0
  9. package/dist/actor/routing.d.ts +15 -0
  10. package/dist/actor/routing.js +80 -0
  11. package/dist/agent/definitions-store.d.ts +11 -0
  12. package/dist/agent/definitions-store.js +10 -0
  13. package/dist/agent/definitions.d.ts +152 -0
  14. package/dist/agent/definitions.js +74 -0
  15. package/dist/agent/effects.d.ts +425 -0
  16. package/dist/agent/effects.js +318 -0
  17. package/dist/agent/events.d.ts +170 -0
  18. package/dist/agent/events.js +61 -0
  19. package/dist/agent/index.d.ts +13 -0
  20. package/dist/agent/index.js +13 -0
  21. package/dist/agent/llm.d.ts +35 -0
  22. package/dist/agent/llm.js +48 -0
  23. package/dist/agent/module.d.ts +1037 -0
  24. package/dist/agent/module.js +27 -0
  25. package/dist/agent/projections.d.ts +17 -0
  26. package/dist/agent/projections.js +81 -0
  27. package/dist/agent/scope.d.ts +171 -0
  28. package/dist/agent/scope.js +7 -0
  29. package/dist/agent/signals.d.ts +17 -0
  30. package/dist/agent/signals.js +19 -0
  31. package/dist/agent/stop-when.d.ts +12 -0
  32. package/dist/agent/stop-when.js +6 -0
  33. package/dist/agent/threads.d.ts +34 -0
  34. package/dist/agent/threads.js +407 -0
  35. package/dist/agent/tool-schema.d.ts +21 -0
  36. package/dist/agent/tool-schema.js +67 -0
  37. package/dist/agent/types.d.ts +87 -0
  38. package/dist/agent/types.js +32 -0
  39. package/dist/ai-vercel/index.d.ts +2 -0
  40. package/dist/ai-vercel/index.js +2 -0
  41. package/dist/ai-vercel/messages.d.ts +9 -0
  42. package/dist/ai-vercel/messages.js +68 -0
  43. package/dist/ai-vercel/vercel-llm.d.ts +8 -0
  44. package/dist/ai-vercel/vercel-llm.js +98 -0
  45. package/dist/approval/effects.d.ts +133 -0
  46. package/dist/approval/effects.js +13 -0
  47. package/dist/approval/events.d.ts +52 -0
  48. package/dist/approval/events.js +28 -0
  49. package/dist/approval/index.d.ts +6 -0
  50. package/dist/approval/index.js +6 -0
  51. package/dist/approval/module.d.ts +342 -0
  52. package/dist/approval/module.js +10 -0
  53. package/dist/approval/projections.d.ts +42 -0
  54. package/dist/approval/projections.js +57 -0
  55. package/dist/approval/scope.d.ts +45 -0
  56. package/dist/approval/scope.js +7 -0
  57. package/dist/approval/signals.d.ts +19 -0
  58. package/dist/approval/signals.js +34 -0
  59. package/dist/cli/cli.d.ts +2 -0
  60. package/dist/cli/cli.js +6 -0
  61. package/dist/cli/commands.d.ts +13 -0
  62. package/dist/cli/commands.js +133 -0
  63. package/dist/cli/index.d.ts +1 -0
  64. package/dist/cli/index.js +1 -0
  65. package/dist/client/client.d.ts +69 -0
  66. package/dist/client/client.js +179 -0
  67. package/dist/client/index.d.ts +2 -0
  68. package/dist/client/index.js +2 -0
  69. package/dist/client/sse.d.ts +10 -0
  70. package/dist/client/sse.js +103 -0
  71. package/dist/cloudflare/alarm-scheduler.d.ts +9 -0
  72. package/dist/cloudflare/alarm-scheduler.js +13 -0
  73. package/dist/cloudflare/durable-object.d.ts +24 -0
  74. package/dist/cloudflare/durable-object.js +43 -0
  75. package/dist/cloudflare/event-store.d.ts +10 -0
  76. package/dist/cloudflare/event-store.js +18 -0
  77. package/dist/cloudflare/index.d.ts +4 -0
  78. package/dist/cloudflare/index.js +4 -0
  79. package/dist/cloudflare/router.d.ts +12 -0
  80. package/dist/cloudflare/router.js +26 -0
  81. package/dist/core/bun-sqlite.d.ts +13 -0
  82. package/dist/core/bun-sqlite.js +19 -0
  83. package/dist/core/catalog.d.ts +49 -0
  84. package/dist/core/catalog.js +39 -0
  85. package/dist/core/coalesce.d.ts +21 -0
  86. package/dist/core/coalesce.js +178 -0
  87. package/dist/core/compose.d.ts +59 -0
  88. package/dist/core/compose.js +97 -0
  89. package/dist/core/cursor.d.ts +16 -0
  90. package/dist/core/cursor.js +46 -0
  91. package/dist/core/effects.d.ts +110 -0
  92. package/dist/core/effects.js +99 -0
  93. package/dist/core/envelope.d.ts +79 -0
  94. package/dist/core/envelope.js +68 -0
  95. package/dist/core/event-codec.d.ts +8 -0
  96. package/dist/core/event-codec.js +82 -0
  97. package/dist/core/event-index.d.ts +28 -0
  98. package/dist/core/event-index.js +86 -0
  99. package/dist/core/fold.d.ts +19 -0
  100. package/dist/core/fold.js +362 -0
  101. package/dist/core/ids.d.ts +11 -0
  102. package/dist/core/ids.js +47 -0
  103. package/dist/core/index.d.ts +26 -0
  104. package/dist/core/index.js +25 -0
  105. package/dist/core/match.d.ts +8 -0
  106. package/dist/core/match.js +58 -0
  107. package/dist/core/module-scope.d.ts +99 -0
  108. package/dist/core/module-scope.js +72 -0
  109. package/dist/core/module.d.ts +74 -0
  110. package/dist/core/module.js +3 -0
  111. package/dist/core/projection.d.ts +83 -0
  112. package/dist/core/projection.js +241 -0
  113. package/dist/core/protocol.d.ts +99 -0
  114. package/dist/core/protocol.js +101 -0
  115. package/dist/core/replay.d.ts +13 -0
  116. package/dist/core/replay.js +34 -0
  117. package/dist/core/schema.d.ts +35 -0
  118. package/dist/core/schema.js +130 -0
  119. package/dist/core/serialize.d.ts +14 -0
  120. package/dist/core/serialize.js +42 -0
  121. package/dist/core/snapshot-store.d.ts +39 -0
  122. package/dist/core/snapshot-store.js +53 -0
  123. package/dist/core/snapshots.d.ts +26 -0
  124. package/dist/core/snapshots.js +100 -0
  125. package/dist/core/sqlite-store.d.ts +31 -0
  126. package/dist/core/sqlite-store.js +328 -0
  127. package/dist/core/state.d.ts +43 -0
  128. package/dist/core/state.js +31 -0
  129. package/dist/core/store.d.ts +146 -0
  130. package/dist/core/store.js +229 -0
  131. package/dist/core/thread.d.ts +41 -0
  132. package/dist/core/thread.js +13 -0
  133. package/dist/core/types.d.ts +27 -0
  134. package/dist/core/types.js +42 -0
  135. package/dist/core/validate-event.d.ts +19 -0
  136. package/dist/core/validate-event.js +42 -0
  137. package/dist/debugger/components/debugger-split.d.ts +23 -0
  138. package/dist/debugger/components/debugger-split.js +25 -0
  139. package/dist/debugger/components/event-inspector.d.ts +5 -0
  140. package/dist/debugger/components/event-inspector.js +38 -0
  141. package/dist/debugger/components/event-stream.d.ts +13 -0
  142. package/dist/debugger/components/event-stream.js +119 -0
  143. package/dist/debugger/components/json-view.d.ts +5 -0
  144. package/dist/debugger/components/json-view.js +5 -0
  145. package/dist/debugger/components/run-tree.d.ts +14 -0
  146. package/dist/debugger/components/run-tree.js +38 -0
  147. package/dist/debugger/components/status-dot.d.ts +3 -0
  148. package/dist/debugger/components/status-dot.js +5 -0
  149. package/dist/debugger/contracts.d.ts +22 -0
  150. package/dist/debugger/contracts.js +1 -0
  151. package/dist/debugger/events/catalog.d.ts +6 -0
  152. package/dist/debugger/events/catalog.js +27 -0
  153. package/dist/debugger/events/domain-summarize.d.ts +3 -0
  154. package/dist/debugger/events/domain-summarize.js +107 -0
  155. package/dist/debugger/events/family.d.ts +8 -0
  156. package/dist/debugger/events/family.js +44 -0
  157. package/dist/debugger/events/protocol-summarize.d.ts +3 -0
  158. package/dist/debugger/events/protocol-summarize.js +70 -0
  159. package/dist/debugger/index.d.ts +17 -0
  160. package/dist/debugger/index.js +16 -0
  161. package/dist/debugger/lib/cn.d.ts +5 -0
  162. package/dist/debugger/lib/cn.js +17 -0
  163. package/dist/debugger/lib/event-counts.d.ts +5 -0
  164. package/dist/debugger/lib/event-counts.js +23 -0
  165. package/dist/debugger/lib/event-meta.d.ts +8 -0
  166. package/dist/debugger/lib/event-meta.js +20 -0
  167. package/dist/debugger/lib/project-run.d.ts +9 -0
  168. package/dist/debugger/lib/project-run.js +14 -0
  169. package/dist/debugger/lib/status.d.ts +3 -0
  170. package/dist/debugger/lib/status.js +31 -0
  171. package/dist/debugger/lib/visible-events.d.ts +8 -0
  172. package/dist/debugger/lib/visible-events.js +21 -0
  173. package/dist/debugger/styles.css +71 -0
  174. package/dist/debugger/ui/checkbox.d.ts +4 -0
  175. package/dist/debugger/ui/checkbox.js +9 -0
  176. package/dist/debugger/ui/input.d.ts +3 -0
  177. package/dist/debugger/ui/input.js +7 -0
  178. package/dist/debugger/ui/scroll-area.d.ts +9 -0
  179. package/dist/debugger/ui/scroll-area.js +10 -0
  180. package/dist/debugger/ui/tabs.d.ts +7 -0
  181. package/dist/debugger/ui/tabs.js +17 -0
  182. package/dist/index.d.ts +2 -0
  183. package/dist/index.js +2 -0
  184. package/dist/projectors/index-model.d.ts +56 -0
  185. package/dist/projectors/index-model.js +117 -0
  186. package/dist/projectors/index.d.ts +4 -0
  187. package/dist/projectors/index.js +3 -0
  188. package/dist/projectors/memory.d.ts +5 -0
  189. package/dist/projectors/memory.js +77 -0
  190. package/dist/projectors/postgres.d.ts +9 -0
  191. package/dist/projectors/postgres.js +108 -0
  192. package/dist/projectors/projector.d.ts +11 -0
  193. package/dist/projectors/projector.js +1 -0
  194. package/dist/projectors/schema.d.ts +5 -0
  195. package/dist/projectors/schema.js +43 -0
  196. package/dist/projectors/sqlite.d.ts +9 -0
  197. package/dist/projectors/sqlite.js +103 -0
  198. package/dist/projectors/with-projectors.d.ts +17 -0
  199. package/dist/projectors/with-projectors.js +55 -0
  200. package/dist/react/derived.d.ts +19 -0
  201. package/dist/react/derived.js +50 -0
  202. package/dist/react/index.d.ts +6 -0
  203. package/dist/react/index.js +5 -0
  204. package/dist/react/materialize.d.ts +3 -0
  205. package/dist/react/materialize.js +86 -0
  206. package/dist/react/notify.d.ts +18 -0
  207. package/dist/react/notify.js +80 -0
  208. package/dist/react/react.d.ts +61 -0
  209. package/dist/react/react.js +187 -0
  210. package/dist/react/register.d.ts +31 -0
  211. package/dist/react/register.js +1 -0
  212. package/dist/react/sse.d.ts +1 -0
  213. package/dist/react/sse.js +1 -0
  214. package/dist/react/store.d.ts +56 -0
  215. package/dist/react/store.js +340 -0
  216. package/dist/react/tables.d.ts +21 -0
  217. package/dist/react/tables.js +6 -0
  218. package/dist/runtime/dispatch-effect.d.ts +3 -0
  219. package/dist/runtime/dispatch-effect.js +113 -0
  220. package/dist/runtime/events-api.d.ts +4 -0
  221. package/dist/runtime/events-api.js +84 -0
  222. package/dist/runtime/index.d.ts +5 -0
  223. package/dist/runtime/index.js +5 -0
  224. package/dist/runtime/looms.d.ts +74 -0
  225. package/dist/runtime/looms.js +109 -0
  226. package/dist/runtime/runtime-helpers.d.ts +51 -0
  227. package/dist/runtime/runtime-helpers.js +230 -0
  228. package/dist/runtime/runtime.d.ts +91 -0
  229. package/dist/runtime/runtime.js +531 -0
  230. package/dist/runtime/server.d.ts +17 -0
  231. package/dist/runtime/server.js +226 -0
  232. package/dist/runtime/sse.d.ts +15 -0
  233. package/dist/runtime/sse.js +96 -0
  234. package/dist/runtime/wake-scheduler.d.ts +8 -0
  235. package/dist/runtime/wake-scheduler.js +38 -0
  236. package/dist/s2/config.d.ts +27 -0
  237. package/dist/s2/config.js +54 -0
  238. package/dist/s2/index.d.ts +6 -0
  239. package/dist/s2/index.js +6 -0
  240. package/dist/s2/lite.d.ts +26 -0
  241. package/dist/s2/lite.js +150 -0
  242. package/dist/s2/projector.d.ts +8 -0
  243. package/dist/s2/projector.js +28 -0
  244. package/dist/s2/serialize.d.ts +1 -0
  245. package/dist/s2/serialize.js +1 -0
  246. package/dist/s2/snapshot-store.d.ts +17 -0
  247. package/dist/s2/snapshot-store.js +320 -0
  248. package/dist/s2/store.d.ts +35 -0
  249. package/dist/s2/store.js +337 -0
  250. package/dist/testing/index.d.ts +11 -0
  251. package/dist/testing/index.js +63 -0
  252. package/dist/workflow/definitions-store.d.ts +11 -0
  253. package/dist/workflow/definitions-store.js +8 -0
  254. package/dist/workflow/definitions.d.ts +82 -0
  255. package/dist/workflow/definitions.js +32 -0
  256. package/dist/workflow/effects.d.ts +305 -0
  257. package/dist/workflow/effects.js +208 -0
  258. package/dist/workflow/events.d.ts +60 -0
  259. package/dist/workflow/events.js +39 -0
  260. package/dist/workflow/index.d.ts +8 -0
  261. package/dist/workflow/index.js +8 -0
  262. package/dist/workflow/module.d.ts +926 -0
  263. package/dist/workflow/module.js +19 -0
  264. package/dist/workflow/projections.d.ts +30 -0
  265. package/dist/workflow/projections.js +43 -0
  266. package/dist/workflow/scope.d.ts +61 -0
  267. package/dist/workflow/scope.js +7 -0
  268. package/dist/workflow/threads.d.ts +171 -0
  269. package/dist/workflow/threads.js +287 -0
  270. package/package.json +183 -0
@@ -0,0 +1,305 @@
1
+ import { Schema } from 'effect';
2
+ import { type EventInputOf, type JsonValue } from '@swirls/looms/core';
3
+ import { type WorkflowDefinition } from './definitions';
4
+ import { WorkflowDefinitionsTag } from './definitions-store';
5
+ import { type WorkflowEvent } from './scope';
6
+ export declare const scheduleEffect: NoInfer<import("@swirls/looms/core").EffectDefinition<{
7
+ readonly definitionName?: string | undefined;
8
+ readonly nodes?: {
9
+ readonly [x: string]: {
10
+ readonly status: "completed" | "failed" | "pending" | "running" | "skipped";
11
+ readonly result: Schema.Json;
12
+ readonly error: string | null;
13
+ };
14
+ } | undefined;
15
+ readonly input?: Schema.Json | undefined;
16
+ }, WorkflowDefinitionsTag, (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
17
+ readonly type: "runtime.effect.failed";
18
+ readonly payload: {
19
+ readonly effectId: string;
20
+ readonly error: string;
21
+ };
22
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
23
+ readonly type: "runtime.run.completed";
24
+ readonly payload: {
25
+ readonly output: Schema.Json;
26
+ readonly error: string | null;
27
+ };
28
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
29
+ readonly type: "runtime.run.started";
30
+ readonly payload: {
31
+ readonly rootThreadId?: string | undefined;
32
+ readonly kind: string;
33
+ readonly definitionName: string;
34
+ readonly input: Schema.Json;
35
+ };
36
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
37
+ readonly type: "runtime.signal.received";
38
+ readonly payload: {
39
+ readonly signalType: string;
40
+ };
41
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
42
+ readonly type: "runtime.snapshot.taken";
43
+ readonly payload: {
44
+ readonly seq: number;
45
+ readonly stateHash: string;
46
+ readonly state?: Schema.Json | undefined;
47
+ };
48
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
49
+ readonly type: "runtime.thread.cancelled";
50
+ readonly payload: {
51
+ readonly threadId: string;
52
+ readonly reason?: string | undefined;
53
+ };
54
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
55
+ readonly type: "runtime.thread.completed";
56
+ readonly payload: {
57
+ readonly threadId: string;
58
+ readonly output: Schema.Json;
59
+ };
60
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
61
+ readonly type: "runtime.thread.failed";
62
+ readonly payload: {
63
+ readonly threadId: string;
64
+ readonly error: string;
65
+ };
66
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
67
+ readonly type: "runtime.thread.started";
68
+ readonly payload: {
69
+ readonly threadId: string;
70
+ readonly kind: string;
71
+ readonly definitionName: string;
72
+ readonly input: Schema.Json;
73
+ readonly parentThreadId: string | null;
74
+ };
75
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
76
+ readonly type: "runtime.timer.fired";
77
+ readonly payload: {
78
+ readonly timerId: string;
79
+ readonly waitId: string;
80
+ };
81
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
82
+ readonly type: "runtime.timer.set";
83
+ readonly payload: {
84
+ readonly timerId: string;
85
+ readonly waitId: string;
86
+ readonly wakeAt: number;
87
+ };
88
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
89
+ readonly type: "runtime.wait.registered";
90
+ readonly payload: {
91
+ readonly waitId: string;
92
+ readonly threadId?: string | undefined;
93
+ readonly on: {
94
+ readonly type: string | readonly string[];
95
+ readonly match?: Schema.Json | undefined;
96
+ } | {
97
+ readonly timerAt: number;
98
+ };
99
+ readonly tag?: Schema.Json | undefined;
100
+ };
101
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
102
+ readonly type: "runtime.wait.satisfied";
103
+ readonly payload: {
104
+ readonly waitId: string;
105
+ readonly tag?: Schema.Json | undefined;
106
+ readonly event: {
107
+ readonly id: string;
108
+ readonly type: string;
109
+ readonly payload: Schema.Json;
110
+ };
111
+ };
112
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
113
+ readonly type: "workflow.effects.requested";
114
+ readonly payload: {
115
+ readonly nodeId: string;
116
+ readonly effects: readonly import("@swirls/looms/core").RuntimeEffect[];
117
+ };
118
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
119
+ readonly type: "workflow.node.finished";
120
+ readonly payload: {
121
+ readonly nodeId: string;
122
+ readonly result: Schema.Json;
123
+ readonly error: string | null;
124
+ };
125
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
126
+ readonly type: "workflow.node.skipped";
127
+ readonly payload: {
128
+ readonly nodeId: string;
129
+ readonly reason: string;
130
+ };
131
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
132
+ readonly type: "workflow.node.started";
133
+ readonly payload: {
134
+ readonly nodeId: string;
135
+ };
136
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
137
+ readonly type: "workflow.sleep.requested";
138
+ readonly payload: {
139
+ readonly nodeId: string;
140
+ readonly waitId: string;
141
+ readonly wakeAt: number;
142
+ };
143
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
144
+ readonly type: "workflow.spawn.requested";
145
+ readonly payload: {
146
+ readonly nodeId: string;
147
+ readonly childThreadId: string;
148
+ readonly kind: string;
149
+ readonly definitionName: string;
150
+ readonly input: Schema.Json;
151
+ };
152
+ })>>;
153
+ export declare function scheduleEvents(definition: WorkflowDefinition, binding: {
154
+ nodes: {
155
+ [id: string]: {
156
+ status: string;
157
+ result: JsonValue | null;
158
+ };
159
+ };
160
+ input: JsonValue;
161
+ }, threadId: string): EventInputOf<WorkflowEvent>[];
162
+ export declare const runNodeEffect: NoInfer<import("@swirls/looms/core").EffectDefinition<{
163
+ readonly definitionName?: string | undefined;
164
+ readonly nodeId: string;
165
+ readonly input?: Schema.Json | undefined;
166
+ readonly results?: {
167
+ readonly [x: string]: Schema.Json;
168
+ } | undefined;
169
+ }, WorkflowDefinitionsTag, (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
170
+ readonly type: "runtime.effect.failed";
171
+ readonly payload: {
172
+ readonly effectId: string;
173
+ readonly error: string;
174
+ };
175
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
176
+ readonly type: "runtime.run.completed";
177
+ readonly payload: {
178
+ readonly output: Schema.Json;
179
+ readonly error: string | null;
180
+ };
181
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
182
+ readonly type: "runtime.run.started";
183
+ readonly payload: {
184
+ readonly rootThreadId?: string | undefined;
185
+ readonly kind: string;
186
+ readonly definitionName: string;
187
+ readonly input: Schema.Json;
188
+ };
189
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
190
+ readonly type: "runtime.signal.received";
191
+ readonly payload: {
192
+ readonly signalType: string;
193
+ };
194
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
195
+ readonly type: "runtime.snapshot.taken";
196
+ readonly payload: {
197
+ readonly seq: number;
198
+ readonly stateHash: string;
199
+ readonly state?: Schema.Json | undefined;
200
+ };
201
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
202
+ readonly type: "runtime.thread.cancelled";
203
+ readonly payload: {
204
+ readonly threadId: string;
205
+ readonly reason?: string | undefined;
206
+ };
207
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
208
+ readonly type: "runtime.thread.completed";
209
+ readonly payload: {
210
+ readonly threadId: string;
211
+ readonly output: Schema.Json;
212
+ };
213
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
214
+ readonly type: "runtime.thread.failed";
215
+ readonly payload: {
216
+ readonly threadId: string;
217
+ readonly error: string;
218
+ };
219
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
220
+ readonly type: "runtime.thread.started";
221
+ readonly payload: {
222
+ readonly threadId: string;
223
+ readonly kind: string;
224
+ readonly definitionName: string;
225
+ readonly input: Schema.Json;
226
+ readonly parentThreadId: string | null;
227
+ };
228
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
229
+ readonly type: "runtime.timer.fired";
230
+ readonly payload: {
231
+ readonly timerId: string;
232
+ readonly waitId: string;
233
+ };
234
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
235
+ readonly type: "runtime.timer.set";
236
+ readonly payload: {
237
+ readonly timerId: string;
238
+ readonly waitId: string;
239
+ readonly wakeAt: number;
240
+ };
241
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
242
+ readonly type: "runtime.wait.registered";
243
+ readonly payload: {
244
+ readonly waitId: string;
245
+ readonly threadId?: string | undefined;
246
+ readonly on: {
247
+ readonly type: string | readonly string[];
248
+ readonly match?: Schema.Json | undefined;
249
+ } | {
250
+ readonly timerAt: number;
251
+ };
252
+ readonly tag?: Schema.Json | undefined;
253
+ };
254
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
255
+ readonly type: "runtime.wait.satisfied";
256
+ readonly payload: {
257
+ readonly waitId: string;
258
+ readonly tag?: Schema.Json | undefined;
259
+ readonly event: {
260
+ readonly id: string;
261
+ readonly type: string;
262
+ readonly payload: Schema.Json;
263
+ };
264
+ };
265
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
266
+ readonly type: "workflow.effects.requested";
267
+ readonly payload: {
268
+ readonly nodeId: string;
269
+ readonly effects: readonly import("@swirls/looms/core").RuntimeEffect[];
270
+ };
271
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
272
+ readonly type: "workflow.node.finished";
273
+ readonly payload: {
274
+ readonly nodeId: string;
275
+ readonly result: Schema.Json;
276
+ readonly error: string | null;
277
+ };
278
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
279
+ readonly type: "workflow.node.skipped";
280
+ readonly payload: {
281
+ readonly nodeId: string;
282
+ readonly reason: string;
283
+ };
284
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
285
+ readonly type: "workflow.node.started";
286
+ readonly payload: {
287
+ readonly nodeId: string;
288
+ };
289
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
290
+ readonly type: "workflow.sleep.requested";
291
+ readonly payload: {
292
+ readonly nodeId: string;
293
+ readonly waitId: string;
294
+ readonly wakeAt: number;
295
+ };
296
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
297
+ readonly type: "workflow.spawn.requested";
298
+ readonly payload: {
299
+ readonly nodeId: string;
300
+ readonly childThreadId: string;
301
+ readonly kind: string;
302
+ readonly definitionName: string;
303
+ readonly input: Schema.Json;
304
+ };
305
+ })>>;
@@ -0,0 +1,208 @@
1
+ import { Effect, Predicate, Schema } from 'effect';
2
+ import { createThreadId, createWaitId } from '@swirls/looms/core';
3
+ import { NodeStateSchema, readyNodes, } from './definitions.js';
4
+ import { WorkflowDefinitionsTag } from './definitions-store.js';
5
+ import { workflowModule } from './scope.js';
6
+ const ScheduleInput = Schema.Struct({
7
+ definitionName: Schema.optional(Schema.String),
8
+ nodes: Schema.optional(Schema.Record(Schema.String, NodeStateSchema)),
9
+ input: Schema.optional(Schema.Json),
10
+ });
11
+ const RunNodeInput = Schema.Struct({
12
+ definitionName: Schema.optional(Schema.String),
13
+ nodeId: Schema.String,
14
+ input: Schema.optional(Schema.Json),
15
+ results: Schema.optional(Schema.Record(Schema.String, Schema.NullOr(Schema.Json))),
16
+ });
17
+ function isNodeResult(raw) {
18
+ if (!Predicate.isObject(raw) || !('type' in raw)) {
19
+ return false;
20
+ }
21
+ return (raw.type === 'value' || raw.type === 'spawn' || raw.type === 'sleep' || raw.type === 'effects');
22
+ }
23
+ export const scheduleEffect = workflowModule.effect({
24
+ type: 'workflow.schedule',
25
+ input: ScheduleInput,
26
+ execute: (input, ctx) => Effect.gen(function* () {
27
+ const workflows = yield* WorkflowDefinitionsTag;
28
+ const threadId = ctx.threadId;
29
+ const definition = input.definitionName ? workflows.get(input.definitionName) : undefined;
30
+ if (!definition) {
31
+ return [];
32
+ }
33
+ const rawNodes = input.nodes ?? {};
34
+ const nodes = {};
35
+ for (const [id, n] of Object.entries(rawNodes)) {
36
+ // SAFETY: NodeState results are valid JSON-serializable node execution outputs.
37
+ nodes[id] = { status: n.status, result: n.result ?? null };
38
+ }
39
+ for (const node of definition.nodes) {
40
+ if (!nodes[node.id]) {
41
+ nodes[node.id] = { status: 'pending', result: null };
42
+ }
43
+ }
44
+ // SAFETY: Workflow input is validated and serialized as JsonValue.
45
+ return scheduleEvents(definition, { nodes, input: input.input ?? null }, threadId);
46
+ }),
47
+ });
48
+ export function scheduleEvents(definition, binding, threadId) {
49
+ const running = Object.values(binding.nodes).filter((n) => n.status === 'running').length;
50
+ const slots = Math.max(0, (definition.concurrency ?? 8) - running);
51
+ const ready = readyNodes(definition, binding.nodes).slice(0, slots);
52
+ const events = [];
53
+ for (const nodeId of ready) {
54
+ events.push({
55
+ type: 'workflow.node.started',
56
+ payload: { nodeId },
57
+ threadId,
58
+ });
59
+ }
60
+ if (ready.length > 0) {
61
+ return events;
62
+ }
63
+ const pending = Object.values(binding.nodes).some((n) => n.status === 'pending' || n.status === 'running');
64
+ if (pending) {
65
+ return [];
66
+ }
67
+ const failed = Object.entries(binding.nodes).find(([, n]) => n.status === 'failed');
68
+ if (failed) {
69
+ return [
70
+ {
71
+ type: 'runtime.thread.failed',
72
+ payload: { threadId, error: `Node ${failed[0]} failed` },
73
+ threadId,
74
+ },
75
+ ];
76
+ }
77
+ const results = {};
78
+ for (const [id, node] of Object.entries(binding.nodes)) {
79
+ results[id] = node.result;
80
+ }
81
+ const output = definition.output ? definition.output({ input: binding.input, results }) : results;
82
+ return [
83
+ {
84
+ type: 'runtime.thread.completed',
85
+ payload: { threadId, output },
86
+ threadId,
87
+ },
88
+ ];
89
+ }
90
+ export const runNodeEffect = workflowModule.effect({
91
+ type: 'workflow.runNode',
92
+ input: RunNodeInput,
93
+ execute: (input, ctx) => Effect.gen(function* () {
94
+ const workflows = yield* WorkflowDefinitionsTag;
95
+ const threadId = ctx.threadId;
96
+ const definition = input.definitionName ? workflows.get(input.definitionName) : undefined;
97
+ if (!definition) {
98
+ return [
99
+ {
100
+ type: 'workflow.node.finished',
101
+ payload: { nodeId: input.nodeId, result: null, error: 'Unknown workflow definition' },
102
+ threadId,
103
+ },
104
+ ];
105
+ }
106
+ const rawResults = input.results ?? {};
107
+ const results = {};
108
+ for (const [id, val] of Object.entries(rawResults)) {
109
+ // SAFETY: Node results dictionary maps node IDs to JSON values or null.
110
+ results[id] = val ?? null;
111
+ }
112
+ return yield* runNode(definition,
113
+ // SAFETY: Workflow input is validated and serialized as JsonValue.
114
+ { input: input.input ?? null, results }, input.nodeId, threadId);
115
+ }),
116
+ });
117
+ function runNode(definition, binding, nodeId, threadId) {
118
+ return Effect.gen(function* () {
119
+ const nodeDef = definition.nodes.find((node) => node.id === nodeId);
120
+ if (!nodeDef) {
121
+ return [
122
+ {
123
+ type: 'workflow.node.finished',
124
+ payload: { nodeId, result: null, error: `Unknown node: ${nodeId}` },
125
+ threadId,
126
+ },
127
+ ];
128
+ }
129
+ const results = binding.results;
130
+ const raw = yield* Effect.tryPromise({
131
+ try: () => Promise.resolve(nodeDef.run({
132
+ threadId,
133
+ nodeId,
134
+ input: binding.input,
135
+ results,
136
+ spawn: (child, input) => ({ type: 'spawn', kind: child.kind, name: child.name, input }),
137
+ sleep: (ms) => ({ type: 'sleep', ms }),
138
+ effects: (effects) => ({ type: 'effects', effects }),
139
+ })),
140
+ catch: (cause) => (cause instanceof Error ? cause : new Error(String(cause))),
141
+ }).pipe(Effect.map((value) => ({ ok: true, value })), Effect.catch((err) => Effect.succeed({ ok: false, error: err.message })));
142
+ if (!raw.ok) {
143
+ return [
144
+ {
145
+ type: 'workflow.node.finished',
146
+ payload: { nodeId, result: null, error: raw.error },
147
+ threadId,
148
+ },
149
+ ];
150
+ }
151
+ const result = isNodeResult(raw.value)
152
+ ? raw.value
153
+ : { type: 'value', value: raw.value };
154
+ switch (result.type) {
155
+ case 'value':
156
+ return [
157
+ {
158
+ type: 'workflow.node.finished',
159
+ payload: { nodeId, result: result.value ?? null, error: null },
160
+ threadId,
161
+ },
162
+ ];
163
+ case 'spawn': {
164
+ const childThreadId = createThreadId();
165
+ return [
166
+ {
167
+ type: 'workflow.spawn.requested',
168
+ payload: {
169
+ nodeId,
170
+ childThreadId,
171
+ kind: result.kind,
172
+ definitionName: result.name,
173
+ input: result.input ?? null,
174
+ },
175
+ threadId,
176
+ },
177
+ ];
178
+ }
179
+ case 'sleep':
180
+ return [
181
+ {
182
+ type: 'workflow.sleep.requested',
183
+ payload: {
184
+ nodeId,
185
+ waitId: createWaitId(threadId, `sleep_${nodeId}`),
186
+ wakeAt: Date.now() + result.ms,
187
+ },
188
+ threadId,
189
+ },
190
+ ];
191
+ case 'effects':
192
+ return [
193
+ {
194
+ type: 'workflow.effects.requested',
195
+ payload: {
196
+ nodeId,
197
+ effects: result.effects ?? [],
198
+ },
199
+ threadId,
200
+ },
201
+ ];
202
+ default: {
203
+ const exhaustiveCheck = result;
204
+ return exhaustiveCheck;
205
+ }
206
+ }
207
+ });
208
+ }
@@ -0,0 +1,60 @@
1
+ import { Schema } from 'effect';
2
+ import { type RuntimeEffect } from '@swirls/looms/core';
3
+ export declare const WorkflowNodeStartedPayloadSchema: Schema.Struct<{
4
+ readonly nodeId: Schema.String;
5
+ }>;
6
+ export declare const WorkflowNodeFinishedPayloadSchema: Schema.Struct<{
7
+ readonly nodeId: Schema.String;
8
+ readonly result: Schema.NullOr<Schema.Codec<Schema.Json, Schema.Json, never, never>>;
9
+ readonly error: Schema.NullOr<Schema.String>;
10
+ }>;
11
+ export declare const WorkflowNodeSkippedPayloadSchema: Schema.Struct<{
12
+ readonly nodeId: Schema.String;
13
+ readonly reason: Schema.String;
14
+ }>;
15
+ export declare const WorkflowSpawnRequestedPayloadSchema: Schema.Struct<{
16
+ readonly nodeId: Schema.String;
17
+ readonly childThreadId: Schema.String;
18
+ readonly kind: Schema.String;
19
+ readonly definitionName: Schema.String;
20
+ readonly input: Schema.Codec<Schema.Json, Schema.Json, never, never>;
21
+ }>;
22
+ export declare const WorkflowSleepRequestedPayloadSchema: Schema.Struct<{
23
+ readonly nodeId: Schema.String;
24
+ readonly waitId: Schema.String;
25
+ readonly wakeAt: Schema.Number;
26
+ }>;
27
+ export declare const WorkflowEffectsRequestedPayloadSchema: Schema.Struct<{
28
+ readonly nodeId: Schema.String;
29
+ readonly effects: Schema.$Array<Schema.Schema<RuntimeEffect>>;
30
+ }>;
31
+ export declare const workflowCatalog: import("@swirls/looms/core").EventCatalog<"workflow", {
32
+ 'node.started': Schema.Struct<{
33
+ readonly nodeId: Schema.String;
34
+ }>;
35
+ 'node.finished': Schema.Struct<{
36
+ readonly nodeId: Schema.String;
37
+ readonly result: Schema.NullOr<Schema.Codec<Schema.Json, Schema.Json, never, never>>;
38
+ readonly error: Schema.NullOr<Schema.String>;
39
+ }>;
40
+ 'node.skipped': Schema.Struct<{
41
+ readonly nodeId: Schema.String;
42
+ readonly reason: Schema.String;
43
+ }>;
44
+ 'spawn.requested': Schema.Struct<{
45
+ readonly nodeId: Schema.String;
46
+ readonly childThreadId: Schema.String;
47
+ readonly kind: Schema.String;
48
+ readonly definitionName: Schema.String;
49
+ readonly input: Schema.Codec<Schema.Json, Schema.Json, never, never>;
50
+ }>;
51
+ 'sleep.requested': Schema.Struct<{
52
+ readonly nodeId: Schema.String;
53
+ readonly waitId: Schema.String;
54
+ readonly wakeAt: Schema.Number;
55
+ }>;
56
+ 'effects.requested': Schema.Struct<{
57
+ readonly nodeId: Schema.String;
58
+ readonly effects: Schema.$Array<Schema.Schema<RuntimeEffect>>;
59
+ }>;
60
+ }>;
@@ -0,0 +1,39 @@
1
+ import { Schema } from 'effect';
2
+ import { defineEventCatalog } from '@swirls/looms/core';
3
+ export const WorkflowNodeStartedPayloadSchema = Schema.Struct({
4
+ nodeId: Schema.String,
5
+ });
6
+ export const WorkflowNodeFinishedPayloadSchema = Schema.Struct({
7
+ nodeId: Schema.String,
8
+ result: Schema.NullOr(Schema.Json),
9
+ error: Schema.NullOr(Schema.String),
10
+ });
11
+ export const WorkflowNodeSkippedPayloadSchema = Schema.Struct({
12
+ nodeId: Schema.String,
13
+ reason: Schema.String,
14
+ });
15
+ export const WorkflowSpawnRequestedPayloadSchema = Schema.Struct({
16
+ nodeId: Schema.String,
17
+ childThreadId: Schema.String,
18
+ kind: Schema.String,
19
+ definitionName: Schema.String,
20
+ input: Schema.Json,
21
+ });
22
+ export const WorkflowSleepRequestedPayloadSchema = Schema.Struct({
23
+ nodeId: Schema.String,
24
+ waitId: Schema.String,
25
+ wakeAt: Schema.Number,
26
+ });
27
+ export const WorkflowEffectsRequestedPayloadSchema = Schema.Struct({
28
+ nodeId: Schema.String,
29
+ // SAFETY: RuntimeEffect represents serializable requested effect instructions.
30
+ effects: Schema.Array(Schema.Unknown),
31
+ });
32
+ export const workflowCatalog = defineEventCatalog('workflow', {
33
+ 'node.started': WorkflowNodeStartedPayloadSchema,
34
+ 'node.finished': WorkflowNodeFinishedPayloadSchema,
35
+ 'node.skipped': WorkflowNodeSkippedPayloadSchema,
36
+ 'spawn.requested': WorkflowSpawnRequestedPayloadSchema,
37
+ 'sleep.requested': WorkflowSleepRequestedPayloadSchema,
38
+ 'effects.requested': WorkflowEffectsRequestedPayloadSchema,
39
+ });
@@ -0,0 +1,8 @@
1
+ export * from './definitions';
2
+ export * from './definitions-store';
3
+ export * from './events';
4
+ export * from './scope';
5
+ export * from './threads';
6
+ export * from './effects';
7
+ export * from './projections';
8
+ export * from './module';
@@ -0,0 +1,8 @@
1
+ export * from './definitions.js';
2
+ export * from './definitions-store.js';
3
+ export * from './events.js';
4
+ export * from './scope.js';
5
+ export * from './threads.js';
6
+ export * from './effects.js';
7
+ export * from './projections.js';
8
+ export * from './module.js';