import{join}from"node:path";import{mkdir,writeFile}from"node:fs/promises";function resolveArtifactDirectory(t,n){return join(t,`.eve`,`evals`,`${new Date().toISOString().replace(/[:.]/g,`-`).slice(0,19)}-${n}`)}async function writeArtifacts(r,i){let a=join(r,`cases`);await mkdir(a,{recursive:!0}),await writeFile(join(r,`summary.json`),JSON.stringify(buildSummaryArtifact(i),null,2));let o=i.cases.map(e=>JSON.stringify(buildCaseResultLine(e))).join(`
`);await writeFile(join(r,`results.jsonl`),`${o}\n`),await Promise.all(i.cases.map(async t=>{let r=sanitizeFileName(t.case.id);await writeFile(join(a,`${r}.json`),JSON.stringify(buildCaseArtifact(t),null,2));let i=t.result.events.map(e=>JSON.stringify(e)).join(`
`);await writeFile(join(a,`${r}.events.ndjson`),`${i}\n`)}))}function buildSummaryArtifact(e){return{id:e.id,target:e.target,startedAt:e.startedAt,completedAt:e.completedAt,passed:e.passed,failed:e.failed,scored:e.scored,skipped:e.skipped,errored:e.errored,totalCases:e.cases.length,cases:e.cases.map(e=>({id:e.case.id,verdict:e.verdict,status:e.result.status,checks:e.checks.map(e=>({name:e.name,passed:e.passed})),scores:e.scores.map(e=>({name:e.name,score:e.score})),error:e.error,skipReason:e.skipReason}))}}function buildCaseResultLine(e){return{caseId:e.case.id,verdict:e.verdict,status:e.result.status,output:e.result.output,checks:e.checks,scores:e.scores.map(e=>({name:e.name,score:e.score})),error:e.error,skipReason:e.skipReason}}function buildCaseArtifact(e){return{case:{id:e.case.id,input:`input`in e.case?e.case.input:void 0,expected:e.case.expected,tags:e.case.tags,metadata:e.case.metadata},result:{output:e.result.output,finalMessage:e.result.finalMessage,sessionId:e.result.sessionId,status:e.result.status,logs:e.result.logs,derived:e.result.derived,sessions:e.result.sessions},verdict:e.verdict,checks:e.checks,scores:e.scores,error:e.error,skipReason:e.skipReason}}function sanitizeFileName(e){return e.replace(/[^a-zA-Z0-9_-]/g,`_`)}export{resolveArtifactDirectory,writeArtifacts};