@demlik/tea 0.2.0 → 0.3.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 (196) hide show
  1. package/README.md +49 -0
  2. package/dist/agent/index.d.ts +16 -770
  3. package/dist/agent/index.js +18 -16
  4. package/dist/authed-call/index.d.ts +3 -3
  5. package/dist/authed-call/index.js +22 -36
  6. package/dist/authed-call/index.js.map +1 -1
  7. package/dist/await-terminal/index.d.ts +2 -2
  8. package/dist/await-terminal/index.js +2 -2
  9. package/dist/batch-window/index.d.ts +3 -3
  10. package/dist/batch-window/index.js +3 -3
  11. package/dist/cache/index.d.ts +2 -2
  12. package/dist/cache/index.js +5 -2
  13. package/dist/{chunk-3545BOYL.js → chunk-25LBDCBC.js} +6 -5
  14. package/dist/chunk-25LBDCBC.js.map +1 -0
  15. package/dist/{chunk-IN33Q4VJ.js → chunk-2KNLKQVN.js} +3 -3
  16. package/dist/{chunk-IN33Q4VJ.js.map → chunk-2KNLKQVN.js.map} +1 -1
  17. package/dist/{chunk-6VDCTR7N.js → chunk-BP2R7TPP.js} +203 -141
  18. package/dist/chunk-BP2R7TPP.js.map +1 -0
  19. package/dist/chunk-C6QC273X.js +71 -0
  20. package/dist/chunk-C6QC273X.js.map +1 -0
  21. package/dist/{chunk-ZDRN3YCE.js → chunk-CAXMQJJ3.js} +17 -24
  22. package/dist/chunk-CAXMQJJ3.js.map +1 -0
  23. package/dist/{chunk-UV6UWGEO.js → chunk-D736QUGF.js} +6 -5
  24. package/dist/chunk-D736QUGF.js.map +1 -0
  25. package/dist/chunk-EWJP3YYP.js +21 -0
  26. package/dist/chunk-EWJP3YYP.js.map +1 -0
  27. package/dist/{chunk-TGG26XMK.js → chunk-FV3Z5MBE.js} +10 -5
  28. package/dist/chunk-FV3Z5MBE.js.map +1 -0
  29. package/dist/chunk-G5E74IJB.js +8 -0
  30. package/dist/chunk-G5E74IJB.js.map +1 -0
  31. package/dist/{chunk-6GIGQT6C.js → chunk-IXBKFQH5.js} +12 -11
  32. package/dist/chunk-IXBKFQH5.js.map +1 -0
  33. package/dist/{chunk-G2U7DJHL.js → chunk-JFFVBEDI.js} +3 -3
  34. package/dist/{chunk-G2U7DJHL.js.map → chunk-JFFVBEDI.js.map} +1 -1
  35. package/dist/chunk-LYLDCIPH.js +365 -0
  36. package/dist/chunk-LYLDCIPH.js.map +1 -0
  37. package/dist/{chunk-HJO6VNQI.js → chunk-MU6MCIAC.js} +3 -3
  38. package/dist/{chunk-HJO6VNQI.js.map → chunk-MU6MCIAC.js.map} +1 -1
  39. package/dist/{chunk-UYWUVEP6.js → chunk-MUUROGIH.js} +2 -2
  40. package/dist/chunk-MUUROGIH.js.map +1 -0
  41. package/dist/{chunk-5KVHID6A.js → chunk-MVY5DAMF.js} +4 -4
  42. package/dist/{chunk-5KVHID6A.js.map → chunk-MVY5DAMF.js.map} +1 -1
  43. package/dist/{chunk-EGWTT5XJ.js → chunk-NPERUUUE.js} +76 -95
  44. package/dist/chunk-NPERUUUE.js.map +1 -0
  45. package/dist/{chunk-DYRKDCJI.js → chunk-PBDYW2TU.js} +41 -7
  46. package/dist/chunk-PBDYW2TU.js.map +1 -0
  47. package/dist/{chunk-5VNWZADP.js → chunk-Q2UM7BXU.js} +18 -7
  48. package/dist/chunk-Q2UM7BXU.js.map +1 -0
  49. package/dist/chunk-RMX4EOQK.js +26 -0
  50. package/dist/chunk-RMX4EOQK.js.map +1 -0
  51. package/dist/{chunk-2YOE5PIS.js → chunk-S2EGRPCM.js} +8 -6
  52. package/dist/chunk-S2EGRPCM.js.map +1 -0
  53. package/dist/{chunk-IK4S5DJN.js → chunk-S4O26D7B.js} +7 -14
  54. package/dist/chunk-S4O26D7B.js.map +1 -0
  55. package/dist/{chunk-6OUDPSSG.js → chunk-SK5JGUY7.js} +3 -3
  56. package/dist/{chunk-6OUDPSSG.js.map → chunk-SK5JGUY7.js.map} +1 -1
  57. package/dist/{chunk-FOGL3TC7.js → chunk-TPGASTFF.js} +8 -10
  58. package/dist/chunk-TPGASTFF.js.map +1 -0
  59. package/dist/{chunk-SC3FAFZN.js → chunk-UF4MZSLT.js} +2 -2
  60. package/dist/chunk-UF4MZSLT.js.map +1 -0
  61. package/dist/{chunk-M6UZT7HS.js → chunk-VBUCHVCV.js} +6 -5
  62. package/dist/chunk-VBUCHVCV.js.map +1 -0
  63. package/dist/{chunk-VFGKTGGC.js → chunk-WGGAMW7Y.js} +191 -178
  64. package/dist/chunk-WGGAMW7Y.js.map +1 -0
  65. package/dist/chunk-ZJ5AOYBH.js +8 -0
  66. package/dist/chunk-ZJ5AOYBH.js.map +1 -0
  67. package/dist/{chunk-LEC4U6CX.js → chunk-ZVJZ72HY.js} +3 -3
  68. package/dist/{chunk-LEC4U6CX.js.map → chunk-ZVJZ72HY.js.map} +1 -1
  69. package/dist/circuit-breaker/index.d.ts +1 -0
  70. package/dist/circuit-breaker/index.js +1 -1
  71. package/dist/{core-BmlJOvxM.d.ts → core-42kapW0n.d.ts} +96 -6
  72. package/dist/deadline/index.d.ts +77 -11
  73. package/dist/deadline/index.js +3 -3
  74. package/dist/devtools/index.js +8 -28
  75. package/dist/devtools/index.js.map +1 -1
  76. package/dist/do/index.d.ts +52 -24
  77. package/dist/do/index.js +94 -92
  78. package/dist/do/index.js.map +1 -1
  79. package/dist/{durable-effects-9LxFpmh3.d.ts → durable-effects-CFRngTNA.d.ts} +3 -3
  80. package/dist/extension/index.d.ts +25 -7
  81. package/dist/extension/index.js +4 -3
  82. package/dist/extension/index.js.map +1 -1
  83. package/dist/extension/react.js +4 -3
  84. package/dist/extension/react.js.map +1 -1
  85. package/dist/extension/subs/index.d.ts +2 -2
  86. package/dist/extension/subs/index.js +7 -10
  87. package/dist/extension/subs/index.js.map +1 -1
  88. package/dist/fan-out/index.d.ts +10 -10
  89. package/dist/fan-out/index.js +3 -3
  90. package/dist/idempotent-intake/index.d.ts +2 -2
  91. package/dist/idempotent-intake/index.js +3 -3
  92. package/dist/index.d.ts +50 -489
  93. package/dist/index.js +2 -2
  94. package/dist/llm-call/index.d.ts +3 -2
  95. package/dist/llm-call/index.js +12 -10
  96. package/dist/machine-B_BF4jij.d.ts +804 -0
  97. package/dist/machine-viz/index.d.ts +1 -1
  98. package/dist/machine-viz/index.js +2 -2
  99. package/dist/mem/index.d.ts +3 -2
  100. package/dist/mem/index.js.map +1 -1
  101. package/dist/monitored-run/index.d.ts +54 -30
  102. package/dist/monitored-run/index.js +7 -7
  103. package/dist/node/index.d.ts +3 -2
  104. package/dist/node/index.js +2 -3
  105. package/dist/node/index.js.map +1 -1
  106. package/dist/paginated-walk/index.d.ts +2 -2
  107. package/dist/paginated-walk/index.js +11 -10
  108. package/dist/parity/index.d.ts +6 -5
  109. package/dist/parity/index.js +5 -4
  110. package/dist/parity/index.js.map +1 -1
  111. package/dist/pbt/arbitraries/index.d.ts +1 -1
  112. package/dist/pbt/index.d.ts +1 -1
  113. package/dist/pbt/index.js +3 -3
  114. package/dist/pbt/index.js.map +1 -1
  115. package/dist/pbt/runners/index.d.ts +1 -1
  116. package/dist/pbt/runners/index.js +3 -3
  117. package/dist/poller/index.d.ts +59 -17
  118. package/dist/poller/index.js +56 -20
  119. package/dist/poller/index.js.map +1 -1
  120. package/dist/prediction/index.d.ts +1 -1
  121. package/dist/prediction/index.js +2 -2
  122. package/dist/pure/index.d.ts +1 -1
  123. package/dist/pure/index.js +2 -2
  124. package/dist/rate-limit/index.d.ts +2 -2
  125. package/dist/rate-limit/index.js +1 -1
  126. package/dist/react/index.d.ts +3 -2
  127. package/dist/react/index.js +2 -2
  128. package/dist/react/index.js.map +1 -1
  129. package/dist/reconciler/index.d.ts +2 -2
  130. package/dist/reconciler/index.js +13 -15
  131. package/dist/reconciler/index.js.map +1 -1
  132. package/dist/recorder/index.d.ts +20 -20
  133. package/dist/recorder/index.js +1 -1
  134. package/dist/resilient-call/index.d.ts +31 -6
  135. package/dist/resilient-call/index.js +10 -9
  136. package/dist/retry-backoff/index.d.ts +191 -14
  137. package/dist/retry-backoff/index.js +1 -1
  138. package/dist/retry-to-success/index.js +1 -1
  139. package/dist/runtime-types-gsog27b6.d.ts +337 -0
  140. package/dist/saga/index.d.ts +3 -2
  141. package/dist/saga/index.js +2 -2
  142. package/dist/saga/index.js.map +1 -1
  143. package/dist/snapshot/index.d.ts +1 -1
  144. package/dist/snapshot/index.js +3 -3
  145. package/dist/subs/index.d.ts +372 -4
  146. package/dist/subs/index.js +4 -1
  147. package/dist/testing/index.d.ts +2 -2
  148. package/dist/testing/index.js +2 -2
  149. package/dist/throttled-input/index.d.ts +2 -2
  150. package/dist/throttled-input/index.js +14 -13
  151. package/dist/throttled-input/index.js.map +1 -1
  152. package/dist/token-refresh/index.d.ts +1 -1
  153. package/dist/token-refresh/index.js +3 -3
  154. package/dist/trace-replay/index.d.ts +12 -7
  155. package/dist/trace-replay/index.js +4 -3
  156. package/dist/{types-BoUWgwSm.d.ts → types-KbL3W1mj.d.ts} +1 -1
  157. package/dist/with-deadline/index.d.ts +1 -1
  158. package/dist/with-deadline/index.js +2 -2
  159. package/dist/with-resilience/index.d.ts +21 -2
  160. package/dist/with-resilience/index.js +12 -23
  161. package/dist/with-resilience/index.js.map +1 -1
  162. package/dist/with-telemetry/index.d.ts +1 -1
  163. package/dist/with-telemetry/index.js +2 -2
  164. package/dist/work-queue/adapter.d.ts +2 -2
  165. package/dist/work-queue/adapter.js +2 -2
  166. package/dist/work-queue/index.d.ts +3 -2
  167. package/dist/work-queue/index.js +1 -1
  168. package/dist/work-queue/index.js.map +1 -1
  169. package/dist/work-queue/ops.d.ts +2 -2
  170. package/dist/work-queue/ops.js +1 -1
  171. package/dist/workflow/index.d.ts +51 -19
  172. package/dist/workflow/index.js +71 -52
  173. package/dist/workflow/index.js.map +1 -1
  174. package/package.json +4 -1
  175. package/dist/chunk-2YOE5PIS.js.map +0 -1
  176. package/dist/chunk-3545BOYL.js.map +0 -1
  177. package/dist/chunk-5VNWZADP.js.map +0 -1
  178. package/dist/chunk-6GIGQT6C.js.map +0 -1
  179. package/dist/chunk-6VDCTR7N.js.map +0 -1
  180. package/dist/chunk-DYRKDCJI.js.map +0 -1
  181. package/dist/chunk-EGWTT5XJ.js.map +0 -1
  182. package/dist/chunk-EMJTPHI7.js +0 -91
  183. package/dist/chunk-EMJTPHI7.js.map +0 -1
  184. package/dist/chunk-FOGL3TC7.js.map +0 -1
  185. package/dist/chunk-IK4S5DJN.js.map +0 -1
  186. package/dist/chunk-M6UZT7HS.js.map +0 -1
  187. package/dist/chunk-NSDFA6M6.js +0 -198
  188. package/dist/chunk-NSDFA6M6.js.map +0 -1
  189. package/dist/chunk-SC3FAFZN.js.map +0 -1
  190. package/dist/chunk-SKAMZKTE.js +0 -20
  191. package/dist/chunk-SKAMZKTE.js.map +0 -1
  192. package/dist/chunk-TGG26XMK.js.map +0 -1
  193. package/dist/chunk-UV6UWGEO.js.map +0 -1
  194. package/dist/chunk-UYWUVEP6.js.map +0 -1
  195. package/dist/chunk-VFGKTGGC.js.map +0 -1
  196. package/dist/chunk-ZDRN3YCE.js.map +0 -1
