@tonyclaw/agent-inspector 3.0.46 → 3.0.48

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/.output/backend/nitro.json +1 -1
  2. package/.output/cli.js +6791 -6006
  3. package/.output/server/_ssr/index.mjs +1 -1
  4. package/.output/server/_ssr/{router-D18yUq36.mjs → router-Cj10mv-Z.mjs} +334 -5
  5. package/.output/server/index.mjs +1 -1
  6. package/.output/ui/assets/{CompareDrawer-DAUuIJ6G.js → CompareDrawer-uRiXFOCp.js} +1 -1
  7. package/.output/ui/assets/{InspectorPet-BRBVjOWI.js → InspectorPet-j-r6xk0V.js} +1 -1
  8. package/.output/ui/assets/{ProxyViewerContainer-D7Sq0ctc.js → ProxyViewerContainer-DnUrkMJF.js} +23 -23
  9. package/.output/ui/assets/{ReplayDialog-nDLsjOhs.js → ReplayDialog-B2URyHMv.js} +1 -1
  10. package/.output/ui/assets/{RequestAnatomy-zd4BDgL0.js → RequestAnatomy-CK0M0CJO.js} +1 -1
  11. package/.output/ui/assets/{ResponseView-AdIXGcSn.js → ResponseView-CYSVA4lT.js} +1 -1
  12. package/.output/ui/assets/{StreamingChunkSequence-CesTz8He.js → StreamingChunkSequence-CHf54ZUV.js} +1 -1
  13. package/.output/ui/assets/{_sessionId-QnBomgPD.js → _sessionId-BXULpTNP.js} +1 -1
  14. package/.output/ui/assets/{_sessionId-BAfzrhSU.js → _sessionId-E4lbj5-I.js} +1 -1
  15. package/.output/ui/assets/{index-D0rtCN9V.js → index-B4ixI3kG.js} +1 -1
  16. package/.output/ui/assets/{index-BcsdxBAd.js → index-BJ-71WLq.js} +1 -1
  17. package/.output/ui/assets/{index-DHpwr08Z.js → index-CW0ab9r3.js} +2 -2
  18. package/.output/ui/assets/{index-dNuk2dsU.js → index-Ce-lO51c.js} +1 -1
  19. package/.output/ui/assets/{json-viewer-BvFHglMb.js → json-viewer-C6E8aLaV.js} +1 -1
  20. package/.output/ui/assets/{jszip.min-B5Z7gNZB.js → jszip.min-DjWdTBbp.js} +1 -1
  21. package/.output/ui/index.html +1 -1
  22. package/README.md +53 -0
  23. package/package.json +17 -3
  24. package/src/backend/routes/api/-instances.ts +7 -109
  25. package/src/cli/instance.ts +21 -0
  26. package/src/cli/instanceApi.ts +213 -0
  27. package/src/cli/instanceArgs.ts +16 -0
  28. package/src/cli/instanceControl.ts +10 -0
  29. package/src/cli/instanceModel.ts +9 -0
  30. package/src/cli/rustBackendPackage.ts +458 -0
  31. package/src/cli.ts +171 -14
  32. package/src/components/ProxyViewer.tsx +4 -13
  33. package/src/components/proxy-viewer/proxyViewerLogic.ts +9 -0
  34. package/src/lib/backendImplementation.ts +16 -0
  35. package/src/lib/instanceContract.ts +3 -0
  36. package/src/lib/managedInstance.ts +9 -1
  37. package/src/mcp/instanceHandlers.ts +1 -0
  38. package/src/proxy/identityProxy.ts +148 -0
  39. package/src/proxy/sessionArchive.ts +0 -8
  40. package/src/proxy/sqliteLogIndex.ts +0 -40
