Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion apps/cli/test/commands/eval/artifact-writer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1938,7 +1938,31 @@ describe('writeArtifactsFromResults', () => {
await expect(readFile(copiedRawLogPath, 'utf8')).rejects.toThrow();

const transcriptPath = runArtifactPath(testDir, indexLine, 'sample-1', 'transcript-raw.jsonl');
await expect(readFile(transcriptPath, 'utf8')).resolves.toBe(rawLog);
const rawTranscriptLines = (await readFile(transcriptPath, 'utf8'))
.trim()
.split('\n')
.map((line) => JSON.parse(line));
expect(rawTranscriptLines).toEqual([
{
schema_version: 'agentv.raw_provider_log_line.v1',
source: {
kind: 'provider_log',
format: 'text',
line_index: 0,
},
content: '# provider-native stream log',
},
{
schema_version: 'agentv.raw_provider_log_line.v1',
source: {
kind: 'provider_log',
format: 'text',
line_index: 1,
},
content:
'{"time":"00:00","data":{"camelCaseProviderKey":true,"toolInput":{"filePath":"src/index.ts"}}}',
},
]);
await expect(readFile(rawLogPath, 'utf8')).resolves.toBe(rawLog);
await expect(
readFile(path.join(testDir, rowDir, 'sample-1', 'transcript.jsonl'), 'utf8'),
Expand Down
48 changes: 47 additions & 1 deletion packages/core/src/evaluation/run-artifacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2471,13 +2471,59 @@ async function writeRawTranscriptJsonl(
): Promise<void> {
const rawSource = rawProviderLogSourcePath(result);
if (rawSource) {
await copyFile(rawSource, filePath);
await copyRawProviderLogAsJsonl(rawSource, filePath);
await cleanupProviderStagingFile(rawSource).catch(() => undefined);
return;
}
await writeGeneratedRawTranscriptJsonl(filePath, result, envelope);
}

async function copyRawProviderLogAsJsonl(sourcePath: string, filePath: string): Promise<void> {
const content = await readFile(sourcePath, 'utf8');
if (isJsonlContent(content)) {
await copyFile(sourcePath, filePath);
return;
}

const lines = splitLogLines(content);
const records = lines.map((line, index) => ({
schema_version: 'agentv.raw_provider_log_line.v1',
source: {
kind: 'provider_log',
format: 'text',
line_index: index,
},
content: line,
}));
await writeJsonlFile(filePath, records);
}

function isJsonlContent(content: string): boolean {
const lines = content.split(/\r?\n/).filter((line) => line.trim().length > 0);
if (lines.length === 0) {
return true;
}
return lines.every((line) => {
try {
JSON.parse(line);
return true;
} catch {
return false;
}
});
}

function splitLogLines(content: string): string[] {
if (content.length === 0) {
return [];
}
const lines = content.replace(/\r\n/g, '\n').split('\n');
if (lines.at(-1) === '') {
lines.pop();
}
return lines;
}

function buildMetricsArtifactPayload(params: {
readonly result: EvaluationResult;
readonly envelope: TraceEnvelope;
Expand Down
Loading