@demlik/tea 0.19.0 → 0.20.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 +25 -18
  2. package/dist/agent/index.d.ts +44 -13
  3. package/dist/agent/index.js +10 -10
  4. package/dist/{chunk-PCJA2HTZ.js → chunk-2774I242.js} +7 -7
  5. package/dist/chunk-2774I242.js.map +1 -0
  6. package/dist/{chunk-YIMOFXST.js → chunk-2R62Q5UK.js} +3 -3
  7. package/dist/chunk-2R62Q5UK.js.map +1 -0
  8. package/dist/{chunk-PQSDUX6B.js → chunk-5HVKDHY6.js} +3 -3
  9. package/dist/{chunk-PQSDUX6B.js.map → chunk-5HVKDHY6.js.map} +1 -1
  10. package/dist/{chunk-WTSOW2MD.js → chunk-72CN3VPY.js} +5 -5
  11. package/dist/{chunk-WTSOW2MD.js.map → chunk-72CN3VPY.js.map} +1 -1
  12. package/dist/{chunk-JVE2LBFJ.js → chunk-A73IJ27X.js} +3 -3
  13. package/dist/{chunk-JVE2LBFJ.js.map → chunk-A73IJ27X.js.map} +1 -1
  14. package/dist/{chunk-I7E7AD2S.js → chunk-AIXC33SE.js} +4 -4
  15. package/dist/chunk-AIXC33SE.js.map +1 -0
  16. package/dist/{chunk-FNGZMVIT.js → chunk-DVNXEB7V.js} +3 -3
  17. package/dist/chunk-DVNXEB7V.js.map +1 -0
  18. package/dist/{chunk-XVIKSRCK.js → chunk-EA47MI5Q.js} +4 -4
  19. package/dist/{chunk-XVIKSRCK.js.map → chunk-EA47MI5Q.js.map} +1 -1
  20. package/dist/{chunk-IHUNKHDX.js → chunk-FTCYY2DO.js} +3 -3
  21. package/dist/{chunk-IHUNKHDX.js.map → chunk-FTCYY2DO.js.map} +1 -1
  22. package/dist/{chunk-JVKU2UQC.js → chunk-HX3C6LDK.js} +3 -3
  23. package/dist/{chunk-JVKU2UQC.js.map → chunk-HX3C6LDK.js.map} +1 -1
  24. package/dist/{chunk-H2ELKHI6.js → chunk-JAKM53JF.js} +4 -4
  25. package/dist/chunk-JAKM53JF.js.map +1 -0
  26. package/dist/{chunk-JYNYG5SF.js → chunk-NGYFBD5G.js} +3 -3
  27. package/dist/chunk-NGYFBD5G.js.map +1 -0
  28. package/dist/{chunk-AIIXV4XB.js → chunk-RKVUVALV.js} +2 -2
  29. package/dist/chunk-RKVUVALV.js.map +1 -0
  30. package/dist/{chunk-C3G2QFEZ.js → chunk-TAKPC6SD.js} +4 -4
  31. package/dist/{chunk-C3G2QFEZ.js.map → chunk-TAKPC6SD.js.map} +1 -1
  32. package/dist/{chunk-BRX3243I.js → chunk-TGJLXZAU.js} +3 -3
  33. package/dist/{chunk-BRX3243I.js.map → chunk-TGJLXZAU.js.map} +1 -1
  34. package/dist/{chunk-AHW2CLPT.js → chunk-UHAQ4PI6.js} +4 -4
  35. package/dist/{chunk-AHW2CLPT.js.map → chunk-UHAQ4PI6.js.map} +1 -1
  36. package/dist/{chunk-H3MWNH7A.js → chunk-XWIE5V7R.js} +4 -4
  37. package/dist/{chunk-H3MWNH7A.js.map → chunk-XWIE5V7R.js.map} +1 -1
  38. package/dist/{core-Ce9ncpuv.d.ts → core-CtvAyPpH.d.ts} +153 -1
  39. package/dist/devtools/index.d.ts +17 -0
  40. package/dist/devtools/index.js.map +1 -1
  41. package/dist/do/index.d.ts +12 -12
  42. package/dist/do/index.js +11 -11
  43. package/dist/{drive-loop-CsUsW3Wo.d.ts → drive-loop-Dw1sGSsW.d.ts} +1 -1
  44. package/dist/{durable-effects-BmUrRA-h.d.ts → durable-effects-Ump5lSdO.d.ts} +1 -1
  45. package/dist/effect/index.d.ts +124 -5
  46. package/dist/effect/index.js +33 -4
  47. package/dist/effect/index.js.map +1 -1
  48. package/dist/extension/index.d.ts +84 -3
  49. package/dist/extension/index.js +2 -2
  50. package/dist/extension/index.js.map +1 -1
  51. package/dist/flow/index.d.ts +29 -13
  52. package/dist/flow/index.js +11 -11
  53. package/dist/flow/index.js.map +1 -1
  54. package/dist/idempotency/index.d.ts +11 -3
  55. package/dist/idempotency/index.js +3 -3
  56. package/dist/{index-D8sYVzCI.d.ts → index-Bk2hBUdK.d.ts} +6 -1
  57. package/dist/{index-2kNxy6az.d.ts → index-CKtEKGyp.d.ts} +15 -3
  58. package/dist/{index-e36uEyl4.d.ts → index-CVU7SK3a.d.ts} +2 -2
  59. package/dist/{index-Dy3379ve.d.ts → index-CZZ3HI-Z.d.ts} +4 -4
  60. package/dist/{index-Ce5GYAuI.d.ts → index-CrcoVfd_.d.ts} +2 -2
  61. package/dist/{index-DWdg7R1l.d.ts → index-D3NY3VCN.d.ts} +5 -1
  62. package/dist/{index-B1Wzarkl.d.ts → index-Dl71V7kt.d.ts} +1 -1
  63. package/dist/{index-Bf9_bNql.d.ts → index-EIgfl83J.d.ts} +2 -2
  64. package/dist/index.d.ts +66 -5
  65. package/dist/index.js +2 -2
  66. package/dist/jev/index.d.ts +39 -27
  67. package/dist/jev/index.js +12 -8
  68. package/dist/jev/index.js.map +1 -1
  69. package/dist/{machine-CuojfZup.d.ts → machine-Dtre2TmN.d.ts} +9 -7
  70. package/dist/machine-viz/index.d.ts +2 -1
  71. package/dist/machine-viz/index.js +2 -2
  72. package/dist/machine-viz/index.js.map +1 -1
  73. package/dist/mem/index.d.ts +2 -2
  74. package/dist/mem/index.js +2 -2
  75. package/dist/node/index.d.ts +11 -2
  76. package/dist/node/index.js +2 -2
  77. package/dist/node/index.js.map +1 -1
  78. package/dist/otel/index.d.ts +10 -10
  79. package/dist/otel/index.js +10 -10
  80. package/dist/paginate/index.d.ts +5 -4
  81. package/dist/paginate/index.js +5 -5
  82. package/dist/parity/index.d.ts +3 -3
  83. package/dist/parity/index.js +3 -3
  84. package/dist/pbt/index.d.ts +1 -1
  85. package/dist/pbt/index.js +2 -2
  86. package/dist/persistence/index.d.ts +5 -5
  87. package/dist/persistence/index.js +4 -4
  88. package/dist/promise/index.d.ts +7 -2
  89. package/dist/promise/index.js +4 -4
  90. package/dist/react/index.d.ts +2 -2
  91. package/dist/resilience/index.d.ts +7 -6
  92. package/dist/resilience/index.js +5 -5
  93. package/dist/resilience/index.js.map +1 -1
  94. package/dist/{index-BnsAqn0-.d.ts → run-fiBe7pOG.d.ts} +8 -5
  95. package/dist/{runtime-types-BKg2CGMx.d.ts → runtime-types-DEluQgGO.d.ts} +74 -2
  96. package/dist/testing/effect/index.d.ts +5 -5
  97. package/dist/testing/effect/index.js +8 -8
  98. package/dist/testing/index.d.ts +2 -2
  99. package/dist/testing/index.js +3 -3
  100. package/dist/testing/promise/index.d.ts +4 -4
  101. package/dist/testing/promise/index.js +5 -5
  102. package/dist/timing/index.d.ts +4 -4
  103. package/dist/timing/index.js +4 -4
  104. package/dist/types-CXNzlbAg.d.ts +9 -0
  105. package/dist/work-queue/index.d.ts +4 -4
  106. package/dist/work-queue/index.js +2 -2
  107. package/dist/work-queue/index.js.map +1 -1
  108. package/package.json +3 -2
  109. package/dist/chunk-AIIXV4XB.js.map +0 -1
  110. package/dist/chunk-FNGZMVIT.js.map +0 -1
  111. package/dist/chunk-H2ELKHI6.js.map +0 -1
  112. package/dist/chunk-I7E7AD2S.js.map +0 -1
  113. package/dist/chunk-JYNYG5SF.js.map +0 -1
  114. package/dist/chunk-PCJA2HTZ.js.map +0 -1
  115. package/dist/chunk-YIMOFXST.js.map +0 -1
  116. package/dist/types-SzNSHKlV.d.ts +0 -5
