@chenpu17/cc-gw 0.12.0 → 0.13.0
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-B4KoKSAM.js → About-BJbSQIDc.js} +1 -1
- package/src/web/dist/assets/{ApiKeys-CwiStTlS.js → ApiKeys-C8I9ti-a.js} +1 -1
- package/src/web/dist/assets/{ConfirmDialog-cZsL-k-v.js → ConfirmDialog-BOe5HI56.js} +1 -1
- package/src/web/dist/assets/{Dashboard-khRk8U0-.js → Dashboard-C7n9KzBy.js} +1 -1
- package/src/web/dist/assets/{Events-BGQklKqB.js → Events-BGfmA69d.js} +1 -1
- package/src/web/dist/assets/{Help-B2MDKuj8.js → Help-DUrs56_n.js} +1 -1
- package/src/web/dist/assets/{Login-CrvH8tn2.js → Login-Dxeq-BfV.js} +1 -1
- package/src/web/dist/assets/{Logs-DoAgVjw3.js → Logs-VRdCNMkl.js} +1 -1
- package/src/web/dist/assets/{ProvidersWorkbench-CI7TbMf1.js → ProvidersWorkbench-DOGrU9Xl.js} +1 -1
- package/src/web/dist/assets/{Settings-BnqMqPol.js → Settings-CGxWfI_h.js} +1 -1
- package/src/web/dist/assets/{Setup-deGPdPcE.js → Setup-yKUdrXJQ.js} +1 -1
- package/src/web/dist/assets/{apiKeys-Ol_q3sZL.js → apiKeys-B-WRyKci.js} +1 -1
- package/src/web/dist/assets/{app-BBAnVEPg.js → app-BnQl39hq.js} +2 -2
- package/src/web/dist/assets/{gateway-B_xLF-Rk.js → gateway-DxCj_uok.js} +1 -1
- package/src/web/dist/assets/{landing-MsSWlQKc.js → landing-BuuM1jg8.js} +1 -1
- package/src/web/dist/assets/package-CKkVmaOi.js +1 -0
- package/src/web/dist/assets/{shared-BIsbTzWd.js → shared-DHBfRHZV.js} +1 -1
- package/src/web/dist/assets/{useAppMutation-Ds2SX3kE.js → useAppMutation-Cix9n50u.js} +1 -1
- package/src/web/dist/assets/{useProviderForm-CtZEenP9.js → useProviderForm-CsPV2Cqr.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-DHb277_G.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as e,aW as se,aP as yt,ak as vt,r as u}from"./vendor-D2wC0h2o.js";import{C as Be}from"./ConfirmDialog-cZsL-k-v.js";import{P as Ie}from"./PageState-U6DpaNu4.js";import{P as jt}from"./PageToolbar-BnDacS2l.js";import{C as P,a as A}from"./card-DhuLMeO9.js";import{B as E,r as I,i as Nt,d as wt,a as Ct,c as ae,q as F}from"./app-BBAnVEPg.js";import{B as W}from"./badge-RZTsODn-.js";import{L as f,I as j}from"./label-Da-JMxO2.js";import{S as Q}from"./switch-CeKtgMDT.js";import{S as Pt,a as St,b as kt,c as Rt,d as Et}from"./select-BTwqvh0l.js";import{c as L}from"./global-CJOj9WGx.js";import{u as C}from"./i18n-Dp-o1LhZ.js";import{u as z}from"./useAppMutation-Ds2SX3kE.js";import{g as Ve}from"./gateway-B_xLF-Rk.js";import{c as Lt}from"./clipboard-BnAnBk_-.js";import{c as At}from"./types-DYz12j32.js";import"./DialogShell-BbpG8sot.js";import"./radix-B9EIjzyN.js";import"./query-DVc6ZTRQ.js";import"./router-CUBM_FND.js";const Tt=[{value:"fatal",labelKey:"fatal"},{value:"error",labelKey:"error"},{value:"warn",labelKey:"warn"},{value:"info",labelKey:"info"},{value:"debug",labelKey:"debug"},{value:"trace",labelKey:"trace"}],ce=[{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 ne(t){var l,m,p,o,a,i,v,T,M,S,O;const s=t.storePayloads,r=c=>typeof c=="boolean"?c:typeof s=="boolean"?s:!0;return{port:String(t.port??((l=t.http)==null?void 0:l.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 c=t.bodyLimit;return typeof c=="number"&&Number.isFinite(c)&&c>0?String(Math.max(1,Math.round(c/(1024*1024)))):"10"})(),enableRoutingFallback:t.enableRoutingFallback===!0,httpEnabled:((p=t.http)==null?void 0:p.enabled)!==!1,httpPort:String(((o=t.http)==null?void 0:o.port)??t.port??4100),httpHost:((a=t.http)==null?void 0:a.host)??t.host??"127.0.0.1",httpsEnabled:((i=t.https)==null?void 0:i.enabled)===!0,httpsPort:String(((v=t.https)==null?void 0:v.port)??4443),httpsHost:((T=t.https)==null?void 0:T.host)??t.host??"127.0.0.1",httpsKeyPath:((M=t.https)==null?void 0:M.keyPath)??"",httpsCertPath:((S=t.https)==null?void 0:S.certPath)??"",httpsCaPath:((O=t.https)==null?void 0:O.caPath)??""}}function oe(t){return{enabled:t.enabled,username:t.username??"",password:"",confirmPassword:""}}function Mt({activeSection:t,onSelectSection:s}){const{t:r}=C();return e.jsxs(e.Fragment,{children:[e.jsx("nav",{className:"hidden xl:block",children:e.jsxs(P,{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:ce.map((l,m)=>e.jsxs("button",{type:"button",onClick:()=>s(l.id),className:L("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===l.id?"bg-secondary text-foreground":"text-muted-foreground hover:text-foreground"),children:[e.jsx("span",{className:L("flex h-7 w-7 items-center justify-center rounded-lg text-[11px] font-semibold",t===l.id?"bg-primary text-primary-foreground":"bg-secondary text-muted-foreground"),children:m+1}),e.jsx("span",{children:r(l.labelKey)})]},l.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:ce.map(l=>e.jsx("button",{type:"button",onClick:()=>s(l.id),className:L("rounded-lg px-4 py-2 text-xs font-semibold transition-all duration-150",t===l.id?"bg-secondary text-foreground font-medium":"text-muted-foreground hover:text-foreground hover:bg-secondary/50"),children:r(l.labelKey)},l.id))})})})]})}function Ot({defaultsSummary:t,errors:s,form:r,onInputChange:l,onSetForm:m,sectionRef:p}){const{t:o}=C();return e.jsx(P,{id:"section-basics",ref:p,className:"bg-card shadow-[var(--surface-shadow)]",children:e.jsxs(A,{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:o("settings.sections.basics")}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:o("settings.description")})]}),e.jsxs("div",{className:"grid gap-2 sm:grid-cols-3",children:[e.jsx(le,{label:o("settings.fields.retention"),value:r.logRetentionDays}),e.jsx(le,{label:o("settings.fields.logExportTimeout"),value:`${r.logExportTimeoutSeconds}s`}),e.jsx(le,{label:o("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:o("settings.fields.port")}),e.jsx(j,{type:"number",min:1,max:65535,value:r.port,onChange:a=>l("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:o("settings.fields.host")}),e.jsx(j,{value:r.host,onChange:a=>l("host")(a.target.value),placeholder:o("settings.fields.hostPlaceholder")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(f,{children:o("settings.fields.retention")}),e.jsx(j,{type:"number",min:1,max:365,value:r.logRetentionDays,onChange:a=>l("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:o("settings.fields.logExportTimeout")}),e.jsx(j,{type:"number",min:5,max:600,value:r.logExportTimeoutSeconds,onChange:a=>l("logExportTimeoutSeconds")(a.target.value),"aria-invalid":!!s.logExportTimeoutSeconds}),e.jsx("p",{className:"text-xs text-muted-foreground",children:o("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:o("settings.fields.bodyLimit")}),e.jsx(j,{type:"number",min:1,max:2048,value:r.bodyLimitMb,onChange:a=>l("bodyLimitMb")(a.target.value),"aria-invalid":!!s.bodyLimitMb}),e.jsx("p",{className:"text-xs text-muted-foreground",children:o("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:o("settings.fields.logLevel")}),e.jsxs(Pt,{value:r.logLevel,onValueChange:a=>m(i=>({...i,logLevel:a})),children:[e.jsx(St,{children:e.jsx(kt,{})}),e.jsx(Rt,{children:Tt.map(a=>e.jsx(Et,{value:a.value,children:o(`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(ie,{label:o("settings.fields.storeRequestPayloads"),hint:o("settings.fields.storeRequestPayloadsHint"),checked:r.storeRequestPayloads,onCheckedChange:a=>m(i=>({...i,storeRequestPayloads:a}))}),e.jsx(ie,{label:o("settings.fields.storeResponsePayloads"),hint:o("settings.fields.storeResponsePayloadsHint"),checked:r.storeResponsePayloads,onCheckedChange:a=>m(i=>({...i,storeResponsePayloads:a}))}),e.jsx(ie,{label:o("settings.fields.enableRoutingFallback"),hint:o("settings.fields.enableRoutingFallbackHint"),checked:r.enableRoutingFallback,onCheckedChange:a=>m(i=>({...i,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:o("settings.fields.defaults")}),e.jsx("p",{className:"mt-2 text-sm",children:t??o("settings.defaults.none")})]})]})]})})}function Ft({errors:t,form:s,onSetForm:r,protocolChangesPending:l,sectionRef:m}){const{t:p}=C();return e.jsx(P,{id:"section-protocol",ref:m,className:"bg-card shadow-[var(--surface-shadow)]",children:e.jsxs(A,{className:"space-y-6 pt-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold",children:p("settings.sections.protocol")}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:p("settings.protocol.description")})]}),l?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(se,{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:p("settings.protocol.restartWarning")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:p("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:p("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(se,{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:p("settings.protocol.http.enable")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:p("settings.protocol.http.hint")})]}),e.jsx(Q,{checked:s.httpEnabled,onCheckedChange:o=>r(a=>({...a,httpEnabled:o}))})]}),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:p("settings.protocol.http.port")}),e.jsx(j,{type:"number",min:1,max:65535,value:s.httpPort,onChange:o=>r(a=>({...a,httpPort:o.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:p("settings.protocol.http.host")}),e.jsx(j,{value:s.httpHost,onChange:o=>r(a=>({...a,httpHost:o.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:p("settings.protocol.https.enable")}),e.jsx(yt,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:p("settings.protocol.https.hint")})]}),e.jsx(Q,{checked:s.httpsEnabled,onCheckedChange:o=>r(a=>({...a,httpsEnabled:o}))})]}),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:p("settings.protocol.https.port")}),e.jsx(j,{type:"number",min:1,max:65535,value:s.httpsPort,onChange:o=>r(a=>({...a,httpsPort:o.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:p("settings.protocol.https.host")}),e.jsx(j,{value:s.httpsHost,onChange:o=>r(a=>({...a,httpsHost:o.target.value})),placeholder:"127.0.0.1"})]})]}),e.jsx(re,{label:p("settings.protocol.https.keyPath"),value:s.httpsKeyPath,onChange:o=>r(a=>({...a,httpsKeyPath:o})),placeholder:"~/.cc-gw/certs/key.pem"}),e.jsx(re,{label:p("settings.protocol.https.certPath"),value:s.httpsCertPath,onChange:o=>r(a=>({...a,httpsCertPath:o})),placeholder:"~/.cc-gw/certs/cert.pem"}),e.jsx(re,{label:p("settings.protocol.https.caPath"),value:s.httpsCaPath,onChange:o=>r(a=>({...a,httpsCaPath:o})),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(se,{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:p("settings.protocol.https.warning")}),e.jsx("p",{className:"text-xs leading-relaxed text-warning",children:p("settings.protocol.https.tip")})]})]})})]}):null]})]})})}function Dt({authErrors:t,authForm:s,authLoading:r,authSettings:l,needsPassword:m,onSetAuthForm:p,sectionRef:o}){const{t:a}=C();return e.jsx(P,{id:"section-security",ref:o,className:"bg-card shadow-[var(--surface-shadow)]",children:e.jsxs(A,{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&&!l?e.jsx(Ie,{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(W,{variant:s.enabled?"success":"secondary",children:s.enabled?a("settings.auth.statusEnabled"):a("settings.auth.statusDisabled")}),e.jsx(Q,{checked:s.enabled,onCheckedChange:i=>p(v=>({...v,enabled:i}))})]})]}),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:i=>p(v=>({...v,username:i.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:i=>p(v=>({...v,password:i.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:i=>p(v=>({...v,confirmPassword:i.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:l!=null&&l.enabled?a("settings.auth.statusEnabled"):a("settings.auth.statusDisabled")}),l!=null&&l.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"),": ",l.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 Ht({configPath:t,onCopyPath:s,sectionRef:r}){const{t:l}=C();return e.jsx(P,{id:"section-config-file",ref:r,className:"bg-card shadow-[var(--surface-shadow)]",children:e.jsxs(A,{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:l("settings.sections.configFile")}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:l("settings.file.description")})]}),e.jsxs(E,{variant:"outline",size:"sm",onClick:s,className:"w-full sm:w-auto",children:[e.jsx(vt,{className:"mr-2 h-4 w-4"}),l("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||l("settings.file.unknown")}),e.jsx("div",{className:"rounded-lg bg-secondary px-4 py-3 text-xs text-muted-foreground",children:l("help.note")})]})})}function Kt({cleaning:t,clearingAll:s,compacting:r,dbSizeDisplay:l,onCompact:m,onOpenCleanup:p,onOpenClearAll:o,sectionRef:a}){const{t:i}=C();return e.jsx(P,{id:"section-cleanup",ref:a,className:"bg-card shadow-[var(--surface-shadow)]",children:e.jsxs(A,{className:"space-y-4 pt-6",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold",children:i("settings.sections.cleanup")}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:i("settings.cleanup.description")})]}),e.jsxs("div",{className:"rounded-lg bg-secondary px-3 py-1.5 text-xs",children:[e.jsxs("span",{className:"text-muted-foreground",children:[i("settings.cleanup.dbSizeLabel"),": "]}),e.jsx("span",{className:"font-semibold tabular-nums text-foreground",children:l})]})]}),e.jsx("div",{className:"rounded-lg bg-secondary px-4 py-3 text-xs text-muted-foreground",children:i("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(W,{variant:"warning",children:i("settings.cleanup.softLabel")}),e.jsx("p",{className:"text-sm font-medium",children:i("settings.cleanup.softTitle")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:i("settings.cleanup.softDescription")}),e.jsx(E,{variant:"outline",onClick:p,disabled:t,className:"w-full sm:w-auto",children:i(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(W,{variant:"outline",className:"border-destructive/40 bg-destructive/10 text-destructive",children:i("settings.cleanup.hardLabel")}),e.jsx("p",{className:"text-sm font-medium",children:i("settings.cleanup.hardTitle")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:i("settings.cleanup.clearAllWarning")}),e.jsx(E,{variant:"destructive",onClick:o,disabled:s,className:"w-full sm:w-auto",children:i(s?"settings.cleanup.clearingAll":"settings.cleanup.clearAll")})]})})]}),e.jsx("div",{className:"rounded-xl border border-border bg-secondary/40 p-5",children:e.jsxs("div",{className:"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("p",{className:"text-sm font-medium",children:i("settings.cleanup.compactTitle")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:i("settings.cleanup.compactDescription")})]}),e.jsx(E,{variant:"outline",onClick:m,disabled:r,className:"w-full sm:w-auto",children:i(r?"common.actions.compacting":"common.actions.compact")})]})})]})})}function qt({dirtyCount:t,protocolChangesPending:s,onReset:r,onSave:l,saving:m}){const{t:p}=C();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(W,{variant:"secondary",children:p("settings.overview.unsavedCount",{count:t})}),e.jsx("p",{className:"text-sm text-muted-foreground",children:p(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(E,{variant:"outline",onClick:r,disabled:m,className:"w-full lg:w-auto",children:p("common.actions.reset")}),e.jsx(E,{onClick:l,disabled:m,className:"w-full lg:w-auto",children:p(m?"common.actions.saving":"common.actions.save")})]})]})}function le({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 ie({checked:t,className:s,hint:r,hintClassName:l,label:m,labelClassName:p,onCheckedChange:o}){return e.jsxs("div",{className:L("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:L("text-sm font-semibold text-foreground",p),children:m}),e.jsx("p",{className:L("text-xs text-muted-foreground",l),children:r})]}),e.jsx(Q,{checked:t,onCheckedChange:o,className:"self-start sm:self-auto"})]})}function re({label:t,onChange:s,placeholder:r,value:l}){return e.jsxs("div",{className:"space-y-2",children:[e.jsx(f,{children:t}),e.jsx(j,{value:l,onChange:m=>s(m.target.value),placeholder:r,className:"font-mono text-xs"})]})}const D={authStatusRequest(){return{url:"/api/auth/web",method:"GET"}},saveWebAuth:async t=>Nt(wt.post("/api/auth/web",t)),cleanupLogs:async()=>I({url:"/api/logs/cleanup",method:"POST"}),clearLogs:async()=>I({url:"/api/logs/clear",method:"POST"}),dbInfo:async()=>I({url:"/api/db/info",method:"GET"}),compactDb:async()=>I({url:"/api/db/compact",method:"POST"})};function Bt(){const{t}=C(),{pushToast:s}=Ct(),[r,l]=u.useState(ce[0].id),m=u.useRef(new Map),p=u.useCallback(n=>{const h=m.current.get(n);h&&h.scrollIntoView({behavior:"smooth",block:"start"})},[]),o=u.useCallback(n=>h=>{h?m.current.set(n,h):m.current.delete(n)},[]),a=ae(F.config.info(),Ve.configInfoRequest()),i=ae(F.auth.web(),D.authStatusRequest()),v=z({mutationFn:D.saveWebAuth,successToast:()=>({title:t("settings.auth.toast.success")}),errorToast:n=>({title:t("settings.auth.toast.failure",{message:n.message})}),invalidateKeys:[F.auth.web()]}),T=z({mutationFn:D.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"]]}),M=z({mutationFn:D.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"]]}),S=ae(F.db.info(),{url:"/api/db/info",method:"GET"}),O=z({mutationFn:D.compactDb,successToast:()=>({title:t("settings.toast.compactSuccess.title"),description:t("settings.toast.compactSuccess.desc")}),errorToast:n=>({title:t("settings.toast.compactFailure",{message:n.message})}),invalidateKeys:[F.db.info(),["dashboard"]]}),[c,de]=u.useState(null),[H,ze]=u.useState(""),[d,K]=u.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:""}),[We,G]=u.useState({}),[Qe,ue]=u.useState(!1),[Ge,pe]=u.useState(!1),[Je,me]=u.useState(!1),[_e,$e]=u.useState(!1),[Ue,Xe]=u.useState(!1),[b,he]=u.useState(null),[g,q]=u.useState({enabled:!1,username:"",password:"",confirmPassword:""}),[Ye,B]=u.useState({}),[Ze,ge]=u.useState(!1),et=u.useMemo(()=>{if(!(c!=null&&c.defaults))return null;const n=[];return c.defaults.completion&&n.push(t("settings.defaults.completion",{model:c.defaults.completion})),c.defaults.reasoning&&n.push(t("settings.defaults.reasoning",{model:c.defaults.reasoning})),c.defaults.background&&n.push(t("settings.defaults.background",{model:c.defaults.background})),n.length>0?n.join(" | "):t("settings.defaults.none")},[c,t]),tt=u.useMemo(()=>d.httpEnabled&&d.httpsEnabled?t("settings.overview.values.httpAndHttps"):d.httpsEnabled?t("settings.overview.values.httpsOnly"):t("settings.overview.values.httpOnly"),[d.httpEnabled,d.httpsEnabled,t]),st=u.useMemo(()=>g.enabled?b!=null&&b.hasPassword?g.username.trim()!==(b.username??""):!0:!1,[g.enabled,g.username,b]),k=u.useMemo(()=>c?ne(c):null,[c]),J=u.useMemo(()=>k?JSON.stringify(d)!==JSON.stringify(k):!1,[d,k]),_=u.useMemo(()=>b?oe(b):null,[b]),$=u.useMemo(()=>_?JSON.stringify(g)!==JSON.stringify(_):!1,[g,_]),at=u.useMemo(()=>k?["httpEnabled","httpPort","httpHost","httpsEnabled","httpsPort","httpsHost","httpsKeyPath","httpsCertPath","httpsCaPath","port","host"].some(h=>d[h]!==k[h]):!1,[d,k]);u.useEffect(()=>{a.data&&(de(a.data.config),ze(a.data.path),K(ne(a.data.config)))},[a.data]),u.useEffect(()=>{i.data&&(he(i.data),q(oe(i.data)),B({}))},[i.data]),u.useEffect(()=>{!a.isError||!a.error||s({title:t("settings.toast.loadFailure",{message:a.error.message}),variant:"error"})},[a.error,a.isError,s,t]),u.useEffect(()=>{!i.isError||!i.error||s({title:t("settings.toast.authLoadFailure",{message:i.error.message}),variant:"error"})},[i.error,i.isError,s,t]);const nt=u.useCallback(n=>h=>{K(y=>({...y,[n]:h}))},[]),xe=u.useCallback(()=>{const n={};if(!d.httpEnabled&&!d.httpsEnabled&&(n.protocol=t("settings.validation.protocolRequired")),d.httpEnabled){const w=Number(d.httpPort);(!Number.isFinite(w)||w<1||w>65535)&&(n.httpPort=t("settings.validation.httpPort"))}if(d.httpsEnabled){const w=Number(d.httpsPort);(!Number.isFinite(w)||w<1||w>65535)&&(n.httpsPort=t("settings.validation.httpsPort")),(!d.httpsKeyPath||!d.httpsCertPath)&&(n.protocol=t("settings.validation.httpsCertificate"))}const h=Number(d.port);(!Number.isFinite(h)||h<1||h>65535)&&(n.port=t("settings.validation.port"));const y=Number(d.logRetentionDays);(!Number.isFinite(y)||y<1||y>365)&&(n.logRetentionDays=t("settings.validation.retention"));const N=Number(d.logExportTimeoutSeconds);(!Number.isFinite(N)||N<5||N>600)&&(n.logExportTimeoutSeconds=t("settings.validation.logExportTimeout"));const R=Number(d.bodyLimitMb);return(!Number.isFinite(R)||R<1||R>2048)&&(n.bodyLimitMb=t("settings.validation.bodyLimit")),G(n),Object.keys(n).length===0},[d,t]),fe=u.useCallback(()=>{const n={},h=g.username.trim(),y=b?h!==(b.username??""):!0,N=g.enabled&&(!(b!=null&&b.hasPassword)||y);return g.enabled&&!h&&(n.username=t("settings.auth.validation.username")),g.password&&g.password.length<6&&(n.password=t("settings.auth.validation.minLength")),N&&!g.password&&(n.password=t("settings.auth.validation.passwordRequired")),(g.password||g.confirmPassword)&&g.password!==g.confirmPassword&&(n.confirmPassword=t("settings.auth.validation.confirmMismatch")),B(n),Object.keys(n).length===0},[g,b,t]),U=u.useCallback(async()=>{var n,h,y,N,R,w,be,ye,ve,je,Ne,we,Ce,Pe,Se,ke,Re,Ee,Le,Ae,Te,Me,Oe,Fe,De,He;if(!c){s({title:t("settings.toast.loadFailure",{message:t("settings.toast.missingConfig")}),variant:"error"});return}if(xe()){ue(!0);try{const V=Number(d.port),ut=Number(d.logRetentionDays),pt=Number(d.logExportTimeoutSeconds),mt=Number(d.bodyLimitMb),x={...c,http:{enabled:d.httpEnabled,port:Number(d.httpPort),host:d.httpHost.trim()||"127.0.0.1"},https:{enabled:d.httpsEnabled,port:Number(d.httpsPort),host:d.httpsHost.trim()||"127.0.0.1",keyPath:d.httpsKeyPath.trim(),certPath:d.httpsCertPath.trim(),caPath:d.httpsCaPath.trim()||void 0},port:V,host:d.host.trim()||void 0,logRetentionDays:ut,logExportTimeoutSeconds:Math.min(Math.max(Math.round(pt),5),600),storeRequestPayloads:d.storeRequestPayloads,storeResponsePayloads:d.storeResponsePayloads,logLevel:d.logLevel,bodyLimit:Math.max(1,Math.floor(mt*1024*1024)),enableRoutingFallback:d.enableRoutingFallback};delete x.requestLogging,delete x.responseLogging;const Ke={...x};delete Ke.webAuth,await Ve.saveConfig(Ke),de({...x,webAuth:c.webAuth});const qe=te=>(te==null?void 0:te.trim())||void 0,ht=c.port??((n=c.http)==null?void 0:n.port)??4100,gt=x.port??((h=x.http)==null?void 0:h.port)??4100,xt=((y=c.host)==null?void 0:y.trim())||((R=(N=c.http)==null?void 0:N.host)==null?void 0:R.trim())||"127.0.0.1",ft=((w=x.host)==null?void 0:w.trim())||((ye=(be=x.http)==null?void 0:be.host)==null?void 0:ye.trim())||"127.0.0.1",bt=ht!==gt||xt!==ft||((ve=c.http)==null?void 0:ve.enabled)!==((je=x.http)==null?void 0:je.enabled)||((Ne=c.http)==null?void 0:Ne.port)!==((we=x.http)==null?void 0:we.port)||(((Ce=c.http)==null?void 0:Ce.host)??c.host??"127.0.0.1")!==(((Pe=x.http)==null?void 0:Pe.host)??x.host??"127.0.0.1")||((Se=c.https)==null?void 0:Se.enabled)!==((ke=x.https)==null?void 0:ke.enabled)||((Re=c.https)==null?void 0:Re.port)!==((Ee=x.https)==null?void 0:Ee.port)||(((Le=c.https)==null?void 0:Le.host)??c.host??"127.0.0.1")!==(((Ae=x.https)==null?void 0:Ae.host)??x.host??"127.0.0.1")||((Te=c.https)==null?void 0:Te.keyPath)!==((Me=x.https)==null?void 0:Me.keyPath)||((Oe=c.https)==null?void 0:Oe.certPath)!==((Fe=x.https)==null?void 0:Fe.certPath)||qe((De=c.https)==null?void 0:De.caPath)!==qe((He=x.https)==null?void 0:He.caPath);s({title:t(bt?"settings.toast.protocolRestartRequired":"settings.toast.saveSuccess"),variant:"success"}),a.refetch()}catch(V){s({title:t("settings.toast.saveFailure",{message:V instanceof Error?V.message:"unknown"}),variant:"error"})}finally{ue(!1)}}},[c,a,d,s,t,xe]),X=u.useCallback(()=>{c&&(K(ne(c)),G({}))},[c]),Y=u.useCallback(async()=>{if(fe()){ge(!0);try{const n={enabled:g.enabled,username:g.username.trim()||void 0};g.password&&(n.password=g.password);const h=await v.mutateAsync(n);h.auth&&(he(h.auth),q({enabled:h.auth.enabled,username:h.auth.username??"",password:"",confirmPassword:""}),B({})),i.refetch()}catch{}finally{ge(!1)}}},[g,i,v,fe]),Z=u.useCallback(()=>{b&&(q(oe(b)),B({}))},[b]),ot=u.useCallback(async()=>{J&&await U(),$&&await Y()},[Y,U,$,J]),lt=u.useCallback(()=>{X(),Z()},[Z,X]),it=u.useCallback(async()=>{if(!H){s({title:t("settings.toast.copyFailure",{message:t("settings.file.unknown")}),variant:"error"});return}try{await Lt(H),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"})}},[H,s,t]),rt=u.useCallback(async()=>{pe(!0);try{await T.mutateAsync()}catch{}finally{pe(!1)}},[T]),ct=u.useCallback(async()=>{me(!0);try{await M.mutateAsync()}catch{}finally{me(!1)}},[M]),dt=S.data?At(S.data.totalBytes??S.data.sizeBytes):"-",ee=a.isPending||!c&&a.isFetching;return u.useEffect(()=>{if(ee)return;const n=Array.from(m.current.values());if(n.length===0)return;const h=new IntersectionObserver(y=>{for(const N of y)if(N.isIntersecting){l(N.target.id);break}},{rootMargin:"-80px 0px -60% 0px",threshold:0});for(const y of n)h.observe(y);return()=>h.disconnect()},[ee]),{activeSection:r,authErrors:Ye,authForm:g,authQuery:i,authSettings:b,clearingAll:Je,cleaning:Ge,compacting:O.isPending,config:c,configPath:H,configQuery:a,confirmCleanupOpen:_e,confirmClearAllOpen:Ue,dbSizeDisplay:dt,defaultsSummary:et,errors:We,form:d,handleAuthReset:Z,handleAuthSave:Y,handleCleanupLogs:rt,handleClearAllLogs:ct,handleCompact:O.mutate,handleCopyPath:it,handleInputChange:nt,handleReset:X,handleResetAll:lt,handleSave:U,handleSaveAll:ot,handleSectionClick:p,isAuthDirty:$,isConfigDirty:J,isLoading:ee,needsPassword:st,protocolSummaryLabel:tt,protocolChangesPending:at,saving:Qe,savingAuth:Ze,sectionRefs:m,setAuthForm:q,setConfirmCleanupOpen:$e,setConfirmClearAllOpen:Xe,setErrors:G,setForm:K,setSectionRef:o,t}}function is(){const{t}=C(),s=Bt(),r=Number(s.isConfigDirty)+Number(s.isAuthDirty);return e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx(jt,{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(Ie,{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(Mt,{activeSection:s.activeSection,onSelectSection:s.handleSectionClick}),e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx(Ot,{defaultsSummary:s.defaultsSummary,errors:s.errors,form:s.form,onInputChange:s.handleInputChange,onSetForm:s.setForm,sectionRef:s.setSectionRef("section-basics")}),e.jsx(Ft,{errors:s.errors,form:s.form,onSetForm:s.setForm,protocolChangesPending:s.protocolChangesPending,sectionRef:s.setSectionRef("section-protocol")}),e.jsx(Dt,{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(Ht,{configPath:s.configPath,onCopyPath:()=>void s.handleCopyPath(),sectionRef:s.setSectionRef("section-config-file")}),e.jsx(Kt,{cleaning:s.cleaning,clearingAll:s.clearingAll,compacting:s.compacting,dbSizeDisplay:s.dbSizeDisplay,onCompact:s.handleCompact,onOpenCleanup:()=>s.setConfirmCleanupOpen(!0),onOpenClearAll:()=>s.setConfirmClearAllOpen(!0),sectionRef:s.setSectionRef("section-cleanup")})]})]}),e.jsx(qt,{dirtyCount:r,protocolChangesPending:s.protocolChangesPending,onReset:s.handleResetAll,onSave:()=>void s.handleSaveAll(),saving:s.saving||s.savingAuth})]}):e.jsx(P,{children:e.jsx(A,{className:"pt-6",children:e.jsx("p",{className:"text-sm font-medium text-destructive",children:t("settings.toast.missingConfig")})})}),e.jsx(Be,{open:s.confirmCleanupOpen,onOpenChange:l=>{!l&&!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(Be,{open:s.confirmClearAllOpen,onOpenChange:l=>{!l&&!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{is as default};
|
|
1
|
+
import{j as e,aW as se,aP as yt,ak as vt,r as u}from"./vendor-D2wC0h2o.js";import{C as Be}from"./ConfirmDialog-BOe5HI56.js";import{P as Ie}from"./PageState-U6DpaNu4.js";import{P as jt}from"./PageToolbar-BnDacS2l.js";import{C as P,a as A}from"./card-DhuLMeO9.js";import{B as E,r as I,i as Nt,d as wt,a as Ct,c as ae,q as F}from"./app-BnQl39hq.js";import{B as W}from"./badge-RZTsODn-.js";import{L as f,I as j}from"./label-Da-JMxO2.js";import{S as Q}from"./switch-CeKtgMDT.js";import{S as Pt,a as St,b as kt,c as Rt,d as Et}from"./select-BTwqvh0l.js";import{c as L}from"./global-CJOj9WGx.js";import{u as C}from"./i18n-Dp-o1LhZ.js";import{u as z}from"./useAppMutation-Cix9n50u.js";import{g as Ve}from"./gateway-DxCj_uok.js";import{c as Lt}from"./clipboard-BnAnBk_-.js";import{c as At}from"./types-DYz12j32.js";import"./DialogShell-BbpG8sot.js";import"./radix-B9EIjzyN.js";import"./query-DVc6ZTRQ.js";import"./router-CUBM_FND.js";const Tt=[{value:"fatal",labelKey:"fatal"},{value:"error",labelKey:"error"},{value:"warn",labelKey:"warn"},{value:"info",labelKey:"info"},{value:"debug",labelKey:"debug"},{value:"trace",labelKey:"trace"}],ce=[{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 ne(t){var l,m,p,o,a,i,v,T,M,S,O;const s=t.storePayloads,r=c=>typeof c=="boolean"?c:typeof s=="boolean"?s:!0;return{port:String(t.port??((l=t.http)==null?void 0:l.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 c=t.bodyLimit;return typeof c=="number"&&Number.isFinite(c)&&c>0?String(Math.max(1,Math.round(c/(1024*1024)))):"10"})(),enableRoutingFallback:t.enableRoutingFallback===!0,httpEnabled:((p=t.http)==null?void 0:p.enabled)!==!1,httpPort:String(((o=t.http)==null?void 0:o.port)??t.port??4100),httpHost:((a=t.http)==null?void 0:a.host)??t.host??"127.0.0.1",httpsEnabled:((i=t.https)==null?void 0:i.enabled)===!0,httpsPort:String(((v=t.https)==null?void 0:v.port)??4443),httpsHost:((T=t.https)==null?void 0:T.host)??t.host??"127.0.0.1",httpsKeyPath:((M=t.https)==null?void 0:M.keyPath)??"",httpsCertPath:((S=t.https)==null?void 0:S.certPath)??"",httpsCaPath:((O=t.https)==null?void 0:O.caPath)??""}}function oe(t){return{enabled:t.enabled,username:t.username??"",password:"",confirmPassword:""}}function Mt({activeSection:t,onSelectSection:s}){const{t:r}=C();return e.jsxs(e.Fragment,{children:[e.jsx("nav",{className:"hidden xl:block",children:e.jsxs(P,{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:ce.map((l,m)=>e.jsxs("button",{type:"button",onClick:()=>s(l.id),className:L("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===l.id?"bg-secondary text-foreground":"text-muted-foreground hover:text-foreground"),children:[e.jsx("span",{className:L("flex h-7 w-7 items-center justify-center rounded-lg text-[11px] font-semibold",t===l.id?"bg-primary text-primary-foreground":"bg-secondary text-muted-foreground"),children:m+1}),e.jsx("span",{children:r(l.labelKey)})]},l.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:ce.map(l=>e.jsx("button",{type:"button",onClick:()=>s(l.id),className:L("rounded-lg px-4 py-2 text-xs font-semibold transition-all duration-150",t===l.id?"bg-secondary text-foreground font-medium":"text-muted-foreground hover:text-foreground hover:bg-secondary/50"),children:r(l.labelKey)},l.id))})})})]})}function Ot({defaultsSummary:t,errors:s,form:r,onInputChange:l,onSetForm:m,sectionRef:p}){const{t:o}=C();return e.jsx(P,{id:"section-basics",ref:p,className:"bg-card shadow-[var(--surface-shadow)]",children:e.jsxs(A,{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:o("settings.sections.basics")}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:o("settings.description")})]}),e.jsxs("div",{className:"grid gap-2 sm:grid-cols-3",children:[e.jsx(le,{label:o("settings.fields.retention"),value:r.logRetentionDays}),e.jsx(le,{label:o("settings.fields.logExportTimeout"),value:`${r.logExportTimeoutSeconds}s`}),e.jsx(le,{label:o("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:o("settings.fields.port")}),e.jsx(j,{type:"number",min:1,max:65535,value:r.port,onChange:a=>l("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:o("settings.fields.host")}),e.jsx(j,{value:r.host,onChange:a=>l("host")(a.target.value),placeholder:o("settings.fields.hostPlaceholder")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(f,{children:o("settings.fields.retention")}),e.jsx(j,{type:"number",min:1,max:365,value:r.logRetentionDays,onChange:a=>l("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:o("settings.fields.logExportTimeout")}),e.jsx(j,{type:"number",min:5,max:600,value:r.logExportTimeoutSeconds,onChange:a=>l("logExportTimeoutSeconds")(a.target.value),"aria-invalid":!!s.logExportTimeoutSeconds}),e.jsx("p",{className:"text-xs text-muted-foreground",children:o("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:o("settings.fields.bodyLimit")}),e.jsx(j,{type:"number",min:1,max:2048,value:r.bodyLimitMb,onChange:a=>l("bodyLimitMb")(a.target.value),"aria-invalid":!!s.bodyLimitMb}),e.jsx("p",{className:"text-xs text-muted-foreground",children:o("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:o("settings.fields.logLevel")}),e.jsxs(Pt,{value:r.logLevel,onValueChange:a=>m(i=>({...i,logLevel:a})),children:[e.jsx(St,{children:e.jsx(kt,{})}),e.jsx(Rt,{children:Tt.map(a=>e.jsx(Et,{value:a.value,children:o(`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(ie,{label:o("settings.fields.storeRequestPayloads"),hint:o("settings.fields.storeRequestPayloadsHint"),checked:r.storeRequestPayloads,onCheckedChange:a=>m(i=>({...i,storeRequestPayloads:a}))}),e.jsx(ie,{label:o("settings.fields.storeResponsePayloads"),hint:o("settings.fields.storeResponsePayloadsHint"),checked:r.storeResponsePayloads,onCheckedChange:a=>m(i=>({...i,storeResponsePayloads:a}))}),e.jsx(ie,{label:o("settings.fields.enableRoutingFallback"),hint:o("settings.fields.enableRoutingFallbackHint"),checked:r.enableRoutingFallback,onCheckedChange:a=>m(i=>({...i,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:o("settings.fields.defaults")}),e.jsx("p",{className:"mt-2 text-sm",children:t??o("settings.defaults.none")})]})]})]})})}function Ft({errors:t,form:s,onSetForm:r,protocolChangesPending:l,sectionRef:m}){const{t:p}=C();return e.jsx(P,{id:"section-protocol",ref:m,className:"bg-card shadow-[var(--surface-shadow)]",children:e.jsxs(A,{className:"space-y-6 pt-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold",children:p("settings.sections.protocol")}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:p("settings.protocol.description")})]}),l?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(se,{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:p("settings.protocol.restartWarning")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:p("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:p("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(se,{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:p("settings.protocol.http.enable")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:p("settings.protocol.http.hint")})]}),e.jsx(Q,{checked:s.httpEnabled,onCheckedChange:o=>r(a=>({...a,httpEnabled:o}))})]}),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:p("settings.protocol.http.port")}),e.jsx(j,{type:"number",min:1,max:65535,value:s.httpPort,onChange:o=>r(a=>({...a,httpPort:o.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:p("settings.protocol.http.host")}),e.jsx(j,{value:s.httpHost,onChange:o=>r(a=>({...a,httpHost:o.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:p("settings.protocol.https.enable")}),e.jsx(yt,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:p("settings.protocol.https.hint")})]}),e.jsx(Q,{checked:s.httpsEnabled,onCheckedChange:o=>r(a=>({...a,httpsEnabled:o}))})]}),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:p("settings.protocol.https.port")}),e.jsx(j,{type:"number",min:1,max:65535,value:s.httpsPort,onChange:o=>r(a=>({...a,httpsPort:o.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:p("settings.protocol.https.host")}),e.jsx(j,{value:s.httpsHost,onChange:o=>r(a=>({...a,httpsHost:o.target.value})),placeholder:"127.0.0.1"})]})]}),e.jsx(re,{label:p("settings.protocol.https.keyPath"),value:s.httpsKeyPath,onChange:o=>r(a=>({...a,httpsKeyPath:o})),placeholder:"~/.cc-gw/certs/key.pem"}),e.jsx(re,{label:p("settings.protocol.https.certPath"),value:s.httpsCertPath,onChange:o=>r(a=>({...a,httpsCertPath:o})),placeholder:"~/.cc-gw/certs/cert.pem"}),e.jsx(re,{label:p("settings.protocol.https.caPath"),value:s.httpsCaPath,onChange:o=>r(a=>({...a,httpsCaPath:o})),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(se,{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:p("settings.protocol.https.warning")}),e.jsx("p",{className:"text-xs leading-relaxed text-warning",children:p("settings.protocol.https.tip")})]})]})})]}):null]})]})})}function Dt({authErrors:t,authForm:s,authLoading:r,authSettings:l,needsPassword:m,onSetAuthForm:p,sectionRef:o}){const{t:a}=C();return e.jsx(P,{id:"section-security",ref:o,className:"bg-card shadow-[var(--surface-shadow)]",children:e.jsxs(A,{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&&!l?e.jsx(Ie,{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(W,{variant:s.enabled?"success":"secondary",children:s.enabled?a("settings.auth.statusEnabled"):a("settings.auth.statusDisabled")}),e.jsx(Q,{checked:s.enabled,onCheckedChange:i=>p(v=>({...v,enabled:i}))})]})]}),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:i=>p(v=>({...v,username:i.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:i=>p(v=>({...v,password:i.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:i=>p(v=>({...v,confirmPassword:i.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:l!=null&&l.enabled?a("settings.auth.statusEnabled"):a("settings.auth.statusDisabled")}),l!=null&&l.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"),": ",l.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 Ht({configPath:t,onCopyPath:s,sectionRef:r}){const{t:l}=C();return e.jsx(P,{id:"section-config-file",ref:r,className:"bg-card shadow-[var(--surface-shadow)]",children:e.jsxs(A,{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:l("settings.sections.configFile")}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:l("settings.file.description")})]}),e.jsxs(E,{variant:"outline",size:"sm",onClick:s,className:"w-full sm:w-auto",children:[e.jsx(vt,{className:"mr-2 h-4 w-4"}),l("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||l("settings.file.unknown")}),e.jsx("div",{className:"rounded-lg bg-secondary px-4 py-3 text-xs text-muted-foreground",children:l("help.note")})]})})}function Kt({cleaning:t,clearingAll:s,compacting:r,dbSizeDisplay:l,onCompact:m,onOpenCleanup:p,onOpenClearAll:o,sectionRef:a}){const{t:i}=C();return e.jsx(P,{id:"section-cleanup",ref:a,className:"bg-card shadow-[var(--surface-shadow)]",children:e.jsxs(A,{className:"space-y-4 pt-6",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold",children:i("settings.sections.cleanup")}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:i("settings.cleanup.description")})]}),e.jsxs("div",{className:"rounded-lg bg-secondary px-3 py-1.5 text-xs",children:[e.jsxs("span",{className:"text-muted-foreground",children:[i("settings.cleanup.dbSizeLabel"),": "]}),e.jsx("span",{className:"font-semibold tabular-nums text-foreground",children:l})]})]}),e.jsx("div",{className:"rounded-lg bg-secondary px-4 py-3 text-xs text-muted-foreground",children:i("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(W,{variant:"warning",children:i("settings.cleanup.softLabel")}),e.jsx("p",{className:"text-sm font-medium",children:i("settings.cleanup.softTitle")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:i("settings.cleanup.softDescription")}),e.jsx(E,{variant:"outline",onClick:p,disabled:t,className:"w-full sm:w-auto",children:i(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(W,{variant:"outline",className:"border-destructive/40 bg-destructive/10 text-destructive",children:i("settings.cleanup.hardLabel")}),e.jsx("p",{className:"text-sm font-medium",children:i("settings.cleanup.hardTitle")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:i("settings.cleanup.clearAllWarning")}),e.jsx(E,{variant:"destructive",onClick:o,disabled:s,className:"w-full sm:w-auto",children:i(s?"settings.cleanup.clearingAll":"settings.cleanup.clearAll")})]})})]}),e.jsx("div",{className:"rounded-xl border border-border bg-secondary/40 p-5",children:e.jsxs("div",{className:"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("p",{className:"text-sm font-medium",children:i("settings.cleanup.compactTitle")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:i("settings.cleanup.compactDescription")})]}),e.jsx(E,{variant:"outline",onClick:m,disabled:r,className:"w-full sm:w-auto",children:i(r?"common.actions.compacting":"common.actions.compact")})]})})]})})}function qt({dirtyCount:t,protocolChangesPending:s,onReset:r,onSave:l,saving:m}){const{t:p}=C();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(W,{variant:"secondary",children:p("settings.overview.unsavedCount",{count:t})}),e.jsx("p",{className:"text-sm text-muted-foreground",children:p(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(E,{variant:"outline",onClick:r,disabled:m,className:"w-full lg:w-auto",children:p("common.actions.reset")}),e.jsx(E,{onClick:l,disabled:m,className:"w-full lg:w-auto",children:p(m?"common.actions.saving":"common.actions.save")})]})]})}function le({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 ie({checked:t,className:s,hint:r,hintClassName:l,label:m,labelClassName:p,onCheckedChange:o}){return e.jsxs("div",{className:L("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:L("text-sm font-semibold text-foreground",p),children:m}),e.jsx("p",{className:L("text-xs text-muted-foreground",l),children:r})]}),e.jsx(Q,{checked:t,onCheckedChange:o,className:"self-start sm:self-auto"})]})}function re({label:t,onChange:s,placeholder:r,value:l}){return e.jsxs("div",{className:"space-y-2",children:[e.jsx(f,{children:t}),e.jsx(j,{value:l,onChange:m=>s(m.target.value),placeholder:r,className:"font-mono text-xs"})]})}const D={authStatusRequest(){return{url:"/api/auth/web",method:"GET"}},saveWebAuth:async t=>Nt(wt.post("/api/auth/web",t)),cleanupLogs:async()=>I({url:"/api/logs/cleanup",method:"POST"}),clearLogs:async()=>I({url:"/api/logs/clear",method:"POST"}),dbInfo:async()=>I({url:"/api/db/info",method:"GET"}),compactDb:async()=>I({url:"/api/db/compact",method:"POST"})};function Bt(){const{t}=C(),{pushToast:s}=Ct(),[r,l]=u.useState(ce[0].id),m=u.useRef(new Map),p=u.useCallback(n=>{const h=m.current.get(n);h&&h.scrollIntoView({behavior:"smooth",block:"start"})},[]),o=u.useCallback(n=>h=>{h?m.current.set(n,h):m.current.delete(n)},[]),a=ae(F.config.info(),Ve.configInfoRequest()),i=ae(F.auth.web(),D.authStatusRequest()),v=z({mutationFn:D.saveWebAuth,successToast:()=>({title:t("settings.auth.toast.success")}),errorToast:n=>({title:t("settings.auth.toast.failure",{message:n.message})}),invalidateKeys:[F.auth.web()]}),T=z({mutationFn:D.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"]]}),M=z({mutationFn:D.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"]]}),S=ae(F.db.info(),{url:"/api/db/info",method:"GET"}),O=z({mutationFn:D.compactDb,successToast:()=>({title:t("settings.toast.compactSuccess.title"),description:t("settings.toast.compactSuccess.desc")}),errorToast:n=>({title:t("settings.toast.compactFailure",{message:n.message})}),invalidateKeys:[F.db.info(),["dashboard"]]}),[c,de]=u.useState(null),[H,ze]=u.useState(""),[d,K]=u.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:""}),[We,G]=u.useState({}),[Qe,ue]=u.useState(!1),[Ge,pe]=u.useState(!1),[Je,me]=u.useState(!1),[_e,$e]=u.useState(!1),[Ue,Xe]=u.useState(!1),[b,he]=u.useState(null),[g,q]=u.useState({enabled:!1,username:"",password:"",confirmPassword:""}),[Ye,B]=u.useState({}),[Ze,ge]=u.useState(!1),et=u.useMemo(()=>{if(!(c!=null&&c.defaults))return null;const n=[];return c.defaults.completion&&n.push(t("settings.defaults.completion",{model:c.defaults.completion})),c.defaults.reasoning&&n.push(t("settings.defaults.reasoning",{model:c.defaults.reasoning})),c.defaults.background&&n.push(t("settings.defaults.background",{model:c.defaults.background})),n.length>0?n.join(" | "):t("settings.defaults.none")},[c,t]),tt=u.useMemo(()=>d.httpEnabled&&d.httpsEnabled?t("settings.overview.values.httpAndHttps"):d.httpsEnabled?t("settings.overview.values.httpsOnly"):t("settings.overview.values.httpOnly"),[d.httpEnabled,d.httpsEnabled,t]),st=u.useMemo(()=>g.enabled?b!=null&&b.hasPassword?g.username.trim()!==(b.username??""):!0:!1,[g.enabled,g.username,b]),k=u.useMemo(()=>c?ne(c):null,[c]),J=u.useMemo(()=>k?JSON.stringify(d)!==JSON.stringify(k):!1,[d,k]),_=u.useMemo(()=>b?oe(b):null,[b]),$=u.useMemo(()=>_?JSON.stringify(g)!==JSON.stringify(_):!1,[g,_]),at=u.useMemo(()=>k?["httpEnabled","httpPort","httpHost","httpsEnabled","httpsPort","httpsHost","httpsKeyPath","httpsCertPath","httpsCaPath","port","host"].some(h=>d[h]!==k[h]):!1,[d,k]);u.useEffect(()=>{a.data&&(de(a.data.config),ze(a.data.path),K(ne(a.data.config)))},[a.data]),u.useEffect(()=>{i.data&&(he(i.data),q(oe(i.data)),B({}))},[i.data]),u.useEffect(()=>{!a.isError||!a.error||s({title:t("settings.toast.loadFailure",{message:a.error.message}),variant:"error"})},[a.error,a.isError,s,t]),u.useEffect(()=>{!i.isError||!i.error||s({title:t("settings.toast.authLoadFailure",{message:i.error.message}),variant:"error"})},[i.error,i.isError,s,t]);const nt=u.useCallback(n=>h=>{K(y=>({...y,[n]:h}))},[]),xe=u.useCallback(()=>{const n={};if(!d.httpEnabled&&!d.httpsEnabled&&(n.protocol=t("settings.validation.protocolRequired")),d.httpEnabled){const w=Number(d.httpPort);(!Number.isFinite(w)||w<1||w>65535)&&(n.httpPort=t("settings.validation.httpPort"))}if(d.httpsEnabled){const w=Number(d.httpsPort);(!Number.isFinite(w)||w<1||w>65535)&&(n.httpsPort=t("settings.validation.httpsPort")),(!d.httpsKeyPath||!d.httpsCertPath)&&(n.protocol=t("settings.validation.httpsCertificate"))}const h=Number(d.port);(!Number.isFinite(h)||h<1||h>65535)&&(n.port=t("settings.validation.port"));const y=Number(d.logRetentionDays);(!Number.isFinite(y)||y<1||y>365)&&(n.logRetentionDays=t("settings.validation.retention"));const N=Number(d.logExportTimeoutSeconds);(!Number.isFinite(N)||N<5||N>600)&&(n.logExportTimeoutSeconds=t("settings.validation.logExportTimeout"));const R=Number(d.bodyLimitMb);return(!Number.isFinite(R)||R<1||R>2048)&&(n.bodyLimitMb=t("settings.validation.bodyLimit")),G(n),Object.keys(n).length===0},[d,t]),fe=u.useCallback(()=>{const n={},h=g.username.trim(),y=b?h!==(b.username??""):!0,N=g.enabled&&(!(b!=null&&b.hasPassword)||y);return g.enabled&&!h&&(n.username=t("settings.auth.validation.username")),g.password&&g.password.length<6&&(n.password=t("settings.auth.validation.minLength")),N&&!g.password&&(n.password=t("settings.auth.validation.passwordRequired")),(g.password||g.confirmPassword)&&g.password!==g.confirmPassword&&(n.confirmPassword=t("settings.auth.validation.confirmMismatch")),B(n),Object.keys(n).length===0},[g,b,t]),U=u.useCallback(async()=>{var n,h,y,N,R,w,be,ye,ve,je,Ne,we,Ce,Pe,Se,ke,Re,Ee,Le,Ae,Te,Me,Oe,Fe,De,He;if(!c){s({title:t("settings.toast.loadFailure",{message:t("settings.toast.missingConfig")}),variant:"error"});return}if(xe()){ue(!0);try{const V=Number(d.port),ut=Number(d.logRetentionDays),pt=Number(d.logExportTimeoutSeconds),mt=Number(d.bodyLimitMb),x={...c,http:{enabled:d.httpEnabled,port:Number(d.httpPort),host:d.httpHost.trim()||"127.0.0.1"},https:{enabled:d.httpsEnabled,port:Number(d.httpsPort),host:d.httpsHost.trim()||"127.0.0.1",keyPath:d.httpsKeyPath.trim(),certPath:d.httpsCertPath.trim(),caPath:d.httpsCaPath.trim()||void 0},port:V,host:d.host.trim()||void 0,logRetentionDays:ut,logExportTimeoutSeconds:Math.min(Math.max(Math.round(pt),5),600),storeRequestPayloads:d.storeRequestPayloads,storeResponsePayloads:d.storeResponsePayloads,logLevel:d.logLevel,bodyLimit:Math.max(1,Math.floor(mt*1024*1024)),enableRoutingFallback:d.enableRoutingFallback};delete x.requestLogging,delete x.responseLogging;const Ke={...x};delete Ke.webAuth,await Ve.saveConfig(Ke),de({...x,webAuth:c.webAuth});const qe=te=>(te==null?void 0:te.trim())||void 0,ht=c.port??((n=c.http)==null?void 0:n.port)??4100,gt=x.port??((h=x.http)==null?void 0:h.port)??4100,xt=((y=c.host)==null?void 0:y.trim())||((R=(N=c.http)==null?void 0:N.host)==null?void 0:R.trim())||"127.0.0.1",ft=((w=x.host)==null?void 0:w.trim())||((ye=(be=x.http)==null?void 0:be.host)==null?void 0:ye.trim())||"127.0.0.1",bt=ht!==gt||xt!==ft||((ve=c.http)==null?void 0:ve.enabled)!==((je=x.http)==null?void 0:je.enabled)||((Ne=c.http)==null?void 0:Ne.port)!==((we=x.http)==null?void 0:we.port)||(((Ce=c.http)==null?void 0:Ce.host)??c.host??"127.0.0.1")!==(((Pe=x.http)==null?void 0:Pe.host)??x.host??"127.0.0.1")||((Se=c.https)==null?void 0:Se.enabled)!==((ke=x.https)==null?void 0:ke.enabled)||((Re=c.https)==null?void 0:Re.port)!==((Ee=x.https)==null?void 0:Ee.port)||(((Le=c.https)==null?void 0:Le.host)??c.host??"127.0.0.1")!==(((Ae=x.https)==null?void 0:Ae.host)??x.host??"127.0.0.1")||((Te=c.https)==null?void 0:Te.keyPath)!==((Me=x.https)==null?void 0:Me.keyPath)||((Oe=c.https)==null?void 0:Oe.certPath)!==((Fe=x.https)==null?void 0:Fe.certPath)||qe((De=c.https)==null?void 0:De.caPath)!==qe((He=x.https)==null?void 0:He.caPath);s({title:t(bt?"settings.toast.protocolRestartRequired":"settings.toast.saveSuccess"),variant:"success"}),a.refetch()}catch(V){s({title:t("settings.toast.saveFailure",{message:V instanceof Error?V.message:"unknown"}),variant:"error"})}finally{ue(!1)}}},[c,a,d,s,t,xe]),X=u.useCallback(()=>{c&&(K(ne(c)),G({}))},[c]),Y=u.useCallback(async()=>{if(fe()){ge(!0);try{const n={enabled:g.enabled,username:g.username.trim()||void 0};g.password&&(n.password=g.password);const h=await v.mutateAsync(n);h.auth&&(he(h.auth),q({enabled:h.auth.enabled,username:h.auth.username??"",password:"",confirmPassword:""}),B({})),i.refetch()}catch{}finally{ge(!1)}}},[g,i,v,fe]),Z=u.useCallback(()=>{b&&(q(oe(b)),B({}))},[b]),ot=u.useCallback(async()=>{J&&await U(),$&&await Y()},[Y,U,$,J]),lt=u.useCallback(()=>{X(),Z()},[Z,X]),it=u.useCallback(async()=>{if(!H){s({title:t("settings.toast.copyFailure",{message:t("settings.file.unknown")}),variant:"error"});return}try{await Lt(H),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"})}},[H,s,t]),rt=u.useCallback(async()=>{pe(!0);try{await T.mutateAsync()}catch{}finally{pe(!1)}},[T]),ct=u.useCallback(async()=>{me(!0);try{await M.mutateAsync()}catch{}finally{me(!1)}},[M]),dt=S.data?At(S.data.totalBytes??S.data.sizeBytes):"-",ee=a.isPending||!c&&a.isFetching;return u.useEffect(()=>{if(ee)return;const n=Array.from(m.current.values());if(n.length===0)return;const h=new IntersectionObserver(y=>{for(const N of y)if(N.isIntersecting){l(N.target.id);break}},{rootMargin:"-80px 0px -60% 0px",threshold:0});for(const y of n)h.observe(y);return()=>h.disconnect()},[ee]),{activeSection:r,authErrors:Ye,authForm:g,authQuery:i,authSettings:b,clearingAll:Je,cleaning:Ge,compacting:O.isPending,config:c,configPath:H,configQuery:a,confirmCleanupOpen:_e,confirmClearAllOpen:Ue,dbSizeDisplay:dt,defaultsSummary:et,errors:We,form:d,handleAuthReset:Z,handleAuthSave:Y,handleCleanupLogs:rt,handleClearAllLogs:ct,handleCompact:O.mutate,handleCopyPath:it,handleInputChange:nt,handleReset:X,handleResetAll:lt,handleSave:U,handleSaveAll:ot,handleSectionClick:p,isAuthDirty:$,isConfigDirty:J,isLoading:ee,needsPassword:st,protocolSummaryLabel:tt,protocolChangesPending:at,saving:Qe,savingAuth:Ze,sectionRefs:m,setAuthForm:q,setConfirmCleanupOpen:$e,setConfirmClearAllOpen:Xe,setErrors:G,setForm:K,setSectionRef:o,t}}function is(){const{t}=C(),s=Bt(),r=Number(s.isConfigDirty)+Number(s.isAuthDirty);return e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx(jt,{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(Ie,{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(Mt,{activeSection:s.activeSection,onSelectSection:s.handleSectionClick}),e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx(Ot,{defaultsSummary:s.defaultsSummary,errors:s.errors,form:s.form,onInputChange:s.handleInputChange,onSetForm:s.setForm,sectionRef:s.setSectionRef("section-basics")}),e.jsx(Ft,{errors:s.errors,form:s.form,onSetForm:s.setForm,protocolChangesPending:s.protocolChangesPending,sectionRef:s.setSectionRef("section-protocol")}),e.jsx(Dt,{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(Ht,{configPath:s.configPath,onCopyPath:()=>void s.handleCopyPath(),sectionRef:s.setSectionRef("section-config-file")}),e.jsx(Kt,{cleaning:s.cleaning,clearingAll:s.clearingAll,compacting:s.compacting,dbSizeDisplay:s.dbSizeDisplay,onCompact:s.handleCompact,onOpenCleanup:()=>s.setConfirmCleanupOpen(!0),onOpenClearAll:()=>s.setConfirmClearAllOpen(!0),sectionRef:s.setSectionRef("section-cleanup")})]})]}),e.jsx(qt,{dirtyCount:r,protocolChangesPending:s.protocolChangesPending,onReset:s.handleResetAll,onSave:()=>void s.handleSaveAll(),saving:s.saving||s.savingAuth})]}):e.jsx(P,{children:e.jsx(A,{className:"pt-6",children:e.jsx("p",{className:"text-sm font-medium text-destructive",children:t("settings.toast.missingConfig")})})}),e.jsx(Be,{open:s.confirmCleanupOpen,onOpenChange:l=>{!l&&!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(Be,{open:s.confirmClearAllOpen,onOpenChange:l=>{!l&&!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{is as default};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{j as e,$ as he,ak as Q,r as d}from"./vendor-D2wC0h2o.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-D2wC0h2o.js";import{B as h,t as z,L as ge}from"./app-BnQl39hq.js";import{C as ve,b as ye,d as fe,e as je,a as Se}from"./card-DhuLMeO9.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-CsPV2Cqr.js";import{L as C,I as R}from"./label-Da-JMxO2.js";import{u as Te,E as Ee}from"./shared-DHBfRHZV.js";import{u as N}from"./i18n-Dp-o1LhZ.js";import{S as Ae,a as Ie,b as He,c as Oe,d as Fe}from"./select-BTwqvh0l.js";import{a as Ue}from"./apiKeys-B-WRyKci.js";import{g as G}from"./gateway-DxCj_uok.js";import{c as $e}from"./clipboard-BnAnBk_-.js";import{u as Le}from"./router-CUBM_FND.js";import"./global-CJOj9WGx.js";import"./query-DVc6ZTRQ.js";import"./radix-B9EIjzyN.js";import"./disclosure-CJdf1-ap.js";import"./switch-CeKtgMDT.js";import"./badge-RZTsODn-.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,onStreamUsageChange:n.handleStreamUsageChange,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 L;const c=Ke(),{t,pushToast:r,config:s,setConfig:n,configQuery:l,customEndpoints:p,ensureConfig:x}=c,g=Le(),[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]),U=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]),$=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=$.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 Ue.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 $e(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:${((L=s==null?void 0:s.http)==null?void 0:L.port)??(s==null?void 0:s.port)??4100}/anthropic`,me=b[u],xe={provider:S.length>0,routing:U>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:U,routeSource:E,setRouteSource:W,routeTarget:$,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-BnQl39hq.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};
|