@chenpu17/cc-gw 0.8.19 → 0.8.20

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 (23) hide show
  1. package/package.json +5 -5
  2. package/src/web/dist/assets/{About-i7u6NHg9.js → About-E813AXIS.js} +1 -1
  3. package/src/web/dist/assets/{ApiKeys-Dor6MgN0.js → ApiKeys-CHoWjny5.js} +1 -1
  4. package/src/web/dist/assets/{ConfirmDialog-CPJRlYPi.js → ConfirmDialog-BuV2d3aQ.js} +1 -1
  5. package/src/web/dist/assets/{Dashboard-DgThbhmI.js → Dashboard-B0KXfDqB.js} +1 -1
  6. package/src/web/dist/assets/{Events-Bt9mPjdt.js → Events-CQ47M36I.js} +1 -1
  7. package/src/web/dist/assets/{Help-Cp7WK4jE.js → Help-DlkNELd-.js} +1 -1
  8. package/src/web/dist/assets/{Login-DdXAfpU_.js → Login-Cnx2XHdt.js} +1 -1
  9. package/src/web/dist/assets/{Logs-DOmV2017.js → Logs-MHwalvMS.js} +1 -1
  10. package/src/web/dist/assets/{ModelManagement-DestXjpI.js → ModelManagement-DBUODkXB.js} +1 -1
  11. package/src/web/dist/assets/{Profiler-CuJSuVJx.js → Profiler-C-LEcskT.js} +1 -1
  12. package/src/web/dist/assets/{RoutingManagement-DUYn00nU.js → RoutingManagement-CUzrRFdV.js} +1 -1
  13. package/src/web/dist/assets/{Settings-BXrnXhxH.js → Settings-kC8ItAD8.js} +1 -1
  14. package/src/web/dist/assets/{app-CSrXQQoX.js → app-BF0X4ljN.js} +2 -2
  15. package/src/web/dist/assets/{gateway-Du8IjjRN.js → gateway-Bo9FVYfn.js} +1 -1
  16. package/src/web/dist/assets/{landing-2m5QuvwF.js → landing-D5PpgO3n.js} +1 -1
  17. package/src/web/dist/assets/package-BeIzyZKv.js +1 -0
  18. package/src/web/dist/assets/{useApiQuery-CvFOQBkt.js → useApiQuery-DaxeBDln.js} +1 -1
  19. package/src/web/dist/assets/{useAppMutation-Db7I627Q.js → useAppMutation-C8scr-Sv.js} +1 -1
  20. package/src/web/dist/assets/{useModelManagementState-C-dnZNnf.js → useModelManagementState-B3Ht0eWY.js} +1 -1
  21. package/src/web/dist/index.html +1 -1
  22. package/src/web/dist/landing.html +2 -2
  23. package/src/web/dist/assets/package-jQyl_aXJ.js +0 -1
