@chenpu17/cc-gw 0.9.0-beta.0 → 0.9.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.
Files changed (26) hide show
  1. package/package.json +5 -5
  2. package/src/web/dist/assets/{About-DY21fypB.js → About-DhB_6utk.js} +1 -1
  3. package/src/web/dist/assets/{ApiKeys-FWkRLPTy.js → ApiKeys-Cx4kYUfE.js} +1 -1
  4. package/src/web/dist/assets/{ConfirmDialog-CyTpXZeT.js → ConfirmDialog-CgKijCNt.js} +1 -1
  5. package/src/web/dist/assets/Dashboard-CyjVgsnF.js +1 -0
  6. package/src/web/dist/assets/{Events-x_fSf1mz.js → Events-CWvgjYnj.js} +1 -1
  7. package/src/web/dist/assets/{Help-BMgllYJq.js → Help-CLGrjSta.js} +1 -1
  8. package/src/web/dist/assets/{Login-DrtDFqbk.js → Login-j6M7LsIk.js} +1 -1
  9. package/src/web/dist/assets/{Logs-18flgbiW.js → Logs-lC0QWlZz.js} +1 -1
  10. package/src/web/dist/assets/{ProvidersWorkbench-aHO5-ApY.js → ProvidersWorkbench-CXS-UBtR.js} +1 -1
  11. package/src/web/dist/assets/Settings-bJkZ6l1O.js +1 -0
  12. package/src/web/dist/assets/{Setup-B1j2zExa.js → Setup-BIEy_Ywx.js} +1 -1
  13. package/src/web/dist/assets/{apiKeys-k1jIJuDa.js → apiKeys-DngGSX7O.js} +1 -1
  14. package/src/web/dist/assets/app-vWIA9Pq_.js +61 -0
  15. package/src/web/dist/assets/{gateway-i49olSPp.js → gateway-B7Y2AqSU.js} +1 -1
  16. package/src/web/dist/assets/{landing-W4f2Nx8j.js → landing-Dj8Ojphq.js} +1 -1
  17. package/src/web/dist/assets/package-BBDLwVNt.js +1 -0
  18. package/src/web/dist/assets/{shared-Cuakym23.js → shared-D9r3kFnp.js} +1 -1
  19. package/src/web/dist/assets/{useAppMutation-CEN5Oa4S.js → useAppMutation-DJ2QsEsU.js} +1 -1
  20. package/src/web/dist/assets/{useProviderForm-DZEYuRhD.js → useProviderForm-eK2SFp4F.js} +1 -1
  21. package/src/web/dist/index.html +1 -1
  22. package/src/web/dist/landing.html +2 -2
  23. package/src/web/dist/assets/Dashboard-FKM-9UNt.js +0 -1
  24. package/src/web/dist/assets/Settings-iEjCAGgm.js +0 -1
  25. package/src/web/dist/assets/app-Citq5KW4.js +0 -61
  26. package/src/web/dist/assets/package-B2CgmdJ7.js +0 -1
