@demlik/tea 0.14.0 → 0.16.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 (116) hide show
  1. package/README.md +30 -7
  2. package/dist/agent/index.d.ts +49 -36
  3. package/dist/agent/index.js +12 -8
  4. package/dist/chunk-4LPY67E4.js +18 -0
  5. package/dist/chunk-4LPY67E4.js.map +1 -0
  6. package/dist/chunk-5XU6ZJO2.js +533 -0
  7. package/dist/chunk-5XU6ZJO2.js.map +1 -0
  8. package/dist/{chunk-AQ6ZIMEA.js → chunk-6NG4V5SB.js} +89 -115
  9. package/dist/chunk-6NG4V5SB.js.map +1 -0
  10. package/dist/{chunk-HYDWG35Q.js → chunk-7MGXQZPW.js} +11 -9
  11. package/dist/chunk-7MGXQZPW.js.map +1 -0
  12. package/dist/{chunk-BLJ2JQSH.js → chunk-BCTEOVOU.js} +3 -3
  13. package/dist/{chunk-BLJ2JQSH.js.map → chunk-BCTEOVOU.js.map} +1 -1
  14. package/dist/chunk-CH5KTOEZ.js +710 -0
  15. package/dist/chunk-CH5KTOEZ.js.map +1 -0
  16. package/dist/chunk-CIHSHLQX.js +64 -0
  17. package/dist/chunk-CIHSHLQX.js.map +1 -0
  18. package/dist/{chunk-Z2L3LSNV.js → chunk-EHUDXAKC.js} +246 -210
  19. package/dist/chunk-EHUDXAKC.js.map +1 -0
  20. package/dist/chunk-GOX2CYIM.js +380 -0
  21. package/dist/chunk-GOX2CYIM.js.map +1 -0
  22. package/dist/chunk-IVJP3GKJ.js +104 -0
  23. package/dist/chunk-IVJP3GKJ.js.map +1 -0
  24. package/dist/{chunk-F7FMAWLA.js → chunk-MVZS5FDM.js} +13 -6
  25. package/dist/chunk-MVZS5FDM.js.map +1 -0
  26. package/dist/{chunk-LYLTKJWM.js → chunk-MYNLY3HP.js} +9 -8
  27. package/dist/chunk-MYNLY3HP.js.map +1 -0
  28. package/dist/{chunk-I5MQMJDW.js → chunk-NSIAORRY.js} +20 -30
  29. package/dist/chunk-NSIAORRY.js.map +1 -0
  30. package/dist/{chunk-MYXFNWAJ.js → chunk-QNGYQMZB.js} +4 -4
  31. package/dist/chunk-QNGYQMZB.js.map +1 -0
  32. package/dist/chunk-WT5PBPLB.js +98 -0
  33. package/dist/chunk-WT5PBPLB.js.map +1 -0
  34. package/dist/{core-CTzMJ82M.d.ts → core-BbgtiXdg.d.ts} +231 -139
  35. package/dist/do/index.d.ts +37 -32
  36. package/dist/do/index.js +21 -14
  37. package/dist/do/index.js.map +1 -1
  38. package/dist/{durable-effects-B0-qGQDy.d.ts → durable-effects-7MTK_jnj.d.ts} +1 -1
  39. package/dist/effect/index.d.ts +151 -0
  40. package/dist/effect/index.js +98 -0
  41. package/dist/effect/index.js.map +1 -0
  42. package/dist/extension/index.d.ts +6 -7
  43. package/dist/extension/index.js +3 -2
  44. package/dist/extension/index.js.map +1 -1
  45. package/dist/flow/index.d.ts +68 -70
  46. package/dist/flow/index.js +32 -27
  47. package/dist/flow/index.js.map +1 -1
  48. package/dist/idempotency/index.d.ts +6 -7
  49. package/dist/idempotency/index.js +4 -2
  50. package/dist/{index-DJWIER_3.d.ts → index-7vV8xmsD.d.ts} +1 -1
  51. package/dist/{index-NjrT3fL2.d.ts → index-Bz5Rh9Ga.d.ts} +19 -96
  52. package/dist/index-CjFDUBeq.d.ts +207 -0
  53. package/dist/{index-6A7dB8f6.d.ts → index-CkFYA9Y6.d.ts} +14 -16
  54. package/dist/{index-B5BZ-_cT.d.ts → index-Cou86-GX.d.ts} +189 -108
  55. package/dist/{index-TvRb1KVf.d.ts → index-DU6JpQ8G.d.ts} +1 -1
  56. package/dist/{index-q0hXFeZ0.d.ts → index-Xufl55W8.d.ts} +286 -215
  57. package/dist/{index-4vZzljCD.d.ts → index-_dOR3xqA.d.ts} +57 -45
  58. package/dist/index.d.ts +181 -385
  59. package/dist/index.js +2 -1
  60. package/dist/jev/index.d.ts +147 -99
  61. package/dist/jev/index.js +329 -233
  62. package/dist/jev/index.js.map +1 -1
  63. package/dist/{machine-CdIcN2Xm.d.ts → machine-BQzTV8On.d.ts} +171 -280
  64. package/dist/machine-viz/index.d.ts +5 -5
  65. package/dist/machine-viz/index.js +8 -4
  66. package/dist/machine-viz/index.js.map +1 -1
  67. package/dist/mem/index.d.ts +3 -4
  68. package/dist/mem/index.js +2 -1
  69. package/dist/mem/index.js.map +1 -1
  70. package/dist/node/index.d.ts +119 -78
  71. package/dist/node/index.js +52 -38
  72. package/dist/node/index.js.map +1 -1
  73. package/dist/paginate/index.d.ts +27 -33
  74. package/dist/paginate/index.js +6 -4
  75. package/dist/parity/index.d.ts +4 -5
  76. package/dist/parity/index.js +3 -2
  77. package/dist/parity/index.js.map +1 -1
  78. package/dist/pbt/index.d.ts +2 -2
  79. package/dist/pbt/index.js +2 -1
  80. package/dist/pbt/index.js.map +1 -1
  81. package/dist/persistence/index.d.ts +6 -7
  82. package/dist/persistence/index.js +5 -3
  83. package/dist/promise/index.d.ts +186 -0
  84. package/dist/promise/index.js +5 -0
  85. package/dist/promise/index.js.map +1 -0
  86. package/dist/protocol-ClRZBhHQ.d.ts +53 -0
  87. package/dist/react/index.d.ts +36 -17
  88. package/dist/react/index.js +27 -4
  89. package/dist/react/index.js.map +1 -1
  90. package/dist/resilience/index.d.ts +63 -455
  91. package/dist/resilience/index.js +37 -483
  92. package/dist/resilience/index.js.map +1 -1
  93. package/dist/{runtime-types-LWDoi943.d.ts → runtime-types-CiVpC0HN.d.ts} +131 -388
  94. package/dist/testing/index.d.ts +165 -15
  95. package/dist/testing/index.js +104 -3
  96. package/dist/testing/index.js.map +1 -1
  97. package/dist/timing/index.d.ts +25 -22
  98. package/dist/timing/index.js +4 -3
  99. package/dist/timing/index.js.map +1 -1
  100. package/dist/{types-DP3f5NIl.d.ts → types-LxZxGYda.d.ts} +2 -2
  101. package/dist/work-queue/index.d.ts +5 -6
  102. package/package.json +18 -5
  103. package/dist/chunk-AQ6ZIMEA.js.map +0 -1
  104. package/dist/chunk-F2US5BW6.js +0 -72
  105. package/dist/chunk-F2US5BW6.js.map +0 -1
  106. package/dist/chunk-F7FMAWLA.js.map +0 -1
  107. package/dist/chunk-HUKZQX6U.js +0 -97
  108. package/dist/chunk-HUKZQX6U.js.map +0 -1
  109. package/dist/chunk-HYDWG35Q.js.map +0 -1
  110. package/dist/chunk-I5MQMJDW.js.map +0 -1
  111. package/dist/chunk-LYLTKJWM.js.map +0 -1
  112. package/dist/chunk-MYXFNWAJ.js.map +0 -1
  113. package/dist/chunk-RQULHGYH.js +0 -1804
  114. package/dist/chunk-RQULHGYH.js.map +0 -1
  115. package/dist/chunk-Z2L3LSNV.js.map +0 -1
  116. package/dist/index-DMCeMPMJ.d.ts +0 -272
