@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
package/README.md CHANGED
@@ -8,21 +8,26 @@ A TEA / Elm-Architecture TypeScript library for durable, replayable state machin
8
8
  pnpm add @demlik/tea
9
9
  ```
10
10
 
11
- `better-result` is a runtime dependency and is installed for you. The host and
11
+ The one runtime dependency is `@standard-schema/spec`, a types-only package
12
+ installed for you. `Cmd.define` takes any Standard Schema, so bring the schema
13
+ library you already use (zod, or Effect Schema through
14
+ `Schema.toStandardSchemaV1`). The host and
12
15
  testing adapters ride on optional peers you add only for the surface you use:
13
16
  `react` / `react-dom` (the `./react` hooks), `ws` (Node WebSocket subs),
14
- `fast-check` (the `./pbt` property-testing helpers), and `vitest` (the testing
15
- utilities).
17
+ `fast-check` (the `./pbt` property-testing helpers), `vitest` (the testing
18
+ utilities), and `effect` (the `./effect` engine).
16
19
 
17
20
  ## Quickstart
18
21
 
19
- A machine is plain data: an `init`, an `update` map keyed by `Msg` type, and —
20
- when it has effects — an `interpret` map. `run` drives it; `dispatch` folds a
21
- `Msg`; `getState` reads the current Model. You name the Model and the `Msg` union
22
+ A machine is plain data: an `init` and an `update` map keyed by `Msg` type.
23
+ `run` drives it, and when it has effects you hand `run` the `interpret` map
24
+ that performs them; `dispatch` folds a `Msg`; `getState` reads the current
25
+ Model. You name the Model and the `Msg` union
22
26
  once, under `types`; everything else is inferred from the machine itself.
23
27
 
24
28
  ```ts
25
- import { defineMachine, run } from "@demlik/tea";
29
+ import { defineMachine } from "@demlik/tea";
30
+ import { run } from "@demlik/tea/promise";
26
31
 
27
32
  type State = { readonly count: number };
28
33
  type Msg = { readonly type: "increment" } | { readonly type: "reset" };
@@ -41,6 +46,24 @@ await runtime.dispatch({ type: "increment" });
41
46
  runtime.getState(); // { count: 1 }
