@chenpu17/cc-gw 0.8.0-alpha.2 → 0.8.0-alpha.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (24) hide show
  1. package/README.md +2 -2
  2. package/package.json +5 -5
  3. package/src/web/dist/assets/{About-CiTmsH3_.js → About-BWDRyUez.js} +1 -1
  4. package/src/web/dist/assets/{ApiKeys-6rCCLhIC.js → ApiKeys-DkOlFxcs.js} +1 -1
  5. package/src/web/dist/assets/{ConfirmDialog-A9gywPpz.js → ConfirmDialog-DFy4NI8g.js} +1 -1
  6. package/src/web/dist/assets/{Dashboard-BoZHGcx0.js → Dashboard-Csl3HA0l.js} +1 -1
  7. package/src/web/dist/assets/{Events-DAiVr1Fh.js → Events-BKTkKtKe.js} +1 -1
  8. package/src/web/dist/assets/{Help-5dtFavzf.js → Help-BcryNGLt.js} +1 -1
  9. package/src/web/dist/assets/{Login-Bf2fjws1.js → Login-Bi-LLRbT.js} +1 -1
  10. package/src/web/dist/assets/{Logs-63hL3C0b.js → Logs-BcNmJUBA.js} +1 -1
  11. package/src/web/dist/assets/{ModelManagement-Sh2TbDu3.js → ModelManagement-BL2IOQpn.js} +1 -1
  12. package/src/web/dist/assets/{PageHeader-BfplRrls.js → PageHeader-Da1cmUY0.js} +1 -1
  13. package/src/web/dist/assets/{PageSection-DLrvM7lY.js → PageSection-Bf8b2jG0.js} +1 -1
  14. package/src/web/dist/assets/{Settings-I4pHQi8Z.js → Settings-BVKO0J1z.js} +1 -1
  15. package/src/web/dist/assets/{Skeleton-m_JcEeRW.js → Skeleton-CN-bCufq.js} +1 -1
  16. package/src/web/dist/assets/{card-pQJ3gJlC.js → card-BD2y3CjZ.js} +1 -1
  17. package/src/web/dist/assets/{index-CB0xlluu.js → index-BuTkie0t.js} +2 -2
  18. package/src/web/dist/assets/{input-DmlfmLRF.js → input-BHq9dQGf.js} +1 -1
  19. package/src/web/dist/assets/{label-WnrqWaUM.js → label-CUv6yhdE.js} +1 -1
  20. package/src/web/dist/assets/{popover-BGLA6gjb.js → popover-0Ho_T06s.js} +1 -1
  21. package/src/web/dist/assets/{select-f3RCxJ98.js → select-Dq7kCMCk.js} +1 -1
  22. package/src/web/dist/assets/{switch-BSgZEVkb.js → switch-NOIFebYg.js} +1 -1
  23. package/src/web/dist/assets/{useApiQuery-BGQDgPyp.js → useApiQuery-BkAH5SvI.js} +1 -1
  24. package/src/web/dist/index.html +1 -1
