@swirls/looms 0.4.0 → 0.5.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 (241) hide show
  1. package/CHANGELOG.md +55 -0
  2. package/dist/actor/cell.d.ts +21 -2
  3. package/dist/actor/cell.js +15 -3
  4. package/dist/actor/host.d.ts +10 -2
  5. package/dist/actor/host.js +27 -4
  6. package/dist/actor/index.d.ts +2 -1
  7. package/dist/actor/index.js +1 -1
  8. package/dist/actor/routing.d.ts +3 -0
  9. package/dist/actor/routing.js +13 -2
  10. package/dist/agent/definitions-store.d.ts +1 -1
  11. package/dist/agent/definitions-store.js +1 -1
  12. package/dist/agent/definitions.d.ts +48 -0
  13. package/dist/agent/definitions.js +44 -0
  14. package/dist/agent/effects.d.ts +184 -0
  15. package/dist/agent/effects.js +172 -40
  16. package/dist/agent/events.d.ts +89 -0
  17. package/dist/agent/events.js +25 -0
  18. package/dist/agent/module.d.ts +412 -0
  19. package/dist/agent/module.js +5 -1
  20. package/dist/agent/scope.d.ts +88 -0
  21. package/dist/agent/threads.js +39 -3
  22. package/dist/agent/types.d.ts +4 -0
  23. package/dist/approval/effects.d.ts +40 -0
  24. package/dist/approval/module.d.ts +80 -0
  25. package/dist/client/client.d.ts +468 -119
  26. package/dist/client/client.js +214 -21
  27. package/dist/client/index.d.ts +1 -1
  28. package/dist/client/sse.d.ts +1 -1
  29. package/dist/client/sse.js +2 -2
  30. package/dist/cloudflare/durable-object.d.ts +66 -2
  31. package/dist/cloudflare/durable-object.js +96 -1
  32. package/dist/cloudflare/event-store.d.ts +7 -3
  33. package/dist/cloudflare/event-store.js +16 -3
  34. package/dist/cloudflare/index.d.ts +7 -1
  35. package/dist/cloudflare/index.js +7 -1
  36. package/dist/cloudflare/memory-queue.d.ts +18 -0
  37. package/dist/cloudflare/memory-queue.js +53 -0
  38. package/dist/cloudflare/queue-consumer.d.ts +52 -0
  39. package/dist/cloudflare/queue-consumer.js +102 -0
  40. package/dist/cloudflare/queue-message.d.ts +31 -0
  41. package/dist/cloudflare/queue-message.js +33 -0
  42. package/dist/cloudflare/queue-pull.d.ts +62 -0
  43. package/dist/cloudflare/queue-pull.js +130 -0
  44. package/dist/cloudflare/queue-worker.d.ts +39 -0
  45. package/dist/cloudflare/queue-worker.js +62 -0
  46. package/dist/cloudflare/r2-blob-store.d.ts +33 -0
  47. package/dist/cloudflare/r2-blob-store.js +60 -0
  48. package/dist/cloudflare/router.d.ts +4 -1
  49. package/dist/cloudflare/router.js +8 -3
  50. package/dist/cloudflare/websocket.d.ts +27 -0
  51. package/dist/cloudflare/websocket.js +215 -0
  52. package/dist/core/blob-offload.d.ts +21 -0
  53. package/dist/core/blob-offload.js +143 -0
  54. package/dist/core/blob-store.d.ts +45 -0
  55. package/dist/core/blob-store.js +164 -0
  56. package/dist/core/blobs.d.ts +37 -0
  57. package/dist/core/blobs.js +160 -0
  58. package/dist/core/definition-resolver.d.ts +40 -0
  59. package/dist/core/definition-resolver.js +129 -0
  60. package/dist/core/definition-store.d.ts +6 -0
  61. package/dist/core/definition-store.js +37 -1
  62. package/dist/core/effects.d.ts +86 -3
  63. package/dist/core/effects.js +99 -3
  64. package/dist/core/envelope.d.ts +9 -0
  65. package/dist/core/envelope.js +4 -0
  66. package/dist/core/event-codec.js +3 -0
  67. package/dist/core/fold.js +83 -1
  68. package/dist/core/ids.d.ts +2 -0
  69. package/dist/core/ids.js +4 -0
  70. package/dist/core/index.d.ts +8 -0
  71. package/dist/core/index.js +8 -0
  72. package/dist/core/launcher.d.ts +97 -0
  73. package/dist/core/launcher.js +67 -0
  74. package/dist/core/module-scope.d.ts +7 -3
  75. package/dist/core/module-scope.js +3 -0
  76. package/dist/core/module.d.ts +10 -0
  77. package/dist/core/projection.js +4 -0
  78. package/dist/core/protocol.d.ts +36 -1
  79. package/dist/core/protocol.js +35 -0
  80. package/dist/core/published.d.ts +2 -0
  81. package/dist/core/published.js +4 -1
  82. package/dist/core/replay.d.ts +96 -0
  83. package/dist/core/run-context.d.ts +33 -0
  84. package/dist/core/run-context.js +23 -0
  85. package/dist/core/sqlite-store.js +57 -5
  86. package/dist/core/state.d.ts +60 -0
  87. package/dist/core/state.js +19 -0
  88. package/dist/core/store.d.ts +6 -0
  89. package/dist/core/store.js +7 -0
  90. package/dist/core/subscription.d.ts +97 -0
  91. package/dist/core/subscription.js +224 -0
  92. package/dist/core/thread.d.ts +7 -0
  93. package/dist/core/thread.js +1 -0
  94. package/dist/core/trace.d.ts +21 -0
  95. package/dist/core/trace.js +45 -0
  96. package/dist/core/worker-callback.d.ts +25 -1
  97. package/dist/debugger/app/assets/{index-CgDzWJg7.css → index-B7GdT1UA.css} +1 -1
  98. package/dist/debugger/app/assets/index-C31SnCuN.js +22 -0
  99. package/dist/debugger/app/assets/routes-DPA3O5AF.js +47 -0
  100. package/dist/debugger/app/index.html +2 -2
  101. package/dist/debugger/components/event-inspector.d.ts +3 -1
  102. package/dist/debugger/components/event-inspector.js +25 -4
  103. package/dist/debugger/components/event-stream.d.ts +4 -1
  104. package/dist/debugger/components/event-stream.js +2 -2
  105. package/dist/debugger/components/run-tree.d.ts +5 -2
  106. package/dist/debugger/components/run-tree.js +10 -4
  107. package/dist/debugger/context.d.ts +8 -1
  108. package/dist/debugger/context.js +15 -3
  109. package/dist/debugger/events/protocol-summarize.js +18 -3
  110. package/dist/debugger/index.d.ts +1 -1
  111. package/dist/debugger/index.js +1 -1
  112. package/dist/debugger/shell/debugger-shell.js +1 -1
  113. package/dist/debugger/shell/events-pane.js +4 -3
  114. package/dist/debugger/styles.css +1 -0
  115. package/dist/evaluator/definitions-store.d.ts +3 -4
  116. package/dist/evaluator/definitions-store.js +3 -3
  117. package/dist/evaluator/definitions.d.ts +4 -1
  118. package/dist/evaluator/definitions.js +5 -2
  119. package/dist/evaluator/effects.d.ts +74 -33
  120. package/dist/evaluator/effects.js +6 -2
  121. package/dist/evaluator/module.d.ts +150 -66
  122. package/dist/evaluator/module.js +7 -3
  123. package/dist/evaluator/threads.d.ts +2 -0
  124. package/dist/evaluator/threads.js +4 -0
  125. package/dist/projectors/event-log.d.ts +87 -0
  126. package/dist/projectors/event-log.js +396 -0
  127. package/dist/projectors/index-model.d.ts +12 -0
  128. package/dist/projectors/index-model.js +12 -3
  129. package/dist/projectors/memory.js +7 -0
  130. package/dist/projectors/postgres.d.ts +1 -0
  131. package/dist/projectors/postgres.js +32 -15
  132. package/dist/projectors/schema.d.ts +5 -0
  133. package/dist/projectors/schema.js +26 -1
  134. package/dist/projectors/sqlite.js +47 -19
  135. package/dist/projectors/with-projectors.d.ts +7 -1
  136. package/dist/projectors/with-projectors.js +13 -3
  137. package/dist/react/materialize.js +5 -1
  138. package/dist/react/react.d.ts +10 -2
  139. package/dist/react/react.js +43 -19
  140. package/dist/react/store.d.ts +11 -2
  141. package/dist/react/store.js +104 -12
  142. package/dist/react/tables.d.ts +4 -1
  143. package/dist/runtime/cancellation.d.ts +2 -1
  144. package/dist/runtime/cancellation.js +35 -2
  145. package/dist/runtime/child-run.d.ts +10 -0
  146. package/dist/runtime/child-run.js +58 -0
  147. package/dist/runtime/deadline-transition-planner.js +11 -2
  148. package/dist/runtime/dispatch-effect.d.ts +2 -2
  149. package/dist/runtime/dispatch-effect.js +43 -19
  150. package/dist/runtime/errors.d.ts +14 -1
  151. package/dist/runtime/errors.js +10 -0
  152. package/dist/runtime/filesystem-blob-store.d.ts +6 -0
  153. package/dist/runtime/filesystem-blob-store.js +59 -0
  154. package/dist/runtime/helpers.d.ts +15 -6
  155. package/dist/runtime/helpers.js +46 -6
  156. package/dist/runtime/index.d.ts +4 -2
  157. package/dist/runtime/index.js +3 -1
  158. package/dist/runtime/local-effect-executor.d.ts +11 -2
  159. package/dist/runtime/local-effect-executor.js +80 -4
  160. package/dist/runtime/looms.d.ts +38 -4
  161. package/dist/runtime/looms.js +17 -3
  162. package/dist/runtime/repository.d.ts +5 -4
  163. package/dist/runtime/repository.js +5 -2
  164. package/dist/runtime/retry-policy.d.ts +5 -0
  165. package/dist/runtime/retry-policy.js +10 -2
  166. package/dist/runtime/run-start.d.ts +1 -1
  167. package/dist/runtime/run-start.js +10 -0
  168. package/dist/runtime/runtime.d.ts +2 -2
  169. package/dist/runtime/runtime.js +191 -68
  170. package/dist/runtime/server/auth.d.ts +3 -0
  171. package/dist/runtime/server/fetch-handler.d.ts +2 -2
  172. package/dist/runtime/server/fetch-handler.js +35 -4
  173. package/dist/runtime/server/grant.d.ts +49 -0
  174. package/dist/runtime/server/grant.js +177 -0
  175. package/dist/runtime/server/routes/effects.js +47 -5
  176. package/dist/runtime/server/routes/runs.js +6 -1
  177. package/dist/runtime/server/run-route.d.ts +18 -0
  178. package/dist/runtime/server/run-route.js +26 -0
  179. package/dist/runtime/server.d.ts +3 -1
  180. package/dist/runtime/server.js +3 -1
  181. package/dist/runtime/sse.js +26 -4
  182. package/dist/runtime/subscription.d.ts +8 -0
  183. package/dist/runtime/subscription.js +23 -0
  184. package/dist/runtime/types.d.ts +87 -8
  185. package/dist/runtime/wake-engine.d.ts +4 -2
  186. package/dist/runtime/wake-engine.js +57 -6
  187. package/dist/runtime/worker-callbacks.d.ts +12 -2
  188. package/dist/runtime/worker-callbacks.js +102 -72
  189. package/dist/runtime/worker-effect-dispatch.d.ts +14 -5
  190. package/dist/runtime/worker-effect-dispatch.js +84 -18
  191. package/dist/schedule/debugger/index.d.ts +4 -0
  192. package/dist/schedule/debugger/index.js +11 -0
  193. package/dist/schedule/debugger/schedule-view.d.ts +3 -0
  194. package/dist/schedule/debugger/schedule-view.js +68 -0
  195. package/dist/schedule/debugger/summarize.d.ts +2 -0
  196. package/dist/schedule/debugger/summarize.js +43 -0
  197. package/dist/schedule/definitions-store.d.ts +10 -0
  198. package/dist/schedule/definitions-store.js +8 -0
  199. package/dist/schedule/definitions.d.ts +57 -0
  200. package/dist/schedule/definitions.js +30 -0
  201. package/dist/schedule/effects.d.ts +756 -0
  202. package/dist/schedule/effects.js +244 -0
  203. package/dist/schedule/ensure.d.ts +55 -0
  204. package/dist/schedule/ensure.js +109 -0
  205. package/dist/schedule/events.d.ts +116 -0
  206. package/dist/schedule/events.js +49 -0
  207. package/dist/schedule/index.d.ts +11 -0
  208. package/dist/schedule/index.js +11 -0
  209. package/dist/schedule/module.d.ts +1474 -0
  210. package/dist/schedule/module.js +22 -0
  211. package/dist/schedule/projections.d.ts +55 -0
  212. package/dist/schedule/projections.js +88 -0
  213. package/dist/schedule/scope.d.ts +121 -0
  214. package/dist/schedule/scope.js +7 -0
  215. package/dist/schedule/signals.d.ts +25 -0
  216. package/dist/schedule/signals.js +33 -0
  217. package/dist/schedule/specs.d.ts +59 -0
  218. package/dist/schedule/specs.js +231 -0
  219. package/dist/schedule/threads.d.ts +25 -0
  220. package/dist/schedule/threads.js +259 -0
  221. package/dist/testing/corpus-module.d.ts +34 -0
  222. package/dist/testing/corpus-module.js +87 -0
  223. package/dist/testing/index.d.ts +2 -0
  224. package/dist/testing/index.js +5 -6
  225. package/dist/testing/replay-corpus.d.ts +22 -0
  226. package/dist/testing/replay-corpus.js +50 -0
  227. package/dist/workflow/definitions-store.d.ts +1 -1
  228. package/dist/workflow/definitions-store.js +1 -1
  229. package/dist/workflow/definitions.d.ts +14 -0
  230. package/dist/workflow/effects.d.ts +122 -0
  231. package/dist/workflow/effects.js +16 -6
  232. package/dist/workflow/events.d.ts +42 -0
  233. package/dist/workflow/events.js +4 -0
  234. package/dist/workflow/module.d.ts +345 -32
  235. package/dist/workflow/module.js +7 -3
  236. package/dist/workflow/scope.d.ts +42 -0
  237. package/dist/workflow/threads.d.ts +72 -0
  238. package/dist/workflow/threads.js +106 -38
  239. package/package.json +10 -1
  240. package/dist/debugger/app/assets/index-D--9esm9.js +0 -22
  241. package/dist/debugger/app/assets/routes-Dakrdusf.js +0 -47
