@tangle-network/agent-runtime 0.104.0 → 0.106.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 (217) hide show
  1. package/README.md +176 -42
  2. package/dist/activation-CRjVfOiy.js +203 -0
  3. package/dist/activation-CRjVfOiy.js.map +1 -0
  4. package/dist/activation-DyWB0K6E.d.ts +98 -0
  5. package/dist/agent.d.ts +216 -234
  6. package/dist/agent.js +615 -547
  7. package/dist/agent.js.map +1 -1
  8. package/dist/analyst-loop-DGdtVENg.js +517 -0
  9. package/dist/analyst-loop-DGdtVENg.js.map +1 -0
  10. package/dist/analyst-loop.d.ts +10 -43
  11. package/dist/analyst-loop.js +2 -11
  12. package/dist/backends-Dy8NujB4.js +713 -0
  13. package/dist/backends-Dy8NujB4.js.map +1 -0
  14. package/dist/candidate-execution/index.d.ts +4 -192
  15. package/dist/candidate-execution/index.js +5 -66
  16. package/dist/candidate-execution-DqMbv1rU.js +488 -0
  17. package/dist/candidate-execution-DqMbv1rU.js.map +1 -0
  18. package/dist/coder-yhVWbdWc.js +40 -0
  19. package/dist/coder-yhVWbdWc.js.map +1 -0
  20. package/dist/conversation-XucG_K3l.js +1265 -0
  21. package/dist/conversation-XucG_K3l.js.map +1 -0
  22. package/dist/conversation.d.ts +2 -804
  23. package/dist/conversation.js +2 -55
  24. package/dist/environment-provider-CfLUmKmf.js +1168 -0
  25. package/dist/environment-provider-CfLUmKmf.js.map +1 -0
  26. package/dist/environment-provider-IUGU3epE.d.ts +964 -0
  27. package/dist/environment-provider.d.ts +2 -78
  28. package/dist/environment-provider.js +2 -18
  29. package/dist/errors-DEAvWQPy.js +111 -0
  30. package/dist/errors-DEAvWQPy.js.map +1 -0
  31. package/dist/improvement-adapter-Cr5TBSji.d.ts +166 -0
  32. package/dist/improvement-cycle-C095kS_g.js +2624 -0
  33. package/dist/improvement-cycle-C095kS_g.js.map +1 -0
  34. package/dist/index-BGdxAwfO.d.ts +838 -0
  35. package/dist/index-C-FYUuFG.d.ts +193 -0
  36. package/dist/index-CbNM40xG.d.ts +140 -0
  37. package/dist/index-DruSKs3Z.d.ts +7224 -0
  38. package/dist/index-Efjb3nrQ.d.ts +671 -0
  39. package/dist/index.d.ts +14 -1134
  40. package/dist/index.js +2134 -1972
  41. package/dist/index.js.map +1 -1
  42. package/dist/intelligence.d.ts +776 -888
  43. package/dist/intelligence.js +1466 -1410
  44. package/dist/intelligence.js.map +1 -1
  45. package/dist/{kb-gate-CwHO0vz6.d.ts → kb-gate-C8z2juK8.d.ts} +33 -31
  46. package/dist/kb-gate-DpaSwXVx.js +80 -0
  47. package/dist/kb-gate-DpaSwXVx.js.map +1 -0
  48. package/dist/knowledge-Ku-mPP4f.js +433 -0
  49. package/dist/knowledge-Ku-mPP4f.js.map +1 -0
  50. package/dist/knowledge.d.ts +2 -150
  51. package/dist/knowledge.js +2 -40
  52. package/dist/local-harness-Dh8PJ0ot.d.ts +455 -0
  53. package/dist/loop-runner-bin-BXsFEUcf.d.ts +162 -0
  54. package/dist/loop-runner-bin-BwjQ1NfH.js +268 -0
  55. package/dist/loop-runner-bin-BwjQ1NfH.js.map +1 -0
  56. package/dist/loop-runner-bin.d.ts +2 -17
  57. package/dist/loop-runner-bin.js +2 -24
  58. package/dist/loops.d.ts +5 -4164
  59. package/dist/loops.js +8 -419
  60. package/dist/mcp/bin.d.ts +1 -1
  61. package/dist/mcp/bin.js +116 -146
  62. package/dist/mcp/bin.js.map +1 -1
  63. package/dist/mcp/index.d.ts +295 -437
  64. package/dist/mcp/index.js +1242 -1177
  65. package/dist/mcp/index.js.map +1 -1
  66. package/dist/mcp/memory-bin.d.ts +1 -1
  67. package/dist/mcp/memory-bin.js +37 -16
  68. package/dist/mcp/memory-bin.js.map +1 -1
  69. package/dist/memory-server-DL6cE2Ag.js +234 -0
  70. package/dist/memory-server-DL6cE2Ag.js.map +1 -0
  71. package/dist/model-resolution-Btd9iIKV.js +98 -0
  72. package/dist/model-resolution-Btd9iIKV.js.map +1 -0
  73. package/dist/openai-tools-B68JaOCx.d.ts +24 -0
  74. package/dist/openai-tools-CKLy1C7M.js +44 -0
  75. package/dist/openai-tools-CKLy1C7M.js.map +1 -0
  76. package/dist/otel-export-D34IQW1C.js +843 -0
  77. package/dist/otel-export-D34IQW1C.js.map +1 -0
  78. package/dist/platform.d.ts +188 -185
  79. package/dist/platform.js +185 -218
  80. package/dist/platform.js.map +1 -1
  81. package/dist/prepare-B53sPV7M.js +4292 -0
  82. package/dist/prepare-B53sPV7M.js.map +1 -0
  83. package/dist/primeintellect/index.d.ts +150 -147
  84. package/dist/primeintellect/index.js +626 -1004
  85. package/dist/primeintellect/index.js.map +1 -1
  86. package/dist/profiles.d.ts +296 -490
  87. package/dist/profiles.js +722 -749
  88. package/dist/profiles.js.map +1 -1
  89. package/dist/protected-model-port-BLPH5VVv.js +722 -0
  90. package/dist/protected-model-port-BLPH5VVv.js.map +1 -0
  91. package/dist/protected-model-port-BP6Z4eau.d.ts +283 -0
  92. package/dist/protected-redaction--F3v1oo8.js +200 -0
  93. package/dist/protected-redaction--F3v1oo8.js.map +1 -0
  94. package/dist/redact-D-u-rrcn.js +82 -0
  95. package/dist/redact-D-u-rrcn.js.map +1 -0
  96. package/dist/redact-kbIOjfjM.d.ts +452 -0
  97. package/dist/researcher-CoVqNhfI.js +433 -0
  98. package/dist/researcher-CoVqNhfI.js.map +1 -0
  99. package/dist/runtime-BG0BziaP.js +5408 -0
  100. package/dist/runtime-BG0BziaP.js.map +1 -0
  101. package/dist/sandbox-events-DeI5xX8P.js +316 -0
  102. package/dist/sandbox-events-DeI5xX8P.js.map +1 -0
  103. package/dist/spawn-journal-CwPvKUTa.js +456 -0
  104. package/dist/spawn-journal-CwPvKUTa.js.map +1 -0
  105. package/dist/structural-rollout-IXUEplky.js +1445 -0
  106. package/dist/structural-rollout-IXUEplky.js.map +1 -0
  107. package/dist/substrate-B0TYNrXn.js +27 -0
  108. package/dist/substrate-B0TYNrXn.js.map +1 -0
  109. package/dist/{substrate-Dyiqmd3o.d.ts → substrate-BcnuSHXm.d.ts} +57 -54
  110. package/dist/supervise-BiRutHS9.js +7321 -0
  111. package/dist/supervise-BiRutHS9.js.map +1 -0
  112. package/dist/supervisor-DTKhF-RV.js +3826 -0
  113. package/dist/supervisor-DTKhF-RV.js.map +1 -0
  114. package/dist/testing.d.ts +4 -3
  115. package/dist/testing.js +2478 -2637
  116. package/dist/testing.js.map +1 -1
  117. package/dist/tool-server-RcWgLIsL.js +141 -0
  118. package/dist/tool-server-RcWgLIsL.js.map +1 -0
  119. package/dist/trace-propagation-CJJC7SVB.js +57 -0
  120. package/dist/trace-propagation-CJJC7SVB.js.map +1 -0
  121. package/dist/types-BaIpb0XT.d.ts +492 -0
  122. package/dist/types-BevOjfTY.d.ts +765 -0
  123. package/dist/types-C9j4qg6l.d.ts +500 -0
  124. package/dist/types-Cja5OTGh.d.ts +190 -0
  125. package/dist/util-MVgdwuIS.js +145 -0
  126. package/dist/util-MVgdwuIS.js.map +1 -0
  127. package/dist/workspace-archive-BosQiotA.js +575 -0
  128. package/dist/workspace-archive-BosQiotA.js.map +1 -0
  129. package/package.json +43 -55
  130. package/skills/build-with-agent-runtime/SKILL.md +16 -9
  131. package/skills/loop-writer/SKILL.md +1 -1
  132. package/dist/activation-Cm-9MMX1.d.ts +0 -69
  133. package/dist/analyst-loop.js.map +0 -1
  134. package/dist/backends-BO4Jqoe2.d.ts +0 -134
  135. package/dist/candidate-execution/index.js.map +0 -1
  136. package/dist/chunk-2KGAN2HM.js +0 -1256
  137. package/dist/chunk-2KGAN2HM.js.map +0 -1
  138. package/dist/chunk-2QJSNOGK.js +0 -48
  139. package/dist/chunk-2QJSNOGK.js.map +0 -1
  140. package/dist/chunk-2UABGGUB.js +0 -474
  141. package/dist/chunk-2UABGGUB.js.map +0 -1
  142. package/dist/chunk-2VZYRB55.js +0 -834
  143. package/dist/chunk-2VZYRB55.js.map +0 -1
  144. package/dist/chunk-2X65HYMI.js +0 -3526
  145. package/dist/chunk-2X65HYMI.js.map +0 -1
  146. package/dist/chunk-3MDZX7YU.js +0 -125
  147. package/dist/chunk-3MDZX7YU.js.map +0 -1
  148. package/dist/chunk-3PPVCS75.js +0 -199
  149. package/dist/chunk-3PPVCS75.js.map +0 -1
  150. package/dist/chunk-5HNDYWUT.js +0 -6424
  151. package/dist/chunk-5HNDYWUT.js.map +0 -1
  152. package/dist/chunk-5IBQAPVB.js +0 -29
  153. package/dist/chunk-5IBQAPVB.js.map +0 -1
  154. package/dist/chunk-5QOB7H74.js +0 -387
  155. package/dist/chunk-5QOB7H74.js.map +0 -1
  156. package/dist/chunk-ATDFUJYI.js +0 -4728
  157. package/dist/chunk-ATDFUJYI.js.map +0 -1
  158. package/dist/chunk-B7K7V22Y.js +0 -699
  159. package/dist/chunk-B7K7V22Y.js.map +0 -1
  160. package/dist/chunk-DPEUKJRO.js +0 -27
  161. package/dist/chunk-DPEUKJRO.js.map +0 -1
  162. package/dist/chunk-FD2MBMOH.js +0 -494
  163. package/dist/chunk-FD2MBMOH.js.map +0 -1
  164. package/dist/chunk-FJI3EXU3.js +0 -2402
  165. package/dist/chunk-FJI3EXU3.js.map +0 -1
  166. package/dist/chunk-HAO4CXHP.js +0 -200
  167. package/dist/chunk-HAO4CXHP.js.map +0 -1
  168. package/dist/chunk-ISPWRSEC.js +0 -408
  169. package/dist/chunk-ISPWRSEC.js.map +0 -1
  170. package/dist/chunk-KRBFHMV6.js +0 -1228
  171. package/dist/chunk-KRBFHMV6.js.map +0 -1
  172. package/dist/chunk-L5DST3QC.js +0 -351
  173. package/dist/chunk-L5DST3QC.js.map +0 -1
  174. package/dist/chunk-M22PL4GH.js +0 -171
  175. package/dist/chunk-M22PL4GH.js.map +0 -1
  176. package/dist/chunk-NURIQBJQ.js +0 -72
  177. package/dist/chunk-NURIQBJQ.js.map +0 -1
  178. package/dist/chunk-PZZKQVQV.js +0 -52
  179. package/dist/chunk-PZZKQVQV.js.map +0 -1
  180. package/dist/chunk-Q2JSAVQ3.js +0 -671
  181. package/dist/chunk-Q2JSAVQ3.js.map +0 -1
  182. package/dist/chunk-SBTWKPVR.js +0 -5576
  183. package/dist/chunk-SBTWKPVR.js.map +0 -1
  184. package/dist/chunk-SGKPNBXE.js +0 -60
  185. package/dist/chunk-SGKPNBXE.js.map +0 -1
  186. package/dist/chunk-SNSMRT6H.js +0 -680
  187. package/dist/chunk-SNSMRT6H.js.map +0 -1
  188. package/dist/chunk-STJEHM5F.js +0 -1338
  189. package/dist/chunk-STJEHM5F.js.map +0 -1
  190. package/dist/chunk-UPWGXKXB.js +0 -254
  191. package/dist/chunk-UPWGXKXB.js.map +0 -1
  192. package/dist/chunk-YEJR7IXO.js +0 -68
  193. package/dist/chunk-YEJR7IXO.js.map +0 -1
  194. package/dist/chunk-ZXICDSAK.js +0 -907
  195. package/dist/chunk-ZXICDSAK.js.map +0 -1
  196. package/dist/completion-gate-Bv47cOnn.d.ts +0 -256
  197. package/dist/conversation.js.map +0 -1
  198. package/dist/coordination-CxtzMxSM.d.ts +0 -2570
  199. package/dist/environment-provider.js.map +0 -1
  200. package/dist/improve--2A0gK1-.d.ts +0 -440
  201. package/dist/improvement-adapter-HAZz-7vK.d.ts +0 -203
  202. package/dist/knowledge.js.map +0 -1
  203. package/dist/local-harness-CtK9dSny.d.ts +0 -175
  204. package/dist/loop-runner-bin-DUOGtvOl.d.ts +0 -207
  205. package/dist/loop-runner-bin.js.map +0 -1
  206. package/dist/loops.js.map +0 -1
  207. package/dist/openai-tools-fnj6SRVg.d.ts +0 -46
  208. package/dist/protected-model-port-DzkUY3HQ.d.ts +0 -271
  209. package/dist/sanitize-DEbPNtyI.d.ts +0 -328
  210. package/dist/structural-rollout-C4mabf87.d.ts +0 -446
  211. package/dist/supervise-7q9F5brx.d.ts +0 -379
  212. package/dist/types-BCoemcXU.d.ts +0 -802
  213. package/dist/types-BwoZWq-i.d.ts +0 -510
  214. package/dist/types-Cbp72qyu.d.ts +0 -491
  215. package/dist/types-CmYCMbFT.d.ts +0 -203
  216. package/dist/types-CvNwMzQt.d.ts +0 -957
  217. package/dist/worktree-fanout-WsOzt8qu.d.ts +0 -999
