import{modelBackedScorerName}from"#evals/scorers/model-marker.js";function defineEval(e){validateEvalInput(e);let t=e.load??(()=>Promise.resolve([...e.cases]));return{...e,load:t,_tag:`EveEval`}}function validateEvalInput(t){if(`id`in t)throw Error("Eval must not specify `id`. Eval identity is derived from the file path under evals/.");if(`name`in t)throw Error("Eval must not specify `name`. Eval identity is derived from the file path under evals/.");if(t.load!==void 0&&t.cases!==void 0)throw Error("Eval cannot specify both `load` and `cases`. Use one or the other.");if(t.load===void 0&&t.cases===void 0)throw Error("Eval requires either a `load` function or a `cases` array.");if(!Array.isArray(t.scores))throw Error("Eval requires a `scores` array.");if(t.checks!==void 0&&!Array.isArray(t.checks))throw Error("Eval `checks` must be an array of check functions.");if(validateRequirements(t.requires,"Eval `requires`"),t.model===void 0){let n=t.scores.map(modelBackedScorerName).find(e=>e!==void 0);if(n!==void 0)throw Error(`Eval requires a \`model\` because the ${n} scorer is model-backed. Set the eval-level \`model\` or pass \`model\` to the scorer.`)}if([t.task?.prompt,t.task?.messages,t.task?.run].filter(e=>e!==void 0).length>1)throw Error("Eval task cannot specify more than one of `prompt`, `messages`, and `run`.");if(t.maxConcurrency!==void 0&&(t.maxConcurrency<1||!Number.isInteger(t.maxConcurrency)))throw Error("Eval `maxConcurrency` must be a positive integer.");if(t.timeoutMs!==void 0&&(t.timeoutMs<0||!Number.isFinite(t.timeoutMs)))throw Error("Eval `timeoutMs` must be a non-negative finite number.");if(t.cases!==void 0)for(let e of t.cases)validateRequirements(e.requires,`Eval case "${e.id}" \`requires\``)}function validateRequirements(e,t){if(e!==void 0){if(!Array.isArray(e))throw Error(`${t} must be an array of requirement strings.`);for(let n of e)if(!(n===`mockModels`||n===`devRoutes`)&&!(n.startsWith(`env:`)&&n.length>4))throw Error(`${t} contains unsupported requirement "${n}". Expected "mockModels", "devRoutes", or "env:<NAME>".`)}}export{defineEval};