@swirls/looms 0.0.1 → 0.1.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.
Files changed (257) hide show
  1. package/CHANGELOG.md +53 -0
  2. package/README.md +2 -0
  3. package/dist/actor/cell.d.ts +9 -4
  4. package/dist/actor/cell.js +7 -11
  5. package/dist/actor/host.d.ts +7 -3
  6. package/dist/actor/host.js +55 -32
  7. package/dist/actor/index.d.ts +1 -1
  8. package/dist/actor/index.js +1 -1
  9. package/dist/actor/routing.d.ts +12 -1
  10. package/dist/actor/routing.js +57 -51
  11. package/dist/agent/agent-session.d.ts +5 -0
  12. package/dist/agent/agent-session.js +270 -0
  13. package/dist/agent/definitions-store.d.ts +2 -3
  14. package/dist/agent/definitions-store.js +2 -4
  15. package/dist/agent/definitions.d.ts +46 -20
  16. package/dist/agent/definitions.js +36 -8
  17. package/dist/agent/effects.d.ts +359 -2
  18. package/dist/agent/effects.js +60 -34
  19. package/dist/agent/events.d.ts +175 -19
  20. package/dist/agent/events.js +45 -10
  21. package/dist/agent/index.d.ts +1 -0
  22. package/dist/agent/index.js +1 -0
  23. package/dist/agent/llm.d.ts +11 -2
  24. package/dist/agent/llm.js +13 -3
  25. package/dist/agent/module.d.ts +812 -78
  26. package/dist/agent/module.js +16 -4
  27. package/dist/agent/scope.d.ts +174 -18
  28. package/dist/agent/signals.d.ts +24 -1
  29. package/dist/agent/signals.js +77 -0
  30. package/dist/agent/threads.d.ts +3 -33
  31. package/dist/agent/threads.js +20 -25
  32. package/dist/agent/tool-schema.js +0 -1
  33. package/dist/agent/types.d.ts +49 -4
  34. package/dist/agent/types.js +5 -5
  35. package/dist/ai-vercel/index.d.ts +1 -0
  36. package/dist/ai-vercel/index.js +1 -0
  37. package/dist/ai-vercel/messages.js +22 -7
  38. package/dist/ai-vercel/vercel-evaluator.d.ts +23 -0
  39. package/dist/ai-vercel/vercel-evaluator.js +68 -0
  40. package/dist/ai-vercel/vercel-llm.js +64 -44
  41. package/dist/approval/effects.d.ts +89 -0
  42. package/dist/approval/module.d.ts +179 -29
  43. package/dist/approval/projections.d.ts +0 -14
  44. package/dist/approval/projections.js +20 -3
  45. package/dist/approval/signals.d.ts +2 -0
  46. package/dist/approval/signals.js +18 -2
  47. package/dist/cli/cli.js +2 -0
  48. package/dist/cli/commands.js +12 -16
  49. package/dist/client/client.d.ts +1195 -18
  50. package/dist/client/client.js +118 -120
  51. package/dist/client/index.d.ts +1 -1
  52. package/dist/client/index.js +1 -1
  53. package/dist/client/sse.d.ts +13 -0
  54. package/dist/client/sse.js +38 -44
  55. package/dist/cloudflare/alarm-scheduler.d.ts +12 -2
  56. package/dist/cloudflare/alarm-scheduler.js +34 -7
  57. package/dist/cloudflare/durable-object.d.ts +10 -2
  58. package/dist/cloudflare/durable-object.js +59 -28
  59. package/dist/cloudflare/event-store.d.ts +7 -2
  60. package/dist/cloudflare/event-store.js +8 -7
  61. package/dist/cloudflare/index.d.ts +2 -2
  62. package/dist/cloudflare/index.js +2 -2
  63. package/dist/cloudflare/router.js +13 -14
  64. package/dist/core/catalog.d.ts +3 -3
  65. package/dist/core/catalog.js +2 -5
  66. package/dist/core/coalesce.js +5 -3
  67. package/dist/core/compose.d.ts +2 -1
  68. package/dist/core/compose.js +18 -2
  69. package/dist/core/definition-store.d.ts +11 -0
  70. package/dist/core/definition-store.js +6 -0
  71. package/dist/core/effects.d.ts +127 -15
  72. package/dist/core/effects.js +89 -17
  73. package/dist/core/envelope.d.ts +27 -7
  74. package/dist/core/envelope.js +20 -6
  75. package/dist/core/event-codec.d.ts +4 -2
  76. package/dist/core/event-codec.js +10 -5
  77. package/dist/core/event-index.js +1 -3
  78. package/dist/core/fold.d.ts +3 -0
  79. package/dist/core/fold.js +171 -24
  80. package/dist/core/ids.d.ts +5 -0
  81. package/dist/core/ids.js +35 -2
  82. package/dist/core/index.d.ts +5 -1
  83. package/dist/core/index.js +5 -1
  84. package/dist/core/kind.d.ts +22 -0
  85. package/dist/core/kind.js +17 -0
  86. package/dist/core/limits.d.ts +34 -0
  87. package/dist/core/limits.js +46 -0
  88. package/dist/core/match.d.ts +1 -0
  89. package/dist/core/match.js +10 -1
  90. package/dist/core/module-scope.d.ts +22 -20
  91. package/dist/core/module-scope.js +38 -28
  92. package/dist/core/module.d.ts +16 -5
  93. package/dist/core/module.js +4 -0
  94. package/dist/core/projection.d.ts +13 -13
  95. package/dist/core/projection.js +9 -5
  96. package/dist/core/protocol.d.ts +68 -11
  97. package/dist/core/protocol.js +82 -11
  98. package/dist/core/replay.d.ts +312 -3
  99. package/dist/core/replay.js +11 -1
  100. package/dist/core/schema.d.ts +8 -19
  101. package/dist/core/schema.js +25 -80
  102. package/dist/core/serialize.js +2 -4
  103. package/dist/core/snapshot-store.d.ts +2 -1
  104. package/dist/core/snapshot-store.js +8 -2
  105. package/dist/core/snapshots.d.ts +5 -1
  106. package/dist/core/snapshots.js +10 -15
  107. package/dist/core/sqlite-store.js +56 -11
  108. package/dist/core/state.d.ts +142 -4
  109. package/dist/core/state.js +78 -0
  110. package/dist/core/store.d.ts +38 -3
  111. package/dist/core/store.js +77 -22
  112. package/dist/core/thread.d.ts +10 -9
  113. package/dist/core/types.d.ts +5 -8
  114. package/dist/core/types.js +28 -24
  115. package/dist/core/validate-event.js +14 -4
  116. package/dist/core/worker-callback.d.ts +17 -0
  117. package/dist/core/worker-callback.js +1 -0
  118. package/dist/debugger/components/event-stream.js +9 -10
  119. package/dist/debugger/events/protocol-summarize.js +26 -0
  120. package/dist/debugger/lib/event-meta.js +1 -2
  121. package/dist/evaluator/definitions-store.d.ts +11 -0
  122. package/dist/evaluator/definitions-store.js +8 -0
  123. package/dist/evaluator/definitions.d.ts +18 -0
  124. package/dist/evaluator/definitions.js +4 -0
  125. package/dist/evaluator/effects.d.ts +226 -0
  126. package/dist/evaluator/effects.js +132 -0
  127. package/dist/evaluator/evaluator.d.ts +24 -0
  128. package/dist/evaluator/evaluator.js +67 -0
  129. package/dist/evaluator/events.d.ts +59 -0
  130. package/dist/evaluator/events.js +21 -0
  131. package/dist/evaluator/index.d.ts +11 -0
  132. package/dist/evaluator/index.js +11 -0
  133. package/dist/evaluator/module.d.ts +606 -0
  134. package/dist/evaluator/module.js +25 -0
  135. package/dist/evaluator/projections.d.ts +50 -0
  136. package/dist/evaluator/projections.js +20 -0
  137. package/dist/evaluator/scope.d.ts +59 -0
  138. package/dist/evaluator/scope.js +7 -0
  139. package/dist/evaluator/signals.d.ts +3 -0
  140. package/dist/evaluator/signals.js +17 -0
  141. package/dist/evaluator/threads.d.ts +62 -0
  142. package/dist/evaluator/threads.js +117 -0
  143. package/dist/evaluator/types.d.ts +125 -0
  144. package/dist/evaluator/types.js +51 -0
  145. package/dist/projectors/delivery.d.ts +83 -0
  146. package/dist/projectors/delivery.js +182 -0
  147. package/dist/projectors/index-model.d.ts +1 -1
  148. package/dist/projectors/index-model.js +4 -6
  149. package/dist/projectors/index.d.ts +2 -0
  150. package/dist/projectors/index.js +2 -0
  151. package/dist/projectors/memory.d.ts +1 -1
  152. package/dist/projectors/memory.js +10 -8
  153. package/dist/projectors/postgres.js +44 -58
  154. package/dist/projectors/projector.d.ts +17 -0
  155. package/dist/projectors/projector.js +26 -1
  156. package/dist/projectors/sqlite-delivery.d.ts +4 -0
  157. package/dist/projectors/sqlite-delivery.js +147 -0
  158. package/dist/projectors/sqlite.js +23 -23
  159. package/dist/projectors/with-projectors.d.ts +7 -2
  160. package/dist/projectors/with-projectors.js +27 -28
  161. package/dist/react/notify.js +11 -8
  162. package/dist/react/react.d.ts +2 -3
  163. package/dist/react/react.js +14 -30
  164. package/dist/react/sse.d.ts +1 -1
  165. package/dist/react/sse.js +1 -1
  166. package/dist/react/store.d.ts +2 -2
  167. package/dist/react/store.js +109 -119
  168. package/dist/runtime/cancellation.d.ts +16 -0
  169. package/dist/runtime/cancellation.js +129 -0
  170. package/dist/runtime/deadline-transition-planner.d.ts +31 -0
  171. package/dist/runtime/deadline-transition-planner.js +139 -0
  172. package/dist/runtime/dispatch-effect.d.ts +3 -2
  173. package/dist/runtime/dispatch-effect.js +7 -13
  174. package/dist/runtime/errors.d.ts +51 -0
  175. package/dist/runtime/errors.js +39 -0
  176. package/dist/runtime/{runtime-helpers.d.ts → helpers.d.ts} +24 -4
  177. package/dist/runtime/{runtime-helpers.js → helpers.js} +56 -19
  178. package/dist/runtime/index.d.ts +3 -3
  179. package/dist/runtime/index.js +3 -3
  180. package/dist/runtime/ingress.d.ts +15 -0
  181. package/dist/runtime/ingress.js +42 -0
  182. package/dist/runtime/local-effect-executor.d.ts +21 -0
  183. package/dist/runtime/local-effect-executor.js +137 -0
  184. package/dist/runtime/looms.d.ts +22 -4
  185. package/dist/runtime/looms.js +54 -36
  186. package/dist/runtime/observer.d.ts +45 -0
  187. package/dist/runtime/observer.js +11 -0
  188. package/dist/runtime/repository.d.ts +55 -0
  189. package/dist/runtime/repository.js +278 -0
  190. package/dist/runtime/retry-policy.d.ts +16 -0
  191. package/dist/runtime/retry-policy.js +29 -0
  192. package/dist/runtime/run-execution-context.d.ts +30 -0
  193. package/dist/runtime/run-execution-context.js +56 -0
  194. package/dist/runtime/run-start.d.ts +4 -0
  195. package/dist/runtime/run-start.js +44 -0
  196. package/dist/runtime/runtime.d.ts +6 -87
  197. package/dist/runtime/runtime.js +233 -470
  198. package/dist/runtime/server/auth.d.ts +40 -0
  199. package/dist/runtime/server/auth.js +40 -0
  200. package/dist/runtime/server/fetch-handler.d.ts +14 -0
  201. package/dist/runtime/server/fetch-handler.js +51 -0
  202. package/dist/runtime/server/http.d.ts +37 -0
  203. package/dist/runtime/server/http.js +62 -0
  204. package/dist/runtime/server/route-table.d.ts +55 -0
  205. package/dist/runtime/server/route-table.js +74 -0
  206. package/dist/runtime/server/routes/effects.d.ts +3 -0
  207. package/dist/runtime/server/routes/effects.js +59 -0
  208. package/dist/runtime/server/routes/operations.d.ts +3 -0
  209. package/dist/runtime/server/routes/operations.js +14 -0
  210. package/dist/runtime/server/routes/runs.d.ts +3 -0
  211. package/dist/runtime/server/routes/runs.js +192 -0
  212. package/dist/runtime/server.d.ts +2 -8
  213. package/dist/runtime/server.js +4 -211
  214. package/dist/runtime/sse.d.ts +2 -1
  215. package/dist/runtime/sse.js +24 -17
  216. package/dist/runtime/types.d.ts +115 -0
  217. package/dist/runtime/types.js +1 -0
  218. package/dist/runtime/wake-engine.d.ts +20 -0
  219. package/dist/runtime/wake-engine.js +311 -0
  220. package/dist/runtime/wake-scheduler.d.ts +3 -4
  221. package/dist/runtime/wake-scheduler.js +25 -31
  222. package/dist/runtime/worker-callbacks.d.ts +16 -0
  223. package/dist/runtime/worker-callbacks.js +167 -0
  224. package/dist/runtime/worker-effect-dispatch.d.ts +36 -0
  225. package/dist/runtime/worker-effect-dispatch.js +126 -0
  226. package/dist/s2/config.d.ts +1 -1
  227. package/dist/s2/config.js +1 -1
  228. package/dist/s2/lite.js +70 -82
  229. package/dist/s2/pagination.d.ts +15 -0
  230. package/dist/s2/pagination.js +36 -0
  231. package/dist/s2/projector.js +6 -5
  232. package/dist/s2/snapshot-store.js +148 -163
  233. package/dist/s2/store.d.ts +3 -21
  234. package/dist/s2/store.js +71 -165
  235. package/dist/testing/index.d.ts +15 -0
  236. package/dist/testing/index.js +53 -16
  237. package/dist/workflow/definitions-store.d.ts +2 -3
  238. package/dist/workflow/definitions-store.js +2 -2
  239. package/dist/workflow/definitions.d.ts +78 -22
  240. package/dist/workflow/definitions.js +80 -14
  241. package/dist/workflow/effects.d.ts +359 -13
  242. package/dist/workflow/effects.js +214 -115
  243. package/dist/workflow/events.d.ts +149 -5
  244. package/dist/workflow/events.js +27 -5
  245. package/dist/workflow/graph.d.ts +56 -0
  246. package/dist/workflow/graph.js +207 -0
  247. package/dist/workflow/index.d.ts +1 -0
  248. package/dist/workflow/index.js +1 -0
  249. package/dist/workflow/module.d.ts +1047 -266
  250. package/dist/workflow/projections.d.ts +14 -12
  251. package/dist/workflow/projections.js +30 -8
  252. package/dist/workflow/scope.d.ts +146 -4
  253. package/dist/workflow/threads.d.ts +383 -155
  254. package/dist/workflow/threads.js +308 -110
  255. package/package.json +8 -2
  256. package/dist/runtime/events-api.d.ts +0 -4
  257. package/dist/runtime/events-api.js +0 -84
