@demlik/tea 0.15.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 (115) hide show
  1. package/README.md +30 -7
  2. package/dist/agent/index.d.ts +49 -37
  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-AYS5N6WY.js → chunk-6NG4V5SB.js} +62 -172
  9. package/dist/chunk-6NG4V5SB.js.map +1 -0
  10. package/dist/{chunk-3B5X7SBB.js → chunk-7MGXQZPW.js} +11 -9
  11. package/dist/chunk-7MGXQZPW.js.map +1 -0
  12. package/dist/{chunk-V46HSVCK.js → chunk-BCTEOVOU.js} +3 -3
  13. package/dist/{chunk-V46HSVCK.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-TCLBCERH.js → chunk-EHUDXAKC.js} +238 -212
  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-22POWGFA.js → chunk-IVJP3GKJ.js} +46 -20
  23. package/dist/chunk-IVJP3GKJ.js.map +1 -0
  24. package/dist/{chunk-QPEVCJ5Q.js → chunk-MVZS5FDM.js} +13 -6
  25. package/dist/chunk-MVZS5FDM.js.map +1 -0
  26. package/dist/{chunk-VTQI2NHP.js → chunk-MYNLY3HP.js} +9 -8
  27. package/dist/chunk-MYNLY3HP.js.map +1 -0
  28. package/dist/{chunk-Q5CQTBFA.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-DnzqWy6u.d.ts → core-BbgtiXdg.d.ts} +231 -139
  35. package/dist/do/index.d.ts +37 -33
  36. package/dist/do/index.js +21 -14
  37. package/dist/do/index.js.map +1 -1
  38. package/dist/{durable-effects-CWzA-o2B.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 -59
  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-CSyMYDAB.d.ts → index-7vV8xmsD.d.ts} +1 -1
  51. package/dist/{index-KXqTRJyb.d.ts → index-Bz5Rh9Ga.d.ts} +19 -96
  52. package/dist/index-CjFDUBeq.d.ts +207 -0
  53. package/dist/{index-CuNO9m8i.d.ts → index-CkFYA9Y6.d.ts} +14 -16
  54. package/dist/{index-CA_7I5g9.d.ts → index-Cou86-GX.d.ts} +137 -246
  55. package/dist/{index-DrIRb_Ch.d.ts → index-DU6JpQ8G.d.ts} +1 -1
  56. package/dist/{index-HSYgG2Yt.d.ts → index-Xufl55W8.d.ts} +247 -211
  57. package/dist/{index-C2DwkjlP.d.ts → index-_dOR3xqA.d.ts} +57 -45
  58. package/dist/index.d.ts +121 -385
  59. package/dist/index.js +2 -1
  60. package/dist/jev/index.d.ts +133 -97
  61. package/dist/jev/index.js +205 -161
  62. package/dist/jev/index.js.map +1 -1
  63. package/dist/{machine-DGlPWCWI.d.ts → machine-BQzTV8On.d.ts} +171 -288
  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 -22
  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-D8VbH-VH.d.ts → protocol-ClRZBhHQ.d.ts} +7 -8
  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 -456
  91. package/dist/resilience/index.js +37 -483
  92. package/dist/resilience/index.js.map +1 -1
  93. package/dist/{runtime-types-CMF13BBh.d.ts → runtime-types-CiVpC0HN.d.ts} +131 -388
  94. package/dist/testing/index.d.ts +22 -16
  95. package/dist/testing/index.js +15 -7
  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-BseNPIhr.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-22POWGFA.js.map +0 -1
  104. package/dist/chunk-3B5X7SBB.js.map +0 -1
  105. package/dist/chunk-66PY5WYF.js +0 -1816
  106. package/dist/chunk-66PY5WYF.js.map +0 -1
  107. package/dist/chunk-AYS5N6WY.js.map +0 -1
  108. package/dist/chunk-L3TND7LA.js +0 -97
  109. package/dist/chunk-L3TND7LA.js.map +0 -1
  110. package/dist/chunk-MYXFNWAJ.js.map +0 -1
  111. package/dist/chunk-Q5CQTBFA.js.map +0 -1
  112. package/dist/chunk-QPEVCJ5Q.js.map +0 -1
  113. package/dist/chunk-TCLBCERH.js.map +0 -1
  114. package/dist/chunk-VTQI2NHP.js.map +0 -1
  115. package/dist/index-ZCMhnVKN.d.ts +0 -272