@@ -1 +1 @@
1
- import{r as w,j as s,$ as le}from"./vendor-CITafuNQ.js";import{u as ne}from"./query-DZF7K6hv.js";import{a as oe,c as ie,q as G,e as ce,i as V,d as O,B as A}from"./app-Citq5KW4.js";import{g as ue}from"./gateway-i49olSPp.js";import{u as P}from"./i18n-PeX9kBVO.js";import{c as T}from"./global-BCehxTGJ.js";import{D as X}from"./disclosure-l5qsWhr7.js";import{L as M,I as C}from"./label-DSVzZIex.js";import{S as me,a as pe,b as he,c as xe,d as L}from"./select-sOwKYsgI.js";import{S as Q}from"./switch-7PH_rDz6.js";import{B as fe}from"./badge-DpUlf_NW.js";const ze=["claude-sonnet-4-5-20250929","claude-sonnet-4-5-20250929-thinking","claude-sonnet-4-20250514","claude-opus-4-1-20250805","claude-opus-4-1-20250805-thinking","claude-haiku-4-5-20251001","claude-haiku-4-5-20251001-thinking","claude-3-5-haiku-20241022"],qe=["gpt-4o-mini","gpt-4o","o4-mini","o4-large","gpt-5-codex"];function be(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():Math.random().toString(36).slice(2,10)}function R(e,a){var t;return(t=e==null?void 0:e.customEndpoints)!=null&&t.length?e.customEndpoints:a}function B(e){return e?Object.entries(e).map(([a,t])=>({id:be(),source:a,target:t})):[]}function Ge(e,a){var r,n,p;if(!e)return{};const t={},o=e.endpointRouting??{};t.anthropic=B(((r=o.anthropic)==null?void 0:r.modelRoutes)??e.modelRoutes??{}),t.openai=B(((n=o.openai)==null?void 0:n.modelRoutes)??{});for(const u of R(e,a))(p=u.routing)!=null&&p.modelRoutes?t[u.id]=B(u.routing.modelRoutes):t[u.id]=[];return t}function ge(e,a,t){var n,p,u;const o=R(e,a).find(y=>y.id===t);if(o)return((n=o.routing)==null?void 0:n.modelRoutes)??{};const r=e.endpointRouting??{};return t==="anthropic"?((p=r.anthropic)==null?void 0:p.modelRoutes)??e.modelRoutes??{}:t==="openai"?((u=r.openai)==null?void 0:u.modelRoutes)??{}:{}}function F(e,a,t){var r,n,p;if(t==="anthropic"||t==="openai")return((n=(r=e.endpointRouting)==null?void 0:r[t])==null?void 0:n.defaults)??e.defaults;const o=R(e,a).find(u=>u.id===t);return((p=o==null?void 0:o.routing)==null?void 0:p.defaults)??e.defaults}function Qe(e,a){if(!e)return{};const t={anthropic:F(e,a,"anthropic"),openai:F(e,a,"openai")};for(const o of R(e,a))t[o.id]=F(e,a,o.id);return t}function ve(e){const a={};for(const t of e){const o=t.source.trim(),r=t.target.trim();o&&r&&(a[o]=r)}return a}function Je(e,a){return JSON.stringify(ve(e))!==JSON.stringify(a)}function Xe(e,a,t){var r,n,p;if(!a)return;if(e==="anthropic"||e==="openai")return(n=(r=a.endpointRouting)==null?void 0:r[e])==null?void 0:n.compatibility;const o=R(a,t).find(u=>u.id===e);return(p=o==null?void 0:o.routing)==null?void 0:p.compatibility}function Ye(e,a){var o,r;const t={anthropic:((o=e.routingPresets)==null?void 0:o.anthropic)??[],openai:((r=e.routingPresets)==null?void 0:r.openai)??[]};for(const n of R(e,a))t[n.id]=n.routingPresets??[];return t}function ye(e,a){const t=[{key:"providers",label:e("modelManagement.tabs.providers"),description:e("modelManagement.tabs.providersDesc"),isSystem:!0,canDelete:!1},{key:"anthropic",label:e("modelManagement.tabs.anthropic"),description:e("modelManagement.tabs.anthropicDesc"),isSystem:!0,canDelete:!1,protocols:["anthropic"]},{key:"openai",label:e("modelManagement.tabs.openai"),description:e("modelManagement.tabs.openaiDesc"),isSystem:!0,canDelete:!1,protocols:["openai-auto","openai-chat","openai-responses"]}],o=a.map(r=>{let n=e("modelManagement.tabs.customEndpoint"),p=[];if(r.paths&&r.paths.length>0)n=`${e("modelManagement.tabs.customEndpoint")}: ${r.paths.map(u=>`${u.path} (${u.protocol})`).join(", ")}`,p=[...new Set(r.paths.map(u=>u.protocol))];else if(r.path){const u=r.protocol||"anthropic";n=`${e("modelManagement.tabs.customEndpoint")}: ${r.path} (${u})`,p=[u]}return{key:r.id,label:r.label||r.id,description:n,isSystem:!1,canDelete:r.deletable!==!1,protocols:p}});return[...t,...o]}function We(e){return e.label&&e.label.trim().length>0?`${e.label} (${e.id})`:e.id}function je(e,a){if(!e)return!1;const[t]=e.split(":");return t===a||e===a}function Ne(e,a,t){if(!e)return[];const o=["anthropic","openai",...R(e,a).map(n=>n.id)],r=[];for(const n of o){const p=ge(e,a,n);for(const[u,y]of Object.entries(p))je(y,t)&&r.push({endpoint:n,source:u,target:y})}return r}function Ze(e,a,t){return Ne(e,a,t).length}function es(){var N;const{t:e}=P(),{pushToast:a}=oe(),t=ie(G.config.full(),ue.configRequest()),o=ne({queryKey:G.customEndpoints.all(),queryFn:ce.list,refetchInterval:1e4}),r=w.useMemo(()=>{var g;return((g=o.data)==null?void 0:g.endpoints)??[]},[(N=o.data)==null?void 0:N.endpoints]),n=w.useMemo(()=>ye(e,r),[r,e]),[p,u]=w.useState(null);return w.useEffect(()=>{t.data&&u(t.data)},[t.data]),w.useEffect(()=>{!t.isError||!t.error||a({title:e("providers.toast.loadFailure",{message:t.error.message}),variant:"error"})},[t.error,t.isError,a,e]),{t:e,pushToast:a,config:p,setConfig:u,configQuery:t,customEndpoints:r,customEndpointsQuery:o,tabs:n,ensureConfig:()=>p?!0:(a({title:e("settings.toast.missingConfig"),variant:"error"}),t.refetch(),!1)}}const ss={savePreset(e,a){return V(O.post(`/api/routing-presets/${e}`,{name:a}))},applyPreset(e,a){return V(O.post(`/api/routing-presets/${e}/apply`,{name:a}))},deletePreset(e,a){return V(O.delete(`/api/routing-presets/${e}/${encodeURIComponent(a)}`))},testProvider(e,a){return V(O.post(`/api/providers/${e}/test`,a??{}))}},we={complete:"border-primary bg-primary text-primary-foreground",current:"border-primary bg-card text-primary ring-2 ring-primary/20",error:"border-destructive bg-card text-destructive ring-2 ring-destructive/20",upcoming:"border-border bg-card text-muted-foreground"},Se={complete:"text-foreground",current:"text-foreground font-medium",error:"text-destructive font-medium",upcoming:"text-muted-foreground"};function rs({steps:e,current:a,onSelect:t,className:o}){return s.jsx("nav",{"aria-label":"steps",className:T("flex items-start",o),children:e.map((r,n)=>{const p=t&&(r.status==="complete"||r.status==="current"),u=n===e.length-1,y=r.status==="complete"?"bg-primary/40":"bg-border",N=s.jsx("span",{className:T("motion-surface flex h-7 w-7 shrink-0 items-center justify-center rounded-lg border text-xs font-semibold",we[r.status]),"aria-current":r.id===a?"step":void 0,children:r.status==="complete"?s.jsx(le,{className:"h-3.5 w-3.5","aria-hidden":!0}):n+1}),g=`stepnav-${r.id}-label`;return s.jsxs("div",{className:"flex flex-1 items-start",children:[s.jsxs("div",{className:"flex min-w-0 flex-col items-center gap-1.5",children:[p?s.jsx("button",{type:"button",onClick:()=>t==null?void 0:t(r.id),"aria-labelledby":g,className:"rounded-lg outline-none focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-offset-2 focus-visible:ring-offset-background motion-surface",children:N}):N,s.jsx("span",{id:g,className:T("text-center text-[11px] leading-tight",Se[r.status]),children:r.label})]}),u?null:s.jsx("span",{"aria-hidden":!0,className:T("mx-1.5 mt-3.5 h-px flex-1",y)})]},r.id)})})}function Me({result:e,className:a}){const{t}=P();return s.jsxs("div",{className:T("flex flex-wrap items-center gap-2 rounded-lg px-3 py-2 text-xs",e.ok?"bg-success-bg text-success":"bg-destructive/10 text-destructive",a),children:[s.jsx(fe,{variant:e.ok?"success":"destructive",className:"shrink-0",children:e.ok?t("workbench.testResult.success"):t("workbench.testResult.failure")}),e.status?s.jsx("span",{className:"shrink-0",children:t("workbench.testResult.status",{status:e.status})}):null,e.durationMs?s.jsx("span",{className:"shrink-0",children:t("workbench.testResult.duration",{duration:`${e.durationMs} ms`})}):null,e.message?s.jsx("span",{className:"min-w-0 truncate",title:e.message,children:e.message}):null]})}function D(){return typeof globalThis.crypto<"u"&&typeof globalThis.crypto.randomUUID=="function"?globalThis.crypto.randomUUID():Math.random().toString(36).slice(2,10)}function ke(){return{_key:D(),id:"",label:""}}function Ce(){return{_key:D(),name:"",value:""}}const K={openai:{baseUrl:"https://api.openai.com/v1"},deepseek:{baseUrl:"https://api.deepseek.com/v1"},huawei:{baseUrl:"https://api.modelarts-maas.com/v1"},kimi:{baseUrl:"https://api.moonshot.cn/v1"},anthropic:{baseUrl:"https://api.anthropic.com/v1"},custom:{}},Ue=[{value:"openai",label:"OpenAI"},{value:"deepseek",label:"DeepSeek"},{value:"huawei",label:"Huawei Cloud"},{value:"kimi",label:"Kimi"},{value:"anthropic",label:"Anthropic"},{value:"custom",label:"Custom"}],as=[{id:"basics",labelKey:"providers.drawer.steps.basics"},{id:"models",labelKey:"providers.drawer.steps.modelsVerify"}];function _(e){return e==="anthropic"?"authToken":"apiKey"}function Re(e,a,t){return t(a==="authToken"?"providers.drawer.fields.authModeAuthToken":a==="xAuthToken"?"providers.drawer.fields.authModeXAuthToken":e==="anthropic"?"providers.drawer.fields.authModeApiKey":"providers.drawer.fields.authModeProviderDefault")}function J(e){return e?{id:e.id,label:e.label??e.id,baseUrl:e.baseUrl,apiKey:e.apiKey??"",type:e.type??"custom",defaultModel:e.defaultModel??"",models:(e.models??[]).map(a=>({...a,_key:D()})),authMode:e.authMode??_(e.type??"custom"),nonStreamViaStream:e.nonStreamViaStream??!1,useAbsoluteUrl:e.useAbsoluteUrl??!1,extraHeaders:Object.entries(e.extraHeaders??{}).map(([a,t])=>({name:a,value:t,_key:D()}))}:{id:"",label:"",baseUrl:"",apiKey:"",type:"custom",defaultModel:"",models:[],authMode:_("custom"),nonStreamViaStream:!1,useAbsoluteUrl:!1,extraHeaders:[]}}function Te(e){return{_key:D(),id:e.id,label:e.label,nonStreamViaStream:e.nonStreamViaStream}}function ts({form:e,errors:a,isCreate:t,advancedOpen:o,onAdvancedOpenChange:r,idInputRef:n,onProviderIdChange:p,onFieldChange:u,onTypeChange:y,onAuthModeChange:N,onNonStreamViaStreamChange:g,onUseAbsoluteUrlChange:m,onAddHeader:E,onRemoveHeader:j,onHeaderChange:S}){const{t:i}=P();return s.jsxs("div",{className:"space-y-8",children:[s.jsxs("section",{className:"space-y-5","aria-labelledby":"provider-type-fields",children:[s.jsxs("div",{className:"space-y-1",children:[s.jsx("h3",{id:"provider-type-fields",className:"text-sm font-semibold",children:i("providers.drawer.sections.type")}),s.jsx("p",{className:"text-xs text-muted-foreground",children:i("providers.drawer.hints.type")})]}),s.jsx("div",{className:"grid gap-2 md:grid-cols-3",children:Ue.map(b=>{var k;const U=b.value===e.type;return s.jsxs("button",{type:"button",onClick:()=>y(b.value),className:T("rounded-2xl border px-4 py-3 text-left transition focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",U?"border-primary bg-primary/10 text-primary":"border-border bg-card text-foreground hover:border-primary/20 hover:bg-accent/50"),children:[s.jsx("div",{className:"text-sm font-semibold",children:b.label}),s.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:((k=K[b.value??"custom"])==null?void 0:k.baseUrl)??i("providers.drawer.hints.customProvider")})]},b.value??"custom")})})]}),s.jsxs("section",{className:"space-y-4","aria-labelledby":"provider-basic-info",children:[s.jsxs("div",{className:"space-y-1",children:[s.jsx("h3",{id:"provider-basic-info",className:"text-sm font-semibold",children:i("providers.drawer.sections.basic")}),s.jsx("p",{className:"text-xs text-muted-foreground",children:i("providers.drawer.hints.basic")})]}),s.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[s.jsxs(M,{className:"flex flex-col gap-2 text-sm",children:[s.jsx("span",{className:"text-xs text-muted-foreground",children:i("providers.drawer.fields.id")}),s.jsx(C,{value:e.id,ref:n,onChange:b=>p(b.target.value),disabled:!t,placeholder:i("providers.drawer.fields.idPlaceholder"),"aria-invalid":!!a.id}),a.id?s.jsx("span",{className:"text-xs text-destructive",children:a.id}):null]}),s.jsxs(M,{className:"flex flex-col gap-2 text-sm",children:[s.jsx("span",{className:"text-xs text-muted-foreground",children:i("providers.drawer.fields.label")}),s.jsx(C,{value:e.label,onChange:b=>u("label")(b.target.value),placeholder:i("providers.drawer.fields.labelPlaceholder")})]})]}),s.jsxs(M,{className:"flex flex-col gap-2 text-sm",children:[s.jsx("span",{className:"text-xs text-muted-foreground",children:i("providers.drawer.fields.baseUrl")}),s.jsx(C,{value:e.baseUrl,onChange:b=>u("baseUrl")(b.target.value),placeholder:i("providers.drawer.fields.baseUrlPlaceholder"),"aria-invalid":!!a.baseUrl}),a.baseUrl?s.jsx("span",{className:"text-xs text-destructive",children:a.baseUrl}):null]})]}),s.jsxs("section",{className:"space-y-4","aria-labelledby":"provider-auth-fields",children:[s.jsxs("div",{className:"space-y-1",children:[s.jsx("h3",{id:"provider-auth-fields",className:"text-sm font-semibold",children:i("providers.drawer.sections.auth")}),s.jsx("p",{className:"text-xs text-muted-foreground",children:i("providers.drawer.hints.auth")})]}),s.jsxs(M,{className:"flex flex-col gap-2 text-sm",children:[s.jsx("span",{className:"text-xs text-muted-foreground",children:i("providers.drawer.fields.apiKey")}),s.jsx(C,{value:e.apiKey,onChange:b=>u("apiKey")(b.target.value),placeholder:i("providers.drawer.fields.apiKeyPlaceholder")})]}),s.jsxs("fieldset",{className:"grid gap-2 rounded-xl border border-transparent bg-card p-4 text-xs shadow-[var(--surface-shadow)]",children:[s.jsx("legend",{className:"px-1 text-muted-foreground",children:i("providers.drawer.fields.authMode")}),s.jsx("p",{className:"text-[11px] text-muted-foreground",children:i("providers.drawer.fields.authModeHint")}),s.jsxs("label",{className:"flex cursor-pointer items-start gap-3 rounded-xl border border-transparent px-3 py-2 transition hover:bg-accent focus-within:bg-accent",children:[s.jsx("input",{type:"radio",name:"provider-auth-mode",value:"apiKey",checked:e.authMode==="apiKey",onChange:()=>N("apiKey"),className:"mt-0.5 h-4 w-4 accent-primary"}),s.jsx("span",{children:Re(e.type,"apiKey",i)})]}),s.jsxs("label",{className:"flex cursor-pointer items-start gap-3 rounded-xl border border-transparent px-3 py-2 transition hover:bg-accent focus-within:bg-accent",children:[s.jsx("input",{type:"radio",name:"provider-auth-mode",value:"authToken",checked:e.authMode==="authToken",onChange:()=>N("authToken"),className:"mt-0.5 h-4 w-4 accent-primary"}),s.jsx("span",{children:i("providers.drawer.fields.authModeAuthToken")})]}),s.jsxs("label",{className:"flex cursor-pointer items-start gap-3 rounded-xl border border-transparent px-3 py-2 transition hover:bg-accent focus-within:bg-accent",children:[s.jsx("input",{type:"radio",name:"provider-auth-mode",value:"xAuthToken",checked:e.authMode==="xAuthToken",onChange:()=>N("xAuthToken"),className:"mt-0.5 h-4 w-4 accent-primary"}),s.jsx("span",{children:i("providers.drawer.fields.authModeXAuthToken")})]})]}),s.jsxs(X,{open:o,onOpenChange:r,summary:i("providers.drawer.fields.advancedOptions"),className:"rounded-xl border border-transparent bg-card shadow-[var(--surface-shadow)]",summaryClassName:"px-4 py-3 text-sm font-medium",contentClassName:"border-t border-border px-4 py-4",children:[s.jsxs("div",{className:"flex items-start justify-between gap-4",children:[s.jsxs("div",{className:"space-y-1",children:[s.jsx("p",{className:"text-sm font-medium",children:i("providers.drawer.fields.nonStreamViaStream")}),s.jsx("p",{className:"text-xs leading-relaxed text-muted-foreground",children:i("providers.drawer.fields.nonStreamViaStreamHint")})]}),s.jsx(Q,{checked:e.nonStreamViaStream,onCheckedChange:g,"aria-label":i("providers.drawer.fields.nonStreamViaStream")})]}),s.jsx("div",{className:"mt-4 border-t border-border pt-4",children:s.jsxs("div",{className:"flex items-start justify-between gap-4",children:[s.jsxs("div",{className:"space-y-1",children:[s.jsx("p",{className:"text-sm font-medium",children:i("providers.drawer.fields.useAbsoluteUrl")}),s.jsx("p",{className:"text-xs leading-relaxed text-muted-foreground",children:i("providers.drawer.fields.useAbsoluteUrlHint")})]}),s.jsx(Q,{checked:e.useAbsoluteUrl,onCheckedChange:m,"aria-label":i("providers.drawer.fields.useAbsoluteUrl")})]})}),s.jsxs("div",{className:"mt-4 border-t border-border pt-4",children:[s.jsxs("div",{className:"flex items-start justify-between gap-4",children:[s.jsxs("div",{className:"space-y-1",children:[s.jsx("p",{className:"text-sm font-medium",children:i("providers.drawer.fields.extraHeaders")}),s.jsx("p",{className:"text-xs leading-relaxed text-muted-foreground",children:i("providers.drawer.fields.extraHeadersHint")})]}),s.jsx(A,{type:"button",variant:"outline",size:"sm",onClick:E,className:"bg-card text-xs",children:i("providers.drawer.fields.addHeader")})]}),a.extraHeaders?s.jsx("p",{className:"mt-2 text-xs text-destructive",children:a.extraHeaders}):null,e.extraHeaders.length>0?s.jsx("div",{className:"mt-3 space-y-3",children:e.extraHeaders.map((b,U)=>s.jsxs("div",{className:"rounded-xl border border-transparent bg-secondary/40 p-3",children:[s.jsxs("div",{className:"grid gap-3 md:grid-cols-2",children:[s.jsxs(M,{className:"flex flex-col gap-1.5 text-sm",children:[s.jsx("span",{className:"text-xs text-muted-foreground",children:i("providers.drawer.fields.headerName")}),s.jsx(C,{value:b.name,onChange:k=>S(U,{name:k.target.value}),placeholder:i("providers.drawer.fields.headerNamePlaceholder")})]}),s.jsxs(M,{className:"flex flex-col gap-1.5 text-sm",children:[s.jsx("span",{className:"text-xs text-muted-foreground",children:i("providers.drawer.fields.headerValue")}),s.jsx(C,{value:b.value,onChange:k=>S(U,{value:k.target.value}),placeholder:i("providers.drawer.fields.headerValuePlaceholder")})]})]}),s.jsx("div",{className:"mt-2 flex justify-end",children:s.jsx(A,{type:"button",variant:"ghost",size:"sm",className:"h-auto px-2 text-destructive",onClick:()=>j(U),children:i("providers.drawer.fields.removeHeader")})})]},b._key))}):null]})]})]})]})}function ds({form:e,errors:a,advancedOpen:t,onAdvancedOpenChange:o,onModelIdChange:r,onModelChange:n,onAddModel:p,onRemoveModel:u,onModelNonStreamViaStreamChange:y,onSetDefaultModel:N,testVerification:g}){const{t:m}=P(),E=e.models.filter(j=>j.id.trim().length>0);return s.jsxs("div",{className:"space-y-8",children:[s.jsxs("section",{className:"space-y-4","aria-labelledby":"provider-model-fields",children:[s.jsxs("div",{className:"flex items-start justify-between gap-4",children:[s.jsxs("div",{className:"space-y-1",children:[s.jsx("h3",{id:"provider-model-fields",className:"text-sm font-semibold",children:m("providers.drawer.fields.models")}),s.jsx("p",{className:"text-xs text-muted-foreground",children:m("providers.drawer.modelsDescription")})]}),s.jsx(A,{type:"button",variant:"outline",size:"sm",onClick:p,className:"bg-card text-xs",children:m("providers.drawer.fields.addModel")})]}),a.models?s.jsx("p",{className:"text-xs text-destructive",children:a.models}):null,s.jsxs("div",{className:"space-y-4",children:[e.models.map((j,S)=>s.jsxs("div",{className:"rounded-xl border border-transparent bg-card p-4 shadow-[var(--surface-shadow)]",children:[s.jsx("div",{className:"grid gap-4 md:grid-cols-2",children:s.jsxs(M,{className:"flex flex-col gap-2 text-sm",children:[s.jsx("span",{className:"text-xs text-muted-foreground",children:m("providers.drawer.fields.modelId")}),s.jsx(C,{value:j.id,onChange:i=>r(S,i.target.value),placeholder:m("providers.drawer.fields.modelIdPlaceholder")})]})}),s.jsxs(X,{open:t,onOpenChange:o,summary:m("providers.drawer.fields.advancedOptions"),className:"mt-4 rounded-xl bg-secondary/50",summaryClassName:"px-3 py-2 text-xs font-medium",contentClassName:"space-y-4 px-3 py-3",children:[s.jsxs(M,{className:"flex flex-col gap-2 text-sm",children:[s.jsx("span",{className:"text-xs text-muted-foreground",children:m("providers.drawer.fields.modelLabel")}),s.jsx(C,{value:j.label??"",onChange:i=>n(S,{label:i.target.value}),placeholder:m("providers.drawer.fields.modelLabelPlaceholder")})]}),s.jsxs(M,{className:"flex flex-col gap-2 text-sm",children:[s.jsx("span",{className:"text-xs text-muted-foreground",children:m("providers.drawer.fields.modelNonStreamViaStream")}),s.jsxs(me,{value:j.nonStreamViaStream===void 0?"inherit":j.nonStreamViaStream?"enabled":"disabled",onValueChange:i=>y(S,i),children:[s.jsx(pe,{children:s.jsx(he,{})}),s.jsxs(xe,{children:[s.jsx(L,{value:"inherit",children:m("providers.drawer.fields.modelNonStreamViaStreamInherit")}),s.jsx(L,{value:"enabled",children:m("providers.drawer.fields.modelNonStreamViaStreamEnabled")}),s.jsx(L,{value:"disabled",children:m("providers.drawer.fields.modelNonStreamViaStreamDisabled")})]})]})]})]}),s.jsxs("div",{className:"mt-3 flex flex-wrap items-center justify-between gap-3 text-xs",children:[s.jsxs("label",{className:"flex items-center gap-2 text-muted-foreground",children:[s.jsx("input",{type:"radio",name:"defaultModel",value:j.id,"aria-label":m("providers.drawer.fields.setDefault"),checked:e.defaultModel===j.id,onChange:()=>N(j.id),disabled:j.id.trim().length===0,className:"h-4 w-4 accent-primary"}),m("providers.drawer.fields.setDefault")]}),s.jsx(A,{type:"button",variant:"ghost",size:"sm",className:"h-auto px-2 text-destructive",onClick:()=>u(S),disabled:e.models.length===0,children:m("providers.drawer.fields.removeModel")})]})]},j._key)),e.models.length===0?s.jsx("div",{className:"rounded-xl border border-warning/30 bg-warning-bg p-5",children:s.jsxs("div",{className:"space-y-2",children:[s.jsx("p",{className:"text-sm font-semibold text-warning",children:m("providers.drawer.noModelsTitle")}),s.jsx("p",{className:"text-xs leading-relaxed text-warning",children:m("providers.drawer.noModelsHint",{providerId:e.id||"provider-id"})}),s.jsxs("div",{className:"rounded-lg bg-secondary/50 p-2.5",children:[s.jsx("p",{className:"mb-1.5 text-xs font-medium text-foreground",children:m("providers.drawer.routeExample")}),s.jsxs("code",{className:"block rounded-lg border border-transparent bg-card px-2.5 py-1.5 font-mono text-xs text-foreground shadow-[var(--surface-shadow)]",children:['"claude-*": "',(e.id||"provider-id").trim()||"provider-id",':*"']})]})]})}):null]}),E.length>1?s.jsx("div",{className:"text-xs text-muted-foreground",children:m("providers.drawer.defaultHint",{model:e.defaultModel||m("providers.card.noDefault")})}):null]}),g?s.jsxs("section",{className:"space-y-3","aria-labelledby":"provider-verify-fields",children:[s.jsxs("div",{className:"space-y-1",children:[s.jsx("h3",{id:"provider-verify-fields",className:"text-sm font-semibold",children:m("workbench.drawer.verifyTitle")}),s.jsx("p",{className:"text-xs text-muted-foreground",children:m("workbench.drawer.verifyHint")})]}),g.available?s.jsxs("div",{className:"space-y-3 rounded-xl border border-transparent bg-card p-4 shadow-[var(--surface-shadow)]",children:[s.jsx(A,{type:"button",variant:"outline",size:"sm",onClick:g.onTest,disabled:g.testing,children:g.testing?m("common.actions.testingConnection"):m("workbench.drawer.verifyRun")}),g.result?s.jsx(Me,{result:g.result}):null]}):s.jsx("p",{className:"rounded-xl bg-secondary/50 px-4 py-3 text-xs text-muted-foreground",children:m("workbench.drawer.verifySaveFirst")})]}):null]})}const Ee=/^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/;function ls({mode:e,provider:a,existingProviderIds:t}){const{t:o}=P(),[r,n]=w.useState(()=>J(a)),[p,u]=w.useState({}),[y,N]=w.useState(e==="edit"),g=w.useRef(null),m=w.useCallback(()=>{n(J(a)),u({}),N(e==="edit")},[a,e]),E=d=>l=>{n(h=>({...h,[d]:l}))},j=d=>{n(l=>{const c=!y||l.label.trim().length===0||l.label===l.id?d:l.label;return{...l,id:d,label:c}})},S=d=>{n(l=>{var q;const c=K[d??"custom"]??K.custom,x=_(l.type),f=_(d),v=Object.values(K).map(H=>H.baseUrl).filter(H=>!!H),$=!l.baseUrl||v.includes(l.baseUrl),de=e==="create"&&(l.models.length===0||l.models.every(H=>H.id.trim().length===0)),I={...l,type:d,authMode:l.authMode===x?f:l.authMode};return c!=null&&c.baseUrl&&$&&(I.baseUrl=c.baseUrl),c!=null&&c.models&&de&&(I.models=c.models.map(Te),I.defaultModel=c.defaultModel??((q=c.models[0])==null?void 0:q.id)??""),I})},i=(d,l)=>{n(h=>{const c=[...h.models];return c[d]={...c[d],...l},{...h,models:c}})},b=(d,l)=>{n(h=>{const c=[...h.models],x=c[d];if(!x)return h;const f=!y||!x.label||x.label===x.id,v={...x,id:l,label:f?l:x.label};c[d]=v;const $=h.defaultModel===x.id?l:h.defaultModel;return{...h,models:c,defaultModel:$}})},U=d=>{n(l=>{if(d<0||d>=l.models.length)return l;const h=l.models.filter((x,f)=>f!==d);let c=l.defaultModel;return h.some(x=>x.id===c)||(c=""),{...l,models:h,defaultModel:c}})},k=()=>{n(d=>({...d,models:[...d.models,ke()]}))},Y=(d,l)=>{n(h=>{const c=[...h.extraHeaders];return c[d]={...c[d],...l},{...h,extraHeaders:c}})},W=()=>{n(d=>({...d,extraHeaders:[...d.extraHeaders,Ce()]}))},Z=d=>{n(l=>{if(d<0||d>=l.extraHeaders.length)return l;const h=l.extraHeaders.filter((c,x)=>x!==d);return{...l,extraHeaders:h}})},ee=d=>{n(l=>({...l,authMode:d}))},se=d=>{n(l=>({...l,nonStreamViaStream:d}))},re=d=>{n(l=>({...l,useAbsoluteUrl:d}))},ae=(d,l)=>{i(d,{nonStreamViaStream:l==="inherit"?void 0:l==="enabled"})},te=d=>{n(l=>({...l,defaultModel:d}))},z=()=>{const d={},l=r.id.trim(),h=r.baseUrl.trim();if(e==="create"&&(l.length===0?d.id=o("providers.drawer.errors.idRequired"):t.includes(l)&&(d.id=o("providers.drawer.errors.idDuplicate"))),e==="edit"&&l.length===0&&(d.id=o("providers.drawer.errors.idRequired")),h.length===0)d.baseUrl=o("providers.drawer.errors.baseUrlInvalid");else try{new URL(h)}catch{d.baseUrl=o("providers.drawer.errors.baseUrlInvalid")}if(r.models.length>0){const c=new Set;r.models.some(f=>{const v=f.id.trim();return v.length===0||c.has(v)?!0:(c.add(v),!1)})&&(d.models=o("providers.drawer.errors.modelInvalid"))}if(r.defaultModel&&!r.models.some(c=>c.id===r.defaultModel)&&(d.models=o("providers.drawer.errors.defaultInvalid")),r.extraHeaders.length>0){const c=new Set;for(const x of r.extraHeaders){const f=x.name.trim();if(f.length===0)continue;if(!Ee.test(f)){d.extraHeaders=o("providers.drawer.errors.headerNameInvalid");break}const v=f.toLowerCase();if(c.has(v)){d.extraHeaders=o("providers.drawer.errors.headerNameDuplicate");break}c.add(v)}}return u(d),d};return{form:r,errors:p,advancedOpen:y,setAdvancedOpen:N,providerIdRef:g,isCreate:e==="create",resetForm:m,validate:()=>Object.keys(z()).length===0,validateErrors:z,serialize:()=>{const d=r.models.map(f=>{var v;return{id:f.id.trim(),label:(v=f.label)!=null&&v.trim()?f.label.trim():void 0,nonStreamViaStream:f.nonStreamViaStream}}).filter(f=>f.id.length>0),l={};for(const f of r.extraHeaders){const v=f.name.trim();v.length>0&&(l[v]=f.value)}const h=Object.keys(l).length>0,c=r.authMode==="apiKey"&&r.type!=="anthropic"?void 0:r.authMode,x={id:r.id.trim(),label:r.label.trim()||r.id.trim(),baseUrl:r.baseUrl.trim(),apiKey:r.apiKey.trim()||void 0,type:r.type??"custom",defaultModel:r.defaultModel||void 0,models:d.length>0?d:void 0,extraHeaders:h?l:void 0,authMode:c};return r.nonStreamViaStream&&(x.nonStreamViaStream=!0),r.useAbsoluteUrl&&(x.useAbsoluteUrl=!0),x},handleFieldChange:E,handleProviderIdChange:j,handleTypeChange:S,handleModelChange:i,handleModelIdChange:b,handleRemoveModel:U,handleAddModel:k,handleHeaderChange:Y,handleAddHeader:W,handleRemoveHeader:Z,handleAuthModeChange:ee,handleProviderNonStreamViaStreamChange:se,handleUseAbsoluteUrlChange:re,handleModelNonStreamViaStreamChange:ae,handleSetDefaultModel:te}}export{ts as B,ze as C,ds as M,qe as O,Ue as P,rs as S,Me as T,Je as a,Qe as b,F as c,Ge as d,Ye as e,be as f,ge as g,We as h,Re as i,as as j,Ne as k,Xe as l,ss as m,es as n,Ze as o,je as r,ls as u};
1
+ import{r as w,j as s,$ as le}from"./vendor-CITafuNQ.js";import{u as ne}from"./query-DZF7K6hv.js";import{a as oe,c as ie,q as G,e as ce,i as V,d as O,B as A}from"./app-vWIA9Pq_.js";import{g as ue}from"./gateway-B7Y2AqSU.js";import{u as P}from"./i18n-PeX9kBVO.js";import{c as T}from"./global-BCehxTGJ.js";import{D as X}from"./disclosure-l5qsWhr7.js";import{L as M,I as C}from"./label-DSVzZIex.js";import{S as me,a as pe,b as he,c as xe,d as L}from"./select-sOwKYsgI.js";import{S as Q}from"./switch-7PH_rDz6.js";import{B as fe}from"./badge-DpUlf_NW.js";const ze=["claude-sonnet-4-5-20250929","claude-sonnet-4-5-20250929-thinking","claude-sonnet-4-20250514","claude-opus-4-1-20250805","claude-opus-4-1-20250805-thinking","claude-haiku-4-5-20251001","claude-haiku-4-5-20251001-thinking","claude-3-5-haiku-20241022"],qe=["gpt-4o-mini","gpt-4o","o4-mini","o4-large","gpt-5-codex"];function be(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():Math.random().toString(36).slice(2,10)}function R(e,a){var t;return(t=e==null?void 0:e.customEndpoints)!=null&&t.length?e.customEndpoints:a}function B(e){return e?Object.entries(e).map(([a,t])=>({id:be(),source:a,target:t})):[]}function Ge(e,a){var r,n,p;if(!e)return{};const t={},o=e.endpointRouting??{};t.anthropic=B(((r=o.anthropic)==null?void 0:r.modelRoutes)??e.modelRoutes??{}),t.openai=B(((n=o.openai)==null?void 0:n.modelRoutes)??{});for(const u of R(e,a))(p=u.routing)!=null&&p.modelRoutes?t[u.id]=B(u.routing.modelRoutes):t[u.id]=[];return t}function ge(e,a,t){var n,p,u;const o=R(e,a).find(y=>y.id===t);if(o)return((n=o.routing)==null?void 0:n.modelRoutes)??{};const r=e.endpointRouting??{};return t==="anthropic"?((p=r.anthropic)==null?void 0:p.modelRoutes)??e.modelRoutes??{}:t==="openai"?((u=r.openai)==null?void 0:u.modelRoutes)??{}:{}}function F(e,a,t){var r,n,p;if(t==="anthropic"||t==="openai")return((n=(r=e.endpointRouting)==null?void 0:r[t])==null?void 0:n.defaults)??e.defaults;const o=R(e,a).find(u=>u.id===t);return((p=o==null?void 0:o.routing)==null?void 0:p.defaults)??e.defaults}function Qe(e,a){if(!e)return{};const t={anthropic:F(e,a,"anthropic"),openai:F(e,a,"openai")};for(const o of R(e,a))t[o.id]=F(e,a,o.id);return t}function ve(e){const a={};for(const t of e){const o=t.source.trim(),r=t.target.trim();o&&r&&(a[o]=r)}return a}function Je(e,a){return JSON.stringify(ve(e))!==JSON.stringify(a)}function Xe(e,a,t){var r,n,p;if(!a)return;if(e==="anthropic"||e==="openai")return(n=(r=a.endpointRouting)==null?void 0:r[e])==null?void 0:n.compatibility;const o=R(a,t).find(u=>u.id===e);return(p=o==null?void 0:o.routing)==null?void 0:p.compatibility}function Ye(e,a){var o,r;const t={anthropic:((o=e.routingPresets)==null?void 0:o.anthropic)??[],openai:((r=e.routingPresets)==null?void 0:r.openai)??[]};for(const n of R(e,a))t[n.id]=n.routingPresets??[];return t}function ye(e,a){const t=[{key:"providers",label:e("modelManagement.tabs.providers"),description:e("modelManagement.tabs.providersDesc"),isSystem:!0,canDelete:!1},{key:"anthropic",label:e("modelManagement.tabs.anthropic"),description:e("modelManagement.tabs.anthropicDesc"),isSystem:!0,canDelete:!1,protocols:["anthropic"]},{key:"openai",label:e("modelManagement.tabs.openai"),description:e("modelManagement.tabs.openaiDesc"),isSystem:!0,canDelete:!1,protocols:["openai-auto","openai-chat","openai-responses"]}],o=a.map(r=>{let n=e("modelManagement.tabs.customEndpoint"),p=[];if(r.paths&&r.paths.length>0)n=`${e("modelManagement.tabs.customEndpoint")}: ${r.paths.map(u=>`${u.path} (${u.protocol})`).join(", ")}`,p=[...new Set(r.paths.map(u=>u.protocol))];else if(r.path){const u=r.protocol||"anthropic";n=`${e("modelManagement.tabs.customEndpoint")}: ${r.path} (${u})`,p=[u]}return{key:r.id,label:r.label||r.id,description:n,isSystem:!1,canDelete:r.deletable!==!1,protocols:p}});return[...t,...o]}function We(e){return e.label&&e.label.trim().length>0?`${e.label} (${e.id})`:e.id}function je(e,a){if(!e)return!1;const[t]=e.split(":");return t===a||e===a}function Ne(e,a,t){if(!e)return[];const o=["anthropic","openai",...R(e,a).map(n=>n.id)],r=[];for(const n of o){const p=ge(e,a,n);for(const[u,y]of Object.entries(p))je(y,t)&&r.push({endpoint:n,source:u,target:y})}return r}function Ze(e,a,t){return Ne(e,a,t).length}function es(){var N;const{t:e}=P(),{pushToast:a}=oe(),t=ie(G.config.full(),ue.configRequest()),o=ne({queryKey:G.customEndpoints.all(),queryFn:ce.list,refetchInterval:1e4}),r=w.useMemo(()=>{var g;return((g=o.data)==null?void 0:g.endpoints)??[]},[(N=o.data)==null?void 0:N.endpoints]),n=w.useMemo(()=>ye(e,r),[r,e]),[p,u]=w.useState(null);return w.useEffect(()=>{t.data&&u(t.data)},[t.data]),w.useEffect(()=>{!t.isError||!t.error||a({title:e("providers.toast.loadFailure",{message:t.error.message}),variant:"error"})},[t.error,t.isError,a,e]),{t:e,pushToast:a,config:p,setConfig:u,configQuery:t,customEndpoints:r,customEndpointsQuery:o,tabs:n,ensureConfig:()=>p?!0:(a({title:e("settings.toast.missingConfig"),variant:"error"}),t.refetch(),!1)}}const ss={savePreset(e,a){return V(O.post(`/api/routing-presets/${e}`,{name:a}))},applyPreset(e,a){return V(O.post(`/api/routing-presets/${e}/apply`,{name:a}))},deletePreset(e,a){return V(O.delete(`/api/routing-presets/${e}/${encodeURIComponent(a)}`))},testProvider(e,a){return V(O.post(`/api/providers/${e}/test`,a??{}))}},we={complete:"border-primary bg-primary text-primary-foreground",current:"border-primary bg-card text-primary ring-2 ring-primary/20",error:"border-destructive bg-card text-destructive ring-2 ring-destructive/20",upcoming:"border-border bg-card text-muted-foreground"},Se={complete:"text-foreground",current:"text-foreground font-medium",error:"text-destructive font-medium",upcoming:"text-muted-foreground"};function rs({steps:e,current:a,onSelect:t,className:o}){return s.jsx("nav",{"aria-label":"steps",className:T("flex items-start",o),children:e.map((r,n)=>{const p=t&&(r.status==="complete"||r.status==="current"),u=n===e.length-1,y=r.status==="complete"?"bg-primary/40":"bg-border",N=s.jsx("span",{className:T("motion-surface flex h-7 w-7 shrink-0 items-center justify-center rounded-lg border text-xs font-semibold",we[r.status]),"aria-current":r.id===a?"step":void 0,children:r.status==="complete"?s.jsx(le,{className:"h-3.5 w-3.5","aria-hidden":!0}):n+1}),g=`stepnav-${r.id}-label`;return s.jsxs("div",{className:"flex flex-1 items-start",children:[s.jsxs("div",{className:"flex min-w-0 flex-col items-center gap-1.5",children:[p?s.jsx("button",{type:"button",onClick:()=>t==null?void 0:t(r.id),"aria-labelledby":g,className:"rounded-lg outline-none focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-offset-2 focus-visible:ring-offset-background motion-surface",children:N}):N,s.jsx("span",{id:g,className:T("text-center text-[11px] leading-tight",Se[r.status]),children:r.label})]}),u?null:s.jsx("span",{"aria-hidden":!0,className:T("mx-1.5 mt-3.5 h-px flex-1",y)})]},r.id)})})}function Me({result:e,className:a}){const{t}=P();return s.jsxs("div",{className:T("flex flex-wrap items-center gap-2 rounded-lg px-3 py-2 text-xs",e.ok?"bg-success-bg text-success":"bg-destructive/10 text-destructive",a),children:[s.jsx(fe,{variant:e.ok?"success":"destructive",className:"shrink-0",children:e.ok?t("workbench.testResult.success"):t("workbench.testResult.failure")}),e.status?s.jsx("span",{className:"shrink-0",children:t("workbench.testResult.status",{status:e.status})}):null,e.durationMs?s.jsx("span",{className:"shrink-0",children:t("workbench.testResult.duration",{duration:`${e.durationMs} ms`})}):null,e.message?s.jsx("span",{className:"min-w-0 truncate",title:e.message,children:e.message}):null]})}function D(){return typeof globalThis.crypto<"u"&&typeof globalThis.crypto.randomUUID=="function"?globalThis.crypto.randomUUID():Math.random().toString(36).slice(2,10)}function ke(){return{_key:D(),id:"",label:""}}function Ce(){return{_key:D(),name:"",value:""}}const K={openai:{baseUrl:"https://api.openai.com/v1"},deepseek:{baseUrl:"https://api.deepseek.com/v1"},huawei:{baseUrl:"https://api.modelarts-maas.com/v1"},kimi:{baseUrl:"https://api.moonshot.cn/v1"},anthropic:{baseUrl:"https://api.anthropic.com/v1"},custom:{}},Ue=[{value:"openai",label:"OpenAI"},{value:"deepseek",label:"DeepSeek"},{value:"huawei",label:"Huawei Cloud"},{value:"kimi",label:"Kimi"},{value:"anthropic",label:"Anthropic"},{value:"custom",label:"Custom"}],as=[{id:"basics",labelKey:"providers.drawer.steps.basics"},{id:"models",labelKey:"providers.drawer.steps.modelsVerify"}];function _(e){return e==="anthropic"?"authToken":"apiKey"}function Re(e,a,t){return t(a==="authToken"?"providers.drawer.fields.authModeAuthToken":a==="xAuthToken"?"providers.drawer.fields.authModeXAuthToken":e==="anthropic"?"providers.drawer.fields.authModeApiKey":"providers.drawer.fields.authModeProviderDefault")}function J(e){return e?{id:e.id,label:e.label??e.id,baseUrl:e.baseUrl,apiKey:e.apiKey??"",type:e.type??"custom",defaultModel:e.defaultModel??"",models:(e.models??[]).map(a=>({...a,_key:D()})),authMode:e.authMode??_(e.type??"custom"),nonStreamViaStream:e.nonStreamViaStream??!1,useAbsoluteUrl:e.useAbsoluteUrl??!1,extraHeaders:Object.entries(e.extraHeaders??{}).map(([a,t])=>({name:a,value:t,_key:D()}))}:{id:"",label:"",baseUrl:"",apiKey:"",type:"custom",defaultModel:"",models:[],authMode:_("custom"),nonStreamViaStream:!1,useAbsoluteUrl:!1,extraHeaders:[]}}function Te(e){return{_key:D(),id:e.id,label:e.label,nonStreamViaStream:e.nonStreamViaStream}}function ts({form:e,errors:a,isCreate:t,advancedOpen:o,onAdvancedOpenChange:r,idInputRef:n,onProviderIdChange:p,onFieldChange:u,onTypeChange:y,onAuthModeChange:N,onNonStreamViaStreamChange:g,onUseAbsoluteUrlChange:m,onAddHeader:E,onRemoveHeader:j,onHeaderChange:S}){const{t:i}=P();return s.jsxs("div",{className:"space-y-8",children:[s.jsxs("section",{className:"space-y-5","aria-labelledby":"provider-type-fields",children:[s.jsxs("div",{className:"space-y-1",children:[s.jsx("h3",{id:"provider-type-fields",className:"text-sm font-semibold",children:i("providers.drawer.sections.type")}),s.jsx("p",{className:"text-xs text-muted-foreground",children:i("providers.drawer.hints.type")})]}),s.jsx("div",{className:"grid gap-2 md:grid-cols-3",children:Ue.map(b=>{var k;const U=b.value===e.type;return s.jsxs("button",{type:"button",onClick:()=>y(b.value),className:T("rounded-2xl border px-4 py-3 text-left transition focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",U?"border-primary bg-primary/10 text-primary":"border-border bg-card text-foreground hover:border-primary/20 hover:bg-accent/50"),children:[s.jsx("div",{className:"text-sm font-semibold",children:b.label}),s.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:((k=K[b.value??"custom"])==null?void 0:k.baseUrl)??i("providers.drawer.hints.customProvider")})]},b.value??"custom")})})]}),s.jsxs("section",{className:"space-y-4","aria-labelledby":"provider-basic-info",children:[s.jsxs("div",{className:"space-y-1",children:[s.jsx("h3",{id:"provider-basic-info",className:"text-sm font-semibold",children:i("providers.drawer.sections.basic")}),s.jsx("p",{className:"text-xs text-muted-foreground",children:i("providers.drawer.hints.basic")})]}),s.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[s.jsxs(M,{className:"flex flex-col gap-2 text-sm",children:[s.jsx("span",{className:"text-xs text-muted-foreground",children:i("providers.drawer.fields.id")}),s.jsx(C,{value:e.id,ref:n,onChange:b=>p(b.target.value),disabled:!t,placeholder:i("providers.drawer.fields.idPlaceholder"),"aria-invalid":!!a.id}),a.id?s.jsx("span",{className:"text-xs text-destructive",children:a.id}):null]}),s.jsxs(M,{className:"flex flex-col gap-2 text-sm",children:[s.jsx("span",{className:"text-xs text-muted-foreground",children:i("providers.drawer.fields.label")}),s.jsx(C,{value:e.label,onChange:b=>u("label")(b.target.value),placeholder:i("providers.drawer.fields.labelPlaceholder")})]})]}),s.jsxs(M,{className:"flex flex-col gap-2 text-sm",children:[s.jsx("span",{className:"text-xs text-muted-foreground",children:i("providers.drawer.fields.baseUrl")}),s.jsx(C,{value:e.baseUrl,onChange:b=>u("baseUrl")(b.target.value),placeholder:i("providers.drawer.fields.baseUrlPlaceholder"),"aria-invalid":!!a.baseUrl}),a.baseUrl?s.jsx("span",{className:"text-xs text-destructive",children:a.baseUrl}):null]})]}),s.jsxs("section",{className:"space-y-4","aria-labelledby":"provider-auth-fields",children:[s.jsxs("div",{className:"space-y-1",children:[s.jsx("h3",{id:"provider-auth-fields",className:"text-sm font-semibold",children:i("providers.drawer.sections.auth")}),s.jsx("p",{className:"text-xs text-muted-foreground",children:i("providers.drawer.hints.auth")})]}),s.jsxs(M,{className:"flex flex-col gap-2 text-sm",children:[s.jsx("span",{className:"text-xs text-muted-foreground",children:i("providers.drawer.fields.apiKey")}),s.jsx(C,{value:e.apiKey,onChange:b=>u("apiKey")(b.target.value),placeholder:i("providers.drawer.fields.apiKeyPlaceholder")})]}),s.jsxs("fieldset",{className:"grid gap-2 rounded-xl border border-transparent bg-card p-4 text-xs shadow-[var(--surface-shadow)]",children:[s.jsx("legend",{className:"px-1 text-muted-foreground",children:i("providers.drawer.fields.authMode")}),s.jsx("p",{className:"text-[11px] text-muted-foreground",children:i("providers.drawer.fields.authModeHint")}),s.jsxs("label",{className:"flex cursor-pointer items-start gap-3 rounded-xl border border-transparent px-3 py-2 transition hover:bg-accent focus-within:bg-accent",children:[s.jsx("input",{type:"radio",name:"provider-auth-mode",value:"apiKey",checked:e.authMode==="apiKey",onChange:()=>N("apiKey"),className:"mt-0.5 h-4 w-4 accent-primary"}),s.jsx("span",{children:Re(e.type,"apiKey",i)})]}),s.jsxs("label",{className:"flex cursor-pointer items-start gap-3 rounded-xl border border-transparent px-3 py-2 transition hover:bg-accent focus-within:bg-accent",children:[s.jsx("input",{type:"radio",name:"provider-auth-mode",value:"authToken",checked:e.authMode==="authToken",onChange:()=>N("authToken"),className:"mt-0.5 h-4 w-4 accent-primary"}),s.jsx("span",{children:i("providers.drawer.fields.authModeAuthToken")})]}),s.jsxs("label",{className:"flex cursor-pointer items-start gap-3 rounded-xl border border-transparent px-3 py-2 transition hover:bg-accent focus-within:bg-accent",children:[s.jsx("input",{type:"radio",name:"provider-auth-mode",value:"xAuthToken",checked:e.authMode==="xAuthToken",onChange:()=>N("xAuthToken"),className:"mt-0.5 h-4 w-4 accent-primary"}),s.jsx("span",{children:i("providers.drawer.fields.authModeXAuthToken")})]})]}),s.jsxs(X,{open:o,onOpenChange:r,summary:i("providers.drawer.fields.advancedOptions"),className:"rounded-xl border border-transparent bg-card shadow-[var(--surface-shadow)]",summaryClassName:"px-4 py-3 text-sm font-medium",contentClassName:"border-t border-border px-4 py-4",children:[s.jsxs("div",{className:"flex items-start justify-between gap-4",children:[s.jsxs("div",{className:"space-y-1",children:[s.jsx("p",{className:"text-sm font-medium",children:i("providers.drawer.fields.nonStreamViaStream")}),s.jsx("p",{className:"text-xs leading-relaxed text-muted-foreground",children:i("providers.drawer.fields.nonStreamViaStreamHint")})]}),s.jsx(Q,{checked:e.nonStreamViaStream,onCheckedChange:g,"aria-label":i("providers.drawer.fields.nonStreamViaStream")})]}),s.jsx("div",{className:"mt-4 border-t border-border pt-4",children:s.jsxs("div",{className:"flex items-start justify-between gap-4",children:[s.jsxs("div",{className:"space-y-1",children:[s.jsx("p",{className:"text-sm font-medium",children:i("providers.drawer.fields.useAbsoluteUrl")}),s.jsx("p",{className:"text-xs leading-relaxed text-muted-foreground",children:i("providers.drawer.fields.useAbsoluteUrlHint")})]}),s.jsx(Q,{checked:e.useAbsoluteUrl,onCheckedChange:m,"aria-label":i("providers.drawer.fields.useAbsoluteUrl")})]})}),s.jsxs("div",{className:"mt-4 border-t border-border pt-4",children:[s.jsxs("div",{className:"flex items-start justify-between gap-4",children:[s.jsxs("div",{className:"space-y-1",children:[s.jsx("p",{className:"text-sm font-medium",children:i("providers.drawer.fields.extraHeaders")}),s.jsx("p",{className:"text-xs leading-relaxed text-muted-foreground",children:i("providers.drawer.fields.extraHeadersHint")})]}),s.jsx(A,{type:"button",variant:"outline",size:"sm",onClick:E,className:"bg-card text-xs",children:i("providers.drawer.fields.addHeader")})]}),a.extraHeaders?s.jsx("p",{className:"mt-2 text-xs text-destructive",children:a.extraHeaders}):null,e.extraHeaders.length>0?s.jsx("div",{className:"mt-3 space-y-3",children:e.extraHeaders.map((b,U)=>s.jsxs("div",{className:"rounded-xl border border-transparent bg-secondary/40 p-3",children:[s.jsxs("div",{className:"grid gap-3 md:grid-cols-2",children:[s.jsxs(M,{className:"flex flex-col gap-1.5 text-sm",children:[s.jsx("span",{className:"text-xs text-muted-foreground",children:i("providers.drawer.fields.headerName")}),s.jsx(C,{value:b.name,onChange:k=>S(U,{name:k.target.value}),placeholder:i("providers.drawer.fields.headerNamePlaceholder")})]}),s.jsxs(M,{className:"flex flex-col gap-1.5 text-sm",children:[s.jsx("span",{className:"text-xs text-muted-foreground",children:i("providers.drawer.fields.headerValue")}),s.jsx(C,{value:b.value,onChange:k=>S(U,{value:k.target.value}),placeholder:i("providers.drawer.fields.headerValuePlaceholder")})]})]}),s.jsx("div",{className:"mt-2 flex justify-end",children:s.jsx(A,{type:"button",variant:"ghost",size:"sm",className:"h-auto px-2 text-destructive",onClick:()=>j(U),children:i("providers.drawer.fields.removeHeader")})})]},b._key))}):null]})]})]})]})}function ds({form:e,errors:a,advancedOpen:t,onAdvancedOpenChange:o,onModelIdChange:r,onModelChange:n,onAddModel:p,onRemoveModel:u,onModelNonStreamViaStreamChange:y,onSetDefaultModel:N,testVerification:g}){const{t:m}=P(),E=e.models.filter(j=>j.id.trim().length>0);return s.jsxs("div",{className:"space-y-8",children:[s.jsxs("section",{className:"space-y-4","aria-labelledby":"provider-model-fields",children:[s.jsxs("div",{className:"flex items-start justify-between gap-4",children:[s.jsxs("div",{className:"space-y-1",children:[s.jsx("h3",{id:"provider-model-fields",className:"text-sm font-semibold",children:m("providers.drawer.fields.models")}),s.jsx("p",{className:"text-xs text-muted-foreground",children:m("providers.drawer.modelsDescription")})]}),s.jsx(A,{type:"button",variant:"outline",size:"sm",onClick:p,className:"bg-card text-xs",children:m("providers.drawer.fields.addModel")})]}),a.models?s.jsx("p",{className:"text-xs text-destructive",children:a.models}):null,s.jsxs("div",{className:"space-y-4",children:[e.models.map((j,S)=>s.jsxs("div",{className:"rounded-xl border border-transparent bg-card p-4 shadow-[var(--surface-shadow)]",children:[s.jsx("div",{className:"grid gap-4 md:grid-cols-2",children:s.jsxs(M,{className:"flex flex-col gap-2 text-sm",children:[s.jsx("span",{className:"text-xs text-muted-foreground",children:m("providers.drawer.fields.modelId")}),s.jsx(C,{value:j.id,onChange:i=>r(S,i.target.value),placeholder:m("providers.drawer.fields.modelIdPlaceholder")})]})}),s.jsxs(X,{open:t,onOpenChange:o,summary:m("providers.drawer.fields.advancedOptions"),className:"mt-4 rounded-xl bg-secondary/50",summaryClassName:"px-3 py-2 text-xs font-medium",contentClassName:"space-y-4 px-3 py-3",children:[s.jsxs(M,{className:"flex flex-col gap-2 text-sm",children:[s.jsx("span",{className:"text-xs text-muted-foreground",children:m("providers.drawer.fields.modelLabel")}),s.jsx(C,{value:j.label??"",onChange:i=>n(S,{label:i.target.value}),placeholder:m("providers.drawer.fields.modelLabelPlaceholder")})]}),s.jsxs(M,{className:"flex flex-col gap-2 text-sm",children:[s.jsx("span",{className:"text-xs text-muted-foreground",children:m("providers.drawer.fields.modelNonStreamViaStream")}),s.jsxs(me,{value:j.nonStreamViaStream===void 0?"inherit":j.nonStreamViaStream?"enabled":"disabled",onValueChange:i=>y(S,i),children:[s.jsx(pe,{children:s.jsx(he,{})}),s.jsxs(xe,{children:[s.jsx(L,{value:"inherit",children:m("providers.drawer.fields.modelNonStreamViaStreamInherit")}),s.jsx(L,{value:"enabled",children:m("providers.drawer.fields.modelNonStreamViaStreamEnabled")}),s.jsx(L,{value:"disabled",children:m("providers.drawer.fields.modelNonStreamViaStreamDisabled")})]})]})]})]}),s.jsxs("div",{className:"mt-3 flex flex-wrap items-center justify-between gap-3 text-xs",children:[s.jsxs("label",{className:"flex items-center gap-2 text-muted-foreground",children:[s.jsx("input",{type:"radio",name:"defaultModel",value:j.id,"aria-label":m("providers.drawer.fields.setDefault"),checked:e.defaultModel===j.id,onChange:()=>N(j.id),disabled:j.id.trim().length===0,className:"h-4 w-4 accent-primary"}),m("providers.drawer.fields.setDefault")]}),s.jsx(A,{type:"button",variant:"ghost",size:"sm",className:"h-auto px-2 text-destructive",onClick:()=>u(S),disabled:e.models.length===0,children:m("providers.drawer.fields.removeModel")})]})]},j._key)),e.models.length===0?s.jsx("div",{className:"rounded-xl border border-warning/30 bg-warning-bg p-5",children:s.jsxs("div",{className:"space-y-2",children:[s.jsx("p",{className:"text-sm font-semibold text-warning",children:m("providers.drawer.noModelsTitle")}),s.jsx("p",{className:"text-xs leading-relaxed text-warning",children:m("providers.drawer.noModelsHint",{providerId:e.id||"provider-id"})}),s.jsxs("div",{className:"rounded-lg bg-secondary/50 p-2.5",children:[s.jsx("p",{className:"mb-1.5 text-xs font-medium text-foreground",children:m("providers.drawer.routeExample")}),s.jsxs("code",{className:"block rounded-lg border border-transparent bg-card px-2.5 py-1.5 font-mono text-xs text-foreground shadow-[var(--surface-shadow)]",children:['"claude-*": "',(e.id||"provider-id").trim()||"provider-id",':*"']})]})]})}):null]}),E.length>1?s.jsx("div",{className:"text-xs text-muted-foreground",children:m("providers.drawer.defaultHint",{model:e.defaultModel||m("providers.card.noDefault")})}):null]}),g?s.jsxs("section",{className:"space-y-3","aria-labelledby":"provider-verify-fields",children:[s.jsxs("div",{className:"space-y-1",children:[s.jsx("h3",{id:"provider-verify-fields",className:"text-sm font-semibold",children:m("workbench.drawer.verifyTitle")}),s.jsx("p",{className:"text-xs text-muted-foreground",children:m("workbench.drawer.verifyHint")})]}),g.available?s.jsxs("div",{className:"space-y-3 rounded-xl border border-transparent bg-card p-4 shadow-[var(--surface-shadow)]",children:[s.jsx(A,{type:"button",variant:"outline",size:"sm",onClick:g.onTest,disabled:g.testing,children:g.testing?m("common.actions.testingConnection"):m("workbench.drawer.verifyRun")}),g.result?s.jsx(Me,{result:g.result}):null]}):s.jsx("p",{className:"rounded-xl bg-secondary/50 px-4 py-3 text-xs text-muted-foreground",children:m("workbench.drawer.verifySaveFirst")})]}):null]})}const Ee=/^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/;function ls({mode:e,provider:a,existingProviderIds:t}){const{t:o}=P(),[r,n]=w.useState(()=>J(a)),[p,u]=w.useState({}),[y,N]=w.useState(e==="edit"),g=w.useRef(null),m=w.useCallback(()=>{n(J(a)),u({}),N(e==="edit")},[a,e]),E=d=>l=>{n(h=>({...h,[d]:l}))},j=d=>{n(l=>{const c=!y||l.label.trim().length===0||l.label===l.id?d:l.label;return{...l,id:d,label:c}})},S=d=>{n(l=>{var q;const c=K[d??"custom"]??K.custom,x=_(l.type),f=_(d),v=Object.values(K).map(H=>H.baseUrl).filter(H=>!!H),$=!l.baseUrl||v.includes(l.baseUrl),de=e==="create"&&(l.models.length===0||l.models.every(H=>H.id.trim().length===0)),I={...l,type:d,authMode:l.authMode===x?f:l.authMode};return c!=null&&c.baseUrl&&$&&(I.baseUrl=c.baseUrl),c!=null&&c.models&&de&&(I.models=c.models.map(Te),I.defaultModel=c.defaultModel??((q=c.models[0])==null?void 0:q.id)??""),I})},i=(d,l)=>{n(h=>{const c=[...h.models];return c[d]={...c[d],...l},{...h,models:c}})},b=(d,l)=>{n(h=>{const c=[...h.models],x=c[d];if(!x)return h;const f=!y||!x.label||x.label===x.id,v={...x,id:l,label:f?l:x.label};c[d]=v;const $=h.defaultModel===x.id?l:h.defaultModel;return{...h,models:c,defaultModel:$}})},U=d=>{n(l=>{if(d<0||d>=l.models.length)return l;const h=l.models.filter((x,f)=>f!==d);let c=l.defaultModel;return h.some(x=>x.id===c)||(c=""),{...l,models:h,defaultModel:c}})},k=()=>{n(d=>({...d,models:[...d.models,ke()]}))},Y=(d,l)=>{n(h=>{const c=[...h.extraHeaders];return c[d]={...c[d],...l},{...h,extraHeaders:c}})},W=()=>{n(d=>({...d,extraHeaders:[...d.extraHeaders,Ce()]}))},Z=d=>{n(l=>{if(d<0||d>=l.extraHeaders.length)return l;const h=l.extraHeaders.filter((c,x)=>x!==d);return{...l,extraHeaders:h}})},ee=d=>{n(l=>({...l,authMode:d}))},se=d=>{n(l=>({...l,nonStreamViaStream:d}))},re=d=>{n(l=>({...l,useAbsoluteUrl:d}))},ae=(d,l)=>{i(d,{nonStreamViaStream:l==="inherit"?void 0:l==="enabled"})},te=d=>{n(l=>({...l,defaultModel:d}))},z=()=>{const d={},l=r.id.trim(),h=r.baseUrl.trim();if(e==="create"&&(l.length===0?d.id=o("providers.drawer.errors.idRequired"):t.includes(l)&&(d.id=o("providers.drawer.errors.idDuplicate"))),e==="edit"&&l.length===0&&(d.id=o("providers.drawer.errors.idRequired")),h.length===0)d.baseUrl=o("providers.drawer.errors.baseUrlInvalid");else try{new URL(h)}catch{d.baseUrl=o("providers.drawer.errors.baseUrlInvalid")}if(r.models.length>0){const c=new Set;r.models.some(f=>{const v=f.id.trim();return v.length===0||c.has(v)?!0:(c.add(v),!1)})&&(d.models=o("providers.drawer.errors.modelInvalid"))}if(r.defaultModel&&!r.models.some(c=>c.id===r.defaultModel)&&(d.models=o("providers.drawer.errors.defaultInvalid")),r.extraHeaders.length>0){const c=new Set;for(const x of r.extraHeaders){const f=x.name.trim();if(f.length===0)continue;if(!Ee.test(f)){d.extraHeaders=o("providers.drawer.errors.headerNameInvalid");break}const v=f.toLowerCase();if(c.has(v)){d.extraHeaders=o("providers.drawer.errors.headerNameDuplicate");break}c.add(v)}}return u(d),d};return{form:r,errors:p,advancedOpen:y,setAdvancedOpen:N,providerIdRef:g,isCreate:e==="create",resetForm:m,validate:()=>Object.keys(z()).length===0,validateErrors:z,serialize:()=>{const d=r.models.map(f=>{var v;return{id:f.id.trim(),label:(v=f.label)!=null&&v.trim()?f.label.trim():void 0,nonStreamViaStream:f.nonStreamViaStream}}).filter(f=>f.id.length>0),l={};for(const f of r.extraHeaders){const v=f.name.trim();v.length>0&&(l[v]=f.value)}const h=Object.keys(l).length>0,c=r.authMode==="apiKey"&&r.type!=="anthropic"?void 0:r.authMode,x={id:r.id.trim(),label:r.label.trim()||r.id.trim(),baseUrl:r.baseUrl.trim(),apiKey:r.apiKey.trim()||void 0,type:r.type??"custom",defaultModel:r.defaultModel||void 0,models:d.length>0?d:void 0,extraHeaders:h?l:void 0,authMode:c};return r.nonStreamViaStream&&(x.nonStreamViaStream=!0),r.useAbsoluteUrl&&(x.useAbsoluteUrl=!0),x},handleFieldChange:E,handleProviderIdChange:j,handleTypeChange:S,handleModelChange:i,handleModelIdChange:b,handleRemoveModel:U,handleAddModel:k,handleHeaderChange:Y,handleAddHeader:W,handleRemoveHeader:Z,handleAuthModeChange:ee,handleProviderNonStreamViaStreamChange:se,handleUseAbsoluteUrlChange:re,handleModelNonStreamViaStreamChange:ae,handleSetDefaultModel:te}}export{ts as B,ze as C,ds as M,qe as O,Ue as P,rs as S,Me as T,Je as a,Qe as b,F as c,Ge as d,Ye as e,be as f,ge as g,We as h,Re as i,as as j,Ne as k,Xe as l,ss as m,es as n,Ze as o,je as r,ls as u};
@@ -14,7 +14,7 @@
14
14
  rel="stylesheet"