@@ -1,18 +1,18 @@
1
- import { S as Store, R as Runtime, B as BootingRuntime, F as FencedStore } from '../runtime-types-LWDoi943.js';
2
- import { P as PendingEffectsRecorder, b as EffectOwed, a as EffectConfirmed } from '../durable-effects-B0-qGQDy.js';
3
- export { D as DeliveryId, E as EffectLedgerEvent, O as OwedEffect, c as PendingEffectsLedger, d as applyEffectEvent, e as emptyLedger, f as foldLedger, i as isOwed, p as pendingEffectsLedger, s as survivingEffects } from '../durable-effects-B0-qGQDy.js';
1
+ import { S as Store, b as BootedRunHandle, E as EngineRun, c as RunHandle, F as FencedStore } from '../runtime-types-CiVpC0HN.js';
2
+ import { P as PendingEffectsRecorder, b as EffectOwed, a as EffectConfirmed } from '../durable-effects-7MTK_jnj.js';
3
+ export { D as DeliveryId, E as EffectLedgerEvent, O as OwedEffect, c as PendingEffectsLedger, d as applyEffectEvent, e as emptyLedger, f as foldLedger, i as isOwed, p as pendingEffectsLedger, s as survivingEffects } from '../durable-effects-7MTK_jnj.js';
4
4
  import { RetryPolicy, Rng } from '../retry-backoff/index.js';