@@ -1,4 +1,6 @@
1
1
  import { Schema } from 'effect';
2
+ import { DEFAULT_DEFINITION_VERSION } from '@swirls/looms/core';
3
+ import { DEFAULT_GRAPH_CONCURRENCY, getReadyNodeIds, resolveGraphConcurrency, topologicalSort, workflowEdges, } from './graph.js';
2
4
  export const NodeStatusSchema = Schema.Union([
3
5
  Schema.Literal('pending'),
4
6
  Schema.Literal('running'),
@@ -10,23 +12,87 @@ export const NodeStateSchema = Schema.Struct({
10
12
  status: NodeStatusSchema,
11
13
  result: Schema.NullOr(Schema.Json),
12
14
  error: Schema.NullOr(Schema.String),
15
+ attempts: Schema.optional(Schema.Finite),
16
+ branch: Schema.optional(Schema.String),
17
+ /** Policy skips (skip/fallback) still satisfy dependents; inactive skips propagate. */
18
+ skipCause: Schema.optional(Schema.Union([Schema.Literal('inactive'), Schema.Literal('policy')])),
19
+ iteration: Schema.optional(Schema.Struct({ index: Schema.Finite, previous: Schema.Json })),
13
20
  });
21
+ function compatibleNodeStatus(status) {
22
+ switch (status) {
23
+ case 'pending':
24
+ case 'running':
25
+ case 'completed':
26
+ case 'failed':
27
+ case 'skipped':
28
+ return status;
29
+ default:
30
+ return 'pending';
31
+ }
32
+ }
14
33
  export function defineWorkflow(def) {
15
- // SAFETY: factory fields match WorkflowDefinition.
16
- return { kind: 'workflow', ...def, input: def.input };
34
+ const definition = {
35
+ kind: 'workflow',
36
+ ...def,
37
+ version: def.version ?? DEFAULT_DEFINITION_VERSION,
38
+ concurrency: resolveGraphConcurrency(def.concurrency),
39
+ };
40
+ topologicalSort(definition.nodes, workflowEdges(definition));
41
+ for (const node of definition.nodes) {
42
+ const failure = node.failure;
43
+ if (failure?.type === 'retry' &&
44
+ (!Number.isInteger(failure.maxAttempts) ||
45
+ failure.maxAttempts < 1 ||
46
+ failure.maxAttempts > 64)) {
47
+ throw new Error(`Node "${node.id}" retry maxAttempts must be between 1 and 64`);
48
+ }
49
+ if (failure?.type === 'fallback' &&
50
+ !definition.nodes.some((candidate) => candidate.id === failure.nodeId)) {
51
+ throw new Error(`Node "${node.id}" references unknown fallback "${failure.nodeId}"`);
52
+ }
53
+ }
54
+ return definition;
17
55
  }
18
56
  export function readyNodes(workflow, nodeStates) {
19
- return workflow.nodes
20
- .filter((node) => {
57
+ const states = {};
58
+ for (const node of workflow.nodes) {
21
59
  const state = nodeStates[node.id];
22
- if (state && state.status !== 'pending') {
23
- return false;
24
- }
25
- const deps = node.deps ?? [];
26
- return deps.every((depId) => {
27
- const dep = nodeStates[depId];
28
- return dep?.status === 'completed' || dep?.status === 'skipped';
29
- });
30
- })
31
- .map((node) => node.id);
60
+ states[node.id] = {
61
+ status: compatibleNodeStatus(state?.status),
62
+ result: null,
63
+ error: null,
64
+ };
65
+ }
66
+ return getReadyNodeIds(workflow, states);
67
+ }
68
+ function childRef(child) {
69
+ return {
70
+ kind: child.kind,
71
+ name: child.name,
72
+ version: child.version ?? DEFAULT_DEFINITION_VERSION,
73
+ };
74
+ }
75
+ function iterations(child, items, concurrency) {
76
+ return {
77
+ type: 'map',
78
+ ...childRef(child),
79
+ items,
80
+ concurrency: resolveGraphConcurrency(concurrency),
81
+ };
82
+ }
83
+ /** Builds the helpers a node's `run` uses to describe durable work. */
84
+ export function nodeResultBuilders() {
85
+ return {
86
+ spawn: (child, input) => ({ type: 'spawn', ...childRef(child), input }),
87
+ sleep: (ms) => ({ type: 'sleep', ms }),
88
+ effects: (effects) => ({ type: 'effects', effects }),
89
+ map: (child, items) => iterations(child, items, 1),
90
+ fanout: (child, items, concurrency = DEFAULT_GRAPH_CONCURRENCY) => iterations(child, items, concurrency),
91
+ loop: (child, input, { maxIterations }) => {
92
+ if (!Number.isInteger(maxIterations) || maxIterations < 0) {
93
+ throw new Error('loop maxIterations must be a non-negative integer');
94
+ }
95
+ return { type: 'loop', ...childRef(child), input, maxIterations };
96
+ },
97
+ };
32
98
  }
@@ -1,24 +1,114 @@
1
- import { Schema } from 'effect';
1
+ import { Effect, Schema } from 'effect';
2
2
  import { type EventInputOf, type JsonValue } from '@swirls/looms/core';
3
- import { type WorkflowDefinition } from './definitions';
3
+ import { type NodeState, type WorkflowDefinition } from './definitions';
4
4
  import { WorkflowDefinitionsTag } from './definitions-store';
5
5
  import { type WorkflowEvent } from './scope';
6
+ type WorkflowEvents = EventInputOf<WorkflowEvent>[];
6
7
  export declare const scheduleEffect: NoInfer<import("@swirls/looms/core").EffectDefinition<{
7
8
  readonly definitionName?: string | undefined;
9
+ readonly definitionVersion: string;
8
10
  readonly nodes?: {
9
11
  readonly [x: string]: {
10
12
  readonly status: "completed" | "failed" | "pending" | "running" | "skipped";
11
13
  readonly result: Schema.Json;
12
14
  readonly error: string | null;
15
+ readonly attempts?: number | undefined;
16
+ readonly branch?: string | undefined;
17
+ readonly skipCause?: "inactive" | "policy" | undefined;
18
+ readonly iteration?: {
19
+ readonly index: number;
20
+ readonly previous: Schema.Json;
21
+ } | undefined;
13
22
  };
14
23
  } | undefined;
15
24
  readonly input?: Schema.Json | undefined;
16
25
  }, WorkflowDefinitionsTag, (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
26
+ readonly type: "runtime.effect.ambiguous";
27
+ readonly payload: {
28
+ readonly effectId: string;
29
+ readonly attempt: number;
30
+ readonly error: string;
31
+ };
32
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
33
+ readonly type: "runtime.effect.attempt.started";
34
+ readonly payload: {
35
+ readonly effectId: string;
36
+ readonly attempt: number;
37
+ };
38
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
39
+ readonly type: "runtime.effect.cancel.requested";
40
+ readonly payload: {
41
+ readonly effectId: string;
42
+ readonly attempt: number;
43
+ readonly deadlineAt: number | null;
44
+ };
45
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
46
+ readonly type: "runtime.effect.cancelled";
47
+ readonly payload: {
48
+ readonly effectId: string;
49
+ readonly attempt: number;
50
+ };
51
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
52
+ readonly type: "runtime.effect.completed";
53
+ readonly payload: {
54
+ readonly effectId: string;
55
+ readonly attempt: number;
56
+ };
57
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
58
+ readonly type: "runtime.effect.dispatched";
59
+ readonly payload: {
60
+ readonly effectId: string;
61
+ readonly attempt: number;
62
+ readonly deadlineAt: number | null;
63
+ };
64
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
17
65
  readonly type: "runtime.effect.failed";
18
66
  readonly payload: {
19
67
  readonly effectId: string;
20
68
  readonly error: string;
21
69
  };
70
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
71
+ readonly type: "runtime.effect.heartbeat";
72
+ readonly payload: {
73
+ readonly effectId: string;
74
+ readonly attempt: number;
75
+ readonly heartbeatAt: number;
76
+ readonly deadlineAt: number | null;
77
+ };
78
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
79
+ readonly type: "runtime.effect.queued";
80
+ readonly payload: {
81
+ readonly effectId: string;
82
+ readonly attempt: number;
83
+ readonly deadlineAt: number | null;
84
+ };
85
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
86
+ readonly type: "runtime.effect.retry.scheduled";
87
+ readonly payload: {
88
+ readonly effectId: string;
89
+ readonly attempt: number;
90
+ readonly nextAttemptAt: number;
91
+ readonly error: string;
92
+ };
93
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
94
+ readonly type: "runtime.effect.timed_out";
95
+ readonly payload: {
96
+ readonly effectId: string;
97
+ readonly attempt: number;
98
+ readonly timeout: string;
99
+ };
100
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
101
+ readonly type: "runtime.effect.worker.started";
102
+ readonly payload: {
103
+ readonly effectId: string;
104
+ readonly attempt: number;
105
+ readonly deadlineAt: number | null;
106
+ };
107
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
108
+ readonly type: "runtime.run.cancelled";
109
+ readonly payload: {
110
+ readonly reason?: string | undefined;
111
+ };
22
112
  }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
23
113
  readonly type: "runtime.run.completed";
24
114
  readonly payload: {
@@ -31,7 +121,9 @@ export declare const scheduleEffect: NoInfer<import("@swirls/looms/core").Effect
31
121
  readonly rootThreadId?: string | undefined;
32
122
  readonly kind: string;
33
123
  readonly definitionName: string;
124
+ readonly definitionVersion: string;
34
125
  readonly input: Schema.Json;
126
+ readonly requestedThreadId?: string | null | undefined;
35
127
  };
36
128
  }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
37
129
  readonly type: "runtime.signal.received";
@@ -45,6 +137,11 @@ export declare const scheduleEffect: NoInfer<import("@swirls/looms/core").Effect
45
137
  readonly stateHash: string;
46
138
  readonly state?: Schema.Json | undefined;
47
139
  };