@@ -1 +1 @@
1
- import{r as l,H as D,j as s,B as y,o as U,n as j,a as ae,F as le,b as L,s as H}from"./index-DHpwr08Z.js";import{c as oe,u as ie,D as de,i as ue,j as ce,k as pe,l as A,T as R,m as N,n as d,o as u,p as me,q as xe,s as fe,t as he,v as ye,w as je,x as be}from"./ProxyViewerContainer-D7Sq0ctc.js";import{ResponseView as O}from"./ResponseView-AdIXGcSn.js";const ge=[["path",{d:"M8 3H7a2 2 0 0 0-2 2v5a2 2 0 0 1-2 2 2 2 0 0 1 2 2v5c0 1.1.9 2 2 2h1",key:"ezmyqa"}],["path",{d:"M16 21h1a2 2 0 0 0 2-2v-5c0-1.1.9-2 2-2a2 2 0 0 1-2-2V5a2 2 0 0 0-2-2h-1",key:"e1hn23"}]],Te=oe("braces",ge);function W(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function ve(e){return e==null?null:new TextEncoder().encode(e).length}function Re(e){try{const t=JSON.parse(e);if(!W(t))return null;const a=t.model;return typeof a=="string"&&a.length>0?a:null}catch{return null}}function Ne(e,t){try{const a=JSON.parse(e);return W(a)?{body:JSON.stringify({...a,model:t},null,2),error:null}:{body:e,error:"Request body must be a JSON object."}}catch{return{body:e,error:"Request body must be valid JSON before changing the replay model."}}}function V(e){return{status:e.status??null,elapsedMs:e.elapsedMs??null,inputTokens:e.inputTokens??null,outputTokens:e.outputTokens??null,responseBytes:ve(e.responseText),streaming:e.streaming===!0}}function g(e,t){return e===null||t===null?null:t-e}function ke(e,t){return[{id:"status",label:"Status",original:e.status,replay:t.status,delta:g(e.status,t.status)},{id:"elapsed",label:"Elapsed",original:e.elapsedMs,replay:t.elapsedMs,delta:g(e.elapsedMs,t.elapsedMs)},{id:"input",label:"Input",original:e.inputTokens,replay:t.inputTokens,delta:g(e.inputTokens,t.inputTokens)},{id:"output",label:"Output",original:e.outputTokens,replay:t.outputTokens,delta:g(e.outputTokens,t.outputTokens)},{id:"bytes",label:"Bytes",original:e.responseBytes,replay:t.responseBytes,delta:g(e.responseBytes,t.responseBytes)},{id:"streaming",label:"Stream",original:e.streaming,replay:t.streaming,delta:null}]}const Se=U({success:L(),error:H().optional(),responseStatus:j().nullable().optional(),responseText:H().nullable().optional(),inputTokens:j().nullable().optional(),outputTokens:j().nullable().optional(),elapsedMs:j().nullable().optional(),streaming:L().optional(),replayLogId:j().optional()}),we=U({logs:ae(be),total:j()}),Me=6e4,Ce=1e4;function k(e){try{const t=JSON.parse(e);return JSON.stringify(t,null,2)}catch{return e}}function Oe(e){try{const t=JSON.parse(e);return JSON.stringify(t)}catch{return e}}function Ee(e){try{return JSON.parse(e),{valid:!0,message:"Valid JSON"}}catch(t){return{valid:!1,message:t instanceof Error?t.message:"Invalid JSON"}}}function E(e){return e<1e3?`${String(e)}ms`:`${(e/1e3).toFixed(1)}s`}function P(e,t){if(e===null)return"-";if(typeof e=="boolean")return e?"stream":"non-stream";switch(t){case"elapsed":return E(e);case"input":case"output":case"bytes":return e.toLocaleString();case"status":return String(e);case"streaming":return e?"stream":"non-stream"}}function Je(e,t){if(e===null)return"-";const a=e>0?"+":"";switch(t){case"elapsed":return`${a}${E(e)}`;case"input":case"output":case"bytes":case"status":return`${a}${e.toLocaleString()}`;case"streaming":return"-"}}function Be(e){return e===null||e===0?"text-muted-foreground":e>0?"text-amber-400":"text-emerald-400"}function Y({comparisons:e}){return s.jsxs("div",{className:"overflow-hidden rounded-md border border-border",children:[s.jsxs("div",{className:"grid grid-cols-[1fr_1fr_1fr_1fr] bg-muted/40 px-3 py-2 text-[11px] font-medium text-muted-foreground",children:[s.jsx("span",{children:"Metric"}),s.jsx("span",{children:"Original"}),s.jsx("span",{children:"Replay"}),s.jsx("span",{children:"Delta"})]}),e.map(t=>s.jsxs("div",{className:"grid grid-cols-[1fr_1fr_1fr_1fr] border-t border-border px-3 py-2 text-xs",children:[s.jsx("span",{className:"text-muted-foreground",children:t.label}),s.jsx("span",{className:"font-mono",children:P(t.original,t.id)}),s.jsx("span",{className:"font-mono",children:P(t.replay,t.id)}),s.jsx("span",{className:`font-mono ${Be(t.delta)}`,children:Je(t.delta,t.id)})]},t.id))]})}function Ie({log:e,displayNumber:t,open:a,onOpenChange:J}){const{providers:B}=ie(),$=e.rawRequestBody??"{}",[c,G]=l.useState(()=>k($)),[r,T]=l.useState(null),[K,Q]=l.useState([]),[q,S]=l.useState(!1),[w,p]=l.useState(null),m=l.useRef(null),x=l.useRef(0),f=l.useMemo(()=>Ee(c),[c]),M=l.useCallback(()=>{x.current+=1,m.current?.abort(),m.current=null,S(!1)},[]),v=l.useCallback(async()=>{if(a)try{const n=await D(`/api/logs?replayOf=${String(e.id)}`,we,Ce);Q(n.logs)}catch{}},[e.id,a]);l.useEffect(()=>{v()},[v]),l.useEffect(()=>{a||M()},[M,a]),l.useEffect(()=>()=>{x.current+=1,m.current?.abort(),m.current=null},[]);async function X(){if(!f.valid){p("Request body must be valid JSON before replay.");return}m.current?.abort();const n=x.current+1;x.current=n;const i=new AbortController;m.current=i,S(!0),p(null),T(null);try{const o=await D(`/api/logs/${e.id}/replay`,Se,Me,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({modifiedBody:c}),signal:i.signal});if(x.current!==n)return;T(o),await v(),o.success||p(o.error??"Replay failed")}catch(o){if(x.current!==n)return;if(o instanceof le||o instanceof DOMException&&o.name==="AbortError"){p("Replay timed out or was canceled.");return}p(o instanceof Error?o.message:"Network error")}finally{x.current===n&&(m.current=null,S(!1))}}function Z(){M(),T(null),p(null),J(!1)}function b(n){G(n),T(null),p(null)}function ee(){b(k(c))}function se(){b(Oe(c))}function te(){b(k($))}function F(n){window.location.hash=`log-${String(n)}`,je({logId:n,tab:"request"}),J(!1)}const C=l.useMemo(()=>{const n=[];for(const i of B)for(const o of i.models)o.trim().length!==0&&n.push({key:`${i.id}:${o}`,providerName:i.name,model:o});return n},[B]),h=Re(c)??e.model??"";function ne(n){const i=Ne(c,n);if(i.error!==null){p(i.error);return}b(k(i.body))}const re=V({status:e.responseStatus,elapsedMs:e.elapsedMs,inputTokens:e.inputTokens,outputTokens:e.outputTokens,responseText:e.responseText,streaming:e.streaming}),I=r===null?null:V({status:r.responseStatus,elapsedMs:r.elapsedMs,inputTokens:r.inputTokens,outputTokens:r.outputTokens,responseText:r.responseText,streaming:r.streaming}),_=I===null?[]:ke(re,I),z=K.slice(-5).reverse();return s.jsx(de,{open:a,onOpenChange:Z,children:s.jsxs(ue,{className:"max-w-4xl max-h-[85vh] overflow-auto",children:[s.jsx(ce,{children:s.jsxs(pe,{className:"flex items-center gap-2",children:[s.jsx(A,{className:"size-4"}),s.jsxs("span",{title:`Log ID ${String(e.id)}`,children:["Replay Request #",t]})]})}),s.jsxs(R,{defaultValue:"modified",children:[s.jsxs(N,{children:[s.jsx(d,{value:"modified",children:"Modified Request"}),s.jsx(d,{value:"original",children:"Original Response"}),r&&s.jsx(d,{value:"replay",children:"Replay Response"}),r&&s.jsx(d,{value:"compare",children:"Compare"})]}),s.jsxs(u,{value:"modified",className:"space-y-4",children:[C.length>0&&s.jsxs("div",{className:"grid gap-1.5",children:[s.jsx("label",{htmlFor:`replay-model-${String(e.id)}`,className:"text-sm font-medium",children:"Replay target"}),s.jsxs("select",{id:`replay-model-${String(e.id)}`,value:h,onChange:n=>ne(n.currentTarget.value),className:"h-8 rounded-md border border-input bg-background px-2 text-sm",children:[h===""&&s.jsx("option",{value:"",children:"Select model"}),h!==""&&!C.some(n=>n.model===h)&&s.jsx("option",{value:h,children:h}),C.map(n=>s.jsxs("option",{value:n.model,children:[n.providerName," / ",n.model]},n.key))]})]}),z.length>0&&s.jsxs("div",{className:"space-y-2 rounded-md border border-border bg-muted/20 px-3 py-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("div",{className:"text-xs font-medium",children:"Replay history"}),s.jsx(y,{type:"button",variant:"ghost",size:"sm",onClick:()=>{v()},children:"Refresh"})]}),s.jsx("div",{className:"grid gap-1",children:z.map(n=>s.jsxs("button",{type:"button",onClick:()=>F(n.id),className:"grid grid-cols-[auto_1fr_auto_auto] items-center gap-2 rounded-sm px-2 py-1 text-left text-xs hover:bg-muted",children:[s.jsxs("span",{className:"font-mono text-emerald-600",children:["#",n.id]}),s.jsx("span",{className:"truncate font-mono text-muted-foreground",children:n.model??"unknown"}),s.jsx("span",{className:"font-mono text-muted-foreground",children:n.responseStatus??"-"}),s.jsx("span",{className:"font-mono text-muted-foreground",children:n.elapsedMs===null?"-":E(n.elapsedMs)})]},n.id))})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[s.jsx("label",{htmlFor:`replay-body-${String(e.id)}`,className:"text-sm font-medium",children:"Request Body"}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:f.valid?"text-xs text-emerald-500":"text-xs text-destructive",children:f.message}),s.jsxs(y,{type:"button",variant:"outline",size:"sm",onClick:ee,disabled:!f.valid,title:"Format JSON",children:[s.jsx(Te,{className:"size-3.5"}),"Format"]}),s.jsxs(y,{type:"button",variant:"outline",size:"sm",onClick:se,disabled:!f.valid,title:"Compact JSON",children:[s.jsx(me,{className:"size-3.5"}),"Compact"]}),s.jsxs(y,{type:"button",variant:"ghost",size:"sm",onClick:te,title:"Reset to original request",children:[s.jsx(A,{className:"size-3.5"}),"Reset"]})]})]}),s.jsx(xe,{children:s.jsxs(fe,{children:[s.jsx(he,{asChild:!0,children:s.jsx("textarea",{id:`replay-body-${String(e.id)}`,className:"w-full min-h-80 p-3 font-mono text-xs leading-5 bg-muted rounded-md border border-input resize-y tabular-nums focus:outline-none focus:ring-2 focus:ring-ring",value:c,onChange:n=>b(n.target.value),spellCheck:!1})}),s.jsx(ye,{children:"Edit formatted JSON before re-sending to the provider"})]})})]}),w!==null&&w!==""&&s.jsx("div",{className:"text-sm text-destructive bg-destructive/10 px-3 py-2 rounded-md",children:w}),s.jsx("div",{className:"flex justify-end",children:s.jsx(y,{onClick:()=>{X()},disabled:q||!f.valid,children:q?"Replaying...":"Replay"})}),r!==null&&s.jsx(Y,{comparisons:_.slice(0,4)}),r?.success===!0&&r.replayLogId!==void 0&&s.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 rounded-md border border-emerald-500/25 bg-emerald-500/10 px-3 py-2 text-xs text-emerald-600",children:[s.jsxs("span",{children:["Replay saved as test log #",r.replayLogId,"."]}),s.jsx(y,{type:"button",variant:"outline",size:"sm",onClick:()=>F(r.replayLogId??e.id),children:"Open saved log"})]}),r&&r.success&&s.jsxs(R,{defaultValue:"parsed",children:[s.jsxs(N,{children:[s.jsx(d,{value:"parsed",children:"Response"}),s.jsx(d,{value:"raw",children:"Raw Response"})]}),s.jsx(u,{value:"parsed",children:s.jsx(O,{responseText:r.responseText??null,responseStatus:r.responseStatus??null,streaming:r.streaming??!1,inputTokens:r.inputTokens??null,outputTokens:r.outputTokens??null,apiFormat:e.apiFormat})}),s.jsx(u,{value:"raw",children:s.jsx("pre",{className:"font-mono text-xs whitespace-pre-wrap bg-muted p-3 rounded-md max-h-96 overflow-auto",children:r.responseText??"No response"})})]})]}),s.jsx(u,{value:"original",children:e.responseText!==null?s.jsxs(R,{defaultValue:"parsed",children:[s.jsxs(N,{children:[s.jsx(d,{value:"parsed",children:"Response"}),s.jsx(d,{value:"raw",children:"Raw Response"})]}),s.jsx(u,{value:"parsed",children:s.jsx(O,{responseText:e.responseText,responseStatus:e.responseStatus,streaming:e.streaming,inputTokens:e.inputTokens,outputTokens:e.outputTokens,cacheCreationInputTokens:e.cacheCreationInputTokens,cacheReadInputTokens:e.cacheReadInputTokens,apiFormat:e.apiFormat})}),s.jsx(u,{value:"raw",children:s.jsx("pre",{className:"font-mono text-xs whitespace-pre-wrap bg-muted p-3 rounded-md max-h-96 overflow-auto",children:e.responseText})})]}):s.jsx("p",{className:"text-sm text-muted-foreground italic",children:"No original response"})}),r&&r.success&&s.jsx(u,{value:"replay",children:(r.responseText??null)!==null?s.jsxs(R,{defaultValue:"parsed",children:[s.jsxs(N,{children:[s.jsx(d,{value:"parsed",children:"Response"}),s.jsx(d,{value:"raw",children:"Raw Response"})]}),s.jsx(u,{value:"parsed",children:s.jsx(O,{responseText:r.responseText??null,responseStatus:r.responseStatus??null,streaming:r.streaming??!1,inputTokens:r.inputTokens??null,outputTokens:r.outputTokens??null,apiFormat:e.apiFormat})}),s.jsx(u,{value:"raw",children:s.jsx("pre",{className:"font-mono text-xs whitespace-pre-wrap bg-muted p-3 rounded-md max-h-96 overflow-auto",children:r.responseText??""})})]}):s.jsx("p",{className:"text-sm text-muted-foreground italic",children:"No replay response"})}),r&&s.jsxs(u,{value:"compare",className:"space-y-3",children:[s.jsx(Y,{comparisons:_}),r.success?null:s.jsx("div",{className:"rounded-md border border-destructive/30 bg-destructive/10 px-3 py-2 text-xs text-destructive",children:r.error??"Replay failed"})]})]})]})})}export{Ie as ReplayDialog};
1
+ import{r as l,H as D,j as s,B as y,o as U,n as j,a as ae,F as le,b as L,s as H}from"./index-CW0ab9r3.js";import{c as oe,u as ie,D as de,i as ue,j as ce,k as pe,l as A,T as R,m as N,n as d,o as u,p as me,q as xe,s as fe,t as he,v as ye,w as je,x as be}from"./ProxyViewerContainer-DnUrkMJF.js";import{ResponseView as O}from"./ResponseView-CYSVA4lT.js";const ge=[["path",{d:"M8 3H7a2 2 0 0 0-2 2v5a2 2 0 0 1-2 2 2 2 0 0 1 2 2v5c0 1.1.9 2 2 2h1",key:"ezmyqa"}],["path",{d:"M16 21h1a2 2 0 0 0 2-2v-5c0-1.1.9-2 2-2a2 2 0 0 1-2-2V5a2 2 0 0 0-2-2h-1",key:"e1hn23"}]],Te=oe("braces",ge);function W(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function ve(e){return e==null?null:new TextEncoder().encode(e).length}function Re(e){try{const t=JSON.parse(e);if(!W(t))return null;const a=t.model;return typeof a=="string"&&a.length>0?a:null}catch{return null}}function Ne(e,t){try{const a=JSON.parse(e);return W(a)?{body:JSON.stringify({...a,model:t},null,2),error:null}:{body:e,error:"Request body must be a JSON object."}}catch{return{body:e,error:"Request body must be valid JSON before changing the replay model."}}}function V(e){return{status:e.status??null,elapsedMs:e.elapsedMs??null,inputTokens:e.inputTokens??null,outputTokens:e.outputTokens??null,responseBytes:ve(e.responseText),streaming:e.streaming===!0}}function g(e,t){return e===null||t===null?null:t-e}function ke(e,t){return[{id:"status",label:"Status",original:e.status,replay:t.status,delta:g(e.status,t.status)},{id:"elapsed",label:"Elapsed",original:e.elapsedMs,replay:t.elapsedMs,delta:g(e.elapsedMs,t.elapsedMs)},{id:"input",label:"Input",original:e.inputTokens,replay:t.inputTokens,delta:g(e.inputTokens,t.inputTokens)},{id:"output",label:"Output",original:e.outputTokens,replay:t.outputTokens,delta:g(e.outputTokens,t.outputTokens)},{id:"bytes",label:"Bytes",original:e.responseBytes,replay:t.responseBytes,delta:g(e.responseBytes,t.responseBytes)},{id:"streaming",label:"Stream",original:e.streaming,replay:t.streaming,delta:null}]}const Se=U({success:L(),error:H().optional(),responseStatus:j().nullable().optional(),responseText:H().nullable().optional(),inputTokens:j().nullable().optional(),outputTokens:j().nullable().optional(),elapsedMs:j().nullable().optional(),streaming:L().optional(),replayLogId:j().optional()}),we=U({logs:ae(be),total:j()}),Me=6e4,Ce=1e4;function k(e){try{const t=JSON.parse(e);return JSON.stringify(t,null,2)}catch{return e}}function Oe(e){try{const t=JSON.parse(e);return JSON.stringify(t)}catch{return e}}function Ee(e){try{return JSON.parse(e),{valid:!0,message:"Valid JSON"}}catch(t){return{valid:!1,message:t instanceof Error?t.message:"Invalid JSON"}}}function E(e){return e<1e3?`${String(e)}ms`:`${(e/1e3).toFixed(1)}s`}function P(e,t){if(e===null)return"-";if(typeof e=="boolean")return e?"stream":"non-stream";switch(t){case"elapsed":return E(e);case"input":case"output":case"bytes":return e.toLocaleString();case"status":return String(e);case"streaming":return e?"stream":"non-stream"}}function Je(e,t){if(e===null)return"-";const a=e>0?"+":"";switch(t){case"elapsed":return`${a}${E(e)}`;case"input":case"output":case"bytes":case"status":return`${a}${e.toLocaleString()}`;case"streaming":return"-"}}function Be(e){return e===null||e===0?"text-muted-foreground":e>0?"text-amber-400":"text-emerald-400"}function Y({comparisons:e}){return s.jsxs("div",{className:"overflow-hidden rounded-md border border-border",children:[s.jsxs("div",{className:"grid grid-cols-[1fr_1fr_1fr_1fr] bg-muted/40 px-3 py-2 text-[11px] font-medium text-muted-foreground",children:[s.jsx("span",{children:"Metric"}),s.jsx("span",{children:"Original"}),s.jsx("span",{children:"Replay"}),s.jsx("span",{children:"Delta"})]}),e.map(t=>s.jsxs("div",{className:"grid grid-cols-[1fr_1fr_1fr_1fr] border-t border-border px-3 py-2 text-xs",children:[s.jsx("span",{className:"text-muted-foreground",children:t.label}),s.jsx("span",{className:"font-mono",children:P(t.original,t.id)}),s.jsx("span",{className:"font-mono",children:P(t.replay,t.id)}),s.jsx("span",{className:`font-mono ${Be(t.delta)}`,children:Je(t.delta,t.id)})]},t.id))]})}function Ie({log:e,displayNumber:t,open:a,onOpenChange:J}){const{providers:B}=ie(),$=e.rawRequestBody??"{}",[c,G]=l.useState(()=>k($)),[r,T]=l.useState(null),[K,Q]=l.useState([]),[q,S]=l.useState(!1),[w,p]=l.useState(null),m=l.useRef(null),x=l.useRef(0),f=l.useMemo(()=>Ee(c),[c]),M=l.useCallback(()=>{x.current+=1,m.current?.abort(),m.current=null,S(!1)},[]),v=l.useCallback(async()=>{if(a)try{const n=await D(`/api/logs?replayOf=${String(e.id)}`,we,Ce);Q(n.logs)}catch{}},[e.id,a]);l.useEffect(()=>{v()},[v]),l.useEffect(()=>{a||M()},[M,a]),l.useEffect(()=>()=>{x.current+=1,m.current?.abort(),m.current=null},[]);async function X(){if(!f.valid){p("Request body must be valid JSON before replay.");return}m.current?.abort();const n=x.current+1;x.current=n;const i=new AbortController;m.current=i,S(!0),p(null),T(null);try{const o=await D(`/api/logs/${e.id}/replay`,Se,Me,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({modifiedBody:c}),signal:i.signal});if(x.current!==n)return;T(o),await v(),o.success||p(o.error??"Replay failed")}catch(o){if(x.current!==n)return;if(o instanceof le||o instanceof DOMException&&o.name==="AbortError"){p("Replay timed out or was canceled.");return}p(o instanceof Error?o.message:"Network error")}finally{x.current===n&&(m.current=null,S(!1))}}function Z(){M(),T(null),p(null),J(!1)}function b(n){G(n),T(null),p(null)}function ee(){b(k(c))}function se(){b(Oe(c))}function te(){b(k($))}function F(n){window.location.hash=`log-${String(n)}`,je({logId:n,tab:"request"}),J(!1)}const C=l.useMemo(()=>{const n=[];for(const i of B)for(const o of i.models)o.trim().length!==0&&n.push({key:`${i.id}:${o}`,providerName:i.name,model:o});return n},[B]),h=Re(c)??e.model??"";function ne(n){const i=Ne(c,n);if(i.error!==null){p(i.error);return}b(k(i.body))}const re=V({status:e.responseStatus,elapsedMs:e.elapsedMs,inputTokens:e.inputTokens,outputTokens:e.outputTokens,responseText:e.responseText,streaming:e.streaming}),I=r===null?null:V({status:r.responseStatus,elapsedMs:r.elapsedMs,inputTokens:r.inputTokens,outputTokens:r.outputTokens,responseText:r.responseText,streaming:r.streaming}),_=I===null?[]:ke(re,I),z=K.slice(-5).reverse();return s.jsx(de,{open:a,onOpenChange:Z,children:s.jsxs(ue,{className:"max-w-4xl max-h-[85vh] overflow-auto",children:[s.jsx(ce,{children:s.jsxs(pe,{className:"flex items-center gap-2",children:[s.jsx(A,{className:"size-4"}),s.jsxs("span",{title:`Log ID ${String(e.id)}`,children:["Replay Request #",t]})]})}),s.jsxs(R,{defaultValue:"modified",children:[s.jsxs(N,{children:[s.jsx(d,{value:"modified",children:"Modified Request"}),s.jsx(d,{value:"original",children:"Original Response"}),r&&s.jsx(d,{value:"replay",children:"Replay Response"}),r&&s.jsx(d,{value:"compare",children:"Compare"})]}),s.jsxs(u,{value:"modified",className:"space-y-4",children:[C.length>0&&s.jsxs("div",{className:"grid gap-1.5",children:[s.jsx("label",{htmlFor:`replay-model-${String(e.id)}`,className:"text-sm font-medium",children:"Replay target"}),s.jsxs("select",{id:`replay-model-${String(e.id)}`,value:h,onChange:n=>ne(n.currentTarget.value),className:"h-8 rounded-md border border-input bg-background px-2 text-sm",children:[h===""&&s.jsx("option",{value:"",children:"Select model"}),h!==""&&!C.some(n=>n.model===h)&&s.jsx("option",{value:h,children:h}),C.map(n=>s.jsxs("option",{value:n.model,children:[n.providerName," / ",n.model]},n.key))]})]}),z.length>0&&s.jsxs("div",{className:"space-y-2 rounded-md border border-border bg-muted/20 px-3 py-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("div",{className:"text-xs font-medium",children:"Replay history"}),s.jsx(y,{type:"button",variant:"ghost",size:"sm",onClick:()=>{v()},children:"Refresh"})]}),s.jsx("div",{className:"grid gap-1",children:z.map(n=>s.jsxs("button",{type:"button",onClick:()=>F(n.id),className:"grid grid-cols-[auto_1fr_auto_auto] items-center gap-2 rounded-sm px-2 py-1 text-left text-xs hover:bg-muted",children:[s.jsxs("span",{className:"font-mono text-emerald-600",children:["#",n.id]}),s.jsx("span",{className:"truncate font-mono text-muted-foreground",children:n.model??"unknown"}),s.jsx("span",{className:"font-mono text-muted-foreground",children:n.responseStatus??"-"}),s.jsx("span",{className:"font-mono text-muted-foreground",children:n.elapsedMs===null?"-":E(n.elapsedMs)})]},n.id))})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[s.jsx("label",{htmlFor:`replay-body-${String(e.id)}`,className:"text-sm font-medium",children:"Request Body"}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:f.valid?"text-xs text-emerald-500":"text-xs text-destructive",children:f.message}),s.jsxs(y,{type:"button",variant:"outline",size:"sm",onClick:ee,disabled:!f.valid,title:"Format JSON",children:[s.jsx(Te,{className:"size-3.5"}),"Format"]}),s.jsxs(y,{type:"button",variant:"outline",size:"sm",onClick:se,disabled:!f.valid,title:"Compact JSON",children:[s.jsx(me,{className:"size-3.5"}),"Compact"]}),s.jsxs(y,{type:"button",variant:"ghost",size:"sm",onClick:te,title:"Reset to original request",children:[s.jsx(A,{className:"size-3.5"}),"Reset"]})]})]}),s.jsx(xe,{children:s.jsxs(fe,{children:[s.jsx(he,{asChild:!0,children:s.jsx("textarea",{id:`replay-body-${String(e.id)}`,className:"w-full min-h-80 p-3 font-mono text-xs leading-5 bg-muted rounded-md border border-input resize-y tabular-nums focus:outline-none focus:ring-2 focus:ring-ring",value:c,onChange:n=>b(n.target.value),spellCheck:!1})}),s.jsx(ye,{children:"Edit formatted JSON before re-sending to the provider"})]})})]}),w!==null&&w!==""&&s.jsx("div",{className:"text-sm text-destructive bg-destructive/10 px-3 py-2 rounded-md",children:w}),s.jsx("div",{className:"flex justify-end",children:s.jsx(y,{onClick:()=>{X()},disabled:q||!f.valid,children:q?"Replaying...":"Replay"})}),r!==null&&s.jsx(Y,{comparisons:_.slice(0,4)}),r?.success===!0&&r.replayLogId!==void 0&&s.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 rounded-md border border-emerald-500/25 bg-emerald-500/10 px-3 py-2 text-xs text-emerald-600",children:[s.jsxs("span",{children:["Replay saved as test log #",r.replayLogId,"."]}),s.jsx(y,{type:"button",variant:"outline",size:"sm",onClick:()=>F(r.replayLogId??e.id),children:"Open saved log"})]}),r&&r.success&&s.jsxs(R,{defaultValue:"parsed",children:[s.jsxs(N,{children:[s.jsx(d,{value:"parsed",children:"Response"}),s.jsx(d,{value:"raw",children:"Raw Response"})]}),s.jsx(u,{value:"parsed",children:s.jsx(O,{responseText:r.responseText??null,responseStatus:r.responseStatus??null,streaming:r.streaming??!1,inputTokens:r.inputTokens??null,outputTokens:r.outputTokens??null,apiFormat:e.apiFormat})}),s.jsx(u,{value:"raw",children:s.jsx("pre",{className:"font-mono text-xs whitespace-pre-wrap bg-muted p-3 rounded-md max-h-96 overflow-auto",children:r.responseText??"No response"})})]})]}),s.jsx(u,{value:"original",children:e.responseText!==null?s.jsxs(R,{defaultValue:"parsed",children:[s.jsxs(N,{children:[s.jsx(d,{value:"parsed",children:"Response"}),s.jsx(d,{value:"raw",children:"Raw Response"})]}),s.jsx(u,{value:"parsed",children:s.jsx(O,{responseText:e.responseText,responseStatus:e.responseStatus,streaming:e.streaming,inputTokens:e.inputTokens,outputTokens:e.outputTokens,cacheCreationInputTokens:e.cacheCreationInputTokens,cacheReadInputTokens:e.cacheReadInputTokens,apiFormat:e.apiFormat})}),s.jsx(u,{value:"raw",children:s.jsx("pre",{className:"font-mono text-xs whitespace-pre-wrap bg-muted p-3 rounded-md max-h-96 overflow-auto",children:e.responseText})})]}):s.jsx("p",{className:"text-sm text-muted-foreground italic",children:"No original response"})}),r&&r.success&&s.jsx(u,{value:"replay",children:(r.responseText??null)!==null?s.jsxs(R,{defaultValue:"parsed",children:[s.jsxs(N,{children:[s.jsx(d,{value:"parsed",children:"Response"}),s.jsx(d,{value:"raw",children:"Raw Response"})]}),s.jsx(u,{value:"parsed",children:s.jsx(O,{responseText:r.responseText??null,responseStatus:r.responseStatus??null,streaming:r.streaming??!1,inputTokens:r.inputTokens??null,outputTokens:r.outputTokens??null,apiFormat:e.apiFormat})}),s.jsx(u,{value:"raw",children:s.jsx("pre",{className:"font-mono text-xs whitespace-pre-wrap bg-muted p-3 rounded-md max-h-96 overflow-auto",children:r.responseText??""})})]}):s.jsx("p",{className:"text-sm text-muted-foreground italic",children:"No replay response"})}),r&&s.jsxs(u,{value:"compare",className:"space-y-3",children:[s.jsx(Y,{comparisons:_}),r.success?null:s.jsx("div",{className:"rounded-md border border-destructive/30 bg-destructive/10 px-3 py-2 text-xs text-destructive",children:r.error??"Replay failed"})]})]})]})})}export{Ie as ReplayDialog};
@@ -1 +1 @@
1
- import{r as f,C as u,j as t,x as p,I as B}from"./index-DHpwr08Z.js";import{u as F,y as q,q as V,s as J,t as Y,I as K,v as X,S as Q,z as $,A as Z,E as C,F as ee,e as z}from"./ProxyViewerContainer-D7Sq0ctc.js";const te=.25,se=5,re=4,ne=6,oe=.25,ae=.2,ie=.2,le=["system","user","assistant","tool","tools"],de={system:"instructions",user:"user turns",assistant:"assistant turns",tool:"tool results",tools:"tool schemas"},ue=[{value:"role",label:"By Role"},{value:"segment",label:"By Segment"}],ce={unknown:"bg-muted-foreground/50",ok:"bg-emerald-500/70",watch:"bg-amber-400/75",danger:"bg-red-500/80"},me={unknown:"text-muted-foreground",ok:"text-emerald-400",watch:"text-amber-300",danger:"text-red-300"},xe={ok:"border-emerald-400/30 bg-emerald-400/8 text-emerald-200",optimizable:"border-amber-400/30 bg-amber-400/8 text-amber-100",risk:"border-red-400/35 bg-red-500/10 text-red-100"},pe={ok:"OK",optimizable:"Optimizable",risk:"Risk"};function h(e){return e>=10?`${e.toFixed(0)}%`:e>=1?`${e.toFixed(1)}%`:e>0?"<1%":"0%"}function w(e){return e===null?"Unknown":h(e*100)}function L(e){return e===null?"Unknown":e<0?`-${u(Math.abs(e))}`:u(e)}function A(e){return e.contextWindow.tokens===null?"Unknown":B(e.contextWindow.tokens)}function fe(e){switch(e.contextWindow.source){case"request":return e.contextWindow.label;case"provider":return e.contextWindow.label;case"model-rule":return e.contextWindow.label;case"unknown":return e.model===null?e.contextWindow.label:`${e.contextWindow.label}: ${e.model}`}}function he(e){switch(e){case"watch":return"border-amber-400/30 bg-amber-400/8 text-amber-100";case"danger":return"border-red-400/35 bg-red-500/10 text-red-100"}}function _(e){const s=pe[e.level];if(e.level==="ok")return s;const r=e.level==="risk"?`${String(e.opportunityCount)} signal${e.opportunityCount===1?"":"s"}`:`${String(e.opportunityCount)} opportunit${e.opportunityCount===1?"y":"ies"}`;return e.reclaimableTokens<=0?`${s} | ${r}`:`${s} | ${r} | ~${u(e.reclaimableTokens)} tokens`}function ge({health:e}){return t.jsx("span",{className:p("inline-flex h-5 max-w-full items-center rounded border px-1.5 font-mono text-[10px]",xe[e.level]),"aria-label":`Context health ${_(e)}`,children:t.jsx("span",{className:"truncate",children:_(e)})})}function y(e,s){return e.roleUsages.find(r=>r.role===s)?.tokens??0}function O(e,s){return e.roleUsages.find(r=>r.role===s)?.percent??0}function S(e,s){if(e<=0)return null;const r=Math.round(e*s);return r>0?r:null}function I(e,s){return[...e].filter(r=>r.role===s).sort((r,n)=>n.size-r.size)[0]??null}function be(e){return[...e].filter(s=>s.role==="user"||s.role==="assistant"||s.role==="tool").sort((s,r)=>r.size-s.size)[0]??null}function ve(e,s){const r=e[0]??null;if(r===null)return null;const n=r.segments[0]??null;return n===null?null:P(n,s)}function je(e){const s=e.reduce((r,n)=>r+n.repeatedTokens,0);return s>0?s:null}function Ne(e){return y(e,"user")+y(e,"assistant")+y(e,"tool")}function ke({diagnostic:e,intelligence:s,segments:r}){switch(e.kind){case"duplicate":return{key:"duplicate",kind:"duplicate",severity:e.severity,title:"Duplicate content",impact:e.detail,action:"Remove repeated blocks or keep one canonical copy in the next request.",savingTokens:je(s.duplicateGroups),target:ve(s.duplicateGroups,r)};case"tool-schema":{const n=y(s,"tools"),l=O(s,"tools");return{key:"tool-schema",kind:"tool-schema",severity:e.severity,title:"Tool schema pressure",impact:`Tool definitions use ~${u(n)} tokens (${h(l*100)}).`,action:"Disable unused tools or shorten verbose schema descriptions.",savingTokens:S(n,oe),target:I(r,"tools")}}case"system-heavy":{const n=y(s,"system"),l=O(s,"system");return{key:"system-heavy",kind:"system-heavy",severity:e.severity,title:"Large system prompt",impact:`System instructions use ~${u(n)} tokens (${h(l*100)}).`,action:"Compress repeated policy text and move stable guidance into reusable memory.",savingTokens:S(n,ae),target:I(r,"system")}}case"history-bloat":{const n=Ne(s);return{key:"history-bloat",kind:"history-bloat",severity:e.severity,title:"Conversation history growth",impact:e.detail,action:"Summarize older turns and trim resolved tool outputs before continuing.",savingTokens:S(n,ie),target:be(r)}}}}function we({intelligence:e,segments:s}){const r=[];return(e.riskLevel==="watch"||e.riskLevel==="danger")&&r.push({key:"context-pressure",kind:"context-pressure",severity:e.riskLevel==="danger"?"danger":"watch",title:"Context window pressure",impact:`${w(e.usagePercent)} used, ${L(e.remainingAfterReserveTokens)} remaining after output reserve.`,action:"Start with the largest context block, then remove duplicates or summarize history.",savingTokens:null,target:[...s].sort((n,l)=>l.size-n.size)[0]??null}),e.contextWindow.source==="unknown"&&r.push({key:"context-window",kind:"context-window",severity:"watch",title:"Context window unknown",impact:"Agent Inspector cannot calculate remaining space for this model.",action:"Add model metadata in Provider settings so risk and remaining space are accurate.",savingTokens:null,target:null}),e.diagnostics.forEach(n=>{r.push(ke({diagnostic:n,intelligence:e,segments:s}))}),r}function ye({items:e,onSegmentActivate:s}){return e.length===0?null:t.jsxs("section",{className:"space-y-2 rounded border border-border/70 bg-muted/15 p-2",children:[t.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[t.jsx("div",{className:"text-xs font-medium text-foreground",children:"Context Advisor"}),t.jsxs("div",{className:"font-mono text-[11px] text-muted-foreground",children:[String(e.length)," issue",e.length===1?"":"s"]})]}),t.jsx("div",{className:"grid gap-2",children:e.map(r=>{const n=r.target,l=n!==null&&s!==void 0;return t.jsx("div",{className:p("rounded border px-2 py-1.5 text-xs",he(r.severity)),children:t.jsxs("div",{className:"flex min-w-0 flex-wrap items-start justify-between gap-2",children:[t.jsxs("div",{className:"min-w-0",children:[t.jsx("div",{className:"font-medium",children:r.title}),t.jsxs("div",{className:"mt-0.5 text-[11px] text-muted-foreground",children:["Impact: ",r.impact]}),t.jsxs("div",{className:"mt-0.5 text-[11px] text-muted-foreground",children:["Action: ",r.action]})]}),t.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[r.savingTokens!==null&&t.jsxs("span",{className:"font-mono text-[11px] text-muted-foreground",children:["Save ~",u(r.savingTokens)]}),l&&n!==null&&s!==void 0&&t.jsxs("button",{type:"button",onClick:()=>s(n),className:"inline-flex h-6 items-center gap-1 rounded border border-border/60 px-1.5 text-[11px] text-muted-foreground hover:border-border hover:bg-muted/40 hover:text-foreground",title:"Jump to the most relevant context block",children:[t.jsx(z,{className:"size-3"}),"Jump"]})]})]})},r.key)})})]})}function Te({intelligence:e,segments:s,onSegmentActivate:r}){const n=e.usagePercent===null?0:Math.max(1,e.usagePercent*100),l=e.outputReserveTokens===null?"No output reserve":`Output reserve ${u(e.outputReserveTokens)}`,c=e.largestRole,m=we({intelligence:e,segments:s});return t.jsxs("div",{className:"space-y-2",children:[t.jsxs("div",{className:"grid gap-x-4 gap-y-2 border-y border-border/60 py-2 text-xs sm:grid-cols-4",children:[t.jsxs("div",{className:"min-w-0",children:[t.jsx("div",{className:"text-[10px] font-medium uppercase text-muted-foreground",children:"Window"}),t.jsx("div",{className:"mt-0.5 truncate font-mono text-foreground",children:A(e)}),t.jsx("div",{className:"truncate text-[11px] text-muted-foreground",children:fe(e)})]}),t.jsxs("div",{className:"min-w-0",children:[t.jsx("div",{className:"text-[10px] font-medium uppercase text-muted-foreground",children:"Used"}),t.jsx("div",{className:p("mt-0.5 font-mono",me[e.riskLevel]),children:w(e.usagePercent)}),t.jsx("div",{className:"truncate text-[11px] text-muted-foreground",children:l})]}),t.jsxs("div",{className:"min-w-0",children:[t.jsx("div",{className:"text-[10px] font-medium uppercase text-muted-foreground",children:"Remaining"}),t.jsx("div",{className:"mt-0.5 font-mono text-foreground",children:L(e.remainingAfterReserveTokens)}),t.jsxs("div",{className:"truncate text-[11px] text-muted-foreground",children:["Input only ",L(e.remainingInputTokens)]})]}),t.jsxs("div",{className:"min-w-0",children:[t.jsx("div",{className:"text-[10px] font-medium uppercase text-muted-foreground",children:"Largest"}),c===null?t.jsx("div",{className:"mt-0.5 text-muted-foreground",children:"Unknown"}):t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"mt-0.5 flex min-w-0 items-center gap-1.5",children:[t.jsx("span",{"aria-hidden":"true",className:p("size-2.5 shrink-0 rounded-[2px]",$[c.role])}),t.jsx("span",{className:"truncate text-foreground",children:c.label})]}),t.jsxs("div",{className:"truncate font-mono text-[11px] text-muted-foreground",children:[h(c.percent*100)," | ~",u(c.tokens)]})]})]})]}),e.contextWindow.tokens!==null&&t.jsxs("div",{className:"space-y-1.5",children:[t.jsxs("div",{className:"relative h-2 overflow-hidden rounded-full bg-muted/40",children:[t.jsx("div",{className:p("h-full rounded-full",ce[e.riskLevel]),style:{width:`${String(n)}%`}}),t.jsx("div",{"aria-hidden":"true",className:"absolute top-0 h-full w-px bg-amber-200/70",style:{left:`${String(C.watch*100)}%`}}),t.jsx("div",{"aria-hidden":"true",className:"absolute top-0 h-full w-px bg-red-200/80",style:{left:`${String(C.danger*100)}%`}})]}),t.jsxs("div",{className:"flex justify-between text-[10px] text-muted-foreground",children:[t.jsx("span",{children:"Context window"}),t.jsxs("span",{children:["Watch ",w(C.watch)," / Danger"," ",w(C.danger)]})]})]}),t.jsx(ye,{items:m,onSegmentActivate:r})]})}function P(e,s){return s.find(r=>r.path===e.path)??null}function Ce({groups:e,segments:s,onSegmentActivate:r}){const[n,l]=f.useState(!1);if(e.length===0)return null;const c=e.slice(0,re),m=e.length-c.length,g=e.reduce((o,i)=>o+i.repeatedTokens,0);return t.jsxs("section",{className:"space-y-2 rounded border border-border/70 bg-muted/15 p-2",children:[t.jsxs("button",{type:"button",onClick:()=>l(o=>!o),"aria-expanded":n,className:"flex w-full flex-wrap items-center justify-between gap-2 rounded px-1 py-0.5 text-left transition-colors hover:bg-muted/30 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1",children:[t.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5",children:[n?t.jsx(ee,{className:"size-3.5 shrink-0 text-muted-foreground"}):t.jsx(z,{className:"size-3.5 shrink-0 text-muted-foreground"}),t.jsx("span",{className:"truncate text-xs font-medium text-foreground",children:"Duplicate Content"})]}),t.jsxs("span",{className:"font-mono text-[11px] text-muted-foreground",children:[String(e.length)," group",e.length===1?"":"s"," | ~",u(g)," repeated"]})]}),n&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"space-y-2",children:c.map((o,i)=>{const b=o.segments.slice(0,ne),T=o.segments.length-b.length;return t.jsxs("div",{className:"space-y-1.5 border-t border-border/50 pt-2 first:border-t-0 first:pt-0",children:[t.jsxs("div",{className:"flex min-w-0 items-center gap-2 text-xs",children:[t.jsx("span",{className:"w-5 shrink-0 text-right font-mono text-muted-foreground/70",children:String(i+1)}),t.jsx("span",{className:"min-w-0 flex-1 truncate text-foreground",children:o.firstLabel}),t.jsxs("span",{className:"shrink-0 font-mono text-muted-foreground",children:["x",String(o.count)," | ~",u(o.repeatedTokens)," saved"]})]}),o.preview.length>0&&t.jsx("div",{className:"ml-7 line-clamp-2 break-words rounded bg-background/40 px-2 py-1 font-mono text-[11px] leading-4 text-muted-foreground",children:o.preview}),t.jsxs("div",{className:"ml-7 flex flex-wrap gap-1",children:[b.map((d,v)=>{const j=P(d,s),N=j===null||r===void 0?void 0:r,k=`${d.label} ~${u(d.tokens)}`;return N===void 0||j===null?t.jsx("span",{className:"inline-flex h-6 max-w-40 items-center rounded border border-border/60 px-1.5 text-[11px] text-muted-foreground",title:k,children:t.jsx("span",{className:"truncate",children:k})},`${d.path}-${v}`):t.jsx("button",{type:"button",onClick:()=>N(j),className:"inline-flex h-6 max-w-40 items-center rounded border border-border/60 px-1.5 text-[11px] text-muted-foreground hover:border-border hover:bg-muted/40 hover:text-foreground",title:"Jump to this duplicate block",children:t.jsx("span",{className:"truncate",children:k})},`${d.path}-${v}`)}),T>0&&t.jsxs("span",{className:"inline-flex h-6 items-center rounded border border-border/40 px-1.5 font-mono text-[11px] text-muted-foreground/70",children:["+",String(T)]})]})]},o.key)})}),m>0&&t.jsxs("div",{className:"border-t border-border/50 pt-2 font-mono text-[11px] text-muted-foreground",children:["+",String(m)," more duplicate group",m===1?"":"s"]})]})]})}function Se(e){const s=[];for(const r of le){const n=e.filter(o=>o.role===r);if(n.length===0)continue;const l=n.reduce((o,i)=>o+i.size,0),c=n.reduce((o,i)=>o+i.characters,0),m=Z[r],g=`${n.length} segment${n.length===1?"":"s"} grouped as ${de[r]}`;s.push({role:r,label:m,size:l,characters:c,text:g,path:`role:${r}`})}return s}function $e(e){return[...e].sort((s,r)=>r.size-s.size).slice(0,se)}function Ee({parsed:e,inputTokens:s,model:r=null,onSegmentActivate:n,segments:l}){const{providers:c}=F(),[m,g]=f.useState("role"),o=f.useMemo(()=>l??null,[l]),i=f.useMemo(()=>(o??[]).reduce((a,x)=>a+x.size,0),[o]),b=f.useMemo(()=>o===null?[]:Se(o),[o]),T=f.useMemo(()=>o===null?[]:$e(o),[o]),d=f.useMemo(()=>o===null?null:q({segments:o,inputTokens:s,parsed:e,model:r,providers:c}),[s,r,e,c,o]),v=f.useMemo(()=>o===null||s===null||i===0?!1:Math.abs(s-i)/Math.max(s,i)>=te,[s,o,i]);if(o===null||o.length===0||e===null&&l===void 0)return null;const j=s!==null&&v?"text-amber-400":"text-muted-foreground",N=m==="role"?b:o,k=i>0?i:N.reduce((a,x)=>a+x.size,0),D=m==="segment"?n:void 0,M=`${String(o.length)} segment${o.length===1?"":"s"}`,U=s===null?"Provider input unknown":`Provider input ${u(s)}`,W=d===null?"Limit unknown":`Limit ${A(d)}`,G=d===null?"Usage unknown":`${w(d.usagePercent)} used`;return t.jsx(V,{delayDuration:150,children:t.jsxs("div",{className:"px-4 py-3 space-y-3","data-testid":"anatomy-root",children:[t.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[t.jsxs("div",{className:"min-w-0",children:[t.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-2",children:[t.jsx("div",{className:"text-sm font-semibold text-foreground",children:"Request Context"}),d!==null&&t.jsx(ge,{health:d.health})]}),t.jsxs("div",{className:p("mt-0.5 text-xs font-mono tabular-nums",j),children:["Estimated ~",u(i)," tokens | ",U," | ",W," |"," ",G," | ",M]})]}),t.jsx("div",{className:"inline-flex shrink-0 rounded border border-border bg-muted/20 p-0.5",role:"group","aria-label":"Context breakdown mode",children:ue.map(a=>t.jsx("button",{type:"button","aria-pressed":m===a.value,onClick:()=>g(a.value),className:p("h-6 rounded-sm px-2 text-[11px] font-medium transition-colors",m===a.value?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"),children:a.label},a.value))})]}),v&&t.jsxs("div",{className:"inline-flex items-center gap-1.5 text-xs text-amber-400",children:[t.jsxs(J,{children:[t.jsx(Y,{asChild:!0,children:t.jsx("button",{type:"button",className:"inline-flex items-center hover:text-amber-300","aria-label":"Token estimate differs from provider input",children:t.jsx(K,{className:"size-3.5"})})}),t.jsx(X,{className:"max-w-xs text-xs",children:"The bar uses a local token estimate. Provider input tokens remain the source of truth for billing and context-window usage."})]}),"Estimate differs from provider-reported input."]}),d!==null&&t.jsx(Te,{intelligence:d,segments:o,onSegmentActivate:n}),d!==null&&t.jsx(Ce,{groups:d.duplicateGroups,segments:o,onSegmentActivate:n}),t.jsx(Q,{segments:N,totalTokens:k,showLabels:m==="segment",onActivate:D}),t.jsx("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1.5 text-[11px] text-muted-foreground",children:b.map(a=>{const x=i>0?a.size/i*100:0;return t.jsxs("div",{className:"inline-flex items-center gap-1.5",children:[t.jsx("span",{"aria-hidden":"true",className:p("size-2.5 rounded-[2px]",$[a.role])}),t.jsx("span",{children:a.label}),t.jsx("span",{className:"font-mono text-muted-foreground/70",children:h(x)})]},a.role)})}),t.jsxs("div",{className:"space-y-1.5",children:[t.jsx("div",{className:"text-xs font-medium text-foreground",children:"Top Contributors"}),t.jsx("div",{className:"grid gap-1",children:T.map((a,x)=>{const H=i>0?a.size/i*100:0,R=n,E=t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"w-5 shrink-0 text-right font-mono text-muted-foreground/70",children:String(x+1)}),t.jsx("span",{"aria-hidden":"true",className:p("size-2.5 shrink-0 rounded-[2px]",$[a.role])}),t.jsx("span",{className:"min-w-0 flex-1 truncate text-left",children:a.label}),t.jsxs("span",{className:"shrink-0 font-mono text-muted-foreground",children:[h(H)," | ~",u(a.size)]})]});return R!==void 0?t.jsx("button",{type:"button",onClick:()=>R(a),className:"flex h-7 items-center gap-2 rounded px-1.5 text-xs text-muted-foreground hover:bg-muted/40 hover:text-foreground",title:"Jump to this request block",children:E},`${a.path}-${x}`):t.jsx("div",{className:"flex h-7 items-center gap-2 rounded px-1.5 text-xs text-muted-foreground",children:E},`${a.path}-${x}`)})})]})]})})}export{Ee as RequestAnatomy};
1
+ import{r as f,C as u,j as t,x as p,I as B}from"./index-CW0ab9r3.js";import{u as F,y as q,q as V,s as J,t as Y,I as K,v as X,S as Q,z as $,A as Z,E as C,F as ee,e as z}from"./ProxyViewerContainer-DnUrkMJF.js";const te=.25,se=5,re=4,ne=6,oe=.25,ae=.2,ie=.2,le=["system","user","assistant","tool","tools"],de={system:"instructions",user:"user turns",assistant:"assistant turns",tool:"tool results",tools:"tool schemas"},ue=[{value:"role",label:"By Role"},{value:"segment",label:"By Segment"}],ce={unknown:"bg-muted-foreground/50",ok:"bg-emerald-500/70",watch:"bg-amber-400/75",danger:"bg-red-500/80"},me={unknown:"text-muted-foreground",ok:"text-emerald-400",watch:"text-amber-300",danger:"text-red-300"},xe={ok:"border-emerald-400/30 bg-emerald-400/8 text-emerald-200",optimizable:"border-amber-400/30 bg-amber-400/8 text-amber-100",risk:"border-red-400/35 bg-red-500/10 text-red-100"},pe={ok:"OK",optimizable:"Optimizable",risk:"Risk"};function h(e){return e>=10?`${e.toFixed(0)}%`:e>=1?`${e.toFixed(1)}%`:e>0?"<1%":"0%"}function w(e){return e===null?"Unknown":h(e*100)}function L(e){return e===null?"Unknown":e<0?`-${u(Math.abs(e))}`:u(e)}function A(e){return e.contextWindow.tokens===null?"Unknown":B(e.contextWindow.tokens)}function fe(e){switch(e.contextWindow.source){case"request":return e.contextWindow.label;case"provider":return e.contextWindow.label;case"model-rule":return e.contextWindow.label;case"unknown":return e.model===null?e.contextWindow.label:`${e.contextWindow.label}: ${e.model}`}}function he(e){switch(e){case"watch":return"border-amber-400/30 bg-amber-400/8 text-amber-100";case"danger":return"border-red-400/35 bg-red-500/10 text-red-100"}}function _(e){const s=pe[e.level];if(e.level==="ok")return s;const r=e.level==="risk"?`${String(e.opportunityCount)} signal${e.opportunityCount===1?"":"s"}`:`${String(e.opportunityCount)} opportunit${e.opportunityCount===1?"y":"ies"}`;return e.reclaimableTokens<=0?`${s} | ${r}`:`${s} | ${r} | ~${u(e.reclaimableTokens)} tokens`}function ge({health:e}){return t.jsx("span",{className:p("inline-flex h-5 max-w-full items-center rounded border px-1.5 font-mono text-[10px]",xe[e.level]),"aria-label":`Context health ${_(e)}`,children:t.jsx("span",{className:"truncate",children:_(e)})})}function y(e,s){return e.roleUsages.find(r=>r.role===s)?.tokens??0}function O(e,s){return e.roleUsages.find(r=>r.role===s)?.percent??0}function S(e,s){if(e<=0)return null;const r=Math.round(e*s);return r>0?r:null}function I(e,s){return[...e].filter(r=>r.role===s).sort((r,n)=>n.size-r.size)[0]??null}function be(e){return[...e].filter(s=>s.role==="user"||s.role==="assistant"||s.role==="tool").sort((s,r)=>r.size-s.size)[0]??null}function ve(e,s){const r=e[0]??null;if(r===null)return null;const n=r.segments[0]??null;return n===null?null:P(n,s)}function je(e){const s=e.reduce((r,n)=>r+n.repeatedTokens,0);return s>0?s:null}function Ne(e){return y(e,"user")+y(e,"assistant")+y(e,"tool")}function ke({diagnostic:e,intelligence:s,segments:r}){switch(e.kind){case"duplicate":return{key:"duplicate",kind:"duplicate",severity:e.severity,title:"Duplicate content",impact:e.detail,action:"Remove repeated blocks or keep one canonical copy in the next request.",savingTokens:je(s.duplicateGroups),target:ve(s.duplicateGroups,r)};case"tool-schema":{const n=y(s,"tools"),l=O(s,"tools");return{key:"tool-schema",kind:"tool-schema",severity:e.severity,title:"Tool schema pressure",impact:`Tool definitions use ~${u(n)} tokens (${h(l*100)}).`,action:"Disable unused tools or shorten verbose schema descriptions.",savingTokens:S(n,oe),target:I(r,"tools")}}case"system-heavy":{const n=y(s,"system"),l=O(s,"system");return{key:"system-heavy",kind:"system-heavy",severity:e.severity,title:"Large system prompt",impact:`System instructions use ~${u(n)} tokens (${h(l*100)}).`,action:"Compress repeated policy text and move stable guidance into reusable memory.",savingTokens:S(n,ae),target:I(r,"system")}}case"history-bloat":{const n=Ne(s);return{key:"history-bloat",kind:"history-bloat",severity:e.severity,title:"Conversation history growth",impact:e.detail,action:"Summarize older turns and trim resolved tool outputs before continuing.",savingTokens:S(n,ie),target:be(r)}}}}function we({intelligence:e,segments:s}){const r=[];return(e.riskLevel==="watch"||e.riskLevel==="danger")&&r.push({key:"context-pressure",kind:"context-pressure",severity:e.riskLevel==="danger"?"danger":"watch",title:"Context window pressure",impact:`${w(e.usagePercent)} used, ${L(e.remainingAfterReserveTokens)} remaining after output reserve.`,action:"Start with the largest context block, then remove duplicates or summarize history.",savingTokens:null,target:[...s].sort((n,l)=>l.size-n.size)[0]??null}),e.contextWindow.source==="unknown"&&r.push({key:"context-window",kind:"context-window",severity:"watch",title:"Context window unknown",impact:"Agent Inspector cannot calculate remaining space for this model.",action:"Add model metadata in Provider settings so risk and remaining space are accurate.",savingTokens:null,target:null}),e.diagnostics.forEach(n=>{r.push(ke({diagnostic:n,intelligence:e,segments:s}))}),r}function ye({items:e,onSegmentActivate:s}){return e.length===0?null:t.jsxs("section",{className:"space-y-2 rounded border border-border/70 bg-muted/15 p-2",children:[t.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[t.jsx("div",{className:"text-xs font-medium text-foreground",children:"Context Advisor"}),t.jsxs("div",{className:"font-mono text-[11px] text-muted-foreground",children:[String(e.length)," issue",e.length===1?"":"s"]})]}),t.jsx("div",{className:"grid gap-2",children:e.map(r=>{const n=r.target,l=n!==null&&s!==void 0;return t.jsx("div",{className:p("rounded border px-2 py-1.5 text-xs",he(r.severity)),children:t.jsxs("div",{className:"flex min-w-0 flex-wrap items-start justify-between gap-2",children:[t.jsxs("div",{className:"min-w-0",children:[t.jsx("div",{className:"font-medium",children:r.title}),t.jsxs("div",{className:"mt-0.5 text-[11px] text-muted-foreground",children:["Impact: ",r.impact]}),t.jsxs("div",{className:"mt-0.5 text-[11px] text-muted-foreground",children:["Action: ",r.action]})]}),t.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[r.savingTokens!==null&&t.jsxs("span",{className:"font-mono text-[11px] text-muted-foreground",children:["Save ~",u(r.savingTokens)]}),l&&n!==null&&s!==void 0&&t.jsxs("button",{type:"button",onClick:()=>s(n),className:"inline-flex h-6 items-center gap-1 rounded border border-border/60 px-1.5 text-[11px] text-muted-foreground hover:border-border hover:bg-muted/40 hover:text-foreground",title:"Jump to the most relevant context block",children:[t.jsx(z,{className:"size-3"}),"Jump"]})]})]})},r.key)})})]})}function Te({intelligence:e,segments:s,onSegmentActivate:r}){const n=e.usagePercent===null?0:Math.max(1,e.usagePercent*100),l=e.outputReserveTokens===null?"No output reserve":`Output reserve ${u(e.outputReserveTokens)}`,c=e.largestRole,m=we({intelligence:e,segments:s});return t.jsxs("div",{className:"space-y-2",children:[t.jsxs("div",{className:"grid gap-x-4 gap-y-2 border-y border-border/60 py-2 text-xs sm:grid-cols-4",children:[t.jsxs("div",{className:"min-w-0",children:[t.jsx("div",{className:"text-[10px] font-medium uppercase text-muted-foreground",children:"Window"}),t.jsx("div",{className:"mt-0.5 truncate font-mono text-foreground",children:A(e)}),t.jsx("div",{className:"truncate text-[11px] text-muted-foreground",children:fe(e)})]}),t.jsxs("div",{className:"min-w-0",children:[t.jsx("div",{className:"text-[10px] font-medium uppercase text-muted-foreground",children:"Used"}),t.jsx("div",{className:p("mt-0.5 font-mono",me[e.riskLevel]),children:w(e.usagePercent)}),t.jsx("div",{className:"truncate text-[11px] text-muted-foreground",children:l})]}),t.jsxs("div",{className:"min-w-0",children:[t.jsx("div",{className:"text-[10px] font-medium uppercase text-muted-foreground",children:"Remaining"}),t.jsx("div",{className:"mt-0.5 font-mono text-foreground",children:L(e.remainingAfterReserveTokens)}),t.jsxs("div",{className:"truncate text-[11px] text-muted-foreground",children:["Input only ",L(e.remainingInputTokens)]})]}),t.jsxs("div",{className:"min-w-0",children:[t.jsx("div",{className:"text-[10px] font-medium uppercase text-muted-foreground",children:"Largest"}),c===null?t.jsx("div",{className:"mt-0.5 text-muted-foreground",children:"Unknown"}):t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"mt-0.5 flex min-w-0 items-center gap-1.5",children:[t.jsx("span",{"aria-hidden":"true",className:p("size-2.5 shrink-0 rounded-[2px]",$[c.role])}),t.jsx("span",{className:"truncate text-foreground",children:c.label})]}),t.jsxs("div",{className:"truncate font-mono text-[11px] text-muted-foreground",children:[h(c.percent*100)," | ~",u(c.tokens)]})]})]})]}),e.contextWindow.tokens!==null&&t.jsxs("div",{className:"space-y-1.5",children:[t.jsxs("div",{className:"relative h-2 overflow-hidden rounded-full bg-muted/40",children:[t.jsx("div",{className:p("h-full rounded-full",ce[e.riskLevel]),style:{width:`${String(n)}%`}}),t.jsx("div",{"aria-hidden":"true",className:"absolute top-0 h-full w-px bg-amber-200/70",style:{left:`${String(C.watch*100)}%`}}),t.jsx("div",{"aria-hidden":"true",className:"absolute top-0 h-full w-px bg-red-200/80",style:{left:`${String(C.danger*100)}%`}})]}),t.jsxs("div",{className:"flex justify-between text-[10px] text-muted-foreground",children:[t.jsx("span",{children:"Context window"}),t.jsxs("span",{children:["Watch ",w(C.watch)," / Danger"," ",w(C.danger)]})]})]}),t.jsx(ye,{items:m,onSegmentActivate:r})]})}function P(e,s){return s.find(r=>r.path===e.path)??null}function Ce({groups:e,segments:s,onSegmentActivate:r}){const[n,l]=f.useState(!1);if(e.length===0)return null;const c=e.slice(0,re),m=e.length-c.length,g=e.reduce((o,i)=>o+i.repeatedTokens,0);return t.jsxs("section",{className:"space-y-2 rounded border border-border/70 bg-muted/15 p-2",children:[t.jsxs("button",{type:"button",onClick:()=>l(o=>!o),"aria-expanded":n,className:"flex w-full flex-wrap items-center justify-between gap-2 rounded px-1 py-0.5 text-left transition-colors hover:bg-muted/30 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1",children:[t.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5",children:[n?t.jsx(ee,{className:"size-3.5 shrink-0 text-muted-foreground"}):t.jsx(z,{className:"size-3.5 shrink-0 text-muted-foreground"}),t.jsx("span",{className:"truncate text-xs font-medium text-foreground",children:"Duplicate Content"})]}),t.jsxs("span",{className:"font-mono text-[11px] text-muted-foreground",children:[String(e.length)," group",e.length===1?"":"s"," | ~",u(g)," repeated"]})]}),n&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"space-y-2",children:c.map((o,i)=>{const b=o.segments.slice(0,ne),T=o.segments.length-b.length;return t.jsxs("div",{className:"space-y-1.5 border-t border-border/50 pt-2 first:border-t-0 first:pt-0",children:[t.jsxs("div",{className:"flex min-w-0 items-center gap-2 text-xs",children:[t.jsx("span",{className:"w-5 shrink-0 text-right font-mono text-muted-foreground/70",children:String(i+1)}),t.jsx("span",{className:"min-w-0 flex-1 truncate text-foreground",children:o.firstLabel}),t.jsxs("span",{className:"shrink-0 font-mono text-muted-foreground",children:["x",String(o.count)," | ~",u(o.repeatedTokens)," saved"]})]}),o.preview.length>0&&t.jsx("div",{className:"ml-7 line-clamp-2 break-words rounded bg-background/40 px-2 py-1 font-mono text-[11px] leading-4 text-muted-foreground",children:o.preview}),t.jsxs("div",{className:"ml-7 flex flex-wrap gap-1",children:[b.map((d,v)=>{const j=P(d,s),N=j===null||r===void 0?void 0:r,k=`${d.label} ~${u(d.tokens)}`;return N===void 0||j===null?t.jsx("span",{className:"inline-flex h-6 max-w-40 items-center rounded border border-border/60 px-1.5 text-[11px] text-muted-foreground",title:k,children:t.jsx("span",{className:"truncate",children:k})},`${d.path}-${v}`):t.jsx("button",{type:"button",onClick:()=>N(j),className:"inline-flex h-6 max-w-40 items-center rounded border border-border/60 px-1.5 text-[11px] text-muted-foreground hover:border-border hover:bg-muted/40 hover:text-foreground",title:"Jump to this duplicate block",children:t.jsx("span",{className:"truncate",children:k})},`${d.path}-${v}`)}),T>0&&t.jsxs("span",{className:"inline-flex h-6 items-center rounded border border-border/40 px-1.5 font-mono text-[11px] text-muted-foreground/70",children:["+",String(T)]})]})]},o.key)})}),m>0&&t.jsxs("div",{className:"border-t border-border/50 pt-2 font-mono text-[11px] text-muted-foreground",children:["+",String(m)," more duplicate group",m===1?"":"s"]})]})]})}function Se(e){const s=[];for(const r of le){const n=e.filter(o=>o.role===r);if(n.length===0)continue;const l=n.reduce((o,i)=>o+i.size,0),c=n.reduce((o,i)=>o+i.characters,0),m=Z[r],g=`${n.length} segment${n.length===1?"":"s"} grouped as ${de[r]}`;s.push({role:r,label:m,size:l,characters:c,text:g,path:`role:${r}`})}return s}function $e(e){return[...e].sort((s,r)=>r.size-s.size).slice(0,se)}function Ee({parsed:e,inputTokens:s,model:r=null,onSegmentActivate:n,segments:l}){const{providers:c}=F(),[m,g]=f.useState("role"),o=f.useMemo(()=>l??null,[l]),i=f.useMemo(()=>(o??[]).reduce((a,x)=>a+x.size,0),[o]),b=f.useMemo(()=>o===null?[]:Se(o),[o]),T=f.useMemo(()=>o===null?[]:$e(o),[o]),d=f.useMemo(()=>o===null?null:q({segments:o,inputTokens:s,parsed:e,model:r,providers:c}),[s,r,e,c,o]),v=f.useMemo(()=>o===null||s===null||i===0?!1:Math.abs(s-i)/Math.max(s,i)>=te,[s,o,i]);if(o===null||o.length===0||e===null&&l===void 0)return null;const j=s!==null&&v?"text-amber-400":"text-muted-foreground",N=m==="role"?b:o,k=i>0?i:N.reduce((a,x)=>a+x.size,0),D=m==="segment"?n:void 0,M=`${String(o.length)} segment${o.length===1?"":"s"}`,U=s===null?"Provider input unknown":`Provider input ${u(s)}`,W=d===null?"Limit unknown":`Limit ${A(d)}`,G=d===null?"Usage unknown":`${w(d.usagePercent)} used`;return t.jsx(V,{delayDuration:150,children:t.jsxs("div",{className:"px-4 py-3 space-y-3","data-testid":"anatomy-root",children:[t.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[t.jsxs("div",{className:"min-w-0",children:[t.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-2",children:[t.jsx("div",{className:"text-sm font-semibold text-foreground",children:"Request Context"}),d!==null&&t.jsx(ge,{health:d.health})]}),t.jsxs("div",{className:p("mt-0.5 text-xs font-mono tabular-nums",j),children:["Estimated ~",u(i)," tokens | ",U," | ",W," |"," ",G," | ",M]})]}),t.jsx("div",{className:"inline-flex shrink-0 rounded border border-border bg-muted/20 p-0.5",role:"group","aria-label":"Context breakdown mode",children:ue.map(a=>t.jsx("button",{type:"button","aria-pressed":m===a.value,onClick:()=>g(a.value),className:p("h-6 rounded-sm px-2 text-[11px] font-medium transition-colors",m===a.value?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"),children:a.label},a.value))})]}),v&&t.jsxs("div",{className:"inline-flex items-center gap-1.5 text-xs text-amber-400",children:[t.jsxs(J,{children:[t.jsx(Y,{asChild:!0,children:t.jsx("button",{type:"button",className:"inline-flex items-center hover:text-amber-300","aria-label":"Token estimate differs from provider input",children:t.jsx(K,{className:"size-3.5"})})}),t.jsx(X,{className:"max-w-xs text-xs",children:"The bar uses a local token estimate. Provider input tokens remain the source of truth for billing and context-window usage."})]}),"Estimate differs from provider-reported input."]}),d!==null&&t.jsx(Te,{intelligence:d,segments:o,onSegmentActivate:n}),d!==null&&t.jsx(Ce,{groups:d.duplicateGroups,segments:o,onSegmentActivate:n}),t.jsx(Q,{segments:N,totalTokens:k,showLabels:m==="segment",onActivate:D}),t.jsx("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1.5 text-[11px] text-muted-foreground",children:b.map(a=>{const x=i>0?a.size/i*100:0;return t.jsxs("div",{className:"inline-flex items-center gap-1.5",children:[t.jsx("span",{"aria-hidden":"true",className:p("size-2.5 rounded-[2px]",$[a.role])}),t.jsx("span",{children:a.label}),t.jsx("span",{className:"font-mono text-muted-foreground/70",children:h(x)})]},a.role)})}),t.jsxs("div",{className:"space-y-1.5",children:[t.jsx("div",{className:"text-xs font-medium text-foreground",children:"Top Contributors"}),t.jsx("div",{className:"grid gap-1",children:T.map((a,x)=>{const H=i>0?a.size/i*100:0,R=n,E=t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"w-5 shrink-0 text-right font-mono text-muted-foreground/70",children:String(x+1)}),t.jsx("span",{"aria-hidden":"true",className:p("size-2.5 shrink-0 rounded-[2px]",$[a.role])}),t.jsx("span",{className:"min-w-0 flex-1 truncate text-left",children:a.label}),t.jsxs("span",{className:"shrink-0 font-mono text-muted-foreground",children:[h(H)," | ~",u(a.size)]})]});return R!==void 0?t.jsx("button",{type:"button",onClick:()=>R(a),className:"flex h-7 items-center gap-2 rounded px-1.5 text-xs text-muted-foreground hover:bg-muted/40 hover:text-foreground",title:"Jump to this request block",children:E},`${a.path}-${x}`):t.jsx("div",{className:"flex h-7 items-center gap-2 rounded px-1.5 text-xs text-muted-foreground",children:E},`${a.path}-${x}`)})})]})]})})}export{Ee as RequestAnatomy};
@@ -1,2 +1,2 @@
1
- import{r as c,j as e,x as B,C as d,G as D}from"./index-DHpwr08Z.js";import{G as F,H as g,J as j,K as H,B as m,F as N,e as v,N as y,O as k,Q as O,U as z,V as S,W as b,Y as T,Z as w,_ as p,g as M,$ as U}from"./ProxyViewerContainer-D7Sq0ctc.js";var $="Separator",C="horizontal",X=["horizontal","vertical"],G=c.forwardRef((n,t)=>{const{decorative:o,orientation:r=C,...s}=n,a=Z(r)?r:C,l=o?{role:"none"}:{"aria-orientation":a==="vertical"?a:void 0,role:"separator"};return e.jsx(F.div,{"data-orientation":a,...l,...s,ref:t})});G.displayName=$;function Z(n){return X.includes(n)}var Q=G;function A({className:n,orientation:t="horizontal",decorative:o=!0,...r}){return e.jsx(Q,{"data-slot":"separator",decorative:o,orientation:t,className:B("bg-border shrink-0 data-[orientation=horizontal]:h-px data-[orientation=horizontal]:w-full data-[orientation=vertical]:h-full data-[orientation=vertical]:w-px",n),...r})}const W=/<think>([\s\S]*?)<\/think>/gi,Y=/<think>([\s\S]*?)<\/think>/i;function L(n){const t=Y.exec(n);if(!t||t[1]===void 0)return{thinking:null,remainingText:n};const o=t[1].trim(),r=n.replace(W,"").trim();return{thinking:o,remainingText:r}}function q(n){return e.jsx(e.Fragment,{})}function ee({text:n}){const[t,o]=c.useState(!1);return e.jsxs(g,{open:t,onOpenChange:o,children:[e.jsxs(j,{className:"flex items-center gap-1.5 py-0.5 cursor-pointer hover:opacity-80 transition-opacity group",children:[t?e.jsx(N,{className:"size-3 text-muted-foreground"}):e.jsx(v,{className:"size-3 text-muted-foreground"}),e.jsx("span",{className:"text-muted-foreground text-xs italic select-none opacity-60",children:"[system-reminder]"})]}),e.jsx(y,{children:e.jsx("div",{className:"pl-4 pt-1",children:e.jsx(b,{text:n})})})]})}const te=c.memo(function({text:t}){if(t.includes("<system-reminder>"))return e.jsx(ee,{text:t});const{thinking:o,remainingText:r}=L(t);return e.jsxs("div",{className:"space-y-2",children:[o!==null&&e.jsx(_,{thinking:o}),r.length>0&&e.jsx(b,{text:r}),o===null&&r.length===0&&e.jsx("p",{className:"text-xs text-muted-foreground italic",children:"Empty text block"})]})}),_=c.memo(function({thinking:t}){const[o,r]=c.useState(!1);return e.jsx(g,{open:o,onOpenChange:r,children:e.jsxs("div",{className:"border-l-2 border-purple-500/40 my-1",children:[e.jsxs(j,{className:"flex items-center gap-1.5 px-3 py-1 w-full text-left cursor-pointer hover:bg-purple-500/5 transition-colors rounded-r-sm group",children:[e.jsx(H,{className:"size-3.5 text-purple-400 shrink-0"}),e.jsx("span",{className:"text-xs font-medium text-purple-400",children:"Thinking"}),e.jsxs(m,{variant:"ghost",className:"text-[10px] text-muted-foreground px-1.5 py-0 h-4 font-mono",children:[t.length.toLocaleString()," chars"]}),e.jsx("span",{className:"flex-1"}),o?e.jsx(N,{className:"size-3 text-muted-foreground"}):e.jsx(v,{className:"size-3 text-muted-foreground"})]}),e.jsx(y,{children:e.jsx("div",{className:"px-3 pb-2",children:e.jsx(k,{className:"max-h-[60vh]",children:e.jsx("pre",{className:"text-xs text-muted-foreground whitespace-pre-wrap font-mono leading-relaxed",children:t})})})})]})})}),ne=c.memo(function({name:t,input:o,toolIndex:r,toolFocus:s}){const[a,i]=c.useState(!1),l=c.useRef(null),x=s?.focusedToolIndex===r;return c.useEffect(()=>{if(!x||s===void 0||s.toolFocusNonce<=0)return;i(!0);const u=window.setTimeout(()=>{const f=l.current;f!==null&&(f.scrollIntoView({block:"center",behavior:"smooth"}),f.focus({preventScroll:!0}))},0);return()=>window.clearTimeout(u)},[x,s,s?.toolFocusNonce]),e.jsx(g,{open:a,onOpenChange:i,children:e.jsxs("div",{className:"border-l-2 border-sky-400/25 my-1","data-response-tool-index":r,children:[e.jsxs(j,{ref:l,className:"flex items-center gap-1.5 px-3 py-1 w-full text-left cursor-pointer hover:bg-sky-400/[0.04] transition-colors rounded-r-sm group focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",children:[e.jsx(O,{className:"size-3.5 text-sky-400/70 shrink-0"}),e.jsx(m,{variant:"outline",className:"text-[10px] font-mono px-1.5 py-0 h-4",children:t}),e.jsx("span",{className:"flex-1"}),a?e.jsx(N,{className:"size-3 text-muted-foreground"}):e.jsx(v,{className:"size-3 text-muted-foreground"})]}),e.jsx(y,{children:a&&e.jsx("div",{className:"px-3 pb-2",children:e.jsx(k,{className:"max-h-[60vh]",children:e.jsx(c.Suspense,{fallback:e.jsx("div",{className:"text-xs text-muted-foreground",children:"Loading JSON..."}),children:e.jsx(z,{data:S(o),defaultExpandDepth:0})})})})})]})})}),se=c.memo(function({block:t,toolIndex:o,toolFocus:r}){switch(t.type){case"text":return e.jsx(te,{text:t.text});case"thinking":case"think":return e.jsx(_,{thinking:t.thinking});case"tool_use":return e.jsx(ne,{name:t.name,input:t.input,toolIndex:o??0,toolFocus:r});default:return q()}}),oe=c.memo(function({response:t,toolFocus:o}){let r=0;return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx(m,{variant:"secondary",className:"text-[10px] px-1.5 py-0 h-5 font-mono",children:t.model}),t.stop_reason!==null&&e.jsxs(m,{variant:"outline",className:"text-[10px] px-1.5 py-0 h-5 font-mono flex items-center gap-1",children:[e.jsx(T,{className:"size-2.5"}),t.stop_reason]}),e.jsxs("span",{className:"flex items-center gap-1 text-muted-foreground text-xs",children:[e.jsx(w,{className:"size-3"}),e.jsxs("span",{className:"font-mono tabular-nums",children:[d(t.usage.input_tokens??0)," in /"," ",d(t.usage.output_tokens??0)," out"]}),t.usage.cache_creation_input_tokens!==void 0&&t.usage.cache_creation_input_tokens!==null&&t.usage.cache_creation_input_tokens>0&&e.jsxs("span",{className:"font-mono tabular-nums text-emerald-400",children:["KV Cache +",d(t.usage.cache_creation_input_tokens)]}),t.usage.cache_read_input_tokens!==void 0&&t.usage.cache_read_input_tokens!==null&&t.usage.cache_read_input_tokens>0&&e.jsxs("span",{className:"font-mono tabular-nums text-purple-400",children:["KV Cache ~",d(t.usage.cache_read_input_tokens)]})]})]}),e.jsx(A,{className:"opacity-50"}),e.jsxs("div",{className:"space-y-2",children:[t.content.map((s,a)=>{const i=s.type==="tool_use"?r:void 0;return s.type==="tool_use"&&(r+=1),e.jsx(se,{block:s,toolIndex:i,toolFocus:o},a)}),t.content.length===0&&e.jsx("p",{className:"text-xs text-muted-foreground italic",children:"Empty response content"})]})]})});function J(n){if(n===void 0||n==="")return{};try{return JSON.parse(n)}catch{return null}}function K({toolIndex:n,toolFocus:t,setOpen:o}){const r=c.useRef(null),s=t?.focusedToolIndex===n;return c.useEffect(()=>{if(!s||t===void 0||t.toolFocusNonce<=0)return;o(!0);const a=window.setTimeout(()=>{const i=r.current;i!==null&&(i.scrollIntoView({block:"center",behavior:"smooth"}),i.focus({preventScroll:!0}))},0);return()=>window.clearTimeout(a)},[o,s,t,t?.toolFocusNonce]),r}function re({name:n,argumentsText:t,toolIndex:o,toolFocus:r}){const s=c.useRef(null),a=r?.focusedToolIndex===o;return c.useEffect(()=>{if(!a||r===void 0||r.toolFocusNonce<=0)return;const i=window.setTimeout(()=>{const l=s.current;l!==null&&(l.scrollIntoView({block:"center",behavior:"smooth"}),l.focus({preventScroll:!0}))},0);return()=>window.clearTimeout(i)},[a,r,r?.toolFocusNonce]),e.jsxs("div",{ref:s,tabIndex:-1,className:"border border-sky-400/20 rounded-md p-3 bg-muted/20 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring","data-response-tool-index":o,children:[e.jsx("div",{className:"text-xs text-sky-400/80 font-mono mb-1",children:"function_call"}),e.jsxs("div",{className:"font-mono text-xs",children:[e.jsx("span",{className:"text-foreground/80",children:n}),e.jsxs("span",{className:"text-muted-foreground",children:["(",t,")"]})]})]})}function ae({call:n,toolIndex:t,toolFocus:o}){const[r,s]=c.useState(!1),a=n.function.name??"(unnamed tool)",i=r?J(n.function.arguments):{},l=K({toolIndex:t,toolFocus:o,setOpen:s});return e.jsx(g,{open:r,onOpenChange:s,children:e.jsxs("div",{className:"border-l-2 border-sky-400/25 my-1","data-response-tool-index":t,children:[e.jsxs(j,{ref:l,className:"flex items-center gap-1.5 px-3 py-1 w-full text-left cursor-pointer hover:bg-sky-400/[0.04] transition-colors rounded-r-sm group focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",children:[e.jsx(O,{className:"size-3.5 text-sky-400/70 shrink-0"}),e.jsx(m,{variant:"outline",className:"text-[10px] font-mono px-1.5 py-0 h-4",children:a}),n.id!==void 0&&n.id!==""&&e.jsx("span",{className:"text-[10px] font-mono text-muted-foreground/60 truncate",children:n.id}),e.jsx("span",{className:"flex-1"}),r?e.jsx(N,{className:"size-3 text-muted-foreground"}):e.jsx(v,{className:"size-3 text-muted-foreground"})]}),e.jsx(y,{children:r&&e.jsx("div",{className:"px-3 pb-2",children:e.jsx(k,{className:"max-h-[60vh]",children:i===null?e.jsx("pre",{className:"font-mono text-xs whitespace-pre-wrap break-words text-rose-300/90",children:n.function.arguments}):e.jsx(c.Suspense,{fallback:e.jsx("div",{className:"text-xs text-muted-foreground",children:"Loading JSON..."}),children:e.jsx(z,{data:S(i),defaultExpandDepth:0})})})})})]})})}function ie(n){if(n.output_text!==void 0&&n.output_text.length>0)return n.output_text;const t=[];for(const o of n.output??[]){if(p(o,"type")!=="message")continue;const r=p(o,"content");if(Array.isArray(r))for(const s of r){const a=p(s,"type"),i=p(s,"text");(a==="output_text"||a==="text")&&typeof i=="string"&&t.push(i)}}return t.join(`
1
+ import{r as c,j as e,x as B,C as d,G as D}from"./index-CW0ab9r3.js";import{G as F,H as g,J as j,K as H,B as m,F as N,e as v,N as y,O as k,Q as O,U as z,V as S,W as b,Y as T,Z as w,_ as p,g as M,$ as U}from"./ProxyViewerContainer-DnUrkMJF.js";var $="Separator",C="horizontal",X=["horizontal","vertical"],G=c.forwardRef((n,t)=>{const{decorative:o,orientation:r=C,...s}=n,a=Z(r)?r:C,l=o?{role:"none"}:{"aria-orientation":a==="vertical"?a:void 0,role:"separator"};return e.jsx(F.div,{"data-orientation":a,...l,...s,ref:t})});G.displayName=$;function Z(n){return X.includes(n)}var Q=G;function A({className:n,orientation:t="horizontal",decorative:o=!0,...r}){return e.jsx(Q,{"data-slot":"separator",decorative:o,orientation:t,className:B("bg-border shrink-0 data-[orientation=horizontal]:h-px data-[orientation=horizontal]:w-full data-[orientation=vertical]:h-full data-[orientation=vertical]:w-px",n),...r})}const W=/<think>([\s\S]*?)<\/think>/gi,Y=/<think>([\s\S]*?)<\/think>/i;function L(n){const t=Y.exec(n);if(!t||t[1]===void 0)return{thinking:null,remainingText:n};const o=t[1].trim(),r=n.replace(W,"").trim();return{thinking:o,remainingText:r}}function q(n){return e.jsx(e.Fragment,{})}function ee({text:n}){const[t,o]=c.useState(!1);return e.jsxs(g,{open:t,onOpenChange:o,children:[e.jsxs(j,{className:"flex items-center gap-1.5 py-0.5 cursor-pointer hover:opacity-80 transition-opacity group",children:[t?e.jsx(N,{className:"size-3 text-muted-foreground"}):e.jsx(v,{className:"size-3 text-muted-foreground"}),e.jsx("span",{className:"text-muted-foreground text-xs italic select-none opacity-60",children:"[system-reminder]"})]}),e.jsx(y,{children:e.jsx("div",{className:"pl-4 pt-1",children:e.jsx(b,{text:n})})})]})}const te=c.memo(function({text:t}){if(t.includes("<system-reminder>"))return e.jsx(ee,{text:t});const{thinking:o,remainingText:r}=L(t);return e.jsxs("div",{className:"space-y-2",children:[o!==null&&e.jsx(_,{thinking:o}),r.length>0&&e.jsx(b,{text:r}),o===null&&r.length===0&&e.jsx("p",{className:"text-xs text-muted-foreground italic",children:"Empty text block"})]})}),_=c.memo(function({thinking:t}){const[o,r]=c.useState(!1);return e.jsx(g,{open:o,onOpenChange:r,children:e.jsxs("div",{className:"border-l-2 border-purple-500/40 my-1",children:[e.jsxs(j,{className:"flex items-center gap-1.5 px-3 py-1 w-full text-left cursor-pointer hover:bg-purple-500/5 transition-colors rounded-r-sm group",children:[e.jsx(H,{className:"size-3.5 text-purple-400 shrink-0"}),e.jsx("span",{className:"text-xs font-medium text-purple-400",children:"Thinking"}),e.jsxs(m,{variant:"ghost",className:"text-[10px] text-muted-foreground px-1.5 py-0 h-4 font-mono",children:[t.length.toLocaleString()," chars"]}),e.jsx("span",{className:"flex-1"}),o?e.jsx(N,{className:"size-3 text-muted-foreground"}):e.jsx(v,{className:"size-3 text-muted-foreground"})]}),e.jsx(y,{children:e.jsx("div",{className:"px-3 pb-2",children:e.jsx(k,{className:"max-h-[60vh]",children:e.jsx("pre",{className:"text-xs text-muted-foreground whitespace-pre-wrap font-mono leading-relaxed",children:t})})})})]})})}),ne=c.memo(function({name:t,input:o,toolIndex:r,toolFocus:s}){const[a,i]=c.useState(!1),l=c.useRef(null),x=s?.focusedToolIndex===r;return c.useEffect(()=>{if(!x||s===void 0||s.toolFocusNonce<=0)return;i(!0);const u=window.setTimeout(()=>{const f=l.current;f!==null&&(f.scrollIntoView({block:"center",behavior:"smooth"}),f.focus({preventScroll:!0}))},0);return()=>window.clearTimeout(u)},[x,s,s?.toolFocusNonce]),e.jsx(g,{open:a,onOpenChange:i,children:e.jsxs("div",{className:"border-l-2 border-sky-400/25 my-1","data-response-tool-index":r,children:[e.jsxs(j,{ref:l,className:"flex items-center gap-1.5 px-3 py-1 w-full text-left cursor-pointer hover:bg-sky-400/[0.04] transition-colors rounded-r-sm group focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",children:[e.jsx(O,{className:"size-3.5 text-sky-400/70 shrink-0"}),e.jsx(m,{variant:"outline",className:"text-[10px] font-mono px-1.5 py-0 h-4",children:t}),e.jsx("span",{className:"flex-1"}),a?e.jsx(N,{className:"size-3 text-muted-foreground"}):e.jsx(v,{className:"size-3 text-muted-foreground"})]}),e.jsx(y,{children:a&&e.jsx("div",{className:"px-3 pb-2",children:e.jsx(k,{className:"max-h-[60vh]",children:e.jsx(c.Suspense,{fallback:e.jsx("div",{className:"text-xs text-muted-foreground",children:"Loading JSON..."}),children:e.jsx(z,{data:S(o),defaultExpandDepth:0})})})})})]})})}),se=c.memo(function({block:t,toolIndex:o,toolFocus:r}){switch(t.type){case"text":return e.jsx(te,{text:t.text});case"thinking":case"think":return e.jsx(_,{thinking:t.thinking});case"tool_use":return e.jsx(ne,{name:t.name,input:t.input,toolIndex:o??0,toolFocus:r});default:return q()}}),oe=c.memo(function({response:t,toolFocus:o}){let r=0;return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx(m,{variant:"secondary",className:"text-[10px] px-1.5 py-0 h-5 font-mono",children:t.model}),t.stop_reason!==null&&e.jsxs(m,{variant:"outline",className:"text-[10px] px-1.5 py-0 h-5 font-mono flex items-center gap-1",children:[e.jsx(T,{className:"size-2.5"}),t.stop_reason]}),e.jsxs("span",{className:"flex items-center gap-1 text-muted-foreground text-xs",children:[e.jsx(w,{className:"size-3"}),e.jsxs("span",{className:"font-mono tabular-nums",children:[d(t.usage.input_tokens??0)," in /"," ",d(t.usage.output_tokens??0)," out"]}),t.usage.cache_creation_input_tokens!==void 0&&t.usage.cache_creation_input_tokens!==null&&t.usage.cache_creation_input_tokens>0&&e.jsxs("span",{className:"font-mono tabular-nums text-emerald-400",children:["KV Cache +",d(t.usage.cache_creation_input_tokens)]}),t.usage.cache_read_input_tokens!==void 0&&t.usage.cache_read_input_tokens!==null&&t.usage.cache_read_input_tokens>0&&e.jsxs("span",{className:"font-mono tabular-nums text-purple-400",children:["KV Cache ~",d(t.usage.cache_read_input_tokens)]})]})]}),e.jsx(A,{className:"opacity-50"}),e.jsxs("div",{className:"space-y-2",children:[t.content.map((s,a)=>{const i=s.type==="tool_use"?r:void 0;return s.type==="tool_use"&&(r+=1),e.jsx(se,{block:s,toolIndex:i,toolFocus:o},a)}),t.content.length===0&&e.jsx("p",{className:"text-xs text-muted-foreground italic",children:"Empty response content"})]})]})});function J(n){if(n===void 0||n==="")return{};try{return JSON.parse(n)}catch{return null}}function K({toolIndex:n,toolFocus:t,setOpen:o}){const r=c.useRef(null),s=t?.focusedToolIndex===n;return c.useEffect(()=>{if(!s||t===void 0||t.toolFocusNonce<=0)return;o(!0);const a=window.setTimeout(()=>{const i=r.current;i!==null&&(i.scrollIntoView({block:"center",behavior:"smooth"}),i.focus({preventScroll:!0}))},0);return()=>window.clearTimeout(a)},[o,s,t,t?.toolFocusNonce]),r}function re({name:n,argumentsText:t,toolIndex:o,toolFocus:r}){const s=c.useRef(null),a=r?.focusedToolIndex===o;return c.useEffect(()=>{if(!a||r===void 0||r.toolFocusNonce<=0)return;const i=window.setTimeout(()=>{const l=s.current;l!==null&&(l.scrollIntoView({block:"center",behavior:"smooth"}),l.focus({preventScroll:!0}))},0);return()=>window.clearTimeout(i)},[a,r,r?.toolFocusNonce]),e.jsxs("div",{ref:s,tabIndex:-1,className:"border border-sky-400/20 rounded-md p-3 bg-muted/20 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring","data-response-tool-index":o,children:[e.jsx("div",{className:"text-xs text-sky-400/80 font-mono mb-1",children:"function_call"}),e.jsxs("div",{className:"font-mono text-xs",children:[e.jsx("span",{className:"text-foreground/80",children:n}),e.jsxs("span",{className:"text-muted-foreground",children:["(",t,")"]})]})]})}function ae({call:n,toolIndex:t,toolFocus:o}){const[r,s]=c.useState(!1),a=n.function.name??"(unnamed tool)",i=r?J(n.function.arguments):{},l=K({toolIndex:t,toolFocus:o,setOpen:s});return e.jsx(g,{open:r,onOpenChange:s,children:e.jsxs("div",{className:"border-l-2 border-sky-400/25 my-1","data-response-tool-index":t,children:[e.jsxs(j,{ref:l,className:"flex items-center gap-1.5 px-3 py-1 w-full text-left cursor-pointer hover:bg-sky-400/[0.04] transition-colors rounded-r-sm group focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",children:[e.jsx(O,{className:"size-3.5 text-sky-400/70 shrink-0"}),e.jsx(m,{variant:"outline",className:"text-[10px] font-mono px-1.5 py-0 h-4",children:a}),n.id!==void 0&&n.id!==""&&e.jsx("span",{className:"text-[10px] font-mono text-muted-foreground/60 truncate",children:n.id}),e.jsx("span",{className:"flex-1"}),r?e.jsx(N,{className:"size-3 text-muted-foreground"}):e.jsx(v,{className:"size-3 text-muted-foreground"})]}),e.jsx(y,{children:r&&e.jsx("div",{className:"px-3 pb-2",children:e.jsx(k,{className:"max-h-[60vh]",children:i===null?e.jsx("pre",{className:"font-mono text-xs whitespace-pre-wrap break-words text-rose-300/90",children:n.function.arguments}):e.jsx(c.Suspense,{fallback:e.jsx("div",{className:"text-xs text-muted-foreground",children:"Loading JSON..."}),children:e.jsx(z,{data:S(i),defaultExpandDepth:0})})})})})]})})}function ie(n){if(n.output_text!==void 0&&n.output_text.length>0)return n.output_text;const t=[];for(const o of n.output??[]){if(p(o,"type")!=="message")continue;const r=p(o,"content");if(Array.isArray(r))for(const s of r){const a=p(s,"type"),i=p(s,"text");(a==="output_text"||a==="text")&&typeof i=="string"&&t.push(i)}}return t.join(`
2
2
  `)}function le(n){const t=[];for(const o of n.output??[]){if(p(o,"type")!=="function_call")continue;const r=p(o,"name");if(typeof r!="string"||r.length===0)continue;const s=p(o,"id"),a=p(o,"call_id"),i=p(o,"arguments"),l=p(o,"status");t.push({id:typeof s=="string"&&s.length>0?s:null,callId:typeof a=="string"&&a.length>0?a:null,name:r,argumentsText:typeof i=="string"?i:"",status:typeof l=="string"&&l.length>0?l:null})}return t}function ce({call:n,toolIndex:t,toolFocus:o}){const[r,s]=c.useState(!1),a=r?J(n.argumentsText):{},i=n.callId??n.id,l=K({toolIndex:t,toolFocus:o,setOpen:s});return e.jsx(g,{open:r,onOpenChange:s,children:e.jsxs("div",{className:"border-l-2 border-sky-400/25 my-1","data-response-tool-index":t,children:[e.jsxs(j,{ref:l,className:"flex items-center gap-1.5 px-3 py-1 w-full text-left cursor-pointer hover:bg-sky-400/[0.04] transition-colors rounded-r-sm group focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",children:[e.jsx(O,{className:"size-3.5 text-sky-400/70 shrink-0"}),e.jsx(m,{variant:"outline",className:"text-[10px] font-mono px-1.5 py-0 h-4",children:n.name}),i!==null&&e.jsx("span",{className:"text-[10px] font-mono text-muted-foreground/60 truncate",children:i}),n.status!==null&&e.jsx(m,{variant:"secondary",className:"text-[10px] px-1.5 py-0 h-4 font-mono",children:n.status}),e.jsx("span",{className:"flex-1"}),r?e.jsx(N,{className:"size-3 text-muted-foreground"}):e.jsx(v,{className:"size-3 text-muted-foreground"})]}),e.jsx(y,{children:r&&e.jsx("div",{className:"px-3 pb-2",children:e.jsx(k,{className:"max-h-[60vh]",children:a===null?e.jsx("pre",{className:"font-mono text-xs whitespace-pre-wrap break-words text-rose-300/90",children:n.argumentsText}):e.jsx(c.Suspense,{fallback:e.jsx("div",{className:"text-xs text-muted-foreground",children:"Loading JSON..."}),children:e.jsx(z,{data:S(a),defaultExpandDepth:0})})})})})]})})}const ue=c.memo(function({response:t,toolFocus:o}){const r=t.choices[0],s=r?.message,a=s?.tool_calls??[];return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx(m,{variant:"secondary",className:"text-[10px] px-1.5 py-0 h-5 font-mono",children:t.model}),r?.finish_reason!==null&&r?.finish_reason!==void 0&&e.jsxs(m,{variant:"outline",className:"text-[10px] px-1.5 py-0 h-5 font-mono flex items-center gap-1",children:[e.jsx(T,{className:"size-2.5"}),r.finish_reason]}),e.jsxs("span",{className:"flex items-center gap-1 text-muted-foreground text-xs",children:[e.jsx(w,{className:"size-3"}),e.jsxs("span",{className:"font-mono tabular-nums",children:[d(t.usage.prompt_tokens??0)," in /"," ",d(t.usage.completion_tokens??0)," out"]})]})]}),e.jsx(A,{className:"opacity-50"}),e.jsxs("div",{className:"space-y-2",children:[s?.reasoning_content!==null&&s?.reasoning_content!==void 0&&s.reasoning_content.length>0&&e.jsx(_,{thinking:s.reasoning_content}),s?.content!==null&&s?.content!==void 0&&s.content.length>0&&(()=>{const i=s.reasoning_content!==null&&s.reasoning_content!==void 0&&s.reasoning_content.length>0,{thinking:l,remainingText:x}=L(s.content);return e.jsxs("div",{className:"space-y-2",children:[l!==null&&!i&&e.jsx(_,{thinking:l}),x.length>0&&e.jsx(b,{text:x})]})})(),a.map((i,l)=>e.jsx(ae,{call:i,toolIndex:l,toolFocus:o},i.id??`tc-${l}`)),s?.function_call!==null&&s?.function_call!==void 0&&e.jsx(re,{name:s.function_call.name,argumentsText:s.function_call.arguments,toolIndex:a.length,toolFocus:o}),(s?.content===null||s?.content===void 0||s.content.length===0)&&(s?.reasoning_content===null||s?.reasoning_content===void 0||s.reasoning_content.length===0)&&(s?.function_call===null||s?.function_call===void 0)&&a.length===0&&e.jsx("p",{className:"text-xs text-muted-foreground italic",children:"Empty response content"})]})]})}),de=c.memo(function({response:t,toolFocus:o}){const r=ie(t),s=le(t),a=t.status??null,i=t.usage?.input_tokens??0,l=t.usage?.output_tokens??0;return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[t.model!==void 0&&t.model.length>0&&e.jsx(m,{variant:"secondary",className:"text-[10px] px-1.5 py-0 h-5 font-mono",children:t.model}),a!==null&&e.jsxs(m,{variant:"outline",className:"text-[10px] px-1.5 py-0 h-5 font-mono flex items-center gap-1",children:[e.jsx(T,{className:"size-2.5"}),a]}),e.jsxs("span",{className:"flex items-center gap-1 text-muted-foreground text-xs",children:[e.jsx(w,{className:"size-3"}),e.jsxs("span",{className:"font-mono tabular-nums",children:[d(i)," in / ",d(l)," out"]})]})]}),e.jsx(A,{className:"opacity-50"}),e.jsxs("div",{className:"space-y-2",children:[r.length>0&&e.jsx(b,{text:r}),s.map((x,u)=>e.jsx(ce,{call:x,toolIndex:u,toolFocus:o},x.callId??x.id??`call-${u}`)),r.length===0&&s.length===0&&e.jsx("p",{className:"text-xs text-muted-foreground italic",children:"Empty response content"})]})]})});function E(n){return typeof n=="object"&&n!==null&&!Array.isArray(n)}function xe(n){return E(n)&&n.object==="chat.completion"}function me(n){return E(n)&&n.object==="response"}function pe(n){return E(n)&&n.type==="message"&&Array.isArray(n.content)}function fe(n,t,o){return n==="openai"&&xe(t)?e.jsx(ue,{response:t,toolFocus:o}):n==="openai"&&me(t)?e.jsx(de,{response:t,toolFocus:o}):n==="anthropic"&&pe(t)?e.jsx(oe,{response:t,toolFocus:o}):null}function he(n){switch(n){case"success":return"text-emerald-400";case"client_error":return"text-amber-400";case"server_error":return"text-red-400";case"pending":return"text-muted-foreground"}}function h({status:n}){const t=D(n),o=he(t);return n===null?e.jsx("span",{className:"text-xs text-muted-foreground italic",children:"pending"}):e.jsxs("span",{className:B("flex items-center gap-1 text-xs font-mono font-semibold",o),children:[t==="server_error"&&e.jsx(U,{className:"size-3"}),n]})}function V({text:n}){return e.jsx("div",{className:"rounded-md border border-red-500/30 bg-red-500/5 p-3",children:e.jsx("pre",{className:"text-xs text-red-300 whitespace-pre-wrap font-mono leading-relaxed overflow-auto max-h-[60vh]",children:n})})}function ge({text:n}){return e.jsx(b,{text:n})}const ye=c.memo(function({responseText:t,responseStatus:o,streaming:r,inputTokens:s,outputTokens:a,cacheCreationInputTokens:i,cacheReadInputTokens:l,apiFormat:x,error:u,focusedToolIndex:f=null,toolFocusNonce:P=0}){const R=x??"unknown",I=c.useMemo(()=>M(R).analyzeResponse(t).parsed,[R,t]);return t===null&&u===void 0?e.jsxs("div",{className:"flex items-center gap-2 py-3",children:[e.jsx(h,{status:o}),e.jsx("span",{className:"text-xs text-muted-foreground italic",children:"No response"})]}):o!==null&&o>=400?e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{status:o}),e.jsx(V,{text:t??""}),u!=null&&e.jsxs("div",{className:"rounded border border-destructive/50 bg-destructive/10 p-3 text-xs",children:[e.jsx("div",{className:"font-semibold text-destructive mb-1",children:"SSE Error"}),e.jsx("div",{className:"text-muted-foreground font-mono",children:u})]})]}):u!=null?e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{status:o}),e.jsxs("div",{className:"rounded border border-destructive/50 bg-destructive/10 p-3 text-xs",children:[e.jsx("div",{className:"font-semibold text-destructive mb-1",children:"SSE Error"}),e.jsx("div",{className:"text-muted-foreground font-mono",children:u})]}),t!==null&&e.jsx("div",{className:"mt-2",children:e.jsx(V,{text:t})})]}):I!==null?e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{status:o}),fe(R,I,{focusedToolIndex:f,toolFocusNonce:P})]}):e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(h,{status:o}),r&&(s!==null||a!==null)&&e.jsxs("span",{className:"flex items-center gap-1 text-muted-foreground text-xs",children:[e.jsx(w,{className:"size-3"}),e.jsxs("span",{className:"font-mono tabular-nums",children:[s!==null?d(s):"—"," in /"," ",a!==null?d(a):"—"," out"]}),i!=null&&i>0&&e.jsxs("span",{className:"font-mono tabular-nums text-emerald-400",children:["KV Cache +",d(i)]}),l!=null&&l>0&&e.jsxs("span",{className:"font-mono tabular-nums text-purple-400",children:["KV Cache ~",d(l)]})]})]}),e.jsx(ge,{text:t??""})]})});export{ye as ResponseView};
@@ -1 +1 @@
1
- import{r,H as b,j as e,o as v,b as N,a as k}from"./index-DHpwr08Z.js";import{q as S,s as C,t as y,F as l,e as x,B as E,v as w,a0 as T,U as z,a1 as R}from"./ProxyViewerContainer-D7Sq0ctc.js";const L=v({chunks:k(R),truncated:N().optional()}),M=1e4,D=r.memo(function({logId:o,truncated:m}){const[i,h]=r.useState(!1),[a,d]=r.useState({status:"idle"}),[p,f]=r.useState(new Set),c=r.useRef(null);r.useEffect(()=>{if(!i||c.current===o)return;const s=new AbortController;return d({status:"loading"}),b(`/api/logs/${o}/chunks`,L,M,{signal:s.signal},()=>"Chunks not found").then(t=>{c.current=o,d({status:"success",chunks:t.chunks})}).catch(t=>{t instanceof DOMException&&t.name==="AbortError"||(c.current=null,d({status:"error",message:t instanceof Error?t.message:"Chunk data unavailable"}))}),()=>{s.abort()}},[i,o]);const u=r.useMemo(()=>{if(a.status!=="success")return[];const s=new Map;for(const t of a.chunks){const n=s.get(t.index);n?n.push(t):s.set(t.index,[t])}return Array.from(s.entries()).map(([t,n])=>({index:t,chunks:n})).sort((t,n)=>t.index-n.index)},[a]),g=s=>{f(t=>{const n=new Set(t);return n.has(s)?n.delete(s):n.add(s),n})};function j(){return a.status==="idle"||a.status==="loading"?e.jsxs("div",{className:"flex items-center gap-2 py-2 text-xs text-muted-foreground",children:[e.jsx(T,{className:"size-3 animate-spin"}),e.jsx("span",{children:"Loading chunks..."})]}):a.status==="error"?e.jsx("div",{className:"py-2 text-xs text-muted-foreground italic",children:a.message}):e.jsxs("div",{className:"p-2 space-y-1",children:[e.jsxs("div",{className:"text-[10px] text-muted-foreground font-mono mb-2",children:[u.length," index group",u.length!==1?"s":""," available"]}),u.map(s=>{const t=p.has(s.index);return e.jsxs("div",{className:"rounded border border-border bg-background",children:[e.jsxs("button",{type:"button",className:"flex items-center gap-2 w-full px-2 py-1.5 text-left hover:bg-muted/50 transition-colors cursor-pointer",onClick:()=>g(s.index),children:[t?e.jsx(l,{className:"size-3 text-muted-foreground"}):e.jsx(x,{className:"size-3 text-muted-foreground"}),e.jsxs("span",{className:"text-[10px] text-muted-foreground font-mono",children:["[",s.index,"] ",s.chunks[0]?.type??""]}),e.jsxs("span",{className:"text-[10px] text-muted-foreground font-mono",children:[s.chunks.length," chunk",s.chunks.length!==1?"s":""]})]}),t&&e.jsx("div",{className:"px-2 pb-2 space-y-1",children:s.chunks.map(n=>e.jsxs("div",{className:"rounded border border-border bg-muted/20 p-2",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsxs("span",{className:"text-[10px] text-muted-foreground font-mono",children:["+",n.timestamp,"ms"]}),e.jsx("span",{className:"text-[10px] text-muted-foreground font-mono",children:n.type})]}),e.jsx(r.Suspense,{fallback:e.jsx("div",{className:"text-xs text-muted-foreground",children:"Loading JSON..."}),children:e.jsx(z,{data:n,defaultExpandDepth:0,showCopy:!0})})]},n.index))})]},s.index)})]})}return e.jsxs("div",{className:"space-y-1",children:[e.jsx(S,{children:e.jsxs(C,{children:[e.jsx(y,{asChild:!0,children:e.jsxs("button",{type:"button",className:"flex items-center gap-1.5 text-xs text-muted-foreground hover:text-foreground transition-colors cursor-pointer",onClick:()=>h(s=>!s),children:[i?e.jsx(l,{className:"size-3"}):e.jsx(x,{className:"size-3"}),e.jsx("span",{children:"Raw SSE Events"}),e.jsxs(E,{variant:"outline",className:"text-[9px] px-1 py-0 h-4 font-mono ml-1",children:[o,m===!0?"+":""]})]})}),e.jsx(w,{children:"Server-Sent Events streaming chunks from the provider"})]})}),i===!0?e.jsx("div",{className:"rounded-md border border-border bg-muted/20 overflow-auto max-h-64",children:j()}):null]})});export{D as StreamingChunkSequence};
1
+ import{r,H as b,j as e,o as v,b as N,a as k}from"./index-CW0ab9r3.js";import{q as S,s as C,t as y,F as l,e as x,B as E,v as w,a0 as T,U as z,a1 as R}from"./ProxyViewerContainer-DnUrkMJF.js";const L=v({chunks:k(R),truncated:N().optional()}),M=1e4,D=r.memo(function({logId:o,truncated:m}){const[i,h]=r.useState(!1),[a,d]=r.useState({status:"idle"}),[p,f]=r.useState(new Set),c=r.useRef(null);r.useEffect(()=>{if(!i||c.current===o)return;const s=new AbortController;return d({status:"loading"}),b(`/api/logs/${o}/chunks`,L,M,{signal:s.signal},()=>"Chunks not found").then(t=>{c.current=o,d({status:"success",chunks:t.chunks})}).catch(t=>{t instanceof DOMException&&t.name==="AbortError"||(c.current=null,d({status:"error",message:t instanceof Error?t.message:"Chunk data unavailable"}))}),()=>{s.abort()}},[i,o]);const u=r.useMemo(()=>{if(a.status!=="success")return[];const s=new Map;for(const t of a.chunks){const n=s.get(t.index);n?n.push(t):s.set(t.index,[t])}return Array.from(s.entries()).map(([t,n])=>({index:t,chunks:n})).sort((t,n)=>t.index-n.index)},[a]),g=s=>{f(t=>{const n=new Set(t);return n.has(s)?n.delete(s):n.add(s),n})};function j(){return a.status==="idle"||a.status==="loading"?e.jsxs("div",{className:"flex items-center gap-2 py-2 text-xs text-muted-foreground",children:[e.jsx(T,{className:"size-3 animate-spin"}),e.jsx("span",{children:"Loading chunks..."})]}):a.status==="error"?e.jsx("div",{className:"py-2 text-xs text-muted-foreground italic",children:a.message}):e.jsxs("div",{className:"p-2 space-y-1",children:[e.jsxs("div",{className:"text-[10px] text-muted-foreground font-mono mb-2",children:[u.length," index group",u.length!==1?"s":""," available"]}),u.map(s=>{const t=p.has(s.index);return e.jsxs("div",{className:"rounded border border-border bg-background",children:[e.jsxs("button",{type:"button",className:"flex items-center gap-2 w-full px-2 py-1.5 text-left hover:bg-muted/50 transition-colors cursor-pointer",onClick:()=>g(s.index),children:[t?e.jsx(l,{className:"size-3 text-muted-foreground"}):e.jsx(x,{className:"size-3 text-muted-foreground"}),e.jsxs("span",{className:"text-[10px] text-muted-foreground font-mono",children:["[",s.index,"] ",s.chunks[0]?.type??""]}),e.jsxs("span",{className:"text-[10px] text-muted-foreground font-mono",children:[s.chunks.length," chunk",s.chunks.length!==1?"s":""]})]}),t&&e.jsx("div",{className:"px-2 pb-2 space-y-1",children:s.chunks.map(n=>e.jsxs("div",{className:"rounded border border-border bg-muted/20 p-2",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsxs("span",{className:"text-[10px] text-muted-foreground font-mono",children:["+",n.timestamp,"ms"]}),e.jsx("span",{className:"text-[10px] text-muted-foreground font-mono",children:n.type})]}),e.jsx(r.Suspense,{fallback:e.jsx("div",{className:"text-xs text-muted-foreground",children:"Loading JSON..."}),children:e.jsx(z,{data:n,defaultExpandDepth:0,showCopy:!0})})]},n.index))})]},s.index)})]})}return e.jsxs("div",{className:"space-y-1",children:[e.jsx(S,{children:e.jsxs(C,{children:[e.jsx(y,{asChild:!0,children:e.jsxs("button",{type:"button",className:"flex items-center gap-1.5 text-xs text-muted-foreground hover:text-foreground transition-colors cursor-pointer",onClick:()=>h(s=>!s),children:[i?e.jsx(l,{className:"size-3"}):e.jsx(x,{className:"size-3"}),e.jsx("span",{children:"Raw SSE Events"}),e.jsxs(E,{variant:"outline",className:"text-[9px] px-1 py-0 h-4 font-mono ml-1",children:[o,m===!0?"+":""]})]})}),e.jsx(w,{children:"Server-Sent Events streaming chunks from the provider"})]})}),i===!0?e.jsx("div",{className:"rounded-md border border-border bg-muted/20 overflow-auto max-h-64",children:j()}):null]})});export{D as StreamingChunkSequence};
@@ -1 +1 @@
1
- import{R as o,j as e,r}from"./index-DHpwr08Z.js";import{P as a}from"./ProxyViewerContainer-D7Sq0ctc.js";function m(){const{sessionId:t}=o.useParams();return e.jsx(i,{sessionId:t})}function i({sessionId:t}){const[s,n]=r.useState(!1);return r.useEffect(()=>{n(!0)},[]),s?e.jsx(a,{initialSessionId:t},t):e.jsx("main",{className:"min-h-screen bg-background text-foreground",children:e.jsx("div",{className:"mx-auto flex min-h-screen w-full max-w-2xl flex-col justify-center px-6 py-16 text-center",children:e.jsxs("div",{className:"rounded-[8px] border border-border bg-card px-4 py-8 shadow-sm",children:[e.jsx("p",{className:"text-sm font-medium text-muted-foreground",children:"Loading session data..."}),e.jsx("p",{className:"mt-3 inline-block max-w-full break-all rounded bg-muted px-3 py-1 font-mono text-xs text-muted-foreground",children:t})]})})})}export{m as component};
1
+ import{R as o,j as e,r}from"./index-CW0ab9r3.js";import{P as a}from"./ProxyViewerContainer-DnUrkMJF.js";function m(){const{sessionId:t}=o.useParams();return e.jsx(i,{sessionId:t})}function i({sessionId:t}){const[s,n]=r.useState(!1);return r.useEffect(()=>{n(!0)},[]),s?e.jsx(a,{initialSessionId:t},t):e.jsx("main",{className:"min-h-screen bg-background text-foreground",children:e.jsx("div",{className:"mx-auto flex min-h-screen w-full max-w-2xl flex-col justify-center px-6 py-16 text-center",children:e.jsxs("div",{className:"rounded-[8px] border border-border bg-card px-4 py-8 shadow-sm",children:[e.jsx("p",{className:"text-sm font-medium text-muted-foreground",children:"Loading session data..."}),e.jsx("p",{className:"mt-3 inline-block max-w-full break-all rounded bg-muted px-3 py-1 font-mono text-xs text-muted-foreground",children:t})]})})})}export{m as component};
@@ -1 +1 @@
1
- import{j as e,S as s}from"./index-DHpwr08Z.js";function n({error:o,reset:r}){return e.jsx(s,{error:o,reset:r,scope:"session-route"})}export{n as errorComponent};
1
+ import{j as e,S as s}from"./index-CW0ab9r3.js";function n({error:o,reset:r}){return e.jsx(s,{error:o,reset:r,scope:"session-route"})}export{n as errorComponent};
@@ -1 +1 @@
1
- import{r,j as e}from"./index-DHpwr08Z.js";import{P as o}from"./ProxyViewerContainer-D7Sq0ctc.js";function x(){const[t,n]=r.useState(!1);return r.useEffect(()=>{n(!0)},[]),t?e.jsx(o,{}):e.jsx("main",{className:"min-h-screen bg-background text-foreground",children:e.jsx("div",{className:"mx-auto flex min-h-screen w-full max-w-2xl flex-col justify-center px-6 py-16 text-center",children:e.jsx("div",{className:"rounded-[8px] border border-border bg-card px-4 py-8 shadow-sm",children:e.jsx("p",{className:"text-sm font-medium text-muted-foreground",children:"Loading Inspector..."})})})})}export{x as component};
1
+ import{r,j as e}from"./index-CW0ab9r3.js";import{P as o}from"./ProxyViewerContainer-DnUrkMJF.js";function x(){const[t,n]=r.useState(!1);return r.useEffect(()=>{n(!0)},[]),t?e.jsx(o,{}):e.jsx("main",{className:"min-h-screen bg-background text-foreground",children:e.jsx("div",{className:"mx-auto flex min-h-screen w-full max-w-2xl flex-col justify-center px-6 py-16 text-center",children:e.jsx("div",{className:"rounded-[8px] border border-border bg-card px-4 py-8 shadow-sm",children:e.jsx("p",{className:"text-sm font-medium text-muted-foreground",children:"Loading Inspector..."})})})})}export{x as component};
@@ -1 +1 @@
1
- import{j as e,S as t}from"./index-DHpwr08Z.js";function m({error:o,reset:r}){return e.jsx(t,{error:o,reset:r,scope:"home-route"})}export{m as errorComponent};
1
+ import{j as e,S as t}from"./index-CW0ab9r3.js";function m({error:o,reset:r}){return e.jsx(t,{error:o,reset:r,scope:"home-route"})}export{m as errorComponent};