15
15
  />
16
16
  <title>cc-gw 控制台</title>
17
- <script type="module" crossorigin src="/assets/app-Citq5KW4.js"></script>
17
+ <script type="module" crossorigin src="/assets/app-vWIA9Pq_.js"></script>
18
18
  <link rel="modulepreload" crossorigin href="/assets/vendor-CITafuNQ.js">
19
19
  <link rel="modulepreload" crossorigin href="/assets/global-BCehxTGJ.js">
20
20
  <link rel="modulepreload" crossorigin href="/assets/query-DZF7K6hv.js">
@@ -42,11 +42,11 @@
42
42
  }
43
43
  </script>
44
44
  <title>cc-gw | 你的 API Key 不该躺在 30 个 .env 里 · local-first AI gateway</title>
45
- <script type="module" crossorigin src="/assets/landing-W4f2Nx8j.js"></script>
45
+ <script type="module" crossorigin src="/assets/landing-Dj8Ojphq.js"></script>
46
46
  <link rel="modulepreload" crossorigin href="/assets/vendor-CITafuNQ.js">
47
47
  <link rel="modulepreload" crossorigin href="/assets/global-BCehxTGJ.js">
48
48
  <link rel="modulepreload" crossorigin href="/assets/clipboard-BnAnBk_-.js">