140
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
141
+ readonly type: "runtime.thread.cancel.requested";
142
+ readonly payload: {
143
+ readonly threadId: string;
144
+ };
48
145
  }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
49
146
  readonly type: "runtime.thread.cancelled";
50
147
  readonly payload: {
@@ -69,6 +166,7 @@ export declare const scheduleEffect: NoInfer<import("@swirls/looms/core").Effect
69
166
  readonly threadId: string;
70
167
  readonly kind: string;
71
168
  readonly definitionName: string;
169
+ readonly definitionVersion: string;
72
170
  readonly input: Schema.Json;
73
171
  readonly parentThreadId: string | null;
74
172
  };
@@ -113,7 +211,75 @@ export declare const scheduleEffect: NoInfer<import("@swirls/looms/core").Effect
113
211
  readonly type: "workflow.effects.requested";
114
212
  readonly payload: {
115
213
  readonly nodeId: string;
116
- readonly effects: readonly import("@swirls/looms/core").RuntimeEffect[];
214
+ readonly effects: readonly ({
215
+ readonly type: "runtime.spawn";
216
+ readonly childThreadId: string;
217
+ readonly kind: string;
218
+ readonly definitionName: string;
219
+ readonly definitionVersion: string;
220
+ readonly input: Schema.Json;
221
+ } | {
222
+ readonly type: "runtime.wait";
223
+ readonly waitId: string;
224
+ readonly on: {
225
+ readonly type: string | readonly string[];
226
+ readonly match?: Schema.Json | undefined;
227
+ } | {
228
+ readonly timerAt: number;
229
+ };
230
+ readonly tag?: Schema.Json | undefined;
231
+ } | {
232
+ readonly type: "runtime.emit";
233
+ readonly event: {
234
+ readonly type: string;
235
+ readonly payload: Schema.Json;
236
+ readonly threadId?: string | null | undefined;
237
+ readonly parentThreadId?: string | null | undefined;
238
+ readonly causationId?: string | null | undefined;
239
+ readonly correlationId?: string | null | undefined;
240
+ readonly effectId?: string | null | undefined;
241
+ readonly origin?: {
242
+ readonly type: "thread";
243
+ readonly threadId: string;
244
+ } | {
245
+ readonly type: "external";
246
+ readonly actorId?: string | undefined;
247
+ } | {
248
+ readonly type: "system";
249
+ } | undefined;
250
+ readonly ephemeral?: boolean | undefined;
251
+ readonly id?: string | undefined;
252
+ readonly ts?: number | undefined;
253
+ readonly idempotencyKey?: string | null | undefined;
254
+ };
255
+ readonly tag?: string | undefined;
256
+ } | {
257
+ readonly type: "runtime.complete";
258
+ readonly output: Schema.Json;
259
+ } | {
260
+ readonly type: "runtime.fail";
261
+ readonly error: string;
262
+ } | {
263
+ readonly type: "runtime.cancel";
264
+ readonly threadId: string;
265
+ readonly tag?: string | undefined;
266
+ } | {
267
+ readonly type: string;
268
+ readonly input: Schema.Json;
269
+ readonly tag?: string | undefined;
270
+ })[];
271
+ };
272
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
273
+ readonly type: "workflow.map.requested";
274
+ readonly payload: {
275
+ readonly nodeId: string;
276
+ readonly attempt: number;
277
+ readonly kind: string;
278
+ readonly definitionName: string;
279
+ readonly definitionVersion: string;
280
+ readonly items: readonly Schema.Json[];
281
+ readonly concurrency: number;
282
+ readonly limitBytes: number;
117
283
  };