@@ -1,19 +1,18 @@
1
- import { S as Store, R as Runtime, B as BootingRuntime, F as FencedStore } from '../runtime-types-CMF13BBh.js';
2
- import { P as PendingEffectsRecorder, b as EffectOwed, a as EffectConfirmed } from '../durable-effects-CWzA-o2B.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-CWzA-o2B.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-DnzqWy6u.js';
6
- import { g as AgentEvent, b as AgentTurn, c as AgentState, i as AgentMachineMsg, D as AgentStatus } from '../machine-DGlPWCWI.js';
7
- import 'better-result';
8
- import 'zod';
9
- import '../index-KXqTRJyb.js';
10
- import '../index-ZCMhnVKN.js';
11
- import '../index-HSYgG2Yt.js';
12
- import '../types-BseNPIhr.js';
13
- import '../index-CSyMYDAB.js';
14
- import '../index-CA_7I5g9.js';
15
- import '../protocol-D8VbH-VH.js';
16
- import '../index-CuNO9m8i.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';
17
16
 
18
17
  /**
19
18
  * @demlik/tea/do — `stepHost`, the HTTP-PULL control carrier (#92).
@@ -408,7 +407,7 @@ declare function runStepLoop<R, I, O>(token: string, runId: string, transport: S
408
407
  * and the vortex arena tick (`room.ts` `armTick` + `onTick`) replicates the
409
408
  * exact shape for the 18 Hz game clock. The two old `do_alarm`/`do_ws` Subs were
410
409
  * dropped (see `./index`'s historical note) because `toMachine` fixes the agent
411
- * 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
412
411
  * Sub set — leaving the alarm re-arm a HOST concern with no first-class home.
413
412
  *
414
413
  * {@link durableTimer} is that home: a tiny, transport- and Msg-agnostic helper
@@ -1057,18 +1056,22 @@ declare function sseFromAgentEvents<R, Frame>(runtime: {
1057
1056
  */
