@cogitator-ai/evals 0.13.2 → 0.14.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/README.md +94 -14
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/plugin-evals/execute.d.ts +45 -0
- package/dist/plugin-evals/execute.d.ts.map +1 -0
- package/dist/plugin-evals/execute.js +508 -0
- package/dist/plugin-evals/execute.js.map +1 -0
- package/dist/plugin-evals/files.d.ts +17 -0
- package/dist/plugin-evals/files.d.ts.map +1 -0
- package/dist/plugin-evals/files.js +46 -0
- package/dist/plugin-evals/files.js.map +1 -0
- package/dist/plugin-evals/glob.d.ts +8 -0
- package/dist/plugin-evals/glob.d.ts.map +1 -0
- package/dist/plugin-evals/glob.js +63 -0
- package/dist/plugin-evals/glob.js.map +1 -0
- package/dist/plugin-evals/graders.d.ts +21 -0
- package/dist/plugin-evals/graders.d.ts.map +1 -0
- package/dist/plugin-evals/graders.js +198 -0
- package/dist/plugin-evals/graders.js.map +1 -0
- package/dist/plugin-evals/index.d.ts +4 -0
- package/dist/plugin-evals/index.d.ts.map +1 -0
- package/dist/plugin-evals/index.js +3 -0
- package/dist/plugin-evals/index.js.map +1 -0
- package/dist/plugin-evals/judge.d.ts +33 -0
- package/dist/plugin-evals/judge.d.ts.map +1 -0
- package/dist/plugin-evals/judge.js +73 -0
- package/dist/plugin-evals/judge.js.map +1 -0
- package/dist/plugin-evals/mocks.d.ts +34 -0
- package/dist/plugin-evals/mocks.d.ts.map +1 -0
- package/dist/plugin-evals/mocks.js +373 -0
- package/dist/plugin-evals/mocks.js.map +1 -0
- package/dist/plugin-evals/report.d.ts +4 -0
- package/dist/plugin-evals/report.d.ts.map +1 -0
- package/dist/plugin-evals/report.js +177 -0
- package/dist/plugin-evals/report.js.map +1 -0
- package/dist/plugin-evals/runner.d.ts +23 -0
- package/dist/plugin-evals/runner.d.ts.map +1 -0
- package/dist/plugin-evals/runner.js +582 -0
- package/dist/plugin-evals/runner.js.map +1 -0
- package/dist/plugin-evals/schema.d.ts +179 -0
- package/dist/plugin-evals/schema.d.ts.map +1 -0
- package/dist/plugin-evals/schema.js +194 -0
- package/dist/plugin-evals/schema.js.map +1 -0
- package/dist/plugin-evals/suite.d.ts +40 -0
- package/dist/plugin-evals/suite.d.ts.map +1 -0
- package/dist/plugin-evals/suite.js +476 -0
- package/dist/plugin-evals/suite.js.map +1 -0
- package/dist/plugin-evals/tools.d.ts +42 -0
- package/dist/plugin-evals/tools.d.ts.map +1 -0
- package/dist/plugin-evals/tools.js +136 -0
- package/dist/plugin-evals/tools.js.map +1 -0
- package/dist/plugin-evals/transcript.d.ts +35 -0
- package/dist/plugin-evals/transcript.d.ts.map +1 -0
- package/dist/plugin-evals/transcript.js +149 -0
- package/dist/plugin-evals/transcript.js.map +1 -0
- package/dist/plugin-evals/types.d.ts +378 -0
- package/dist/plugin-evals/types.d.ts.map +1 -0
- package/dist/plugin-evals/types.js +2 -0
- package/dist/plugin-evals/types.js.map +1 -0
- package/dist/reporters/html-format.d.ts +5 -2
- package/dist/reporters/html-format.d.ts.map +1 -1
- package/dist/reporters/html-format.js +6 -3
- package/dist/reporters/html-format.js.map +1 -1
- package/package.json +5 -3
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { globMatches } from './glob.js';
|
|
2
|
+
/** Claude Code's name of each Cogitator tool an eval run can have */
|
|
3
|
+
const CLAUDE_NAME_OF = {
|
|
4
|
+
read_file: 'Read',
|
|
5
|
+
list_files: 'LS',
|
|
6
|
+
glob: 'Glob',
|
|
7
|
+
grep: 'Grep',
|
|
8
|
+
write_file: 'Write',
|
|
9
|
+
edit_file: 'Edit',
|
|
10
|
+
run_command: 'Bash',
|
|
11
|
+
use_skill: 'Skill',
|
|
12
|
+
write_todos: 'TodoWrite',
|
|
13
|
+
agent: 'Agent',
|
|
14
|
+
send_message: 'SendMessage',
|
|
15
|
+
task_output: 'TaskOutput',
|
|
16
|
+
task_stop: 'TaskStop',
|
|
17
|
+
http_request: 'WebFetch',
|
|
18
|
+
web_search: 'WebSearch',
|
|
19
|
+
};
|
|
20
|
+
/** The Cogitator tools a Claude Code tool name stands for */
|
|
21
|
+
const TOOLS_OF = {
|
|
22
|
+
Read: ['read_file', 'list_files'],
|
|
23
|
+
LS: ['list_files'],
|
|
24
|
+
Glob: ['glob'],
|
|
25
|
+
Grep: ['grep'],
|
|
26
|
+
Write: ['write_file'],
|
|
27
|
+
Edit: ['edit_file'],
|
|
28
|
+
Bash: ['run_command'],
|
|
29
|
+
Skill: ['use_skill', 'read_skill_file'],
|
|
30
|
+
TodoWrite: ['write_todos'],
|
|
31
|
+
Agent: ['agent'],
|
|
32
|
+
Task: ['agent'],
|
|
33
|
+
SendMessage: ['send_message'],
|
|
34
|
+
TaskOutput: ['task_output'],
|
|
35
|
+
TaskStop: ['task_stop'],
|
|
36
|
+
WebFetch: ['http_request'],
|
|
37
|
+
WebSearch: ['web_search'],
|
|
38
|
+
};
|
|
39
|
+
/** The tools a case's `allowed_tools` grants by itself, any other needs a grant of the run */
|
|
40
|
+
export const READ_ONLY_TOOLS = new Set([
|
|
41
|
+
'Read',
|
|
42
|
+
'Glob',
|
|
43
|
+
'Grep',
|
|
44
|
+
'NotebookRead',
|
|
45
|
+
'Skill',
|
|
46
|
+
'AskUserQuestion',
|
|
47
|
+
'Agent',
|
|
48
|
+
'TodoWrite',
|
|
49
|
+
'TaskCreate',
|
|
50
|
+
'TaskGet',
|
|
51
|
+
'TaskList',
|
|
52
|
+
'TaskUpdate',
|
|
53
|
+
'TaskStop',
|
|
54
|
+
]);
|
|
55
|
+
/** Claude Code tools an eval run has no Cogitator counterpart for */
|
|
56
|
+
const NO_COUNTERPART = new Set([
|
|
57
|
+
'NotebookRead',
|
|
58
|
+
'NotebookEdit',
|
|
59
|
+
'MultiEdit',
|
|
60
|
+
'AskUserQuestion',
|
|
61
|
+
'TaskCreate',
|
|
62
|
+
'TaskGet',
|
|
63
|
+
'TaskList',
|
|
64
|
+
'TaskUpdate',
|
|
65
|
+
'PowerShell',
|
|
66
|
+
'BashOutput',
|
|
67
|
+
'KillShell',
|
|
68
|
+
'SlashCommand',
|
|
69
|
+
]);
|
|
70
|
+
/** The workspace tools an eval run can give, in the order the agent gets them */
|
|
71
|
+
export const WORKSPACE_TOOLS = [
|
|
72
|
+
'read_file',
|
|
73
|
+
'list_files',
|
|
74
|
+
'glob',
|
|
75
|
+
'grep',
|
|
76
|
+
'write_file',
|
|
77
|
+
'edit_file',
|
|
78
|
+
'run_command',
|
|
79
|
+
];
|
|
80
|
+
/** A grant read from its rule text, or why the text is not a rule */
|
|
81
|
+
export function parseGrant(rule) {
|
|
82
|
+
const text = rule.trim();
|
|
83
|
+
const match = /^([^()\s]+)(?:\((.*)\))?$/s.exec(text);
|
|
84
|
+
if (!match)
|
|
85
|
+
return { error: `"${rule}" is not a tool name or a rule such as Bash(npm test *)` };
|
|
86
|
+
const [, tool = '', specifier] = match;
|
|
87
|
+
const trimmed = specifier?.trim();
|
|
88
|
+
return trimmed === undefined || trimmed === '' || trimmed === '*'
|
|
89
|
+
? { rule: text, tool }
|
|
90
|
+
: { rule: text, tool, specifier: trimmed };
|
|
91
|
+
}
|
|
92
|
+
/** Claude Code's name of a Cogitator tool, the tool's own name when it has no counterpart */
|
|
93
|
+
export function claudeNameOf(tool) {
|
|
94
|
+
return CLAUDE_NAME_OF[tool] ?? tool;
|
|
95
|
+
}
|
|
96
|
+
/** Whether a grant of `grantTool` covers the tool named `tool` */
|
|
97
|
+
export function grantCovers(grantTool, tool) {
|
|
98
|
+
if (TOOLS_OF[grantTool]?.includes(tool))
|
|
99
|
+
return true;
|
|
100
|
+
if (grantTool === tool)
|
|
101
|
+
return true;
|
|
102
|
+
return grantTool.includes('*') && globMatches(grantTool, tool);
|
|
103
|
+
}
|
|
104
|
+
/** Whether `name` (a grader's `tool`) names the call, by Claude Code's name or Cogitator's own */
|
|
105
|
+
export function namesCall(name, call) {
|
|
106
|
+
if (name === call.name || name === call.tool)
|
|
107
|
+
return true;
|
|
108
|
+
return name === 'Task' && call.name === 'Agent';
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* What a case may use: the read-only tools its `allowed_tools` lists, and every grant of the run.
|
|
112
|
+
* A rule that cannot be read is an error
|
|
113
|
+
*/
|
|
114
|
+
export function caseGrants(allowedTools, runGrants) {
|
|
115
|
+
const grants = [...runGrants];
|
|
116
|
+
const notGranted = [];
|
|
117
|
+
for (const entry of allowedTools) {
|
|
118
|
+
const grant = parseGrant(entry);
|
|
119
|
+
if ('error' in grant)
|
|
120
|
+
return { error: `allowed_tools: ${grant.error}` };
|
|
121
|
+
if (READ_ONLY_TOOLS.has(grant.tool))
|
|
122
|
+
grants.push(grant);
|
|
123
|
+
else if (!runGrants.some((given) => grantCovers(given.tool, grant.tool) || given.rule === grant.rule)) {
|
|
124
|
+
notGranted.push(grant.rule);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
const noCounterpart = [
|
|
128
|
+
...new Set(grants.filter((grant) => NO_COUNTERPART.has(grant.tool)).map((g) => g.tool)),
|
|
129
|
+
];
|
|
130
|
+
return { grants, notGranted, noCounterpart };
|
|
131
|
+
}
|
|
132
|
+
/** Whether any grant covers the tool named `tool` */
|
|
133
|
+
export function isGranted(grants, tool) {
|
|
134
|
+
return grants.some((grant) => grantCovers(grant.tool, tool));
|
|
135
|
+
}
|
|
136
|
+
//# sourceMappingURL=tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.js","sourceRoot":"","sources":["../../src/plugin-evals/tools.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAErC,qEAAqE;AACrE,MAAM,cAAc,GAAqC;IACvD,SAAS,EAAE,MAAM;IACjB,UAAU,EAAE,IAAI;IAChB,IAAI,EAAE,MAAM;IACZ,IAAI,EA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C,CAAC,KAAK,EAAE,EAAE,CAAC,cAAc,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;KACxF,CAAC;IACF,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,aAAa,EAAE,CAAC;AAC/C,CAAC;AAED,qDAAqD;AACrD,MAAM,UAAU,SAAS,CAAC,MAA4B,EAAE,IAAY;IAClE,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,WAAW,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;AAC/D,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/** A tool call of a transcript, under the name the transcript gives it */
|
|
2
|
+
export interface TranscriptToolCall {
|
|
3
|
+
id: string;
|
|
4
|
+
name: string;
|
|
5
|
+
input: Record<string, unknown>;
|
|
6
|
+
}
|
|
7
|
+
/** One message of a session, in the order it happened */
|
|
8
|
+
export type TranscriptEntry = {
|
|
9
|
+
role: 'user';
|
|
10
|
+
text: string;
|
|
11
|
+
} | {
|
|
12
|
+
role: 'assistant';
|
|
13
|
+
text: string;
|
|
14
|
+
toolCalls: TranscriptToolCall[];
|
|
15
|
+
} | {
|
|
16
|
+
role: 'tool';
|
|
17
|
+
toolUseId: string;
|
|
18
|
+
name: string;
|
|
19
|
+
content: string;
|
|
20
|
+
isError: boolean;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* A `.jsonl` transcript read into its messages: Claude Code's session lines (`{ type: 'user' |
|
|
24
|
+
* 'assistant', message: { role, content } }`, content a string or text, tool_use and
|
|
25
|
+
* tool_result blocks) or plain `{ role, content }` lines. Other lines (summaries, snapshots,
|
|
26
|
+
* system events) are skipped, thinking blocks are left out
|
|
27
|
+
*/
|
|
28
|
+
export declare function parseTranscript(text: string): TranscriptEntry[] | {
|
|
29
|
+
error: string;
|
|
30
|
+
};
|
|
31
|
+
/** The session as JSON, one message per line, in the shape of Claude Code's transcripts */
|
|
32
|
+
export declare function traceLines(entries: readonly TranscriptEntry[]): string[];
|
|
33
|
+
/** A transcript as plain text a judge reads: who said what, each tool call and a cut result */
|
|
34
|
+
export declare function readableTranscript(entries: readonly TranscriptEntry[]): string;
|
|
35
|
+
//# sourceMappingURL=transcript.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transcript.d.ts","sourceRoot":"","sources":["../../src/plugin-evals/transcript.ts"],"names":[],"mappings":"AAEA,0EAA0E;AAC1E,MAAM,WAAW,kBAAkB;IACjC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAChC;AAED,yDAAyD;AACzD,MAAM,MAAM,eAAe,GACvB;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAC9B;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,kBAAkB,EAAE,CAAA;CAAE,GACpE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,CAAC;AAEzF;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,EAAE,GAAG;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,CAyDnF;AAYD,2FAA2F;AAC3F,wBAAgB,UAAU,CAAC,OAAO,EAAE,SAAS,eAAe,EAAE,GAAG,MAAM,EAAE,CAsCxE;AAID,+FAA+F;AAC/F,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,SAAS,eAAe,EAAE,GAAG,MAAM,CAoB9E"}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { isRecord } from './schema.js';
|
|
2
|
+
/**
|
|
3
|
+
* A `.jsonl` transcript read into its messages: Claude Code's session lines (`{ type: 'user' |
|
|
4
|
+
* 'assistant', message: { role, content } }`, content a string or text, tool_use and
|
|
5
|
+
* tool_result blocks) or plain `{ role, content }` lines. Other lines (summaries, snapshots,
|
|
6
|
+
* system events) are skipped, thinking blocks are left out
|
|
7
|
+
*/
|
|
8
|
+
export function parseTranscript(text) {
|
|
9
|
+
const entries = [];
|
|
10
|
+
const toolNames = new Map();
|
|
11
|
+
const lines = text.split('\n');
|
|
12
|
+
for (const [index, raw] of lines.entries()) {
|
|
13
|
+
const line = raw.trim();
|
|
14
|
+
if (line === '')
|
|
15
|
+
continue;
|
|
16
|
+
let json;
|
|
17
|
+
try {
|
|
18
|
+
json = JSON.parse(line);
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
return { error: `line ${index + 1} is not JSON` };
|
|
22
|
+
}
|
|
23
|
+
if (!isRecord(json))
|
|
24
|
+
return { error: `line ${index + 1} is not a JSON object` };
|
|
25
|
+
const message = isRecord(json.message) ? json.message : json;
|
|
26
|
+
const role = message.role;
|
|
27
|
+
if (role !== 'user' && role !== 'assistant')
|
|
28
|
+
continue;
|
|
29
|
+
if (json.type !== undefined && json.type !== 'user' && json.type !== 'assistant')
|
|
30
|
+
continue;
|
|
31
|
+
const content = message.content;
|
|
32
|
+
if (typeof content === 'string') {
|
|
33
|
+
entries.push(role === 'user' ? { role, text: content } : { role, text: content, toolCalls: [] });
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
if (!Array.isArray(content)) {
|
|
37
|
+
return { error: `line ${index + 1} has no content string or list of blocks` };
|
|
38
|
+
}
|
|
39
|
+
const texts = [];
|
|
40
|
+
const toolCalls = [];
|
|
41
|
+
for (const block of content) {
|
|
42
|
+
if (!isRecord(block))
|
|
43
|
+
continue;
|
|
44
|
+
if (block.type === 'text' && typeof block.text === 'string')
|
|
45
|
+
texts.push(block.text);
|
|
46
|
+
else if (block.type === 'tool_use' && role === 'assistant') {
|
|
47
|
+
const id = typeof block.id === 'string' ? block.id : `call_${index}_${toolCalls.length}`;
|
|
48
|
+
const name = typeof block.name === 'string' ? block.name : 'unknown';
|
|
49
|
+
toolNames.set(id, name);
|
|
50
|
+
toolCalls.push({ id, name, input: isRecord(block.input) ? block.input : {} });
|
|
51
|
+
}
|
|
52
|
+
else if (block.type === 'tool_result' && role === 'user') {
|
|
53
|
+
const toolUseId = typeof block.tool_use_id === 'string' ? block.tool_use_id : '';
|
|
54
|
+
entries.push({
|
|
55
|
+
role: 'tool',
|
|
56
|
+
toolUseId,
|
|
57
|
+
name: toolNames.get(toolUseId) ?? 'unknown',
|
|
58
|
+
content: blockText(block.content),
|
|
59
|
+
isError: block.is_error === true,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
const joined = texts.join('\n');
|
|
64
|
+
if (role === 'assistant') {
|
|
65
|
+
if (joined !== '' || toolCalls.length > 0) {
|
|
66
|
+
entries.push({ role, text: joined, toolCalls });
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
else if (joined !== '')
|
|
70
|
+
entries.push({ role, text: joined });
|
|
71
|
+
}
|
|
72
|
+
return entries;
|
|
73
|
+
}
|
|
74
|
+
function blockText(content) {
|
|
75
|
+
if (typeof content === 'string')
|
|
76
|
+
return content;
|
|
77
|
+
if (!Array.isArray(content))
|
|
78
|
+
return content === undefined ? '' : JSON.stringify(content);
|
|
79
|
+
return content
|
|
80
|
+
.map((part) => isRecord(part) && typeof part.text === 'string' ? part.text : JSON.stringify(part))
|
|
81
|
+
.join('\n');
|
|
82
|
+
}
|
|
83
|
+
/** The session as JSON, one message per line, in the shape of Claude Code's transcripts */
|
|
84
|
+
export function traceLines(entries) {
|
|
85
|
+
return entries.map((entry) => {
|
|
86
|
+
switch (entry.role) {
|
|
87
|
+
case 'user':
|
|
88
|
+
return JSON.stringify({ type: 'user', message: { role: 'user', content: entry.text } });
|
|
89
|
+
case 'assistant':
|
|
90
|
+
return JSON.stringify({
|
|
91
|
+
type: 'assistant',
|
|
92
|
+
message: {
|
|
93
|
+
role: 'assistant',
|
|
94
|
+
content: [
|
|
95
|
+
...(entry.text !== '' ? [{ type: 'text', text: entry.text }] : []),
|
|
96
|
+
...entry.toolCalls.map((call) => ({
|
|
97
|
+
type: 'tool_use',
|
|
98
|
+
id: call.id,
|
|
99
|
+
name: call.name,
|
|
100
|
+
input: call.input,
|
|
101
|
+
})),
|
|
102
|
+
],
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
case 'tool':
|
|
106
|
+
return JSON.stringify({
|
|
107
|
+
type: 'user',
|
|
108
|
+
message: {
|
|
109
|
+
role: 'user',
|
|
110
|
+
content: [
|
|
111
|
+
{
|
|
112
|
+
type: 'tool_result',
|
|
113
|
+
tool_use_id: entry.toolUseId,
|
|
114
|
+
content: entry.content,
|
|
115
|
+
...(entry.isError && { is_error: true }),
|
|
116
|
+
},
|
|
117
|
+
],
|
|
118
|
+
},
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
const READABLE_LIMIT = 4000;
|
|
124
|
+
/** A transcript as plain text a judge reads: who said what, each tool call and a cut result */
|
|
125
|
+
export function readableTranscript(entries) {
|
|
126
|
+
return entries
|
|
127
|
+
.map((entry) => {
|
|
128
|
+
switch (entry.role) {
|
|
129
|
+
case 'user':
|
|
130
|
+
return `[user]\n${entry.text}`;
|
|
131
|
+
case 'assistant':
|
|
132
|
+
return [
|
|
133
|
+
entry.text !== '' ? `[assistant]\n${entry.text}` : '',
|
|
134
|
+
...entry.toolCalls.map((call) => `[tool call ${call.name}] ${cut(JSON.stringify(call.input))}`),
|
|
135
|
+
]
|
|
136
|
+
.filter((part) => part !== '')
|
|
137
|
+
.join('\n');
|
|
138
|
+
case 'tool':
|
|
139
|
+
return `[tool result ${entry.name}${entry.isError ? ', error' : ''}]\n${cut(entry.content)}`;
|
|
140
|
+
}
|
|
141
|
+
})
|
|
142
|
+
.join('\n\n');
|
|
143
|
+
}
|
|
144
|
+
function cut(text) {
|
|
145
|
+
return text.length <= READABLE_LIMIT
|
|
146
|
+
? text
|
|
147
|
+
: `${text.slice(0, READABLE_LIMIT)}... (${text.length - READABLE_LIMIT} more characters)`;
|
|
148
|
+
}
|
|
149
|
+
//# sourceMappingURL=transcript.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transcript.js","sourceRoot":"","sources":["../../src/plugin-evals/transcript.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAepC;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAAC,IAAY;IAC1C,MAAM,OAAO,GAAsB,EAAE,CAAC;IACtC,MAAM,SAAS,GAAG,IAAI,GAAG,EAAkB,CAAC;IAC5C,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC/B,KAAK,MAAM,CAAC,KAAK,EAAE,GAAG,CAAC,IAAI,KAAK,CAAC,OAAO,EAAE,EAAE,CAAC;QAC3C,MAAM,IAAI,GAAG,GAAG,CAAC,IAAI,EAAE,CAAC;QACxB,IAAI,IAAI,KAAK,EAAE;YAAE,SAAS;QAC1B,IAAI,IAAa,CAAC;QAClB,IAAI,CAAC;YACH,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC1B,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,EAAE,KAAK,EAAE,QAAQ,KAAK,GAAG,CAAC,cAAc,EAAE,CAAC;QACpD,CAAC;QACD,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC;YAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,KAAK,GAAG,CAAC,uBAAuB,EAAE,CAAC;QAChF,MAAM,OAAO,GAAG,QAAQ,C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