118
284
  }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
119
285
  readonly type: "workflow.node.finished";
@@ -121,12 +287,14 @@ export declare const scheduleEffect: NoInfer<import("@swirls/looms/core").Effect
121
287
  readonly nodeId: string;
122
288
  readonly result: Schema.Json;
123
289
  readonly error: string | null;
290
+ readonly branch?: string | undefined;
124
291
  };
125
292
  }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
126
293
  readonly type: "workflow.node.skipped";
127
294
  readonly payload: {
128
295
  readonly nodeId: string;
129
296
  readonly reason: string;
297
+ readonly cause: "inactive" | "policy";
130
298
  };
131
299
  }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
132
300
  readonly type: "workflow.node.started";
@@ -144,34 +312,130 @@ export declare const scheduleEffect: NoInfer<import("@swirls/looms/core").Effect
144
312
  readonly type: "workflow.spawn.requested";
145
313
  readonly payload: {
146
314
  readonly nodeId: string;
315
+ readonly attempt: number;
147
316
  readonly childThreadId: string;
148
317
  readonly kind: string;
149
318
  readonly definitionName: string;
319
+ readonly definitionVersion: string;
150
320
  readonly input: Schema.Json;
321
+ readonly loopIndex: number | null;
151
322
  };
152
323
  })>>;
