@chenpu17/cc-gw 0.8.2 → 0.8.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 (36) hide show
  1. package/README.md +3 -3
  2. package/package.json +5 -5
  3. package/src/web/dist/assets/About-CTbbI3Xf.js +1 -0
  4. package/src/web/dist/assets/ApiKeys-Dca6MyO2.js +1 -0
  5. package/src/web/dist/assets/ConfirmDialog-DW7jBfm1.js +1 -0
  6. package/src/web/dist/assets/{Dashboard-BizLDn_V.js → Dashboard-DMo-YHgS.js} +1 -1
  7. package/src/web/dist/assets/{DialogShell-CiIvBp8J.js → DialogShell-BqzUE3vU.js} +1 -1
  8. package/src/web/dist/assets/{Events-DpPg8dt0.js → Events-19qjsHJf.js} +1 -1
  9. package/src/web/dist/assets/{Help-B9ewdIkl.js → Help-FrXAXPhx.js} +1 -1
  10. package/src/web/dist/assets/{Login-5O2Xtr5G.js → Login-BYpsX-S8.js} +1 -1
  11. package/src/web/dist/assets/{Logs-D29vlNyO.js → Logs-ynLMNHgv.js} +1 -1
  12. package/src/web/dist/assets/ModelManagement-DrE_4kky.js +1 -0
  13. package/src/web/dist/assets/{PageHeader-CSF0BWul.js → PageHeader-DDxjKW4B.js} +1 -1
  14. package/src/web/dist/assets/{PageSection-Bp_SuEp0.js → PageSection-DRyQEnmK.js} +1 -1
  15. package/src/web/dist/assets/{PageState-BeXrzVEe.js → PageState-DA98vXl7.js} +1 -1
  16. package/src/web/dist/assets/{Profiler-Cwuq3cjV.js → Profiler-D5P7FF0I.js} +1 -1
  17. package/src/web/dist/assets/Settings-D8Xgk7cH.js +1 -0
  18. package/src/web/dist/assets/{Skeleton-8j6Dxod1.js → Skeleton-D_opZxQ7.js} +1 -1
  19. package/src/web/dist/assets/{badge-BvMdmUqJ.js → badge-B-TfGxGB.js} +1 -1
  20. package/src/web/dist/assets/{card-CjhYPqKk.js → card-I07afQF2.js} +1 -1
  21. package/src/web/dist/assets/{gateway-B0gBBN92.js → gateway-CkqHb_VE.js} +1 -1
  22. package/src/web/dist/assets/index-CYeQpt9d.js +61 -0
  23. package/src/web/dist/assets/{input-BnFZKjRM.js → input-DZMeIHxj.js} +1 -1
  24. package/src/web/dist/assets/{label-i5-Lf72z.js → label-DZr7itdg.js} +1 -1
  25. package/src/web/dist/assets/{popover-EFz6sQ7C.js → popover-_LyL4tgU.js} +1 -1
  26. package/src/web/dist/assets/{select-KdDvaKo4.js → select-BUvJR07s.js} +1 -1
  27. package/src/web/dist/assets/{switch-BVWWsjy3.js → switch-BpfcwR9i.js} +1 -1
  28. package/src/web/dist/assets/{useApiQuery-fBWRSgFK.js → useApiQuery-BzbOtl4s.js} +1 -1
  29. package/src/web/dist/assets/useAppMutation-D8Mjcv9t.js +1 -0
  30. package/src/web/dist/index.html +1 -1
  31. package/src/web/dist/assets/About-BCHV3wbt.js +0 -1
  32. package/src/web/dist/assets/ApiKeys-Do48QVpZ.js +0 -1
  33. package/src/web/dist/assets/ModelManagement-CrmNhCAh.js +0 -1
  34. package/src/web/dist/assets/Settings-Q6TBItFQ.js +0 -1
  35. package/src/web/dist/assets/index-BzuBtvAC.js +0 -61
  36. package/src/web/dist/assets/useAppMutation-Cd6HN12q.js +0 -1