5
- import { C as Cmd, S as Sub, M as Machine, R as RequiredCtx } from '../core-CTzMJ82M.js';
6
- import { g as AgentEvent, b as AgentTurn, c as AgentState, i as AgentMachineMsg, D as AgentStatus } from '../machine-CdIcN2Xm.js';
7
- import 'better-result';
8
- import 'zod';
9
- import '../index-NjrT3fL2.js';
10
- import '../index-DMCeMPMJ.js';
11
- import '../index-q0hXFeZ0.js';
12
- import '../types-DP3f5NIl.js';
13
- import '../index-DJWIER_3.js';
14
- import '../index-B5BZ-_cT.js';
15
- import '../index-6A7dB8f6.js';
5
+ import { C as Cmd, S as Sub, M as Machine, W as Wired } from '../core-BbgtiXdg.js';
6
+ import { g as AgentEvent, b as AgentTurn, c as AgentState, i as AgentMachineMsg, B as AgentStatus } from '../machine-BQzTV8On.js';
7
+ import '@standard-schema/spec';
8
+ import '../index-Bz5Rh9Ga.js';
9
+ import '../index-CjFDUBeq.js';
10
+ import '../index-Xufl55W8.js';
11
+ import '../types-LxZxGYda.js';
12
+ import '../index-7vV8xmsD.js';
13
+ import '../index-Cou86-GX.js';
14
+ import '../protocol-ClRZBhHQ.js';
15
+ import '../index-CkFYA9Y6.js';
16
16
 