153
324
  export declare function scheduleEvents(definition: WorkflowDefinition, binding: {
154
- nodes: {
155
- [id: string]: {
156
- status: string;
157
- result: JsonValue | null;
158
- };
159
- };
325
+ nodes: Record<string, NodeState>;
160
326
  input: JsonValue;
161
- }, threadId: string): EventInputOf<WorkflowEvent>[];
327
+ }, threadId: string): Effect.Effect<WorkflowEvents>;
162
328
  export declare const runNodeEffect: NoInfer<import("@swirls/looms/core").EffectDefinition<{
163
329
  readonly definitionName?: string | undefined;
330
+ readonly definitionVersion: string;
164
331
  readonly nodeId: string;
332
+ readonly attempt: number;
333
+ readonly iteration?: {
334
+ readonly index: number;
335
+ readonly previous: Schema.Json;
336
+ } | undefined;
165
337
  readonly input?: Schema.Json | undefined;
166
- readonly results?: {
167
- readonly [x: string]: Schema.Json;
338
+ readonly nodes?: {
339
+ readonly [x: string]: {
340
+ readonly status: "completed" | "failed" | "pending" | "running" | "skipped";
341
+ readonly result: Schema.Json;
342
+ readonly error: string | null;
343
+ readonly attempts?: number | undefined;
344
+ readonly branch?: string | undefined;
345
+ readonly skipCause?: "inactive" | "policy" | undefined;
346
+ readonly iteration?: {
347
+ readonly index: number;
348
+ readonly previous: Schema.Json;
349
+ } | undefined;
350
+ };
168
351
  } | undefined;
169
352
  }, WorkflowDefinitionsTag, (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
353
+ readonly type: "runtime.effect.ambiguous";
354
+ readonly payload: {
355
+ readonly effectId: string;
356
+ readonly attempt: number;
357
+ readonly error: string;
358
+ };
359
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
360
+ readonly type: "runtime.effect.attempt.started";
361
+ readonly payload: {
362
+ readonly effectId: string;
363
+ readonly attempt: number;
364
+ };
365
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
366
+ readonly type: "runtime.effect.cancel.requested";
367
+ readonly payload: {
368
+ readonly effectId: string;
369
+ readonly attempt: number;
370
+ readonly deadlineAt: number | null;
371
+ };
372
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
373
+ readonly type: "runtime.effect.cancelled";
374
+ readonly payload: {
375
+ readonly effectId: string;
376
+ readonly attempt: number;
377
+ };
378
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
379
+ readonly type: "runtime.effect.completed";
380
+ readonly payload: {
381
+ readonly effectId: string;
382
+ readonly attempt: number;
383
+ };
384
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
385
+ readonly type: "runtime.effect.dispatched";
386
+ readonly payload: {
387
+ readonly effectId: string;
388
+ readonly attempt: number;
389
+ readonly deadlineAt: number | null;
390
+ };
391
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
170
392
  readonly type: "runtime.effect.failed";
171
393
  readonly payload: {
172
394
  readonly effectId: string;
173
395
  readonly error: string;
174
396
  };
397
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
398
+ readonly type: "runtime.effect.heartbeat";
399
+ readonly payload: {
400
+ readonly effectId: string;
401
+ readonly attempt: number;
402
+ readonly heartbeatAt: number;
403
+ readonly deadlineAt: number | null;
404
+ };
405
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
406
+ readonly type: "runtime.effect.queued";
407
+ readonly payload: {
408
+ readonly effectId: string;
409
+ readonly attempt: number;
410
+ readonly deadlineAt: number | null;
411
+ };
412
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
413
+ readonly type: "runtime.effect.retry.scheduled";
414
+ readonly payload: {
415
+ readonly effectId: string;
416
+ readonly attempt: number;
417
+ readonly nextAttemptAt: number;
418
+ readonly error: string;
419
+ };
420
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
421
+ readonly type: "runtime.effect.timed_out";
422
+ readonly payload: {
423
+ readonly effectId: string;
424
+ readonly attempt: number;
425
+ readonly timeout: string;
426
+ };
427
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
428
+ readonly type: "runtime.effect.worker.started";
429
+ readonly payload: {
430
+ readonly effectId: string;
431
+ readonly attempt: number;
432
+ readonly deadlineAt: number | null;
433
+ };
434
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
435
+ readonly type: "runtime.run.cancelled";
436
+ readonly payload: {
437
+ readonly reason?: string | undefined;
438
+ };
175
439
  }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
176
440
  readonly type: "runtime.run.completed";
177
441
  readonly payload: {
@@ -184,7 +448,9 @@ export declare const runNodeEffect: NoInfer<import("@swirls/looms/core").EffectD
184
448
  readonly rootThreadId?: string | undefined;
185
449
  readonly kind: string;
186
450
  readonly definitionName: string;
451
+ readonly definitionVersion: string;
187
452
  readonly input: Schema.Json;
453
+ readonly requestedThreadId?: string | null | undefined;
188
454
  };
189
455
  }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