package/README.md CHANGED
@@ -9,21 +9,23 @@ pnpm add @demlik/tea
9
9
  ```
10
10
 
11
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
12
+ installed for you. [`Cmd.define`](https://github.com/kamp-us/demlik/blob/main/packages/tea/docs/glossary.md#cmd) takes any Standard Schema, so bring the schema
13
13
  library you already use (zod, or Effect Schema through
14
14
  `Schema.toStandardSchemaV1`). The host and
15
15
  testing adapters ride on optional peers you add only for the surface you use:
16
16
  `react` / `react-dom` (the `./react` hooks), `ws` (Node WebSocket subs),
17
17
  `fast-check` (the `./pbt` property-testing helpers), `vitest` (the testing
18
- utilities), and `effect` (the `./effect` engine).
18
+ utilities), `effect` (the `./effect` engine), and `@opentelemetry/api` (the
19
+ `./otel` spans).
19
20
 
20
21
  ## Quickstart
21
22
 
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
26
- once, under `types`; everything else is inferred from the machine itself.
23
+ A [machine](https://github.com/kamp-us/demlik/blob/main/packages/tea/docs/glossary.md#machine) is plain data: an `init` and an [`update`](https://github.com/kamp-us/demlik/blob/main/packages/tea/docs/glossary.md#update) map keyed by [`Msg`](https://github.com/kamp-us/demlik/blob/main/packages/tea/docs/glossary.md#msg) type.
24
+ [`run`](https://github.com/kamp-us/demlik/blob/main/packages/tea/docs/glossary.md#run) drives it, and when it has effects you hand `run` the [`interpret`](https://github.com/kamp-us/demlik/blob/main/packages/tea/docs/glossary.md#interpret) map
25
+ that performs them; [`dispatch`](https://github.com/kamp-us/demlik/blob/main/packages/tea/docs/glossary.md#dispatch) folds a `Msg`; `getState` reads the current
26
+ [Model](https://github.com/kamp-us/demlik/blob/main/packages/tea/docs/glossary.md#model). You name the Model and the `Msg` union
27
+ once, under `types`; everything else is inferred from the machine itself. Each of
28
+ these words has an entry in the [glossary](https://github.com/kamp-us/demlik/blob/main/packages/tea/docs/glossary.md).
27
29
 
28
30
  ```ts
