evalution 1.0.7 → 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.
@@ -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-DOmAST6D.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 Ce,r as v,t as es,u as ss,a as $e,v as ts,w as ns,x as as,y as cs,z as rs,A as Ie,B as is,C as ls,D as os,F as ds,j as s,G as us,H as hs,T as Me,P as Ee,I as Re,J as z,e as ms,K as ps,R as xs,L as vs,M as fs,N as gs,O as js,Q as bs,U as ks,V as ys,W as Ns,X as ws,Y as Ss,Z as Cs,_ as $s,$ as Is,a0 as Es,f as Pe,h as Rs,a1 as Ps,m as Os,n as Ds,a2 as Ts,a3 as Ms,a4 as ne,a5 as Fs,a6 as As,a7 as Bs,a8 as Us,a9 as Ks}from"./index-DOmAST6D.js";function Fe(a,n){var l;return(l=n.find(o=>o.def.name===a.name&&o.def.type.syntax===a.type.syntax))==null?void 0:l.id}function _s(a,n){if((a==null?void 0:a.kind)==="object")return a.properties[n];if((a==null?void 0:a.kind)==="value"&&a.value.kind==="object"){const l=a.value.properties[n];return l&&{kind:"value",value:l}}}function Ae(a,n,l,o,d,p){if(n&&n.kind!=="object")return n;if(!n){const m=Fe(a,o);if(m)return p.push(d),{kind:"dataset",field:m}}if(a.type.kind==="object"){const m={...(n==null?void 0:n.kind)==="object"?n.properties:{}},g=[];for(const u of a.type.properties){const f=Ae(u,m[u.name],_s(l,u.name),o,`${d}.${u.name}`,g);f&&(m[u.name]=f)}const x=g.length>0;return!n&&!x&&l?(p.push(d),l):(p.push(...g),Object.keys(m).length===0?n:{kind:"object",properties:m})}return!n&&l?(p.push(d),l):n}function Ls(a,n,l){const o={...n},d=[...Object.values(a.functionInputs),...Object.values(a.executeInputs)].flatMap(Ce);for(;d.length>0;){const p=d.pop(),m=l==null?void 0:l[p];if(Object.hasOwn(o,p)||!m)continue;const{receipt:g,...x}=m;o[p]=x,d.push(...Object.values(m.args??{}).flatMap(Ce))}return Object.keys(o).length>0?o:void 0}function Vs(a){const{prompt:n,fields:l,stored:o}=a,d=[],p=(u,f,y,j)=>{const S={...f};for(const I of u){const E=Ae(I,f[I.name],y==null?void 0:y[I.name],l,`${j}:${I.name}`,d);E&&(S[I.name]=E)}return S},m={functionInputs:p(n.functionParameters,a.inputs.functionInputs,o==null?void 0:o.functionInputs,"fn"),executeInputs:p(n.executeParameters??[],a.inputs.executeInputs,o==null?void 0:o.executeInputs,"exec")},g=Ls(m,a.inputs.resources,o==null?void 0:o.resources);g&&(m.resources=g);const x=a.checks.map(u=>{const f=a.checkInfos.find(j=>j.uri===u.uri);if(!f)return u;const y={...u.args};for(const j of f.parameters){if(y[j.name])continue;const S=Fe(j,l);if(S){y[j.name]={kind:"dataset",field:S},d.push(`check:${u.id}:${j.name}`);continue}const I=n.functionParameters.some(E=>E.name===j.name&&E.type.syntax===j.type.syntax)?"function":(n.executeParameters??[]).some(E=>E.name===j.name&&E.type.syntax===j.type.syntax)?"execute":void 0;I&&(y[j.name]={kind:"input",half:I,path:j.name},d.push(`check:${u.id}:${j.name}`))}return{...u,args:y}});return{inputs:m,checks:x,matched:d}}const Ws={resources:[]},Ys=400;function Oe(a){const n=l=>Object.fromEntries(Object.entries(l).map(([o,d])=>[o,Fs(d)]));return{fn:n(a.inputs.functionInputs),exec:n(a.inputs.executeInputs),checks:Object.fromEntries(a.checks.map(l=>[l.id,n(l.args)])),instances:ys(a.inputs.resources)}}function ae(a){return Object.fromEntries(Object.entries(a).flatMap(([n,l])=>{const o=As(l);return o?[[n,o]]:[]}))}function qs(a){let n=a.length+1;for(;a.some(l=>l.id===`c${n}`);)n++;return`c${n}`}function De(a){var n;return(n=Object.entries(a.resources??{}).find(([,l])=>l===Bs))==null?void 0:n[0]}function st({providerId:a,evalId:n,prompts:l,datasets:o,version:d,datasetVersion:p,progress:m,onOpenRun:g,onRunStarted:x,onOpenPrompt:u,onOpenDataset:f,onDeleted:y,onDuplicated:j,onRunDeleted:S,agents:I=[],onAskAgent:E}){var we,Se;const[r,b]=v.useState(null),[T,O]=v.useState(null),[A,R]=v.useState(null),[M,G]=v.useState(),[F,Be]=v.useState([]),[ce,J]=v.useState([]),[N,W]=v.useState({fn:{},exec:{},checks:{},instances:{}}),[Ue,re]=v.useState(new Set),[Ke,X]=v.useState(!1),[ie,Y]=v.useState(""),i=r?es(l,r.prompt):void 0,le=zs(i),$=r&&o.find(e=>e.providerId===r.dataset.providerId&&e.id===r.dataset.id),q=(i==null?void 0:i.functionParameters)??[],K=(i==null?void 0:i.executeParameters)??[],oe=v.useMemo(()=>{var e;return new Map((((e=i==null?void 0:i.inputSources)==null?void 0:e.resources)??[]).map(t=>[t.uri,t]))},[i==null?void 0:i.inputSources]),de=v.useRef(null);v.useEffect(()=>{let e=!1;return ss(a,n).then(t=>{if(!e&&(b(t),de.current!==n)){de.current=n,Y(t.name);const c=Oe(t);P.current=c,W(c)}}).catch(t=>!e&&O(t.message)),$e(a,n).then(t=>!e&&J(t)).catch(()=>{}),()=>{e=!0}},[a,n,d]);const ue=Object.values(m).filter(e=>e.evalId===n).map(e=>`${e.runId}:${e.done}`).join();v.useEffect(()=>{ue&&$e(a,n).then(J).catch(()=>{})},[ue]);const Z=r==null?void 0:r.dataset.providerId,ee=r==null?void 0:r.dataset.id;v.useEffect(()=>{!Z||!ee||ts(Z,ee).then(e=>G(e.dataset.fields)).catch(()=>G([]))},[Z,ee,p]);const he=i==null?void 0:i.providerId;v.useEffect(()=>{ns().then(e=>{var t,c;return Be(((t=e.find(h=>h.providerId===he))==null?void 0:t.checks)??((c=e[0])==null?void 0:c.checks)??[])}).catch(()=>{})},[he]);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 as(a,n,e))}catch(t){R(t.message)}},[a,n]);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 _(),Ys)},te=e=>{const t=Ns(e.instances);return{functionInputs:ae(e.fn),executeInputs:ae(e.exec),...t&&{resources:t}}},B=(e,t)=>t.map(c=>({...c,args:ae(e.checks[c.id]??{})})),P=v.useRef(N),me=v.useRef(r);me.current=r;const L=(e,t=(c=>(c=me.current)==null?void 0:c.checks)()??[])=>{P.current=e,W(e),D({inputs:te(e),checks:B(e,t)})},_e=(r==null?void 0:r.checks.map(e=>`${e.id}=${e.uri}`).join())??"";v.useEffect(()=>{if(!r||!i||!M)return;const e={inputs:te(N),checks:B(N,r.checks)},t=Vs({prompt:i,fields:M,inputs:e.inputs,checks:e.checks,checkInfos:F,stored:cs(i)});if(t.matched.length===0)return;const c=Oe({inputs:t.inputs,checks:t.checks});re(h=>new Set([...h,...t.matched])),P.current=c,W(c),D({inputs:t.inputs,checks:t.checks})},[r==null?void 0:r.id,i==null?void 0:i.id,M,F,_e]);const pe=e=>re(t=>{if(!t.has(e))return t;const c=new Set(t);return c.delete(e),c}),xe=te(N),Le=r?B(N,r.checks):[],V=r?rs(xe,Le,{...i&&{prompt:i},...M&&{fields:M},checks:F}):[];r&&!i&&V.unshift("The eval's prompt no longer exists"),r&&!$&&V.unshift("The eval's dataset no longer exists");const Q=Ie(is(ls(i==null?void 0:i.inputSources,N.instances),{functionParameters:q,executeParameters:K,bindings:xe,fields:M??[],offerMismatches:!0,newColumn:!0})),ve={functionParameters:q,executeParameters:K,fields:M},fe=Ie(Object.fromEntries(((r==null?void 0:r.checks)??[]).map(e=>{var t;return[e.id,os(((t=F.find(c=>c.uri===e.uri))==null?void 0:t.parameters)??[],ve)]}))),ge=(e,t)=>{const c=P.current,h=typeof e=="function"?e(c.instances):e;if(!t)return L({...c,instances:h});const[k,w]=t.kind==="rename"?[t.from,t.to]:[t.name,null];L({fn:ne(c.fn,k,w),exec:ne(c.exec,k,w),checks:Object.fromEntries(Object.entries(c.checks).map(([C,U])=>[C,ne(U,k,w)])),instances:h})},je=ds({instances:N.instances,catalogByUri:oe,rowsMayDeclare:!0,adopt:e=>{const t=Ts(P.current.instances,e,oe);return ge(t.instances),t.uri},describeOther:(e,t)=>Ms(e,t,ve)}),be=async(e,t)=>{if(!r||!(i!=null&&i.providerId))return t(null);try{const c=await Us(r.dataset.providerId,r.dataset.id,"checkUri"in e?{from:{providerId:i.providerId,...e}}:{from:{providerId:i.providerId,promptId:i.id,...e}});G(h=>[...h??[],c]),t(Ks(c.id))}catch(c){R(c.message),t(null)}},Ve=e=>(t,c)=>{pe(`${e}:${t}`);const h=De(c),k=w=>{const C={...c.resources};h!==void 0&&(w?C[h]=w:delete C[h]);const U=P.current;L({...U,[e]:{...U[e],[t]:{...c,resources:C}}})};if(h===void 0){const w=P.current;L({...w,[e]:{...w[e],[t]:c}});return}be({half:e==="fn"?"function":"execute",path:h?`${t}.${h}`:t},k)},We=e=>(t,c)=>{pe(`check:${e.id}:${t}`);const h=De(c),k=w=>{const C=P.current;L({...C,checks:{...C.checks,[e.id]:{...C.checks[e.id],[t]:w}}})};if(h===void 0)return k(c);be({checkUri:e.uri,path:h?`${t}.${h}`:t},w=>{const C={...c.resources};w?C[h]=w:delete C[h],k({...c,resources:C})})},Ye=(e,t)=>{if(!r)return;const c=r.checks.map(h=>{if(h.id!==e)return h;const k={...h,...t};return t.threshold===void 0&&"threshold"in t&&delete k.threshold,t.label===void 0&&"label"in t&&delete k.label,k});D({checks:B(N,c)})},qe=e=>{if(!r)return;const t=[...r.checks,{id:qs(r.checks),uri:e,args:{}}];D({checks:B(N,t)},!0)},He=e=>{if(!r)return;const{[e]:t,...c}=N.checks,h={...N,checks:c};P.current=h,W(h),D({checks:B(h,r.checks.filter(k=>k.id!==e))},!0)},ke=()=>{X(!1);const e=ie.trim();e&&r&&e!==r.name?D({name:e},!0):r&&Y(r.name)},Qe=async()=>{if(r)try{j(await ws(Ss(r),a))}catch(e){R(e.message)}},ze=async()=>{if(r&&window.confirm(`Delete "${r.name}" and all its runs?`))try{await Cs(a,n),y()}catch(e){R(e.message)}},Ge=async e=>{var c;const t=(((c=m[e.id])==null?void 0:c.status)??e.status)==="running";if(window.confirm(Os(e.startedAt,t)))try{await Ds(a,e.id),J(h=>h.filter(k=>k.id!==e.id)),S(e)}catch(h){R(h.message)}};if(T)return s.jsxs("div",{className:"eval-view eval-view-error",children:["Error: ",T]});if(!r)return s.jsx("div",{className:"eval-view"});const ye=(e,{key:t,label:c,matchedKey:h,selection:k,onChange:w,sources:C,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:Is(e.type.syntax,60)}),Ue.has(h)&&s.jsx("span",{className:"eval-matched",title:"Filled in for you — change it if it's wrong",children:"matched"})]}),s.jsx(Es,{propDef:e,selection:k,onChange:w,resources:C.resources,slots:U,context:je})]},t),Ne=(e,t)=>e.map(c=>ye(c,{key:`${t}:${c.name}`,label:t==="exec"?`execute.${c.name}`:c.name,matchedKey:`${t}:${c.name}`,selection:N[t][c.name]??{},onChange:h=>Ve(t)(c.name,h),sources:Q,slots:t==="fn"?Q.functionSlots:Q.executeSlots})),Je=s.jsxs("div",{className:"pg-prompt-header eval-header",children:[s.jsxs("div",{className:"pg-prompt-header-row",children:[Ke?s.jsx("form",{className:"dataset-view-rename",onSubmit:e=>{e.preventDefault(),ke()},children:s.jsx("input",{autoFocus:!0,"aria-label":"Eval name",value:ie,onChange:e=>Y(e.target.value),onFocus:e=>e.target.select(),onBlur:ke,onKeyDown:e=>{e.key==="Escape"&&(Y(r.name),X(!1))}})}):s.jsx("span",{className:"pg-prompt-name",onDoubleClick:()=>X(!0),title:"Double-click to rename",children:r.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:()=>R(null),children:"×"})]}),E&&s.jsx(us,{agents:I,onAsk:E}),s.jsx("button",{type:"button",className:"trace-view-prompt-btn",onClick:Qe,title:"Duplicate eval","aria-label":"Duplicate eval",children:s.jsx(hs,{})}),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(Me,{})})]})]}),s.jsxs("div",{className:"eval-header-links",children:[s.jsxs("button",{type:"button",className:"eval-header-link",disabled:!i,title:"Open the prompt",onClick:()=>i&&u(i),children:[s.jsx(Ee,{}),s.jsx("span",{className:"eval-header-link-name",children:(i==null?void 0:i.name)??"Prompt missing"}),i&&"↗"]}),s.jsxs("button",{type:"button",className:"eval-header-link",disabled:!$,title:"Open the dataset",onClick:()=>$&&f($),children:[s.jsx(Re,{}),s.jsx("span",{className:"eval-header-link-name",children:($==null?void 0:$.name)??"Dataset missing"}),$&&"↗"]})]})]}),Xe=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(Ee,{}),"Prompt"]}),s.jsx(Te,{label:(i==null?void 0:i.name)??"(missing prompt)",children:s.jsxs("select",{className:"pg-model-overlay-select","aria-label":"Prompt",value:i?`${i.providerId}:${i.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:[!i&&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(Re,{}),"Dataset"]}),s.jsx(Te,{label:($==null?void 0:$.name)??"(missing dataset)",children:s.jsxs("select",{className:"pg-model-overlay-select","aria-label":"Dataset",value:$?z($):"",onChange:e=>{const t=o.find(c=>z(c)===e.target.value);t&&D({dataset:{providerId:t.providerId,id:t.id}},!0)},children:[!$&&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"}),r.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."}),r.checks.map(e=>{var t;return s.jsx(Hs,{check:e,info:F.find(c=>c.uri===e.uri),onChangeCheck:c=>Ye(e.id,c),onRemove:()=>He(e.id),children:(t=F.find(c=>c.uri===e.uri))==null?void 0:t.parameters.map(c=>{var h,k;return ye(c,{key:`check:${e.id}:${c.name}`,label:c.name,matchedKey:`check:${e.id}:${c.name}`,selection:((h=N.checks[e.id])==null?void 0:h[c.name])??{},onChange:w=>We(e)(c.name,w),sources:fe[e.id]??Ws,slots:((k=fe[e.id])==null?void 0:k.functionSlots)??{}})})},e.id)}),s.jsx(Qs,{checks:F,onAdd:qe})]}),s.jsxs("section",{className:"eval-section",children:[s.jsx("h4",{className:"pg-msg-header pg-role-label eval-section-title",children:"Runs"}),ce.length===0?s.jsx("p",{className:"eval-empty",children:"No runs yet. Run it from the panel."}):s.jsx(Xs,{runs:ce,progress:m,onOpen:e=>g(e,r.name),onCancel:e=>ms(a,e.id).catch(t=>R(t.message)),onDelete:Ge})]})]}),Ze=s.jsxs(ps,{title:"Inputs",notice:V.length>0&&s.jsx("ul",{className:"eval-problems","aria-label":"Problems",children:V.map(e=>s.jsx("li",{children:e},e))}),footer:s.jsx(Js,{choices:le,disabled:V.length>0,onRun:async e=>{await _();try{const t=await fs(a,n,e);x(t,r.name)}catch(t){R(t instanceof gs?`Can't run: ${t.problems.join("; ")}`:t.message)}}}),children:[i?s.jsxs(s.Fragment,{children:[Ne(q,"fn"),K.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"pg-exec-section"}),Ne(K,"exec")]}),q.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"}),((((we=i==null?void 0:i.inputSources)==null?void 0:we.resources.length)??0)>0||Object.keys(N.instances).length>0)&&s.jsx(xs,{instances:N.instances,onChange:ge,sources:Q,catalog:((Se=i==null?void 0:i.inputSources)==null?void 0:Se.resources)??[],referencedBy:e=>vs(e,N.instances,[{selections:N.fn},{selections:N.exec},...Object.values(N.checks).map(t=>({selections:t}))]),context:je}),s.jsx("div",{className:"pg-exec-section"}),s.jsx(Gs,{choices:le})]});return s.jsx("div",{className:"eval-view",children:s.jsx(js,{header:Je,editor:Xe,panel:Ze})})}function Hs({check:a,info:n,onChangeCheck:l,onRemove:o,children:d}){const p=a.label??(n==null?void 0:n.label)??a.uri,m=(n==null?void 0:n.group)!=="Built-in"||a.threshold!==void 0;return s.jsxs("div",{className:"eval-check",children:[s.jsxs("div",{className:"eval-check-header",children:[s.jsx($s,{className:"eval-check-label",label:"Check name",title:a.uri,value:p,onCommit:g=>l({label:g.trim()||void 0})}),(n==null?void 0:n.group)&&s.jsx("span",{className:"eval-check-group",children:n.group}),s.jsx("button",{type:"button",className:"pg-dismiss eval-check-remove",title:"Remove check","aria-label":`Remove ${p}`,onClick:o,children:"×"})]}),(n==null?void 0:n.description)&&s.jsx("div",{className:"pg-exec-param-desc",children:n.description}),!n&&s.jsx("div",{className:"eval-check-missing",children:"This check no longer exists."}),(n==null?void 0:n.error)&&s.jsx("div",{className:"eval-check-missing",children:n.error}),(d||m)&&s.jsxs("div",{className:"eval-check-fields",children:[d&&s.jsx("div",{className:"eval-check-params",children:d}),m&&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:a.threshold??"",onChange:g=>l({threshold:g.target.value===""?void 0:Number(g.target.value)})})]})]})]})}function Te({label:a,children:n}){return s.jsxs("div",{className:"eval-select",children:[s.jsx("span",{className:"proppy-catalog-label",children:a}),s.jsx("span",{"aria-hidden":!0,className:"proppy-catalog-chevron",children:"▾"}),n]})}function Qs({checks:a,onAdd:n}){const l=new Map;for(const d of a){if(d.error)continue;const p=d.group??"Playground";l.set(p,[...l.get(p)??[],d])}const o=a.filter(d=>d.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:d=>d.target.value&&n(d.target.value),children:[s.jsx("option",{value:"",children:"+ Add check…"}),[...l].map(([d,p])=>s.jsx("optgroup",{label:d,children:p.map(m=>s.jsx("option",{value:m.uri,title:m.description,children:m.label},m.uri))},d))]})]}),o.map(d=>s.jsxs("div",{className:"pg-exec-error",children:[s.jsx("code",{children:d.uri})," failed to load: ",d.error]},d.uri))]})}function zs(a){const[n,l]=v.useState([]),[o,d]=v.useState(),[p,m]=v.useState(new Set(["head"])),[g,x]=v.useState(4),u=v.useRef(void 0),f=n.find(b=>b.wip&&b.onHead),y=n.filter(b=>!b.wip&&b.names.length>0),j=a&&`${a.providerId}:${a.id}`;v.useEffect(()=>{if(!(a!=null&&a.providerId))return;let b=!1;return Promise.all([bs(a).catch(()=>[]),ks(a.providerId).catch(()=>{})]).then(([T,O])=>{if(b)return;l(T),d(O);const A=T.find(R=>R.wip&&R.onHead);A&&A.id!==u.current&&(u.current=A.id,m(R=>new Set([...R,"wip"])))}),()=>{b=!0}},[j,a==null?void 0:a.wipId]);const S=b=>m(T=>{const O=new Set(T);return O.has(b)?O.delete(b):O.add(b),O}),I=!f&&y.length===0,E=[...I||p.has("head")?[{kind:"head"}]:[],...f&&p.has("wip")?[{kind:"wip",variation:f.id}]:[],...y.filter(b=>p.has(b.id)).map(b=>({kind:"variation",variation:b.id,label:b.names[0]}))],r=o&&!o.versioned?"⚠️ Results won't record a version.":o&&!o.clean?"⚠️ There are uncommitted changes.":void 0;return{wip:f,named:y,single:I,chosen:p,toggle:S,concurrency:g,setConcurrency:x,arms:E,warning:r}}function Gs({choices:a}){const{wip:n,named:l,single:o,chosen:d,toggle:p,concurrency:m,setConcurrency:g}=a,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:d.has("head"),onChange:()=>p("head")}),"Working tree"]}),n&&s.jsxs("label",{children:[s.jsx("input",{type:"checkbox",checked:d.has("wip"),onChange:()=>p("wip")}),"Unsaved edits"]}),l.map(u=>s.jsxs("label",{children:[s.jsx("input",{type:"checkbox",checked:d.has(u.id),onChange:()=>p(u.id)}),u.names[0]]},u.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:m,onChange:u=>g(Math.max(1,Number(u.target.value)||1))})]})]})}function Js({choices:a,disabled:n,onRun:l}){const{arms:o,concurrency:d,warning:p}=a,[m,g]=v.useState(!1);return s.jsxs("div",{className:"eval-run-control",children:[p&&s.jsx("p",{className:"eval-run-warning",children:p}),s.jsx("button",{type:"button",className:"pg-run-btn",disabled:n||m||o.length===0,title:n?"Fix the problems below to run":o.length===0?"Choose what to run against":void 0,onClick:async()=>{g(!0),await l({arms:o,concurrency:d}),g(!1)},children:m?"…":"▶ Run"})]})}function Xs({runs:a,progress:n,onOpen:l,onCancel:o,onDelete:d}){const[p,m]=v.useState(new Set),g=async x=>{m(u=>new Set(u).add(x.id)),await d(x),m(u=>{const f=new Set(u);return f.delete(x.id),f})};return s.jsx("div",{className:"eval-runs-scroll",children:s.jsx("table",{className:"eval-runs",children:s.jsx("tbody",{children:a.map(x=>{const u=n[x.id],f=(u==null?void 0:u.status)??x.status,y=(u==null?void 0:u.counts)??x.counts,j=(u==null?void 0:u.done)??x.done;return s.jsxs("tr",{className:"eval-run-row",onClick:()=>l(x),children:[s.jsx("td",{children:Pe(x.startedAt)}),s.jsx("td",{children:x.arms.map(S=>S.label).join(" · ")}),s.jsx("td",{children:f==="running"?s.jsxs(s.Fragment,{children:[s.jsx("progress",{max:x.total,value:j})," ",j,"/",x.total]}):s.jsx("span",{className:`eval-status eval-status-${f}`,children:f==="done"?`${Rs(Ps(y))} passing`:f})}),s.jsxs("td",{className:"eval-run-counts",children:[y.fail>0&&s.jsxs("span",{className:"eval-count-fail",children:[y.fail," failed"]}),y.error>0&&s.jsxs("span",{className:"eval-count-error",children:[y.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"}),f==="running"&&s.jsx("button",{type:"button",className:"dialog-btn-cancel",onClick:S=>{S.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 ${Pe(x.startedAt)}`,disabled:p.has(x.id),onClick:S=>{S.stopPropagation(),g(x)},children:s.jsx(Me,{})})})]},x.id)})})})})}export{st as default};