@swirls/looms 0.0.2 → 0.2.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 (375) hide show
  1. package/CHANGELOG.md +24 -2
  2. package/dist/actor/cell.d.ts +9 -4
  3. package/dist/actor/cell.js +7 -11
  4. package/dist/actor/host.d.ts +7 -3
  5. package/dist/actor/host.js +57 -33
  6. package/dist/actor/index.d.ts +1 -1
  7. package/dist/actor/index.js +1 -1
  8. package/dist/actor/routing.d.ts +12 -1
  9. package/dist/actor/routing.js +57 -51
  10. package/dist/agent/agent-session.d.ts +5 -0
  11. package/dist/agent/agent-session.js +270 -0
  12. package/dist/agent/debugger/agent-chat.d.ts +2 -0
  13. package/dist/agent/debugger/agent-chat.js +176 -0
  14. package/dist/agent/debugger/index.d.ts +5 -0
  15. package/dist/agent/debugger/index.js +19 -0
  16. package/dist/agent/debugger/summarize.d.ts +2 -0
  17. package/dist/agent/debugger/summarize.js +51 -0
  18. package/dist/agent/debugger/token-usage.d.ts +3 -0
  19. package/dist/agent/debugger/token-usage.js +11 -0
  20. package/dist/agent/definitions-store.d.ts +2 -3
  21. package/dist/agent/definitions-store.js +2 -4
  22. package/dist/agent/definitions.d.ts +47 -29
  23. package/dist/agent/definitions.js +39 -12
  24. package/dist/agent/effects.d.ts +359 -2
  25. package/dist/agent/effects.js +60 -34
  26. package/dist/agent/events.d.ts +175 -19
  27. package/dist/agent/events.js +45 -10
  28. package/dist/agent/index.d.ts +1 -0
  29. package/dist/agent/index.js +1 -0
  30. package/dist/agent/llm.d.ts +11 -2
  31. package/dist/agent/llm.js +13 -3
  32. package/dist/agent/module.d.ts +812 -78
  33. package/dist/agent/module.js +16 -4
  34. package/dist/agent/scope.d.ts +174 -18
  35. package/dist/agent/signals.d.ts +26 -1
  36. package/dist/agent/signals.js +79 -0
  37. package/dist/agent/threads.d.ts +3 -33
  38. package/dist/agent/threads.js +20 -25
  39. package/dist/agent/tool-schema.d.ts +1 -17
  40. package/dist/agent/tool-schema.js +3 -43
  41. package/dist/agent/types.d.ts +49 -4
  42. package/dist/agent/types.js +5 -5
  43. package/dist/ai-vercel/index.d.ts +1 -0
  44. package/dist/ai-vercel/index.js +1 -0
  45. package/dist/ai-vercel/messages.js +22 -7
  46. package/dist/ai-vercel/vercel-evaluator.d.ts +36 -0
  47. package/dist/ai-vercel/vercel-evaluator.js +73 -0
  48. package/dist/ai-vercel/vercel-llm.js +64 -44
  49. package/dist/approval/debugger/approvals-view.d.ts +3 -0
  50. package/dist/approval/debugger/approvals-view.js +16 -0
  51. package/dist/approval/debugger/index.d.ts +4 -0
  52. package/dist/approval/debugger/index.js +11 -0
  53. package/dist/approval/debugger/summarize.d.ts +2 -0
  54. package/dist/approval/debugger/summarize.js +17 -0
  55. package/dist/approval/effects.d.ts +89 -0
  56. package/dist/approval/module.d.ts +179 -29
  57. package/dist/approval/projections.d.ts +0 -14
  58. package/dist/approval/projections.js +20 -3
  59. package/dist/approval/signals.d.ts +2 -0
  60. package/dist/approval/signals.js +18 -2
  61. package/dist/cli/cli.js +2 -0
  62. package/dist/cli/commands.js +12 -16
  63. package/dist/client/client.d.ts +1213 -18
  64. package/dist/client/client.js +120 -120
  65. package/dist/client/index.d.ts +1 -1
  66. package/dist/client/index.js +1 -1
  67. package/dist/client/sse.d.ts +13 -0
  68. package/dist/client/sse.js +38 -44
  69. package/dist/cloudflare/alarm-scheduler.d.ts +12 -2
  70. package/dist/cloudflare/alarm-scheduler.js +34 -7
  71. package/dist/cloudflare/durable-object.d.ts +10 -2
  72. package/dist/cloudflare/durable-object.js +59 -28
  73. package/dist/cloudflare/event-store.d.ts +7 -2
  74. package/dist/cloudflare/event-store.js +8 -7
  75. package/dist/cloudflare/index.d.ts +2 -2
  76. package/dist/cloudflare/index.js +2 -2
  77. package/dist/cloudflare/router.d.ts +1 -1
  78. package/dist/cloudflare/router.js +15 -16
  79. package/dist/core/catalog.d.ts +3 -3
  80. package/dist/core/catalog.js +2 -5
  81. package/dist/core/coalesce.js +5 -3
  82. package/dist/core/compose.d.ts +2 -1
  83. package/dist/core/compose.js +19 -2
  84. package/dist/core/debugger-host.d.ts +16 -0
  85. package/dist/core/debugger-host.js +1 -0
  86. package/dist/core/definition-store.d.ts +11 -0
  87. package/dist/core/definition-store.js +6 -0
  88. package/dist/core/effects.d.ts +127 -15
  89. package/dist/core/effects.js +89 -17
  90. package/dist/core/envelope.d.ts +27 -7
  91. package/dist/core/envelope.js +20 -6
  92. package/dist/core/event-codec.d.ts +4 -2
  93. package/dist/core/event-codec.js +10 -5
  94. package/dist/core/event-index.js +1 -3
  95. package/dist/core/fold.d.ts +3 -0
  96. package/dist/core/fold.js +171 -24
  97. package/dist/core/ids.d.ts +5 -0
  98. package/dist/core/ids.js +35 -2
  99. package/dist/core/index.d.ts +7 -1
  100. package/dist/core/index.js +6 -1
  101. package/dist/core/kind.d.ts +22 -0
  102. package/dist/core/kind.js +17 -0
  103. package/dist/core/limits.d.ts +34 -0
  104. package/dist/core/limits.js +46 -0
  105. package/dist/core/match.d.ts +1 -0
  106. package/dist/core/match.js +10 -1
  107. package/dist/core/module-scope.d.ts +22 -20
  108. package/dist/core/module-scope.js +38 -28
  109. package/dist/core/module.d.ts +18 -5
  110. package/dist/core/module.js +4 -0
  111. package/dist/core/projection.d.ts +13 -13
  112. package/dist/core/projection.js +9 -5
  113. package/dist/core/protocol.d.ts +68 -11
  114. package/dist/core/protocol.js +82 -11
  115. package/dist/core/published.d.ts +43 -0
  116. package/dist/core/published.js +44 -0
  117. package/dist/core/replay.d.ts +312 -3
  118. package/dist/core/replay.js +11 -1
  119. package/dist/core/schema.d.ts +11 -20
  120. package/dist/core/schema.js +63 -80
  121. package/dist/core/serialize.js +2 -4
  122. package/dist/core/snapshot-store.d.ts +6 -1
  123. package/dist/core/snapshot-store.js +15 -2
  124. package/dist/core/snapshots.d.ts +5 -1
  125. package/dist/core/snapshots.js +10 -15
  126. package/dist/core/sqlite-store.js +95 -11
  127. package/dist/core/state.d.ts +142 -4
  128. package/dist/core/state.js +78 -0
  129. package/dist/core/store.d.ts +38 -3
  130. package/dist/core/store.js +77 -22
  131. package/dist/core/thread.d.ts +10 -9
  132. package/dist/core/types.d.ts +5 -8
  133. package/dist/core/types.js +28 -24
  134. package/dist/core/validate-event.js +14 -4
  135. package/dist/core/worker-callback.d.ts +17 -0
  136. package/dist/core/worker-callback.js +1 -0
  137. package/dist/debugger/app/assets/index-B3Ah8WAE.css +2 -0
  138. package/dist/debugger/app/assets/index-Qb371t_O.js +22 -0
  139. package/dist/debugger/app/assets/rolldown-runtime-CbXtAM7H.js +1 -0
  140. package/dist/debugger/app/assets/routes-CjtEHgPQ.js +47 -0
  141. package/dist/debugger/app/index.html +14 -0
  142. package/dist/debugger/components/composer.d.ts +17 -0
  143. package/dist/debugger/components/composer.js +25 -0
  144. package/dist/debugger/components/debugger-split.d.ts +2 -1
  145. package/dist/debugger/components/debugger-split.js +2 -2
  146. package/dist/debugger/components/event-inspector.d.ts +2 -1
  147. package/dist/debugger/components/event-inspector.js +25 -16
  148. package/dist/debugger/components/event-stream.d.ts +2 -1
  149. package/dist/debugger/components/event-stream.js +14 -74
  150. package/dist/debugger/components/follow-list.d.ts +19 -0
  151. package/dist/debugger/components/follow-list.js +96 -0
  152. package/dist/debugger/components/json-tree.d.ts +11 -0
  153. package/dist/debugger/components/json-tree.js +120 -0
  154. package/dist/debugger/components/json-view.js +2 -2
  155. package/dist/debugger/components/run-tree.js +53 -20
  156. package/dist/debugger/components/status-dot.d.ts +4 -0
  157. package/dist/debugger/components/status-dot.js +6 -2
  158. package/dist/debugger/context.d.ts +14 -0
  159. package/dist/debugger/context.js +17 -0
  160. package/dist/debugger/contracts.d.ts +7 -4
  161. package/dist/debugger/events/builtin-families.d.ts +3 -0
  162. package/dist/debugger/events/builtin-families.js +9 -0
  163. package/dist/debugger/events/catalog.d.ts +3 -4
  164. package/dist/debugger/events/catalog.js +27 -17
  165. package/dist/debugger/events/protocol-summarize.d.ts +1 -2
  166. package/dist/debugger/events/protocol-summarize.js +42 -24
  167. package/dist/debugger/index.d.ts +20 -6
  168. package/dist/debugger/index.js +19 -5
  169. package/dist/debugger/lib/cn.d.ts +1 -0
  170. package/dist/debugger/lib/cn.js +3 -0
  171. package/dist/debugger/lib/event-meta.d.ts +2 -3
  172. package/dist/debugger/lib/event-meta.js +6 -12
  173. package/dist/debugger/lib/json.d.ts +25 -0
  174. package/dist/debugger/lib/json.js +87 -0
  175. package/dist/debugger/lib/payload.d.ts +7 -0
  176. package/dist/debugger/lib/payload.js +11 -0
  177. package/dist/debugger/lib/time.d.ts +3 -0
  178. package/dist/debugger/lib/time.js +24 -0
  179. package/dist/debugger/plugin.d.ts +36 -0
  180. package/dist/debugger/plugin.js +14 -0
  181. package/dist/debugger/server/index.d.ts +14 -0
  182. package/dist/debugger/server/index.js +114 -0
  183. package/dist/debugger/shell/debugger-shell.d.ts +15 -0
  184. package/dist/debugger/shell/debugger-shell.js +43 -0
  185. package/dist/debugger/shell/definition-key.d.ts +3 -0
  186. package/dist/debugger/shell/definition-key.js +4 -0
  187. package/dist/debugger/shell/events-pane.d.ts +12 -0
  188. package/dist/debugger/shell/events-pane.js +25 -0
  189. package/dist/debugger/shell/projections-panel.d.ts +4 -0
  190. package/dist/debugger/shell/projections-panel.js +59 -0
  191. package/dist/debugger/shell/run-controls.d.ts +4 -0
  192. package/dist/debugger/shell/run-controls.js +72 -0
  193. package/dist/debugger/shell/run-search.d.ts +6 -0
  194. package/dist/debugger/shell/run-search.js +102 -0
  195. package/dist/debugger/shell/run-type-menu.d.ts +6 -0
  196. package/dist/debugger/shell/run-type-menu.js +11 -0
  197. package/dist/debugger/shell/schema-form.d.ts +31 -0
  198. package/dist/debugger/shell/schema-form.js +117 -0
  199. package/dist/debugger/shell/start-form.d.ts +3 -0
  200. package/dist/debugger/shell/start-form.js +75 -0
  201. package/dist/debugger/shell/use-start-run.d.ts +14 -0
  202. package/dist/debugger/shell/use-start-run.js +32 -0
  203. package/dist/debugger/shell/workspace.d.ts +6 -0
  204. package/dist/debugger/shell/workspace.js +15 -0
  205. package/dist/debugger/styles.css +111 -27
  206. package/dist/debugger/ui/button.d.ts +24 -0
  207. package/dist/debugger/ui/button.js +24 -0
  208. package/dist/debugger/ui/command.d.ts +9 -0
  209. package/dist/debugger/ui/command.js +24 -0
  210. package/dist/debugger/ui/dropdown-menu.d.ts +13 -0
  211. package/dist/debugger/ui/dropdown-menu.js +37 -0
  212. package/dist/debugger/ui/panel.d.ts +14 -0
  213. package/dist/debugger/ui/panel.js +16 -0
  214. package/dist/debugger/ui/popover.d.ts +7 -0
  215. package/dist/debugger/ui/popover.js +17 -0
  216. package/dist/debugger/ui/resizable.d.ts +7 -0
  217. package/dist/debugger/ui/resizable.js +14 -0
  218. package/dist/debugger/ui/scroll-area.d.ts +2 -1
  219. package/dist/debugger/ui/scroll-area.js +5 -3
  220. package/dist/debugger/ui/select.d.ts +10 -0
  221. package/dist/debugger/ui/select.js +21 -0
  222. package/dist/debugger/ui/tabs.js +2 -2
  223. package/dist/debugger/ui/textarea.d.ts +3 -0
  224. package/dist/debugger/ui/textarea.js +7 -0
  225. package/dist/evaluator/definitions-store.d.ts +11 -0
  226. package/dist/evaluator/definitions-store.js +8 -0
  227. package/dist/evaluator/definitions.d.ts +18 -0
  228. package/dist/evaluator/definitions.js +4 -0
  229. package/dist/evaluator/effects.d.ts +226 -0
  230. package/dist/evaluator/effects.js +132 -0
  231. package/dist/evaluator/evaluator.d.ts +24 -0
  232. package/dist/evaluator/evaluator.js +67 -0
  233. package/dist/evaluator/events.d.ts +59 -0
  234. package/dist/evaluator/events.js +21 -0
  235. package/dist/evaluator/index.d.ts +11 -0
  236. package/dist/evaluator/index.js +11 -0
  237. package/dist/evaluator/module.d.ts +606 -0
  238. package/dist/evaluator/module.js +25 -0
  239. package/dist/evaluator/projections.d.ts +50 -0
  240. package/dist/evaluator/projections.js +20 -0
  241. package/dist/evaluator/scope.d.ts +59 -0
  242. package/dist/evaluator/scope.js +7 -0
  243. package/dist/evaluator/signals.d.ts +3 -0
  244. package/dist/evaluator/signals.js +17 -0
  245. package/dist/evaluator/threads.d.ts +62 -0
  246. package/dist/evaluator/threads.js +117 -0
  247. package/dist/evaluator/types.d.ts +125 -0
  248. package/dist/evaluator/types.js +51 -0
  249. package/dist/projectors/delivery.d.ts +83 -0
  250. package/dist/projectors/delivery.js +182 -0
  251. package/dist/projectors/index-model.d.ts +1 -1
  252. package/dist/projectors/index-model.js +4 -6
  253. package/dist/projectors/index.d.ts +2 -0
  254. package/dist/projectors/index.js +2 -0
  255. package/dist/projectors/memory.d.ts +1 -1
  256. package/dist/projectors/memory.js +10 -8
  257. package/dist/projectors/postgres.js +44 -58
  258. package/dist/projectors/projector.d.ts +17 -0
  259. package/dist/projectors/projector.js +26 -1
  260. package/dist/projectors/sqlite-delivery.d.ts +4 -0
  261. package/dist/projectors/sqlite-delivery.js +147 -0
  262. package/dist/projectors/sqlite.js +23 -23
  263. package/dist/projectors/with-projectors.d.ts +7 -2
  264. package/dist/projectors/with-projectors.js +27 -28
  265. package/dist/react/notify.js +11 -8
  266. package/dist/react/react.d.ts +2 -3
  267. package/dist/react/react.js +14 -30
  268. package/dist/react/sse.d.ts +1 -1
  269. package/dist/react/sse.js +1 -1
  270. package/dist/react/store.d.ts +3 -3
  271. package/dist/react/store.js +109 -119
  272. package/dist/runtime/cancellation.d.ts +16 -0
  273. package/dist/runtime/cancellation.js +129 -0
  274. package/dist/runtime/deadline-transition-planner.d.ts +31 -0
  275. package/dist/runtime/deadline-transition-planner.js +139 -0
  276. package/dist/runtime/dispatch-effect.d.ts +3 -2
  277. package/dist/runtime/dispatch-effect.js +7 -13
  278. package/dist/runtime/errors.d.ts +51 -0
  279. package/dist/runtime/errors.js +39 -0
  280. package/dist/runtime/{runtime-helpers.d.ts → helpers.d.ts} +24 -4
  281. package/dist/runtime/{runtime-helpers.js → helpers.js} +56 -19
  282. package/dist/runtime/index.d.ts +3 -3
  283. package/dist/runtime/index.js +3 -3
  284. package/dist/runtime/ingress.d.ts +15 -0
  285. package/dist/runtime/ingress.js +42 -0
  286. package/dist/runtime/local-effect-executor.d.ts +21 -0
  287. package/dist/runtime/local-effect-executor.js +137 -0
  288. package/dist/runtime/looms.d.ts +30 -4
  289. package/dist/runtime/looms.js +57 -37
  290. package/dist/runtime/observer.d.ts +45 -0
  291. package/dist/runtime/observer.js +11 -0
  292. package/dist/runtime/repository.d.ts +55 -0
  293. package/dist/runtime/repository.js +293 -0
  294. package/dist/runtime/retry-policy.d.ts +16 -0
  295. package/dist/runtime/retry-policy.js +29 -0
  296. package/dist/runtime/run-execution-context.d.ts +30 -0
  297. package/dist/runtime/run-execution-context.js +56 -0
  298. package/dist/runtime/run-start.d.ts +4 -0
  299. package/dist/runtime/run-start.js +44 -0
  300. package/dist/runtime/runtime.d.ts +6 -87
  301. package/dist/runtime/runtime.js +248 -470
  302. package/dist/runtime/server/auth.d.ts +41 -0
  303. package/dist/runtime/server/auth.js +45 -0
  304. package/dist/runtime/server/debugger-host.d.ts +11 -0
  305. package/dist/runtime/server/debugger-host.js +32 -0
  306. package/dist/runtime/server/fetch-handler.d.ts +18 -0
  307. package/dist/runtime/server/fetch-handler.js +62 -0
  308. package/dist/runtime/server/http.d.ts +38 -0
  309. package/dist/runtime/server/http.js +66 -0
  310. package/dist/runtime/server/route-table.d.ts +55 -0
  311. package/dist/runtime/server/route-table.js +74 -0
  312. package/dist/runtime/server/routes/definitions.d.ts +3 -0
  313. package/dist/runtime/server/routes/definitions.js +20 -0
  314. package/dist/runtime/server/routes/effects.d.ts +3 -0
  315. package/dist/runtime/server/routes/effects.js +59 -0
  316. package/dist/runtime/server/routes/operations.d.ts +3 -0
  317. package/dist/runtime/server/routes/operations.js +14 -0
  318. package/dist/runtime/server/routes/runs.d.ts +3 -0
  319. package/dist/runtime/server/routes/runs.js +199 -0
  320. package/dist/runtime/server.d.ts +4 -8
  321. package/dist/runtime/server.js +6 -211
  322. package/dist/runtime/sse.d.ts +2 -1
  323. package/dist/runtime/sse.js +24 -17
  324. package/dist/runtime/types.d.ts +117 -0
  325. package/dist/runtime/types.js +1 -0
  326. package/dist/runtime/wake-engine.d.ts +20 -0
  327. package/dist/runtime/wake-engine.js +311 -0
  328. package/dist/runtime/wake-scheduler.d.ts +3 -4
  329. package/dist/runtime/wake-scheduler.js +25 -31
  330. package/dist/runtime/worker-callbacks.d.ts +16 -0
  331. package/dist/runtime/worker-callbacks.js +167 -0
  332. package/dist/runtime/worker-effect-dispatch.d.ts +36 -0
  333. package/dist/runtime/worker-effect-dispatch.js +126 -0
  334. package/dist/s2/config.d.ts +1 -1
  335. package/dist/s2/config.js +1 -1
  336. package/dist/s2/lite.js +70 -82
  337. package/dist/s2/pagination.d.ts +15 -0
  338. package/dist/s2/pagination.js +36 -0
  339. package/dist/s2/projector.js +6 -5
  340. package/dist/s2/snapshot-store.js +188 -161
  341. package/dist/s2/store.d.ts +3 -21
  342. package/dist/s2/store.js +71 -165
  343. package/dist/testing/index.d.ts +15 -0
  344. package/dist/testing/index.js +53 -16
  345. package/dist/workflow/debugger/index.d.ts +4 -0
  346. package/dist/workflow/debugger/index.js +11 -0
  347. package/dist/workflow/debugger/nodes-view.d.ts +3 -0
  348. package/dist/workflow/debugger/nodes-view.js +13 -0
  349. package/dist/workflow/debugger/summarize.d.ts +2 -0
  350. package/dist/workflow/debugger/summarize.js +30 -0
  351. package/dist/workflow/definitions-store.d.ts +2 -3
  352. package/dist/workflow/definitions-store.js +2 -2
  353. package/dist/workflow/definitions.d.ts +78 -22
  354. package/dist/workflow/definitions.js +80 -14
  355. package/dist/workflow/effects.d.ts +453 -107
  356. package/dist/workflow/effects.js +214 -115
  357. package/dist/workflow/events.d.ts +149 -5
  358. package/dist/workflow/events.js +27 -5
  359. package/dist/workflow/graph.d.ts +56 -0
  360. package/dist/workflow/graph.js +207 -0
  361. package/dist/workflow/index.d.ts +1 -0
  362. package/dist/workflow/index.js +1 -0
  363. package/dist/workflow/module.d.ts +1047 -266
  364. package/dist/workflow/projections.d.ts +14 -12
  365. package/dist/workflow/projections.js +30 -8
  366. package/dist/workflow/scope.d.ts +146 -4
  367. package/dist/workflow/threads.d.ts +383 -155
  368. package/dist/workflow/threads.js +308 -110
  369. package/package.json +26 -2
  370. package/dist/debugger/events/domain-summarize.d.ts +0 -3
  371. package/dist/debugger/events/domain-summarize.js +0 -107
  372. package/dist/debugger/events/family.d.ts +0 -8
  373. package/dist/debugger/events/family.js +0 -44
  374. package/dist/runtime/events-api.d.ts +0 -4
  375. package/dist/runtime/events-api.js +0 -84