@@ -9,7 +9,7 @@ import { agentModule } from './scope.js';
9
9
  import { agentThread } from './threads.js';
10
10
  export function agent(options = {}) {
11
11
  const definitions = options.definitions ?? [];
12
- const agentDefinitions = definitions.filter((definition) => definition.kind === 'agent');
12
+ const agentDefinitions = makeDefinitionStore('agent', definitions.filter((definition) => definition.kind === 'agent'));
13
13
  const sessionDefinitions = makeDefinitionStore('agent-session', definitions.filter((definition) => definition.kind === 'agent-session'));
14
14
  const llmLayer = options.llm
15
15
  ? Layer.succeed(LlmTag, llmFromAdapter(options.llm))
@@ -31,6 +31,10 @@ export function agent(options = {}) {
31
31
  },
32
32
  services: () => Layer.merge(llmLayer, AgentDefinitionsLive(agentDefinitions)),
33
33
  interruptsOnSignal,
34
+ bindHost(host) {
35
+ agentDefinitions.useResolver(host.definitionResolver);
36
+ sessionDefinitions.useResolver(host.definitionResolver);
37
+ },
34
38
  }));
35
39
  }
36
40
  /** A stop or an interrupting steer abandons the turn in progress on its thread. */
@@ -97,6 +97,7 @@ export declare const agentModule: import("@swirls/looms/core").ModuleScope<"agen
97
97
  readonly definitionVersion: import("effect/Schema").withDecodingDefaultKey<import("effect/Schema").String, never>;
