@chenpu17/cc-gw 0.9.0-beta.0 → 0.9.0-beta.1
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-DY21fypB.js → About-WPCkWxkz.js} +1 -1
- package/src/web/dist/assets/{ApiKeys-FWkRLPTy.js → ApiKeys-Q-EteBox.js} +1 -1
- package/src/web/dist/assets/{ConfirmDialog-CyTpXZeT.js → ConfirmDialog-CvC_VLb2.js} +1 -1
- package/src/web/dist/assets/{Dashboard-FKM-9UNt.js → Dashboard-Q99L2W8N.js} +1 -1
- package/src/web/dist/assets/{Events-x_fSf1mz.js → Events-CBVp1fVz.js} +1 -1
- package/src/web/dist/assets/{Help-BMgllYJq.js → Help-M3pIEoJN.js} +1 -1
- package/src/web/dist/assets/{Login-DrtDFqbk.js → Login-DtAkFJMT.js} +1 -1
- package/src/web/dist/assets/{Logs-18flgbiW.js → Logs-CIPbrHMJ.js} +1 -1
- package/src/web/dist/assets/{ProvidersWorkbench-aHO5-ApY.js → ProvidersWorkbench-DvlPlloy.js} +1 -1
- package/src/web/dist/assets/{Settings-iEjCAGgm.js → Settings-CNI4qHrl.js} +1 -1
- package/src/web/dist/assets/{Setup-B1j2zExa.js → Setup-CfD6U8Nf.js} +1 -1
- package/src/web/dist/assets/{apiKeys-k1jIJuDa.js → apiKeys-CoQ69TK_.js} +1 -1
- package/src/web/dist/assets/{app-Citq5KW4.js → app-czRBzLXv.js} +2 -2
- package/src/web/dist/assets/{gateway-i49olSPp.js → gateway-Dxoj2rj4.js} +1 -1
- package/src/web/dist/assets/{landing-W4f2Nx8j.js → landing-DBrU8FIr.js} +1 -1
- package/src/web/dist/assets/package-BXeeAB6b.js +1 -0
- package/src/web/dist/assets/{shared-Cuakym23.js → shared-HT9X1BTy.js} +1 -1
- package/src/web/dist/assets/{useAppMutation-CEN5Oa4S.js → useAppMutation-DbIs5qvT.js} +1 -1
- package/src/web/dist/assets/{useProviderForm-DZEYuRhD.js → useProviderForm-BiVzWP3H.js} +1 -1
- package/src/web/dist/index.html +1 -1
- package/src/web/dist/landing.html +2 -2
- package/src/web/dist/assets/package-B2CgmdJ7.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as e,aW as Y,aP as xt,ak as ft,r as d}from"./vendor-CITafuNQ.js";import{C as He}from"./ConfirmDialog-CyTpXZeT.js";import{P as Ve}from"./PageState-CFLrRswm.js";import{P as bt}from"./PageToolbar-CWw40AFL.js";import{C as k,a as L}from"./card-D4YOc5eB.js";import{B as O,r as Ke,i as vt,d as yt,a as jt,c as De,q as Z}from"./app-Citq5KW4.js";import{B as V}from"./badge-DpUlf_NW.js";import{L as f,I as j}from"./label-DSVzZIex.js";import{S as B}from"./switch-7PH_rDz6.js";import{S as Nt,a as wt,b as Ct,c as Pt,d as kt}from"./select-sOwKYsgI.js";import{c as E}from"./global-BCehxTGJ.js";import{u as P}from"./i18n-PeX9kBVO.js";import{u as ee}from"./useAppMutation-CEN5Oa4S.js";import{g as qe}from"./gateway-i49olSPp.js";import{c as St}from"./clipboard-BnAnBk_-.js";import"./DialogShell-CM92wXHo.js";import"./radix-Bux_1C5J.js";import"./query-DZF7K6hv.js";import"./router-BoBrmro7.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"}],oe=[{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 te(t){var o,m,l,i,a,p,y,A,T,u,M;const s=t.storePayloads,r=N=>typeof N=="boolean"?N:typeof s=="boolean"?s:!0;return{port:String(t.port??((o=t.http)==null?void 0:o.port)??""),host:t.host??((m=t.http)==null?void 0:m.host)??"127.0.0.1",logRetentionDays:String(t.logRetentionDays??30),logExportTimeoutSeconds:String(t.logExportTimeoutSeconds??60),storeRequestPayloads:r(t.storeRequestPayloads),storeResponsePayloads:r(t.storeResponsePayloads),logLevel:t.logLevel??"info",bodyLimitMb:(()=>{const N=t.bodyLimit;return typeof N=="number"&&Number.isFinite(N)&&N>0?String(Math.max(1,Math.round(N/(1024*1024)))):"10"})(),enableRoutingFallback:t.enableRoutingFallback===!0,httpEnabled:((l=t.http)==null?void 0:l.enabled)!==!1,httpPort:String(((i=t.http)==null?void 0:i.port)??t.port??4100),httpHost:((a=t.http)==null?void 0:a.host)??t.host??"127.0.0.1",httpsEnabled:((p=t.https)==null?void 0:p.enabled)===!0,httpsPort:String(((y=t.https)==null?void 0:y.port)??4443),httpsHost:((A=t.https)==null?void 0:A.host)??t.host??"127.0.0.1",httpsKeyPath:((T=t.https)==null?void 0:T.keyPath)??"",httpsCertPath:((u=t.https)==null?void 0:u.certPath)??"",httpsCaPath:((M=t.https)==null?void 0:M.caPath)??""}}function se(t){return{enabled:t.enabled,username:t.username??"",password:"",confirmPassword:""}}function Et({activeSection:t,onSelectSection:s}){const{t:r}=P();return e.jsxs(e.Fragment,{children:[e.jsx("nav",{className:"hidden xl:block",children:e.jsxs(k,{className:"sticky top-20 p-3.5",children:[e.jsx("p",{className:"mb-2.5 px-2 text-[10px] font-semibold uppercase tracking-wider text-muted-foreground",children:r("settings.sections.jump")}),e.jsx("div",{className:"space-y-1.5",children:oe.map((o,m)=>e.jsxs("button",{type:"button",onClick:()=>s(o.id),className:E("flex w-full items-center gap-2.5 rounded-lg px-3 py-2 text-left text-sm font-semibold transition-all duration-200",t===o.id?"bg-secondary text-foreground":"text-muted-foreground hover:text-foreground"),children:[e.jsx("span",{className:E("flex h-7 w-7 items-center justify-center rounded-lg text-[11px] font-semibold",t===o.id?"bg-primary text-primary-foreground":"bg-secondary text-muted-foreground"),children:m+1}),e.jsx("span",{children:r(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:oe.map(o=>e.jsx("button",{type:"button",onClick:()=>s(o.id),className:E("rounded-lg px-4 py-2 text-xs font-semibold transition-all duration-150",t===o.id?"bg-secondary text-foreground font-medium":"text-muted-foreground hover:text-foreground hover:bg-secondary/50"),children:r(o.labelKey)},o.id))})})})]})}function Lt({defaultsSummary:t,errors:s,form:r,onInputChange:o,onSetForm:m,sectionRef:l}){const{t:i}=P();return e.jsx(k,{id:"section-basics",ref:l,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:i("settings.sections.basics")}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:i("settings.description")})]}),e.jsxs("div",{className:"grid gap-2 sm:grid-cols-3",children:[e.jsx(ae,{label:i("settings.fields.retention"),value:r.logRetentionDays}),e.jsx(ae,{label:i("settings.fields.logExportTimeout"),value:`${r.logExportTimeoutSeconds}s`}),e.jsx(ae,{label:i("settings.fields.bodyLimit"),value:`${r.bodyLimitMb} MB`})]})]}),e.jsxs("div",{className:"grid gap-5 md:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(f,{children:i("settings.fields.port")}),e.jsx(j,{type:"number",min:1,max:65535,value:r.port,onChange:a=>o("port")(a.target.value),"aria-invalid":!!s.port}),s.port?e.jsx("p",{className:"text-xs text-destructive",children:s.port}):null]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(f,{children:i("settings.fields.host")}),e.jsx(j,{value:r.host,onChange:a=>o("host")(a.target.value),placeholder:i("settings.fields.hostPlaceholder")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(f,{children:i("settings.fields.retention")}),e.jsx(j,{type:"number",min:1,max:365,value:r.logRetentionDays,onChange:a=>o("logRetentionDays")(a.target.value),"aria-invalid":!!s.logRetentionDays}),s.logRetentionDays?e.jsx("p",{className:"text-xs text-destructive",children:s.logRetentionDays}):null]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(f,{children:i("settings.fields.logExportTimeout")}),e.jsx(j,{type:"number",min:5,max:600,value:r.logExportTimeoutSeconds,onChange:a=>o("logExportTimeoutSeconds")(a.target.value),"aria-invalid":!!s.logExportTimeoutSeconds}),e.jsx("p",{className:"text-xs text-muted-foreground",children:i("settings.fields.logExportTimeoutHint")}),s.logExportTimeoutSeconds?e.jsx("p",{className:"text-xs text-destructive",children:s.logExportTimeoutSeconds}):null]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(f,{children:i("settings.fields.bodyLimit")}),e.jsx(j,{type:"number",min:1,max:2048,value:r.bodyLimitMb,onChange:a=>o("bodyLimitMb")(a.target.value),"aria-invalid":!!s.bodyLimitMb}),e.jsx("p",{className:"text-xs text-muted-foreground",children:i("settings.fields.bodyLimitHint")}),s.bodyLimitMb?e.jsx("p",{className:"text-xs text-destructive",children:s.bodyLimitMb}):null]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(f,{children:i("settings.fields.logLevel")}),e.jsxs(Nt,{value:r.logLevel,onValueChange:a=>m(p=>({...p,logLevel:a})),children:[e.jsx(wt,{children:e.jsx(Ct,{})}),e.jsx(Pt,{children:Rt.map(a=>e.jsx(kt,{value:a.value,children:i(`settings.fields.logLevelOption.${a.labelKey}`)},a.value))})]})]}),e.jsxs("div",{className:"grid gap-4 md:col-span-2 sm:grid-cols-2",children:[e.jsx(ne,{label:i("settings.fields.storeRequestPayloads"),hint:i("settings.fields.storeRequestPayloadsHint"),checked:r.storeRequestPayloads,onCheckedChange:a=>m(p=>({...p,storeRequestPayloads:a}))}),e.jsx(ne,{label:i("settings.fields.storeResponsePayloads"),hint:i("settings.fields.storeResponsePayloadsHint"),checked:r.storeResponsePayloads,onCheckedChange:a=>m(p=>({...p,storeResponsePayloads:a}))}),e.jsx(ne,{label:i("settings.fields.enableRoutingFallback"),hint:i("settings.fields.enableRoutingFallbackHint"),checked:r.enableRoutingFallback,onCheckedChange:a=>m(p=>({...p,enableRoutingFallback:a}))})]}),e.jsxs("div",{className:"rounded-xl bg-secondary px-4 py-5 md:col-span-2",children:[e.jsx(f,{className:"text-xs uppercase tracking-wide text-muted-foreground",children:i("settings.fields.defaults")}),e.jsx("p",{className:"mt-2 text-sm",children:t??i("settings.defaults.none")})]})]})]})})}function At({errors:t,form:s,onSetForm:r,protocolChangesPending:o,sectionRef:m}){const{t:l}=P();return e.jsx(k,{id:"section-protocol",ref:m,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:l("settings.sections.protocol")}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:l("settings.protocol.description")})]}),o?e.jsx("div",{className:"rounded-xl bg-warning-bg ring-1 ring-warning/30 p-4",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(Y,{className:"mt-0.5 h-5 w-5 flex-shrink-0 text-warning"}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm font-medium text-foreground",children:l("settings.protocol.restartWarning")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:l("settings.protocol.restartHint")}),e.jsx("code",{className:"block rounded-lg border border-border bg-secondary px-3 py-2 text-xs font-mono text-foreground",children:"cc-gw restart --daemon"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:l("settings.protocol.restartTip")})]})]})}):null,t.protocol?e.jsxs("div",{className:"rounded-xl bg-destructive/10 ring-1 ring-destructive/30 p-4 text-sm text-destructive",children:[e.jsx(Y,{className:"mr-2 inline h-4 w-4"}),t.protocol]}):null,e.jsxs("div",{className:"rounded-xl bg-secondary p-5",children:[e.jsxs("div",{className:"mb-4 flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(f,{className:"text-sm font-medium text-foreground",children:l("settings.protocol.http.enable")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:l("settings.protocol.http.hint")})]}),e.jsx(B,{checked:s.httpEnabled,onCheckedChange:i=>r(a=>({...a,httpEnabled:i}))})]}),s.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(f,{children:l("settings.protocol.http.port")}),e.jsx(j,{type:"number",min:1,max:65535,value:s.httpPort,onChange:i=>r(a=>({...a,httpPort:i.target.value})),"aria-invalid":!!t.httpPort}),t.httpPort?e.jsx("p",{className:"text-xs text-destructive",children:t.httpPort}):null]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(f,{children:l("settings.protocol.http.host")}),e.jsx(j,{value:s.httpHost,onChange:i=>r(a=>({...a,httpHost:i.target.value})),placeholder:"127.0.0.1"})]})]}):null]}),e.jsxs("div",{className:"rounded-xl bg-secondary p-5",children:[e.jsxs("div",{className:"mb-4 flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(f,{className:"text-sm font-medium text-foreground",children:l("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:l("settings.protocol.https.hint")})]}),e.jsx(B,{checked:s.httpsEnabled,onCheckedChange:i=>r(a=>({...a,httpsEnabled:i}))})]}),s.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(f,{children:l("settings.protocol.https.port")}),e.jsx(j,{type:"number",min:1,max:65535,value:s.httpsPort,onChange:i=>r(a=>({...a,httpsPort:i.target.value})),"aria-invalid":!!t.httpsPort}),t.httpsPort?e.jsx("p",{className:"text-xs text-destructive",children:t.httpsPort}):null]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(f,{children:l("settings.protocol.https.host")}),e.jsx(j,{value:s.httpsHost,onChange:i=>r(a=>({...a,httpsHost:i.target.value})),placeholder:"127.0.0.1"})]})]}),e.jsx(le,{label:l("settings.protocol.https.keyPath"),value:s.httpsKeyPath,onChange:i=>r(a=>({...a,httpsKeyPath:i})),placeholder:"~/.cc-gw/certs/key.pem"}),e.jsx(le,{label:l("settings.protocol.https.certPath"),value:s.httpsCertPath,onChange:i=>r(a=>({...a,httpsCertPath:i})),placeholder:"~/.cc-gw/certs/cert.pem"}),e.jsx(le,{label:l("settings.protocol.https.caPath"),value:s.httpsCaPath,onChange:i=>r(a=>({...a,httpsCaPath:i})),placeholder:"留空则不使用"}),e.jsx("div",{className:"rounded-xl bg-warning-bg ring-1 ring-warning/30 p-4",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(Y,{className:"mt-0.5 h-5 w-5 flex-shrink-0 text-warning"}),e.jsxs("div",{className:"flex-1 space-y-1.5",children:[e.jsx("p",{className:"text-sm font-medium text-warning",children:l("settings.protocol.https.warning")}),e.jsx("p",{className:"text-xs leading-relaxed text-warning",children:l("settings.protocol.https.tip")})]})]})})]}):null]})]})})}function Tt({authErrors:t,authForm:s,authLoading:r,authSettings:o,needsPassword:m,onSetAuthForm:l,sectionRef:i}){const{t:a}=P();return e.jsx(k,{id:"section-security",ref:i,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:a("settings.sections.security")}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:a("settings.auth.description")})]}),r&&!o?e.jsx(Ve,{compact:!0,label:a("common.loading")}):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(f,{className:"text-sm font-medium",children:a("settings.auth.enable")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a("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-lg bg-secondary px-3 py-1 text-[11px] tracking-[0.08em]",children:"/ui"}),e.jsx("span",{className:"rounded-lg bg-secondary px-3 py-1 text-[11px] tracking-[0.08em]",children:"/api/*"}),e.jsx("span",{className:"rounded-lg 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(V,{variant:s.enabled?"success":"secondary",children:s.enabled?a("settings.auth.statusEnabled"):a("settings.auth.statusDisabled")}),e.jsx(B,{checked:s.enabled,onCheckedChange:p=>l(y=>({...y,enabled:p}))})]})]}),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(f,{children:a("settings.auth.username")}),e.jsx(j,{value:s.username,onChange:p=>l(y=>({...y,username:p.target.value})),placeholder:a("settings.auth.usernamePlaceholder")}),t.username?e.jsx("p",{className:"text-xs text-destructive",children:t.username}):null]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(f,{children:a("settings.auth.password")}),e.jsx(j,{type:"password",value:s.password,disabled:!s.enabled,onChange:p=>l(y=>({...y,password:p.target.value})),placeholder:a("settings.auth.passwordPlaceholder")}),t.password?e.jsx("p",{className:"text-xs text-destructive",children:t.password}):e.jsx("p",{className:"text-xs text-muted-foreground",children:a(m?"settings.auth.passwordHintRequired":"settings.auth.passwordHintOptional")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(f,{children:a("settings.auth.confirmPassword")}),e.jsx(j,{type:"password",value:s.confirmPassword,disabled:!s.enabled,onChange:p=>l(y=>({...y,confirmPassword:p.target.value})),placeholder:a("settings.auth.confirmPasswordPlaceholder")}),t.confirmPassword?e.jsx("p",{className:"text-xs text-destructive",children:t.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:a("settings.auth.status")}),e.jsx("p",{className:"mt-2 text-base font-semibold",children:o!=null&&o.enabled?a("settings.auth.statusEnabled"):a("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:[a("settings.auth.username"),": ",o.username]}):null]}),e.jsx("div",{className:"rounded-xl bg-secondary px-4 py-3 text-xs text-muted-foreground",children:a(m?"settings.auth.passwordHintRequired":"settings.auth.passwordHintOptional")})]})]})]})]})})}function Mt({configPath:t,onCopyPath:s,sectionRef:r}){const{t:o}=P();return e.jsx(k,{id:"section-config-file",ref:r,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(O,{variant:"outline",size:"sm",onClick:s,className:"w-full sm:w-auto",children:[e.jsx(ft,{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:t||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 Ot({cleaning:t,clearingAll:s,onOpenCleanup:r,onOpenClearAll:o,sectionRef:m}){const{t:l}=P();return e.jsx(k,{id:"section-cleanup",ref:m,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:l("settings.sections.cleanup")}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:l("settings.cleanup.description")})]}),e.jsx("div",{className:"rounded-lg bg-secondary px-4 py-3 text-xs text-muted-foreground",children:l("settings.cleanup.confirmCleanup")}),e.jsxs("div",{className:"grid gap-4 lg:grid-cols-2",children:[e.jsx("div",{className:"rounded-xl border border-warning/30 bg-warning-bg p-5",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx(V,{variant:"warning",children:l("settings.cleanup.softLabel")}),e.jsx("p",{className:"text-sm font-medium",children:l("settings.cleanup.softTitle")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:l("settings.cleanup.softDescription")}),e.jsx(O,{variant:"outline",onClick:r,disabled:t,className:"w-full sm:w-auto",children:l(t?"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(V,{variant:"outline",className:"border-destructive/40 bg-destructive/10 text-destructive",children:l("settings.cleanup.hardLabel")}),e.jsx("p",{className:"text-sm font-medium",children:l("settings.cleanup.hardTitle")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:l("settings.cleanup.clearAllWarning")}),e.jsx(O,{variant:"destructive",onClick:o,disabled:s,className:"w-full sm:w-auto",children:l(s?"settings.cleanup.clearingAll":"settings.cleanup.clearAll")})]})})]})]})})}function Ft({dirtyCount:t,protocolChangesPending:s,onReset:r,onSave:o,saving:m}){const{t:l}=P();return t===0?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-[var(--surface-shadow-lg)] md:flex-row md:items-center md:justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(V,{variant:"secondary",children:l("settings.overview.unsavedCount",{count:t})}),e.jsx("p",{className:"text-sm text-muted-foreground",children:l(s?"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:[e.jsx(O,{variant:"outline",onClick:r,disabled:m,className:"w-full lg:w-auto",children:l("common.actions.reset")}),e.jsx(O,{onClick:o,disabled:m,className:"w-full lg:w-auto",children:l(m?"common.actions.saving":"common.actions.save")})]})]})}function ae({label:t,value:s}){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:t}),e.jsx("p",{className:"mt-1 text-sm font-semibold text-foreground",children:s})]})}function ne({checked:t,className:s,hint:r,hintClassName:o,label:m,labelClassName:l,onCheckedChange:i}){return e.jsxs("div",{className:E("flex flex-col gap-3 rounded-xl bg-secondary p-4 sm:flex-row sm:items-center sm:justify-between",s),children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(f,{className:E("text-sm font-semibold text-foreground",l),children:m}),e.jsx("p",{className:E("text-xs text-muted-foreground",o),children:r})]}),e.jsx(B,{checked:t,onCheckedChange:i,className:"self-start sm:self-auto"})]})}function le({label:t,onChange:s,placeholder:r,value:o}){return e.jsxs("div",{className:"space-y-2",children:[e.jsx(f,{children:t}),e.jsx(j,{value:o,onChange:m=>s(m.target.value),placeholder:r,className:"font-mono text-xs"})]})}const q={authStatusRequest(){return{url:"/api/auth/web",method:"GET"}},saveWebAuth:async t=>vt(yt.post("/api/auth/web",t)),cleanupLogs:async()=>Ke({url:"/api/logs/cleanup",method:"POST"}),clearLogs:async()=>Ke({url:"/api/logs/clear",method:"POST"})};function Ht(){const{t}=P(),{pushToast:s}=jt(),[r,o]=d.useState(oe[0].id),m=d.useRef(new Map),l=d.useCallback(n=>{const h=m.current.get(n);h&&h.scrollIntoView({behavior:"smooth",block:"start"})},[]),i=d.useCallback(n=>h=>{h?m.current.set(n,h):m.current.delete(n)},[]),a=De(Z.config.info(),qe.configInfoRequest()),p=De(Z.auth.web(),q.authStatusRequest()),y=ee({mutationFn:q.saveWebAuth,successToast:()=>({title:t("settings.auth.toast.success")}),errorToast:n=>({title:t("settings.auth.toast.failure",{message:n.message})}),invalidateKeys:[Z.auth.web()]}),A=ee({mutationFn:q.cleanupLogs,successToast:n=>({title:n.deleted>0?t("settings.toast.cleanupSuccess",{count:n.deleted}):t("settings.toast.cleanupNone")}),errorToast:n=>({title:t("settings.toast.cleanupFailure",{message:n.message})}),invalidateKeys:[["logs"],["dashboard"],["db"]]}),T=ee({mutationFn:q.clearLogs,successToast:n=>({title:t("settings.toast.clearAllSuccess",{logs:n.deleted,metrics:n.metricsCleared})}),errorToast:n=>({title:t("settings.toast.clearAllFailure",{message:n.message})}),invalidateKeys:[["logs"],["stats"],["dashboard"],["db"]]}),[u,M]=d.useState(null),[N,Be]=d.useState(""),[c,F]=d.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:""}),[Ie,I]=d.useState({}),[We,ie]=d.useState(!1),[Je,re]=d.useState(!1),[Qe,ce]=d.useState(!1),[_e,ze]=d.useState(!1),[Ge,$e]=d.useState(!1),[b,de]=d.useState(null),[g,H]=d.useState({enabled:!1,username:"",password:"",confirmPassword:""}),[Ue,K]=d.useState({}),[Xe,ue]=d.useState(!1),Ye=d.useMemo(()=>{if(!(u!=null&&u.defaults))return null;const n=[];return u.defaults.completion&&n.push(t("settings.defaults.completion",{model:u.defaults.completion})),u.defaults.reasoning&&n.push(t("settings.defaults.reasoning",{model:u.defaults.reasoning})),u.defaults.background&&n.push(t("settings.defaults.background",{model:u.defaults.background})),n.length>0?n.join(" | "):t("settings.defaults.none")},[u,t]),Ze=d.useMemo(()=>c.httpEnabled&&c.httpsEnabled?t("settings.overview.values.httpAndHttps"):c.httpsEnabled?t("settings.overview.values.httpsOnly"):t("settings.overview.values.httpOnly"),[c.httpEnabled,c.httpsEnabled,t]),et=d.useMemo(()=>g.enabled?b!=null&&b.hasPassword?g.username.trim()!==(b.username??""):!0:!1,[g.enabled,g.username,b]),S=d.useMemo(()=>u?te(u):null,[u]),W=d.useMemo(()=>S?JSON.stringify(c)!==JSON.stringify(S):!1,[c,S]),J=d.useMemo(()=>b?se(b):null,[b]),Q=d.useMemo(()=>J?JSON.stringify(g)!==JSON.stringify(J):!1,[g,J]),tt=d.useMemo(()=>S?["httpEnabled","httpPort","httpHost","httpsEnabled","httpsPort","httpsHost","httpsKeyPath","httpsCertPath","httpsCaPath","port","host"].some(h=>c[h]!==S[h]):!1,[c,S]);d.useEffect(()=>{a.data&&(M(a.data.config),Be(a.data.path),F(te(a.data.config)))},[a.data]),d.useEffect(()=>{p.data&&(de(p.data),H(se(p.data)),K({}))},[p.data]),d.useEffect(()=>{!a.isError||!a.error||s({title:t("settings.toast.loadFailure",{message:a.error.message}),variant:"error"})},[a.error,a.isError,s,t]),d.useEffect(()=>{!p.isError||!p.error||s({title:t("settings.toast.authLoadFailure",{message:p.error.message}),variant:"error"})},[p.error,p.isError,s,t]);const st=d.useCallback(n=>h=>{F(v=>({...v,[n]:h}))},[]),pe=d.useCallback(()=>{const n={};if(!c.httpEnabled&&!c.httpsEnabled&&(n.protocol=t("settings.validation.protocolRequired")),c.httpEnabled){const C=Number(c.httpPort);(!Number.isFinite(C)||C<1||C>65535)&&(n.httpPort=t("settings.validation.httpPort"))}if(c.httpsEnabled){const C=Number(c.httpsPort);(!Number.isFinite(C)||C<1||C>65535)&&(n.httpsPort=t("settings.validation.httpsPort")),(!c.httpsKeyPath||!c.httpsCertPath)&&(n.protocol=t("settings.validation.httpsCertificate"))}const h=Number(c.port);(!Number.isFinite(h)||h<1||h>65535)&&(n.port=t("settings.validation.port"));const v=Number(c.logRetentionDays);(!Number.isFinite(v)||v<1||v>365)&&(n.logRetentionDays=t("settings.validation.retention"));const w=Number(c.logExportTimeoutSeconds);(!Number.isFinite(w)||w<5||w>600)&&(n.logExportTimeoutSeconds=t("settings.validation.logExportTimeout"));const R=Number(c.bodyLimitMb);return(!Number.isFinite(R)||R<1||R>2048)&&(n.bodyLimitMb=t("settings.validation.bodyLimit")),I(n),Object.keys(n).length===0},[c,t]),me=d.useCallback(()=>{const n={},h=g.username.trim(),v=b?h!==(b.username??""):!0,w=g.enabled&&(!(b!=null&&b.hasPassword)||v);return g.enabled&&!h&&(n.username=t("settings.auth.validation.username")),g.password&&g.password.length<6&&(n.password=t("settings.auth.validation.minLength")),w&&!g.password&&(n.password=t("settings.auth.validation.passwordRequired")),(g.password||g.confirmPassword)&&g.password!==g.confirmPassword&&(n.confirmPassword=t("settings.auth.validation.confirmMismatch")),K(n),Object.keys(n).length===0},[g,b,t]),_=d.useCallback(async()=>{var n,h,v,w,R,C,he,ge,xe,fe,be,ve,ye,je,Ne,we,Ce,Pe,ke,Se,Re,Ee,Le,Ae,Te,Me;if(!u){s({title:t("settings.toast.loadFailure",{message:t("settings.toast.missingConfig")}),variant:"error"});return}if(pe()){ie(!0);try{const D=Number(c.port),rt=Number(c.logRetentionDays),ct=Number(c.logExportTimeoutSeconds),dt=Number(c.bodyLimitMb),x={...u,http:{enabled:c.httpEnabled,port:Number(c.httpPort),host:c.httpHost.trim()||"127.0.0.1"},https:{enabled:c.httpsEnabled,port:Number(c.httpsPort),host:c.httpsHost.trim()||"127.0.0.1",keyPath:c.httpsKeyPath.trim(),certPath:c.httpsCertPath.trim(),caPath:c.httpsCaPath.trim()||void 0},port:D,host:c.host.trim()||void 0,logRetentionDays:rt,logExportTimeoutSeconds:Math.min(Math.max(Math.round(ct),5),600),storeRequestPayloads:c.storeRequestPayloads,storeResponsePayloads:c.storeResponsePayloads,logLevel:c.logLevel,bodyLimit:Math.max(1,Math.floor(dt*1024*1024)),enableRoutingFallback:c.enableRoutingFallback};delete x.requestLogging,delete x.responseLogging;const Oe={...x};delete Oe.webAuth,await qe.saveConfig(Oe),M({...x,webAuth:u.webAuth});const Fe=X=>(X==null?void 0:X.trim())||void 0,ut=u.port??((n=u.http)==null?void 0:n.port)??4100,pt=x.port??((h=x.http)==null?void 0:h.port)??4100,mt=((v=u.host)==null?void 0:v.trim())||((R=(w=u.http)==null?void 0:w.host)==null?void 0:R.trim())||"127.0.0.1",ht=((C=x.host)==null?void 0:C.trim())||((ge=(he=x.http)==null?void 0:he.host)==null?void 0:ge.trim())||"127.0.0.1",gt=ut!==pt||mt!==ht||((xe=u.http)==null?void 0:xe.enabled)!==((fe=x.http)==null?void 0:fe.enabled)||((be=u.http)==null?void 0:be.port)!==((ve=x.http)==null?void 0:ve.port)||(((ye=u.http)==null?void 0:ye.host)??u.host??"127.0.0.1")!==(((je=x.http)==null?void 0:je.host)??x.host??"127.0.0.1")||((Ne=u.https)==null?void 0:Ne.enabled)!==((we=x.https)==null?void 0:we.enabled)||((Ce=u.https)==null?void 0:Ce.port)!==((Pe=x.https)==null?void 0:Pe.port)||(((ke=u.https)==null?void 0:ke.host)??u.host??"127.0.0.1")!==(((Se=x.https)==null?void 0:Se.host)??x.host??"127.0.0.1")||((Re=u.https)==null?void 0:Re.keyPath)!==((Ee=x.https)==null?void 0:Ee.keyPath)||((Le=u.https)==null?void 0:Le.certPath)!==((Ae=x.https)==null?void 0:Ae.certPath)||Fe((Te=u.https)==null?void 0:Te.caPath)!==Fe((Me=x.https)==null?void 0:Me.caPath);s({title:t(gt?"settings.toast.protocolRestartRequired":"settings.toast.saveSuccess"),variant:"success"}),a.refetch()}catch(D){s({title:t("settings.toast.saveFailure",{message:D instanceof Error?D.message:"unknown"}),variant:"error"})}finally{ie(!1)}}},[u,a,c,s,t,pe]),z=d.useCallback(()=>{u&&(F(te(u)),I({}))},[u]),G=d.useCallback(async()=>{if(me()){ue(!0);try{const n={enabled:g.enabled,username:g.username.trim()||void 0};g.password&&(n.password=g.password);const h=await y.mutateAsync(n);h.auth&&(de(h.auth),H({enabled:h.auth.enabled,username:h.auth.username??"",password:"",confirmPassword:""}),K({})),p.refetch()}catch{}finally{ue(!1)}}},[g,p,y,me]),$=d.useCallback(()=>{b&&(H(se(b)),K({}))},[b]),at=d.useCallback(async()=>{W&&await _(),Q&&await G()},[G,_,Q,W]),nt=d.useCallback(()=>{z(),$()},[$,z]),lt=d.useCallback(async()=>{if(!N){s({title:t("settings.toast.copyFailure",{message:t("settings.file.unknown")}),variant:"error"});return}try{await St(N),s({title:t("settings.toast.copySuccess"),variant:"success"})}catch(n){s({title:t("settings.toast.copyFailure",{message:n instanceof Error?n.message:"unknown"}),variant:"error"})}},[N,s,t]),ot=d.useCallback(async()=>{re(!0);try{await A.mutateAsync()}catch{}finally{re(!1)}},[A]),it=d.useCallback(async()=>{ce(!0);try{await T.mutateAsync()}catch{}finally{ce(!1)}},[T]),U=a.isPending||!u&&a.isFetching;return d.useEffect(()=>{if(U)return;const n=Array.from(m.current.values());if(n.length===0)return;const h=new IntersectionObserver(v=>{for(const w of v)if(w.isIntersecting){o(w.target.id);break}},{rootMargin:"-80px 0px -60% 0px",threshold:0});for(const v of n)h.observe(v);return()=>h.disconnect()},[U]),{activeSection:r,authErrors:Ue,authForm:g,authQuery:p,authSettings:b,clearingAll:Qe,cleaning:Je,config:u,configPath:N,configQuery:a,confirmCleanupOpen:_e,confirmClearAllOpen:Ge,defaultsSummary:Ye,errors:Ie,form:c,handleAuthReset:$,handleAuthSave:G,handleCleanupLogs:ot,handleClearAllLogs:it,handleCopyPath:lt,handleInputChange:st,handleReset:z,handleResetAll:nt,handleSave:_,handleSaveAll:at,handleSectionClick:l,isAuthDirty:Q,isConfigDirty:W,isLoading:U,needsPassword:et,protocolSummaryLabel:Ze,protocolChangesPending:tt,saving:We,savingAuth:Xe,sectionRefs:m,setAuthForm:H,setConfirmCleanupOpen:ze,setConfirmClearAllOpen:$e,setErrors:I,setForm:F,setSectionRef:i,t}}function ss(){const{t}=P(),s=Ht(),r=Number(s.isConfigDirty)+Number(s.isAuthDirty);return e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx(bt,{info:r>0?e.jsx("span",{className:"rounded-lg bg-warning-bg px-2.5 py-1 text-xs font-medium text-warning",children:t("settings.overview.unsavedCount",{count:r})}):null,status:s.config?e.jsx("span",{className:"text-xs text-muted-foreground",children:s.protocolChangesPending?t("settings.protocol.restartWarning"):t("common.status.success")}):null,actions:null}),s.isLoading?e.jsx(Ve,{label:t("common.loading")}):s.config?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid gap-6 xl:grid-cols-[200px_1fr]",children:[e.jsx(Et,{activeSection:s.activeSection,onSelectSection:s.handleSectionClick}),e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx(Lt,{defaultsSummary:s.defaultsSummary,errors:s.errors,form:s.form,onInputChange:s.handleInputChange,onSetForm:s.setForm,sectionRef:s.setSectionRef("section-basics")}),e.jsx(At,{errors:s.errors,form:s.form,onSetForm:s.setForm,protocolChangesPending:s.protocolChangesPending,sectionRef:s.setSectionRef("section-protocol")}),e.jsx(Tt,{authErrors:s.authErrors,authForm:s.authForm,authLoading:s.authQuery.isPending||!s.authSettings&&s.authQuery.isFetching,authSettings:s.authSettings,needsPassword:s.needsPassword,onSetAuthForm:s.setAuthForm,sectionRef:s.setSectionRef("section-security")}),e.jsx(Mt,{configPath:s.configPath,onCopyPath:()=>void s.handleCopyPath(),sectionRef:s.setSectionRef("section-config-file")}),e.jsx(Ot,{cleaning:s.cleaning,clearingAll:s.clearingAll,onOpenCleanup:()=>s.setConfirmCleanupOpen(!0),onOpenClearAll:()=>s.setConfirmClearAllOpen(!0),sectionRef:s.setSectionRef("section-cleanup")})]})]}),e.jsx(Ft,{dirtyCount:r,protocolChangesPending:s.protocolChangesPending,onReset:s.handleResetAll,onSave:()=>void s.handleSaveAll(),saving:s.saving||s.savingAuth})]}):e.jsx(k,{children:e.jsx(L,{className:"pt-6",children:e.jsx("p",{className:"text-sm font-medium text-destructive",children:t("settings.toast.missingConfig")})})}),e.jsx(He,{open:s.confirmCleanupOpen,onOpenChange:o=>{!o&&!s.cleaning&&s.setConfirmCleanupOpen(!1)},title:t("settings.cleanup.confirmTitle"),description:t("settings.cleanup.confirmDescription"),confirmLabel:s.cleaning?t("common.actions.cleaning"):t("common.actions.cleanup"),cancelLabel:t("common.actions.cancel"),loading:s.cleaning,onConfirm:async()=>{await s.handleCleanupLogs(),s.setConfirmCleanupOpen(!1)}}),e.jsx(He,{open:s.confirmClearAllOpen,onOpenChange:o=>{!o&&!s.clearingAll&&s.setConfirmClearAllOpen(!1)},title:t("settings.cleanup.clearAllTitle"),description:t("settings.cleanup.clearAllWarning"),confirmLabel:s.clearingAll?t("settings.cleanup.clearingAll"):t("settings.cleanup.clearAll"),cancelLabel:t("common.actions.cancel"),loading:s.clearingAll,onConfirm:async()=>{await s.handleClearAllLogs(),s.setConfirmClearAllOpen(!1)}})]})}export{ss as default};
|
|
1
|
+
import{j as e,aW as Y,aP as xt,ak as ft,r as d}from"./vendor-CITafuNQ.js";import{C as He}from"./ConfirmDialog-CvC_VLb2.js";import{P as Ve}from"./PageState-CFLrRswm.js";import{P as bt}from"./PageToolbar-CWw40AFL.js";import{C as k,a as L}from"./card-D4YOc5eB.js";import{B as O,r as Ke,i as vt,d as yt,a as jt,c as De,q as Z}from"./app-czRBzLXv.js";import{B as V}from"./badge-DpUlf_NW.js";import{L as f,I as j}from"./label-DSVzZIex.js";import{S as B}from"./switch-7PH_rDz6.js";import{S as Nt,a as wt,b as Ct,c as Pt,d as kt}from"./select-sOwKYsgI.js";import{c as E}from"./global-BCehxTGJ.js";import{u as P}from"./i18n-PeX9kBVO.js";import{u as ee}from"./useAppMutation-DbIs5qvT.js";import{g as qe}from"./gateway-Dxoj2rj4.js";import{c as St}from"./clipboard-BnAnBk_-.js";import"./DialogShell-CM92wXHo.js";import"./radix-Bux_1C5J.js";import"./query-DZF7K6hv.js";import"./router-BoBrmro7.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"}],oe=[{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 te(t){var o,m,l,i,a,p,y,A,T,u,M;const s=t.storePayloads,r=N=>typeof N=="boolean"?N:typeof s=="boolean"?s:!0;return{port:String(t.port??((o=t.http)==null?void 0:o.port)??""),host:t.host??((m=t.http)==null?void 0:m.host)??"127.0.0.1",logRetentionDays:String(t.logRetentionDays??30),logExportTimeoutSeconds:String(t.logExportTimeoutSeconds??60),storeRequestPayloads:r(t.storeRequestPayloads),storeResponsePayloads:r(t.storeResponsePayloads),logLevel:t.logLevel??"info",bodyLimitMb:(()=>{const N=t.bodyLimit;return typeof N=="number"&&Number.isFinite(N)&&N>0?String(Math.max(1,Math.round(N/(1024*1024)))):"10"})(),enableRoutingFallback:t.enableRoutingFallback===!0,httpEnabled:((l=t.http)==null?void 0:l.enabled)!==!1,httpPort:String(((i=t.http)==null?void 0:i.port)??t.port??4100),httpHost:((a=t.http)==null?void 0:a.host)??t.host??"127.0.0.1",httpsEnabled:((p=t.https)==null?void 0:p.enabled)===!0,httpsPort:String(((y=t.https)==null?void 0:y.port)??4443),httpsHost:((A=t.https)==null?void 0:A.host)??t.host??"127.0.0.1",httpsKeyPath:((T=t.https)==null?void 0:T.keyPath)??"",httpsCertPath:((u=t.https)==null?void 0:u.certPath)??"",httpsCaPath:((M=t.https)==null?void 0:M.caPath)??""}}function se(t){return{enabled:t.enabled,username:t.username??"",password:"",confirmPassword:""}}function Et({activeSection:t,onSelectSection:s}){const{t:r}=P();return e.jsxs(e.Fragment,{children:[e.jsx("nav",{className:"hidden xl:block",children:e.jsxs(k,{className:"sticky top-20 p-3.5",children:[e.jsx("p",{className:"mb-2.5 px-2 text-[10px] font-semibold uppercase tracking-wider text-muted-foreground",children:r("settings.sections.jump")}),e.jsx("div",{className:"space-y-1.5",children:oe.map((o,m)=>e.jsxs("button",{type:"button",onClick:()=>s(o.id),className:E("flex w-full items-center gap-2.5 rounded-lg px-3 py-2 text-left text-sm font-semibold transition-all duration-200",t===o.id?"bg-secondary text-foreground":"text-muted-foreground hover:text-foreground"),children:[e.jsx("span",{className:E("flex h-7 w-7 items-center justify-center rounded-lg text-[11px] font-semibold",t===o.id?"bg-primary text-primary-foreground":"bg-secondary text-muted-foreground"),children:m+1}),e.jsx("span",{children:r(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:oe.map(o=>e.jsx("button",{type:"button",onClick:()=>s(o.id),className:E("rounded-lg px-4 py-2 text-xs font-semibold transition-all duration-150",t===o.id?"bg-secondary text-foreground font-medium":"text-muted-foreground hover:text-foreground hover:bg-secondary/50"),children:r(o.labelKey)},o.id))})})})]})}function Lt({defaultsSummary:t,errors:s,form:r,onInputChange:o,onSetForm:m,sectionRef:l}){const{t:i}=P();return e.jsx(k,{id:"section-basics",ref:l,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:i("settings.sections.basics")}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:i("settings.description")})]}),e.jsxs("div",{className:"grid gap-2 sm:grid-cols-3",children:[e.jsx(ae,{label:i("settings.fields.retention"),value:r.logRetentionDays}),e.jsx(ae,{label:i("settings.fields.logExportTimeout"),value:`${r.logExportTimeoutSeconds}s`}),e.jsx(ae,{label:i("settings.fields.bodyLimit"),value:`${r.bodyLimitMb} MB`})]})]}),e.jsxs("div",{className:"grid gap-5 md:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(f,{children:i("settings.fields.port")}),e.jsx(j,{type:"number",min:1,max:65535,value:r.port,onChange:a=>o("port")(a.target.value),"aria-invalid":!!s.port}),s.port?e.jsx("p",{className:"text-xs text-destructive",children:s.port}):null]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(f,{children:i("settings.fields.host")}),e.jsx(j,{value:r.host,onChange:a=>o("host")(a.target.value),placeholder:i("settings.fields.hostPlaceholder")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(f,{children:i("settings.fields.retention")}),e.jsx(j,{type:"number",min:1,max:365,value:r.logRetentionDays,onChange:a=>o("logRetentionDays")(a.target.value),"aria-invalid":!!s.logRetentionDays}),s.logRetentionDays?e.jsx("p",{className:"text-xs text-destructive",children:s.logRetentionDays}):null]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(f,{children:i("settings.fields.logExportTimeout")}),e.jsx(j,{type:"number",min:5,max:600,value:r.logExportTimeoutSeconds,onChange:a=>o("logExportTimeoutSeconds")(a.target.value),"aria-invalid":!!s.logExportTimeoutSeconds}),e.jsx("p",{className:"text-xs text-muted-foreground",children:i("settings.fields.logExportTimeoutHint")}),s.logExportTimeoutSeconds?e.jsx("p",{className:"text-xs text-destructive",children:s.logExportTimeoutSeconds}):null]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(f,{children:i("settings.fields.bodyLimit")}),e.jsx(j,{type:"number",min:1,max:2048,value:r.bodyLimitMb,onChange:a=>o("bodyLimitMb")(a.target.value),"aria-invalid":!!s.bodyLimitMb}),e.jsx("p",{className:"text-xs text-muted-foreground",children:i("settings.fields.bodyLimitHint")}),s.bodyLimitMb?e.jsx("p",{className:"text-xs text-destructive",children:s.bodyLimitMb}):null]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(f,{children:i("settings.fields.logLevel")}),e.jsxs(Nt,{value:r.logLevel,onValueChange:a=>m(p=>({...p,logLevel:a})),children:[e.jsx(wt,{children:e.jsx(Ct,{})}),e.jsx(Pt,{children:Rt.map(a=>e.jsx(kt,{value:a.value,children:i(`settings.fields.logLevelOption.${a.labelKey}`)},a.value))})]})]}),e.jsxs("div",{className:"grid gap-4 md:col-span-2 sm:grid-cols-2",children:[e.jsx(ne,{label:i("settings.fields.storeRequestPayloads"),hint:i("settings.fields.storeRequestPayloadsHint"),checked:r.storeRequestPayloads,onCheckedChange:a=>m(p=>({...p,storeRequestPayloads:a}))}),e.jsx(ne,{label:i("settings.fields.storeResponsePayloads"),hint:i("settings.fields.storeResponsePayloadsHint"),checked:r.storeResponsePayloads,onCheckedChange:a=>m(p=>({...p,storeResponsePayloads:a}))}),e.jsx(ne,{label:i("settings.fields.enableRoutingFallback"),hint:i("settings.fields.enableRoutingFallbackHint"),checked:r.enableRoutingFallback,onCheckedChange:a=>m(p=>({...p,enableRoutingFallback:a}))})]}),e.jsxs("div",{className:"rounded-xl bg-secondary px-4 py-5 md:col-span-2",children:[e.jsx(f,{className:"text-xs uppercase tracking-wide text-muted-foreground",children:i("settings.fields.defaults")}),e.jsx("p",{className:"mt-2 text-sm",children:t??i("settings.defaults.none")})]})]})]})})}function At({errors:t,form:s,onSetForm:r,protocolChangesPending:o,sectionRef:m}){const{t:l}=P();return e.jsx(k,{id:"section-protocol",ref:m,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:l("settings.sections.protocol")}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:l("settings.protocol.description")})]}),o?e.jsx("div",{className:"rounded-xl bg-warning-bg ring-1 ring-warning/30 p-4",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(Y,{className:"mt-0.5 h-5 w-5 flex-shrink-0 text-warning"}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm font-medium text-foreground",children:l("settings.protocol.restartWarning")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:l("settings.protocol.restartHint")}),e.jsx("code",{className:"block rounded-lg border border-border bg-secondary px-3 py-2 text-xs font-mono text-foreground",children:"cc-gw restart --daemon"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:l("settings.protocol.restartTip")})]})]})}):null,t.protocol?e.jsxs("div",{className:"rounded-xl bg-destructive/10 ring-1 ring-destructive/30 p-4 text-sm text-destructive",children:[e.jsx(Y,{className:"mr-2 inline h-4 w-4"}),t.protocol]}):null,e.jsxs("div",{className:"rounded-xl bg-secondary p-5",children:[e.jsxs("div",{className:"mb-4 flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(f,{className:"text-sm font-medium text-foreground",children:l("settings.protocol.http.enable")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:l("settings.protocol.http.hint")})]}),e.jsx(B,{checked:s.httpEnabled,onCheckedChange:i=>r(a=>({...a,httpEnabled:i}))})]}),s.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(f,{children:l("settings.protocol.http.port")}),e.jsx(j,{type:"number",min:1,max:65535,value:s.httpPort,onChange:i=>r(a=>({...a,httpPort:i.target.value})),"aria-invalid":!!t.httpPort}),t.httpPort?e.jsx("p",{className:"text-xs text-destructive",children:t.httpPort}):null]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(f,{children:l("settings.protocol.http.host")}),e.jsx(j,{value:s.httpHost,onChange:i=>r(a=>({...a,httpHost:i.target.value})),placeholder:"127.0.0.1"})]})]}):null]}),e.jsxs("div",{className:"rounded-xl bg-secondary p-5",children:[e.jsxs("div",{className:"mb-4 flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(f,{className:"text-sm font-medium text-foreground",children:l("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:l("settings.protocol.https.hint")})]}),e.jsx(B,{checked:s.httpsEnabled,onCheckedChange:i=>r(a=>({...a,httpsEnabled:i}))})]}),s.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(f,{children:l("settings.protocol.https.port")}),e.jsx(j,{type:"number",min:1,max:65535,value:s.httpsPort,onChange:i=>r(a=>({...a,httpsPort:i.target.value})),"aria-invalid":!!t.httpsPort}),t.httpsPort?e.jsx("p",{className:"text-xs text-destructive",children:t.httpsPort}):null]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(f,{children:l("settings.protocol.https.host")}),e.jsx(j,{value:s.httpsHost,onChange:i=>r(a=>({...a,httpsHost:i.target.value})),placeholder:"127.0.0.1"})]})]}),e.jsx(le,{label:l("settings.protocol.https.keyPath"),value:s.httpsKeyPath,onChange:i=>r(a=>({...a,httpsKeyPath:i})),placeholder:"~/.cc-gw/certs/key.pem"}),e.jsx(le,{label:l("settings.protocol.https.certPath"),value:s.httpsCertPath,onChange:i=>r(a=>({...a,httpsCertPath:i})),placeholder:"~/.cc-gw/certs/cert.pem"}),e.jsx(le,{label:l("settings.protocol.https.caPath"),value:s.httpsCaPath,onChange:i=>r(a=>({...a,httpsCaPath:i})),placeholder:"留空则不使用"}),e.jsx("div",{className:"rounded-xl bg-warning-bg ring-1 ring-warning/30 p-4",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(Y,{className:"mt-0.5 h-5 w-5 flex-shrink-0 text-warning"}),e.jsxs("div",{className:"flex-1 space-y-1.5",children:[e.jsx("p",{className:"text-sm font-medium text-warning",children:l("settings.protocol.https.warning")}),e.jsx("p",{className:"text-xs leading-relaxed text-warning",children:l("settings.protocol.https.tip")})]})]})})]}):null]})]})})}function Tt({authErrors:t,authForm:s,authLoading:r,authSettings:o,needsPassword:m,onSetAuthForm:l,sectionRef:i}){const{t:a}=P();return e.jsx(k,{id:"section-security",ref:i,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:a("settings.sections.security")}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:a("settings.auth.description")})]}),r&&!o?e.jsx(Ve,{compact:!0,label:a("common.loading")}):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(f,{className:"text-sm font-medium",children:a("settings.auth.enable")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a("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-lg bg-secondary px-3 py-1 text-[11px] tracking-[0.08em]",children:"/ui"}),e.jsx("span",{className:"rounded-lg bg-secondary px-3 py-1 text-[11px] tracking-[0.08em]",children:"/api/*"}),e.jsx("span",{className:"rounded-lg 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(V,{variant:s.enabled?"success":"secondary",children:s.enabled?a("settings.auth.statusEnabled"):a("settings.auth.statusDisabled")}),e.jsx(B,{checked:s.enabled,onCheckedChange:p=>l(y=>({...y,enabled:p}))})]})]}),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(f,{children:a("settings.auth.username")}),e.jsx(j,{value:s.username,onChange:p=>l(y=>({...y,username:p.target.value})),placeholder:a("settings.auth.usernamePlaceholder")}),t.username?e.jsx("p",{className:"text-xs text-destructive",children:t.username}):null]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(f,{children:a("settings.auth.password")}),e.jsx(j,{type:"password",value:s.password,disabled:!s.enabled,onChange:p=>l(y=>({...y,password:p.target.value})),placeholder:a("settings.auth.passwordPlaceholder")}),t.password?e.jsx("p",{className:"text-xs text-destructive",children:t.password}):e.jsx("p",{className:"text-xs text-muted-foreground",children:a(m?"settings.auth.passwordHintRequired":"settings.auth.passwordHintOptional")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(f,{children:a("settings.auth.confirmPassword")}),e.jsx(j,{type:"password",value:s.confirmPassword,disabled:!s.enabled,onChange:p=>l(y=>({...y,confirmPassword:p.target.value})),placeholder:a("settings.auth.confirmPasswordPlaceholder")}),t.confirmPassword?e.jsx("p",{className:"text-xs text-destructive",children:t.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:a("settings.auth.status")}),e.jsx("p",{className:"mt-2 text-base font-semibold",children:o!=null&&o.enabled?a("settings.auth.statusEnabled"):a("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:[a("settings.auth.username"),": ",o.username]}):null]}),e.jsx("div",{className:"rounded-xl bg-secondary px-4 py-3 text-xs text-muted-foreground",children:a(m?"settings.auth.passwordHintRequired":"settings.auth.passwordHintOptional")})]})]})]})]})})}function Mt({configPath:t,onCopyPath:s,sectionRef:r}){const{t:o}=P();return e.jsx(k,{id:"section-config-file",ref:r,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(O,{variant:"outline",size:"sm",onClick:s,className:"w-full sm:w-auto",children:[e.jsx(ft,{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:t||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 Ot({cleaning:t,clearingAll:s,onOpenCleanup:r,onOpenClearAll:o,sectionRef:m}){const{t:l}=P();return e.jsx(k,{id:"section-cleanup",ref:m,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:l("settings.sections.cleanup")}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:l("settings.cleanup.description")})]}),e.jsx("div",{className:"rounded-lg bg-secondary px-4 py-3 text-xs text-muted-foreground",children:l("settings.cleanup.confirmCleanup")}),e.jsxs("div",{className:"grid gap-4 lg:grid-cols-2",children:[e.jsx("div",{className:"rounded-xl border border-warning/30 bg-warning-bg p-5",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx(V,{variant:"warning",children:l("settings.cleanup.softLabel")}),e.jsx("p",{className:"text-sm font-medium",children:l("settings.cleanup.softTitle")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:l("settings.cleanup.softDescription")}),e.jsx(O,{variant:"outline",onClick:r,disabled:t,className:"w-full sm:w-auto",children:l(t?"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(V,{variant:"outline",className:"border-destructive/40 bg-destructive/10 text-destructive",children:l("settings.cleanup.hardLabel")}),e.jsx("p",{className:"text-sm font-medium",children:l("settings.cleanup.hardTitle")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:l("settings.cleanup.clearAllWarning")}),e.jsx(O,{variant:"destructive",onClick:o,disabled:s,className:"w-full sm:w-auto",children:l(s?"settings.cleanup.clearingAll":"settings.cleanup.clearAll")})]})})]})]})})}function Ft({dirtyCount:t,protocolChangesPending:s,onReset:r,onSave:o,saving:m}){const{t:l}=P();return t===0?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-[var(--surface-shadow-lg)] md:flex-row md:items-center md:justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(V,{variant:"secondary",children:l("settings.overview.unsavedCount",{count:t})}),e.jsx("p",{className:"text-sm text-muted-foreground",children:l(s?"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:[e.jsx(O,{variant:"outline",onClick:r,disabled:m,className:"w-full lg:w-auto",children:l("common.actions.reset")}),e.jsx(O,{onClick:o,disabled:m,className:"w-full lg:w-auto",children:l(m?"common.actions.saving":"common.actions.save")})]})]})}function ae({label:t,value:s}){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:t}),e.jsx("p",{className:"mt-1 text-sm font-semibold text-foreground",children:s})]})}function ne({checked:t,className:s,hint:r,hintClassName:o,label:m,labelClassName:l,onCheckedChange:i}){return e.jsxs("div",{className:E("flex flex-col gap-3 rounded-xl bg-secondary p-4 sm:flex-row sm:items-center sm:justify-between",s),children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(f,{className:E("text-sm font-semibold text-foreground",l),children:m}),e.jsx("p",{className:E("text-xs text-muted-foreground",o),children:r})]}),e.jsx(B,{checked:t,onCheckedChange:i,className:"self-start sm:self-auto"})]})}function le({label:t,onChange:s,placeholder:r,value:o}){return e.jsxs("div",{className:"space-y-2",children:[e.jsx(f,{children:t}),e.jsx(j,{value:o,onChange:m=>s(m.target.value),placeholder:r,className:"font-mono text-xs"})]})}const q={authStatusRequest(){return{url:"/api/auth/web",method:"GET"}},saveWebAuth:async t=>vt(yt.post("/api/auth/web",t)),cleanupLogs:async()=>Ke({url:"/api/logs/cleanup",method:"POST"}),clearLogs:async()=>Ke({url:"/api/logs/clear",method:"POST"})};function Ht(){const{t}=P(),{pushToast:s}=jt(),[r,o]=d.useState(oe[0].id),m=d.useRef(new Map),l=d.useCallback(n=>{const h=m.current.get(n);h&&h.scrollIntoView({behavior:"smooth",block:"start"})},[]),i=d.useCallback(n=>h=>{h?m.current.set(n,h):m.current.delete(n)},[]),a=De(Z.config.info(),qe.configInfoRequest()),p=De(Z.auth.web(),q.authStatusRequest()),y=ee({mutationFn:q.saveWebAuth,successToast:()=>({title:t("settings.auth.toast.success")}),errorToast:n=>({title:t("settings.auth.toast.failure",{message:n.message})}),invalidateKeys:[Z.auth.web()]}),A=ee({mutationFn:q.cleanupLogs,successToast:n=>({title:n.deleted>0?t("settings.toast.cleanupSuccess",{count:n.deleted}):t("settings.toast.cleanupNone")}),errorToast:n=>({title:t("settings.toast.cleanupFailure",{message:n.message})}),invalidateKeys:[["logs"],["dashboard"],["db"]]}),T=ee({mutationFn:q.clearLogs,successToast:n=>({title:t("settings.toast.clearAllSuccess",{logs:n.deleted,metrics:n.metricsCleared})}),errorToast:n=>({title:t("settings.toast.clearAllFailure",{message:n.message})}),invalidateKeys:[["logs"],["stats"],["dashboard"],["db"]]}),[u,M]=d.useState(null),[N,Be]=d.useState(""),[c,F]=d.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:""}),[Ie,I]=d.useState({}),[We,ie]=d.useState(!1),[Je,re]=d.useState(!1),[Qe,ce]=d.useState(!1),[_e,ze]=d.useState(!1),[Ge,$e]=d.useState(!1),[b,de]=d.useState(null),[g,H]=d.useState({enabled:!1,username:"",password:"",confirmPassword:""}),[Ue,K]=d.useState({}),[Xe,ue]=d.useState(!1),Ye=d.useMemo(()=>{if(!(u!=null&&u.defaults))return null;const n=[];return u.defaults.completion&&n.push(t("settings.defaults.completion",{model:u.defaults.completion})),u.defaults.reasoning&&n.push(t("settings.defaults.reasoning",{model:u.defaults.reasoning})),u.defaults.background&&n.push(t("settings.defaults.background",{model:u.defaults.background})),n.length>0?n.join(" | "):t("settings.defaults.none")},[u,t]),Ze=d.useMemo(()=>c.httpEnabled&&c.httpsEnabled?t("settings.overview.values.httpAndHttps"):c.httpsEnabled?t("settings.overview.values.httpsOnly"):t("settings.overview.values.httpOnly"),[c.httpEnabled,c.httpsEnabled,t]),et=d.useMemo(()=>g.enabled?b!=null&&b.hasPassword?g.username.trim()!==(b.username??""):!0:!1,[g.enabled,g.username,b]),S=d.useMemo(()=>u?te(u):null,[u]),W=d.useMemo(()=>S?JSON.stringify(c)!==JSON.stringify(S):!1,[c,S]),J=d.useMemo(()=>b?se(b):null,[b]),Q=d.useMemo(()=>J?JSON.stringify(g)!==JSON.stringify(J):!1,[g,J]),tt=d.useMemo(()=>S?["httpEnabled","httpPort","httpHost","httpsEnabled","httpsPort","httpsHost","httpsKeyPath","httpsCertPath","httpsCaPath","port","host"].some(h=>c[h]!==S[h]):!1,[c,S]);d.useEffect(()=>{a.data&&(M(a.data.config),Be(a.data.path),F(te(a.data.config)))},[a.data]),d.useEffect(()=>{p.data&&(de(p.data),H(se(p.data)),K({}))},[p.data]),d.useEffect(()=>{!a.isError||!a.error||s({title:t("settings.toast.loadFailure",{message:a.error.message}),variant:"error"})},[a.error,a.isError,s,t]),d.useEffect(()=>{!p.isError||!p.error||s({title:t("settings.toast.authLoadFailure",{message:p.error.message}),variant:"error"})},[p.error,p.isError,s,t]);const st=d.useCallback(n=>h=>{F(v=>({...v,[n]:h}))},[]),pe=d.useCallback(()=>{const n={};if(!c.httpEnabled&&!c.httpsEnabled&&(n.protocol=t("settings.validation.protocolRequired")),c.httpEnabled){const C=Number(c.httpPort);(!Number.isFinite(C)||C<1||C>65535)&&(n.httpPort=t("settings.validation.httpPort"))}if(c.httpsEnabled){const C=Number(c.httpsPort);(!Number.isFinite(C)||C<1||C>65535)&&(n.httpsPort=t("settings.validation.httpsPort")),(!c.httpsKeyPath||!c.httpsCertPath)&&(n.protocol=t("settings.validation.httpsCertificate"))}const h=Number(c.port);(!Number.isFinite(h)||h<1||h>65535)&&(n.port=t("settings.validation.port"));const v=Number(c.logRetentionDays);(!Number.isFinite(v)||v<1||v>365)&&(n.logRetentionDays=t("settings.validation.retention"));const w=Number(c.logExportTimeoutSeconds);(!Number.isFinite(w)||w<5||w>600)&&(n.logExportTimeoutSeconds=t("settings.validation.logExportTimeout"));const R=Number(c.bodyLimitMb);return(!Number.isFinite(R)||R<1||R>2048)&&(n.bodyLimitMb=t("settings.validation.bodyLimit")),I(n),Object.keys(n).length===0},[c,t]),me=d.useCallback(()=>{const n={},h=g.username.trim(),v=b?h!==(b.username??""):!0,w=g.enabled&&(!(b!=null&&b.hasPassword)||v);return g.enabled&&!h&&(n.username=t("settings.auth.validation.username")),g.password&&g.password.length<6&&(n.password=t("settings.auth.validation.minLength")),w&&!g.password&&(n.password=t("settings.auth.validation.passwordRequired")),(g.password||g.confirmPassword)&&g.password!==g.confirmPassword&&(n.confirmPassword=t("settings.auth.validation.confirmMismatch")),K(n),Object.keys(n).length===0},[g,b,t]),_=d.useCallback(async()=>{var n,h,v,w,R,C,he,ge,xe,fe,be,ve,ye,je,Ne,we,Ce,Pe,ke,Se,Re,Ee,Le,Ae,Te,Me;if(!u){s({title:t("settings.toast.loadFailure",{message:t("settings.toast.missingConfig")}),variant:"error"});return}if(pe()){ie(!0);try{const D=Number(c.port),rt=Number(c.logRetentionDays),ct=Number(c.logExportTimeoutSeconds),dt=Number(c.bodyLimitMb),x={...u,http:{enabled:c.httpEnabled,port:Number(c.httpPort),host:c.httpHost.trim()||"127.0.0.1"},https:{enabled:c.httpsEnabled,port:Number(c.httpsPort),host:c.httpsHost.trim()||"127.0.0.1",keyPath:c.httpsKeyPath.trim(),certPath:c.httpsCertPath.trim(),caPath:c.httpsCaPath.trim()||void 0},port:D,host:c.host.trim()||void 0,logRetentionDays:rt,logExportTimeoutSeconds:Math.min(Math.max(Math.round(ct),5),600),storeRequestPayloads:c.storeRequestPayloads,storeResponsePayloads:c.storeResponsePayloads,logLevel:c.logLevel,bodyLimit:Math.max(1,Math.floor(dt*1024*1024)),enableRoutingFallback:c.enableRoutingFallback};delete x.requestLogging,delete x.responseLogging;const Oe={...x};delete Oe.webAuth,await qe.saveConfig(Oe),M({...x,webAuth:u.webAuth});const Fe=X=>(X==null?void 0:X.trim())||void 0,ut=u.port??((n=u.http)==null?void 0:n.port)??4100,pt=x.port??((h=x.http)==null?void 0:h.port)??4100,mt=((v=u.host)==null?void 0:v.trim())||((R=(w=u.http)==null?void 0:w.host)==null?void 0:R.trim())||"127.0.0.1",ht=((C=x.host)==null?void 0:C.trim())||((ge=(he=x.http)==null?void 0:he.host)==null?void 0:ge.trim())||"127.0.0.1",gt=ut!==pt||mt!==ht||((xe=u.http)==null?void 0:xe.enabled)!==((fe=x.http)==null?void 0:fe.enabled)||((be=u.http)==null?void 0:be.port)!==((ve=x.http)==null?void 0:ve.port)||(((ye=u.http)==null?void 0:ye.host)??u.host??"127.0.0.1")!==(((je=x.http)==null?void 0:je.host)??x.host??"127.0.0.1")||((Ne=u.https)==null?void 0:Ne.enabled)!==((we=x.https)==null?void 0:we.enabled)||((Ce=u.https)==null?void 0:Ce.port)!==((Pe=x.https)==null?void 0:Pe.port)||(((ke=u.https)==null?void 0:ke.host)??u.host??"127.0.0.1")!==(((Se=x.https)==null?void 0:Se.host)??x.host??"127.0.0.1")||((Re=u.https)==null?void 0:Re.keyPath)!==((Ee=x.https)==null?void 0:Ee.keyPath)||((Le=u.https)==null?void 0:Le.certPath)!==((Ae=x.https)==null?void 0:Ae.certPath)||Fe((Te=u.https)==null?void 0:Te.caPath)!==Fe((Me=x.https)==null?void 0:Me.caPath);s({title:t(gt?"settings.toast.protocolRestartRequired":"settings.toast.saveSuccess"),variant:"success"}),a.refetch()}catch(D){s({title:t("settings.toast.saveFailure",{message:D instanceof Error?D.message:"unknown"}),variant:"error"})}finally{ie(!1)}}},[u,a,c,s,t,pe]),z=d.useCallback(()=>{u&&(F(te(u)),I({}))},[u]),G=d.useCallback(async()=>{if(me()){ue(!0);try{const n={enabled:g.enabled,username:g.username.trim()||void 0};g.password&&(n.password=g.password);const h=await y.mutateAsync(n);h.auth&&(de(h.auth),H({enabled:h.auth.enabled,username:h.auth.username??"",password:"",confirmPassword:""}),K({})),p.refetch()}catch{}finally{ue(!1)}}},[g,p,y,me]),$=d.useCallback(()=>{b&&(H(se(b)),K({}))},[b]),at=d.useCallback(async()=>{W&&await _(),Q&&await G()},[G,_,Q,W]),nt=d.useCallback(()=>{z(),$()},[$,z]),lt=d.useCallback(async()=>{if(!N){s({title:t("settings.toast.copyFailure",{message:t("settings.file.unknown")}),variant:"error"});return}try{await St(N),s({title:t("settings.toast.copySuccess"),variant:"success"})}catch(n){s({title:t("settings.toast.copyFailure",{message:n instanceof Error?n.message:"unknown"}),variant:"error"})}},[N,s,t]),ot=d.useCallback(async()=>{re(!0);try{await A.mutateAsync()}catch{}finally{re(!1)}},[A]),it=d.useCallback(async()=>{ce(!0);try{await T.mutateAsync()}catch{}finally{ce(!1)}},[T]),U=a.isPending||!u&&a.isFetching;return d.useEffect(()=>{if(U)return;const n=Array.from(m.current.values());if(n.length===0)return;const h=new IntersectionObserver(v=>{for(const w of v)if(w.isIntersecting){o(w.target.id);break}},{rootMargin:"-80px 0px -60% 0px",threshold:0});for(const v of n)h.observe(v);return()=>h.disconnect()},[U]),{activeSection:r,authErrors:Ue,authForm:g,authQuery:p,authSettings:b,clearingAll:Qe,cleaning:Je,config:u,configPath:N,configQuery:a,confirmCleanupOpen:_e,confirmClearAllOpen:Ge,defaultsSummary:Ye,errors:Ie,form:c,handleAuthReset:$,handleAuthSave:G,handleCleanupLogs:ot,handleClearAllLogs:it,handleCopyPath:lt,handleInputChange:st,handleReset:z,handleResetAll:nt,handleSave:_,handleSaveAll:at,handleSectionClick:l,isAuthDirty:Q,isConfigDirty:W,isLoading:U,needsPassword:et,protocolSummaryLabel:Ze,protocolChangesPending:tt,saving:We,savingAuth:Xe,sectionRefs:m,setAuthForm:H,setConfirmCleanupOpen:ze,setConfirmClearAllOpen:$e,setErrors:I,setForm:F,setSectionRef:i,t}}function ss(){const{t}=P(),s=Ht(),r=Number(s.isConfigDirty)+Number(s.isAuthDirty);return e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx(bt,{info:r>0?e.jsx("span",{className:"rounded-lg bg-warning-bg px-2.5 py-1 text-xs font-medium text-warning",children:t("settings.overview.unsavedCount",{count:r})}):null,status:s.config?e.jsx("span",{className:"text-xs text-muted-foreground",children:s.protocolChangesPending?t("settings.protocol.restartWarning"):t("common.status.success")}):null,actions:null}),s.isLoading?e.jsx(Ve,{label:t("common.loading")}):s.config?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid gap-6 xl:grid-cols-[200px_1fr]",children:[e.jsx(Et,{activeSection:s.activeSection,onSelectSection:s.handleSectionClick}),e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx(Lt,{defaultsSummary:s.defaultsSummary,errors:s.errors,form:s.form,onInputChange:s.handleInputChange,onSetForm:s.setForm,sectionRef:s.setSectionRef("section-basics")}),e.jsx(At,{errors:s.errors,form:s.form,onSetForm:s.setForm,protocolChangesPending:s.protocolChangesPending,sectionRef:s.setSectionRef("section-protocol")}),e.jsx(Tt,{authErrors:s.authErrors,authForm:s.authForm,authLoading:s.authQuery.isPending||!s.authSettings&&s.authQuery.isFetching,authSettings:s.authSettings,needsPassword:s.needsPassword,onSetAuthForm:s.setAuthForm,sectionRef:s.setSectionRef("section-security")}),e.jsx(Mt,{configPath:s.configPath,onCopyPath:()=>void s.handleCopyPath(),sectionRef:s.setSectionRef("section-config-file")}),e.jsx(Ot,{cleaning:s.cleaning,clearingAll:s.clearingAll,onOpenCleanup:()=>s.setConfirmCleanupOpen(!0),onOpenClearAll:()=>s.setConfirmClearAllOpen(!0),sectionRef:s.setSectionRef("section-cleanup")})]})]}),e.jsx(Ft,{dirtyCount:r,protocolChangesPending:s.protocolChangesPending,onReset:s.handleResetAll,onSave:()=>void s.handleSaveAll(),saving:s.saving||s.savingAuth})]}):e.jsx(k,{children:e.jsx(L,{className:"pt-6",children:e.jsx("p",{className:"text-sm font-medium text-destructive",children:t("settings.toast.missingConfig")})})}),e.jsx(He,{open:s.confirmCleanupOpen,onOpenChange:o=>{!o&&!s.cleaning&&s.setConfirmCleanupOpen(!1)},title:t("settings.cleanup.confirmTitle"),description:t("settings.cleanup.confirmDescription"),confirmLabel:s.cleaning?t("common.actions.cleaning"):t("common.actions.cleanup"),cancelLabel:t("common.actions.cancel"),loading:s.cleaning,onConfirm:async()=>{await s.handleCleanupLogs(),s.setConfirmCleanupOpen(!1)}}),e.jsx(He,{open:s.confirmClearAllOpen,onOpenChange:o=>{!o&&!s.clearingAll&&s.setConfirmClearAllOpen(!1)},title:t("settings.cleanup.clearAllTitle"),description:t("settings.cleanup.clearAllWarning"),confirmLabel:s.clearingAll?t("settings.cleanup.clearingAll"):t("settings.cleanup.clearAll"),cancelLabel:t("common.actions.cancel"),loading:s.clearingAll,onConfirm:async()=>{await s.handleClearAllLogs(),s.setConfirmClearAllOpen(!1)}})]})}export{ss as default};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{j as e,$ as he,ak as Q,r as d}from"./vendor-CITafuNQ.js";import{B as h,t as z,L as ge}from"./app-
|
|
1
|
+
import{j as e,$ as he,ak as Q,r as d}from"./vendor-CITafuNQ.js";import{B as h,t as z,L as ge}from"./app-czRBzLXv.js";import{C as ve,b as ye,d as fe,e as je,a as Se}from"./card-D4YOc5eB.js";import{u as Ce,B as Ne,M as be,C as ke,T as Re,n as Ke,g as Pe,m as we,S as Me}from"./useProviderForm-BiVzWP3H.js";import{L as C,I as R}from"./label-DSVzZIex.js";import{u as Te,E as Ee}from"./shared-HT9X1BTy.js";import{u as N}from"./i18n-PeX9kBVO.js";import{S as Ae,a as Ie,b as He,c as Oe,d as Fe}from"./select-sOwKYsgI.js";import{a as $e}from"./apiKeys-CoQ69TK_.js";import{g as G}from"./gateway-Dxoj2rj4.js";import{c as Le}from"./clipboard-BnAnBk_-.js";import{u as Ue}from"./router-BoBrmro7.js";import"./global-BCehxTGJ.js";import"./query-DZF7K6hv.js";import"./radix-Bux_1C5J.js";import"./disclosure-l5qsWhr7.js";import"./switch-7PH_rDz6.js";import"./badge-DpUlf_NW.js";function Be({state:c}){const{t}=N(),r=Te(),{keyName:s,setKeyName:n,keyEndpoints:l,setKeyEndpoints:p,keyMaxConcurrency:x,setKeyMaxConcurrency:g,creatingKey:u,createdKey:m,createApiKey:y,copyCreatedKey:i}=c;return m?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex h-10 w-10 items-center justify-center rounded-lg bg-success-bg text-success",children:e.jsx(he,{className:"h-5 w-5","aria-hidden":"true"})}),e.jsx("p",{className:"text-sm font-semibold",children:t("apiKeys.keyCreated")})]}),e.jsx("p",{className:"text-sm font-medium text-warning",children:t("apiKeys.saveKeyWarning")}),e.jsx("div",{className:"break-all rounded-lg border border-border bg-secondary px-4 py-3 font-mono text-sm",children:m.key}),e.jsx("div",{children:e.jsxs(h,{type:"button",onClick:()=>void i(m.key),children:[e.jsx(Q,{className:"mr-2 h-4 w-4","aria-hidden":"true"}),t("common.actions.copy")]})})]}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs(C,{htmlFor:"setupKeyName",children:[t("apiKeys.keyNamePlaceholder")," *"]}),e.jsx(R,{id:"setupKeyName",value:s,onChange:f=>n(f.target.value),placeholder:t("apiKeys.keyNamePlaceholder")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{children:t("apiKeys.allowedEndpoints")}),e.jsx(Ee,{available:r,selected:l,onChange:p,hint:t("apiKeys.selectEndpoints")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{htmlFor:"setupMaxConcurrency",children:t("apiKeys.maxConcurrency")}),e.jsx(R,{id:"setupMaxConcurrency",type:"number",min:"0",value:x,onChange:f=>g(f.target.value),placeholder:t("apiKeys.maxConcurrencyPlaceholder")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("apiKeys.maxConcurrencyHelper")})]}),e.jsx("div",{className:"flex justify-end",children:e.jsx(h,{type:"button",onClick:()=>void y(),disabled:u||s.trim().length===0,children:t(u?"setup.steps.apiKey.creating":"setup.steps.apiKey.create")})})]})}function De({existingProviderIds:c,saving:t,onSave:r}){const{t:s}=N(),n=Ce({mode:"create",existingProviderIds:c}),l={form:n.form,errors:n.errors,isCreate:!0,advancedOpen:n.advancedOpen,onAdvancedOpenChange:n.setAdvancedOpen,idInputRef:n.providerIdRef,onProviderIdChange:n.handleProviderIdChange,onFieldChange:n.handleFieldChange,onTypeChange:n.handleTypeChange,onAuthModeChange:n.handleAuthModeChange,onNonStreamViaStreamChange:n.handleProviderNonStreamViaStreamChange,onUseAbsoluteUrlChange:n.handleUseAbsoluteUrlChange,onAddHeader:n.handleAddHeader,onRemoveHeader:n.handleRemoveHeader,onHeaderChange:n.handleHeaderChange,onModelIdChange:n.handleModelIdChange,onModelChange:n.handleModelChange,onAddModel:n.handleAddModel,onRemoveModel:n.handleRemoveModel,onModelNonStreamViaStreamChange:n.handleModelNonStreamViaStreamChange,onSetDefaultModel:n.handleSetDefaultModel},p=()=>{n.validate()&&r(n.serialize())};return e.jsxs("div",{className:"space-y-8",children:[e.jsx(Ne,{...l}),e.jsx(be,{...l}),e.jsx("div",{className:"flex justify-end",children:e.jsx(h,{type:"button",onClick:p,disabled:t,children:s(t?"common.actions.saving":"setup.steps.provider.saveAndContinue")})})]})}function _e({state:c,onSaved:t}){const{t:r}=N(),{providers:s,setupProvider:n,setSetupProviderId:l,savingProvider:p,saveProvider:x}=c,[g,u]=d.useState(null),m=g??s.length===0,y=i=>{x(i).then(f=>{f&&t()})};return e.jsxs("div",{className:"space-y-6",children:[s.length>0?e.jsxs("div",{className:"space-y-3 rounded-xl bg-secondary/50 p-4",children:[e.jsx("p",{className:"text-sm font-semibold",children:r("setup.steps.provider.existingTitle",{count:s.length})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:r("setup.steps.provider.existingHint")}),e.jsxs(C,{className:"flex flex-col gap-2 text-sm",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:r("setup.steps.provider.chooseLabel")}),e.jsxs(Ae,{value:(n==null?void 0:n.id)??"",onValueChange:l,children:[e.jsx(Ie,{children:e.jsx(He,{})}),e.jsx(Oe,{children:s.map(i=>e.jsx(Fe,{value:i.id,children:i.label||i.id},i.id))})]})]})]}):null,m?e.jsx(De,{existingProviderIds:s.map(i=>i.id),saving:p,onSave:y}):e.jsx("div",{children:e.jsx(h,{type:"button",variant:"outline",onClick:()=>u(!0),children:r("setup.steps.provider.addAnother")})}),m&&s.length>0?e.jsx("div",{children:e.jsx(h,{type:"button",variant:"ghost",size:"sm",onClick:()=>u(!1),children:r("setup.steps.provider.backToList")})}):null]})}const Ve=ke.slice(0,3);function qe({state:c}){const{t}=N(),{setupProvider:r,anthropicRoutes:s,routeSource:n,setRouteSource:l,routeTarget:p,setRouteTarget:x,savingRoute:g,saveDefaultRoute:u}=c,m=Object.entries(s),y=!!r&&n.trim().length>0&&p.trim().length>0&&!g;return e.jsxs("div",{className:"space-y-6",children:[m.length>0?e.jsxs("section",{className:"space-y-3","aria-labelledby":"setup-existing-routes",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("h3",{id:"setup-existing-routes",className:"text-sm font-semibold",children:t("setup.steps.routing.existingTitle")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("setup.steps.routing.existingHint")})]}),e.jsx("div",{className:"divide-y divide-border rounded-xl border border-border",children:m.map(([i,f])=>e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 px-4 py-2.5 text-xs",children:[e.jsx("code",{className:"font-mono text-foreground",children:i}),e.jsxs("code",{className:"font-mono text-muted-foreground",children:["→ ",f]})]},i))})]}):e.jsx("p",{className:"rounded-xl bg-secondary/50 px-4 py-3 text-xs text-muted-foreground",children:t("setup.steps.routing.emptyHint")}),e.jsxs("section",{className:"space-y-4","aria-labelledby":"setup-new-route",children:[e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs(C,{className:"flex flex-col gap-2 text-sm",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:t("setup.steps.routing.sourceLabel")}),e.jsx(R,{value:n,onChange:i=>l(i.target.value)})]}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:Ve.map(i=>e.jsx(h,{type:"button",variant:"outline",size:"sm",className:"h-7 rounded-md px-2.5 text-[11px] font-normal",onClick:()=>l(i),children:i},i))}),e.jsx("p",{className:"text-xs leading-5 text-muted-foreground",children:t("setup.steps.routing.sourceHint")})]}),e.jsxs(C,{className:"flex flex-col gap-2 text-sm",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:t("setup.steps.routing.targetLabel")}),e.jsx(R,{value:p,onChange:i=>x(i.target.value)})]})]}),e.jsx("div",{className:"flex justify-end",children:e.jsx(h,{type:"button",onClick:()=>void u(),disabled:!y,children:t(g?"setup.steps.routing.saving":"setup.steps.routing.save")})})]})]})}function ze({state:c}){const{t}=N(),{setupProvider:r,testingProvider:s,testResult:n,testSetupProvider:l,anthropicBaseUrl:p,createdKey:x,copyCreatedKey:g}=c;if(!r)return e.jsx("p",{className:"rounded-xl bg-secondary/50 px-4 py-3 text-xs text-muted-foreground",children:t("setup.steps.verify.noProvider")});const u=[`export ANTHROPIC_BASE_URL=${p}`,`export ANTHROPIC_API_KEY=${(x==null?void 0:x.key)??"<your-api-key>"}`].join(`
|
|
2
2
|
`);return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("section",{className:"space-y-3","aria-labelledby":"setup-verify-connection",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("h3",{id:"setup-verify-connection",className:"text-sm font-semibold",children:t("workbench.drawer.verifyTitle")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("setup.steps.verify.testingProvider",{name:r.label||r.id})})]}),e.jsxs("div",{className:"space-y-3 rounded-xl border border-transparent bg-card p-4 shadow-[var(--surface-shadow)]",children:[e.jsx(h,{type:"button",variant:"outline",size:"sm",onClick:()=>void l(),disabled:s,children:t(s?"common.actions.testingConnection":"workbench.drawer.verifyRun")}),n?e.jsx(Re,{result:n}):null]})]}),e.jsxs("section",{className:"space-y-3","aria-labelledby":"setup-verify-first-request",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("h3",{id:"setup-verify-first-request",className:"text-sm font-semibold",children:t("setup.steps.verify.envTitle")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("setup.steps.verify.envHint")})]}),e.jsx("pre",{className:"overflow-x-auto rounded-lg border border-border bg-secondary px-4 py-3 font-mono text-xs",children:u}),e.jsx("div",{children:e.jsxs(h,{type:"button",variant:"outline",size:"sm",onClick:()=>void g(u),children:[e.jsx(Q,{className:"mr-2 h-4 w-4","aria-hidden":"true"}),t("common.actions.copy")]})})]})]})}const b=["provider","routing","apiKey","verify"];function Ge(){var U;const c=Ke(),{t,pushToast:r,config:s,setConfig:n,configQuery:l,customEndpoints:p,ensureConfig:x}=c,g=Ue(),[u,m]=d.useState(0),[y,i]=d.useState(null),[f,T]=d.useState(!1),[E,W]=d.useState(""),[Y,J]=d.useState(null),[X,A]=d.useState(!1),[K,Z]=d.useState(""),[P,ee]=d.useState(["anthropic"]),[I,te]=d.useState(""),[se,H]=d.useState(!1),[O,ne]=d.useState(null),[ae,F]=d.useState(!1),[re,w]=d.useState(null),S=d.useMemo(()=>(s==null?void 0:s.providers)??[],[s]),j=d.useMemo(()=>S.find(a=>a.id===y)??S[0]??null,[S,y]),M=d.useMemo(()=>s?Pe(s,p,"anthropic"):{},[s,p]),$=Object.keys(M).length,oe=d.useMemo(()=>{var o,v;if(!j)return"";const a=j.defaultModel??((v=(o=j.models)==null?void 0:o.find(k=>k.id.trim().length>0))==null?void 0:v.id);return a?`${j.id}:${a}`:`${j.id}:*`},[j]),L=Y??oe,ie=async a=>{if(!s||!x())return!1;const o={...s,providers:[...S,a]};T(!0);try{return await G.saveConfig(o),n(o),l.refetch(),i(a.id),r({title:t("providers.toast.createSuccess",{name:a.label||a.id}),variant:"success"}),!0}catch(v){return r({title:t("providers.drawer.toast.saveFailure",{message:v instanceof Error?v.message:"unknown"}),variant:"error"}),!1}finally{T(!1)}},ce=async()=>{var B,D,_,V;if(!s||!x())return;const a=E.trim(),o=L.trim();if(!a||!o)return;const v={...M,[a]:o},k={...s,endpointRouting:{...s.endpointRouting??{},anthropic:{defaults:((D=(B=s.endpointRouting)==null?void 0:B.anthropic)==null?void 0:D.defaults)??s.defaults,modelRoutes:v,compatibility:(V=(_=s.endpointRouting)==null?void 0:_.anthropic)==null?void 0:V.compatibility}},modelRoutes:v};A(!0);try{await G.saveConfig(k),n(k),l.refetch(),r({title:t("modelManagement.toast.routesSaved"),variant:"success"})}catch(q){r({title:t("modelManagement.toast.routesSaveFailure",{message:q instanceof Error?q.message:"unknown"}),variant:"error"})}finally{A(!1)}},de=async()=>{if(!K.trim()){r({title:t("apiKeys.errors.nameRequired"),variant:"error"});return}const a=I.trim();if(a&&(!Number.isInteger(Number(a))||Number(a)<1)){r({title:t("apiKeys.errors.maxConcurrencyInvalid"),variant:"error"});return}H(!0);try{const o=await $e.create({name:K.trim(),allowedEndpoints:P.length>0?P:void 0,maxConcurrency:a?Number(a):null});ne(o)}catch(o){const v=z(o);r({title:t("setup.steps.apiKey.createFailed",{message:v.message}),variant:"error"})}finally{H(!1)}},le=async a=>{try{await Le(a),r({title:t("apiKeys.toast.keyCopied"),variant:"success"})}catch(o){r({title:t("apiKeys.toast.copyFailure"),description:o instanceof Error?o.message:t("common.unknownError"),variant:"error"})}},ue=async()=>{if(j){F(!0);try{const a=await we.testProvider(j.id);if(a.ok){w({ok:!0,status:a.status,statusText:a.statusText,durationMs:a.durationMs,testedAt:Date.now()});return}w({ok:!1,status:a.status,statusText:a.statusText,durationMs:a.durationMs,message:`${a.status} ${a.statusText}`,testedAt:Date.now()})}catch(a){const o=z(a);w({ok:!1,status:o.status,message:o.status?`${o.status} ${o.message}`:o.message,testedAt:Date.now()})}finally{F(!1)}}},pe=`http://127.0.0.1:${((U=s==null?void 0:s.http)==null?void 0:U.port)??(s==null?void 0:s.port)??4100}/anthropic`,me=b[u],xe={provider:S.length>0,routing:$>0,apiKey:O!==null,verify:!0};return{...c,stepIndex:u,activeStep:me,canProceed:xe,goNext:()=>{m(a=>Math.min(a+1,b.length-1))},goBack:()=>{m(a=>Math.max(a-1,0))},goToStep:a=>{const o=b.indexOf(a);o>=0&&o<=u&&m(o)},finish:()=>{g("/")},providers:S,setupProvider:j,setupProviderId:y,setSetupProviderId:i,savingProvider:f,saveProvider:ie,anthropicRoutes:M,anthropicRouteCount:$,routeSource:E,setRouteSource:W,routeTarget:L,setRouteTarget:J,savingRoute:X,saveDefaultRoute:ce,keyName:K,setKeyName:Z,keyEndpoints:P,setKeyEndpoints:ee,keyMaxConcurrency:I,setKeyMaxConcurrency:te,creatingKey:se,createdKey:O,createApiKey:de,copyCreatedKey:le,testingProvider:ae,testResult:re,testSetupProvider:ue,anthropicBaseUrl:pe}}function vt(){const{t:c}=N(),t=Ge();if(t.configQuery.isPending&&!t.config)return e.jsx(ge,{});const r=b.map((n,l)=>({id:n,label:c(`setup.steps.${n}.navLabel`),status:l<t.stepIndex?"complete":l===t.stepIndex?"current":"upcoming"})),s=t.stepIndex===b.length-1;return e.jsxs("div",{className:"mx-auto flex w-full max-w-3xl flex-col gap-6",children:[e.jsxs("header",{className:"space-y-1.5",children:[e.jsx("h1",{className:"text-xl font-semibold tracking-[-0.02em]",children:c("setup.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:c("setup.description")})]}),e.jsx(Me,{steps:r,current:t.activeStep,onSelect:t.goToStep}),e.jsxs(ve,{children:[e.jsxs(ye,{children:[e.jsx(fe,{children:c(`setup.steps.${t.activeStep}.title`)}),e.jsx(je,{children:c(`setup.steps.${t.activeStep}.description`)})]}),e.jsxs(Se,{children:[t.activeStep==="provider"?e.jsx(_e,{state:t,onSaved:t.goNext}):null,t.activeStep==="routing"?e.jsx(qe,{state:t}):null,t.activeStep==="apiKey"?e.jsx(Be,{state:t}):null,t.activeStep==="verify"?e.jsx(ze,{state:t}):null]})]}),e.jsxs("footer",{className:"flex items-center justify-between",children:[e.jsx(h,{type:"button",variant:"outline",onClick:t.goBack,disabled:t.stepIndex===0,children:c("common.actions.previous")}),s?e.jsx(h,{type:"button",onClick:t.finish,children:c("setup.actions.finish")}):e.jsx(h,{type:"button",onClick:t.goNext,disabled:!t.canProceed[t.activeStep],children:c("common.actions.next")})]})]})}export{vt as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r,i as s,d as t}from"./app-
|
|
1
|
+
import{r,i as s,d as t}from"./app-czRBzLXv.js";const i={listRequest(){return{url:"/api/keys",method:"GET"}},overviewRequest(e){return{url:"/api/stats/api-keys/overview",method:"GET",params:{days:e}}},usageRequest(e,a=10){return{url:"/api/stats/api-keys/usage",method:"GET",params:{days:e,limit:a}}},customEndpointOptionsRequest(){return{url:"/api/custom-endpoints",method:"GET"}},create:async e=>s(t.post("/api/keys",e)),update:async(e,a)=>{await s(t.patch(`/api/keys/${e}`,a))},delete:async e=>{await s(t.delete(`/api/keys/${e}`))},reveal:async e=>r({url:`/api/keys/${e}/reveal`,method:"GET"})};export{i as a};
|