@@ -1 +1 @@
1
- import{r as x,f as e,aj as Ve,$ as rs,a5 as _e,ad as as,ak as ce,k as ns,N as ht,af as os}from"./vendor-C92xTG6Z.js";import{u as ds,a as ls,b as lt}from"./query-CDpWKdnY.js";import{c as Z,u as gt,B as P,a as Y,b as ve,t as Te,T as is,d as cs,f as ms,g as us}from"./index-CB0xlluu.js";import{u as ps}from"./useApiQuery-BGQDgPyp.js";import{P as xs,B as F}from"./PageHeader-BfplRrls.js";import{C as hs,D as ft,a as bt,b as vt,c as jt,d as yt,e as Nt}from"./ConfirmDialog-A9gywPpz.js";import{I as re}from"./input-DmlfmLRF.js";import{L as Q}from"./label-WnrqWaUM.js";import{C as Re,a as De}from"./card-pQJ3gJlC.js";import{S as wt}from"./switch-BSgZEVkb.js";import{S as kt,a as Mt,b as Ct,c as Et,d as W}from"./select-f3RCxJ98.js";import{P as gs,a as fs,b as bs}from"./popover-BGLA6gjb.js";import{u as me}from"./i18n-CZ1qKIdj.js";import"./router-DjNibHfR.js";import"./radix-Ccu1urVd.js";function qe(){return typeof globalThis.crypto<"u"&&typeof globalThis.crypto.randomUUID=="function"?globalThis.crypto.randomUUID():Math.random().toString(36).slice(2,10)}function vs(){return{_key:qe(),id:"",label:""}}const Pe={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:{}},it=[{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 ct(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(l=>({...l,_key:qe()})),authMode:s.authMode??"apiKey"}:{id:"",label:"",baseUrl:"",apiKey:"",type:"custom",defaultModel:"",models:[],authMode:"apiKey"}}function js(s){return{_key:qe(),id:s.id,label:s.label}}function ys({open:s,mode:l,provider:f,existingProviderIds:h,onClose:p,onSubmit:j}){const{t:r}=me(),[i,w]=x.useState(()=>ct(f)),[S,I]=x.useState({}),[U,g]=x.useState(!1),[C,k]=x.useState(null),v=x.useRef(null),E=x.useRef(null),$=x.useRef(null),[L,ae]=x.useState(l==="edit");x.useEffect(()=>{s&&(w(ct(f)),I({}),k(null),g(!1),ae(l==="edit"))},[s,f,l]),x.useEffect(()=>{if(!s)return;const c=b=>{b.key==="Escape"&&p()};return window.addEventListener("keydown",c),()=>window.removeEventListener("keydown",c)},[s,p]),x.useEffect(()=>{if(s){if(l==="create"&&$.current){$.current.focus();return}E.current&&E.current.focus()}},[s,l]);const ne=l==="create",oe=x.useMemo(()=>i.models.filter(c=>c.id.trim().length>0),[i.models]),je=x.useMemo(()=>{var c;return((c=it.find(b=>b.value===i.type))==null?void 0:c.label)??"Custom"},[i.type]),ye=i.label.trim()||i.id.trim()||r("providers.drawer.summary.untitled"),Ne=x.useMemo(()=>[{label:r("providers.drawer.summary.type"),value:je},{label:r("providers.drawer.summary.auth"),value:i.authMode==="apiKey"?r("providers.drawer.fields.authModeApiKey"):i.authMode==="authToken"?r("providers.drawer.fields.authModeAuthToken"):r("providers.drawer.fields.authModeXAuthToken")},{label:r("providers.drawer.summary.models"),value:oe.length.toLocaleString()}],[oe.length,i.authMode,je,r]),de=c=>b=>{w(R=>({...R,[c]:b}))},G=c=>{w(b=>{const M=!L||b.label.trim().length===0||b.label===b.id?c:b.label;return{...b,id:c,label:M}})},B=c=>{w(b=>{var Ce;const M=Pe[c??"custom"]??Pe.custom,_=Object.values(Pe).map(te=>te.baseUrl).filter(te=>!!te),q=!b.baseUrl||_.includes(b.baseUrl),z=l==="create"&&(b.models.length===0||b.models.every(te=>te.id.trim().length===0)),X={...b,type:c,authMode:b.authMode??"apiKey"};return M!=null&&M.baseUrl&&q&&(X.baseUrl=M.baseUrl),M!=null&&M.models&&z&&(X.models=M.models.map(js),X.defaultModel=M.defaultModel??((Ce=M.models[0])==null?void 0:Ce.id)??""),X})},Oe=(c,b)=>{w(R=>{const M=[...R.models];return M[c]={...M[c],...b},{...R,models:M}})},H=(c,b)=>{w(R=>{const M=[...R.models],_=M[c];if(!_)return R;const q=!L||!_.label||_.label===_.id,z={..._,id:b,label:q?b:_.label};M[c]=z;const X=R.defaultModel===_.id?b:R.defaultModel;return{...R,models:M,defaultModel:X}})},Ue=c=>{w(b=>{if(c<0||c>=b.models.length)return b;const R=b.models.filter((_,q)=>q!==c);let M=b.defaultModel;return R.some(_=>_.id===M)||(M=""),{...b,models:R,defaultModel:M}})},we=()=>{w(c=>({...c,models:[...c.models,vs()]}))},le=c=>{w(b=>({...b,authMode:c}))},ue=()=>{const c={},b=i.id.trim(),R=i.baseUrl.trim();if(l==="create"&&(b.length===0?c.id=r("providers.drawer.errors.idRequired"):h.includes(b)&&(c.id=r("providers.drawer.errors.idDuplicate"))),l==="edit"&&b.length===0&&(c.id=r("providers.drawer.errors.idRequired")),R.length===0)c.baseUrl=r("providers.drawer.errors.baseUrlInvalid");else try{new URL(R)}catch{c.baseUrl=r("providers.drawer.errors.baseUrlInvalid")}if(i.models.length>0){const M=new Set;i.models.some(q=>{const z=q.id.trim();return z.length===0||M.has(z)?!0:(M.add(z),!1)})&&(c.models=r("providers.drawer.errors.modelInvalid"))}return i.defaultModel&&!i.models.some(M=>M.id===i.defaultModel)&&(c.models=r("providers.drawer.errors.defaultInvalid")),I(c),Object.keys(c).length===0},ke=()=>{const c=i.models.map(M=>{var _;return{id:M.id.trim(),label:(_=M.label)!=null&&_.trim()?M.label.trim():void 0}}).filter(M=>M.id.length>0),b=f!=null&&f.extraHeaders&&Object.keys(f.extraHeaders).length>0?f.extraHeaders:void 0,R=i.authMode!=="apiKey"?i.authMode:void 0;return{id:i.id.trim(),label:i.label.trim()||i.id.trim(),baseUrl:i.baseUrl.trim(),apiKey:i.apiKey.trim()||void 0,type:i.type??"custom",defaultModel:i.defaultModel||void 0,models:c.length>0?c:void 0,extraHeaders:b,authMode:R}},Me=async()=>{if(k(null),!!ue()){g(!0);try{const c=ke();await j(c)}catch(c){k(r("providers.drawer.toast.saveFailure",{message:c instanceof Error?c.message:"unknown"})),g(!1);return}g(!1),p()}};return s?e.jsxs("div",{className:"fixed inset-0 z-50 flex",children:[e.jsx("div",{className:"flex-1 bg-slate-900/60 backdrop-blur-sm",onClick:p,"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-white/50 bg-background/96 shadow-[0_24px_80px_-32px_rgba(15,23,42,0.4)] backdrop-blur-xl dark:border-slate-800 dark:bg-slate-950/96",children:[e.jsxs("header",{className:"border-b border-border/70 bg-background/70 px-6 py-5 dark:border-slate-800",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:r(ne?"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:r(ne?"providers.drawer.createTitle":"providers.drawer.editTitle")}),e.jsx("p",{id:"provider-drawer-desc",className:"text-sm text-muted-foreground",children:r("providers.drawer.description")})]})]}),e.jsx("button",{type:"button",ref:E,onClick:p,className:"rounded-full border border-border/80 bg-background/85 px-4 py-2 text-sm transition hover:border-primary/20 hover:bg-primary/5",children:r("common.actions.close")})]}),e.jsx("div",{className:"mt-4 grid gap-3 md:grid-cols-3",children:Ne.map(c=>e.jsxs("div",{className:"rounded-[1.2rem] border border-white/50 bg-card/88 px-4 py-3 shadow-[0_1px_2px_rgba(15,23,42,0.03)]",children:[e.jsx("p",{className:"text-[11px] font-medium uppercase tracking-[0.16em] text-muted-foreground",children:c.label}),e.jsx("p",{className:"mt-2 text-sm font-semibold text-foreground",children:c.value})]},c.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:r("providers.drawer.sections.type")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:r("providers.drawer.hints.type")})]}),e.jsx("div",{className:"grid gap-2 md:grid-cols-3",children:it.map(c=>{var R;const b=c.value===i.type;return e.jsxs("button",{type:"button",onClick:()=>B(c.value),className:Z("rounded-2xl border px-4 py-3 text-left transition",b?"border-primary bg-primary/10 text-primary shadow-sm":"border-white/50 bg-card/88 text-foreground hover:border-primary/20 hover:bg-primary/5"),children:[e.jsx("div",{className:"text-sm font-semibold",children:c.label}),e.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:((R=Pe[c.value??"custom"])==null?void 0:R.baseUrl)??r("providers.drawer.hints.customProvider")})]},c.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:r("providers.drawer.sections.basic")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:r("providers.drawer.hints.basic")})]}),e.jsx("button",{type:"button",onClick:()=>ae(c=>!c),className:"rounded-full border border-border/80 bg-background/85 px-3 py-1.5 text-xs transition hover:border-primary/20 hover:bg-primary/5",children:r(L?"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:r("providers.drawer.fields.id")}),e.jsx("input",{value:i.id,ref:$,onChange:c=>G(c.target.value),disabled:!ne,placeholder:r("providers.drawer.fields.idPlaceholder"),className:"h-11 rounded-2xl border border-border/80 bg-background/85 px-4 py-2 text-sm shadow-[0_1px_2px_rgba(15,23,42,0.03)] transition-all duration-200 focus:border-primary/40 focus:outline-none focus:ring-2 focus:ring-primary/20 disabled:bg-muted/60 disabled:text-muted-foreground","aria-invalid":!!S.id}),S.id?e.jsx("span",{className:"text-xs text-red-500",children:S.id}):null]}),e.jsxs("label",{className:"flex flex-col gap-2 text-sm",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:r("providers.drawer.fields.label")}),e.jsx("input",{value:i.label,onChange:c=>de("label")(c.target.value),placeholder:r("providers.drawer.fields.labelPlaceholder"),className:"h-11 rounded-2xl border border-border/80 bg-background/85 px-4 py-2 text-sm shadow-[0_1px_2px_rgba(15,23,42,0.03)] transition-all duration-200 focus:border-primary/40 focus:outline-none focus:ring-2 focus:ring-primary/20 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:r("providers.drawer.fields.baseUrl")}),e.jsx("input",{value:i.baseUrl,onChange:c=>de("baseUrl")(c.target.value),placeholder:r("providers.drawer.fields.baseUrlPlaceholder"),className:"h-11 rounded-2xl border border-border/80 bg-background/85 px-4 py-2 text-sm shadow-[0_1px_2px_rgba(15,23,42,0.03)] transition-all duration-200 focus:border-primary/40 focus:outline-none focus:ring-2 focus:ring-primary/20 disabled:bg-muted/60 disabled:text-muted-foreground","aria-invalid":!!S.baseUrl}),S.baseUrl?e.jsx("span",{className:"text-xs text-red-500",children:S.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:r("providers.drawer.sections.auth")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:r("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:r("providers.drawer.fields.apiKey")}),e.jsx("input",{value:i.apiKey,onChange:c=>de("apiKey")(c.target.value),placeholder:r("providers.drawer.fields.apiKeyPlaceholder"),className:"h-11 rounded-2xl border border-border/80 bg-background/85 px-4 py-2 text-sm shadow-[0_1px_2px_rgba(15,23,42,0.03)] transition-all duration-200 focus:border-primary/40 focus:outline-none focus:ring-2 focus:ring-primary/20 disabled:bg-muted/60 disabled:text-muted-foreground"})]}),e.jsxs("fieldset",{className:"grid gap-2 rounded-[1.3rem] border border-white/50 bg-card/88 p-4 text-xs shadow-[0_1px_2px_rgba(15,23,42,0.03)]",children:[e.jsx("legend",{className:"px-1 text-muted-foreground",children:r("providers.drawer.fields.authMode")}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:r("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:i.authMode==="apiKey",onChange:()=>le("apiKey"),className:"mt-0.5"}),e.jsx("span",{children:r("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:i.authMode==="authToken",onChange:()=>le("authToken"),className:"mt-0.5"}),e.jsx("span",{children:r("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:i.authMode==="xAuthToken",onChange:()=>le("xAuthToken"),className:"mt-0.5"}),e.jsx("span",{children:r("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:r("providers.drawer.fields.models")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:r("providers.drawer.modelsDescription")})]}),e.jsx("button",{type:"button",onClick:we,className:"rounded-full border border-border/80 bg-background/85 px-3 py-1.5 text-xs transition hover:border-primary/20 hover:bg-primary/5",children:r("providers.drawer.fields.addModel")})]}),S.models?e.jsx("p",{className:"text-xs text-red-500",children:S.models}):null,e.jsxs("div",{className:"space-y-4",children:[i.models.map((c,b)=>e.jsxs("div",{className:"rounded-[1.3rem] border border-white/50 bg-card/88 p-4 shadow-[0_1px_2px_rgba(15,23,42,0.03)]",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:r("providers.drawer.fields.modelId")}),e.jsx("input",{value:c.id,onChange:R=>H(b,R.target.value),placeholder:r("providers.drawer.fields.modelIdPlaceholder"),className:"h-11 rounded-2xl border border-border/80 bg-background/85 px-4 py-2 text-sm shadow-[0_1px_2px_rgba(15,23,42,0.03)] transition-all duration-200 focus:border-primary/40 focus:outline-none focus:ring-2 focus:ring-primary/20 disabled:bg-muted/60 disabled:text-muted-foreground"})]}),L?e.jsxs("label",{className:"flex flex-col gap-2 text-sm",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:r("providers.drawer.fields.modelLabel")}),e.jsx("input",{value:c.label??"",onChange:R=>Oe(b,{label:R.target.value}),placeholder:r("providers.drawer.fields.modelLabelPlaceholder"),className:"h-11 rounded-2xl border border-border/80 bg-background/85 px-4 py-2 text-sm shadow-[0_1px_2px_rgba(15,23,42,0.03)] transition-all duration-200 focus:border-primary/40 focus:outline-none focus:ring-2 focus:ring-primary/20 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-slate-600 dark:text-slate-300",children:[e.jsx("input",{type:"radio",name:"defaultModel",value:c.id,checked:i.defaultModel===c.id,onChange:()=>w(R=>({...R,defaultModel:c.id})),disabled:c.id.trim().length===0}),r("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:()=>Ue(b),disabled:i.models.length===0,children:r("providers.drawer.fields.removeModel")})]})]},c._key)),i.models.length===0?e.jsx("div",{className:"rounded-2xl border border-amber-300 bg-gradient-to-br from-amber-50 to-yellow-50 p-5 shadow-sm dark:border-amber-600/60 dark:from-amber-900/20 dark:to-yellow-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:r("providers.drawer.noModelsTitle")}),e.jsx("p",{className:"text-xs leading-relaxed text-amber-800 dark:text-amber-300",children:r("providers.drawer.noModelsHint",{providerId:i.id||"provider-id"})}),e.jsxs("div",{className:"rounded-md bg-amber-100/80 p-2.5 dark:bg-amber-800/40",children:[e.jsx("p",{className:"mb-1.5 text-xs font-medium text-amber-900 dark:text-amber-200",children:r("providers.drawer.routeExample")}),e.jsxs("code",{className:"block rounded-xl bg-white/90 px-2.5 py-1.5 font-mono text-xs text-amber-900 shadow-[0_1px_2px_rgba(15,23,42,0.06)] dark:bg-slate-900 dark:text-amber-100",children:['"claude-*": "',(i.id||"provider-id").trim()||"provider-id",':*"']})]})]})}):null]}),oe.length>1?e.jsx("div",{className:"text-xs text-muted-foreground",children:r("providers.drawer.defaultHint",{model:i.defaultModel||r("providers.card.noDefault")})}):null]})]}),e.jsx("aside",{className:"hidden border-l border-border/70 bg-background/55 px-5 py-5 xl:block",children:e.jsxs("div",{className:"sticky top-0 space-y-5",children:[e.jsxs("div",{className:"rounded-[1.3rem] border border-white/50 bg-card/92 p-4 shadow-[0_1px_2px_rgba(15,23,42,0.03)]",children:[e.jsx("p",{className:"text-[11px] font-medium uppercase tracking-[0.16em] text-muted-foreground",children:r("providers.drawer.formSummary")}),e.jsx("p",{className:"mt-2 text-base font-semibold",children:ye}),e.jsx("div",{className:"mt-4 space-y-3 text-sm",children:Ne.map(c=>e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsx("span",{className:"text-muted-foreground",children:c.label}),e.jsx("span",{className:"text-right font-medium",children:c.value})]},c.label))})]}),e.jsxs("div",{className:"rounded-[1.3rem] border border-white/50 bg-card/92 p-4 shadow-[0_1px_2px_rgba(15,23,42,0.03)]",children:[e.jsx("p",{className:"text-[11px] font-medium uppercase tracking-[0.16em] text-muted-foreground",children:r("providers.drawer.sections.checklist")}),e.jsxs("ul",{className:"mt-3 space-y-2 text-sm text-muted-foreground",children:[e.jsx("li",{children:r("providers.drawer.hints.checkUrl")}),e.jsx("li",{children:r("providers.drawer.hints.checkAuth")}),e.jsx("li",{children:r("providers.drawer.hints.checkModels")})]})]}),L&&e.jsxs("div",{className:"rounded-[1.3rem] border border-primary/20 bg-primary/5 p-4 text-sm text-foreground",children:[e.jsx("p",{className:"font-medium text-primary",children:r("providers.drawer.hints.advancedTitle")}),e.jsx("p",{className:"mt-2 text-xs text-muted-foreground",children:r("providers.drawer.hints.advancedBody")})]})]})})]}),e.jsxs("footer",{className:"flex items-center justify-between gap-3 border-t border-border/70 bg-background/70 px-6 py-4 text-sm",children:[e.jsx("div",{className:"flex flex-col text-xs text-red-500","aria-live":"polite",children:C?e.jsx("span",{children:C}):null}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{type:"button",onClick:p,className:"rounded-full border border-border/80 bg-background/85 px-4 py-2 transition hover:border-primary/20 hover:bg-primary/5",disabled:U,children:r("common.actions.cancel")}),e.jsx("button",{type:"button",onClick:Me,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:U,children:r(U?"common.actions.saving":"common.actions.save")})]})]})]})]}):null}const Ns=["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"],ws=["gpt-4o-mini","gpt-4o","o4-mini","o4-large","gpt-5-codex"];function He(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():Math.random().toString(36).slice(2,10)}function ee(s){return s?Object.entries(s).map(([l,f])=>({id:He(),source:l,target:f})):[]}function ze(s,l){var p,j,r;if(!s)return{};const f={},h=s.endpointRouting??{};f.anthropic=ee(((p=h.anthropic)==null?void 0:p.modelRoutes)??s.modelRoutes??{}),f.openai=ee(((j=h.openai)==null?void 0:j.modelRoutes)??{});for(const i of l)(r=i.routing)!=null&&r.modelRoutes?f[i.id]=ee(i.routing.modelRoutes):f[i.id]=[];return f}function mt(s,l,f){var j,r,i;const h=l.find(w=>w.id===f);if(h)return((j=h.routing)==null?void 0:j.modelRoutes)??{};const p=s.endpointRouting??{};return f==="anthropic"?((r=p.anthropic)==null?void 0:r.modelRoutes)??s.modelRoutes??{}:f==="openai"?((i=p.openai)==null?void 0:i.modelRoutes)??{}:{}}function ks(s){const l={};for(const f of s){const h=f.source.trim(),p=f.target.trim();h&&p&&(l[h]=p)}return l}function ut(s,l){return JSON.stringify(ks(s))!==JSON.stringify(l)}function Ms(s,l){if(s==="anthropic")return!0;const f=l.find(h=>h.id===s);return f?f.paths&&f.paths.length>0?f.paths.some(h=>h.protocol==="anthropic"):f.protocol==="anthropic":!1}function Cs(s,l,f){var p,j,r;if(!l)return;if(s==="anthropic"||s==="openai")return(j=(p=l.endpointRouting)==null?void 0:p[s])==null?void 0:j.validation;const h=f.find(i=>i.id===s);return(r=h==null?void 0:h.routing)==null?void 0:r.validation}function Qs(){const{t:s}=me(),{pushToast:l}=gt(),f=ds(),h=ps(["config","full"],{url:"/api/config",method:"GET"}),{data:p}=ls({queryKey:["custom-endpoints"],queryFn:ve.list,refetchInterval:1e4}),j=(p==null?void 0:p.endpoints)??[],r=x.useMemo(()=>{const t=[{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"]}],n=j.map(a=>{let o,d=[];if(a.paths&&a.paths.length>0){const m=a.paths.map(u=>`${u.path} (${u.protocol})`).join(", ");o=`${s("modelManagement.tabs.customEndpoint")}: ${m}`,d=[...new Set(a.paths.map(u=>u.protocol))]}else if(a.path){const m=a.protocol||"anthropic";o=`${s("modelManagement.tabs.customEndpoint")}: ${a.path} (${m})`,d=[m]}else o=s("modelManagement.tabs.customEndpoint");return{key:a.id,label:a.label,description:o,isSystem:!1,canDelete:a.deletable!==!1,protocols:d}});return[...t,...n]},[s,j]),[i,w]=x.useState("providers"),S=x.useMemo(()=>r.filter(t=>t.isSystem),[r]),I=x.useMemo(()=>r.filter(t=>!t.isSystem),[r]),U=x.useMemo(()=>r.find(t=>t.key===i)??r[0]??null,[i,r]),[g,C]=x.useState(null),[k,v]=x.useState(!1),[E,$]=x.useState("create"),[L,ae]=x.useState(void 0),[ne,oe]=x.useState(null),[je,ye]=x.useState(!1),[Ne,de]=x.useState(void 0),[G,B]=x.useState({}),[Oe,H]=x.useState({}),[Ue,we]=x.useState(null),[le,ue]=x.useState({}),[ke,Me]=x.useState({}),[c,b]=x.useState({}),[R,M]=x.useState(null),[_,q]=x.useState(null),[z,X]=x.useState(null),[Ce,te]=x.useState(!1),[$e,Qe]=x.useState(null),[Ee,Ae]=x.useState(!0),[Ge,Xe]=x.useState({}),[St,Je]=x.useState(!1),[Rt,Dt]=x.useState({}),[Le,Ie]=x.useState(null),[N,pe]=x.useState(null),[Fe,Ye]=x.useState(!1),[Se,We]=x.useState(""),[xe,Ze]=x.useState("all"),V=(g==null?void 0:g.providers)??[],et=V.length,tt=x.useMemo(()=>V.filter(t=>{var d;if(!(xe==="all"||(t.type??"custom")===xe))return!1;const a=Se.trim().toLowerCase();return a?[t.id,t.label??"",t.baseUrl,t.defaultModel??"",...((d=t.models)==null?void 0:d.map(m=>m.id))??[]].join(" ").toLowerCase().includes(a):!0}),[Se,xe,V]),he=x.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]);x.useEffect(()=>{var t,n;if(h.data){const a=h.data;C(a),B(d=>{const m=ze(a,j);if(!d||Object.keys(d).length===0)return m;const u={...m};for(const[y,D]of Object.entries(d)){if(!(y in m))continue;const A=mt(a,j,y);ut(D,A)&&(u[y]=D)}return u}),H({});const o={anthropic:((t=a.routingPresets)==null?void 0:t.anthropic)??[],openai:((n=a.routingPresets)==null?void 0:n.openai)??[]};for(const d of j)o[d.id]=d.routingPresets??[];ue(o)}},[h.data,j]),x.useEffect(()=>{h.isError&&h.error&&l({title:s("providers.toast.loadFailure",{message:h.error.message}),variant:"error"})},[h.isError,h.error,l,s]);const st=x.useMemo(()=>{const t=new Map;for(const n of V){if(!n.defaultModel||!n.models)continue;const a=n.models.find(o=>o.id===n.defaultModel);a&&t.set(n.id,xt(a))}return t},[V]),Pt=x.useMemo(()=>{const t=[],n=new Set;for(const o of V){const d=o.label&&o.label!==o.id?`${o.label} (${o.id})`:o.id,m=o.models??[];if(m.length>0)for(const y of m){const D=`${o.id}:${y.id}`;n.has(D)||(n.add(D),t.push({value:D,label:`${d} · ${y.label??y.id}`}))}else if(o.defaultModel){const y=`${o.id}:${o.defaultModel}`;n.has(y)||(n.add(y),t.push({value:y,label:`${d} · ${o.defaultModel}`}))}const u=`${o.id}:*`;n.has(u)||(n.add(u),t.push({value:u,label:s("settings.routing.providerPassthroughOption",{provider:d})}))}const a=Object.values(G).flat();for(const o of a){const d=o.target.trim();d&&!n.has(d)&&(n.add(d),t.push({value:d,label:d}))}return t},[V,G,s]),_t=t=>g?mt(g,j,t):{},Tt=(t,n)=>ut(t,n),Ke=x.useMemo(()=>{const t={};for(const n of r){if(n.key==="providers")continue;const a=G[n.key]||[],o=_t(n.key);t[n.key]=Tt(a,o)}return t},[G,g,j,r]),rt=(t,n)=>{ue(a=>({...a,[t]:n})),C(a=>{if(!a)return a;if(t==="anthropic"||t==="openai")return{...a,routingPresets:{...a.routingPresets,[t]:n}};const o=a.customEndpoints??[],d=o.findIndex(u=>u.id===t);if(d===-1)return a;const m=[...o];return m[d]={...m[d],routingPresets:n},{...a,customEndpoints:m}})},se=()=>g?!0:(l({title:s("settings.toast.missingConfig"),variant:"error"}),h.refetch(),!1),Ot=(t,n)=>{Me(a=>({...a,[t]:n})),n.trim()&&b(a=>({...a,[t]:null}))},Ut=async t=>{if(!se())return;const n=ke[t].trim();if(!n){b(a=>({...a,[t]:s("modelManagement.validation.presetName")}));return}if(le[t].some(a=>a.name.toLowerCase()===n.toLowerCase())){b(a=>({...a,[t]:s("modelManagement.validation.presetDuplicate",{name:n})}));return}M(t);try{const o=(await Y.post(`/api/routing-presets/${t}`,{name:n})).data.presets??[];rt(t,o),Me(d=>({...d,[t]:""})),b(d=>({...d,[t]:null})),l({title:s("modelManagement.toast.presetSaved",{name:n}),variant:"success"})}catch(a){l({title:s("modelManagement.toast.presetSaveFailure",{message:a instanceof Error?a.message:"unknown"}),variant:"error"})}finally{M(null),h.refetch()}},$t=async(t,n)=>{var a,o,d;if(se()){q({endpoint:t,name:n.name});try{const u=(await Y.post(`/api/routing-presets/${t}/apply`,{name:n.name})).data.config;if(u){C(u),B(ze(u,j));const y={anthropic:((a=u.routingPresets)==null?void 0:a.anthropic)??[],openai:((o=u.routingPresets)==null?void 0:o.openai)??[]};for(const D of j){const A=(d=u.customEndpoints)==null?void 0:d.find(T=>T.id===D.id);y[D.id]=(A==null?void 0:A.routingPresets)??[]}ue(y)}else B(y=>({...y,[t]:ee(n.modelRoutes)}));l({title:s("modelManagement.toast.presetApplySuccess",{name:n.name}),variant:"success"})}catch(m){l({title:s("modelManagement.toast.presetApplyFailure",{message:m instanceof Error?m.message:"unknown"}),variant:"error"})}finally{q(null),h.refetch()}}},At=async(t,n)=>{if(se()){X({endpoint:t,name:n.name});try{const o=(await Y.delete(`/api/routing-presets/${t}/${encodeURIComponent(n.name)}`)).data.presets??[];rt(t,o),l({title:s("modelManagement.toast.presetDeleteSuccess",{name:n.name}),variant:"success"})}catch(a){l({title:s("modelManagement.toast.presetDeleteFailure",{message:a instanceof Error?a.message:"unknown"}),variant:"error"})}finally{X(null),h.refetch()}}},Lt=()=>{se()&&($("create"),ae(void 0),v(!0))},It=t=>{se()&&($("edit"),ae(t),v(!0))},Ft=async t=>{if(!g)throw new Error(s("settings.toast.missingConfig"));const n=E==="create"?[...V,t]:V.map(d=>L&&d.id===L.id?{...t,id:L.id}:d),a={...g,providers:n};await Y.put("/api/config",a),C(a),B(ze(a,j)),h.refetch();const o=E==="create"?s("providers.toast.createSuccess",{name:t.label||t.id}):s("providers.toast.updateSuccess",{name:t.label||t.id});l({title:o,variant:"success"})},Kt=async t=>{const n=j.find(a=>a.id===t);if(n&&n.deletable!==!1)try{await ve.delete(t),f.invalidateQueries({queryKey:["custom-endpoints"]}),l({title:s("modelManagement.deleteEndpointSuccess"),variant:"success"}),i===t&&w("providers")}catch(a){const o=Te(a);l({title:s("modelManagement.deleteEndpointError",{error:o.message}),variant:"error"})}},at=async(t,n)=>{oe(t.id);try{const a=n&&(n.headers||n.query)?{headers:n.headers&&Object.keys(n.headers).length>0?n.headers:void 0,query:n.query&&n.query.trim().length>0?n.query.trim():void 0}:void 0,o=await Y.post(`/api/providers/${t.id}/test`,a);o.data.ok?l({title:s("providers.toast.testSuccess"),description:s("providers.toast.testSuccessDesc",{status:o.data.status,duration:o.data.durationMs?`${o.data.durationMs} ms`:"—"}),variant:"success"}):l({title:s("providers.toast.testFailure",{message:`${o.data.status} ${o.data.statusText}`}),variant:"error"})}catch(a){l({title:s("providers.toast.testFailure",{message:a instanceof Error?a.message:"unknown"}),variant:"error"})}finally{oe(null)}},Bt=t=>{if(t.type==="anthropic"){const n=t.extraHeaders??{},a=new Map(he.map(m=>[m.key.toLowerCase(),m])),o={};let d=!0;for(const m of he){const u=Object.entries(n).find(([y])=>y.toLowerCase()===m.key.toLowerCase());if(u){const[y,D]=u;String(D??"")===m.value||(d=!1,o[y]=String(D??""))}}for(const[m,u]of Object.entries(n))a.has(m.toLowerCase())||(o[m]=String(u??""));Xe(o),Ae(d),Qe(t),te(!0);return}at(t)},nt=()=>{te(!1),Qe(null),Ae(!0),Xe({})},zt=async()=>{if(!$e)return;const t={};if(Ee)for(const o of he)t[o.key]=o.value;const n=new Map(he.map(o=>[o.key.toLowerCase(),o]));for(const[o,d]of Object.entries(Ge)){const m=o.toLowerCase();n.get(m)&&Ee||(t[o]=d)}const a=$e;nt(),await at(a,{headers:Object.keys(t).length>0?t:void 0,query:Ee?"beta=true":void 0})},Vt=async t=>{var y,D,A,T;if(!se())return;const n=V.filter(K=>K.id!==t.id),a=K=>{const J={};if(!K)return J;for(const[ge,ie]of Object.entries(K)){if(!ie)continue;const[fe]=ie.split(":");fe&&fe===t.id||ie===t.id||(J[ge]=ie)}return J},o=(g==null?void 0:g.endpointRouting)??{},d=a(((y=o.anthropic)==null?void 0:y.modelRoutes)??(g==null?void 0:g.modelRoutes)??{}),m=a(((D=o.openai)==null?void 0:D.modelRoutes)??{}),u={...g,providers:n,modelRoutes:d,endpointRouting:{anthropic:{defaults:((A=o.anthropic)==null?void 0:A.defaults)??g.defaults,modelRoutes:d},openai:{defaults:((T=o.openai)==null?void 0:T.defaults)??g.defaults,modelRoutes:m}}};try{await Y.put("/api/config",u),C(u),B({anthropic:ee(d),openai:ee(m)}),l({title:s("providers.toast.deleteSuccess",{name:t.label||t.id}),variant:"success"}),h.refetch()}catch(K){l({title:s("providers.toast.deleteFailure",{message:K instanceof Error?K.message:"unknown"}),variant:"error"})}},Ht=async()=>{if(N){Ye(!0);try{N.kind==="provider"?await Vt(N.provider):N.kind==="preset"?await At(N.endpoint,N.preset):await Kt(N.endpoint.id),pe(null)}finally{Ye(!1)}}},qt=t=>{B(n=>({...n,[t]:[...n[t]||[],{id:He(),source:"",target:""}]})),H(n=>({...n,[t]:null}))},Qt=async(t,n)=>{if(se()){Je(!0);try{if(t==="anthropic"||t==="openai"){const a=g.endpointRouting?{...g.endpointRouting}:{},o=a[t]??{defaults:g.defaults,modelRoutes:(t==="anthropic"?g.modelRoutes:{})??{}},d={defaults:o.defaults??g.defaults,modelRoutes:o.modelRoutes??{}};let m=o.validation;n?(m={...m??{},mode:"claude-code"},m.allowExperimentalBlocks===void 0&&(m.allowExperimentalBlocks=!0)):m=void 0;const u=m?{...d,validation:m}:{...d},y={...a,[t]:u},D={...g,endpointRouting:y};await Y.put("/api/config",D),C(D)}else{const a=g.customEndpoints??[],o=a.findIndex(K=>K.id===t);if(o===-1)throw new Error(s("modelManagement.toast.endpointNotFound"));const d=a[o],m=d.routing??{defaults:g.defaults,modelRoutes:{}};let u=m.validation;n?(u={...u??{},mode:"claude-code"},u.allowExperimentalBlocks===void 0&&(u.allowExperimentalBlocks=!0)):u=void 0;const y=u?{...m,validation:u}:{...m},D={...d,routing:y},A=[...a];A[o]=D;const T={...g,customEndpoints:A};await Y.put("/api/config",T),C(T)}l({title:s(n?"modelManagement.toast.claudeValidationEnabled":"modelManagement.toast.claudeValidationDisabled"),variant:"success"}),h.refetch()}catch(a){const o=Te(a);l({title:s("modelManagement.toast.claudeValidationFailure",{message:o.message}),variant:"error"})}finally{Je(!1)}}},Gt=(t,n)=>{B(a=>{const o=a[t]||[];return o.some(d=>d.source.trim()===n.trim())?a:{...a,[t]:[...o,{id:He(),source:n,target:""}]}}),H(a=>({...a,[t]:null}))},ot=(t,n,a,o)=>{B(d=>({...d,[t]:(d[t]||[]).map(m=>m.id===n?{...m,[a]:o}:m)})),H(d=>({...d,[t]:null}))},Xt=(t,n)=>{B(a=>({...a,[t]:(a[t]||[]).filter(o=>o.id!==n)})),H(a=>({...a,[t]:null}))},Jt=t=>{var a,o;if(!g)return;const n=j.find(d=>d.id===t);if(n){const d=((a=n.routing)==null?void 0:a.modelRoutes)??{};B(m=>({...m,[t]:ee(d)}))}else{const d=g.endpointRouting??{},m=t,u=m==="anthropic"?g.modelRoutes??{}:{},y=((o=d[m])==null?void 0:o.modelRoutes)??u;B(D=>({...D,[t]:ee(y)}))}H(d=>({...d,[t]:null}))},Yt=async t=>{var o;if(!se())return;const n=G[t]||[],a={};for(const d of n){const m=d.source.trim(),u=d.target.trim();if(!(!m&&!u)){if(!m||!u){H(y=>({...y,[t]:s("settings.validation.routePair")}));return}if(a[m]){H(y=>({...y,[t]:s("settings.validation.routeDuplicate",{model:m})}));return}a[m]=u}}H(d=>({...d,[t]:null})),we(t);try{const d=j.find(m=>m.id===t);if(d){const m={...d.routing||{},modelRoutes:a,defaults:((o=d.routing)==null?void 0:o.defaults)||g.defaults};await ve.update(t,{routing:m}),f.invalidateQueries({queryKey:["custom-endpoints"]}),l({title:s("modelManagement.toast.routesSaved"),variant:"success"})}else{const m=g.endpointRouting?{...g.endpointRouting}:{},u=t,y=m[u]??{defaults:g.defaults,modelRoutes:u==="anthropic"?g.modelRoutes??{}:{}},D={...y,defaults:y.defaults??g.defaults,modelRoutes:a},A={...m,[u]:D},T={...g,endpointRouting:A,modelRoutes:u==="anthropic"?a:g.modelRoutes??{}};await Y.put("/api/config",T),C(T),l({title:s("modelManagement.toast.routesSaved"),variant:"success"}),h.refetch()}B(m=>({...m,[t]:ee(a)}))}catch(d){l({title:s("modelManagement.toast.routesSaveFailure",{message:d instanceof Error?d.message:"unknown"}),variant:"error"})}finally{we(null)}},Wt=()=>e.jsx(Re,{className:"surface-1",children:e.jsxs(De,{className:"pt-6 space-y-6",children:[e.jsx(pt,{eyebrow:"Model Access",title:s("providers.title"),description:s("providers.description"),breadcrumb:[s("modelManagement.title"),s("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(F,{variant:"secondary",children:s("providers.count",{count:et})}),e.jsxs(P,{variant:"outline",size:"sm",onClick:()=>h.refetch(),disabled:h.isFetching,children:[e.jsx(as,{className:Z("mr-2 h-4 w-4",h.isFetching&&"animate-spin")}),h.isFetching?s("common.actions.refreshing"):s("providers.actions.refresh")]}),e.jsxs(P,{size:"sm",onClick:Lt,children:[e.jsx(Ve,{className:"mr-2 h-4 w-4"}),s("providers.actions.add")]})]})}),e.jsxs("div",{className:"grid gap-3 rounded-[1.35rem] border border-border/70 bg-[linear-gradient(135deg,rgba(255,255,255,0.7),rgba(248,250,252,0.82))] p-4 lg:grid-cols-[minmax(0,1fr)_220px_auto]",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(Q,{className:"text-[11px] uppercase tracking-[0.16em] text-muted-foreground",children:s("providers.filters.searchPlaceholder")}),e.jsx(re,{value:Se,onChange:t=>We(t.target.value),placeholder:s("providers.filters.searchPlaceholder")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Q,{className:"text-[11px] uppercase tracking-[0.16em] text-muted-foreground",children:s("providers.filters.typeAll")}),e.jsxs(kt,{value:xe,onValueChange:Ze,children:[e.jsx(Mt,{children:e.jsx(Ct,{})}),e.jsxs(Et,{children:[e.jsx(W,{value:"all",children:s("providers.filters.typeAll")}),e.jsx(W,{value:"openai",children:"OpenAI"}),e.jsx(W,{value:"anthropic",children:"Anthropic"}),e.jsx(W,{value:"deepseek",children:"DeepSeek"}),e.jsx(W,{value:"huawei",children:"Huawei"}),e.jsx(W,{value:"kimi",children:"Kimi"}),e.jsx(W,{value:"custom",children:"Custom"})]})]})]}),e.jsx("div",{className:"flex items-end",children:e.jsx(P,{variant:"ghost",size:"sm",onClick:()=>{We(""),Ze("all")},disabled:!Se.trim()&&xe==="all",children:s("common.actions.reset")})})]}),h.isPending||!g&&h.isFetching?e.jsx("div",{className:"flex min-h-[200px] items-center justify-center rounded-[1.25rem] border border-border/70 bg-background/45 text-sm text-muted-foreground",children:s("common.loading")}):V.length===0?e.jsxs("div",{className:"rounded-[1.25rem] border border-dashed border-border/70 bg-background/45 p-12 text-center text-sm text-muted-foreground",children:[e.jsx("p",{className:"font-medium",children:s("providers.emptyState")}),e.jsx("p",{className:"mt-2 text-xs",children:s("providers.emptyStateSub",{default:"点击上方按钮添加您的第一个提供商"})})]}):tt.length===0?e.jsx("div",{className:"rounded-[1.25rem] border border-dashed border-border/70 bg-background/45 p-12 text-center text-sm text-muted-foreground",children:e.jsx("p",{className:"font-medium",children:s("providers.emptyFiltered")})}):e.jsx("div",{className:"grid gap-4 [grid-template-columns:repeat(auto-fit,minmax(280px,1fr))]",children:tt.map(t=>{var n;return e.jsx(Re,{className:"surface-1 flex flex-col overflow-hidden border-border/70",children:e.jsxs(De,{className:"flex flex-1 flex-col gap-4 pt-6",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",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:t.label||t.id}),t.type&&e.jsx(Ds,{type:t.type})]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["ID: ",t.id]}),e.jsx("p",{className:"break-all text-xs text-muted-foreground",children:t.baseUrl})]}),t.defaultModel?e.jsx(F,{variant:"default",className:"text-xs",children:st.get(t.id)??t.defaultModel}):e.jsx(F,{variant:"secondary",className:"text-xs",children:s("providers.card.noDefault")})]}),e.jsxs("div",{className:"grid gap-2 sm:grid-cols-3",children:[e.jsxs("div",{className:"rounded-2xl border border-border/70 bg-background/80 px-3 py-3",children:[e.jsx("p",{className:"text-[11px] font-medium uppercase tracking-[0.16em] text-muted-foreground",children:s("providers.card.authMode")}),e.jsx("p",{className:"mt-1 text-sm font-medium",children:t.authMode==="authToken"?"Bearer":t.authMode==="xAuthToken"?"X-Auth-Token":"API Key"})]}),e.jsxs("div",{className:"rounded-2xl border border-border/70 bg-background/80 px-3 py-3",children:[e.jsx("p",{className:"text-[11px] font-medium uppercase tracking-[0.16em] text-muted-foreground",children:s("providers.card.modelsTitle")}),e.jsx("p",{className:"mt-1 text-sm font-medium",children:(n=t.models)!=null&&n.length?s("providers.card.modelCount",{count:t.models.length}):s("providers.card.passthrough")})]}),e.jsxs("div",{className:"rounded-2xl border border-border/70 bg-background/80 px-3 py-3",children:[e.jsx("p",{className:"text-[11px] font-medium uppercase tracking-[0.16em] text-muted-foreground",children:s("providers.card.defaultModelLabel")}),e.jsx("p",{className:"mt-1 truncate text-sm font-medium",children:t.defaultModel?st.get(t.id)??t.defaultModel:s("providers.card.noDefault")})]})]}),e.jsxs("div",{className:"space-y-2 rounded-[1.1rem] border border-border/70 bg-background/55 p-3",children:[e.jsx(Q,{className:"text-xs uppercase tracking-[0.16em] text-muted-foreground",children:s("providers.card.modelsTitle")}),t.models&&t.models.length>0?e.jsx("div",{className:"flex max-h-24 flex-wrap gap-1 overflow-y-auto",children:t.models.map(a=>e.jsx(F,{variant:"outline",className:"text-xs",children:xt(a)},a.id))}):e.jsx("p",{className:"text-xs text-muted-foreground",children:s("providers.card.noModels")})]}),e.jsxs("div",{className:"mt-auto flex flex-wrap gap-2 border-t border-border/70 pt-4",children:[e.jsx(P,{variant:"default",size:"sm",onClick:()=>It(t),children:s("providers.actions.edit")}),e.jsx(P,{variant:"outline",size:"sm",onClick:()=>Bt(t),disabled:ne===t.id,children:ne===t.id?s("common.actions.testingConnection"):s("providers.actions.test")}),e.jsx(P,{variant:"destructive",size:"sm",onClick:()=>pe({kind:"provider",provider:t}),children:s("providers.actions.delete")})]})]})},t.id)})})]})}),Zt=t=>{const n=le[t]??[],a=ke[t]??"",o=c[t],d=R===t,m=Rt[t]===!0;return e.jsxs("div",{className:"rounded-[1.25rem] border border-dashed border-border/70 bg-background/45",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:()=>Dt(u=>({...u,[t]:!m})),children:e.jsxs("div",{className:"flex items-center gap-2",children:[m?e.jsx(os,{className:"h-4 w-4"}):e.jsx(ht,{className:"h-4 w-4"}),e.jsx("h3",{className:"font-medium",children:s("modelManagement.presets.title")}),e.jsx(F,{variant:"secondary",className:"text-xs",children:n.length})]})}),m&&e.jsxs("div",{className:"border-t px-4 pb-4 pt-3 space-y-4",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:s("modelManagement.presets.description")}),e.jsxs("div",{className:"flex flex-col gap-3 md:flex-row md:items-center",children:[e.jsx(re,{value:a,onChange:u=>Ot(t,u.target.value),placeholder:s("modelManagement.presets.namePlaceholder"),disabled:d,className:"w-full md:w-48"}),e.jsx(P,{onClick:()=>void Ut(t),disabled:d,children:s(d?"modelManagement.presets.saving":"modelManagement.presets.save")})]}),o&&e.jsx("p",{className:"text-sm text-destructive",children:o}),n.length===0?e.jsx("p",{className:"text-sm text-muted-foreground text-center py-4",children:s("modelManagement.presets.empty")}):e.jsx(is,{children:e.jsx("div",{className:"grid gap-2 sm:grid-cols-2 lg:grid-cols-3",children:n.map(u=>{const y=(_==null?void 0:_.endpoint)===t&&(_==null?void 0:_.name)===u.name,D=(z==null?void 0:z.endpoint)===t&&(z==null?void 0:z.name)===u.name,A=Object.entries(u.modelRoutes??{}),T=A.length;return e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-[1.15rem] border border-white/50 bg-card/88 px-4 py-3 shadow-[0_1px_2px_rgba(15,23,42,0.03)]",children:[e.jsxs(cs,{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:u.name}),e.jsx(F,{variant:"outline",className:"mt-1 text-xs",children:T>0?s("modelManagement.presets.rulesCount",{count:T}):s("modelManagement.presets.noRules")})]})}),T>0&&e.jsx(us,{side:"bottom",className:"max-w-xs",children:e.jsxs("div",{className:"space-y-1 text-xs",children:[A.slice(0,5).map(([K,J])=>e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"truncate",children:K}),e.jsx(ce,{className:"h-3 w-3 flex-shrink-0"}),e.jsx("span",{className:"truncate",children:J})]},K)),T>5&&e.jsxs("div",{className:"text-muted-foreground",children:["…+",T-5]})]})})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[e.jsx(P,{size:"sm",onClick:()=>Ie({endpoint:t,preset:u}),disabled:y||D,children:s(y?"modelManagement.presets.applying":"modelManagement.presets.apply")}),e.jsx(P,{variant:"destructive",size:"sm",onClick:()=>pe({kind:"preset",endpoint:t,preset:u}),disabled:D||y,children:s(D?"modelManagement.presets.deleting":"modelManagement.presets.delete")})]})]},u.name)})})})]})]})},es=t=>{var fe;const n=G[t]||[],a=Oe[t],o=r.find(O=>O.key===t),m=((fe=o==null?void 0:o.protocols)==null?void 0:fe.includes("anthropic"))??t==="anthropic"?Ns:ws,u=Ue===t,y=Ke[t]??!1,D=(o==null?void 0:o.label)??s(`modelManagement.tabs.${t}`),A=(o==null?void 0:o.isSystem)===!1?o.description:s(`settings.routing.descriptionByEndpoint.${t}`),T=`route-source-${t}`,K=Ms(t,j),J=Cs(t,g,j),ge=K&&(J==null?void 0:J.mode)==="claude-code",ie=new Set(n.map(O=>O.source.trim()).filter(Boolean));return e.jsx(Re,{className:"surface-1",children:e.jsxs(De,{className:"pt-6 space-y-6",children:[e.jsx(pt,{eyebrow:"Routing Workspace",title:s("settings.routing.titleByEndpoint",{endpoint:D}),description:A,breadcrumb:[s("modelManagement.title"),D],aside:e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs(F,{variant:"outline",children:[n.length," rules"]}),y?e.jsx(F,{variant:"outline",className:"border-amber-300 text-amber-700 dark:border-amber-700 dark:text-amber-300",children:s("modelManagement.actions.unsaved")}):e.jsx(F,{variant:"secondary",children:s("common.status.success")})]})}),e.jsx("div",{className:"rounded-[1.2rem] border border-border/70 bg-background/55 px-4 py-3 text-xs text-muted-foreground",children:s("settings.routing.wildcardHint")}),K&&e.jsx("div",{className:"rounded-[1.25rem] border border-blue-200 bg-blue-50/75 p-4 dark:border-blue-800 dark:bg-blue-950",children:e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-sm font-medium text-blue-800 dark:text-blue-200",children:s("modelManagement.claudeValidation.title")}),e.jsx("p",{className:"text-xs text-blue-700 dark:text-blue-300",children:s("modelManagement.claudeValidation.description")})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(wt,{checked:ge,onCheckedChange:O=>void Qt(t,O),disabled:St}),e.jsx("span",{className:Z("text-xs font-medium",ge?"text-emerald-600 dark:text-emerald-400":"text-muted-foreground"),children:s(ge?"modelManagement.claudeValidation.statusEnabled":"modelManagement.claudeValidation.statusDisabled")})]})]})}),Zt(t),a&&e.jsx("p",{className:"text-sm text-destructive",children:a}),e.jsxs("div",{className:"space-y-3 rounded-[1.35rem] border border-border/70 bg-[linear-gradient(135deg,rgba(255,255,255,0.7),rgba(248,250,252,0.82))] p-4",children:[e.jsx("div",{className:"flex items-center justify-between gap-3",children:e.jsxs("div",{children:[e.jsx(Q,{className:"text-sm font-semibold text-foreground",children:s("modelManagement.routesEditorTitle")}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:"Source model -> target provider:model"})]})}),n.length===0?e.jsxs("div",{className:"rounded-[1.25rem] border border-dashed border-border/70 bg-background/45 p-12 text-center text-sm text-muted-foreground",children:[e.jsx("p",{className:"font-medium",children:s("settings.routing.empty")}),e.jsx("p",{className:"mt-2 text-xs",children:s("modelManagement.emptyRoutesHint")})]}):e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"grid grid-cols-[minmax(0,1fr)_auto_minmax(0,1fr)_auto] items-center gap-3 px-1 text-xs font-medium text-muted-foreground",children:[e.jsx("span",{children:s("settings.routing.source")}),e.jsx("span",{}),e.jsx("span",{children:s("settings.routing.target")}),e.jsx("span",{})]}),n.map((O,be)=>e.jsxs("div",{className:"grid grid-cols-[minmax(0,1fr)_auto_minmax(0,1fr)_auto] items-center gap-3 rounded-[1rem] border border-border/60 bg-background/80 p-3",children:[e.jsx(re,{value:O.source,onChange:Be=>ot(t,O.id,"source",Be.target.value),placeholder:s("settings.routing.sourcePlaceholder"),list:T,disabled:u,"aria-label":`route-source-${be+1}`}),e.jsx(ce,{className:"h-4 w-4 text-muted-foreground flex-shrink-0"}),e.jsx(Ss,{value:O.target,onChange:Be=>ot(t,O.id,"target",Be),options:Pt,disabled:u,placeholder:s("settings.routing.targetPlaceholder")}),e.jsx(P,{variant:"ghost",size:"icon",className:"h-8 w-8 text-muted-foreground hover:text-destructive",onClick:()=>Xt(t,O.id),disabled:u,children:e.jsx(_e,{className:"h-4 w-4"})})]},O.id))]})]}),e.jsxs("div",{className:"rounded-[1.25rem] border border-border/70 bg-background/55 p-4 space-y-3",children:[e.jsxs("div",{children:[e.jsx(Q,{className:"text-sm font-semibold text-foreground",children:s("settings.routing.suggested")}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:"One click to seed common source models for this endpoint."})]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:m.map(O=>{const be=ie.has(O);return e.jsx(P,{variant:be?"ghost":"outline",size:"sm",onClick:()=>Gt(t,O),disabled:u||be,className:be?"opacity-50":"",children:O},`${t}-${O}`)})})]}),e.jsxs("div",{className:"flex flex-col gap-3 rounded-[1.25rem] border border-white/50 bg-card/82 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:s("modelManagement.actions.footerTitle")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s(y?"modelManagement.actions.footerDirtyHint":"modelManagement.actions.footerSavedHint")})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(P,{variant:"outline",size:"sm",onClick:()=>qt(t),disabled:u,children:s("settings.routing.add")}),e.jsx(P,{variant:"outline",size:"sm",onClick:()=>Jt(t),disabled:u||!y,children:s("common.actions.reset")}),e.jsxs(P,{size:"sm",onClick:()=>void Yt(t),disabled:u,className:"relative",children:[s(u?"common.actions.saving":"modelManagement.actions.saveRoutes"),y&&e.jsx("span",{className:"absolute -top-1 -right-1 h-2 w-2 rounded-full bg-amber-500"})]})]})]}),e.jsx("datalist",{id:T,children:m.map(O=>e.jsx("option",{value:O},`${T}-${O}`))})]})})},ts=(N==null?void 0:N.kind)==="provider"?s("providers.actions.delete"):(N==null?void 0:N.kind)==="preset"?s("modelManagement.presets.delete"):(N==null?void 0:N.kind)==="endpoint"?s("common.delete"):"",ss=(N==null?void 0:N.kind)==="provider"?s("providers.confirm.delete",{name:N.provider.label||N.provider.id}):(N==null?void 0:N.kind)==="preset"?s("modelManagement.confirm.deletePreset",{name:N.preset.name}):(N==null?void 0:N.kind)==="endpoint"?s("modelManagement.deleteEndpointConfirm",{label:N.endpoint.label}):"",dt=(N==null?void 0:N.kind)==="provider"?N.provider.label||N.provider.id:(N==null?void 0:N.kind)==="preset"?N.preset.name:(N==null?void 0:N.kind)==="endpoint"?N.endpoint.label:"";return e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx(xs,{icon:e.jsx(rs,{className:"h-5 w-5","aria-hidden":"true"}),title:s("modelManagement.title"),description:s("modelManagement.description"),actions:e.jsxs(P,{onClick:()=>{de(void 0),ye(!0)},children:[e.jsx(Ve,{className:"mr-2 h-4 w-4"}),s("modelManagement.addEndpoint")]})}),e.jsx(Re,{className:"surface-1 overflow-hidden",children:e.jsxs(De,{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(F,{variant:"outline",className:"border-primary/20 bg-primary/5 text-primary",children:[s("modelManagement.tabs.providers")," · ",et]}),e.jsxs(F,{variant:"outline",children:[s("modelManagement.tabs.customEndpoint")," · ",I.length]})]}),e.jsx("p",{className:"text-sm font-semibold text-foreground",children:U==null?void 0:U.label}),e.jsx("p",{className:"text-sm text-muted-foreground",children:U==null?void 0:U.description})]}),e.jsx("div",{className:"rounded-2xl border border-border/70 bg-background/75 px-3 py-2 text-xs text-muted-foreground",children:I.length>0?"自定义端点较多时,优先在下方端点带中切换,避免横向挤压布局。":"先配置提供商与内置路由,需要时再追加自定义端点。"})]}),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-[0.18em] text-muted-foreground",children:"内置视图"})}),e.jsx("div",{className:"grid gap-3 md:grid-cols-3",children:S.map(t=>{const n=i===t.key,a=t.key!=="providers"&&Ke[t.key];return e.jsxs("button",{type:"button",onClick:()=>w(t.key),className:Z("group flex min-h-[108px] flex-col justify-between rounded-[1.25rem] border px-4 py-4 text-left transition-all",n?"border-primary/35 bg-[linear-gradient(135deg,rgba(59,130,246,0.12),rgba(59,130,246,0.03))] shadow-[inset_0_0_0_1px_rgba(59,130,246,0.08)]":"border-border/70 bg-background/75 hover:border-primary/20 hover:bg-primary/5"),children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsx("span",{className:Z("text-lg font-semibold tracking-[-0.02em]",n?"text-primary":"text-foreground"),children:t.label}),a?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:t.description})]},t.key)})})]}),I.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-[0.18em] text-muted-foreground",children:"自定义接入端点"}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:"端点较多时保留紧凑卡片与横向滚动,避免标题和路径把整行撑乱。"})]})}),e.jsx("div",{className:"overflow-x-auto pb-1",children:e.jsx("div",{className:"flex min-w-full gap-3",children:I.map(t=>{const n=i===t.key,a=Ke[t.key];return e.jsxs("div",{className:Z("group relative flex w-[260px] shrink-0 snap-start flex-col gap-3 rounded-[1.2rem] border px-4 py-4 text-left transition-all",n?"border-primary/35 bg-[linear-gradient(135deg,rgba(59,130,246,0.12),rgba(59,130,246,0.03))] shadow-[inset_0_0_0_1px_rgba(59,130,246,0.08)]":"border-border/70 bg-background/80 hover:border-primary/20 hover:bg-primary/5"),children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsxs("button",{type:"button",onClick:()=>w(t.key),className:"min-w-0 flex-1 text-left",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:Z("truncate text-base font-semibold tracking-[-0.02em]",n?"text-primary":"text-foreground"),children:t.label}),a?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:t.description})]}),t.canDelete?e.jsx("button",{type:"button",onClick:o=>{o.stopPropagation();const d=j.find(m=>m.id===t.key);d&&pe({kind:"endpoint",endpoint:d})},className:"flex h-7 w-7 items-center justify-center rounded-full border border-transparent text-muted-foreground transition hover:border-destructive/20 hover:bg-destructive/10 hover:text-destructive",title:s("common.delete"),children:e.jsx(_e,{className:"h-3.5 w-3.5"})}):null]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:(t.protocols??[]).map(o=>e.jsx(F,{variant:"outline",className:"max-w-full truncate border-border/70 bg-background/80 text-[11px] text-muted-foreground",children:o},`${t.key}-${o}`))})]},t.key)})})})]}):null]})}),i==="providers"?Wt():es(i),e.jsx(ys,{open:k,mode:E,provider:E==="edit"?L:void 0,existingProviderIds:V.map(t=>t.id).filter(t=>E==="edit"&&L?t!==L.id:!0),onClose:()=>{v(!1),ae(void 0),$("create")},onSubmit:Ft}),e.jsx(Ps,{open:je,endpoint:Ne,onClose:()=>{ye(!1),de(void 0)},onSuccess:()=>{f.invalidateQueries({queryKey:["custom-endpoints"]})}}),e.jsx(Es,{open:Ce,provider:$e,options:he,preservedExtras:Ge,usePreset:Ee,onPresetChange:Ae,onConfirm:zt,onClose:nt}),e.jsx(Rs,{dialog:Le,currentRoutes:Le?G[Le.endpoint]||[]:[],onConfirm:(t,n)=>{Ie(null),$t(t,n)},onClose:()=>Ie(null)}),e.jsx(hs,{open:!!N,onOpenChange:t=>{!t&&!Fe&&pe(null)},title:ts,description:ss,confirmLabel:s(Fe?"common.actions.loading":"common.delete"),cancelLabel:s("common.actions.cancel"),loading:Fe,onConfirm:Ht,children:dt?e.jsx("div",{className:"rounded-[1rem] border border-destructive/20 bg-destructive/5 px-3 py-2 font-mono text-xs text-foreground",children:dt}):null})]})}function pt({eyebrow:s,title:l,description:f,breadcrumb:h,aside:p}){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}),h.map((j,r)=>e.jsxs(ns.Fragment,{children:[r>0?e.jsx(ht,{className:"h-3.5 w-3.5"}):null,e.jsx("span",{className:Z(r===h.length-1&&"text-foreground"),children:j})]},`${j}-${r}`))]}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-semibold tracking-[-0.03em] text-foreground",children:l}),e.jsx("p",{className:"mt-1 max-w-3xl text-sm text-muted-foreground",children:f})]})]}),p?e.jsx("div",{className:"flex shrink-0 items-center gap-2",children:p}):null]})}function Es({open:s,provider:l,options:f,usePreset:h,preservedExtras:p,onPresetChange:j,onConfirm:r,onClose:i}){const{t:w}=me();return l?e.jsx(ft,{open:s,onOpenChange:S=>!S&&i(),children:e.jsxs(bt,{children:[e.jsxs(vt,{children:[e.jsx(jt,{children:w("providers.testDialog.title")}),e.jsx(yt,{children:w("providers.testDialog.subtitle",{name:l.label||l.id})})]}),e.jsxs("div",{className:"min-h-0 space-y-4 overflow-y-auto",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:w("providers.testDialog.description")}),e.jsxs("div",{className:"flex items-start gap-3 rounded-[1.2rem] border border-border/70 bg-background/45 p-4",children:[e.jsx("input",{type:"checkbox",className:"mt-1 h-4 w-4 rounded border",checked:h,onChange:S=>j(S.target.checked)}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Q,{children:w("providers.testDialog.presetLabel")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:w("providers.testDialog.presetDescription")}),e.jsxs("details",{className:"rounded-[1rem] border border-border/70 bg-background/70 p-2 text-xs",children:[e.jsx("summary",{className:"cursor-pointer text-primary hover:underline",children:w("providers.testDialog.presetPreviewSummary")}),e.jsx("div",{className:"mt-2 space-y-1",children:f.map(S=>e.jsxs("code",{className:"block rounded-xl border border-border/70 bg-background/85 px-2 py-1 text-xs",children:[S.key,": ",S.value]},S.key))})]})]})]}),Object.keys(p).length>0&&e.jsxs("div",{className:"rounded-[1.15rem] border border-border/70 bg-background/70 p-4 text-xs space-y-2",children:[e.jsx("p",{className:"font-medium",children:w("providers.testDialog.preservedInfo")}),Object.entries(p).map(([S,I])=>e.jsxs("code",{className:"block rounded-xl border border-border/70 bg-background/85 px-2 py-1",children:[S,": ",I]},S))]})]}),e.jsxs(Nt,{children:[e.jsx(P,{variant:"outline",onClick:i,children:w("providers.testDialog.cancel")}),e.jsx(P,{onClick:()=>void r(),children:w("providers.testDialog.primary")})]})]})}):null}function Ss({value:s,onChange:l,options:f,disabled:h,placeholder:p}){const{t:j}=me(),[r,i]=x.useState(!1),[w,S]=x.useState(""),I=x.useRef(null),U=x.useMemo(()=>{if(!w.trim())return f;const C=w.toLowerCase();return f.filter(k=>k.label.toLowerCase().includes(C)||k.value.toLowerCase().includes(C))},[f,w]),g=C=>{l(C),S(""),i(!1)};return e.jsxs(gs,{open:r,onOpenChange:C=>{i(C),C&&S("")},children:[e.jsx(fs,{asChild:!0,children:e.jsx(re,{ref:I,value:s,onChange:C=>{l(C.target.value),S(C.target.value),r||i(!0)},onFocus:()=>{S(""),i(!0)},onClick:()=>{r||i(!0)},placeholder:p,disabled:h,autoComplete:"off"})}),e.jsx(bs,{className:"w-[var(--radix-popover-trigger-width)] max-h-60 overflow-y-auto p-1",align:"start",onOpenAutoFocus:C=>C.preventDefault(),children:U.length===0?e.jsx("div",{className:"px-2 py-3 text-center text-xs text-muted-foreground",children:j("common.noMatches")}):U.map(C=>e.jsx("button",{type:"button",className:Z("flex w-full items-center rounded-sm px-2 py-1.5 text-left text-sm hover:bg-accent",C.value===s.trim()&&"bg-accent"),onMouseDown:k=>{k.preventDefault(),g(C.value)},children:e.jsx("span",{className:"truncate",children:C.label})},C.value))})]})}function Rs({dialog:s,currentRoutes:l,onConfirm:f,onClose:h}){const{t:p}=me();if(!s)return null;const{endpoint:j,preset:r}=s,i=r.modelRoutes??{},w={};for(const k of l){const v=k.source.trim(),E=k.target.trim();v&&E&&(w[v]=E)}const S=new Set([...Object.keys(w),...Object.keys(i)]),I=[],U=[],g=[];for(const k of S){const v=k in w,E=k in i;E&&!v?I.push([k,i[k]]):v&&!E?U.push([k,w[k]]):v&&E&&w[k]!==i[k]&&g.push([k,w[k],i[k]])}const C=I.length>0||U.length>0||g.length>0;return e.jsx(ft,{open:!0,onOpenChange:k=>!k&&h(),children:e.jsxs(bt,{className:"max-w-lg",children:[e.jsxs(vt,{children:[e.jsx(jt,{children:p("modelManagement.presets.diffTitle")}),e.jsx(yt,{children:p("modelManagement.presets.diffDescription",{name:r.name})})]}),C?e.jsxs("div",{className:"max-h-72 overflow-y-auto space-y-2 text-sm",children:[I.map(([k,v])=>e.jsxs("div",{className:"flex items-center gap-2 rounded-xl px-2 py-1.5 bg-emerald-50 dark:bg-emerald-950 text-emerald-800 dark:text-emerald-200",children:[e.jsx(F,{variant:"outline",className:"text-xs border-emerald-300 dark:border-emerald-700",children:p("modelManagement.presets.diffAdded")}),e.jsx("span",{className:"truncate",children:k}),e.jsx(ce,{className:"h-3 w-3 flex-shrink-0"}),e.jsx("span",{className:"truncate",children:v})]},`add-${k}`)),U.map(([k,v])=>e.jsxs("div",{className:"flex items-center gap-2 rounded-xl px-2 py-1.5 bg-red-50 dark:bg-red-950 text-red-800 dark:text-red-200",children:[e.jsx(F,{variant:"outline",className:"text-xs border-red-300 dark:border-red-700",children:p("modelManagement.presets.diffRemoved")}),e.jsx("span",{className:"truncate",children:k}),e.jsx(ce,{className:"h-3 w-3 flex-shrink-0"}),e.jsx("span",{className:"truncate",children:v})]},`rm-${k}`)),g.map(([k,v,E])=>e.jsxs("div",{className:"flex items-center gap-2 rounded-xl px-2 py-1.5 bg-amber-50 dark:bg-amber-950 text-amber-800 dark:text-amber-200",children:[e.jsx(F,{variant:"outline",className:"text-xs border-amber-300 dark:border-amber-700",children:p("modelManagement.presets.diffChanged")}),e.jsx("span",{className:"truncate",children:k}),e.jsx(ce,{className:"h-3 w-3 flex-shrink-0"}),e.jsx("span",{className:"truncate line-through opacity-60",children:v}),e.jsx(ce,{className:"h-3 w-3 flex-shrink-0"}),e.jsx("span",{className:"truncate",children:E})]},`chg-${k}`))]}):e.jsx("p",{className:"py-4 text-center text-sm text-muted-foreground",children:p("modelManagement.presets.diffEmpty")}),e.jsxs(Nt,{children:[e.jsx(P,{variant:"outline",onClick:h,children:p("common.cancel")}),e.jsx(P,{onClick:()=>f(j,r),disabled:!C,children:p("modelManagement.presets.diffConfirm")})]})]})})}function xt(s){return s.label&&s.label.trim().length>0?`${s.label} (${s.id})`:s.id}function Ds({type:s}){const l={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:f,variant:h}=l[s]||l.custom;return e.jsx(F,{variant:h,className:"text-xs",children:f})}function Ps({open:s,endpoint:l,onClose:f,onSuccess:h}){const{t:p}=me(),{pushToast:j}=gt(),[r,i]=x.useState({id:"",label:"",paths:[{path:"",protocol:"openai-auto"}],enabled:!0});x.useEffect(()=>{if(l){let v;l.paths&&l.paths.length>0?v=l.paths:l.path&&l.protocol?v=[{path:l.path,protocol:l.protocol}]:v=[{path:"",protocol:"openai-auto"}],i({id:l.id,label:l.label,paths:v,enabled:l.enabled!==!1})}else i({id:"",label:"",paths:[{path:"",protocol:"openai-auto"}],enabled:!0})},[l,s]);const w=lt({mutationFn:ve.create,onSuccess:()=>{j({title:p("modelManagement.createEndpointSuccess"),variant:"success"}),h(),f()},onError:v=>{const E=Te(v);j({title:p("modelManagement.createEndpointError",{error:E.message}),variant:"error"})}}),S=lt({mutationFn:v=>ve.update(v.id,v.updates),onSuccess:()=>{j({title:p("modelManagement.updateEndpointSuccess"),variant:"success"}),h(),f()},onError:v=>{const E=Te(v);j({title:p("modelManagement.updateEndpointError",{error:E.message}),variant:"error"})}}),I=()=>{i({...r,paths:[...r.paths,{path:"",protocol:"anthropic"}]})},U=v=>{if(r.paths.length===1){j({title:p("modelManagement.atLeastOnePath"),variant:"error"});return}const E=r.paths.filter(($,L)=>L!==v);i({...r,paths:E})},g=(v,E,$)=>{const L=[...r.paths];L[v]={...L[v],[E]:$},i({...r,paths:L})},C=v=>{if(v.preventDefault(),!r.id.trim()||!r.label.trim()){j({title:p("modelManagement.endpointValidationError"),variant:"error"});return}for(const $ of r.paths)if(!$.path.trim()){j({title:p("modelManagement.pathValidationError"),variant:"error"});return}const E=r.paths.map($=>({path:$.path.trim(),protocol:$.protocol}));l?S.mutate({id:l.id,updates:{label:r.label.trim(),paths:E,enabled:r.enabled}}):w.mutate({id:r.id.trim(),label:r.label.trim(),paths:E,enabled:r.enabled})},k=w.isPending||S.isPending;return s?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-40 bg-slate-950/45 backdrop-blur-sm",onClick:f}),e.jsx("div",{className:"fixed inset-y-0 right-0 z-50 w-full max-w-md border-l border-white/50 bg-background/96 shadow-[0_24px_80px_-32px_rgba(15,23,42,0.4)] backdrop-blur-xl",children:e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-border/70 bg-background/70 p-6",children:[e.jsx("h2",{className:"text-lg font-semibold tracking-[-0.02em]",children:p(l?"modelManagement.editEndpoint":"modelManagement.createEndpoint")}),e.jsx(P,{variant:"ghost",size:"sm",onClick:f,children:e.jsx(_e,{className:"h-4 w-4"})})]}),e.jsxs("form",{onSubmit:C,className:"flex-1 overflow-y-auto p-6 space-y-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs(Q,{children:[p("modelManagement.endpointId")," ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(re,{value:r.id,onChange:v=>i({...r,id:v.target.value}),placeholder:p("modelManagement.endpointIdPlaceholder"),disabled:!!l,required:!0}),e.jsx("p",{className:"text-xs text-muted-foreground",children:p("modelManagement.endpointIdHint")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(Q,{children:[p("modelManagement.endpointLabel")," ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(re,{value:r.label,onChange:v=>i({...r,label:v.target.value}),placeholder:p("modelManagement.endpointLabelPlaceholder"),required:!0})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(Q,{children:[p("modelManagement.endpointPaths")," ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsxs(P,{type:"button",variant:"ghost",size:"sm",onClick:I,children:[e.jsx(Ve,{className:"mr-1 h-3 w-3"}),p("modelManagement.addPath")]})]}),e.jsx("div",{className:"space-y-3",children:r.paths.map((v,E)=>e.jsxs("div",{className:"rounded-[1.15rem] border border-white/50 bg-card/88 p-3 space-y-2 shadow-[0_1px_2px_rgba(15,23,42,0.03)]",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(re,{value:v.path,onChange:$=>g(E,"path",$.target.value),placeholder:p("modelManagement.endpointPathPlaceholder"),required:!0}),e.jsxs(kt,{value:v.protocol,onValueChange:$=>g(E,"protocol",$),children:[e.jsx(Mt,{children:e.jsx(Ct,{})}),e.jsxs(Et,{children:[e.jsx(W,{value:"anthropic",children:p("modelManagement.protocolAnthropic")}),e.jsx(W,{value:"openai-auto",children:p("modelManagement.protocolOpenAI")})]})]})]}),r.paths.length>1&&e.jsx(P,{type:"button",variant:"ghost",size:"sm",onClick:()=>U(E),className:"text-destructive",children:e.jsx(_e,{className:"h-4 w-4"})})]}),E===0&&e.jsx("p",{className:"text-xs text-muted-foreground",children:p("modelManagement.endpointPathHint")})]},E))})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(wt,{id:"enabled",checked:r.enabled,onCheckedChange:v=>i({...r,enabled:v})}),e.jsx(Q,{htmlFor:"enabled",children:p("modelManagement.endpointEnabled")})]}),!l&&e.jsx("div",{className:"rounded-[1.2rem] border border-blue-200 bg-blue-50/75 p-4 dark:border-blue-800 dark:bg-blue-950",children:e.jsx("p",{className:"text-sm text-blue-800 dark:text-blue-200",children:p("modelManagement.endpointRoutingHint")})})]}),e.jsxs("div",{className:"flex gap-3 border-t border-border/70 bg-background/70 p-6",children:[e.jsx(P,{variant:"outline",className:"flex-1",onClick:f,disabled:k,children:p("common.cancel")}),e.jsx(P,{className:"flex-1",onClick:C,disabled:k,children:p(k?"common.saving":l?"common.save":"common.create")})]})]})})]}):null}export{Qs as default};
1
+ import{r as x,f as e,aj as Ve,$ as rs,a5 as _e,ad as as,ak as ce,k as ns,N as ht,af as os}from"./vendor-C92xTG6Z.js";import{u as ds,a as ls,b as lt}from"./query-CDpWKdnY.js";import{c as Z,u as gt,B as P,a as Y,b as ve,t as Te,T as is,d as cs,f as ms,g as us}from"./index-BuTkie0t.js";import{u as ps}from"./useApiQuery-BkAH5SvI.js";import{P as xs,B as F}from"./PageHeader-Da1cmUY0.js";import{C as hs,D as ft,a as bt,b as vt,c as jt,d as yt,e as Nt}from"./ConfirmDialog-DFy4NI8g.js";import{I as re}from"./input-BHq9dQGf.js";import{L as Q}from"./label-CUv6yhdE.js";import{C as Re,a as De}from"./card-BD2y3CjZ.js";import{S as wt}from"./switch-NOIFebYg.js";import{S as kt,a as Mt,b as Ct,c as Et,d as W}from"./select-Dq7kCMCk.js";import{P as gs,a as fs,b as bs}from"./popover-0Ho_T06s.js";import{u as me}from"./i18n-CZ1qKIdj.js";import"./router-DjNibHfR.js";import"./radix-Ccu1urVd.js";function qe(){return typeof globalThis.crypto<"u"&&typeof globalThis.crypto.randomUUID=="function"?globalThis.crypto.randomUUID():Math.random().toString(36).slice(2,10)}function vs(){return{_key:qe(),id:"",label:""}}const Pe={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:{}},it=[{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 ct(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(l=>({...l,_key:qe()})),authMode:s.authMode??"apiKey"}:{id:"",label:"",baseUrl:"",apiKey:"",type:"custom",defaultModel:"",models:[],authMode:"apiKey"}}function js(s){return{_key:qe(),id:s.id,label:s.label}}function ys({open:s,mode:l,provider:f,existingProviderIds:h,onClose:p,onSubmit:j}){const{t:r}=me(),[i,w]=x.useState(()=>ct(f)),[S,I]=x.useState({}),[U,g]=x.useState(!1),[C,k]=x.useState(null),v=x.useRef(null),E=x.useRef(null),$=x.useRef(null),[L,ae]=x.useState(l==="edit");x.useEffect(()=>{s&&(w(ct(f)),I({}),k(null),g(!1),ae(l==="edit"))},[s,f,l]),x.useEffect(()=>{if(!s)return;const c=b=>{b.key==="Escape"&&p()};return window.addEventListener("keydown",c),()=>window.removeEventListener("keydown",c)},[s,p]),x.useEffect(()=>{if(s){if(l==="create"&&$.current){$.current.focus();return}E.current&&E.current.focus()}},[s,l]);const ne=l==="create",oe=x.useMemo(()=>i.models.filter(c=>c.id.trim().length>0),[i.models]),je=x.useMemo(()=>{var c;return((c=it.find(b=>b.value===i.type))==null?void 0:c.label)??"Custom"},[i.type]),ye=i.label.trim()||i.id.trim()||r("providers.drawer.summary.untitled"),Ne=x.useMemo(()=>[{label:r("providers.drawer.summary.type"),value:je},{label:r("providers.drawer.summary.auth"),value:i.authMode==="apiKey"?r("providers.drawer.fields.authModeApiKey"):i.authMode==="authToken"?r("providers.drawer.fields.authModeAuthToken"):r("providers.drawer.fields.authModeXAuthToken")},{label:r("providers.drawer.summary.models"),value:oe.length.toLocaleString()}],[oe.length,i.authMode,je,r]),de=c=>b=>{w(R=>({...R,[c]:b}))},G=c=>{w(b=>{const M=!L||b.label.trim().length===0||b.label===b.id?c:b.label;return{...b,id:c,label:M}})},B=c=>{w(b=>{var Ce;const M=Pe[c??"custom"]??Pe.custom,_=Object.values(Pe).map(te=>te.baseUrl).filter(te=>!!te),q=!b.baseUrl||_.includes(b.baseUrl),z=l==="create"&&(b.models.length===0||b.models.every(te=>te.id.trim().length===0)),X={...b,type:c,authMode:b.authMode??"apiKey"};return M!=null&&M.baseUrl&&q&&(X.baseUrl=M.baseUrl),M!=null&&M.models&&z&&(X.models=M.models.map(js),X.defaultModel=M.defaultModel??((Ce=M.models[0])==null?void 0:Ce.id)??""),X})},Oe=(c,b)=>{w(R=>{const M=[...R.models];return M[c]={...M[c],...b},{...R,models:M}})},H=(c,b)=>{w(R=>{const M=[...R.models],_=M[c];if(!_)return R;const q=!L||!_.label||_.label===_.id,z={..._,id:b,label:q?b:_.label};M[c]=z;const X=R.defaultModel===_.id?b:R.defaultModel;return{...R,models:M,defaultModel:X}})},Ue=c=>{w(b=>{if(c<0||c>=b.models.length)return b;const R=b.models.filter((_,q)=>q!==c);let M=b.defaultModel;return R.some(_=>_.id===M)||(M=""),{...b,models:R,defaultModel:M}})},we=()=>{w(c=>({...c,models:[...c.models,vs()]}))},le=c=>{w(b=>({...b,authMode:c}))},ue=()=>{const c={},b=i.id.trim(),R=i.baseUrl.trim();if(l==="create"&&(b.length===0?c.id=r("providers.drawer.errors.idRequired"):h.includes(b)&&(c.id=r("providers.drawer.errors.idDuplicate"))),l==="edit"&&b.length===0&&(c.id=r("providers.drawer.errors.idRequired")),R.length===0)c.baseUrl=r("providers.drawer.errors.baseUrlInvalid");else try{new URL(R)}catch{c.baseUrl=r("providers.drawer.errors.baseUrlInvalid")}if(i.models.length>0){const M=new Set;i.models.some(q=>{const z=q.id.trim();return z.length===0||M.has(z)?!0:(M.add(z),!1)})&&(c.models=r("providers.drawer.errors.modelInvalid"))}return i.defaultModel&&!i.models.some(M=>M.id===i.defaultModel)&&(c.models=r("providers.drawer.errors.defaultInvalid")),I(c),Object.keys(c).length===0},ke=()=>{const c=i.models.map(M=>{var _;return{id:M.id.trim(),label:(_=M.label)!=null&&_.trim()?M.label.trim():void 0}}).filter(M=>M.id.length>0),b=f!=null&&f.extraHeaders&&Object.keys(f.extraHeaders).length>0?f.extraHeaders:void 0,R=i.authMode!=="apiKey"?i.authMode:void 0;return{id:i.id.trim(),label:i.label.trim()||i.id.trim(),baseUrl:i.baseUrl.trim(),apiKey:i.apiKey.trim()||void 0,type:i.type??"custom",defaultModel:i.defaultModel||void 0,models:c.length>0?c:void 0,extraHeaders:b,authMode:R}},Me=async()=>{if(k(null),!!ue()){g(!0);try{const c=ke();await j(c)}catch(c){k(r("providers.drawer.toast.saveFailure",{message:c instanceof Error?c.message:"unknown"})),g(!1);return}g(!1),p()}};return s?e.jsxs("div",{className:"fixed inset-0 z-50 flex",children:[e.jsx("div",{className:"flex-1 bg-slate-900/60 backdrop-blur-sm",onClick:p,"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-white/50 bg-background/96 shadow-[0_24px_80px_-32px_rgba(15,23,42,0.4)] backdrop-blur-xl dark:border-slate-800 dark:bg-slate-950/96",children:[e.jsxs("header",{className:"border-b border-border/70 bg-background/70 px-6 py-5 dark:border-slate-800",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:r(ne?"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:r(ne?"providers.drawer.createTitle":"providers.drawer.editTitle")}),e.jsx("p",{id:"provider-drawer-desc",className:"text-sm text-muted-foreground",children:r("providers.drawer.description")})]})]}),e.jsx("button",{type:"button",ref:E,onClick:p,className:"rounded-full border border-border/80 bg-background/85 px-4 py-2 text-sm transition hover:border-primary/20 hover:bg-primary/5",children:r("common.actions.close")})]}),e.jsx("div",{className:"mt-4 grid gap-3 md:grid-cols-3",children:Ne.map(c=>e.jsxs("div",{className:"rounded-[1.2rem] border border-white/50 bg-card/88 px-4 py-3 shadow-[0_1px_2px_rgba(15,23,42,0.03)]",children:[e.jsx("p",{className:"text-[11px] font-medium uppercase tracking-[0.16em] text-muted-foreground",children:c.label}),e.jsx("p",{className:"mt-2 text-sm font-semibold text-foreground",children:c.value})]},c.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:r("providers.drawer.sections.type")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:r("providers.drawer.hints.type")})]}),e.jsx("div",{className:"grid gap-2 md:grid-cols-3",children:it.map(c=>{var R;const b=c.value===i.type;return e.jsxs("button",{type:"button",onClick:()=>B(c.value),className:Z("rounded-2xl border px-4 py-3 text-left transition",b?"border-primary bg-primary/10 text-primary shadow-sm":"border-white/50 bg-card/88 text-foreground hover:border-primary/20 hover:bg-primary/5"),children:[e.jsx("div",{className:"text-sm font-semibold",children:c.label}),e.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:((R=Pe[c.value??"custom"])==null?void 0:R.baseUrl)??r("providers.drawer.hints.customProvider")})]},c.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:r("providers.drawer.sections.basic")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:r("providers.drawer.hints.basic")})]}),e.jsx("button",{type:"button",onClick:()=>ae(c=>!c),className:"rounded-full border border-border/80 bg-background/85 px-3 py-1.5 text-xs transition hover:border-primary/20 hover:bg-primary/5",children:r(L?"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:r("providers.drawer.fields.id")}),e.jsx("input",{value:i.id,ref:$,onChange:c=>G(c.target.value),disabled:!ne,placeholder:r("providers.drawer.fields.idPlaceholder"),className:"h-11 rounded-2xl border border-border/80 bg-background/85 px-4 py-2 text-sm shadow-[0_1px_2px_rgba(15,23,42,0.03)] transition-all duration-200 focus:border-primary/40 focus:outline-none focus:ring-2 focus:ring-primary/20 disabled:bg-muted/60 disabled:text-muted-foreground","aria-invalid":!!S.id}),S.id?e.jsx("span",{className:"text-xs text-red-500",children:S.id}):null]}),e.jsxs("label",{className:"flex flex-col gap-2 text-sm",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:r("providers.drawer.fields.label")}),e.jsx("input",{value:i.label,onChange:c=>de("label")(c.target.value),placeholder:r("providers.drawer.fields.labelPlaceholder"),className:"h-11 rounded-2xl border border-border/80 bg-background/85 px-4 py-2 text-sm shadow-[0_1px_2px_rgba(15,23,42,0.03)] transition-all duration-200 focus:border-primary/40 focus:outline-none focus:ring-2 focus:ring-primary/20 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:r("providers.drawer.fields.baseUrl")}),e.jsx("input",{value:i.baseUrl,onChange:c=>de("baseUrl")(c.target.value),placeholder:r("providers.drawer.fields.baseUrlPlaceholder"),className:"h-11 rounded-2xl border border-border/80 bg-background/85 px-4 py-2 text-sm shadow-[0_1px_2px_rgba(15,23,42,0.03)] transition-all duration-200 focus:border-primary/40 focus:outline-none focus:ring-2 focus:ring-primary/20 disabled:bg-muted/60 disabled:text-muted-foreground","aria-invalid":!!S.baseUrl}),S.baseUrl?e.jsx("span",{className:"text-xs text-red-500",children:S.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:r("providers.drawer.sections.auth")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:r("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:r("providers.drawer.fields.apiKey")}),e.jsx("input",{value:i.apiKey,onChange:c=>de("apiKey")(c.target.value),placeholder:r("providers.drawer.fields.apiKeyPlaceholder"),className:"h-11 rounded-2xl border border-border/80 bg-background/85 px-4 py-2 text-sm shadow-[0_1px_2px_rgba(15,23,42,0.03)] transition-all duration-200 focus:border-primary/40 focus:outline-none focus:ring-2 focus:ring-primary/20 disabled:bg-muted/60 disabled:text-muted-foreground"})]}),e.jsxs("fieldset",{className:"grid gap-2 rounded-[1.3rem] border border-white/50 bg-card/88 p-4 text-xs shadow-[0_1px_2px_rgba(15,23,42,0.03)]",children:[e.jsx("legend",{className:"px-1 text-muted-foreground",children:r("providers.drawer.fields.authMode")}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:r("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:i.authMode==="apiKey",onChange:()=>le("apiKey"),className:"mt-0.5"}),e.jsx("span",{children:r("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:i.authMode==="authToken",onChange:()=>le("authToken"),className:"mt-0.5"}),e.jsx("span",{children:r("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:i.authMode==="xAuthToken",onChange:()=>le("xAuthToken"),className:"mt-0.5"}),e.jsx("span",{children:r("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:r("providers.drawer.fields.models")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:r("providers.drawer.modelsDescription")})]}),e.jsx("button",{type:"button",onClick:we,className:"rounded-full border border-border/80 bg-background/85 px-3 py-1.5 text-xs transition hover:border-primary/20 hover:bg-primary/5",children:r("providers.drawer.fields.addModel")})]}),S.models?e.jsx("p",{className:"text-xs text-red-500",children:S.models}):null,e.jsxs("div",{className:"space-y-4",children:[i.models.map((c,b)=>e.jsxs("div",{className:"rounded-[1.3rem] border border-white/50 bg-card/88 p-4 shadow-[0_1px_2px_rgba(15,23,42,0.03)]",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:r("providers.drawer.fields.modelId")}),e.jsx("input",{value:c.id,onChange:R=>H(b,R.target.value),placeholder:r("providers.drawer.fields.modelIdPlaceholder"),className:"h-11 rounded-2xl border border-border/80 bg-background/85 px-4 py-2 text-sm shadow-[0_1px_2px_rgba(15,23,42,0.03)] transition-all duration-200 focus:border-primary/40 focus:outline-none focus:ring-2 focus:ring-primary/20 disabled:bg-muted/60 disabled:text-muted-foreground"})]}),L?e.jsxs("label",{className:"flex flex-col gap-2 text-sm",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:r("providers.drawer.fields.modelLabel")}),e.jsx("input",{value:c.label??"",onChange:R=>Oe(b,{label:R.target.value}),placeholder:r("providers.drawer.fields.modelLabelPlaceholder"),className:"h-11 rounded-2xl border border-border/80 bg-background/85 px-4 py-2 text-sm shadow-[0_1px_2px_rgba(15,23,42,0.03)] transition-all duration-200 focus:border-primary/40 focus:outline-none focus:ring-2 focus:ring-primary/20 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-slate-600 dark:text-slate-300",children:[e.jsx("input",{type:"radio",name:"defaultModel",value:c.id,checked:i.defaultModel===c.id,onChange:()=>w(R=>({...R,defaultModel:c.id})),disabled:c.id.trim().length===0}),r("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:()=>Ue(b),disabled:i.models.length===0,children:r("providers.drawer.fields.removeModel")})]})]},c._key)),i.models.length===0?e.jsx("div",{className:"rounded-2xl border border-amber-300 bg-gradient-to-br from-amber-50 to-yellow-50 p-5 shadow-sm dark:border-amber-600/60 dark:from-amber-900/20 dark:to-yellow-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:r("providers.drawer.noModelsTitle")}),e.jsx("p",{className:"text-xs leading-relaxed text-amber-800 dark:text-amber-300",children:r("providers.drawer.noModelsHint",{providerId:i.id||"provider-id"})}),e.jsxs("div",{className:"rounded-md bg-amber-100/80 p-2.5 dark:bg-amber-800/40",children:[e.jsx("p",{className:"mb-1.5 text-xs font-medium text-amber-900 dark:text-amber-200",children:r("providers.drawer.routeExample")}),e.jsxs("code",{className:"block rounded-xl bg-white/90 px-2.5 py-1.5 font-mono text-xs text-amber-900 shadow-[0_1px_2px_rgba(15,23,42,0.06)] dark:bg-slate-900 dark:text-amber-100",children:['"claude-*": "',(i.id||"provider-id").trim()||"provider-id",':*"']})]})]})}):null]}),oe.length>1?e.jsx("div",{className:"text-xs text-muted-foreground",children:r("providers.drawer.defaultHint",{model:i.defaultModel||r("providers.card.noDefault")})}):null]})]}),e.jsx("aside",{className:"hidden border-l border-border/70 bg-background/55 px-5 py-5 xl:block",children:e.jsxs("div",{className:"sticky top-0 space-y-5",children:[e.jsxs("div",{className:"rounded-[1.3rem] border border-white/50 bg-card/92 p-4 shadow-[0_1px_2px_rgba(15,23,42,0.03)]",children:[e.jsx("p",{className:"text-[11px] font-medium uppercase tracking-[0.16em] text-muted-foreground",children:r("providers.drawer.formSummary")}),e.jsx("p",{className:"mt-2 text-base font-semibold",children:ye}),e.jsx("div",{className:"mt-4 space-y-3 text-sm",children:Ne.map(c=>e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsx("span",{className:"text-muted-foreground",children:c.label}),e.jsx("span",{className:"text-right font-medium",children:c.value})]},c.label))})]}),e.jsxs("div",{className:"rounded-[1.3rem] border border-white/50 bg-card/92 p-4 shadow-[0_1px_2px_rgba(15,23,42,0.03)]",children:[e.jsx("p",{className:"text-[11px] font-medium uppercase tracking-[0.16em] text-muted-foreground",children:r("providers.drawer.sections.checklist")}),e.jsxs("ul",{className:"mt-3 space-y-2 text-sm text-muted-foreground",children:[e.jsx("li",{children:r("providers.drawer.hints.checkUrl")}),e.jsx("li",{children:r("providers.drawer.hints.checkAuth")}),e.jsx("li",{children:r("providers.drawer.hints.checkModels")})]})]}),L&&e.jsxs("div",{className:"rounded-[1.3rem] border border-primary/20 bg-primary/5 p-4 text-sm text-foreground",children:[e.jsx("p",{className:"font-medium text-primary",children:r("providers.drawer.hints.advancedTitle")}),e.jsx("p",{className:"mt-2 text-xs text-muted-foreground",children:r("providers.drawer.hints.advancedBody")})]})]})})]}),e.jsxs("footer",{className:"flex items-center justify-between gap-3 border-t border-border/70 bg-background/70 px-6 py-4 text-sm",children:[e.jsx("div",{className:"flex flex-col text-xs text-red-500","aria-live":"polite",children:C?e.jsx("span",{children:C}):null}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{type:"button",onClick:p,className:"rounded-full border border-border/80 bg-background/85 px-4 py-2 transition hover:border-primary/20 hover:bg-primary/5",disabled:U,children:r("common.actions.cancel")}),e.jsx("button",{type:"button",onClick:Me,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:U,children:r(U?"common.actions.saving":"common.actions.save")})]})]})]})]}):null}const Ns=["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"],ws=["gpt-4o-mini","gpt-4o","o4-mini","o4-large","gpt-5-codex"];function He(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():Math.random().toString(36).slice(2,10)}function ee(s){return s?Object.entries(s).map(([l,f])=>({id:He(),source:l,target:f})):[]}function ze(s,l){var p,j,r;if(!s)return{};const f={},h=s.endpointRouting??{};f.anthropic=ee(((p=h.anthropic)==null?void 0:p.modelRoutes)??s.modelRoutes??{}),f.openai=ee(((j=h.openai)==null?void 0:j.modelRoutes)??{});for(const i of l)(r=i.routing)!=null&&r.modelRoutes?f[i.id]=ee(i.routing.modelRoutes):f[i.id]=[];return f}function mt(s,l,f){var j,r,i;const h=l.find(w=>w.id===f);if(h)return((j=h.routing)==null?void 0:j.modelRoutes)??{};const p=s.endpointRouting??{};return f==="anthropic"?((r=p.anthropic)==null?void 0:r.modelRoutes)??s.modelRoutes??{}:f==="openai"?((i=p.openai)==null?void 0:i.modelRoutes)??{}:{}}function ks(s){const l={};for(const f of s){const h=f.source.trim(),p=f.target.trim();h&&p&&(l[h]=p)}return l}function ut(s,l){return JSON.stringify(ks(s))!==JSON.stringify(l)}function Ms(s,l){if(s==="anthropic")return!0;const f=l.find(h=>h.id===s);return f?f.paths&&f.paths.length>0?f.paths.some(h=>h.protocol==="anthropic"):f.protocol==="anthropic":!1}function Cs(s,l,f){var p,j,r;if(!l)return;if(s==="anthropic"||s==="openai")return(j=(p=l.endpointRouting)==null?void 0:p[s])==null?void 0:j.validation;const h=f.find(i=>i.id===s);return(r=h==null?void 0:h.routing)==null?void 0:r.validation}function Qs(){const{t:s}=me(),{pushToast:l}=gt(),f=ds(),h=ps(["config","full"],{url:"/api/config",method:"GET"}),{data:p}=ls({queryKey:["custom-endpoints"],queryFn:ve.list,refetchInterval:1e4}),j=(p==null?void 0:p.endpoints)??[],r=x.useMemo(()=>{const t=[{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"]}],n=j.map(a=>{let o,d=[];if(a.paths&&a.paths.length>0){const m=a.paths.map(u=>`${u.path} (${u.protocol})`).join(", ");o=`${s("modelManagement.tabs.customEndpoint")}: ${m}`,d=[...new Set(a.paths.map(u=>u.protocol))]}else if(a.path){const m=a.protocol||"anthropic";o=`${s("modelManagement.tabs.customEndpoint")}: ${a.path} (${m})`,d=[m]}else o=s("modelManagement.tabs.customEndpoint");return{key:a.id,label:a.label,description:o,isSystem:!1,canDelete:a.deletable!==!1,protocols:d}});return[...t,...n]},[s,j]),[i,w]=x.useState("providers"),S=x.useMemo(()=>r.filter(t=>t.isSystem),[r]),I=x.useMemo(()=>r.filter(t=>!t.isSystem),[r]),U=x.useMemo(()=>r.find(t=>t.key===i)??r[0]??null,[i,r]),[g,C]=x.useState(null),[k,v]=x.useState(!1),[E,$]=x.useState("create"),[L,ae]=x.useState(void 0),[ne,oe]=x.useState(null),[je,ye]=x.useState(!1),[Ne,de]=x.useState(void 0),[G,B]=x.useState({}),[Oe,H]=x.useState({}),[Ue,we]=x.useState(null),[le,ue]=x.useState({}),[ke,Me]=x.useState({}),[c,b]=x.useState({}),[R,M]=x.useState(null),[_,q]=x.useState(null),[z,X]=x.useState(null),[Ce,te]=x.useState(!1),[$e,Qe]=x.useState(null),[Ee,Ae]=x.useState(!0),[Ge,Xe]=x.useState({}),[St,Je]=x.useState(!1),[Rt,Dt]=x.useState({}),[Le,Ie]=x.useState(null),[N,pe]=x.useState(null),[Fe,Ye]=x.useState(!1),[Se,We]=x.useState(""),[xe,Ze]=x.useState("all"),V=(g==null?void 0:g.providers)??[],et=V.length,tt=x.useMemo(()=>V.filter(t=>{var d;if(!(xe==="all"||(t.type??"custom")===xe))return!1;const a=Se.trim().toLowerCase();return a?[t.id,t.label??"",t.baseUrl,t.defaultModel??"",...((d=t.models)==null?void 0:d.map(m=>m.id))??[]].join(" ").toLowerCase().includes(a):!0}),[Se,xe,V]),he=x.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]);x.useEffect(()=>{var t,n;if(h.data){const a=h.data;C(a),B(d=>{const m=ze(a,j);if(!d||Object.keys(d).length===0)return m;const u={...m};for(const[y,D]of Object.entries(d)){if(!(y in m))continue;const A=mt(a,j,y);ut(D,A)&&(u[y]=D)}return u}),H({});const o={anthropic:((t=a.routingPresets)==null?void 0:t.anthropic)??[],openai:((n=a.routingPresets)==null?void 0:n.openai)??[]};for(const d of j)o[d.id]=d.routingPresets??[];ue(o)}},[h.data,j]),x.useEffect(()=>{h.isError&&h.error&&l({title:s("providers.toast.loadFailure",{message:h.error.message}),variant:"error"})},[h.isError,h.error,l,s]);const st=x.useMemo(()=>{const t=new Map;for(const n of V){if(!n.defaultModel||!n.models)continue;const a=n.models.find(o=>o.id===n.defaultModel);a&&t.set(n.id,xt(a))}return t},[V]),Pt=x.useMemo(()=>{const t=[],n=new Set;for(const o of V){const d=o.label&&o.label!==o.id?`${o.label} (${o.id})`:o.id,m=o.models??[];if(m.length>0)for(const y of m){const D=`${o.id}:${y.id}`;n.has(D)||(n.add(D),t.push({value:D,label:`${d} · ${y.label??y.id}`}))}else if(o.defaultModel){const y=`${o.id}:${o.defaultModel}`;n.has(y)||(n.add(y),t.push({value:y,label:`${d} · ${o.defaultModel}`}))}const u=`${o.id}:*`;n.has(u)||(n.add(u),t.push({value:u,label:s("settings.routing.providerPassthroughOption",{provider:d})}))}const a=Object.values(G).flat();for(const o of a){const d=o.target.trim();d&&!n.has(d)&&(n.add(d),t.push({value:d,label:d}))}return t},[V,G,s]),_t=t=>g?mt(g,j,t):{},Tt=(t,n)=>ut(t,n),Ke=x.useMemo(()=>{const t={};for(const n of r){if(n.key==="providers")continue;const a=G[n.key]||[],o=_t(n.key);t[n.key]=Tt(a,o)}return t},[G,g,j,r]),rt=(t,n)=>{ue(a=>({...a,[t]:n})),C(a=>{if(!a)return a;if(t==="anthropic"||t==="openai")return{...a,routingPresets:{...a.routingPresets,[t]:n}};const o=a.customEndpoints??[],d=o.findIndex(u=>u.id===t);if(d===-1)return a;const m=[...o];return m[d]={...m[d],routingPresets:n},{...a,customEndpoints:m}})},se=()=>g?!0:(l({title:s("settings.toast.missingConfig"),variant:"error"}),h.refetch(),!1),Ot=(t,n)=>{Me(a=>({...a,[t]:n})),n.trim()&&b(a=>({...a,[t]:null}))},Ut=async t=>{if(!se())return;const n=ke[t].trim();if(!n){b(a=>({...a,[t]:s("modelManagement.validation.presetName")}));return}if(le[t].some(a=>a.name.toLowerCase()===n.toLowerCase())){b(a=>({...a,[t]:s("modelManagement.validation.presetDuplicate",{name:n})}));return}M(t);try{const o=(await Y.post(`/api/routing-presets/${t}`,{name:n})).data.presets??[];rt(t,o),Me(d=>({...d,[t]:""})),b(d=>({...d,[t]:null})),l({title:s("modelManagement.toast.presetSaved",{name:n}),variant:"success"})}catch(a){l({title:s("modelManagement.toast.presetSaveFailure",{message:a instanceof Error?a.message:"unknown"}),variant:"error"})}finally{M(null),h.refetch()}},$t=async(t,n)=>{var a,o,d;if(se()){q({endpoint:t,name:n.name});try{const u=(await Y.post(`/api/routing-presets/${t}/apply`,{name:n.name})).data.config;if(u){C(u),B(ze(u,j));const y={anthropic:((a=u.routingPresets)==null?void 0:a.anthropic)??[],openai:((o=u.routingPresets)==null?void 0:o.openai)??[]};for(const D of j){const A=(d=u.customEndpoints)==null?void 0:d.find(T=>T.id===D.id);y[D.id]=(A==null?void 0:A.routingPresets)??[]}ue(y)}else B(y=>({...y,[t]:ee(n.modelRoutes)}));l({title:s("modelManagement.toast.presetApplySuccess",{name:n.name}),variant:"success"})}catch(m){l({title:s("modelManagement.toast.presetApplyFailure",{message:m instanceof Error?m.message:"unknown"}),variant:"error"})}finally{q(null),h.refetch()}}},At=async(t,n)=>{if(se()){X({endpoint:t,name:n.name});try{const o=(await Y.delete(`/api/routing-presets/${t}/${encodeURIComponent(n.name)}`)).data.presets??[];rt(t,o),l({title:s("modelManagement.toast.presetDeleteSuccess",{name:n.name}),variant:"success"})}catch(a){l({title:s("modelManagement.toast.presetDeleteFailure",{message:a instanceof Error?a.message:"unknown"}),variant:"error"})}finally{X(null),h.refetch()}}},Lt=()=>{se()&&($("create"),ae(void 0),v(!0))},It=t=>{se()&&($("edit"),ae(t),v(!0))},Ft=async t=>{if(!g)throw new Error(s("settings.toast.missingConfig"));const n=E==="create"?[...V,t]:V.map(d=>L&&d.id===L.id?{...t,id:L.id}:d),a={...g,providers:n};await Y.put("/api/config",a),C(a),B(ze(a,j)),h.refetch();const o=E==="create"?s("providers.toast.createSuccess",{name:t.label||t.id}):s("providers.toast.updateSuccess",{name:t.label||t.id});l({title:o,variant:"success"})},Kt=async t=>{const n=j.find(a=>a.id===t);if(n&&n.deletable!==!1)try{await ve.delete(t),f.invalidateQueries({queryKey:["custom-endpoints"]}),l({title:s("modelManagement.deleteEndpointSuccess"),variant:"success"}),i===t&&w("providers")}catch(a){const o=Te(a);l({title:s("modelManagement.deleteEndpointError",{error:o.message}),variant:"error"})}},at=async(t,n)=>{oe(t.id);try{const a=n&&(n.headers||n.query)?{headers:n.headers&&Object.keys(n.headers).length>0?n.headers:void 0,query:n.query&&n.query.trim().length>0?n.query.trim():void 0}:void 0,o=await Y.post(`/api/providers/${t.id}/test`,a);o.data.ok?l({title:s("providers.toast.testSuccess"),description:s("providers.toast.testSuccessDesc",{status:o.data.status,duration:o.data.durationMs?`${o.data.durationMs} ms`:"—"}),variant:"success"}):l({title:s("providers.toast.testFailure",{message:`${o.data.status} ${o.data.statusText}`}),variant:"error"})}catch(a){l({title:s("providers.toast.testFailure",{message:a instanceof Error?a.message:"unknown"}),variant:"error"})}finally{oe(null)}},Bt=t=>{if(t.type==="anthropic"){const n=t.extraHeaders??{},a=new Map(he.map(m=>[m.key.toLowerCase(),m])),o={};let d=!0;for(const m of he){const u=Object.entries(n).find(([y])=>y.toLowerCase()===m.key.toLowerCase());if(u){const[y,D]=u;String(D??"")===m.value||(d=!1,o[y]=String(D??""))}}for(const[m,u]of Object.entries(n))a.has(m.toLowerCase())||(o[m]=String(u??""));Xe(o),Ae(d),Qe(t),te(!0);return}at(t)},nt=()=>{te(!1),Qe(null),Ae(!0),Xe({})},zt=async()=>{if(!$e)return;const t={};if(Ee)for(const o of he)t[o.key]=o.value;const n=new Map(he.map(o=>[o.key.toLowerCase(),o]));for(const[o,d]of Object.entries(Ge)){const m=o.toLowerCase();n.get(m)&&Ee||(t[o]=d)}const a=$e;nt(),await at(a,{headers:Object.keys(t).length>0?t:void 0,query:Ee?"beta=true":void 0})},Vt=async t=>{var y,D,A,T;if(!se())return;const n=V.filter(K=>K.id!==t.id),a=K=>{const J={};if(!K)return J;for(const[ge,ie]of Object.entries(K)){if(!ie)continue;const[fe]=ie.split(":");fe&&fe===t.id||ie===t.id||(J[ge]=ie)}return J},o=(g==null?void 0:g.endpointRouting)??{},d=a(((y=o.anthropic)==null?void 0:y.modelRoutes)??(g==null?void 0:g.modelRoutes)??{}),m=a(((D=o.openai)==null?void 0:D.modelRoutes)??{}),u={...g,providers:n,modelRoutes:d,endpointRouting:{anthropic:{defaults:((A=o.anthropic)==null?void 0:A.defaults)??g.defaults,modelRoutes:d},openai:{defaults:((T=o.openai)==null?void 0:T.defaults)??g.defaults,modelRoutes:m}}};try{await Y.put("/api/config",u),C(u),B({anthropic:ee(d),openai:ee(m)}),l({title:s("providers.toast.deleteSuccess",{name:t.label||t.id}),variant:"success"}),h.refetch()}catch(K){l({title:s("providers.toast.deleteFailure",{message:K instanceof Error?K.message:"unknown"}),variant:"error"})}},Ht=async()=>{if(N){Ye(!0);try{N.kind==="provider"?await Vt(N.provider):N.kind==="preset"?await At(N.endpoint,N.preset):await Kt(N.endpoint.id),pe(null)}finally{Ye(!1)}}},qt=t=>{B(n=>({...n,[t]:[...n[t]||[],{id:He(),source:"",target:""}]})),H(n=>({...n,[t]:null}))},Qt=async(t,n)=>{if(se()){Je(!0);try{if(t==="anthropic"||t==="openai"){const a=g.endpointRouting?{...g.endpointRouting}:{},o=a[t]??{defaults:g.defaults,modelRoutes:(t==="anthropic"?g.modelRoutes:{})??{}},d={defaults:o.defaults??g.defaults,modelRoutes:o.modelRoutes??{}};let m=o.validation;n?(m={...m??{},mode:"claude-code"},m.allowExperimentalBlocks===void 0&&(m.allowExperimentalBlocks=!0)):m=void 0;const u=m?{...d,validation:m}:{...d},y={...a,[t]:u},D={...g,endpointRouting:y};await Y.put("/api/config",D),C(D)}else{const a=g.customEndpoints??[],o=a.findIndex(K=>K.id===t);if(o===-1)throw new Error(s("modelManagement.toast.endpointNotFound"));const d=a[o],m=d.routing??{defaults:g.defaults,modelRoutes:{}};let u=m.validation;n?(u={...u??{},mode:"claude-code"},u.allowExperimentalBlocks===void 0&&(u.allowExperimentalBlocks=!0)):u=void 0;const y=u?{...m,validation:u}:{...m},D={...d,routing:y},A=[...a];A[o]=D;const T={...g,customEndpoints:A};await Y.put("/api/config",T),C(T)}l({title:s(n?"modelManagement.toast.claudeValidationEnabled":"modelManagement.toast.claudeValidationDisabled"),variant:"success"}),h.refetch()}catch(a){const o=Te(a);l({title:s("modelManagement.toast.claudeValidationFailure",{message:o.message}),variant:"error"})}finally{Je(!1)}}},Gt=(t,n)=>{B(a=>{const o=a[t]||[];return o.some(d=>d.source.trim()===n.trim())?a:{...a,[t]:[...o,{id:He(),source:n,target:""}]}}),H(a=>({...a,[t]:null}))},ot=(t,n,a,o)=>{B(d=>({...d,[t]:(d[t]||[]).map(m=>m.id===n?{...m,[a]:o}:m)})),H(d=>({...d,[t]:null}))},Xt=(t,n)=>{B(a=>({...a,[t]:(a[t]||[]).filter(o=>o.id!==n)})),H(a=>({...a,[t]:null}))},Jt=t=>{var a,o;if(!g)return;const n=j.find(d=>d.id===t);if(n){const d=((a=n.routing)==null?void 0:a.modelRoutes)??{};B(m=>({...m,[t]:ee(d)}))}else{const d=g.endpointRouting??{},m=t,u=m==="anthropic"?g.modelRoutes??{}:{},y=((o=d[m])==null?void 0:o.modelRoutes)??u;B(D=>({...D,[t]:ee(y)}))}H(d=>({...d,[t]:null}))},Yt=async t=>{var o;if(!se())return;const n=G[t]||[],a={};for(const d of n){const m=d.source.trim(),u=d.target.trim();if(!(!m&&!u)){if(!m||!u){H(y=>({...y,[t]:s("settings.validation.routePair")}));return}if(a[m]){H(y=>({...y,[t]:s("settings.validation.routeDuplicate",{model:m})}));return}a[m]=u}}H(d=>({...d,[t]:null})),we(t);try{const d=j.find(m=>m.id===t);if(d){const m={...d.routing||{},modelRoutes:a,defaults:((o=d.routing)==null?void 0:o.defaults)||g.defaults};await ve.update(t,{routing:m}),f.invalidateQueries({queryKey:["custom-endpoints"]}),l({title:s("modelManagement.toast.routesSaved"),variant:"success"})}else{const m=g.endpointRouting?{...g.endpointRouting}:{},u=t,y=m[u]??{defaults:g.defaults,modelRoutes:u==="anthropic"?g.modelRoutes??{}:{}},D={...y,defaults:y.defaults??g.defaults,modelRoutes:a},A={...m,[u]:D},T={...g,endpointRouting:A,modelRoutes:u==="anthropic"?a:g.modelRoutes??{}};await Y.put("/api/config",T),C(T),l({title:s("modelManagement.toast.routesSaved"),variant:"success"}),h.refetch()}B(m=>({...m,[t]:ee(a)}))}catch(d){l({title:s("modelManagement.toast.routesSaveFailure",{message:d instanceof Error?d.message:"unknown"}),variant:"error"})}finally{we(null)}},Wt=()=>e.jsx(Re,{className:"surface-1",children:e.jsxs(De,{className:"pt-6 space-y-6",children:[e.jsx(pt,{eyebrow:"Model Access",title:s("providers.title"),description:s("providers.description"),breadcrumb:[s("modelManagement.title"),s("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(F,{variant:"secondary",children:s("providers.count",{count:et})}),e.jsxs(P,{variant:"outline",size:"sm",onClick:()=>h.refetch(),disabled:h.isFetching,children:[e.jsx(as,{className:Z("mr-2 h-4 w-4",h.isFetching&&"animate-spin")}),h.isFetching?s("common.actions.refreshing"):s("providers.actions.refresh")]}),e.jsxs(P,{size:"sm",onClick:Lt,children:[e.jsx(Ve,{className:"mr-2 h-4 w-4"}),s("providers.actions.add")]})]})}),e.jsxs("div",{className:"grid gap-3 rounded-[1.35rem] border border-border/70 bg-[linear-gradient(135deg,rgba(255,255,255,0.7),rgba(248,250,252,0.82))] p-4 lg:grid-cols-[minmax(0,1fr)_220px_auto]",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(Q,{className:"text-[11px] uppercase tracking-[0.16em] text-muted-foreground",children:s("providers.filters.searchPlaceholder")}),e.jsx(re,{value:Se,onChange:t=>We(t.target.value),placeholder:s("providers.filters.searchPlaceholder")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Q,{className:"text-[11px] uppercase tracking-[0.16em] text-muted-foreground",children:s("providers.filters.typeAll")}),e.jsxs(kt,{value:xe,onValueChange:Ze,children:[e.jsx(Mt,{children:e.jsx(Ct,{})}),e.jsxs(Et,{children:[e.jsx(W,{value:"all",children:s("providers.filters.typeAll")}),e.jsx(W,{value:"openai",children:"OpenAI"}),e.jsx(W,{value:"anthropic",children:"Anthropic"}),e.jsx(W,{value:"deepseek",children:"DeepSeek"}),e.jsx(W,{value:"huawei",children:"Huawei"}),e.jsx(W,{value:"kimi",children:"Kimi"}),e.jsx(W,{value:"custom",children:"Custom"})]})]})]}),e.jsx("div",{className:"flex items-end",children:e.jsx(P,{variant:"ghost",size:"sm",onClick:()=>{We(""),Ze("all")},disabled:!Se.trim()&&xe==="all",children:s("common.actions.reset")})})]}),h.isPending||!g&&h.isFetching?e.jsx("div",{className:"flex min-h-[200px] items-center justify-center rounded-[1.25rem] border border-border/70 bg-background/45 text-sm text-muted-foreground",children:s("common.loading")}):V.length===0?e.jsxs("div",{className:"rounded-[1.25rem] border border-dashed border-border/70 bg-background/45 p-12 text-center text-sm text-muted-foreground",children:[e.jsx("p",{className:"font-medium",children:s("providers.emptyState")}),e.jsx("p",{className:"mt-2 text-xs",children:s("providers.emptyStateSub",{default:"点击上方按钮添加您的第一个提供商"})})]}):tt.length===0?e.jsx("div",{className:"rounded-[1.25rem] border border-dashed border-border/70 bg-background/45 p-12 text-center text-sm text-muted-foreground",children:e.jsx("p",{className:"font-medium",children:s("providers.emptyFiltered")})}):e.jsx("div",{className:"grid gap-4 [grid-template-columns:repeat(auto-fit,minmax(280px,1fr))]",children:tt.map(t=>{var n;return e.jsx(Re,{className:"surface-1 flex flex-col overflow-hidden border-border/70",children:e.jsxs(De,{className:"flex flex-1 flex-col gap-4 pt-6",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",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:t.label||t.id}),t.type&&e.jsx(Ds,{type:t.type})]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["ID: ",t.id]}),e.jsx("p",{className:"break-all text-xs text-muted-foreground",children:t.baseUrl})]}),t.defaultModel?e.jsx(F,{variant:"default",className:"text-xs",children:st.get(t.id)??t.defaultModel}):e.jsx(F,{variant:"secondary",className:"text-xs",children:s("providers.card.noDefault")})]}),e.jsxs("div",{className:"grid gap-2 sm:grid-cols-3",children:[e.jsxs("div",{className:"rounded-2xl border border-border/70 bg-background/80 px-3 py-3",children:[e.jsx("p",{className:"text-[11px] font-medium uppercase tracking-[0.16em] text-muted-foreground",children:s("providers.card.authMode")}),e.jsx("p",{className:"mt-1 text-sm font-medium",children:t.authMode==="authToken"?"Bearer":t.authMode==="xAuthToken"?"X-Auth-Token":"API Key"})]}),e.jsxs("div",{className:"rounded-2xl border border-border/70 bg-background/80 px-3 py-3",children:[e.jsx("p",{className:"text-[11px] font-medium uppercase tracking-[0.16em] text-muted-foreground",children:s("providers.card.modelsTitle")}),e.jsx("p",{className:"mt-1 text-sm font-medium",children:(n=t.models)!=null&&n.length?s("providers.card.modelCount",{count:t.models.length}):s("providers.card.passthrough")})]}),e.jsxs("div",{className:"rounded-2xl border border-border/70 bg-background/80 px-3 py-3",children:[e.jsx("p",{className:"text-[11px] font-medium uppercase tracking-[0.16em] text-muted-foreground",children:s("providers.card.defaultModelLabel")}),e.jsx("p",{className:"mt-1 truncate text-sm font-medium",children:t.defaultModel?st.get(t.id)??t.defaultModel:s("providers.card.noDefault")})]})]}),e.jsxs("div",{className:"space-y-2 rounded-[1.1rem] border border-border/70 bg-background/55 p-3",children:[e.jsx(Q,{className:"text-xs uppercase tracking-[0.16em] text-muted-foreground",children:s("providers.card.modelsTitle")}),t.models&&t.models.length>0?e.jsx("div",{className:"flex max-h-24 flex-wrap gap-1 overflow-y-auto",children:t.models.map(a=>e.jsx(F,{variant:"outline",className:"text-xs",children:xt(a)},a.id))}):e.jsx("p",{className:"text-xs text-muted-foreground",children:s("providers.card.noModels")})]}),e.jsxs("div",{className:"mt-auto flex flex-wrap gap-2 border-t border-border/70 pt-4",children:[e.jsx(P,{variant:"default",size:"sm",onClick:()=>It(t),children:s("providers.actions.edit")}),e.jsx(P,{variant:"outline",size:"sm",onClick:()=>Bt(t),disabled:ne===t.id,children:ne===t.id?s("common.actions.testingConnection"):s("providers.actions.test")}),e.jsx(P,{variant:"destructive",size:"sm",onClick:()=>pe({kind:"provider",provider:t}),children:s("providers.actions.delete")})]})]})},t.id)})})]})}),Zt=t=>{const n=le[t]??[],a=ke[t]??"",o=c[t],d=R===t,m=Rt[t]===!0;return e.jsxs("div",{className:"rounded-[1.25rem] border border-dashed border-border/70 bg-background/45",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:()=>Dt(u=>({...u,[t]:!m})),children:e.jsxs("div",{className:"flex items-center gap-2",children:[m?e.jsx(os,{className:"h-4 w-4"}):e.jsx(ht,{className:"h-4 w-4"}),e.jsx("h3",{className:"font-medium",children:s("modelManagement.presets.title")}),e.jsx(F,{variant:"secondary",className:"text-xs",children:n.length})]})}),m&&e.jsxs("div",{className:"border-t px-4 pb-4 pt-3 space-y-4",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:s("modelManagement.presets.description")}),e.jsxs("div",{className:"flex flex-col gap-3 md:flex-row md:items-center",children:[e.jsx(re,{value:a,onChange:u=>Ot(t,u.target.value),placeholder:s("modelManagement.presets.namePlaceholder"),disabled:d,className:"w-full md:w-48"}),e.jsx(P,{onClick:()=>void Ut(t),disabled:d,children:s(d?"modelManagement.presets.saving":"modelManagement.presets.save")})]}),o&&e.jsx("p",{className:"text-sm text-destructive",children:o}),n.length===0?e.jsx("p",{className:"text-sm text-muted-foreground text-center py-4",children:s("modelManagement.presets.empty")}):e.jsx(is,{children:e.jsx("div",{className:"grid gap-2 sm:grid-cols-2 lg:grid-cols-3",children:n.map(u=>{const y=(_==null?void 0:_.endpoint)===t&&(_==null?void 0:_.name)===u.name,D=(z==null?void 0:z.endpoint)===t&&(z==null?void 0:z.name)===u.name,A=Object.entries(u.modelRoutes??{}),T=A.length;return e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-[1.15rem] border border-white/50 bg-card/88 px-4 py-3 shadow-[0_1px_2px_rgba(15,23,42,0.03)]",children:[e.jsxs(cs,{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:u.name}),e.jsx(F,{variant:"outline",className:"mt-1 text-xs",children:T>0?s("modelManagement.presets.rulesCount",{count:T}):s("modelManagement.presets.noRules")})]})}),T>0&&e.jsx(us,{side:"bottom",className:"max-w-xs",children:e.jsxs("div",{className:"space-y-1 text-xs",children:[A.slice(0,5).map(([K,J])=>e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"truncate",children:K}),e.jsx(ce,{className:"h-3 w-3 flex-shrink-0"}),e.jsx("span",{className:"truncate",children:J})]},K)),T>5&&e.jsxs("div",{className:"text-muted-foreground",children:["…+",T-5]})]})})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[e.jsx(P,{size:"sm",onClick:()=>Ie({endpoint:t,preset:u}),disabled:y||D,children:s(y?"modelManagement.presets.applying":"modelManagement.presets.apply")}),e.jsx(P,{variant:"destructive",size:"sm",onClick:()=>pe({kind:"preset",endpoint:t,preset:u}),disabled:D||y,children:s(D?"modelManagement.presets.deleting":"modelManagement.presets.delete")})]})]},u.name)})})})]})]})},es=t=>{var fe;const n=G[t]||[],a=Oe[t],o=r.find(O=>O.key===t),m=((fe=o==null?void 0:o.protocols)==null?void 0:fe.includes("anthropic"))??t==="anthropic"?Ns:ws,u=Ue===t,y=Ke[t]??!1,D=(o==null?void 0:o.label)??s(`modelManagement.tabs.${t}`),A=(o==null?void 0:o.isSystem)===!1?o.description:s(`settings.routing.descriptionByEndpoint.${t}`),T=`route-source-${t}`,K=Ms(t,j),J=Cs(t,g,j),ge=K&&(J==null?void 0:J.mode)==="claude-code",ie=new Set(n.map(O=>O.source.trim()).filter(Boolean));return e.jsx(Re,{className:"surface-1",children:e.jsxs(De,{className:"pt-6 space-y-6",children:[e.jsx(pt,{eyebrow:"Routing Workspace",title:s("settings.routing.titleByEndpoint",{endpoint:D}),description:A,breadcrumb:[s("modelManagement.title"),D],aside:e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs(F,{variant:"outline",children:[n.length," rules"]}),y?e.jsx(F,{variant:"outline",className:"border-amber-300 text-amber-700 dark:border-amber-700 dark:text-amber-300",children:s("modelManagement.actions.unsaved")}):e.jsx(F,{variant:"secondary",children:s("common.status.success")})]})}),e.jsx("div",{className:"rounded-[1.2rem] border border-border/70 bg-background/55 px-4 py-3 text-xs text-muted-foreground",children:s("settings.routing.wildcardHint")}),K&&e.jsx("div",{className:"rounded-[1.25rem] border border-blue-200 bg-blue-50/75 p-4 dark:border-blue-800 dark:bg-blue-950",children:e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-sm font-medium text-blue-800 dark:text-blue-200",children:s("modelManagement.claudeValidation.title")}),e.jsx("p",{className:"text-xs text-blue-700 dark:text-blue-300",children:s("modelManagement.claudeValidation.description")})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(wt,{checked:ge,onCheckedChange:O=>void Qt(t,O),disabled:St}),e.jsx("span",{className:Z("text-xs font-medium",ge?"text-emerald-600 dark:text-emerald-400":"text-muted-foreground"),children:s(ge?"modelManagement.claudeValidation.statusEnabled":"modelManagement.claudeValidation.statusDisabled")})]})]})}),Zt(t),a&&e.jsx("p",{className:"text-sm text-destructive",children:a}),e.jsxs("div",{className:"space-y-3 rounded-[1.35rem] border border-border/70 bg-[linear-gradient(135deg,rgba(255,255,255,0.7),rgba(248,250,252,0.82))] p-4",children:[e.jsx("div",{className:"flex items-center justify-between gap-3",children:e.jsxs("div",{children:[e.jsx(Q,{className:"text-sm font-semibold text-foreground",children:s("modelManagement.routesEditorTitle")}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:"Source model -> target provider:model"})]})}),n.length===0?e.jsxs("div",{className:"rounded-[1.25rem] border border-dashed border-border/70 bg-background/45 p-12 text-center text-sm text-muted-foreground",children:[e.jsx("p",{className:"font-medium",children:s("settings.routing.empty")}),e.jsx("p",{className:"mt-2 text-xs",children:s("modelManagement.emptyRoutesHint")})]}):e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"grid grid-cols-[minmax(0,1fr)_auto_minmax(0,1fr)_auto] items-center gap-3 px-1 text-xs font-medium text-muted-foreground",children:[e.jsx("span",{children:s("settings.routing.source")}),e.jsx("span",{}),e.jsx("span",{children:s("settings.routing.target")}),e.jsx("span",{})]}),n.map((O,be)=>e.jsxs("div",{className:"grid grid-cols-[minmax(0,1fr)_auto_minmax(0,1fr)_auto] items-center gap-3 rounded-[1rem] border border-border/60 bg-background/80 p-3",children:[e.jsx(re,{value:O.source,onChange:Be=>ot(t,O.id,"source",Be.target.value),placeholder:s("settings.routing.sourcePlaceholder"),list:T,disabled:u,"aria-label":`route-source-${be+1}`}),e.jsx(ce,{className:"h-4 w-4 text-muted-foreground flex-shrink-0"}),e.jsx(Ss,{value:O.target,onChange:Be=>ot(t,O.id,"target",Be),options:Pt,disabled:u,placeholder:s("settings.routing.targetPlaceholder")}),e.jsx(P,{variant:"ghost",size:"icon",className:"h-8 w-8 text-muted-foreground hover:text-destructive",onClick:()=>Xt(t,O.id),disabled:u,children:e.jsx(_e,{className:"h-4 w-4"})})]},O.id))]})]}),e.jsxs("div",{className:"rounded-[1.25rem] border border-border/70 bg-background/55 p-4 space-y-3",children:[e.jsxs("div",{children:[e.jsx(Q,{className:"text-sm font-semibold text-foreground",children:s("settings.routing.suggested")}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:"One click to seed common source models for this endpoint."})]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:m.map(O=>{const be=ie.has(O);return e.jsx(P,{variant:be?"ghost":"outline",size:"sm",onClick:()=>Gt(t,O),disabled:u||be,className:be?"opacity-50":"",children:O},`${t}-${O}`)})})]}),e.jsxs("div",{className:"flex flex-col gap-3 rounded-[1.25rem] border border-white/50 bg-card/82 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:s("modelManagement.actions.footerTitle")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s(y?"modelManagement.actions.footerDirtyHint":"modelManagement.actions.footerSavedHint")})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(P,{variant:"outline",size:"sm",onClick:()=>qt(t),disabled:u,children:s("settings.routing.add")}),e.jsx(P,{variant:"outline",size:"sm",onClick:()=>Jt(t),disabled:u||!y,children:s("common.actions.reset")}),e.jsxs(P,{size:"sm",onClick:()=>void Yt(t),disabled:u,className:"relative",children:[s(u?"common.actions.saving":"modelManagement.actions.saveRoutes"),y&&e.jsx("span",{className:"absolute -top-1 -right-1 h-2 w-2 rounded-full bg-amber-500"})]})]})]}),e.jsx("datalist",{id:T,children:m.map(O=>e.jsx("option",{value:O},`${T}-${O}`))})]})})},ts=(N==null?void 0:N.kind)==="provider"?s("providers.actions.delete"):(N==null?void 0:N.kind)==="preset"?s("modelManagement.presets.delete"):(N==null?void 0:N.kind)==="endpoint"?s("common.delete"):"",ss=(N==null?void 0:N.kind)==="provider"?s("providers.confirm.delete",{name:N.provider.label||N.provider.id}):(N==null?void 0:N.kind)==="preset"?s("modelManagement.confirm.deletePreset",{name:N.preset.name}):(N==null?void 0:N.kind)==="endpoint"?s("modelManagement.deleteEndpointConfirm",{label:N.endpoint.label}):"",dt=(N==null?void 0:N.kind)==="provider"?N.provider.label||N.provider.id:(N==null?void 0:N.kind)==="preset"?N.preset.name:(N==null?void 0:N.kind)==="endpoint"?N.endpoint.label:"";return e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx(xs,{icon:e.jsx(rs,{className:"h-5 w-5","aria-hidden":"true"}),title:s("modelManagement.title"),description:s("modelManagement.description"),actions:e.jsxs(P,{onClick:()=>{de(void 0),ye(!0)},children:[e.jsx(Ve,{className:"mr-2 h-4 w-4"}),s("modelManagement.addEndpoint")]})}),e.jsx(Re,{className:"surface-1 overflow-hidden",children:e.jsxs(De,{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(F,{variant:"outline",className:"border-primary/20 bg-primary/5 text-primary",children:[s("modelManagement.tabs.providers")," · ",et]}),e.jsxs(F,{variant:"outline",children:[s("modelManagement.tabs.customEndpoint")," · ",I.length]})]}),e.jsx("p",{className:"text-sm font-semibold text-foreground",children:U==null?void 0:U.label}),e.jsx("p",{className:"text-sm text-muted-foreground",children:U==null?void 0:U.description})]}),e.jsx("div",{className:"rounded-2xl border border-border/70 bg-background/75 px-3 py-2 text-xs text-muted-foreground",children:I.length>0?"自定义端点较多时,优先在下方端点带中切换,避免横向挤压布局。":"先配置提供商与内置路由,需要时再追加自定义端点。"})]}),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-[0.18em] text-muted-foreground",children:"内置视图"})}),e.jsx("div",{className:"grid gap-3 md:grid-cols-3",children:S.map(t=>{const n=i===t.key,a=t.key!=="providers"&&Ke[t.key];return e.jsxs("button",{type:"button",onClick:()=>w(t.key),className:Z("group flex min-h-[108px] flex-col justify-between rounded-[1.25rem] border px-4 py-4 text-left transition-all",n?"border-primary/35 bg-[linear-gradient(135deg,rgba(59,130,246,0.12),rgba(59,130,246,0.03))] shadow-[inset_0_0_0_1px_rgba(59,130,246,0.08)]":"border-border/70 bg-background/75 hover:border-primary/20 hover:bg-primary/5"),children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsx("span",{className:Z("text-lg font-semibold tracking-[-0.02em]",n?"text-primary":"text-foreground"),children:t.label}),a?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:t.description})]},t.key)})})]}),I.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-[0.18em] text-muted-foreground",children:"自定义接入端点"}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:"端点较多时保留紧凑卡片与横向滚动,避免标题和路径把整行撑乱。"})]})}),e.jsx("div",{className:"overflow-x-auto pb-1",children:e.jsx("div",{className:"flex min-w-full gap-3",children:I.map(t=>{const n=i===t.key,a=Ke[t.key];return e.jsxs("div",{className:Z("group relative flex w-[260px] shrink-0 snap-start flex-col gap-3 rounded-[1.2rem] border px-4 py-4 text-left transition-all",n?"border-primary/35 bg-[linear-gradient(135deg,rgba(59,130,246,0.12),rgba(59,130,246,0.03))] shadow-[inset_0_0_0_1px_rgba(59,130,246,0.08)]":"border-border/70 bg-background/80 hover:border-primary/20 hover:bg-primary/5"),children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsxs("button",{type:"button",onClick:()=>w(t.key),className:"min-w-0 flex-1 text-left",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:Z("truncate text-base font-semibold tracking-[-0.02em]",n?"text-primary":"text-foreground"),children:t.label}),a?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:t.description})]}),t.canDelete?e.jsx("button",{type:"button",onClick:o=>{o.stopPropagation();const d=j.find(m=>m.id===t.key);d&&pe({kind:"endpoint",endpoint:d})},className:"flex h-7 w-7 items-center justify-center rounded-full border border-transparent text-muted-foreground transition hover:border-destructive/20 hover:bg-destructive/10 hover:text-destructive",title:s("common.delete"),children:e.jsx(_e,{className:"h-3.5 w-3.5"})}):null]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:(t.protocols??[]).map(o=>e.jsx(F,{variant:"outline",className:"max-w-full truncate border-border/70 bg-background/80 text-[11px] text-muted-foreground",children:o},`${t.key}-${o}`))})]},t.key)})})})]}):null]})}),i==="providers"?Wt():es(i),e.jsx(ys,{open:k,mode:E,provider:E==="edit"?L:void 0,existingProviderIds:V.map(t=>t.id).filter(t=>E==="edit"&&L?t!==L.id:!0),onClose:()=>{v(!1),ae(void 0),$("create")},onSubmit:Ft}),e.jsx(Ps,{open:je,endpoint:Ne,onClose:()=>{ye(!1),de(void 0)},onSuccess:()=>{f.invalidateQueries({queryKey:["custom-endpoints"]})}}),e.jsx(Es,{open:Ce,provider:$e,options:he,preservedExtras:Ge,usePreset:Ee,onPresetChange:Ae,onConfirm:zt,onClose:nt}),e.jsx(Rs,{dialog:Le,currentRoutes:Le?G[Le.endpoint]||[]:[],onConfirm:(t,n)=>{Ie(null),$t(t,n)},onClose:()=>Ie(null)}),e.jsx(hs,{open:!!N,onOpenChange:t=>{!t&&!Fe&&pe(null)},title:ts,description:ss,confirmLabel:s(Fe?"common.actions.loading":"common.delete"),cancelLabel:s("common.actions.cancel"),loading:Fe,onConfirm:Ht,children:dt?e.jsx("div",{className:"rounded-[1rem] border border-destructive/20 bg-destructive/5 px-3 py-2 font-mono text-xs text-foreground",children:dt}):null})]})}function pt({eyebrow:s,title:l,description:f,breadcrumb:h,aside:p}){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}),h.map((j,r)=>e.jsxs(ns.Fragment,{children:[r>0?e.jsx(ht,{className:"h-3.5 w-3.5"}):null,e.jsx("span",{className:Z(r===h.length-1&&"text-foreground"),children:j})]},`${j}-${r}`))]}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-semibold tracking-[-0.03em] text-foreground",children:l}),e.jsx("p",{className:"mt-1 max-w-3xl text-sm text-muted-foreground",children:f})]})]}),p?e.jsx("div",{className:"flex shrink-0 items-center gap-2",children:p}):null]})}function Es({open:s,provider:l,options:f,usePreset:h,preservedExtras:p,onPresetChange:j,onConfirm:r,onClose:i}){const{t:w}=me();return l?e.jsx(ft,{open:s,onOpenChange:S=>!S&&i(),children:e.jsxs(bt,{children:[e.jsxs(vt,{children:[e.jsx(jt,{children:w("providers.testDialog.title")}),e.jsx(yt,{children:w("providers.testDialog.subtitle",{name:l.label||l.id})})]}),e.jsxs("div",{className:"min-h-0 space-y-4 overflow-y-auto",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:w("providers.testDialog.description")}),e.jsxs("div",{className:"flex items-start gap-3 rounded-[1.2rem] border border-border/70 bg-background/45 p-4",children:[e.jsx("input",{type:"checkbox",className:"mt-1 h-4 w-4 rounded border",checked:h,onChange:S=>j(S.target.checked)}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Q,{children:w("providers.testDialog.presetLabel")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:w("providers.testDialog.presetDescription")}),e.jsxs("details",{className:"rounded-[1rem] border border-border/70 bg-background/70 p-2 text-xs",children:[e.jsx("summary",{className:"cursor-pointer text-primary hover:underline",children:w("providers.testDialog.presetPreviewSummary")}),e.jsx("div",{className:"mt-2 space-y-1",children:f.map(S=>e.jsxs("code",{className:"block rounded-xl border border-border/70 bg-background/85 px-2 py-1 text-xs",children:[S.key,": ",S.value]},S.key))})]})]})]}),Object.keys(p).length>0&&e.jsxs("div",{className:"rounded-[1.15rem] border border-border/70 bg-background/70 p-4 text-xs space-y-2",children:[e.jsx("p",{className:"font-medium",children:w("providers.testDialog.preservedInfo")}),Object.entries(p).map(([S,I])=>e.jsxs("code",{className:"block rounded-xl border border-border/70 bg-background/85 px-2 py-1",children:[S,": ",I]},S))]})]}),e.jsxs(Nt,{children:[e.jsx(P,{variant:"outline",onClick:i,children:w("providers.testDialog.cancel")}),e.jsx(P,{onClick:()=>void r(),children:w("providers.testDialog.primary")})]})]})}):null}function Ss({value:s,onChange:l,options:f,disabled:h,placeholder:p}){const{t:j}=me(),[r,i]=x.useState(!1),[w,S]=x.useState(""),I=x.useRef(null),U=x.useMemo(()=>{if(!w.trim())return f;const C=w.toLowerCase();return f.filter(k=>k.label.toLowerCase().includes(C)||k.value.toLowerCase().includes(C))},[f,w]),g=C=>{l(C),S(""),i(!1)};return e.jsxs(gs,{open:r,onOpenChange:C=>{i(C),C&&S("")},children:[e.jsx(fs,{asChild:!0,children:e.jsx(re,{ref:I,value:s,onChange:C=>{l(C.target.value),S(C.target.value),r||i(!0)},onFocus:()=>{S(""),i(!0)},onClick:()=>{r||i(!0)},placeholder:p,disabled:h,autoComplete:"off"})}),e.jsx(bs,{className:"w-[var(--radix-popover-trigger-width)] max-h-60 overflow-y-auto p-1",align:"start",onOpenAutoFocus:C=>C.preventDefault(),children:U.length===0?e.jsx("div",{className:"px-2 py-3 text-center text-xs text-muted-foreground",children:j("common.noMatches")}):U.map(C=>e.jsx("button",{type:"button",className:Z("flex w-full items-center rounded-sm px-2 py-1.5 text-left text-sm hover:bg-accent",C.value===s.trim()&&"bg-accent"),onMouseDown:k=>{k.preventDefault(),g(C.value)},children:e.jsx("span",{className:"truncate",children:C.label})},C.value))})]})}function Rs({dialog:s,currentRoutes:l,onConfirm:f,onClose:h}){const{t:p}=me();if(!s)return null;const{endpoint:j,preset:r}=s,i=r.modelRoutes??{},w={};for(const k of l){const v=k.source.trim(),E=k.target.trim();v&&E&&(w[v]=E)}const S=new Set([...Object.keys(w),...Object.keys(i)]),I=[],U=[],g=[];for(const k of S){const v=k in w,E=k in i;E&&!v?I.push([k,i[k]]):v&&!E?U.push([k,w[k]]):v&&E&&w[k]!==i[k]&&g.push([k,w[k],i[k]])}const C=I.length>0||U.length>0||g.length>0;return e.jsx(ft,{open:!0,onOpenChange:k=>!k&&h(),children:e.jsxs(bt,{className:"max-w-lg",children:[e.jsxs(vt,{children:[e.jsx(jt,{children:p("modelManagement.presets.diffTitle")}),e.jsx(yt,{children:p("modelManagement.presets.diffDescription",{name:r.name})})]}),C?e.jsxs("div",{className:"max-h-72 overflow-y-auto space-y-2 text-sm",children:[I.map(([k,v])=>e.jsxs("div",{className:"flex items-center gap-2 rounded-xl px-2 py-1.5 bg-emerald-50 dark:bg-emerald-950 text-emerald-800 dark:text-emerald-200",children:[e.jsx(F,{variant:"outline",className:"text-xs border-emerald-300 dark:border-emerald-700",children:p("modelManagement.presets.diffAdded")}),e.jsx("span",{className:"truncate",children:k}),e.jsx(ce,{className:"h-3 w-3 flex-shrink-0"}),e.jsx("span",{className:"truncate",children:v})]},`add-${k}`)),U.map(([k,v])=>e.jsxs("div",{className:"flex items-center gap-2 rounded-xl px-2 py-1.5 bg-red-50 dark:bg-red-950 text-red-800 dark:text-red-200",children:[e.jsx(F,{variant:"outline",className:"text-xs border-red-300 dark:border-red-700",children:p("modelManagement.presets.diffRemoved")}),e.jsx("span",{className:"truncate",children:k}),e.jsx(ce,{className:"h-3 w-3 flex-shrink-0"}),e.jsx("span",{className:"truncate",children:v})]},`rm-${k}`)),g.map(([k,v,E])=>e.jsxs("div",{className:"flex items-center gap-2 rounded-xl px-2 py-1.5 bg-amber-50 dark:bg-amber-950 text-amber-800 dark:text-amber-200",children:[e.jsx(F,{variant:"outline",className:"text-xs border-amber-300 dark:border-amber-700",children:p("modelManagement.presets.diffChanged")}),e.jsx("span",{className:"truncate",children:k}),e.jsx(ce,{className:"h-3 w-3 flex-shrink-0"}),e.jsx("span",{className:"truncate line-through opacity-60",children:v}),e.jsx(ce,{className:"h-3 w-3 flex-shrink-0"}),e.jsx("span",{className:"truncate",children:E})]},`chg-${k}`))]}):e.jsx("p",{className:"py-4 text-center text-sm text-muted-foreground",children:p("modelManagement.presets.diffEmpty")}),e.jsxs(Nt,{children:[e.jsx(P,{variant:"outline",onClick:h,children:p("common.cancel")}),e.jsx(P,{onClick:()=>f(j,r),disabled:!C,children:p("modelManagement.presets.diffConfirm")})]})]})})}function xt(s){return s.label&&s.label.trim().length>0?`${s.label} (${s.id})`:s.id}function Ds({type:s}){const l={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:f,variant:h}=l[s]||l.custom;return e.jsx(F,{variant:h,className:"text-xs",children:f})}function Ps({open:s,endpoint:l,onClose:f,onSuccess:h}){const{t:p}=me(),{pushToast:j}=gt(),[r,i]=x.useState({id:"",label:"",paths:[{path:"",protocol:"openai-auto"}],enabled:!0});x.useEffect(()=>{if(l){let v;l.paths&&l.paths.length>0?v=l.paths:l.path&&l.protocol?v=[{path:l.path,protocol:l.protocol}]:v=[{path:"",protocol:"openai-auto"}],i({id:l.id,label:l.label,paths:v,enabled:l.enabled!==!1})}else i({id:"",label:"",paths:[{path:"",protocol:"openai-auto"}],enabled:!0})},[l,s]);const w=lt({mutationFn:ve.create,onSuccess:()=>{j({title:p("modelManagement.createEndpointSuccess"),variant:"success"}),h(),f()},onError:v=>{const E=Te(v);j({title:p("modelManagement.createEndpointError",{error:E.message}),variant:"error"})}}),S=lt({mutationFn:v=>ve.update(v.id,v.updates),onSuccess:()=>{j({title:p("modelManagement.updateEndpointSuccess"),variant:"success"}),h(),f()},onError:v=>{const E=Te(v);j({title:p("modelManagement.updateEndpointError",{error:E.message}),variant:"error"})}}),I=()=>{i({...r,paths:[...r.paths,{path:"",protocol:"anthropic"}]})},U=v=>{if(r.paths.length===1){j({title:p("modelManagement.atLeastOnePath"),variant:"error"});return}const E=r.paths.filter(($,L)=>L!==v);i({...r,paths:E})},g=(v,E,$)=>{const L=[...r.paths];L[v]={...L[v],[E]:$},i({...r,paths:L})},C=v=>{if(v.preventDefault(),!r.id.trim()||!r.label.trim()){j({title:p("modelManagement.endpointValidationError"),variant:"error"});return}for(const $ of r.paths)if(!$.path.trim()){j({title:p("modelManagement.pathValidationError"),variant:"error"});return}const E=r.paths.map($=>({path:$.path.trim(),protocol:$.protocol}));l?S.mutate({id:l.id,updates:{label:r.label.trim(),paths:E,enabled:r.enabled}}):w.mutate({id:r.id.trim(),label:r.label.trim(),paths:E,enabled:r.enabled})},k=w.isPending||S.isPending;return s?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-40 bg-slate-950/45 backdrop-blur-sm",onClick:f}),e.jsx("div",{className:"fixed inset-y-0 right-0 z-50 w-full max-w-md border-l border-white/50 bg-background/96 shadow-[0_24px_80px_-32px_rgba(15,23,42,0.4)] backdrop-blur-xl",children:e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-border/70 bg-background/70 p-6",children:[e.jsx("h2",{className:"text-lg font-semibold tracking-[-0.02em]",children:p(l?"modelManagement.editEndpoint":"modelManagement.createEndpoint")}),e.jsx(P,{variant:"ghost",size:"sm",onClick:f,children:e.jsx(_e,{className:"h-4 w-4"})})]}),e.jsxs("form",{onSubmit:C,className:"flex-1 overflow-y-auto p-6 space-y-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs(Q,{children:[p("modelManagement.endpointId")," ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(re,{value:r.id,onChange:v=>i({...r,id:v.target.value}),placeholder:p("modelManagement.endpointIdPlaceholder"),disabled:!!l,required:!0}),e.jsx("p",{className:"text-xs text-muted-foreground",children:p("modelManagement.endpointIdHint")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(Q,{children:[p("modelManagement.endpointLabel")," ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(re,{value:r.label,onChange:v=>i({...r,label:v.target.value}),placeholder:p("modelManagement.endpointLabelPlaceholder"),required:!0})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(Q,{children:[p("modelManagement.endpointPaths")," ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsxs(P,{type:"button",variant:"ghost",size:"sm",onClick:I,children:[e.jsx(Ve,{className:"mr-1 h-3 w-3"}),p("modelManagement.addPath")]})]}),e.jsx("div",{className:"space-y-3",children:r.paths.map((v,E)=>e.jsxs("div",{className:"rounded-[1.15rem] border border-white/50 bg-card/88 p-3 space-y-2 shadow-[0_1px_2px_rgba(15,23,42,0.03)]",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(re,{value:v.path,onChange:$=>g(E,"path",$.target.value),placeholder:p("modelManagement.endpointPathPlaceholder"),required:!0}),e.jsxs(kt,{value:v.protocol,onValueChange:$=>g(E,"protocol",$),children:[e.jsx(Mt,{children:e.jsx(Ct,{})}),e.jsxs(Et,{children:[e.jsx(W,{value:"anthropic",children:p("modelManagement.protocolAnthropic")}),e.jsx(W,{value:"openai-auto",children:p("modelManagement.protocolOpenAI")})]})]})]}),r.paths.length>1&&e.jsx(P,{type:"button",variant:"ghost",size:"sm",onClick:()=>U(E),className:"text-destructive",children:e.jsx(_e,{className:"h-4 w-4"})})]}),E===0&&e.jsx("p",{className:"text-xs text-muted-foreground",children:p("modelManagement.endpointPathHint")})]},E))})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(wt,{id:"enabled",checked:r.enabled,onCheckedChange:v=>i({...r,enabled:v})}),e.jsx(Q,{htmlFor:"enabled",children:p("modelManagement.endpointEnabled")})]}),!l&&e.jsx("div",{className:"rounded-[1.2rem] border border-blue-200 bg-blue-50/75 p-4 dark:border-blue-800 dark:bg-blue-950",children:e.jsx("p",{className:"text-sm text-blue-800 dark:text-blue-200",children:p("modelManagement.endpointRoutingHint")})})]}),e.jsxs("div",{className:"flex gap-3 border-t border-border/70 bg-background/70 p-6",children:[e.jsx(P,{variant:"outline",className:"flex-1",onClick:f,disabled:k,children:p("common.cancel")}),e.jsx(P,{className:"flex-1",onClick:C,disabled:k,children:p(k?"common.saving":l?"common.save":"common.create")})]})]})})]}):null}export{Qs as default};
@@ -1 +1 @@
1
- import{f as r,L as b}from"./vendor-C92xTG6Z.js";import{c as l}from"./index-CB0xlluu.js";const c=b("inline-flex items-center rounded-full border px-2.5 py-1 text-[11px] font-semibold tracking-[0.02em] transition-all duration-200 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",{variants:{variant:{default:"border-primary/15 bg-primary/10 text-primary hover:bg-primary/15 dark:border-primary/25 dark:bg-primary/15 dark:text-primary-foreground",secondary:"border-border/70 bg-secondary/90 text-secondary-foreground hover:bg-secondary dark:border-border dark:bg-secondary/70 dark:text-secondary-foreground",destructive:"border-red-200 bg-red-50 text-red-700 hover:bg-red-100 dark:border-red-900 dark:bg-red-950/60 dark:text-red-300",outline:"border-border bg-transparent text-muted-foreground hover:bg-accent dark:border-border dark:text-muted-foreground dark:hover:bg-accent",success:"border-emerald-200 bg-emerald-50 text-emerald-700 hover:bg-emerald-100 dark:border-emerald-900 dark:bg-emerald-950/60 dark:text-emerald-300",warning:"border-amber-200 bg-amber-50 text-amber-700 hover:bg-amber-100 dark:border-amber-900 dark:bg-amber-950/60 dark:text-amber-300",info:"border-cyan-200 bg-cyan-50 text-cyan-700 hover:bg-cyan-100 dark:border-cyan-900 dark:bg-cyan-950/60 dark:text-cyan-300",purple:"border-violet-200 bg-violet-50 text-violet-700 hover:bg-violet-100 dark:border-violet-900 dark:bg-violet-950/60 dark:text-violet-300",pink:"border-pink-200 bg-pink-50 text-pink-700 hover:bg-pink-100 dark:border-pink-900 dark:bg-pink-950/60 dark:text-pink-300"}},defaultVariants:{variant:"default"}});function m({className:e,variant:n,...a}){return r.jsx("div",{className:l(c({variant:n}),e),...a})}function f({icon:e,title:n,description:a,badge:o,eyebrow:d,breadcrumb:t,helper:s,actions:i,className:x}){return r.jsxs("div",{className:l("flex flex-col gap-5 rounded-[1.6rem] border border-white/50 bg-[linear-gradient(135deg,rgba(255,255,255,0.72),rgba(248,250,252,0.88))] p-5 shadow-[0_1px_2px_rgba(15,23,42,0.03)] backdrop-blur sm:flex-row sm:items-start sm:justify-between",x),children:[r.jsxs("div",{className:"flex flex-1 flex-wrap items-start gap-4",children:[e&&r.jsx("div",{className:"flex h-12 w-12 items-center justify-center rounded-2xl bg-primary/10 text-primary shadow-[inset_0_0_0_1px_rgba(59,130,246,0.08)]",children:e}),r.jsxs("div",{className:"min-w-0 space-y-2",children:[(d||t)&&r.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-[11px] font-semibold uppercase tracking-[0.18em] text-muted-foreground",children:[d?r.jsx("span",{children:d}):null,d&&t?r.jsx("span",{className:"h-1 w-1 rounded-full bg-muted-foreground/50"}):null,t?r.jsx("span",{className:"text-muted-foreground/90",children:t}):null]}),r.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[r.jsx("h1",{className:"text-2xl font-semibold tracking-[-0.02em]",children:n}),o&&r.jsx(m,{variant:"secondary",children:o})]}),a&&r.jsx("p",{className:"max-w-3xl text-sm text-muted-foreground",children:a}),s&&r.jsx("div",{className:"rounded-2xl border border-border/70 bg-background/70 px-3.5 py-2 text-xs text-muted-foreground",children:s})]})]}),i&&r.jsx("div",{className:"flex shrink-0 flex-wrap items-center gap-2 self-start",children:i})]})}export{m as B,f as P};
1
+ import{f as r,L as b}from"./vendor-C92xTG6Z.js";import{c as l}from"./index-BuTkie0t.js";const c=b("inline-flex items-center rounded-full border px-2.5 py-1 text-[11px] font-semibold tracking-[0.02em] transition-all duration-200 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",{variants:{variant:{default:"border-primary/15 bg-primary/10 text-primary hover:bg-primary/15 dark:border-primary/25 dark:bg-primary/15 dark:text-primary-foreground",secondary:"border-border/70 bg-secondary/90 text-secondary-foreground hover:bg-secondary dark:border-border dark:bg-secondary/70 dark:text-secondary-foreground",destructive:"border-red-200 bg-red-50 text-red-700 hover:bg-red-100 dark:border-red-900 dark:bg-red-950/60 dark:text-red-300",outline:"border-border bg-transparent text-muted-foreground hover:bg-accent dark:border-border dark:text-muted-foreground dark:hover:bg-accent",success:"border-emerald-200 bg-emerald-50 text-emerald-700 hover:bg-emerald-100 dark:border-emerald-900 dark:bg-emerald-950/60 dark:text-emerald-300",warning:"border-amber-200 bg-amber-50 text-amber-700 hover:bg-amber-100 dark:border-amber-900 dark:bg-amber-950/60 dark:text-amber-300",info:"border-cyan-200 bg-cyan-50 text-cyan-700 hover:bg-cyan-100 dark:border-cyan-900 dark:bg-cyan-950/60 dark:text-cyan-300",purple:"border-violet-200 bg-violet-50 text-violet-700 hover:bg-violet-100 dark:border-violet-900 dark:bg-violet-950/60 dark:text-violet-300",pink:"border-pink-200 bg-pink-50 text-pink-700 hover:bg-pink-100 dark:border-pink-900 dark:bg-pink-950/60 dark:text-pink-300"}},defaultVariants:{variant:"default"}});function m({className:e,variant:n,...a}){return r.jsx("div",{className:l(c({variant:n}),e),...a})}function f({icon:e,title:n,description:a,badge:o,eyebrow:d,breadcrumb:t,helper:s,actions:i,className:x}){return r.jsxs("div",{className:l("flex flex-col gap-5 rounded-[1.6rem] border border-white/50 bg-[linear-gradient(135deg,rgba(255,255,255,0.72),rgba(248,250,252,0.88))] p-5 shadow-[0_1px_2px_rgba(15,23,42,0.03)] backdrop-blur sm:flex-row sm:items-start sm:justify-between",x),children:[r.jsxs("div",{className:"flex flex-1 flex-wrap items-start gap-4",children:[e&&r.jsx("div",{className:"flex h-12 w-12 items-center justify-center rounded-2xl bg-primary/10 text-primary shadow-[inset_0_0_0_1px_rgba(59,130,246,0.08)]",children:e}),r.jsxs("div",{className:"min-w-0 space-y-2",children:[(d||t)&&r.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-[11px] font-semibold uppercase tracking-[0.18em] text-muted-foreground",children:[d?r.jsx("span",{children:d}):null,d&&t?r.jsx("span",{className:"h-1 w-1 rounded-full bg-muted-foreground/50"}):null,t?r.jsx("span",{className:"text-muted-foreground/90",children:t}):null]}),r.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[r.jsx("h1",{className:"text-2xl font-semibold tracking-[-0.02em]",children:n}),o&&r.jsx(m,{variant:"secondary",children:o})]}),a&&r.jsx("p",{className:"max-w-3xl text-sm text-muted-foreground",children:a}),s&&r.jsx("div",{className:"rounded-2xl border border-border/70 bg-background/70 px-3.5 py-2 text-xs text-muted-foreground",children:s})]})]}),i&&r.jsx("div",{className:"flex shrink-0 flex-wrap items-center gap-2 self-start",children:i})]})}export{m as B,f as P};
@@ -1 +1 @@
1
- import{f as e}from"./vendor-C92xTG6Z.js";import{c as m}from"./index-CB0xlluu.js";import{C as o,b as x,c as f,d as i,a as p}from"./card-pQJ3gJlC.js";function b({title:a,description:s,eyebrow:d,actions:r,className:c,contentClassName:l,children:n}){const t=a||s||r;return e.jsxs(o,{className:m("surface-1 overflow-hidden",c),children:[t&&e.jsxs(x,{className:"flex flex-col gap-4 border-b border-border/60 bg-background/35 sm:flex-row sm:items-start sm:justify-between sm:space-y-0",children:[e.jsxs("div",{className:"space-y-1.5",children:[d?e.jsx("div",{className:"text-[11px] font-semibold uppercase tracking-[0.18em] text-muted-foreground",children:d}):null,typeof a=="string"?e.jsx(f,{className:"text-base font-semibold",children:a}):a,s&&(typeof s=="string"?e.jsx(i,{children:s}):e.jsx("div",{className:"text-sm text-muted-foreground",children:s}))]}),r&&e.jsx("div",{className:"flex shrink-0 flex-wrap items-center gap-2",children:r})]}),e.jsx(p,{className:m(!t&&"pt-6",t&&"pt-5",l),children:n})]})}export{b as P};
1
+ import{f as e}from"./vendor-C92xTG6Z.js";import{c as m}from"./index-BuTkie0t.js";import{C as o,b as x,c as f,d as i,a as p}from"./card-BD2y3CjZ.js";function b({title:a,description:s,eyebrow:d,actions:r,className:c,contentClassName:l,children:n}){const t=a||s||r;return e.jsxs(o,{className:m("surface-1 overflow-hidden",c),children:[t&&e.jsxs(x,{className:"flex flex-col gap-4 border-b border-border/60 bg-background/35 sm:flex-row sm:items-start sm:justify-between sm:space-y-0",children:[e.jsxs("div",{className:"space-y-1.5",children:[d?e.jsx("div",{className:"text-[11px] font-semibold uppercase tracking-[0.18em] text-muted-foreground",children:d}):null,typeof a=="string"?e.jsx(f,{className:"text-base font-semibold",children:a}):a,s&&(typeof s=="string"?e.jsx(i,{children:s}):e.jsx("div",{className:"text-sm text-muted-foreground",children:s}))]}),r&&e.jsx("div",{className:"flex shrink-0 flex-wrap items-center gap-2",children:r})]}),e.jsx(p,{className:m(!t&&"pt-6",t&&"pt-5",l),children:n})]})}export{b as P};