@tonyclaw/agent-inspector 2.0.31 → 2.0.32

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 (33) hide show
  1. package/.output/nitro.json +1 -1
  2. package/.output/public/assets/{CompareDrawer-tIUf2EJm.js → CompareDrawer-Dgi0hhg5.js} +1 -1
  3. package/.output/public/assets/{ProxyViewerContainer-BxRaXhKR.js → ProxyViewerContainer-4dG0nLRp.js} +28 -28
  4. package/.output/public/assets/{ReplayDialog-D6v1xcuC.js → ReplayDialog-BL6BwDuI.js} +1 -1
  5. package/.output/public/assets/{RequestAnatomy-D6PniTlx.js → RequestAnatomy-DZMmiIiD.js} +1 -1
  6. package/.output/public/assets/{ResponseView-Sx8PjuvU.js → ResponseView-DJLOiTYq.js} +1 -1
  7. package/.output/public/assets/{StreamingChunkSequence-D-Rbfnxh.js → StreamingChunkSequence--SxZ5cxc.js} +1 -1
  8. package/.output/public/assets/_sessionId-C4z6gu9i.js +1 -0
  9. package/.output/public/assets/index-Drpb2qR5.js +1 -0
  10. package/.output/public/assets/{index-Byk60-jA.css → index-fUUi8iQF.css} +1 -1
  11. package/.output/public/assets/{main-B1kdhY98.js → main-CbRIHhJ5.js} +2 -2
  12. package/.output/server/_libs/lucide-react.mjs +9 -9
  13. package/.output/server/{_sessionId-BceHFKf4.mjs → _sessionId-DNfumR8F.mjs} +2 -2
  14. package/.output/server/_ssr/{CompareDrawer-uSxK5Ei5.mjs → CompareDrawer-CzgjhnUa.mjs} +3 -3
  15. package/.output/server/_ssr/{ProxyViewerContainer-_npQ_f2i.mjs → ProxyViewerContainer-BqOcZ7en.mjs} +258 -87
  16. package/.output/server/_ssr/{ReplayDialog-BHAzSLCT.mjs → ReplayDialog-DmEknIL8.mjs} +3 -3
  17. package/.output/server/_ssr/{RequestAnatomy-DjlZLXBd.mjs → RequestAnatomy-DNoiMudY.mjs} +3 -3
  18. package/.output/server/_ssr/{ResponseView-BuDEJ3fl.mjs → ResponseView-C_cRrleT.mjs} +3 -3
  19. package/.output/server/_ssr/{StreamingChunkSequence-DFcu0bD8.mjs → StreamingChunkSequence-DHZ9Q_dL.mjs} +3 -3
  20. package/.output/server/_ssr/{index-Bw6Fw33c.mjs → index-coYS9XyS.mjs} +2 -2
  21. package/.output/server/_ssr/index.mjs +2 -2
  22. package/.output/server/_ssr/{router-D90tMCb3.mjs → router-DUb5lKw1.mjs} +138 -39
  23. package/.output/server/{_tanstack-start-manifest_v-BVM4AUlx.mjs → _tanstack-start-manifest_v-xcG1o8Vt.mjs} +1 -1
  24. package/.output/server/index.mjs +67 -67
  25. package/package.json +1 -1
  26. package/src/components/groups/GroupsDialog.tsx +291 -78
  27. package/src/lib/groupContract.ts +13 -0
  28. package/src/mcp/server.ts +16 -0
  29. package/src/mcp/toolHandlers.ts +22 -0
  30. package/src/proxy/groupStore.ts +52 -2
  31. package/src/routes/api/groups.$groupId.ts +38 -1
  32. package/.output/public/assets/_sessionId-BhNTuZ31.js +0 -1
  33. package/.output/public/assets/index-Kxptlkpg.js +0 -1