29
31
  import { defineMachine } from "@demlik/tea";
@@ -41,14 +43,14 @@ const counter = defineMachine({
41
43
  },
42
44
  });
43
45
 
44
- const runtime = await run(counter, { ctx: {} }).ready;
46
+ const runtime = await run(counter, {}).ready;
45
47
  await runtime.dispatch({ type: "increment" });
46
48
  runtime.getState(); // { count: 1 }
47
49
  ```
48
50
 
49
51
  ## Two engines, one machine
50
52
 
51
- The core is `@demlik/tea`, and each engine has its own entry point. A machine
53
+ The core is `@demlik/tea`, and each [engine](https://github.com/kamp-us/demlik/blob/main/packages/tea/docs/glossary.md#engine) has its own entry point. A machine
52
54
  file imports only the core, so it runs unchanged on either engine.
53
55
 
54
56
  - `@demlik/tea` — the core: `defineMachine`, `Cmd`, `replay` and the types. It
@@ -59,20 +61,25 @@ file imports only the core, so it runs unchanged on either engine.
59
61
  Effects with typed errors, and closing the scope interrupts whatever is in
60
62
  flight.
61
63
 
62
- [Run a machine on the Promise engine](https://github.com/kamp-us/demlik/blob/main/docs/how-to/run-on-the-promise-engine.md)
63
- and [on the Effect engine](https://github.com/kamp-us/demlik/blob/main/docs/how-to/run-on-the-effect-engine.md)
64
- build on the same machine file. Coming from 0.15?
65
- [The migration guide](https://github.com/kamp-us/demlik/blob/main/docs/how-to/migrate-from-0-15.md)
64
+ [Run a machine on the Promise engine](https://github.com/kamp-us/demlik/blob/main/packages/tea/docs/how-to/run-on-the-promise-engine.md)
65
+ and [on the Effect engine](https://github.com/kamp-us/demlik/blob/main/packages/tea/docs/how-to/run-on-the-effect-engine.md)
66
+ build on the same machine file.
67
+ [Run many machines under one parent](https://github.com/kamp-us/demlik/blob/main/packages/tea/docs/how-to/run-many-machines.md)
68
+ starts child machines on the Effect engine with `spawn`, `tell` and `stop`.
69
+ Coming from 0.15?
70
+ [The migration guide](https://github.com/kamp-us/demlik/blob/main/packages/tea/docs/how-to/migrate-from-0-15.md)
66
71
  shows every removed or reshaped API, before and after.
67
72
 
68
73
  ## Documentation
69
74
 
70
- The four Diátaxis quadrants live in [`docs/`](https://github.com/kamp-us/demlik/blob/main/docs/README.md):
75
+ The four Diátaxis quadrants live in [`docs/`](https://github.com/kamp-us/demlik/blob/main/packages/tea/docs/README.md):
71
76
 
72
- - [Tutorials](https://github.com/kamp-us/demlik/blob/main/docs/tutorial/index.md) — learning-oriented lessons that take you through the library by building a real machine.
73
- - [How-to guides](https://github.com/kamp-us/demlik/blob/main/docs/how-to/index.md) — goal-oriented directions for getting a specific job done.
74
- - [Reference](https://github.com/kamp-us/demlik/blob/main/docs/reference/index.md) — information-oriented API description, generated per public module.
75
- - [Explanation](https://github.com/kamp-us/demlik/blob/main/docs/explanation/index.md) — understanding-oriented discussion of how it works and why it is shaped this way.
77
+ - [Tutorials](https://github.com/kamp-us/demlik/blob/main/packages/tea/docs/tutorial/index.md) — learning-oriented lessons that take you through the library by building a real machine.
78
+ - [How-to guides](https://github.com/kamp-us/demlik/blob/main/packages/tea/docs/how-to/index.md) — goal-oriented directions for getting a specific job done.
79
+ - [Reference](https://github.com/kamp-us/demlik/blob/main/packages/tea/docs/reference/index.md) — information-oriented API description, generated per public module.
80
+ - [Explanation](https://github.com/kamp-us/demlik/blob/main/packages/tea/docs/explanation/index.md) — understanding-oriented discussion of how it works and why it is shaped this way.
81
+
82
+ The [glossary](https://github.com/kamp-us/demlik/blob/main/packages/tea/docs/glossary.md) defines each word those pages use: Model, Msg, Cmd, Sub, Store and the rest.
76
83
 
77
84
  Two more surfaces sit behind those, for people working on the library rather than using it:
78
85
  [`.patterns/`](https://github.com/kamp-us/demlik/blob/main/.patterns/index.md) is how the code is shaped, and
@@ -1,19 +1,19 @@
1
- import { M as Machine, I as Interpret, S as Subscribe, H as HandlerCtx, C as Cmd } from '../core-Ce9ncpuv.js';
2
- import { b as DeadlinesSub } from '../index-e36uEyl4.js';
3
- export { a as DeadlineSub, m as deadlineSub, o as deadlinesSub, s as subscribeDeadline } from '../index-e36uEyl4.js';
4
- import { M as MessageContent, T as ToolCall, a as ToolOutcome, C as ContentPart, b as Conversation, c as AnyToolDef, d as ToolsCtx, e as AgentState, f as AgentTurn, g as ToolResult, A as AgentEvent, h as TurnChunk, i as AgentMachineMsg, W as WiredToolMsg, j as AgentCmd, k as ToolCmd, P as PlainModel, S as StreamingModel, l as ToolFailureOf, m as AgentTerminalFailure, N as NotReserved, n as ToolDef, o as ToolThrown, p as AgentEndedStatus, q as AgentConfigCore, r as CompactionPolicy, s as AgentKnob } from '../machine-CuojfZup.js';
5
- export { t as AGENT_EVENT_TYPES, u as AgentBootMsg, v as AgentCancelMsg, w as AgentCompactErrMsg, x as AgentCompactOkMsg, y as AgentCompactRunCmd, z as AgentCompactionConfig, B as AgentConfig, D as AgentEventHead, E as AgentFailure, F as AgentLifecycleNote, G as AgentLlmErrMsg, H as AgentLlmOkMsg, I as AgentLlmRunCmd, J as AgentSnapshotConfig, K as AgentStatus, L as AgentTimerMsg, O as AgentToMachine, Q as Awaiting, R as COMPACTION_PURPOSE, U as CompactInterpret, V as CompactionOutputs, X as CompactionPurpose, Y as CompactionSummary, Z as FILE_OMITTED, _ as FilePart, $ as IMAGE_OMITTED, a0 as ImagePart, a1 as Llm, a2 as LlmCall, a3 as LlmErr, a4 as LlmFailMsg, a5 as LlmOk, a6 as LlmRunCmd, a7 as LlmSucceedMsg, a8 as MediaSource, a9 as MessageLoader, aa as ModelFactory, ab as ModelPort, ac as ModelStream, ad as PLAIN_MODEL_MISROUTE_REASON, ae as ReservedToolName, af as Schema, ag as SnapshotInterpret, ah as TOOL_RETRY_EXHAUSTED_TAG, ai as TOOL_TIMEOUT_TAG, aj as TaggedFailure, ak as TextPart, al as ToolConstructors, am as ToolError, an as ToolFail, ao as ToolFailure, ap as ToolHandler, aq as ToolInput, ar as ToolMsg, as as ToolOk, at as ToolRecord, au as ToolRejectedCmd, av as ToolRejection, aw as ToolResilience, ax as ToolResilienceError, ay as ToolRetryExhausted, az as ToolRouter, aA as ToolSettlement, aB as ToolTimedOut, aC as TurnUsage, aD as WiredToolCmd, aE as agentBootMsg, aF as agentCancelMsg, aG as agentEvents, aH as agentTurnSchema, aI as compactionSummarySchema, aJ as contentParts, aK as fanOutInterpret, aL as isAgentTurn, aM as isCompactionSummary, aN as isReservedToolName, aO as isStreamingModel, aP as isTurnUsage, aQ as liftAgent, aR as mergeInterpret, aS as omitMedia, aT as plainModel, aU as status, aV as tool, aW as toolErrorReason, aX as toolRouter } from '../machine-CuojfZup.js';
1
+ import { M as Machine, I as Interpret, c as Subscribe, H as HandlerCtx, C as Cmd } from '../core-CtvAyPpH.js';
2
+ import { b as DeadlinesSub } from '../index-CVU7SK3a.js';
3
+ export { a as DeadlineSub, m as deadlineSub, o as deadlinesSub, s as subscribeDeadline } from '../index-CVU7SK3a.js';
4
+ import { M as MessageContent, T as ToolCall, a as ToolOutcome, C as ContentPart, b as Conversation, c as AnyToolDef, d as ToolsCtx, e as AgentState, f as AgentTurn, g as ToolResult, A as AgentEvent, h as TurnChunk, i as AgentMachineMsg, W as WiredToolMsg, j as AgentCmd, k as ToolCmd, P as PlainModel, S as StreamingModel, l as ToolFailureOf, m as AgentTerminalFailure, N as NotReserved, n as ToolDef, o as ToolThrown, p as AgentEndedStatus, q as AgentConfigCore, r as CompactionPolicy, s as AgentKnob } from '../machine-Dtre2TmN.js';
5
+ export { t as AGENT_EVENT_TYPES, u as AgentBootMsg, v as AgentCancelMsg, w as AgentCompactErrMsg, x as AgentCompactOkMsg, y as AgentCompactRunCmd, z as AgentCompactionConfig, B as AgentConfig, D as AgentEventHead, E as AgentFailure, F as AgentLifecycleNote, G as AgentLlmErrMsg, H as AgentLlmOkMsg, I as AgentLlmRunCmd, J as AgentSnapshotConfig, K as AgentStatus, L as AgentTimerMsg, O as AgentToMachine, Q as Awaiting, R as COMPACTION_PURPOSE, U as CompactInterpret, V as CompactionOutputs, X as CompactionPurpose, Y as CompactionSummary, Z as FILE_OMITTED, _ as FilePart, $ as IMAGE_OMITTED, a0 as ImagePart, a1 as Llm, a2 as LlmCall, a3 as LlmErr, a4 as LlmFailMsg, a5 as LlmOk, a6 as LlmRunCmd, a7 as LlmSucceedMsg, a8 as MediaSource, a9 as MessageLoader, aa as ModelFactory, ab as ModelPort, ac as ModelStream, ad as PLAIN_MODEL_MISROUTE_REASON, ae as ReservedToolName, af as Schema, ag as SnapshotInterpret, ah as TOOL_RETRY_EXHAUSTED_TAG, ai as TOOL_TIMEOUT_TAG, aj as TaggedFailure, ak as TextPart, al as ToolConstructors, am as ToolError, an as ToolFail, ao as ToolFailure, ap as ToolHandler, aq as ToolInput, ar as ToolMsg, as as ToolOk, at as ToolRecord, au as ToolRejectedCmd, av as ToolRejection, aw as ToolResilience, ax as ToolResilienceError, ay as ToolRetryExhausted, az as ToolRouter, aA as ToolSettlement, aB as ToolTimedOut, aC as TurnUsage, aD as WiredToolCmd, aE as agentBootMsg, aF as agentCancelMsg, aG as agentEvents, aH as agentTurnSchema, aI as compactionSummarySchema, aJ as contentParts, aK as fanOutInterpret, aL as isAgentTurn, aM as isCompactionSummary, aN as isReservedToolName, aO as isStreamingModel, aP as isTurnUsage, aQ as liftAgent, aR as mergeInterpret, aS as omitMedia, aT as plainModel, aU as status, aV as tool, aW as toolErrorReason, aX as toolRouter } from '../machine-Dtre2TmN.js';
6
6
  import { StandardSchemaV1 } from '@standard-schema/spec';
7
- import { C as CtxArg, S as Store } from '../runtime-types-BKg2CGMx.js';
8
- import { E as EndedRun } from '../index-Dy3379ve.js';
9
- export { M as MonitoredRunCmd, R as RunFailure } from '../index-Dy3379ve.js';
7
+ import { C as CtxArg, S as Store } from '../runtime-types-DEluQgGO.js';
8
+ import { E as EndedRun } from '../index-CZZ3HI-Z.js';
9
+ export { M as MonitoredRunCmd, R as RunFailure } from '../index-CZZ3HI-Z.js';
10
10
  import { RetryPolicy } from '../retry-backoff/index.js';
11
- import '../types-SzNSHKlV.js';
12
- import '../index-2kNxy6az.js';
11
+ import '../types-CXNzlbAg.js';
12
+ import '../index-CKtEKGyp.js';
13
13
  import '../protocol-ClRZBhHQ.js';
14
- import '../index-Ce5GYAuI.js';
15
- import '../index-DWdg7R1l.js';
16
- import '../index-D8sYVzCI.js';
14
+ import '../index-CrcoVfd_.js';
15
+ import '../index-D3NY3VCN.js';
16
+ import '../index-Bk2hBUdK.js';
17
17
 
18
18
  /**
19
19
  * @demlik/tea/agent — `defineAgent`, the convenience layer over `createAgent`.
@@ -181,6 +181,14 @@ interface DefineAgentConfig<T extends AnyToolDef> {
181
181
  * Stops a run that keeps going: the maximum number of model round-trips it
182
182
  * may take. Once the completed-turn count reaches it the run fails rather
183
183
  * than calling the model again. Omit → no limit on turns.
184
+ *
185
+ * The count is COMPLETED model round-trips. A compaction pass is not one, and
186
+ * tool calls are not counted at all: a turn that asks for six tools is one
187
+ * turn.
188
+ *
189
+ * The failure is `{ reason: "turn_limit", at }` on the Model's own `failure`
190
+ * field. `run` rejects with a `DriveFailedError` whose `.state` is that final
191
+ * Model.
184
192
  */
185
193
  readonly maxTurns?: number;
186
194
  /**
@@ -188,6 +196,12 @@ interface DefineAgentConfig<T extends AnyToolDef> {
188
196
  * advancing before it fails. The budget is a no-progress watchdog, not a
189
197
  * total wall-clock cap — it restarts each time the run moves. Omit → no
190
198
  * watchdog.
199
+ *
200
+ * The failure is `{ reason: "deadline", at }` on the Model's `run.failure`,
201
+ * the monitored-run slice, and not on the agent's own `failure` field where
202
+ * `turn_limit` and `elapsed_limit` land. `at` is when the watchdog fired. A
203
+ * tool or model call already out runs to its own end first, so `run` can
204
+ * settle later than `at`.
191
205
  */
192
206
  readonly deadlineMs?: number;
193
207
  /**
@@ -199,6 +213,12 @@ interface DefineAgentConfig<T extends AnyToolDef> {
199
213
  * at the turn boundary, so like both of those it stops the run rather than
200
214
  * cancelling the work already in flight. Omit → no wall-clock cap.
201
215
  *
216
+ * Read at the turn boundary means the run ends at the first boundary past
217
+ * the budget, not at the millisecond it comes due: a run 10ms into a 400ms
218
+ * tool call under a 150ms budget fails when that tool settles. The failure
219
+ * is `{ reason: "elapsed_limit", at }` on the Model's own `failure` field,
220
+ * beside `turn_limit`.
221
+ *
202
222
  * The run's start time is on the durable Model, so a run killed and resumed
203
223
  * continues the ORIGINAL budget — the time it spent dead counts against it.
204
224
  *
@@ -218,6 +238,10 @@ interface DefineAgentConfig<T extends AnyToolDef> {
218
238
  * run's provider-reported total), an external flag, a condition on the turns
219
239
  * so far. Omit → no predicate.
220
240
  *
241
+ * A stop you asked for is not a failure, so `run` RESOLVES with the final
242
+ * Model where the other three guards make it reject, and `status(state)`
243
+ * answers `{ kind: "cancelled", at }`.
244
+ *
221
245
  * It must be PURE: the reducer calls it, so a replay hands it the same state
222
246
  * and must get the same answer. And it is config rather than Model — a
223
247
  * resumed run consults the predicate the config passed to THIS boot, exactly
@@ -279,6 +303,13 @@ interface DefineAgentConfig<T extends AnyToolDef> {
279
303
  * summarize round-trip that enforces it is wiring, so the lid takes the
280
304
  * former and supplies the latter from the `model` it already has.
281
305
  *
306
+ * `afterTurns: 20` folds once the conversation holds twenty turns.
307
+ * `afterContextTokens: 8_000` folds once the last brain turn's reported
308
+ * `inputTokens + outputTokens` reaches eight thousand; the number is yours,
309
+ * because tea knows no model's window size. Set both and the first one
310
+ * reached folds. `keepTurns` is how many of the newest turns survive the
311
+ * fold intact. It is not a guard: nothing fails, and the run goes on.
312
+ *
282
313
  * Omit → NO compaction, exactly as before: the transcript grows for as long
283
314
  * as the model keeps asking for tools. Nothing is defaulted on your behalf —
284
315
  * a silent budget would change the prompt every existing caller sends.
@@ -1,16 +1,16 @@
1
- export { AGENT_EVENT_TYPES, COMPACTION_PURPOSE, FILE_OMITTED, IMAGE_OMITTED, PLAIN_MODEL_MISROUTE_REASON, TOOL_RETRY_EXHAUSTED_TAG, TOOL_TIMEOUT_TAG, agentBootMsg, agentCancelMsg, agentEvents, agentTool, agentTurnSchema, compactionSummarySchema, contentParts, createAgent, defineAgent, fanOutInterpret, isAgentTurn, isCompactionSummary, isReservedToolName, isStreamingModel, isTurnUsage, liftAgent, mergeInterpret, omitMedia, plainModel, renderPrompt, status, tool, toolErrorReason, toolRouter, transcript } from '../chunk-PCJA2HTZ.js';
2
- import '../chunk-XVIKSRCK.js';
3
- import '../chunk-YIMOFXST.js';
1
+ export { AGENT_EVENT_TYPES, COMPACTION_PURPOSE, FILE_OMITTED, IMAGE_OMITTED, PLAIN_MODEL_MISROUTE_REASON, TOOL_RETRY_EXHAUSTED_TAG, TOOL_TIMEOUT_TAG, agentBootMsg, agentCancelMsg, agentEvents, agentTool, agentTurnSchema, compactionSummarySchema, contentParts, createAgent, defineAgent, fanOutInterpret, isAgentTurn, isCompactionSummary, isReservedToolName, isStreamingModel, isTurnUsage, liftAgent, mergeInterpret, omitMedia, plainModel, renderPrompt, status, tool, toolErrorReason, toolRouter, transcript } from '../chunk-2774I242.js';
2
+ import '../chunk-EA47MI5Q.js';
3
+ import '../chunk-2R62Q5UK.js';
4
4
  import '../chunk-QNGYQMZB.js';
5
- import '../chunk-WTSOW2MD.js';
6
- export { deadlineSub, deadlinesSub, subscribeDeadline } from '../chunk-C3G2QFEZ.js';
5
+ import '../chunk-72CN3VPY.js';
6
+ export { deadlineSub, deadlinesSub, subscribeDeadline } from '../chunk-TAKPC6SD.js';
7
7
  import '../chunk-VBDU4JL6.js';
8
8
  import '../chunk-4LPY67E4.js';
9
9
  import '../chunk-TXN2KFHF.js';
10
- import '../chunk-H2ELKHI6.js';
11
- import '../chunk-AHW2CLPT.js';
12
- import '../chunk-JVE2LBFJ.js';
13
- import '../chunk-FNGZMVIT.js';
14
- import '../chunk-AIIXV4XB.js';
10
+ import '../chunk-JAKM53JF.js';
11
+ import '../chunk-UHAQ4PI6.js';
12
+ import '../chunk-A73IJ27X.js';
13
+ import '../chunk-DVNXEB7V.js';
14
+ import '../chunk-RKVUVALV.js';
15
15
  //# sourceMappingURL=index.js.map
16
16
  //# sourceMappingURL=index.js.map
@@ -1,10 +1,10 @@
1
- import { createMonitoredRun } from './chunk-XVIKSRCK.js';
1
+ import { createMonitoredRun } from './chunk-EA47MI5Q.js';
2
2
  import { createFanOut, initFanOut } from './chunk-QNGYQMZB.js';
3
- import { createResilientCall } from './chunk-WTSOW2MD.js';
4
- import { deadlinesSub, subscribeDeadline } from './chunk-C3G2QFEZ.js';
3
+ import { createResilientCall } from './chunk-72CN3VPY.js';
4
+ import { deadlinesSub, subscribeDeadline } from './chunk-TAKPC6SD.js';
5
5
  import { rejectAll, unchecked } from './chunk-4LPY67E4.js';
6
- import { run, driveToDone } from './chunk-H2ELKHI6.js';
7
- import { Cmd, absurd, Outcome, cmdEdgeOf, detachWorkOf, defineMachine, validateSync, malformedResult, describeError, DriveFailedError } from './chunk-AIIXV4XB.js';
6
+ import { run, driveToDone } from './chunk-JAKM53JF.js';
7
+ import { Cmd, absurd, Outcome, cmdEdgeOf, detachWorkOf, defineMachine, validateSync, malformedResult, describeError, DriveFailedError } from './chunk-RKVUVALV.js';
8
8
 
9
9
  // src/internal/llm-call/index.ts
10
10
  function createLlmCall(config, rng = Math.random) {
@@ -1777,5 +1777,5 @@ function createAgent(config) {
1777
1777
  }
1778
1778
 
1779
1779
  export { AGENT_EVENT_TYPES, COMPACTION_PURPOSE, FILE_OMITTED, IMAGE_OMITTED, PLAIN_MODEL_MISROUTE_REASON, TOOL_RETRY_EXHAUSTED_TAG, TOOL_TIMEOUT_TAG, agentBootMsg, agentCancelMsg, agentEvents, agentTool, agentTurnSchema, compactionSummarySchema, contentParts, createAgent, defineAgent, fanOutInterpret, isAgentTurn, isCompactionSummary, isReservedToolName, isStreamingModel, isTurnUsage, liftAgent, mergeInterpret, omitMedia, plainModel, renderPrompt, status, tool, toolErrorReason, toolRouter, transcript };
1780
- //# sourceMappingURL=chunk-PCJA2HTZ.js.map
1781
- //# sourceMappingURL=chunk-PCJA2HTZ.js.map
1780
+ //# sourceMappingURL=chunk-2774I242.js.map
1781
+ //# sourceMappingURL=chunk-2774I242.js.map