@@ -1,5 +1,6 @@
1
- import type { RuntimeEffect } from './effects';
2
- import type { EventEnvelope } from './envelope';
1
+ import { Schema } from 'effect';
2
+ import { type RuntimeEffect } from './effects';
3
+ import { type EventEnvelope } from './envelope';
3
4
  import { type FoldRegistry } from './fold';
4
5
  import { type RunState } from './state';
5
6
  export interface ReplayStep {
@@ -7,7 +8,315 @@ export interface ReplayStep {
7
8
  event: EventEnvelope;
8
9
  before: RunState;
9
10
  after: RunState;
10
- effects: RuntimeEffect[];
11
+ effects: readonly RuntimeEffect[];
11
12
  }
13
+ export declare const ReplayStepSchema: Schema.Struct<{
14
+ readonly seq: Schema.Finite;
15
+ readonly event: Schema.Struct<{
16
+ readonly id: Schema.String;
17
+ readonly runId: Schema.String;
18
+ readonly seq: Schema.Finite;
19
+ readonly ts: Schema.Finite;
20
+ readonly type: Schema.String;
21
+ readonly payload: Schema.Codec<Schema.Json, Schema.Json, never, never>;
22
+ readonly threadId: Schema.NullOr<Schema.String>;
23
+ readonly parentThreadId: Schema.optional<Schema.NullOr<Schema.String>>;
24
+ readonly causationId: Schema.optional<Schema.NullOr<Schema.String>>;
25
+ readonly correlationId: Schema.optional<Schema.NullOr<Schema.String>>;
26
+ readonly effectId: Schema.optional<Schema.NullOr<Schema.String>>;
27
+ readonly origin: Schema.Union<readonly [Schema.Struct<{
28
+ readonly type: Schema.Literal<"thread">;
29
+ readonly threadId: Schema.String;
30
+ }>, Schema.Struct<{
31
+ readonly type: Schema.Literal<"external">;
32
+ readonly actorId: Schema.optional<Schema.String>;
33
+ }>, Schema.Struct<{
34
+ readonly type: Schema.Literal<"system">;
35
+ }>]>;
36
+ readonly ephemeral: Schema.optional<Schema.Boolean>;
37
+ readonly idempotencyKey: Schema.optional<Schema.NullOr<Schema.String>>;
38
+ }>;
39
+ readonly before: Schema.Struct<{
40
+ readonly runId: Schema.String;
41
+ readonly status: Schema.Union<readonly [Schema.Literal<"running">, Schema.Literal<"completed">, Schema.Literal<"failed">, Schema.Literal<"cancelled">]>;
42
+ readonly rootThreadId: Schema.NullOr<Schema.String>;
43
+ readonly startIdentity: Schema.withDecodingDefaultKey<Schema.NullOr<Schema.Struct<{
44
+ readonly kind: Schema.String;
45
+ readonly definitionName: Schema.String;
46
+ readonly definitionVersion: Schema.String;
47
+ readonly input: Schema.Codec<Schema.Json, Schema.Json, never, never>;
48
+ readonly requestedThreadId: Schema.NullOr<Schema.String>;
49
+ readonly idempotencyKey: Schema.NullOr<Schema.String>;
50
+ readonly rootThreadId: Schema.String;
51
+ }>>, never>;
52
+ readonly threads: Schema.$Record<Schema.String, Schema.Struct<{
53
+ readonly threadId: Schema.String;
54
+ readonly kind: Schema.String;
55
+ readonly definitionName: Schema.String;
56
+ readonly definitionVersion: Schema.withDecodingDefaultKey<Schema.String, never>;
57
+ readonly parentThreadId: Schema.NullOr<Schema.String>;
58
+ readonly status: Schema.Union<readonly [Schema.Literal<"running">, Schema.Literal<"waiting">, Schema.Literal<"completed">, Schema.Literal<"failed">, Schema.Literal<"cancelled">]>;
59
+ readonly input: Schema.Codec<Schema.Json, Schema.Json, never, never>;
60
+ readonly output: Schema.NullOr<Schema.Codec<Schema.Json, Schema.Json, never, never>>;
61
+ readonly error: Schema.NullOr<Schema.String>;
62
+ readonly state: Schema.Codec<Schema.Json, Schema.Json, never, never>;
63
+ }>>;
64
+ readonly waits: Schema.$Record<Schema.String, Schema.Struct<{
65
+ readonly waitId: Schema.String;
66
+ readonly threadId: Schema.String;
67
+ readonly on: Schema.Union<readonly [Schema.Struct<{
68
+ readonly type: Schema.Union<readonly [Schema.String, Schema.$Array<Schema.String>]>;
69
+ readonly match: Schema.optional<Schema.Codec<Schema.Json, Schema.Json, never, never>>;
70
+ }>, Schema.Struct<{
71
+ readonly timerAt: Schema.Finite;
72
+ }>]>;
73
+ readonly tag: Schema.optional<Schema.Codec<Schema.Json, Schema.Json, never, never>>;
74
+ }>>;
75
+ readonly outstandingEffects: Schema.$Array<Schema.Struct<{
76
+ readonly effectId: Schema.String;
77
+ readonly threadId: Schema.String;
78
+ readonly causingSeq: Schema.Finite;
79
+ readonly causingEventId: Schema.String;
80
+ readonly effect: Schema.Union<readonly [Schema.Struct<{
81
+ readonly type: Schema.Literal<"runtime.spawn">;
82
+ readonly childThreadId: Schema.String;
83
+ readonly kind: Schema.String;
84
+ readonly definitionName: Schema.String;
85
+ readonly definitionVersion: Schema.withDecodingDefaultKey<Schema.String, never>;
86
+ readonly input: Schema.Codec<Schema.Json, Schema.Json, never, never>;
87
+ }>, Schema.Struct<{
88
+ readonly type: Schema.Literal<"runtime.wait">;
89
+ readonly waitId: Schema.String;
90
+ readonly on: Schema.Union<readonly [Schema.Struct<{
91
+ readonly type: Schema.Union<readonly [Schema.String, Schema.$Array<Schema.String>]>;
92
+ readonly match: Schema.optional<Schema.Codec<Schema.Json, Schema.Json, never, never>>;
93
+ }>, Schema.Struct<{
94
+ readonly timerAt: Schema.Finite;
95
+ }>]>;
96
+ readonly tag: Schema.optional<Schema.Codec<Schema.Json, Schema.Json, never, never>>;
97
+ }>, Schema.Struct<{
98
+ readonly type: Schema.Literal<"runtime.emit">;
99
+ readonly event: Schema.Struct<{
100
+ readonly type: Schema.String;
101
+ readonly payload: Schema.Codec<Schema.Json, Schema.Json, never, never>;
102
+ readonly threadId: Schema.optional<Schema.NullOr<Schema.String>>;
103
+ readonly parentThreadId: Schema.optional<Schema.NullOr<Schema.String>>;
104
+ readonly causationId: Schema.optional<Schema.NullOr<Schema.String>>;
105
+ readonly correlationId: Schema.optional<Schema.NullOr<Schema.String>>;
106
+ readonly effectId: Schema.optional<Schema.NullOr<Schema.String>>;
107
+ readonly origin: Schema.optional<Schema.Union<readonly [Schema.Struct<{
108
+ readonly type: Schema.Literal<"thread">;
109
+ readonly threadId: Schema.String;
110
+ }>, Schema.Struct<{
111
+ readonly type: Schema.Literal<"external">;
112
+ readonly actorId: Schema.optional<Schema.String>;
113
+ }>, Schema.Struct<{
114
+ readonly type: Schema.Literal<"system">;
115
+ }>]>>;
116
+ readonly ephemeral: Schema.optional<Schema.Boolean>;
117
+ readonly id: Schema.optional<Schema.String>;
118
+ readonly ts: Schema.optional<Schema.Finite>;
119
+ readonly idempotencyKey: Schema.optional<Schema.NullOr<Schema.String>>;
120
+ }>;
121
+ readonly tag: Schema.optional<Schema.String>;
122
+ }>, Schema.Struct<{
123
+ readonly type: Schema.Literal<"runtime.complete">;
124
+ readonly output: Schema.Codec<Schema.Json, Schema.Json, never, never>;
125
+ }>, Schema.Struct<{
126
+ readonly type: Schema.Literal<"runtime.fail">;
127
+ readonly error: Schema.String;
128
+ }>, Schema.Struct<{
129
+ readonly type: Schema.Literal<"runtime.cancel">;
130
+ readonly threadId: Schema.String;
131
+ readonly tag: Schema.optional<Schema.String>;
132
+ }>, Schema.Struct<{
133
+ readonly type: Schema.String;
134
+ readonly input: Schema.Codec<Schema.Json, Schema.Json, never, never>;
135
+ readonly tag: Schema.optional<Schema.String>;
136
+ }>]>;
137
+ }>>;
138
+ readonly effectExecutions: Schema.withDecodingDefaultKey<Schema.$Record<Schema.String, Schema.Struct<{
139
+ readonly effectId: Schema.String;
140
+ readonly attempt: Schema.Finite;
141
+ readonly status: Schema.Union<readonly [Schema.Literal<"queued">, Schema.Literal<"dispatched">, Schema.Literal<"started">, Schema.Literal<"heartbeat">, Schema.Literal<"retry_wait">, Schema.Literal<"cancel_requested">, Schema.Literal<"timed_out">, Schema.Literal<"ambiguous">, Schema.Literal<"running">]>;
142
+ readonly nextAttemptAt: Schema.NullOr<Schema.Finite>;
143
+ readonly deadlineAt: Schema.withDecodingDefaultKey<Schema.NullOr<Schema.Finite>, never>;
144
+ readonly startedAt: Schema.withDecodingDefaultKey<Schema.NullOr<Schema.Finite>, never>;
145
+ readonly lastHeartbeatAt: Schema.withDecodingDefaultKey<Schema.NullOr<Schema.Finite>, never>;
146
+ readonly lastError: Schema.NullOr<Schema.String>;
147
+ }>>, never>;
148
+ readonly completedEffectIds: Schema.withDecodingDefaultKey<Schema.$Array<Schema.String>, never>;
149
+ readonly processedIdempotencyKeys: Schema.withDecodingDefaultKey<Schema.$Array<Schema.String>, never>;
150
+ }>;
151
+ readonly after: Schema.Struct<{
152
+ readonly runId: Schema.String;
153
+ readonly status: Schema.Union<readonly [Schema.Literal<"running">, Schema.Literal<"completed">, Schema.Literal<"failed">, Schema.Literal<"cancelled">]>;
154
+ readonly rootThreadId: Schema.NullOr<Schema.String>;
155
+ readonly startIdentity: Schema.withDecodingDefaultKey<Schema.NullOr<Schema.Struct<{
156
+ readonly kind: Schema.String;
157
+ readonly definitionName: Schema.String;
158
+ readonly definitionVersion: Schema.String;
159
+ readonly input: Schema.Codec<Schema.Json, Schema.Json, never, never>;
160
+ readonly requestedThreadId: Schema.NullOr<Schema.String>;
161
+ readonly idempotencyKey: Schema.NullOr<Schema.String>;
162
+ readonly rootThreadId: Schema.String;
163
+ }>>, never>;
164
+ readonly threads: Schema.$Record<Schema.String, Schema.Struct<{
165
+ readonly threadId: Schema.String;
166
+ readonly kind: Schema.String;
167
+ readonly definitionName: Schema.String;
168
+ readonly definitionVersion: Schema.withDecodingDefaultKey<Schema.String, never>;
169
+ readonly parentThreadId: Schema.NullOr<Schema.String>;
170
+ readonly status: Schema.Union<readonly [Schema.Literal<"running">, Schema.Literal<"waiting">, Schema.Literal<"completed">, Schema.Literal<"failed">, Schema.Literal<"cancelled">]>;
171
+ readonly input: Schema.Codec<Schema.Json, Schema.Json, never, never>;
172
+ readonly output: Schema.NullOr<Schema.Codec<Schema.Json, Schema.Json, never, never>>;
173
+ readonly error: Schema.NullOr<Schema.String>;
174
+ readonly state: Schema.Codec<Schema.Json, Schema.Json, never, never>;
175
+ }>>;
176
+ readonly waits: Schema.$Record<Schema.String, Schema.Struct<{
177
+ readonly waitId: Schema.String;
178
+ readonly threadId: Schema.String;
179
+ readonly on: Schema.Union<readonly [Schema.Struct<{
180
+ readonly type: Schema.Union<readonly [Schema.String, Schema.$Array<Schema.String>]>;
181
+ readonly match: Schema.optional<Schema.Codec<Schema.Json, Schema.Json, never, never>>;
182
+ }>, Schema.Struct<{
183
+ readonly timerAt: Schema.Finite;
184
+ }>]>;
185
+ readonly tag: Schema.optional<Schema.Codec<Schema.Json, Schema.Json, never, never>>;
186
+ }>>;
187
+ readonly outstandingEffects: Schema.$Array<Schema.Struct<{
188
+ readonly effectId: Schema.String;
189
+ readonly threadId: Schema.String;
190
+ readonly causingSeq: Schema.Finite;
191
+ readonly causingEventId: Schema.String;
192
+ readonly effect: Schema.Union<readonly [Schema.Struct<{
193
+ readonly type: Schema.Literal<"runtime.spawn">;
194
+ readonly childThreadId: Schema.String;
195
+ readonly kind: Schema.String;
196
+ readonly definitionName: Schema.String;
197
+ readonly definitionVersion: Schema.withDecodingDefaultKey<Schema.String, never>;
198
+ readonly input: Schema.Codec<Schema.Json, Schema.Json, never, never>;
199
+ }>, Schema.Struct<{
200
+ readonly type: Schema.Literal<"runtime.wait">;
201
+ readonly waitId: Schema.String;
202
+ readonly on: Schema.Union<readonly [Schema.Struct<{
203
+ readonly type: Schema.Union<readonly [Schema.String, Schema.$Array<Schema.String>]>;
204
+ readonly match: Schema.optional<Schema.Codec<Schema.Json, Schema.Json, never, never>>;
205
+ }>, Schema.Struct<{
206
+ readonly timerAt: Schema.Finite;
207
+ }>]>;
208
+ readonly tag: Schema.optional<Schema.Codec<Schema.Json, Schema.Json, never, never>>;
209
+ }>, Schema.Struct<{
210
+ readonly type: Schema.Literal<"runtime.emit">;
211
+ readonly event: Schema.Struct<{
212
+ readonly type: Schema.String;
213
+ readonly payload: Schema.Codec<Schema.Json, Schema.Json, never, never>;
214
+ readonly threadId: Schema.optional<Schema.NullOr<Schema.String>>;
215
+ readonly parentThreadId: Schema.optional<Schema.NullOr<Schema.String>>;
216
+ readonly causationId: Schema.optional<Schema.NullOr<Schema.String>>;
217
+ readonly correlationId: Schema.optional<Schema.NullOr<Schema.String>>;
218
+ readonly effectId: Schema.optional<Schema.NullOr<Schema.String>>;
219
+ readonly origin: Schema.optional<Schema.Union<readonly [Schema.Struct<{
220
+ readonly type: Schema.Literal<"thread">;
221
+ readonly threadId: Schema.String;
222
+ }>, Schema.Struct<{
223
+ readonly type: Schema.Literal<"external">;
224
+ readonly actorId: Schema.optional<Schema.String>;
225
+ }>, Schema.Struct<{
226
+ readonly type: Schema.Literal<"system">;
227
+ }>]>>;
228
+ readonly ephemeral: Schema.optional<Schema.Boolean>;
229
+ readonly id: Schema.optional<Schema.String>;
230
+ readonly ts: Schema.optional<Schema.Finite>;
231
+ readonly idempotencyKey: Schema.optional<Schema.NullOr<Schema.String>>;
232
+ }>;
233
+ readonly tag: Schema.optional<Schema.String>;
234
+ }>, Schema.Struct<{
235
+ readonly type: Schema.Literal<"runtime.complete">;
236
+ readonly output: Schema.Codec<Schema.Json, Schema.Json, never, never>;
237
+ }>, Schema.Struct<{
238
+ readonly type: Schema.Literal<"runtime.fail">;
239
+ readonly error: Schema.String;
240
+ }>, Schema.Struct<{
241
+ readonly type: Schema.Literal<"runtime.cancel">;
242
+ readonly threadId: Schema.String;
243
+ readonly tag: Schema.optional<Schema.String>;
244
+ }>, Schema.Struct<{
245
+ readonly type: Schema.String;
246
+ readonly input: Schema.Codec<Schema.Json, Schema.Json, never, never>;
247
+ readonly tag: Schema.optional<Schema.String>;
248
+ }>]>;
249
+ }>>;
250
+ readonly effectExecutions: Schema.withDecodingDefaultKey<Schema.$Record<Schema.String, Schema.Struct<{
251
+ readonly effectId: Schema.String;
252
+ readonly attempt: Schema.Finite;
253
+ readonly status: Schema.Union<readonly [Schema.Literal<"queued">, Schema.Literal<"dispatched">, Schema.Literal<"started">, Schema.Literal<"heartbeat">, Schema.Literal<"retry_wait">, Schema.Literal<"cancel_requested">, Schema.Literal<"timed_out">, Schema.Literal<"ambiguous">, Schema.Literal<"running">]>;
254
+ readonly nextAttemptAt: Schema.NullOr<Schema.Finite>;
255
+ readonly deadlineAt: Schema.withDecodingDefaultKey<Schema.NullOr<Schema.Finite>, never>;
256
+ readonly startedAt: Schema.withDecodingDefaultKey<Schema.NullOr<Schema.Finite>, never>;
257
+ readonly lastHeartbeatAt: Schema.withDecodingDefaultKey<Schema.NullOr<Schema.Finite>, never>;
258
+ readonly lastError: Schema.NullOr<Schema.String>;
259
+ }>>, never>;
260
+ readonly completedEffectIds: Schema.withDecodingDefaultKey<Schema.$Array<Schema.String>, never>;
261
+ readonly processedIdempotencyKeys: Schema.withDecodingDefaultKey<Schema.$Array<Schema.String>, never>;
262
+ }>;
263
+ readonly effects: Schema.$Array<Schema.Union<readonly [Schema.Struct<{
264
+ readonly type: Schema.Literal<"runtime.spawn">;
265
+ readonly childThreadId: Schema.String;
266
+ readonly kind: Schema.String;
267
+ readonly definitionName: Schema.String;
268
+ readonly definitionVersion: Schema.withDecodingDefaultKey<Schema.String, never>;
269
+ readonly input: Schema.Codec<Schema.Json, Schema.Json, never, never>;
270
+ }>, Schema.Struct<{
271
+ readonly type: Schema.Literal<"runtime.wait">;
272
+ readonly waitId: Schema.String;
273
+ readonly on: Schema.Union<readonly [Schema.Struct<{
274
+ readonly type: Schema.Union<readonly [Schema.String, Schema.$Array<Schema.String>]>;
275
+ readonly match: Schema.optional<Schema.Codec<Schema.Json, Schema.Json, never, never>>;
276
+ }>, Schema.Struct<{
277
+ readonly timerAt: Schema.Finite;
278
+ }>]>;
279
+ readonly tag: Schema.optional<Schema.Codec<Schema.Json, Schema.Json, never, never>>;
280
+ }>, Schema.Struct<{
281
+ readonly type: Schema.Literal<"runtime.emit">;
282
+ readonly event: Schema.Struct<{
283
+ readonly type: Schema.String;
284
+ readonly payload: Schema.Codec<Schema.Json, Schema.Json, never, never>;
285
+ readonly threadId: Schema.optional<Schema.NullOr<Schema.String>>;
286
+ readonly parentThreadId: Schema.optional<Schema.NullOr<Schema.String>>;
287
+ readonly causationId: Schema.optional<Schema.NullOr<Schema.String>>;
288
+ readonly correlationId: Schema.optional<Schema.NullOr<Schema.String>>;
289
+ readonly effectId: Schema.optional<Schema.NullOr<Schema.String>>;
290
+ readonly origin: Schema.optional<Schema.Union<readonly [Schema.Struct<{
291
+ readonly type: Schema.Literal<"thread">;
292
+ readonly threadId: Schema.String;
293
+ }>, Schema.Struct<{
294
+ readonly type: Schema.Literal<"external">;
295
+ readonly actorId: Schema.optional<Schema.String>;
296
+ }>, Schema.Struct<{
297
+ readonly type: Schema.Literal<"system">;
298
+ }>]>>;
299
+ readonly ephemeral: Schema.optional<Schema.Boolean>;
300
+ readonly id: Schema.optional<Schema.String>;
301
+ readonly ts: Schema.optional<Schema.Finite>;
302
+ readonly idempotencyKey: Schema.optional<Schema.NullOr<Schema.String>>;
303
+ }>;
304
+ readonly tag: Schema.optional<Schema.String>;
305
+ }>, Schema.Struct<{
306
+ readonly type: Schema.Literal<"runtime.complete">;
307
+ readonly output: Schema.Codec<Schema.Json, Schema.Json, never, never>;
308
+ }>, Schema.Struct<{
309
+ readonly type: Schema.Literal<"runtime.fail">;
310
+ readonly error: Schema.String;
311
+ }>, Schema.Struct<{
312
+ readonly type: Schema.Literal<"runtime.cancel">;
313
+ readonly threadId: Schema.String;
314
+ readonly tag: Schema.optional<Schema.String>;
315
+ }>, Schema.Struct<{
316
+ readonly type: Schema.String;
317
+ readonly input: Schema.Codec<Schema.Json, Schema.Json, never, never>;
318
+ readonly tag: Schema.optional<Schema.String>;
319
+ }>]>>;
320
+ }>;
12
321
  export declare function replayTo(events: readonly EventEnvelope[], registry: FoldRegistry, seq: number): ReplayStep | null;
13
322
  export declare function replayAll(events: readonly EventEnvelope[], registry: FoldRegistry): ReplayStep[];
@@ -1,5 +1,15 @@
1
+ import { Schema } from 'effect';
2
+ import { RuntimeEffectSchema } from './effects.js';
3
+ import { EventEnvelopeSchema } from './envelope.js';
1
4
  import { foldEvent, foldRun } from './fold.js';
2
- import { emptyRunState } from './state.js';
5
+ import { emptyRunState, RunStateSchema } from './state.js';
6
+ export const ReplayStepSchema = Schema.Struct({
7
+ seq: Schema.Finite,
8
+ event: EventEnvelopeSchema,
9
+ before: RunStateSchema,
10
+ after: RunStateSchema,
11
+ effects: Schema.Array(RuntimeEffectSchema),
12
+ });
3
13
  export function replayTo(events, registry, seq) {
4
14
  const target = events.find((event) => event.seq === seq && !event.ephemeral);
5
15
  if (!target) {
@@ -1,6 +1,6 @@
1
1
  import type { StandardSchemaV1 } from '@standard-schema/spec';
2
2
  import { Effect, Schema } from 'effect';
3
- import type { JsonValue } from './types';
3
+ import { type JsonValue } from './types';
4
4
  declare const InvalidInputError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
5
5
  readonly _tag: "InvalidInputError";
6
6
  } & Readonly<A>;
@@ -11,25 +11,16 @@ export declare class InvalidInputError extends InvalidInputError_base<{
11
11
  readonly issues: ReadonlyArray<StandardSchemaV1.Issue>;
12
12
  constructor(text: string, issues?: ReadonlyArray<StandardSchemaV1.Issue>);
13
13
  }
14
- export type SchemaInput = StandardSchemaV1<any, any> | Schema.Top | Schema.Schema<any> | {
15
- _output: any;
16
- };
17
- export type InferSchemaOutput<T> = T extends Schema.Schema<infer Out> ? Out : T extends Schema.Top ? Schema.Schema.Type<T> : T extends StandardSchemaV1<any, infer Out> ? Out : T extends {
18
- _output: infer Out;
19
- } ? Out : never;
14
+ export type SchemaInput = StandardSchemaV1<any, any> | Schema.ConstraintDecoder<unknown>;
15
+ export type InferSchemaOutput<T> = T extends Schema.Schema<infer Out> ? Out : T extends Schema.ConstraintDecoder<unknown> ? Schema.Schema.Type<T> : T extends StandardSchemaV1<any, infer Out> ? Out : never;
20
16
  /** Output of an optional `input` / `shape` schema, or `TFallback` when the schema is omitted. */
21
17
  export type InferDefinedSchema<T, TFallback = JsonValue> = [T] extends [undefined] ? TFallback : InferSchemaOutput<NonNullable<T>>;
22
- type SchemaCandidate<TInput> = StandardSchemaV1<JsonValue, TInput> | StandardSchemaV1<unknown, TInput> | StandardSchemaV1<any, TInput> | Schema.Schema<TInput> | {
23
- _output: TInput;
24
- } | {
25
- input?: StandardSchemaV1<JsonValue, TInput> | StandardSchemaV1<unknown, TInput> | StandardSchemaV1<any, TInput> | Schema.Schema<TInput> | {
26
- _output: TInput;
27
- };
28
- schema?: StandardSchemaV1<JsonValue, TInput> | StandardSchemaV1<unknown, TInput> | StandardSchemaV1<any, TInput> | Schema.Schema<TInput> | {
29
- _output: TInput;
30
- };
31
- } | null | undefined;
32
- export declare function validateInputEffect<TInput = JsonValue>(schemaOrDef: SchemaCandidate<TInput>, raw: JsonValue): Effect.Effect<TInput, InvalidInputError>;
33
- export declare function validateInput<TInput = JsonValue>(schemaOrDef: SchemaCandidate<TInput>, raw: JsonValue): Promise<TInput>;
34
- export declare function validateInputSync<TInput = JsonValue>(schemaOrDef: SchemaCandidate<TInput>, raw: JsonValue): TInput;
18
+ type ValidatedInput<TSchema extends SchemaInput | null | undefined> = TSchema extends SchemaInput ? InferSchemaOutput<TSchema> : JsonValue;
19
+ export declare function validateInputEffect<TSchema extends SchemaInput | null | undefined>(schema: TSchema, raw: JsonValue): Effect.Effect<ValidatedInput<TSchema>, InvalidInputError>;
20
+ export declare function validateInput<TSchema extends SchemaInput>(schema: TSchema, raw: JsonValue): Promise<InferSchemaOutput<TSchema>>;
21
+ export declare function validateInput(schema: null | undefined, raw: JsonValue): Promise<JsonValue>;
22
+ export declare function validateInputSync<TSchema extends SchemaInput>(schema: TSchema, raw: JsonValue): InferSchemaOutput<TSchema>;
23
+ export declare function validateInputSync(schema: null | undefined, raw: JsonValue): JsonValue;
24
+ /** JSON Schema for a definition input, when the schema can describe itself. */
25
+ export declare function jsonSchemaOfInput(input: SchemaInput | null | undefined): JsonValue | undefined;
35
26
  export {};
@@ -1,4 +1,5 @@
1
1
  import { Data, Effect, Predicate, Schema } from 'effect';
2
+ import { isJsonObject } from './types.js';
2
3
  export class InvalidInputError extends Data.TaggedError('InvalidInputError') {
3
4
  issues;
4
5
  constructor(text, issues = []) {
@@ -7,65 +8,17 @@ export class InvalidInputError extends Data.TaggedError('InvalidInputError') {
7
8
  this.issues = issues;
8
9
  }
9
10
  }
10
- function toStandard(candidate) {
11
- if (!candidate) {
12
- return undefined;
13
- }
14
- if (Schema.isSchema(candidate)) {
15
- // SAFETY: Effect Schema converts to StandardSchemaV1 via official helper.
16
- return Schema.toStandardSchemaV1(candidate);
17
- }
18
- if (Predicate.isObject(candidate) && '~standard' in candidate) {
19
- // SAFETY: verified '~standard' property exists on object.
20
- return candidate;
21
- }
22
- if (Predicate.isObject(candidate) && 'safeParse' in candidate) {
23
- // SAFETY: candidate has safeParse property verified by key check.
24
- const safeParse = candidate.safeParse;
25
- if (Predicate.isFunction(safeParse)) {
26
- // SAFETY: verified safeParse is a function matching the Zod safeParse contract.
27
- const zodSchema = candidate;
28
- return {
29
- '~standard': {
30
- version: 1,
31
- vendor: 'zod-compat',
32
- validate(raw) {
33
- const res = zodSchema.safeParse(raw);
34
- if (res.success) {
35
- return { value: res.data };
36
- }
37
- return {
38
- issues: res.error.issues.map((issue) => ({
39
- message: issue.message,
40
- path: issue.path,
41
- })),
42
- };
43
- },
44
- },
45
- };
46
- }
11
+ function isStandardSchema(candidate) {
12
+ if (!Predicate.isReadonlyObject(candidate) || !('~standard' in candidate)) {
13
+ return false;
47
14
  }
48
- return undefined;
15
+ const standard = candidate['~standard'];
16
+ return (Predicate.isReadonlyObject(standard) &&
17
+ 'validate' in standard &&
18
+ Predicate.isFunction(standard.validate));
49
19
  }
50
- function extractSchema(schemaOrDef) {
51
- const direct = toStandard(schemaOrDef);
52
- if (direct) {
53
- return direct;
54
- }
55
- if (schemaOrDef && Predicate.isObject(schemaOrDef)) {
56
- if ('schema' in schemaOrDef) {
57
- // SAFETY: verified schemaOrDef has schema property.
58
- const fromSchema = toStandard(schemaOrDef.schema);
59
- if (fromSchema) {
60
- return fromSchema;
61
- }
62
- }
63
- if ('input' in schemaOrDef) {
64
- // SAFETY: Verified schemaOrDef has input property.
65
- return toStandard(schemaOrDef.input);
66
- }
67
- }
68
- return undefined;
20
+ function toStandard(candidate) {
21
+ return isStandardSchema(candidate) ? candidate : Schema.toStandardSchemaV1(candidate);
69
22
  }
70
23
  function formatIssue(issue) {
71
24
  if (!issue.path || issue.path.length === 0) {
@@ -85,39 +38,33 @@ function formatIssue(issue) {
85
38
  .join('.');
86
39
  return `${pathStr}: ${issue.message}`;
87
40
  }
88
- export function validateInputEffect(schemaOrDef, raw) {
89
- const schema = extractSchema(schemaOrDef);
41
+ function decodeInput(schema, raw) {
90
42
  if (!schema) {
91
- // SAFETY: when no schema is provided, raw JsonValue is accepted as TInput.
92
43
  return Effect.succeed(raw);
93
44
  }
94
- return Effect.gen(function* () {
95
- let result = schema['~standard'].validate(raw);
96
- if (result instanceof Promise) {
97
- result = yield* Effect.tryPromise({
98
- // SAFETY: Standard Schema validate() returns this Promise when async.
99
- try: () => result,
100
- catch: (cause) => new InvalidInputError(`Schema validation failed: ${cause instanceof Error ? cause.message : String(cause)}`),
101
- });
102
- }
45
+ const standard = toStandard(schema);
46
+ return Effect.tryPromise({
47
+ try: () => Promise.resolve(standard['~standard'].validate(raw)),
48
+ catch: (cause) => new InvalidInputError(`Schema validation failed: ${cause instanceof Error ? cause.message : String(cause)}`),
49
+ }).pipe(Effect.flatMap((result) => {
103
50
  if (result.issues !== undefined) {
104
51
  const text = result.issues.map(formatIssue).join(', ');
105
- return yield* Effect.fail(new InvalidInputError(`Invalid input: ${text}`, result.issues));
52
+ return new InvalidInputError(`Invalid input: ${text}`, result.issues);
106
53
  }
107
- return result.value;
108
- });
54
+ return Effect.succeed(result.value);
55
+ }));
109
56
  }
110
- export async function validateInput(schemaOrDef, raw) {
111
- return Effect.runPromise(validateInputEffect(schemaOrDef, raw));
57
+ export function validateInputEffect(schema, raw) {
58
+ return decodeInput(schema, raw);
112
59
  }
113
- export function validateInputSync(schemaOrDef, raw) {
114
- const schema = extractSchema(schemaOrDef);
60
+ export function validateInput(schema, raw) {
61
+ return Effect.runPromise(decodeInput(schema, raw));
62
+ }
63
+ export function validateInputSync(schema, raw) {
115
64
  if (!schema) {
116
- // SAFETY: when no schema is provided, raw JsonValue is accepted as TInput.
117
65
  return raw;
118
66
  }
119
- // SAFETY: StandardSchemaV1.validate returns Result<TInput> or Promise<Result<TInput>>.
120
- const result = schema['~standard'].validate(raw);
67
+ const result = toStandard(schema)['~standard'].validate(raw);
121
68
  if (result instanceof Promise) {
122
69
  throw new Error('Async schema validation is not supported in synchronous context');
123
70
  }
@@ -125,6 +72,42 @@ export function validateInputSync(schemaOrDef, raw) {
125
72
  const text = result.issues.map(formatIssue).join(', ');
126
73
  throw new InvalidInputError(`Invalid input: ${text}`, result.issues);
127
74
  }
128
- // SAFETY: When result.issues is undefined, result is SuccessResult.
129
75
  return result.value;
130
76
  }
77
+ function isStandardJsonSchemaHolder(value) {
78
+ return '~standard' in value;
79
+ }
80
+ function jsonSchemaFromHolder(value) {
81
+ if (!isStandardJsonSchemaHolder(value)) {
82
+ return undefined;
83
+ }
84
+ const input = value['~standard'].jsonSchema?.input;
85
+ if (!input) {
86
+ return undefined;
87
+ }
88
+ try {
89
+ const schema = input({ target: 'draft-2020-12' });
90
+ return isJsonObject(schema) ? schema : undefined;
91
+ }
92
+ catch {
93
+ return undefined;
94
+ }
95
+ }
96
+ /** JSON Schema for a definition input, when the schema can describe itself. */
97
+ export function jsonSchemaOfInput(input) {
98
+ if (!input) {
99
+ return undefined;
100
+ }
101
+ if (isStandardSchema(input)) {
102
+ return jsonSchemaFromHolder(input);
103
+ }
104
+ if (!Schema.isSchema(input)) {
105
+ return undefined;
106
+ }
107
+ try {
108
+ return jsonSchemaFromHolder(Schema.toStandardJSONSchemaV1(input));
109
+ }
110
+ catch {
111
+ return undefined;
112
+ }
113
+ }
@@ -23,11 +23,9 @@ export function createKeyedSerializer() {
23
23
  tails.set(key, cleanup);
24
24
  return next;
25
25
  };
26
- const drain = async (key) => {
26
+ const drain = (key) => {
27
27
  const pending = tails.get(key);
28
- if (pending) {
29
- await pending;
30
- }
28
+ return pending ? pending.then(() => undefined) : Promise.resolve();
31
29
  };
32
30
  const clear = (key) => {
33
31
  if (key !== undefined) {
@@ -1,4 +1,6 @@
1
1
  import { Context, Effect, Option } from 'effect';
2
+ import { SnapshotPayloadTooLargeError } from './limits';
3
+ import type { RunSummary } from './published';
2
4
  import type { RunState } from './state';
3
5
  import type { EventStore } from './store';
4
6
  /**
@@ -25,9 +27,12 @@ export declare class SnapshotStoreError extends SnapshotStoreError_base<{
25
27
  }
26
28
  export interface SnapshotStore {
27
29
  readonly loadLatest: (runId: string) => Effect.Effect<Option.Option<RunSnapshot>, SnapshotStoreError>;
28
- readonly save: (snapshot: RunSnapshot) => Effect.Effect<void, SnapshotStoreError>;
30
+ readonly save: (snapshot: RunSnapshot) => Effect.Effect<void, SnapshotStoreError | SnapshotPayloadTooLargeError>;
29
31
  readonly listCursors?: (runId: string) => Effect.Effect<number[], SnapshotStoreError>;
30
32
  readonly prune?: (runId: string, keepLatest: number) => Effect.Effect<void, SnapshotStoreError>;
33
+ /** Upsert the list-row for a run. Written where the cursor already advanced. */
34
+ readonly saveHeader: (header: RunSummary) => Effect.Effect<void, SnapshotStoreError>;
35
+ readonly listHeaders: Effect.Effect<readonly RunSummary[], SnapshotStoreError>;
31
36
  }
32
37
  declare const SnapshotStoreTag_base: Context.ServiceClass<SnapshotStoreTag, "looms/SnapshotStore", SnapshotStore>;
33
38
  export declare class SnapshotStoreTag extends SnapshotStoreTag_base {
@@ -1,4 +1,5 @@
1
1
  import { Context, Data, Effect, Option, Ref } from 'effect';
2
+ import { assertSnapshotByteLimit, SnapshotPayloadTooLargeError } from './limits.js';
2
3
  export class SnapshotStoreError extends Data.TaggedError('SnapshotStoreError') {
3
4
  constructor(text, cause) {
4
5
  super({ message: text, cause });
@@ -20,6 +21,7 @@ export function snapshotStoreOf(store) {
20
21
  }
21
22
  export const makeMemorySnapshotStore = Effect.gen(function* () {
22
23
  const snapshots = yield* Ref.make(new Map());
24
+ const headers = yield* Ref.make(new Map());
23
25
  const service = {
24
26
  loadLatest: (runId) => Effect.gen(function* () {
25
27
  const map = yield* Ref.get(snapshots);
@@ -29,12 +31,17 @@ export const makeMemorySnapshotStore = Effect.gen(function* () {
29
31
  }
30
32
  return Option.some(list[list.length - 1]);
31
33
  }),
32
- save: (snapshot) => Ref.update(snapshots, (map) => {
34
+ save: (snapshot) => Effect.try({
35
+ try: () => assertSnapshotByteLimit(snapshot),
36
+ catch: (cause) => cause instanceof SnapshotPayloadTooLargeError
37
+ ? cause
38
+ : new SnapshotStoreError('snapshot size validation failed', cause),
39
+ }).pipe(Effect.andThen(Ref.update(snapshots, (map) => {
33
40
  const next = new Map(map);
34
41
  const existing = next.get(snapshot.runId) ?? [];
35
42
  next.set(snapshot.runId, [...existing, snapshot]);
36
43
  return next;
37
- }),
44
+ }))),
38
45
  listCursors: (runId) => Effect.gen(function* () {
39
46
  const map = yield* Ref.get(snapshots);
40
47
  return (map.get(runId) ?? []).map((item) => item.cursor);
@@ -48,6 +55,12 @@ export const makeMemorySnapshotStore = Effect.gen(function* () {
48
55
  next.set(runId, list.slice(list.length - keepLatest));
49
56
  return next;
50
57
  }),
58
+ saveHeader: (header) => Ref.update(headers, (map) => {
59
+ const next = new Map(map);
60
+ next.set(header.runId, header);
61
+ return next;
62
+ }),
63
+ listHeaders: Ref.get(headers).pipe(Effect.map((map) => [...map.values()])),
51
64
  };
52
65
  return service;
53
66
  });