@@ -1,804 +1,2 @@
1
- import { c as AgentExecutionBackend, k as RuntimeSessionStore } from './types-BwoZWq-i.js';
2
- import { AgentProfile, MaximumCharge } from '@tangle-network/agent-eval';
3
- import { Scenario, ProfileDispatchFn } from '@tangle-network/agent-eval/campaign';
4
-
5
- /**
6
- *
7
- * Per-call resilience policy for participant backends: deadline, retry with
8
- * backoff, and a circuit breaker. Each policy is applied *around* a single
9
- * turn's backend invocation, not across the whole conversation — the
10
- * conversation-level credit cap and `maxTurns` bound the broader run.
11
- *
12
- * Deadlines abort the underlying backend stream via `AbortSignal` linkage so
13
- * the OpenAI/SDK clients tear down their HTTP request cleanly instead of
14
- * leaking sockets. Retries replay the same logical turn (same `turnId`) so
15
- * any caching gateway can dedupe. Circuit breakers are *per participant*: A's
16
- * failures don't open B's breaker.
17
- *
18
- * @stable
19
- */
20
- /** Pure judgment of whether an error is worth retrying. Defaults: TimeoutError, AbortError, fetch-level network errors. */
21
- type RetryableErrorPredicate = (err: unknown) => boolean;
22
- /** Backoff between attempts. Constant ms, or `(attempt: 1-indexed) => ms`. */
23
- type RetryBackoff = number | ((attempt: number) => number);
24
- /** Circuit-breaker tuning. `failuresToOpen` consecutive failures opens it; closed only after `cooldownMs`. */
25
- interface CircuitBreakerConfig {
26
- failuresToOpen: number;
27
- cooldownMs: number;
28
- }
29
- interface BackendCallPolicy {
30
- /** Per-attempt wall clock limit. Exceeding fires an AbortSignal and is treated as a retryable failure. */
31
- perAttemptDeadlineMs?: number;
32
- /** Number of retries after the first attempt; total attempts = 1 + maxRetries. Default 0. */
33
- maxRetries?: number;
34
- /** Backoff between attempts. Default 250ms with jitter. */
35
- retryBackoffMs?: RetryBackoff;
36
- /** Custom retry classifier. Defaults to {@link defaultIsRetryable}. */
37
- isRetryable?: RetryableErrorPredicate;
38
- /** Circuit breaker that opens after N consecutive failures per participant. */
39
- circuitBreaker?: CircuitBreakerConfig;
40
- }
41
- /** Thrown when the circuit breaker is open for a participant and no retry is allowed yet. */
42
- declare class CircuitOpenError extends Error {
43
- constructor(participant: string, retryAfterMs: number);
44
- }
45
- /** Thrown when a backend call exceeds its per-attempt deadline. */
46
- declare class DeadlineExceededError extends Error {
47
- constructor(deadlineMs: number);
48
- }
49
- /**
50
- * Default retryable classification — network/timeout class errors. Errors
51
- * a model deliberately throws (validation, refusal, 4xx) are not retried;
52
- * those represent real outcomes, not transient infrastructure faults.
53
- */
54
- declare const defaultIsRetryable: RetryableErrorPredicate;
55
- /** Live circuit-breaker state — one instance per (participant, conversation run). */
56
- declare class CircuitBreakerState {
57
- private readonly config;
58
- private consecutiveFailures;
59
- private openedAt;
60
- constructor(config: CircuitBreakerConfig | undefined);
61
- /**
62
- * Check whether the next call is allowed. Throws `CircuitOpenError` when
63
- * the breaker is open and the cooldown hasn't elapsed.
64
- */
65
- preflight(participant: string, now?: number): void;
66
- recordSuccess(): void;
67
- recordFailure(now?: number): void;
68
- }
69
- /**
70
- * Build a per-attempt AbortSignal linked to the parent signal AND fired when
71
- * the deadline elapses. The returned `dispose()` MUST be called in a
72
- * `finally` (clears the timer, detaches the listener) so we don't leak.
73
- *
74
- * When the deadline fires, the signal's `reason` is a `DeadlineExceededError`
75
- * — callers can detect timeout-vs-cancel by reading `signal.reason` after
76
- * the underlying operation throws.
77
- */
78
- declare function makePerAttemptSignal(parentSignal: AbortSignal | undefined, deadlineMs: number | undefined): {
79
- signal: AbortSignal;
80
- dispose: () => void;
81
- getDeadlineError(): DeadlineExceededError | undefined;
82
- };
83
- /** Compute the delay before the next attempt. Default: 250ms exponential with jitter. */
84
- declare function computeBackoff(spec: RetryBackoff | undefined, attempt: number): number;
85
- /** Resolve after `ms` milliseconds — used for retry backoff in conversation call policy. */
86
- declare function sleep(ms: number): Promise<void>;
87
-
88
- /**
89
- *
90
- * Cross-gateway forwarding headers — the wire-level contract that makes
91
- * agent-to-agent communication composable across organizational boundaries.
92
- * Every header here is read on inbound and re-emitted on outbound, so a chain
93
- * `caller → A's gateway → A's runtime → B's gateway → B's runtime` ends with
94
- * B billing the original user, the depth counter monotonically incremented,
95
- * and the run/turn correlation IDs preserved end-to-end.
96
- *
97
- * The actual depth refusal (HTTP 413 at MAX_DEPTH) is enforced by
98
- * `agent-gateway`'s middleware; this module owns the names + the propagation
99
- * rules so both sides agree.
100
- *
101
- * Full protocol: `docs/agent-bus-protocol.md`.
102
- *
103
- * @stable
104
- */
105
- /** Standard names — lowercased so Headers maps interop on every runtime. */
106
- declare const FORWARD_HEADERS: {
107
- /** Forwarded original-user identity (`Bearer sk-tan-<user>`); downstream gateways bill against this. */
108
- readonly authorization: "x-tangle-forwarded-authorization";
109
- /** Monotonically incremented on every gateway hop. Refused at MAX_DEPTH. */
110
- readonly depth: "x-tangle-forwarded-depth";
111
- /** Top-level conversation run identifier, propagated through every nested call. */
112
- readonly runId: "x-tangle-runid";
113
- /** This call's turn within the run; deterministic + stable across retries. */
114
- readonly turnId: "x-tangle-turnid";
115
- /** When the call is *inside* another turn (recursion), the parent turn's id. */
116
- readonly parentTurnId: "x-tangle-parent-turnid";
117
- /** Logical conversation peer label at the sending side, for trace stitching. */
118
- readonly speaker: "x-tangle-speaker";
119
- };
120
- type ForwardHeaderName = (typeof FORWARD_HEADERS)[keyof typeof FORWARD_HEADERS];
121
- /** Hard cap on chained gateway hops; refused beyond this. Default keeps recursion bounded. */
122
- declare const DEFAULT_MAX_DEPTH = 4;
123
- /**
124
- * Read the depth counter off an inbound request. Missing → 0 (caller is the
125
- * origin). Non-integer → throws — silent coercion would let a bad caller
126
- * reset depth and bypass the limit.
127
- */
128
- declare function readDepth(headers: Readonly<Record<string, string | string[] | undefined>>): number;
129
- /**
130
- * Refuse further forwarding when the inbound depth has reached the limit.
131
- * Callers (the gateway middleware) translate the boolean to an HTTP 413.
132
- */
133
- declare function isDepthExceeded(inboundDepth: number, max?: number): boolean;
134
- /**
135
- * Build the headers to emit on an outbound participant call, given the
136
- * conversation's propagation context. Depth is incremented from the inbound
137
- * value; runId / turnId / speaker stamp the current hop; the user's
138
- * `Authorization` is preserved verbatim so the downstream gateway bills the
139
- * right wallet.
140
- */
141
- declare function buildForwardHeaders(input: {
142
- inboundDepth: number;
143
- forwardedAuthorization?: string;
144
- runId: string;
145
- turnId: string;
146
- parentTurnId?: string;
147
- speaker: string;
148
- }): Record<string, string>;
149
- /**
150
- * Header bag carried through `AgentBackendContext.propagatedHeaders` so
151
- * backends that opt in can merge them into their outbound HTTP requests.
152
- * Distinct from `buildForwardHeaders` so callers can attach extra
153
- * non-protocol headers (e.g. tracing) without colliding.
154
- */
155
- type PropagatedHeaders = Readonly<Record<string, string>>;
156
-
157
- /**
158
- *
159
- * Durable conversation transcript — survives a driver process crash mid-run.
160
- * The runner journals every committed turn before yielding `turn_end`, so a
161
- * resumed run replays the same `runId` against the same journal and picks up
162
- * from the first un-recorded turn. Combined with the deterministic
163
- * `turnId(runId, index, speaker)`, a retried turn collides with the prior
164
- * attempt's id and any caching gateway can dedupe.
165
- *
166
- * The interface is small enough that a Cloudflare D1 / R2 / postgres adapter
167
- * is ~30 lines. The in-memory adapter is the default for tests and scratch.
168
- * The file adapter (JSONL on disk) is the default-durable choice when no
169
- * upstream store is wired.
170
- *
171
- * @stable
172
- */
173
-
174
- interface ConversationJournalEntry {
175
- runId: string;
176
- startedAt: string;
177
- /** Set when the run reaches a terminal state. */
178
- halted?: HaltReason;
179
- endedAt?: string;
180
- turns: ConversationTurn[];
181
- }
182
- interface ConversationJournal {
183
- /**
184
- * Load any prior state for `runId`. Returns `undefined` for a fresh run.
185
- * Implementations MUST NOT mutate the returned object — the runner clones
186
- * before continuing — but the runtime treats absence and emptiness
187
- * identically, so a journal with zero turns is equivalent to "fresh."
188
- */
189
- loadRun(runId: string): Promise<ConversationJournalEntry | undefined>;
190
- /**
191
- * Initialise journal state for a fresh run. Called once per run, before any
192
- * `appendTurn`. Idempotent: calling with an existing runId is a no-op if
193
- * the entry already exists with the same `startedAt`.
194
- */
195
- beginRun(runId: string, startedAt: string): Promise<void>;
196
- /**
197
- * Append a committed turn. The runner only calls this AFTER the turn's
198
- * backend stream completed and the credit total has been updated, so an
199
- * appended turn is observed-committed and never speculative.
200
- */
201
- appendTurn(runId: string, turn: ConversationTurn): Promise<void>;
202
- /**
203
- * Record the run's terminal halt reason + end time. Once called, the run
204
- * is observed-final; subsequent `loadRun` returns the same halt.
205
- */
206
- recordHalt(runId: string, halt: HaltReason, endedAt: string): Promise<void>;
207
- }
208
- /** In-memory `ConversationJournal` — suitable for testing and single-process runs. */
209
- declare class InMemoryConversationJournal implements ConversationJournal {
210
- private readonly entries;
211
- loadRun(runId: string): Promise<ConversationJournalEntry | undefined>;
212
- beginRun(runId: string, startedAt: string): Promise<void>;
213
- appendTurn(runId: string, turn: ConversationTurn): Promise<void>;
214
- recordHalt(runId: string, halt: HaltReason, endedAt: string): Promise<void>;
215
- }
216
- /**
217
- * JSONL on disk. One line per record; first line is the `begin`, subsequent
218
- * lines are `turn` records, terminal line is `halt`. Replays the whole file
219
- * on `loadRun` — cheap for the conversation sizes this is designed for
220
- * (thousands of turns, not millions). For huge runs, plug in a real DB
221
- * adapter; the interface is small.
222
- *
223
- * Each `appendTurn` / `recordHalt` calls `fsync` after the write so a
224
- * process crash between writes never loses an acknowledged turn.
225
- */
226
- declare class FileConversationJournal implements ConversationJournal {
227
- private readonly path;
228
- constructor(path: string);
229
- loadRun(runId: string): Promise<ConversationJournalEntry | undefined>;
230
- beginRun(runId: string, startedAt: string): Promise<void>;
231
- appendTurn(runId: string, turn: ConversationTurn): Promise<void>;
232
- recordHalt(runId: string, halt: HaltReason, endedAt: string): Promise<void>;
233
- private appendRecord;
234
- }
235
-
236
- /**
237
- *
238
- * Public types for multi-agent conversations. A `Conversation` is two-or-more
239
- * participants taking turns through their own `AgentExecutionBackend`s, driven
240
- * by a `ConversationPolicy` (turn order, halting, hard credit ceiling).
241
- *
242
- * Each participant's backend can resolve to any reachable endpoint —
243
- * in-process iterable, local cli-bridge, sandbox, router, or a remote
244
- * agent-gateway — so the same `runConversation` call drives same-machine,
245
- * same-cloud, and cross-cloud orchestration without code change.
246
- *
247
- * @stable
248
- */
249
-
250
- /** @stable */
251
- interface ConversationParticipant {
252
- /**
253
- * Stable name used as the speaker label in the transcript. Must be unique
254
- * within a `Conversation`.
255
- */
256
- name: string;
257
- /**
258
- * Backend that runs this participant's turn. Reuses the existing
259
- * `AgentExecutionBackend` contract from `runAgentTaskStream`, so any
260
- * registered backend (iterable, sandbox, OpenAI-compatible) works without
261
- * adaptation.
262
- */
263
- backend: AgentExecutionBackend;
264
- /**
265
- * Optional human label for traces / dashboards. Distinct from `name`, which
266
- * is the addressing key.
267
- */
268
- label?: string;
269
- /**
270
- * Optional per-participant override of the conversation's default
271
- * `callPolicy`. Use to tighten the deadline or raise the retry budget for
272
- * a participant known to be slow or flaky.
273
- */
274
- callPolicy?: BackendCallPolicy;
275
- /**
276
- * Who pays for THIS participant's outbound calls?
277
- *
278
- * - `'forward-user'` (default) — propagate the caller's
279
- * `X-Tangle-Forwarded-Authorization` so the downstream gateway bills the
280
- * original user. Right for pass-through agents that aggregate/route
281
- * without taking economic risk.
282
- * - `'agent-owned'` — DO NOT forward the user's auth; the participant's
283
- * backend uses its own credentials (typically a sk-tan-AGENT or x402
284
- * wallet baked into the backend at construction). Downstream charges
285
- * land on the agent, not the user. Right for resold-bundle agents that
286
- * take margin between their inbound price and their sub-agent costs.
287
- * - `(state) => AuthSource` — per-turn / per-condition decision, e.g. base
288
- * sub-services are agent-owned but premium add-ons forward the user.
289
- *
290
- * The agent's own credentials live on the backend (set at construction
291
- * time, e.g. `createOpenAICompatibleBackend({ apiKey })`); this field is
292
- * purely about *whether to also forward the user's identity downstream*.
293
- */
294
- authSource?: AuthSource;
295
- }
296
- /** @stable */
297
- type AuthSource = 'forward-user' | 'agent-owned' | ((state: ConversationDriveState) => 'forward-user' | 'agent-owned');
298
- /** @stable */
299
- type TurnOrder = 'alternate' | 'round-robin' | ((state: ConversationDriveState) => number);
300
- /** @stable */
301
- interface ConversationDriveState {
302
- transcript: readonly ConversationTurn[];
303
- turnIndex: number;
304
- spentCreditsCents: number;
305
- }
306
- /** @stable */
307
- interface HaltContext extends ConversationDriveState {
308
- lastTurn: ConversationTurn;
309
- }
310
- /** @stable */
311
- interface HaltSignal {
312
- halted: true;
313
- reason: string;
314
- }
315
- /** @stable */
316
- type HaltPredicate = (ctx: HaltContext) => boolean | HaltSignal | Promise<boolean | HaltSignal>;
317
- /** @stable */
318
- type HaltReason = {
319
- kind: 'max_turns';
320
- turns: number;
321
- } | {
322
- kind: 'max_credits';
323
- spentCents: number;
324
- capCents: number;
325
- } | {
326
- kind: 'predicate';
327
- reason: string;
328
- } | {
329
- kind: 'abort';
330
- } | {
331
- kind: 'participant_error';
332
- participant: string;
333
- message: string;
334
- };
335
- /** @stable */
336
- interface ConversationPolicy {
337
- /** Hard cap on speaker-turns. Each call into a participant's backend counts as 1. */
338
- maxTurns: number;
339
- /**
340
- * Hard cap on aggregate credit spend across all participants, in cents.
341
- * Computed by summing `llm_call.costUsd` from every participant's stream.
342
- * Unset (`undefined`) means no credit ceiling — the run is bounded only by
343
- * `maxTurns` and `haltOn`.
344
- */
345
- maxCreditsCents?: number;
346
- /**
347
- * Speaker selection. Defaults to `'alternate'` for two-participant
348
- * conversations and `'round-robin'` for any other arity.
349
- */
350
- turnOrder?: TurnOrder;
351
- /**
352
- * Optional convergence / content-based halt. Called after every turn ends;
353
- * returning truthy stops the loop with `{ kind: 'predicate', ... }`.
354
- */
355
- haltOn?: HaltPredicate;
356
- /**
357
- * Default per-turn resilience policy applied to every participant call
358
- * (deadline, retries, circuit breaker). Individual participants may
359
- * override via `ConversationParticipant.callPolicy`.
360
- */
361
- defaultCallPolicy?: BackendCallPolicy;
362
- }
363
- /** @stable */
364
- interface ConversationTurn {
365
- index: number;
366
- speaker: string;
367
- /**
368
- * Deterministic turn identifier — stable across retries of the same logical
369
- * turn so caching gateways and trace backends can dedupe. Shape:
370
- * `${runId}.t${index}.${speakerSlug}`.
371
- */
372
- turnId: string;
373
- /** Backend session used for this turn. Present on turns recorded by session-aware runners. */
374
- sessionId?: string;
375
- text: string;
376
- /**
377
- * Aggregated backend usage for this turn alone. Populated from any
378
- * `llm_call` stream events the backend emitted; `undefined` when the
379
- * backend reports no usage.
380
- */
381
- usage?: {
382
- tokensIn?: number;
383
- tokensOut?: number;
384
- costUsd?: number;
385
- latencyMs?: number;
386
- model?: string;
387
- };
388
- /**
389
- * Number of attempts that ran before this turn committed. `1` is the
390
- * common case; higher means the call policy retried after transient
391
- * failures.
392
- */
393
- attempts: number;
394
- startedAt: string;
395
- endedAt: string;
396
- }
397
- /** @stable */
398
- interface Conversation {
399
- participants: readonly ConversationParticipant[];
400
- policy: ConversationPolicy;
401
- }
402
- /** @stable */
403
- interface RunConversationOptions {
404
- /** First message kicking off the conversation. Routes to the first speaker. */
405
- seed: string;
406
- /**
407
- * Optional run identifier for cross-participant trace correlation. Auto-
408
- * generated when omitted. Reusing a runId against the same `journal`
409
- * resumes the prior run — the runner replays the persisted transcript and
410
- * continues from the first un-recorded turn.
411
- */
412
- runId?: string;
413
- /** Cancellation signal — aborts mid-stream and halts with `{ kind: 'abort' }`. */
414
- signal?: AbortSignal;
415
- /**
416
- * Event sink for per-turn micro-events. Distinct from the result transcript:
417
- * the sink fires for every text-delta, every turn-start/end, and the
418
- * conversation-start/end markers. Used to drive SSE / dashboard updates
419
- * without waiting for the conversation to finish.
420
- */
421
- onEvent?: (event: ConversationStreamEvent) => void | Promise<void>;
422
- /**
423
- * Optional durable transcript. When set, the runner persists every
424
- * committed turn before yielding `turn_end`. Reusing the same `runId`
425
- * against the same journal resumes from the last committed turn — so a
426
- * driver process crash mid-run loses zero acknowledged turns.
427
- */
428
- journal?: ConversationJournal;
429
- /**
430
- * Stores each participant's backend session. The runner keeps an in-memory
431
- * store for one invocation when omitted. Reuse a durable store with the same
432
- * `runId` and journal after a process restart. Backends implementing `resume`
433
- * continue their provider session; other backends receive the full transcript.
434
- */
435
- sessionStore?: RuntimeSessionStore;
436
- /**
437
- * Headers to forward verbatim to every participant backend call (gateway
438
- * propagation: `X-Tangle-Forwarded-Authorization`, run/turn correlation,
439
- * depth counter). Backends opt in by reading `propagatedHeaders` from
440
- * their `AgentBackendContext`; backends that ignore the field still work.
441
- */
442
- propagatedHeaders?: PropagatedHeaders;
443
- /**
444
- * Inbound depth at the point this driver was invoked. The runner
445
- * increments it on every outbound participant call; gateways refuse at
446
- * `DEFAULT_MAX_DEPTH`. Default 0 (origin caller).
447
- */
448
- inboundDepth?: number;
449
- /**
450
- * Parent turn id when this conversation is *inside* another turn (i.e. the
451
- * driver is itself a participant via `createConversationBackend`). The
452
- * runner stamps each outbound call with this as `X-Tangle-Parent-TurnId`
453
- * so trace stitching survives nested orchestration.
454
- */
455
- parentTurnId?: string;
456
- }
457
- /** @stable */
458
- interface ConversationResult {
459
- runId: string;
460
- transcript: ConversationTurn[];
461
- turns: number;
462
- spentCreditsCents: number;
463
- halted: HaltReason;
464
- durationMs: number;
465
- startedAt: string;
466
- endedAt: string;
467
- }
468
- /** @stable */
469
- type ConversationStreamEvent = {
470
- type: 'conversation_start';
471
- runId: string;
472
- participants: readonly string[];
473
- seed: string;
474
- timestamp: string;
475
- } | {
476
- type: 'conversation_resumed';
477
- runId: string;
478
- participants: readonly string[];
479
- transcript: readonly ConversationTurn[];
480
- timestamp: string;
481
- } | {
482
- type: 'turn_start';
483
- runId: string;
484
- index: number;
485
- speaker: string;
486
- turnId: string;
487
- attempt: number;
488
- timestamp: string;
489
- } | {
490
- type: 'turn_text_delta';
491
- runId: string;
492
- index: number;
493
- speaker: string;
494
- turnId: string;
495
- text: string;
496
- timestamp?: string;
497
- } | {
498
- type: 'turn_retry';
499
- runId: string;
500
- index: number;
501
- speaker: string;
502
- turnId: string;
503
- attempt: number;
504
- reason: string;
505
- timestamp: string;
506
- } | {
507
- type: 'turn_end';
508
- runId: string;
509
- turn: ConversationTurn;
510
- timestamp: string;
511
- } | {
512
- type: 'conversation_end';
513
- runId: string;
514
- result: ConversationResult;
515
- timestamp: string;
516
- };
517
-
518
- /**
519
- *
520
- * Wrap a `Conversation` so it satisfies `AgentExecutionBackend`. The result is
521
- * an addressable "single agent" whose internal behavior is an N-party
522
- * orchestrated conversation — the recursion primitive that lets a swarm be a
523
- * participant inside another swarm, or be published behind a single
524
- * agent-gateway endpoint.
525
- *
526
- * Stream events from inner participants are NOT forwarded verbatim. Outer
527
- * callers see one `text_delta` per inner turn (the turn's full text), tagged
528
- * with `[speaker] ` prefix so the outer transcript stays attributable. The
529
- * conversation's `conversation_end` halt reason rides on a `final` event.
530
- *
531
- * @stable
532
- */
533
-
534
- declare function createConversationBackend(options: {
535
- conversation: Conversation;
536
- /** Optional backend kind label. Defaults to `'conversation'`. */
537
- kind?: string;
538
- }): AgentExecutionBackend;
539
-
540
- /**
541
- *
542
- * Declarative constructor for a multi-agent `Conversation`. Validates inputs
543
- * fail-loud at definition time (duplicate participant names, alternate order
544
- * with ≠2 participants, non-positive `maxTurns`) so misconfiguration is caught
545
- * before `runConversation` is called and not buried inside a streaming run.
546
- *
547
- * @stable
548
- */
549
-
550
- declare function defineConversation(input: {
551
- participants: ConversationParticipant[];
552
- policy: ConversationPolicy;
553
- }): Conversation;
554
-
555
- /**
556
- *
557
- * Durable conversation journal backed by any SQL store. Adapter-agnostic by
558
- * design: callers wire a `SqlAdapter` against their driver of choice (D1,
559
- * postgres, sqlite, libSQL…) and the same journal implementation persists
560
- * conversation runs durably across process restarts. The schema is two
561
- * tables — runs (latest state) + events (append-only log) — so a partial
562
- * crash in the middle of a turn leaves an unambiguous "last committed turn"
563
- * to resume from.
564
- *
565
- * Why not bake in a specific driver? agent-runtime ships against multiple
566
- * runtimes (Cloudflare Workers, Node, Bun, Deno) and consumers' fleets have
567
- * already standardized on one of D1 / postgres / sqlite / libSQL. Adapter
568
- * indirection costs ~5 lines per driver in the consumer's code and keeps the
569
- * SDK free of native deps.
570
- *
571
- * @example D1 (Cloudflare Workers)
572
- * import { SqlConversationJournal, d1ToSqlAdapter } from '@tangle-network/agent-runtime'
573
- * const journal = new SqlConversationJournal(d1ToSqlAdapter(env.DB))
574
- * await journal.migrate() // once at deploy
575
- * await runConversation(conv, { seed, journal, runId: 'run_abc' })
576
- *
577
- * @example node-postgres
578
- * import { Pool } from 'pg'
579
- * const pool = new Pool({ connectionString: process.env.DATABASE_URL })
580
- * const pg: SqlAdapter = {
581
- * exec: async (sql, params = []) => {
582
- * const r = await pool.query(sql, params as never)
583
- * return { rowsAffected: r.rowCount ?? 0 }
584
- * },
585
- * query: async (sql, params = []) => (await pool.query(sql, params as never)).rows,
586
- * }
587
- * const journal = new SqlConversationJournal(pg)
588
- * await journal.migrate()
589
- *
590
- * @stable
591
- */
592
-
593
- /**
594
- * Minimal SQL driver shape. Implementations forward to whichever client the
595
- * deployment already uses; agent-runtime takes no opinion on which.
596
- *
597
- * Parameter placeholders MUST be `?` (positional). All adapters listed in the
598
- * file header accept this convention.
599
- */
600
- interface SqlAdapter {
601
- /** Execute a write statement (INSERT/UPDATE/DELETE/DDL). */
602
- exec(sql: string, params?: readonly unknown[]): Promise<{
603
- rowsAffected: number;
604
- }>;
605
- /** Execute a read statement (SELECT). Returns rows as plain objects. */
606
- query<TRow = Record<string, unknown>>(sql: string, params?: readonly unknown[]): Promise<TRow[]>;
607
- }
608
- /**
609
- * Adapt a Cloudflare D1 binding to the SqlAdapter shape. Lives here so D1
610
- * consumers don't have to write the wrapper themselves; the runtime never
611
- * imports `@cloudflare/workers-types` directly (peer-style typing).
612
- */
613
- declare function d1ToSqlAdapter(db: D1DatabaseLike): SqlAdapter;
614
- /**
615
- * Structural type matching the surface of `D1Database` we depend on, so the
616
- * SDK never imports `@cloudflare/workers-types`. Consumers pass their real
617
- * `D1Database` from `env.DB` and TS structural compatibility lines it up.
618
- */
619
- interface D1DatabaseLike {
620
- prepare(sql: string): D1StmtLike;
621
- }
622
- interface D1StmtLike {
623
- bind(...params: unknown[]): D1StmtLike;
624
- run(): Promise<unknown>;
625
- all<TRow = unknown>(): Promise<{
626
- results?: TRow[];
627
- }>;
628
- }
629
- /**
630
- * SQL-backed ConversationJournal. Two tables — runs (one row per runId, holds
631
- * start/halt timestamps + halt reason) and turns (one row per committed turn,
632
- * payload is the ConversationTurn JSON). Replays the turns table on
633
- * `loadRun` and writes append-only per `appendTurn`.
634
- */
635
- declare class SqlConversationJournal implements ConversationJournal {
636
- private readonly db;
637
- private readonly table;
638
- /**
639
- * @param db SQL adapter (D1, postgres, sqlite, libSQL — all work)
640
- * @param table Table-name prefix; the journal creates `${table}_runs` and
641
- * `${table}_turns`. Lets multiple journals share a database
642
- * without colliding (e.g. one per product surface).
643
- */
644
- constructor(db: SqlAdapter, table?: string);
645
- /**
646
- * Create the journal's tables if absent. Idempotent. Call once at deploy
647
- * (or at app boot) — running on every request is harmless but adds latency.
648
- */
649
- migrate(): Promise<void>;
650
- loadRun(runId: string): Promise<ConversationJournalEntry | undefined>;
651
- beginRun(runId: string, startedAt: string): Promise<void>;
652
- appendTurn(runId: string, turn: ConversationTurn): Promise<void>;
653
- recordHalt(runId: string, halt: HaltReason, endedAt: string): Promise<void>;
654
- }
655
-
656
- /**
657
- *
658
- * Conversation orchestrator. Drives N participants in turn through their own
659
- * `AgentExecutionBackend`s, aggregating per-turn text + usage, enforcing
660
- * `maxTurns` / `maxCreditsCents` / `haltOn`, and emitting per-event stream
661
- * markers so callers can plumb the run through SSE without buffering.
662
- *
663
- * `runConversation` returns the full result; `runConversationStream` returns
664
- * an `AsyncIterable<ConversationStreamEvent>` for callers that want to
665
- * forward events as they arrive. Both share one driving loop.
666
- *
667
- * Distributed-systems primitives layered on top of the loop:
668
- * - **Participant sessions**: one backend session per participant is resumed
669
- * between turns; stateless backends receive one reconstructed transcript.
670
- * - **Idempotent turn ids** — `turnId(runId, index, speaker)` stays stable
671
- * across retries so caching gateways can dedupe.
672
- * - **Durable journal** — optional `ConversationJournal` persists every
673
- * committed turn; reusing a runId against the same journal resumes
674
- * transparently from the last committed turn.
675
- * - **Per-turn call policy** — deadline, retry-with-backoff, and a
676
- * per-participant circuit breaker. Retries replay the same logical turn
677
- * (same `turnId`); the retry loop lives inside the outer generator so
678
- * deltas yield naturally without cross-coroutine buffering.
679
- * - **Header propagation** — run/turn/depth headers (+ forwarded user
680
- * authorization) stamped onto every outbound backend call so downstream
681
- * gateways can bill the right user and enforce `X-Tangle-Forwarded-Depth`.
682
- *
683
- * Credit cap is enforced *between turns*, not mid-stream: a turn that
684
- * overshoots the cap completes, the cap then halts the conversation before
685
- * the next turn.
686
- *
687
- * @stable
688
- */
689
-
690
- declare function runConversation(conversation: Conversation, options: RunConversationOptions): Promise<ConversationResult>;
691
- /** Streaming conversation orchestrator: drives N participants in turn through their own backends, enforcing `maxTurns` / `maxCreditsCents` / `haltOn`, yielding per-event stream markers. */
692
- declare function runConversationStream(conversation: Conversation, options: RunConversationOptions): AsyncIterable<ConversationStreamEvent>;
693
-
694
- /**
695
- * `runPersonaConversation` — the persona loop runner: run a WORKER `AgentProfile`
696
- * (the agent under test) as a multi-round conversation driven by a PERSONA (the
697
- * simulated user), over the persistent conversation transcript.
698
- *
699
- * It is profiles-vs-profiles: the persona is itself a driver `AgentProfile` (an
700
- * LLM role-playing the user from its facts) — `runConversation` runs the two
701
- * against each other. Scripted persona turns are kept as a deterministic
702
- * fast-path. Only the WORKER is metered (it is the side under test); the
703
- * persona-driver is the test harness, not billed against the agent.
704
- *
705
- * `runPersonaDispatch` wraps the runner as a `ProfileDispatchFn` so it drops
706
- * straight into `runProfileMatrix({ dispatch })` — the same loop serves a single
707
- * cell and the whole matrix, replacing the per-agent hand-rolled
708
- * `dispatchWithSurface` bridges.
709
- */
710
-
711
- /** A persona that drives the conversation: either a full driver `AgentProfile`
712
- * (an LLM user-sim) or a deterministic script of user turns (the fast-path). */
713
- type PersonaDriver = {
714
- kind: 'profile';
715
- profile: AgentProfile;
716
- } | {
717
- kind: 'scripted';
718
- turns: string[];
719
- };
720
- interface RunPersonaConversationOptions {
721
- /** The agent under test. Metered; its rendered prompt leads its turns. */
722
- worker: AgentProfile;
723
- /** The simulated user driving the dialogue. */
724
- persona: PersonaDriver;
725
- /** Turn an `AgentProfile` into a runnable backend (router / sandbox / fake).
726
- * Applied to the worker and to a `profile`-kind persona. */
727
- backendFor: (profile: AgentProfile, role: 'worker' | 'persona') => AgentExecutionBackend;
728
- /** Render a profile's system prompt — prepended to that profile's messages. */
729
- systemPromptOf: (profile: AgentProfile) => string;
730
- /** Speaker-turn cap. Default for a scripted persona = `2 * turns.length`
731
- * (worker answers each user turn). REQUIRED for a `profile` persona. */
732
- maxTurns?: number;
733
- /** Kickoff message routed to the first speaker (the persona). Default 'Begin.' */
734
- seed?: string;
735
- /** Content-based "until satisfied" halt, called after every turn. `maxTurns` is the
736
- * hard ceiling; this is the early stop (the persona declares the goal met / unreachable). */
737
- haltOn?: HaltPredicate;
738
- signal?: AbortSignal;
739
- /** Worker participant / transcript speaker label. Default 'agent'. */
740
- workerName?: string;
741
- }
742
- interface PersonaConversationResult {
743
- transcript: ConversationTurn[];
744
- turns: number;
745
- halted: HaltReason;
746
- /** Worker-only spend (the side under test). */
747
- costUsd: number;
748
- tokensIn: number;
749
- tokensOut: number;
750
- }
751
- /**
752
- * Run one worker profile against one persona as a multi-round conversation.
753
- * The persona leads (participant 0): it speaks, the worker answers, repeat,
754
- * until `maxTurns`. Returns the persistent transcript + worker-only usage.
755
- */
756
- declare function runPersonaConversation(opts: RunPersonaConversationOptions): Promise<PersonaConversationResult>;
757
- interface RunPersonaConfig<TScenario extends Scenario, TArtifact> {
758
- /** Turn an `AgentProfile` into a runnable backend (router / sandbox / fake). */
759
- backendFor: (profile: AgentProfile, role: 'worker' | 'persona') => AgentExecutionBackend;
760
- /** Render a profile's system prompt. */
761
- systemPromptOf: (profile: AgentProfile) => string;
762
- /** The persona driving each scenario — a driver profile or scripted turns. */
763
- personaOf: (scenario: TScenario) => PersonaDriver;
764
- /** Build the scored artifact from the finished transcript. */
765
- artifactOf: (transcript: ConversationTurn[], scenario: TScenario) => TArtifact;
766
- /** Speaker-turn cap (required when a persona is profile-driven). */
767
- maxTurns?: (scenario: TScenario) => number;
768
- seed?: (scenario: TScenario) => string;
769
- workerName?: string;
770
- /** Provider- or executor-enforced maximum for the whole worker conversation.
771
- * Required before execution when the enclosing campaign is cost-capped. */
772
- maximumCharge?: MaximumCharge | ((worker: AgentProfile, scenario: TScenario) => MaximumCharge | undefined);
773
- }
774
- /**
775
- * Wrap {@link runPersonaConversation} as a `ProfileDispatchFn` for
776
- * `runProfileMatrix`: the profile axis is the worker-under-test, the scenario
777
- * axis is the persona, and the runner is the cell. Meters the worker through
778
- * `ctx.cost` so the matrix's backend-integrity guard sees real usage.
779
- */
780
- declare function runPersonaDispatch<TScenario extends Scenario, TArtifact>(config: RunPersonaConfig<TScenario, TArtifact>): ProfileDispatchFn<TScenario, TArtifact>;
781
-
782
- /**
783
- *
784
- * Deterministic turn identifier. Stable across retries of the same logical
785
- * turn so backends (and any caching gateway in between) can dedupe on it.
786
- * A retry triggered by a network blip or deadline timeout MUST produce the
787
- * same `turn_id`; only the underlying attempt count differs.
788
- *
789
- * Shape: `${runId}.t${index}.${speakerSlug}` — readable in logs, sortable by
790
- * turn index, attributable to a speaker. Slugify keeps the speaker portion
791
- * URL-safe so it can ride in HTTP headers without escaping.
792
- *
793
- * @stable
794
- */
795
- declare function turnId(runId: string, index: number, speaker: string): string;
796
- /**
797
- * Reduce a speaker name to ASCII alphanumerics + dashes. Preserves enough
798
- * substance to read in a log line; collisions between speakers within a
799
- * single Conversation are prevented by `defineConversation`'s
800
- * unique-name check, so the slug only needs to be deterministic, not unique.
801
- */
802
- declare function slugifySpeaker(speaker: string): string;
803
-
804
- export { type AuthSource, type BackendCallPolicy, type CircuitBreakerConfig, CircuitBreakerState, CircuitOpenError, type Conversation, type ConversationDriveState, type ConversationJournal, type ConversationJournalEntry, type ConversationParticipant, type ConversationPolicy, type ConversationResult, type ConversationStreamEvent, type ConversationTurn, type D1DatabaseLike, type D1StmtLike, DEFAULT_MAX_DEPTH, DeadlineExceededError, FORWARD_HEADERS, FileConversationJournal, type ForwardHeaderName, type HaltContext, type HaltPredicate, type HaltReason, type HaltSignal, InMemoryConversationJournal, type PersonaConversationResult, type PersonaDriver, type PropagatedHeaders, type RetryBackoff, type RetryableErrorPredicate, type RunConversationOptions, type RunPersonaConfig, type RunPersonaConversationOptions, type SqlAdapter, SqlConversationJournal, type TurnOrder, buildForwardHeaders, computeBackoff, createConversationBackend, d1ToSqlAdapter, defaultIsRetryable, defineConversation, isDepthExceeded, makePerAttemptSignal, readDepth, runConversation, runConversationStream, runPersonaConversation, runPersonaDispatch, sleep, slugifySpeaker, turnId };
1
+ import { $ as sleep, A as RunConversationOptions, B as buildForwardHeaders, C as ConversationResult, D as HaltPredicate, E as HaltContext, F as InMemoryConversationJournal, G as CircuitBreakerState, H as readDepth, I as DEFAULT_MAX_DEPTH, J as RetryBackoff, K as CircuitOpenError, L as FORWARD_HEADERS, M as ConversationJournal, N as ConversationJournalEntry, O as HaltReason, P as FileConversationJournal, Q as makePerAttemptSignal, R as ForwardHeaderName, S as ConversationPolicy, T as ConversationTurn, U as BackendCallPolicy, V as isDepthExceeded, W as CircuitBreakerConfig, X as computeBackoff, Y as RetryableErrorPredicate, Z as defaultIsRetryable, _ as createConversationBackend, a as RunPersonaConfig, b as ConversationDriveState, c as runPersonaDispatch, d as D1DatabaseLike, f as D1StmtLike, g as defineConversation, h as d1ToSqlAdapter, i as PersonaDriver, j as TurnOrder, k as HaltSignal, l as runConversation, m as SqlConversationJournal, n as turnId, o as RunPersonaConversationOptions, p as SqlAdapter, q as DeadlineExceededError, r as PersonaConversationResult, s as runPersonaConversation, t as slugifySpeaker, u as runConversationStream, v as AuthSource, w as ConversationStreamEvent, x as ConversationParticipant, y as Conversation, z as PropagatedHeaders } from "./index-Efjb3nrQ.js";
2
+ export { type AuthSource, type BackendCallPolicy, type CircuitBreakerConfig, CircuitBreakerState, CircuitOpenError, type Conversation, type ConversationDriveState, type ConversationJournal, type ConversationJournalEntry, type ConversationParticipant, type ConversationPolicy, type ConversationResult, type ConversationStreamEvent, type ConversationTurn, type D1DatabaseLike, type D1StmtLike, DEFAULT_MAX_DEPTH, DeadlineExceededError, FORWARD_HEADERS, FileConversationJournal, type ForwardHeaderName, type HaltContext, type HaltPredicate, type HaltReason, type HaltSignal, InMemoryConversationJournal, type PersonaConversationResult, type PersonaDriver, type PropagatedHeaders, type RetryBackoff, type RetryableErrorPredicate, type RunConversationOptions, type RunPersonaConfig, type RunPersonaConversationOptions, type SqlAdapter, SqlConversationJournal, type TurnOrder, buildForwardHeaders, computeBackoff, createConversationBackend, d1ToSqlAdapter, defaultIsRetryable, defineConversation, isDepthExceeded, makePerAttemptSignal, readDepth, runConversation, runConversationStream, runPersonaConversation, runPersonaDispatch, sleep, slugifySpeaker, turnId };