@tangle-network/agent-eval 0.117.0 → 0.118.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 (143) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/dist/analyst/index.d.ts +2772 -21
  3. package/dist/analyst/index.js +7 -6
  4. package/dist/analyst/index.js.map +1 -1
  5. package/dist/belief-state/index.d.ts +706 -10
  6. package/dist/belief-state/index.js +2 -1
  7. package/dist/belief-state/index.js.map +1 -1
  8. package/dist/benchmarks/index.d.ts +958 -14
  9. package/dist/benchmarks/index.js +12 -10
  10. package/dist/builder-eval/index.d.ts +449 -4
  11. package/dist/builder-eval/index.js +4 -3
  12. package/dist/builder-eval/index.js.map +1 -1
  13. package/dist/campaign/index.d.ts +4276 -74
  14. package/dist/campaign/index.js +12 -10
  15. package/dist/{chunk-VF3XSYTI.js → chunk-33JA4TFA.js} +6 -6
  16. package/dist/{chunk-4JLWXDYA.js → chunk-3EHHMC6E.js} +2 -2
  17. package/dist/{chunk-CCZIVI3F.js → chunk-BFW56GTT.js} +2 -2
  18. package/dist/{chunk-YZPO4UHR.js → chunk-DP3BBMYJ.js} +100 -143
  19. package/dist/chunk-DP3BBMYJ.js.map +1 -0
  20. package/dist/{chunk-E4BUPP7Z.js → chunk-HKUCJ437.js} +38 -66
  21. package/dist/chunk-HKUCJ437.js.map +1 -0
  22. package/dist/{chunk-HZHNRYHK.js → chunk-K6N6XJJX.js} +2 -2
  23. package/dist/chunk-KSDQVPLR.js +286 -0
  24. package/dist/chunk-KSDQVPLR.js.map +1 -0
  25. package/dist/chunk-MA6HLL3S.js +65 -0
  26. package/dist/chunk-MA6HLL3S.js.map +1 -0
  27. package/dist/{chunk-MGEHEHSN.js → chunk-OIIMMLRB.js} +11 -11
  28. package/dist/{chunk-DXZRATT5.js → chunk-OYZAPX5G.js} +3 -3
  29. package/dist/chunk-PXE2VKMX.js +140 -0
  30. package/dist/chunk-PXE2VKMX.js.map +1 -0
  31. package/dist/{chunk-ZUXV7UWZ.js → chunk-Q442S5AS.js} +73 -19
  32. package/dist/{chunk-ZUXV7UWZ.js.map → chunk-Q442S5AS.js.map} +1 -1
  33. package/dist/{chunk-ODVOOEWQ.js → chunk-QBRSJK47.js} +2 -2
  34. package/dist/{chunk-S2F4J57L.js → chunk-QKEGNI5B.js} +77 -32
  35. package/dist/chunk-QKEGNI5B.js.map +1 -0
  36. package/dist/{chunk-5UF54T55.js → chunk-S3UZOQ5Y.js} +34 -7
  37. package/dist/chunk-S3UZOQ5Y.js.map +1 -0
  38. package/dist/{chunk-FQNLDL4D.js → chunk-SVH2ANFD.js} +136 -4
  39. package/dist/chunk-SVH2ANFD.js.map +1 -0
  40. package/dist/{chunk-GQCZRZ7L.js → chunk-U5CHZ5M3.js} +9 -9
  41. package/dist/{chunk-TVVP3ZZQ.js → chunk-VQMK5FMP.js} +2 -1
  42. package/dist/{chunk-TVVP3ZZQ.js.map → chunk-VQMK5FMP.js.map} +1 -1
  43. package/dist/chunk-WDHBCA3M.js +31 -0
  44. package/dist/chunk-WDHBCA3M.js.map +1 -0
  45. package/dist/{chunk-HQPHZGL6.js → chunk-YLMUS4MM.js} +9 -9
  46. package/dist/{chunk-LQUTGLOZ.js → chunk-ZET2UAYW.js} +15 -65
  47. package/dist/chunk-ZET2UAYW.js.map +1 -0
  48. package/dist/contract/index.d.ts +4012 -38
  49. package/dist/contract/index.js +56 -29
  50. package/dist/contract/index.js.map +1 -1
  51. package/dist/control.d.ts +1013 -9
  52. package/dist/control.js +4 -3
  53. package/dist/fuzz.d.ts +194 -4
  54. package/dist/fuzz.js +3 -3
  55. package/dist/hosted/index.d.ts +498 -17
  56. package/dist/index.d.ts +10982 -1286
  57. package/dist/index.js +97 -80
  58. package/dist/index.js.map +1 -1
  59. package/dist/matrix/index.d.ts +139 -4
  60. package/dist/meta-eval/index.d.ts +862 -15
  61. package/dist/meta-eval/index.js +2 -1
  62. package/dist/meta-eval/index.js.map +1 -1
  63. package/dist/multishot/index.d.ts +214 -14
  64. package/dist/openapi.json +1 -1
  65. package/dist/pipelines/index.d.ts +392 -7
  66. package/dist/pipelines/index.js +5 -3
  67. package/dist/pipelines/index.js.map +1 -1
  68. package/dist/reporting.d.ts +1277 -17
  69. package/dist/rl.d.ts +2359 -28
  70. package/dist/rl.js +6 -5
  71. package/dist/rl.js.map +1 -1
  72. package/dist/storyboard/index.d.ts +86 -1
  73. package/dist/trace-attributes.d.ts +16 -0
  74. package/dist/trace-attributes.js +32 -0
  75. package/dist/trace-attributes.js.map +1 -0
  76. package/dist/traces.d.ts +1970 -697
  77. package/dist/traces.js +49 -32
  78. package/dist/wire/index.d.ts +655 -9
  79. package/docs/insight-report.md +44 -0
  80. package/package.json +9 -3
  81. package/dist/adversarial-B7loGVVX.d.ts +0 -19
  82. package/dist/analyst-C8HHvfJp.d.ts +0 -88
  83. package/dist/analyze-runs--2x39HZ7.d.ts +0 -81
  84. package/dist/baseline-DKq3gJpP.d.ts +0 -141
  85. package/dist/calibration-C8MTS7cw.d.ts +0 -101
  86. package/dist/chunk-5UF54T55.js.map +0 -1
  87. package/dist/chunk-E4BUPP7Z.js.map +0 -1
  88. package/dist/chunk-FQNLDL4D.js.map +0 -1
  89. package/dist/chunk-LQUTGLOZ.js.map +0 -1
  90. package/dist/chunk-S2F4J57L.js.map +0 -1
  91. package/dist/chunk-YZPO4UHR.js.map +0 -1
  92. package/dist/code-agent-session-CjZsVd19.d.ts +0 -87
  93. package/dist/control-6vuGfmDH.d.ts +0 -258
  94. package/dist/cost-ledger-DWy3XdJc.d.ts +0 -183
  95. package/dist/dataset-NENEzRgk.d.ts +0 -115
  96. package/dist/default-registry-DaK8b3fv.d.ts +0 -155
  97. package/dist/emitter-CjD7vUwv.d.ts +0 -122
  98. package/dist/errors-oeQrLqXC.d.ts +0 -74
  99. package/dist/failure-cluster-DOAcSJ87.d.ts +0 -76
  100. package/dist/feedback-trajectory-BUnM58xL.d.ts +0 -348
  101. package/dist/gepa-eESocoDi.d.ts +0 -642
  102. package/dist/index-PdX4VnPA.d.ts +0 -423
  103. package/dist/insight-report-DY4nDW9Q.d.ts +0 -310
  104. package/dist/integrity-DqlBiLyK.d.ts +0 -81
  105. package/dist/judge-calibration-7C-IDmKr.d.ts +0 -145
  106. package/dist/kind-factory-ClZmO25A.d.ts +0 -171
  107. package/dist/llm-client-qoDd18Qz.d.ts +0 -289
  108. package/dist/multi-layer-verifier-BsqKuLyN.d.ts +0 -150
  109. package/dist/off-policy-DiwuKKg7.d.ts +0 -132
  110. package/dist/outcome-store-rnXLEqSn.d.ts +0 -63
  111. package/dist/policy-edit-wG9uFEFm.d.ts +0 -455
  112. package/dist/pre-registration-BWQhJ3vz.d.ts +0 -761
  113. package/dist/provenance-DpjwyseI.d.ts +0 -541
  114. package/dist/query-CF7PG61p.d.ts +0 -35
  115. package/dist/raw-provider-sink-C46HDghv.d.ts +0 -132
  116. package/dist/release-report-C8G2i5Xi.d.ts +0 -236
  117. package/dist/researcher-C8XyxQsu.d.ts +0 -387
  118. package/dist/rubric-predictive-validity-p49lLVrE.d.ts +0 -105
  119. package/dist/run-record-BDH49H2E.d.ts +0 -360
  120. package/dist/runtime-trajectory-DGBIUt4B.d.ts +0 -49
  121. package/dist/schema-B3Q3l9Z_.d.ts +0 -201
  122. package/dist/semantic-concept-judge-CXnPEJbf.d.ts +0 -723
  123. package/dist/sequential-5iSVfzl2.d.ts +0 -139
  124. package/dist/series-convergence-D5OWMBg6.d.ts +0 -33
  125. package/dist/statistics-KUnG73jH.d.ts +0 -494
  126. package/dist/storage-DrX3v_5B.d.ts +0 -50
  127. package/dist/store-C1YxJDEK.d.ts +0 -248
  128. package/dist/store-DGqD0Pyo.d.ts +0 -116
  129. package/dist/summary-report-C5bKFfm-.d.ts +0 -445
  130. package/dist/test-graded-scenario-B0ybnPY7.d.ts +0 -166
  131. package/dist/types-BSw1rOUB.d.ts +0 -634
  132. package/dist/types-BUxNaJ8c.d.ts +0 -108
  133. package/dist/types-BkfcQnxV.d.ts +0 -313
  134. package/dist/verdict-C9MlYujm.d.ts +0 -35
  135. /package/dist/{chunk-VF3XSYTI.js.map → chunk-33JA4TFA.js.map} +0 -0
  136. /package/dist/{chunk-4JLWXDYA.js.map → chunk-3EHHMC6E.js.map} +0 -0
  137. /package/dist/{chunk-CCZIVI3F.js.map → chunk-BFW56GTT.js.map} +0 -0
  138. /package/dist/{chunk-HZHNRYHK.js.map → chunk-K6N6XJJX.js.map} +0 -0
  139. /package/dist/{chunk-MGEHEHSN.js.map → chunk-OIIMMLRB.js.map} +0 -0
  140. /package/dist/{chunk-DXZRATT5.js.map → chunk-OYZAPX5G.js.map} +0 -0
  141. /package/dist/{chunk-ODVOOEWQ.js.map → chunk-QBRSJK47.js.map} +0 -0
  142. /package/dist/{chunk-GQCZRZ7L.js.map → chunk-U5CHZ5M3.js.map} +0 -0
  143. /package/dist/{chunk-HQPHZGL6.js.map → chunk-YLMUS4MM.js.map} +0 -0
