evalution 1.0.6 → 1.0.8

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.
Files changed (25) hide show
  1. package/LICENSING.md +1 -0
  2. package/dist/{check-BTg6THHB.d.ts → check-CR4fU1S5.d.ts} +43 -15
  3. package/dist/checks/index.d.ts +1 -1
  4. package/dist/cli/index.js +116 -69
  5. package/dist/client/assets/DatasetView-BqSWI_pm.js +15 -0
  6. package/dist/client/assets/EvalRunView-CR6ZksSu.js +2 -0
  7. package/dist/client/assets/EvalView-JPEM5IY8.js +1 -0
  8. package/dist/client/assets/{data-grid-overlay-editor-CBtkQufd.js → data-grid-overlay-editor-B_nPhXKR.js} +1 -1
  9. package/dist/client/assets/{highlighted-body-KPVGNVTW-DyudWmoO.js → highlighted-body-KPVGNVTW-dPpneB8R.js} +1 -1
  10. package/dist/client/assets/{index-B7OFMd2c.css → index-BGcZZetP.css} +1 -1
  11. package/dist/client/assets/{index-aypgoZcG.js → index-CwjMcK6S.js} +150 -150
  12. package/dist/client/assets/{number-overlay-editor-CXHiTLsp.js → number-overlay-editor-CRWFlaQs.js} +1 -1
  13. package/dist/client/index.html +2 -2
  14. package/dist/{dataset-types-CSjbM_Vz.d.ts → dataset-types-Dqi5vVg-.d.ts} +20 -5
  15. package/dist/index.d.ts +169 -9
  16. package/dist/index.js +24 -13
  17. package/dist/{trace-Dn6Pfcc5.d.ts → trace-DGj5oW7z.d.ts} +1 -1
  18. package/dist/{otlp-trace-ingestor-V8_bbpUG.js → trace-event-ingestor-BghQcCHe.js} +566 -75
  19. package/dist/views/datasets/index.d.ts +1 -1
  20. package/dist/views/index.d.ts +2 -2
  21. package/dist/views/react/index.d.ts +1 -1
  22. package/package.json +2 -2
  23. package/dist/client/assets/DatasetView-CyX0mCj8.js +0 -15
  24. package/dist/client/assets/EvalRunView-5IZp_6Ob.js +0 -2
  25. package/dist/client/assets/EvalView-DBTK6rCe.js +0 -1
