@chenpu17/cc-gw 0.9.0-beta.1 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/package.json +5 -5
  2. package/src/web/dist/assets/{About-WPCkWxkz.js → About-BSEe89Db.js} +1 -1
  3. package/src/web/dist/assets/{ApiKeys-Q-EteBox.js → ApiKeys-BSd06Z1F.js} +1 -1
  4. package/src/web/dist/assets/{ConfirmDialog-CvC_VLb2.js → ConfirmDialog-MHzJAg_R.js} +1 -1
  5. package/src/web/dist/assets/Dashboard-BTnS3Joq.js +1 -0
  6. package/src/web/dist/assets/{DialogShell-CM92wXHo.js → DialogShell-Dadn4IyM.js} +1 -1
  7. package/src/web/dist/assets/{Events-CBVp1fVz.js → Events-DbCJcwIJ.js} +1 -1
  8. package/src/web/dist/assets/{Help-M3pIEoJN.js → Help-BsB7et-K.js} +1 -1
  9. package/src/web/dist/assets/{Login-DtAkFJMT.js → Login-C8phChBf.js} +1 -1
  10. package/src/web/dist/assets/{Logs-CIPbrHMJ.js → Logs-Cj6iucOs.js} +1 -1
  11. package/src/web/dist/assets/{PageSection-N34Nu8NO.js → PageSection-B3MOBwwu.js} +1 -1
  12. package/src/web/dist/assets/{PageState-CFLrRswm.js → PageState-BfMFsTrq.js} +1 -1
  13. package/src/web/dist/assets/{PageToolbar-CWw40AFL.js → PageToolbar-BdMtFJ0X.js} +1 -1
  14. package/src/web/dist/assets/{ProvidersWorkbench-DvlPlloy.js → ProvidersWorkbench-Bb3ZnLKq.js} +1 -1
  15. package/src/web/dist/assets/Settings-DE727ml-.js +1 -0
  16. package/src/web/dist/assets/{Setup-CfD6U8Nf.js → Setup-DPWSztq9.js} +1 -1
  17. package/src/web/dist/assets/{apiKeys-CoQ69TK_.js → apiKeys-Ysiv6YG4.js} +1 -1
  18. package/src/web/dist/assets/app-ClWj0qTa.js +61 -0
  19. package/src/web/dist/assets/{badge-DpUlf_NW.js → badge-BYKFKxPI.js} +1 -1
  20. package/src/web/dist/assets/{card-D4YOc5eB.js → card-BzBD4ugM.js} +1 -1
  21. package/src/web/dist/assets/{disclosure-l5qsWhr7.js → disclosure-DtTSMZlG.js} +1 -1
  22. package/src/web/dist/assets/{gateway-Dxoj2rj4.js → gateway-D48923x2.js} +1 -1
  23. package/src/web/dist/assets/global-B_aXL20T.css +1 -0
  24. package/src/web/dist/assets/{label-DSVzZIex.js → label-D10XnuKJ.js} +1 -1
  25. package/src/web/dist/assets/{landing-DBrU8FIr.js → landing-CXAblwjd.js} +1 -1
  26. package/src/web/dist/assets/{metric-card-G1bbpbiR.js → metric-card-0Uj1WjoH.js} +1 -1
  27. package/src/web/dist/assets/package-C1LS7ceb.js +1 -0
  28. package/src/web/dist/assets/{popover-QZXvcPr8.js → popover-CVazrITd.js} +1 -1
  29. package/src/web/dist/assets/{segmented-control-13KTib6k.js → segmented-control-BDDSq6CX.js} +1 -1
  30. package/src/web/dist/assets/{select-sOwKYsgI.js → select-Csn9x4DW.js} +1 -1
  31. package/src/web/dist/assets/{shared-HT9X1BTy.js → shared-BzrM3juK.js} +1 -1
  32. package/src/web/dist/assets/{switch-7PH_rDz6.js → switch-CgcoKdbt.js} +1 -1
  33. package/src/web/dist/assets/{table-CVuTTP1s.js → table-w41b0TvK.js} +1 -1
  34. package/src/web/dist/assets/{tabs-UWyz9J_W.js → tabs-BkwWF2Pt.js} +1 -1
  35. package/src/web/dist/assets/{useAppMutation-DbIs5qvT.js → useAppMutation-B4G9utID.js} +1 -1
  36. package/src/web/dist/assets/{useProviderForm-BiVzWP3H.js → useProviderForm-Bh-rUNZP.js} +1 -1
  37. package/src/web/dist/assets/{utils-B_Q3Hhgb.js → utils-CERcr-xC.js} +1 -1
  38. package/src/web/dist/index.html +3 -3
  39. package/src/web/dist/landing.html +4 -4
  40. package/src/web/dist/assets/Dashboard-Q99L2W8N.js +0 -1
  41. package/src/web/dist/assets/Settings-CNI4qHrl.js +0 -1
  42. package/src/web/dist/assets/app-czRBzLXv.js +0 -61
  43. package/src/web/dist/assets/global-CIVH6GQV.css +0 -1
  44. package/src/web/dist/assets/package-BXeeAB6b.js +0 -1
  45. /package/src/web/dist/assets/{global-BCehxTGJ.js → global-CHsQhrWl.js} +0 -0