1058
1057
  interface AgentHostConfig<Stage, P extends string, O extends Record<P, AgentTurn>, R, Frame, C extends Cmd = Cmd, U extends Sub = Sub, Ctx = unknown> {
1059
1058
  /**
1060
- * Build the wired agent machine. Called once per host build (per activation),
1061
- * AFTER the previous runtime — if any — was torn down. The consumer wires its
1062
- * 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.
1063
1061
  */
1064
- readonly buildMachine: () => Machine<AgentState<Stage, P, O, R>, AgentMachineMsg<P, O, R>, C, U, Ctx>;
1065
- /** The durable `Store` for the agent slice (typically `doStore(storage, parse)`). */
1066
- 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>>;
1067
1063
  /**
1068
- * The Ctx the machine threads to its interpret cells — checked against
1069
- * `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.
1070
1069
  */
1071
- 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;
1072
1075
  /**
1073
1076
  * The run-terminality predicate (#46) — what makes `result()` first-class.
1074
1077
  * Defaults to the agent's own terminal phases (`done` / `failed`).
@@ -1099,10 +1102,10 @@ interface AgentHost<Stage, P extends string, O extends Record<P, AgentTurn>, R,
1099
1102
  * Get (or build) the booted runtime. Build-once-boot-once: the first call
1100
1103
  * builds the machine, wires SSE off the semantic event stream, awaits the boot
1101
1104
  * gate, runs the `autoBoot` re-fire for a rehydrated suspended run, and caches
1102
- * the booted `Runtime`; subsequent calls return the cached handle. The single
1105
+ * the booted handle; subsequent calls return the cached handle. The single
1103
1106
  * assembly every consumer used to hand-roll in `getRuntime()`.
1104
1107
  */
1105
- 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>>>;
1106
1109
  /**
1107
1110
  * The agent's lifecycle status (#49) — the ONE typed channel a consumer reads
1108
1111
  * instead of re-deriving `run.phase` / `awaiting` by hand. Ensures the runtime
@@ -1138,6 +1141,7 @@ interface AgentHost<Stage, P extends string, O extends Record<P, AgentTurn>, R,
1138
1141
  *
1139
1142
  * @example
1140
1143
  * const host = createAgentHost<Stage, Purpose, Outputs, ClientResult, SseEvent>({
1144
+ * run, // from `@demlik/tea/promise`
1141
1145
  * buildMachine: () => agent.toMachine<Ctx>({ toolInterpret }),
1142
1146
  * store: doStore(storage, parse),
1143
1147
  * ctx,
@@ -1373,14 +1377,14 @@ interface ResumePort<S, M extends {
1373
1377
  * every DO-hosted machine otherwise re-derives.
1374
1378
  *
1375
1379
  * `await ready` is the single boot gate (issue #45): `getState()` is total only
1376
- * on the booted `Runtime`, so state cannot be inspected before boot populates
1377
- * 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.
1378
1382
  */
1379
1383
  declare function bootResume<S, M extends {
1380
1384
  type: string;
1381
1385
  }, E extends {
1382
1386
  type: string;
1383
- } = 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>;
1384
1388
  /**
1385
1389
  * True iff an agent slice loaded from storage is mid-loop (running + awaiting
1386
1390
  * tools) — the resumable case `agent_boot` re-fires.
@@ -1404,7 +1408,7 @@ declare function agentIsResumable<Stage, P extends string, O extends Record<P, u
1404
1408
  */
1405
1409
  declare function autoBoot<Stage, P extends string, O extends Record<P, unknown>, R, E extends {
1406
1410
  type: string;
1407
- } = 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>;
1408
1412
  /**
1409
1413
  * Re-fire every round-trip a rehydrated actor still owes, on wake. Given a
1410
1414
  * durable carrier whose recorder was rehydrated from the persisted ledger
@@ -1834,7 +1838,7 @@ declare function presenceCount(ctx: PresenceCtx, tag?: string): number;
1834
1838
  *
1835
1839
  * 2. `deferredGateway` + `createAgentHost` (from `./host`) — THE transport for
1836
1840
  * a DO-hosted agent. A `createAgent().toMachine()` machine owns exactly one
1837
- * 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
1838
1842
  * no DO-native Sub variant to compose, and it needs none. The gateway owns
1839
1843
  * each deferred tool round-trip as a Promise the interpret cell awaits:
1840
1844
  * - Inbound WebSocket frames are bridged straight into `gateway.settle(...)`
@@ -1848,7 +1852,7 @@ declare function presenceCount(ctx: PresenceCtx, tag?: string): number;
1848
1852
  *
1849
1853
  * (Historical note: this module previously also shipped `do_ws` / `do_alarm`
1850
1854
  * Subs + a `doSubscribe` registry. Because `toMachine` fixes the agent machine's
1851
- * 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
1852
1856
  * Sub set — they were structurally unusable by the flagship consumer and had no
1853
1857
  * callers. They were dropped in favor of the gateway as the single transport.)
1854
1858
  */
package/dist/do/index.js CHANGED
@@ -1,16 +1,20 @@
1
- import { status, agentBootMsg, agentEvents } from '../chunk-TCLBCERH.js';
2
- import { createIntake } from '../chunk-VTQI2NHP.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-3B5X7SBB.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-L3TND7LA.js';
9
- import '../chunk-AYS5N6WY.js';
10
+ import '../chunk-6NG4V5SB.js';
10
11
  import { defaultRetryPolicy, initRetry, recordFailure, shouldRetry, nextDelayMs } from '../chunk-VBDU4JL6.js';
11
- import '../chunk-22POWGFA.js';
12
- import '../chunk-G5E74IJB.js';
13
- import { StoreConflictError, replay, run } from '../chunk-66PY5WYF.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() {