@@ -1,21 +1,21 @@
1
- import { Store, Runtime, BootingRuntime } from '../index.js';
2
- import { P as PendingEffectsRecorder, b as EffectOwed, a as EffectConfirmed } from '../durable-effects-9LxFpmh3.js';
3
- export { D as DeliveryId, E as EffectLedgerEvent, O as OwedEffect, d as PendingEffectsLedger, c as applyEffectEvent, e as emptyLedger, f as foldLedger, i as isOwed, p as pendingEffectsLedger, s as survivingEffects } from '../durable-effects-9LxFpmh3.js';
1
+ import { S as Store, R as Runtime, B as BootingRuntime } from '../runtime-types-gsog27b6.js';
2
+ import { P as PendingEffectsRecorder, b as EffectOwed, a as EffectConfirmed } from '../durable-effects-CFRngTNA.js';
3
+ export { D as DeliveryId, E as EffectLedgerEvent, O as OwedEffect, d as PendingEffectsLedger, c as applyEffectEvent, e as emptyLedger, f as foldLedger, i as isOwed, p as pendingEffectsLedger, s as survivingEffects } from '../durable-effects-CFRngTNA.js';
4
4
  import { RetryPolicy, Rng } from '../retry-backoff/index.js';
5
- import { C as Cmd, S as Sub, M as Machine } from '../core-BmlJOvxM.js';
6
- import { AgentEvent, AgentTurn, AgentState, AgentMachineMsg, AgentStatus } from '../agent/index.js';
7
- import '../fan-out/index.js';
8
- import '../work-queue/index.js';
5
+ import { C as Cmd, S as Sub, M as Machine } from '../core-42kapW0n.js';
6
+ import { y as AgentEvent, A as AgentTurn, N as AgentState, x as AgentMachineMsg, P as AgentStatus } from '../machine-B_BF4jij.js';
9
7
  import '../llm-call/index.js';