@@ -1,2 +0,0 @@
1
- import{r as n,g as P,a as ee,c as se,j as s,i as ae,b as te,d as I,E as le,f as z,e as ne,T as re,s as ce,h as ie,k as de,l as H,m as oe,n as me}from"./index-aypgoZcG.js";const he=500,ue={pass:"✓",fail:"✗",error:"!",skipped:"–",scored:""};function ve(r){if(!r)return"";const m=r.score===void 0?"":Number.isInteger(r.score)?String(r.score):r.score.toFixed(2);return[ue[r.outcome],m].filter(Boolean).join(" ")}function je({providerId:r,runId:m,version:T,progress:i,onOpenTrace:L,onDeleted:_}){var B;const[l,G]=n.useState(null),[u,J]=n.useState({rows:[],checks:[]}),[g,w]=n.useState(null),[v,K]=n.useState(null),[$,Q]=n.useState([]),[N,D]=n.useState(""),[U,M]=n.useState(!1),[b,O]=n.useState(null),[Y,q]=n.useState(0),k=n.useRef(void 0),A=i==null?void 0:i.done;n.useEffect(()=>{A===void 0||k.current||(k.current=setTimeout(()=>{k.current=void 0,q(e=>e+1)},he))},[A]),n.useEffect(()=>()=>clearTimeout(k.current),[]),n.useEffect(()=>{let e=!1;return P(r,m).then(a=>{e||(G(a.run),J(a.results))}).catch(a=>!e&&w(a.message)),()=>{e=!0}},[r,m,T,Y]);const C=l==null?void 0:l.evalId;n.useEffect(()=>{C&&ee(r,C).then(e=>{const a=e.filter(t=>t.id!==m);Q(a),D(t=>a.some(j=>j.id===t)?t:"")}).catch(()=>{})},[r,C,m,T]),n.useEffect(()=>{if(O(null),!N)return;let e=!1;return P(r,N).then(a=>!e&&O(a)).catch(a=>!e&&w(a.message)),()=>{e=!0}},[r,N]);const p=n.useMemo(()=>l&&b?se({results:u,arms:l.arms},{results:b.results,arms:b.run.arms}):null,[l,u,b]);if(g&&!l)return s.jsxs("div",{className:"eval-view eval-view-error",children:["Error: ",g]});if(!l)return s.jsx("div",{className:"eval-view"});const h=l.definition.checks,E=e=>{const a=h.find(t=>t.id===e);return(a==null?void 0:a.label)??(a==null?void 0:a.uri.split("#").pop())??e},x=l.arms.filter(e=>!e.error),F=ae(u.checks),R=te(u),W=new Map((p??[]).map(e=>[I(e.armId,e.rowId,e.checkId),e])),S=(i==null?void 0:i.status)??l.status,V=(i==null?void 0:i.done)??u.rows.length,d=v?F.get(v):void 0,y=v?(B=R.find(e=>e.rowId===v.split(":")[1]))==null?void 0:B.arms.get(v.split(":")[0]):void 0,X=async()=>{if(window.confirm(oe(l.startedAt,S==="running"))){M(!0);try{await me(r,m),_()}catch(e){w(e.message),M(!1)}}},Z=(e,a,t)=>{var o;const j=I(e,a,t);K(j);const c=(o=R.find(f=>f.rowId===a))==null?void 0:o.arms.get(e);c!=null&&c.traceId&&c.traceProviderId&&L(c.traceProviderId,c.traceId)};return s.jsxs("div",{className:"eval-view eval-run-view",children:[s.jsxs("div",{className:"trace-view-header",children:[s.jsxs("div",{className:"trace-view-header-row",children:[s.jsxs("div",{className:"trace-view-title",children:[s.jsx(le,{size:14}),s.jsxs("span",{className:"trace-view-name",children:[l.definition.name," · ",z(l.startedAt)]})]}),s.jsxs("div",{className:"trace-view-header-actions",children:[S==="running"&&s.jsx("button",{type:"button",className:"dialog-btn-cancel",onClick:()=>ne(r,m).catch(e=>w(e.message)),children:"Cancel"}),s.jsx("button",{type:"button",className:"trace-view-prompt-btn trace-view-delete-btn",onClick:X,disabled:U,title:"Delete run","aria-label":"Delete run",children:s.jsx(re,{})})]})]}),s.jsxs("div",{className:"trace-view-meta",children:[s.jsx("span",{className:"trace-view-meta-item",children:S==="running"?s.jsxs(s.Fragment,{children:[s.jsx("progress",{max:l.total,value:V})," ",V,"/",l.total]}):S}),l.startVersion&&s.jsx("span",{className:"trace-view-meta-item",title:`Commit ${l.startVersion}`,children:l.startVersion.slice(0,7)}),l.dirty&&s.jsx("span",{className:"eval-badge",children:"uncommitted changes"}),l.drifted&&s.jsx("span",{className:"eval-badge",children:"drifted"}),$.length>0&&s.jsxs("label",{className:"trace-view-meta-item eval-compare",children:["Compare with",s.jsxs("select",{"aria-label":"Compare with run",value:N,onChange:e=>D(e.target.value),children:[s.jsx("option",{value:"",children:"—"}),$.map(e=>s.jsxs("option",{value:e.id,children:[z(e.startedAt)," (",e.arms.map(a=>a.label).join(", "),")"]},e.id))]})]})]})]}),g&&s.jsx("div",{className:"pg-exec-error",children:g}),s.jsxs("div",{className:"eval-view-body",children:[s.jsx("div",{className:"eval-arm-summaries",children:l.arms.map(e=>{if(e.error)return s.jsxs("div",{className:"eval-arm-summary",children:[s.jsx("div",{className:"eval-arm-label",children:e.label}),s.jsx("div",{className:"eval-check-missing",children:e.error})]},e.id);const a=ce(u,e.id,h.map(t=>t.id));return s.jsxs("div",{className:"eval-arm-summary",children:[s.jsx("div",{className:"eval-arm-label",children:e.label}),a.checks.map(t=>s.jsxs("div",{className:"eval-arm-check",children:[s.jsx("span",{children:E(t.checkId)}),s.jsx("span",{className:"eval-arm-rate",children:t.meanScore!==void 0&&t.passRate===void 0?`mean ${t.meanScore.toFixed(2)}`:ie(t.passRate)})]},t.checkId)),s.jsxs("div",{className:"eval-arm-stats",children:[a.rowErrors>0&&s.jsxs("span",{children:[a.rowErrors," row errors"]}),a.totalCost!==void 0&&s.jsx("span",{children:de(a.totalCost)}),a.p50Duration!==void 0&&s.jsxs("span",{children:["p50 ",H(a.p50Duration)," · p95"," ",H(a.p95Duration??a.p50Duration)]})]})]},e.id)})}),p&&s.jsx("p",{className:"eval-compare-summary",children:p.length===0?"No outcome changed.":`${p.filter(e=>e.regressed).length} regressed, ${p.filter(e=>!e.regressed).length} otherwise changed — outlined below.`}),s.jsx("div",{className:"eval-grid-scroll",children:s.jsxs("table",{className:"eval-grid",children:[s.jsxs("thead",{children:[s.jsxs("tr",{children:[s.jsx("th",{rowSpan:x.length>1?2:1,children:"Row"}),x.length>1?x.map(e=>s.jsx("th",{colSpan:h.length||1,children:e.label},e.id)):h.map(e=>s.jsx("th",{children:E(e.id)},e.id))]}),x.length>1&&s.jsx("tr",{children:x.flatMap(e=>h.map(a=>s.jsx("th",{children:E(a.id)},`${e.id}:${a.id}`)))})]}),s.jsx("tbody",{children:R.map(e=>s.jsxs("tr",{children:[s.jsx("td",{className:"eval-grid-row",children:e.rowIndex+1}),x.flatMap(a=>{const t=e.arms.get(a.id);return t&&t.status!=="ok"?[s.jsxs("td",{colSpan:h.length||1,className:`eval-cell eval-cell-${t.status}`,title:t.error,children:[t.status,": ",t.error]},a.id)]:h.map(j=>{const c=I(a.id,e.rowId,j.id),o=F.get(c),f=W.get(c);return s.jsx("td",{className:["eval-cell",o&&`eval-cell-${o.outcome}`,v===c&&"eval-cell-selected",f&&(f.regressed?"eval-cell-regressed":"eval-cell-changed")].filter(Boolean).join(" "),title:[o==null?void 0:o.message,f&&`was ${f.before}`,(t==null?void 0:t.traceIncomplete)&&"The trace was incomplete when checks ran"].filter(Boolean).join(`
2
- `)||void 0,onClick:()=>Z(a.id,e.rowId,j.id),children:ve(o)},c)})})]},e.rowId))})]})}),d&&s.jsxs("div",{className:"eval-cell-detail",children:[s.jsxs("div",{className:"eval-arm-label",children:["Row ",((y==null?void 0:y.rowIndex)??0)+1," ·"," ",E(d.checkId)," · ",d.outcome,d.score!==void 0&&` (${d.score})`]}),d.message&&s.jsx("pre",{className:"eval-cell-message",children:d.message}),d.details!==void 0&&s.jsx("pre",{className:"eval-cell-message",children:JSON.stringify(d.details,null,2)})]})]})]})}export{je as default};
@@ -1 +0,0 @@
1
- import{q as Ie,t as as,u as cs,v as ne,r as v,w as rs,x as is,a as Re,y as os,z as ls,A as us,B as ds,C as Ee,D as hs,F as ms,G as ps,H as fs,j as s,I as xs,J as gs,T as Ae,P as Pe,K as Oe,L as z,e as vs,M as js,R as bs,N as ks,O as ys,Q as Ns,U as ws,V as $s,W as Cs,X as Ss,Y as Is,Z as Rs,_ as Es,$ as Ps,a0 as Os,a1 as Ds,a2 as Ms,f as De,h as Ts,a3 as Fs,m as As,n as Bs,a4 as Us,a5 as Ks,a6 as ae,a7 as _s,a8 as Ls,a9 as qs,aa as Vs,ab as Ws}from"./index-aypgoZcG.js";function Be(n,a){var l;return(l=a.find(o=>o.def.name===n.name&&o.def.type.syntax===n.type.syntax))==null?void 0:l.id}function Ys(n,a){if((n==null?void 0:n.kind)==="object")return n.properties[a];if((n==null?void 0:n.kind)==="value"&&n.value.kind==="object"){const l=n.value.properties[a];return l&&{kind:"value",value:l}}}function Ue(n,a,l,o,r,m){if(a&&a.kind!=="object")return a;if(!a){const d=Be(n,o);if(d)return m.push(r),{kind:"dataset",field:d}}if(n.type.kind==="object"){const d={...(a==null?void 0:a.kind)==="object"?a.properties:{}},k=[];for(const h of n.type.properties){const y=Ue(h,d[h.name],Ys(l,h.name),o,`${r}.${h.name}`,k);y&&(d[h.name]=y)}const x=k.length>0;return!a&&!x&&l?(m.push(r),l):(m.push(...k),Object.keys(d).length===0?a:{kind:"object",properties:d})}return!a&&l?(m.push(r),l):a}function Hs(n,a,l){const o={...a},r=[...Object.values(n.functionInputs),...Object.values(n.executeInputs)].flatMap(Ie);for(;r.length>0;){const m=r.pop(),d=l==null?void 0:l[m];if(Object.hasOwn(o,m)||!d)continue;const{receipt:k,...x}=d;o[m]=x,r.push(...Object.values(d.args??{}).flatMap(Ie))}return Object.keys(o).length>0?o:void 0}function Qs(n){const{prompt:a,fields:l,stored:o}=n,r=[],m=(h,y,g,p)=>{const j={...y};for(const N of h){const C=Ue(N,y[N.name],g==null?void 0:g[N.name],l,`${p}:${N.name}`,r);C&&(j[N.name]=C)}return j},d={functionInputs:m(a.functionParameters,n.inputs.functionInputs,o==null?void 0:o.functionInputs,"fn"),executeInputs:m(a.executeParameters??[],n.inputs.executeInputs,o==null?void 0:o.executeInputs,"exec")},k=Hs(d,n.inputs.resources,o==null?void 0:o.resources);k&&(d.resources=k);const x=n.checks.map(h=>{const y=n.checkInfos.find(p=>p.uri===h.uri);if(!y)return h;const g={...h.args};for(const p of y.parameters){if(g[p.name])continue;const j=Be(p,l);if(j){g[p.name]={kind:"dataset",field:j},r.push(`check:${h.id}:${p.name}`);continue}const N=a.functionParameters.some(C=>C.name===p.name&&C.type.syntax===p.type.syntax)?"function":(a.executeParameters??[]).some(C=>C.name===p.name&&C.type.syntax===p.type.syntax)?"execute":void 0;N&&(g[p.name]={kind:"input",half:N,path:p.name},r.push(`check:${h.id}:${p.name}`))}return{...h,args:g}});return{inputs:d,checks:x,matched:r}}function Ke(n){switch(n.kind){case"dataset":return[n.field];case"object":return Object.values(n.properties).flatMap(Ke);default:return[]}}function _e(n){switch(n.kind){case"input":return[n];case"object":return Object.values(n.properties).flatMap(_e);default:return[]}}function re(n,a,l=""){const o=[];for(const r of n){const m=l?`${l}.${r.name}`:r.name,d=a[r.name];if(!d){r.optional||o.push(m);continue}d.kind==="object"&&r.type.kind==="object"&&o.push(...re(r.type.properties,d.properties,m))}return o}function zs(n,a,l){var y;const o=[],{prompt:r,fields:m}=l,d=m&&new Set(m.map(g=>g.id)),k=(g,p)=>{if(d)for(const j of Ke(g))d.has(j)||o.push(`${p} is bound to a column that no longer exists`)},x=[["function",n.functionInputs,r==null?void 0:r.functionParameters],["execute",n.executeInputs,(r==null?void 0:r.executeParameters)??[]]];for(const[g,p,j]of x){for(const[N,C]of Object.entries(p)){const i=`Input '${ne(g,N)}'`;if(j&&!j.some(b=>b.name===N)){o.push(`${i} is bound, but the prompt no longer has it`);continue}k(C,i)}if(j)for(const N of re(j,p))o.push(`Input '${ne(g,N)}' is required but unbound`)}for(const[g,p]of Object.entries(n.resources??{}))for(const[j,N]of Object.entries(p.args??{}))k(N,`Resource '${g}': '${j}'`);r&&o.push(...as(n,r,{undeclaredInstances:!0}));const h=r&&cs(r);for(const g of a){const p=(y=l.checks)==null?void 0:y.find(N=>N.uri===g.uri),j=`Check '${g.label??(p==null?void 0:p.label)??g.uri}'`;if(l.checks&&!p){o.push(`${j} no longer exists`);continue}if(p!=null&&p.error){o.push(`${j} can't load: ${p.error}`);continue}for(const[N,C]of Object.entries(g.args)){const i=`${j}: '${N}'`;if(k(C,i),!!h)for(const b of _e(C))h[b.half].has(b.path)||o.push(`${i} names input '${ne(b.half,b.path)}', which the prompt doesn't have`)}if(p)for(const N of re(p.parameters,g.args))o.push(`${j}: '${N}' is required but unbound`)}return o}const Gs={resources:[]},Js=400;function Me(n){const a=l=>Object.fromEntries(Object.entries(l).map(([o,r])=>[o,_s(r)]));return{fn:a(n.inputs.functionInputs),exec:a(n.inputs.executeInputs),checks:Object.fromEntries(n.checks.map(l=>[l.id,a(l.args)])),instances:Ss(n.inputs.resources)}}function ce(n){return Object.fromEntries(Object.entries(n).flatMap(([a,l])=>{const o=Ls(l);return o?[[a,o]]:[]}))}function Xs(n){let a=n.length+1;for(;n.some(l=>l.id===`c${a}`);)a++;return`c${a}`}function Te(n){var a;return(a=Object.entries(n.resources??{}).find(([,l])=>l===qs))==null?void 0:a[0]}function it({providerId:n,evalId:a,prompts:l,datasets:o,version:r,datasetVersion:m,progress:d,onOpenRun:k,onRunStarted:x,onOpenPrompt:h,onOpenDataset:y,onDeleted:g,onDuplicated:p,onRunDeleted:j,agents:N=[],onAskAgent:C}){var Ce,Se;const[i,b]=v.useState(null),[M,O]=v.useState(null),[A,E]=v.useState(null),[T,G]=v.useState(),[F,Le]=v.useState([]),[ie,J]=v.useState([]),[$,V]=v.useState({fn:{},exec:{},checks:{},instances:{}}),[qe,oe]=v.useState(new Set),[Ve,X]=v.useState(!1),[le,W]=v.useState(""),u=i?rs(l,i.prompt):void 0,ue=st(u),R=i&&o.find(e=>e.providerId===i.dataset.providerId&&e.id===i.dataset.id),Y=(u==null?void 0:u.functionParameters)??[],K=(u==null?void 0:u.executeParameters)??[],de=v.useMemo(()=>{var e;return new Map((((e=u==null?void 0:u.inputSources)==null?void 0:e.resources)??[]).map(t=>[t.uri,t]))},[u==null?void 0:u.inputSources]),he=v.useRef(null);v.useEffect(()=>{let e=!1;return is(n,a).then(t=>{if(!e&&(b(t),he.current!==a)){he.current=a,W(t.name);const c=Me(t);P.current=c,V(c)}}).catch(t=>!e&&O(t.message)),Re(n,a).then(t=>!e&&J(t)).catch(()=>{}),()=>{e=!0}},[n,a,r]);const me=Object.values(d).filter(e=>e.evalId===a).map(e=>`${e.runId}:${e.done}`).join();v.useEffect(()=>{me&&Re(n,a).then(J).catch(()=>{})},[me]);const Z=i==null?void 0:i.dataset.providerId,ee=i==null?void 0:i.dataset.id;v.useEffect(()=>{!Z||!ee||os(Z,ee).then(e=>G(e.dataset.fields)).catch(()=>G([]))},[Z,ee,m]);const pe=u==null?void 0:u.providerId;v.useEffect(()=>{ls().then(e=>{var t,c;return Le(((t=e.find(f=>f.providerId===pe))==null?void 0:t.checks)??((c=e[0])==null?void 0:c.checks)??[])}).catch(()=>{})},[pe]);const H=v.useRef({}),se=v.useRef(void 0),_=v.useCallback(async()=>{clearTimeout(se.current);const e=H.current;if(H.current={},Object.keys(e).length!==0)try{b(await us(n,a,e))}catch(t){E(t.message)}},[n,a]);v.useEffect(()=>()=>void _(),[_]);const D=(e,t=!1)=>{H.current={...H.current,...e},b(c=>c&&{...c,...e}),clearTimeout(se.current),t?_():se.current=setTimeout(()=>void _(),Js)},te=e=>{const t=Is(e.instances);return{functionInputs:ce(e.fn),executeInputs:ce(e.exec),...t&&{resources:t}}},B=(e,t)=>t.map(c=>({...c,args:ce(e.checks[c.id]??{})})),P=v.useRef($),fe=v.useRef(i);fe.current=i;const L=(e,t=(c=>(c=fe.current)==null?void 0:c.checks)()??[])=>{P.current=e,V(e),D({inputs:te(e),checks:B(e,t)})},We=(i==null?void 0:i.checks.map(e=>`${e.id}=${e.uri}`).join())??"";v.useEffect(()=>{if(!i||!u||!T)return;const e={inputs:te($),checks:B($,i.checks)},t=Qs({prompt:u,fields:T,inputs:e.inputs,checks:e.checks,checkInfos:F,stored:ds(u)});if(t.matched.length===0)return;const c=Me({inputs:t.inputs,checks:t.checks});oe(f=>new Set([...f,...t.matched])),P.current=c,V(c),D({inputs:t.inputs,checks:t.checks})},[i==null?void 0:i.id,u==null?void 0:u.id,T,F,We]);const xe=e=>oe(t=>{if(!t.has(e))return t;const c=new Set(t);return c.delete(e),c}),ge=te($),Ye=i?B($,i.checks):[],q=i?zs(ge,Ye,{...u&&{prompt:u},...T&&{fields:T},checks:F}):[];i&&!u&&q.unshift("The eval's prompt no longer exists"),i&&!R&&q.unshift("The eval's dataset no longer exists");const Q=Ee(hs(ms(u==null?void 0:u.inputSources,$.instances),{functionParameters:Y,executeParameters:K,bindings:ge,fields:T??[],offerMismatches:!0,newColumn:!0})),ve={functionParameters:Y,executeParameters:K,fields:T},je=Ee(Object.fromEntries(((i==null?void 0:i.checks)??[]).map(e=>{var t;return[e.id,ps(((t=F.find(c=>c.uri===e.uri))==null?void 0:t.parameters)??[],ve)]}))),be=(e,t)=>{const c=P.current,f=typeof e=="function"?e(c.instances):e;if(!t)return L({...c,instances:f});const[w,S]=t.kind==="rename"?[t.from,t.to]:[t.name,null];L({fn:ae(c.fn,w,S),exec:ae(c.exec,w,S),checks:Object.fromEntries(Object.entries(c.checks).map(([I,U])=>[I,ae(U,w,S)])),instances:f})},ke=fs({instances:$.instances,catalogByUri:de,rowsMayDeclare:!0,adopt:e=>{const t=Us(P.current.instances,e,de);return be(t.instances),t.uri},describeOther:(e,t)=>Ks(e,t,ve)}),ye=async(e,t)=>{if(!i||!(u!=null&&u.providerId))return t(null);try{const c=await Vs(i.dataset.providerId,i.dataset.id,"checkUri"in e?{from:{providerId:u.providerId,...e}}:{from:{providerId:u.providerId,promptId:u.id,...e}});G(f=>[...f??[],c]),t(Ws(c.id))}catch(c){E(c.message),t(null)}},He=e=>(t,c)=>{xe(`${e}:${t}`);const f=Te(c),w=S=>{const I={...c.resources};f!==void 0&&(S?I[f]=S:delete I[f]);const U=P.current;L({...U,[e]:{...U[e],[t]:{...c,resources:I}}})};if(f===void 0){const S=P.current;L({...S,[e]:{...S[e],[t]:c}});return}ye({half:e==="fn"?"function":"execute",path:f?`${t}.${f}`:t},w)},Qe=e=>(t,c)=>{xe(`check:${e.id}:${t}`);const f=Te(c),w=S=>{const I=P.current;L({...I,checks:{...I.checks,[e.id]:{...I.checks[e.id],[t]:S}}})};if(f===void 0)return w(c);ye({checkUri:e.uri,path:f?`${t}.${f}`:t},S=>{const I={...c.resources};S?I[f]=S:delete I[f],w({...c,resources:I})})},ze=(e,t)=>{if(!i)return;const c=i.checks.map(f=>{if(f.id!==e)return f;const w={...f,...t};return t.threshold===void 0&&"threshold"in t&&delete w.threshold,t.label===void 0&&"label"in t&&delete w.label,w});D({checks:B($,c)})},Ge=e=>{if(!i)return;const t=[...i.checks,{id:Xs(i.checks),uri:e,args:{}}];D({checks:B($,t)},!0)},Je=e=>{if(!i)return;const{[e]:t,...c}=$.checks,f={...$,checks:c};P.current=f,V(f),D({checks:B(f,i.checks.filter(w=>w.id!==e))},!0)},Ne=()=>{X(!1);const e=le.trim();e&&i&&e!==i.name?D({name:e},!0):i&&W(i.name)},Xe=async()=>{if(i)try{p(await Rs(Es(i),n))}catch(e){E(e.message)}},Ze=async()=>{if(i&&window.confirm(`Delete "${i.name}" and all its runs?`))try{await Ps(n,a),g()}catch(e){E(e.message)}},es=async e=>{var c;const t=(((c=d[e.id])==null?void 0:c.status)??e.status)==="running";if(window.confirm(As(e.startedAt,t)))try{await Bs(n,e.id),J(f=>f.filter(w=>w.id!==e.id)),j(e)}catch(f){E(f.message)}};if(M)return s.jsxs("div",{className:"eval-view eval-view-error",children:["Error: ",M]});if(!i)return s.jsx("div",{className:"eval-view"});const we=(e,{key:t,label:c,matchedKey:f,selection:w,onChange:S,sources:I,slots:U})=>s.jsxs("div",{className:"pg-exec-param",children:[s.jsxs("div",{className:"pg-exec-param-label",children:[s.jsxs("span",{className:"pg-exec-param-name",children:[c,e.optional?"":" *"]}),s.jsx("span",{className:"pg-exec-param-type",title:e.type.syntax,children:Ds(e.type.syntax,60)}),qe.has(f)&&s.jsx("span",{className:"eval-matched",title:"Filled in for you — change it if it's wrong",children:"matched"})]}),s.jsx(Ms,{propDef:e,selection:w,onChange:S,resources:I.resources,slots:U,context:ke})]},t),$e=(e,t)=>e.map(c=>we(c,{key:`${t}:${c.name}`,label:t==="exec"?`execute.${c.name}`:c.name,matchedKey:`${t}:${c.name}`,selection:$[t][c.name]??{},onChange:f=>He(t)(c.name,f),sources:Q,slots:t==="fn"?Q.functionSlots:Q.executeSlots})),ss=s.jsxs("div",{className:"pg-prompt-header eval-header",children:[s.jsxs("div",{className:"pg-prompt-header-row",children:[Ve?s.jsx("form",{className:"dataset-view-rename",onSubmit:e=>{e.preventDefault(),Ne()},children:s.jsx("input",{autoFocus:!0,"aria-label":"Eval name",value:le,onChange:e=>W(e.target.value),onFocus:e=>e.target.select(),onBlur:Ne,onKeyDown:e=>{e.key==="Escape"&&(W(i.name),X(!1))}})}):s.jsx("span",{className:"pg-prompt-name",onDoubleClick:()=>X(!0),title:"Double-click to rename",children:i.name}),s.jsxs("div",{className:"pg-prompt-header-right",children:[A&&s.jsxs("div",{className:"pg-header-error",children:[A,s.jsx("button",{type:"button",className:"pg-dismiss",onClick:()=>E(null),children:"×"})]}),C&&s.jsx(xs,{agents:N,onAsk:C}),s.jsx("button",{type:"button",className:"trace-view-prompt-btn",onClick:Xe,title:"Duplicate eval","aria-label":"Duplicate eval",children:s.jsx(gs,{})}),s.jsx("button",{type:"button",className:"trace-view-prompt-btn trace-view-delete-btn",onClick:Ze,title:"Delete eval","aria-label":"Delete eval",children:s.jsx(Ae,{})})]})]}),s.jsxs("div",{className:"eval-header-links",children:[s.jsxs("button",{type:"button",className:"eval-header-link",disabled:!u,title:"Open the prompt",onClick:()=>u&&h(u),children:[s.jsx(Pe,{}),s.jsx("span",{className:"eval-header-link-name",children:(u==null?void 0:u.name)??"Prompt missing"}),u&&"↗"]}),s.jsxs("button",{type:"button",className:"eval-header-link",disabled:!R,title:"Open the dataset",onClick:()=>R&&y(R),children:[s.jsx(Oe,{}),s.jsx("span",{className:"eval-header-link-name",children:(R==null?void 0:R.name)??"Dataset missing"}),R&&"↗"]})]})]}),ts=s.jsxs("div",{className:"eval-editor",children:[s.jsxs("section",{className:"eval-section",children:[s.jsxs("label",{className:"eval-select-row",children:[s.jsxs("span",{className:"eval-select-label",children:[s.jsx(Pe,{}),"Prompt"]}),s.jsx(Fe,{label:(u==null?void 0:u.name)??"(missing prompt)",children:s.jsxs("select",{className:"pg-model-overlay-select","aria-label":"Prompt",value:u?`${u.providerId}:${u.id}`:"",onChange:e=>{const t=l.find(c=>`${c.providerId}:${c.id}`===e.target.value);t!=null&&t.providerId&&D({prompt:{id:t.globalId??t.id,providerId:t.providerId}},!0)},children:[!u&&s.jsx("option",{value:"",children:"(missing prompt)"}),l.map(e=>s.jsx("option",{value:`${e.providerId}:${e.id}`,children:e.name},`${e.providerId}:${e.id}`))]})})]}),s.jsxs("label",{className:"eval-select-row",children:[s.jsxs("span",{className:"eval-select-label",children:[s.jsx(Oe,{}),"Dataset"]}),s.jsx(Fe,{label:(R==null?void 0:R.name)??"(missing dataset)",children:s.jsxs("select",{className:"pg-model-overlay-select","aria-label":"Dataset",value:R?z(R):"",onChange:e=>{const t=o.find(c=>z(c)===e.target.value);t&&D({dataset:{providerId:t.providerId,id:t.id}},!0)},children:[!R&&s.jsx("option",{value:"",children:"(missing dataset)"}),o.map(e=>s.jsx("option",{value:z(e),children:e.name},z(e)))]})})]})]}),s.jsxs("section",{className:"eval-section",children:[s.jsx("h4",{className:"pg-msg-header pg-role-label eval-section-title",children:"Checks"}),i.checks.length===0&&s.jsx("p",{className:"eval-empty",children:"Nothing judges a run yet. Add a check to say what a good answer is."}),i.checks.map(e=>{var t;return s.jsx(Zs,{check:e,info:F.find(c=>c.uri===e.uri),onChangeCheck:c=>ze(e.id,c),onRemove:()=>Je(e.id),children:(t=F.find(c=>c.uri===e.uri))==null?void 0:t.parameters.map(c=>{var f,w;return we(c,{key:`check:${e.id}:${c.name}`,label:c.name,matchedKey:`check:${e.id}:${c.name}`,selection:((f=$.checks[e.id])==null?void 0:f[c.name])??{},onChange:S=>Qe(e)(c.name,S),sources:je[e.id]??Gs,slots:((w=je[e.id])==null?void 0:w.functionSlots)??{}})})},e.id)}),s.jsx(et,{checks:F,onAdd:Ge})]}),s.jsxs("section",{className:"eval-section",children:[s.jsx("h4",{className:"pg-msg-header pg-role-label eval-section-title",children:"Runs"}),ie.length===0?s.jsx("p",{className:"eval-empty",children:"No runs yet. Run it from the panel."}):s.jsx(at,{runs:ie,progress:d,onOpen:e=>k(e,i.name),onCancel:e=>vs(n,e.id).catch(t=>E(t.message)),onDelete:es})]})]}),ns=s.jsxs(js,{title:"Inputs",notice:q.length>0&&s.jsx("ul",{className:"eval-problems","aria-label":"Problems",children:q.map(e=>s.jsx("li",{children:e},e))}),footer:s.jsx(nt,{choices:ue,disabled:q.length>0,onRun:async e=>{await _();try{const t=await ys(n,a,e);x(t,i.name)}catch(t){E(t instanceof Ns?`Can't run: ${t.problems.join("; ")}`:t.message)}}}),children:[u?s.jsxs(s.Fragment,{children:[$e(Y,"fn"),K.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"pg-exec-section"}),$e(K,"exec")]}),Y.length+K.length===0&&s.jsx("p",{className:"eval-empty",children:"This prompt takes no inputs."})]}):s.jsx("p",{className:"eval-empty",children:"Choose a prompt."}),s.jsx("div",{className:"pg-exec-section"}),((((Ce=u==null?void 0:u.inputSources)==null?void 0:Ce.resources.length)??0)>0||Object.keys($.instances).length>0)&&s.jsx(bs,{instances:$.instances,onChange:be,sources:Q,catalog:((Se=u==null?void 0:u.inputSources)==null?void 0:Se.resources)??[],referencedBy:e=>ks(e,$.instances,[{selections:$.fn},{selections:$.exec},...Object.values($.checks).map(t=>({selections:t}))]),context:ke}),s.jsx("div",{className:"pg-exec-section"}),s.jsx(tt,{choices:ue})]});return s.jsx("div",{className:"eval-view",children:s.jsx(ws,{header:ss,editor:ts,panel:ns})})}function Zs({check:n,info:a,onChangeCheck:l,onRemove:o,children:r}){const m=n.label??(a==null?void 0:a.label)??n.uri,d=(a==null?void 0:a.group)!=="Built-in"||n.threshold!==void 0;return s.jsxs("div",{className:"eval-check",children:[s.jsxs("div",{className:"eval-check-header",children:[s.jsx(Os,{className:"eval-check-label",label:"Check name",title:n.uri,value:m,onCommit:k=>l({label:k.trim()||void 0})}),(a==null?void 0:a.group)&&s.jsx("span",{className:"eval-check-group",children:a.group}),s.jsx("button",{type:"button",className:"pg-dismiss eval-check-remove",title:"Remove check","aria-label":`Remove ${m}`,onClick:o,children:"×"})]}),(a==null?void 0:a.description)&&s.jsx("div",{className:"pg-exec-param-desc",children:a.description}),!a&&s.jsx("div",{className:"eval-check-missing",children:"This check no longer exists."}),(a==null?void 0:a.error)&&s.jsx("div",{className:"eval-check-missing",children:a.error}),(r||d)&&s.jsxs("div",{className:"eval-check-fields",children:[r&&s.jsx("div",{className:"eval-check-params",children:r}),d&&s.jsxs("label",{className:"eval-check-threshold",title:"For a check that returns a score: pass at or above this. Left empty, the score is just recorded.",children:[s.jsx("span",{children:"Pass at score ≥"}),s.jsx("input",{type:"number",step:"any",placeholder:"—","aria-label":"Threshold",value:n.threshold??"",onChange:k=>l({threshold:k.target.value===""?void 0:Number(k.target.value)})})]})]})]})}function Fe({label:n,children:a}){return s.jsxs("div",{className:"eval-select",children:[s.jsx("span",{className:"proppy-catalog-label",children:n}),s.jsx("span",{"aria-hidden":!0,className:"proppy-catalog-chevron",children:"▾"}),a]})}function et({checks:n,onAdd:a}){const l=new Map;for(const r of n){if(r.error)continue;const m=r.group??"Playground";l.set(m,[...l.get(m)??[],r])}const o=n.filter(r=>r.error);return s.jsxs("div",{className:"eval-add-check",children:[s.jsxs("div",{className:"pg-add-msg-btn pg-add-question",children:["+ Add check",s.jsxs("select",{"aria-label":"Add check",className:"pg-model-overlay-select",value:"",onChange:r=>r.target.value&&a(r.target.value),children:[s.jsx("option",{value:"",children:"+ Add check…"}),[...l].map(([r,m])=>s.jsx("optgroup",{label:r,children:m.map(d=>s.jsx("option",{value:d.uri,title:d.description,children:d.label},d.uri))},r))]})]}),o.map(r=>s.jsxs("div",{className:"pg-exec-error",children:[s.jsx("code",{children:r.uri})," failed to load: ",r.error]},r.uri))]})}function st(n){const[a,l]=v.useState([]),[o,r]=v.useState(),[m,d]=v.useState(new Set(["head"])),[k,x]=v.useState(4),h=v.useRef(void 0),y=a.find(b=>b.wip&&b.onHead),g=a.filter(b=>!b.wip&&b.names.length>0),p=n&&`${n.providerId}:${n.id}`;v.useEffect(()=>{if(!(n!=null&&n.providerId))return;let b=!1;return Promise.all([$s(n).catch(()=>[]),Cs(n.providerId).catch(()=>{})]).then(([M,O])=>{if(b)return;l(M),r(O);const A=M.find(E=>E.wip&&E.onHead);A&&A.id!==h.current&&(h.current=A.id,d(E=>new Set([...E,"wip"])))}),()=>{b=!0}},[p,n==null?void 0:n.wipId]);const j=b=>d(M=>{const O=new Set(M);return O.has(b)?O.delete(b):O.add(b),O}),N=!y&&g.length===0,C=[...N||m.has("head")?[{kind:"head"}]:[],...y&&m.has("wip")?[{kind:"wip",variation:y.id}]:[],...g.filter(b=>m.has(b.id)).map(b=>({kind:"variation",variation:b.id,label:b.names[0]}))],i=o&&!o.versioned?"⚠️ Results won't record a version.":o&&!o.clean?"⚠️ There are uncommitted changes.":void 0;return{wip:y,named:g,single:N,chosen:m,toggle:j,concurrency:k,setConcurrency:x,arms:C,warning:i}}function tt({choices:n}){const{wip:a,named:l,single:o,chosen:r,toggle:m,concurrency:d,setConcurrency:k}=n,x=v.useId();return s.jsxs("div",{className:"eval-run-options",role:"group","aria-labelledby":o?void 0:x,children:[!o&&s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"pg-exec-param-name",id:x,children:"Run against"}),s.jsxs("label",{children:[s.jsx("input",{type:"checkbox",checked:r.has("head"),onChange:()=>m("head")}),"Working tree"]}),a&&s.jsxs("label",{children:[s.jsx("input",{type:"checkbox",checked:r.has("wip"),onChange:()=>m("wip")}),"Unsaved edits"]}),l.map(h=>s.jsxs("label",{children:[s.jsx("input",{type:"checkbox",checked:r.has(h.id),onChange:()=>m(h.id)}),h.names[0]]},h.id)),s.jsx("div",{className:"pg-exec-section"})]}),s.jsxs("label",{className:"eval-run-concurrency",children:["Parallel workers",s.jsx("input",{type:"number",min:1,value:d,onChange:h=>k(Math.max(1,Number(h.target.value)||1))})]})]})}function nt({choices:n,disabled:a,onRun:l}){const{arms:o,concurrency:r,warning:m}=n,[d,k]=v.useState(!1);return s.jsxs("div",{className:"eval-run-control",children:[m&&s.jsx("p",{className:"eval-run-warning",children:m}),s.jsx("button",{type:"button",className:"pg-run-btn",disabled:a||d||o.length===0,title:a?"Fix the problems below to run":o.length===0?"Choose what to run against":void 0,onClick:async()=>{k(!0),await l({arms:o,concurrency:r}),k(!1)},children:d?"…":"▶ Run"})]})}function at({runs:n,progress:a,onOpen:l,onCancel:o,onDelete:r}){const[m,d]=v.useState(new Set),k=async x=>{d(h=>new Set(h).add(x.id)),await r(x),d(h=>{const y=new Set(h);return y.delete(x.id),y})};return s.jsx("div",{className:"eval-runs-scroll",children:s.jsx("table",{className:"eval-runs",children:s.jsx("tbody",{children:n.map(x=>{const h=a[x.id],y=(h==null?void 0:h.status)??x.status,g=(h==null?void 0:h.counts)??x.counts,p=(h==null?void 0:h.done)??x.done;return s.jsxs("tr",{className:"eval-run-row",onClick:()=>l(x),children:[s.jsx("td",{children:De(x.startedAt)}),s.jsx("td",{children:x.arms.map(j=>j.label).join(" · ")}),s.jsx("td",{children:y==="running"?s.jsxs(s.Fragment,{children:[s.jsx("progress",{max:x.total,value:p})," ",p,"/",x.total]}):s.jsx("span",{className:`eval-status eval-status-${y}`,children:y==="done"?`${Ts(Fs(g))} passing`:y})}),s.jsxs("td",{className:"eval-run-counts",children:[g.fail>0&&s.jsxs("span",{className:"eval-count-fail",children:[g.fail," failed"]}),g.error>0&&s.jsxs("span",{className:"eval-count-error",children:[g.error," errors"]})]}),s.jsxs("td",{className:"eval-run-badges",children:[x.dirty&&s.jsx("span",{className:"eval-badge",title:"Run with uncommitted changes",children:"uncommitted changes"}),x.drifted&&s.jsx("span",{className:"eval-badge",title:"The working tree changed mid-run",children:"drifted"}),y==="running"&&s.jsx("button",{type:"button",className:"dialog-btn-cancel",onClick:j=>{j.stopPropagation(),o(x)},children:"Cancel"})]}),s.jsx("td",{className:"eval-run-actions",children:s.jsx("button",{type:"button",className:"eval-run-delete",title:"Delete run","aria-label":`Delete run from ${De(x.startedAt)}`,disabled:m.has(x.id),onClick:j=>{j.stopPropagation(),k(x)},children:s.jsx(Ae,{})})})]},x.id)})})})})}export{it as default};