@@ -1 +1 @@
1
- import{r as b,j as t,a7 as Se,az as Ae,aO as je,aT as $e,W as Ee,aU as _e,O as Re,ag as qe,aD as Fe,a0 as Le,al as De}from"./vendor-DdPBfMMb.js";import{u as Pe,a as ae,b as X}from"./query-QCek5MsK.js";import{L as Oe}from"./router-D2Fb4U0L.js";import{P as Ke}from"./PageToolbar-CDzxx36L.js";import{P as ke,a as H}from"./PageState-C9j-dOzv.js";import{B as ie,q as $}from"./queryKeys-0HDa7byL.js";import{g as V,b as Z,r as de,B as O}from"./app-CSrXQQoX.js";import{c as y}from"./global-CsDL9Nt2.js";import{f as Be}from"./utils-RIyUChKi.js";import{u as D}from"./i18n-C8tBby0x.js";import"./radix-CtQBp6Ie.js";const L={getStatus:()=>de({url:"/api/profiler/status",method:"GET"}),start:()=>V(Z.post("/api/profiler/start")),stop:()=>V(Z.post("/api/profiler/stop")),listSessions:e=>de({url:"/api/profiler/sessions",method:"GET",params:e}),getSession:e=>de({url:`/api/profiler/sessions/${e}`,method:"GET"}),deleteSession:e=>V(Z.delete(`/api/profiler/sessions/${e}`)),clearAll:()=>V(Z.post("/api/profiler/sessions/clear"))};function Q(e){if(!e)return null;try{return JSON.parse(e)}catch{return null}}function k(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function C(e,s){return e.length<=s?e:e.slice(0,s-1)+"…"}function Ce(e){if(typeof e=="string")return e;if(Array.isArray(e)){for(const s of e)if(k(s)&&s.type==="text"&&typeof s.text=="string")return s.text}return""}function He(e){if(!k(e))return"";const s=Object.entries(e);if(!s.length)return"";const[n,r]=s[0],o=typeof r=="string"?`"${C(r,60)}"`:String(r);return`${n}: ${o}`}function Je(e){if(typeof e=="string")return C(e,120);if(Array.isArray(e)){for(const s of e)if(k(s)&&s.type==="text"&&typeof s.text=="string")return C(s.text,120);return C(JSON.stringify(e),120)}return k(e)?C(JSON.stringify(e),120):""}function ce(e,s){if(k(s)&&Array.isArray(s.choices))return"openai";if(k(s)&&Array.isArray(s.content))return"anthropic";if(k(e)&&Array.isArray(e.messages)){for(const n of e.messages)if(k(n)&&n.role==="tool")return"openai";return"anthropic"}return"unknown"}function Ne(e,s){var n;if(s==="openai"){if(!k(e)||!Array.isArray(e.choices))return[];const r=(n=e.choices[0])==null?void 0:n.message;return!k(r)||!Array.isArray(r.tool_calls)?[]:r.tool_calls.filter(o=>o.id&&k(o.function)&&o.function.name).map(o=>{const l=o.function;let a={};try{a=JSON.parse(String(l.arguments??"{}"))}catch{}return{id:String(o.id),name:String(l.name),input:a}})}return!k(e)||!Array.isArray(e.content)?[]:e.content.filter(r=>r.type==="tool_use"&&r.id&&r.name).map(r=>({id:String(r.id),name:String(r.name),input:r.input}))}function We(e,s){if(!k(e)||!Array.isArray(e.messages))return[];const n=e.messages;if(s==="openai")return n.filter(o=>o.role==="tool"&&o.tool_call_id).map(o=>({toolCallId:String(o.tool_call_id),content:o.content,isError:!1}));const r=[];for(const o of n)if(!(o.role!=="user"||!Array.isArray(o.content)))for(const l of o.content)l.type==="tool_result"&&l.tool_use_id&&r.push({toolCallId:String(l.tool_use_id),content:l.content,isError:l.is_error===!0});return r}function Qe(e,s){if(!k(e)||!Array.isArray(e.messages))return{messageKind:"unknown",messageExcerpt:""};const n=e.messages.filter(o=>o.role!=="system");if(!n.length)return{messageKind:"unknown",messageExcerpt:""};const r=n[n.length-1];if(s==="openai"){if(r.role==="tool"){const o=n.filter(l=>l.role==="tool").length;return{messageKind:"tool-results",messageExcerpt:`${o} tool result${o!==1?"s":""}`}}return r.role==="user"?{messageKind:"user",messageExcerpt:C(String(r.content??""),80)}:{messageKind:"unknown",messageExcerpt:""}}if(r.role==="user"){if(Array.isArray(r.content)){const o=r.content,l=o.some(i=>i.type==="tool_result"),a=o.some(i=>i.type==="text");if(l&&a)return{messageKind:"mixed",messageExcerpt:""};if(l){const i=o.filter(f=>f.type==="tool_result").length;return{messageKind:"tool-results",messageExcerpt:`${i} tool result${i!==1?"s":""}`}}return{messageKind:"user",messageExcerpt:C(Ce(r.content),80)}}return{messageKind:"user",messageExcerpt:C(String(r.content??""),80)}}return{messageKind:"unknown",messageExcerpt:""}}function Ue(e,s){var r;if(s==="openai"){if(!k(e)||!Array.isArray(e.choices))return null;const o=(r=e.choices[0])==null?void 0:r.message;if(!k(o))return null;const l=String(o.content??"");return l?C(l,80):null}if(!k(e))return null;const n=Ce(e.content);return n?C(n,80):null}function Ge(e,s){var n;if(!k(e))return null;if(s==="anthropic")return typeof e.stop_reason=="string"?e.stop_reason:null;if(s==="openai"){const r=(n=e.choices)==null?void 0:n[0];if(k(r))return typeof r.finish_reason=="string"?r.finish_reason:null}return null}function ze(e,s){return k(e)?s==="anthropic"?e.content??null:s==="openai"?e.choices??null:null:null}function Ye(e){const{records:s,startedAt:n}=e;if(!s.length)return{lanes:[],turns:[],sessionDurationMs:0,totalToolCalls:0,uniqueToolNames:[]};const r=[...s].sort((m,c)=>m.turnIndex-c.turnIndex),o=[],l=new Set;for(const m of r){const c=Q(m.clientResponse),d=Q(m.clientRequest);for(const u of Ne(c,ce(d,c)))l.has(u.name)||(l.add(u.name),o.push(u.name))}const i=[{id:"agent",label:(()=>{switch(r[0].clientKind){case"claude-code":return"Claude Code";case"codex":return"Codex";case"opencode":return"OpenCode";default:return"Agent"}})()},{id:"llm",label:"LLM",sublabel:C(r[0].model??"",32)||void 0},{id:"tools",label:"Tools",sublabel:o.length?`${o.length} tool${o.length!==1?"s":""}`:void 0}];let f=0;const j=[];for(let m=0;m<r.length;m++){const c=r[m],d=r[m+1],u=Q(c.clientRequest),N=Q(c.clientResponse),p=ce(u,N),M=c.timestamp-n,_=M+(c.latencyMs??0),S=[],{messageKind:G,messageExcerpt:le}=Qe(u,p);S.push({kind:"request",id:`t${c.turnIndex}-req`,turnIndex:c.turnIndex,messageKind:G,messageExcerpt:le,inputTokens:c.inputTokens,rawMessages:k(u)?u.messages:null});const A=Ne(N,p);S.push({kind:"response",id:`t${c.turnIndex}-res`,turnIndex:c.turnIndex,textExcerpt:Ue(N,p),toolUseCount:A.length,stopReason:Ge(N,p),outputTokens:c.outputTokens,latencyMs:c.latencyMs,ttftMs:c.ttftMs,rawContent:ze(N,p)}),c.error&&S.push({kind:"error",id:`t${c.turnIndex}-err`,turnIndex:c.turnIndex,message:c.error,statusCode:c.statusCode});const P=d?Q(d.clientRequest):null,h=d?ce(P,null):"unknown",W=d?We(P,h):[],z=new Map(W.map(T=>[T.toolCallId,T])),Y=(d==null?void 0:d.latencyMs)??null;for(const T of A){S.push({kind:"tool-invoke",id:`t${c.turnIndex}-invoke-${T.id}`,turnIndex:c.turnIndex,toolName:T.name,toolCallId:T.id,inputPreview:He(T.input),rawInput:T.input}),f++;const q=z.get(T.id);q&&S.push({kind:"tool-result",id:`t${c.turnIndex}-result-${T.id}`,turnIndex:c.turnIndex,toolName:T.name,toolCallId:T.id,resultPreview:Je(q.content),isError:q.isError,rawResult:q.content,durationMs:Y})}j.push({index:c.turnIndex,events:S,startOffsetMs:M,endOffsetMs:_,inputTokens:c.inputTokens,outputTokens:c.outputTokens,latencyMs:c.latencyMs,ttftMs:c.ttftMs,hasError:!!c.error,toolCallCount:A.length})}const v=r[r.length-1],x=(e.endedAt??v.timestamp+(v.latencyMs??0))-n;return{lanes:i,turns:j,sessionDurationMs:x,totalToolCalls:f,uniqueToolNames:o}}const U=64,ve=28,te=56,Xe=12,se=24,we=640;function R(e){return e==null?"–":e>=1e3?`${(e/1e3).toFixed(2)}s`:`${Math.round(e)}ms`}function Te(e){return e==null?"":e.toLocaleString()}function K(e,s){return e.length<=s?e:e.slice(0,s-1)+"…"}function Ve(e,s){const r=Math.max(s-se*2,200)/(e.length-1||1);return e.map((o,l)=>({id:o.id,label:o.label,sublabel:o.sublabel,x:se+r*l}))}function Ze(e){const s=[];let n=U;for(const r of e.turns){const o=n+ve/2;n+=ve;const l=r.events.map(a=>{const i=n+te/2;return n+=te,{turnIndex:r.index,y:i,event:a}});n+=Xe,s.push({turn:r,headerY:o,endY:n,rows:l})}return{turns:s,totalHeight:n+12}}function et(e){switch(e.kind){case"request":{const s=e.messageKind==="tool-results"?"tool results":e.messageKind==="mixed"?"mixed":e.messageKind==="user"?"user":"request",n=e.messageExcerpt?`${s}: ${K(e.messageExcerpt,80)}`:s,r=e.inputTokens!=null?`↑ ${Te(e.inputTokens)} tok`:void 0;return{src:"agent",tgt:"llm",label:n,sublabel:r,style:"solid",tone:"request"}}case"response":{const s=[];e.textExcerpt&&s.push(`"${K(e.textExcerpt,60)}"`),e.toolUseCount>0&&s.push(`${e.toolUseCount} tool_use`),e.stopReason&&s.push(e.stopReason);const n=s.join(" · ")||"(empty)",r=[];return e.outputTokens!=null&&r.push(`↓ ${Te(e.outputTokens)} tok`),e.ttftMs!=null&&r.push(`TTFT ${R(e.ttftMs)}`),e.latencyMs!=null&&r.push(R(e.latencyMs)),{src:"llm",tgt:"agent",label:n,sublabel:r.join(" · ")||void 0,style:"dashed",tone:"response"}}case"tool-invoke":return{src:"agent",tgt:"tools",label:e.inputPreview?`${e.toolName}(${K(e.inputPreview,80)})`:`${e.toolName}()`,style:"solid",tone:"invoke"};case"tool-result":{const s=e.isError?`error: ${K(e.resultPreview||"error",80)}`:K(e.resultPreview||"(empty)",100),n=e.durationMs!=null?R(e.durationMs):void 0;return{src:"tools",tgt:"agent",label:s,sublabel:n,style:"dashed",tone:e.isError?"error":"result",isError:e.isError}}case"error":return{src:"llm",tgt:"agent",label:`${e.statusCode??"ERR"} · ${K(e.message,100)}`,style:"dashed",tone:"error"}}}const fe={request:{stroke:"stroke-indigo-500",fill:"fill-indigo-500",text:"fill-indigo-700 dark:fill-indigo-300"},response:{stroke:"stroke-violet-500",fill:"fill-violet-500",text:"fill-violet-700 dark:fill-violet-300",activation:"fill-violet-400/40 dark:fill-violet-500/30"},invoke:{stroke:"stroke-amber-500",fill:"fill-amber-500",text:"fill-amber-700 dark:fill-amber-300"},result:{stroke:"stroke-emerald-500",fill:"fill-emerald-500",text:"fill-emerald-700 dark:fill-emerald-300",activation:"fill-emerald-400/40 dark:fill-emerald-500/25"},error:{stroke:"stroke-rose-500",fill:"fill-rose-500",text:"fill-rose-700 dark:fill-rose-300"}};function tt(e){const s=[];for(const n of e){let r=null;const o=new Map;for(const l of n.rows){const a=l.event;if(a.kind==="request")r=l.y;else if(a.kind==="response"&&r!=null)s.push({laneId:"llm",y1:r,y2:l.y,tone:"response"}),r=null;else if(a.kind==="tool-invoke")o.set(a.toolCallId,l.y);else if(a.kind==="tool-result"){const i=o.get(a.toolCallId);i!=null&&(s.push({laneId:"tools",y1:i,y2:l.y,tone:"result"}),o.delete(a.toolCallId))}}}return s}function st({y:e,arrow:s,laneByX:n,active:r,onClick:o,eventId:l}){const a=n[s.src],i=n[s.tgt],f=fe[s.tone],j=i>a?1:-1,v=6,x=a,m=i-j*v,c=(a+i)/2,d=e-8,u=e+16;return t.jsxs("g",{"data-event-id":l,className:"cursor-pointer",onClick:o,children:[t.jsx("rect",{x:Math.min(a,i)-12,y:e-te/2+2,width:Math.abs(i-a)+24,height:te-4,className:y("transition-colors",r?"fill-foreground/[0.06]":"fill-transparent hover:fill-foreground/[0.04]"),rx:6}),t.jsx("line",{x1:x,y1:e,x2:m,y2:e,className:y(f.stroke,"pointer-events-none"),strokeWidth:1.6,strokeDasharray:s.style==="dashed"?"5 4":void 0}),t.jsx("polygon",{points:`${i},${e} ${i-j*7},${e-4} ${i-j*7},${e+4}`,className:y(f.fill,"pointer-events-none")}),t.jsx("text",{x:c,y:d,textAnchor:"middle",className:y("pointer-events-none select-none text-[11px] font-medium",f.text),children:s.label}),s.sublabel&&t.jsx("text",{x:c,y:u,textAnchor:"middle",className:"pointer-events-none select-none fill-muted-foreground text-[10px]",children:s.sublabel})]})}function rt({lane:e}){var f;const s=e.id==="agent"?"fill-indigo-700 dark:fill-indigo-300":e.id==="llm"?"fill-violet-700 dark:fill-violet-300":"fill-amber-700 dark:fill-amber-300",n=e.id==="agent"?"fill-indigo-50 dark:fill-indigo-500/10":e.id==="llm"?"fill-violet-50 dark:fill-violet-500/10":"fill-amber-50 dark:fill-amber-500/10",r=e.id==="agent"?"stroke-indigo-300 dark:stroke-indigo-500/40":e.id==="llm"?"stroke-violet-300 dark:stroke-violet-500/40":"stroke-amber-300 dark:stroke-amber-500/40",o=14,l=Math.max(e.label.length,((f=e.sublabel)==null?void 0:f.length)??0),a=Math.max(96,l*7+o*2),i=e.sublabel?44:28;return t.jsxs("g",{children:[t.jsx("rect",{x:e.x-a/2,y:10,width:a,height:i,rx:6,className:y(n,r),strokeWidth:1}),t.jsx("text",{x:e.x,y:e.sublabel?24:28,textAnchor:"middle",className:y("select-none text-[12px] font-semibold",s),children:e.label}),e.sublabel&&t.jsx("text",{x:e.x,y:40,textAnchor:"middle",className:"select-none fill-muted-foreground text-[10px]",children:e.sublabel})]})}function ee({data:e}){return e==null?t.jsx("span",{className:"text-muted-foreground",children:"(empty)"}):t.jsx("pre",{className:"overflow-auto rounded bg-muted/60 p-3 text-[11px] leading-relaxed text-foreground",children:JSON.stringify(e,null,2)})}function w({label:e,value:s}){return t.jsxs("div",{className:"flex items-center justify-between text-xs",children:[t.jsx("span",{className:"text-muted-foreground",children:e}),t.jsx("span",{className:"font-medium tabular-nums",children:s})]})}function I({title:e,children:s}){return t.jsxs("div",{className:"space-y-1.5",children:[t.jsx("h4",{className:"text-[11px] font-semibold uppercase tracking-wide text-muted-foreground",children:e}),s]})}const nt={request:{label:"Request",classes:"bg-indigo-50 text-indigo-700 border-indigo-200 dark:bg-indigo-500/15 dark:text-indigo-300 dark:border-indigo-500/30"},response:{label:"Response",classes:"bg-violet-50 text-violet-700 border-violet-200 dark:bg-violet-500/15 dark:text-violet-300 dark:border-violet-500/30"},"tool-invoke":{label:"Tool Invoke",classes:"bg-amber-50 text-amber-700 border-amber-200 dark:bg-amber-500/15 dark:text-amber-300 dark:border-amber-500/30"},"tool-result":{label:"Tool Result",classes:"bg-emerald-50 text-emerald-700 border-emerald-200 dark:bg-emerald-500/15 dark:text-emerald-300 dark:border-emerald-500/30"},error:{label:"Error",classes:"bg-rose-50 text-rose-700 border-rose-200 dark:bg-rose-500/15 dark:text-rose-300 dark:border-rose-500/30"}};function ot({event:e,onClose:s}){b.useEffect(()=>{const o=l=>{l.key==="Escape"&&s()};return document.addEventListener("keydown",o),()=>document.removeEventListener("keydown",o)},[s]);const n=()=>e.kind==="request"?t.jsxs("div",{className:"space-y-4",children:[t.jsxs(I,{title:"Info",children:[t.jsx(w,{label:"Turn",value:`#${e.turnIndex+1}`}),t.jsx(w,{label:"Kind",value:e.messageKind}),e.inputTokens!=null&&t.jsx(w,{label:"Input tokens",value:e.inputTokens.toLocaleString()})]}),t.jsx(I,{title:"Messages",children:t.jsx(ee,{data:e.rawMessages})})]}):e.kind==="response"?t.jsxs("div",{className:"space-y-4",children:[t.jsxs(I,{title:"Metrics",children:[t.jsx(w,{label:"Turn",value:`#${e.turnIndex+1}`}),e.latencyMs!=null&&t.jsx(w,{label:"Latency",value:R(e.latencyMs)}),e.ttftMs!=null&&t.jsx(w,{label:"TTFT",value:R(e.ttftMs)}),e.outputTokens!=null&&t.jsx(w,{label:"Output tokens",value:e.outputTokens.toLocaleString()}),e.stopReason&&t.jsx(w,{label:"Stop reason",value:e.stopReason})]}),t.jsx(I,{title:"Content",children:t.jsx(ee,{data:e.rawContent})})]}):e.kind==="tool-invoke"?t.jsxs("div",{className:"space-y-4",children:[t.jsxs(I,{title:"Info",children:[t.jsx(w,{label:"Turn",value:`#${e.turnIndex+1}`}),t.jsx(w,{label:"Tool",value:e.toolName}),t.jsx(w,{label:"Call ID",value:e.toolCallId})]}),t.jsx(I,{title:"Input",children:t.jsx(ee,{data:e.rawInput})})]}):e.kind==="tool-result"?t.jsxs("div",{className:"space-y-4",children:[t.jsxs(I,{title:"Info",children:[t.jsx(w,{label:"Turn",value:`#${e.turnIndex+1}`}),t.jsx(w,{label:"Tool",value:e.toolName}),t.jsx(w,{label:"Status",value:e.isError?"error":"success"}),e.durationMs!=null&&t.jsx(w,{label:"Duration",value:R(e.durationMs)})]}),t.jsx(I,{title:"Result",children:t.jsx(ee,{data:e.rawResult})})]}):t.jsxs("div",{className:"space-y-4",children:[t.jsxs(I,{title:"Info",children:[t.jsx(w,{label:"Turn",value:`#${e.turnIndex+1}`}),e.statusCode!=null&&t.jsx(w,{label:"Status code",value:String(e.statusCode)})]}),t.jsx(I,{title:"Message",children:t.jsx("p",{className:"text-sm text-rose-600 dark:text-rose-400",children:e.message})})]}),r=nt[e.kind];return t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"fixed inset-0 z-30 bg-black/10",onClick:s,"aria-hidden":"true"}),t.jsxs("div",{className:"fixed right-0 top-0 z-40 flex h-full w-[440px] flex-col border-l border-border bg-background shadow-xl",children:[t.jsxs("div",{className:"flex items-center justify-between border-b border-border px-4 py-3",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:y("rounded border px-2 py-0.5 text-xs font-semibold",r.classes),children:r.label}),t.jsxs("span",{className:"text-sm font-medium text-foreground",children:["Turn ",e.turnIndex+1]})]}),t.jsx("button",{type:"button",onClick:s,className:"rounded p-1 text-muted-foreground hover:bg-muted",children:t.jsx(Se,{className:"h-4 w-4"})})]}),t.jsx("div",{className:"flex-1 overflow-auto p-4",children:n()})]})]})}function lt(){return t.jsxs("div",{className:"flex flex-col items-center justify-center gap-2 py-16 text-center",children:[t.jsx("p",{className:"text-sm font-medium text-muted-foreground",children:"No flow data available"}),t.jsx("p",{className:"max-w-xs text-xs text-muted-foreground/70",children:"This session has no parseable request/response payloads."})]})}function at({detail:e}){const{t:s}=D(),n=b.useMemo(()=>Ye(e),[e]),[r,o]=b.useState(null),l=b.useRef(null),[a,i]=b.useState(we);b.useLayoutEffect(()=>{const d=l.current;if(!d)return;const u=()=>i(Math.max(d.clientWidth,we));u();const N=new ResizeObserver(u);return N.observe(d),()=>N.disconnect()},[]);const f=b.useMemo(()=>Ve(n.lanes,a),[n.lanes,a]),j=b.useMemo(()=>{const d={};for(const u of f)d[u.id]=u.x;return d},[f]),{turns:v,totalHeight:x}=b.useMemo(()=>Ze(n),[n]),m=b.useMemo(()=>tt(v),[v]),c=b.useMemo(()=>{if(!r)return null;for(const d of v){const u=d.rows.find(N=>N.event.id===r);if(u)return u.event}return null},[r,v]);return n.turns.length?t.jsxs("div",{ref:l,className:"relative overflow-x-auto overflow-y-hidden",children:[t.jsxs("div",{className:"flex items-center gap-3 border-b border-border bg-secondary/30 px-4 py-1.5 text-[11px] text-muted-foreground",children:[t.jsxs("span",{children:[n.turns.length," turn",n.turns.length!==1?"s":""]}),n.totalToolCalls>0&&t.jsxs("span",{className:"rounded border border-amber-200 bg-amber-50 px-1.5 py-0.5 text-amber-700 dark:border-amber-500/30 dark:bg-amber-500/10 dark:text-amber-300",children:["⚡ ",n.totalToolCalls," tool call",n.totalToolCalls!==1?"s":""]}),t.jsxs("span",{className:"ml-auto tabular-nums",children:[R(n.sessionDurationMs)," total"]})]}),t.jsxs("svg",{width:a,height:x,viewBox:`0 0 ${a} ${x}`,className:"block",children:[f.map(d=>t.jsx("line",{x1:d.x,x2:d.x,y1:U,y2:x-8,className:"stroke-border",strokeWidth:1,strokeDasharray:"3 4"},d.id)),t.jsx("rect",{x:0,y:0,width:a,height:U,className:"fill-background"}),f.map(d=>t.jsx(rt,{lane:d},d.id)),t.jsx("line",{x1:0,x2:a,y1:U-.5,y2:U-.5,className:"stroke-border",strokeWidth:1}),m.map((d,u)=>{const N=j[d.laneId],p=d.tone==="response"?fe.response:fe.result;return t.jsx("rect",{x:N-5,y:d.y1,width:10,height:Math.max(d.y2-d.y1,4),rx:2,className:y(p.activation)},u)}),v.map(d=>{const u=d.turn,N=`${s("profiler.turn.title",{index:u.index+1})}`+(u.latencyMs!=null?` · ${R(u.latencyMs)}`:"")+(u.inputTokens!=null?` · ↑${u.inputTokens.toLocaleString()}`:"")+(u.outputTokens!=null?` ↓${u.outputTokens.toLocaleString()}`:"");return t.jsxs("g",{children:[t.jsx("line",{x1:se-8,x2:a-se+8,y1:d.headerY,y2:d.headerY,className:"stroke-border",strokeWidth:1}),t.jsx("g",{children:(()=>{const p=Math.max(120,N.length*6.2),M=(a-p)/2;return t.jsxs(t.Fragment,{children:[t.jsx("rect",{x:M,y:d.headerY-9,width:p,height:18,rx:9,className:"fill-muted stroke-border",strokeWidth:1}),t.jsx("text",{x:a/2,y:d.headerY+4,textAnchor:"middle",className:"select-none fill-muted-foreground text-[10px] font-semibold tracking-wide",children:N})]})})()}),t.jsxs("text",{x:4,y:d.headerY+4,className:"select-none fill-muted-foreground/60 text-[9px] tabular-nums",children:[(u.startOffsetMs/1e3).toFixed(2),"s"]}),d.rows.map(p=>{const M=et(p.event);return M?t.jsx(st,{eventId:p.event.id,y:p.y,arrow:M,laneByX:j,active:r===p.event.id,onClick:()=>o(_=>_===p.event.id?null:p.event.id)},p.event.id):null})]},u.index)})]}),c&&t.jsx(ot,{event:c,onClose:()=>o(null)})]}):t.jsx(lt,{})}function E(e){return e==null?"-":e>=1e3?`${(e/1e3).toFixed(2)}s`:`${Math.round(e)}ms`}function re(e){return e==null?"-":e>=1e3?`${(e/1e3).toFixed(1)}s`:`${Math.round(e)}ms`}function J(e){return e==null?"-":e.toLocaleString()}function ge(e){return e==null?"-":e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:e.toLocaleString()}function oe(e){return e.endedAt==null||e.turnCount===0?e.totalLatencyMs??0:e.endedAt-e.startedAt}function it(e){const s=e.sessionId;return s.length>18?`${s.slice(0,8)}…${s.slice(-6)}`:s}function dt(e){switch(e){case"claude-code":return"Claude Code";case"codex":return"Codex";case"opencode":return"OpenCode";case"anthropic-compatible":return"Anthropic Compatible";case"openai-compatible":return"OpenAI Compatible";default:return e||null}}function ct(e,s){const n=Math.max(0,Date.now()-e),r=Math.floor(n/6e4);if(r<1)return s("profiler.relativeTime.justNow");if(r<60)return s("profiler.relativeTime.minutesAgo",{count:r});const o=Math.floor(r/60);if(o<24)return s("profiler.relativeTime.hoursAgo",{count:o});const l=Math.floor(o/24);return s("profiler.relativeTime.daysAgo",{count:l})}function ut(e){if(!e)return null;try{return JSON.parse(e)}catch{return null}}function pe(e,s){if(Array.isArray(e)){for(const n of e)pe(n,s);return}if(e&&typeof e=="object"){const n=e,r=n.type;(r==="tool_use"||r==="tool_call"||r==="function_call"||r==="computer_call"||r==="web_search_call"||r==="file_search_call"||r==="mcp_call"||r==="custom_tool_call")&&s.push(n);const o=n.tool_calls;Array.isArray(o)&&s.push(...o);const l=n.content;if(Array.isArray(l)){for(const a of l)if(a&&typeof a=="object"){const i=a;i.type==="tool_use"&&s.push(i)}}for(const a of Object.values(n))pe(a,s)}}function ne(e){const s=[];return pe(ut(e.clientResponse),s),s}function Ie(e,s){const n=e.timestamp-s,r=n+(e.latencyMs??0);return`${(n/1e3).toFixed(3)}s → ${(r/1e3).toFixed(3)}s`}function he(e,s){return Be(e??null,s)}function xt(e,s){const n=new Blob([JSON.stringify(s,null,2)],{type:"application/json"}),r=URL.createObjectURL(n),o=document.createElement("a");o.href=r,o.download=e,o.click(),URL.revokeObjectURL(r)}function ue({tone:e="default",children:s}){return t.jsx("span",{className:y("inline-flex items-center rounded-full px-2.5 py-1 text-[11px] font-medium",e==="accent"?"bg-primary/10 text-primary":"bg-secondary text-muted-foreground"),children:s})}function mt({session:e,selected:s,index:n,onClick:r}){const{t:o}=D(),l=["bg-indigo-500","bg-emerald-500","bg-amber-500"],a=s?"bg-indigo-500":l[n%l.length],i=(e.totalInputTokens??0)+(e.totalOutputTokens??0);return t.jsxs("button",{type:"button",onClick:r,className:y("w-full border-b border-border/45 px-4 py-3 text-left transition-colors",s?"bg-secondary":"hover:bg-secondary/50"),children:[t.jsxs("div",{className:"flex items-center justify-between gap-3",children:[t.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[t.jsx("span",{className:y("h-2 w-2 flex-shrink-0 rounded-full",a)}),t.jsx("span",{className:y("truncate text-sm font-semibold",s?"text-primary":"text-foreground"),children:it(e)})]}),t.jsx("span",{className:"text-[11px] text-muted-foreground",children:ct(e.startedAt,o)})]}),t.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2 pl-4",children:[t.jsx(ue,{tone:s?"accent":"default",children:o("profiler.metricTurns",{count:e.turnCount})}),t.jsx(ue,{children:re(oe(e))}),t.jsx(ue,{children:o("profiler.metricTokens",{value:ge(i)})})]})]})}function xe({active:e,icon:s,label:n,onClick:r}){return t.jsxs("button",{type:"button",onClick:r,className:y("inline-flex h-8 items-center gap-1.5 rounded-full border px-3 text-xs font-medium transition-all",e?"border-primary/20 bg-primary/10 text-primary":"border-transparent bg-secondary text-muted-foreground hover:bg-secondary/80 hover:text-foreground"),children:[t.jsx(s,{className:"h-3.5 w-3.5"}),n]})}function me({active:e,label:s,count:n,onClick:r}){return t.jsxs("button",{type:"button",onClick:r,className:y("inline-flex h-7 items-center gap-1.5 rounded-full border px-3 text-[11px] font-medium transition-all",e?"border-primary/20 bg-primary/10 text-primary":"border-transparent bg-transparent text-muted-foreground hover:bg-secondary hover:text-foreground"),children:[t.jsx("span",{children:s}),typeof n=="number"&&t.jsx("span",{className:"rounded-full bg-amber-100 px-1.5 py-0.5 text-[11px] font-semibold text-amber-700",children:n})]})}function ft({detail:e,selectedTurn:s,onSelectTurn:n}){const{t:r}=D(),o=e.records;if(o.length===0)return t.jsx(H,{compact:!0,className:"min-h-[220px]",title:r("profiler.empty.noTurnsTitle"),description:r("profiler.empty.noTurnsDescription")});const l=oe(e),a=Math.max(1,...o.map(i=>Math.max(i.latencyMs??0,i.ttftMs??0,1)));return Math.max(1,...o.map(i=>ne(i).length)),t.jsxs("div",{className:"rounded-xl bg-card shadow-[var(--surface-shadow)]",children:[t.jsxs("div",{className:"flex items-center justify-between gap-4 border-b border-border/45 px-5 py-3.5",children:[t.jsx("p",{className:"text-xs text-muted-foreground",children:r("profiler.timeline.summary")}),t.jsxs("div",{className:"flex items-center gap-2 text-[11px]",children:[t.jsx("span",{className:"text-muted-foreground",children:r("profiler.timeline.mode")}),t.jsx("span",{className:"rounded-full border border-border bg-secondary/70 px-2.5 py-1 font-medium text-foreground",children:r("profiler.timeline.compressed")}),t.jsx("span",{className:"rounded-full border border-border bg-card px-2.5 py-1 font-medium text-foreground",children:r("profiler.timeline.sessionDuration",{duration:re(l)})})]})]}),t.jsxs("div",{className:"px-5 pb-4",children:[t.jsxs("div",{className:"mb-3 flex items-center justify-between text-[11px] text-muted-foreground/70",children:[t.jsx("span",{children:r("profiler.timeline.start")}),t.jsxs("span",{children:[(l/1e3).toFixed(1),"s"]})]}),t.jsx("div",{className:"grid gap-x-2 gap-y-5",style:{gridTemplateColumns:"repeat(10, minmax(0, 1fr))"},children:o.map((i,f)=>{const j=f===s,v=Math.max(i.latencyMs??0,1),x=`${Math.max(28,Math.min(100,v/a*100))}%`,m=i.ttftMs!=null?`${Math.max(0,Math.min(100,Math.min(i.ttftMs,a)/a*100))}%`:null,c=Math.max(0,i.timestamp-e.startedAt),d=ne(i);return t.jsxs("button",{type:"button",onClick:()=>n(f),className:y("rounded-xl border border-transparent bg-card px-2 py-2 text-left shadow-sm transition-all",j?"border-primary/20 bg-primary/5":"hover:bg-secondary/50"),title:r("profiler.turn.title",{index:i.turnIndex+1}),children:[t.jsx("div",{className:"flex min-w-0 items-center gap-2",children:t.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[t.jsx("span",{className:y("inline-flex h-5 min-w-5 items-center justify-center rounded-full border px-1.5 text-[11px] font-semibold",j?"border-primary/30 bg-primary/10 text-primary":"border-border bg-card text-foreground"),children:i.turnIndex+1}),t.jsx("span",{className:"truncate text-[15px] font-semibold text-foreground",children:re(i.latencyMs)})]})}),t.jsx("p",{className:"mt-1 text-[11px] text-muted-foreground",children:r("profiler.timeline.startAt",{time:(c/1e3).toFixed(1)})}),t.jsxs("div",{className:"mt-2",children:[t.jsx("div",{className:"flex items-center justify-between text-[11px] text-muted-foreground",children:t.jsxs("span",{children:[E(i.ttftMs)," TTFT"]})}),t.jsxs("div",{className:"relative mt-1 h-4 rounded-sm bg-secondary",children:[t.jsx("div",{className:"h-4 rounded-sm bg-primary/20",style:{width:x}}),m!=null&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"absolute top-[-3px] h-5 w-[3px] -translate-x-1/2 rounded-full bg-violet-500 ring-1 ring-white",style:{left:m}}),t.jsx("span",{className:"absolute top-[-6px] h-2.5 w-2.5 -translate-x-1/2 rounded-full border border-white bg-violet-500",style:{left:m}})]})]})]}),t.jsxs("div",{className:"mt-2",children:[t.jsxs("div",{className:"mb-1 flex items-center justify-between text-[11px] text-muted-foreground",children:[t.jsx("span",{children:r("profiler.timeline.tools")}),t.jsx("span",{children:d.length})]}),t.jsx("div",{className:"flex h-5 items-center gap-1",children:t.jsx("span",{className:y("inline-flex h-5 min-w-5 items-center justify-center rounded-md border text-[11px] font-semibold",d.length>0?"border-amber-400 bg-amber-200 text-amber-900":"border-border bg-card text-muted-foreground"),children:d.length})})]})]},i.id)})}),t.jsxs("div",{className:"mt-4 flex flex-wrap items-center gap-4 text-[11px] text-muted-foreground",children:[t.jsxs("span",{className:"flex items-center gap-1.5",children:[t.jsx("span",{className:"h-2.5 w-2.5 rounded-sm bg-blue-200"}),r("profiler.timeline.legend.totalLatency")]}),t.jsxs("span",{className:"flex items-center gap-1.5",children:[t.jsx("span",{className:"relative inline-block h-2.5 w-2.5 rounded-full border border-white bg-violet-500 ring-1 ring-violet-500/35"}),r("profiler.timeline.legend.firstToken")]}),t.jsxs("span",{className:"flex items-center gap-1.5",children:[t.jsx("span",{className:"h-2.5 w-2.5 rounded-sm border border-amber-400 bg-amber-200"}),r("profiler.timeline.legend.toolExecuting")]}),t.jsxs("span",{className:"flex items-center gap-1.5",children:[t.jsx("span",{className:"h-2.5 w-2.5 rounded-sm border border-rose-300 bg-rose-50"}),r("profiler.timeline.legend.selectedTurn")]})]})]})]})}function pt({detail:e,selectedTurn:s,detailTab:n,onDetailTabChange:r,onSelectTurn:o}){const{t:l}=D(),a=e.records[s];if(!a)return null;const i=ne(a),f=(a.inputTokens??0)+(a.outputTokens??0),j=n==="request"?he(a.clientRequest,l("profiler.payload.emptyRequest")):n==="response"?he(a.clientResponse,l("profiler.payload.emptyResponse")):i.length>0?JSON.stringify(i,null,2):l("profiler.payload.noToolCalls");return t.jsxs("div",{"data-testid":"profiler-turn-detail",className:"mt-3 shrink-0 rounded-xl bg-card shadow-[var(--surface-shadow)]",children:[t.jsxs("div",{className:"flex items-center justify-between gap-4 border-b border-border px-5 py-3",children:[t.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-2 text-xs",children:[t.jsx("span",{className:"rounded-full bg-primary px-2 py-1 font-semibold text-primary-foreground",children:l("profiler.turn.title",{index:a.turnIndex+1})}),t.jsx("span",{className:"text-muted-foreground",children:Ie(a,e.startedAt)}),t.jsxs("span",{className:"rounded-full bg-violet-50 border border-violet-200 px-2 py-1 font-semibold text-violet-700 dark:bg-violet-500/16 dark:border-violet-400/20 dark:text-violet-200",children:["TTFT ",E(a.ttftMs)]}),t.jsxs("span",{className:"rounded-full bg-sky-50 border border-sky-200 px-2 py-1 font-semibold text-sky-700 dark:bg-sky-500/16 dark:border-sky-400/20 dark:text-sky-200",children:[ge(f)," tokens"]})]}),t.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[t.jsx("button",{type:"button",onClick:()=>o(Math.max(0,s-1)),disabled:s===0,className:"rounded-full p-1.5 transition-colors hover:bg-secondary disabled:cursor-not-allowed disabled:opacity-40","aria-label":l("profiler.turn.previous"),children:t.jsx(Fe,{className:"h-4 w-4"})}),t.jsxs("span",{className:"min-w-10 text-center font-medium text-muted-foreground",children:[s+1," / ",e.records.length]}),t.jsx("button",{type:"button",onClick:()=>o(Math.min(e.records.length-1,s+1)),disabled:s===e.records.length-1,className:"rounded-full p-1.5 transition-colors hover:bg-secondary disabled:cursor-not-allowed disabled:opacity-40","aria-label":l("profiler.turn.next"),children:t.jsx(Le,{className:"h-4 w-4"})})]})]}),t.jsx("div",{className:"border-b border-border bg-secondary/30 px-5 py-2",children:t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[t.jsx(me,{active:n==="request",label:l("profiler.payload.request"),onClick:()=>r("request")}),t.jsx(me,{active:n==="response",label:l("profiler.payload.response"),onClick:()=>r("response")}),t.jsx(me,{active:n==="tools",label:l("profiler.payload.toolCalls"),count:i.length,onClick:()=>r("tools")})]})}),t.jsxs("div",{className:"bg-secondary/30 p-5",children:[t.jsx("pre",{className:"max-h-[420px] overflow-auto rounded-xl bg-[#1E1E2E] p-4 text-xs leading-5 text-slate-200",children:j}),a.error&&t.jsx("p",{className:"mt-3 rounded-lg border border-red-200 bg-red-50 px-3 py-2 text-xs text-red-700",children:a.error})]})]})}function ht({detail:e,selectedTurn:s,detailTab:n,onSelectTurn:r,onDetailTabChange:o}){return t.jsxs("div",{className:"flex min-h-full flex-col",children:[t.jsx(ft,{detail:e,selectedTurn:s,onSelectTurn:r}),t.jsx(pt,{detail:e,selectedTurn:s,detailTab:n,onDetailTabChange:o,onSelectTurn:r})]})}function Me({title:e,payload:s,accentClass:n,emptyLabel:r}){return t.jsxs("div",{className:"rounded-xl border border-white/45 bg-white/88 p-3 shadow-[0_12px_28px_rgba(15,23,42,0.06)] dark:border-white/10 dark:bg-slate-950/[0.58] dark:shadow-[0_12px_28px_rgba(0,0,0,0.28)]",children:[t.jsx("p",{className:y("mb-2 text-[11px] font-semibold uppercase tracking-wider",n),children:e}),t.jsx("pre",{className:"max-h-64 overflow-auto rounded-lg bg-slate-950/95 p-3 text-xs leading-5 text-slate-200",children:he(s,r)})]})}function B({label:e,value:s,sub:n,accentClass:r}){return t.jsxs("div",{className:"rounded-xl bg-card p-4 shadow-sm",children:[t.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-wider text-muted-foreground",children:e}),t.jsx("p",{className:y("metric-number mt-2 text-2xl font-semibold text-foreground",r),children:s}),n&&t.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:n})]})}function gt({record:e,sessionStart:s,expanded:n,onToggle:r}){const{t:o}=D(),l=ne(e);return t.jsxs("div",{className:"overflow-hidden rounded-xl bg-card shadow-sm",children:[t.jsxs("button",{type:"button",onClick:r,className:"flex w-full items-center gap-4 px-4 py-3 text-left transition-colors hover:bg-secondary/50",children:[t.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-3",children:[t.jsxs("span",{className:"rounded-full bg-primary px-2 py-0.5 text-[11px] font-semibold text-primary-foreground",children:["T",e.turnIndex+1]}),t.jsxs("div",{className:"min-w-0",children:[t.jsx("div",{className:"text-sm font-medium text-foreground",children:Ie(e,s)}),t.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-2 text-[11px] text-muted-foreground",children:[t.jsx("span",{children:o("profiler.breakdown.total",{value:E(e.latencyMs)})}),t.jsxs("span",{children:["TTFT ",E(e.ttftMs)]}),t.jsxs("span",{children:["TPOT ",e.tpotMs!=null?`${e.tpotMs.toFixed(1)} ms/tok`:"-"]}),t.jsxs("span",{children:["↑ ",J(e.inputTokens)]}),t.jsxs("span",{children:["↓ ",J(e.outputTokens)]}),t.jsx("span",{children:o("profiler.breakdown.toolCallsCount",{count:l.length})}),e.error&&t.jsx("span",{className:"rounded-full bg-red-50 px-2 py-0.5 font-medium text-red-600 dark:bg-red-500/14 dark:text-red-300",children:o("profiler.breakdown.error")})]})]})]}),t.jsx(De,{className:y("h-4 w-4 flex-shrink-0 text-muted-foreground/70 transition-transform",n&&"rotate-180")})]}),n&&t.jsxs("div",{className:"border-t border-border bg-secondary/30 p-4",children:[t.jsxs("div",{className:"grid gap-3 xl:grid-cols-2",children:[t.jsx(Me,{title:o("profiler.payload.request"),payload:e.clientRequest,accentClass:"text-blue-600",emptyLabel:o("profiler.payload.empty")}),t.jsx(Me,{title:o("profiler.payload.response"),payload:e.clientResponse,accentClass:"text-violet-600",emptyLabel:o("profiler.payload.empty")})]}),t.jsxs("div",{className:"mt-3 grid gap-3 xl:grid-cols-[minmax(0,1fr)_280px]",children:[t.jsxs("div",{className:"rounded-xl bg-card p-3 shadow-sm",children:[t.jsx("p",{className:"mb-2 text-[11px] font-semibold uppercase tracking-wider text-amber-600",children:o("profiler.payload.toolCalls")}),t.jsx("pre",{className:"max-h-64 overflow-auto rounded-lg bg-slate-950/95 p-3 text-xs leading-5 text-slate-200",children:l.length>0?JSON.stringify(l,null,2):o("profiler.payload.noToolCalls")})]}),t.jsxs("div",{className:"rounded-xl bg-card p-3 shadow-sm",children:[t.jsx("p",{className:"mb-2 text-[11px] font-semibold uppercase tracking-wider text-muted-foreground",children:o("profiler.breakdown.turnMetrics")}),t.jsxs("dl",{className:"grid grid-cols-2 gap-x-3 gap-y-2 text-xs",children:[t.jsxs("div",{children:[t.jsx("dt",{className:"text-muted-foreground",children:o("profiler.breakdown.duration")}),t.jsx("dd",{className:"mt-0.5 font-medium text-foreground",children:E(e.latencyMs)})]}),t.jsxs("div",{children:[t.jsx("dt",{className:"text-muted-foreground",children:"TTFT"}),t.jsx("dd",{className:"mt-0.5 font-medium text-foreground",children:E(e.ttftMs)})]}),t.jsxs("div",{children:[t.jsx("dt",{className:"text-muted-foreground",children:"TPOT"}),t.jsx("dd",{className:"mt-0.5 font-medium text-foreground",children:e.tpotMs!=null?`${e.tpotMs.toFixed(1)} ms/tok`:"-"})]}),t.jsxs("div",{children:[t.jsx("dt",{className:"text-muted-foreground",children:o("profiler.breakdown.status")}),t.jsx("dd",{className:"mt-0.5 font-medium text-foreground",children:e.statusCode??"-"})]}),t.jsxs("div",{children:[t.jsx("dt",{className:"text-muted-foreground",children:o("profiler.breakdown.input")}),t.jsx("dd",{className:"mt-0.5 font-medium text-foreground",children:J(e.inputTokens)})]}),t.jsxs("div",{children:[t.jsx("dt",{className:"text-muted-foreground",children:o("profiler.breakdown.output")}),t.jsx("dd",{className:"mt-0.5 font-medium text-foreground",children:J(e.outputTokens)})]})]}),e.error&&t.jsx("p",{className:"mt-3 rounded-lg border border-red-200 bg-red-50 px-3 py-2 text-xs text-red-700",children:e.error})]})]})]})]})}function bt({detail:e,expandedTurn:s,onToggleTurn:n}){const{t:r}=D();if(e.records.length===0)return t.jsx(H,{compact:!0,className:"min-h-[220px]",title:r("profiler.empty.noTurnsTitle"),description:r("profiler.empty.noTurnsDescription")});const o=oe(e),l=e.records.reduce((x,m)=>{const c=m.latencyMs??0,d=m.ttftMs??0;return x+Math.max(c-d,0)},0),a=o>0?(l/o*100).toFixed(1):"-",i=e.records.map(x=>x.ttftMs).filter(x=>x!=null),f=e.records.map(x=>x.tpotMs).filter(x=>x!=null),j=i.length>0?i.reduce((x,m)=>x+m,0)/i.length:null,v=f.length>0?f.reduce((x,m)=>x+m,0)/f.length:null;return t.jsxs("div",{className:"space-y-5 p-5",children:[t.jsxs("div",{className:"grid gap-3 sm:grid-cols-2 xl:grid-cols-6",children:[t.jsx(B,{label:r("profiler.breakdown.totalDuration"),value:E(o),sub:r("profiler.breakdown.turnsSub",{count:e.records.length})}),t.jsx(B,{label:r("profiler.breakdown.llmTime"),value:E(l),sub:r("profiler.breakdown.sessionShare",{value:a}),accentClass:"text-violet-700"}),t.jsx(B,{label:r("profiler.breakdown.avgTtft"),value:E(j)}),t.jsx(B,{label:r("profiler.breakdown.avgTpot"),value:v!=null?`${v.toFixed(1)} ms/tok`:"-"}),t.jsx(B,{label:r("profiler.breakdown.inputTokens"),value:J(e.totalInputTokens)}),t.jsx(B,{label:r("profiler.breakdown.outputTokens"),value:J(e.totalOutputTokens)})]}),t.jsxs("div",{className:"space-y-3",children:[t.jsx("div",{className:"flex items-center justify-between",children:t.jsxs("div",{children:[t.jsx("h3",{className:"text-sm font-semibold text-foreground",children:r("profiler.breakdown.perTurnTitle")}),t.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:r("profiler.breakdown.perTurnDescription")})]})}),e.records.map(x=>t.jsx(gt,{record:x,sessionStart:e.startedAt,expanded:s===x.turnIndex,onToggle:()=>n(x.turnIndex)},x.id))]})]})}function At(){var q,be,ye;const{t:e}=D(),s=Pe(),[n,r]=b.useState(null),[o,l]=b.useState("timeline"),[a,i]=b.useState("request"),[f,j]=b.useState(0),[v,x]=b.useState(0),[m,c]=b.useState(""),u=((q=ae({queryKey:$.profiler.status(),queryFn:()=>L.getStatus(),refetchInterval:3e3}).data)==null?void 0:q.active)??!1,N=ae({queryKey:$.profiler.sessions({}),queryFn:()=>L.listSessions({limit:100}),refetchInterval:u?2e3:!1}),p=((be=N.data)==null?void 0:be.items)??[],M=ae({queryKey:$.profiler.session(n),queryFn:()=>L.getSession(n),enabled:n!=null,refetchInterval:u&&n!=null?2e3:!1}),_=X({mutationFn:()=>L.start(),onSuccess:()=>{s.invalidateQueries({queryKey:$.profiler.status()}),s.invalidateQueries({queryKey:$.profiler.sessions({})})}}),S=X({mutationFn:()=>L.stop(),onSuccess:()=>{s.invalidateQueries({queryKey:$.profiler.status()}),s.invalidateQueries({queryKey:$.profiler.sessions({})})}}),G=X({mutationFn:g=>L.deleteSession(g),onSuccess:(g,F)=>{n===F&&r(null),s.invalidateQueries({queryKey:$.profiler.sessions({})})}}),le=X({mutationFn:()=>L.clearAll(),onSuccess:()=>{r(null),s.invalidateQueries({queryKey:$.profiler.sessions({})})}}),A=b.useMemo(()=>{const g=m.trim().toLowerCase();return g?p.filter(F=>F.sessionId.toLowerCase().includes(g)):p},[m,p]),P=m.trim().length>0,h=M.data,W=p.find(g=>g.id===n)??null,z=(h==null?void 0:h.records[f])??null,Y=dt(((ye=h==null?void 0:h.records[0])==null?void 0:ye.clientKind)??null);b.useEffect(()=>{n&&!p.some(g=>g.id===n)&&r(null)},[n,p]),b.useEffect(()=>{!n&&A.length>0&&r(A[0].id)},[A,n]),b.useEffect(()=>{j(0),x(0),i("request")},[n]),b.useEffect(()=>{if(!h){j(0),x(0);return}j(g=>Math.min(g,Math.max(h.records.length-1,0))),x(g=>g==null?0:Math.min(g,Math.max(h.records.length-1,0)))},[h]);const T=()=>{h&&xt(`profiler-${h.sessionId}.json`,h)};return t.jsxs("div",{className:"flex min-h-0 flex-1 flex-col gap-3",children:[t.jsx(Ke,{status:t.jsxs("span",{className:y("inline-flex items-center gap-1.5 text-xs",u?"text-red-600 dark:text-red-300":"text-muted-foreground"),children:[t.jsx("span",{className:y("inline-block h-1.5 w-1.5 rounded-full",u?"bg-red-500":"bg-muted-foreground/70")}),e(u?"profiler.status.recording":"profiler.status.idle")]}),info:t.jsx(ie,{variant:"secondary",className:"rounded-full px-2.5 py-0.5 text-[11px]",children:e("profiler.sessionsCount",{count:p.length})}),actions:t.jsxs(t.Fragment,{children:[t.jsx(O,{size:"sm",variant:u?"destructive":"default",onClick:()=>u?S.mutate():_.mutate(),disabled:_.isPending||S.isPending,children:e(u?"profiler.actions.stop":"profiler.actions.start")}),t.jsxs(O,{size:"sm",variant:"outline",onClick:T,disabled:!h,children:[t.jsx(Ae,{className:"mr-1.5 h-3.5 w-3.5"}),e("profiler.actions.export")]}),t.jsxs(O,{size:"sm",variant:"outline",onClick:()=>le.mutate(),disabled:p.length===0,className:"border-red-200 bg-red-50 text-red-700 hover:bg-red-100 hover:text-red-800 dark:border-red-400/20 dark:bg-red-500/14 dark:text-red-300 dark:hover:bg-red-500/20 dark:hover:text-red-200",children:[t.jsx(je,{className:"mr-1.5 h-3.5 w-3.5"}),e("profiler.actions.clear")]})]})}),t.jsxs("div",{className:"flex min-h-0 flex-1 flex-col gap-3 bg-background lg:flex-row lg:gap-0 lg:overflow-hidden",children:[t.jsxs("div",{className:"flex w-full flex-shrink-0 flex-col overflow-hidden rounded-[1.2rem] border border-white/70 bg-card/96 shadow-[0_20px_48px_-42px_rgba(15,23,42,0.26)] lg:w-[300px]",children:[t.jsxs("div",{className:"flex items-center justify-between border-b border-border/45 px-4 py-3",children:[t.jsx("span",{className:"text-sm font-semibold text-foreground",children:e("profiler.sessionsTitle")}),t.jsx(ie,{variant:"secondary",className:"rounded-full px-2 py-0.5",children:p.length})]}),t.jsxs("div",{className:"flex items-center gap-2 border-b border-border bg-secondary/50 px-3 py-2.5",children:[t.jsx($e,{className:"h-3.5 w-3.5 text-muted-foreground/70"}),t.jsx("input",{className:"w-full bg-transparent text-sm outline-none placeholder:text-muted-foreground/70",placeholder:e("profiler.searchPlaceholder"),value:m,onChange:g=>c(g.target.value)})]}),t.jsx("div",{className:"max-h-[240px] overflow-y-auto lg:min-h-0 lg:max-h-none lg:flex-1",children:N.isPending?t.jsx(ke,{compact:!0,className:"min-h-[160px]",label:e("common.loading")}):A.length===0?t.jsx(H,{compact:!0,className:"m-4 min-h-[160px]",title:e(P?"profiler.empty.searchTitle":u?"profiler.empty.waitingTitle":"profiler.empty.idleTitle"),description:e(P?"profiler.empty.searchDescription":u?"profiler.empty.waitingDescription":"profiler.empty.idleDescription"),action:P?void 0:u?t.jsx(O,{asChild:!0,variant:"ghost",size:"sm",children:t.jsx(Oe,{to:"/logs",children:e("profiler.empty.actions.logs")})}):t.jsx(O,{size:"sm",onClick:()=>_.mutate(),disabled:_.isPending,children:e("profiler.actions.start")})}):A.map((g,F)=>t.jsx(mt,{session:g,selected:n===g.id,index:F,onClick:()=>r(g.id)},g.id))})]}),t.jsx("div",{className:"flex min-w-0 flex-1 flex-col overflow-hidden rounded-[1.2rem] border border-white/70 bg-card/96 shadow-[0_20px_48px_-42px_rgba(15,23,42,0.26)] lg:ml-3",children:n?t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"flex items-center justify-between gap-4 border-b border-border bg-card px-5 py-3.5",children:[t.jsxs("div",{className:"flex min-w-0 items-center gap-2.5",children:[t.jsx("span",{className:"h-2.5 w-2.5 flex-shrink-0 rounded-full bg-indigo-500"}),t.jsx("span",{className:"truncate text-sm font-semibold text-foreground",children:(h==null?void 0:h.sessionId)??(W==null?void 0:W.sessionId)??n}),Y&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"text-muted-foreground/70",children:"·"}),t.jsx(ie,{variant:"secondary",className:"rounded-full px-2 py-0.5 text-[10px]",children:Y})]}),t.jsx("span",{className:"text-muted-foreground/70",children:"·"}),t.jsx("span",{className:"truncate text-sm text-muted-foreground",children:h?e("profiler.sessionSummary",{turns:h.turnCount,duration:re(oe(h)),tokens:ge((h.totalInputTokens??0)+(h.totalOutputTokens??0))}):e("profiler.loadingSession")})]}),t.jsx(O,{variant:"ghost",size:"sm",onClick:()=>n&&G.mutate(n),disabled:!n||G.isPending,className:"text-muted-foreground hover:text-red-700",children:t.jsx(je,{className:"h-3.5 w-3.5"})})]}),t.jsx("div",{className:"border-b border-border bg-secondary/30 px-5 py-2.5",children:t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[t.jsx(xe,{active:o==="timeline",icon:_e,label:e("profiler.tabs.timeline"),onClick:()=>l("timeline")}),t.jsx(xe,{active:o==="breakdown",icon:Re,label:e("profiler.tabs.breakdown"),onClick:()=>l("breakdown")}),t.jsx(xe,{active:o==="flow",icon:qe,label:e("profiler.tabs.flow"),onClick:()=>l("flow")})]})}),t.jsx("div",{"data-testid":"profiler-session-content",className:"min-h-0 flex-1 overflow-auto bg-secondary/20",children:M.isPending?t.jsx(ke,{compact:!0,className:"min-h-[240px]",label:e("profiler.loadingSession")}):M.isError?t.jsx(H,{compact:!0,className:"m-5 min-h-[220px]",tone:"danger",title:e("profiler.errors.loadFailed")}):h?o==="timeline"?t.jsx(ht,{detail:h,selectedTurn:f,detailTab:a,onSelectTurn:j,onDetailTabChange:i}):o==="flow"?t.jsx(at,{detail:h}):t.jsx(bt,{detail:h,expandedTurn:v,onToggleTurn:g=>x(F=>F===g?null:g)}):t.jsx(H,{compact:!0,className:"m-5 min-h-[220px]",title:e("profiler.errors.notFound")})}),z&&t.jsxs("span",{className:"sr-only",children:["Selected turn ",z.turnIndex+1]})]}):t.jsx("div",{className:"flex flex-1 items-center justify-center",children:t.jsx(H,{title:e("profiler.empty.selectTitle"),description:e("profiler.empty.selectDescription"),icon:t.jsx(Ee,{className:"h-5 w-5"})})})})]})]})}export{At as default};
1
+ import{r as b,j as t,a7 as Se,az as Ae,aO as je,aT as $e,W as Ee,aU as _e,O as Re,ag as qe,aD as Fe,a0 as Le,al as De}from"./vendor-DdPBfMMb.js";import{u as Pe,a as ae,b as X}from"./query-QCek5MsK.js";import{L as Oe}from"./router-D2Fb4U0L.js";import{P as Ke}from"./PageToolbar-CDzxx36L.js";import{P as ke,a as H}from"./PageState-C9j-dOzv.js";import{B as ie,q as $}from"./queryKeys-0HDa7byL.js";import{g as V,b as Z,r as de,B as O}from"./app-BF0X4ljN.js";import{c as y}from"./global-CsDL9Nt2.js";import{f as Be}from"./utils-RIyUChKi.js";import{u as D}from"./i18n-C8tBby0x.js";import"./radix-CtQBp6Ie.js";const L={getStatus:()=>de({url:"/api/profiler/status",method:"GET"}),start:()=>V(Z.post("/api/profiler/start")),stop:()=>V(Z.post("/api/profiler/stop")),listSessions:e=>de({url:"/api/profiler/sessions",method:"GET",params:e}),getSession:e=>de({url:`/api/profiler/sessions/${e}`,method:"GET"}),deleteSession:e=>V(Z.delete(`/api/profiler/sessions/${e}`)),clearAll:()=>V(Z.post("/api/profiler/sessions/clear"))};function Q(e){if(!e)return null;try{return JSON.parse(e)}catch{return null}}function k(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function C(e,s){return e.length<=s?e:e.slice(0,s-1)+"…"}function Ce(e){if(typeof e=="string")return e;if(Array.isArray(e)){for(const s of e)if(k(s)&&s.type==="text"&&typeof s.text=="string")return s.text}return""}function He(e){if(!k(e))return"";const s=Object.entries(e);if(!s.length)return"";const[n,r]=s[0],o=typeof r=="string"?`"${C(r,60)}"`:String(r);return`${n}: ${o}`}function Je(e){if(typeof e=="string")return C(e,120);if(Array.isArray(e)){for(const s of e)if(k(s)&&s.type==="text"&&typeof s.text=="string")return C(s.text,120);return C(JSON.stringify(e),120)}return k(e)?C(JSON.stringify(e),120):""}function ce(e,s){if(k(s)&&Array.isArray(s.choices))return"openai";if(k(s)&&Array.isArray(s.content))return"anthropic";if(k(e)&&Array.isArray(e.messages)){for(const n of e.messages)if(k(n)&&n.role==="tool")return"openai";return"anthropic"}return"unknown"}function Ne(e,s){var n;if(s==="openai"){if(!k(e)||!Array.isArray(e.choices))return[];const r=(n=e.choices[0])==null?void 0:n.message;return!k(r)||!Array.isArray(r.tool_calls)?[]:r.tool_calls.filter(o=>o.id&&k(o.function)&&o.function.name).map(o=>{const l=o.function;let a={};try{a=JSON.parse(String(l.arguments??"{}"))}catch{}return{id:String(o.id),name:String(l.name),input:a}})}return!k(e)||!Array.isArray(e.content)?[]:e.content.filter(r=>r.type==="tool_use"&&r.id&&r.name).map(r=>({id:String(r.id),name:String(r.name),input:r.input}))}function We(e,s){if(!k(e)||!Array.isArray(e.messages))return[];const n=e.messages;if(s==="openai")return n.filter(o=>o.role==="tool"&&o.tool_call_id).map(o=>({toolCallId:String(o.tool_call_id),content:o.content,isError:!1}));const r=[];for(const o of n)if(!(o.role!=="user"||!Array.isArray(o.content)))for(const l of o.content)l.type==="tool_result"&&l.tool_use_id&&r.push({toolCallId:String(l.tool_use_id),content:l.content,isError:l.is_error===!0});return r}function Qe(e,s){if(!k(e)||!Array.isArray(e.messages))return{messageKind:"unknown",messageExcerpt:""};const n=e.messages.filter(o=>o.role!=="system");if(!n.length)return{messageKind:"unknown",messageExcerpt:""};const r=n[n.length-1];if(s==="openai"){if(r.role==="tool"){const o=n.filter(l=>l.role==="tool").length;return{messageKind:"tool-results",messageExcerpt:`${o} tool result${o!==1?"s":""}`}}return r.role==="user"?{messageKind:"user",messageExcerpt:C(String(r.content??""),80)}:{messageKind:"unknown",messageExcerpt:""}}if(r.role==="user"){if(Array.isArray(r.content)){const o=r.content,l=o.some(i=>i.type==="tool_result"),a=o.some(i=>i.type==="text");if(l&&a)return{messageKind:"mixed",messageExcerpt:""};if(l){const i=o.filter(f=>f.type==="tool_result").length;return{messageKind:"tool-results",messageExcerpt:`${i} tool result${i!==1?"s":""}`}}return{messageKind:"user",messageExcerpt:C(Ce(r.content),80)}}return{messageKind:"user",messageExcerpt:C(String(r.content??""),80)}}return{messageKind:"unknown",messageExcerpt:""}}function Ue(e,s){var r;if(s==="openai"){if(!k(e)||!Array.isArray(e.choices))return null;const o=(r=e.choices[0])==null?void 0:r.message;if(!k(o))return null;const l=String(o.content??"");return l?C(l,80):null}if(!k(e))return null;const n=Ce(e.content);return n?C(n,80):null}function Ge(e,s){var n;if(!k(e))return null;if(s==="anthropic")return typeof e.stop_reason=="string"?e.stop_reason:null;if(s==="openai"){const r=(n=e.choices)==null?void 0:n[0];if(k(r))return typeof r.finish_reason=="string"?r.finish_reason:null}return null}function ze(e,s){return k(e)?s==="anthropic"?e.content??null:s==="openai"?e.choices??null:null:null}function Ye(e){const{records:s,startedAt:n}=e;if(!s.length)return{lanes:[],turns:[],sessionDurationMs:0,totalToolCalls:0,uniqueToolNames:[]};const r=[...s].sort((m,c)=>m.turnIndex-c.turnIndex),o=[],l=new Set;for(const m of r){const c=Q(m.clientResponse),d=Q(m.clientRequest);for(const u of Ne(c,ce(d,c)))l.has(u.name)||(l.add(u.name),o.push(u.name))}const i=[{id:"agent",label:(()=>{switch(r[0].clientKind){case"claude-code":return"Claude Code";case"codex":return"Codex";case"opencode":return"OpenCode";default:return"Agent"}})()},{id:"llm",label:"LLM",sublabel:C(r[0].model??"",32)||void 0},{id:"tools",label:"Tools",sublabel:o.length?`${o.length} tool${o.length!==1?"s":""}`:void 0}];let f=0;const j=[];for(let m=0;m<r.length;m++){const c=r[m],d=r[m+1],u=Q(c.clientRequest),N=Q(c.clientResponse),p=ce(u,N),M=c.timestamp-n,_=M+(c.latencyMs??0),S=[],{messageKind:G,messageExcerpt:le}=Qe(u,p);S.push({kind:"request",id:`t${c.turnIndex}-req`,turnIndex:c.turnIndex,messageKind:G,messageExcerpt:le,inputTokens:c.inputTokens,rawMessages:k(u)?u.messages:null});const A=Ne(N,p);S.push({kind:"response",id:`t${c.turnIndex}-res`,turnIndex:c.turnIndex,textExcerpt:Ue(N,p),toolUseCount:A.length,stopReason:Ge(N,p),outputTokens:c.outputTokens,latencyMs:c.latencyMs,ttftMs:c.ttftMs,rawContent:ze(N,p)}),c.error&&S.push({kind:"error",id:`t${c.turnIndex}-err`,turnIndex:c.turnIndex,message:c.error,statusCode:c.statusCode});const P=d?Q(d.clientRequest):null,h=d?ce(P,null):"unknown",W=d?We(P,h):[],z=new Map(W.map(T=>[T.toolCallId,T])),Y=(d==null?void 0:d.latencyMs)??null;for(const T of A){S.push({kind:"tool-invoke",id:`t${c.turnIndex}-invoke-${T.id}`,turnIndex:c.turnIndex,toolName:T.name,toolCallId:T.id,inputPreview:He(T.input),rawInput:T.input}),f++;const q=z.get(T.id);q&&S.push({kind:"tool-result",id:`t${c.turnIndex}-result-${T.id}`,turnIndex:c.turnIndex,toolName:T.name,toolCallId:T.id,resultPreview:Je(q.content),isError:q.isError,rawResult:q.content,durationMs:Y})}j.push({index:c.turnIndex,events:S,startOffsetMs:M,endOffsetMs:_,inputTokens:c.inputTokens,outputTokens:c.outputTokens,latencyMs:c.latencyMs,ttftMs:c.ttftMs,hasError:!!c.error,toolCallCount:A.length})}const v=r[r.length-1],x=(e.endedAt??v.timestamp+(v.latencyMs??0))-n;return{lanes:i,turns:j,sessionDurationMs:x,totalToolCalls:f,uniqueToolNames:o}}const U=64,ve=28,te=56,Xe=12,se=24,we=640;function R(e){return e==null?"–":e>=1e3?`${(e/1e3).toFixed(2)}s`:`${Math.round(e)}ms`}function Te(e){return e==null?"":e.toLocaleString()}function K(e,s){return e.length<=s?e:e.slice(0,s-1)+"…"}function Ve(e,s){const r=Math.max(s-se*2,200)/(e.length-1||1);return e.map((o,l)=>({id:o.id,label:o.label,sublabel:o.sublabel,x:se+r*l}))}function Ze(e){const s=[];let n=U;for(const r of e.turns){const o=n+ve/2;n+=ve;const l=r.events.map(a=>{const i=n+te/2;return n+=te,{turnIndex:r.index,y:i,event:a}});n+=Xe,s.push({turn:r,headerY:o,endY:n,rows:l})}return{turns:s,totalHeight:n+12}}function et(e){switch(e.kind){case"request":{const s=e.messageKind==="tool-results"?"tool results":e.messageKind==="mixed"?"mixed":e.messageKind==="user"?"user":"request",n=e.messageExcerpt?`${s}: ${K(e.messageExcerpt,80)}`:s,r=e.inputTokens!=null?`↑ ${Te(e.inputTokens)} tok`:void 0;return{src:"agent",tgt:"llm",label:n,sublabel:r,style:"solid",tone:"request"}}case"response":{const s=[];e.textExcerpt&&s.push(`"${K(e.textExcerpt,60)}"`),e.toolUseCount>0&&s.push(`${e.toolUseCount} tool_use`),e.stopReason&&s.push(e.stopReason);const n=s.join(" · ")||"(empty)",r=[];return e.outputTokens!=null&&r.push(`↓ ${Te(e.outputTokens)} tok`),e.ttftMs!=null&&r.push(`TTFT ${R(e.ttftMs)}`),e.latencyMs!=null&&r.push(R(e.latencyMs)),{src:"llm",tgt:"agent",label:n,sublabel:r.join(" · ")||void 0,style:"dashed",tone:"response"}}case"tool-invoke":return{src:"agent",tgt:"tools",label:e.inputPreview?`${e.toolName}(${K(e.inputPreview,80)})`:`${e.toolName}()`,style:"solid",tone:"invoke"};case"tool-result":{const s=e.isError?`error: ${K(e.resultPreview||"error",80)}`:K(e.resultPreview||"(empty)",100),n=e.durationMs!=null?R(e.durationMs):void 0;return{src:"tools",tgt:"agent",label:s,sublabel:n,style:"dashed",tone:e.isError?"error":"result",isError:e.isError}}case"error":return{src:"llm",tgt:"agent",label:`${e.statusCode??"ERR"} · ${K(e.message,100)}`,style:"dashed",tone:"error"}}}const fe={request:{stroke:"stroke-indigo-500",fill:"fill-indigo-500",text:"fill-indigo-700 dark:fill-indigo-300"},response:{stroke:"stroke-violet-500",fill:"fill-violet-500",text:"fill-violet-700 dark:fill-violet-300",activation:"fill-violet-400/40 dark:fill-violet-500/30"},invoke:{stroke:"stroke-amber-500",fill:"fill-amber-500",text:"fill-amber-700 dark:fill-amber-300"},result:{stroke:"stroke-emerald-500",fill:"fill-emerald-500",text:"fill-emerald-700 dark:fill-emerald-300",activation:"fill-emerald-400/40 dark:fill-emerald-500/25"},error:{stroke:"stroke-rose-500",fill:"fill-rose-500",text:"fill-rose-700 dark:fill-rose-300"}};function tt(e){const s=[];for(const n of e){let r=null;const o=new Map;for(const l of n.rows){const a=l.event;if(a.kind==="request")r=l.y;else if(a.kind==="response"&&r!=null)s.push({laneId:"llm",y1:r,y2:l.y,tone:"response"}),r=null;else if(a.kind==="tool-invoke")o.set(a.toolCallId,l.y);else if(a.kind==="tool-result"){const i=o.get(a.toolCallId);i!=null&&(s.push({laneId:"tools",y1:i,y2:l.y,tone:"result"}),o.delete(a.toolCallId))}}}return s}function st({y:e,arrow:s,laneByX:n,active:r,onClick:o,eventId:l}){const a=n[s.src],i=n[s.tgt],f=fe[s.tone],j=i>a?1:-1,v=6,x=a,m=i-j*v,c=(a+i)/2,d=e-8,u=e+16;return t.jsxs("g",{"data-event-id":l,className:"cursor-pointer",onClick:o,children:[t.jsx("rect",{x:Math.min(a,i)-12,y:e-te/2+2,width:Math.abs(i-a)+24,height:te-4,className:y("transition-colors",r?"fill-foreground/[0.06]":"fill-transparent hover:fill-foreground/[0.04]"),rx:6}),t.jsx("line",{x1:x,y1:e,x2:m,y2:e,className:y(f.stroke,"pointer-events-none"),strokeWidth:1.6,strokeDasharray:s.style==="dashed"?"5 4":void 0}),t.jsx("polygon",{points:`${i},${e} ${i-j*7},${e-4} ${i-j*7},${e+4}`,className:y(f.fill,"pointer-events-none")}),t.jsx("text",{x:c,y:d,textAnchor:"middle",className:y("pointer-events-none select-none text-[11px] font-medium",f.text),children:s.label}),s.sublabel&&t.jsx("text",{x:c,y:u,textAnchor:"middle",className:"pointer-events-none select-none fill-muted-foreground text-[10px]",children:s.sublabel})]})}function rt({lane:e}){var f;const s=e.id==="agent"?"fill-indigo-700 dark:fill-indigo-300":e.id==="llm"?"fill-violet-700 dark:fill-violet-300":"fill-amber-700 dark:fill-amber-300",n=e.id==="agent"?"fill-indigo-50 dark:fill-indigo-500/10":e.id==="llm"?"fill-violet-50 dark:fill-violet-500/10":"fill-amber-50 dark:fill-amber-500/10",r=e.id==="agent"?"stroke-indigo-300 dark:stroke-indigo-500/40":e.id==="llm"?"stroke-violet-300 dark:stroke-violet-500/40":"stroke-amber-300 dark:stroke-amber-500/40",o=14,l=Math.max(e.label.length,((f=e.sublabel)==null?void 0:f.length)??0),a=Math.max(96,l*7+o*2),i=e.sublabel?44:28;return t.jsxs("g",{children:[t.jsx("rect",{x:e.x-a/2,y:10,width:a,height:i,rx:6,className:y(n,r),strokeWidth:1}),t.jsx("text",{x:e.x,y:e.sublabel?24:28,textAnchor:"middle",className:y("select-none text-[12px] font-semibold",s),children:e.label}),e.sublabel&&t.jsx("text",{x:e.x,y:40,textAnchor:"middle",className:"select-none fill-muted-foreground text-[10px]",children:e.sublabel})]})}function ee({data:e}){return e==null?t.jsx("span",{className:"text-muted-foreground",children:"(empty)"}):t.jsx("pre",{className:"overflow-auto rounded bg-muted/60 p-3 text-[11px] leading-relaxed text-foreground",children:JSON.stringify(e,null,2)})}function w({label:e,value:s}){return t.jsxs("div",{className:"flex items-center justify-between text-xs",children:[t.jsx("span",{className:"text-muted-foreground",children:e}),t.jsx("span",{className:"font-medium tabular-nums",children:s})]})}function I({title:e,children:s}){return t.jsxs("div",{className:"space-y-1.5",children:[t.jsx("h4",{className:"text-[11px] font-semibold uppercase tracking-wide text-muted-foreground",children:e}),s]})}const nt={request:{label:"Request",classes:"bg-indigo-50 text-indigo-700 border-indigo-200 dark:bg-indigo-500/15 dark:text-indigo-300 dark:border-indigo-500/30"},response:{label:"Response",classes:"bg-violet-50 text-violet-700 border-violet-200 dark:bg-violet-500/15 dark:text-violet-300 dark:border-violet-500/30"},"tool-invoke":{label:"Tool Invoke",classes:"bg-amber-50 text-amber-700 border-amber-200 dark:bg-amber-500/15 dark:text-amber-300 dark:border-amber-500/30"},"tool-result":{label:"Tool Result",classes:"bg-emerald-50 text-emerald-700 border-emerald-200 dark:bg-emerald-500/15 dark:text-emerald-300 dark:border-emerald-500/30"},error:{label:"Error",classes:"bg-rose-50 text-rose-700 border-rose-200 dark:bg-rose-500/15 dark:text-rose-300 dark:border-rose-500/30"}};function ot({event:e,onClose:s}){b.useEffect(()=>{const o=l=>{l.key==="Escape"&&s()};return document.addEventListener("keydown",o),()=>document.removeEventListener("keydown",o)},[s]);const n=()=>e.kind==="request"?t.jsxs("div",{className:"space-y-4",children:[t.jsxs(I,{title:"Info",children:[t.jsx(w,{label:"Turn",value:`#${e.turnIndex+1}`}),t.jsx(w,{label:"Kind",value:e.messageKind}),e.inputTokens!=null&&t.jsx(w,{label:"Input tokens",value:e.inputTokens.toLocaleString()})]}),t.jsx(I,{title:"Messages",children:t.jsx(ee,{data:e.rawMessages})})]}):e.kind==="response"?t.jsxs("div",{className:"space-y-4",children:[t.jsxs(I,{title:"Metrics",children:[t.jsx(w,{label:"Turn",value:`#${e.turnIndex+1}`}),e.latencyMs!=null&&t.jsx(w,{label:"Latency",value:R(e.latencyMs)}),e.ttftMs!=null&&t.jsx(w,{label:"TTFT",value:R(e.ttftMs)}),e.outputTokens!=null&&t.jsx(w,{label:"Output tokens",value:e.outputTokens.toLocaleString()}),e.stopReason&&t.jsx(w,{label:"Stop reason",value:e.stopReason})]}),t.jsx(I,{title:"Content",children:t.jsx(ee,{data:e.rawContent})})]}):e.kind==="tool-invoke"?t.jsxs("div",{className:"space-y-4",children:[t.jsxs(I,{title:"Info",children:[t.jsx(w,{label:"Turn",value:`#${e.turnIndex+1}`}),t.jsx(w,{label:"Tool",value:e.toolName}),t.jsx(w,{label:"Call ID",value:e.toolCallId})]}),t.jsx(I,{title:"Input",children:t.jsx(ee,{data:e.rawInput})})]}):e.kind==="tool-result"?t.jsxs("div",{className:"space-y-4",children:[t.jsxs(I,{title:"Info",children:[t.jsx(w,{label:"Turn",value:`#${e.turnIndex+1}`}),t.jsx(w,{label:"Tool",value:e.toolName}),t.jsx(w,{label:"Status",value:e.isError?"error":"success"}),e.durationMs!=null&&t.jsx(w,{label:"Duration",value:R(e.durationMs)})]}),t.jsx(I,{title:"Result",children:t.jsx(ee,{data:e.rawResult})})]}):t.jsxs("div",{className:"space-y-4",children:[t.jsxs(I,{title:"Info",children:[t.jsx(w,{label:"Turn",value:`#${e.turnIndex+1}`}),e.statusCode!=null&&t.jsx(w,{label:"Status code",value:String(e.statusCode)})]}),t.jsx(I,{title:"Message",children:t.jsx("p",{className:"text-sm text-rose-600 dark:text-rose-400",children:e.message})})]}),r=nt[e.kind];return t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"fixed inset-0 z-30 bg-black/10",onClick:s,"aria-hidden":"true"}),t.jsxs("div",{className:"fixed right-0 top-0 z-40 flex h-full w-[440px] flex-col border-l border-border bg-background shadow-xl",children:[t.jsxs("div",{className:"flex items-center justify-between border-b border-border px-4 py-3",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:y("rounded border px-2 py-0.5 text-xs font-semibold",r.classes),children:r.label}),t.jsxs("span",{className:"text-sm font-medium text-foreground",children:["Turn ",e.turnIndex+1]})]}),t.jsx("button",{type:"button",onClick:s,className:"rounded p-1 text-muted-foreground hover:bg-muted",children:t.jsx(Se,{className:"h-4 w-4"})})]}),t.jsx("div",{className:"flex-1 overflow-auto p-4",children:n()})]})]})}function lt(){return t.jsxs("div",{className:"flex flex-col items-center justify-center gap-2 py-16 text-center",children:[t.jsx("p",{className:"text-sm font-medium text-muted-foreground",children:"No flow data available"}),t.jsx("p",{className:"max-w-xs text-xs text-muted-foreground/70",children:"This session has no parseable request/response payloads."})]})}function at({detail:e}){const{t:s}=D(),n=b.useMemo(()=>Ye(e),[e]),[r,o]=b.useState(null),l=b.useRef(null),[a,i]=b.useState(we);b.useLayoutEffect(()=>{const d=l.current;if(!d)return;const u=()=>i(Math.max(d.clientWidth,we));u();const N=new ResizeObserver(u);return N.observe(d),()=>N.disconnect()},[]);const f=b.useMemo(()=>Ve(n.lanes,a),[n.lanes,a]),j=b.useMemo(()=>{const d={};for(const u of f)d[u.id]=u.x;return d},[f]),{turns:v,totalHeight:x}=b.useMemo(()=>Ze(n),[n]),m=b.useMemo(()=>tt(v),[v]),c=b.useMemo(()=>{if(!r)return null;for(const d of v){const u=d.rows.find(N=>N.event.id===r);if(u)return u.event}return null},[r,v]);return n.turns.length?t.jsxs("div",{ref:l,className:"relative overflow-x-auto overflow-y-hidden",children:[t.jsxs("div",{className:"flex items-center gap-3 border-b border-border bg-secondary/30 px-4 py-1.5 text-[11px] text-muted-foreground",children:[t.jsxs("span",{children:[n.turns.length," turn",n.turns.length!==1?"s":""]}),n.totalToolCalls>0&&t.jsxs("span",{className:"rounded border border-amber-200 bg-amber-50 px-1.5 py-0.5 text-amber-700 dark:border-amber-500/30 dark:bg-amber-500/10 dark:text-amber-300",children:["⚡ ",n.totalToolCalls," tool call",n.totalToolCalls!==1?"s":""]}),t.jsxs("span",{className:"ml-auto tabular-nums",children:[R(n.sessionDurationMs)," total"]})]}),t.jsxs("svg",{width:a,height:x,viewBox:`0 0 ${a} ${x}`,className:"block",children:[f.map(d=>t.jsx("line",{x1:d.x,x2:d.x,y1:U,y2:x-8,className:"stroke-border",strokeWidth:1,strokeDasharray:"3 4"},d.id)),t.jsx("rect",{x:0,y:0,width:a,height:U,className:"fill-background"}),f.map(d=>t.jsx(rt,{lane:d},d.id)),t.jsx("line",{x1:0,x2:a,y1:U-.5,y2:U-.5,className:"stroke-border",strokeWidth:1}),m.map((d,u)=>{const N=j[d.laneId],p=d.tone==="response"?fe.response:fe.result;return t.jsx("rect",{x:N-5,y:d.y1,width:10,height:Math.max(d.y2-d.y1,4),rx:2,className:y(p.activation)},u)}),v.map(d=>{const u=d.turn,N=`${s("profiler.turn.title",{index:u.index+1})}`+(u.latencyMs!=null?` · ${R(u.latencyMs)}`:"")+(u.inputTokens!=null?` · ↑${u.inputTokens.toLocaleString()}`:"")+(u.outputTokens!=null?` ↓${u.outputTokens.toLocaleString()}`:"");return t.jsxs("g",{children:[t.jsx("line",{x1:se-8,x2:a-se+8,y1:d.headerY,y2:d.headerY,className:"stroke-border",strokeWidth:1}),t.jsx("g",{children:(()=>{const p=Math.max(120,N.length*6.2),M=(a-p)/2;return t.jsxs(t.Fragment,{children:[t.jsx("rect",{x:M,y:d.headerY-9,width:p,height:18,rx:9,className:"fill-muted stroke-border",strokeWidth:1}),t.jsx("text",{x:a/2,y:d.headerY+4,textAnchor:"middle",className:"select-none fill-muted-foreground text-[10px] font-semibold tracking-wide",children:N})]})})()}),t.jsxs("text",{x:4,y:d.headerY+4,className:"select-none fill-muted-foreground/60 text-[9px] tabular-nums",children:[(u.startOffsetMs/1e3).toFixed(2),"s"]}),d.rows.map(p=>{const M=et(p.event);return M?t.jsx(st,{eventId:p.event.id,y:p.y,arrow:M,laneByX:j,active:r===p.event.id,onClick:()=>o(_=>_===p.event.id?null:p.event.id)},p.event.id):null})]},u.index)})]}),c&&t.jsx(ot,{event:c,onClose:()=>o(null)})]}):t.jsx(lt,{})}function E(e){return e==null?"-":e>=1e3?`${(e/1e3).toFixed(2)}s`:`${Math.round(e)}ms`}function re(e){return e==null?"-":e>=1e3?`${(e/1e3).toFixed(1)}s`:`${Math.round(e)}ms`}function J(e){return e==null?"-":e.toLocaleString()}function ge(e){return e==null?"-":e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:e.toLocaleString()}function oe(e){return e.endedAt==null||e.turnCount===0?e.totalLatencyMs??0:e.endedAt-e.startedAt}function it(e){const s=e.sessionId;return s.length>18?`${s.slice(0,8)}…${s.slice(-6)}`:s}function dt(e){switch(e){case"claude-code":return"Claude Code";case"codex":return"Codex";case"opencode":return"OpenCode";case"anthropic-compatible":return"Anthropic Compatible";case"openai-compatible":return"OpenAI Compatible";default:return e||null}}function ct(e,s){const n=Math.max(0,Date.now()-e),r=Math.floor(n/6e4);if(r<1)return s("profiler.relativeTime.justNow");if(r<60)return s("profiler.relativeTime.minutesAgo",{count:r});const o=Math.floor(r/60);if(o<24)return s("profiler.relativeTime.hoursAgo",{count:o});const l=Math.floor(o/24);return s("profiler.relativeTime.daysAgo",{count:l})}function ut(e){if(!e)return null;try{return JSON.parse(e)}catch{return null}}function pe(e,s){if(Array.isArray(e)){for(const n of e)pe(n,s);return}if(e&&typeof e=="object"){const n=e,r=n.type;(r==="tool_use"||r==="tool_call"||r==="function_call"||r==="computer_call"||r==="web_search_call"||r==="file_search_call"||r==="mcp_call"||r==="custom_tool_call")&&s.push(n);const o=n.tool_calls;Array.isArray(o)&&s.push(...o);const l=n.content;if(Array.isArray(l)){for(const a of l)if(a&&typeof a=="object"){const i=a;i.type==="tool_use"&&s.push(i)}}for(const a of Object.values(n))pe(a,s)}}function ne(e){const s=[];return pe(ut(e.clientResponse),s),s}function Ie(e,s){const n=e.timestamp-s,r=n+(e.latencyMs??0);return`${(n/1e3).toFixed(3)}s → ${(r/1e3).toFixed(3)}s`}function he(e,s){return Be(e??null,s)}function xt(e,s){const n=new Blob([JSON.stringify(s,null,2)],{type:"application/json"}),r=URL.createObjectURL(n),o=document.createElement("a");o.href=r,o.download=e,o.click(),URL.revokeObjectURL(r)}function ue({tone:e="default",children:s}){return t.jsx("span",{className:y("inline-flex items-center rounded-full px-2.5 py-1 text-[11px] font-medium",e==="accent"?"bg-primary/10 text-primary":"bg-secondary text-muted-foreground"),children:s})}function mt({session:e,selected:s,index:n,onClick:r}){const{t:o}=D(),l=["bg-indigo-500","bg-emerald-500","bg-amber-500"],a=s?"bg-indigo-500":l[n%l.length],i=(e.totalInputTokens??0)+(e.totalOutputTokens??0);return t.jsxs("button",{type:"button",onClick:r,className:y("w-full border-b border-border/45 px-4 py-3 text-left transition-colors",s?"bg-secondary":"hover:bg-secondary/50"),children:[t.jsxs("div",{className:"flex items-center justify-between gap-3",children:[t.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[t.jsx("span",{className:y("h-2 w-2 flex-shrink-0 rounded-full",a)}),t.jsx("span",{className:y("truncate text-sm font-semibold",s?"text-primary":"text-foreground"),children:it(e)})]}),t.jsx("span",{className:"text-[11px] text-muted-foreground",children:ct(e.startedAt,o)})]}),t.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2 pl-4",children:[t.jsx(ue,{tone:s?"accent":"default",children:o("profiler.metricTurns",{count:e.turnCount})}),t.jsx(ue,{children:re(oe(e))}),t.jsx(ue,{children:o("profiler.metricTokens",{value:ge(i)})})]})]})}function xe({active:e,icon:s,label:n,onClick:r}){return t.jsxs("button",{type:"button",onClick:r,className:y("inline-flex h-8 items-center gap-1.5 rounded-full border px-3 text-xs font-medium transition-all",e?"border-primary/20 bg-primary/10 text-primary":"border-transparent bg-secondary text-muted-foreground hover:bg-secondary/80 hover:text-foreground"),children:[t.jsx(s,{className:"h-3.5 w-3.5"}),n]})}function me({active:e,label:s,count:n,onClick:r}){return t.jsxs("button",{type:"button",onClick:r,className:y("inline-flex h-7 items-center gap-1.5 rounded-full border px-3 text-[11px] font-medium transition-all",e?"border-primary/20 bg-primary/10 text-primary":"border-transparent bg-transparent text-muted-foreground hover:bg-secondary hover:text-foreground"),children:[t.jsx("span",{children:s}),typeof n=="number"&&t.jsx("span",{className:"rounded-full bg-amber-100 px-1.5 py-0.5 text-[11px] font-semibold text-amber-700",children:n})]})}function ft({detail:e,selectedTurn:s,onSelectTurn:n}){const{t:r}=D(),o=e.records;if(o.length===0)return t.jsx(H,{compact:!0,className:"min-h-[220px]",title:r("profiler.empty.noTurnsTitle"),description:r("profiler.empty.noTurnsDescription")});const l=oe(e),a=Math.max(1,...o.map(i=>Math.max(i.latencyMs??0,i.ttftMs??0,1)));return Math.max(1,...o.map(i=>ne(i).length)),t.jsxs("div",{className:"rounded-xl bg-card shadow-[var(--surface-shadow)]",children:[t.jsxs("div",{className:"flex items-center justify-between gap-4 border-b border-border/45 px-5 py-3.5",children:[t.jsx("p",{className:"text-xs text-muted-foreground",children:r("profiler.timeline.summary")}),t.jsxs("div",{className:"flex items-center gap-2 text-[11px]",children:[t.jsx("span",{className:"text-muted-foreground",children:r("profiler.timeline.mode")}),t.jsx("span",{className:"rounded-full border border-border bg-secondary/70 px-2.5 py-1 font-medium text-foreground",children:r("profiler.timeline.compressed")}),t.jsx("span",{className:"rounded-full border border-border bg-card px-2.5 py-1 font-medium text-foreground",children:r("profiler.timeline.sessionDuration",{duration:re(l)})})]})]}),t.jsxs("div",{className:"px-5 pb-4",children:[t.jsxs("div",{className:"mb-3 flex items-center justify-between text-[11px] text-muted-foreground/70",children:[t.jsx("span",{children:r("profiler.timeline.start")}),t.jsxs("span",{children:[(l/1e3).toFixed(1),"s"]})]}),t.jsx("div",{className:"grid gap-x-2 gap-y-5",style:{gridTemplateColumns:"repeat(10, minmax(0, 1fr))"},children:o.map((i,f)=>{const j=f===s,v=Math.max(i.latencyMs??0,1),x=`${Math.max(28,Math.min(100,v/a*100))}%`,m=i.ttftMs!=null?`${Math.max(0,Math.min(100,Math.min(i.ttftMs,a)/a*100))}%`:null,c=Math.max(0,i.timestamp-e.startedAt),d=ne(i);return t.jsxs("button",{type:"button",onClick:()=>n(f),className:y("rounded-xl border border-transparent bg-card px-2 py-2 text-left shadow-sm transition-all",j?"border-primary/20 bg-primary/5":"hover:bg-secondary/50"),title:r("profiler.turn.title",{index:i.turnIndex+1}),children:[t.jsx("div",{className:"flex min-w-0 items-center gap-2",children:t.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[t.jsx("span",{className:y("inline-flex h-5 min-w-5 items-center justify-center rounded-full border px-1.5 text-[11px] font-semibold",j?"border-primary/30 bg-primary/10 text-primary":"border-border bg-card text-foreground"),children:i.turnIndex+1}),t.jsx("span",{className:"truncate text-[15px] font-semibold text-foreground",children:re(i.latencyMs)})]})}),t.jsx("p",{className:"mt-1 text-[11px] text-muted-foreground",children:r("profiler.timeline.startAt",{time:(c/1e3).toFixed(1)})}),t.jsxs("div",{className:"mt-2",children:[t.jsx("div",{className:"flex items-center justify-between text-[11px] text-muted-foreground",children:t.jsxs("span",{children:[E(i.ttftMs)," TTFT"]})}),t.jsxs("div",{className:"relative mt-1 h-4 rounded-sm bg-secondary",children:[t.jsx("div",{className:"h-4 rounded-sm bg-primary/20",style:{width:x}}),m!=null&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"absolute top-[-3px] h-5 w-[3px] -translate-x-1/2 rounded-full bg-violet-500 ring-1 ring-white",style:{left:m}}),t.jsx("span",{className:"absolute top-[-6px] h-2.5 w-2.5 -translate-x-1/2 rounded-full border border-white bg-violet-500",style:{left:m}})]})]})]}),t.jsxs("div",{className:"mt-2",children:[t.jsxs("div",{className:"mb-1 flex items-center justify-between text-[11px] text-muted-foreground",children:[t.jsx("span",{children:r("profiler.timeline.tools")}),t.jsx("span",{children:d.length})]}),t.jsx("div",{className:"flex h-5 items-center gap-1",children:t.jsx("span",{className:y("inline-flex h-5 min-w-5 items-center justify-center rounded-md border text-[11px] font-semibold",d.length>0?"border-amber-400 bg-amber-200 text-amber-900":"border-border bg-card text-muted-foreground"),children:d.length})})]})]},i.id)})}),t.jsxs("div",{className:"mt-4 flex flex-wrap items-center gap-4 text-[11px] text-muted-foreground",children:[t.jsxs("span",{className:"flex items-center gap-1.5",children:[t.jsx("span",{className:"h-2.5 w-2.5 rounded-sm bg-blue-200"}),r("profiler.timeline.legend.totalLatency")]}),t.jsxs("span",{className:"flex items-center gap-1.5",children:[t.jsx("span",{className:"relative inline-block h-2.5 w-2.5 rounded-full border border-white bg-violet-500 ring-1 ring-violet-500/35"}),r("profiler.timeline.legend.firstToken")]}),t.jsxs("span",{className:"flex items-center gap-1.5",children:[t.jsx("span",{className:"h-2.5 w-2.5 rounded-sm border border-amber-400 bg-amber-200"}),r("profiler.timeline.legend.toolExecuting")]}),t.jsxs("span",{className:"flex items-center gap-1.5",children:[t.jsx("span",{className:"h-2.5 w-2.5 rounded-sm border border-rose-300 bg-rose-50"}),r("profiler.timeline.legend.selectedTurn")]})]})]})]})}function pt({detail:e,selectedTurn:s,detailTab:n,onDetailTabChange:r,onSelectTurn:o}){const{t:l}=D(),a=e.records[s];if(!a)return null;const i=ne(a),f=(a.inputTokens??0)+(a.outputTokens??0),j=n==="request"?he(a.clientRequest,l("profiler.payload.emptyRequest")):n==="response"?he(a.clientResponse,l("profiler.payload.emptyResponse")):i.length>0?JSON.stringify(i,null,2):l("profiler.payload.noToolCalls");return t.jsxs("div",{"data-testid":"profiler-turn-detail",className:"mt-3 shrink-0 rounded-xl bg-card shadow-[var(--surface-shadow)]",children:[t.jsxs("div",{className:"flex items-center justify-between gap-4 border-b border-border px-5 py-3",children:[t.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-2 text-xs",children:[t.jsx("span",{className:"rounded-full bg-primary px-2 py-1 font-semibold text-primary-foreground",children:l("profiler.turn.title",{index:a.turnIndex+1})}),t.jsx("span",{className:"text-muted-foreground",children:Ie(a,e.startedAt)}),t.jsxs("span",{className:"rounded-full bg-violet-50 border border-violet-200 px-2 py-1 font-semibold text-violet-700 dark:bg-violet-500/16 dark:border-violet-400/20 dark:text-violet-200",children:["TTFT ",E(a.ttftMs)]}),t.jsxs("span",{className:"rounded-full bg-sky-50 border border-sky-200 px-2 py-1 font-semibold text-sky-700 dark:bg-sky-500/16 dark:border-sky-400/20 dark:text-sky-200",children:[ge(f)," tokens"]})]}),t.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[t.jsx("button",{type:"button",onClick:()=>o(Math.max(0,s-1)),disabled:s===0,className:"rounded-full p-1.5 transition-colors hover:bg-secondary disabled:cursor-not-allowed disabled:opacity-40","aria-label":l("profiler.turn.previous"),children:t.jsx(Fe,{className:"h-4 w-4"})}),t.jsxs("span",{className:"min-w-10 text-center font-medium text-muted-foreground",children:[s+1," / ",e.records.length]}),t.jsx("button",{type:"button",onClick:()=>o(Math.min(e.records.length-1,s+1)),disabled:s===e.records.length-1,className:"rounded-full p-1.5 transition-colors hover:bg-secondary disabled:cursor-not-allowed disabled:opacity-40","aria-label":l("profiler.turn.next"),children:t.jsx(Le,{className:"h-4 w-4"})})]})]}),t.jsx("div",{className:"border-b border-border bg-secondary/30 px-5 py-2",children:t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[t.jsx(me,{active:n==="request",label:l("profiler.payload.request"),onClick:()=>r("request")}),t.jsx(me,{active:n==="response",label:l("profiler.payload.response"),onClick:()=>r("response")}),t.jsx(me,{active:n==="tools",label:l("profiler.payload.toolCalls"),count:i.length,onClick:()=>r("tools")})]})}),t.jsxs("div",{className:"bg-secondary/30 p-5",children:[t.jsx("pre",{className:"max-h-[420px] overflow-auto rounded-xl bg-[#1E1E2E] p-4 text-xs leading-5 text-slate-200",children:j}),a.error&&t.jsx("p",{className:"mt-3 rounded-lg border border-red-200 bg-red-50 px-3 py-2 text-xs text-red-700",children:a.error})]})]})}function ht({detail:e,selectedTurn:s,detailTab:n,onSelectTurn:r,onDetailTabChange:o}){return t.jsxs("div",{className:"flex min-h-full flex-col",children:[t.jsx(ft,{detail:e,selectedTurn:s,onSelectTurn:r}),t.jsx(pt,{detail:e,selectedTurn:s,detailTab:n,onDetailTabChange:o,onSelectTurn:r})]})}function Me({title:e,payload:s,accentClass:n,emptyLabel:r}){return t.jsxs("div",{className:"rounded-xl border border-white/45 bg-white/88 p-3 shadow-[0_12px_28px_rgba(15,23,42,0.06)] dark:border-white/10 dark:bg-slate-950/[0.58] dark:shadow-[0_12px_28px_rgba(0,0,0,0.28)]",children:[t.jsx("p",{className:y("mb-2 text-[11px] font-semibold uppercase tracking-wider",n),children:e}),t.jsx("pre",{className:"max-h-64 overflow-auto rounded-lg bg-slate-950/95 p-3 text-xs leading-5 text-slate-200",children:he(s,r)})]})}function B({label:e,value:s,sub:n,accentClass:r}){return t.jsxs("div",{className:"rounded-xl bg-card p-4 shadow-sm",children:[t.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-wider text-muted-foreground",children:e}),t.jsx("p",{className:y("metric-number mt-2 text-2xl font-semibold text-foreground",r),children:s}),n&&t.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:n})]})}function gt({record:e,sessionStart:s,expanded:n,onToggle:r}){const{t:o}=D(),l=ne(e);return t.jsxs("div",{className:"overflow-hidden rounded-xl bg-card shadow-sm",children:[t.jsxs("button",{type:"button",onClick:r,className:"flex w-full items-center gap-4 px-4 py-3 text-left transition-colors hover:bg-secondary/50",children:[t.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-3",children:[t.jsxs("span",{className:"rounded-full bg-primary px-2 py-0.5 text-[11px] font-semibold text-primary-foreground",children:["T",e.turnIndex+1]}),t.jsxs("div",{className:"min-w-0",children:[t.jsx("div",{className:"text-sm font-medium text-foreground",children:Ie(e,s)}),t.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-2 text-[11px] text-muted-foreground",children:[t.jsx("span",{children:o("profiler.breakdown.total",{value:E(e.latencyMs)})}),t.jsxs("span",{children:["TTFT ",E(e.ttftMs)]}),t.jsxs("span",{children:["TPOT ",e.tpotMs!=null?`${e.tpotMs.toFixed(1)} ms/tok`:"-"]}),t.jsxs("span",{children:["↑ ",J(e.inputTokens)]}),t.jsxs("span",{children:["↓ ",J(e.outputTokens)]}),t.jsx("span",{children:o("profiler.breakdown.toolCallsCount",{count:l.length})}),e.error&&t.jsx("span",{className:"rounded-full bg-red-50 px-2 py-0.5 font-medium text-red-600 dark:bg-red-500/14 dark:text-red-300",children:o("profiler.breakdown.error")})]})]})]}),t.jsx(De,{className:y("h-4 w-4 flex-shrink-0 text-muted-foreground/70 transition-transform",n&&"rotate-180")})]}),n&&t.jsxs("div",{className:"border-t border-border bg-secondary/30 p-4",children:[t.jsxs("div",{className:"grid gap-3 xl:grid-cols-2",children:[t.jsx(Me,{title:o("profiler.payload.request"),payload:e.clientRequest,accentClass:"text-blue-600",emptyLabel:o("profiler.payload.empty")}),t.jsx(Me,{title:o("profiler.payload.response"),payload:e.clientResponse,accentClass:"text-violet-600",emptyLabel:o("profiler.payload.empty")})]}),t.jsxs("div",{className:"mt-3 grid gap-3 xl:grid-cols-[minmax(0,1fr)_280px]",children:[t.jsxs("div",{className:"rounded-xl bg-card p-3 shadow-sm",children:[t.jsx("p",{className:"mb-2 text-[11px] font-semibold uppercase tracking-wider text-amber-600",children:o("profiler.payload.toolCalls")}),t.jsx("pre",{className:"max-h-64 overflow-auto rounded-lg bg-slate-950/95 p-3 text-xs leading-5 text-slate-200",children:l.length>0?JSON.stringify(l,null,2):o("profiler.payload.noToolCalls")})]}),t.jsxs("div",{className:"rounded-xl bg-card p-3 shadow-sm",children:[t.jsx("p",{className:"mb-2 text-[11px] font-semibold uppercase tracking-wider text-muted-foreground",children:o("profiler.breakdown.turnMetrics")}),t.jsxs("dl",{className:"grid grid-cols-2 gap-x-3 gap-y-2 text-xs",children:[t.jsxs("div",{children:[t.jsx("dt",{className:"text-muted-foreground",children:o("profiler.breakdown.duration")}),t.jsx("dd",{className:"mt-0.5 font-medium text-foreground",children:E(e.latencyMs)})]}),t.jsxs("div",{children:[t.jsx("dt",{className:"text-muted-foreground",children:"TTFT"}),t.jsx("dd",{className:"mt-0.5 font-medium text-foreground",children:E(e.ttftMs)})]}),t.jsxs("div",{children:[t.jsx("dt",{className:"text-muted-foreground",children:"TPOT"}),t.jsx("dd",{className:"mt-0.5 font-medium text-foreground",children:e.tpotMs!=null?`${e.tpotMs.toFixed(1)} ms/tok`:"-"})]}),t.jsxs("div",{children:[t.jsx("dt",{className:"text-muted-foreground",children:o("profiler.breakdown.status")}),t.jsx("dd",{className:"mt-0.5 font-medium text-foreground",children:e.statusCode??"-"})]}),t.jsxs("div",{children:[t.jsx("dt",{className:"text-muted-foreground",children:o("profiler.breakdown.input")}),t.jsx("dd",{className:"mt-0.5 font-medium text-foreground",children:J(e.inputTokens)})]}),t.jsxs("div",{children:[t.jsx("dt",{className:"text-muted-foreground",children:o("profiler.breakdown.output")}),t.jsx("dd",{className:"mt-0.5 font-medium text-foreground",children:J(e.outputTokens)})]})]}),e.error&&t.jsx("p",{className:"mt-3 rounded-lg border border-red-200 bg-red-50 px-3 py-2 text-xs text-red-700",children:e.error})]})]})]})]})}function bt({detail:e,expandedTurn:s,onToggleTurn:n}){const{t:r}=D();if(e.records.length===0)return t.jsx(H,{compact:!0,className:"min-h-[220px]",title:r("profiler.empty.noTurnsTitle"),description:r("profiler.empty.noTurnsDescription")});const o=oe(e),l=e.records.reduce((x,m)=>{const c=m.latencyMs??0,d=m.ttftMs??0;return x+Math.max(c-d,0)},0),a=o>0?(l/o*100).toFixed(1):"-",i=e.records.map(x=>x.ttftMs).filter(x=>x!=null),f=e.records.map(x=>x.tpotMs).filter(x=>x!=null),j=i.length>0?i.reduce((x,m)=>x+m,0)/i.length:null,v=f.length>0?f.reduce((x,m)=>x+m,0)/f.length:null;return t.jsxs("div",{className:"space-y-5 p-5",children:[t.jsxs("div",{className:"grid gap-3 sm:grid-cols-2 xl:grid-cols-6",children:[t.jsx(B,{label:r("profiler.breakdown.totalDuration"),value:E(o),sub:r("profiler.breakdown.turnsSub",{count:e.records.length})}),t.jsx(B,{label:r("profiler.breakdown.llmTime"),value:E(l),sub:r("profiler.breakdown.sessionShare",{value:a}),accentClass:"text-violet-700"}),t.jsx(B,{label:r("profiler.breakdown.avgTtft"),value:E(j)}),t.jsx(B,{label:r("profiler.breakdown.avgTpot"),value:v!=null?`${v.toFixed(1)} ms/tok`:"-"}),t.jsx(B,{label:r("profiler.breakdown.inputTokens"),value:J(e.totalInputTokens)}),t.jsx(B,{label:r("profiler.breakdown.outputTokens"),value:J(e.totalOutputTokens)})]}),t.jsxs("div",{className:"space-y-3",children:[t.jsx("div",{className:"flex items-center justify-between",children:t.jsxs("div",{children:[t.jsx("h3",{className:"text-sm font-semibold text-foreground",children:r("profiler.breakdown.perTurnTitle")}),t.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:r("profiler.breakdown.perTurnDescription")})]})}),e.records.map(x=>t.jsx(gt,{record:x,sessionStart:e.startedAt,expanded:s===x.turnIndex,onToggle:()=>n(x.turnIndex)},x.id))]})]})}function At(){var q,be,ye;const{t:e}=D(),s=Pe(),[n,r]=b.useState(null),[o,l]=b.useState("timeline"),[a,i]=b.useState("request"),[f,j]=b.useState(0),[v,x]=b.useState(0),[m,c]=b.useState(""),u=((q=ae({queryKey:$.profiler.status(),queryFn:()=>L.getStatus(),refetchInterval:3e3}).data)==null?void 0:q.active)??!1,N=ae({queryKey:$.profiler.sessions({}),queryFn:()=>L.listSessions({limit:100}),refetchInterval:u?2e3:!1}),p=((be=N.data)==null?void 0:be.items)??[],M=ae({queryKey:$.profiler.session(n),queryFn:()=>L.getSession(n),enabled:n!=null,refetchInterval:u&&n!=null?2e3:!1}),_=X({mutationFn:()=>L.start(),onSuccess:()=>{s.invalidateQueries({queryKey:$.profiler.status()}),s.invalidateQueries({queryKey:$.profiler.sessions({})})}}),S=X({mutationFn:()=>L.stop(),onSuccess:()=>{s.invalidateQueries({queryKey:$.profiler.status()}),s.invalidateQueries({queryKey:$.profiler.sessions({})})}}),G=X({mutationFn:g=>L.deleteSession(g),onSuccess:(g,F)=>{n===F&&r(null),s.invalidateQueries({queryKey:$.profiler.sessions({})})}}),le=X({mutationFn:()=>L.clearAll(),onSuccess:()=>{r(null),s.invalidateQueries({queryKey:$.profiler.sessions({})})}}),A=b.useMemo(()=>{const g=m.trim().toLowerCase();return g?p.filter(F=>F.sessionId.toLowerCase().includes(g)):p},[m,p]),P=m.trim().length>0,h=M.data,W=p.find(g=>g.id===n)??null,z=(h==null?void 0:h.records[f])??null,Y=dt(((ye=h==null?void 0:h.records[0])==null?void 0:ye.clientKind)??null);b.useEffect(()=>{n&&!p.some(g=>g.id===n)&&r(null)},[n,p]),b.useEffect(()=>{!n&&A.length>0&&r(A[0].id)},[A,n]),b.useEffect(()=>{j(0),x(0),i("request")},[n]),b.useEffect(()=>{if(!h){j(0),x(0);return}j(g=>Math.min(g,Math.max(h.records.length-1,0))),x(g=>g==null?0:Math.min(g,Math.max(h.records.length-1,0)))},[h]);const T=()=>{h&&xt(`profiler-${h.sessionId}.json`,h)};return t.jsxs("div",{className:"flex min-h-0 flex-1 flex-col gap-3",children:[t.jsx(Ke,{status:t.jsxs("span",{className:y("inline-flex items-center gap-1.5 text-xs",u?"text-red-600 dark:text-red-300":"text-muted-foreground"),children:[t.jsx("span",{className:y("inline-block h-1.5 w-1.5 rounded-full",u?"bg-red-500":"bg-muted-foreground/70")}),e(u?"profiler.status.recording":"profiler.status.idle")]}),info:t.jsx(ie,{variant:"secondary",className:"rounded-full px-2.5 py-0.5 text-[11px]",children:e("profiler.sessionsCount",{count:p.length})}),actions:t.jsxs(t.Fragment,{children:[t.jsx(O,{size:"sm",variant:u?"destructive":"default",onClick:()=>u?S.mutate():_.mutate(),disabled:_.isPending||S.isPending,children:e(u?"profiler.actions.stop":"profiler.actions.start")}),t.jsxs(O,{size:"sm",variant:"outline",onClick:T,disabled:!h,children:[t.jsx(Ae,{className:"mr-1.5 h-3.5 w-3.5"}),e("profiler.actions.export")]}),t.jsxs(O,{size:"sm",variant:"outline",onClick:()=>le.mutate(),disabled:p.length===0,className:"border-red-200 bg-red-50 text-red-700 hover:bg-red-100 hover:text-red-800 dark:border-red-400/20 dark:bg-red-500/14 dark:text-red-300 dark:hover:bg-red-500/20 dark:hover:text-red-200",children:[t.jsx(je,{className:"mr-1.5 h-3.5 w-3.5"}),e("profiler.actions.clear")]})]})}),t.jsxs("div",{className:"flex min-h-0 flex-1 flex-col gap-3 bg-background lg:flex-row lg:gap-0 lg:overflow-hidden",children:[t.jsxs("div",{className:"flex w-full flex-shrink-0 flex-col overflow-hidden rounded-[1.2rem] border border-white/70 bg-card/96 shadow-[0_20px_48px_-42px_rgba(15,23,42,0.26)] lg:w-[300px]",children:[t.jsxs("div",{className:"flex items-center justify-between border-b border-border/45 px-4 py-3",children:[t.jsx("span",{className:"text-sm font-semibold text-foreground",children:e("profiler.sessionsTitle")}),t.jsx(ie,{variant:"secondary",className:"rounded-full px-2 py-0.5",children:p.length})]}),t.jsxs("div",{className:"flex items-center gap-2 border-b border-border bg-secondary/50 px-3 py-2.5",children:[t.jsx($e,{className:"h-3.5 w-3.5 text-muted-foreground/70"}),t.jsx("input",{className:"w-full bg-transparent text-sm outline-none placeholder:text-muted-foreground/70",placeholder:e("profiler.searchPlaceholder"),value:m,onChange:g=>c(g.target.value)})]}),t.jsx("div",{className:"max-h-[240px] overflow-y-auto lg:min-h-0 lg:max-h-none lg:flex-1",children:N.isPending?t.jsx(ke,{compact:!0,className:"min-h-[160px]",label:e("common.loading")}):A.length===0?t.jsx(H,{compact:!0,className:"m-4 min-h-[160px]",title:e(P?"profiler.empty.searchTitle":u?"profiler.empty.waitingTitle":"profiler.empty.idleTitle"),description:e(P?"profiler.empty.searchDescription":u?"profiler.empty.waitingDescription":"profiler.empty.idleDescription"),action:P?void 0:u?t.jsx(O,{asChild:!0,variant:"ghost",size:"sm",children:t.jsx(Oe,{to:"/logs",children:e("profiler.empty.actions.logs")})}):t.jsx(O,{size:"sm",onClick:()=>_.mutate(),disabled:_.isPending,children:e("profiler.actions.start")})}):A.map((g,F)=>t.jsx(mt,{session:g,selected:n===g.id,index:F,onClick:()=>r(g.id)},g.id))})]}),t.jsx("div",{className:"flex min-w-0 flex-1 flex-col overflow-hidden rounded-[1.2rem] border border-white/70 bg-card/96 shadow-[0_20px_48px_-42px_rgba(15,23,42,0.26)] lg:ml-3",children:n?t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"flex items-center justify-between gap-4 border-b border-border bg-card px-5 py-3.5",children:[t.jsxs("div",{className:"flex min-w-0 items-center gap-2.5",children:[t.jsx("span",{className:"h-2.5 w-2.5 flex-shrink-0 rounded-full bg-indigo-500"}),t.jsx("span",{className:"truncate text-sm font-semibold text-foreground",children:(h==null?void 0:h.sessionId)??(W==null?void 0:W.sessionId)??n}),Y&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"text-muted-foreground/70",children:"·"}),t.jsx(ie,{variant:"secondary",className:"rounded-full px-2 py-0.5 text-[10px]",children:Y})]}),t.jsx("span",{className:"text-muted-foreground/70",children:"·"}),t.jsx("span",{className:"truncate text-sm text-muted-foreground",children:h?e("profiler.sessionSummary",{turns:h.turnCount,duration:re(oe(h)),tokens:ge((h.totalInputTokens??0)+(h.totalOutputTokens??0))}):e("profiler.loadingSession")})]}),t.jsx(O,{variant:"ghost",size:"sm",onClick:()=>n&&G.mutate(n),disabled:!n||G.isPending,className:"text-muted-foreground hover:text-red-700",children:t.jsx(je,{className:"h-3.5 w-3.5"})})]}),t.jsx("div",{className:"border-b border-border bg-secondary/30 px-5 py-2.5",children:t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[t.jsx(xe,{active:o==="timeline",icon:_e,label:e("profiler.tabs.timeline"),onClick:()=>l("timeline")}),t.jsx(xe,{active:o==="breakdown",icon:Re,label:e("profiler.tabs.breakdown"),onClick:()=>l("breakdown")}),t.jsx(xe,{active:o==="flow",icon:qe,label:e("profiler.tabs.flow"),onClick:()=>l("flow")})]})}),t.jsx("div",{"data-testid":"profiler-session-content",className:"min-h-0 flex-1 overflow-auto bg-secondary/20",children:M.isPending?t.jsx(ke,{compact:!0,className:"min-h-[240px]",label:e("profiler.loadingSession")}):M.isError?t.jsx(H,{compact:!0,className:"m-5 min-h-[220px]",tone:"danger",title:e("profiler.errors.loadFailed")}):h?o==="timeline"?t.jsx(ht,{detail:h,selectedTurn:f,detailTab:a,onSelectTurn:j,onDetailTabChange:i}):o==="flow"?t.jsx(at,{detail:h}):t.jsx(bt,{detail:h,expandedTurn:v,onToggleTurn:g=>x(F=>F===g?null:g)}):t.jsx(H,{compact:!0,className:"m-5 min-h-[220px]",title:e("profiler.errors.notFound")})}),z&&t.jsxs("span",{className:"sr-only",children:["Selected turn ",z.turnIndex+1]})]}):t.jsx("div",{className:"flex flex-1 items-center justify-center",children:t.jsx(H,{title:e("profiler.empty.selectTitle"),description:e("profiler.empty.selectDescription"),icon:t.jsx(Ee,{className:"h-5 w-5"})})})})]})]})}export{At as default};
@@ -1 +1 @@
1
- import{r as A,j as e,a7 as H,aH as be,aI as Y,ac as z,al as ve,a0 as Ne,S as ye}from"./vendor-DdPBfMMb.js";import{L as we}from"./router-D2Fb4U0L.js";import{C as ke}from"./ConfirmDialog-CPJRlYPi.js";import{P as Me}from"./PageToolbar-CDzxx36L.js";import{B as k,c as ne,a as Ce,s as Ee,T as Pe,d as De,e as Ae,f as Se}from"./app-CSrXQQoX.js";import{u as re}from"./useAppMutation-Db7I627Q.js";import{I as T}from"./input-k8bXT6Gd.js";import{L as P}from"./label-DDQd-HKi.js";import{S as oe,a as de,b as ce,c as me,d as F}from"./select-CrEhP63g.js";import{S as xe}from"./switch-DfFXX_ey.js";import{q as le,B as C}from"./queryKeys-0HDa7byL.js";import{u as O}from"./i18n-C8tBby0x.js";import{C as pe,a as ue}from"./card-D-kPX9ag.js";import{c as V}from"./global-CsDL9Nt2.js";import{D as Te,A as Oe,a as Re,b as Le,c as _e,d as $e,e as ze}from"./DialogShell-Dciv2SOq.js";import{P as Ve,a as Be,b as He}from"./popover-D4mE0Sqd.js";import{i as Ie,g as Fe,a as qe,C as Ge,O as Ke,u as Ue}from"./useModelManagementState-C-dnZNnf.js";import"./query-QCek5MsK.js";import"./radix-CtQBp6Ie.js";import"./gateway-Du8IjjRN.js";import"./useApiQuery-CvFOQBkt.js";const We=["anthropic","openai-auto","openai-chat","openai-responses"];function Qe({open:o,endpoint:s,onClose:g,onSuccess:r}){const{t:a}=O(),[d,p]=A.useState({id:"",label:"",paths:[{path:"",protocol:"openai-auto"}],enabled:!0});A.useEffect(()=>{if(s){const t=s.paths&&s.paths.length>0?s.paths:s.path&&s.protocol?[{path:s.path,protocol:s.protocol}]:[{path:"",protocol:"openai-auto"}];p({id:s.id,label:s.label,paths:t,enabled:s.enabled!==!1});return}p({id:"",label:"",paths:[{path:"",protocol:"openai-auto"}],enabled:!0})},[s,o]);const n=re({mutationFn:ne.create,invalidateKeys:[le.customEndpoints.all()],successToast:()=>({title:a("modelManagement.createEndpointSuccess")}),errorToast:t=>({title:a("modelManagement.createEndpointError",{error:t.message})}),onSuccess:async()=>{r(),g()}}),c=re({mutationFn:t=>ne.update(t.id,t.updates),invalidateKeys:[le.customEndpoints.all()],successToast:()=>({title:a("modelManagement.updateEndpointSuccess")}),errorToast:t=>({title:a("modelManagement.updateEndpointError",{error:t.message})}),onSuccess:async()=>{r(),g()}}),w=()=>{p(t=>({...t,paths:[...t.paths,{path:"",protocol:"anthropic"}]}))},m=t=>{d.paths.length!==1&&p(x=>({...x,paths:x.paths.filter((j,E)=>E!==t)}))},v=(t,x,j)=>{p(E=>{const D=[...E.paths];return D[t]={...D[t],[x]:j},{...E,paths:D}})},f=t=>{if(t==null||t.preventDefault(),!d.id.trim()||!d.label.trim())return;for(const j of d.paths)if(!j.path.trim())return;const x=d.paths.map(j=>({path:j.path.trim(),protocol:j.protocol}));if(s){c.mutate({id:s.id,updates:{label:d.label.trim(),paths:x,enabled:d.enabled}});return}n.mutate({id:d.id.trim(),label:d.label.trim(),paths:x,enabled:d.enabled})},h=n.isPending||c.isPending,l=d.paths.length===0?a("modelManagement.atLeastOnePath"):!d.id.trim()||!d.label.trim()?a("modelManagement.endpointValidationError"):d.paths.some(t=>!t.path.trim())?a("modelManagement.pathValidationError"):null;return o?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-40 bg-background/80 backdrop-blur-sm",onClick:g}),e.jsx("div",{className:"fixed inset-y-0 right-0 z-50 w-full max-w-md border-l border-border/45 bg-background/96 shadow-[var(--surface-shadow-lg)] backdrop-blur",children:e.jsxs("div",{className:"flex h-full flex-col",children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-border/45 bg-secondary/45 p-6 backdrop-blur-sm",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("h2",{className:"text-lg font-semibold tracking-[-0.02em]",children:a(s?"modelManagement.editEndpoint":"modelManagement.createEndpoint")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s?s.id:a("modelManagement.endpointRoutingHint")})]}),e.jsx(k,{variant:"ghost",size:"sm",onClick:g,className:"rounded-2xl bg-white/70",children:e.jsx(H,{className:"h-4 w-4"})})]}),e.jsxs("form",{onSubmit:f,className:"flex-1 space-y-6 overflow-y-auto p-6",children:[e.jsxs("div",{className:"grid gap-3 rounded-xl bg-secondary/50 p-4 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-[0.16em] text-muted-foreground",children:a("modelManagement.endpointId")}),e.jsx("p",{className:"truncate text-sm font-medium text-foreground",children:(s==null?void 0:s.id)||"new-endpoint"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-[0.16em] text-muted-foreground",children:a("modelManagement.endpointEnabled")}),e.jsx("p",{className:"text-sm font-medium text-foreground",children:d.enabled?a("common.status.enabled"):a("common.status.disabled")})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(P,{children:[a("modelManagement.endpointId")," ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(T,{value:d.id,onChange:t=>p(x=>({...x,id:t.target.value})),placeholder:a("modelManagement.endpointIdPlaceholder"),disabled:!!s,required:!0}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a("modelManagement.endpointIdHint")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(P,{children:[a("modelManagement.endpointLabel")," ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(T,{value:d.label,onChange:t=>p(x=>({...x,label:t.target.value})),placeholder:a("modelManagement.endpointLabelPlaceholder"),required:!0})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(P,{children:[a("modelManagement.endpointPaths")," ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsxs(k,{type:"button",variant:"ghost",size:"sm",onClick:w,children:[e.jsx(be,{className:"mr-1 h-3 w-3"}),a("modelManagement.addPath")]})]}),e.jsx("div",{className:"space-y-3",children:d.paths.map((t,x)=>e.jsxs("div",{className:"space-y-2 rounded-xl border border-transparent bg-card p-3 shadow-[var(--surface-shadow)]",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsx(T,{value:t.path,onChange:j=>v(x,"path",j.target.value),placeholder:a("modelManagement.endpointPathPlaceholder"),required:!0}),e.jsxs(oe,{value:t.protocol,onValueChange:j=>v(x,"protocol",j),children:[e.jsx(de,{children:e.jsx(ce,{})}),e.jsx(me,{children:We.map(j=>e.jsx(F,{value:j,children:a(j==="anthropic"?"modelManagement.protocolAnthropic":j==="openai-auto"?"modelManagement.protocolOpenAI":j==="openai-chat"?"modelManagement.protocolOpenAIChat":"modelManagement.protocolOpenAIResponses")},j))})]})]}),d.paths.length>1?e.jsx(k,{type:"button",variant:"ghost",size:"sm",onClick:()=>m(x),className:"text-destructive",children:e.jsx(H,{className:"h-4 w-4"})}):null]}),e.jsxs("div",{className:"space-y-1 text-xs text-muted-foreground",children:[x===0?e.jsx("p",{children:a("modelManagement.endpointPathHint")}):null,e.jsx("p",{children:a(`modelManagement.protocolHints.${t.protocol}`)})]})]},`${t.protocol}-${x}`))}),l?e.jsx("p",{className:"text-xs text-destructive",children:l}):null]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(xe,{id:"enabled",checked:d.enabled,onCheckedChange:t=>p(x=>({...x,enabled:t}))}),e.jsx(P,{htmlFor:"enabled",children:a("modelManagement.endpointEnabled")})]}),s?null:e.jsx("div",{className:"rounded-xl bg-accent p-4",children:e.jsx("p",{className:"text-sm text-primary",children:a("modelManagement.endpointRoutingHint")})})]}),e.jsxs("div",{className:"flex gap-3 border-t border-border/45 bg-secondary/45 p-6 backdrop-blur-sm",children:[e.jsx(k,{variant:"outline",className:"flex-1",onClick:g,disabled:h,children:a("common.cancel")}),e.jsx(k,{className:"flex-1",onClick:()=>f(),disabled:h,children:a(h?"common.saving":s?"common.save":"common.create")})]})]})})]}):null}function q(o,s){return s(o==="anthropic"?"modelManagement.protocolAnthropic":o==="openai-chat"?"modelManagement.protocolOpenAIChat":o==="openai-responses"?"modelManagement.protocolOpenAIResponses":"modelManagement.protocolOpenAI")}function Xe({activeTab:o,customEndpoints:s,customTabs:g,isDirtyByEndpoint:r,onDeleteEndpoint:a,onEditEndpoint:d,onSelectTab:p,systemTabs:n}){const{t:c}=O(),w=[...n,...g].find(m=>m.key===o)??null;return e.jsx(pe,{className:"overflow-hidden rounded-[1.35rem] border border-white/70 bg-card/95 shadow-[0_22px_56px_-46px_rgba(15,23,42,0.22)]",children:e.jsxs(ue,{className:"space-y-4 p-4 sm:p-5",children:[e.jsxs("div",{className:"grid gap-3 lg:grid-cols-[minmax(0,1fr)_minmax(280px,0.6fr)]",children:[e.jsxs("div",{className:"rounded-[1.1rem] bg-secondary/60 p-2.5",children:[e.jsx("div",{className:"mb-2 flex items-center justify-between px-1",children:e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-[0.16em] text-muted-foreground/75",children:c("modelManagement.overview.providerAndSystem")})}),e.jsx("div",{className:"grid gap-2 sm:grid-cols-2 xl:grid-cols-3",children:n.map(m=>{const v=o===m.key,f=m.key!=="providers"&&r[m.key];return e.jsxs("button",{type:"button",onClick:()=>p(m.key),"aria-pressed":v,className:V("group flex min-h-[76px] flex-col justify-between rounded-[0.95rem] px-3 py-3 text-left transition-all",v?"bg-card text-foreground shadow-[0_14px_34px_-28px_rgba(15,23,42,0.3)] ring-1 ring-primary/10":"bg-transparent text-muted-foreground hover:bg-card/58 hover:text-foreground"),children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("span",{className:"block truncate text-[15px] font-semibold text-foreground",children:m.label}),e.jsx("div",{className:"mt-0.5 text-[10px] uppercase tracking-[0.14em] text-muted-foreground/70",children:m.key==="providers"?c("modelManagement.overview.providerPoolTag"):c("modelManagement.overview.systemEndpointTag")})]}),f?e.jsx("span",{className:"mt-1 h-2.5 w-2.5 rounded-full bg-amber-500"}):null]}),e.jsxs("div",{className:"mt-2 flex items-center justify-between gap-3",children:[e.jsx("span",{className:"line-clamp-1 text-xs text-muted-foreground/70",children:m.description}),v?e.jsx("span",{className:"inline-flex h-6 w-6 shrink-0 items-center justify-center rounded-full bg-primary/10 text-primary",children:e.jsx(Y,{className:"h-3.5 w-3.5"})}):null]})]},m.key)})})]}),w?e.jsxs("div",{className:"flex min-h-[116px] flex-col justify-between rounded-[1.1rem] bg-[linear-gradient(135deg,hsl(var(--primary)/0.1),rgba(255,255,255,0.78))] p-4 ring-1 ring-primary/10 dark:bg-[linear-gradient(135deg,rgba(14,165,233,0.14),rgba(15,23,42,0.72))] dark:ring-white/10",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"inline-flex h-8 w-8 items-center justify-center rounded-xl bg-primary/10 text-primary",children:e.jsx(Y,{className:"h-4 w-4"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-[0.16em] text-primary/75",children:"Active workspace"}),e.jsx("p",{className:"truncate text-sm font-semibold text-foreground",children:w.label})]})]}),e.jsx("p",{className:"mt-3 line-clamp-2 text-xs leading-5 text-muted-foreground",children:w.description})]}):null]}),g.length>0?e.jsxs("div",{className:"space-y-2.5",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-[0.16em] text-muted-foreground/75",children:c("modelManagement.overview.customEndpoints")}),e.jsx("div",{className:"grid gap-3 md:grid-cols-2 2xl:grid-cols-3",children:g.map(m=>{const v=o===m.key,f=r[m.key],h=s.find(l=>l.id===m.key);return e.jsxs("div",{className:V("group relative flex min-w-0 flex-col gap-2.5 overflow-hidden rounded-[1.05rem] border px-3 py-3 text-left transition-all sm:px-3.5",v?"border-primary/20 bg-secondary/80 text-foreground shadow-[0_14px_34px_-30px_rgba(59,130,246,0.32)]":"border-border/55 bg-background/42 hover:bg-secondary/50"),children:[e.jsxs("button",{type:"button",onClick:()=>p(m.key),"aria-pressed":v,className:"min-w-0 flex-1 text-left",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"truncate text-sm font-semibold text-foreground sm:text-[15px]",title:m.label,children:m.label}),f?e.jsx("span",{className:"h-2 w-2 rounded-full bg-amber-500"}):null]}),e.jsxs("div",{className:"mt-1.5 flex items-end justify-between gap-3",children:[e.jsx("p",{className:"line-clamp-2 text-[11px] leading-4.5 text-muted-foreground/72 sm:line-clamp-1 sm:text-xs",children:m.description}),v?e.jsx("span",{className:"inline-flex h-6 w-6 shrink-0 items-center justify-center rounded-full bg-primary/10 text-primary",children:e.jsx(Y,{className:"h-3.5 w-3.5"})}):null]})]}),e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-1.5",children:[e.jsx(C,{variant:(h==null?void 0:h.enabled)===!1?"secondary":"success",className:"rounded-full border-0 px-2 py-0.5 text-[10px]",children:(h==null?void 0:h.enabled)===!1?c("modelManagement.overview.endpointDisabled"):c("modelManagement.overview.endpointEnabled")}),(m.protocols??[]).slice(0,2).map(l=>e.jsx(C,{variant:"outline",className:"max-w-[130px] truncate rounded-full text-[10px]",title:q(l,c),children:q(l,c)},`${m.key}-${l}`))]}),e.jsxs("div",{className:"min-w-0 rounded-[0.8rem] bg-secondary/55 px-2.5 py-2",children:[e.jsx("p",{className:"mb-1 text-[10px] font-medium uppercase tracking-[0.14em] text-muted-foreground/70",children:c("modelManagement.overview.endpointPaths")}),e.jsx("div",{className:"space-y-1",children:Je(h,c).map(l=>e.jsx("p",{className:"truncate text-xs font-medium text-foreground",title:l,children:l},l))})]}),e.jsxs("div",{className:"grid grid-cols-[1fr_auto] gap-2",children:[e.jsx(k,{variant:"ghost",size:"sm",className:"h-7 justify-start rounded-full px-2 text-[11px]",disabled:!h,onClick:()=>{h&&d(h)},children:c("common.edit")}),m.canDelete?e.jsx("button",{type:"button",onClick:l=>{l.stopPropagation(),h&&a({kind:"endpoint",endpoint:h})},className:"flex h-7 w-full items-center justify-center rounded-md text-muted-foreground transition hover:bg-destructive/10 hover:text-destructive sm:w-7",title:c("common.delete"),children:e.jsx(H,{className:"h-3.5 w-3.5"})}):null]}),m.canDelete?null:e.jsx("div",{className:"text-[11px] text-muted-foreground/70",children:c("modelManagement.overview.endpointManagedExternally")})]},m.key)})})]}):null]})})}function Je(o,s){var g;if(!o)return[s("common.noData")];if((g=o.paths)!=null&&g.length){const r=o.paths.slice(0,2).map(a=>`${a.path} · ${q(a.protocol,s)}`);return o.paths.length>2&&r.push(s("modelManagement.overview.endpointMorePaths",{count:o.paths.length-2})),r}return o.path?[`${o.path} · ${q(o.protocol??"anthropic",s)}`]:[s("common.noData")]}function Ye({dialog:o,currentRoutes:s,onConfirm:g,onClose:r}){const{t:a}=O();if(!o)return null;const{endpoint:d,preset:p}=o,n=p.modelRoutes??{},c={};for(const l of s){const t=l.source.trim(),x=l.target.trim();t&&x&&(c[t]=x)}const w=new Set([...Object.keys(c),...Object.keys(n)]),m=[],v=[],f=[];for(const l of w){const t=l in c,x=l in n;x&&!t?m.push([l,n[l]]):t&&!x?v.push([l,c[l]]):t&&x&&c[l]!==n[l]&&f.push([l,c[l],n[l]])}const h=m.length>0||v.length>0||f.length>0;return e.jsx(Te,{open:!0,onOpenChange:l=>!l&&r(),children:e.jsxs(Oe,{className:"max-w-2xl",children:[e.jsxs(Re,{children:[e.jsx(Le,{children:a("modelManagement.presets.diffTitle")}),e.jsx(_e,{children:a("modelManagement.presets.diffDescription",{name:p.name})})]}),e.jsx($e,{children:h?e.jsxs("div",{className:"max-h-80 space-y-2 rounded-xl bg-secondary/50 p-3 text-sm",children:[m.map(([l,t])=>e.jsxs("div",{className:"flex items-center gap-2 rounded-xl bg-emerald-50 px-2 py-1.5 text-emerald-800 dark:bg-emerald-950 dark:text-emerald-200",children:[e.jsx(C,{variant:"outline",className:"border-emerald-300 text-xs dark:border-emerald-700",children:a("modelManagement.presets.diffAdded")}),e.jsx("span",{className:"truncate",children:l}),e.jsx(z,{className:"h-3 w-3 flex-shrink-0"}),e.jsx("span",{className:"truncate",children:t})]},`add-${l}`)),v.map(([l,t])=>e.jsxs("div",{className:"flex items-center gap-2 rounded-xl bg-red-50 px-2 py-1.5 text-red-800 dark:bg-red-950 dark:text-red-200",children:[e.jsx(C,{variant:"outline",className:"border-red-300 text-xs dark:border-red-700",children:a("modelManagement.presets.diffRemoved")}),e.jsx("span",{className:"truncate",children:l}),e.jsx(z,{className:"h-3 w-3 flex-shrink-0"}),e.jsx("span",{className:"truncate",children:t})]},`rm-${l}`)),f.map(([l,t,x])=>e.jsxs("div",{className:"flex items-center gap-2 rounded-xl bg-amber-50 px-2 py-1.5 text-amber-800 dark:bg-amber-950 dark:text-amber-200",children:[e.jsx(C,{variant:"outline",className:"border-amber-300 text-xs dark:border-amber-700",children:a("modelManagement.presets.diffChanged")}),e.jsx("span",{className:"truncate",children:l}),e.jsx(z,{className:"h-3 w-3 flex-shrink-0"}),e.jsx("span",{className:"truncate line-through opacity-60",children:t}),e.jsx(z,{className:"h-3 w-3 flex-shrink-0"}),e.jsx("span",{className:"truncate",children:x})]},`chg-${l}`))]}):e.jsx("p",{className:"rounded-xl bg-secondary/50 py-8 text-center text-sm text-muted-foreground",children:a("modelManagement.presets.diffEmpty")})}),e.jsxs(ze,{children:[e.jsx(k,{variant:"outline",onClick:r,children:a("common.cancel")}),e.jsx(k,{onClick:()=>g(d,p),disabled:!h,children:a("modelManagement.presets.diffConfirm")})]})]})})}const ie=6;function Ze({value:o,onChange:s,options:g,disabled:r,placeholder:a}){const{t:d}=O(),[p,n]=A.useState(!1),[c,w]=A.useState(""),m=A.useRef(null),v=A.useRef(!1),[f,h]=Ce(Ee.modelManagement.recentRouteTargets,[]),l=A.useMemo(()=>{const i=new Map;for(const b of g)i.set(b.value,b);return i},[g]),t=(i,b)=>b?[i.label,i.value,i.providerId??"",i.providerLabel??"",i.modelId??"",i.modelLabel??""].join(" ").toLowerCase().includes(b):!0,x=A.useMemo(()=>{const i=c.trim().toLowerCase(),b=g.filter(y=>t(y,i)),S=f.map(y=>l.get(y)??(i?void 0:{value:y,label:y,kind:"custom"})).filter(y=>!!y).filter(y=>t(y,i)).slice(0,ie),R=[];S.length>0&&R.push({key:"recent",label:d("modelManagement.targetPicker.recent"),options:S});const L=new Map,_=[];for(const y of b){if(y.kind==="custom"||!y.providerId){_.push(y);continue}const B=`provider:${y.providerId}`,I=L.get(B);I?I.options.push(y):L.set(B,{key:B,label:y.providerLabel??y.providerId,options:[y]})}return R.push(...L.values()),_.length>0&&R.push({key:"custom",label:d("modelManagement.targetPicker.custom"),options:_,muted:!0}),R},[l,g,f,c,d]),j=x.reduce((i,b)=>i+b.options.length,0),E=i=>{s(i),h(b=>[i,...b.filter(S=>S!==i)].slice(0,ie)),w(""),v.current=!0,typeof document<"u"&&document.activeElement instanceof HTMLElement&&document.activeElement.blur(),n(!1),typeof window<"u"?window.requestAnimationFrame(()=>{v.current=!1}):v.current=!1},D=i=>i.kind==="passthrough"?d("modelManagement.targetPicker.passthrough"):i.kind==="custom"?d("modelManagement.targetPicker.customValue"):d("modelManagement.targetPicker.model"),G=i=>i.kind==="passthrough"||i.kind==="custom"?i.label:i.modelLabel??i.label;return e.jsxs(Ve,{open:p,onOpenChange:i=>{i&&v.current||(n(i),i&&w(""))},children:[e.jsx(Be,{asChild:!0,children:e.jsx(T,{value:o,onChange:i=>{s(i.target.value),w(i.target.value),p||n(!0)},onFocus:()=>{w(""),n(!0)},onClick:()=>{p||n(!0)},placeholder:a,disabled:r,autoComplete:"off"})}),e.jsxs(He,{className:"flex max-h-[min(28rem,var(--radix-popover-content-available-height))] flex-col overflow-hidden rounded-xl border border-[color:var(--surface-border)] bg-popover/96 p-0 shadow-[var(--surface-shadow-lg)] backdrop-blur",style:{width:"max(var(--radix-popover-trigger-width), 360px)"},align:"start",onOpenAutoFocus:i=>{var b;i.preventDefault(),(b=m.current)==null||b.focus()},children:[e.jsxs("div",{className:"space-y-2 border-b border-border/70 px-3 py-3",children:[e.jsx(T,{ref:m,value:c,onChange:i=>w(i.target.value),placeholder:d("modelManagement.targetPicker.searchPlaceholder"),className:"h-9",autoComplete:"off"}),e.jsx("div",{className:"text-xs text-muted-foreground",children:c.trim()?d("modelManagement.targetPicker.matchCount",{count:j}):d("modelManagement.targetPicker.helper")})]}),j===0?e.jsx("div",{className:"px-3 py-4 text-center text-xs text-muted-foreground",children:d("common.noMatches")}):e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto p-1.5",children:x.map(i=>e.jsxs("div",{className:"py-1",children:[e.jsxs("div",{className:V("sticky top-0 z-10 flex items-center justify-between bg-popover/95 px-2 py-1 text-[11px] font-semibold uppercase tracking-wide text-muted-foreground backdrop-blur",i.muted&&"opacity-80"),children:[e.jsx("span",{className:"truncate",children:i.label}),e.jsx("span",{children:i.options.length})]}),e.jsx("div",{className:"space-y-1",children:i.options.map(b=>e.jsxs("button",{type:"button",className:V("flex w-full min-w-0 items-center gap-2 rounded-lg px-3 py-2 text-left text-sm transition-colors hover:bg-accent/80 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",b.value===o.trim()&&"bg-accent/90 text-accent-foreground"),onMouseDown:S=>{S.preventDefault()},onClick:()=>E(b.value),children:[e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate font-medium",children:G(b)}),e.jsx("span",{className:"block truncate text-xs text-muted-foreground",children:b.value})]}),e.jsxs("span",{className:"flex shrink-0 items-center gap-1",children:[b.isDefault?e.jsx(C,{variant:"secondary",className:"text-[10px]",children:d("modelManagement.targetPicker.default")}):null,e.jsx(C,{variant:b.kind==="passthrough"?"outline":"secondary",className:"text-[10px]",children:D(b)})]})]},`${i.key}-${b.value}`))})]},i.key))})]})]})}function es({endpoint:o,tabs:s,customEndpoints:g,config:r,routes:a,routeError:d,savingRoute:p,isDirty:n,presets:c,presetName:w,presetError:m,savingPreset:v,applyingPreset:f,deletingPreset:h,presetsExpanded:l,savingClaudeValidation:t,savingCompatibilityPolicy:x,providerModelOptions:j,onTogglePresetsExpanded:E,onPresetNameChange:D,onSavePreset:G,onRequestPresetDiff:i,onRequestDeletePreset:b,onValidationModeChange:S,onCompatibilityEnabledChange:R,onRouteChange:L,onRemoveRoute:_,onAddSuggestion:y,onAddRoute:B,onResetRoutes:I,onSaveRoutes:he}){var ae,te;const{t:u}=O(),M=s.find(N=>N.key===o),K=((ae=M==null?void 0:M.protocols)==null?void 0:ae.includes("anthropic"))??o==="anthropic"?Ge:Ke,ge=(M==null?void 0:M.label)??o;(M==null?void 0:M.isSystem)===!1?M.description:u(`settings.routing.descriptionByEndpoint.${o}`);const U=`route-source-${o}`,Z=Ie(o,g),ee=((te=M==null?void 0:M.protocols)==null?void 0:te.some(N=>N.startsWith("openai")))??o==="openai",W=Fe(o,r,g),Q=qe(o,r,g),X=Z?(W==null?void 0:W.mode)??"off":"off",se=ee?(Q==null?void 0:Q.enabled)??!1:!1,fe=new Set(a.map(N=>N.source.trim()).filter(Boolean)),je=`modelManagement.claudeValidation.options.${X}.description`;return e.jsx(pe,{children:e.jsxs(ue,{className:"space-y-6 pt-6",children:[e.jsx("div",{className:"rounded-full bg-secondary px-4 py-3 text-xs text-muted-foreground",children:u("settings.routing.wildcardHint")}),Z?e.jsx("div",{className:"rounded-xl border border-primary/12 bg-[linear-gradient(135deg,hsl(var(--primary)/0.08),hsl(var(--accent)/0.72))] p-4 shadow-[var(--surface-shadow)] dark:border-sky-300/12 dark:bg-[linear-gradient(135deg,rgba(14,165,233,0.12),rgba(15,23,42,0.72))]",children:e.jsxs("div",{className:"flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-sm font-medium text-primary dark:text-sky-100",children:u("modelManagement.claudeValidation.title")}),e.jsx("p",{className:"max-w-2xl text-xs leading-5 text-muted-foreground dark:text-slate-300",children:u("modelManagement.claudeValidation.description")})]}),e.jsxs("div",{className:"flex w-full max-w-xs flex-col gap-2 self-start sm:self-auto",children:[e.jsx(P,{className:"text-[11px] font-semibold uppercase tracking-[0.16em] text-primary/70 dark:text-sky-200/75",children:u("modelManagement.claudeValidation.modeLabel")}),e.jsxs(oe,{value:X,onValueChange:N=>S(N),disabled:t,children:[e.jsx(de,{className:"border-primary/15 bg-card/90 dark:border-white/10 dark:bg-slate-950/50",children:e.jsx(ce,{})}),e.jsxs(me,{children:[e.jsx(F,{value:"off",children:u("modelManagement.claudeValidation.options.off.label")}),e.jsx(F,{value:"anthropic-strict",children:u("modelManagement.claudeValidation.options.anthropic-strict.label")}),e.jsx(F,{value:"claude-code",children:u("modelManagement.claudeValidation.options.claude-code.label")})]})]}),e.jsx("span",{className:V("text-xs",X==="off"?"text-muted-foreground dark:text-slate-400":"text-primary/80 dark:text-sky-200/80"),children:u(je)})]})]})}):null,ee?e.jsx("div",{className:"rounded-xl border border-primary/12 bg-[linear-gradient(135deg,hsl(var(--primary)/0.08),hsl(var(--accent)/0.72))] p-4 shadow-[var(--surface-shadow)] dark:border-sky-300/12 dark:bg-[linear-gradient(135deg,rgba(14,165,233,0.12),rgba(15,23,42,0.72))]",children:e.jsxs("div",{className:"flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-sm font-medium text-primary dark:text-sky-100",children:u("modelManagement.openaiCompatibility.title")}),e.jsx("p",{className:"max-w-2xl text-xs leading-5 text-muted-foreground dark:text-slate-300",children:u("modelManagement.openaiCompatibility.description")})]}),e.jsx("div",{className:"flex w-full max-w-xs flex-col gap-2 self-start sm:self-auto",children:e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-lg border border-primary/12 bg-card/85 px-3 py-2 dark:border-white/10 dark:bg-slate-950/50",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(P,{className:"text-[11px] font-semibold uppercase tracking-[0.16em] text-primary/70 dark:text-sky-200/75",children:u("modelManagement.openaiCompatibility.toggleLabel")}),e.jsx("p",{className:"text-xs text-muted-foreground dark:text-slate-300",children:u(se?"modelManagement.openaiCompatibility.enabledHint":"modelManagement.openaiCompatibility.disabledHint")})]}),e.jsx(xe,{checked:se,onCheckedChange:R,disabled:x,"aria-label":u("modelManagement.openaiCompatibility.toggleLabel")})]})})]})}):null,d?e.jsx("p",{className:"text-sm text-destructive",children:d}):null,e.jsx(ss,{presets:c,presetName:w,presetError:m,savingPreset:v,applyingPreset:f,deletingPreset:h,expanded:l,onToggleExpanded:E,onPresetNameChange:D,onSavePreset:G,onRequestPresetDiff:i,onRequestDeletePreset:b}),e.jsxs("div",{className:"space-y-3 rounded-xl bg-secondary/50 p-4",children:[e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(P,{className:"text-sm font-semibold text-foreground",children:u("modelManagement.routesEditorTitle")}),e.jsxs(C,{variant:"outline",children:[a.length," active"]})]}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:u("modelManagement.overview.routesEditorHint")})]}),e.jsxs("div",{className:"self-start rounded-full bg-card px-3 py-2 text-[11px] font-medium text-muted-foreground",children:["Active workspace · ",ge]})]}),a.length===0?e.jsxs("div",{className:"rounded-xl border-2 border-dashed border-border/30 bg-background/60 p-12 text-center text-sm text-muted-foreground",children:[e.jsx("p",{className:"font-medium",children:u("settings.routing.empty")}),e.jsx("p",{className:"mt-2 text-xs",children:u("modelManagement.emptyRoutesHint")})]}):e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"hidden grid-cols-[minmax(0,1fr)_auto_minmax(0,1fr)_auto] items-center gap-3 px-1 text-xs font-medium text-muted-foreground md:grid",children:[e.jsx("span",{children:u("settings.routing.source")}),e.jsx("span",{}),e.jsx("span",{children:u("settings.routing.target")}),e.jsx("span",{})]}),a.map((N,$)=>e.jsxs("div",{className:"rounded-xl bg-card p-3 shadow-sm",children:[e.jsxs("div",{className:"mb-3 flex items-center justify-between md:hidden",children:[e.jsxs(C,{variant:"outline",className:"text-[11px]",children:["#",$+1]}),e.jsx(k,{variant:"ghost",size:"icon",className:"h-8 w-8 text-muted-foreground hover:text-destructive",onClick:()=>_(N.id),disabled:p,children:e.jsx(H,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"grid gap-3 md:grid-cols-[minmax(0,1fr)_auto_minmax(0,1fr)_auto] md:items-center",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(P,{className:"text-[11px] uppercase tracking-[0.16em] text-muted-foreground md:hidden",children:u("settings.routing.source")}),e.jsx(T,{value:N.source,onChange:J=>L(N.id,"source",J.target.value),placeholder:u("settings.routing.sourcePlaceholder"),list:U,disabled:p,"aria-label":`route-source-${$+1}`})]}),e.jsx(z,{className:"hidden h-4 w-4 flex-shrink-0 text-muted-foreground md:block"}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(P,{className:"text-[11px] uppercase tracking-[0.16em] text-muted-foreground md:hidden",children:u("settings.routing.target")}),e.jsx(Ze,{value:N.target,onChange:J=>L(N.id,"target",J),options:j,disabled:p,placeholder:u("settings.routing.targetPlaceholder")})]}),e.jsx(k,{variant:"ghost",size:"icon",className:"hidden h-8 w-8 text-muted-foreground hover:text-destructive md:inline-flex",onClick:()=>_(N.id),disabled:p,children:e.jsx(H,{className:"h-4 w-4"})})]})]},N.id))]})]}),e.jsxs("div",{className:"flex flex-col gap-3 rounded-xl bg-card p-4 shadow-[var(--surface-shadow)] md:flex-row md:items-center md:justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-sm font-medium",children:u("modelManagement.actions.footerTitle")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:u(n?"modelManagement.actions.footerDirtyHint":"modelManagement.actions.footerSavedHint")})]}),e.jsxs("div",{className:"grid gap-2 sm:grid-cols-3 md:flex md:flex-wrap md:items-center",children:[e.jsx(k,{variant:"outline",size:"sm",onClick:B,disabled:p,className:"w-full",children:u("settings.routing.add")}),e.jsx(k,{variant:"outline",size:"sm",onClick:I,disabled:p||!n,className:"w-full",children:u("common.actions.reset")}),e.jsxs(k,{size:"sm",onClick:he,disabled:p,className:"relative w-full",children:[u(p?"common.actions.saving":"modelManagement.actions.saveRoutes"),n?e.jsx("span",{className:"absolute -right-1 -top-1 h-2 w-2 rounded-full bg-amber-500"}):null]})]})]}),e.jsxs("div",{className:"space-y-3 rounded-xl bg-secondary/50 p-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(P,{className:"text-sm font-medium text-foreground",children:u("settings.routing.suggested")}),e.jsx(C,{variant:"outline",className:"text-[11px]",children:K.length})]}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:u("modelManagement.overview.suggestionHint")})]}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:K.map(N=>{const $=fe.has(N);return e.jsx(k,{variant:$?"ghost":"outline",size:"sm",onClick:()=>y(N),disabled:p||$,className:V("h-7 rounded-md px-2.5 text-[11px] font-normal",$?"opacity-45":"bg-background/70"),children:N},`${o}-${N}`)})})]}),e.jsx("datalist",{id:U,children:K.map(N=>e.jsx("option",{value:N},`${U}-${N}`))})]})})}function ss({presets:o,presetName:s,presetError:g,savingPreset:r,applyingPreset:a,deletingPreset:d,expanded:p,onToggleExpanded:n,onPresetNameChange:c,onSavePreset:w,onRequestPresetDiff:m,onRequestDeletePreset:v}){const{t:f}=O();return e.jsxs("div",{className:"rounded-xl bg-card shadow-[var(--surface-shadow)]",children:[e.jsx("button",{type:"button",className:"flex w-full items-center justify-between gap-3 rounded-xl p-4 text-left transition-colors hover:bg-accent",onClick:n,children:e.jsxs("div",{className:"flex items-center gap-2",children:[p?e.jsx(ve,{className:"h-4 w-4"}):e.jsx(Ne,{className:"h-4 w-4"}),e.jsx("h3",{className:"font-medium",children:f("modelManagement.presets.title")}),e.jsx(C,{variant:"secondary",className:"text-xs",children:o.length})]})}),p?e.jsxs("div",{className:"space-y-4 border-t border-border/45 px-4 pb-4 pt-3",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:f("modelManagement.presets.description")}),e.jsxs("div",{className:"flex flex-col gap-3 md:flex-row md:items-center",children:[e.jsx(T,{value:s,onChange:h=>c(h.target.value),placeholder:f("modelManagement.presets.namePlaceholder"),disabled:r,className:"w-full md:w-48"}),e.jsx(k,{onClick:w,disabled:r,className:"w-full md:w-auto",children:f(r?"modelManagement.presets.saving":"modelManagement.presets.save")})]}),g?e.jsx("p",{className:"text-sm text-destructive",children:g}):null,o.length===0?e.jsx("p",{className:"py-4 text-center text-sm text-muted-foreground",children:f("modelManagement.presets.empty")}):e.jsx(Pe,{children:e.jsx("div",{className:"grid gap-2 sm:grid-cols-2 lg:grid-cols-3",children:o.map(h=>{const l=a===h.name,t=d===h.name,x=Object.entries(h.modelRoutes??{}),j=x.length;return e.jsxs("div",{className:"flex flex-col gap-3 rounded-xl bg-secondary/50 px-4 py-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs(De,{children:[e.jsx(Ae,{asChild:!0,children:e.jsxs("div",{className:"min-w-0 flex-1 cursor-default",children:[e.jsx("span",{className:"block truncate text-sm font-medium",children:h.name}),e.jsx(C,{variant:"outline",className:"mt-1 text-xs",children:j>0?f("modelManagement.presets.rulesCount",{count:j}):f("modelManagement.presets.noRules")})]})}),j>0?e.jsx(Se,{side:"bottom",className:"max-w-xs",children:e.jsxs("div",{className:"space-y-1 text-xs",children:[x.slice(0,5).map(([E,D])=>e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"truncate",children:E}),e.jsx(z,{className:"h-3 w-3 flex-shrink-0"}),e.jsx("span",{className:"truncate",children:D})]},E)),j>5?e.jsxs("div",{className:"text-muted-foreground",children:["…+",j-5]}):null]})}):null]}),e.jsxs("div",{className:"grid flex-shrink-0 gap-2 sm:flex sm:items-center",children:[e.jsx(k,{size:"sm",onClick:()=>m(h),disabled:l||t,className:"w-full sm:w-auto",children:f(l?"modelManagement.presets.applying":"modelManagement.presets.apply")}),e.jsx(k,{variant:"destructive",size:"sm",onClick:()=>v(h),disabled:t||l,className:"w-full sm:w-auto",children:f(t?"modelManagement.presets.deleting":"modelManagement.presets.delete")})]})]},h.name)})})})]}):null]})}function ks(){var d,p;const{t:o}=O(),s=Ue(),g=s.systemTabs.filter(n=>n.key!=="providers"),r=s.activeTab==="providers"?"anthropic":s.activeTab,a=s.tabs.find(n=>n.key===r)??null;return A.useEffect(()=>{s.activeTab==="providers"&&s.setActiveTab("anthropic")},[s.activeTab,s.setActiveTab]),e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx(Me,{info:(a==null?void 0:a.label)??r?e.jsx("span",{className:"rounded-full bg-secondary px-2.5 py-1 text-xs text-muted-foreground",children:(a==null?void 0:a.label)??r}):null,actions:e.jsxs(e.Fragment,{children:[e.jsx(k,{asChild:!0,variant:"outline",size:"sm",children:e.jsxs(we,{to:"/models",children:[e.jsx(ye,{className:"h-4 w-4","aria-hidden":"true"}),o("nav.models")]})}),e.jsx(k,{size:"sm",onClick:s.handleOpenCreateEndpoint,children:o("modelManagement.addEndpoint")})]})}),e.jsx(Xe,{activeTab:r,customEndpoints:s.customEndpoints,customTabs:s.customTabs,isDirtyByEndpoint:s.isDirtyByEndpoint,onDeleteEndpoint:s.setConfirmAction,onEditEndpoint:s.handleOpenEditEndpoint,onSelectTab:s.setActiveTab,systemTabs:g}),e.jsx(es,{endpoint:r,applyingPreset:((d=s.applyingPreset)==null?void 0:d.endpoint)===r?s.applyingPreset.name:null,config:s.config,customEndpoints:s.customEndpoints,deletingPreset:((p=s.deletingPreset)==null?void 0:p.endpoint)===r?s.deletingPreset.name:null,isDirty:s.isDirtyByEndpoint[r]??!1,onAddRoute:()=>s.handleAddRoute(r),onAddSuggestion:n=>s.handleAddSuggestion(r,n),onPresetNameChange:n=>s.handlePresetNameChange(r,n),onRequestDeletePreset:n=>s.setConfirmAction({kind:"preset",endpoint:r,preset:n}),onRequestPresetDiff:n=>s.setPresetDiffDialog({endpoint:r,preset:n}),onRemoveRoute:n=>s.handleRemoveRoute(r,n),onResetRoutes:()=>s.handleResetRoutes(r),onRouteChange:(n,c,w)=>s.handleRouteChange(r,n,c,w),onSavePreset:()=>void s.handleSavePreset(r),onSaveRoutes:()=>void s.handleSaveRoutes(r),onCompatibilityEnabledChange:n=>void s.handleCompatibilityEnabledChange(r,n),onValidationModeChange:n=>void s.handleValidationModeChange(r,n),onTogglePresetsExpanded:()=>s.setPresetsExpanded(n=>({...n,[r]:!n[r]})),presetError:s.presetErrorByEndpoint[r],presetName:s.presetNameByEndpoint[r]??"",presets:s.presetsByEndpoint[r]??[],presetsExpanded:s.presetsExpanded[r]===!0,providerModelOptions:s.providerModelOptions,routeError:s.routeError[r],routes:s.routesByEndpoint[r]||[],savingClaudeValidation:s.savingClaudeValidation,savingCompatibilityPolicy:s.savingCompatibilityPolicy,savingPreset:s.savingPresetFor===r,savingRoute:s.savingRouteFor===r,tabs:s.tabs.filter(n=>n.key!=="providers")}),e.jsx(Qe,{open:s.endpointDrawerOpen,endpoint:s.editingEndpoint,onClose:()=>{s.setEndpointDrawerOpen(!1),s.setEditingEndpoint(void 0)},onSuccess:()=>{s.configQuery.refetch()}}),e.jsx(Ye,{dialog:s.presetDiffDialog,currentRoutes:s.presetDiffDialog?s.routesByEndpoint[s.presetDiffDialog.endpoint]||[]:[],onConfirm:(n,c)=>{s.setPresetDiffDialog(null),s.handleApplyPreset(n,c)},onClose:()=>s.setPresetDiffDialog(null)}),e.jsx(ke,{open:!!s.confirmAction,onOpenChange:n=>{!n&&!s.confirmingAction&&s.setConfirmAction(null)},title:s.confirmDialogTitle,description:s.confirmDialogDescription,confirmLabel:s.confirmingAction?o("common.actions.loading"):o("common.delete"),cancelLabel:o("common.actions.cancel"),loading:s.confirmingAction,onConfirm:s.handleConfirmDialog,children:s.confirmDialogName?e.jsx("div",{className:"rounded-lg bg-destructive/5 px-3 py-2 font-mono text-xs text-foreground ring-1 ring-destructive/20",children:s.confirmDialogName}):null})]})}export{ks as default};
1
+ import{r as A,j as e,a7 as H,aH as be,aI as Y,ac as z,al as ve,a0 as Ne,S as ye}from"./vendor-DdPBfMMb.js";import{L as we}from"./router-D2Fb4U0L.js";import{C as ke}from"./ConfirmDialog-BuV2d3aQ.js";import{P as Me}from"./PageToolbar-CDzxx36L.js";import{B as k,c as ne,a as Ce,s as Ee,T as Pe,d as De,e as Ae,f as Se}from"./app-BF0X4ljN.js";import{u as re}from"./useAppMutation-C8scr-Sv.js";import{I as T}from"./input-k8bXT6Gd.js";import{L as P}from"./label-DDQd-HKi.js";import{S as oe,a as de,b as ce,c as me,d as F}from"./select-CrEhP63g.js";import{S as xe}from"./switch-DfFXX_ey.js";import{q as le,B as C}from"./queryKeys-0HDa7byL.js";import{u as O}from"./i18n-C8tBby0x.js";import{C as pe,a as ue}from"./card-D-kPX9ag.js";import{c as V}from"./global-CsDL9Nt2.js";import{D as Te,A as Oe,a as Re,b as Le,c as _e,d as $e,e as ze}from"./DialogShell-Dciv2SOq.js";import{P as Ve,a as Be,b as He}from"./popover-D4mE0Sqd.js";import{i as Ie,g as Fe,a as qe,C as Ge,O as Ke,u as Ue}from"./useModelManagementState-B3Ht0eWY.js";import"./query-QCek5MsK.js";import"./radix-CtQBp6Ie.js";import"./gateway-Bo9FVYfn.js";import"./useApiQuery-DaxeBDln.js";const We=["anthropic","openai-auto","openai-chat","openai-responses"];function Qe({open:o,endpoint:s,onClose:g,onSuccess:r}){const{t:a}=O(),[d,p]=A.useState({id:"",label:"",paths:[{path:"",protocol:"openai-auto"}],enabled:!0});A.useEffect(()=>{if(s){const t=s.paths&&s.paths.length>0?s.paths:s.path&&s.protocol?[{path:s.path,protocol:s.protocol}]:[{path:"",protocol:"openai-auto"}];p({id:s.id,label:s.label,paths:t,enabled:s.enabled!==!1});return}p({id:"",label:"",paths:[{path:"",protocol:"openai-auto"}],enabled:!0})},[s,o]);const n=re({mutationFn:ne.create,invalidateKeys:[le.customEndpoints.all()],successToast:()=>({title:a("modelManagement.createEndpointSuccess")}),errorToast:t=>({title:a("modelManagement.createEndpointError",{error:t.message})}),onSuccess:async()=>{r(),g()}}),c=re({mutationFn:t=>ne.update(t.id,t.updates),invalidateKeys:[le.customEndpoints.all()],successToast:()=>({title:a("modelManagement.updateEndpointSuccess")}),errorToast:t=>({title:a("modelManagement.updateEndpointError",{error:t.message})}),onSuccess:async()=>{r(),g()}}),w=()=>{p(t=>({...t,paths:[...t.paths,{path:"",protocol:"anthropic"}]}))},m=t=>{d.paths.length!==1&&p(x=>({...x,paths:x.paths.filter((j,E)=>E!==t)}))},v=(t,x,j)=>{p(E=>{const D=[...E.paths];return D[t]={...D[t],[x]:j},{...E,paths:D}})},f=t=>{if(t==null||t.preventDefault(),!d.id.trim()||!d.label.trim())return;for(const j of d.paths)if(!j.path.trim())return;const x=d.paths.map(j=>({path:j.path.trim(),protocol:j.protocol}));if(s){c.mutate({id:s.id,updates:{label:d.label.trim(),paths:x,enabled:d.enabled}});return}n.mutate({id:d.id.trim(),label:d.label.trim(),paths:x,enabled:d.enabled})},h=n.isPending||c.isPending,l=d.paths.length===0?a("modelManagement.atLeastOnePath"):!d.id.trim()||!d.label.trim()?a("modelManagement.endpointValidationError"):d.paths.some(t=>!t.path.trim())?a("modelManagement.pathValidationError"):null;return o?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-40 bg-background/80 backdrop-blur-sm",onClick:g}),e.jsx("div",{className:"fixed inset-y-0 right-0 z-50 w-full max-w-md border-l border-border/45 bg-background/96 shadow-[var(--surface-shadow-lg)] backdrop-blur",children:e.jsxs("div",{className:"flex h-full flex-col",children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-border/45 bg-secondary/45 p-6 backdrop-blur-sm",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("h2",{className:"text-lg font-semibold tracking-[-0.02em]",children:a(s?"modelManagement.editEndpoint":"modelManagement.createEndpoint")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s?s.id:a("modelManagement.endpointRoutingHint")})]}),e.jsx(k,{variant:"ghost",size:"sm",onClick:g,className:"rounded-2xl bg-white/70",children:e.jsx(H,{className:"h-4 w-4"})})]}),e.jsxs("form",{onSubmit:f,className:"flex-1 space-y-6 overflow-y-auto p-6",children:[e.jsxs("div",{className:"grid gap-3 rounded-xl bg-secondary/50 p-4 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-[0.16em] text-muted-foreground",children:a("modelManagement.endpointId")}),e.jsx("p",{className:"truncate text-sm font-medium text-foreground",children:(s==null?void 0:s.id)||"new-endpoint"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-[0.16em] text-muted-foreground",children:a("modelManagement.endpointEnabled")}),e.jsx("p",{className:"text-sm font-medium text-foreground",children:d.enabled?a("common.status.enabled"):a("common.status.disabled")})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(P,{children:[a("modelManagement.endpointId")," ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(T,{value:d.id,onChange:t=>p(x=>({...x,id:t.target.value})),placeholder:a("modelManagement.endpointIdPlaceholder"),disabled:!!s,required:!0}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a("modelManagement.endpointIdHint")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(P,{children:[a("modelManagement.endpointLabel")," ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(T,{value:d.label,onChange:t=>p(x=>({...x,label:t.target.value})),placeholder:a("modelManagement.endpointLabelPlaceholder"),required:!0})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(P,{children:[a("modelManagement.endpointPaths")," ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsxs(k,{type:"button",variant:"ghost",size:"sm",onClick:w,children:[e.jsx(be,{className:"mr-1 h-3 w-3"}),a("modelManagement.addPath")]})]}),e.jsx("div",{className:"space-y-3",children:d.paths.map((t,x)=>e.jsxs("div",{className:"space-y-2 rounded-xl border border-transparent bg-card p-3 shadow-[var(--surface-shadow)]",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsx(T,{value:t.path,onChange:j=>v(x,"path",j.target.value),placeholder:a("modelManagement.endpointPathPlaceholder"),required:!0}),e.jsxs(oe,{value:t.protocol,onValueChange:j=>v(x,"protocol",j),children:[e.jsx(de,{children:e.jsx(ce,{})}),e.jsx(me,{children:We.map(j=>e.jsx(F,{value:j,children:a(j==="anthropic"?"modelManagement.protocolAnthropic":j==="openai-auto"?"modelManagement.protocolOpenAI":j==="openai-chat"?"modelManagement.protocolOpenAIChat":"modelManagement.protocolOpenAIResponses")},j))})]})]}),d.paths.length>1?e.jsx(k,{type:"button",variant:"ghost",size:"sm",onClick:()=>m(x),className:"text-destructive",children:e.jsx(H,{className:"h-4 w-4"})}):null]}),e.jsxs("div",{className:"space-y-1 text-xs text-muted-foreground",children:[x===0?e.jsx("p",{children:a("modelManagement.endpointPathHint")}):null,e.jsx("p",{children:a(`modelManagement.protocolHints.${t.protocol}`)})]})]},`${t.protocol}-${x}`))}),l?e.jsx("p",{className:"text-xs text-destructive",children:l}):null]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(xe,{id:"enabled",checked:d.enabled,onCheckedChange:t=>p(x=>({...x,enabled:t}))}),e.jsx(P,{htmlFor:"enabled",children:a("modelManagement.endpointEnabled")})]}),s?null:e.jsx("div",{className:"rounded-xl bg-accent p-4",children:e.jsx("p",{className:"text-sm text-primary",children:a("modelManagement.endpointRoutingHint")})})]}),e.jsxs("div",{className:"flex gap-3 border-t border-border/45 bg-secondary/45 p-6 backdrop-blur-sm",children:[e.jsx(k,{variant:"outline",className:"flex-1",onClick:g,disabled:h,children:a("common.cancel")}),e.jsx(k,{className:"flex-1",onClick:()=>f(),disabled:h,children:a(h?"common.saving":s?"common.save":"common.create")})]})]})})]}):null}function q(o,s){return s(o==="anthropic"?"modelManagement.protocolAnthropic":o==="openai-chat"?"modelManagement.protocolOpenAIChat":o==="openai-responses"?"modelManagement.protocolOpenAIResponses":"modelManagement.protocolOpenAI")}function Xe({activeTab:o,customEndpoints:s,customTabs:g,isDirtyByEndpoint:r,onDeleteEndpoint:a,onEditEndpoint:d,onSelectTab:p,systemTabs:n}){const{t:c}=O(),w=[...n,...g].find(m=>m.key===o)??null;return e.jsx(pe,{className:"overflow-hidden rounded-[1.35rem] border border-white/70 bg-card/95 shadow-[0_22px_56px_-46px_rgba(15,23,42,0.22)]",children:e.jsxs(ue,{className:"space-y-4 p-4 sm:p-5",children:[e.jsxs("div",{className:"grid gap-3 lg:grid-cols-[minmax(0,1fr)_minmax(280px,0.6fr)]",children:[e.jsxs("div",{className:"rounded-[1.1rem] bg-secondary/60 p-2.5",children:[e.jsx("div",{className:"mb-2 flex items-center justify-between px-1",children:e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-[0.16em] text-muted-foreground/75",children:c("modelManagement.overview.providerAndSystem")})}),e.jsx("div",{className:"grid gap-2 sm:grid-cols-2 xl:grid-cols-3",children:n.map(m=>{const v=o===m.key,f=m.key!=="providers"&&r[m.key];return e.jsxs("button",{type:"button",onClick:()=>p(m.key),"aria-pressed":v,className:V("group flex min-h-[76px] flex-col justify-between rounded-[0.95rem] px-3 py-3 text-left transition-all",v?"bg-card text-foreground shadow-[0_14px_34px_-28px_rgba(15,23,42,0.3)] ring-1 ring-primary/10":"bg-transparent text-muted-foreground hover:bg-card/58 hover:text-foreground"),children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("span",{className:"block truncate text-[15px] font-semibold text-foreground",children:m.label}),e.jsx("div",{className:"mt-0.5 text-[10px] uppercase tracking-[0.14em] text-muted-foreground/70",children:m.key==="providers"?c("modelManagement.overview.providerPoolTag"):c("modelManagement.overview.systemEndpointTag")})]}),f?e.jsx("span",{className:"mt-1 h-2.5 w-2.5 rounded-full bg-amber-500"}):null]}),e.jsxs("div",{className:"mt-2 flex items-center justify-between gap-3",children:[e.jsx("span",{className:"line-clamp-1 text-xs text-muted-foreground/70",children:m.description}),v?e.jsx("span",{className:"inline-flex h-6 w-6 shrink-0 items-center justify-center rounded-full bg-primary/10 text-primary",children:e.jsx(Y,{className:"h-3.5 w-3.5"})}):null]})]},m.key)})})]}),w?e.jsxs("div",{className:"flex min-h-[116px] flex-col justify-between rounded-[1.1rem] bg-[linear-gradient(135deg,hsl(var(--primary)/0.1),rgba(255,255,255,0.78))] p-4 ring-1 ring-primary/10 dark:bg-[linear-gradient(135deg,rgba(14,165,233,0.14),rgba(15,23,42,0.72))] dark:ring-white/10",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"inline-flex h-8 w-8 items-center justify-center rounded-xl bg-primary/10 text-primary",children:e.jsx(Y,{className:"h-4 w-4"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-[0.16em] text-primary/75",children:"Active workspace"}),e.jsx("p",{className:"truncate text-sm font-semibold text-foreground",children:w.label})]})]}),e.jsx("p",{className:"mt-3 line-clamp-2 text-xs leading-5 text-muted-foreground",children:w.description})]}):null]}),g.length>0?e.jsxs("div",{className:"space-y-2.5",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-[0.16em] text-muted-foreground/75",children:c("modelManagement.overview.customEndpoints")}),e.jsx("div",{className:"grid gap-3 md:grid-cols-2 2xl:grid-cols-3",children:g.map(m=>{const v=o===m.key,f=r[m.key],h=s.find(l=>l.id===m.key);return e.jsxs("div",{className:V("group relative flex min-w-0 flex-col gap-2.5 overflow-hidden rounded-[1.05rem] border px-3 py-3 text-left transition-all sm:px-3.5",v?"border-primary/20 bg-secondary/80 text-foreground shadow-[0_14px_34px_-30px_rgba(59,130,246,0.32)]":"border-border/55 bg-background/42 hover:bg-secondary/50"),children:[e.jsxs("button",{type:"button",onClick:()=>p(m.key),"aria-pressed":v,className:"min-w-0 flex-1 text-left",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"truncate text-sm font-semibold text-foreground sm:text-[15px]",title:m.label,children:m.label}),f?e.jsx("span",{className:"h-2 w-2 rounded-full bg-amber-500"}):null]}),e.jsxs("div",{className:"mt-1.5 flex items-end justify-between gap-3",children:[e.jsx("p",{className:"line-clamp-2 text-[11px] leading-4.5 text-muted-foreground/72 sm:line-clamp-1 sm:text-xs",children:m.description}),v?e.jsx("span",{className:"inline-flex h-6 w-6 shrink-0 items-center justify-center rounded-full bg-primary/10 text-primary",children:e.jsx(Y,{className:"h-3.5 w-3.5"})}):null]})]}),e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-1.5",children:[e.jsx(C,{variant:(h==null?void 0:h.enabled)===!1?"secondary":"success",className:"rounded-full border-0 px-2 py-0.5 text-[10px]",children:(h==null?void 0:h.enabled)===!1?c("modelManagement.overview.endpointDisabled"):c("modelManagement.overview.endpointEnabled")}),(m.protocols??[]).slice(0,2).map(l=>e.jsx(C,{variant:"outline",className:"max-w-[130px] truncate rounded-full text-[10px]",title:q(l,c),children:q(l,c)},`${m.key}-${l}`))]}),e.jsxs("div",{className:"min-w-0 rounded-[0.8rem] bg-secondary/55 px-2.5 py-2",children:[e.jsx("p",{className:"mb-1 text-[10px] font-medium uppercase tracking-[0.14em] text-muted-foreground/70",children:c("modelManagement.overview.endpointPaths")}),e.jsx("div",{className:"space-y-1",children:Je(h,c).map(l=>e.jsx("p",{className:"truncate text-xs font-medium text-foreground",title:l,children:l},l))})]}),e.jsxs("div",{className:"grid grid-cols-[1fr_auto] gap-2",children:[e.jsx(k,{variant:"ghost",size:"sm",className:"h-7 justify-start rounded-full px-2 text-[11px]",disabled:!h,onClick:()=>{h&&d(h)},children:c("common.edit")}),m.canDelete?e.jsx("button",{type:"button",onClick:l=>{l.stopPropagation(),h&&a({kind:"endpoint",endpoint:h})},className:"flex h-7 w-full items-center justify-center rounded-md text-muted-foreground transition hover:bg-destructive/10 hover:text-destructive sm:w-7",title:c("common.delete"),children:e.jsx(H,{className:"h-3.5 w-3.5"})}):null]}),m.canDelete?null:e.jsx("div",{className:"text-[11px] text-muted-foreground/70",children:c("modelManagement.overview.endpointManagedExternally")})]},m.key)})})]}):null]})})}function Je(o,s){var g;if(!o)return[s("common.noData")];if((g=o.paths)!=null&&g.length){const r=o.paths.slice(0,2).map(a=>`${a.path} · ${q(a.protocol,s)}`);return o.paths.length>2&&r.push(s("modelManagement.overview.endpointMorePaths",{count:o.paths.length-2})),r}return o.path?[`${o.path} · ${q(o.protocol??"anthropic",s)}`]:[s("common.noData")]}function Ye({dialog:o,currentRoutes:s,onConfirm:g,onClose:r}){const{t:a}=O();if(!o)return null;const{endpoint:d,preset:p}=o,n=p.modelRoutes??{},c={};for(const l of s){const t=l.source.trim(),x=l.target.trim();t&&x&&(c[t]=x)}const w=new Set([...Object.keys(c),...Object.keys(n)]),m=[],v=[],f=[];for(const l of w){const t=l in c,x=l in n;x&&!t?m.push([l,n[l]]):t&&!x?v.push([l,c[l]]):t&&x&&c[l]!==n[l]&&f.push([l,c[l],n[l]])}const h=m.length>0||v.length>0||f.length>0;return e.jsx(Te,{open:!0,onOpenChange:l=>!l&&r(),children:e.jsxs(Oe,{className:"max-w-2xl",children:[e.jsxs(Re,{children:[e.jsx(Le,{children:a("modelManagement.presets.diffTitle")}),e.jsx(_e,{children:a("modelManagement.presets.diffDescription",{name:p.name})})]}),e.jsx($e,{children:h?e.jsxs("div",{className:"max-h-80 space-y-2 rounded-xl bg-secondary/50 p-3 text-sm",children:[m.map(([l,t])=>e.jsxs("div",{className:"flex items-center gap-2 rounded-xl bg-emerald-50 px-2 py-1.5 text-emerald-800 dark:bg-emerald-950 dark:text-emerald-200",children:[e.jsx(C,{variant:"outline",className:"border-emerald-300 text-xs dark:border-emerald-700",children:a("modelManagement.presets.diffAdded")}),e.jsx("span",{className:"truncate",children:l}),e.jsx(z,{className:"h-3 w-3 flex-shrink-0"}),e.jsx("span",{className:"truncate",children:t})]},`add-${l}`)),v.map(([l,t])=>e.jsxs("div",{className:"flex items-center gap-2 rounded-xl bg-red-50 px-2 py-1.5 text-red-800 dark:bg-red-950 dark:text-red-200",children:[e.jsx(C,{variant:"outline",className:"border-red-300 text-xs dark:border-red-700",children:a("modelManagement.presets.diffRemoved")}),e.jsx("span",{className:"truncate",children:l}),e.jsx(z,{className:"h-3 w-3 flex-shrink-0"}),e.jsx("span",{className:"truncate",children:t})]},`rm-${l}`)),f.map(([l,t,x])=>e.jsxs("div",{className:"flex items-center gap-2 rounded-xl bg-amber-50 px-2 py-1.5 text-amber-800 dark:bg-amber-950 dark:text-amber-200",children:[e.jsx(C,{variant:"outline",className:"border-amber-300 text-xs dark:border-amber-700",children:a("modelManagement.presets.diffChanged")}),e.jsx("span",{className:"truncate",children:l}),e.jsx(z,{className:"h-3 w-3 flex-shrink-0"}),e.jsx("span",{className:"truncate line-through opacity-60",children:t}),e.jsx(z,{className:"h-3 w-3 flex-shrink-0"}),e.jsx("span",{className:"truncate",children:x})]},`chg-${l}`))]}):e.jsx("p",{className:"rounded-xl bg-secondary/50 py-8 text-center text-sm text-muted-foreground",children:a("modelManagement.presets.diffEmpty")})}),e.jsxs(ze,{children:[e.jsx(k,{variant:"outline",onClick:r,children:a("common.cancel")}),e.jsx(k,{onClick:()=>g(d,p),disabled:!h,children:a("modelManagement.presets.diffConfirm")})]})]})})}const ie=6;function Ze({value:o,onChange:s,options:g,disabled:r,placeholder:a}){const{t:d}=O(),[p,n]=A.useState(!1),[c,w]=A.useState(""),m=A.useRef(null),v=A.useRef(!1),[f,h]=Ce(Ee.modelManagement.recentRouteTargets,[]),l=A.useMemo(()=>{const i=new Map;for(const b of g)i.set(b.value,b);return i},[g]),t=(i,b)=>b?[i.label,i.value,i.providerId??"",i.providerLabel??"",i.modelId??"",i.modelLabel??""].join(" ").toLowerCase().includes(b):!0,x=A.useMemo(()=>{const i=c.trim().toLowerCase(),b=g.filter(y=>t(y,i)),S=f.map(y=>l.get(y)??(i?void 0:{value:y,label:y,kind:"custom"})).filter(y=>!!y).filter(y=>t(y,i)).slice(0,ie),R=[];S.length>0&&R.push({key:"recent",label:d("modelManagement.targetPicker.recent"),options:S});const L=new Map,_=[];for(const y of b){if(y.kind==="custom"||!y.providerId){_.push(y);continue}const B=`provider:${y.providerId}`,I=L.get(B);I?I.options.push(y):L.set(B,{key:B,label:y.providerLabel??y.providerId,options:[y]})}return R.push(...L.values()),_.length>0&&R.push({key:"custom",label:d("modelManagement.targetPicker.custom"),options:_,muted:!0}),R},[l,g,f,c,d]),j=x.reduce((i,b)=>i+b.options.length,0),E=i=>{s(i),h(b=>[i,...b.filter(S=>S!==i)].slice(0,ie)),w(""),v.current=!0,typeof document<"u"&&document.activeElement instanceof HTMLElement&&document.activeElement.blur(),n(!1),typeof window<"u"?window.requestAnimationFrame(()=>{v.current=!1}):v.current=!1},D=i=>i.kind==="passthrough"?d("modelManagement.targetPicker.passthrough"):i.kind==="custom"?d("modelManagement.targetPicker.customValue"):d("modelManagement.targetPicker.model"),G=i=>i.kind==="passthrough"||i.kind==="custom"?i.label:i.modelLabel??i.label;return e.jsxs(Ve,{open:p,onOpenChange:i=>{i&&v.current||(n(i),i&&w(""))},children:[e.jsx(Be,{asChild:!0,children:e.jsx(T,{value:o,onChange:i=>{s(i.target.value),w(i.target.value),p||n(!0)},onFocus:()=>{w(""),n(!0)},onClick:()=>{p||n(!0)},placeholder:a,disabled:r,autoComplete:"off"})}),e.jsxs(He,{className:"flex max-h-[min(28rem,var(--radix-popover-content-available-height))] flex-col overflow-hidden rounded-xl border border-[color:var(--surface-border)] bg-popover/96 p-0 shadow-[var(--surface-shadow-lg)] backdrop-blur",style:{width:"max(var(--radix-popover-trigger-width), 360px)"},align:"start",onOpenAutoFocus:i=>{var b;i.preventDefault(),(b=m.current)==null||b.focus()},children:[e.jsxs("div",{className:"space-y-2 border-b border-border/70 px-3 py-3",children:[e.jsx(T,{ref:m,value:c,onChange:i=>w(i.target.value),placeholder:d("modelManagement.targetPicker.searchPlaceholder"),className:"h-9",autoComplete:"off"}),e.jsx("div",{className:"text-xs text-muted-foreground",children:c.trim()?d("modelManagement.targetPicker.matchCount",{count:j}):d("modelManagement.targetPicker.helper")})]}),j===0?e.jsx("div",{className:"px-3 py-4 text-center text-xs text-muted-foreground",children:d("common.noMatches")}):e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto p-1.5",children:x.map(i=>e.jsxs("div",{className:"py-1",children:[e.jsxs("div",{className:V("sticky top-0 z-10 flex items-center justify-between bg-popover/95 px-2 py-1 text-[11px] font-semibold uppercase tracking-wide text-muted-foreground backdrop-blur",i.muted&&"opacity-80"),children:[e.jsx("span",{className:"truncate",children:i.label}),e.jsx("span",{children:i.options.length})]}),e.jsx("div",{className:"space-y-1",children:i.options.map(b=>e.jsxs("button",{type:"button",className:V("flex w-full min-w-0 items-center gap-2 rounded-lg px-3 py-2 text-left text-sm transition-colors hover:bg-accent/80 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",b.value===o.trim()&&"bg-accent/90 text-accent-foreground"),onMouseDown:S=>{S.preventDefault()},onClick:()=>E(b.value),children:[e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate font-medium",children:G(b)}),e.jsx("span",{className:"block truncate text-xs text-muted-foreground",children:b.value})]}),e.jsxs("span",{className:"flex shrink-0 items-center gap-1",children:[b.isDefault?e.jsx(C,{variant:"secondary",className:"text-[10px]",children:d("modelManagement.targetPicker.default")}):null,e.jsx(C,{variant:b.kind==="passthrough"?"outline":"secondary",className:"text-[10px]",children:D(b)})]})]},`${i.key}-${b.value}`))})]},i.key))})]})]})}function es({endpoint:o,tabs:s,customEndpoints:g,config:r,routes:a,routeError:d,savingRoute:p,isDirty:n,presets:c,presetName:w,presetError:m,savingPreset:v,applyingPreset:f,deletingPreset:h,presetsExpanded:l,savingClaudeValidation:t,savingCompatibilityPolicy:x,providerModelOptions:j,onTogglePresetsExpanded:E,onPresetNameChange:D,onSavePreset:G,onRequestPresetDiff:i,onRequestDeletePreset:b,onValidationModeChange:S,onCompatibilityEnabledChange:R,onRouteChange:L,onRemoveRoute:_,onAddSuggestion:y,onAddRoute:B,onResetRoutes:I,onSaveRoutes:he}){var ae,te;const{t:u}=O(),M=s.find(N=>N.key===o),K=((ae=M==null?void 0:M.protocols)==null?void 0:ae.includes("anthropic"))??o==="anthropic"?Ge:Ke,ge=(M==null?void 0:M.label)??o;(M==null?void 0:M.isSystem)===!1?M.description:u(`settings.routing.descriptionByEndpoint.${o}`);const U=`route-source-${o}`,Z=Ie(o,g),ee=((te=M==null?void 0:M.protocols)==null?void 0:te.some(N=>N.startsWith("openai")))??o==="openai",W=Fe(o,r,g),Q=qe(o,r,g),X=Z?(W==null?void 0:W.mode)??"off":"off",se=ee?(Q==null?void 0:Q.enabled)??!1:!1,fe=new Set(a.map(N=>N.source.trim()).filter(Boolean)),je=`modelManagement.claudeValidation.options.${X}.description`;return e.jsx(pe,{children:e.jsxs(ue,{className:"space-y-6 pt-6",children:[e.jsx("div",{className:"rounded-full bg-secondary px-4 py-3 text-xs text-muted-foreground",children:u("settings.routing.wildcardHint")}),Z?e.jsx("div",{className:"rounded-xl border border-primary/12 bg-[linear-gradient(135deg,hsl(var(--primary)/0.08),hsl(var(--accent)/0.72))] p-4 shadow-[var(--surface-shadow)] dark:border-sky-300/12 dark:bg-[linear-gradient(135deg,rgba(14,165,233,0.12),rgba(15,23,42,0.72))]",children:e.jsxs("div",{className:"flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-sm font-medium text-primary dark:text-sky-100",children:u("modelManagement.claudeValidation.title")}),e.jsx("p",{className:"max-w-2xl text-xs leading-5 text-muted-foreground dark:text-slate-300",children:u("modelManagement.claudeValidation.description")})]}),e.jsxs("div",{className:"flex w-full max-w-xs flex-col gap-2 self-start sm:self-auto",children:[e.jsx(P,{className:"text-[11px] font-semibold uppercase tracking-[0.16em] text-primary/70 dark:text-sky-200/75",children:u("modelManagement.claudeValidation.modeLabel")}),e.jsxs(oe,{value:X,onValueChange:N=>S(N),disabled:t,children:[e.jsx(de,{className:"border-primary/15 bg-card/90 dark:border-white/10 dark:bg-slate-950/50",children:e.jsx(ce,{})}),e.jsxs(me,{children:[e.jsx(F,{value:"off",children:u("modelManagement.claudeValidation.options.off.label")}),e.jsx(F,{value:"anthropic-strict",children:u("modelManagement.claudeValidation.options.anthropic-strict.label")}),e.jsx(F,{value:"claude-code",children:u("modelManagement.claudeValidation.options.claude-code.label")})]})]}),e.jsx("span",{className:V("text-xs",X==="off"?"text-muted-foreground dark:text-slate-400":"text-primary/80 dark:text-sky-200/80"),children:u(je)})]})]})}):null,ee?e.jsx("div",{className:"rounded-xl border border-primary/12 bg-[linear-gradient(135deg,hsl(var(--primary)/0.08),hsl(var(--accent)/0.72))] p-4 shadow-[var(--surface-shadow)] dark:border-sky-300/12 dark:bg-[linear-gradient(135deg,rgba(14,165,233,0.12),rgba(15,23,42,0.72))]",children:e.jsxs("div",{className:"flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-sm font-medium text-primary dark:text-sky-100",children:u("modelManagement.openaiCompatibility.title")}),e.jsx("p",{className:"max-w-2xl text-xs leading-5 text-muted-foreground dark:text-slate-300",children:u("modelManagement.openaiCompatibility.description")})]}),e.jsx("div",{className:"flex w-full max-w-xs flex-col gap-2 self-start sm:self-auto",children:e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-lg border border-primary/12 bg-card/85 px-3 py-2 dark:border-white/10 dark:bg-slate-950/50",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(P,{className:"text-[11px] font-semibold uppercase tracking-[0.16em] text-primary/70 dark:text-sky-200/75",children:u("modelManagement.openaiCompatibility.toggleLabel")}),e.jsx("p",{className:"text-xs text-muted-foreground dark:text-slate-300",children:u(se?"modelManagement.openaiCompatibility.enabledHint":"modelManagement.openaiCompatibility.disabledHint")})]}),e.jsx(xe,{checked:se,onCheckedChange:R,disabled:x,"aria-label":u("modelManagement.openaiCompatibility.toggleLabel")})]})})]})}):null,d?e.jsx("p",{className:"text-sm text-destructive",children:d}):null,e.jsx(ss,{presets:c,presetName:w,presetError:m,savingPreset:v,applyingPreset:f,deletingPreset:h,expanded:l,onToggleExpanded:E,onPresetNameChange:D,onSavePreset:G,onRequestPresetDiff:i,onRequestDeletePreset:b}),e.jsxs("div",{className:"space-y-3 rounded-xl bg-secondary/50 p-4",children:[e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(P,{className:"text-sm font-semibold text-foreground",children:u("modelManagement.routesEditorTitle")}),e.jsxs(C,{variant:"outline",children:[a.length," active"]})]}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:u("modelManagement.overview.routesEditorHint")})]}),e.jsxs("div",{className:"self-start rounded-full bg-card px-3 py-2 text-[11px] font-medium text-muted-foreground",children:["Active workspace · ",ge]})]}),a.length===0?e.jsxs("div",{className:"rounded-xl border-2 border-dashed border-border/30 bg-background/60 p-12 text-center text-sm text-muted-foreground",children:[e.jsx("p",{className:"font-medium",children:u("settings.routing.empty")}),e.jsx("p",{className:"mt-2 text-xs",children:u("modelManagement.emptyRoutesHint")})]}):e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"hidden grid-cols-[minmax(0,1fr)_auto_minmax(0,1fr)_auto] items-center gap-3 px-1 text-xs font-medium text-muted-foreground md:grid",children:[e.jsx("span",{children:u("settings.routing.source")}),e.jsx("span",{}),e.jsx("span",{children:u("settings.routing.target")}),e.jsx("span",{})]}),a.map((N,$)=>e.jsxs("div",{className:"rounded-xl bg-card p-3 shadow-sm",children:[e.jsxs("div",{className:"mb-3 flex items-center justify-between md:hidden",children:[e.jsxs(C,{variant:"outline",className:"text-[11px]",children:["#",$+1]}),e.jsx(k,{variant:"ghost",size:"icon",className:"h-8 w-8 text-muted-foreground hover:text-destructive",onClick:()=>_(N.id),disabled:p,children:e.jsx(H,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"grid gap-3 md:grid-cols-[minmax(0,1fr)_auto_minmax(0,1fr)_auto] md:items-center",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(P,{className:"text-[11px] uppercase tracking-[0.16em] text-muted-foreground md:hidden",children:u("settings.routing.source")}),e.jsx(T,{value:N.source,onChange:J=>L(N.id,"source",J.target.value),placeholder:u("settings.routing.sourcePlaceholder"),list:U,disabled:p,"aria-label":`route-source-${$+1}`})]}),e.jsx(z,{className:"hidden h-4 w-4 flex-shrink-0 text-muted-foreground md:block"}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(P,{className:"text-[11px] uppercase tracking-[0.16em] text-muted-foreground md:hidden",children:u("settings.routing.target")}),e.jsx(Ze,{value:N.target,onChange:J=>L(N.id,"target",J),options:j,disabled:p,placeholder:u("settings.routing.targetPlaceholder")})]}),e.jsx(k,{variant:"ghost",size:"icon",className:"hidden h-8 w-8 text-muted-foreground hover:text-destructive md:inline-flex",onClick:()=>_(N.id),disabled:p,children:e.jsx(H,{className:"h-4 w-4"})})]})]},N.id))]})]}),e.jsxs("div",{className:"flex flex-col gap-3 rounded-xl bg-card p-4 shadow-[var(--surface-shadow)] md:flex-row md:items-center md:justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-sm font-medium",children:u("modelManagement.actions.footerTitle")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:u(n?"modelManagement.actions.footerDirtyHint":"modelManagement.actions.footerSavedHint")})]}),e.jsxs("div",{className:"grid gap-2 sm:grid-cols-3 md:flex md:flex-wrap md:items-center",children:[e.jsx(k,{variant:"outline",size:"sm",onClick:B,disabled:p,className:"w-full",children:u("settings.routing.add")}),e.jsx(k,{variant:"outline",size:"sm",onClick:I,disabled:p||!n,className:"w-full",children:u("common.actions.reset")}),e.jsxs(k,{size:"sm",onClick:he,disabled:p,className:"relative w-full",children:[u(p?"common.actions.saving":"modelManagement.actions.saveRoutes"),n?e.jsx("span",{className:"absolute -right-1 -top-1 h-2 w-2 rounded-full bg-amber-500"}):null]})]})]}),e.jsxs("div",{className:"space-y-3 rounded-xl bg-secondary/50 p-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(P,{className:"text-sm font-medium text-foreground",children:u("settings.routing.suggested")}),e.jsx(C,{variant:"outline",className:"text-[11px]",children:K.length})]}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:u("modelManagement.overview.suggestionHint")})]}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:K.map(N=>{const $=fe.has(N);return e.jsx(k,{variant:$?"ghost":"outline",size:"sm",onClick:()=>y(N),disabled:p||$,className:V("h-7 rounded-md px-2.5 text-[11px] font-normal",$?"opacity-45":"bg-background/70"),children:N},`${o}-${N}`)})})]}),e.jsx("datalist",{id:U,children:K.map(N=>e.jsx("option",{value:N},`${U}-${N}`))})]})})}function ss({presets:o,presetName:s,presetError:g,savingPreset:r,applyingPreset:a,deletingPreset:d,expanded:p,onToggleExpanded:n,onPresetNameChange:c,onSavePreset:w,onRequestPresetDiff:m,onRequestDeletePreset:v}){const{t:f}=O();return e.jsxs("div",{className:"rounded-xl bg-card shadow-[var(--surface-shadow)]",children:[e.jsx("button",{type:"button",className:"flex w-full items-center justify-between gap-3 rounded-xl p-4 text-left transition-colors hover:bg-accent",onClick:n,children:e.jsxs("div",{className:"flex items-center gap-2",children:[p?e.jsx(ve,{className:"h-4 w-4"}):e.jsx(Ne,{className:"h-4 w-4"}),e.jsx("h3",{className:"font-medium",children:f("modelManagement.presets.title")}),e.jsx(C,{variant:"secondary",className:"text-xs",children:o.length})]})}),p?e.jsxs("div",{className:"space-y-4 border-t border-border/45 px-4 pb-4 pt-3",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:f("modelManagement.presets.description")}),e.jsxs("div",{className:"flex flex-col gap-3 md:flex-row md:items-center",children:[e.jsx(T,{value:s,onChange:h=>c(h.target.value),placeholder:f("modelManagement.presets.namePlaceholder"),disabled:r,className:"w-full md:w-48"}),e.jsx(k,{onClick:w,disabled:r,className:"w-full md:w-auto",children:f(r?"modelManagement.presets.saving":"modelManagement.presets.save")})]}),g?e.jsx("p",{className:"text-sm text-destructive",children:g}):null,o.length===0?e.jsx("p",{className:"py-4 text-center text-sm text-muted-foreground",children:f("modelManagement.presets.empty")}):e.jsx(Pe,{children:e.jsx("div",{className:"grid gap-2 sm:grid-cols-2 lg:grid-cols-3",children:o.map(h=>{const l=a===h.name,t=d===h.name,x=Object.entries(h.modelRoutes??{}),j=x.length;return e.jsxs("div",{className:"flex flex-col gap-3 rounded-xl bg-secondary/50 px-4 py-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs(De,{children:[e.jsx(Ae,{asChild:!0,children:e.jsxs("div",{className:"min-w-0 flex-1 cursor-default",children:[e.jsx("span",{className:"block truncate text-sm font-medium",children:h.name}),e.jsx(C,{variant:"outline",className:"mt-1 text-xs",children:j>0?f("modelManagement.presets.rulesCount",{count:j}):f("modelManagement.presets.noRules")})]})}),j>0?e.jsx(Se,{side:"bottom",className:"max-w-xs",children:e.jsxs("div",{className:"space-y-1 text-xs",children:[x.slice(0,5).map(([E,D])=>e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"truncate",children:E}),e.jsx(z,{className:"h-3 w-3 flex-shrink-0"}),e.jsx("span",{className:"truncate",children:D})]},E)),j>5?e.jsxs("div",{className:"text-muted-foreground",children:["…+",j-5]}):null]})}):null]}),e.jsxs("div",{className:"grid flex-shrink-0 gap-2 sm:flex sm:items-center",children:[e.jsx(k,{size:"sm",onClick:()=>m(h),disabled:l||t,className:"w-full sm:w-auto",children:f(l?"modelManagement.presets.applying":"modelManagement.presets.apply")}),e.jsx(k,{variant:"destructive",size:"sm",onClick:()=>v(h),disabled:t||l,className:"w-full sm:w-auto",children:f(t?"modelManagement.presets.deleting":"modelManagement.presets.delete")})]})]},h.name)})})})]}):null]})}function ks(){var d,p;const{t:o}=O(),s=Ue(),g=s.systemTabs.filter(n=>n.key!=="providers"),r=s.activeTab==="providers"?"anthropic":s.activeTab,a=s.tabs.find(n=>n.key===r)??null;return A.useEffect(()=>{s.activeTab==="providers"&&s.setActiveTab("anthropic")},[s.activeTab,s.setActiveTab]),e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx(Me,{info:(a==null?void 0:a.label)??r?e.jsx("span",{className:"rounded-full bg-secondary px-2.5 py-1 text-xs text-muted-foreground",children:(a==null?void 0:a.label)??r}):null,actions:e.jsxs(e.Fragment,{children:[e.jsx(k,{asChild:!0,variant:"outline",size:"sm",children:e.jsxs(we,{to:"/models",children:[e.jsx(ye,{className:"h-4 w-4","aria-hidden":"true"}),o("nav.models")]})}),e.jsx(k,{size:"sm",onClick:s.handleOpenCreateEndpoint,children:o("modelManagement.addEndpoint")})]})}),e.jsx(Xe,{activeTab:r,customEndpoints:s.customEndpoints,customTabs:s.customTabs,isDirtyByEndpoint:s.isDirtyByEndpoint,onDeleteEndpoint:s.setConfirmAction,onEditEndpoint:s.handleOpenEditEndpoint,onSelectTab:s.setActiveTab,systemTabs:g}),e.jsx(es,{endpoint:r,applyingPreset:((d=s.applyingPreset)==null?void 0:d.endpoint)===r?s.applyingPreset.name:null,config:s.config,customEndpoints:s.customEndpoints,deletingPreset:((p=s.deletingPreset)==null?void 0:p.endpoint)===r?s.deletingPreset.name:null,isDirty:s.isDirtyByEndpoint[r]??!1,onAddRoute:()=>s.handleAddRoute(r),onAddSuggestion:n=>s.handleAddSuggestion(r,n),onPresetNameChange:n=>s.handlePresetNameChange(r,n),onRequestDeletePreset:n=>s.setConfirmAction({kind:"preset",endpoint:r,preset:n}),onRequestPresetDiff:n=>s.setPresetDiffDialog({endpoint:r,preset:n}),onRemoveRoute:n=>s.handleRemoveRoute(r,n),onResetRoutes:()=>s.handleResetRoutes(r),onRouteChange:(n,c,w)=>s.handleRouteChange(r,n,c,w),onSavePreset:()=>void s.handleSavePreset(r),onSaveRoutes:()=>void s.handleSaveRoutes(r),onCompatibilityEnabledChange:n=>void s.handleCompatibilityEnabledChange(r,n),onValidationModeChange:n=>void s.handleValidationModeChange(r,n),onTogglePresetsExpanded:()=>s.setPresetsExpanded(n=>({...n,[r]:!n[r]})),presetError:s.presetErrorByEndpoint[r],presetName:s.presetNameByEndpoint[r]??"",presets:s.presetsByEndpoint[r]??[],presetsExpanded:s.presetsExpanded[r]===!0,providerModelOptions:s.providerModelOptions,routeError:s.routeError[r],routes:s.routesByEndpoint[r]||[],savingClaudeValidation:s.savingClaudeValidation,savingCompatibilityPolicy:s.savingCompatibilityPolicy,savingPreset:s.savingPresetFor===r,savingRoute:s.savingRouteFor===r,tabs:s.tabs.filter(n=>n.key!=="providers")}),e.jsx(Qe,{open:s.endpointDrawerOpen,endpoint:s.editingEndpoint,onClose:()=>{s.setEndpointDrawerOpen(!1),s.setEditingEndpoint(void 0)},onSuccess:()=>{s.configQuery.refetch()}}),e.jsx(Ye,{dialog:s.presetDiffDialog,currentRoutes:s.presetDiffDialog?s.routesByEndpoint[s.presetDiffDialog.endpoint]||[]:[],onConfirm:(n,c)=>{s.setPresetDiffDialog(null),s.handleApplyPreset(n,c)},onClose:()=>s.setPresetDiffDialog(null)}),e.jsx(ke,{open:!!s.confirmAction,onOpenChange:n=>{!n&&!s.confirmingAction&&s.setConfirmAction(null)},title:s.confirmDialogTitle,description:s.confirmDialogDescription,confirmLabel:s.confirmingAction?o("common.actions.loading"):o("common.delete"),cancelLabel:o("common.actions.cancel"),loading:s.confirmingAction,onConfirm:s.handleConfirmDialog,children:s.confirmDialogName?e.jsx("div",{className:"rounded-lg bg-destructive/5 px-3 py-2 font-mono text-xs text-foreground ring-1 ring-destructive/20",children:s.confirmDialogName}):null})]})}export{ks as default};