@chenpu17/cc-gw 0.8.0-beta.1 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/README.md +32 -2
  2. package/package.json +6 -5
  3. package/src/web/dist/assets/About-DockN9He.js +1 -0
  4. package/src/web/dist/assets/{ApiKeys-Cq26DYhq.js → ApiKeys-Fx_SaOSe.js} +1 -1
  5. package/src/web/dist/assets/{Dashboard-DPK1vZIh.js → Dashboard-De61szKh.js} +1 -1
  6. package/src/web/dist/assets/{DialogShell-DfNF-aGB.js → DialogShell-BKB8x8Yv.js} +1 -1
  7. package/src/web/dist/assets/{Events-CBybr6NR.js → Events-CmUNBQ-L.js} +1 -1
  8. package/src/web/dist/assets/{Help-B_Gv6fxg.js → Help-Bo6GcOG7.js} +1 -1
  9. package/src/web/dist/assets/{Login-b0UTBvLE.js → Login-uKKAO1uN.js} +1 -1
  10. package/src/web/dist/assets/{Logs-Cee9IbYJ.js → Logs-ChD1V5Mf.js} +1 -1
  11. package/src/web/dist/assets/{ModelManagement-ToEpbTSg.js → ModelManagement-DTlt9WMp.js} +1 -1
  12. package/src/web/dist/assets/{PageHeader-C2dWqrhL.js → PageHeader-DWkUnwoU.js} +1 -1
  13. package/src/web/dist/assets/{PageSection-Bo342pqO.js → PageSection-9-z2ysug.js} +1 -1
  14. package/src/web/dist/assets/{PageState-CwdRJgzr.js → PageState-5sxEzXut.js} +1 -1
  15. package/src/web/dist/assets/Profiler-DBeKtgDs.js +1 -0
  16. package/src/web/dist/assets/{Settings-vkbX-roP.js → Settings-YMHmPlBz.js} +1 -1
  17. package/src/web/dist/assets/{Skeleton--dmlcnAs.js → Skeleton-CvBK2w-C.js} +1 -1
  18. package/src/web/dist/assets/{badge-C0zaY90P.js → badge-tREH_88e.js} +1 -1
  19. package/src/web/dist/assets/{card-trgtgeo-.js → card-yK3LQB_K.js} +1 -1
  20. package/src/web/dist/assets/{gateway-CBqZtiXq.js → gateway-D-NOc-e6.js} +1 -1
  21. package/src/web/dist/assets/index-8bCfrPhk.css +1 -0
  22. package/src/web/dist/assets/{index-Bit1YrKY.js → index-BiTh8byX.js} +2 -2
  23. package/src/web/dist/assets/{input-qaoXek91.js → input-CXrASgDm.js} +1 -1
  24. package/src/web/dist/assets/{label-BnaA-bMD.js → label-CzHv4dNP.js} +1 -1
  25. package/src/web/dist/assets/{popover-BHvlazWa.js → popover-C-WmNbKp.js} +1 -1
  26. package/src/web/dist/assets/{select-9XUksDWE.js → select-DH6I1mKJ.js} +1 -1
  27. package/src/web/dist/assets/{switch-C6QFLGRv.js → switch-IXq8M3lq.js} +1 -1
  28. package/src/web/dist/assets/{useApiQuery-RQCL-J9v.js → useApiQuery-CCy5_Mc8.js} +1 -1
  29. package/src/web/dist/assets/{useAppMutation-hYRpzVBg.js → useAppMutation-COEUmNH4.js} +1 -1
  30. package/src/web/dist/index.html +2 -2
  31. package/src/web/dist/assets/About--y9YE6K4.js +0 -1
  32. package/src/web/dist/assets/Profiler-BL-Ksg3a.js +0 -1
  33. package/src/web/dist/assets/index-DkFxUocM.css +0 -1