17
17
  /**
18
18
  * @demlik/tea/do — `stepHost`, the HTTP-PULL control carrier (#92).
@@ -407,7 +407,7 @@ declare function runStepLoop<R, I, O>(token: string, runId: string, transport: S
407
407
  * and the vortex arena tick (`room.ts` `armTick` + `onTick`) replicates the
408
408
  * exact shape for the 18 Hz game clock. The two old `do_alarm`/`do_ws` Subs were
409
409
  * dropped (see `./index`'s historical note) because `toMachine` fixes the agent
410
- * machine's Sub type to `DeadlineSub`, so they could never union into a grain's
410
+ * machine's Sub type to `DeadlinesSub`, so they could never union into a grain's
411
411
  * Sub set — leaving the alarm re-arm a HOST concern with no first-class home.
412
412
  *
413
413
  * {@link durableTimer} is that home: a tiny, transport- and Msg-agnostic helper
@@ -1056,18 +1056,22 @@ declare function sseFromAgentEvents<R, Frame>(runtime: {
1056
1056
  */
1057
1057
  interface AgentHostConfig<Stage, P extends string, O extends Record<P, AgentTurn>, R, Frame, C extends Cmd = Cmd, U extends Sub = Sub, Ctx = unknown> {
1058
1058
  /**
1059
- * Build the wired agent machine. Called once per host build (per activation),
1060
- * AFTER the previous runtime — if any — was torn down. The consumer wires its
1061
- * per-tool interpret here (`agent.toMachine({ toolInterpret })`).
1059
+ * The engine's `run` — `run` from `@demlik/tea/promise`, or any engine's. The
1060
+ * host imports no engine; it boots the machine through this.
1062
1061
  */
1063
- readonly buildMachine: () => Machine<AgentState<Stage, P, O, R>, AgentMachineMsg<P, O, R>, C, U, Ctx>;
1064
- /** The durable `Store` for the agent slice (typically `doStore(storage, parse)`). */
1065
- readonly store: Store<AgentState<Stage, P, O, R>>;
1062
+ readonly run: EngineRun<AgentState<Stage, P, O, R>, AgentMachineMsg<P, O, R>, C, U, Ctx, AgentEvent<R>>;
1066
1063
  /**
1067
- * The Ctx the machine threads to its interpret cells — checked against
1068
- * `buildMachine`'s, plus every typed Cmd's `R` (what `run` itself demands).
1064
+ * Build the wired agent machine and the handlers it runs under — its
1065
+ * `interpret` table and `subscribe` runners (a machine carries none — #278,
1066
+ * #279). Called once per host build (per activation), AFTER the previous
1067
+ * runtime — if any — was torn down. The consumer wires its per-tool interpret
1068
+ * here, and `agent.toMachine({ toolInterpret })` already returns exactly this.
1069
1069
  */
1070
- readonly ctx: Ctx & RequiredCtx<C>;
1070
+ readonly buildMachine: () => Wired<AgentState<Stage, P, O, R>, AgentMachineMsg<P, O, R>, C, U, Ctx>;
1071
+ /** The durable `Store` for the agent slice (typically `doStore(storage, parse)`). */
1072
+ readonly store: Store<AgentState<Stage, P, O, R>>;
1073
+ /** The plain Ctx the machine threads to its interpret cells. */
1074
+ readonly ctx: Ctx;
1071
1075
  /**
1072
1076
  * The run-terminality predicate (#46) — what makes `result()` first-class.
1073
1077
  * Defaults to the agent's own terminal phases (`done` / `failed`).
@@ -1098,10 +1102,10 @@ interface AgentHost<Stage, P extends string, O extends Record<P, AgentTurn>, R,
1098
1102
  * Get (or build) the booted runtime. Build-once-boot-once: the first call
1099
1103
  * builds the machine, wires SSE off the semantic event stream, awaits the boot
1100
1104
  * gate, runs the `autoBoot` re-fire for a rehydrated suspended run, and caches
1101
- * the booted `Runtime`; subsequent calls return the cached handle. The single
1105
+ * the booted handle; subsequent calls return the cached handle. The single
1102
1106
  * assembly every consumer used to hand-roll in `getRuntime()`.
1103
1107
  */
1104
- runtime(): Promise<Runtime<AgentState<Stage, P, O, R>, AgentMachineMsg<P, O, R>, AgentEvent<R>>>;
1108
+ runtime(): Promise<BootedRunHandle<AgentState<Stage, P, O, R>, AgentMachineMsg<P, O, R>, AgentEvent<R>>>;
1105
1109
  /**
1106
1110
  * The agent's lifecycle status (#49) — the ONE typed channel a consumer reads
1107
1111
  * instead of re-deriving `run.phase` / `awaiting` by hand. Ensures the runtime
@@ -1137,6 +1141,7 @@ interface AgentHost<Stage, P extends string, O extends Record<P, AgentTurn>, R,
1137
1141
  *
1138
1142
  * @example
1139
1143
  * const host = createAgentHost<Stage, Purpose, Outputs, ClientResult, SseEvent>({
1144
+ * run, // from `@demlik/tea/promise`
1140
1145
  * buildMachine: () => agent.toMachine<Ctx>({ toolInterpret }),
1141
1146
  * store: doStore(storage, parse),
1142
1147
  * ctx,
@@ -1372,14 +1377,14 @@ interface ResumePort<S, M extends {
1372
1377
  * every DO-hosted machine otherwise re-derives.
1373
1378
  *
1374
1379
  * `await ready` is the single boot gate (issue #45): `getState()` is total only
1375
- * on the booted `Runtime`, so state cannot be inspected before boot populates
1376
- * it. `now` is injected (the sole boot clock read) so a test can pin it.
1380
+ * on the booted handle, so state cannot be inspected before boot populates
1381
+ * it. Takes any engine's {@link RunHandle}. `now` is injected (the sole boot clock read) so a test can pin it.
1377
1382
  */
1378
1383
  declare function bootResume<S, M extends {
1379
1384
  type: string;
1380
1385
  }, E extends {
1381
1386
  type: string;
1382
- } = never>(booting: BootingRuntime<S, M, E>, port: ResumePort<S, M>, now?: () => number): Promise<void>;
1387
+ } = never>(booting: RunHandle<S, M, E>, port: ResumePort<S, M>, now?: () => number): Promise<void>;
1383
1388
  /**
1384
1389
  * True iff an agent slice loaded from storage is mid-loop (running + awaiting
1385
1390
  * tools) — the resumable case `agent_boot` re-fires.
@@ -1403,7 +1408,7 @@ declare function agentIsResumable<Stage, P extends string, O extends Record<P, u
1403
1408
  */