98
98
  readonly toolCallId: import("effect/Schema").String;
99
99
  readonly input: import("effect/Schema").Codec<import("effect/Schema").Json, import("effect/Schema").Json, never, never>;
100
+ readonly depth: import("effect/Schema").optional<import("effect/Schema").Finite>;
100
101
  }>;
101
102
  'effects.requested': import("effect/Schema").Struct<{
102
103
  readonly toolCallId: import("effect/Schema").String;
@@ -135,6 +136,9 @@ export declare const agentModule: import("@swirls/looms/core").ModuleScope<"agen
135
136
  readonly actorId: import("effect/Schema").optional<import("effect/Schema").String>;
136
137
  }>, import("effect/Schema").Struct<{
137
138
  readonly type: import("effect/Schema").Literal<"system">;
139
+ }>, import("effect/Schema").Struct<{
140
+ readonly type: import("effect/Schema").Literal<"run">;
141
+ readonly runId: import("effect/Schema").String;
138
142
  }>]>>;
139
143
  readonly ephemeral: import("effect/Schema").optional<import("effect/Schema").Boolean>;
140
144
  readonly id: import("effect/Schema").optional<import("effect/Schema").String>;
@@ -152,16 +156,56 @@ export declare const agentModule: import("@swirls/looms/core").ModuleScope<"agen
152
156
  readonly type: import("effect/Schema").Literal<"runtime.cancel">;