@@ -1 +0,0 @@
1
- import{r as N,j as e,a8 as Se,as as pt,at as Ne,q as hs,a1 as xt,aj as fs,al as bs,U as vs}from"./vendor-5iCEqDpV.js";import{u as Le,C as js}from"./useAppMutation-Cd6HN12q.js";import{P as ys}from"./PageHeader-CSF0BWul.js";import{c as oe,B as L,d as Ee,T as Ns,e as ws,f as Ms,g as ks,h as Re,b as Te,u as Cs,t as ot}from"./index-BzuBtvAC.js";import{u as te}from"./i18n-C7VVFIdN.js";import{I as fe}from"./input-BnFZKjRM.js";import{L as J}from"./label-i5-Lf72z.js";import{S as gt,a as ht,b as ft,c as bt,d as me}from"./select-KdDvaKo4.js";import{S as qe}from"./switch-BVWWsjy3.js";import{q as he}from"./queryKeys-BMvyDTQS.js";import{B as H}from"./badge-BvMdmUqJ.js";import{C as Fe,a as Be}from"./card-CjhYPqKk.js";import{D as vt,A as jt,a as yt,b as Nt,c as wt,d as Mt,e as kt}from"./DialogShell-CiIvBp8J.js";import{P as Es,a as Ss,b as Ps}from"./popover-EFz6sQ7C.js";import{u as Ds,a as Rs}from"./query-DxhDvnDC.js";import{g as ye}from"./gateway-B0gBBN92.js";import{u as Ts}from"./useApiQuery-fBWRSgFK.js";import"./router-D8u_RlVh.js";import"./radix-CmyU-WBH.js";function We(){return typeof globalThis.crypto<"u"&&typeof globalThis.crypto.randomUUID=="function"?globalThis.crypto.randomUUID():Math.random().toString(36).slice(2,10)}function Os(){return{_key:We(),id:"",label:""}}const Oe={openai:{baseUrl:"https://api.openai.com/v1"},deepseek:{baseUrl:"https://api.deepseek.com/v1"},huawei:{baseUrl:"https://api.modelarts-maas.com/v1"},kimi:{baseUrl:"https://api.moonshot.cn/v1"},anthropic:{baseUrl:"https://api.anthropic.com/v1"},custom:{}},dt=[{value:"openai",label:"OpenAI"},{value:"deepseek",label:"DeepSeek"},{value:"huawei",label:"Huawei Cloud"},{value:"kimi",label:"Kimi"},{value:"anthropic",label:"Anthropic"},{value:"custom",label:"Custom"}];function lt(s){return s?{id:s.id,label:s.label??s.id,baseUrl:s.baseUrl,apiKey:s.apiKey??"",type:s.type??"custom",defaultModel:s.defaultModel??"",models:(s.models??[]).map(t=>({...t,_key:We()})),authMode:s.authMode??"apiKey"}:{id:"",label:"",baseUrl:"",apiKey:"",type:"custom",defaultModel:"",models:[],authMode:"apiKey"}}function As(s){return{_key:We(),id:s.id,label:s.label}}function Us({open:s,mode:t,provider:c,existingProviderIds:g,onClose:d,onSubmit:x}){const{t:a}=te(),[o,m]=N.useState(()=>lt(c)),[u,h]=N.useState({}),[F,k]=N.useState(!1),[M,C]=N.useState(null),v=N.useRef(null),f=N.useRef(null),b=N.useRef(null),[j,Q]=N.useState(t==="edit");N.useEffect(()=>{s&&(m(lt(c)),h({}),C(null),k(!1),Q(t==="edit"))},[s,c,t]),N.useEffect(()=>{if(!s)return;const i=E=>{E.key==="Escape"&&d()};return window.addEventListener("keydown",i),()=>window.removeEventListener("keydown",i)},[s,d]),N.useEffect(()=>{if(s){if(t==="create"&&b.current){b.current.focus();return}f.current&&f.current.focus()}},[s,t]);const Y=t==="create",ue=N.useMemo(()=>o.models.filter(i=>i.id.trim().length>0),[o.models]),le=N.useMemo(()=>{var i;return((i=dt.find(E=>E.value===o.type))==null?void 0:i.label)??"Custom"},[o.type]),Z=o.label.trim()||o.id.trim()||a("providers.drawer.summary.untitled"),V=N.useMemo(()=>[{label:a("providers.drawer.summary.type"),value:le},{label:a("providers.drawer.summary.auth"),value:o.authMode==="apiKey"?a("providers.drawer.fields.authModeApiKey"):o.authMode==="authToken"?a("providers.drawer.fields.authModeAuthToken"):a("providers.drawer.fields.authModeXAuthToken")},{label:a("providers.drawer.summary.models"),value:ue.length.toLocaleString()}],[ue.length,o.authMode,le,a]),pe=i=>E=>{m(R=>({...R,[i]:E}))},G=i=>{m(E=>{const P=!j||E.label.trim().length===0||E.label===E.id?i:E.label;return{...E,id:i,label:P}})},we=i=>{m(E=>{var de;const P=Oe[i??"custom"]??Oe.custom,B=Object.values(Oe).map(re=>re.baseUrl).filter(re=>!!re),X=!E.baseUrl||B.includes(E.baseUrl),A=t==="create"&&(E.models.length===0||E.models.every(re=>re.id.trim().length===0)),q={...E,type:i,authMode:E.authMode??"apiKey"};return P!=null&&P.baseUrl&&X&&(q.baseUrl=P.baseUrl),P!=null&&P.models&&A&&(q.models=P.models.map(As),q.defaultModel=P.defaultModel??((de=P.models[0])==null?void 0:de.id)??""),q})},be=(i,E)=>{m(R=>{const P=[...R.models];return P[i]={...P[i],...E},{...R,models:P}})},T=(i,E)=>{m(R=>{const P=[...R.models],B=P[i];if(!B)return R;const X=!j||!B.label||B.label===B.id,A={...B,id:E,label:X?E:B.label};P[i]=A;const q=R.defaultModel===B.id?E:R.defaultModel;return{...R,models:P,defaultModel:q}})},I=i=>{m(E=>{if(i<0||i>=E.models.length)return E;const R=E.models.filter((B,X)=>X!==i);let P=E.defaultModel;return R.some(B=>B.id===P)||(P=""),{...E,models:R,defaultModel:P}})},Me=()=>{m(i=>({...i,models:[...i.models,Os()]}))},se=i=>{m(E=>({...E,authMode:i}))},xe=()=>{const i={},E=o.id.trim(),R=o.baseUrl.trim();if(t==="create"&&(E.length===0?i.id=a("providers.drawer.errors.idRequired"):g.includes(E)&&(i.id=a("providers.drawer.errors.idDuplicate"))),t==="edit"&&E.length===0&&(i.id=a("providers.drawer.errors.idRequired")),R.length===0)i.baseUrl=a("providers.drawer.errors.baseUrlInvalid");else try{new URL(R)}catch{i.baseUrl=a("providers.drawer.errors.baseUrlInvalid")}if(o.models.length>0){const P=new Set;o.models.some(X=>{const A=X.id.trim();return A.length===0||P.has(A)?!0:(P.add(A),!1)})&&(i.models=a("providers.drawer.errors.modelInvalid"))}return o.defaultModel&&!o.models.some(P=>P.id===o.defaultModel)&&(i.models=a("providers.drawer.errors.defaultInvalid")),h(i),Object.keys(i).length===0},ie=()=>{const i=o.models.map(P=>{var B;return{id:P.id.trim(),label:(B=P.label)!=null&&B.trim()?P.label.trim():void 0}}).filter(P=>P.id.length>0),E=c!=null&&c.extraHeaders&&Object.keys(c.extraHeaders).length>0?c.extraHeaders:void 0,R=o.authMode!=="apiKey"?o.authMode:void 0;return{id:o.id.trim(),label:o.label.trim()||o.id.trim(),baseUrl:o.baseUrl.trim(),apiKey:o.apiKey.trim()||void 0,type:o.type??"custom",defaultModel:o.defaultModel||void 0,models:i.length>0?i:void 0,extraHeaders:E,authMode:R}},ge=async()=>{if(C(null),!!xe()){k(!0);try{const i=ie();await x(i)}catch(i){C(a("providers.drawer.toast.saveFailure",{message:i instanceof Error?i.message:"unknown"})),k(!1);return}k(!1),d()}};return s?e.jsxs("div",{className:"fixed inset-0 z-50 flex",children:[e.jsx("div",{className:"flex-1 bg-background/80 backdrop-blur-sm",onClick:d,"aria-hidden":"true"}),e.jsxs("aside",{ref:v,role:"dialog","aria-modal":"true","aria-labelledby":"provider-drawer-title","aria-describedby":"provider-drawer-desc",className:"flex h-full w-full max-w-5xl flex-col border-l border-border bg-background shadow-lg",children:[e.jsxs("header",{className:"border-b border-border bg-secondary px-6 py-5",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"inline-flex rounded-full border border-primary/20 bg-primary/10 px-3 py-1 text-[11px] font-medium uppercase tracking-[0.18em] text-primary",children:a(Y?"providers.drawer.quickStart":"providers.drawer.editTitle")}),e.jsxs("div",{children:[e.jsx("h2",{id:"provider-drawer-title",className:"text-lg font-semibold tracking-[-0.02em]",children:a(Y?"providers.drawer.createTitle":"providers.drawer.editTitle")}),e.jsx("p",{id:"provider-drawer-desc",className:"text-sm text-muted-foreground",children:a("providers.drawer.description")})]})]}),e.jsx("button",{type:"button",ref:f,onClick:d,className:"rounded-full border border-border bg-card px-4 py-2 text-sm transition hover:border-primary/20 hover:bg-accent/50",children:a("common.actions.close")})]}),e.jsx("div",{className:"mt-4 grid gap-3 md:grid-cols-3",children:V.map(i=>e.jsxs("div",{className:"rounded-lg border border-border bg-card px-4 py-3",children:[e.jsx("p",{className:"text-[11px] font-medium uppercase tracking-[0.16em] text-muted-foreground",children:i.label}),e.jsx("p",{className:"mt-2 text-sm font-semibold text-foreground",children:i.value})]},i.label))})]}),e.jsxs("div",{className:"grid flex-1 overflow-hidden xl:grid-cols-[minmax(0,1fr)_280px]",children:[e.jsxs("div",{className:"overflow-y-auto px-6 py-5",children:[e.jsxs("section",{className:"space-y-5","aria-labelledby":"provider-type-fields",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("h3",{id:"provider-type-fields",className:"text-sm font-semibold",children:a("providers.drawer.sections.type")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a("providers.drawer.hints.type")})]}),e.jsx("div",{className:"grid gap-2 md:grid-cols-3",children:dt.map(i=>{var R;const E=i.value===o.type;return e.jsxs("button",{type:"button",onClick:()=>we(i.value),className:oe("rounded-2xl border px-4 py-3 text-left transition",E?"border-primary bg-primary/10 text-primary shadow-sm":"border-border bg-card text-foreground hover:border-primary/20 hover:bg-accent/50"),children:[e.jsx("div",{className:"text-sm font-semibold",children:i.label}),e.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:((R=Oe[i.value??"custom"])==null?void 0:R.baseUrl)??a("providers.drawer.hints.customProvider")})]},i.value??"custom")})})]}),e.jsxs("section",{className:"mt-8 space-y-4","aria-labelledby":"provider-basic-info",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("h3",{id:"provider-basic-info",className:"text-sm font-semibold",children:a("providers.drawer.sections.basic")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a("providers.drawer.hints.basic")})]}),e.jsx("button",{type:"button",onClick:()=>Q(i=>!i),className:"rounded-full border border-border bg-card px-3 py-1.5 text-xs transition hover:border-primary/20 hover:bg-accent/50",children:a(j?"providers.drawer.fields.hideAdvanced":"providers.drawer.fields.showAdvanced")})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs("label",{className:"flex flex-col gap-2 text-sm",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:a("providers.drawer.fields.id")}),e.jsx("input",{value:o.id,ref:b,onChange:i=>G(i.target.value),disabled:!Y,placeholder:a("providers.drawer.fields.idPlaceholder"),className:"h-10 rounded-md border border-input bg-background px-3 py-2 text-sm transition-all focus:border-primary/40 focus:outline-none focus:ring-2 focus:ring-ring disabled:bg-muted/60 disabled:text-muted-foreground","aria-invalid":!!u.id}),u.id?e.jsx("span",{className:"text-xs text-red-500",children:u.id}):null]}),e.jsxs("label",{className:"flex flex-col gap-2 text-sm",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:a("providers.drawer.fields.label")}),e.jsx("input",{value:o.label,onChange:i=>pe("label")(i.target.value),placeholder:a("providers.drawer.fields.labelPlaceholder"),className:"h-10 rounded-md border border-input bg-background px-3 py-2 text-sm transition-all focus:border-primary/40 focus:outline-none focus:ring-2 focus:ring-ring disabled:bg-muted/60 disabled:text-muted-foreground"})]})]}),e.jsxs("label",{className:"flex flex-col gap-2 text-sm",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:a("providers.drawer.fields.baseUrl")}),e.jsx("input",{value:o.baseUrl,onChange:i=>pe("baseUrl")(i.target.value),placeholder:a("providers.drawer.fields.baseUrlPlaceholder"),className:"h-10 rounded-md border border-input bg-background px-3 py-2 text-sm transition-all focus:border-primary/40 focus:outline-none focus:ring-2 focus:ring-ring disabled:bg-muted/60 disabled:text-muted-foreground","aria-invalid":!!u.baseUrl}),u.baseUrl?e.jsx("span",{className:"text-xs text-red-500",children:u.baseUrl}):null]})]}),e.jsxs("section",{className:"mt-8 space-y-4","aria-labelledby":"provider-auth-fields",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("h3",{id:"provider-auth-fields",className:"text-sm font-semibold",children:a("providers.drawer.sections.auth")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a("providers.drawer.hints.auth")})]}),e.jsxs("label",{className:"flex flex-col gap-2 text-sm",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:a("providers.drawer.fields.apiKey")}),e.jsx("input",{value:o.apiKey,onChange:i=>pe("apiKey")(i.target.value),placeholder:a("providers.drawer.fields.apiKeyPlaceholder"),className:"h-10 rounded-md border border-input bg-background px-3 py-2 text-sm transition-all focus:border-primary/40 focus:outline-none focus:ring-2 focus:ring-ring disabled:bg-muted/60 disabled:text-muted-foreground"})]}),e.jsxs("fieldset",{className:"grid gap-2 rounded-lg border border-border bg-card p-4 text-xs",children:[e.jsx("legend",{className:"px-1 text-muted-foreground",children:a("providers.drawer.fields.authMode")}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:a("providers.drawer.fields.authModeHint")}),e.jsxs("label",{className:"flex cursor-pointer items-start gap-3 rounded-xl border border-transparent px-3 py-2 transition hover:bg-primary/5",children:[e.jsx("input",{type:"radio",name:"provider-auth-mode",value:"apiKey",checked:o.authMode==="apiKey",onChange:()=>se("apiKey"),className:"mt-0.5"}),e.jsx("span",{children:a("providers.drawer.fields.authModeApiKey")})]}),e.jsxs("label",{className:"flex cursor-pointer items-start gap-3 rounded-xl border border-transparent px-3 py-2 transition hover:bg-primary/5",children:[e.jsx("input",{type:"radio",name:"provider-auth-mode",value:"authToken",checked:o.authMode==="authToken",onChange:()=>se("authToken"),className:"mt-0.5"}),e.jsx("span",{children:a("providers.drawer.fields.authModeAuthToken")})]}),e.jsxs("label",{className:"flex cursor-pointer items-start gap-3 rounded-xl border border-transparent px-3 py-2 transition hover:bg-primary/5",children:[e.jsx("input",{type:"radio",name:"provider-auth-mode",value:"xAuthToken",checked:o.authMode==="xAuthToken",onChange:()=>se("xAuthToken"),className:"mt-0.5"}),e.jsx("span",{children:a("providers.drawer.fields.authModeXAuthToken")})]})]})]}),e.jsxs("section",{className:"mt-8 space-y-4","aria-labelledby":"provider-model-fields",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("h3",{id:"provider-model-fields",className:"text-sm font-semibold",children:a("providers.drawer.fields.models")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a("providers.drawer.modelsDescription")})]}),e.jsx("button",{type:"button",onClick:Me,className:"rounded-full border border-border bg-card px-3 py-1.5 text-xs transition hover:border-primary/20 hover:bg-accent/50",children:a("providers.drawer.fields.addModel")})]}),u.models?e.jsx("p",{className:"text-xs text-red-500",children:u.models}):null,e.jsxs("div",{className:"space-y-4",children:[o.models.map((i,E)=>e.jsxs("div",{className:"rounded-lg border border-border bg-card p-4",children:[e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs("label",{className:"flex flex-col gap-2 text-sm",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:a("providers.drawer.fields.modelId")}),e.jsx("input",{value:i.id,onChange:R=>T(E,R.target.value),placeholder:a("providers.drawer.fields.modelIdPlaceholder"),className:"h-10 rounded-md border border-input bg-background px-3 py-2 text-sm transition-all focus:border-primary/40 focus:outline-none focus:ring-2 focus:ring-ring disabled:bg-muted/60 disabled:text-muted-foreground"})]}),j?e.jsxs("label",{className:"flex flex-col gap-2 text-sm",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:a("providers.drawer.fields.modelLabel")}),e.jsx("input",{value:i.label??"",onChange:R=>be(E,{label:R.target.value}),placeholder:a("providers.drawer.fields.modelLabelPlaceholder"),className:"h-10 rounded-md border border-input bg-background px-3 py-2 text-sm transition-all focus:border-primary/40 focus:outline-none focus:ring-2 focus:ring-ring disabled:bg-muted/60 disabled:text-muted-foreground"})]}):null]}),e.jsxs("div",{className:"mt-3 flex flex-wrap items-center justify-between gap-3 text-xs",children:[e.jsxs("label",{className:"flex items-center gap-2 text-muted-foreground",children:[e.jsx("input",{type:"radio",name:"defaultModel",value:i.id,checked:o.defaultModel===i.id,onChange:()=>m(R=>({...R,defaultModel:i.id})),disabled:i.id.trim().length===0}),a("providers.drawer.fields.setDefault")]}),e.jsx("button",{type:"button",className:"text-red-500 transition hover:text-red-600 disabled:cursor-not-allowed disabled:opacity-40",onClick:()=>I(E),disabled:o.models.length===0,children:a("providers.drawer.fields.removeModel")})]})]},i._key)),o.models.length===0?e.jsx("div",{className:"rounded-lg border border-amber-200 bg-amber-50/60 p-5 dark:border-amber-700/50 dark:bg-amber-900/20",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm font-semibold text-amber-900 dark:text-amber-200",children:a("providers.drawer.noModelsTitle")}),e.jsx("p",{className:"text-xs leading-relaxed text-amber-800 dark:text-amber-300",children:a("providers.drawer.noModelsHint",{providerId:o.id||"provider-id"})}),e.jsxs("div",{className:"rounded-md border border-border bg-secondary p-2.5",children:[e.jsx("p",{className:"mb-1.5 text-xs font-medium text-foreground",children:a("providers.drawer.routeExample")}),e.jsxs("code",{className:"block rounded-md border border-border bg-card px-2.5 py-1.5 font-mono text-xs text-foreground",children:['"claude-*": "',(o.id||"provider-id").trim()||"provider-id",':*"']})]})]})}):null]}),ue.length>1?e.jsx("div",{className:"text-xs text-muted-foreground",children:a("providers.drawer.defaultHint",{model:o.defaultModel||a("providers.card.noDefault")})}):null]})]}),e.jsx("aside",{className:"hidden border-l border-border bg-secondary px-5 py-5 xl:block",children:e.jsxs("div",{className:"sticky top-0 space-y-5",children:[e.jsxs("div",{className:"rounded-lg border border-border bg-card p-4",children:[e.jsx("p",{className:"text-[11px] font-medium uppercase tracking-[0.16em] text-muted-foreground",children:a("providers.drawer.formSummary")}),e.jsx("p",{className:"mt-2 text-base font-semibold",children:Z}),e.jsx("div",{className:"mt-4 space-y-3 text-sm",children:V.map(i=>e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsx("span",{className:"text-muted-foreground",children:i.label}),e.jsx("span",{className:"text-right font-medium",children:i.value})]},i.label))})]}),e.jsxs("div",{className:"rounded-lg border border-border bg-card p-4",children:[e.jsx("p",{className:"text-[11px] font-medium uppercase tracking-[0.16em] text-muted-foreground",children:a("providers.drawer.sections.checklist")}),e.jsxs("ul",{className:"mt-3 space-y-2 text-sm text-muted-foreground",children:[e.jsx("li",{children:a("providers.drawer.hints.checkUrl")}),e.jsx("li",{children:a("providers.drawer.hints.checkAuth")}),e.jsx("li",{children:a("providers.drawer.hints.checkModels")})]})]}),j&&e.jsxs("div",{className:"rounded-lg border border-primary/20 bg-accent p-4 text-sm text-foreground",children:[e.jsx("p",{className:"font-medium text-primary",children:a("providers.drawer.hints.advancedTitle")}),e.jsx("p",{className:"mt-2 text-xs text-muted-foreground",children:a("providers.drawer.hints.advancedBody")})]})]})})]}),e.jsxs("footer",{className:"flex items-center justify-between gap-3 border-t border-border bg-secondary px-6 py-4 text-sm",children:[e.jsx("div",{className:"flex flex-col text-xs text-red-500","aria-live":"polite",children:M?e.jsx("span",{children:M}):null}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{type:"button",onClick:d,className:"rounded-full border border-border bg-card px-4 py-2 transition hover:border-primary/20 hover:bg-accent/50",disabled:F,children:a("common.actions.cancel")}),e.jsx("button",{type:"button",onClick:ge,className:"rounded-full bg-primary px-5 py-2 text-primary-foreground shadow-[0_8px_20px_-12px_rgba(59,130,246,0.65)] transition hover:-translate-y-0.5 hover:bg-primary/95 disabled:opacity-60",disabled:F,children:a(F?"common.actions.saving":"common.actions.save")})]})]})]})]}):null}const $s=["anthropic","openai-auto","openai-chat","openai-responses"];function Ls({open:s,endpoint:t,onClose:c,onSuccess:g}){const{t:d}=te(),[x,a]=N.useState({id:"",label:"",paths:[{path:"",protocol:"openai-auto"}],enabled:!0});N.useEffect(()=>{if(t){const v=t.paths&&t.paths.length>0?t.paths:t.path&&t.protocol?[{path:t.path,protocol:t.protocol}]:[{path:"",protocol:"openai-auto"}];a({id:t.id,label:t.label,paths:v,enabled:t.enabled!==!1});return}a({id:"",label:"",paths:[{path:"",protocol:"openai-auto"}],enabled:!0})},[t,s]);const o=Le({mutationFn:Ee.create,invalidateKeys:[he.customEndpoints.all()],successToast:()=>({title:d("modelManagement.createEndpointSuccess")}),errorToast:v=>({title:d("modelManagement.createEndpointError",{error:v.message})}),onSuccess:async()=>{g(),c()}}),m=Le({mutationFn:v=>Ee.update(v.id,v.updates),invalidateKeys:[he.customEndpoints.all()],successToast:()=>({title:d("modelManagement.updateEndpointSuccess")}),errorToast:v=>({title:d("modelManagement.updateEndpointError",{error:v.message})}),onSuccess:async()=>{g(),c()}}),u=()=>{a(v=>({...v,paths:[...v.paths,{path:"",protocol:"anthropic"}]}))},h=v=>{x.paths.length!==1&&a(f=>({...f,paths:f.paths.filter((b,j)=>j!==v)}))},F=(v,f,b)=>{a(j=>{const Q=[...j.paths];return Q[v]={...Q[v],[f]:b},{...j,paths:Q}})},k=v=>{if(v==null||v.preventDefault(),!x.id.trim()||!x.label.trim())return;for(const b of x.paths)if(!b.path.trim())return;const f=x.paths.map(b=>({path:b.path.trim(),protocol:b.protocol}));if(t){m.mutate({id:t.id,updates:{label:x.label.trim(),paths:f,enabled:x.enabled}});return}o.mutate({id:x.id.trim(),label:x.label.trim(),paths:f,enabled:x.enabled})},M=o.isPending||m.isPending,C=x.paths.length===0?d("modelManagement.atLeastOnePath"):!x.id.trim()||!x.label.trim()?d("modelManagement.endpointValidationError"):x.paths.some(v=>!v.path.trim())?d("modelManagement.pathValidationError"):null;return s?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-40 bg-background/80 backdrop-blur-sm",onClick:c}),e.jsx("div",{className:"fixed inset-y-0 right-0 z-50 w-full max-w-md border-l border-border bg-background shadow-lg",children:e.jsxs("div",{className:"flex h-full flex-col",children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-border bg-secondary p-6",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("h2",{className:"text-lg font-semibold tracking-[-0.02em]",children:d(t?"modelManagement.editEndpoint":"modelManagement.createEndpoint")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t?t.id:d("modelManagement.endpointRoutingHint")})]}),e.jsx(L,{variant:"ghost",size:"sm",onClick:c,children:e.jsx(Se,{className:"h-4 w-4"})})]}),e.jsxs("form",{onSubmit:k,className:"flex-1 space-y-6 overflow-y-auto p-6",children:[e.jsxs("div",{className:"grid gap-3 rounded-lg border border-border bg-secondary p-4 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-[0.16em] text-muted-foreground",children:d("modelManagement.endpointId")}),e.jsx("p",{className:"truncate text-sm font-medium text-foreground",children:(t==null?void 0:t.id)||"new-endpoint"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-[0.16em] text-muted-foreground",children:d("modelManagement.endpointEnabled")}),e.jsx("p",{className:"text-sm font-medium text-foreground",children:x.enabled?d("common.status.enabled"):d("common.status.disabled")})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(J,{children:[d("modelManagement.endpointId")," ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(fe,{value:x.id,onChange:v=>a(f=>({...f,id:v.target.value})),placeholder:d("modelManagement.endpointIdPlaceholder"),disabled:!!t,required:!0}),e.jsx("p",{className:"text-xs text-muted-foreground",children:d("modelManagement.endpointIdHint")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(J,{children:[d("modelManagement.endpointLabel")," ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(fe,{value:x.label,onChange:v=>a(f=>({...f,label:v.target.value})),placeholder:d("modelManagement.endpointLabelPlaceholder"),required:!0})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(J,{children:[d("modelManagement.endpointPaths")," ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsxs(L,{type:"button",variant:"ghost",size:"sm",onClick:u,children:[e.jsx(pt,{className:"mr-1 h-3 w-3"}),d("modelManagement.addPath")]})]}),e.jsx("div",{className:"space-y-3",children:x.paths.map((v,f)=>e.jsxs("div",{className:"space-y-2 rounded-lg border border-border bg-card p-3",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsx(fe,{value:v.path,onChange:b=>F(f,"path",b.target.value),placeholder:d("modelManagement.endpointPathPlaceholder"),required:!0}),e.jsxs(gt,{value:v.protocol,onValueChange:b=>F(f,"protocol",b),children:[e.jsx(ht,{children:e.jsx(ft,{})}),e.jsx(bt,{children:$s.map(b=>e.jsx(me,{value:b,children:d(b==="anthropic"?"modelManagement.protocolAnthropic":b==="openai-auto"?"modelManagement.protocolOpenAI":b==="openai-chat"?"modelManagement.protocolOpenAIChat":"modelManagement.protocolOpenAIResponses")},b))})]})]}),x.paths.length>1?e.jsx(L,{type:"button",variant:"ghost",size:"sm",onClick:()=>h(f),className:"text-destructive",children:e.jsx(Se,{className:"h-4 w-4"})}):null]}),e.jsxs("div",{className:"space-y-1 text-xs text-muted-foreground",children:[f===0?e.jsx("p",{children:d("modelManagement.endpointPathHint")}):null,e.jsx("p",{children:d(`modelManagement.protocolHints.${v.protocol}`)})]})]},`${v.protocol}-${f}`))}),C?e.jsx("p",{className:"text-xs text-destructive",children:C}):null]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(qe,{id:"enabled",checked:x.enabled,onCheckedChange:v=>a(f=>({...f,enabled:v}))}),e.jsx(J,{htmlFor:"enabled",children:d("modelManagement.endpointEnabled")})]}),t?null:e.jsx("div",{className:"rounded-lg border border-primary/20 bg-accent p-4",children:e.jsx("p",{className:"text-sm text-blue-800 dark:text-blue-200",children:d("modelManagement.endpointRoutingHint")})})]}),e.jsxs("div",{className:"flex gap-3 border-t border-border bg-secondary p-6",children:[e.jsx(L,{variant:"outline",className:"flex-1",onClick:c,disabled:M,children:d("common.cancel")}),e.jsx(L,{className:"flex-1",onClick:()=>k(),disabled:M,children:d(M?"common.saving":t?"common.save":"common.create")})]})]})})]}):null}function Ke(s,t){return t(s==="anthropic"?"modelManagement.protocolAnthropic":s==="openai-chat"?"modelManagement.protocolOpenAIChat":s==="openai-responses"?"modelManagement.protocolOpenAIResponses":"modelManagement.protocolOpenAI")}function Fs({activeTab:s,activeTabInfo:t,customEndpoints:c,customTabs:g,isDirtyByEndpoint:d,onDeleteEndpoint:x,onEditEndpoint:a,onSelectTab:o,providerCount:m,systemTabs:u}){const{t:h}=te(),F=Object.values(d).filter(Boolean).length,k=u.length-1+g.length;return e.jsx(Fe,{className:"overflow-hidden",children:e.jsxs(Be,{className:"space-y-5 pt-5",children:[e.jsxs("div",{className:"flex flex-col gap-3 lg:flex-row lg:items-end lg:justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs(H,{variant:"outline",className:"border-primary/20 bg-accent text-primary",children:[h("modelManagement.tabs.providers")," · ",m]}),e.jsxs(H,{variant:"outline",children:[h("modelManagement.tabs.customEndpoint")," · ",g.length]}),F>0?e.jsx(H,{variant:"warning",children:h("modelManagement.overview.unsavedCount",{count:F})}):e.jsx(H,{variant:"success",children:h("modelManagement.overview.synced")})]}),e.jsx("p",{className:"text-sm font-semibold text-foreground",children:t==null?void 0:t.label}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t==null?void 0:t.description})]}),e.jsxs("div",{className:"flex w-full flex-col gap-3 sm:w-auto sm:flex-row sm:flex-wrap sm:items-center",children:[e.jsx("div",{className:"rounded-lg border border-border bg-secondary px-3 py-2 text-xs text-muted-foreground",children:g.length>0?h("modelManagement.overview.headerWithCustom"):h("modelManagement.overview.headerWithoutCustom")}),e.jsxs("div",{className:"rounded-lg border border-primary/20 bg-accent px-3 py-2 text-xs font-medium text-primary",children:[h("modelManagement.overview.routeWorkspacesStat")," · ",k]})]})]}),e.jsxs("div",{className:"grid gap-3 md:grid-cols-4",children:[e.jsx(Ae,{label:h("modelManagement.overview.providersStat"),value:m.toString(),helper:h("modelManagement.overview.providersStatHint")}),e.jsx(Ae,{label:h("modelManagement.overview.routeWorkspacesStat"),value:k.toString(),helper:h("modelManagement.overview.routeWorkspacesStatHint")}),e.jsx(Ae,{label:h("modelManagement.overview.customEndpointsStat"),value:g.length.toString(),helper:h("modelManagement.overview.customEndpointsStatHint")}),e.jsx(Ae,{label:h("modelManagement.overview.activeWorkspace"),value:(t==null?void 0:t.label)??"-",helper:h(s==="providers"?"modelManagement.overview.activeWorkspaceProvider":"modelManagement.overview.activeWorkspaceRouting")})]}),e.jsxs("div",{className:"grid gap-3 rounded-lg border border-border bg-secondary p-4 md:grid-cols-2",children:[e.jsx(it,{title:h("modelManagement.overview.resourceCardTitle"),description:h("modelManagement.overview.resourceCardDescription")}),e.jsx(it,{title:h("modelManagement.overview.entryCardTitle"),description:h("modelManagement.overview.entryCardDescription")})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsx("p",{className:"text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:h("modelManagement.overview.providerAndSystem")})}),e.jsx("div",{className:"grid gap-3 md:grid-cols-3",children:u.map(M=>{const C=s===M.key,v=M.key!=="providers"&&d[M.key];return e.jsxs("button",{type:"button",onClick:()=>o(M.key),className:oe("group flex min-h-[96px] flex-col justify-between rounded-lg border px-4 py-4 text-left transition-all",C?"border-primary/30 bg-accent":"border-border bg-card hover:border-primary/20 hover:bg-accent/50"),children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx("span",{className:oe("text-base font-semibold",C?"text-primary":"text-foreground"),children:M.label}),e.jsx("div",{className:"text-[11px] uppercase tracking-wider text-muted-foreground",children:M.key==="providers"?h("modelManagement.overview.providerPoolTag"):h("modelManagement.overview.systemEndpointTag")})]}),v?e.jsx("span",{className:"mt-1 h-2.5 w-2.5 rounded-full bg-amber-500"}):null]}),e.jsx("span",{className:"line-clamp-2 text-sm text-muted-foreground",children:M.description})]},M.key)})})]}),g.length>0?e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"flex items-center justify-between gap-3",children:e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:h("modelManagement.overview.customEndpoints")}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:h("modelManagement.overview.customEndpointsHint")})]})}),e.jsx("div",{className:"overflow-x-auto pb-1",children:e.jsx("div",{className:"flex min-w-full snap-x gap-3",children:g.map(M=>{var b;const C=s===M.key,v=d[M.key],f=c.find(j=>j.id===M.key);return e.jsxs("div",{className:oe("group relative flex w-[260px] shrink-0 snap-start flex-col gap-3 rounded-lg border px-4 py-4 text-left transition-all",C?"border-primary/30 bg-accent":"border-border bg-card hover:border-primary/20 hover:bg-accent/50"),children:[e.jsxs("button",{type:"button",onClick:()=>o(M.key),className:"min-w-0 flex-1 text-left",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:oe("truncate text-base font-semibold",C?"text-primary":"text-foreground"),children:M.label}),v?e.jsx("span",{className:"h-2 w-2 rounded-full bg-amber-500"}):null]}),e.jsx("p",{className:"mt-1 line-clamp-2 text-sm text-muted-foreground",children:M.description})]}),e.jsxs("div",{className:"grid gap-2 sm:flex sm:items-start",children:[e.jsx(L,{variant:"ghost",size:"sm",className:"h-7 w-full px-2 text-xs sm:w-auto",disabled:!f,onClick:()=>{f&&a(f)},children:h("common.edit")}),M.canDelete?e.jsx("button",{type:"button",onClick:j=>{j.stopPropagation(),f&&x({kind:"endpoint",endpoint:f})},className:"flex h-7 w-full items-center justify-center rounded-full border border-transparent text-muted-foreground transition hover:border-destructive/20 hover:bg-destructive/10 hover:text-destructive sm:w-7",title:h("common.delete"),children:e.jsx(Se,{className:"h-3.5 w-3.5"})}):null]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[(M.protocols??[]).map(j=>e.jsx(H,{variant:"outline",className:"max-w-full truncate text-[11px]",children:Ke(j,h)},`${M.key}-${j}`)),e.jsx(H,{variant:(f==null?void 0:f.enabled)===!1?"secondary":"success",className:"text-[11px]",children:(f==null?void 0:f.enabled)===!1?h("modelManagement.overview.endpointDisabled"):h("modelManagement.overview.endpointEnabled")})]}),f!=null&&f.paths&&f.paths.length>0?e.jsxs("div",{className:"space-y-1 rounded-lg border border-border bg-secondary px-3 py-2 text-[11px] text-muted-foreground",children:[f.paths.slice(0,2).map(j=>e.jsxs("div",{className:"truncate",children:[e.jsx("span",{className:"font-medium text-foreground",children:j.path})," · ",Ke(j.protocol,h)]},`${f.id}-${j.path}-${j.protocol}`)),f.paths.length>2?e.jsx("div",{children:h("modelManagement.overview.endpointMorePaths",{count:f.paths.length-2})}):null]}):f!=null&&f.path?e.jsxs("div",{className:"rounded-lg border border-border bg-secondary px-3 py-2 text-[11px] text-muted-foreground",children:[e.jsx("span",{className:"font-medium text-foreground",children:f.path})," · ",Ke(f.protocol??"anthropic",h)]}):null,e.jsx("div",{className:"rounded-lg border border-border bg-secondary px-3 py-2 text-[11px] text-muted-foreground",children:(b=M.protocols)!=null&&b.length?h("modelManagement.overview.endpointProtocols",{count:M.protocols.length}):h("modelManagement.overview.endpointNoProtocol")}),M.canDelete?null:e.jsx("div",{className:"text-[11px] text-muted-foreground",children:h("modelManagement.overview.endpointManagedExternally")})]},M.key)})})})]}):null]})})}function it({description:s,title:t}){return e.jsxs("div",{className:"rounded-lg border border-border bg-card px-4 py-3",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-wider text-muted-foreground",children:t}),e.jsx("p",{className:"mt-2 text-sm leading-6 text-foreground",children:s})]})}function Ae({helper:s,label:t,value:c}){return e.jsxs("div",{className:"rounded-lg border border-border bg-card px-4 py-3",children:[e.jsx("p",{className:"text-[11px] font-medium uppercase tracking-wider text-muted-foreground",children:t}),e.jsx("p",{className:"mt-2 truncate text-base font-semibold text-foreground",children:c}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:s})]})}function Bs({dialog:s,currentRoutes:t,onConfirm:c,onClose:g}){const{t:d}=te();if(!s)return null;const{endpoint:x,preset:a}=s,o=a.modelRoutes??{},m={};for(const C of t){const v=C.source.trim(),f=C.target.trim();v&&f&&(m[v]=f)}const u=new Set([...Object.keys(m),...Object.keys(o)]),h=[],F=[],k=[];for(const C of u){const v=C in m,f=C in o;f&&!v?h.push([C,o[C]]):v&&!f?F.push([C,m[C]]):v&&f&&m[C]!==o[C]&&k.push([C,m[C],o[C]])}const M=h.length>0||F.length>0||k.length>0;return e.jsx(vt,{open:!0,onOpenChange:C=>!C&&g(),children:e.jsxs(jt,{className:"max-w-2xl",children:[e.jsxs(yt,{children:[e.jsx(Nt,{children:d("modelManagement.presets.diffTitle")}),e.jsx(wt,{children:d("modelManagement.presets.diffDescription",{name:a.name})})]}),e.jsx(Mt,{children:M?e.jsxs("div",{className:"max-h-80 space-y-2 rounded-lg border border-border bg-secondary p-3 text-sm",children:[h.map(([C,v])=>e.jsxs("div",{className:"flex items-center gap-2 rounded-xl bg-emerald-50 px-2 py-1.5 text-emerald-800 dark:bg-emerald-950 dark:text-emerald-200",children:[e.jsx(H,{variant:"outline",className:"border-emerald-300 text-xs dark:border-emerald-700",children:d("modelManagement.presets.diffAdded")}),e.jsx("span",{className:"truncate",children:C}),e.jsx(Ne,{className:"h-3 w-3 flex-shrink-0"}),e.jsx("span",{className:"truncate",children:v})]},`add-${C}`)),F.map(([C,v])=>e.jsxs("div",{className:"flex items-center gap-2 rounded-xl bg-red-50 px-2 py-1.5 text-red-800 dark:bg-red-950 dark:text-red-200",children:[e.jsx(H,{variant:"outline",className:"border-red-300 text-xs dark:border-red-700",children:d("modelManagement.presets.diffRemoved")}),e.jsx("span",{className:"truncate",children:C}),e.jsx(Ne,{className:"h-3 w-3 flex-shrink-0"}),e.jsx("span",{className:"truncate",children:v})]},`rm-${C}`)),k.map(([C,v,f])=>e.jsxs("div",{className:"flex items-center gap-2 rounded-xl bg-amber-50 px-2 py-1.5 text-amber-800 dark:bg-amber-950 dark:text-amber-200",children:[e.jsx(H,{variant:"outline",className:"border-amber-300 text-xs dark:border-amber-700",children:d("modelManagement.presets.diffChanged")}),e.jsx("span",{className:"truncate",children:C}),e.jsx(Ne,{className:"h-3 w-3 flex-shrink-0"}),e.jsx("span",{className:"truncate line-through opacity-60",children:v}),e.jsx(Ne,{className:"h-3 w-3 flex-shrink-0"}),e.jsx("span",{className:"truncate",children:f})]},`chg-${C}`))]}):e.jsx("p",{className:"rounded-lg border border-border bg-secondary py-8 text-center text-sm text-muted-foreground",children:d("modelManagement.presets.diffEmpty")})}),e.jsxs(kt,{children:[e.jsx(L,{variant:"outline",onClick:g,children:d("common.cancel")}),e.jsx(L,{onClick:()=>c(x,a),disabled:!M,children:d("modelManagement.presets.diffConfirm")})]})]})})}function Ct({eyebrow:s,title:t,description:c,breadcrumb:g,aside:d}){return e.jsxs("div",{className:"flex flex-col gap-4 lg:flex-row lg:items-start lg:justify-between",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-[11px] font-semibold uppercase tracking-[0.18em] text-muted-foreground",children:[e.jsx("span",{children:s}),g.map((x,a)=>e.jsxs(hs.Fragment,{children:[a>0?e.jsx(xt,{className:"h-3.5 w-3.5"}):null,e.jsx("span",{className:oe(a===g.length-1&&"text-foreground"),children:x})]},`${x}-${a}`))]}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-semibold tracking-[-0.03em] text-foreground",children:t}),e.jsx("p",{className:"mt-1 max-w-3xl text-sm text-muted-foreground",children:c})]})]}),d?e.jsx("div",{className:"w-full shrink-0 lg:w-auto",children:d}):null]})}const Hs=["claude-sonnet-4-5-20250929","claude-sonnet-4-5-20250929-thinking","claude-sonnet-4-20250514","claude-opus-4-1-20250805","claude-opus-4-1-20250805-thinking","claude-haiku-4-5-20251001","claude-haiku-4-5-20251001-thinking","claude-3-5-haiku-20241022"],Is=["gpt-4o-mini","gpt-4o","o4-mini","o4-large","gpt-5-codex"];function ne(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():Math.random().toString(36).slice(2,10)}function Qe(s,t){var c;return(c=s==null?void 0:s.customEndpoints)!=null&&c.length?s.customEndpoints:t}function ze(s){return s?Object.entries(s).map(([t,c])=>({id:ne(),source:t,target:c})):[]}function Ve(s,t){var d,x,a;if(!s)return{};const c={},g=s.endpointRouting??{};c.anthropic=ze(((d=g.anthropic)==null?void 0:d.modelRoutes)??s.modelRoutes??{}),c.openai=ze(((x=g.openai)==null?void 0:x.modelRoutes)??{});for(const o of Qe(s,t))(a=o.routing)!=null&&a.modelRoutes?c[o.id]=ze(o.routing.modelRoutes):c[o.id]=[];return c}function ct(s,t,c){var x,a,o;const g=Qe(s,t).find(m=>m.id===c);if(g)return((x=g.routing)==null?void 0:x.modelRoutes)??{};const d=s.endpointRouting??{};return c==="anthropic"?((a=d.anthropic)==null?void 0:a.modelRoutes)??s.modelRoutes??{}:c==="openai"?((o=d.openai)==null?void 0:o.modelRoutes)??{}:{}}function Ks(s){const t={};for(const c of s){const g=c.source.trim(),d=c.target.trim();g&&d&&(t[g]=d)}return t}function mt(s,t){return JSON.stringify(Ks(s))!==JSON.stringify(t)}function zs(s,t){if(s==="anthropic")return!0;const c=t.find(g=>g.id===s);return c?c.paths&&c.paths.length>0?c.paths.some(g=>g.protocol==="anthropic"):c.protocol==="anthropic":!1}function Vs(s,t,c){var d,x,a;if(!t)return;if(s==="anthropic"||s==="openai")return(x=(d=t.endpointRouting)==null?void 0:d[s])==null?void 0:x.validation;const g=Qe(t,c).find(o=>o.id===s);return(a=g==null?void 0:g.routing)==null?void 0:a.validation}function _s(s,t){const c=[{key:"providers",label:s("modelManagement.tabs.providers"),description:s("modelManagement.tabs.providersDesc"),isSystem:!0,canDelete:!1},{key:"anthropic",label:s("modelManagement.tabs.anthropic"),description:s("modelManagement.tabs.anthropicDesc"),isSystem:!0,canDelete:!1,protocols:["anthropic"]},{key:"openai",label:s("modelManagement.tabs.openai"),description:s("modelManagement.tabs.openaiDesc"),isSystem:!0,canDelete:!1,protocols:["openai-auto","openai-chat","openai-responses"]}],g=t.map(d=>{let x=s("modelManagement.tabs.customEndpoint"),a=[];if(d.paths&&d.paths.length>0)x=`${s("modelManagement.tabs.customEndpoint")}: ${d.paths.map(o=>`${o.path} (${o.protocol})`).join(", ")}`,a=[...new Set(d.paths.map(o=>o.protocol))];else if(d.path){const o=d.protocol||"anthropic";x=`${s("modelManagement.tabs.customEndpoint")}: ${d.path} (${o})`,a=[o]}return{key:d.id,label:d.label||d.id,description:x,isSystem:!1,canDelete:d.deletable!==!1,protocols:a}});return[...c,...g]}function Et(s){return s.label&&s.label.trim().length>0?`${s.label} (${s.id})`:s.id}function qs({providerCount:s,providersLength:t,filteredProviders:c,defaultLabels:g,providerSearch:d,providerTypeFilter:x,configPending:a,configFetching:o,testingProviderId:m,onRefresh:u,onOpenCreate:h,onOpenEdit:F,onTestConnection:k,onRequestDelete:M,onProviderSearchChange:C,onProviderTypeChange:v,onResetFilters:f}){const{t:b}=te();return e.jsx(Fe,{children:e.jsxs(Be,{className:"space-y-6 pt-6",children:[e.jsx(Ct,{eyebrow:"Model Access",title:b("providers.title"),description:b("providers.description"),breadcrumb:[b("modelManagement.title"),b("modelManagement.tabs.providers")],aside:e.jsxs("div",{className:"flex w-full flex-wrap items-center gap-2 sm:w-auto sm:gap-3",children:[e.jsx(H,{variant:"secondary",children:b("providers.count",{count:s})}),e.jsxs(L,{variant:"outline",size:"sm",onClick:u,disabled:o,className:"w-full sm:w-auto",children:[e.jsx(fs,{className:oe("mr-2 h-4 w-4",o&&"animate-spin")}),b(o?"common.actions.refreshing":"providers.actions.refresh")]}),e.jsxs(L,{size:"sm",onClick:h,className:"w-full sm:w-auto",children:[e.jsx(pt,{className:"mr-2 h-4 w-4"}),b("providers.actions.add")]})]})}),e.jsxs("div",{className:"grid gap-3 md:grid-cols-3",children:[e.jsx(_e,{label:"Configured",value:s.toString(),helper:"Total providers in supply pool",tone:"blue"}),e.jsx(_e,{label:"Visible",value:c.length.toString(),helper:"Providers matching current filter",tone:"emerald"}),e.jsx(_e,{label:"Connection Status",value:m?"Testing":"Idle",helper:m?`Testing ${m}`:"Ready for diagnostics",tone:"amber"})]}),e.jsxs("div",{className:"rounded-lg border border-border bg-accent px-4 py-3 text-sm text-primary",children:[e.jsx("p",{className:"font-medium",children:b("modelManagement.providersSemantics.title")}),e.jsx("p",{className:"mt-1 leading-6 text-primary/80",children:b("modelManagement.providersSemantics.description")})]}),e.jsxs("div",{className:"grid gap-3 rounded-lg border border-border bg-secondary p-4 sm:grid-cols-2 xl:grid-cols-[minmax(0,1fr)_220px_auto]",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(J,{className:"text-[11px] uppercase tracking-[0.16em] text-muted-foreground",children:b("providers.filters.searchPlaceholder")}),e.jsx(fe,{value:d,onChange:j=>C(j.target.value),placeholder:b("providers.filters.searchPlaceholder")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(J,{className:"text-[11px] uppercase tracking-[0.16em] text-muted-foreground",children:b("providers.filters.typeAll")}),e.jsxs(gt,{value:x,onValueChange:v,children:[e.jsx(ht,{children:e.jsx(ft,{})}),e.jsxs(bt,{children:[e.jsx(me,{value:"all",children:b("providers.filters.typeAll")}),e.jsx(me,{value:"openai",children:"OpenAI"}),e.jsx(me,{value:"anthropic",children:"Anthropic"}),e.jsx(me,{value:"deepseek",children:"DeepSeek"}),e.jsx(me,{value:"huawei",children:"Huawei"}),e.jsx(me,{value:"kimi",children:"Kimi"}),e.jsx(me,{value:"custom",children:"Custom"})]})]})]}),e.jsx("div",{className:"flex items-end sm:col-span-2 xl:col-span-1",children:e.jsx(L,{variant:"ghost",size:"sm",onClick:f,disabled:!d.trim()&&x==="all",className:"w-full xl:w-auto",children:b("common.actions.reset")})})]}),a?e.jsx("div",{className:"flex min-h-[200px] items-center justify-center rounded-lg border border-border bg-secondary text-sm text-muted-foreground",children:b("common.loading")}):t===0?e.jsxs("div",{className:"rounded-lg border border-dashed border-border p-12 text-center text-sm text-muted-foreground",children:[e.jsx("p",{className:"font-medium",children:b("providers.emptyState")}),e.jsx("p",{className:"mt-2 text-xs",children:b("providers.emptyStateSub",{default:"点击上方按钮添加您的第一个提供商"})})]}):c.length===0?e.jsx("div",{className:"rounded-lg border border-dashed border-border p-12 text-center text-sm text-muted-foreground",children:e.jsx("p",{className:"font-medium",children:b("providers.emptyFiltered")})}):e.jsx("div",{className:"grid gap-4 [grid-template-columns:repeat(auto-fit,minmax(280px,1fr))]",children:c.map(j=>{var Q;return e.jsx(Fe,{className:"flex flex-col overflow-hidden","data-testid":"provider-card",children:e.jsxs(Be,{className:"flex flex-1 flex-col gap-4 pt-6",children:[e.jsxs("div",{className:"flex flex-col gap-4 sm:flex-row sm:items-start sm:justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h3",{className:"text-base font-semibold tracking-[-0.02em]",children:j.label||j.id}),j.type?e.jsx(Ws,{type:j.type}):null]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["ID: ",j.id]}),e.jsx("code",{className:"block max-w-full break-all rounded-lg border border-border bg-secondary px-2.5 py-1.5 text-[11px] text-muted-foreground",children:j.baseUrl})]}),j.defaultModel?e.jsx(H,{variant:"default",className:"text-xs",children:g.get(j.id)??j.defaultModel}):e.jsx(H,{variant:"secondary",className:"text-xs",children:b("providers.card.noDefault")})]}),e.jsxs("div",{className:"grid gap-2 sm:grid-cols-3",children:[e.jsx(Ce,{label:b("providers.card.authMode"),value:j.authMode==="authToken"?"Bearer":j.authMode==="xAuthToken"?"X-Auth-Token":"API Key"}),e.jsx(Ce,{label:b("providers.card.modelsTitle"),value:(Q=j.models)!=null&&Q.length?b("providers.card.modelCount",{count:j.models.length}):b("providers.card.passthrough")}),e.jsx(Ce,{label:b("providers.card.defaultModelLabel"),value:j.defaultModel?g.get(j.id)??j.defaultModel:b("providers.card.noDefault"),truncate:!0})]}),e.jsxs("div",{className:"grid gap-2 sm:grid-cols-2",children:[e.jsx(Ce,{label:"Routing readiness",value:j.defaultModel?"Ready":"Needs default"}),e.jsx(Ce,{label:"Endpoint type",value:j.type?j.type:"custom"})]}),e.jsxs("div",{className:"space-y-2 rounded-lg border border-border bg-secondary p-3",children:[e.jsx(J,{className:"text-xs uppercase tracking-[0.16em] text-muted-foreground",children:b("providers.card.modelsTitle")}),j.models&&j.models.length>0?e.jsx("div",{className:"flex max-h-24 flex-wrap gap-1 overflow-y-auto",children:j.models.map(Y=>e.jsx(H,{variant:"outline",className:"text-xs",children:Et(Y)},Y.id))}):e.jsx("p",{className:"text-xs text-muted-foreground",children:b("providers.card.noModels")})]}),e.jsxs("div",{className:"mt-auto grid gap-2 border-t border-border pt-4 sm:grid-cols-3",children:[e.jsx(L,{variant:"default",size:"sm",onClick:()=>F(j),className:"w-full",children:b("providers.actions.edit")}),e.jsx(L,{variant:"outline",size:"sm",onClick:()=>k(j),disabled:m===j.id,className:"w-full",children:m===j.id?b("common.actions.testingConnection"):b("providers.actions.test")}),e.jsx(L,{variant:"destructive",size:"sm",onClick:()=>M(j),className:"w-full",children:b("providers.actions.delete")})]})]})},j.id)})})]})})}function _e({helper:s,label:t,value:c}){return e.jsxs("div",{className:"rounded-lg border border-border bg-card px-4 py-3",children:[e.jsx("p",{className:"text-[11px] font-medium uppercase tracking-wider text-muted-foreground",children:t}),e.jsx("p",{className:"mt-2 text-base font-semibold text-foreground",children:c}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:s})]})}function Ce({label:s,value:t,truncate:c}){return e.jsxs("div",{className:"rounded-lg border border-border bg-secondary px-3 py-2",children:[e.jsx("p",{className:"text-[11px] font-medium uppercase tracking-[0.16em] text-muted-foreground",children:s}),e.jsx("p",{className:oe("mt-1 text-sm font-medium",c&&"truncate"),children:t})]})}function Ws({type:s}){const t={openai:{label:"OpenAI",variant:"success"},deepseek:{label:"DeepSeek",variant:"info"},huawei:{label:"华为云",variant:"warning"},kimi:{label:"Kimi",variant:"purple"},anthropic:{label:"Anthropic",variant:"pink"},custom:{label:"Custom",variant:"secondary"}},{label:c,variant:g}=t[s]||t.custom;return e.jsx(H,{variant:g,className:"text-xs",children:c})}function Qs({value:s,onChange:t,options:c,disabled:g,placeholder:d}){const{t:x}=te(),[a,o]=N.useState(!1),[m,u]=N.useState(""),h=N.useMemo(()=>{if(!m.trim())return c;const k=m.toLowerCase();return c.filter(M=>M.label.toLowerCase().includes(k)||M.value.toLowerCase().includes(k))},[c,m]),F=k=>{t(k),u(""),o(!1)};return e.jsxs(Es,{open:a,onOpenChange:k=>{o(k),k&&u("")},children:[e.jsx(Ss,{asChild:!0,children:e.jsx(fe,{value:s,onChange:k=>{t(k.target.value),u(k.target.value),a||o(!0)},onFocus:()=>{u(""),o(!0)},onClick:()=>{a||o(!0)},placeholder:d,disabled:g,autoComplete:"off"})}),e.jsx(Ps,{className:"max-h-60 w-[var(--radix-popover-trigger-width)] overflow-y-auto p-1",align:"start",onOpenAutoFocus:k=>k.preventDefault(),children:h.length===0?e.jsx("div",{className:"px-2 py-3 text-center text-xs text-muted-foreground",children:x("common.noMatches")}):h.map(k=>e.jsx("button",{type:"button",className:oe("flex w-full items-center rounded-sm px-2 py-1.5 text-left text-sm hover:bg-accent",k.value===s.trim()&&"bg-accent"),onMouseDown:M=>{M.preventDefault(),F(k.value)},children:e.jsx("span",{className:"truncate",children:k.label})},k.value))})]})}function Gs({endpoint:s,tabs:t,customEndpoints:c,config:g,routes:d,routeError:x,savingRoute:a,isDirty:o,presets:m,presetName:u,presetError:h,savingPreset:F,applyingPreset:k,deletingPreset:M,presetsExpanded:C,savingClaudeValidation:v,providerModelOptions:f,onTogglePresetsExpanded:b,onPresetNameChange:j,onSavePreset:Q,onRequestPresetDiff:Y,onRequestDeletePreset:ue,onToggleClaudeValidation:le,onRouteChange:Z,onRemoveRoute:V,onAddSuggestion:pe,onAddRoute:G,onResetRoutes:we,onSaveRoutes:be}){var B,X;const{t:T}=te(),I=t.find(A=>A.key===s),se=((B=I==null?void 0:I.protocols)==null?void 0:B.includes("anthropic"))??s==="anthropic"?Hs:Is,xe=(I==null?void 0:I.label)??s,ie=(I==null?void 0:I.isSystem)===!1?I.description:T(`settings.routing.descriptionByEndpoint.${s}`),ge=`route-source-${s}`,i=zs(s,c),E=Vs(s,g,c),R=i&&(E==null?void 0:E.mode)==="claude-code",P=new Set(d.map(A=>A.source.trim()).filter(Boolean));return e.jsx(Fe,{children:e.jsxs(Be,{className:"space-y-6 pt-6",children:[e.jsx(Ct,{eyebrow:"Routing Workspace",title:T("settings.routing.titleByEndpoint",{endpoint:xe}),description:ie,breadcrumb:[T("modelManagement.title"),xe],aside:e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs(H,{variant:"outline",children:[d.length," rules"]}),o?e.jsx(H,{variant:"outline",className:"border-amber-300 text-amber-700 dark:border-amber-700 dark:text-amber-300",children:T("modelManagement.actions.unsaved")}):e.jsx(H,{variant:"secondary",children:T("common.status.success")})]})}),e.jsxs("div",{className:"grid gap-3 md:grid-cols-4",children:[e.jsx(Ue,{label:"Rules",value:d.length.toString(),helper:"Current model routes",tone:"blue"}),e.jsx(Ue,{label:"Presets",value:m.length.toString(),helper:"Reusable routing templates",tone:"emerald"}),e.jsx(Ue,{label:"Protocols",value:(((X=I==null?void 0:I.protocols)==null?void 0:X.length)??0).toString(),helper:"Bound to this endpoint",tone:"amber"}),e.jsx(Ue,{label:"Validation",value:i?R?"Claude Code":"Disabled":"Standard",helper:i?"Anthropic compatibility mode":"Default endpoint routing",tone:"rose"})]}),e.jsx("div",{className:"rounded-lg border border-border bg-secondary px-4 py-3 text-xs text-muted-foreground",children:T("settings.routing.wildcardHint")}),i?e.jsx("div",{className:"rounded-lg border border-primary/20 bg-accent p-4",children:e.jsxs("div",{className:"flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-sm font-medium text-primary",children:T("modelManagement.claudeValidation.title")}),e.jsx("p",{className:"text-xs text-primary/80",children:T("modelManagement.claudeValidation.description")})]}),e.jsxs("div",{className:"flex items-center gap-2 self-start sm:self-auto",children:[e.jsx(qe,{checked:R,onCheckedChange:le,disabled:v}),e.jsx("span",{className:oe("text-xs font-medium",R?"text-emerald-600 dark:text-emerald-400":"text-muted-foreground"),children:T(R?"modelManagement.claudeValidation.statusEnabled":"modelManagement.claudeValidation.statusDisabled")})]})]})}):null,x?e.jsx("p",{className:"text-sm text-destructive",children:x}):null,e.jsxs("div",{className:"space-y-3 rounded-lg border border-border bg-secondary p-4",children:[e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(J,{className:"text-sm font-semibold text-foreground",children:T("modelManagement.routesEditorTitle")}),e.jsxs(H,{variant:"outline",children:[d.length," active"]})]}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:T("modelManagement.overview.routesEditorHint")})]}),e.jsxs("div",{className:"self-start rounded-lg border border-border bg-card px-3 py-2 text-[11px] text-muted-foreground",children:[xe," workspace"]})]}),d.length===0?e.jsxs("div",{className:"rounded-lg border border-dashed border-border p-12 text-center text-sm text-muted-foreground",children:[e.jsx("p",{className:"font-medium",children:T("settings.routing.empty")}),e.jsx("p",{className:"mt-2 text-xs",children:T("modelManagement.emptyRoutesHint")})]}):e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"hidden grid-cols-[minmax(0,1fr)_auto_minmax(0,1fr)_auto] items-center gap-3 px-1 text-xs font-medium text-muted-foreground md:grid",children:[e.jsx("span",{children:T("settings.routing.source")}),e.jsx("span",{}),e.jsx("span",{children:T("settings.routing.target")}),e.jsx("span",{})]}),d.map((A,q)=>e.jsxs("div",{className:"rounded-lg border border-border bg-card p-3",children:[e.jsxs("div",{className:"mb-3 flex items-center justify-between md:hidden",children:[e.jsxs(H,{variant:"outline",className:"text-[11px]",children:["#",q+1]}),e.jsx(L,{variant:"ghost",size:"icon",className:"h-8 w-8 text-muted-foreground hover:text-destructive",onClick:()=>V(A.id),disabled:a,children:e.jsx(Se,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"grid gap-3 md:grid-cols-[minmax(0,1fr)_auto_minmax(0,1fr)_auto] md:items-center",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(J,{className:"text-[11px] uppercase tracking-[0.16em] text-muted-foreground md:hidden",children:T("settings.routing.source")}),e.jsx(fe,{value:A.source,onChange:de=>Z(A.id,"source",de.target.value),placeholder:T("settings.routing.sourcePlaceholder"),list:ge,disabled:a,"aria-label":`route-source-${q+1}`})]}),e.jsx(Ne,{className:"hidden h-4 w-4 flex-shrink-0 text-muted-foreground md:block"}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(J,{className:"text-[11px] uppercase tracking-[0.16em] text-muted-foreground md:hidden",children:T("settings.routing.target")}),e.jsx(Qs,{value:A.target,onChange:de=>Z(A.id,"target",de),options:f,disabled:a,placeholder:T("settings.routing.targetPlaceholder")})]}),e.jsx(L,{variant:"ghost",size:"icon",className:"hidden h-8 w-8 text-muted-foreground hover:text-destructive md:inline-flex",onClick:()=>V(A.id),disabled:a,children:e.jsx(Se,{className:"h-4 w-4"})})]})]},A.id))]})]}),e.jsxs("div",{className:"space-y-3 rounded-lg border border-border bg-secondary p-4",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(J,{className:"text-sm font-semibold text-foreground",children:T("settings.routing.suggested")}),e.jsxs(H,{variant:"outline",children:[se.length," presets"]})]}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:T("modelManagement.overview.suggestionHint")})]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:se.map(A=>{const q=P.has(A);return e.jsx(L,{variant:q?"ghost":"outline",size:"sm",onClick:()=>pe(A),disabled:a||q,className:q?"opacity-50":"",children:A},`${s}-${A}`)})})]}),e.jsxs("div",{className:"flex flex-col gap-3 rounded-lg border border-border bg-card p-4 md:flex-row md:items-center md:justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-sm font-medium",children:T("modelManagement.actions.footerTitle")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:T(o?"modelManagement.actions.footerDirtyHint":"modelManagement.actions.footerSavedHint")})]}),e.jsxs("div",{className:"grid gap-2 sm:grid-cols-3 md:flex md:flex-wrap md:items-center",children:[e.jsx(L,{variant:"outline",size:"sm",onClick:G,disabled:a,className:"w-full",children:T("settings.routing.add")}),e.jsx(L,{variant:"outline",size:"sm",onClick:we,disabled:a||!o,className:"w-full",children:T("common.actions.reset")}),e.jsxs(L,{size:"sm",onClick:be,disabled:a,className:"relative w-full",children:[T(a?"common.actions.saving":"modelManagement.actions.saveRoutes"),o?e.jsx("span",{className:"absolute -right-1 -top-1 h-2 w-2 rounded-full bg-amber-500"}):null]})]})]}),e.jsx(Xs,{presets:m,presetName:u,presetError:h,savingPreset:F,applyingPreset:k,deletingPreset:M,expanded:C,onToggleExpanded:b,onPresetNameChange:j,onSavePreset:Q,onRequestPresetDiff:Y,onRequestDeletePreset:ue}),e.jsx("datalist",{id:ge,children:se.map(A=>e.jsx("option",{value:A},`${ge}-${A}`))})]})})}function Ue({helper:s,label:t,value:c}){return e.jsxs("div",{className:"rounded-lg border border-border bg-card px-4 py-3",children:[e.jsx("p",{className:"text-[11px] font-medium uppercase tracking-wider text-muted-foreground",children:t}),e.jsx("p",{className:"mt-2 truncate text-base font-semibold text-foreground",children:c}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:s})]})}function Xs({presets:s,presetName:t,presetError:c,savingPreset:g,applyingPreset:d,deletingPreset:x,expanded:a,onToggleExpanded:o,onPresetNameChange:m,onSavePreset:u,onRequestPresetDiff:h,onRequestDeletePreset:F}){const{t:k}=te();return e.jsxs("div",{className:"rounded-lg border border-dashed border-border bg-card",children:[e.jsx("button",{type:"button",className:"flex w-full items-center justify-between gap-3 p-4 text-left transition-colors hover:bg-primary/5",onClick:o,children:e.jsxs("div",{className:"flex items-center gap-2",children:[a?e.jsx(bs,{className:"h-4 w-4"}):e.jsx(xt,{className:"h-4 w-4"}),e.jsx("h3",{className:"font-medium",children:k("modelManagement.presets.title")}),e.jsx(H,{variant:"secondary",className:"text-xs",children:s.length})]})}),a?e.jsxs("div",{className:"space-y-4 border-t px-4 pb-4 pt-3",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:k("modelManagement.presets.description")}),e.jsxs("div",{className:"flex flex-col gap-3 md:flex-row md:items-center",children:[e.jsx(fe,{value:t,onChange:M=>m(M.target.value),placeholder:k("modelManagement.presets.namePlaceholder"),disabled:g,className:"w-full md:w-48"}),e.jsx(L,{onClick:u,disabled:g,className:"w-full md:w-auto",children:k(g?"modelManagement.presets.saving":"modelManagement.presets.save")})]}),c?e.jsx("p",{className:"text-sm text-destructive",children:c}):null,s.length===0?e.jsx("p",{className:"py-4 text-center text-sm text-muted-foreground",children:k("modelManagement.presets.empty")}):e.jsx(Ns,{children:e.jsx("div",{className:"grid gap-2 sm:grid-cols-2 lg:grid-cols-3",children:s.map(M=>{const C=d===M.name,v=x===M.name,f=Object.entries(M.modelRoutes??{}),b=f.length;return e.jsxs("div",{className:"flex flex-col gap-3 rounded-lg border border-border bg-secondary px-4 py-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs(ws,{children:[e.jsx(Ms,{asChild:!0,children:e.jsxs("div",{className:"min-w-0 flex-1 cursor-default",children:[e.jsx("span",{className:"block truncate text-sm font-medium",children:M.name}),e.jsx(H,{variant:"outline",className:"mt-1 text-xs",children:b>0?k("modelManagement.presets.rulesCount",{count:b}):k("modelManagement.presets.noRules")})]})}),b>0?e.jsx(ks,{side:"bottom",className:"max-w-xs",children:e.jsxs("div",{className:"space-y-1 text-xs",children:[f.slice(0,5).map(([j,Q])=>e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"truncate",children:j}),e.jsx(Ne,{className:"h-3 w-3 flex-shrink-0"}),e.jsx("span",{className:"truncate",children:Q})]},j)),b>5?e.jsxs("div",{className:"text-muted-foreground",children:["…+",b-5]}):null]})}):null]}),e.jsxs("div",{className:"grid flex-shrink-0 gap-2 sm:flex sm:items-center",children:[e.jsx(L,{size:"sm",onClick:()=>h(M),disabled:C||v,className:"w-full sm:w-auto",children:k(C?"modelManagement.presets.applying":"modelManagement.presets.apply")}),e.jsx(L,{variant:"destructive",size:"sm",onClick:()=>F(M),disabled:v||C,className:"w-full sm:w-auto",children:k(v?"modelManagement.presets.deleting":"modelManagement.presets.delete")})]})]},M.name)})})})]}):null]})}function Js({open:s,provider:t,options:c,usePreset:g,preservedExtras:d,onPresetChange:x,onConfirm:a,onClose:o}){const{t:m}=te();return t?e.jsx(vt,{open:s,onOpenChange:u=>!u&&o(),children:e.jsxs(jt,{className:"max-w-2xl",children:[e.jsxs(yt,{children:[e.jsx(Nt,{children:m("providers.testDialog.title")}),e.jsx(wt,{children:m("providers.testDialog.subtitle",{name:t.label||t.id})})]}),e.jsxs(Mt,{className:"space-y-4",children:[e.jsx("div",{className:"rounded-lg border border-primary/20 bg-accent p-4 text-sm text-primary",children:m("providers.testDialog.description")}),e.jsxs("div",{className:"space-y-4 rounded-lg border border-border bg-secondary p-4",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(J,{htmlFor:"provider-test-preset",children:m("providers.testDialog.presetLabel")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:m("providers.testDialog.presetDescription")})]}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(qe,{id:"provider-test-preset",checked:g,onCheckedChange:x})})]}),g?e.jsx("div",{className:"space-y-2",children:e.jsxs("details",{className:"rounded-lg border border-border bg-secondary p-2 text-xs",children:[e.jsx("summary",{className:"cursor-pointer text-primary hover:underline",children:m("providers.testDialog.presetPreviewSummary")}),e.jsx("div",{className:"mt-2 space-y-1",children:c.map(u=>e.jsxs("code",{className:"block rounded-md border border-border bg-card px-2 py-1 text-xs",children:[u.key,": ",u.value]},u.key))})]})}):e.jsx("p",{className:"text-xs text-muted-foreground",children:m("providers.testDialog.presetDescription")})]}),Object.keys(d).length>0&&e.jsxs("div",{className:"space-y-2 rounded-lg border border-border bg-secondary p-4 text-xs",children:[e.jsx("p",{className:"font-medium",children:m("providers.testDialog.preservedInfo")}),Object.entries(d).map(([u,h])=>e.jsxs("code",{className:"block rounded-md border border-border bg-card px-2 py-1",children:[u,": ",h]},u))]})]}),e.jsxs(kt,{children:[e.jsx(L,{variant:"outline",onClick:o,children:m("providers.testDialog.cancel")}),e.jsx(L,{onClick:()=>void a(),children:m("providers.testDialog.primary")})]})]})}):null}const $e={savePreset(s,t){return Re(Te.post(`/api/routing-presets/${s}`,{name:t}))},applyPreset(s,t){return Re(Te.post(`/api/routing-presets/${s}/apply`,{name:t}))},deletePreset(s,t){return Re(Te.delete(`/api/routing-presets/${s}/${encodeURIComponent(t)}`))},testProvider(s,t){return Re(Te.post(`/api/providers/${s}/test`,t))}};function ut(s,t){var g,d,x;const c={anthropic:((g=s.routingPresets)==null?void 0:g.anthropic)??[],openai:((d=s.routingPresets)==null?void 0:d.openai)??[]};for(const a of t){const o=(x=s.customEndpoints)==null?void 0:x.find(m=>m.id===a.id);c[a.id]=(o==null?void 0:o.routingPresets)??a.routingPresets??[]}return c}function Ys(){var at;const{t:s}=te(),{pushToast:t}=Cs(),c=Ds(),g=Ts(he.config.full(),ye.configRequest()),x=((at=Rs({queryKey:he.customEndpoints.all(),queryFn:Ee.list,refetchInterval:1e4}).data)==null?void 0:at.endpoints)??[],a=N.useMemo(()=>_s(s,x),[x,s]),[o,m]=N.useState("providers"),[u,h]=N.useState(null),[F,k]=N.useState(!1),[M,C]=N.useState("create"),[v,f]=N.useState(void 0),[b,j]=N.useState(void 0),[Q,Y]=N.useState(null),[ue,le]=N.useState(!1),[Z,V]=N.useState({}),[pe,G]=N.useState({}),[we,be]=N.useState(null),[T,I]=N.useState({}),[Me,se]=N.useState({}),[xe,ie]=N.useState({}),[ge,i]=N.useState(null),[E,R]=N.useState(null),[P,B]=N.useState(null),[X,A]=N.useState(!1),[q,de]=N.useState(null),[re,He]=N.useState(!0),[Ge,Xe]=N.useState({}),[St,Je]=N.useState(!1),[Pt,Dt]=N.useState({}),[Rt,Tt]=N.useState(null),[S,Ye]=N.useState(null),[Ot,Ze]=N.useState(!1),[Ie,At]=N.useState(""),[Pe,Ut]=N.useState("all"),$t=N.useMemo(()=>a.filter(r=>r.isSystem),[a]),Lt=N.useMemo(()=>a.filter(r=>!r.isSystem),[a]),Ft=N.useMemo(()=>a.find(r=>r.key===o)??a[0]??null,[o,a]),ee=(u==null?void 0:u.providers)??[],Bt=ee.length,Ht=N.useMemo(()=>ee.filter(r=>{var w;if(!(Pe==="all"||(r.type??"custom")===Pe))return!1;const n=Ie.trim().toLowerCase();return n?[r.id,r.label??"",r.baseUrl,r.defaultModel??"",...((w=r.models)==null?void 0:w.map(y=>y.id))??[]].join(" ").toLowerCase().includes(n):!0}),[Ie,Pe,ee]),ke=N.useMemo(()=>[{key:"anthropic-beta",value:"claude-code-20250219,interleaved-thinking-2025-05-14,fine-grained-tool-streaming-2025-05-14",label:s("providers.testDialog.options.beta.label"),description:s("providers.testDialog.options.beta.description")}],[s]);N.useEffect(()=>{if(!g.data)return;const r=g.data;h(r),V(l=>{const n=Ve(r,x);if(!l||Object.keys(l).length===0)return n;const p={...n};for(const[w,y]of Object.entries(l)){if(!(w in n))continue;const D=ct(r,x,w);mt(y,D)&&(p[w]=y)}return p}),G({}),I(ut(r,x))},[g.data,x]),N.useEffect(()=>{!g.isError||!g.error||t({title:s("providers.toast.loadFailure",{message:g.error.message}),variant:"error"})},[g.error,g.isError,t,s]),N.useEffect(()=>{a.some(r=>r.key===o)||m("providers")},[o,a]);const It=N.useMemo(()=>{const r=new Map;for(const l of ee){if(!l.defaultModel||!l.models)continue;const n=l.models.find(p=>p.id===l.defaultModel);n&&r.set(l.id,Et(n))}return r},[ee]),Kt=N.useMemo(()=>{const r=[],l=new Set;for(const n of ee){const p=n.label&&n.label!==n.id?`${n.label} (${n.id})`:n.id,w=n.models??[];if(w.length>0)for(const D of w){const $=`${n.id}:${D.id}`;l.has($)||(l.add($),r.push({value:$,label:`${p} · ${D.label??D.id}`}))}else if(n.defaultModel){const D=`${n.id}:${n.defaultModel}`;l.has(D)||(l.add(D),r.push({value:D,label:`${p} · ${n.defaultModel}`}))}const y=`${n.id}:*`;l.has(y)||(l.add(y),r.push({value:y,label:s("settings.routing.providerPassthroughOption",{provider:p})}))}for(const n of Object.values(Z).flat()){const p=n.target.trim();p&&!l.has(p)&&(l.add(p),r.push({value:p,label:p}))}return r},[ee,Z,s]),zt=()=>{j(void 0),le(!0)},Vt=r=>{j(r),le(!0)},_t=r=>u?ct(u,x,r):{},qt=N.useMemo(()=>{const r={};for(const l of a){if(l.key==="providers")continue;const n=Z[l.key]||[];r[l.key]=mt(n,_t(l.key))}return r},[u,x,Z,a]),et=(r,l)=>{I(n=>({...n,[r]:l})),h(n=>{if(!n)return n;if(r==="anthropic"||r==="openai")return{...n,routingPresets:{...n.routingPresets,[r]:l}};const p=[...n.customEndpoints??[]],w=p.findIndex(y=>y.id===r);return w===-1?n:(p[w]={...p[w],routingPresets:l},{...n,customEndpoints:p})})},ce=()=>u?!0:(t({title:s("settings.toast.missingConfig"),variant:"error"}),g.refetch(),!1),Wt=(r,l)=>{se(n=>({...n,[r]:l})),l.trim()&&ie(n=>({...n,[r]:null}))},Qt=async r=>{if(!ce())return;const l=(Me[r]??"").trim();if(!l){ie(n=>({...n,[r]:s("modelManagement.validation.presetName")}));return}if((T[r]??[]).some(n=>n.name.toLowerCase()===l.toLowerCase())){ie(n=>({...n,[r]:s("modelManagement.validation.presetDuplicate",{name:l})}));return}i(r);try{const p=(await $e.savePreset(r,l)).presets??[];et(r,p),se(w=>({...w,[r]:""})),ie(w=>({...w,[r]:null})),t({title:s("modelManagement.toast.presetSaved",{name:l}),variant:"success"})}catch(n){t({title:s("modelManagement.toast.presetSaveFailure",{message:n instanceof Error?n.message:"unknown"}),variant:"error"})}finally{i(null),g.refetch()}},Gt=async(r,l)=>{if(ce()){R({endpoint:r,name:l.name});try{const p=(await $e.applyPreset(r,l.name)).config;if(p)h(p),V(Ve(p,x)),I(ut(p,x));else{const w=l.modelRoutes??{};V(y=>({...y,[r]:Object.entries(w).map(([D,$])=>({id:ne(),source:D,target:$}))})),h(y=>{var $,U,O,K;if(!y)return y;const D=(y.customEndpoints??[]).findIndex(z=>z.id===r);if(D!==-1){const z=[...y.customEndpoints??[]],ae=z[D];return z[D]={...ae,routing:{defaults:(($=ae.routing)==null?void 0:$.defaults)??y.defaults,...ae.routing??{},modelRoutes:w}},{...y,customEndpoints:z}}return r==="anthropic"||r==="openai"?{...y,endpointRouting:{...y.endpointRouting??{},[r]:{defaults:((O=(U=y.endpointRouting)==null?void 0:U[r])==null?void 0:O.defaults)??y.defaults,...((K=y.endpointRouting)==null?void 0:K[r])??{},modelRoutes:w}},modelRoutes:r==="anthropic"?w:y.modelRoutes??{}}:y})}r!=="anthropic"&&r!=="openai"&&await c.invalidateQueries({queryKey:he.customEndpoints.all()}),t({title:s("modelManagement.toast.presetApplySuccess",{name:l.name}),variant:"success"})}catch(n){t({title:s("modelManagement.toast.presetApplyFailure",{message:n instanceof Error?n.message:"unknown"}),variant:"error"})}finally{R(null),g.refetch()}}},Xt=async(r,l)=>{if(ce()){B({endpoint:r,name:l.name});try{const n=await $e.deletePreset(r,l.name);et(r,n.presets??[]),t({title:s("modelManagement.toast.presetDeleteSuccess",{name:l.name}),variant:"success"})}catch(n){t({title:s("modelManagement.toast.presetDeleteFailure",{message:n instanceof Error?n.message:"unknown"}),variant:"error"})}finally{B(null),g.refetch()}}},Jt=()=>{ce()&&(C("create"),f(void 0),k(!0))},Yt=r=>{ce()&&(C("edit"),f(r),k(!0))},Zt=async r=>{if(!u)throw new Error(s("settings.toast.missingConfig"));const l=M==="create"?[...ee,r]:ee.map(p=>v&&p.id===v.id?{...r,id:v.id}:p),n={...u,providers:l};await ye.saveConfig(n),h(n),V(Ve(n,x)),g.refetch(),t({title:M==="create"?s("providers.toast.createSuccess",{name:r.label||r.id}):s("providers.toast.updateSuccess",{name:r.label||r.id}),variant:"success"})},es=async r=>{const l=x.find(n=>n.id===r);if(!(!l||l.deletable===!1))try{await Ee.delete(r),await c.invalidateQueries({queryKey:he.customEndpoints.all()}),t({title:s("modelManagement.deleteEndpointSuccess"),variant:"success"}),o===r&&m("providers")}catch(n){const p=ot(n);t({title:s("modelManagement.deleteEndpointError",{error:p.message}),variant:"error"})}},tt=async(r,l)=>{Y(r.id);try{const n=l&&(l.headers||l.query)?{headers:l.headers&&Object.keys(l.headers).length>0?l.headers:void 0,query:l.query&&l.query.trim().length>0?l.query.trim():void 0}:void 0,p=await $e.testProvider(r.id,n);if(p.ok){t({title:s("providers.toast.testSuccess"),description:s("providers.toast.testSuccessDesc",{status:p.status,duration:p.durationMs?`${p.durationMs} ms`:"—"}),variant:"success"});return}t({title:s("providers.toast.testFailure",{message:`${p.status} ${p.statusText}`}),variant:"error"})}catch(n){t({title:s("providers.toast.testFailure",{message:n instanceof Error?n.message:"unknown"}),variant:"error"})}finally{Y(null)}},ts=r=>{if(r.type!=="anthropic"){tt(r);return}const l=r.extraHeaders??{},n=new Map(ke.map(y=>[y.key.toLowerCase(),y])),p={};let w=!0;for(const y of ke){const D=Object.entries(l).find(([O])=>O.toLowerCase()===y.key.toLowerCase());if(!D)continue;const[$,U]=D;String(U??"")!==y.value&&(w=!1,p[$]=String(U??""))}for(const[y,D]of Object.entries(l))n.has(y.toLowerCase())||(p[y]=String(D??""));Xe(p),He(w),de(r),A(!0)},st=()=>{A(!1),de(null),He(!0),Xe({})},ss=async()=>{if(!q)return;const r={};if(re)for(const p of ke)r[p.key]=p.value;const l=new Map(ke.map(p=>[p.key.toLowerCase(),p]));for(const[p,w]of Object.entries(Ge))l.get(p.toLowerCase())&&re||(r[p]=w);const n=q;st(),await tt(n,{headers:Object.keys(r).length>0?r:void 0,query:re?"beta=true":void 0})},rt=async r=>{var U,O,K,z,ae,De;if(!ce())return;const l=ee.filter(_=>_.id!==r.id),n=_=>{const W={};if(!_)return W;for(const[ve,je]of Object.entries(_)){if(!je)continue;const[nt]=je.split(":");nt&&nt===r.id||je===r.id||(W[ve]=je)}return W},p=(u==null?void 0:u.endpointRouting)??{},w=n(((U=p.anthropic)==null?void 0:U.modelRoutes)??(u==null?void 0:u.modelRoutes)??{}),y=n(((O=p.openai)==null?void 0:O.modelRoutes)??{}),D=((u==null?void 0:u.customEndpoints)??x).map(_=>{const W=_.routing,ve=W==null?void 0:W.modelRoutes;return ve?{..._,routing:{...W,defaults:W.defaults??u.defaults,modelRoutes:n(ve)}}:_}),$={...u,providers:l,modelRoutes:w,customEndpoints:D,endpointRouting:{anthropic:{defaults:((K=p.anthropic)==null?void 0:K.defaults)??u.defaults,modelRoutes:w,validation:(z=p.anthropic)==null?void 0:z.validation},openai:{defaults:((ae=p.openai)==null?void 0:ae.defaults)??u.defaults,modelRoutes:y,validation:(De=p.openai)==null?void 0:De.validation}}};try{await ye.saveConfig($),h($),V({anthropic:Object.entries(w).map(([_,W])=>({id:ne(),source:_,target:W})),openai:Object.entries(y).map(([_,W])=>({id:ne(),source:_,target:W})),...Object.fromEntries(D.map(_=>{var W;return[_.id,Object.entries(((W=_.routing)==null?void 0:W.modelRoutes)??{}).map(([ve,je])=>({id:ne(),source:ve,target:je}))]}))}),t({title:s("providers.toast.deleteSuccess",{name:r.label||r.id}),variant:"success"}),g.refetch()}catch(_){t({title:s("providers.toast.deleteFailure",{message:_ instanceof Error?_.message:"unknown"}),variant:"error"})}},rs=async()=>{if(S){Ze(!0);try{S.kind==="provider"?await rt(S.provider):S.kind==="preset"?await Xt(S.endpoint,S.preset):await es(S.endpoint.id),Ye(null)}finally{Ze(!1)}}},as=r=>{V(l=>({...l,[r]:[...l[r]||[],{id:ne(),source:"",target:""}]})),G(l=>({...l,[r]:null}))},ns=async(r,l)=>{var n,p;if(ce()){Je(!0);try{if(r==="anthropic"||r==="openai"){const w=r,y=u.endpointRouting?{...u.endpointRouting}:{},D=y[w]??{defaults:u.defaults,modelRoutes:(w==="anthropic"?u.modelRoutes:{})??{}},$={defaults:D.defaults??u.defaults,modelRoutes:D.modelRoutes??{}},U=l?{...D.validation??{},mode:"claude-code",allowExperimentalBlocks:((n=D.validation)==null?void 0:n.allowExperimentalBlocks)??!0}:void 0,O={...u,endpointRouting:{...y,[w]:U?{...$,validation:U}:{...$}}};await ye.saveConfig(O),h(O)}else{const w=[...u.customEndpoints??[]],y=w.findIndex(K=>K.id===r);if(y===-1)throw new Error(s("modelManagement.toast.endpointNotFound"));const D=w[y],$=D.routing??{defaults:u.defaults,modelRoutes:{}},U=l?{...$.validation??{},mode:"claude-code",allowExperimentalBlocks:((p=$.validation)==null?void 0:p.allowExperimentalBlocks)??!0}:void 0;w[y]={...D,routing:U?{...$,validation:U}:{defaults:$.defaults,modelRoutes:$.modelRoutes}};const O={...u,customEndpoints:w};await ye.saveConfig(O),h(O)}t({title:s(l?"modelManagement.toast.claudeValidationEnabled":"modelManagement.toast.claudeValidationDisabled"),variant:"success"}),g.refetch()}catch(w){const y=ot(w);t({title:s("modelManagement.toast.claudeValidationFailure",{message:y.message}),variant:"error"})}finally{Je(!1)}}},os=(r,l)=>{V(n=>{const p=n[r]||[];return p.some(w=>w.source.trim()===l.trim())?n:{...n,[r]:[...p,{id:ne(),source:l,target:""}]}}),G(n=>({...n,[r]:null}))},ds=(r,l,n,p)=>{V(w=>({...w,[r]:(w[r]||[]).map(y=>y.id===l?{...y,[n]:p}:y)})),G(w=>({...w,[r]:null}))},ls=(r,l)=>{V(n=>({...n,[r]:(n[r]||[]).filter(p=>p.id!==l)})),G(n=>({...n,[r]:null}))},is=r=>{var n;if(!u)return;const l=(u.customEndpoints??x).find(p=>p.id===r);if(l)V(p=>{var w;return{...p,[r]:Object.entries(((w=l.routing)==null?void 0:w.modelRoutes)??{}).map(([y,D])=>({id:ne(),source:y,target:D}))}});else{const p=u.endpointRouting??{},w=r,y=w==="anthropic"?u.modelRoutes??{}:{},D=((n=p[w])==null?void 0:n.modelRoutes)??y;V($=>({...$,[r]:Object.entries(D).map(([U,O])=>({id:ne(),source:U,target:O}))}))}G(p=>({...p,[r]:null}))},cs=Le({mutationFn:async r=>(await ye.saveConfig(r.nextConfig),r)}),ms=Le({mutationFn:async r=>(await Ee.update(r.endpoint,{routing:r.routing}),r)}),us=async r=>{var p,w,y,D,$;if(!ce())return;const l=Z[r]||[],n={};for(const U of l){const O=U.source.trim(),K=U.target.trim();if(!(!O&&!K)){if(!O||!K){G(z=>({...z,[r]:s("settings.validation.routePair")}));return}if(n[O]){G(z=>({...z,[r]:s("settings.validation.routeDuplicate",{model:O})}));return}n[O]=K}}G(U=>({...U,[r]:null})),be(r);try{const U=x.find(O=>O.id===r);if(U){const O={...U.routing??{},modelRoutes:n,defaults:((p=U.routing)==null?void 0:p.defaults)||u.defaults};await ms.mutateAsync({endpoint:r,routing:O}),h(K=>{if(!K)return K;const z=[...K.customEndpoints??[]],ae=z.findIndex(De=>De.id===r);return ae===-1?K:(z[ae]={...z[ae],routing:O},{...K,customEndpoints:z})}),await c.invalidateQueries({queryKey:he.customEndpoints.all()})}else{const O={...u,endpointRouting:{...u.endpointRouting??{},[r]:{defaults:((y=(w=u.endpointRouting)==null?void 0:w[r])==null?void 0:y.defaults)??u.defaults,modelRoutes:n,validation:($=(D=u.endpointRouting)==null?void 0:D[r])==null?void 0:$.validation}},modelRoutes:r==="anthropic"?n:u.modelRoutes??{}};await cs.mutateAsync({endpoint:r,nextConfig:O}),h(O)}V(O=>({...O,[r]:Object.entries(n).map(([K,z])=>({id:ne(),source:K,target:z}))})),t({title:s("modelManagement.toast.routesSaved"),variant:"success"}),g.refetch()}catch(U){t({title:s("modelManagement.toast.routesSaveFailure",{message:U instanceof Error?U.message:"unknown"}),variant:"error"})}finally{be(null)}},ps=(S==null?void 0:S.kind)==="provider"?s("providers.actions.delete"):(S==null?void 0:S.kind)==="preset"?s("modelManagement.presets.delete"):(S==null?void 0:S.kind)==="endpoint"?s("common.delete"):"",xs=(S==null?void 0:S.kind)==="provider"?s("providers.confirm.delete",{name:S.provider.label||S.provider.id}):(S==null?void 0:S.kind)==="preset"?s("modelManagement.confirm.deletePreset",{name:S.preset.name}):(S==null?void 0:S.kind)==="endpoint"?s("modelManagement.deleteEndpointConfirm",{label:S.endpoint.label}):"",gs=(S==null?void 0:S.kind)==="provider"?S.provider.label||S.provider.id:(S==null?void 0:S.kind)==="preset"?S.preset.name:(S==null?void 0:S.kind)==="endpoint"?S.endpoint.label:"";return{activeTab:o,activeTabInfo:Ft,anthropicTestHeaderOptions:ke,applyingPreset:E,config:u,configQuery:g,confirmAction:S,confirmDialogDescription:xs,confirmDialogName:gs,confirmDialogTitle:ps,confirmingAction:Ot,customEndpoints:x,customTabs:Lt,defaultLabels:It,deletingPreset:P,drawerMode:M,drawerOpen:F,editingEndpoint:b,editingProvider:v,endpointDrawerOpen:ue,filteredProviders:Ht,handleAddRoute:as,handleAddSuggestion:os,handleApplyPreset:Gt,handleConfirmDialog:rs,handleDeleteProvider:rt,handleOpenCreate:Jt,handleOpenCreateEndpoint:zt,handleOpenEditEndpoint:Vt,handleOpenEdit:Yt,handlePresetNameChange:Wt,handleProviderSubmit:Zt,handleRemoveRoute:ls,handleResetRoutes:is,handleRouteChange:ds,handleSavePreset:Qt,handleSaveRoutes:us,handleToggleClaudeValidation:ns,initiateTestConnection:ts,isDirtyByEndpoint:qt,presetDiffDialog:Rt,presetErrorByEndpoint:xe,presetNameByEndpoint:Me,presetsByEndpoint:T,presetsExpanded:Pt,providerCount:Bt,providerModelOptions:Kt,providerSearch:Ie,providerTypeFilter:Pe,providers:ee,pushToast:t,routeError:pe,routesByEndpoint:Z,savingClaudeValidation:St,savingPresetFor:ge,savingRouteFor:we,setActiveTab:m,setConfirmAction:Ye,setDrawerMode:C,setDrawerOpen:k,setEditingEndpoint:j,setEditingProvider:f,setEndpointDrawerOpen:le,setPresetDiffDialog:Tt,setPresetsExpanded:Dt,setProviderSearch:At,setProviderTypeFilter:Ut,setTestDialogUsePreset:He,systemTabs:$t,tabs:a,testDialogOpen:X,testDialogPreservedExtras:Ge,testDialogProvider:q,testDialogUsePreset:re,testingProviderId:Q,closeTestDialog:st,confirmTestDialog:ss}}function br(){var x,a,o;const{t:s}=te(),t=Ys(),c=Object.values(t.isDirtyByEndpoint).filter(Boolean).length,g=Math.max(0,t.systemTabs.length-1)+t.customTabs.length,d=t.activeTab==="providers"?s("modelManagement.header.providersHelper"):s("modelManagement.header.routingHelper",{name:((x=t.activeTabInfo)==null?void 0:x.label)??t.activeTab});return e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx(ys,{icon:e.jsx(vs,{className:"h-5 w-5","aria-hidden":"true"}),title:s("modelManagement.title"),description:s("modelManagement.description"),eyebrow:"Routing Control",breadcrumb:"Gateway / Model Management",helper:d,badge:c>0?s("modelManagement.overview.unsavedCount",{count:c}):void 0,actions:e.jsxs("div",{className:"flex w-full flex-col gap-2 sm:w-auto sm:flex-row sm:flex-wrap sm:justify-end",children:[e.jsxs("div",{className:"rounded-lg border border-border bg-secondary px-3 py-2 text-xs text-muted-foreground",children:[s("modelManagement.tabs.providers")," · ",t.providerCount," / ",s("modelManagement.overview.routeWorkspacesStat")," · ",g]}),e.jsx(L,{onClick:t.handleOpenCreateEndpoint,className:"w-full sm:w-auto",children:s("modelManagement.addEndpoint")})]})}),e.jsx(Fs,{activeTab:t.activeTab,activeTabInfo:t.activeTabInfo,customEndpoints:t.customEndpoints,customTabs:t.customTabs,isDirtyByEndpoint:t.isDirtyByEndpoint,onDeleteEndpoint:t.setConfirmAction,onEditEndpoint:t.handleOpenEditEndpoint,onSelectTab:t.setActiveTab,providerCount:t.providerCount,systemTabs:t.systemTabs}),t.activeTab==="providers"?e.jsx(qs,{configPending:t.configQuery.isPending||!t.config&&t.configQuery.isFetching,configFetching:t.configQuery.isFetching,defaultLabels:t.defaultLabels,filteredProviders:t.filteredProviders,onOpenCreate:t.handleOpenCreate,onOpenEdit:t.handleOpenEdit,onRefresh:()=>void t.configQuery.refetch(),onRequestDelete:m=>t.setConfirmAction({kind:"provider",provider:m}),onResetFilters:()=>{t.setProviderSearch(""),t.setProviderTypeFilter("all")},onProviderSearchChange:t.setProviderSearch,onProviderTypeChange:t.setProviderTypeFilter,onTestConnection:t.initiateTestConnection,providerCount:t.providerCount,providerSearch:t.providerSearch,providerTypeFilter:t.providerTypeFilter,providersLength:t.providers.length,testingProviderId:t.testingProviderId}):e.jsx(Gs,{endpoint:t.activeTab,applyingPreset:((a=t.applyingPreset)==null?void 0:a.endpoint)===t.activeTab?t.applyingPreset.name:null,config:t.config,customEndpoints:t.customEndpoints,deletingPreset:((o=t.deletingPreset)==null?void 0:o.endpoint)===t.activeTab?t.deletingPreset.name:null,isDirty:t.isDirtyByEndpoint[t.activeTab]??!1,onAddRoute:()=>t.handleAddRoute(t.activeTab),onAddSuggestion:m=>t.handleAddSuggestion(t.activeTab,m),onPresetNameChange:m=>t.handlePresetNameChange(t.activeTab,m),onRequestDeletePreset:m=>t.setConfirmAction({kind:"preset",endpoint:t.activeTab,preset:m}),onRequestPresetDiff:m=>t.setPresetDiffDialog({endpoint:t.activeTab,preset:m}),onRemoveRoute:m=>t.handleRemoveRoute(t.activeTab,m),onResetRoutes:()=>t.handleResetRoutes(t.activeTab),onRouteChange:(m,u,h)=>t.handleRouteChange(t.activeTab,m,u,h),onSavePreset:()=>void t.handleSavePreset(t.activeTab),onSaveRoutes:()=>void t.handleSaveRoutes(t.activeTab),onToggleClaudeValidation:m=>void t.handleToggleClaudeValidation(t.activeTab,m),onTogglePresetsExpanded:()=>t.setPresetsExpanded(m=>({...m,[t.activeTab]:!m[t.activeTab]})),presetError:t.presetErrorByEndpoint[t.activeTab],presetName:t.presetNameByEndpoint[t.activeTab]??"",presets:t.presetsByEndpoint[t.activeTab]??[],presetsExpanded:t.presetsExpanded[t.activeTab]===!0,providerModelOptions:t.providerModelOptions,routeError:t.routeError[t.activeTab],routes:t.routesByEndpoint[t.activeTab]||[],savingClaudeValidation:t.savingClaudeValidation,savingPreset:t.savingPresetFor===t.activeTab,savingRoute:t.savingRouteFor===t.activeTab,tabs:t.tabs}),e.jsx(Us,{open:t.drawerOpen,mode:t.drawerMode,provider:t.drawerMode==="edit"?t.editingProvider:void 0,existingProviderIds:t.providers.map(m=>m.id).filter(m=>t.drawerMode==="edit"&&t.editingProvider?m!==t.editingProvider.id:!0),onClose:()=>{t.setDrawerOpen(!1),t.setEditingProvider(void 0),t.setDrawerMode("create")},onSubmit:t.handleProviderSubmit}),e.jsx(Ls,{open:t.endpointDrawerOpen,endpoint:t.editingEndpoint,onClose:()=>{t.setEndpointDrawerOpen(!1),t.setEditingEndpoint(void 0)},onSuccess:()=>{t.configQuery.refetch()}}),e.jsx(Js,{open:t.testDialogOpen,provider:t.testDialogProvider,options:t.anthropicTestHeaderOptions,preservedExtras:t.testDialogPreservedExtras,usePreset:t.testDialogUsePreset,onPresetChange:t.setTestDialogUsePreset,onConfirm:t.confirmTestDialog,onClose:t.closeTestDialog}),e.jsx(Bs,{dialog:t.presetDiffDialog,currentRoutes:t.presetDiffDialog?t.routesByEndpoint[t.presetDiffDialog.endpoint]||[]:[],onConfirm:(m,u)=>{t.setPresetDiffDialog(null),t.handleApplyPreset(m,u)},onClose:()=>t.setPresetDiffDialog(null)}),e.jsx(js,{open:!!t.confirmAction,onOpenChange:m=>{!m&&!t.confirmingAction&&t.setConfirmAction(null)},title:t.confirmDialogTitle,description:t.confirmDialogDescription,confirmLabel:t.confirmingAction?s("common.actions.loading"):s("common.delete"),cancelLabel:s("common.actions.cancel"),loading:t.confirmingAction,onConfirm:t.handleConfirmDialog,children:t.confirmDialogName?e.jsx("div",{className:"rounded-[1rem] border border-destructive/20 bg-destructive/5 px-3 py-2 font-mono text-xs text-foreground",children:t.confirmDialogName}):null})]})}export{br as default};
@@ -1 +0,0 @@
1
- import{j as e,az as J,av as gt,au as xt,r as m,Y as bt}from"./vendor-5iCEqDpV.js";import{u as Q,C as Le}from"./useAppMutation-Cd6HN12q.js";import{c as M,L as Fe,B as k,r as Te,h as ft,b as vt,u as jt}from"./index-BzuBtvAC.js";import{P as yt}from"./PageHeader-CSF0BWul.js";import{C as A,a as L}from"./card-CjhYPqKk.js";import{B as E}from"./badge-BvMdmUqJ.js";import{I as w}from"./input-BnFZKjRM.js";import{L as v}from"./label-i5-Lf72z.js";import{S as B}from"./switch-BVWWsjy3.js";import{S as Nt,a as wt,b as Ct,c as Pt,d as kt}from"./select-KdDvaKo4.js";import{u as R}from"./i18n-C7VVFIdN.js";import{u as Me}from"./useApiQuery-fBWRSgFK.js";import{g as Oe}from"./gateway-B0gBBN92.js";import{c as St}from"./clipboard-CALi6bTW.js";import{q as _}from"./queryKeys-BMvyDTQS.js";import"./DialogShell-CiIvBp8J.js";import"./radix-CmyU-WBH.js";import"./query-DxhDvnDC.js";import"./router-D8u_RlVh.js";const Rt=[{value:"fatal",labelKey:"fatal"},{value:"error",labelKey:"error"},{value:"warn",labelKey:"warn"},{value:"info",labelKey:"info"},{value:"debug",labelKey:"debug"},{value:"trace",labelKey:"trace"}],te=[{id:"section-basics",labelKey:"settings.sections.basics"},{id:"section-protocol",labelKey:"settings.sections.protocol"},{id:"section-security",labelKey:"settings.sections.security"},{id:"section-config-file",labelKey:"settings.sections.configFile"},{id:"section-cleanup",labelKey:"settings.sections.cleanup"}];function z(s){var o,l,c,a,i,h,p,T,x,d,N;const t=s.storePayloads,n=C=>typeof C=="boolean"?C:typeof t=="boolean"?t:!0;return{port:String(s.port??((o=s.http)==null?void 0:o.port)??""),host:s.host??((l=s.http)==null?void 0:l.host)??"127.0.0.1",logRetentionDays:String(s.logRetentionDays??30),logExportTimeoutSeconds:String(s.logExportTimeoutSeconds??60),storeRequestPayloads:n(s.storeRequestPayloads),storeResponsePayloads:n(s.storeResponsePayloads),logLevel:s.logLevel??"info",bodyLimitMb:(()=>{const C=s.bodyLimit;return typeof C=="number"&&Number.isFinite(C)&&C>0?String(Math.max(1,Math.round(C/(1024*1024)))):"10"})(),enableRoutingFallback:s.enableRoutingFallback===!0,httpEnabled:((c=s.http)==null?void 0:c.enabled)!==!1,httpPort:String(((a=s.http)==null?void 0:a.port)??s.port??4100),httpHost:((i=s.http)==null?void 0:i.host)??s.host??"127.0.0.1",httpsEnabled:((h=s.https)==null?void 0:h.enabled)===!0,httpsPort:String(((p=s.https)==null?void 0:p.port)??4443),httpsHost:((T=s.https)==null?void 0:T.host)??s.host??"127.0.0.1",httpsKeyPath:((x=s.https)==null?void 0:x.keyPath)??"",httpsCertPath:((d=s.https)==null?void 0:d.certPath)??"",httpsCaPath:((N=s.https)==null?void 0:N.caPath)??""}}function Y(s){return{enabled:s.enabled,username:s.username??"",password:"",confirmPassword:""}}function Et({activeSection:s,onSelectSection:t}){const{t:n}=R();return e.jsxs(e.Fragment,{children:[e.jsx("nav",{className:"hidden xl:block",children:e.jsxs("div",{className:"sticky top-20 rounded-lg border border-border bg-card p-4",children:[e.jsx("p",{className:"mb-3 text-xs font-medium uppercase tracking-wider text-muted-foreground",children:n("settings.sections.jump")}),e.jsx("div",{className:"space-y-1",children:te.map((o,l)=>e.jsxs("button",{type:"button",onClick:()=>t(o.id),className:M("flex w-full items-center gap-3 rounded-full px-3.5 py-2.5 text-left text-sm transition-all",s===o.id?"bg-accent font-medium text-primary":"text-muted-foreground hover:bg-secondary hover:text-foreground"),children:[e.jsx("span",{className:M("flex h-7 w-7 items-center justify-center rounded-full border text-[11px] font-semibold",s===o.id?"border-primary/20 bg-primary text-primary-foreground":"border-border bg-secondary text-muted-foreground"),children:l+1}),e.jsx("span",{children:n(o.labelKey)})]},o.id))})]})}),e.jsx("div",{className:"xl:hidden",children:e.jsx("div",{className:"-mx-1 overflow-x-auto pb-1",children:e.jsx("div",{className:"flex w-max gap-2 px-1",children:te.map(o=>e.jsx("button",{type:"button",onClick:()=>t(o.id),className:M("rounded-full border px-3.5 py-2 text-xs font-medium transition-all",s===o.id?"border-primary bg-accent text-primary":"border-border bg-card text-muted-foreground hover:border-primary/20 hover:bg-accent hover:text-primary"),children:n(o.labelKey)},o.id))})})})]})}function At({configPath:s,defaultsSummary:t,form:n,protocolSummaryLabel:o,protocolChangesPending:l,isAuthDirty:c,isConfigDirty:a,authEnabled:i,authUsername:h}){const{t:p}=R();return e.jsx(A,{children:e.jsxs(L,{className:"space-y-4 pt-5",children:[e.jsxs("div",{className:"flex flex-col gap-3 lg:flex-row lg:items-start lg:justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-[0.18em] text-muted-foreground",children:p("settings.overview.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:p("settings.overview.description")})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(E,{variant:a||c?"warning":"success",children:p(a||c?"modelManagement.actions.unsaved":"common.status.success")}),l?e.jsx(E,{variant:"outline",className:"border-amber-300 text-amber-700 dark:border-amber-700 dark:text-amber-300",children:p("settings.protocol.restartWarning")}):null]})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-3",children:[e.jsx(U,{label:p("settings.overview.cards.protocols"),value:o,helper:`${n.httpHost||"127.0.0.1"}:${n.httpPort}${n.httpsEnabled?` / ${n.httpsHost||"127.0.0.1"}:${n.httpsPort}`:""}`}),e.jsx(U,{label:p("settings.overview.cards.security"),value:p(i?"settings.overview.values.authEnabled":"settings.overview.values.authDisabled"),helper:h?`${p("settings.auth.username")}: ${h}`:p("settings.auth.enableHint")}),e.jsx(U,{label:p("settings.overview.cards.configFile"),value:s||p("settings.file.unknown"),helper:t??p("settings.defaults.none"),mono:!0})]})]})})}function Lt({defaultsSummary:s,errors:t,form:n,onInputChange:o,onSetForm:l,sectionRef:c}){const{t:a}=R();return e.jsx(A,{id:"section-basics",ref:c,children:e.jsxs(L,{className:"pt-6",children:[e.jsxs("div",{className:"mb-4 flex flex-col gap-3 lg:flex-row lg:items-start lg:justify-between",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold",children:a("settings.sections.basics")}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:a("settings.description")})]}),e.jsxs("div",{className:"grid gap-2 sm:grid-cols-3",children:[e.jsx(X,{label:a("settings.fields.retention"),value:n.logRetentionDays}),e.jsx(X,{label:a("settings.fields.logExportTimeout"),value:`${n.logExportTimeoutSeconds}s`}),e.jsx(X,{label:a("settings.fields.bodyLimit"),value:`${n.bodyLimitMb} MB`})]})]}),e.jsxs("div",{className:"grid gap-5 md:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(v,{children:a("settings.fields.port")}),e.jsx(w,{type:"number",min:1,max:65535,value:n.port,onChange:i=>o("port")(i.target.value),"aria-invalid":!!t.port}),t.port?e.jsx("p",{className:"text-xs text-destructive",children:t.port}):null]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(v,{children:a("settings.fields.host")}),e.jsx(w,{value:n.host,onChange:i=>o("host")(i.target.value),placeholder:a("settings.fields.hostPlaceholder")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(v,{children:a("settings.fields.retention")}),e.jsx(w,{type:"number",min:1,max:365,value:n.logRetentionDays,onChange:i=>o("logRetentionDays")(i.target.value),"aria-invalid":!!t.logRetentionDays}),t.logRetentionDays?e.jsx("p",{className:"text-xs text-destructive",children:t.logRetentionDays}):null]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(v,{children:a("settings.fields.logExportTimeout")}),e.jsx(w,{type:"number",min:5,max:600,value:n.logExportTimeoutSeconds,onChange:i=>o("logExportTimeoutSeconds")(i.target.value),"aria-invalid":!!t.logExportTimeoutSeconds}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a("settings.fields.logExportTimeoutHint")}),t.logExportTimeoutSeconds?e.jsx("p",{className:"text-xs text-destructive",children:t.logExportTimeoutSeconds}):null]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(v,{children:a("settings.fields.bodyLimit")}),e.jsx(w,{type:"number",min:1,max:2048,value:n.bodyLimitMb,onChange:i=>o("bodyLimitMb")(i.target.value),"aria-invalid":!!t.bodyLimitMb}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a("settings.fields.bodyLimitHint")}),t.bodyLimitMb?e.jsx("p",{className:"text-xs text-destructive",children:t.bodyLimitMb}):null]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(v,{children:a("settings.fields.logLevel")}),e.jsxs(Nt,{value:n.logLevel,onValueChange:i=>l(h=>({...h,logLevel:i})),children:[e.jsx(wt,{children:e.jsx(Ct,{})}),e.jsx(Pt,{children:Rt.map(i=>e.jsx(kt,{value:i.value,children:a(`settings.fields.logLevelOption.${i.labelKey}`)},i.value))})]})]}),e.jsxs("div",{className:"grid gap-4 md:col-span-2 sm:grid-cols-2",children:[e.jsx(Z,{label:a("settings.fields.storeRequestPayloads"),hint:a("settings.fields.storeRequestPayloadsHint"),checked:n.storeRequestPayloads,onCheckedChange:i=>l(h=>({...h,storeRequestPayloads:i}))}),e.jsx(Z,{label:a("settings.fields.storeResponsePayloads"),hint:a("settings.fields.storeResponsePayloadsHint"),checked:n.storeResponsePayloads,onCheckedChange:i=>l(h=>({...h,storeResponsePayloads:i}))}),e.jsx(Z,{label:a("settings.fields.enableRoutingFallback"),hint:a("settings.fields.enableRoutingFallbackHint"),checked:n.enableRoutingFallback,onCheckedChange:i=>l(h=>({...h,enableRoutingFallback:i}))})]}),e.jsxs("div",{className:"rounded-lg border border-border bg-secondary p-4 md:col-span-2",children:[e.jsx(v,{className:"text-xs uppercase tracking-wide text-muted-foreground",children:a("settings.fields.defaults")}),e.jsx("p",{className:"mt-2 text-sm",children:s??a("settings.defaults.none")})]})]})]})})}function Tt({errors:s,form:t,onSetForm:n,sectionRef:o}){const{t:l}=R();return e.jsx(A,{id:"section-protocol",ref:o,children:e.jsxs(L,{className:"space-y-6 pt-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold",children:l("settings.sections.protocol")}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:l("settings.protocol.description")})]}),e.jsx("div",{className:"rounded-lg border border-[hsl(var(--warning)/0.3)] bg-[hsl(var(--warning-bg))] p-4",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(J,{className:"mt-0.5 h-5 w-5 flex-shrink-0 text-[hsl(var(--warning)/1)]"}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm font-medium text-foreground",children:l("settings.protocol.restartWarning")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:l("settings.protocol.restartHint")}),e.jsx("code",{className:"block rounded-lg border border-border bg-secondary px-3 py-2 text-xs font-mono text-foreground",children:"cc-gw restart --daemon"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:l("settings.protocol.restartTip")})]})]})}),s.protocol?e.jsxs("div",{className:"rounded-lg border border-destructive/30 bg-destructive/10 p-4 text-sm text-destructive",children:[e.jsx(J,{className:"mr-2 inline h-4 w-4"}),s.protocol]}):null,e.jsxs("div",{className:"rounded-lg border border-border bg-secondary p-5",children:[e.jsxs("div",{className:"mb-4 flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(v,{className:"text-sm font-medium text-foreground",children:l("settings.protocol.http.enable")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:l("settings.protocol.http.hint")})]}),e.jsx(B,{checked:t.httpEnabled,onCheckedChange:c=>n(a=>({...a,httpEnabled:c}))})]}),t.httpEnabled?e.jsxs("div",{className:"mt-4 grid gap-4 border-t border-border pt-4 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(v,{children:l("settings.protocol.http.port")}),e.jsx(w,{type:"number",min:1,max:65535,value:t.httpPort,onChange:c=>n(a=>({...a,httpPort:c.target.value})),"aria-invalid":!!s.httpPort}),s.httpPort?e.jsx("p",{className:"text-xs text-destructive",children:s.httpPort}):null]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(v,{children:l("settings.protocol.http.host")}),e.jsx(w,{value:t.httpHost,onChange:c=>n(a=>({...a,httpHost:c.target.value})),placeholder:"127.0.0.1"})]})]}):null]}),e.jsxs("div",{className:"rounded-lg border border-border bg-secondary p-5",children:[e.jsxs("div",{className:"mb-4 flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(v,{className:"text-sm font-medium text-foreground",children:l("settings.protocol.https.enable")}),e.jsx(gt,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:l("settings.protocol.https.hint")})]}),e.jsx(B,{checked:t.httpsEnabled,onCheckedChange:c=>n(a=>({...a,httpsEnabled:c}))})]}),t.httpsEnabled?e.jsxs("div",{className:"mt-4 space-y-4 border-t border-border pt-4",children:[e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(v,{children:l("settings.protocol.https.port")}),e.jsx(w,{type:"number",min:1,max:65535,value:t.httpsPort,onChange:c=>n(a=>({...a,httpsPort:c.target.value})),"aria-invalid":!!s.httpsPort}),s.httpsPort?e.jsx("p",{className:"text-xs text-destructive",children:s.httpsPort}):null]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(v,{children:l("settings.protocol.https.host")}),e.jsx(w,{value:t.httpsHost,onChange:c=>n(a=>({...a,httpsHost:c.target.value})),placeholder:"127.0.0.1"})]})]}),e.jsx(ee,{label:l("settings.protocol.https.keyPath"),value:t.httpsKeyPath,onChange:c=>n(a=>({...a,httpsKeyPath:c})),placeholder:"~/.cc-gw/certs/key.pem"}),e.jsx(ee,{label:l("settings.protocol.https.certPath"),value:t.httpsCertPath,onChange:c=>n(a=>({...a,httpsCertPath:c})),placeholder:"~/.cc-gw/certs/cert.pem"}),e.jsx(ee,{label:l("settings.protocol.https.caPath"),value:t.httpsCaPath,onChange:c=>n(a=>({...a,httpsCaPath:c})),placeholder:"留空则不使用"}),e.jsx("div",{className:"rounded-lg border border-[hsl(var(--warning)/0.3)] bg-[hsl(var(--warning-bg))] p-4",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(J,{className:"mt-0.5 h-5 w-5 flex-shrink-0 text-[hsl(var(--warning)/1)]"}),e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsx("p",{className:"text-sm font-medium text-amber-800 dark:text-amber-200",children:l("settings.protocol.https.warning")}),e.jsxs("p",{className:"text-xs leading-relaxed text-amber-700 dark:text-amber-300",children:[e.jsx("strong",{children:l("settings.protocol.https.invalidCert")}),l("settings.protocol.https.invalidCertDetail")]}),e.jsxs("p",{className:"text-xs leading-relaxed text-amber-700 dark:text-amber-300",children:[e.jsx("strong",{children:l("settings.protocol.https.recommended")}),l("settings.protocol.https.recommendedDetail")]}),e.jsx("p",{className:"text-xs leading-relaxed text-amber-600 dark:text-amber-400",children:l("settings.protocol.https.tip")})]})]})})]}):null]})]})})}function Mt({authErrors:s,authForm:t,authLoading:n,authSettings:o,needsPassword:l,onAuthReset:c,onAuthSave:a,onSetAuthForm:i,savingAuth:h,isAuthDirty:p,sectionRef:T}){const{t:x}=R();return e.jsx(A,{id:"section-security",ref:T,children:e.jsxs(L,{className:"space-y-5 pt-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold",children:x("settings.sections.security")}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:x("settings.auth.description")})]}),n&&!o?e.jsx("div",{className:"flex min-h-[120px] items-center justify-center",children:e.jsx(Fe,{})}):e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex flex-col gap-4 rounded-lg border border-border bg-secondary p-4 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(v,{className:"text-sm font-medium",children:x("settings.auth.enable")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:x("settings.auth.enableHint")}),e.jsxs("div",{className:"flex flex-wrap gap-2 text-xs font-medium text-muted-foreground",children:[e.jsx("span",{className:"rounded-full border border-border bg-card px-3 py-1",children:"/ui"}),e.jsx("span",{className:"rounded-full border border-border bg-card px-3 py-1",children:"/api/*"}),e.jsx("span",{className:"rounded-full border border-border bg-card px-3 py-1",children:"Cookie Session"})]})]}),e.jsxs("div",{className:"flex items-center gap-3 self-start sm:self-auto",children:[e.jsx(E,{variant:t.enabled?"success":"secondary",children:t.enabled?x("settings.auth.statusEnabled"):x("settings.auth.statusDisabled")}),e.jsx(B,{checked:t.enabled,onCheckedChange:d=>i(N=>({...N,enabled:d}))})]})]}),e.jsxs("div",{className:"grid gap-6 lg:grid-cols-[minmax(0,1fr)_minmax(0,0.85fr)]",children:[e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2 sm:col-span-2",children:[e.jsx(v,{children:x("settings.auth.username")}),e.jsx(w,{value:t.username,onChange:d=>i(N=>({...N,username:d.target.value})),placeholder:x("settings.auth.usernamePlaceholder")}),s.username?e.jsx("p",{className:"text-xs text-destructive",children:s.username}):null]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(v,{children:x("settings.auth.password")}),e.jsx(w,{type:"password",value:t.password,disabled:!t.enabled,onChange:d=>i(N=>({...N,password:d.target.value})),placeholder:x("settings.auth.passwordPlaceholder")}),s.password?e.jsx("p",{className:"text-xs text-destructive",children:s.password}):e.jsx("p",{className:"text-xs text-muted-foreground",children:x(l?"settings.auth.passwordHintRequired":"settings.auth.passwordHintOptional")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(v,{children:x("settings.auth.confirmPassword")}),e.jsx(w,{type:"password",value:t.confirmPassword,disabled:!t.enabled,onChange:d=>i(N=>({...N,confirmPassword:d.target.value})),placeholder:x("settings.auth.confirmPasswordPlaceholder")}),s.confirmPassword?e.jsx("p",{className:"text-xs text-destructive",children:s.confirmPassword}):null]})]}),e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"rounded-lg border border-border bg-secondary p-4",children:[e.jsx("p",{className:"text-xs uppercase tracking-wide text-muted-foreground",children:x("settings.auth.status")}),e.jsx("p",{className:"mt-2 text-base font-semibold",children:o!=null&&o.enabled?x("settings.auth.statusEnabled"):x("settings.auth.statusDisabled")}),o!=null&&o.username?e.jsxs("div",{className:"mt-3 rounded-lg bg-accent px-3 py-2 text-xs font-medium text-primary",children:[x("settings.auth.username"),": ",o.username]}):null]}),e.jsx("div",{className:"rounded-lg border border-border bg-secondary p-4 text-xs text-muted-foreground",children:x(l?"settings.auth.passwordHintRequired":"settings.auth.passwordHintOptional")})]})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2 lg:flex lg:flex-wrap lg:justify-end",children:[e.jsx(k,{onClick:a,disabled:h||!p,className:"w-full lg:w-auto",children:x(h?"common.actions.saving":"settings.auth.actions.save")}),e.jsx(k,{variant:"outline",onClick:c,disabled:h||!p,className:"w-full lg:w-auto",children:x("common.actions.reset")})]})]})]})})}function Ot({configPath:s,onCopyPath:t,sectionRef:n}){const{t:o}=R();return e.jsx(A,{id:"section-config-file",ref:n,children:e.jsxs(L,{className:"space-y-3 pt-6",children:[e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold",children:o("settings.sections.configFile")}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:o("settings.file.description")})]}),e.jsxs(k,{variant:"outline",size:"sm",onClick:t,className:"w-full sm:w-auto",children:[e.jsx(xt,{className:"mr-2 h-4 w-4"}),o("common.actions.copy")]})]}),e.jsx("code",{className:"block break-all rounded-lg border border-border bg-secondary px-4 py-3 text-xs",children:s||o("settings.file.unknown")}),e.jsx("div",{className:"rounded-lg border border-border bg-secondary px-4 py-3 text-xs text-muted-foreground",children:o("help.note")})]})})}function Ft({cleaning:s,clearingAll:t,onOpenCleanup:n,onOpenClearAll:o,sectionRef:l}){const{t:c}=R();return e.jsx(A,{id:"section-cleanup",ref:l,children:e.jsxs(L,{className:"space-y-4 pt-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold",children:c("settings.sections.cleanup")}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:c("settings.cleanup.description")})]}),e.jsx("div",{className:"rounded-lg border border-border bg-secondary px-4 py-3 text-xs text-muted-foreground",children:c("settings.cleanup.confirmCleanup")}),e.jsxs("div",{className:"grid gap-4 lg:grid-cols-2",children:[e.jsx("div",{className:"rounded-lg border border-[hsl(var(--warning)/0.3)] bg-[hsl(var(--warning-bg))] p-4",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx(E,{variant:"warning",children:c("settings.cleanup.softLabel")}),e.jsx("p",{className:"text-sm font-medium",children:c("settings.cleanup.softTitle")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:c("settings.cleanup.softDescription")}),e.jsx(k,{variant:"outline",onClick:n,disabled:s,className:"w-full sm:w-auto",children:c(s?"common.actions.cleaning":"common.actions.cleanup")})]})}),e.jsx("div",{className:"rounded-lg border border-destructive/30 bg-destructive/5 p-4",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx(E,{variant:"outline",className:"border-destructive/40 bg-destructive/10 text-destructive",children:c("settings.cleanup.hardLabel")}),e.jsx("p",{className:"text-sm font-medium",children:c("settings.cleanup.hardTitle")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:c("settings.cleanup.clearAllWarning")}),e.jsx(k,{variant:"destructive",onClick:o,disabled:t,className:"w-full sm:w-auto",children:c(t?"settings.cleanup.clearingAll":"settings.cleanup.clearAll")})]})})]})]})})}function Ht({isAuthDirty:s,isConfigDirty:t,protocolChangesPending:n,onAuthReset:o,onAuthSave:l,onReset:c,onSave:a,saving:i,savingAuth:h}){const{t:p}=R();return!s&&!t?null:e.jsxs("div",{className:"sticky bottom-4 z-20 flex flex-col gap-3 rounded-lg border border-primary/20 bg-card p-4 shadow-lg backdrop-blur-sm md:flex-row md:items-center md:justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(E,{variant:"secondary",children:p("modelManagement.actions.unsaved")}),t?e.jsx(E,{variant:"outline",children:p("settings.sections.basics")}):null,s?e.jsx(E,{variant:"outline",children:p("settings.sections.security")}):null,n?e.jsx(E,{variant:"outline",className:"border-amber-300 text-amber-700 dark:border-amber-700 dark:text-amber-300",children:p("settings.sections.protocol")}):null]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:p(n?"settings.toast.protocolRestartRequired":"modelManagement.actions.footerDirtyHint")})]}),e.jsxs("div",{className:"grid gap-2 sm:grid-cols-2 lg:flex lg:flex-wrap lg:items-center",children:[s?e.jsxs(e.Fragment,{children:[e.jsx(k,{variant:"outline",onClick:o,disabled:h,className:"w-full lg:w-auto",children:p("common.actions.reset")}),e.jsx(k,{onClick:l,disabled:h,className:"w-full lg:w-auto",children:p(h?"common.actions.saving":"settings.auth.actions.save")})]}):null,t?e.jsxs(e.Fragment,{children:[e.jsx(k,{variant:"outline",onClick:c,disabled:i,className:"w-full lg:w-auto",children:p("common.actions.reset")}),e.jsx(k,{onClick:a,disabled:i,className:"w-full lg:w-auto",children:p(i?"common.actions.saving":"common.actions.save")})]}):null]})]})}function U({label:s,value:t,helper:n,mono:o=!1}){return e.jsxs("div",{className:"rounded-lg border border-border bg-card px-4 py-3",children:[e.jsx("p",{className:"text-[11px] font-medium uppercase tracking-wider text-muted-foreground",children:s}),e.jsx("p",{className:M("mt-2 text-sm font-semibold text-foreground",o&&"break-all font-mono text-xs"),children:t}),e.jsx("p",{className:"mt-2 text-xs text-muted-foreground",children:n})]})}function X({label:s,value:t}){return e.jsxs("div",{className:"rounded-lg border border-border bg-secondary px-3 py-2",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-[0.16em] text-muted-foreground",children:s}),e.jsx("p",{className:"mt-1 text-sm font-semibold text-foreground",children:t})]})}function Z({checked:s,className:t,hint:n,hintClassName:o,label:l,labelClassName:c,onCheckedChange:a}){return e.jsxs("div",{className:M("flex flex-col gap-4 rounded-lg border border-border bg-secondary p-4 sm:flex-row sm:items-center sm:justify-between",t),children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(v,{className:M("text-sm font-medium",c),children:l}),e.jsx("p",{className:M("text-xs text-muted-foreground",o),children:n})]}),e.jsx(B,{checked:s,onCheckedChange:a,className:"self-start sm:self-auto"})]})}function ee({label:s,onChange:t,placeholder:n,value:o}){return e.jsxs("div",{className:"space-y-2",children:[e.jsx(v,{children:s}),e.jsx(w,{value:o,onChange:l=>t(l.target.value),placeholder:n,className:"font-mono text-xs"})]})}const V={authStatusRequest(){return{url:"/api/auth/web",method:"GET"}},saveWebAuth:async s=>ft(vt.post("/api/auth/web",s)),cleanupLogs:async()=>Te({url:"/api/logs/cleanup",method:"POST"}),clearLogs:async()=>Te({url:"/api/logs/clear",method:"POST"})};function Dt(){const{t:s}=R(),{pushToast:t}=jt(),[n,o]=m.useState(te[0].id),l=m.useRef(new Map),c=m.useCallback(r=>{const g=l.current.get(r);g&&g.scrollIntoView({behavior:"smooth",block:"start"})},[]),a=m.useCallback(r=>g=>{g?l.current.set(r,g):l.current.delete(r)},[]),i=Me(_.config.info(),Oe.configInfoRequest()),h=Me(_.auth.web(),V.authStatusRequest()),p=Q({mutationFn:V.saveWebAuth,successToast:()=>({title:s("settings.auth.toast.success")}),errorToast:r=>({title:s("settings.auth.toast.failure",{message:r.message})}),invalidateKeys:[_.auth.web()]}),T=Q({mutationFn:V.cleanupLogs,successToast:r=>({title:r.deleted>0?s("settings.toast.cleanupSuccess",{count:r.deleted}):s("settings.toast.cleanupNone")}),errorToast:r=>({title:s("settings.toast.cleanupFailure",{message:r.message})})}),x=Q({mutationFn:V.clearLogs,successToast:r=>({title:s("settings.toast.clearAllSuccess",{logs:r.deleted,metrics:r.metricsCleared})}),errorToast:r=>({title:s("settings.toast.clearAllFailure",{message:r.message})})}),[d,N]=m.useState(null),[C,He]=m.useState(""),[u,H]=m.useState({port:"",host:"",logRetentionDays:"",logExportTimeoutSeconds:"60",storeRequestPayloads:!0,storeResponsePayloads:!0,logLevel:"info",bodyLimitMb:"10",enableRoutingFallback:!1,httpEnabled:!0,httpPort:"4100",httpHost:"127.0.0.1",httpsEnabled:!1,httpsPort:"4443",httpsHost:"127.0.0.1",httpsKeyPath:"",httpsCertPath:"",httpsCaPath:""}),[De,I]=m.useState({}),[Ke,se]=m.useState(!1),[qe,ae]=m.useState(!1),[Ve,ne]=m.useState(!1),[Be,Ie]=m.useState(!1),[$e,We]=m.useState(!1),[j,re]=m.useState(null),[b,D]=m.useState({enabled:!1,username:"",password:"",confirmPassword:""}),[Ge,K]=m.useState({}),[Je,le]=m.useState(!1),Qe=m.useMemo(()=>{if(!(d!=null&&d.defaults))return null;const r=[];return d.defaults.completion&&r.push(s("settings.defaults.completion",{model:d.defaults.completion})),d.defaults.reasoning&&r.push(s("settings.defaults.reasoning",{model:d.defaults.reasoning})),d.defaults.background&&r.push(s("settings.defaults.background",{model:d.defaults.background})),r.length>0?r.join(" | "):s("settings.defaults.none")},[d,s]),_e=m.useMemo(()=>u.httpEnabled&&u.httpsEnabled?s("settings.overview.values.httpAndHttps"):u.httpsEnabled?s("settings.overview.values.httpsOnly"):s("settings.overview.values.httpOnly"),[u.httpEnabled,u.httpsEnabled,s]),ze=m.useMemo(()=>b.enabled?j!=null&&j.hasPassword?b.username.trim()!==(j.username??""):!0:!1,[b.enabled,b.username,j]),O=m.useMemo(()=>d?z(d):null,[d]),Ye=m.useMemo(()=>O?JSON.stringify(u)!==JSON.stringify(O):!1,[u,O]),$=m.useMemo(()=>j?Y(j):null,[j]),Ue=m.useMemo(()=>$?JSON.stringify(b)!==JSON.stringify($):!1,[b,$]),Xe=m.useMemo(()=>O?["httpEnabled","httpPort","httpHost","httpsEnabled","httpsPort","httpsHost","httpsKeyPath","httpsCertPath","httpsCaPath","port","host"].some(g=>u[g]!==O[g]):!1,[u,O]);m.useEffect(()=>{i.data&&(N(i.data.config),He(i.data.path),H(z(i.data.config)))},[i.data]),m.useEffect(()=>{h.data&&(re(h.data),D(Y(h.data)),K({}))},[h.data]),m.useEffect(()=>{!i.isError||!i.error||t({title:s("settings.toast.loadFailure",{message:i.error.message}),variant:"error"})},[i.error,i.isError,t,s]),m.useEffect(()=>{!h.isError||!h.error||t({title:s("settings.toast.authLoadFailure",{message:h.error.message}),variant:"error"})},[h.error,h.isError,t,s]);const Ze=m.useCallback(r=>g=>{H(y=>({...y,[r]:g}))},[]),oe=m.useCallback(()=>{const r={};if(!u.httpEnabled&&!u.httpsEnabled&&(r.protocol=s("settings.validation.protocolRequired")),u.httpEnabled){const S=Number(u.httpPort);(!Number.isFinite(S)||S<1||S>65535)&&(r.httpPort=s("settings.validation.httpPort"))}if(u.httpsEnabled){const S=Number(u.httpsPort);(!Number.isFinite(S)||S<1||S>65535)&&(r.httpsPort=s("settings.validation.httpsPort")),(!u.httpsKeyPath||!u.httpsCertPath)&&(r.protocol=s("settings.validation.httpsCertificate"))}const g=Number(u.port);(!Number.isFinite(g)||g<1||g>65535)&&(r.port=s("settings.validation.port"));const y=Number(u.logRetentionDays);(!Number.isFinite(y)||y<1||y>365)&&(r.logRetentionDays=s("settings.validation.retention"));const P=Number(u.logExportTimeoutSeconds);(!Number.isFinite(P)||P<5||P>600)&&(r.logExportTimeoutSeconds=s("settings.validation.logExportTimeout"));const F=Number(u.bodyLimitMb);return(!Number.isFinite(F)||F<1||F>2048)&&(r.bodyLimitMb=s("settings.validation.bodyLimit")),I(r),Object.keys(r).length===0},[u,s]),ie=m.useCallback(()=>{const r={},g=b.username.trim(),y=j?g!==(j.username??""):!0,P=b.enabled&&(!(j!=null&&j.hasPassword)||y);return b.enabled&&!g&&(r.username=s("settings.auth.validation.username")),b.password&&b.password.length<6&&(r.password=s("settings.auth.validation.minLength")),P&&!b.password&&(r.password=s("settings.auth.validation.passwordRequired")),(b.password||b.confirmPassword)&&b.password!==b.confirmPassword&&(r.confirmPassword=s("settings.auth.validation.confirmMismatch")),K(r),Object.keys(r).length===0},[b,j,s]),et=m.useCallback(async()=>{var r,g,y,P,F,S,ce,de,ue,me,pe,he,ge,xe,be,fe,ve,je,ye,Ne,we,Ce,Pe,ke,Se,Re;if(!d){t({title:s("settings.toast.loadFailure",{message:s("settings.toast.missingConfig")}),variant:"error"});return}if(oe()){se(!0);try{const q=Number(u.port),ot=Number(u.logRetentionDays),it=Number(u.logExportTimeoutSeconds),ct=Number(u.bodyLimitMb),f={...d,http:{enabled:u.httpEnabled,port:Number(u.httpPort),host:u.httpHost.trim()||"127.0.0.1"},https:{enabled:u.httpsEnabled,port:Number(u.httpsPort),host:u.httpsHost.trim()||"127.0.0.1",keyPath:u.httpsKeyPath.trim(),certPath:u.httpsCertPath.trim(),caPath:u.httpsCaPath.trim()||void 0},port:q,host:u.host.trim()||void 0,logRetentionDays:ot,logExportTimeoutSeconds:Math.min(Math.max(Math.round(it),5),600),storeRequestPayloads:u.storeRequestPayloads,storeResponsePayloads:u.storeResponsePayloads,logLevel:u.logLevel,bodyLimit:Math.max(1,Math.floor(ct*1024*1024)),enableRoutingFallback:u.enableRoutingFallback};delete f.requestLogging,delete f.responseLogging;const Ee={...f};delete Ee.webAuth,await Oe.saveConfig(Ee),N({...f,webAuth:d.webAuth});const Ae=G=>(G==null?void 0:G.trim())||void 0,dt=d.port??((r=d.http)==null?void 0:r.port)??4100,ut=f.port??((g=f.http)==null?void 0:g.port)??4100,mt=((y=d.host)==null?void 0:y.trim())||((F=(P=d.http)==null?void 0:P.host)==null?void 0:F.trim())||"127.0.0.1",pt=((S=f.host)==null?void 0:S.trim())||((de=(ce=f.http)==null?void 0:ce.host)==null?void 0:de.trim())||"127.0.0.1",ht=dt!==ut||mt!==pt||((ue=d.http)==null?void 0:ue.enabled)!==((me=f.http)==null?void 0:me.enabled)||((pe=d.http)==null?void 0:pe.port)!==((he=f.http)==null?void 0:he.port)||(((ge=d.http)==null?void 0:ge.host)??d.host??"127.0.0.1")!==(((xe=f.http)==null?void 0:xe.host)??f.host??"127.0.0.1")||((be=d.https)==null?void 0:be.enabled)!==((fe=f.https)==null?void 0:fe.enabled)||((ve=d.https)==null?void 0:ve.port)!==((je=f.https)==null?void 0:je.port)||(((ye=d.https)==null?void 0:ye.host)??d.host??"127.0.0.1")!==(((Ne=f.https)==null?void 0:Ne.host)??f.host??"127.0.0.1")||((we=d.https)==null?void 0:we.keyPath)!==((Ce=f.https)==null?void 0:Ce.keyPath)||((Pe=d.https)==null?void 0:Pe.certPath)!==((ke=f.https)==null?void 0:ke.certPath)||Ae((Se=d.https)==null?void 0:Se.caPath)!==Ae((Re=f.https)==null?void 0:Re.caPath);t({title:s(ht?"settings.toast.protocolRestartRequired":"settings.toast.saveSuccess"),variant:"success"}),i.refetch()}catch(q){t({title:s("settings.toast.saveFailure",{message:q instanceof Error?q.message:"unknown"}),variant:"error"})}finally{se(!1)}}},[d,i,u,t,s,oe]),tt=m.useCallback(()=>{d&&(H(z(d)),I({}))},[d]),st=m.useCallback(async()=>{if(ie()){le(!0);try{const r={enabled:b.enabled,username:b.username.trim()||void 0};b.password&&(r.password=b.password);const g=await p.mutateAsync(r);g.auth&&(re(g.auth),D({enabled:g.auth.enabled,username:g.auth.username??"",password:"",confirmPassword:""}),K({})),h.refetch()}catch{}finally{le(!1)}}},[b,h,p,ie]),at=m.useCallback(()=>{j&&(D(Y(j)),K({}))},[j]),nt=m.useCallback(async()=>{if(!C){t({title:s("settings.toast.copyFailure",{message:s("settings.file.unknown")}),variant:"error"});return}try{await St(C),t({title:s("settings.toast.copySuccess"),variant:"success"})}catch(r){t({title:s("settings.toast.copyFailure",{message:r instanceof Error?r.message:"unknown"}),variant:"error"})}},[C,t,s]),rt=m.useCallback(async()=>{ae(!0);try{await T.mutateAsync()}catch{}finally{ae(!1)}},[T]),lt=m.useCallback(async()=>{ne(!0);try{await x.mutateAsync()}catch{}finally{ne(!1)}},[x]),W=i.isPending||!d&&i.isFetching;return m.useEffect(()=>{if(W)return;const r=Array.from(l.current.values());if(r.length===0)return;const g=new IntersectionObserver(y=>{for(const P of y)if(P.isIntersecting){o(P.target.id);break}},{rootMargin:"-80px 0px -60% 0px",threshold:0});for(const y of r)g.observe(y);return()=>g.disconnect()},[W]),{activeSection:n,authErrors:Ge,authForm:b,authQuery:h,authSettings:j,clearingAll:Ve,cleaning:qe,config:d,configPath:C,configQuery:i,confirmCleanupOpen:Be,confirmClearAllOpen:$e,defaultsSummary:Qe,errors:De,form:u,handleAuthReset:at,handleAuthSave:st,handleCleanupLogs:rt,handleClearAllLogs:lt,handleCopyPath:nt,handleInputChange:Ze,handleReset:tt,handleSave:et,handleSectionClick:c,isAuthDirty:Ue,isConfigDirty:Ye,isLoading:W,needsPassword:ze,protocolSummaryLabel:_e,protocolChangesPending:Xe,saving:Ke,savingAuth:Je,sectionRefs:l,setAuthForm:D,setConfirmCleanupOpen:Ie,setConfirmClearAllOpen:We,setErrors:I,setForm:H,setSectionRef:a,t:s}}function as(){var l,c;const{t:s}=R(),t=Dt(),n=Number(t.isConfigDirty)+Number(t.isAuthDirty),o=t.protocolChangesPending?s("settings.protocol.restartHint"):s("settings.overview.description");return e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx(yt,{icon:e.jsx(bt,{className:"h-5 w-5","aria-hidden":"true"}),title:s("settings.title"),description:s("settings.description"),eyebrow:"Gateway Controls",breadcrumb:"Gateway / Settings",helper:o,badge:n>0?s("settings.overview.unsavedCount",{count:n}):void 0,actions:t.config?e.jsxs("div",{className:"flex w-full flex-col gap-2 sm:w-auto sm:flex-row sm:items-center",children:[e.jsx("div",{className:"rounded-lg border border-border bg-secondary px-3 py-2 text-xs text-muted-foreground",children:t.protocolChangesPending?s("settings.protocol.restartWarning"):s("common.status.success")}),e.jsx(k,{variant:"outline",onClick:t.handleReset,disabled:t.saving||!t.isConfigDirty,className:"w-full sm:w-auto",children:s("common.actions.reset")}),e.jsx(k,{onClick:()=>void t.handleSave(),disabled:t.saving||!t.isConfigDirty,className:"w-full sm:w-auto",children:t.saving?s("common.actions.saving"):s("common.actions.save")})]}):null}),t.isLoading?e.jsx(A,{children:e.jsx(L,{className:"flex min-h-[220px] items-center justify-center",children:e.jsx(Fe,{})})}):t.config?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid gap-6 xl:grid-cols-[200px_1fr]",children:[e.jsx(Et,{activeSection:t.activeSection,onSelectSection:t.handleSectionClick}),e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx(At,{configPath:t.configPath,defaultsSummary:t.defaultsSummary,form:t.form,protocolSummaryLabel:t.protocolSummaryLabel,protocolChangesPending:t.protocolChangesPending,isAuthDirty:t.isAuthDirty,isConfigDirty:t.isConfigDirty,authEnabled:((l=t.authSettings)==null?void 0:l.enabled)??!1,authUsername:(c=t.authSettings)==null?void 0:c.username}),e.jsx(Lt,{defaultsSummary:t.defaultsSummary,errors:t.errors,form:t.form,onInputChange:t.handleInputChange,onSetForm:t.setForm,sectionRef:t.setSectionRef("section-basics")}),e.jsx(Tt,{errors:t.errors,form:t.form,onSetForm:t.setForm,sectionRef:t.setSectionRef("section-protocol")}),e.jsx(Mt,{authErrors:t.authErrors,authForm:t.authForm,authLoading:t.authQuery.isPending||!t.authSettings&&t.authQuery.isFetching,authSettings:t.authSettings,needsPassword:t.needsPassword,onAuthReset:t.handleAuthReset,onAuthSave:()=>void t.handleAuthSave(),onSetAuthForm:t.setAuthForm,savingAuth:t.savingAuth,isAuthDirty:t.isAuthDirty,sectionRef:t.setSectionRef("section-security")}),e.jsx(Ot,{configPath:t.configPath,onCopyPath:()=>void t.handleCopyPath(),sectionRef:t.setSectionRef("section-config-file")}),e.jsx(Ft,{cleaning:t.cleaning,clearingAll:t.clearingAll,onOpenCleanup:()=>t.setConfirmCleanupOpen(!0),onOpenClearAll:()=>t.setConfirmClearAllOpen(!0),sectionRef:t.setSectionRef("section-cleanup")})]})]}),e.jsx(Ht,{isAuthDirty:t.isAuthDirty,isConfigDirty:t.isConfigDirty,protocolChangesPending:t.protocolChangesPending,onAuthReset:t.handleAuthReset,onAuthSave:()=>void t.handleAuthSave(),onReset:t.handleReset,onSave:()=>void t.handleSave(),saving:t.saving,savingAuth:t.savingAuth})]}):e.jsx(A,{children:e.jsx(L,{className:"pt-6",children:e.jsx("p",{className:"text-sm font-medium text-destructive",children:s("settings.toast.missingConfig")})})}),e.jsx(Le,{open:t.confirmCleanupOpen,onOpenChange:a=>{!a&&!t.cleaning&&t.setConfirmCleanupOpen(!1)},title:s("settings.cleanup.confirmTitle"),description:s("settings.cleanup.confirmDescription"),confirmLabel:t.cleaning?s("common.actions.cleaning"):s("common.actions.cleanup"),cancelLabel:s("common.actions.cancel"),loading:t.cleaning,onConfirm:async()=>{await t.handleCleanupLogs(),t.setConfirmCleanupOpen(!1)}}),e.jsx(Le,{open:t.confirmClearAllOpen,onOpenChange:a=>{!a&&!t.clearingAll&&t.setConfirmClearAllOpen(!1)},title:s("settings.cleanup.clearAllTitle"),description:s("settings.cleanup.clearAllWarning"),confirmLabel:t.clearingAll?s("settings.cleanup.clearingAll"):s("settings.cleanup.clearAll"),cancelLabel:s("common.actions.cancel"),loading:t.clearingAll,onConfirm:async()=>{await t.handleClearAllLogs(),t.setConfirmClearAllOpen(!1)}})]})}export{as as default};