@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.
- package/CHANGELOG.md +30 -0
- package/dist/analyst/index.d.ts +2772 -21
- package/dist/analyst/index.js +7 -6
- package/dist/analyst/index.js.map +1 -1
- package/dist/belief-state/index.d.ts +706 -10
- package/dist/belief-state/index.js +2 -1
- package/dist/belief-state/index.js.map +1 -1
- package/dist/benchmarks/index.d.ts +958 -14
- package/dist/benchmarks/index.js +12 -10
- package/dist/builder-eval/index.d.ts +449 -4
- package/dist/builder-eval/index.js +4 -3
- package/dist/builder-eval/index.js.map +1 -1
- package/dist/campaign/index.d.ts +4276 -74
- package/dist/campaign/index.js +12 -10
- package/dist/{chunk-VF3XSYTI.js → chunk-33JA4TFA.js} +6 -6
- package/dist/{chunk-4JLWXDYA.js → chunk-3EHHMC6E.js} +2 -2
- package/dist/{chunk-CCZIVI3F.js → chunk-BFW56GTT.js} +2 -2
- package/dist/{chunk-YZPO4UHR.js → chunk-DP3BBMYJ.js} +100 -143
- package/dist/chunk-DP3BBMYJ.js.map +1 -0
- package/dist/{chunk-E4BUPP7Z.js → chunk-HKUCJ437.js} +38 -66
- package/dist/chunk-HKUCJ437.js.map +1 -0
- package/dist/{chunk-HZHNRYHK.js → chunk-K6N6XJJX.js} +2 -2
- package/dist/chunk-KSDQVPLR.js +286 -0
- package/dist/chunk-KSDQVPLR.js.map +1 -0
- package/dist/chunk-MA6HLL3S.js +65 -0
- package/dist/chunk-MA6HLL3S.js.map +1 -0
- package/dist/{chunk-MGEHEHSN.js → chunk-OIIMMLRB.js} +11 -11
- package/dist/{chunk-DXZRATT5.js → chunk-OYZAPX5G.js} +3 -3
- package/dist/chunk-PXE2VKMX.js +140 -0
- package/dist/chunk-PXE2VKMX.js.map +1 -0
- package/dist/{chunk-ZUXV7UWZ.js → chunk-Q442S5AS.js} +73 -19
- package/dist/{chunk-ZUXV7UWZ.js.map → chunk-Q442S5AS.js.map} +1 -1
- package/dist/{chunk-ODVOOEWQ.js → chunk-QBRSJK47.js} +2 -2
- package/dist/{chunk-S2F4J57L.js → chunk-QKEGNI5B.js} +77 -32
- package/dist/chunk-QKEGNI5B.js.map +1 -0
- package/dist/{chunk-5UF54T55.js → chunk-S3UZOQ5Y.js} +34 -7
- package/dist/chunk-S3UZOQ5Y.js.map +1 -0
- package/dist/{chunk-FQNLDL4D.js → chunk-SVH2ANFD.js} +136 -4
- package/dist/chunk-SVH2ANFD.js.map +1 -0
- package/dist/{chunk-GQCZRZ7L.js → chunk-U5CHZ5M3.js} +9 -9
- package/dist/{chunk-TVVP3ZZQ.js → chunk-VQMK5FMP.js} +2 -1
- package/dist/{chunk-TVVP3ZZQ.js.map → chunk-VQMK5FMP.js.map} +1 -1
- package/dist/chunk-WDHBCA3M.js +31 -0
- package/dist/chunk-WDHBCA3M.js.map +1 -0
- package/dist/{chunk-HQPHZGL6.js → chunk-YLMUS4MM.js} +9 -9
- package/dist/{chunk-LQUTGLOZ.js → chunk-ZET2UAYW.js} +15 -65
- package/dist/chunk-ZET2UAYW.js.map +1 -0
- package/dist/contract/index.d.ts +4012 -38
- package/dist/contract/index.js +56 -29
- package/dist/contract/index.js.map +1 -1
- package/dist/control.d.ts +1013 -9
- package/dist/control.js +4 -3
- package/dist/fuzz.d.ts +194 -4
- package/dist/fuzz.js +3 -3
- package/dist/hosted/index.d.ts +498 -17
- package/dist/index.d.ts +10982 -1286
- package/dist/index.js +97 -80
- package/dist/index.js.map +1 -1
- package/dist/matrix/index.d.ts +139 -4
- package/dist/meta-eval/index.d.ts +862 -15
- package/dist/meta-eval/index.js +2 -1
- package/dist/meta-eval/index.js.map +1 -1
- package/dist/multishot/index.d.ts +214 -14
- package/dist/openapi.json +1 -1
- package/dist/pipelines/index.d.ts +392 -7
- package/dist/pipelines/index.js +5 -3
- package/dist/pipelines/index.js.map +1 -1
- package/dist/reporting.d.ts +1277 -17
- package/dist/rl.d.ts +2359 -28
- package/dist/rl.js +6 -5
- package/dist/rl.js.map +1 -1
- package/dist/storyboard/index.d.ts +86 -1
- package/dist/trace-attributes.d.ts +16 -0
- package/dist/trace-attributes.js +32 -0
- package/dist/trace-attributes.js.map +1 -0
- package/dist/traces.d.ts +1970 -697
- package/dist/traces.js +49 -32
- package/dist/wire/index.d.ts +655 -9
- package/docs/insight-report.md +44 -0
- package/package.json +9 -3
- package/dist/adversarial-B7loGVVX.d.ts +0 -19
- package/dist/analyst-C8HHvfJp.d.ts +0 -88
- package/dist/analyze-runs--2x39HZ7.d.ts +0 -81
- package/dist/baseline-DKq3gJpP.d.ts +0 -141
- package/dist/calibration-C8MTS7cw.d.ts +0 -101
- package/dist/chunk-5UF54T55.js.map +0 -1
- package/dist/chunk-E4BUPP7Z.js.map +0 -1
- package/dist/chunk-FQNLDL4D.js.map +0 -1
- package/dist/chunk-LQUTGLOZ.js.map +0 -1
- package/dist/chunk-S2F4J57L.js.map +0 -1
- package/dist/chunk-YZPO4UHR.js.map +0 -1
- package/dist/code-agent-session-CjZsVd19.d.ts +0 -87
- package/dist/control-6vuGfmDH.d.ts +0 -258
- package/dist/cost-ledger-DWy3XdJc.d.ts +0 -183
- package/dist/dataset-NENEzRgk.d.ts +0 -115
- package/dist/default-registry-DaK8b3fv.d.ts +0 -155
- package/dist/emitter-CjD7vUwv.d.ts +0 -122
- package/dist/errors-oeQrLqXC.d.ts +0 -74
- package/dist/failure-cluster-DOAcSJ87.d.ts +0 -76
- package/dist/feedback-trajectory-BUnM58xL.d.ts +0 -348
- package/dist/gepa-eESocoDi.d.ts +0 -642
- package/dist/index-PdX4VnPA.d.ts +0 -423
- package/dist/insight-report-DY4nDW9Q.d.ts +0 -310
- package/dist/integrity-DqlBiLyK.d.ts +0 -81
- package/dist/judge-calibration-7C-IDmKr.d.ts +0 -145
- package/dist/kind-factory-ClZmO25A.d.ts +0 -171
- package/dist/llm-client-qoDd18Qz.d.ts +0 -289
- package/dist/multi-layer-verifier-BsqKuLyN.d.ts +0 -150
- package/dist/off-policy-DiwuKKg7.d.ts +0 -132
- package/dist/outcome-store-rnXLEqSn.d.ts +0 -63
- package/dist/policy-edit-wG9uFEFm.d.ts +0 -455
- package/dist/pre-registration-BWQhJ3vz.d.ts +0 -761
- package/dist/provenance-DpjwyseI.d.ts +0 -541
- package/dist/query-CF7PG61p.d.ts +0 -35
- package/dist/raw-provider-sink-C46HDghv.d.ts +0 -132
- package/dist/release-report-C8G2i5Xi.d.ts +0 -236
- package/dist/researcher-C8XyxQsu.d.ts +0 -387
- package/dist/rubric-predictive-validity-p49lLVrE.d.ts +0 -105
- package/dist/run-record-BDH49H2E.d.ts +0 -360
- package/dist/runtime-trajectory-DGBIUt4B.d.ts +0 -49
- package/dist/schema-B3Q3l9Z_.d.ts +0 -201
- package/dist/semantic-concept-judge-CXnPEJbf.d.ts +0 -723
- package/dist/sequential-5iSVfzl2.d.ts +0 -139
- package/dist/series-convergence-D5OWMBg6.d.ts +0 -33
- package/dist/statistics-KUnG73jH.d.ts +0 -494
- package/dist/storage-DrX3v_5B.d.ts +0 -50
- package/dist/store-C1YxJDEK.d.ts +0 -248
- package/dist/store-DGqD0Pyo.d.ts +0 -116
- package/dist/summary-report-C5bKFfm-.d.ts +0 -445
- package/dist/test-graded-scenario-B0ybnPY7.d.ts +0 -166
- package/dist/types-BSw1rOUB.d.ts +0 -634
- package/dist/types-BUxNaJ8c.d.ts +0 -108
- package/dist/types-BkfcQnxV.d.ts +0 -313
- package/dist/verdict-C9MlYujm.d.ts +0 -35
- /package/dist/{chunk-VF3XSYTI.js.map → chunk-33JA4TFA.js.map} +0 -0
- /package/dist/{chunk-4JLWXDYA.js.map → chunk-3EHHMC6E.js.map} +0 -0
- /package/dist/{chunk-CCZIVI3F.js.map → chunk-BFW56GTT.js.map} +0 -0
- /package/dist/{chunk-HZHNRYHK.js.map → chunk-K6N6XJJX.js.map} +0 -0
- /package/dist/{chunk-MGEHEHSN.js.map → chunk-OIIMMLRB.js.map} +0 -0
- /package/dist/{chunk-DXZRATT5.js.map → chunk-OYZAPX5G.js.map} +0 -0
- /package/dist/{chunk-ODVOOEWQ.js.map → chunk-QBRSJK47.js.map} +0 -0
- /package/dist/{chunk-GQCZRZ7L.js.map → chunk-U5CHZ5M3.js.map} +0 -0
- /package/dist/{chunk-HQPHZGL6.js.map → chunk-YLMUS4MM.js.map} +0 -0
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
// src/trace/extract-usage.ts
|
|
2
|
+
import { SSEChunkParser } from "@tangle-network/agent-core/sse";
|
|
3
|
+
import {
|
|
4
|
+
firstTokenCount,
|
|
5
|
+
TOKEN_USAGE_INPUT_KEYS,
|
|
6
|
+
TOKEN_USAGE_OUTPUT_KEYS,
|
|
7
|
+
tokenUsageSource
|
|
8
|
+
} from "@tangle-network/agent-core/telemetry";
|
|
9
|
+
var INPUT_OTHER_KEYS = ["input_other"];
|
|
10
|
+
var EXCLUSIVE_REASONING_KEYS = ["reasoning", "reasoning_tokens", "reasoningTokens"];
|
|
11
|
+
var INCLUSIVE_REASONING_KEYS = ["reasoning_output_tokens", "reasoningOutputTokens"];
|
|
12
|
+
var INPUT_DETAIL_KEYS = ["prompt_tokens_details", "input_tokens_details"];
|
|
13
|
+
var OUTPUT_DETAIL_KEYS = ["completion_tokens_details", "output_tokens_details"];
|
|
14
|
+
var CACHED_KEYS = [
|
|
15
|
+
"cache",
|
|
16
|
+
"cached_tokens",
|
|
17
|
+
"cached_input_tokens",
|
|
18
|
+
"cache_read_tokens",
|
|
19
|
+
"cache_read_input_tokens",
|
|
20
|
+
"cachedTokens",
|
|
21
|
+
"cachedInputTokens",
|
|
22
|
+
"cacheReadTokens",
|
|
23
|
+
"cacheReadInputTokens",
|
|
24
|
+
"input_cache_read"
|
|
25
|
+
];
|
|
26
|
+
var CACHE_WRITE_KEYS = [
|
|
27
|
+
"cache_creation_tokens",
|
|
28
|
+
"cache_creation_input_tokens",
|
|
29
|
+
"cacheCreationTokens",
|
|
30
|
+
"cacheCreationInputTokens",
|
|
31
|
+
"input_cache_creation"
|
|
32
|
+
];
|
|
33
|
+
function nestedRecord(source, key) {
|
|
34
|
+
const value = source[key];
|
|
35
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : void 0;
|
|
36
|
+
}
|
|
37
|
+
function nestedNumber(source, recordKeys, valueKeys) {
|
|
38
|
+
for (const recordKey of recordKeys) {
|
|
39
|
+
const value = firstTokenCount(nestedRecord(source, recordKey), valueKeys);
|
|
40
|
+
if (value !== void 0) return value;
|
|
41
|
+
}
|
|
42
|
+
return void 0;
|
|
43
|
+
}
|
|
44
|
+
function extractUsage(body) {
|
|
45
|
+
if (!body || typeof body !== "object") return null;
|
|
46
|
+
const obj = body;
|
|
47
|
+
const usage = tokenUsageSource(obj);
|
|
48
|
+
const input = firstTokenCount(usage, TOKEN_USAGE_INPUT_KEYS);
|
|
49
|
+
const inputOther = firstTokenCount(usage, INPUT_OTHER_KEYS);
|
|
50
|
+
const output = firstTokenCount(usage, TOKEN_USAGE_OUTPUT_KEYS);
|
|
51
|
+
const exclusiveReasoning = firstTokenCount(usage, EXCLUSIVE_REASONING_KEYS);
|
|
52
|
+
const inclusiveReasoning = firstTokenCount(usage, INCLUSIVE_REASONING_KEYS) ?? nestedNumber(usage, OUTPUT_DETAIL_KEYS, ["reasoning_tokens", "reasoningTokens"]);
|
|
53
|
+
const reasoning = exclusiveReasoning ?? inclusiveReasoning;
|
|
54
|
+
const nestedCache = nestedRecord(usage, "cache");
|
|
55
|
+
const cached = firstTokenCount(usage, CACHED_KEYS) ?? firstTokenCount(nestedCache, ["read"]) ?? nestedNumber(usage, INPUT_DETAIL_KEYS, ["cached_tokens", "cachedTokens"]);
|
|
56
|
+
const cacheWrite = firstTokenCount(usage, CACHE_WRITE_KEYS) ?? firstTokenCount(nestedCache, ["write"]);
|
|
57
|
+
if (input === void 0 && inputOther === void 0 && output === void 0 && reasoning === void 0 && cached === void 0 && cacheWrite === void 0)
|
|
58
|
+
return null;
|
|
59
|
+
const result = {
|
|
60
|
+
input: (input ?? 0) + (inputOther ?? 0),
|
|
61
|
+
output: (output ?? (inclusiveReasoning !== void 0 ? inclusiveReasoning : 0)) + (exclusiveReasoning ?? 0)
|
|
62
|
+
};
|
|
63
|
+
if (reasoning !== void 0) result.reasoning = reasoning;
|
|
64
|
+
if (cached !== void 0) result.cached = cached;
|
|
65
|
+
if (cacheWrite !== void 0) result.cacheWrite = cacheWrite;
|
|
66
|
+
return result;
|
|
67
|
+
}
|
|
68
|
+
function extractUsageFromSse(text, options = {}) {
|
|
69
|
+
const mode = options.mode ?? "cumulative";
|
|
70
|
+
let input = 0;
|
|
71
|
+
let output = 0;
|
|
72
|
+
let reasoning = 0;
|
|
73
|
+
let sawReasoning = false;
|
|
74
|
+
let cached = 0;
|
|
75
|
+
let sawCached = false;
|
|
76
|
+
let cacheWrite = 0;
|
|
77
|
+
let sawCacheWrite = false;
|
|
78
|
+
let found = false;
|
|
79
|
+
const parser = new SSEChunkParser({ transform: parseSseJson });
|
|
80
|
+
const events = [...parser.push(text), ...parser.flush()];
|
|
81
|
+
const merge = mode === "delta" ? (current, next) => current + next : Math.max;
|
|
82
|
+
for (const event of events) {
|
|
83
|
+
const usage = extractUsage(event.data);
|
|
84
|
+
if (!usage) continue;
|
|
85
|
+
input = merge(input, usage.input);
|
|
86
|
+
output = merge(output, usage.output);
|
|
87
|
+
if (usage.reasoning !== void 0) {
|
|
88
|
+
reasoning = merge(reasoning, usage.reasoning);
|
|
89
|
+
sawReasoning = true;
|
|
90
|
+
}
|
|
91
|
+
if (usage.cached !== void 0) {
|
|
92
|
+
cached = merge(cached, usage.cached);
|
|
93
|
+
sawCached = true;
|
|
94
|
+
}
|
|
95
|
+
if (usage.cacheWrite !== void 0) {
|
|
96
|
+
cacheWrite = merge(cacheWrite, usage.cacheWrite);
|
|
97
|
+
sawCacheWrite = true;
|
|
98
|
+
}
|
|
99
|
+
found = true;
|
|
100
|
+
}
|
|
101
|
+
if (!found) return null;
|
|
102
|
+
return {
|
|
103
|
+
input,
|
|
104
|
+
output,
|
|
105
|
+
...sawReasoning ? { reasoning } : {},
|
|
106
|
+
...sawCached ? { cached } : {},
|
|
107
|
+
...sawCacheWrite ? { cacheWrite } : {}
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
function parseSseJson(raw) {
|
|
111
|
+
const payload = raw.trim();
|
|
112
|
+
if (!payload || payload === "[DONE]") return null;
|
|
113
|
+
try {
|
|
114
|
+
return JSON.parse(payload);
|
|
115
|
+
} catch {
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
async function extractUsageFromResponse(response, sseOptions) {
|
|
120
|
+
let text;
|
|
121
|
+
try {
|
|
122
|
+
text = await response.clone().text();
|
|
123
|
+
} catch {
|
|
124
|
+
return null;
|
|
125
|
+
}
|
|
126
|
+
let json;
|
|
127
|
+
try {
|
|
128
|
+
json = JSON.parse(text);
|
|
129
|
+
} catch {
|
|
130
|
+
json = void 0;
|
|
131
|
+
}
|
|
132
|
+
return extractUsage(json) ?? extractUsageFromSse(text, sseOptions);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export {
|
|
136
|
+
extractUsage,
|
|
137
|
+
extractUsageFromSse,
|
|
138
|
+
extractUsageFromResponse
|
|
139
|
+
};
|
|
140
|
+
//# sourceMappingURL=chunk-PXE2VKMX.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/trace/extract-usage.ts"],"sourcesContent":["/**\n * Provider response and SSE usage extraction.\n *\n * Missing usage returns `null`; reported zeroes and cache-only activity remain\n * distinguishable from absent telemetry.\n */\n\nimport { SSEChunkParser } from '@tangle-network/agent-core/sse'\nimport {\n firstTokenCount,\n TOKEN_USAGE_INPUT_KEYS,\n TOKEN_USAGE_OUTPUT_KEYS,\n tokenUsageSource,\n} from '@tangle-network/agent-core/telemetry'\nimport type { RunTokenUsage } from '../run-record'\n\nexport type ExtractedUsage = RunTokenUsage\nexport type SseUsageMode = 'cumulative' | 'delta'\n\nexport interface ExtractUsageFromSseOptions {\n /** Provider usage events are cumulative snapshots unless explicitly marked as deltas. */\n mode?: SseUsageMode\n}\n\nconst INPUT_OTHER_KEYS = ['input_other'] as const\nconst EXCLUSIVE_REASONING_KEYS = ['reasoning', 'reasoning_tokens', 'reasoningTokens'] as const\nconst INCLUSIVE_REASONING_KEYS = ['reasoning_output_tokens', 'reasoningOutputTokens'] as const\nconst INPUT_DETAIL_KEYS = ['prompt_tokens_details', 'input_tokens_details'] as const\nconst OUTPUT_DETAIL_KEYS = ['completion_tokens_details', 'output_tokens_details'] as const\nconst CACHED_KEYS = [\n 'cache',\n 'cached_tokens',\n 'cached_input_tokens',\n 'cache_read_tokens',\n 'cache_read_input_tokens',\n 'cachedTokens',\n 'cachedInputTokens',\n 'cacheReadTokens',\n 'cacheReadInputTokens',\n 'input_cache_read',\n] as const\nconst CACHE_WRITE_KEYS = [\n 'cache_creation_tokens',\n 'cache_creation_input_tokens',\n 'cacheCreationTokens',\n 'cacheCreationInputTokens',\n 'input_cache_creation',\n] as const\n\nfunction nestedRecord(\n source: Record<string, unknown>,\n key: string,\n): Record<string, unknown> | undefined {\n const value = source[key]\n return value && typeof value === 'object' && !Array.isArray(value)\n ? (value as Record<string, unknown>)\n : undefined\n}\n\nfunction nestedNumber(\n source: Record<string, unknown>,\n recordKeys: readonly string[],\n valueKeys: readonly string[],\n): number | undefined {\n for (const recordKey of recordKeys) {\n const value = firstTokenCount(nestedRecord(source, recordKey), valueKeys)\n if (value !== undefined) return value\n }\n return undefined\n}\n\n/**\n * Pull `{ input, output, cached?, cacheWrite? }` from a parsed response\n * body. Accepts a top-level `usage` object (the common case) or a body that IS\n * the usage object. Returns null only when none of those categories is present.\n */\nexport function extractUsage(body: unknown): ExtractedUsage | null {\n if (!body || typeof body !== 'object') return null\n const obj = body as Record<string, unknown>\n const usage = tokenUsageSource(obj)\n const input = firstTokenCount(usage, TOKEN_USAGE_INPUT_KEYS)\n const inputOther = firstTokenCount(usage, INPUT_OTHER_KEYS)\n const output = firstTokenCount(usage, TOKEN_USAGE_OUTPUT_KEYS)\n const exclusiveReasoning = firstTokenCount(usage, EXCLUSIVE_REASONING_KEYS)\n const inclusiveReasoning =\n firstTokenCount(usage, INCLUSIVE_REASONING_KEYS) ??\n nestedNumber(usage, OUTPUT_DETAIL_KEYS, ['reasoning_tokens', 'reasoningTokens'])\n const reasoning = exclusiveReasoning ?? inclusiveReasoning\n const nestedCache = nestedRecord(usage, 'cache')\n const cached =\n firstTokenCount(usage, CACHED_KEYS) ??\n firstTokenCount(nestedCache, ['read']) ??\n nestedNumber(usage, INPUT_DETAIL_KEYS, ['cached_tokens', 'cachedTokens'])\n const cacheWrite =\n firstTokenCount(usage, CACHE_WRITE_KEYS) ?? firstTokenCount(nestedCache, ['write'])\n if (\n input === undefined &&\n inputOther === undefined &&\n output === undefined &&\n reasoning === undefined &&\n cached === undefined &&\n cacheWrite === undefined\n )\n return null\n const result: ExtractedUsage = {\n input: (input ?? 0) + (inputOther ?? 0),\n output:\n (output ?? (inclusiveReasoning !== undefined ? inclusiveReasoning : 0)) +\n (exclusiveReasoning ?? 0),\n }\n if (reasoning !== undefined) result.reasoning = reasoning\n if (cached !== undefined) result.cached = cached\n if (cacheWrite !== undefined) result.cacheWrite = cacheWrite\n return result\n}\n\n/**\n * Extract token usage from a complete SSE response body using the shared SSE\n * frame parser. Cumulative snapshots are the fail-safe default because summing\n * them inflates billing; callers with explicit delta events opt into `mode: 'delta'`.\n */\nexport function extractUsageFromSse(\n text: string,\n options: ExtractUsageFromSseOptions = {},\n): ExtractedUsage | null {\n const mode = options.mode ?? 'cumulative'\n let input = 0\n let output = 0\n let reasoning = 0\n let sawReasoning = false\n let cached = 0\n let sawCached = false\n let cacheWrite = 0\n let sawCacheWrite = false\n let found = false\n const parser = new SSEChunkParser<unknown>({ transform: parseSseJson })\n const events = [...parser.push(text), ...parser.flush()]\n const merge = mode === 'delta' ? (current: number, next: number) => current + next : Math.max\n\n for (const event of events) {\n const usage = extractUsage(event.data)\n if (!usage) continue\n input = merge(input, usage.input)\n output = merge(output, usage.output)\n if (usage.reasoning !== undefined) {\n reasoning = merge(reasoning, usage.reasoning)\n sawReasoning = true\n }\n if (usage.cached !== undefined) {\n cached = merge(cached, usage.cached)\n sawCached = true\n }\n if (usage.cacheWrite !== undefined) {\n cacheWrite = merge(cacheWrite, usage.cacheWrite)\n sawCacheWrite = true\n }\n found = true\n }\n if (!found) return null\n return {\n input,\n output,\n ...(sawReasoning ? { reasoning } : {}),\n ...(sawCached ? { cached } : {}),\n ...(sawCacheWrite ? { cacheWrite } : {}),\n }\n}\n\nfunction parseSseJson(raw: string): unknown | null {\n const payload = raw.trim()\n if (!payload || payload === '[DONE]') return null\n try {\n return JSON.parse(payload)\n } catch {\n return null\n }\n}\n\n/**\n * Extract usage from an HTTP `Response` without consuming the caller's body:\n * clones, reads the text, and tries the JSON parser first, then the SSE\n * accumulator. Best-effort — returns null on any read/parse miss so a usage tee\n * never takes down the underlying call.\n */\nexport async function extractUsageFromResponse(\n response: Response,\n sseOptions?: ExtractUsageFromSseOptions,\n): Promise<ExtractedUsage | null> {\n let text: string\n try {\n text = await response.clone().text()\n } catch {\n return null\n }\n let json: unknown\n try {\n json = JSON.parse(text)\n } catch {\n json = undefined\n }\n return extractUsage(json) ?? extractUsageFromSse(text, sseOptions)\n}\n"],"mappings":";AAOA,SAAS,sBAAsB;AAC/B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAWP,IAAM,mBAAmB,CAAC,aAAa;AACvC,IAAM,2BAA2B,CAAC,aAAa,oBAAoB,iBAAiB;AACpF,IAAM,2BAA2B,CAAC,2BAA2B,uBAAuB;AACpF,IAAM,oBAAoB,CAAC,yBAAyB,sBAAsB;AAC1E,IAAM,qBAAqB,CAAC,6BAA6B,uBAAuB;AAChF,IAAM,cAAc;AAAA,EAClB;AAAA,EACA;AAAA,EACA;AAAA,EAC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Ae,EAAE,UAAU,IAAI,CAAC;AAAA,IACpC,GAAI,YAAY,EAAE,OAAO,IAAI,CAAC;AAAA,IAC9B,GAAI,gBAAgB,EAAE,WAAW,IAAI,CAAC;AAAA,EACxC;AACF;AAEA,SAAS,aAAa,KAA6B;AACjD,QAAM,UAAU,IAAI,KAAK;AACzB,MAAI,CAAC,WAAW,YAAY,SAAU,QAAO;AAC7C,MAAI;AACF,WAAO,KAAK,MAAM,OAAO;AAAA,EAC3B,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAQA,eAAsB,yBACpB,UACA,YACgC;AAChC,MAAI;AACJ,MAAI;AACF,WAAO,MAAM,SAAS,MAAM,EAAE,KAAK;AAAA,EACrC,QAAQ;AACN,WAAO;AAAA,EACT;AACA,MAAI;AACJ,MAAI;AACF,WAAO,KAAK,MAAM,IAAI;AAAA,EACxB,QAAQ;AACN,WAAO;AAAA,EACT;AACA,SAAO,aAAa,IAAI,KAAK,oBAAoB,MAAM,UAAU;AACnE;","names":[]}
|
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
runImprovementLoop,
|
|
16
16
|
surfaceContentHash,
|
|
17
17
|
surfaceHash
|
|
18
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-YLMUS4MM.js";
|
|
19
19
|
import {
|
|
20
20
|
SearchLedgerConflictError,
|
|
21
21
|
SearchLedgerError,
|
|
@@ -48,7 +48,14 @@ import {
|
|
|
48
48
|
makePolicyEditCandidateRecord,
|
|
49
49
|
policyEditsFromFindings,
|
|
50
50
|
validatePolicyEditCandidateRecord
|
|
51
|
-
} from "./chunk-
|
|
51
|
+
} from "./chunk-OIIMMLRB.js";
|
|
52
|
+
import {
|
|
53
|
+
callLlm,
|
|
54
|
+
callLlmJson,
|
|
55
|
+
costReceiptFromLlm,
|
|
56
|
+
costReceiptFromLlmError,
|
|
57
|
+
maximumChargeForLlmRequest
|
|
58
|
+
} from "./chunk-NJC7U437.js";
|
|
52
59
|
import {
|
|
53
60
|
eProcess,
|
|
54
61
|
mcnemar,
|
|
@@ -57,33 +64,26 @@ import {
|
|
|
57
64
|
pairedRiskDifference,
|
|
58
65
|
wilcoxonSignedRank
|
|
59
66
|
} from "./chunk-PJQFMIOX.js";
|
|
67
|
+
import {
|
|
68
|
+
CostAccountingIncompleteError,
|
|
69
|
+
CostLedger
|
|
70
|
+
} from "./chunk-VCTY3W6J.js";
|
|
60
71
|
import {
|
|
61
72
|
analyzeTraces
|
|
62
|
-
} from "./chunk-
|
|
73
|
+
} from "./chunk-3EHHMC6E.js";
|
|
63
74
|
import {
|
|
64
75
|
OtlpFileTraceStore
|
|
65
|
-
} from "./chunk-
|
|
76
|
+
} from "./chunk-QKEGNI5B.js";
|
|
66
77
|
import {
|
|
67
78
|
modelHasSnapshot,
|
|
68
79
|
validateRunRecord
|
|
69
|
-
} from "./chunk-
|
|
80
|
+
} from "./chunk-S3UZOQ5Y.js";
|
|
70
81
|
import {
|
|
71
82
|
buildAgentProfileCell
|
|
72
83
|
} from "./chunk-XJYR7XFV.js";
|
|
73
84
|
import {
|
|
74
85
|
canonicalize
|
|
75
86
|
} from "./chunk-VSMTAMNK.js";
|
|
76
|
-
import {
|
|
77
|
-
callLlm,
|
|
78
|
-
callLlmJson,
|
|
79
|
-
costReceiptFromLlm,
|
|
80
|
-
costReceiptFromLlmError,
|
|
81
|
-
maximumChargeForLlmRequest
|
|
82
|
-
} from "./chunk-NJC7U437.js";
|
|
83
|
-
import {
|
|
84
|
-
CostAccountingIncompleteError,
|
|
85
|
-
CostLedger
|
|
86
|
-
} from "./chunk-VCTY3W6J.js";
|
|
87
87
|
import {
|
|
88
88
|
AgentEvalError,
|
|
89
89
|
ValidationError
|
|
@@ -7483,6 +7483,45 @@ function gitBytes(git, args, cwd, env) {
|
|
|
7483
7483
|
function gitText(git, args, cwd, env) {
|
|
7484
7484
|
return gitBytes(git, args, cwd, env).toString("utf8").trim();
|
|
7485
7485
|
}
|
|
7486
|
+
function hasRegisteredWorktree(git, repoRoot, path) {
|
|
7487
|
+
const expected = Buffer.from(`worktree ${resolve3(path)}`, "utf8");
|
|
7488
|
+
const records = gitBytes(git, ["worktree", "list", "--porcelain", "-z"], repoRoot);
|
|
7489
|
+
let start = 0;
|
|
7490
|
+
while (start < records.length) {
|
|
7491
|
+
const end = records.indexOf(0, start);
|
|
7492
|
+
if (end < 0) {
|
|
7493
|
+
throw new WorktreeAdapterError("Git worktree list output was not NUL-terminated");
|
|
7494
|
+
}
|
|
7495
|
+
if (records.subarray(start, end).equals(expected)) return true;
|
|
7496
|
+
start = end + 1;
|
|
7497
|
+
}
|
|
7498
|
+
return false;
|
|
7499
|
+
}
|
|
7500
|
+
function hasLocalBranch(git, repoRoot, branch) {
|
|
7501
|
+
const ref = `refs/heads/${branch}`;
|
|
7502
|
+
return gitText(git, ["for-each-ref", "--format=%(refname)", "--", ref], repoRoot).split("\n").some((candidate) => candidate === ref);
|
|
7503
|
+
}
|
|
7504
|
+
function reconcileAbsent(exists, remove) {
|
|
7505
|
+
try {
|
|
7506
|
+
if (!exists()) return void 0;
|
|
7507
|
+
} catch (err) {
|
|
7508
|
+
return err;
|
|
7509
|
+
}
|
|
7510
|
+
try {
|
|
7511
|
+
remove();
|
|
7512
|
+
return void 0;
|
|
7513
|
+
} catch (removeError) {
|
|
7514
|
+
try {
|
|
7515
|
+
if (!exists()) return void 0;
|
|
7516
|
+
} catch (recheckError) {
|
|
7517
|
+
return new AggregateError(
|
|
7518
|
+
[removeError, recheckError],
|
|
7519
|
+
"Removal failed and the resulting resource state could not be checked"
|
|
7520
|
+
);
|
|
7521
|
+
}
|
|
7522
|
+
return removeError;
|
|
7523
|
+
}
|
|
7524
|
+
}
|
|
7486
7525
|
function sha2562(bytes) {
|
|
7487
7526
|
return `sha256:${createHash8("sha256").update(bytes).digest("hex")}`;
|
|
7488
7527
|
}
|
|
@@ -7947,8 +7986,23 @@ function gitWorktreeAdapter(opts) {
|
|
|
7947
7986
|
return surface;
|
|
7948
7987
|
},
|
|
7949
7988
|
async discard(worktree) {
|
|
7950
|
-
|
|
7951
|
-
|
|
7989
|
+
const failures = [
|
|
7990
|
+
reconcileAbsent(
|
|
7991
|
+
() => hasRegisteredWorktree(git, opts.repoRoot, worktree.path),
|
|
7992
|
+
() => gitText(git, ["worktree", "remove", "--force", "--", worktree.path], opts.repoRoot)
|
|
7993
|
+
),
|
|
7994
|
+
reconcileAbsent(
|
|
7995
|
+
() => hasLocalBranch(git, opts.repoRoot, worktree.branch),
|
|
7996
|
+
() => gitText(git, ["branch", "-D", "--", worktree.branch], opts.repoRoot)
|
|
7997
|
+
)
|
|
7998
|
+
].filter((failure) => failure !== void 0);
|
|
7999
|
+
if (failures.length > 0) {
|
|
8000
|
+
const cause = failures.length === 1 ? failures[0] : new AggregateError(failures, "Multiple Git resources could not be removed");
|
|
8001
|
+
throw new WorktreeAdapterError(
|
|
8002
|
+
`Failed to discard worktree ${worktree.path} and branch ${worktree.branch}`,
|
|
8003
|
+
cause
|
|
8004
|
+
);
|
|
8005
|
+
}
|
|
7952
8006
|
}
|
|
7953
8007
|
};
|
|
7954
8008
|
}
|
|
@@ -8044,4 +8098,4 @@ export {
|
|
|
8044
8098
|
verifyCodeSurface,
|
|
8045
8099
|
resolveWorktreePath
|
|
8046
8100
|
};
|
|
8047
|
-
//# sourceMappingURL=chunk-
|
|
8101
|
+
//# sourceMappingURL=chunk-Q442S5AS.js.map
|