153
157
  readonly threadId: import("effect/Schema").String;
154
158
  readonly tag: import("effect/Schema").optional<import("effect/Schema").String>;
159
+ }>, import("effect/Schema").Struct<{
160
+ readonly type: import("effect/Schema").Literal<"runtime.launch">;
161
+ readonly runId: import("effect/Schema").String;
162
+ readonly kind: import("effect/Schema").String;
163
+ readonly definitionName: import("effect/Schema").String;
164
+ readonly definitionVersion: import("effect/Schema").withDecodingDefaultKey<import("effect/Schema").String, never>;
165
+ readonly input: import("effect/Schema").Codec<import("effect/Schema").Json, import("effect/Schema").Json, never, never>;
166
+ readonly close: import("effect/Schema").withDecodingDefaultKey<import("effect/Schema").Union<readonly [import("effect/Schema").Literal<"terminate">, import("effect/Schema").Literal<"wait">]>, never>;
167
+ readonly tag: import("effect/Schema").optional<import("effect/Schema").String>;
168
+ }>, import("effect/Schema").Struct<{
169
+ readonly type: import("effect/Schema").Literal<"runtime.cancelRun">;
170
+ readonly runId: import("effect/Schema").String;
171
+ readonly tag: import("effect/Schema").optional<import("effect/Schema").String>;
155
172
  }>, import("effect/Schema").Struct<{
156
173
  readonly type: import("effect/Schema").String;
157
174
  readonly input: import("effect/Schema").Codec<import("effect/Schema").Json, import("effect/Schema").Json, never, never>;
158
175
  readonly tag: import("effect/Schema").optional<import("effect/Schema").String>;
176
+ readonly at: import("effect/Schema").optional<import("effect/Schema").Finite>;
159
177
  }>]>>;
160
178
  readonly waitOn: import("effect/Schema").optional<import("effect/Schema").Struct<{
161
179
  readonly type: import("effect/Schema").Union<readonly [import("effect/Schema").String, import("effect/Schema").$Array<import("effect/Schema").String>]>;
162
180
  readonly match: import("effect/Schema").optional<import("effect/Schema").Codec<import("effect/Schema").Json, import("effect/Schema").Json, never, never>>;
163
181
  }>>;
164
182
  }>;