@@ -1 +1 @@
1
- import{r as N,j as e,a8 as Se,as as pt,at as Ne,q as hs,a1 as xt,aj as fs,al as bs,U as vs}from"./vendor-CjJPKsTb.js";import{u as Le,C as js}from"./useAppMutation-hYRpzVBg.js";import{P as ys}from"./PageHeader-C2dWqrhL.js";import{c as oe,B as L,d as Ee,T as Ns,e as ws,f as Ms,g as ks,h as Re,b as Te,u as Cs,t as ot}from"./index-Bit1YrKY.js";import{u as te}from"./i18n-CfLThlXq.js";import{I as fe}from"./input-qaoXek91.js";import{L as J}from"./label-BnaA-bMD.js";import{S as gt,a as ht,b as ft,c as bt,d as me}from"./select-9XUksDWE.js";import{S as qe}from"./switch-C6QFLGRv.js";import{q as he}from"./queryKeys-BMvyDTQS.js";import{B as H}from"./badge-C0zaY90P.js";import{C as Fe,a as Be}from"./card-trgtgeo-.js";import{D as vt,A as jt,a as yt,b as Nt,c as wt,d as Mt,e as kt}from"./DialogShell-DfNF-aGB.js";import{P as Es,a as Ss,b as Ps}from"./popover-BHvlazWa.js";import{u as Ds,a as Rs}from"./query-D3IfCUhp.js";import{g as ye}from"./gateway-CBqZtiXq.js";import{u as Ts}from"./useApiQuery-RQCL-J9v.js";import"./router-CmaL1NgV.js";import"./radix-54BMi3RD.js";function We(){return typeof globalThis.crypto<"u"&&typeof globalThis.crypto.randomUUID=="function"?globalThis.crypto.randomUUID():Math.random().toString(36).slice(2,10)}function Os(){return{_key:We(),id:"",label:""}}const Oe={openai:{baseUrl:"https://api.openai.com/v1"},deepseek:{baseUrl:"https://api.deepseek.com/v1"},huawei:{baseUrl:"https://api.modelarts-maas.com/v1"},kimi:{baseUrl:"https://api.moonshot.cn/v1"},anthropic:{baseUrl:"https://api.anthropic.com/v1"},custom:{}},dt=[{value:"openai",label:"OpenAI"},{value:"deepseek",label:"DeepSeek"},{value:"huawei",label:"Huawei Cloud"},{value:"kimi",label:"Kimi"},{value:"anthropic",label:"Anthropic"},{value:"custom",label:"Custom"}];function lt(s){return s?{id:s.id,label:s.label??s.id,baseUrl:s.baseUrl,apiKey:s.apiKey??"",type:s.type??"custom",defaultModel:s.defaultModel??"",models:(s.models??[]).map(t=>({...t,_key:We()})),authMode:s.authMode??"apiKey"}:{id:"",label:"",baseUrl:"",apiKey:"",type:"custom",defaultModel:"",models:[],authMode:"apiKey"}}function As(s){return{_key:We(),id:s.id,label:s.label}}function Us({open:s,mode:t,provider:c,existingProviderIds:g,onClose:d,onSubmit:x}){const{t:a}=te(),[o,m]=N.useState(()=>lt(c)),[u,h]=N.useState({}),[F,k]=N.useState(!1),[M,C]=N.useState(null),v=N.useRef(null),f=N.useRef(null),b=N.useRef(null),[j,Q]=N.useState(t==="edit");N.useEffect(()=>{s&&(m(lt(c)),h({}),C(null),k(!1),Q(t==="edit"))},[s,c,t]),N.useEffect(()=>{if(!s)return;const i=E=>{E.key==="Escape"&&d()};return window.addEventListener("keydown",i),()=>window.removeEventListener("keydown",i)},[s,d]),N.useEffect(()=>{if(s){if(t==="create"&&b.current){b.current.focus();return}f.current&&f.current.focus()}},[s,t]);const Y=t==="create",ue=N.useMemo(()=>o.models.filter(i=>i.id.trim().length>0),[o.models]),le=N.useMemo(()=>{var i;return((i=dt.find(E=>E.value===o.type))==null?void 0:i.label)??"Custom"},[o.type]),Z=o.label.trim()||o.id.trim()||a("providers.drawer.summary.untitled"),V=N.useMemo(()=>[{label:a("providers.drawer.summary.type"),value:le},{label:a("providers.drawer.summary.auth"),value:o.authMode==="apiKey"?a("providers.drawer.fields.authModeApiKey"):o.authMode==="authToken"?a("providers.drawer.fields.authModeAuthToken"):a("providers.drawer.fields.authModeXAuthToken")},{label:a("providers.drawer.summary.models"),value:ue.length.toLocaleString()}],[ue.length,o.authMode,le,a]),pe=i=>E=>{m(R=>({...R,[i]:E}))},G=i=>{m(E=>{const P=!j||E.label.trim().length===0||E.label===E.id?i:E.label;return{...E,id:i,label:P}})},we=i=>{m(E=>{var de;const P=Oe[i??"custom"]??Oe.custom,B=Object.values(Oe).map(re=>re.baseUrl).filter(re=>!!re),X=!E.baseUrl||B.includes(E.baseUrl),A=t==="create"&&(E.models.length===0||E.models.every(re=>re.id.trim().length===0)),q={...E,type:i,authMode:E.authMode??"apiKey"};return P!=null&&P.baseUrl&&X&&(q.baseUrl=P.baseUrl),P!=null&&P.models&&A&&(q.models=P.models.map(As),q.defaultModel=P.defaultModel??((de=P.models[0])==null?void 0:de.id)??""),q})},be=(i,E)=>{m(R=>{const P=[...R.models];return P[i]={...P[i],...E},{...R,models:P}})},T=(i,E)=>{m(R=>{const P=[...R.models],B=P[i];if(!B)return R;const X=!j||!B.label||B.label===B.id,A={...B,id:E,label:X?E:B.label};P[i]=A;const q=R.defaultModel===B.id?E:R.defaultModel;return{...R,models:P,defaultModel:q}})},I=i=>{m(E=>{if(i<0||i>=E.models.length)return E;const R=E.models.filter((B,X)=>X!==i);let P=E.defaultModel;return R.some(B=>B.id===P)||(P=""),{...E,models:R,defaultModel:P}})},Me=()=>{m(i=>({...i,models:[...i.models,Os()]}))},se=i=>{m(E=>({...E,authMode:i}))},xe=()=>{const i={},E=o.id.trim(),R=o.baseUrl.trim();if(t==="create"&&(E.length===0?i.id=a("providers.drawer.errors.idRequired"):g.includes(E)&&(i.id=a("providers.drawer.errors.idDuplicate"))),t==="edit"&&E.length===0&&(i.id=a("providers.drawer.errors.idRequired")),R.length===0)i.baseUrl=a("providers.drawer.errors.baseUrlInvalid");else try{new URL(R)}catch{i.baseUrl=a("providers.drawer.errors.baseUrlInvalid")}if(o.models.length>0){const P=new Set;o.models.some(X=>{const A=X.id.trim();return A.length===0||P.has(A)?!0:(P.add(A),!1)})&&(i.models=a("providers.drawer.errors.modelInvalid"))}return o.defaultModel&&!o.models.some(P=>P.id===o.defaultModel)&&(i.models=a("providers.drawer.errors.defaultInvalid")),h(i),Object.keys(i).length===0},ie=()=>{const i=o.models.map(P=>{var B;return{id:P.id.trim(),label:(B=P.label)!=null&&B.trim()?P.label.trim():void 0}}).filter(P=>P.id.length>0),E=c!=null&&c.extraHeaders&&Object.keys(c.extraHeaders).length>0?c.extraHeaders:void 0,R=o.authMode!=="apiKey"?o.authMode:void 0;return{id:o.id.trim(),label:o.label.trim()||o.id.trim(),baseUrl:o.baseUrl.trim(),apiKey:o.apiKey.trim()||void 0,type:o.type??"custom",defaultModel:o.defaultModel||void 0,models:i.length>0?i:void 0,extraHeaders:E,authMode:R}},ge=async()=>{if(C(null),!!xe()){k(!0);try{const i=ie();await x(i)}catch(i){C(a("providers.drawer.toast.saveFailure",{message:i instanceof Error?i.message:"unknown"})),k(!1);return}k(!1),d()}};return s?e.jsxs("div",{className:"fixed inset-0 z-50 flex",children:[e.jsx("div",{className:"flex-1 bg-background/80 backdrop-blur-sm",onClick:d,"aria-hidden":"true"}),e.jsxs("aside",{ref:v,role:"dialog","aria-modal":"true","aria-labelledby":"provider-drawer-title","aria-describedby":"provider-drawer-desc",className:"flex h-full w-full max-w-5xl flex-col border-l border-border bg-background shadow-lg",children:[e.jsxs("header",{className:"border-b border-border bg-secondary px-6 py-5",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"inline-flex rounded-full border border-primary/20 bg-primary/10 px-3 py-1 text-[11px] font-medium uppercase tracking-[0.18em] text-primary",children:a(Y?"providers.drawer.quickStart":"providers.drawer.editTitle")}),e.jsxs("div",{children:[e.jsx("h2",{id:"provider-drawer-title",className:"text-lg font-semibold tracking-[-0.02em]",children:a(Y?"providers.drawer.createTitle":"providers.drawer.editTitle")}),e.jsx("p",{id:"provider-drawer-desc",className:"text-sm text-muted-foreground",children:a("providers.drawer.description")})]})]}),e.jsx("button",{type:"button",ref:f,onClick:d,className:"rounded-full border border-border bg-card px-4 py-2 text-sm transition hover:border-primary/20 hover:bg-accent/50",children:a("common.actions.close")})]}),e.jsx("div",{className:"mt-4 grid gap-3 md:grid-cols-3",children:V.map(i=>e.jsxs("div",{className:"rounded-lg border border-border bg-card px-4 py-3",children:[e.jsx("p",{className:"text-[11px] font-medium uppercase tracking-[0.16em] text-muted-foreground",children:i.label}),e.jsx("p",{className:"mt-2 text-sm font-semibold text-foreground",children:i.value})]},i.label))})]}),e.jsxs("div",{className:"grid flex-1 overflow-hidden xl:grid-cols-[minmax(0,1fr)_280px]",children:[e.jsxs("div",{className:"overflow-y-auto px-6 py-5",children:[e.jsxs("section",{className:"space-y-5","aria-labelledby":"provider-type-fields",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("h3",{id:"provider-type-fields",className:"text-sm font-semibold",children:a("providers.drawer.sections.type")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a("providers.drawer.hints.type")})]}),e.jsx("div",{className:"grid gap-2 md:grid-cols-3",children:dt.map(i=>{var R;const E=i.value===o.type;return e.jsxs("button",{type:"button",onClick:()=>we(i.value),className:oe("rounded-2xl border px-4 py-3 text-left transition",E?"border-primary bg-primary/10 text-primary shadow-sm":"border-border bg-card text-foreground hover:border-primary/20 hover:bg-accent/50"),children:[e.jsx("div",{className:"text-sm font-semibold",children:i.label}),e.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:((R=Oe[i.value??"custom"])==null?void 0:R.baseUrl)??a("providers.drawer.hints.customProvider")})]},i.value??"custom")})})]}),e.jsxs("section",{className:"mt-8 space-y-4","aria-labelledby":"provider-basic-info",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("h3",{id:"provider-basic-info",className:"text-sm font-semibold",children:a("providers.drawer.sections.basic")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a("providers.drawer.hints.basic")})]}),e.jsx("button",{type:"button",onClick:()=>Q(i=>!i),className:"rounded-full border border-border bg-card px-3 py-1.5 text-xs transition hover:border-primary/20 hover:bg-accent/50",children:a(j?"providers.drawer.fields.hideAdvanced":"providers.drawer.fields.showAdvanced")})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs("label",{className:"flex flex-col gap-2 text-sm",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:a("providers.drawer.fields.id")}),e.jsx("input",{value:o.id,ref:b,onChange:i=>G(i.target.value),disabled:!Y,placeholder:a("providers.drawer.fields.idPlaceholder"),className:"h-10 rounded-md border border-input bg-background px-3 py-2 text-sm transition-all focus:border-primary/40 focus:outline-none focus:ring-2 focus:ring-ring disabled:bg-muted/60 disabled:text-muted-foreground","aria-invalid":!!u.id}),u.id?e.jsx("span",{className:"text-xs text-red-500",children:u.id}):null]}),e.jsxs("label",{className:"flex flex-col gap-2 text-sm",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:a("providers.drawer.fields.label")}),e.jsx("input",{value:o.label,onChange:i=>pe("label")(i.target.value),placeholder:a("providers.drawer.fields.labelPlaceholder"),className:"h-10 rounded-md border border-input bg-background px-3 py-2 text-sm transition-all focus:border-primary/40 focus:outline-none focus:ring-2 focus:ring-ring disabled:bg-muted/60 disabled:text-muted-foreground"})]})]}),e.jsxs("label",{className:"flex flex-col gap-2 text-sm",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:a("providers.drawer.fields.baseUrl")}),e.jsx("input",{value:o.baseUrl,onChange:i=>pe("baseUrl")(i.target.value),placeholder:a("providers.drawer.fields.baseUrlPlaceholder"),className:"h-10 rounded-md border border-input bg-background px-3 py-2 text-sm transition-all focus:border-primary/40 focus:outline-none focus:ring-2 focus:ring-ring disabled:bg-muted/60 disabled:text-muted-foreground","aria-invalid":!!u.baseUrl}),u.baseUrl?e.jsx("span",{className:"text-xs text-red-500",children:u.baseUrl}):null]})]}),e.jsxs("section",{className:"mt-8 space-y-4","aria-labelledby":"provider-auth-fields",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("h3",{id:"provider-auth-fields",className:"text-sm font-semibold",children:a("providers.drawer.sections.auth")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a("providers.drawer.hints.auth")})]}),e.jsxs("label",{className:"flex flex-col gap-2 text-sm",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:a("providers.drawer.fields.apiKey")}),e.jsx("input",{value:o.apiKey,onChange:i=>pe("apiKey")(i.target.value),placeholder:a("providers.drawer.fields.apiKeyPlaceholder"),className:"h-10 rounded-md border border-input bg-background px-3 py-2 text-sm transition-all focus:border-primary/40 focus:outline-none focus:ring-2 focus:ring-ring disabled:bg-muted/60 disabled:text-muted-foreground"})]}),e.jsxs("fieldset",{className:"grid gap-2 rounded-lg border border-border bg-card p-4 text-xs",children:[e.jsx("legend",{className:"px-1 text-muted-foreground",children:a("providers.drawer.fields.authMode")}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:a("providers.drawer.fields.authModeHint")}),e.jsxs("label",{className:"flex cursor-pointer items-start gap-3 rounded-xl border border-transparent px-3 py-2 transition hover:bg-primary/5",children:[e.jsx("input",{type:"radio",name:"provider-auth-mode",value:"apiKey",checked:o.authMode==="apiKey",onChange:()=>se("apiKey"),className:"mt-0.5"}),e.jsx("span",{children:a("providers.drawer.fields.authModeApiKey")})]}),e.jsxs("label",{className:"flex cursor-pointer items-start gap-3 rounded-xl border border-transparent px-3 py-2 transition hover:bg-primary/5",children:[e.jsx("input",{type:"radio",name:"provider-auth-mode",value:"authToken",checked:o.authMode==="authToken",onChange:()=>se("authToken"),className:"mt-0.5"}),e.jsx("span",{children:a("providers.drawer.fields.authModeAuthToken")})]}),e.jsxs("label",{className:"flex cursor-pointer items-start gap-3 rounded-xl border border-transparent px-3 py-2 transition hover:bg-primary/5",children:[e.jsx("input",{type:"radio",name:"provider-auth-mode",value:"xAuthToken",checked:o.authMode==="xAuthToken",onChange:()=>se("xAuthToken"),className:"mt-0.5"}),e.jsx("span",{children:a("providers.drawer.fields.authModeXAuthToken")})]})]})]}),e.jsxs("section",{className:"mt-8 space-y-4","aria-labelledby":"provider-model-fields",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("h3",{id:"provider-model-fields",className:"text-sm font-semibold",children:a("providers.drawer.fields.models")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a("providers.drawer.modelsDescription")})]}),e.jsx("button",{type:"button",onClick:Me,className:"rounded-full border border-border bg-card px-3 py-1.5 text-xs transition hover:border-primary/20 hover:bg-accent/50",children:a("providers.drawer.fields.addModel")})]}),u.models?e.jsx("p",{className:"text-xs text-red-500",children:u.models}):null,e.jsxs("div",{className:"space-y-4",children:[o.models.map((i,E)=>e.jsxs("div",{className:"rounded-lg border border-border bg-card p-4",children:[e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs("label",{className:"flex flex-col gap-2 text-sm",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:a("providers.drawer.fields.modelId")}),e.jsx("input",{value:i.id,onChange:R=>T(E,R.target.value),placeholder:a("providers.drawer.fields.modelIdPlaceholder"),className:"h-10 rounded-md border border-input bg-background px-3 py-2 text-sm transition-all focus:border-primary/40 focus:outline-none focus:ring-2 focus:ring-ring disabled:bg-muted/60 disabled:text-muted-foreground"})]}),j?e.jsxs("label",{className:"flex flex-col gap-2 text-sm",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:a("providers.drawer.fields.modelLabel")}),e.jsx("input",{value:i.label??"",onChange:R=>be(E,{label:R.target.value}),placeholder:a("providers.drawer.fields.modelLabelPlaceholder"),className:"h-10 rounded-md border border-input bg-background px-3 py-2 text-sm transition-all focus:border-primary/40 focus:outline-none focus:ring-2 focus:ring-ring disabled:bg-muted/60 disabled:text-muted-foreground"})]}):null]}),e.jsxs("div",{className:"mt-3 flex flex-wrap items-center justify-between gap-3 text-xs",children:[e.jsxs("label",{className:"flex items-center gap-2 text-muted-foreground",children:[e.jsx("input",{type:"radio",name:"defaultModel",value:i.id,checked:o.defaultModel===i.id,onChange:()=>m(R=>({...R,defaultModel:i.id})),disabled:i.id.trim().length===0}),a("providers.drawer.fields.setDefault")]}),e.jsx("button",{type:"button",className:"text-red-500 transition hover:text-red-600 disabled:cursor-not-allowed disabled:opacity-40",onClick:()=>I(E),disabled:o.models.length===0,children:a("providers.drawer.fields.removeModel")})]})]},i._key)),o.models.length===0?e.jsx("div",{className:"rounded-lg border border-amber-200 bg-amber-50/60 p-5 dark:border-amber-700/50 dark:bg-amber-900/20",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm font-semibold text-amber-900 dark:text-amber-200",children:a("providers.drawer.noModelsTitle")}),e.jsx("p",{className:"text-xs leading-relaxed text-amber-800 dark:text-amber-300",children:a("providers.drawer.noModelsHint",{providerId:o.id||"provider-id"})}),e.jsxs("div",{className:"rounded-md border border-border bg-secondary p-2.5",children:[e.jsx("p",{className:"mb-1.5 text-xs font-medium text-foreground",children:a("providers.drawer.routeExample")}),e.jsxs("code",{className:"block rounded-md border border-border bg-card px-2.5 py-1.5 font-mono text-xs text-foreground",children:['"claude-*": "',(o.id||"provider-id").trim()||"provider-id",':*"']})]})]})}):null]}),ue.length>1?e.jsx("div",{className:"text-xs text-muted-foreground",children:a("providers.drawer.defaultHint",{model:o.defaultModel||a("providers.card.noDefault")})}):null]})]}),e.jsx("aside",{className:"hidden border-l border-border bg-secondary px-5 py-5 xl:block",children:e.jsxs("div",{className:"sticky top-0 space-y-5",children:[e.jsxs("div",{className:"rounded-lg border border-border bg-card p-4",children:[e.jsx("p",{className:"text-[11px] font-medium uppercase tracking-[0.16em] text-muted-foreground",children:a("providers.drawer.formSummary")}),e.jsx("p",{className:"mt-2 text-base font-semibold",children:Z}),e.jsx("div",{className:"mt-4 space-y-3 text-sm",children:V.map(i=>e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsx("span",{className:"text-muted-foreground",children:i.label}),e.jsx("span",{className:"text-right font-medium",children:i.value})]},i.label))})]}),e.jsxs("div",{className:"rounded-lg border border-border bg-card p-4",children:[e.jsx("p",{className:"text-[11px] font-medium uppercase tracking-[0.16em] text-muted-foreground",children:a("providers.drawer.sections.checklist")}),e.jsxs("ul",{className:"mt-3 space-y-2 text-sm text-muted-foreground",children:[e.jsx("li",{children:a("providers.drawer.hints.checkUrl")}),e.jsx("li",{children:a("providers.drawer.hints.checkAuth")}),e.jsx("li",{children:a("providers.drawer.hints.checkModels")})]})]}),j&&e.jsxs("div",{className:"rounded-lg border border-primary/20 bg-accent p-4 text-sm text-foreground",children:[e.jsx("p",{className:"font-medium text-primary",children:a("providers.drawer.hints.advancedTitle")}),e.jsx("p",{className:"mt-2 text-xs text-muted-foreground",children:a("providers.drawer.hints.advancedBody")})]})]})})]}),e.jsxs("footer",{className:"flex items-center justify-between gap-3 border-t border-border bg-secondary px-6 py-4 text-sm",children:[e.jsx("div",{className:"flex flex-col text-xs text-red-500","aria-live":"polite",children:M?e.jsx("span",{children:M}):null}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{type:"button",onClick:d,className:"rounded-full border border-border bg-card px-4 py-2 transition hover:border-primary/20 hover:bg-accent/50",disabled:F,children:a("common.actions.cancel")}),e.jsx("button",{type:"button",onClick:ge,className:"rounded-full bg-primary px-5 py-2 text-primary-foreground shadow-[0_8px_20px_-12px_rgba(59,130,246,0.65)] transition hover:-translate-y-0.5 hover:bg-primary/95 disabled:opacity-60",disabled:F,children:a(F?"common.actions.saving":"common.actions.save")})]})]})]})]}):null}const $s=["anthropic","openai-auto","openai-chat","openai-responses"];function Ls({open:s,endpoint:t,onClose:c,onSuccess:g}){const{t:d}=te(),[x,a]=N.useState({id:"",label:"",paths:[{path:"",protocol:"openai-auto"}],enabled:!0});N.useEffect(()=>{if(t){const v=t.paths&&t.paths.length>0?t.paths:t.path&&t.protocol?[{path:t.path,protocol:t.protocol}]:[{path:"",protocol:"openai-auto"}];a({id:t.id,label:t.label,paths:v,enabled:t.enabled!==!1});return}a({id:"",label:"",paths:[{path:"",protocol:"openai-auto"}],enabled:!0})},[t,s]);const o=Le({mutationFn:Ee.create,invalidateKeys:[he.customEndpoints.all()],successToast:()=>({title:d("modelManagement.createEndpointSuccess")}),errorToast:v=>({title:d("modelManagement.createEndpointError",{error:v.message})}),onSuccess:async()=>{g(),c()}}),m=Le({mutationFn:v=>Ee.update(v.id,v.updates),invalidateKeys:[he.customEndpoints.all()],successToast:()=>({title:d("modelManagement.updateEndpointSuccess")}),errorToast:v=>({title:d("modelManagement.updateEndpointError",{error:v.message})}),onSuccess:async()=>{g(),c()}}),u=()=>{a(v=>({...v,paths:[...v.paths,{path:"",protocol:"anthropic"}]}))},h=v=>{x.paths.length!==1&&a(f=>({...f,paths:f.paths.filter((b,j)=>j!==v)}))},F=(v,f,b)=>{a(j=>{const Q=[...j.paths];return Q[v]={...Q[v],[f]:b},{...j,paths:Q}})},k=v=>{if(v==null||v.preventDefault(),!x.id.trim()||!x.label.trim())return;for(const b of x.paths)if(!b.path.trim())return;const f=x.paths.map(b=>({path:b.path.trim(),protocol:b.protocol}));if(t){m.mutate({id:t.id,updates:{label:x.label.trim(),paths:f,enabled:x.enabled}});return}o.mutate({id:x.id.trim(),label:x.label.trim(),paths:f,enabled:x.enabled})},M=o.isPending||m.isPending,C=x.paths.length===0?d("modelManagement.atLeastOnePath"):!x.id.trim()||!x.label.trim()?d("modelManagement.endpointValidationError"):x.paths.some(v=>!v.path.trim())?d("modelManagement.pathValidationError"):null;return s?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-40 bg-background/80 backdrop-blur-sm",onClick:c}),e.jsx("div",{className:"fixed inset-y-0 right-0 z-50 w-full max-w-md border-l border-border bg-background shadow-lg",children:e.jsxs("div",{className:"flex h-full flex-col",children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-border bg-secondary p-6",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("h2",{className:"text-lg font-semibold tracking-[-0.02em]",children:d(t?"modelManagement.editEndpoint":"modelManagement.createEndpoint")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t?t.id:d("modelManagement.endpointRoutingHint")})]}),e.jsx(L,{variant:"ghost",size:"sm",onClick:c,children:e.jsx(Se,{className:"h-4 w-4"})})]}),e.jsxs("form",{onSubmit:k,className:"flex-1 space-y-6 overflow-y-auto p-6",children:[e.jsxs("div",{className:"grid gap-3 rounded-lg border border-border bg-secondary 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:d("modelManagement.endpointId")}),e.jsx("p",{className:"truncate text-sm font-medium text-foreground",children:(t==null?void 0:t.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:d("modelManagement.endpointEnabled")}),e.jsx("p",{className:"text-sm font-medium text-foreground",children:x.enabled?d("common.status.enabled"):d("common.status.disabled")})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(J,{children:[d("modelManagement.endpointId")," ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(fe,{value:x.id,onChange:v=>a(f=>({...f,id:v.target.value})),placeholder:d("modelManagement.endpointIdPlaceholder"),disabled:!!t,required:!0}),e.jsx("p",{className:"text-xs text-muted-foreground",children:d("modelManagement.endpointIdHint")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(J,{children:[d("modelManagement.endpointLabel")," ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(fe,{value:x.label,onChange:v=>a(f=>({...f,label:v.target.value})),placeholder:d("modelManagement.endpointLabelPlaceholder"),required:!0})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(J,{children:[d("modelManagement.endpointPaths")," ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsxs(L,{type:"button",variant:"ghost",size:"sm",onClick:u,children:[e.jsx(pt,{className:"mr-1 h-3 w-3"}),d("modelManagement.addPath")]})]}),e.jsx("div",{className:"space-y-3",children:x.paths.map((v,f)=>e.jsxs("div",{className:"space-y-2 rounded-lg border border-border bg-card p-3",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(fe,{value:v.path,onChange:b=>F(f,"path",b.target.value),placeholder:d("modelManagement.endpointPathPlaceholder"),required:!0}),e.jsxs(gt,{value:v.protocol,onValueChange:b=>F(f,"protocol",b),children:[e.jsx(ht,{children:e.jsx(ft,{})}),e.jsx(bt,{children:$s.map(b=>e.jsx(me,{value:b,children:d(b==="anthropic"?"modelManagement.protocolAnthropic":b==="openai-auto"?"modelManagement.protocolOpenAI":b==="openai-chat"?"modelManagement.protocolOpenAIChat":"modelManagement.protocolOpenAIResponses")},b))})]})]}),x.paths.length>1?e.jsx(L,{type:"button",variant:"ghost",size:"sm",onClick:()=>h(f),className:"text-destructive",children:e.jsx(Se,{className:"h-4 w-4"})}):null]}),e.jsxs("div",{className:"space-y-1 text-xs text-muted-foreground",children:[f===0?e.jsx("p",{children:d("modelManagement.endpointPathHint")}):null,e.jsx("p",{children:d(`modelManagement.protocolHints.${v.protocol}`)})]})]},`${v.protocol}-${f}`))}),C?e.jsx("p",{className:"text-xs text-destructive",children:C}):null]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(qe,{id:"enabled",checked:x.enabled,onCheckedChange:v=>a(f=>({...f,enabled:v}))}),e.jsx(J,{htmlFor:"enabled",children:d("modelManagement.endpointEnabled")})]}),t?null:e.jsx("div",{className:"rounded-lg border border-primary/20 bg-accent p-4",children:e.jsx("p",{className:"text-sm text-blue-800 dark:text-blue-200",children:d("modelManagement.endpointRoutingHint")})})]}),e.jsxs("div",{className:"flex gap-3 border-t border-border bg-secondary p-6",children:[e.jsx(L,{variant:"outline",className:"flex-1",onClick:c,disabled:M,children:d("common.cancel")}),e.jsx(L,{className:"flex-1",onClick:()=>k(),disabled:M,children:d(M?"common.saving":t?"common.save":"common.create")})]})]})})]}):null}function Ke(s,t){return t(s==="anthropic"?"modelManagement.protocolAnthropic":s==="openai-chat"?"modelManagement.protocolOpenAIChat":s==="openai-responses"?"modelManagement.protocolOpenAIResponses":"modelManagement.protocolOpenAI")}function Fs({activeTab:s,activeTabInfo:t,customEndpoints:c,customTabs:g,isDirtyByEndpoint:d,onDeleteEndpoint:x,onEditEndpoint:a,onSelectTab:o,providerCount:m,systemTabs:u}){const{t:h}=te(),F=Object.values(d).filter(Boolean).length,k=u.length-1+g.length;return e.jsx(Fe,{className:"overflow-hidden",children:e.jsxs(Be,{className:"space-y-5 pt-5",children:[e.jsxs("div",{className:"flex flex-col gap-3 lg:flex-row lg:items-end lg:justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs(H,{variant:"outline",className:"border-primary/20 bg-accent text-primary",children:[h("modelManagement.tabs.providers")," · ",m]}),e.jsxs(H,{variant:"outline",children:[h("modelManagement.tabs.customEndpoint")," · ",g.length]}),F>0?e.jsx(H,{variant:"warning",children:h("modelManagement.overview.unsavedCount",{count:F})}):e.jsx(H,{variant:"success",children:h("modelManagement.overview.synced")})]}),e.jsx("p",{className:"text-sm font-semibold text-foreground",children:t==null?void 0:t.label}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t==null?void 0:t.description})]}),e.jsxs("div",{className:"flex w-full flex-col gap-3 sm:w-auto sm:flex-row sm:flex-wrap sm:items-center",children:[e.jsx("div",{className:"rounded-lg border border-border bg-secondary px-3 py-2 text-xs text-muted-foreground",children:g.length>0?h("modelManagement.overview.headerWithCustom"):h("modelManagement.overview.headerWithoutCustom")}),e.jsxs("div",{className:"rounded-lg border border-primary/20 bg-accent px-3 py-2 text-xs font-medium text-primary",children:[h("modelManagement.overview.routeWorkspacesStat")," · ",k]})]})]}),e.jsxs("div",{className:"grid gap-3 md:grid-cols-4",children:[e.jsx(Ae,{label:h("modelManagement.overview.providersStat"),value:m.toString(),helper:h("modelManagement.overview.providersStatHint")}),e.jsx(Ae,{label:h("modelManagement.overview.routeWorkspacesStat"),value:k.toString(),helper:h("modelManagement.overview.routeWorkspacesStatHint")}),e.jsx(Ae,{label:h("modelManagement.overview.customEndpointsStat"),value:g.length.toString(),helper:h("modelManagement.overview.customEndpointsStatHint")}),e.jsx(Ae,{label:h("modelManagement.overview.activeWorkspace"),value:(t==null?void 0:t.label)??"-",helper:h(s==="providers"?"modelManagement.overview.activeWorkspaceProvider":"modelManagement.overview.activeWorkspaceRouting")})]}),e.jsxs("div",{className:"grid gap-3 rounded-lg border border-border bg-secondary p-4 md:grid-cols-2",children:[e.jsx(it,{title:h("modelManagement.overview.resourceCardTitle"),description:h("modelManagement.overview.resourceCardDescription")}),e.jsx(it,{title:h("modelManagement.overview.entryCardTitle"),description:h("modelManagement.overview.entryCardDescription")})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsx("p",{className:"text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:h("modelManagement.overview.providerAndSystem")})}),e.jsx("div",{className:"grid gap-3 md:grid-cols-3",children:u.map(M=>{const C=s===M.key,v=M.key!=="providers"&&d[M.key];return e.jsxs("button",{type:"button",onClick:()=>o(M.key),className:oe("group flex min-h-[96px] flex-col justify-between rounded-lg border px-4 py-4 text-left transition-all",C?"border-primary/30 bg-accent":"border-border bg-card hover:border-primary/20 hover:bg-accent/50"),children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx("span",{className:oe("text-base font-semibold",C?"text-primary":"text-foreground"),children:M.label}),e.jsx("div",{className:"text-[11px] uppercase tracking-wider text-muted-foreground",children:M.key==="providers"?h("modelManagement.overview.providerPoolTag"):h("modelManagement.overview.systemEndpointTag")})]}),v?e.jsx("span",{className:"mt-1 h-2.5 w-2.5 rounded-full bg-amber-500"}):null]}),e.jsx("span",{className:"line-clamp-2 text-sm text-muted-foreground",children:M.description})]},M.key)})})]}),g.length>0?e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"flex items-center justify-between gap-3",children:e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:h("modelManagement.overview.customEndpoints")}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:h("modelManagement.overview.customEndpointsHint")})]})}),e.jsx("div",{className:"overflow-x-auto pb-1",children:e.jsx("div",{className:"flex min-w-full snap-x gap-3",children:g.map(M=>{var b;const C=s===M.key,v=d[M.key],f=c.find(j=>j.id===M.key);return e.jsxs("div",{className:oe("group relative flex w-[260px] shrink-0 snap-start flex-col gap-3 rounded-lg border px-4 py-4 text-left transition-all",C?"border-primary/30 bg-accent":"border-border bg-card hover:border-primary/20 hover:bg-accent/50"),children:[e.jsxs("button",{type:"button",onClick:()=>o(M.key),className:"min-w-0 flex-1 text-left",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:oe("truncate text-base font-semibold",C?"text-primary":"text-foreground"),children:M.label}),v?e.jsx("span",{className:"h-2 w-2 rounded-full bg-amber-500"}):null]}),e.jsx("p",{className:"mt-1 line-clamp-2 text-sm text-muted-foreground",children:M.description})]}),e.jsxs("div",{className:"grid gap-2 sm:flex sm:items-start",children:[e.jsx(L,{variant:"ghost",size:"sm",className:"h-7 w-full px-2 text-xs sm:w-auto",disabled:!f,onClick:()=>{f&&a(f)},children:h("common.edit")}),M.canDelete?e.jsx("button",{type:"button",onClick:j=>{j.stopPropagation(),f&&x({kind:"endpoint",endpoint:f})},className:"flex h-7 w-full items-center justify-center rounded-full border border-transparent text-muted-foreground transition hover:border-destructive/20 hover:bg-destructive/10 hover:text-destructive sm:w-7",title:h("common.delete"),children:e.jsx(Se,{className:"h-3.5 w-3.5"})}):null]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[(M.protocols??[]).map(j=>e.jsx(H,{variant:"outline",className:"max-w-full truncate text-[11px]",children:Ke(j,h)},`${M.key}-${j}`)),e.jsx(H,{variant:(f==null?void 0:f.enabled)===!1?"secondary":"success",className:"text-[11px]",children:(f==null?void 0:f.enabled)===!1?h("modelManagement.overview.endpointDisabled"):h("modelManagement.overview.endpointEnabled")})]}),f!=null&&f.paths&&f.paths.length>0?e.jsxs("div",{className:"space-y-1 rounded-lg border border-border bg-secondary px-3 py-2 text-[11px] text-muted-foreground",children:[f.paths.slice(0,2).map(j=>e.jsxs("div",{className:"truncate",children:[e.jsx("span",{className:"font-medium text-foreground",children:j.path})," · ",Ke(j.protocol,h)]},`${f.id}-${j.path}-${j.protocol}`)),f.paths.length>2?e.jsx("div",{children:h("modelManagement.overview.endpointMorePaths",{count:f.paths.length-2})}):null]}):f!=null&&f.path?e.jsxs("div",{className:"rounded-lg border border-border bg-secondary px-3 py-2 text-[11px] text-muted-foreground",children:[e.jsx("span",{className:"font-medium text-foreground",children:f.path})," · ",Ke(f.protocol??"anthropic",h)]}):null,e.jsx("div",{className:"rounded-lg border border-border bg-secondary px-3 py-2 text-[11px] text-muted-foreground",children:(b=M.protocols)!=null&&b.length?h("modelManagement.overview.endpointProtocols",{count:M.protocols.length}):h("modelManagement.overview.endpointNoProtocol")}),M.canDelete?null:e.jsx("div",{className:"text-[11px] text-muted-foreground",children:h("modelManagement.overview.endpointManagedExternally")})]},M.key)})})})]}):null]})})}function it({description:s,title:t}){return e.jsxs("div",{className:"rounded-lg border border-border bg-card px-4 py-3",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-wider text-muted-foreground",children:t}),e.jsx("p",{className:"mt-2 text-sm leading-6 text-foreground",children:s})]})}function Ae({helper:s,label:t,value:c}){return e.jsxs("div",{className:"rounded-lg border border-border bg-card px-4 py-3",children:[e.jsx("p",{className:"text-[11px] font-medium uppercase tracking-wider text-muted-foreground",children:t}),e.jsx("p",{className:"mt-2 truncate text-base font-semibold text-foreground",children:c}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:s})]})}function Bs({dialog:s,currentRoutes:t,onConfirm:c,onClose:g}){const{t:d}=te();if(!s)return null;const{endpoint:x,preset:a}=s,o=a.modelRoutes??{},m={};for(const C of t){const v=C.source.trim(),f=C.target.trim();v&&f&&(m[v]=f)}const u=new Set([...Object.keys(m),...Object.keys(o)]),h=[],F=[],k=[];for(const C of u){const v=C in m,f=C in o;f&&!v?h.push([C,o[C]]):v&&!f?F.push([C,m[C]]):v&&f&&m[C]!==o[C]&&k.push([C,m[C],o[C]])}const M=h.length>0||F.length>0||k.length>0;return e.jsx(vt,{open:!0,onOpenChange:C=>!C&&g(),children:e.jsxs(jt,{className:"max-w-2xl",children:[e.jsxs(yt,{children:[e.jsx(Nt,{children:d("modelManagement.presets.diffTitle")}),e.jsx(wt,{children:d("modelManagement.presets.diffDescription",{name:a.name})})]}),e.jsx(Mt,{children:M?e.jsxs("div",{className:"max-h-80 space-y-2 rounded-lg border border-border bg-secondary p-3 text-sm",children:[h.map(([C,v])=>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(H,{variant:"outline",className:"border-emerald-300 text-xs dark:border-emerald-700",children:d("modelManagement.presets.diffAdded")}),e.jsx("span",{className:"truncate",children:C}),e.jsx(Ne,{className:"h-3 w-3 flex-shrink-0"}),e.jsx("span",{className:"truncate",children:v})]},`add-${C}`)),F.map(([C,v])=>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(H,{variant:"outline",className:"border-red-300 text-xs dark:border-red-700",children:d("modelManagement.presets.diffRemoved")}),e.jsx("span",{className:"truncate",children:C}),e.jsx(Ne,{className:"h-3 w-3 flex-shrink-0"}),e.jsx("span",{className:"truncate",children:v})]},`rm-${C}`)),k.map(([C,v,f])=>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(H,{variant:"outline",className:"border-amber-300 text-xs dark:border-amber-700",children:d("modelManagement.presets.diffChanged")}),e.jsx("span",{className:"truncate",children:C}),e.jsx(Ne,{className:"h-3 w-3 flex-shrink-0"}),e.jsx("span",{className:"truncate line-through opacity-60",children:v}),e.jsx(Ne,{className:"h-3 w-3 flex-shrink-0"}),e.jsx("span",{className:"truncate",children:f})]},`chg-${C}`))]}):e.jsx("p",{className:"rounded-lg border border-border bg-secondary py-8 text-center text-sm text-muted-foreground",children:d("modelManagement.presets.diffEmpty")})}),e.jsxs(kt,{children:[e.jsx(L,{variant:"outline",onClick:g,children:d("common.cancel")}),e.jsx(L,{onClick:()=>c(x,a),disabled:!M,children:d("modelManagement.presets.diffConfirm")})]})]})})}function Ct({eyebrow:s,title:t,description:c,breadcrumb:g,aside:d}){return e.jsxs("div",{className:"flex flex-col gap-4 lg:flex-row lg:items-start lg:justify-between",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-[11px] font-semibold uppercase tracking-[0.18em] text-muted-foreground",children:[e.jsx("span",{children:s}),g.map((x,a)=>e.jsxs(hs.Fragment,{children:[a>0?e.jsx(xt,{className:"h-3.5 w-3.5"}):null,e.jsx("span",{className:oe(a===g.length-1&&"text-foreground"),children:x})]},`${x}-${a}`))]}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-semibold tracking-[-0.03em] text-foreground",children:t}),e.jsx("p",{className:"mt-1 max-w-3xl text-sm text-muted-foreground",children:c})]})]}),d?e.jsx("div",{className:"w-full shrink-0 lg:w-auto",children:d}):null]})}const Hs=["claude-sonnet-4-5-20250929","claude-sonnet-4-5-20250929-thinking","claude-sonnet-4-20250514","claude-opus-4-1-20250805","claude-opus-4-1-20250805-thinking","claude-haiku-4-5-20251001","claude-haiku-4-5-20251001-thinking","claude-3-5-haiku-20241022"],Is=["gpt-4o-mini","gpt-4o","o4-mini","o4-large","gpt-5-codex"];function ne(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():Math.random().toString(36).slice(2,10)}function Qe(s,t){var c;return(c=s==null?void 0:s.customEndpoints)!=null&&c.length?s.customEndpoints:t}function ze(s){return s?Object.entries(s).map(([t,c])=>({id:ne(),source:t,target:c})):[]}function Ve(s,t){var d,x,a;if(!s)return{};const c={},g=s.endpointRouting??{};c.anthropic=ze(((d=g.anthropic)==null?void 0:d.modelRoutes)??s.modelRoutes??{}),c.openai=ze(((x=g.openai)==null?void 0:x.modelRoutes)??{});for(const o of Qe(s,t))(a=o.routing)!=null&&a.modelRoutes?c[o.id]=ze(o.routing.modelRoutes):c[o.id]=[];return c}function ct(s,t,c){var x,a,o;const g=Qe(s,t).find(m=>m.id===c);if(g)return((x=g.routing)==null?void 0:x.modelRoutes)??{};const d=s.endpointRouting??{};return c==="anthropic"?((a=d.anthropic)==null?void 0:a.modelRoutes)??s.modelRoutes??{}:c==="openai"?((o=d.openai)==null?void 0:o.modelRoutes)??{}:{}}function Ks(s){const t={};for(const c of s){const g=c.source.trim(),d=c.target.trim();g&&d&&(t[g]=d)}return t}function mt(s,t){return JSON.stringify(Ks(s))!==JSON.stringify(t)}function zs(s,t){if(s==="anthropic")return!0;const c=t.find(g=>g.id===s);return c?c.paths&&c.paths.length>0?c.paths.some(g=>g.protocol==="anthropic"):c.protocol==="anthropic":!1}function Vs(s,t,c){var d,x,a;if(!t)return;if(s==="anthropic"||s==="openai")return(x=(d=t.endpointRouting)==null?void 0:d[s])==null?void 0:x.validation;const g=Qe(t,c).find(o=>o.id===s);return(a=g==null?void 0:g.routing)==null?void 0:a.validation}function _s(s,t){const c=[{key:"providers",label:s("modelManagement.tabs.providers"),description:s("modelManagement.tabs.providersDesc"),isSystem:!0,canDelete:!1},{key:"anthropic",label:s("modelManagement.tabs.anthropic"),description:s("modelManagement.tabs.anthropicDesc"),isSystem:!0,canDelete:!1,protocols:["anthropic"]},{key:"openai",label:s("modelManagement.tabs.openai"),description:s("modelManagement.tabs.openaiDesc"),isSystem:!0,canDelete:!1,protocols:["openai-auto","openai-chat","openai-responses"]}],g=t.map(d=>{let x=s("modelManagement.tabs.customEndpoint"),a=[];if(d.paths&&d.paths.length>0)x=`${s("modelManagement.tabs.customEndpoint")}: ${d.paths.map(o=>`${o.path} (${o.protocol})`).join(", ")}`,a=[...new Set(d.paths.map(o=>o.protocol))];else if(d.path){const o=d.protocol||"anthropic";x=`${s("modelManagement.tabs.customEndpoint")}: ${d.path} (${o})`,a=[o]}return{key:d.id,label:d.label||d.id,description:x,isSystem:!1,canDelete:d.deletable!==!1,protocols:a}});return[...c,...g]}function Et(s){return s.label&&s.label.trim().length>0?`${s.label} (${s.id})`:s.id}function qs({providerCount:s,providersLength:t,filteredProviders:c,defaultLabels:g,providerSearch:d,providerTypeFilter:x,configPending:a,configFetching:o,testingProviderId:m,onRefresh:u,onOpenCreate:h,onOpenEdit:F,onTestConnection:k,onRequestDelete:M,onProviderSearchChange:C,onProviderTypeChange:v,onResetFilters:f}){const{t:b}=te();return e.jsx(Fe,{children:e.jsxs(Be,{className:"space-y-6 pt-6",children:[e.jsx(Ct,{eyebrow:"Model Access",title:b("providers.title"),description:b("providers.description"),breadcrumb:[b("modelManagement.title"),b("modelManagement.tabs.providers")],aside:e.jsxs("div",{className:"flex w-full flex-wrap items-center gap-2 sm:w-auto sm:gap-3",children:[e.jsx(H,{variant:"secondary",children:b("providers.count",{count:s})}),e.jsxs(L,{variant:"outline",size:"sm",onClick:u,disabled:o,className:"w-full sm:w-auto",children:[e.jsx(fs,{className:oe("mr-2 h-4 w-4",o&&"animate-spin")}),b(o?"common.actions.refreshing":"providers.actions.refresh")]}),e.jsxs(L,{size:"sm",onClick:h,className:"w-full sm:w-auto",children:[e.jsx(pt,{className:"mr-2 h-4 w-4"}),b("providers.actions.add")]})]})}),e.jsxs("div",{className:"grid gap-3 md:grid-cols-3",children:[e.jsx(_e,{label:"Configured",value:s.toString(),helper:"Total providers in supply pool",tone:"blue"}),e.jsx(_e,{label:"Visible",value:c.length.toString(),helper:"Providers matching current filter",tone:"emerald"}),e.jsx(_e,{label:"Connection Status",value:m?"Testing":"Idle",helper:m?`Testing ${m}`:"Ready for diagnostics",tone:"amber"})]}),e.jsxs("div",{className:"rounded-lg border border-border bg-accent px-4 py-3 text-sm text-primary",children:[e.jsx("p",{className:"font-medium",children:b("modelManagement.providersSemantics.title")}),e.jsx("p",{className:"mt-1 leading-6 text-primary/80",children:b("modelManagement.providersSemantics.description")})]}),e.jsxs("div",{className:"grid gap-3 rounded-lg border border-border bg-secondary p-4 sm:grid-cols-2 xl:grid-cols-[minmax(0,1fr)_220px_auto]",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(J,{className:"text-[11px] uppercase tracking-[0.16em] text-muted-foreground",children:b("providers.filters.searchPlaceholder")}),e.jsx(fe,{value:d,onChange:j=>C(j.target.value),placeholder:b("providers.filters.searchPlaceholder")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(J,{className:"text-[11px] uppercase tracking-[0.16em] text-muted-foreground",children:b("providers.filters.typeAll")}),e.jsxs(gt,{value:x,onValueChange:v,children:[e.jsx(ht,{children:e.jsx(ft,{})}),e.jsxs(bt,{children:[e.jsx(me,{value:"all",children:b("providers.filters.typeAll")}),e.jsx(me,{value:"openai",children:"OpenAI"}),e.jsx(me,{value:"anthropic",children:"Anthropic"}),e.jsx(me,{value:"deepseek",children:"DeepSeek"}),e.jsx(me,{value:"huawei",children:"Huawei"}),e.jsx(me,{value:"kimi",children:"Kimi"}),e.jsx(me,{value:"custom",children:"Custom"})]})]})]}),e.jsx("div",{className:"flex items-end sm:col-span-2 xl:col-span-1",children:e.jsx(L,{variant:"ghost",size:"sm",onClick:f,disabled:!d.trim()&&x==="all",className:"w-full xl:w-auto",children:b("common.actions.reset")})})]}),a?e.jsx("div",{className:"flex min-h-[200px] items-center justify-center rounded-lg border border-border bg-secondary text-sm text-muted-foreground",children:b("common.loading")}):t===0?e.jsxs("div",{className:"rounded-lg border border-dashed border-border p-12 text-center text-sm text-muted-foreground",children:[e.jsx("p",{className:"font-medium",children:b("providers.emptyState")}),e.jsx("p",{className:"mt-2 text-xs",children:b("providers.emptyStateSub",{default:"点击上方按钮添加您的第一个提供商"})})]}):c.length===0?e.jsx("div",{className:"rounded-lg border border-dashed border-border p-12 text-center text-sm text-muted-foreground",children:e.jsx("p",{className:"font-medium",children:b("providers.emptyFiltered")})}):e.jsx("div",{className:"grid gap-4 [grid-template-columns:repeat(auto-fit,minmax(280px,1fr))]",children:c.map(j=>{var Q;return e.jsx(Fe,{className:"flex flex-col overflow-hidden","data-testid":"provider-card",children:e.jsxs(Be,{className:"flex flex-1 flex-col gap-4 pt-6",children:[e.jsxs("div",{className:"flex flex-col gap-4 sm:flex-row sm:items-start sm:justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h3",{className:"text-base font-semibold tracking-[-0.02em]",children:j.label||j.id}),j.type?e.jsx(Ws,{type:j.type}):null]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["ID: ",j.id]}),e.jsx("code",{className:"block max-w-full break-all rounded-lg border border-border bg-secondary px-2.5 py-1.5 text-[11px] text-muted-foreground",children:j.baseUrl})]}),j.defaultModel?e.jsx(H,{variant:"default",className:"text-xs",children:g.get(j.id)??j.defaultModel}):e.jsx(H,{variant:"secondary",className:"text-xs",children:b("providers.card.noDefault")})]}),e.jsxs("div",{className:"grid gap-2 sm:grid-cols-3",children:[e.jsx(Ce,{label:b("providers.card.authMode"),value:j.authMode==="authToken"?"Bearer":j.authMode==="xAuthToken"?"X-Auth-Token":"API Key"}),e.jsx(Ce,{label:b("providers.card.modelsTitle"),value:(Q=j.models)!=null&&Q.length?b("providers.card.modelCount",{count:j.models.length}):b("providers.card.passthrough")}),e.jsx(Ce,{label:b("providers.card.defaultModelLabel"),value:j.defaultModel?g.get(j.id)??j.defaultModel:b("providers.card.noDefault"),truncate:!0})]}),e.jsxs("div",{className:"grid gap-2 sm:grid-cols-2",children:[e.jsx(Ce,{label:"Routing readiness",value:j.defaultModel?"Ready":"Needs default"}),e.jsx(Ce,{label:"Endpoint type",value:j.type?j.type:"custom"})]}),e.jsxs("div",{className:"space-y-2 rounded-lg border border-border bg-secondary p-3",children:[e.jsx(J,{className:"text-xs uppercase tracking-[0.16em] text-muted-foreground",children:b("providers.card.modelsTitle")}),j.models&&j.models.length>0?e.jsx("div",{className:"flex max-h-24 flex-wrap gap-1 overflow-y-auto",children:j.models.map(Y=>e.jsx(H,{variant:"outline",className:"text-xs",children:Et(Y)},Y.id))}):e.jsx("p",{className:"text-xs text-muted-foreground",children:b("providers.card.noModels")})]}),e.jsxs("div",{className:"mt-auto grid gap-2 border-t border-border pt-4 sm:grid-cols-3",children:[e.jsx(L,{variant:"default",size:"sm",onClick:()=>F(j),className:"w-full",children:b("providers.actions.edit")}),e.jsx(L,{variant:"outline",size:"sm",onClick:()=>k(j),disabled:m===j.id,className:"w-full",children:m===j.id?b("common.actions.testingConnection"):b("providers.actions.test")}),e.jsx(L,{variant:"destructive",size:"sm",onClick:()=>M(j),className:"w-full",children:b("providers.actions.delete")})]})]})},j.id)})})]})})}function _e({helper:s,label:t,value:c}){return e.jsxs("div",{className:"rounded-lg border border-border bg-card px-4 py-3",children:[e.jsx("p",{className:"text-[11px] font-medium uppercase tracking-wider text-muted-foreground",children:t}),e.jsx("p",{className:"mt-2 text-base font-semibold text-foreground",children:c}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:s})]})}function Ce({label:s,value:t,truncate:c}){return e.jsxs("div",{className:"rounded-lg border border-border bg-secondary px-3 py-2",children:[e.jsx("p",{className:"text-[11px] font-medium uppercase tracking-[0.16em] text-muted-foreground",children:s}),e.jsx("p",{className:oe("mt-1 text-sm font-medium",c&&"truncate"),children:t})]})}function Ws({type:s}){const t={openai:{label:"OpenAI",variant:"success"},deepseek:{label:"DeepSeek",variant:"info"},huawei:{label:"华为云",variant:"warning"},kimi:{label:"Kimi",variant:"purple"},anthropic:{label:"Anthropic",variant:"pink"},custom:{label:"Custom",variant:"secondary"}},{label:c,variant:g}=t[s]||t.custom;return e.jsx(H,{variant:g,className:"text-xs",children:c})}function Qs({value:s,onChange:t,options:c,disabled:g,placeholder:d}){const{t:x}=te(),[a,o]=N.useState(!1),[m,u]=N.useState(""),h=N.useMemo(()=>{if(!m.trim())return c;const k=m.toLowerCase();return c.filter(M=>M.label.toLowerCase().includes(k)||M.value.toLowerCase().includes(k))},[c,m]),F=k=>{t(k),u(""),o(!1)};return e.jsxs(Es,{open:a,onOpenChange:k=>{o(k),k&&u("")},children:[e.jsx(Ss,{asChild:!0,children:e.jsx(fe,{value:s,onChange:k=>{t(k.target.value),u(k.target.value),a||o(!0)},onFocus:()=>{u(""),o(!0)},onClick:()=>{a||o(!0)},placeholder:d,disabled:g,autoComplete:"off"})}),e.jsx(Ps,{className:"max-h-60 w-[var(--radix-popover-trigger-width)] overflow-y-auto p-1",align:"start",onOpenAutoFocus:k=>k.preventDefault(),children:h.length===0?e.jsx("div",{className:"px-2 py-3 text-center text-xs text-muted-foreground",children:x("common.noMatches")}):h.map(k=>e.jsx("button",{type:"button",className:oe("flex w-full items-center rounded-sm px-2 py-1.5 text-left text-sm hover:bg-accent",k.value===s.trim()&&"bg-accent"),onMouseDown:M=>{M.preventDefault(),F(k.value)},children:e.jsx("span",{className:"truncate",children:k.label})},k.value))})]})}function Gs({endpoint:s,tabs:t,customEndpoints:c,config:g,routes:d,routeError:x,savingRoute:a,isDirty:o,presets:m,presetName:u,presetError:h,savingPreset:F,applyingPreset:k,deletingPreset:M,presetsExpanded:C,savingClaudeValidation:v,providerModelOptions:f,onTogglePresetsExpanded:b,onPresetNameChange:j,onSavePreset:Q,onRequestPresetDiff:Y,onRequestDeletePreset:ue,onToggleClaudeValidation:le,onRouteChange:Z,onRemoveRoute:V,onAddSuggestion:pe,onAddRoute:G,onResetRoutes:we,onSaveRoutes:be}){var B,X;const{t:T}=te(),I=t.find(A=>A.key===s),se=((B=I==null?void 0:I.protocols)==null?void 0:B.includes("anthropic"))??s==="anthropic"?Hs:Is,xe=(I==null?void 0:I.label)??s,ie=(I==null?void 0:I.isSystem)===!1?I.description:T(`settings.routing.descriptionByEndpoint.${s}`),ge=`route-source-${s}`,i=zs(s,c),E=Vs(s,g,c),R=i&&(E==null?void 0:E.mode)==="claude-code",P=new Set(d.map(A=>A.source.trim()).filter(Boolean));return e.jsx(Fe,{children:e.jsxs(Be,{className:"space-y-6 pt-6",children:[e.jsx(Ct,{eyebrow:"Routing Workspace",title:T("settings.routing.titleByEndpoint",{endpoint:xe}),description:ie,breadcrumb:[T("modelManagement.title"),xe],aside:e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs(H,{variant:"outline",children:[d.length," rules"]}),o?e.jsx(H,{variant:"outline",className:"border-amber-300 text-amber-700 dark:border-amber-700 dark:text-amber-300",children:T("modelManagement.actions.unsaved")}):e.jsx(H,{variant:"secondary",children:T("common.status.success")})]})}),e.jsxs("div",{className:"grid gap-3 md:grid-cols-4",children:[e.jsx(Ue,{label:"Rules",value:d.length.toString(),helper:"Current model routes",tone:"blue"}),e.jsx(Ue,{label:"Presets",value:m.length.toString(),helper:"Reusable routing templates",tone:"emerald"}),e.jsx(Ue,{label:"Protocols",value:(((X=I==null?void 0:I.protocols)==null?void 0:X.length)??0).toString(),helper:"Bound to this endpoint",tone:"amber"}),e.jsx(Ue,{label:"Validation",value:i?R?"Claude Code":"Disabled":"Standard",helper:i?"Anthropic compatibility mode":"Default endpoint routing",tone:"rose"})]}),e.jsx("div",{className:"rounded-lg border border-border bg-secondary px-4 py-3 text-xs text-muted-foreground",children:T("settings.routing.wildcardHint")}),i?e.jsx("div",{className:"rounded-lg border border-primary/20 bg-accent p-4",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",children:T("modelManagement.claudeValidation.title")}),e.jsx("p",{className:"text-xs text-primary/80",children:T("modelManagement.claudeValidation.description")})]}),e.jsxs("div",{className:"flex items-center gap-2 self-start sm:self-auto",children:[e.jsx(qe,{checked:R,onCheckedChange:le,disabled:v}),e.jsx("span",{className:oe("text-xs font-medium",R?"text-emerald-600 dark:text-emerald-400":"text-muted-foreground"),children:T(R?"modelManagement.claudeValidation.statusEnabled":"modelManagement.claudeValidation.statusDisabled")})]})]})}):null,x?e.jsx("p",{className:"text-sm text-destructive",children:x}):null,e.jsxs("div",{className:"space-y-3 rounded-lg border border-border bg-secondary 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(J,{className:"text-sm font-semibold text-foreground",children:T("modelManagement.routesEditorTitle")}),e.jsxs(H,{variant:"outline",children:[d.length," active"]})]}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:T("modelManagement.overview.routesEditorHint")})]}),e.jsxs("div",{className:"self-start rounded-lg border border-border bg-card px-3 py-2 text-[11px] text-muted-foreground",children:[xe," workspace"]})]}),d.length===0?e.jsxs("div",{className:"rounded-lg border border-dashed border-border p-12 text-center text-sm text-muted-foreground",children:[e.jsx("p",{className:"font-medium",children:T("settings.routing.empty")}),e.jsx("p",{className:"mt-2 text-xs",children:T("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:T("settings.routing.source")}),e.jsx("span",{}),e.jsx("span",{children:T("settings.routing.target")}),e.jsx("span",{})]}),d.map((A,q)=>e.jsxs("div",{className:"rounded-lg border border-border bg-card p-3",children:[e.jsxs("div",{className:"mb-3 flex items-center justify-between md:hidden",children:[e.jsxs(H,{variant:"outline",className:"text-[11px]",children:["#",q+1]}),e.jsx(L,{variant:"ghost",size:"icon",className:"h-8 w-8 text-muted-foreground hover:text-destructive",onClick:()=>V(A.id),disabled:a,children:e.jsx(Se,{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(J,{className:"text-[11px] uppercase tracking-[0.16em] text-muted-foreground md:hidden",children:T("settings.routing.source")}),e.jsx(fe,{value:A.source,onChange:de=>Z(A.id,"source",de.target.value),placeholder:T("settings.routing.sourcePlaceholder"),list:ge,disabled:a,"aria-label":`route-source-${q+1}`})]}),e.jsx(Ne,{className:"hidden h-4 w-4 flex-shrink-0 text-muted-foreground md:block"}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(J,{className:"text-[11px] uppercase tracking-[0.16em] text-muted-foreground md:hidden",children:T("settings.routing.target")}),e.jsx(Qs,{value:A.target,onChange:de=>Z(A.id,"target",de),options:f,disabled:a,placeholder:T("settings.routing.targetPlaceholder")})]}),e.jsx(L,{variant:"ghost",size:"icon",className:"hidden h-8 w-8 text-muted-foreground hover:text-destructive md:inline-flex",onClick:()=>V(A.id),disabled:a,children:e.jsx(Se,{className:"h-4 w-4"})})]})]},A.id))]})]}),e.jsxs("div",{className:"space-y-3 rounded-lg border border-border bg-secondary p-4",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(J,{className:"text-sm font-semibold text-foreground",children:T("settings.routing.suggested")}),e.jsxs(H,{variant:"outline",children:[se.length," presets"]})]}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:T("modelManagement.overview.suggestionHint")})]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:se.map(A=>{const q=P.has(A);return e.jsx(L,{variant:q?"ghost":"outline",size:"sm",onClick:()=>pe(A),disabled:a||q,className:q?"opacity-50":"",children:A},`${s}-${A}`)})})]}),e.jsxs("div",{className:"flex flex-col gap-3 rounded-lg border border-border bg-card p-4 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:T("modelManagement.actions.footerTitle")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:T(o?"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(L,{variant:"outline",size:"sm",onClick:G,disabled:a,className:"w-full",children:T("settings.routing.add")}),e.jsx(L,{variant:"outline",size:"sm",onClick:we,disabled:a||!o,className:"w-full",children:T("common.actions.reset")}),e.jsxs(L,{size:"sm",onClick:be,disabled:a,className:"relative w-full",children:[T(a?"common.actions.saving":"modelManagement.actions.saveRoutes"),o?e.jsx("span",{className:"absolute -right-1 -top-1 h-2 w-2 rounded-full bg-amber-500"}):null]})]})]}),e.jsx(Xs,{presets:m,presetName:u,presetError:h,savingPreset:F,applyingPreset:k,deletingPreset:M,expanded:C,onToggleExpanded:b,onPresetNameChange:j,onSavePreset:Q,onRequestPresetDiff:Y,onRequestDeletePreset:ue}),e.jsx("datalist",{id:ge,children:se.map(A=>e.jsx("option",{value:A},`${ge}-${A}`))})]})})}function Ue({helper:s,label:t,value:c}){return e.jsxs("div",{className:"rounded-lg border border-border bg-card px-4 py-3",children:[e.jsx("p",{className:"text-[11px] font-medium uppercase tracking-wider text-muted-foreground",children:t}),e.jsx("p",{className:"mt-2 truncate text-base font-semibold text-foreground",children:c}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:s})]})}function Xs({presets:s,presetName:t,presetError:c,savingPreset:g,applyingPreset:d,deletingPreset:x,expanded:a,onToggleExpanded:o,onPresetNameChange:m,onSavePreset:u,onRequestPresetDiff:h,onRequestDeletePreset:F}){const{t:k}=te();return e.jsxs("div",{className:"rounded-lg border border-dashed border-border bg-card",children:[e.jsx("button",{type:"button",className:"flex w-full items-center justify-between gap-3 p-4 text-left transition-colors hover:bg-primary/5",onClick:o,children:e.jsxs("div",{className:"flex items-center gap-2",children:[a?e.jsx(bs,{className:"h-4 w-4"}):e.jsx(xt,{className:"h-4 w-4"}),e.jsx("h3",{className:"font-medium",children:k("modelManagement.presets.title")}),e.jsx(H,{variant:"secondary",className:"text-xs",children:s.length})]})}),a?e.jsxs("div",{className:"space-y-4 border-t px-4 pb-4 pt-3",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:k("modelManagement.presets.description")}),e.jsxs("div",{className:"flex flex-col gap-3 md:flex-row md:items-center",children:[e.jsx(fe,{value:t,onChange:M=>m(M.target.value),placeholder:k("modelManagement.presets.namePlaceholder"),disabled:g,className:"w-full md:w-48"}),e.jsx(L,{onClick:u,disabled:g,className:"w-full md:w-auto",children:k(g?"modelManagement.presets.saving":"modelManagement.presets.save")})]}),c?e.jsx("p",{className:"text-sm text-destructive",children:c}):null,s.length===0?e.jsx("p",{className:"py-4 text-center text-sm text-muted-foreground",children:k("modelManagement.presets.empty")}):e.jsx(Ns,{children:e.jsx("div",{className:"grid gap-2 sm:grid-cols-2 lg:grid-cols-3",children:s.map(M=>{const C=d===M.name,v=x===M.name,f=Object.entries(M.modelRoutes??{}),b=f.length;return e.jsxs("div",{className:"flex flex-col gap-3 rounded-lg border border-border bg-secondary px-4 py-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs(ws,{children:[e.jsx(Ms,{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:M.name}),e.jsx(H,{variant:"outline",className:"mt-1 text-xs",children:b>0?k("modelManagement.presets.rulesCount",{count:b}):k("modelManagement.presets.noRules")})]})}),b>0?e.jsx(ks,{side:"bottom",className:"max-w-xs",children:e.jsxs("div",{className:"space-y-1 text-xs",children:[f.slice(0,5).map(([j,Q])=>e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"truncate",children:j}),e.jsx(Ne,{className:"h-3 w-3 flex-shrink-0"}),e.jsx("span",{className:"truncate",children:Q})]},j)),b>5?e.jsxs("div",{className:"text-muted-foreground",children:["…+",b-5]}):null]})}):null]}),e.jsxs("div",{className:"grid flex-shrink-0 gap-2 sm:flex sm:items-center",children:[e.jsx(L,{size:"sm",onClick:()=>h(M),disabled:C||v,className:"w-full sm:w-auto",children:k(C?"modelManagement.presets.applying":"modelManagement.presets.apply")}),e.jsx(L,{variant:"destructive",size:"sm",onClick:()=>F(M),disabled:v||C,className:"w-full sm:w-auto",children:k(v?"modelManagement.presets.deleting":"modelManagement.presets.delete")})]})]},M.name)})})})]}):null]})}function Js({open:s,provider:t,options:c,usePreset:g,preservedExtras:d,onPresetChange:x,onConfirm:a,onClose:o}){const{t:m}=te();return t?e.jsx(vt,{open:s,onOpenChange:u=>!u&&o(),children:e.jsxs(jt,{className:"max-w-2xl",children:[e.jsxs(yt,{children:[e.jsx(Nt,{children:m("providers.testDialog.title")}),e.jsx(wt,{children:m("providers.testDialog.subtitle",{name:t.label||t.id})})]}),e.jsxs(Mt,{className:"space-y-4",children:[e.jsx("div",{className:"rounded-lg border border-primary/20 bg-accent p-4 text-sm text-primary",children:m("providers.testDialog.description")}),e.jsxs("div",{className:"space-y-4 rounded-lg border border-border bg-secondary p-4",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(J,{htmlFor:"provider-test-preset",children:m("providers.testDialog.presetLabel")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:m("providers.testDialog.presetDescription")})]}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(qe,{id:"provider-test-preset",checked:g,onCheckedChange:x})})]}),g?e.jsx("div",{className:"space-y-2",children:e.jsxs("details",{className:"rounded-lg border border-border bg-secondary p-2 text-xs",children:[e.jsx("summary",{className:"cursor-pointer text-primary hover:underline",children:m("providers.testDialog.presetPreviewSummary")}),e.jsx("div",{className:"mt-2 space-y-1",children:c.map(u=>e.jsxs("code",{className:"block rounded-md border border-border bg-card px-2 py-1 text-xs",children:[u.key,": ",u.value]},u.key))})]})}):e.jsx("p",{className:"text-xs text-muted-foreground",children:m("providers.testDialog.presetDescription")})]}),Object.keys(d).length>0&&e.jsxs("div",{className:"space-y-2 rounded-lg border border-border bg-secondary p-4 text-xs",children:[e.jsx("p",{className:"font-medium",children:m("providers.testDialog.preservedInfo")}),Object.entries(d).map(([u,h])=>e.jsxs("code",{className:"block rounded-md border border-border bg-card px-2 py-1",children:[u,": ",h]},u))]})]}),e.jsxs(kt,{children:[e.jsx(L,{variant:"outline",onClick:o,children:m("providers.testDialog.cancel")}),e.jsx(L,{onClick:()=>void a(),children:m("providers.testDialog.primary")})]})]})}):null}const $e={savePreset(s,t){return Re(Te.post(`/api/routing-presets/${s}`,{name:t}))},applyPreset(s,t){return Re(Te.post(`/api/routing-presets/${s}/apply`,{name:t}))},deletePreset(s,t){return Re(Te.delete(`/api/routing-presets/${s}/${encodeURIComponent(t)}`))},testProvider(s,t){return Re(Te.post(`/api/providers/${s}/test`,t))}};function ut(s,t){var g,d,x;const c={anthropic:((g=s.routingPresets)==null?void 0:g.anthropic)??[],openai:((d=s.routingPresets)==null?void 0:d.openai)??[]};for(const a of t){const o=(x=s.customEndpoints)==null?void 0:x.find(m=>m.id===a.id);c[a.id]=(o==null?void 0:o.routingPresets)??a.routingPresets??[]}return c}function Ys(){var at;const{t:s}=te(),{pushToast:t}=Cs(),c=Ds(),g=Ts(he.config.full(),ye.configRequest()),x=((at=Rs({queryKey:he.customEndpoints.all(),queryFn:Ee.list,refetchInterval:1e4}).data)==null?void 0:at.endpoints)??[],a=N.useMemo(()=>_s(s,x),[x,s]),[o,m]=N.useState("providers"),[u,h]=N.useState(null),[F,k]=N.useState(!1),[M,C]=N.useState("create"),[v,f]=N.useState(void 0),[b,j]=N.useState(void 0),[Q,Y]=N.useState(null),[ue,le]=N.useState(!1),[Z,V]=N.useState({}),[pe,G]=N.useState({}),[we,be]=N.useState(null),[T,I]=N.useState({}),[Me,se]=N.useState({}),[xe,ie]=N.useState({}),[ge,i]=N.useState(null),[E,R]=N.useState(null),[P,B]=N.useState(null),[X,A]=N.useState(!1),[q,de]=N.useState(null),[re,He]=N.useState(!0),[Ge,Xe]=N.useState({}),[St,Je]=N.useState(!1),[Pt,Dt]=N.useState({}),[Rt,Tt]=N.useState(null),[S,Ye]=N.useState(null),[Ot,Ze]=N.useState(!1),[Ie,At]=N.useState(""),[Pe,Ut]=N.useState("all"),$t=N.useMemo(()=>a.filter(r=>r.isSystem),[a]),Lt=N.useMemo(()=>a.filter(r=>!r.isSystem),[a]),Ft=N.useMemo(()=>a.find(r=>r.key===o)??a[0]??null,[o,a]),ee=(u==null?void 0:u.providers)??[],Bt=ee.length,Ht=N.useMemo(()=>ee.filter(r=>{var w;if(!(Pe==="all"||(r.type??"custom")===Pe))return!1;const n=Ie.trim().toLowerCase();return n?[r.id,r.label??"",r.baseUrl,r.defaultModel??"",...((w=r.models)==null?void 0:w.map(y=>y.id))??[]].join(" ").toLowerCase().includes(n):!0}),[Ie,Pe,ee]),ke=N.useMemo(()=>[{key:"anthropic-beta",value:"claude-code-20250219,interleaved-thinking-2025-05-14,fine-grained-tool-streaming-2025-05-14",label:s("providers.testDialog.options.beta.label"),description:s("providers.testDialog.options.beta.description")}],[s]);N.useEffect(()=>{if(!g.data)return;const r=g.data;h(r),V(l=>{const n=Ve(r,x);if(!l||Object.keys(l).length===0)return n;const p={...n};for(const[w,y]of Object.entries(l)){if(!(w in n))continue;const D=ct(r,x,w);mt(y,D)&&(p[w]=y)}return p}),G({}),I(ut(r,x))},[g.data,x]),N.useEffect(()=>{!g.isError||!g.error||t({title:s("providers.toast.loadFailure",{message:g.error.message}),variant:"error"})},[g.error,g.isError,t,s]),N.useEffect(()=>{a.some(r=>r.key===o)||m("providers")},[o,a]);const It=N.useMemo(()=>{const r=new Map;for(const l of ee){if(!l.defaultModel||!l.models)continue;const n=l.models.find(p=>p.id===l.defaultModel);n&&r.set(l.id,Et(n))}return r},[ee]),Kt=N.useMemo(()=>{const r=[],l=new Set;for(const n of ee){const p=n.label&&n.label!==n.id?`${n.label} (${n.id})`:n.id,w=n.models??[];if(w.length>0)for(const D of w){const $=`${n.id}:${D.id}`;l.has($)||(l.add($),r.push({value:$,label:`${p} · ${D.label??D.id}`}))}else if(n.defaultModel){const D=`${n.id}:${n.defaultModel}`;l.has(D)||(l.add(D),r.push({value:D,label:`${p} · ${n.defaultModel}`}))}const y=`${n.id}:*`;l.has(y)||(l.add(y),r.push({value:y,label:s("settings.routing.providerPassthroughOption",{provider:p})}))}for(const n of Object.values(Z).flat()){const p=n.target.trim();p&&!l.has(p)&&(l.add(p),r.push({value:p,label:p}))}return r},[ee,Z,s]),zt=()=>{j(void 0),le(!0)},Vt=r=>{j(r),le(!0)},_t=r=>u?ct(u,x,r):{},qt=N.useMemo(()=>{const r={};for(const l of a){if(l.key==="providers")continue;const n=Z[l.key]||[];r[l.key]=mt(n,_t(l.key))}return r},[u,x,Z,a]),et=(r,l)=>{I(n=>({...n,[r]:l})),h(n=>{if(!n)return n;if(r==="anthropic"||r==="openai")return{...n,routingPresets:{...n.routingPresets,[r]:l}};const p=[...n.customEndpoints??[]],w=p.findIndex(y=>y.id===r);return w===-1?n:(p[w]={...p[w],routingPresets:l},{...n,customEndpoints:p})})},ce=()=>u?!0:(t({title:s("settings.toast.missingConfig"),variant:"error"}),g.refetch(),!1),Wt=(r,l)=>{se(n=>({...n,[r]:l})),l.trim()&&ie(n=>({...n,[r]:null}))},Qt=async r=>{if(!ce())return;const l=(Me[r]??"").trim();if(!l){ie(n=>({...n,[r]:s("modelManagement.validation.presetName")}));return}if((T[r]??[]).some(n=>n.name.toLowerCase()===l.toLowerCase())){ie(n=>({...n,[r]:s("modelManagement.validation.presetDuplicate",{name:l})}));return}i(r);try{const p=(await $e.savePreset(r,l)).presets??[];et(r,p),se(w=>({...w,[r]:""})),ie(w=>({...w,[r]:null})),t({title:s("modelManagement.toast.presetSaved",{name:l}),variant:"success"})}catch(n){t({title:s("modelManagement.toast.presetSaveFailure",{message:n instanceof Error?n.message:"unknown"}),variant:"error"})}finally{i(null),g.refetch()}},Gt=async(r,l)=>{if(ce()){R({endpoint:r,name:l.name});try{const p=(await $e.applyPreset(r,l.name)).config;if(p)h(p),V(Ve(p,x)),I(ut(p,x));else{const w=l.modelRoutes??{};V(y=>({...y,[r]:Object.entries(w).map(([D,$])=>({id:ne(),source:D,target:$}))})),h(y=>{var $,U,O,K;if(!y)return y;const D=(y.customEndpoints??[]).findIndex(z=>z.id===r);if(D!==-1){const z=[...y.customEndpoints??[]],ae=z[D];return z[D]={...ae,routing:{defaults:(($=ae.routing)==null?void 0:$.defaults)??y.defaults,...ae.routing??{},modelRoutes:w}},{...y,customEndpoints:z}}return r==="anthropic"||r==="openai"?{...y,endpointRouting:{...y.endpointRouting??{},[r]:{defaults:((O=(U=y.endpointRouting)==null?void 0:U[r])==null?void 0:O.defaults)??y.defaults,...((K=y.endpointRouting)==null?void 0:K[r])??{},modelRoutes:w}},modelRoutes:r==="anthropic"?w:y.modelRoutes??{}}:y})}r!=="anthropic"&&r!=="openai"&&await c.invalidateQueries({queryKey:he.customEndpoints.all()}),t({title:s("modelManagement.toast.presetApplySuccess",{name:l.name}),variant:"success"})}catch(n){t({title:s("modelManagement.toast.presetApplyFailure",{message:n instanceof Error?n.message:"unknown"}),variant:"error"})}finally{R(null),g.refetch()}}},Xt=async(r,l)=>{if(ce()){B({endpoint:r,name:l.name});try{const n=await $e.deletePreset(r,l.name);et(r,n.presets??[]),t({title:s("modelManagement.toast.presetDeleteSuccess",{name:l.name}),variant:"success"})}catch(n){t({title:s("modelManagement.toast.presetDeleteFailure",{message:n instanceof Error?n.message:"unknown"}),variant:"error"})}finally{B(null),g.refetch()}}},Jt=()=>{ce()&&(C("create"),f(void 0),k(!0))},Yt=r=>{ce()&&(C("edit"),f(r),k(!0))},Zt=async r=>{if(!u)throw new Error(s("settings.toast.missingConfig"));const l=M==="create"?[...ee,r]:ee.map(p=>v&&p.id===v.id?{...r,id:v.id}:p),n={...u,providers:l};await ye.saveConfig(n),h(n),V(Ve(n,x)),g.refetch(),t({title:M==="create"?s("providers.toast.createSuccess",{name:r.label||r.id}):s("providers.toast.updateSuccess",{name:r.label||r.id}),variant:"success"})},es=async r=>{const l=x.find(n=>n.id===r);if(!(!l||l.deletable===!1))try{await Ee.delete(r),await c.invalidateQueries({queryKey:he.customEndpoints.all()}),t({title:s("modelManagement.deleteEndpointSuccess"),variant:"success"}),o===r&&m("providers")}catch(n){const p=ot(n);t({title:s("modelManagement.deleteEndpointError",{error:p.message}),variant:"error"})}},tt=async(r,l)=>{Y(r.id);try{const n=l&&(l.headers||l.query)?{headers:l.headers&&Object.keys(l.headers).length>0?l.headers:void 0,query:l.query&&l.query.trim().length>0?l.query.trim():void 0}:void 0,p=await $e.testProvider(r.id,n);if(p.ok){t({title:s("providers.toast.testSuccess"),description:s("providers.toast.testSuccessDesc",{status:p.status,duration:p.durationMs?`${p.durationMs} ms`:"—"}),variant:"success"});return}t({title:s("providers.toast.testFailure",{message:`${p.status} ${p.statusText}`}),variant:"error"})}catch(n){t({title:s("providers.toast.testFailure",{message:n instanceof Error?n.message:"unknown"}),variant:"error"})}finally{Y(null)}},ts=r=>{if(r.type!=="anthropic"){tt(r);return}const l=r.extraHeaders??{},n=new Map(ke.map(y=>[y.key.toLowerCase(),y])),p={};let w=!0;for(const y of ke){const D=Object.entries(l).find(([O])=>O.toLowerCase()===y.key.toLowerCase());if(!D)continue;const[$,U]=D;String(U??"")!==y.value&&(w=!1,p[$]=String(U??""))}for(const[y,D]of Object.entries(l))n.has(y.toLowerCase())||(p[y]=String(D??""));Xe(p),He(w),de(r),A(!0)},st=()=>{A(!1),de(null),He(!0),Xe({})},ss=async()=>{if(!q)return;const r={};if(re)for(const p of ke)r[p.key]=p.value;const l=new Map(ke.map(p=>[p.key.toLowerCase(),p]));for(const[p,w]of Object.entries(Ge))l.get(p.toLowerCase())&&re||(r[p]=w);const n=q;st(),await tt(n,{headers:Object.keys(r).length>0?r:void 0,query:re?"beta=true":void 0})},rt=async r=>{var U,O,K,z,ae,De;if(!ce())return;const l=ee.filter(_=>_.id!==r.id),n=_=>{const W={};if(!_)return W;for(const[ve,je]of Object.entries(_)){if(!je)continue;const[nt]=je.split(":");nt&&nt===r.id||je===r.id||(W[ve]=je)}return W},p=(u==null?void 0:u.endpointRouting)??{},w=n(((U=p.anthropic)==null?void 0:U.modelRoutes)??(u==null?void 0:u.modelRoutes)??{}),y=n(((O=p.openai)==null?void 0:O.modelRoutes)??{}),D=((u==null?void 0:u.customEndpoints)??x).map(_=>{const W=_.routing,ve=W==null?void 0:W.modelRoutes;return ve?{..._,routing:{...W,defaults:W.defaults??u.defaults,modelRoutes:n(ve)}}:_}),$={...u,providers:l,modelRoutes:w,customEndpoints:D,endpointRouting:{anthropic:{defaults:((K=p.anthropic)==null?void 0:K.defaults)??u.defaults,modelRoutes:w,validation:(z=p.anthropic)==null?void 0:z.validation},openai:{defaults:((ae=p.openai)==null?void 0:ae.defaults)??u.defaults,modelRoutes:y,validation:(De=p.openai)==null?void 0:De.validation}}};try{await ye.saveConfig($),h($),V({anthropic:Object.entries(w).map(([_,W])=>({id:ne(),source:_,target:W})),openai:Object.entries(y).map(([_,W])=>({id:ne(),source:_,target:W})),...Object.fromEntries(D.map(_=>{var W;return[_.id,Object.entries(((W=_.routing)==null?void 0:W.modelRoutes)??{}).map(([ve,je])=>({id:ne(),source:ve,target:je}))]}))}),t({title:s("providers.toast.deleteSuccess",{name:r.label||r.id}),variant:"success"}),g.refetch()}catch(_){t({title:s("providers.toast.deleteFailure",{message:_ instanceof Error?_.message:"unknown"}),variant:"error"})}},rs=async()=>{if(S){Ze(!0);try{S.kind==="provider"?await rt(S.provider):S.kind==="preset"?await Xt(S.endpoint,S.preset):await es(S.endpoint.id),Ye(null)}finally{Ze(!1)}}},as=r=>{V(l=>({...l,[r]:[...l[r]||[],{id:ne(),source:"",target:""}]})),G(l=>({...l,[r]:null}))},ns=async(r,l)=>{var n,p;if(ce()){Je(!0);try{if(r==="anthropic"||r==="openai"){const w=r,y=u.endpointRouting?{...u.endpointRouting}:{},D=y[w]??{defaults:u.defaults,modelRoutes:(w==="anthropic"?u.modelRoutes:{})??{}},$={defaults:D.defaults??u.defaults,modelRoutes:D.modelRoutes??{}},U=l?{...D.validation??{},mode:"claude-code",allowExperimentalBlocks:((n=D.validation)==null?void 0:n.allowExperimentalBlocks)??!0}:void 0,O={...u,endpointRouting:{...y,[w]:U?{...$,validation:U}:{...$}}};await ye.saveConfig(O),h(O)}else{const w=[...u.customEndpoints??[]],y=w.findIndex(K=>K.id===r);if(y===-1)throw new Error(s("modelManagement.toast.endpointNotFound"));const D=w[y],$=D.routing??{defaults:u.defaults,modelRoutes:{}},U=l?{...$.validation??{},mode:"claude-code",allowExperimentalBlocks:((p=$.validation)==null?void 0:p.allowExperimentalBlocks)??!0}:void 0;w[y]={...D,routing:U?{...$,validation:U}:{defaults:$.defaults,modelRoutes:$.modelRoutes}};const O={...u,customEndpoints:w};await ye.saveConfig(O),h(O)}t({title:s(l?"modelManagement.toast.claudeValidationEnabled":"modelManagement.toast.claudeValidationDisabled"),variant:"success"}),g.refetch()}catch(w){const y=ot(w);t({title:s("modelManagement.toast.claudeValidationFailure",{message:y.message}),variant:"error"})}finally{Je(!1)}}},os=(r,l)=>{V(n=>{const p=n[r]||[];return p.some(w=>w.source.trim()===l.trim())?n:{...n,[r]:[...p,{id:ne(),source:l,target:""}]}}),G(n=>({...n,[r]:null}))},ds=(r,l,n,p)=>{V(w=>({...w,[r]:(w[r]||[]).map(y=>y.id===l?{...y,[n]:p}:y)})),G(w=>({...w,[r]:null}))},ls=(r,l)=>{V(n=>({...n,[r]:(n[r]||[]).filter(p=>p.id!==l)})),G(n=>({...n,[r]:null}))},is=r=>{var n;if(!u)return;const l=(u.customEndpoints??x).find(p=>p.id===r);if(l)V(p=>{var w;return{...p,[r]:Object.entries(((w=l.routing)==null?void 0:w.modelRoutes)??{}).map(([y,D])=>({id:ne(),source:y,target:D}))}});else{const p=u.endpointRouting??{},w=r,y=w==="anthropic"?u.modelRoutes??{}:{},D=((n=p[w])==null?void 0:n.modelRoutes)??y;V($=>({...$,[r]:Object.entries(D).map(([U,O])=>({id:ne(),source:U,target:O}))}))}G(p=>({...p,[r]:null}))},cs=Le({mutationFn:async r=>(await ye.saveConfig(r.nextConfig),r)}),ms=Le({mutationFn:async r=>(await Ee.update(r.endpoint,{routing:r.routing}),r)}),us=async r=>{var p,w,y,D,$;if(!ce())return;const l=Z[r]||[],n={};for(const U of l){const O=U.source.trim(),K=U.target.trim();if(!(!O&&!K)){if(!O||!K){G(z=>({...z,[r]:s("settings.validation.routePair")}));return}if(n[O]){G(z=>({...z,[r]:s("settings.validation.routeDuplicate",{model:O})}));return}n[O]=K}}G(U=>({...U,[r]:null})),be(r);try{const U=x.find(O=>O.id===r);if(U){const O={...U.routing??{},modelRoutes:n,defaults:((p=U.routing)==null?void 0:p.defaults)||u.defaults};await ms.mutateAsync({endpoint:r,routing:O}),h(K=>{if(!K)return K;const z=[...K.customEndpoints??[]],ae=z.findIndex(De=>De.id===r);return ae===-1?K:(z[ae]={...z[ae],routing:O},{...K,customEndpoints:z})}),await c.invalidateQueries({queryKey:he.customEndpoints.all()})}else{const O={...u,endpointRouting:{...u.endpointRouting??{},[r]:{defaults:((y=(w=u.endpointRouting)==null?void 0:w[r])==null?void 0:y.defaults)??u.defaults,modelRoutes:n,validation:($=(D=u.endpointRouting)==null?void 0:D[r])==null?void 0:$.validation}},modelRoutes:r==="anthropic"?n:u.modelRoutes??{}};await cs.mutateAsync({endpoint:r,nextConfig:O}),h(O)}V(O=>({...O,[r]:Object.entries(n).map(([K,z])=>({id:ne(),source:K,target:z}))})),t({title:s("modelManagement.toast.routesSaved"),variant:"success"}),g.refetch()}catch(U){t({title:s("modelManagement.toast.routesSaveFailure",{message:U instanceof Error?U.message:"unknown"}),variant:"error"})}finally{be(null)}},ps=(S==null?void 0:S.kind)==="provider"?s("providers.actions.delete"):(S==null?void 0:S.kind)==="preset"?s("modelManagement.presets.delete"):(S==null?void 0:S.kind)==="endpoint"?s("common.delete"):"",xs=(S==null?void 0:S.kind)==="provider"?s("providers.confirm.delete",{name:S.provider.label||S.provider.id}):(S==null?void 0:S.kind)==="preset"?s("modelManagement.confirm.deletePreset",{name:S.preset.name}):(S==null?void 0:S.kind)==="endpoint"?s("modelManagement.deleteEndpointConfirm",{label:S.endpoint.label}):"",gs=(S==null?void 0:S.kind)==="provider"?S.provider.label||S.provider.id:(S==null?void 0:S.kind)==="preset"?S.preset.name:(S==null?void 0:S.kind)==="endpoint"?S.endpoint.label:"";return{activeTab:o,activeTabInfo:Ft,anthropicTestHeaderOptions:ke,applyingPreset:E,config:u,configQuery:g,confirmAction:S,confirmDialogDescription:xs,confirmDialogName:gs,confirmDialogTitle:ps,confirmingAction:Ot,customEndpoints:x,customTabs:Lt,defaultLabels:It,deletingPreset:P,drawerMode:M,drawerOpen:F,editingEndpoint:b,editingProvider:v,endpointDrawerOpen:ue,filteredProviders:Ht,handleAddRoute:as,handleAddSuggestion:os,handleApplyPreset:Gt,handleConfirmDialog:rs,handleDeleteProvider:rt,handleOpenCreate:Jt,handleOpenCreateEndpoint:zt,handleOpenEditEndpoint:Vt,handleOpenEdit:Yt,handlePresetNameChange:Wt,handleProviderSubmit:Zt,handleRemoveRoute:ls,handleResetRoutes:is,handleRouteChange:ds,handleSavePreset:Qt,handleSaveRoutes:us,handleToggleClaudeValidation:ns,initiateTestConnection:ts,isDirtyByEndpoint:qt,presetDiffDialog:Rt,presetErrorByEndpoint:xe,presetNameByEndpoint:Me,presetsByEndpoint:T,presetsExpanded:Pt,providerCount:Bt,providerModelOptions:Kt,providerSearch:Ie,providerTypeFilter:Pe,providers:ee,pushToast:t,routeError:pe,routesByEndpoint:Z,savingClaudeValidation:St,savingPresetFor:ge,savingRouteFor:we,setActiveTab:m,setConfirmAction:Ye,setDrawerMode:C,setDrawerOpen:k,setEditingEndpoint:j,setEditingProvider:f,setEndpointDrawerOpen:le,setPresetDiffDialog:Tt,setPresetsExpanded:Dt,setProviderSearch:At,setProviderTypeFilter:Ut,setTestDialogUsePreset:He,systemTabs:$t,tabs:a,testDialogOpen:X,testDialogPreservedExtras:Ge,testDialogProvider:q,testDialogUsePreset:re,testingProviderId:Q,closeTestDialog:st,confirmTestDialog:ss}}function br(){var x,a,o;const{t:s}=te(),t=Ys(),c=Object.values(t.isDirtyByEndpoint).filter(Boolean).length,g=Math.max(0,t.systemTabs.length-1)+t.customTabs.length,d=t.activeTab==="providers"?s("modelManagement.header.providersHelper"):s("modelManagement.header.routingHelper",{name:((x=t.activeTabInfo)==null?void 0:x.label)??t.activeTab});return e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx(ys,{icon:e.jsx(vs,{className:"h-5 w-5","aria-hidden":"true"}),title:s("modelManagement.title"),description:s("modelManagement.description"),eyebrow:"Routing Control",breadcrumb:"Gateway / Model Management",helper:d,badge:c>0?s("modelManagement.overview.unsavedCount",{count:c}):void 0,actions:e.jsxs("div",{className:"flex w-full flex-col gap-2 sm:w-auto sm:flex-row sm:flex-wrap sm:justify-end",children:[e.jsxs("div",{className:"rounded-lg border border-border bg-secondary px-3 py-2 text-xs text-muted-foreground",children:[s("modelManagement.tabs.providers")," · ",t.providerCount," / ",s("modelManagement.overview.routeWorkspacesStat")," · ",g]}),e.jsx(L,{onClick:t.handleOpenCreateEndpoint,className:"w-full sm:w-auto",children:s("modelManagement.addEndpoint")})]})}),e.jsx(Fs,{activeTab:t.activeTab,activeTabInfo:t.activeTabInfo,customEndpoints:t.customEndpoints,customTabs:t.customTabs,isDirtyByEndpoint:t.isDirtyByEndpoint,onDeleteEndpoint:t.setConfirmAction,onEditEndpoint:t.handleOpenEditEndpoint,onSelectTab:t.setActiveTab,providerCount:t.providerCount,systemTabs:t.systemTabs}),t.activeTab==="providers"?e.jsx(qs,{configPending:t.configQuery.isPending||!t.config&&t.configQuery.isFetching,configFetching:t.configQuery.isFetching,defaultLabels:t.defaultLabels,filteredProviders:t.filteredProviders,onOpenCreate:t.handleOpenCreate,onOpenEdit:t.handleOpenEdit,onRefresh:()=>void t.configQuery.refetch(),onRequestDelete:m=>t.setConfirmAction({kind:"provider",provider:m}),onResetFilters:()=>{t.setProviderSearch(""),t.setProviderTypeFilter("all")},onProviderSearchChange:t.setProviderSearch,onProviderTypeChange:t.setProviderTypeFilter,onTestConnection:t.initiateTestConnection,providerCount:t.providerCount,providerSearch:t.providerSearch,providerTypeFilter:t.providerTypeFilter,providersLength:t.providers.length,testingProviderId:t.testingProviderId}):e.jsx(Gs,{endpoint:t.activeTab,applyingPreset:((a=t.applyingPreset)==null?void 0:a.endpoint)===t.activeTab?t.applyingPreset.name:null,config:t.config,customEndpoints:t.customEndpoints,deletingPreset:((o=t.deletingPreset)==null?void 0:o.endpoint)===t.activeTab?t.deletingPreset.name:null,isDirty:t.isDirtyByEndpoint[t.activeTab]??!1,onAddRoute:()=>t.handleAddRoute(t.activeTab),onAddSuggestion:m=>t.handleAddSuggestion(t.activeTab,m),onPresetNameChange:m=>t.handlePresetNameChange(t.activeTab,m),onRequestDeletePreset:m=>t.setConfirmAction({kind:"preset",endpoint:t.activeTab,preset:m}),onRequestPresetDiff:m=>t.setPresetDiffDialog({endpoint:t.activeTab,preset:m}),onRemoveRoute:m=>t.handleRemoveRoute(t.activeTab,m),onResetRoutes:()=>t.handleResetRoutes(t.activeTab),onRouteChange:(m,u,h)=>t.handleRouteChange(t.activeTab,m,u,h),onSavePreset:()=>void t.handleSavePreset(t.activeTab),onSaveRoutes:()=>void t.handleSaveRoutes(t.activeTab),onToggleClaudeValidation:m=>void t.handleToggleClaudeValidation(t.activeTab,m),onTogglePresetsExpanded:()=>t.setPresetsExpanded(m=>({...m,[t.activeTab]:!m[t.activeTab]})),presetError:t.presetErrorByEndpoint[t.activeTab],presetName:t.presetNameByEndpoint[t.activeTab]??"",presets:t.presetsByEndpoint[t.activeTab]??[],presetsExpanded:t.presetsExpanded[t.activeTab]===!0,providerModelOptions:t.providerModelOptions,routeError:t.routeError[t.activeTab],routes:t.routesByEndpoint[t.activeTab]||[],savingClaudeValidation:t.savingClaudeValidation,savingPreset:t.savingPresetFor===t.activeTab,savingRoute:t.savingRouteFor===t.activeTab,tabs:t.tabs}),e.jsx(Us,{open:t.drawerOpen,mode:t.drawerMode,provider:t.drawerMode==="edit"?t.editingProvider:void 0,existingProviderIds:t.providers.map(m=>m.id).filter(m=>t.drawerMode==="edit"&&t.editingProvider?m!==t.editingProvider.id:!0),onClose:()=>{t.setDrawerOpen(!1),t.setEditingProvider(void 0),t.setDrawerMode("create")},onSubmit:t.handleProviderSubmit}),e.jsx(Ls,{open:t.endpointDrawerOpen,endpoint:t.editingEndpoint,onClose:()=>{t.setEndpointDrawerOpen(!1),t.setEditingEndpoint(void 0)},onSuccess:()=>{t.configQuery.refetch()}}),e.jsx(Js,{open:t.testDialogOpen,provider:t.testDialogProvider,options:t.anthropicTestHeaderOptions,preservedExtras:t.testDialogPreservedExtras,usePreset:t.testDialogUsePreset,onPresetChange:t.setTestDialogUsePreset,onConfirm:t.confirmTestDialog,onClose:t.closeTestDialog}),e.jsx(Bs,{dialog:t.presetDiffDialog,currentRoutes:t.presetDiffDialog?t.routesByEndpoint[t.presetDiffDialog.endpoint]||[]:[],onConfirm:(m,u)=>{t.setPresetDiffDialog(null),t.handleApplyPreset(m,u)},onClose:()=>t.setPresetDiffDialog(null)}),e.jsx(js,{open:!!t.confirmAction,onOpenChange:m=>{!m&&!t.confirmingAction&&t.setConfirmAction(null)},title:t.confirmDialogTitle,description:t.confirmDialogDescription,confirmLabel:t.confirmingAction?s("common.actions.loading"):s("common.delete"),cancelLabel:s("common.actions.cancel"),loading:t.confirmingAction,onConfirm:t.handleConfirmDialog,children:t.confirmDialogName?e.jsx("div",{className:"rounded-[1rem] border border-destructive/20 bg-destructive/5 px-3 py-2 font-mono text-xs text-foreground",children:t.confirmDialogName}):null})]})}export{br as default};
1
+ import{r as N,j as e,a8 as Se,as as pt,at as Ne,q as hs,a1 as xt,aj as fs,al as bs,U as vs}from"./vendor-CjJPKsTb.js";import{u as Le,C as js}from"./useAppMutation-COEUmNH4.js";import{P as ys}from"./PageHeader-DWkUnwoU.js";import{c as oe,B as L,d as Ee,T as Ns,e as ws,f as Ms,g as ks,h as Re,b as Te,u as Cs,t as ot}from"./index-BiTh8byX.js";import{u as te}from"./i18n-CfLThlXq.js";import{I as fe}from"./input-CXrASgDm.js";import{L as J}from"./label-CzHv4dNP.js";import{S as gt,a as ht,b as ft,c as bt,d as me}from"./select-DH6I1mKJ.js";import{S as qe}from"./switch-IXq8M3lq.js";import{q as he}from"./queryKeys-BMvyDTQS.js";import{B as H}from"./badge-tREH_88e.js";import{C as Fe,a as Be}from"./card-yK3LQB_K.js";import{D as vt,A as jt,a as yt,b as Nt,c as wt,d as Mt,e as kt}from"./DialogShell-BKB8x8Yv.js";import{P as Es,a as Ss,b as Ps}from"./popover-C-WmNbKp.js";import{u as Ds,a as Rs}from"./query-D3IfCUhp.js";import{g as ye}from"./gateway-D-NOc-e6.js";import{u as Ts}from"./useApiQuery-CCy5_Mc8.js";import"./router-CmaL1NgV.js";import"./radix-54BMi3RD.js";function We(){return typeof globalThis.crypto<"u"&&typeof globalThis.crypto.randomUUID=="function"?globalThis.crypto.randomUUID():Math.random().toString(36).slice(2,10)}function Os(){return{_key:We(),id:"",label:""}}const Oe={openai:{baseUrl:"https://api.openai.com/v1"},deepseek:{baseUrl:"https://api.deepseek.com/v1"},huawei:{baseUrl:"https://api.modelarts-maas.com/v1"},kimi:{baseUrl:"https://api.moonshot.cn/v1"},anthropic:{baseUrl:"https://api.anthropic.com/v1"},custom:{}},dt=[{value:"openai",label:"OpenAI"},{value:"deepseek",label:"DeepSeek"},{value:"huawei",label:"Huawei Cloud"},{value:"kimi",label:"Kimi"},{value:"anthropic",label:"Anthropic"},{value:"custom",label:"Custom"}];function lt(s){return s?{id:s.id,label:s.label??s.id,baseUrl:s.baseUrl,apiKey:s.apiKey??"",type:s.type??"custom",defaultModel:s.defaultModel??"",models:(s.models??[]).map(t=>({...t,_key:We()})),authMode:s.authMode??"apiKey"}:{id:"",label:"",baseUrl:"",apiKey:"",type:"custom",defaultModel:"",models:[],authMode:"apiKey"}}function As(s){return{_key:We(),id:s.id,label:s.label}}function Us({open:s,mode:t,provider:c,existingProviderIds:g,onClose:d,onSubmit:x}){const{t:a}=te(),[o,m]=N.useState(()=>lt(c)),[u,h]=N.useState({}),[F,k]=N.useState(!1),[M,C]=N.useState(null),v=N.useRef(null),f=N.useRef(null),b=N.useRef(null),[j,Q]=N.useState(t==="edit");N.useEffect(()=>{s&&(m(lt(c)),h({}),C(null),k(!1),Q(t==="edit"))},[s,c,t]),N.useEffect(()=>{if(!s)return;const i=E=>{E.key==="Escape"&&d()};return window.addEventListener("keydown",i),()=>window.removeEventListener("keydown",i)},[s,d]),N.useEffect(()=>{if(s){if(t==="create"&&b.current){b.current.focus();return}f.current&&f.current.focus()}},[s,t]);const Y=t==="create",ue=N.useMemo(()=>o.models.filter(i=>i.id.trim().length>0),[o.models]),le=N.useMemo(()=>{var i;return((i=dt.find(E=>E.value===o.type))==null?void 0:i.label)??"Custom"},[o.type]),Z=o.label.trim()||o.id.trim()||a("providers.drawer.summary.untitled"),V=N.useMemo(()=>[{label:a("providers.drawer.summary.type"),value:le},{label:a("providers.drawer.summary.auth"),value:o.authMode==="apiKey"?a("providers.drawer.fields.authModeApiKey"):o.authMode==="authToken"?a("providers.drawer.fields.authModeAuthToken"):a("providers.drawer.fields.authModeXAuthToken")},{label:a("providers.drawer.summary.models"),value:ue.length.toLocaleString()}],[ue.length,o.authMode,le,a]),pe=i=>E=>{m(R=>({...R,[i]:E}))},G=i=>{m(E=>{const P=!j||E.label.trim().length===0||E.label===E.id?i:E.label;return{...E,id:i,label:P}})},we=i=>{m(E=>{var de;const P=Oe[i??"custom"]??Oe.custom,B=Object.values(Oe).map(re=>re.baseUrl).filter(re=>!!re),X=!E.baseUrl||B.includes(E.baseUrl),A=t==="create"&&(E.models.length===0||E.models.every(re=>re.id.trim().length===0)),q={...E,type:i,authMode:E.authMode??"apiKey"};return P!=null&&P.baseUrl&&X&&(q.baseUrl=P.baseUrl),P!=null&&P.models&&A&&(q.models=P.models.map(As),q.defaultModel=P.defaultModel??((de=P.models[0])==null?void 0:de.id)??""),q})},be=(i,E)=>{m(R=>{const P=[...R.models];return P[i]={...P[i],...E},{...R,models:P}})},T=(i,E)=>{m(R=>{const P=[...R.models],B=P[i];if(!B)return R;const X=!j||!B.label||B.label===B.id,A={...B,id:E,label:X?E:B.label};P[i]=A;const q=R.defaultModel===B.id?E:R.defaultModel;return{...R,models:P,defaultModel:q}})},I=i=>{m(E=>{if(i<0||i>=E.models.length)return E;const R=E.models.filter((B,X)=>X!==i);let P=E.defaultModel;return R.some(B=>B.id===P)||(P=""),{...E,models:R,defaultModel:P}})},Me=()=>{m(i=>({...i,models:[...i.models,Os()]}))},se=i=>{m(E=>({...E,authMode:i}))},xe=()=>{const i={},E=o.id.trim(),R=o.baseUrl.trim();if(t==="create"&&(E.length===0?i.id=a("providers.drawer.errors.idRequired"):g.includes(E)&&(i.id=a("providers.drawer.errors.idDuplicate"))),t==="edit"&&E.length===0&&(i.id=a("providers.drawer.errors.idRequired")),R.length===0)i.baseUrl=a("providers.drawer.errors.baseUrlInvalid");else try{new URL(R)}catch{i.baseUrl=a("providers.drawer.errors.baseUrlInvalid")}if(o.models.length>0){const P=new Set;o.models.some(X=>{const A=X.id.trim();return A.length===0||P.has(A)?!0:(P.add(A),!1)})&&(i.models=a("providers.drawer.errors.modelInvalid"))}return o.defaultModel&&!o.models.some(P=>P.id===o.defaultModel)&&(i.models=a("providers.drawer.errors.defaultInvalid")),h(i),Object.keys(i).length===0},ie=()=>{const i=o.models.map(P=>{var B;return{id:P.id.trim(),label:(B=P.label)!=null&&B.trim()?P.label.trim():void 0}}).filter(P=>P.id.length>0),E=c!=null&&c.extraHeaders&&Object.keys(c.extraHeaders).length>0?c.extraHeaders:void 0,R=o.authMode!=="apiKey"?o.authMode:void 0;return{id:o.id.trim(),label:o.label.trim()||o.id.trim(),baseUrl:o.baseUrl.trim(),apiKey:o.apiKey.trim()||void 0,type:o.type??"custom",defaultModel:o.defaultModel||void 0,models:i.length>0?i:void 0,extraHeaders:E,authMode:R}},ge=async()=>{if(C(null),!!xe()){k(!0);try{const i=ie();await x(i)}catch(i){C(a("providers.drawer.toast.saveFailure",{message:i instanceof Error?i.message:"unknown"})),k(!1);return}k(!1),d()}};return s?e.jsxs("div",{className:"fixed inset-0 z-50 flex",children:[e.jsx("div",{className:"flex-1 bg-background/80 backdrop-blur-sm",onClick:d,"aria-hidden":"true"}),e.jsxs("aside",{ref:v,role:"dialog","aria-modal":"true","aria-labelledby":"provider-drawer-title","aria-describedby":"provider-drawer-desc",className:"flex h-full w-full max-w-5xl flex-col border-l border-border bg-background shadow-lg",children:[e.jsxs("header",{className:"border-b border-border bg-secondary px-6 py-5",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"inline-flex rounded-full border border-primary/20 bg-primary/10 px-3 py-1 text-[11px] font-medium uppercase tracking-[0.18em] text-primary",children:a(Y?"providers.drawer.quickStart":"providers.drawer.editTitle")}),e.jsxs("div",{children:[e.jsx("h2",{id:"provider-drawer-title",className:"text-lg font-semibold tracking-[-0.02em]",children:a(Y?"providers.drawer.createTitle":"providers.drawer.editTitle")}),e.jsx("p",{id:"provider-drawer-desc",className:"text-sm text-muted-foreground",children:a("providers.drawer.description")})]})]}),e.jsx("button",{type:"button",ref:f,onClick:d,className:"rounded-full border border-border bg-card px-4 py-2 text-sm transition hover:border-primary/20 hover:bg-accent/50",children:a("common.actions.close")})]}),e.jsx("div",{className:"mt-4 grid gap-3 md:grid-cols-3",children:V.map(i=>e.jsxs("div",{className:"rounded-lg border border-border bg-card px-4 py-3",children:[e.jsx("p",{className:"text-[11px] font-medium uppercase tracking-[0.16em] text-muted-foreground",children:i.label}),e.jsx("p",{className:"mt-2 text-sm font-semibold text-foreground",children:i.value})]},i.label))})]}),e.jsxs("div",{className:"grid flex-1 overflow-hidden xl:grid-cols-[minmax(0,1fr)_280px]",children:[e.jsxs("div",{className:"overflow-y-auto px-6 py-5",children:[e.jsxs("section",{className:"space-y-5","aria-labelledby":"provider-type-fields",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("h3",{id:"provider-type-fields",className:"text-sm font-semibold",children:a("providers.drawer.sections.type")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a("providers.drawer.hints.type")})]}),e.jsx("div",{className:"grid gap-2 md:grid-cols-3",children:dt.map(i=>{var R;const E=i.value===o.type;return e.jsxs("button",{type:"button",onClick:()=>we(i.value),className:oe("rounded-2xl border px-4 py-3 text-left transition",E?"border-primary bg-primary/10 text-primary shadow-sm":"border-border bg-card text-foreground hover:border-primary/20 hover:bg-accent/50"),children:[e.jsx("div",{className:"text-sm font-semibold",children:i.label}),e.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:((R=Oe[i.value??"custom"])==null?void 0:R.baseUrl)??a("providers.drawer.hints.customProvider")})]},i.value??"custom")})})]}),e.jsxs("section",{className:"mt-8 space-y-4","aria-labelledby":"provider-basic-info",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("h3",{id:"provider-basic-info",className:"text-sm font-semibold",children:a("providers.drawer.sections.basic")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a("providers.drawer.hints.basic")})]}),e.jsx("button",{type:"button",onClick:()=>Q(i=>!i),className:"rounded-full border border-border bg-card px-3 py-1.5 text-xs transition hover:border-primary/20 hover:bg-accent/50",children:a(j?"providers.drawer.fields.hideAdvanced":"providers.drawer.fields.showAdvanced")})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs("label",{className:"flex flex-col gap-2 text-sm",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:a("providers.drawer.fields.id")}),e.jsx("input",{value:o.id,ref:b,onChange:i=>G(i.target.value),disabled:!Y,placeholder:a("providers.drawer.fields.idPlaceholder"),className:"h-10 rounded-md border border-input bg-background px-3 py-2 text-sm transition-all focus:border-primary/40 focus:outline-none focus:ring-2 focus:ring-ring disabled:bg-muted/60 disabled:text-muted-foreground","aria-invalid":!!u.id}),u.id?e.jsx("span",{className:"text-xs text-red-500",children:u.id}):null]}),e.jsxs("label",{className:"flex flex-col gap-2 text-sm",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:a("providers.drawer.fields.label")}),e.jsx("input",{value:o.label,onChange:i=>pe("label")(i.target.value),placeholder:a("providers.drawer.fields.labelPlaceholder"),className:"h-10 rounded-md border border-input bg-background px-3 py-2 text-sm transition-all focus:border-primary/40 focus:outline-none focus:ring-2 focus:ring-ring disabled:bg-muted/60 disabled:text-muted-foreground"})]})]}),e.jsxs("label",{className:"flex flex-col gap-2 text-sm",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:a("providers.drawer.fields.baseUrl")}),e.jsx("input",{value:o.baseUrl,onChange:i=>pe("baseUrl")(i.target.value),placeholder:a("providers.drawer.fields.baseUrlPlaceholder"),className:"h-10 rounded-md border border-input bg-background px-3 py-2 text-sm transition-all focus:border-primary/40 focus:outline-none focus:ring-2 focus:ring-ring disabled:bg-muted/60 disabled:text-muted-foreground","aria-invalid":!!u.baseUrl}),u.baseUrl?e.jsx("span",{className:"text-xs text-red-500",children:u.baseUrl}):null]})]}),e.jsxs("section",{className:"mt-8 space-y-4","aria-labelledby":"provider-auth-fields",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("h3",{id:"provider-auth-fields",className:"text-sm font-semibold",children:a("providers.drawer.sections.auth")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a("providers.drawer.hints.auth")})]}),e.jsxs("label",{className:"flex flex-col gap-2 text-sm",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:a("providers.drawer.fields.apiKey")}),e.jsx("input",{value:o.apiKey,onChange:i=>pe("apiKey")(i.target.value),placeholder:a("providers.drawer.fields.apiKeyPlaceholder"),className:"h-10 rounded-md border border-input bg-background px-3 py-2 text-sm transition-all focus:border-primary/40 focus:outline-none focus:ring-2 focus:ring-ring disabled:bg-muted/60 disabled:text-muted-foreground"})]}),e.jsxs("fieldset",{className:"grid gap-2 rounded-lg border border-border bg-card p-4 text-xs",children:[e.jsx("legend",{className:"px-1 text-muted-foreground",children:a("providers.drawer.fields.authMode")}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:a("providers.drawer.fields.authModeHint")}),e.jsxs("label",{className:"flex cursor-pointer items-start gap-3 rounded-xl border border-transparent px-3 py-2 transition hover:bg-primary/5",children:[e.jsx("input",{type:"radio",name:"provider-auth-mode",value:"apiKey",checked:o.authMode==="apiKey",onChange:()=>se("apiKey"),className:"mt-0.5"}),e.jsx("span",{children:a("providers.drawer.fields.authModeApiKey")})]}),e.jsxs("label",{className:"flex cursor-pointer items-start gap-3 rounded-xl border border-transparent px-3 py-2 transition hover:bg-primary/5",children:[e.jsx("input",{type:"radio",name:"provider-auth-mode",value:"authToken",checked:o.authMode==="authToken",onChange:()=>se("authToken"),className:"mt-0.5"}),e.jsx("span",{children:a("providers.drawer.fields.authModeAuthToken")})]}),e.jsxs("label",{className:"flex cursor-pointer items-start gap-3 rounded-xl border border-transparent px-3 py-2 transition hover:bg-primary/5",children:[e.jsx("input",{type:"radio",name:"provider-auth-mode",value:"xAuthToken",checked:o.authMode==="xAuthToken",onChange:()=>se("xAuthToken"),className:"mt-0.5"}),e.jsx("span",{children:a("providers.drawer.fields.authModeXAuthToken")})]})]})]}),e.jsxs("section",{className:"mt-8 space-y-4","aria-labelledby":"provider-model-fields",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("h3",{id:"provider-model-fields",className:"text-sm font-semibold",children:a("providers.drawer.fields.models")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a("providers.drawer.modelsDescription")})]}),e.jsx("button",{type:"button",onClick:Me,className:"rounded-full border border-border bg-card px-3 py-1.5 text-xs transition hover:border-primary/20 hover:bg-accent/50",children:a("providers.drawer.fields.addModel")})]}),u.models?e.jsx("p",{className:"text-xs text-red-500",children:u.models}):null,e.jsxs("div",{className:"space-y-4",children:[o.models.map((i,E)=>e.jsxs("div",{className:"rounded-lg border border-border bg-card p-4",children:[e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs("label",{className:"flex flex-col gap-2 text-sm",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:a("providers.drawer.fields.modelId")}),e.jsx("input",{value:i.id,onChange:R=>T(E,R.target.value),placeholder:a("providers.drawer.fields.modelIdPlaceholder"),className:"h-10 rounded-md border border-input bg-background px-3 py-2 text-sm transition-all focus:border-primary/40 focus:outline-none focus:ring-2 focus:ring-ring disabled:bg-muted/60 disabled:text-muted-foreground"})]}),j?e.jsxs("label",{className:"flex flex-col gap-2 text-sm",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:a("providers.drawer.fields.modelLabel")}),e.jsx("input",{value:i.label??"",onChange:R=>be(E,{label:R.target.value}),placeholder:a("providers.drawer.fields.modelLabelPlaceholder"),className:"h-10 rounded-md border border-input bg-background px-3 py-2 text-sm transition-all focus:border-primary/40 focus:outline-none focus:ring-2 focus:ring-ring disabled:bg-muted/60 disabled:text-muted-foreground"})]}):null]}),e.jsxs("div",{className:"mt-3 flex flex-wrap items-center justify-between gap-3 text-xs",children:[e.jsxs("label",{className:"flex items-center gap-2 text-muted-foreground",children:[e.jsx("input",{type:"radio",name:"defaultModel",value:i.id,checked:o.defaultModel===i.id,onChange:()=>m(R=>({...R,defaultModel:i.id})),disabled:i.id.trim().length===0}),a("providers.drawer.fields.setDefault")]}),e.jsx("button",{type:"button",className:"text-red-500 transition hover:text-red-600 disabled:cursor-not-allowed disabled:opacity-40",onClick:()=>I(E),disabled:o.models.length===0,children:a("providers.drawer.fields.removeModel")})]})]},i._key)),o.models.length===0?e.jsx("div",{className:"rounded-lg border border-amber-200 bg-amber-50/60 p-5 dark:border-amber-700/50 dark:bg-amber-900/20",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm font-semibold text-amber-900 dark:text-amber-200",children:a("providers.drawer.noModelsTitle")}),e.jsx("p",{className:"text-xs leading-relaxed text-amber-800 dark:text-amber-300",children:a("providers.drawer.noModelsHint",{providerId:o.id||"provider-id"})}),e.jsxs("div",{className:"rounded-md border border-border bg-secondary p-2.5",children:[e.jsx("p",{className:"mb-1.5 text-xs font-medium text-foreground",children:a("providers.drawer.routeExample")}),e.jsxs("code",{className:"block rounded-md border border-border bg-card px-2.5 py-1.5 font-mono text-xs text-foreground",children:['"claude-*": "',(o.id||"provider-id").trim()||"provider-id",':*"']})]})]})}):null]}),ue.length>1?e.jsx("div",{className:"text-xs text-muted-foreground",children:a("providers.drawer.defaultHint",{model:o.defaultModel||a("providers.card.noDefault")})}):null]})]}),e.jsx("aside",{className:"hidden border-l border-border bg-secondary px-5 py-5 xl:block",children:e.jsxs("div",{className:"sticky top-0 space-y-5",children:[e.jsxs("div",{className:"rounded-lg border border-border bg-card p-4",children:[e.jsx("p",{className:"text-[11px] font-medium uppercase tracking-[0.16em] text-muted-foreground",children:a("providers.drawer.formSummary")}),e.jsx("p",{className:"mt-2 text-base font-semibold",children:Z}),e.jsx("div",{className:"mt-4 space-y-3 text-sm",children:V.map(i=>e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsx("span",{className:"text-muted-foreground",children:i.label}),e.jsx("span",{className:"text-right font-medium",children:i.value})]},i.label))})]}),e.jsxs("div",{className:"rounded-lg border border-border bg-card p-4",children:[e.jsx("p",{className:"text-[11px] font-medium uppercase tracking-[0.16em] text-muted-foreground",children:a("providers.drawer.sections.checklist")}),e.jsxs("ul",{className:"mt-3 space-y-2 text-sm text-muted-foreground",children:[e.jsx("li",{children:a("providers.drawer.hints.checkUrl")}),e.jsx("li",{children:a("providers.drawer.hints.checkAuth")}),e.jsx("li",{children:a("providers.drawer.hints.checkModels")})]})]}),j&&e.jsxs("div",{className:"rounded-lg border border-primary/20 bg-accent p-4 text-sm text-foreground",children:[e.jsx("p",{className:"font-medium text-primary",children:a("providers.drawer.hints.advancedTitle")}),e.jsx("p",{className:"mt-2 text-xs text-muted-foreground",children:a("providers.drawer.hints.advancedBody")})]})]})})]}),e.jsxs("footer",{className:"flex items-center justify-between gap-3 border-t border-border bg-secondary px-6 py-4 text-sm",children:[e.jsx("div",{className:"flex flex-col text-xs text-red-500","aria-live":"polite",children:M?e.jsx("span",{children:M}):null}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{type:"button",onClick:d,className:"rounded-full border border-border bg-card px-4 py-2 transition hover:border-primary/20 hover:bg-accent/50",disabled:F,children:a("common.actions.cancel")}),e.jsx("button",{type:"button",onClick:ge,className:"rounded-full bg-primary px-5 py-2 text-primary-foreground shadow-[0_8px_20px_-12px_rgba(59,130,246,0.65)] transition hover:-translate-y-0.5 hover:bg-primary/95 disabled:opacity-60",disabled:F,children:a(F?"common.actions.saving":"common.actions.save")})]})]})]})]}):null}const $s=["anthropic","openai-auto","openai-chat","openai-responses"];function Ls({open:s,endpoint:t,onClose:c,onSuccess:g}){const{t:d}=te(),[x,a]=N.useState({id:"",label:"",paths:[{path:"",protocol:"openai-auto"}],enabled:!0});N.useEffect(()=>{if(t){const v=t.paths&&t.paths.length>0?t.paths:t.path&&t.protocol?[{path:t.path,protocol:t.protocol}]:[{path:"",protocol:"openai-auto"}];a({id:t.id,label:t.label,paths:v,enabled:t.enabled!==!1});return}a({id:"",label:"",paths:[{path:"",protocol:"openai-auto"}],enabled:!0})},[t,s]);const o=Le({mutationFn:Ee.create,invalidateKeys:[he.customEndpoints.all()],successToast:()=>({title:d("modelManagement.createEndpointSuccess")}),errorToast:v=>({title:d("modelManagement.createEndpointError",{error:v.message})}),onSuccess:async()=>{g(),c()}}),m=Le({mutationFn:v=>Ee.update(v.id,v.updates),invalidateKeys:[he.customEndpoints.all()],successToast:()=>({title:d("modelManagement.updateEndpointSuccess")}),errorToast:v=>({title:d("modelManagement.updateEndpointError",{error:v.message})}),onSuccess:async()=>{g(),c()}}),u=()=>{a(v=>({...v,paths:[...v.paths,{path:"",protocol:"anthropic"}]}))},h=v=>{x.paths.length!==1&&a(f=>({...f,paths:f.paths.filter((b,j)=>j!==v)}))},F=(v,f,b)=>{a(j=>{const Q=[...j.paths];return Q[v]={...Q[v],[f]:b},{...j,paths:Q}})},k=v=>{if(v==null||v.preventDefault(),!x.id.trim()||!x.label.trim())return;for(const b of x.paths)if(!b.path.trim())return;const f=x.paths.map(b=>({path:b.path.trim(),protocol:b.protocol}));if(t){m.mutate({id:t.id,updates:{label:x.label.trim(),paths:f,enabled:x.enabled}});return}o.mutate({id:x.id.trim(),label:x.label.trim(),paths:f,enabled:x.enabled})},M=o.isPending||m.isPending,C=x.paths.length===0?d("modelManagement.atLeastOnePath"):!x.id.trim()||!x.label.trim()?d("modelManagement.endpointValidationError"):x.paths.some(v=>!v.path.trim())?d("modelManagement.pathValidationError"):null;return s?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-40 bg-background/80 backdrop-blur-sm",onClick:c}),e.jsx("div",{className:"fixed inset-y-0 right-0 z-50 w-full max-w-md border-l border-border bg-background shadow-lg",children:e.jsxs("div",{className:"flex h-full flex-col",children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-border bg-secondary p-6",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("h2",{className:"text-lg font-semibold tracking-[-0.02em]",children:d(t?"modelManagement.editEndpoint":"modelManagement.createEndpoint")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t?t.id:d("modelManagement.endpointRoutingHint")})]}),e.jsx(L,{variant:"ghost",size:"sm",onClick:c,children:e.jsx(Se,{className:"h-4 w-4"})})]}),e.jsxs("form",{onSubmit:k,className:"flex-1 space-y-6 overflow-y-auto p-6",children:[e.jsxs("div",{className:"grid gap-3 rounded-lg border border-border bg-secondary 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:d("modelManagement.endpointId")}),e.jsx("p",{className:"truncate text-sm font-medium text-foreground",children:(t==null?void 0:t.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:d("modelManagement.endpointEnabled")}),e.jsx("p",{className:"text-sm font-medium text-foreground",children:x.enabled?d("common.status.enabled"):d("common.status.disabled")})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(J,{children:[d("modelManagement.endpointId")," ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(fe,{value:x.id,onChange:v=>a(f=>({...f,id:v.target.value})),placeholder:d("modelManagement.endpointIdPlaceholder"),disabled:!!t,required:!0}),e.jsx("p",{className:"text-xs text-muted-foreground",children:d("modelManagement.endpointIdHint")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(J,{children:[d("modelManagement.endpointLabel")," ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(fe,{value:x.label,onChange:v=>a(f=>({...f,label:v.target.value})),placeholder:d("modelManagement.endpointLabelPlaceholder"),required:!0})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(J,{children:[d("modelManagement.endpointPaths")," ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsxs(L,{type:"button",variant:"ghost",size:"sm",onClick:u,children:[e.jsx(pt,{className:"mr-1 h-3 w-3"}),d("modelManagement.addPath")]})]}),e.jsx("div",{className:"space-y-3",children:x.paths.map((v,f)=>e.jsxs("div",{className:"space-y-2 rounded-lg border border-border bg-card p-3",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(fe,{value:v.path,onChange:b=>F(f,"path",b.target.value),placeholder:d("modelManagement.endpointPathPlaceholder"),required:!0}),e.jsxs(gt,{value:v.protocol,onValueChange:b=>F(f,"protocol",b),children:[e.jsx(ht,{children:e.jsx(ft,{})}),e.jsx(bt,{children:$s.map(b=>e.jsx(me,{value:b,children:d(b==="anthropic"?"modelManagement.protocolAnthropic":b==="openai-auto"?"modelManagement.protocolOpenAI":b==="openai-chat"?"modelManagement.protocolOpenAIChat":"modelManagement.protocolOpenAIResponses")},b))})]})]}),x.paths.length>1?e.jsx(L,{type:"button",variant:"ghost",size:"sm",onClick:()=>h(f),className:"text-destructive",children:e.jsx(Se,{className:"h-4 w-4"})}):null]}),e.jsxs("div",{className:"space-y-1 text-xs text-muted-foreground",children:[f===0?e.jsx("p",{children:d("modelManagement.endpointPathHint")}):null,e.jsx("p",{children:d(`modelManagement.protocolHints.${v.protocol}`)})]})]},`${v.protocol}-${f}`))}),C?e.jsx("p",{className:"text-xs text-destructive",children:C}):null]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(qe,{id:"enabled",checked:x.enabled,onCheckedChange:v=>a(f=>({...f,enabled:v}))}),e.jsx(J,{htmlFor:"enabled",children:d("modelManagement.endpointEnabled")})]}),t?null:e.jsx("div",{className:"rounded-lg border border-primary/20 bg-accent p-4",children:e.jsx("p",{className:"text-sm text-blue-800 dark:text-blue-200",children:d("modelManagement.endpointRoutingHint")})})]}),e.jsxs("div",{className:"flex gap-3 border-t border-border bg-secondary p-6",children:[e.jsx(L,{variant:"outline",className:"flex-1",onClick:c,disabled:M,children:d("common.cancel")}),e.jsx(L,{className:"flex-1",onClick:()=>k(),disabled:M,children:d(M?"common.saving":t?"common.save":"common.create")})]})]})})]}):null}function Ke(s,t){return t(s==="anthropic"?"modelManagement.protocolAnthropic":s==="openai-chat"?"modelManagement.protocolOpenAIChat":s==="openai-responses"?"modelManagement.protocolOpenAIResponses":"modelManagement.protocolOpenAI")}function Fs({activeTab:s,activeTabInfo:t,customEndpoints:c,customTabs:g,isDirtyByEndpoint:d,onDeleteEndpoint:x,onEditEndpoint:a,onSelectTab:o,providerCount:m,systemTabs:u}){const{t:h}=te(),F=Object.values(d).filter(Boolean).length,k=u.length-1+g.length;return e.jsx(Fe,{className:"overflow-hidden",children:e.jsxs(Be,{className:"space-y-5 pt-5",children:[e.jsxs("div",{className:"flex flex-col gap-3 lg:flex-row lg:items-end lg:justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs(H,{variant:"outline",className:"border-primary/20 bg-accent text-primary",children:[h("modelManagement.tabs.providers")," · ",m]}),e.jsxs(H,{variant:"outline",children:[h("modelManagement.tabs.customEndpoint")," · ",g.length]}),F>0?e.jsx(H,{variant:"warning",children:h("modelManagement.overview.unsavedCount",{count:F})}):e.jsx(H,{variant:"success",children:h("modelManagement.overview.synced")})]}),e.jsx("p",{className:"text-sm font-semibold text-foreground",children:t==null?void 0:t.label}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t==null?void 0:t.description})]}),e.jsxs("div",{className:"flex w-full flex-col gap-3 sm:w-auto sm:flex-row sm:flex-wrap sm:items-center",children:[e.jsx("div",{className:"rounded-lg border border-border bg-secondary px-3 py-2 text-xs text-muted-foreground",children:g.length>0?h("modelManagement.overview.headerWithCustom"):h("modelManagement.overview.headerWithoutCustom")}),e.jsxs("div",{className:"rounded-lg border border-primary/20 bg-accent px-3 py-2 text-xs font-medium text-primary",children:[h("modelManagement.overview.routeWorkspacesStat")," · ",k]})]})]}),e.jsxs("div",{className:"grid gap-3 md:grid-cols-4",children:[e.jsx(Ae,{label:h("modelManagement.overview.providersStat"),value:m.toString(),helper:h("modelManagement.overview.providersStatHint")}),e.jsx(Ae,{label:h("modelManagement.overview.routeWorkspacesStat"),value:k.toString(),helper:h("modelManagement.overview.routeWorkspacesStatHint")}),e.jsx(Ae,{label:h("modelManagement.overview.customEndpointsStat"),value:g.length.toString(),helper:h("modelManagement.overview.customEndpointsStatHint")}),e.jsx(Ae,{label:h("modelManagement.overview.activeWorkspace"),value:(t==null?void 0:t.label)??"-",helper:h(s==="providers"?"modelManagement.overview.activeWorkspaceProvider":"modelManagement.overview.activeWorkspaceRouting")})]}),e.jsxs("div",{className:"grid gap-3 rounded-lg border border-border bg-secondary p-4 md:grid-cols-2",children:[e.jsx(it,{title:h("modelManagement.overview.resourceCardTitle"),description:h("modelManagement.overview.resourceCardDescription")}),e.jsx(it,{title:h("modelManagement.overview.entryCardTitle"),description:h("modelManagement.overview.entryCardDescription")})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsx("p",{className:"text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:h("modelManagement.overview.providerAndSystem")})}),e.jsx("div",{className:"grid gap-3 md:grid-cols-3",children:u.map(M=>{const C=s===M.key,v=M.key!=="providers"&&d[M.key];return e.jsxs("button",{type:"button",onClick:()=>o(M.key),className:oe("group flex min-h-[96px] flex-col justify-between rounded-lg border px-4 py-4 text-left transition-all",C?"border-primary/30 bg-accent":"border-border bg-card hover:border-primary/20 hover:bg-accent/50"),children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx("span",{className:oe("text-base font-semibold",C?"text-primary":"text-foreground"),children:M.label}),e.jsx("div",{className:"text-[11px] uppercase tracking-wider text-muted-foreground",children:M.key==="providers"?h("modelManagement.overview.providerPoolTag"):h("modelManagement.overview.systemEndpointTag")})]}),v?e.jsx("span",{className:"mt-1 h-2.5 w-2.5 rounded-full bg-amber-500"}):null]}),e.jsx("span",{className:"line-clamp-2 text-sm text-muted-foreground",children:M.description})]},M.key)})})]}),g.length>0?e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"flex items-center justify-between gap-3",children:e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:h("modelManagement.overview.customEndpoints")}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:h("modelManagement.overview.customEndpointsHint")})]})}),e.jsx("div",{className:"overflow-x-auto pb-1",children:e.jsx("div",{className:"flex min-w-full snap-x gap-3",children:g.map(M=>{var b;const C=s===M.key,v=d[M.key],f=c.find(j=>j.id===M.key);return e.jsxs("div",{className:oe("group relative flex w-[260px] shrink-0 snap-start flex-col gap-3 rounded-lg border px-4 py-4 text-left transition-all",C?"border-primary/30 bg-accent":"border-border bg-card hover:border-primary/20 hover:bg-accent/50"),children:[e.jsxs("button",{type:"button",onClick:()=>o(M.key),className:"min-w-0 flex-1 text-left",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:oe("truncate text-base font-semibold",C?"text-primary":"text-foreground"),children:M.label}),v?e.jsx("span",{className:"h-2 w-2 rounded-full bg-amber-500"}):null]}),e.jsx("p",{className:"mt-1 line-clamp-2 text-sm text-muted-foreground",children:M.description})]}),e.jsxs("div",{className:"grid gap-2 sm:flex sm:items-start",children:[e.jsx(L,{variant:"ghost",size:"sm",className:"h-7 w-full px-2 text-xs sm:w-auto",disabled:!f,onClick:()=>{f&&a(f)},children:h("common.edit")}),M.canDelete?e.jsx("button",{type:"button",onClick:j=>{j.stopPropagation(),f&&x({kind:"endpoint",endpoint:f})},className:"flex h-7 w-full items-center justify-center rounded-full border border-transparent text-muted-foreground transition hover:border-destructive/20 hover:bg-destructive/10 hover:text-destructive sm:w-7",title:h("common.delete"),children:e.jsx(Se,{className:"h-3.5 w-3.5"})}):null]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[(M.protocols??[]).map(j=>e.jsx(H,{variant:"outline",className:"max-w-full truncate text-[11px]",children:Ke(j,h)},`${M.key}-${j}`)),e.jsx(H,{variant:(f==null?void 0:f.enabled)===!1?"secondary":"success",className:"text-[11px]",children:(f==null?void 0:f.enabled)===!1?h("modelManagement.overview.endpointDisabled"):h("modelManagement.overview.endpointEnabled")})]}),f!=null&&f.paths&&f.paths.length>0?e.jsxs("div",{className:"space-y-1 rounded-lg border border-border bg-secondary px-3 py-2 text-[11px] text-muted-foreground",children:[f.paths.slice(0,2).map(j=>e.jsxs("div",{className:"truncate",children:[e.jsx("span",{className:"font-medium text-foreground",children:j.path})," · ",Ke(j.protocol,h)]},`${f.id}-${j.path}-${j.protocol}`)),f.paths.length>2?e.jsx("div",{children:h("modelManagement.overview.endpointMorePaths",{count:f.paths.length-2})}):null]}):f!=null&&f.path?e.jsxs("div",{className:"rounded-lg border border-border bg-secondary px-3 py-2 text-[11px] text-muted-foreground",children:[e.jsx("span",{className:"font-medium text-foreground",children:f.path})," · ",Ke(f.protocol??"anthropic",h)]}):null,e.jsx("div",{className:"rounded-lg border border-border bg-secondary px-3 py-2 text-[11px] text-muted-foreground",children:(b=M.protocols)!=null&&b.length?h("modelManagement.overview.endpointProtocols",{count:M.protocols.length}):h("modelManagement.overview.endpointNoProtocol")}),M.canDelete?null:e.jsx("div",{className:"text-[11px] text-muted-foreground",children:h("modelManagement.overview.endpointManagedExternally")})]},M.key)})})})]}):null]})})}function it({description:s,title:t}){return e.jsxs("div",{className:"rounded-lg border border-border bg-card px-4 py-3",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-wider text-muted-foreground",children:t}),e.jsx("p",{className:"mt-2 text-sm leading-6 text-foreground",children:s})]})}function Ae({helper:s,label:t,value:c}){return e.jsxs("div",{className:"rounded-lg border border-border bg-card px-4 py-3",children:[e.jsx("p",{className:"text-[11px] font-medium uppercase tracking-wider text-muted-foreground",children:t}),e.jsx("p",{className:"mt-2 truncate text-base font-semibold text-foreground",children:c}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:s})]})}function Bs({dialog:s,currentRoutes:t,onConfirm:c,onClose:g}){const{t:d}=te();if(!s)return null;const{endpoint:x,preset:a}=s,o=a.modelRoutes??{},m={};for(const C of t){const v=C.source.trim(),f=C.target.trim();v&&f&&(m[v]=f)}const u=new Set([...Object.keys(m),...Object.keys(o)]),h=[],F=[],k=[];for(const C of u){const v=C in m,f=C in o;f&&!v?h.push([C,o[C]]):v&&!f?F.push([C,m[C]]):v&&f&&m[C]!==o[C]&&k.push([C,m[C],o[C]])}const M=h.length>0||F.length>0||k.length>0;return e.jsx(vt,{open:!0,onOpenChange:C=>!C&&g(),children:e.jsxs(jt,{className:"max-w-2xl",children:[e.jsxs(yt,{children:[e.jsx(Nt,{children:d("modelManagement.presets.diffTitle")}),e.jsx(wt,{children:d("modelManagement.presets.diffDescription",{name:a.name})})]}),e.jsx(Mt,{children:M?e.jsxs("div",{className:"max-h-80 space-y-2 rounded-lg border border-border bg-secondary p-3 text-sm",children:[h.map(([C,v])=>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(H,{variant:"outline",className:"border-emerald-300 text-xs dark:border-emerald-700",children:d("modelManagement.presets.diffAdded")}),e.jsx("span",{className:"truncate",children:C}),e.jsx(Ne,{className:"h-3 w-3 flex-shrink-0"}),e.jsx("span",{className:"truncate",children:v})]},`add-${C}`)),F.map(([C,v])=>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(H,{variant:"outline",className:"border-red-300 text-xs dark:border-red-700",children:d("modelManagement.presets.diffRemoved")}),e.jsx("span",{className:"truncate",children:C}),e.jsx(Ne,{className:"h-3 w-3 flex-shrink-0"}),e.jsx("span",{className:"truncate",children:v})]},`rm-${C}`)),k.map(([C,v,f])=>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(H,{variant:"outline",className:"border-amber-300 text-xs dark:border-amber-700",children:d("modelManagement.presets.diffChanged")}),e.jsx("span",{className:"truncate",children:C}),e.jsx(Ne,{className:"h-3 w-3 flex-shrink-0"}),e.jsx("span",{className:"truncate line-through opacity-60",children:v}),e.jsx(Ne,{className:"h-3 w-3 flex-shrink-0"}),e.jsx("span",{className:"truncate",children:f})]},`chg-${C}`))]}):e.jsx("p",{className:"rounded-lg border border-border bg-secondary py-8 text-center text-sm text-muted-foreground",children:d("modelManagement.presets.diffEmpty")})}),e.jsxs(kt,{children:[e.jsx(L,{variant:"outline",onClick:g,children:d("common.cancel")}),e.jsx(L,{onClick:()=>c(x,a),disabled:!M,children:d("modelManagement.presets.diffConfirm")})]})]})})}function Ct({eyebrow:s,title:t,description:c,breadcrumb:g,aside:d}){return e.jsxs("div",{className:"flex flex-col gap-4 lg:flex-row lg:items-start lg:justify-between",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-[11px] font-semibold uppercase tracking-[0.18em] text-muted-foreground",children:[e.jsx("span",{children:s}),g.map((x,a)=>e.jsxs(hs.Fragment,{children:[a>0?e.jsx(xt,{className:"h-3.5 w-3.5"}):null,e.jsx("span",{className:oe(a===g.length-1&&"text-foreground"),children:x})]},`${x}-${a}`))]}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-semibold tracking-[-0.03em] text-foreground",children:t}),e.jsx("p",{className:"mt-1 max-w-3xl text-sm text-muted-foreground",children:c})]})]}),d?e.jsx("div",{className:"w-full shrink-0 lg:w-auto",children:d}):null]})}const Hs=["claude-sonnet-4-5-20250929","claude-sonnet-4-5-20250929-thinking","claude-sonnet-4-20250514","claude-opus-4-1-20250805","claude-opus-4-1-20250805-thinking","claude-haiku-4-5-20251001","claude-haiku-4-5-20251001-thinking","claude-3-5-haiku-20241022"],Is=["gpt-4o-mini","gpt-4o","o4-mini","o4-large","gpt-5-codex"];function ne(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():Math.random().toString(36).slice(2,10)}function Qe(s,t){var c;return(c=s==null?void 0:s.customEndpoints)!=null&&c.length?s.customEndpoints:t}function ze(s){return s?Object.entries(s).map(([t,c])=>({id:ne(),source:t,target:c})):[]}function Ve(s,t){var d,x,a;if(!s)return{};const c={},g=s.endpointRouting??{};c.anthropic=ze(((d=g.anthropic)==null?void 0:d.modelRoutes)??s.modelRoutes??{}),c.openai=ze(((x=g.openai)==null?void 0:x.modelRoutes)??{});for(const o of Qe(s,t))(a=o.routing)!=null&&a.modelRoutes?c[o.id]=ze(o.routing.modelRoutes):c[o.id]=[];return c}function ct(s,t,c){var x,a,o;const g=Qe(s,t).find(m=>m.id===c);if(g)return((x=g.routing)==null?void 0:x.modelRoutes)??{};const d=s.endpointRouting??{};return c==="anthropic"?((a=d.anthropic)==null?void 0:a.modelRoutes)??s.modelRoutes??{}:c==="openai"?((o=d.openai)==null?void 0:o.modelRoutes)??{}:{}}function Ks(s){const t={};for(const c of s){const g=c.source.trim(),d=c.target.trim();g&&d&&(t[g]=d)}return t}function mt(s,t){return JSON.stringify(Ks(s))!==JSON.stringify(t)}function zs(s,t){if(s==="anthropic")return!0;const c=t.find(g=>g.id===s);return c?c.paths&&c.paths.length>0?c.paths.some(g=>g.protocol==="anthropic"):c.protocol==="anthropic":!1}function Vs(s,t,c){var d,x,a;if(!t)return;if(s==="anthropic"||s==="openai")return(x=(d=t.endpointRouting)==null?void 0:d[s])==null?void 0:x.validation;const g=Qe(t,c).find(o=>o.id===s);return(a=g==null?void 0:g.routing)==null?void 0:a.validation}function _s(s,t){const c=[{key:"providers",label:s("modelManagement.tabs.providers"),description:s("modelManagement.tabs.providersDesc"),isSystem:!0,canDelete:!1},{key:"anthropic",label:s("modelManagement.tabs.anthropic"),description:s("modelManagement.tabs.anthropicDesc"),isSystem:!0,canDelete:!1,protocols:["anthropic"]},{key:"openai",label:s("modelManagement.tabs.openai"),description:s("modelManagement.tabs.openaiDesc"),isSystem:!0,canDelete:!1,protocols:["openai-auto","openai-chat","openai-responses"]}],g=t.map(d=>{let x=s("modelManagement.tabs.customEndpoint"),a=[];if(d.paths&&d.paths.length>0)x=`${s("modelManagement.tabs.customEndpoint")}: ${d.paths.map(o=>`${o.path} (${o.protocol})`).join(", ")}`,a=[...new Set(d.paths.map(o=>o.protocol))];else if(d.path){const o=d.protocol||"anthropic";x=`${s("modelManagement.tabs.customEndpoint")}: ${d.path} (${o})`,a=[o]}return{key:d.id,label:d.label||d.id,description:x,isSystem:!1,canDelete:d.deletable!==!1,protocols:a}});return[...c,...g]}function Et(s){return s.label&&s.label.trim().length>0?`${s.label} (${s.id})`:s.id}function qs({providerCount:s,providersLength:t,filteredProviders:c,defaultLabels:g,providerSearch:d,providerTypeFilter:x,configPending:a,configFetching:o,testingProviderId:m,onRefresh:u,onOpenCreate:h,onOpenEdit:F,onTestConnection:k,onRequestDelete:M,onProviderSearchChange:C,onProviderTypeChange:v,onResetFilters:f}){const{t:b}=te();return e.jsx(Fe,{children:e.jsxs(Be,{className:"space-y-6 pt-6",children:[e.jsx(Ct,{eyebrow:"Model Access",title:b("providers.title"),description:b("providers.description"),breadcrumb:[b("modelManagement.title"),b("modelManagement.tabs.providers")],aside:e.jsxs("div",{className:"flex w-full flex-wrap items-center gap-2 sm:w-auto sm:gap-3",children:[e.jsx(H,{variant:"secondary",children:b("providers.count",{count:s})}),e.jsxs(L,{variant:"outline",size:"sm",onClick:u,disabled:o,className:"w-full sm:w-auto",children:[e.jsx(fs,{className:oe("mr-2 h-4 w-4",o&&"animate-spin")}),b(o?"common.actions.refreshing":"providers.actions.refresh")]}),e.jsxs(L,{size:"sm",onClick:h,className:"w-full sm:w-auto",children:[e.jsx(pt,{className:"mr-2 h-4 w-4"}),b("providers.actions.add")]})]})}),e.jsxs("div",{className:"grid gap-3 md:grid-cols-3",children:[e.jsx(_e,{label:"Configured",value:s.toString(),helper:"Total providers in supply pool",tone:"blue"}),e.jsx(_e,{label:"Visible",value:c.length.toString(),helper:"Providers matching current filter",tone:"emerald"}),e.jsx(_e,{label:"Connection Status",value:m?"Testing":"Idle",helper:m?`Testing ${m}`:"Ready for diagnostics",tone:"amber"})]}),e.jsxs("div",{className:"rounded-lg border border-border bg-accent px-4 py-3 text-sm text-primary",children:[e.jsx("p",{className:"font-medium",children:b("modelManagement.providersSemantics.title")}),e.jsx("p",{className:"mt-1 leading-6 text-primary/80",children:b("modelManagement.providersSemantics.description")})]}),e.jsxs("div",{className:"grid gap-3 rounded-lg border border-border bg-secondary p-4 sm:grid-cols-2 xl:grid-cols-[minmax(0,1fr)_220px_auto]",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(J,{className:"text-[11px] uppercase tracking-[0.16em] text-muted-foreground",children:b("providers.filters.searchPlaceholder")}),e.jsx(fe,{value:d,onChange:j=>C(j.target.value),placeholder:b("providers.filters.searchPlaceholder")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(J,{className:"text-[11px] uppercase tracking-[0.16em] text-muted-foreground",children:b("providers.filters.typeAll")}),e.jsxs(gt,{value:x,onValueChange:v,children:[e.jsx(ht,{children:e.jsx(ft,{})}),e.jsxs(bt,{children:[e.jsx(me,{value:"all",children:b("providers.filters.typeAll")}),e.jsx(me,{value:"openai",children:"OpenAI"}),e.jsx(me,{value:"anthropic",children:"Anthropic"}),e.jsx(me,{value:"deepseek",children:"DeepSeek"}),e.jsx(me,{value:"huawei",children:"Huawei"}),e.jsx(me,{value:"kimi",children:"Kimi"}),e.jsx(me,{value:"custom",children:"Custom"})]})]})]}),e.jsx("div",{className:"flex items-end sm:col-span-2 xl:col-span-1",children:e.jsx(L,{variant:"ghost",size:"sm",onClick:f,disabled:!d.trim()&&x==="all",className:"w-full xl:w-auto",children:b("common.actions.reset")})})]}),a?e.jsx("div",{className:"flex min-h-[200px] items-center justify-center rounded-lg border border-border bg-secondary text-sm text-muted-foreground",children:b("common.loading")}):t===0?e.jsxs("div",{className:"rounded-lg border border-dashed border-border p-12 text-center text-sm text-muted-foreground",children:[e.jsx("p",{className:"font-medium",children:b("providers.emptyState")}),e.jsx("p",{className:"mt-2 text-xs",children:b("providers.emptyStateSub",{default:"点击上方按钮添加您的第一个提供商"})})]}):c.length===0?e.jsx("div",{className:"rounded-lg border border-dashed border-border p-12 text-center text-sm text-muted-foreground",children:e.jsx("p",{className:"font-medium",children:b("providers.emptyFiltered")})}):e.jsx("div",{className:"grid gap-4 [grid-template-columns:repeat(auto-fit,minmax(280px,1fr))]",children:c.map(j=>{var Q;return e.jsx(Fe,{className:"flex flex-col overflow-hidden","data-testid":"provider-card",children:e.jsxs(Be,{className:"flex flex-1 flex-col gap-4 pt-6",children:[e.jsxs("div",{className:"flex flex-col gap-4 sm:flex-row sm:items-start sm:justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h3",{className:"text-base font-semibold tracking-[-0.02em]",children:j.label||j.id}),j.type?e.jsx(Ws,{type:j.type}):null]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["ID: ",j.id]}),e.jsx("code",{className:"block max-w-full break-all rounded-lg border border-border bg-secondary px-2.5 py-1.5 text-[11px] text-muted-foreground",children:j.baseUrl})]}),j.defaultModel?e.jsx(H,{variant:"default",className:"text-xs",children:g.get(j.id)??j.defaultModel}):e.jsx(H,{variant:"secondary",className:"text-xs",children:b("providers.card.noDefault")})]}),e.jsxs("div",{className:"grid gap-2 sm:grid-cols-3",children:[e.jsx(Ce,{label:b("providers.card.authMode"),value:j.authMode==="authToken"?"Bearer":j.authMode==="xAuthToken"?"X-Auth-Token":"API Key"}),e.jsx(Ce,{label:b("providers.card.modelsTitle"),value:(Q=j.models)!=null&&Q.length?b("providers.card.modelCount",{count:j.models.length}):b("providers.card.passthrough")}),e.jsx(Ce,{label:b("providers.card.defaultModelLabel"),value:j.defaultModel?g.get(j.id)??j.defaultModel:b("providers.card.noDefault"),truncate:!0})]}),e.jsxs("div",{className:"grid gap-2 sm:grid-cols-2",children:[e.jsx(Ce,{label:"Routing readiness",value:j.defaultModel?"Ready":"Needs default"}),e.jsx(Ce,{label:"Endpoint type",value:j.type?j.type:"custom"})]}),e.jsxs("div",{className:"space-y-2 rounded-lg border border-border bg-secondary p-3",children:[e.jsx(J,{className:"text-xs uppercase tracking-[0.16em] text-muted-foreground",children:b("providers.card.modelsTitle")}),j.models&&j.models.length>0?e.jsx("div",{className:"flex max-h-24 flex-wrap gap-1 overflow-y-auto",children:j.models.map(Y=>e.jsx(H,{variant:"outline",className:"text-xs",children:Et(Y)},Y.id))}):e.jsx("p",{className:"text-xs text-muted-foreground",children:b("providers.card.noModels")})]}),e.jsxs("div",{className:"mt-auto grid gap-2 border-t border-border pt-4 sm:grid-cols-3",children:[e.jsx(L,{variant:"default",size:"sm",onClick:()=>F(j),className:"w-full",children:b("providers.actions.edit")}),e.jsx(L,{variant:"outline",size:"sm",onClick:()=>k(j),disabled:m===j.id,className:"w-full",children:m===j.id?b("common.actions.testingConnection"):b("providers.actions.test")}),e.jsx(L,{variant:"destructive",size:"sm",onClick:()=>M(j),className:"w-full",children:b("providers.actions.delete")})]})]})},j.id)})})]})})}function _e({helper:s,label:t,value:c}){return e.jsxs("div",{className:"rounded-lg border border-border bg-card px-4 py-3",children:[e.jsx("p",{className:"text-[11px] font-medium uppercase tracking-wider text-muted-foreground",children:t}),e.jsx("p",{className:"mt-2 text-base font-semibold text-foreground",children:c}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:s})]})}function Ce({label:s,value:t,truncate:c}){return e.jsxs("div",{className:"rounded-lg border border-border bg-secondary px-3 py-2",children:[e.jsx("p",{className:"text-[11px] font-medium uppercase tracking-[0.16em] text-muted-foreground",children:s}),e.jsx("p",{className:oe("mt-1 text-sm font-medium",c&&"truncate"),children:t})]})}function Ws({type:s}){const t={openai:{label:"OpenAI",variant:"success"},deepseek:{label:"DeepSeek",variant:"info"},huawei:{label:"华为云",variant:"warning"},kimi:{label:"Kimi",variant:"purple"},anthropic:{label:"Anthropic",variant:"pink"},custom:{label:"Custom",variant:"secondary"}},{label:c,variant:g}=t[s]||t.custom;return e.jsx(H,{variant:g,className:"text-xs",children:c})}function Qs({value:s,onChange:t,options:c,disabled:g,placeholder:d}){const{t:x}=te(),[a,o]=N.useState(!1),[m,u]=N.useState(""),h=N.useMemo(()=>{if(!m.trim())return c;const k=m.toLowerCase();return c.filter(M=>M.label.toLowerCase().includes(k)||M.value.toLowerCase().includes(k))},[c,m]),F=k=>{t(k),u(""),o(!1)};return e.jsxs(Es,{open:a,onOpenChange:k=>{o(k),k&&u("")},children:[e.jsx(Ss,{asChild:!0,children:e.jsx(fe,{value:s,onChange:k=>{t(k.target.value),u(k.target.value),a||o(!0)},onFocus:()=>{u(""),o(!0)},onClick:()=>{a||o(!0)},placeholder:d,disabled:g,autoComplete:"off"})}),e.jsx(Ps,{className:"max-h-60 w-[var(--radix-popover-trigger-width)] overflow-y-auto p-1",align:"start",onOpenAutoFocus:k=>k.preventDefault(),children:h.length===0?e.jsx("div",{className:"px-2 py-3 text-center text-xs text-muted-foreground",children:x("common.noMatches")}):h.map(k=>e.jsx("button",{type:"button",className:oe("flex w-full items-center rounded-sm px-2 py-1.5 text-left text-sm hover:bg-accent",k.value===s.trim()&&"bg-accent"),onMouseDown:M=>{M.preventDefault(),F(k.value)},children:e.jsx("span",{className:"truncate",children:k.label})},k.value))})]})}function Gs({endpoint:s,tabs:t,customEndpoints:c,config:g,routes:d,routeError:x,savingRoute:a,isDirty:o,presets:m,presetName:u,presetError:h,savingPreset:F,applyingPreset:k,deletingPreset:M,presetsExpanded:C,savingClaudeValidation:v,providerModelOptions:f,onTogglePresetsExpanded:b,onPresetNameChange:j,onSavePreset:Q,onRequestPresetDiff:Y,onRequestDeletePreset:ue,onToggleClaudeValidation:le,onRouteChange:Z,onRemoveRoute:V,onAddSuggestion:pe,onAddRoute:G,onResetRoutes:we,onSaveRoutes:be}){var B,X;const{t:T}=te(),I=t.find(A=>A.key===s),se=((B=I==null?void 0:I.protocols)==null?void 0:B.includes("anthropic"))??s==="anthropic"?Hs:Is,xe=(I==null?void 0:I.label)??s,ie=(I==null?void 0:I.isSystem)===!1?I.description:T(`settings.routing.descriptionByEndpoint.${s}`),ge=`route-source-${s}`,i=zs(s,c),E=Vs(s,g,c),R=i&&(E==null?void 0:E.mode)==="claude-code",P=new Set(d.map(A=>A.source.trim()).filter(Boolean));return e.jsx(Fe,{children:e.jsxs(Be,{className:"space-y-6 pt-6",children:[e.jsx(Ct,{eyebrow:"Routing Workspace",title:T("settings.routing.titleByEndpoint",{endpoint:xe}),description:ie,breadcrumb:[T("modelManagement.title"),xe],aside:e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs(H,{variant:"outline",children:[d.length," rules"]}),o?e.jsx(H,{variant:"outline",className:"border-amber-300 text-amber-700 dark:border-amber-700 dark:text-amber-300",children:T("modelManagement.actions.unsaved")}):e.jsx(H,{variant:"secondary",children:T("common.status.success")})]})}),e.jsxs("div",{className:"grid gap-3 md:grid-cols-4",children:[e.jsx(Ue,{label:"Rules",value:d.length.toString(),helper:"Current model routes",tone:"blue"}),e.jsx(Ue,{label:"Presets",value:m.length.toString(),helper:"Reusable routing templates",tone:"emerald"}),e.jsx(Ue,{label:"Protocols",value:(((X=I==null?void 0:I.protocols)==null?void 0:X.length)??0).toString(),helper:"Bound to this endpoint",tone:"amber"}),e.jsx(Ue,{label:"Validation",value:i?R?"Claude Code":"Disabled":"Standard",helper:i?"Anthropic compatibility mode":"Default endpoint routing",tone:"rose"})]}),e.jsx("div",{className:"rounded-lg border border-border bg-secondary px-4 py-3 text-xs text-muted-foreground",children:T("settings.routing.wildcardHint")}),i?e.jsx("div",{className:"rounded-lg border border-primary/20 bg-accent p-4",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",children:T("modelManagement.claudeValidation.title")}),e.jsx("p",{className:"text-xs text-primary/80",children:T("modelManagement.claudeValidation.description")})]}),e.jsxs("div",{className:"flex items-center gap-2 self-start sm:self-auto",children:[e.jsx(qe,{checked:R,onCheckedChange:le,disabled:v}),e.jsx("span",{className:oe("text-xs font-medium",R?"text-emerald-600 dark:text-emerald-400":"text-muted-foreground"),children:T(R?"modelManagement.claudeValidation.statusEnabled":"modelManagement.claudeValidation.statusDisabled")})]})]})}):null,x?e.jsx("p",{className:"text-sm text-destructive",children:x}):null,e.jsxs("div",{className:"space-y-3 rounded-lg border border-border bg-secondary 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(J,{className:"text-sm font-semibold text-foreground",children:T("modelManagement.routesEditorTitle")}),e.jsxs(H,{variant:"outline",children:[d.length," active"]})]}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:T("modelManagement.overview.routesEditorHint")})]}),e.jsxs("div",{className:"self-start rounded-lg border border-border bg-card px-3 py-2 text-[11px] text-muted-foreground",children:[xe," workspace"]})]}),d.length===0?e.jsxs("div",{className:"rounded-lg border border-dashed border-border p-12 text-center text-sm text-muted-foreground",children:[e.jsx("p",{className:"font-medium",children:T("settings.routing.empty")}),e.jsx("p",{className:"mt-2 text-xs",children:T("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:T("settings.routing.source")}),e.jsx("span",{}),e.jsx("span",{children:T("settings.routing.target")}),e.jsx("span",{})]}),d.map((A,q)=>e.jsxs("div",{className:"rounded-lg border border-border bg-card p-3",children:[e.jsxs("div",{className:"mb-3 flex items-center justify-between md:hidden",children:[e.jsxs(H,{variant:"outline",className:"text-[11px]",children:["#",q+1]}),e.jsx(L,{variant:"ghost",size:"icon",className:"h-8 w-8 text-muted-foreground hover:text-destructive",onClick:()=>V(A.id),disabled:a,children:e.jsx(Se,{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(J,{className:"text-[11px] uppercase tracking-[0.16em] text-muted-foreground md:hidden",children:T("settings.routing.source")}),e.jsx(fe,{value:A.source,onChange:de=>Z(A.id,"source",de.target.value),placeholder:T("settings.routing.sourcePlaceholder"),list:ge,disabled:a,"aria-label":`route-source-${q+1}`})]}),e.jsx(Ne,{className:"hidden h-4 w-4 flex-shrink-0 text-muted-foreground md:block"}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(J,{className:"text-[11px] uppercase tracking-[0.16em] text-muted-foreground md:hidden",children:T("settings.routing.target")}),e.jsx(Qs,{value:A.target,onChange:de=>Z(A.id,"target",de),options:f,disabled:a,placeholder:T("settings.routing.targetPlaceholder")})]}),e.jsx(L,{variant:"ghost",size:"icon",className:"hidden h-8 w-8 text-muted-foreground hover:text-destructive md:inline-flex",onClick:()=>V(A.id),disabled:a,children:e.jsx(Se,{className:"h-4 w-4"})})]})]},A.id))]})]}),e.jsxs("div",{className:"space-y-3 rounded-lg border border-border bg-secondary p-4",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(J,{className:"text-sm font-semibold text-foreground",children:T("settings.routing.suggested")}),e.jsxs(H,{variant:"outline",children:[se.length," presets"]})]}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:T("modelManagement.overview.suggestionHint")})]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:se.map(A=>{const q=P.has(A);return e.jsx(L,{variant:q?"ghost":"outline",size:"sm",onClick:()=>pe(A),disabled:a||q,className:q?"opacity-50":"",children:A},`${s}-${A}`)})})]}),e.jsxs("div",{className:"flex flex-col gap-3 rounded-lg border border-border bg-card p-4 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:T("modelManagement.actions.footerTitle")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:T(o?"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(L,{variant:"outline",size:"sm",onClick:G,disabled:a,className:"w-full",children:T("settings.routing.add")}),e.jsx(L,{variant:"outline",size:"sm",onClick:we,disabled:a||!o,className:"w-full",children:T("common.actions.reset")}),e.jsxs(L,{size:"sm",onClick:be,disabled:a,className:"relative w-full",children:[T(a?"common.actions.saving":"modelManagement.actions.saveRoutes"),o?e.jsx("span",{className:"absolute -right-1 -top-1 h-2 w-2 rounded-full bg-amber-500"}):null]})]})]}),e.jsx(Xs,{presets:m,presetName:u,presetError:h,savingPreset:F,applyingPreset:k,deletingPreset:M,expanded:C,onToggleExpanded:b,onPresetNameChange:j,onSavePreset:Q,onRequestPresetDiff:Y,onRequestDeletePreset:ue}),e.jsx("datalist",{id:ge,children:se.map(A=>e.jsx("option",{value:A},`${ge}-${A}`))})]})})}function Ue({helper:s,label:t,value:c}){return e.jsxs("div",{className:"rounded-lg border border-border bg-card px-4 py-3",children:[e.jsx("p",{className:"text-[11px] font-medium uppercase tracking-wider text-muted-foreground",children:t}),e.jsx("p",{className:"mt-2 truncate text-base font-semibold text-foreground",children:c}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:s})]})}function Xs({presets:s,presetName:t,presetError:c,savingPreset:g,applyingPreset:d,deletingPreset:x,expanded:a,onToggleExpanded:o,onPresetNameChange:m,onSavePreset:u,onRequestPresetDiff:h,onRequestDeletePreset:F}){const{t:k}=te();return e.jsxs("div",{className:"rounded-lg border border-dashed border-border bg-card",children:[e.jsx("button",{type:"button",className:"flex w-full items-center justify-between gap-3 p-4 text-left transition-colors hover:bg-primary/5",onClick:o,children:e.jsxs("div",{className:"flex items-center gap-2",children:[a?e.jsx(bs,{className:"h-4 w-4"}):e.jsx(xt,{className:"h-4 w-4"}),e.jsx("h3",{className:"font-medium",children:k("modelManagement.presets.title")}),e.jsx(H,{variant:"secondary",className:"text-xs",children:s.length})]})}),a?e.jsxs("div",{className:"space-y-4 border-t px-4 pb-4 pt-3",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:k("modelManagement.presets.description")}),e.jsxs("div",{className:"flex flex-col gap-3 md:flex-row md:items-center",children:[e.jsx(fe,{value:t,onChange:M=>m(M.target.value),placeholder:k("modelManagement.presets.namePlaceholder"),disabled:g,className:"w-full md:w-48"}),e.jsx(L,{onClick:u,disabled:g,className:"w-full md:w-auto",children:k(g?"modelManagement.presets.saving":"modelManagement.presets.save")})]}),c?e.jsx("p",{className:"text-sm text-destructive",children:c}):null,s.length===0?e.jsx("p",{className:"py-4 text-center text-sm text-muted-foreground",children:k("modelManagement.presets.empty")}):e.jsx(Ns,{children:e.jsx("div",{className:"grid gap-2 sm:grid-cols-2 lg:grid-cols-3",children:s.map(M=>{const C=d===M.name,v=x===M.name,f=Object.entries(M.modelRoutes??{}),b=f.length;return e.jsxs("div",{className:"flex flex-col gap-3 rounded-lg border border-border bg-secondary px-4 py-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs(ws,{children:[e.jsx(Ms,{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:M.name}),e.jsx(H,{variant:"outline",className:"mt-1 text-xs",children:b>0?k("modelManagement.presets.rulesCount",{count:b}):k("modelManagement.presets.noRules")})]})}),b>0?e.jsx(ks,{side:"bottom",className:"max-w-xs",children:e.jsxs("div",{className:"space-y-1 text-xs",children:[f.slice(0,5).map(([j,Q])=>e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"truncate",children:j}),e.jsx(Ne,{className:"h-3 w-3 flex-shrink-0"}),e.jsx("span",{className:"truncate",children:Q})]},j)),b>5?e.jsxs("div",{className:"text-muted-foreground",children:["…+",b-5]}):null]})}):null]}),e.jsxs("div",{className:"grid flex-shrink-0 gap-2 sm:flex sm:items-center",children:[e.jsx(L,{size:"sm",onClick:()=>h(M),disabled:C||v,className:"w-full sm:w-auto",children:k(C?"modelManagement.presets.applying":"modelManagement.presets.apply")}),e.jsx(L,{variant:"destructive",size:"sm",onClick:()=>F(M),disabled:v||C,className:"w-full sm:w-auto",children:k(v?"modelManagement.presets.deleting":"modelManagement.presets.delete")})]})]},M.name)})})})]}):null]})}function Js({open:s,provider:t,options:c,usePreset:g,preservedExtras:d,onPresetChange:x,onConfirm:a,onClose:o}){const{t:m}=te();return t?e.jsx(vt,{open:s,onOpenChange:u=>!u&&o(),children:e.jsxs(jt,{className:"max-w-2xl",children:[e.jsxs(yt,{children:[e.jsx(Nt,{children:m("providers.testDialog.title")}),e.jsx(wt,{children:m("providers.testDialog.subtitle",{name:t.label||t.id})})]}),e.jsxs(Mt,{className:"space-y-4",children:[e.jsx("div",{className:"rounded-lg border border-primary/20 bg-accent p-4 text-sm text-primary",children:m("providers.testDialog.description")}),e.jsxs("div",{className:"space-y-4 rounded-lg border border-border bg-secondary p-4",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(J,{htmlFor:"provider-test-preset",children:m("providers.testDialog.presetLabel")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:m("providers.testDialog.presetDescription")})]}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(qe,{id:"provider-test-preset",checked:g,onCheckedChange:x})})]}),g?e.jsx("div",{className:"space-y-2",children:e.jsxs("details",{className:"rounded-lg border border-border bg-secondary p-2 text-xs",children:[e.jsx("summary",{className:"cursor-pointer text-primary hover:underline",children:m("providers.testDialog.presetPreviewSummary")}),e.jsx("div",{className:"mt-2 space-y-1",children:c.map(u=>e.jsxs("code",{className:"block rounded-md border border-border bg-card px-2 py-1 text-xs",children:[u.key,": ",u.value]},u.key))})]})}):e.jsx("p",{className:"text-xs text-muted-foreground",children:m("providers.testDialog.presetDescription")})]}),Object.keys(d).length>0&&e.jsxs("div",{className:"space-y-2 rounded-lg border border-border bg-secondary p-4 text-xs",children:[e.jsx("p",{className:"font-medium",children:m("providers.testDialog.preservedInfo")}),Object.entries(d).map(([u,h])=>e.jsxs("code",{className:"block rounded-md border border-border bg-card px-2 py-1",children:[u,": ",h]},u))]})]}),e.jsxs(kt,{children:[e.jsx(L,{variant:"outline",onClick:o,children:m("providers.testDialog.cancel")}),e.jsx(L,{onClick:()=>void a(),children:m("providers.testDialog.primary")})]})]})}):null}const $e={savePreset(s,t){return Re(Te.post(`/api/routing-presets/${s}`,{name:t}))},applyPreset(s,t){return Re(Te.post(`/api/routing-presets/${s}/apply`,{name:t}))},deletePreset(s,t){return Re(Te.delete(`/api/routing-presets/${s}/${encodeURIComponent(t)}`))},testProvider(s,t){return Re(Te.post(`/api/providers/${s}/test`,t))}};function ut(s,t){var g,d,x;const c={anthropic:((g=s.routingPresets)==null?void 0:g.anthropic)??[],openai:((d=s.routingPresets)==null?void 0:d.openai)??[]};for(const a of t){const o=(x=s.customEndpoints)==null?void 0:x.find(m=>m.id===a.id);c[a.id]=(o==null?void 0:o.routingPresets)??a.routingPresets??[]}return c}function Ys(){var at;const{t:s}=te(),{pushToast:t}=Cs(),c=Ds(),g=Ts(he.config.full(),ye.configRequest()),x=((at=Rs({queryKey:he.customEndpoints.all(),queryFn:Ee.list,refetchInterval:1e4}).data)==null?void 0:at.endpoints)??[],a=N.useMemo(()=>_s(s,x),[x,s]),[o,m]=N.useState("providers"),[u,h]=N.useState(null),[F,k]=N.useState(!1),[M,C]=N.useState("create"),[v,f]=N.useState(void 0),[b,j]=N.useState(void 0),[Q,Y]=N.useState(null),[ue,le]=N.useState(!1),[Z,V]=N.useState({}),[pe,G]=N.useState({}),[we,be]=N.useState(null),[T,I]=N.useState({}),[Me,se]=N.useState({}),[xe,ie]=N.useState({}),[ge,i]=N.useState(null),[E,R]=N.useState(null),[P,B]=N.useState(null),[X,A]=N.useState(!1),[q,de]=N.useState(null),[re,He]=N.useState(!0),[Ge,Xe]=N.useState({}),[St,Je]=N.useState(!1),[Pt,Dt]=N.useState({}),[Rt,Tt]=N.useState(null),[S,Ye]=N.useState(null),[Ot,Ze]=N.useState(!1),[Ie,At]=N.useState(""),[Pe,Ut]=N.useState("all"),$t=N.useMemo(()=>a.filter(r=>r.isSystem),[a]),Lt=N.useMemo(()=>a.filter(r=>!r.isSystem),[a]),Ft=N.useMemo(()=>a.find(r=>r.key===o)??a[0]??null,[o,a]),ee=(u==null?void 0:u.providers)??[],Bt=ee.length,Ht=N.useMemo(()=>ee.filter(r=>{var w;if(!(Pe==="all"||(r.type??"custom")===Pe))return!1;const n=Ie.trim().toLowerCase();return n?[r.id,r.label??"",r.baseUrl,r.defaultModel??"",...((w=r.models)==null?void 0:w.map(y=>y.id))??[]].join(" ").toLowerCase().includes(n):!0}),[Ie,Pe,ee]),ke=N.useMemo(()=>[{key:"anthropic-beta",value:"claude-code-20250219,interleaved-thinking-2025-05-14,fine-grained-tool-streaming-2025-05-14",label:s("providers.testDialog.options.beta.label"),description:s("providers.testDialog.options.beta.description")}],[s]);N.useEffect(()=>{if(!g.data)return;const r=g.data;h(r),V(l=>{const n=Ve(r,x);if(!l||Object.keys(l).length===0)return n;const p={...n};for(const[w,y]of Object.entries(l)){if(!(w in n))continue;const D=ct(r,x,w);mt(y,D)&&(p[w]=y)}return p}),G({}),I(ut(r,x))},[g.data,x]),N.useEffect(()=>{!g.isError||!g.error||t({title:s("providers.toast.loadFailure",{message:g.error.message}),variant:"error"})},[g.error,g.isError,t,s]),N.useEffect(()=>{a.some(r=>r.key===o)||m("providers")},[o,a]);const It=N.useMemo(()=>{const r=new Map;for(const l of ee){if(!l.defaultModel||!l.models)continue;const n=l.models.find(p=>p.id===l.defaultModel);n&&r.set(l.id,Et(n))}return r},[ee]),Kt=N.useMemo(()=>{const r=[],l=new Set;for(const n of ee){const p=n.label&&n.label!==n.id?`${n.label} (${n.id})`:n.id,w=n.models??[];if(w.length>0)for(const D of w){const $=`${n.id}:${D.id}`;l.has($)||(l.add($),r.push({value:$,label:`${p} · ${D.label??D.id}`}))}else if(n.defaultModel){const D=`${n.id}:${n.defaultModel}`;l.has(D)||(l.add(D),r.push({value:D,label:`${p} · ${n.defaultModel}`}))}const y=`${n.id}:*`;l.has(y)||(l.add(y),r.push({value:y,label:s("settings.routing.providerPassthroughOption",{provider:p})}))}for(const n of Object.values(Z).flat()){const p=n.target.trim();p&&!l.has(p)&&(l.add(p),r.push({value:p,label:p}))}return r},[ee,Z,s]),zt=()=>{j(void 0),le(!0)},Vt=r=>{j(r),le(!0)},_t=r=>u?ct(u,x,r):{},qt=N.useMemo(()=>{const r={};for(const l of a){if(l.key==="providers")continue;const n=Z[l.key]||[];r[l.key]=mt(n,_t(l.key))}return r},[u,x,Z,a]),et=(r,l)=>{I(n=>({...n,[r]:l})),h(n=>{if(!n)return n;if(r==="anthropic"||r==="openai")return{...n,routingPresets:{...n.routingPresets,[r]:l}};const p=[...n.customEndpoints??[]],w=p.findIndex(y=>y.id===r);return w===-1?n:(p[w]={...p[w],routingPresets:l},{...n,customEndpoints:p})})},ce=()=>u?!0:(t({title:s("settings.toast.missingConfig"),variant:"error"}),g.refetch(),!1),Wt=(r,l)=>{se(n=>({...n,[r]:l})),l.trim()&&ie(n=>({...n,[r]:null}))},Qt=async r=>{if(!ce())return;const l=(Me[r]??"").trim();if(!l){ie(n=>({...n,[r]:s("modelManagement.validation.presetName")}));return}if((T[r]??[]).some(n=>n.name.toLowerCase()===l.toLowerCase())){ie(n=>({...n,[r]:s("modelManagement.validation.presetDuplicate",{name:l})}));return}i(r);try{const p=(await $e.savePreset(r,l)).presets??[];et(r,p),se(w=>({...w,[r]:""})),ie(w=>({...w,[r]:null})),t({title:s("modelManagement.toast.presetSaved",{name:l}),variant:"success"})}catch(n){t({title:s("modelManagement.toast.presetSaveFailure",{message:n instanceof Error?n.message:"unknown"}),variant:"error"})}finally{i(null),g.refetch()}},Gt=async(r,l)=>{if(ce()){R({endpoint:r,name:l.name});try{const p=(await $e.applyPreset(r,l.name)).config;if(p)h(p),V(Ve(p,x)),I(ut(p,x));else{const w=l.modelRoutes??{};V(y=>({...y,[r]:Object.entries(w).map(([D,$])=>({id:ne(),source:D,target:$}))})),h(y=>{var $,U,O,K;if(!y)return y;const D=(y.customEndpoints??[]).findIndex(z=>z.id===r);if(D!==-1){const z=[...y.customEndpoints??[]],ae=z[D];return z[D]={...ae,routing:{defaults:(($=ae.routing)==null?void 0:$.defaults)??y.defaults,...ae.routing??{},modelRoutes:w}},{...y,customEndpoints:z}}return r==="anthropic"||r==="openai"?{...y,endpointRouting:{...y.endpointRouting??{},[r]:{defaults:((O=(U=y.endpointRouting)==null?void 0:U[r])==null?void 0:O.defaults)??y.defaults,...((K=y.endpointRouting)==null?void 0:K[r])??{},modelRoutes:w}},modelRoutes:r==="anthropic"?w:y.modelRoutes??{}}:y})}r!=="anthropic"&&r!=="openai"&&await c.invalidateQueries({queryKey:he.customEndpoints.all()}),t({title:s("modelManagement.toast.presetApplySuccess",{name:l.name}),variant:"success"})}catch(n){t({title:s("modelManagement.toast.presetApplyFailure",{message:n instanceof Error?n.message:"unknown"}),variant:"error"})}finally{R(null),g.refetch()}}},Xt=async(r,l)=>{if(ce()){B({endpoint:r,name:l.name});try{const n=await $e.deletePreset(r,l.name);et(r,n.presets??[]),t({title:s("modelManagement.toast.presetDeleteSuccess",{name:l.name}),variant:"success"})}catch(n){t({title:s("modelManagement.toast.presetDeleteFailure",{message:n instanceof Error?n.message:"unknown"}),variant:"error"})}finally{B(null),g.refetch()}}},Jt=()=>{ce()&&(C("create"),f(void 0),k(!0))},Yt=r=>{ce()&&(C("edit"),f(r),k(!0))},Zt=async r=>{if(!u)throw new Error(s("settings.toast.missingConfig"));const l=M==="create"?[...ee,r]:ee.map(p=>v&&p.id===v.id?{...r,id:v.id}:p),n={...u,providers:l};await ye.saveConfig(n),h(n),V(Ve(n,x)),g.refetch(),t({title:M==="create"?s("providers.toast.createSuccess",{name:r.label||r.id}):s("providers.toast.updateSuccess",{name:r.label||r.id}),variant:"success"})},es=async r=>{const l=x.find(n=>n.id===r);if(!(!l||l.deletable===!1))try{await Ee.delete(r),await c.invalidateQueries({queryKey:he.customEndpoints.all()}),t({title:s("modelManagement.deleteEndpointSuccess"),variant:"success"}),o===r&&m("providers")}catch(n){const p=ot(n);t({title:s("modelManagement.deleteEndpointError",{error:p.message}),variant:"error"})}},tt=async(r,l)=>{Y(r.id);try{const n=l&&(l.headers||l.query)?{headers:l.headers&&Object.keys(l.headers).length>0?l.headers:void 0,query:l.query&&l.query.trim().length>0?l.query.trim():void 0}:void 0,p=await $e.testProvider(r.id,n);if(p.ok){t({title:s("providers.toast.testSuccess"),description:s("providers.toast.testSuccessDesc",{status:p.status,duration:p.durationMs?`${p.durationMs} ms`:"—"}),variant:"success"});return}t({title:s("providers.toast.testFailure",{message:`${p.status} ${p.statusText}`}),variant:"error"})}catch(n){t({title:s("providers.toast.testFailure",{message:n instanceof Error?n.message:"unknown"}),variant:"error"})}finally{Y(null)}},ts=r=>{if(r.type!=="anthropic"){tt(r);return}const l=r.extraHeaders??{},n=new Map(ke.map(y=>[y.key.toLowerCase(),y])),p={};let w=!0;for(const y of ke){const D=Object.entries(l).find(([O])=>O.toLowerCase()===y.key.toLowerCase());if(!D)continue;const[$,U]=D;String(U??"")!==y.value&&(w=!1,p[$]=String(U??""))}for(const[y,D]of Object.entries(l))n.has(y.toLowerCase())||(p[y]=String(D??""));Xe(p),He(w),de(r),A(!0)},st=()=>{A(!1),de(null),He(!0),Xe({})},ss=async()=>{if(!q)return;const r={};if(re)for(const p of ke)r[p.key]=p.value;const l=new Map(ke.map(p=>[p.key.toLowerCase(),p]));for(const[p,w]of Object.entries(Ge))l.get(p.toLowerCase())&&re||(r[p]=w);const n=q;st(),await tt(n,{headers:Object.keys(r).length>0?r:void 0,query:re?"beta=true":void 0})},rt=async r=>{var U,O,K,z,ae,De;if(!ce())return;const l=ee.filter(_=>_.id!==r.id),n=_=>{const W={};if(!_)return W;for(const[ve,je]of Object.entries(_)){if(!je)continue;const[nt]=je.split(":");nt&&nt===r.id||je===r.id||(W[ve]=je)}return W},p=(u==null?void 0:u.endpointRouting)??{},w=n(((U=p.anthropic)==null?void 0:U.modelRoutes)??(u==null?void 0:u.modelRoutes)??{}),y=n(((O=p.openai)==null?void 0:O.modelRoutes)??{}),D=((u==null?void 0:u.customEndpoints)??x).map(_=>{const W=_.routing,ve=W==null?void 0:W.modelRoutes;return ve?{..._,routing:{...W,defaults:W.defaults??u.defaults,modelRoutes:n(ve)}}:_}),$={...u,providers:l,modelRoutes:w,customEndpoints:D,endpointRouting:{anthropic:{defaults:((K=p.anthropic)==null?void 0:K.defaults)??u.defaults,modelRoutes:w,validation:(z=p.anthropic)==null?void 0:z.validation},openai:{defaults:((ae=p.openai)==null?void 0:ae.defaults)??u.defaults,modelRoutes:y,validation:(De=p.openai)==null?void 0:De.validation}}};try{await ye.saveConfig($),h($),V({anthropic:Object.entries(w).map(([_,W])=>({id:ne(),source:_,target:W})),openai:Object.entries(y).map(([_,W])=>({id:ne(),source:_,target:W})),...Object.fromEntries(D.map(_=>{var W;return[_.id,Object.entries(((W=_.routing)==null?void 0:W.modelRoutes)??{}).map(([ve,je])=>({id:ne(),source:ve,target:je}))]}))}),t({title:s("providers.toast.deleteSuccess",{name:r.label||r.id}),variant:"success"}),g.refetch()}catch(_){t({title:s("providers.toast.deleteFailure",{message:_ instanceof Error?_.message:"unknown"}),variant:"error"})}},rs=async()=>{if(S){Ze(!0);try{S.kind==="provider"?await rt(S.provider):S.kind==="preset"?await Xt(S.endpoint,S.preset):await es(S.endpoint.id),Ye(null)}finally{Ze(!1)}}},as=r=>{V(l=>({...l,[r]:[...l[r]||[],{id:ne(),source:"",target:""}]})),G(l=>({...l,[r]:null}))},ns=async(r,l)=>{var n,p;if(ce()){Je(!0);try{if(r==="anthropic"||r==="openai"){const w=r,y=u.endpointRouting?{...u.endpointRouting}:{},D=y[w]??{defaults:u.defaults,modelRoutes:(w==="anthropic"?u.modelRoutes:{})??{}},$={defaults:D.defaults??u.defaults,modelRoutes:D.modelRoutes??{}},U=l?{...D.validation??{},mode:"claude-code",allowExperimentalBlocks:((n=D.validation)==null?void 0:n.allowExperimentalBlocks)??!0}:void 0,O={...u,endpointRouting:{...y,[w]:U?{...$,validation:U}:{...$}}};await ye.saveConfig(O),h(O)}else{const w=[...u.customEndpoints??[]],y=w.findIndex(K=>K.id===r);if(y===-1)throw new Error(s("modelManagement.toast.endpointNotFound"));const D=w[y],$=D.routing??{defaults:u.defaults,modelRoutes:{}},U=l?{...$.validation??{},mode:"claude-code",allowExperimentalBlocks:((p=$.validation)==null?void 0:p.allowExperimentalBlocks)??!0}:void 0;w[y]={...D,routing:U?{...$,validation:U}:{defaults:$.defaults,modelRoutes:$.modelRoutes}};const O={...u,customEndpoints:w};await ye.saveConfig(O),h(O)}t({title:s(l?"modelManagement.toast.claudeValidationEnabled":"modelManagement.toast.claudeValidationDisabled"),variant:"success"}),g.refetch()}catch(w){const y=ot(w);t({title:s("modelManagement.toast.claudeValidationFailure",{message:y.message}),variant:"error"})}finally{Je(!1)}}},os=(r,l)=>{V(n=>{const p=n[r]||[];return p.some(w=>w.source.trim()===l.trim())?n:{...n,[r]:[...p,{id:ne(),source:l,target:""}]}}),G(n=>({...n,[r]:null}))},ds=(r,l,n,p)=>{V(w=>({...w,[r]:(w[r]||[]).map(y=>y.id===l?{...y,[n]:p}:y)})),G(w=>({...w,[r]:null}))},ls=(r,l)=>{V(n=>({...n,[r]:(n[r]||[]).filter(p=>p.id!==l)})),G(n=>({...n,[r]:null}))},is=r=>{var n;if(!u)return;const l=(u.customEndpoints??x).find(p=>p.id===r);if(l)V(p=>{var w;return{...p,[r]:Object.entries(((w=l.routing)==null?void 0:w.modelRoutes)??{}).map(([y,D])=>({id:ne(),source:y,target:D}))}});else{const p=u.endpointRouting??{},w=r,y=w==="anthropic"?u.modelRoutes??{}:{},D=((n=p[w])==null?void 0:n.modelRoutes)??y;V($=>({...$,[r]:Object.entries(D).map(([U,O])=>({id:ne(),source:U,target:O}))}))}G(p=>({...p,[r]:null}))},cs=Le({mutationFn:async r=>(await ye.saveConfig(r.nextConfig),r)}),ms=Le({mutationFn:async r=>(await Ee.update(r.endpoint,{routing:r.routing}),r)}),us=async r=>{var p,w,y,D,$;if(!ce())return;const l=Z[r]||[],n={};for(const U of l){const O=U.source.trim(),K=U.target.trim();if(!(!O&&!K)){if(!O||!K){G(z=>({...z,[r]:s("settings.validation.routePair")}));return}if(n[O]){G(z=>({...z,[r]:s("settings.validation.routeDuplicate",{model:O})}));return}n[O]=K}}G(U=>({...U,[r]:null})),be(r);try{const U=x.find(O=>O.id===r);if(U){const O={...U.routing??{},modelRoutes:n,defaults:((p=U.routing)==null?void 0:p.defaults)||u.defaults};await ms.mutateAsync({endpoint:r,routing:O}),h(K=>{if(!K)return K;const z=[...K.customEndpoints??[]],ae=z.findIndex(De=>De.id===r);return ae===-1?K:(z[ae]={...z[ae],routing:O},{...K,customEndpoints:z})}),await c.invalidateQueries({queryKey:he.customEndpoints.all()})}else{const O={...u,endpointRouting:{...u.endpointRouting??{},[r]:{defaults:((y=(w=u.endpointRouting)==null?void 0:w[r])==null?void 0:y.defaults)??u.defaults,modelRoutes:n,validation:($=(D=u.endpointRouting)==null?void 0:D[r])==null?void 0:$.validation}},modelRoutes:r==="anthropic"?n:u.modelRoutes??{}};await cs.mutateAsync({endpoint:r,nextConfig:O}),h(O)}V(O=>({...O,[r]:Object.entries(n).map(([K,z])=>({id:ne(),source:K,target:z}))})),t({title:s("modelManagement.toast.routesSaved"),variant:"success"}),g.refetch()}catch(U){t({title:s("modelManagement.toast.routesSaveFailure",{message:U instanceof Error?U.message:"unknown"}),variant:"error"})}finally{be(null)}},ps=(S==null?void 0:S.kind)==="provider"?s("providers.actions.delete"):(S==null?void 0:S.kind)==="preset"?s("modelManagement.presets.delete"):(S==null?void 0:S.kind)==="endpoint"?s("common.delete"):"",xs=(S==null?void 0:S.kind)==="provider"?s("providers.confirm.delete",{name:S.provider.label||S.provider.id}):(S==null?void 0:S.kind)==="preset"?s("modelManagement.confirm.deletePreset",{name:S.preset.name}):(S==null?void 0:S.kind)==="endpoint"?s("modelManagement.deleteEndpointConfirm",{label:S.endpoint.label}):"",gs=(S==null?void 0:S.kind)==="provider"?S.provider.label||S.provider.id:(S==null?void 0:S.kind)==="preset"?S.preset.name:(S==null?void 0:S.kind)==="endpoint"?S.endpoint.label:"";return{activeTab:o,activeTabInfo:Ft,anthropicTestHeaderOptions:ke,applyingPreset:E,config:u,configQuery:g,confirmAction:S,confirmDialogDescription:xs,confirmDialogName:gs,confirmDialogTitle:ps,confirmingAction:Ot,customEndpoints:x,customTabs:Lt,defaultLabels:It,deletingPreset:P,drawerMode:M,drawerOpen:F,editingEndpoint:b,editingProvider:v,endpointDrawerOpen:ue,filteredProviders:Ht,handleAddRoute:as,handleAddSuggestion:os,handleApplyPreset:Gt,handleConfirmDialog:rs,handleDeleteProvider:rt,handleOpenCreate:Jt,handleOpenCreateEndpoint:zt,handleOpenEditEndpoint:Vt,handleOpenEdit:Yt,handlePresetNameChange:Wt,handleProviderSubmit:Zt,handleRemoveRoute:ls,handleResetRoutes:is,handleRouteChange:ds,handleSavePreset:Qt,handleSaveRoutes:us,handleToggleClaudeValidation:ns,initiateTestConnection:ts,isDirtyByEndpoint:qt,presetDiffDialog:Rt,presetErrorByEndpoint:xe,presetNameByEndpoint:Me,presetsByEndpoint:T,presetsExpanded:Pt,providerCount:Bt,providerModelOptions:Kt,providerSearch:Ie,providerTypeFilter:Pe,providers:ee,pushToast:t,routeError:pe,routesByEndpoint:Z,savingClaudeValidation:St,savingPresetFor:ge,savingRouteFor:we,setActiveTab:m,setConfirmAction:Ye,setDrawerMode:C,setDrawerOpen:k,setEditingEndpoint:j,setEditingProvider:f,setEndpointDrawerOpen:le,setPresetDiffDialog:Tt,setPresetsExpanded:Dt,setProviderSearch:At,setProviderTypeFilter:Ut,setTestDialogUsePreset:He,systemTabs:$t,tabs:a,testDialogOpen:X,testDialogPreservedExtras:Ge,testDialogProvider:q,testDialogUsePreset:re,testingProviderId:Q,closeTestDialog:st,confirmTestDialog:ss}}function br(){var x,a,o;const{t:s}=te(),t=Ys(),c=Object.values(t.isDirtyByEndpoint).filter(Boolean).length,g=Math.max(0,t.systemTabs.length-1)+t.customTabs.length,d=t.activeTab==="providers"?s("modelManagement.header.providersHelper"):s("modelManagement.header.routingHelper",{name:((x=t.activeTabInfo)==null?void 0:x.label)??t.activeTab});return e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx(ys,{icon:e.jsx(vs,{className:"h-5 w-5","aria-hidden":"true"}),title:s("modelManagement.title"),description:s("modelManagement.description"),eyebrow:"Routing Control",breadcrumb:"Gateway / Model Management",helper:d,badge:c>0?s("modelManagement.overview.unsavedCount",{count:c}):void 0,actions:e.jsxs("div",{className:"flex w-full flex-col gap-2 sm:w-auto sm:flex-row sm:flex-wrap sm:justify-end",children:[e.jsxs("div",{className:"rounded-lg border border-border bg-secondary px-3 py-2 text-xs text-muted-foreground",children:[s("modelManagement.tabs.providers")," · ",t.providerCount," / ",s("modelManagement.overview.routeWorkspacesStat")," · ",g]}),e.jsx(L,{onClick:t.handleOpenCreateEndpoint,className:"w-full sm:w-auto",children:s("modelManagement.addEndpoint")})]})}),e.jsx(Fs,{activeTab:t.activeTab,activeTabInfo:t.activeTabInfo,customEndpoints:t.customEndpoints,customTabs:t.customTabs,isDirtyByEndpoint:t.isDirtyByEndpoint,onDeleteEndpoint:t.setConfirmAction,onEditEndpoint:t.handleOpenEditEndpoint,onSelectTab:t.setActiveTab,providerCount:t.providerCount,systemTabs:t.systemTabs}),t.activeTab==="providers"?e.jsx(qs,{configPending:t.configQuery.isPending||!t.config&&t.configQuery.isFetching,configFetching:t.configQuery.isFetching,defaultLabels:t.defaultLabels,filteredProviders:t.filteredProviders,onOpenCreate:t.handleOpenCreate,onOpenEdit:t.handleOpenEdit,onRefresh:()=>void t.configQuery.refetch(),onRequestDelete:m=>t.setConfirmAction({kind:"provider",provider:m}),onResetFilters:()=>{t.setProviderSearch(""),t.setProviderTypeFilter("all")},onProviderSearchChange:t.setProviderSearch,onProviderTypeChange:t.setProviderTypeFilter,onTestConnection:t.initiateTestConnection,providerCount:t.providerCount,providerSearch:t.providerSearch,providerTypeFilter:t.providerTypeFilter,providersLength:t.providers.length,testingProviderId:t.testingProviderId}):e.jsx(Gs,{endpoint:t.activeTab,applyingPreset:((a=t.applyingPreset)==null?void 0:a.endpoint)===t.activeTab?t.applyingPreset.name:null,config:t.config,customEndpoints:t.customEndpoints,deletingPreset:((o=t.deletingPreset)==null?void 0:o.endpoint)===t.activeTab?t.deletingPreset.name:null,isDirty:t.isDirtyByEndpoint[t.activeTab]??!1,onAddRoute:()=>t.handleAddRoute(t.activeTab),onAddSuggestion:m=>t.handleAddSuggestion(t.activeTab,m),onPresetNameChange:m=>t.handlePresetNameChange(t.activeTab,m),onRequestDeletePreset:m=>t.setConfirmAction({kind:"preset",endpoint:t.activeTab,preset:m}),onRequestPresetDiff:m=>t.setPresetDiffDialog({endpoint:t.activeTab,preset:m}),onRemoveRoute:m=>t.handleRemoveRoute(t.activeTab,m),onResetRoutes:()=>t.handleResetRoutes(t.activeTab),onRouteChange:(m,u,h)=>t.handleRouteChange(t.activeTab,m,u,h),onSavePreset:()=>void t.handleSavePreset(t.activeTab),onSaveRoutes:()=>void t.handleSaveRoutes(t.activeTab),onToggleClaudeValidation:m=>void t.handleToggleClaudeValidation(t.activeTab,m),onTogglePresetsExpanded:()=>t.setPresetsExpanded(m=>({...m,[t.activeTab]:!m[t.activeTab]})),presetError:t.presetErrorByEndpoint[t.activeTab],presetName:t.presetNameByEndpoint[t.activeTab]??"",presets:t.presetsByEndpoint[t.activeTab]??[],presetsExpanded:t.presetsExpanded[t.activeTab]===!0,providerModelOptions:t.providerModelOptions,routeError:t.routeError[t.activeTab],routes:t.routesByEndpoint[t.activeTab]||[],savingClaudeValidation:t.savingClaudeValidation,savingPreset:t.savingPresetFor===t.activeTab,savingRoute:t.savingRouteFor===t.activeTab,tabs:t.tabs}),e.jsx(Us,{open:t.drawerOpen,mode:t.drawerMode,provider:t.drawerMode==="edit"?t.editingProvider:void 0,existingProviderIds:t.providers.map(m=>m.id).filter(m=>t.drawerMode==="edit"&&t.editingProvider?m!==t.editingProvider.id:!0),onClose:()=>{t.setDrawerOpen(!1),t.setEditingProvider(void 0),t.setDrawerMode("create")},onSubmit:t.handleProviderSubmit}),e.jsx(Ls,{open:t.endpointDrawerOpen,endpoint:t.editingEndpoint,onClose:()=>{t.setEndpointDrawerOpen(!1),t.setEditingEndpoint(void 0)},onSuccess:()=>{t.configQuery.refetch()}}),e.jsx(Js,{open:t.testDialogOpen,provider:t.testDialogProvider,options:t.anthropicTestHeaderOptions,preservedExtras:t.testDialogPreservedExtras,usePreset:t.testDialogUsePreset,onPresetChange:t.setTestDialogUsePreset,onConfirm:t.confirmTestDialog,onClose:t.closeTestDialog}),e.jsx(Bs,{dialog:t.presetDiffDialog,currentRoutes:t.presetDiffDialog?t.routesByEndpoint[t.presetDiffDialog.endpoint]||[]:[],onConfirm:(m,u)=>{t.setPresetDiffDialog(null),t.handleApplyPreset(m,u)},onClose:()=>t.setPresetDiffDialog(null)}),e.jsx(js,{open:!!t.confirmAction,onOpenChange:m=>{!m&&!t.confirmingAction&&t.setConfirmAction(null)},title:t.confirmDialogTitle,description:t.confirmDialogDescription,confirmLabel:t.confirmingAction?s("common.actions.loading"):s("common.delete"),cancelLabel:s("common.actions.cancel"),loading:t.confirmingAction,onConfirm:t.handleConfirmDialog,children:t.confirmDialogName?e.jsx("div",{className:"rounded-[1rem] border border-destructive/20 bg-destructive/5 px-3 py-2 font-mono text-xs text-foreground",children:t.confirmDialogName}):null})]})}export{br as default};
@@ -1 +1 @@
1
- import{j as e}from"./vendor-CjJPKsTb.js";import{c as i}from"./index-Bit1YrKY.js";import{B as c}from"./badge-C0zaY90P.js";function u({icon:l,title:x,description:t,badge:a,eyebrow:s,breadcrumb:r,helper:d,actions:n,className:m}){return e.jsxs("div",{className:i("flex flex-col gap-5 rounded-lg border border-border bg-card p-5 sm:flex-row sm:items-start sm:justify-between",m),children:[e.jsxs("div",{className:"flex flex-1 flex-wrap items-start gap-4",children:[l&&e.jsx("div",{className:"flex h-12 w-12 items-center justify-center rounded-xl bg-primary/10 text-primary",children:l}),e.jsxs("div",{className:"min-w-0 space-y-2",children:[(s||r)&&e.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-[11px] font-semibold uppercase tracking-[0.18em] text-muted-foreground",children:[s?e.jsx("span",{children:s}):null,s&&r?e.jsx("span",{className:"h-1 w-1 rounded-full bg-muted-foreground/50"}):null,r?e.jsx("span",{className:"text-muted-foreground/90",children:r}):null]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsx("h1",{className:"text-2xl font-semibold tracking-[-0.02em]",children:x}),a&&e.jsx(c,{variant:"secondary",children:a})]}),t&&e.jsx("p",{className:"max-w-3xl text-sm text-muted-foreground",children:t}),d&&e.jsx("div",{className:"rounded-lg border border-border bg-secondary px-3 py-2 text-xs text-muted-foreground",children:d})]})]}),n&&e.jsx("div",{className:"w-full shrink-0 self-start sm:w-auto",children:n})]})}export{u as P};
1
+ import{j as e}from"./vendor-CjJPKsTb.js";import{c as i}from"./index-BiTh8byX.js";import{B as c}from"./badge-tREH_88e.js";function u({icon:l,title:x,description:t,badge:a,eyebrow:s,breadcrumb:r,helper:d,actions:n,className:m}){return e.jsxs("div",{className:i("flex flex-col gap-5 rounded-lg border border-border bg-card p-5 sm:flex-row sm:items-start sm:justify-between",m),children:[e.jsxs("div",{className:"flex flex-1 flex-wrap items-start gap-4",children:[l&&e.jsx("div",{className:"flex h-12 w-12 items-center justify-center rounded-xl bg-primary/10 text-primary",children:l}),e.jsxs("div",{className:"min-w-0 space-y-2",children:[(s||r)&&e.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-[11px] font-semibold uppercase tracking-[0.18em] text-muted-foreground",children:[s?e.jsx("span",{children:s}):null,s&&r?e.jsx("span",{className:"h-1 w-1 rounded-full bg-muted-foreground/50"}):null,r?e.jsx("span",{className:"text-muted-foreground/90",children:r}):null]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsx("h1",{className:"text-2xl font-semibold tracking-[-0.02em]",children:x}),a&&e.jsx(c,{variant:"secondary",children:a})]}),t&&e.jsx("p",{className:"max-w-3xl text-sm text-muted-foreground",children:t}),d&&e.jsx("div",{className:"rounded-lg border border-border bg-secondary px-3 py-2 text-xs text-muted-foreground",children:d})]})]}),n&&e.jsx("div",{className:"w-full shrink-0 self-start sm:w-auto",children:n})]})}export{u as P};
@@ -1 +1 @@
1
- import{j as s}from"./vendor-CjJPKsTb.js";import{c as m}from"./index-Bit1YrKY.js";import{C as c,b as x,c as i,d as f,a as j}from"./card-trgtgeo-.js";function b({title:a,description:e,eyebrow:d,actions:r,className:l,contentClassName:n,children:o}){const t=a||e||r;return s.jsxs(c,{className:m("overflow-hidden",l),children:[t&&s.jsxs(x,{className:"flex flex-col gap-4 border-b border-border bg-secondary sm:flex-row sm:items-start sm:justify-between sm:space-y-0",children:[s.jsxs("div",{className:"min-w-0 space-y-1.5",children:[d?s.jsx("div",{className:"text-[11px] font-semibold uppercase tracking-[0.18em] text-muted-foreground",children:d}):null,typeof a=="string"?s.jsx(i,{className:"text-base font-semibold",children:a}):a,e&&(typeof e=="string"?s.jsx(f,{children:e}):s.jsx("div",{className:"text-sm text-muted-foreground",children:e}))]}),r&&s.jsx("div",{className:"w-full shrink-0 sm:w-auto",children:r})]}),s.jsx(j,{className:m(!t&&"pt-6",t&&"pt-5",n),children:o})]})}export{b as P};
1
+ import{j as s}from"./vendor-CjJPKsTb.js";import{c as m}from"./index-BiTh8byX.js";import{C as c,b as x,c as i,d as f,a as j}from"./card-yK3LQB_K.js";function b({title:a,description:e,eyebrow:d,actions:r,className:l,contentClassName:n,children:o}){const t=a||e||r;return s.jsxs(c,{className:m("overflow-hidden",l),children:[t&&s.jsxs(x,{className:"flex flex-col gap-4 border-b border-border bg-secondary sm:flex-row sm:items-start sm:justify-between sm:space-y-0",children:[s.jsxs("div",{className:"min-w-0 space-y-1.5",children:[d?s.jsx("div",{className:"text-[11px] font-semibold uppercase tracking-[0.18em] text-muted-foreground",children:d}):null,typeof a=="string"?s.jsx(i,{className:"text-base font-semibold",children:a}):a,e&&(typeof e=="string"?s.jsx(f,{children:e}):s.jsx("div",{className:"text-sm text-muted-foreground",children:e}))]}),r&&s.jsx("div",{className:"w-full shrink-0 sm:w-auto",children:r})]}),s.jsx(j,{className:m(!t&&"pt-6",t&&"pt-5",n),children:o})]})}export{b as P};
@@ -1 +1 @@
1
- import{j as e,P as c}from"./vendor-CjJPKsTb.js";import{c as i}from"./index-Bit1YrKY.js";const m={default:"border-border bg-secondary",primary:"border-primary/15 bg-accent",danger:"border-destructive/20 bg-destructive/10"},x={default:"bg-secondary text-primary",primary:"bg-primary/10 text-primary",danger:"bg-destructive/10 text-destructive"};function o({icon:r,title:s,description:t,action:a,className:d,compact:l=!1,tone:n="default"}){return e.jsxs("div",{className:i("flex flex-col items-center justify-center rounded-lg border border-dashed px-6 text-center",l?"min-h-[180px] py-8":"min-h-[260px] py-12",m[n],d),children:[r?e.jsx("div",{className:i("mb-4 flex h-12 w-12 items-center justify-center rounded-2xl",x[n]),children:r}):null,e.jsxs("div",{className:"max-w-xl space-y-1.5",children:[e.jsx("div",{className:"text-base font-semibold tracking-[-0.01em]",children:s}),t?e.jsx("div",{className:"text-sm text-muted-foreground",children:t}):null]}),a?e.jsx("div",{className:"mt-5 flex flex-wrap items-center justify-center gap-2",children:a}):null]})}function p({label:r,className:s,compact:t=!1}){return e.jsx(o,{className:s,compact:t,tone:"primary",icon:e.jsx(c,{className:"h-5 w-5 animate-spin","aria-hidden":"true"}),title:r})}export{p as P,o as a};
1
+ import{j as e,P as c}from"./vendor-CjJPKsTb.js";import{c as i}from"./index-BiTh8byX.js";const m={default:"border-border bg-secondary",primary:"border-primary/15 bg-accent",danger:"border-destructive/20 bg-destructive/10"},x={default:"bg-secondary text-primary",primary:"bg-primary/10 text-primary",danger:"bg-destructive/10 text-destructive"};function o({icon:r,title:s,description:t,action:a,className:d,compact:l=!1,tone:n="default"}){return e.jsxs("div",{className:i("flex flex-col items-center justify-center rounded-lg border border-dashed px-6 text-center",l?"min-h-[180px] py-8":"min-h-[260px] py-12",m[n],d),children:[r?e.jsx("div",{className:i("mb-4 flex h-12 w-12 items-center justify-center rounded-2xl",x[n]),children:r}):null,e.jsxs("div",{className:"max-w-xl space-y-1.5",children:[e.jsx("div",{className:"text-base font-semibold tracking-[-0.01em]",children:s}),t?e.jsx("div",{className:"text-sm text-muted-foreground",children:t}):null]}),a?e.jsx("div",{className:"mt-5 flex flex-wrap items-center justify-center gap-2",children:a}):null]})}function p({label:r,className:s,compact:t=!1}){return e.jsx(o,{className:s,compact:t,tone:"primary",icon:e.jsx(c,{className:"h-5 w-5 animate-spin","aria-hidden":"true"}),title:r})}export{p as P,o as a};
@@ -0,0 +1 @@
1
+ import{r as f,j as e,X as Y,am as ie,ay as Z,aH as oe,aI as de,S as ce,ar as xe,a1 as me,al as ue}from"./vendor-CjJPKsTb.js";import{u as pe,a as A,b as S}from"./query-D3IfCUhp.js";import{P as ee,a as M}from"./PageState-5sxEzXut.js";import{B as se}from"./badge-tREH_88e.js";import{h as F,b as q,r as O,c as m,B as $}from"./index-BiTh8byX.js";import{d as he}from"./utils-DQfq7gRo.js";import{q as b}from"./queryKeys-BMvyDTQS.js";import"./i18n-CfLThlXq.js";import"./router-CmaL1NgV.js";import"./radix-54BMi3RD.js";const v={getStatus:()=>O({url:"/api/profiler/status",method:"GET"}),start:()=>F(q.post("/api/profiler/start")),stop:()=>F(q.post("/api/profiler/stop")),listSessions:s=>O({url:"/api/profiler/sessions",method:"GET",params:s}),getSession:s=>O({url:`/api/profiler/sessions/${s}`,method:"GET"}),deleteSession:s=>F(q.delete(`/api/profiler/sessions/${s}`)),clearAll:()=>F(q.post("/api/profiler/sessions/clear"))};function g(s){return s==null?"-":s>=1e3?`${(s/1e3).toFixed(2)}s`:`${Math.round(s)}ms`}function I(s){return s==null?"-":s>=1e3?`${(s/1e3).toFixed(1)}s`:`${Math.round(s)}ms`}function k(s){return s==null?"-":s.toLocaleString()}function K(s){return s==null?"-":s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toLocaleString()}function L(s){return s.endedAt==null||s.turnCount===0?s.totalLatencyMs??0:s.endedAt-s.startedAt}function fe(s){const t=s.sessionId;return t.length>18?`${t.slice(0,8)}…${t.slice(-6)}`:t}function be(s){const t=Math.max(0,Date.now()-s),n=Math.floor(t/6e4);if(n<1)return"just now";if(n<60)return`${n} min ago`;const l=Math.floor(n/60);if(l<24)return`${l} hr ago`;const r=Math.floor(l/24);return`${r} day${r===1?"":"s"} ago`}function ge(s){if(!s)return null;try{return JSON.parse(s)}catch{return null}}function _(s,t){if(Array.isArray(s)){for(const n of s)_(n,t);return}if(s&&typeof s=="object"){const n=s,l=n.tool_calls;Array.isArray(l)&&t.push(...l);const r=n.content;if(Array.isArray(r)){for(const i of r)if(i&&typeof i=="object"){const a=i;a.type==="tool_use"&&t.push(a)}}for(const i of Object.values(n))_(i,t)}}function R(s){const t=[];return _(ge(s.clientResponse),t),t}function le(s,t){const n=s.timestamp-t,l=n+(s.latencyMs??0);return`${(n/1e3).toFixed(3)}s → ${(l/1e3).toFixed(3)}s`}function Q(s,t){return he(s??null,t)}function je(s,t){const n=new Blob([JSON.stringify(t,null,2)],{type:"application/json"}),l=URL.createObjectURL(n),r=document.createElement("a");r.href=l,r.download=s,r.click(),URL.revokeObjectURL(l)}function B({tone:s="default",children:t}){return e.jsx("span",{className:m("inline-flex items-center rounded-full px-2 py-0.5 text-[11px] font-medium",s==="accent"?"bg-indigo-100 text-indigo-700":"bg-slate-100 text-slate-600"),children:t})}function Ne({session:s,selected:t,index:n,onClick:l}){const r=["bg-indigo-500","bg-emerald-500","bg-amber-500"],i=t?"bg-indigo-500":r[n%r.length],a=(s.totalInputTokens??0)+(s.totalOutputTokens??0);return e.jsxs("button",{type:"button",onClick:l,className:m("w-full border-b border-border px-4 py-3 text-left transition-colors",t?"bg-indigo-50/70":"hover:bg-slate-50"),children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{className:m("h-2 w-2 flex-shrink-0 rounded-full",i)}),e.jsx("span",{className:m("truncate text-sm font-semibold",t?"text-indigo-700":"text-slate-800"),children:fe(s)})]}),e.jsx("span",{className:"text-[10px] text-muted-foreground",children:be(s.startedAt)})]}),e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2 pl-4",children:[e.jsxs(B,{tone:t?"accent":"default",children:[s.turnCount," turns"]}),e.jsx(B,{children:I(L(s))}),e.jsxs(B,{children:[K(a)," tok"]})]})]})}function te({active:s,icon:t,label:n,onClick:l}){return e.jsxs("button",{type:"button",onClick:l,className:m("inline-flex h-7 items-center gap-1.5 rounded-full border px-3 text-xs font-medium transition-colors",s?"border-indigo-200 bg-indigo-50 text-indigo-700":"border-transparent bg-slate-50 text-slate-500 hover:bg-slate-100 hover:text-slate-700"),children:[e.jsx(t,{className:"h-3.5 w-3.5"}),n]})}function D({active:s,label:t,count:n,onClick:l}){return e.jsxs("button",{type:"button",onClick:l,className:m("inline-flex h-6 items-center gap-1.5 rounded-full border px-2.5 text-[11px] font-medium transition-colors",s?"border-indigo-200 bg-indigo-50 text-indigo-700":"border-transparent bg-transparent text-slate-500 hover:bg-slate-100 hover:text-slate-700"),children:[e.jsx("span",{children:t}),typeof n=="number"&&e.jsx("span",{className:"rounded-full bg-amber-100 px-1.5 py-0.5 text-[10px] font-semibold text-amber-800",children:n})]})}function ve({detail:s,selectedTurn:t,onSelectTurn:n}){const l=s.records;if(l.length===0)return e.jsx(M,{compact:!0,className:"min-h-[220px]",title:"No turns recorded"});const r=L(s),i=Math.max(1,...l.map(a=>Math.max(a.latencyMs??0,a.ttftMs??0,1)));return Math.max(1,...l.map(a=>R(a).length)),e.jsxs("div",{className:"border-b border-border bg-white",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4 px-5 py-3",children:[e.jsx("p",{className:"text-xs text-slate-500",children:"Compressed overview · idle gaps folded · wraps as turns grow"}),e.jsxs("div",{className:"flex items-center gap-2 text-[11px]",children:[e.jsx("span",{className:"text-slate-500",children:"Mode:"}),e.jsx("span",{className:"rounded border border-slate-200 bg-slate-100 px-2 py-0.5 font-medium text-slate-700",children:"Compressed"}),e.jsxs("span",{className:"rounded border border-slate-200 bg-white px-2 py-0.5 font-medium text-slate-700",children:["Session ",I(r)]})]})]}),e.jsxs("div",{className:"px-5 pb-4",children:[e.jsxs("div",{className:"mb-3 flex items-center justify-between text-[10px] text-slate-400",children:[e.jsx("span",{children:"start"}),e.jsxs("span",{children:[(r/1e3).toFixed(1),"s"]})]}),e.jsx("div",{className:"grid gap-x-2 gap-y-5",style:{gridTemplateColumns:"repeat(10, minmax(0, 1fr))"},children:l.map((a,u)=>{const p=u===t,y=Math.max(a.latencyMs??0,1),o=`${Math.max(28,Math.min(100,y/i*100))}%`,x=a.ttftMs!=null?`${Math.max(0,Math.min(100,Math.min(a.ttftMs,i)/i*100))}%`:null,C=Math.max(0,a.timestamp-s.startedAt),w=R(a);return e.jsxs("button",{type:"button",onClick:()=>n(u),className:m("border border-transparent px-1.5 py-1 text-left transition-colors",p?"rounded-md border-rose-300":"hover:bg-slate-50/40"),title:`Turn ${a.turnIndex+1}`,children:[e.jsx("div",{className:"flex min-w-0 items-center gap-2",children:e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{className:m("inline-flex h-5 min-w-5 items-center justify-center rounded-full border px-1.5 text-[11px] font-semibold",p?"border-indigo-300 bg-indigo-100 text-indigo-700":"border-slate-200 bg-white text-slate-700"),children:a.turnIndex+1}),e.jsx("span",{className:"truncate text-[15px] font-semibold text-slate-800",children:I(a.latencyMs)})]})}),e.jsxs("p",{className:"mt-1 text-[10px] text-slate-500",children:["start ",(C/1e3).toFixed(1),"s"]}),e.jsxs("div",{className:"mt-2",children:[e.jsx("div",{className:"flex items-center justify-between text-[10px] text-slate-500",children:e.jsxs("span",{children:[g(a.ttftMs)," TTFT"]})}),e.jsxs("div",{className:"relative mt-1 h-4 rounded-sm bg-slate-100",children:[e.jsx("div",{className:"h-4 rounded-sm bg-blue-200",style:{width:o}}),x!=null&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"absolute top-[-3px] h-5 w-[3px] -translate-x-1/2 rounded-full bg-violet-500 shadow-[0_0_0_1px_rgba(255,255,255,0.9)]",style:{left:x}}),e.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:x}})]})]})]}),e.jsxs("div",{className:"mt-2",children:[e.jsxs("div",{className:"mb-1 flex items-center justify-between text-[10px] text-slate-500",children:[e.jsx("span",{children:"Tools"}),e.jsx("span",{children:w.length})]}),e.jsx("div",{className:"flex h-5 items-center gap-1",children:e.jsx("span",{className:m("inline-flex h-5 min-w-5 items-center justify-center rounded-md border text-[10px] font-semibold",w.length>0?"border-amber-400 bg-amber-200 text-amber-900":"border-slate-300 bg-white text-slate-500"),children:w.length})})]})]},a.id)})}),e.jsxs("div",{className:"mt-4 flex flex-wrap items-center gap-4 text-[11px] text-slate-500",children:[e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"h-2.5 w-2.5 rounded-sm bg-blue-200"}),"Total latency"]}),e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"relative inline-block h-2.5 w-2.5 rounded-full border border-white bg-violet-500 shadow-[0_0_0_1px_rgba(139,92,246,0.35)]"}),"First token (TTFT)"]}),e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"h-2.5 w-2.5 rounded-sm border border-amber-400 bg-amber-200"}),"Tool executing"]}),e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"h-2.5 w-2.5 rounded-sm border border-rose-300 bg-rose-50"}),"Selected turn"]})]})]})]})}function ye({detail:s,selectedTurn:t,detailTab:n,onDetailTabChange:l,onSelectTurn:r}){const i=s.records[t];if(!i)return null;const a=R(i),u=(i.inputTokens??0)+(i.outputTokens??0),p=n==="request"?Q(i.clientRequest,"(empty request)"):n==="response"?Q(i.clientResponse,"(empty response)"):a.length>0?JSON.stringify(a,null,2):"(no tool calls)";return e.jsxs("div",{"data-testid":"profiler-turn-detail",className:"shrink-0 bg-slate-50",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4 border-b border-slate-200 bg-white px-5 py-3",children:[e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-2 text-xs",children:[e.jsxs("span",{className:"rounded-full px-2 py-1 font-semibold text-white",style:{background:"linear-gradient(135deg, #6E63FF, #4E8DFF)"},children:["Turn ",i.turnIndex+1]}),e.jsx("span",{className:"text-slate-500",children:le(i,s.startedAt)}),e.jsxs("span",{className:"rounded-full bg-violet-100 px-2 py-1 font-semibold text-violet-700",children:["TTFT ",g(i.ttftMs)]}),e.jsxs("span",{className:"rounded-full bg-blue-100 px-2 py-1 font-semibold text-blue-700",children:[K(u)," tokens"]})]}),e.jsxs("div",{className:"flex items-center gap-2 text-xs text-slate-500",children:[e.jsx("button",{type:"button",onClick:()=>r(Math.max(0,t-1)),disabled:t===0,className:"rounded p-1 hover:bg-slate-100 disabled:cursor-not-allowed disabled:opacity-40","aria-label":"Previous turn",children:e.jsx(xe,{className:"h-4 w-4"})}),e.jsxs("span",{className:"min-w-10 text-center font-medium text-slate-600",children:[t+1," / ",s.records.length]}),e.jsx("button",{type:"button",onClick:()=>r(Math.min(s.records.length-1,t+1)),disabled:t===s.records.length-1,className:"rounded p-1 hover:bg-slate-100 disabled:cursor-not-allowed disabled:opacity-40","aria-label":"Next turn",children:e.jsx(me,{className:"h-4 w-4"})})]})]}),e.jsx("div",{className:"border-b border-slate-200 bg-white px-5 py-2",children:e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(D,{active:n==="request",label:"Request",onClick:()=>l("request")}),e.jsx(D,{active:n==="response",label:"Response",onClick:()=>l("response")}),e.jsx(D,{active:n==="tools",label:"Tool Calls",count:a.length,onClick:()=>l("tools")})]})}),e.jsxs("div",{className:"p-5",children:[e.jsx("pre",{className:"max-h-[420px] overflow-auto rounded-xl bg-[#1E1E2E] p-4 text-xs leading-5 text-slate-200",children:p}),i.error&&e.jsx("p",{className:"mt-3 rounded-lg border border-red-200 bg-red-50 px-3 py-2 text-xs text-red-700",children:i.error})]})]})}function we({detail:s,selectedTurn:t,detailTab:n,onSelectTurn:l,onDetailTabChange:r}){return e.jsxs("div",{className:"flex min-h-full flex-col",children:[e.jsx(ve,{detail:s,selectedTurn:t,onSelectTurn:l}),e.jsx(ye,{detail:s,selectedTurn:t,detailTab:n,onDetailTabChange:r,onSelectTurn:l})]})}function ne({title:s,payload:t,accentClass:n}){return e.jsxs("div",{className:"rounded-xl border border-border bg-white p-3",children:[e.jsx("p",{className:m("mb-2 text-[11px] font-semibold uppercase tracking-[0.16em]",n),children:s}),e.jsx("pre",{className:"max-h-64 overflow-auto rounded-lg bg-slate-950/95 p-3 text-xs leading-5 text-slate-200",children:Q(t,"(empty)")})]})}function T({label:s,value:t,sub:n,accentClass:l}){return e.jsxs("div",{className:"rounded-2xl border border-border bg-white p-4",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-[0.16em] text-slate-500",children:s}),e.jsx("p",{className:m("mt-2 text-2xl font-semibold text-slate-900",l),children:t}),n&&e.jsx("p",{className:"mt-1 text-xs text-slate-500",children:n})]})}function Te({record:s,sessionStart:t,expanded:n,onToggle:l}){const r=R(s);return e.jsxs("div",{className:"overflow-hidden rounded-2xl border border-border bg-white",children:[e.jsxs("button",{type:"button",onClick:l,className:"flex w-full items-center gap-4 px-4 py-3 text-left hover:bg-slate-50",children:[e.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-3",children:[e.jsxs("span",{className:"rounded-full px-2 py-0.5 text-[11px] font-semibold text-white",style:{background:"linear-gradient(135deg, #6E63FF, #4E8DFF)"},children:["T",s.turnIndex+1]}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-sm font-medium text-slate-900",children:le(s,t)}),e.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-2 text-[11px] text-slate-500",children:[e.jsxs("span",{children:["Total ",g(s.latencyMs)]}),e.jsxs("span",{children:["TTFT ",g(s.ttftMs)]}),e.jsxs("span",{children:["TPOT ",s.tpotMs!=null?`${s.tpotMs.toFixed(1)} ms/tok`:"-"]}),e.jsxs("span",{children:["↑ ",k(s.inputTokens)]}),e.jsxs("span",{children:["↓ ",k(s.outputTokens)]}),e.jsxs("span",{children:[r.length," tool calls"]}),s.error&&e.jsx("span",{className:"rounded-full bg-red-50 px-2 py-0.5 font-medium text-red-600",children:"Error"})]})]})]}),e.jsx(ue,{className:m("h-4 w-4 flex-shrink-0 text-slate-400 transition-transform",n&&"rotate-180")})]}),n&&e.jsxs("div",{className:"border-t border-border bg-slate-50/70 p-4",children:[e.jsxs("div",{className:"grid gap-3 xl:grid-cols-2",children:[e.jsx(ne,{title:"Request",payload:s.clientRequest,accentClass:"text-blue-600"}),e.jsx(ne,{title:"Response",payload:s.clientResponse,accentClass:"text-violet-600"})]}),e.jsxs("div",{className:"mt-3 grid gap-3 xl:grid-cols-[minmax(0,1fr)_280px]",children:[e.jsxs("div",{className:"rounded-xl border border-border bg-white p-3",children:[e.jsx("p",{className:"mb-2 text-[11px] font-semibold uppercase tracking-[0.16em] text-amber-600",children:"Tool Calls"}),e.jsx("pre",{className:"max-h-64 overflow-auto rounded-lg bg-slate-950/95 p-3 text-xs leading-5 text-slate-200",children:r.length>0?JSON.stringify(r,null,2):"(no tool calls)"})]}),e.jsxs("div",{className:"rounded-xl border border-border bg-white p-3",children:[e.jsx("p",{className:"mb-2 text-[11px] font-semibold uppercase tracking-[0.16em] text-slate-500",children:"Turn Metrics"}),e.jsxs("dl",{className:"grid grid-cols-2 gap-x-3 gap-y-2 text-xs",children:[e.jsxs("div",{children:[e.jsx("dt",{className:"text-slate-500",children:"Duration"}),e.jsx("dd",{className:"mt-0.5 font-medium text-slate-900",children:g(s.latencyMs)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-slate-500",children:"TTFT"}),e.jsx("dd",{className:"mt-0.5 font-medium text-slate-900",children:g(s.ttftMs)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-slate-500",children:"TPOT"}),e.jsx("dd",{className:"mt-0.5 font-medium text-slate-900",children:s.tpotMs!=null?`${s.tpotMs.toFixed(1)} ms/tok`:"-"})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-slate-500",children:"Status"}),e.jsx("dd",{className:"mt-0.5 font-medium text-slate-900",children:s.statusCode??"-"})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-slate-500",children:"Input"}),e.jsx("dd",{className:"mt-0.5 font-medium text-slate-900",children:k(s.inputTokens)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-slate-500",children:"Output"}),e.jsx("dd",{className:"mt-0.5 font-medium text-slate-900",children:k(s.outputTokens)})]})]}),s.error&&e.jsx("p",{className:"mt-3 rounded-lg border border-red-200 bg-red-50 px-3 py-2 text-xs text-red-700",children:s.error})]})]})]})]})}function Me({detail:s,expandedTurn:t,onToggleTurn:n}){if(s.records.length===0)return e.jsx(M,{compact:!0,className:"min-h-[220px]",title:"No turns recorded"});const l=L(s),r=s.records.reduce((o,x)=>{const C=x.latencyMs??0,w=x.ttftMs??0;return o+Math.max(C-w,0)},0),i=l>0?(r/l*100).toFixed(1):"-",a=s.records.map(o=>o.ttftMs).filter(o=>o!=null),u=s.records.map(o=>o.tpotMs).filter(o=>o!=null),p=a.length>0?a.reduce((o,x)=>o+x,0)/a.length:null,y=u.length>0?u.reduce((o,x)=>o+x,0)/u.length:null;return e.jsxs("div",{className:"space-y-5 p-5",children:[e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2 xl:grid-cols-6",children:[e.jsx(T,{label:"Total Duration",value:g(l),sub:`${s.records.length} turns`}),e.jsx(T,{label:"LLM Time",value:g(r),sub:`${i}% of session`,accentClass:"text-violet-700"}),e.jsx(T,{label:"Avg TTFT",value:g(p)}),e.jsx(T,{label:"Avg TPOT",value:y!=null?`${y.toFixed(1)} ms/tok`:"-"}),e.jsx(T,{label:"Input Tokens",value:k(s.totalInputTokens)}),e.jsx(T,{label:"Output Tokens",value:k(s.totalOutputTokens)})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-slate-900",children:"Per-Turn Breakdown"}),e.jsx("p",{className:"mt-1 text-xs text-slate-500",children:"Expand a turn to inspect request, response, tool calls, and errors."})]})}),s.records.map(o=>e.jsx(Te,{record:o,sessionStart:s.startedAt,expanded:t===o.turnIndex,onToggle:()=>n(o.turnIndex)},o.id))]})]})}function Ee(){var H,X;const s=pe(),[t,n]=f.useState(null),[l,r]=f.useState("timeline"),[i,a]=f.useState("request"),[u,p]=f.useState(0),[y,o]=f.useState(0),[x,C]=f.useState(""),h=((H=A({queryKey:b.profiler.status(),queryFn:()=>v.getStatus(),refetchInterval:3e3}).data)==null?void 0:H.active)??!1,J=A({queryKey:b.profiler.sessions({}),queryFn:()=>v.listSessions({limit:100}),refetchInterval:h?2e3:!1}),j=((X=J.data)==null?void 0:X.items)??[],P=A({queryKey:b.profiler.session(t),queryFn:()=>v.getSession(t),enabled:t!=null,refetchInterval:h&&t!=null?2e3:!1}),z=S({mutationFn:()=>v.start(),onSuccess:()=>{s.invalidateQueries({queryKey:b.profiler.status()}),s.invalidateQueries({queryKey:b.profiler.sessions({})})}}),U=S({mutationFn:()=>v.stop(),onSuccess:()=>{s.invalidateQueries({queryKey:b.profiler.status()}),s.invalidateQueries({queryKey:b.profiler.sessions({})})}}),G=S({mutationFn:d=>v.deleteSession(d),onSuccess:(d,N)=>{t===N&&n(null),s.invalidateQueries({queryKey:b.profiler.sessions({})})}}),ae=S({mutationFn:()=>v.clearAll(),onSuccess:()=>{n(null),s.invalidateQueries({queryKey:b.profiler.sessions({})})}}),V=f.useMemo(()=>{const d=x.trim().toLowerCase();return d?j.filter(N=>N.sessionId.toLowerCase().includes(d)):j},[x,j]),c=P.data,E=j.find(d=>d.id===t)??null,W=(c==null?void 0:c.records[u])??null;f.useEffect(()=>{t&&!j.some(d=>d.id===t)&&n(null)},[t,j]),f.useEffect(()=>{p(0),o(0),a("request")},[t]),f.useEffect(()=>{if(!c){p(0),o(0);return}p(d=>Math.min(d,Math.max(c.records.length-1,0))),o(d=>d==null?0:Math.min(d,Math.max(c.records.length-1,0)))},[c]);const re=()=>{c&&je(`profiler-${c.sessionId}.json`,c)};return e.jsxs("div",{className:"flex h-full min-h-0 flex-col",style:{height:"calc(100vh - 64px)"},children:[e.jsxs("div",{className:"flex items-center justify-between gap-4 border-b border-border bg-white px-6 py-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Y,{className:"h-5 w-5 text-indigo-500"}),e.jsx("span",{className:"text-base font-semibold text-slate-900",children:"Profiler"}),e.jsxs(se,{variant:"outline",className:m("rounded-full border px-2.5 py-1 text-xs font-semibold",h?"border-red-200 bg-red-50 text-red-600":"border-slate-200 bg-slate-50 text-slate-500"),children:[e.jsx("span",{className:m("mr-2 inline-block h-1.5 w-1.5 rounded-full",h?"bg-red-500":"bg-slate-400")}),h?"Recording":"Not Recording"]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx($,{size:"sm",variant:h?"destructive":"default",onClick:()=>h?U.mutate():z.mutate(),disabled:z.isPending||U.isPending,children:h?"Stop Recording":"Start Recording"}),e.jsxs($,{size:"sm",variant:"outline",onClick:re,disabled:!c,children:[e.jsx(ie,{className:"mr-1.5 h-3.5 w-3.5"}),"Export"]}),e.jsxs($,{size:"sm",variant:"outline",onClick:()=>ae.mutate(),disabled:j.length===0,className:"border-red-200 bg-red-50 text-red-700 hover:bg-red-100 hover:text-red-800",children:[e.jsx(Z,{className:"mr-1.5 h-3.5 w-3.5"}),"Clear"]})]})]}),e.jsxs("div",{className:"flex min-h-0 flex-1 overflow-hidden bg-[#F1F3F4]",children:[e.jsxs("div",{className:"flex w-80 flex-shrink-0 flex-col border-r border-border bg-white",children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-border px-4 py-3",children:[e.jsx("span",{className:"text-sm font-semibold text-slate-900",children:"Sessions"}),e.jsx(se,{variant:"secondary",className:"rounded-full px-2 py-0.5",children:j.length})]}),e.jsxs("div",{className:"flex items-center gap-2 border-b border-border px-3 py-2.5",children:[e.jsx(oe,{className:"h-3.5 w-3.5 text-slate-400"}),e.jsx("input",{className:"w-full bg-transparent text-sm outline-none placeholder:text-slate-400",placeholder:"Search sessions...",value:x,onChange:d=>C(d.target.value)})]}),e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto",children:J.isPending?e.jsx(ee,{compact:!0,className:"min-h-[160px]",label:"Loading..."}):V.length===0?e.jsx(M,{compact:!0,className:"m-4 min-h-[160px]",title:h?"Waiting for requests…":"No sessions",description:h?"Requests with session_id will appear here.":"Start recording to capture LLM sessions."}):V.map((d,N)=>e.jsx(Ne,{session:d,selected:t===d.id,index:N,onClick:()=>n(d.id)},d.id))})]}),e.jsx("div",{className:"flex min-w-0 flex-1 flex-col bg-white",children:t?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between gap-4 border-b border-border bg-white px-5 py-3",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2.5",children:[e.jsx("span",{className:"h-2.5 w-2.5 flex-shrink-0 rounded-full bg-indigo-500"}),e.jsx("span",{className:"truncate text-sm font-semibold text-slate-900",children:(c==null?void 0:c.sessionId)??(E==null?void 0:E.sessionId)??t}),e.jsx("span",{className:"text-slate-300",children:"·"}),e.jsx("span",{className:"truncate text-sm text-slate-500",children:c?`${c.turnCount} turns · ${I(L(c))} · ${K((c.totalInputTokens??0)+(c.totalOutputTokens??0))} tokens`:"Loading session…"})]}),e.jsx($,{variant:"ghost",size:"sm",onClick:()=>t&&G.mutate(t),disabled:!t||G.isPending,className:"text-slate-500 hover:text-red-700",children:e.jsx(Z,{className:"h-3.5 w-3.5"})})]}),e.jsx("div",{className:"border-b border-border bg-white px-5 py-2",children:e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(te,{active:l==="timeline",icon:de,label:"Timeline",onClick:()=>r("timeline")}),e.jsx(te,{active:l==="breakdown",icon:ce,label:"Breakdown",onClick:()=>r("breakdown")})]})}),e.jsx("div",{"data-testid":"profiler-session-content",className:"min-h-0 flex-1 overflow-auto bg-slate-50",children:P.isPending?e.jsx(ee,{compact:!0,className:"min-h-[240px]",label:"Loading session..."}):P.isError?e.jsx(M,{compact:!0,className:"m-5 min-h-[220px]",tone:"danger",title:"Failed to load session"}):c?l==="timeline"?e.jsx(we,{detail:c,selectedTurn:u,detailTab:i,onSelectTurn:p,onDetailTabChange:a}):e.jsx(Me,{detail:c,expandedTurn:y,onToggleTurn:d=>o(N=>N===d?null:d)}):e.jsx(M,{compact:!0,className:"m-5 min-h-[220px]",title:"Session not found"})}),W&&e.jsxs("span",{className:"sr-only",children:["Selected turn ",W.turnIndex+1]})]}):e.jsx("div",{className:"flex flex-1 items-center justify-center",children:e.jsx(M,{title:"Select a session",description:"Choose a session from the left to inspect its timeline, message payloads, and stats.",icon:e.jsx(Y,{className:"h-5 w-5"})})})})]})]})}export{Ee as default};