1404
1409
  declare function autoBoot<Stage, P extends string, O extends Record<P, unknown>, R, E extends {
1405
1410
  type: string;
1406
- } = never>(booting: BootingRuntime<AgentState<Stage, P, O, R>, AgentMachineMsg<P, O, R>, E>, now?: () => number): Promise<void>;
1411
+ } = never>(booting: RunHandle<AgentState<Stage, P, O, R>, AgentMachineMsg<P, O, R>, E>, now?: () => number): Promise<void>;
1407
1412
  /**
1408
1413
  * Re-fire every round-trip a rehydrated actor still owes, on wake. Given a
1409
1414
  * durable carrier whose recorder was rehydrated from the persisted ledger
@@ -1833,7 +1838,7 @@ declare function presenceCount(ctx: PresenceCtx, tag?: string): number;
1833
1838
  *
1834
1839
  * 2. `deferredGateway` + `createAgentHost` (from `./host`) — THE transport for
1835
1840
  * a DO-hosted agent. A `createAgent().toMachine()` machine owns exactly one
1836
- * Sub type, `DeadlineSub` (the agent's own retry + watchdog timers); it has
1841
+ * Sub type, `DeadlinesSub` (the agent's own retry + watchdog timers); it has
1837
1842
  * no DO-native Sub variant to compose, and it needs none. The gateway owns
1838
1843
  * each deferred tool round-trip as a Promise the interpret cell awaits:
1839
1844
  * - Inbound WebSocket frames are bridged straight into `gateway.settle(...)`
@@ -1847,7 +1852,7 @@ declare function presenceCount(ctx: PresenceCtx, tag?: string): number;
1847
1852
  *
1848
1853
  * (Historical note: this module previously also shipped `do_ws` / `do_alarm`
1849
1854
  * Subs + a `doSubscribe` registry. Because `toMachine` fixes the agent machine's
1850
- * Sub type to `DeadlineSub`, those Subs could never union into an agent host's
1855
+ * Sub type to `DeadlinesSub`, those Subs could never union into an agent host's
1851
1856
  * Sub set — they were structurally unusable by the flagship consumer and had no
1852
1857
  * callers. They were dropped in favor of the gateway as the single transport.)
1853
1858
  */
