function l(t){return{...t,expected_output:t.expected_output??"",files:Array.isArray(t.files)?t.files:[],assertions:Array.isArray(t.assertions)?t.assertions:[]}}function m(t,o,r){const a=o.filter((e,n)=>r.get(n)===!0);if(a.length===0)return t;const d=a.filter(e=>e.action==="remove"),f=a.filter(e=>e.action==="modify"),c=a.filter(e=>e.action==="add");let i=[...t.evals],v=t.evals.length>0?Math.max(...t.evals.map(e=>e.id))+1:1;const s=new Set(d.map(e=>e.evalId).filter(e=>e!=null));s.size>0&&(i=i.filter(e=>!s.has(e.id)));for(const e of f){if(e.evalId==null||!e.eval)continue;const n=i.findIndex(u=>u.id===e.evalId);n<0||(i[n]=l({...e.eval,id:e.evalId}))}for(const e of c)e.eval&&i.push(l({...e.eval,id:v++}));return{...t,evals:i}}export{m as mergeEvalChanges};
