@chenpu17/cc-gw 0.8.9 → 0.8.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +5 -5
- package/src/web/dist/assets/{About-DADVPUhW.js → About-BXBR_bL5.js} +1 -1
- package/src/web/dist/assets/{ApiKeys-DdFhoA4z.js → ApiKeys-Bc7INW0n.js} +1 -1
- package/src/web/dist/assets/{ConfirmDialog-DopoB7CA.js → ConfirmDialog-CPNJmevF.js} +1 -1
- package/src/web/dist/assets/Dashboard-DdisKH--.js +1 -0
- package/src/web/dist/assets/{DialogShell-blgQezT9.js → DialogShell-C0EfvzaN.js} +1 -1
- package/src/web/dist/assets/{Events-UNpWTigu.js → Events-ChrSkBPR.js} +1 -1
- package/src/web/dist/assets/{Help-D1pNXm10.js → Help-CsahUtl5.js} +1 -1
- package/src/web/dist/assets/{Login-B_yWya4w.js → Login-B-oy31QU.js} +1 -1
- package/src/web/dist/assets/{Logs-DMxgWFjk.js → Logs-L88mrDoR.js} +1 -1
- package/src/web/dist/assets/ModelManagement-BEeket-Z.js +1 -0
- package/src/web/dist/assets/{PageHeader-C01S2XTN.js → PageHeader-bDiw2pSJ.js} +1 -1
- package/src/web/dist/assets/{PageSection-CPPskzEi.js → PageSection-WDuhqLCi.js} +1 -1
- package/src/web/dist/assets/{PageState-Cntv0Sf4.js → PageState-KEq7s0Bk.js} +1 -1
- package/src/web/dist/assets/{Profiler-B24pf-u2.js → Profiler--DIXdL38.js} +1 -1
- package/src/web/dist/assets/{RoutingManagement-CiODaKbs.js → RoutingManagement-DgkHoHvd.js} +1 -1
- package/src/web/dist/assets/{Settings-DkDJipv4.js → Settings-B8oJpE9S.js} +1 -1
- package/src/web/dist/assets/{Skeleton-DgZEIS_E.js → Skeleton-BRLpX8rl.js} +1 -1
- package/src/web/dist/assets/{app-Bd27xdw7.js → app-BxSHC5_o.js} +3 -3
- package/src/web/dist/assets/{card-BMPheH9g.js → card-7EdLPk_C.js} +1 -1
- package/src/web/dist/assets/{gateway-BJysEYM8.js → gateway-mlUZb7iD.js} +1 -1
- package/src/web/dist/assets/{global-DOpF330e.css → global-BOV4QSBB.css} +1 -1
- package/src/web/dist/assets/{input-1_zNDnlx.js → input-BjD2rjIj.js} +1 -1
- package/src/web/dist/assets/{label-B5W3eu-E.js → label-DPJWPvWM.js} +1 -1
- package/src/web/dist/assets/{landing-DjqZxabN.js → landing-DV2hroBA.js} +1 -1
- package/src/web/dist/assets/package-CVSxn1pM.js +1 -0
- package/src/web/dist/assets/{popover-UGE5kTdI.js → popover-CMRfoAfg.js} +1 -1
- package/src/web/dist/assets/{queryKeys-DDTfNI_C.js → queryKeys-CsNzv19i.js} +1 -1
- package/src/web/dist/assets/{select-DJFQztdh.js → select-UI4HSm85.js} +1 -1
- package/src/web/dist/assets/{switch-BqheRBDw.js → switch-_3mhCfFY.js} +1 -1
- package/src/web/dist/assets/{table-C5nemz39.js → table-C1ufAZAv.js} +1 -1
- package/src/web/dist/assets/{useApiQuery-rsgixQ8H.js → useApiQuery-Y63AiXYK.js} +1 -1
- package/src/web/dist/assets/{useAppMutation-Cxb97sFV.js → useAppMutation-wWyqqlf8.js} +1 -1
- package/src/web/dist/assets/{useModelManagementState-M3Ms-cuY.js → useModelManagementState-BroT3Cj7.js} +1 -1
- package/src/web/dist/index.html +3 -3
- package/src/web/dist/landing.html +4 -4
- package/src/web/dist/assets/Dashboard-CBDC3lcl.js +0 -1
- package/src/web/dist/assets/ModelManagement-BTDHuojc.js +0 -1
- package/src/web/dist/assets/package-_RyhJB5F.js +0 -1
- /package/src/web/dist/assets/{global-B_AcmMvG.js → global-NDOUShP9.js} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as A,j as e,a7 as T,aD as me,aE as H,aa as P,af as xe,a0 as pe,S as ue,T as he}from"./vendor-LWJeAdU1.js";import{L as ge}from"./router-DspBTS8b.js";import{C as fe}from"./ConfirmDialog-DopoB7CA.js";import{P as je}from"./PageHeader-C01S2XTN.js";import{B as v,c as K,T as be,d as ve,e as Ne,f as ye}from"./app-Bd27xdw7.js";import{u as U}from"./useAppMutation-Cxb97sFV.js";import{I as S}from"./input-1_zNDnlx.js";import{L as M}from"./label-B5W3eu-E.js";import{S as W,a as X,b as J,c as Y,d as R}from"./select-DJFQztdh.js";import{S as we}from"./switch-BqheRBDw.js";import{q as Q,B as w}from"./queryKeys-DDTfNI_C.js";import{u as E}from"./i18n-B3N4Df3E.js";import{C as Z,a as ee}from"./card-BMPheH9g.js";import{c as O}from"./global-B_AcmMvG.js";import{D as ke,A as Me,a as Ce,b as Ee,c as De,d as Pe,e as Ae}from"./DialogShell-blgQezT9.js";import{P as Se,a as Te,b as Oe}from"./popover-UGE5kTdI.js";import{i as Re,g as _e,C as Le,O as $e,u as Ve}from"./useModelManagementState-M3Ms-cuY.js";import"./query-Cpxr1dul.js";import"./radix-bG5h1Ymq.js";import"./gateway-BJysEYM8.js";import"./useApiQuery-rsgixQ8H.js";const Be=["anthropic","openai-auto","openai-chat","openai-responses"];function ze({open:l,endpoint:s,onClose:g,onSuccess:r}){const{t:a}=E(),[p,m]=A.useState({id:"",label:"",paths:[{path:"",protocol:"openai-auto"}],enabled:!0});A.useEffect(()=>{if(s){const t=s.paths&&s.paths.length>0?s.paths:s.path&&s.protocol?[{path:s.path,protocol:s.protocol}]:[{path:"",protocol:"openai-auto"}];m({id:s.id,label:s.label,paths:t,enabled:s.enabled!==!1});return}m({id:"",label:"",paths:[{path:"",protocol:"openai-auto"}],enabled:!0})},[s,l]);const n=U({mutationFn:K.create,invalidateKeys:[Q.customEndpoints.all()],successToast:()=>({title:a("modelManagement.createEndpointSuccess")}),errorToast:t=>({title:a("modelManagement.createEndpointError",{error:t.message})}),onSuccess:async()=>{r(),g()}}),x=U({mutationFn:t=>K.update(t.id,t.updates),invalidateKeys:[Q.customEndpoints.all()],successToast:()=>({title:a("modelManagement.updateEndpointSuccess")}),errorToast:t=>({title:a("modelManagement.updateEndpointError",{error:t.message})}),onSuccess:async()=>{r(),g()}}),N=()=>{m(t=>({...t,paths:[...t.paths,{path:"",protocol:"anthropic"}]}))},d=t=>{p.paths.length!==1&&m(u=>({...u,paths:u.paths.filter((f,k)=>k!==t)}))},b=(t,u,f)=>{m(k=>{const C=[...k.paths];return C[t]={...C[t],[u]:f},{...k,paths:C}})},o=t=>{if(t==null||t.preventDefault(),!p.id.trim()||!p.label.trim())return;for(const f of p.paths)if(!f.path.trim())return;const u=p.paths.map(f=>({path:f.path.trim(),protocol:f.protocol}));if(s){x.mutate({id:s.id,updates:{label:p.label.trim(),paths:u,enabled:p.enabled}});return}n.mutate({id:p.id.trim(),label:p.label.trim(),paths:u,enabled:p.enabled})},c=n.isPending||x.isPending,i=p.paths.length===0?a("modelManagement.atLeastOnePath"):!p.id.trim()||!p.label.trim()?a("modelManagement.endpointValidationError"):p.paths.some(t=>!t.path.trim())?a("modelManagement.pathValidationError"):null;return l?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-40 bg-background/80 backdrop-blur-sm",onClick:g}),e.jsx("div",{className:"fixed inset-y-0 right-0 z-50 w-full max-w-md border-l border-border/45 bg-background/96 shadow-[var(--surface-shadow-lg)] backdrop-blur",children:e.jsxs("div",{className:"flex h-full flex-col",children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-border/45 bg-secondary/45 p-6 backdrop-blur-sm",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("h2",{className:"text-lg font-semibold tracking-[-0.02em]",children:a(s?"modelManagement.editEndpoint":"modelManagement.createEndpoint")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s?s.id:a("modelManagement.endpointRoutingHint")})]}),e.jsx(v,{variant:"ghost",size:"sm",onClick:g,className:"rounded-2xl bg-white/70",children:e.jsx(T,{className:"h-4 w-4"})})]}),e.jsxs("form",{onSubmit:o,className:"flex-1 space-y-6 overflow-y-auto p-6",children:[e.jsxs("div",{className:"grid gap-3 rounded-xl bg-secondary/50 p-4 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-[0.16em] text-muted-foreground",children:a("modelManagement.endpointId")}),e.jsx("p",{className:"truncate text-sm font-medium text-foreground",children:(s==null?void 0:s.id)||"new-endpoint"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-[0.16em] text-muted-foreground",children:a("modelManagement.endpointEnabled")}),e.jsx("p",{className:"text-sm font-medium text-foreground",children:p.enabled?a("common.status.enabled"):a("common.status.disabled")})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(M,{children:[a("modelManagement.endpointId")," ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(S,{value:p.id,onChange:t=>m(u=>({...u,id:t.target.value})),placeholder:a("modelManagement.endpointIdPlaceholder"),disabled:!!s,required:!0}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a("modelManagement.endpointIdHint")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(M,{children:[a("modelManagement.endpointLabel")," ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(S,{value:p.label,onChange:t=>m(u=>({...u,label:t.target.value})),placeholder:a("modelManagement.endpointLabelPlaceholder"),required:!0})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(M,{children:[a("modelManagement.endpointPaths")," ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsxs(v,{type:"button",variant:"ghost",size:"sm",onClick:N,children:[e.jsx(me,{className:"mr-1 h-3 w-3"}),a("modelManagement.addPath")]})]}),e.jsx("div",{className:"space-y-3",children:p.paths.map((t,u)=>e.jsxs("div",{className:"space-y-2 rounded-xl border border-transparent bg-card p-3 shadow-[var(--surface-shadow)]",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsx(S,{value:t.path,onChange:f=>b(u,"path",f.target.value),placeholder:a("modelManagement.endpointPathPlaceholder"),required:!0}),e.jsxs(W,{value:t.protocol,onValueChange:f=>b(u,"protocol",f),children:[e.jsx(X,{children:e.jsx(J,{})}),e.jsx(Y,{children:Be.map(f=>e.jsx(R,{value:f,children:a(f==="anthropic"?"modelManagement.protocolAnthropic":f==="openai-auto"?"modelManagement.protocolOpenAI":f==="openai-chat"?"modelManagement.protocolOpenAIChat":"modelManagement.protocolOpenAIResponses")},f))})]})]}),p.paths.length>1?e.jsx(v,{type:"button",variant:"ghost",size:"sm",onClick:()=>d(u),className:"text-destructive",children:e.jsx(T,{className:"h-4 w-4"})}):null]}),e.jsxs("div",{className:"space-y-1 text-xs text-muted-foreground",children:[u===0?e.jsx("p",{children:a("modelManagement.endpointPathHint")}):null,e.jsx("p",{children:a(`modelManagement.protocolHints.${t.protocol}`)})]})]},`${t.protocol}-${u}`))}),i?e.jsx("p",{className:"text-xs text-destructive",children:i}):null]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(we,{id:"enabled",checked:p.enabled,onCheckedChange:t=>m(u=>({...u,enabled:t}))}),e.jsx(M,{htmlFor:"enabled",children:a("modelManagement.endpointEnabled")})]}),s?null:e.jsx("div",{className:"rounded-xl bg-accent p-4",children:e.jsx("p",{className:"text-sm text-primary",children:a("modelManagement.endpointRoutingHint")})})]}),e.jsxs("div",{className:"flex gap-3 border-t border-border/45 bg-secondary/45 p-6 backdrop-blur-sm",children:[e.jsx(v,{variant:"outline",className:"flex-1",onClick:g,disabled:c,children:a("common.cancel")}),e.jsx(v,{className:"flex-1",onClick:()=>o(),disabled:c,children:a(c?"common.saving":s?"common.save":"common.create")})]})]})})]}):null}function _(l,s){return s(l==="anthropic"?"modelManagement.protocolAnthropic":l==="openai-chat"?"modelManagement.protocolOpenAIChat":l==="openai-responses"?"modelManagement.protocolOpenAIResponses":"modelManagement.protocolOpenAI")}function He({activeTab:l,customEndpoints:s,customTabs:g,isDirtyByEndpoint:r,onDeleteEndpoint:a,onEditEndpoint:p,onSelectTab:m,systemTabs:n}){const{t:x}=E(),N=[...n,...g].find(d=>d.key===l)??null;return e.jsx(Z,{className:"overflow-hidden rounded-[1.35rem] border border-white/70 bg-card/95 shadow-[0_22px_56px_-46px_rgba(15,23,42,0.22)]",children:e.jsxs(ee,{className:"space-y-4 p-4 sm:p-5",children:[e.jsxs("div",{className:"grid gap-3 lg:grid-cols-[minmax(0,1fr)_minmax(280px,0.6fr)]",children:[e.jsxs("div",{className:"rounded-[1.1rem] bg-secondary/60 p-2.5",children:[e.jsx("div",{className:"mb-2 flex items-center justify-between px-1",children:e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-[0.16em] text-muted-foreground/75",children:x("modelManagement.overview.providerAndSystem")})}),e.jsx("div",{className:"grid gap-2 sm:grid-cols-2 xl:grid-cols-3",children:n.map(d=>{const b=l===d.key,o=d.key!=="providers"&&r[d.key];return e.jsxs("button",{type:"button",onClick:()=>m(d.key),"aria-pressed":b,className:O("group flex min-h-[76px] flex-col justify-between rounded-[0.95rem] px-3 py-3 text-left transition-all",b?"bg-card text-foreground shadow-[0_14px_34px_-28px_rgba(15,23,42,0.3)] ring-1 ring-primary/10":"bg-transparent text-muted-foreground hover:bg-card/58 hover:text-foreground"),children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("span",{className:"block truncate text-[15px] font-semibold text-foreground",children:d.label}),e.jsx("div",{className:"mt-0.5 text-[10px] uppercase tracking-[0.14em] text-muted-foreground/70",children:d.key==="providers"?x("modelManagement.overview.providerPoolTag"):x("modelManagement.overview.systemEndpointTag")})]}),o?e.jsx("span",{className:"mt-1 h-2.5 w-2.5 rounded-full bg-amber-500"}):null]}),e.jsxs("div",{className:"mt-2 flex items-center justify-between gap-3",children:[e.jsx("span",{className:"line-clamp-1 text-xs text-muted-foreground/70",children:d.description}),b?e.jsx("span",{className:"inline-flex h-6 w-6 shrink-0 items-center justify-center rounded-full bg-primary/10 text-primary",children:e.jsx(H,{className:"h-3.5 w-3.5"})}):null]})]},d.key)})})]}),N?e.jsxs("div",{className:"flex min-h-[116px] flex-col justify-between rounded-[1.1rem] bg-[linear-gradient(135deg,hsl(var(--primary)/0.1),rgba(255,255,255,0.78))] p-4 ring-1 ring-primary/10 dark:bg-[linear-gradient(135deg,rgba(14,165,233,0.14),rgba(15,23,42,0.72))] dark:ring-white/10",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"inline-flex h-8 w-8 items-center justify-center rounded-xl bg-primary/10 text-primary",children:e.jsx(H,{className:"h-4 w-4"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-[0.16em] text-primary/75",children:"Active workspace"}),e.jsx("p",{className:"truncate text-sm font-semibold text-foreground",children:N.label})]})]}),e.jsx("p",{className:"mt-3 line-clamp-2 text-xs leading-5 text-muted-foreground",children:N.description})]}):null]}),g.length>0?e.jsxs("div",{className:"space-y-2.5",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-[0.16em] text-muted-foreground/75",children:x("modelManagement.overview.customEndpoints")}),e.jsx("div",{className:"grid gap-3 md:grid-cols-2 2xl:grid-cols-3",children:g.map(d=>{const b=l===d.key,o=r[d.key],c=s.find(i=>i.id===d.key);return e.jsxs("div",{className:O("group relative flex min-w-0 flex-col gap-2.5 overflow-hidden rounded-[1.05rem] border px-3 py-3 text-left transition-all sm:px-3.5",b?"border-primary/20 bg-secondary/80 text-foreground shadow-[0_14px_34px_-30px_rgba(59,130,246,0.32)]":"border-border/55 bg-background/42 hover:bg-secondary/50"),children:[e.jsxs("button",{type:"button",onClick:()=>m(d.key),"aria-pressed":b,className:"min-w-0 flex-1 text-left",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"truncate text-sm font-semibold text-foreground sm:text-[15px]",title:d.label,children:d.label}),o?e.jsx("span",{className:"h-2 w-2 rounded-full bg-amber-500"}):null]}),e.jsxs("div",{className:"mt-1.5 flex items-end justify-between gap-3",children:[e.jsx("p",{className:"line-clamp-2 text-[11px] leading-4.5 text-muted-foreground/72 sm:line-clamp-1 sm:text-xs",children:d.description}),b?e.jsx("span",{className:"inline-flex h-6 w-6 shrink-0 items-center justify-center rounded-full bg-primary/10 text-primary",children:e.jsx(H,{className:"h-3.5 w-3.5"})}):null]})]}),e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-1.5",children:[e.jsx(w,{variant:(c==null?void 0:c.enabled)===!1?"secondary":"success",className:"rounded-full border-0 px-2 py-0.5 text-[10px]",children:(c==null?void 0:c.enabled)===!1?x("modelManagement.overview.endpointDisabled"):x("modelManagement.overview.endpointEnabled")}),(d.protocols??[]).slice(0,2).map(i=>e.jsx(w,{variant:"outline",className:"max-w-[130px] truncate rounded-full text-[10px]",title:_(i,x),children:_(i,x)},`${d.key}-${i}`))]}),e.jsxs("div",{className:"min-w-0 rounded-[0.8rem] bg-secondary/55 px-2.5 py-2",children:[e.jsx("p",{className:"mb-1 text-[10px] font-medium uppercase tracking-[0.14em] text-muted-foreground/70",children:x("modelManagement.overview.endpointPaths")}),e.jsx("div",{className:"space-y-1",children:Fe(c,x).map(i=>e.jsx("p",{className:"truncate text-xs font-medium text-foreground",title:i,children:i},i))})]}),e.jsxs("div",{className:"grid grid-cols-[1fr_auto] gap-2",children:[e.jsx(v,{variant:"ghost",size:"sm",className:"h-7 justify-start rounded-full px-2 text-[11px]",disabled:!c,onClick:()=>{c&&p(c)},children:x("common.edit")}),d.canDelete?e.jsx("button",{type:"button",onClick:i=>{i.stopPropagation(),c&&a({kind:"endpoint",endpoint:c})},className:"flex h-7 w-full items-center justify-center rounded-md text-muted-foreground transition hover:bg-destructive/10 hover:text-destructive sm:w-7",title:x("common.delete"),children:e.jsx(T,{className:"h-3.5 w-3.5"})}):null]}),d.canDelete?null:e.jsx("div",{className:"text-[11px] text-muted-foreground/70",children:x("modelManagement.overview.endpointManagedExternally")})]},d.key)})})]}):null]})})}function Fe(l,s){var g;if(!l)return[s("common.noData")];if((g=l.paths)!=null&&g.length){const r=l.paths.slice(0,2).map(a=>`${a.path} · ${_(a.protocol,s)}`);return l.paths.length>2&&r.push(s("modelManagement.overview.endpointMorePaths",{count:l.paths.length-2})),r}return l.path?[`${l.path} · ${_(l.protocol??"anthropic",s)}`]:[s("common.noData")]}function Ie({dialog:l,currentRoutes:s,onConfirm:g,onClose:r}){const{t:a}=E();if(!l)return null;const{endpoint:p,preset:m}=l,n=m.modelRoutes??{},x={};for(const i of s){const t=i.source.trim(),u=i.target.trim();t&&u&&(x[t]=u)}const N=new Set([...Object.keys(x),...Object.keys(n)]),d=[],b=[],o=[];for(const i of N){const t=i in x,u=i in n;u&&!t?d.push([i,n[i]]):t&&!u?b.push([i,x[i]]):t&&u&&x[i]!==n[i]&&o.push([i,x[i],n[i]])}const c=d.length>0||b.length>0||o.length>0;return e.jsx(ke,{open:!0,onOpenChange:i=>!i&&r(),children:e.jsxs(Me,{className:"max-w-2xl",children:[e.jsxs(Ce,{children:[e.jsx(Ee,{children:a("modelManagement.presets.diffTitle")}),e.jsx(De,{children:a("modelManagement.presets.diffDescription",{name:m.name})})]}),e.jsx(Pe,{children:c?e.jsxs("div",{className:"max-h-80 space-y-2 rounded-xl bg-secondary/50 p-3 text-sm",children:[d.map(([i,t])=>e.jsxs("div",{className:"flex items-center gap-2 rounded-xl bg-emerald-50 px-2 py-1.5 text-emerald-800 dark:bg-emerald-950 dark:text-emerald-200",children:[e.jsx(w,{variant:"outline",className:"border-emerald-300 text-xs dark:border-emerald-700",children:a("modelManagement.presets.diffAdded")}),e.jsx("span",{className:"truncate",children:i}),e.jsx(P,{className:"h-3 w-3 flex-shrink-0"}),e.jsx("span",{className:"truncate",children:t})]},`add-${i}`)),b.map(([i,t])=>e.jsxs("div",{className:"flex items-center gap-2 rounded-xl bg-red-50 px-2 py-1.5 text-red-800 dark:bg-red-950 dark:text-red-200",children:[e.jsx(w,{variant:"outline",className:"border-red-300 text-xs dark:border-red-700",children:a("modelManagement.presets.diffRemoved")}),e.jsx("span",{className:"truncate",children:i}),e.jsx(P,{className:"h-3 w-3 flex-shrink-0"}),e.jsx("span",{className:"truncate",children:t})]},`rm-${i}`)),o.map(([i,t,u])=>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(w,{variant:"outline",className:"border-amber-300 text-xs dark:border-amber-700",children:a("modelManagement.presets.diffChanged")}),e.jsx("span",{className:"truncate",children:i}),e.jsx(P,{className:"h-3 w-3 flex-shrink-0"}),e.jsx("span",{className:"truncate line-through opacity-60",children:t}),e.jsx(P,{className:"h-3 w-3 flex-shrink-0"}),e.jsx("span",{className:"truncate",children:u})]},`chg-${i}`))]}):e.jsx("p",{className:"rounded-xl bg-secondary/50 py-8 text-center text-sm text-muted-foreground",children:a("modelManagement.presets.diffEmpty")})}),e.jsxs(Ae,{children:[e.jsx(v,{variant:"outline",onClick:r,children:a("common.cancel")}),e.jsx(v,{onClick:()=>g(p,m),disabled:!c,children:a("modelManagement.presets.diffConfirm")})]})]})})}function qe({value:l,onChange:s,options:g,disabled:r,placeholder:a}){const{t:p}=E(),[m,n]=A.useState(!1),[x,N]=A.useState(""),d=A.useMemo(()=>{if(!x.trim())return g;const o=x.toLowerCase();return g.filter(c=>c.label.toLowerCase().includes(o)||c.value.toLowerCase().includes(o))},[g,x]),b=o=>{s(o),N(""),n(!1)};return e.jsxs(Se,{open:m,onOpenChange:o=>{n(o),o&&N("")},children:[e.jsx(Te,{asChild:!0,children:e.jsx(S,{value:l,onChange:o=>{s(o.target.value),N(o.target.value),m||n(!0)},onFocus:()=>{N(""),n(!0)},onClick:()=>{m||n(!0)},placeholder:a,disabled:r,autoComplete:"off"})}),e.jsx(Oe,{className:"max-h-60 w-[var(--radix-popover-trigger-width)] overflow-y-auto rounded-xl border border-[color:var(--surface-border)] bg-popover/96 p-1.5 shadow-[var(--surface-shadow-lg)] backdrop-blur",align:"start",onOpenAutoFocus:o=>o.preventDefault(),children:d.length===0?e.jsx("div",{className:"px-2 py-3 text-center text-xs text-muted-foreground",children:p("common.noMatches")}):d.map(o=>e.jsx("button",{type:"button",className:O("flex w-full items-center rounded-lg px-3 py-2 text-left text-sm transition-colors hover:bg-accent/80 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",o.value===l.trim()&&"bg-accent/90 text-accent-foreground"),onMouseDown:c=>{c.preventDefault(),b(o.value)},children:e.jsx("span",{className:"truncate",children:o.label})},o.value))})]})}function Ge({endpoint:l,tabs:s,customEndpoints:g,config:r,routes:a,routeError:p,savingRoute:m,isDirty:n,presets:x,presetName:N,presetError:d,savingPreset:b,applyingPreset:o,deletingPreset:c,presetsExpanded:i,savingClaudeValidation:t,providerModelOptions:u,onTogglePresetsExpanded:f,onPresetNameChange:k,onSavePreset:C,onRequestPresetDiff:se,onRequestDeletePreset:ae,onValidationModeChange:te,onRouteChange:F,onRemoveRoute:I,onAddSuggestion:ne,onAddRoute:re,onResetRoutes:le,onSaveRoutes:ie}){var G;const{t:h}=E(),y=s.find(j=>j.key===l),L=((G=y==null?void 0:y.protocols)==null?void 0:G.includes("anthropic"))??l==="anthropic"?Le:$e,oe=(y==null?void 0:y.label)??l;(y==null?void 0:y.isSystem)===!1?y.description:h(`settings.routing.descriptionByEndpoint.${l}`);const $=`route-source-${l}`,q=Re(l,g),V=_e(l,r,g),B=q?(V==null?void 0:V.mode)??"off":"off",de=new Set(a.map(j=>j.source.trim()).filter(Boolean)),ce=`modelManagement.claudeValidation.options.${B}.description`;return e.jsx(Z,{children:e.jsxs(ee,{className:"space-y-6 pt-6",children:[e.jsx("div",{className:"rounded-full bg-secondary px-4 py-3 text-xs text-muted-foreground",children:h("settings.routing.wildcardHint")}),q?e.jsx("div",{className:"rounded-xl border border-primary/12 bg-[linear-gradient(135deg,hsl(var(--primary)/0.08),hsl(var(--accent)/0.72))] p-4 shadow-[var(--surface-shadow)] dark:border-sky-300/12 dark:bg-[linear-gradient(135deg,rgba(14,165,233,0.12),rgba(15,23,42,0.72))]",children:e.jsxs("div",{className:"flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-sm font-medium text-primary dark:text-sky-100",children:h("modelManagement.claudeValidation.title")}),e.jsx("p",{className:"max-w-2xl text-xs leading-5 text-muted-foreground dark:text-slate-300",children:h("modelManagement.claudeValidation.description")})]}),e.jsxs("div",{className:"flex w-full max-w-xs flex-col gap-2 self-start sm:self-auto",children:[e.jsx(M,{className:"text-[11px] font-semibold uppercase tracking-[0.16em] text-primary/70 dark:text-sky-200/75",children:h("modelManagement.claudeValidation.modeLabel")}),e.jsxs(W,{value:B,onValueChange:j=>te(j),disabled:t,children:[e.jsx(X,{className:"border-primary/15 bg-card/90 dark:border-white/10 dark:bg-slate-950/50",children:e.jsx(J,{})}),e.jsxs(Y,{children:[e.jsx(R,{value:"off",children:h("modelManagement.claudeValidation.options.off.label")}),e.jsx(R,{value:"anthropic-strict",children:h("modelManagement.claudeValidation.options.anthropic-strict.label")}),e.jsx(R,{value:"claude-code",children:h("modelManagement.claudeValidation.options.claude-code.label")})]})]}),e.jsx("span",{className:O("text-xs",B==="off"?"text-muted-foreground dark:text-slate-400":"text-primary/80 dark:text-sky-200/80"),children:h(ce)})]})]})}):null,p?e.jsx("p",{className:"text-sm text-destructive",children:p}):null,e.jsx(Ke,{presets:x,presetName:N,presetError:d,savingPreset:b,applyingPreset:o,deletingPreset:c,expanded:i,onToggleExpanded:f,onPresetNameChange:k,onSavePreset:C,onRequestPresetDiff:se,onRequestDeletePreset:ae}),e.jsxs("div",{className:"space-y-3 rounded-xl bg-secondary/50 p-4",children:[e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(M,{className:"text-sm font-semibold text-foreground",children:h("modelManagement.routesEditorTitle")}),e.jsxs(w,{variant:"outline",children:[a.length," active"]})]}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:h("modelManagement.overview.routesEditorHint")})]}),e.jsxs("div",{className:"self-start rounded-full bg-card px-3 py-2 text-[11px] font-medium text-muted-foreground",children:["Active workspace · ",oe]})]}),a.length===0?e.jsxs("div",{className:"rounded-xl border-2 border-dashed border-border/30 bg-background/60 p-12 text-center text-sm text-muted-foreground",children:[e.jsx("p",{className:"font-medium",children:h("settings.routing.empty")}),e.jsx("p",{className:"mt-2 text-xs",children:h("modelManagement.emptyRoutesHint")})]}):e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"hidden grid-cols-[minmax(0,1fr)_auto_minmax(0,1fr)_auto] items-center gap-3 px-1 text-xs font-medium text-muted-foreground md:grid",children:[e.jsx("span",{children:h("settings.routing.source")}),e.jsx("span",{}),e.jsx("span",{children:h("settings.routing.target")}),e.jsx("span",{})]}),a.map((j,D)=>e.jsxs("div",{className:"rounded-xl bg-card p-3 shadow-sm",children:[e.jsxs("div",{className:"mb-3 flex items-center justify-between md:hidden",children:[e.jsxs(w,{variant:"outline",className:"text-[11px]",children:["#",D+1]}),e.jsx(v,{variant:"ghost",size:"icon",className:"h-8 w-8 text-muted-foreground hover:text-destructive",onClick:()=>I(j.id),disabled:m,children:e.jsx(T,{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(M,{className:"text-[11px] uppercase tracking-[0.16em] text-muted-foreground md:hidden",children:h("settings.routing.source")}),e.jsx(S,{value:j.source,onChange:z=>F(j.id,"source",z.target.value),placeholder:h("settings.routing.sourcePlaceholder"),list:$,disabled:m,"aria-label":`route-source-${D+1}`})]}),e.jsx(P,{className:"hidden h-4 w-4 flex-shrink-0 text-muted-foreground md:block"}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(M,{className:"text-[11px] uppercase tracking-[0.16em] text-muted-foreground md:hidden",children:h("settings.routing.target")}),e.jsx(qe,{value:j.target,onChange:z=>F(j.id,"target",z),options:u,disabled:m,placeholder:h("settings.routing.targetPlaceholder")})]}),e.jsx(v,{variant:"ghost",size:"icon",className:"hidden h-8 w-8 text-muted-foreground hover:text-destructive md:inline-flex",onClick:()=>I(j.id),disabled:m,children:e.jsx(T,{className:"h-4 w-4"})})]})]},j.id))]})]}),e.jsxs("div",{className:"flex flex-col gap-3 rounded-xl bg-card p-4 shadow-[var(--surface-shadow)] md:flex-row md:items-center md:justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-sm font-medium",children:h("modelManagement.actions.footerTitle")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:h(n?"modelManagement.actions.footerDirtyHint":"modelManagement.actions.footerSavedHint")})]}),e.jsxs("div",{className:"grid gap-2 sm:grid-cols-3 md:flex md:flex-wrap md:items-center",children:[e.jsx(v,{variant:"outline",size:"sm",onClick:re,disabled:m,className:"w-full",children:h("settings.routing.add")}),e.jsx(v,{variant:"outline",size:"sm",onClick:le,disabled:m||!n,className:"w-full",children:h("common.actions.reset")}),e.jsxs(v,{size:"sm",onClick:ie,disabled:m,className:"relative w-full",children:[h(m?"common.actions.saving":"modelManagement.actions.saveRoutes"),n?e.jsx("span",{className:"absolute -right-1 -top-1 h-2 w-2 rounded-full bg-amber-500"}):null]})]})]}),e.jsxs("div",{className:"space-y-3 rounded-xl bg-secondary/50 p-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(M,{className:"text-sm font-medium text-foreground",children:h("settings.routing.suggested")}),e.jsx(w,{variant:"outline",className:"text-[11px]",children:L.length})]}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:h("modelManagement.overview.suggestionHint")})]}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:L.map(j=>{const D=de.has(j);return e.jsx(v,{variant:D?"ghost":"outline",size:"sm",onClick:()=>ne(j),disabled:m||D,className:O("h-7 rounded-md px-2.5 text-[11px] font-normal",D?"opacity-45":"bg-background/70"),children:j},`${l}-${j}`)})})]}),e.jsx("datalist",{id:$,children:L.map(j=>e.jsx("option",{value:j},`${$}-${j}`))})]})})}function Ke({presets:l,presetName:s,presetError:g,savingPreset:r,applyingPreset:a,deletingPreset:p,expanded:m,onToggleExpanded:n,onPresetNameChange:x,onSavePreset:N,onRequestPresetDiff:d,onRequestDeletePreset:b}){const{t:o}=E();return e.jsxs("div",{className:"rounded-xl bg-card shadow-[var(--surface-shadow)]",children:[e.jsx("button",{type:"button",className:"flex w-full items-center justify-between gap-3 rounded-xl p-4 text-left transition-colors hover:bg-accent",onClick:n,children:e.jsxs("div",{className:"flex items-center gap-2",children:[m?e.jsx(xe,{className:"h-4 w-4"}):e.jsx(pe,{className:"h-4 w-4"}),e.jsx("h3",{className:"font-medium",children:o("modelManagement.presets.title")}),e.jsx(w,{variant:"secondary",className:"text-xs",children:l.length})]})}),m?e.jsxs("div",{className:"space-y-4 border-t border-border/45 px-4 pb-4 pt-3",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:o("modelManagement.presets.description")}),e.jsxs("div",{className:"flex flex-col gap-3 md:flex-row md:items-center",children:[e.jsx(S,{value:s,onChange:c=>x(c.target.value),placeholder:o("modelManagement.presets.namePlaceholder"),disabled:r,className:"w-full md:w-48"}),e.jsx(v,{onClick:N,disabled:r,className:"w-full md:w-auto",children:o(r?"modelManagement.presets.saving":"modelManagement.presets.save")})]}),g?e.jsx("p",{className:"text-sm text-destructive",children:g}):null,l.length===0?e.jsx("p",{className:"py-4 text-center text-sm text-muted-foreground",children:o("modelManagement.presets.empty")}):e.jsx(be,{children:e.jsx("div",{className:"grid gap-2 sm:grid-cols-2 lg:grid-cols-3",children:l.map(c=>{const i=a===c.name,t=p===c.name,u=Object.entries(c.modelRoutes??{}),f=u.length;return e.jsxs("div",{className:"flex flex-col gap-3 rounded-xl bg-secondary/50 px-4 py-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs(ve,{children:[e.jsx(Ne,{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:c.name}),e.jsx(w,{variant:"outline",className:"mt-1 text-xs",children:f>0?o("modelManagement.presets.rulesCount",{count:f}):o("modelManagement.presets.noRules")})]})}),f>0?e.jsx(ye,{side:"bottom",className:"max-w-xs",children:e.jsxs("div",{className:"space-y-1 text-xs",children:[u.slice(0,5).map(([k,C])=>e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"truncate",children:k}),e.jsx(P,{className:"h-3 w-3 flex-shrink-0"}),e.jsx("span",{className:"truncate",children:C})]},k)),f>5?e.jsxs("div",{className:"text-muted-foreground",children:["…+",f-5]}):null]})}):null]}),e.jsxs("div",{className:"grid flex-shrink-0 gap-2 sm:flex sm:items-center",children:[e.jsx(v,{size:"sm",onClick:()=>d(c),disabled:i||t,className:"w-full sm:w-auto",children:o(i?"modelManagement.presets.applying":"modelManagement.presets.apply")}),e.jsx(v,{variant:"destructive",size:"sm",onClick:()=>b(c),disabled:t||i,className:"w-full sm:w-auto",children:o(t?"modelManagement.presets.deleting":"modelManagement.presets.delete")})]})]},c.name)})})})]}):null]})}function hs(){var p,m;const{t:l}=E(),s=Ve(),g=s.systemTabs.filter(n=>n.key!=="providers"),r=s.activeTab==="providers"?"anthropic":s.activeTab,a=s.tabs.find(n=>n.key===r)??null;return A.useEffect(()=>{s.activeTab==="providers"&&s.setActiveTab("anthropic")},[s.activeTab,s.setActiveTab]),e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx(je,{icon:e.jsx(he,{className:"h-5 w-5","aria-hidden":"true"}),title:l("routingManagement.title"),description:l("routingManagement.description"),eyebrow:l("routingManagement.eyebrow"),breadcrumb:"Gateway / Routing",badge:(a==null?void 0:a.label)??r,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.jsx(v,{asChild:!0,variant:"outline",className:"w-full sm:w-auto",children:e.jsxs(ge,{to:"/models",children:[e.jsx(ue,{className:"h-4 w-4","aria-hidden":"true"}),l("nav.models")]})}),e.jsx(v,{onClick:s.handleOpenCreateEndpoint,className:"w-full sm:w-auto",children:l("modelManagement.addEndpoint")})]})}),e.jsx(He,{activeTab:r,customEndpoints:s.customEndpoints,customTabs:s.customTabs,isDirtyByEndpoint:s.isDirtyByEndpoint,onDeleteEndpoint:s.setConfirmAction,onEditEndpoint:s.handleOpenEditEndpoint,onSelectTab:s.setActiveTab,systemTabs:g}),e.jsx(Ge,{endpoint:r,applyingPreset:((p=s.applyingPreset)==null?void 0:p.endpoint)===r?s.applyingPreset.name:null,config:s.config,customEndpoints:s.customEndpoints,deletingPreset:((m=s.deletingPreset)==null?void 0:m.endpoint)===r?s.deletingPreset.name:null,isDirty:s.isDirtyByEndpoint[r]??!1,onAddRoute:()=>s.handleAddRoute(r),onAddSuggestion:n=>s.handleAddSuggestion(r,n),onPresetNameChange:n=>s.handlePresetNameChange(r,n),onRequestDeletePreset:n=>s.setConfirmAction({kind:"preset",endpoint:r,preset:n}),onRequestPresetDiff:n=>s.setPresetDiffDialog({endpoint:r,preset:n}),onRemoveRoute:n=>s.handleRemoveRoute(r,n),onResetRoutes:()=>s.handleResetRoutes(r),onRouteChange:(n,x,N)=>s.handleRouteChange(r,n,x,N),onSavePreset:()=>void s.handleSavePreset(r),onSaveRoutes:()=>void s.handleSaveRoutes(r),onValidationModeChange:n=>void s.handleValidationModeChange(r,n),onTogglePresetsExpanded:()=>s.setPresetsExpanded(n=>({...n,[r]:!n[r]})),presetError:s.presetErrorByEndpoint[r],presetName:s.presetNameByEndpoint[r]??"",presets:s.presetsByEndpoint[r]??[],presetsExpanded:s.presetsExpanded[r]===!0,providerModelOptions:s.providerModelOptions,routeError:s.routeError[r],routes:s.routesByEndpoint[r]||[],savingClaudeValidation:s.savingClaudeValidation,savingPreset:s.savingPresetFor===r,savingRoute:s.savingRouteFor===r,tabs:s.tabs.filter(n=>n.key!=="providers")}),e.jsx(ze,{open:s.endpointDrawerOpen,endpoint:s.editingEndpoint,onClose:()=>{s.setEndpointDrawerOpen(!1),s.setEditingEndpoint(void 0)},onSuccess:()=>{s.configQuery.refetch()}}),e.jsx(Ie,{dialog:s.presetDiffDialog,currentRoutes:s.presetDiffDialog?s.routesByEndpoint[s.presetDiffDialog.endpoint]||[]:[],onConfirm:(n,x)=>{s.setPresetDiffDialog(null),s.handleApplyPreset(n,x)},onClose:()=>s.setPresetDiffDialog(null)}),e.jsx(fe,{open:!!s.confirmAction,onOpenChange:n=>{!n&&!s.confirmingAction&&s.setConfirmAction(null)},title:s.confirmDialogTitle,description:s.confirmDialogDescription,confirmLabel:s.confirmingAction?l("common.actions.loading"):l("common.delete"),cancelLabel:l("common.actions.cancel"),loading:s.confirmingAction,onConfirm:s.handleConfirmDialog,children:s.confirmDialogName?e.jsx("div",{className:"rounded-lg bg-destructive/5 px-3 py-2 font-mono text-xs text-foreground ring-1 ring-destructive/20",children:s.confirmDialogName}):null})]})}export{hs as default};
|
|
1
|
+
import{r as A,j as e,a7 as T,aD as me,aE as H,aa as P,af as xe,a0 as pe,S as ue,T as he}from"./vendor-LWJeAdU1.js";import{L as ge}from"./router-DspBTS8b.js";import{C as fe}from"./ConfirmDialog-CPNJmevF.js";import{P as je}from"./PageHeader-bDiw2pSJ.js";import{B as v,c as K,T as be,d as ve,e as Ne,f as ye}from"./app-BxSHC5_o.js";import{u as U}from"./useAppMutation-wWyqqlf8.js";import{I as S}from"./input-BjD2rjIj.js";import{L as M}from"./label-DPJWPvWM.js";import{S as W,a as X,b as J,c as Y,d as R}from"./select-UI4HSm85.js";import{S as we}from"./switch-_3mhCfFY.js";import{q as Q,B as w}from"./queryKeys-CsNzv19i.js";import{u as E}from"./i18n-B3N4Df3E.js";import{C as Z,a as ee}from"./card-7EdLPk_C.js";import{c as O}from"./global-NDOUShP9.js";import{D as ke,A as Me,a as Ce,b as Ee,c as De,d as Pe,e as Ae}from"./DialogShell-C0EfvzaN.js";import{P as Se,a as Te,b as Oe}from"./popover-CMRfoAfg.js";import{i as Re,g as _e,C as Le,O as $e,u as Ve}from"./useModelManagementState-BroT3Cj7.js";import"./query-Cpxr1dul.js";import"./radix-bG5h1Ymq.js";import"./gateway-mlUZb7iD.js";import"./useApiQuery-Y63AiXYK.js";const Be=["anthropic","openai-auto","openai-chat","openai-responses"];function ze({open:l,endpoint:s,onClose:g,onSuccess:r}){const{t:a}=E(),[p,m]=A.useState({id:"",label:"",paths:[{path:"",protocol:"openai-auto"}],enabled:!0});A.useEffect(()=>{if(s){const t=s.paths&&s.paths.length>0?s.paths:s.path&&s.protocol?[{path:s.path,protocol:s.protocol}]:[{path:"",protocol:"openai-auto"}];m({id:s.id,label:s.label,paths:t,enabled:s.enabled!==!1});return}m({id:"",label:"",paths:[{path:"",protocol:"openai-auto"}],enabled:!0})},[s,l]);const n=U({mutationFn:K.create,invalidateKeys:[Q.customEndpoints.all()],successToast:()=>({title:a("modelManagement.createEndpointSuccess")}),errorToast:t=>({title:a("modelManagement.createEndpointError",{error:t.message})}),onSuccess:async()=>{r(),g()}}),x=U({mutationFn:t=>K.update(t.id,t.updates),invalidateKeys:[Q.customEndpoints.all()],successToast:()=>({title:a("modelManagement.updateEndpointSuccess")}),errorToast:t=>({title:a("modelManagement.updateEndpointError",{error:t.message})}),onSuccess:async()=>{r(),g()}}),N=()=>{m(t=>({...t,paths:[...t.paths,{path:"",protocol:"anthropic"}]}))},d=t=>{p.paths.length!==1&&m(u=>({...u,paths:u.paths.filter((f,k)=>k!==t)}))},b=(t,u,f)=>{m(k=>{const C=[...k.paths];return C[t]={...C[t],[u]:f},{...k,paths:C}})},o=t=>{if(t==null||t.preventDefault(),!p.id.trim()||!p.label.trim())return;for(const f of p.paths)if(!f.path.trim())return;const u=p.paths.map(f=>({path:f.path.trim(),protocol:f.protocol}));if(s){x.mutate({id:s.id,updates:{label:p.label.trim(),paths:u,enabled:p.enabled}});return}n.mutate({id:p.id.trim(),label:p.label.trim(),paths:u,enabled:p.enabled})},c=n.isPending||x.isPending,i=p.paths.length===0?a("modelManagement.atLeastOnePath"):!p.id.trim()||!p.label.trim()?a("modelManagement.endpointValidationError"):p.paths.some(t=>!t.path.trim())?a("modelManagement.pathValidationError"):null;return l?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-40 bg-background/80 backdrop-blur-sm",onClick:g}),e.jsx("div",{className:"fixed inset-y-0 right-0 z-50 w-full max-w-md border-l border-border/45 bg-background/96 shadow-[var(--surface-shadow-lg)] backdrop-blur",children:e.jsxs("div",{className:"flex h-full flex-col",children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-border/45 bg-secondary/45 p-6 backdrop-blur-sm",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("h2",{className:"text-lg font-semibold tracking-[-0.02em]",children:a(s?"modelManagement.editEndpoint":"modelManagement.createEndpoint")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s?s.id:a("modelManagement.endpointRoutingHint")})]}),e.jsx(v,{variant:"ghost",size:"sm",onClick:g,className:"rounded-2xl bg-white/70",children:e.jsx(T,{className:"h-4 w-4"})})]}),e.jsxs("form",{onSubmit:o,className:"flex-1 space-y-6 overflow-y-auto p-6",children:[e.jsxs("div",{className:"grid gap-3 rounded-xl bg-secondary/50 p-4 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-[0.16em] text-muted-foreground",children:a("modelManagement.endpointId")}),e.jsx("p",{className:"truncate text-sm font-medium text-foreground",children:(s==null?void 0:s.id)||"new-endpoint"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-[0.16em] text-muted-foreground",children:a("modelManagement.endpointEnabled")}),e.jsx("p",{className:"text-sm font-medium text-foreground",children:p.enabled?a("common.status.enabled"):a("common.status.disabled")})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(M,{children:[a("modelManagement.endpointId")," ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(S,{value:p.id,onChange:t=>m(u=>({...u,id:t.target.value})),placeholder:a("modelManagement.endpointIdPlaceholder"),disabled:!!s,required:!0}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a("modelManagement.endpointIdHint")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(M,{children:[a("modelManagement.endpointLabel")," ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(S,{value:p.label,onChange:t=>m(u=>({...u,label:t.target.value})),placeholder:a("modelManagement.endpointLabelPlaceholder"),required:!0})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(M,{children:[a("modelManagement.endpointPaths")," ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsxs(v,{type:"button",variant:"ghost",size:"sm",onClick:N,children:[e.jsx(me,{className:"mr-1 h-3 w-3"}),a("modelManagement.addPath")]})]}),e.jsx("div",{className:"space-y-3",children:p.paths.map((t,u)=>e.jsxs("div",{className:"space-y-2 rounded-xl border border-transparent bg-card p-3 shadow-[var(--surface-shadow)]",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsx(S,{value:t.path,onChange:f=>b(u,"path",f.target.value),placeholder:a("modelManagement.endpointPathPlaceholder"),required:!0}),e.jsxs(W,{value:t.protocol,onValueChange:f=>b(u,"protocol",f),children:[e.jsx(X,{children:e.jsx(J,{})}),e.jsx(Y,{children:Be.map(f=>e.jsx(R,{value:f,children:a(f==="anthropic"?"modelManagement.protocolAnthropic":f==="openai-auto"?"modelManagement.protocolOpenAI":f==="openai-chat"?"modelManagement.protocolOpenAIChat":"modelManagement.protocolOpenAIResponses")},f))})]})]}),p.paths.length>1?e.jsx(v,{type:"button",variant:"ghost",size:"sm",onClick:()=>d(u),className:"text-destructive",children:e.jsx(T,{className:"h-4 w-4"})}):null]}),e.jsxs("div",{className:"space-y-1 text-xs text-muted-foreground",children:[u===0?e.jsx("p",{children:a("modelManagement.endpointPathHint")}):null,e.jsx("p",{children:a(`modelManagement.protocolHints.${t.protocol}`)})]})]},`${t.protocol}-${u}`))}),i?e.jsx("p",{className:"text-xs text-destructive",children:i}):null]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(we,{id:"enabled",checked:p.enabled,onCheckedChange:t=>m(u=>({...u,enabled:t}))}),e.jsx(M,{htmlFor:"enabled",children:a("modelManagement.endpointEnabled")})]}),s?null:e.jsx("div",{className:"rounded-xl bg-accent p-4",children:e.jsx("p",{className:"text-sm text-primary",children:a("modelManagement.endpointRoutingHint")})})]}),e.jsxs("div",{className:"flex gap-3 border-t border-border/45 bg-secondary/45 p-6 backdrop-blur-sm",children:[e.jsx(v,{variant:"outline",className:"flex-1",onClick:g,disabled:c,children:a("common.cancel")}),e.jsx(v,{className:"flex-1",onClick:()=>o(),disabled:c,children:a(c?"common.saving":s?"common.save":"common.create")})]})]})})]}):null}function _(l,s){return s(l==="anthropic"?"modelManagement.protocolAnthropic":l==="openai-chat"?"modelManagement.protocolOpenAIChat":l==="openai-responses"?"modelManagement.protocolOpenAIResponses":"modelManagement.protocolOpenAI")}function He({activeTab:l,customEndpoints:s,customTabs:g,isDirtyByEndpoint:r,onDeleteEndpoint:a,onEditEndpoint:p,onSelectTab:m,systemTabs:n}){const{t:x}=E(),N=[...n,...g].find(d=>d.key===l)??null;return e.jsx(Z,{className:"overflow-hidden rounded-[1.35rem] border border-white/70 bg-card/95 shadow-[0_22px_56px_-46px_rgba(15,23,42,0.22)]",children:e.jsxs(ee,{className:"space-y-4 p-4 sm:p-5",children:[e.jsxs("div",{className:"grid gap-3 lg:grid-cols-[minmax(0,1fr)_minmax(280px,0.6fr)]",children:[e.jsxs("div",{className:"rounded-[1.1rem] bg-secondary/60 p-2.5",children:[e.jsx("div",{className:"mb-2 flex items-center justify-between px-1",children:e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-[0.16em] text-muted-foreground/75",children:x("modelManagement.overview.providerAndSystem")})}),e.jsx("div",{className:"grid gap-2 sm:grid-cols-2 xl:grid-cols-3",children:n.map(d=>{const b=l===d.key,o=d.key!=="providers"&&r[d.key];return e.jsxs("button",{type:"button",onClick:()=>m(d.key),"aria-pressed":b,className:O("group flex min-h-[76px] flex-col justify-between rounded-[0.95rem] px-3 py-3 text-left transition-all",b?"bg-card text-foreground shadow-[0_14px_34px_-28px_rgba(15,23,42,0.3)] ring-1 ring-primary/10":"bg-transparent text-muted-foreground hover:bg-card/58 hover:text-foreground"),children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("span",{className:"block truncate text-[15px] font-semibold text-foreground",children:d.label}),e.jsx("div",{className:"mt-0.5 text-[10px] uppercase tracking-[0.14em] text-muted-foreground/70",children:d.key==="providers"?x("modelManagement.overview.providerPoolTag"):x("modelManagement.overview.systemEndpointTag")})]}),o?e.jsx("span",{className:"mt-1 h-2.5 w-2.5 rounded-full bg-amber-500"}):null]}),e.jsxs("div",{className:"mt-2 flex items-center justify-between gap-3",children:[e.jsx("span",{className:"line-clamp-1 text-xs text-muted-foreground/70",children:d.description}),b?e.jsx("span",{className:"inline-flex h-6 w-6 shrink-0 items-center justify-center rounded-full bg-primary/10 text-primary",children:e.jsx(H,{className:"h-3.5 w-3.5"})}):null]})]},d.key)})})]}),N?e.jsxs("div",{className:"flex min-h-[116px] flex-col justify-between rounded-[1.1rem] bg-[linear-gradient(135deg,hsl(var(--primary)/0.1),rgba(255,255,255,0.78))] p-4 ring-1 ring-primary/10 dark:bg-[linear-gradient(135deg,rgba(14,165,233,0.14),rgba(15,23,42,0.72))] dark:ring-white/10",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"inline-flex h-8 w-8 items-center justify-center rounded-xl bg-primary/10 text-primary",children:e.jsx(H,{className:"h-4 w-4"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-[0.16em] text-primary/75",children:"Active workspace"}),e.jsx("p",{className:"truncate text-sm font-semibold text-foreground",children:N.label})]})]}),e.jsx("p",{className:"mt-3 line-clamp-2 text-xs leading-5 text-muted-foreground",children:N.description})]}):null]}),g.length>0?e.jsxs("div",{className:"space-y-2.5",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-[0.16em] text-muted-foreground/75",children:x("modelManagement.overview.customEndpoints")}),e.jsx("div",{className:"grid gap-3 md:grid-cols-2 2xl:grid-cols-3",children:g.map(d=>{const b=l===d.key,o=r[d.key],c=s.find(i=>i.id===d.key);return e.jsxs("div",{className:O("group relative flex min-w-0 flex-col gap-2.5 overflow-hidden rounded-[1.05rem] border px-3 py-3 text-left transition-all sm:px-3.5",b?"border-primary/20 bg-secondary/80 text-foreground shadow-[0_14px_34px_-30px_rgba(59,130,246,0.32)]":"border-border/55 bg-background/42 hover:bg-secondary/50"),children:[e.jsxs("button",{type:"button",onClick:()=>m(d.key),"aria-pressed":b,className:"min-w-0 flex-1 text-left",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"truncate text-sm font-semibold text-foreground sm:text-[15px]",title:d.label,children:d.label}),o?e.jsx("span",{className:"h-2 w-2 rounded-full bg-amber-500"}):null]}),e.jsxs("div",{className:"mt-1.5 flex items-end justify-between gap-3",children:[e.jsx("p",{className:"line-clamp-2 text-[11px] leading-4.5 text-muted-foreground/72 sm:line-clamp-1 sm:text-xs",children:d.description}),b?e.jsx("span",{className:"inline-flex h-6 w-6 shrink-0 items-center justify-center rounded-full bg-primary/10 text-primary",children:e.jsx(H,{className:"h-3.5 w-3.5"})}):null]})]}),e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-1.5",children:[e.jsx(w,{variant:(c==null?void 0:c.enabled)===!1?"secondary":"success",className:"rounded-full border-0 px-2 py-0.5 text-[10px]",children:(c==null?void 0:c.enabled)===!1?x("modelManagement.overview.endpointDisabled"):x("modelManagement.overview.endpointEnabled")}),(d.protocols??[]).slice(0,2).map(i=>e.jsx(w,{variant:"outline",className:"max-w-[130px] truncate rounded-full text-[10px]",title:_(i,x),children:_(i,x)},`${d.key}-${i}`))]}),e.jsxs("div",{className:"min-w-0 rounded-[0.8rem] bg-secondary/55 px-2.5 py-2",children:[e.jsx("p",{className:"mb-1 text-[10px] font-medium uppercase tracking-[0.14em] text-muted-foreground/70",children:x("modelManagement.overview.endpointPaths")}),e.jsx("div",{className:"space-y-1",children:Fe(c,x).map(i=>e.jsx("p",{className:"truncate text-xs font-medium text-foreground",title:i,children:i},i))})]}),e.jsxs("div",{className:"grid grid-cols-[1fr_auto] gap-2",children:[e.jsx(v,{variant:"ghost",size:"sm",className:"h-7 justify-start rounded-full px-2 text-[11px]",disabled:!c,onClick:()=>{c&&p(c)},children:x("common.edit")}),d.canDelete?e.jsx("button",{type:"button",onClick:i=>{i.stopPropagation(),c&&a({kind:"endpoint",endpoint:c})},className:"flex h-7 w-full items-center justify-center rounded-md text-muted-foreground transition hover:bg-destructive/10 hover:text-destructive sm:w-7",title:x("common.delete"),children:e.jsx(T,{className:"h-3.5 w-3.5"})}):null]}),d.canDelete?null:e.jsx("div",{className:"text-[11px] text-muted-foreground/70",children:x("modelManagement.overview.endpointManagedExternally")})]},d.key)})})]}):null]})})}function Fe(l,s){var g;if(!l)return[s("common.noData")];if((g=l.paths)!=null&&g.length){const r=l.paths.slice(0,2).map(a=>`${a.path} · ${_(a.protocol,s)}`);return l.paths.length>2&&r.push(s("modelManagement.overview.endpointMorePaths",{count:l.paths.length-2})),r}return l.path?[`${l.path} · ${_(l.protocol??"anthropic",s)}`]:[s("common.noData")]}function Ie({dialog:l,currentRoutes:s,onConfirm:g,onClose:r}){const{t:a}=E();if(!l)return null;const{endpoint:p,preset:m}=l,n=m.modelRoutes??{},x={};for(const i of s){const t=i.source.trim(),u=i.target.trim();t&&u&&(x[t]=u)}const N=new Set([...Object.keys(x),...Object.keys(n)]),d=[],b=[],o=[];for(const i of N){const t=i in x,u=i in n;u&&!t?d.push([i,n[i]]):t&&!u?b.push([i,x[i]]):t&&u&&x[i]!==n[i]&&o.push([i,x[i],n[i]])}const c=d.length>0||b.length>0||o.length>0;return e.jsx(ke,{open:!0,onOpenChange:i=>!i&&r(),children:e.jsxs(Me,{className:"max-w-2xl",children:[e.jsxs(Ce,{children:[e.jsx(Ee,{children:a("modelManagement.presets.diffTitle")}),e.jsx(De,{children:a("modelManagement.presets.diffDescription",{name:m.name})})]}),e.jsx(Pe,{children:c?e.jsxs("div",{className:"max-h-80 space-y-2 rounded-xl bg-secondary/50 p-3 text-sm",children:[d.map(([i,t])=>e.jsxs("div",{className:"flex items-center gap-2 rounded-xl bg-emerald-50 px-2 py-1.5 text-emerald-800 dark:bg-emerald-950 dark:text-emerald-200",children:[e.jsx(w,{variant:"outline",className:"border-emerald-300 text-xs dark:border-emerald-700",children:a("modelManagement.presets.diffAdded")}),e.jsx("span",{className:"truncate",children:i}),e.jsx(P,{className:"h-3 w-3 flex-shrink-0"}),e.jsx("span",{className:"truncate",children:t})]},`add-${i}`)),b.map(([i,t])=>e.jsxs("div",{className:"flex items-center gap-2 rounded-xl bg-red-50 px-2 py-1.5 text-red-800 dark:bg-red-950 dark:text-red-200",children:[e.jsx(w,{variant:"outline",className:"border-red-300 text-xs dark:border-red-700",children:a("modelManagement.presets.diffRemoved")}),e.jsx("span",{className:"truncate",children:i}),e.jsx(P,{className:"h-3 w-3 flex-shrink-0"}),e.jsx("span",{className:"truncate",children:t})]},`rm-${i}`)),o.map(([i,t,u])=>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(w,{variant:"outline",className:"border-amber-300 text-xs dark:border-amber-700",children:a("modelManagement.presets.diffChanged")}),e.jsx("span",{className:"truncate",children:i}),e.jsx(P,{className:"h-3 w-3 flex-shrink-0"}),e.jsx("span",{className:"truncate line-through opacity-60",children:t}),e.jsx(P,{className:"h-3 w-3 flex-shrink-0"}),e.jsx("span",{className:"truncate",children:u})]},`chg-${i}`))]}):e.jsx("p",{className:"rounded-xl bg-secondary/50 py-8 text-center text-sm text-muted-foreground",children:a("modelManagement.presets.diffEmpty")})}),e.jsxs(Ae,{children:[e.jsx(v,{variant:"outline",onClick:r,children:a("common.cancel")}),e.jsx(v,{onClick:()=>g(p,m),disabled:!c,children:a("modelManagement.presets.diffConfirm")})]})]})})}function qe({value:l,onChange:s,options:g,disabled:r,placeholder:a}){const{t:p}=E(),[m,n]=A.useState(!1),[x,N]=A.useState(""),d=A.useMemo(()=>{if(!x.trim())return g;const o=x.toLowerCase();return g.filter(c=>c.label.toLowerCase().includes(o)||c.value.toLowerCase().includes(o))},[g,x]),b=o=>{s(o),N(""),n(!1)};return e.jsxs(Se,{open:m,onOpenChange:o=>{n(o),o&&N("")},children:[e.jsx(Te,{asChild:!0,children:e.jsx(S,{value:l,onChange:o=>{s(o.target.value),N(o.target.value),m||n(!0)},onFocus:()=>{N(""),n(!0)},onClick:()=>{m||n(!0)},placeholder:a,disabled:r,autoComplete:"off"})}),e.jsx(Oe,{className:"max-h-60 w-[var(--radix-popover-trigger-width)] overflow-y-auto rounded-xl border border-[color:var(--surface-border)] bg-popover/96 p-1.5 shadow-[var(--surface-shadow-lg)] backdrop-blur",align:"start",onOpenAutoFocus:o=>o.preventDefault(),children:d.length===0?e.jsx("div",{className:"px-2 py-3 text-center text-xs text-muted-foreground",children:p("common.noMatches")}):d.map(o=>e.jsx("button",{type:"button",className:O("flex w-full items-center rounded-lg px-3 py-2 text-left text-sm transition-colors hover:bg-accent/80 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",o.value===l.trim()&&"bg-accent/90 text-accent-foreground"),onMouseDown:c=>{c.preventDefault(),b(o.value)},children:e.jsx("span",{className:"truncate",children:o.label})},o.value))})]})}function Ge({endpoint:l,tabs:s,customEndpoints:g,config:r,routes:a,routeError:p,savingRoute:m,isDirty:n,presets:x,presetName:N,presetError:d,savingPreset:b,applyingPreset:o,deletingPreset:c,presetsExpanded:i,savingClaudeValidation:t,providerModelOptions:u,onTogglePresetsExpanded:f,onPresetNameChange:k,onSavePreset:C,onRequestPresetDiff:se,onRequestDeletePreset:ae,onValidationModeChange:te,onRouteChange:F,onRemoveRoute:I,onAddSuggestion:ne,onAddRoute:re,onResetRoutes:le,onSaveRoutes:ie}){var G;const{t:h}=E(),y=s.find(j=>j.key===l),L=((G=y==null?void 0:y.protocols)==null?void 0:G.includes("anthropic"))??l==="anthropic"?Le:$e,oe=(y==null?void 0:y.label)??l;(y==null?void 0:y.isSystem)===!1?y.description:h(`settings.routing.descriptionByEndpoint.${l}`);const $=`route-source-${l}`,q=Re(l,g),V=_e(l,r,g),B=q?(V==null?void 0:V.mode)??"off":"off",de=new Set(a.map(j=>j.source.trim()).filter(Boolean)),ce=`modelManagement.claudeValidation.options.${B}.description`;return e.jsx(Z,{children:e.jsxs(ee,{className:"space-y-6 pt-6",children:[e.jsx("div",{className:"rounded-full bg-secondary px-4 py-3 text-xs text-muted-foreground",children:h("settings.routing.wildcardHint")}),q?e.jsx("div",{className:"rounded-xl border border-primary/12 bg-[linear-gradient(135deg,hsl(var(--primary)/0.08),hsl(var(--accent)/0.72))] p-4 shadow-[var(--surface-shadow)] dark:border-sky-300/12 dark:bg-[linear-gradient(135deg,rgba(14,165,233,0.12),rgba(15,23,42,0.72))]",children:e.jsxs("div",{className:"flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-sm font-medium text-primary dark:text-sky-100",children:h("modelManagement.claudeValidation.title")}),e.jsx("p",{className:"max-w-2xl text-xs leading-5 text-muted-foreground dark:text-slate-300",children:h("modelManagement.claudeValidation.description")})]}),e.jsxs("div",{className:"flex w-full max-w-xs flex-col gap-2 self-start sm:self-auto",children:[e.jsx(M,{className:"text-[11px] font-semibold uppercase tracking-[0.16em] text-primary/70 dark:text-sky-200/75",children:h("modelManagement.claudeValidation.modeLabel")}),e.jsxs(W,{value:B,onValueChange:j=>te(j),disabled:t,children:[e.jsx(X,{className:"border-primary/15 bg-card/90 dark:border-white/10 dark:bg-slate-950/50",children:e.jsx(J,{})}),e.jsxs(Y,{children:[e.jsx(R,{value:"off",children:h("modelManagement.claudeValidation.options.off.label")}),e.jsx(R,{value:"anthropic-strict",children:h("modelManagement.claudeValidation.options.anthropic-strict.label")}),e.jsx(R,{value:"claude-code",children:h("modelManagement.claudeValidation.options.claude-code.label")})]})]}),e.jsx("span",{className:O("text-xs",B==="off"?"text-muted-foreground dark:text-slate-400":"text-primary/80 dark:text-sky-200/80"),children:h(ce)})]})]})}):null,p?e.jsx("p",{className:"text-sm text-destructive",children:p}):null,e.jsx(Ke,{presets:x,presetName:N,presetError:d,savingPreset:b,applyingPreset:o,deletingPreset:c,expanded:i,onToggleExpanded:f,onPresetNameChange:k,onSavePreset:C,onRequestPresetDiff:se,onRequestDeletePreset:ae}),e.jsxs("div",{className:"space-y-3 rounded-xl bg-secondary/50 p-4",children:[e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(M,{className:"text-sm font-semibold text-foreground",children:h("modelManagement.routesEditorTitle")}),e.jsxs(w,{variant:"outline",children:[a.length," active"]})]}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:h("modelManagement.overview.routesEditorHint")})]}),e.jsxs("div",{className:"self-start rounded-full bg-card px-3 py-2 text-[11px] font-medium text-muted-foreground",children:["Active workspace · ",oe]})]}),a.length===0?e.jsxs("div",{className:"rounded-xl border-2 border-dashed border-border/30 bg-background/60 p-12 text-center text-sm text-muted-foreground",children:[e.jsx("p",{className:"font-medium",children:h("settings.routing.empty")}),e.jsx("p",{className:"mt-2 text-xs",children:h("modelManagement.emptyRoutesHint")})]}):e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"hidden grid-cols-[minmax(0,1fr)_auto_minmax(0,1fr)_auto] items-center gap-3 px-1 text-xs font-medium text-muted-foreground md:grid",children:[e.jsx("span",{children:h("settings.routing.source")}),e.jsx("span",{}),e.jsx("span",{children:h("settings.routing.target")}),e.jsx("span",{})]}),a.map((j,D)=>e.jsxs("div",{className:"rounded-xl bg-card p-3 shadow-sm",children:[e.jsxs("div",{className:"mb-3 flex items-center justify-between md:hidden",children:[e.jsxs(w,{variant:"outline",className:"text-[11px]",children:["#",D+1]}),e.jsx(v,{variant:"ghost",size:"icon",className:"h-8 w-8 text-muted-foreground hover:text-destructive",onClick:()=>I(j.id),disabled:m,children:e.jsx(T,{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(M,{className:"text-[11px] uppercase tracking-[0.16em] text-muted-foreground md:hidden",children:h("settings.routing.source")}),e.jsx(S,{value:j.source,onChange:z=>F(j.id,"source",z.target.value),placeholder:h("settings.routing.sourcePlaceholder"),list:$,disabled:m,"aria-label":`route-source-${D+1}`})]}),e.jsx(P,{className:"hidden h-4 w-4 flex-shrink-0 text-muted-foreground md:block"}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(M,{className:"text-[11px] uppercase tracking-[0.16em] text-muted-foreground md:hidden",children:h("settings.routing.target")}),e.jsx(qe,{value:j.target,onChange:z=>F(j.id,"target",z),options:u,disabled:m,placeholder:h("settings.routing.targetPlaceholder")})]}),e.jsx(v,{variant:"ghost",size:"icon",className:"hidden h-8 w-8 text-muted-foreground hover:text-destructive md:inline-flex",onClick:()=>I(j.id),disabled:m,children:e.jsx(T,{className:"h-4 w-4"})})]})]},j.id))]})]}),e.jsxs("div",{className:"flex flex-col gap-3 rounded-xl bg-card p-4 shadow-[var(--surface-shadow)] md:flex-row md:items-center md:justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-sm font-medium",children:h("modelManagement.actions.footerTitle")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:h(n?"modelManagement.actions.footerDirtyHint":"modelManagement.actions.footerSavedHint")})]}),e.jsxs("div",{className:"grid gap-2 sm:grid-cols-3 md:flex md:flex-wrap md:items-center",children:[e.jsx(v,{variant:"outline",size:"sm",onClick:re,disabled:m,className:"w-full",children:h("settings.routing.add")}),e.jsx(v,{variant:"outline",size:"sm",onClick:le,disabled:m||!n,className:"w-full",children:h("common.actions.reset")}),e.jsxs(v,{size:"sm",onClick:ie,disabled:m,className:"relative w-full",children:[h(m?"common.actions.saving":"modelManagement.actions.saveRoutes"),n?e.jsx("span",{className:"absolute -right-1 -top-1 h-2 w-2 rounded-full bg-amber-500"}):null]})]})]}),e.jsxs("div",{className:"space-y-3 rounded-xl bg-secondary/50 p-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(M,{className:"text-sm font-medium text-foreground",children:h("settings.routing.suggested")}),e.jsx(w,{variant:"outline",className:"text-[11px]",children:L.length})]}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:h("modelManagement.overview.suggestionHint")})]}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:L.map(j=>{const D=de.has(j);return e.jsx(v,{variant:D?"ghost":"outline",size:"sm",onClick:()=>ne(j),disabled:m||D,className:O("h-7 rounded-md px-2.5 text-[11px] font-normal",D?"opacity-45":"bg-background/70"),children:j},`${l}-${j}`)})})]}),e.jsx("datalist",{id:$,children:L.map(j=>e.jsx("option",{value:j},`${$}-${j}`))})]})})}function Ke({presets:l,presetName:s,presetError:g,savingPreset:r,applyingPreset:a,deletingPreset:p,expanded:m,onToggleExpanded:n,onPresetNameChange:x,onSavePreset:N,onRequestPresetDiff:d,onRequestDeletePreset:b}){const{t:o}=E();return e.jsxs("div",{className:"rounded-xl bg-card shadow-[var(--surface-shadow)]",children:[e.jsx("button",{type:"button",className:"flex w-full items-center justify-between gap-3 rounded-xl p-4 text-left transition-colors hover:bg-accent",onClick:n,children:e.jsxs("div",{className:"flex items-center gap-2",children:[m?e.jsx(xe,{className:"h-4 w-4"}):e.jsx(pe,{className:"h-4 w-4"}),e.jsx("h3",{className:"font-medium",children:o("modelManagement.presets.title")}),e.jsx(w,{variant:"secondary",className:"text-xs",children:l.length})]})}),m?e.jsxs("div",{className:"space-y-4 border-t border-border/45 px-4 pb-4 pt-3",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:o("modelManagement.presets.description")}),e.jsxs("div",{className:"flex flex-col gap-3 md:flex-row md:items-center",children:[e.jsx(S,{value:s,onChange:c=>x(c.target.value),placeholder:o("modelManagement.presets.namePlaceholder"),disabled:r,className:"w-full md:w-48"}),e.jsx(v,{onClick:N,disabled:r,className:"w-full md:w-auto",children:o(r?"modelManagement.presets.saving":"modelManagement.presets.save")})]}),g?e.jsx("p",{className:"text-sm text-destructive",children:g}):null,l.length===0?e.jsx("p",{className:"py-4 text-center text-sm text-muted-foreground",children:o("modelManagement.presets.empty")}):e.jsx(be,{children:e.jsx("div",{className:"grid gap-2 sm:grid-cols-2 lg:grid-cols-3",children:l.map(c=>{const i=a===c.name,t=p===c.name,u=Object.entries(c.modelRoutes??{}),f=u.length;return e.jsxs("div",{className:"flex flex-col gap-3 rounded-xl bg-secondary/50 px-4 py-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs(ve,{children:[e.jsx(Ne,{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:c.name}),e.jsx(w,{variant:"outline",className:"mt-1 text-xs",children:f>0?o("modelManagement.presets.rulesCount",{count:f}):o("modelManagement.presets.noRules")})]})}),f>0?e.jsx(ye,{side:"bottom",className:"max-w-xs",children:e.jsxs("div",{className:"space-y-1 text-xs",children:[u.slice(0,5).map(([k,C])=>e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"truncate",children:k}),e.jsx(P,{className:"h-3 w-3 flex-shrink-0"}),e.jsx("span",{className:"truncate",children:C})]},k)),f>5?e.jsxs("div",{className:"text-muted-foreground",children:["…+",f-5]}):null]})}):null]}),e.jsxs("div",{className:"grid flex-shrink-0 gap-2 sm:flex sm:items-center",children:[e.jsx(v,{size:"sm",onClick:()=>d(c),disabled:i||t,className:"w-full sm:w-auto",children:o(i?"modelManagement.presets.applying":"modelManagement.presets.apply")}),e.jsx(v,{variant:"destructive",size:"sm",onClick:()=>b(c),disabled:t||i,className:"w-full sm:w-auto",children:o(t?"modelManagement.presets.deleting":"modelManagement.presets.delete")})]})]},c.name)})})})]}):null]})}function hs(){var p,m;const{t:l}=E(),s=Ve(),g=s.systemTabs.filter(n=>n.key!=="providers"),r=s.activeTab==="providers"?"anthropic":s.activeTab,a=s.tabs.find(n=>n.key===r)??null;return A.useEffect(()=>{s.activeTab==="providers"&&s.setActiveTab("anthropic")},[s.activeTab,s.setActiveTab]),e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx(je,{icon:e.jsx(he,{className:"h-5 w-5","aria-hidden":"true"}),title:l("routingManagement.title"),description:l("routingManagement.description"),eyebrow:l("routingManagement.eyebrow"),breadcrumb:"Gateway / Routing",badge:(a==null?void 0:a.label)??r,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.jsx(v,{asChild:!0,variant:"outline",className:"w-full sm:w-auto",children:e.jsxs(ge,{to:"/models",children:[e.jsx(ue,{className:"h-4 w-4","aria-hidden":"true"}),l("nav.models")]})}),e.jsx(v,{onClick:s.handleOpenCreateEndpoint,className:"w-full sm:w-auto",children:l("modelManagement.addEndpoint")})]})}),e.jsx(He,{activeTab:r,customEndpoints:s.customEndpoints,customTabs:s.customTabs,isDirtyByEndpoint:s.isDirtyByEndpoint,onDeleteEndpoint:s.setConfirmAction,onEditEndpoint:s.handleOpenEditEndpoint,onSelectTab:s.setActiveTab,systemTabs:g}),e.jsx(Ge,{endpoint:r,applyingPreset:((p=s.applyingPreset)==null?void 0:p.endpoint)===r?s.applyingPreset.name:null,config:s.config,customEndpoints:s.customEndpoints,deletingPreset:((m=s.deletingPreset)==null?void 0:m.endpoint)===r?s.deletingPreset.name:null,isDirty:s.isDirtyByEndpoint[r]??!1,onAddRoute:()=>s.handleAddRoute(r),onAddSuggestion:n=>s.handleAddSuggestion(r,n),onPresetNameChange:n=>s.handlePresetNameChange(r,n),onRequestDeletePreset:n=>s.setConfirmAction({kind:"preset",endpoint:r,preset:n}),onRequestPresetDiff:n=>s.setPresetDiffDialog({endpoint:r,preset:n}),onRemoveRoute:n=>s.handleRemoveRoute(r,n),onResetRoutes:()=>s.handleResetRoutes(r),onRouteChange:(n,x,N)=>s.handleRouteChange(r,n,x,N),onSavePreset:()=>void s.handleSavePreset(r),onSaveRoutes:()=>void s.handleSaveRoutes(r),onValidationModeChange:n=>void s.handleValidationModeChange(r,n),onTogglePresetsExpanded:()=>s.setPresetsExpanded(n=>({...n,[r]:!n[r]})),presetError:s.presetErrorByEndpoint[r],presetName:s.presetNameByEndpoint[r]??"",presets:s.presetsByEndpoint[r]??[],presetsExpanded:s.presetsExpanded[r]===!0,providerModelOptions:s.providerModelOptions,routeError:s.routeError[r],routes:s.routesByEndpoint[r]||[],savingClaudeValidation:s.savingClaudeValidation,savingPreset:s.savingPresetFor===r,savingRoute:s.savingRouteFor===r,tabs:s.tabs.filter(n=>n.key!=="providers")}),e.jsx(ze,{open:s.endpointDrawerOpen,endpoint:s.editingEndpoint,onClose:()=>{s.setEndpointDrawerOpen(!1),s.setEditingEndpoint(void 0)},onSuccess:()=>{s.configQuery.refetch()}}),e.jsx(Ie,{dialog:s.presetDiffDialog,currentRoutes:s.presetDiffDialog?s.routesByEndpoint[s.presetDiffDialog.endpoint]||[]:[],onConfirm:(n,x)=>{s.setPresetDiffDialog(null),s.handleApplyPreset(n,x)},onClose:()=>s.setPresetDiffDialog(null)}),e.jsx(fe,{open:!!s.confirmAction,onOpenChange:n=>{!n&&!s.confirmingAction&&s.setConfirmAction(null)},title:s.confirmDialogTitle,description:s.confirmDialogDescription,confirmLabel:s.confirmingAction?l("common.actions.loading"):l("common.delete"),cancelLabel:l("common.actions.cancel"),loading:s.confirmingAction,onConfirm:s.handleConfirmDialog,children:s.confirmDialogName?e.jsx("div",{className:"rounded-lg bg-destructive/5 px-3 py-2 font-mono text-xs text-foreground ring-1 ring-destructive/20",children:s.confirmDialogName}):null})]})}export{hs as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as e,aL as G,aF as xt,ag as gt,r as m,X as ft}from"./vendor-LWJeAdU1.js";import{C as Le}from"./ConfirmDialog-DopoB7CA.js";import{L as Fe,B as k,r as Te,g as bt,b as vt,u as jt}from"./app-Bd27xdw7.js";import{P as yt}from"./PageHeader-C01S2XTN.js";import{C as A,a as L}from"./card-BMPheH9g.js";import{B as E,q as J}from"./queryKeys-DDTfNI_C.js";import{I as w}from"./input-1_zNDnlx.js";import{L as v}from"./label-B5W3eu-E.js";import{S as V}from"./switch-BqheRBDw.js";import{S as Nt,a as wt,b as Ct,c as Pt,d as kt}from"./select-DJFQztdh.js";import{c as M}from"./global-B_AcmMvG.js";import{u as R}from"./i18n-B3N4Df3E.js";import{u as Me}from"./useApiQuery-rsgixQ8H.js";import{u as Q}from"./useAppMutation-Cxb97sFV.js";import{g as Oe}from"./gateway-BJysEYM8.js";import{c as St}from"./clipboard-CALi6bTW.js";import"./DialogShell-blgQezT9.js";import"./radix-bG5h1Ymq.js";import"./query-Cpxr1dul.js";import"./router-DspBTS8b.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,r,c,a,i,h,p,T,g,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??((r=s.http)==null?void 0:r.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:((g=s.https)==null?void 0:g.keyPath)??"",httpsCertPath:((d=s.https)==null?void 0:d.certPath)??"",httpsCaPath:((N=s.https)==null?void 0:N.caPath)??""}}function X(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-[1.1rem] border border-white/70 bg-card/95 p-3.5 shadow-[0_20px_48px_-42px_rgba(15,23,42,0.24)]",children:[e.jsx("p",{className:"mb-2.5 px-2 text-[10px] font-semibold uppercase tracking-wider text-muted-foreground",children:n("settings.sections.jump")}),e.jsx("div",{className:"space-y-1.5",children:te.map((o,r)=>e.jsxs("button",{type:"button",onClick:()=>t(o.id),className:M("flex w-full items-center gap-2.5 rounded-[0.85rem] px-3 py-2 text-left text-sm font-semibold transition-all duration-200",s===o.id?"bg-secondary text-foreground shadow-[inset_0_1px_0_rgba(255,255,255,0.62)]":"text-muted-foreground hover:text-foreground"),children:[e.jsx("span",{className:M("flex h-7 w-7 items-center justify-center rounded-full text-[11px] font-semibold",s===o.id?"bg-primary text-primary-foreground":"bg-secondary text-muted-foreground"),children:r+1}),e.jsx("span",{children:n(o.labelKey)})]},o.id))})]})}),e.jsx("div",{className:"xl:hidden",children:e.jsx("div",{className:"overflow-x-auto pb-1",children:e.jsx("div",{className:"flex w-max gap-2 px-1",children:te.map(o=>e.jsx("button",{type:"button",onClick:()=>t(o.id),className:M("rounded-full px-4 py-2 text-xs font-semibold transition-all duration-150",s===o.id?"bg-secondary text-foreground font-medium":"text-muted-foreground hover:text-foreground hover:bg-secondary/50"),children:n(o.labelKey)},o.id))})})})]})}function At({configPath:s,defaultsSummary:t,form:n,protocolSummaryLabel:o,protocolChangesPending:r,isAuthDirty:c,isConfigDirty:a,authEnabled:i,authUsername:h}){const{t:p}=R();return e.jsx(A,{variant:"ghost",className:"rounded-[1.25rem] border border-white/70 bg-card/95 shadow-[0_20px_50px_-42px_rgba(15,23,42,0.24)]",children:e.jsxs(L,{className:"space-y-3 p-4",children:[e.jsxs("div",{className:"flex flex-col gap-2 lg:flex-row lg:items-center lg:justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-[10px] font-semibold uppercase tracking-[0.18em] text-primary/75",children:p("settings.overview.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:p("settings.overview.description")})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(E,{variant:a||c?"warning":"success",children:p(a||c?"modelManagement.actions.unsaved":"common.status.success")}),r?e.jsx(E,{variant:"outline",className:"border-amber-300 text-amber-700 dark:border-amber-700 dark:text-amber-300",children:p("settings.protocol.restartWarning")}):null]})]}),e.jsxs("div",{className:"grid gap-3 md:grid-cols-3",children:[e.jsx(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:r,sectionRef:c}){const{t:a}=R();return e.jsx(A,{id:"section-basics",ref:c,className:"bg-card shadow-[var(--surface-shadow)]",children:e.jsxs(L,{className:"pt-6",children:[e.jsxs("div",{className:"mb-4 flex flex-col gap-3 lg:flex-row lg:items-start lg:justify-between",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold",children: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(Y,{label:a("settings.fields.retention"),value:n.logRetentionDays}),e.jsx(Y,{label:a("settings.fields.logExportTimeout"),value:`${n.logExportTimeoutSeconds}s`}),e.jsx(Y,{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=>r(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=>r(h=>({...h,storeRequestPayloads:i}))}),e.jsx(Z,{label:a("settings.fields.storeResponsePayloads"),hint:a("settings.fields.storeResponsePayloadsHint"),checked:n.storeResponsePayloads,onCheckedChange:i=>r(h=>({...h,storeResponsePayloads:i}))}),e.jsx(Z,{label:a("settings.fields.enableRoutingFallback"),hint:a("settings.fields.enableRoutingFallbackHint"),checked:n.enableRoutingFallback,onCheckedChange:i=>r(h=>({...h,enableRoutingFallback:i}))})]}),e.jsxs("div",{className:"rounded-xl bg-secondary px-4 py-5 md:col-span-2",children:[e.jsx(v,{className:"text-xs uppercase tracking-wide text-muted-foreground",children: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:r}=R();return e.jsx(A,{id:"section-protocol",ref:o,className:"bg-card shadow-[var(--surface-shadow)]",children:e.jsxs(L,{className:"space-y-6 pt-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold",children:r("settings.sections.protocol")}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:r("settings.protocol.description")})]}),e.jsx("div",{className:"rounded-xl bg-amber-50 ring-1 ring-amber-200/50 p-4 shadow-sm dark:bg-amber-950/24 dark:ring-amber-500/20",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(G,{className:"mt-0.5 h-5 w-5 flex-shrink-0 text-amber-600 dark:text-amber-400"}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm font-medium text-foreground",children:r("settings.protocol.restartWarning")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:r("settings.protocol.restartHint")}),e.jsx("code",{className:"block rounded-lg border border-border bg-secondary px-3 py-2 text-xs font-mono text-foreground dark:bg-secondary dark:border-border",children:"cc-gw restart --daemon"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:r("settings.protocol.restartTip")})]})]})}),s.protocol?e.jsxs("div",{className:"rounded-xl bg-destructive/10 ring-1 ring-destructive/30 p-4 text-sm text-destructive shadow-sm",children:[e.jsx(G,{className:"mr-2 inline h-4 w-4"}),s.protocol]}):null,e.jsxs("div",{className:"rounded-xl bg-secondary p-5 dark:bg-secondary",children:[e.jsxs("div",{className:"mb-4 flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(v,{className:"text-sm font-medium text-foreground",children:r("settings.protocol.http.enable")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:r("settings.protocol.http.hint")})]}),e.jsx(V,{checked:t.httpEnabled,onCheckedChange: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:r("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:r("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-xl bg-secondary p-5 dark:bg-secondary",children:[e.jsxs("div",{className:"mb-4 flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(v,{className:"text-sm font-medium text-foreground",children:r("settings.protocol.https.enable")}),e.jsx(xt,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:r("settings.protocol.https.hint")})]}),e.jsx(V,{checked:t.httpsEnabled,onCheckedChange: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:r("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:r("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:r("settings.protocol.https.keyPath"),value:t.httpsKeyPath,onChange:c=>n(a=>({...a,httpsKeyPath:c})),placeholder:"~/.cc-gw/certs/key.pem"}),e.jsx(ee,{label:r("settings.protocol.https.certPath"),value:t.httpsCertPath,onChange:c=>n(a=>({...a,httpsCertPath:c})),placeholder:"~/.cc-gw/certs/cert.pem"}),e.jsx(ee,{label:r("settings.protocol.https.caPath"),value:t.httpsCaPath,onChange:c=>n(a=>({...a,httpsCaPath:c})),placeholder:"留空则不使用"}),e.jsx("div",{className:"rounded-xl bg-amber-50 ring-1 ring-amber-200/50 p-4 shadow-sm dark:bg-amber-950/24 dark:ring-amber-500/20",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(G,{className:"mt-0.5 h-5 w-5 flex-shrink-0 text-amber-600 dark:text-amber-400"}),e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsx("p",{className:"text-sm font-medium text-amber-800 dark:text-amber-200",children:r("settings.protocol.https.warning")}),e.jsxs("p",{className:"text-xs leading-relaxed text-amber-700 dark:text-amber-300",children:[e.jsx("strong",{children:r("settings.protocol.https.invalidCert")}),r("settings.protocol.https.invalidCertDetail")]}),e.jsxs("p",{className:"text-xs leading-relaxed text-amber-700 dark:text-amber-300",children:[e.jsx("strong",{children:r("settings.protocol.https.recommended")}),r("settings.protocol.https.recommendedDetail")]}),e.jsx("p",{className:"text-xs leading-relaxed text-amber-600 dark:text-amber-400",children:r("settings.protocol.https.tip")})]})]})})]}):null]})]})})}function Mt({authErrors:s,authForm:t,authLoading:n,authSettings:o,needsPassword:r,onAuthReset:c,onAuthSave:a,onSetAuthForm:i,savingAuth:h,isAuthDirty:p,sectionRef:T}){const{t:g}=R();return e.jsx(A,{id:"section-security",ref:T,className:"bg-card shadow-[var(--surface-shadow)]",children:e.jsxs(L,{className:"space-y-5 pt-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold",children:g("settings.sections.security")}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:g("settings.auth.description")})]}),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-xl bg-secondary p-4 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(v,{className:"text-sm font-medium",children:g("settings.auth.enable")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:g("settings.auth.enableHint")}),e.jsxs("div",{className:"flex flex-wrap gap-2 text-xs font-medium text-muted-foreground",children:[e.jsx("span",{className:"rounded-full bg-secondary px-3 py-1 text-[11px] tracking-[0.08em]",children:"/ui"}),e.jsx("span",{className:"rounded-full bg-secondary px-3 py-1 text-[11px] tracking-[0.08em]",children:"/api/*"}),e.jsx("span",{className:"rounded-full bg-secondary px-3 py-1 text-[11px] tracking-[0.08em]",children:"Cookie Session"})]})]}),e.jsxs("div",{className:"flex items-center gap-3 self-start sm:self-auto",children:[e.jsx(E,{variant:t.enabled?"success":"secondary",children:t.enabled?g("settings.auth.statusEnabled"):g("settings.auth.statusDisabled")}),e.jsx(V,{checked:t.enabled,onCheckedChange:d=>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:g("settings.auth.username")}),e.jsx(w,{value:t.username,onChange:d=>i(N=>({...N,username:d.target.value})),placeholder:g("settings.auth.usernamePlaceholder")}),s.username?e.jsx("p",{className:"text-xs text-destructive",children:s.username}):null]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(v,{children:g("settings.auth.password")}),e.jsx(w,{type:"password",value:t.password,disabled:!t.enabled,onChange:d=>i(N=>({...N,password:d.target.value})),placeholder:g("settings.auth.passwordPlaceholder")}),s.password?e.jsx("p",{className:"text-xs text-destructive",children:s.password}):e.jsx("p",{className:"text-xs text-muted-foreground",children:g(r?"settings.auth.passwordHintRequired":"settings.auth.passwordHintOptional")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(v,{children:g("settings.auth.confirmPassword")}),e.jsx(w,{type:"password",value:t.confirmPassword,disabled:!t.enabled,onChange:d=>i(N=>({...N,confirmPassword:d.target.value})),placeholder:g("settings.auth.confirmPasswordPlaceholder")}),s.confirmPassword?e.jsx("p",{className:"text-xs text-destructive",children:s.confirmPassword}):null]})]}),e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"rounded-xl bg-secondary p-4",children:[e.jsx("p",{className:"text-[10px] font-semibold uppercase tracking-[0.34em] text-muted-foreground",children:g("settings.auth.status")}),e.jsx("p",{className:"mt-2 text-base font-semibold",children:o!=null&&o.enabled?g("settings.auth.statusEnabled"):g("settings.auth.statusDisabled")}),o!=null&&o.username?e.jsxs("div",{className:"mt-3 rounded-lg bg-accent px-3 py-2 text-xs font-medium text-primary",children:[g("settings.auth.username"),": ",o.username]}):null]}),e.jsx("div",{className:"rounded-xl bg-secondary px-4 py-3 text-xs text-muted-foreground",children:g(r?"settings.auth.passwordHintRequired":"settings.auth.passwordHintOptional")})]})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2 lg:flex lg:flex-wrap lg:justify-end",children:[e.jsx(k,{onClick:a,disabled:h||!p,className:"w-full lg:w-auto",children:g(h?"common.actions.saving":"settings.auth.actions.save")}),e.jsx(k,{variant:"outline",onClick:c,disabled:h||!p,className:"w-full lg:w-auto",children:g("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,className:"bg-card shadow-[var(--surface-shadow)]",children:e.jsxs(L,{className:"space-y-3 pt-6",children:[e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold",children:o("settings.sections.configFile")}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:o("settings.file.description")})]}),e.jsxs(k,{variant:"outline",size:"sm",onClick:t,className:"w-full sm:w-auto",children:[e.jsx(gt,{className:"mr-2 h-4 w-4"}),o("common.actions.copy")]})]}),e.jsx("code",{className:"block break-all rounded-lg bg-secondary px-4 py-3 text-xs font-mono text-muted-foreground",children:s||o("settings.file.unknown")}),e.jsx("div",{className:"rounded-lg bg-secondary px-4 py-3 text-xs text-muted-foreground",children:o("help.note")})]})})}function Ft({cleaning:s,clearingAll:t,onOpenCleanup:n,onOpenClearAll:o,sectionRef:r}){const{t:c}=R();return e.jsx(A,{id:"section-cleanup",ref:r,className:"bg-card shadow-[var(--surface-shadow)]",children:e.jsxs(L,{className:"space-y-4 pt-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold",children: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 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-xl border border-amber-200 bg-amber-50 p-5 dark:border-amber-800 dark:bg-amber-950/30",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx(E,{variant:"warning",children: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-xl border border-destructive/30 bg-destructive/10 p-5 text-destructive",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx(E,{variant:"outline",className:"border-destructive/40 bg-destructive/10 text-destructive",children: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:r,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-xl bg-card border border-border px-6 py-5 shadow-lg md:flex-row md:items-center md:justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(E,{variant:"secondary",children:p("modelManagement.actions.unsaved")}),t?e.jsx(E,{variant:"outline",children:p("settings.sections.basics")}):null,s?e.jsx(E,{variant:"outline",children:p("settings.sections.security")}):null,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:r,disabled:h,className:"w-full lg:w-auto",children:p(h?"common.actions.saving":"settings.auth.actions.save")})]}):null,t?e.jsxs(e.Fragment,{children:[e.jsx(k,{variant:"outline",onClick: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:"min-w-0 rounded-[0.95rem] bg-secondary/65 px-3.5 py-3 shadow-[inset_0_1px_0_rgba(255,255,255,0.62)]",children:[e.jsx("p",{className:"text-[10px] font-semibold uppercase tracking-[0.22em] text-muted-foreground",children:s}),e.jsx("p",{className:M("mt-1.5 truncate text-xl font-semibold text-foreground",o?"font-mono text-sm leading-tight":""),title:typeof t=="string"?t:void 0,children:t}),e.jsx("p",{className:"mt-1.5 line-clamp-2 text-xs leading-relaxed text-muted-foreground",children:n})]})}function Y({label:s,value:t}){return e.jsxs("div",{className:"rounded-lg bg-secondary px-3 py-2 text-center",children:[e.jsx("p",{className:"text-[10px] font-semibold uppercase tracking-[0.3em] text-muted-foreground",children:s}),e.jsx("p",{className:"mt-1 text-sm font-semibold text-foreground",children:t})]})}function Z({checked:s,className:t,hint:n,hintClassName:o,label:r,labelClassName:c,onCheckedChange:a}){return e.jsxs("div",{className:M("flex flex-col gap-3 rounded-xl bg-secondary p-4 sm:flex-row sm:items-center sm:justify-between",t),children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(v,{className:M("text-sm font-semibold text-foreground",c),children:r}),e.jsx("p",{className:M("text-xs text-muted-foreground",o),children:n})]}),e.jsx(V,{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:r=>t(r.target.value),placeholder:n,className:"font-mono text-xs"})]})}const _={authStatusRequest(){return{url:"/api/auth/web",method:"GET"}},saveWebAuth:async s=>bt(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),r=m.useRef(new Map),c=m.useCallback(l=>{const x=r.current.get(l);x&&x.scrollIntoView({behavior:"smooth",block:"start"})},[]),a=m.useCallback(l=>x=>{x?r.current.set(l,x):r.current.delete(l)},[]),i=Me(J.config.info(),Oe.configInfoRequest()),h=Me(J.auth.web(),_.authStatusRequest()),p=Q({mutationFn:_.saveWebAuth,successToast:()=>({title:s("settings.auth.toast.success")}),errorToast:l=>({title:s("settings.auth.toast.failure",{message:l.message})}),invalidateKeys:[J.auth.web()]}),T=Q({mutationFn:_.cleanupLogs,successToast:l=>({title:l.deleted>0?s("settings.toast.cleanupSuccess",{count:l.deleted}):s("settings.toast.cleanupNone")}),errorToast:l=>({title:s("settings.toast.cleanupFailure",{message:l.message})})}),g=Q({mutationFn:_.clearLogs,successToast:l=>({title:s("settings.toast.clearAllSuccess",{logs:l.deleted,metrics:l.metricsCleared})}),errorToast:l=>({title:s("settings.toast.clearAllFailure",{message:l.message})})}),[d,N]=m.useState(null),[C,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,B]=m.useState({}),[Ke,se]=m.useState(!1),[qe,ae]=m.useState(!1),[_e,ne]=m.useState(!1),[Ve,Be]=m.useState(!1),[Ie,$e]=m.useState(!1),[j,le]=m.useState(null),[f,D]=m.useState({enabled:!1,username:"",password:"",confirmPassword:""}),[We,K]=m.useState({}),[Ge,re]=m.useState(!1),Je=m.useMemo(()=>{if(!(d!=null&&d.defaults))return null;const l=[];return d.defaults.completion&&l.push(s("settings.defaults.completion",{model:d.defaults.completion})),d.defaults.reasoning&&l.push(s("settings.defaults.reasoning",{model:d.defaults.reasoning})),d.defaults.background&&l.push(s("settings.defaults.background",{model:d.defaults.background})),l.length>0?l.join(" | "):s("settings.defaults.none")},[d,s]),Qe=m.useMemo(()=>u.httpEnabled&&u.httpsEnabled?s("settings.overview.values.httpAndHttps"):u.httpsEnabled?s("settings.overview.values.httpsOnly"):s("settings.overview.values.httpOnly"),[u.httpEnabled,u.httpsEnabled,s]),ze=m.useMemo(()=>f.enabled?j!=null&&j.hasPassword?f.username.trim()!==(j.username??""):!0:!1,[f.enabled,f.username,j]),O=m.useMemo(()=>d?z(d):null,[d]),Xe=m.useMemo(()=>O?JSON.stringify(u)!==JSON.stringify(O):!1,[u,O]),I=m.useMemo(()=>j?X(j):null,[j]),Ue=m.useMemo(()=>I?JSON.stringify(f)!==JSON.stringify(I):!1,[f,I]),Ye=m.useMemo(()=>O?["httpEnabled","httpPort","httpHost","httpsEnabled","httpsPort","httpsHost","httpsKeyPath","httpsCertPath","httpsCaPath","port","host"].some(x=>u[x]!==O[x]):!1,[u,O]);m.useEffect(()=>{i.data&&(N(i.data.config),He(i.data.path),H(z(i.data.config)))},[i.data]),m.useEffect(()=>{h.data&&(le(h.data),D(X(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(l=>x=>{H(y=>({...y,[l]:x}))},[]),oe=m.useCallback(()=>{const l={};if(!u.httpEnabled&&!u.httpsEnabled&&(l.protocol=s("settings.validation.protocolRequired")),u.httpEnabled){const S=Number(u.httpPort);(!Number.isFinite(S)||S<1||S>65535)&&(l.httpPort=s("settings.validation.httpPort"))}if(u.httpsEnabled){const S=Number(u.httpsPort);(!Number.isFinite(S)||S<1||S>65535)&&(l.httpsPort=s("settings.validation.httpsPort")),(!u.httpsKeyPath||!u.httpsCertPath)&&(l.protocol=s("settings.validation.httpsCertificate"))}const x=Number(u.port);(!Number.isFinite(x)||x<1||x>65535)&&(l.port=s("settings.validation.port"));const y=Number(u.logRetentionDays);(!Number.isFinite(y)||y<1||y>365)&&(l.logRetentionDays=s("settings.validation.retention"));const P=Number(u.logExportTimeoutSeconds);(!Number.isFinite(P)||P<5||P>600)&&(l.logExportTimeoutSeconds=s("settings.validation.logExportTimeout"));const F=Number(u.bodyLimitMb);return(!Number.isFinite(F)||F<1||F>2048)&&(l.bodyLimitMb=s("settings.validation.bodyLimit")),B(l),Object.keys(l).length===0},[u,s]),ie=m.useCallback(()=>{const l={},x=f.username.trim(),y=j?x!==(j.username??""):!0,P=f.enabled&&(!(j!=null&&j.hasPassword)||y);return f.enabled&&!x&&(l.username=s("settings.auth.validation.username")),f.password&&f.password.length<6&&(l.password=s("settings.auth.validation.minLength")),P&&!f.password&&(l.password=s("settings.auth.validation.passwordRequired")),(f.password||f.confirmPassword)&&f.password!==f.confirmPassword&&(l.confirmPassword=s("settings.auth.validation.confirmMismatch")),K(l),Object.keys(l).length===0},[f,j,s]),et=m.useCallback(async()=>{var l,x,y,P,F,S,ce,de,ue,me,pe,he,xe,ge,fe,be,ve,je,ye,Ne,we,Ce,Pe,ke,Se,Re;if(!d){t({title:s("settings.toast.loadFailure",{message:s("settings.toast.missingConfig")}),variant:"error"});return}if(oe()){se(!0);try{const q=Number(u.port),ot=Number(u.logRetentionDays),it=Number(u.logExportTimeoutSeconds),ct=Number(u.bodyLimitMb),b={...d,http:{enabled:u.httpEnabled,port:Number(u.httpPort),host:u.httpHost.trim()||"127.0.0.1"},https:{enabled:u.httpsEnabled,port:Number(u.httpsPort),host:u.httpsHost.trim()||"127.0.0.1",keyPath:u.httpsKeyPath.trim(),certPath:u.httpsCertPath.trim(),caPath:u.httpsCaPath.trim()||void 0},port:q,host:u.host.trim()||void 0,logRetentionDays:ot,logExportTimeoutSeconds:Math.min(Math.max(Math.round(it),5),600),storeRequestPayloads:u.storeRequestPayloads,storeResponsePayloads:u.storeResponsePayloads,logLevel:u.logLevel,bodyLimit:Math.max(1,Math.floor(ct*1024*1024)),enableRoutingFallback:u.enableRoutingFallback};delete b.requestLogging,delete b.responseLogging;const Ee={...b};delete Ee.webAuth,await Oe.saveConfig(Ee),N({...b,webAuth:d.webAuth});const Ae=W=>(W==null?void 0:W.trim())||void 0,dt=d.port??((l=d.http)==null?void 0:l.port)??4100,ut=b.port??((x=b.http)==null?void 0:x.port)??4100,mt=((y=d.host)==null?void 0:y.trim())||((F=(P=d.http)==null?void 0:P.host)==null?void 0:F.trim())||"127.0.0.1",pt=((S=b.host)==null?void 0:S.trim())||((de=(ce=b.http)==null?void 0:ce.host)==null?void 0:de.trim())||"127.0.0.1",ht=dt!==ut||mt!==pt||((ue=d.http)==null?void 0:ue.enabled)!==((me=b.http)==null?void 0:me.enabled)||((pe=d.http)==null?void 0:pe.port)!==((he=b.http)==null?void 0:he.port)||(((xe=d.http)==null?void 0:xe.host)??d.host??"127.0.0.1")!==(((ge=b.http)==null?void 0:ge.host)??b.host??"127.0.0.1")||((fe=d.https)==null?void 0:fe.enabled)!==((be=b.https)==null?void 0:be.enabled)||((ve=d.https)==null?void 0:ve.port)!==((je=b.https)==null?void 0:je.port)||(((ye=d.https)==null?void 0:ye.host)??d.host??"127.0.0.1")!==(((Ne=b.https)==null?void 0:Ne.host)??b.host??"127.0.0.1")||((we=d.https)==null?void 0:we.keyPath)!==((Ce=b.https)==null?void 0:Ce.keyPath)||((Pe=d.https)==null?void 0:Pe.certPath)!==((ke=b.https)==null?void 0:ke.certPath)||Ae((Se=d.https)==null?void 0:Se.caPath)!==Ae((Re=b.https)==null?void 0:Re.caPath);t({title:s(ht?"settings.toast.protocolRestartRequired":"settings.toast.saveSuccess"),variant:"success"}),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)),B({}))},[d]),st=m.useCallback(async()=>{if(ie()){re(!0);try{const l={enabled:f.enabled,username:f.username.trim()||void 0};f.password&&(l.password=f.password);const x=await p.mutateAsync(l);x.auth&&(le(x.auth),D({enabled:x.auth.enabled,username:x.auth.username??"",password:"",confirmPassword:""}),K({})),h.refetch()}catch{}finally{re(!1)}}},[f,h,p,ie]),at=m.useCallback(()=>{j&&(D(X(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(l){t({title:s("settings.toast.copyFailure",{message:l instanceof Error?l.message:"unknown"}),variant:"error"})}},[C,t,s]),lt=m.useCallback(async()=>{ae(!0);try{await T.mutateAsync()}catch{}finally{ae(!1)}},[T]),rt=m.useCallback(async()=>{ne(!0);try{await g.mutateAsync()}catch{}finally{ne(!1)}},[g]),$=i.isPending||!d&&i.isFetching;return m.useEffect(()=>{if($)return;const l=Array.from(r.current.values());if(l.length===0)return;const x=new IntersectionObserver(y=>{for(const P of y)if(P.isIntersecting){o(P.target.id);break}},{rootMargin:"-80px 0px -60% 0px",threshold:0});for(const y of l)x.observe(y);return()=>x.disconnect()},[$]),{activeSection:n,authErrors:We,authForm:f,authQuery:h,authSettings:j,clearingAll:_e,cleaning:qe,config:d,configPath:C,configQuery:i,confirmCleanupOpen:Ve,confirmClearAllOpen:Ie,defaultsSummary:Je,errors:De,form:u,handleAuthReset:at,handleAuthSave:st,handleCleanupLogs:lt,handleClearAllLogs:rt,handleCopyPath:nt,handleInputChange:Ze,handleReset:tt,handleSave:et,handleSectionClick:c,isAuthDirty:Ue,isConfigDirty:Xe,isLoading:$,needsPassword:ze,protocolSummaryLabel:Qe,protocolChangesPending:Ye,saving:Ke,savingAuth:Ge,sectionRefs:r,setAuthForm:D,setConfirmCleanupOpen:Be,setConfirmClearAllOpen:$e,setErrors:B,setForm:H,setSectionRef:a,t:s}}function ns(){var r,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(ft,{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-full bg-secondary px-3.5 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,{className:"bg-card/82",children:e.jsx(L,{className:"flex min-h-[220px] items-center justify-center",children:e.jsx(Fe,{})})}):t.config?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid gap-6 xl:grid-cols-[200px_1fr]",children:[e.jsx(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:((r=t.authSettings)==null?void 0:r.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,{className:"bg-card/82",children:e.jsx(L,{className:"pt-6",children:e.jsx("p",{className:"text-sm font-medium text-destructive",children:s("settings.toast.missingConfig")})})}),e.jsx(Le,{open:t.confirmCleanupOpen,onOpenChange: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{ns as default};
|
|
1
|
+
import{j as e,aL as G,aF as xt,ag as gt,r as m,X as ft}from"./vendor-LWJeAdU1.js";import{C as Le}from"./ConfirmDialog-CPNJmevF.js";import{L as Fe,B as k,r as Te,g as bt,b as vt,u as jt}from"./app-BxSHC5_o.js";import{P as yt}from"./PageHeader-bDiw2pSJ.js";import{C as A,a as L}from"./card-7EdLPk_C.js";import{B as E,q as J}from"./queryKeys-CsNzv19i.js";import{I as w}from"./input-BjD2rjIj.js";import{L as v}from"./label-DPJWPvWM.js";import{S as V}from"./switch-_3mhCfFY.js";import{S as Nt,a as wt,b as Ct,c as Pt,d as kt}from"./select-UI4HSm85.js";import{c as M}from"./global-NDOUShP9.js";import{u as R}from"./i18n-B3N4Df3E.js";import{u as Me}from"./useApiQuery-Y63AiXYK.js";import{u as Q}from"./useAppMutation-wWyqqlf8.js";import{g as Oe}from"./gateway-mlUZb7iD.js";import{c as St}from"./clipboard-CALi6bTW.js";import"./DialogShell-C0EfvzaN.js";import"./radix-bG5h1Ymq.js";import"./query-Cpxr1dul.js";import"./router-DspBTS8b.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,r,c,a,i,h,p,T,g,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??((r=s.http)==null?void 0:r.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:((g=s.https)==null?void 0:g.keyPath)??"",httpsCertPath:((d=s.https)==null?void 0:d.certPath)??"",httpsCaPath:((N=s.https)==null?void 0:N.caPath)??""}}function X(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-[1.1rem] border border-white/70 bg-card/95 p-3.5 shadow-[0_20px_48px_-42px_rgba(15,23,42,0.24)]",children:[e.jsx("p",{className:"mb-2.5 px-2 text-[10px] font-semibold uppercase tracking-wider text-muted-foreground",children:n("settings.sections.jump")}),e.jsx("div",{className:"space-y-1.5",children:te.map((o,r)=>e.jsxs("button",{type:"button",onClick:()=>t(o.id),className:M("flex w-full items-center gap-2.5 rounded-[0.85rem] px-3 py-2 text-left text-sm font-semibold transition-all duration-200",s===o.id?"bg-secondary text-foreground shadow-[inset_0_1px_0_rgba(255,255,255,0.62)]":"text-muted-foreground hover:text-foreground"),children:[e.jsx("span",{className:M("flex h-7 w-7 items-center justify-center rounded-full text-[11px] font-semibold",s===o.id?"bg-primary text-primary-foreground":"bg-secondary text-muted-foreground"),children:r+1}),e.jsx("span",{children:n(o.labelKey)})]},o.id))})]})}),e.jsx("div",{className:"xl:hidden",children:e.jsx("div",{className:"overflow-x-auto pb-1",children:e.jsx("div",{className:"flex w-max gap-2 px-1",children:te.map(o=>e.jsx("button",{type:"button",onClick:()=>t(o.id),className:M("rounded-full px-4 py-2 text-xs font-semibold transition-all duration-150",s===o.id?"bg-secondary text-foreground font-medium":"text-muted-foreground hover:text-foreground hover:bg-secondary/50"),children:n(o.labelKey)},o.id))})})})]})}function At({configPath:s,defaultsSummary:t,form:n,protocolSummaryLabel:o,protocolChangesPending:r,isAuthDirty:c,isConfigDirty:a,authEnabled:i,authUsername:h}){const{t:p}=R();return e.jsx(A,{variant:"ghost",className:"rounded-[1.25rem] border border-white/70 bg-card/95 shadow-[0_20px_50px_-42px_rgba(15,23,42,0.24)]",children:e.jsxs(L,{className:"space-y-3 p-4",children:[e.jsxs("div",{className:"flex flex-col gap-2 lg:flex-row lg:items-center lg:justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-[10px] font-semibold uppercase tracking-[0.18em] text-primary/75",children:p("settings.overview.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:p("settings.overview.description")})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(E,{variant:a||c?"warning":"success",children:p(a||c?"modelManagement.actions.unsaved":"common.status.success")}),r?e.jsx(E,{variant:"outline",className:"border-amber-300 text-amber-700 dark:border-amber-700 dark:text-amber-300",children:p("settings.protocol.restartWarning")}):null]})]}),e.jsxs("div",{className:"grid gap-3 md:grid-cols-3",children:[e.jsx(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:r,sectionRef:c}){const{t:a}=R();return e.jsx(A,{id:"section-basics",ref:c,className:"bg-card shadow-[var(--surface-shadow)]",children:e.jsxs(L,{className:"pt-6",children:[e.jsxs("div",{className:"mb-4 flex flex-col gap-3 lg:flex-row lg:items-start lg:justify-between",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold",children: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(Y,{label:a("settings.fields.retention"),value:n.logRetentionDays}),e.jsx(Y,{label:a("settings.fields.logExportTimeout"),value:`${n.logExportTimeoutSeconds}s`}),e.jsx(Y,{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=>r(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=>r(h=>({...h,storeRequestPayloads:i}))}),e.jsx(Z,{label:a("settings.fields.storeResponsePayloads"),hint:a("settings.fields.storeResponsePayloadsHint"),checked:n.storeResponsePayloads,onCheckedChange:i=>r(h=>({...h,storeResponsePayloads:i}))}),e.jsx(Z,{label:a("settings.fields.enableRoutingFallback"),hint:a("settings.fields.enableRoutingFallbackHint"),checked:n.enableRoutingFallback,onCheckedChange:i=>r(h=>({...h,enableRoutingFallback:i}))})]}),e.jsxs("div",{className:"rounded-xl bg-secondary px-4 py-5 md:col-span-2",children:[e.jsx(v,{className:"text-xs uppercase tracking-wide text-muted-foreground",children: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:r}=R();return e.jsx(A,{id:"section-protocol",ref:o,className:"bg-card shadow-[var(--surface-shadow)]",children:e.jsxs(L,{className:"space-y-6 pt-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold",children:r("settings.sections.protocol")}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:r("settings.protocol.description")})]}),e.jsx("div",{className:"rounded-xl bg-amber-50 ring-1 ring-amber-200/50 p-4 shadow-sm dark:bg-amber-950/24 dark:ring-amber-500/20",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(G,{className:"mt-0.5 h-5 w-5 flex-shrink-0 text-amber-600 dark:text-amber-400"}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm font-medium text-foreground",children:r("settings.protocol.restartWarning")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:r("settings.protocol.restartHint")}),e.jsx("code",{className:"block rounded-lg border border-border bg-secondary px-3 py-2 text-xs font-mono text-foreground dark:bg-secondary dark:border-border",children:"cc-gw restart --daemon"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:r("settings.protocol.restartTip")})]})]})}),s.protocol?e.jsxs("div",{className:"rounded-xl bg-destructive/10 ring-1 ring-destructive/30 p-4 text-sm text-destructive shadow-sm",children:[e.jsx(G,{className:"mr-2 inline h-4 w-4"}),s.protocol]}):null,e.jsxs("div",{className:"rounded-xl bg-secondary p-5 dark:bg-secondary",children:[e.jsxs("div",{className:"mb-4 flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(v,{className:"text-sm font-medium text-foreground",children:r("settings.protocol.http.enable")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:r("settings.protocol.http.hint")})]}),e.jsx(V,{checked:t.httpEnabled,onCheckedChange: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:r("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:r("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-xl bg-secondary p-5 dark:bg-secondary",children:[e.jsxs("div",{className:"mb-4 flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(v,{className:"text-sm font-medium text-foreground",children:r("settings.protocol.https.enable")}),e.jsx(xt,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:r("settings.protocol.https.hint")})]}),e.jsx(V,{checked:t.httpsEnabled,onCheckedChange: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:r("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:r("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:r("settings.protocol.https.keyPath"),value:t.httpsKeyPath,onChange:c=>n(a=>({...a,httpsKeyPath:c})),placeholder:"~/.cc-gw/certs/key.pem"}),e.jsx(ee,{label:r("settings.protocol.https.certPath"),value:t.httpsCertPath,onChange:c=>n(a=>({...a,httpsCertPath:c})),placeholder:"~/.cc-gw/certs/cert.pem"}),e.jsx(ee,{label:r("settings.protocol.https.caPath"),value:t.httpsCaPath,onChange:c=>n(a=>({...a,httpsCaPath:c})),placeholder:"留空则不使用"}),e.jsx("div",{className:"rounded-xl bg-amber-50 ring-1 ring-amber-200/50 p-4 shadow-sm dark:bg-amber-950/24 dark:ring-amber-500/20",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(G,{className:"mt-0.5 h-5 w-5 flex-shrink-0 text-amber-600 dark:text-amber-400"}),e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsx("p",{className:"text-sm font-medium text-amber-800 dark:text-amber-200",children:r("settings.protocol.https.warning")}),e.jsxs("p",{className:"text-xs leading-relaxed text-amber-700 dark:text-amber-300",children:[e.jsx("strong",{children:r("settings.protocol.https.invalidCert")}),r("settings.protocol.https.invalidCertDetail")]}),e.jsxs("p",{className:"text-xs leading-relaxed text-amber-700 dark:text-amber-300",children:[e.jsx("strong",{children:r("settings.protocol.https.recommended")}),r("settings.protocol.https.recommendedDetail")]}),e.jsx("p",{className:"text-xs leading-relaxed text-amber-600 dark:text-amber-400",children:r("settings.protocol.https.tip")})]})]})})]}):null]})]})})}function Mt({authErrors:s,authForm:t,authLoading:n,authSettings:o,needsPassword:r,onAuthReset:c,onAuthSave:a,onSetAuthForm:i,savingAuth:h,isAuthDirty:p,sectionRef:T}){const{t:g}=R();return e.jsx(A,{id:"section-security",ref:T,className:"bg-card shadow-[var(--surface-shadow)]",children:e.jsxs(L,{className:"space-y-5 pt-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold",children:g("settings.sections.security")}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:g("settings.auth.description")})]}),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-xl bg-secondary p-4 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(v,{className:"text-sm font-medium",children:g("settings.auth.enable")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:g("settings.auth.enableHint")}),e.jsxs("div",{className:"flex flex-wrap gap-2 text-xs font-medium text-muted-foreground",children:[e.jsx("span",{className:"rounded-full bg-secondary px-3 py-1 text-[11px] tracking-[0.08em]",children:"/ui"}),e.jsx("span",{className:"rounded-full bg-secondary px-3 py-1 text-[11px] tracking-[0.08em]",children:"/api/*"}),e.jsx("span",{className:"rounded-full bg-secondary px-3 py-1 text-[11px] tracking-[0.08em]",children:"Cookie Session"})]})]}),e.jsxs("div",{className:"flex items-center gap-3 self-start sm:self-auto",children:[e.jsx(E,{variant:t.enabled?"success":"secondary",children:t.enabled?g("settings.auth.statusEnabled"):g("settings.auth.statusDisabled")}),e.jsx(V,{checked:t.enabled,onCheckedChange:d=>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:g("settings.auth.username")}),e.jsx(w,{value:t.username,onChange:d=>i(N=>({...N,username:d.target.value})),placeholder:g("settings.auth.usernamePlaceholder")}),s.username?e.jsx("p",{className:"text-xs text-destructive",children:s.username}):null]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(v,{children:g("settings.auth.password")}),e.jsx(w,{type:"password",value:t.password,disabled:!t.enabled,onChange:d=>i(N=>({...N,password:d.target.value})),placeholder:g("settings.auth.passwordPlaceholder")}),s.password?e.jsx("p",{className:"text-xs text-destructive",children:s.password}):e.jsx("p",{className:"text-xs text-muted-foreground",children:g(r?"settings.auth.passwordHintRequired":"settings.auth.passwordHintOptional")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(v,{children:g("settings.auth.confirmPassword")}),e.jsx(w,{type:"password",value:t.confirmPassword,disabled:!t.enabled,onChange:d=>i(N=>({...N,confirmPassword:d.target.value})),placeholder:g("settings.auth.confirmPasswordPlaceholder")}),s.confirmPassword?e.jsx("p",{className:"text-xs text-destructive",children:s.confirmPassword}):null]})]}),e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"rounded-xl bg-secondary p-4",children:[e.jsx("p",{className:"text-[10px] font-semibold uppercase tracking-[0.34em] text-muted-foreground",children:g("settings.auth.status")}),e.jsx("p",{className:"mt-2 text-base font-semibold",children:o!=null&&o.enabled?g("settings.auth.statusEnabled"):g("settings.auth.statusDisabled")}),o!=null&&o.username?e.jsxs("div",{className:"mt-3 rounded-lg bg-accent px-3 py-2 text-xs font-medium text-primary",children:[g("settings.auth.username"),": ",o.username]}):null]}),e.jsx("div",{className:"rounded-xl bg-secondary px-4 py-3 text-xs text-muted-foreground",children:g(r?"settings.auth.passwordHintRequired":"settings.auth.passwordHintOptional")})]})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2 lg:flex lg:flex-wrap lg:justify-end",children:[e.jsx(k,{onClick:a,disabled:h||!p,className:"w-full lg:w-auto",children:g(h?"common.actions.saving":"settings.auth.actions.save")}),e.jsx(k,{variant:"outline",onClick:c,disabled:h||!p,className:"w-full lg:w-auto",children:g("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,className:"bg-card shadow-[var(--surface-shadow)]",children:e.jsxs(L,{className:"space-y-3 pt-6",children:[e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold",children:o("settings.sections.configFile")}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:o("settings.file.description")})]}),e.jsxs(k,{variant:"outline",size:"sm",onClick:t,className:"w-full sm:w-auto",children:[e.jsx(gt,{className:"mr-2 h-4 w-4"}),o("common.actions.copy")]})]}),e.jsx("code",{className:"block break-all rounded-lg bg-secondary px-4 py-3 text-xs font-mono text-muted-foreground",children:s||o("settings.file.unknown")}),e.jsx("div",{className:"rounded-lg bg-secondary px-4 py-3 text-xs text-muted-foreground",children:o("help.note")})]})})}function Ft({cleaning:s,clearingAll:t,onOpenCleanup:n,onOpenClearAll:o,sectionRef:r}){const{t:c}=R();return e.jsx(A,{id:"section-cleanup",ref:r,className:"bg-card shadow-[var(--surface-shadow)]",children:e.jsxs(L,{className:"space-y-4 pt-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold",children: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 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-xl border border-amber-200 bg-amber-50 p-5 dark:border-amber-800 dark:bg-amber-950/30",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx(E,{variant:"warning",children: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-xl border border-destructive/30 bg-destructive/10 p-5 text-destructive",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx(E,{variant:"outline",className:"border-destructive/40 bg-destructive/10 text-destructive",children: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:r,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-xl bg-card border border-border px-6 py-5 shadow-lg md:flex-row md:items-center md:justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(E,{variant:"secondary",children:p("modelManagement.actions.unsaved")}),t?e.jsx(E,{variant:"outline",children:p("settings.sections.basics")}):null,s?e.jsx(E,{variant:"outline",children:p("settings.sections.security")}):null,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:r,disabled:h,className:"w-full lg:w-auto",children:p(h?"common.actions.saving":"settings.auth.actions.save")})]}):null,t?e.jsxs(e.Fragment,{children:[e.jsx(k,{variant:"outline",onClick: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:"min-w-0 rounded-[0.95rem] bg-secondary/65 px-3.5 py-3 shadow-[inset_0_1px_0_rgba(255,255,255,0.62)]",children:[e.jsx("p",{className:"text-[10px] font-semibold uppercase tracking-[0.22em] text-muted-foreground",children:s}),e.jsx("p",{className:M("mt-1.5 truncate text-xl font-semibold text-foreground",o?"font-mono text-sm leading-tight":""),title:typeof t=="string"?t:void 0,children:t}),e.jsx("p",{className:"mt-1.5 line-clamp-2 text-xs leading-relaxed text-muted-foreground",children:n})]})}function Y({label:s,value:t}){return e.jsxs("div",{className:"rounded-lg bg-secondary px-3 py-2 text-center",children:[e.jsx("p",{className:"text-[10px] font-semibold uppercase tracking-[0.3em] text-muted-foreground",children:s}),e.jsx("p",{className:"mt-1 text-sm font-semibold text-foreground",children:t})]})}function Z({checked:s,className:t,hint:n,hintClassName:o,label:r,labelClassName:c,onCheckedChange:a}){return e.jsxs("div",{className:M("flex flex-col gap-3 rounded-xl bg-secondary p-4 sm:flex-row sm:items-center sm:justify-between",t),children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(v,{className:M("text-sm font-semibold text-foreground",c),children:r}),e.jsx("p",{className:M("text-xs text-muted-foreground",o),children:n})]}),e.jsx(V,{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:r=>t(r.target.value),placeholder:n,className:"font-mono text-xs"})]})}const _={authStatusRequest(){return{url:"/api/auth/web",method:"GET"}},saveWebAuth:async s=>bt(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),r=m.useRef(new Map),c=m.useCallback(l=>{const x=r.current.get(l);x&&x.scrollIntoView({behavior:"smooth",block:"start"})},[]),a=m.useCallback(l=>x=>{x?r.current.set(l,x):r.current.delete(l)},[]),i=Me(J.config.info(),Oe.configInfoRequest()),h=Me(J.auth.web(),_.authStatusRequest()),p=Q({mutationFn:_.saveWebAuth,successToast:()=>({title:s("settings.auth.toast.success")}),errorToast:l=>({title:s("settings.auth.toast.failure",{message:l.message})}),invalidateKeys:[J.auth.web()]}),T=Q({mutationFn:_.cleanupLogs,successToast:l=>({title:l.deleted>0?s("settings.toast.cleanupSuccess",{count:l.deleted}):s("settings.toast.cleanupNone")}),errorToast:l=>({title:s("settings.toast.cleanupFailure",{message:l.message})})}),g=Q({mutationFn:_.clearLogs,successToast:l=>({title:s("settings.toast.clearAllSuccess",{logs:l.deleted,metrics:l.metricsCleared})}),errorToast:l=>({title:s("settings.toast.clearAllFailure",{message:l.message})})}),[d,N]=m.useState(null),[C,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,B]=m.useState({}),[Ke,se]=m.useState(!1),[qe,ae]=m.useState(!1),[_e,ne]=m.useState(!1),[Ve,Be]=m.useState(!1),[Ie,$e]=m.useState(!1),[j,le]=m.useState(null),[f,D]=m.useState({enabled:!1,username:"",password:"",confirmPassword:""}),[We,K]=m.useState({}),[Ge,re]=m.useState(!1),Je=m.useMemo(()=>{if(!(d!=null&&d.defaults))return null;const l=[];return d.defaults.completion&&l.push(s("settings.defaults.completion",{model:d.defaults.completion})),d.defaults.reasoning&&l.push(s("settings.defaults.reasoning",{model:d.defaults.reasoning})),d.defaults.background&&l.push(s("settings.defaults.background",{model:d.defaults.background})),l.length>0?l.join(" | "):s("settings.defaults.none")},[d,s]),Qe=m.useMemo(()=>u.httpEnabled&&u.httpsEnabled?s("settings.overview.values.httpAndHttps"):u.httpsEnabled?s("settings.overview.values.httpsOnly"):s("settings.overview.values.httpOnly"),[u.httpEnabled,u.httpsEnabled,s]),ze=m.useMemo(()=>f.enabled?j!=null&&j.hasPassword?f.username.trim()!==(j.username??""):!0:!1,[f.enabled,f.username,j]),O=m.useMemo(()=>d?z(d):null,[d]),Xe=m.useMemo(()=>O?JSON.stringify(u)!==JSON.stringify(O):!1,[u,O]),I=m.useMemo(()=>j?X(j):null,[j]),Ue=m.useMemo(()=>I?JSON.stringify(f)!==JSON.stringify(I):!1,[f,I]),Ye=m.useMemo(()=>O?["httpEnabled","httpPort","httpHost","httpsEnabled","httpsPort","httpsHost","httpsKeyPath","httpsCertPath","httpsCaPath","port","host"].some(x=>u[x]!==O[x]):!1,[u,O]);m.useEffect(()=>{i.data&&(N(i.data.config),He(i.data.path),H(z(i.data.config)))},[i.data]),m.useEffect(()=>{h.data&&(le(h.data),D(X(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(l=>x=>{H(y=>({...y,[l]:x}))},[]),oe=m.useCallback(()=>{const l={};if(!u.httpEnabled&&!u.httpsEnabled&&(l.protocol=s("settings.validation.protocolRequired")),u.httpEnabled){const S=Number(u.httpPort);(!Number.isFinite(S)||S<1||S>65535)&&(l.httpPort=s("settings.validation.httpPort"))}if(u.httpsEnabled){const S=Number(u.httpsPort);(!Number.isFinite(S)||S<1||S>65535)&&(l.httpsPort=s("settings.validation.httpsPort")),(!u.httpsKeyPath||!u.httpsCertPath)&&(l.protocol=s("settings.validation.httpsCertificate"))}const x=Number(u.port);(!Number.isFinite(x)||x<1||x>65535)&&(l.port=s("settings.validation.port"));const y=Number(u.logRetentionDays);(!Number.isFinite(y)||y<1||y>365)&&(l.logRetentionDays=s("settings.validation.retention"));const P=Number(u.logExportTimeoutSeconds);(!Number.isFinite(P)||P<5||P>600)&&(l.logExportTimeoutSeconds=s("settings.validation.logExportTimeout"));const F=Number(u.bodyLimitMb);return(!Number.isFinite(F)||F<1||F>2048)&&(l.bodyLimitMb=s("settings.validation.bodyLimit")),B(l),Object.keys(l).length===0},[u,s]),ie=m.useCallback(()=>{const l={},x=f.username.trim(),y=j?x!==(j.username??""):!0,P=f.enabled&&(!(j!=null&&j.hasPassword)||y);return f.enabled&&!x&&(l.username=s("settings.auth.validation.username")),f.password&&f.password.length<6&&(l.password=s("settings.auth.validation.minLength")),P&&!f.password&&(l.password=s("settings.auth.validation.passwordRequired")),(f.password||f.confirmPassword)&&f.password!==f.confirmPassword&&(l.confirmPassword=s("settings.auth.validation.confirmMismatch")),K(l),Object.keys(l).length===0},[f,j,s]),et=m.useCallback(async()=>{var l,x,y,P,F,S,ce,de,ue,me,pe,he,xe,ge,fe,be,ve,je,ye,Ne,we,Ce,Pe,ke,Se,Re;if(!d){t({title:s("settings.toast.loadFailure",{message:s("settings.toast.missingConfig")}),variant:"error"});return}if(oe()){se(!0);try{const q=Number(u.port),ot=Number(u.logRetentionDays),it=Number(u.logExportTimeoutSeconds),ct=Number(u.bodyLimitMb),b={...d,http:{enabled:u.httpEnabled,port:Number(u.httpPort),host:u.httpHost.trim()||"127.0.0.1"},https:{enabled:u.httpsEnabled,port:Number(u.httpsPort),host:u.httpsHost.trim()||"127.0.0.1",keyPath:u.httpsKeyPath.trim(),certPath:u.httpsCertPath.trim(),caPath:u.httpsCaPath.trim()||void 0},port:q,host:u.host.trim()||void 0,logRetentionDays:ot,logExportTimeoutSeconds:Math.min(Math.max(Math.round(it),5),600),storeRequestPayloads:u.storeRequestPayloads,storeResponsePayloads:u.storeResponsePayloads,logLevel:u.logLevel,bodyLimit:Math.max(1,Math.floor(ct*1024*1024)),enableRoutingFallback:u.enableRoutingFallback};delete b.requestLogging,delete b.responseLogging;const Ee={...b};delete Ee.webAuth,await Oe.saveConfig(Ee),N({...b,webAuth:d.webAuth});const Ae=W=>(W==null?void 0:W.trim())||void 0,dt=d.port??((l=d.http)==null?void 0:l.port)??4100,ut=b.port??((x=b.http)==null?void 0:x.port)??4100,mt=((y=d.host)==null?void 0:y.trim())||((F=(P=d.http)==null?void 0:P.host)==null?void 0:F.trim())||"127.0.0.1",pt=((S=b.host)==null?void 0:S.trim())||((de=(ce=b.http)==null?void 0:ce.host)==null?void 0:de.trim())||"127.0.0.1",ht=dt!==ut||mt!==pt||((ue=d.http)==null?void 0:ue.enabled)!==((me=b.http)==null?void 0:me.enabled)||((pe=d.http)==null?void 0:pe.port)!==((he=b.http)==null?void 0:he.port)||(((xe=d.http)==null?void 0:xe.host)??d.host??"127.0.0.1")!==(((ge=b.http)==null?void 0:ge.host)??b.host??"127.0.0.1")||((fe=d.https)==null?void 0:fe.enabled)!==((be=b.https)==null?void 0:be.enabled)||((ve=d.https)==null?void 0:ve.port)!==((je=b.https)==null?void 0:je.port)||(((ye=d.https)==null?void 0:ye.host)??d.host??"127.0.0.1")!==(((Ne=b.https)==null?void 0:Ne.host)??b.host??"127.0.0.1")||((we=d.https)==null?void 0:we.keyPath)!==((Ce=b.https)==null?void 0:Ce.keyPath)||((Pe=d.https)==null?void 0:Pe.certPath)!==((ke=b.https)==null?void 0:ke.certPath)||Ae((Se=d.https)==null?void 0:Se.caPath)!==Ae((Re=b.https)==null?void 0:Re.caPath);t({title:s(ht?"settings.toast.protocolRestartRequired":"settings.toast.saveSuccess"),variant:"success"}),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)),B({}))},[d]),st=m.useCallback(async()=>{if(ie()){re(!0);try{const l={enabled:f.enabled,username:f.username.trim()||void 0};f.password&&(l.password=f.password);const x=await p.mutateAsync(l);x.auth&&(le(x.auth),D({enabled:x.auth.enabled,username:x.auth.username??"",password:"",confirmPassword:""}),K({})),h.refetch()}catch{}finally{re(!1)}}},[f,h,p,ie]),at=m.useCallback(()=>{j&&(D(X(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(l){t({title:s("settings.toast.copyFailure",{message:l instanceof Error?l.message:"unknown"}),variant:"error"})}},[C,t,s]),lt=m.useCallback(async()=>{ae(!0);try{await T.mutateAsync()}catch{}finally{ae(!1)}},[T]),rt=m.useCallback(async()=>{ne(!0);try{await g.mutateAsync()}catch{}finally{ne(!1)}},[g]),$=i.isPending||!d&&i.isFetching;return m.useEffect(()=>{if($)return;const l=Array.from(r.current.values());if(l.length===0)return;const x=new IntersectionObserver(y=>{for(const P of y)if(P.isIntersecting){o(P.target.id);break}},{rootMargin:"-80px 0px -60% 0px",threshold:0});for(const y of l)x.observe(y);return()=>x.disconnect()},[$]),{activeSection:n,authErrors:We,authForm:f,authQuery:h,authSettings:j,clearingAll:_e,cleaning:qe,config:d,configPath:C,configQuery:i,confirmCleanupOpen:Ve,confirmClearAllOpen:Ie,defaultsSummary:Je,errors:De,form:u,handleAuthReset:at,handleAuthSave:st,handleCleanupLogs:lt,handleClearAllLogs:rt,handleCopyPath:nt,handleInputChange:Ze,handleReset:tt,handleSave:et,handleSectionClick:c,isAuthDirty:Ue,isConfigDirty:Xe,isLoading:$,needsPassword:ze,protocolSummaryLabel:Qe,protocolChangesPending:Ye,saving:Ke,savingAuth:Ge,sectionRefs:r,setAuthForm:D,setConfirmCleanupOpen:Be,setConfirmClearAllOpen:$e,setErrors:B,setForm:H,setSectionRef:a,t:s}}function ns(){var r,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(ft,{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-full bg-secondary px-3.5 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,{className:"bg-card/82",children:e.jsx(L,{className:"flex min-h-[220px] items-center justify-center",children:e.jsx(Fe,{})})}):t.config?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid gap-6 xl:grid-cols-[200px_1fr]",children:[e.jsx(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:((r=t.authSettings)==null?void 0:r.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,{className:"bg-card/82",children:e.jsx(L,{className:"pt-6",children:e.jsx("p",{className:"text-sm font-medium text-destructive",children:s("settings.toast.missingConfig")})})}),e.jsx(Le,{open:t.confirmCleanupOpen,onOpenChange: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{ns as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as s}from"./vendor-LWJeAdU1.js";import{c as n}from"./global-
|
|
1
|
+
import{j as s}from"./vendor-LWJeAdU1.js";import{c as n}from"./global-NDOUShP9.js";function e({className:a}){return s.jsx("div",{role:"status","aria-label":"Loading",className:n("animate-pulse rounded-xl bg-muted",a)})}function o(){return s.jsxs("div",{className:"space-y-3 rounded-xl bg-card/86 p-6 shadow-[var(--surface-shadow)]",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx(e,{className:"h-3 w-24"}),s.jsx(e,{className:"h-10 w-10 rounded-xl"})]}),s.jsx(e,{className:"h-8 w-32"})]})}function x(){return s.jsxs("div",{className:"space-y-4 rounded-xl bg-card/86 p-6 shadow-[var(--surface-shadow)]",children:[s.jsxs("div",{className:"space-y-2",children:[s.jsx(e,{className:"h-4 w-32"}),s.jsx(e,{className:"h-3 w-48"})]}),s.jsx(e,{className:"h-[320px] w-full rounded-xl"})]})}function m({columns:a=6}){const r=["w-24","w-16","w-20","w-28","w-14","w-12","w-20","w-16","w-14","w-12"];return s.jsx("tr",{className:"border-b",children:Array.from({length:a}).map((c,l)=>s.jsx("td",{className:"px-3 py-3",children:s.jsx(e,{className:n("h-4",r[l%r.length])})},l))})}export{x as C,o as S,m as T};
|