package/dist/do/index.js CHANGED
@@ -1,16 +1,20 @@
1
- import { status, agentBootMsg, agentEvents } from '../chunk-Z2L3LSNV.js';
2
- import { createIntake } from '../chunk-LYLTKJWM.js';
1
+ import { status, agentBootMsg, agentEvents } from '../chunk-EHUDXAKC.js';
2
+ import '../chunk-G5E74IJB.js';
3
+ import { createIntake } from '../chunk-MYNLY3HP.js';
3
4
  export { applyEffectEvent, emptyLedger, foldLedger, isOwed, pendingEffectsLedger, survivingEffects } from '../chunk-6IQPODUF.js';
4
- import '../chunk-HYDWG35Q.js';
5
- import '../chunk-MYXFNWAJ.js';
5
+ import '../chunk-7MGXQZPW.js';
6
+ import '../chunk-CIHSHLQX.js';
7
+ import '../chunk-QNGYQMZB.js';
6
8
  import '../chunk-PR6TB3BL.js';
7
9
  import '../chunk-TXN2KFHF.js';
8
- import '../chunk-HUKZQX6U.js';
9
- import '../chunk-AQ6ZIMEA.js';
10
+ import '../chunk-6NG4V5SB.js';
10
11
  import { defaultRetryPolicy, initRetry, recordFailure, shouldRetry, nextDelayMs } from '../chunk-VBDU4JL6.js';
11
- import '../chunk-F2US5BW6.js';
12
- import '../chunk-G5E74IJB.js';
13
- import { StoreConflictError, replay, run } from '../chunk-RQULHGYH.js';
12
+ import '../chunk-4LPY67E4.js';
13
+ import '../chunk-IVJP3GKJ.js';
14
+ import '../chunk-WT5PBPLB.js';
15
+ import '../chunk-5XU6ZJO2.js';
16
+ import '../chunk-GOX2CYIM.js';
17
+ import { StoreConflictError, replay } from '../chunk-CH5KTOEZ.js';
14
18
 
15
19
  // src/do/durable-timer.ts
16
20
  function durableTimer(config) {
@@ -247,11 +251,13 @@ function createAgentHost(config) {
247
251
  const isTerminal = config.terminal ?? ((s) => s.run.phase === "done" || s.run.phase === "failed" || s.run.phase === "cancelled");
248
252
  let cached = null;
249
253
  async function build() {
250
- const booting = run(config.buildMachine(), {
251
- ctx: config.ctx,
254
+ const wired = config.buildMachine();
255
+ const ctxArg = { ctx: config.ctx };
256
+ const booting = config.run(wired.machine, {
257
+ ...wired,
258
+ ...ctxArg,
252
259
  store: config.store,
253
- events: agentEvents(),
254
- terminal: isTerminal
260
+ events: agentEvents()
255
261
  });
256
262
  sseFromAgentEvents(booting, sse, config.toSseFrame);
257
263
  await autoBoot(booting, now);
@@ -272,7 +278,8 @@ function createAgentHost(config) {
272
278
  return status((await runtime()).getState());
273
279
  },
274
280
  async result() {
275
- return (await runtime()).result();
281
+ const state = (await runtime()).getState();
282
+ return isTerminal(state) ? state : void 0;
276
283
  },
277
284
  sse,
278
285
  async reset() {