183
+ lineage: import("effect/Schema").Struct<{
184
+ readonly depth: import("effect/Schema").Finite;
185
+ }>;
186
+ 'context.compacted': import("effect/Schema").Struct<{
187
+ readonly turn: import("effect/Schema").Finite;
188
+ readonly originalCount: import("effect/Schema").Finite;
189
+ readonly compactedCount: import("effect/Schema").Finite;
190
+ readonly summary: import("effect/Schema").optional<import("effect/Schema").String>;
191
+ readonly reason: import("effect/Schema").optional<import("effect/Schema").Union<readonly [import("effect/Schema").Literal<"overflow">, import("effect/Schema").Literal<"manual">, import("effect/Schema").Literal<"threshold">]>>;
192
+ readonly messages: import("effect/Schema").optional<import("effect/Schema").$Array<import("effect/Schema").Struct<{
193
+ readonly role: import("effect/Schema").Union<readonly [import("effect/Schema").Literal<"system">, import("effect/Schema").Literal<"user">, import("effect/Schema").Literal<"assistant">, import("effect/Schema").Literal<"tool">]>;
194
+ readonly content: import("effect/Schema").String;
195
+ readonly toolCallId: import("effect/Schema").optional<import("effect/Schema").String>;
196
+ readonly name: import("effect/Schema").optional<import("effect/Schema").String>;
197
+ readonly toolCalls: import("effect/Schema").optional<import("effect/Schema").mutable<import("effect/Schema").$Array<import("effect/Schema").Struct<{
198
+ readonly id: import("effect/Schema").String;
199
+ readonly name: import("effect/Schema").String;
200
+ readonly arguments: import("effect/Schema").Codec<import("effect/Schema").Json, import("effect/Schema").Json, never, never>;
201
+ }>>>>;
202
+ }>>>;
203
+ }>;
204
+ 'turn.usage': import("effect/Schema").Struct<{
205
+ readonly turn: import("effect/Schema").Finite;
206
+ readonly input: import("effect/Schema").Finite;
207
+ readonly output: import("effect/Schema").Finite;
208
+ }>;
165
209
  }>, undefined>, import("@swirls/looms/core").EventCatalog<"agent", {
166
210
  'message.received': import("effect/Schema").Struct<{
167
211
  readonly message: import("effect/Schema").Struct<{
@@ -260,6 +304,7 @@ export declare const agentModule: import("@swirls/looms/core").ModuleScope<"agen
260
304
  readonly definitionVersion: import("effect/Schema").withDecodingDefaultKey<import("effect/Schema").String, never>;
261
305
  readonly toolCallId: import("effect/Schema").String;
262
306
  readonly input: import("effect/Schema").Codec<import("effect/Schema").Json, import("effect/Schema").Json, never, never>;
307
+ readonly depth: import("effect/Schema").optional<import("effect/Schema").Finite>;
263
308
  }>;
264
309
  'effects.requested': import("effect/Schema").Struct<{
265
310
  readonly toolCallId: import("effect/Schema").String;
@@ -298,6 +343,9 @@ export declare const agentModule: import("@swirls/looms/core").ModuleScope<"agen
298
343
  readonly actorId: import("effect/Schema").optional<import("effect/Schema").String>;
299
344
  }>, import("effect/Schema").Struct<{
300
345
  readonly type: import("effect/Schema").Literal<"system">;
346
+ }>, import("effect/Schema").Struct<{
347
+ readonly type: import("effect/Schema").Literal<"run">;
348
+ readonly runId: import("effect/Schema").String;
301
349
  }>]>>;
302
350
  readonly ephemeral: import("effect/Schema").optional<import("effect/Schema").Boolean>;
303
351
  readonly id: import("effect/Schema").optional<import("effect/Schema").String>;
@@ -315,15 +363,55 @@ export declare const agentModule: import("@swirls/looms/core").ModuleScope<"agen
315
363
  readonly type: import("effect/Schema").Literal<"runtime.cancel">;
316
364
  readonly threadId: import("effect/Schema").String;
317
365
  readonly tag: import("effect/Schema").optional<import("effect/Schema").String>;
366
+ }>, import("effect/Schema").Struct<{
367
+ readonly type: import("effect/Schema").Literal<"runtime.launch">;
368
+ readonly runId: import("effect/Schema").String;
369
+ readonly kind: import("effect/Schema").String;
370
+ readonly definitionName: import("effect/Schema").String;
371
+ readonly definitionVersion: import("effect/Schema").withDecodingDefaultKey<import("effect/Schema").String, never>;
372
+ readonly input: import("effect/Schema").Codec<import("effect/Schema").Json, import("effect/Schema").Json, never, never>;
373
+ readonly close: import("effect/Schema").withDecodingDefaultKey<import("effect/Schema").Union<readonly [import("effect/Schema").Literal<"terminate">, import("effect/Schema").Literal<"wait">]>, never>;
374
+ readonly tag: import("effect/Schema").optional<import("effect/Schema").String>;
375
+ }>, import("effect/Schema").Struct<{
376
+ readonly type: import("effect/Schema").Literal<"runtime.cancelRun">;
377
+ readonly runId: import("effect/Schema").String;
378
+ readonly tag: import("effect/Schema").optional<import("effect/Schema").String>;
318
379
  }>, import("effect/Schema").Struct<{
319
380
  readonly type: import("effect/Schema").String;
320
381
  readonly input: import("effect/Schema").Codec<import("effect/Schema").Json, import("effect/Schema").Json, never, never>;
321
382
  readonly tag: import("effect/Schema").optional<import("effect/Schema").String>;
383
+ readonly at: import("effect/Schema").optional<import("effect/Schema").Finite>;
322
384
  }>]>>;
323
385
  readonly waitOn: import("effect/Schema").optional<import("effect/Schema").Struct<{
324
386
  readonly type: import("effect/Schema").Union<readonly [import("effect/Schema").String, import("effect/Schema").$Array<import("effect/Schema").String>]>;
325
387
  readonly match: import("effect/Schema").optional<import("effect/Schema").Codec<import("effect/Schema").Json, import("effect/Schema").Json, never, never>>;
326
388
  }>>;
327
389
  }>;
390
+ lineage: import("effect/Schema").Struct<{
391
+ readonly depth: import("effect/Schema").Finite;
392
+ }>;
393
+ 'context.compacted': import("effect/Schema").Struct<{
394
+ readonly turn: import("effect/Schema").Finite;
395
+ readonly originalCount: import("effect/Schema").Finite;
396
+ readonly compactedCount: import("effect/Schema").Finite;
397
+ readonly summary: import("effect/Schema").optional<import("effect/Schema").String>;
398
+ readonly reason: import("effect/Schema").optional<import("effect/Schema").Union<readonly [import("effect/Schema").Literal<"overflow">, import("effect/Schema").Literal<"manual">, import("effect/Schema").Literal<"threshold">]>>;
399
+ readonly messages: import("effect/Schema").optional<import("effect/Schema").$Array<import("effect/Schema").Struct<{
400
+ readonly role: import("effect/Schema").Union<readonly [import("effect/Schema").Literal<"system">, import("effect/Schema").Literal<"user">, import("effect/Schema").Literal<"assistant">, import("effect/Schema").Literal<"tool">]>;
401
+ readonly content: import("effect/Schema").String;
402
+ readonly toolCallId: import("effect/Schema").optional<import("effect/Schema").String>;
403
+ readonly name: import("effect/Schema").optional<import("effect/Schema").String>;
404
+ readonly toolCalls: import("effect/Schema").optional<import("effect/Schema").mutable<import("effect/Schema").$Array<import("effect/Schema").Struct<{
405
+ readonly id: import("effect/Schema").String;
406
+ readonly name: import("effect/Schema").String;
407
+ readonly arguments: import("effect/Schema").Codec<import("effect/Schema").Json, import("effect/Schema").Json, never, never>;
408
+ }>>>>;
409
+ }>>>;
410
+ }>;
411
+ 'turn.usage': import("effect/Schema").Struct<{
412
+ readonly turn: import("effect/Schema").Finite;
413
+ readonly input: import("effect/Schema").Finite;
414
+ readonly output: import("effect/Schema").Finite;
415
+ }>;
328
416
  }>, undefined>;