49
- <link rel="modulepreload" crossorigin href="/assets/package-B2CgmdJ7.js">
49
+ <link rel="modulepreload" crossorigin href="/assets/package-BBDLwVNt.js">
50
50
  <link rel="stylesheet" crossorigin href="/assets/global-CIVH6GQV.css">
51
51
  </head>
52
52
  <body class="bg-slate-50 text-slate-900">
@@ -1 +0,0 @@
1
- import{j as e,an as Le,ao as Re,ap as oe,ac as Ie,O as _,r as f,aq as Me,T as Ee}from"./vendor-CITafuNQ.js";import{P as qe}from"./PageToolbar-CWw40AFL.js";import{P as $,a as q}from"./PageState-CFLrRswm.js";import{B as M,u as ke,a as Pe,b as Ae,c as A,d as De,t as Oe,q as D,s as ze}from"./app-Citq5KW4.js";import{S as Fe,a as Be,b as Ve,c as He,d as O}from"./select-sOwKYsgI.js";import{c as _e}from"./global-BCehxTGJ.js";import{L as E}from"./router-BoBrmro7.js";import{T as ne,a as ie,b as F,c as N,d as le,e as T,E as de}from"./table-CVuTTP1s.js";import{P as K}from"./PageSection-N34Nu8NO.js";import{S as $e,C as Ke,T as Qe,g as se}from"./utils-B_Q3Hhgb.js";import{B as S}from"./badge-DpUlf_NW.js";import{C as ce,a as ue}from"./card-D4YOc5eB.js";import{D as he}from"./disclosure-l5qsWhr7.js";import{M as g}from"./metric-card-G1bbpbiR.js";import{f as Ge,a as ae,b as z,L as Ue,T as We,c as re}from"./types-DYz12j32.js";import{u as p}from"./i18n-PeX9kBVO.js";import{e as me}from"./charts-core-BTTtAoo-.js";import{u as Ye}from"./useEventStream-BYg6oKvQ.js";import{a as Je}from"./apiKeys-k1jIJuDa.js";import{g as Xe}from"./gateway-i49olSPp.js";import"./query-DZF7K6hv.js";import"./radix-Bux_1C5J.js";import"./charts-react-BQP6-BFp.js";import"./charts-engine-CFhx8nba.js";function Ze(){return e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx("div",{className:"grid gap-3 sm:grid-cols-2 xl:grid-cols-4",children:Array.from({length:4}).map((s,a)=>e.jsx($e,{},a))}),e.jsx(Ke,{}),e.jsx("div",{className:"rounded-xl bg-card shadow-[var(--surface-shadow)]",children:e.jsx("table",{className:"w-full",children:e.jsx("tbody",{children:Array.from({length:5}).map((s,a)=>e.jsx(Qe,{columns:6},a))})})})]})}function et({status:s}){const{t:a}=p();return e.jsxs("div",{className:"space-y-3","data-testid":"dashboard-spotlight-grid",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1 text-sm","data-testid":"dashboard-overview-panel",children:[e.jsx("span",{className:"inline-flex items-center gap-1.5 rounded-md bg-success-bg px-1.5 py-0.5 text-[11px] font-medium text-success before:h-1.5 before:w-1.5 before:rounded-full before:bg-success before:animate-live-pulse",children:a("dashboard.status.listeningLabel")}),e.jsxs("span",{"data-testid":"dashboard-runtime-address",className:"metric-number text-sm font-semibold tracking-tight text-foreground",children:[(s==null?void 0:s.host)??"0.0.0.0",":",(s==null?void 0:s.port)??"-"]}),e.jsx("span",{className:"text-xs text-muted-foreground",children:a("dashboard.status.providers",{value:(s==null?void 0:s.providers)??0})})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2 xl:grid-cols-4",children:[e.jsx(g,{size:"md",label:a("dashboard.labels.activeRequests"),value:((s==null?void 0:s.activeRequests)??0).toLocaleString(),rawValue:(s==null?void 0:s.activeRequests)??0,valueTestId:"dashboard-spotlight-value-active"}),e.jsx(g,{size:"md",label:a("dashboard.labels.requestsPerMinute"),value:((s==null?void 0:s.requestsPerMinute)??0).toLocaleString(),rawValue:(s==null?void 0:s.requestsPerMinute)??0,valueTestId:"dashboard-spotlight-value-rpm"}),e.jsx(g,{size:"md",label:a("dashboard.labels.uniqueClientAddressesLastHour"),value:((s==null?void 0:s.uniqueClientAddressesLastHour)??0).toLocaleString(),rawValue:(s==null?void 0:s.uniqueClientAddressesLastHour)??0}),e.jsx(g,{size:"md",label:a("dashboard.labels.cpu"),value:Ge(s==null?void 0:s.cpuUsagePercent),valueTestId:"dashboard-spotlight-value-cpu"})]})]})}function tt(s){switch(s){case"error":return e.jsx(S,{variant:"destructive",children:"error"});case"warn":return e.jsx(S,{variant:"warning",children:"warn"});default:return e.jsx(S,{variant:"secondary",children:"info"})}}function st({overview:s}){const{t:a}=p(),t=s==null?void 0:s.today,r=s==null?void 0:s.yesterday,o=(t==null?void 0:t.requests)??0,n=(t==null?void 0:t.inputTokens)??0,d=(t==null?void 0:t.outputTokens)??0,l=(t==null?void 0:t.cacheReadTokens)??0,i=(t==null?void 0:t.errorCount)??0,h=o>0?i/o*100:0,L=r&&(r.requests??0)>0?r.errorCount/r.requests*100:void 0,w=l+n,B=w>0?l/w*100:0,R=(m,v)=>v!==void 0&&v>0?((m??0)-v)/v*100:void 0,u=m=>`${m>0?"+":""}${m.toFixed(1)}%`,I=(m,v=!1)=>m!==void 0&&Math.abs(m)>=.05?{value:m,invertColor:v,format:u}:void 0,C=o>0?R(h,L):void 0;return e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2 xl:grid-cols-5","data-testid":"dashboard-today-grid",children:[e.jsx(g,{size:"md",label:a("dashboard.cards.todayRequests"),value:o.toLocaleString(),rawValue:o,delta:I(R(o,r==null?void 0:r.requests)),hint:r&&r.requests>0?a("dashboard.cards.yesterdayHint",{value:r.requests.toLocaleString()}):void 0,valueTestId:"dashboard-today-value-requests"}),e.jsx(g,{size:"md",label:a("dashboard.cards.todayInput"),value:n.toLocaleString(),rawValue:n,suffix:a("common.units.token"),delta:I(R(n,r==null?void 0:r.inputTokens)),valueTestId:"dashboard-today-value-input"}),e.jsx(g,{size:"md",label:a("dashboard.cards.todayOutput"),value:d.toLocaleString(),rawValue:d,suffix:a("common.units.token"),delta:I(R(d,r==null?void 0:r.outputTokens)),valueTestId:"dashboard-today-value-output"}),e.jsx(g,{size:"md",label:a("dashboard.cards.todayCacheRead"),value:l.toLocaleString(),rawValue:l,suffix:a("common.units.token"),hint:w>0?a("dashboard.cards.cacheHitHint",{value:B.toFixed(1)}):void 0,valueTestId:"dashboard-today-value-cache-read"}),e.jsx(g,{size:"md",label:a("dashboard.cards.todayErrorRate"),value:h>0?e.jsxs("span",{className:"text-destructive",children:[h.toFixed(1),"%"]}):`${h.toFixed(1)}%`,delta:I(C,!0),hint:i>0?a("dashboard.cards.errorCountHint",{value:i}):void 0,valueTestId:"dashboard-today-value-error-rate"})]})}function at({connected:s,failed:a,events:t}){const{t:r}=p();return t.length===0?null:e.jsx(K,{title:r("dashboard.attention.title"),description:r("dashboard.attention.subtitle"),actions:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:a?"inline-flex items-center gap-1 text-[11px] font-medium text-destructive before:h-1.5 before:w-1.5 before:rounded-full before:bg-destructive":s?"inline-flex items-center gap-1 text-[11px] font-medium text-success before:h-1.5 before:w-1.5 before:rounded-full before:bg-success before:animate-live-pulse":"inline-flex items-center gap-1 text-[11px] font-medium text-warning before:h-1.5 before:w-1.5 before:rounded-full before:bg-warning",children:r(a?"dashboard.attention.failed":s?"dashboard.attention.live":"dashboard.attention.reconnecting")}),e.jsx(M,{asChild:!0,variant:"ghost",size:"sm",className:"h-7",children:e.jsx(E,{to:"/events",children:r("dashboard.attention.viewAll")})})]}),children:e.jsx("ul",{className:"divide-y divide-border",children:e.jsx(Re,{initial:!1,children:t.map(o=>e.jsxs(oe.li,{initial:{opacity:0,y:-8},animate:{opacity:1,y:0},exit:{opacity:0},transition:{duration:.18},className:"flex items-start gap-3 py-2.5 first:pt-0 last:pb-0",children:[e.jsx("div",{className:"pt-0.5",children:tt(o.level)}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"truncate text-sm font-medium text-foreground",children:o.title??o.type}),o.message?e.jsx("p",{className:"mt-0.5 line-clamp-1 text-xs text-muted-foreground",children:o.message}):null]}),e.jsx("span",{className:"shrink-0 pt-0.5 text-[11px] tabular-nums text-muted-foreground/70",children:new Date(o.createdAt).toLocaleTimeString()})]},o.id))})})})}function rt({connected:s,failed:a}){const{t}=p();return e.jsxs(oe.div,{initial:{opacity:0,y:-4},animate:{opacity:1,y:0},transition:{duration:.18},"data-testid":"dashboard-all-clear",className:"flex h-8 flex-wrap items-center gap-x-2 gap-y-1 rounded-full bg-success-bg px-3 text-xs text-success",children:[e.jsx(Ie,{className:"h-3.5 w-3.5 shrink-0","aria-hidden":"true"}),e.jsx("span",{className:"font-medium",children:t("dashboard.attention.allClear")}),e.jsx("span",{className:a?"ml-auto inline-flex items-center gap-1.5 text-[11px] font-medium text-destructive before:h-1.5 before:w-1.5 before:rounded-full before:bg-destructive":s?"ml-auto inline-flex items-center gap-1.5 text-[11px] font-medium before:h-1.5 before:w-1.5 before:rounded-full before:bg-success before:animate-live-pulse":"ml-auto inline-flex items-center gap-1.5 text-[11px] font-medium text-warning before:h-1.5 before:w-1.5 before:rounded-full before:bg-warning",children:t(a?"dashboard.attention.failed":s?"dashboard.attention.live":"dashboard.attention.reconnecting")}),e.jsx(E,{to:"/events",className:"shrink-0 underline-offset-2 hover:underline",children:t("dashboard.attention.viewAll")})]})}function ot({empty:s,loading:a,option:t}){const{t:r}=p();return e.jsx(mt,{title:r("dashboard.charts.trendTitle"),description:r("dashboard.charts.trendDesc"),loading:a,option:t,empty:s,emptyText:r("dashboard.charts.empty")})}function nt({daily:s,models:a}){const{t}=p();if(s.length===0&&a.length===0)return null;const r=s.reduce((i,h)=>i+h.requestCount,0),o=s.length>0?s.reduce((i,h)=>h.requestCount>i.requestCount?h:i,s[0]):null,n=a.length>0?a.reduce((i,h)=>h.requests>i.requests?h:i,a[0]):null,d=a.filter(i=>i.avgTtftMs!=null&&i.avgTtftMs>0).sort((i,h)=>(i.avgTtftMs??Number.POSITIVE_INFINITY)-(h.avgTtftMs??Number.POSITIVE_INFINITY))[0],l=[{label:t("dashboard.insights.totalRequests"),value:r>0?r.toLocaleString():"—",hint:r>0?t("dashboard.insights.totalRequestsHint"):void 0},{label:t("dashboard.insights.busiestDay"),value:o?o.date.slice(5):"—",hint:o?t("dashboard.insights.busiestDayHint",{value:o.requestCount.toLocaleString()}):void 0},{label:t("dashboard.insights.topModel"),value:n?n.model:"—",hint:n?t("dashboard.insights.topModelHint",{value:n.requests.toLocaleString()}):void 0},{label:t("dashboard.insights.fastestTtft"),value:d?d.model:"—",hint:d?t("dashboard.insights.fastestTtftHint",{value:Math.round(d.avgTtftMs??0)}):void 0}];return e.jsx("div",{className:"grid grid-cols-2 gap-3 xl:grid-cols-4","data-testid":"dashboard-insights-grid",children:l.map(i=>e.jsxs("div",{className:"rounded-lg border border-border bg-card px-4 py-3",children:[e.jsx("div",{className:"text-[10.5px] font-semibold uppercase tracking-[0.06em] text-muted-foreground",children:i.label}),e.jsx("div",{className:"metric-number mt-2 truncate text-base font-bold tracking-tight text-foreground",children:i.value}),i.hint?e.jsx("div",{className:"mt-0.5 text-[11px] text-muted-foreground",children:i.hint}):null]},i.label))})}function it({modelRequestsOption:s,models:a,ttftOption:t,tpotOption:r}){const{t:o}=p();return e.jsxs(he,{variant:"card",summaryClassName:"px-4 py-3",contentClassName:"border-t border-border px-4 py-4",summary:e.jsx("span",{className:"text-sm font-medium text-foreground",children:o("dashboard.sections.performance")}),children:[e.jsxs("div",{className:"grid gap-4 lg:grid-cols-3",children:[e.jsx(H,{title:o("dashboard.charts.modelTitle"),option:s,empty:!a.length}),e.jsx(H,{title:o("dashboard.charts.ttftTitle"),option:t,empty:!a.some(n=>n.avgTtftMs!=null&&n.avgTtftMs>0)}),e.jsx(H,{title:o("dashboard.charts.tpotTitle"),option:r,empty:!a.some(n=>n.avgTpotMs!=null&&n.avgTpotMs>0)})]}),e.jsx("div",{className:"mt-4",children:e.jsx(ut,{models:a,embedded:!0})})]})}function lt({compacting:s,dbInfo:a,dbSizeDisplay:t,memoryDisplay:r,onCompact:o,status:n}){const{t:d}=p();return e.jsxs(he,{variant:"card",summaryClassName:"px-4 py-3",contentClassName:"border-t border-border px-4 py-4",summary:e.jsx("span",{className:"text-sm font-medium text-foreground",children:d("dashboard.cards.systemResources")}),badge:e.jsxs("span",{className:"text-xs tabular-nums text-muted-foreground",children:[t," · ",r]}),children:[e.jsxs("div",{className:"grid gap-2.5 sm:grid-cols-2 lg:grid-cols-4",children:[e.jsx(g,{size:"sm",label:d("dashboard.labels.networkIngress"),value:ae(n==null?void 0:n.networkIngressBytesPerSecond),valueTestId:"dashboard-spotlight-value-ingress"}),e.jsx(g,{size:"sm",label:d("dashboard.labels.networkEgress"),value:ae(n==null?void 0:n.networkEgressBytesPerSecond),valueTestId:"dashboard-spotlight-value-egress"}),e.jsx(g,{size:"sm",label:d("dashboard.labels.database"),value:t,valueTestId:"dashboard-spotlight-value-database"}),e.jsx(g,{size:"sm",label:d("dashboard.labels.memory"),value:r,valueTestId:"dashboard-spotlight-value-memory"})]}),e.jsx("div",{className:"mt-4 flex justify-end",children:e.jsx(M,{variant:"outline",size:"sm",onClick:o,disabled:s,children:d(s?"dashboard.actions.compacting":"dashboard.actions.compact")})})]})}function dt({doneCount:s,total:a}){const{t}=p(),r=Math.min(100,Math.round(s/a*100));return e.jsxs("div",{"data-testid":"dashboard-setup-progress",className:"flex flex-wrap items-center gap-x-3 gap-y-2 rounded-full bg-secondary/60 px-4 py-2",children:[e.jsx("span",{className:"text-xs font-medium text-foreground",children:t("dashboard.setupProgress.label",{done:s,total:a})}),e.jsx("div",{className:"h-1.5 min-w-24 flex-1 overflow-hidden rounded-full bg-border/60",children:e.jsx("div",{className:"h-1.5 rounded-full bg-primary transition-all",style:{width:`${r}%`}})}),e.jsx(E,{to:"/setup",className:"shrink-0 text-xs font-medium text-primary underline-offset-2 hover:underline",children:t("dashboard.setupProgress.cta")})]})}function ct({endpointCount:s,providerCount:a}){const{t}=p(),r=[{title:t("dashboard.guide.step1Title"),description:a>0?t("dashboard.guide.step1DescDone",{count:a}):t("dashboard.guide.step1Desc"),href:"/providers",cta:t("dashboard.guide.step1Cta")},{title:t("dashboard.guide.step2Title"),description:s>0?t("dashboard.guide.step2DescDone",{count:s}):t("dashboard.guide.step2Desc"),href:"/providers",cta:t("dashboard.guide.step2Cta")},{title:t("dashboard.guide.step3Title"),description:t("dashboard.guide.step3Desc"),href:"/api-keys",cta:t("dashboard.guide.step3Cta")}];return e.jsx(ce,{className:"relative overflow-hidden",children:e.jsxs(ue,{className:"space-y-5 pt-5",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("h3",{className:"text-base font-semibold text-foreground",children:t("dashboard.guide.title")}),e.jsx("p",{className:"text-sm leading-6 text-muted-foreground",children:t("dashboard.guide.subtitle")})]}),e.jsx(M,{asChild:!0,size:"sm",children:e.jsx(E,{to:"/setup",children:t("dashboard.guide.startWizard")})})]}),e.jsx("ol",{className:"grid gap-3 lg:grid-cols-3",children:r.map((o,n)=>e.jsxs("li",{className:"rounded-lg border border-border p-4",children:[e.jsx("span",{className:"metric-number text-xs font-semibold text-muted-foreground",children:String(n+1).padStart(2,"0")}),e.jsx("h4",{className:"mt-2 text-sm font-semibold text-foreground",children:o.title}),e.jsx("p",{className:"mt-1.5 text-xs leading-6 text-muted-foreground",children:o.description}),e.jsx(M,{asChild:!0,variant:"ghost",size:"sm",className:"mt-2 h-8 px-0 text-primary hover:bg-transparent hover:text-primary/80",children:e.jsx(E,{to:o.href,children:o.cta})})]},o.title))})]})})}function ut({models:s,loading:a,embedded:t}){const{t:r}=p(),o=a?e.jsx($,{compact:!0,label:r("common.loadingShort")}):s.length===0?e.jsx(q,{compact:!0,icon:e.jsx(_,{className:"h-5 w-5","aria-hidden":"true"}),title:r("dashboard.modelTable.empty")}):e.jsx("div",{className:"overflow-auto",children:e.jsxs(ne,{children:[e.jsx(ie,{children:e.jsxs(F,{children:[e.jsx(N,{children:r("dashboard.modelTable.columns.model")}),e.jsx(N,{className:"text-right",children:r("dashboard.modelTable.columns.requests")}),e.jsx(N,{className:"text-right",children:r("dashboard.modelTable.columns.latency")}),e.jsx(N,{className:"text-right",children:r("dashboard.modelTable.columns.ttft")}),e.jsx(N,{className:"text-right",children:r("dashboard.modelTable.columns.tpot")})]})}),e.jsx(le,{children:s.map(n=>e.jsxs(F,{children:[e.jsx(T,{children:e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"font-medium",children:n.provider}),e.jsx("span",{className:"text-xs text-muted-foreground",children:n.model})]})}),e.jsx(T,{className:"text-right font-medium",children:n.requests.toLocaleString()}),e.jsx(T,{className:"text-right",children:z(n.avgLatencyMs,r("common.units.ms"))}),e.jsx(T,{className:"text-right",children:z(n.avgTtftMs,r("common.units.ms"))}),e.jsx(T,{className:"text-right",children:z(n.avgTpotMs,r("common.units.msPerToken"),{maximumFractionDigits:2})})]},`${n.provider}/${n.model}`))})]})});return t?o:e.jsx(K,{title:r("dashboard.modelTable.title"),description:r("dashboard.modelTable.description"),children:o})}function ht({records:s,loading:a}){const{t}=p(),r=s.map(l=>se(l,t)),o=r.filter(l=>l.tone==="success").length,n=r.filter(l=>l.tone==="error").length,d=r.filter(l=>l.tone==="pending").length;return e.jsx(K,{title:t("dashboard.recent.title"),description:t("dashboard.recent.subtitle",{count:5}),actions:s.length>0?e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(S,{variant:"secondary",children:s.length}),e.jsxs(S,{variant:"success",children:[t("common.status.success"),": ",o]}),e.jsxs(S,{variant:"outline",className:"border-destructive/30 bg-destructive/10 text-destructive",children:[t("common.status.error"),": ",n]}),d>0?e.jsxs(S,{variant:"warning",children:[t("common.status.pending"),": ",d]}):null]}):null,children:a?e.jsx($,{compact:!0,label:t("dashboard.recent.loading")}):s.length===0?e.jsx(q,{compact:!0,icon:e.jsx(Le,{className:"h-5 w-5","aria-hidden":"true"}),title:t("dashboard.recent.empty")}):e.jsx("div",{className:"overflow-auto",children:e.jsxs(ne,{children:[e.jsx(ie,{children:e.jsxs(F,{children:[e.jsx(N,{children:t("dashboard.recent.columns.time")}),e.jsx(N,{children:t("dashboard.recent.columns.endpoint")}),e.jsx(N,{children:t("dashboard.recent.columns.provider")}),e.jsx(N,{children:t("dashboard.recent.columns.route")}),e.jsx(N,{className:"text-right",children:t("dashboard.recent.columns.latency")}),e.jsx(N,{children:t("dashboard.recent.columns.status")})]})}),e.jsx(le,{children:s.map(l=>{const i=se(l,t);return e.jsxs(F,{children:[e.jsx(T,{children:e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"text-xs font-medium",children:new Date(l.timestamp).toLocaleString()}),e.jsxs("span",{className:"text-[11px] text-muted-foreground",children:["#",l.id]})]})}),e.jsx(T,{children:e.jsx(S,{variant:"outline",className:"text-[11px]",children:l.endpoint==="anthropic"?t("logs.endpointAnthropic"):l.endpoint==="openai"?t("logs.endpointOpenAI"):l.endpoint})}),e.jsx(T,{children:e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"font-medium",children:l.provider}),e.jsx("span",{className:"text-[11px] text-muted-foreground",children:l.stream?"stream":"sync"})]})}),e.jsx(T,{children:e.jsxs("div",{className:"flex flex-col gap-1 text-xs",children:[e.jsxs("div",{className:"flex items-center gap-1 text-muted-foreground",children:[e.jsx("span",{children:l.client_model??t("dashboard.recent.routePlaceholder")}),e.jsx("span",{children:"->"}),e.jsx("span",{className:"font-medium text-foreground",children:l.model})]}),l.error?e.jsx("span",{className:"truncate text-destructive",children:l.error}):null]})}),e.jsx(T,{className:"text-right font-medium",children:z(l.latency_ms,t("common.units.ms"))}),e.jsx(T,{children:e.jsx(S,{variant:i.variant,className:"min-w-14 justify-center",children:i.label})})]},l.id)})})]})})})}function H({empty:s,option:a,title:t}){const{t:r}=p();return e.jsxs("div",{className:"rounded-lg border border-border p-3",children:[e.jsx("p",{className:"mb-2 text-xs font-medium text-muted-foreground",children:t}),s?e.jsx(q,{compact:!0,className:"min-h-[160px]",icon:e.jsx(_,{className:"h-4 w-4","aria-hidden":"true"}),title:r("dashboard.charts.empty")}):e.jsx(de,{echarts:me,option:a,className:"h-[220px]",notMerge:!0,lazyUpdate:!0})]})}function mt({description:s,empty:a,emptyText:t,loading:r,option:o,title:n}){const{t:d}=p();return e.jsx(ce,{children:e.jsxs(ue,{className:"space-y-4 pt-5",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-semibold",children:n}),e.jsx("p",{className:"mt-0.5 text-xs text-muted-foreground/70",children:s})]}),r?e.jsx($,{compact:!0,className:"min-h-[220px]",label:d("common.loadingShort")}):a?e.jsx(q,{compact:!0,className:"min-h-[188px] rounded-xl border border-dashed border-border/45 bg-muted",icon:e.jsx(_,{className:"h-5 w-5","aria-hidden":"true"}),title:t??d("dashboard.charts.empty"),description:s}):e.jsx("div",{className:"pt-2",children:e.jsx(de,{echarts:me,option:o,className:"h-[36vh] min-h-[260px] max-h-[400px]",notMerge:!0,lazyUpdate:!0})})]})})}function j(s,a){return typeof window>"u"?a:getComputedStyle(document.documentElement).getPropertyValue(s).trim()||a}function xt(){const{resolved:s}=ke();return f.useMemo(()=>{const a=j("--foreground","#201e1d"),t=j("--muted-foreground","#605d5d"),r=j("--border","#d7d3d3"),o=j("--card","#ffffff");return{palette:[j("--chart-1","#ec3013"),j("--chart-2","#ae1800"),j("--chart-3","#ff9783"),j("--chart-4","#444141"),j("--chart-5","#9b9797")],success:j("--success","#444141"),warning:j("--warning","#ae1800"),error:j("--error","#dd2b0f"),axis:t,splitLine:r,base:{textStyle:{color:t,fontSize:11},grid:{left:8,right:8,top:32,bottom:4,containLabel:!0},tooltip:{backgroundColor:o,borderColor:r,textStyle:{color:a,fontSize:12}},legend:{textStyle:{color:t,fontSize:11}}}}},[s])}const pt=4;function bt(s){var t;if(!s)return 0;let a=Object.keys(s.modelRoutes??{}).length;for(const r of Object.values(s.endpointRouting??{}))a+=Object.keys((r==null?void 0:r.modelRoutes)??{}).length;for(const r of s.customEndpoints??[])a+=Object.keys(((t=r.routing)==null?void 0:t.modelRoutes)??{}).length;return a}function ft(){var Y,J,X,Z,ee,te;const{t:s}=p(),{pushToast:a}=Pe(),t=xt(),[r,o]=Ae(ze.dashboard.endpointFilter,"all"),[n,d]=f.useState(!1),l=r==="all"?void 0:r,i=A(D.dashboard.summary(r),{url:"/api/dashboard/summary",method:"GET",params:l?{endpoint:l}:void 0},{refetchInterval:Ue}),h=A(D.customEndpoints.all(),{url:"/api/custom-endpoints",method:"GET"},{refetchInterval:We}),L=Ye({level:"warn,error",maxEvents:20}),w=f.useRef(!1);f.useEffect(()=>{var x;const c=i.error!=null;c&&!w.current&&(w.current=!0,a({title:s("dashboard.toast.overviewError"),description:((x=i.error)==null?void 0:x.message)??"",variant:"error"})),c||(w.current=!1)},[i.error,a,s]);const B=f.useCallback(async()=>{await Promise.all([i.refetch(),h.refetch()])},[i,h]),R=f.useCallback(async()=>{if(!n){d(!0);try{await De.post("/api/db/compact"),await i.refetch(),a({title:s("dashboard.toast.compactSuccess.title"),description:s("dashboard.toast.compactSuccess.desc"),variant:"success"})}catch(c){const x=Oe(c);a({title:s("dashboard.toast.compactError.title"),description:x.message,variant:"error"})}finally{d(!1)}}},[n,i,a,s]),u=i.data,I=u==null?void 0:u.overview,C=f.useMemo(()=>(u==null?void 0:u.daily)??[],[u]),m=f.useMemo(()=>(u==null?void 0:u.modelStats)??[],[u]),v=u==null?void 0:u.status,xe=u==null?void 0:u.dbInfo,Q=(u==null?void 0:u.recentRequests.items)??[],k=((v==null?void 0:v.providers)??0)>0,G=Q.length>0,U=A(D.config.full(),Xe.configRequest(),{enabled:k}),V=f.useMemo(()=>bt(U.data),[U.data])>0,W=(((Y=A(D.apiKeys.all(),Je.listRequest(),{enabled:k&&V}).data)==null?void 0:Y.length)??0)>0,pe=k&&V&&W&&G,be=[k,V,W,G].filter(Boolean).length,fe=f.useMemo(()=>{const c=(u==null?void 0:u.recentErrors)??[],x=new Set;return[...L.events,...c].filter(b=>!(x.has(b.id)||(x.add(b.id),l&&b.endpoint!==l))).slice(0,10)},[L.events,u,l]),ge=r==="all"?s("dashboard.filters.endpointAll"):r==="anthropic"?s("dashboard.filters.endpointAnthropic"):r==="openai"?s("dashboard.filters.endpointOpenAI"):((Z=(X=(J=h.data)==null?void 0:J.endpoints)==null?void 0:X.find(c=>c.id===r))==null?void 0:Z.label)||r,je=m.filter(c=>c.avgTtftMs!=null&&c.avgTtftMs>0).sort((c,x)=>(c.avgTtftMs??Number.POSITIVE_INFINITY)-(x.avgTtftMs??Number.POSITIVE_INFINITY))[0],ve=i.isFetching||h.isFetching,ye=i.isPending,Ne=((ee=i.error)==null?void 0:ee.message)??null,Te=f.useMemo(()=>{const c=s("dashboard.charts.barRequests"),x=s("dashboard.charts.latencyLabel");return{...t.base,color:t.palette,tooltip:{trigger:"axis",...t.base.tooltip},legend:{data:[c,x],...t.base.legend},grid:t.base.grid,xAxis:{type:"category",data:C.map(y=>y.date.slice(5)),axisLabel:{color:t.axis},axisLine:{lineStyle:{color:t.splitLine}}},yAxis:[{type:"value",name:c,nameTextStyle:{color:t.axis},axisLabel:{color:t.axis},splitLine:{lineStyle:{color:t.splitLine}}},{type:"value",name:x,nameTextStyle:{color:t.axis},axisLabel:{color:t.axis},splitLine:{show:!1}}],series:[{name:c,type:"bar",data:C.map(y=>y.requestCount),itemStyle:{color:t.palette[0],borderRadius:[4,4,0,0]},barMaxWidth:24},{name:x,type:"line",yAxisIndex:1,smooth:!0,showSymbol:!1,data:C.map(y=>Math.round(y.avgLatencyMs)),itemStyle:{color:t.palette[3]},lineStyle:{width:2}}]}},[C,t,s]),P=f.useCallback((c,x,y)=>({...t.base,tooltip:{trigger:"axis",...t.base.tooltip},grid:{...t.base.grid,bottom:24},xAxis:{type:"category",data:m.map(b=>`${b.provider}/${b.model}`),axisLabel:{color:t.axis,rotate:28},axisLine:{lineStyle:{color:t.splitLine}}},yAxis:{type:"value",name:c,nameTextStyle:{color:t.axis},axisLabel:{color:t.axis},splitLine:{lineStyle:{color:t.splitLine}}},series:[{name:c,type:"bar",data:m.map(x),itemStyle:{color:y,borderRadius:[4,4,0,0]},barMaxWidth:32}]}),[m,t]),Se=f.useMemo(()=>P(s("dashboard.charts.ttftAxis"),c=>c.avgTtftMs??0,t.palette[2]),[P,t,s]),we=f.useMemo(()=>P(s("dashboard.charts.tpotAxis"),c=>c.avgTpotMs??0,t.palette[4]),[P,t,s]),Ce=f.useMemo(()=>{const c=s("dashboard.charts.barRequests"),x=s("dashboard.charts.lineInput"),y=s("dashboard.charts.lineOutput");return{...t.base,color:t.palette,tooltip:{trigger:"axis",...t.base.tooltip},legend:{data:[c,x,y],...t.base.legend},grid:{...t.base.grid,bottom:24},xAxis:{type:"category",data:m.map(b=>`${b.provider}/${b.model}`),axisLabel:{color:t.axis,rotate:28},axisLine:{lineStyle:{color:t.splitLine}}},yAxis:[{type:"value",name:c,nameTextStyle:{color:t.axis},axisLabel:{color:t.axis},splitLine:{lineStyle:{color:t.splitLine}}},{type:"value",name:s("dashboard.charts.axisTokens"),position:"right",nameTextStyle:{color:t.axis},axisLabel:{color:t.axis},splitLine:{show:!1}}],series:[{name:c,type:"bar",data:m.map(b=>b.requests),itemStyle:{color:t.palette[0],borderRadius:[4,4,0,0]},barMaxWidth:24},{name:x,type:"line",yAxisIndex:1,smooth:!0,showSymbol:!1,data:m.map(b=>b.inputTokens??0),itemStyle:{color:t.palette[1]},lineStyle:{width:2}},{name:y,type:"line",yAxisIndex:1,smooth:!0,showSymbol:!1,data:m.map(b=>b.outputTokens??0),itemStyle:{color:t.palette[2]},lineStyle:{width:2}}]}},[m,t,s]);return{attentionEvents:fe,compacting:n,customEndpoints:((te=h.data)==null?void 0:te.endpoints)??[],daily:C,dbInfo:xe,endpointFilter:r,fastestTtftModel:je,handleCompact:R,handleRefresh:B,bootstrapError:Ne,isBootstrapping:ye,isRefreshing:ve,liveConnected:L.connected,liveFailed:L.failed,modelRequestsOption:Ce,models:m,overview:I,recentLogs:Q,selectedEndpointLabel:ge,setEndpointFilter:o,setupComplete:pe,setupDoneCount:be,status:v,summaryPending:i.isPending,trendOption:Te,ttftOption:Se,tpotOption:we}}function $t(){var o,n;const{t:s}=p(),a=ft(),t=a.dbInfo?re(a.dbInfo.totalBytes??a.dbInfo.sizeBytes):"-",r=re((o=a.dbInfo)==null?void 0:o.memoryRssBytes);return e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx(qe,{actions:e.jsxs(e.Fragment,{children:[e.jsxs(Fe,{value:a.endpointFilter,onValueChange:a.setEndpointFilter,children:[e.jsx(Be,{className:"h-8 w-[168px]",children:e.jsx(Ve,{})}),e.jsxs(He,{children:[e.jsx(O,{value:"all",children:s("dashboard.filters.endpointAll")}),e.jsx(O,{value:"anthropic",children:s("dashboard.filters.endpointAnthropic")}),e.jsx(O,{value:"openai",children:s("dashboard.filters.endpointOpenAI")}),a.customEndpoints.map(d=>e.jsx(O,{value:d.id,children:d.label||d.id},d.id))]})]}),e.jsxs(M,{variant:"outline",size:"sm",onClick:()=>void a.handleRefresh(),disabled:a.isRefreshing,children:[e.jsx(Me,{className:_e("mr-2 h-4 w-4",a.isRefreshing&&"animate-spin"),"aria-hidden":"true"}),a.isRefreshing?s("common.actions.refreshing"):s("common.actions.refresh")]})]})}),a.isBootstrapping?e.jsx(Ze,{}):a.bootstrapError?e.jsx(q,{icon:e.jsx(Ee,{className:"h-5 w-5","aria-hidden":"true"}),tone:"danger",title:s("common.status.error"),description:a.bootstrapError,action:e.jsx(M,{variant:"outline",onClick:()=>void a.handleRefresh(),children:s("common.actions.refresh")})}):e.jsxs(e.Fragment,{children:[a.setupComplete?null:e.jsx(ct,{endpointCount:a.customEndpoints.length,providerCount:((n=a.status)==null?void 0:n.providers)??0}),e.jsx(et,{status:a.status}),e.jsx(st,{overview:a.overview}),a.setupComplete?null:e.jsx(dt,{doneCount:a.setupDoneCount,total:pt}),e.jsx(ot,{empty:!a.daily.length,loading:a.summaryPending,option:a.trendOption}),e.jsx(nt,{daily:a.daily,models:a.models}),e.jsx(it,{modelRequestsOption:a.modelRequestsOption,models:a.models,ttftOption:a.ttftOption,tpotOption:a.tpotOption}),e.jsx(lt,{compacting:a.compacting,dbInfo:a.dbInfo,dbSizeDisplay:t,memoryDisplay:r,onCompact:()=>void a.handleCompact(),status:a.status}),e.jsx(ht,{records:a.recentLogs,loading:a.summaryPending}),a.attentionEvents.length>0?e.jsx(at,{connected:a.liveConnected,failed:a.liveFailed,events:a.attentionEvents}):e.jsx(rt,{connected:a.liveConnected,failed:a.liveFailed})]})]})}export{$t as default};
@@ -1 +0,0 @@
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};