@vercel/agent-eval 2.4.1 → 2.6.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/dist/cli.js +27 -21
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +8 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -2
- package/dist/index.js.map +1 -1
- package/dist/lib/agents/claude-code/agent.d.ts.map +1 -1
- package/dist/lib/agents/claude-code/agent.js +5 -1
- package/dist/lib/agents/claude-code/agent.js.map +1 -1
- package/dist/lib/agents/codex/agent.d.ts.map +1 -1
- package/dist/lib/agents/codex/agent.js +5 -1
- package/dist/lib/agents/codex/agent.js.map +1 -1
- package/dist/lib/agents/cursor/agent.d.ts.map +1 -1
- package/dist/lib/agents/cursor/agent.js +5 -0
- package/dist/lib/agents/cursor/agent.js.map +1 -1
- package/dist/lib/agents/fx/agent.d.ts.map +1 -1
- package/dist/lib/agents/fx/agent.js +3 -0
- package/dist/lib/agents/fx/agent.js.map +1 -1
- package/dist/lib/agents/fx/run.mjs +26 -0
- package/dist/lib/agents/gemini/agent.d.ts.map +1 -1
- package/dist/lib/agents/gemini/agent.js +5 -1
- package/dist/lib/agents/gemini/agent.js.map +1 -1
- package/dist/lib/agents/index.d.ts +1 -0
- package/dist/lib/agents/index.d.ts.map +1 -1
- package/dist/lib/agents/index.js +4 -0
- package/dist/lib/agents/index.js.map +1 -1
- package/dist/lib/agents/opencode/agent.d.ts.map +1 -1
- package/dist/lib/agents/opencode/agent.js +6 -0
- package/dist/lib/agents/opencode/agent.js.map +1 -1
- package/dist/lib/agents/pi-coding-agent/agent.d.ts +61 -0
- package/dist/lib/agents/pi-coding-agent/agent.d.ts.map +1 -0
- package/dist/lib/agents/pi-coding-agent/agent.js +127 -0
- package/dist/lib/agents/pi-coding-agent/agent.js.map +1 -0
- package/dist/lib/agents/pi-coding-agent/run.mjs +278 -0
- package/dist/lib/agents/plugin/contract.d.ts +40 -0
- package/dist/lib/agents/plugin/contract.d.ts.map +1 -1
- package/dist/lib/agents/plugin/contract.js.map +1 -1
- package/dist/lib/agents/plugin/orchestrator.d.ts +19 -0
- package/dist/lib/agents/plugin/orchestrator.d.ts.map +1 -1
- package/dist/lib/agents/plugin/orchestrator.js +269 -53
- package/dist/lib/agents/plugin/orchestrator.js.map +1 -1
- package/dist/lib/agents/redact.d.ts +34 -3
- package/dist/lib/agents/redact.d.ts.map +1 -1
- package/dist/lib/agents/redact.js +148 -35
- package/dist/lib/agents/redact.js.map +1 -1
- package/dist/lib/agents/shared.d.ts +24 -1
- package/dist/lib/agents/shared.d.ts.map +1 -1
- package/dist/lib/agents/shared.js +48 -13
- package/dist/lib/agents/shared.js.map +1 -1
- package/dist/lib/agents/types.d.ts +24 -1
- package/dist/lib/agents/types.d.ts.map +1 -1
- package/dist/lib/agents/verifier.d.ts +96 -0
- package/dist/lib/agents/verifier.d.ts.map +1 -0
- package/dist/lib/agents/verifier.js +176 -0
- package/dist/lib/agents/verifier.js.map +1 -0
- package/dist/lib/config.d.ts.map +1 -1
- package/dist/lib/config.js +24 -0
- package/dist/lib/config.js.map +1 -1
- package/dist/lib/dashboard.d.ts +3 -1
- package/dist/lib/dashboard.d.ts.map +1 -1
- package/dist/lib/dashboard.js +12 -1
- package/dist/lib/dashboard.js.map +1 -1
- package/dist/lib/docker-sandbox.d.ts +9 -0
- package/dist/lib/docker-sandbox.d.ts.map +1 -1
- package/dist/lib/docker-sandbox.js +15 -0
- package/dist/lib/docker-sandbox.js.map +1 -1
- package/dist/lib/fingerprint.d.ts +3 -0
- package/dist/lib/fingerprint.d.ts.map +1 -1
- package/dist/lib/fingerprint.js +34 -0
- package/dist/lib/fingerprint.js.map +1 -1
- package/dist/lib/o11y/index.d.ts +3 -2
- package/dist/lib/o11y/index.d.ts.map +1 -1
- package/dist/lib/o11y/index.js +2 -1
- package/dist/lib/o11y/index.js.map +1 -1
- package/dist/lib/o11y/parsers/claude-code.d.ts +19 -1
- package/dist/lib/o11y/parsers/claude-code.d.ts.map +1 -1
- package/dist/lib/o11y/parsers/claude-code.js +72 -1
- package/dist/lib/o11y/parsers/claude-code.js.map +1 -1
- package/dist/lib/o11y/parsers/codex.d.ts +13 -1
- package/dist/lib/o11y/parsers/codex.d.ts.map +1 -1
- package/dist/lib/o11y/parsers/codex.js +68 -1
- package/dist/lib/o11y/parsers/codex.js.map +1 -1
- package/dist/lib/o11y/parsers/fx.d.ts +2 -1
- package/dist/lib/o11y/parsers/fx.d.ts.map +1 -1
- package/dist/lib/o11y/parsers/fx.js +21 -1
- package/dist/lib/o11y/parsers/fx.js.map +1 -1
- package/dist/lib/o11y/parsers/gemini.d.ts +13 -1
- package/dist/lib/o11y/parsers/gemini.d.ts.map +1 -1
- package/dist/lib/o11y/parsers/gemini.js +35 -1
- package/dist/lib/o11y/parsers/gemini.js.map +1 -1
- package/dist/lib/o11y/parsers/index.d.ts +9 -2
- package/dist/lib/o11y/parsers/index.d.ts.map +1 -1
- package/dist/lib/o11y/parsers/index.js +15 -1
- package/dist/lib/o11y/parsers/index.js.map +1 -1
- package/dist/lib/o11y/parsers/opencode.d.ts +17 -1
- package/dist/lib/o11y/parsers/opencode.d.ts.map +1 -1
- package/dist/lib/o11y/parsers/opencode.js +47 -4
- package/dist/lib/o11y/parsers/opencode.js.map +1 -1
- package/dist/lib/o11y/parsers/pi-coding-agent.d.ts +22 -0
- package/dist/lib/o11y/parsers/pi-coding-agent.d.ts.map +1 -0
- package/dist/lib/o11y/parsers/pi-coding-agent.js +217 -0
- package/dist/lib/o11y/parsers/pi-coding-agent.js.map +1 -0
- package/dist/lib/o11y/types.d.ts +30 -0
- package/dist/lib/o11y/types.d.ts.map +1 -1
- package/dist/lib/o11y/usage.d.ts +27 -0
- package/dist/lib/o11y/usage.d.ts.map +1 -0
- package/dist/lib/o11y/usage.js +75 -0
- package/dist/lib/o11y/usage.js.map +1 -0
- package/dist/lib/reporters.d.ts +101 -0
- package/dist/lib/reporters.d.ts.map +1 -0
- package/dist/lib/reporters.js +176 -0
- package/dist/lib/reporters.js.map +1 -0
- package/dist/lib/results.d.ts +15 -2
- package/dist/lib/results.d.ts.map +1 -1
- package/dist/lib/results.js +75 -4
- package/dist/lib/results.js.map +1 -1
- package/dist/lib/runner.d.ts +16 -1
- package/dist/lib/runner.d.ts.map +1 -1
- package/dist/lib/runner.js +85 -3
- package/dist/lib/runner.js.map +1 -1
- package/dist/lib/sandbox.d.ts +9 -0
- package/dist/lib/sandbox.d.ts.map +1 -1
- package/dist/lib/sandbox.js +14 -1
- package/dist/lib/sandbox.js.map +1 -1
- package/dist/lib/types.d.ts +185 -1
- package/dist/lib/types.d.ts.map +1 -1
- package/dist/lib/types.js.map +1 -1
- package/dist/lib/version.d.ts +7 -0
- package/dist/lib/version.d.ts.map +1 -0
- package/dist/lib/version.js +8 -0
- package/dist/lib/version.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parser for the PI coding agent transcript format (`pi --mode json`).
|
|
3
|
+
*
|
|
4
|
+
* The transcript is JSONL of PI session events. Everything we need rides on
|
|
5
|
+
* `message_end`, whose `message` is one of:
|
|
6
|
+
* - role 'user' → the prompt
|
|
7
|
+
* - role 'assistant' → content blocks: text | thinking | toolCall
|
|
8
|
+
* - role 'toolResult' → the result of one toolCall (isError, content blocks)
|
|
9
|
+
*
|
|
10
|
+
* The runner already strips the streaming duplicates (`message_update`,
|
|
11
|
+
* `turn_end`, `agent_end`, …), but they are ignored here too, so a raw
|
|
12
|
+
* unfiltered stream parses to the same events without double counting.
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* Map PI tool names to canonical names.
|
|
16
|
+
*/
|
|
17
|
+
function normalizeToolName(name) {
|
|
18
|
+
const toolMap = {
|
|
19
|
+
read: 'file_read',
|
|
20
|
+
write: 'file_write',
|
|
21
|
+
edit: 'file_edit',
|
|
22
|
+
bash: 'shell',
|
|
23
|
+
grep: 'grep',
|
|
24
|
+
find: 'glob',
|
|
25
|
+
ls: 'list_dir',
|
|
26
|
+
};
|
|
27
|
+
return toolMap[name.toLowerCase()] || 'unknown';
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Convert PI's epoch-millisecond timestamps to ISO strings.
|
|
31
|
+
*/
|
|
32
|
+
function toISO(ts) {
|
|
33
|
+
if (typeof ts === 'number')
|
|
34
|
+
return new Date(ts).toISOString();
|
|
35
|
+
if (typeof ts === 'string')
|
|
36
|
+
return ts;
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Join the text blocks of a PI content value (a string or an array of blocks).
|
|
41
|
+
*/
|
|
42
|
+
function extractText(content) {
|
|
43
|
+
if (typeof content === 'string')
|
|
44
|
+
return content;
|
|
45
|
+
if (!Array.isArray(content))
|
|
46
|
+
return '';
|
|
47
|
+
return content
|
|
48
|
+
.filter((block) => block?.type === 'text' && typeof block.text === 'string')
|
|
49
|
+
.map((block) => block.text)
|
|
50
|
+
.join('\n');
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* PI's bash tool reports a non-zero exit as a trailing "Command exited with code N"
|
|
54
|
+
* line in the result text, and nothing at all on success — so the suffix only
|
|
55
|
+
* means something on a failed result (a successful command may print that text).
|
|
56
|
+
*/
|
|
57
|
+
function extractExitCode(text, success) {
|
|
58
|
+
if (success)
|
|
59
|
+
return 0;
|
|
60
|
+
const match = text.match(/Command exited with code (\d+)\s*$/);
|
|
61
|
+
return match ? Number(match[1]) : undefined;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Move each tool result directly after the call it answers.
|
|
65
|
+
*
|
|
66
|
+
* PI emits one assistant message carrying ALL its tool calls, then the results
|
|
67
|
+
* (`call A, call B, result A, result B`). The shared summary — like the other
|
|
68
|
+
* parsers' output — expects a result to follow its own call, so pair them by
|
|
69
|
+
* PI's toolCallId. Results with no matching call keep their position.
|
|
70
|
+
*/
|
|
71
|
+
function pairToolResults(events) {
|
|
72
|
+
const ordered = [];
|
|
73
|
+
const openCalls = new Map();
|
|
74
|
+
for (const event of events) {
|
|
75
|
+
if (event.type === 'tool_call') {
|
|
76
|
+
const id = event.raw?.id;
|
|
77
|
+
if (typeof id === 'string')
|
|
78
|
+
openCalls.set(id, event);
|
|
79
|
+
}
|
|
80
|
+
else if (event.type === 'tool_result') {
|
|
81
|
+
const id = event.raw?.message?.toolCallId;
|
|
82
|
+
const call = typeof id === 'string' ? openCalls.get(id) : undefined;
|
|
83
|
+
if (call) {
|
|
84
|
+
openCalls.delete(id);
|
|
85
|
+
ordered.splice(ordered.indexOf(call) + 1, 0, event);
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
ordered.push(event);
|
|
90
|
+
}
|
|
91
|
+
return ordered;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Parse a single JSONL line from a PI transcript.
|
|
95
|
+
*/
|
|
96
|
+
function parsePiLine(line) {
|
|
97
|
+
const events = [];
|
|
98
|
+
try {
|
|
99
|
+
const data = JSON.parse(line);
|
|
100
|
+
if (data.type === 'auto_retry_end' && data.success === false) {
|
|
101
|
+
events.push({
|
|
102
|
+
type: 'error',
|
|
103
|
+
content: data.finalError || 'PI exhausted its retries',
|
|
104
|
+
raw: data,
|
|
105
|
+
});
|
|
106
|
+
return events;
|
|
107
|
+
}
|
|
108
|
+
if (data.type !== 'message_end' || !data.message) {
|
|
109
|
+
// session, agent/turn lifecycle, tool_execution_*, compaction, streaming
|
|
110
|
+
// deltas — nothing the message_end events don't already carry.
|
|
111
|
+
return events;
|
|
112
|
+
}
|
|
113
|
+
const message = data.message;
|
|
114
|
+
const timestamp = toISO(message.timestamp);
|
|
115
|
+
if (message.role === 'user') {
|
|
116
|
+
const text = extractText(message.content);
|
|
117
|
+
if (text.trim()) {
|
|
118
|
+
events.push({ timestamp, type: 'message', role: 'user', content: text, raw: data });
|
|
119
|
+
}
|
|
120
|
+
return events;
|
|
121
|
+
}
|
|
122
|
+
if (message.role === 'assistant') {
|
|
123
|
+
const blocks = Array.isArray(message.content) ? message.content : [];
|
|
124
|
+
for (const block of blocks) {
|
|
125
|
+
if (block?.type === 'thinking' && typeof block.thinking === 'string' && block.thinking.trim()) {
|
|
126
|
+
events.push({ timestamp, type: 'thinking', content: block.thinking, raw: block });
|
|
127
|
+
}
|
|
128
|
+
else if (block?.type === 'toolCall') {
|
|
129
|
+
const name = block.name || 'unknown';
|
|
130
|
+
events.push({
|
|
131
|
+
timestamp,
|
|
132
|
+
type: 'tool_call',
|
|
133
|
+
tool: {
|
|
134
|
+
name: normalizeToolName(name),
|
|
135
|
+
originalName: name,
|
|
136
|
+
args: block.arguments || {},
|
|
137
|
+
},
|
|
138
|
+
raw: block,
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
// One message event per assistant message (= one turn), even when it only
|
|
143
|
+
// carries tool calls.
|
|
144
|
+
events.push({
|
|
145
|
+
timestamp,
|
|
146
|
+
type: 'message',
|
|
147
|
+
role: 'assistant',
|
|
148
|
+
content: extractText(blocks),
|
|
149
|
+
raw: data,
|
|
150
|
+
});
|
|
151
|
+
if (message.stopReason === 'error' || message.stopReason === 'aborted') {
|
|
152
|
+
events.push({
|
|
153
|
+
timestamp,
|
|
154
|
+
type: 'error',
|
|
155
|
+
content: message.errorMessage || `PI stopped with reason "${message.stopReason}"`,
|
|
156
|
+
raw: data,
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
return events;
|
|
160
|
+
}
|
|
161
|
+
if (message.role === 'toolResult') {
|
|
162
|
+
const name = message.toolName || 'unknown';
|
|
163
|
+
const toolName = normalizeToolName(name);
|
|
164
|
+
const text = extractText(message.content);
|
|
165
|
+
const success = message.isError !== true;
|
|
166
|
+
events.push({
|
|
167
|
+
timestamp,
|
|
168
|
+
type: 'tool_result',
|
|
169
|
+
tool: {
|
|
170
|
+
name: toolName,
|
|
171
|
+
originalName: name,
|
|
172
|
+
result: toolName === 'shell' ? { output: text, exitCode: extractExitCode(text, success) } : text,
|
|
173
|
+
success,
|
|
174
|
+
},
|
|
175
|
+
raw: data,
|
|
176
|
+
});
|
|
177
|
+
return events;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
catch {
|
|
181
|
+
// Skip unparseable lines
|
|
182
|
+
}
|
|
183
|
+
return events;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Parse PI JSONL transcript into normalized events.
|
|
187
|
+
*/
|
|
188
|
+
export function parsePiCodingAgentTranscript(raw) {
|
|
189
|
+
const parsed = [];
|
|
190
|
+
const errors = [];
|
|
191
|
+
const lines = raw.split('\n').filter((line) => line.trim());
|
|
192
|
+
for (const line of lines) {
|
|
193
|
+
try {
|
|
194
|
+
parsed.push(...parsePiLine(line));
|
|
195
|
+
}
|
|
196
|
+
catch (e) {
|
|
197
|
+
errors.push(`Failed to parse line: ${e instanceof Error ? e.message : String(e)}`);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
const events = pairToolResults(parsed);
|
|
201
|
+
// Post-process: extract metadata into tool args
|
|
202
|
+
for (const event of events) {
|
|
203
|
+
if (event.type === 'tool_call' && event.tool) {
|
|
204
|
+
const args = event.tool.args || {};
|
|
205
|
+
if (['file_read', 'file_write', 'file_edit'].includes(event.tool.name)) {
|
|
206
|
+
if (typeof args.path === 'string') {
|
|
207
|
+
event.tool.args = { ...args, _extractedPath: args.path };
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
if (event.tool.name === 'shell' && typeof args.command === 'string') {
|
|
211
|
+
event.tool.args = { ...args, _extractedCommand: args.command };
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
return { events, errors };
|
|
216
|
+
}
|
|
217
|
+
//# sourceMappingURL=pi-coding-agent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pi-coding-agent.js","sourceRoot":"","sources":["../../../../src/lib/o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**
|
|
74
|
+
* Token usage for one agent run, read from what the agent CLI itself reports.
|
|
75
|
+
*
|
|
76
|
+
* Every field is optional: a field is set only when the transcript exposes it,
|
|
77
|
+
* and nothing is estimated or derived from a price table. Agent CLIs count
|
|
78
|
+
* tokens differently, so compare `totalTokens` across agents and treat the
|
|
79
|
+
* per-component fields as each CLI reports them (see the README's per-agent
|
|
80
|
+
* table).
|
|
81
|
+
*/
|
|
82
|
+
export interface TokenUsage {
|
|
83
|
+
/** Prompt tokens. Excludes cache reads and writes when the CLI reports those
|
|
84
|
+
* separately; otherwise the CLI's full prompt count. */
|
|
85
|
+
inputTokens?: number;
|
|
86
|
+
/** Generated tokens, as the CLI counts them. */
|
|
87
|
+
outputTokens?: number;
|
|
88
|
+
/** Prompt tokens served from the provider's prompt cache. */
|
|
89
|
+
cacheReadTokens?: number;
|
|
90
|
+
/** Prompt tokens written to the provider's prompt cache. */
|
|
91
|
+
cacheWriteTokens?: number;
|
|
92
|
+
/** Reasoning tokens, when the CLI reports them separately. */
|
|
93
|
+
reasoningTokens?: number;
|
|
94
|
+
/** The CLI's own total, or the sum of the input, cache, and output counts
|
|
95
|
+
* when the CLI reports non-overlapping counts but no total. */
|
|
96
|
+
totalTokens?: number;
|
|
97
|
+
/** Only when the agent CLI itself reports a cost. Never computed from a price table. */
|
|
98
|
+
costUsd?: number;
|
|
99
|
+
}
|
|
73
100
|
/**
|
|
74
101
|
* Summary statistics derived from the transcript.
|
|
75
102
|
*/
|
|
@@ -92,6 +119,9 @@ export interface TranscriptSummary {
|
|
|
92
119
|
errors: string[];
|
|
93
120
|
/** Thinking/reasoning blocks (if available) */
|
|
94
121
|
thinkingBlocks: number;
|
|
122
|
+
/** Token usage of the code-generation run, when the transcript reports it.
|
|
123
|
+
* Judge assertions run separately and are not included. */
|
|
124
|
+
usage?: TokenUsage;
|
|
95
125
|
}
|
|
96
126
|
/**
|
|
97
127
|
* A parsed transcript with events and summary.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{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C,YAAY,EAAE,OAAO,CAAC;IAEtB,kCAAkC;IAClC,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;CACxB"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared helpers for reading token usage out of agent transcripts.
|
|
3
|
+
*
|
|
4
|
+
* Each parser owns the knowledge of where its CLI reports usage; these helpers
|
|
5
|
+
* only keep the arithmetic consistent: counts must be finite and non-negative,
|
|
6
|
+
* a sum is reported only when every part of it was reported, and a usage object
|
|
7
|
+
* with nothing in it is undefined rather than a row of zeros.
|
|
8
|
+
*/
|
|
9
|
+
import type { TokenUsage } from './types.js';
|
|
10
|
+
/** The usage fields that hold token counts (everything except cost). */
|
|
11
|
+
export declare const TOKEN_COUNT_FIELDS: readonly ["inputTokens", "outputTokens", "cacheReadTokens", "cacheWriteTokens", "reasoningTokens", "totalTokens"];
|
|
12
|
+
/** A reported count: a finite, non-negative number. Anything else is unreported. */
|
|
13
|
+
export declare function reportedNumber(value: unknown): number | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* Sum values that must all be reported. One missing value makes the sum
|
|
16
|
+
* undefined, because a partial sum would understate the real figure.
|
|
17
|
+
*/
|
|
18
|
+
export declare function sumReported(values: readonly (number | undefined)[]): number | undefined;
|
|
19
|
+
/** Sum each field of several usage records with {@link sumReported} semantics. */
|
|
20
|
+
export declare function sumUsage(records: readonly TokenUsage[]): TokenUsage | undefined;
|
|
21
|
+
/** Drop unreported fields. Returns undefined when no field was reported. */
|
|
22
|
+
export declare function compactUsage(usage: TokenUsage): TokenUsage | undefined;
|
|
23
|
+
/** Parse one JSONL line into an object, or undefined for anything else. */
|
|
24
|
+
export declare function parseJsonLine(line: string): Record<string, unknown> | undefined;
|
|
25
|
+
/** Narrow an unknown value to a plain object. */
|
|
26
|
+
export declare function asRecord(value: unknown): Record<string, unknown> | undefined;
|
|
27
|
+
//# sourceMappingURL=usage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usage.d.ts","sourceRoot":"","sources":["../../../src/lib/o11y/usage.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C,wEAAwE;AACxE,eAAO,MAAM,kBAAkB,mHAOmB,CAAC;AAEnD,oFAAoF;AACpF,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAEjE;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,SAAS,CAAC,MAAM,GAAG,SAAS,CAAC,EAAE,GAAG,MAAM,GAAG,SAAS,CAQvF;AAED,kFAAkF;AAClF,wBAAgB,QAAQ,CAAC,OAAO,EAAE,SAAS,UAAU,EAAE,GAAG,UAAU,GAAG,SAAS,CAO/E;AAED,4EAA4E;AAC5E,wBAAgB,YAAY,CAAC,KAAK,EAAE,UAAU,GAAG,UAAU,GAAG,SAAS,CAMtE;AAED,2EAA2E;AAC3E,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAS/E;AAED,iDAAiD;AACjD,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAI5E"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared helpers for reading token usage out of agent transcripts.
|
|
3
|
+
*
|
|
4
|
+
* Each parser owns the knowledge of where its CLI reports usage; these helpers
|
|
5
|
+
* only keep the arithmetic consistent: counts must be finite and non-negative,
|
|
6
|
+
* a sum is reported only when every part of it was reported, and a usage object
|
|
7
|
+
* with nothing in it is undefined rather than a row of zeros.
|
|
8
|
+
*/
|
|
9
|
+
/** The usage fields that hold token counts (everything except cost). */
|
|
10
|
+
export const TOKEN_COUNT_FIELDS = [
|
|
11
|
+
'inputTokens',
|
|
12
|
+
'outputTokens',
|
|
13
|
+
'cacheReadTokens',
|
|
14
|
+
'cacheWriteTokens',
|
|
15
|
+
'reasoningTokens',
|
|
16
|
+
'totalTokens',
|
|
17
|
+
];
|
|
18
|
+
/** A reported count: a finite, non-negative number. Anything else is unreported. */
|
|
19
|
+
export function reportedNumber(value) {
|
|
20
|
+
return typeof value === 'number' && Number.isFinite(value) && value >= 0 ? value : undefined;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Sum values that must all be reported. One missing value makes the sum
|
|
24
|
+
* undefined, because a partial sum would understate the real figure.
|
|
25
|
+
*/
|
|
26
|
+
export function sumReported(values) {
|
|
27
|
+
if (values.length === 0)
|
|
28
|
+
return undefined;
|
|
29
|
+
let total = 0;
|
|
30
|
+
for (const value of values) {
|
|
31
|
+
if (value === undefined)
|
|
32
|
+
return undefined;
|
|
33
|
+
total += value;
|
|
34
|
+
}
|
|
35
|
+
return total;
|
|
36
|
+
}
|
|
37
|
+
/** Sum each field of several usage records with {@link sumReported} semantics. */
|
|
38
|
+
export function sumUsage(records) {
|
|
39
|
+
if (records.length === 0)
|
|
40
|
+
return undefined;
|
|
41
|
+
const summed = {};
|
|
42
|
+
for (const field of [...TOKEN_COUNT_FIELDS, 'costUsd']) {
|
|
43
|
+
summed[field] = sumReported(records.map((record) => record[field]));
|
|
44
|
+
}
|
|
45
|
+
return compactUsage(summed);
|
|
46
|
+
}
|
|
47
|
+
/** Drop unreported fields. Returns undefined when no field was reported. */
|
|
48
|
+
export function compactUsage(usage) {
|
|
49
|
+
const compacted = {};
|
|
50
|
+
for (const [field, value] of Object.entries(usage)) {
|
|
51
|
+
if (value !== undefined)
|
|
52
|
+
compacted[field] = value;
|
|
53
|
+
}
|
|
54
|
+
return Object.keys(compacted).length > 0 ? compacted : undefined;
|
|
55
|
+
}
|
|
56
|
+
/** Parse one JSONL line into an object, or undefined for anything else. */
|
|
57
|
+
export function parseJsonLine(line) {
|
|
58
|
+
const trimmed = line.trim();
|
|
59
|
+
if (!trimmed.startsWith('{'))
|
|
60
|
+
return undefined;
|
|
61
|
+
try {
|
|
62
|
+
const value = JSON.parse(trimmed);
|
|
63
|
+
return asRecord(value);
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
return undefined;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/** Narrow an unknown value to a plain object. */
|
|
70
|
+
export function asRecord(value) {
|
|
71
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value)
|
|
72
|
+
? value
|
|
73
|
+
: undefined;
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=usage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usage.js","sourceRoot":"","sources":["../../../src/lib/o11y/usage.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,wEAAwE;AACxE,MAAM,CAAC,MAAM,kBAAkB,GAAG;IAChC,aAAa;IACb,cAAc;IACd,iBAAiB;IACjB,kBAAkB;IAClB,iBAAiB;IACjB,aAAa;CACmC,CAAC;AAEnD,oFAAoF;AACpF,MAAM,UAAU,cAAc,CAAC,KAAc;IAC3C,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;AAC/F,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAC,MAAuC;IACjE,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,SAAS,CAAC;IAC1C,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,IAAI,KAAK,KAAK,SAAS;YAAE,OAAO,SAAS,CAAC;QAC1C,KAAK,IAAI,KAAK,CAAC;IACjB,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,kFAAkF;A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AACH,CAAC;AAED,iDAAiD;AACjD,MAAM,UAAU,QAAQ,CAAC,KAAc;IACrC,OAAO,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QACzE,CAAC,CAAE,KAAiC;QACpC,CAAC,CAAC,SAAS,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reporters: first-class hooks that send results somewhere besides the local
|
|
3
|
+
* results/ tree.
|
|
4
|
+
*
|
|
5
|
+
* The runner calls {@link notifyRunComplete} once per finished run and
|
|
6
|
+
* {@link notifyExperimentComplete} once per experiment. Both isolate reporter
|
|
7
|
+
* failures: an error is caught, redacted, handed to `onFailure`, and the next
|
|
8
|
+
* reporter still runs. Nothing a reporter does can change an eval result.
|
|
9
|
+
*/
|
|
10
|
+
import type { ProgressEvent, Reporter, ReporterExperimentEvent, ReporterRunEvent } from './types.js';
|
|
11
|
+
/** One reporter call that threw or rejected. */
|
|
12
|
+
export interface ReporterFailure {
|
|
13
|
+
/** Name of the reporter that failed. */
|
|
14
|
+
reporter: string;
|
|
15
|
+
/** Which hook failed. */
|
|
16
|
+
hook: 'onRunComplete' | 'onExperimentComplete';
|
|
17
|
+
/** Set for run events. */
|
|
18
|
+
evalName?: string;
|
|
19
|
+
/** Zero-based attempt index, set for run events. */
|
|
20
|
+
runIndex?: number;
|
|
21
|
+
/** The error message, redacted. */
|
|
22
|
+
error: string;
|
|
23
|
+
}
|
|
24
|
+
/** How to deliver an event to a list of reporters. */
|
|
25
|
+
export interface ReporterDispatchOptions {
|
|
26
|
+
/** Credentials to scrub from the payload and from error messages. */
|
|
27
|
+
secrets: readonly (string | undefined)[];
|
|
28
|
+
/** Called for each reporter call that fails. */
|
|
29
|
+
onFailure?: (failure: ReporterFailure) => void;
|
|
30
|
+
}
|
|
31
|
+
/** One line describing a failed reporter call, for the CLI and logs. */
|
|
32
|
+
export declare function formatReporterError(event: Extract<ProgressEvent, {
|
|
33
|
+
type: 'reporter:error';
|
|
34
|
+
}>): string;
|
|
35
|
+
/**
|
|
36
|
+
* Deliver a run event to every reporter with an `onRunComplete` hook, in order.
|
|
37
|
+
* Returns the failures (also passed to `onFailure`).
|
|
38
|
+
*/
|
|
39
|
+
export declare function notifyRunComplete(reporters: readonly Reporter[], event: ReporterRunEvent, options: ReporterDispatchOptions): Promise<ReporterFailure[]>;
|
|
40
|
+
/**
|
|
41
|
+
* Deliver an experiment event to every reporter with an
|
|
42
|
+
* `onExperimentComplete` hook, in order. Returns the failures (also passed to
|
|
43
|
+
* `onFailure`).
|
|
44
|
+
*/
|
|
45
|
+
export declare function notifyExperimentComplete(reporters: readonly Reporter[], event: ReporterExperimentEvent, options: ReporterDispatchOptions): Promise<ReporterFailure[]>;
|
|
46
|
+
/**
|
|
47
|
+
* The JSON form of an experiment event used by the built-in reporters.
|
|
48
|
+
*
|
|
49
|
+
* `results` in a {@link ReporterExperimentEvent} carries everything the run
|
|
50
|
+
* produced: transcripts, script output, and generated files as raw bytes. A
|
|
51
|
+
* network payload doesn't need those (they're on disk under `outputDir`), so
|
|
52
|
+
* each run is reduced to its `result`. Config functions and the reporters
|
|
53
|
+
* themselves are left out too, since they aren't data.
|
|
54
|
+
*/
|
|
55
|
+
export declare function experimentEventToJson(event: ReporterExperimentEvent): Record<string, unknown>;
|
|
56
|
+
/** Options for {@link jsonlReporter}. */
|
|
57
|
+
export interface JsonlReporterOptions {
|
|
58
|
+
/** File to append to. Parent directories are created. */
|
|
59
|
+
path: string;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Append one JSON line per finished run to a file. Each line is a
|
|
63
|
+
* {@link ReporterRunEvent}. Writes are serialized, so concurrent runs never
|
|
64
|
+
* interleave lines.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```ts
|
|
68
|
+
* reporters: [jsonlReporter({ path: 'results/runs.jsonl' })]
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
export declare function jsonlReporter(options: JsonlReporterOptions): Reporter;
|
|
72
|
+
/** Options for {@link httpReporter}. */
|
|
73
|
+
export interface HttpReporterOptions {
|
|
74
|
+
/** Endpoint that receives a JSON POST per event. */
|
|
75
|
+
url: string;
|
|
76
|
+
/** Extra request headers, for example an authorization header. */
|
|
77
|
+
headers?: Record<string, string>;
|
|
78
|
+
/** Retries after the first attempt for network errors, 429, and 5xx responses. @default 2 */
|
|
79
|
+
retries?: number;
|
|
80
|
+
/** Delay before the first retry, doubled for each later one. @default 500 */
|
|
81
|
+
retryDelayMs?: number;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* POST each event as JSON. Run events are sent as
|
|
85
|
+
* `{ "type": "run", ...ReporterRunEvent }`; experiment events as
|
|
86
|
+
* `{ "type": "experiment", ...experimentEventToJson(event) }`. Network errors,
|
|
87
|
+
* 429, and 5xx responses are retried with exponential backoff; other non-2xx
|
|
88
|
+
* responses fail at once.
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* ```ts
|
|
92
|
+
* reporters: [
|
|
93
|
+
* httpReporter({
|
|
94
|
+
* url: 'https://example.com/ingest',
|
|
95
|
+
* headers: { authorization: `Bearer ${process.env.INGEST_TOKEN}` },
|
|
96
|
+
* }),
|
|
97
|
+
* ]
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
export declare function httpReporter(options: HttpReporterOptions): Reporter;
|
|
101
|
+
//# sourceMappingURL=reporters.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reporters.d.ts","sourceRoot":"","sources":["../../src/lib/reporters.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,OAAO,KAAK,EACV,aAAa,EACb,QAAQ,EACR,uBAAuB,EACvB,gBAAgB,EACjB,MAAM,YAAY,CAAC;AAGpB,gDAAgD;AAChD,MAAM,WAAW,eAAe;IAC9B,wCAAw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