@chenpu17/cc-gw 0.8.0 → 0.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/package.json +5 -5
- package/src/web/dist/assets/{About-DockN9He.js → About-BCHV3wbt.js} +1 -1
- package/src/web/dist/assets/ApiKeys-Do48QVpZ.js +1 -0
- package/src/web/dist/assets/Dashboard-BizLDn_V.js +1 -0
- package/src/web/dist/assets/{DialogShell-BKB8x8Yv.js → DialogShell-CiIvBp8J.js} +1 -1
- package/src/web/dist/assets/EChart-VRAvk6sX.js +1 -0
- package/src/web/dist/assets/{Events-CmUNBQ-L.js → Events-DpPg8dt0.js} +1 -1
- package/src/web/dist/assets/{Help-Bo6GcOG7.js → Help-B9ewdIkl.js} +1 -1
- package/src/web/dist/assets/{Login-uKKAO1uN.js → Login-5O2Xtr5G.js} +1 -1
- package/src/web/dist/assets/{Logs-ChD1V5Mf.js → Logs-D29vlNyO.js} +1 -1
- package/src/web/dist/assets/{ModelManagement-DTlt9WMp.js → ModelManagement-CrmNhCAh.js} +1 -1
- package/src/web/dist/assets/{PageHeader-DWkUnwoU.js → PageHeader-CSF0BWul.js} +1 -1
- package/src/web/dist/assets/{PageSection-9-z2ysug.js → PageSection-Bp_SuEp0.js} +1 -1
- package/src/web/dist/assets/{PageState-5sxEzXut.js → PageState-BeXrzVEe.js} +1 -1
- package/src/web/dist/assets/{Profiler-DBeKtgDs.js → Profiler-Cwuq3cjV.js} +1 -1
- package/src/web/dist/assets/{Settings-YMHmPlBz.js → Settings-Q6TBItFQ.js} +1 -1
- package/src/web/dist/assets/{Skeleton-CvBK2w-C.js → Skeleton-8j6Dxod1.js} +1 -1
- package/src/web/dist/assets/{badge-tREH_88e.js → badge-BvMdmUqJ.js} +1 -1
- package/src/web/dist/assets/{card-yK3LQB_K.js → card-CjhYPqKk.js} +1 -1
- package/src/web/dist/assets/{charts-core-vuhzGmuT.js → charts-core-C-3-Lo7l.js} +1 -1
- package/src/web/dist/assets/{charts-engine-BJQRnjQ_.js → charts-engine-BI1CmRJo.js} +1 -1
- package/src/web/dist/assets/{charts-react-BeVWPrMt.js → charts-react-DJ_0LNAP.js} +1 -1
- package/src/web/dist/assets/{gateway-D-NOc-e6.js → gateway-B0gBBN92.js} +1 -1
- package/src/web/dist/assets/{i18n-CfLThlXq.js → i18n-C7VVFIdN.js} +1 -1
- package/src/web/dist/assets/index-BzuBtvAC.js +61 -0
- package/src/web/dist/assets/{input-CXrASgDm.js → input-BnFZKjRM.js} +1 -1
- package/src/web/dist/assets/{label-CzHv4dNP.js → label-i5-Lf72z.js} +1 -1
- package/src/web/dist/assets/{popover-C-WmNbKp.js → popover-EFz6sQ7C.js} +1 -1
- package/src/web/dist/assets/{query-D3IfCUhp.js → query-DxhDvnDC.js} +1 -1
- package/src/web/dist/assets/{radix-54BMi3RD.js → radix-CmyU-WBH.js} +1 -1
- package/src/web/dist/assets/{router-CmaL1NgV.js → router-D8u_RlVh.js} +1 -1
- package/src/web/dist/assets/{select-DH6I1mKJ.js → select-KdDvaKo4.js} +1 -1
- package/src/web/dist/assets/{switch-IXq8M3lq.js → switch-BVWWsjy3.js} +1 -1
- package/src/web/dist/assets/{useApiQuery-CCy5_Mc8.js → useApiQuery-fBWRSgFK.js} +1 -1
- package/src/web/dist/assets/{useAppMutation-COEUmNH4.js → useAppMutation-Cd6HN12q.js} +1 -1
- package/src/web/dist/assets/{vendor-CjJPKsTb.js → vendor-5iCEqDpV.js} +1 -1
- package/src/web/dist/index.html +6 -6
- package/src/web/dist/assets/ApiKeys-Fx_SaOSe.js +0 -1
- package/src/web/dist/assets/Dashboard-De61szKh.js +0 -1
- package/src/web/dist/assets/EChart-Dqa_Xbrn.js +0 -1
- package/src/web/dist/assets/index-BiTh8byX.js +0 -61
|
@@ -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-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
|
+
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-5iCEqDpV.js";import{u as Le,C as js}from"./useAppMutation-Cd6HN12q.js";import{P as ys}from"./PageHeader-CSF0BWul.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-BzuBtvAC.js";import{u as te}from"./i18n-C7VVFIdN.js";import{I as fe}from"./input-BnFZKjRM.js";import{L as J}from"./label-i5-Lf72z.js";import{S as gt,a as ht,b as ft,c as bt,d as me}from"./select-KdDvaKo4.js";import{S as qe}from"./switch-BVWWsjy3.js";import{q as he}from"./queryKeys-BMvyDTQS.js";import{B as H}from"./badge-BvMdmUqJ.js";import{C as Fe,a as Be}from"./card-CjhYPqKk.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-CiIvBp8J.js";import{P as Es,a as Ss,b as Ps}from"./popover-EFz6sQ7C.js";import{u as Ds,a as Rs}from"./query-DxhDvnDC.js";import{g as ye}from"./gateway-B0gBBN92.js";import{u as Ts}from"./useApiQuery-fBWRSgFK.js";import"./router-D8u_RlVh.js";import"./radix-CmyU-WBH.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-
|
|
1
|
+
import{j as e}from"./vendor-5iCEqDpV.js";import{c as i}from"./index-BzuBtvAC.js";import{B as c}from"./badge-BvMdmUqJ.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-
|
|
1
|
+
import{j as s}from"./vendor-5iCEqDpV.js";import{c as m}from"./index-BzuBtvAC.js";import{C as c,b as x,c as i,d as f,a as j}from"./card-CjhYPqKk.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-
|
|
1
|
+
import{j as e,P as c}from"./vendor-5iCEqDpV.js";import{c as i}from"./index-BzuBtvAC.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};
|