190
456
  readonly type: "runtime.signal.received";
@@ -198,6 +464,11 @@ export declare const runNodeEffect: NoInfer<import("@swirls/looms/core").EffectD
198
464
  readonly stateHash: string;
199
465
  readonly state?: Schema.Json | undefined;
200
466
  };
467
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
468
+ readonly type: "runtime.thread.cancel.requested";
469
+ readonly payload: {
470
+ readonly threadId: string;
471
+ };
201
472
  }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
202
473
  readonly type: "runtime.thread.cancelled";
203
474
  readonly payload: {
@@ -222,6 +493,7 @@ export declare const runNodeEffect: NoInfer<import("@swirls/looms/core").EffectD
222
493
  readonly threadId: string;
223
494
  readonly kind: string;
224
495
  readonly definitionName: string;
496
+ readonly definitionVersion: string;
225
497
  readonly input: Schema.Json;
226
498
  readonly parentThreadId: string | null;
227
499
  };
@@ -266,7 +538,75 @@ export declare const runNodeEffect: NoInfer<import("@swirls/looms/core").EffectD
266
538
  readonly type: "workflow.effects.requested";
267
539
  readonly payload: {
268
540
  readonly nodeId: string;
269
- readonly effects: readonly import("@swirls/looms/core").RuntimeEffect[];
541
+ readonly effects: readonly ({
542
+ readonly type: "runtime.spawn";
543
+ readonly childThreadId: string;
544
+ readonly kind: string;
545
+ readonly definitionName: string;
546
+ readonly definitionVersion: string;
547
+ readonly input: Schema.Json;
548
+ } | {
549
+ readonly type: "runtime.wait";
550
+ readonly waitId: string;
551
+ readonly on: {
552
+ readonly type: string | readonly string[];
553
+ readonly match?: Schema.Json | undefined;
554
+ } | {
555
+ readonly timerAt: number;
556
+ };
557
+ readonly tag?: Schema.Json | undefined;
558
+ } | {
559
+ readonly type: "runtime.emit";
560
+ readonly event: {
561
+ readonly type: string;
562
+ readonly payload: Schema.Json;
563
+ readonly threadId?: string | null | undefined;
564
+ readonly parentThreadId?: string | null | undefined;
565
+ readonly causationId?: string | null | undefined;
566
+ readonly correlationId?: string | null | undefined;
567
+ readonly effectId?: string | null | undefined;
568
+ readonly origin?: {
569
+ readonly type: "thread";
570
+ readonly threadId: string;
571
+ } | {
572
+ readonly type: "external";
573
+ readonly actorId?: string | undefined;
574
+ } | {
575
+ readonly type: "system";
576
+ } | undefined;
577
+ readonly ephemeral?: boolean | undefined;
578
+ readonly id?: string | undefined;
579
+ readonly ts?: number | undefined;
580
+ readonly idempotencyKey?: string | null | undefined;
581
+ };
582
+ readonly tag?: string | undefined;
583
+ } | {
584
+ readonly type: "runtime.complete";
585
+ readonly output: Schema.Json;
586
+ } | {
587
+ readonly type: "runtime.fail";
588
+ readonly error: string;
589
+ } | {
590
+ readonly type: "runtime.cancel";
591
+ readonly threadId: string;
592
+ readonly tag?: string | undefined;
593
+ } | {
594
+ readonly type: string;
595
+ readonly input: Schema.Json;
596
+ readonly tag?: string | undefined;
597
+ })[];
598
+ };
599
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
600
+ readonly type: "workflow.map.requested";
601
+ readonly payload: {
602
+ readonly nodeId: string;
603
+ readonly attempt: number;
604
+ readonly kind: string;
605
+ readonly definitionName: string;
606
+ readonly definitionVersion: string;
607
+ readonly items: readonly Schema.Json[];
608
+ readonly concurrency: number;
609
+ readonly limitBytes: number;
270
610
  };