329
417
  export type AgentEvent = EventOf<typeof agentModule>;
@@ -1,5 +1,6 @@
1
1
  import { Predicate } from 'effect';
2
- import { cancel, createWaitId, DEFAULT_DEFINITION_VERSION, emit, invoke, isWithdrawnError, parseEffectId, spawn, wait, waitOutcome, } from '@swirls/looms/core';
2
+ import { cancel, createWaitId, DEFAULT_DEFINITION_VERSION, emit, invoke, isJsonObject, isWithdrawnError, parseEffectId, spawn, wait, waitOutcome, } from '@swirls/looms/core';
3
+ import { STRUCTURED_OUTPUT_TOOL_NAME } from './definitions.js';
3
4
  import { callLlmEffect, executeToolEffect } from './effects.js';
4
5
  import { agentModule } from './scope.js';
5
6
  import { closeOpenToolCalls } from './transcript.js';
@@ -67,6 +68,9 @@ export const agentThread = agentModule.thread({
67
68
  needsLlmCall: false,
68
69
  turn: 0,
69
70
  maxTurns: 20,
71
+ depth: 0,
72
+ structuredOutput: null,
73
+ alreadyCompactedTurns: [],
70
74
  pendingSteer: null,
71
75
  input: ctx.input,
72
76
  output: null,
@@ -92,6 +96,8 @@ export const agentThread = agentModule.thread({
92
96
  needsLlmCall: true,
93
97
  };
94
98
  }
99
+ case 'agent.lineage':
100
+ return { ...state, depth: event.payload.depth };
95
101
  case 'agent.turn.started': {
96
102
  return {
97
103
  ...state,
@@ -132,6 +138,11 @@ export const agentThread = agentModule.thread({
132
138
  const pendingEffects = state.pendingEffects.filter((item) => item.toolCallId !== toolCallId);
133
139
  const pendingEmits = state.pendingEmits.filter((item) => item.id !== `res_${toolCallId}`);
134
140
  const content = Predicate.isString(error) && error.length > 0 ? error : JSON.stringify(result ?? null);
141
+ let structuredOutput = state.structuredOutput;
142
+ if (name === STRUCTURED_OUTPUT_TOOL_NAME && !error && result !== null) {
143
+ structuredOutput =
144
+ isJsonObject(result) && 'output' in result ? (result.output ?? null) : result;
145
+ }
135
146
  const lines = [
136
147
  ...state.lines,
137
148
  {
@@ -145,6 +156,7 @@ export const agentThread = agentModule.thread({
145
156
  return {
146
157
  ...state,
147
158
  lines,
159
+ structuredOutput,
148
160
  pendingToolCalls,
149
161
  executingToolCalls,
150
162
  pendingSpawns,
@@ -177,10 +189,21 @@ export const agentThread = agentModule.thread({
177
189
  consumedSteerMessageIds,
178
190
  };
179
191
  }
192
+ case 'agent.context.compacted': {
193
+ const compactedMessages = event.payload.messages;
194
+ const alreadyCompactedTurns = state.alreadyCompactedTurns
195
+ ? [...state.alreadyCompactedTurns, event.payload.turn]
196
+ : [event.payload.turn];
197
+ return {
198
+ ...state,
199
+ lines: compactedMessages ? [...compactedMessages] : state.lines,
200
+ alreadyCompactedTurns,
201
+ };
202
+ }
180
203
  case 'agent.turn.stopped':
181
204
  return abandonTurn(state);
182
205
  case 'agent.spawn.requested': {
183
- const { childThreadId, kind, definitionName, definitionVersion, toolCallId, input } = event.payload;
206
+ const { childThreadId, kind, definitionName, definitionVersion, toolCallId, input, depth } = event.payload;
184
207
  return {
185
208
  ...state,
186
209
  executingToolCalls: state.executingToolCalls.filter((item) => item.id !== toolCallId),
@@ -194,6 +217,7 @@ export const agentThread = agentModule.thread({
194
217
  toolCallId,
195
218
  // SAFETY: schema-decoded input is JSON
196
219
  input: input ?? null,
220
+ depth: depth ?? state.depth + 1,
197
221
  },
198
222
  ],
199
223
  };
@@ -338,6 +362,8 @@ export const agentThread = agentModule.thread({
338
362
  definitionVersion: state.definitionVersion ?? DEFAULT_DEFINITION_VERSION,
339
363
  messages: state.lines,
340
364
  input: state.input,
365
+ structuredOutput: state.structuredOutput,
366
+ alreadyCompacted: (state.alreadyCompactedTurns ?? []).includes(state.turn + 1),
341
367
  consumedSteerMessageIds: state.consumedSteerMessageIds,
342
368
  }, `llm_turn_${state.turn + 1}`));
343
369
  }
@@ -347,6 +373,8 @@ export const agentThread = agentModule.thread({
347
373
  definitionName: state.definitionName,
348
374
  definitionVersion: state.definitionVersion ?? DEFAULT_DEFINITION_VERSION,
349
375
  toolCall,
376
+ input: state.input,
377
+ depth: state.depth,
350
378
  }, `tool_${toolCall.id}`));
351
379
  }
352
380
  for (const spawnReq of state.pendingSpawns) {
@@ -357,7 +385,15 @@ export const agentThread = agentModule.thread({
357
385
  definitionName: spawnReq.definitionName,
358
386
  definitionVersion: spawnReq.definitionVersion,
359
387
  input: spawnReq.input,
360
- }), wait({
388
+ }));
389
+ if (spawnReq.kind === 'agent') {
390
+ effects.push(emit({
391
+ type: 'agent.lineage',
392
+ payload: { depth: spawnReq.depth ?? state.depth + 1 },
393
+ threadId: spawnReq.childThreadId,
394
+ }, `lineage_${spawnReq.childThreadId}`));
395
+ }
396
+ effects.push(wait({
361
397
  waitId,
362
398
  on: {
363
399
  type: ['runtime.thread.completed', 'runtime.thread.failed'],
@@ -60,6 +60,7 @@ export interface AgentPendingSpawn {
60
60
  readonly definitionVersion: string;
61
61
  readonly toolCallId: string;
62
62
  readonly input: JsonValue;
63
+ readonly depth?: number;
63
64
  }
64
65
  export interface AgentPendingEffects {
65
66
  readonly toolCallId: string;
@@ -85,6 +86,9 @@ export interface AgentState {
85
86
  needsLlmCall: boolean;
86
87
  turn: number;
87
88
  maxTurns: number;
89
+ depth: number;
90
+ structuredOutput?: JsonValue | null;
91
+ alreadyCompactedTurns?: number[];
88
92
  pendingSteer: Message | null;
89
93
  input: JsonValue;
90
94
  output: JsonValue | null;
@@ -34,6 +34,19 @@ export declare const requestApprovalEffect: NoInfer<import("@swirls/looms/core")
34
34
  readonly payload: {
35
35
  readonly approvalId: string;
36
36
  };
37
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
38
+ readonly type: "runtime.child.close.requested";
39
+ readonly payload: {
40
+ readonly policy: "terminate" | "wait";
41
+ };
42
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
43
+ readonly type: "runtime.child.settled";
44
+ readonly payload: {
45
+ readonly runId: string;
46
+ readonly status: "cancelled" | "completed" | "failed";
47
+ readonly output: import("effect/Schema").Json;
48
+ readonly error: string | null;
49
+ };
37
50
  }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
38
51
  readonly type: "runtime.effect.ambiguous";
39
52
  readonly payload: {
@@ -78,6 +91,8 @@ export declare const requestApprovalEffect: NoInfer<import("@swirls/looms/core")
78
91
  readonly payload: {
79
92
  readonly effectId: string;
80
93
  readonly error: string;
94
+ readonly nonRetryable?: boolean | undefined;
95
+ readonly retryAfterMs?: number | undefined;
81
96
  };
82
97
  }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
83
98
  readonly type: "runtime.effect.heartbeat";
@@ -86,6 +101,7 @@ export declare const requestApprovalEffect: NoInfer<import("@swirls/looms/core")
86
101
  readonly attempt: number;
87
102
  readonly heartbeatAt: number;
88
103
  readonly deadlineAt: number | null;
104
+ readonly details?: import("effect/Schema").Json | undefined;
89
105
  };
90
106
  }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
91
107
  readonly type: "runtime.effect.queued";
@@ -138,6 +154,16 @@ export declare const requestApprovalEffect: NoInfer<import("@swirls/looms/core")
138
154
  readonly sourceRunId: string;
139
155
  readonly sourceSeq: number;
140
156
  };
157
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
158
+ readonly type: "runtime.run.launched";
159
+ readonly payload: {
160
+ readonly runId: string;
161
+ readonly kind: string;
162
+ readonly definitionName: string;
163
+ readonly definitionVersion: string;
164
+ readonly effectId: string;
165
+ readonly close: "terminate" | "wait";
166
+ };
141
167
  }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
142
168
  readonly type: "runtime.run.started";
143
169
  readonly payload: {
@@ -147,6 +173,20 @@ export declare const requestApprovalEffect: NoInfer<import("@swirls/looms/core")
147
173
  readonly definitionVersion: string;
148
174
  readonly input: import("effect/Schema").Json;
149
175
  readonly requestedThreadId?: string | null | undefined;
176
+ readonly launchedBy?: {
177
+ readonly runId: string;
178
+ readonly threadId: string;
179
+ readonly effectId: string;
180
+ readonly causationId: string;
181
+ readonly causationSeq: number;
182
+ } | undefined;
183
+ readonly attributes?: {
184
+ readonly [x: string]: string;
185
+ } | undefined;
186
+ readonly trace?: {
187
+ readonly traceparent: string;
188
+ readonly tracestate?: string | undefined;
189
+ } | undefined;
150
190
  };
151
191
  }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
152
192
  readonly type: "runtime.signal.received";
@@ -56,6 +56,19 @@ export declare function approval(): import("@swirls/looms/core").RuntimeModule<"
56
56
  readonly payload: {
57
57
  readonly approvalId: string;
58
58
  };
59
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
60
+ readonly type: "runtime.child.close.requested";
61
+ readonly payload: {
62
+ readonly policy: "terminate" | "wait";
63
+ };
64
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
65
+ readonly type: "runtime.child.settled";
66
+ readonly payload: {
67
+ readonly runId: string;
68
+ readonly status: "cancelled" | "completed" | "failed";
69
+ readonly output: import("effect/Schema").Json;
70
+ readonly error: string | null;
71
+ };
59
72
  }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
60
73
  readonly type: "runtime.effect.ambiguous";
61
74
  readonly payload: {
@@ -100,6 +113,8 @@ export declare function approval(): import("@swirls/looms/core").RuntimeModule<"
100
113
  readonly payload: {
101
114
  readonly effectId: string;
102
115
  readonly error: string;
116
+ readonly nonRetryable?: boolean | undefined;
117
+ readonly retryAfterMs?: number | undefined;
103
118
  };
104
119
  }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
105
120
  readonly type: "runtime.effect.heartbeat";
@@ -108,6 +123,7 @@ export declare function approval(): import("@swirls/looms/core").RuntimeModule<"
108
123
  readonly attempt: number;
109
124
  readonly heartbeatAt: number;
110
125
  readonly deadlineAt: number | null;
126
+ readonly details?: import("effect/Schema").Json | undefined;
111
127
  };
112
128
  }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
113
129
  readonly type: "runtime.effect.queued";
@@ -160,6 +176,16 @@ export declare function approval(): import("@swirls/looms/core").RuntimeModule<"
160
176
  readonly sourceRunId: string;
161
177
  readonly sourceSeq: number;
162
178
  };
179
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
180
+ readonly type: "runtime.run.launched";
181
+ readonly payload: {
182
+ readonly runId: string;
183
+ readonly kind: string;
184
+ readonly definitionName: string;
185
+ readonly definitionVersion: string;
186
+ readonly effectId: string;
187
+ readonly close: "terminate" | "wait";
188
+ };
163
189
  }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
164
190
  readonly type: "runtime.run.started";
165
191
  readonly payload: {
@@ -169,6 +195,20 @@ export declare function approval(): import("@swirls/looms/core").RuntimeModule<"
169
195
  readonly definitionVersion: string;
170
196
  readonly input: import("effect/Schema").Json;
171
197
  readonly requestedThreadId?: string | null | undefined;
198
+ readonly launchedBy?: {
199
+ readonly runId: string;
200
+ readonly threadId: string;
201
+ readonly effectId: string;
202
+ readonly causationId: string;
203
+ readonly causationSeq: number;
204
+ } | undefined;
205
+ readonly attributes?: {
206
+ readonly [x: string]: string;
207
+ } | undefined;
208
+ readonly trace?: {
209
+ readonly traceparent: string;
210
+ readonly tracestate?: string | undefined;
211
+ } | undefined;
172
212
  };
173
213
  }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
174
214
  readonly type: "runtime.signal.received";
@@ -302,6 +342,19 @@ export declare function approval(): import("@swirls/looms/core").RuntimeModule<"
302
342
  readonly payload: {
303
343
  readonly approvalId: string;
304
344
  };
345
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
346
+ readonly type: "runtime.child.close.requested";
347
+ readonly payload: {
348
+ readonly policy: "terminate" | "wait";
349
+ };
350
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
351
+ readonly type: "runtime.child.settled";
352
+ readonly payload: {
353
+ readonly runId: string;
354
+ readonly status: "cancelled" | "completed" | "failed";
355
+ readonly output: import("effect/Schema").Json;
356
+ readonly error: string | null;
357
+ };
305
358
  }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
306
359
  readonly type: "runtime.effect.ambiguous";
307
360
  readonly payload: {
@@ -346,6 +399,8 @@ export declare function approval(): import("@swirls/looms/core").RuntimeModule<"
346
399
  readonly payload: {
347
400
  readonly effectId: string;
348
401
  readonly error: string;
402
+ readonly nonRetryable?: boolean | undefined;
403
+ readonly retryAfterMs?: number | undefined;
349
404
  };
350
405
  }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
351
406
  readonly type: "runtime.effect.heartbeat";
@@ -354,6 +409,7 @@ export declare function approval(): import("@swirls/looms/core").RuntimeModule<"
354
409
  readonly attempt: number;
355
410
  readonly heartbeatAt: number;
356
411
  readonly deadlineAt: number | null;
412
+ readonly details?: import("effect/Schema").Json | undefined;
357
413
  };