@@ -1,17 +1,663 @@
1
- import { C as CostLedger } from '../cost-ledger-DWy3XdJc.js';
2
- import { F as FeedbackTrajectoryStore } from '../feedback-trajectory-BUnM58xL.js';
3
- import { a as LlmClientOptions } from '../llm-client-qoDd18Qz.js';
4
- import { T as TraceStore } from '../store-DGqD0Pyo.js';
5
1
  import { z } from 'zod';
6
2
  import { OpenAPIObject } from 'openapi3-ts/oas31';
7
3
  import * as hono_types from 'hono/types';
8
4
  import { ServerType } from '@hono/node-server';
9
5
  import { Hono } from 'hono';
10
- import '../errors-oeQrLqXC.js';
11
- import '../emitter-CjD7vUwv.js';
12
- import '../schema-B3Q3l9Z_.js';
13
- import '../dataset-NENEzRgk.js';
14
- import '../raw-provider-sink-C46HDghv.js';
6
+
7
+ type CostChannel = 'agent' | 'judge' | 'verifier' | 'analyst' | 'driver' | (string & {});
8
+ interface CostUsage {
9
+ inputTokens: number;
10
+ outputTokens: number;
11
+ cachedTokens?: number;
12
+ }
13
+ interface CostCallBase {
14
+ callId: string;
15
+ channel: CostChannel;
16
+ phase: string;
17
+ actor: string;
18
+ model: string;
19
+ maximumCostUsd?: number;
20
+ tags?: Record<string, string>;
21
+ timestamp: number;
22
+ }
23
+ interface CostReceipt extends CostCallBase, CostUsage {
24
+ status: 'settled';
25
+ costUsd: number;
26
+ costUnknown: boolean;
27
+ usageUnknown?: boolean;
28
+ pricing?: {
29
+ inputUsdPerThousand: number;
30
+ outputUsdPerThousand: number;
31
+ };
32
+ actualCostUsd?: number;
33
+ error?: string;
34
+ }
35
+ interface CostReceiptInput extends CostUsage {
36
+ model: string;
37
+ actualCostUsd?: number;
38
+ costUnknown?: boolean;
39
+ usageUnknown?: boolean;
40
+ }
41
+ type MaximumCharge = {
42
+ externallyEnforcedMaximumUsd: number;
43
+ } | ({
44
+ model: string;
45
+ } & CostUsage);
46
+ interface RunPaidCallInput<T> {
47
+ callId?: string;
48
+ channel: CostChannel;
49
+ phase: string;
50
+ actor: string;
51
+ /** Used before a provider receipt exists and on failures without one. */
52
+ model?: string;
53
+ tags?: Record<string, string>;
54
+ signal?: AbortSignal;
55
+ /** Provider-enforced dollar maximum, or maximum priced token usage. Required when capped. */
56
+ maximumCharge?: MaximumCharge;
57
+ /** `callId` can be forwarded as the provider's idempotency key. */
58
+ execute(signal: AbortSignal, callId: string): Promise<T>;
59
+ receipt(value: T): CostReceiptInput;
60
+ receiptFromError?(error: Error): CostReceiptInput | undefined;
61
+ }
62
+ type PaidCallResult<T> = {
63
+ succeeded: true;
64
+ callId: string;
65
+ value: T;
66
+ receipt: CostReceipt;
67
+ } | {
68
+ succeeded: false;
69
+ callId?: string;
70
+ error: Error;
71
+ receipt?: CostReceipt;
72
+ };
73
+ interface ChannelRollup {
74
+ channel: CostChannel;
75
+ calls: number;
76
+ inputTokens: number;
77
+ outputTokens: number;
78
+ cachedTokens: number;
79
+ costUsd: number;
80
+ unpricedCalls: number;
81
+ unknownUsageCalls: number;
82
+ }
83
+ interface CostLedgerSummary {
84
+ totalCalls: number;
85
+ pendingCalls: number;
86
+ unresolvedCalls: number;
87
+ reservedCostUsd: number;
88
+ inputTokens: number;
89
+ outputTokens: number;
90
+ cachedTokens: number;
91
+ totalCostUsd: number;
92
+ byChannel: ChannelRollup[];
93
+ unpricedModels: string[];
94
+ fullyPriced: boolean;
95
+ usageComplete: boolean;
96
+ accountingComplete: boolean;
97
+ incompleteReasons: string[];
98
+ }
99
+ interface CostLedgerFilter {
100
+ channel?: CostChannel;
101
+ phase?: string;
102
+ tags?: Record<string, string>;
103
+ }
104
+ /** Append-only storage. `append` must atomically reject stale revisions. */
105
+ interface CostLedgerPersistence {
106
+ read(): {
107
+ revision: string;
108
+ events: string;
109
+ };
110
+ append(expectedRevision: string, event: string): string | undefined;
111
+ }
112
+ interface CostLedgerOptions {
113
+ costCeilingUsd?: number;
114
+ persistence?: CostLedgerPersistence;
115
+ /** Import already-settled receipts without admitting new paid work. */
116
+ receipts?: readonly CostReceipt[];
117
+ }
118
+ /** Run-wide paid-call admission, durable call state, receipts, and summaries. */
119
+ declare class CostLedger {
120
+ private readonly records;
121
+ private readonly activeCallIds;
122
+ private readonly lateCallIds;
123
+ private completedTasks;
124
+ private revision;
125
+ private costLimitPersisted;
126
+ readonly costCeilingUsd?: number;
127
+ private readonly persistence?;
128
+ constructor(input?: number | CostLedgerOptions);
129
+ runPaidCall<T>(input: RunPaidCallInput<T>): Promise<PaidCallResult<T>>;
130
+ /** Settle a call left pending by a crashed process after reconciling with the provider. */
131
+ reconcile(callId: string, observed: CostReceiptInput, options?: {
132
+ error?: string;
133
+ }): CostReceipt;
134
+ list(filter?: CostLedgerFilter): CostReceipt[];
135
+ summary(filter?: CostLedgerFilter): CostLedgerSummary;
136
+ markCompleted(count?: number): void;
137
+ costPerCompletedTask(): number | null;
138
+ private execute;
139
+ private captureLateOutcome;
140
+ private commitOutcome;
141
+ private captureFailure;
142
+ private commitReceipt;
143
+ private resolveMaximum;
144
+ private hasIncompleteSettledCall;
145
+ private appendRecord;
146
+ private ensureCostLimitPersisted;
147
+ private appendEvent;
148
+ }
149
+
150
+ type RunStatus = 'running' | 'completed' | 'failed' | 'aborted';
151
+ interface BudgetSpec {
152
+ tokens?: number;
153
+ wallMs?: number;
154
+ calls?: number;
155
+ usd?: number;
156
+ }
157
+ interface RunOutcome {
158
+ score?: number;
159
+ pass?: boolean;
160
+ failureClass?: FailureClass;
161
+ notes?: string;
162
+ }
163
+ /**
164
+ * Layer — optional classification in a nested build workflow.
165
+ * `builder`: the meta-agent editing a project (e.g. agent-builder Forge chat).
166
+ * `app-build`: sandbox harness that compiled + tested the generated scaffold.
167
+ * `app-runtime`: a run of the generated agent against a domain scenario.
168
+ * `meta`: any meta-eval (judge replay, correlation analysis).
169
+ */
170
+ type RunLayer = 'builder' | 'app-build' | 'app-runtime' | 'meta' | 'custom';
171
+ interface Run {
172
+ runId: string;
173
+ /**
174
+ * Stable identifier of the scenario being executed.
175
+ *
176
+ * Always populated on the persisted Run — but `TraceEmitter.startRun` accepts
177
+ * input WITHOUT this field, substituting a sensible default
178
+ * (`run.layer ?? run.tags?.['kind'] ?? 'runtime'`) when the caller has no
179
+ * curated scenario to anchor to (runtime / operator / meta-eval runs). This
180
+ * keeps the persisted shape unambiguous for downstream filters + aggregations
181
+ * while removing the boilerplate of inventing placeholder ids at the call site.
182
+ */
183
+ scenarioId: string;
184
+ variantId?: string;
185
+ datasetVersion?: string;
186
+ /** Git SHA of agent code at run time. */
187
+ codeSha?: string;
188
+ /** Hash of the prompt template + any system prompt. */
189
+ promptSha?: string;
190
+ /** Model id + date + system-prompt hash, concatenated. */
191
+ modelFingerprint?: string;
192
+ seed?: number;
193
+ /** Arbitrary environment markers (shell, docker version, tz). */
194
+ envFingerprint?: Record<string, string>;
195
+ /** Version of the redaction rules applied to this run. */
196
+ redactionVersion?: string;
197
+ /** Parent run in a nested build workflow. A builder run's children are
198
+ * app-build runs; those children are app-runtime runs. */
199
+ parentRunId?: string;
200
+ /** Stable project identifier — groups runs across chats + sessions. */
201
+ projectId?: string;
202
+ /** Chat/conversation identifier within a project. */
203
+ chatId?: string;
204
+ /** Layer classification — hint for aggregation; not enforced. */
205
+ layer?: RunLayer;
206
+ startedAt: number;
207
+ endedAt?: number;
208
+ status: RunStatus;
209
+ outcome?: RunOutcome;
210
+ budget?: BudgetSpec;
211
+ /** Free-form labels for downstream grouping. */
212
+ tags?: Record<string, string>;
213
+ }
214
+ type SpanKind = 'agent' | 'llm' | 'tool' | 'retrieval' | 'judge' | 'sandbox' | 'custom';
215
+ type SpanStatus = 'ok' | 'error';
216
+ interface SpanBase {
217
+ spanId: string;
218
+ parentSpanId?: string;
219
+ runId: string;
220
+ kind: SpanKind;
221
+ name: string;
222
+ startedAt: number;
223
+ endedAt?: number;
224
+ status?: SpanStatus;
225
+ error?: string;
226
+ /** Anything not covered by typed fields. Kept deliberately free-form. */
227
+ attributes?: Record<string, unknown>;
228
+ }
229
+ interface Message {
230
+ role: 'system' | 'user' | 'assistant' | 'tool';
231
+ content: string;
232
+ tokens?: number;
233
+ /** Multi-modal content descriptors; blobs themselves live in Artifacts. */
234
+ images?: Array<{
235
+ artifactId?: string;
236
+ url?: string;
237
+ mime?: string;
238
+ }>;
239
+ }
240
+ interface LlmSpan extends SpanBase {
241
+ kind: 'llm';
242
+ model: string;
243
+ messages: Message[];
244
+ output?: string;
245
+ inputTokens?: number;
246
+ /** All generated tokens, including the reasoning subset when present. */
247
+ outputTokens?: number;
248
+ cachedTokens?: number;
249
+ cacheWriteTokens?: number;
250
+ /** Reasoning-token subset of `outputTokens`. */
251
+ reasoningTokens?: number;
252
+ costUsd?: number;
253
+ finishReason?: string;
254
+ }
255
+ interface ToolSpan extends SpanBase {
256
+ kind: 'tool';
257
+ toolName: string;
258
+ args: unknown;
259
+ /** False when the source observed the call but did not capture its arguments. */
260
+ argsCaptured?: boolean;
261
+ result?: unknown;
262
+ latencyMs?: number;
263
+ }
264
+ interface RetrievalSpan extends SpanBase {
265
+ kind: 'retrieval';
266
+ query: string;
267
+ hits: Array<{
268
+ docId: string;
269
+ score: number;
270
+ content?: string;
271
+ }>;
272
+ }
273
+ interface JudgeSpan extends SpanBase {
274
+ kind: 'judge';
275
+ judgeId: string;
276
+ /** Span this judgment applies to. */
277
+ targetSpanId: string;
278
+ dimension: string;
279
+ /** Numeric score (free-range; interpretation up to the judge). */
280
+ score: number;
281
+ rationale?: string;
282
+ evidence?: string;
283
+ }
284
+ interface SandboxSpan extends SpanBase {
285
+ kind: 'sandbox';
286
+ image?: string;
287
+ command?: string;
288
+ exitCode?: number;
289
+ testsTotal?: number;
290
+ testsPassed?: number;
291
+ stdoutHash?: string;
292
+ stderrHash?: string;
293
+ /** Duration in ms; the harness fills this explicitly (endedAt - startedAt may miss setup). */
294
+ wallMs?: number;
295
+ }
296
+ interface GenericSpan extends SpanBase {
297
+ kind: 'agent' | 'custom';
298
+ }
299
+ type Span = LlmSpan | ToolSpan | RetrievalSpan | JudgeSpan | SandboxSpan | GenericSpan;
300
+ type EventKind = 'log' | 'error' | 'budget_decrement' | 'budget_breach' | 'state_mutation' | 'policy_violation' | 'redaction_applied' | 'custom';
301
+ interface TraceEvent$1 {
302
+ eventId: string;
303
+ runId: string;
304
+ spanId?: string;
305
+ kind: EventKind;
306
+ timestamp: number;
307
+ payload: Record<string, unknown>;
308
+ }
309
+ interface BudgetLedgerEntry {
310
+ runId: string;
311
+ dimension: keyof BudgetSpec;
312
+ limit: number;
313
+ consumed: number;
314
+ remaining: number;
315
+ timestamp: number;
316
+ breached: boolean;
317
+ /** Span that triggered this entry, if any. */
318
+ spanId?: string;
319
+ }
320
+ interface Artifact {
321
+ artifactId: string;
322
+ runId: string;
323
+ spanId?: string;
324
+ contentType: string;
325
+ sizeBytes: number;
326
+ /** sha256 in hex. */
327
+ hash: string;
328
+ /** External storage URL (R2, S3, filesystem path). */
329
+ storageUrl?: string;
330
+ /** Inline content for small blobs — keep under ~64KB. */
331
+ inlineContent?: string;
332
+ }
333
+ type FailureClass = 'success' | 'reasoning_error' | 'tool_selection_error' | 'tool_argument_error' | 'tool_recovery_failure' | 'hallucination' | 'instruction_following' | 'safety_refusal_miss' | 'policy_violation' | 'budget_exceeded' | 'format_drift' | 'permission_escalation' | 'pii_leak' | 'cost_overrun' | 'timeout' | 'sandbox_failure' | 'missing_user_data' | 'missing_domain_data' | 'missing_codebase_context' | 'missing_runtime_context' | 'missing_credentials' | 'missing_integration_connection' | 'missing_integration_scope' | 'integration_approval_required' | 'integration_auth_expired' | 'integration_provider_failure' | 'bad_integration_manifest' | 'unsafe_integration_write_denied' | 'stale_external_data' | 'bad_retrieval' | 'insufficient_evidence' | 'contradictory_evidence' | 'ambiguous_user_intent' | 'knowledge_readiness_blocked' | 'unknown';
334
+
335
+ interface RunFilter {
336
+ scenarioId?: string;
337
+ variantId?: string;
338
+ status?: RunStatus;
339
+ since?: number;
340
+ until?: number;
341
+ tag?: {
342
+ key: string;
343
+ value: string;
344
+ };
345
+ parentRunId?: string;
346
+ projectId?: string;
347
+ chatId?: string;
348
+ layer?: RunLayer;
349
+ }
350
+ interface SpanFilter {
351
+ runId?: string;
352
+ parentSpanId?: string;
353
+ kind?: SpanKind;
354
+ name?: string;
355
+ toolName?: string;
356
+ judgeId?: string;
357
+ since?: number;
358
+ until?: number;
359
+ }
360
+ interface EventFilter {
361
+ runId?: string;
362
+ spanId?: string;
363
+ kind?: EventKind;
364
+ since?: number;
365
+ until?: number;
366
+ }
367
+ interface TraceStore {
368
+ appendRun(run: Run): Promise<void>;
369
+ updateRun(runId: string, patch: Partial<Run>): Promise<void>;
370
+ appendSpan(span: Span): Promise<void>;
371
+ updateSpan(spanId: string, patch: Partial<Span>): Promise<void>;
372
+ appendEvent(event: TraceEvent$1): Promise<void>;
373
+ appendArtifact(artifact: Artifact): Promise<void>;
374
+ appendBudgetEntry(entry: BudgetLedgerEntry): Promise<void>;
375
+ getRun(runId: string): Promise<Run | undefined>;
376
+ listRuns(filter?: RunFilter): Promise<Run[]>;
377
+ spans(filter?: SpanFilter): Promise<Span[]>;
378
+ events(filter?: EventFilter): Promise<TraceEvent$1[]>;
379
+ budget(runId: string): Promise<BudgetLedgerEntry[]>;
380
+ artifacts(runId: string): Promise<Artifact[]>;
381
+ }
382
+
383
+ /**
384
+ * Policy-based agent control runtime.
385
+ *
386
+ * This is the minimal reusable loop behind driver-agent patterns:
387
+ *
388
+ * observe state -> validate -> decide next action -> act -> observe -> ...
389
+ *
390
+ * It deliberately does not model named "topologies". Direct execution,
391
+ * critic/revise, driver intervention, specialist calls, and human escalation
392
+ * are all just actions chosen by the control policy.
393
+ */
394
+
395
+ type ControlSeverity = 'info' | 'warning' | 'error' | 'critical';
396
+ interface ControlEvalResult {
397
+ /** Stable validator or judge id. */
398
+ id: string;
399
+ /** Whether this check passed. */
400
+ passed: boolean;
401
+ /** Optional normalized score. 1 = best, 0 = worst. */
402
+ score?: number;
403
+ /** Objective validators should usually be "error" or "critical" when failed. */
404
+ severity?: ControlSeverity;
405
+ /** Human-readable result. */
406
+ detail?: string;
407
+ /** Small evidence string or pointer. Avoid large payloads. */
408
+ evidence?: string;
409
+ /** True when the result came from deterministic state, not LLM judgment. */
410
+ objective?: boolean;
411
+ /** Structured details for downstream control policies and reports. */
412
+ metadata?: Record<string, unknown>;
413
+ }
414
+
415
+ /**
416
+ * Dataset — versioned, sliceable, content-hashed scenario collection.
417
+ *
418
+ * Scenarios stop being ephemeral arrays and become first-class
419
+ * artifacts. Every Dataset carries:
420
+ * - content hash (sha256 over canonicalized scenario array)
421
+ * - provenance (contributor, createdAt, sourceUrl)
422
+ * - split labels (train | dev | test | holdout)
423
+ * - difficulty tiers (easy | medium | hard | extreme)
424
+ * - tags (free-form, per-scenario)
425
+ *
426
+ * `Dataset.slice({ difficulty, split, holdout, seed })` returns a
427
+ * deterministic, reproducible subset. Holdout slices are locked: you
428
+ * can read them but `mutate` throws, which prevents "oh I'll just
429
+ * tweak that one scenario" contamination drift.
430
+ */
431
+ type DatasetSplit = 'train' | 'dev' | 'test' | 'holdout';
432
+
433
+ type FeedbackArtifactType = 'text' | 'code' | 'plan' | 'research' | 'action' | 'ui' | 'decision' | 'data' | 'other';
434
+ type FeedbackLabelSource = 'user' | 'judge' | 'environment' | 'metric' | 'policy' | 'system';
435
+ type FeedbackLabelKind = 'approve' | 'reject' | 'select' | 'edit' | 'rank' | 'rate' | 'comment' | 'metric_outcome' | 'policy_block' | 'revision_request';
436
+ type FeedbackSeverity = 'info' | 'warning' | 'error' | 'critical';
437
+ interface FeedbackTask {
438
+ intent: string;
439
+ context?: unknown;
440
+ }
441
+ interface ProposedSideEffect {
442
+ type: string;
443
+ risk?: 'low' | 'medium' | 'high';
444
+ costUsd?: number;
445
+ externalSideEffect?: boolean;
446
+ requiresApproval?: boolean;
447
+ metadata?: Record<string, unknown>;
448
+ }
449
+ interface FeedbackLabel {
450
+ id?: string;
451
+ source: FeedbackLabelSource;
452
+ kind: FeedbackLabelKind;
453
+ value: unknown;
454
+ reason?: string;
455
+ severity?: FeedbackSeverity;
456
+ createdAt: string;
457
+ metadata?: Record<string, unknown>;
458
+ }
459
+ interface FeedbackAttempt {
460
+ id: string;
461
+ stepIndex: number;
462
+ artifactType: FeedbackArtifactType;
463
+ artifact: unknown;
464
+ options?: unknown[];
465
+ proposedAction?: ProposedSideEffect;
466
+ evals?: ControlEvalResult[];
467
+ feedback?: FeedbackLabel[];
468
+ createdAt: string;
469
+ metadata?: Record<string, unknown>;
470
+ }
471
+ interface FeedbackOutcome {
472
+ success?: boolean;
473
+ score?: number;
474
+ metrics?: Record<string, number>;
475
+ costUsd?: number;
476
+ detail?: string;
477
+ observedAt?: string;
478
+ metadata?: Record<string, unknown>;
479
+ }
480
+ interface FeedbackTrajectory$1 {
481
+ id: string;
482
+ projectId?: string;
483
+ scenarioId?: string;
484
+ task: FeedbackTask;
485
+ attempts: FeedbackAttempt[];
486
+ labels: FeedbackLabel[];
487
+ outcome?: FeedbackOutcome;
488
+ split?: DatasetSplit;
489
+ tags?: Record<string, string>;
490
+ createdAt: string;
491
+ updatedAt?: string;
492
+ metadata?: Record<string, unknown>;
493
+ }
494
+ interface FeedbackTrajectoryStore {
495
+ save(trajectory: FeedbackTrajectory$1): Promise<void>;
496
+ get(id: string): Promise<FeedbackTrajectory$1 | null>;
497
+ list(filter?: FeedbackTrajectoryFilter): Promise<FeedbackTrajectory$1[]>;
498
+ appendAttempt(id: string, attempt: FeedbackAttempt): Promise<FeedbackTrajectory$1>;
499
+ appendLabel(id: string, label: FeedbackLabel, attemptId?: string): Promise<FeedbackTrajectory$1>;
500
+ }
501
+ interface FeedbackTrajectoryFilter {
502
+ projectId?: string;
503
+ scenarioId?: string;
504
+ split?: DatasetSplit;
505
+ tag?: [string, string];
506
+ }
507
+
508
+ /**
509
+ * RawProviderSink — first-class persistence for the actual HTTP-level
510
+ * request/response bodies of every LLM provider call.
511
+ *
512
+ * Why this is a separate sink from the structured `LlmSpan`:
513
+ *
514
+ * - `LlmSpan` records the *intent* — model name, messages, output text,
515
+ * usage. It's what dashboards read; it's NOT enough for forensics.
516
+ * - When a downstream consumer reports "the verifier used the wrong route"
517
+ * or "tokens look right but reasoning was missing," the only way to
518
+ * answer is the raw HTTP body. Span fields can lie (a proxy can echo
519
+ * a different `model` value than what actually answered); the raw
520
+ * response is ground truth.
521
+ *
522
+ * Default behaviour: opt-in. Pass `rawSink` to `LlmClientOptions` (or the
523
+ * matrix runner / BuilderSession sets it up automatically) and every
524
+ * request, response, and error is recorded — including retries, with the
525
+ * attempt index attached so a flaky call's full event chain is recoverable.
526
+ *
527
+ * Redaction is enforced at sink time. The default redactor strips
528
+ * `Authorization`, `X-Api-Key`, `X-Auth-Token`, `Cookie` headers and any
529
+ * payload field whose key matches `apiKey | api_key | bearer | password |
530
+ * secret | token` (case-insensitive). Override via the sink constructor or
531
+ * the per-call `redactor`. The `redactedFields` array on the persisted
532
+ * event lets a reviewer see what was stripped without exposing the values.
533
+ */
534
+ type RawProviderDirection = 'request' | 'response' | 'error';
535
+ interface RawProviderEvent {
536
+ /** Stable id. Generated by the sink if omitted. */
537
+ eventId: string;
538
+ /** Trace context populated by `LlmClient` when the call is wrapped in a span. */
539
+ runId?: string;
540
+ spanId?: string;
541
+ /**
542
+ * Logical provider name. Free-form so callers can use whatever id matches
543
+ * their topology (`'openai'`, `'anthropic'`, `'tangle-router'`, …). When
544
+ * omitted, derived from `baseUrl` in `LlmClientOptions`.
545
+ */
546
+ provider: string;
547
+ model: string;
548
+ /** Endpoint path, e.g. `'/v1/chat/completions'`. */
549
+ endpoint: string;
550
+ /** Base URL used for the call (already-normalised — no trailing slash). */
551
+ baseUrl: string;
552
+ /** 0-indexed retry attempt. The first attempt is 0; a retried call gets 1, 2, … */
553
+ attemptIndex: number;
554
+ direction: RawProviderDirection;
555
+ /** Unix ms. */
556
+ timestamp: number;
557
+ /** Wall-clock duration of the call leg. Set on `response` and `error` events; null on `request`. */
558
+ durationMs?: number;
559
+ statusCode?: number;
560
+ requestHeaders?: Record<string, string>;
561
+ requestBody?: unknown;
562
+ responseHeaders?: Record<string, string>;
563
+ responseBody?: unknown;
564
+ /** Set on `direction: 'error'` events. */
565
+ errorMessage?: string;
566
+ /** Field paths the redactor stripped from this event ('header:Authorization', 'body.apiKey', …). */
567
+ redactedFields: string[];
568
+ }
569
+ interface RawProviderSinkFilter {
570
+ runId?: string;
571
+ spanId?: string;
572
+ direction?: RawProviderDirection;
573
+ attemptIndex?: number;
574
+ }
575
+ interface RawProviderSink {
576
+ record(event: RawProviderEvent): Promise<void>;
577
+ /** Optional listing — implementations that durably persist (file, db) should support this. */
578
+ list?(filter?: RawProviderSinkFilter): Promise<RawProviderEvent[]>;
579
+ /** Optional teardown for backed implementations. */
580
+ close?(): Promise<void>;
581
+ }
582
+ type ProviderRedactor = (event: RawProviderEvent) => RawProviderEvent;
583
+
584
+ /**
585
+ * LLM client with graceful degrade.
586
+ *
587
+ * OpenAI-compatible `/v1/chat/completions` client with:
588
+ * - Exponential-backoff retry on 429 + 5xx gateway errors (502/503/504).
589
+ * - Retry on transient network errors (fetch failed, AbortError, ECONNRESET).
590
+ * - Graceful json_schema → json_object degrade on 400 with schema-reject body.
591
+ * - Fenced-JSON stripping (```json ... ```) for models that wrap structured output.
592
+ * - Configurable base URL + api key / bearer, works with LiteLLM proxies, OpenAI
593
+ * directly, cli-bridge subscriptions, and any router that speaks the spec.
594
+ *
595
+ * Usage:
596
+ * const { value, result } = await callLlmJson<MyType>(
597
+ * { model: 'gpt-4o', messages: [...], jsonSchema: { name: 'x', schema: {...} } },
598
+ * { baseUrl: 'https://router.tangle.tools/v1', apiKey: process.env.KEY },
599
+ * )
600
+ *
601
+ * This is THE llm-calling seam for agent-eval primitives that need structured
602
+ * output (semantic concept judge, reviewer directives, critic scores). Primitives
603
+ * that need free-form text use `callLlm` and parse output themselves.
604
+ */
605
+
606
+ interface LlmClientOptions {
607
+ /** Base URL (without trailing slash). Must end at the `/v1` prefix. */
608
+ baseUrl?: string;
609
+ /** Bearer token — either `apiKey` or `bearer` populates `Authorization: Bearer ...`. */
610
+ apiKey?: string;
611
+ bearer?: string;
612
+ /** Override for the `Authorization` header (e.g. `X-Auth: ...`). Takes precedence over apiKey/bearer. */
613
+ authHeader?: {
614
+ name: string;
615
+ value: string;
616
+ };
617
+ /** Stable provider idempotency key, reused across retries of this logical call. */
618
+ idempotencyKey?: string;
619
+ /** Default timeout in ms. Per-call can override. */
620
+ defaultTimeoutMs?: number;
621
+ /**
622
+ * Caller-supplied abort signal — e.g. a campaign-wide cancel. Linked to
623
+ * each attempt's per-attempt timeout controller, so aborting it cancels
624
+ * the in-flight fetch. A caller abort is FATAL: it is not retried even
625
+ * though an AbortError otherwise matches the transient patterns.
626
+ */
627
+ signal?: AbortSignal;
628
+ /**
629
+ * Cross-attempt wall-clock budget in ms, measured from the first attempt.
630
+ * Before launching each attempt the loop checks the remaining budget and
631
+ * stops retrying once it is exhausted, rather than waiting the full
632
+ * per-attempt timeout on every retry. Bounds total time independent of
633
+ * total attempts × `timeoutMs`.
634
+ */
635
+ deadlineMs?: number;
636
+ /** Total provider attempts. Legacy option name; default 3 (1 initial + 2 retries). */
637
+ maxRetries?: number;
638
+ /** Fetch implementation — defaults to global `fetch`. Override for custom transport (e.g. tests). */
639
+ fetch?: typeof fetch;
640
+ /**
641
+ * Optional raw HTTP capture sink. When provided, every request, response,
642
+ * and error (across all retry attempts) is recorded to the sink, with auth
643
+ * headers and credential-shaped body fields redacted by default. This is
644
+ * the layer-1 forensics primitive: structured `LlmSpan`s record intent,
645
+ * raw events record what actually crossed the wire.
646
+ */
647
+ rawSink?: RawProviderSink;
648
+ /**
649
+ * Logical provider id attached to raw events. When omitted, derived from
650
+ * `baseUrl` via `providerFromBaseUrl`.
651
+ */
652
+ provider?: string;
653
+ /** Trace context attached to raw events; populated by emitter-aware callers. */
654
+ traceContext?: {
655
+ runId?: string;
656
+ spanId?: string;
657
+ };
658
+ /** Override the redaction strategy for this call. Defaults to `defaultProviderRedactor`. */
659
+ redactor?: ProviderRedactor;
660
+ }
15
661
 
16
662
  declare const RubricDimensionSchema: z.ZodObject<{
17
663
  id: z.ZodString;