271
611
  }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
272
612
  readonly type: "workflow.node.finished";
@@ -274,12 +614,14 @@ export declare const runNodeEffect: NoInfer<import("@swirls/looms/core").EffectD
274
614
  readonly nodeId: string;
275
615
  readonly result: Schema.Json;
276
616
  readonly error: string | null;
617
+ readonly branch?: string | undefined;
277
618
  };
278
619
  }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
279
620
  readonly type: "workflow.node.skipped";
280
621
  readonly payload: {
281
622
  readonly nodeId: string;
282
623
  readonly reason: string;
624
+ readonly cause: "inactive" | "policy";
283
625
  };
284
626
  }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
285
627
  readonly type: "workflow.node.started";
@@ -297,9 +639,13 @@ export declare const runNodeEffect: NoInfer<import("@swirls/looms/core").EffectD
297
639
  readonly type: "workflow.spawn.requested";
298
640
  readonly payload: {
299
641
  readonly nodeId: string;
642
+ readonly attempt: number;
300
643
  readonly childThreadId: string;
301
644
  readonly kind: string;
302
645
  readonly definitionName: string;
646
+ readonly definitionVersion: string;
303
647
  readonly input: Schema.Json;
648
+ readonly loopIndex: number | null;
304
649
  };
305
650
  })>>;
651
+ export {};