358
414
  }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
359
415
  readonly type: "runtime.effect.queued";
@@ -406,6 +462,16 @@ export declare function approval(): import("@swirls/looms/core").RuntimeModule<"
406
462
  readonly sourceRunId: string;
407
463
  readonly sourceSeq: number;
408
464
  };
465
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
466
+ readonly type: "runtime.run.launched";
467
+ readonly payload: {
468
+ readonly runId: string;
469
+ readonly kind: string;
470
+ readonly definitionName: string;
471
+ readonly definitionVersion: string;
472
+ readonly effectId: string;
473
+ readonly close: "terminate" | "wait";
474
+ };
409
475
  }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
410
476
  readonly type: "runtime.run.started";
411
477
  readonly payload: {
@@ -415,6 +481,20 @@ export declare function approval(): import("@swirls/looms/core").RuntimeModule<"
415
481
  readonly definitionVersion: string;
416
482
  readonly input: import("effect/Schema").Json;
417
483
  readonly requestedThreadId?: string | null | undefined;
484
+ readonly launchedBy?: {
485
+ readonly runId: string;
486
+ readonly threadId: string;
487
+ readonly effectId: string;
488
+ readonly causationId: string;
489
+ readonly causationSeq: number;
490
+ } | undefined;
491
+ readonly attributes?: {
492
+ readonly [x: string]: string;
493
+ } | undefined;
494
+ readonly trace?: {
495
+ readonly traceparent: string;
496
+ readonly tracestate?: string | undefined;
497
+ } | undefined;
418
498
  };
419
499
  }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
420
500
  readonly type: "runtime.signal.received";