@chenpu17/cc-gw 0.8.15 → 0.8.17
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.
- package/package.json +5 -5
- package/src/web/dist/assets/About-CO9V8AyO.js +1 -0
- package/src/web/dist/assets/ApiKeys-CEW3ffw1.js +1 -0
- package/src/web/dist/assets/{ConfirmDialog-BHfhtrze.js → ConfirmDialog-Dx-KyPyo.js} +1 -1
- package/src/web/dist/assets/Dashboard-Cevbc6du.js +1 -0
- package/src/web/dist/assets/{DialogShell-BpzUpswv.js → DialogShell-BWia_d99.js} +1 -1
- package/src/web/dist/assets/Events-S5ncSnD_.js +1 -0
- package/src/web/dist/assets/Help-JfcvUCsA.js +4 -0
- package/src/web/dist/assets/{Login-CJwzn0Sh.js → Login-BvndMGjs.js} +1 -1
- package/src/web/dist/assets/Logs-BTu7ppWL.js +1 -0
- package/src/web/dist/assets/ModelManagement-CHJiJws5.js +1 -0
- package/src/web/dist/assets/{PageSection-Mw-tAM8I.js → PageSection-DVs3faWw.js} +1 -1
- package/src/web/dist/assets/{PageState-Bb3fEov-.js → PageState-Dvjip2P-.js} +1 -1
- package/src/web/dist/assets/PageToolbar-BxRZF-QJ.js +1 -0
- package/src/web/dist/assets/Profiler-DPbWModV.js +1 -0
- package/src/web/dist/assets/RoutingManagement-CZW9Jycg.js +1 -0
- package/src/web/dist/assets/Settings-8q1aFqEb.js +1 -0
- package/src/web/dist/assets/{Skeleton-DEv_MFPR.js → Skeleton-DHQ8ApGX.js} +1 -1
- package/src/web/dist/assets/app-B604X4iv.js +61 -0
- package/src/web/dist/assets/{card-BE_b5SvI.js → card-Bx5Pg_wP.js} +1 -1
- package/src/web/dist/assets/{charts-core-DzWzxST6.js → charts-core-CK8TVJro.js} +1 -1
- package/src/web/dist/assets/{charts-engine-Ds7lwC51.js → charts-engine-CWjgwbj5.js} +1 -1
- package/src/web/dist/assets/{charts-react-D0nWbUCA.js → charts-react-CmmN-08P.js} +1 -1
- package/src/web/dist/assets/{gateway-Zpcl3bpd.js → gateway-CXg6BjAe.js} +1 -1
- package/src/web/dist/assets/global-CMwh_4v7.css +1 -0
- package/src/web/dist/assets/{global-xoXYOIOz.js → global-D8DuA4wF.js} +1 -1
- package/src/web/dist/assets/{i18n-Bl2BcCDG.js → i18n-C8tBby0x.js} +1 -1
- package/src/web/dist/assets/{input-Brr3avKW.js → input-b5NRkUKN.js} +1 -1
- package/src/web/dist/assets/{label-Bc4vkpLF.js → label-DUoPO5Jo.js} +1 -1
- package/src/web/dist/assets/{landing-D9E0GJD9.js → landing-ZIZVx1ft.js} +1 -1
- package/src/web/dist/assets/package-CfiB50Gz.js +1 -0
- package/src/web/dist/assets/{popover-D8l2FwYm.js → popover-BAGiqp11.js} +1 -1
- package/src/web/dist/assets/{query-BbGWgOFk.js → query-QCek5MsK.js} +1 -1
- package/src/web/dist/assets/{queryKeys-DifG1fTh.js → queryKeys-BpeJfcg0.js} +1 -1
- package/src/web/dist/assets/{radix-mHySgtou.js → radix-CtQBp6Ie.js} +1 -1
- package/src/web/dist/assets/{router-CL3rf_uf.js → router-D2Fb4U0L.js} +1 -1
- package/src/web/dist/assets/{select-zM5TPRdZ.js → select-B5oPLG9G.js} +1 -1
- package/src/web/dist/assets/{switch-fb9u33D-.js → switch-BDc99Vsq.js} +1 -1
- package/src/web/dist/assets/{table-BpLpq7tJ.js → table-BG-JeOj-.js} +1 -1
- package/src/web/dist/assets/{useApiQuery-DCgUtGKI.js → useApiQuery-b8AdsIsi.js} +1 -1
- package/src/web/dist/assets/{useAppMutation-BjZN2gaQ.js → useAppMutation-C9CUOR7n.js} +1 -1
- package/src/web/dist/assets/{useModelManagementState-1NXqPQ5M.js → useModelManagementState-ByZBhfct.js} +1 -1
- package/src/web/dist/assets/{vendor-z22RpOY0.js → vendor-DdPBfMMb.js} +67 -82
- package/src/web/dist/index.html +8 -8
- package/src/web/dist/landing.html +5 -5
- package/src/web/dist/assets/About-BGBg2q_J.js +0 -1
- package/src/web/dist/assets/ApiKeys-DUuKvZ5b.js +0 -1
- package/src/web/dist/assets/Dashboard-DZdfzGEK.js +0 -1
- package/src/web/dist/assets/Events-9Yq8nG75.js +0 -1
- package/src/web/dist/assets/Help-qSGvYIjs.js +0 -5
- package/src/web/dist/assets/Logs--D9Xm5KV.js +0 -1
- package/src/web/dist/assets/ModelManagement-zi8mFqEf.js +0 -1
- package/src/web/dist/assets/PageHeader-DLI9m-gU.js +0 -1
- package/src/web/dist/assets/Profiler-D6Akb9_x.js +0 -1
- package/src/web/dist/assets/RoutingManagement-CeIC-QD2.js +0 -1
- package/src/web/dist/assets/Settings-G5Pswxtq.js +0 -1
- package/src/web/dist/assets/app-CfipX5HX.js +0 -61
- package/src/web/dist/assets/global-D8jT4xUX.css +0 -1
- package/src/web/dist/assets/package-GpB9DOR2.js +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{j as r}from"./vendor-DdPBfMMb.js";import{c as m}from"./global-D8DuA4wF.js";function a({info:s,status:l,actions:e,className:t}){return!s&&!l&&!e?null:r.jsxs("div",{className:m("flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between",t),children:[r.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-2 text-xs text-muted-foreground",children:[l,s]}),e?r.jsx("div",{className:"flex flex-wrap items-center gap-2",children:e}):null]})}export{a as P};
|
|
@@ -0,0 +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-BxRZF-QJ.js";import{P as ke,a as H}from"./PageState-Dvjip2P-.js";import{B as ie,q as $}from"./queryKeys-BpeJfcg0.js";import{g as V,b as Z,r as de,B as O}from"./app-B604X4iv.js";import{c as y}from"./global-D8DuA4wF.js";import{f as Be}from"./utils-DSaa7c6v.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};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{r as S,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-Dx-KyPyo.js";import{P as Me}from"./PageToolbar-BxRZF-QJ.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-B604X4iv.js";import{u as re}from"./useAppMutation-C9CUOR7n.js";import{I as T}from"./input-b5NRkUKN.js";import{L as P}from"./label-DUoPO5Jo.js";import{S as oe,a as de,b as ce,c as me,d as F}from"./select-B5oPLG9G.js";import{S as xe}from"./switch-BDc99Vsq.js";import{q as le,B as C}from"./queryKeys-BpeJfcg0.js";import{u as O}from"./i18n-C8tBby0x.js";import{C as pe,a as ue}from"./card-Bx5Pg_wP.js";import{c as V}from"./global-D8DuA4wF.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-BWia_d99.js";import{P as Ve,a as Be,b as He}from"./popover-BAGiqp11.js";import{i as Ie,g as Fe,a as qe,C as Ge,O as Ke,u as Ue}from"./useModelManagementState-ByZBhfct.js";import"./query-QCek5MsK.js";import"./radix-CtQBp6Ie.js";import"./gateway-CXg6BjAe.js";import"./useApiQuery-b8AdsIsi.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]=S.useState({id:"",label:"",paths:[{path:"",protocol:"openai-auto"}],enabled:!0});S.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)}))},y=(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})},u=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=>y(x,"path",j.target.value),placeholder:a("modelManagement.endpointPathPlaceholder"),required:!0}),e.jsxs(oe,{value:t.protocol,onValueChange:j=>y(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:u,children:a("common.cancel")}),e.jsx(k,{className:"flex-1",onClick:()=>f(),disabled:u,children:a(u?"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 y=o===m.key,f=m.key!=="providers"&&r[m.key];return e.jsxs("button",{type:"button",onClick:()=>p(m.key),"aria-pressed":y,className:V("group flex min-h-[76px] flex-col justify-between rounded-[0.95rem] px-3 py-3 text-left transition-all",y?"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}),y?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 y=o===m.key,f=r[m.key],u=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",y?"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":y,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}),y?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:(u==null?void 0:u.enabled)===!1?"secondary":"success",className:"rounded-full border-0 px-2 py-0.5 text-[10px]",children:(u==null?void 0:u.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(u,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:!u,onClick:()=>{u&&d(u)},children:c("common.edit")}),m.canDelete?e.jsx("button",{type:"button",onClick:l=>{l.stopPropagation(),u&&a({kind:"endpoint",endpoint:u})},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=[],y=[],f=[];for(const l of w){const t=l in c,x=l in n;x&&!t?m.push([l,n[l]]):t&&!x?y.push([l,c[l]]):t&&x&&c[l]!==n[l]&&f.push([l,c[l],n[l]])}const u=m.length>0||y.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:u?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}`)),y.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:!u,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]=S.useState(!1),[c,w]=S.useState(""),m=S.useRef(null),[y,f]=Ce(Ee.modelManagement.recentRouteTargets,[]),u=S.useMemo(()=>{const i=new Map;for(const b of g)i.set(b.value,b);return i},[g]),l=(i,b)=>b?[i.label,i.value,i.providerId??"",i.providerLabel??"",i.modelId??"",i.modelLabel??""].join(" ").toLowerCase().includes(b):!0,t=S.useMemo(()=>{const i=c.trim().toLowerCase(),b=g.filter(v=>l(v,i)),A=y.map(v=>u.get(v)??(i?void 0:{value:v,label:v,kind:"custom"})).filter(v=>!!v).filter(v=>l(v,i)).slice(0,ie),G=new Set(A.map(v=>v.value)),R=[];A.length>0&&R.push({key:"recent",label:d("modelManagement.targetPicker.recent"),options:A});const L=new Map,_=[];for(const v of b){if(G.has(v.value))continue;if(v.kind==="custom"||!v.providerId){_.push(v);continue}const B=`provider:${v.providerId}`,I=L.get(B);I?I.options.push(v):L.set(B,{key:B,label:v.providerLabel??v.providerId,options:[v]})}return R.push(...L.values()),_.length>0&&R.push({key:"custom",label:d("modelManagement.targetPicker.custom"),options:_,muted:!0}),R},[u,g,y,c,d]),x=t.reduce((i,b)=>i+b.options.length,0),j=i=>{s(i),f(b=>[i,...b.filter(A=>A!==i)].slice(0,ie)),w(""),n(!1)},E=i=>i.kind==="passthrough"?d("modelManagement.targetPicker.passthrough"):i.kind==="custom"?d("modelManagement.targetPicker.customValue"):d("modelManagement.targetPicker.model"),D=i=>i.kind==="passthrough"||i.kind==="custom"?i.label:i.modelLabel??i.label;return e.jsxs(Ve,{open:p,onOpenChange:i=>{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:"max-h-80 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:x}):d("modelManagement.targetPicker.helper")})]}),x===0?e.jsx("div",{className:"px-3 py-4 text-center text-xs text-muted-foreground",children:d("common.noMatches")}):e.jsx("div",{className:"max-h-72 overflow-y-auto p-1.5",children:t.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:A=>{A.preventDefault(),j(b.value)},children:[e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate font-medium",children:D(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:E(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:y,applyingPreset:f,deletingPreset:u,presetsExpanded:l,savingClaudeValidation:t,savingCompatibilityPolicy:x,providerModelOptions:j,onTogglePresetsExpanded:E,onPresetNameChange:D,onSavePreset:i,onRequestPresetDiff:b,onRequestDeletePreset:A,onValidationModeChange:G,onCompatibilityEnabledChange:R,onRouteChange:L,onRemoveRoute:_,onAddSuggestion:v,onAddRoute:B,onResetRoutes:I,onSaveRoutes:he}){var ae,te;const{t:h}=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:h(`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:h("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:h("modelManagement.claudeValidation.title")}),e.jsx("p",{className:"max-w-2xl text-xs leading-5 text-muted-foreground dark:text-slate-300",children:h("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:h("modelManagement.claudeValidation.modeLabel")}),e.jsxs(oe,{value:X,onValueChange:N=>G(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:h("modelManagement.claudeValidation.options.off.label")}),e.jsx(F,{value:"anthropic-strict",children:h("modelManagement.claudeValidation.options.anthropic-strict.label")}),e.jsx(F,{value:"claude-code",children:h("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:h(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:h("modelManagement.openaiCompatibility.title")}),e.jsx("p",{className:"max-w-2xl text-xs leading-5 text-muted-foreground dark:text-slate-300",children:h("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:h("modelManagement.openaiCompatibility.toggleLabel")}),e.jsx("p",{className:"text-xs text-muted-foreground dark:text-slate-300",children:h(se?"modelManagement.openaiCompatibility.enabledHint":"modelManagement.openaiCompatibility.disabledHint")})]}),e.jsx(xe,{checked:se,onCheckedChange:R,disabled:x,"aria-label":h("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:y,applyingPreset:f,deletingPreset:u,expanded:l,onToggleExpanded:E,onPresetNameChange:D,onSavePreset:i,onRequestPresetDiff:b,onRequestDeletePreset:A}),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:h("modelManagement.routesEditorTitle")}),e.jsxs(C,{variant:"outline",children:[a.length," active"]})]}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:h("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:h("settings.routing.empty")}),e.jsx("p",{className:"mt-2 text-xs",children:h("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:h("settings.routing.source")}),e.jsx("span",{}),e.jsx("span",{children:h("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:h("settings.routing.source")}),e.jsx(T,{value:N.source,onChange:J=>L(N.id,"source",J.target.value),placeholder:h("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:h("settings.routing.target")}),e.jsx(Ze,{value:N.target,onChange:J=>L(N.id,"target",J),options:j,disabled:p,placeholder:h("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:h("modelManagement.actions.footerTitle")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:h(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:h("settings.routing.add")}),e.jsx(k,{variant:"outline",size:"sm",onClick:I,disabled:p||!n,className:"w-full",children:h("common.actions.reset")}),e.jsxs(k,{size:"sm",onClick:he,disabled:p,className:"relative w-full",children:[h(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:h("settings.routing.suggested")}),e.jsx(C,{variant:"outline",className:"text-[11px]",children:K.length})]}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:h("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:()=>v(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:y}){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:u=>c(u.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(u=>{const l=a===u.name,t=d===u.name,x=Object.entries(u.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:u.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(u),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:()=>y(u),disabled:t||l,className:"w-full sm:w-auto",children:f(t?"modelManagement.presets.deleting":"modelManagement.presets.delete")})]})]},u.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 S.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};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{j as e,aP as J,aJ as xt,am as gt,r as m}from"./vendor-DdPBfMMb.js";import{C as Le}from"./ConfirmDialog-Dx-KyPyo.js";import{L as Fe,B as k,r as Te,g as ft,b as bt,u as vt}from"./app-B604X4iv.js";import{P as jt}from"./PageToolbar-BxRZF-QJ.js";import{C as A,a as L}from"./card-Bx5Pg_wP.js";import{B as E,q as z}from"./queryKeys-BpeJfcg0.js";import{I as w}from"./input-b5NRkUKN.js";import{L as v}from"./label-DUoPO5Jo.js";import{S as V}from"./switch-BDc99Vsq.js";import{S as yt,a as Nt,b as wt,c as Ct,d as Pt}from"./select-B5oPLG9G.js";import{c as M}from"./global-D8DuA4wF.js";import{u as R}from"./i18n-C8tBby0x.js";import{u as Me}from"./useApiQuery-b8AdsIsi.js";import{u as Q}from"./useAppMutation-C9CUOR7n.js";import{g as Oe}from"./gateway-CXg6BjAe.js";import{c as kt}from"./clipboard-CALi6bTW.js";import"./DialogShell-BWia_d99.js";import"./radix-CtQBp6Ie.js";import"./query-QCek5MsK.js";import"./router-D2Fb4U0L.js";const St=[{value:"fatal",labelKey:"fatal"},{value:"error",labelKey:"error"},{value:"warn",labelKey:"warn"},{value:"info",labelKey:"info"},{value:"debug",labelKey:"debug"},{value:"trace",labelKey:"trace"}],te=[{id:"section-basics",labelKey:"settings.sections.basics"},{id:"section-protocol",labelKey:"settings.sections.protocol"},{id:"section-security",labelKey:"settings.sections.security"},{id:"section-config-file",labelKey:"settings.sections.configFile"},{id:"section-cleanup",labelKey:"settings.sections.cleanup"}];function G(s){var o,r,i,n,c,h,p,T,g,d,N;const t=s.storePayloads,a=C=>typeof C=="boolean"?C:typeof t=="boolean"?t:!0;return{port:String(s.port??((o=s.http)==null?void 0:o.port)??""),host:s.host??((r=s.http)==null?void 0:r.host)??"127.0.0.1",logRetentionDays:String(s.logRetentionDays??30),logExportTimeoutSeconds:String(s.logExportTimeoutSeconds??60),storeRequestPayloads:a(s.storeRequestPayloads),storeResponsePayloads:a(s.storeResponsePayloads),logLevel:s.logLevel??"info",bodyLimitMb:(()=>{const C=s.bodyLimit;return typeof C=="number"&&Number.isFinite(C)&&C>0?String(Math.max(1,Math.round(C/(1024*1024)))):"10"})(),enableRoutingFallback:s.enableRoutingFallback===!0,httpEnabled:((i=s.http)==null?void 0:i.enabled)!==!1,httpPort:String(((n=s.http)==null?void 0:n.port)??s.port??4100),httpHost:((c=s.http)==null?void 0:c.host)??s.host??"127.0.0.1",httpsEnabled:((h=s.https)==null?void 0:h.enabled)===!0,httpsPort:String(((p=s.https)==null?void 0:p.port)??4443),httpsHost:((T=s.https)==null?void 0:T.host)??s.host??"127.0.0.1",httpsKeyPath:((g=s.https)==null?void 0:g.keyPath)??"",httpsCertPath:((d=s.https)==null?void 0:d.certPath)??"",httpsCaPath:((N=s.https)==null?void 0:N.caPath)??""}}function U(s){return{enabled:s.enabled,username:s.username??"",password:"",confirmPassword:""}}function Rt({activeSection:s,onSelectSection:t}){const{t:a}=R();return e.jsxs(e.Fragment,{children:[e.jsx("nav",{className:"hidden xl:block",children:e.jsxs("div",{className:"sticky top-20 rounded-[1.1rem] border border-white/70 bg-card/95 p-3.5 shadow-[0_20px_48px_-42px_rgba(15,23,42,0.24)]",children:[e.jsx("p",{className:"mb-2.5 px-2 text-[10px] font-semibold uppercase tracking-wider text-muted-foreground",children:a("settings.sections.jump")}),e.jsx("div",{className:"space-y-1.5",children:te.map((o,r)=>e.jsxs("button",{type:"button",onClick:()=>t(o.id),className:M("flex w-full items-center gap-2.5 rounded-[0.85rem] px-3 py-2 text-left text-sm font-semibold transition-all duration-200",s===o.id?"bg-secondary text-foreground shadow-[inset_0_1px_0_rgba(255,255,255,0.62)]":"text-muted-foreground hover:text-foreground"),children:[e.jsx("span",{className:M("flex h-7 w-7 items-center justify-center rounded-full text-[11px] font-semibold",s===o.id?"bg-primary text-primary-foreground":"bg-secondary text-muted-foreground"),children:r+1}),e.jsx("span",{children:a(o.labelKey)})]},o.id))})]})}),e.jsx("div",{className:"xl:hidden",children:e.jsx("div",{className:"overflow-x-auto pb-1",children:e.jsx("div",{className:"flex w-max gap-2 px-1",children:te.map(o=>e.jsx("button",{type:"button",onClick:()=>t(o.id),className:M("rounded-full px-4 py-2 text-xs font-semibold transition-all duration-150",s===o.id?"bg-secondary text-foreground font-medium":"text-muted-foreground hover:text-foreground hover:bg-secondary/50"),children:a(o.labelKey)},o.id))})})})]})}function Et({configPath:s,defaultsSummary:t,form:a,protocolSummaryLabel:o,protocolChangesPending:r,isAuthDirty:i,isConfigDirty:n,authEnabled:c,authUsername:h}){const{t:p}=R();return e.jsx(A,{variant:"ghost",className:"rounded-[1.25rem] border border-white/70 bg-card/95 shadow-[0_20px_50px_-42px_rgba(15,23,42,0.24)]",children:e.jsxs(L,{className:"space-y-3 p-4",children:[e.jsxs("div",{className:"flex flex-col gap-2 lg:flex-row lg:items-center lg:justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-[10px] font-semibold uppercase tracking-[0.18em] text-primary/75",children:p("settings.overview.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:p("settings.overview.description")})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(E,{variant:n||i?"warning":"success",children:p(n||i?"modelManagement.actions.unsaved":"common.status.success")}),r?e.jsx(E,{variant:"outline",className:"border-amber-300 text-amber-700 dark:border-amber-700 dark:text-amber-300",children:p("settings.protocol.restartWarning")}):null]})]}),e.jsxs("div",{className:"grid gap-3 md:grid-cols-3",children:[e.jsx(X,{label:p("settings.overview.cards.protocols"),value:o,helper:`${a.httpHost||"127.0.0.1"}:${a.httpPort}${a.httpsEnabled?` / ${a.httpsHost||"127.0.0.1"}:${a.httpsPort}`:""}`}),e.jsx(X,{label:p("settings.overview.cards.security"),value:p(c?"settings.overview.values.authEnabled":"settings.overview.values.authDisabled"),helper:h?`${p("settings.auth.username")}: ${h}`:p("settings.auth.enableHint")}),e.jsx(X,{label:p("settings.overview.cards.configFile"),value:s||p("settings.file.unknown"),helper:t??p("settings.defaults.none"),mono:!0})]})]})})}function At({defaultsSummary:s,errors:t,form:a,onInputChange:o,onSetForm:r,sectionRef:i}){const{t:n}=R();return e.jsx(A,{id:"section-basics",ref:i,className:"bg-card shadow-[var(--surface-shadow)]",children:e.jsxs(L,{className:"pt-6",children:[e.jsxs("div",{className:"mb-4 flex flex-col gap-3 lg:flex-row lg:items-start lg:justify-between",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold",children:n("settings.sections.basics")}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:n("settings.description")})]}),e.jsxs("div",{className:"grid gap-2 sm:grid-cols-3",children:[e.jsx(Y,{label:n("settings.fields.retention"),value:a.logRetentionDays}),e.jsx(Y,{label:n("settings.fields.logExportTimeout"),value:`${a.logExportTimeoutSeconds}s`}),e.jsx(Y,{label:n("settings.fields.bodyLimit"),value:`${a.bodyLimitMb} MB`})]})]}),e.jsxs("div",{className:"grid gap-5 md:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(v,{children:n("settings.fields.port")}),e.jsx(w,{type:"number",min:1,max:65535,value:a.port,onChange:c=>o("port")(c.target.value),"aria-invalid":!!t.port}),t.port?e.jsx("p",{className:"text-xs text-destructive",children:t.port}):null]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(v,{children:n("settings.fields.host")}),e.jsx(w,{value:a.host,onChange:c=>o("host")(c.target.value),placeholder:n("settings.fields.hostPlaceholder")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(v,{children:n("settings.fields.retention")}),e.jsx(w,{type:"number",min:1,max:365,value:a.logRetentionDays,onChange:c=>o("logRetentionDays")(c.target.value),"aria-invalid":!!t.logRetentionDays}),t.logRetentionDays?e.jsx("p",{className:"text-xs text-destructive",children:t.logRetentionDays}):null]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(v,{children:n("settings.fields.logExportTimeout")}),e.jsx(w,{type:"number",min:5,max:600,value:a.logExportTimeoutSeconds,onChange:c=>o("logExportTimeoutSeconds")(c.target.value),"aria-invalid":!!t.logExportTimeoutSeconds}),e.jsx("p",{className:"text-xs text-muted-foreground",children:n("settings.fields.logExportTimeoutHint")}),t.logExportTimeoutSeconds?e.jsx("p",{className:"text-xs text-destructive",children:t.logExportTimeoutSeconds}):null]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(v,{children:n("settings.fields.bodyLimit")}),e.jsx(w,{type:"number",min:1,max:2048,value:a.bodyLimitMb,onChange:c=>o("bodyLimitMb")(c.target.value),"aria-invalid":!!t.bodyLimitMb}),e.jsx("p",{className:"text-xs text-muted-foreground",children:n("settings.fields.bodyLimitHint")}),t.bodyLimitMb?e.jsx("p",{className:"text-xs text-destructive",children:t.bodyLimitMb}):null]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(v,{children:n("settings.fields.logLevel")}),e.jsxs(yt,{value:a.logLevel,onValueChange:c=>r(h=>({...h,logLevel:c})),children:[e.jsx(Nt,{children:e.jsx(wt,{})}),e.jsx(Ct,{children:St.map(c=>e.jsx(Pt,{value:c.value,children:n(`settings.fields.logLevelOption.${c.labelKey}`)},c.value))})]})]}),e.jsxs("div",{className:"grid gap-4 md:col-span-2 sm:grid-cols-2",children:[e.jsx(Z,{label:n("settings.fields.storeRequestPayloads"),hint:n("settings.fields.storeRequestPayloadsHint"),checked:a.storeRequestPayloads,onCheckedChange:c=>r(h=>({...h,storeRequestPayloads:c}))}),e.jsx(Z,{label:n("settings.fields.storeResponsePayloads"),hint:n("settings.fields.storeResponsePayloadsHint"),checked:a.storeResponsePayloads,onCheckedChange:c=>r(h=>({...h,storeResponsePayloads:c}))}),e.jsx(Z,{label:n("settings.fields.enableRoutingFallback"),hint:n("settings.fields.enableRoutingFallbackHint"),checked:a.enableRoutingFallback,onCheckedChange:c=>r(h=>({...h,enableRoutingFallback:c}))})]}),e.jsxs("div",{className:"rounded-xl bg-secondary px-4 py-5 md:col-span-2",children:[e.jsx(v,{className:"text-xs uppercase tracking-wide text-muted-foreground",children:n("settings.fields.defaults")}),e.jsx("p",{className:"mt-2 text-sm",children:s??n("settings.defaults.none")})]})]})]})})}function Lt({errors:s,form:t,onSetForm:a,sectionRef:o}){const{t:r}=R();return e.jsx(A,{id:"section-protocol",ref:o,className:"bg-card shadow-[var(--surface-shadow)]",children:e.jsxs(L,{className:"space-y-6 pt-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold",children:r("settings.sections.protocol")}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:r("settings.protocol.description")})]}),e.jsx("div",{className:"rounded-xl bg-amber-50 ring-1 ring-amber-200/50 p-4 shadow-sm dark:bg-amber-950/24 dark:ring-amber-500/20",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(J,{className:"mt-0.5 h-5 w-5 flex-shrink-0 text-amber-600 dark:text-amber-400"}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm font-medium text-foreground",children:r("settings.protocol.restartWarning")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:r("settings.protocol.restartHint")}),e.jsx("code",{className:"block rounded-lg border border-border bg-secondary px-3 py-2 text-xs font-mono text-foreground dark:bg-secondary dark:border-border",children:"cc-gw restart --daemon"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:r("settings.protocol.restartTip")})]})]})}),s.protocol?e.jsxs("div",{className:"rounded-xl bg-destructive/10 ring-1 ring-destructive/30 p-4 text-sm text-destructive shadow-sm",children:[e.jsx(J,{className:"mr-2 inline h-4 w-4"}),s.protocol]}):null,e.jsxs("div",{className:"rounded-xl bg-secondary p-5 dark:bg-secondary",children:[e.jsxs("div",{className:"mb-4 flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(v,{className:"text-sm font-medium text-foreground",children:r("settings.protocol.http.enable")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:r("settings.protocol.http.hint")})]}),e.jsx(V,{checked:t.httpEnabled,onCheckedChange:i=>a(n=>({...n,httpEnabled:i}))})]}),t.httpEnabled?e.jsxs("div",{className:"mt-4 grid gap-4 border-t border-border pt-4 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(v,{children:r("settings.protocol.http.port")}),e.jsx(w,{type:"number",min:1,max:65535,value:t.httpPort,onChange:i=>a(n=>({...n,httpPort:i.target.value})),"aria-invalid":!!s.httpPort}),s.httpPort?e.jsx("p",{className:"text-xs text-destructive",children:s.httpPort}):null]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(v,{children:r("settings.protocol.http.host")}),e.jsx(w,{value:t.httpHost,onChange:i=>a(n=>({...n,httpHost:i.target.value})),placeholder:"127.0.0.1"})]})]}):null]}),e.jsxs("div",{className:"rounded-xl bg-secondary p-5 dark:bg-secondary",children:[e.jsxs("div",{className:"mb-4 flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(v,{className:"text-sm font-medium text-foreground",children:r("settings.protocol.https.enable")}),e.jsx(xt,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:r("settings.protocol.https.hint")})]}),e.jsx(V,{checked:t.httpsEnabled,onCheckedChange:i=>a(n=>({...n,httpsEnabled:i}))})]}),t.httpsEnabled?e.jsxs("div",{className:"mt-4 space-y-4 border-t border-border pt-4",children:[e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(v,{children:r("settings.protocol.https.port")}),e.jsx(w,{type:"number",min:1,max:65535,value:t.httpsPort,onChange:i=>a(n=>({...n,httpsPort:i.target.value})),"aria-invalid":!!s.httpsPort}),s.httpsPort?e.jsx("p",{className:"text-xs text-destructive",children:s.httpsPort}):null]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(v,{children:r("settings.protocol.https.host")}),e.jsx(w,{value:t.httpsHost,onChange:i=>a(n=>({...n,httpsHost:i.target.value})),placeholder:"127.0.0.1"})]})]}),e.jsx(ee,{label:r("settings.protocol.https.keyPath"),value:t.httpsKeyPath,onChange:i=>a(n=>({...n,httpsKeyPath:i})),placeholder:"~/.cc-gw/certs/key.pem"}),e.jsx(ee,{label:r("settings.protocol.https.certPath"),value:t.httpsCertPath,onChange:i=>a(n=>({...n,httpsCertPath:i})),placeholder:"~/.cc-gw/certs/cert.pem"}),e.jsx(ee,{label:r("settings.protocol.https.caPath"),value:t.httpsCaPath,onChange:i=>a(n=>({...n,httpsCaPath:i})),placeholder:"留空则不使用"}),e.jsx("div",{className:"rounded-xl bg-amber-50 ring-1 ring-amber-200/50 p-4 shadow-sm dark:bg-amber-950/24 dark:ring-amber-500/20",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(J,{className:"mt-0.5 h-5 w-5 flex-shrink-0 text-amber-600 dark:text-amber-400"}),e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsx("p",{className:"text-sm font-medium text-amber-800 dark:text-amber-200",children:r("settings.protocol.https.warning")}),e.jsxs("p",{className:"text-xs leading-relaxed text-amber-700 dark:text-amber-300",children:[e.jsx("strong",{children:r("settings.protocol.https.invalidCert")}),r("settings.protocol.https.invalidCertDetail")]}),e.jsxs("p",{className:"text-xs leading-relaxed text-amber-700 dark:text-amber-300",children:[e.jsx("strong",{children:r("settings.protocol.https.recommended")}),r("settings.protocol.https.recommendedDetail")]}),e.jsx("p",{className:"text-xs leading-relaxed text-amber-600 dark:text-amber-400",children:r("settings.protocol.https.tip")})]})]})})]}):null]})]})})}function Tt({authErrors:s,authForm:t,authLoading:a,authSettings:o,needsPassword:r,onAuthReset:i,onAuthSave:n,onSetAuthForm:c,savingAuth:h,isAuthDirty:p,sectionRef:T}){const{t:g}=R();return e.jsx(A,{id:"section-security",ref:T,className:"bg-card shadow-[var(--surface-shadow)]",children:e.jsxs(L,{className:"space-y-5 pt-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold",children:g("settings.sections.security")}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:g("settings.auth.description")})]}),a&&!o?e.jsx("div",{className:"flex min-h-[120px] items-center justify-center",children:e.jsx(Fe,{})}):e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex flex-col gap-4 rounded-xl bg-secondary p-4 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(v,{className:"text-sm font-medium",children:g("settings.auth.enable")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:g("settings.auth.enableHint")}),e.jsxs("div",{className:"flex flex-wrap gap-2 text-xs font-medium text-muted-foreground",children:[e.jsx("span",{className:"rounded-full bg-secondary px-3 py-1 text-[11px] tracking-[0.08em]",children:"/ui"}),e.jsx("span",{className:"rounded-full bg-secondary px-3 py-1 text-[11px] tracking-[0.08em]",children:"/api/*"}),e.jsx("span",{className:"rounded-full bg-secondary px-3 py-1 text-[11px] tracking-[0.08em]",children:"Cookie Session"})]})]}),e.jsxs("div",{className:"flex items-center gap-3 self-start sm:self-auto",children:[e.jsx(E,{variant:t.enabled?"success":"secondary",children:t.enabled?g("settings.auth.statusEnabled"):g("settings.auth.statusDisabled")}),e.jsx(V,{checked:t.enabled,onCheckedChange:d=>c(N=>({...N,enabled:d}))})]})]}),e.jsxs("div",{className:"grid gap-6 lg:grid-cols-[minmax(0,1fr)_minmax(0,0.85fr)]",children:[e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2 sm:col-span-2",children:[e.jsx(v,{children:g("settings.auth.username")}),e.jsx(w,{value:t.username,onChange:d=>c(N=>({...N,username:d.target.value})),placeholder:g("settings.auth.usernamePlaceholder")}),s.username?e.jsx("p",{className:"text-xs text-destructive",children:s.username}):null]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(v,{children:g("settings.auth.password")}),e.jsx(w,{type:"password",value:t.password,disabled:!t.enabled,onChange:d=>c(N=>({...N,password:d.target.value})),placeholder:g("settings.auth.passwordPlaceholder")}),s.password?e.jsx("p",{className:"text-xs text-destructive",children:s.password}):e.jsx("p",{className:"text-xs text-muted-foreground",children:g(r?"settings.auth.passwordHintRequired":"settings.auth.passwordHintOptional")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(v,{children:g("settings.auth.confirmPassword")}),e.jsx(w,{type:"password",value:t.confirmPassword,disabled:!t.enabled,onChange:d=>c(N=>({...N,confirmPassword:d.target.value})),placeholder:g("settings.auth.confirmPasswordPlaceholder")}),s.confirmPassword?e.jsx("p",{className:"text-xs text-destructive",children:s.confirmPassword}):null]})]}),e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"rounded-xl bg-secondary p-4",children:[e.jsx("p",{className:"text-[10px] font-semibold uppercase tracking-[0.34em] text-muted-foreground",children:g("settings.auth.status")}),e.jsx("p",{className:"mt-2 text-base font-semibold",children:o!=null&&o.enabled?g("settings.auth.statusEnabled"):g("settings.auth.statusDisabled")}),o!=null&&o.username?e.jsxs("div",{className:"mt-3 rounded-lg bg-accent px-3 py-2 text-xs font-medium text-primary",children:[g("settings.auth.username"),": ",o.username]}):null]}),e.jsx("div",{className:"rounded-xl bg-secondary px-4 py-3 text-xs text-muted-foreground",children:g(r?"settings.auth.passwordHintRequired":"settings.auth.passwordHintOptional")})]})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2 lg:flex lg:flex-wrap lg:justify-end",children:[e.jsx(k,{onClick:n,disabled:h||!p,className:"w-full lg:w-auto",children:g(h?"common.actions.saving":"settings.auth.actions.save")}),e.jsx(k,{variant:"outline",onClick:i,disabled:h||!p,className:"w-full lg:w-auto",children:g("common.actions.reset")})]})]})]})})}function Mt({configPath:s,onCopyPath:t,sectionRef:a}){const{t:o}=R();return e.jsx(A,{id:"section-config-file",ref:a,className:"bg-card shadow-[var(--surface-shadow)]",children:e.jsxs(L,{className:"space-y-3 pt-6",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.jsx("h3",{className:"text-sm font-semibold",children:o("settings.sections.configFile")}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:o("settings.file.description")})]}),e.jsxs(k,{variant:"outline",size:"sm",onClick:t,className:"w-full sm:w-auto",children:[e.jsx(gt,{className:"mr-2 h-4 w-4"}),o("common.actions.copy")]})]}),e.jsx("code",{className:"block break-all rounded-lg bg-secondary px-4 py-3 text-xs font-mono text-muted-foreground",children:s||o("settings.file.unknown")}),e.jsx("div",{className:"rounded-lg bg-secondary px-4 py-3 text-xs text-muted-foreground",children:o("help.note")})]})})}function Ot({cleaning:s,clearingAll:t,onOpenCleanup:a,onOpenClearAll:o,sectionRef:r}){const{t:i}=R();return e.jsx(A,{id:"section-cleanup",ref:r,className:"bg-card shadow-[var(--surface-shadow)]",children:e.jsxs(L,{className:"space-y-4 pt-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold",children:i("settings.sections.cleanup")}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:i("settings.cleanup.description")})]}),e.jsx("div",{className:"rounded-lg bg-secondary px-4 py-3 text-xs text-muted-foreground",children:i("settings.cleanup.confirmCleanup")}),e.jsxs("div",{className:"grid gap-4 lg:grid-cols-2",children:[e.jsx("div",{className:"rounded-xl border border-amber-200 bg-amber-50 p-5 dark:border-amber-800 dark:bg-amber-950/30",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx(E,{variant:"warning",children:i("settings.cleanup.softLabel")}),e.jsx("p",{className:"text-sm font-medium",children:i("settings.cleanup.softTitle")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:i("settings.cleanup.softDescription")}),e.jsx(k,{variant:"outline",onClick:a,disabled:s,className:"w-full sm:w-auto",children:i(s?"common.actions.cleaning":"common.actions.cleanup")})]})}),e.jsx("div",{className:"rounded-xl border border-destructive/30 bg-destructive/10 p-5 text-destructive",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx(E,{variant:"outline",className:"border-destructive/40 bg-destructive/10 text-destructive",children:i("settings.cleanup.hardLabel")}),e.jsx("p",{className:"text-sm font-medium",children:i("settings.cleanup.hardTitle")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:i("settings.cleanup.clearAllWarning")}),e.jsx(k,{variant:"destructive",onClick:o,disabled:t,className:"w-full sm:w-auto",children:i(t?"settings.cleanup.clearingAll":"settings.cleanup.clearAll")})]})})]})]})})}function Ft({isAuthDirty:s,isConfigDirty:t,protocolChangesPending:a,onAuthReset:o,onAuthSave:r,onReset:i,onSave:n,saving:c,savingAuth:h}){const{t:p}=R();return!s&&!t?null:e.jsxs("div",{className:"sticky bottom-4 z-20 flex flex-col gap-3 rounded-xl bg-card border border-border px-6 py-5 shadow-lg md:flex-row md:items-center md:justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(E,{variant:"secondary",children:p("modelManagement.actions.unsaved")}),t?e.jsx(E,{variant:"outline",children:p("settings.sections.basics")}):null,s?e.jsx(E,{variant:"outline",children:p("settings.sections.security")}):null,a?e.jsx(E,{variant:"outline",className:"border-amber-300 text-amber-700 dark:border-amber-700 dark:text-amber-300",children:p("settings.sections.protocol")}):null]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:p(a?"settings.toast.protocolRestartRequired":"modelManagement.actions.footerDirtyHint")})]}),e.jsxs("div",{className:"grid gap-2 sm:grid-cols-2 lg:flex lg:flex-wrap lg:items-center",children:[s?e.jsxs(e.Fragment,{children:[e.jsx(k,{variant:"outline",onClick:o,disabled:h,className:"w-full lg:w-auto",children:p("common.actions.reset")}),e.jsx(k,{onClick:r,disabled:h,className:"w-full lg:w-auto",children:p(h?"common.actions.saving":"settings.auth.actions.save")})]}):null,t?e.jsxs(e.Fragment,{children:[e.jsx(k,{variant:"outline",onClick:i,disabled:c,className:"w-full lg:w-auto",children:p("common.actions.reset")}),e.jsx(k,{onClick:n,disabled:c,className:"w-full lg:w-auto",children:p(c?"common.actions.saving":"common.actions.save")})]}):null]})]})}function X({label:s,value:t,helper:a,mono:o=!1}){return e.jsxs("div",{className:"min-w-0 rounded-[0.95rem] bg-secondary/65 px-3.5 py-3 shadow-[inset_0_1px_0_rgba(255,255,255,0.62)]",children:[e.jsx("p",{className:"text-[10px] font-semibold uppercase tracking-[0.22em] text-muted-foreground",children:s}),e.jsx("p",{className:M("mt-1.5 truncate text-xl font-semibold text-foreground",o?"font-mono text-sm leading-tight":""),title:typeof t=="string"?t:void 0,children:t}),e.jsx("p",{className:"mt-1.5 line-clamp-2 text-xs leading-relaxed text-muted-foreground",children:a})]})}function Y({label:s,value:t}){return e.jsxs("div",{className:"rounded-lg bg-secondary px-3 py-2 text-center",children:[e.jsx("p",{className:"text-[10px] font-semibold uppercase tracking-[0.3em] text-muted-foreground",children:s}),e.jsx("p",{className:"mt-1 text-sm font-semibold text-foreground",children:t})]})}function Z({checked:s,className:t,hint:a,hintClassName:o,label:r,labelClassName:i,onCheckedChange:n}){return e.jsxs("div",{className:M("flex flex-col gap-3 rounded-xl bg-secondary p-4 sm:flex-row sm:items-center sm:justify-between",t),children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(v,{className:M("text-sm font-semibold text-foreground",i),children:r}),e.jsx("p",{className:M("text-xs text-muted-foreground",o),children:a})]}),e.jsx(V,{checked:s,onCheckedChange:n,className:"self-start sm:self-auto"})]})}function ee({label:s,onChange:t,placeholder:a,value:o}){return e.jsxs("div",{className:"space-y-2",children:[e.jsx(v,{children:s}),e.jsx(w,{value:o,onChange:r=>t(r.target.value),placeholder:a,className:"font-mono text-xs"})]})}const _={authStatusRequest(){return{url:"/api/auth/web",method:"GET"}},saveWebAuth:async s=>ft(bt.post("/api/auth/web",s)),cleanupLogs:async()=>Te({url:"/api/logs/cleanup",method:"POST"}),clearLogs:async()=>Te({url:"/api/logs/clear",method:"POST"})};function Dt(){const{t:s}=R(),{pushToast:t}=vt(),[a,o]=m.useState(te[0].id),r=m.useRef(new Map),i=m.useCallback(l=>{const x=r.current.get(l);x&&x.scrollIntoView({behavior:"smooth",block:"start"})},[]),n=m.useCallback(l=>x=>{x?r.current.set(l,x):r.current.delete(l)},[]),c=Me(z.config.info(),Oe.configInfoRequest()),h=Me(z.auth.web(),_.authStatusRequest()),p=Q({mutationFn:_.saveWebAuth,successToast:()=>({title:s("settings.auth.toast.success")}),errorToast:l=>({title:s("settings.auth.toast.failure",{message:l.message})}),invalidateKeys:[z.auth.web()]}),T=Q({mutationFn:_.cleanupLogs,successToast:l=>({title:l.deleted>0?s("settings.toast.cleanupSuccess",{count:l.deleted}):s("settings.toast.cleanupNone")}),errorToast:l=>({title:s("settings.toast.cleanupFailure",{message:l.message})})}),g=Q({mutationFn:_.clearLogs,successToast:l=>({title:s("settings.toast.clearAllSuccess",{logs:l.deleted,metrics:l.metricsCleared})}),errorToast:l=>({title:s("settings.toast.clearAllFailure",{message:l.message})})}),[d,N]=m.useState(null),[C,De]=m.useState(""),[u,D]=m.useState({port:"",host:"",logRetentionDays:"",logExportTimeoutSeconds:"60",storeRequestPayloads:!0,storeResponsePayloads:!0,logLevel:"info",bodyLimitMb:"10",enableRoutingFallback:!1,httpEnabled:!0,httpPort:"4100",httpHost:"127.0.0.1",httpsEnabled:!1,httpsPort:"4443",httpsHost:"127.0.0.1",httpsKeyPath:"",httpsCertPath:"",httpsCaPath:""}),[He,B]=m.useState({}),[Ke,se]=m.useState(!1),[qe,ae]=m.useState(!1),[_e,ne]=m.useState(!1),[Ve,Be]=m.useState(!1),[Ie,$e]=m.useState(!1),[j,le]=m.useState(null),[f,H]=m.useState({enabled:!1,username:"",password:"",confirmPassword:""}),[We,K]=m.useState({}),[Je,re]=m.useState(!1),ze=m.useMemo(()=>{if(!(d!=null&&d.defaults))return null;const l=[];return d.defaults.completion&&l.push(s("settings.defaults.completion",{model:d.defaults.completion})),d.defaults.reasoning&&l.push(s("settings.defaults.reasoning",{model:d.defaults.reasoning})),d.defaults.background&&l.push(s("settings.defaults.background",{model:d.defaults.background})),l.length>0?l.join(" | "):s("settings.defaults.none")},[d,s]),Qe=m.useMemo(()=>u.httpEnabled&&u.httpsEnabled?s("settings.overview.values.httpAndHttps"):u.httpsEnabled?s("settings.overview.values.httpsOnly"):s("settings.overview.values.httpOnly"),[u.httpEnabled,u.httpsEnabled,s]),Ge=m.useMemo(()=>f.enabled?j!=null&&j.hasPassword?f.username.trim()!==(j.username??""):!0:!1,[f.enabled,f.username,j]),O=m.useMemo(()=>d?G(d):null,[d]),Ue=m.useMemo(()=>O?JSON.stringify(u)!==JSON.stringify(O):!1,[u,O]),I=m.useMemo(()=>j?U(j):null,[j]),Xe=m.useMemo(()=>I?JSON.stringify(f)!==JSON.stringify(I):!1,[f,I]),Ye=m.useMemo(()=>O?["httpEnabled","httpPort","httpHost","httpsEnabled","httpsPort","httpsHost","httpsKeyPath","httpsCertPath","httpsCaPath","port","host"].some(x=>u[x]!==O[x]):!1,[u,O]);m.useEffect(()=>{c.data&&(N(c.data.config),De(c.data.path),D(G(c.data.config)))},[c.data]),m.useEffect(()=>{h.data&&(le(h.data),H(U(h.data)),K({}))},[h.data]),m.useEffect(()=>{!c.isError||!c.error||t({title:s("settings.toast.loadFailure",{message:c.error.message}),variant:"error"})},[c.error,c.isError,t,s]),m.useEffect(()=>{!h.isError||!h.error||t({title:s("settings.toast.authLoadFailure",{message:h.error.message}),variant:"error"})},[h.error,h.isError,t,s]);const Ze=m.useCallback(l=>x=>{D(y=>({...y,[l]:x}))},[]),oe=m.useCallback(()=>{const l={};if(!u.httpEnabled&&!u.httpsEnabled&&(l.protocol=s("settings.validation.protocolRequired")),u.httpEnabled){const S=Number(u.httpPort);(!Number.isFinite(S)||S<1||S>65535)&&(l.httpPort=s("settings.validation.httpPort"))}if(u.httpsEnabled){const S=Number(u.httpsPort);(!Number.isFinite(S)||S<1||S>65535)&&(l.httpsPort=s("settings.validation.httpsPort")),(!u.httpsKeyPath||!u.httpsCertPath)&&(l.protocol=s("settings.validation.httpsCertificate"))}const x=Number(u.port);(!Number.isFinite(x)||x<1||x>65535)&&(l.port=s("settings.validation.port"));const y=Number(u.logRetentionDays);(!Number.isFinite(y)||y<1||y>365)&&(l.logRetentionDays=s("settings.validation.retention"));const P=Number(u.logExportTimeoutSeconds);(!Number.isFinite(P)||P<5||P>600)&&(l.logExportTimeoutSeconds=s("settings.validation.logExportTimeout"));const F=Number(u.bodyLimitMb);return(!Number.isFinite(F)||F<1||F>2048)&&(l.bodyLimitMb=s("settings.validation.bodyLimit")),B(l),Object.keys(l).length===0},[u,s]),ie=m.useCallback(()=>{const l={},x=f.username.trim(),y=j?x!==(j.username??""):!0,P=f.enabled&&(!(j!=null&&j.hasPassword)||y);return f.enabled&&!x&&(l.username=s("settings.auth.validation.username")),f.password&&f.password.length<6&&(l.password=s("settings.auth.validation.minLength")),P&&!f.password&&(l.password=s("settings.auth.validation.passwordRequired")),(f.password||f.confirmPassword)&&f.password!==f.confirmPassword&&(l.confirmPassword=s("settings.auth.validation.confirmMismatch")),K(l),Object.keys(l).length===0},[f,j,s]),et=m.useCallback(async()=>{var l,x,y,P,F,S,ce,de,ue,me,pe,he,xe,ge,fe,be,ve,je,ye,Ne,we,Ce,Pe,ke,Se,Re;if(!d){t({title:s("settings.toast.loadFailure",{message:s("settings.toast.missingConfig")}),variant:"error"});return}if(oe()){se(!0);try{const q=Number(u.port),ot=Number(u.logRetentionDays),it=Number(u.logExportTimeoutSeconds),ct=Number(u.bodyLimitMb),b={...d,http:{enabled:u.httpEnabled,port:Number(u.httpPort),host:u.httpHost.trim()||"127.0.0.1"},https:{enabled:u.httpsEnabled,port:Number(u.httpsPort),host:u.httpsHost.trim()||"127.0.0.1",keyPath:u.httpsKeyPath.trim(),certPath:u.httpsCertPath.trim(),caPath:u.httpsCaPath.trim()||void 0},port:q,host:u.host.trim()||void 0,logRetentionDays:ot,logExportTimeoutSeconds:Math.min(Math.max(Math.round(it),5),600),storeRequestPayloads:u.storeRequestPayloads,storeResponsePayloads:u.storeResponsePayloads,logLevel:u.logLevel,bodyLimit:Math.max(1,Math.floor(ct*1024*1024)),enableRoutingFallback:u.enableRoutingFallback};delete b.requestLogging,delete b.responseLogging;const Ee={...b};delete Ee.webAuth,await Oe.saveConfig(Ee),N({...b,webAuth:d.webAuth});const Ae=W=>(W==null?void 0:W.trim())||void 0,dt=d.port??((l=d.http)==null?void 0:l.port)??4100,ut=b.port??((x=b.http)==null?void 0:x.port)??4100,mt=((y=d.host)==null?void 0:y.trim())||((F=(P=d.http)==null?void 0:P.host)==null?void 0:F.trim())||"127.0.0.1",pt=((S=b.host)==null?void 0:S.trim())||((de=(ce=b.http)==null?void 0:ce.host)==null?void 0:de.trim())||"127.0.0.1",ht=dt!==ut||mt!==pt||((ue=d.http)==null?void 0:ue.enabled)!==((me=b.http)==null?void 0:me.enabled)||((pe=d.http)==null?void 0:pe.port)!==((he=b.http)==null?void 0:he.port)||(((xe=d.http)==null?void 0:xe.host)??d.host??"127.0.0.1")!==(((ge=b.http)==null?void 0:ge.host)??b.host??"127.0.0.1")||((fe=d.https)==null?void 0:fe.enabled)!==((be=b.https)==null?void 0:be.enabled)||((ve=d.https)==null?void 0:ve.port)!==((je=b.https)==null?void 0:je.port)||(((ye=d.https)==null?void 0:ye.host)??d.host??"127.0.0.1")!==(((Ne=b.https)==null?void 0:Ne.host)??b.host??"127.0.0.1")||((we=d.https)==null?void 0:we.keyPath)!==((Ce=b.https)==null?void 0:Ce.keyPath)||((Pe=d.https)==null?void 0:Pe.certPath)!==((ke=b.https)==null?void 0:ke.certPath)||Ae((Se=d.https)==null?void 0:Se.caPath)!==Ae((Re=b.https)==null?void 0:Re.caPath);t({title:s(ht?"settings.toast.protocolRestartRequired":"settings.toast.saveSuccess"),variant:"success"}),c.refetch()}catch(q){t({title:s("settings.toast.saveFailure",{message:q instanceof Error?q.message:"unknown"}),variant:"error"})}finally{se(!1)}}},[d,c,u,t,s,oe]),tt=m.useCallback(()=>{d&&(D(G(d)),B({}))},[d]),st=m.useCallback(async()=>{if(ie()){re(!0);try{const l={enabled:f.enabled,username:f.username.trim()||void 0};f.password&&(l.password=f.password);const x=await p.mutateAsync(l);x.auth&&(le(x.auth),H({enabled:x.auth.enabled,username:x.auth.username??"",password:"",confirmPassword:""}),K({})),h.refetch()}catch{}finally{re(!1)}}},[f,h,p,ie]),at=m.useCallback(()=>{j&&(H(U(j)),K({}))},[j]),nt=m.useCallback(async()=>{if(!C){t({title:s("settings.toast.copyFailure",{message:s("settings.file.unknown")}),variant:"error"});return}try{await kt(C),t({title:s("settings.toast.copySuccess"),variant:"success"})}catch(l){t({title:s("settings.toast.copyFailure",{message:l instanceof Error?l.message:"unknown"}),variant:"error"})}},[C,t,s]),lt=m.useCallback(async()=>{ae(!0);try{await T.mutateAsync()}catch{}finally{ae(!1)}},[T]),rt=m.useCallback(async()=>{ne(!0);try{await g.mutateAsync()}catch{}finally{ne(!1)}},[g]),$=c.isPending||!d&&c.isFetching;return m.useEffect(()=>{if($)return;const l=Array.from(r.current.values());if(l.length===0)return;const x=new IntersectionObserver(y=>{for(const P of y)if(P.isIntersecting){o(P.target.id);break}},{rootMargin:"-80px 0px -60% 0px",threshold:0});for(const y of l)x.observe(y);return()=>x.disconnect()},[$]),{activeSection:a,authErrors:We,authForm:f,authQuery:h,authSettings:j,clearingAll:_e,cleaning:qe,config:d,configPath:C,configQuery:c,confirmCleanupOpen:Ve,confirmClearAllOpen:Ie,defaultsSummary:ze,errors:He,form:u,handleAuthReset:at,handleAuthSave:st,handleCleanupLogs:lt,handleClearAllLogs:rt,handleCopyPath:nt,handleInputChange:Ze,handleReset:tt,handleSave:et,handleSectionClick:i,isAuthDirty:Xe,isConfigDirty:Ue,isLoading:$,needsPassword:Ge,protocolSummaryLabel:Qe,protocolChangesPending:Ye,saving:Ke,savingAuth:Je,sectionRefs:r,setAuthForm:H,setConfirmCleanupOpen:Be,setConfirmClearAllOpen:$e,setErrors:B,setForm:D,setSectionRef:n,t:s}}function as(){var o,r;const{t:s}=R(),t=Dt(),a=Number(t.isConfigDirty)+Number(t.isAuthDirty);return e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx(jt,{info:a>0?e.jsx("span",{className:"rounded-full bg-amber-100 px-2.5 py-1 text-xs font-medium text-amber-800 dark:bg-amber-950/40 dark:text-amber-300",children:s("settings.overview.unsavedCount",{count:a})}):null,status:t.config?e.jsx("span",{className:"text-xs text-muted-foreground",children:t.protocolChangesPending?s("settings.protocol.restartWarning"):s("common.status.success")}):null,actions:t.config?e.jsxs(e.Fragment,{children:[e.jsx(k,{variant:"outline",size:"sm",onClick:t.handleReset,disabled:t.saving||!t.isConfigDirty,children:s("common.actions.reset")}),e.jsx(k,{size:"sm",onClick:()=>void t.handleSave(),disabled:t.saving||!t.isConfigDirty,children:t.saving?s("common.actions.saving"):s("common.actions.save")})]}):null}),t.isLoading?e.jsx(A,{className:"bg-card/82",children:e.jsx(L,{className:"flex min-h-[220px] items-center justify-center",children:e.jsx(Fe,{})})}):t.config?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid gap-6 xl:grid-cols-[200px_1fr]",children:[e.jsx(Rt,{activeSection:t.activeSection,onSelectSection:t.handleSectionClick}),e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx(Et,{configPath:t.configPath,defaultsSummary:t.defaultsSummary,form:t.form,protocolSummaryLabel:t.protocolSummaryLabel,protocolChangesPending:t.protocolChangesPending,isAuthDirty:t.isAuthDirty,isConfigDirty:t.isConfigDirty,authEnabled:((o=t.authSettings)==null?void 0:o.enabled)??!1,authUsername:(r=t.authSettings)==null?void 0:r.username}),e.jsx(At,{defaultsSummary:t.defaultsSummary,errors:t.errors,form:t.form,onInputChange:t.handleInputChange,onSetForm:t.setForm,sectionRef:t.setSectionRef("section-basics")}),e.jsx(Lt,{errors:t.errors,form:t.form,onSetForm:t.setForm,sectionRef:t.setSectionRef("section-protocol")}),e.jsx(Tt,{authErrors:t.authErrors,authForm:t.authForm,authLoading:t.authQuery.isPending||!t.authSettings&&t.authQuery.isFetching,authSettings:t.authSettings,needsPassword:t.needsPassword,onAuthReset:t.handleAuthReset,onAuthSave:()=>void t.handleAuthSave(),onSetAuthForm:t.setAuthForm,savingAuth:t.savingAuth,isAuthDirty:t.isAuthDirty,sectionRef:t.setSectionRef("section-security")}),e.jsx(Mt,{configPath:t.configPath,onCopyPath:()=>void t.handleCopyPath(),sectionRef:t.setSectionRef("section-config-file")}),e.jsx(Ot,{cleaning:t.cleaning,clearingAll:t.clearingAll,onOpenCleanup:()=>t.setConfirmCleanupOpen(!0),onOpenClearAll:()=>t.setConfirmClearAllOpen(!0),sectionRef:t.setSectionRef("section-cleanup")})]})]}),e.jsx(Ft,{isAuthDirty:t.isAuthDirty,isConfigDirty:t.isConfigDirty,protocolChangesPending:t.protocolChangesPending,onAuthReset:t.handleAuthReset,onAuthSave:()=>void t.handleAuthSave(),onReset:t.handleReset,onSave:()=>void t.handleSave(),saving:t.saving,savingAuth:t.savingAuth})]}):e.jsx(A,{className:"bg-card/82",children:e.jsx(L,{className:"pt-6",children:e.jsx("p",{className:"text-sm font-medium text-destructive",children:s("settings.toast.missingConfig")})})}),e.jsx(Le,{open:t.confirmCleanupOpen,onOpenChange:i=>{!i&&!t.cleaning&&t.setConfirmCleanupOpen(!1)},title:s("settings.cleanup.confirmTitle"),description:s("settings.cleanup.confirmDescription"),confirmLabel:t.cleaning?s("common.actions.cleaning"):s("common.actions.cleanup"),cancelLabel:s("common.actions.cancel"),loading:t.cleaning,onConfirm:async()=>{await t.handleCleanupLogs(),t.setConfirmCleanupOpen(!1)}}),e.jsx(Le,{open:t.confirmClearAllOpen,onOpenChange:i=>{!i&&!t.clearingAll&&t.setConfirmClearAllOpen(!1)},title:s("settings.cleanup.clearAllTitle"),description:s("settings.cleanup.clearAllWarning"),confirmLabel:t.clearingAll?s("settings.cleanup.clearingAll"):s("settings.cleanup.clearAll"),cancelLabel:s("common.actions.cancel"),loading:t.clearingAll,onConfirm:async()=>{await t.handleClearAllLogs(),t.setConfirmClearAllOpen(!1)}})]})}export{as as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as s}from"./vendor-
|
|
1
|
+
import{j as s}from"./vendor-DdPBfMMb.js";import{c as n}from"./global-D8DuA4wF.js";function e({className:a}){return s.jsx("div",{role:"status","aria-label":"Loading",className:n("animate-pulse rounded-xl bg-muted",a)})}function o(){return s.jsxs("div",{className:"space-y-3 rounded-xl bg-card/86 p-6 shadow-[var(--surface-shadow)]",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx(e,{className:"h-3 w-24"}),s.jsx(e,{className:"h-10 w-10 rounded-xl"})]}),s.jsx(e,{className:"h-8 w-32"})]})}function x(){return s.jsxs("div",{className:"space-y-4 rounded-xl bg-card/86 p-6 shadow-[var(--surface-shadow)]",children:[s.jsxs("div",{className:"space-y-2",children:[s.jsx(e,{className:"h-4 w-32"}),s.jsx(e,{className:"h-3 w-48"})]}),s.jsx(e,{className:"h-[320px] w-full rounded-xl"})]})}function m({columns:a=6}){const r=["w-24","w-16","w-20","w-28","w-14","w-12","w-20","w-16","w-14","w-12"];return s.jsx("tr",{className:"border-b",children:Array.from({length:a}).map((c,l)=>s.jsx("td",{className:"px-3 py-3",children:s.jsx(e,{className:n("h-4",r[l%r.length])})},l))})}export{x as C,o as S,m as T};
|