@axlsdk/studio 0.23.1 → 0.23.3

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.
@@ -308,11 +308,11 @@ ${i.content??""}`).join(`
308
308
 
309
309
  ───
310
310
 
311
- `)})]}):null}function j2({event:s}){const r=Lg(s);return r?n.jsxs(n.Fragment,{children:[s.model&&n.jsxs("p",{className:"text-xs mb-1",children:[n.jsx("strong",{children:"Model:"})," ",s.model,r.turn!=null&&n.jsxs("span",{className:"ml-2 text-[hsl(var(--muted-foreground))]",children:["· turn ",r.turn]})]}),s.promptVersion&&n.jsxs("p",{className:"text-xs mb-1",children:[n.jsx("strong",{children:"Version:"})," ",s.promptVersion]}),s.tokens&&(s.tokens.input!=null||s.tokens.output!=null)&&n.jsxs("p",{className:"text-xs mb-1",children:[n.jsx("strong",{children:"Tokens:"}),s.tokens.input!=null?` in=${s.tokens.input}`:"",s.tokens.output!=null?` out=${s.tokens.output}`:"",s.tokens.reasoning?` reasoning=${s.tokens.reasoning}`:""]}),r.thinking&&n.jsx(da,{label:"Thinking",content:r.thinking,tone:"info"}),r.response&&n.jsx(da,{label:"Response",content:r.response,defaultOpen:!0}),r.error&&n.jsx(da,{label:"Provider error",content:r.error,tone:"warning",defaultOpen:!0})]}):null}function N2({event:s}){const r=g2(s);return r?n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"flex items-center gap-2 mb-2 text-xs",children:n.jsx("span",{className:F("px-2 py-0.5 rounded-full text-[10px] font-medium",r.approved?"bg-green-100 text-green-800 dark:bg-green-950/40 dark:text-green-300":"bg-red-100 text-red-800 dark:bg-red-950/40 dark:text-red-300"),children:r.approved?"APPROVED":"DENIED"})}),r.reason&&n.jsxs("p",{className:"text-xs mb-2",children:[n.jsx("strong",{children:"Reason:"})," ",r.reason]}),r.args!==void 0&&n.jsxs(n.Fragment,{children:[n.jsx("p",{className:"text-[11px] font-medium uppercase tracking-wider opacity-70 mb-1",children:"Arguments"}),n.jsx(Ps,{data:r.args})]})]}):null}function qg({status:s}){const r=s==="succeeded"?"bg-green-100 text-green-800 dark:bg-green-950/40 dark:text-green-300":s==="cancelled"?"bg-amber-100 text-amber-800 dark:bg-amber-950/40 dark:text-amber-300":"bg-red-100 text-red-800 dark:bg-red-950/40 dark:text-red-300";return n.jsx("span",{className:F("px-2 py-0.5 rounded-full text-[10px] font-medium",r),children:s.toUpperCase()})}function S2({event:s}){if(s.type!=="tool_call_end"||s.schemaVersion!==2)return null;const{outcome:r}=s.data;return n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"flex items-center gap-2 mb-2 text-xs",children:[n.jsx(qg,{status:r.status}),r.status==="failed"&&n.jsxs("span",{className:"text-[hsl(var(--muted-foreground))]",children:[r.failure.phase," · ",r.failure.kind," · ",r.failure.disposition]}),r.status==="cancelled"&&n.jsx("span",{className:"text-[hsl(var(--muted-foreground))]",children:r.cancellation.phase})]}),s.data.requestedTool&&s.data.requestedTool!==s.tool&&n.jsxs("p",{className:"text-xs mb-2",children:[n.jsx("strong",{children:"Requested as:"})," ",s.data.requestedTool]}),n.jsx("p",{className:"text-[11px] font-medium uppercase tracking-wider opacity-70 mb-1",children:"Arguments"}),n.jsx(Ps,{data:s.data.args}),r.status==="succeeded"&&n.jsxs(n.Fragment,{children:[n.jsx("p",{className:"text-[11px] font-medium uppercase tracking-wider opacity-70 mt-2 mb-1",children:"Result"}),n.jsx(Ps,{data:r.result})]}),r.status==="failed"&&"result"in r.failure&&n.jsxs(n.Fragment,{children:[n.jsx("p",{className:"text-[11px] font-medium uppercase tracking-wider opacity-70 mt-2 mb-1",children:"Result before failure"}),n.jsx(Ps,{data:r.failure.result})]}),r.status==="failed"&&n.jsx(da,{label:"Host failure",content:`${r.failure.error.name}: ${r.failure.error.message}`,tone:"warning",defaultOpen:!0}),r.status==="denied"&&r.reason&&n.jsxs("p",{className:"text-xs mt-2",children:[n.jsx("strong",{children:"Reason:"})," ",r.reason]}),r.status==="cancelled"&&r.cancellation.reason&&n.jsxs("p",{className:"text-xs mt-2",children:[n.jsx("strong",{children:"Reason:"})," ",r.cancellation.reason]}),r.status==="cancelled"&&"result"in r.cancellation&&n.jsxs(n.Fragment,{children:[n.jsx("p",{className:"text-[11px] font-medium uppercase tracking-wider opacity-70 mt-2 mb-1",children:"Result before cancellation"}),n.jsx(Ps,{data:r.cancellation.result})]})]})}function w2({event:s}){return s.type!=="tool_call_rejected"?null:n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"flex items-center gap-2 mb-2 text-xs",children:[n.jsx(qg,{status:"rejected"}),n.jsx("span",{className:"text-[hsl(var(--muted-foreground))]",children:s.data.reason})]}),n.jsxs("p",{className:"text-xs mb-2",children:[n.jsx("strong",{children:"Requested tool:"})," ",s.data.requestedTool]}),s.data.reason==="unavailable"&&n.jsxs("p",{className:"text-xs mb-2",children:[n.jsx("strong",{children:"Available tools:"})," ",s.data.availableTools.join(", ")||"none"]}),s.data.reason==="invalid_arguments"&&n.jsx(Ps,{data:{args:s.data.args,issues:s.data.issues}}),s.data.reason==="invalid_json"&&n.jsx(da,{label:"Parse error",content:s.data.message,tone:"warning",defaultOpen:!0})]})}function k2({event:s}){const r=Hg(s);if(!r)return null;const i=r.valid===!1||r.blocked===!0;return n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"flex items-center gap-2 mb-2 text-xs",children:[n.jsx("span",{className:F("px-2 py-0.5 rounded-full text-[10px] font-medium",i?"bg-red-100 text-red-800 dark:bg-red-950/40 dark:text-red-300":"bg-green-100 text-green-800 dark:bg-green-950/40 dark:text-green-300"),children:i?"FAILED":"PASSED"}),r.attempt!=null&&r.maxAttempts!=null&&n.jsxs("span",{className:"text-[hsl(var(--muted-foreground))]",children:["attempt ",r.attempt," of ",r.maxAttempts]}),r.guardrailType&&n.jsxs("span",{className:"text-[hsl(var(--muted-foreground))]",children:["· ",r.guardrailType]})]}),r.reason&&n.jsxs("p",{className:"text-xs mb-2",children:[n.jsx("strong",{children:"Reason:"})," ",r.reason]}),r.feedbackMessage&&n.jsx(da,{label:"Retry feedback sent to LLM",content:r.feedbackMessage,tone:"warning",defaultOpen:!0})]})}function C2({event:s}){if(s.type!=="ask_start")return null;const{prompt:r}=s;return n.jsxs(n.Fragment,{children:[r.length>0?n.jsx(da,{label:"Prompt",content:r,defaultOpen:!0}):n.jsx("p",{className:"text-xs text-[hsl(var(--muted-foreground))]",children:"(no prompt)"}),s.input&&n.jsxs("div",{className:"mt-2 text-xs text-[hsl(var(--muted-foreground))]",children:[n.jsx("strong",{children:"Model input:"})," ",s.input.parts.map(i=>i.type==="text"?`text (${i.characters} characters)`:`image (${i.source}${i.mediaType?`, ${i.mediaType}`:""}${i.bytes!==void 0?`, ${i.bytes} bytes`:""})`).join(", ")]})]})}function E2({event:s}){if(s.type!=="ask_end")return null;const{outcome:r,cost:i,duration:o}=s;return n.jsxs(n.Fragment,{children:[n.jsxs("p",{className:"text-xs mb-1",children:[n.jsx("strong",{children:"Outcome:"})," ",n.jsx("span",{className:r.ok?"text-green-600 dark:text-green-400":"text-red-600 dark:text-red-400",children:r.ok?"ok":"error"})]}),n.jsxs("p",{className:"text-xs mb-1",children:[n.jsx("strong",{children:"Ask cost:"})," ",at(i)]}),n.jsxs("p",{className:"text-xs mb-1",children:[n.jsx("strong",{children:"Duration:"})," ",o,"ms"]}),r.ok&&r.result!==void 0&&n.jsx(da,{label:"Result",content:typeof r.result=="string"?r.result:JSON.stringify(r.result,null,2),defaultOpen:!0}),!r.ok&&r.error&&n.jsx(da,{label:"Error",content:r.error,tone:"warning",defaultOpen:!0})]})}function T2({event:s}){if(s.type!=="pipeline")return null;const{status:r,stage:i,attempt:o,maxAttempts:d}=s,f=s.status==="failed"?s.reason:void 0;return n.jsxs(n.Fragment,{children:[n.jsxs("p",{className:"text-xs mb-1",children:[n.jsx("strong",{children:"Pipeline:"})," ",i," · ",r," · attempt ",o,"/",d]}),f&&n.jsx(da,{label:"Failure reason",content:f,tone:"warning",defaultOpen:!0})]})}function M2({event:s}){if(s.type==="handoff_start"){if(!s.data)return null;const{source:r,target:i,mode:o,message:d}=s.data;return n.jsxs(n.Fragment,{children:[n.jsxs("p",{className:"text-xs mb-1",children:[n.jsx("strong",{children:"Handoff starts:"})," ",r," → ",i,o?` · ${o}`:""]}),d&&n.jsx(da,{label:"Prompt to target",content:d,defaultOpen:!0})]})}if(s.type==="handoff_return"){if(!s.data)return null;const{source:r,target:i,duration:o}=s.data;return n.jsxs(n.Fragment,{children:[n.jsxs("p",{className:"text-xs mb-1",children:[n.jsx("strong",{children:"Handoff returns:"})," ",r," → ",i]}),typeof o=="number"&&n.jsxs("p",{className:"text-xs mb-1",children:[n.jsx("strong",{children:"Round-trip duration:"})," ",o,"ms"]})]})}return null}function A2({event:s}){const r="data"in s?s.data:void 0;return n.jsxs(n.Fragment,{children:[s.model&&n.jsxs("p",{className:"text-xs mb-1",children:[n.jsx("strong",{children:"Model:"})," ",s.model]}),s.promptVersion&&n.jsxs("p",{className:"text-xs mb-1",children:[n.jsx("strong",{children:"Version:"})," ",s.promptVersion]}),s.tokens&&(s.tokens.input!=null||s.tokens.output!=null)&&n.jsxs("p",{className:"text-xs mb-1",children:[n.jsx("strong",{children:"Tokens:"}),s.tokens.input!=null?` in=${s.tokens.input}`:"",s.tokens.output!=null?` out=${s.tokens.output}`:"",s.tokens.reasoning?` reasoning=${s.tokens.reasoning}`:""]}),r!=null&&n.jsx(Ps,{data:r,collapsed:!0})]})}function _2({event:s,index:r,isExpanded:i,onToggle:o,maxDuration:d,baseDepth:f,lifecycleBadge:m}){var w,C;const h=Math.max(0,zg(s)-f),x=v2(s),p=Hg(s),v=s.type==="guardrail"||s.type==="schema_check"||s.type==="validate",y=v&&((p==null?void 0:p.valid)===!1||(p==null?void 0:p.blocked)===!0),E=s.step!=null&&s.step!==Number.MAX_SAFE_INTEGER?`#${s.step}`:"";return n.jsxs("div",{children:[n.jsxs("button",{onClick:o,className:F("w-full flex items-center gap-2 px-3 py-1.5 text-xs rounded-xl cursor-pointer hover:bg-[hsl(var(--accent))] text-left",x||y?"bg-amber-100/60 dark:bg-amber-950/30 ring-1 ring-amber-400/40":"bg-[hsl(var(--secondary))]"),style:{marginLeft:`${h*16}px`},children:[i?n.jsx(Bn,{size:12,className:"shrink-0 text-[hsl(var(--muted-foreground))]"}):n.jsx(Ba,{size:12,className:"shrink-0 text-[hsl(var(--muted-foreground))]"}),n.jsx("span",{className:"font-mono text-[hsl(var(--muted-foreground))] w-8 truncate",children:E||`#${r}`}),n.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${t0(s)}`}),n.jsx("span",{className:"font-medium w-28 truncate",children:s.type}),m&&n.jsx("span",{className:F("px-1.5 py-0.5 text-[9px] font-medium rounded-full whitespace-nowrap",m==="succeeded"||m==="approved"?"bg-green-100 text-green-800 dark:bg-green-950/40 dark:text-green-300":m==="running"||m==="accepted"||m==="legacy result"||m==="legacy"?"bg-slate-200 text-slate-800 dark:bg-slate-800 dark:text-slate-200":m.includes("incomplete")||m==="cancelled"?"bg-amber-100 text-amber-800 dark:bg-amber-950/40 dark:text-amber-300":"bg-red-100 text-red-800 dark:bg-red-950/40 dark:text-red-300"),children:m}),x&&n.jsxs("span",{className:"inline-flex items-center gap-0.5 px-1.5 py-0.5 text-[9px] font-medium rounded-full bg-amber-200 text-amber-900 dark:bg-amber-800 dark:text-amber-100",title:`Retry after ${((w=Ug(s))==null?void 0:w.retryReason)??((C=Lg(s))==null?void 0:C.retryReason)} failure`,children:[n.jsx(ON,{size:9}),"retry"]}),(p==null?void 0:p.attempt)!=null&&p.maxAttempts!=null&&n.jsxs("span",{className:"px-1.5 py-0.5 text-[9px] font-medium rounded-full bg-[hsl(var(--muted))] text-[hsl(var(--muted-foreground))]",title:`Attempt ${p.attempt} of ${p.maxAttempts}`,children:[p.attempt,"/",p.maxAttempts]}),s.agent&&n.jsx("span",{className:"text-blue-600 dark:text-blue-400 w-28 truncate",children:s.agent}),"tool"in s&&s.tool&&n.jsx("span",{className:"text-purple-600 dark:text-purple-400 w-28 truncate",children:s.tool}),n.jsx("div",{className:"flex-1 h-3 bg-[hsl(var(--background))] rounded overflow-hidden",children:s.duration!=null&&s.duration>0&&n.jsx("div",{className:`h-full rounded ${t0(s)}`,style:{width:`${Math.max(s.duration/d*100,2)}%`,opacity:.7}})}),s.duration!=null&&n.jsx(Df,{ms:s.duration}),s.cost!=null&&s.cost>0&&n.jsx(Fa,{cost:s.cost})]}),i&&n.jsx("div",{className:"mt-1 mb-2 p-3 rounded-xl bg-[hsl(var(--card))] border border-[hsl(var(--border))]",style:{marginLeft:`${h*16+32}px`},children:s.type==="agent_call_start"?n.jsx(y2,{event:s}):s.type==="agent_call_end"?n.jsx(j2,{event:s}):v?n.jsx(k2,{event:s}):s.type==="tool_approval"?n.jsx(N2,{event:s}):s.type==="tool_call_end"&&s.schemaVersion===2?n.jsx(S2,{event:s}):s.type==="tool_call_rejected"?n.jsx(w2,{event:s}):s.type==="ask_start"?n.jsx(C2,{event:s}):s.type==="ask_end"?n.jsx(E2,{event:s}):s.type==="pipeline"?n.jsx(T2,{event:s}):s.type==="handoff_start"||s.type==="handoff_return"?n.jsx(M2,{event:s}):n.jsx(A2,{event:s})})]})}function Di({events:s,lifecycleEvents:r=s,traceComplete:i,maxDuration:o,showToolbar:d=!0,header:f}){const[m,h]=b.useState(new Set),[x,p]=b.useState(0),[v,y]=b.useState(0),E=b.useMemo(()=>o??Math.max(...s.map(H=>H.duration??0),1),[s,o]),w=b.useMemo(()=>{const H=new Map,T=i??r.some(S=>S.type==="done"||S.type==="error"||S.type==="workflow_end"||S.type==="log"&&typeof S.data=="object"&&S.data!==null&&"event"in S.data&&S.data.event==="events_truncated"),j=new Set(r.filter(S=>S.type==="tool_call_end"&&S.schemaVersion===2).map(S=>`${S.executionId}\0${S.askId}\0${S.callId}`)),k=r.filter(S=>S.type==="tool_call_end"&&S.schemaVersion!==2);for(const S of r)if(S.type==="tool_call_start")if(S.schemaVersion===2){const B=`${S.executionId}\0${S.askId}\0${S.callId}`;H.set(S,j.has(B)?"accepted":T?"incomplete trace":"running")}else{const B=k.some($=>{const W="callId"in S?S.callId:void 0,K="callId"in $?$.callId:void 0;return W!=null&&K!=null?W===K:$.tool===S.tool});H.set(S,B?"legacy":T?"legacy incomplete":"legacy")}else S.type==="tool_call_end"?H.set(S,S.schemaVersion===2?S.data.outcome.status:"legacy result"):S.type==="tool_call_rejected"?H.set(S,"rejected"):S.type==="tool_denied"?H.set(S,"legacy denied"):S.type==="tool_approval"&&H.set(S,S.data.approved?"approved":"denied");return H},[r,i]),C=b.useMemo(()=>{let H=1/0;for(const T of s){const j=zg(T);j<H&&(H=j)}return Number.isFinite(H)?H:0},[s]),_=H=>{h(T=>{const j=new Set(T);return j.has(H)?j.delete(H):j.add(H),j})},R=()=>{const H=s.map((T,j)=>T.step??j);h(new Set(H)),p(1),y(T=>T+1)},D=()=>{h(new Set),p(0),y(H=>H+1)};return n.jsxs(n.Fragment,{children:[d&&n.jsxs("div",{className:"flex items-center justify-between mb-3",children:[n.jsxs("span",{className:"text-xs text-[hsl(var(--muted-foreground))]",children:[s.length," event",s.length!==1?"s":"",f&&n.jsx("span",{className:"ml-2",children:f})]}),s.length>0&&n.jsxs("div",{className:"flex items-center gap-1",children:[n.jsxs("button",{onClick:R,className:"inline-flex items-center gap-1 px-2 py-1 text-xs rounded-md hover:bg-[hsl(var(--accent))] text-[hsl(var(--muted-foreground))]",title:"Expand all — including inner sections",children:[n.jsx(yg,{size:12}),"Expand"]}),n.jsxs("button",{onClick:D,className:"inline-flex items-center gap-1 px-2 py-1 text-xs rounded-md hover:bg-[hsl(var(--accent))] text-[hsl(var(--muted-foreground))]",title:"Collapse all",children:[n.jsx(bg,{size:12}),"Collapse"]})]})]}),n.jsx(zf.Provider,{value:{level:x,version:v},children:n.jsx("div",{className:"space-y-1",children:s.map((H,T)=>{const j=H.step??T;return n.jsx(_2,{event:H,index:T,isExpanded:m.has(j),onToggle:()=>_(j),maxDuration:E,baseDepth:C,lifecycleBadge:w.get(H)},j)})})})]})}const a0="axl.studio.split.",n0=2,O2=6;function s0(s,r){return s<=0?!1:s<2*r+O2}function Ud(s,r,i){return Math.min(i,Math.max(r,s))}function jr({left:s,right:r,defaultPercent:i=50,minPercent:o=20,maxPercent:d=80,minPx:f=200,storageKey:m,className:h}){const[x,p]=b.useState(()=>{if(!m)return i;try{const k=localStorage.getItem(a0+m);if(!k)return i;const S=Number(k);return Number.isFinite(S)?Ud(S,o,d):i}catch{return i}}),[v,y]=b.useState(!1),E=b.useRef(null),w=b.useRef(!1),C=b.useRef(null),_=b.useRef(null);b.useEffect(()=>{if(m)try{localStorage.setItem(a0+m,String(x))}catch{}},[m,x]),b.useEffect(()=>{const k=E.current;if(!k||typeof ResizeObserver>"u"){k&&y(s0(k.getBoundingClientRect().width,f));return}const S=new ResizeObserver(B=>{const $=B[0];if(!$)return;const W=$.contentRect.width;y(s0(W,f))});return S.observe(k),()=>S.disconnect()},[f]);const R=b.useCallback(()=>{var B;const k=((B=E.current)==null?void 0:B.getBoundingClientRect().width)??0;if(!k||!Number.isFinite(k))return{min:o,max:d};const S=f/k*100;return{min:Math.max(o,S),max:Math.min(d,100-S)}},[o,d,f]);b.useEffect(()=>()=>{C.current&&(document.removeEventListener("mousemove",C.current),document.removeEventListener("touchmove",C.current)),_.current&&(document.removeEventListener("mouseup",_.current),document.removeEventListener("touchend",_.current),document.removeEventListener("touchcancel",_.current)),w.current&&(document.body.style.cursor="",document.body.style.userSelect="")},[]);const D=b.useCallback(k=>{w.current=!0;const S=k,B=E.current;if(!B)return;const $=B.getBoundingClientRect().width,W=x,K=re=>{var ve;if(!w.current)return;const Me=B.getBoundingClientRect().width||$,z=(("touches"in re?((ve=re.touches[0])==null?void 0:ve.clientX)??S:re.clientX)-S)/Me*100,{min:L,max:ie}=R();p(Ud(W+z,L,ie))},te=()=>{w.current=!1,document.removeEventListener("mousemove",K),document.removeEventListener("touchmove",K),document.removeEventListener("mouseup",te),document.removeEventListener("touchend",te),document.removeEventListener("touchcancel",te),document.body.style.cursor="",document.body.style.userSelect="",C.current=null,_.current=null};C.current=K,_.current=te,document.addEventListener("mousemove",K),document.addEventListener("touchmove",K,{passive:!1}),document.addEventListener("mouseup",te),document.addEventListener("touchend",te),document.addEventListener("touchcancel",te),document.body.style.cursor="col-resize",document.body.style.userSelect="none"},[x,R]),H=b.useCallback(k=>{k.preventDefault(),D(k.clientX)},[D]),T=b.useCallback(k=>{const S=k.touches[0];S&&D(S.clientX)},[D]),j=b.useCallback(k=>{if(k.key!=="ArrowLeft"&&k.key!=="ArrowRight")return;k.preventDefault();const S=k.key==="ArrowLeft"?-1:1,B=k.shiftKey?n0*5:n0,{min:$,max:W}=R();p(K=>Ud(K+S*B,$,W))},[R]);return v?n.jsxs("div",{ref:E,className:F("flex flex-col min-h-0",h),children:[n.jsx("div",{className:"min-h-0 min-w-0 flex flex-col flex-1 overflow-auto",children:s}),n.jsx("div",{role:"separator","aria-orientation":"horizontal",className:"h-px shrink-0 bg-[hsl(var(--border))]"}),n.jsx("div",{className:"min-h-0 min-w-0 flex flex-col flex-1 overflow-auto",children:r})]}):n.jsxs("div",{ref:E,className:F("flex min-h-0",h),children:[n.jsx("div",{className:"min-h-0 min-w-0 flex flex-col",style:{width:`${x}%`},children:s}),n.jsx("div",{role:"separator","aria-orientation":"vertical","aria-valuenow":Math.round(x),"aria-valuemin":o,"aria-valuemax":d,tabIndex:0,onMouseDown:H,onTouchStart:T,onKeyDown:j,className:"w-1.5 shrink-0 cursor-col-resize bg-[hsl(var(--border))] hover:bg-[hsl(var(--ring))] focus:bg-[hsl(var(--ring))] focus:outline-none transition-colors"}),n.jsx("div",{className:"min-h-0 min-w-0 flex flex-col",style:{width:`${100-x}%`},children:r})]})}const R2=(window.__AXL_STUDIO_BASE__??"")+"/api";async function rt(s,r){const i=await fetch(`${R2}${s}`,{headers:{"Content-Type":"application/json",...r==null?void 0:r.headers},...r});if(i.status===413){if((i.headers.get("content-type")??"").includes("application/json")){const m=await i.json().catch(()=>{});if(m&&!m.ok)throw new Error(m.error.message)}throw new Error(`Request body too large (HTTP 413). If you're importing a large eval file through an embedded Studio middleware, raise your host framework's JSON body limit on the Studio mount. See the Studio README "Host body limits" section.`)}if(!(i.headers.get("content-type")??"").includes("application/json")){const m=(await i.text().catch(()=>"")).slice(0,200).trim();throw new Error(`Server returned HTTP ${i.status} with non-JSON response`+(m?`: ${m}`:""))}let d;try{d=await i.json()}catch(f){throw new Error(`Failed to parse server response as JSON (HTTP ${i.status}): ${f instanceof Error?f.message:String(f)}`)}if(!d.ok)throw new Error(d.error.message);return d.data}const D2=()=>rt("/health"),z2=()=>rt("/workflows"),U2=s=>rt(`/workflows/${encodeURIComponent(s)}`),L2=(s,r,i=!1)=>rt(`/workflows/${encodeURIComponent(s)}/execute`,{method:"POST",body:JSON.stringify({input:r,stream:i})}),H2=()=>rt("/executions"),q2=()=>rt("/sessions"),B2=s=>rt(`/sessions/${encodeURIComponent(s)}`),$2=s=>rt(`/sessions/${encodeURIComponent(s)}`,{method:"DELETE"}),Q2=()=>rt("/agents"),G2=()=>rt("/tools"),Y2=s=>rt(`/tools/${encodeURIComponent(s)}`),K2=(s,r)=>rt(`/tools/${encodeURIComponent(s)}/test`,{method:"POST",body:JSON.stringify({input:r})}),V2=s=>rt(`/memory/${encodeURIComponent(s)}`),X2=(s,r,i)=>rt(`/memory/${encodeURIComponent(s)}/${encodeURIComponent(r)}`,{method:"PUT",body:JSON.stringify({value:i})}),F2=(s,r)=>rt(`/memory/${encodeURIComponent(s)}/${encodeURIComponent(r)}`,{method:"DELETE"}),Z2=(s,r,i)=>rt("/memory/search",{method:"POST",body:JSON.stringify({query:s,scope:r,limit:i})}),J2=(s="7d")=>rt(`/costs?window=${s}`),I2=(s="7d")=>rt(`/eval-trends?window=${s}`),W2=(s="7d")=>rt(`/workflow-stats?window=${s}`),P2=(s="7d")=>rt(`/trace-stats?window=${s}`),eS=()=>rt("/evals"),tS=()=>rt("/evals/history"),aS=(s,r)=>rt(`/evals/${encodeURIComponent(s)}/run`,{method:"POST",body:JSON.stringify({runs:r==null?void 0:r.runs,stream:!0,captureTraces:r==null?void 0:r.captureTraces})}),Bg=s=>rt(`/evals/runs/${encodeURIComponent(s)}/cancel`,{method:"POST"}),nS=(s,r)=>rt(`/evals/${encodeURIComponent(s)}/rescore`,{method:"POST",body:JSON.stringify({resultId:r})}),sS=(s,r,i)=>rt("/evals/compare",{method:"POST",body:JSON.stringify({baselineId:s,candidateId:r,options:i})}),lS=(s,r)=>rt("/evals/import",{method:"POST",body:JSON.stringify({result:s,eval:r})}),rS=s=>rt(`/evals/history/${encodeURIComponent(s)}`,{method:"DELETE"}),l0=(s,r,i,o)=>rt("/playground/chat",{method:"POST",body:JSON.stringify(o?{message:s,sessionId:r,agent:i,image:o}:{message:s,sessionId:r,agent:i})});class iS{constructor(){Wl(this,"ws",null);Wl(this,"listeners",new Map);Wl(this,"connectionListeners",new Set);Wl(this,"reconnectTimer",null);Wl(this,"url");const r=window.location.protocol==="https:"?"wss:":"ws:",i=window.__AXL_STUDIO_BASE__??"";this.url=`${r}//${window.location.host}${i}/ws`}connect(){var r;((r=this.ws)==null?void 0:r.readyState)!==WebSocket.OPEN&&(this.ws=new WebSocket(this.url),this.ws.onopen=()=>{for(const i of this.connectionListeners)i(!0);for(const i of this.listeners.keys())this.send({type:"subscribe",channel:i})},this.ws.onmessage=i=>{try{const o=JSON.parse(i.data);if(o.type==="event"&&o.channel){const d=this.listeners.get(o.channel);if(d)for(const m of d)m(o.data);const f=o.channel.indexOf(":");if(f>0){const m=o.channel.substring(0,f)+":*",h=this.listeners.get(m);if(h)for(const x of h)x(o.data)}}}catch{}},this.ws.onclose=()=>{for(const i of this.connectionListeners)i(!1);this.scheduleReconnect()},this.ws.onerror=()=>{var i;(i=this.ws)==null||i.close()})}scheduleReconnect(){this.reconnectTimer||(this.reconnectTimer=setTimeout(()=>{this.reconnectTimer=null,this.connect()},2e3))}send(r){var i;((i=this.ws)==null?void 0:i.readyState)===WebSocket.OPEN&&this.ws.send(JSON.stringify(r))}subscribe(r,i){let o=this.listeners.get(r);return o||(o=new Set,this.listeners.set(r,o),this.send({type:"subscribe",channel:r})),o.add(i),this.connect(),()=>{o.delete(i),o.size===0&&(this.listeners.delete(r),this.send({type:"unsubscribe",channel:r}))}}subscribeConnection(r){return this.connectionListeners.add(r),()=>this.connectionListeners.delete(r)}disconnect(){var r;this.reconnectTimer&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null),(r=this.ws)==null||r.close(),this.ws=null}}const Ni=new iS;function Uf(s,r,i){const o=b.useRef(r);o.current=r;const d=b.useRef(i);d.current=i,b.useEffect(()=>{var h;if(!s)return;const f=Ni.subscribe(s,x=>o.current(x)),m=(h=Ni.subscribeConnection)==null?void 0:h.call(Ni,x=>{var p;x||(p=d.current)==null||p.call(d)});return()=>{f(),m==null||m()}},[s])}const r0={tokens:"",events:[],done:!1,interrupted:!1,error:null,result:null};function $g(s){const[r,i]=b.useState(r0),o=b.useRef(null);b.useEffect(()=>{if(s===o.current)return;const m=o.current;o.current=s,s!==null?i(r0):m!==null&&i(h=>({...h,done:!1,result:null,error:null}))},[s]);const d=b.useCallback(m=>{const h=m;i(x=>{var p,v;switch(h.type){case"token":{const E=(h.depth??0)===0?x.tokens+(h.data??""):x.tokens;return{...x,tokens:E,events:[...x.events,h]}}case"done":return{...x,done:!0,result:((p=h.data)==null?void 0:p.result)??null,events:[...x.events,h]};case"error":return{...x,done:!0,error:((v=h.data)==null?void 0:v.message)||"Unknown error",events:[...x.events,h]};default:return{...x,events:[...x.events,h]}}})},[]),f=b.useCallback(()=>{i(m=>m.done?m:{...m,interrupted:!0})},[]);return Uf(s?`execution:${s}`:null,d,f),r}const i0=5*1024*1024,oS=["image/png","image/jpeg","image/webp","image/gif"];function cS(s){return typeof s=="string"&&oS.includes(s)}function uS(s){if(s.length===0||s.length%4!==0||!/^[A-Za-z0-9+/]*={0,2}$/.test(s))return;const r=s.endsWith("==")?2:s.endsWith("=")?1:0;return s.length/4*3-r}function dS({status:s}){const r=s==="succeeded"?"bg-green-100 text-green-800 dark:bg-green-950/40 dark:text-green-300":s==="running"?"bg-blue-100 text-blue-800 dark:bg-blue-950/40 dark:text-blue-300":s==="incomplete"||s==="cancelled"?"bg-amber-100 text-amber-800 dark:bg-amber-950/40 dark:text-amber-300":"bg-red-100 text-red-800 dark:bg-red-950/40 dark:text-red-300";return n.jsx("span",{className:F("px-1.5 py-0.5 text-[9px] font-medium rounded-full",r),children:s})}const fS=new Set(["tool_call_start","tool_call_rejected","handoff_start","tool_approval"]);function hS(s){var f;let r=null;const i=new Map;let o=null;const d=m=>{for(const h of[...i.keys()])h.startsWith(m+"|")&&(i.delete(h),o===h&&(o=null))};for(const m of s)if(m.type==="partial_object")r={askId:m.askId??"",object:(f=m.data)==null?void 0:f.object};else if(m.type==="string_delta"){const h=m.askId??"",x=`${h}|${m.data.path}`,p=i.get(x);i.set(x,{askId:h,path:m.data.path,accumulated:((p==null?void 0:p.accumulated)??"")+m.data.delta}),o=x}else(m.type==="pipeline"&&m.status==="failed"||m.type==="ask_end")&&d(m.askId??"");return{latestPartial:r,latestStringDelta:o?i.get(o)??null:null}}function mS({partial:s,streamingField:r}){return n.jsxs("div",{className:"space-y-2",children:[n.jsx("div",{className:"text-[10px] uppercase tracking-wide text-[hsl(var(--muted-foreground))]",children:"Streaming structured output"}),n.jsx(Ct,{data:s,defaultExpandDepth:3}),r&&r.accumulated.length>0&&n.jsxs("div",{className:"border-t border-[hsl(var(--border))] pt-2",children:[n.jsxs("div",{className:"text-[10px] uppercase tracking-wide text-[hsl(var(--muted-foreground))] mb-1",children:["Writing ",n.jsx("code",{className:"font-mono",children:r.path})]}),n.jsxs("div",{className:"whitespace-pre-wrap font-mono text-xs",children:[r.accumulated,n.jsx("span",{className:"inline-block w-1.5 h-3 ml-0.5 align-middle bg-[hsl(var(--foreground))] animate-pulse"})]})]})]})}function pS(s){if(!s)return;const r=s.trim();if(!(!r.startsWith("{")&&!r.startsWith("[")))try{return JSON.parse(r)}catch{return}}function xS(){const[s,r]=b.useState([]),[i,o]=b.useState(""),[d,f]=b.useState(null),[m,h]=b.useState(null),[x,p]=b.useState(!1),v=b.useRef(null),y=b.useRef(null),E=b.useRef(0),w=b.useRef(null),[C,_]=b.useState(null),[R,D]=b.useState(null),[H,T]=b.useState(""),[j,k]=b.useState(!1),[S,B]=b.useState(0),[$,W]=b.useState({input:0,output:0}),[K,te]=b.useState(!1),re=b.useRef(!1),Me=b.useRef(null),he=b.useRef(0),ae=b.useRef(0),{data:z=[]}=Sa({queryKey:["agents"],queryFn:Q2}),L=$g(R);b.useEffect(()=>{if(L.tokens&&j&&r(X=>{const ne=X[X.length-1];return(ne==null?void 0:ne.role)==="assistant"?[...X.slice(0,-1),{...ne,content:L.tokens}]:[...X,{role:"assistant",content:L.tokens}]}),L.done&&j){if(k(!1),D(null),L.error)r(X=>{const ne=X[X.length-1];return(ne==null?void 0:ne.role)==="assistant"&&!ne.content?[...X.slice(0,-1),{role:"assistant",content:`Error: ${L.error}`}]:[...X,{role:"assistant",content:`Error: ${L.error}`}]});else if(L.result!=null){let X=null;if(typeof L.result=="string"){const we=L.result.trim();if(we.startsWith("{")||we.startsWith("["))try{X=JSON.stringify(JSON.parse(we))}catch{}}else typeof L.result=="object"&&(X=JSON.stringify(L.result));if(!(!L.tokens||X!==null))return;const ce=X??(typeof L.result=="string"?L.result:JSON.stringify(L.result));r(we=>{const Re=we[we.length-1];return(Re==null?void 0:Re.role)==="assistant"?[...we.slice(0,-1),{...Re,content:ce}]:[...we,{role:"assistant",content:ce}]})}}},[L.tokens,L.done,L.error,j]),b.useEffect(()=>{var dt,yt;const X=new Map,ne=[],ce=[],we=[];for(const pe of L.events)if(pe.type==="tool_call_start"){const Te=`${pe.executionId}\0${pe.askId}\0${pe.callId}`;X.set(Te,{name:pe.tool,args:(dt=pe.data)==null?void 0:dt.args,callId:pe.callId,executionId:pe.executionId,askId:pe.askId,startObserved:!0,status:"running"}),ne.push(Te)}else if(pe.type==="tool_call_end"){const Te=`${pe.executionId}\0${pe.askId}\0${pe.callId}`,Ie=X.get(Te);if(!Ie||Ie.status!=="rejected"){const ye={name:pe.tool,args:pe.data.args,callId:pe.callId,executionId:pe.executionId,askId:pe.askId,startObserved:Ie!=null},Je=pe.data.outcome;switch(Je.status){case"succeeded":X.set(Te,{...ye,status:"succeeded",result:Je.result});break;case"failed":X.set(Te,{...ye,status:"failed",failure:Je.failure});break;case"denied":X.set(Te,{...ye,status:"denied",reason:Je.reason});break;case"cancelled":X.set(Te,{...ye,status:"cancelled",cancellation:Je.cancellation});break}Ie||ne.push(Te)}}else if(pe.type==="tool_call_rejected"){const Te=`${pe.executionId}\0${pe.askId}\0${pe.callId}`;X.set(Te,{name:pe.tool,callId:pe.callId,executionId:pe.executionId,askId:pe.askId,status:"rejected",rejection:pe.data}),ne.push(Te)}else if(pe.type==="handoff_start"){const Te=pe.data;Te&&ce.push({source:Te.source,target:Te.target,mode:Te.mode})}else pe.type==="tool_approval"&&we.push({tool:pe.tool,approved:((yt=pe.data)==null?void 0:yt.approved)===!0});if(L.done||L.interrupted)for(const[pe,Te]of X)Te.status==="running"&&X.set(pe,{...Te,status:"incomplete"});const Re=ne.flatMap(pe=>{const Te=X.get(pe);return Te?[Te]:[]});(Re.length>0||ce.length>0||we.length>0)&&r(pe=>{const Te=pe[pe.length-1];return(Te==null?void 0:Te.role)==="assistant"?[...pe.slice(0,-1),{...Te,toolCalls:Re.length>0?Re:Te.toolCalls,handoffs:ce.length>0?ce:Te.handoffs,approvals:we.length>0?we:Te.approvals}]:pe})},[L.events,L.done,L.interrupted]),b.useEffect(()=>{const X=L.events.slice(he.current);if(X.length===0)return;he.current=L.events.length;let ne=0,ce=0,we=0;for(const Re of X)ne+=Ag(Re),Re.type==="agent_call_end"&&Re.tokens&&(ce+=Re.tokens.input??0,we+=Re.tokens.output??0);ne>0&&B(Re=>Re+ne),(ce>0||we>0)&&W(Re=>({input:Re.input+ce,output:Re.output+we}))},[L.events]),b.useEffect(()=>{if(K||re.current){ae.current=L.events.length;return}for(let X=ae.current;X<L.events.length;X++){const ne=L.events[X];if(!ne)continue;const ce="depth"in ne&&typeof ne.depth=="number"?ne.depth:0;if(fS.has(ne.type)||ce>=1){te(!0),ae.current=L.events.length;return}}ae.current=L.events.length},[L.events,K]),b.useEffect(()=>{var X;(X=Me.current)==null||X.scrollIntoView({behavior:"smooth"})},[s]);const ie=b.useCallback(X=>{var ne;E.current+=1,(ne=y.current)==null||ne.abort(),y.current=null,w.current&&URL.revokeObjectURL(w.current),w.current=null,f(null),h(X??null),p(!1),v.current&&(v.current.value="")},[]),ve=b.useCallback(()=>ie(),[ie]),ge=b.useCallback(X=>{var dt;const ne=(dt=X.target.files)==null?void 0:dt[0];if(!ne)return;if(ie(),!cS(ne.type)){h("Choose a PNG, JPEG, WebP, or GIF image.");return}const ce=ne.type;if(ne.size>i0){h("Image must be 5 MiB or smaller.");return}const we=new FileReader,Re=E.current;y.current=we,p(!0),we.onerror=()=>{Re===E.current&&(y.current=null,p(!1),h("Could not read that image."))},we.onload=()=>{if(Re!==E.current)return;y.current=null,p(!1);const pe=(typeof we.result=="string"?we.result:"").split(",",2)[1]??"",Te=uS(pe);if(Te===void 0||Te>i0){h("Could not read that image safely.");return}const Ie=URL.createObjectURL(ne);w.current=Ie,f({mediaType:ce,data:pe,previewUrl:Ie}),h(null)},we.readAsDataURL(ne)},[ie]);b.useEffect(()=>()=>{var X;E.current+=1,(X=y.current)==null||X.abort(),w.current&&URL.revokeObjectURL(w.current)},[]);const M=b.useCallback(async()=>{if(!i.trim()||j||x)return;const X=i.trim();o(""),r(ne=>[...ne,{role:"user",content:X}]),k(!0);try{const ne=d?await l0(X,C??void 0,H||void 0,{mediaType:d.mediaType,data:d.data}):await l0(X,C??void 0,H||void 0);ie(),_(ne.sessionId),D(ne.executionId)}catch(ne){k(!1),r(ce=>[...ce,{role:"assistant",content:`Error: ${ne instanceof Error?ne.message:String(ne)}`}])}},[i,j,x,C,H,d,ie]),Q=X=>{X.key==="Enter"&&!X.shiftKey&&(X.preventDefault(),M())},G=S>0||$.input>0,J=s.length,oe=b.useMemo(()=>hS(L.events),[L.events]),me=L.events.filter(X=>X.type!=="token"&&X.type!=="partial_object"&&X.type!=="string_delta"&&X.type!=="done"&&X.type!=="error"),be=n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"flex-1 overflow-auto p-3 sm:p-5 space-y-4",children:[s.length===0&&n.jsx(ta,{title:"Start a conversation",description:"Type a message below to chat with an agent. Tool calls, handoffs, and streaming responses will be displayed in real-time."}),s.map((X,ne)=>n.jsx("div",{className:`flex ${X.role==="user"?"justify-end":"justify-start"}`,children:n.jsxs("div",{className:`max-w-[80%] rounded-xl px-4 py-2.5 text-sm ${X.role==="user"?"bg-[hsl(var(--primary))] text-[hsl(var(--primary-foreground))]":"bg-[hsl(var(--secondary))] text-[hsl(var(--secondary-foreground))]"}`,children:[(()=>{const ce=X.role==="assistant"&&j&&ne===s.length-1;if(ce&&oe.latestPartial)return n.jsx(mS,{partial:oe.latestPartial.object,streamingField:oe.latestStringDelta});if(ce)return n.jsx(n2,{text:X.content});const we=X.role==="assistant"?pS(X.content):void 0;return we!==void 0?n.jsx(Ct,{data:we,defaultExpandDepth:3}):n.jsx("div",{className:"whitespace-pre-wrap",children:X.content})})(),X.handoffs&&X.handoffs.length>0&&n.jsx("div",{className:"mt-2 space-y-1 border-t border-[hsl(var(--border))] pt-2",children:X.handoffs.map((ce,we)=>n.jsxs("div",{className:"flex items-center gap-1.5 text-xs",children:[n.jsx(mr,{size:12,className:"text-amber-500"}),n.jsx("span",{className:"font-medium",children:ce.source}),n.jsx(mr,{size:10}),n.jsx("span",{className:"font-medium",children:ce.target}),n.jsxs("span",{className:"text-[hsl(var(--muted-foreground))]",children:["(",ce.mode,")"]})]},we))}),X.approvals&&X.approvals.length>0&&n.jsx("div",{className:"mt-2 space-y-1 border-t border-[hsl(var(--border))] pt-2",children:X.approvals.map((ce,we)=>n.jsxs("div",{className:"flex items-center gap-1.5 text-xs",children:[n.jsx(LN,{size:12,className:ce.approved?"text-green-500":"text-red-500"}),n.jsxs("span",{children:["Tool ",n.jsx("span",{className:"font-mono",children:ce.tool}),":"," ",ce.approved?"approved":"denied"]})]},we))}),X.toolCalls&&X.toolCalls.length>0&&n.jsx("div",{className:"mt-2 space-y-2 border-t border-[hsl(var(--border))] pt-2",children:X.toolCalls.map((ce,we)=>n.jsxs("div",{className:"text-xs",children:[n.jsxs("div",{className:"flex items-center gap-2 font-medium mb-1",children:[n.jsxs("span",{children:["Tool: ",ce.name]}),n.jsx(dS,{status:ce.status})]}),n.jsxs("div",{className:"space-y-1",children:[ce.status!=="rejected"&&n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"text-[hsl(var(--muted-foreground))]",children:"Input:"}),n.jsx(Ct,{data:ce.args,collapsed:!0})]}),ce.status!=="rejected"&&!ce.startObserved&&n.jsx("div",{className:"text-amber-600 dark:text-amber-400",children:"Terminal observed without its matching start; the trace is incomplete."}),ce.status==="succeeded"&&n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"text-[hsl(var(--muted-foreground))]",children:"Output:"}),n.jsx(Ct,{data:ce.result,collapsed:!0})]}),ce.status==="failed"&&n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"text-red-600 dark:text-red-400",children:["Failed in ",ce.failure.phase,": ",ce.failure.error.name," —"," ",ce.failure.error.message]}),"result"in ce.failure&&n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"text-[hsl(var(--muted-foreground))]",children:"Output before failure:"}),n.jsx(Ct,{data:ce.failure.result,collapsed:!0})]})]}),ce.status==="denied"&&ce.reason&&n.jsxs("div",{className:"text-red-600 dark:text-red-400",children:["Reason: ",ce.reason]}),ce.status==="cancelled"&&n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"text-amber-600 dark:text-amber-400",children:["Cancelled in ",ce.cancellation.phase,ce.cancellation.reason?`: ${ce.cancellation.reason}`:""]}),"result"in ce.cancellation&&n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"text-[hsl(var(--muted-foreground))]",children:"Output before cancellation:"}),n.jsx(Ct,{data:ce.cancellation.result,collapsed:!0})]})]}),ce.status==="incomplete"&&n.jsx("div",{className:"text-amber-600 dark:text-amber-400",children:"Trace ended before a matching tool terminal was observed."}),ce.status==="rejected"&&n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"text-red-600 dark:text-red-400",children:["Rejected before execution: ",ce.rejection.reason]}),ce.rejection.reason==="invalid_arguments"&&n.jsx(Ct,{data:{args:ce.rejection.args,issues:ce.rejection.issues},collapsed:!0})]})]})]},we))})]})},ne)),n.jsx("div",{ref:Me})]}),n.jsxs("div",{className:"border-t border-[hsl(var(--border))] p-4 shrink-0",children:[(d||m)&&n.jsxs("div",{className:"max-w-3xl mx-auto mb-2",children:[d&&n.jsxs("div",{className:"inline-flex items-center gap-2 rounded-lg border border-[hsl(var(--input))] bg-[hsl(var(--secondary))] p-1.5 text-xs text-[hsl(var(--secondary-foreground))]",children:[n.jsx("img",{src:d.previewUrl,alt:"Selected image preview",className:"h-10 w-10 rounded object-cover"}),n.jsx("span",{children:"Image attached"}),n.jsx("button",{type:"button",onClick:ve,"aria-label":"Remove selected image",className:"rounded p-1 hover:bg-[hsl(var(--background))]",children:n.jsx(Rf,{size:14})})]}),m&&n.jsx("p",{role:"alert",className:"mt-1 text-xs text-red-600 dark:text-red-400",children:m})]}),n.jsxs("div",{className:"flex items-end gap-2 max-w-3xl mx-auto",children:[n.jsx("input",{ref:v,type:"file",accept:"image/png,image/jpeg,image/webp,image/gif",className:"hidden","aria-label":"Choose image",onChange:ge}),n.jsx("button",{type:"button",onClick:()=>{var X;return(X=v.current)==null?void 0:X.click()},disabled:j||x,"aria-label":"Attach image",title:"Attach PNG, JPEG, WebP, or GIF (max 5 MiB)",className:"p-2.5 rounded-xl border border-[hsl(var(--input))] hover:bg-[hsl(var(--secondary))] disabled:opacity-50",children:n.jsx(oN,{size:16})}),n.jsx("textarea",{value:i,onChange:X=>o(X.target.value),onKeyDown:Q,placeholder:"Type a message...",rows:1,className:"flex-1 px-3 py-2.5 text-sm rounded-xl border border-[hsl(var(--input))] bg-[hsl(var(--background))] resize-none focus:outline-none focus:ring-2 focus:ring-[hsl(var(--ring))]"}),n.jsx("button",{onClick:M,disabled:!i.trim()||j||x,className:"p-2.5 rounded-xl bg-[hsl(var(--primary))] text-[hsl(var(--primary-foreground))] hover:opacity-90 disabled:opacity-50 transition-opacity",children:n.jsx(zN,{size:16})})]})]})]});return n.jsxs("div",{className:"flex flex-col h-screen",children:[n.jsx(dl,{title:"Agent Playground",description:J>0?n.jsxs(n.Fragment,{children:[n.jsxs("span",{children:[J," message",J!==1?"s":""]}),C&&n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"opacity-40 mx-1.5",children:"·"}),n.jsxs("span",{className:"font-mono",children:["session ",C.slice(0,8)]})]})]}):z.length>0?n.jsxs(n.Fragment,{children:[n.jsxs("span",{children:[z.length," registered agent",z.length!==1?"s":""]}),n.jsx("span",{className:"opacity-40 mx-1.5",children:"·"}),n.jsx("span",{children:"pick one or use the default"})]}):"Interactive chat with registered agents",actions:n.jsxs(n.Fragment,{children:[G&&n.jsxs("div",{className:"flex items-center gap-1.5",children:[S>0&&n.jsx("span",{className:"px-1.5 py-0.5 rounded text-xs font-mono bg-[hsl(var(--secondary))] text-[hsl(var(--secondary-foreground))]",children:at(S)}),$.input>0&&n.jsxs("span",{className:"px-1.5 py-0.5 rounded text-xs font-mono bg-[hsl(var(--secondary))] text-[hsl(var(--secondary-foreground))]",children:[qa($.input+$.output)," tok"]})]}),n.jsxs("button",{type:"button",onClick:()=>{te(X=>(X&&(re.current=!0),!X))},"aria-pressed":K,title:"Show execution activity (tool calls, handoffs, agent calls)",className:F("inline-flex items-center gap-1 rounded-full px-2 py-1 text-xs","ring-1 ring-[hsl(var(--input))] hover:ring-[hsl(var(--ring))]",K?"bg-[hsl(var(--secondary))] text-[hsl(var(--secondary-foreground))]":"bg-[hsl(var(--background))] text-[hsl(var(--muted-foreground))]"),children:[n.jsx(mc,{size:12}),"Activity"]}),n.jsxs("div",{className:F("inline-flex items-stretch rounded-full bg-[hsl(var(--background))]","ring-1 ring-[hsl(var(--input))] shadow-sm","hover:ring-[hsl(var(--ring))] focus-within:ring-[hsl(var(--ring))]","transition-shadow"),children:[n.jsx(ki,{items:z,value:H,onSelect:T,getKey:X=>X.name,getLabel:X=>X.name,getDescription:X=>n.jsxs(n.Fragment,{children:[n.jsx("span",{children:X.model}),X.tools.length>0&&n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"opacity-40 mx-1",children:"·"}),n.jsxs("span",{children:[X.tools.length," tool",X.tools.length!==1?"s":""]})]}),X.handoffs.length>0&&n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"opacity-40 mx-1",children:"·"}),n.jsxs("span",{children:[X.handoffs.length," handoff",X.handoffs.length!==1?"s":""]})]})]}),searchMatch:(X,ne)=>X.name.toLowerCase().includes(ne)||X.model.toLowerCase().includes(ne)||X.tools.some(ce=>ce.toLowerCase().includes(ne)),placeholder:"Default agent",searchPlaceholder:"Search agents…",emptyLabel:"No agents registered",shortcut:!0,triggerClassName:"rounded-l-full",ariaLabel:"Select an agent"}),n.jsxs("button",{onClick:()=>{ie(),r([]),_(null),D(null),B(0),W({input:0,output:0}),te(!1),re.current=!1,he.current=0,ae.current=0},className:F("inline-flex items-center gap-1.5 pl-3.5 pr-4 py-2 text-sm font-medium cursor-pointer","border-l border-[hsl(var(--input))] rounded-r-full","hover:bg-[hsl(var(--muted))] transition-colors","focus:outline-none focus-visible:bg-[hsl(var(--muted))]"),children:[n.jsx(hN,{size:12}),"New chat"]})]})]})}),K?n.jsx(jr,{className:"flex-1",left:be,right:n.jsxs("div",{className:"flex-1 overflow-y-auto p-3 sm:p-5 space-y-4",children:[n.jsx("h3",{className:"text-[11px] font-medium uppercase tracking-wider text-[hsl(var(--muted-foreground))]",children:"Activity"}),n.jsx(Dg,{events:L.events}),me.length>0?n.jsx(Di,{events:me,lifecycleEvents:L.events,traceComplete:L.done||L.interrupted,showToolbar:!1}):n.jsx("p",{className:"text-xs text-[hsl(var(--muted-foreground))]",children:"Events will appear here as the agent executes."})]})}):n.jsx("div",{className:"flex-1 min-h-0 flex flex-col",children:be})]})}function Qg({value:s,onChange:r,placeholder:i,className:o}){const[d,f]=b.useState(!1),[m,h]=b.useState(null),x=b.useRef(null),p=b.useCallback(y=>{const E=y.target.value;r(E);try{E.trim()&&JSON.parse(E),h(null)}catch(w){h(w instanceof Error?w.message:"Invalid JSON")}},[r]);b.useEffect(()=>{var y;d&&((y=x.current)==null||y.focus())},[d]);let v=null;try{v=s.trim()?JSON.parse(s):{}}catch{}return v===null||d?n.jsxs("div",{className:o,children:[n.jsx("textarea",{ref:x,value:s,onChange:p,onBlur:()=>{m||f(!1)},placeholder:i??"{}",className:"w-full h-40 p-3 text-xs font-mono rounded-xl bg-[hsl(var(--secondary))] text-[hsl(var(--foreground))] border-none resize-y focus:outline-none focus:ring-2 focus:ring-[hsl(var(--ring))]",spellCheck:!1}),m&&n.jsx("p",{className:"text-xs text-red-500 mt-1",children:m})]}):n.jsx("div",{className:o,children:n.jsxs("div",{children:[n.jsx(Ct,{data:v,maxHeight:"12rem"}),n.jsxs("button",{onClick:()=>f(!0),className:"mt-1.5 inline-flex items-center gap-1 px-2 py-1 text-[10px] font-medium rounded-md text-[hsl(var(--muted-foreground))] hover:text-[hsl(var(--foreground))] hover:bg-[hsl(var(--accent))] transition-colors cursor-pointer",children:[n.jsx(CN,{size:10}),"Edit"]})]})})}function Gg({schema:s,onSubmit:r,submitLabel:i="Submit",className:o}){const[d,f]=b.useState({}),m=s.properties??{},h=new Set(s.required??[]),x=b.useCallback(p=>{p.preventDefault();const v={};for(const[y,E]of Object.entries(m)){const w=d[y]??"";if(!(!w&&!h.has(y)))if(E.type==="number")v[y]=Number(w);else if(E.type==="boolean")v[y]=w==="true";else if(E.type==="object"||E.type==="array")try{v[y]=JSON.parse(w)}catch{v[y]=w}else v[y]=w}r(v)},[d,m,h,r]);return n.jsxs("form",{onSubmit:x,className:`space-y-3 ${o??""}`,children:[Object.entries(m).map(([p,v])=>n.jsxs("div",{children:[n.jsxs("label",{className:"block text-xs font-medium text-[hsl(var(--foreground))] mb-1",children:[p,h.has(p)&&n.jsx("span",{className:"text-red-500 ml-0.5",children:"*"}),v.description&&n.jsxs("span",{className:"text-[hsl(var(--muted-foreground))] font-normal ml-1",children:["- ",v.description]})]}),v.enum?n.jsxs("select",{value:d[p]??"",onChange:y=>f({...d,[p]:y.target.value}),className:"w-full px-2 py-1.5 text-sm rounded-md border border-[hsl(var(--input))] bg-[hsl(var(--background))]",children:[n.jsx("option",{value:"",children:"Select..."}),v.enum.map(y=>n.jsx("option",{value:y,children:y},y))]}):v.type==="boolean"?n.jsxs("select",{value:d[p]??"",onChange:y=>f({...d,[p]:y.target.value}),className:"w-full px-2 py-1.5 text-sm rounded-md border border-[hsl(var(--input))] bg-[hsl(var(--background))]",children:[n.jsx("option",{value:"",children:"Select..."}),n.jsx("option",{value:"true",children:"true"}),n.jsx("option",{value:"false",children:"false"})]}):n.jsx("input",{type:v.type==="number"?"number":"text",value:d[p]??"",onChange:y=>f({...d,[p]:y.target.value}),placeholder:v.type??"string",className:"w-full px-2 py-1.5 text-sm rounded-md border border-[hsl(var(--input))] bg-[hsl(var(--background))]"})]},p)),n.jsx("button",{type:"submit",className:"px-4 py-2 text-sm font-medium rounded-md bg-[hsl(var(--primary))] text-[hsl(var(--primary-foreground))] hover:opacity-90 transition-opacity",children:i})]})}function Yg({status:s,className:r}){return n.jsxs("span",{className:F("inline-flex items-center gap-1.5 whitespace-nowrap px-2 py-0.5 rounded-full text-xs font-medium",ZN(s),s==="running"&&"animate-pulse",r),children:[n.jsx("span",{className:F("w-1.5 h-1.5 rounded-full",s==="running"&&"bg-blue-500",s==="completed"&&"bg-green-500",s==="failed"&&"bg-red-500",s==="waiting"&&"bg-amber-500")}),s]})}function tt({label:s,value:r,subtitle:i,subtitleColor:o,accent:d,tint:f,badge:m}){return n.jsxs("div",{className:F("px-4 py-3.5 rounded-xl min-w-0",f||"bg-[hsl(var(--card))] border border-[hsl(var(--border))]"),children:[n.jsx("p",{className:"text-[11px] font-medium uppercase tracking-wider text-[hsl(var(--muted-foreground))] truncate",children:s}),m?n.jsx("div",{className:"mt-1",children:m}):n.jsx("p",{className:F("text-lg sm:text-2xl font-semibold mt-1 font-mono tracking-tight truncate select-text",d),title:r,children:r}),i&&n.jsx("p",{className:F("text-xs mt-0.5 truncate",o??"text-[hsl(var(--muted-foreground))]"),title:i,children:i})]})}function gS(s){const{events:r,askId:i,onClose:o,className:d}=s,{filtered:f,summary:m}=b.useMemo(()=>{var R;const h=r.filter(D=>"askId"in D&&D.askId===i||(D.type==="handoff_start"||D.type==="handoff_return")&&(D.fromAskId===i||D.toAskId===i)),x=h.find(D=>D.type==="ask_start"),p=h.find(D=>D.type==="ask_end"),v=(x==null?void 0:x.agent)??((R=h.find(D=>"agent"in D&&!!D.agent))==null?void 0:R.agent),y=x==null?void 0:x.prompt,E=p==null?void 0:p.cost,w=(p==null?void 0:p.unpriced)===!0,C=x&&p&&typeof x.timestamp=="number"&&typeof p.timestamp=="number"?p.timestamp-x.timestamp:void 0,_=p==null?void 0:p.outcome;return{filtered:h,summary:{agent:v,prompt:y,cost:E,unpriced:w,duration:C,outcome:_}}},[r,i]);return n.jsxs("div",{"data-testid":"ask-details","data-ask-id":i,className:F("flex flex-col h-full bg-white border-l border-slate-200 dark:bg-slate-900 dark:border-slate-700",d),children:[n.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-slate-200 dark:border-slate-700",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("span",{className:"font-medium truncate",children:m.agent??"<unknown agent>"}),n.jsx("span",{className:"text-xs font-mono text-[hsl(var(--muted-foreground))]",title:i,children:i.slice(0,8)})]}),o&&n.jsx("button",{type:"button",onClick:o,"aria-label":"Close ask details",className:"rounded p-1 hover:bg-slate-100 dark:hover:bg-slate-800",children:n.jsx(Rf,{className:"h-4 w-4"})})]}),n.jsxs("div",{className:"px-4 py-2 border-b border-slate-200 dark:border-slate-700 flex items-center gap-3 text-xs",children:[m.duration!==void 0&&n.jsx(Df,{ms:m.duration}),typeof m.cost=="number"&&n.jsx(Fa,{cost:m.cost,unpriced:m.unpriced}),m.outcome&&n.jsx("span",{className:F("inline-flex items-center rounded-full px-2 py-0.5 text-xs font-medium",m.outcome.ok?"bg-emerald-100 text-emerald-900 dark:bg-emerald-900/30 dark:text-emerald-200":"bg-red-100 text-red-900 dark:bg-red-900/30 dark:text-red-200"),children:m.outcome.ok?"ok":"failed"})]}),m.prompt&&n.jsxs("div",{className:"px-4 py-2 border-b border-slate-200 text-sm dark:border-slate-700",children:[n.jsx("div",{className:"text-xs uppercase tracking-wide text-[hsl(var(--muted-foreground))] mb-1",children:"Prompt"}),n.jsx("div",{className:"font-mono whitespace-pre-wrap break-words",children:m.prompt})]}),n.jsx("div",{className:"flex-1 overflow-auto px-2 py-2",children:f.length===0?n.jsx("div",{className:"text-sm text-[hsl(var(--muted-foreground))] py-4 text-center",children:"No events for this ask."}):n.jsx(Di,{events:f})})]})}const Kg=[{id:"24h",label:"24h"},{id:"7d",label:"7d"},{id:"30d",label:"30d"},{id:"all",label:"All"}],Vg="axl.studio.window";function vS(){try{const s=localStorage.getItem(Vg);if(s&&Kg.some(r=>r.id===s))return s}catch{}return"7d"}function bS(s){try{localStorage.setItem(Vg,s)}catch{}}function Es({value:s,onChange:r}){return n.jsx("div",{className:"inline-flex items-center gap-0.5 p-0.5 rounded-lg bg-[hsl(var(--muted))]",role:"radiogroup","aria-label":"Time window",children:Kg.map(i=>n.jsx("button",{type:"button",role:"radio","aria-checked":s===i.id,"aria-label":`Window: ${i.label}`,onClick:()=>r(i.id),className:F("px-2.5 py-1 text-xs font-medium rounded-md transition-all cursor-pointer",s===i.id?"bg-[hsl(var(--background))] text-[hsl(var(--foreground))] shadow-sm":"text-[hsl(var(--muted-foreground))] hover:text-[hsl(var(--foreground))]"),children:i.label},i.id))})}function pc(s,r){const[i,o]=b.useState(vS),[d,f]=b.useState(null),[m,h]=b.useState(null),{data:x}=Sa({queryKey:[s,i],queryFn:()=>r(i)});return Uf(s,b.useCallback(v=>{const y=v;y.snapshots&&(f(y.snapshots),typeof y.updatedAt=="number"&&h(y.updatedAt))},[])),{window:i,handleWindowChange:v=>{o(v),bS(v)},data:(d==null?void 0:d[i])??x??null,updatedAt:m}}function yS({onWorkflowClick:s,selectedWorkflow:r}={}){const{window:i,handleWindowChange:o,data:d}=pc("workflow-stats",W2),f=!d||d.totalExecutions===0,m=d?Object.entries(d.byWorkflow).sort(([,h],[,x])=>x.total-h.total):[];return f?n.jsxs("div",{className:"space-y-3 mb-5",children:[n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsx("h3",{className:"text-[11px] font-medium uppercase tracking-wider text-[hsl(var(--muted-foreground))]",children:"Workflow Stats"}),n.jsx(Es,{value:i,onChange:o})]}),n.jsxs("p",{className:"text-xs text-[hsl(var(--muted-foreground))] italic",children:["No executions in the ",i," window. Try a wider window."]})]}):n.jsxs("div",{className:"space-y-3 mb-5",children:[n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsx("h3",{className:"text-[11px] font-medium uppercase tracking-wider text-[hsl(var(--muted-foreground))]",children:"Workflow Stats"}),n.jsx(Es,{value:i,onChange:o})]}),n.jsxs("div",{className:"grid grid-cols-2 lg:grid-cols-4 gap-3",children:[n.jsx(tt,{label:"Total Executions",value:String(d.totalExecutions),subtitle:i}),n.jsx(tt,{label:"Failure Rate",value:`${(d.failureRate*100).toFixed(1)}%`,subtitle:d.failureRate>.1?"high":"normal",subtitleColor:d.failureRate>.1?"text-red-500":void 0})]}),m.length>0&&n.jsx("div",{className:"rounded-xl border border-[hsl(var(--border))] overflow-x-auto",children:n.jsxs("table",{className:"w-full text-xs min-w-[560px]",children:[n.jsx("thead",{children:n.jsxs("tr",{className:"border-b border-[hsl(var(--border))] bg-[hsl(var(--card))]",children:[n.jsx("th",{className:"py-2 px-3 text-left font-medium",children:"Workflow"}),n.jsx("th",{className:"py-2 px-3 text-right font-medium",children:"Total"}),n.jsx("th",{className:"py-2 px-3 text-right font-medium",children:"Failed"}),n.jsx("th",{className:"py-2 px-3 text-right font-medium",title:"50th percentile duration (approximate for workflows with 200+ executions)",children:"p50"}),n.jsx("th",{className:"py-2 px-3 text-right font-medium",title:"95th percentile duration (approximate for workflows with 200+ executions)",children:"p95"}),n.jsx("th",{className:"py-2 px-3 text-right font-medium",children:"Avg"})]})}),n.jsx("tbody",{children:m.map(([h,x])=>n.jsxs("tr",{onClick:s?()=>s(h):void 0,className:F("border-b last:border-b-0 border-[hsl(var(--border))]",s&&"cursor-pointer hover:bg-[hsl(var(--accent))]",r===h&&"bg-[hsl(var(--accent))]"),title:s?"Click to select this workflow":void 0,children:[n.jsx("td",{className:"py-2 px-3 font-mono",children:h}),n.jsx("td",{className:"py-2 px-3 text-right",children:x.total}),n.jsx("td",{className:"py-2 px-3 text-right",children:x.failed>0?n.jsx("span",{className:"text-red-500",children:x.failed}):"0"}),n.jsx("td",{className:"py-2 px-3 text-right font-mono",children:x.durationP50!=null?xt(x.durationP50):"—"}),n.jsx("td",{className:"py-2 px-3 text-right font-mono",children:x.durationP95!=null?xt(x.durationP95):"—"}),n.jsx("td",{className:"py-2 px-3 text-right font-mono",children:xt(x.avgDuration)})]},h))})]})})]})}function jS(){const[s,r]=b.useState(""),[i,o]=b.useState("{}"),[d,f]=b.useState(!0),[m,h]=b.useState(null),[x,p]=b.useState(void 0),[v,y]=b.useState(null),[E,w]=b.useState("idle"),[C,_]=b.useState("run"),[R,D]=b.useState("tree"),[H,T]=b.useState(void 0),{data:j=[]}=Sa({queryKey:["workflows"],queryFn:z2}),{data:k}=Sa({queryKey:["workflow",s],queryFn:()=>U2(s),enabled:!!s}),S=$g(m),B=b.useCallback(async L=>{if(s){p(void 0),y(null),w("running");try{const ie=await L2(s,L,!0);ie.streaming&&ie.executionId?h(ie.executionId):(p(ie.result),w("completed"))}catch(ie){y(ie instanceof Error?ie.message:String(ie)),w("failed")}}},[s]),$=b.useCallback(()=>{try{const L=JSON.parse(i);B(L)}catch(L){y(L instanceof Error?L.message:String(L)),w("failed")}},[i,B]),W=b.useCallback(L=>{r(L),o("{}"),p(void 0),y(null),w("idle")},[]),K=j.find(L=>L.name===s),te=b.useCallback(L=>{B(L)},[B]);b.useEffect(()=>{S.done&&E==="running"&&(w(S.error?"failed":"completed"),S.error&&y(S.error),S.result!==void 0&&p(S.result),h(null))},[S.done,S.error,S.result,E]);const re=S.events,Me=!!(k!=null&&k.inputSchema),he=Math.max(...re.map(L=>L.duration??0),1),ae=re.reduce((L,ie)=>L+(ie.duration??0),0),z=re.reduce((L,ie)=>L+Ag(ie),0);return n.jsxs("div",{className:"flex flex-col h-screen",children:[n.jsx(dl,{title:"Workflow Runner",description:K?n.jsxs(n.Fragment,{children:[n.jsx("span",{children:K.name}),(K.hasInputSchema||K.hasOutputSchema)&&n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"opacity-40 mx-1.5",children:"·"}),n.jsxs("span",{children:[K.hasInputSchema&&"input schema",K.hasInputSchema&&K.hasOutputSchema&&" · ",K.hasOutputSchema&&"output schema"]})]})]}):j.length>0?`${j.length} registered workflow${j.length!==1?"s":""} · select one to run`:"No workflows registered",actions:j.length>0&&n.jsxs("div",{className:F("inline-flex items-stretch rounded-full bg-[hsl(var(--background))] shrink-0","ring-1 ring-[hsl(var(--input))] shadow-sm","hover:ring-[hsl(var(--ring))] focus-within:ring-[hsl(var(--ring))]","transition-shadow"),children:[n.jsx(ki,{items:j,value:s,onSelect:W,getKey:L=>L.name,getLabel:L=>L.name,getDescription:L=>{const ie=[];return L.hasInputSchema&&ie.push("input schema"),L.hasOutputSchema&&ie.push("output schema"),ie.length>0?ie.join(" · "):"no schema"},placeholder:"Select workflow",searchPlaceholder:"Search workflows…",emptyLabel:"No workflows registered",shortcut:!0,triggerClassName:"rounded-l-full",ariaLabel:"Select a workflow"}),n.jsxs("button",{onClick:$,disabled:!s||E==="running",className:F("inline-flex items-center gap-1.5 pl-3.5 pr-4 py-2 text-sm font-medium cursor-pointer","bg-[hsl(var(--foreground))] text-[hsl(var(--background))] rounded-r-full","hover:opacity-90 focus:outline-none focus-visible:ring-2 focus-visible:ring-offset-1 focus-visible:ring-[hsl(var(--foreground))]","disabled:opacity-40 disabled:cursor-not-allowed transition-opacity"),children:[n.jsx(_f,{size:12,className:F("fill-current",E==="running"&&"animate-spin fill-none")}),E==="running"?"Running…":"Run"]})]})}),n.jsx("div",{role:"tablist","aria-label":"Workflow Runner views",className:"shrink-0 flex items-center gap-1 px-4 sm:px-6 border-b border-[hsl(var(--border))]",children:["run","stats"].map(L=>n.jsx("button",{type:"button",role:"tab","aria-selected":C===L,onClick:()=>_(L),className:F("px-3 py-2.5 text-sm -mb-px border-b-2 transition-colors cursor-pointer",C===L?"border-[hsl(var(--foreground))] text-[hsl(var(--foreground))] font-medium":"border-transparent text-[hsl(var(--muted-foreground))] hover:text-[hsl(var(--foreground))]"),children:L.charAt(0).toUpperCase()+L.slice(1)},L))}),C==="stats"&&n.jsx("div",{className:"flex-1 min-h-0 overflow-auto p-3 sm:p-5",children:n.jsx(yS,{onWorkflowClick:L=>{W(L),_("run")},selectedWorkflow:s})}),C==="run"&&n.jsx(jr,{className:"flex-1",defaultPercent:30,minPercent:15,maxPercent:50,left:n.jsxs("div",{className:"flex-1 overflow-y-auto p-3 sm:p-5 space-y-4",children:[Me&&n.jsxs("div",{className:"flex items-center gap-1",children:[n.jsx("button",{onClick:()=>f(!0),className:F("px-3 py-1 text-xs rounded-lg transition-colors",d?"bg-[hsl(var(--foreground))] text-[hsl(var(--background))]":"text-[hsl(var(--muted-foreground))] hover:bg-[hsl(var(--accent))]"),children:"Form"}),n.jsx("button",{onClick:()=>f(!1),className:F("px-3 py-1 text-xs rounded-lg transition-colors",d?"text-[hsl(var(--muted-foreground))] hover:bg-[hsl(var(--accent))]":"bg-[hsl(var(--foreground))] text-[hsl(var(--background))]"),children:"JSON"})]}),Me&&d?n.jsx(Gg,{schema:k.inputSchema,onSubmit:te,submitLabel:E==="running"?"Running…":"Execute"}):n.jsxs("div",{children:[n.jsx("label",{className:"block text-[11px] font-medium uppercase tracking-wider text-[hsl(var(--muted-foreground))] mb-2",children:"Input (JSON)"}),n.jsx(Qg,{value:i,onChange:o})]}),(k==null?void 0:k.outputSchema)!=null&&n.jsxs("div",{children:[n.jsx("label",{className:"block text-[11px] font-medium uppercase tracking-wider text-[hsl(var(--muted-foreground))] mb-2",children:"Output Schema"}),n.jsx(Ct,{data:k.outputSchema,collapsed:!0})]})]}),right:n.jsx("div",{className:"flex-1 overflow-y-auto p-3 sm:p-5",children:E==="idle"?n.jsx("div",{className:"flex items-center justify-center h-full",children:n.jsx(ta,{icon:n.jsx(pr,{size:32}),title:"No execution",description:"Select a workflow and click Run to see results."})}):n.jsxs("div",{className:"space-y-5",children:[n.jsxs("div",{className:"grid grid-cols-2 lg:grid-cols-4 gap-3",children:[n.jsx(tt,{label:"Status",badge:n.jsx(Yg,{status:E})}),n.jsx(tt,{label:"Steps",value:String(re.length)}),n.jsx(tt,{label:"Duration",value:ae>0?xt(ae):"—"}),n.jsx(tt,{label:"Cost",value:z>0?at(z):"—"})]}),v&&n.jsx("div",{className:"p-4 rounded-xl bg-red-50 dark:bg-red-950/30 border border-red-200 dark:border-red-800 text-red-700 dark:text-red-300 text-sm",children:v}),x!==void 0&&n.jsxs("div",{children:[n.jsx("h3",{className:"text-[11px] font-medium uppercase tracking-wider text-[hsl(var(--muted-foreground))] mb-2",children:"Result"}),n.jsx(Ct,{data:x})]}),re.length>0&&n.jsxs("div",{children:[n.jsxs("div",{className:"flex items-center justify-between mb-2",children:[n.jsx("h3",{className:"text-[11px] font-medium uppercase tracking-wider text-[hsl(var(--muted-foreground))]",children:"Timeline"}),n.jsxs("div",{className:"flex gap-1 text-xs",children:[n.jsx("button",{type:"button",onClick:()=>D("tree"),className:F("px-2 py-0.5 rounded",R==="tree"?"bg-[hsl(var(--secondary))] text-[hsl(var(--secondary-foreground))]":"text-[hsl(var(--muted-foreground))] hover:bg-[hsl(var(--secondary))]/50"),children:"Tree"}),n.jsx("button",{type:"button",onClick:()=>D("flat"),className:F("px-2 py-0.5 rounded",R==="flat"?"bg-[hsl(var(--secondary))] text-[hsl(var(--secondary-foreground))]":"text-[hsl(var(--muted-foreground))] hover:bg-[hsl(var(--secondary))]/50"),children:"Flat"})]})]}),R==="tree"?n.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-[minmax(0,1fr)_360px] gap-3 max-w-[960px]",children:[n.jsx(Dg,{events:re,selectedAskId:H,onSelectAsk:T}),H&&n.jsx(gS,{events:re,askId:H,onClose:()=>T(void 0),className:"max-h-[600px] rounded border border-slate-200 dark:border-slate-700"})]}):n.jsx(Di,{events:re,maxDuration:he,traceComplete:S.done||S.interrupted})]}),E==="running"&&re.length===0&&n.jsxs("div",{className:"flex items-center justify-center py-12 text-sm text-[hsl(var(--muted-foreground))]",children:[n.jsx(pr,{size:16,className:"animate-pulse mr-2"}),"Executing workflow…"]})]})})})]})}function o0({data:s,maxBars:r,defaultColor:i="hsl(var(--primary))",formatValue:o=f=>String(f),className:d}){const f=[...s].sort((x,p)=>p.value-x.value),m=r?f.slice(0,r):f,h=m.length>0?Math.max(...m.map(x=>x.value)):1;return m.length===0?n.jsx("p",{className:F("text-xs text-[hsl(var(--muted-foreground))]",d),children:"No data"}):n.jsx("div",{className:F("space-y-1",d),children:m.map(x=>{const p=h>0?x.value/h*100:0;return n.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[n.jsx("div",{className:"w-24 truncate font-mono text-[hsl(var(--muted-foreground))]",title:x.label,children:x.label}),n.jsx("div",{className:"relative flex-1 h-5 rounded bg-[hsl(var(--muted))]",children:n.jsx("div",{className:"absolute inset-y-0 left-0 rounded",style:{width:`${p}%`,backgroundColor:x.color??i,opacity:.7}})}),n.jsx("div",{className:"w-12 text-right font-mono tabular-nums",children:o(x.value)})]},x.label)})})}function Po({data:s,maxBars:r,formatValue:i=f=>String(f),showLegend:o=!0,className:d}){const m=[...s.map(v=>({...v,total:v.segments.reduce((y,E)=>y+E.value,0)}))].sort((v,y)=>y.total-v.total),h=r?m.slice(0,r):m,x=h.length>0?Math.max(...h.map(v=>v.total)):1;if(h.length===0)return n.jsx("p",{className:F("text-xs text-[hsl(var(--muted-foreground))]",d),children:"No data"});const p=new Map;for(const v of h)for(const y of v.segments)p.has(y.name)||p.set(y.name,y.color);return n.jsxs("div",{className:F("space-y-2",d),children:[o&&p.size>0&&n.jsx("div",{className:"flex flex-wrap gap-3 text-[10px] text-[hsl(var(--muted-foreground))]",children:Array.from(p.entries()).map(([v,y])=>n.jsxs("div",{className:"flex items-center gap-1",children:[n.jsx("span",{className:"inline-block h-2 w-2 rounded-full",style:{backgroundColor:y}}),n.jsx("span",{children:v})]},v))}),n.jsx("div",{className:"space-y-1",children:h.map(v=>{const y=x>0?v.total/x*100:0;return n.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[n.jsx("div",{className:"w-24 truncate font-mono text-[hsl(var(--muted-foreground))]",title:v.label,children:v.label}),n.jsx("div",{className:"relative flex-1 h-5 rounded bg-[hsl(var(--muted))] overflow-hidden",children:n.jsx("div",{className:"absolute inset-y-0 left-0 flex",style:{width:`${y}%`},children:v.segments.map((E,w)=>{const C=v.total>0?E.value/v.total*100:0;return n.jsx("div",{style:{width:`${C}%`,backgroundColor:E.color,opacity:.75},title:`${E.name}: ${E.value}`},`${E.name}-${w}`)})})}),n.jsx("div",{className:"w-12 text-right font-mono tabular-nums",children:i(v.total)})]},v.label)})})]})}const Ld={schema:"#f59e0b",validate:"#eab308",guardrail:"#ef4444"},NS={agent_call:"#3b82f6",tool_call:"#10b981",tool_call_rejected:"#ef4444",tool_approval:"#14b8a6",tool_denied:"#ef4444",workflow_start:"#8b5cf6",workflow_end:"#6366f1",log:"#64748b",guardrail:"#dc2626",schema_check:"#f59e0b",validate:"#eab308",delegate:"#ec4899",handoff:"#f97316",verify:"#06b6d4"};function SS(s){return NS[s]??"#64748b"}function wS(){const{window:s,handleWindowChange:r,data:i}=pc("trace-stats",P2);if(!i||i.totalEvents===0)return n.jsxs("div",{className:"p-6",children:[n.jsxs("div",{className:"flex items-center justify-between mb-6",children:[n.jsx("h3",{className:"text-sm font-medium",children:"Trace Stats"}),n.jsx(Es,{value:s,onChange:r})]}),n.jsx(ta,{icon:n.jsx(Gj,{size:32}),title:"No trace stats yet",description:"Execute workflows to see trace statistics."})]});const o=Object.entries(i.eventTypeCounts).sort(([,p],[,v])=>v-p),d=Object.entries(i.byTool).sort(([,p],[,v])=>v.accepted+v.legacy.calls-(p.accepted+p.legacy.calls)),f=Object.entries(i.retryByAgent).filter(([,p])=>p.schema+p.validate+p.guardrail>0),m=o.map(([p,v])=>({label:p,value:v,color:SS(p)})),h=d.filter(([,p])=>p.accepted>0).map(([p,v])=>({label:p,value:v.accepted})),x=f.map(([p,v])=>({label:p,segments:[{name:"schema",value:v.schema,color:Ld.schema},{name:"validate",value:v.validate,color:Ld.validate},{name:"guardrail",value:v.guardrail,color:Ld.guardrail}].filter(y=>y.value>0)}));return n.jsxs("div",{className:"p-6 space-y-6",children:[n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsx("h3",{className:"text-sm font-medium",children:"Trace Stats"}),n.jsx(Es,{value:s,onChange:r})]}),n.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-3",children:[n.jsx(tt,{label:"Total Events",value:String(i.totalEvents),subtitle:s}),n.jsx(tt,{label:"Event Types",value:String(o.length),subtitle:"distinct types"}),n.jsx(tt,{label:"Tools Used",value:String(d.length),subtitle:d.length===1?"tool":"tools"})]}),n.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[n.jsxs("div",{className:"rounded-xl border border-[hsl(var(--border))] p-4",children:[n.jsx("h4",{className:"text-sm font-medium mb-3",children:"Event Type Distribution"}),n.jsx(o0,{data:m,formatValue:p=>p.toString()})]}),n.jsxs("div",{className:"rounded-xl border border-[hsl(var(--border))] p-4",children:[n.jsxs("h4",{className:"text-sm font-medium mb-3",children:["Accepted Tool Calls"," ",h.length>10&&n.jsx("span",{className:"text-[10px] text-[hsl(var(--muted-foreground))]",children:"(top 10)"})]}),h.length===0?n.jsx("p",{className:"text-xs text-[hsl(var(--muted-foreground))]",children:"No accepted v2 tool calls in window"}):n.jsx(o0,{data:h,maxBars:10})]}),d.some(([,p])=>p.succeeded+p.failed+p.denied+p.cancelled+p.rejected>0)&&n.jsxs("div",{className:"lg:col-span-2 rounded-xl border border-[hsl(var(--border))] p-4",children:[n.jsx("h4",{className:"text-sm font-medium mb-3",children:"Tool Lifecycle Outcomes (v2)"}),n.jsx(Po,{data:d.filter(([,p])=>p.succeeded+p.failed+p.denied+p.cancelled+p.rejected>0).map(([p,v])=>({label:p,segments:[{name:"succeeded",value:v.succeeded,color:"#10b981"},{name:"failed",value:v.failed,color:"#ef4444"},{name:"denied",value:v.denied,color:"#dc2626"},{name:"cancelled",value:v.cancelled,color:"#f59e0b"},{name:"rejected",value:v.rejected,color:"#be123c"}].filter(y=>y.value>0)})),formatValue:p=>p.toString()})]}),d.some(([,p])=>p.legacy.calls+p.legacy.approved+p.legacy.denied>0)&&n.jsxs("div",{className:"lg:col-span-2 rounded-xl border border-amber-500/30 bg-amber-500/5 p-4",children:[n.jsx("h4",{className:"text-sm font-medium mb-1",children:"Legacy Tool Lifecycle (v1)"}),n.jsx("p",{className:"text-xs text-[hsl(var(--muted-foreground))] mb-3",children:"Historical call, approval, and denial counts are kept separate because v1 did not record the v2 terminal outcome union."}),n.jsx(Po,{data:d.filter(([,p])=>p.legacy.calls+p.legacy.approved+p.legacy.denied>0).map(([p,v])=>({label:p,segments:[{name:"legacy calls",value:v.legacy.calls,color:"#64748b"},{name:"legacy approved",value:v.legacy.approved,color:"#059669"},{name:"legacy denied",value:v.legacy.denied,color:"#b91c1c"}].filter(y=>y.value>0)})),formatValue:p=>p.toString()})]}),f.length>0&&n.jsxs("div",{className:"lg:col-span-2 rounded-xl border border-[hsl(var(--border))] p-4",children:[n.jsx("h4",{className:"text-sm font-medium mb-3",children:"Retries by Agent"}),n.jsx(Po,{data:x,formatValue:p=>p.toString()})]}),d.some(([,p])=>p.approved+p.denied>0)&&n.jsxs("div",{className:"lg:col-span-2 rounded-xl border border-[hsl(var(--border))] p-4",children:[n.jsx("h4",{className:"text-sm font-medium mb-3",children:"Tool Approvals / Denials"}),n.jsx(Po,{data:d.filter(([,p])=>p.approved+p.denied>0).map(([p,v])=>({label:p,segments:[{name:"approved",value:v.approved,color:"#10b981"},{name:"denied",value:v.denied,color:"#ef4444"}].filter(y=>y.value>0)})),formatValue:p=>p.toString()})]})]})]})}const kS={running:"border-l-blue-500",completed:"border-l-green-500",failed:"border-l-red-500"};function CS(s){const r=new Date(s),i=new Date;return r.getFullYear()===i.getFullYear()&&r.getMonth()===i.getMonth()&&r.getDate()===i.getDate()?r.toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit",second:"2-digit"}):r.toLocaleDateString(void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}function ES(s){switch(s.reason){case"branch_drain_timeout":return`Trace incomplete: terminal finalization stopped after ${s.timeoutMs} ms with ${s.pendingContinuations} branch continuations still running.`;case"queue_overflow":return`Trace incomplete: ${s.droppedEvents} queued events were dropped.`;case"persistence_truncated":return`Trace incomplete: persisted events were truncated at ${s.maxEvents} entries.`;case"process_interrupted":return"Trace incomplete: the process terminated before the execution reached a terminal boundary."}}function TS(){var j;const[s,r]=b.useState("events"),[i,o]=b.useState(null),[d,f]=b.useState([]),[m,h]=b.useState(""),[x,p]=b.useState(""),{data:v=[],refetch:y}=Sa({queryKey:["executions"],queryFn:H2,refetchInterval:3e3});Uf("trace:*",b.useCallback(k=>{f(S=>[...S.slice(-200),k])},[]));const E=i?i.events:d;let w=E;m&&(w=w.filter(k=>k.type===m)),x&&(w=w.filter(k=>k.agent===x));const C=b.useMemo(()=>[...new Set(E.map(k=>k.type))].sort(),[E]),_=b.useMemo(()=>[...new Set(E.map(k=>k.agent).filter(k=>!!k))].sort(),[E]),R=b.useMemo(()=>[{value:"",label:"All types"},...C.map(k=>({value:k,label:k}))],[C]),D=b.useMemo(()=>[{value:"",label:"All agents"},..._.map(k=>({value:k,label:k}))],[_]),H=Math.max(...w.map(k=>k.duration??0),1),T=b.useMemo(()=>{if(!i)return null;const k=[...new Set(i.events.map(S=>S.model).filter(Boolean))];return{duration:i.duration,eventCount:i.events.length,cost:i.totalCost,models:k}},[i]);return n.jsxs("div",{className:"flex flex-col h-screen",children:[n.jsx(dl,{title:"Trace Explorer",description:i?n.jsxs(n.Fragment,{children:[n.jsx("span",{children:i.workflow}),n.jsx("span",{className:"opacity-40 mx-1.5",children:"·"}),n.jsx("span",{className:"font-mono",children:i.executionId.slice(0,8)}),n.jsx("span",{className:"opacity-40 mx-1.5",children:"·"}),n.jsxs("span",{children:[i.events.length," event",i.events.length!==1?"s":""]})]}):n.jsxs(n.Fragment,{children:[v.length," execution",v.length!==1?"s":"",n.jsx("span",{className:"opacity-40 mx-1.5",children:"·"}),d.length," live event",d.length!==1?"s":""]}),actions:n.jsxs(n.Fragment,{children:[n.jsx(ki,{items:R,value:m,onSelect:h,getKey:k=>k.value,getLabel:k=>k.label,placeholder:"All types",searchPlaceholder:"Filter types…",variant:"filter",triggerClassName:F("rounded-full shadow-sm ring-1 transition-shadow",m?"ring-[hsl(var(--foreground))] text-[hsl(var(--foreground))] font-medium":"ring-[hsl(var(--input))]"),ariaLabel:"Filter by event type"}),_.length>0&&n.jsx(ki,{items:D,value:x,onSelect:p,getKey:k=>k.value,getLabel:k=>k.label,placeholder:"All agents",searchPlaceholder:"Filter agents…",variant:"filter",triggerClassName:F("rounded-full shadow-sm ring-1 transition-shadow",x?"ring-[hsl(var(--foreground))] text-[hsl(var(--foreground))] font-medium":"ring-[hsl(var(--input))]"),ariaLabel:"Filter by agent"}),n.jsxs("button",{onClick:()=>{y(),f([])},className:F("inline-flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium rounded-full cursor-pointer","ring-1 ring-[hsl(var(--input))] bg-[hsl(var(--background))] shadow-sm","hover:bg-[hsl(var(--muted))] hover:ring-[hsl(var(--ring))]","focus:outline-none focus-visible:ring-[hsl(var(--ring))] transition-all"),children:[n.jsx(AN,{size:12}),"Refresh"]})]})}),n.jsx("div",{role:"tablist","aria-label":"Trace views",className:"shrink-0 flex items-center gap-1 px-4 sm:px-6 border-b border-[hsl(var(--border))]",children:["events","stats"].map(k=>n.jsx("button",{type:"button",role:"tab","aria-selected":s===k,onClick:()=>r(k),className:F("px-3 py-2.5 text-sm -mb-px border-b-2 transition-colors cursor-pointer",s===k?"border-[hsl(var(--foreground))] text-[hsl(var(--foreground))] font-medium":"border-transparent text-[hsl(var(--muted-foreground))] hover:text-[hsl(var(--foreground))]"),children:k.charAt(0).toUpperCase()+k.slice(1)},k))}),s==="stats"&&n.jsx("div",{className:"flex-1 min-h-0 overflow-auto",children:n.jsx(wS,{})}),s==="events"&&n.jsx(jr,{className:"flex-1",defaultPercent:25,minPercent:15,maxPercent:40,left:n.jsxs("div",{className:"flex-1 overflow-y-auto p-4 sm:p-6 space-y-2",children:[n.jsx("h3",{className:"text-sm font-medium mb-2",children:"Executions"}),n.jsxs("button",{onClick:()=>{o(null)},className:F("w-full text-left px-3 py-2 text-xs rounded-xl border",i?"border-[hsl(var(--border))] hover:bg-[hsl(var(--accent))]":"border-[hsl(var(--primary))] bg-[hsl(var(--accent))]"),children:["Live Events (",d.length,")"]}),v.map(k=>n.jsxs("button",{onClick:()=>{o(k)},className:F("w-full text-left px-3 py-2.5 text-xs rounded-xl border border-l-[3px] transition-colors",kS[k.status]??"border-l-slate-400",(i==null?void 0:i.executionId)===k.executionId?"border-[hsl(var(--primary))] bg-[hsl(var(--accent))]":"border-[hsl(var(--border))] hover:bg-[hsl(var(--accent))]"),children:[n.jsxs("div",{className:"flex items-center justify-between gap-2",children:[n.jsx("span",{className:"font-medium truncate",children:k.workflow}),n.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[e0(k)===1&&n.jsx("span",{className:"rounded bg-amber-500/15 px-1.5 py-0.5 text-[9px] font-medium text-amber-600 dark:text-amber-400",title:"Legacy v1 lifecycle semantics",children:"legacy v1"}),n.jsx(Yg,{status:k.status})]})]}),n.jsxs("div",{className:"flex items-center justify-between mt-1",children:[n.jsxs("span",{className:"text-[hsl(var(--muted-foreground))] truncate",children:[k.executionId.slice(0,8),"… | ",k.events.length," events"]}),(k.totalCost>0||k.unpriced)&&n.jsx(Fa,{cost:k.totalCost,unpriced:k.unpriced})]}),n.jsxs("div",{className:"flex items-center gap-2 mt-1 text-[10px] text-[hsl(var(--muted-foreground))]",children:[n.jsx("span",{children:CS(k.startedAt)}),k.duration>0&&n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"text-[hsl(var(--border))]",children:"·"}),n.jsx("span",{children:xt(k.duration)})]})]})]},k.executionId)),v.length===0&&n.jsx("p",{className:"text-xs text-[hsl(var(--muted-foreground))]",children:"No executions yet"})]}),right:n.jsxs("div",{className:"flex-1 overflow-y-auto p-4 sm:p-6",children:[T&&n.jsxs("div",{className:"grid grid-cols-2 lg:grid-cols-4 gap-3 mb-4",children:[n.jsx(tt,{label:"Duration",value:xt(T.duration)}),n.jsx(tt,{label:"Events",value:String(T.eventCount)}),n.jsx(tt,{label:"Cost",value:T.cost>0?at(T.cost):"—"}),n.jsx(tt,{label:"Model",value:T.models.length>0?T.models[0]:"—",subtitle:T.models.length>1?`+${T.models.length-1} more`:void 0})]}),i&&e0(i)===1&&n.jsx("div",{className:"mb-4 rounded-lg border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-xs text-amber-700 dark:text-amber-300",children:"Legacy v1 lifecycle: tool outcomes retain their historical semantics and may contain unmatched starts."}),((j=i==null?void 0:i.observation)==null?void 0:j.complete)===!1&&n.jsx("div",{className:"mb-4 rounded-lg border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-xs text-amber-700 dark:text-amber-300",children:ES(i.observation)}),(i==null?void 0:i.status)==="completed"&&i.result!=null&&n.jsxs("div",{className:"mb-4",children:[n.jsx("h3",{className:"text-[11px] font-medium uppercase tracking-wider text-[hsl(var(--muted-foreground))] mb-2",children:"Result"}),n.jsx(Ct,{data:i.result})]}),w.length===0?n.jsx(ta,{icon:n.jsx(mc,{size:32}),title:"No trace events",description:"Execute a workflow to see trace events here."}):n.jsx(Di,{events:w,lifecycleEvents:E,traceComplete:i?i.status!=="running":void 0,maxDuration:H})]})})]})}function sf({title:s,description:r,actions:i,children:o}){return n.jsxs("div",{className:"flex flex-col h-screen",children:[n.jsx(dl,{title:s,description:r,actions:i}),n.jsx("main",{className:"flex-1 overflow-auto p-4 sm:p-6",children:o})]})}function c0({tokens:s,label:r,className:i}){return n.jsxs("span",{className:`inline-flex items-center gap-1 whitespace-nowrap px-1.5 py-0.5 rounded text-xs font-mono bg-[hsl(var(--secondary))] text-[hsl(var(--secondary-foreground))] ${i??""}`,children:[r&&n.jsx("span",{className:"text-[hsl(var(--muted-foreground))]",children:r}),qa(s)]})}function MS(s,r){const i=Math.max(0,r-s);return i<1e3?"just now":i<6e4?`${Math.floor(i/1e3)}s ago`:i<36e5?`${Math.floor(i/6e4)}m ago`:`${Math.floor(i/36e5)}h ago`}function AS(){const{window:s,handleWindowChange:r,data:i,updatedAt:o}=pc("costs",J2),[d,f]=b.useState(()=>Date.now());if(b.useEffect(()=>{const j=setInterval(()=>f(Date.now()),1e3);return()=>clearInterval(j)},[]),!i)return n.jsx(sf,{title:"Cost Dashboard",description:"Spending across agents, models, and workflows",actions:n.jsx(Es,{value:s,onChange:r}),children:n.jsx(ta,{icon:n.jsx(Ng,{size:32}),title:"No cost data",description:"Execute workflows to see cost data."})});const m=i.totalTokens.reasoning>0,h=Object.keys(i.byAgent).length,x=Object.keys(i.byModel).length,p=Object.values(i.byWorkflow).reduce((j,k)=>j+k.executions,0),v=i.retry??{primary:0,primaryCalls:0,schema:0,schemaCalls:0,validate:0,validateCalls:0,guardrail:0,guardrailCalls:0,retryCalls:0},y=v.schema+v.validate+v.guardrail,E=i.totalCost>0?y/i.totalCost*100:0,w=i.byEmbedder??{},C=Object.entries(w),_=C.reduce((j,[,k])=>j+k.cost,0),R=C.reduce((j,[,k])=>j+k.calls,0),D=C.reduce((j,[,k])=>j+(k.unpricedCalls??0),0),H=C.reduce((j,[,k])=>j+k.tokens,0),T=i.totalCost>0?_/i.totalCost*100:0;return n.jsxs(sf,{title:"Cost Dashboard",description:i.totalCost>0?n.jsxs(n.Fragment,{children:[n.jsxs("span",{children:[at(i.totalCost)," total"]}),n.jsx("span",{className:"opacity-40 mx-1.5",children:"·"}),n.jsxs("span",{children:[h," agent",h!==1?"s":""]}),n.jsx("span",{className:"opacity-40 mx-1.5",children:"·"}),n.jsxs("span",{children:[x," model",x!==1?"s":""]})]}):"Spending across agents, models, and workflows",actions:n.jsx(Es,{value:s,onChange:r}),children:[n.jsxs("div",{className:F("grid grid-cols-1 sm:grid-cols-2 gap-3 mb-8",m?"lg:grid-cols-4":"lg:grid-cols-3"),children:[n.jsx(tt,{label:"Total Cost",value:i.unpricedCalls>0?`≥ ${at(i.totalCost)}`:at(i.totalCost),subtitle:i.unpricedCalls>0?`${s} · lower bound (${i.unpricedCalls} unpriced call${i.unpricedCalls!==1?"s":""})`:s}),n.jsx(tt,{label:"Input Tokens",value:qa(i.totalTokens.input),subtitle:"prompt"}),n.jsx(tt,{label:"Output Tokens",value:qa(i.totalTokens.output),subtitle:"completion"}),m&&n.jsx(tt,{label:"Reasoning Tokens",value:qa(i.totalTokens.reasoning),subtitle:"thinking"})]}),n.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[n.jsxs("div",{children:[n.jsx("h3",{className:"text-sm font-medium mb-3",children:"Cost by Agent"}),Object.keys(i.byAgent).length===0?n.jsx("p",{className:"text-xs text-[hsl(var(--muted-foreground))]",children:"No agent data"}):n.jsx(yi,{columns:[{label:"Agent",sortKey:j=>j.agent,render:j=>n.jsx("span",{className:"font-mono",children:j.agent})},{label:"Calls",sortKey:j=>j.calls,render:j=>n.jsx("span",{children:j.calls})},{label:"Cost",sortKey:j=>j.cost,render:j=>n.jsx(Fa,{cost:j.cost,unpriced:j.unpricedCalls>0})}],rows:Object.entries(i.byAgent).map(([j,k])=>({agent:j,cost:k.cost,calls:k.calls,unpricedCalls:k.unpricedCalls??0})),rowKey:j=>j.agent,defaultSort:{index:2,dir:"desc"},costValue:j=>j.cost})]}),n.jsxs("div",{children:[n.jsx("h3",{className:"text-sm font-medium mb-3",children:"Cost by Model"}),Object.keys(i.byModel).length===0?n.jsx("p",{className:"text-xs text-[hsl(var(--muted-foreground))]",children:"No model data"}):n.jsx(yi,{columns:[{label:"Model",sortKey:j=>j.model,render:j=>n.jsx("span",{className:"font-mono",children:j.model})},{label:"Calls",sortKey:j=>j.calls,render:j=>n.jsx("span",{children:j.calls})},{label:"Tokens",sortKey:j=>j.tokens,render:j=>n.jsx(c0,{tokens:j.tokens})},{label:"Cost",sortKey:j=>j.cost,render:j=>n.jsx(Fa,{cost:j.cost,unpriced:j.unpricedCalls>0})}],rows:Object.entries(i.byModel).map(([j,k])=>({model:j,calls:k.calls,tokens:k.tokens.input+k.tokens.output,cost:k.cost,unpricedCalls:k.unpricedCalls??0})),rowKey:j=>j.model,defaultSort:{index:3,dir:"desc"},costValue:j=>j.cost})]}),n.jsxs("div",{className:"lg:col-span-2",children:[n.jsx("h3",{className:"text-sm font-medium mb-3",children:"Cost by Workflow"}),Object.keys(i.byWorkflow).length===0?n.jsx("p",{className:"text-xs text-[hsl(var(--muted-foreground))]",children:"No workflow data"}):n.jsx(yi,{columns:[{label:"Workflow",sortKey:j=>j.workflow,render:j=>n.jsx("span",{className:"font-mono",children:j.workflow})},{label:"Executions",sortKey:j=>j.executions,render:j=>n.jsx("span",{children:j.executions})},{label:"Total Cost",sortKey:j=>j.cost,render:j=>n.jsx(Fa,{cost:j.cost,unpriced:j.unpricedCalls>0})},{label:"Avg Cost",sortKey:j=>j.avgCost,render:j=>n.jsx(Fa,{cost:j.avgCost,unpriced:j.unpricedCalls>0})}],rows:Object.entries(i.byWorkflow).map(([j,k])=>({workflow:j,executions:k.executions,cost:k.cost,avgCost:k.executions>0?k.cost/k.executions:0,unpricedCalls:k.unpricedCalls??0})),rowKey:j=>j.workflow,defaultSort:{index:2,dir:"desc"},costValue:j=>j.cost})]}),C.length>0&&n.jsxs("div",{className:"lg:col-span-2",children:[n.jsxs("div",{className:"flex items-baseline justify-between mb-3",children:[n.jsx("h3",{className:"text-sm font-medium",children:"Memory (Embedder)"}),n.jsxs("span",{className:"text-xs text-[hsl(var(--muted-foreground))]",children:[D>0?`≥ ${at(_)}`:at(_)," ","across ",R," call",R!==1?"s":"",n.jsx("span",{className:"opacity-40 mx-1.5",children:"·"}),qa(H)," tokens",T>0&&n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"opacity-40 mx-1.5",children:"·"}),T.toFixed(1),"% of total"]})]})]}),n.jsx(yi,{columns:[{label:"Embedder Model",sortKey:j=>j.model,render:j=>n.jsx("span",{className:"font-mono",children:j.model})},{label:"Calls",sortKey:j=>j.calls,render:j=>n.jsx("span",{children:j.calls})},{label:"Tokens",sortKey:j=>j.tokens,render:j=>n.jsx(c0,{tokens:j.tokens})},{label:"Cost",sortKey:j=>j.cost,render:j=>n.jsx(Fa,{cost:j.cost,unpriced:j.unpricedCalls>0})}],rows:C.map(([j,k])=>({model:j,calls:k.calls,tokens:k.tokens,cost:k.cost,unpricedCalls:k.unpricedCalls??0})),rowKey:j=>j.model,defaultSort:{index:3,dir:"desc"},costValue:j=>j.cost})]}),(y>0||v.retryCalls>0)&&n.jsxs("div",{className:"lg:col-span-2",children:[n.jsxs("div",{className:"flex items-baseline justify-between mb-3",children:[n.jsx("h3",{className:"text-sm font-medium",children:"Retry Overhead"}),n.jsxs("span",{className:"text-xs text-[hsl(var(--muted-foreground))]",children:[at(y)," across ",v.retryCalls," retry call",v.retryCalls!==1?"s":"",E>0&&n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"opacity-40 mx-1.5",children:"·"}),E.toFixed(1),"% of total"]})]})]}),n.jsx(yi,{columns:[{label:"Reason",sortKey:j=>j.reason,render:j=>j.reasonLabel},{label:"Calls",sortKey:j=>j.calls,render:j=>n.jsx("span",{children:j.calls})},{label:"Cost",sortKey:j=>j.cost,render:j=>n.jsx(Fa,{cost:j.cost})}],rows:[{reason:"primary",reasonLabel:n.jsx("span",{className:"text-[hsl(var(--muted-foreground))]",children:"primary (first attempt)"}),calls:v.primaryCalls,cost:v.primary},{reason:"schema",reasonLabel:n.jsx("span",{className:"font-mono text-teal-600 dark:text-teal-400",children:"schema retry"}),calls:v.schemaCalls,cost:v.schema},{reason:"validate",reasonLabel:n.jsx("span",{className:"font-mono text-teal-600 dark:text-teal-400",children:"validate retry"}),calls:v.validateCalls,cost:v.validate},{reason:"guardrail",reasonLabel:n.jsx("span",{className:"font-mono text-rose-600 dark:text-rose-400",children:"guardrail retry"}),calls:v.guardrailCalls,cost:v.guardrail}],rowKey:j=>j.reason,defaultSort:{index:2,dir:"desc"},costValue:j=>j.cost})]})]}),n.jsxs("div",{className:"mt-6 pt-3 border-t border-[hsl(var(--border))] text-[11px] text-[hsl(var(--muted-foreground))] flex items-center gap-2 flex-wrap",children:[n.jsxs("span",{children:["Window: ",n.jsx("span",{className:"font-mono",children:s})]}),n.jsx("span",{className:"opacity-40",children:"·"}),n.jsxs("span",{children:["Last updated: ",o!=null?MS(o,d):"pending"]}),n.jsx("span",{className:"opacity-40",children:"·"}),n.jsxs("span",{children:[p," execution",p!==1?"s":""," in window"]})]})]})}function yi({columns:s,rows:r,rowKey:i,defaultSort:o,costValue:d}){const f=(o==null?void 0:o.index)??s.findIndex(C=>C.sortKey!==void 0),m=(o==null?void 0:o.dir)??"desc",[h,x]=b.useState(f),[p,v]=b.useState(m),y=b.useMemo(()=>{const C=s[h];if(!(C!=null&&C.sortKey))return r;const _=C.sortKey,R=[...r];return R.sort((D,H)=>{const T=_(D),j=_(H);if(typeof T=="number"&&typeof j=="number")return p==="asc"?T-j:j-T;const k=String(T),S=String(j);return p==="asc"?k.localeCompare(S):S.localeCompare(k)}),R},[r,s,h,p]),E=b.useMemo(()=>{if(!d)return 0;let C=0;for(const _ of r){const R=d(_);R>C&&(C=R)}return C},[r,d]),w=C=>{s[C].sortKey&&(h===C?v(_=>_==="desc"?"asc":"desc"):(x(C),v("desc")))};return n.jsx("div",{className:"rounded-xl border border-[hsl(var(--border))] overflow-x-auto",children:n.jsxs("table",{className:"w-full text-xs min-w-[480px]",children:[n.jsx("thead",{children:n.jsx("tr",{className:"border-b border-[hsl(var(--border))] bg-[hsl(var(--card))]",children:s.map((C,_)=>{const R=C.align??(_===0?"left":"right"),D=C.sortKey!==void 0,H=D&&h===_,T=H?p==="asc"?" ↑":" ↓":"";return n.jsxs("th",{"aria-sort":H?p==="asc"?"ascending":"descending":void 0,className:F("py-2 px-3 font-medium",R==="left"?"text-left":"text-right",D&&"cursor-pointer select-none hover:text-[hsl(var(--foreground))]",D&&!H&&"text-[hsl(var(--muted-foreground))]"),onClick:D?()=>w(_):void 0,title:D?"Click to sort":void 0,children:[C.label,T]},C.label)})})}),n.jsx("tbody",{children:y.map(C=>{const _=d?d(C):0;return n.jsx("tr",{className:"border-b last:border-b-0 border-[hsl(var(--border))]",children:s.map((R,D)=>{const H=R.align??(D===0?"left":"right");return n.jsxs("td",{className:F("py-2 px-3 relative",H==="left"?"text-left":"text-right"),children:[D===s.length-1&&E>0&&n.jsx("div",{className:"absolute inset-y-0 right-0 bg-[hsl(var(--primary)/0.08)] rounded-sm",style:{width:`${_/E*100}%`}}),n.jsx("span",{className:"relative",children:R.render(C)})]},R.label)})},i(C))})})]})})}function _S(){const[s,r]=b.useState("session"),[i,o]=b.useState(""),[d,f]=b.useState("{}"),[m,h]=b.useState(!1),[x,p]=b.useState(""),[v,y]=b.useState(null),[E,w]=b.useState(null),C=_i(),{data:_=[]}=Sa({queryKey:["memory",s],queryFn:()=>V2(s)}),R=ef({mutationFn:({key:k,value:S})=>X2(s,k,S),onSuccess:()=>{C.invalidateQueries({queryKey:["memory",s]}),h(!1),o(""),f("{}")}}),D=ef({mutationFn:k=>F2(s,k),onSuccess:()=>{C.invalidateQueries({queryKey:["memory",s]}),w(null)}}),H=b.useCallback(async()=>{if(!x.trim())return;const k=await Z2(x,s);y(k.results)},[x,s]),T=b.useCallback(()=>{if(i.trim())try{const k=JSON.parse(d);R.mutate({key:i,value:k})}catch{R.mutate({key:i,value:d})}},[i,d,R]),j=b.useCallback(k=>{E===k?D.mutate(k):w(k)},[E,D]);return n.jsxs(sf,{title:"Memory Browser",description:_.length>0?n.jsxs(n.Fragment,{children:[n.jsxs("span",{children:[_.length," entr",_.length!==1?"ies":"y"]}),n.jsx("span",{className:"opacity-40 mx-1.5",children:"·"}),n.jsxs("span",{children:[s," scope"]})]}):"Key-value entries stored via ctx.remember()",actions:n.jsxs("button",{type:"button",onClick:()=>h(!m),className:F("inline-flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium rounded-full cursor-pointer","bg-[hsl(var(--foreground))] text-[hsl(var(--background))] shadow-sm","hover:opacity-90 focus:outline-none focus-visible:ring-2 focus-visible:ring-[hsl(var(--ring))]","transition-opacity"),children:[n.jsx(wg,{size:12}),"Add entry"]}),children:[n.jsxs("div",{role:"tablist","aria-label":"Memory scope",className:"flex items-center gap-0 mb-4 border-b border-[hsl(var(--border))]",children:[["session","global"].map(k=>n.jsx("button",{type:"button",role:"tab","aria-selected":s===k,onClick:()=>{r(k),y(null),w(null)},className:F("px-3 py-2.5 text-sm -mb-px border-b-2 transition-colors",s===k?"border-[hsl(var(--foreground))] text-[hsl(var(--foreground))] font-medium":"border-transparent text-[hsl(var(--muted-foreground))] hover:text-[hsl(var(--foreground))]"),children:k.charAt(0).toUpperCase()+k.slice(1)},k)),n.jsx("div",{className:"flex-1"}),n.jsxs("div",{className:"flex items-center gap-1 -mb-px pb-2",children:[n.jsx("input",{value:x,onChange:k=>p(k.target.value),onKeyDown:k=>k.key==="Enter"&&H(),placeholder:"Semantic search...",className:"px-2 py-1.5 text-sm rounded-md border border-[hsl(var(--input))] bg-[hsl(var(--background))] w-48"}),n.jsx("button",{onClick:H,className:"p-1.5 rounded-md hover:bg-[hsl(var(--accent))]",children:n.jsx(nf,{size:14})})]})]}),m&&n.jsxs("div",{className:"mb-4 p-4 rounded-xl border border-[hsl(var(--border))] bg-[hsl(var(--card))] space-y-3",children:[n.jsx("input",{value:i,onChange:k=>o(k.target.value),placeholder:"Key",className:"w-full px-2 py-1.5 text-sm rounded-md border border-[hsl(var(--input))] bg-[hsl(var(--background))]"}),n.jsx(Qg,{value:d,onChange:f,placeholder:"Value (JSON)"}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("button",{onClick:T,disabled:!i.trim(),className:"px-3 py-1.5 text-sm rounded-md bg-[hsl(var(--primary))] text-[hsl(var(--primary-foreground))] hover:opacity-90 disabled:opacity-50",children:"Save"}),n.jsx("button",{onClick:()=>h(!1),className:"px-3 py-1.5 text-sm rounded-md border border-[hsl(var(--input))] hover:bg-[hsl(var(--accent))]",children:"Cancel"})]})]}),v&&n.jsxs("div",{className:"mb-4 p-4 rounded-xl border border-[hsl(var(--border))] bg-[hsl(var(--card))]",children:[n.jsx("h3",{className:"text-sm font-medium mb-2",children:"Search Results"}),v.length===0?n.jsx("p",{className:"text-xs text-[hsl(var(--muted-foreground))]",children:"No results found"}):n.jsx(Ct,{data:v})]}),_.length===0?n.jsx(ta,{icon:n.jsx(gg,{size:32}),title:"No memory entries",description:`No entries in the ${s} scope. Use ctx.remember() in workflows or add entries manually.`}):n.jsx("div",{className:"space-y-2",children:_.map(k=>n.jsxs("div",{className:"p-3 rounded-xl border border-[hsl(var(--border))] bg-[hsl(var(--card))]",children:[n.jsxs("div",{className:"flex items-center justify-between mb-2",children:[n.jsx("span",{className:"text-sm font-mono font-medium",children:k.key}),n.jsx("div",{className:"flex items-center gap-1",children:E===k.key?n.jsxs(n.Fragment,{children:[n.jsx("button",{onClick:()=>j(k.key),className:"px-2 py-0.5 text-xs rounded bg-[hsl(var(--destructive))] text-[hsl(var(--destructive-foreground))]",children:"Confirm"}),n.jsx("button",{onClick:()=>w(null),className:"px-2 py-0.5 text-xs rounded border border-[hsl(var(--input))] hover:bg-[hsl(var(--accent))]",children:"Cancel"})]}):n.jsx("button",{onClick:()=>j(k.key),className:"p-1 rounded hover:bg-[hsl(var(--destructive))] hover:text-[hsl(var(--destructive-foreground))] text-[hsl(var(--muted-foreground))]",children:n.jsx(Of,{size:14})})})]}),n.jsx(Ct,{data:k.value,collapsed:!0})]},k.key))})]})}function OS(s){try{return JSON.parse(s)}catch{return s}}function RS(s,r){if(typeof s!="string")return n.jsxs("div",{className:"space-y-1 text-xs text-[hsl(var(--muted-foreground))]",children:[n.jsx("div",{children:"Rich model input"}),s.parts.map((i,o)=>i.type==="text"?n.jsxs("div",{children:["Text: ",i.characters," characters"]},o):n.jsxs("div",{children:["Image: ",i.source,i.mediaType?` (${i.mediaType})`:"",i.bytes!==void 0?`, ${i.bytes} bytes`:""]},o))]});if(r==="assistant"){const i=s.trim();if(i.startsWith("{")||i.startsWith("["))try{const o=JSON.parse(i);return n.jsx(Ct,{data:o,collapsed:!0})}catch{}}return n.jsx("div",{className:"whitespace-pre-wrap",children:s})}function DS(){const[s,r]=b.useState(null),[i,o]=b.useState(null),[d,f]=b.useState(null),[m,h]=b.useState(null),x=_i(),{data:p=[]}=Sa({queryKey:["sessions"],queryFn:q2,refetchInterval:5e3}),{data:v}=Sa({queryKey:["session",s],queryFn:()=>B2(s),enabled:!!s}),y=ef({mutationFn:$2,onSuccess:()=>{x.invalidateQueries({queryKey:["sessions"]}),r(null),f(null)}}),E=v!=null&&v.history?i!==null?v.history.slice(0,i+1):v.history:[];return n.jsxs("div",{className:"flex flex-col h-screen",children:[n.jsx(dl,{title:"Session Manager",description:p.length>0?s&&v?n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"font-mono",children:v.id.slice(0,16)}),n.jsx("span",{className:"opacity-40 mx-1.5",children:"·"}),n.jsxs("span",{children:[v.history.length," message",v.history.length!==1?"s":""]})]}):n.jsxs(n.Fragment,{children:[n.jsxs("span",{children:[p.length," active session",p.length!==1?"s":""]}),n.jsx("span",{className:"opacity-40 mx-1.5",children:"·"}),n.jsx("span",{children:"select one to replay"})]}):"Multi-turn conversations tracked via runtime.session()"}),n.jsx(jr,{className:"flex-1",defaultPercent:33,minPercent:20,maxPercent:50,left:n.jsxs("div",{className:"flex-1 overflow-y-auto p-4 sm:p-6 space-y-2",children:[n.jsxs("h3",{className:"text-sm font-medium mb-2",children:["Sessions (",p.length,")"]}),p.length===0?n.jsx(ta,{icon:n.jsx(Cg,{size:24}),title:"No sessions",description:"Sessions are created when using runtime.session()"}):p.map(w=>n.jsxs("button",{onClick:()=>{r(w.id),o(null)},className:`w-full text-left px-3 py-2.5 text-xs rounded-xl border transition-colors ${s===w.id?"border-[hsl(var(--primary))] bg-[hsl(var(--accent))]":"border-[hsl(var(--border))] hover:bg-[hsl(var(--accent))]"}`,children:[n.jsx("div",{className:"font-mono truncate text-[11px]",title:w.id,children:w.id}),n.jsxs("div",{className:"flex items-center gap-1.5 text-[hsl(var(--muted-foreground))] mt-1",children:[n.jsx(Sg,{size:11}),n.jsxs("span",{children:[w.messageCount," message",w.messageCount!==1?"s":""]})]})]},w.id))]}),right:n.jsx("div",{className:"flex-1 overflow-y-auto p-4 sm:p-6",children:v?n.jsxs("div",{className:"space-y-4",children:[n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsxs("div",{children:[n.jsx("h3",{className:"text-sm font-medium font-mono",children:v.id}),n.jsxs("p",{className:"text-xs text-[hsl(var(--muted-foreground))]",children:[v.history.length," messages"]})]}),d===v.id?n.jsxs("div",{className:"flex items-center gap-1.5",children:[n.jsx("button",{onClick:()=>y.mutate(v.id),className:"px-2 py-1 text-xs rounded-md bg-red-600 text-white hover:bg-red-700 dark:bg-red-700 dark:hover:bg-red-800",children:"Confirm"}),n.jsx("button",{onClick:()=>f(null),className:"px-2 py-1 text-xs rounded-md border border-[hsl(var(--border))] hover:bg-[hsl(var(--accent))]",children:"Cancel"})]}):n.jsxs("button",{onClick:()=>f(v.id),className:"flex items-center gap-1 px-2 py-1 text-xs rounded-md border border-red-300 text-red-600 hover:bg-red-50 dark:border-red-800 dark:text-red-400 dark:hover:bg-red-950",children:[n.jsx(Of,{size:12}),"Delete"]})]}),v.handoffHistory&&v.handoffHistory.length>0&&n.jsxs("div",{children:[n.jsx("h4",{className:"text-xs font-medium mb-2",children:"Handoff Chain"}),n.jsx("div",{className:"flex items-center gap-1 flex-wrap",children:v.handoffHistory.map((w,C)=>n.jsxs("div",{className:"flex items-center gap-1",children:[n.jsx("span",{className:"px-2 py-0.5 text-xs rounded bg-blue-100 dark:bg-blue-900 text-blue-700 dark:text-blue-300",children:w.source}),n.jsx(mr,{size:12,className:"text-[hsl(var(--muted-foreground))]"}),n.jsx("span",{className:"px-2 py-0.5 text-xs rounded bg-blue-100 dark:bg-blue-900 text-blue-700 dark:text-blue-300",children:w.target}),n.jsxs("span",{className:"text-xs text-[hsl(var(--muted-foreground))]",children:["(",w.mode,")"]}),C<v.handoffHistory.length-1&&n.jsx("span",{className:"mx-1 text-[hsl(var(--muted-foreground))]",children:"|"})]},C))})]}),v.history.length>1&&n.jsxs("div",{className:"rounded-xl border border-[hsl(var(--border))] p-3",children:[n.jsxs("div",{className:"flex items-center justify-between mb-2",children:[n.jsx("label",{className:"text-xs font-medium",children:"Replay"}),n.jsx("span",{className:"text-xs text-[hsl(var(--muted-foreground))] font-mono",children:i!==null?`${i+1} / ${v.history.length}`:`${v.history.length} / ${v.history.length}`})]}),n.jsx("input",{type:"range",min:0,max:v.history.length-1,value:i??v.history.length-1,onChange:w=>o(Number(w.target.value)),className:"w-full h-1.5 rounded-full appearance-none cursor-pointer bg-[hsl(var(--secondary))] [&::-webkit-slider-thumb]:appearance-none [&::-webkit-slider-thumb]:w-3.5 [&::-webkit-slider-thumb]:h-3.5 [&::-webkit-slider-thumb]:rounded-full [&::-webkit-slider-thumb]:bg-[hsl(var(--primary))] [&::-webkit-slider-thumb]:shadow-sm [&::-moz-range-thumb]:w-3.5 [&::-moz-range-thumb]:h-3.5 [&::-moz-range-thumb]:rounded-full [&::-moz-range-thumb]:bg-[hsl(var(--primary))] [&::-moz-range-thumb]:border-0"}),n.jsxs("div",{className:"flex justify-between mt-1",children:[n.jsx("span",{className:"text-[10px] text-[hsl(var(--muted-foreground))]",children:"Start"}),n.jsx("span",{className:"text-[10px] text-[hsl(var(--muted-foreground))]",children:"Latest"})]})]}),n.jsx("div",{className:"space-y-3",children:E.map((w,C)=>{const _=m!==null&&w.role==="assistant"&&w.agent!==m;return n.jsxs("div",{className:`p-3 rounded-xl text-sm transition-opacity ${_?"opacity-30":""} ${w.role==="user"?"bg-[hsl(var(--primary))] text-[hsl(var(--primary-foreground))] ml-8":w.role==="assistant"?"bg-[hsl(var(--secondary))] mr-8":"bg-[hsl(var(--muted))] text-xs font-mono"}`,children:[n.jsxs("div",{className:"text-xs font-medium mb-1 flex items-center gap-1.5",children:[n.jsx("span",{className:"opacity-70",children:w.role}),w.agent&&n.jsx("button",{type:"button",onClick:()=>h(m===w.agent?null:w.agent??null),className:`px-1.5 py-0.5 rounded font-mono text-[10px] truncate max-w-[12rem] cursor-pointer transition-colors ${m===w.agent?"bg-[hsl(var(--primary))] text-[hsl(var(--primary-foreground))]":"bg-[hsl(var(--muted))] text-[hsl(var(--muted-foreground))] hover:bg-[hsl(var(--accent))] hover:text-[hsl(var(--accent-foreground))]"}`,title:m===w.agent?"Click to clear filter":`Click to highlight messages from ${w.agent}`,children:w.agent})]}),RS(w.content,w.role),w.tool_calls&&w.tool_calls.length>0&&n.jsx("div",{className:"mt-2 space-y-1",children:w.tool_calls.map(R=>n.jsxs("details",{className:"text-xs",children:[n.jsx("summary",{className:"cursor-pointer font-mono",children:R.function.name}),n.jsx(Ct,{data:OS(R.function.arguments),collapsed:!0})]},R.id))})]},C)})})]}):n.jsx(ta,{title:"Select a session",description:"Click a session to view its history"})})})]})}function zS(){const[s,r]=b.useState(null),[i,o]=b.useState(void 0),[d,f]=b.useState(null),[m,h]=b.useState(!1),[x,p]=b.useState(!1),{data:v=[]}=Sa({queryKey:["tools"],queryFn:G2}),{data:y}=Sa({queryKey:["tool",s],queryFn:()=>Y2(s),enabled:!!s}),E=b.useCallback(async C=>{if(s){o(null),f(null),h(!0);try{const _=await K2(s,C);o(_.result)}catch(_){f(_ instanceof Error?_.message:String(_))}finally{h(!1)}}},[s]),w=v.find(C=>C.name===s);return n.jsxs("div",{className:"flex flex-col h-screen",children:[n.jsx(dl,{title:"Tool Inspector",description:w?n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"font-mono",children:w.name}),w.description&&n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"opacity-40 mx-1.5",children:"·"}),n.jsx("span",{children:w.description})]})]}):v.length>0?n.jsxs(n.Fragment,{children:[n.jsxs("span",{className:"whitespace-nowrap",children:[v.length," registered tool",v.length!==1?"s":""]}),n.jsx("span",{className:"opacity-40 mx-1.5",children:"·"}),n.jsx("span",{children:"select one to inspect"})]}):"Registered tools with schemas and direct testing"}),n.jsx(jr,{className:"flex-1",defaultPercent:33,minPercent:20,maxPercent:50,left:n.jsx("div",{className:"flex-1 overflow-y-auto p-4 sm:p-6",children:n.jsxs("div",{className:"space-y-2",children:[n.jsxs("h3",{className:"text-sm font-medium mb-2",children:["Tools (",v.length,")"]}),v.length===0?n.jsx(ta,{icon:n.jsx(Eg,{size:24}),title:"No tools",description:"Register tools with runtime.registerTool()"}):v.map(C=>n.jsxs("button",{onClick:()=>{r(C.name),o(void 0),f(null),p(!1)},className:`w-full text-left px-3 py-2 text-xs rounded-xl border ${s===C.name?"border-[hsl(var(--primary))] bg-[hsl(var(--accent))]":"border-[hsl(var(--border))] hover:bg-[hsl(var(--accent))]"}`,children:[n.jsx("div",{className:"font-medium",children:C.name}),n.jsx("div",{className:"text-[hsl(var(--muted-foreground))] mt-0.5 truncate",children:C.description}),n.jsxs("div",{className:"flex items-center gap-1.5 mt-1",children:[C.sensitive&&n.jsx("span",{className:"px-1 py-0.5 rounded bg-amber-100 dark:bg-amber-900 text-amber-700 dark:text-amber-300 text-[10px]",children:"sensitive"}),C.requireApproval&&n.jsx("span",{className:"px-1 py-0.5 rounded bg-blue-100 dark:bg-blue-900 text-blue-700 dark:text-blue-300 text-[10px]",children:"approval"})]})]},C.name))]})}),right:n.jsx("div",{className:"flex-1 overflow-y-auto p-4 sm:p-6",children:s?y?n.jsxs("div",{className:"space-y-6",children:[n.jsxs("div",{children:[n.jsx("h3",{className:"text-lg font-medium",children:y.name}),n.jsx("p",{className:"text-sm text-[hsl(var(--muted-foreground))]",children:y.description})]}),n.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[y.sensitive&&n.jsx("span",{className:"px-2 py-1 text-xs rounded-md bg-amber-100 dark:bg-amber-900 text-amber-700 dark:text-amber-300",children:"Sensitive"}),y.requireApproval&&n.jsx("span",{className:"px-2 py-1 text-xs rounded-md bg-blue-100 dark:bg-blue-900 text-blue-700 dark:text-blue-300",children:"Requires Approval"}),y.retry.attempts&&y.retry.attempts>1&&n.jsxs("span",{className:"px-2 py-1 text-xs rounded-md bg-green-100 dark:bg-green-900 text-green-700 dark:text-green-300",children:["Retry: ",y.retry.attempts,"x ",y.retry.backoff]}),y.hasHooks&&y.hooks&&n.jsxs("span",{className:"px-2 py-1 text-xs rounded-md bg-purple-100 dark:bg-purple-900 text-purple-700 dark:text-purple-300",children:["Hooks:"," ",[y.hooks.hasBefore&&"before",y.hooks.hasAfter&&"after"].filter(Boolean).join(" + ")]})]}),n.jsxs("div",{children:[n.jsxs("button",{onClick:()=>p(!x),className:"flex items-center gap-1.5 text-sm font-medium text-[hsl(var(--muted-foreground))] hover:text-[hsl(var(--foreground))] transition-colors",children:[n.jsx(Ba,{size:14,className:F("transition-transform",x&&"rotate-90")}),"View raw schema"]}),x&&n.jsx("div",{className:"mt-2",children:n.jsx(Ct,{data:y.inputSchema})})]}),n.jsxs("div",{children:[n.jsx("h4",{className:"text-sm font-medium mb-2",children:"Test Tool"}),n.jsx("div",{className:"rounded-xl border border-[hsl(var(--border))] p-4 bg-[hsl(var(--card))]",children:n.jsx(Gg,{schema:y.inputSchema,onSubmit:E,submitLabel:m?"Running...":"Run Tool"})})]}),i!==void 0&&n.jsxs("div",{children:[n.jsx("h4",{className:"text-sm font-medium mb-2",children:"Result"}),n.jsx("div",{className:"rounded-xl border border-[hsl(var(--border))] p-4 bg-[hsl(var(--card))]",children:n.jsx(Ct,{data:i})})]}),d&&n.jsx("div",{className:"p-3 rounded-xl bg-red-50 dark:bg-red-950 border border-red-200 dark:border-red-800 text-red-700 dark:text-red-300 text-sm",children:d})]}):n.jsxs("div",{className:"flex items-center gap-2 text-sm text-[hsl(var(--muted-foreground))]",children:[n.jsx(dN,{size:16,className:"animate-spin"}),"Loading tool details..."]}):n.jsx(ta,{title:"Select a tool",description:"Click a tool to view its schema and test it"})})})]})}const cc={status:"idle",evalRunId:null,evalName:null,runCount:1,startedAt:null,progress:null,done:null,error:null},US=300*1e3;let Kt=cc;const lf=new Set;let lc=null,Pl=null;function Ka(s){Kt=s;for(const r of lf)r()}function LS(){return Kt}function HS(s){return lf.add(s),()=>lf.delete(s)}function er(){lc&&(lc(),lc=null),Pl&&(clearTimeout(Pl),Pl=null)}function u0(){Pl&&clearTimeout(Pl),Pl=setTimeout(()=>{Kt.status==="running"&&(Ka({...Kt,status:"error",error:"Lost contact with the server — no progress received. The eval may still be running; check the History tab."}),er())},US)}function qS(){return b.useSyncExternalStore(HS,LS)}async function BS(s,r,i=!1){if(Kt.status==="running"&&Kt.evalRunId)try{await Bg(Kt.evalRunId)}catch{}er(),Ka({...cc,status:"running",evalName:s,runCount:r,startedAt:Date.now()});let o;try{o=(await aS(s,{runs:r,captureTraces:i})).evalRunId}catch(d){Ka({...cc,status:"error",error:d instanceof Error?d.message:String(d)});return}Ka({...Kt,evalRunId:o}),u0(),lc=Ni.subscribe(`eval:${o}`,d=>{var m;const f=d;switch(u0(),f.type){case"item_done":{const h=f.itemIndex,x=f.totalItems,p=typeof f.run=="number"?f.run:1,v=typeof f.totalRuns=="number"?f.totalRuns:1;Ka({...Kt,progress:{completedItems:h+1,totalItems:x,completedRuns:p-1,totalRuns:v}});break}case"run_done":{const h=f.run,x=f.totalRuns;Ka({...Kt,progress:{completedItems:0,totalItems:((m=Kt.progress)==null?void 0:m.totalItems)??0,completedRuns:h,totalRuns:x}});break}case"done":{const h=typeof f.evalResultId=="string"?f.evalResultId:null,x=typeof f.runGroupId=="string"?f.runGroupId:void 0;Ka(h?{...Kt,status:"done",done:x?{evalResultId:h,runGroupId:x}:{evalResultId:h}}:{...Kt,status:"error",error:"Eval completed without a result id — cannot adopt from history."}),er();break}case"error":Ka({...Kt,status:"error",error:f.message}),er();break}})}async function $S(){if(Kt.evalRunId)try{await Bg(Kt.evalRunId)}catch{}Ka({...Kt,status:"error",error:"Cancelled"}),er()}function d0(){Ka(cc),er()}function QS({series:s,xMin:r,xMax:i,yMin:o,yMax:d,yDomain:f,yClamp:m,height:h=160,padding:x={top:8,right:8,bottom:20,left:32},formatX:p=C=>String(C),formatY:v=C=>C.toFixed(2),onPointClick:y,ariaLabel:E,className:w}){const[C,_]=b.useState(null),[R,D]=b.useState({width:480,height:h}),H=(f==null?void 0:f.strategy)??"data",T=(f==null?void 0:f.minSpan)??.1,j=(f==null?void 0:f.padPct)??.1;let k,S;if(H==="fixed"||o!=null&&d!=null)k=o??0,S=d??1;else{const ae=[];for(const z of s)for(const L of z.points)Number.isFinite(L.y)&&ae.push(L.y);if(ae.length===0)k=o??0,S=d??1;else{let z=Math.min(...ae),L=Math.max(...ae);if(L-z<T){const Q=(z+L)/2;z=Q-T/2,L=Q+T/2}const ve=Math.max(T,L-z)*j;let ge=z-ve,M=L+ve;(m==null?void 0:m.min)!=null&&(ge=Math.max(ge,m.min)),(m==null?void 0:m.max)!=null&&(M=Math.min(M,m.max)),k=o??ge,S=d??M}}const B=Math.max(1,R.width-x.left-x.right),$=Math.max(1,R.height-x.top-x.bottom),W=Math.max(1,i-r),K=Math.max(.001,S-k),te=ae=>x.left+(ae-r)/W*B,re=ae=>x.top+$-(ae-k)/K*$,Me=ae=>{const z=ae.currentTarget.getBoundingClientRect(),L=ae.clientX-z.left,ie=r+(L-x.left)/B*W;let ve=null,ge=1/0;for(const G of s)for(const J of G.points){const oe=Math.abs(J.x-ie);oe<ge&&(ge=oe,ve={series:G,point:J})}if(!ve)return;const M=ve.point.x,Q=[];for(const G of s){const J=G.points.find(oe=>oe.x===M);J&&Q.push({series:G,point:J})}_({x:M,points:Q})},he=[k,k+(S-k)*.25,k+(S-k)*.5,k+(S-k)*.75,S];return n.jsxs("div",{className:F("relative w-full",w),ref:ae=>{ae&&ae.clientWidth>0&&ae.clientWidth!==R.width&&D({width:ae.clientWidth,height:h})},children:[n.jsxs("svg",{width:"100%",height:R.height,viewBox:`0 0 ${R.width} ${R.height}`,preserveAspectRatio:"none",role:"img","aria-label":E??`Line chart with ${s.length} series and ${s.reduce((ae,z)=>ae+z.points.length,0)} data points.`,onMouseMove:Me,onMouseLeave:()=>_(null),onClick:y&&C&&C.points.length>0?()=>{const ae=C.points[0];y(ae.series,ae.point)}:void 0,className:F("block",y&&C&&C.points.length>0&&"cursor-pointer"),children:[he.map(ae=>n.jsxs("g",{children:[n.jsx("line",{x1:x.left,x2:R.width-x.right,y1:re(ae),y2:re(ae),stroke:"currentColor",strokeOpacity:.08,strokeDasharray:"2 3"}),n.jsx("text",{x:x.left-4,y:re(ae)+3,textAnchor:"end",fontSize:9,fill:"currentColor",fillOpacity:.5,children:v(ae)})]},ae)),(()=>{const ae=C?new Set(C.points.map(z=>z.series.name)):null;return s.map(z=>{const L=[...z.points].filter(ge=>Number.isFinite(ge.x)&&Number.isFinite(ge.y)).sort((ge,M)=>ge.x-M.x);if(L.length===0)return null;const ie=L.map((ge,M)=>`${M===0?"M":"L"} ${te(ge.x).toFixed(2)} ${re(ge.y).toFixed(2)}`).join(" "),ve=!ae||ae.has(z.name);return n.jsxs("g",{style:{opacity:ve?1:.2,transition:"opacity 120ms ease-out"},children:[n.jsx("path",{d:ie,stroke:z.color,strokeWidth:ve&&ae?2:1.5,fill:"none"}),L.map((ge,M)=>ge.partial?n.jsx("circle",{cx:te(ge.x),cy:re(ge.y),r:3,fill:"hsl(var(--background))",stroke:z.color,strokeWidth:1.5,children:n.jsxs("title",{children:["Partial batch",ge.label?` — ${ge.label}`:""," (fewer runs completed than planned)"]})},M):n.jsx("circle",{cx:te(ge.x),cy:re(ge.y),r:2.5,fill:z.color},M))]},z.name)})})(),C&&n.jsxs("g",{children:[n.jsx("line",{x1:te(C.x),x2:te(C.x),y1:x.top,y2:R.height-x.bottom,stroke:"currentColor",strokeOpacity:.15}),C.points.map(({series:ae,point:z})=>n.jsx("circle",{cx:te(z.x),cy:re(z.y),r:4,fill:ae.color,stroke:"hsl(var(--background))",strokeWidth:1.5},ae.name))]}),n.jsx("text",{x:x.left,y:R.height-4,fontSize:9,fill:"currentColor",fillOpacity:.5,textAnchor:"start",children:p(r)}),n.jsx("text",{x:R.width-x.right,y:R.height-4,fontSize:9,fill:"currentColor",fillOpacity:.5,textAnchor:"end",children:p(i)})]}),C&&(()=>{var ge;const ae=te(C.x),z=8,L=240,ve=ae>R.width/2?{right:`${Math.max(z,R.width-ae+z)}px`,top:`${x.top+2}px`,maxWidth:`${L}px`}:{left:`${Math.min(ae+z,R.width-z)}px`,top:`${x.top+2}px`,maxWidth:`${L}px`};return n.jsxs("div",{className:"pointer-events-none absolute z-10 rounded border border-[hsl(var(--border))] bg-[hsl(var(--card))] px-2 py-1 text-[10px] shadow-sm",style:ve,children:[n.jsx("div",{className:"mb-0.5 text-[hsl(var(--muted-foreground))]",children:p(C.x)}),C.points.map(({series:M,point:Q})=>n.jsxs("div",{className:"flex items-center gap-1.5",children:[n.jsx("span",{className:"inline-block h-2 w-2 rounded-full shrink-0",style:{backgroundColor:M.color}}),n.jsx("span",{className:"font-mono truncate",children:M.name}),n.jsx("span",{className:"ml-auto font-mono shrink-0",children:v(Q.y)})]},M.name)),((ge=C.points[0])==null?void 0:ge.point.label)&&n.jsx("div",{className:"mt-0.5 truncate text-[hsl(var(--muted-foreground))]",children:C.points[0].point.label})]})})()]})}function GS({values:s,color:r="hsl(var(--primary))",width:i=120,height:o=24,fill:d=!0,className:f}){if(s.length===0)return n.jsx("div",{className:F("inline-block",f),style:{width:i,height:o}});if(s.length===1)return n.jsx("svg",{width:i,height:o,className:F("inline-block",f),children:n.jsx("circle",{cx:i/2,cy:o/2,r:2,fill:r})});const m=Math.min(...s),h=Math.max(...s),x=Math.max(.001,h-m),p=2,v=o-p*2,E=s.map((C,_)=>{const R=_/(s.length-1)*i,D=p+v-(C-m)/x*v;return[R,D]}).map(([C,_],R)=>`${R===0?"M":"L"} ${C.toFixed(1)} ${_.toFixed(1)}`).join(" "),w=d?`${E} L ${i} ${o} L 0 ${o} Z`:null;return n.jsxs("svg",{width:i,height:o,viewBox:`0 0 ${i} ${o}`,className:F("inline-block",f),children:[w&&n.jsx("path",{d:w,fill:r,fillOpacity:.12}),n.jsx("path",{d:E,stroke:r,strokeWidth:1.25,fill:"none"})]})}function f0(s){return s>=.8?"text-green-600 dark:text-green-400":s>=.5?"text-amber-600 dark:text-amber-400":"text-red-600 dark:text-red-400"}function Hd(s){return s.toFixed(3)}const h0=["#3b82f6","#10b981","#f59e0b","#ef4444","#8b5cf6","#ec4899","#14b8a6","#f97316"];function Is(s,r){return h0[r%h0.length]??"#64748b"}function YS(s){const r=new Date(s),o=Date.now()-s,d=1440*60*1e3;return o<d?r.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):o<7*d?r.toLocaleDateString([],{weekday:"short"}):r.toLocaleDateString()}function KS({onViewRun:s}={}){const{window:r,handleWindowChange:i,data:o}=pc("eval-trends",I2),[d,f]=b.useState("scorer");if(!o||o.totalRuns===0)return n.jsxs("div",{className:"flex-1 overflow-auto p-6",children:[n.jsxs("div",{className:"flex items-center justify-between mb-6",children:[n.jsx("h3",{className:"text-sm font-medium",children:"Eval Trends"}),n.jsx(Es,{value:r,onChange:i})]}),n.jsx(ta,{icon:n.jsx(QN,{size:32}),title:"No eval trends yet",description:"Run evaluations to see score trends over time."})]});const m=Object.keys(o.byEval).sort();return n.jsxs("div",{className:"flex-1 overflow-auto p-6 space-y-6",children:[n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsx("h3",{className:"text-sm font-medium",children:"Eval Trends"}),n.jsx(Es,{value:r,onChange:i})]}),n.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-3",children:[n.jsx(tt,{label:"Total Runs",value:String(o.totalRuns),subtitle:r}),n.jsx(tt,{label:"Evals Tracked",value:String(m.length),subtitle:m.length===1?"eval":"evals"}),n.jsx(tt,{label:"Total Cost",value:at(o.totalCost),subtitle:"all evals"})]}),n.jsxs("div",{className:"flex items-center gap-1 text-xs",role:"group","aria-label":"Trend chart view mode",children:[n.jsx("span",{className:"text-[hsl(var(--muted-foreground))] mr-1",children:"View:"}),["scorer","model","duration"].map(h=>n.jsx("button",{onClick:()=>f(h),"aria-pressed":d===h,className:F("px-2.5 py-1 rounded-md transition-colors",d===h?"bg-[hsl(var(--foreground))] text-[hsl(var(--background))]":"text-[hsl(var(--muted-foreground))] hover:bg-[hsl(var(--accent))]"),children:h==="scorer"?"By Scorer":h==="model"?"By Model":"Duration"},h))]}),m.map(h=>{const x=o.byEval[h],p=Object.keys(x.scoreMean).sort(),v=[...x.runs].sort((S,B)=>S.timestamp-B.timestamp),y=(()=>{const S=new Map;for(const $ of v)$.runGroupId&&S.set($.runGroupId,(S.get($.runGroupId)??0)+1);const B=new Set;for(const $ of v)$.runGroupId&&typeof $.batchAttempted=="number"&&(S.get($.runGroupId)??0)<$.batchAttempted&&B.add($.id);return B})();let E=[],w=[],C="",_,R=S=>S.toFixed(2);if(d==="scorer")C="Score Trend by Scorer",_={min:0,max:1},E=p.map((S,B)=>({name:S,color:Is(S,B),points:v.filter($=>$.scores[S]!=null).map($=>({x:$.timestamp,y:$.scores[S],label:$.model?`${$.id.slice(0,8)}… · ${$.model}`:$.id,meta:$,...y.has($.id)?{partial:!0}:{}}))})),w=p.map((S,B)=>({name:S,color:Is(S,B)}));else if(d==="model"){C="Score Trend by Model (mean of all scorers)",_={min:0,max:1};const S=new Map;for(const $ of v){const W=$.model??"unknown",K=S.get(W)??[];K.push($),S.set(W,K)}const B=[...S.keys()].sort();E=B.map(($,W)=>{const K=S.get($)??[];return{name:$,color:Is($,W),points:K.map(te=>{const re=Object.values(te.scores).filter(he=>Number.isFinite(he));if(re.length===0)return null;const Me=re.reduce((he,ae)=>he+ae,0)/re.length;return{x:te.timestamp,y:Me,label:`${te.id.slice(0,8)}… · ${$}`,meta:te,...y.has(te.id)?{partial:!0}:{}}}).filter(te=>te!==null)}}),w=B.map(($,W)=>({name:$,color:Is($,W)}))}else{C="Duration Trend by Model",R=$=>xt($);const S=new Map;for(const $ of v){if($.duration==null)continue;const W=$.model??"unknown",K=S.get(W)??[];K.push($),S.set(W,K)}const B=[...S.keys()].sort();E=B.map(($,W)=>{const K=S.get($)??[];return{name:$,color:Is($,W),points:K.map(te=>({x:te.timestamp,y:te.duration,label:`${te.id.slice(0,8)}… · ${$}`,meta:te,...y.has(te.id)?{partial:!0}:{}}))}}),w=B.map(($,W)=>({name:$,color:Is($,W)}))}const D=v.length>0?v[0].timestamp:0,H=v.length>0?v[v.length-1].timestamp:1,T=v.map(S=>S.cost),j=E.some(S=>S.points.length>=2),k=d==="duration"&&v.every(S=>S.duration==null)?"No duration metadata recorded on these runs.":(d==="model"||d==="duration")&&v.every(S=>S.model==null)?'No model metadata recorded on these runs — each run will show as "unknown".':null;return n.jsxs("div",{className:"rounded-xl border border-[hsl(var(--border))] overflow-hidden",children:[n.jsxs("div",{className:"px-4 py-3 bg-[hsl(var(--card))] border-b border-[hsl(var(--border))] flex items-center justify-between",children:[n.jsxs("div",{children:[n.jsx("span",{className:"font-mono text-sm font-medium",children:h}),n.jsxs("span",{className:"text-xs text-[hsl(var(--muted-foreground))] ml-2",children:[x.runCount," run",x.runCount!==1?"s":""]})]}),n.jsxs("div",{className:"flex items-center gap-3",children:[T.length>1&&n.jsxs("div",{className:"flex items-center gap-2 text-[10px] text-[hsl(var(--muted-foreground))]",title:"Cost over time",children:[n.jsx("span",{children:"cost"}),n.jsx(GS,{values:T,color:"hsl(var(--primary))",width:80,height:22})]}),n.jsx(Fa,{cost:x.costTotal})]})]}),v.length>1&&n.jsxs("div",{className:"px-4 py-3 border-b border-[hsl(var(--border))]",children:[n.jsxs("div",{className:"flex items-center justify-between mb-2",children:[n.jsx("p",{className:"text-[11px] font-medium uppercase tracking-wider text-[hsl(var(--muted-foreground))]",children:C}),n.jsxs("div",{className:"flex flex-wrap gap-2 text-[10px]",children:[w.map(S=>n.jsxs("div",{className:"flex items-center gap-1",children:[n.jsx("span",{className:"inline-block h-2 w-2 rounded-full",style:{backgroundColor:S.color}}),n.jsx("span",{className:"font-mono text-[hsl(var(--muted-foreground))]",children:S.name})]},S.name)),y.size>0&&n.jsxs("div",{className:"flex items-center gap-1",title:"Hollow ring marks a partial-batch run (fewer runs completed than were planned). The line still passes through it; the marker style is the only difference.",children:[n.jsx("span",{className:"inline-block h-2 w-2 rounded-full border",style:{borderColor:"hsl(var(--muted-foreground))",backgroundColor:"hsl(var(--background))"}}),n.jsx("span",{className:"font-mono text-[hsl(var(--muted-foreground))]",children:"partial"})]})]})]}),k?n.jsx("p",{className:"py-4 text-xs text-[hsl(var(--muted-foreground))] italic",children:k}):j?n.jsx(QS,{series:E,xMin:D,xMax:H,yClamp:_,yDomain:{strategy:"data",minSpan:d==="duration"?100:.1,padPct:.1},height:180,formatX:YS,formatY:R,ariaLabel:`${h}: ${C}, ${E.length} series across ${v.length} runs. Click a point to view that run.`,onPointClick:s?(S,B)=>{const $=B.meta;$!=null&&$.id&&s($.id)}:void 0}):n.jsx("p",{className:"py-4 text-xs text-[hsl(var(--muted-foreground))] italic",children:d==="scorer"?"Need at least 2 runs to draw a trend.":d==="model"?"Not enough runs per model yet — need at least 2 runs from the same model to draw a trend.":"Not enough runs per model with duration to draw a trend."})]}),v.length===1&&p.length>0&&n.jsx("p",{className:"px-4 py-2 text-[11px] text-[hsl(var(--muted-foreground))] border-b border-[hsl(var(--border))]",children:"Only one run in window — run again to see trend line."}),p.length>0&&n.jsxs("table",{className:"w-full text-xs",children:[n.jsx("thead",{children:n.jsxs("tr",{className:"border-b border-[hsl(var(--border))] bg-[hsl(var(--card))]",children:[n.jsx("th",{className:"py-2 px-4 text-left font-medium",children:"Scorer"}),n.jsx("th",{className:"py-2 px-4 text-right font-medium",children:"Latest"}),n.jsxs("th",{className:"py-2 px-4 text-right font-medium",title:x.runCount>50?"Computed over the 50 most recent runs":void 0,children:["Mean",x.runCount>50?"*":""]}),n.jsxs("th",{className:"py-2 px-4 text-right font-medium",title:x.runCount>50?"Computed over the 50 most recent runs":void 0,children:["Std",x.runCount>50?"*":""]})]})}),n.jsx("tbody",{children:p.map((S,B)=>n.jsxs("tr",{className:"border-b last:border-b-0 border-[hsl(var(--border))]",children:[n.jsx("td",{className:"py-2 px-4 font-mono",children:n.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[n.jsx("span",{className:"inline-block h-2 w-2 rounded-full",style:{backgroundColor:d==="scorer"?Is(S,B):"hsl(var(--muted-foreground) / 0.4)"}}),S]})}),n.jsx("td",{className:F("py-2 px-4 text-right font-mono",f0(x.latestScores[S]??0)),children:x.latestScores[S]!=null?Hd(x.latestScores[S]):"—"}),n.jsx("td",{className:F("py-2 px-4 text-right font-mono",f0(x.scoreMean[S]??0)),children:Hd(x.scoreMean[S]??0)}),n.jsx("td",{className:"py-2 px-4 text-right font-mono text-[hsl(var(--muted-foreground))]",children:Hd(x.scoreStd[S]??0)})]},S))})]}),x.runCount>50&&n.jsx("p",{className:"px-4 pt-2 text-[10px] text-[hsl(var(--muted-foreground))]",children:"* Mean and Std computed over the 50 most recent runs"})]},h)})]})}function m0(s){var y,E,w,C;if(s.length===0)return null;const r=s[0],i=Object.keys(((y=r.summary)==null?void 0:y.scorers)??{}),o={};for(const _ of i){const R=s.filter($=>{var K,te,re;const W=(re=(te=(K=$.summary)==null?void 0:K.scorers)==null?void 0:te[_])==null?void 0:re.scored;return W==null||W>0}),H=(R.length>0?R:s).map($=>{var W,K,te;return((te=(K=(W=$.summary)==null?void 0:W.scorers)==null?void 0:K[_])==null?void 0:te.mean)??0}),T=H.reduce(($,W)=>$+W,0)/H.length,j=H.length>1?Math.sqrt(H.reduce(($,W)=>$+(W-T)**2,0)/(H.length-1)):0,k=s.reduce(($,W)=>{var K,te,re;return $+(((re=(te=(K=W.summary)==null?void 0:K.scorers)==null?void 0:te[_])==null?void 0:re.scored)??0)},0),S=s.reduce(($,W)=>{var K,te,re;return $+(((re=(te=(K=W.summary)==null?void 0:K.scorers)==null?void 0:te[_])==null?void 0:re.failed)??0)},0),B=s.reduce(($,W)=>{var K,te,re;return $+(((re=(te=(K=W.summary)==null?void 0:K.scorers)==null?void 0:te[_])==null?void 0:re.skipped)??0)},0);o[_]={mean:Math.round(T*1e3)/1e3,std:Math.round(j*1e3)/1e3,min:Math.round(Math.min(...H)*1e3)/1e3,max:Math.round(Math.max(...H)*1e3)/1e3,scored:k,failed:S,skipped:B}}const d=new Set,f=[];for(const _ of s){const R=(E=_.metadata)==null?void 0:E.workflows;if(Array.isArray(R))for(const D of R)typeof D=="string"&&!d.has(D)&&(d.add(D),f.push(D))}const m={runGroupId:((w=r.metadata)==null?void 0:w.runGroupId)??"",runCount:s.length,workflows:f.length>0?f:void 0,scorers:o};let h;for(const _ of s){const R=(C=_.metadata)==null?void 0:C.batchAttempted;if(typeof R=="number"&&Number.isFinite(R)){h=R;break}}const x=h!==void 0&&s.length<h,p=x?s.map(_=>{var R;return(R=_.metadata)==null?void 0:R.batchFailure}).find(_=>typeof _=="string"&&_.length>0):void 0,v=VS(s);return{...r,summary:{...r.summary,...v.length>0?{degraded:v}:{}},_multiRun:{aggregate:m,allRuns:s,...x&&{partial:!0,batchCompleted:s.length,batchAttempted:h,...p?{batchFailure:p}:{}}}}}function VS(s){const r=new Map;for(const i of s)for(const o of Fg(i)){const d=r.get(o.scorer);if(!d)r.set(o.scorer,{...o,runsAffected:1});else{const f=o.rate>d.rate?o:d;r.set(o.scorer,{...f,runsAffected:d.runsAffected+1})}}return[...r.values()]}function uc(s){return s>=.8?"bg-emerald-100 dark:bg-emerald-900/50 text-emerald-700 dark:text-emerald-300":s>=.5?"bg-amber-100 dark:bg-amber-900/40 text-amber-700 dark:text-amber-300":"bg-red-100 dark:bg-red-900/40 text-red-700 dark:text-red-300"}function xc(s){return s>=.8?"bg-emerald-500 dark:bg-emerald-400":s>=.5?"bg-amber-500 dark:bg-amber-400":"bg-red-500 dark:bg-red-400"}function Rt(s){return s>=.8?"text-emerald-600 dark:text-emerald-400":s>=.5?"text-amber-600 dark:text-amber-400":"text-red-600 dark:text-red-400"}function p0(s){return s>=.8?"bg-emerald-50/60 dark:bg-emerald-950/20":s>=.5?"bg-amber-50/60 dark:bg-amber-950/20":"bg-red-50/60 dark:bg-red-950/20"}function XS(s){var r;return Array.isArray((r=s.metadata)==null?void 0:r.models)?s.metadata.models.filter(i=>typeof i=="string"):[]}function Xg(s,r){var f,m,h,x;const i=[];let o=0,d=0;for(const p of s){if(p.error)continue;const v=p.scores[r];v!=null?i.push(v):((m=(f=p.scoreDetails)==null?void 0:f[r])==null?void 0:m.skipped)===!0?d++:((x=(h=p.scoreDetails)==null?void 0:h[r])==null?void 0:x.duration)!=null&&o++}return{scores:i,failed:o,skipped:d}}function FS(s,r,i){const o=i?Xg(i,r):void 0,d=s.skipped??(o==null?void 0:o.skipped)??0;return s.scored!=null&&s.failed!=null?{scored:s.scored,failed:s.failed,skipped:d}:o?{scored:o.scores.length,failed:o.failed,skipped:d}:{scored:s.scored??0,failed:s.failed??0,skipped:d}}function $n(s){var r;return Array.isArray((r=s.metadata)==null?void 0:r.models)?s.metadata.models.filter(i=>typeof i=="string"):[]}function ZS(s){var i;const r=(i=s.metadata)==null?void 0:i.droppedAnnotationKeys;return Array.isArray(r)?r.filter(o=>typeof o=="string"):[]}function JS(s){var i,o;if(((i=s.metadata)==null?void 0:i.scorerFiltered)!==!0)return[];const r=(o=s.metadata)==null?void 0:o.scorersRun;return Array.isArray(r)?r.filter(d=>typeof d=="string"):[]}function Fg(s){var i;const r=(i=s.summary)==null?void 0:i.degraded;return Array.isArray(r)?r.filter(o=>o!=null&&typeof o=="object"&&typeof o.scorer=="string"&&typeof o.rate=="number"&&typeof o.limit=="number"&&(o.type==="llm"||o.type==="deterministic")&&typeof o.scored=="number"&&typeof o.failed=="number"):[]}function Ts(s){var o;const r=(o=s.metadata)==null?void 0:o.modelCounts;if(!r||typeof r!="object")return null;const i={};for(const[d,f]of Object.entries(r))typeof f=="number"&&(i[d]=f);return Object.keys(i).length>0?i:null}function tr(s){var d,f;const r=(d=s._multiRun)==null?void 0:d.aggregate.workflows;if(Array.isArray(r)&&r.length>0){const m=r.filter(h=>typeof h=="string");if(m.length>0)return m}const i=(f=s.metadata)==null?void 0:f.workflows;if(Array.isArray(i)){const m=i.filter(h=>typeof h=="string");if(m.length>0)return m}const o=s.workflow;return typeof o=="string"&&o?[o]:[]}function rf(s){var o;const r=(o=s.metadata)==null?void 0:o.workflowCounts;if(!r||typeof r!="object")return null;const i={};for(const[d,f]of Object.entries(r))typeof f=="number"&&(i[d]=f);return Object.keys(i).length>0?i:null}function wa(s){const r=s.indexOf(":");return r>=0?s.slice(r+1):s}function Zg(s){var o;const r=(o=s.metadata)==null?void 0:o.tokens;if(!r||typeof r!="object")return null;const i=r;return typeof i.input!="number"?null:{input:i.input,output:typeof i.output=="number"?i.output:0,reasoning:typeof i.reasoning=="number"?i.reasoning:0}}function IS(s){var i;const r=(i=s.metadata)==null?void 0:i.agentCalls;return typeof r=="number"?r:0}function of(s){const r={input:0,output:0,reasoning:0};for(const i of s.items){const o=Zg(i);o&&(r.input+=o.input,r.output+=o.output,r.reasoning+=o.reasoning)}return r}function Lf(s){const r=new Map;for(const i of s){const o=i.data,d=Ts(o);if(d)for(const[f,m]of Object.entries(d))r.set(f,(r.get(f)??0)+m);else for(const f of $n(o))r.set(f,(r.get(f)??0)+1)}return[...r.entries()].sort((i,o)=>o[1]-i[1])}function x0(s){const r={input:0,output:0,reasoning:0};for(const i of s){const o=of(i);r.input+=o.input,r.output+=o.output,r.reasoning+=o.reasoning}return r}function g0(s){return s.reduce((r,i)=>r+i.totalCost,0)}function Hf({failed:s,skipped:r,scored:i}){const o=s??0;return n.jsxs(n.Fragment,{children:[o>0&&n.jsx("span",{className:"ml-1.5 px-1 py-0.5 text-[9px] font-medium rounded bg-amber-100 text-amber-700 dark:bg-amber-900/40 dark:text-amber-300 align-middle",title:`${s} scorer run(s) failed — the mean is computed over the runs/items that succeeded.`,children:i!=null?`${i}/${i+o} scored, ${o} failed`:`${o} failed`}),(r??0)>0&&n.jsxs("span",{className:"ml-1.5 px-1 py-0.5 text-[9px] font-medium rounded bg-[hsl(var(--muted))] text-[hsl(var(--muted-foreground))] align-middle",title:`${r} item(s) not applicable to this scorer (applies predicate returned false) — excluded from the mean and the failure rate`,children:["N/A: ",r]})]})}function WS(s,r){if(r===0)return"text-[hsl(var(--muted-foreground))]";const i=s/r;return i<.02?"text-[hsl(var(--muted-foreground))]":i<=.05?"text-amber-600 dark:text-amber-400":"text-red-600 dark:text-red-400"}function PS({name:s,stats:r,isLlm:i}){const o=(r.scored??0)>0;return n.jsxs("tr",{className:"border-b border-[hsl(var(--border))] last:border-b-0",children:[n.jsxs("td",{className:"px-4 py-2.5 font-mono",children:[s,i&&n.jsx("span",{className:"ml-1.5 px-1 py-0.5 text-[9px] font-medium rounded bg-purple-100 text-purple-600 dark:bg-purple-900/30 dark:text-purple-400 align-middle",title:"LLM scorer — scores may vary between runs",children:"LLM"}),n.jsx(Hf,{failed:r.failed,skipped:r.skipped})]}),o?n.jsxs(n.Fragment,{children:[n.jsx("td",{className:F("px-3 py-2.5 text-right font-mono font-medium",Rt(r.mean)),children:r.mean.toFixed(3)}),n.jsx("td",{className:F("px-3 py-2.5 text-right font-mono",WS(r.std,r.mean)),children:r.std.toFixed(3)}),n.jsx("td",{className:F("px-3 py-2.5 text-right font-mono",Rt(r.min)),children:r.min.toFixed(3)}),n.jsx("td",{className:F("px-3 py-2.5 text-right font-mono",Rt(r.max)),children:r.max.toFixed(3)})]}):n.jsx("td",{colSpan:4,className:"px-3 py-2.5 text-center text-[hsl(var(--muted-foreground))]",children:"No valid scores"})]})}const e5=20;function v0({result:s}){const r=ZS(s);if(r.length===0)return null;const i=r.slice(0,e5),o=r.length-i.length,d=r.length===1;return n.jsxs("div",{className:"mb-3 rounded-md border border-amber-300/60 bg-amber-50 dark:border-amber-500/40 dark:bg-amber-950/40 px-4 py-3 text-sm text-amber-900 dark:text-amber-200",role:"status",children:[n.jsxs("div",{className:"font-medium",children:[r.length," annotation ",d?"key":"keys"," dropped by the dataset schema"]}),n.jsxs("div",{className:"mt-1 text-amber-800/90 dark:text-amber-300/90",children:["Stripped before reaching scorers, so any scorer reading ",d?"it":"them"," silently sees ",n.jsx("code",{className:"font-mono",children:"undefined"}),". Declare ",d?"it":"them"," in the dataset’s ",n.jsx("code",{className:"font-mono",children:"annotations"})," schema."]}),n.jsxs("div",{className:"mt-2 flex flex-wrap gap-1",children:[i.map(f=>n.jsx("span",{className:"px-1.5 py-0.5 rounded bg-amber-100 dark:bg-amber-900/50 text-amber-800 dark:text-amber-200 text-[10px] font-mono font-medium",children:f},f)),o>0&&n.jsxs("span",{className:"px-1.5 py-0.5 text-[10px] text-amber-800/80 dark:text-amber-300/80 font-medium",children:["+",o," more"]})]})]})}const t5=20;function b0({result:s}){const r=JS(s);if(r.length===0)return null;const i=r.slice(0,t5),o=r.length-i.length,d=r.length===1;return n.jsxs("div",{className:"mb-3 rounded-md border border-amber-300/60 bg-amber-50 dark:border-amber-500/40 dark:bg-amber-950/40 px-4 py-3 text-sm text-amber-900 dark:text-amber-200",role:"status",children:[n.jsxs("div",{className:"font-medium",children:["Filtered scorer subset — ran ",r.length," ",d?"scorer":"scorers"]}),n.jsxs("div",{className:"mt-1 text-amber-800/90 dark:text-amber-300/90",children:["Only ",d?"this scorer was":"these scorers were"," run, not the eval’s full set. This is not a full-coverage run — don’t use it as a baseline."]}),n.jsxs("div",{className:"mt-2 flex flex-wrap gap-1",children:[i.map(f=>n.jsx("span",{className:"px-1.5 py-0.5 rounded bg-amber-100 dark:bg-amber-900/50 text-amber-800 dark:text-amber-200 text-[10px] font-mono font-medium",children:f},f)),o>0&&n.jsxs("span",{className:"px-1.5 py-0.5 text-[10px] text-amber-800/80 dark:text-amber-300/80 font-medium",children:["+",o," more"]})]})]})}const a5=5;function n5(s){const r=s.scored+s.failed,i=(s.rate*100).toFixed(1),o=`"${s.scorer}" failed ${i}% (${s.failed}/${r})`,d=s.runsAffected!=null&&s.runsAffected>0?` (in ${s.runsAffected} run${s.runsAffected===1?"":"s"})`:"";return s.type==="deterministic"?`${o} — deterministic scorers tolerate no failures${d}`:`${o} — over the ${(s.limit*100).toFixed(1)}% limit (llm)${d}`}function y0({result:s}){const r=Fg(s);if(r.length===0)return null;const i=r.slice(0,a5),o=r.length-i.length,d=r.length===1;return n.jsxs("div",{className:"mb-3 rounded-md border border-amber-300/60 bg-amber-50 dark:border-amber-500/40 dark:bg-amber-950/40 px-4 py-3 text-sm text-amber-900 dark:text-amber-200",role:"status",children:[n.jsxs("div",{className:"font-medium",children:[r.length," ",d?"scorer":"scorers"," exceeded the failure-rate tolerance"]}),n.jsxs("div",{className:"mt-1 text-amber-800/90 dark:text-amber-300/90",children:[d?"This scorer":"These scorers"," ran and failed on too many items, so the reported mean rests on a thinned, unrepresentative sample — don’t trust it."]}),n.jsxs("ul",{className:"mt-2 space-y-0.5",children:[i.map(f=>n.jsx("li",{className:"text-[11px] font-mono text-amber-800/90 dark:text-amber-300/90",children:n5(f)},f.scorer)),o>0&&n.jsxs("li",{className:"text-[11px] text-amber-800/80 dark:text-amber-300/80 font-medium",children:["+",o," more"]})]})]})}function s5({summary:s,items:r,totalCost:i,scorerTypes:o}){const d=s.scorers?Object.entries(s.scorers):[];return d.length===0&&!s.timing&&i<=0?null:n.jsxs("div",{className:"rounded-xl border border-[hsl(var(--border))] overflow-hidden",children:[n.jsx("div",{className:"px-4 py-2.5 bg-[hsl(var(--muted))] border-b border-[hsl(var(--border))]",children:n.jsx("h3",{className:"text-[11px] font-medium uppercase tracking-wider text-[hsl(var(--muted-foreground))]",children:"Scorer Summary"})}),n.jsx("div",{className:"overflow-x-auto",children:n.jsxs("table",{className:"w-full text-xs",children:[n.jsx("thead",{children:n.jsxs("tr",{className:"border-b border-[hsl(var(--border))]",children:[n.jsx("th",{className:"text-left px-4 py-2 font-medium w-48",children:"Metric"}),n.jsx("th",{className:"px-4 py-2 w-28"}),n.jsx("th",{className:"text-right px-3 py-2 font-medium",children:"Mean"}),n.jsx("th",{className:"text-right px-3 py-2 font-medium",children:"P50"}),n.jsx("th",{className:"text-right px-3 py-2 font-medium",children:"P95"}),n.jsx("th",{className:"text-right px-3 py-2 font-medium",children:"Min"}),n.jsx("th",{className:"text-right px-3 py-2 font-medium",children:"Max"})]})}),n.jsxs("tbody",{children:[d.map(([f,m])=>{const{scored:h,failed:x,skipped:p}=FS(m,f,r),v=h>0;return n.jsxs("tr",{className:"border-b border-[hsl(var(--border))] last:border-b-0",children:[n.jsxs("td",{className:"px-4 py-2.5 font-mono text-[hsl(var(--foreground))]",children:[f,(o==null?void 0:o[f])==="llm"&&n.jsx("span",{className:"ml-1.5 px-1 py-0.5 text-[9px] font-medium rounded bg-purple-100 text-purple-600 dark:bg-purple-900/30 dark:text-purple-400 align-middle",title:"LLM scorer — scores may vary between runs",children:"LLM"}),n.jsx(Hf,{failed:x,skipped:p,scored:h})]}),v?n.jsxs(n.Fragment,{children:[n.jsx("td",{className:"px-4 py-2.5",children:n.jsx("div",{className:"h-2 bg-[hsl(var(--secondary))] rounded-full overflow-hidden",children:n.jsx("div",{className:F("h-full rounded-full transition-all",xc(m.mean)),style:{width:`${m.mean*100}%`}})})}),n.jsx("td",{className:F("px-3 py-2.5 text-right font-mono font-medium",Rt(m.mean)),children:m.mean.toFixed(3)}),n.jsx("td",{className:"px-3 py-2.5 text-right font-mono text-[hsl(var(--muted-foreground))]",children:m.p50.toFixed(3)}),n.jsx("td",{className:"px-3 py-2.5 text-right font-mono text-[hsl(var(--muted-foreground))]",children:m.p95.toFixed(3)}),n.jsx("td",{className:"px-3 py-2.5 text-right font-mono text-[hsl(var(--muted-foreground))]",children:m.min.toFixed(3)}),n.jsx("td",{className:"px-3 py-2.5 text-right font-mono text-[hsl(var(--muted-foreground))]",children:m.max.toFixed(3)})]}):n.jsx("td",{colSpan:6,className:"px-3 py-2.5 text-center text-[hsl(var(--muted-foreground))]",children:"No valid scores"})]},f)}),s.timing&&n.jsxs("tr",{className:"border-t border-[hsl(var(--border))]",children:[n.jsx("td",{className:"px-4 py-2.5 font-mono text-[hsl(var(--muted-foreground))]",children:"Timing"}),n.jsx("td",{className:"px-4 py-2.5"}),n.jsx("td",{className:"px-3 py-2.5 text-right font-mono text-[hsl(var(--muted-foreground))]",children:xt(s.timing.mean)}),n.jsx("td",{className:"px-3 py-2.5 text-right font-mono text-[hsl(var(--muted-foreground))]",children:xt(s.timing.p50)}),n.jsx("td",{className:"px-3 py-2.5 text-right font-mono text-[hsl(var(--muted-foreground))]",children:xt(s.timing.p95)}),n.jsx("td",{className:"px-3 py-2.5 text-right font-mono text-[hsl(var(--muted-foreground))]",children:xt(s.timing.min)}),n.jsx("td",{className:"px-3 py-2.5 text-right font-mono text-[hsl(var(--muted-foreground))]",children:xt(s.timing.max)})]})]})]})}),i>0&&n.jsx("div",{className:"px-4 py-2 border-t border-[hsl(var(--border))] bg-[hsl(var(--muted))]/50",children:n.jsxs("span",{className:"text-xs text-[hsl(var(--muted-foreground))]",children:["Total cost: ",n.jsx("span",{className:"font-mono font-medium",children:at(i)})]})})]})}function l5({items:s,scorerNames:r,onSelectItem:i,errorFilter:o,onErrorFilterChange:d,scorerFilter:f,onScorerFilterChange:m,threshold:h,onThresholdChange:x,sortField:p,onSortFieldChange:v,sortDir:y,onSortDirChange:E}){const w=h!==""?parseFloat(h):null,C=o!=="all"||f!==""&&w!=null&&!isNaN(w),_=b.useMemo(()=>s.map((T,j)=>({item:T,index:j})),[s]),R=b.useMemo(()=>{let T=_;return o==="errors"?T=T.filter(({item:j})=>!!j.error):o==="no-errors"&&(T=T.filter(({item:j})=>!j.error)),f&&w!=null&&!isNaN(w)&&(T=T.filter(({item:j})=>{const k=j.scores[f];return k!=null&&k<w})),T},[_,o,f,w]),D=b.useMemo(()=>{const T=[...R],j=y==="asc"?1:-1;return T.sort((k,S)=>{let B,$;return p==="index"?(B=k.index,$=S.index):p==="duration"?(B=k.item.duration??1/0,$=S.item.duration??1/0):p==="cost"?(B=k.item.cost??1/0,$=S.item.cost??1/0):(B=k.item.scores[p]??-1/0,$=S.item.scores[p]??-1/0),(B-$)*j}),T},[R,p,y]),H=[{value:"index",label:"Item #"},{value:"duration",label:"Duration"},{value:"cost",label:"Cost"},...r.map(T=>({value:T,label:T}))];return n.jsxs("div",{children:[n.jsxs("div",{className:"flex items-center justify-between gap-3 mb-3 flex-wrap",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("h3",{className:"text-[11px] font-medium uppercase tracking-wider text-[hsl(var(--muted-foreground))]",children:"All Items"}),n.jsx("span",{className:"text-xs text-[hsl(var(--muted-foreground))] font-mono tabular-nums",children:C?`${R.length} of ${s.length}`:String(s.length)}),C&&n.jsx("button",{onClick:()=>{d("all"),m(""),x("")},className:"text-xs text-[hsl(var(--primary))] hover:underline cursor-pointer",children:"Reset"})]}),n.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[n.jsxs("select",{value:o,onChange:T=>d(T.target.value),className:"px-2 py-1 text-xs rounded-lg border border-[hsl(var(--input))] bg-[hsl(var(--background))]",children:[n.jsx("option",{value:"all",children:"All"}),n.jsx("option",{value:"errors",children:"Errors"}),n.jsx("option",{value:"no-errors",children:"Passed"})]}),r.length>0&&n.jsxs(n.Fragment,{children:[n.jsxs("select",{value:f,onChange:T=>m(T.target.value),className:"px-2 py-1 text-xs rounded-lg border border-[hsl(var(--input))] bg-[hsl(var(--background))]",children:[n.jsx("option",{value:"",children:"Score filter…"}),r.map(T=>n.jsx("option",{value:T,children:T},T))]}),f&&n.jsx("input",{type:"number",step:"0.1",min:"0",max:"1",placeholder:"< threshold",value:h,onChange:T=>x(T.target.value),className:"w-20 px-2 py-1 text-xs rounded-lg border border-[hsl(var(--input))] bg-[hsl(var(--background))]"})]}),n.jsx("div",{className:"w-px h-4 bg-[hsl(var(--border))]"}),n.jsx("select",{value:p,onChange:T=>v(T.target.value),className:"px-2 py-1 text-xs rounded-lg border border-[hsl(var(--input))] bg-[hsl(var(--background))]",children:H.map(T=>n.jsx("option",{value:T.value,children:T.label},T.value))}),n.jsx("button",{onClick:()=>E(y==="asc"?"desc":"asc"),className:"px-2 py-1 text-xs rounded-lg border border-[hsl(var(--input))] hover:bg-[hsl(var(--accent))] transition-colors cursor-pointer",title:y==="asc"?"Ascending":"Descending",children:y==="asc"?"↑":"↓"})]})]}),D.length===0&&C&&n.jsx("p",{className:"text-xs text-[hsl(var(--muted-foreground))] py-6 text-center",children:"No items match the current filters."}),D.length>0&&n.jsx("div",{className:"rounded-xl border border-[hsl(var(--border))] overflow-hidden",children:n.jsx("div",{className:"overflow-x-auto",children:n.jsxs("table",{className:"w-full text-xs",children:[n.jsx("thead",{children:n.jsxs("tr",{className:"bg-[hsl(var(--muted))]",children:[n.jsx("th",{className:"text-left px-3 py-2.5 font-medium w-10",children:"#"}),n.jsx("th",{className:"text-left px-3 py-2.5 font-medium min-w-[180px]",children:"Input"}),r.map(T=>n.jsx("th",{className:"text-right px-2 py-2.5 font-medium font-mono max-w-24 truncate",title:T,children:T},T)),n.jsx("th",{className:"text-right px-3 py-2.5 font-medium w-16",children:"Duration"}),n.jsx("th",{className:"text-right px-3 py-2.5 font-medium w-16",children:"Cost"}),n.jsx("th",{className:"w-8"})]})}),n.jsx("tbody",{children:D.map(({item:T,index:j})=>n.jsxs("tr",{onClick:()=>i(j),className:"border-t border-[hsl(var(--border))] hover:bg-[hsl(var(--accent))] cursor-pointer transition-colors group",children:[n.jsxs("td",{className:"px-3 py-2 font-mono text-[hsl(var(--muted-foreground))]",children:[j+1,T.error&&n.jsx("span",{className:"ml-1 inline-flex items-center text-red-500",title:"Workflow error","aria-label":"Workflow error",children:n.jsx(jg,{size:12})}),!T.error&&T.scorerErrors&&T.scorerErrors.length>0&&n.jsx("span",{className:"ml-1 inline-flex items-center text-amber-500",title:"Scorer errors","aria-label":"Scorer errors",children:n.jsx(kg,{size:12})})]}),n.jsx("td",{className:"px-3 py-2 max-w-xs",children:n.jsx("span",{className:"text-[11px] leading-tight text-[hsl(var(--muted-foreground))] truncate block group-hover:text-[hsl(var(--foreground))] transition-colors",children:xr(T.input)==="[redacted]"?`Item ${j+1}`:xr(T.input)})}),r.map(k=>{var W;const S=T.scores[k],B=(W=T.scoreDetails)==null?void 0:W[k],$=(B==null?void 0:B.skipped)===!0;return n.jsx("td",{className:"text-right px-2 py-2 font-mono",children:S!=null?n.jsx("span",{className:F("font-medium tabular-nums",Rt(S)),children:S.toFixed(2)}):$?n.jsx("span",{className:"text-[10px] text-[hsl(var(--muted-foreground))]",title:"Not applicable (N/A)",children:"N/A"}):n.jsx("span",{className:"text-[hsl(var(--muted-foreground))]",title:(B==null?void 0:B.duration)!=null?"Scorer failed":void 0,children:"—"})},k)}),n.jsx("td",{className:"text-right px-3 py-2 font-mono text-[hsl(var(--muted-foreground))]",children:T.duration!=null?xt(T.duration):"—"}),n.jsx("td",{className:"text-right px-3 py-2 font-mono text-[hsl(var(--muted-foreground))]",children:T.cost!=null&&T.cost>0?at(T.cost):"—"}),n.jsx("td",{className:"px-2 py-2",children:n.jsx(Ba,{size:12,className:"text-[hsl(var(--muted-foreground))] opacity-0 group-hover:opacity-60 transition-opacity"})})]},j))})]})})})]})}const j0=300;function r5({text:s}){const[r,i]=b.useState(!1),o=s.length>j0;return n.jsxs("div",{children:[n.jsx("pre",{className:"text-xs font-mono p-3 rounded-lg bg-[hsl(var(--secondary))] overflow-auto max-h-96 whitespace-pre-wrap leading-relaxed",children:o&&!r?s.slice(0,j0)+"…":s}),o&&n.jsx("button",{onClick:()=>i(!r),className:"text-xs text-[hsl(var(--primary))] hover:underline mt-1.5 cursor-pointer",children:r?"Show less":"Show more"})]})}function qd({label:s,data:r}){return n.jsxs("div",{className:"rounded-xl border border-[hsl(var(--border))] overflow-hidden",children:[n.jsx("div",{className:"px-4 py-2.5 bg-[hsl(var(--muted))]/50 border-b border-[hsl(var(--border))]",children:n.jsx("span",{className:"text-[11px] font-medium uppercase tracking-wider text-[hsl(var(--muted-foreground))]",children:s})}),n.jsx("div",{className:"p-4",children:n.jsx(Ct,{data:r,collapsed:!0})})]})}function i5({traces:s}){const[r,i]=b.useState(!1);return n.jsxs("div",{className:"rounded-xl border border-[hsl(var(--border))] overflow-hidden",children:[n.jsxs("button",{onClick:()=>i(o=>!o),className:"w-full flex items-center gap-2 px-4 py-2.5 bg-[hsl(var(--muted))]/50 border-b border-[hsl(var(--border))] hover:bg-[hsl(var(--muted))] text-left cursor-pointer",children:[n.jsx("span",{className:F("text-[11px]",r?"rotate-0":"rotate-90"),children:"▶"}),n.jsx("span",{className:"text-[11px] font-medium uppercase tracking-wider text-[hsl(var(--muted-foreground))]",children:"Trace"}),n.jsxs("span",{className:"text-[11px] text-[hsl(var(--muted-foreground))] ml-1",children:[s.length," event",s.length!==1?"s":""]})]}),!r&&n.jsx("div",{className:"p-2",children:n.jsx(Di,{events:s})})]})}function o5({item:s,itemIndex:r,scorerNames:i,onBack:o}){const d=s.scorerErrors??[],f=XS(s),m=Zg(s),h=IS(s),x=s.cost??0,p=s.scorerCost??0,v=x+p;return n.jsxs("div",{className:"space-y-5",children:[n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsxs("nav",{className:"flex items-center gap-1.5 text-sm",children:[n.jsx("button",{onClick:o,className:"text-[hsl(var(--muted-foreground))] hover:text-[hsl(var(--foreground))] transition-colors cursor-pointer",children:"Overview"}),n.jsx("span",{className:"text-[hsl(var(--muted-foreground))]",children:"/"}),n.jsxs("span",{className:"font-medium",children:["Item #",r+1]}),s.error&&n.jsx("span",{className:"ml-1 inline-flex items-center px-2 py-0.5 rounded-full text-[10px] font-medium text-red-600 dark:text-red-400 bg-red-50 dark:bg-red-950/30",children:"Error"})]}),n.jsxs("div",{className:"flex items-center gap-2 text-xs text-[hsl(var(--muted-foreground))] font-mono",children:[f.length>0&&f.map(y=>n.jsx("span",{className:"px-1.5 py-0.5 rounded bg-[hsl(var(--secondary))] text-[hsl(var(--foreground))] text-[10px] font-medium",title:y,children:wa(y)},y)),m&&n.jsxs("span",{title:`Input: ${m.input.toLocaleString()} Output: ${m.output.toLocaleString()}${m.reasoning?` Reasoning: ${m.reasoning.toLocaleString()}`:""}`,children:[(m.input+m.output+m.reasoning).toLocaleString()," tok"]}),h>1&&n.jsxs("span",{title:`${h} agent calls for this item`,children:[h," calls"]}),s.duration!=null&&n.jsx("span",{children:xt(s.duration)}),v>0&&n.jsx("span",{children:at(v)})]})]}),i.length>0&&n.jsx("div",{className:"flex flex-wrap items-center gap-x-4 gap-y-2 py-3 px-4 rounded-xl bg-[hsl(var(--muted))]/50",children:i.map(y=>{var C,_;const E=s.scores[y],w=((_=(C=s.scoreDetails)==null?void 0:C[y])==null?void 0:_.skipped)===!0;return n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("span",{className:"text-xs text-[hsl(var(--muted-foreground))]",children:y}),E!=null?n.jsxs("div",{className:"flex items-center gap-1.5",children:[n.jsx("div",{className:"w-12 h-1.5 bg-[hsl(var(--secondary))] rounded-full overflow-hidden",children:n.jsx("div",{className:F("h-full rounded-full",xc(E)),style:{width:`${E*100}%`}})}),n.jsx("span",{className:F("text-xs font-mono font-medium tabular-nums",Rt(E)),children:E.toFixed(2)})]}):w?n.jsx("span",{className:"text-xs text-[hsl(var(--muted-foreground))] font-mono",title:"Not applicable (N/A)",children:"N/A"}):n.jsx("span",{className:"text-xs text-[hsl(var(--muted-foreground))] font-mono",children:"—"})]},y)})}),s.error&&n.jsx("div",{className:"p-3 rounded-xl bg-red-50 dark:bg-red-950/30 border border-red-200 dark:border-red-800 text-red-700 dark:text-red-300 text-xs font-mono",children:s.error}),n.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-3",children:[n.jsx(qd,{label:"Input",data:s.input}),n.jsx(qd,{label:"Output",data:s.output})]}),s.annotations!=null&&n.jsx(qd,{label:"Expected (Annotations)",data:s.annotations}),v>0&&x>0&&p>0&&n.jsxs("div",{className:"flex items-center gap-3 text-xs text-[hsl(var(--muted-foreground))] font-mono",children:[n.jsxs("span",{children:["Workflow: ",at(x)]}),n.jsx("span",{children:"+"}),n.jsxs("span",{children:["Scoring: ",at(p)]}),n.jsx("span",{children:"="}),n.jsx("span",{className:"font-medium text-[hsl(var(--foreground))]",children:at(v)})]}),s.traces&&s.traces.length>0&&n.jsx(i5,{traces:s.traces}),i.length>0&&n.jsxs("div",{className:"space-y-3",children:[n.jsx("h4",{className:"text-[11px] font-medium uppercase tracking-wider text-[hsl(var(--muted-foreground))]",children:"Scorer Results"}),i.map(y=>{var R;const E=s.scores[y],w=(R=s.scoreDetails)==null?void 0:R[y],C=d.find(D=>D.includes(`"${y}"`)),_=(w==null?void 0:w.skipped)===!0;return n.jsxs("div",{className:"rounded-xl border border-[hsl(var(--border))] overflow-hidden",children:[n.jsxs("div",{className:"flex items-center gap-2 px-4 py-2.5 bg-[hsl(var(--muted))]/50",children:[n.jsx("span",{className:"font-mono text-xs font-medium",children:y}),E!=null&&n.jsx("span",{className:F("px-2 py-0.5 rounded-full text-xs font-mono font-medium",uc(E)),children:E.toFixed(3)}),E==null&&_&&n.jsx("span",{className:"px-2 py-0.5 rounded-full text-xs font-mono bg-[hsl(var(--muted))] text-[hsl(var(--muted-foreground))]",title:"Skipped — the scorer's `applies` predicate returned false for this item (excluded from the mean and failure rate)",children:"N/A"}),E==null&&!_&&!C&&n.jsx("span",{className:"px-2 py-0.5 rounded-full text-xs font-mono bg-[hsl(var(--secondary))] text-[hsl(var(--muted-foreground))]",children:"null"}),n.jsxs("div",{className:"ml-auto flex items-center gap-2",children:[(w==null?void 0:w.duration)!=null&&n.jsx("span",{className:"text-xs font-mono text-[hsl(var(--muted-foreground))]",children:xt(w.duration)}),(w==null?void 0:w.cost)!=null&&w.cost>0&&n.jsx("span",{className:"text-xs font-mono text-[hsl(var(--muted-foreground))]",children:at(w.cost)})]})]}),((w==null?void 0:w.metadata)||C||_)&&n.jsxs("div",{className:"px-4 py-3 space-y-2",children:[_&&n.jsxs("p",{className:"text-xs text-[hsl(var(--muted-foreground))]",children:["Not applicable — the scorer’s ",n.jsx("code",{children:"applies"})," predicate returned false for this item, so it was skipped (excluded from the mean and the failure rate)."]}),(w==null?void 0:w.metadata)&&typeof w.metadata.reasoning=="string"&&w.metadata.reasoning.length>0&&n.jsxs("div",{children:[n.jsx("span",{className:"text-[11px] font-medium text-[hsl(var(--muted-foreground))] block mb-1.5 uppercase tracking-wider",children:"Reasoning"}),n.jsx(r5,{text:w.metadata.reasoning})]}),(w==null?void 0:w.metadata)&&(()=>{const D=Object.keys(w.metadata).filter(T=>T!=="reasoning");if(D.length===0)return null;const H={};for(const T of D)H[T]=w.metadata[T];return n.jsxs("div",{children:[n.jsx("span",{className:"text-[11px] font-medium text-[hsl(var(--muted-foreground))] block mb-1.5 uppercase tracking-wider",children:"Metadata"}),n.jsx(Ct,{data:H,collapsed:!0})]})})(),C&&n.jsx("div",{className:"text-xs text-amber-600 dark:text-amber-400 font-mono p-2.5 rounded-lg bg-amber-50 dark:bg-amber-950/30",children:C})]})]},y)})]})]})}function c5(s,r){const i=r.map(o=>s.scores[o]).filter(o=>o!=null);return i.length===0?null:i.reduce((o,d)=>o+d,0)/i.length}function u5({items:s,scorerNames:r,selectedIndex:i,onSelectItem:o,onDeselectItem:d}){const f=b.useMemo(()=>s.map((h,x)=>({item:h,index:x,avg:c5(h,r),label:xr(h.input,60)})),[s,r]),m=s.filter(h=>h.error).length;return n.jsxs("div",{className:"flex flex-col h-full",children:[n.jsx("div",{className:"shrink-0 px-4 py-3 border-b border-[hsl(var(--border))]",children:n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsxs("button",{onClick:d,className:F("text-xs font-medium transition-colors cursor-pointer",i==null?"text-[hsl(var(--foreground))]":"text-[hsl(var(--muted-foreground))] hover:text-[hsl(var(--foreground))]"),children:[s.length," items"]}),m>0?n.jsxs("span",{className:"text-[10px] font-medium text-red-600 dark:text-red-400",children:[m," failed"]}):n.jsx("span",{className:"text-[10px] font-medium text-emerald-600 dark:text-emerald-400",children:"all passed"})]})}),n.jsx("div",{className:"flex-1 overflow-y-auto",children:f.map(({item:h,index:x,avg:p,label:v})=>{const y=i===x;return n.jsxs("button",{onClick:()=>o(x),className:F("w-full text-left px-4 py-2.5 flex items-center gap-3 border-b border-[hsl(var(--border))]/50 transition-colors group cursor-pointer",y?"bg-[hsl(var(--accent))] border-l-2 border-l-[hsl(var(--foreground))]":"hover:bg-[hsl(var(--accent))]/50 border-l-2 border-l-transparent"),children:[n.jsx("span",{className:F("text-[10px] font-mono w-5 shrink-0",y?"text-[hsl(var(--foreground))] font-medium":"text-[hsl(var(--muted-foreground))]"),children:x+1}),n.jsx("span",{className:F("flex-1 text-xs truncate leading-snug",y?"text-[hsl(var(--foreground))]":"text-[hsl(var(--muted-foreground))] group-hover:text-[hsl(var(--foreground))]"),children:v}),h.error&&n.jsx("span",{className:"inline-flex items-center text-red-500 shrink-0",title:"Workflow error","aria-label":"Workflow error",children:n.jsx(jg,{size:11})}),!h.error&&h.scorerErrors&&h.scorerErrors.length>0&&n.jsx("span",{className:"inline-flex items-center text-amber-500 shrink-0",title:"Scorer errors","aria-label":"Scorer errors",children:n.jsx(kg,{size:11})}),p!=null?n.jsx("span",{className:F("text-[11px] font-mono font-medium shrink-0 tabular-nums",Rt(p)),children:p.toFixed(2)}):n.jsx("span",{className:"text-[10px] text-[hsl(var(--muted-foreground))] shrink-0",children:"-"}),n.jsx(Ba,{size:12,className:F("shrink-0 transition-all",y?"text-[hsl(var(--foreground))] opacity-100":"text-[hsl(var(--muted-foreground))] opacity-0 group-hover:opacity-60")})]},x)})})]})}function d5({name:s,scores:r,mean:i,failed:o,skipped:d}){const f=n.jsx(Hf,{failed:o,skipped:d});return r.length===0?n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsx("span",{className:"w-28 text-xs font-mono truncate text-[hsl(var(--muted-foreground))]",title:s,children:s}),n.jsx("span",{className:"text-xs text-[hsl(var(--muted-foreground))]",children:"No valid scores"}),f]}):n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsxs("span",{className:"w-28 text-xs font-mono truncate",title:s,children:[s,f]}),n.jsxs("div",{className:"flex-1 h-5 relative bg-[hsl(var(--secondary))] rounded",children:[[.25,.5,.75].map(m=>n.jsx("div",{className:"absolute top-0 bottom-0 w-px bg-[hsl(var(--border))]",style:{left:`${m*100}%`}},m)),r.map((m,h)=>n.jsx("div",{className:F("absolute w-1 top-[3px] bottom-[3px] rounded-sm",xc(m)),style:{left:`${Math.max(1,Math.min(99,m*100))}%`,transform:"translateX(-50%)",opacity:.45},title:m.toFixed(3)},h)),n.jsx("div",{className:"absolute top-0 bottom-0 w-0.5 bg-[hsl(var(--foreground))]",style:{left:`${i*100}%`,opacity:.3},title:`Mean: ${i.toFixed(3)}`})]}),n.jsx("span",{className:"w-12 text-xs font-mono text-right text-[hsl(var(--muted-foreground))] tabular-nums",children:i.toFixed(3)})]})}function f5({items:s,scorerNames:r}){const i=b.useMemo(()=>r.map(o=>{const{scores:d,failed:f,skipped:m}=Xg(s,o),h=d.length>0?d.reduce((x,p)=>x+p,0)/d.length:0;return{name:o,scores:d,mean:h,failed:f,skipped:m}}),[s,r]);return r.length===0?null:n.jsxs("div",{className:"rounded-xl border border-[hsl(var(--border))] overflow-hidden",children:[n.jsx("div",{className:"px-4 py-2.5 bg-[hsl(var(--muted))] border-b border-[hsl(var(--border))]",children:n.jsx("h3",{className:"text-[11px] font-medium uppercase tracking-wider text-[hsl(var(--muted-foreground))]",children:"Score Distribution"})}),n.jsxs("div",{className:"p-4 space-y-2",children:[n.jsxs("div",{className:"flex items-center gap-3 mb-1",children:[n.jsx("span",{className:"w-28"}),n.jsxs("div",{className:"flex-1 flex justify-between text-[10px] font-mono text-[hsl(var(--muted-foreground))]",children:[n.jsx("span",{children:"0"}),n.jsx("span",{children:"0.25"}),n.jsx("span",{children:"0.5"}),n.jsx("span",{children:"0.75"}),n.jsx("span",{children:"1.0"})]}),n.jsx("span",{className:"w-12"})]}),i.map(o=>n.jsx(d5,{name:o.name,scores:o.scores,mean:o.mean,failed:o.failed,skipped:o.skipped},o.name))]})]})}function ec({field:s,current:r,dir:i,onSort:o,align:d,className:f,children:m}){const h=r===s;return n.jsxs("th",{className:F(d==="right"?"text-right":"text-left","px-3 py-2 font-medium cursor-pointer select-none hover:text-[hsl(var(--foreground))]",f,d==="left"&&"px-4"),onClick:()=>o(s),children:[m,h&&n.jsx("span",{className:"ml-0.5",children:i==="desc"?"▼":"▲"})]})}function h5({baseline:s,candidate:r,scorerNames:i,baselineRuns:o,candidateRuns:d,scorerTypes:f}){const[m,h]=b.useState(i[0]??""),[x,p]=b.useState("delta"),[v,y]=b.useState("desc"),[E,w]=b.useState(!1),C=o&&o.length>1||d&&d.length>1,_=(o==null?void 0:o.length)??1,R=(d==null?void 0:d.length)??1,[D,H]=b.useState(null),T=S=>{x===S?y(B=>B==="desc"?"asc":"desc"):(p(S),y(S==="index"?"asc":"desc"))},j=Math.min(s.items.length,r.items.length),k=b.useMemo(()=>{var $,W,K,te,re,Me,he,ae;const S=[],B=Math.min((o==null?void 0:o.length)??0,(d==null?void 0:d.length)??0);for(let z=0;z<j;z++){const L=s.items[z].scores[m]??null,ie=r.items[z].scores[m]??null,ve=($=s.items[z].scoreDetails)==null?void 0:$[m],ge=(W=r.items[z].scoreDetails)==null?void 0:W[m],M=(ve==null?void 0:ve.skipped)===!0,Q=(ge==null?void 0:ge.skipped)===!0,G=L==null&&!M&&(ve==null?void 0:ve.duration)!=null,J=ie==null&&!Q&&(ge==null?void 0:ge.duration)!=null,oe=M||Q,me=!oe&&L!=null&&ie!=null?ie-L:0;let be;if(B>1){be=[];for(let X=0;X<B;X++){const ne=(K=o[X])==null?void 0:K.items[z],ce=(te=d[X])==null?void 0:te.items[z],we=ne==null?void 0:ne.scores[m],Re=ce==null?void 0:ce.scores[m];!(((Me=(re=ne==null?void 0:ne.scoreDetails)==null?void 0:re[m])==null?void 0:Me.skipped)===!0||((ae=(he=ce==null?void 0:ce.scoreDetails)==null?void 0:he[m])==null?void 0:ae.skipped)===!0)&&we!=null&&Re!=null&&be.push(Re-we)}}S.push({index:z,input:s.items[z].input,baselineScore:L,candidateScore:ie,delta:me,baselineSkipped:M,candidateSkipped:Q,baselineFailed:G,candidateFailed:J,nonComparable:oe,runDeltas:be})}return S.sort((z,L)=>{let ie,ve;switch(x){case"index":ie=z.index,ve=L.index;break;case"baseline":ie=z.baselineScore??-1,ve=L.baselineScore??-1;break;case"candidate":ie=z.candidateScore??-1,ve=L.candidateScore??-1;break;case"delta":default:ie=Math.abs(z.delta),ve=Math.abs(L.delta);break}return v==="desc"?ve-ie:ie-ve}),S},[s,r,m,x,v,j,o,d]);return i.length===0||j===0?null:n.jsxs("div",{className:"border border-[hsl(var(--border))] rounded-xl overflow-hidden",children:[n.jsxs("button",{onClick:()=>w(S=>!S),className:"w-full flex items-center gap-2 px-4 py-2.5 bg-[hsl(var(--muted))] border-b border-[hsl(var(--border))] hover:bg-[hsl(var(--accent))] transition-colors cursor-pointer",children:[E?n.jsx(Ba,{className:"h-3.5 w-3.5 text-[hsl(var(--muted-foreground))]"}):n.jsx(Bn,{className:"h-3.5 w-3.5 text-[hsl(var(--muted-foreground))]"}),n.jsxs("h3",{className:"text-xs font-medium uppercase tracking-wider text-[hsl(var(--muted-foreground))]",children:["All Items (",j,")",C&&n.jsxs("span",{className:"normal-case tracking-normal font-normal ml-1.5 opacity-70",children:["—"," scores averaged across"," ",_===R?`${_} runs`:`${_} / ${R} runs`]})]})]}),!E&&n.jsxs("div",{children:[n.jsx("div",{className:"flex items-center gap-1.5 px-4 py-2 border-b border-[hsl(var(--border))] bg-[hsl(var(--card))] flex-wrap",children:i.map(S=>n.jsxs("button",{onClick:()=>h(S),className:F("px-2 py-1 text-[11px] font-mono rounded-md transition-colors cursor-pointer",m===S?"bg-[hsl(var(--foreground))] text-[hsl(var(--background))] font-medium":"bg-[hsl(var(--secondary))] text-[hsl(var(--muted-foreground))] hover:bg-[hsl(var(--accent))] hover:text-[hsl(var(--foreground))]"),children:[S,(f==null?void 0:f[S])==="llm"&&n.jsx("span",{className:"ml-1 text-[8px] opacity-70",children:"LLM"})]},S))}),n.jsx("div",{className:"overflow-x-auto",children:n.jsxs("table",{className:"w-full text-xs",children:[n.jsx("thead",{children:n.jsxs("tr",{className:"border-b border-[hsl(var(--border))]",children:[n.jsx(ec,{field:"index",current:x,dir:v,onSort:T,align:"left",className:"w-10",children:"#"}),n.jsx("th",{className:"text-left px-3 py-2 font-medium",children:"Input"}),n.jsxs(ec,{field:"baseline",current:x,dir:v,onSort:T,align:"right",children:["Baseline",C&&_>1&&n.jsxs("span",{className:"font-normal opacity-60 ml-0.5",children:["(",_,")"]})]}),n.jsxs(ec,{field:"candidate",current:x,dir:v,onSort:T,align:"right",children:["Candidate",C&&R>1&&n.jsxs("span",{className:"font-normal opacity-60 ml-0.5",children:["(",R,")"]})]}),n.jsx(ec,{field:"delta",current:x,dir:v,onSort:T,align:"right",children:"Delta"})]})}),n.jsx("tbody",{children:k.map(S=>{const B=D===S.index,$=S.delta>0?"text-emerald-600 dark:text-emerald-400":S.delta<0?"text-red-600 dark:text-red-400":"text-[hsl(var(--muted-foreground))]";return n.jsxs("tr",{className:F("border-b border-[hsl(var(--border))] last:border-b-0 cursor-pointer hover:bg-[hsl(var(--accent))] transition-colors",B&&"bg-[hsl(var(--accent))]"),children:[n.jsx("td",{className:"px-4 py-2.5 font-mono text-[hsl(var(--muted-foreground))]",onClick:()=>H(B?null:S.index),children:S.index+1}),n.jsx("td",{className:"px-3 py-2.5 max-w-xs truncate",onClick:()=>H(B?null:S.index),children:xr(S.input)}),n.jsx("td",{className:F("px-3 py-2.5 text-right font-mono",S.baselineScore!=null?Rt(S.baselineScore):"text-[hsl(var(--muted-foreground))]"),onClick:()=>H(B?null:S.index),children:S.baselineScore!=null?S.baselineScore.toFixed(3):S.baselineSkipped?n.jsx("span",{title:"Not applicable (N/A)",children:"N/A"}):n.jsx("span",{title:S.baselineFailed?"Scorer failed":void 0,children:"—"})}),n.jsx("td",{className:F("px-3 py-2.5 text-right font-mono",S.candidateScore!=null?Rt(S.candidateScore):"text-[hsl(var(--muted-foreground))]"),onClick:()=>H(B?null:S.index),children:S.candidateScore!=null?S.candidateScore.toFixed(3):S.candidateSkipped?n.jsx("span",{title:"Not applicable (N/A)",children:"N/A"}):n.jsx("span",{title:S.candidateFailed?"Scorer failed":void 0,children:"—"})}),n.jsxs("td",{className:F("px-3 py-2.5 text-right",S.nonComparable?"text-[hsl(var(--muted-foreground))]":$),onClick:()=>H(B?null:S.index),children:[n.jsx("div",{className:"font-mono",children:S.nonComparable?n.jsx("span",{title:"Not comparable — a side was skipped (N/A) for this scorer",children:"N/A"}):S.delta!==0?`${S.delta>0?"+":""}${S.delta.toFixed(3)}`:"—"}),S.runDeltas&&S.runDeltas.length>1&&n.jsxs("div",{className:"flex items-center justify-end gap-0.5 mt-1",title:S.runDeltas.map((W,K)=>`Run ${K+1}: ${W>=0?"+":""}${W.toFixed(3)}`).join(", "),children:[S.runDeltas.map((W,K)=>n.jsx("div",{className:F("w-1.5 h-1.5 rounded-full",W<0?"bg-red-500 dark:bg-red-400":W>0?"bg-emerald-500 dark:bg-emerald-400":"bg-[hsl(var(--muted-foreground))]")},K)),n.jsxs("span",{className:"text-[9px] text-[hsl(var(--muted-foreground))] ml-0.5",children:[S.runDeltas.filter(W=>S.delta<0?W<0:W>0).length,"/",S.runDeltas.length]})]})]})]},S.index)})})]})}),D!=null&&D<s.items.length&&D<r.items.length&&n.jsx(Jg,{baselineItem:s.items[D],candidateItem:r.items[D],scorer:m,baselineRunItems:o==null?void 0:o.map(S=>S.items[D]).filter(Boolean),candidateRunItems:d==null?void 0:d.map(S=>S.items[D]).filter(Boolean)})]})]})}function m5({stats:s}){const r=s.n,i=s.baselineScored,o=s.candidateScored,d=s.baselineSkipped??0,f=s.candidateSkipped??0,m=s.baselineFailed??0,h=s.candidateFailed??0;if(!(r!=null&&i!=null&&o!=null&&(d+f+m+h>0||r<Math.min(i,o))))return null;const p=(v,y,E)=>`${v} scored${y>0?`, ${y} N/A`:""}${E>0?`, ${E} failed`:""}`;return n.jsxs("div",{className:"font-mono text-[10px] text-[hsl(var(--muted-foreground))] mt-0.5 underline decoration-dotted underline-offset-2 cursor-help",title:`Delta compares per-side means — baseline over ${p(i,d,m)}; candidate over ${p(o,f,h)}. The CI / significance use the ${r} item(s) scored on BOTH sides, so the delta and CI rest on different samples here.`,children:["paired n=",r," · per-side ",i,"/",o]})}function p5({text:s,children:r}){return n.jsxs("span",{className:"relative group/tip cursor-help",children:[r,n.jsx("span",{className:"invisible group-hover/tip:visible absolute bottom-full left-1/2 -translate-x-1/2 mb-1.5 px-2.5 py-1.5 text-[10px] leading-snug rounded-md bg-[hsl(var(--foreground))] text-[hsl(var(--background))] whitespace-normal w-56 z-50 shadow-md pointer-events-none",children:s})]})}function N0({value:s,percent:r,invert:i,format:o}){const d=i?s<0:s>0,f=i?s>0:s<0,m=d?"text-emerald-600 dark:text-emerald-400":f?"text-red-600 dark:text-red-400":"text-[hsl(var(--muted-foreground))]",h=o?`${s>0?"+":s<0?"-":""}${o(Math.abs(s))}`:`${s>0?"+":""}${Math.abs(s)<100?s.toFixed(3):s.toFixed(0)}`,x=`${r>0?"+":""}${r.toFixed(1)}%`;return n.jsx("td",{className:F("px-3 py-2.5 text-right",m),children:n.jsxs("div",{className:"font-mono",children:[h," (",x,")"]})})}function S0(s){return(s>=0?"+":"")+s.toFixed(4)}function x5({compareResult:s,baseline:r,candidate:i,isGroupComparison:o,baselineRuns:d,candidateRuns:f}){var L,ie,ve,ge,M,Q;const[m,h]=b.useState(null),[x,p]=b.useState("delta"),[v,y]=b.useState("desc"),[E,w]=b.useState({}),C=(G,J)=>{(m==null?void 0:m.type)===G&&(m==null?void 0:m.index)===J?h(null):h({type:G,index:J})},_=((L=r==null?void 0:r.metadata)==null?void 0:L.scorerTypes)??((ie=i==null?void 0:i.metadata)==null?void 0:ie.scorerTypes),R=(d==null?void 0:d.length)??1,D=(f==null?void 0:f.length)??1,H=o?`averaged across ${R===D?`${R} runs`:`${R} / ${D} runs`}`:null,T=(ve=s.baseline)==null?void 0:ve.partial,j=(ge=s.candidate)==null?void 0:ge.partial,k=(M=s.baseline)==null?void 0:M.runCount,S=(Q=s.candidate)==null?void 0:Q.runCount,B=k!=null&&d!=null&&k<d.length,$=S!=null&&f!=null&&S<f.length,W=B||$,K=b.useMemo(()=>{const G=Object.entries(s.scorers);return G.sort((J,oe)=>{if(x==="delta"){const X=J[1].significant===!0?1:0,ne=oe[1].significant===!0?1:0;if(X!==ne)return ne-X}let me,be;switch(x){case"metric":return v==="asc"?J[0].localeCompare(oe[0]):oe[0].localeCompare(J[0]);case"baseline":me=J[1].baselineMean,be=oe[1].baselineMean;break;case"candidate":me=J[1].candidateMean,be=oe[1].candidateMean;break;case"delta":default:me=Math.abs(J[1].delta),be=Math.abs(oe[1].delta);break}return v==="desc"?be-me:me-be}),G},[s.scorers,x,v]),te=K.some(([,G])=>G.ci!=null),re=G=>{x===G?y(J=>J==="desc"?"asc":"desc"):(p(G),y("desc"))},Me=G=>x===G?v==="desc"?" ▼":" ▲":"",he=K.filter(([,G])=>G.significant===!0).length,ae=s.regressions.length,z=s.improvements.length;return n.jsxs("div",{className:"space-y-6",children:[(T||j)&&n.jsx("div",{className:"flex items-start gap-2.5 px-4 py-3 rounded-xl border border-amber-300/60 dark:border-amber-500/40 bg-amber-50 dark:bg-amber-950/40",role:"status",children:n.jsxs("div",{className:"text-sm text-amber-900 dark:text-amber-200",children:[n.jsx("div",{className:"font-medium",children:"Partial batch in this comparison."}),n.jsxs("ul",{className:"mt-1 space-y-0.5 text-amber-800/90 dark:text-amber-300/90 list-disc list-inside",children:[T&&n.jsxs("li",{children:["Baseline pooled ",T.completed," of an attempted"," ",T.attempted," runs."]}),j&&n.jsxs("li",{children:["Candidate pooled ",j.completed," of an attempted"," ",j.attempted," runs."]})]}),n.jsx("div",{className:"mt-1 text-amber-800/80 dark:text-amber-300/80",children:"Statistics below are computed honestly for the included runs."})]})}),W&&n.jsx("div",{className:"flex items-start gap-2.5 px-4 py-3 rounded-xl border border-blue-300/60 dark:border-blue-500/40 bg-blue-50 dark:bg-blue-950/40",role:"status",children:n.jsxs("div",{className:"text-sm text-blue-900 dark:text-blue-200",children:[n.jsxs("div",{className:"font-medium",children:["Comparing ",k," baseline vs ",S," candidate run",S===1?"":"s","."]}),n.jsxs("div",{className:"mt-1 text-blue-800/90 dark:text-blue-300/90",children:["You pooled ",(d==null?void 0:d.length)??1," baseline and ",(f==null?void 0:f.length)??1," ","candidate run",((f==null?void 0:f.length)??1)===1?"":"s","; the comparison uses the first ",Math.min(k??0,S??0)," from each side so the displayed means and paired bootstrap CI are computed over the same sample. Re-pool symmetrically if you want every selected run included."]})]})}),K.length>0&&(()=>{const G=K.some(([,X])=>X.significant===!0&&X.delta<0),J=K.some(([,X])=>X.significant===!0&&X.delta>0),oe=s.regressions.length>0,me=K.every(([,X])=>X.significant===!1),be=(X,ne)=>{const ce=ne.delta<0?ne.pRegression!=null?`${Math.round(ne.pRegression*100)}%`:null:ne.pImprovement!=null?`${Math.round(ne.pImprovement*100)}%`:null,we=`${ne.delta>0?"+":""}${ne.delta.toFixed(3)}`;return`${X} ${we}${ce?` (${ce} probability)`:""}`};if(G){const X=K.filter(([,ne])=>ne.significant===!0&&ne.delta<0);return n.jsxs("div",{className:"flex items-start gap-2.5 px-4 py-3 rounded-xl border border-red-200 dark:border-red-900 bg-red-50 dark:bg-red-950/30",children:[n.jsx("div",{className:"h-6 w-6 rounded-full bg-red-100 dark:bg-red-900/50 flex items-center justify-center shrink-0 mt-0.5",children:n.jsx("span",{className:"text-red-600 dark:text-red-400 text-xs font-bold",children:"✕"})}),n.jsxs("div",{children:[n.jsx("p",{className:"text-sm font-medium text-red-800 dark:text-red-200",children:"Significant regression detected"}),n.jsx("p",{className:"text-xs text-red-600 dark:text-red-400 mt-0.5",children:X.map(([ne,ce])=>be(ne,ce)).join("; ")})]})]})}if(J){const X=K.filter(([,ne])=>ne.significant===!0&&ne.delta>0);return n.jsxs("div",{className:"flex items-start gap-2.5 px-4 py-3 rounded-xl border border-emerald-200 dark:border-emerald-900 bg-emerald-50 dark:bg-emerald-950/30",children:[n.jsx("div",{className:"h-6 w-6 rounded-full bg-emerald-100 dark:bg-emerald-900/50 flex items-center justify-center shrink-0 mt-0.5",children:n.jsx("span",{className:"text-emerald-600 dark:text-emerald-400 text-xs font-bold",children:"✓"})}),n.jsxs("div",{children:[n.jsx("p",{className:"text-sm font-medium text-emerald-800 dark:text-emerald-200",children:"Significant improvement detected"}),n.jsx("p",{className:"text-xs text-emerald-600 dark:text-emerald-400 mt-0.5",children:X.map(([ne,ce])=>be(ne,ce)).join("; ")})]})]})}return oe&&me?n.jsxs("div",{className:"flex items-center gap-2.5 px-4 py-3 rounded-xl border border-amber-200 dark:border-amber-900 bg-amber-50 dark:bg-amber-950/30",children:[n.jsx("div",{className:"h-6 w-6 rounded-full bg-amber-100 dark:bg-amber-900/50 flex items-center justify-center shrink-0",children:n.jsx("span",{className:"text-amber-600 dark:text-amber-400 text-xs font-bold",children:"~"})}),n.jsxs("div",{children:[n.jsxs("p",{className:"text-sm font-medium text-amber-800 dark:text-amber-200",children:[s.regressions.length," item regressions, but not statistically significant"]}),n.jsx("p",{className:"text-xs text-amber-600 dark:text-amber-400",children:o?"Even with pooled multi-run data, the score differences are within normal variation.":"Score differences are within normal LLM variation. Consider multi-run for stronger confidence."})]})]}):n.jsxs("div",{className:"flex items-center gap-2.5 px-4 py-3 rounded-xl border border-[hsl(var(--border))] bg-[hsl(var(--muted))]",children:[n.jsx("div",{className:"h-6 w-6 rounded-full bg-emerald-100 dark:bg-emerald-900/50 flex items-center justify-center shrink-0",children:n.jsx("span",{className:"text-emerald-600 dark:text-emerald-400 text-xs font-bold",children:"✓"})}),n.jsxs("div",{children:[n.jsx("p",{className:"text-sm font-medium",children:"No significant changes"}),n.jsx("p",{className:"text-xs text-[hsl(var(--muted-foreground))]",children:"Scores are stable between baseline and candidate"})]})]})})(),(()=>{const G=($e,Ja)=>{const dn=Ja&&Ja.length>0?Ja:$e?[$e]:[],Ia=new Set;for(const fn of dn)for(const Ea of $n(fn))Ia.add(Ea);return[...Ia]},J=d&&d.length>0?d:r?[r]:[],oe=f&&f.length>0?f:i?[i]:[],me=($e,Ja)=>{const dn=Ja&&Ja.length>0?Ja:$e?[$e]:[],Ia=new Set,fn=[];for(const Ea of dn)for(const Nt of tr(Ea))Ia.has(Nt)||(Ia.add(Nt),fn.push(Nt));return fn},be=G(r,d),X=G(i,f),ne=me(r,d),ce=me(i,f),we=x0(J),Re=x0(oe),dt=we.input+we.output+we.reasoning,yt=Re.input+Re.output+Re.reasoning,pe=g0(J),Te=g0(oe),Ie=ne.length>0||ce.length>0,ye=new Set(ne),Je=new Set(ce),jt=ye.size!==Je.size||ne.some($e=>!Je.has($e)),Dt=be.length>0||X.length>0,Ca=dt>0&&yt>0,zt=pe>0||Te>0;if(!Ie&&!Dt&&!Ca&&!zt)return null;const Be=new Set(be),fa=new Set(X),$a=Be.size!==fa.size||be.some($e=>!fa.has($e)),ha=dt>0?(yt-dt)/dt*100:0;return n.jsxs("div",{className:"flex items-center gap-3 px-4 py-2.5 rounded-lg bg-[hsl(var(--muted))]/50 text-xs flex-wrap",children:[Ie&&n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"text-[hsl(var(--muted-foreground))] uppercase tracking-wider text-[10px] font-medium shrink-0",children:ne.length>1||ce.length>1?"Workflows":"Workflow"}),n.jsx("div",{className:"flex items-center gap-1.5",children:ne.length>0?ne.map($e=>n.jsx("span",{className:"px-1.5 py-0.5 rounded border border-[hsl(var(--border))] bg-[hsl(var(--background))] font-mono",title:$e,children:$e},$e)):n.jsx("span",{className:"text-[hsl(var(--muted-foreground))] italic",children:"unknown"})}),n.jsx("span",{className:"text-[hsl(var(--muted-foreground))]",children:"→"}),n.jsx("div",{className:"flex items-center gap-1.5",children:ce.length>0?ce.map($e=>n.jsx("span",{className:F("px-1.5 py-0.5 rounded font-mono",jt?"bg-blue-100 dark:bg-blue-900/30 text-blue-700 dark:text-blue-300":"border border-[hsl(var(--border))] bg-[hsl(var(--background))]"),title:$e,children:$e},$e)):n.jsx("span",{className:"text-[hsl(var(--muted-foreground))] italic",children:"unknown"})}),jt&&n.jsx("span",{className:"text-[10px] font-medium text-blue-600 dark:text-blue-400",children:"changed"})]}),Dt&&n.jsxs(n.Fragment,{children:[Ie&&n.jsx("span",{className:"text-[hsl(var(--border))]",children:"|"}),n.jsx("span",{className:"text-[hsl(var(--muted-foreground))] uppercase tracking-wider text-[10px] font-medium shrink-0",children:"Models"}),n.jsx("div",{className:"flex items-center gap-1.5",children:be.length>0?be.map($e=>n.jsx("span",{className:"px-1.5 py-0.5 rounded border border-[hsl(var(--border))] bg-[hsl(var(--background))] font-mono",title:$e,children:wa($e)},$e)):n.jsx("span",{className:"text-[hsl(var(--muted-foreground))] italic",children:"unknown"})}),n.jsx("span",{className:"text-[hsl(var(--muted-foreground))]",children:"→"}),n.jsx("div",{className:"flex items-center gap-1.5",children:X.length>0?X.map($e=>n.jsx("span",{className:F("px-1.5 py-0.5 rounded font-mono",$a?"bg-blue-100 dark:bg-blue-900/30 text-blue-700 dark:text-blue-300":"border border-[hsl(var(--border))] bg-[hsl(var(--background))]"),title:$e,children:wa($e)},$e)):n.jsx("span",{className:"text-[hsl(var(--muted-foreground))] italic",children:"unknown"})}),$a&&n.jsx("span",{className:"text-[10px] font-medium text-blue-600 dark:text-blue-400",children:"changed"})]}),Ca&&n.jsxs(n.Fragment,{children:[Dt&&n.jsx("span",{className:"text-[hsl(var(--border))]",children:"|"}),n.jsx("span",{className:"text-[hsl(var(--muted-foreground))] uppercase tracking-wider text-[10px] font-medium shrink-0",children:"Tokens"}),n.jsx("span",{className:"font-mono",children:dt.toLocaleString()}),n.jsx("span",{className:"text-[hsl(var(--muted-foreground))]",children:"→"}),n.jsx("span",{className:"font-mono",children:yt.toLocaleString()}),Math.abs(ha)>=1&&n.jsxs("span",{className:F("text-[10px] font-medium",ha>0?"text-red-600 dark:text-red-400":"text-emerald-600 dark:text-emerald-400"),children:[ha>0?"+":"",ha.toFixed(0),"%"]})]}),zt&&n.jsxs(n.Fragment,{children:[(Dt||Ca)&&n.jsx("span",{className:"text-[hsl(var(--border))]",children:"|"}),n.jsx("span",{className:"text-[hsl(var(--muted-foreground))] uppercase tracking-wider text-[10px] font-medium shrink-0",children:"Cost"}),n.jsx("span",{className:"font-mono",children:at(pe)}),n.jsx("span",{className:"text-[hsl(var(--muted-foreground))]",children:"→"}),n.jsx("span",{className:"font-mono",children:at(Te)}),pe>0&&Te>0&&(()=>{const $e=(Te-pe)/pe*100;return Math.abs($e)>=1?n.jsxs("span",{className:F("text-[10px] font-medium",$e>0?"text-red-600 dark:text-red-400":"text-emerald-600 dark:text-emerald-400"),children:[$e>0?"+":"",$e.toFixed(0),"%"]}):null})()]})]})})(),n.jsxs("div",{className:"grid grid-cols-4 gap-3",children:[n.jsxs("div",{className:"px-3 py-2 rounded-lg border border-[hsl(var(--border))] bg-[hsl(var(--card))]",children:[n.jsx("div",{className:"text-[10px] uppercase tracking-wider text-[hsl(var(--muted-foreground))]",children:"Significant"}),n.jsx("div",{className:"text-lg font-semibold mt-0.5",children:he})]}),n.jsxs("div",{className:"px-3 py-2 rounded-lg border border-[hsl(var(--border))] bg-[hsl(var(--card))]",children:[n.jsx("div",{className:"text-[10px] uppercase tracking-wider text-[hsl(var(--muted-foreground))]",children:"Regressions"}),n.jsx("div",{className:F("text-lg font-semibold mt-0.5",ae>0?"text-red-600 dark:text-red-400":""),children:ae})]}),n.jsxs("div",{className:"px-3 py-2 rounded-lg border border-[hsl(var(--border))] bg-[hsl(var(--card))]",children:[n.jsx("div",{className:"text-[10px] uppercase tracking-wider text-[hsl(var(--muted-foreground))]",children:"Improvements"}),n.jsx("div",{className:F("text-lg font-semibold mt-0.5",z>0?"text-emerald-600 dark:text-emerald-400":""),children:z})]}),s.cost&&n.jsxs("div",{className:"px-3 py-2 rounded-lg border border-[hsl(var(--border))] bg-[hsl(var(--card))]",children:[n.jsx("div",{className:"text-[10px] uppercase tracking-wider text-[hsl(var(--muted-foreground))]",children:"Cost Delta"}),n.jsxs("div",{className:F("text-lg font-semibold mt-0.5",s.cost.delta>0?"text-red-600 dark:text-red-400":s.cost.delta<0?"text-emerald-600 dark:text-emerald-400":""),children:[s.cost.delta>0?"+":"",at(Math.abs(s.cost.delta))]})]})]}),K.length>0&&n.jsxs("div",{className:"border border-[hsl(var(--border))] rounded-xl overflow-hidden",children:[n.jsx("div",{className:"px-4 py-2.5 bg-[hsl(var(--muted))] border-b border-[hsl(var(--border))]",children:n.jsxs("h3",{className:"text-xs font-medium uppercase tracking-wider text-[hsl(var(--muted-foreground))]",children:["Scorer Comparison",H&&n.jsxs("span",{className:"normal-case tracking-normal font-normal ml-1.5 opacity-70",children:["—"," ",H]})]})}),n.jsx("div",{className:"overflow-x-auto",children:n.jsxs("table",{className:"w-full text-xs",children:[n.jsx("thead",{children:n.jsxs("tr",{className:"border-b border-[hsl(var(--border))]",children:[n.jsxs("th",{className:"text-left px-4 py-2 font-medium cursor-pointer select-none hover:text-[hsl(var(--foreground))]",onClick:()=>re("metric"),children:["Metric",Me("metric")]}),n.jsxs("th",{className:"text-right px-3 py-2 font-medium cursor-pointer select-none hover:text-[hsl(var(--foreground))]",onClick:()=>re("baseline"),children:["Baseline",o&&R>1&&n.jsxs("span",{className:"font-normal opacity-60 ml-0.5",children:["(",R,")"]}),T&&n.jsxs("span",{className:"font-normal ml-1 px-1 py-0.5 rounded text-[9px] uppercase tracking-wide bg-amber-100 text-amber-900 dark:bg-amber-950/60 dark:text-amber-200",title:`Partial batch — ${T.completed} of ${T.attempted} runs included`,children:[T.completed,"/",T.attempted]}),Me("baseline")]}),n.jsxs("th",{className:"text-right px-3 py-2 font-medium cursor-pointer select-none hover:text-[hsl(var(--foreground))]",onClick:()=>re("candidate"),children:["Candidate",o&&D>1&&n.jsxs("span",{className:"font-normal opacity-60 ml-0.5",children:["(",D,")"]}),j&&n.jsxs("span",{className:"font-normal ml-1 px-1 py-0.5 rounded text-[9px] uppercase tracking-wide bg-amber-100 text-amber-900 dark:bg-amber-950/60 dark:text-amber-200",title:`Partial batch — ${j.completed} of ${j.attempted} runs included`,children:[j.completed,"/",j.attempted]}),Me("candidate")]}),n.jsx("th",{className:"text-right px-3 py-2 font-medium cursor-pointer select-none hover:text-[hsl(var(--foreground))]",onClick:()=>re("delta"),children:te?n.jsxs(p5,{text:"Score delta with 95% confidence interval via paired bootstrap. If the CI excludes zero and the effect exceeds the practical threshold, the difference is significant (shown with a colored left border). The Baseline and Candidate columns are per-side means (each over that side's own scored items); the CI is paired over items scored on BOTH sides. A per-row 'paired n' note appears when the two samples diverge — different skips (N/A) or failures per side.",children:["Delta",Me("delta")]}):n.jsxs(n.Fragment,{children:["Delta",Me("delta")]})})]})}),n.jsxs("tbody",{children:[K.map(([G,J])=>{const oe=J.delta>0?"+":(J.delta<0,""),me=J.delta>0?"text-emerald-600 dark:text-emerald-400":J.delta<0?"text-red-600 dark:text-red-400":"text-[hsl(var(--muted-foreground))]";return n.jsxs("tr",{className:F("border-b border-[hsl(var(--border))] last:border-b-0",J.significant===!0&&J.delta<0&&"border-l-[3px] border-l-red-500",J.significant===!0&&J.delta>0&&"border-l-[3px] border-l-emerald-500"),children:[n.jsxs("td",{className:"px-4 py-2.5 font-mono",children:[G,(_==null?void 0:_[G])==="llm"&&n.jsx("span",{className:"ml-1.5 px-1 py-0.5 text-[9px] font-medium rounded bg-purple-100 text-purple-600 dark:bg-purple-900/30 dark:text-purple-400 align-middle",title:"LLM scorer — scores may vary between runs",children:"LLM"})]}),n.jsx("td",{className:F("px-3 py-2.5 text-right font-mono",J.baselineScored===0?"text-[hsl(var(--muted-foreground))]":Rt(J.baselineMean)),children:J.baselineMean.toFixed(3)}),n.jsx("td",{className:F("px-3 py-2.5 text-right font-mono",J.candidateScored===0?"text-[hsl(var(--muted-foreground))]":Rt(J.candidateMean)),children:J.candidateMean.toFixed(3)}),n.jsxs("td",{className:"px-3 py-2.5 text-right",children:[n.jsxs("div",{className:F("font-mono",me),children:[oe,Math.abs(J.delta).toFixed(3)," (",oe,Math.abs(J.deltaPercent).toFixed(1),"%)"]}),J.ci&&n.jsxs("div",{className:"font-mono text-[10px] text-[hsl(var(--muted-foreground))] mt-0.5",children:["CI [",S0(J.ci.lower),", ",S0(J.ci.upper),"]"]}),J.pRegression!=null&&J.pImprovement!=null&&(()=>{const be=J.pRegression??0,X=J.pImprovement??0;if(be===0&&X===0)return null;let ne,ce,we;if(be>X)ce=be,ne="regression",we=Math.round(ce*100)>=95?"text-red-600 dark:text-red-400":"text-[hsl(var(--muted-foreground))]";else if(X>be)ce=X,ne="improvement",we=Math.round(ce*100)>=95?"text-emerald-600 dark:text-emerald-400":"text-[hsl(var(--muted-foreground))]";else return null;const Re=Math.round(ce*100);return n.jsxs("div",{className:F("text-[10px] mt-0.5",we),children:[Re,"% probability of ",ne,J.n!=null&&n.jsxs("span",{className:"opacity-60 ml-1",children:["(n=",J.n,")"]})]})})(),n.jsx(m5,{stats:J})]})]},G)}),s.timing&&n.jsxs("tr",{className:"border-t-2 border-[hsl(var(--border))]",children:[n.jsx("td",{className:"px-4 py-2.5 font-mono text-[hsl(var(--muted-foreground))]",children:"Timing (mean)"}),n.jsx("td",{className:"px-3 py-2.5 text-right font-mono text-[hsl(var(--muted-foreground))]",children:xt(s.timing.baselineMean)}),n.jsx("td",{className:"px-3 py-2.5 text-right font-mono text-[hsl(var(--muted-foreground))]",children:xt(s.timing.candidateMean)}),n.jsx(N0,{value:s.timing.delta,percent:s.timing.deltaPercent,invert:!0,format:xt})]}),s.cost!=null&&n.jsxs("tr",{className:"border-t border-[hsl(var(--border))]",children:[n.jsx("td",{className:"px-4 py-2.5 font-mono text-[hsl(var(--muted-foreground))]",children:"Cost (total)"}),n.jsx("td",{className:"px-3 py-2.5 text-right font-mono text-[hsl(var(--muted-foreground))]",children:at(s.cost.baselineTotal)}),n.jsx("td",{className:"px-3 py-2.5 text-right font-mono text-[hsl(var(--muted-foreground))]",children:at(s.cost.candidateTotal)}),n.jsx(N0,{value:s.cost.delta,percent:s.cost.deltaPercent,invert:!0,format:at})]})]})]})})]}),[{type:"regression",items:s.regressions,borderColor:"border-red-200 dark:border-red-900",bgColor:"bg-red-50 dark:bg-red-950/30",textColor:"text-red-700 dark:text-red-300",deltaColor:"text-red-600 dark:text-red-400",label:"Regressions",direction:-1},{type:"improvement",items:s.improvements,borderColor:"border-emerald-200 dark:border-emerald-900",bgColor:"bg-emerald-50 dark:bg-emerald-950/30",textColor:"text-emerald-700 dark:text-emerald-300",deltaColor:"text-emerald-600 dark:text-emerald-400",label:"Improvements",direction:1}].filter(G=>G.items.length>0).map(G=>{const J=d&&f&&d.length>1,oe=J?Math.min(d.length,f.length):0,me=G.items.map((ye,Je)=>{var Dt,Ca,zt,Be;let jt=0;if(J)for(let fa=0;fa<oe;fa++){const $a=(Ca=(Dt=d[fa])==null?void 0:Dt.items[ye.itemIndex])==null?void 0:Ca.scores[ye.scorer],ha=(Be=(zt=f[fa])==null?void 0:zt.items[ye.itemIndex])==null?void 0:Be.scores[ye.scorer];$a!=null&&ha!=null&&(G.direction<0?ha<$a:ha>$a)&&jt++}return{...ye,originalIndex:Je,consistentCount:jt,totalRuns:oe}});J?me.sort((ye,Je)=>Je.consistentCount-ye.consistentCount||Math.abs(Je.delta)-Math.abs(ye.delta)):me.sort((ye,Je)=>Math.abs(Je.delta)-Math.abs(ye.delta));const be=[...new Set(G.items.map(ye=>ye.scorer))],X=be.length===1?be[0]:null,ne=new Map;for(const ye of me)ne.has(ye.scorer)||ne.set(ye.scorer,[]),ne.get(ye.scorer).push(ye);const ce=ye=>{const Je=(m==null?void 0:m.type)===G.type&&m.index===ye.originalIndex,jt=r==null?void 0:r.items[ye.itemIndex],Dt=i==null?void 0:i.items[ye.itemIndex],Ca=ye.input?xr(ye.input,40):`Item #${ye.itemIndex+1}`,zt=J?ye.consistentCount===oe?"":ye.consistentCount===0?"opacity-40":"opacity-65":"";return n.jsxs("div",{className:zt,children:[n.jsxs("button",{onClick:()=>C(G.type,ye.originalIndex),className:"w-full text-left flex items-center gap-3 px-4 py-2.5 text-xs hover:bg-[hsl(var(--accent))] transition-colors cursor-pointer",children:[J&&n.jsxs("span",{className:F("shrink-0 text-[10px] font-mono font-medium px-1.5 py-0.5 rounded",ye.consistentCount===oe?G.type==="regression"?"bg-red-100 dark:bg-red-900/40 text-red-700 dark:text-red-300":"bg-emerald-100 dark:bg-emerald-900/40 text-emerald-700 dark:text-emerald-300":"bg-[hsl(var(--muted))] text-[hsl(var(--muted-foreground))]"),children:[ye.consistentCount,"/",oe]}),n.jsxs("span",{className:"min-w-0 truncate flex-1",children:[n.jsxs("span",{className:"font-mono text-[hsl(var(--muted-foreground))]",children:["#",ye.itemIndex+1]})," ",n.jsx("span",{children:Ca})]}),n.jsxs("span",{className:F("font-mono shrink-0",G.deltaColor),children:[ye.baselineScore.toFixed(2)," ","→"," ",ye.candidateScore.toFixed(2)," ",n.jsxs("span",{className:"text-[hsl(var(--muted-foreground))]",children:["(",ye.delta>0?"+":"",ye.delta.toFixed(2),")"]})]})]}),Je&&jt&&Dt&&n.jsx(Jg,{baselineItem:jt,candidateItem:Dt,scorer:ye.scorer,baselineRunItems:d==null?void 0:d.map(Be=>Be.items[ye.itemIndex]).filter(Boolean),candidateRunItems:f==null?void 0:f.map(Be=>Be.items[ye.itemIndex]).filter(Boolean)})]},ye.originalIndex)},we=5;let Re,dt;if(J){const ye=Math.ceil(oe/2);Re=me.filter(Je=>Je.consistentCount>=ye),dt=me.filter(Je=>Je.consistentCount<ye)}else Re=me.slice(0,we),dt=me.slice(we);const yt=E[G.type]??!1,pe=J?`${dt.length} likely noise (minority of runs)`:`${dt.length} more`,Te=ye=>{const Je=new Map;for(const jt of ye)Je.has(jt.scorer)||Je.set(jt.scorer,[]),Je.get(jt.scorer).push(jt);return Je},Ie=ye=>{if(X)return n.jsx("div",{className:"divide-y divide-[hsl(var(--border))]",children:ye.map(ce)});const Je=Te(ye);return n.jsx("div",{children:[...Je.entries()].map(([jt,Dt])=>n.jsxs("div",{children:[n.jsxs("div",{className:F("px-4 py-2 border-b border-t border-[hsl(var(--border))]",G.type==="regression"?"bg-red-50/30 dark:bg-red-950/5":"bg-emerald-50/30 dark:bg-emerald-950/5"),children:[n.jsx("span",{className:"text-[10px] font-medium uppercase tracking-wider text-[hsl(var(--muted-foreground))]",children:jt}),n.jsxs("span",{className:"text-[10px] text-[hsl(var(--muted-foreground))] ml-1.5",children:["(",Dt.length,")"]})]}),n.jsx("div",{className:"divide-y divide-[hsl(var(--border))]",children:Dt.map(ce)})]},jt))})};return n.jsxs("div",{className:F("border rounded-lg overflow-hidden",G.borderColor),children:[n.jsx("div",{className:F("px-4 py-2.5 border-b",G.bgColor,G.borderColor),children:n.jsxs("h3",{className:F("text-xs font-medium",G.textColor),children:[G.label," (",Re.length,dt.length>0?` + ${dt.length} noise`:"",")",H&&n.jsxs("span",{className:"font-normal opacity-70 ml-1",children:[" — ","scores ",H]})]})}),Re.length>0?Ie(Re):n.jsxs("div",{className:"px-4 py-3 text-xs text-[hsl(var(--muted-foreground))]",children:["No reliable ",G.label.toLowerCase()," detected (all within noise)."]}),dt.length>0&&n.jsxs(n.Fragment,{children:[n.jsxs("button",{onClick:()=>w(ye=>({...ye,[G.type]:!yt})),className:"w-full flex items-center justify-center gap-1.5 px-4 py-2 text-[11px] font-medium text-[hsl(var(--muted-foreground))] hover:text-[hsl(var(--foreground))] transition-colors border-t border-dashed border-[hsl(var(--border))] cursor-pointer",children:[yt?n.jsx(Jj,{className:"h-3 w-3"}):n.jsx(Bn,{className:"h-3 w-3"}),yt?"Hide":"Show"," ",pe]}),yt&&Ie(dt)]})]},G.type)}),r&&i&&n.jsx(h5,{baseline:r,candidate:i,scorerNames:K.map(([G])=>G),baselineRuns:d??void 0,candidateRuns:f??void 0,scorerTypes:_})]})}function w0({label:s,item:r,scorer:i}){var f,m;const o=(f=r.scoreDetails)==null?void 0:f[i],d=typeof((m=o==null?void 0:o.metadata)==null?void 0:m.reasoning)=="string"?o.metadata.reasoning:null;return n.jsxs("div",{className:"p-4 space-y-3",children:[n.jsx("h5",{className:"font-medium text-[hsl(var(--muted-foreground))] uppercase tracking-wider text-[10px]",children:s}),n.jsx(Ct,{data:r.output,collapsed:!0}),(o==null?void 0:o.score)!=null&&n.jsxs("div",{className:"flex items-center gap-1.5",children:[n.jsx("span",{className:"text-[hsl(var(--muted-foreground))]",children:"Score:"}),n.jsx("span",{className:F("px-2 py-0.5 rounded-full font-mono font-medium",uc(o.score)),children:o.score.toFixed(3)})]}),d&&n.jsxs("div",{children:[n.jsx("span",{className:"font-medium text-[hsl(var(--muted-foreground))] text-[10px] uppercase tracking-wider block mb-1",children:"Reasoning"}),n.jsx("pre",{className:"text-xs font-mono p-2 rounded-md bg-[hsl(var(--secondary))] overflow-auto max-h-48 whitespace-pre-wrap leading-relaxed",children:d})]})]})}function Jg({baselineItem:s,candidateItem:r,scorer:i,baselineRunItems:o,candidateRunItems:d}){var w,C,_,R;const[f,m]=b.useState(0),h=o&&o.length>1||d&&d.length>1,x=Math.max((o==null?void 0:o.length)??1,(d==null?void 0:d.length)??1),p=h&&o?o[f]??s:s,v=h&&d?d[f]??r:r,y=(C=(w=s.scoreDetails)==null?void 0:w[i])==null?void 0:C.score,E=(R=(_=r.scoreDetails)==null?void 0:_[i])==null?void 0:R.score;return n.jsxs("div",{className:"border-t border-[hsl(var(--border))] bg-[hsl(var(--card))] text-xs",children:[h&&(y!=null||E!=null)&&n.jsxs("div",{className:"flex items-center gap-4 px-4 py-2 border-b border-[hsl(var(--border))] bg-[hsl(var(--card))]",children:[n.jsxs("span",{className:"text-[10px] font-medium uppercase tracking-wider text-[hsl(var(--muted-foreground))]",children:["Mean across ",x," runs"]}),n.jsxs("div",{className:"flex items-center gap-3",children:[y!=null&&n.jsxs("span",{className:"flex items-center gap-1",children:[n.jsx("span",{className:"text-[hsl(var(--muted-foreground))]",children:"Baseline:"}),n.jsx("span",{className:F("font-mono font-medium",Rt(y)),children:y.toFixed(3)})]}),E!=null&&n.jsxs("span",{className:"flex items-center gap-1",children:[n.jsx("span",{className:"text-[hsl(var(--muted-foreground))]",children:"Candidate:"}),n.jsx("span",{className:F("font-mono font-medium",Rt(E)),children:E.toFixed(3)})]}),y!=null&&E!=null&&n.jsxs("span",{className:F("font-mono",E-y>0?"text-emerald-600 dark:text-emerald-400":E-y<0?"text-red-600 dark:text-red-400":"text-[hsl(var(--muted-foreground))]"),children:["(",E-y>0?"+":"",(E-y).toFixed(3),")"]})]})]}),h&&n.jsxs("div",{className:"flex items-center gap-2 px-4 py-2 border-b border-[hsl(var(--border))] bg-[hsl(var(--muted))]",children:[n.jsx("span",{className:"text-[10px] font-medium uppercase tracking-wider text-[hsl(var(--muted-foreground))]",children:"Run"}),n.jsx("div",{className:"flex items-center gap-0.5",children:Array.from({length:x},(D,H)=>n.jsx("button",{onClick:()=>m(H),className:F("px-2 py-0.5 rounded text-[10px] font-mono transition-colors cursor-pointer",H===f?"bg-[hsl(var(--foreground))] text-[hsl(var(--background))]":"text-[hsl(var(--muted-foreground))] hover:bg-[hsl(var(--accent))]"),children:H+1},H))}),n.jsxs("span",{className:"text-[10px] text-[hsl(var(--muted-foreground))] ml-auto",children:["Showing output and reasoning from run ",f+1," of ",x]})]}),n.jsxs("div",{className:"grid grid-cols-2 gap-0",children:[n.jsx("div",{className:"border-r border-[hsl(var(--border))]",children:n.jsx(w0,{label:"Baseline",item:p,scorer:i})}),n.jsx(w0,{label:"Candidate",item:v,scorer:i})]})]})}function dc(s){const r=Date.now()-s;return r<6e4?"just now":r<36e5?`${Math.floor(r/6e4)}m ago`:r<864e5?`${Math.floor(r/36e5)}h ago`:new Date(s).toLocaleDateString()}function qf(s){return s.data.dataset??""}function g5(s){var r;return(r=s.data.metadata)==null?void 0:r.runGroupId}function v5(s){var d;const r=new Map,i=[];for(const f of s){const m=g5(f);m?(r.has(m)||r.set(m,[]),r.get(m).push(f)):i.push(f)}const o=[];for(const[f,m]of r){if(m.length===1){i.push(m[0]);continue}const h=m[0].data,x=Object.keys(((d=h.summary)==null?void 0:d.scorers)??{}),p={};for(const v of x){const y=m.map(E=>{var w,C,_;return((_=(C=(w=E.data.summary)==null?void 0:w.scorers)==null?void 0:C[v])==null?void 0:_.mean)??0});p[v]={mean:y.reduce((E,w)=>E+w,0)/y.length}}o.push({type:"group",groupId:f,entries:m.sort((v,y)=>y.timestamp-v.timestamp),evalName:m[0].eval,timestamp:Math.max(...m.map(v=>v.timestamp)),dataset:qf(m[0]),runCount:m.length,aggregateScorers:p})}for(const f of i)o.push({type:"single",entry:f});return o.sort((f,m)=>{const h=f.type==="group"?f.timestamp:f.entry.timestamp;return(m.type==="group"?m.timestamp:m.entry.timestamp)-h}),o}function Bf({scorers:s}){const r=Object.entries(s);return r.length===0?null:n.jsx("div",{className:"flex items-center gap-0.5 shrink-0",children:r.map(([i,o])=>n.jsx("div",{className:"relative h-3.5 w-4 rounded-sm bg-[hsl(var(--muted))] overflow-hidden",title:`${i}: ${o.mean.toFixed(3)}`,children:n.jsx("div",{className:F("absolute bottom-0 left-0 right-0 rounded-sm",xc(o.mean)),style:{height:`${Math.max(0,Math.min(100,o.mean*100))}%`}})},i))})}function cf({data:s}){var o;const r=(o=s.summary)==null?void 0:o.scorers;if(!r)return null;const i={};for(const[d,f]of Object.entries(r))i[d]={mean:f.mean};return n.jsx(Bf,{scorers:i})}function b5({selection:s,history:r,pickerItems:i,placeholder:o}){if(!s)return n.jsx("span",{className:"text-sm text-[hsl(var(--muted-foreground))]",children:o});if(s.groupIds&&s.groupIds.length>1){const x=i.find(p=>p.type==="group"&&p.entries.some(v=>v.id===s.id));if(x&&x.type==="group"){const p=Lf(x.entries);return n.jsxs("div",{className:"flex items-center gap-2.5 min-w-0",children:[n.jsx(Bf,{scorers:x.aggregateScorers}),n.jsxs("div",{className:"min-w-0 flex-1",children:[n.jsxs("div",{className:"flex items-center gap-1.5",children:[n.jsx("span",{className:"text-sm font-medium truncate",children:x.evalName}),n.jsxs("span",{className:"inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded text-[10px] font-medium bg-violet-100 dark:bg-violet-900/40 text-violet-700 dark:text-violet-300",children:[n.jsx(Af,{className:"h-2.5 w-2.5"}),x.runCount," runs"]}),p.map(([v,y])=>n.jsxs("span",{className:"px-1 py-0.5 rounded bg-[hsl(var(--secondary))] font-mono text-[9px]",title:`${v} — ${y} calls`,children:[wa(v)," ",n.jsxs("span",{className:"text-[hsl(var(--muted-foreground))]",children:["(",y,")"]})]},v))]}),n.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] text-[hsl(var(--muted-foreground))]",children:[n.jsx(Px,{className:"h-2.5 w-2.5"}),dc(x.timestamp)]})]})]})}}const d=r.find(x=>x.id===s.id);if(!d)return n.jsx("span",{className:"text-sm text-[hsl(var(--muted-foreground))]",children:o});const f=d.data,m=$n(f),h=Ts(f);return n.jsxs("div",{className:"flex items-center gap-2.5 min-w-0",children:[n.jsx(cf,{data:f}),n.jsxs("div",{className:"min-w-0 flex-1",children:[n.jsxs("div",{className:"flex items-center gap-1.5",children:[n.jsx("span",{className:"text-sm font-medium truncate",children:d.eval}),m.map(x=>n.jsxs("span",{className:"px-1 py-0.5 rounded bg-[hsl(var(--secondary))] font-mono text-[9px]",title:h?`${x} — ${h[x]} calls`:x,children:[wa(x),h&&n.jsxs("span",{className:"text-[hsl(var(--muted-foreground))]",children:[" (",h[x],")"]})]},x))]}),n.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] text-[hsl(var(--muted-foreground))]",children:[n.jsx(Px,{className:"h-2.5 w-2.5"}),dc(d.timestamp),n.jsx("span",{className:"opacity-50",children:"·"}),n.jsx("span",{className:"font-mono",children:d.id.slice(0,8)})]})]})]})}function k0({label:s,selection:r,pickerItems:i,disabledSelection:o,history:d,onChange:f,filterDataset:m}){const[h,x]=b.useState(!1),[p,v]=b.useState(null),y=b.useRef(null);b.useEffect(()=>{function C(_){y.current&&!y.current.contains(_.target)&&(x(!1),v(null))}return h&&document.addEventListener("mousedown",C),()=>document.removeEventListener("mousedown",C)},[h]);const E=m?i.filter(C=>C.type==="group"?C.dataset===m:qf(C.entry)===m):i,w=new Set((o==null?void 0:o.groupIds)??(o?[o.id]:[]));return n.jsxs("div",{ref:y,className:"flex-1 min-w-0 relative",children:[n.jsx("label",{className:"block text-[10px] font-medium uppercase tracking-wider text-[hsl(var(--muted-foreground))] mb-1.5",children:s}),n.jsxs("button",{onClick:()=>{x(!h),v(null)},className:F("w-full px-3 py-2 rounded-lg border text-left flex items-center justify-between gap-2 transition-colors min-h-[44px] cursor-pointer",h?"border-[hsl(var(--foreground))] ring-1 ring-[hsl(var(--foreground))]":"border-[hsl(var(--input))] hover:border-[hsl(var(--foreground))/30]","bg-[hsl(var(--background))]"),children:[n.jsx(b5,{selection:r,history:d,pickerItems:i,placeholder:`Select ${s.toLowerCase()}...`}),n.jsx(Bn,{className:F("h-3.5 w-3.5 shrink-0 text-[hsl(var(--muted-foreground))] transition-transform",h&&"rotate-180")})]}),h&&n.jsx("div",{className:"absolute z-50 top-full left-0 right-0 mt-1 max-h-72 overflow-y-auto rounded-lg border border-[hsl(var(--border))] bg-[hsl(var(--background))] shadow-lg",children:E.length===0?n.jsx("div",{className:"px-3 py-4 text-xs text-center text-[hsl(var(--muted-foreground))]",children:"No matching runs"}):E.map(C=>{var T;if(C.type==="group"){const j=p===C.groupId,k=(T=r==null?void 0:r.groupIds)==null?void 0:T.some(S=>C.entries.some(B=>B.id===S));return n.jsxs("div",{className:"border-b border-[hsl(var(--border))] last:border-b-0",children:[n.jsxs("div",{className:"flex items-stretch",children:[n.jsxs("button",{onClick:()=>{f({id:C.entries[0].id,groupIds:C.entries.map(S=>S.id)}),x(!1),v(null)},className:F("flex-1 text-left px-3 py-2.5 flex items-center gap-2.5 transition-colors cursor-pointer",k?"bg-[hsl(var(--accent))]":"hover:bg-[hsl(var(--accent))]"),children:[n.jsx(Bf,{scorers:C.aggregateScorers}),n.jsxs("div",{className:"min-w-0 flex-1",children:[n.jsxs("div",{className:"flex items-center gap-1.5",children:[n.jsx("span",{className:"text-xs font-medium truncate",children:C.evalName}),n.jsxs("span",{className:"inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded text-[9px] font-medium bg-violet-100 dark:bg-violet-900/40 text-violet-700 dark:text-violet-300",children:[n.jsx(Af,{className:"h-2 w-2"}),C.runCount," runs"]}),Lf(C.entries).map(([S,B])=>n.jsxs("span",{className:"px-1 py-0.5 rounded bg-[hsl(var(--secondary))] font-mono text-[9px]",title:`${S} — ${B} calls`,children:[wa(S)," ",n.jsxs("span",{className:"text-[hsl(var(--muted-foreground))]",children:["(",B,")"]})]},S))]}),n.jsxs("div",{className:"text-[10px] text-[hsl(var(--muted-foreground))]",children:[dc(C.timestamp),n.jsxs("span",{className:"opacity-50",children:[" ","·"," "]}),"pooled comparison"]})]}),k&&n.jsx("div",{className:"shrink-0 h-1.5 w-1.5 rounded-full bg-[hsl(var(--foreground))]"})]}),n.jsx("button",{onClick:S=>{S.stopPropagation(),v(j?null:C.groupId)},className:"shrink-0 w-8 flex items-center justify-center border-l border-[hsl(var(--border))] hover:bg-[hsl(var(--accent))] transition-colors cursor-pointer",title:j?"Hide individual runs":"Show individual runs",children:j?n.jsx(Bn,{className:"h-3 w-3 text-[hsl(var(--muted-foreground))]"}):n.jsx(Ba,{className:"h-3 w-3 text-[hsl(var(--muted-foreground))]"})})]}),j&&C.entries.map(S=>{var K;const B=S.data,$=(r==null?void 0:r.id)===S.id&&!(r!=null&&r.groupIds),W=w.has(S.id);return n.jsxs("button",{onClick:()=>{f({id:S.id}),x(!1),v(null)},disabled:W,className:F("w-full text-left pl-8 pr-3 py-2 flex items-center gap-2.5 transition-colors border-t border-[hsl(var(--border))] cursor-pointer","bg-[hsl(var(--muted))]/30",$?"bg-[hsl(var(--accent))]":"hover:bg-[hsl(var(--accent))]",W&&"opacity-30 cursor-not-allowed"),children:[n.jsx(cf,{data:B}),n.jsx("div",{className:"min-w-0 flex-1",children:n.jsxs("div",{className:"flex items-center gap-1 text-[10px] text-[hsl(var(--muted-foreground))]",children:[n.jsxs("span",{children:["Run ",(((K=B.metadata)==null?void 0:K.runIndex)??0)+1]}),n.jsx("span",{className:"opacity-50",children:"·"}),n.jsx("span",{className:"font-mono",children:S.id.slice(0,8)}),(()=>{const te=Ts(B);return $n(B).map(re=>n.jsxs("span",{className:"px-1 py-0.5 rounded bg-[hsl(var(--secondary))] text-[hsl(var(--foreground))] font-mono text-[9px]",title:te?`${re} — ${te[re]} calls`:re,children:[wa(re),te&&n.jsxs("span",{className:"text-[hsl(var(--muted-foreground))]",children:[" ","(",te[re],")"]})]},re))})()]})}),$&&n.jsx("div",{className:"shrink-0 h-1.5 w-1.5 rounded-full bg-[hsl(var(--foreground))]"})]},S.id)})]},C.groupId)}const{entry:_}=C,R=_.data,D=(r==null?void 0:r.id)===_.id,H=w.has(_.id);return n.jsxs("button",{onClick:()=>{f({id:_.id}),x(!1),v(null)},disabled:H,className:F("w-full text-left px-3 py-2.5 flex items-center gap-2.5 transition-colors border-b border-[hsl(var(--border))] last:border-b-0 cursor-pointer",D?"bg-[hsl(var(--accent))]":"hover:bg-[hsl(var(--accent))]",H&&"opacity-30 cursor-not-allowed"),children:[n.jsx(cf,{data:R}),n.jsxs("div",{className:"min-w-0 flex-1",children:[n.jsxs("div",{className:"flex items-center gap-1.5",children:[n.jsx("span",{className:"text-xs font-medium truncate",children:_.eval}),(()=>{const j=Ts(R);return $n(R).map(k=>n.jsxs("span",{className:"px-1 py-0.5 rounded bg-[hsl(var(--secondary))] font-mono text-[9px]",title:j?`${k} — ${j[k]} calls`:k,children:[wa(k),j&&n.jsxs("span",{className:"text-[hsl(var(--muted-foreground))]",children:[" ","(",j[k],")"]})]},k))})()]}),n.jsxs("div",{className:"text-[10px] text-[hsl(var(--muted-foreground))]",children:[dc(_.timestamp),n.jsxs("span",{className:"opacity-50",children:[" ","·"," "]}),n.jsx("span",{className:"font-mono",children:_.id.slice(0,8)}),n.jsxs("span",{className:"opacity-50",children:[" ","·"," "]}),R.summary.count," items"]})]}),D&&n.jsx("div",{className:"shrink-0 h-1.5 w-1.5 rounded-full bg-[hsl(var(--foreground))]"})]},_.id)})})]})}function y5({history:s,baselineSelection:r,candidateSelection:i,onBaselineChange:o,onCandidateChange:d,onCompare:f,comparing:m}){const h=b.useMemo(()=>v5(s),[s]),x=r?s.find(y=>y.id===r.id):null,p=x?qf(x):null,v=r!=null&&i!=null&&r.id!==i.id&&!m;return n.jsx("div",{className:"space-y-3",children:n.jsxs("div",{className:"flex items-end gap-2",children:[n.jsx(k0,{label:"Baseline",selection:r,pickerItems:h,disabledSelection:i,history:s,onChange:o,filterDataset:null}),n.jsx("button",{onClick:()=>{if(r&&i){const y=r;o(i),d(y)}},disabled:!r||!i,className:"shrink-0 p-2 rounded-lg border border-[hsl(var(--input))] hover:bg-[hsl(var(--accent))] disabled:opacity-30 transition-colors mb-[1px] cursor-pointer",title:"Swap baseline and candidate",children:n.jsx(Lj,{className:"h-3.5 w-3.5 text-[hsl(var(--muted-foreground))]"})}),n.jsx(k0,{label:"Candidate",selection:i,pickerItems:h,disabledSelection:r,history:s,onChange:d,filterDataset:p}),n.jsx("button",{onClick:f,disabled:!v,className:F("shrink-0 px-5 py-2 text-sm font-medium rounded-lg transition-all cursor-pointer","bg-[hsl(var(--foreground))] text-[hsl(var(--background))]","hover:opacity-90 disabled:opacity-40"),children:m?"Comparing…":"Compare"})]})})}function j5({currentIndex:s,totalRuns:r,aggregate:i,onIndexChange:o}){const d=s===-1,f=s>-1,m=s<r-1;return n.jsx("div",{className:"px-6",children:n.jsxs("div",{className:"flex items-center justify-between px-4 py-2 rounded-lg bg-[hsl(var(--muted))]",children:[n.jsx("button",{onClick:()=>o(s-1),disabled:!f,className:"p-1 rounded hover:bg-[hsl(var(--accent))] disabled:opacity-30 transition-colors cursor-pointer",children:n.jsx(Xj,{size:16})}),n.jsxs("div",{className:"text-center",children:[n.jsx("span",{className:"text-sm font-medium",children:d?`Aggregate (${r} runs)`:`Run ${s+1} of ${r}`}),!d&&n.jsx("button",{onClick:()=>o(-1),className:"ml-3 text-xs text-[hsl(var(--muted-foreground))] hover:text-[hsl(var(--foreground))] underline transition-colors cursor-pointer",children:"View aggregate"}),d&&(()=>{const h=Object.values(i.scorers),x=h.reduce((p,v)=>p+v.mean,0)/Math.max(h.length,1);return n.jsxs("div",{className:"text-xs text-[hsl(var(--muted-foreground))]",children:["Overall mean: ",x.toFixed(3)," across ",h.length," scorer",h.length!==1?"s":""]})})()]}),n.jsx("button",{onClick:()=>o(s+1),disabled:!m,className:"p-1 rounded hover:bg-[hsl(var(--accent))] disabled:opacity-30 transition-colors cursor-pointer",children:n.jsx(Ba,{size:16})})]})})}function N5(s){var f;const r={},i=[];for(const m of s){const h=m.data;if(!((f=h.summary)!=null&&f.scorers))continue;const x=[];for(const[p,v]of Object.entries(h.summary.scorers))r[p]||(r[p]=[]),r[p].push(v.mean),x.push(v.mean);x.length>0&&i.push(x.reduce((p,v)=>p+v,0)/x.length)}const o={};for(const[m,h]of Object.entries(r)){const x=h.reduce((v,y)=>v+y,0)/h.length,p=h.length>1?Math.sqrt(h.reduce((v,y)=>v+(y-x)**2,0)/(h.length-1)):0;o[m]={mean:x,std:p}}let d=null;if(i.length>0){const m=i.reduce((x,p)=>x+p,0)/i.length,h=i.length>1?Math.sqrt(i.reduce((x,p)=>x+(p-m)**2,0)/(i.length-1)):0;d={mean:m,std:h}}return{scorers:o,overall:d}}function S5(s){const r=s.eval.replace(/[^a-zA-Z0-9_-]+/g,"-").replace(/^-+|-+$/g,"")||"eval",i=s.id.slice(0,8),o=new Date(s.timestamp).toISOString().replace(/[-:]/g,"").replace(/\.\d{3}Z$/,"Z"),d=`${r}-${i}-${o}.json`,f=JSON.stringify(s.data,null,2),m=new Blob([f],{type:"application/json"}),h=URL.createObjectURL(m),x=document.createElement("a");x.href=h,x.download=d,document.body.appendChild(x),x.click(),document.body.removeChild(x),setTimeout(()=>URL.revokeObjectURL(h),0)}function w5({history:s,evalFilter:r,onEvalFilterChange:i,onSelect:o,onSelectGroup:d,onRescore:f,onDelete:m,registeredEvalNames:h,readOnly:x,expandedGroups:p,onToggleGroup:v}){const[y,E]=b.useState(null),w=[...new Set(s.map(j=>j.eval))].sort(),C=b.useMemo(()=>r?s.filter(j=>j.eval===r):s,[s,r]),{rows:_,scorerCols:R}=b.useMemo(()=>{var $,W;const j=new Map,k=[];for(const K of C){const re=($=K.data.metadata)==null?void 0:$.runGroupId;re?(j.has(re)||j.set(re,[]),j.get(re).push(K)):k.push(K)}const S=[];for(const[K,te]of j)te.sort((re,Me)=>Me.timestamp-re.timestamp),te.length===1?S.push({type:"entry",entry:te[0]}):S.push({type:"group",groupId:K,entries:te,evalName:te[0].eval,newestTimestamp:te[0].timestamp});for(const K of k)S.push({type:"entry",entry:K});S.sort((K,te)=>{const re=K.type==="group"?K.newestTimestamp:K.entry.timestamp;return(te.type==="group"?te.newestTimestamp:te.entry.timestamp)-re});const B=new Set;for(const K of C){const te=K.data;if((W=te.summary)!=null&&W.scorers)for(const re of Object.keys(te.summary.scorers))B.add(re)}return{rows:S,scorerCols:[...B].sort()}},[C]),D=b.useMemo(()=>{var k;const j={};for(const S of C){const $=(k=S.data.metadata)==null?void 0:k.scorerTypes;$&&Object.assign(j,$)}return j},[C]),H=8+R.length+(f?1:0),T=(j,k,S)=>{const B=j.data,$=y===j.id;return n.jsxs(b.Fragment,{children:[n.jsxs("tr",{"data-entry-id":j.id,className:F("border-t border-[hsl(var(--border))] cursor-pointer hover:bg-[hsl(var(--accent))] transition-colors",S&&!k&&"bg-[hsl(var(--accent))]/30",$&&"bg-[hsl(var(--accent))]/40"),onClick:()=>E($?null:j.id),children:[n.jsx("td",{className:F("px-3 py-2.5 font-mono",k&&"pl-9"),children:n.jsxs("div",{className:"flex flex-col gap-0.5",children:[n.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[k&&n.jsx("span",{className:"inline-block w-1 h-3 mr-0.5 rounded-sm bg-[hsl(var(--border))]"}),j.eval]}),(()=>{const W=tr(B);if(W.length===0||W.length===1&&W[0]===j.eval)return null;const K=rf(B),te=K?`Workflows: ${W.map(re=>`${re} (${K[re]??"?"} calls)`).join(", ")}`:`Workflows: ${W.join(", ")}`;return n.jsx("span",{className:"text-[10px] font-normal text-[hsl(var(--muted-foreground))] truncate max-w-[240px]",title:te,children:W.join(" · ")})})()]})}),n.jsx("td",{className:"px-3 py-2.5",children:(()=>{const W=$n(B);if(W.length===0)return n.jsx("span",{className:"text-[hsl(var(--muted-foreground))]",children:"-"});const K=Ts(B);return n.jsx("span",{className:"inline-flex items-center gap-1 flex-wrap",children:W.map(te=>n.jsxs("span",{className:"px-1.5 py-0.5 rounded bg-[hsl(var(--secondary))] text-[hsl(var(--foreground))] font-mono text-[10px]",title:K?`${te} — ${K[te]} calls`:te,children:[wa(te),K&&K[te]!=null&&n.jsxs("span",{className:"ml-0.5 text-[hsl(var(--muted-foreground))]",children:["(",K[te],")"]})]},te))})})()}),n.jsx("td",{className:"px-3 py-2.5 text-[hsl(var(--muted-foreground))]",children:new Date(j.timestamp).toLocaleString()}),n.jsx("td",{className:"px-3 py-2.5 text-right font-mono",children:B.summary.count}),n.jsx("td",{className:"px-3 py-2.5 text-right font-mono",children:B.summary.failures>0?n.jsx("span",{className:"text-red-600 dark:text-red-400",children:B.summary.failures}):n.jsx("span",{className:"text-[hsl(var(--muted-foreground))]",children:"0"})}),n.jsx("td",{className:"px-3 py-2.5 text-right font-mono text-[hsl(var(--muted-foreground))]",children:B.duration>0?xt(B.duration):"-"}),n.jsx("td",{className:"px-3 py-2.5 text-right font-mono text-[hsl(var(--muted-foreground))]",children:B.totalCost>0?at(B.totalCost):"-"}),(()=>{var te;const W=Object.values(((te=B.summary)==null?void 0:te.scorers)??{}).map(re=>re.mean),K=W.length>0?W.reduce((re,Me)=>re+Me,0)/W.length:null;return n.jsx("td",{className:"px-3 py-2.5 text-right font-mono font-medium border-l border-[hsl(var(--border))]",children:K!=null?n.jsx("span",{className:Rt(K),children:K.toFixed(3)}):n.jsx("span",{className:"text-[hsl(var(--muted-foreground))]",children:"-"})})})(),R.map(W=>{var te,re;const K=(re=(te=B.summary)==null?void 0:te.scorers)==null?void 0:re[W];return n.jsx("td",{className:"px-3 py-2.5 text-right font-mono",children:K?n.jsxs("div",{children:[n.jsx("span",{className:Rt(K.mean),children:K.mean.toFixed(3)}),K.min!==K.max&&n.jsxs("div",{className:"text-[9px] text-[hsl(var(--muted-foreground))]",children:[K.min.toFixed(2),"–",K.max.toFixed(2)]})]}):n.jsx("span",{className:"text-[hsl(var(--muted-foreground))]",children:"-"})},W)}),f&&n.jsx("td",{className:"px-3 py-2.5"})]}),$&&(()=>{var te,re,Me;const W=(te=B.metadata)==null?void 0:te.scorerTypes,K=(re=B.metadata)==null?void 0:re.originalId;return n.jsx("tr",{className:"border-t border-[hsl(var(--border))] bg-[hsl(var(--muted))]/50",children:n.jsx("td",{colSpan:H,className:"px-4 py-3",children:n.jsxs("div",{className:"flex items-center justify-between gap-4",children:[n.jsxs("div",{className:"flex items-center gap-4 text-[10px] text-[hsl(var(--muted-foreground))] flex-wrap",children:[n.jsxs("span",{children:["ID: ",n.jsx("span",{className:"font-mono",children:B.id.slice(0,8)})]}),n.jsxs("span",{children:["Dataset:"," ",n.jsx("span",{className:"font-medium text-[hsl(var(--foreground))]",children:B.dataset})]}),(()=>{const he=tr(B);return he.length===0?null:n.jsxs("span",{children:[he.length>1?"Workflows":"Workflow",":"," ",n.jsx("span",{className:"font-medium text-[hsl(var(--foreground))]",children:he.join(", ")})]})})(),(()=>{const he=$n(B);if(he.length===0)return null;const ae=Ts(B);return n.jsx("span",{className:"inline-flex items-center gap-1",children:he.map(z=>n.jsxs("span",{className:"px-1.5 py-0.5 rounded bg-[hsl(var(--secondary))] text-[hsl(var(--foreground))] font-mono",title:ae?`${z} — ${ae[z]} calls`:z,children:[wa(z),ae&&ae[z]!=null&&n.jsxs("span",{className:"ml-0.5 text-[hsl(var(--muted-foreground))]",children:["(",ae[z],")"]})]},z))})})(),!!((Me=B.metadata)!=null&&Me.rescored)&&n.jsx("span",{className:"px-1.5 py-0.5 rounded bg-amber-100 text-amber-700 dark:bg-amber-900/30 dark:text-amber-400",children:"Rescored"}),K&&n.jsxs("span",{children:["from"," ",n.jsx("button",{onClick:he=>{he.stopPropagation(),E(K),requestAnimationFrame(()=>{var ae;(ae=document.querySelector(`[data-entry-id="${CSS.escape(K)}"]`))==null||ae.scrollIntoView({behavior:"smooth",block:"center"})})},className:"font-mono underline hover:text-[hsl(var(--foreground))] transition-colors cursor-pointer",children:K.slice(0,8)})]}),W&&Object.keys(W).length>0&&n.jsxs("span",{className:"inline-flex items-center gap-1.5",children:["Scorers:",Object.entries(W).sort(([he],[ae])=>he.localeCompare(ae)).map(([he,ae])=>n.jsx("span",{className:F("px-1.5 py-0.5 rounded font-mono cursor-default",ae==="llm"?"bg-purple-100 text-purple-700 dark:bg-purple-900/30 dark:text-purple-400":"bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-400"),title:ae==="llm"?`${he} — LLM scorer (scores may vary between runs)`:`${he} — deterministic scorer`,children:he},he))]})]}),n.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[f&&(()=>{const he=!h||h.has(j.eval),ae=he&&!x,z=x?"Rescore unavailable — Studio is mounted in read-only mode.":he?"Re-run scorers on saved outputs without re-executing the workflow":`Rescore unavailable — no registered eval named "${j.eval}". Imported CLI artifacts can only be rescored when the runtime has a matching registered eval config.`;return n.jsx("button",{onClick:L=>{L.stopPropagation(),ae&&f(j.eval,j.id)},disabled:!ae,className:F("px-2.5 py-1 text-[10px] font-medium rounded border border-[hsl(var(--input))] transition-colors",ae?"hover:bg-[hsl(var(--accent))] cursor-pointer":"opacity-40 cursor-not-allowed"),title:z,children:"Rescore"})})(),n.jsx("button",{onClick:he=>{he.stopPropagation(),S5(j)},className:"p-1 rounded border border-[hsl(var(--input))] hover:bg-[hsl(var(--accent))] cursor-pointer transition-colors",title:`Export this result as JSON (${j.eval}-${j.id.slice(0,8)}-...json)`,"aria-label":"Export result as JSON",children:n.jsx(lN,{size:12})}),m&&n.jsx("button",{onClick:he=>{he.stopPropagation(),!x&&m(j)},disabled:x,className:F("p-1 rounded border border-[hsl(var(--input))] transition-colors",x?"opacity-40 cursor-not-allowed":"hover:bg-red-50 hover:border-red-200 hover:text-red-600 dark:hover:bg-red-950/30 dark:hover:border-red-900 dark:hover:text-red-400 cursor-pointer"),title:x?"Delete unavailable — Studio is mounted in read-only mode.":"Delete this history entry","aria-label":"Delete history entry",children:n.jsx(Of,{size:12})}),n.jsxs("button",{onClick:he=>{he.stopPropagation(),o(B)},className:"inline-flex items-center gap-1 px-2.5 py-1 text-[10px] font-medium rounded border border-[hsl(var(--input))] hover:bg-[hsl(var(--accent))] transition-colors cursor-pointer",title:"Open full run details in the Run tab",children:["View Details",n.jsx(mr,{size:10})]})]})]})})})})()]},j.id)};return n.jsxs("div",{children:[w.length>1&&n.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[n.jsxs("select",{value:r,onChange:j=>i(j.target.value),className:"px-2 py-1 text-xs rounded-lg border border-[hsl(var(--input))] bg-[hsl(var(--background))]",children:[n.jsx("option",{value:"",children:"All evals"}),w.map(j=>n.jsx("option",{value:j,children:j},j))]}),r&&n.jsxs("span",{className:"text-xs text-[hsl(var(--muted-foreground))]",children:[C.length," run",C.length!==1?"s":""]})]}),n.jsx("div",{className:"border border-[hsl(var(--border))] rounded-xl overflow-hidden",children:n.jsx("div",{className:"overflow-x-auto",children:n.jsxs("table",{className:"w-full text-xs",children:[n.jsx("thead",{children:n.jsxs("tr",{className:"bg-[hsl(var(--muted))]",children:[n.jsx("th",{className:"text-left px-3 py-2.5 font-medium",children:"Eval"}),n.jsx("th",{className:"text-left px-3 py-2.5 font-medium",children:"Model"}),n.jsx("th",{className:"text-left px-3 py-2.5 font-medium",children:"Timestamp"}),n.jsx("th",{className:"text-right px-3 py-2.5 font-medium",children:"Items"}),n.jsx("th",{className:"text-right px-3 py-2.5 font-medium",children:"Failures"}),n.jsx("th",{className:"text-right px-3 py-2.5 font-medium",children:"Duration"}),n.jsx("th",{className:"text-right px-3 py-2.5 font-medium",children:"Cost"}),n.jsx("th",{className:"text-right px-3 py-2.5 font-medium border-l border-[hsl(var(--border))]",children:"Overall"}),R.map(j=>n.jsxs("th",{className:"text-right px-3 py-2.5 font-medium font-mono whitespace-nowrap",title:j,children:[j,D[j]==="llm"&&n.jsx("span",{className:"ml-1 px-1 py-0.5 text-[9px] font-medium rounded bg-purple-100 text-purple-600 dark:bg-purple-900/30 dark:text-purple-400 align-middle",title:"LLM scorer — scores may vary between runs",children:"LLM"})]},j)),f&&n.jsx("th",{className:"px-3 py-2.5 font-medium w-8"})]})}),n.jsx("tbody",{children:_.map((j,k)=>{if(j.type==="group"){const S=p.has(j.groupId),B=N5(j.entries),$=B.scorers,W=j.entries.reduce((he,ae)=>he+ae.data.summary.count,0),K=(()=>{var he;for(const ae of j.entries){const z=(he=ae.data.metadata)==null?void 0:he.batchAttempted;if(typeof z=="number")return z}})(),te=K!==void 0&&j.entries.length<K,re=j.entries.reduce((he,ae)=>he+ae.data.duration,0),Me=j.entries.reduce((he,ae)=>he+ae.data.totalCost,0);return n.jsxs(b.Fragment,{children:[n.jsxs("tr",{className:F("border-t border-[hsl(var(--border))] cursor-pointer hover:bg-[hsl(var(--accent))] transition-colors",k===0&&"bg-[hsl(var(--accent))]/30"),onClick:()=>v(j.groupId),children:[n.jsx("td",{className:"px-3 py-2.5 font-mono",children:n.jsxs("div",{className:"flex flex-col gap-0.5",children:[n.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[n.jsx("span",{className:"shrink-0 p-0.5 -m-0.5",children:S?n.jsx(Bn,{size:14}):n.jsx(Ba,{size:14})}),j.evalName]}),(()=>{const he=new Set,ae=[];for(const z of j.entries)for(const L of tr(z.data))he.has(L)||(he.add(L),ae.push(L));return ae.length===0||ae.length===1&&ae[0]===j.evalName?null:n.jsx("span",{className:"text-[10px] font-normal text-[hsl(var(--muted-foreground))] truncate max-w-[240px] pl-[22px]",title:`Workflows: ${ae.join(", ")}`,children:ae.join(" · ")})})()]})}),n.jsx("td",{className:"px-3 py-2.5",children:(()=>{const he=Lf(j.entries);return he.length===0?n.jsx("span",{className:"text-[hsl(var(--muted-foreground))]",children:"-"}):n.jsx("span",{className:"inline-flex items-center gap-1 flex-wrap",children:he.map(([ae,z])=>n.jsxs("span",{className:"px-1.5 py-0.5 rounded bg-[hsl(var(--secondary))] text-[hsl(var(--foreground))] font-mono text-[10px]",title:`${ae} — ${z} calls`,children:[wa(ae),n.jsxs("span",{className:"ml-0.5 text-[hsl(var(--muted-foreground))]",children:["(",z,")"]})]},ae))})})()}),n.jsx("td",{className:"px-3 py-2.5 text-[hsl(var(--muted-foreground))]",children:new Date(j.newestTimestamp).toLocaleString()}),n.jsx("td",{className:"px-3 py-2.5 text-right font-mono",children:W}),n.jsx("td",{className:"px-3 py-2.5 text-right",children:n.jsxs("span",{className:F("inline-flex items-center gap-1 px-1.5 py-0.5 rounded-md",te?"bg-amber-100 text-amber-900 dark:bg-amber-950/60 dark:text-amber-200":"bg-[hsl(var(--secondary))] text-[hsl(var(--muted-foreground))]"),title:te?`Partial batch — ${j.entries.length} of ${K} runs completed`:void 0,children:[n.jsx(Af,{size:10}),te?n.jsxs(n.Fragment,{children:[j.entries.length,"/",K," runs",n.jsx("span",{className:"font-medium uppercase tracking-wide text-[9px] ml-1",children:"partial"})]}):n.jsxs(n.Fragment,{children:[j.entries.length," runs"]})]})}),n.jsx("td",{className:"px-3 py-2.5 text-right font-mono text-[hsl(var(--muted-foreground))]",children:re>0?xt(re):"-"}),n.jsx("td",{className:"px-3 py-2.5 text-right font-mono text-[hsl(var(--muted-foreground))]",children:Me>0?at(Me):"-"}),n.jsx("td",{className:"px-3 py-2.5 text-right font-mono font-medium border-l border-[hsl(var(--border))]",children:B.overall?n.jsxs("span",{className:Rt(B.overall.mean),children:[B.overall.mean.toFixed(3),B.overall.std>0&&n.jsxs("span",{className:"text-[hsl(var(--muted-foreground))] font-normal",children:[" ± ",B.overall.std.toFixed(3)]})]}):n.jsx("span",{className:"text-[hsl(var(--muted-foreground))]",children:"-"})}),R.map(he=>{const ae=$[he];return n.jsx("td",{className:"px-3 py-2.5 text-right font-mono",children:ae?n.jsxs("span",{className:Rt(ae.mean),children:[ae.mean.toFixed(3),n.jsxs("span",{className:"text-[hsl(var(--muted-foreground))]",children:[" "," ± ",ae.std.toFixed(3)]})]}):n.jsx("span",{className:"text-[hsl(var(--muted-foreground))]",children:"-"})},he)}),f&&n.jsx("td",{className:"px-3 py-2.5"})]}),S&&n.jsxs(n.Fragment,{children:[d&&n.jsx("tr",{className:"border-t border-[hsl(var(--border))] bg-[hsl(var(--muted))]/50",children:n.jsx("td",{colSpan:H,className:"px-4 py-2.5",children:n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsxs("span",{className:"text-[10px] text-[hsl(var(--muted-foreground))]",children:[j.entries.length," runs in this group"]}),n.jsxs("button",{onClick:he=>{he.stopPropagation(),d(j.entries)},className:"inline-flex items-center gap-1 px-2.5 py-1 text-[10px] font-medium rounded border border-[hsl(var(--input))] hover:bg-[hsl(var(--accent))] transition-colors cursor-pointer",title:"View combined statistics across all runs in this group",children:["View Aggregate",n.jsx(mr,{size:10})]})]})})}),j.entries.map(he=>T(he,!0,!1))]})]},j.groupId)}return T(j.entry,!1,k===0)})})]})})})]})}const uf=1,df=25,k5=5,tc=s=>Math.max(uf,Math.min(df,Math.round(s)));function C5({evals:s,selectedEval:r,onSelectEval:i,runCount:o,onRunCountChange:d,captureTraces:f,onCaptureTracesChange:m,running:h,onRun:x}){return n.jsxs("div",{className:F("inline-flex items-stretch rounded-full bg-[hsl(var(--background))]","ring-1 ring-[hsl(var(--input))] shadow-sm","hover:ring-[hsl(var(--ring))] focus-within:ring-[hsl(var(--ring))]","transition-shadow"),children:[n.jsx(ki,{items:s,value:r,onSelect:i,getKey:p=>p.name,getLabel:p=>p.name,getDescription:p=>n.jsxs(n.Fragment,{children:[n.jsx("span",{children:p.workflow}),n.jsx("span",{className:"opacity-40 mx-1",children:"·"}),n.jsx("span",{children:p.dataset}),n.jsx("span",{className:"opacity-40 mx-1",children:"·"}),n.jsxs("span",{children:[p.scorers.length," scorer",p.scorers.length!==1?"s":""]})]}),searchMatch:(p,v)=>p.name.toLowerCase().includes(v)||p.workflow.toLowerCase().includes(v)||p.dataset.toLowerCase().includes(v),placeholder:"Select eval",searchPlaceholder:"Search evals…",emptyLabel:"No evals registered",shortcut:!0,triggerClassName:"rounded-l-full",ariaLabel:"Select an eval"}),n.jsx(E5,{value:o,onChange:d,disabled:h}),n.jsx("button",{type:"button",role:"switch","aria-checked":f,"aria-label":"Capture per-item trace events",onClick:()=>m(!f),disabled:h,title:f?"Capturing per-item traces (click to disable) — traces appear inline on each item":"Capture per-item traces — extra memory, but lets you inspect every event per item",className:F("flex items-center px-2 border-l border-[hsl(var(--input))] transition-colors cursor-pointer","focus:outline-none focus-visible:bg-[hsl(var(--muted))]","disabled:opacity-40 disabled:cursor-not-allowed",f?"text-[hsl(var(--foreground))] bg-[hsl(var(--muted))]":"text-[hsl(var(--muted-foreground))] hover:bg-[hsl(var(--muted))] hover:text-[hsl(var(--foreground))]"),children:n.jsx(mc,{size:12,strokeWidth:2.5})}),n.jsxs("button",{type:"button",onClick:x,disabled:!r||h,className:F("inline-flex items-center gap-1.5 pl-3.5 pr-4 py-2 text-sm font-medium cursor-pointer","bg-[hsl(var(--foreground))] text-[hsl(var(--background))] rounded-r-full","hover:opacity-90 focus:outline-none focus-visible:ring-2 focus-visible:ring-offset-1 focus-visible:ring-[hsl(var(--foreground))]","disabled:opacity-40 disabled:cursor-not-allowed transition-opacity"),children:[n.jsx(_f,{size:12,className:F("fill-current",h&&"animate-spin fill-none")}),h?"Running…":"Run"]})]})}function E5({value:s,onChange:r,disabled:i=!1}){const[o,d]=b.useState(!1),[f,m]=b.useState(""),h=b.useRef(null),x=b.useRef(!1),p=b.useCallback((D,H)=>{const T=(H?k5:1)*D;r(tc(s+T))},[s,r]),v=b.useCallback(()=>{i||(x.current=!1,m(String(s)),d(!0))},[s,i]);b.useEffect(()=>{o||m(String(s))},[s,o]),b.useEffect(()=>{o&&requestAnimationFrame(()=>{var D,H;(D=h.current)==null||D.focus(),(H=h.current)==null||H.select()})},[o]);const y=b.useCallback(()=>{if(x.current){d(!1);return}x.current=!0;const D=parseInt(f,10);Number.isNaN(D)||r(tc(D)),d(!1)},[f,r]),E=b.useCallback(()=>{x.current=!0,d(!1)},[]),w=b.useCallback(D=>{if(D.key==="Enter")D.preventDefault(),y();else if(D.key==="Escape")D.preventDefault(),E();else if(D.key==="ArrowUp"){D.preventDefault();const H=parseInt(f,10);Number.isNaN(H)||m(String(tc(H+1)))}else if(D.key==="ArrowDown"){D.preventDefault();const H=parseInt(f,10);Number.isNaN(H)||m(String(tc(H-1)))}},[y,E,f]),C=b.useCallback(D=>{i||(D.key==="Enter"||D.key===" "?(D.preventDefault(),v()):D.key==="ArrowUp"?(D.preventDefault(),p(1,D.shiftKey)):D.key==="ArrowDown"&&(D.preventDefault(),p(-1,D.shiftKey)))},[i,v,p]),_=s<=uf,R=s>=df;return n.jsxs("div",{className:"flex items-stretch border-l border-[hsl(var(--input))]",role:"group","aria-label":"Run count",children:[n.jsx("button",{type:"button",onClick:D=>p(-1,D.shiftKey),disabled:i||_,title:"Decrease runs — Shift+click: −5","aria-label":"Decrease run count",className:F("flex items-center px-1.5 transition-colors cursor-pointer","text-[hsl(var(--muted-foreground))]","hover:bg-[hsl(var(--muted))] hover:text-[hsl(var(--foreground))]","focus:outline-none focus-visible:bg-[hsl(var(--muted))]","disabled:opacity-40 disabled:cursor-not-allowed disabled:hover:bg-transparent disabled:hover:text-[hsl(var(--muted-foreground))]"),children:n.jsx(xN,{size:12,strokeWidth:2.5})}),o?n.jsx("input",{ref:h,type:"text",inputMode:"numeric",value:f,onChange:D=>m(D.target.value.replace(/[^0-9]/g,"").slice(0,2)),onKeyDown:w,onBlur:y,"aria-label":"Run count",className:F("w-10 text-center text-xs font-semibold tabular-nums bg-transparent","focus:outline-none text-[hsl(var(--foreground))]")}):n.jsxs("button",{type:"button",role:"spinbutton","aria-valuenow":s,"aria-valuemin":uf,"aria-valuemax":df,"aria-valuetext":`${s} run${s!==1?"s":""}`,onClick:v,onKeyDown:C,disabled:i,title:"Click or press Enter to type a value — Arrow keys step","aria-label":`Run count: ${s}. Press Enter to edit, arrow keys to step.`,className:F("flex items-center justify-center min-w-[2.5rem] px-1 text-xs tabular-nums cursor-text","transition-colors hover:bg-[hsl(var(--muted))]","focus:outline-none focus-visible:bg-[hsl(var(--muted))]","disabled:opacity-60 disabled:cursor-not-allowed",s>1?"text-[hsl(var(--foreground))] font-semibold":"text-[hsl(var(--muted-foreground))]"),children:[n.jsx("span",{className:"opacity-50 mr-0.5",children:"×"}),s]}),n.jsx("button",{type:"button",onClick:D=>p(1,D.shiftKey),disabled:i||R,title:"Increase runs — Shift+click: +5","aria-label":"Increase run count",className:F("flex items-center px-1.5 transition-colors cursor-pointer","text-[hsl(var(--muted-foreground))]","hover:bg-[hsl(var(--muted))] hover:text-[hsl(var(--foreground))]","focus:outline-none focus-visible:bg-[hsl(var(--muted))]","disabled:opacity-40 disabled:cursor-not-allowed disabled:hover:bg-transparent disabled:hover:text-[hsl(var(--muted-foreground))]"),children:n.jsx(wg,{size:12,strokeWidth:2.5})})]})}function T5(){var Li,Hi,kr,Vn,xl;const s=_i(),[r,i]=b.useState("run"),[o,d]=b.useState(""),f=qS(),m=f.status==="running",[h,x]=b.useState(null),[p,v]=b.useState(null),[y,E]=b.useState(null),[w,C]=b.useState(1),[_,R]=b.useState(!0),[D,H]=b.useState(-1),[T,j]=b.useState(new Set),[k,S]=b.useState(null),[B,$]=b.useState(0),[W,K]=b.useState(null),[te,re]=b.useState("all"),[Me,he]=b.useState(""),[ae,z]=b.useState(""),[L,ie]=b.useState("index"),[ve,ge]=b.useState("asc"),[M,Q]=b.useState("mean"),[G,J]=b.useState("asc"),[oe,me]=b.useState(""),[be,X]=b.useState(!1),[ne,ce]=b.useState(null),[we,Re]=b.useState(null),[dt,yt]=b.useState(null),[pe,Te]=b.useState(null),[Ie,ye]=b.useState(null),[Je,jt]=b.useState(null),[Dt,Ca]=b.useState(null),{data:zt=[]}=Sa({queryKey:["evals"],queryFn:eS}),{data:Be=[]}=Sa({queryKey:["evalHistory"],queryFn:tS}),{data:fa,isLoading:$a,isError:ha}=Sa({queryKey:["health"],queryFn:D2,staleTime:1/0}),$e=!!(fa!=null&&fa.readOnly),dn=(!$a||ha)&&!$e,Ia=b.useRef(null),[fn,Ea]=b.useState(!1),[Nt,Zt]=b.useState(null);b.useEffect(()=>{if(!Nt)return;const ee=setTimeout(()=>Zt(null),6e3);return()=>clearTimeout(ee)},[Nt]),b.useEffect(()=>{if(p!=="Cancelled")return;const ee=setTimeout(()=>v(null),4e3);return()=>clearTimeout(ee)},[p]);const Jt=b.useCallback(async ee=>{var ue;v(null),Zt(null),Ea(!0);try{const de=await ee.text();let Se;try{Se=JSON.parse(de)}catch{throw new Error(`${ee.name} is not valid JSON`)}const fe=await lS(Se),qe="imported"in fe?fe.imported:[fe],De=qe.length,_e=(ue=qe[0])==null?void 0:ue.id;await s.invalidateQueries({queryKey:["evalHistory"]});const Qe=De>1?` (${De} runs)`:"";if(!_e)throw new Error("Import succeeded but no entries were returned");pe?Ie?Zt(`Imported ${ee.name}${Qe} — added to history (both compare slots full)`):(ye({id:_e}),Zt(`Imported ${ee.name}${Qe} — selected as candidate`)):(Te({id:_e}),Zt(`Imported ${ee.name}${Qe} — selected as baseline`))}catch(de){v(de instanceof Error?de.message:String(de))}finally{Ea(!1)}},[s,pe,Ie]);b.useEffect(()=>{var fe;if(pe||Ie||Be.length<2)return;const ee=Be[0].eval,ue=Be.filter(qe=>qe.eval===ee);if(ue.length<2)return;const de=new Set,Se=[];for(const qe of ue){const De=(fe=qe.data.metadata)==null?void 0:fe.runGroupId,_e=De??qe.id;if(!de.has(_e)){if(de.add(_e),De){const Qe=ue.filter(ft=>{var ht;return((ht=ft.data.metadata)==null?void 0:ht.runGroupId)===De}).map(ft=>ft.id);Qe.length>1?Se.push({id:Qe[0],groupIds:Qe}):Se.push({id:Qe[0]})}else Se.push({id:qe.id});if(Se.length>=2)break}}Se.length>=2&&(ye(Se[0]),Te(Se[1]))},[Be,pe,Ie]);const As=zt.find(ee=>ee.name===o),gc=b.useMemo(()=>new Set(zt.map(ee=>ee.name)),[zt]),Ke=h==null?void 0:h._multiRun,Qn=Ke!=null&&D===-1,Ue=Ke&&D>=0?Ke.allRuns[D]:h;b.useEffect(()=>{E(null)},[D]);const Gn=b.useRef(f.status);b.useEffect(()=>{if(Gn.current!==f.status)if(Gn.current=f.status,f.status==="done"&&f.done){const{evalResultId:ee,runGroupId:ue}=f.done;(async()=>{try{await s.refetchQueries({queryKey:["evalHistory"]});const de=s.getQueryData(["evalHistory"])??[],Se=de.find(fe=>fe.id===ee);if(!Se){v(`Eval completed but result ${ee} was not found in history.`);return}if(ue){const qe=de.filter(_e=>{var Qe;return((Qe=_e.data.metadata)==null?void 0:Qe.runGroupId)===ue}).map(_e=>_e.data),De=m0(qe);x(De??Se.data)}else x(Se.data);E(null),H(-1)}catch(de){v(de instanceof Error?de.message:String(de))}finally{d0()}})()}else f.status==="error"&&f.error&&(Gn.current!=="done"&&v(f.error),s.invalidateQueries({queryKey:["evalHistory"]}),d0())},[f.status,f.done,f.error,s]);const hn=b.useCallback(async()=>{if(o){v(null),x(null),E(null),H(-1);try{await BS(o,w,_)}catch(ee){v(ee instanceof Error?ee.message:String(ee))}}},[o,w,_]),fl=b.useCallback(async()=>{if(!(!pe||!Ie)){X(!0),ce(null);try{const ee=De=>De.groupIds&&De.groupIds.length>1?De.groupIds:De.id,ue=ee(pe),de=ee(Ie),Se=De=>{var Rs;const _e=Be.find(ma=>ma.id===De.id);if(!_e)return null;const Qe=_e.data;if(!De.groupIds||De.groupIds.length<=1)return Qe;const ft=De.groupIds.map(ma=>{var It;return(It=Be.find(Bt=>Bt.id===ma))==null?void 0:It.data}).filter(ma=>ma!=null),ht=Math.min(...ft.map(ma=>ma.items.length)),Os=Object.keys(((Rs=Qe.summary)==null?void 0:Rs.scorers)??{}),gl=Array.from({length:ht},(ma,It)=>{const Bt={},Cr={};for(const Er of Os){const Ds=ft.map(en=>{var vl;return(vl=en.items[It])==null?void 0:vl.scores[Er]}).filter(en=>en!=null),Tr=Ds.length>0?Math.round(Ds.reduce((en,vl)=>en+vl,0)/Ds.length*1e3)/1e3:null;Bt[Er]=Tr,Cr[Er]={score:Tr}}return{...Qe.items[It],scores:Bt,scoreDetails:Cr}});return{...Qe,items:gl}};Re(Se(pe)),yt(Se(Ie));const fe=De=>!De.groupIds||De.groupIds.length<=1?null:De.groupIds.map(_e=>{var Qe;return(Qe=Be.find(ft=>ft.id===_e))==null?void 0:Qe.data}).filter(_e=>_e!=null);jt(fe(pe)),Ca(fe(Ie));const qe=await sS(ue,de);ce(qe)}catch(ee){v(ee instanceof Error?ee.message:String(ee))}finally{X(!1)}}},[Be,pe,Ie]),_s=b.useCallback(async(ee,ue)=>{v(null);try{const de=await nS(ee,ue);x(de),E(null),H(-1),i("run"),s.invalidateQueries({queryKey:["evalHistory"]})}catch(de){v(de instanceof Error?de.message:String(de))}},[s]),vc=b.useCallback(async ee=>{var Se;v(null);const ue=ee.id.slice(0,8);if(window.confirm(`Delete this eval history entry?
311
+ `)})]}):null}function j2({event:s}){const r=Lg(s);return r?n.jsxs(n.Fragment,{children:[s.model&&n.jsxs("p",{className:"text-xs mb-1",children:[n.jsx("strong",{children:"Model:"})," ",s.model,r.turn!=null&&n.jsxs("span",{className:"ml-2 text-[hsl(var(--muted-foreground))]",children:["· turn ",r.turn]})]}),s.promptVersion&&n.jsxs("p",{className:"text-xs mb-1",children:[n.jsx("strong",{children:"Version:"})," ",s.promptVersion]}),s.tokens&&(s.tokens.input!=null||s.tokens.output!=null)&&n.jsxs("p",{className:"text-xs mb-1",children:[n.jsx("strong",{children:"Tokens:"}),s.tokens.input!=null?` in=${s.tokens.input}`:"",s.tokens.output!=null?` out=${s.tokens.output}`:"",s.tokens.reasoning?` reasoning=${s.tokens.reasoning}`:""]}),r.thinking&&n.jsx(da,{label:"Thinking",content:r.thinking,tone:"info"}),r.response&&n.jsx(da,{label:"Response",content:r.response,defaultOpen:!0}),r.error&&n.jsx(da,{label:"Provider error",content:r.error,tone:"warning",defaultOpen:!0})]}):null}function N2({event:s}){const r=g2(s);return r?n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"flex items-center gap-2 mb-2 text-xs",children:n.jsx("span",{className:F("px-2 py-0.5 rounded-full text-[10px] font-medium",r.approved?"bg-green-100 text-green-800 dark:bg-green-950/40 dark:text-green-300":"bg-red-100 text-red-800 dark:bg-red-950/40 dark:text-red-300"),children:r.approved?"APPROVED":"DENIED"})}),r.reason&&n.jsxs("p",{className:"text-xs mb-2",children:[n.jsx("strong",{children:"Reason:"})," ",r.reason]}),r.args!==void 0&&n.jsxs(n.Fragment,{children:[n.jsx("p",{className:"text-[11px] font-medium uppercase tracking-wider opacity-70 mb-1",children:"Arguments"}),n.jsx(Ps,{data:r.args})]})]}):null}function qg({status:s}){const r=s==="succeeded"?"bg-green-100 text-green-800 dark:bg-green-950/40 dark:text-green-300":s==="cancelled"?"bg-amber-100 text-amber-800 dark:bg-amber-950/40 dark:text-amber-300":"bg-red-100 text-red-800 dark:bg-red-950/40 dark:text-red-300";return n.jsx("span",{className:F("px-2 py-0.5 rounded-full text-[10px] font-medium",r),children:s.toUpperCase()})}function S2({event:s}){if(s.type!=="tool_call_end"||s.schemaVersion!==2)return null;const{outcome:r}=s.data;return n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"flex items-center gap-2 mb-2 text-xs",children:[n.jsx(qg,{status:r.status}),r.status==="failed"&&n.jsxs("span",{className:"text-[hsl(var(--muted-foreground))]",children:[r.failure.phase," · ",r.failure.kind," · ",r.failure.disposition]}),r.status==="cancelled"&&n.jsx("span",{className:"text-[hsl(var(--muted-foreground))]",children:r.cancellation.phase})]}),s.data.requestedTool&&s.data.requestedTool!==s.tool&&n.jsxs("p",{className:"text-xs mb-2",children:[n.jsx("strong",{children:"Requested as:"})," ",s.data.requestedTool]}),n.jsx("p",{className:"text-[11px] font-medium uppercase tracking-wider opacity-70 mb-1",children:"Arguments"}),n.jsx(Ps,{data:s.data.args}),r.status==="succeeded"&&n.jsxs(n.Fragment,{children:[n.jsx("p",{className:"text-[11px] font-medium uppercase tracking-wider opacity-70 mt-2 mb-1",children:"Result"}),n.jsx(Ps,{data:r.result})]}),r.status==="failed"&&"result"in r.failure&&n.jsxs(n.Fragment,{children:[n.jsx("p",{className:"text-[11px] font-medium uppercase tracking-wider opacity-70 mt-2 mb-1",children:"Result before failure"}),n.jsx(Ps,{data:r.failure.result})]}),r.status==="failed"&&n.jsx(da,{label:"Host failure",content:`${r.failure.error.name}: ${r.failure.error.message}`,tone:"warning",defaultOpen:!0}),r.status==="denied"&&r.reason&&n.jsxs("p",{className:"text-xs mt-2",children:[n.jsx("strong",{children:"Reason:"})," ",r.reason]}),r.status==="cancelled"&&r.cancellation.reason&&n.jsxs("p",{className:"text-xs mt-2",children:[n.jsx("strong",{children:"Reason:"})," ",r.cancellation.reason]}),r.status==="cancelled"&&"result"in r.cancellation&&n.jsxs(n.Fragment,{children:[n.jsx("p",{className:"text-[11px] font-medium uppercase tracking-wider opacity-70 mt-2 mb-1",children:"Result before cancellation"}),n.jsx(Ps,{data:r.cancellation.result})]})]})}function w2({event:s}){return s.type!=="tool_call_rejected"?null:n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"flex items-center gap-2 mb-2 text-xs",children:[n.jsx(qg,{status:"rejected"}),n.jsx("span",{className:"text-[hsl(var(--muted-foreground))]",children:s.data.reason})]}),n.jsxs("p",{className:"text-xs mb-2",children:[n.jsx("strong",{children:"Requested tool:"})," ",s.data.requestedTool]}),s.data.reason==="unavailable"&&n.jsxs("p",{className:"text-xs mb-2",children:[n.jsx("strong",{children:"Available tools:"})," ",s.data.availableTools.join(", ")||"none"]}),s.data.reason==="invalid_arguments"&&n.jsx(Ps,{data:{args:s.data.args,issues:s.data.issues}}),s.data.reason==="invalid_json"&&n.jsx(da,{label:"Parse error",content:s.data.message,tone:"warning",defaultOpen:!0})]})}function k2({event:s}){const r=Hg(s);if(!r)return null;const i=r.valid===!1||r.blocked===!0;return n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"flex items-center gap-2 mb-2 text-xs",children:[n.jsx("span",{className:F("px-2 py-0.5 rounded-full text-[10px] font-medium",i?"bg-red-100 text-red-800 dark:bg-red-950/40 dark:text-red-300":"bg-green-100 text-green-800 dark:bg-green-950/40 dark:text-green-300"),children:i?"FAILED":"PASSED"}),r.attempt!=null&&r.maxAttempts!=null&&n.jsxs("span",{className:"text-[hsl(var(--muted-foreground))]",children:["attempt ",r.attempt," of ",r.maxAttempts]}),r.guardrailType&&n.jsxs("span",{className:"text-[hsl(var(--muted-foreground))]",children:["· ",r.guardrailType]})]}),r.reason&&n.jsxs("p",{className:"text-xs mb-2",children:[n.jsx("strong",{children:"Reason:"})," ",r.reason]}),r.feedbackMessage&&n.jsx(da,{label:"Retry feedback sent to LLM",content:r.feedbackMessage,tone:"warning",defaultOpen:!0})]})}function C2(s){switch(s.type){case"text":return`text (${s.characters} characters)`;case"image":case"audio":{const r=s.mediaType?`, ${s.mediaType}`:"",i=s.bytes!==void 0?`, ${s.bytes} bytes`:"";return`${s.type} (${s.source}${r}${i})`}default:return`unknown (${String(s.type)})`}}function E2({event:s}){if(s.type!=="ask_start")return null;const{prompt:r}=s;return n.jsxs(n.Fragment,{children:[r.length>0?n.jsx(da,{label:"Prompt",content:r,defaultOpen:!0}):n.jsx("p",{className:"text-xs text-[hsl(var(--muted-foreground))]",children:"(no prompt)"}),s.input&&n.jsxs("div",{className:"mt-2 text-xs text-[hsl(var(--muted-foreground))]",children:[n.jsx("strong",{children:"Model input:"})," ",s.input.parts.map(C2).join(", ")]})]})}function T2({event:s}){if(s.type!=="ask_end")return null;const{outcome:r,cost:i,duration:o}=s;return n.jsxs(n.Fragment,{children:[n.jsxs("p",{className:"text-xs mb-1",children:[n.jsx("strong",{children:"Outcome:"})," ",n.jsx("span",{className:r.ok?"text-green-600 dark:text-green-400":"text-red-600 dark:text-red-400",children:r.ok?"ok":"error"})]}),n.jsxs("p",{className:"text-xs mb-1",children:[n.jsx("strong",{children:"Ask cost:"})," ",at(i)]}),n.jsxs("p",{className:"text-xs mb-1",children:[n.jsx("strong",{children:"Duration:"})," ",o,"ms"]}),r.ok&&r.result!==void 0&&n.jsx(da,{label:"Result",content:typeof r.result=="string"?r.result:JSON.stringify(r.result,null,2),defaultOpen:!0}),!r.ok&&r.error&&n.jsx(da,{label:"Error",content:r.error,tone:"warning",defaultOpen:!0})]})}function M2({event:s}){if(s.type!=="pipeline")return null;const{status:r,stage:i,attempt:o,maxAttempts:d}=s,f=s.status==="failed"?s.reason:void 0;return n.jsxs(n.Fragment,{children:[n.jsxs("p",{className:"text-xs mb-1",children:[n.jsx("strong",{children:"Pipeline:"})," ",i," · ",r," · attempt ",o,"/",d]}),f&&n.jsx(da,{label:"Failure reason",content:f,tone:"warning",defaultOpen:!0})]})}function A2({event:s}){if(s.type==="handoff_start"){if(!s.data)return null;const{source:r,target:i,mode:o,message:d}=s.data;return n.jsxs(n.Fragment,{children:[n.jsxs("p",{className:"text-xs mb-1",children:[n.jsx("strong",{children:"Handoff starts:"})," ",r," → ",i,o?` · ${o}`:""]}),d&&n.jsx(da,{label:"Prompt to target",content:d,defaultOpen:!0})]})}if(s.type==="handoff_return"){if(!s.data)return null;const{source:r,target:i,duration:o}=s.data;return n.jsxs(n.Fragment,{children:[n.jsxs("p",{className:"text-xs mb-1",children:[n.jsx("strong",{children:"Handoff returns:"})," ",r," → ",i]}),typeof o=="number"&&n.jsxs("p",{className:"text-xs mb-1",children:[n.jsx("strong",{children:"Round-trip duration:"})," ",o,"ms"]})]})}return null}function _2({event:s}){const r="data"in s?s.data:void 0;return n.jsxs(n.Fragment,{children:[s.model&&n.jsxs("p",{className:"text-xs mb-1",children:[n.jsx("strong",{children:"Model:"})," ",s.model]}),s.promptVersion&&n.jsxs("p",{className:"text-xs mb-1",children:[n.jsx("strong",{children:"Version:"})," ",s.promptVersion]}),s.tokens&&(s.tokens.input!=null||s.tokens.output!=null)&&n.jsxs("p",{className:"text-xs mb-1",children:[n.jsx("strong",{children:"Tokens:"}),s.tokens.input!=null?` in=${s.tokens.input}`:"",s.tokens.output!=null?` out=${s.tokens.output}`:"",s.tokens.reasoning?` reasoning=${s.tokens.reasoning}`:""]}),r!=null&&n.jsx(Ps,{data:r,collapsed:!0})]})}function O2({event:s,index:r,isExpanded:i,onToggle:o,maxDuration:d,baseDepth:f,lifecycleBadge:m}){var w,C;const h=Math.max(0,zg(s)-f),x=v2(s),p=Hg(s),v=s.type==="guardrail"||s.type==="schema_check"||s.type==="validate",y=v&&((p==null?void 0:p.valid)===!1||(p==null?void 0:p.blocked)===!0),E=s.step!=null&&s.step!==Number.MAX_SAFE_INTEGER?`#${s.step}`:"";return n.jsxs("div",{children:[n.jsxs("button",{onClick:o,className:F("w-full flex items-center gap-2 px-3 py-1.5 text-xs rounded-xl cursor-pointer hover:bg-[hsl(var(--accent))] text-left",x||y?"bg-amber-100/60 dark:bg-amber-950/30 ring-1 ring-amber-400/40":"bg-[hsl(var(--secondary))]"),style:{marginLeft:`${h*16}px`},children:[i?n.jsx(Bn,{size:12,className:"shrink-0 text-[hsl(var(--muted-foreground))]"}):n.jsx(Ba,{size:12,className:"shrink-0 text-[hsl(var(--muted-foreground))]"}),n.jsx("span",{className:"font-mono text-[hsl(var(--muted-foreground))] w-8 truncate",children:E||`#${r}`}),n.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${t0(s)}`}),n.jsx("span",{className:"font-medium w-28 truncate",children:s.type}),m&&n.jsx("span",{className:F("px-1.5 py-0.5 text-[9px] font-medium rounded-full whitespace-nowrap",m==="succeeded"||m==="approved"?"bg-green-100 text-green-800 dark:bg-green-950/40 dark:text-green-300":m==="running"||m==="accepted"||m==="legacy result"||m==="legacy"?"bg-slate-200 text-slate-800 dark:bg-slate-800 dark:text-slate-200":m.includes("incomplete")||m==="cancelled"?"bg-amber-100 text-amber-800 dark:bg-amber-950/40 dark:text-amber-300":"bg-red-100 text-red-800 dark:bg-red-950/40 dark:text-red-300"),children:m}),x&&n.jsxs("span",{className:"inline-flex items-center gap-0.5 px-1.5 py-0.5 text-[9px] font-medium rounded-full bg-amber-200 text-amber-900 dark:bg-amber-800 dark:text-amber-100",title:`Retry after ${((w=Ug(s))==null?void 0:w.retryReason)??((C=Lg(s))==null?void 0:C.retryReason)} failure`,children:[n.jsx(ON,{size:9}),"retry"]}),(p==null?void 0:p.attempt)!=null&&p.maxAttempts!=null&&n.jsxs("span",{className:"px-1.5 py-0.5 text-[9px] font-medium rounded-full bg-[hsl(var(--muted))] text-[hsl(var(--muted-foreground))]",title:`Attempt ${p.attempt} of ${p.maxAttempts}`,children:[p.attempt,"/",p.maxAttempts]}),s.agent&&n.jsx("span",{className:"text-blue-600 dark:text-blue-400 w-28 truncate",children:s.agent}),"tool"in s&&s.tool&&n.jsx("span",{className:"text-purple-600 dark:text-purple-400 w-28 truncate",children:s.tool}),n.jsx("div",{className:"flex-1 h-3 bg-[hsl(var(--background))] rounded overflow-hidden",children:s.duration!=null&&s.duration>0&&n.jsx("div",{className:`h-full rounded ${t0(s)}`,style:{width:`${Math.max(s.duration/d*100,2)}%`,opacity:.7}})}),s.duration!=null&&n.jsx(Df,{ms:s.duration}),s.cost!=null&&s.cost>0&&n.jsx(Fa,{cost:s.cost})]}),i&&n.jsx("div",{className:"mt-1 mb-2 p-3 rounded-xl bg-[hsl(var(--card))] border border-[hsl(var(--border))]",style:{marginLeft:`${h*16+32}px`},children:s.type==="agent_call_start"?n.jsx(y2,{event:s}):s.type==="agent_call_end"?n.jsx(j2,{event:s}):v?n.jsx(k2,{event:s}):s.type==="tool_approval"?n.jsx(N2,{event:s}):s.type==="tool_call_end"&&s.schemaVersion===2?n.jsx(S2,{event:s}):s.type==="tool_call_rejected"?n.jsx(w2,{event:s}):s.type==="ask_start"?n.jsx(E2,{event:s}):s.type==="ask_end"?n.jsx(T2,{event:s}):s.type==="pipeline"?n.jsx(M2,{event:s}):s.type==="handoff_start"||s.type==="handoff_return"?n.jsx(A2,{event:s}):n.jsx(_2,{event:s})})]})}function Di({events:s,lifecycleEvents:r=s,traceComplete:i,maxDuration:o,showToolbar:d=!0,header:f}){const[m,h]=b.useState(new Set),[x,p]=b.useState(0),[v,y]=b.useState(0),E=b.useMemo(()=>o??Math.max(...s.map(H=>H.duration??0),1),[s,o]),w=b.useMemo(()=>{const H=new Map,T=i??r.some(S=>S.type==="done"||S.type==="error"||S.type==="workflow_end"||S.type==="log"&&typeof S.data=="object"&&S.data!==null&&"event"in S.data&&S.data.event==="events_truncated"),j=new Set(r.filter(S=>S.type==="tool_call_end"&&S.schemaVersion===2).map(S=>`${S.executionId}\0${S.askId}\0${S.callId}`)),k=r.filter(S=>S.type==="tool_call_end"&&S.schemaVersion!==2);for(const S of r)if(S.type==="tool_call_start")if(S.schemaVersion===2){const B=`${S.executionId}\0${S.askId}\0${S.callId}`;H.set(S,j.has(B)?"accepted":T?"incomplete trace":"running")}else{const B=k.some($=>{const W="callId"in S?S.callId:void 0,K="callId"in $?$.callId:void 0;return W!=null&&K!=null?W===K:$.tool===S.tool});H.set(S,B?"legacy":T?"legacy incomplete":"legacy")}else S.type==="tool_call_end"?H.set(S,S.schemaVersion===2?S.data.outcome.status:"legacy result"):S.type==="tool_call_rejected"?H.set(S,"rejected"):S.type==="tool_denied"?H.set(S,"legacy denied"):S.type==="tool_approval"&&H.set(S,S.data.approved?"approved":"denied");return H},[r,i]),C=b.useMemo(()=>{let H=1/0;for(const T of s){const j=zg(T);j<H&&(H=j)}return Number.isFinite(H)?H:0},[s]),_=H=>{h(T=>{const j=new Set(T);return j.has(H)?j.delete(H):j.add(H),j})},R=()=>{const H=s.map((T,j)=>T.step??j);h(new Set(H)),p(1),y(T=>T+1)},D=()=>{h(new Set),p(0),y(H=>H+1)};return n.jsxs(n.Fragment,{children:[d&&n.jsxs("div",{className:"flex items-center justify-between mb-3",children:[n.jsxs("span",{className:"text-xs text-[hsl(var(--muted-foreground))]",children:[s.length," event",s.length!==1?"s":"",f&&n.jsx("span",{className:"ml-2",children:f})]}),s.length>0&&n.jsxs("div",{className:"flex items-center gap-1",children:[n.jsxs("button",{onClick:R,className:"inline-flex items-center gap-1 px-2 py-1 text-xs rounded-md hover:bg-[hsl(var(--accent))] text-[hsl(var(--muted-foreground))]",title:"Expand all — including inner sections",children:[n.jsx(yg,{size:12}),"Expand"]}),n.jsxs("button",{onClick:D,className:"inline-flex items-center gap-1 px-2 py-1 text-xs rounded-md hover:bg-[hsl(var(--accent))] text-[hsl(var(--muted-foreground))]",title:"Collapse all",children:[n.jsx(bg,{size:12}),"Collapse"]})]})]}),n.jsx(zf.Provider,{value:{level:x,version:v},children:n.jsx("div",{className:"space-y-1",children:s.map((H,T)=>{const j=H.step??T;return n.jsx(O2,{event:H,index:T,isExpanded:m.has(j),onToggle:()=>_(j),maxDuration:E,baseDepth:C,lifecycleBadge:w.get(H)},j)})})})]})}const a0="axl.studio.split.",n0=2,R2=6;function s0(s,r){return s<=0?!1:s<2*r+R2}function Ud(s,r,i){return Math.min(i,Math.max(r,s))}function jr({left:s,right:r,defaultPercent:i=50,minPercent:o=20,maxPercent:d=80,minPx:f=200,storageKey:m,className:h}){const[x,p]=b.useState(()=>{if(!m)return i;try{const k=localStorage.getItem(a0+m);if(!k)return i;const S=Number(k);return Number.isFinite(S)?Ud(S,o,d):i}catch{return i}}),[v,y]=b.useState(!1),E=b.useRef(null),w=b.useRef(!1),C=b.useRef(null),_=b.useRef(null);b.useEffect(()=>{if(m)try{localStorage.setItem(a0+m,String(x))}catch{}},[m,x]),b.useEffect(()=>{const k=E.current;if(!k||typeof ResizeObserver>"u"){k&&y(s0(k.getBoundingClientRect().width,f));return}const S=new ResizeObserver(B=>{const $=B[0];if(!$)return;const W=$.contentRect.width;y(s0(W,f))});return S.observe(k),()=>S.disconnect()},[f]);const R=b.useCallback(()=>{var B;const k=((B=E.current)==null?void 0:B.getBoundingClientRect().width)??0;if(!k||!Number.isFinite(k))return{min:o,max:d};const S=f/k*100;return{min:Math.max(o,S),max:Math.min(d,100-S)}},[o,d,f]);b.useEffect(()=>()=>{C.current&&(document.removeEventListener("mousemove",C.current),document.removeEventListener("touchmove",C.current)),_.current&&(document.removeEventListener("mouseup",_.current),document.removeEventListener("touchend",_.current),document.removeEventListener("touchcancel",_.current)),w.current&&(document.body.style.cursor="",document.body.style.userSelect="")},[]);const D=b.useCallback(k=>{w.current=!0;const S=k,B=E.current;if(!B)return;const $=B.getBoundingClientRect().width,W=x,K=re=>{var ve;if(!w.current)return;const Me=B.getBoundingClientRect().width||$,z=(("touches"in re?((ve=re.touches[0])==null?void 0:ve.clientX)??S:re.clientX)-S)/Me*100,{min:L,max:ie}=R();p(Ud(W+z,L,ie))},te=()=>{w.current=!1,document.removeEventListener("mousemove",K),document.removeEventListener("touchmove",K),document.removeEventListener("mouseup",te),document.removeEventListener("touchend",te),document.removeEventListener("touchcancel",te),document.body.style.cursor="",document.body.style.userSelect="",C.current=null,_.current=null};C.current=K,_.current=te,document.addEventListener("mousemove",K),document.addEventListener("touchmove",K,{passive:!1}),document.addEventListener("mouseup",te),document.addEventListener("touchend",te),document.addEventListener("touchcancel",te),document.body.style.cursor="col-resize",document.body.style.userSelect="none"},[x,R]),H=b.useCallback(k=>{k.preventDefault(),D(k.clientX)},[D]),T=b.useCallback(k=>{const S=k.touches[0];S&&D(S.clientX)},[D]),j=b.useCallback(k=>{if(k.key!=="ArrowLeft"&&k.key!=="ArrowRight")return;k.preventDefault();const S=k.key==="ArrowLeft"?-1:1,B=k.shiftKey?n0*5:n0,{min:$,max:W}=R();p(K=>Ud(K+S*B,$,W))},[R]);return v?n.jsxs("div",{ref:E,className:F("flex flex-col min-h-0",h),children:[n.jsx("div",{className:"min-h-0 min-w-0 flex flex-col flex-1 overflow-auto",children:s}),n.jsx("div",{role:"separator","aria-orientation":"horizontal",className:"h-px shrink-0 bg-[hsl(var(--border))]"}),n.jsx("div",{className:"min-h-0 min-w-0 flex flex-col flex-1 overflow-auto",children:r})]}):n.jsxs("div",{ref:E,className:F("flex min-h-0",h),children:[n.jsx("div",{className:"min-h-0 min-w-0 flex flex-col",style:{width:`${x}%`},children:s}),n.jsx("div",{role:"separator","aria-orientation":"vertical","aria-valuenow":Math.round(x),"aria-valuemin":o,"aria-valuemax":d,tabIndex:0,onMouseDown:H,onTouchStart:T,onKeyDown:j,className:"w-1.5 shrink-0 cursor-col-resize bg-[hsl(var(--border))] hover:bg-[hsl(var(--ring))] focus:bg-[hsl(var(--ring))] focus:outline-none transition-colors"}),n.jsx("div",{className:"min-h-0 min-w-0 flex flex-col",style:{width:`${100-x}%`},children:r})]})}const D2=(window.__AXL_STUDIO_BASE__??"")+"/api";async function rt(s,r){const i=await fetch(`${D2}${s}`,{headers:{"Content-Type":"application/json",...r==null?void 0:r.headers},...r});if(i.status===413){if((i.headers.get("content-type")??"").includes("application/json")){const m=await i.json().catch(()=>{});if(m&&!m.ok)throw new Error(m.error.message)}throw new Error(`Request body too large (HTTP 413). If you're importing a large eval file through an embedded Studio middleware, raise your host framework's JSON body limit on the Studio mount. See the Studio README "Host body limits" section.`)}if(!(i.headers.get("content-type")??"").includes("application/json")){const m=(await i.text().catch(()=>"")).slice(0,200).trim();throw new Error(`Server returned HTTP ${i.status} with non-JSON response`+(m?`: ${m}`:""))}let d;try{d=await i.json()}catch(f){throw new Error(`Failed to parse server response as JSON (HTTP ${i.status}): ${f instanceof Error?f.message:String(f)}`)}if(!d.ok)throw new Error(d.error.message);return d.data}const z2=()=>rt("/health"),U2=()=>rt("/workflows"),L2=s=>rt(`/workflows/${encodeURIComponent(s)}`),H2=(s,r,i=!1)=>rt(`/workflows/${encodeURIComponent(s)}/execute`,{method:"POST",body:JSON.stringify({input:r,stream:i})}),q2=()=>rt("/executions"),B2=()=>rt("/sessions"),$2=s=>rt(`/sessions/${encodeURIComponent(s)}`),Q2=s=>rt(`/sessions/${encodeURIComponent(s)}`,{method:"DELETE"}),G2=()=>rt("/agents"),Y2=()=>rt("/tools"),K2=s=>rt(`/tools/${encodeURIComponent(s)}`),V2=(s,r)=>rt(`/tools/${encodeURIComponent(s)}/test`,{method:"POST",body:JSON.stringify({input:r})}),X2=s=>rt(`/memory/${encodeURIComponent(s)}`),F2=(s,r,i)=>rt(`/memory/${encodeURIComponent(s)}/${encodeURIComponent(r)}`,{method:"PUT",body:JSON.stringify({value:i})}),Z2=(s,r)=>rt(`/memory/${encodeURIComponent(s)}/${encodeURIComponent(r)}`,{method:"DELETE"}),J2=(s,r,i)=>rt("/memory/search",{method:"POST",body:JSON.stringify({query:s,scope:r,limit:i})}),I2=(s="7d")=>rt(`/costs?window=${s}`),W2=(s="7d")=>rt(`/eval-trends?window=${s}`),P2=(s="7d")=>rt(`/workflow-stats?window=${s}`),eS=(s="7d")=>rt(`/trace-stats?window=${s}`),tS=()=>rt("/evals"),aS=()=>rt("/evals/history"),nS=(s,r)=>rt(`/evals/${encodeURIComponent(s)}/run`,{method:"POST",body:JSON.stringify({runs:r==null?void 0:r.runs,stream:!0,captureTraces:r==null?void 0:r.captureTraces})}),Bg=s=>rt(`/evals/runs/${encodeURIComponent(s)}/cancel`,{method:"POST"}),sS=(s,r)=>rt(`/evals/${encodeURIComponent(s)}/rescore`,{method:"POST",body:JSON.stringify({resultId:r})}),lS=(s,r,i)=>rt("/evals/compare",{method:"POST",body:JSON.stringify({baselineId:s,candidateId:r,options:i})}),rS=(s,r)=>rt("/evals/import",{method:"POST",body:JSON.stringify({result:s,eval:r})}),iS=s=>rt(`/evals/history/${encodeURIComponent(s)}`,{method:"DELETE"}),l0=(s,r,i,o)=>rt("/playground/chat",{method:"POST",body:JSON.stringify(o?{message:s,sessionId:r,agent:i,image:o}:{message:s,sessionId:r,agent:i})});class oS{constructor(){Wl(this,"ws",null);Wl(this,"listeners",new Map);Wl(this,"connectionListeners",new Set);Wl(this,"reconnectTimer",null);Wl(this,"url");const r=window.location.protocol==="https:"?"wss:":"ws:",i=window.__AXL_STUDIO_BASE__??"";this.url=`${r}//${window.location.host}${i}/ws`}connect(){var r;((r=this.ws)==null?void 0:r.readyState)!==WebSocket.OPEN&&(this.ws=new WebSocket(this.url),this.ws.onopen=()=>{for(const i of this.connectionListeners)i(!0);for(const i of this.listeners.keys())this.send({type:"subscribe",channel:i})},this.ws.onmessage=i=>{try{const o=JSON.parse(i.data);if(o.type==="event"&&o.channel){const d=this.listeners.get(o.channel);if(d)for(const m of d)m(o.data);const f=o.channel.indexOf(":");if(f>0){const m=o.channel.substring(0,f)+":*",h=this.listeners.get(m);if(h)for(const x of h)x(o.data)}}}catch{}},this.ws.onclose=()=>{for(const i of this.connectionListeners)i(!1);this.scheduleReconnect()},this.ws.onerror=()=>{var i;(i=this.ws)==null||i.close()})}scheduleReconnect(){this.reconnectTimer||(this.reconnectTimer=setTimeout(()=>{this.reconnectTimer=null,this.connect()},2e3))}send(r){var i;((i=this.ws)==null?void 0:i.readyState)===WebSocket.OPEN&&this.ws.send(JSON.stringify(r))}subscribe(r,i){let o=this.listeners.get(r);return o||(o=new Set,this.listeners.set(r,o),this.send({type:"subscribe",channel:r})),o.add(i),this.connect(),()=>{o.delete(i),o.size===0&&(this.listeners.delete(r),this.send({type:"unsubscribe",channel:r}))}}subscribeConnection(r){return this.connectionListeners.add(r),()=>this.connectionListeners.delete(r)}disconnect(){var r;this.reconnectTimer&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null),(r=this.ws)==null||r.close(),this.ws=null}}const Ni=new oS;function Uf(s,r,i){const o=b.useRef(r);o.current=r;const d=b.useRef(i);d.current=i,b.useEffect(()=>{var h;if(!s)return;const f=Ni.subscribe(s,x=>o.current(x)),m=(h=Ni.subscribeConnection)==null?void 0:h.call(Ni,x=>{var p;x||(p=d.current)==null||p.call(d)});return()=>{f(),m==null||m()}},[s])}const r0={tokens:"",events:[],done:!1,interrupted:!1,error:null,result:null};function $g(s){const[r,i]=b.useState(r0),o=b.useRef(null);b.useEffect(()=>{if(s===o.current)return;const m=o.current;o.current=s,s!==null?i(r0):m!==null&&i(h=>({...h,done:!1,result:null,error:null}))},[s]);const d=b.useCallback(m=>{const h=m;i(x=>{var p,v;switch(h.type){case"token":{const E=(h.depth??0)===0?x.tokens+(h.data??""):x.tokens;return{...x,tokens:E,events:[...x.events,h]}}case"done":return{...x,done:!0,result:((p=h.data)==null?void 0:p.result)??null,events:[...x.events,h]};case"error":return{...x,done:!0,error:((v=h.data)==null?void 0:v.message)||"Unknown error",events:[...x.events,h]};default:return{...x,events:[...x.events,h]}}})},[]),f=b.useCallback(()=>{i(m=>m.done?m:{...m,interrupted:!0})},[]);return Uf(s?`execution:${s}`:null,d,f),r}const i0=5*1024*1024,cS=["image/png","image/jpeg","image/webp","image/gif"];function uS(s){return typeof s=="string"&&cS.includes(s)}function dS(s){if(s.length===0||s.length%4!==0||!/^[A-Za-z0-9+/]*={0,2}$/.test(s))return;const r=s.endsWith("==")?2:s.endsWith("=")?1:0;return s.length/4*3-r}function fS({status:s}){const r=s==="succeeded"?"bg-green-100 text-green-800 dark:bg-green-950/40 dark:text-green-300":s==="running"?"bg-blue-100 text-blue-800 dark:bg-blue-950/40 dark:text-blue-300":s==="incomplete"||s==="cancelled"?"bg-amber-100 text-amber-800 dark:bg-amber-950/40 dark:text-amber-300":"bg-red-100 text-red-800 dark:bg-red-950/40 dark:text-red-300";return n.jsx("span",{className:F("px-1.5 py-0.5 text-[9px] font-medium rounded-full",r),children:s})}const hS=new Set(["tool_call_start","tool_call_rejected","handoff_start","tool_approval"]);function mS(s){var f;let r=null;const i=new Map;let o=null;const d=m=>{for(const h of[...i.keys()])h.startsWith(m+"|")&&(i.delete(h),o===h&&(o=null))};for(const m of s)if(m.type==="partial_object")r={askId:m.askId??"",object:(f=m.data)==null?void 0:f.object};else if(m.type==="string_delta"){const h=m.askId??"",x=`${h}|${m.data.path}`,p=i.get(x);i.set(x,{askId:h,path:m.data.path,accumulated:((p==null?void 0:p.accumulated)??"")+m.data.delta}),o=x}else(m.type==="pipeline"&&m.status==="failed"||m.type==="ask_end")&&d(m.askId??"");return{latestPartial:r,latestStringDelta:o?i.get(o)??null:null}}function pS({partial:s,streamingField:r}){return n.jsxs("div",{className:"space-y-2",children:[n.jsx("div",{className:"text-[10px] uppercase tracking-wide text-[hsl(var(--muted-foreground))]",children:"Streaming structured output"}),n.jsx(Ct,{data:s,defaultExpandDepth:3}),r&&r.accumulated.length>0&&n.jsxs("div",{className:"border-t border-[hsl(var(--border))] pt-2",children:[n.jsxs("div",{className:"text-[10px] uppercase tracking-wide text-[hsl(var(--muted-foreground))] mb-1",children:["Writing ",n.jsx("code",{className:"font-mono",children:r.path})]}),n.jsxs("div",{className:"whitespace-pre-wrap font-mono text-xs",children:[r.accumulated,n.jsx("span",{className:"inline-block w-1.5 h-3 ml-0.5 align-middle bg-[hsl(var(--foreground))] animate-pulse"})]})]})]})}function xS(s){if(!s)return;const r=s.trim();if(!(!r.startsWith("{")&&!r.startsWith("[")))try{return JSON.parse(r)}catch{return}}function gS(){const[s,r]=b.useState([]),[i,o]=b.useState(""),[d,f]=b.useState(null),[m,h]=b.useState(null),[x,p]=b.useState(!1),v=b.useRef(null),y=b.useRef(null),E=b.useRef(0),w=b.useRef(null),[C,_]=b.useState(null),[R,D]=b.useState(null),[H,T]=b.useState(""),[j,k]=b.useState(!1),[S,B]=b.useState(0),[$,W]=b.useState({input:0,output:0}),[K,te]=b.useState(!1),re=b.useRef(!1),Me=b.useRef(null),he=b.useRef(0),ae=b.useRef(0),{data:z=[]}=Sa({queryKey:["agents"],queryFn:G2}),L=$g(R);b.useEffect(()=>{if(L.tokens&&j&&r(X=>{const ne=X[X.length-1];return(ne==null?void 0:ne.role)==="assistant"?[...X.slice(0,-1),{...ne,content:L.tokens}]:[...X,{role:"assistant",content:L.tokens}]}),L.done&&j){if(k(!1),D(null),L.error)r(X=>{const ne=X[X.length-1];return(ne==null?void 0:ne.role)==="assistant"&&!ne.content?[...X.slice(0,-1),{role:"assistant",content:`Error: ${L.error}`}]:[...X,{role:"assistant",content:`Error: ${L.error}`}]});else if(L.result!=null){let X=null;if(typeof L.result=="string"){const we=L.result.trim();if(we.startsWith("{")||we.startsWith("["))try{X=JSON.stringify(JSON.parse(we))}catch{}}else typeof L.result=="object"&&(X=JSON.stringify(L.result));if(!(!L.tokens||X!==null))return;const ce=X??(typeof L.result=="string"?L.result:JSON.stringify(L.result));r(we=>{const Re=we[we.length-1];return(Re==null?void 0:Re.role)==="assistant"?[...we.slice(0,-1),{...Re,content:ce}]:[...we,{role:"assistant",content:ce}]})}}},[L.tokens,L.done,L.error,j]),b.useEffect(()=>{var dt,yt;const X=new Map,ne=[],ce=[],we=[];for(const pe of L.events)if(pe.type==="tool_call_start"){const Te=`${pe.executionId}\0${pe.askId}\0${pe.callId}`;X.set(Te,{name:pe.tool,args:(dt=pe.data)==null?void 0:dt.args,callId:pe.callId,executionId:pe.executionId,askId:pe.askId,startObserved:!0,status:"running"}),ne.push(Te)}else if(pe.type==="tool_call_end"){const Te=`${pe.executionId}\0${pe.askId}\0${pe.callId}`,Ie=X.get(Te);if(!Ie||Ie.status!=="rejected"){const ye={name:pe.tool,args:pe.data.args,callId:pe.callId,executionId:pe.executionId,askId:pe.askId,startObserved:Ie!=null},Je=pe.data.outcome;switch(Je.status){case"succeeded":X.set(Te,{...ye,status:"succeeded",result:Je.result});break;case"failed":X.set(Te,{...ye,status:"failed",failure:Je.failure});break;case"denied":X.set(Te,{...ye,status:"denied",reason:Je.reason});break;case"cancelled":X.set(Te,{...ye,status:"cancelled",cancellation:Je.cancellation});break}Ie||ne.push(Te)}}else if(pe.type==="tool_call_rejected"){const Te=`${pe.executionId}\0${pe.askId}\0${pe.callId}`;X.set(Te,{name:pe.tool,callId:pe.callId,executionId:pe.executionId,askId:pe.askId,status:"rejected",rejection:pe.data}),ne.push(Te)}else if(pe.type==="handoff_start"){const Te=pe.data;Te&&ce.push({source:Te.source,target:Te.target,mode:Te.mode})}else pe.type==="tool_approval"&&we.push({tool:pe.tool,approved:((yt=pe.data)==null?void 0:yt.approved)===!0});if(L.done||L.interrupted)for(const[pe,Te]of X)Te.status==="running"&&X.set(pe,{...Te,status:"incomplete"});const Re=ne.flatMap(pe=>{const Te=X.get(pe);return Te?[Te]:[]});(Re.length>0||ce.length>0||we.length>0)&&r(pe=>{const Te=pe[pe.length-1];return(Te==null?void 0:Te.role)==="assistant"?[...pe.slice(0,-1),{...Te,toolCalls:Re.length>0?Re:Te.toolCalls,handoffs:ce.length>0?ce:Te.handoffs,approvals:we.length>0?we:Te.approvals}]:pe})},[L.events,L.done,L.interrupted]),b.useEffect(()=>{const X=L.events.slice(he.current);if(X.length===0)return;he.current=L.events.length;let ne=0,ce=0,we=0;for(const Re of X)ne+=Ag(Re),Re.type==="agent_call_end"&&Re.tokens&&(ce+=Re.tokens.input??0,we+=Re.tokens.output??0);ne>0&&B(Re=>Re+ne),(ce>0||we>0)&&W(Re=>({input:Re.input+ce,output:Re.output+we}))},[L.events]),b.useEffect(()=>{if(K||re.current){ae.current=L.events.length;return}for(let X=ae.current;X<L.events.length;X++){const ne=L.events[X];if(!ne)continue;const ce="depth"in ne&&typeof ne.depth=="number"?ne.depth:0;if(hS.has(ne.type)||ce>=1){te(!0),ae.current=L.events.length;return}}ae.current=L.events.length},[L.events,K]),b.useEffect(()=>{var X;(X=Me.current)==null||X.scrollIntoView({behavior:"smooth"})},[s]);const ie=b.useCallback(X=>{var ne;E.current+=1,(ne=y.current)==null||ne.abort(),y.current=null,w.current&&URL.revokeObjectURL(w.current),w.current=null,f(null),h(X??null),p(!1),v.current&&(v.current.value="")},[]),ve=b.useCallback(()=>ie(),[ie]),ge=b.useCallback(X=>{var dt;const ne=(dt=X.target.files)==null?void 0:dt[0];if(!ne)return;if(ie(),!uS(ne.type)){h("Choose a PNG, JPEG, WebP, or GIF image.");return}const ce=ne.type;if(ne.size>i0){h("Image must be 5 MiB or smaller.");return}const we=new FileReader,Re=E.current;y.current=we,p(!0),we.onerror=()=>{Re===E.current&&(y.current=null,p(!1),h("Could not read that image."))},we.onload=()=>{if(Re!==E.current)return;y.current=null,p(!1);const pe=(typeof we.result=="string"?we.result:"").split(",",2)[1]??"",Te=dS(pe);if(Te===void 0||Te>i0){h("Could not read that image safely.");return}const Ie=URL.createObjectURL(ne);w.current=Ie,f({mediaType:ce,data:pe,previewUrl:Ie}),h(null)},we.readAsDataURL(ne)},[ie]);b.useEffect(()=>()=>{var X;E.current+=1,(X=y.current)==null||X.abort(),w.current&&URL.revokeObjectURL(w.current)},[]);const M=b.useCallback(async()=>{if(!i.trim()||j||x)return;const X=i.trim();o(""),r(ne=>[...ne,{role:"user",content:X}]),k(!0);try{const ne=d?await l0(X,C??void 0,H||void 0,{mediaType:d.mediaType,data:d.data}):await l0(X,C??void 0,H||void 0);ie(),_(ne.sessionId),D(ne.executionId)}catch(ne){k(!1),r(ce=>[...ce,{role:"assistant",content:`Error: ${ne instanceof Error?ne.message:String(ne)}`}])}},[i,j,x,C,H,d,ie]),Q=X=>{X.key==="Enter"&&!X.shiftKey&&(X.preventDefault(),M())},G=S>0||$.input>0,J=s.length,oe=b.useMemo(()=>mS(L.events),[L.events]),me=L.events.filter(X=>X.type!=="token"&&X.type!=="partial_object"&&X.type!=="string_delta"&&X.type!=="done"&&X.type!=="error"),be=n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"flex-1 overflow-auto p-3 sm:p-5 space-y-4",children:[s.length===0&&n.jsx(ta,{title:"Start a conversation",description:"Type a message below to chat with an agent. Tool calls, handoffs, and streaming responses will be displayed in real-time."}),s.map((X,ne)=>n.jsx("div",{className:`flex ${X.role==="user"?"justify-end":"justify-start"}`,children:n.jsxs("div",{className:`max-w-[80%] rounded-xl px-4 py-2.5 text-sm ${X.role==="user"?"bg-[hsl(var(--primary))] text-[hsl(var(--primary-foreground))]":"bg-[hsl(var(--secondary))] text-[hsl(var(--secondary-foreground))]"}`,children:[(()=>{const ce=X.role==="assistant"&&j&&ne===s.length-1;if(ce&&oe.latestPartial)return n.jsx(pS,{partial:oe.latestPartial.object,streamingField:oe.latestStringDelta});if(ce)return n.jsx(n2,{text:X.content});const we=X.role==="assistant"?xS(X.content):void 0;return we!==void 0?n.jsx(Ct,{data:we,defaultExpandDepth:3}):n.jsx("div",{className:"whitespace-pre-wrap",children:X.content})})(),X.handoffs&&X.handoffs.length>0&&n.jsx("div",{className:"mt-2 space-y-1 border-t border-[hsl(var(--border))] pt-2",children:X.handoffs.map((ce,we)=>n.jsxs("div",{className:"flex items-center gap-1.5 text-xs",children:[n.jsx(mr,{size:12,className:"text-amber-500"}),n.jsx("span",{className:"font-medium",children:ce.source}),n.jsx(mr,{size:10}),n.jsx("span",{className:"font-medium",children:ce.target}),n.jsxs("span",{className:"text-[hsl(var(--muted-foreground))]",children:["(",ce.mode,")"]})]},we))}),X.approvals&&X.approvals.length>0&&n.jsx("div",{className:"mt-2 space-y-1 border-t border-[hsl(var(--border))] pt-2",children:X.approvals.map((ce,we)=>n.jsxs("div",{className:"flex items-center gap-1.5 text-xs",children:[n.jsx(LN,{size:12,className:ce.approved?"text-green-500":"text-red-500"}),n.jsxs("span",{children:["Tool ",n.jsx("span",{className:"font-mono",children:ce.tool}),":"," ",ce.approved?"approved":"denied"]})]},we))}),X.toolCalls&&X.toolCalls.length>0&&n.jsx("div",{className:"mt-2 space-y-2 border-t border-[hsl(var(--border))] pt-2",children:X.toolCalls.map((ce,we)=>n.jsxs("div",{className:"text-xs",children:[n.jsxs("div",{className:"flex items-center gap-2 font-medium mb-1",children:[n.jsxs("span",{children:["Tool: ",ce.name]}),n.jsx(fS,{status:ce.status})]}),n.jsxs("div",{className:"space-y-1",children:[ce.status!=="rejected"&&n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"text-[hsl(var(--muted-foreground))]",children:"Input:"}),n.jsx(Ct,{data:ce.args,collapsed:!0})]}),ce.status!=="rejected"&&!ce.startObserved&&n.jsx("div",{className:"text-amber-600 dark:text-amber-400",children:"Terminal observed without its matching start; the trace is incomplete."}),ce.status==="succeeded"&&n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"text-[hsl(var(--muted-foreground))]",children:"Output:"}),n.jsx(Ct,{data:ce.result,collapsed:!0})]}),ce.status==="failed"&&n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"text-red-600 dark:text-red-400",children:["Failed in ",ce.failure.phase,": ",ce.failure.error.name," —"," ",ce.failure.error.message]}),"result"in ce.failure&&n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"text-[hsl(var(--muted-foreground))]",children:"Output before failure:"}),n.jsx(Ct,{data:ce.failure.result,collapsed:!0})]})]}),ce.status==="denied"&&ce.reason&&n.jsxs("div",{className:"text-red-600 dark:text-red-400",children:["Reason: ",ce.reason]}),ce.status==="cancelled"&&n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"text-amber-600 dark:text-amber-400",children:["Cancelled in ",ce.cancellation.phase,ce.cancellation.reason?`: ${ce.cancellation.reason}`:""]}),"result"in ce.cancellation&&n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"text-[hsl(var(--muted-foreground))]",children:"Output before cancellation:"}),n.jsx(Ct,{data:ce.cancellation.result,collapsed:!0})]})]}),ce.status==="incomplete"&&n.jsx("div",{className:"text-amber-600 dark:text-amber-400",children:"Trace ended before a matching tool terminal was observed."}),ce.status==="rejected"&&n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"text-red-600 dark:text-red-400",children:["Rejected before execution: ",ce.rejection.reason]}),ce.rejection.reason==="invalid_arguments"&&n.jsx(Ct,{data:{args:ce.rejection.args,issues:ce.rejection.issues},collapsed:!0})]})]})]},we))})]})},ne)),n.jsx("div",{ref:Me})]}),n.jsxs("div",{className:"border-t border-[hsl(var(--border))] p-4 shrink-0",children:[(d||m)&&n.jsxs("div",{className:"max-w-3xl mx-auto mb-2",children:[d&&n.jsxs("div",{className:"inline-flex items-center gap-2 rounded-lg border border-[hsl(var(--input))] bg-[hsl(var(--secondary))] p-1.5 text-xs text-[hsl(var(--secondary-foreground))]",children:[n.jsx("img",{src:d.previewUrl,alt:"Selected image preview",className:"h-10 w-10 rounded object-cover"}),n.jsx("span",{children:"Image attached"}),n.jsx("button",{type:"button",onClick:ve,"aria-label":"Remove selected image",className:"rounded p-1 hover:bg-[hsl(var(--background))]",children:n.jsx(Rf,{size:14})})]}),m&&n.jsx("p",{role:"alert",className:"mt-1 text-xs text-red-600 dark:text-red-400",children:m})]}),n.jsxs("div",{className:"flex items-end gap-2 max-w-3xl mx-auto",children:[n.jsx("input",{ref:v,type:"file",accept:"image/png,image/jpeg,image/webp,image/gif",className:"hidden","aria-label":"Choose image",onChange:ge}),n.jsx("button",{type:"button",onClick:()=>{var X;return(X=v.current)==null?void 0:X.click()},disabled:j||x,"aria-label":"Attach image",title:"Attach PNG, JPEG, WebP, or GIF (max 5 MiB)",className:"p-2.5 rounded-xl border border-[hsl(var(--input))] hover:bg-[hsl(var(--secondary))] disabled:opacity-50",children:n.jsx(oN,{size:16})}),n.jsx("textarea",{value:i,onChange:X=>o(X.target.value),onKeyDown:Q,placeholder:"Type a message...",rows:1,className:"flex-1 px-3 py-2.5 text-sm rounded-xl border border-[hsl(var(--input))] bg-[hsl(var(--background))] resize-none focus:outline-none focus:ring-2 focus:ring-[hsl(var(--ring))]"}),n.jsx("button",{onClick:M,disabled:!i.trim()||j||x,className:"p-2.5 rounded-xl bg-[hsl(var(--primary))] text-[hsl(var(--primary-foreground))] hover:opacity-90 disabled:opacity-50 transition-opacity",children:n.jsx(zN,{size:16})})]})]})]});return n.jsxs("div",{className:"flex flex-col h-screen",children:[n.jsx(dl,{title:"Agent Playground",description:J>0?n.jsxs(n.Fragment,{children:[n.jsxs("span",{children:[J," message",J!==1?"s":""]}),C&&n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"opacity-40 mx-1.5",children:"·"}),n.jsxs("span",{className:"font-mono",children:["session ",C.slice(0,8)]})]})]}):z.length>0?n.jsxs(n.Fragment,{children:[n.jsxs("span",{children:[z.length," registered agent",z.length!==1?"s":""]}),n.jsx("span",{className:"opacity-40 mx-1.5",children:"·"}),n.jsx("span",{children:"pick one or use the default"})]}):"Interactive chat with registered agents",actions:n.jsxs(n.Fragment,{children:[G&&n.jsxs("div",{className:"flex items-center gap-1.5",children:[S>0&&n.jsx("span",{className:"px-1.5 py-0.5 rounded text-xs font-mono bg-[hsl(var(--secondary))] text-[hsl(var(--secondary-foreground))]",children:at(S)}),$.input>0&&n.jsxs("span",{className:"px-1.5 py-0.5 rounded text-xs font-mono bg-[hsl(var(--secondary))] text-[hsl(var(--secondary-foreground))]",children:[qa($.input+$.output)," tok"]})]}),n.jsxs("button",{type:"button",onClick:()=>{te(X=>(X&&(re.current=!0),!X))},"aria-pressed":K,title:"Show execution activity (tool calls, handoffs, agent calls)",className:F("inline-flex items-center gap-1 rounded-full px-2 py-1 text-xs","ring-1 ring-[hsl(var(--input))] hover:ring-[hsl(var(--ring))]",K?"bg-[hsl(var(--secondary))] text-[hsl(var(--secondary-foreground))]":"bg-[hsl(var(--background))] text-[hsl(var(--muted-foreground))]"),children:[n.jsx(mc,{size:12}),"Activity"]}),n.jsxs("div",{className:F("inline-flex items-stretch rounded-full bg-[hsl(var(--background))]","ring-1 ring-[hsl(var(--input))] shadow-sm","hover:ring-[hsl(var(--ring))] focus-within:ring-[hsl(var(--ring))]","transition-shadow"),children:[n.jsx(ki,{items:z,value:H,onSelect:T,getKey:X=>X.name,getLabel:X=>X.name,getDescription:X=>n.jsxs(n.Fragment,{children:[n.jsx("span",{children:X.model}),X.tools.length>0&&n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"opacity-40 mx-1",children:"·"}),n.jsxs("span",{children:[X.tools.length," tool",X.tools.length!==1?"s":""]})]}),X.handoffs.length>0&&n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"opacity-40 mx-1",children:"·"}),n.jsxs("span",{children:[X.handoffs.length," handoff",X.handoffs.length!==1?"s":""]})]})]}),searchMatch:(X,ne)=>X.name.toLowerCase().includes(ne)||X.model.toLowerCase().includes(ne)||X.tools.some(ce=>ce.toLowerCase().includes(ne)),placeholder:"Default agent",searchPlaceholder:"Search agents…",emptyLabel:"No agents registered",shortcut:!0,triggerClassName:"rounded-l-full",ariaLabel:"Select an agent"}),n.jsxs("button",{onClick:()=>{ie(),r([]),_(null),D(null),B(0),W({input:0,output:0}),te(!1),re.current=!1,he.current=0,ae.current=0},className:F("inline-flex items-center gap-1.5 pl-3.5 pr-4 py-2 text-sm font-medium cursor-pointer","border-l border-[hsl(var(--input))] rounded-r-full","hover:bg-[hsl(var(--muted))] transition-colors","focus:outline-none focus-visible:bg-[hsl(var(--muted))]"),children:[n.jsx(hN,{size:12}),"New chat"]})]})]})}),K?n.jsx(jr,{className:"flex-1",left:be,right:n.jsxs("div",{className:"flex-1 overflow-y-auto p-3 sm:p-5 space-y-4",children:[n.jsx("h3",{className:"text-[11px] font-medium uppercase tracking-wider text-[hsl(var(--muted-foreground))]",children:"Activity"}),n.jsx(Dg,{events:L.events}),me.length>0?n.jsx(Di,{events:me,lifecycleEvents:L.events,traceComplete:L.done||L.interrupted,showToolbar:!1}):n.jsx("p",{className:"text-xs text-[hsl(var(--muted-foreground))]",children:"Events will appear here as the agent executes."})]})}):n.jsx("div",{className:"flex-1 min-h-0 flex flex-col",children:be})]})}function Qg({value:s,onChange:r,placeholder:i,className:o}){const[d,f]=b.useState(!1),[m,h]=b.useState(null),x=b.useRef(null),p=b.useCallback(y=>{const E=y.target.value;r(E);try{E.trim()&&JSON.parse(E),h(null)}catch(w){h(w instanceof Error?w.message:"Invalid JSON")}},[r]);b.useEffect(()=>{var y;d&&((y=x.current)==null||y.focus())},[d]);let v=null;try{v=s.trim()?JSON.parse(s):{}}catch{}return v===null||d?n.jsxs("div",{className:o,children:[n.jsx("textarea",{ref:x,value:s,onChange:p,onBlur:()=>{m||f(!1)},placeholder:i??"{}",className:"w-full h-40 p-3 text-xs font-mono rounded-xl bg-[hsl(var(--secondary))] text-[hsl(var(--foreground))] border-none resize-y focus:outline-none focus:ring-2 focus:ring-[hsl(var(--ring))]",spellCheck:!1}),m&&n.jsx("p",{className:"text-xs text-red-500 mt-1",children:m})]}):n.jsx("div",{className:o,children:n.jsxs("div",{children:[n.jsx(Ct,{data:v,maxHeight:"12rem"}),n.jsxs("button",{onClick:()=>f(!0),className:"mt-1.5 inline-flex items-center gap-1 px-2 py-1 text-[10px] font-medium rounded-md text-[hsl(var(--muted-foreground))] hover:text-[hsl(var(--foreground))] hover:bg-[hsl(var(--accent))] transition-colors cursor-pointer",children:[n.jsx(CN,{size:10}),"Edit"]})]})})}function Gg({schema:s,onSubmit:r,submitLabel:i="Submit",className:o}){const[d,f]=b.useState({}),m=s.properties??{},h=new Set(s.required??[]),x=b.useCallback(p=>{p.preventDefault();const v={};for(const[y,E]of Object.entries(m)){const w=d[y]??"";if(!(!w&&!h.has(y)))if(E.type==="number")v[y]=Number(w);else if(E.type==="boolean")v[y]=w==="true";else if(E.type==="object"||E.type==="array")try{v[y]=JSON.parse(w)}catch{v[y]=w}else v[y]=w}r(v)},[d,m,h,r]);return n.jsxs("form",{onSubmit:x,className:`space-y-3 ${o??""}`,children:[Object.entries(m).map(([p,v])=>n.jsxs("div",{children:[n.jsxs("label",{className:"block text-xs font-medium text-[hsl(var(--foreground))] mb-1",children:[p,h.has(p)&&n.jsx("span",{className:"text-red-500 ml-0.5",children:"*"}),v.description&&n.jsxs("span",{className:"text-[hsl(var(--muted-foreground))] font-normal ml-1",children:["- ",v.description]})]}),v.enum?n.jsxs("select",{value:d[p]??"",onChange:y=>f({...d,[p]:y.target.value}),className:"w-full px-2 py-1.5 text-sm rounded-md border border-[hsl(var(--input))] bg-[hsl(var(--background))]",children:[n.jsx("option",{value:"",children:"Select..."}),v.enum.map(y=>n.jsx("option",{value:y,children:y},y))]}):v.type==="boolean"?n.jsxs("select",{value:d[p]??"",onChange:y=>f({...d,[p]:y.target.value}),className:"w-full px-2 py-1.5 text-sm rounded-md border border-[hsl(var(--input))] bg-[hsl(var(--background))]",children:[n.jsx("option",{value:"",children:"Select..."}),n.jsx("option",{value:"true",children:"true"}),n.jsx("option",{value:"false",children:"false"})]}):n.jsx("input",{type:v.type==="number"?"number":"text",value:d[p]??"",onChange:y=>f({...d,[p]:y.target.value}),placeholder:v.type??"string",className:"w-full px-2 py-1.5 text-sm rounded-md border border-[hsl(var(--input))] bg-[hsl(var(--background))]"})]},p)),n.jsx("button",{type:"submit",className:"px-4 py-2 text-sm font-medium rounded-md bg-[hsl(var(--primary))] text-[hsl(var(--primary-foreground))] hover:opacity-90 transition-opacity",children:i})]})}function Yg({status:s,className:r}){return n.jsxs("span",{className:F("inline-flex items-center gap-1.5 whitespace-nowrap px-2 py-0.5 rounded-full text-xs font-medium",ZN(s),s==="running"&&"animate-pulse",r),children:[n.jsx("span",{className:F("w-1.5 h-1.5 rounded-full",s==="running"&&"bg-blue-500",s==="completed"&&"bg-green-500",s==="failed"&&"bg-red-500",s==="waiting"&&"bg-amber-500")}),s]})}function tt({label:s,value:r,subtitle:i,subtitleColor:o,accent:d,tint:f,badge:m}){return n.jsxs("div",{className:F("px-4 py-3.5 rounded-xl min-w-0",f||"bg-[hsl(var(--card))] border border-[hsl(var(--border))]"),children:[n.jsx("p",{className:"text-[11px] font-medium uppercase tracking-wider text-[hsl(var(--muted-foreground))] truncate",children:s}),m?n.jsx("div",{className:"mt-1",children:m}):n.jsx("p",{className:F("text-lg sm:text-2xl font-semibold mt-1 font-mono tracking-tight truncate select-text",d),title:r,children:r}),i&&n.jsx("p",{className:F("text-xs mt-0.5 truncate",o??"text-[hsl(var(--muted-foreground))]"),title:i,children:i})]})}function vS(s){const{events:r,askId:i,onClose:o,className:d}=s,{filtered:f,summary:m}=b.useMemo(()=>{var R;const h=r.filter(D=>"askId"in D&&D.askId===i||(D.type==="handoff_start"||D.type==="handoff_return")&&(D.fromAskId===i||D.toAskId===i)),x=h.find(D=>D.type==="ask_start"),p=h.find(D=>D.type==="ask_end"),v=(x==null?void 0:x.agent)??((R=h.find(D=>"agent"in D&&!!D.agent))==null?void 0:R.agent),y=x==null?void 0:x.prompt,E=p==null?void 0:p.cost,w=(p==null?void 0:p.unpriced)===!0,C=x&&p&&typeof x.timestamp=="number"&&typeof p.timestamp=="number"?p.timestamp-x.timestamp:void 0,_=p==null?void 0:p.outcome;return{filtered:h,summary:{agent:v,prompt:y,cost:E,unpriced:w,duration:C,outcome:_}}},[r,i]);return n.jsxs("div",{"data-testid":"ask-details","data-ask-id":i,className:F("flex flex-col h-full bg-white border-l border-slate-200 dark:bg-slate-900 dark:border-slate-700",d),children:[n.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-slate-200 dark:border-slate-700",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("span",{className:"font-medium truncate",children:m.agent??"<unknown agent>"}),n.jsx("span",{className:"text-xs font-mono text-[hsl(var(--muted-foreground))]",title:i,children:i.slice(0,8)})]}),o&&n.jsx("button",{type:"button",onClick:o,"aria-label":"Close ask details",className:"rounded p-1 hover:bg-slate-100 dark:hover:bg-slate-800",children:n.jsx(Rf,{className:"h-4 w-4"})})]}),n.jsxs("div",{className:"px-4 py-2 border-b border-slate-200 dark:border-slate-700 flex items-center gap-3 text-xs",children:[m.duration!==void 0&&n.jsx(Df,{ms:m.duration}),typeof m.cost=="number"&&n.jsx(Fa,{cost:m.cost,unpriced:m.unpriced}),m.outcome&&n.jsx("span",{className:F("inline-flex items-center rounded-full px-2 py-0.5 text-xs font-medium",m.outcome.ok?"bg-emerald-100 text-emerald-900 dark:bg-emerald-900/30 dark:text-emerald-200":"bg-red-100 text-red-900 dark:bg-red-900/30 dark:text-red-200"),children:m.outcome.ok?"ok":"failed"})]}),m.prompt&&n.jsxs("div",{className:"px-4 py-2 border-b border-slate-200 text-sm dark:border-slate-700",children:[n.jsx("div",{className:"text-xs uppercase tracking-wide text-[hsl(var(--muted-foreground))] mb-1",children:"Prompt"}),n.jsx("div",{className:"font-mono whitespace-pre-wrap break-words",children:m.prompt})]}),n.jsx("div",{className:"flex-1 overflow-auto px-2 py-2",children:f.length===0?n.jsx("div",{className:"text-sm text-[hsl(var(--muted-foreground))] py-4 text-center",children:"No events for this ask."}):n.jsx(Di,{events:f})})]})}const Kg=[{id:"24h",label:"24h"},{id:"7d",label:"7d"},{id:"30d",label:"30d"},{id:"all",label:"All"}],Vg="axl.studio.window";function bS(){try{const s=localStorage.getItem(Vg);if(s&&Kg.some(r=>r.id===s))return s}catch{}return"7d"}function yS(s){try{localStorage.setItem(Vg,s)}catch{}}function Es({value:s,onChange:r}){return n.jsx("div",{className:"inline-flex items-center gap-0.5 p-0.5 rounded-lg bg-[hsl(var(--muted))]",role:"radiogroup","aria-label":"Time window",children:Kg.map(i=>n.jsx("button",{type:"button",role:"radio","aria-checked":s===i.id,"aria-label":`Window: ${i.label}`,onClick:()=>r(i.id),className:F("px-2.5 py-1 text-xs font-medium rounded-md transition-all cursor-pointer",s===i.id?"bg-[hsl(var(--background))] text-[hsl(var(--foreground))] shadow-sm":"text-[hsl(var(--muted-foreground))] hover:text-[hsl(var(--foreground))]"),children:i.label},i.id))})}function pc(s,r){const[i,o]=b.useState(bS),[d,f]=b.useState(null),[m,h]=b.useState(null),{data:x}=Sa({queryKey:[s,i],queryFn:()=>r(i)});return Uf(s,b.useCallback(v=>{const y=v;y.snapshots&&(f(y.snapshots),typeof y.updatedAt=="number"&&h(y.updatedAt))},[])),{window:i,handleWindowChange:v=>{o(v),yS(v)},data:(d==null?void 0:d[i])??x??null,updatedAt:m}}function jS({onWorkflowClick:s,selectedWorkflow:r}={}){const{window:i,handleWindowChange:o,data:d}=pc("workflow-stats",P2),f=!d||d.totalExecutions===0,m=d?Object.entries(d.byWorkflow).sort(([,h],[,x])=>x.total-h.total):[];return f?n.jsxs("div",{className:"space-y-3 mb-5",children:[n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsx("h3",{className:"text-[11px] font-medium uppercase tracking-wider text-[hsl(var(--muted-foreground))]",children:"Workflow Stats"}),n.jsx(Es,{value:i,onChange:o})]}),n.jsxs("p",{className:"text-xs text-[hsl(var(--muted-foreground))] italic",children:["No executions in the ",i," window. Try a wider window."]})]}):n.jsxs("div",{className:"space-y-3 mb-5",children:[n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsx("h3",{className:"text-[11px] font-medium uppercase tracking-wider text-[hsl(var(--muted-foreground))]",children:"Workflow Stats"}),n.jsx(Es,{value:i,onChange:o})]}),n.jsxs("div",{className:"grid grid-cols-2 lg:grid-cols-4 gap-3",children:[n.jsx(tt,{label:"Total Executions",value:String(d.totalExecutions),subtitle:i}),n.jsx(tt,{label:"Failure Rate",value:`${(d.failureRate*100).toFixed(1)}%`,subtitle:d.failureRate>.1?"high":"normal",subtitleColor:d.failureRate>.1?"text-red-500":void 0})]}),m.length>0&&n.jsx("div",{className:"rounded-xl border border-[hsl(var(--border))] overflow-x-auto",children:n.jsxs("table",{className:"w-full text-xs min-w-[560px]",children:[n.jsx("thead",{children:n.jsxs("tr",{className:"border-b border-[hsl(var(--border))] bg-[hsl(var(--card))]",children:[n.jsx("th",{className:"py-2 px-3 text-left font-medium",children:"Workflow"}),n.jsx("th",{className:"py-2 px-3 text-right font-medium",children:"Total"}),n.jsx("th",{className:"py-2 px-3 text-right font-medium",children:"Failed"}),n.jsx("th",{className:"py-2 px-3 text-right font-medium",title:"50th percentile duration (approximate for workflows with 200+ executions)",children:"p50"}),n.jsx("th",{className:"py-2 px-3 text-right font-medium",title:"95th percentile duration (approximate for workflows with 200+ executions)",children:"p95"}),n.jsx("th",{className:"py-2 px-3 text-right font-medium",children:"Avg"})]})}),n.jsx("tbody",{children:m.map(([h,x])=>n.jsxs("tr",{onClick:s?()=>s(h):void 0,className:F("border-b last:border-b-0 border-[hsl(var(--border))]",s&&"cursor-pointer hover:bg-[hsl(var(--accent))]",r===h&&"bg-[hsl(var(--accent))]"),title:s?"Click to select this workflow":void 0,children:[n.jsx("td",{className:"py-2 px-3 font-mono",children:h}),n.jsx("td",{className:"py-2 px-3 text-right",children:x.total}),n.jsx("td",{className:"py-2 px-3 text-right",children:x.failed>0?n.jsx("span",{className:"text-red-500",children:x.failed}):"0"}),n.jsx("td",{className:"py-2 px-3 text-right font-mono",children:x.durationP50!=null?xt(x.durationP50):"—"}),n.jsx("td",{className:"py-2 px-3 text-right font-mono",children:x.durationP95!=null?xt(x.durationP95):"—"}),n.jsx("td",{className:"py-2 px-3 text-right font-mono",children:xt(x.avgDuration)})]},h))})]})})]})}function NS(){const[s,r]=b.useState(""),[i,o]=b.useState("{}"),[d,f]=b.useState(!0),[m,h]=b.useState(null),[x,p]=b.useState(void 0),[v,y]=b.useState(null),[E,w]=b.useState("idle"),[C,_]=b.useState("run"),[R,D]=b.useState("tree"),[H,T]=b.useState(void 0),{data:j=[]}=Sa({queryKey:["workflows"],queryFn:U2}),{data:k}=Sa({queryKey:["workflow",s],queryFn:()=>L2(s),enabled:!!s}),S=$g(m),B=b.useCallback(async L=>{if(s){p(void 0),y(null),w("running");try{const ie=await H2(s,L,!0);ie.streaming&&ie.executionId?h(ie.executionId):(p(ie.result),w("completed"))}catch(ie){y(ie instanceof Error?ie.message:String(ie)),w("failed")}}},[s]),$=b.useCallback(()=>{try{const L=JSON.parse(i);B(L)}catch(L){y(L instanceof Error?L.message:String(L)),w("failed")}},[i,B]),W=b.useCallback(L=>{r(L),o("{}"),p(void 0),y(null),w("idle")},[]),K=j.find(L=>L.name===s),te=b.useCallback(L=>{B(L)},[B]);b.useEffect(()=>{S.done&&E==="running"&&(w(S.error?"failed":"completed"),S.error&&y(S.error),S.result!==void 0&&p(S.result),h(null))},[S.done,S.error,S.result,E]);const re=S.events,Me=!!(k!=null&&k.inputSchema),he=Math.max(...re.map(L=>L.duration??0),1),ae=re.reduce((L,ie)=>L+(ie.duration??0),0),z=re.reduce((L,ie)=>L+Ag(ie),0);return n.jsxs("div",{className:"flex flex-col h-screen",children:[n.jsx(dl,{title:"Workflow Runner",description:K?n.jsxs(n.Fragment,{children:[n.jsx("span",{children:K.name}),(K.hasInputSchema||K.hasOutputSchema)&&n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"opacity-40 mx-1.5",children:"·"}),n.jsxs("span",{children:[K.hasInputSchema&&"input schema",K.hasInputSchema&&K.hasOutputSchema&&" · ",K.hasOutputSchema&&"output schema"]})]})]}):j.length>0?`${j.length} registered workflow${j.length!==1?"s":""} · select one to run`:"No workflows registered",actions:j.length>0&&n.jsxs("div",{className:F("inline-flex items-stretch rounded-full bg-[hsl(var(--background))] shrink-0","ring-1 ring-[hsl(var(--input))] shadow-sm","hover:ring-[hsl(var(--ring))] focus-within:ring-[hsl(var(--ring))]","transition-shadow"),children:[n.jsx(ki,{items:j,value:s,onSelect:W,getKey:L=>L.name,getLabel:L=>L.name,getDescription:L=>{const ie=[];return L.hasInputSchema&&ie.push("input schema"),L.hasOutputSchema&&ie.push("output schema"),ie.length>0?ie.join(" · "):"no schema"},placeholder:"Select workflow",searchPlaceholder:"Search workflows…",emptyLabel:"No workflows registered",shortcut:!0,triggerClassName:"rounded-l-full",ariaLabel:"Select a workflow"}),n.jsxs("button",{onClick:$,disabled:!s||E==="running",className:F("inline-flex items-center gap-1.5 pl-3.5 pr-4 py-2 text-sm font-medium cursor-pointer","bg-[hsl(var(--foreground))] text-[hsl(var(--background))] rounded-r-full","hover:opacity-90 focus:outline-none focus-visible:ring-2 focus-visible:ring-offset-1 focus-visible:ring-[hsl(var(--foreground))]","disabled:opacity-40 disabled:cursor-not-allowed transition-opacity"),children:[n.jsx(_f,{size:12,className:F("fill-current",E==="running"&&"animate-spin fill-none")}),E==="running"?"Running…":"Run"]})]})}),n.jsx("div",{role:"tablist","aria-label":"Workflow Runner views",className:"shrink-0 flex items-center gap-1 px-4 sm:px-6 border-b border-[hsl(var(--border))]",children:["run","stats"].map(L=>n.jsx("button",{type:"button",role:"tab","aria-selected":C===L,onClick:()=>_(L),className:F("px-3 py-2.5 text-sm -mb-px border-b-2 transition-colors cursor-pointer",C===L?"border-[hsl(var(--foreground))] text-[hsl(var(--foreground))] font-medium":"border-transparent text-[hsl(var(--muted-foreground))] hover:text-[hsl(var(--foreground))]"),children:L.charAt(0).toUpperCase()+L.slice(1)},L))}),C==="stats"&&n.jsx("div",{className:"flex-1 min-h-0 overflow-auto p-3 sm:p-5",children:n.jsx(jS,{onWorkflowClick:L=>{W(L),_("run")},selectedWorkflow:s})}),C==="run"&&n.jsx(jr,{className:"flex-1",defaultPercent:30,minPercent:15,maxPercent:50,left:n.jsxs("div",{className:"flex-1 overflow-y-auto p-3 sm:p-5 space-y-4",children:[Me&&n.jsxs("div",{className:"flex items-center gap-1",children:[n.jsx("button",{onClick:()=>f(!0),className:F("px-3 py-1 text-xs rounded-lg transition-colors",d?"bg-[hsl(var(--foreground))] text-[hsl(var(--background))]":"text-[hsl(var(--muted-foreground))] hover:bg-[hsl(var(--accent))]"),children:"Form"}),n.jsx("button",{onClick:()=>f(!1),className:F("px-3 py-1 text-xs rounded-lg transition-colors",d?"text-[hsl(var(--muted-foreground))] hover:bg-[hsl(var(--accent))]":"bg-[hsl(var(--foreground))] text-[hsl(var(--background))]"),children:"JSON"})]}),Me&&d?n.jsx(Gg,{schema:k.inputSchema,onSubmit:te,submitLabel:E==="running"?"Running…":"Execute"}):n.jsxs("div",{children:[n.jsx("label",{className:"block text-[11px] font-medium uppercase tracking-wider text-[hsl(var(--muted-foreground))] mb-2",children:"Input (JSON)"}),n.jsx(Qg,{value:i,onChange:o})]}),(k==null?void 0:k.outputSchema)!=null&&n.jsxs("div",{children:[n.jsx("label",{className:"block text-[11px] font-medium uppercase tracking-wider text-[hsl(var(--muted-foreground))] mb-2",children:"Output Schema"}),n.jsx(Ct,{data:k.outputSchema,collapsed:!0})]})]}),right:n.jsx("div",{className:"flex-1 overflow-y-auto p-3 sm:p-5",children:E==="idle"?n.jsx("div",{className:"flex items-center justify-center h-full",children:n.jsx(ta,{icon:n.jsx(pr,{size:32}),title:"No execution",description:"Select a workflow and click Run to see results."})}):n.jsxs("div",{className:"space-y-5",children:[n.jsxs("div",{className:"grid grid-cols-2 lg:grid-cols-4 gap-3",children:[n.jsx(tt,{label:"Status",badge:n.jsx(Yg,{status:E})}),n.jsx(tt,{label:"Steps",value:String(re.length)}),n.jsx(tt,{label:"Duration",value:ae>0?xt(ae):"—"}),n.jsx(tt,{label:"Cost",value:z>0?at(z):"—"})]}),v&&n.jsx("div",{className:"p-4 rounded-xl bg-red-50 dark:bg-red-950/30 border border-red-200 dark:border-red-800 text-red-700 dark:text-red-300 text-sm",children:v}),x!==void 0&&n.jsxs("div",{children:[n.jsx("h3",{className:"text-[11px] font-medium uppercase tracking-wider text-[hsl(var(--muted-foreground))] mb-2",children:"Result"}),n.jsx(Ct,{data:x})]}),re.length>0&&n.jsxs("div",{children:[n.jsxs("div",{className:"flex items-center justify-between mb-2",children:[n.jsx("h3",{className:"text-[11px] font-medium uppercase tracking-wider text-[hsl(var(--muted-foreground))]",children:"Timeline"}),n.jsxs("div",{className:"flex gap-1 text-xs",children:[n.jsx("button",{type:"button",onClick:()=>D("tree"),className:F("px-2 py-0.5 rounded",R==="tree"?"bg-[hsl(var(--secondary))] text-[hsl(var(--secondary-foreground))]":"text-[hsl(var(--muted-foreground))] hover:bg-[hsl(var(--secondary))]/50"),children:"Tree"}),n.jsx("button",{type:"button",onClick:()=>D("flat"),className:F("px-2 py-0.5 rounded",R==="flat"?"bg-[hsl(var(--secondary))] text-[hsl(var(--secondary-foreground))]":"text-[hsl(var(--muted-foreground))] hover:bg-[hsl(var(--secondary))]/50"),children:"Flat"})]})]}),R==="tree"?n.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-[minmax(0,1fr)_360px] gap-3 max-w-[960px]",children:[n.jsx(Dg,{events:re,selectedAskId:H,onSelectAsk:T}),H&&n.jsx(vS,{events:re,askId:H,onClose:()=>T(void 0),className:"max-h-[600px] rounded border border-slate-200 dark:border-slate-700"})]}):n.jsx(Di,{events:re,maxDuration:he,traceComplete:S.done||S.interrupted})]}),E==="running"&&re.length===0&&n.jsxs("div",{className:"flex items-center justify-center py-12 text-sm text-[hsl(var(--muted-foreground))]",children:[n.jsx(pr,{size:16,className:"animate-pulse mr-2"}),"Executing workflow…"]})]})})})]})}function o0({data:s,maxBars:r,defaultColor:i="hsl(var(--primary))",formatValue:o=f=>String(f),className:d}){const f=[...s].sort((x,p)=>p.value-x.value),m=r?f.slice(0,r):f,h=m.length>0?Math.max(...m.map(x=>x.value)):1;return m.length===0?n.jsx("p",{className:F("text-xs text-[hsl(var(--muted-foreground))]",d),children:"No data"}):n.jsx("div",{className:F("space-y-1",d),children:m.map(x=>{const p=h>0?x.value/h*100:0;return n.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[n.jsx("div",{className:"w-24 truncate font-mono text-[hsl(var(--muted-foreground))]",title:x.label,children:x.label}),n.jsx("div",{className:"relative flex-1 h-5 rounded bg-[hsl(var(--muted))]",children:n.jsx("div",{className:"absolute inset-y-0 left-0 rounded",style:{width:`${p}%`,backgroundColor:x.color??i,opacity:.7}})}),n.jsx("div",{className:"w-12 text-right font-mono tabular-nums",children:o(x.value)})]},x.label)})})}function Po({data:s,maxBars:r,formatValue:i=f=>String(f),showLegend:o=!0,className:d}){const m=[...s.map(v=>({...v,total:v.segments.reduce((y,E)=>y+E.value,0)}))].sort((v,y)=>y.total-v.total),h=r?m.slice(0,r):m,x=h.length>0?Math.max(...h.map(v=>v.total)):1;if(h.length===0)return n.jsx("p",{className:F("text-xs text-[hsl(var(--muted-foreground))]",d),children:"No data"});const p=new Map;for(const v of h)for(const y of v.segments)p.has(y.name)||p.set(y.name,y.color);return n.jsxs("div",{className:F("space-y-2",d),children:[o&&p.size>0&&n.jsx("div",{className:"flex flex-wrap gap-3 text-[10px] text-[hsl(var(--muted-foreground))]",children:Array.from(p.entries()).map(([v,y])=>n.jsxs("div",{className:"flex items-center gap-1",children:[n.jsx("span",{className:"inline-block h-2 w-2 rounded-full",style:{backgroundColor:y}}),n.jsx("span",{children:v})]},v))}),n.jsx("div",{className:"space-y-1",children:h.map(v=>{const y=x>0?v.total/x*100:0;return n.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[n.jsx("div",{className:"w-24 truncate font-mono text-[hsl(var(--muted-foreground))]",title:v.label,children:v.label}),n.jsx("div",{className:"relative flex-1 h-5 rounded bg-[hsl(var(--muted))] overflow-hidden",children:n.jsx("div",{className:"absolute inset-y-0 left-0 flex",style:{width:`${y}%`},children:v.segments.map((E,w)=>{const C=v.total>0?E.value/v.total*100:0;return n.jsx("div",{style:{width:`${C}%`,backgroundColor:E.color,opacity:.75},title:`${E.name}: ${E.value}`},`${E.name}-${w}`)})})}),n.jsx("div",{className:"w-12 text-right font-mono tabular-nums",children:i(v.total)})]},v.label)})})]})}const Ld={schema:"#f59e0b",validate:"#eab308",guardrail:"#ef4444"},SS={agent_call:"#3b82f6",tool_call:"#10b981",tool_call_rejected:"#ef4444",tool_approval:"#14b8a6",tool_denied:"#ef4444",workflow_start:"#8b5cf6",workflow_end:"#6366f1",log:"#64748b",guardrail:"#dc2626",schema_check:"#f59e0b",validate:"#eab308",delegate:"#ec4899",handoff:"#f97316",verify:"#06b6d4"};function wS(s){return SS[s]??"#64748b"}function kS(){const{window:s,handleWindowChange:r,data:i}=pc("trace-stats",eS);if(!i||i.totalEvents===0)return n.jsxs("div",{className:"p-6",children:[n.jsxs("div",{className:"flex items-center justify-between mb-6",children:[n.jsx("h3",{className:"text-sm font-medium",children:"Trace Stats"}),n.jsx(Es,{value:s,onChange:r})]}),n.jsx(ta,{icon:n.jsx(Gj,{size:32}),title:"No trace stats yet",description:"Execute workflows to see trace statistics."})]});const o=Object.entries(i.eventTypeCounts).sort(([,p],[,v])=>v-p),d=Object.entries(i.byTool).sort(([,p],[,v])=>v.accepted+v.legacy.calls-(p.accepted+p.legacy.calls)),f=Object.entries(i.retryByAgent).filter(([,p])=>p.schema+p.validate+p.guardrail>0),m=o.map(([p,v])=>({label:p,value:v,color:wS(p)})),h=d.filter(([,p])=>p.accepted>0).map(([p,v])=>({label:p,value:v.accepted})),x=f.map(([p,v])=>({label:p,segments:[{name:"schema",value:v.schema,color:Ld.schema},{name:"validate",value:v.validate,color:Ld.validate},{name:"guardrail",value:v.guardrail,color:Ld.guardrail}].filter(y=>y.value>0)}));return n.jsxs("div",{className:"p-6 space-y-6",children:[n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsx("h3",{className:"text-sm font-medium",children:"Trace Stats"}),n.jsx(Es,{value:s,onChange:r})]}),n.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-3",children:[n.jsx(tt,{label:"Total Events",value:String(i.totalEvents),subtitle:s}),n.jsx(tt,{label:"Event Types",value:String(o.length),subtitle:"distinct types"}),n.jsx(tt,{label:"Tools Used",value:String(d.length),subtitle:d.length===1?"tool":"tools"})]}),n.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[n.jsxs("div",{className:"rounded-xl border border-[hsl(var(--border))] p-4",children:[n.jsx("h4",{className:"text-sm font-medium mb-3",children:"Event Type Distribution"}),n.jsx(o0,{data:m,formatValue:p=>p.toString()})]}),n.jsxs("div",{className:"rounded-xl border border-[hsl(var(--border))] p-4",children:[n.jsxs("h4",{className:"text-sm font-medium mb-3",children:["Accepted Tool Calls"," ",h.length>10&&n.jsx("span",{className:"text-[10px] text-[hsl(var(--muted-foreground))]",children:"(top 10)"})]}),h.length===0?n.jsx("p",{className:"text-xs text-[hsl(var(--muted-foreground))]",children:"No accepted v2 tool calls in window"}):n.jsx(o0,{data:h,maxBars:10})]}),d.some(([,p])=>p.succeeded+p.failed+p.denied+p.cancelled+p.rejected>0)&&n.jsxs("div",{className:"lg:col-span-2 rounded-xl border border-[hsl(var(--border))] p-4",children:[n.jsx("h4",{className:"text-sm font-medium mb-3",children:"Tool Lifecycle Outcomes (v2)"}),n.jsx(Po,{data:d.filter(([,p])=>p.succeeded+p.failed+p.denied+p.cancelled+p.rejected>0).map(([p,v])=>({label:p,segments:[{name:"succeeded",value:v.succeeded,color:"#10b981"},{name:"failed",value:v.failed,color:"#ef4444"},{name:"denied",value:v.denied,color:"#dc2626"},{name:"cancelled",value:v.cancelled,color:"#f59e0b"},{name:"rejected",value:v.rejected,color:"#be123c"}].filter(y=>y.value>0)})),formatValue:p=>p.toString()})]}),d.some(([,p])=>p.legacy.calls+p.legacy.approved+p.legacy.denied>0)&&n.jsxs("div",{className:"lg:col-span-2 rounded-xl border border-amber-500/30 bg-amber-500/5 p-4",children:[n.jsx("h4",{className:"text-sm font-medium mb-1",children:"Legacy Tool Lifecycle (v1)"}),n.jsx("p",{className:"text-xs text-[hsl(var(--muted-foreground))] mb-3",children:"Historical call, approval, and denial counts are kept separate because v1 did not record the v2 terminal outcome union."}),n.jsx(Po,{data:d.filter(([,p])=>p.legacy.calls+p.legacy.approved+p.legacy.denied>0).map(([p,v])=>({label:p,segments:[{name:"legacy calls",value:v.legacy.calls,color:"#64748b"},{name:"legacy approved",value:v.legacy.approved,color:"#059669"},{name:"legacy denied",value:v.legacy.denied,color:"#b91c1c"}].filter(y=>y.value>0)})),formatValue:p=>p.toString()})]}),f.length>0&&n.jsxs("div",{className:"lg:col-span-2 rounded-xl border border-[hsl(var(--border))] p-4",children:[n.jsx("h4",{className:"text-sm font-medium mb-3",children:"Retries by Agent"}),n.jsx(Po,{data:x,formatValue:p=>p.toString()})]}),d.some(([,p])=>p.approved+p.denied>0)&&n.jsxs("div",{className:"lg:col-span-2 rounded-xl border border-[hsl(var(--border))] p-4",children:[n.jsx("h4",{className:"text-sm font-medium mb-3",children:"Tool Approvals / Denials"}),n.jsx(Po,{data:d.filter(([,p])=>p.approved+p.denied>0).map(([p,v])=>({label:p,segments:[{name:"approved",value:v.approved,color:"#10b981"},{name:"denied",value:v.denied,color:"#ef4444"}].filter(y=>y.value>0)})),formatValue:p=>p.toString()})]})]})]})}const CS={running:"border-l-blue-500",completed:"border-l-green-500",failed:"border-l-red-500"};function ES(s){const r=new Date(s),i=new Date;return r.getFullYear()===i.getFullYear()&&r.getMonth()===i.getMonth()&&r.getDate()===i.getDate()?r.toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit",second:"2-digit"}):r.toLocaleDateString(void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}function TS(s){switch(s.reason){case"branch_drain_timeout":return`Trace incomplete: terminal finalization stopped after ${s.timeoutMs} ms with ${s.pendingContinuations} branch continuations still running.`;case"queue_overflow":return`Trace incomplete: ${s.droppedEvents} queued events were dropped.`;case"persistence_truncated":return`Trace incomplete: persisted events were truncated at ${s.maxEvents} entries.`;case"process_interrupted":return"Trace incomplete: the process terminated before the execution reached a terminal boundary."}}function MS(){var j;const[s,r]=b.useState("events"),[i,o]=b.useState(null),[d,f]=b.useState([]),[m,h]=b.useState(""),[x,p]=b.useState(""),{data:v=[],refetch:y}=Sa({queryKey:["executions"],queryFn:q2,refetchInterval:3e3});Uf("trace:*",b.useCallback(k=>{f(S=>[...S.slice(-200),k])},[]));const E=i?i.events:d;let w=E;m&&(w=w.filter(k=>k.type===m)),x&&(w=w.filter(k=>k.agent===x));const C=b.useMemo(()=>[...new Set(E.map(k=>k.type))].sort(),[E]),_=b.useMemo(()=>[...new Set(E.map(k=>k.agent).filter(k=>!!k))].sort(),[E]),R=b.useMemo(()=>[{value:"",label:"All types"},...C.map(k=>({value:k,label:k}))],[C]),D=b.useMemo(()=>[{value:"",label:"All agents"},..._.map(k=>({value:k,label:k}))],[_]),H=Math.max(...w.map(k=>k.duration??0),1),T=b.useMemo(()=>{if(!i)return null;const k=[...new Set(i.events.map(S=>S.model).filter(Boolean))];return{duration:i.duration,eventCount:i.events.length,cost:i.totalCost,models:k}},[i]);return n.jsxs("div",{className:"flex flex-col h-screen",children:[n.jsx(dl,{title:"Trace Explorer",description:i?n.jsxs(n.Fragment,{children:[n.jsx("span",{children:i.workflow}),n.jsx("span",{className:"opacity-40 mx-1.5",children:"·"}),n.jsx("span",{className:"font-mono",children:i.executionId.slice(0,8)}),n.jsx("span",{className:"opacity-40 mx-1.5",children:"·"}),n.jsxs("span",{children:[i.events.length," event",i.events.length!==1?"s":""]})]}):n.jsxs(n.Fragment,{children:[v.length," execution",v.length!==1?"s":"",n.jsx("span",{className:"opacity-40 mx-1.5",children:"·"}),d.length," live event",d.length!==1?"s":""]}),actions:n.jsxs(n.Fragment,{children:[n.jsx(ki,{items:R,value:m,onSelect:h,getKey:k=>k.value,getLabel:k=>k.label,placeholder:"All types",searchPlaceholder:"Filter types…",variant:"filter",triggerClassName:F("rounded-full shadow-sm ring-1 transition-shadow",m?"ring-[hsl(var(--foreground))] text-[hsl(var(--foreground))] font-medium":"ring-[hsl(var(--input))]"),ariaLabel:"Filter by event type"}),_.length>0&&n.jsx(ki,{items:D,value:x,onSelect:p,getKey:k=>k.value,getLabel:k=>k.label,placeholder:"All agents",searchPlaceholder:"Filter agents…",variant:"filter",triggerClassName:F("rounded-full shadow-sm ring-1 transition-shadow",x?"ring-[hsl(var(--foreground))] text-[hsl(var(--foreground))] font-medium":"ring-[hsl(var(--input))]"),ariaLabel:"Filter by agent"}),n.jsxs("button",{onClick:()=>{y(),f([])},className:F("inline-flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium rounded-full cursor-pointer","ring-1 ring-[hsl(var(--input))] bg-[hsl(var(--background))] shadow-sm","hover:bg-[hsl(var(--muted))] hover:ring-[hsl(var(--ring))]","focus:outline-none focus-visible:ring-[hsl(var(--ring))] transition-all"),children:[n.jsx(AN,{size:12}),"Refresh"]})]})}),n.jsx("div",{role:"tablist","aria-label":"Trace views",className:"shrink-0 flex items-center gap-1 px-4 sm:px-6 border-b border-[hsl(var(--border))]",children:["events","stats"].map(k=>n.jsx("button",{type:"button",role:"tab","aria-selected":s===k,onClick:()=>r(k),className:F("px-3 py-2.5 text-sm -mb-px border-b-2 transition-colors cursor-pointer",s===k?"border-[hsl(var(--foreground))] text-[hsl(var(--foreground))] font-medium":"border-transparent text-[hsl(var(--muted-foreground))] hover:text-[hsl(var(--foreground))]"),children:k.charAt(0).toUpperCase()+k.slice(1)},k))}),s==="stats"&&n.jsx("div",{className:"flex-1 min-h-0 overflow-auto",children:n.jsx(kS,{})}),s==="events"&&n.jsx(jr,{className:"flex-1",defaultPercent:25,minPercent:15,maxPercent:40,left:n.jsxs("div",{className:"flex-1 overflow-y-auto p-4 sm:p-6 space-y-2",children:[n.jsx("h3",{className:"text-sm font-medium mb-2",children:"Executions"}),n.jsxs("button",{onClick:()=>{o(null)},className:F("w-full text-left px-3 py-2 text-xs rounded-xl border",i?"border-[hsl(var(--border))] hover:bg-[hsl(var(--accent))]":"border-[hsl(var(--primary))] bg-[hsl(var(--accent))]"),children:["Live Events (",d.length,")"]}),v.map(k=>n.jsxs("button",{onClick:()=>{o(k)},className:F("w-full text-left px-3 py-2.5 text-xs rounded-xl border border-l-[3px] transition-colors",CS[k.status]??"border-l-slate-400",(i==null?void 0:i.executionId)===k.executionId?"border-[hsl(var(--primary))] bg-[hsl(var(--accent))]":"border-[hsl(var(--border))] hover:bg-[hsl(var(--accent))]"),children:[n.jsxs("div",{className:"flex items-center justify-between gap-2",children:[n.jsx("span",{className:"font-medium truncate",children:k.workflow}),n.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[e0(k)===1&&n.jsx("span",{className:"rounded bg-amber-500/15 px-1.5 py-0.5 text-[9px] font-medium text-amber-600 dark:text-amber-400",title:"Legacy v1 lifecycle semantics",children:"legacy v1"}),n.jsx(Yg,{status:k.status})]})]}),n.jsxs("div",{className:"flex items-center justify-between mt-1",children:[n.jsxs("span",{className:"text-[hsl(var(--muted-foreground))] truncate",children:[k.executionId.slice(0,8),"… | ",k.events.length," events"]}),(k.totalCost>0||k.unpriced)&&n.jsx(Fa,{cost:k.totalCost,unpriced:k.unpriced})]}),n.jsxs("div",{className:"flex items-center gap-2 mt-1 text-[10px] text-[hsl(var(--muted-foreground))]",children:[n.jsx("span",{children:ES(k.startedAt)}),k.duration>0&&n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"text-[hsl(var(--border))]",children:"·"}),n.jsx("span",{children:xt(k.duration)})]})]})]},k.executionId)),v.length===0&&n.jsx("p",{className:"text-xs text-[hsl(var(--muted-foreground))]",children:"No executions yet"})]}),right:n.jsxs("div",{className:"flex-1 overflow-y-auto p-4 sm:p-6",children:[T&&n.jsxs("div",{className:"grid grid-cols-2 lg:grid-cols-4 gap-3 mb-4",children:[n.jsx(tt,{label:"Duration",value:xt(T.duration)}),n.jsx(tt,{label:"Events",value:String(T.eventCount)}),n.jsx(tt,{label:"Cost",value:T.cost>0?at(T.cost):"—"}),n.jsx(tt,{label:"Model",value:T.models.length>0?T.models[0]:"—",subtitle:T.models.length>1?`+${T.models.length-1} more`:void 0})]}),i&&e0(i)===1&&n.jsx("div",{className:"mb-4 rounded-lg border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-xs text-amber-700 dark:text-amber-300",children:"Legacy v1 lifecycle: tool outcomes retain their historical semantics and may contain unmatched starts."}),((j=i==null?void 0:i.observation)==null?void 0:j.complete)===!1&&n.jsx("div",{className:"mb-4 rounded-lg border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-xs text-amber-700 dark:text-amber-300",children:TS(i.observation)}),(i==null?void 0:i.status)==="completed"&&i.result!=null&&n.jsxs("div",{className:"mb-4",children:[n.jsx("h3",{className:"text-[11px] font-medium uppercase tracking-wider text-[hsl(var(--muted-foreground))] mb-2",children:"Result"}),n.jsx(Ct,{data:i.result})]}),w.length===0?n.jsx(ta,{icon:n.jsx(mc,{size:32}),title:"No trace events",description:"Execute a workflow to see trace events here."}):n.jsx(Di,{events:w,lifecycleEvents:E,traceComplete:i?i.status!=="running":void 0,maxDuration:H})]})})]})}function sf({title:s,description:r,actions:i,children:o}){return n.jsxs("div",{className:"flex flex-col h-screen",children:[n.jsx(dl,{title:s,description:r,actions:i}),n.jsx("main",{className:"flex-1 overflow-auto p-4 sm:p-6",children:o})]})}function c0({tokens:s,label:r,className:i}){return n.jsxs("span",{className:`inline-flex items-center gap-1 whitespace-nowrap px-1.5 py-0.5 rounded text-xs font-mono bg-[hsl(var(--secondary))] text-[hsl(var(--secondary-foreground))] ${i??""}`,children:[r&&n.jsx("span",{className:"text-[hsl(var(--muted-foreground))]",children:r}),qa(s)]})}function AS(s,r){const i=Math.max(0,r-s);return i<1e3?"just now":i<6e4?`${Math.floor(i/1e3)}s ago`:i<36e5?`${Math.floor(i/6e4)}m ago`:`${Math.floor(i/36e5)}h ago`}function _S(){const{window:s,handleWindowChange:r,data:i,updatedAt:o}=pc("costs",I2),[d,f]=b.useState(()=>Date.now());if(b.useEffect(()=>{const j=setInterval(()=>f(Date.now()),1e3);return()=>clearInterval(j)},[]),!i)return n.jsx(sf,{title:"Cost Dashboard",description:"Spending across agents, models, and workflows",actions:n.jsx(Es,{value:s,onChange:r}),children:n.jsx(ta,{icon:n.jsx(Ng,{size:32}),title:"No cost data",description:"Execute workflows to see cost data."})});const m=i.totalTokens.reasoning>0,h=Object.keys(i.byAgent).length,x=Object.keys(i.byModel).length,p=Object.values(i.byWorkflow).reduce((j,k)=>j+k.executions,0),v=i.retry??{primary:0,primaryCalls:0,schema:0,schemaCalls:0,validate:0,validateCalls:0,guardrail:0,guardrailCalls:0,retryCalls:0},y=v.schema+v.validate+v.guardrail,E=i.totalCost>0?y/i.totalCost*100:0,w=i.byEmbedder??{},C=Object.entries(w),_=C.reduce((j,[,k])=>j+k.cost,0),R=C.reduce((j,[,k])=>j+k.calls,0),D=C.reduce((j,[,k])=>j+(k.unpricedCalls??0),0),H=C.reduce((j,[,k])=>j+k.tokens,0),T=i.totalCost>0?_/i.totalCost*100:0;return n.jsxs(sf,{title:"Cost Dashboard",description:i.totalCost>0?n.jsxs(n.Fragment,{children:[n.jsxs("span",{children:[at(i.totalCost)," total"]}),n.jsx("span",{className:"opacity-40 mx-1.5",children:"·"}),n.jsxs("span",{children:[h," agent",h!==1?"s":""]}),n.jsx("span",{className:"opacity-40 mx-1.5",children:"·"}),n.jsxs("span",{children:[x," model",x!==1?"s":""]})]}):"Spending across agents, models, and workflows",actions:n.jsx(Es,{value:s,onChange:r}),children:[n.jsxs("div",{className:F("grid grid-cols-1 sm:grid-cols-2 gap-3 mb-8",m?"lg:grid-cols-4":"lg:grid-cols-3"),children:[n.jsx(tt,{label:"Total Cost",value:i.unpricedCalls>0?`≥ ${at(i.totalCost)}`:at(i.totalCost),subtitle:i.unpricedCalls>0?`${s} · lower bound (${i.unpricedCalls} unpriced call${i.unpricedCalls!==1?"s":""})`:s}),n.jsx(tt,{label:"Input Tokens",value:qa(i.totalTokens.input),subtitle:"prompt"}),n.jsx(tt,{label:"Output Tokens",value:qa(i.totalTokens.output),subtitle:"completion"}),m&&n.jsx(tt,{label:"Reasoning Tokens",value:qa(i.totalTokens.reasoning),subtitle:"thinking"})]}),n.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[n.jsxs("div",{children:[n.jsx("h3",{className:"text-sm font-medium mb-3",children:"Cost by Agent"}),Object.keys(i.byAgent).length===0?n.jsx("p",{className:"text-xs text-[hsl(var(--muted-foreground))]",children:"No agent data"}):n.jsx(yi,{columns:[{label:"Agent",sortKey:j=>j.agent,render:j=>n.jsx("span",{className:"font-mono",children:j.agent})},{label:"Calls",sortKey:j=>j.calls,render:j=>n.jsx("span",{children:j.calls})},{label:"Cost",sortKey:j=>j.cost,render:j=>n.jsx(Fa,{cost:j.cost,unpriced:j.unpricedCalls>0})}],rows:Object.entries(i.byAgent).map(([j,k])=>({agent:j,cost:k.cost,calls:k.calls,unpricedCalls:k.unpricedCalls??0})),rowKey:j=>j.agent,defaultSort:{index:2,dir:"desc"},costValue:j=>j.cost})]}),n.jsxs("div",{children:[n.jsx("h3",{className:"text-sm font-medium mb-3",children:"Cost by Model"}),Object.keys(i.byModel).length===0?n.jsx("p",{className:"text-xs text-[hsl(var(--muted-foreground))]",children:"No model data"}):n.jsx(yi,{columns:[{label:"Model",sortKey:j=>j.model,render:j=>n.jsx("span",{className:"font-mono",children:j.model})},{label:"Calls",sortKey:j=>j.calls,render:j=>n.jsx("span",{children:j.calls})},{label:"Tokens",sortKey:j=>j.tokens,render:j=>n.jsx(c0,{tokens:j.tokens})},{label:"Cost",sortKey:j=>j.cost,render:j=>n.jsx(Fa,{cost:j.cost,unpriced:j.unpricedCalls>0})}],rows:Object.entries(i.byModel).map(([j,k])=>({model:j,calls:k.calls,tokens:k.tokens.input+k.tokens.output,cost:k.cost,unpricedCalls:k.unpricedCalls??0})),rowKey:j=>j.model,defaultSort:{index:3,dir:"desc"},costValue:j=>j.cost})]}),n.jsxs("div",{className:"lg:col-span-2",children:[n.jsx("h3",{className:"text-sm font-medium mb-3",children:"Cost by Workflow"}),Object.keys(i.byWorkflow).length===0?n.jsx("p",{className:"text-xs text-[hsl(var(--muted-foreground))]",children:"No workflow data"}):n.jsx(yi,{columns:[{label:"Workflow",sortKey:j=>j.workflow,render:j=>n.jsx("span",{className:"font-mono",children:j.workflow})},{label:"Executions",sortKey:j=>j.executions,render:j=>n.jsx("span",{children:j.executions})},{label:"Total Cost",sortKey:j=>j.cost,render:j=>n.jsx(Fa,{cost:j.cost,unpriced:j.unpricedCalls>0})},{label:"Avg Cost",sortKey:j=>j.avgCost,render:j=>n.jsx(Fa,{cost:j.avgCost,unpriced:j.unpricedCalls>0})}],rows:Object.entries(i.byWorkflow).map(([j,k])=>({workflow:j,executions:k.executions,cost:k.cost,avgCost:k.executions>0?k.cost/k.executions:0,unpricedCalls:k.unpricedCalls??0})),rowKey:j=>j.workflow,defaultSort:{index:2,dir:"desc"},costValue:j=>j.cost})]}),C.length>0&&n.jsxs("div",{className:"lg:col-span-2",children:[n.jsxs("div",{className:"flex items-baseline justify-between mb-3",children:[n.jsx("h3",{className:"text-sm font-medium",children:"Memory (Embedder)"}),n.jsxs("span",{className:"text-xs text-[hsl(var(--muted-foreground))]",children:[D>0?`≥ ${at(_)}`:at(_)," ","across ",R," call",R!==1?"s":"",n.jsx("span",{className:"opacity-40 mx-1.5",children:"·"}),qa(H)," tokens",T>0&&n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"opacity-40 mx-1.5",children:"·"}),T.toFixed(1),"% of total"]})]})]}),n.jsx(yi,{columns:[{label:"Embedder Model",sortKey:j=>j.model,render:j=>n.jsx("span",{className:"font-mono",children:j.model})},{label:"Calls",sortKey:j=>j.calls,render:j=>n.jsx("span",{children:j.calls})},{label:"Tokens",sortKey:j=>j.tokens,render:j=>n.jsx(c0,{tokens:j.tokens})},{label:"Cost",sortKey:j=>j.cost,render:j=>n.jsx(Fa,{cost:j.cost,unpriced:j.unpricedCalls>0})}],rows:C.map(([j,k])=>({model:j,calls:k.calls,tokens:k.tokens,cost:k.cost,unpricedCalls:k.unpricedCalls??0})),rowKey:j=>j.model,defaultSort:{index:3,dir:"desc"},costValue:j=>j.cost})]}),(y>0||v.retryCalls>0)&&n.jsxs("div",{className:"lg:col-span-2",children:[n.jsxs("div",{className:"flex items-baseline justify-between mb-3",children:[n.jsx("h3",{className:"text-sm font-medium",children:"Retry Overhead"}),n.jsxs("span",{className:"text-xs text-[hsl(var(--muted-foreground))]",children:[at(y)," across ",v.retryCalls," retry call",v.retryCalls!==1?"s":"",E>0&&n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"opacity-40 mx-1.5",children:"·"}),E.toFixed(1),"% of total"]})]})]}),n.jsx(yi,{columns:[{label:"Reason",sortKey:j=>j.reason,render:j=>j.reasonLabel},{label:"Calls",sortKey:j=>j.calls,render:j=>n.jsx("span",{children:j.calls})},{label:"Cost",sortKey:j=>j.cost,render:j=>n.jsx(Fa,{cost:j.cost})}],rows:[{reason:"primary",reasonLabel:n.jsx("span",{className:"text-[hsl(var(--muted-foreground))]",children:"primary (first attempt)"}),calls:v.primaryCalls,cost:v.primary},{reason:"schema",reasonLabel:n.jsx("span",{className:"font-mono text-teal-600 dark:text-teal-400",children:"schema retry"}),calls:v.schemaCalls,cost:v.schema},{reason:"validate",reasonLabel:n.jsx("span",{className:"font-mono text-teal-600 dark:text-teal-400",children:"validate retry"}),calls:v.validateCalls,cost:v.validate},{reason:"guardrail",reasonLabel:n.jsx("span",{className:"font-mono text-rose-600 dark:text-rose-400",children:"guardrail retry"}),calls:v.guardrailCalls,cost:v.guardrail}],rowKey:j=>j.reason,defaultSort:{index:2,dir:"desc"},costValue:j=>j.cost})]})]}),n.jsxs("div",{className:"mt-6 pt-3 border-t border-[hsl(var(--border))] text-[11px] text-[hsl(var(--muted-foreground))] flex items-center gap-2 flex-wrap",children:[n.jsxs("span",{children:["Window: ",n.jsx("span",{className:"font-mono",children:s})]}),n.jsx("span",{className:"opacity-40",children:"·"}),n.jsxs("span",{children:["Last updated: ",o!=null?AS(o,d):"pending"]}),n.jsx("span",{className:"opacity-40",children:"·"}),n.jsxs("span",{children:[p," execution",p!==1?"s":""," in window"]})]})]})}function yi({columns:s,rows:r,rowKey:i,defaultSort:o,costValue:d}){const f=(o==null?void 0:o.index)??s.findIndex(C=>C.sortKey!==void 0),m=(o==null?void 0:o.dir)??"desc",[h,x]=b.useState(f),[p,v]=b.useState(m),y=b.useMemo(()=>{const C=s[h];if(!(C!=null&&C.sortKey))return r;const _=C.sortKey,R=[...r];return R.sort((D,H)=>{const T=_(D),j=_(H);if(typeof T=="number"&&typeof j=="number")return p==="asc"?T-j:j-T;const k=String(T),S=String(j);return p==="asc"?k.localeCompare(S):S.localeCompare(k)}),R},[r,s,h,p]),E=b.useMemo(()=>{if(!d)return 0;let C=0;for(const _ of r){const R=d(_);R>C&&(C=R)}return C},[r,d]),w=C=>{s[C].sortKey&&(h===C?v(_=>_==="desc"?"asc":"desc"):(x(C),v("desc")))};return n.jsx("div",{className:"rounded-xl border border-[hsl(var(--border))] overflow-x-auto",children:n.jsxs("table",{className:"w-full text-xs min-w-[480px]",children:[n.jsx("thead",{children:n.jsx("tr",{className:"border-b border-[hsl(var(--border))] bg-[hsl(var(--card))]",children:s.map((C,_)=>{const R=C.align??(_===0?"left":"right"),D=C.sortKey!==void 0,H=D&&h===_,T=H?p==="asc"?" ↑":" ↓":"";return n.jsxs("th",{"aria-sort":H?p==="asc"?"ascending":"descending":void 0,className:F("py-2 px-3 font-medium",R==="left"?"text-left":"text-right",D&&"cursor-pointer select-none hover:text-[hsl(var(--foreground))]",D&&!H&&"text-[hsl(var(--muted-foreground))]"),onClick:D?()=>w(_):void 0,title:D?"Click to sort":void 0,children:[C.label,T]},C.label)})})}),n.jsx("tbody",{children:y.map(C=>{const _=d?d(C):0;return n.jsx("tr",{className:"border-b last:border-b-0 border-[hsl(var(--border))]",children:s.map((R,D)=>{const H=R.align??(D===0?"left":"right");return n.jsxs("td",{className:F("py-2 px-3 relative",H==="left"?"text-left":"text-right"),children:[D===s.length-1&&E>0&&n.jsx("div",{className:"absolute inset-y-0 right-0 bg-[hsl(var(--primary)/0.08)] rounded-sm",style:{width:`${_/E*100}%`}}),n.jsx("span",{className:"relative",children:R.render(C)})]},R.label)})},i(C))})})]})})}function OS(){const[s,r]=b.useState("session"),[i,o]=b.useState(""),[d,f]=b.useState("{}"),[m,h]=b.useState(!1),[x,p]=b.useState(""),[v,y]=b.useState(null),[E,w]=b.useState(null),C=_i(),{data:_=[]}=Sa({queryKey:["memory",s],queryFn:()=>X2(s)}),R=ef({mutationFn:({key:k,value:S})=>F2(s,k,S),onSuccess:()=>{C.invalidateQueries({queryKey:["memory",s]}),h(!1),o(""),f("{}")}}),D=ef({mutationFn:k=>Z2(s,k),onSuccess:()=>{C.invalidateQueries({queryKey:["memory",s]}),w(null)}}),H=b.useCallback(async()=>{if(!x.trim())return;const k=await J2(x,s);y(k.results)},[x,s]),T=b.useCallback(()=>{if(i.trim())try{const k=JSON.parse(d);R.mutate({key:i,value:k})}catch{R.mutate({key:i,value:d})}},[i,d,R]),j=b.useCallback(k=>{E===k?D.mutate(k):w(k)},[E,D]);return n.jsxs(sf,{title:"Memory Browser",description:_.length>0?n.jsxs(n.Fragment,{children:[n.jsxs("span",{children:[_.length," entr",_.length!==1?"ies":"y"]}),n.jsx("span",{className:"opacity-40 mx-1.5",children:"·"}),n.jsxs("span",{children:[s," scope"]})]}):"Key-value entries stored via ctx.remember()",actions:n.jsxs("button",{type:"button",onClick:()=>h(!m),className:F("inline-flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium rounded-full cursor-pointer","bg-[hsl(var(--foreground))] text-[hsl(var(--background))] shadow-sm","hover:opacity-90 focus:outline-none focus-visible:ring-2 focus-visible:ring-[hsl(var(--ring))]","transition-opacity"),children:[n.jsx(wg,{size:12}),"Add entry"]}),children:[n.jsxs("div",{role:"tablist","aria-label":"Memory scope",className:"flex items-center gap-0 mb-4 border-b border-[hsl(var(--border))]",children:[["session","global"].map(k=>n.jsx("button",{type:"button",role:"tab","aria-selected":s===k,onClick:()=>{r(k),y(null),w(null)},className:F("px-3 py-2.5 text-sm -mb-px border-b-2 transition-colors",s===k?"border-[hsl(var(--foreground))] text-[hsl(var(--foreground))] font-medium":"border-transparent text-[hsl(var(--muted-foreground))] hover:text-[hsl(var(--foreground))]"),children:k.charAt(0).toUpperCase()+k.slice(1)},k)),n.jsx("div",{className:"flex-1"}),n.jsxs("div",{className:"flex items-center gap-1 -mb-px pb-2",children:[n.jsx("input",{value:x,onChange:k=>p(k.target.value),onKeyDown:k=>k.key==="Enter"&&H(),placeholder:"Semantic search...",className:"px-2 py-1.5 text-sm rounded-md border border-[hsl(var(--input))] bg-[hsl(var(--background))] w-48"}),n.jsx("button",{onClick:H,className:"p-1.5 rounded-md hover:bg-[hsl(var(--accent))]",children:n.jsx(nf,{size:14})})]})]}),m&&n.jsxs("div",{className:"mb-4 p-4 rounded-xl border border-[hsl(var(--border))] bg-[hsl(var(--card))] space-y-3",children:[n.jsx("input",{value:i,onChange:k=>o(k.target.value),placeholder:"Key",className:"w-full px-2 py-1.5 text-sm rounded-md border border-[hsl(var(--input))] bg-[hsl(var(--background))]"}),n.jsx(Qg,{value:d,onChange:f,placeholder:"Value (JSON)"}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("button",{onClick:T,disabled:!i.trim(),className:"px-3 py-1.5 text-sm rounded-md bg-[hsl(var(--primary))] text-[hsl(var(--primary-foreground))] hover:opacity-90 disabled:opacity-50",children:"Save"}),n.jsx("button",{onClick:()=>h(!1),className:"px-3 py-1.5 text-sm rounded-md border border-[hsl(var(--input))] hover:bg-[hsl(var(--accent))]",children:"Cancel"})]})]}),v&&n.jsxs("div",{className:"mb-4 p-4 rounded-xl border border-[hsl(var(--border))] bg-[hsl(var(--card))]",children:[n.jsx("h3",{className:"text-sm font-medium mb-2",children:"Search Results"}),v.length===0?n.jsx("p",{className:"text-xs text-[hsl(var(--muted-foreground))]",children:"No results found"}):n.jsx(Ct,{data:v})]}),_.length===0?n.jsx(ta,{icon:n.jsx(gg,{size:32}),title:"No memory entries",description:`No entries in the ${s} scope. Use ctx.remember() in workflows or add entries manually.`}):n.jsx("div",{className:"space-y-2",children:_.map(k=>n.jsxs("div",{className:"p-3 rounded-xl border border-[hsl(var(--border))] bg-[hsl(var(--card))]",children:[n.jsxs("div",{className:"flex items-center justify-between mb-2",children:[n.jsx("span",{className:"text-sm font-mono font-medium",children:k.key}),n.jsx("div",{className:"flex items-center gap-1",children:E===k.key?n.jsxs(n.Fragment,{children:[n.jsx("button",{onClick:()=>j(k.key),className:"px-2 py-0.5 text-xs rounded bg-[hsl(var(--destructive))] text-[hsl(var(--destructive-foreground))]",children:"Confirm"}),n.jsx("button",{onClick:()=>w(null),className:"px-2 py-0.5 text-xs rounded border border-[hsl(var(--input))] hover:bg-[hsl(var(--accent))]",children:"Cancel"})]}):n.jsx("button",{onClick:()=>j(k.key),className:"p-1 rounded hover:bg-[hsl(var(--destructive))] hover:text-[hsl(var(--destructive-foreground))] text-[hsl(var(--muted-foreground))]",children:n.jsx(Of,{size:14})})})]}),n.jsx(Ct,{data:k.value,collapsed:!0})]},k.key))})]})}function RS(s){try{return JSON.parse(s)}catch{return s}}function DS(s){switch(s.type){case"text":return`Text: ${s.characters} characters`;case"image":case"audio":{const r=s.type==="image"?"Image":"Audio",i=s.mediaType?` (${s.mediaType})`:"",o=s.bytes!==void 0?`, ${s.bytes} bytes`:"";return`${r}: ${s.source}${i}${o}`}default:return`Unknown part: ${String(s.type)}`}}function zS(s,r){if(typeof s!="string")return n.jsxs("div",{className:"space-y-1 text-xs text-[hsl(var(--muted-foreground))]",children:[n.jsx("div",{children:"Rich model input"}),s.parts.map((i,o)=>n.jsx("div",{children:DS(i)},o))]});if(r==="assistant"){const i=s.trim();if(i.startsWith("{")||i.startsWith("["))try{const o=JSON.parse(i);return n.jsx(Ct,{data:o,collapsed:!0})}catch{}}return n.jsx("div",{className:"whitespace-pre-wrap",children:s})}function US(){const[s,r]=b.useState(null),[i,o]=b.useState(null),[d,f]=b.useState(null),[m,h]=b.useState(null),x=_i(),{data:p=[]}=Sa({queryKey:["sessions"],queryFn:B2,refetchInterval:5e3}),{data:v}=Sa({queryKey:["session",s],queryFn:()=>$2(s),enabled:!!s}),y=ef({mutationFn:Q2,onSuccess:()=>{x.invalidateQueries({queryKey:["sessions"]}),r(null),f(null)}}),E=v!=null&&v.history?i!==null?v.history.slice(0,i+1):v.history:[];return n.jsxs("div",{className:"flex flex-col h-screen",children:[n.jsx(dl,{title:"Session Manager",description:p.length>0?s&&v?n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"font-mono",children:v.id.slice(0,16)}),n.jsx("span",{className:"opacity-40 mx-1.5",children:"·"}),n.jsxs("span",{children:[v.history.length," message",v.history.length!==1?"s":""]})]}):n.jsxs(n.Fragment,{children:[n.jsxs("span",{children:[p.length," active session",p.length!==1?"s":""]}),n.jsx("span",{className:"opacity-40 mx-1.5",children:"·"}),n.jsx("span",{children:"select one to replay"})]}):"Multi-turn conversations tracked via runtime.session()"}),n.jsx(jr,{className:"flex-1",defaultPercent:33,minPercent:20,maxPercent:50,left:n.jsxs("div",{className:"flex-1 overflow-y-auto p-4 sm:p-6 space-y-2",children:[n.jsxs("h3",{className:"text-sm font-medium mb-2",children:["Sessions (",p.length,")"]}),p.length===0?n.jsx(ta,{icon:n.jsx(Cg,{size:24}),title:"No sessions",description:"Sessions are created when using runtime.session()"}):p.map(w=>n.jsxs("button",{onClick:()=>{r(w.id),o(null)},className:`w-full text-left px-3 py-2.5 text-xs rounded-xl border transition-colors ${s===w.id?"border-[hsl(var(--primary))] bg-[hsl(var(--accent))]":"border-[hsl(var(--border))] hover:bg-[hsl(var(--accent))]"}`,children:[n.jsx("div",{className:"font-mono truncate text-[11px]",title:w.id,children:w.id}),n.jsxs("div",{className:"flex items-center gap-1.5 text-[hsl(var(--muted-foreground))] mt-1",children:[n.jsx(Sg,{size:11}),n.jsxs("span",{children:[w.messageCount," message",w.messageCount!==1?"s":""]})]})]},w.id))]}),right:n.jsx("div",{className:"flex-1 overflow-y-auto p-4 sm:p-6",children:v?n.jsxs("div",{className:"space-y-4",children:[n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsxs("div",{children:[n.jsx("h3",{className:"text-sm font-medium font-mono",children:v.id}),n.jsxs("p",{className:"text-xs text-[hsl(var(--muted-foreground))]",children:[v.history.length," messages"]})]}),d===v.id?n.jsxs("div",{className:"flex items-center gap-1.5",children:[n.jsx("button",{onClick:()=>y.mutate(v.id),className:"px-2 py-1 text-xs rounded-md bg-red-600 text-white hover:bg-red-700 dark:bg-red-700 dark:hover:bg-red-800",children:"Confirm"}),n.jsx("button",{onClick:()=>f(null),className:"px-2 py-1 text-xs rounded-md border border-[hsl(var(--border))] hover:bg-[hsl(var(--accent))]",children:"Cancel"})]}):n.jsxs("button",{onClick:()=>f(v.id),className:"flex items-center gap-1 px-2 py-1 text-xs rounded-md border border-red-300 text-red-600 hover:bg-red-50 dark:border-red-800 dark:text-red-400 dark:hover:bg-red-950",children:[n.jsx(Of,{size:12}),"Delete"]})]}),v.handoffHistory&&v.handoffHistory.length>0&&n.jsxs("div",{children:[n.jsx("h4",{className:"text-xs font-medium mb-2",children:"Handoff Chain"}),n.jsx("div",{className:"flex items-center gap-1 flex-wrap",children:v.handoffHistory.map((w,C)=>n.jsxs("div",{className:"flex items-center gap-1",children:[n.jsx("span",{className:"px-2 py-0.5 text-xs rounded bg-blue-100 dark:bg-blue-900 text-blue-700 dark:text-blue-300",children:w.source}),n.jsx(mr,{size:12,className:"text-[hsl(var(--muted-foreground))]"}),n.jsx("span",{className:"px-2 py-0.5 text-xs rounded bg-blue-100 dark:bg-blue-900 text-blue-700 dark:text-blue-300",children:w.target}),n.jsxs("span",{className:"text-xs text-[hsl(var(--muted-foreground))]",children:["(",w.mode,")"]}),C<v.handoffHistory.length-1&&n.jsx("span",{className:"mx-1 text-[hsl(var(--muted-foreground))]",children:"|"})]},C))})]}),v.history.length>1&&n.jsxs("div",{className:"rounded-xl border border-[hsl(var(--border))] p-3",children:[n.jsxs("div",{className:"flex items-center justify-between mb-2",children:[n.jsx("label",{className:"text-xs font-medium",children:"Replay"}),n.jsx("span",{className:"text-xs text-[hsl(var(--muted-foreground))] font-mono",children:i!==null?`${i+1} / ${v.history.length}`:`${v.history.length} / ${v.history.length}`})]}),n.jsx("input",{type:"range",min:0,max:v.history.length-1,value:i??v.history.length-1,onChange:w=>o(Number(w.target.value)),className:"w-full h-1.5 rounded-full appearance-none cursor-pointer bg-[hsl(var(--secondary))] [&::-webkit-slider-thumb]:appearance-none [&::-webkit-slider-thumb]:w-3.5 [&::-webkit-slider-thumb]:h-3.5 [&::-webkit-slider-thumb]:rounded-full [&::-webkit-slider-thumb]:bg-[hsl(var(--primary))] [&::-webkit-slider-thumb]:shadow-sm [&::-moz-range-thumb]:w-3.5 [&::-moz-range-thumb]:h-3.5 [&::-moz-range-thumb]:rounded-full [&::-moz-range-thumb]:bg-[hsl(var(--primary))] [&::-moz-range-thumb]:border-0"}),n.jsxs("div",{className:"flex justify-between mt-1",children:[n.jsx("span",{className:"text-[10px] text-[hsl(var(--muted-foreground))]",children:"Start"}),n.jsx("span",{className:"text-[10px] text-[hsl(var(--muted-foreground))]",children:"Latest"})]})]}),n.jsx("div",{className:"space-y-3",children:E.map((w,C)=>{const _=m!==null&&w.role==="assistant"&&w.agent!==m;return n.jsxs("div",{className:`p-3 rounded-xl text-sm transition-opacity ${_?"opacity-30":""} ${w.role==="user"?"bg-[hsl(var(--primary))] text-[hsl(var(--primary-foreground))] ml-8":w.role==="assistant"?"bg-[hsl(var(--secondary))] mr-8":"bg-[hsl(var(--muted))] text-xs font-mono"}`,children:[n.jsxs("div",{className:"text-xs font-medium mb-1 flex items-center gap-1.5",children:[n.jsx("span",{className:"opacity-70",children:w.role}),w.agent&&n.jsx("button",{type:"button",onClick:()=>h(m===w.agent?null:w.agent??null),className:`px-1.5 py-0.5 rounded font-mono text-[10px] truncate max-w-[12rem] cursor-pointer transition-colors ${m===w.agent?"bg-[hsl(var(--primary))] text-[hsl(var(--primary-foreground))]":"bg-[hsl(var(--muted))] text-[hsl(var(--muted-foreground))] hover:bg-[hsl(var(--accent))] hover:text-[hsl(var(--accent-foreground))]"}`,title:m===w.agent?"Click to clear filter":`Click to highlight messages from ${w.agent}`,children:w.agent})]}),zS(w.content,w.role),w.tool_calls&&w.tool_calls.length>0&&n.jsx("div",{className:"mt-2 space-y-1",children:w.tool_calls.map(R=>n.jsxs("details",{className:"text-xs",children:[n.jsx("summary",{className:"cursor-pointer font-mono",children:R.function.name}),n.jsx(Ct,{data:RS(R.function.arguments),collapsed:!0})]},R.id))})]},C)})})]}):n.jsx(ta,{title:"Select a session",description:"Click a session to view its history"})})})]})}function LS(){const[s,r]=b.useState(null),[i,o]=b.useState(void 0),[d,f]=b.useState(null),[m,h]=b.useState(!1),[x,p]=b.useState(!1),{data:v=[]}=Sa({queryKey:["tools"],queryFn:Y2}),{data:y}=Sa({queryKey:["tool",s],queryFn:()=>K2(s),enabled:!!s}),E=b.useCallback(async C=>{if(s){o(null),f(null),h(!0);try{const _=await V2(s,C);o(_.result)}catch(_){f(_ instanceof Error?_.message:String(_))}finally{h(!1)}}},[s]),w=v.find(C=>C.name===s);return n.jsxs("div",{className:"flex flex-col h-screen",children:[n.jsx(dl,{title:"Tool Inspector",description:w?n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"font-mono",children:w.name}),w.description&&n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"opacity-40 mx-1.5",children:"·"}),n.jsx("span",{children:w.description})]})]}):v.length>0?n.jsxs(n.Fragment,{children:[n.jsxs("span",{className:"whitespace-nowrap",children:[v.length," registered tool",v.length!==1?"s":""]}),n.jsx("span",{className:"opacity-40 mx-1.5",children:"·"}),n.jsx("span",{children:"select one to inspect"})]}):"Registered tools with schemas and direct testing"}),n.jsx(jr,{className:"flex-1",defaultPercent:33,minPercent:20,maxPercent:50,left:n.jsx("div",{className:"flex-1 overflow-y-auto p-4 sm:p-6",children:n.jsxs("div",{className:"space-y-2",children:[n.jsxs("h3",{className:"text-sm font-medium mb-2",children:["Tools (",v.length,")"]}),v.length===0?n.jsx(ta,{icon:n.jsx(Eg,{size:24}),title:"No tools",description:"Register tools with runtime.registerTool()"}):v.map(C=>n.jsxs("button",{onClick:()=>{r(C.name),o(void 0),f(null),p(!1)},className:`w-full text-left px-3 py-2 text-xs rounded-xl border ${s===C.name?"border-[hsl(var(--primary))] bg-[hsl(var(--accent))]":"border-[hsl(var(--border))] hover:bg-[hsl(var(--accent))]"}`,children:[n.jsx("div",{className:"font-medium",children:C.name}),n.jsx("div",{className:"text-[hsl(var(--muted-foreground))] mt-0.5 truncate",children:C.description}),n.jsxs("div",{className:"flex items-center gap-1.5 mt-1",children:[C.sensitive&&n.jsx("span",{className:"px-1 py-0.5 rounded bg-amber-100 dark:bg-amber-900 text-amber-700 dark:text-amber-300 text-[10px]",children:"sensitive"}),C.requireApproval&&n.jsx("span",{className:"px-1 py-0.5 rounded bg-blue-100 dark:bg-blue-900 text-blue-700 dark:text-blue-300 text-[10px]",children:"approval"})]})]},C.name))]})}),right:n.jsx("div",{className:"flex-1 overflow-y-auto p-4 sm:p-6",children:s?y?n.jsxs("div",{className:"space-y-6",children:[n.jsxs("div",{children:[n.jsx("h3",{className:"text-lg font-medium",children:y.name}),n.jsx("p",{className:"text-sm text-[hsl(var(--muted-foreground))]",children:y.description})]}),n.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[y.sensitive&&n.jsx("span",{className:"px-2 py-1 text-xs rounded-md bg-amber-100 dark:bg-amber-900 text-amber-700 dark:text-amber-300",children:"Sensitive"}),y.requireApproval&&n.jsx("span",{className:"px-2 py-1 text-xs rounded-md bg-blue-100 dark:bg-blue-900 text-blue-700 dark:text-blue-300",children:"Requires Approval"}),y.retry.attempts&&y.retry.attempts>1&&n.jsxs("span",{className:"px-2 py-1 text-xs rounded-md bg-green-100 dark:bg-green-900 text-green-700 dark:text-green-300",children:["Retry: ",y.retry.attempts,"x ",y.retry.backoff]}),y.hasHooks&&y.hooks&&n.jsxs("span",{className:"px-2 py-1 text-xs rounded-md bg-purple-100 dark:bg-purple-900 text-purple-700 dark:text-purple-300",children:["Hooks:"," ",[y.hooks.hasBefore&&"before",y.hooks.hasAfter&&"after"].filter(Boolean).join(" + ")]})]}),n.jsxs("div",{children:[n.jsxs("button",{onClick:()=>p(!x),className:"flex items-center gap-1.5 text-sm font-medium text-[hsl(var(--muted-foreground))] hover:text-[hsl(var(--foreground))] transition-colors",children:[n.jsx(Ba,{size:14,className:F("transition-transform",x&&"rotate-90")}),"View raw schema"]}),x&&n.jsx("div",{className:"mt-2",children:n.jsx(Ct,{data:y.inputSchema})})]}),n.jsxs("div",{children:[n.jsx("h4",{className:"text-sm font-medium mb-2",children:"Test Tool"}),n.jsx("div",{className:"rounded-xl border border-[hsl(var(--border))] p-4 bg-[hsl(var(--card))]",children:n.jsx(Gg,{schema:y.inputSchema,onSubmit:E,submitLabel:m?"Running...":"Run Tool"})})]}),i!==void 0&&n.jsxs("div",{children:[n.jsx("h4",{className:"text-sm font-medium mb-2",children:"Result"}),n.jsx("div",{className:"rounded-xl border border-[hsl(var(--border))] p-4 bg-[hsl(var(--card))]",children:n.jsx(Ct,{data:i})})]}),d&&n.jsx("div",{className:"p-3 rounded-xl bg-red-50 dark:bg-red-950 border border-red-200 dark:border-red-800 text-red-700 dark:text-red-300 text-sm",children:d})]}):n.jsxs("div",{className:"flex items-center gap-2 text-sm text-[hsl(var(--muted-foreground))]",children:[n.jsx(dN,{size:16,className:"animate-spin"}),"Loading tool details..."]}):n.jsx(ta,{title:"Select a tool",description:"Click a tool to view its schema and test it"})})})]})}const cc={status:"idle",evalRunId:null,evalName:null,runCount:1,startedAt:null,progress:null,done:null,error:null},HS=300*1e3;let Kt=cc;const lf=new Set;let lc=null,Pl=null;function Ka(s){Kt=s;for(const r of lf)r()}function qS(){return Kt}function BS(s){return lf.add(s),()=>lf.delete(s)}function er(){lc&&(lc(),lc=null),Pl&&(clearTimeout(Pl),Pl=null)}function u0(){Pl&&clearTimeout(Pl),Pl=setTimeout(()=>{Kt.status==="running"&&(Ka({...Kt,status:"error",error:"Lost contact with the server — no progress received. The eval may still be running; check the History tab."}),er())},HS)}function $S(){return b.useSyncExternalStore(BS,qS)}async function QS(s,r,i=!1){if(Kt.status==="running"&&Kt.evalRunId)try{await Bg(Kt.evalRunId)}catch{}er(),Ka({...cc,status:"running",evalName:s,runCount:r,startedAt:Date.now()});let o;try{o=(await nS(s,{runs:r,captureTraces:i})).evalRunId}catch(d){Ka({...cc,status:"error",error:d instanceof Error?d.message:String(d)});return}Ka({...Kt,evalRunId:o}),u0(),lc=Ni.subscribe(`eval:${o}`,d=>{var m;const f=d;switch(u0(),f.type){case"item_done":{const h=f.itemIndex,x=f.totalItems,p=typeof f.run=="number"?f.run:1,v=typeof f.totalRuns=="number"?f.totalRuns:1;Ka({...Kt,progress:{completedItems:h+1,totalItems:x,completedRuns:p-1,totalRuns:v}});break}case"run_done":{const h=f.run,x=f.totalRuns;Ka({...Kt,progress:{completedItems:0,totalItems:((m=Kt.progress)==null?void 0:m.totalItems)??0,completedRuns:h,totalRuns:x}});break}case"done":{const h=typeof f.evalResultId=="string"?f.evalResultId:null,x=typeof f.runGroupId=="string"?f.runGroupId:void 0;Ka(h?{...Kt,status:"done",done:x?{evalResultId:h,runGroupId:x}:{evalResultId:h}}:{...Kt,status:"error",error:"Eval completed without a result id — cannot adopt from history."}),er();break}case"error":Ka({...Kt,status:"error",error:f.message}),er();break}})}async function GS(){if(Kt.evalRunId)try{await Bg(Kt.evalRunId)}catch{}Ka({...Kt,status:"error",error:"Cancelled"}),er()}function d0(){Ka(cc),er()}function YS({series:s,xMin:r,xMax:i,yMin:o,yMax:d,yDomain:f,yClamp:m,height:h=160,padding:x={top:8,right:8,bottom:20,left:32},formatX:p=C=>String(C),formatY:v=C=>C.toFixed(2),onPointClick:y,ariaLabel:E,className:w}){const[C,_]=b.useState(null),[R,D]=b.useState({width:480,height:h}),H=(f==null?void 0:f.strategy)??"data",T=(f==null?void 0:f.minSpan)??.1,j=(f==null?void 0:f.padPct)??.1;let k,S;if(H==="fixed"||o!=null&&d!=null)k=o??0,S=d??1;else{const ae=[];for(const z of s)for(const L of z.points)Number.isFinite(L.y)&&ae.push(L.y);if(ae.length===0)k=o??0,S=d??1;else{let z=Math.min(...ae),L=Math.max(...ae);if(L-z<T){const Q=(z+L)/2;z=Q-T/2,L=Q+T/2}const ve=Math.max(T,L-z)*j;let ge=z-ve,M=L+ve;(m==null?void 0:m.min)!=null&&(ge=Math.max(ge,m.min)),(m==null?void 0:m.max)!=null&&(M=Math.min(M,m.max)),k=o??ge,S=d??M}}const B=Math.max(1,R.width-x.left-x.right),$=Math.max(1,R.height-x.top-x.bottom),W=Math.max(1,i-r),K=Math.max(.001,S-k),te=ae=>x.left+(ae-r)/W*B,re=ae=>x.top+$-(ae-k)/K*$,Me=ae=>{const z=ae.currentTarget.getBoundingClientRect(),L=ae.clientX-z.left,ie=r+(L-x.left)/B*W;let ve=null,ge=1/0;for(const G of s)for(const J of G.points){const oe=Math.abs(J.x-ie);oe<ge&&(ge=oe,ve={series:G,point:J})}if(!ve)return;const M=ve.point.x,Q=[];for(const G of s){const J=G.points.find(oe=>oe.x===M);J&&Q.push({series:G,point:J})}_({x:M,points:Q})},he=[k,k+(S-k)*.25,k+(S-k)*.5,k+(S-k)*.75,S];return n.jsxs("div",{className:F("relative w-full",w),ref:ae=>{ae&&ae.clientWidth>0&&ae.clientWidth!==R.width&&D({width:ae.clientWidth,height:h})},children:[n.jsxs("svg",{width:"100%",height:R.height,viewBox:`0 0 ${R.width} ${R.height}`,preserveAspectRatio:"none",role:"img","aria-label":E??`Line chart with ${s.length} series and ${s.reduce((ae,z)=>ae+z.points.length,0)} data points.`,onMouseMove:Me,onMouseLeave:()=>_(null),onClick:y&&C&&C.points.length>0?()=>{const ae=C.points[0];y(ae.series,ae.point)}:void 0,className:F("block",y&&C&&C.points.length>0&&"cursor-pointer"),children:[he.map(ae=>n.jsxs("g",{children:[n.jsx("line",{x1:x.left,x2:R.width-x.right,y1:re(ae),y2:re(ae),stroke:"currentColor",strokeOpacity:.08,strokeDasharray:"2 3"}),n.jsx("text",{x:x.left-4,y:re(ae)+3,textAnchor:"end",fontSize:9,fill:"currentColor",fillOpacity:.5,children:v(ae)})]},ae)),(()=>{const ae=C?new Set(C.points.map(z=>z.series.name)):null;return s.map(z=>{const L=[...z.points].filter(ge=>Number.isFinite(ge.x)&&Number.isFinite(ge.y)).sort((ge,M)=>ge.x-M.x);if(L.length===0)return null;const ie=L.map((ge,M)=>`${M===0?"M":"L"} ${te(ge.x).toFixed(2)} ${re(ge.y).toFixed(2)}`).join(" "),ve=!ae||ae.has(z.name);return n.jsxs("g",{style:{opacity:ve?1:.2,transition:"opacity 120ms ease-out"},children:[n.jsx("path",{d:ie,stroke:z.color,strokeWidth:ve&&ae?2:1.5,fill:"none"}),L.map((ge,M)=>ge.partial?n.jsx("circle",{cx:te(ge.x),cy:re(ge.y),r:3,fill:"hsl(var(--background))",stroke:z.color,strokeWidth:1.5,children:n.jsxs("title",{children:["Partial batch",ge.label?` — ${ge.label}`:""," (fewer runs completed than planned)"]})},M):n.jsx("circle",{cx:te(ge.x),cy:re(ge.y),r:2.5,fill:z.color},M))]},z.name)})})(),C&&n.jsxs("g",{children:[n.jsx("line",{x1:te(C.x),x2:te(C.x),y1:x.top,y2:R.height-x.bottom,stroke:"currentColor",strokeOpacity:.15}),C.points.map(({series:ae,point:z})=>n.jsx("circle",{cx:te(z.x),cy:re(z.y),r:4,fill:ae.color,stroke:"hsl(var(--background))",strokeWidth:1.5},ae.name))]}),n.jsx("text",{x:x.left,y:R.height-4,fontSize:9,fill:"currentColor",fillOpacity:.5,textAnchor:"start",children:p(r)}),n.jsx("text",{x:R.width-x.right,y:R.height-4,fontSize:9,fill:"currentColor",fillOpacity:.5,textAnchor:"end",children:p(i)})]}),C&&(()=>{var ge;const ae=te(C.x),z=8,L=240,ve=ae>R.width/2?{right:`${Math.max(z,R.width-ae+z)}px`,top:`${x.top+2}px`,maxWidth:`${L}px`}:{left:`${Math.min(ae+z,R.width-z)}px`,top:`${x.top+2}px`,maxWidth:`${L}px`};return n.jsxs("div",{className:"pointer-events-none absolute z-10 rounded border border-[hsl(var(--border))] bg-[hsl(var(--card))] px-2 py-1 text-[10px] shadow-sm",style:ve,children:[n.jsx("div",{className:"mb-0.5 text-[hsl(var(--muted-foreground))]",children:p(C.x)}),C.points.map(({series:M,point:Q})=>n.jsxs("div",{className:"flex items-center gap-1.5",children:[n.jsx("span",{className:"inline-block h-2 w-2 rounded-full shrink-0",style:{backgroundColor:M.color}}),n.jsx("span",{className:"font-mono truncate",children:M.name}),n.jsx("span",{className:"ml-auto font-mono shrink-0",children:v(Q.y)})]},M.name)),((ge=C.points[0])==null?void 0:ge.point.label)&&n.jsx("div",{className:"mt-0.5 truncate text-[hsl(var(--muted-foreground))]",children:C.points[0].point.label})]})})()]})}function KS({values:s,color:r="hsl(var(--primary))",width:i=120,height:o=24,fill:d=!0,className:f}){if(s.length===0)return n.jsx("div",{className:F("inline-block",f),style:{width:i,height:o}});if(s.length===1)return n.jsx("svg",{width:i,height:o,className:F("inline-block",f),children:n.jsx("circle",{cx:i/2,cy:o/2,r:2,fill:r})});const m=Math.min(...s),h=Math.max(...s),x=Math.max(.001,h-m),p=2,v=o-p*2,E=s.map((C,_)=>{const R=_/(s.length-1)*i,D=p+v-(C-m)/x*v;return[R,D]}).map(([C,_],R)=>`${R===0?"M":"L"} ${C.toFixed(1)} ${_.toFixed(1)}`).join(" "),w=d?`${E} L ${i} ${o} L 0 ${o} Z`:null;return n.jsxs("svg",{width:i,height:o,viewBox:`0 0 ${i} ${o}`,className:F("inline-block",f),children:[w&&n.jsx("path",{d:w,fill:r,fillOpacity:.12}),n.jsx("path",{d:E,stroke:r,strokeWidth:1.25,fill:"none"})]})}function f0(s){return s>=.8?"text-green-600 dark:text-green-400":s>=.5?"text-amber-600 dark:text-amber-400":"text-red-600 dark:text-red-400"}function Hd(s){return s.toFixed(3)}const h0=["#3b82f6","#10b981","#f59e0b","#ef4444","#8b5cf6","#ec4899","#14b8a6","#f97316"];function Is(s,r){return h0[r%h0.length]??"#64748b"}function VS(s){const r=new Date(s),o=Date.now()-s,d=1440*60*1e3;return o<d?r.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):o<7*d?r.toLocaleDateString([],{weekday:"short"}):r.toLocaleDateString()}function XS({onViewRun:s}={}){const{window:r,handleWindowChange:i,data:o}=pc("eval-trends",W2),[d,f]=b.useState("scorer");if(!o||o.totalRuns===0)return n.jsxs("div",{className:"flex-1 overflow-auto p-6",children:[n.jsxs("div",{className:"flex items-center justify-between mb-6",children:[n.jsx("h3",{className:"text-sm font-medium",children:"Eval Trends"}),n.jsx(Es,{value:r,onChange:i})]}),n.jsx(ta,{icon:n.jsx(QN,{size:32}),title:"No eval trends yet",description:"Run evaluations to see score trends over time."})]});const m=Object.keys(o.byEval).sort();return n.jsxs("div",{className:"flex-1 overflow-auto p-6 space-y-6",children:[n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsx("h3",{className:"text-sm font-medium",children:"Eval Trends"}),n.jsx(Es,{value:r,onChange:i})]}),n.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-3",children:[n.jsx(tt,{label:"Total Runs",value:String(o.totalRuns),subtitle:r}),n.jsx(tt,{label:"Evals Tracked",value:String(m.length),subtitle:m.length===1?"eval":"evals"}),n.jsx(tt,{label:"Total Cost",value:at(o.totalCost),subtitle:"all evals"})]}),n.jsxs("div",{className:"flex items-center gap-1 text-xs",role:"group","aria-label":"Trend chart view mode",children:[n.jsx("span",{className:"text-[hsl(var(--muted-foreground))] mr-1",children:"View:"}),["scorer","model","duration"].map(h=>n.jsx("button",{onClick:()=>f(h),"aria-pressed":d===h,className:F("px-2.5 py-1 rounded-md transition-colors",d===h?"bg-[hsl(var(--foreground))] text-[hsl(var(--background))]":"text-[hsl(var(--muted-foreground))] hover:bg-[hsl(var(--accent))]"),children:h==="scorer"?"By Scorer":h==="model"?"By Model":"Duration"},h))]}),m.map(h=>{const x=o.byEval[h],p=Object.keys(x.scoreMean).sort(),v=[...x.runs].sort((S,B)=>S.timestamp-B.timestamp),y=(()=>{const S=new Map;for(const $ of v)$.runGroupId&&S.set($.runGroupId,(S.get($.runGroupId)??0)+1);const B=new Set;for(const $ of v)$.runGroupId&&typeof $.batchAttempted=="number"&&(S.get($.runGroupId)??0)<$.batchAttempted&&B.add($.id);return B})();let E=[],w=[],C="",_,R=S=>S.toFixed(2);if(d==="scorer")C="Score Trend by Scorer",_={min:0,max:1},E=p.map((S,B)=>({name:S,color:Is(S,B),points:v.filter($=>$.scores[S]!=null).map($=>({x:$.timestamp,y:$.scores[S],label:$.model?`${$.id.slice(0,8)}… · ${$.model}`:$.id,meta:$,...y.has($.id)?{partial:!0}:{}}))})),w=p.map((S,B)=>({name:S,color:Is(S,B)}));else if(d==="model"){C="Score Trend by Model (mean of all scorers)",_={min:0,max:1};const S=new Map;for(const $ of v){const W=$.model??"unknown",K=S.get(W)??[];K.push($),S.set(W,K)}const B=[...S.keys()].sort();E=B.map(($,W)=>{const K=S.get($)??[];return{name:$,color:Is($,W),points:K.map(te=>{const re=Object.values(te.scores).filter(he=>Number.isFinite(he));if(re.length===0)return null;const Me=re.reduce((he,ae)=>he+ae,0)/re.length;return{x:te.timestamp,y:Me,label:`${te.id.slice(0,8)}… · ${$}`,meta:te,...y.has(te.id)?{partial:!0}:{}}}).filter(te=>te!==null)}}),w=B.map(($,W)=>({name:$,color:Is($,W)}))}else{C="Duration Trend by Model",R=$=>xt($);const S=new Map;for(const $ of v){if($.duration==null)continue;const W=$.model??"unknown",K=S.get(W)??[];K.push($),S.set(W,K)}const B=[...S.keys()].sort();E=B.map(($,W)=>{const K=S.get($)??[];return{name:$,color:Is($,W),points:K.map(te=>({x:te.timestamp,y:te.duration,label:`${te.id.slice(0,8)}… · ${$}`,meta:te,...y.has(te.id)?{partial:!0}:{}}))}}),w=B.map(($,W)=>({name:$,color:Is($,W)}))}const D=v.length>0?v[0].timestamp:0,H=v.length>0?v[v.length-1].timestamp:1,T=v.map(S=>S.cost),j=E.some(S=>S.points.length>=2),k=d==="duration"&&v.every(S=>S.duration==null)?"No duration metadata recorded on these runs.":(d==="model"||d==="duration")&&v.every(S=>S.model==null)?'No model metadata recorded on these runs — each run will show as "unknown".':null;return n.jsxs("div",{className:"rounded-xl border border-[hsl(var(--border))] overflow-hidden",children:[n.jsxs("div",{className:"px-4 py-3 bg-[hsl(var(--card))] border-b border-[hsl(var(--border))] flex items-center justify-between",children:[n.jsxs("div",{children:[n.jsx("span",{className:"font-mono text-sm font-medium",children:h}),n.jsxs("span",{className:"text-xs text-[hsl(var(--muted-foreground))] ml-2",children:[x.runCount," run",x.runCount!==1?"s":""]})]}),n.jsxs("div",{className:"flex items-center gap-3",children:[T.length>1&&n.jsxs("div",{className:"flex items-center gap-2 text-[10px] text-[hsl(var(--muted-foreground))]",title:"Cost over time",children:[n.jsx("span",{children:"cost"}),n.jsx(KS,{values:T,color:"hsl(var(--primary))",width:80,height:22})]}),n.jsx(Fa,{cost:x.costTotal})]})]}),v.length>1&&n.jsxs("div",{className:"px-4 py-3 border-b border-[hsl(var(--border))]",children:[n.jsxs("div",{className:"flex items-center justify-between mb-2",children:[n.jsx("p",{className:"text-[11px] font-medium uppercase tracking-wider text-[hsl(var(--muted-foreground))]",children:C}),n.jsxs("div",{className:"flex flex-wrap gap-2 text-[10px]",children:[w.map(S=>n.jsxs("div",{className:"flex items-center gap-1",children:[n.jsx("span",{className:"inline-block h-2 w-2 rounded-full",style:{backgroundColor:S.color}}),n.jsx("span",{className:"font-mono text-[hsl(var(--muted-foreground))]",children:S.name})]},S.name)),y.size>0&&n.jsxs("div",{className:"flex items-center gap-1",title:"Hollow ring marks a partial-batch run (fewer runs completed than were planned). The line still passes through it; the marker style is the only difference.",children:[n.jsx("span",{className:"inline-block h-2 w-2 rounded-full border",style:{borderColor:"hsl(var(--muted-foreground))",backgroundColor:"hsl(var(--background))"}}),n.jsx("span",{className:"font-mono text-[hsl(var(--muted-foreground))]",children:"partial"})]})]})]}),k?n.jsx("p",{className:"py-4 text-xs text-[hsl(var(--muted-foreground))] italic",children:k}):j?n.jsx(YS,{series:E,xMin:D,xMax:H,yClamp:_,yDomain:{strategy:"data",minSpan:d==="duration"?100:.1,padPct:.1},height:180,formatX:VS,formatY:R,ariaLabel:`${h}: ${C}, ${E.length} series across ${v.length} runs. Click a point to view that run.`,onPointClick:s?(S,B)=>{const $=B.meta;$!=null&&$.id&&s($.id)}:void 0}):n.jsx("p",{className:"py-4 text-xs text-[hsl(var(--muted-foreground))] italic",children:d==="scorer"?"Need at least 2 runs to draw a trend.":d==="model"?"Not enough runs per model yet — need at least 2 runs from the same model to draw a trend.":"Not enough runs per model with duration to draw a trend."})]}),v.length===1&&p.length>0&&n.jsx("p",{className:"px-4 py-2 text-[11px] text-[hsl(var(--muted-foreground))] border-b border-[hsl(var(--border))]",children:"Only one run in window — run again to see trend line."}),p.length>0&&n.jsxs("table",{className:"w-full text-xs",children:[n.jsx("thead",{children:n.jsxs("tr",{className:"border-b border-[hsl(var(--border))] bg-[hsl(var(--card))]",children:[n.jsx("th",{className:"py-2 px-4 text-left font-medium",children:"Scorer"}),n.jsx("th",{className:"py-2 px-4 text-right font-medium",children:"Latest"}),n.jsxs("th",{className:"py-2 px-4 text-right font-medium",title:x.runCount>50?"Computed over the 50 most recent runs":void 0,children:["Mean",x.runCount>50?"*":""]}),n.jsxs("th",{className:"py-2 px-4 text-right font-medium",title:x.runCount>50?"Computed over the 50 most recent runs":void 0,children:["Std",x.runCount>50?"*":""]})]})}),n.jsx("tbody",{children:p.map((S,B)=>n.jsxs("tr",{className:"border-b last:border-b-0 border-[hsl(var(--border))]",children:[n.jsx("td",{className:"py-2 px-4 font-mono",children:n.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[n.jsx("span",{className:"inline-block h-2 w-2 rounded-full",style:{backgroundColor:d==="scorer"?Is(S,B):"hsl(var(--muted-foreground) / 0.4)"}}),S]})}),n.jsx("td",{className:F("py-2 px-4 text-right font-mono",f0(x.latestScores[S]??0)),children:x.latestScores[S]!=null?Hd(x.latestScores[S]):"—"}),n.jsx("td",{className:F("py-2 px-4 text-right font-mono",f0(x.scoreMean[S]??0)),children:Hd(x.scoreMean[S]??0)}),n.jsx("td",{className:"py-2 px-4 text-right font-mono text-[hsl(var(--muted-foreground))]",children:Hd(x.scoreStd[S]??0)})]},S))})]}),x.runCount>50&&n.jsx("p",{className:"px-4 pt-2 text-[10px] text-[hsl(var(--muted-foreground))]",children:"* Mean and Std computed over the 50 most recent runs"})]},h)})]})}function m0(s){var y,E,w,C;if(s.length===0)return null;const r=s[0],i=Object.keys(((y=r.summary)==null?void 0:y.scorers)??{}),o={};for(const _ of i){const R=s.filter($=>{var K,te,re;const W=(re=(te=(K=$.summary)==null?void 0:K.scorers)==null?void 0:te[_])==null?void 0:re.scored;return W==null||W>0}),H=(R.length>0?R:s).map($=>{var W,K,te;return((te=(K=(W=$.summary)==null?void 0:W.scorers)==null?void 0:K[_])==null?void 0:te.mean)??0}),T=H.reduce(($,W)=>$+W,0)/H.length,j=H.length>1?Math.sqrt(H.reduce(($,W)=>$+(W-T)**2,0)/(H.length-1)):0,k=s.reduce(($,W)=>{var K,te,re;return $+(((re=(te=(K=W.summary)==null?void 0:K.scorers)==null?void 0:te[_])==null?void 0:re.scored)??0)},0),S=s.reduce(($,W)=>{var K,te,re;return $+(((re=(te=(K=W.summary)==null?void 0:K.scorers)==null?void 0:te[_])==null?void 0:re.failed)??0)},0),B=s.reduce(($,W)=>{var K,te,re;return $+(((re=(te=(K=W.summary)==null?void 0:K.scorers)==null?void 0:te[_])==null?void 0:re.skipped)??0)},0);o[_]={mean:Math.round(T*1e3)/1e3,std:Math.round(j*1e3)/1e3,min:Math.round(Math.min(...H)*1e3)/1e3,max:Math.round(Math.max(...H)*1e3)/1e3,scored:k,failed:S,skipped:B}}const d=new Set,f=[];for(const _ of s){const R=(E=_.metadata)==null?void 0:E.workflows;if(Array.isArray(R))for(const D of R)typeof D=="string"&&!d.has(D)&&(d.add(D),f.push(D))}const m={runGroupId:((w=r.metadata)==null?void 0:w.runGroupId)??"",runCount:s.length,workflows:f.length>0?f:void 0,scorers:o};let h;for(const _ of s){const R=(C=_.metadata)==null?void 0:C.batchAttempted;if(typeof R=="number"&&Number.isFinite(R)){h=R;break}}const x=h!==void 0&&s.length<h,p=x?s.map(_=>{var R;return(R=_.metadata)==null?void 0:R.batchFailure}).find(_=>typeof _=="string"&&_.length>0):void 0,v=FS(s);return{...r,summary:{...r.summary,...v.length>0?{degraded:v}:{}},_multiRun:{aggregate:m,allRuns:s,...x&&{partial:!0,batchCompleted:s.length,batchAttempted:h,...p?{batchFailure:p}:{}}}}}function FS(s){const r=new Map;for(const i of s)for(const o of Fg(i)){const d=r.get(o.scorer);if(!d)r.set(o.scorer,{...o,runsAffected:1});else{const f=o.rate>d.rate?o:d;r.set(o.scorer,{...f,runsAffected:d.runsAffected+1})}}return[...r.values()]}function uc(s){return s>=.8?"bg-emerald-100 dark:bg-emerald-900/50 text-emerald-700 dark:text-emerald-300":s>=.5?"bg-amber-100 dark:bg-amber-900/40 text-amber-700 dark:text-amber-300":"bg-red-100 dark:bg-red-900/40 text-red-700 dark:text-red-300"}function xc(s){return s>=.8?"bg-emerald-500 dark:bg-emerald-400":s>=.5?"bg-amber-500 dark:bg-amber-400":"bg-red-500 dark:bg-red-400"}function Rt(s){return s>=.8?"text-emerald-600 dark:text-emerald-400":s>=.5?"text-amber-600 dark:text-amber-400":"text-red-600 dark:text-red-400"}function p0(s){return s>=.8?"bg-emerald-50/60 dark:bg-emerald-950/20":s>=.5?"bg-amber-50/60 dark:bg-amber-950/20":"bg-red-50/60 dark:bg-red-950/20"}function ZS(s){var r;return Array.isArray((r=s.metadata)==null?void 0:r.models)?s.metadata.models.filter(i=>typeof i=="string"):[]}function Xg(s,r){var f,m,h,x;const i=[];let o=0,d=0;for(const p of s){if(p.error)continue;const v=p.scores[r];v!=null?i.push(v):((m=(f=p.scoreDetails)==null?void 0:f[r])==null?void 0:m.skipped)===!0?d++:((x=(h=p.scoreDetails)==null?void 0:h[r])==null?void 0:x.duration)!=null&&o++}return{scores:i,failed:o,skipped:d}}function JS(s,r,i){const o=i?Xg(i,r):void 0,d=s.skipped??(o==null?void 0:o.skipped)??0;return s.scored!=null&&s.failed!=null?{scored:s.scored,failed:s.failed,skipped:d}:o?{scored:o.scores.length,failed:o.failed,skipped:d}:{scored:s.scored??0,failed:s.failed??0,skipped:d}}function $n(s){var r;return Array.isArray((r=s.metadata)==null?void 0:r.models)?s.metadata.models.filter(i=>typeof i=="string"):[]}function IS(s){var i;const r=(i=s.metadata)==null?void 0:i.droppedAnnotationKeys;return Array.isArray(r)?r.filter(o=>typeof o=="string"):[]}function WS(s){var i,o;if(((i=s.metadata)==null?void 0:i.scorerFiltered)!==!0)return[];const r=(o=s.metadata)==null?void 0:o.scorersRun;return Array.isArray(r)?r.filter(d=>typeof d=="string"):[]}function Fg(s){var i;const r=(i=s.summary)==null?void 0:i.degraded;return Array.isArray(r)?r.filter(o=>o!=null&&typeof o=="object"&&typeof o.scorer=="string"&&typeof o.rate=="number"&&typeof o.limit=="number"&&(o.type==="llm"||o.type==="deterministic")&&typeof o.scored=="number"&&typeof o.failed=="number"):[]}function Ts(s){var o;const r=(o=s.metadata)==null?void 0:o.modelCounts;if(!r||typeof r!="object")return null;const i={};for(const[d,f]of Object.entries(r))typeof f=="number"&&(i[d]=f);return Object.keys(i).length>0?i:null}function tr(s){var d,f;const r=(d=s._multiRun)==null?void 0:d.aggregate.workflows;if(Array.isArray(r)&&r.length>0){const m=r.filter(h=>typeof h=="string");if(m.length>0)return m}const i=(f=s.metadata)==null?void 0:f.workflows;if(Array.isArray(i)){const m=i.filter(h=>typeof h=="string");if(m.length>0)return m}const o=s.workflow;return typeof o=="string"&&o?[o]:[]}function rf(s){var o;const r=(o=s.metadata)==null?void 0:o.workflowCounts;if(!r||typeof r!="object")return null;const i={};for(const[d,f]of Object.entries(r))typeof f=="number"&&(i[d]=f);return Object.keys(i).length>0?i:null}function wa(s){const r=s.indexOf(":");return r>=0?s.slice(r+1):s}function Zg(s){var o;const r=(o=s.metadata)==null?void 0:o.tokens;if(!r||typeof r!="object")return null;const i=r;return typeof i.input!="number"?null:{input:i.input,output:typeof i.output=="number"?i.output:0,reasoning:typeof i.reasoning=="number"?i.reasoning:0}}function PS(s){var i;const r=(i=s.metadata)==null?void 0:i.agentCalls;return typeof r=="number"?r:0}function of(s){const r={input:0,output:0,reasoning:0};for(const i of s.items){const o=Zg(i);o&&(r.input+=o.input,r.output+=o.output,r.reasoning+=o.reasoning)}return r}function Lf(s){const r=new Map;for(const i of s){const o=i.data,d=Ts(o);if(d)for(const[f,m]of Object.entries(d))r.set(f,(r.get(f)??0)+m);else for(const f of $n(o))r.set(f,(r.get(f)??0)+1)}return[...r.entries()].sort((i,o)=>o[1]-i[1])}function x0(s){const r={input:0,output:0,reasoning:0};for(const i of s){const o=of(i);r.input+=o.input,r.output+=o.output,r.reasoning+=o.reasoning}return r}function g0(s){return s.reduce((r,i)=>r+i.totalCost,0)}function Hf({failed:s,skipped:r,scored:i}){const o=s??0;return n.jsxs(n.Fragment,{children:[o>0&&n.jsx("span",{className:"ml-1.5 px-1 py-0.5 text-[9px] font-medium rounded bg-amber-100 text-amber-700 dark:bg-amber-900/40 dark:text-amber-300 align-middle",title:`${s} scorer run(s) failed — the mean is computed over the runs/items that succeeded.`,children:i!=null?`${i}/${i+o} scored, ${o} failed`:`${o} failed`}),(r??0)>0&&n.jsxs("span",{className:"ml-1.5 px-1 py-0.5 text-[9px] font-medium rounded bg-[hsl(var(--muted))] text-[hsl(var(--muted-foreground))] align-middle",title:`${r} item(s) not applicable to this scorer (applies predicate returned false) — excluded from the mean and the failure rate`,children:["N/A: ",r]})]})}function e5(s,r){if(r===0)return"text-[hsl(var(--muted-foreground))]";const i=s/r;return i<.02?"text-[hsl(var(--muted-foreground))]":i<=.05?"text-amber-600 dark:text-amber-400":"text-red-600 dark:text-red-400"}function t5({name:s,stats:r,isLlm:i}){const o=(r.scored??0)>0;return n.jsxs("tr",{className:"border-b border-[hsl(var(--border))] last:border-b-0",children:[n.jsxs("td",{className:"px-4 py-2.5 font-mono",children:[s,i&&n.jsx("span",{className:"ml-1.5 px-1 py-0.5 text-[9px] font-medium rounded bg-purple-100 text-purple-600 dark:bg-purple-900/30 dark:text-purple-400 align-middle",title:"LLM scorer — scores may vary between runs",children:"LLM"}),n.jsx(Hf,{failed:r.failed,skipped:r.skipped})]}),o?n.jsxs(n.Fragment,{children:[n.jsx("td",{className:F("px-3 py-2.5 text-right font-mono font-medium",Rt(r.mean)),children:r.mean.toFixed(3)}),n.jsx("td",{className:F("px-3 py-2.5 text-right font-mono",e5(r.std,r.mean)),children:r.std.toFixed(3)}),n.jsx("td",{className:F("px-3 py-2.5 text-right font-mono",Rt(r.min)),children:r.min.toFixed(3)}),n.jsx("td",{className:F("px-3 py-2.5 text-right font-mono",Rt(r.max)),children:r.max.toFixed(3)})]}):n.jsx("td",{colSpan:4,className:"px-3 py-2.5 text-center text-[hsl(var(--muted-foreground))]",children:"No valid scores"})]})}const a5=20;function v0({result:s}){const r=IS(s);if(r.length===0)return null;const i=r.slice(0,a5),o=r.length-i.length,d=r.length===1;return n.jsxs("div",{className:"mb-3 rounded-md border border-amber-300/60 bg-amber-50 dark:border-amber-500/40 dark:bg-amber-950/40 px-4 py-3 text-sm text-amber-900 dark:text-amber-200",role:"status",children:[n.jsxs("div",{className:"font-medium",children:[r.length," annotation ",d?"key":"keys"," dropped by the dataset schema"]}),n.jsxs("div",{className:"mt-1 text-amber-800/90 dark:text-amber-300/90",children:["Stripped before reaching scorers, so any scorer reading ",d?"it":"them"," silently sees ",n.jsx("code",{className:"font-mono",children:"undefined"}),". Declare ",d?"it":"them"," in the dataset’s ",n.jsx("code",{className:"font-mono",children:"annotations"})," schema."]}),n.jsxs("div",{className:"mt-2 flex flex-wrap gap-1",children:[i.map(f=>n.jsx("span",{className:"px-1.5 py-0.5 rounded bg-amber-100 dark:bg-amber-900/50 text-amber-800 dark:text-amber-200 text-[10px] font-mono font-medium",children:f},f)),o>0&&n.jsxs("span",{className:"px-1.5 py-0.5 text-[10px] text-amber-800/80 dark:text-amber-300/80 font-medium",children:["+",o," more"]})]})]})}const n5=20;function b0({result:s}){const r=WS(s);if(r.length===0)return null;const i=r.slice(0,n5),o=r.length-i.length,d=r.length===1;return n.jsxs("div",{className:"mb-3 rounded-md border border-amber-300/60 bg-amber-50 dark:border-amber-500/40 dark:bg-amber-950/40 px-4 py-3 text-sm text-amber-900 dark:text-amber-200",role:"status",children:[n.jsxs("div",{className:"font-medium",children:["Filtered scorer subset — ran ",r.length," ",d?"scorer":"scorers"]}),n.jsxs("div",{className:"mt-1 text-amber-800/90 dark:text-amber-300/90",children:["Only ",d?"this scorer was":"these scorers were"," run, not the eval’s full set. This is not a full-coverage run — don’t use it as a baseline."]}),n.jsxs("div",{className:"mt-2 flex flex-wrap gap-1",children:[i.map(f=>n.jsx("span",{className:"px-1.5 py-0.5 rounded bg-amber-100 dark:bg-amber-900/50 text-amber-800 dark:text-amber-200 text-[10px] font-mono font-medium",children:f},f)),o>0&&n.jsxs("span",{className:"px-1.5 py-0.5 text-[10px] text-amber-800/80 dark:text-amber-300/80 font-medium",children:["+",o," more"]})]})]})}const s5=5;function l5(s){const r=s.scored+s.failed,i=(s.rate*100).toFixed(1),o=`"${s.scorer}" failed ${i}% (${s.failed}/${r})`,d=s.runsAffected!=null&&s.runsAffected>0?` (in ${s.runsAffected} run${s.runsAffected===1?"":"s"})`:"";return s.type==="deterministic"?`${o} — deterministic scorers tolerate no failures${d}`:`${o} — over the ${(s.limit*100).toFixed(1)}% limit (llm)${d}`}function y0({result:s}){const r=Fg(s);if(r.length===0)return null;const i=r.slice(0,s5),o=r.length-i.length,d=r.length===1;return n.jsxs("div",{className:"mb-3 rounded-md border border-amber-300/60 bg-amber-50 dark:border-amber-500/40 dark:bg-amber-950/40 px-4 py-3 text-sm text-amber-900 dark:text-amber-200",role:"status",children:[n.jsxs("div",{className:"font-medium",children:[r.length," ",d?"scorer":"scorers"," exceeded the failure-rate tolerance"]}),n.jsxs("div",{className:"mt-1 text-amber-800/90 dark:text-amber-300/90",children:[d?"This scorer":"These scorers"," ran and failed on too many items, so the reported mean rests on a thinned, unrepresentative sample — don’t trust it."]}),n.jsxs("ul",{className:"mt-2 space-y-0.5",children:[i.map(f=>n.jsx("li",{className:"text-[11px] font-mono text-amber-800/90 dark:text-amber-300/90",children:l5(f)},f.scorer)),o>0&&n.jsxs("li",{className:"text-[11px] text-amber-800/80 dark:text-amber-300/80 font-medium",children:["+",o," more"]})]})]})}function r5({summary:s,items:r,totalCost:i,scorerTypes:o}){const d=s.scorers?Object.entries(s.scorers):[];return d.length===0&&!s.timing&&i<=0?null:n.jsxs("div",{className:"rounded-xl border border-[hsl(var(--border))] overflow-hidden",children:[n.jsx("div",{className:"px-4 py-2.5 bg-[hsl(var(--muted))] border-b border-[hsl(var(--border))]",children:n.jsx("h3",{className:"text-[11px] font-medium uppercase tracking-wider text-[hsl(var(--muted-foreground))]",children:"Scorer Summary"})}),n.jsx("div",{className:"overflow-x-auto",children:n.jsxs("table",{className:"w-full text-xs",children:[n.jsx("thead",{children:n.jsxs("tr",{className:"border-b border-[hsl(var(--border))]",children:[n.jsx("th",{className:"text-left px-4 py-2 font-medium w-48",children:"Metric"}),n.jsx("th",{className:"px-4 py-2 w-28"}),n.jsx("th",{className:"text-right px-3 py-2 font-medium",children:"Mean"}),n.jsx("th",{className:"text-right px-3 py-2 font-medium",children:"P50"}),n.jsx("th",{className:"text-right px-3 py-2 font-medium",children:"P95"}),n.jsx("th",{className:"text-right px-3 py-2 font-medium",children:"Min"}),n.jsx("th",{className:"text-right px-3 py-2 font-medium",children:"Max"})]})}),n.jsxs("tbody",{children:[d.map(([f,m])=>{const{scored:h,failed:x,skipped:p}=JS(m,f,r),v=h>0;return n.jsxs("tr",{className:"border-b border-[hsl(var(--border))] last:border-b-0",children:[n.jsxs("td",{className:"px-4 py-2.5 font-mono text-[hsl(var(--foreground))]",children:[f,(o==null?void 0:o[f])==="llm"&&n.jsx("span",{className:"ml-1.5 px-1 py-0.5 text-[9px] font-medium rounded bg-purple-100 text-purple-600 dark:bg-purple-900/30 dark:text-purple-400 align-middle",title:"LLM scorer — scores may vary between runs",children:"LLM"}),n.jsx(Hf,{failed:x,skipped:p,scored:h})]}),v?n.jsxs(n.Fragment,{children:[n.jsx("td",{className:"px-4 py-2.5",children:n.jsx("div",{className:"h-2 bg-[hsl(var(--secondary))] rounded-full overflow-hidden",children:n.jsx("div",{className:F("h-full rounded-full transition-all",xc(m.mean)),style:{width:`${m.mean*100}%`}})})}),n.jsx("td",{className:F("px-3 py-2.5 text-right font-mono font-medium",Rt(m.mean)),children:m.mean.toFixed(3)}),n.jsx("td",{className:"px-3 py-2.5 text-right font-mono text-[hsl(var(--muted-foreground))]",children:m.p50.toFixed(3)}),n.jsx("td",{className:"px-3 py-2.5 text-right font-mono text-[hsl(var(--muted-foreground))]",children:m.p95.toFixed(3)}),n.jsx("td",{className:"px-3 py-2.5 text-right font-mono text-[hsl(var(--muted-foreground))]",children:m.min.toFixed(3)}),n.jsx("td",{className:"px-3 py-2.5 text-right font-mono text-[hsl(var(--muted-foreground))]",children:m.max.toFixed(3)})]}):n.jsx("td",{colSpan:6,className:"px-3 py-2.5 text-center text-[hsl(var(--muted-foreground))]",children:"No valid scores"})]},f)}),s.timing&&n.jsxs("tr",{className:"border-t border-[hsl(var(--border))]",children:[n.jsx("td",{className:"px-4 py-2.5 font-mono text-[hsl(var(--muted-foreground))]",children:"Timing"}),n.jsx("td",{className:"px-4 py-2.5"}),n.jsx("td",{className:"px-3 py-2.5 text-right font-mono text-[hsl(var(--muted-foreground))]",children:xt(s.timing.mean)}),n.jsx("td",{className:"px-3 py-2.5 text-right font-mono text-[hsl(var(--muted-foreground))]",children:xt(s.timing.p50)}),n.jsx("td",{className:"px-3 py-2.5 text-right font-mono text-[hsl(var(--muted-foreground))]",children:xt(s.timing.p95)}),n.jsx("td",{className:"px-3 py-2.5 text-right font-mono text-[hsl(var(--muted-foreground))]",children:xt(s.timing.min)}),n.jsx("td",{className:"px-3 py-2.5 text-right font-mono text-[hsl(var(--muted-foreground))]",children:xt(s.timing.max)})]})]})]})}),i>0&&n.jsx("div",{className:"px-4 py-2 border-t border-[hsl(var(--border))] bg-[hsl(var(--muted))]/50",children:n.jsxs("span",{className:"text-xs text-[hsl(var(--muted-foreground))]",children:["Total cost: ",n.jsx("span",{className:"font-mono font-medium",children:at(i)})]})})]})}function i5({items:s,scorerNames:r,onSelectItem:i,errorFilter:o,onErrorFilterChange:d,scorerFilter:f,onScorerFilterChange:m,threshold:h,onThresholdChange:x,sortField:p,onSortFieldChange:v,sortDir:y,onSortDirChange:E}){const w=h!==""?parseFloat(h):null,C=o!=="all"||f!==""&&w!=null&&!isNaN(w),_=b.useMemo(()=>s.map((T,j)=>({item:T,index:j})),[s]),R=b.useMemo(()=>{let T=_;return o==="errors"?T=T.filter(({item:j})=>!!j.error):o==="no-errors"&&(T=T.filter(({item:j})=>!j.error)),f&&w!=null&&!isNaN(w)&&(T=T.filter(({item:j})=>{const k=j.scores[f];return k!=null&&k<w})),T},[_,o,f,w]),D=b.useMemo(()=>{const T=[...R],j=y==="asc"?1:-1;return T.sort((k,S)=>{let B,$;return p==="index"?(B=k.index,$=S.index):p==="duration"?(B=k.item.duration??1/0,$=S.item.duration??1/0):p==="cost"?(B=k.item.cost??1/0,$=S.item.cost??1/0):(B=k.item.scores[p]??-1/0,$=S.item.scores[p]??-1/0),(B-$)*j}),T},[R,p,y]),H=[{value:"index",label:"Item #"},{value:"duration",label:"Duration"},{value:"cost",label:"Cost"},...r.map(T=>({value:T,label:T}))];return n.jsxs("div",{children:[n.jsxs("div",{className:"flex items-center justify-between gap-3 mb-3 flex-wrap",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("h3",{className:"text-[11px] font-medium uppercase tracking-wider text-[hsl(var(--muted-foreground))]",children:"All Items"}),n.jsx("span",{className:"text-xs text-[hsl(var(--muted-foreground))] font-mono tabular-nums",children:C?`${R.length} of ${s.length}`:String(s.length)}),C&&n.jsx("button",{onClick:()=>{d("all"),m(""),x("")},className:"text-xs text-[hsl(var(--primary))] hover:underline cursor-pointer",children:"Reset"})]}),n.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[n.jsxs("select",{value:o,onChange:T=>d(T.target.value),className:"px-2 py-1 text-xs rounded-lg border border-[hsl(var(--input))] bg-[hsl(var(--background))]",children:[n.jsx("option",{value:"all",children:"All"}),n.jsx("option",{value:"errors",children:"Errors"}),n.jsx("option",{value:"no-errors",children:"Passed"})]}),r.length>0&&n.jsxs(n.Fragment,{children:[n.jsxs("select",{value:f,onChange:T=>m(T.target.value),className:"px-2 py-1 text-xs rounded-lg border border-[hsl(var(--input))] bg-[hsl(var(--background))]",children:[n.jsx("option",{value:"",children:"Score filter…"}),r.map(T=>n.jsx("option",{value:T,children:T},T))]}),f&&n.jsx("input",{type:"number",step:"0.1",min:"0",max:"1",placeholder:"< threshold",value:h,onChange:T=>x(T.target.value),className:"w-20 px-2 py-1 text-xs rounded-lg border border-[hsl(var(--input))] bg-[hsl(var(--background))]"})]}),n.jsx("div",{className:"w-px h-4 bg-[hsl(var(--border))]"}),n.jsx("select",{value:p,onChange:T=>v(T.target.value),className:"px-2 py-1 text-xs rounded-lg border border-[hsl(var(--input))] bg-[hsl(var(--background))]",children:H.map(T=>n.jsx("option",{value:T.value,children:T.label},T.value))}),n.jsx("button",{onClick:()=>E(y==="asc"?"desc":"asc"),className:"px-2 py-1 text-xs rounded-lg border border-[hsl(var(--input))] hover:bg-[hsl(var(--accent))] transition-colors cursor-pointer",title:y==="asc"?"Ascending":"Descending",children:y==="asc"?"↑":"↓"})]})]}),D.length===0&&C&&n.jsx("p",{className:"text-xs text-[hsl(var(--muted-foreground))] py-6 text-center",children:"No items match the current filters."}),D.length>0&&n.jsx("div",{className:"rounded-xl border border-[hsl(var(--border))] overflow-hidden",children:n.jsx("div",{className:"overflow-x-auto",children:n.jsxs("table",{className:"w-full text-xs",children:[n.jsx("thead",{children:n.jsxs("tr",{className:"bg-[hsl(var(--muted))]",children:[n.jsx("th",{className:"text-left px-3 py-2.5 font-medium w-10",children:"#"}),n.jsx("th",{className:"text-left px-3 py-2.5 font-medium min-w-[180px]",children:"Input"}),r.map(T=>n.jsx("th",{className:"text-right px-2 py-2.5 font-medium font-mono max-w-24 truncate",title:T,children:T},T)),n.jsx("th",{className:"text-right px-3 py-2.5 font-medium w-16",children:"Duration"}),n.jsx("th",{className:"text-right px-3 py-2.5 font-medium w-16",children:"Cost"}),n.jsx("th",{className:"w-8"})]})}),n.jsx("tbody",{children:D.map(({item:T,index:j})=>n.jsxs("tr",{onClick:()=>i(j),className:"border-t border-[hsl(var(--border))] hover:bg-[hsl(var(--accent))] cursor-pointer transition-colors group",children:[n.jsxs("td",{className:"px-3 py-2 font-mono text-[hsl(var(--muted-foreground))]",children:[j+1,T.error&&n.jsx("span",{className:"ml-1 inline-flex items-center text-red-500",title:"Workflow error","aria-label":"Workflow error",children:n.jsx(jg,{size:12})}),!T.error&&T.scorerErrors&&T.scorerErrors.length>0&&n.jsx("span",{className:"ml-1 inline-flex items-center text-amber-500",title:"Scorer errors","aria-label":"Scorer errors",children:n.jsx(kg,{size:12})})]}),n.jsx("td",{className:"px-3 py-2 max-w-xs",children:n.jsx("span",{className:"text-[11px] leading-tight text-[hsl(var(--muted-foreground))] truncate block group-hover:text-[hsl(var(--foreground))] transition-colors",children:xr(T.input)==="[redacted]"?`Item ${j+1}`:xr(T.input)})}),r.map(k=>{var W;const S=T.scores[k],B=(W=T.scoreDetails)==null?void 0:W[k],$=(B==null?void 0:B.skipped)===!0;return n.jsx("td",{className:"text-right px-2 py-2 font-mono",children:S!=null?n.jsx("span",{className:F("font-medium tabular-nums",Rt(S)),children:S.toFixed(2)}):$?n.jsx("span",{className:"text-[10px] text-[hsl(var(--muted-foreground))]",title:"Not applicable (N/A)",children:"N/A"}):n.jsx("span",{className:"text-[hsl(var(--muted-foreground))]",title:(B==null?void 0:B.duration)!=null?"Scorer failed":void 0,children:"—"})},k)}),n.jsx("td",{className:"text-right px-3 py-2 font-mono text-[hsl(var(--muted-foreground))]",children:T.duration!=null?xt(T.duration):"—"}),n.jsx("td",{className:"text-right px-3 py-2 font-mono text-[hsl(var(--muted-foreground))]",children:T.cost!=null&&T.cost>0?at(T.cost):"—"}),n.jsx("td",{className:"px-2 py-2",children:n.jsx(Ba,{size:12,className:"text-[hsl(var(--muted-foreground))] opacity-0 group-hover:opacity-60 transition-opacity"})})]},j))})]})})})]})}const j0=300;function o5({text:s}){const[r,i]=b.useState(!1),o=s.length>j0;return n.jsxs("div",{children:[n.jsx("pre",{className:"text-xs font-mono p-3 rounded-lg bg-[hsl(var(--secondary))] overflow-auto max-h-96 whitespace-pre-wrap leading-relaxed",children:o&&!r?s.slice(0,j0)+"…":s}),o&&n.jsx("button",{onClick:()=>i(!r),className:"text-xs text-[hsl(var(--primary))] hover:underline mt-1.5 cursor-pointer",children:r?"Show less":"Show more"})]})}function qd({label:s,data:r}){return n.jsxs("div",{className:"rounded-xl border border-[hsl(var(--border))] overflow-hidden",children:[n.jsx("div",{className:"px-4 py-2.5 bg-[hsl(var(--muted))]/50 border-b border-[hsl(var(--border))]",children:n.jsx("span",{className:"text-[11px] font-medium uppercase tracking-wider text-[hsl(var(--muted-foreground))]",children:s})}),n.jsx("div",{className:"p-4",children:n.jsx(Ct,{data:r,collapsed:!0})})]})}function c5({traces:s}){const[r,i]=b.useState(!1);return n.jsxs("div",{className:"rounded-xl border border-[hsl(var(--border))] overflow-hidden",children:[n.jsxs("button",{onClick:()=>i(o=>!o),className:"w-full flex items-center gap-2 px-4 py-2.5 bg-[hsl(var(--muted))]/50 border-b border-[hsl(var(--border))] hover:bg-[hsl(var(--muted))] text-left cursor-pointer",children:[n.jsx("span",{className:F("text-[11px]",r?"rotate-0":"rotate-90"),children:"▶"}),n.jsx("span",{className:"text-[11px] font-medium uppercase tracking-wider text-[hsl(var(--muted-foreground))]",children:"Trace"}),n.jsxs("span",{className:"text-[11px] text-[hsl(var(--muted-foreground))] ml-1",children:[s.length," event",s.length!==1?"s":""]})]}),!r&&n.jsx("div",{className:"p-2",children:n.jsx(Di,{events:s})})]})}function u5({item:s,itemIndex:r,scorerNames:i,onBack:o}){const d=s.scorerErrors??[],f=ZS(s),m=Zg(s),h=PS(s),x=s.cost??0,p=s.scorerCost??0,v=x+p;return n.jsxs("div",{className:"space-y-5",children:[n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsxs("nav",{className:"flex items-center gap-1.5 text-sm",children:[n.jsx("button",{onClick:o,className:"text-[hsl(var(--muted-foreground))] hover:text-[hsl(var(--foreground))] transition-colors cursor-pointer",children:"Overview"}),n.jsx("span",{className:"text-[hsl(var(--muted-foreground))]",children:"/"}),n.jsxs("span",{className:"font-medium",children:["Item #",r+1]}),s.error&&n.jsx("span",{className:"ml-1 inline-flex items-center px-2 py-0.5 rounded-full text-[10px] font-medium text-red-600 dark:text-red-400 bg-red-50 dark:bg-red-950/30",children:"Error"})]}),n.jsxs("div",{className:"flex items-center gap-2 text-xs text-[hsl(var(--muted-foreground))] font-mono",children:[f.length>0&&f.map(y=>n.jsx("span",{className:"px-1.5 py-0.5 rounded bg-[hsl(var(--secondary))] text-[hsl(var(--foreground))] text-[10px] font-medium",title:y,children:wa(y)},y)),m&&n.jsxs("span",{title:`Input: ${m.input.toLocaleString()} Output: ${m.output.toLocaleString()}${m.reasoning?` Reasoning: ${m.reasoning.toLocaleString()}`:""}`,children:[(m.input+m.output+m.reasoning).toLocaleString()," tok"]}),h>1&&n.jsxs("span",{title:`${h} agent calls for this item`,children:[h," calls"]}),s.duration!=null&&n.jsx("span",{children:xt(s.duration)}),v>0&&n.jsx("span",{children:at(v)})]})]}),i.length>0&&n.jsx("div",{className:"flex flex-wrap items-center gap-x-4 gap-y-2 py-3 px-4 rounded-xl bg-[hsl(var(--muted))]/50",children:i.map(y=>{var C,_;const E=s.scores[y],w=((_=(C=s.scoreDetails)==null?void 0:C[y])==null?void 0:_.skipped)===!0;return n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("span",{className:"text-xs text-[hsl(var(--muted-foreground))]",children:y}),E!=null?n.jsxs("div",{className:"flex items-center gap-1.5",children:[n.jsx("div",{className:"w-12 h-1.5 bg-[hsl(var(--secondary))] rounded-full overflow-hidden",children:n.jsx("div",{className:F("h-full rounded-full",xc(E)),style:{width:`${E*100}%`}})}),n.jsx("span",{className:F("text-xs font-mono font-medium tabular-nums",Rt(E)),children:E.toFixed(2)})]}):w?n.jsx("span",{className:"text-xs text-[hsl(var(--muted-foreground))] font-mono",title:"Not applicable (N/A)",children:"N/A"}):n.jsx("span",{className:"text-xs text-[hsl(var(--muted-foreground))] font-mono",children:"—"})]},y)})}),s.error&&n.jsx("div",{className:"p-3 rounded-xl bg-red-50 dark:bg-red-950/30 border border-red-200 dark:border-red-800 text-red-700 dark:text-red-300 text-xs font-mono",children:s.error}),n.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-3",children:[n.jsx(qd,{label:"Input",data:s.input}),n.jsx(qd,{label:"Output",data:s.output})]}),s.annotations!=null&&n.jsx(qd,{label:"Expected (Annotations)",data:s.annotations}),v>0&&x>0&&p>0&&n.jsxs("div",{className:"flex items-center gap-3 text-xs text-[hsl(var(--muted-foreground))] font-mono",children:[n.jsxs("span",{children:["Workflow: ",at(x)]}),n.jsx("span",{children:"+"}),n.jsxs("span",{children:["Scoring: ",at(p)]}),n.jsx("span",{children:"="}),n.jsx("span",{className:"font-medium text-[hsl(var(--foreground))]",children:at(v)})]}),s.traces&&s.traces.length>0&&n.jsx(c5,{traces:s.traces}),i.length>0&&n.jsxs("div",{className:"space-y-3",children:[n.jsx("h4",{className:"text-[11px] font-medium uppercase tracking-wider text-[hsl(var(--muted-foreground))]",children:"Scorer Results"}),i.map(y=>{var R;const E=s.scores[y],w=(R=s.scoreDetails)==null?void 0:R[y],C=d.find(D=>D.includes(`"${y}"`)),_=(w==null?void 0:w.skipped)===!0;return n.jsxs("div",{className:"rounded-xl border border-[hsl(var(--border))] overflow-hidden",children:[n.jsxs("div",{className:"flex items-center gap-2 px-4 py-2.5 bg-[hsl(var(--muted))]/50",children:[n.jsx("span",{className:"font-mono text-xs font-medium",children:y}),E!=null&&n.jsx("span",{className:F("px-2 py-0.5 rounded-full text-xs font-mono font-medium",uc(E)),children:E.toFixed(3)}),E==null&&_&&n.jsx("span",{className:"px-2 py-0.5 rounded-full text-xs font-mono bg-[hsl(var(--muted))] text-[hsl(var(--muted-foreground))]",title:"Skipped — the scorer's `applies` predicate returned false for this item (excluded from the mean and failure rate)",children:"N/A"}),E==null&&!_&&!C&&n.jsx("span",{className:"px-2 py-0.5 rounded-full text-xs font-mono bg-[hsl(var(--secondary))] text-[hsl(var(--muted-foreground))]",children:"null"}),n.jsxs("div",{className:"ml-auto flex items-center gap-2",children:[(w==null?void 0:w.duration)!=null&&n.jsx("span",{className:"text-xs font-mono text-[hsl(var(--muted-foreground))]",children:xt(w.duration)}),(w==null?void 0:w.cost)!=null&&w.cost>0&&n.jsx("span",{className:"text-xs font-mono text-[hsl(var(--muted-foreground))]",children:at(w.cost)})]})]}),((w==null?void 0:w.metadata)||C||_)&&n.jsxs("div",{className:"px-4 py-3 space-y-2",children:[_&&n.jsxs("p",{className:"text-xs text-[hsl(var(--muted-foreground))]",children:["Not applicable — the scorer’s ",n.jsx("code",{children:"applies"})," predicate returned false for this item, so it was skipped (excluded from the mean and the failure rate)."]}),(w==null?void 0:w.metadata)&&typeof w.metadata.reasoning=="string"&&w.metadata.reasoning.length>0&&n.jsxs("div",{children:[n.jsx("span",{className:"text-[11px] font-medium text-[hsl(var(--muted-foreground))] block mb-1.5 uppercase tracking-wider",children:"Reasoning"}),n.jsx(o5,{text:w.metadata.reasoning})]}),(w==null?void 0:w.metadata)&&(()=>{const D=Object.keys(w.metadata).filter(T=>T!=="reasoning");if(D.length===0)return null;const H={};for(const T of D)H[T]=w.metadata[T];return n.jsxs("div",{children:[n.jsx("span",{className:"text-[11px] font-medium text-[hsl(var(--muted-foreground))] block mb-1.5 uppercase tracking-wider",children:"Metadata"}),n.jsx(Ct,{data:H,collapsed:!0})]})})(),C&&n.jsx("div",{className:"text-xs text-amber-600 dark:text-amber-400 font-mono p-2.5 rounded-lg bg-amber-50 dark:bg-amber-950/30",children:C})]})]},y)})]})]})}function d5(s,r){const i=r.map(o=>s.scores[o]).filter(o=>o!=null);return i.length===0?null:i.reduce((o,d)=>o+d,0)/i.length}function f5({items:s,scorerNames:r,selectedIndex:i,onSelectItem:o,onDeselectItem:d}){const f=b.useMemo(()=>s.map((h,x)=>({item:h,index:x,avg:d5(h,r),label:xr(h.input,60)})),[s,r]),m=s.filter(h=>h.error).length;return n.jsxs("div",{className:"flex flex-col h-full",children:[n.jsx("div",{className:"shrink-0 px-4 py-3 border-b border-[hsl(var(--border))]",children:n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsxs("button",{onClick:d,className:F("text-xs font-medium transition-colors cursor-pointer",i==null?"text-[hsl(var(--foreground))]":"text-[hsl(var(--muted-foreground))] hover:text-[hsl(var(--foreground))]"),children:[s.length," items"]}),m>0?n.jsxs("span",{className:"text-[10px] font-medium text-red-600 dark:text-red-400",children:[m," failed"]}):n.jsx("span",{className:"text-[10px] font-medium text-emerald-600 dark:text-emerald-400",children:"all passed"})]})}),n.jsx("div",{className:"flex-1 overflow-y-auto",children:f.map(({item:h,index:x,avg:p,label:v})=>{const y=i===x;return n.jsxs("button",{onClick:()=>o(x),className:F("w-full text-left px-4 py-2.5 flex items-center gap-3 border-b border-[hsl(var(--border))]/50 transition-colors group cursor-pointer",y?"bg-[hsl(var(--accent))] border-l-2 border-l-[hsl(var(--foreground))]":"hover:bg-[hsl(var(--accent))]/50 border-l-2 border-l-transparent"),children:[n.jsx("span",{className:F("text-[10px] font-mono w-5 shrink-0",y?"text-[hsl(var(--foreground))] font-medium":"text-[hsl(var(--muted-foreground))]"),children:x+1}),n.jsx("span",{className:F("flex-1 text-xs truncate leading-snug",y?"text-[hsl(var(--foreground))]":"text-[hsl(var(--muted-foreground))] group-hover:text-[hsl(var(--foreground))]"),children:v}),h.error&&n.jsx("span",{className:"inline-flex items-center text-red-500 shrink-0",title:"Workflow error","aria-label":"Workflow error",children:n.jsx(jg,{size:11})}),!h.error&&h.scorerErrors&&h.scorerErrors.length>0&&n.jsx("span",{className:"inline-flex items-center text-amber-500 shrink-0",title:"Scorer errors","aria-label":"Scorer errors",children:n.jsx(kg,{size:11})}),p!=null?n.jsx("span",{className:F("text-[11px] font-mono font-medium shrink-0 tabular-nums",Rt(p)),children:p.toFixed(2)}):n.jsx("span",{className:"text-[10px] text-[hsl(var(--muted-foreground))] shrink-0",children:"-"}),n.jsx(Ba,{size:12,className:F("shrink-0 transition-all",y?"text-[hsl(var(--foreground))] opacity-100":"text-[hsl(var(--muted-foreground))] opacity-0 group-hover:opacity-60")})]},x)})})]})}function h5({name:s,scores:r,mean:i,failed:o,skipped:d}){const f=n.jsx(Hf,{failed:o,skipped:d});return r.length===0?n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsx("span",{className:"w-28 text-xs font-mono truncate text-[hsl(var(--muted-foreground))]",title:s,children:s}),n.jsx("span",{className:"text-xs text-[hsl(var(--muted-foreground))]",children:"No valid scores"}),f]}):n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsxs("span",{className:"w-28 text-xs font-mono truncate",title:s,children:[s,f]}),n.jsxs("div",{className:"flex-1 h-5 relative bg-[hsl(var(--secondary))] rounded",children:[[.25,.5,.75].map(m=>n.jsx("div",{className:"absolute top-0 bottom-0 w-px bg-[hsl(var(--border))]",style:{left:`${m*100}%`}},m)),r.map((m,h)=>n.jsx("div",{className:F("absolute w-1 top-[3px] bottom-[3px] rounded-sm",xc(m)),style:{left:`${Math.max(1,Math.min(99,m*100))}%`,transform:"translateX(-50%)",opacity:.45},title:m.toFixed(3)},h)),n.jsx("div",{className:"absolute top-0 bottom-0 w-0.5 bg-[hsl(var(--foreground))]",style:{left:`${i*100}%`,opacity:.3},title:`Mean: ${i.toFixed(3)}`})]}),n.jsx("span",{className:"w-12 text-xs font-mono text-right text-[hsl(var(--muted-foreground))] tabular-nums",children:i.toFixed(3)})]})}function m5({items:s,scorerNames:r}){const i=b.useMemo(()=>r.map(o=>{const{scores:d,failed:f,skipped:m}=Xg(s,o),h=d.length>0?d.reduce((x,p)=>x+p,0)/d.length:0;return{name:o,scores:d,mean:h,failed:f,skipped:m}}),[s,r]);return r.length===0?null:n.jsxs("div",{className:"rounded-xl border border-[hsl(var(--border))] overflow-hidden",children:[n.jsx("div",{className:"px-4 py-2.5 bg-[hsl(var(--muted))] border-b border-[hsl(var(--border))]",children:n.jsx("h3",{className:"text-[11px] font-medium uppercase tracking-wider text-[hsl(var(--muted-foreground))]",children:"Score Distribution"})}),n.jsxs("div",{className:"p-4 space-y-2",children:[n.jsxs("div",{className:"flex items-center gap-3 mb-1",children:[n.jsx("span",{className:"w-28"}),n.jsxs("div",{className:"flex-1 flex justify-between text-[10px] font-mono text-[hsl(var(--muted-foreground))]",children:[n.jsx("span",{children:"0"}),n.jsx("span",{children:"0.25"}),n.jsx("span",{children:"0.5"}),n.jsx("span",{children:"0.75"}),n.jsx("span",{children:"1.0"})]}),n.jsx("span",{className:"w-12"})]}),i.map(o=>n.jsx(h5,{name:o.name,scores:o.scores,mean:o.mean,failed:o.failed,skipped:o.skipped},o.name))]})]})}function ec({field:s,current:r,dir:i,onSort:o,align:d,className:f,children:m}){const h=r===s;return n.jsxs("th",{className:F(d==="right"?"text-right":"text-left","px-3 py-2 font-medium cursor-pointer select-none hover:text-[hsl(var(--foreground))]",f,d==="left"&&"px-4"),onClick:()=>o(s),children:[m,h&&n.jsx("span",{className:"ml-0.5",children:i==="desc"?"▼":"▲"})]})}function p5({baseline:s,candidate:r,scorerNames:i,baselineRuns:o,candidateRuns:d,scorerTypes:f}){const[m,h]=b.useState(i[0]??""),[x,p]=b.useState("delta"),[v,y]=b.useState("desc"),[E,w]=b.useState(!1),C=o&&o.length>1||d&&d.length>1,_=(o==null?void 0:o.length)??1,R=(d==null?void 0:d.length)??1,[D,H]=b.useState(null),T=S=>{x===S?y(B=>B==="desc"?"asc":"desc"):(p(S),y(S==="index"?"asc":"desc"))},j=Math.min(s.items.length,r.items.length),k=b.useMemo(()=>{var $,W,K,te,re,Me,he,ae;const S=[],B=Math.min((o==null?void 0:o.length)??0,(d==null?void 0:d.length)??0);for(let z=0;z<j;z++){const L=s.items[z].scores[m]??null,ie=r.items[z].scores[m]??null,ve=($=s.items[z].scoreDetails)==null?void 0:$[m],ge=(W=r.items[z].scoreDetails)==null?void 0:W[m],M=(ve==null?void 0:ve.skipped)===!0,Q=(ge==null?void 0:ge.skipped)===!0,G=L==null&&!M&&(ve==null?void 0:ve.duration)!=null,J=ie==null&&!Q&&(ge==null?void 0:ge.duration)!=null,oe=M||Q,me=!oe&&L!=null&&ie!=null?ie-L:0;let be;if(B>1){be=[];for(let X=0;X<B;X++){const ne=(K=o[X])==null?void 0:K.items[z],ce=(te=d[X])==null?void 0:te.items[z],we=ne==null?void 0:ne.scores[m],Re=ce==null?void 0:ce.scores[m];!(((Me=(re=ne==null?void 0:ne.scoreDetails)==null?void 0:re[m])==null?void 0:Me.skipped)===!0||((ae=(he=ce==null?void 0:ce.scoreDetails)==null?void 0:he[m])==null?void 0:ae.skipped)===!0)&&we!=null&&Re!=null&&be.push(Re-we)}}S.push({index:z,input:s.items[z].input,baselineScore:L,candidateScore:ie,delta:me,baselineSkipped:M,candidateSkipped:Q,baselineFailed:G,candidateFailed:J,nonComparable:oe,runDeltas:be})}return S.sort((z,L)=>{let ie,ve;switch(x){case"index":ie=z.index,ve=L.index;break;case"baseline":ie=z.baselineScore??-1,ve=L.baselineScore??-1;break;case"candidate":ie=z.candidateScore??-1,ve=L.candidateScore??-1;break;case"delta":default:ie=Math.abs(z.delta),ve=Math.abs(L.delta);break}return v==="desc"?ve-ie:ie-ve}),S},[s,r,m,x,v,j,o,d]);return i.length===0||j===0?null:n.jsxs("div",{className:"border border-[hsl(var(--border))] rounded-xl overflow-hidden",children:[n.jsxs("button",{onClick:()=>w(S=>!S),className:"w-full flex items-center gap-2 px-4 py-2.5 bg-[hsl(var(--muted))] border-b border-[hsl(var(--border))] hover:bg-[hsl(var(--accent))] transition-colors cursor-pointer",children:[E?n.jsx(Ba,{className:"h-3.5 w-3.5 text-[hsl(var(--muted-foreground))]"}):n.jsx(Bn,{className:"h-3.5 w-3.5 text-[hsl(var(--muted-foreground))]"}),n.jsxs("h3",{className:"text-xs font-medium uppercase tracking-wider text-[hsl(var(--muted-foreground))]",children:["All Items (",j,")",C&&n.jsxs("span",{className:"normal-case tracking-normal font-normal ml-1.5 opacity-70",children:["—"," scores averaged across"," ",_===R?`${_} runs`:`${_} / ${R} runs`]})]})]}),!E&&n.jsxs("div",{children:[n.jsx("div",{className:"flex items-center gap-1.5 px-4 py-2 border-b border-[hsl(var(--border))] bg-[hsl(var(--card))] flex-wrap",children:i.map(S=>n.jsxs("button",{onClick:()=>h(S),className:F("px-2 py-1 text-[11px] font-mono rounded-md transition-colors cursor-pointer",m===S?"bg-[hsl(var(--foreground))] text-[hsl(var(--background))] font-medium":"bg-[hsl(var(--secondary))] text-[hsl(var(--muted-foreground))] hover:bg-[hsl(var(--accent))] hover:text-[hsl(var(--foreground))]"),children:[S,(f==null?void 0:f[S])==="llm"&&n.jsx("span",{className:"ml-1 text-[8px] opacity-70",children:"LLM"})]},S))}),n.jsx("div",{className:"overflow-x-auto",children:n.jsxs("table",{className:"w-full text-xs",children:[n.jsx("thead",{children:n.jsxs("tr",{className:"border-b border-[hsl(var(--border))]",children:[n.jsx(ec,{field:"index",current:x,dir:v,onSort:T,align:"left",className:"w-10",children:"#"}),n.jsx("th",{className:"text-left px-3 py-2 font-medium",children:"Input"}),n.jsxs(ec,{field:"baseline",current:x,dir:v,onSort:T,align:"right",children:["Baseline",C&&_>1&&n.jsxs("span",{className:"font-normal opacity-60 ml-0.5",children:["(",_,")"]})]}),n.jsxs(ec,{field:"candidate",current:x,dir:v,onSort:T,align:"right",children:["Candidate",C&&R>1&&n.jsxs("span",{className:"font-normal opacity-60 ml-0.5",children:["(",R,")"]})]}),n.jsx(ec,{field:"delta",current:x,dir:v,onSort:T,align:"right",children:"Delta"})]})}),n.jsx("tbody",{children:k.map(S=>{const B=D===S.index,$=S.delta>0?"text-emerald-600 dark:text-emerald-400":S.delta<0?"text-red-600 dark:text-red-400":"text-[hsl(var(--muted-foreground))]";return n.jsxs("tr",{className:F("border-b border-[hsl(var(--border))] last:border-b-0 cursor-pointer hover:bg-[hsl(var(--accent))] transition-colors",B&&"bg-[hsl(var(--accent))]"),children:[n.jsx("td",{className:"px-4 py-2.5 font-mono text-[hsl(var(--muted-foreground))]",onClick:()=>H(B?null:S.index),children:S.index+1}),n.jsx("td",{className:"px-3 py-2.5 max-w-xs truncate",onClick:()=>H(B?null:S.index),children:xr(S.input)}),n.jsx("td",{className:F("px-3 py-2.5 text-right font-mono",S.baselineScore!=null?Rt(S.baselineScore):"text-[hsl(var(--muted-foreground))]"),onClick:()=>H(B?null:S.index),children:S.baselineScore!=null?S.baselineScore.toFixed(3):S.baselineSkipped?n.jsx("span",{title:"Not applicable (N/A)",children:"N/A"}):n.jsx("span",{title:S.baselineFailed?"Scorer failed":void 0,children:"—"})}),n.jsx("td",{className:F("px-3 py-2.5 text-right font-mono",S.candidateScore!=null?Rt(S.candidateScore):"text-[hsl(var(--muted-foreground))]"),onClick:()=>H(B?null:S.index),children:S.candidateScore!=null?S.candidateScore.toFixed(3):S.candidateSkipped?n.jsx("span",{title:"Not applicable (N/A)",children:"N/A"}):n.jsx("span",{title:S.candidateFailed?"Scorer failed":void 0,children:"—"})}),n.jsxs("td",{className:F("px-3 py-2.5 text-right",S.nonComparable?"text-[hsl(var(--muted-foreground))]":$),onClick:()=>H(B?null:S.index),children:[n.jsx("div",{className:"font-mono",children:S.nonComparable?n.jsx("span",{title:"Not comparable — a side was skipped (N/A) for this scorer",children:"N/A"}):S.delta!==0?`${S.delta>0?"+":""}${S.delta.toFixed(3)}`:"—"}),S.runDeltas&&S.runDeltas.length>1&&n.jsxs("div",{className:"flex items-center justify-end gap-0.5 mt-1",title:S.runDeltas.map((W,K)=>`Run ${K+1}: ${W>=0?"+":""}${W.toFixed(3)}`).join(", "),children:[S.runDeltas.map((W,K)=>n.jsx("div",{className:F("w-1.5 h-1.5 rounded-full",W<0?"bg-red-500 dark:bg-red-400":W>0?"bg-emerald-500 dark:bg-emerald-400":"bg-[hsl(var(--muted-foreground))]")},K)),n.jsxs("span",{className:"text-[9px] text-[hsl(var(--muted-foreground))] ml-0.5",children:[S.runDeltas.filter(W=>S.delta<0?W<0:W>0).length,"/",S.runDeltas.length]})]})]})]},S.index)})})]})}),D!=null&&D<s.items.length&&D<r.items.length&&n.jsx(Jg,{baselineItem:s.items[D],candidateItem:r.items[D],scorer:m,baselineRunItems:o==null?void 0:o.map(S=>S.items[D]).filter(Boolean),candidateRunItems:d==null?void 0:d.map(S=>S.items[D]).filter(Boolean)})]})]})}function x5({stats:s}){const r=s.n,i=s.baselineScored,o=s.candidateScored,d=s.baselineSkipped??0,f=s.candidateSkipped??0,m=s.baselineFailed??0,h=s.candidateFailed??0;if(!(r!=null&&i!=null&&o!=null&&(d+f+m+h>0||r<Math.min(i,o))))return null;const p=(v,y,E)=>`${v} scored${y>0?`, ${y} N/A`:""}${E>0?`, ${E} failed`:""}`;return n.jsxs("div",{className:"font-mono text-[10px] text-[hsl(var(--muted-foreground))] mt-0.5 underline decoration-dotted underline-offset-2 cursor-help",title:`Delta compares per-side means — baseline over ${p(i,d,m)}; candidate over ${p(o,f,h)}. The CI / significance use the ${r} item(s) scored on BOTH sides, so the delta and CI rest on different samples here.`,children:["paired n=",r," · per-side ",i,"/",o]})}function g5({text:s,children:r}){return n.jsxs("span",{className:"relative group/tip cursor-help",children:[r,n.jsx("span",{className:"invisible group-hover/tip:visible absolute bottom-full left-1/2 -translate-x-1/2 mb-1.5 px-2.5 py-1.5 text-[10px] leading-snug rounded-md bg-[hsl(var(--foreground))] text-[hsl(var(--background))] whitespace-normal w-56 z-50 shadow-md pointer-events-none",children:s})]})}function N0({value:s,percent:r,invert:i,format:o}){const d=i?s<0:s>0,f=i?s>0:s<0,m=d?"text-emerald-600 dark:text-emerald-400":f?"text-red-600 dark:text-red-400":"text-[hsl(var(--muted-foreground))]",h=o?`${s>0?"+":s<0?"-":""}${o(Math.abs(s))}`:`${s>0?"+":""}${Math.abs(s)<100?s.toFixed(3):s.toFixed(0)}`,x=`${r>0?"+":""}${r.toFixed(1)}%`;return n.jsx("td",{className:F("px-3 py-2.5 text-right",m),children:n.jsxs("div",{className:"font-mono",children:[h," (",x,")"]})})}function S0(s){return(s>=0?"+":"")+s.toFixed(4)}function v5({compareResult:s,baseline:r,candidate:i,isGroupComparison:o,baselineRuns:d,candidateRuns:f}){var L,ie,ve,ge,M,Q;const[m,h]=b.useState(null),[x,p]=b.useState("delta"),[v,y]=b.useState("desc"),[E,w]=b.useState({}),C=(G,J)=>{(m==null?void 0:m.type)===G&&(m==null?void 0:m.index)===J?h(null):h({type:G,index:J})},_=((L=r==null?void 0:r.metadata)==null?void 0:L.scorerTypes)??((ie=i==null?void 0:i.metadata)==null?void 0:ie.scorerTypes),R=(d==null?void 0:d.length)??1,D=(f==null?void 0:f.length)??1,H=o?`averaged across ${R===D?`${R} runs`:`${R} / ${D} runs`}`:null,T=(ve=s.baseline)==null?void 0:ve.partial,j=(ge=s.candidate)==null?void 0:ge.partial,k=(M=s.baseline)==null?void 0:M.runCount,S=(Q=s.candidate)==null?void 0:Q.runCount,B=k!=null&&d!=null&&k<d.length,$=S!=null&&f!=null&&S<f.length,W=B||$,K=b.useMemo(()=>{const G=Object.entries(s.scorers);return G.sort((J,oe)=>{if(x==="delta"){const X=J[1].significant===!0?1:0,ne=oe[1].significant===!0?1:0;if(X!==ne)return ne-X}let me,be;switch(x){case"metric":return v==="asc"?J[0].localeCompare(oe[0]):oe[0].localeCompare(J[0]);case"baseline":me=J[1].baselineMean,be=oe[1].baselineMean;break;case"candidate":me=J[1].candidateMean,be=oe[1].candidateMean;break;case"delta":default:me=Math.abs(J[1].delta),be=Math.abs(oe[1].delta);break}return v==="desc"?be-me:me-be}),G},[s.scorers,x,v]),te=K.some(([,G])=>G.ci!=null),re=G=>{x===G?y(J=>J==="desc"?"asc":"desc"):(p(G),y("desc"))},Me=G=>x===G?v==="desc"?" ▼":" ▲":"",he=K.filter(([,G])=>G.significant===!0).length,ae=s.regressions.length,z=s.improvements.length;return n.jsxs("div",{className:"space-y-6",children:[(T||j)&&n.jsx("div",{className:"flex items-start gap-2.5 px-4 py-3 rounded-xl border border-amber-300/60 dark:border-amber-500/40 bg-amber-50 dark:bg-amber-950/40",role:"status",children:n.jsxs("div",{className:"text-sm text-amber-900 dark:text-amber-200",children:[n.jsx("div",{className:"font-medium",children:"Partial batch in this comparison."}),n.jsxs("ul",{className:"mt-1 space-y-0.5 text-amber-800/90 dark:text-amber-300/90 list-disc list-inside",children:[T&&n.jsxs("li",{children:["Baseline pooled ",T.completed," of an attempted"," ",T.attempted," runs."]}),j&&n.jsxs("li",{children:["Candidate pooled ",j.completed," of an attempted"," ",j.attempted," runs."]})]}),n.jsx("div",{className:"mt-1 text-amber-800/80 dark:text-amber-300/80",children:"Statistics below are computed honestly for the included runs."})]})}),W&&n.jsx("div",{className:"flex items-start gap-2.5 px-4 py-3 rounded-xl border border-blue-300/60 dark:border-blue-500/40 bg-blue-50 dark:bg-blue-950/40",role:"status",children:n.jsxs("div",{className:"text-sm text-blue-900 dark:text-blue-200",children:[n.jsxs("div",{className:"font-medium",children:["Comparing ",k," baseline vs ",S," candidate run",S===1?"":"s","."]}),n.jsxs("div",{className:"mt-1 text-blue-800/90 dark:text-blue-300/90",children:["You pooled ",(d==null?void 0:d.length)??1," baseline and ",(f==null?void 0:f.length)??1," ","candidate run",((f==null?void 0:f.length)??1)===1?"":"s","; the comparison uses the first ",Math.min(k??0,S??0)," from each side so the displayed means and paired bootstrap CI are computed over the same sample. Re-pool symmetrically if you want every selected run included."]})]})}),K.length>0&&(()=>{const G=K.some(([,X])=>X.significant===!0&&X.delta<0),J=K.some(([,X])=>X.significant===!0&&X.delta>0),oe=s.regressions.length>0,me=K.every(([,X])=>X.significant===!1),be=(X,ne)=>{const ce=ne.delta<0?ne.pRegression!=null?`${Math.round(ne.pRegression*100)}%`:null:ne.pImprovement!=null?`${Math.round(ne.pImprovement*100)}%`:null,we=`${ne.delta>0?"+":""}${ne.delta.toFixed(3)}`;return`${X} ${we}${ce?` (${ce} probability)`:""}`};if(G){const X=K.filter(([,ne])=>ne.significant===!0&&ne.delta<0);return n.jsxs("div",{className:"flex items-start gap-2.5 px-4 py-3 rounded-xl border border-red-200 dark:border-red-900 bg-red-50 dark:bg-red-950/30",children:[n.jsx("div",{className:"h-6 w-6 rounded-full bg-red-100 dark:bg-red-900/50 flex items-center justify-center shrink-0 mt-0.5",children:n.jsx("span",{className:"text-red-600 dark:text-red-400 text-xs font-bold",children:"✕"})}),n.jsxs("div",{children:[n.jsx("p",{className:"text-sm font-medium text-red-800 dark:text-red-200",children:"Significant regression detected"}),n.jsx("p",{className:"text-xs text-red-600 dark:text-red-400 mt-0.5",children:X.map(([ne,ce])=>be(ne,ce)).join("; ")})]})]})}if(J){const X=K.filter(([,ne])=>ne.significant===!0&&ne.delta>0);return n.jsxs("div",{className:"flex items-start gap-2.5 px-4 py-3 rounded-xl border border-emerald-200 dark:border-emerald-900 bg-emerald-50 dark:bg-emerald-950/30",children:[n.jsx("div",{className:"h-6 w-6 rounded-full bg-emerald-100 dark:bg-emerald-900/50 flex items-center justify-center shrink-0 mt-0.5",children:n.jsx("span",{className:"text-emerald-600 dark:text-emerald-400 text-xs font-bold",children:"✓"})}),n.jsxs("div",{children:[n.jsx("p",{className:"text-sm font-medium text-emerald-800 dark:text-emerald-200",children:"Significant improvement detected"}),n.jsx("p",{className:"text-xs text-emerald-600 dark:text-emerald-400 mt-0.5",children:X.map(([ne,ce])=>be(ne,ce)).join("; ")})]})]})}return oe&&me?n.jsxs("div",{className:"flex items-center gap-2.5 px-4 py-3 rounded-xl border border-amber-200 dark:border-amber-900 bg-amber-50 dark:bg-amber-950/30",children:[n.jsx("div",{className:"h-6 w-6 rounded-full bg-amber-100 dark:bg-amber-900/50 flex items-center justify-center shrink-0",children:n.jsx("span",{className:"text-amber-600 dark:text-amber-400 text-xs font-bold",children:"~"})}),n.jsxs("div",{children:[n.jsxs("p",{className:"text-sm font-medium text-amber-800 dark:text-amber-200",children:[s.regressions.length," item regressions, but not statistically significant"]}),n.jsx("p",{className:"text-xs text-amber-600 dark:text-amber-400",children:o?"Even with pooled multi-run data, the score differences are within normal variation.":"Score differences are within normal LLM variation. Consider multi-run for stronger confidence."})]})]}):n.jsxs("div",{className:"flex items-center gap-2.5 px-4 py-3 rounded-xl border border-[hsl(var(--border))] bg-[hsl(var(--muted))]",children:[n.jsx("div",{className:"h-6 w-6 rounded-full bg-emerald-100 dark:bg-emerald-900/50 flex items-center justify-center shrink-0",children:n.jsx("span",{className:"text-emerald-600 dark:text-emerald-400 text-xs font-bold",children:"✓"})}),n.jsxs("div",{children:[n.jsx("p",{className:"text-sm font-medium",children:"No significant changes"}),n.jsx("p",{className:"text-xs text-[hsl(var(--muted-foreground))]",children:"Scores are stable between baseline and candidate"})]})]})})(),(()=>{const G=($e,Ja)=>{const dn=Ja&&Ja.length>0?Ja:$e?[$e]:[],Ia=new Set;for(const fn of dn)for(const Ea of $n(fn))Ia.add(Ea);return[...Ia]},J=d&&d.length>0?d:r?[r]:[],oe=f&&f.length>0?f:i?[i]:[],me=($e,Ja)=>{const dn=Ja&&Ja.length>0?Ja:$e?[$e]:[],Ia=new Set,fn=[];for(const Ea of dn)for(const Nt of tr(Ea))Ia.has(Nt)||(Ia.add(Nt),fn.push(Nt));return fn},be=G(r,d),X=G(i,f),ne=me(r,d),ce=me(i,f),we=x0(J),Re=x0(oe),dt=we.input+we.output+we.reasoning,yt=Re.input+Re.output+Re.reasoning,pe=g0(J),Te=g0(oe),Ie=ne.length>0||ce.length>0,ye=new Set(ne),Je=new Set(ce),jt=ye.size!==Je.size||ne.some($e=>!Je.has($e)),Dt=be.length>0||X.length>0,Ca=dt>0&&yt>0,zt=pe>0||Te>0;if(!Ie&&!Dt&&!Ca&&!zt)return null;const Be=new Set(be),fa=new Set(X),$a=Be.size!==fa.size||be.some($e=>!fa.has($e)),ha=dt>0?(yt-dt)/dt*100:0;return n.jsxs("div",{className:"flex items-center gap-3 px-4 py-2.5 rounded-lg bg-[hsl(var(--muted))]/50 text-xs flex-wrap",children:[Ie&&n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"text-[hsl(var(--muted-foreground))] uppercase tracking-wider text-[10px] font-medium shrink-0",children:ne.length>1||ce.length>1?"Workflows":"Workflow"}),n.jsx("div",{className:"flex items-center gap-1.5",children:ne.length>0?ne.map($e=>n.jsx("span",{className:"px-1.5 py-0.5 rounded border border-[hsl(var(--border))] bg-[hsl(var(--background))] font-mono",title:$e,children:$e},$e)):n.jsx("span",{className:"text-[hsl(var(--muted-foreground))] italic",children:"unknown"})}),n.jsx("span",{className:"text-[hsl(var(--muted-foreground))]",children:"→"}),n.jsx("div",{className:"flex items-center gap-1.5",children:ce.length>0?ce.map($e=>n.jsx("span",{className:F("px-1.5 py-0.5 rounded font-mono",jt?"bg-blue-100 dark:bg-blue-900/30 text-blue-700 dark:text-blue-300":"border border-[hsl(var(--border))] bg-[hsl(var(--background))]"),title:$e,children:$e},$e)):n.jsx("span",{className:"text-[hsl(var(--muted-foreground))] italic",children:"unknown"})}),jt&&n.jsx("span",{className:"text-[10px] font-medium text-blue-600 dark:text-blue-400",children:"changed"})]}),Dt&&n.jsxs(n.Fragment,{children:[Ie&&n.jsx("span",{className:"text-[hsl(var(--border))]",children:"|"}),n.jsx("span",{className:"text-[hsl(var(--muted-foreground))] uppercase tracking-wider text-[10px] font-medium shrink-0",children:"Models"}),n.jsx("div",{className:"flex items-center gap-1.5",children:be.length>0?be.map($e=>n.jsx("span",{className:"px-1.5 py-0.5 rounded border border-[hsl(var(--border))] bg-[hsl(var(--background))] font-mono",title:$e,children:wa($e)},$e)):n.jsx("span",{className:"text-[hsl(var(--muted-foreground))] italic",children:"unknown"})}),n.jsx("span",{className:"text-[hsl(var(--muted-foreground))]",children:"→"}),n.jsx("div",{className:"flex items-center gap-1.5",children:X.length>0?X.map($e=>n.jsx("span",{className:F("px-1.5 py-0.5 rounded font-mono",$a?"bg-blue-100 dark:bg-blue-900/30 text-blue-700 dark:text-blue-300":"border border-[hsl(var(--border))] bg-[hsl(var(--background))]"),title:$e,children:wa($e)},$e)):n.jsx("span",{className:"text-[hsl(var(--muted-foreground))] italic",children:"unknown"})}),$a&&n.jsx("span",{className:"text-[10px] font-medium text-blue-600 dark:text-blue-400",children:"changed"})]}),Ca&&n.jsxs(n.Fragment,{children:[Dt&&n.jsx("span",{className:"text-[hsl(var(--border))]",children:"|"}),n.jsx("span",{className:"text-[hsl(var(--muted-foreground))] uppercase tracking-wider text-[10px] font-medium shrink-0",children:"Tokens"}),n.jsx("span",{className:"font-mono",children:dt.toLocaleString()}),n.jsx("span",{className:"text-[hsl(var(--muted-foreground))]",children:"→"}),n.jsx("span",{className:"font-mono",children:yt.toLocaleString()}),Math.abs(ha)>=1&&n.jsxs("span",{className:F("text-[10px] font-medium",ha>0?"text-red-600 dark:text-red-400":"text-emerald-600 dark:text-emerald-400"),children:[ha>0?"+":"",ha.toFixed(0),"%"]})]}),zt&&n.jsxs(n.Fragment,{children:[(Dt||Ca)&&n.jsx("span",{className:"text-[hsl(var(--border))]",children:"|"}),n.jsx("span",{className:"text-[hsl(var(--muted-foreground))] uppercase tracking-wider text-[10px] font-medium shrink-0",children:"Cost"}),n.jsx("span",{className:"font-mono",children:at(pe)}),n.jsx("span",{className:"text-[hsl(var(--muted-foreground))]",children:"→"}),n.jsx("span",{className:"font-mono",children:at(Te)}),pe>0&&Te>0&&(()=>{const $e=(Te-pe)/pe*100;return Math.abs($e)>=1?n.jsxs("span",{className:F("text-[10px] font-medium",$e>0?"text-red-600 dark:text-red-400":"text-emerald-600 dark:text-emerald-400"),children:[$e>0?"+":"",$e.toFixed(0),"%"]}):null})()]})]})})(),n.jsxs("div",{className:"grid grid-cols-4 gap-3",children:[n.jsxs("div",{className:"px-3 py-2 rounded-lg border border-[hsl(var(--border))] bg-[hsl(var(--card))]",children:[n.jsx("div",{className:"text-[10px] uppercase tracking-wider text-[hsl(var(--muted-foreground))]",children:"Significant"}),n.jsx("div",{className:"text-lg font-semibold mt-0.5",children:he})]}),n.jsxs("div",{className:"px-3 py-2 rounded-lg border border-[hsl(var(--border))] bg-[hsl(var(--card))]",children:[n.jsx("div",{className:"text-[10px] uppercase tracking-wider text-[hsl(var(--muted-foreground))]",children:"Regressions"}),n.jsx("div",{className:F("text-lg font-semibold mt-0.5",ae>0?"text-red-600 dark:text-red-400":""),children:ae})]}),n.jsxs("div",{className:"px-3 py-2 rounded-lg border border-[hsl(var(--border))] bg-[hsl(var(--card))]",children:[n.jsx("div",{className:"text-[10px] uppercase tracking-wider text-[hsl(var(--muted-foreground))]",children:"Improvements"}),n.jsx("div",{className:F("text-lg font-semibold mt-0.5",z>0?"text-emerald-600 dark:text-emerald-400":""),children:z})]}),s.cost&&n.jsxs("div",{className:"px-3 py-2 rounded-lg border border-[hsl(var(--border))] bg-[hsl(var(--card))]",children:[n.jsx("div",{className:"text-[10px] uppercase tracking-wider text-[hsl(var(--muted-foreground))]",children:"Cost Delta"}),n.jsxs("div",{className:F("text-lg font-semibold mt-0.5",s.cost.delta>0?"text-red-600 dark:text-red-400":s.cost.delta<0?"text-emerald-600 dark:text-emerald-400":""),children:[s.cost.delta>0?"+":"",at(Math.abs(s.cost.delta))]})]})]}),K.length>0&&n.jsxs("div",{className:"border border-[hsl(var(--border))] rounded-xl overflow-hidden",children:[n.jsx("div",{className:"px-4 py-2.5 bg-[hsl(var(--muted))] border-b border-[hsl(var(--border))]",children:n.jsxs("h3",{className:"text-xs font-medium uppercase tracking-wider text-[hsl(var(--muted-foreground))]",children:["Scorer Comparison",H&&n.jsxs("span",{className:"normal-case tracking-normal font-normal ml-1.5 opacity-70",children:["—"," ",H]})]})}),n.jsx("div",{className:"overflow-x-auto",children:n.jsxs("table",{className:"w-full text-xs",children:[n.jsx("thead",{children:n.jsxs("tr",{className:"border-b border-[hsl(var(--border))]",children:[n.jsxs("th",{className:"text-left px-4 py-2 font-medium cursor-pointer select-none hover:text-[hsl(var(--foreground))]",onClick:()=>re("metric"),children:["Metric",Me("metric")]}),n.jsxs("th",{className:"text-right px-3 py-2 font-medium cursor-pointer select-none hover:text-[hsl(var(--foreground))]",onClick:()=>re("baseline"),children:["Baseline",o&&R>1&&n.jsxs("span",{className:"font-normal opacity-60 ml-0.5",children:["(",R,")"]}),T&&n.jsxs("span",{className:"font-normal ml-1 px-1 py-0.5 rounded text-[9px] uppercase tracking-wide bg-amber-100 text-amber-900 dark:bg-amber-950/60 dark:text-amber-200",title:`Partial batch — ${T.completed} of ${T.attempted} runs included`,children:[T.completed,"/",T.attempted]}),Me("baseline")]}),n.jsxs("th",{className:"text-right px-3 py-2 font-medium cursor-pointer select-none hover:text-[hsl(var(--foreground))]",onClick:()=>re("candidate"),children:["Candidate",o&&D>1&&n.jsxs("span",{className:"font-normal opacity-60 ml-0.5",children:["(",D,")"]}),j&&n.jsxs("span",{className:"font-normal ml-1 px-1 py-0.5 rounded text-[9px] uppercase tracking-wide bg-amber-100 text-amber-900 dark:bg-amber-950/60 dark:text-amber-200",title:`Partial batch — ${j.completed} of ${j.attempted} runs included`,children:[j.completed,"/",j.attempted]}),Me("candidate")]}),n.jsx("th",{className:"text-right px-3 py-2 font-medium cursor-pointer select-none hover:text-[hsl(var(--foreground))]",onClick:()=>re("delta"),children:te?n.jsxs(g5,{text:"Score delta with 95% confidence interval via paired bootstrap. If the CI excludes zero and the effect exceeds the practical threshold, the difference is significant (shown with a colored left border). The Baseline and Candidate columns are per-side means (each over that side's own scored items); the CI is paired over items scored on BOTH sides. A per-row 'paired n' note appears when the two samples diverge — different skips (N/A) or failures per side.",children:["Delta",Me("delta")]}):n.jsxs(n.Fragment,{children:["Delta",Me("delta")]})})]})}),n.jsxs("tbody",{children:[K.map(([G,J])=>{const oe=J.delta>0?"+":(J.delta<0,""),me=J.delta>0?"text-emerald-600 dark:text-emerald-400":J.delta<0?"text-red-600 dark:text-red-400":"text-[hsl(var(--muted-foreground))]";return n.jsxs("tr",{className:F("border-b border-[hsl(var(--border))] last:border-b-0",J.significant===!0&&J.delta<0&&"border-l-[3px] border-l-red-500",J.significant===!0&&J.delta>0&&"border-l-[3px] border-l-emerald-500"),children:[n.jsxs("td",{className:"px-4 py-2.5 font-mono",children:[G,(_==null?void 0:_[G])==="llm"&&n.jsx("span",{className:"ml-1.5 px-1 py-0.5 text-[9px] font-medium rounded bg-purple-100 text-purple-600 dark:bg-purple-900/30 dark:text-purple-400 align-middle",title:"LLM scorer — scores may vary between runs",children:"LLM"})]}),n.jsx("td",{className:F("px-3 py-2.5 text-right font-mono",J.baselineScored===0?"text-[hsl(var(--muted-foreground))]":Rt(J.baselineMean)),children:J.baselineMean.toFixed(3)}),n.jsx("td",{className:F("px-3 py-2.5 text-right font-mono",J.candidateScored===0?"text-[hsl(var(--muted-foreground))]":Rt(J.candidateMean)),children:J.candidateMean.toFixed(3)}),n.jsxs("td",{className:"px-3 py-2.5 text-right",children:[n.jsxs("div",{className:F("font-mono",me),children:[oe,Math.abs(J.delta).toFixed(3)," (",oe,Math.abs(J.deltaPercent).toFixed(1),"%)"]}),J.ci&&n.jsxs("div",{className:"font-mono text-[10px] text-[hsl(var(--muted-foreground))] mt-0.5",children:["CI [",S0(J.ci.lower),", ",S0(J.ci.upper),"]"]}),J.pRegression!=null&&J.pImprovement!=null&&(()=>{const be=J.pRegression??0,X=J.pImprovement??0;if(be===0&&X===0)return null;let ne,ce,we;if(be>X)ce=be,ne="regression",we=Math.round(ce*100)>=95?"text-red-600 dark:text-red-400":"text-[hsl(var(--muted-foreground))]";else if(X>be)ce=X,ne="improvement",we=Math.round(ce*100)>=95?"text-emerald-600 dark:text-emerald-400":"text-[hsl(var(--muted-foreground))]";else return null;const Re=Math.round(ce*100);return n.jsxs("div",{className:F("text-[10px] mt-0.5",we),children:[Re,"% probability of ",ne,J.n!=null&&n.jsxs("span",{className:"opacity-60 ml-1",children:["(n=",J.n,")"]})]})})(),n.jsx(x5,{stats:J})]})]},G)}),s.timing&&n.jsxs("tr",{className:"border-t-2 border-[hsl(var(--border))]",children:[n.jsx("td",{className:"px-4 py-2.5 font-mono text-[hsl(var(--muted-foreground))]",children:"Timing (mean)"}),n.jsx("td",{className:"px-3 py-2.5 text-right font-mono text-[hsl(var(--muted-foreground))]",children:xt(s.timing.baselineMean)}),n.jsx("td",{className:"px-3 py-2.5 text-right font-mono text-[hsl(var(--muted-foreground))]",children:xt(s.timing.candidateMean)}),n.jsx(N0,{value:s.timing.delta,percent:s.timing.deltaPercent,invert:!0,format:xt})]}),s.cost!=null&&n.jsxs("tr",{className:"border-t border-[hsl(var(--border))]",children:[n.jsx("td",{className:"px-4 py-2.5 font-mono text-[hsl(var(--muted-foreground))]",children:"Cost (total)"}),n.jsx("td",{className:"px-3 py-2.5 text-right font-mono text-[hsl(var(--muted-foreground))]",children:at(s.cost.baselineTotal)}),n.jsx("td",{className:"px-3 py-2.5 text-right font-mono text-[hsl(var(--muted-foreground))]",children:at(s.cost.candidateTotal)}),n.jsx(N0,{value:s.cost.delta,percent:s.cost.deltaPercent,invert:!0,format:at})]})]})]})})]}),[{type:"regression",items:s.regressions,borderColor:"border-red-200 dark:border-red-900",bgColor:"bg-red-50 dark:bg-red-950/30",textColor:"text-red-700 dark:text-red-300",deltaColor:"text-red-600 dark:text-red-400",label:"Regressions",direction:-1},{type:"improvement",items:s.improvements,borderColor:"border-emerald-200 dark:border-emerald-900",bgColor:"bg-emerald-50 dark:bg-emerald-950/30",textColor:"text-emerald-700 dark:text-emerald-300",deltaColor:"text-emerald-600 dark:text-emerald-400",label:"Improvements",direction:1}].filter(G=>G.items.length>0).map(G=>{const J=d&&f&&d.length>1,oe=J?Math.min(d.length,f.length):0,me=G.items.map((ye,Je)=>{var Dt,Ca,zt,Be;let jt=0;if(J)for(let fa=0;fa<oe;fa++){const $a=(Ca=(Dt=d[fa])==null?void 0:Dt.items[ye.itemIndex])==null?void 0:Ca.scores[ye.scorer],ha=(Be=(zt=f[fa])==null?void 0:zt.items[ye.itemIndex])==null?void 0:Be.scores[ye.scorer];$a!=null&&ha!=null&&(G.direction<0?ha<$a:ha>$a)&&jt++}return{...ye,originalIndex:Je,consistentCount:jt,totalRuns:oe}});J?me.sort((ye,Je)=>Je.consistentCount-ye.consistentCount||Math.abs(Je.delta)-Math.abs(ye.delta)):me.sort((ye,Je)=>Math.abs(Je.delta)-Math.abs(ye.delta));const be=[...new Set(G.items.map(ye=>ye.scorer))],X=be.length===1?be[0]:null,ne=new Map;for(const ye of me)ne.has(ye.scorer)||ne.set(ye.scorer,[]),ne.get(ye.scorer).push(ye);const ce=ye=>{const Je=(m==null?void 0:m.type)===G.type&&m.index===ye.originalIndex,jt=r==null?void 0:r.items[ye.itemIndex],Dt=i==null?void 0:i.items[ye.itemIndex],Ca=ye.input?xr(ye.input,40):`Item #${ye.itemIndex+1}`,zt=J?ye.consistentCount===oe?"":ye.consistentCount===0?"opacity-40":"opacity-65":"";return n.jsxs("div",{className:zt,children:[n.jsxs("button",{onClick:()=>C(G.type,ye.originalIndex),className:"w-full text-left flex items-center gap-3 px-4 py-2.5 text-xs hover:bg-[hsl(var(--accent))] transition-colors cursor-pointer",children:[J&&n.jsxs("span",{className:F("shrink-0 text-[10px] font-mono font-medium px-1.5 py-0.5 rounded",ye.consistentCount===oe?G.type==="regression"?"bg-red-100 dark:bg-red-900/40 text-red-700 dark:text-red-300":"bg-emerald-100 dark:bg-emerald-900/40 text-emerald-700 dark:text-emerald-300":"bg-[hsl(var(--muted))] text-[hsl(var(--muted-foreground))]"),children:[ye.consistentCount,"/",oe]}),n.jsxs("span",{className:"min-w-0 truncate flex-1",children:[n.jsxs("span",{className:"font-mono text-[hsl(var(--muted-foreground))]",children:["#",ye.itemIndex+1]})," ",n.jsx("span",{children:Ca})]}),n.jsxs("span",{className:F("font-mono shrink-0",G.deltaColor),children:[ye.baselineScore.toFixed(2)," ","→"," ",ye.candidateScore.toFixed(2)," ",n.jsxs("span",{className:"text-[hsl(var(--muted-foreground))]",children:["(",ye.delta>0?"+":"",ye.delta.toFixed(2),")"]})]})]}),Je&&jt&&Dt&&n.jsx(Jg,{baselineItem:jt,candidateItem:Dt,scorer:ye.scorer,baselineRunItems:d==null?void 0:d.map(Be=>Be.items[ye.itemIndex]).filter(Boolean),candidateRunItems:f==null?void 0:f.map(Be=>Be.items[ye.itemIndex]).filter(Boolean)})]},ye.originalIndex)},we=5;let Re,dt;if(J){const ye=Math.ceil(oe/2);Re=me.filter(Je=>Je.consistentCount>=ye),dt=me.filter(Je=>Je.consistentCount<ye)}else Re=me.slice(0,we),dt=me.slice(we);const yt=E[G.type]??!1,pe=J?`${dt.length} likely noise (minority of runs)`:`${dt.length} more`,Te=ye=>{const Je=new Map;for(const jt of ye)Je.has(jt.scorer)||Je.set(jt.scorer,[]),Je.get(jt.scorer).push(jt);return Je},Ie=ye=>{if(X)return n.jsx("div",{className:"divide-y divide-[hsl(var(--border))]",children:ye.map(ce)});const Je=Te(ye);return n.jsx("div",{children:[...Je.entries()].map(([jt,Dt])=>n.jsxs("div",{children:[n.jsxs("div",{className:F("px-4 py-2 border-b border-t border-[hsl(var(--border))]",G.type==="regression"?"bg-red-50/30 dark:bg-red-950/5":"bg-emerald-50/30 dark:bg-emerald-950/5"),children:[n.jsx("span",{className:"text-[10px] font-medium uppercase tracking-wider text-[hsl(var(--muted-foreground))]",children:jt}),n.jsxs("span",{className:"text-[10px] text-[hsl(var(--muted-foreground))] ml-1.5",children:["(",Dt.length,")"]})]}),n.jsx("div",{className:"divide-y divide-[hsl(var(--border))]",children:Dt.map(ce)})]},jt))})};return n.jsxs("div",{className:F("border rounded-lg overflow-hidden",G.borderColor),children:[n.jsx("div",{className:F("px-4 py-2.5 border-b",G.bgColor,G.borderColor),children:n.jsxs("h3",{className:F("text-xs font-medium",G.textColor),children:[G.label," (",Re.length,dt.length>0?` + ${dt.length} noise`:"",")",H&&n.jsxs("span",{className:"font-normal opacity-70 ml-1",children:[" — ","scores ",H]})]})}),Re.length>0?Ie(Re):n.jsxs("div",{className:"px-4 py-3 text-xs text-[hsl(var(--muted-foreground))]",children:["No reliable ",G.label.toLowerCase()," detected (all within noise)."]}),dt.length>0&&n.jsxs(n.Fragment,{children:[n.jsxs("button",{onClick:()=>w(ye=>({...ye,[G.type]:!yt})),className:"w-full flex items-center justify-center gap-1.5 px-4 py-2 text-[11px] font-medium text-[hsl(var(--muted-foreground))] hover:text-[hsl(var(--foreground))] transition-colors border-t border-dashed border-[hsl(var(--border))] cursor-pointer",children:[yt?n.jsx(Jj,{className:"h-3 w-3"}):n.jsx(Bn,{className:"h-3 w-3"}),yt?"Hide":"Show"," ",pe]}),yt&&Ie(dt)]})]},G.type)}),r&&i&&n.jsx(p5,{baseline:r,candidate:i,scorerNames:K.map(([G])=>G),baselineRuns:d??void 0,candidateRuns:f??void 0,scorerTypes:_})]})}function w0({label:s,item:r,scorer:i}){var f,m;const o=(f=r.scoreDetails)==null?void 0:f[i],d=typeof((m=o==null?void 0:o.metadata)==null?void 0:m.reasoning)=="string"?o.metadata.reasoning:null;return n.jsxs("div",{className:"p-4 space-y-3",children:[n.jsx("h5",{className:"font-medium text-[hsl(var(--muted-foreground))] uppercase tracking-wider text-[10px]",children:s}),n.jsx(Ct,{data:r.output,collapsed:!0}),(o==null?void 0:o.score)!=null&&n.jsxs("div",{className:"flex items-center gap-1.5",children:[n.jsx("span",{className:"text-[hsl(var(--muted-foreground))]",children:"Score:"}),n.jsx("span",{className:F("px-2 py-0.5 rounded-full font-mono font-medium",uc(o.score)),children:o.score.toFixed(3)})]}),d&&n.jsxs("div",{children:[n.jsx("span",{className:"font-medium text-[hsl(var(--muted-foreground))] text-[10px] uppercase tracking-wider block mb-1",children:"Reasoning"}),n.jsx("pre",{className:"text-xs font-mono p-2 rounded-md bg-[hsl(var(--secondary))] overflow-auto max-h-48 whitespace-pre-wrap leading-relaxed",children:d})]})]})}function Jg({baselineItem:s,candidateItem:r,scorer:i,baselineRunItems:o,candidateRunItems:d}){var w,C,_,R;const[f,m]=b.useState(0),h=o&&o.length>1||d&&d.length>1,x=Math.max((o==null?void 0:o.length)??1,(d==null?void 0:d.length)??1),p=h&&o?o[f]??s:s,v=h&&d?d[f]??r:r,y=(C=(w=s.scoreDetails)==null?void 0:w[i])==null?void 0:C.score,E=(R=(_=r.scoreDetails)==null?void 0:_[i])==null?void 0:R.score;return n.jsxs("div",{className:"border-t border-[hsl(var(--border))] bg-[hsl(var(--card))] text-xs",children:[h&&(y!=null||E!=null)&&n.jsxs("div",{className:"flex items-center gap-4 px-4 py-2 border-b border-[hsl(var(--border))] bg-[hsl(var(--card))]",children:[n.jsxs("span",{className:"text-[10px] font-medium uppercase tracking-wider text-[hsl(var(--muted-foreground))]",children:["Mean across ",x," runs"]}),n.jsxs("div",{className:"flex items-center gap-3",children:[y!=null&&n.jsxs("span",{className:"flex items-center gap-1",children:[n.jsx("span",{className:"text-[hsl(var(--muted-foreground))]",children:"Baseline:"}),n.jsx("span",{className:F("font-mono font-medium",Rt(y)),children:y.toFixed(3)})]}),E!=null&&n.jsxs("span",{className:"flex items-center gap-1",children:[n.jsx("span",{className:"text-[hsl(var(--muted-foreground))]",children:"Candidate:"}),n.jsx("span",{className:F("font-mono font-medium",Rt(E)),children:E.toFixed(3)})]}),y!=null&&E!=null&&n.jsxs("span",{className:F("font-mono",E-y>0?"text-emerald-600 dark:text-emerald-400":E-y<0?"text-red-600 dark:text-red-400":"text-[hsl(var(--muted-foreground))]"),children:["(",E-y>0?"+":"",(E-y).toFixed(3),")"]})]})]}),h&&n.jsxs("div",{className:"flex items-center gap-2 px-4 py-2 border-b border-[hsl(var(--border))] bg-[hsl(var(--muted))]",children:[n.jsx("span",{className:"text-[10px] font-medium uppercase tracking-wider text-[hsl(var(--muted-foreground))]",children:"Run"}),n.jsx("div",{className:"flex items-center gap-0.5",children:Array.from({length:x},(D,H)=>n.jsx("button",{onClick:()=>m(H),className:F("px-2 py-0.5 rounded text-[10px] font-mono transition-colors cursor-pointer",H===f?"bg-[hsl(var(--foreground))] text-[hsl(var(--background))]":"text-[hsl(var(--muted-foreground))] hover:bg-[hsl(var(--accent))]"),children:H+1},H))}),n.jsxs("span",{className:"text-[10px] text-[hsl(var(--muted-foreground))] ml-auto",children:["Showing output and reasoning from run ",f+1," of ",x]})]}),n.jsxs("div",{className:"grid grid-cols-2 gap-0",children:[n.jsx("div",{className:"border-r border-[hsl(var(--border))]",children:n.jsx(w0,{label:"Baseline",item:p,scorer:i})}),n.jsx(w0,{label:"Candidate",item:v,scorer:i})]})]})}function dc(s){const r=Date.now()-s;return r<6e4?"just now":r<36e5?`${Math.floor(r/6e4)}m ago`:r<864e5?`${Math.floor(r/36e5)}h ago`:new Date(s).toLocaleDateString()}function qf(s){return s.data.dataset??""}function b5(s){var r;return(r=s.data.metadata)==null?void 0:r.runGroupId}function y5(s){var d;const r=new Map,i=[];for(const f of s){const m=b5(f);m?(r.has(m)||r.set(m,[]),r.get(m).push(f)):i.push(f)}const o=[];for(const[f,m]of r){if(m.length===1){i.push(m[0]);continue}const h=m[0].data,x=Object.keys(((d=h.summary)==null?void 0:d.scorers)??{}),p={};for(const v of x){const y=m.map(E=>{var w,C,_;return((_=(C=(w=E.data.summary)==null?void 0:w.scorers)==null?void 0:C[v])==null?void 0:_.mean)??0});p[v]={mean:y.reduce((E,w)=>E+w,0)/y.length}}o.push({type:"group",groupId:f,entries:m.sort((v,y)=>y.timestamp-v.timestamp),evalName:m[0].eval,timestamp:Math.max(...m.map(v=>v.timestamp)),dataset:qf(m[0]),runCount:m.length,aggregateScorers:p})}for(const f of i)o.push({type:"single",entry:f});return o.sort((f,m)=>{const h=f.type==="group"?f.timestamp:f.entry.timestamp;return(m.type==="group"?m.timestamp:m.entry.timestamp)-h}),o}function Bf({scorers:s}){const r=Object.entries(s);return r.length===0?null:n.jsx("div",{className:"flex items-center gap-0.5 shrink-0",children:r.map(([i,o])=>n.jsx("div",{className:"relative h-3.5 w-4 rounded-sm bg-[hsl(var(--muted))] overflow-hidden",title:`${i}: ${o.mean.toFixed(3)}`,children:n.jsx("div",{className:F("absolute bottom-0 left-0 right-0 rounded-sm",xc(o.mean)),style:{height:`${Math.max(0,Math.min(100,o.mean*100))}%`}})},i))})}function cf({data:s}){var o;const r=(o=s.summary)==null?void 0:o.scorers;if(!r)return null;const i={};for(const[d,f]of Object.entries(r))i[d]={mean:f.mean};return n.jsx(Bf,{scorers:i})}function j5({selection:s,history:r,pickerItems:i,placeholder:o}){if(!s)return n.jsx("span",{className:"text-sm text-[hsl(var(--muted-foreground))]",children:o});if(s.groupIds&&s.groupIds.length>1){const x=i.find(p=>p.type==="group"&&p.entries.some(v=>v.id===s.id));if(x&&x.type==="group"){const p=Lf(x.entries);return n.jsxs("div",{className:"flex items-center gap-2.5 min-w-0",children:[n.jsx(Bf,{scorers:x.aggregateScorers}),n.jsxs("div",{className:"min-w-0 flex-1",children:[n.jsxs("div",{className:"flex items-center gap-1.5",children:[n.jsx("span",{className:"text-sm font-medium truncate",children:x.evalName}),n.jsxs("span",{className:"inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded text-[10px] font-medium bg-violet-100 dark:bg-violet-900/40 text-violet-700 dark:text-violet-300",children:[n.jsx(Af,{className:"h-2.5 w-2.5"}),x.runCount," runs"]}),p.map(([v,y])=>n.jsxs("span",{className:"px-1 py-0.5 rounded bg-[hsl(var(--secondary))] font-mono text-[9px]",title:`${v} — ${y} calls`,children:[wa(v)," ",n.jsxs("span",{className:"text-[hsl(var(--muted-foreground))]",children:["(",y,")"]})]},v))]}),n.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] text-[hsl(var(--muted-foreground))]",children:[n.jsx(Px,{className:"h-2.5 w-2.5"}),dc(x.timestamp)]})]})]})}}const d=r.find(x=>x.id===s.id);if(!d)return n.jsx("span",{className:"text-sm text-[hsl(var(--muted-foreground))]",children:o});const f=d.data,m=$n(f),h=Ts(f);return n.jsxs("div",{className:"flex items-center gap-2.5 min-w-0",children:[n.jsx(cf,{data:f}),n.jsxs("div",{className:"min-w-0 flex-1",children:[n.jsxs("div",{className:"flex items-center gap-1.5",children:[n.jsx("span",{className:"text-sm font-medium truncate",children:d.eval}),m.map(x=>n.jsxs("span",{className:"px-1 py-0.5 rounded bg-[hsl(var(--secondary))] font-mono text-[9px]",title:h?`${x} — ${h[x]} calls`:x,children:[wa(x),h&&n.jsxs("span",{className:"text-[hsl(var(--muted-foreground))]",children:[" (",h[x],")"]})]},x))]}),n.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] text-[hsl(var(--muted-foreground))]",children:[n.jsx(Px,{className:"h-2.5 w-2.5"}),dc(d.timestamp),n.jsx("span",{className:"opacity-50",children:"·"}),n.jsx("span",{className:"font-mono",children:d.id.slice(0,8)})]})]})]})}function k0({label:s,selection:r,pickerItems:i,disabledSelection:o,history:d,onChange:f,filterDataset:m}){const[h,x]=b.useState(!1),[p,v]=b.useState(null),y=b.useRef(null);b.useEffect(()=>{function C(_){y.current&&!y.current.contains(_.target)&&(x(!1),v(null))}return h&&document.addEventListener("mousedown",C),()=>document.removeEventListener("mousedown",C)},[h]);const E=m?i.filter(C=>C.type==="group"?C.dataset===m:qf(C.entry)===m):i,w=new Set((o==null?void 0:o.groupIds)??(o?[o.id]:[]));return n.jsxs("div",{ref:y,className:"flex-1 min-w-0 relative",children:[n.jsx("label",{className:"block text-[10px] font-medium uppercase tracking-wider text-[hsl(var(--muted-foreground))] mb-1.5",children:s}),n.jsxs("button",{onClick:()=>{x(!h),v(null)},className:F("w-full px-3 py-2 rounded-lg border text-left flex items-center justify-between gap-2 transition-colors min-h-[44px] cursor-pointer",h?"border-[hsl(var(--foreground))] ring-1 ring-[hsl(var(--foreground))]":"border-[hsl(var(--input))] hover:border-[hsl(var(--foreground))/30]","bg-[hsl(var(--background))]"),children:[n.jsx(j5,{selection:r,history:d,pickerItems:i,placeholder:`Select ${s.toLowerCase()}...`}),n.jsx(Bn,{className:F("h-3.5 w-3.5 shrink-0 text-[hsl(var(--muted-foreground))] transition-transform",h&&"rotate-180")})]}),h&&n.jsx("div",{className:"absolute z-50 top-full left-0 right-0 mt-1 max-h-72 overflow-y-auto rounded-lg border border-[hsl(var(--border))] bg-[hsl(var(--background))] shadow-lg",children:E.length===0?n.jsx("div",{className:"px-3 py-4 text-xs text-center text-[hsl(var(--muted-foreground))]",children:"No matching runs"}):E.map(C=>{var T;if(C.type==="group"){const j=p===C.groupId,k=(T=r==null?void 0:r.groupIds)==null?void 0:T.some(S=>C.entries.some(B=>B.id===S));return n.jsxs("div",{className:"border-b border-[hsl(var(--border))] last:border-b-0",children:[n.jsxs("div",{className:"flex items-stretch",children:[n.jsxs("button",{onClick:()=>{f({id:C.entries[0].id,groupIds:C.entries.map(S=>S.id)}),x(!1),v(null)},className:F("flex-1 text-left px-3 py-2.5 flex items-center gap-2.5 transition-colors cursor-pointer",k?"bg-[hsl(var(--accent))]":"hover:bg-[hsl(var(--accent))]"),children:[n.jsx(Bf,{scorers:C.aggregateScorers}),n.jsxs("div",{className:"min-w-0 flex-1",children:[n.jsxs("div",{className:"flex items-center gap-1.5",children:[n.jsx("span",{className:"text-xs font-medium truncate",children:C.evalName}),n.jsxs("span",{className:"inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded text-[9px] font-medium bg-violet-100 dark:bg-violet-900/40 text-violet-700 dark:text-violet-300",children:[n.jsx(Af,{className:"h-2 w-2"}),C.runCount," runs"]}),Lf(C.entries).map(([S,B])=>n.jsxs("span",{className:"px-1 py-0.5 rounded bg-[hsl(var(--secondary))] font-mono text-[9px]",title:`${S} — ${B} calls`,children:[wa(S)," ",n.jsxs("span",{className:"text-[hsl(var(--muted-foreground))]",children:["(",B,")"]})]},S))]}),n.jsxs("div",{className:"text-[10px] text-[hsl(var(--muted-foreground))]",children:[dc(C.timestamp),n.jsxs("span",{className:"opacity-50",children:[" ","·"," "]}),"pooled comparison"]})]}),k&&n.jsx("div",{className:"shrink-0 h-1.5 w-1.5 rounded-full bg-[hsl(var(--foreground))]"})]}),n.jsx("button",{onClick:S=>{S.stopPropagation(),v(j?null:C.groupId)},className:"shrink-0 w-8 flex items-center justify-center border-l border-[hsl(var(--border))] hover:bg-[hsl(var(--accent))] transition-colors cursor-pointer",title:j?"Hide individual runs":"Show individual runs",children:j?n.jsx(Bn,{className:"h-3 w-3 text-[hsl(var(--muted-foreground))]"}):n.jsx(Ba,{className:"h-3 w-3 text-[hsl(var(--muted-foreground))]"})})]}),j&&C.entries.map(S=>{var K;const B=S.data,$=(r==null?void 0:r.id)===S.id&&!(r!=null&&r.groupIds),W=w.has(S.id);return n.jsxs("button",{onClick:()=>{f({id:S.id}),x(!1),v(null)},disabled:W,className:F("w-full text-left pl-8 pr-3 py-2 flex items-center gap-2.5 transition-colors border-t border-[hsl(var(--border))] cursor-pointer","bg-[hsl(var(--muted))]/30",$?"bg-[hsl(var(--accent))]":"hover:bg-[hsl(var(--accent))]",W&&"opacity-30 cursor-not-allowed"),children:[n.jsx(cf,{data:B}),n.jsx("div",{className:"min-w-0 flex-1",children:n.jsxs("div",{className:"flex items-center gap-1 text-[10px] text-[hsl(var(--muted-foreground))]",children:[n.jsxs("span",{children:["Run ",(((K=B.metadata)==null?void 0:K.runIndex)??0)+1]}),n.jsx("span",{className:"opacity-50",children:"·"}),n.jsx("span",{className:"font-mono",children:S.id.slice(0,8)}),(()=>{const te=Ts(B);return $n(B).map(re=>n.jsxs("span",{className:"px-1 py-0.5 rounded bg-[hsl(var(--secondary))] text-[hsl(var(--foreground))] font-mono text-[9px]",title:te?`${re} — ${te[re]} calls`:re,children:[wa(re),te&&n.jsxs("span",{className:"text-[hsl(var(--muted-foreground))]",children:[" ","(",te[re],")"]})]},re))})()]})}),$&&n.jsx("div",{className:"shrink-0 h-1.5 w-1.5 rounded-full bg-[hsl(var(--foreground))]"})]},S.id)})]},C.groupId)}const{entry:_}=C,R=_.data,D=(r==null?void 0:r.id)===_.id,H=w.has(_.id);return n.jsxs("button",{onClick:()=>{f({id:_.id}),x(!1),v(null)},disabled:H,className:F("w-full text-left px-3 py-2.5 flex items-center gap-2.5 transition-colors border-b border-[hsl(var(--border))] last:border-b-0 cursor-pointer",D?"bg-[hsl(var(--accent))]":"hover:bg-[hsl(var(--accent))]",H&&"opacity-30 cursor-not-allowed"),children:[n.jsx(cf,{data:R}),n.jsxs("div",{className:"min-w-0 flex-1",children:[n.jsxs("div",{className:"flex items-center gap-1.5",children:[n.jsx("span",{className:"text-xs font-medium truncate",children:_.eval}),(()=>{const j=Ts(R);return $n(R).map(k=>n.jsxs("span",{className:"px-1 py-0.5 rounded bg-[hsl(var(--secondary))] font-mono text-[9px]",title:j?`${k} — ${j[k]} calls`:k,children:[wa(k),j&&n.jsxs("span",{className:"text-[hsl(var(--muted-foreground))]",children:[" ","(",j[k],")"]})]},k))})()]}),n.jsxs("div",{className:"text-[10px] text-[hsl(var(--muted-foreground))]",children:[dc(_.timestamp),n.jsxs("span",{className:"opacity-50",children:[" ","·"," "]}),n.jsx("span",{className:"font-mono",children:_.id.slice(0,8)}),n.jsxs("span",{className:"opacity-50",children:[" ","·"," "]}),R.summary.count," items"]})]}),D&&n.jsx("div",{className:"shrink-0 h-1.5 w-1.5 rounded-full bg-[hsl(var(--foreground))]"})]},_.id)})})]})}function N5({history:s,baselineSelection:r,candidateSelection:i,onBaselineChange:o,onCandidateChange:d,onCompare:f,comparing:m}){const h=b.useMemo(()=>y5(s),[s]),x=r?s.find(y=>y.id===r.id):null,p=x?qf(x):null,v=r!=null&&i!=null&&r.id!==i.id&&!m;return n.jsx("div",{className:"space-y-3",children:n.jsxs("div",{className:"flex items-end gap-2",children:[n.jsx(k0,{label:"Baseline",selection:r,pickerItems:h,disabledSelection:i,history:s,onChange:o,filterDataset:null}),n.jsx("button",{onClick:()=>{if(r&&i){const y=r;o(i),d(y)}},disabled:!r||!i,className:"shrink-0 p-2 rounded-lg border border-[hsl(var(--input))] hover:bg-[hsl(var(--accent))] disabled:opacity-30 transition-colors mb-[1px] cursor-pointer",title:"Swap baseline and candidate",children:n.jsx(Lj,{className:"h-3.5 w-3.5 text-[hsl(var(--muted-foreground))]"})}),n.jsx(k0,{label:"Candidate",selection:i,pickerItems:h,disabledSelection:r,history:s,onChange:d,filterDataset:p}),n.jsx("button",{onClick:f,disabled:!v,className:F("shrink-0 px-5 py-2 text-sm font-medium rounded-lg transition-all cursor-pointer","bg-[hsl(var(--foreground))] text-[hsl(var(--background))]","hover:opacity-90 disabled:opacity-40"),children:m?"Comparing…":"Compare"})]})})}function S5({currentIndex:s,totalRuns:r,aggregate:i,onIndexChange:o}){const d=s===-1,f=s>-1,m=s<r-1;return n.jsx("div",{className:"px-6",children:n.jsxs("div",{className:"flex items-center justify-between px-4 py-2 rounded-lg bg-[hsl(var(--muted))]",children:[n.jsx("button",{onClick:()=>o(s-1),disabled:!f,className:"p-1 rounded hover:bg-[hsl(var(--accent))] disabled:opacity-30 transition-colors cursor-pointer",children:n.jsx(Xj,{size:16})}),n.jsxs("div",{className:"text-center",children:[n.jsx("span",{className:"text-sm font-medium",children:d?`Aggregate (${r} runs)`:`Run ${s+1} of ${r}`}),!d&&n.jsx("button",{onClick:()=>o(-1),className:"ml-3 text-xs text-[hsl(var(--muted-foreground))] hover:text-[hsl(var(--foreground))] underline transition-colors cursor-pointer",children:"View aggregate"}),d&&(()=>{const h=Object.values(i.scorers),x=h.reduce((p,v)=>p+v.mean,0)/Math.max(h.length,1);return n.jsxs("div",{className:"text-xs text-[hsl(var(--muted-foreground))]",children:["Overall mean: ",x.toFixed(3)," across ",h.length," scorer",h.length!==1?"s":""]})})()]}),n.jsx("button",{onClick:()=>o(s+1),disabled:!m,className:"p-1 rounded hover:bg-[hsl(var(--accent))] disabled:opacity-30 transition-colors cursor-pointer",children:n.jsx(Ba,{size:16})})]})})}function w5(s){var f;const r={},i=[];for(const m of s){const h=m.data;if(!((f=h.summary)!=null&&f.scorers))continue;const x=[];for(const[p,v]of Object.entries(h.summary.scorers))r[p]||(r[p]=[]),r[p].push(v.mean),x.push(v.mean);x.length>0&&i.push(x.reduce((p,v)=>p+v,0)/x.length)}const o={};for(const[m,h]of Object.entries(r)){const x=h.reduce((v,y)=>v+y,0)/h.length,p=h.length>1?Math.sqrt(h.reduce((v,y)=>v+(y-x)**2,0)/(h.length-1)):0;o[m]={mean:x,std:p}}let d=null;if(i.length>0){const m=i.reduce((x,p)=>x+p,0)/i.length,h=i.length>1?Math.sqrt(i.reduce((x,p)=>x+(p-m)**2,0)/(i.length-1)):0;d={mean:m,std:h}}return{scorers:o,overall:d}}function k5(s){const r=s.eval.replace(/[^a-zA-Z0-9_-]+/g,"-").replace(/^-+|-+$/g,"")||"eval",i=s.id.slice(0,8),o=new Date(s.timestamp).toISOString().replace(/[-:]/g,"").replace(/\.\d{3}Z$/,"Z"),d=`${r}-${i}-${o}.json`,f=JSON.stringify(s.data,null,2),m=new Blob([f],{type:"application/json"}),h=URL.createObjectURL(m),x=document.createElement("a");x.href=h,x.download=d,document.body.appendChild(x),x.click(),document.body.removeChild(x),setTimeout(()=>URL.revokeObjectURL(h),0)}function C5({history:s,evalFilter:r,onEvalFilterChange:i,onSelect:o,onSelectGroup:d,onRescore:f,onDelete:m,registeredEvalNames:h,readOnly:x,expandedGroups:p,onToggleGroup:v}){const[y,E]=b.useState(null),w=[...new Set(s.map(j=>j.eval))].sort(),C=b.useMemo(()=>r?s.filter(j=>j.eval===r):s,[s,r]),{rows:_,scorerCols:R}=b.useMemo(()=>{var $,W;const j=new Map,k=[];for(const K of C){const re=($=K.data.metadata)==null?void 0:$.runGroupId;re?(j.has(re)||j.set(re,[]),j.get(re).push(K)):k.push(K)}const S=[];for(const[K,te]of j)te.sort((re,Me)=>Me.timestamp-re.timestamp),te.length===1?S.push({type:"entry",entry:te[0]}):S.push({type:"group",groupId:K,entries:te,evalName:te[0].eval,newestTimestamp:te[0].timestamp});for(const K of k)S.push({type:"entry",entry:K});S.sort((K,te)=>{const re=K.type==="group"?K.newestTimestamp:K.entry.timestamp;return(te.type==="group"?te.newestTimestamp:te.entry.timestamp)-re});const B=new Set;for(const K of C){const te=K.data;if((W=te.summary)!=null&&W.scorers)for(const re of Object.keys(te.summary.scorers))B.add(re)}return{rows:S,scorerCols:[...B].sort()}},[C]),D=b.useMemo(()=>{var k;const j={};for(const S of C){const $=(k=S.data.metadata)==null?void 0:k.scorerTypes;$&&Object.assign(j,$)}return j},[C]),H=8+R.length+(f?1:0),T=(j,k,S)=>{const B=j.data,$=y===j.id;return n.jsxs(b.Fragment,{children:[n.jsxs("tr",{"data-entry-id":j.id,className:F("border-t border-[hsl(var(--border))] cursor-pointer hover:bg-[hsl(var(--accent))] transition-colors",S&&!k&&"bg-[hsl(var(--accent))]/30",$&&"bg-[hsl(var(--accent))]/40"),onClick:()=>E($?null:j.id),children:[n.jsx("td",{className:F("px-3 py-2.5 font-mono",k&&"pl-9"),children:n.jsxs("div",{className:"flex flex-col gap-0.5",children:[n.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[k&&n.jsx("span",{className:"inline-block w-1 h-3 mr-0.5 rounded-sm bg-[hsl(var(--border))]"}),j.eval]}),(()=>{const W=tr(B);if(W.length===0||W.length===1&&W[0]===j.eval)return null;const K=rf(B),te=K?`Workflows: ${W.map(re=>`${re} (${K[re]??"?"} calls)`).join(", ")}`:`Workflows: ${W.join(", ")}`;return n.jsx("span",{className:"text-[10px] font-normal text-[hsl(var(--muted-foreground))] truncate max-w-[240px]",title:te,children:W.join(" · ")})})()]})}),n.jsx("td",{className:"px-3 py-2.5",children:(()=>{const W=$n(B);if(W.length===0)return n.jsx("span",{className:"text-[hsl(var(--muted-foreground))]",children:"-"});const K=Ts(B);return n.jsx("span",{className:"inline-flex items-center gap-1 flex-wrap",children:W.map(te=>n.jsxs("span",{className:"px-1.5 py-0.5 rounded bg-[hsl(var(--secondary))] text-[hsl(var(--foreground))] font-mono text-[10px]",title:K?`${te} — ${K[te]} calls`:te,children:[wa(te),K&&K[te]!=null&&n.jsxs("span",{className:"ml-0.5 text-[hsl(var(--muted-foreground))]",children:["(",K[te],")"]})]},te))})})()}),n.jsx("td",{className:"px-3 py-2.5 text-[hsl(var(--muted-foreground))]",children:new Date(j.timestamp).toLocaleString()}),n.jsx("td",{className:"px-3 py-2.5 text-right font-mono",children:B.summary.count}),n.jsx("td",{className:"px-3 py-2.5 text-right font-mono",children:B.summary.failures>0?n.jsx("span",{className:"text-red-600 dark:text-red-400",children:B.summary.failures}):n.jsx("span",{className:"text-[hsl(var(--muted-foreground))]",children:"0"})}),n.jsx("td",{className:"px-3 py-2.5 text-right font-mono text-[hsl(var(--muted-foreground))]",children:B.duration>0?xt(B.duration):"-"}),n.jsx("td",{className:"px-3 py-2.5 text-right font-mono text-[hsl(var(--muted-foreground))]",children:B.totalCost>0?at(B.totalCost):"-"}),(()=>{var te;const W=Object.values(((te=B.summary)==null?void 0:te.scorers)??{}).map(re=>re.mean),K=W.length>0?W.reduce((re,Me)=>re+Me,0)/W.length:null;return n.jsx("td",{className:"px-3 py-2.5 text-right font-mono font-medium border-l border-[hsl(var(--border))]",children:K!=null?n.jsx("span",{className:Rt(K),children:K.toFixed(3)}):n.jsx("span",{className:"text-[hsl(var(--muted-foreground))]",children:"-"})})})(),R.map(W=>{var te,re;const K=(re=(te=B.summary)==null?void 0:te.scorers)==null?void 0:re[W];return n.jsx("td",{className:"px-3 py-2.5 text-right font-mono",children:K?n.jsxs("div",{children:[n.jsx("span",{className:Rt(K.mean),children:K.mean.toFixed(3)}),K.min!==K.max&&n.jsxs("div",{className:"text-[9px] text-[hsl(var(--muted-foreground))]",children:[K.min.toFixed(2),"–",K.max.toFixed(2)]})]}):n.jsx("span",{className:"text-[hsl(var(--muted-foreground))]",children:"-"})},W)}),f&&n.jsx("td",{className:"px-3 py-2.5"})]}),$&&(()=>{var te,re,Me;const W=(te=B.metadata)==null?void 0:te.scorerTypes,K=(re=B.metadata)==null?void 0:re.originalId;return n.jsx("tr",{className:"border-t border-[hsl(var(--border))] bg-[hsl(var(--muted))]/50",children:n.jsx("td",{colSpan:H,className:"px-4 py-3",children:n.jsxs("div",{className:"flex items-center justify-between gap-4",children:[n.jsxs("div",{className:"flex items-center gap-4 text-[10px] text-[hsl(var(--muted-foreground))] flex-wrap",children:[n.jsxs("span",{children:["ID: ",n.jsx("span",{className:"font-mono",children:B.id.slice(0,8)})]}),n.jsxs("span",{children:["Dataset:"," ",n.jsx("span",{className:"font-medium text-[hsl(var(--foreground))]",children:B.dataset})]}),(()=>{const he=tr(B);return he.length===0?null:n.jsxs("span",{children:[he.length>1?"Workflows":"Workflow",":"," ",n.jsx("span",{className:"font-medium text-[hsl(var(--foreground))]",children:he.join(", ")})]})})(),(()=>{const he=$n(B);if(he.length===0)return null;const ae=Ts(B);return n.jsx("span",{className:"inline-flex items-center gap-1",children:he.map(z=>n.jsxs("span",{className:"px-1.5 py-0.5 rounded bg-[hsl(var(--secondary))] text-[hsl(var(--foreground))] font-mono",title:ae?`${z} — ${ae[z]} calls`:z,children:[wa(z),ae&&ae[z]!=null&&n.jsxs("span",{className:"ml-0.5 text-[hsl(var(--muted-foreground))]",children:["(",ae[z],")"]})]},z))})})(),!!((Me=B.metadata)!=null&&Me.rescored)&&n.jsx("span",{className:"px-1.5 py-0.5 rounded bg-amber-100 text-amber-700 dark:bg-amber-900/30 dark:text-amber-400",children:"Rescored"}),K&&n.jsxs("span",{children:["from"," ",n.jsx("button",{onClick:he=>{he.stopPropagation(),E(K),requestAnimationFrame(()=>{var ae;(ae=document.querySelector(`[data-entry-id="${CSS.escape(K)}"]`))==null||ae.scrollIntoView({behavior:"smooth",block:"center"})})},className:"font-mono underline hover:text-[hsl(var(--foreground))] transition-colors cursor-pointer",children:K.slice(0,8)})]}),W&&Object.keys(W).length>0&&n.jsxs("span",{className:"inline-flex items-center gap-1.5",children:["Scorers:",Object.entries(W).sort(([he],[ae])=>he.localeCompare(ae)).map(([he,ae])=>n.jsx("span",{className:F("px-1.5 py-0.5 rounded font-mono cursor-default",ae==="llm"?"bg-purple-100 text-purple-700 dark:bg-purple-900/30 dark:text-purple-400":"bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-400"),title:ae==="llm"?`${he} — LLM scorer (scores may vary between runs)`:`${he} — deterministic scorer`,children:he},he))]})]}),n.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[f&&(()=>{const he=!h||h.has(j.eval),ae=he&&!x,z=x?"Rescore unavailable — Studio is mounted in read-only mode.":he?"Re-run scorers on saved outputs without re-executing the workflow":`Rescore unavailable — no registered eval named "${j.eval}". Imported CLI artifacts can only be rescored when the runtime has a matching registered eval config.`;return n.jsx("button",{onClick:L=>{L.stopPropagation(),ae&&f(j.eval,j.id)},disabled:!ae,className:F("px-2.5 py-1 text-[10px] font-medium rounded border border-[hsl(var(--input))] transition-colors",ae?"hover:bg-[hsl(var(--accent))] cursor-pointer":"opacity-40 cursor-not-allowed"),title:z,children:"Rescore"})})(),n.jsx("button",{onClick:he=>{he.stopPropagation(),k5(j)},className:"p-1 rounded border border-[hsl(var(--input))] hover:bg-[hsl(var(--accent))] cursor-pointer transition-colors",title:`Export this result as JSON (${j.eval}-${j.id.slice(0,8)}-...json)`,"aria-label":"Export result as JSON",children:n.jsx(lN,{size:12})}),m&&n.jsx("button",{onClick:he=>{he.stopPropagation(),!x&&m(j)},disabled:x,className:F("p-1 rounded border border-[hsl(var(--input))] transition-colors",x?"opacity-40 cursor-not-allowed":"hover:bg-red-50 hover:border-red-200 hover:text-red-600 dark:hover:bg-red-950/30 dark:hover:border-red-900 dark:hover:text-red-400 cursor-pointer"),title:x?"Delete unavailable — Studio is mounted in read-only mode.":"Delete this history entry","aria-label":"Delete history entry",children:n.jsx(Of,{size:12})}),n.jsxs("button",{onClick:he=>{he.stopPropagation(),o(B)},className:"inline-flex items-center gap-1 px-2.5 py-1 text-[10px] font-medium rounded border border-[hsl(var(--input))] hover:bg-[hsl(var(--accent))] transition-colors cursor-pointer",title:"Open full run details in the Run tab",children:["View Details",n.jsx(mr,{size:10})]})]})]})})})})()]},j.id)};return n.jsxs("div",{children:[w.length>1&&n.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[n.jsxs("select",{value:r,onChange:j=>i(j.target.value),className:"px-2 py-1 text-xs rounded-lg border border-[hsl(var(--input))] bg-[hsl(var(--background))]",children:[n.jsx("option",{value:"",children:"All evals"}),w.map(j=>n.jsx("option",{value:j,children:j},j))]}),r&&n.jsxs("span",{className:"text-xs text-[hsl(var(--muted-foreground))]",children:[C.length," run",C.length!==1?"s":""]})]}),n.jsx("div",{className:"border border-[hsl(var(--border))] rounded-xl overflow-hidden",children:n.jsx("div",{className:"overflow-x-auto",children:n.jsxs("table",{className:"w-full text-xs",children:[n.jsx("thead",{children:n.jsxs("tr",{className:"bg-[hsl(var(--muted))]",children:[n.jsx("th",{className:"text-left px-3 py-2.5 font-medium",children:"Eval"}),n.jsx("th",{className:"text-left px-3 py-2.5 font-medium",children:"Model"}),n.jsx("th",{className:"text-left px-3 py-2.5 font-medium",children:"Timestamp"}),n.jsx("th",{className:"text-right px-3 py-2.5 font-medium",children:"Items"}),n.jsx("th",{className:"text-right px-3 py-2.5 font-medium",children:"Failures"}),n.jsx("th",{className:"text-right px-3 py-2.5 font-medium",children:"Duration"}),n.jsx("th",{className:"text-right px-3 py-2.5 font-medium",children:"Cost"}),n.jsx("th",{className:"text-right px-3 py-2.5 font-medium border-l border-[hsl(var(--border))]",children:"Overall"}),R.map(j=>n.jsxs("th",{className:"text-right px-3 py-2.5 font-medium font-mono whitespace-nowrap",title:j,children:[j,D[j]==="llm"&&n.jsx("span",{className:"ml-1 px-1 py-0.5 text-[9px] font-medium rounded bg-purple-100 text-purple-600 dark:bg-purple-900/30 dark:text-purple-400 align-middle",title:"LLM scorer — scores may vary between runs",children:"LLM"})]},j)),f&&n.jsx("th",{className:"px-3 py-2.5 font-medium w-8"})]})}),n.jsx("tbody",{children:_.map((j,k)=>{if(j.type==="group"){const S=p.has(j.groupId),B=w5(j.entries),$=B.scorers,W=j.entries.reduce((he,ae)=>he+ae.data.summary.count,0),K=(()=>{var he;for(const ae of j.entries){const z=(he=ae.data.metadata)==null?void 0:he.batchAttempted;if(typeof z=="number")return z}})(),te=K!==void 0&&j.entries.length<K,re=j.entries.reduce((he,ae)=>he+ae.data.duration,0),Me=j.entries.reduce((he,ae)=>he+ae.data.totalCost,0);return n.jsxs(b.Fragment,{children:[n.jsxs("tr",{className:F("border-t border-[hsl(var(--border))] cursor-pointer hover:bg-[hsl(var(--accent))] transition-colors",k===0&&"bg-[hsl(var(--accent))]/30"),onClick:()=>v(j.groupId),children:[n.jsx("td",{className:"px-3 py-2.5 font-mono",children:n.jsxs("div",{className:"flex flex-col gap-0.5",children:[n.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[n.jsx("span",{className:"shrink-0 p-0.5 -m-0.5",children:S?n.jsx(Bn,{size:14}):n.jsx(Ba,{size:14})}),j.evalName]}),(()=>{const he=new Set,ae=[];for(const z of j.entries)for(const L of tr(z.data))he.has(L)||(he.add(L),ae.push(L));return ae.length===0||ae.length===1&&ae[0]===j.evalName?null:n.jsx("span",{className:"text-[10px] font-normal text-[hsl(var(--muted-foreground))] truncate max-w-[240px] pl-[22px]",title:`Workflows: ${ae.join(", ")}`,children:ae.join(" · ")})})()]})}),n.jsx("td",{className:"px-3 py-2.5",children:(()=>{const he=Lf(j.entries);return he.length===0?n.jsx("span",{className:"text-[hsl(var(--muted-foreground))]",children:"-"}):n.jsx("span",{className:"inline-flex items-center gap-1 flex-wrap",children:he.map(([ae,z])=>n.jsxs("span",{className:"px-1.5 py-0.5 rounded bg-[hsl(var(--secondary))] text-[hsl(var(--foreground))] font-mono text-[10px]",title:`${ae} — ${z} calls`,children:[wa(ae),n.jsxs("span",{className:"ml-0.5 text-[hsl(var(--muted-foreground))]",children:["(",z,")"]})]},ae))})})()}),n.jsx("td",{className:"px-3 py-2.5 text-[hsl(var(--muted-foreground))]",children:new Date(j.newestTimestamp).toLocaleString()}),n.jsx("td",{className:"px-3 py-2.5 text-right font-mono",children:W}),n.jsx("td",{className:"px-3 py-2.5 text-right",children:n.jsxs("span",{className:F("inline-flex items-center gap-1 px-1.5 py-0.5 rounded-md",te?"bg-amber-100 text-amber-900 dark:bg-amber-950/60 dark:text-amber-200":"bg-[hsl(var(--secondary))] text-[hsl(var(--muted-foreground))]"),title:te?`Partial batch — ${j.entries.length} of ${K} runs completed`:void 0,children:[n.jsx(Af,{size:10}),te?n.jsxs(n.Fragment,{children:[j.entries.length,"/",K," runs",n.jsx("span",{className:"font-medium uppercase tracking-wide text-[9px] ml-1",children:"partial"})]}):n.jsxs(n.Fragment,{children:[j.entries.length," runs"]})]})}),n.jsx("td",{className:"px-3 py-2.5 text-right font-mono text-[hsl(var(--muted-foreground))]",children:re>0?xt(re):"-"}),n.jsx("td",{className:"px-3 py-2.5 text-right font-mono text-[hsl(var(--muted-foreground))]",children:Me>0?at(Me):"-"}),n.jsx("td",{className:"px-3 py-2.5 text-right font-mono font-medium border-l border-[hsl(var(--border))]",children:B.overall?n.jsxs("span",{className:Rt(B.overall.mean),children:[B.overall.mean.toFixed(3),B.overall.std>0&&n.jsxs("span",{className:"text-[hsl(var(--muted-foreground))] font-normal",children:[" ± ",B.overall.std.toFixed(3)]})]}):n.jsx("span",{className:"text-[hsl(var(--muted-foreground))]",children:"-"})}),R.map(he=>{const ae=$[he];return n.jsx("td",{className:"px-3 py-2.5 text-right font-mono",children:ae?n.jsxs("span",{className:Rt(ae.mean),children:[ae.mean.toFixed(3),n.jsxs("span",{className:"text-[hsl(var(--muted-foreground))]",children:[" "," ± ",ae.std.toFixed(3)]})]}):n.jsx("span",{className:"text-[hsl(var(--muted-foreground))]",children:"-"})},he)}),f&&n.jsx("td",{className:"px-3 py-2.5"})]}),S&&n.jsxs(n.Fragment,{children:[d&&n.jsx("tr",{className:"border-t border-[hsl(var(--border))] bg-[hsl(var(--muted))]/50",children:n.jsx("td",{colSpan:H,className:"px-4 py-2.5",children:n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsxs("span",{className:"text-[10px] text-[hsl(var(--muted-foreground))]",children:[j.entries.length," runs in this group"]}),n.jsxs("button",{onClick:he=>{he.stopPropagation(),d(j.entries)},className:"inline-flex items-center gap-1 px-2.5 py-1 text-[10px] font-medium rounded border border-[hsl(var(--input))] hover:bg-[hsl(var(--accent))] transition-colors cursor-pointer",title:"View combined statistics across all runs in this group",children:["View Aggregate",n.jsx(mr,{size:10})]})]})})}),j.entries.map(he=>T(he,!0,!1))]})]},j.groupId)}return T(j.entry,!1,k===0)})})]})})})]})}const uf=1,df=25,E5=5,tc=s=>Math.max(uf,Math.min(df,Math.round(s)));function T5({evals:s,selectedEval:r,onSelectEval:i,runCount:o,onRunCountChange:d,captureTraces:f,onCaptureTracesChange:m,running:h,onRun:x}){return n.jsxs("div",{className:F("inline-flex items-stretch rounded-full bg-[hsl(var(--background))]","ring-1 ring-[hsl(var(--input))] shadow-sm","hover:ring-[hsl(var(--ring))] focus-within:ring-[hsl(var(--ring))]","transition-shadow"),children:[n.jsx(ki,{items:s,value:r,onSelect:i,getKey:p=>p.name,getLabel:p=>p.name,getDescription:p=>n.jsxs(n.Fragment,{children:[n.jsx("span",{children:p.workflow}),n.jsx("span",{className:"opacity-40 mx-1",children:"·"}),n.jsx("span",{children:p.dataset}),n.jsx("span",{className:"opacity-40 mx-1",children:"·"}),n.jsxs("span",{children:[p.scorers.length," scorer",p.scorers.length!==1?"s":""]})]}),searchMatch:(p,v)=>p.name.toLowerCase().includes(v)||p.workflow.toLowerCase().includes(v)||p.dataset.toLowerCase().includes(v),placeholder:"Select eval",searchPlaceholder:"Search evals…",emptyLabel:"No evals registered",shortcut:!0,triggerClassName:"rounded-l-full",ariaLabel:"Select an eval"}),n.jsx(M5,{value:o,onChange:d,disabled:h}),n.jsx("button",{type:"button",role:"switch","aria-checked":f,"aria-label":"Capture per-item trace events",onClick:()=>m(!f),disabled:h,title:f?"Capturing per-item traces (click to disable) — traces appear inline on each item":"Capture per-item traces — extra memory, but lets you inspect every event per item",className:F("flex items-center px-2 border-l border-[hsl(var(--input))] transition-colors cursor-pointer","focus:outline-none focus-visible:bg-[hsl(var(--muted))]","disabled:opacity-40 disabled:cursor-not-allowed",f?"text-[hsl(var(--foreground))] bg-[hsl(var(--muted))]":"text-[hsl(var(--muted-foreground))] hover:bg-[hsl(var(--muted))] hover:text-[hsl(var(--foreground))]"),children:n.jsx(mc,{size:12,strokeWidth:2.5})}),n.jsxs("button",{type:"button",onClick:x,disabled:!r||h,className:F("inline-flex items-center gap-1.5 pl-3.5 pr-4 py-2 text-sm font-medium cursor-pointer","bg-[hsl(var(--foreground))] text-[hsl(var(--background))] rounded-r-full","hover:opacity-90 focus:outline-none focus-visible:ring-2 focus-visible:ring-offset-1 focus-visible:ring-[hsl(var(--foreground))]","disabled:opacity-40 disabled:cursor-not-allowed transition-opacity"),children:[n.jsx(_f,{size:12,className:F("fill-current",h&&"animate-spin fill-none")}),h?"Running…":"Run"]})]})}function M5({value:s,onChange:r,disabled:i=!1}){const[o,d]=b.useState(!1),[f,m]=b.useState(""),h=b.useRef(null),x=b.useRef(!1),p=b.useCallback((D,H)=>{const T=(H?E5:1)*D;r(tc(s+T))},[s,r]),v=b.useCallback(()=>{i||(x.current=!1,m(String(s)),d(!0))},[s,i]);b.useEffect(()=>{o||m(String(s))},[s,o]),b.useEffect(()=>{o&&requestAnimationFrame(()=>{var D,H;(D=h.current)==null||D.focus(),(H=h.current)==null||H.select()})},[o]);const y=b.useCallback(()=>{if(x.current){d(!1);return}x.current=!0;const D=parseInt(f,10);Number.isNaN(D)||r(tc(D)),d(!1)},[f,r]),E=b.useCallback(()=>{x.current=!0,d(!1)},[]),w=b.useCallback(D=>{if(D.key==="Enter")D.preventDefault(),y();else if(D.key==="Escape")D.preventDefault(),E();else if(D.key==="ArrowUp"){D.preventDefault();const H=parseInt(f,10);Number.isNaN(H)||m(String(tc(H+1)))}else if(D.key==="ArrowDown"){D.preventDefault();const H=parseInt(f,10);Number.isNaN(H)||m(String(tc(H-1)))}},[y,E,f]),C=b.useCallback(D=>{i||(D.key==="Enter"||D.key===" "?(D.preventDefault(),v()):D.key==="ArrowUp"?(D.preventDefault(),p(1,D.shiftKey)):D.key==="ArrowDown"&&(D.preventDefault(),p(-1,D.shiftKey)))},[i,v,p]),_=s<=uf,R=s>=df;return n.jsxs("div",{className:"flex items-stretch border-l border-[hsl(var(--input))]",role:"group","aria-label":"Run count",children:[n.jsx("button",{type:"button",onClick:D=>p(-1,D.shiftKey),disabled:i||_,title:"Decrease runs — Shift+click: −5","aria-label":"Decrease run count",className:F("flex items-center px-1.5 transition-colors cursor-pointer","text-[hsl(var(--muted-foreground))]","hover:bg-[hsl(var(--muted))] hover:text-[hsl(var(--foreground))]","focus:outline-none focus-visible:bg-[hsl(var(--muted))]","disabled:opacity-40 disabled:cursor-not-allowed disabled:hover:bg-transparent disabled:hover:text-[hsl(var(--muted-foreground))]"),children:n.jsx(xN,{size:12,strokeWidth:2.5})}),o?n.jsx("input",{ref:h,type:"text",inputMode:"numeric",value:f,onChange:D=>m(D.target.value.replace(/[^0-9]/g,"").slice(0,2)),onKeyDown:w,onBlur:y,"aria-label":"Run count",className:F("w-10 text-center text-xs font-semibold tabular-nums bg-transparent","focus:outline-none text-[hsl(var(--foreground))]")}):n.jsxs("button",{type:"button",role:"spinbutton","aria-valuenow":s,"aria-valuemin":uf,"aria-valuemax":df,"aria-valuetext":`${s} run${s!==1?"s":""}`,onClick:v,onKeyDown:C,disabled:i,title:"Click or press Enter to type a value — Arrow keys step","aria-label":`Run count: ${s}. Press Enter to edit, arrow keys to step.`,className:F("flex items-center justify-center min-w-[2.5rem] px-1 text-xs tabular-nums cursor-text","transition-colors hover:bg-[hsl(var(--muted))]","focus:outline-none focus-visible:bg-[hsl(var(--muted))]","disabled:opacity-60 disabled:cursor-not-allowed",s>1?"text-[hsl(var(--foreground))] font-semibold":"text-[hsl(var(--muted-foreground))]"),children:[n.jsx("span",{className:"opacity-50 mr-0.5",children:"×"}),s]}),n.jsx("button",{type:"button",onClick:D=>p(1,D.shiftKey),disabled:i||R,title:"Increase runs — Shift+click: +5","aria-label":"Increase run count",className:F("flex items-center px-1.5 transition-colors cursor-pointer","text-[hsl(var(--muted-foreground))]","hover:bg-[hsl(var(--muted))] hover:text-[hsl(var(--foreground))]","focus:outline-none focus-visible:bg-[hsl(var(--muted))]","disabled:opacity-40 disabled:cursor-not-allowed disabled:hover:bg-transparent disabled:hover:text-[hsl(var(--muted-foreground))]"),children:n.jsx(wg,{size:12,strokeWidth:2.5})})]})}function A5(){var Li,Hi,kr,Vn,xl;const s=_i(),[r,i]=b.useState("run"),[o,d]=b.useState(""),f=$S(),m=f.status==="running",[h,x]=b.useState(null),[p,v]=b.useState(null),[y,E]=b.useState(null),[w,C]=b.useState(1),[_,R]=b.useState(!0),[D,H]=b.useState(-1),[T,j]=b.useState(new Set),[k,S]=b.useState(null),[B,$]=b.useState(0),[W,K]=b.useState(null),[te,re]=b.useState("all"),[Me,he]=b.useState(""),[ae,z]=b.useState(""),[L,ie]=b.useState("index"),[ve,ge]=b.useState("asc"),[M,Q]=b.useState("mean"),[G,J]=b.useState("asc"),[oe,me]=b.useState(""),[be,X]=b.useState(!1),[ne,ce]=b.useState(null),[we,Re]=b.useState(null),[dt,yt]=b.useState(null),[pe,Te]=b.useState(null),[Ie,ye]=b.useState(null),[Je,jt]=b.useState(null),[Dt,Ca]=b.useState(null),{data:zt=[]}=Sa({queryKey:["evals"],queryFn:tS}),{data:Be=[]}=Sa({queryKey:["evalHistory"],queryFn:aS}),{data:fa,isLoading:$a,isError:ha}=Sa({queryKey:["health"],queryFn:z2,staleTime:1/0}),$e=!!(fa!=null&&fa.readOnly),dn=(!$a||ha)&&!$e,Ia=b.useRef(null),[fn,Ea]=b.useState(!1),[Nt,Zt]=b.useState(null);b.useEffect(()=>{if(!Nt)return;const ee=setTimeout(()=>Zt(null),6e3);return()=>clearTimeout(ee)},[Nt]),b.useEffect(()=>{if(p!=="Cancelled")return;const ee=setTimeout(()=>v(null),4e3);return()=>clearTimeout(ee)},[p]);const Jt=b.useCallback(async ee=>{var ue;v(null),Zt(null),Ea(!0);try{const de=await ee.text();let Se;try{Se=JSON.parse(de)}catch{throw new Error(`${ee.name} is not valid JSON`)}const fe=await rS(Se),qe="imported"in fe?fe.imported:[fe],De=qe.length,_e=(ue=qe[0])==null?void 0:ue.id;await s.invalidateQueries({queryKey:["evalHistory"]});const Qe=De>1?` (${De} runs)`:"";if(!_e)throw new Error("Import succeeded but no entries were returned");pe?Ie?Zt(`Imported ${ee.name}${Qe} — added to history (both compare slots full)`):(ye({id:_e}),Zt(`Imported ${ee.name}${Qe} — selected as candidate`)):(Te({id:_e}),Zt(`Imported ${ee.name}${Qe} — selected as baseline`))}catch(de){v(de instanceof Error?de.message:String(de))}finally{Ea(!1)}},[s,pe,Ie]);b.useEffect(()=>{var fe;if(pe||Ie||Be.length<2)return;const ee=Be[0].eval,ue=Be.filter(qe=>qe.eval===ee);if(ue.length<2)return;const de=new Set,Se=[];for(const qe of ue){const De=(fe=qe.data.metadata)==null?void 0:fe.runGroupId,_e=De??qe.id;if(!de.has(_e)){if(de.add(_e),De){const Qe=ue.filter(ft=>{var ht;return((ht=ft.data.metadata)==null?void 0:ht.runGroupId)===De}).map(ft=>ft.id);Qe.length>1?Se.push({id:Qe[0],groupIds:Qe}):Se.push({id:Qe[0]})}else Se.push({id:qe.id});if(Se.length>=2)break}}Se.length>=2&&(ye(Se[0]),Te(Se[1]))},[Be,pe,Ie]);const As=zt.find(ee=>ee.name===o),gc=b.useMemo(()=>new Set(zt.map(ee=>ee.name)),[zt]),Ke=h==null?void 0:h._multiRun,Qn=Ke!=null&&D===-1,Ue=Ke&&D>=0?Ke.allRuns[D]:h;b.useEffect(()=>{E(null)},[D]);const Gn=b.useRef(f.status);b.useEffect(()=>{if(Gn.current!==f.status)if(Gn.current=f.status,f.status==="done"&&f.done){const{evalResultId:ee,runGroupId:ue}=f.done;(async()=>{try{await s.refetchQueries({queryKey:["evalHistory"]});const de=s.getQueryData(["evalHistory"])??[],Se=de.find(fe=>fe.id===ee);if(!Se){v(`Eval completed but result ${ee} was not found in history.`);return}if(ue){const qe=de.filter(_e=>{var Qe;return((Qe=_e.data.metadata)==null?void 0:Qe.runGroupId)===ue}).map(_e=>_e.data),De=m0(qe);x(De??Se.data)}else x(Se.data);E(null),H(-1)}catch(de){v(de instanceof Error?de.message:String(de))}finally{d0()}})()}else f.status==="error"&&f.error&&(Gn.current!=="done"&&v(f.error),s.invalidateQueries({queryKey:["evalHistory"]}),d0())},[f.status,f.done,f.error,s]);const hn=b.useCallback(async()=>{if(o){v(null),x(null),E(null),H(-1);try{await QS(o,w,_)}catch(ee){v(ee instanceof Error?ee.message:String(ee))}}},[o,w,_]),fl=b.useCallback(async()=>{if(!(!pe||!Ie)){X(!0),ce(null);try{const ee=De=>De.groupIds&&De.groupIds.length>1?De.groupIds:De.id,ue=ee(pe),de=ee(Ie),Se=De=>{var Rs;const _e=Be.find(ma=>ma.id===De.id);if(!_e)return null;const Qe=_e.data;if(!De.groupIds||De.groupIds.length<=1)return Qe;const ft=De.groupIds.map(ma=>{var It;return(It=Be.find(Bt=>Bt.id===ma))==null?void 0:It.data}).filter(ma=>ma!=null),ht=Math.min(...ft.map(ma=>ma.items.length)),Os=Object.keys(((Rs=Qe.summary)==null?void 0:Rs.scorers)??{}),gl=Array.from({length:ht},(ma,It)=>{const Bt={},Cr={};for(const Er of Os){const Ds=ft.map(en=>{var vl;return(vl=en.items[It])==null?void 0:vl.scores[Er]}).filter(en=>en!=null),Tr=Ds.length>0?Math.round(Ds.reduce((en,vl)=>en+vl,0)/Ds.length*1e3)/1e3:null;Bt[Er]=Tr,Cr[Er]={score:Tr}}return{...Qe.items[It],scores:Bt,scoreDetails:Cr}});return{...Qe,items:gl}};Re(Se(pe)),yt(Se(Ie));const fe=De=>!De.groupIds||De.groupIds.length<=1?null:De.groupIds.map(_e=>{var Qe;return(Qe=Be.find(ft=>ft.id===_e))==null?void 0:Qe.data}).filter(_e=>_e!=null);jt(fe(pe)),Ca(fe(Ie));const qe=await lS(ue,de);ce(qe)}catch(ee){v(ee instanceof Error?ee.message:String(ee))}finally{X(!1)}}},[Be,pe,Ie]),_s=b.useCallback(async(ee,ue)=>{v(null);try{const de=await sS(ee,ue);x(de),E(null),H(-1),i("run"),s.invalidateQueries({queryKey:["evalHistory"]})}catch(de){v(de instanceof Error?de.message:String(de))}},[s]),vc=b.useCallback(async ee=>{var Se;v(null);const ue=ee.id.slice(0,8);if(window.confirm(`Delete this eval history entry?
312
312
 
313
313
  ${ee.eval} (${ue})
314
314
 
315
- This cannot be undone.`))try{await rS(ee.id);const fe=qe=>{var De;return qe?qe.id===ee.id?!0:!!((De=qe.groupIds)!=null&&De.includes(ee.id)):!1};if(fe(pe)&&Te(null),fe(Ie)&&ye(null),h){const qe=h.id===ee.id,De=!!((Se=h._multiRun)!=null&&Se.allRuns.some(_e=>_e.id===ee.id));(qe||De)&&(x(null),E(null),H(-1),S(null))}s.invalidateQueries({queryKey:["evalHistory"]})}catch(fe){v(fe instanceof Error?fe.message:String(fe))}},[s,pe,Ie,h]),zi=b.useCallback(ee=>{j(ue=>{const de=new Set(ue);return de.has(ee)?de.delete(ee):de.add(ee),de})},[]),Yn=(Li=h==null?void 0:h.metadata)==null?void 0:Li.scorerTypes,Wa=(Hi=Ue==null?void 0:Ue.summary)!=null&&Hi.scorers?Object.keys(Ue.summary.scorers):[],Kn=(kr=Ue==null?void 0:Ue.summary)!=null&&kr.scorers?Object.entries(Ue.summary.scorers):[],hl=Kn.length>0?Kn.reduce((ee,[,ue])=>ee+ue.mean,0)/Kn.length:0,Pa=Ke?Object.entries(Ke.aggregate.scorers):[],ml=Pa.length>0?Pa.reduce((ee,[,ue])=>ee+ue.mean,0)/Pa.length:0,Nr=b.useMemo(()=>{if(!Ke)return 0;const ee=Ke.allRuns,ue=Object.keys(Ke.aggregate.scorers);if(ue.length===0||ee.length<=1)return 0;const de=ee.map(fe=>{const qe=ue.map(De=>{var _e,Qe,ft;return(ft=(Qe=(_e=fe.summary)==null?void 0:_e.scorers)==null?void 0:Qe[De])==null?void 0:ft.mean}).filter(De=>De!=null);return qe.length>0?qe.reduce((De,_e)=>De+_e,0)/qe.length:0}),Se=de.reduce((fe,qe)=>fe+qe,0)/de.length;return Math.sqrt(de.reduce((fe,qe)=>fe+(qe-Se)**2,0)/(de.length-1))},[Ke]),pl=Ke?Ke.allRuns.reduce((ee,ue)=>ee+ue.duration,0):0,Sr=Ke?Ke.allRuns.reduce((ee,ue)=>ee+ue.totalCost,0):0,Ui=b.useMemo(()=>{if(!Ke)return[];const ee=Object.entries(Ke.aggregate.scorers);return ee.sort((ue,de)=>{let Se,fe;switch(M){case"scorer":return G==="asc"?ue[0].localeCompare(de[0]):de[0].localeCompare(ue[0]);case"mean":Se=ue[1].mean,fe=de[1].mean;break;case"std":Se=ue[1].std,fe=de[1].std;break;case"min":Se=ue[1].min,fe=de[1].min;break;case"max":default:Se=ue[1].max,fe=de[1].max;break}return G==="desc"?fe-Se:Se-fe}),ee},[Ke,M,G]),aa=ee=>{M===ee?J(ue=>ue==="desc"?"asc":"desc"):(Q(ee),J("asc"))},bt=ee=>M===ee?G==="desc"?" ▼":" ▲":"",Vt=5,mn=b.useMemo(()=>{var Se;if(!Qn||!h)return[];const ee=h.items,ue=Object.keys(((Se=h.summary)==null?void 0:Se.scorers)??{});if(ue.length===0||ee.length===0)return[];const de=ee.map((fe,qe)=>{const De=ue.map(Qe=>fe.scores[Qe]).filter(Qe=>Qe!=null),_e=De.length>0?De.reduce((Qe,ft)=>Qe+ft,0)/De.length:1;return{item:fe,index:qe,avgScore:_e,scores:fe.scores}});return de.sort((fe,qe)=>fe.avgScore-qe.avgScore),de.slice(0,Vt)},[Qn,h]),wr=["run","history","compare","trends"];return n.jsxs("div",{className:"flex flex-col h-screen",children:[n.jsx(dl,{title:"Eval Runner",description:As?n.jsxs(n.Fragment,{children:[n.jsx("span",{children:As.workflow}),n.jsx("span",{className:"opacity-40 mx-1.5",children:"·"}),n.jsx("span",{children:As.dataset}),n.jsx("span",{className:"opacity-40 mx-1.5",children:"·"}),n.jsxs("span",{children:[As.scorers.length," scorer",As.scorers.length!==1?"s":""]})]}):zt.length>0?`${zt.length} registered eval${zt.length!==1?"s":""} · select one to run`:"No evals registered",actions:n.jsxs(n.Fragment,{children:[dn&&n.jsxs(n.Fragment,{children:[n.jsx("input",{ref:Ia,type:"file",accept:"application/json,.json",className:"hidden",onChange:ee=>{var de;const ue=(de=ee.target.files)==null?void 0:de[0];ue&&Jt(ue),ee.target.value=""}}),n.jsxs("button",{type:"button",onClick:()=>{var ee;return(ee=Ia.current)==null?void 0:ee.click()},disabled:fn,className:F("inline-flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium rounded-full cursor-pointer","ring-1 ring-[hsl(var(--input))] bg-[hsl(var(--background))] shadow-sm","hover:bg-[hsl(var(--muted))] hover:ring-[hsl(var(--ring))]","focus:outline-none focus-visible:ring-[hsl(var(--ring))] transition-all","disabled:opacity-40 disabled:cursor-not-allowed"),title:"Import an eval result JSON file (e.g. from `axl-eval --output`). Imported entries persist as long as the runtime's state store does.",children:[n.jsx(KN,{size:12}),fn?"Importing…":"Import result"]})]}),zt.length>0&&dn&&n.jsx(C5,{evals:zt,selectedEval:o,onSelectEval:d,runCount:w,onRunCountChange:C,captureTraces:_,onCaptureTracesChange:R,running:m,onRun:hn})]})}),n.jsx("div",{role:"tablist","aria-label":"Eval views",className:"shrink-0 flex items-center gap-1 px-4 sm:px-6 border-b border-[hsl(var(--border))]",children:wr.map(ee=>n.jsx("button",{type:"button",role:"tab","aria-selected":r===ee,onClick:()=>i(ee),className:F("px-3 py-2.5 text-sm -mb-px border-b-2 transition-colors cursor-pointer",r===ee?"border-[hsl(var(--foreground))] text-[hsl(var(--foreground))] font-medium":"border-transparent text-[hsl(var(--muted-foreground))] hover:text-[hsl(var(--foreground))]"),children:ee.charAt(0).toUpperCase()+ee.slice(1)},ee))}),p&&n.jsx("div",{className:"shrink-0 px-6 py-3 border-b border-red-200 dark:border-red-800 bg-red-50 dark:bg-red-950/30",children:n.jsxs("div",{className:"flex items-start justify-between gap-4",children:[n.jsx("div",{className:"text-sm text-red-700 dark:text-red-300 whitespace-pre-wrap break-words",children:p}),n.jsx("button",{onClick:()=>v(null),className:"shrink-0 text-xs text-red-600 dark:text-red-400 hover:text-red-900 dark:hover:text-red-200 cursor-pointer","aria-label":"Dismiss error",children:"Dismiss"})]})}),Nt&&n.jsx("div",{className:"shrink-0 px-6 py-2 border-b border-emerald-200 dark:border-emerald-900 bg-emerald-50 dark:bg-emerald-950/30",children:n.jsxs("div",{className:"flex items-start justify-between gap-4",children:[n.jsx("div",{className:"text-xs text-emerald-700 dark:text-emerald-300 whitespace-pre-wrap break-words",children:Nt}),n.jsx("button",{onClick:()=>Zt(null),className:"shrink-0 text-xs text-emerald-600 dark:text-emerald-400 hover:text-emerald-900 dark:hover:text-emerald-200 cursor-pointer","aria-label":"Dismiss import status",children:"Dismiss"})]})}),r==="run"&&n.jsx("div",{className:"flex-1 min-h-0 flex flex-col",children:zt.length===0?n.jsx("div",{className:"flex-1 flex items-center justify-center p-6",children:n.jsx(ta,{icon:n.jsx(pr,{size:32}),title:"No evals registered",description:"Define evals with defineEval() and load them via the evals middleware option or runtime.registerEval()."})}):h?n.jsxs(n.Fragment,{children:[(W==="history"||W==="trends")&&n.jsx("div",{className:"shrink-0 px-6 pt-4",children:n.jsxs("button",{onClick:()=>{i(W),K(null)},className:"inline-flex items-center gap-1.5 text-xs text-[hsl(var(--muted-foreground))] hover:text-[hsl(var(--foreground))] transition-colors cursor-pointer",children:[n.jsx(qj,{size:14}),"Back to ",W==="history"?"History":"Trends"]})}),Ke&&n.jsx("div",{className:"shrink-0 pt-4",children:n.jsx(j5,{currentIndex:D,totalRuns:Ke.allRuns.length,aggregate:Ke.aggregate,onIndexChange:H})}),(Ke==null?void 0:Ke.partial)&&n.jsxs("div",{className:"shrink-0 mx-6 mt-4 rounded-md border border-amber-300/60 bg-amber-50 dark:border-amber-500/40 dark:bg-amber-950/40 px-4 py-3 text-sm text-amber-900 dark:text-amber-200",role:"status",children:[n.jsxs("div",{className:"font-medium",children:["Partial batch — ",Ke.batchCompleted??Ke.allRuns.length," of"," ",Ke.batchAttempted??"?"," runs completed."]}),Ke.batchFailure&&n.jsxs("div",{className:"mt-1 text-amber-800/90 dark:text-amber-300/90",children:["Stopped after: ",Ke.batchFailure]}),n.jsxs("div",{className:"mt-1 text-amber-800/80 dark:text-amber-300/80",children:["Aggregate stats below are computed over the ",Ke.allRuns.length," completed run",Ke.allRuns.length===1?"":"s","."]})]}),Qn?n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"shrink-0 px-6 py-4",children:[n.jsxs("div",{className:"flex items-start justify-between mb-3",children:[n.jsxs("div",{className:"flex-1 flex flex-wrap items-center gap-x-4 gap-y-1.5",children:[(()=>{const ee=h?tr(h):[];if(ee.length===0)return null;const ue=h?rf(h):null;return n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("span",{className:"text-[10px] font-medium uppercase tracking-wider text-[hsl(var(--muted-foreground))]",children:ee.length>1?"Workflows":"Workflow"}),ee.map(de=>n.jsxs("span",{className:"px-1.5 py-0.5 rounded bg-[hsl(var(--secondary))] text-[hsl(var(--foreground))] text-[10px] font-mono font-medium",title:ue?`${de} — ${ue[de]} calls`:de,children:[de,ue&&ue[de]!=null&&n.jsxs("span",{className:"ml-1 text-[hsl(var(--muted-foreground))] font-normal",children:["(",ue[de],")"]})]},de))]})})(),(()=>{const ee=h?$n(h):[];if(ee.length===0)return null;const ue=h?Ts(h):null;return n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("span",{className:"text-[10px] font-medium uppercase tracking-wider text-[hsl(var(--muted-foreground))]",children:ee.length>1?"Models":"Model"}),ee.map(de=>n.jsxs("span",{className:"px-1.5 py-0.5 rounded bg-[hsl(var(--secondary))] text-[hsl(var(--foreground))] text-[10px] font-mono font-medium",title:ue?`${de} — ${ue[de]} calls`:de,children:[wa(de),ue&&ue[de]!=null&&n.jsxs("span",{className:"ml-1 text-[hsl(var(--muted-foreground))] font-normal",children:["(",ue[de],")"]})]},de))]})})()]}),n.jsx("button",{onClick:()=>{var ue;const ee=(ue=h==null?void 0:h.metadata)==null?void 0:ue.runGroupId;if(ee){const de=Be.filter(Se=>{var fe;return((fe=Se.data.metadata)==null?void 0:fe.runGroupId)===ee}).map(Se=>Se.id);de.length>0&&ye({id:de[0],groupIds:de})}else if(h){const de=Be.find(Se=>Se.id===h.id);de&&ye({id:de.id})}i("compare")},className:"px-3 py-1.5 text-xs font-medium rounded-lg border border-[hsl(var(--input))] hover:bg-[hsl(var(--accent))] transition-colors cursor-pointer",children:"Compare with previous..."})]}),h&&n.jsx(v0,{result:h}),h&&n.jsx(b0,{result:h}),h&&n.jsx(y0,{result:h}),n.jsxs("div",{className:"grid grid-cols-2 lg:grid-cols-5 gap-3",children:[n.jsx(tt,{label:"Runs",value:String(Ke.aggregate.runCount),subtitle:"individual runs"}),n.jsx(tt,{label:"Mean Score",value:Pa.length>0?ml.toFixed(3):"—",accent:Pa.length>0?Rt(ml):void 0,tint:Pa.length>0?p0(ml):void 0,subtitle:Pa.length>0?`± ${Nr.toFixed(3)} across runs`:"across all scorers"}),n.jsx(tt,{label:"Total Duration",value:pl>0?xt(pl):"—",subtitle:"all runs combined"}),n.jsx(tt,{label:"Total Cost",value:Sr>0?at(Sr):"—",subtitle:"all runs combined"}),(()=>{const ee=Ke.allRuns,ue={input:0,output:0,reasoning:0};for(const Se of ee){const fe=of(Se);ue.input+=fe.input,ue.output+=fe.output,ue.reasoning+=fe.reasoning}const de=ue.input+ue.output+ue.reasoning;return de>0?n.jsx(tt,{label:"Total Tokens",value:qa(de),subtitle:`${qa(ue.input)} in / ${qa(ue.output)} out`}):null})()]})]}),n.jsxs("div",{className:"flex-1 overflow-y-auto px-6 pb-6 space-y-6",children:[n.jsxs("div",{className:"rounded-xl border border-[hsl(var(--border))] overflow-hidden",children:[n.jsx("div",{className:"px-4 py-2.5 bg-[hsl(var(--muted))] border-b border-[hsl(var(--border))]",children:n.jsx("h3",{className:"text-[11px] font-medium uppercase tracking-wider text-[hsl(var(--muted-foreground))]",children:"Per-Scorer Aggregate"})}),n.jsx("div",{className:"overflow-x-auto",children:n.jsxs("table",{className:"w-full text-xs",children:[n.jsx("thead",{children:n.jsxs("tr",{className:"border-b border-[hsl(var(--border))]",children:[n.jsxs("th",{className:"text-left px-4 py-2 font-medium w-48 cursor-pointer select-none hover:text-[hsl(var(--foreground))]",onClick:()=>aa("scorer"),children:["Scorer",bt("scorer")]}),n.jsxs("th",{className:"text-right px-3 py-2 font-medium cursor-pointer select-none hover:text-[hsl(var(--foreground))]",onClick:()=>aa("mean"),children:["Mean",bt("mean")]}),n.jsxs("th",{className:"text-right px-3 py-2 font-medium cursor-pointer select-none hover:text-[hsl(var(--foreground))]",onClick:()=>aa("std"),children:["Std",bt("std")]}),n.jsxs("th",{className:"text-right px-3 py-2 font-medium cursor-pointer select-none hover:text-[hsl(var(--foreground))]",onClick:()=>aa("min"),children:["Min",bt("min")]}),n.jsxs("th",{className:"text-right px-3 py-2 font-medium cursor-pointer select-none hover:text-[hsl(var(--foreground))]",onClick:()=>aa("max"),children:["Max",bt("max")]})]})}),n.jsx("tbody",{children:Ui.map(([ee,ue])=>n.jsx(PS,{name:ee,stats:ue,isLlm:(Yn==null?void 0:Yn[ee])==="llm"},ee))})]})})]}),mn.length>0&&n.jsxs("div",{className:"rounded-xl border border-[hsl(var(--border))] overflow-hidden",children:[n.jsx("div",{className:"px-4 py-2.5 bg-[hsl(var(--muted))] border-b border-[hsl(var(--border))]",children:n.jsx("h3",{className:"text-[11px] font-medium uppercase tracking-wider text-[hsl(var(--muted-foreground))]",children:"Lowest Scoring Items"})}),n.jsx("div",{className:"divide-y divide-[hsl(var(--border))]",children:mn.map(({item:ee,index:ue,avgScore:de,scores:Se})=>{var Qe;const fe=k===ue,qe=Ke==null?void 0:Ke.allRuns,De=(qe==null?void 0:qe.length)??0,_e=fe&&qe?(Qe=qe[B])==null?void 0:Qe.items[ue]:null;return n.jsxs("div",{children:[n.jsxs("button",{onClick:()=>{S(fe?null:ue),$(0)},className:F("w-full text-left px-4 py-3 flex items-center gap-3 hover:bg-[hsl(var(--accent))] transition-colors cursor-pointer",fe&&"bg-[hsl(var(--accent))]"),children:[n.jsxs("span",{className:"shrink-0 text-[10px] font-mono text-[hsl(var(--muted-foreground))] w-6 text-right",children:["#",ue+1]}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsx("div",{className:"text-xs truncate",children:xr(ee.input,60)}),n.jsx("div",{className:"flex items-center gap-1.5 mt-1 flex-wrap",children:Object.entries(Se).map(([ft,ht])=>ht!=null?n.jsxs("span",{className:F("inline-flex items-center px-1.5 py-0.5 rounded text-[9px] font-mono",uc(ht)),title:ft,children:[ft,": ",ht.toFixed(2)]},ft):null)})]}),n.jsx("span",{className:F("shrink-0 text-xs font-mono font-medium",Rt(de)),children:de.toFixed(3)})]}),fe&&n.jsxs("div",{className:"border-t border-[hsl(var(--border))] bg-[hsl(var(--card))] text-xs",children:[De>1&&n.jsxs("div",{className:"flex items-center gap-2 px-4 py-2 border-b border-[hsl(var(--border))] bg-[hsl(var(--muted))]",children:[n.jsx("span",{className:"text-[10px] font-medium uppercase tracking-wider text-[hsl(var(--muted-foreground))]",children:"Run"}),n.jsx("div",{className:"flex items-center gap-0.5",children:Array.from({length:De},(ft,ht)=>n.jsx("button",{onClick:()=>$(ht),className:F("px-2 py-0.5 rounded text-[10px] font-mono transition-colors cursor-pointer",ht===B?"bg-[hsl(var(--foreground))] text-[hsl(var(--background))]":"text-[hsl(var(--muted-foreground))] hover:bg-[hsl(var(--accent))]"),children:ht+1},ht))})]}),n.jsxs("div",{className:"p-4 space-y-3",children:[_e&&n.jsx("div",{className:"flex items-center gap-1.5 flex-wrap",children:Object.entries(_e.scores).map(([ft,ht])=>ht!=null?n.jsxs("span",{className:F("inline-flex items-center px-1.5 py-0.5 rounded text-[9px] font-mono",uc(ht)),children:[ft,": ",ht.toFixed(3)]},ft):null)}),n.jsxs("div",{children:[n.jsx("span",{className:"font-medium text-[hsl(var(--muted-foreground))] text-[10px] uppercase tracking-wider block mb-1",children:"Output"}),n.jsx(Ct,{data:(_e==null?void 0:_e.output)??ee.output,collapsed:!0})]}),(_e==null?void 0:_e.scoreDetails)&&Object.entries(_e.scoreDetails).map(([ft,ht])=>{var gl;const Os=typeof((gl=ht==null?void 0:ht.metadata)==null?void 0:gl.reasoning)=="string"?ht.metadata.reasoning:null;return Os?n.jsxs("div",{children:[n.jsxs("span",{className:"font-medium text-[hsl(var(--muted-foreground))] text-[10px] uppercase tracking-wider block mb-1",children:[ft," reasoning"]}),n.jsx("pre",{className:"text-xs font-mono p-2 rounded-md bg-[hsl(var(--secondary))] overflow-auto max-h-32 whitespace-pre-wrap leading-relaxed",children:Os})]},ft):null})]})]})]},ue)})})]})]})]}):Ue?n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"shrink-0 px-6 py-4",children:[(()=>{const ee=tr(Ue),ue=rf(Ue),de=$n(Ue),Se=Ts(Ue);return ee.length===0&&de.length===0?null:n.jsxs("div",{className:"flex flex-wrap items-center gap-x-4 gap-y-1.5 mb-3",children:[ee.length>0&&n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("span",{className:"text-[10px] font-medium uppercase tracking-wider text-[hsl(var(--muted-foreground))]",children:ee.length>1?"Workflows":"Workflow"}),ee.map(fe=>n.jsxs("span",{className:"px-1.5 py-0.5 rounded bg-[hsl(var(--secondary))] text-[hsl(var(--foreground))] text-[10px] font-mono font-medium",title:ue?`${fe} — ${ue[fe]} calls`:fe,children:[fe,ue&&ue[fe]!=null&&n.jsxs("span",{className:"ml-1 text-[hsl(var(--muted-foreground))] font-normal",children:["(",ue[fe],")"]})]},fe))]}),de.length>0&&n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("span",{className:"text-[10px] font-medium uppercase tracking-wider text-[hsl(var(--muted-foreground))]",children:de.length>1?"Models":"Model"}),de.map(fe=>n.jsxs("span",{className:"px-1.5 py-0.5 rounded bg-[hsl(var(--secondary))] text-[hsl(var(--foreground))] text-[10px] font-mono font-medium",title:Se?`${fe} — ${Se[fe]} calls`:fe,children:[wa(fe),Se&&Se[fe]!=null&&n.jsxs("span",{className:"ml-1 text-[hsl(var(--muted-foreground))] font-normal",children:["(",Se[fe],")"]})]},fe))]})]})})(),n.jsx(v0,{result:Ue}),n.jsx(b0,{result:Ue}),n.jsx(y0,{result:Ue}),n.jsxs("div",{className:"grid grid-cols-2 lg:grid-cols-5 gap-3",children:[n.jsx(tt,{label:"Items",value:String(Ue.summary.count),subtitle:Ue.summary.failures>0?`${Ue.summary.failures} failed`:"all passed",subtitleColor:Ue.summary.failures>0?"text-red-600 dark:text-red-400":"text-emerald-600 dark:text-emerald-400"}),n.jsx(tt,{label:"Mean Score",value:Kn.length>0?hl.toFixed(3):"—",accent:Kn.length>0?Rt(hl):void 0,tint:Kn.length>0?p0(hl):void 0,subtitle:"across all scorers"}),n.jsx(tt,{label:"Duration",value:Ue.summary.timing?xt(Ue.summary.timing.mean):xt(Ue.duration),subtitle:Ue.summary.timing?`p95 ${xt(Ue.summary.timing.p95)}`:"total"}),n.jsx(tt,{label:"Cost",value:Ue.totalCost>0?at(Ue.totalCost):"—",subtitle:"total"}),(()=>{const ee=of(Ue),ue=ee.input+ee.output+ee.reasoning;return ue>0?n.jsx(tt,{label:"Tokens",value:qa(ue),subtitle:`${qa(ee.input)} in / ${qa(ee.output)} out`}):null})()]})]}),n.jsx(jr,{className:"flex-1 border-t border-[hsl(var(--border))]",defaultPercent:30,minPercent:15,maxPercent:50,left:n.jsx("div",{className:"flex-1 overflow-y-auto bg-[hsl(var(--card))]",children:n.jsx(u5,{items:Ue.items,scorerNames:Wa,selectedIndex:y,onSelectItem:E,onDeselectItem:()=>E(null)})}),right:n.jsx("div",{className:"flex-1 overflow-y-auto",children:y!=null?n.jsx("div",{className:"p-6",children:n.jsx(o5,{item:Ue.items[y],itemIndex:y,scorerNames:Wa,onBack:()=>E(null)})}):n.jsxs("div",{className:"p-6 space-y-6",children:[n.jsx(s5,{summary:Ue.summary,items:Ue.items,totalCost:Ue.totalCost,scorerTypes:Yn}),n.jsx(f5,{items:Ue.items,scorerNames:Wa}),Ue.items.length>0&&n.jsx(l5,{items:Ue.items,scorerNames:Wa,onSelectItem:E,errorFilter:te,onErrorFilterChange:re,scorerFilter:Me,onScorerFilterChange:he,threshold:ae,onThresholdChange:z,sortField:L,onSortFieldChange:ie,sortDir:ve,onSortDirChange:ge})]})})})]}):null]}):m?n.jsx(M5,{exec:f,onCancel:$S}):n.jsx("div",{className:"flex-1 flex items-center justify-center",children:n.jsx(ta,{icon:n.jsx(pr,{size:32}),title:"No results",description:"Select an eval and run it to see results."})})}),r==="history"&&n.jsx("div",{className:"flex-1 overflow-auto p-4 sm:p-6",children:Be.length===0?n.jsx(ta,{title:"No eval history",description:"Run evaluations to build history."}):n.jsx(w5,{history:Be,evalFilter:oe,onEvalFilterChange:me,onSelect:ee=>{x(ee),E(null),H(-1),K("history"),i("run")},onSelectGroup:ee=>{const ue=ee.map(Se=>Se.data),de=m0(ue);de&&(x(de),E(null),H(-1),K("history"),i("run"))},onRescore:_s,onDelete:vc,registeredEvalNames:gc,readOnly:$e,expandedGroups:T,onToggleGroup:zi})}),r==="trends"&&n.jsx(KS,{onViewRun:ee=>{const ue=Be.find(de=>de.id===ee);ue&&(x(ue.data),E(null),H(-1),K("trends"),i("run"))}}),r==="compare"&&n.jsx("div",{className:"flex-1 overflow-auto p-4 sm:p-6",children:n.jsx("div",{className:"space-y-4",children:Be.length<2?n.jsx(ta,{title:"Need at least 2 eval runs",description:"Run evaluations to compare results."}):n.jsxs(n.Fragment,{children:[n.jsx(y5,{history:Be,baselineSelection:pe,candidateSelection:Ie,onBaselineChange:Te,onCandidateChange:ye,onCompare:fl,comparing:be}),ne&&n.jsx(x5,{compareResult:ne,baseline:we,candidate:dt,isGroupComparison:(((Vn=pe==null?void 0:pe.groupIds)==null?void 0:Vn.length)??0)>1||(((xl=Ie==null?void 0:Ie.groupIds)==null?void 0:xl.length)??0)>1,baselineRuns:Je,candidateRuns:Dt})]})})})]})}function M5({exec:s,onCancel:r}){const[i,o]=b.useState(0);b.useEffect(()=>{if(!s.startedAt)return;o(Math.floor((Date.now()-s.startedAt)/1e3));const C=setInterval(()=>{o(Math.floor((Date.now()-s.startedAt)/1e3))},1e3);return()=>clearInterval(C)},[s.startedAt]);const d=Math.floor(i/60),f=i%60,m=d>0?`${d}m ${f}s`:`${f}s`,h=s.progress,x=(s.runCount??1)>1,p=(h==null?void 0:h.totalItems)??0,v=(h==null?void 0:h.completedItems)??0,y=(h==null?void 0:h.completedRuns)??0,E=(h==null?void 0:h.totalRuns)??s.runCount??1,w=p>0?Math.round(v/p*100):0;return n.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center gap-5",children:[n.jsxs("div",{className:"relative",children:[n.jsx(pr,{size:28,className:"text-[hsl(var(--muted-foreground))]"}),n.jsx("div",{className:"absolute -top-0.5 -right-0.5 w-2.5 h-2.5 rounded-full bg-emerald-500 animate-ping"}),n.jsx("div",{className:"absolute -top-0.5 -right-0.5 w-2.5 h-2.5 rounded-full bg-emerald-500"})]}),n.jsxs("div",{className:"text-center space-y-1",children:[n.jsx("p",{className:"text-sm font-medium",children:x?`Run ${y+1} of ${E}`:"Running evaluation…"}),s.evalName&&n.jsxs("p",{className:"text-xs text-[hsl(var(--muted-foreground))]",children:[s.evalName,x?` · ${E} runs`:""]})]}),p>0&&n.jsxs("div",{className:"w-56 space-y-1.5",children:[n.jsx("div",{className:"h-1.5 rounded-full bg-[hsl(var(--muted))] overflow-hidden",children:n.jsx("div",{className:"h-full rounded-full bg-emerald-500 transition-all duration-300 ease-out",style:{width:`${w}%`}})}),n.jsxs("p",{className:"text-[11px] text-[hsl(var(--muted-foreground))] text-center tabular-nums",children:[v," / ",p," items"]})]}),n.jsx("p",{className:"text-[11px] text-[hsl(var(--muted-foreground))] tabular-nums",children:m}),n.jsxs("button",{onClick:r,className:`inline-flex items-center gap-1.5 px-3 py-1 text-xs rounded-md
315
+ This cannot be undone.`))try{await iS(ee.id);const fe=qe=>{var De;return qe?qe.id===ee.id?!0:!!((De=qe.groupIds)!=null&&De.includes(ee.id)):!1};if(fe(pe)&&Te(null),fe(Ie)&&ye(null),h){const qe=h.id===ee.id,De=!!((Se=h._multiRun)!=null&&Se.allRuns.some(_e=>_e.id===ee.id));(qe||De)&&(x(null),E(null),H(-1),S(null))}s.invalidateQueries({queryKey:["evalHistory"]})}catch(fe){v(fe instanceof Error?fe.message:String(fe))}},[s,pe,Ie,h]),zi=b.useCallback(ee=>{j(ue=>{const de=new Set(ue);return de.has(ee)?de.delete(ee):de.add(ee),de})},[]),Yn=(Li=h==null?void 0:h.metadata)==null?void 0:Li.scorerTypes,Wa=(Hi=Ue==null?void 0:Ue.summary)!=null&&Hi.scorers?Object.keys(Ue.summary.scorers):[],Kn=(kr=Ue==null?void 0:Ue.summary)!=null&&kr.scorers?Object.entries(Ue.summary.scorers):[],hl=Kn.length>0?Kn.reduce((ee,[,ue])=>ee+ue.mean,0)/Kn.length:0,Pa=Ke?Object.entries(Ke.aggregate.scorers):[],ml=Pa.length>0?Pa.reduce((ee,[,ue])=>ee+ue.mean,0)/Pa.length:0,Nr=b.useMemo(()=>{if(!Ke)return 0;const ee=Ke.allRuns,ue=Object.keys(Ke.aggregate.scorers);if(ue.length===0||ee.length<=1)return 0;const de=ee.map(fe=>{const qe=ue.map(De=>{var _e,Qe,ft;return(ft=(Qe=(_e=fe.summary)==null?void 0:_e.scorers)==null?void 0:Qe[De])==null?void 0:ft.mean}).filter(De=>De!=null);return qe.length>0?qe.reduce((De,_e)=>De+_e,0)/qe.length:0}),Se=de.reduce((fe,qe)=>fe+qe,0)/de.length;return Math.sqrt(de.reduce((fe,qe)=>fe+(qe-Se)**2,0)/(de.length-1))},[Ke]),pl=Ke?Ke.allRuns.reduce((ee,ue)=>ee+ue.duration,0):0,Sr=Ke?Ke.allRuns.reduce((ee,ue)=>ee+ue.totalCost,0):0,Ui=b.useMemo(()=>{if(!Ke)return[];const ee=Object.entries(Ke.aggregate.scorers);return ee.sort((ue,de)=>{let Se,fe;switch(M){case"scorer":return G==="asc"?ue[0].localeCompare(de[0]):de[0].localeCompare(ue[0]);case"mean":Se=ue[1].mean,fe=de[1].mean;break;case"std":Se=ue[1].std,fe=de[1].std;break;case"min":Se=ue[1].min,fe=de[1].min;break;case"max":default:Se=ue[1].max,fe=de[1].max;break}return G==="desc"?fe-Se:Se-fe}),ee},[Ke,M,G]),aa=ee=>{M===ee?J(ue=>ue==="desc"?"asc":"desc"):(Q(ee),J("asc"))},bt=ee=>M===ee?G==="desc"?" ▼":" ▲":"",Vt=5,mn=b.useMemo(()=>{var Se;if(!Qn||!h)return[];const ee=h.items,ue=Object.keys(((Se=h.summary)==null?void 0:Se.scorers)??{});if(ue.length===0||ee.length===0)return[];const de=ee.map((fe,qe)=>{const De=ue.map(Qe=>fe.scores[Qe]).filter(Qe=>Qe!=null),_e=De.length>0?De.reduce((Qe,ft)=>Qe+ft,0)/De.length:1;return{item:fe,index:qe,avgScore:_e,scores:fe.scores}});return de.sort((fe,qe)=>fe.avgScore-qe.avgScore),de.slice(0,Vt)},[Qn,h]),wr=["run","history","compare","trends"];return n.jsxs("div",{className:"flex flex-col h-screen",children:[n.jsx(dl,{title:"Eval Runner",description:As?n.jsxs(n.Fragment,{children:[n.jsx("span",{children:As.workflow}),n.jsx("span",{className:"opacity-40 mx-1.5",children:"·"}),n.jsx("span",{children:As.dataset}),n.jsx("span",{className:"opacity-40 mx-1.5",children:"·"}),n.jsxs("span",{children:[As.scorers.length," scorer",As.scorers.length!==1?"s":""]})]}):zt.length>0?`${zt.length} registered eval${zt.length!==1?"s":""} · select one to run`:"No evals registered",actions:n.jsxs(n.Fragment,{children:[dn&&n.jsxs(n.Fragment,{children:[n.jsx("input",{ref:Ia,type:"file",accept:"application/json,.json",className:"hidden",onChange:ee=>{var de;const ue=(de=ee.target.files)==null?void 0:de[0];ue&&Jt(ue),ee.target.value=""}}),n.jsxs("button",{type:"button",onClick:()=>{var ee;return(ee=Ia.current)==null?void 0:ee.click()},disabled:fn,className:F("inline-flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium rounded-full cursor-pointer","ring-1 ring-[hsl(var(--input))] bg-[hsl(var(--background))] shadow-sm","hover:bg-[hsl(var(--muted))] hover:ring-[hsl(var(--ring))]","focus:outline-none focus-visible:ring-[hsl(var(--ring))] transition-all","disabled:opacity-40 disabled:cursor-not-allowed"),title:"Import an eval result JSON file (e.g. from `axl-eval --output`). Imported entries persist as long as the runtime's state store does.",children:[n.jsx(KN,{size:12}),fn?"Importing…":"Import result"]})]}),zt.length>0&&dn&&n.jsx(T5,{evals:zt,selectedEval:o,onSelectEval:d,runCount:w,onRunCountChange:C,captureTraces:_,onCaptureTracesChange:R,running:m,onRun:hn})]})}),n.jsx("div",{role:"tablist","aria-label":"Eval views",className:"shrink-0 flex items-center gap-1 px-4 sm:px-6 border-b border-[hsl(var(--border))]",children:wr.map(ee=>n.jsx("button",{type:"button",role:"tab","aria-selected":r===ee,onClick:()=>i(ee),className:F("px-3 py-2.5 text-sm -mb-px border-b-2 transition-colors cursor-pointer",r===ee?"border-[hsl(var(--foreground))] text-[hsl(var(--foreground))] font-medium":"border-transparent text-[hsl(var(--muted-foreground))] hover:text-[hsl(var(--foreground))]"),children:ee.charAt(0).toUpperCase()+ee.slice(1)},ee))}),p&&n.jsx("div",{className:"shrink-0 px-6 py-3 border-b border-red-200 dark:border-red-800 bg-red-50 dark:bg-red-950/30",children:n.jsxs("div",{className:"flex items-start justify-between gap-4",children:[n.jsx("div",{className:"text-sm text-red-700 dark:text-red-300 whitespace-pre-wrap break-words",children:p}),n.jsx("button",{onClick:()=>v(null),className:"shrink-0 text-xs text-red-600 dark:text-red-400 hover:text-red-900 dark:hover:text-red-200 cursor-pointer","aria-label":"Dismiss error",children:"Dismiss"})]})}),Nt&&n.jsx("div",{className:"shrink-0 px-6 py-2 border-b border-emerald-200 dark:border-emerald-900 bg-emerald-50 dark:bg-emerald-950/30",children:n.jsxs("div",{className:"flex items-start justify-between gap-4",children:[n.jsx("div",{className:"text-xs text-emerald-700 dark:text-emerald-300 whitespace-pre-wrap break-words",children:Nt}),n.jsx("button",{onClick:()=>Zt(null),className:"shrink-0 text-xs text-emerald-600 dark:text-emerald-400 hover:text-emerald-900 dark:hover:text-emerald-200 cursor-pointer","aria-label":"Dismiss import status",children:"Dismiss"})]})}),r==="run"&&n.jsx("div",{className:"flex-1 min-h-0 flex flex-col",children:zt.length===0?n.jsx("div",{className:"flex-1 flex items-center justify-center p-6",children:n.jsx(ta,{icon:n.jsx(pr,{size:32}),title:"No evals registered",description:"Define evals with defineEval() and load them via the evals middleware option or runtime.registerEval()."})}):h?n.jsxs(n.Fragment,{children:[(W==="history"||W==="trends")&&n.jsx("div",{className:"shrink-0 px-6 pt-4",children:n.jsxs("button",{onClick:()=>{i(W),K(null)},className:"inline-flex items-center gap-1.5 text-xs text-[hsl(var(--muted-foreground))] hover:text-[hsl(var(--foreground))] transition-colors cursor-pointer",children:[n.jsx(qj,{size:14}),"Back to ",W==="history"?"History":"Trends"]})}),Ke&&n.jsx("div",{className:"shrink-0 pt-4",children:n.jsx(S5,{currentIndex:D,totalRuns:Ke.allRuns.length,aggregate:Ke.aggregate,onIndexChange:H})}),(Ke==null?void 0:Ke.partial)&&n.jsxs("div",{className:"shrink-0 mx-6 mt-4 rounded-md border border-amber-300/60 bg-amber-50 dark:border-amber-500/40 dark:bg-amber-950/40 px-4 py-3 text-sm text-amber-900 dark:text-amber-200",role:"status",children:[n.jsxs("div",{className:"font-medium",children:["Partial batch — ",Ke.batchCompleted??Ke.allRuns.length," of"," ",Ke.batchAttempted??"?"," runs completed."]}),Ke.batchFailure&&n.jsxs("div",{className:"mt-1 text-amber-800/90 dark:text-amber-300/90",children:["Stopped after: ",Ke.batchFailure]}),n.jsxs("div",{className:"mt-1 text-amber-800/80 dark:text-amber-300/80",children:["Aggregate stats below are computed over the ",Ke.allRuns.length," completed run",Ke.allRuns.length===1?"":"s","."]})]}),Qn?n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"shrink-0 px-6 py-4",children:[n.jsxs("div",{className:"flex items-start justify-between mb-3",children:[n.jsxs("div",{className:"flex-1 flex flex-wrap items-center gap-x-4 gap-y-1.5",children:[(()=>{const ee=h?tr(h):[];if(ee.length===0)return null;const ue=h?rf(h):null;return n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("span",{className:"text-[10px] font-medium uppercase tracking-wider text-[hsl(var(--muted-foreground))]",children:ee.length>1?"Workflows":"Workflow"}),ee.map(de=>n.jsxs("span",{className:"px-1.5 py-0.5 rounded bg-[hsl(var(--secondary))] text-[hsl(var(--foreground))] text-[10px] font-mono font-medium",title:ue?`${de} — ${ue[de]} calls`:de,children:[de,ue&&ue[de]!=null&&n.jsxs("span",{className:"ml-1 text-[hsl(var(--muted-foreground))] font-normal",children:["(",ue[de],")"]})]},de))]})})(),(()=>{const ee=h?$n(h):[];if(ee.length===0)return null;const ue=h?Ts(h):null;return n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("span",{className:"text-[10px] font-medium uppercase tracking-wider text-[hsl(var(--muted-foreground))]",children:ee.length>1?"Models":"Model"}),ee.map(de=>n.jsxs("span",{className:"px-1.5 py-0.5 rounded bg-[hsl(var(--secondary))] text-[hsl(var(--foreground))] text-[10px] font-mono font-medium",title:ue?`${de} — ${ue[de]} calls`:de,children:[wa(de),ue&&ue[de]!=null&&n.jsxs("span",{className:"ml-1 text-[hsl(var(--muted-foreground))] font-normal",children:["(",ue[de],")"]})]},de))]})})()]}),n.jsx("button",{onClick:()=>{var ue;const ee=(ue=h==null?void 0:h.metadata)==null?void 0:ue.runGroupId;if(ee){const de=Be.filter(Se=>{var fe;return((fe=Se.data.metadata)==null?void 0:fe.runGroupId)===ee}).map(Se=>Se.id);de.length>0&&ye({id:de[0],groupIds:de})}else if(h){const de=Be.find(Se=>Se.id===h.id);de&&ye({id:de.id})}i("compare")},className:"px-3 py-1.5 text-xs font-medium rounded-lg border border-[hsl(var(--input))] hover:bg-[hsl(var(--accent))] transition-colors cursor-pointer",children:"Compare with previous..."})]}),h&&n.jsx(v0,{result:h}),h&&n.jsx(b0,{result:h}),h&&n.jsx(y0,{result:h}),n.jsxs("div",{className:"grid grid-cols-2 lg:grid-cols-5 gap-3",children:[n.jsx(tt,{label:"Runs",value:String(Ke.aggregate.runCount),subtitle:"individual runs"}),n.jsx(tt,{label:"Mean Score",value:Pa.length>0?ml.toFixed(3):"—",accent:Pa.length>0?Rt(ml):void 0,tint:Pa.length>0?p0(ml):void 0,subtitle:Pa.length>0?`± ${Nr.toFixed(3)} across runs`:"across all scorers"}),n.jsx(tt,{label:"Total Duration",value:pl>0?xt(pl):"—",subtitle:"all runs combined"}),n.jsx(tt,{label:"Total Cost",value:Sr>0?at(Sr):"—",subtitle:"all runs combined"}),(()=>{const ee=Ke.allRuns,ue={input:0,output:0,reasoning:0};for(const Se of ee){const fe=of(Se);ue.input+=fe.input,ue.output+=fe.output,ue.reasoning+=fe.reasoning}const de=ue.input+ue.output+ue.reasoning;return de>0?n.jsx(tt,{label:"Total Tokens",value:qa(de),subtitle:`${qa(ue.input)} in / ${qa(ue.output)} out`}):null})()]})]}),n.jsxs("div",{className:"flex-1 overflow-y-auto px-6 pb-6 space-y-6",children:[n.jsxs("div",{className:"rounded-xl border border-[hsl(var(--border))] overflow-hidden",children:[n.jsx("div",{className:"px-4 py-2.5 bg-[hsl(var(--muted))] border-b border-[hsl(var(--border))]",children:n.jsx("h3",{className:"text-[11px] font-medium uppercase tracking-wider text-[hsl(var(--muted-foreground))]",children:"Per-Scorer Aggregate"})}),n.jsx("div",{className:"overflow-x-auto",children:n.jsxs("table",{className:"w-full text-xs",children:[n.jsx("thead",{children:n.jsxs("tr",{className:"border-b border-[hsl(var(--border))]",children:[n.jsxs("th",{className:"text-left px-4 py-2 font-medium w-48 cursor-pointer select-none hover:text-[hsl(var(--foreground))]",onClick:()=>aa("scorer"),children:["Scorer",bt("scorer")]}),n.jsxs("th",{className:"text-right px-3 py-2 font-medium cursor-pointer select-none hover:text-[hsl(var(--foreground))]",onClick:()=>aa("mean"),children:["Mean",bt("mean")]}),n.jsxs("th",{className:"text-right px-3 py-2 font-medium cursor-pointer select-none hover:text-[hsl(var(--foreground))]",onClick:()=>aa("std"),children:["Std",bt("std")]}),n.jsxs("th",{className:"text-right px-3 py-2 font-medium cursor-pointer select-none hover:text-[hsl(var(--foreground))]",onClick:()=>aa("min"),children:["Min",bt("min")]}),n.jsxs("th",{className:"text-right px-3 py-2 font-medium cursor-pointer select-none hover:text-[hsl(var(--foreground))]",onClick:()=>aa("max"),children:["Max",bt("max")]})]})}),n.jsx("tbody",{children:Ui.map(([ee,ue])=>n.jsx(t5,{name:ee,stats:ue,isLlm:(Yn==null?void 0:Yn[ee])==="llm"},ee))})]})})]}),mn.length>0&&n.jsxs("div",{className:"rounded-xl border border-[hsl(var(--border))] overflow-hidden",children:[n.jsx("div",{className:"px-4 py-2.5 bg-[hsl(var(--muted))] border-b border-[hsl(var(--border))]",children:n.jsx("h3",{className:"text-[11px] font-medium uppercase tracking-wider text-[hsl(var(--muted-foreground))]",children:"Lowest Scoring Items"})}),n.jsx("div",{className:"divide-y divide-[hsl(var(--border))]",children:mn.map(({item:ee,index:ue,avgScore:de,scores:Se})=>{var Qe;const fe=k===ue,qe=Ke==null?void 0:Ke.allRuns,De=(qe==null?void 0:qe.length)??0,_e=fe&&qe?(Qe=qe[B])==null?void 0:Qe.items[ue]:null;return n.jsxs("div",{children:[n.jsxs("button",{onClick:()=>{S(fe?null:ue),$(0)},className:F("w-full text-left px-4 py-3 flex items-center gap-3 hover:bg-[hsl(var(--accent))] transition-colors cursor-pointer",fe&&"bg-[hsl(var(--accent))]"),children:[n.jsxs("span",{className:"shrink-0 text-[10px] font-mono text-[hsl(var(--muted-foreground))] w-6 text-right",children:["#",ue+1]}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsx("div",{className:"text-xs truncate",children:xr(ee.input,60)}),n.jsx("div",{className:"flex items-center gap-1.5 mt-1 flex-wrap",children:Object.entries(Se).map(([ft,ht])=>ht!=null?n.jsxs("span",{className:F("inline-flex items-center px-1.5 py-0.5 rounded text-[9px] font-mono",uc(ht)),title:ft,children:[ft,": ",ht.toFixed(2)]},ft):null)})]}),n.jsx("span",{className:F("shrink-0 text-xs font-mono font-medium",Rt(de)),children:de.toFixed(3)})]}),fe&&n.jsxs("div",{className:"border-t border-[hsl(var(--border))] bg-[hsl(var(--card))] text-xs",children:[De>1&&n.jsxs("div",{className:"flex items-center gap-2 px-4 py-2 border-b border-[hsl(var(--border))] bg-[hsl(var(--muted))]",children:[n.jsx("span",{className:"text-[10px] font-medium uppercase tracking-wider text-[hsl(var(--muted-foreground))]",children:"Run"}),n.jsx("div",{className:"flex items-center gap-0.5",children:Array.from({length:De},(ft,ht)=>n.jsx("button",{onClick:()=>$(ht),className:F("px-2 py-0.5 rounded text-[10px] font-mono transition-colors cursor-pointer",ht===B?"bg-[hsl(var(--foreground))] text-[hsl(var(--background))]":"text-[hsl(var(--muted-foreground))] hover:bg-[hsl(var(--accent))]"),children:ht+1},ht))})]}),n.jsxs("div",{className:"p-4 space-y-3",children:[_e&&n.jsx("div",{className:"flex items-center gap-1.5 flex-wrap",children:Object.entries(_e.scores).map(([ft,ht])=>ht!=null?n.jsxs("span",{className:F("inline-flex items-center px-1.5 py-0.5 rounded text-[9px] font-mono",uc(ht)),children:[ft,": ",ht.toFixed(3)]},ft):null)}),n.jsxs("div",{children:[n.jsx("span",{className:"font-medium text-[hsl(var(--muted-foreground))] text-[10px] uppercase tracking-wider block mb-1",children:"Output"}),n.jsx(Ct,{data:(_e==null?void 0:_e.output)??ee.output,collapsed:!0})]}),(_e==null?void 0:_e.scoreDetails)&&Object.entries(_e.scoreDetails).map(([ft,ht])=>{var gl;const Os=typeof((gl=ht==null?void 0:ht.metadata)==null?void 0:gl.reasoning)=="string"?ht.metadata.reasoning:null;return Os?n.jsxs("div",{children:[n.jsxs("span",{className:"font-medium text-[hsl(var(--muted-foreground))] text-[10px] uppercase tracking-wider block mb-1",children:[ft," reasoning"]}),n.jsx("pre",{className:"text-xs font-mono p-2 rounded-md bg-[hsl(var(--secondary))] overflow-auto max-h-32 whitespace-pre-wrap leading-relaxed",children:Os})]},ft):null})]})]})]},ue)})})]})]})]}):Ue?n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"shrink-0 px-6 py-4",children:[(()=>{const ee=tr(Ue),ue=rf(Ue),de=$n(Ue),Se=Ts(Ue);return ee.length===0&&de.length===0?null:n.jsxs("div",{className:"flex flex-wrap items-center gap-x-4 gap-y-1.5 mb-3",children:[ee.length>0&&n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("span",{className:"text-[10px] font-medium uppercase tracking-wider text-[hsl(var(--muted-foreground))]",children:ee.length>1?"Workflows":"Workflow"}),ee.map(fe=>n.jsxs("span",{className:"px-1.5 py-0.5 rounded bg-[hsl(var(--secondary))] text-[hsl(var(--foreground))] text-[10px] font-mono font-medium",title:ue?`${fe} — ${ue[fe]} calls`:fe,children:[fe,ue&&ue[fe]!=null&&n.jsxs("span",{className:"ml-1 text-[hsl(var(--muted-foreground))] font-normal",children:["(",ue[fe],")"]})]},fe))]}),de.length>0&&n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("span",{className:"text-[10px] font-medium uppercase tracking-wider text-[hsl(var(--muted-foreground))]",children:de.length>1?"Models":"Model"}),de.map(fe=>n.jsxs("span",{className:"px-1.5 py-0.5 rounded bg-[hsl(var(--secondary))] text-[hsl(var(--foreground))] text-[10px] font-mono font-medium",title:Se?`${fe} — ${Se[fe]} calls`:fe,children:[wa(fe),Se&&Se[fe]!=null&&n.jsxs("span",{className:"ml-1 text-[hsl(var(--muted-foreground))] font-normal",children:["(",Se[fe],")"]})]},fe))]})]})})(),n.jsx(v0,{result:Ue}),n.jsx(b0,{result:Ue}),n.jsx(y0,{result:Ue}),n.jsxs("div",{className:"grid grid-cols-2 lg:grid-cols-5 gap-3",children:[n.jsx(tt,{label:"Items",value:String(Ue.summary.count),subtitle:Ue.summary.failures>0?`${Ue.summary.failures} failed`:"all passed",subtitleColor:Ue.summary.failures>0?"text-red-600 dark:text-red-400":"text-emerald-600 dark:text-emerald-400"}),n.jsx(tt,{label:"Mean Score",value:Kn.length>0?hl.toFixed(3):"—",accent:Kn.length>0?Rt(hl):void 0,tint:Kn.length>0?p0(hl):void 0,subtitle:"across all scorers"}),n.jsx(tt,{label:"Duration",value:Ue.summary.timing?xt(Ue.summary.timing.mean):xt(Ue.duration),subtitle:Ue.summary.timing?`p95 ${xt(Ue.summary.timing.p95)}`:"total"}),n.jsx(tt,{label:"Cost",value:Ue.totalCost>0?at(Ue.totalCost):"—",subtitle:"total"}),(()=>{const ee=of(Ue),ue=ee.input+ee.output+ee.reasoning;return ue>0?n.jsx(tt,{label:"Tokens",value:qa(ue),subtitle:`${qa(ee.input)} in / ${qa(ee.output)} out`}):null})()]})]}),n.jsx(jr,{className:"flex-1 border-t border-[hsl(var(--border))]",defaultPercent:30,minPercent:15,maxPercent:50,left:n.jsx("div",{className:"flex-1 overflow-y-auto bg-[hsl(var(--card))]",children:n.jsx(f5,{items:Ue.items,scorerNames:Wa,selectedIndex:y,onSelectItem:E,onDeselectItem:()=>E(null)})}),right:n.jsx("div",{className:"flex-1 overflow-y-auto",children:y!=null?n.jsx("div",{className:"p-6",children:n.jsx(u5,{item:Ue.items[y],itemIndex:y,scorerNames:Wa,onBack:()=>E(null)})}):n.jsxs("div",{className:"p-6 space-y-6",children:[n.jsx(r5,{summary:Ue.summary,items:Ue.items,totalCost:Ue.totalCost,scorerTypes:Yn}),n.jsx(m5,{items:Ue.items,scorerNames:Wa}),Ue.items.length>0&&n.jsx(i5,{items:Ue.items,scorerNames:Wa,onSelectItem:E,errorFilter:te,onErrorFilterChange:re,scorerFilter:Me,onScorerFilterChange:he,threshold:ae,onThresholdChange:z,sortField:L,onSortFieldChange:ie,sortDir:ve,onSortDirChange:ge})]})})})]}):null]}):m?n.jsx(_5,{exec:f,onCancel:GS}):n.jsx("div",{className:"flex-1 flex items-center justify-center",children:n.jsx(ta,{icon:n.jsx(pr,{size:32}),title:"No results",description:"Select an eval and run it to see results."})})}),r==="history"&&n.jsx("div",{className:"flex-1 overflow-auto p-4 sm:p-6",children:Be.length===0?n.jsx(ta,{title:"No eval history",description:"Run evaluations to build history."}):n.jsx(C5,{history:Be,evalFilter:oe,onEvalFilterChange:me,onSelect:ee=>{x(ee),E(null),H(-1),K("history"),i("run")},onSelectGroup:ee=>{const ue=ee.map(Se=>Se.data),de=m0(ue);de&&(x(de),E(null),H(-1),K("history"),i("run"))},onRescore:_s,onDelete:vc,registeredEvalNames:gc,readOnly:$e,expandedGroups:T,onToggleGroup:zi})}),r==="trends"&&n.jsx(XS,{onViewRun:ee=>{const ue=Be.find(de=>de.id===ee);ue&&(x(ue.data),E(null),H(-1),K("trends"),i("run"))}}),r==="compare"&&n.jsx("div",{className:"flex-1 overflow-auto p-4 sm:p-6",children:n.jsx("div",{className:"space-y-4",children:Be.length<2?n.jsx(ta,{title:"Need at least 2 eval runs",description:"Run evaluations to compare results."}):n.jsxs(n.Fragment,{children:[n.jsx(N5,{history:Be,baselineSelection:pe,candidateSelection:Ie,onBaselineChange:Te,onCandidateChange:ye,onCompare:fl,comparing:be}),ne&&n.jsx(v5,{compareResult:ne,baseline:we,candidate:dt,isGroupComparison:(((Vn=pe==null?void 0:pe.groupIds)==null?void 0:Vn.length)??0)>1||(((xl=Ie==null?void 0:Ie.groupIds)==null?void 0:xl.length)??0)>1,baselineRuns:Je,candidateRuns:Dt})]})})})]})}function _5({exec:s,onCancel:r}){const[i,o]=b.useState(0);b.useEffect(()=>{if(!s.startedAt)return;o(Math.floor((Date.now()-s.startedAt)/1e3));const C=setInterval(()=>{o(Math.floor((Date.now()-s.startedAt)/1e3))},1e3);return()=>clearInterval(C)},[s.startedAt]);const d=Math.floor(i/60),f=i%60,m=d>0?`${d}m ${f}s`:`${f}s`,h=s.progress,x=(s.runCount??1)>1,p=(h==null?void 0:h.totalItems)??0,v=(h==null?void 0:h.completedItems)??0,y=(h==null?void 0:h.completedRuns)??0,E=(h==null?void 0:h.totalRuns)??s.runCount??1,w=p>0?Math.round(v/p*100):0;return n.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center gap-5",children:[n.jsxs("div",{className:"relative",children:[n.jsx(pr,{size:28,className:"text-[hsl(var(--muted-foreground))]"}),n.jsx("div",{className:"absolute -top-0.5 -right-0.5 w-2.5 h-2.5 rounded-full bg-emerald-500 animate-ping"}),n.jsx("div",{className:"absolute -top-0.5 -right-0.5 w-2.5 h-2.5 rounded-full bg-emerald-500"})]}),n.jsxs("div",{className:"text-center space-y-1",children:[n.jsx("p",{className:"text-sm font-medium",children:x?`Run ${y+1} of ${E}`:"Running evaluation…"}),s.evalName&&n.jsxs("p",{className:"text-xs text-[hsl(var(--muted-foreground))]",children:[s.evalName,x?` · ${E} runs`:""]})]}),p>0&&n.jsxs("div",{className:"w-56 space-y-1.5",children:[n.jsx("div",{className:"h-1.5 rounded-full bg-[hsl(var(--muted))] overflow-hidden",children:n.jsx("div",{className:"h-full rounded-full bg-emerald-500 transition-all duration-300 ease-out",style:{width:`${w}%`}})}),n.jsxs("p",{className:"text-[11px] text-[hsl(var(--muted-foreground))] text-center tabular-nums",children:[v," / ",p," items"]})]}),n.jsx("p",{className:"text-[11px] text-[hsl(var(--muted-foreground))] tabular-nums",children:m}),n.jsxs("button",{onClick:r,className:`inline-flex items-center gap-1.5 px-3 py-1 text-xs rounded-md
316
316
  border border-[hsl(var(--border))] text-[hsl(var(--muted-foreground))]
317
317
  hover:bg-[hsl(var(--muted))] hover:text-[hsl(var(--foreground))]
318
- transition-colors cursor-pointer`,children:[n.jsx(Rf,{size:12}),"Cancel"]})]})}function A5(){return n.jsx(Sj,{basename:window.__AXL_STUDIO_BASE__||"/",children:n.jsxs("div",{className:"flex h-screen overflow-hidden",children:[n.jsx(a2,{}),n.jsx("div",{className:"flex-1 overflow-hidden",children:n.jsxs(P1,{children:[n.jsx(ln,{path:"/playground",element:n.jsx(xS,{})}),n.jsx(ln,{path:"/workflows",element:n.jsx(jS,{})}),n.jsx(ln,{path:"/traces",element:n.jsx(TS,{})}),n.jsx(ln,{path:"/costs",element:n.jsx(AS,{})}),n.jsx(ln,{path:"/memory",element:n.jsx(_S,{})}),n.jsx(ln,{path:"/sessions",element:n.jsx(DS,{})}),n.jsx(ln,{path:"/tools",element:n.jsx(zS,{})}),n.jsx(ln,{path:"/evals",element:n.jsx(T5,{})}),n.jsx(ln,{path:"*",element:n.jsx(I1,{to:"/playground",replace:!0})})]})})]})})}Nf(jf(yf()));e1();hy.createRoot(document.getElementById("root")).render(n.jsx(b.StrictMode,{children:n.jsx(Hy,{client:Jy,children:n.jsx(A5,{})})}));
318
+ transition-colors cursor-pointer`,children:[n.jsx(Rf,{size:12}),"Cancel"]})]})}function O5(){return n.jsx(Sj,{basename:window.__AXL_STUDIO_BASE__||"/",children:n.jsxs("div",{className:"flex h-screen overflow-hidden",children:[n.jsx(a2,{}),n.jsx("div",{className:"flex-1 overflow-hidden",children:n.jsxs(P1,{children:[n.jsx(ln,{path:"/playground",element:n.jsx(gS,{})}),n.jsx(ln,{path:"/workflows",element:n.jsx(NS,{})}),n.jsx(ln,{path:"/traces",element:n.jsx(MS,{})}),n.jsx(ln,{path:"/costs",element:n.jsx(_S,{})}),n.jsx(ln,{path:"/memory",element:n.jsx(OS,{})}),n.jsx(ln,{path:"/sessions",element:n.jsx(US,{})}),n.jsx(ln,{path:"/tools",element:n.jsx(LS,{})}),n.jsx(ln,{path:"/evals",element:n.jsx(A5,{})}),n.jsx(ln,{path:"*",element:n.jsx(I1,{to:"/playground",replace:!0})})]})})]})})}Nf(jf(yf()));e1();hy.createRoot(document.getElementById("root")).render(n.jsx(b.StrictMode,{children:n.jsx(Hy,{client:Jy,children:n.jsx(O5,{})})}));