10
8
  import '../resilient-call/index.js';
11
9
  import '../cache/index.js';
12
- import '../types-BoUWgwSm.js';
10
+ import '../types-KbL3W1mj.js';
13
11
  import '../circuit-breaker/index.js';
14
12
  import '../deadline/index.js';
15
13
  import '../protocol-B5YmJr0d.js';
16
14
  import '../rate-limit/index.js';
17
15
  import '../monitored-run/index.js';
18
16
  import '../snapshot/index.js';
17
+ import '../work-queue/index.js';
18
+ import '../fan-out/index.js';
19
19
 
20
20
  /**
21
21
  * @demlik/tea/do — `stepHost`, the HTTP-PULL control carrier (#92).
@@ -275,7 +275,7 @@ interface DeferResumeHook<R> {
275
275
  * Optional advisory re-poll delay (ms) surfaced on the {@link StepWorking} arm
276
276
  * so the hands can back off to the host's expected step latency.
277
277
  */
278
- retryAfterMs?: number;
278
+ readonly retryAfterMs?: number;
279
279
  }
280
280
  /**
281
281
  * `StepHostConfig` with the defer-resume hook engaged — the presence of
@@ -774,6 +774,18 @@ interface ProjectionId {
774
774
  }
775
775
  /** Render a `ProjectionId` to its canonical `name-key` string. */