@@ -1 +1 @@
1
- import{r as u,j as s}from"./main-B1kdhY98.js";import{c as L,u as te,D as ne,k as re,l as ae,m as le,n as z,T as v,o as T,p as o,q as i,s as h,t as oe,v as ie,w as de,x as ue,y as P,z as f,A as ce,E as pe,F as _,G as I,H as me}from"./ProxyViewerContainer-BxRaXhKR.js";import{ResponseView as M}from"./ResponseView-Sx8PjuvU.js";const xe=[["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"}]],he=L("braces",xe);const fe=[["path",{d:"m14 10 7-7",key:"oa77jy"}],["path",{d:"M20 10h-6V4",key:"mjg0md"}],["path",{d:"m3 21 7-7",key:"tjx5ai"}],["path",{d:"M4 14h6v6",key:"rmj7iw"}]],ye=L("minimize-2",fe);function A(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function je(e){return e==null?null:new TextEncoder().encode(e).length}function ge(e){try{const t=JSON.parse(e);if(!A(t))return null;const a=t.model;return typeof a=="string"&&a.length>0?a:null}catch{return null}}function be(e,t){try{const a=JSON.parse(e);return A(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 D(e){return{status:e.status??null,elapsedMs:e.elapsedMs??null,inputTokens:e.inputTokens??null,outputTokens:e.outputTokens??null,responseBytes:je(e.responseText),streaming:e.streaming===!0}}function j(e,t){return e===null||t===null?null:t-e}function ve(e,t){return[{id:"status",label:"Status",original:e.status,replay:t.status,delta:j(e.status,t.status)},{id:"elapsed",label:"Elapsed",original:e.elapsedMs,replay:t.elapsedMs,delta:j(e.elapsedMs,t.elapsedMs)},{id:"input",label:"Input",original:e.inputTokens,replay:t.inputTokens,delta:j(e.inputTokens,t.inputTokens)},{id:"output",label:"Output",original:e.outputTokens,replay:t.outputTokens,delta:j(e.outputTokens,t.outputTokens)},{id:"bytes",label:"Bytes",original:e.responseBytes,replay:t.responseBytes,delta:j(e.responseBytes,t.responseBytes)},{id:"streaming",label:"Stream",original:e.streaming,replay:t.streaming,delta:null}]}const Te=P({success:_(),error:I().optional(),responseStatus:f().nullable().optional(),responseText:I().nullable().optional(),inputTokens:f().nullable().optional(),outputTokens:f().nullable().optional(),elapsedMs:f().nullable().optional(),streaming:_().optional(),replayLogId:f().optional()}),Ne=P({logs:ce(me),total:f()});function N(e){try{const t=JSON.parse(e);return JSON.stringify(t,null,2)}catch{return e}}function ke(e){try{const t=JSON.parse(e);return JSON.stringify(t)}catch{return e}}function Re(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 C(e){return e<1e3?`${String(e)}ms`:`${(e/1e3).toFixed(1)}s`}function V(e,t){if(e===null)return"-";if(typeof e=="boolean")return e?"stream":"non-stream";switch(t){case"elapsed":return C(e);case"input":case"output":case"bytes":return e.toLocaleString();case"status":return String(e);case"streaming":return e?"stream":"non-stream"}}function Se(e,t){if(e===null)return"-";const a=e>0?"+":"";switch(t){case"elapsed":return`${a}${C(e)}`;case"input":case"output":case"bytes":case"status":return`${a}${e.toLocaleString()}`;case"streaming":return"-"}}function we(e){return e===null||e===0?"text-muted-foreground":e>0?"text-amber-400":"text-emerald-400"}function H({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:V(t.original,t.id)}),s.jsx("span",{className:"font-mono",children:V(t.replay,t.id)}),s.jsx("span",{className:`font-mono ${we(t.delta)}`,children:Se(t.delta,t.id)})]},t.id))]})}function Je({log:e,open:t,onOpenChange:a}){const{providers:O}=te(),J=e.rawRequestBody??"{}",[c,G]=u.useState(()=>N(J)),[r,g]=u.useState(null),[K,Q]=u.useState([]),[B,k]=u.useState(!1),[R,p]=u.useState(null),m=u.useMemo(()=>Re(c),[c]),b=u.useCallback(async()=>{if(t)try{const n=await fetch(`/api/logs?replayOf=${String(e.id)}`);if(!n.ok)return;const l=await n.json(),d=Ne.safeParse(l);if(!d.success)return;Q(d.data.logs)}catch{}},[e.id,t]);u.useEffect(()=>{b()},[b]);async function U(){if(!m.valid){p("Request body must be valid JSON before replay.");return}k(!0),p(null),g(null);try{const l=await(await fetch(`/api/logs/${e.id}/replay`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({modifiedBody:c})})).json(),d=Te.safeParse(l);if(!d.success){p("Invalid response from server"),k(!1);return}const w=d.data;g(w),await b(),w.success||p(w.error??"Replay failed")}catch(n){p(n instanceof Error?n.message:"Network error")}finally{k(!1)}}function W(){g(null),p(null),a(!1)}function y(n){G(n),g(null),p(null)}function X(){y(N(c))}function Y(){y(ke(c))}function Z(){y(N(J))}function $(n){window.location.hash=`log-${String(n)}`,pe({logId:n,tab:"request"}),a(!1)}const S=u.useMemo(()=>{const n=[];for(const l of O)for(const d of l.models)d.trim().length!==0&&n.push({key:`${l.id}:${d}`,providerName:l.name,model:d});return n},[O]),x=ge(c)??e.model??"";function ee(n){const l=be(c,n);if(l.error!==null){p(l.error);return}y(N(l.body))}const se=D({status:e.responseStatus,elapsedMs:e.elapsedMs,inputTokens:e.inputTokens,outputTokens:e.outputTokens,responseText:e.responseText,streaming:e.streaming}),F=r===null?null:D({status:r.responseStatus,elapsedMs:r.elapsedMs,inputTokens:r.inputTokens,outputTokens:r.outputTokens,responseText:r.responseText,streaming:r.streaming}),E=F===null?[]:ve(se,F),q=K.slice(-5).reverse();return s.jsx(ne,{open:t,onOpenChange:W,children:s.jsxs(re,{className:"max-w-4xl max-h-[85vh] overflow-auto",children:[s.jsx(ae,{children:s.jsxs(le,{className:"flex items-center gap-2",children:[s.jsx(z,{className:"size-4"}),"Replay Request #",e.id]})}),s.jsxs(v,{defaultValue:"modified",children:[s.jsxs(T,{children:[s.jsx(o,{value:"modified",children:"Modified Request"}),s.jsx(o,{value:"original",children:"Original Response"}),r&&s.jsx(o,{value:"replay",children:"Replay Response"}),r&&s.jsx(o,{value:"compare",children:"Compare"})]}),s.jsxs(i,{value:"modified",className:"space-y-4",children:[S.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:x,onChange:n=>ee(n.currentTarget.value),className:"h-8 rounded-md border border-input bg-background px-2 text-sm",children:[x===""&&s.jsx("option",{value:"",children:"Select model"}),x!==""&&!S.some(n=>n.model===x)&&s.jsx("option",{value:x,children:x}),S.map(n=>s.jsxs("option",{value:n.model,children:[n.providerName," / ",n.model]},n.key))]})]}),q.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(h,{type:"button",variant:"ghost",size:"sm",onClick:()=>{b()},children:"Refresh"})]}),s.jsx("div",{className:"grid gap-1",children:q.map(n=>s.jsxs("button",{type:"button",onClick:()=>$(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?"-":C(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:m.valid?"text-xs text-emerald-500":"text-xs text-destructive",children:m.message}),s.jsxs(h,{type:"button",variant:"outline",size:"sm",onClick:X,disabled:!m.valid,title:"Format JSON",children:[s.jsx(he,{className:"size-3.5"}),"Format"]}),s.jsxs(h,{type:"button",variant:"outline",size:"sm",onClick:Y,disabled:!m.valid,title:"Compact JSON",children:[s.jsx(ye,{className:"size-3.5"}),"Compact"]}),s.jsxs(h,{type:"button",variant:"ghost",size:"sm",onClick:Z,title:"Reset to original request",children:[s.jsx(z,{className:"size-3.5"}),"Reset"]})]})]}),s.jsx(oe,{children:s.jsxs(ie,{children:[s.jsx(de,{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=>y(n.target.value),spellCheck:!1})}),s.jsx(ue,{children:"Edit formatted JSON before re-sending to the provider"})]})})]}),R!==null&&R!==""&&s.jsx("div",{className:"text-sm text-destructive bg-destructive/10 px-3 py-2 rounded-md",children:R}),s.jsx("div",{className:"flex justify-end",children:s.jsx(h,{onClick:()=>{U()},disabled:B||!m.valid,children:B?"Replaying...":"Replay"})}),r!==null&&s.jsx(H,{comparisons:E.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(h,{type:"button",variant:"outline",size:"sm",onClick:()=>$(r.replayLogId??e.id),children:"Open saved log"})]}),r&&r.success&&s.jsxs(v,{defaultValue:"parsed",children:[s.jsxs(T,{children:[s.jsx(o,{value:"parsed",children:"Response"}),s.jsx(o,{value:"raw",children:"Raw Response"})]}),s.jsx(i,{value:"parsed",children:s.jsx(M,{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(i,{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(i,{value:"original",children:e.responseText!==null?s.jsxs(v,{defaultValue:"parsed",children:[s.jsxs(T,{children:[s.jsx(o,{value:"parsed",children:"Response"}),s.jsx(o,{value:"raw",children:"Raw Response"})]}),s.jsx(i,{value:"parsed",children:s.jsx(M,{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(i,{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(i,{value:"replay",children:(r.responseText??null)!==null?s.jsxs(v,{defaultValue:"parsed",children:[s.jsxs(T,{children:[s.jsx(o,{value:"parsed",children:"Response"}),s.jsx(o,{value:"raw",children:"Raw Response"})]}),s.jsx(i,{value:"parsed",children:s.jsx(M,{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(i,{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(i,{value:"compare",className:"space-y-3",children:[s.jsx(H,{comparisons:E}),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{Je as ReplayDialog};
1
+ import{r as u,j as s}from"./main-CbRIHhJ5.js";import{c as L,u as te,D as ne,k as re,l as ae,m as le,n as z,T as v,o as T,p as o,q as i,s as h,t as oe,v as ie,w as de,x as ue,y as P,z as f,A as ce,E as pe,F as _,G as I,H as me}from"./ProxyViewerContainer-4dG0nLRp.js";import{ResponseView as M}from"./ResponseView-DJLOiTYq.js";const xe=[["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"}]],he=L("braces",xe);const fe=[["path",{d:"m14 10 7-7",key:"oa77jy"}],["path",{d:"M20 10h-6V4",key:"mjg0md"}],["path",{d:"m3 21 7-7",key:"tjx5ai"}],["path",{d:"M4 14h6v6",key:"rmj7iw"}]],ye=L("minimize-2",fe);function A(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function je(e){return e==null?null:new TextEncoder().encode(e).length}function ge(e){try{const t=JSON.parse(e);if(!A(t))return null;const a=t.model;return typeof a=="string"&&a.length>0?a:null}catch{return null}}function be(e,t){try{const a=JSON.parse(e);return A(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 D(e){return{status:e.status??null,elapsedMs:e.elapsedMs??null,inputTokens:e.inputTokens??null,outputTokens:e.outputTokens??null,responseBytes:je(e.responseText),streaming:e.streaming===!0}}function j(e,t){return e===null||t===null?null:t-e}function ve(e,t){return[{id:"status",label:"Status",original:e.status,replay:t.status,delta:j(e.status,t.status)},{id:"elapsed",label:"Elapsed",original:e.elapsedMs,replay:t.elapsedMs,delta:j(e.elapsedMs,t.elapsedMs)},{id:"input",label:"Input",original:e.inputTokens,replay:t.inputTokens,delta:j(e.inputTokens,t.inputTokens)},{id:"output",label:"Output",original:e.outputTokens,replay:t.outputTokens,delta:j(e.outputTokens,t.outputTokens)},{id:"bytes",label:"Bytes",original:e.responseBytes,replay:t.responseBytes,delta:j(e.responseBytes,t.responseBytes)},{id:"streaming",label:"Stream",original:e.streaming,replay:t.streaming,delta:null}]}const Te=P({success:_(),error:I().optional(),responseStatus:f().nullable().optional(),responseText:I().nullable().optional(),inputTokens:f().nullable().optional(),outputTokens:f().nullable().optional(),elapsedMs:f().nullable().optional(),streaming:_().optional(),replayLogId:f().optional()}),Ne=P({logs:ce(me),total:f()});function N(e){try{const t=JSON.parse(e);return JSON.stringify(t,null,2)}catch{return e}}function ke(e){try{const t=JSON.parse(e);return JSON.stringify(t)}catch{return e}}function Re(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 C(e){return e<1e3?`${String(e)}ms`:`${(e/1e3).toFixed(1)}s`}function V(e,t){if(e===null)return"-";if(typeof e=="boolean")return e?"stream":"non-stream";switch(t){case"elapsed":return C(e);case"input":case"output":case"bytes":return e.toLocaleString();case"status":return String(e);case"streaming":return e?"stream":"non-stream"}}function Se(e,t){if(e===null)return"-";const a=e>0?"+":"";switch(t){case"elapsed":return`${a}${C(e)}`;case"input":case"output":case"bytes":case"status":return`${a}${e.toLocaleString()}`;case"streaming":return"-"}}function we(e){return e===null||e===0?"text-muted-foreground":e>0?"text-amber-400":"text-emerald-400"}function H({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:V(t.original,t.id)}),s.jsx("span",{className:"font-mono",children:V(t.replay,t.id)}),s.jsx("span",{className:`font-mono ${we(t.delta)}`,children:Se(t.delta,t.id)})]},t.id))]})}function Je({log:e,open:t,onOpenChange:a}){const{providers:O}=te(),J=e.rawRequestBody??"{}",[c,G]=u.useState(()=>N(J)),[r,g]=u.useState(null),[K,Q]=u.useState([]),[B,k]=u.useState(!1),[R,p]=u.useState(null),m=u.useMemo(()=>Re(c),[c]),b=u.useCallback(async()=>{if(t)try{const n=await fetch(`/api/logs?replayOf=${String(e.id)}`);if(!n.ok)return;const l=await n.json(),d=Ne.safeParse(l);if(!d.success)return;Q(d.data.logs)}catch{}},[e.id,t]);u.useEffect(()=>{b()},[b]);async function U(){if(!m.valid){p("Request body must be valid JSON before replay.");return}k(!0),p(null),g(null);try{const l=await(await fetch(`/api/logs/${e.id}/replay`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({modifiedBody:c})})).json(),d=Te.safeParse(l);if(!d.success){p("Invalid response from server"),k(!1);return}const w=d.data;g(w),await b(),w.success||p(w.error??"Replay failed")}catch(n){p(n instanceof Error?n.message:"Network error")}finally{k(!1)}}function W(){g(null),p(null),a(!1)}function y(n){G(n),g(null),p(null)}function X(){y(N(c))}function Y(){y(ke(c))}function Z(){y(N(J))}function $(n){window.location.hash=`log-${String(n)}`,pe({logId:n,tab:"request"}),a(!1)}const S=u.useMemo(()=>{const n=[];for(const l of O)for(const d of l.models)d.trim().length!==0&&n.push({key:`${l.id}:${d}`,providerName:l.name,model:d});return n},[O]),x=ge(c)??e.model??"";function ee(n){const l=be(c,n);if(l.error!==null){p(l.error);return}y(N(l.body))}const se=D({status:e.responseStatus,elapsedMs:e.elapsedMs,inputTokens:e.inputTokens,outputTokens:e.outputTokens,responseText:e.responseText,streaming:e.streaming}),F=r===null?null:D({status:r.responseStatus,elapsedMs:r.elapsedMs,inputTokens:r.inputTokens,outputTokens:r.outputTokens,responseText:r.responseText,streaming:r.streaming}),E=F===null?[]:ve(se,F),q=K.slice(-5).reverse();return s.jsx(ne,{open:t,onOpenChange:W,children:s.jsxs(re,{className:"max-w-4xl max-h-[85vh] overflow-auto",children:[s.jsx(ae,{children:s.jsxs(le,{className:"flex items-center gap-2",children:[s.jsx(z,{className:"size-4"}),"Replay Request #",e.id]})}),s.jsxs(v,{defaultValue:"modified",children:[s.jsxs(T,{children:[s.jsx(o,{value:"modified",children:"Modified Request"}),s.jsx(o,{value:"original",children:"Original Response"}),r&&s.jsx(o,{value:"replay",children:"Replay Response"}),r&&s.jsx(o,{value:"compare",children:"Compare"})]}),s.jsxs(i,{value:"modified",className:"space-y-4",children:[S.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:x,onChange:n=>ee(n.currentTarget.value),className:"h-8 rounded-md border border-input bg-background px-2 text-sm",children:[x===""&&s.jsx("option",{value:"",children:"Select model"}),x!==""&&!S.some(n=>n.model===x)&&s.jsx("option",{value:x,children:x}),S.map(n=>s.jsxs("option",{value:n.model,children:[n.providerName," / ",n.model]},n.key))]})]}),q.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(h,{type:"button",variant:"ghost",size:"sm",onClick:()=>{b()},children:"Refresh"})]}),s.jsx("div",{className:"grid gap-1",children:q.map(n=>s.jsxs("button",{type:"button",onClick:()=>$(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?"-":C(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:m.valid?"text-xs text-emerald-500":"text-xs text-destructive",children:m.message}),s.jsxs(h,{type:"button",variant:"outline",size:"sm",onClick:X,disabled:!m.valid,title:"Format JSON",children:[s.jsx(he,{className:"size-3.5"}),"Format"]}),s.jsxs(h,{type:"button",variant:"outline",size:"sm",onClick:Y,disabled:!m.valid,title:"Compact JSON",children:[s.jsx(ye,{className:"size-3.5"}),"Compact"]}),s.jsxs(h,{type:"button",variant:"ghost",size:"sm",onClick:Z,title:"Reset to original request",children:[s.jsx(z,{className:"size-3.5"}),"Reset"]})]})]}),s.jsx(oe,{children:s.jsxs(ie,{children:[s.jsx(de,{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=>y(n.target.value),spellCheck:!1})}),s.jsx(ue,{children:"Edit formatted JSON before re-sending to the provider"})]})})]}),R!==null&&R!==""&&s.jsx("div",{className:"text-sm text-destructive bg-destructive/10 px-3 py-2 rounded-md",children:R}),s.jsx("div",{className:"flex justify-end",children:s.jsx(h,{onClick:()=>{U()},disabled:B||!m.valid,children:B?"Replaying...":"Replay"})}),r!==null&&s.jsx(H,{comparisons:E.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(h,{type:"button",variant:"outline",size:"sm",onClick:()=>$(r.replayLogId??e.id),children:"Open saved log"})]}),r&&r.success&&s.jsxs(v,{defaultValue:"parsed",children:[s.jsxs(T,{children:[s.jsx(o,{value:"parsed",children:"Response"}),s.jsx(o,{value:"raw",children:"Raw Response"})]}),s.jsx(i,{value:"parsed",children:s.jsx(M,{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(i,{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(i,{value:"original",children:e.responseText!==null?s.jsxs(v,{defaultValue:"parsed",children:[s.jsxs(T,{children:[s.jsx(o,{value:"parsed",children:"Response"}),s.jsx(o,{value:"raw",children:"Raw Response"})]}),s.jsx(i,{value:"parsed",children:s.jsx(M,{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(i,{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(i,{value:"replay",children:(r.responseText??null)!==null?s.jsxs(v,{defaultValue:"parsed",children:[s.jsxs(T,{children:[s.jsx(o,{value:"parsed",children:"Response"}),s.jsx(o,{value:"raw",children:"Raw Response"})]}),s.jsx(i,{value:"parsed",children:s.jsx(M,{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(i,{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(i,{value:"compare",className:"space-y-3",children:[s.jsx(H,{comparisons:E}),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{Je as ReplayDialog};
@@ -1 +1 @@
1
- import{r as f,j as t}from"./main-B1kdhY98.js";import{c as B,u as F,I as V,f as c,t as q,b as p,v as J,w as Y,x as K,S as X,K as $,L as Q,N as Z,O as S,Q as ee,h as z}from"./ProxyViewerContainer-BxRaXhKR.js";const te=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 16v-4",key:"1dtifu"}],["path",{d:"M12 8h.01",key:"e9boi3"}]],se=B("info",te),re=.25,ne=5,oe=4,ae=6,ie=.25,le=.2,de=.2,ce=["system","user","assistant","tool","tools"],ue={system:"instructions",user:"user turns",assistant:"assistant turns",tool:"tool results",tools:"tool schemas"},me=[{value:"role",label:"By Role"},{value:"segment",label:"By Segment"}],xe={unknown:"bg-muted-foreground/50",ok:"bg-emerald-500/70",watch:"bg-amber-400/75",danger:"bg-red-500/80"},pe={unknown:"text-muted-foreground",ok:"text-emerald-400",watch:"text-amber-300",danger:"text-red-300"},fe={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"},he={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?`-${c(Math.abs(e))}`:c(e)}function A(e){return e.contextWindow.tokens===null?"Unknown":Z(e.contextWindow.tokens)}function ge(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 be(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(e){const s=he[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} | ~${c(e.reclaimableTokens)} tokens`}function ve({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]",fe[e.level]),"aria-label":`Context health ${E(e)}`,children:t.jsx("span",{className:"truncate",children:E(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 C(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 je(e){return[...e].filter(s=>s.role==="user"||s.role==="assistant"||s.role==="tool").sort((s,r)=>r.size-s.size)[0]??null}function Ne(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 ke(e){const s=e.reduce((r,n)=>r+n.repeatedTokens,0);return s>0?s:null}function we(e){return y(e,"user")+y(e,"assistant")+y(e,"tool")}function ye({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:ke(s.duplicateGroups),target:Ne(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 ~${c(n)} tokens (${h(l*100)}).`,action:"Disable unused tools or shorten verbose schema descriptions.",savingTokens:C(n,ie),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 ~${c(n)} tokens (${h(l*100)}).`,action:"Compress repeated policy text and move stable guidance into reusable memory.",savingTokens:C(n,le),target:I(r,"system")}}case"history-bloat":{const n=we(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:C(n,de),target:je(r)}}}}function Te({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(ye({diagnostic:n,intelligence:e,segments:s}))}),r}function Se({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",be(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 ~",c(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 Ce({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 ${c(e.outputReserveTokens)}`,u=e.largestRole,m=Te({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:ge(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",pe[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"}),u===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]",$[u.role])}),t.jsx("span",{className:"truncate text-foreground",children:u.label})]}),t.jsxs("div",{className:"truncate font-mono text-[11px] text-muted-foreground",children:[h(u.percent*100)," | ~",c(u.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",xe[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(S.watch*100)}%`}}),t.jsx("div",{"aria-hidden":"true",className:"absolute top-0 h-full w-px bg-red-200/80",style:{left:`${String(S.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(S.watch)," / Danger"," ",w(S.danger)]})]})]}),t.jsx(Se,{items:m,onSegmentActivate:r})]})}function P(e,s){return s.find(r=>r.path===e.path)??null}function $e({groups:e,segments:s,onSegmentActivate:r}){const[n,l]=f.useState(!1);if(e.length===0)return null;const u=e.slice(0,oe),m=e.length-u.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"," | ~",c(g)," repeated"]})]}),n&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"space-y-2",children:u.map((o,i)=>{const b=o.segments.slice(0,ae),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)," | ~",c(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} ~${c(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 Le(e){const s=[];for(const r of ce){const n=e.filter(o=>o.role===r);if(n.length===0)continue;const l=n.reduce((o,i)=>o+i.size,0),u=n.reduce((o,i)=>o+i.characters,0),m=Q[r],g=`${n.length} segment${n.length===1?"":"s"} grouped as ${ue[r]}`;s.push({role:r,label:m,size:l,characters:u,text:g,path:`role:${r}`})}return s}function Re(e){return[...e].sort((s,r)=>r.size-s.size).slice(0,ne)}function Oe({parsed:e,inputTokens:s,model:r=null,onSegmentActivate:n,segments:l}){const{providers:u}=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?[]:Le(o),[o]),T=f.useMemo(()=>o===null?[]:Re(o),[o]),d=f.useMemo(()=>o===null?null:V({segments:o,inputTokens:s,parsed:e,model:r,providers:u}),[s,r,e,u,o]),v=f.useMemo(()=>o===null||s===null||i===0?!1:Math.abs(s-i)/Math.max(s,i)>=re,[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 ${c(s)}`,W=d===null?"Limit unknown":`Limit ${A(d)}`,G=d===null?"Usage unknown":`${w(d.usagePercent)} used`;return t.jsx(q,{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(ve,{health:d.health})]}),t.jsxs("div",{className:p("mt-0.5 text-xs font-mono tabular-nums",j),children:["Estimated ~",c(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:me.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(se,{className:"size-3.5"})})}),t.jsx(K,{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(Ce,{intelligence:d,segments:o,onSegmentActivate:n}),d!==null&&t.jsx($e,{groups:d.duplicateGroups,segments:o,onSegmentActivate:n}),t.jsx(X,{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,_=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)," | ~",c(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:_},`${a.path}-${x}`):t.jsx("div",{className:"flex h-7 items-center gap-2 rounded px-1.5 text-xs text-muted-foreground",children:_},`${a.path}-${x}`)})})]})]})})}export{Oe as RequestAnatomy};
1
+ import{r as f,j as t}from"./main-CbRIHhJ5.js";import{c as B,u as F,I as V,f as c,t as q,b as p,v as J,w as Y,x as K,S as X,K as $,L as Q,N as Z,O as S,Q as ee,h as z}from"./ProxyViewerContainer-4dG0nLRp.js";const te=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 16v-4",key:"1dtifu"}],["path",{d:"M12 8h.01",key:"e9boi3"}]],se=B("info",te),re=.25,ne=5,oe=4,ae=6,ie=.25,le=.2,de=.2,ce=["system","user","assistant","tool","tools"],ue={system:"instructions",user:"user turns",assistant:"assistant turns",tool:"tool results",tools:"tool schemas"},me=[{value:"role",label:"By Role"},{value:"segment",label:"By Segment"}],xe={unknown:"bg-muted-foreground/50",ok:"bg-emerald-500/70",watch:"bg-amber-400/75",danger:"bg-red-500/80"},pe={unknown:"text-muted-foreground",ok:"text-emerald-400",watch:"text-amber-300",danger:"text-red-300"},fe={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"},he={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?`-${c(Math.abs(e))}`:c(e)}function A(e){return e.contextWindow.tokens===null?"Unknown":Z(e.contextWindow.tokens)}function ge(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 be(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(e){const s=he[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} | ~${c(e.reclaimableTokens)} tokens`}function ve({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]",fe[e.level]),"aria-label":`Context health ${E(e)}`,children:t.jsx("span",{className:"truncate",children:E(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 C(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 je(e){return[...e].filter(s=>s.role==="user"||s.role==="assistant"||s.role==="tool").sort((s,r)=>r.size-s.size)[0]??null}function Ne(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 ke(e){const s=e.reduce((r,n)=>r+n.repeatedTokens,0);return s>0?s:null}function we(e){return y(e,"user")+y(e,"assistant")+y(e,"tool")}function ye({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:ke(s.duplicateGroups),target:Ne(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 ~${c(n)} tokens (${h(l*100)}).`,action:"Disable unused tools or shorten verbose schema descriptions.",savingTokens:C(n,ie),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 ~${c(n)} tokens (${h(l*100)}).`,action:"Compress repeated policy text and move stable guidance into reusable memory.",savingTokens:C(n,le),target:I(r,"system")}}case"history-bloat":{const n=we(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:C(n,de),target:je(r)}}}}function Te({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(ye({diagnostic:n,intelligence:e,segments:s}))}),r}function Se({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",be(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 ~",c(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 Ce({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 ${c(e.outputReserveTokens)}`,u=e.largestRole,m=Te({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:ge(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",pe[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"}),u===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]",$[u.role])}),t.jsx("span",{className:"truncate text-foreground",children:u.label})]}),t.jsxs("div",{className:"truncate font-mono text-[11px] text-muted-foreground",children:[h(u.percent*100)," | ~",c(u.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",xe[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(S.watch*100)}%`}}),t.jsx("div",{"aria-hidden":"true",className:"absolute top-0 h-full w-px bg-red-200/80",style:{left:`${String(S.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(S.watch)," / Danger"," ",w(S.danger)]})]})]}),t.jsx(Se,{items:m,onSegmentActivate:r})]})}function P(e,s){return s.find(r=>r.path===e.path)??null}function $e({groups:e,segments:s,onSegmentActivate:r}){const[n,l]=f.useState(!1);if(e.length===0)return null;const u=e.slice(0,oe),m=e.length-u.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"," | ~",c(g)," repeated"]})]}),n&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"space-y-2",children:u.map((o,i)=>{const b=o.segments.slice(0,ae),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)," | ~",c(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} ~${c(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 Le(e){const s=[];for(const r of ce){const n=e.filter(o=>o.role===r);if(n.length===0)continue;const l=n.reduce((o,i)=>o+i.size,0),u=n.reduce((o,i)=>o+i.characters,0),m=Q[r],g=`${n.length} segment${n.length===1?"":"s"} grouped as ${ue[r]}`;s.push({role:r,label:m,size:l,characters:u,text:g,path:`role:${r}`})}return s}function Re(e){return[...e].sort((s,r)=>r.size-s.size).slice(0,ne)}function Oe({parsed:e,inputTokens:s,model:r=null,onSegmentActivate:n,segments:l}){const{providers:u}=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?[]:Le(o),[o]),T=f.useMemo(()=>o===null?[]:Re(o),[o]),d=f.useMemo(()=>o===null?null:V({segments:o,inputTokens:s,parsed:e,model:r,providers:u}),[s,r,e,u,o]),v=f.useMemo(()=>o===null||s===null||i===0?!1:Math.abs(s-i)/Math.max(s,i)>=re,[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 ${c(s)}`,W=d===null?"Limit unknown":`Limit ${A(d)}`,G=d===null?"Usage unknown":`${w(d.usagePercent)} used`;return t.jsx(q,{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(ve,{health:d.health})]}),t.jsxs("div",{className:p("mt-0.5 text-xs font-mono tabular-nums",j),children:["Estimated ~",c(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:me.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(se,{className:"size-3.5"})})}),t.jsx(K,{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(Ce,{intelligence:d,segments:o,onSegmentActivate:n}),d!==null&&t.jsx($e,{groups:d.duplicateGroups,segments:o,onSegmentActivate:n}),t.jsx(X,{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,_=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)," | ~",c(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:_},`${a.path}-${x}`):t.jsx("div",{className:"flex h-7 items-center gap-2 rounded px-1.5 text-xs text-muted-foreground",children:_},`${a.path}-${x}`)})})]})]})})}export{Oe as RequestAnatomy};
@@ -1 +1 @@
1
- import{r as o,j as e}from"./main-B1kdhY98.js";import{c as F,U as G,V as K,b as E,W as h,Y as f,Z as L,B as m,Q as g,h as j,_ as N,$ as y,a0 as R,a1 as z,a2 as S,a3 as k,f as l,g as M,a4 as D,a5 as H}from"./ProxyViewerContainer-BxRaXhKR.js";const P=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["rect",{x:"9",y:"9",width:"6",height:"6",rx:"1",key:"1ssd4o"}]],O=F("circle-stop",P);var U="Separator",w="horizontal",J=["horizontal","vertical"],C=o.forwardRef((n,t)=>{const{decorative:a,orientation:s=w,...r}=n,i=W(s)?s:w,d=a?{role:"none"}:{"aria-orientation":i==="vertical"?i:void 0,role:"separator"};return e.jsx(G.div,{"data-orientation":i,...d,...r,ref:t})});C.displayName=U;function W(n){return J.includes(n)}var $=C;const X="prose prose-sm dark:prose-invert max-w-none text-[13px] leading-[1.65] [&_pre]:bg-muted [&_pre]:text-foreground [&_code]:text-[0.8em] [&_p]:my-1 [&_p]:leading-[1.65] [&_ul]:my-1 [&_ol]:my-1 [&_li]:my-0.5 [&_li]:leading-[1.6]";function v({text:n}){return e.jsx("div",{className:X,children:e.jsx(K,{children:n})})}function V({className:n,orientation:t="horizontal",decorative:a=!0,...s}){return e.jsx($,{"data-slot":"separator",decorative:a,orientation:t,className:E("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),...s})}const Z=/<think>([\s\S]*?)<\/think>/gi,Q=/<think>([\s\S]*?)<\/think>/i;function B(n){const t=Q.exec(n);if(!t||t[1]===void 0)return{thinking:null,remainingText:n};const a=t[1].trim(),s=n.replace(Z,"").trim();return{thinking:a,remainingText:s}}function Y(n){return e.jsx(e.Fragment,{})}function q({text:n}){const[t,a]=o.useState(!1);return e.jsxs(h,{open:t,onOpenChange:a,children:[e.jsxs(f,{className:"flex items-center gap-1.5 py-0.5 cursor-pointer hover:opacity-80 transition-opacity group",children:[t?e.jsx(g,{className:"size-3 text-muted-foreground"}):e.jsx(j,{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(N,{children:e.jsx("div",{className:"pl-4 pt-1",children:e.jsx(v,{text:n})})})]})}const ee=o.memo(function({text:t}){if(t.includes("<system-reminder>"))return e.jsx(q,{text:t});const{thinking:a,remainingText:s}=B(t);return e.jsxs("div",{className:"space-y-2",children:[a!==null&&e.jsx(p,{thinking:a}),s.length>0&&e.jsx(v,{text:s}),a===null&&s.length===0&&e.jsx("p",{className:"text-xs text-muted-foreground italic",children:"Empty text block"})]})}),p=o.memo(function({thinking:t}){const[a,s]=o.useState(!1);return e.jsx(h,{open:a,onOpenChange:s,children:e.jsxs("div",{className:"border-l-2 border-purple-500/40 my-1",children:[e.jsxs(f,{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(L,{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"}),a?e.jsx(g,{className:"size-3 text-muted-foreground"}):e.jsx(j,{className:"size-3 text-muted-foreground"})]}),e.jsx(N,{children:e.jsx("div",{className:"px-3 pb-2",children:e.jsx(y,{className:"max-h-[60vh]",children:e.jsx("pre",{className:"text-xs text-muted-foreground whitespace-pre-wrap font-mono leading-relaxed",children:t})})})})]})})}),te=o.memo(function({name:t,input:a}){const[s,r]=o.useState(!1);return e.jsx(h,{open:s,onOpenChange:r,children:e.jsxs("div",{className:"border-l-2 border-sky-400/25 my-1",children:[e.jsxs(f,{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",children:[e.jsx(R,{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"}),s?e.jsx(g,{className:"size-3 text-muted-foreground"}):e.jsx(j,{className:"size-3 text-muted-foreground"})]}),e.jsx(N,{children:e.jsx("div",{className:"px-3 pb-2",children:e.jsx(y,{className:"max-h-[60vh]",children:e.jsx(z,{data:S(a),defaultExpandDepth:0})})})})]})})}),ne=o.memo(function({block:t}){switch(t.type){case"text":return e.jsx(ee,{text:t.text});case"thinking":case"think":return e.jsx(p,{thinking:t.thinking});case"tool_use":return e.jsx(te,{name:t.name,input:t.input});default:return Y()}}),se=o.memo(function({response:t}){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(O,{className:"size-2.5"}),t.stop_reason]}),e.jsxs("span",{className:"flex items-center gap-1 text-muted-foreground text-xs",children:[e.jsx(k,{className:"size-3"}),e.jsxs("span",{className:"font-mono tabular-nums",children:[l(t.usage.input_tokens??0)," in /"," ",l(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 +",l(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 ~",l(t.usage.cache_read_input_tokens)]})]})]}),e.jsx(V,{className:"opacity-50"}),e.jsxs("div",{className:"space-y-2",children:[t.content.map((a,s)=>e.jsx(ne,{block:a},s)),t.content.length===0&&e.jsx("p",{className:"text-xs text-muted-foreground italic",children:"Empty response content"})]})]})});function ae(n){if(n===void 0||n==="")return{};try{return JSON.parse(n)}catch{return null}}function re({call:n}){const[t,a]=o.useState(!1),s=n.function.name??"(unnamed tool)",r=ae(n.function.arguments);return e.jsx(h,{open:t,onOpenChange:a,children:e.jsxs("div",{className:"border-l-2 border-sky-400/25 my-1",children:[e.jsxs(f,{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",children:[e.jsx(R,{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:s}),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"}),t?e.jsx(g,{className:"size-3 text-muted-foreground"}):e.jsx(j,{className:"size-3 text-muted-foreground"})]}),e.jsx(N,{children:e.jsx("div",{className:"px-3 pb-2",children:e.jsx(y,{className:"max-h-[60vh]",children:r===null?e.jsx("pre",{className:"font-mono text-xs whitespace-pre-wrap break-words text-rose-300/90",children:n.function.arguments}):e.jsx(z,{data:S(r),defaultExpandDepth:0})})})})]})})}const oe=o.memo(function({response:t}){const a=t.choices[0],s=a?.message,r=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}),a?.finish_reason!==null&&a?.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(O,{className:"size-2.5"}),a.finish_reason]}),e.jsxs("span",{className:"flex items-center gap-1 text-muted-foreground text-xs",children:[e.jsx(k,{className:"size-3"}),e.jsxs("span",{className:"font-mono tabular-nums",children:[l(t.usage.prompt_tokens??0)," in /"," ",l(t.usage.completion_tokens??0)," out"]})]})]}),e.jsx(V,{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(p,{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:c,remainingText:d}=B(s.content);return e.jsxs("div",{className:"space-y-2",children:[c!==null&&!i&&e.jsx(p,{thinking:c}),d.length>0&&e.jsx(v,{text:d})]})})(),r.map((i,c)=>e.jsx(re,{call:i},i.id??`tc-${c}`)),s?.function_call!==null&&s?.function_call!==void 0&&e.jsxs("div",{className:"border border-sky-400/20 rounded-md p-3 bg-muted/20",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:s.function_call.name}),e.jsxs("span",{className:"text-muted-foreground",children:["(",s.function_call.arguments,")"]})]})]}),(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)&&r.length===0&&e.jsx("p",{className:"text-xs text-muted-foreground italic",children:"Empty response content"})]})]})});function T(n){return typeof n=="object"&&n!==null&&!Array.isArray(n)}function ie(n){return T(n)&&n.object==="chat.completion"}function ce(n){return T(n)&&n.type==="message"&&Array.isArray(n.content)}function le(n,t){return n==="openai"&&ie(t)?e.jsx(oe,{response:t}):n==="anthropic"&&ce(t)?e.jsx(se,{response:t}):null}function de(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 u({status:n}){const t=H(n),a=de(t);return n===null?e.jsx("span",{className:"text-xs text-muted-foreground italic",children:"pending"}):e.jsxs("span",{className:E("flex items-center gap-1 text-xs font-mono font-semibold",a),children:[t==="server_error"&&e.jsx(D,{className:"size-3"}),n]})}function A({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 xe({text:n}){return e.jsx(v,{text:n})}const he=o.memo(function({responseText:t,responseStatus:a,streaming:s,inputTokens:r,outputTokens:i,cacheCreationInputTokens:c,cacheReadInputTokens:d,apiFormat:I,error:x}){const _=I??"unknown",b=o.useMemo(()=>M(_).analyzeResponse(t).parsed,[_,t]);return t===null&&x===void 0?e.jsxs("div",{className:"flex items-center gap-2 py-3",children:[e.jsx(u,{status:a}),e.jsx("span",{className:"text-xs text-muted-foreground italic",children:"No response"})]}):a!==null&&a>=400?e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{status:a}),e.jsx(A,{text:t??""}),x!=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:x})]})]}):x!=null?e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{status:a}),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:x})]}),t!==null&&e.jsx("div",{className:"mt-2",children:e.jsx(A,{text:t})})]}):b!==null?e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{status:a}),le(_,b)]}):e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(u,{status:a}),s&&(r!==null||i!==null)&&e.jsxs("span",{className:"flex items-center gap-1 text-muted-foreground text-xs",children:[e.jsx(k,{className:"size-3"}),e.jsxs("span",{className:"font-mono tabular-nums",children:[r!==null?l(r):"—"," in /"," ",i!==null?l(i):"—"," out"]}),c!=null&&c>0&&e.jsxs("span",{className:"font-mono tabular-nums text-emerald-400",children:["KV Cache +",l(c)]}),d!=null&&d>0&&e.jsxs("span",{className:"font-mono tabular-nums text-purple-400",children:["KV Cache ~",l(d)]})]})]}),e.jsx(xe,{text:t??""})]})});export{he as ResponseView};
1
+ import{r as o,j as e}from"./main-CbRIHhJ5.js";import{c as F,U as G,V as K,b as E,W as h,Y as f,Z as L,B as m,Q as g,h as j,_ as N,$ as y,a0 as R,a1 as z,a2 as S,a3 as k,f as l,g as M,a4 as D,a5 as H}from"./ProxyViewerContainer-4dG0nLRp.js";const P=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["rect",{x:"9",y:"9",width:"6",height:"6",rx:"1",key:"1ssd4o"}]],O=F("circle-stop",P);var U="Separator",w="horizontal",J=["horizontal","vertical"],C=o.forwardRef((n,t)=>{const{decorative:a,orientation:s=w,...r}=n,i=W(s)?s:w,d=a?{role:"none"}:{"aria-orientation":i==="vertical"?i:void 0,role:"separator"};return e.jsx(G.div,{"data-orientation":i,...d,...r,ref:t})});C.displayName=U;function W(n){return J.includes(n)}var $=C;const X="prose prose-sm dark:prose-invert max-w-none text-[13px] leading-[1.65] [&_pre]:bg-muted [&_pre]:text-foreground [&_code]:text-[0.8em] [&_p]:my-1 [&_p]:leading-[1.65] [&_ul]:my-1 [&_ol]:my-1 [&_li]:my-0.5 [&_li]:leading-[1.6]";function v({text:n}){return e.jsx("div",{className:X,children:e.jsx(K,{children:n})})}function V({className:n,orientation:t="horizontal",decorative:a=!0,...s}){return e.jsx($,{"data-slot":"separator",decorative:a,orientation:t,className:E("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),...s})}const Z=/<think>([\s\S]*?)<\/think>/gi,Q=/<think>([\s\S]*?)<\/think>/i;function B(n){const t=Q.exec(n);if(!t||t[1]===void 0)return{thinking:null,remainingText:n};const a=t[1].trim(),s=n.replace(Z,"").trim();return{thinking:a,remainingText:s}}function Y(n){return e.jsx(e.Fragment,{})}function q({text:n}){const[t,a]=o.useState(!1);return e.jsxs(h,{open:t,onOpenChange:a,children:[e.jsxs(f,{className:"flex items-center gap-1.5 py-0.5 cursor-pointer hover:opacity-80 transition-opacity group",children:[t?e.jsx(g,{className:"size-3 text-muted-foreground"}):e.jsx(j,{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(N,{children:e.jsx("div",{className:"pl-4 pt-1",children:e.jsx(v,{text:n})})})]})}const ee=o.memo(function({text:t}){if(t.includes("<system-reminder>"))return e.jsx(q,{text:t});const{thinking:a,remainingText:s}=B(t);return e.jsxs("div",{className:"space-y-2",children:[a!==null&&e.jsx(p,{thinking:a}),s.length>0&&e.jsx(v,{text:s}),a===null&&s.length===0&&e.jsx("p",{className:"text-xs text-muted-foreground italic",children:"Empty text block"})]})}),p=o.memo(function({thinking:t}){const[a,s]=o.useState(!1);return e.jsx(h,{open:a,onOpenChange:s,children:e.jsxs("div",{className:"border-l-2 border-purple-500/40 my-1",children:[e.jsxs(f,{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(L,{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"}),a?e.jsx(g,{className:"size-3 text-muted-foreground"}):e.jsx(j,{className:"size-3 text-muted-foreground"})]}),e.jsx(N,{children:e.jsx("div",{className:"px-3 pb-2",children:e.jsx(y,{className:"max-h-[60vh]",children:e.jsx("pre",{className:"text-xs text-muted-foreground whitespace-pre-wrap font-mono leading-relaxed",children:t})})})})]})})}),te=o.memo(function({name:t,input:a}){const[s,r]=o.useState(!1);return e.jsx(h,{open:s,onOpenChange:r,children:e.jsxs("div",{className:"border-l-2 border-sky-400/25 my-1",children:[e.jsxs(f,{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",children:[e.jsx(R,{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"}),s?e.jsx(g,{className:"size-3 text-muted-foreground"}):e.jsx(j,{className:"size-3 text-muted-foreground"})]}),e.jsx(N,{children:e.jsx("div",{className:"px-3 pb-2",children:e.jsx(y,{className:"max-h-[60vh]",children:e.jsx(z,{data:S(a),defaultExpandDepth:0})})})})]})})}),ne=o.memo(function({block:t}){switch(t.type){case"text":return e.jsx(ee,{text:t.text});case"thinking":case"think":return e.jsx(p,{thinking:t.thinking});case"tool_use":return e.jsx(te,{name:t.name,input:t.input});default:return Y()}}),se=o.memo(function({response:t}){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(O,{className:"size-2.5"}),t.stop_reason]}),e.jsxs("span",{className:"flex items-center gap-1 text-muted-foreground text-xs",children:[e.jsx(k,{className:"size-3"}),e.jsxs("span",{className:"font-mono tabular-nums",children:[l(t.usage.input_tokens??0)," in /"," ",l(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 +",l(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 ~",l(t.usage.cache_read_input_tokens)]})]})]}),e.jsx(V,{className:"opacity-50"}),e.jsxs("div",{className:"space-y-2",children:[t.content.map((a,s)=>e.jsx(ne,{block:a},s)),t.content.length===0&&e.jsx("p",{className:"text-xs text-muted-foreground italic",children:"Empty response content"})]})]})});function ae(n){if(n===void 0||n==="")return{};try{return JSON.parse(n)}catch{return null}}function re({call:n}){const[t,a]=o.useState(!1),s=n.function.name??"(unnamed tool)",r=ae(n.function.arguments);return e.jsx(h,{open:t,onOpenChange:a,children:e.jsxs("div",{className:"border-l-2 border-sky-400/25 my-1",children:[e.jsxs(f,{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",children:[e.jsx(R,{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:s}),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"}),t?e.jsx(g,{className:"size-3 text-muted-foreground"}):e.jsx(j,{className:"size-3 text-muted-foreground"})]}),e.jsx(N,{children:e.jsx("div",{className:"px-3 pb-2",children:e.jsx(y,{className:"max-h-[60vh]",children:r===null?e.jsx("pre",{className:"font-mono text-xs whitespace-pre-wrap break-words text-rose-300/90",children:n.function.arguments}):e.jsx(z,{data:S(r),defaultExpandDepth:0})})})})]})})}const oe=o.memo(function({response:t}){const a=t.choices[0],s=a?.message,r=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}),a?.finish_reason!==null&&a?.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(O,{className:"size-2.5"}),a.finish_reason]}),e.jsxs("span",{className:"flex items-center gap-1 text-muted-foreground text-xs",children:[e.jsx(k,{className:"size-3"}),e.jsxs("span",{className:"font-mono tabular-nums",children:[l(t.usage.prompt_tokens??0)," in /"," ",l(t.usage.completion_tokens??0)," out"]})]})]}),e.jsx(V,{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(p,{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:c,remainingText:d}=B(s.content);return e.jsxs("div",{className:"space-y-2",children:[c!==null&&!i&&e.jsx(p,{thinking:c}),d.length>0&&e.jsx(v,{text:d})]})})(),r.map((i,c)=>e.jsx(re,{call:i},i.id??`tc-${c}`)),s?.function_call!==null&&s?.function_call!==void 0&&e.jsxs("div",{className:"border border-sky-400/20 rounded-md p-3 bg-muted/20",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:s.function_call.name}),e.jsxs("span",{className:"text-muted-foreground",children:["(",s.function_call.arguments,")"]})]})]}),(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)&&r.length===0&&e.jsx("p",{className:"text-xs text-muted-foreground italic",children:"Empty response content"})]})]})});function T(n){return typeof n=="object"&&n!==null&&!Array.isArray(n)}function ie(n){return T(n)&&n.object==="chat.completion"}function ce(n){return T(n)&&n.type==="message"&&Array.isArray(n.content)}function le(n,t){return n==="openai"&&ie(t)?e.jsx(oe,{response:t}):n==="anthropic"&&ce(t)?e.jsx(se,{response:t}):null}function de(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 u({status:n}){const t=H(n),a=de(t);return n===null?e.jsx("span",{className:"text-xs text-muted-foreground italic",children:"pending"}):e.jsxs("span",{className:E("flex items-center gap-1 text-xs font-mono font-semibold",a),children:[t==="server_error"&&e.jsx(D,{className:"size-3"}),n]})}function A({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 xe({text:n}){return e.jsx(v,{text:n})}const he=o.memo(function({responseText:t,responseStatus:a,streaming:s,inputTokens:r,outputTokens:i,cacheCreationInputTokens:c,cacheReadInputTokens:d,apiFormat:I,error:x}){const _=I??"unknown",b=o.useMemo(()=>M(_).analyzeResponse(t).parsed,[_,t]);return t===null&&x===void 0?e.jsxs("div",{className:"flex items-center gap-2 py-3",children:[e.jsx(u,{status:a}),e.jsx("span",{className:"text-xs text-muted-foreground italic",children:"No response"})]}):a!==null&&a>=400?e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{status:a}),e.jsx(A,{text:t??""}),x!=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:x})]})]}):x!=null?e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{status:a}),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:x})]}),t!==null&&e.jsx("div",{className:"mt-2",children:e.jsx(A,{text:t})})]}):b!==null?e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{status:a}),le(_,b)]}):e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(u,{status:a}),s&&(r!==null||i!==null)&&e.jsxs("span",{className:"flex items-center gap-1 text-muted-foreground text-xs",children:[e.jsx(k,{className:"size-3"}),e.jsxs("span",{className:"font-mono tabular-nums",children:[r!==null?l(r):"—"," in /"," ",i!==null?l(i):"—"," out"]}),c!=null&&c>0&&e.jsxs("span",{className:"font-mono tabular-nums text-emerald-400",children:["KV Cache +",l(c)]}),d!=null&&d>0&&e.jsxs("span",{className:"font-mono tabular-nums text-purple-400",children:["KV Cache ~",l(d)]})]})]}),e.jsx(xe,{text:t??""})]})});export{he as ResponseView};
@@ -1 +1 @@
1
- import{r as a,j as e}from"./main-B1kdhY98.js";import{t as j,v,w as b,Q as l,h as u,B as N,x as k,a6 as S,a1 as y}from"./ProxyViewerContainer-BxRaXhKR.js";const z=a.memo(function({logId:d,truncated:x}){const[o,m]=a.useState(!1),[r,i]=a.useState({status:"idle"}),[h,p]=a.useState(new Set);a.useEffect(()=>{if(!o||r.status!=="idle")return;let s=!1;return i({status:"loading"}),fetch(`/api/logs/${d}/chunks`).then(t=>t.ok?t.json():Promise.reject(new Error("Chunks not found"))).then(t=>{s||i({status:"success",chunks:t.chunks})}).catch(()=>{s||i({status:"error",message:"Chunk data unavailable"})}),()=>{s=!0}},[o,d]);const c=a.useMemo(()=>{if(r.status!=="success")return[];const s=new Map;for(const t of r.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)},[r]),f=s=>{p(t=>{const n=new Set(t);return n.has(s)?n.delete(s):n.add(s),n})};function g(){return r.status==="idle"||r.status==="loading"?e.jsxs("div",{className:"flex items-center gap-2 py-2 text-xs text-muted-foreground",children:[e.jsx(S,{className:"size-3 animate-spin"}),e.jsx("span",{children:"Loading chunks..."})]}):r.status==="error"?e.jsx("div",{className:"py-2 text-xs text-muted-foreground italic",children:r.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:[c.length," index group",c.length!==1?"s":""," available"]}),c.map(s=>{const t=h.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:()=>f(s.index),children:[t?e.jsx(l,{className:"size-3 text-muted-foreground"}):e.jsx(u,{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(y,{data:n,defaultExpandDepth:0,showCopy:!0})]},n.index))})]},s.index)})]})}return e.jsxs("div",{className:"space-y-1",children:[e.jsx(j,{children:e.jsxs(v,{children:[e.jsx(b,{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:()=>m(s=>!s),children:[o?e.jsx(l,{className:"size-3"}):e.jsx(u,{className:"size-3"}),e.jsx("span",{children:"Raw SSE Events"}),e.jsxs(N,{variant:"outline",className:"text-[9px] px-1 py-0 h-4 font-mono ml-1",children:[d,x===!0?"+":""]})]})}),e.jsx(k,{children:"Server-Sent Events streaming chunks from the provider"})]})}),o===!0?e.jsx("div",{className:"rounded-md border border-border bg-muted/20 overflow-auto max-h-64",children:g()}):null]})});export{z as StreamingChunkSequence};
1
+ import{r as a,j as e}from"./main-CbRIHhJ5.js";import{t as j,v,w as b,Q as l,h as u,B as N,x as k,a6 as S,a1 as y}from"./ProxyViewerContainer-4dG0nLRp.js";const z=a.memo(function({logId:d,truncated:x}){const[o,m]=a.useState(!1),[r,i]=a.useState({status:"idle"}),[h,p]=a.useState(new Set);a.useEffect(()=>{if(!o||r.status!=="idle")return;let s=!1;return i({status:"loading"}),fetch(`/api/logs/${d}/chunks`).then(t=>t.ok?t.json():Promise.reject(new Error("Chunks not found"))).then(t=>{s||i({status:"success",chunks:t.chunks})}).catch(()=>{s||i({status:"error",message:"Chunk data unavailable"})}),()=>{s=!0}},[o,d]);const c=a.useMemo(()=>{if(r.status!=="success")return[];const s=new Map;for(const t of r.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)},[r]),f=s=>{p(t=>{const n=new Set(t);return n.has(s)?n.delete(s):n.add(s),n})};function g(){return r.status==="idle"||r.status==="loading"?e.jsxs("div",{className:"flex items-center gap-2 py-2 text-xs text-muted-foreground",children:[e.jsx(S,{className:"size-3 animate-spin"}),e.jsx("span",{children:"Loading chunks..."})]}):r.status==="error"?e.jsx("div",{className:"py-2 text-xs text-muted-foreground italic",children:r.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:[c.length," index group",c.length!==1?"s":""," available"]}),c.map(s=>{const t=h.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:()=>f(s.index),children:[t?e.jsx(l,{className:"size-3 text-muted-foreground"}):e.jsx(u,{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(y,{data:n,defaultExpandDepth:0,showCopy:!0})]},n.index))})]},s.index)})]})}return e.jsxs("div",{className:"space-y-1",children:[e.jsx(j,{children:e.jsxs(v,{children:[e.jsx(b,{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:()=>m(s=>!s),children:[o?e.jsx(l,{className:"size-3"}):e.jsx(u,{className:"size-3"}),e.jsx("span",{children:"Raw SSE Events"}),e.jsxs(N,{variant:"outline",className:"text-[9px] px-1 py-0 h-4 font-mono ml-1",children:[d,x===!0?"+":""]})]})}),e.jsx(k,{children:"Server-Sent Events streaming chunks from the provider"})]})}),o===!0?e.jsx("div",{className:"rounded-md border border-border bg-muted/20 overflow-auto max-h-64",children:g()}):null]})});export{z as StreamingChunkSequence};
@@ -0,0 +1 @@
1
+ import{R as s,j as e}from"./main-CbRIHhJ5.js";import{P as i}from"./ProxyViewerContainer-4dG0nLRp.js";function t(){const{sessionId:o}=s.useParams();return e.jsx(i,{initialSessionId:o},o)}export{t as component};
@@ -0,0 +1 @@
1
+ import{P as o}from"./ProxyViewerContainer-4dG0nLRp.js";import"./main-CbRIHhJ5.js";const r=o;export{r as component};