42
47
  ```
43
48
 
49
+ ## Two engines, one machine
50
+
51
+ The core is `@demlik/tea`, and each engine has its own entry point. A machine
52
+ file imports only the core, so it runs unchanged on either engine.
53
+
54
+ - `@demlik/tea` — the core: `defineMachine`, `Cmd`, `replay` and the types. It
55
+ imports no engine.
56
+ - `@demlik/tea/promise` — the Promise engine. Handlers return Promises.
57
+ - `@demlik/tea/effect` — the Effect engine (`experimental`, Effect v4). Handlers
58
+ return Effects, services come from your Layers, and closing the scope
59
+ interrupts whatever is in flight.
60
+
61
+ [Run a machine on the Promise engine](https://github.com/kamp-us/demlik/blob/main/docs/how-to/run-on-the-promise-engine.md)
62
+ and [on the Effect engine](https://github.com/kamp-us/demlik/blob/main/docs/how-to/run-on-the-effect-engine.md)
63
+ build on the same machine file. Coming from 0.15?
64
+ [The migration guide](https://github.com/kamp-us/demlik/blob/main/docs/how-to/migrate-from-0-15.md)
65
+ shows every removed or reshaped API, before and after.
66
+
44
67
  ## Documentation
45
68
 
46
69
  The four Diátaxis quadrants live in [`docs/`](https://github.com/kamp-us/demlik/blob/main/docs/README.md):
@@ -1,20 +1,19 @@
1
- import { R as RequiredCtx, M as Machine, I as Interpret, C as Cmd } from '../core-DnzqWy6u.js';
2
- import { T as ToolCall, a as ToolOutcome, C as Conversation, A as AnyToolDef, P as PlainModel, b as AgentTurn, S as StreamingModel, c as AgentState, d as ToolResult, e as ToolFailureOf, f as ToolCmd, g as AgentEvent, h as TurnChunk, i as AgentMachineMsg, W as WiredToolMsg, j as AgentCmd, k as AgentConfigCore, l as CompactionPolicy, m as AgentKnob } from '../machine-DGlPWCWI.js';
3
- export { n as AgentBootMsg, o as AgentCancelMsg, p as AgentCompactErrMsg, q as AgentCompactOkMsg, r as AgentCompactRunCmd, s as AgentCompactionConfig, t as AgentConfig, u as AgentDetachedHandlers, v as AgentFailure, w as AgentLlmErrMsg, x as AgentLlmOkMsg, y as AgentLlmRunCmd, z as AgentPorts, B as AgentSnapshotConfig, D as AgentStatus, E as AgentTerminalFailure, F as AgentTimerMsg, G as AgentToMachine, H as Awaiting, I as COMPACTION_PURPOSE, J as CompactInterpret, K as CompactionOutputs, L as CompactionPurpose, M as CompactionSummary, N as LlmCall, O as LlmErr, Q as LlmFailMsg, R as LlmOk, U as LlmRunCmd, V as LlmSucceedMsg, X as MessageLoader, Y as ModelFactory, Z as ModelPort, _ as ModelStream, $ as PLAIN_MODEL_MISROUTE_REASON, a0 as ReservedToolName, a1 as Schema, a2 as SnapshotInterpret, a3 as TOOL_RETRY_EXHAUSTED_TAG, a4 as TOOL_TIMEOUT_TAG, a5 as TaggedFailure, a6 as ToolConstructors, a7 as ToolDef, a8 as ToolError, a9 as ToolFail, aa as ToolFailure, ab as ToolHandler, ac as ToolInput, ad as ToolMsg, ae as ToolOk, af as ToolRecord, ag as ToolRejectedCmd, ah as ToolRejection, ai as ToolResilience, aj as ToolResilienceError, ak as ToolRetryExhausted, al as ToolRouter, am as ToolSettlement, an as ToolThrown, ao as ToolTimedOut, ap as WiredToolCmd, aq as agentBootMsg, ar as agentCancelMsg, as as agentEvents, at as agentTurnSchema, au as compactionSummarySchema, av as fanOutInterpret, aw as isAgentTurn, ax as isCompactionSummary, ay as isReservedToolName, az as isStreamingModel, aA as liftAgent, aB as mergeInterpret, aC as plainModel, aD as status, aE as tool, aF as toolErrorReason, aG as toolRouter } from '../machine-DGlPWCWI.js';
4
- import { a as ScopedCtxArg, S as Store } from '../runtime-types-CMF13BBh.js';
5
- import { E as EndedRun } from '../index-KXqTRJyb.js';
6
- export { M as MonitoredRunCmd, R as RunFailure } from '../index-KXqTRJyb.js';
1
+ import { M as Machine, p as Interpret, d as Subscribe, C as Cmd } from '../core-BbgtiXdg.js';
2
+ import { b as DeadlinesSub } from '../index-Xufl55W8.js';
3
+ export { a as DeadlineSub, c as deadlineSub, e as deadlinesSub, s as subscribeDeadline } from '../index-Xufl55W8.js';
4
+ import { T as ToolCall, a as ToolOutcome, C as Conversation, A as AnyToolDef, P as PlainModel, b as AgentTurn, S as StreamingModel, c as AgentState, d as ToolResult, e as ToolFailureOf, f as ToolsCtx, g as AgentEvent, h as TurnChunk, i as AgentMachineMsg, W as WiredToolMsg, j as AgentCmd, k as ToolCmd, l as AgentConfigCore, m as CompactionPolicy, n as AgentKnob } from '../machine-BQzTV8On.js';
5
+ export { o as AgentBootMsg, p as AgentCancelMsg, q as AgentCompactErrMsg, r as AgentCompactOkMsg, s as AgentCompactRunCmd, t as AgentCompactionConfig, u as AgentConfig, v as AgentFailure, w as AgentLlmErrMsg, x as AgentLlmOkMsg, y as AgentLlmRunCmd, z as AgentSnapshotConfig, B as AgentStatus, D as AgentTerminalFailure, E as AgentTimerMsg, F as AgentToMachine, G as Awaiting, H as COMPACTION_PURPOSE, I as CompactInterpret, J as CompactionOutputs, K as CompactionPurpose, L as CompactionSummary, M as Llm, N as LlmCall, O as LlmErr, Q as LlmFailMsg, R as LlmOk, U as LlmRunCmd, V as LlmSucceedMsg, X as MessageLoader, Y as ModelFactory, Z as ModelPort, _ as ModelStream, $ as PLAIN_MODEL_MISROUTE_REASON, a0 as ReservedToolName, a1 as Schema, a2 as SnapshotInterpret, a3 as TOOL_RETRY_EXHAUSTED_TAG, a4 as TOOL_TIMEOUT_TAG, a5 as TaggedFailure, a6 as ToolConstructors, a7 as ToolDef, a8 as ToolError, a9 as ToolFail, aa as ToolFailure, ab as ToolHandler, ac as ToolInput, ad as ToolMsg, ae as ToolOk, af as ToolRecord, ag as ToolRejectedCmd, ah as ToolRejection, ai as ToolResilience, aj as ToolResilienceError, ak as ToolRetryExhausted, al as ToolRouter, am as ToolSettlement, an as ToolThrown, ao as ToolTimedOut, ap as WiredToolCmd, aq as agentBootMsg, ar as agentCancelMsg, as as agentEvents, at as agentTurnSchema, au as compactionSummarySchema, av as fanOutInterpret, aw as isAgentTurn, ax as isCompactionSummary, ay as isReservedToolName, az as isStreamingModel, aA as liftAgent, aB as mergeInterpret, aC as plainModel, aD as status, aE as tool, aF as toolErrorReason, aG as toolRouter } from '../machine-BQzTV8On.js';
6
+ import { C as CtxArg, S as Store } from '../runtime-types-CiVpC0HN.js';
7
+ import { E as EndedRun } from '../index-Bz5Rh9Ga.js';
8
+ export { M as MonitoredRunCmd, R as RunFailure } from '../index-Bz5Rh9Ga.js';
7
9
  import { RetryPolicy } from '../retry-backoff/index.js';
8
- import { a as DeadlineSub } from '../index-HSYgG2Yt.js';
9
- export { b as deadlineSub, s as subscribeDeadline } from '../index-HSYgG2Yt.js';
10
- import 'zod';
11
- import '../index-CA_7I5g9.js';
12
- import '../protocol-D8VbH-VH.js';
13
- import '../index-CuNO9m8i.js';
14
- import '../index-CSyMYDAB.js';
15
- import 'better-result';
16
- import '../index-ZCMhnVKN.js';
17
- import '../types-BseNPIhr.js';
10
+ import '@standard-schema/spec';
11
+ import '../types-LxZxGYda.js';
12
+ import '../index-Cou86-GX.js';
13
+ import '../protocol-ClRZBhHQ.js';
14
+ import '../index-CkFYA9Y6.js';
15
+ import '../index-7vV8xmsD.js';
16
+ import '../index-CjFDUBeq.js';
18
17
 
19
18
  /**
20
19
  * @demlik/tea/agent — `defineAgent`, the convenience layer over `createAgent`.
@@ -88,8 +87,8 @@ type DefinedAgentState<T extends AnyToolDef> = AgentState<string, LidPurpose, Li
88
87
  type DefinedAgentResolvedState<T extends AnyToolDef> = Omit<DefinedAgentState<T>, "run"> & {
89
88
  readonly run: EndedRun<string>;
90
89
  };
91
- /** The ctx the tools' `needs` demand, intersected — what `run` asks for. */
92
- type DefinedAgentCtx<T extends AnyToolDef> = RequiredCtx<ToolCmd<T>>;
90
+ /** The ctx the tools' handlers read, intersected — what `run` asks for. */
91
+ type DefinedAgentCtx<T extends AnyToolDef> = ToolsCtx<T>;
93
92
  /** The Msg union a defined agent's machine folds. */
94
93
  type DefinedAgentMsg<T extends AnyToolDef> = AgentMachineMsg<LidPurpose, LidOutputs, ToolResult<T>> | WiredToolMsg<T>;
95
94
  /**
@@ -112,8 +111,19 @@ type DefinedAgentCmd<T extends AnyToolDef> = AgentCmd<LidPurpose, ToolCmd<T>, fa
112
111
  * router's `tool_rejected`, and the agent-owned brain call.
113
112
  */
114
113
  type DefinedAgentInterpret<T extends AnyToolDef> = Interpret<DefinedAgentMsg<T>, DefinedAgentCmd<T>, DefinedAgentCtx<T>>;
115
- /** The wired machine `defineAgent` builds per `input` — feed it to the raw `run`. */
116
- type DefinedAgentMachine<T extends AnyToolDef> = Machine<DefinedAgentState<T>, DefinedAgentMsg<T>, DefinedAgentCmd<T>, DeadlineSub, DefinedAgentCtx<T>>;
114
+ /** The wired machine `defineAgent` builds per `input`. */
115
+ type DefinedAgentMachine<T extends AnyToolDef> = Machine<DefinedAgentState<T>, DefinedAgentMsg<T>, DefinedAgentCmd<T>, DeadlinesSub, DefinedAgentCtx<T>>;
116
+ /**
117
+ * The machine `defineAgent` builds per `input` beside the handlers it runs
118
+ * under — the interpret table and the `deadline` runner (a machine carries
119
+ * none — #278, #279). It is a `Wired`; feed it to the raw `run`:
120
+ * `run(wired.machine, { ...wired, ctx })`.
121
+ */
122
+ type DefinedAgentWired<T extends AnyToolDef> = {
123
+ readonly machine: DefinedAgentMachine<T>;
124
+ readonly interpret: DefinedAgentInterpret<T>;
125
+ readonly subscribe: Subscribe<DefinedAgentMsg<T>, DeadlinesSub, DefinedAgentCtx<T>>;
126
+ };
117
127
  /**
118
128
  * The brain a defined agent runs, in either of its two shapes:
119
129
  *
@@ -327,12 +337,10 @@ type DefinedAgentEvent<T extends AnyToolDef> = AgentEvent<ToolResult<T>>;
327
337
  /**
328
338
  * Host wiring for one `run`: the store, the ctx the tools need, a runId, a clock.
329
339
  *
330
- * `ctx` is `ScopedCtxArg`, the same widening `run` itself takes: an agent's tools
331
- * are exactly the handlers a scoped resource is for, so a `provide({ … })` graph
332
- * is accepted here in place of the object and gets the same acquire-at-boot /
333
- * release-at-terminal lifetime.
340
+ * `ctx` is the plain object the tools' handlers read (ADR 0020). A host with a
341
+ * resource to release wraps `run` in its own `try` / `finally`.
334
342
  */
335
- type DefinedAgentRunOptions<T extends AnyToolDef> = ScopedCtxArg<DefinedAgentCtx<T>> & {
343
+ type DefinedAgentRunOptions<T extends AnyToolDef> = CtxArg<DefinedAgentCtx<T>> & {
336
344
  readonly store?: Store<DefinedAgentState<T>>;
337
345
  /** The run's identity. Omit → a fresh UUID. */
338
346
  readonly runId?: string;
@@ -407,9 +415,10 @@ type DefinedAgentRunOptions<T extends AnyToolDef> = ScopedCtxArg<DefinedAgentCtx
407
415
  * `defineAgent` built.
408
416
  *
409
417
  * The wrapper's signature is the cell's, so calling `next(cmd, ctx, dispatch)`
410
- * is how the wrapped work happens — that is the typed Cmd→Msg edge
411
- * (`Cmd.define`'s `_ok` / `_err` Msgs), and returning its Msg is what keeps the
412
- * fold, and therefore a replay, identical to the unwrapped run's.
418
+ * is how the wrapped work happens. A tool cell returns its outcome and the
419
+ * engine mints `<name>_ok` / `<name>_err` from it (ADR 0021), so returning
420
+ * what `next` returned is what keeps the fold, and therefore a replay,
421
+ * identical to the unwrapped run's.
413
422
  */
414
423
  type InterpretOverlay<T extends AnyToolDef> = CellWrappers<DefinedAgentInterpret<T>>;
415
424
  /**
@@ -444,8 +453,11 @@ interface DefinedAgent<T extends AnyToolDef> {
444
453
  * reads without a guard against an `idle` arm this promise cannot produce.
445
454
  */
446
455
  readonly run: (input: string, ...opts: [Record<never, never>] extends [DefinedAgentCtx<T>] ? [opts?: DefinedAgentRunOptions<T>] : [opts: DefinedAgentRunOptions<T>]) => Promise<DefinedAgentResolvedState<T>>;
447
- /** The machine `run` drives for `input` — the door down to the raw kernel. */
448
- readonly machine: (input: string) => DefinedAgentMachine<T>;
456
+ /**
457
+ * The machine `run` drives for `input` and the interpret table it runs under
458
+ * — the door down to the raw kernel.
459
+ */
460
+ readonly machine: (input: string) => DefinedAgentWired<T>;
449
461
  /**
450
462
  * The ramp between the lid and `createAgent`: wrap ONE interpret cell of the
451
463
  * machine this agent builds and get back a NEW defined agent that runs the
@@ -616,8 +628,8 @@ declare function transcript<R>(seed?: TranscriptSeed<R>): Transcript<R>;
616
628
  * (via the llm-call message loader), the schemas, and the model. `createAgent(config)` returns the uniform handle contract every
617
629
  * composition exposes (`init` / verbs returning `readonly [State, Cmd[]]` /
618
630
  * `subs`) AND a ready-to-`run` `defineMachine` (`toMachine`) — THE one wired
619
- * path. (`unsafeDetachedHandlers` is the hand-wiring escape hatch; its name
620
- * advertises that it does not drive the retry loop.)
631
+ * path. (`brainInterpret` and `brain` are the pieces a consumer wiring the
632
+ * verbs by hand reaches for.)
621
633
  *
622
634
  * ## The composition (three siblings wired into ONE machine)
623
635
  *
@@ -628,7 +640,8 @@ declare function transcript<R>(seed?: TranscriptSeed<R>): Transcript<R>;
628
640
  * delegates `start` / `advance` / `progress` / `onDeadline` / `boot` to it.
629
641
  * - `../llm-call` — every brain call. One
630
642
  * `LlmCall` per turn, structured-output parsed, retry composed in. The agent
631
- * delegates the resilient slice + verbs and reuses the detached handler.
643
+ * delegates the resilient slice + verbs, and owns the one Promise handler
644
+ * that invokes the model (`./model`).
632
645
  * - `../fan-out` — the tool calls a turn produced. Tools dispatch SERIALLY by
633
646
  * default (concurrency 1); fan-out generalizes that to a bounded number
634
647
  * LAUNCHED per transition, `config.toolConcurrency`. Above `1` a router's
@@ -700,8 +713,8 @@ declare function transcript<R>(seed?: TranscriptSeed<R>): Transcript<R>;
700
713
  * });
701
714
  * // The consumer supplies the per-tool (+ snapshot) interpret; the agent owns
702
715
  * // the brain interpret and merges them in `toMachine`.
703
- * const machine = agent.toMachine({ toolInterpret });
704
- * const runtime = run(machine, { ctx, store });
716
+ * const wired = agent.toMachine({ toolInterpret });
717
+ * const runtime = run(wired.machine, { ...wired, ctx, store });
705
718
  */
706
719
 
707
720
  /**
@@ -716,7 +729,6 @@ declare function transcript<R>(seed?: TranscriptSeed<R>): Transcript<R>;
716
729
  * pass obliges you to supply the matching handler at `toMachine`, and each one
717
730
  * you omit forbids it. `rng` is the determinism seam for the retry backoff —
718
731
  * pass a fixed `() => 0` to pin it in tests; omit for `Math.random`.
719
- * `unsafeDetachedHandlers` is the hand-wiring escape hatch.
720
732
  *
721
733
  * The four overloads exist because the two obligations are derived
722
734
  * from the `config` VALUE, never inferred. `{ snapshotEvery: number }` REQUIRES
@@ -745,4 +757,4 @@ declare function createAgent<Stage, P extends string, O extends Record<P, AgentT
745
757
  readonly compaction?: never;
746
758
  }): AgentKnob<Stage, P, O, R, TC, false, false>;
747
759
 
748
- export { AgentCmd, AgentConfigCore, AgentEvent, AgentKnob, AgentMachineMsg, type AgentMessage, type AgentPrompt, AgentState, AgentTurn, AnyToolDef, CompactionPolicy, Conversation, DeadlineSub, type DefineAgentCompaction, type DefineAgentConfig, type DefinedAgent, type DefinedAgentCmd, type DefinedAgentCtx, type DefinedAgentEvent, type DefinedAgentInterpret, type DefinedAgentMachine, type DefinedAgentModel, type DefinedAgentMsg, type DefinedAgentOverlay, type DefinedAgentResolvedState, type DefinedAgentRunOptions, type DefinedAgentState, EndedRun, type InterpretOverlay, type LidPurpose, PlainModel, StreamingModel, ToolCall, ToolCmd, type ToolErrorContext, ToolFailureOf, ToolOutcome, ToolResult, type Transcript, type TranscriptOutcome, type TranscriptSeed, type TranscriptSnapshot, type TranscriptToolResult, TurnChunk, WiredToolMsg, createAgent, defineAgent, renderPrompt, transcript };
760
+ export { AgentCmd, AgentConfigCore, AgentEvent, AgentKnob, AgentMachineMsg, type AgentMessage, type AgentPrompt, AgentState, AgentTurn, AnyToolDef, CompactionPolicy, Conversation, DeadlinesSub, type DefineAgentCompaction, type DefineAgentConfig, type DefinedAgent, type DefinedAgentCmd, type DefinedAgentCtx, type DefinedAgentEvent, type DefinedAgentInterpret, type DefinedAgentMachine, type DefinedAgentModel, type DefinedAgentMsg, type DefinedAgentOverlay, type DefinedAgentResolvedState, type DefinedAgentRunOptions, type DefinedAgentState, type DefinedAgentWired, EndedRun, type InterpretOverlay, type LidPurpose, PlainModel, StreamingModel, ToolCall, ToolCmd, type ToolErrorContext, ToolFailureOf, ToolOutcome, ToolResult, ToolsCtx, type Transcript, type TranscriptOutcome, type TranscriptSeed, type TranscriptSnapshot, type TranscriptToolResult, TurnChunk, WiredToolMsg, createAgent, defineAgent, renderPrompt, transcript };
@@ -1,12 +1,16 @@
1
- export { COMPACTION_PURPOSE, PLAIN_MODEL_MISROUTE_REASON, TOOL_RETRY_EXHAUSTED_TAG, TOOL_TIMEOUT_TAG, agentBootMsg, agentCancelMsg, agentEvents, agentTurnSchema, compactionSummarySchema, createAgent, defineAgent, fanOutInterpret, isAgentTurn, isCompactionSummary, isReservedToolName, isStreamingModel, liftAgent, mergeInterpret, plainModel, renderPrompt, status, tool, toolErrorReason, toolRouter, transcript } from '../chunk-TCLBCERH.js';
2
- import '../chunk-3B5X7SBB.js';
3
- import '../chunk-MYXFNWAJ.js';
1
+ export { COMPACTION_PURPOSE, PLAIN_MODEL_MISROUTE_REASON, TOOL_RETRY_EXHAUSTED_TAG, TOOL_TIMEOUT_TAG, agentBootMsg, agentCancelMsg, agentEvents, agentTurnSchema, compactionSummarySchema, createAgent, defineAgent, fanOutInterpret, isAgentTurn, isCompactionSummary, isReservedToolName, isStreamingModel, liftAgent, mergeInterpret, plainModel, renderPrompt, status, tool, toolErrorReason, toolRouter, transcript } from '../chunk-EHUDXAKC.js';
2
+ import '../chunk-G5E74IJB.js';
3
+ import '../chunk-7MGXQZPW.js';
4
+ import '../chunk-CIHSHLQX.js';
5
+ import '../chunk-QNGYQMZB.js';
4
6
  import '../chunk-TXN2KFHF.js';
5
- import '../chunk-L3TND7LA.js';
6
- import '../chunk-AYS5N6WY.js';
7
+ import '../chunk-6NG4V5SB.js';
7
8
  import '../chunk-VBDU4JL6.js';
8
- export { deadlineSub, subscribeDeadline } from '../chunk-22POWGFA.js';
9
- import '../chunk-G5E74IJB.js';
10
- import '../chunk-66PY5WYF.js';
9
+ import '../chunk-4LPY67E4.js';
10
+ export { deadlineSub, deadlinesSub, subscribeDeadline } from '../chunk-IVJP3GKJ.js';
11
+ import '../chunk-WT5PBPLB.js';
12
+ import '../chunk-5XU6ZJO2.js';
13
+ import '../chunk-GOX2CYIM.js';
14
+ import '../chunk-CH5KTOEZ.js';
11
15
  //# sourceMappingURL=index.js.map
12
16
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,18 @@
1
+ // src/internal/schema.ts
2
+ var VENDOR = "@demlik/tea";
3
+ function schema(validate) {
4
+ return { "~standard": { version: 1, vendor: VENDOR, validate } };
5
+ }
6
+ function unchecked() {
7
+ return schema((value) => ({ value }));
8
+ }
9
+ var undefinedOnly = schema(
10
+ (value) => value === void 0 ? { value: void 0 } : { issues: [{ message: "expected no value" }] }
11
+ );
12
+ var rejectAll = schema(() => ({
13
+ issues: [{ message: "this Cmd never settles Ok" }]
14
+ }));
15
+
16
+ export { rejectAll, unchecked, undefinedOnly };
17
+ //# sourceMappingURL=chunk-4LPY67E4.js.map
18
+ //# sourceMappingURL=chunk-4LPY67E4.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/internal/schema.ts"],"names":[],"mappings":";AAaA,IAAM,MAAA,GAAS,aAAA;AAEf,SAAS,OACP,QAAA,EACwB;AACxB,EAAA,OAAO,EAAE,aAAa,EAAE,OAAA,EAAS,GAAG,MAAA,EAAQ,MAAA,EAAQ,UAAS,EAAE;AACjE;AAGO,SAAS,SAAA,GAAuC;AACrD,EAAA,OAAO,MAAA,CAAO,CAAC,KAAA,MAAW,EAAE,OAAkB,CAAE,CAAA;AAClD;AAGO,IAAM,aAAA,GAAwD,MAAA;AAAA,EACnE,CAAC,KAAA,KACC,KAAA,KAAU,MAAA,GACN,EAAE,KAAA,EAAO,MAAA,EAAU,GACnB,EAAE,QAAQ,CAAC,EAAE,OAAA,EAAS,mBAAA,EAAqB,CAAA;AACnD;AAGO,IAAM,SAAA,GAA4C,OAAO,OAAO;AAAA,EACrE,MAAA,EAAQ,CAAC,EAAE,OAAA,EAAS,6BAA6B;AACnD,CAAA,CAAE","file":"chunk-4LPY67E4.js","sourcesContent":["/**\n * The three Standard Schemas tea's own `Cmd.define`s need, written by hand so\n * the published package depends on no schema library (ADR 0021 §5).\n *\n * A battery's Cmd input is data it built itself and its `ok` is mostly a type\n * annotation, so what these check is deliberately thin: `unchecked<T>()` names\n * a type and checks nothing, `undefinedOnly` is a handler that settles with no\n * value, and `rejectAll` is a Cmd that never settles `Ok`. A consumer's own\n * `Cmd.define` brings a real schema — zod, Effect Schema — instead.\n */\n\nimport type { StandardSchemaV1 } from \"@standard-schema/spec\";\n\nconst VENDOR = \"@demlik/tea\";\n\nfunction schema<T>(\n validate: (value: unknown) => StandardSchemaV1.Result<T>,\n): StandardSchemaV1<T, T> {\n return { \"~standard\": { version: 1, vendor: VENDOR, validate } };\n}\n\n/** Accept every value as `T`. The type is the whole contract. */\nexport function unchecked<T>(): StandardSchemaV1<T, T> {\n return schema((value) => ({ value: value as T }));\n}\n\n/** Accept `undefined` only — the `ok` of a handler that settles with no value. */\nexport const undefinedOnly: StandardSchemaV1<undefined, undefined> = schema(\n (value) =>\n value === undefined\n ? { value: undefined }\n : { issues: [{ message: \"expected no value\" }] },\n);\n\n/** Accept nothing — the `ok` of a Cmd whose handler only ever fails. */\nexport const rejectAll: StandardSchemaV1<never, never> = schema(() => ({\n issues: [{ message: \"this Cmd never settles Ok\" }],\n}));\n"]}