776
776
  declare function projectionIdString(id: ProjectionId): string;
777
+ /** Context handed to a {@link ProjectionOnError} sink alongside the throw. */
778
+ interface ProjectionErrorContext {
779
+ /** The id of the projection whose `apply`/`emit` threw. */
780
+ readonly id: ProjectionId;
781
+ }
782
+ /**
783
+ * Sink for a projection `apply`/`emit` throw the driver isolated. Injected into
784
+ * {@link projectionRegistry}; called with the original error and the id of the
785
+ * failing projection so a broken projection surfaces instead of being silently
786
+ * discarded (errors-are-data). Should be total.
787
+ */
788
+ type ProjectionOnError = (error: unknown, context: ProjectionErrorContext) => void;
777
789
  /**
778
790
  * One unit the projection driver presents to a projection's `apply`. Mirrors
779
791
  * the `(msg, model)` pair `runtime.observe` fans out, plus the exclusive
@@ -862,9 +874,11 @@ interface ProjectionRunner<Model, Msg extends {
862
874
  * `startOffset` (the driver's offset guard enforces exclusivity even if an
863
875
  * already-applied update is re-presented).
864
876
  *
865
- * `emitOnStart`/`emitOnReset` default false: a fresh runner holds `initial` but
866
- * does not push it at the sink until the first real update lands (an SSE client
867
- * that just connected wants the next event, not a replay of the seed).
877
+ * The runner never emits the seed: a fresh runner holds `initial` but does not
878
+ * push it at the sink until the first real update lands (an SSE client that just
879
+ * connected wants the next event, not a replay of the seed), and `reset()`
880
+ * likewise re-seeds `view`/`offset` silently — `emit` fires only from `present`
881
+ * when a strictly-newer update is folded.
868
882
  */
869
883
  declare function runProjection<Model, Msg extends {
870
884
  type: string;
@@ -883,7 +897,8 @@ interface ProjectionRegistry<Model, Msg extends {
883
897
  * Present one update to EVERY registered runner. Each folds independently; an
884
898
  * `apply`/`emit` throw in one runner is caught so it cannot strand the others
885
899
  * (errors-are-data: a broken projection is dropped from THIS update, not
886
- * allowed to corrupt siblings). Returns the offset assigned to this update.
900
+ * allowed to corrupt siblings) and routed to the registry's `onError` sink so
901
+ * it surfaces rather than vanishing. Returns the offset assigned to this update.
887
902
  */
888
903
  dispatch(msg: Msg | null, model: Model): number;
889
904
  /** The current monotonic offset (the last dispatched update's position). */
@@ -891,10 +906,15 @@ interface ProjectionRegistry<Model, Msg extends {
891
906
  /** The registered runners (introspection / tests). */
892
907
  runners(): readonly ProjectionRunner<Model, Msg, unknown>[];
893
908
  }
894
- /** Build an empty {@link ProjectionRegistry}. */
909
+ /**
910
+ * Build an empty {@link ProjectionRegistry}. Pass an `onError` sink to receive
911
+ * any `apply`/`emit` throw the driver isolates — without it a broken projection
912
+ * is still isolated from its siblings, but its failure is not surfaced (the
913
+ * substrate's `run(machine, { onError })` is the natural source to forward).
914
+ */
895
915
  declare function projectionRegistry<Model, Msg extends {
896
916
  type: string;
897
- }>(): ProjectionRegistry<Model, Msg>;
917
+ }>(onError?: ProjectionOnError): ProjectionRegistry<Model, Msg>;
898
918
  /**
899
919
  * Wire a {@link ProjectionRegistry} to a runtime's transition stream. The boot
900
920
  * update (the initial state, offset 0) is presented via `onBoot`; every applied
@@ -1149,6 +1169,11 @@ declare function acceptCommandSocket(clients: Set<WebSocket>, onFrame: (data: st
1149
1169
  * Broadcast a JSON frame to every connected command-runner socket. A dead
1150
1170
  * socket is skipped (dropped on its own `close` event). Lifts the consumer's
1151
1171
  * fan-out loop in `sendCommand`.
1172
+ *
1173
+ * Thin delegation to {@link broadcastFrame} — the general fan-out (serialize
1174
+ * once, send to every OPEN socket, skip a closed/errored one). The
1175
+ * {@link BroadcastReport} it returns is discarded here to keep the `void`
1176
+ * command-socket signature.
1152
1177
  */