@@ -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-czRBzLXv.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-CoQ69TK_.js";import{g as Xe}from"./gateway-Dxoj2rj4.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-CvC_VLb2.js";import{P as Ve}from"./PageState-CFLrRswm.js";import{P as bt}from"./PageToolbar-CWw40AFL.js";import{C as k,a as L}from"./card-D4YOc5eB.js";import{B as O,r as Ke,i as vt,d as yt,a as jt,c as De,q as Z}from"./app-czRBzLXv.js";import{B as V}from"./badge-DpUlf_NW.js";import{L as f,I as j}from"./label-DSVzZIex.js";import{S as B}from"./switch-7PH_rDz6.js";import{S as Nt,a as wt,b as Ct,c as Pt,d as kt}from"./select-sOwKYsgI.js";import{c as E}from"./global-BCehxTGJ.js";import{u as P}from"./i18n-PeX9kBVO.js";import{u as ee}from"./useAppMutation-DbIs5qvT.js";import{g as qe}from"./gateway-Dxoj2rj4.js";import{c as St}from"./clipboard-BnAnBk_-.js";import"./DialogShell-CM92wXHo.js";import"./radix-Bux_1C5J.js";import"./query-DZF7K6hv.js";import"./router-BoBrmro7.js";const Rt=[{value:"fatal",labelKey:"fatal"},{value:"error",labelKey:"error"},{value:"warn",labelKey:"warn"},{value:"info",labelKey:"info"},{value:"debug",labelKey:"debug"},{value:"trace",labelKey:"trace"}],oe=[{id:"section-basics",labelKey:"settings.sections.basics"},{id:"section-protocol",labelKey:"settings.sections.protocol"},{id:"section-security",labelKey:"settings.sections.security"},{id:"section-config-file",labelKey:"settings.sections.configFile"},{id:"section-cleanup",labelKey:"settings.sections.cleanup"}];function te(t){var o,m,l,i,a,p,y,A,T,u,M;const s=t.storePayloads,r=N=>typeof N=="boolean"?N:typeof s=="boolean"?s:!0;return{port:String(t.port??((o=t.http)==null?void 0:o.port)??""),host:t.host??((m=t.http)==null?void 0:m.host)??"127.0.0.1",logRetentionDays:String(t.logRetentionDays??30),logExportTimeoutSeconds:String(t.logExportTimeoutSeconds??60),storeRequestPayloads:r(t.storeRequestPayloads),storeResponsePayloads:r(t.storeResponsePayloads),logLevel:t.logLevel??"info",bodyLimitMb:(()=>{const N=t.bodyLimit;return typeof N=="number"&&Number.isFinite(N)&&N>0?String(Math.max(1,Math.round(N/(1024*1024)))):"10"})(),enableRoutingFallback:t.enableRoutingFallback===!0,httpEnabled:((l=t.http)==null?void 0:l.enabled)!==!1,httpPort:String(((i=t.http)==null?void 0:i.port)??t.port??4100),httpHost:((a=t.http)==null?void 0:a.host)??t.host??"127.0.0.1",httpsEnabled:((p=t.https)==null?void 0:p.enabled)===!0,httpsPort:String(((y=t.https)==null?void 0:y.port)??4443),httpsHost:((A=t.https)==null?void 0:A.host)??t.host??"127.0.0.1",httpsKeyPath:((T=t.https)==null?void 0:T.keyPath)??"",httpsCertPath:((u=t.https)==null?void 0:u.certPath)??"",httpsCaPath:((M=t.https)==null?void 0:M.caPath)??""}}function se(t){return{enabled:t.enabled,username:t.username??"",password:"",confirmPassword:""}}function Et({activeSection:t,onSelectSection:s}){const{t:r}=P();return e.jsxs(e.Fragment,{children:[e.jsx("nav",{className:"hidden xl:block",children:e.jsxs(k,{className:"sticky top-20 p-3.5",children:[e.jsx("p",{className:"mb-2.5 px-2 text-[10px] font-semibold uppercase tracking-wider text-muted-foreground",children:r("settings.sections.jump")}),e.jsx("div",{className:"space-y-1.5",children:oe.map((o,m)=>e.jsxs("button",{type:"button",onClick:()=>s(o.id),className:E("flex w-full items-center gap-2.5 rounded-lg px-3 py-2 text-left text-sm font-semibold transition-all duration-200",t===o.id?"bg-secondary text-foreground":"text-muted-foreground hover:text-foreground"),children:[e.jsx("span",{className:E("flex h-7 w-7 items-center justify-center rounded-lg text-[11px] font-semibold",t===o.id?"bg-primary text-primary-foreground":"bg-secondary text-muted-foreground"),children:m+1}),e.jsx("span",{children:r(o.labelKey)})]},o.id))})]})}),e.jsx("div",{className:"xl:hidden",children:e.jsx("div",{className:"overflow-x-auto pb-1",children:e.jsx("div",{className:"flex w-max gap-2 px-1",children:oe.map(o=>e.jsx("button",{type:"button",onClick:()=>s(o.id),className:E("rounded-lg px-4 py-2 text-xs font-semibold transition-all duration-150",t===o.id?"bg-secondary text-foreground font-medium":"text-muted-foreground hover:text-foreground hover:bg-secondary/50"),children:r(o.labelKey)},o.id))})})})]})}function Lt({defaultsSummary:t,errors:s,form:r,onInputChange:o,onSetForm:m,sectionRef:l}){const{t:i}=P();return e.jsx(k,{id:"section-basics",ref:l,className:"bg-card shadow-[var(--surface-shadow)]",children:e.jsxs(L,{className:"pt-6",children:[e.jsxs("div",{className:"mb-4 flex flex-col gap-3 lg:flex-row lg:items-start lg:justify-between",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold",children:i("settings.sections.basics")}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:i("settings.description")})]}),e.jsxs("div",{className:"grid gap-2 sm:grid-cols-3",children:[e.jsx(ae,{label:i("settings.fields.retention"),value:r.logRetentionDays}),e.jsx(ae,{label:i("settings.fields.logExportTimeout"),value:`${r.logExportTimeoutSeconds}s`}),e.jsx(ae,{label:i("settings.fields.bodyLimit"),value:`${r.bodyLimitMb} MB`})]})]}),e.jsxs("div",{className:"grid gap-5 md:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(f,{children:i("settings.fields.port")}),e.jsx(j,{type:"number",min:1,max:65535,value:r.port,onChange:a=>o("port")(a.target.value),"aria-invalid":!!s.port}),s.port?e.jsx("p",{className:"text-xs text-destructive",children:s.port}):null]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(f,{children:i("settings.fields.host")}),e.jsx(j,{value:r.host,onChange:a=>o("host")(a.target.value),placeholder:i("settings.fields.hostPlaceholder")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(f,{children:i("settings.fields.retention")}),e.jsx(j,{type:"number",min:1,max:365,value:r.logRetentionDays,onChange:a=>o("logRetentionDays")(a.target.value),"aria-invalid":!!s.logRetentionDays}),s.logRetentionDays?e.jsx("p",{className:"text-xs text-destructive",children:s.logRetentionDays}):null]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(f,{children:i("settings.fields.logExportTimeout")}),e.jsx(j,{type:"number",min:5,max:600,value:r.logExportTimeoutSeconds,onChange:a=>o("logExportTimeoutSeconds")(a.target.value),"aria-invalid":!!s.logExportTimeoutSeconds}),e.jsx("p",{className:"text-xs text-muted-foreground",children:i("settings.fields.logExportTimeoutHint")}),s.logExportTimeoutSeconds?e.jsx("p",{className:"text-xs text-destructive",children:s.logExportTimeoutSeconds}):null]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(f,{children:i("settings.fields.bodyLimit")}),e.jsx(j,{type:"number",min:1,max:2048,value:r.bodyLimitMb,onChange:a=>o("bodyLimitMb")(a.target.value),"aria-invalid":!!s.bodyLimitMb}),e.jsx("p",{className:"text-xs text-muted-foreground",children:i("settings.fields.bodyLimitHint")}),s.bodyLimitMb?e.jsx("p",{className:"text-xs text-destructive",children:s.bodyLimitMb}):null]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(f,{children:i("settings.fields.logLevel")}),e.jsxs(Nt,{value:r.logLevel,onValueChange:a=>m(p=>({...p,logLevel:a})),children:[e.jsx(wt,{children:e.jsx(Ct,{})}),e.jsx(Pt,{children:Rt.map(a=>e.jsx(kt,{value:a.value,children:i(`settings.fields.logLevelOption.${a.labelKey}`)},a.value))})]})]}),e.jsxs("div",{className:"grid gap-4 md:col-span-2 sm:grid-cols-2",children:[e.jsx(ne,{label:i("settings.fields.storeRequestPayloads"),hint:i("settings.fields.storeRequestPayloadsHint"),checked:r.storeRequestPayloads,onCheckedChange:a=>m(p=>({...p,storeRequestPayloads:a}))}),e.jsx(ne,{label:i("settings.fields.storeResponsePayloads"),hint:i("settings.fields.storeResponsePayloadsHint"),checked:r.storeResponsePayloads,onCheckedChange:a=>m(p=>({...p,storeResponsePayloads:a}))}),e.jsx(ne,{label:i("settings.fields.enableRoutingFallback"),hint:i("settings.fields.enableRoutingFallbackHint"),checked:r.enableRoutingFallback,onCheckedChange:a=>m(p=>({...p,enableRoutingFallback:a}))})]}),e.jsxs("div",{className:"rounded-xl bg-secondary px-4 py-5 md:col-span-2",children:[e.jsx(f,{className:"text-xs uppercase tracking-wide text-muted-foreground",children:i("settings.fields.defaults")}),e.jsx("p",{className:"mt-2 text-sm",children:t??i("settings.defaults.none")})]})]})]})})}function At({errors:t,form:s,onSetForm:r,protocolChangesPending:o,sectionRef:m}){const{t:l}=P();return e.jsx(k,{id:"section-protocol",ref:m,className:"bg-card shadow-[var(--surface-shadow)]",children:e.jsxs(L,{className:"space-y-6 pt-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold",children:l("settings.sections.protocol")}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:l("settings.protocol.description")})]}),o?e.jsx("div",{className:"rounded-xl bg-warning-bg ring-1 ring-warning/30 p-4",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(Y,{className:"mt-0.5 h-5 w-5 flex-shrink-0 text-warning"}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm font-medium text-foreground",children:l("settings.protocol.restartWarning")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:l("settings.protocol.restartHint")}),e.jsx("code",{className:"block rounded-lg border border-border bg-secondary px-3 py-2 text-xs font-mono text-foreground",children:"cc-gw restart --daemon"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:l("settings.protocol.restartTip")})]})]})}):null,t.protocol?e.jsxs("div",{className:"rounded-xl bg-destructive/10 ring-1 ring-destructive/30 p-4 text-sm text-destructive",children:[e.jsx(Y,{className:"mr-2 inline h-4 w-4"}),t.protocol]}):null,e.jsxs("div",{className:"rounded-xl bg-secondary p-5",children:[e.jsxs("div",{className:"mb-4 flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(f,{className:"text-sm font-medium text-foreground",children:l("settings.protocol.http.enable")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:l("settings.protocol.http.hint")})]}),e.jsx(B,{checked:s.httpEnabled,onCheckedChange:i=>r(a=>({...a,httpEnabled:i}))})]}),s.httpEnabled?e.jsxs("div",{className:"mt-4 grid gap-4 border-t border-border pt-4 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(f,{children:l("settings.protocol.http.port")}),e.jsx(j,{type:"number",min:1,max:65535,value:s.httpPort,onChange:i=>r(a=>({...a,httpPort:i.target.value})),"aria-invalid":!!t.httpPort}),t.httpPort?e.jsx("p",{className:"text-xs text-destructive",children:t.httpPort}):null]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(f,{children:l("settings.protocol.http.host")}),e.jsx(j,{value:s.httpHost,onChange:i=>r(a=>({...a,httpHost:i.target.value})),placeholder:"127.0.0.1"})]})]}):null]}),e.jsxs("div",{className:"rounded-xl bg-secondary p-5",children:[e.jsxs("div",{className:"mb-4 flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(f,{className:"text-sm font-medium text-foreground",children:l("settings.protocol.https.enable")}),e.jsx(xt,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:l("settings.protocol.https.hint")})]}),e.jsx(B,{checked:s.httpsEnabled,onCheckedChange:i=>r(a=>({...a,httpsEnabled:i}))})]}),s.httpsEnabled?e.jsxs("div",{className:"mt-4 space-y-4 border-t border-border pt-4",children:[e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(f,{children:l("settings.protocol.https.port")}),e.jsx(j,{type:"number",min:1,max:65535,value:s.httpsPort,onChange:i=>r(a=>({...a,httpsPort:i.target.value})),"aria-invalid":!!t.httpsPort}),t.httpsPort?e.jsx("p",{className:"text-xs text-destructive",children:t.httpsPort}):null]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(f,{children:l("settings.protocol.https.host")}),e.jsx(j,{value:s.httpsHost,onChange:i=>r(a=>({...a,httpsHost:i.target.value})),placeholder:"127.0.0.1"})]})]}),e.jsx(le,{label:l("settings.protocol.https.keyPath"),value:s.httpsKeyPath,onChange:i=>r(a=>({...a,httpsKeyPath:i})),placeholder:"~/.cc-gw/certs/key.pem"}),e.jsx(le,{label:l("settings.protocol.https.certPath"),value:s.httpsCertPath,onChange:i=>r(a=>({...a,httpsCertPath:i})),placeholder:"~/.cc-gw/certs/cert.pem"}),e.jsx(le,{label:l("settings.protocol.https.caPath"),value:s.httpsCaPath,onChange:i=>r(a=>({...a,httpsCaPath:i})),placeholder:"留空则不使用"}),e.jsx("div",{className:"rounded-xl bg-warning-bg ring-1 ring-warning/30 p-4",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(Y,{className:"mt-0.5 h-5 w-5 flex-shrink-0 text-warning"}),e.jsxs("div",{className:"flex-1 space-y-1.5",children:[e.jsx("p",{className:"text-sm font-medium text-warning",children:l("settings.protocol.https.warning")}),e.jsx("p",{className:"text-xs leading-relaxed text-warning",children:l("settings.protocol.https.tip")})]})]})})]}):null]})]})})}function Tt({authErrors:t,authForm:s,authLoading:r,authSettings:o,needsPassword:m,onSetAuthForm:l,sectionRef:i}){const{t:a}=P();return e.jsx(k,{id:"section-security",ref:i,className:"bg-card shadow-[var(--surface-shadow)]",children:e.jsxs(L,{className:"space-y-5 pt-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold",children:a("settings.sections.security")}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:a("settings.auth.description")})]}),r&&!o?e.jsx(Ve,{compact:!0,label:a("common.loading")}):e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex flex-col gap-4 rounded-xl bg-secondary p-4 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(f,{className:"text-sm font-medium",children:a("settings.auth.enable")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a("settings.auth.enableHint")}),e.jsxs("div",{className:"flex flex-wrap gap-2 text-xs font-medium text-muted-foreground",children:[e.jsx("span",{className:"rounded-lg bg-secondary px-3 py-1 text-[11px] tracking-[0.08em]",children:"/ui"}),e.jsx("span",{className:"rounded-lg bg-secondary px-3 py-1 text-[11px] tracking-[0.08em]",children:"/api/*"}),e.jsx("span",{className:"rounded-lg bg-secondary px-3 py-1 text-[11px] tracking-[0.08em]",children:"Cookie Session"})]})]}),e.jsxs("div",{className:"flex items-center gap-3 self-start sm:self-auto",children:[e.jsx(V,{variant:s.enabled?"success":"secondary",children:s.enabled?a("settings.auth.statusEnabled"):a("settings.auth.statusDisabled")}),e.jsx(B,{checked:s.enabled,onCheckedChange:p=>l(y=>({...y,enabled:p}))})]})]}),e.jsxs("div",{className:"grid gap-6 lg:grid-cols-[minmax(0,1fr)_minmax(0,0.85fr)]",children:[e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2 sm:col-span-2",children:[e.jsx(f,{children:a("settings.auth.username")}),e.jsx(j,{value:s.username,onChange:p=>l(y=>({...y,username:p.target.value})),placeholder:a("settings.auth.usernamePlaceholder")}),t.username?e.jsx("p",{className:"text-xs text-destructive",children:t.username}):null]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(f,{children:a("settings.auth.password")}),e.jsx(j,{type:"password",value:s.password,disabled:!s.enabled,onChange:p=>l(y=>({...y,password:p.target.value})),placeholder:a("settings.auth.passwordPlaceholder")}),t.password?e.jsx("p",{className:"text-xs text-destructive",children:t.password}):e.jsx("p",{className:"text-xs text-muted-foreground",children:a(m?"settings.auth.passwordHintRequired":"settings.auth.passwordHintOptional")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(f,{children:a("settings.auth.confirmPassword")}),e.jsx(j,{type:"password",value:s.confirmPassword,disabled:!s.enabled,onChange:p=>l(y=>({...y,confirmPassword:p.target.value})),placeholder:a("settings.auth.confirmPasswordPlaceholder")}),t.confirmPassword?e.jsx("p",{className:"text-xs text-destructive",children:t.confirmPassword}):null]})]}),e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"rounded-xl bg-secondary p-4",children:[e.jsx("p",{className:"text-[10px] font-semibold uppercase tracking-[0.34em] text-muted-foreground",children:a("settings.auth.status")}),e.jsx("p",{className:"mt-2 text-base font-semibold",children:o!=null&&o.enabled?a("settings.auth.statusEnabled"):a("settings.auth.statusDisabled")}),o!=null&&o.username?e.jsxs("div",{className:"mt-3 rounded-lg bg-accent px-3 py-2 text-xs font-medium text-primary",children:[a("settings.auth.username"),": ",o.username]}):null]}),e.jsx("div",{className:"rounded-xl bg-secondary px-4 py-3 text-xs text-muted-foreground",children:a(m?"settings.auth.passwordHintRequired":"settings.auth.passwordHintOptional")})]})]})]})]})})}function Mt({configPath:t,onCopyPath:s,sectionRef:r}){const{t:o}=P();return e.jsx(k,{id:"section-config-file",ref:r,className:"bg-card shadow-[var(--surface-shadow)]",children:e.jsxs(L,{className:"space-y-3 pt-6",children:[e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold",children:o("settings.sections.configFile")}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:o("settings.file.description")})]}),e.jsxs(O,{variant:"outline",size:"sm",onClick:s,className:"w-full sm:w-auto",children:[e.jsx(ft,{className:"mr-2 h-4 w-4"}),o("common.actions.copy")]})]}),e.jsx("code",{className:"block break-all rounded-lg bg-secondary px-4 py-3 text-xs font-mono text-muted-foreground",children:t||o("settings.file.unknown")}),e.jsx("div",{className:"rounded-lg bg-secondary px-4 py-3 text-xs text-muted-foreground",children:o("help.note")})]})})}function Ot({cleaning:t,clearingAll:s,onOpenCleanup:r,onOpenClearAll:o,sectionRef:m}){const{t:l}=P();return e.jsx(k,{id:"section-cleanup",ref:m,className:"bg-card shadow-[var(--surface-shadow)]",children:e.jsxs(L,{className:"space-y-4 pt-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold",children:l("settings.sections.cleanup")}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:l("settings.cleanup.description")})]}),e.jsx("div",{className:"rounded-lg bg-secondary px-4 py-3 text-xs text-muted-foreground",children:l("settings.cleanup.confirmCleanup")}),e.jsxs("div",{className:"grid gap-4 lg:grid-cols-2",children:[e.jsx("div",{className:"rounded-xl border border-warning/30 bg-warning-bg p-5",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx(V,{variant:"warning",children:l("settings.cleanup.softLabel")}),e.jsx("p",{className:"text-sm font-medium",children:l("settings.cleanup.softTitle")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:l("settings.cleanup.softDescription")}),e.jsx(O,{variant:"outline",onClick:r,disabled:t,className:"w-full sm:w-auto",children:l(t?"common.actions.cleaning":"common.actions.cleanup")})]})}),e.jsx("div",{className:"rounded-xl border border-destructive/30 bg-destructive/10 p-5 text-destructive",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx(V,{variant:"outline",className:"border-destructive/40 bg-destructive/10 text-destructive",children:l("settings.cleanup.hardLabel")}),e.jsx("p",{className:"text-sm font-medium",children:l("settings.cleanup.hardTitle")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:l("settings.cleanup.clearAllWarning")}),e.jsx(O,{variant:"destructive",onClick:o,disabled:s,className:"w-full sm:w-auto",children:l(s?"settings.cleanup.clearingAll":"settings.cleanup.clearAll")})]})})]})]})})}function Ft({dirtyCount:t,protocolChangesPending:s,onReset:r,onSave:o,saving:m}){const{t:l}=P();return t===0?null:e.jsxs("div",{className:"sticky bottom-4 z-20 flex flex-col gap-3 rounded-xl bg-card border border-border px-6 py-5 shadow-[var(--surface-shadow-lg)] md:flex-row md:items-center md:justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(V,{variant:"secondary",children:l("settings.overview.unsavedCount",{count:t})}),e.jsx("p",{className:"text-sm text-muted-foreground",children:l(s?"settings.toast.protocolRestartRequired":"modelManagement.actions.footerDirtyHint")})]}),e.jsxs("div",{className:"grid gap-2 sm:grid-cols-2 lg:flex lg:flex-wrap lg:items-center",children:[e.jsx(O,{variant:"outline",onClick:r,disabled:m,className:"w-full lg:w-auto",children:l("common.actions.reset")}),e.jsx(O,{onClick:o,disabled:m,className:"w-full lg:w-auto",children:l(m?"common.actions.saving":"common.actions.save")})]})]})}function ae({label:t,value:s}){return e.jsxs("div",{className:"rounded-lg bg-secondary px-3 py-2 text-center",children:[e.jsx("p",{className:"text-[10px] font-semibold uppercase tracking-[0.3em] text-muted-foreground",children:t}),e.jsx("p",{className:"mt-1 text-sm font-semibold text-foreground",children:s})]})}function ne({checked:t,className:s,hint:r,hintClassName:o,label:m,labelClassName:l,onCheckedChange:i}){return e.jsxs("div",{className:E("flex flex-col gap-3 rounded-xl bg-secondary p-4 sm:flex-row sm:items-center sm:justify-between",s),children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(f,{className:E("text-sm font-semibold text-foreground",l),children:m}),e.jsx("p",{className:E("text-xs text-muted-foreground",o),children:r})]}),e.jsx(B,{checked:t,onCheckedChange:i,className:"self-start sm:self-auto"})]})}function le({label:t,onChange:s,placeholder:r,value:o}){return e.jsxs("div",{className:"space-y-2",children:[e.jsx(f,{children:t}),e.jsx(j,{value:o,onChange:m=>s(m.target.value),placeholder:r,className:"font-mono text-xs"})]})}const q={authStatusRequest(){return{url:"/api/auth/web",method:"GET"}},saveWebAuth:async t=>vt(yt.post("/api/auth/web",t)),cleanupLogs:async()=>Ke({url:"/api/logs/cleanup",method:"POST"}),clearLogs:async()=>Ke({url:"/api/logs/clear",method:"POST"})};function Ht(){const{t}=P(),{pushToast:s}=jt(),[r,o]=d.useState(oe[0].id),m=d.useRef(new Map),l=d.useCallback(n=>{const h=m.current.get(n);h&&h.scrollIntoView({behavior:"smooth",block:"start"})},[]),i=d.useCallback(n=>h=>{h?m.current.set(n,h):m.current.delete(n)},[]),a=De(Z.config.info(),qe.configInfoRequest()),p=De(Z.auth.web(),q.authStatusRequest()),y=ee({mutationFn:q.saveWebAuth,successToast:()=>({title:t("settings.auth.toast.success")}),errorToast:n=>({title:t("settings.auth.toast.failure",{message:n.message})}),invalidateKeys:[Z.auth.web()]}),A=ee({mutationFn:q.cleanupLogs,successToast:n=>({title:n.deleted>0?t("settings.toast.cleanupSuccess",{count:n.deleted}):t("settings.toast.cleanupNone")}),errorToast:n=>({title:t("settings.toast.cleanupFailure",{message:n.message})}),invalidateKeys:[["logs"],["dashboard"],["db"]]}),T=ee({mutationFn:q.clearLogs,successToast:n=>({title:t("settings.toast.clearAllSuccess",{logs:n.deleted,metrics:n.metricsCleared})}),errorToast:n=>({title:t("settings.toast.clearAllFailure",{message:n.message})}),invalidateKeys:[["logs"],["stats"],["dashboard"],["db"]]}),[u,M]=d.useState(null),[N,Be]=d.useState(""),[c,F]=d.useState({port:"",host:"",logRetentionDays:"",logExportTimeoutSeconds:"60",storeRequestPayloads:!0,storeResponsePayloads:!0,logLevel:"info",bodyLimitMb:"10",enableRoutingFallback:!1,httpEnabled:!0,httpPort:"4100",httpHost:"127.0.0.1",httpsEnabled:!1,httpsPort:"4443",httpsHost:"127.0.0.1",httpsKeyPath:"",httpsCertPath:"",httpsCaPath:""}),[Ie,I]=d.useState({}),[We,ie]=d.useState(!1),[Je,re]=d.useState(!1),[Qe,ce]=d.useState(!1),[_e,ze]=d.useState(!1),[Ge,$e]=d.useState(!1),[b,de]=d.useState(null),[g,H]=d.useState({enabled:!1,username:"",password:"",confirmPassword:""}),[Ue,K]=d.useState({}),[Xe,ue]=d.useState(!1),Ye=d.useMemo(()=>{if(!(u!=null&&u.defaults))return null;const n=[];return u.defaults.completion&&n.push(t("settings.defaults.completion",{model:u.defaults.completion})),u.defaults.reasoning&&n.push(t("settings.defaults.reasoning",{model:u.defaults.reasoning})),u.defaults.background&&n.push(t("settings.defaults.background",{model:u.defaults.background})),n.length>0?n.join(" | "):t("settings.defaults.none")},[u,t]),Ze=d.useMemo(()=>c.httpEnabled&&c.httpsEnabled?t("settings.overview.values.httpAndHttps"):c.httpsEnabled?t("settings.overview.values.httpsOnly"):t("settings.overview.values.httpOnly"),[c.httpEnabled,c.httpsEnabled,t]),et=d.useMemo(()=>g.enabled?b!=null&&b.hasPassword?g.username.trim()!==(b.username??""):!0:!1,[g.enabled,g.username,b]),S=d.useMemo(()=>u?te(u):null,[u]),W=d.useMemo(()=>S?JSON.stringify(c)!==JSON.stringify(S):!1,[c,S]),J=d.useMemo(()=>b?se(b):null,[b]),Q=d.useMemo(()=>J?JSON.stringify(g)!==JSON.stringify(J):!1,[g,J]),tt=d.useMemo(()=>S?["httpEnabled","httpPort","httpHost","httpsEnabled","httpsPort","httpsHost","httpsKeyPath","httpsCertPath","httpsCaPath","port","host"].some(h=>c[h]!==S[h]):!1,[c,S]);d.useEffect(()=>{a.data&&(M(a.data.config),Be(a.data.path),F(te(a.data.config)))},[a.data]),d.useEffect(()=>{p.data&&(de(p.data),H(se(p.data)),K({}))},[p.data]),d.useEffect(()=>{!a.isError||!a.error||s({title:t("settings.toast.loadFailure",{message:a.error.message}),variant:"error"})},[a.error,a.isError,s,t]),d.useEffect(()=>{!p.isError||!p.error||s({title:t("settings.toast.authLoadFailure",{message:p.error.message}),variant:"error"})},[p.error,p.isError,s,t]);const st=d.useCallback(n=>h=>{F(v=>({...v,[n]:h}))},[]),pe=d.useCallback(()=>{const n={};if(!c.httpEnabled&&!c.httpsEnabled&&(n.protocol=t("settings.validation.protocolRequired")),c.httpEnabled){const C=Number(c.httpPort);(!Number.isFinite(C)||C<1||C>65535)&&(n.httpPort=t("settings.validation.httpPort"))}if(c.httpsEnabled){const C=Number(c.httpsPort);(!Number.isFinite(C)||C<1||C>65535)&&(n.httpsPort=t("settings.validation.httpsPort")),(!c.httpsKeyPath||!c.httpsCertPath)&&(n.protocol=t("settings.validation.httpsCertificate"))}const h=Number(c.port);(!Number.isFinite(h)||h<1||h>65535)&&(n.port=t("settings.validation.port"));const v=Number(c.logRetentionDays);(!Number.isFinite(v)||v<1||v>365)&&(n.logRetentionDays=t("settings.validation.retention"));const w=Number(c.logExportTimeoutSeconds);(!Number.isFinite(w)||w<5||w>600)&&(n.logExportTimeoutSeconds=t("settings.validation.logExportTimeout"));const R=Number(c.bodyLimitMb);return(!Number.isFinite(R)||R<1||R>2048)&&(n.bodyLimitMb=t("settings.validation.bodyLimit")),I(n),Object.keys(n).length===0},[c,t]),me=d.useCallback(()=>{const n={},h=g.username.trim(),v=b?h!==(b.username??""):!0,w=g.enabled&&(!(b!=null&&b.hasPassword)||v);return g.enabled&&!h&&(n.username=t("settings.auth.validation.username")),g.password&&g.password.length<6&&(n.password=t("settings.auth.validation.minLength")),w&&!g.password&&(n.password=t("settings.auth.validation.passwordRequired")),(g.password||g.confirmPassword)&&g.password!==g.confirmPassword&&(n.confirmPassword=t("settings.auth.validation.confirmMismatch")),K(n),Object.keys(n).length===0},[g,b,t]),_=d.useCallback(async()=>{var n,h,v,w,R,C,he,ge,xe,fe,be,ve,ye,je,Ne,we,Ce,Pe,ke,Se,Re,Ee,Le,Ae,Te,Me;if(!u){s({title:t("settings.toast.loadFailure",{message:t("settings.toast.missingConfig")}),variant:"error"});return}if(pe()){ie(!0);try{const D=Number(c.port),rt=Number(c.logRetentionDays),ct=Number(c.logExportTimeoutSeconds),dt=Number(c.bodyLimitMb),x={...u,http:{enabled:c.httpEnabled,port:Number(c.httpPort),host:c.httpHost.trim()||"127.0.0.1"},https:{enabled:c.httpsEnabled,port:Number(c.httpsPort),host:c.httpsHost.trim()||"127.0.0.1",keyPath:c.httpsKeyPath.trim(),certPath:c.httpsCertPath.trim(),caPath:c.httpsCaPath.trim()||void 0},port:D,host:c.host.trim()||void 0,logRetentionDays:rt,logExportTimeoutSeconds:Math.min(Math.max(Math.round(ct),5),600),storeRequestPayloads:c.storeRequestPayloads,storeResponsePayloads:c.storeResponsePayloads,logLevel:c.logLevel,bodyLimit:Math.max(1,Math.floor(dt*1024*1024)),enableRoutingFallback:c.enableRoutingFallback};delete x.requestLogging,delete x.responseLogging;const Oe={...x};delete Oe.webAuth,await qe.saveConfig(Oe),M({...x,webAuth:u.webAuth});const Fe=X=>(X==null?void 0:X.trim())||void 0,ut=u.port??((n=u.http)==null?void 0:n.port)??4100,pt=x.port??((h=x.http)==null?void 0:h.port)??4100,mt=((v=u.host)==null?void 0:v.trim())||((R=(w=u.http)==null?void 0:w.host)==null?void 0:R.trim())||"127.0.0.1",ht=((C=x.host)==null?void 0:C.trim())||((ge=(he=x.http)==null?void 0:he.host)==null?void 0:ge.trim())||"127.0.0.1",gt=ut!==pt||mt!==ht||((xe=u.http)==null?void 0:xe.enabled)!==((fe=x.http)==null?void 0:fe.enabled)||((be=u.http)==null?void 0:be.port)!==((ve=x.http)==null?void 0:ve.port)||(((ye=u.http)==null?void 0:ye.host)??u.host??"127.0.0.1")!==(((je=x.http)==null?void 0:je.host)??x.host??"127.0.0.1")||((Ne=u.https)==null?void 0:Ne.enabled)!==((we=x.https)==null?void 0:we.enabled)||((Ce=u.https)==null?void 0:Ce.port)!==((Pe=x.https)==null?void 0:Pe.port)||(((ke=u.https)==null?void 0:ke.host)??u.host??"127.0.0.1")!==(((Se=x.https)==null?void 0:Se.host)??x.host??"127.0.0.1")||((Re=u.https)==null?void 0:Re.keyPath)!==((Ee=x.https)==null?void 0:Ee.keyPath)||((Le=u.https)==null?void 0:Le.certPath)!==((Ae=x.https)==null?void 0:Ae.certPath)||Fe((Te=u.https)==null?void 0:Te.caPath)!==Fe((Me=x.https)==null?void 0:Me.caPath);s({title:t(gt?"settings.toast.protocolRestartRequired":"settings.toast.saveSuccess"),variant:"success"}),a.refetch()}catch(D){s({title:t("settings.toast.saveFailure",{message:D instanceof Error?D.message:"unknown"}),variant:"error"})}finally{ie(!1)}}},[u,a,c,s,t,pe]),z=d.useCallback(()=>{u&&(F(te(u)),I({}))},[u]),G=d.useCallback(async()=>{if(me()){ue(!0);try{const n={enabled:g.enabled,username:g.username.trim()||void 0};g.password&&(n.password=g.password);const h=await y.mutateAsync(n);h.auth&&(de(h.auth),H({enabled:h.auth.enabled,username:h.auth.username??"",password:"",confirmPassword:""}),K({})),p.refetch()}catch{}finally{ue(!1)}}},[g,p,y,me]),$=d.useCallback(()=>{b&&(H(se(b)),K({}))},[b]),at=d.useCallback(async()=>{W&&await _(),Q&&await G()},[G,_,Q,W]),nt=d.useCallback(()=>{z(),$()},[$,z]),lt=d.useCallback(async()=>{if(!N){s({title:t("settings.toast.copyFailure",{message:t("settings.file.unknown")}),variant:"error"});return}try{await St(N),s({title:t("settings.toast.copySuccess"),variant:"success"})}catch(n){s({title:t("settings.toast.copyFailure",{message:n instanceof Error?n.message:"unknown"}),variant:"error"})}},[N,s,t]),ot=d.useCallback(async()=>{re(!0);try{await A.mutateAsync()}catch{}finally{re(!1)}},[A]),it=d.useCallback(async()=>{ce(!0);try{await T.mutateAsync()}catch{}finally{ce(!1)}},[T]),U=a.isPending||!u&&a.isFetching;return d.useEffect(()=>{if(U)return;const n=Array.from(m.current.values());if(n.length===0)return;const h=new IntersectionObserver(v=>{for(const w of v)if(w.isIntersecting){o(w.target.id);break}},{rootMargin:"-80px 0px -60% 0px",threshold:0});for(const v of n)h.observe(v);return()=>h.disconnect()},[U]),{activeSection:r,authErrors:Ue,authForm:g,authQuery:p,authSettings:b,clearingAll:Qe,cleaning:Je,config:u,configPath:N,configQuery:a,confirmCleanupOpen:_e,confirmClearAllOpen:Ge,defaultsSummary:Ye,errors:Ie,form:c,handleAuthReset:$,handleAuthSave:G,handleCleanupLogs:ot,handleClearAllLogs:it,handleCopyPath:lt,handleInputChange:st,handleReset:z,handleResetAll:nt,handleSave:_,handleSaveAll:at,handleSectionClick:l,isAuthDirty:Q,isConfigDirty:W,isLoading:U,needsPassword:et,protocolSummaryLabel:Ze,protocolChangesPending:tt,saving:We,savingAuth:Xe,sectionRefs:m,setAuthForm:H,setConfirmCleanupOpen:ze,setConfirmClearAllOpen:$e,setErrors:I,setForm:F,setSectionRef:i,t}}function ss(){const{t}=P(),s=Ht(),r=Number(s.isConfigDirty)+Number(s.isAuthDirty);return e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx(bt,{info:r>0?e.jsx("span",{className:"rounded-lg bg-warning-bg px-2.5 py-1 text-xs font-medium text-warning",children:t("settings.overview.unsavedCount",{count:r})}):null,status:s.config?e.jsx("span",{className:"text-xs text-muted-foreground",children:s.protocolChangesPending?t("settings.protocol.restartWarning"):t("common.status.success")}):null,actions:null}),s.isLoading?e.jsx(Ve,{label:t("common.loading")}):s.config?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid gap-6 xl:grid-cols-[200px_1fr]",children:[e.jsx(Et,{activeSection:s.activeSection,onSelectSection:s.handleSectionClick}),e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx(Lt,{defaultsSummary:s.defaultsSummary,errors:s.errors,form:s.form,onInputChange:s.handleInputChange,onSetForm:s.setForm,sectionRef:s.setSectionRef("section-basics")}),e.jsx(At,{errors:s.errors,form:s.form,onSetForm:s.setForm,protocolChangesPending:s.protocolChangesPending,sectionRef:s.setSectionRef("section-protocol")}),e.jsx(Tt,{authErrors:s.authErrors,authForm:s.authForm,authLoading:s.authQuery.isPending||!s.authSettings&&s.authQuery.isFetching,authSettings:s.authSettings,needsPassword:s.needsPassword,onSetAuthForm:s.setAuthForm,sectionRef:s.setSectionRef("section-security")}),e.jsx(Mt,{configPath:s.configPath,onCopyPath:()=>void s.handleCopyPath(),sectionRef:s.setSectionRef("section-config-file")}),e.jsx(Ot,{cleaning:s.cleaning,clearingAll:s.clearingAll,onOpenCleanup:()=>s.setConfirmCleanupOpen(!0),onOpenClearAll:()=>s.setConfirmClearAllOpen(!0),sectionRef:s.setSectionRef("section-cleanup")})]})]}),e.jsx(Ft,{dirtyCount:r,protocolChangesPending:s.protocolChangesPending,onReset:s.handleResetAll,onSave:()=>void s.handleSaveAll(),saving:s.saving||s.savingAuth})]}):e.jsx(k,{children:e.jsx(L,{className:"pt-6",children:e.jsx("p",{className:"text-sm font-medium text-destructive",children:t("settings.toast.missingConfig")})})}),e.jsx(He,{open:s.confirmCleanupOpen,onOpenChange:o=>{!o&&!s.cleaning&&s.setConfirmCleanupOpen(!1)},title:t("settings.cleanup.confirmTitle"),description:t("settings.cleanup.confirmDescription"),confirmLabel:s.cleaning?t("common.actions.cleaning"):t("common.actions.cleanup"),cancelLabel:t("common.actions.cancel"),loading:s.cleaning,onConfirm:async()=>{await s.handleCleanupLogs(),s.setConfirmCleanupOpen(!1)}}),e.jsx(He,{open:s.confirmClearAllOpen,onOpenChange:o=>{!o&&!s.clearingAll&&s.setConfirmClearAllOpen(!1)},title:t("settings.cleanup.clearAllTitle"),description:t("settings.cleanup.clearAllWarning"),confirmLabel:s.clearingAll?t("settings.cleanup.clearingAll"):t("settings.cleanup.clearAll"),cancelLabel:t("common.actions.cancel"),loading:s.clearingAll,onConfirm:async()=>{await s.handleClearAllLogs(),s.setConfirmClearAllOpen(!1)}})]})}export{ss as default};