1153
1178
  declare function broadcast(clients: Set<WebSocket>, frame: unknown): void;
1154
1179
  /**
@@ -1180,6 +1205,11 @@ declare function acceptDurableCommandSocket(ctx: HibernatableCtx): Response;
1180
1205
  * set is read from `ctx.getWebSockets()` (the runtime repopulates it after a
1181
1206
  * wake), NOT a resident `Set<WebSocket>` — so it is correct immediately after an
1182
1207
  * eviction, before any other lifecycle method has run. A dead socket is skipped.
1208
+ *
1209
+ * Thin delegation to {@link broadcastFrame} over `ctx.getWebSockets()` — the
1210
+ * general fan-out (serialize once, send to every OPEN socket, skip a
1211
+ * closed/errored one). The {@link BroadcastReport} it returns is discarded here
1212
+ * to keep the `void` command-socket signature.
1183
1213
  */
1184
1214
  declare function broadcastHibernatable(ctx: HibernatableCtx, frame: unknown): void;
1185
1215
 
@@ -1274,16 +1304,13 @@ declare function durableDeferredGateway<R>(inner: DeferredGateway<R>, recorder:
1274
1304
  * the consumer reads its persisted ledger events back and calls
1275
1305
  * `reissueSurvivingEffects` (see `./resume`) to re-fire the survivors.
1276
1306
  *
1277
- * It extends `DurableDeferredGateway` (so it is a drop-in for the gateway the
1307
+ * It IS a `DurableDeferredGateway` (so it is a drop-in for the gateway the
1278
1308
  * interpret cell already awaits) and exposes the underlying `recorder` for a
1279
- * host that wants to read `surviving()` directly.
1309
+ * host that wants to read `surviving()` directly. The #91 "command carrier"
1310
+ * concept is exactly the durable gateway under a domain name — a type alias, not
1311
+ * a second byte-identical interface that could drift.
1280
1312
  */
1281
- interface DurableCommandCarrier<R> extends DeferredGateway<R> {
1282
- /** The ledger recorder backing this carrier (for `surviving()` introspection). */
1283
- readonly recorder: PendingEffectsRecorder<{
1284
- callId: string;
1285
- }>;
1286
- }
1313
+ type DurableCommandCarrier<R> = DurableDeferredGateway<R>;
1287
1314
  /**
1288
1315
  * Build a durable command carrier over a (volatile) `DeferredGateway<R>` and a
1289
1316
  * `PendingEffectsRecorder`. Thin assembly over {@link durableDeferredGateway}:
@@ -1784,6 +1811,7 @@ declare function acceptPresenceSocket<A>(ctx: PresenceCtx, options?: RegisterOpt
1784
1811
  declare function presenceCount(ctx: PresenceCtx, tag?: string): number;
1785
1812
 
1786
1813
  /**
1814
+ * @packageDocumentation
1787
1815
  * @demlik/tea/do — Durable Object adapter for `@demlik/tea`.
1788
1816
  *
1789
1817
  * The integration is built on ONE transport model and one durability primitive:
@@ -1879,4 +1907,4 @@ interface DoStoreOptions<S> {
1879
1907
  */
1880
1908
  declare function doStore<S>(storage: DurableObjectStorage, parse: (raw: unknown) => S | null, keyOrOptions?: string | DoStoreOptions<S>): Store<S>;
1881
1909
 
1882
- export { type AgentHost, type AgentHostConfig, type AlarmStorage, type AppliedEffects, type AppliedEffectsEvent, type AppliedEffectsGuard, type AttachableSocket, type BroadcastOptions, type BroadcastReport, type DeferResumeHook, type DeferStepHostConfig, type DeferredGateway, type DeferredStepOutcome, type DeferredStepResponse, type DoStoreOptions, type DurableCommandCarrier, type DurableTimer, type DurableTimerConfig, type EffectApplied, EffectConfirmed, type EffectForgotten, type EffectKey, EffectOwed, type EventLogRange, type EventSourcedOptions, type EventSourcedStore, type ExecuteStep, type HibernatableCtx, type IdempotentEffect, type IdempotentOutcome, type NextStep, PendingEffectsRecorder, type PersistedEvent, type PresenceCtx, type PresenceSocket, type PresenceUpgrade, type Projection, type ProjectionId, type ProjectionRegistry, type ProjectionRunner, type ProjectionUpdate, type RegisterOptions, type ResumePort, type RunStepLoopConfig, type SseHub, type StepCtx, type StepEngine, type StepHostConfig, type StepLoopOutcome, type StepOutcome, type StepRequest, type StepResponse, type StepResult, type StepTransport, type StepWorking, WS_READY_STATE_OPEN, acceptCommandSocket, acceptDurableCommandSocket, acceptPresenceSocket, agentIsResumable, appliedEffects, applyAppliedEvent, autoBoot, bootResume, broadcast, broadcastFrame, broadcastHibernatable, constantTimeEqual, createAgentHost, deferredGateway, doEventSourcedStore, doStore, driveProjections, durableCommandCarrier, durableDeferredGateway, durableTimer, emptyApplied, foldApplied, idempotentEffect, isApplied, mintRunToken, presenceCount, projectionIdString, projectionRegistry, rebuildProjection, registerHibernatableSocket, reissueSurvivingEffects, runProjection, runStepLoop, sseFromAgentEvents, sseHub, sseProjection, stepHost };
1910
+ export { type AgentHost, type AgentHostConfig, type AlarmStorage, type AppliedEffects, type AppliedEffectsEvent, type AppliedEffectsGuard, type AttachableSocket, type BroadcastOptions, type BroadcastReport, type DeferResumeHook, type DeferStepHostConfig, type DeferredGateway, type DeferredStepOutcome, type DeferredStepResponse, type DoStoreOptions, type DurableCommandCarrier, type DurableTimer, type DurableTimerConfig, type EffectApplied, EffectConfirmed, type EffectForgotten, type EffectKey, EffectOwed, type EventLogRange, type EventSourcedOptions, type EventSourcedStore, type ExecuteStep, type HibernatableCtx, type IdempotentEffect, type IdempotentOutcome, type NextStep, PendingEffectsRecorder, type PersistedEvent, type PresenceCtx, type PresenceSocket, type PresenceUpgrade, type Projection, type ProjectionErrorContext, type ProjectionId, type ProjectionOnError, type ProjectionRegistry, type ProjectionRunner, type ProjectionUpdate, type RegisterOptions, type ResumePort, type RunStepLoopConfig, type SseHub, type StepCtx, type StepEngine, type StepHostConfig, type StepLoopOutcome, type StepOutcome, type StepRequest, type StepResponse, type StepResult, type StepTransport, type StepWorking, WS_READY_STATE_OPEN, acceptCommandSocket, acceptDurableCommandSocket, acceptPresenceSocket, agentIsResumable, appliedEffects, applyAppliedEvent, autoBoot, bootResume, broadcast, broadcastFrame, broadcastHibernatable, constantTimeEqual, createAgentHost, deferredGateway, doEventSourcedStore, doStore, driveProjections, durableCommandCarrier, durableDeferredGateway, durableTimer, emptyApplied, foldApplied, idempotentEffect, isApplied, mintRunToken, presenceCount, projectionIdString, projectionRegistry, rebuildProjection, registerHibernatableSocket, reissueSurvivingEffects, runProjection, runStepLoop, sseFromAgentEvents, sseHub, sseProjection, stepHost };
package/dist/do/index.js CHANGED
@@ -1,25 +1,27 @@
1
- import { status, agentBootMsg, agentEvents } from '../chunk-VFGKTGGC.js';
2
- export { applyEffectEvent, emptyLedger, foldLedger, isOwed, pendingEffectsLedger, survivingEffects } from '../chunk-3545BOYL.js';
3
- import '../chunk-ZDRN3YCE.js';
4
- import '../chunk-M6UZT7HS.js';
5
- import '../chunk-5KVHID6A.js';
6
- import '../chunk-6GIGQT6C.js';
1
+ import { status, agentBootMsg, agentEvents } from '../chunk-WGGAMW7Y.js';
2
+ export { applyEffectEvent, emptyLedger, foldLedger, isOwed, pendingEffectsLedger, survivingEffects } from '../chunk-25LBDCBC.js';
3
+ import '../chunk-CAXMQJJ3.js';
4
+ import '../chunk-VBUCHVCV.js';
5
+ import '../chunk-MVY5DAMF.js';
6
+ import '../chunk-IXBKFQH5.js';
7
7
  import '../chunk-JELSZN25.js';
8
- import '../chunk-UV6UWGEO.js';
9
- import { createIntake } from '../chunk-LEC4U6CX.js';
10
- import '../chunk-SKAMZKTE.js';
11
- import { defaultRetryPolicy, initRetry, recordFailure, shouldRetry, nextDelayMs } from '../chunk-5VNWZADP.js';
12
- import '../chunk-2YOE5PIS.js';
8
+ import '../chunk-D736QUGF.js';
9
+ import { createIntake } from '../chunk-ZVJZ72HY.js';
10
+ import '../chunk-RMX4EOQK.js';
11
+ import { defaultRetryPolicy, initRetry, recordFailure, shouldRetry, nextDelayMs } from '../chunk-Q2UM7BXU.js';
12
+ import '../chunk-S2EGRPCM.js';
13
13
  import '../chunk-BYQUGDD3.js';
14
14
  import '../chunk-K575PT4S.js';
15
- import '../chunk-SC3FAFZN.js';
16
- import '../chunk-IN33Q4VJ.js';
17
- import '../chunk-HJO6VNQI.js';
18
- import '../chunk-TGG26XMK.js';
19
- import '../chunk-NSDFA6M6.js';
15
+ import '../chunk-UF4MZSLT.js';
16
+ import '../chunk-2KNLKQVN.js';
17
+ import '../chunk-MU6MCIAC.js';
18
+ import '../chunk-FV3Z5MBE.js';
19
+ import '../chunk-LYLDCIPH.js';
20
20
  import '../chunk-2YFLOCWX.js';
21
- import { run, replay } from '../chunk-6VDCTR7N.js';
22
- import '../chunk-DYRKDCJI.js';
21
+ import '../chunk-ZJ5AOYBH.js';
22
+ import '../chunk-G5E74IJB.js';
23
+ import { replay, run } from '../chunk-BP2R7TPP.js';
24
+ import '../chunk-PBDYW2TU.js';
23
25
 
24
26
  // src/do/durable-timer.ts
25
27
  function durableTimer(config) {
@@ -69,6 +71,10 @@ function doEventSourcedStore(storage, machine, ctx, opts = {}) {
69
71
  const meta = JSON.parse(raw);
70
72
  return typeof meta.lastSeq === "number" ? meta.lastSeq : 0;
71
73
  }
74
+ async function ensureLastSeq() {
75
+ if (lastSeq === null) lastSeq = await readMeta();
76
+ return lastSeq;
77
+ }
72
78
  async function readSnapshot() {
73
79
  const raw = await storage.get(snapshotKey);
74
80
  if (raw === void 0 || raw === null) return { state: null, seq: 0 };
@@ -126,8 +132,7 @@ function doEventSourcedStore(storage, machine, ctx, opts = {}) {
126
132
  snapshotSeq = seq;
127
133
  }
128
134
  async function append(msg) {
129
- if (lastSeq === null) lastSeq = await readMeta();
130
- const seq = lastSeq + 1;
135
+ const seq = await ensureLastSeq() + 1;
131
136
  lastSeq = seq;
132
137
  await storage.put(eventKey(eventPrefix, seq), JSON.stringify(msg));
133
138
  await storage.put(
@@ -139,9 +144,9 @@ function doEventSourcedStore(storage, machine, ctx, opts = {}) {
139
144
  }
140
145
  }
141
146
  async function snapshotNow() {
142
- if (lastSeq === null) lastSeq = await readMeta();
143
- if (latestState === null || lastSeq <= snapshotSeq) return false;
144
- await writeSnapshot(lastSeq, latestState);
147
+ const seq = await ensureLastSeq();
148
+ if (latestState === null || seq <= snapshotSeq) return false;
149
+ await writeSnapshot(seq, latestState);
145
150
  return true;
146
151
  }
147
152
  return { store, append, snapshotNow, readEvents };
@@ -252,8 +257,7 @@ function createAgentHost(config) {
252
257
  const now = config.now ?? Date.now;
253
258
  const isTerminal = config.terminal ?? ((s) => s.run.phase === "done" || s.run.phase === "failed");
254
259
  let cached = null;
255
- async function runtime() {
256
- if (cached !== null) return cached;
260
+ async function build() {
257
261
  const booting = run(config.buildMachine(), {
258
262
  ctx: config.ctx,
259
263
  store: config.store,
@@ -262,7 +266,15 @@ function createAgentHost(config) {
262
266
  });
263
267
  sseFromAgentEvents(booting, sse, config.toSseFrame);
264
268
  await autoBoot(booting, now);
265
- cached = await booting.ready;
269
+ return booting.ready;
270
+ }
271
+ function runtime() {
272
+ if (cached !== null) return cached;
273
+ const building = build();
274
+ cached = building;
275
+ building.catch(() => {
276
+ if (cached === building) cached = null;
277
+ });
266
278
  return cached;
267
279
  }
268
280
  return {
@@ -276,12 +288,62 @@ function createAgentHost(config) {
276
288
  sse,
277
289
  async reset() {
278
290
  if (cached === null) return;
279
- await cached.stop();
291
+ const built = await cached.catch(() => null);
280
292
  cached = null;
293
+ await built?.stop();
281
294
  }
282
295
  };
283
296
  }
284
297
 
298
+ // src/do/presence.ts
299
+ var WS_READY_STATE_OPEN = 1;
300
+ function broadcastFrame(sockets, frame, options) {
301
+ const serialize = options?.serialize ?? JSON.stringify;
302
+ const except = options?.except;
303
+ const json = serialize(frame);
304
+ let sent = 0;
305
+ let skipped = 0;
306
+ for (const ws of sockets) {
307
+ if (except !== void 0 && ws === except) {
308
+ skipped++;
309
+ continue;
310
+ }
311
+ if (ws.readyState !== void 0 && ws.readyState !== WS_READY_STATE_OPEN) {
312
+ skipped++;
313
+ continue;
314
+ }
315
+ try {
316
+ ws.send(json);
317
+ sent++;
318
+ } catch {
319
+ skipped++;
320
+ }
321
+ }
322
+ return { sent, skipped };
323
+ }
324
+ function registerHibernatableSocket(ctx, server, options) {
325
+ ctx.acceptWebSocket(
326
+ server,
327
+ options?.tags === void 0 ? void 0 : [...options.tags]
328
+ );
329
+ if (options?.attachment !== void 0) {
330
+ server.serializeAttachment(options.attachment);
331
+ }
332
+ }
333
+ function acceptPresenceSocket(ctx, options) {
334
+ const pair = new WebSocketPair();
335
+ const client = pair[0];
336
+ const server = pair[1];
337
+ registerHibernatableSocket(ctx, server, options);
338
+ return {
339
+ server,
340
+ response: new Response(null, { status: 101, webSocket: client })
341
+ };
342
+ }
343
+ function presenceCount(ctx, tag) {
344
+ return ctx.getWebSockets(tag).length;
345
+ }
346
+
285
347
  // src/do/command-socket.ts
286
348
  function acceptCommandSocket(clients, onFrame) {
287
349
  const pair = new WebSocketPair();
@@ -295,13 +357,7 @@ function acceptCommandSocket(clients, onFrame) {
295
357
  return new Response(null, { status: 101, webSocket: client });
296
358
  }
297
359
  function broadcast(clients, frame) {
298
- const json = JSON.stringify(frame);
299
- for (const ws of clients) {
300
- try {
301
- ws.send(json);
302
- } catch {
303
- }
304
- }
360
+ broadcastFrame(clients, frame);
305
361
  }
306
362
  function acceptDurableCommandSocket(ctx) {
307
363
  const pair = new WebSocketPair();
@@ -310,13 +366,7 @@ function acceptDurableCommandSocket(ctx) {
310
366
  return new Response(null, { status: 101, webSocket: client });
311
367
  }
312
368
  function broadcastHibernatable(ctx, frame) {
313
- const json = JSON.stringify(frame);
314
- for (const ws of ctx.getWebSockets()) {
315
- try {
316
- ws.send(json);
317
- } catch {
318
- }
319
- }
369
+ broadcastFrame(ctx.getWebSockets(), frame);
320
370
  }
321
371
 
322
372
  // src/do/deferred-gateway.ts
@@ -461,55 +511,6 @@ function appliedEffects(restore) {
461
511
  };
462
512
  }
463
513
 
464
- // src/do/presence.ts
465
- var WS_READY_STATE_OPEN = 1;
466
- function broadcastFrame(sockets, frame, options) {
467
- const serialize = options?.serialize ?? JSON.stringify;
468
- const except = options?.except;
469
- const json = serialize(frame);
470
- let sent = 0;
471
- let skipped = 0;
472
- for (const ws of sockets) {
473
- if (except !== void 0 && ws === except) {
474
- skipped++;
475
- continue;
476
- }
477
- if (ws.readyState !== void 0 && ws.readyState !== WS_READY_STATE_OPEN) {
478
- skipped++;
479
- continue;
480
- }
481
- try {
482
- ws.send(json);
483
- sent++;
484
- } catch {
485
- skipped++;
486
- }
487
- }
488
- return { sent, skipped };
489
- }
490
- function registerHibernatableSocket(ctx, server, options) {
491
- ctx.acceptWebSocket(
492
- server,
493
- options?.tags === void 0 ? void 0 : [...options.tags]
494
- );
495
- if (options?.attachment !== void 0) {
496
- server.serializeAttachment(options.attachment);
497
- }
498
- }
499
- function acceptPresenceSocket(ctx, options) {
500
- const pair = new WebSocketPair();
501
- const client = pair[0];
502
- const server = pair[1];
503
- registerHibernatableSocket(ctx, server, options);
504
- return {
505
- server,
506
- response: new Response(null, { status: 101, webSocket: client })
507
- };
508
- }
509
- function presenceCount(ctx, tag) {
510
- return ctx.getWebSockets(tag).length;
511
- }
512
-
513
514
  // src/do/projection.ts
514
515
  function projectionIdString(id) {
515
516
  return `${id.name}-${id.key}`;
@@ -535,7 +536,7 @@ function runProjection(projection, startOffset = 0) {
535
536
  }
536
537
  };
537
538
  }
538
- function projectionRegistry() {
539
+ function projectionRegistry(onError) {
539
540
  const runners = /* @__PURE__ */ new Set();
540
541
  let counter = -1;
541
542
  return {
@@ -550,7 +551,8 @@ function projectionRegistry() {
550
551
  for (const runner of runners) {
551
552
  try {
552
553
  runner.present(update);
553
- } catch {
554
+ } catch (err) {
555
+ onError?.(err, { id: runner.id });
554
556
  }
555
557
  }
556
558
  return offset;