@chenpu17/cc-gw 0.8.0-alpha.10 → 0.8.0-alpha.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/README.md +18 -2
  2. package/package.json +9 -5
  3. package/src/cli/dist/index.js +0 -2
  4. package/src/web/dist/assets/About-BgsBDZmU.js +1 -0
  5. package/src/web/dist/assets/ApiKeys-Y74gz6EM.js +1 -0
  6. package/src/web/dist/assets/Dashboard-BthghOfo.js +1 -0
  7. package/src/web/dist/assets/DialogShell-CCYRHVHF.js +1 -0
  8. package/src/web/dist/assets/EChart-CTWV6r1m.js +1 -0
  9. package/src/web/dist/assets/Events-BxX2s4AJ.js +1 -0
  10. package/src/web/dist/assets/Help-B9DwKvWW.js +8 -0
  11. package/src/web/dist/assets/Login-iJitfH-y.js +1 -0
  12. package/src/web/dist/assets/Logs-CjWtUBum.js +1 -0
  13. package/src/web/dist/assets/ModelManagement-CGAdMYdb.js +1 -0
  14. package/src/web/dist/assets/{PageHeader-Dcl2eX9i.js → PageHeader-BoMzY33X.js} +1 -1
  15. package/src/web/dist/assets/PageSection-DMHGizgh.js +1 -0
  16. package/src/web/dist/assets/PageState-CoBpDxLj.js +1 -0
  17. package/src/web/dist/assets/Settings-CJlv5psW.js +1 -0
  18. package/src/web/dist/assets/Skeleton-BMLOZAD8.js +1 -0
  19. package/src/web/dist/assets/card-DZKUcIo6.js +1 -0
  20. package/src/web/dist/assets/{charts-core-BE9sa9zn.js → charts-core-Bkq02SMi.js} +1 -1
  21. package/src/web/dist/assets/{charts-engine-DAwKT7Yg.js → charts-engine-BCuhIgMH.js} +1 -1
  22. package/src/web/dist/assets/{charts-react-Dnkr-ZWt.js → charts-react-08lL1GLe.js} +1 -1
  23. package/src/web/dist/assets/gateway-Cv9wYNta.js +1 -0
  24. package/src/web/dist/assets/{i18n-CZ1qKIdj.js → i18n-CO7_kqjg.js} +1 -1
  25. package/src/web/dist/assets/index-BEpsixrU.css +1 -0
  26. package/src/web/dist/assets/index-Do-c7aim.js +61 -0
  27. package/src/web/dist/assets/input-CJmvMsFH.js +1 -0
  28. package/src/web/dist/assets/{label-DQa7VwSx.js → label-QrXl4oW8.js} +1 -1
  29. package/src/web/dist/assets/popover-B5SqN_8N.js +1 -0
  30. package/src/web/dist/assets/{query-CDpWKdnY.js → query-DeMZnAJS.js} +1 -1
  31. package/src/web/dist/assets/queryKeys-CQ-Y0kH9.js +1 -0
  32. package/src/web/dist/assets/radix-Bg9QIv2e.js +5 -0
  33. package/src/web/dist/assets/{router-DjNibHfR.js → router-DwL4vhvg.js} +2 -2
  34. package/src/web/dist/assets/select-Bjy18Ntu.js +1 -0
  35. package/src/web/dist/assets/{switch-B6L3GFK8.js → switch-CrV3fty5.js} +1 -1
  36. package/src/web/dist/assets/useAppMutation-rCuN0OOS.js +1 -0
  37. package/src/web/dist/assets/{vendor-C92xTG6Z.js → vendor-OD8r2VI0.js} +110 -65
  38. package/src/web/dist/index.html +7 -7
  39. package/src/web/dist/assets/About-CYjwSwQR.js +0 -1
  40. package/src/web/dist/assets/ApiKeys-gdS7YBnv.js +0 -1
  41. package/src/web/dist/assets/ConfirmDialog-ZaBxSKvR.js +0 -1
  42. package/src/web/dist/assets/Dashboard-CHjs3cfB.js +0 -1
  43. package/src/web/dist/assets/EChart-C_zeFtIj.js +0 -1
  44. package/src/web/dist/assets/Events-B8rYWY-7.js +0 -1
  45. package/src/web/dist/assets/Help-BTkrauUz.js +0 -8
  46. package/src/web/dist/assets/Login-DcVi95VP.js +0 -1
  47. package/src/web/dist/assets/Logs-CzD10cko.js +0 -1
  48. package/src/web/dist/assets/ModelManagement-B_mBfVsK.js +0 -1
  49. package/src/web/dist/assets/PageSection-DfoNp0k-.js +0 -1
  50. package/src/web/dist/assets/Settings-DU9fzvb7.js +0 -1
  51. package/src/web/dist/assets/Skeleton-Bz0jpCrd.js +0 -1
  52. package/src/web/dist/assets/card-DgOF9KZW.js +0 -1
  53. package/src/web/dist/assets/index-CmNN6IIg.js +0 -61
  54. package/src/web/dist/assets/index-NGg4j8sr.css +0 -1
  55. package/src/web/dist/assets/input-CODjVWbb.js +0 -1
  56. package/src/web/dist/assets/popover-YrTS-yDD.js +0 -1
  57. package/src/web/dist/assets/radix-Ccu1urVd.js +0 -5
  58. package/src/web/dist/assets/select-B5LBtudS.js +0 -1
  59. package/src/web/dist/assets/useApiQuery-BvrOKWhr.js +0 -1
package/README.md CHANGED
@@ -118,8 +118,8 @@ Linux 版本使用 `musl`,Windows 版本使用静态 CRT,目标是让用户
118
118
  ```bash
119
119
  pnpm pack:dry-run
120
120
  pnpm --dir packages/native/darwin-arm64 pack --pack-destination ../../../.pack/native
121
- npm install -g ./.pack/native/chenpu17-cc-gw-darwin-arm64-0.8.0-alpha.10.tgz
122
- npm install -g ./.pack/chenpu17-cc-gw-0.8.0-alpha.10.tgz
121
+ npm install -g ./.pack/native/chenpu17-cc-gw-darwin-arm64-0.8.0-alpha.11.tgz
122
+ npm install -g ./.pack/chenpu17-cc-gw-0.8.0-alpha.11.tgz
123
123
  ```
124
124
 
125
125
  当前发布目标:
@@ -147,10 +147,26 @@ pnpm exec playwright install --with-deps chromium
147
147
  pnpm test:e2e:web
148
148
  ```
149
149
 
150
+ 如果只想跑分层回归,可直接用:
151
+
152
+ ```bash
153
+ pnpm test:e2e:web:core
154
+ pnpm test:e2e:web:hardening
155
+ pnpm test:e2e:web:visual
156
+ ```
157
+
158
+ 如需刷新页面级截图基线:
159
+
160
+ ```bash
161
+ pnpm test:e2e:web:update-snapshots
162
+ ```
163
+
150
164
  当前仓库已具备:
151
165
 
152
166
  - Web UI 构建通过
153
167
  - Web Playwright E2E 通过
168
+ - 页面级视觉截图基线回归
169
+ - 低频危险路径 E2E
154
170
  - CLI smoke 流程可单独执行
155
171
  - GitHub Actions CI 与 release workflow 已落地
156
172
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chenpu17/cc-gw",
3
- "version": "0.8.0-alpha.10",
3
+ "version": "0.8.0-alpha.11",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "Rust-backed local Claude Code compatible gateway with web console and CLI daemon.",
@@ -25,10 +25,10 @@
25
25
  "README.md"
26
26
  ],
27
27
  "optionalDependencies": {
28
- "@chenpu17/cc-gw-darwin-arm64": "0.8.0-alpha.10",
29
- "@chenpu17/cc-gw-linux-x64": "0.8.0-alpha.10",
30
- "@chenpu17/cc-gw-linux-arm64": "0.8.0-alpha.10",
31
- "@chenpu17/cc-gw-win32-x64": "0.8.0-alpha.10"
28
+ "@chenpu17/cc-gw-darwin-arm64": "0.8.0-alpha.11",
29
+ "@chenpu17/cc-gw-linux-x64": "0.8.0-alpha.11",
30
+ "@chenpu17/cc-gw-linux-arm64": "0.8.0-alpha.11",
31
+ "@chenpu17/cc-gw-win32-x64": "0.8.0-alpha.11"
32
32
  },
33
33
  "dependencies": {
34
34
  "colorette": "^2.0.20",
@@ -54,6 +54,10 @@
54
54
  "pack:dry-run": "pnpm run build:package && node scripts/pack-root-package.mjs",
55
55
  "publish:packed": "node scripts/publish-artifacts.mjs",
56
56
  "test:e2e:web": "pnpm build && playwright test",
57
+ "test:e2e:web:core": "pnpm build && playwright test tests/playwright/pages.spec.ts tests/playwright/auth.spec.ts tests/playwright/logs.spec.ts tests/playwright/model-management.spec.ts tests/playwright/settings.spec.ts tests/playwright/api-keys.spec.ts --reporter=line",
58
+ "test:e2e:web:visual": "pnpm build && playwright test tests/playwright/visual.spec.ts --reporter=line",
59
+ "test:e2e:web:hardening": "pnpm build && playwright test tests/playwright/hardening.spec.ts --reporter=line",
60
+ "test:e2e:web:update-snapshots": "pnpm build && playwright test tests/playwright/visual.spec.ts --update-snapshots --reporter=line",
57
61
  "typecheck": "pnpm --filter @cc-gw/cli exec tsc --noEmit && pnpm --filter @cc-gw/web exec tsc --noEmit"
58
62
  }
59
63
  }
@@ -196,8 +196,6 @@ async function ensureConfigTemplate(port) {
196
196
  logRetentionDays: 30,
197
197
  modelRoutes: {},
198
198
  logLevel: "info",
199
- requestLogging: true,
200
- responseLogging: true,
201
199
  bodyLimit: 10 * 1024 * 1024,
202
200
  webAuth: {
203
201
  enabled: false,
@@ -0,0 +1 @@
1
+ import{r as c,j as e,aa as P,az as T,aA as u,ai as B,Y as R}from"./vendor-OD8r2VI0.js";import{P as q,B as o}from"./PageHeader-BoMzY33X.js";import{P as m}from"./PageSection-DMHGizgh.js";import{P as A,a as C}from"./PageState-CoBpDxLj.js";import{u as I,q as V}from"./queryKeys-CQ-Y0kH9.js";import{u as z,B as p}from"./index-Do-c7aim.js";import{C as l,a as n}from"./card-DZKUcIo6.js";import{u as F}from"./i18n-CO7_kqjg.js";import"./query-DeMZnAJS.js";import"./router-DwL4vhvg.js";import"./radix-Bg9QIv2e.js";const G="0.8.0-alpha.11",M={version:G};function X(){var b,h,f,g,j,v,N,y,w,k;const{t:a}=F(),{pushToast:t}=z(),s=I(V.status.gateway(),{url:"/api/status",method:"GET"},{staleTime:6e4});c.useEffect(()=>{s.isError&&s.error&&t({title:a("about.toast.statusError.title"),description:s.error.message,variant:"error"})},[t,s.error,s.isError,a]);const i=M.version,d="2026-03-20T09:30:26.954Z",L=c.useMemo(()=>{var r,S;return[{label:a("about.app.labels.name"),value:e.jsx("span",{className:"font-mono",children:"cc-gw"})},{label:a("about.app.labels.version"),value:e.jsxs("span",{className:"font-mono text-primary",children:["v",i]})},{label:a("about.app.labels.buildTime"),value:d,hint:a("about.app.hint.buildTime")},{label:a("about.app.labels.runtime"),value:e.jsx("span",{className:"font-mono",children:((r=s.data)==null?void 0:r.runtime)??"rust"})},{label:a("about.app.labels.backendVersion"),value:e.jsx("span",{className:"font-mono",children:((S=s.data)==null?void 0:S.backendVersion)??"-"})}]},[i,d,(b=s.data)==null?void 0:b.backendVersion,(h=s.data)==null?void 0:h.runtime,a]),x=c.useMemo(()=>{var r;return s.data?[{label:a("about.status.labels.host"),value:s.data.host??"127.0.0.1"},{label:a("about.status.labels.port"),value:s.data.port.toLocaleString()},{label:a("about.status.labels.providers"),value:s.data.providers.toLocaleString()},{label:a("about.status.labels.active"),value:(s.data.activeRequests??0).toLocaleString(),hint:a("about.status.hint.active")},{label:a("about.status.labels.platform"),value:s.data.platform??"-"},{label:a("about.status.labels.pid"),value:((r=s.data.pid)==null?void 0:r.toLocaleString())??"-"}]:[]},[s.data,a]);return e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx(q,{icon:e.jsx(T,{className:"h-5 w-5","aria-hidden":"true"}),title:a("about.title"),description:a("about.description"),badge:`v${i}`,eyebrow:"Runtime",breadcrumb:"Gateway / About",helper:a("about.support.description"),actions:e.jsxs("div",{className:"flex w-full flex-col gap-2 sm:w-auto sm:flex-row sm:flex-wrap sm:justify-end",children:[e.jsx("div",{className:"rounded-lg border border-border bg-secondary px-3 py-2 text-xs text-muted-foreground",children:"manual refresh only"}),e.jsxs(p,{onClick:()=>t({title:a("about.toast.updatesPlanned"),variant:"info"}),className:"w-full sm:w-auto",children:[e.jsx(P,{className:"mr-2 h-4 w-4","aria-hidden":"true"}),a("about.support.actions.checkUpdates")]})]})}),e.jsxs("div",{className:"grid gap-4 xl:grid-cols-[minmax(0,1.3fr)_minmax(320px,0.9fr)]",children:[e.jsx(l,{className:"overflow-hidden",children:e.jsx(n,{className:"pt-6",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"inline-flex items-center gap-2 rounded-full border border-primary/20 bg-accent px-3 py-1 text-xs font-semibold uppercase tracking-wider text-primary",children:[e.jsx(u,{className:"h-3.5 w-3.5","aria-hidden":"true"}),"Runtime snapshot"]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("p",{className:"text-3xl font-semibold tracking-tight text-foreground",children:[((f=s.data)==null?void 0:f.host)??"127.0.0.1",":",((g=s.data)==null?void 0:g.port)??"-"]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:a("about.description")})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(o,{variant:"outline",children:((j=s.data)==null?void 0:j.runtime)??"rust"}),e.jsx(o,{variant:"outline",children:((v=s.data)==null?void 0:v.platform)??"-"}),e.jsxs(o,{variant:"secondary",children:[a("about.status.labels.providers"),": ",((y=(N=s.data)==null?void 0:N.providers)==null?void 0:y.toLocaleString())??"-"]}),e.jsxs(o,{variant:"secondary",children:[a("about.status.labels.active"),": ",(((w=s.data)==null?void 0:w.activeRequests)??0).toLocaleString()]})]})]})})}),e.jsx(l,{className:"overflow-hidden",children:e.jsx(n,{className:"pt-6",children:e.jsxs("div",{className:"space-y-3",children:[e.jsx("p",{className:"text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:"Build"}),e.jsxs("p",{className:"font-mono text-lg text-primary",children:["v",i]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:d}),e.jsx("div",{className:"rounded-lg border border-border bg-secondary px-4 py-3 text-sm text-muted-foreground",children:a("about.support.tip")})]})})})]}),e.jsxs("div",{className:"grid gap-6 lg:grid-cols-2",children:[e.jsx(m,{title:a("about.app.title"),description:a("about.app.subtitle"),children:e.jsx(E,{items:L})}),e.jsx(m,{title:a("about.status.title"),description:a("about.status.subtitle"),actions:e.jsxs(p,{variant:"outline",size:"sm",onClick:()=>void s.refetch(),disabled:s.isFetching,children:[e.jsx(B,{className:Q(s.isFetching),"aria-hidden":"true"}),s.isFetching?a("common.actions.refreshing"):a("common.actions.refresh")]}),children:s.isLoading?e.jsx(A,{compact:!0,label:a("about.status.loading")}):s.isError?e.jsx(C,{compact:!0,tone:"danger",icon:e.jsx(u,{className:"h-5 w-5","aria-hidden":"true"}),title:a("common.status.error"),description:((k=s.error)==null?void 0:k.message)??a("common.unknownError"),action:e.jsx(p,{variant:"outline",size:"sm",onClick:()=>void s.refetch(),children:a("common.actions.refresh")})}):x.length>0?e.jsx(E,{items:x}):e.jsx(C,{compact:!0,tone:"primary",icon:e.jsx(u,{className:"h-5 w-5","aria-hidden":"true"}),title:a("about.status.empty"),description:a("common.actions.refresh")})})]}),e.jsx(m,{title:a("about.support.title"),description:e.jsxs("span",{className:"space-y-1",children:[e.jsx("span",{className:"block text-sm font-medium text-primary",children:a("about.support.subtitle")}),e.jsx("span",{children:a("about.support.description")})]}),children:e.jsx(l,{children:e.jsxs(n,{className:"flex flex-col gap-4 pt-5 md:flex-row md:items-start md:justify-between",children:[e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx("div",{className:"flex h-11 w-11 items-center justify-center rounded-2xl bg-primary/10 text-primary",children:e.jsx(R,{className:"h-5 w-5","aria-hidden":"true"})}),e.jsx("p",{className:"max-w-2xl text-sm text-muted-foreground",children:a("about.support.tip")})]}),e.jsx("code",{className:"inline-flex self-start rounded-lg border border-border bg-secondary px-3 py-2 text-xs font-medium",children:"~/.cc-gw/config.json"})]})})})]})}function E({items:a}){return a.length===0?null:e.jsx("dl",{className:"grid gap-4 sm:grid-cols-2",children:a.map(t=>e.jsx(l,{children:e.jsxs(n,{className:"pt-5",children:[e.jsx("dt",{className:"text-xs font-semibold uppercase tracking-[0.16em] text-muted-foreground",children:t.label}),e.jsx("dd",{className:"mt-2 text-sm font-semibold text-foreground",children:t.value}),t.hint?e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:t.hint}):null]})},t.label))})}function Q(a){return`mr-2 h-4 w-4${a?" animate-spin":""}`}export{X as default};
@@ -0,0 +1 @@
1
+ import{r as d,j as e,a1 as _e,at as ge,W as be,au as je,av as fe,aw as Je,ax as Xe,ar as Ye}from"./vendor-OD8r2VI0.js";import{c as Z,r as Ze,h as H,b as V,B as v,u as es,a as G,s as B,L as ss}from"./index-Do-c7aim.js";import{B as w,P as ts}from"./PageHeader-BoMzY33X.js";import{C as as,u as P}from"./useAppMutation-rCuN0OOS.js";import{D as ee,A as se,a as te,b as ae,c as ve,d as ie,e as ne}from"./DialogShell-CCYRHVHF.js";import{I as Ke}from"./input-CJmvMsFH.js";import{L as U}from"./label-QrXl4oW8.js";import{u as I,q as f}from"./queryKeys-CQ-Y0kH9.js";import{u as K}from"./i18n-CO7_kqjg.js";import{E as is}from"./EChart-CTWV6r1m.js";import{P as re}from"./PageSection-DMHGizgh.js";import{C as le,a as oe}from"./card-DZKUcIo6.js";import{e as ns}from"./charts-core-Bkq02SMi.js";import{c as rs}from"./clipboard-CALi6bTW.js";import"./query-DeMZnAJS.js";import"./router-DwL4vhvg.js";import"./radix-Bg9QIv2e.js";import"./charts-react-08lL1GLe.js";import"./charts-engine-BCuhIgMH.js";const we=d.forwardRef(({className:s,...t},r)=>e.jsx("textarea",{className:Z("flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",s),ref:r,...t}));we.displayName="Textarea";const E={listRequest(){return{url:"/api/keys",method:"GET"}},overviewRequest(s){return{url:"/api/stats/api-keys/overview",method:"GET",params:{days:s}}},usageRequest(s,t=10){return{url:"/api/stats/api-keys/usage",method:"GET",params:{days:s,limit:t}}},customEndpointOptionsRequest(){return{url:"/api/custom-endpoints",method:"GET"}},create:async s=>H(V.post("/api/keys",s)),update:async(s,t)=>{await H(V.patch(`/api/keys/${s}`,t))},delete:async s=>{await H(V.delete(`/api/keys/${s}`))},reveal:async s=>Ze({url:`/api/keys/${s}/reveal`,method:"GET"})},Ne=[{value:1,labelKey:"apiKeys.analytics.range.today"},{value:7,labelKey:"apiKeys.analytics.range.week"},{value:30,labelKey:"apiKeys.analytics.range.month"}];function ls(){var r;const s=[{id:"anthropic",label:"Anthropic"},{id:"openai",label:"OpenAI"}],t=I(f.customEndpoints.all(),E.customEndpointOptionsRequest());return d.useMemo(()=>{var l;const a=(((l=t.data)==null?void 0:l.endpoints)??[]).map(u=>({id:u.id,label:u.label||u.id}));return[...s,...a]},[(r=t.data)==null?void 0:r.endpoints])}function Ce({available:s,hint:t,onChange:r,selected:a}){const{t:l}=K(),u=a.length===0,m=()=>{r([])},g=c=>{if(a.includes(c)){r(a.filter(x=>x!==c));return}r([...a,c])};return e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"rounded-lg border border-border bg-secondary px-3 py-3 text-xs text-muted-foreground",children:t}),e.jsxs("label",{className:"flex cursor-pointer items-center gap-2 rounded-lg border border-border bg-card px-3 py-2.5 transition-colors hover:border-primary/20 hover:bg-accent/50",children:[e.jsx("input",{type:"checkbox",checked:u,onChange:m,className:"h-4 w-4 rounded border-input accent-primary"}),e.jsx("span",{className:"text-sm font-medium",children:l("apiKeys.allEndpoints")})]}),e.jsx("div",{className:"grid max-h-40 gap-1 overflow-y-auto",children:s.map(c=>e.jsxs("label",{className:"flex cursor-pointer items-center gap-2 rounded-lg border border-border bg-card px-3 py-2.5 transition-colors hover:border-primary/20 hover:bg-accent/50",children:[e.jsx("input",{type:"checkbox",checked:!u&&a.includes(c.id),onChange:()=>g(c.id),className:"h-4 w-4 rounded border-input accent-primary"}),e.jsx("span",{className:"text-sm",children:c.label}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:["(",c.id,")"]})]},c.id))})]})}function os({availableEndpoints:s,isOpen:t,keyDescription:r,keyName:a,onDescriptionChange:l,onEndpointsChange:u,onKeyNameChange:m,onOpenChange:g,onSubmit:c,selectedEndpoints:x}){const{t:p}=K();return e.jsx(ee,{open:t,onOpenChange:g,children:e.jsxs(se,{className:"max-w-2xl",children:[e.jsxs(te,{children:[e.jsx(ae,{children:p("apiKeys.createNew")}),e.jsx(ve,{children:p("apiKeys.createDescription")})]}),e.jsxs(ie,{className:"space-y-4",children:[e.jsx("div",{className:"rounded-lg border border-primary/20 bg-accent px-4 py-3 text-xs text-primary",children:p("apiKeys.selectEndpoints")}),e.jsxs("div",{className:"grid gap-3 md:grid-cols-3",children:[e.jsxs("div",{className:"rounded-[1rem] border border-blue-200 bg-blue-50/70 px-3 py-3 text-xs text-blue-900 dark:border-blue-800 dark:bg-blue-950/30 dark:text-blue-100",children:[e.jsx("p",{className:"font-semibold",children:"Restricted"}),e.jsx("p",{className:"mt-1 text-blue-800/85 dark:text-blue-100/80",children:"Select explicit endpoints before saving."})]}),e.jsxs("div",{className:"rounded-[1rem] border border-amber-200 bg-amber-50/70 px-3 py-3 text-xs text-amber-900 dark:border-amber-800 dark:bg-amber-950/30 dark:text-amber-100",children:[e.jsx("p",{className:"font-semibold",children:"Unrestricted"}),e.jsx("p",{className:"mt-1 text-amber-800/85 dark:text-amber-100/80",children:"Leave endpoint selection empty for broad access."})]}),e.jsxs("div",{className:"rounded-[1rem] border border-rose-200 bg-rose-50/70 px-3 py-3 text-xs text-rose-900 dark:border-rose-800 dark:bg-rose-950/30 dark:text-rose-100",children:[e.jsx("p",{className:"font-semibold",children:"Wildcard"}),e.jsx("p",{className:"mt-1 text-rose-800/85 dark:text-rose-100/80",children:"Special-case key with the highest blast radius."})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(U,{htmlFor:"keyName",children:[p("apiKeys.keyNamePlaceholder")," *"]}),e.jsx(Ke,{id:"keyName",value:a,onChange:n=>m(n.target.value),placeholder:p("apiKeys.keyNamePlaceholder"),onKeyDown:n=>{n.key==="Enter"&&(n.preventDefault(),c())}})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(U,{htmlFor:"keyDescription",children:p("apiKeys.descriptionLabel")}),e.jsx(we,{id:"keyDescription",value:r,onChange:n=>l(n.target.value),placeholder:p("apiKeys.keyDescriptionPlaceholder"),rows:3})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(U,{children:p("apiKeys.allowedEndpoints")}),e.jsx(Ce,{available:s,selected:x,onChange:u,hint:p("apiKeys.selectEndpoints")})]})]}),e.jsxs(ne,{children:[e.jsx(v,{variant:"outline",onClick:()=>g(!1),children:p("common.actions.cancel")}),e.jsx(v,{onClick:c,children:p("apiKeys.createAction")})]})]})})}function ds({createdKey:s,onClose:t,onCopy:r}){const{t:a}=K();return e.jsx(ee,{open:!!s,onOpenChange:l=>{l||t()},children:e.jsxs(se,{className:"max-w-xl",children:[e.jsx(te,{children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex h-10 w-10 items-center justify-center rounded-full bg-emerald-500/10 text-emerald-600",children:e.jsx(_e,{className:"h-5 w-5","aria-hidden":"true"})}),e.jsx(ae,{children:a("apiKeys.keyCreated")})]})}),e.jsxs(ie,{className:"space-y-4",children:[e.jsx("p",{className:"text-sm font-medium text-amber-600 dark:text-amber-400",children:a("apiKeys.saveKeyWarning")}),e.jsx("div",{className:"rounded-lg border border-border bg-secondary px-4 py-3 font-mono text-sm",children:s==null?void 0:s.key}),s!=null&&s.description?e.jsx("p",{className:"whitespace-pre-wrap text-sm text-muted-foreground",children:s.description}):null]}),e.jsxs(ne,{children:[e.jsxs(v,{onClick:()=>r((s==null?void 0:s.key)??""),children:[e.jsx(ge,{className:"mr-2 h-4 w-4","aria-hidden":"true"}),a("common.actions.copy")]}),e.jsx(v,{variant:"outline",onClick:t,children:a("common.actions.close")})]})]})})}function cs({apiKey:s,availableEndpoints:t,onClose:r,onEndpointsChange:a,onSave:l,selectedEndpoints:u}){const{t:m}=K();return e.jsx(ee,{open:!!s,onOpenChange:g=>{g||r()},children:e.jsxs(se,{className:"max-w-2xl",children:[e.jsxs(te,{children:[e.jsx(ae,{children:m("apiKeys.editEndpoints")}),e.jsx(ve,{children:s==null?void 0:s.name})]}),e.jsxs(ie,{className:"space-y-4",children:[e.jsx("div",{className:"rounded-lg border border-[hsl(var(--warning)/0.3)] bg-[hsl(var(--warning-bg))] px-4 py-3 text-xs text-[hsl(var(--warning)/1)]",children:m("apiKeys.allEndpoints")}),e.jsx("div",{className:"rounded-lg border border-border bg-secondary px-4 py-3 text-xs text-muted-foreground",children:"Empty selection means unrestricted access. Only explicit selections create a restricted key scope."}),e.jsx(Ce,{available:t,selected:u,onChange:a,hint:m("apiKeys.selectEndpoints")})]}),e.jsxs(ne,{children:[e.jsx(v,{variant:"outline",onClick:r,children:m("common.actions.cancel")}),e.jsx(v,{onClick:l,children:m("common.save")})]})]})})}function ps({deleteTarget:s,isDeleting:t,onConfirm:r,onOpenChange:a}){const{t:l}=K();return e.jsx(as,{open:!!s,onOpenChange:a,title:l("apiKeys.deleteDialogTitle"),description:l("apiKeys.confirmDelete"),confirmLabel:s&&t===s.id?l("common.actions.loading"):l("apiKeys.actions.delete"),cancelLabel:l("common.actions.cancel"),loading:s?t===s.id:!1,onConfirm:r,children:s?e.jsx("div",{className:"rounded-lg border border-destructive/20 bg-destructive/10 px-3 py-2 font-mono text-xs text-foreground",children:s.name}):null})}function us(){const{t:s}=K();return e.jsx(re,{eyebrow:"Recommended",title:s("apiKeys.quickStart.title"),description:s("apiKeys.quickStart.description"),contentClassName:"pt-5",children:e.jsxs("div",{className:"grid gap-4 md:grid-cols-3",children:[e.jsx(_,{icon:e.jsx(be,{className:"h-4 w-4","aria-hidden":"true"}),title:s("apiKeys.quickStart.create.title"),description:s("apiKeys.quickStart.create.description")}),e.jsx(_,{icon:e.jsx(je,{className:"h-4 w-4","aria-hidden":"true"}),title:s("apiKeys.quickStart.restrict.title"),description:s("apiKeys.quickStart.restrict.description")}),e.jsx(_,{icon:e.jsx(fe,{className:"h-4 w-4","aria-hidden":"true"}),title:s("apiKeys.quickStart.wildcard.title"),description:s("apiKeys.quickStart.wildcard.description")})]})})}function xs({activeKeysValue:s,enabledKeysValue:t,loading:r,onRangeChange:a,rangeDays:l,requestsChartOption:u,totalKeysValue:m,tokensChartOption:g,usageLength:c}){const{t:x}=K();return e.jsx(re,{eyebrow:"Usage",title:x("apiKeys.analytics.title"),description:x("apiKeys.analytics.description",{days:l}),actions:e.jsx("div",{className:"flex w-full items-center gap-1 overflow-x-auto rounded-full border border-border bg-secondary p-1 sm:w-auto",children:Ne.map(p=>{const n=l===p.value;return e.jsx("button",{type:"button",onClick:()=>a(p.value),className:Z("inline-flex h-8 shrink-0 items-center rounded-full px-3.5 text-xs font-medium transition-all",n?"bg-primary text-primary-foreground":"text-muted-foreground hover:bg-primary/5 hover:text-foreground"),children:x(p.labelKey)},p.value)})}),children:e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2 xl:grid-cols-3",children:[e.jsx(J,{label:x("apiKeys.analytics.cards.total"),value:m}),e.jsx(J,{label:x("apiKeys.analytics.cards.enabled"),value:t}),e.jsx(J,{label:x("apiKeys.analytics.cards.active",{days:l}),value:s})]}),e.jsxs("div",{className:"grid gap-6 lg:grid-cols-2",children:[e.jsx(ye,{title:x("apiKeys.analytics.charts.requests"),loading:r,empty:c===0,emptyText:x("apiKeys.analytics.empty"),option:u}),e.jsx(ye,{title:x("apiKeys.analytics.charts.tokens"),loading:r,empty:c===0,emptyText:x("apiKeys.analytics.empty"),option:g})]})]})})}function ms({filteredKeys:s,formatDate:t,hasWildcard:r,isDeleting:a,isRevealing:l,keys:u,onCopy:m,onDelete:g,onEditEndpoints:c,onFilterChange:x,onHide:p,onReveal:n,onStatusFilterChange:F,onToggleEnabled:k,restrictedCount:j,revealedKeys:D,search:y,statusFilter:q,unrestrictedCount:O,wildcardCount:A}){const{t:h}=K();return e.jsx(re,{eyebrow:"Inventory",title:h("apiKeys.list.title"),description:r?h("apiKeys.wildcardHint"):void 0,actions:e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(w,{variant:"outline",children:`${s.length}/${u.length}`}),e.jsx(w,{variant:"outline",children:h("apiKeys.summary.wildcard",{count:A})}),e.jsx(w,{variant:"outline",children:h("apiKeys.summary.restricted",{count:j})})]}),children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid gap-4 md:grid-cols-3",children:[e.jsx(X,{label:h("apiKeys.list.title"),value:`${s.length}/${u.length}`,helper:h("apiKeys.filters.searchPlaceholder")}),e.jsx(X,{label:h("apiKeys.summary.wildcard",{count:A}),value:String(A),helper:h("apiKeys.wildcardHint")}),e.jsx(X,{label:h("apiKeys.summary.restricted",{count:j}),value:String(j),helper:h("apiKeys.summary.unrestricted",{count:O})})]}),e.jsxs("div",{className:"grid gap-3 rounded-lg border border-border bg-secondary p-4 lg:grid-cols-[minmax(0,1fr)_minmax(0,360px)] xl:grid-cols-[minmax(0,1fr)_180px_auto]",children:[e.jsx(Ke,{value:y,onChange:b=>x(b.target.value),placeholder:h("apiKeys.filters.searchPlaceholder")}),e.jsx("div",{className:"flex items-center gap-1 overflow-x-auto rounded-full border border-border bg-secondary p-1",children:["all","enabled","disabled"].map(b=>e.jsx("button",{type:"button",onClick:()=>F(b),className:Z("inline-flex h-8 shrink-0 items-center rounded-full px-3.5 text-xs font-medium transition-all",q===b?"bg-primary text-primary-foreground":"text-muted-foreground hover:bg-primary/5 hover:text-foreground"),children:h(`apiKeys.filters.${b}`)},b))}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 lg:col-span-2 xl:col-span-1",children:[e.jsx(w,{variant:"secondary",children:h("apiKeys.summary.wildcard",{count:A})}),e.jsx(w,{variant:"secondary",children:h("apiKeys.summary.restricted",{count:j})})]})]}),u.length===0?e.jsx("div",{className:"flex h-32 items-center justify-center rounded-lg border border-dashed border-border",children:e.jsx("p",{className:"text-sm text-muted-foreground",children:h("apiKeys.list.empty")})}):s.length===0?e.jsx("div",{className:"flex h-32 items-center justify-center rounded-lg border border-dashed border-border",children:e.jsx("p",{className:"text-sm text-muted-foreground",children:h("apiKeys.list.emptyFiltered")})}):e.jsx("div",{className:"grid gap-4",children:s.map(b=>e.jsx(hs,{formatDate:t,isDeleting:a===b.id,isRevealing:l===b.id,keySummary:b,onCopy:m,onDelete:g,onEditEndpoints:c,onHide:p,onReveal:n,onToggleEnabled:k,revealedValue:D.get(b.id)},b.id))})]})})}function _({description:s,icon:t,title:r}){return e.jsxs("div",{className:"rounded-lg border border-border bg-card p-4",children:[e.jsx("div",{className:"flex h-9 w-9 items-center justify-center rounded-lg bg-primary/10 text-primary",children:t}),e.jsx("p",{className:"mt-3 text-sm font-semibold text-foreground",children:r}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:s})]})}function hs({formatDate:s,isDeleting:t,isRevealing:r,keySummary:a,onCopy:l,onDelete:u,onEditEndpoints:m,onHide:g,onReveal:c,onToggleEnabled:x,revealedValue:p}){var k,j,D,y;const{t:n}=K(),F=(a.totalInputTokens+a.totalOutputTokens).toLocaleString();return a.isWildcard||(((k=a.allowedEndpoints)==null?void 0:k.length)??0)>0,e.jsx(le,{"data-testid":"api-key-card",children:e.jsx(oe,{className:"space-y-4 pt-4",children:e.jsxs("div",{className:"flex flex-col gap-4 lg:flex-row lg:items-start lg:justify-between",children:[e.jsxs("div",{className:"min-w-0 space-y-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("h3",{className:"text-base font-semibold",children:a.name}),a.isWildcard?e.jsx(w,{variant:"secondary",children:n("apiKeys.wildcard")}):null,e.jsx(w,{variant:a.enabled?"default":"outline",children:a.enabled?n("apiKeys.status.enabled"):n("apiKeys.status.disabled")}),a.isWildcard?null:e.jsx(w,{variant:"outline",className:"text-xs",children:(((j=a.allowedEndpoints)==null?void 0:j.length)??0)>0?n("apiKeys.endpointRestricted"):n("apiKeys.allEndpoints")}),!a.isWildcard&&a.allowedEndpoints&&a.allowedEndpoints.length>0?a.allowedEndpoints.map(q=>e.jsx(w,{variant:"outline",className:"text-xs",children:q},q)):a.isWildcard?null:e.jsx(w,{variant:"secondary",className:"text-xs opacity-60",children:n("apiKeys.allEndpoints")})]}),e.jsxs("div",{className:"grid gap-2 sm:grid-cols-3",children:[e.jsx(Y,{label:n("apiKeys.requestCount"),value:a.requestCount.toLocaleString()}),e.jsx(Y,{label:n("apiKeys.totalTokens"),value:F}),e.jsx(Y,{label:n("apiKeys.allowedEndpoints"),value:a.isWildcard?n("apiKeys.wildcard"):a.allowedEndpoints&&a.allowedEndpoints.length>0?a.allowedEndpoints.join(", "):n("apiKeys.allEndpoints")})]}),e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center",children:[e.jsx("code",{className:"block max-w-full break-all rounded-lg border border-border bg-secondary px-3 py-1.5 font-mono text-sm",children:a.isWildcard?n("apiKeys.wildcard"):p??a.maskedKey??"********"}),a.isWildcard?null:e.jsx("div",{className:"flex items-center gap-1 self-start",children:p?e.jsxs(e.Fragment,{children:[e.jsx(v,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:()=>l(p),"aria-label":n("common.actions.copy"),title:n("common.actions.copy"),children:e.jsx(ge,{className:"h-4 w-4","aria-hidden":"true"})}),e.jsx(v,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:()=>g(a.id),"aria-label":n("apiKeys.actions.hide"),title:n("apiKeys.actions.hide"),children:e.jsx(fe,{className:"h-4 w-4","aria-hidden":"true"})})]}):e.jsx(v,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:()=>c(a.id),disabled:r,"aria-label":n("apiKeys.actions.reveal"),title:n("apiKeys.actions.reveal"),children:r?e.jsx("div",{className:"h-4 w-4 animate-spin rounded-full border-2 border-primary border-t-transparent"}):e.jsx(Je,{className:"h-4 w-4","aria-hidden":"true"})})})]}),a.isWildcard?e.jsx("p",{className:"text-sm text-muted-foreground",children:n("apiKeys.wildcardHint")}):a.description?e.jsx("p",{className:"whitespace-pre-wrap text-sm text-muted-foreground",children:a.description}):null,a.isWildcard?null:e.jsx("div",{className:"rounded-lg border border-border bg-secondary px-3 py-2 text-xs text-muted-foreground",children:(((D=a.allowedEndpoints)==null?void 0:D.length)??0)>0?`${n("apiKeys.allowedEndpoints")}: ${(y=a.allowedEndpoints)==null?void 0:y.join(", ")}`:n("apiKeys.allEndpoints")}),e.jsxs("div",{className:"grid gap-3 text-sm sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("span",{className:"text-xs font-medium uppercase tracking-wide text-muted-foreground",children:n("apiKeys.created")}),e.jsx("p",{className:"font-medium",children:s(a.createdAt)})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("span",{className:"text-xs font-medium uppercase tracking-wide text-muted-foreground",children:n("apiKeys.lastUsed")}),e.jsx("p",{className:"font-medium",children:s(a.lastUsedAt)})]})]})]}),e.jsxs("div",{className:"grid gap-2 sm:grid-cols-2 lg:flex lg:flex-wrap lg:justify-end",children:[a.isWildcard?null:e.jsxs(v,{variant:"outline",size:"sm",onClick:()=>m(a),className:"w-full lg:w-auto",children:[e.jsx(je,{className:"mr-1 h-3.5 w-3.5","aria-hidden":"true"}),n("apiKeys.editEndpoints")]}),e.jsx(v,{variant:a.enabled?"outline":"default",size:"sm",onClick:()=>x(a.id,a.enabled),className:"w-full lg:w-auto",children:a.enabled?n("apiKeys.actions.disable"):n("apiKeys.actions.enable")}),a.isWildcard?null:e.jsx(v,{variant:"ghost",size:"icon",className:"h-9 w-full text-destructive hover:bg-destructive/10 hover:text-destructive sm:w-9",onClick:()=>u(a),disabled:t,"aria-label":n("apiKeys.actions.delete"),children:e.jsx(Xe,{className:"h-4 w-4","aria-hidden":"true"})})]})]})})})}function J({label:s,value:t}){return e.jsx(le,{children:e.jsxs(oe,{className:"pt-4",children:[e.jsx("p",{className:"text-xs font-medium uppercase tracking-wider text-muted-foreground",children:s}),e.jsx("p",{className:"mt-2 text-2xl font-semibold text-foreground",children:t})]})})}function X({helper:s,label:t,value:r}){return e.jsxs("div",{className:"rounded-lg border border-border bg-card px-4 py-3",children:[e.jsx("p",{className:"text-[11px] font-medium uppercase tracking-wider text-muted-foreground",children:t}),e.jsx("p",{className:"mt-2 text-lg font-semibold text-foreground",children:r}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:s})]})}function Y({label:s,value:t}){return e.jsxs("div",{className:"rounded-lg border border-border bg-secondary px-3 py-2",children:[e.jsx("p",{className:"text-[11px] font-medium uppercase tracking-[0.16em] text-muted-foreground",children:s}),e.jsx("p",{className:"mt-1 truncate text-sm font-medium",children:t})]})}function ye({empty:s,emptyText:t,loading:r,option:a,title:l}){const{t:u}=K();return e.jsx(le,{children:e.jsxs(oe,{className:"space-y-4 pt-4",children:[e.jsx("h3",{className:"text-base font-semibold",children:l}),r?e.jsx("div",{className:"flex h-[280px] items-center justify-center",children:e.jsx("span",{className:"text-sm text-muted-foreground",children:u("common.loadingShort")})}):s?e.jsx("div",{className:"flex h-[280px] items-center justify-center rounded-lg border border-dashed border-border",children:e.jsx("span",{className:"text-sm text-muted-foreground",children:t})}):e.jsx(is,{echarts:ns,option:a,style:{height:280},notMerge:!0,lazyUpdate:!0})]})})}function ys(){const{t:s}=K(),{pushToast:t}=es(),[r,a]=d.useState(!1),[l,u]=d.useState(""),[m,g]=d.useState(""),[c,x]=d.useState([]),[p,n]=d.useState(null),[F,k]=d.useState(null),[j,D]=d.useState(null),[y,q]=G(B.apiKeys.rangeDays,7,{serialize:i=>String(i),deserialize:i=>{const o=Number(i);return Ne.some(N=>N.value===o)?o:7}}),[O,A]=d.useState(new Map),[h,b]=d.useState(null),[S,z]=d.useState(null),[W,de]=d.useState([]),[$,Ee]=G(B.apiKeys.search,""),[L,ke]=G(B.apiKeys.statusFilter,"all",{serialize:i=>i,deserialize:i=>i==="enabled"||i==="disabled"?i:"all"}),De=ls(),ce=I(f.apiKeys.all(),E.listRequest()),Ae=I(f.apiKeys.overview(y),E.overviewRequest(y)),pe=I(f.apiKeys.usage(y),E.usageRequest(y)),ue=P({mutationFn:E.create,invalidateKeys:[f.apiKeys.all(),f.apiKeys.overview(y),f.apiKeys.usage(y)],successToast:()=>({title:s("apiKeys.toast.keyCreated")}),errorToast:i=>({title:s("apiKeys.toast.createFailure",{message:i.message})})}),M=P({mutationFn:({id:i,...o})=>E.update(i,o),invalidateKeys:[f.apiKeys.all(),f.apiKeys.overview(y),f.apiKeys.usage(y)],successToast:()=>({title:s("apiKeys.toast.keyUpdated")}),errorToast:i=>({title:s("apiKeys.toast.updateFailure",{message:i.message})})}),xe=P({mutationFn:({id:i})=>E.delete(i),invalidateKeys:[f.apiKeys.all(),f.apiKeys.overview(y),f.apiKeys.usage(y)],successToast:()=>({title:s("apiKeys.toast.keyDeleted")}),errorToast:i=>({title:s("apiKeys.toast.deleteFailure",{message:i.message})})}),me=P({mutationFn:({id:i})=>E.reveal(i),errorToast:i=>({title:s("apiKeys.toast.revealFailure"),description:i.message})}),T=ce.data??[],R=Ae.data,C=pe.data??[],Te=T.some(i=>i.isWildcard),qe=T.filter(i=>i.isWildcard).length,Re=T.filter(i=>{var o;return!i.isWildcard&&(((o=i.allowedEndpoints)==null?void 0:o.length)??0)>0}).length,Fe=T.filter(i=>{var o;return!i.isWildcard&&(((o=i.allowedEndpoints)==null?void 0:o.length)??0)===0}).length,Oe=R?R.totalKeys.toLocaleString():"-",Se=R?R.enabledKeys.toLocaleString():"-",We=R?R.activeKeys.toLocaleString():"-",Le=d.useMemo(()=>T.filter(i=>{if(!(L==="all"||(L==="enabled"?i.enabled:!i.enabled)))return!1;const N=$.trim().toLowerCase();return N?[i.name,i.description??"",i.maskedKey??"",...i.allowedEndpoints??[]].join(" ").toLowerCase().includes(N):!0}),[T,$,L]),Me=d.useMemo(()=>{const i=C.map(o=>o.apiKeyName??s("apiKeys.analytics.unknownKey"));return{tooltip:{trigger:"axis"},grid:{left:60,right:20,top:40,bottom:40},xAxis:{type:"category",data:i,axisLabel:{interval:0,rotate:20}},yAxis:{type:"value"},series:[{name:s("apiKeys.analytics.requestsSeries"),type:"bar",data:C.map(o=>o.requests),itemStyle:{color:"hsl(var(--primary))"}}]}},[s,C]),Pe=d.useMemo(()=>{const i=C.map(o=>o.apiKeyName??s("apiKeys.analytics.unknownKey"));return{tooltip:{trigger:"axis"},legend:{data:[s("apiKeys.analytics.tokens.input"),s("apiKeys.analytics.tokens.output")]},grid:{left:60,right:20,top:50,bottom:40},xAxis:{type:"category",data:i,axisLabel:{interval:0,rotate:20}},yAxis:{type:"value"},series:[{name:s("apiKeys.analytics.tokens.input"),type:"bar",stack:"tokens",itemStyle:{color:"#22c55e"},data:C.map(o=>o.inputTokens)},{name:s("apiKeys.analytics.tokens.output"),type:"bar",stack:"tokens",itemStyle:{color:"#0ea5e9"},data:C.map(o=>o.outputTokens)}]}},[s,C]),he=d.useCallback(()=>{u(""),g(""),x([])},[]),Q=d.useCallback(i=>{a(i),i||he()},[he]),Ie=d.useCallback(async()=>{if(!l.trim()){t({title:s("apiKeys.errors.nameRequired"),variant:"error"});return}try{const i=await ue.mutateAsync({name:l.trim(),description:m.trim()||void 0,allowedEndpoints:c.length>0?c:void 0});n(i),Q(!1)}catch{}},[ue,Q,m,c,l,t,s]),ze=d.useCallback(async(i,o)=>{try{await M.mutateAsync({id:i,enabled:!o})}catch{}},[M]),$e=d.useCallback(async()=>{if(j){k(j.id);try{await xe.mutateAsync({id:j.id}),D(null)}catch{}finally{k(null)}}},[j,xe]),Qe=d.useCallback(async i=>{if(!O.has(i)){b(i);try{const o=await me.mutateAsync({id:i});A(N=>new Map(N).set(i,o.key))}catch{}finally{b(null)}}},[me,O]),He=d.useCallback(i=>{A(o=>{const N=new Map(o);return N.delete(i),N})},[]),Ve=d.useCallback(async i=>{try{await rs(i),t({title:s("apiKeys.toast.keyCopied"),variant:"success"})}catch(o){t({title:s("apiKeys.toast.copyFailure"),description:o instanceof Error?o.message:s("common.unknownError"),variant:"error"})}},[t,s]),Ge=d.useCallback(i=>{z(i),de(i.allowedEndpoints??[])},[]),Be=d.useCallback(async()=>{if(S)try{await M.mutateAsync({id:S.id,allowedEndpoints:W.length>0?W:null}),z(null)}catch{}},[S,W,M]),Ue=d.useCallback(i=>i?new Date(i).toLocaleString():s("common.noData"),[s]);return{activeKeysValue:We,availableEndpoints:De,deleteTarget:j,editEndpointsKey:S,editEndpointsSelection:W,enabledKeysValue:Se,filteredKeys:Le,formatDate:Ue,handleCopyKey:Ve,handleCreateDialogChange:Q,handleCreateKey:Ie,handleDeleteKey:$e,handleHideKey:He,handleOpenEditEndpoints:Ge,handleRevealKey:Qe,handleSaveEndpoints:Be,handleToggleEnabled:ze,hasWildcard:Te,isCreateDialogOpen:r,isDeleting:F,isRevealing:h,keys:T,keysQuery:ce,newKeyDescription:m,newKeyEndpoints:c,newKeyName:l,newlyCreatedKey:p,rangeDays:y,requestsChartOption:Me,restrictedCount:Re,revealedKeys:O,search:$,setDeleteTarget:D,setEditEndpointsKey:z,setEditEndpointsSelection:de,setNewKeyDescription:g,setNewKeyEndpoints:x,setNewKeyName:u,setNewlyCreatedKey:n,setRangeDays:q,setSearch:Ee,setStatusFilter:ke,statusFilter:L,tokensChartOption:Pe,totalKeysValue:Oe,unrestrictedCount:Fe,usage:C,usageQuery:pe,wildcardCount:qe}}function Ws(){const{t:s}=K(),t=ys(),r=s("apiKeys.summary.totalCount",{count:t.keys.length});return t.keysQuery.isLoading?e.jsx(ss,{}):e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx(ts,{icon:e.jsx(be,{className:"h-5 w-5","aria-hidden":"true"}),title:s("apiKeys.title"),description:s("apiKeys.description"),eyebrow:"Access Control",breadcrumb:"Gateway / API Keys",helper:s("apiKeys.helper"),badge:r,actions:e.jsxs("div",{className:"flex w-full flex-col gap-2 sm:w-auto sm:flex-row sm:flex-wrap sm:justify-end",children:[e.jsxs("div",{className:"rounded-lg border border-border bg-secondary px-3 py-2 text-xs text-muted-foreground",children:[s("apiKeys.summary.wildcard",{count:t.wildcardCount})," / ",s("apiKeys.summary.restricted",{count:t.restrictedCount})," / ",s("apiKeys.summary.unrestricted",{count:t.unrestrictedCount})]}),e.jsxs(v,{onClick:()=>t.handleCreateDialogChange(!0),className:"w-full sm:w-auto",children:[e.jsx(Ye,{className:"mr-2 h-4 w-4","aria-hidden":"true"}),s("apiKeys.createNew")]})]})}),e.jsx(us,{}),e.jsx(xs,{activeKeysValue:t.activeKeysValue,enabledKeysValue:t.enabledKeysValue,loading:t.usageQuery.isLoading,onRangeChange:t.setRangeDays,rangeDays:t.rangeDays,requestsChartOption:t.requestsChartOption,totalKeysValue:t.totalKeysValue,tokensChartOption:t.tokensChartOption,usageLength:t.usage.length}),e.jsx(ms,{filteredKeys:t.filteredKeys,formatDate:t.formatDate,hasWildcard:t.hasWildcard,isDeleting:t.isDeleting,isRevealing:t.isRevealing,keys:t.keys,onCopy:a=>void t.handleCopyKey(a),onDelete:t.setDeleteTarget,onEditEndpoints:t.handleOpenEditEndpoints,onFilterChange:t.setSearch,onHide:t.handleHideKey,onReveal:a=>void t.handleRevealKey(a),onStatusFilterChange:t.setStatusFilter,onToggleEnabled:(a,l)=>void t.handleToggleEnabled(a,l),restrictedCount:t.restrictedCount,revealedKeys:t.revealedKeys,search:t.search,statusFilter:t.statusFilter,unrestrictedCount:t.unrestrictedCount,wildcardCount:t.wildcardCount}),e.jsx(os,{availableEndpoints:t.availableEndpoints,isOpen:t.isCreateDialogOpen,keyDescription:t.newKeyDescription,keyName:t.newKeyName,onDescriptionChange:t.setNewKeyDescription,onEndpointsChange:t.setNewKeyEndpoints,onKeyNameChange:t.setNewKeyName,onOpenChange:t.handleCreateDialogChange,onSubmit:()=>void t.handleCreateKey(),selectedEndpoints:t.newKeyEndpoints}),e.jsx(ds,{createdKey:t.newlyCreatedKey,onClose:()=>t.setNewlyCreatedKey(null),onCopy:a=>void t.handleCopyKey(a)}),e.jsx(cs,{apiKey:t.editEndpointsKey,availableEndpoints:t.availableEndpoints,onClose:()=>t.setEditEndpointsKey(null),onEndpointsChange:t.setEditEndpointsSelection,onSave:()=>void t.handleSaveEndpoints(),selectedEndpoints:t.editEndpointsSelection}),e.jsx(ps,{deleteTarget:t.deleteTarget,isDeleting:t.isDeleting,onConfirm:()=>void t.handleDeleteKey(),onOpenChange:a=>{!a&&t.isDeleting===null&&t.setDeleteTarget(null)}})]})}export{Ws as default};
@@ -0,0 +1 @@
1
+ import{r as i,j as e,aa as le,ab as Le,ac as ie,ad as qe,ae as ce,af as Ae,ag as Me,S as H,ah as Pe,ai as De,V as Be}from"./vendor-OD8r2VI0.js";import{B as C,P as Oe}from"./PageHeader-BoMzY33X.js";import{P as K,a as Q}from"./PageState-CoBpDxLj.js";import{c as S,u as Fe,a as _e,b as $e,t as Ge,s as He,B as z}from"./index-Do-c7aim.js";import{S as Qe,a as ze,b as Ve,c as Ue,d as O}from"./select-Bjy18Ntu.js";import{E as Ke}from"./EChart-CTWV6r1m.js";import{P as me}from"./PageSection-DMHGizgh.js";import{S as Ye,C as Ze,T as Je}from"./Skeleton-BMLOZAD8.js";import{C as P,a as D}from"./card-DZKUcIo6.js";import{u as E}from"./i18n-CO7_kqjg.js";import{e as We}from"./charts-core-Bkq02SMi.js";import{u as w,q as I}from"./queryKeys-CQ-Y0kH9.js";import"./query-DeMZnAJS.js";import"./router-DwL4vhvg.js";import"./radix-Bg9QIv2e.js";import"./charts-react-08lL1GLe.js";import"./charts-engine-BCuhIgMH.js";const Y=i.forwardRef(({className:t,...s},a)=>e.jsx("div",{className:"relative w-full overflow-auto rounded-lg border border-border bg-background",children:e.jsx("table",{ref:a,className:S("w-full caption-bottom border-collapse text-sm",t),...s})}));Y.displayName="Table";const Z=i.forwardRef(({className:t,...s},a)=>e.jsx("thead",{ref:a,className:S("bg-muted/35 [&_tr]:border-b [&_tr]:border-border/60",t),...s}));Z.displayName="TableHeader";const J=i.forwardRef(({className:t,...s},a)=>e.jsx("tbody",{ref:a,className:S("[&_tr:last-child]:border-0",t),...s}));J.displayName="TableBody";const Xe=i.forwardRef(({className:t,...s},a)=>e.jsx("tfoot",{ref:a,className:S("border-t bg-muted/45 font-medium [&>tr]:last:border-b-0",t),...s}));Xe.displayName="TableFooter";const B=i.forwardRef(({className:t,...s},a)=>e.jsx("tr",{ref:a,className:S("border-b border-border/50 transition-all duration-150","hover:bg-primary/5 data-[state=selected]:bg-primary/10","group",t),...s}));B.displayName="TableRow";const p=i.forwardRef(({className:t,...s},a)=>e.jsx("th",{ref:a,className:S("h-12 px-4 text-left align-middle text-[11px] font-semibold uppercase tracking-[0.14em] text-muted-foreground/80","[&:has([role=checkbox])]:pr-0",t),...s}));p.displayName="TableHead";const b=i.forwardRef(({className:t,...s},a)=>e.jsx("td",{ref:a,className:S("px-4 py-3.5 align-middle text-sm","[&:has([role=checkbox])]:pr-0","group-hover:text-foreground transition-colors",t),...s}));b.displayName="TableCell";const et=i.forwardRef(({className:t,...s},a)=>e.jsx("caption",{ref:a,className:S("mt-4 text-sm text-muted-foreground",t),...s}));et.displayName="TableCaption";const F=15e3,V=6e4,T={requests:"#2563eb",input:"#059669",output:"#ea580c",cacheRead:"#7c3aed",cacheCreation:"#e11d48",latency:"#0891b2"};function M(t,s,a){return t==null?"-":`${t.toLocaleString(void 0,a)} ${s}`}function de(t){if(t==null)return"-";if(t<1024)return`${t} B`;const s=["KB","MB","GB","TB"];let a=t/1024,r=0;for(;a>=1024&&r<s.length-1;)a/=1024,r+=1;return`${a.toFixed(a>=100?0:a>=10?1:2)} ${s[r]}`}function tt(){return e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx("div",{className:"grid gap-4 sm:grid-cols-2 xl:grid-cols-3",children:Array.from({length:6}).map((t,s)=>e.jsx(Ye,{},s))}),e.jsx("div",{className:"grid gap-6 lg:grid-cols-2",children:Array.from({length:4}).map((t,s)=>e.jsx(Ze,{},s))}),e.jsx("div",{className:"rounded-lg border border-border",children:e.jsx("table",{className:"w-full",children:e.jsx("tbody",{children:Array.from({length:5}).map((t,s)=>e.jsx(Je,{columns:6},s))})})})]})}function st({dbSizeDisplay:t,memoryDisplay:s,selectedEndpointLabel:a,status:r,todayRequests:d}){const{t:o}=E();return e.jsxs("div",{className:"grid gap-4 xl:grid-cols-[minmax(0,1.4fr)_minmax(320px,0.9fr)]",children:[e.jsx(P,{children:e.jsx(D,{className:"pt-6",children:e.jsxs("div",{className:"flex flex-col gap-6 lg:flex-row lg:items-end lg:justify-between",children:[e.jsxs("div",{className:"max-w-2xl space-y-3",children:[e.jsxs("div",{className:"inline-flex items-center gap-1.5 rounded-full border border-primary/20 bg-accent px-3 py-1 text-xs font-semibold text-primary",children:[e.jsx(le,{className:"h-3.5 w-3.5","aria-hidden":"true"}),"Live Gateway"]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("h2",{className:"text-xl font-semibold text-foreground",children:a}),e.jsx("p",{className:"max-w-xl text-sm text-muted-foreground",children:o("dashboard.description")})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(C,{variant:"outline",className:"border-[hsl(var(--success)/0.3)] bg-[hsl(var(--success-bg))] text-[hsl(var(--success)/1)]",children:o("dashboard.status.listeningLabel")}),e.jsx(C,{variant:"secondary",children:a}),e.jsxs(C,{variant:"outline",children:[o("dashboard.labels.todayRequests"),": ",d.toLocaleString()]})]})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-3 lg:min-w-[320px] lg:flex-1",children:[e.jsx(U,{icon:e.jsx(Le,{className:"h-4 w-4","aria-hidden":"true"}),label:o("dashboard.labels.activeRequests"),value:((r==null?void 0:r.activeRequests)??0).toLocaleString()}),e.jsx(U,{icon:e.jsx(ie,{className:"h-4 w-4","aria-hidden":"true"}),label:o("dashboard.labels.database"),value:t}),e.jsx(U,{icon:e.jsx(qe,{className:"h-4 w-4","aria-hidden":"true"}),label:o("dashboard.labels.memory"),value:s})]})]})})}),e.jsx(P,{children:e.jsx(D,{className:"pt-6",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:"Gateway runtime"}),e.jsxs("p",{className:"mt-1.5 text-xl font-semibold text-foreground",children:[(r==null?void 0:r.host)??"0.0.0.0",":",(r==null?void 0:r.port)??"-"]})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsx(_,{label:o("dashboard.labels.providers"),value:((r==null?void 0:r.providers)??0).toLocaleString()}),e.jsx(_,{label:o("dashboard.labels.activeClientAddresses"),value:((r==null?void 0:r.activeClientAddresses)??0).toLocaleString()}),e.jsx(_,{label:o("dashboard.labels.activeClientSessions"),value:((r==null?void 0:r.activeClientSessions)??0).toLocaleString()}),e.jsx(_,{label:o("dashboard.labels.uniqueClientSessionsLastHour"),value:((r==null?void 0:r.uniqueClientSessionsLastHour)??0).toLocaleString()})]})]})})})]})}function at({overview:t}){const{t:s}=E();return e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2 xl:grid-cols-3",children:[e.jsx(L,{icon:e.jsx(ce,{className:"h-5 w-5"}),title:s("dashboard.cards.todayRequests"),value:(t==null?void 0:t.today.requests)??0,suffix:s("common.units.request"),iconClass:"bg-blue-50 text-blue-600 dark:bg-blue-950 dark:text-blue-400"}),e.jsx(L,{icon:e.jsx(Ae,{className:"h-5 w-5"}),title:s("dashboard.cards.todayInput"),value:(t==null?void 0:t.today.inputTokens)??0,suffix:s("common.units.token"),iconClass:"bg-emerald-50 text-emerald-600 dark:bg-emerald-950 dark:text-emerald-400"}),e.jsx(L,{icon:e.jsx(Me,{className:"h-5 w-5"}),title:s("dashboard.cards.todayCacheRead"),value:(t==null?void 0:t.today.cacheReadTokens)??0,suffix:s("common.units.token"),iconClass:"bg-violet-50 text-violet-600 dark:bg-violet-950 dark:text-violet-400"}),e.jsx(L,{icon:e.jsx(le,{className:"h-5 w-5"}),title:s("dashboard.cards.todayCacheCreation"),value:(t==null?void 0:t.today.cacheCreationTokens)??0,suffix:s("common.units.token"),iconClass:"bg-rose-50 text-rose-600 dark:bg-rose-950 dark:text-rose-400"}),e.jsx(L,{icon:e.jsx(H,{className:"h-5 w-5"}),title:s("dashboard.cards.todayOutput"),value:(t==null?void 0:t.today.outputTokens)??0,suffix:s("common.units.token"),iconClass:"bg-amber-50 text-amber-600 dark:bg-amber-950 dark:text-amber-400"}),e.jsx(L,{icon:e.jsx(Pe,{className:"h-5 w-5"}),title:s("dashboard.cards.avgLatency"),value:(t==null?void 0:t.today.avgLatencyMs)??0,suffix:s("common.units.ms"),iconClass:"bg-cyan-50 text-cyan-600 dark:bg-cyan-950 dark:text-cyan-400"})]})}function rt({busiestDay:t,fastestTtftModel:s,topModel:a,totalRequestsInRange:r}){const{t:d}=E();return e.jsxs("div",{className:"grid gap-4 lg:grid-cols-4",children:[e.jsx($,{label:d("dashboard.insights.totalRequests"),value:r.toLocaleString(),hint:d("dashboard.insights.totalRequestsHint")}),e.jsx($,{label:d("dashboard.insights.busiestDay"),value:t?t.date:"-",hint:t?d("dashboard.insights.busiestDayHint",{value:t.requestCount.toLocaleString()}):d("common.noData")}),e.jsx($,{label:d("dashboard.insights.topModel"),value:a?`${a.provider}/${a.model}`:"-",hint:a?d("dashboard.insights.topModelHint",{value:a.requests.toLocaleString()}):d("common.noData")}),e.jsx($,{label:d("dashboard.insights.fastestTtft"),value:s?`${s.provider}/${s.model}`:"-",hint:s?M(s.avgTtftMs,d("common.units.ms")):d("common.noData")})]})}function ot({dailyEmpty:t,dailyOption:s,dailyPending:a,models:r,modelRequestsOption:d,modelUsagePending:o,ttftOption:m,tpotOption:R}){const{t:l}=E();return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid gap-6 lg:grid-cols-2",children:[e.jsx(G,{title:l("dashboard.charts.requestsTitle"),description:l("dashboard.charts.requestsDesc"),loading:a,option:s,empty:t,emptyText:l("dashboard.charts.empty")}),e.jsx(G,{title:l("dashboard.charts.modelTitle"),description:l("dashboard.charts.modelDesc"),loading:o,option:d,empty:!r.length,emptyText:l("dashboard.charts.empty")})]}),e.jsxs("div",{className:"grid gap-6 lg:grid-cols-2",children:[e.jsx(G,{title:l("dashboard.charts.ttftTitle"),description:l("dashboard.charts.ttftDesc"),loading:o,option:m,empty:!r.some(c=>c.avgTtftMs!=null&&c.avgTtftMs>0),emptyText:l("dashboard.charts.ttftEmpty")}),e.jsx(G,{title:l("dashboard.charts.tpotTitle"),description:l("dashboard.charts.tpotDesc"),loading:o,option:R,empty:!r.some(c=>c.avgTpotMs!=null&&c.avgTpotMs>0),emptyText:l("dashboard.charts.tpotEmpty")})]})]})}function nt({models:t,loading:s}){const{t:a}=E();return e.jsx(me,{title:a("dashboard.modelTable.title"),description:a("dashboard.modelTable.description"),children:s?e.jsx(K,{compact:!0,label:a("common.loadingShort")}):t.length===0?e.jsx(Q,{compact:!0,icon:e.jsx(H,{className:"h-5 w-5","aria-hidden":"true"}),title:a("dashboard.modelTable.empty")}):e.jsx("div",{className:"overflow-auto rounded-lg border border-border",children:e.jsxs(Y,{children:[e.jsx(Z,{children:e.jsxs(B,{children:[e.jsx(p,{children:a("dashboard.modelTable.columns.model")}),e.jsx(p,{className:"text-right",children:a("dashboard.modelTable.columns.requests")}),e.jsx(p,{className:"text-right",children:a("dashboard.modelTable.columns.latency")}),e.jsx(p,{className:"text-right",children:a("dashboard.modelTable.columns.ttft")}),e.jsx(p,{className:"text-right",children:a("dashboard.modelTable.columns.tpot")})]})}),e.jsx(J,{children:t.map(r=>e.jsxs(B,{children:[e.jsx(b,{children:e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"font-medium",children:r.provider}),e.jsx("span",{className:"text-xs text-muted-foreground",children:r.model})]})}),e.jsx(b,{className:"text-right font-medium",children:r.requests.toLocaleString()}),e.jsx(b,{className:"text-right",children:M(r.avgLatencyMs,a("common.units.ms"))}),e.jsx(b,{className:"text-right",children:M(r.avgTtftMs,a("common.units.ms"))}),e.jsx(b,{className:"text-right",children:M(r.avgTpotMs,a("common.units.msPerToken"),{maximumFractionDigits:2})})]},`${r.provider}/${r.model}`))})]})})})}function dt({records:t,loading:s}){const{t:a}=E(),r=t.filter(o=>!o.error&&(o.status_code??200)<400).length,d=t.filter(o=>o.error||(o.status_code??200)>=400).length;return e.jsx(me,{title:a("dashboard.recent.title"),description:a("dashboard.recent.subtitle",{count:5}),actions:t.length>0?e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(C,{variant:"secondary",children:t.length}),e.jsxs(C,{variant:"outline",className:"border-[hsl(var(--success)/0.3)] bg-[hsl(var(--success-bg))] text-[hsl(var(--success)/1)]",children:[a("common.status.success"),": ",r]}),e.jsxs(C,{variant:"outline",className:"border-destructive/30 bg-destructive/10 text-destructive",children:[a("common.status.error"),": ",d]})]}):null,children:s?e.jsx(K,{compact:!0,label:a("dashboard.recent.loading")}):t.length===0?e.jsx(Q,{compact:!0,icon:e.jsx(ce,{className:"h-5 w-5","aria-hidden":"true"}),title:a("dashboard.recent.empty")}):e.jsx("div",{className:"overflow-auto rounded-lg border border-border",children:e.jsxs(Y,{children:[e.jsx(Z,{children:e.jsxs(B,{children:[e.jsx(p,{children:a("dashboard.recent.columns.time")}),e.jsx(p,{children:a("dashboard.recent.columns.endpoint")}),e.jsx(p,{children:a("dashboard.recent.columns.provider")}),e.jsx(p,{children:a("dashboard.recent.columns.route")}),e.jsx(p,{className:"text-right",children:a("dashboard.recent.columns.latency")}),e.jsx(p,{children:a("dashboard.recent.columns.status")})]})}),e.jsx(J,{children:t.map(o=>e.jsxs(B,{children:[e.jsx(b,{children:e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"text-xs font-medium",children:new Date(o.timestamp).toLocaleString()}),e.jsxs("span",{className:"text-[11px] text-muted-foreground",children:["#",o.id]})]})}),e.jsx(b,{children:e.jsx(C,{variant:"outline",className:"text-[11px]",children:o.endpoint==="anthropic"?a("logs.table.endpointAnthropic"):o.endpoint==="openai"?a("logs.table.endpointOpenAI"):o.endpoint})}),e.jsx(b,{children:e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"font-medium",children:o.provider}),e.jsx("span",{className:"text-[11px] text-muted-foreground",children:o.stream?"stream":"sync"})]})}),e.jsx(b,{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:o.client_model??a("dashboard.recent.routePlaceholder")}),e.jsx("span",{children:"->"}),e.jsx("span",{className:"font-medium text-foreground",children:o.model})]}),o.error?e.jsx("span",{className:"truncate text-destructive",children:o.error}):null]})}),e.jsx(b,{className:"text-right font-medium",children:M(o.latency_ms,a("common.units.ms"))}),e.jsx(b,{children:e.jsx(C,{variant:o.error?"destructive":"default",className:"min-w-14 justify-center",children:(o.status_code??(o.error?500:200)).toString()})})]},o.id))})]})})})}function U({icon:t,label:s,value:a}){return e.jsxs("div",{className:"rounded-lg border border-border bg-secondary px-4 py-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[e.jsx("span",{className:"flex h-6 w-6 items-center justify-center rounded-md bg-primary/10 text-primary",children:t}),s]}),e.jsx("p",{className:"mt-2 text-lg font-semibold text-foreground",children:a})]})}function _({label:t,value:s}){return e.jsxs("div",{className:"rounded-lg border border-border bg-secondary px-3 py-2.5",children:[e.jsx("p",{className:"text-[11px] text-muted-foreground",children:t}),e.jsx("p",{className:"mt-1 text-sm font-semibold text-foreground",children:s})]})}function L({icon:t,iconClass:s,suffix:a,title:r,value:d}){return e.jsx(P,{children:e.jsxs(D,{className:"pt-5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground",children:r}),t?e.jsx("div",{className:S("flex h-9 w-9 items-center justify-center rounded-lg",s),children:t}):null]}),e.jsxs("p",{className:"mt-3 text-2xl font-bold text-foreground",children:[d.toLocaleString(),a?e.jsx("span",{className:"ml-1.5 text-sm font-normal text-muted-foreground",children:a}):null]})]})})}function $({label:t,value:s,hint:a}){return e.jsx(P,{children:e.jsxs(D,{className:"pt-4",children:[e.jsx("p",{className:"text-[11px] font-medium uppercase tracking-wider text-muted-foreground",children:t}),e.jsx("p",{className:"mt-2 line-clamp-1 text-sm font-semibold text-foreground",children:s}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:a})]})})}function G({description:t,empty:s,emptyText:a,loading:r,option:d,title:o}){const{t:m}=E();return e.jsx(P,{children:e.jsxs(D,{className:"space-y-4 pt-5",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-semibold",children:o}),e.jsx("p",{className:"mt-0.5 text-xs text-muted-foreground",children:t})]}),r?e.jsx(K,{compact:!0,className:"min-h-[320px]",label:m("common.loadingShort")}):s?e.jsx(Q,{compact:!0,className:"min-h-[320px]",icon:e.jsx(H,{className:"h-5 w-5","aria-hidden":"true"}),title:a??m("dashboard.charts.empty")}):e.jsx(Ke,{echarts:We,option:d,className:"h-[40vh] min-h-[280px] max-h-[420px]",notMerge:!0,lazyUpdate:!0})]})})}function lt(){var W,X,ee,te,se,ae,re,oe;const{t}=E(),{pushToast:s}=Fe(),[a,r]=_e(He.dashboard.endpointFilter,"all"),[d,o]=i.useState(!1),m=a==="all"?void 0:a,R=w(I.customEndpoints.all(),{url:"/api/custom-endpoints",method:"GET"},{refetchInterval:V,refetchIntervalInBackground:!0}),l=w(I.stats.overview(a),{url:"/api/stats/overview",method:"GET",params:m?{endpoint:m}:void 0},{refetchInterval:F,refetchIntervalInBackground:!0}),c=w(I.stats.daily(14,a),{url:"/api/stats/daily",method:"GET",params:{days:14,...m?{endpoint:m}:{}}},{refetchInterval:V,refetchIntervalInBackground:!0}),y=w(I.stats.model(7,6,a),{url:"/api/stats/model",method:"GET",params:{days:7,limit:6,...m?{endpoint:m}:{}}},{refetchInterval:V,refetchIntervalInBackground:!0}),g=w(I.status.byEndpoint(a),{url:"/api/status",method:"GET",params:m?{endpoint:m}:void 0},{refetchInterval:F,refetchIntervalInBackground:!0}),x=w(I.db.info(),{url:"/api/db/info",method:"GET"},{refetchInterval:F,refetchIntervalInBackground:!0}),N=w(I.logs.recent(a),{url:"/api/logs",method:"GET",params:{limit:5,...m?{endpoint:m}:{}}},{refetchInterval:F,refetchIntervalInBackground:!0});i.useEffect(()=>{l.isError&&l.error&&s({title:t("dashboard.toast.overviewError"),description:l.error.message,variant:"error"})},[l.error,l.isError,s,t]),i.useEffect(()=>{c.isError&&c.error&&s({title:t("dashboard.toast.dailyError"),description:c.error.message,variant:"error"})},[c.error,c.isError,s,t]),i.useEffect(()=>{y.isError&&y.error&&s({title:t("dashboard.toast.modelError"),description:y.error.message,variant:"error"})},[y.error,y.isError,s,t]),i.useEffect(()=>{g.isError&&g.error&&s({title:t("dashboard.toast.statusError"),description:g.error.message,variant:"error"})},[g.error,g.isError,s,t]),i.useEffect(()=>{x.isError&&x.error&&s({title:t("dashboard.toast.dbError"),description:x.error.message,variant:"error"})},[x.error,x.isError,s,t]),i.useEffect(()=>{N.isError&&N.error&&s({title:t("dashboard.toast.recentError"),description:N.error.message,variant:"error"})},[N.error,N.isError,s,t]);const he=i.useCallback(async()=>{await Promise.all([R.refetch(),l.refetch(),c.refetch(),y.refetch(),g.refetch(),x.refetch(),N.refetch()])},[R,x,c,N,y,l,g]),ue=i.useCallback(async()=>{if(!d){o(!0);try{await $e.post("/api/db/compact"),await x.refetch(),s({title:t("dashboard.toast.compactSuccess.title"),description:t("dashboard.toast.compactSuccess.desc"),variant:"success"})}catch(n){const h=Ge(n);s({title:t("dashboard.toast.compactError.title"),description:h.message,variant:"error"})}finally{o(!1)}}},[d,x,s,t]),xe=l.data,v=c.data??[],u=y.data??[],pe=g.data,k=x.data,be=((W=N.data)==null?void 0:W.items)??[],ge=a==="all"?t("dashboard.filters.endpointAll"):a==="anthropic"?t("dashboard.filters.endpointAnthropic"):a==="openai"?t("dashboard.filters.endpointOpenAI"):((te=(ee=(X=R.data)==null?void 0:X.endpoints)==null?void 0:ee.find(n=>n.id===a))==null?void 0:te.label)||a,fe=v.reduce((n,h)=>n+h.requestCount,0),je=v.reduce((n,h)=>!n||h.requestCount>n.requestCount?h:n,null),ye=u[0],Ne=u.filter(n=>n.avgTtftMs!=null&&n.avgTtftMs>0).sort((n,h)=>(n.avgTtftMs??Number.POSITIVE_INFINITY)-(h.avgTtftMs??Number.POSITIVE_INFINITY))[0],ve=R.isFetching||l.isFetching||c.isFetching||y.isFetching||g.isFetching||x.isFetching||N.isFetching,Te=l.isPending||g.isPending||x.isPending,Se=((se=l.error)==null?void 0:se.message)??((ae=g.error)==null?void 0:ae.message)??((re=x.error)==null?void 0:re.message)??null,Ee=k?de(k.totalBytes??k.sizeBytes):"-",Ce=de(k==null?void 0:k.memoryRssBytes),Re=i.useMemo(()=>{const n=v.map(j=>j.date),h=t("dashboard.charts.barRequests"),q=t("dashboard.charts.lineInput"),A=t("dashboard.charts.lineOutput"),f=t("dashboard.charts.lineCacheRead"),ne=t("dashboard.charts.lineCacheCreation");return{tooltip:{trigger:"axis"},legend:{data:[h,q,A,f,ne]},grid:{left:56,right:28,top:56,bottom:54},xAxis:{type:"category",data:n},yAxis:{type:"value"},series:[{name:h,type:"bar",data:v.map(j=>j.requestCount),itemStyle:{color:T.requests,borderRadius:[6,6,0,0]}},{name:q,type:"line",smooth:!0,data:v.map(j=>j.inputTokens),itemStyle:{color:T.input},lineStyle:{width:2}},{name:A,type:"line",smooth:!0,data:v.map(j=>j.outputTokens),itemStyle:{color:T.output},lineStyle:{width:2}},{name:f,type:"line",smooth:!0,data:v.map(j=>j.cacheReadTokens),itemStyle:{color:T.cacheRead},lineStyle:{width:2}},{name:ne,type:"line",smooth:!0,data:v.map(j=>j.cacheCreationTokens),itemStyle:{color:T.cacheCreation},lineStyle:{width:2}}]}},[v,t]),ke=i.useMemo(()=>{const n=u.map(f=>`${f.provider}/${f.model}`),h=t("dashboard.charts.barRequests"),q=t("dashboard.charts.lineInput"),A=t("dashboard.charts.lineOutput");return{tooltip:{trigger:"axis"},legend:{data:[h,q,A]},grid:{left:72,right:52,top:56,bottom:96},xAxis:{type:"category",data:n,axisLabel:{rotate:28}},yAxis:[{type:"value",name:h},{type:"value",name:t("dashboard.charts.axisTokens"),position:"right"}],series:[{name:h,type:"bar",data:u.map(f=>f.requests),itemStyle:{color:T.requests,borderRadius:[6,6,0,0]}},{name:q,type:"line",yAxisIndex:1,smooth:!0,data:u.map(f=>f.inputTokens??0),itemStyle:{color:T.input}},{name:A,type:"line",yAxisIndex:1,smooth:!0,data:u.map(f=>f.outputTokens??0),itemStyle:{color:T.output}}]}},[u,t]),we=i.useMemo(()=>({tooltip:{trigger:"axis"},grid:{left:72,right:40,top:56,bottom:96},xAxis:{type:"category",data:u.map(n=>`${n.provider}/${n.model}`),axisLabel:{rotate:28}},yAxis:{type:"value",name:t("dashboard.charts.ttftAxis")},series:[{name:t("dashboard.charts.ttftLabel"),type:"bar",data:u.map(n=>n.avgTtftMs??0),itemStyle:{color:T.latency,borderRadius:[6,6,0,0]}}]}),[u,t]),Ie=i.useMemo(()=>({tooltip:{trigger:"axis"},grid:{left:72,right:40,top:56,bottom:96},xAxis:{type:"category",data:u.map(n=>`${n.provider}/${n.model}`),axisLabel:{rotate:28}},yAxis:{type:"value",name:t("dashboard.charts.tpotAxis")},series:[{name:t("dashboard.charts.tpotLabel"),type:"bar",data:u.map(n=>n.avgTpotMs??0),itemStyle:{color:T.output,borderRadius:[6,6,0,0]}}]}),[u,t]);return{compacting:d,customEndpoints:((oe=R.data)==null?void 0:oe.endpoints)??[],daily:v,dailyOption:Re,dailyPending:c.isPending,dbInfo:k,dbSizeDisplay:Ee,endpointFilter:a,fastestTtftModel:Ne,handleCompact:ue,handleRefresh:he,bootstrapError:Se,isBootstrapping:Te,isRefreshing:ve,latestLogsPending:N.isPending,memoryDisplay:Ce,modelRequestsOption:ke,modelUsagePending:y.isPending,models:u,overview:xe,recentLogs:be,selectedEndpointLabel:ge,setEndpointFilter:r,status:pe,topModel:ye,totalRequestsInRange:fe,busiestDay:je,ttftOption:we,tpotOption:Ie}}function Ct(){var a;const{t}=E(),s=lt();return e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx(Oe,{icon:e.jsx(H,{className:"h-5 w-5","aria-hidden":"true"}),title:t("nav.dashboard"),description:t("dashboard.description"),badge:s.selectedEndpointLabel,eyebrow:"Operations",breadcrumb:"Gateway / Dashboard",helper:t("dashboard.charts.requestsDesc"),actions:e.jsxs("div",{className:"flex w-full flex-col gap-2 sm:w-auto sm:flex-row sm:flex-wrap sm:items-center sm:justify-end",children:[e.jsxs("div",{className:"rounded-lg border border-border bg-secondary px-3 py-2 text-xs text-muted-foreground",children:[t("dashboard.filters.endpoint")," · ",s.selectedEndpointLabel]}),e.jsxs(Qe,{value:s.endpointFilter,onValueChange:s.setEndpointFilter,children:[e.jsx(ze,{className:"w-full sm:w-[168px]",children:e.jsx(Ve,{})}),e.jsxs(Ue,{children:[e.jsx(O,{value:"all",children:t("dashboard.filters.endpointAll")}),e.jsx(O,{value:"anthropic",children:t("dashboard.filters.endpointAnthropic")}),e.jsx(O,{value:"openai",children:t("dashboard.filters.endpointOpenAI")}),s.customEndpoints.map(r=>e.jsx(O,{value:r.id,children:r.label||r.id},r.id))]})]}),e.jsxs(z,{variant:"outline",size:"sm",onClick:()=>void s.handleRefresh(),disabled:s.isRefreshing,className:"w-full sm:w-auto",children:[e.jsx(De,{className:S("mr-2 h-4 w-4",s.isRefreshing&&"animate-spin"),"aria-hidden":"true"}),s.isRefreshing?t("common.actions.refreshing"):t("common.actions.refresh")]}),e.jsxs(z,{variant:"outline",size:"sm",onClick:()=>void s.handleCompact(),disabled:s.compacting,className:"w-full sm:w-auto",children:[e.jsx(ie,{className:"mr-2 h-4 w-4","aria-hidden":"true"}),s.compacting?t("dashboard.actions.compacting"):t("dashboard.actions.compact")]})]})}),s.isBootstrapping?e.jsx(tt,{}):s.bootstrapError?e.jsx(Q,{icon:e.jsx(Be,{className:"h-5 w-5","aria-hidden":"true"}),tone:"danger",title:t("common.status.error"),description:s.bootstrapError,action:e.jsx(z,{variant:"outline",onClick:()=>void s.handleRefresh(),children:t("common.actions.refresh")})}):e.jsxs(e.Fragment,{children:[e.jsx(st,{dbSizeDisplay:s.dbSizeDisplay,memoryDisplay:s.memoryDisplay,selectedEndpointLabel:s.selectedEndpointLabel,status:s.status,todayRequests:((a=s.overview)==null?void 0:a.today.requests)??0}),e.jsx(at,{overview:s.overview}),e.jsx(rt,{busiestDay:s.busiestDay,fastestTtftModel:s.fastestTtftModel,topModel:s.topModel,totalRequestsInRange:s.totalRequestsInRange}),e.jsx(ot,{dailyEmpty:!s.daily.length,dailyOption:s.dailyOption,dailyPending:s.dailyPending,models:s.models,modelRequestsOption:s.modelRequestsOption,modelUsagePending:s.modelUsagePending,ttftOption:s.ttftOption,tpotOption:s.tpotOption}),e.jsx(nt,{models:s.models,loading:s.modelUsagePending}),e.jsx(dt,{records:s.recentLogs,loading:s.latestLogsPending})]})]})}export{Ct as default};
@@ -0,0 +1 @@
1
+ import{r,j as t,a7 as g}from"./vendor-OD8r2VI0.js";import{F as u,G as n,H as d,J as b,K as l,M as y,O as i}from"./radix-Bg9QIv2e.js";import{c as o}from"./index-Do-c7aim.js";const k=u,N=b,c=r.forwardRef(({className:a,...e},s)=>t.jsx(i,{ref:s,className:o("fixed inset-0 z-50 bg-background/80 backdrop-blur-sm data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",a),...e}));c.displayName=i.displayName;const p=r.forwardRef(({className:a,children:e,...s},x)=>t.jsxs(N,{children:[t.jsx(c,{}),t.jsxs(l,{ref:x,className:o("fixed left-[50%] top-[50%] z-50 flex max-h-[85vh] w-full max-w-lg translate-x-[-50%] translate-y-[-50%] flex-col gap-4 rounded-lg border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%]",a),...s,children:[e,t.jsxs(y,{className:"absolute right-4 top-4 rounded-2xl border border-transparent p-2 opacity-70 ring-offset-background transition-all hover:border-border hover:bg-accent hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground",children:[t.jsx(g,{className:"h-4 w-4"}),t.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));p.displayName=l.displayName;const m=({className:a,...e})=>t.jsx("div",{className:o("flex shrink-0 flex-col space-y-1.5 text-center sm:text-left",a),...e});m.displayName="DialogHeader";const f=({className:a,...e})=>t.jsx("div",{className:o("flex shrink-0 flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",a),...e});f.displayName="DialogFooter";const j=r.forwardRef(({className:a,...e},s)=>t.jsx(n,{ref:s,className:o("text-lg font-semibold leading-none tracking-[-0.02em]",a),...e}));j.displayName=n.displayName;const h=r.forwardRef(({className:a,...e},s)=>t.jsx(d,{ref:s,className:o("text-sm leading-6 text-muted-foreground",a),...e}));h.displayName=d.displayName;function R({children:a,className:e}){return t.jsx(p,{className:o("gap-0 overflow-hidden p-0",e),children:a})}function A({children:a,className:e}){return t.jsx("div",{className:o("border-b border-border bg-secondary px-6 py-5",e),children:t.jsx(m,{children:a})})}function C({children:a,className:e}){return t.jsx("div",{className:o("min-h-0 overflow-y-auto px-6 py-5",e),children:a})}function z({children:a,className:e}){return t.jsx(f,{className:o("border-t border-border bg-secondary px-6 py-4",e),children:a})}export{R as A,k as D,A as a,j as b,h as c,C as d,z as e};
@@ -0,0 +1 @@
1
+ import{_ as a}from"./charts-react-08lL1GLe.js";import{u as s,i as l,a as t,b as i,c as n,d as o,f as r,g as $}from"./charts-core-Bkq02SMi.js";s([l,t,i,n,o,r,$]);const e=a;export{e as E};
@@ -0,0 +1 @@
1
+ import{r as v,j as e,ai as R,am as M,an as I,V as T,ao as V,ap as q,aq as B,a0 as D}from"./vendor-OD8r2VI0.js";import{P as K,B as c}from"./PageHeader-BoMzY33X.js";import{P as G}from"./PageSection-DMHGizgh.js";import{P as Q,a as $}from"./PageState-CoBpDxLj.js";import{u as H,q as J}from"./queryKeys-CQ-Y0kH9.js";import{u as O,B as x,c as p}from"./index-Do-c7aim.js";import{C as N,a as y}from"./card-DZKUcIo6.js";import{I as U}from"./input-CJmvMsFH.js";import{S as _,a as W,b as X,c as Y,d as g}from"./select-Bjy18Ntu.js";import{u as z}from"./i18n-CO7_kqjg.js";import"./query-DeMZnAJS.js";import"./router-DwL4vhvg.js";import"./radix-Bg9QIv2e.js";function Z(s){const a=Date.now()-s,n=Math.abs(a),t=60*1e3,m=60*t,u=24*m;if(n<t){const o=Math.max(Math.round(n/1e3),1);return a>=0?`${o}s ago`:`in ${o}s`}if(n<m){const o=Math.round(n/t);return a>=0?`${o}m ago`:`in ${o}m`}if(n<u){const o=Math.round(n/m);return a>=0?`${o}h ago`:`in ${o}h`}const l=Math.round(n/u);return a>=0?`${l}d ago`:`in ${l}d`}function ee(s){return new Date(s).toLocaleString()}const se={info:"secondary",warn:"outline",error:"destructive"};function fe(){var L,A,P;const{t:s}=z(),{pushToast:i}=O(),[a,n]=v.useState(null),[t,m]=v.useState({level:"",type:""}),u=v.useMemo(()=>({limit:50,cursor:a??void 0,level:t.level||void 0,type:t.type.trim()||void 0}),[a,t.level,t.type]),l=H(J.events.list(u),{url:"/api/events",method:"GET",params:u});v.useEffect(()=>{l.isError&&l.error&&i({title:s("events.toast.loadFailure",{message:l.error.message}),variant:"error"})},[l.error,l.isError,i,s]);const o=()=>{n(null),m({level:"",type:""})},d=((L=l.data)==null?void 0:L.events)??[],k=((A=l.data)==null?void 0:A.nextCursor)??null,F=l.isLoading,j=l.isFetching&&!l.isLoading,h=v.useMemo(()=>{const r=[];return t.level&&r.push(s(`events.levels.${t.level}`)),t.type.trim()&&r.push(t.type.trim()),r},[t.level,t.type,s]),C=d.filter(r=>r.level==="info").length,S=d.filter(r=>r.level==="warn").length,E=d.filter(r=>r.level==="error").length;return e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx(K,{icon:e.jsx(M,{className:"h-5 w-5","aria-hidden":"true"}),title:s("events.title"),description:s("events.description"),eyebrow:"Audit",breadcrumb:"Gateway / Events",helper:s("events.filters.title"),badge:d.length>0?`${d.length} events`:void 0,actions:e.jsxs("div",{className:"flex w-full flex-col gap-2 sm:w-auto sm:flex-row sm:flex-wrap sm:justify-end",children:[e.jsx("div",{className:"rounded-lg border border-border bg-secondary px-3 py-2 text-xs text-muted-foreground",children:s(a?"events.actions.older":"events.actions.newest")}),e.jsxs(x,{variant:"outline",size:"sm",onClick:()=>void l.refetch(),disabled:j,className:"w-full sm:w-auto",children:[e.jsx(R,{className:p("mr-2 h-4 w-4",j&&"animate-spin"),"aria-hidden":"true"}),s(j?"common.actions.refreshing":"common.actions.refresh")]})]})}),e.jsxs("div",{className:"grid gap-4 sm:grid-cols-3",children:[e.jsx(w,{icon:e.jsx(I,{className:"h-4 w-4","aria-hidden":"true"}),title:s("events.levels.info"),value:C.toLocaleString(),tone:"emerald"}),e.jsx(w,{icon:e.jsx(T,{className:"h-4 w-4","aria-hidden":"true"}),title:s("events.levels.warn"),value:S.toLocaleString(),tone:"amber"}),e.jsx(w,{icon:e.jsx(V,{className:"h-4 w-4","aria-hidden":"true"}),title:s("events.levels.error"),value:E.toLocaleString(),tone:"rose"})]}),e.jsx(N,{"data-testid":"events-filters-card",className:"overflow-hidden",children:e.jsx(y,{className:"pt-5",children:e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"flex flex-col gap-3 lg:flex-row lg:items-center lg:justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-semibold text-foreground",children:[e.jsx(q,{className:"h-4 w-4 text-primary","aria-hidden":"true"}),s("events.filters.title"),e.jsx(c,{variant:"outline",children:d.length})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("events.description")})]}),e.jsxs("div",{className:"grid gap-2 sm:flex sm:flex-wrap sm:items-center",children:[h.length>0?e.jsx(x,{variant:"ghost",size:"sm",onClick:o,className:"w-full sm:w-auto",children:s("common.actions.reset")}):null,e.jsxs(x,{variant:"outline",size:"sm",disabled:!a,onClick:()=>n(null),className:"w-full sm:w-auto",children:[e.jsx(B,{className:"mr-1 h-4 w-4","aria-hidden":"true"}),s("events.actions.newest")]}),e.jsxs(x,{variant:"outline",size:"sm",disabled:!k,onClick:()=>n(k),className:"w-full sm:w-auto",children:[s("events.actions.older"),e.jsx(D,{className:"ml-1 h-4 w-4","aria-hidden":"true"})]})]})]}),e.jsxs("div",{className:"flex flex-col gap-2 md:flex-row md:flex-wrap md:items-center",children:[e.jsxs(_,{value:t.level,onValueChange:r=>{n(null),m(b=>({...b,level:r==="all"?"":r}))},children:[e.jsx(W,{className:"w-full md:w-[160px]",children:e.jsx(X,{placeholder:s("events.filters.allLevels")})}),e.jsxs(Y,{children:[e.jsx(g,{value:"all",children:s("events.filters.allLevels")}),e.jsx(g,{value:"info",children:s("events.levels.info")}),e.jsx(g,{value:"warn",children:s("events.levels.warn")}),e.jsx(g,{value:"error",children:s("events.levels.error")})]})]}),e.jsx(U,{className:"w-full md:w-[220px]",placeholder:s("events.filters.typePlaceholder"),value:t.type,onChange:r=>{n(null),m(b=>({...b,type:r.target.value}))}}),e.jsx(x,{variant:"ghost",size:"sm",onClick:o,disabled:h.length===0,className:"w-full md:w-auto",children:s("common.actions.reset")})]}),h.length>0?e.jsx("div",{className:"flex flex-wrap gap-2",children:h.map(r=>e.jsx(c,{variant:"secondary",children:r},r))}):null]})})}),e.jsx(G,{title:s("events.title"),description:s(a?"events.actions.older":"events.actions.newest"),actions:d.length>0?e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs(c,{variant:"outline",className:"border-blue-200 bg-blue-50 text-blue-700 dark:border-blue-800 dark:bg-blue-950/30 dark:text-blue-300",children:[s("events.levels.info"),": ",C]}),e.jsxs(c,{variant:"outline",className:"border-amber-200 bg-amber-50 text-amber-700 dark:border-amber-800 dark:bg-amber-950/30 dark:text-amber-300",children:[s("events.levels.warn"),": ",S]}),e.jsxs(c,{variant:"outline",className:"border-rose-200 bg-rose-50 text-rose-700 dark:border-rose-800 dark:bg-rose-950/30 dark:text-rose-300",children:[s("events.levels.error"),": ",E]})]}):null,children:F?e.jsx(Q,{label:s("common.loading")}):l.isError?e.jsx($,{icon:e.jsx(T,{className:"h-5 w-5","aria-hidden":"true"}),tone:"danger",title:s("common.status.error"),description:s("events.toast.loadFailure",{message:((P=l.error)==null?void 0:P.message)??s("common.unknownError")}),action:e.jsx(x,{variant:"outline",size:"sm",onClick:()=>void l.refetch(),children:s("common.actions.refresh")})}):d.length===0?e.jsx($,{icon:e.jsx(M,{className:"h-5 w-5","aria-hidden":"true"}),tone:"primary",title:s("events.empty.title"),description:s("events.empty.subtitle"),action:h.length>0?e.jsx(x,{variant:"outline",size:"sm",onClick:o,children:s("common.actions.reset")}):void 0}):e.jsx("div",{className:"grid gap-4",children:d.map(r=>e.jsx(re,{event:r},r.id))})})]})}function w({icon:s,title:i,tone:a,value:n}){const t={emerald:"bg-emerald-50 text-emerald-600 dark:bg-emerald-950 dark:text-emerald-400",amber:"bg-amber-50 text-amber-600 dark:bg-amber-950 dark:text-amber-400",rose:"bg-rose-50 text-rose-600 dark:bg-rose-950 dark:text-rose-400"}[a];return e.jsx(N,{children:e.jsxs(y,{className:"flex items-center justify-between gap-3 pt-5",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:i}),e.jsx("p",{className:"mt-2 text-3xl font-bold tracking-tight text-foreground",children:n})]}),e.jsx("div",{className:p("flex h-11 w-11 items-center justify-center rounded-xl",t),children:s})]})})}function re({event:s}){const{t:i}=z(),a=s.level==="error"?"border-l-destructive":s.level==="warn"?"border-l-amber-500":"border-l-emerald-500";return e.jsx(N,{className:p("overflow-hidden border-l-4",a),children:e.jsxs(y,{className:"space-y-4 pt-5",children:[e.jsxs("div",{className:"flex flex-col gap-3 xl:flex-row xl:items-start xl:justify-between",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(c,{variant:se[s.level]||"secondary",children:i(`events.levels.${s.level}`)}),e.jsxs(c,{variant:"outline",children:["#",s.id]}),s.mode?e.jsx(c,{variant:"secondary",children:s.mode}):null,s.endpoint?e.jsx(c,{variant:"outline",children:s.endpoint}):null]}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-base font-semibold tracking-[-0.01em]",children:s.title||i("events.defaultTitle")}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:s.message||i("events.defaultMessage")})]})]}),e.jsxs("div",{className:"space-y-1 text-sm text-muted-foreground xl:text-right",children:[e.jsx("p",{children:ee(s.createdAt)}),e.jsx("p",{children:Z(s.createdAt)})]})]}),e.jsxs("div",{className:"grid gap-3 text-sm sm:grid-cols-2 xl:grid-cols-4",children:[e.jsx(f,{label:"Type",value:s.type}),e.jsx(f,{label:"Source",value:s.source}),e.jsx(f,{label:"IP",value:s.ipAddress}),e.jsx(f,{label:"API Key",value:s.apiKeyName}),e.jsx(f,{label:"User Agent",value:s.userAgent,wide:!0})]}),s.details?e.jsxs("details",{className:"rounded-lg border border-border bg-secondary p-3 text-sm",children:[e.jsx("summary",{className:"cursor-pointer text-sm font-medium text-primary",children:i("events.details")}),e.jsx("pre",{className:"mt-3 overflow-x-auto rounded-lg border border-border bg-card p-3 text-xs leading-6",children:JSON.stringify(s.details,null,2)})]}):null]})})}function f({label:s,value:i,wide:a=!1}){return i?e.jsxs("div",{className:p("rounded-lg border border-border bg-secondary px-3 py-3",a&&"sm:col-span-2 xl:col-span-2"),children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-[0.16em] text-muted-foreground",children:s}),e.jsx("p",{className:"mt-1 break-all text-sm text-foreground",children:i})]}):null}export{fe as default};
@@ -0,0 +1,8 @@
1
+ import{r as u,j as e,aC as b,az as N,aD as v,aE as y}from"./vendor-OD8r2VI0.js";import{P as w}from"./PageHeader-BoMzY33X.js";import{P as a}from"./PageSection-DMHGizgh.js";import{c as h}from"./clipboard-CALi6bTW.js";import{C as p,a as j}from"./card-DZKUcIo6.js";import{B as f}from"./index-Do-c7aim.js";import{u as x}from"./i18n-CO7_kqjg.js";import"./query-DeMZnAJS.js";import"./router-DwL4vhvg.js";import"./radix-Bg9QIv2e.js";function z(){const{t:s}=x(),t=u.useMemo(()=>{const i=s("help.sections.configuration.items",{returnObjects:!0}),n=s("help.sections.claudeCodeConfig.items",{returnObjects:!0}),c=s("help.sections.codexConfig.items",{returnObjects:!0}),d=s("help.sections.usage.items",{returnObjects:!0}),g=s("help.sections.tips.items",{returnObjects:!0});return[{title:s("help.sections.configuration.title"),items:i},{title:s("help.sections.claudeCodeConfig.title"),items:n},{title:s("help.sections.codexConfig.title"),items:c},{title:s("help.sections.usage.title"),items:d},{title:s("help.sections.tips.title"),items:g}]},[s]),r=s("help.faq.items",{returnObjects:!0}),l=u.useMemo(()=>[{id:"configuration",title:t[0].title,subtitle:t[0].items[0]??""},{id:"claude",title:t[1].title,subtitle:t[1].items[0]??""},{id:"codex",title:t[2].title,subtitle:t[2].items[0]??""},{id:"faq",title:s("help.faq.title"),subtitle:`${r.length} FAQ`}],[r.length,t,s]);return e.jsxs("div",{className:"space-y-6",children:[e.jsx(w,{icon:e.jsx(b,{className:"h-5 w-5","aria-hidden":"true"}),title:s("help.title"),description:s("help.intro"),eyebrow:"Guided Setup",breadcrumb:"Gateway / Help",helper:s("help.helper"),badge:`${t.length} guides`}),e.jsx(p,{children:e.jsxs(j,{className:"flex items-start gap-4 pt-4",children:[e.jsx("div",{className:"flex h-10 w-10 shrink-0 items-center justify-center rounded-xl bg-accent text-primary",children:e.jsx(N,{className:"h-5 w-5","aria-hidden":"true"})}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("help.note")})]})}),e.jsx("div",{className:"grid gap-4 md:grid-cols-2 xl:grid-cols-4",children:l.map(i=>e.jsxs("a",{href:`#help-${i.id}`,className:"rounded-lg border border-border bg-card px-4 py-4 transition hover:bg-accent/50",children:[e.jsx("p",{className:"text-sm font-semibold",children:i.title}),e.jsx("p",{className:"mt-2 line-clamp-2 text-xs text-muted-foreground",children:i.subtitle})]},i.id))}),e.jsxs("div",{className:"space-y-6",children:[e.jsx("div",{id:"help-configuration",children:e.jsx(a,{eyebrow:"01",title:t[0].title,children:e.jsx(o,{items:t[0].items})})}),e.jsxs("div",{className:"space-y-1 text-center",children:[e.jsx("h2",{className:"text-xl font-semibold",children:s("help.clientConfig.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("help.clientConfig.subtitle")})]}),e.jsxs("div",{className:"grid gap-6 lg:grid-cols-2",children:[e.jsx("div",{id:"help-claude",children:e.jsxs(a,{eyebrow:"02",title:t[1].title,children:[e.jsxs("div",{className:"mb-4 flex items-center gap-3 rounded-lg border border-border bg-secondary p-4",children:[e.jsx("div",{className:"flex h-10 w-10 items-center justify-center rounded-xl bg-primary text-primary-foreground",children:e.jsx(v,{className:"h-4 w-4"})}),e.jsxs("div",{children:[e.jsx("span",{className:"text-sm font-medium",children:"Claude Code"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"IDE / Desktop workflow"})]})]}),e.jsx(o,{items:t[1].items})]})}),e.jsx("div",{id:"help-codex",children:e.jsxs(a,{eyebrow:"03",title:t[2].title,children:[e.jsxs("div",{className:"mb-4 flex items-center gap-3 rounded-lg border border-border bg-secondary p-4",children:[e.jsx("div",{className:"flex h-10 w-10 items-center justify-center rounded-xl bg-emerald-600 text-white",children:e.jsx(y,{className:"h-4 w-4"})}),e.jsxs("div",{children:[e.jsx("span",{className:"text-sm font-medium",children:"Codex CLI"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Terminal workflow"})]})]}),e.jsx(o,{items:t[2].items})]})})]}),e.jsxs("div",{className:"mt-8",children:[e.jsxs("div",{className:"mb-6 space-y-1 text-center",children:[e.jsx("h2",{className:"text-lg font-semibold",children:s("help.advancedGuide.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("help.advancedGuide.subtitle")})]}),e.jsxs("div",{className:"grid gap-6 lg:grid-cols-2",children:[e.jsx(a,{eyebrow:"04",title:t[3].title,children:e.jsx(o,{items:t[3].items})}),e.jsx(a,{eyebrow:"05",title:t[4].title,children:e.jsx(o,{items:t[4].items})})]})]})]}),e.jsx("div",{id:"help-faq",children:e.jsx(a,{eyebrow:"FAQ",title:s("help.faq.title"),children:e.jsx(q,{items:r})})})]})}function o({items:s}){return e.jsx("ol",{className:"flex flex-col gap-3",children:s.map((t,r)=>e.jsxs("li",{className:"flex gap-3 rounded-lg border border-border bg-card p-3",children:[e.jsx("span",{className:"flex h-7 w-7 shrink-0 items-center justify-center rounded-xl bg-primary text-xs font-medium text-primary-foreground",children:r+1}),e.jsx("div",{className:"flex-1 text-sm text-muted-foreground",children:e.jsx(C,{content:t})})]},`${r}-${t}`))})}function C({content:s}){const{t}=x();if(s.includes("```")){const r=s.split("```");return e.jsx("div",{className:"space-y-2",children:r.map((l,i)=>{if(i%2===0)return l?e.jsx("div",{className:"whitespace-pre-line",children:m(l)},i):null;{const[n,...c]=l.split(`
2
+ `),d=c.join(`
3
+ `);return e.jsxs("div",{className:"relative",children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between",children:[e.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:n||"bash"}),e.jsx(f,{variant:"ghost",size:"sm",className:"h-6 px-2 text-xs",onClick:()=>h(d),children:t("common.actions.copy")})]}),e.jsx("pre",{className:"overflow-x-auto rounded-lg border border-border bg-secondary p-3 text-xs",children:e.jsx("code",{children:d})})]},i)}})})}return s.includes(`
4
+ `)?e.jsx("div",{className:"whitespace-pre-line",children:m(s)}):e.jsx("div",{children:m(s)})}function m(s){return s.split(/(\*\*[^*]+\*\*)/g).map((r,l)=>r.startsWith("**")&&r.endsWith("**")?e.jsx("strong",{className:"font-medium text-foreground",children:r.slice(2,-2)},l):e.jsx("span",{children:r},l))}function q({items:s}){return s.length===0?null:e.jsx("dl",{className:"flex flex-col gap-3",children:s.map(t=>e.jsx(p,{children:e.jsxs(j,{className:"pt-4",children:[e.jsx("dt",{className:"text-sm font-medium",children:t.q}),e.jsx("dd",{className:"mt-2 text-sm text-muted-foreground",children:e.jsx(k,{content:t.a})})]})},t.q))})}function k({content:s}){const{t}=x();if(s.includes("1)")||s.includes("2)")){const r=s.split(`
5
+ `).filter(i=>i.trim());if(r.some(i=>/^\d+\)/.test(i.trim())))return e.jsx("div",{className:"space-y-1",children:r.map((i,n)=>{const c=i.match(/^\d+\)\s*(.*)/);return c?e.jsxs("div",{className:"flex gap-2",children:[e.jsx("span",{className:"text-muted-foreground",children:"•"}),e.jsx("span",{children:c[1]})]},n):e.jsx("div",{children:i},n)})})}if(s.includes("```")){const r=s.split("```");return e.jsx("div",{className:"space-y-2",children:r.map((l,i)=>{if(i%2===0)return l?e.jsx("div",{className:"whitespace-pre-line",children:l},i):null;{const[n,...c]=l.split(`
6
+ `),d=c.join(`
7
+ `);return e.jsxs("div",{className:"relative",children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between",children:[e.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:n||"bash"}),e.jsx(f,{variant:"ghost",size:"sm",className:"h-6 px-2 text-xs",onClick:()=>h(d),children:t("common.actions.copy")})]}),e.jsx("pre",{className:"overflow-x-auto rounded-lg border border-border bg-secondary p-3 text-xs",children:e.jsx("code",{children:d})})]},i)}})})}return s.includes(`
8
+ `)?e.jsx("div",{className:"whitespace-pre-line",children:s}):e.jsx("div",{children:s})}export{z as default};
@@ -0,0 +1 @@
1
+ import{r as n,j as e,an as S,aF as E}from"./vendor-OD8r2VI0.js";import{i as F,L as k,B as L}from"./index-Do-c7aim.js";import{C as j,a as b,b as P,c as T,d as A,e as B}from"./card-DZKUcIo6.js";import{I as N}from"./input-CJmvMsFH.js";import{L as y}from"./label-QrXl4oW8.js";import{u as D}from"./i18n-CO7_kqjg.js";import{c as G,u as I}from"./router-DwL4vhvg.js";import"./query-DeMZnAJS.js";import"./radix-Bg9QIv2e.js";function O(){const{t:s}=D(),a=G(),l=I(),{authEnabled:o,isAuthenticated:u,loading:d,login:w,error:x}=F(),[i,p]=n.useState({username:"",password:""}),[h,m]=n.useState(null),[f,g]=n.useState(!1),c=n.useMemo(()=>{var t;const r=l.state;return((t=r==null?void 0:r.from)==null?void 0:t.pathname)??"/"},[l.state]);n.useEffect(()=>{if(!o&&!d){a(c,{replace:!0});return}o&&u&&!d&&a(c,{replace:!0})},[o,c,u,d,a]);const C=async r=>{if(r.preventDefault(),m(null),!i.username.trim()||!i.password){m(s("login.validation.required"));return}g(!0);try{await w(i.username.trim(),i.password),a(c,{replace:!0})}catch(t){m(t instanceof Error?t.message:s("login.validation.failed"))}finally{g(!1)}};return d?e.jsx("div",{className:"flex min-h-screen items-center justify-center bg-background px-4",children:e.jsx(j,{className:"w-full max-w-md",children:e.jsx(b,{className:"flex min-h-[320px] items-center justify-center",children:e.jsx(k,{})})})}):o?e.jsx("div",{className:"flex min-h-screen items-center justify-center bg-background px-4 py-10",children:e.jsxs("div",{className:"mx-auto grid w-full max-w-5xl items-center gap-8 lg:grid-cols-[minmax(0,1fr)_minmax(400px,0.8fr)]",children:[e.jsx("div",{className:"hidden lg:block",children:e.jsxs("div",{className:"max-w-lg space-y-6",children:[e.jsx("div",{className:"inline-flex items-center gap-1.5 rounded-full border border-primary/20 bg-accent px-3 py-1 text-xs font-semibold text-primary",children:"Secure Gateway Control"}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("h1",{className:"text-4xl font-semibold tracking-tight text-foreground",children:s("login.title")}),e.jsx("p",{className:"max-w-md text-base leading-7 text-muted-foreground",children:s("login.description")})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsx(v,{icon:e.jsx(S,{className:"h-5 w-5","aria-hidden":"true"}),title:s("login.hint"),description:s("about.support.tip")}),e.jsx(v,{icon:e.jsx(E,{className:"h-5 w-5","aria-hidden":"true"}),title:"Session protected",description:s("help.note")})]})]})}),e.jsxs(j,{className:"w-full",children:[e.jsxs(P,{className:"pb-4 text-center",children:[e.jsx("div",{className:"mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-xl bg-primary text-sm font-bold text-primary-foreground",children:"GW"}),e.jsx(T,{className:"text-xl",children:s("login.title")}),e.jsx(A,{children:s("login.description")})]}),e.jsx(b,{children:e.jsxs("form",{className:"space-y-4",onSubmit:C,children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{htmlFor:"username",children:s("login.fields.username")}),e.jsx(N,{id:"username",value:i.username,autoComplete:"username",autoFocus:!0,onChange:r=>p(t=>({...t,username:r.target.value})),placeholder:s("login.fields.usernamePlaceholder")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{htmlFor:"password",children:s("login.fields.password")}),e.jsx(N,{id:"password",type:"password",value:i.password,autoComplete:"current-password",onChange:r=>p(t=>({...t,password:r.target.value})),placeholder:s("login.fields.passwordPlaceholder")})]}),h||x?e.jsx("div",{className:"rounded-lg border border-destructive/40 bg-destructive/10 px-4 py-3 text-sm text-destructive",children:h||x}):null,e.jsx(L,{type:"submit",className:"w-full",disabled:f,children:s(f?"common.actions.loading":"login.actions.submit")})]})}),e.jsx(B,{className:"justify-center pt-2",children:e.jsx("p",{className:"text-center text-xs text-muted-foreground",children:s("login.hint")})})]})]})}):null}function v({description:s,icon:a,title:l}){return e.jsxs("div",{className:"rounded-lg border border-border bg-card px-4 py-4",children:[e.jsx("div",{className:"flex h-9 w-9 items-center justify-center rounded-lg bg-primary/10 text-primary",children:a}),e.jsx("p",{className:"mt-3 text-sm font-semibold text-foreground",children:l}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:s})]})}export{O as default};
@@ -0,0 +1 @@
1
+ import{r as g,j as e,aj as Be,ak as We,a7 as Ge,al as Je,ai as Xe,V as Ye,T as Ze}from"./vendor-OD8r2VI0.js";import{B as K,P as et}from"./PageHeader-BoMzY33X.js";import{c as v,B as C,b as tt,u as ge,s as S,t as st,a as D}from"./index-Do-c7aim.js";import{C as _e,a as Ee}from"./card-DZKUcIo6.js";import{I as ue}from"./input-CJmvMsFH.js";import{L as $}from"./label-QrXl4oW8.js";import{S as ee,a as te,b as se,c as le,d as F}from"./select-Bjy18Ntu.js";import{u as R}from"./i18n-CO7_kqjg.js";import{D as lt,A as at,a as rt,b as ot,c as nt,d as it}from"./DialogShell-CCYRHVHF.js";import{P as dt,a as xe}from"./PageState-CoBpDxLj.js";import{c as ct}from"./clipboard-CALi6bTW.js";import{u as V,q as U}from"./queryKeys-CQ-Y0kH9.js";import{P as mt,a as pt,b as ut}from"./popover-B5SqN_8N.js";import{T as xt}from"./Skeleton-BMLOZAD8.js";import{g as Se}from"./gateway-Cv9wYNta.js";import"./query-DeMZnAJS.js";import"./router-DwL4vhvg.js";import"./radix-Bg9QIv2e.js";function gt({apiKeys:s,selected:t,onChange:o,disabled:i,className:d}){const{t:l}=R(),[r,h]=g.useState(!1),c=g.useRef(null);g.useEffect(()=>{if(!r)return;const n=a=>{var p;(p=c.current)!=null&&p.contains(a.target)||h(!1)};return window.addEventListener("mousedown",n),()=>window.removeEventListener("mousedown",n)},[r]);const j=g.useMemo(()=>{if(t.length===0)return[];const n=new Map;for(const a of s)n.set(a.id,a);return t.map(a=>{const p=n.get(a);return p?p.isWildcard?l("apiKeys.wildcard"):p.name:null}).filter(a=>!!a)},[s,t,l]),u=t.length===0?l("logs.filters.apiKeyAll"):l("logs.filters.apiKeySelected",{count:t.length}),y=n=>{t.includes(n)?o(t.filter(a=>a!==n)):o([...t,n])};return e.jsxs("div",{className:v("relative space-y-2",d),ref:c,children:[e.jsx($,{children:l("logs.filters.apiKey")}),e.jsxs("button",{type:"button",onClick:()=>h(n=>!n),disabled:i||s.length===0,title:l("logs.filters.apiKeyHint"),className:v("flex h-10 w-full items-center justify-between rounded-md border border-input bg-background px-3 text-sm ring-offset-background transition-all focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",t.length>0&&"border-primary",r&&"ring-2 ring-ring ring-offset-2"),children:[e.jsxs("span",{className:"truncate",children:[u,j.length>0&&e.jsx("span",{className:"ml-1 text-xs text-muted-foreground",children:j.join(", ")})]}),e.jsx("svg",{className:v("h-4 w-4 opacity-50 transition-transform",r&&"rotate-180"),viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M5.23 7.21a.75.75 0 011.06.02L10 10.94l3.71-3.71a.75.75 0 111.06 1.06l-4.24 4.25a.75.75 0 01-1.06 0L5.21 8.29a.75.75 0 01.02-1.08z",clipRule:"evenodd"})})]}),r&&e.jsxs("div",{className:"absolute left-0 top-full z-30 mt-2 w-64 rounded-md border bg-popover p-2 shadow-md",children:[e.jsxs("div",{className:"flex items-center justify-between rounded-md bg-secondary px-3 py-2 text-xs",children:[e.jsx("span",{children:u}),e.jsx("button",{type:"button",onClick:()=>o([]),disabled:t.length===0,className:"text-primary hover:underline disabled:opacity-40",children:l("common.actions.reset")})]}),e.jsxs("div",{className:"max-h-56 overflow-y-auto py-2",children:[s.map(n=>{const a=n.isWildcard?l("apiKeys.wildcard"):n.name,p=t.includes(n.id);return e.jsxs("label",{className:v("flex cursor-pointer items-center gap-2 rounded-xl px-3 py-2 text-sm transition hover:bg-primary/5",p&&"bg-primary/10 text-primary"),children:[e.jsx("input",{type:"checkbox",className:"h-4 w-4 rounded border-border",checked:p,onChange:()=>y(n.id)}),e.jsx("span",{className:"truncate",children:a})]},n.id)}),s.length===0&&e.jsx("p",{className:"px-2 py-2 text-xs text-muted-foreground",children:l("logs.filters.apiKeyAll")})]})]})]})}function ht(s){const{t}=R(),{total:o,activeFilters:i,filtersExpanded:d,setFiltersExpanded:l,handleResetFilters:r,activeQuickView:h,applyQuickView:c,providerFilter:j,setProviderFilter:u,endpointFilter:y,setEndpointFilter:n,selectedApiKeys:a,setSelectedApiKeys:p,modelFilter:f,setModelFilter:k,statusFilter:P,setStatusFilter:T,fromDate:_,setFromDate:L,toDate:w,setToDate:b,providerOptions:B,apiKeys:re,apiKeysLoading:oe,customEndpoints:W}=s;return e.jsx(_e,{"data-testid":"logs-filters-card",className:"overflow-hidden",children:e.jsxs(Ee,{className:"pt-4",children:[e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("p",{className:"text-sm font-semibold text-foreground",children:t("logs.filtersTitle")}),e.jsx(K,{variant:"outline",children:t("logs.summary.total",{value:o.toLocaleString()})}),i.length>0&&e.jsx(K,{variant:"secondary",children:t("common.filters.activeCount",{count:i.length})})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("logs.filtersDescription")})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[i.length>0&&e.jsx(C,{variant:"ghost",size:"sm",onClick:r,children:t("common.actions.reset")}),e.jsx(C,{variant:"ghost",size:"sm",onClick:()=>l(x=>!x),children:d?e.jsxs(e.Fragment,{children:[t("common.filters.collapse"),e.jsx(Be,{className:"ml-1 h-4 w-4"})]}):e.jsxs(e.Fragment,{children:[t("common.filters.expand"),e.jsx(We,{className:"ml-1 h-4 w-4"})]})})]})]}),e.jsxs("div",{className:"grid gap-3 lg:grid-cols-[minmax(0,1fr)_auto]",children:[e.jsx("div",{className:"flex min-h-[52px] items-center rounded-lg border border-border bg-secondary px-3 py-2",children:i.length>0?e.jsx("div",{className:"flex flex-wrap items-center gap-2",children:i.map(x=>e.jsxs(K,{variant:"secondary",role:"button",tabIndex:0,className:"cursor-pointer gap-1 border border-transparent bg-primary/10 text-primary hover:bg-destructive/10 hover:text-destructive",onClick:x.onRemove,onKeyDown:G=>{(G.key==="Enter"||G.key===" ")&&(G.preventDefault(),x.onRemove())},children:[x.label,e.jsx(Ge,{className:"h-3 w-3","aria-hidden":"true"})]},x.key))}):e.jsx("span",{className:"text-sm text-muted-foreground",children:t("common.filters.allRequests")})}),e.jsxs("div",{className:"grid grid-cols-2 gap-3 sm:grid-cols-4 lg:min-w-[360px]",children:[e.jsx(Z,{label:t("common.filters.activeCount",{count:i.length}),value:i.length.toString()}),e.jsx(Z,{label:t("logs.filters.apiKey"),value:a.length.toString()}),e.jsx(Z,{label:t("logs.filters.provider"),value:j==="all"?t("common.noData"):"1"}),e.jsx(Z,{label:t("logs.filters.endpoint"),value:y==="all"?t("common.noData"):"1"})]})]}),e.jsx("div",{className:"flex flex-wrap items-center gap-2 rounded-lg border border-border bg-secondary p-2",children:["all","errors","today","anthropic","openai"].map(x=>e.jsx(C,{variant:h===x?"default":"outline",size:"sm",className:v("rounded-full border-transparent",h===x&&x==="all"&&"bg-foreground text-background hover:bg-foreground/90",h===x&&x==="errors"&&"bg-rose-500 text-white hover:bg-rose-500/90",h===x&&x==="today"&&"bg-emerald-500 text-white hover:bg-emerald-500/90",h===x&&(x==="anthropic"||x==="openai")&&"bg-amber-500 text-white hover:bg-amber-500/90"),onClick:()=>c(x),children:t(`logs.quickViews.${x}`)},x))})]}),d&&e.jsxs("div",{className:"mt-4 grid gap-4 rounded-lg border border-border bg-secondary p-4 md:grid-cols-2 xl:grid-cols-4 animate-in fade-in slide-in-from-top-2 duration-200",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx($,{children:t("logs.filters.provider")}),e.jsxs(ee,{value:j,onValueChange:u,children:[e.jsx(te,{children:e.jsx(se,{})}),e.jsxs(le,{children:[e.jsx(F,{value:"all",children:t("logs.filters.providerAll")}),B.map(x=>e.jsx(F,{value:x.id,children:x.label??x.id},x.id))]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx($,{children:t("logs.filters.endpoint")}),e.jsxs(ee,{value:y,onValueChange:n,children:[e.jsx(te,{children:e.jsx(se,{})}),e.jsxs(le,{children:[e.jsx(F,{value:"all",children:t("logs.filters.endpointAll")}),e.jsx(F,{value:"anthropic",children:t("logs.filters.endpointAnthropic")}),e.jsx(F,{value:"openai",children:t("logs.filters.endpointOpenAI")}),W==null?void 0:W.map(x=>e.jsx(F,{value:x.id,children:x.label||x.id},x.id))]})]})]}),e.jsx(gt,{className:"md:col-span-2",apiKeys:re,selected:a,disabled:oe,onChange:p}),e.jsxs("div",{className:"space-y-2",children:[e.jsx($,{children:t("logs.filters.modelId")}),e.jsx(ue,{value:f,onChange:x=>k(x.target.value),placeholder:t("logs.filters.modelPlaceholder")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx($,{children:t("logs.filters.status")}),e.jsxs(ee,{value:P,onValueChange:x=>T(x),children:[e.jsx(te,{children:e.jsx(se,{})}),e.jsxs(le,{children:[e.jsx(F,{value:"all",children:t("logs.filters.statusAll")}),e.jsx(F,{value:"success",children:t("logs.filters.statusSuccess")}),e.jsx(F,{value:"error",children:t("logs.filters.statusError")})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx($,{children:t("logs.filters.startDate")}),e.jsx(ue,{type:"date",value:_,onChange:x=>L(x.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx($,{children:t("logs.filters.endDate")}),e.jsx(ue,{type:"date",value:w,onChange:x=>b(x.target.value)})]})]})]})})}function Z({label:s,value:t}){return e.jsxs("div",{className:"rounded-lg border border-border bg-card px-3 py-2",children:[e.jsx("p",{className:"text-[11px] text-muted-foreground",children:s}),e.jsx("p",{className:"mt-1 text-sm font-semibold text-foreground",children:t})]})}const he={listRequest(s){return{url:"/api/logs",method:"GET",params:s}},detailRequest(s){return{url:s===null?"":`/api/logs/${s}`,method:"GET"}},async exportArchive(s,t){const o=await tt.post("/api/logs/export",s,{responseType:"blob",timeout:t});return new Blob([o.data],{type:"application/zip"})}};function ft({apiKeyMap:s,logId:t,open:o,providerLabelMap:i}){var n;const{t:d}=R(),{pushToast:l}=ge(),r=V(U.logs.detail(t),he.detailRequest(t),{enabled:o&&t!==null,staleTime:3e4});g.useEffect(()=>{!r.isError||!r.error||l({title:d("logs.detail.loadError"),description:r.error.message,variant:"error"})},[r.error,r.isError,l,d]);const h=g.useCallback(async(a,p,f)=>{if(!p){l({title:d("logs.detail.copy.empty",{label:a}),variant:"info"});return}try{await ct(p),l({title:d(f),variant:"success"})}catch(k){l({title:d("logs.detail.copy.failure"),description:k instanceof Error?k.message:d("logs.detail.copy.failureFallback"),variant:"error"})}},[l,d]),c=r.data,j=c?i.get(c.provider)??c.provider:"",u=c&&c.api_key_id!=null?s.get(c.api_key_id):void 0,y=c?c.status_code??(c.error?500:200):null;return{apiKeyMeta:u,errorMessage:r.isError?((n=r.error)==null?void 0:n.message)??null:null,handleCopy:h,isError:r.isError,isPending:r.isPending,providerLabel:j,refetch:r.refetch,record:c,statusCode:y}}function De(s){const t=new Date(s);return`${t.getFullYear()}-${`${t.getMonth()+1}`.padStart(2,"0")}-${`${t.getDate()}`.padStart(2,"0")} ${`${t.getHours()}`.padStart(2,"0")}:${`${t.getMinutes()}`.padStart(2,"0")}:${`${t.getSeconds()}`.padStart(2,"0")}`}function M(s){return s==null?"-":s.toLocaleString()}function z(s,t){const o=M(s);return o==="-"?"-":`${o} ${t}`}function bt(s){return s?"true":"false"}function yt(s,t){if(!s||s.trim().length===0)return t;try{const o=JSON.parse(s);return JSON.stringify(o,null,2)}catch{return s}}function jt({open:s,logId:t,onClose:o,providerLabelMap:i,apiKeyMap:d}){var k,P,T,_,L,w;const{t:l}=R(),{apiKeyMeta:r,errorMessage:h,handleCopy:c,isError:j,isPending:u,providerLabel:y,refetch:n,record:a,statusCode:p}=ft({apiKeyMap:d,logId:t,open:s,providerLabelMap:i}),f=a?[{key:"client-request",title:l("logs.detail.payload.clientRequest"),value:((k=a.payload)==null?void 0:k.client_request)??null,emptyLabel:l("logs.detail.payload.emptyRequest"),copyToast:"logs.detail.copy.requestSuccess"},...(P=a.payload)!=null&&P.upstream_request?[{key:"upstream-request",title:l("logs.detail.payload.upstreamRequest"),value:a.payload.upstream_request,emptyLabel:l("logs.detail.payload.emptyRequest"),copyToast:"logs.detail.copy.requestSuccess"}]:[],...(T=a.payload)!=null&&T.upstream_response?[{key:"upstream-response",title:l("logs.detail.payload.upstreamResponse"),value:a.payload.upstream_response,emptyLabel:l("logs.detail.payload.emptyResponse"),copyToast:"logs.detail.copy.responseSuccess"}]:[],{key:"client-response",title:l("logs.detail.payload.clientResponse"),value:((_=a.payload)==null?void 0:_.client_response)??null,emptyLabel:l("logs.detail.payload.emptyResponse"),copyToast:"logs.detail.copy.responseSuccess"}]:[];return e.jsx(lt,{open:s,onOpenChange:b=>{b||o()},children:e.jsxs(at,{className:"w-[min(96vw,1200px)] max-w-[1200px]",children:[e.jsxs(rt,{className:"pr-14",children:[e.jsx(ot,{children:l("logs.detail.title")}),e.jsx(nt,{children:a?l("logs.detail.id",{id:a.id}):l("logs.detail.loadError")})]}),e.jsx(it,{className:"max-h-[78vh]",children:u?e.jsx(dt,{compact:!0,className:"min-h-[240px]",label:l("common.loading")}):j?e.jsx(xe,{compact:!0,className:"min-h-[240px]",tone:"danger",title:l("logs.detail.loadError"),description:h??l("common.unknownError"),action:e.jsx(C,{variant:"outline",onClick:()=>void n(),children:l("common.actions.refresh")})}):a?e.jsxs("div",{className:"space-y-6 text-sm",children:[e.jsxs("section",{className:"space-y-4 rounded-lg border border-border bg-card p-5",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:l("logs.detail.infoSection")}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 rounded-lg border border-border bg-secondary p-3 text-xs",children:[e.jsx("span",{className:"font-medium",children:l("logs.detail.summary.route",{from:a.client_model??l("logs.detail.info.noRequestedModel"),to:a.model})}),e.jsx("span",{className:"text-muted-foreground",children:l("logs.detail.summary.latency",{value:z(a.latency_ms,l("common.units.ms"))})}),a.ttft_ms!==null?e.jsxs("span",{className:"text-muted-foreground",children:["TTFT: ",z(a.ttft_ms,l("common.units.ms"))]}):null]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(K,{variant:a.error?"destructive":"default",children:p==null?void 0:p.toString()}),e.jsx(K,{variant:"outline",children:a.stream?l("logs.stream.streaming"):l("logs.stream.single")})]})]}),e.jsxs("div",{className:"grid gap-3 md:grid-cols-4",children:[e.jsx(O,{label:l("logs.detail.info.latency"),value:z(a.latency_ms,l("common.units.ms"))}),e.jsx(O,{label:l("logs.detail.info.ttft"),value:z(a.ttft_ms,l("common.units.ms"))}),e.jsx(O,{label:l("logs.detail.info.tpot"),value:z(a.tpot_ms,l("common.units.msPerToken"))}),e.jsx(O,{label:l("logs.detail.info.status"),value:(p==null?void 0:p.toString())??"-"})]}),e.jsxs("dl",{className:"grid gap-x-4 gap-y-3 md:grid-cols-2 xl:grid-cols-4",children:[e.jsx(E,{label:l("logs.detail.info.time"),value:De(a.timestamp)}),e.jsx(E,{label:l("logs.detail.info.sessionId"),value:a.session_id??"-"}),e.jsx(E,{label:l("logs.detail.info.endpoint"),value:a.endpoint||"-"}),e.jsx(E,{label:l("logs.detail.info.provider"),value:y}),e.jsx(E,{label:l("logs.detail.info.requestedModel"),value:a.client_model??l("logs.detail.info.noRequestedModel")}),e.jsx(E,{label:l("logs.detail.info.model"),value:a.model}),e.jsx(E,{label:l("logs.detail.info.stream"),value:bt(a.stream)}),e.jsx(E,{label:l("logs.detail.info.status"),value:p})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2 xl:grid-cols-4",children:[e.jsx(O,{label:l("logs.detail.info.inputTokens"),value:M(a.input_tokens)}),e.jsx(O,{label:l("logs.detail.info.cacheReadTokens"),value:M(a.cache_read_tokens)}),e.jsx(O,{label:l("logs.detail.info.cacheCreationTokens"),value:M(a.cache_creation_tokens)}),e.jsx(O,{label:l("logs.detail.info.outputTokens"),value:M(a.output_tokens)})]}),a.error?e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:l("logs.detail.info.error")}),e.jsx("p",{className:"rounded-[1rem] border border-destructive/50 bg-destructive/10 p-3 text-xs text-destructive",children:a.error})]}):null]}),e.jsxs("div",{className:"grid gap-6 xl:grid-cols-[minmax(0,0.9fr)_minmax(0,1.1fr)]",children:[e.jsxs("section",{className:"space-y-3 rounded-lg border border-border bg-card p-5",children:[e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:l("logs.detail.apiKey.title")}),e.jsxs("dl",{className:"grid gap-x-4 gap-y-3 sm:grid-cols-2",children:[e.jsx(E,{label:l("logs.detail.apiKey.name"),value:a.api_key_id==null&&!a.api_key_name?l("logs.detail.apiKey.missing"):r!=null&&r.isWildcard?l("apiKeys.wildcard"):(r==null?void 0:r.name)??a.api_key_name??l("logs.detail.apiKey.missing")}),e.jsx(E,{label:l("logs.detail.apiKey.identifier"),value:a.api_key_id??l("common.noData")}),e.jsx(E,{label:l("logs.detail.apiKey.masked"),value:r!=null&&r.isWildcard?l("apiKeys.wildcard"):(r==null?void 0:r.maskedKey)??a.api_key_name??l("logs.detail.apiKey.maskedUnavailable")}),e.jsx(E,{label:l("logs.detail.apiKey.lastUsed"),value:r!=null&&r.lastUsedAt?new Date(r.lastUsedAt).toLocaleString():l("common.noData")})]}),e.jsxs("div",{className:"rounded-lg border border-border bg-secondary p-3 text-xs",children:[e.jsx("p",{className:"font-medium",children:l("logs.detail.apiKey.rawMasked")}),e.jsx("p",{className:"mt-1 break-all font-mono",children:a.api_key_value_available?a.api_key_value_masked??l("logs.detail.apiKey.rawUnavailable"):l("logs.detail.apiKey.rawUnavailable")}),e.jsx("p",{className:"mt-2 text-[11px] text-muted-foreground",children:l("logs.detail.apiKey.rawMaskedHint")})]})]}),e.jsxs("section",{className:"space-y-4 rounded-lg border border-border bg-card p-5",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:l("logs.detail.payload.title")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:(L=a.payload)!=null&&L.upstream_request||(w=a.payload)!=null&&w.upstream_response?l("logs.detail.payload.helperWithUpstream"):l("logs.detail.payload.helperClientOnly")})]}),e.jsx("div",{className:"grid gap-4 xl:grid-cols-2",children:f.map(b=>e.jsx(vt,{title:b.title,value:b.value,emptyLabel:b.emptyLabel,onCopy:()=>c(b.title,b.value,b.copyToast),t:l},b.key))})]})]})]}):e.jsx(xe,{compact:!0,className:"min-h-[240px]",title:l("logs.detail.loadError"),description:l("common.noData")})})]})})}function O({label:s,value:t}){return e.jsxs("div",{className:"rounded-lg border border-border bg-secondary px-3 py-3",children:[e.jsx("p",{className:"text-[11px] font-medium uppercase tracking-[0.16em] text-muted-foreground",children:s}),e.jsx("p",{className:"mt-2 text-sm font-semibold",children:t})]})}function E({label:s,value:t}){return e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:s}),e.jsx("dd",{className:"font-medium",children:t??"-"})]})}function vt({emptyLabel:s,onCopy:t,title:o,value:i,t:d}){return e.jsxs("div",{className:"space-y-3 rounded-lg border border-border bg-secondary/40 p-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsx("h4",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:o}),e.jsx(C,{variant:"outline",size:"sm",onClick:t,children:d("common.actions.copy")})]}),e.jsx("pre",{className:"max-h-72 overflow-auto whitespace-pre-wrap rounded-lg border border-border bg-secondary p-3 text-xs",children:yt(i,s)})]})}const H=[20,50,100],I=["endpoint","provider","requestedModel","routedModel","apiKey","inputTokens","cacheReadTokens","cacheCreationTokens","outputTokens","latency","ttft","tpot","status","error"],ae=["endpoint","provider","requestedModel","routedModel","apiKey","inputTokens","cacheReadTokens","cacheCreationTokens","outputTokens","latency","ttft","tpot","status","error"];function Nt(){if(typeof window>"u")return I;try{const s=window.localStorage.getItem(S.logs.visibleColumns);if(!s)return I;const t=JSON.parse(s);if(!Array.isArray(t))return I;const o=t.filter(i=>ae.includes(i));return o.length>0?o:I}catch{return I}}function wt(){return typeof window>"u"?"comfortable":window.localStorage.getItem(S.logs.density)==="compact"?"compact":"comfortable"}function kt(){if(typeof window>"u")return H[0];const s=window.localStorage.getItem(S.logs.pageSize),t=Number(s);return H.includes(t)?t:H[0]}function St(){if(typeof window>"u")return[];try{const s=window.localStorage.getItem(S.logs.selectedApiKeys);if(!s)return[];const t=JSON.parse(s);return Array.isArray(t)?t.map(o=>Number(o)).filter(o=>Number.isInteger(o)&&o>0):[]}catch{return[]}}function Ce(s,t=!1){if(!s)return;const o=t?`${s}T23:59:59.999`:`${s}T00:00:00.000`,i=Date.parse(o);return Number.isFinite(i)?i:void 0}function Ct(s,t,o){return s===o&&t===o}function _t({columnOptions:s,exporting:t,onExport:o,onRefresh:i,onResetColumns:d,onSetDensity:l,onToggleColumn:r,refreshing:h,rowDensity:c,total:j,visibleColumns:u,visibleColumnSet:y}){const{t:n}=R(),a=JSON.stringify(u)===JSON.stringify(I);return e.jsxs("div",{className:"flex w-full flex-col gap-3 xl:w-auto xl:flex-row xl:items-center",children:[e.jsxs("div",{className:"flex w-full flex-col gap-3 sm:flex-row sm:flex-wrap sm:items-center xl:w-auto xl:flex-nowrap",children:[e.jsxs("div",{className:"flex w-full items-center gap-1 overflow-x-auto rounded-full border border-border bg-secondary p-1 sm:w-auto",children:[e.jsx("button",{type:"button",onClick:()=>l("comfortable"),className:v("inline-flex h-8 flex-1 items-center justify-center whitespace-nowrap rounded-full px-3.5 text-xs font-medium transition-all sm:flex-none",c==="comfortable"?"bg-primary text-primary-foreground shadow-[0_8px_18px_-14px_rgba(59,130,246,0.7)]":"text-muted-foreground hover:bg-primary/5 hover:text-foreground"),children:n("logs.table.density.comfortable")}),e.jsx("button",{type:"button",onClick:()=>l("compact"),className:v("inline-flex h-8 flex-1 items-center justify-center whitespace-nowrap rounded-full px-3.5 text-xs font-medium transition-all sm:flex-none",c==="compact"?"bg-primary text-primary-foreground shadow-[0_8px_18px_-14px_rgba(59,130,246,0.7)]":"text-muted-foreground hover:bg-primary/5 hover:text-foreground"),children:n("logs.table.density.compact")})]}),e.jsxs(mt,{children:[e.jsx(pt,{asChild:!0,children:e.jsx(C,{variant:"outline",size:"sm",className:"w-full sm:w-auto",children:n("logs.actions.columns")})}),e.jsxs(ut,{align:"end",className:"w-64 p-3",children:[e.jsxs("div",{className:"mb-3 flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-semibold",children:n("logs.actions.columns")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:n("logs.actions.visibleCount",{count:u.length})})]}),e.jsx(C,{variant:"ghost",size:"sm",onClick:d,disabled:a,children:n("common.actions.reset")})]}),e.jsx("div",{className:"grid gap-1.5",children:s.map(p=>{const f=y.has(p.id);return e.jsxs("label",{className:v("flex cursor-pointer items-center gap-3 rounded-xl px-3 py-2 text-sm transition hover:bg-primary/5",f&&"bg-primary/10 text-primary"),children:[e.jsx("input",{type:"checkbox",checked:f,onChange:()=>r(p.id),className:"h-4 w-4 rounded border-border"}),e.jsx("span",{children:p.label})]},p.id)})})]})]}),e.jsxs(C,{onClick:o,disabled:t,className:"w-full sm:w-auto",children:[e.jsx(Je,{className:"mr-2 h-4 w-4"}),n(t?"logs.actions.exporting":"logs.actions.export")]})]}),e.jsxs("div",{className:"flex w-full items-center justify-between gap-3 xl:w-auto xl:justify-start",children:[e.jsx("span",{className:"text-xs text-muted-foreground sm:text-sm",children:n("logs.summary.total",{value:j.toLocaleString()})}),e.jsxs(C,{variant:"outline",size:"sm",onClick:i,disabled:h,className:"shrink-0",children:[e.jsx(Xe,{className:v("mr-2 h-4 w-4",h&&"animate-spin")}),n(h?"common.actions.refreshing":"logs.actions.manualRefresh")]})]})]})}function Et({record:s,providerLabelMap:t,apiKeyMap:o,onSelect:i,isEven:d,density:l,visibleColumnSet:r}){const{t:h}=R(),c=t.get(s.provider)??s.provider,j=s.endpoint||"-",u=!!s.error,y=s.status_code,n=s.client_model??h("logs.table.requestedModelFallback"),a=s.api_key_id!=null?o.get(s.api_key_id):void 0,p=s.api_key_id==null?h("logs.table.apiKeyUnknown"):a!=null&&a.isWildcard?h("apiKeys.wildcard"):a!=null&&a.name?a.name:s.api_key_name?s.api_key_name:h("logs.table.apiKeyUnknown"),f=l==="compact"?"px-3 py-1.5":"px-3 py-2",k=d?"bg-muted/30":"bg-background";return e.jsxs("tr",{className:v("transition-colors",d?"bg-muted/30":"","hover:bg-muted/50"),children:[e.jsx("td",{className:v("sticky left-0 z-10 text-xs",f,k),children:De(s.timestamp)}),r.has("endpoint")&&e.jsx("td",{className:v(f,"text-xs"),children:j}),r.has("provider")&&e.jsx("td",{className:v(f,"text-xs"),children:e.jsx("div",{className:"max-w-[100px] truncate",title:c,children:c})}),r.has("requestedModel")&&e.jsx("td",{className:v(f,"text-xs text-muted-foreground"),children:e.jsx("div",{className:"max-w-[120px] truncate",title:n,children:n})}),r.has("routedModel")&&e.jsx("td",{className:v(f,"text-xs"),children:e.jsx("div",{className:"max-w-[120px] truncate",title:s.model,children:s.model})}),r.has("apiKey")&&e.jsx("td",{className:v(f,"text-xs text-muted-foreground"),children:e.jsx("div",{className:"max-w-[90px] truncate",title:p,children:p})}),r.has("inputTokens")&&e.jsx("td",{className:v(f,"text-right text-xs tabular-nums"),children:M(s.input_tokens)}),r.has("cacheReadTokens")&&e.jsx("td",{className:v(f,"text-right text-xs tabular-nums"),children:M(s.cache_read_tokens)}),r.has("cacheCreationTokens")&&e.jsx("td",{className:v(f,"text-right text-xs tabular-nums"),children:M(s.cache_creation_tokens)}),r.has("outputTokens")&&e.jsx("td",{className:v(f,"text-right text-xs tabular-nums"),children:M(s.output_tokens)}),r.has("latency")&&e.jsx("td",{className:v(f,"text-right text-xs tabular-nums"),children:z(s.latency_ms,"ms")}),r.has("ttft")&&e.jsx("td",{className:v(f,"text-right text-xs tabular-nums"),children:z(s.ttft_ms,"ms")}),r.has("tpot")&&e.jsx("td",{className:v(f,"text-right text-xs tabular-nums"),children:z(s.tpot_ms,"ms/tk")}),r.has("status")&&e.jsx("td",{className:v(f,"text-center"),children:e.jsx(K,{variant:u?"destructive":"default",className:"text-xs",children:y??(u?500:200)})}),r.has("error")&&e.jsx("td",{className:v(f,"text-xs text-muted-foreground"),children:e.jsx("div",{className:"max-w-[100px] truncate",title:s.error??"",children:s.error?s.error:"-"})}),e.jsx("td",{className:v("sticky right-0 z-10 text-center",f,k),children:e.jsx(C,{variant:"outline",size:"sm",onClick:()=>i(s.id),children:h("logs.actions.detail")})})]})}function Dt(s){const{t}=R(),{tableScrollRef:o,visibleColumnSet:i,visibleColumnCount:d,logsError:l,logsPending:r,items:h,activeFiltersCount:c,handleResetFilters:j,handleRetry:u,providerLabelMap:y,apiKeyMap:n,handleOpenDetail:a,rowDensity:p,showScrollHint:f,pageSize:k,setPageSize:P,page:T,totalPages:_,setPage:L}=s;return e.jsx(_e,{className:"overflow-hidden",children:e.jsxs(Ee,{className:"p-0",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 border-b border-border bg-secondary px-4 py-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-sm font-semibold",children:t("logs.title")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("logs.actions.visibleCount",{count:d-2})})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(K,{variant:"secondary",children:"Wide Table"}),e.jsx(K,{variant:"outline",children:t(p==="compact"?"logs.table.density.compact":"logs.table.density.comfortable")}),f?e.jsx(K,{variant:"outline",className:"border-amber-200 bg-amber-50 text-amber-700 dark:border-amber-800 dark:bg-amber-950/30 dark:text-amber-300",children:"Scroll for more"}):null]})]}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{ref:o,className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full min-w-[1480px] text-sm",children:[e.jsx("thead",{className:"border-b bg-muted/50",children:e.jsxs("tr",{children:[e.jsx("th",{className:"sticky left-0 z-20 bg-muted/95 px-3 py-2 text-left text-xs font-medium backdrop-blur",children:t("logs.table.columns.time")}),i.has("endpoint")&&e.jsx("th",{className:"px-3 py-2 text-left text-xs font-medium",children:t("logs.table.columns.endpoint")}),i.has("provider")&&e.jsx("th",{className:"px-3 py-2 text-left text-xs font-medium",children:t("logs.table.columns.provider")}),i.has("requestedModel")&&e.jsx("th",{className:"px-3 py-2 text-left text-xs font-medium",children:t("logs.table.columns.requestedModel")}),i.has("routedModel")&&e.jsx("th",{className:"px-3 py-2 text-left text-xs font-medium",children:t("logs.table.columns.routedModel")}),i.has("apiKey")&&e.jsx("th",{className:"px-3 py-2 text-left text-xs font-medium",children:t("logs.table.columns.apiKey")}),i.has("inputTokens")&&e.jsx("th",{className:"px-3 py-2 text-right text-xs font-medium",children:t("logs.table.columns.inputTokens")}),i.has("cacheReadTokens")&&e.jsx("th",{className:"px-3 py-2 text-right text-xs font-medium",children:t("logs.table.columns.cacheReadTokens")}),i.has("cacheCreationTokens")&&e.jsx("th",{className:"px-3 py-2 text-right text-xs font-medium",children:t("logs.table.columns.cacheCreationTokens")}),i.has("outputTokens")&&e.jsx("th",{className:"px-3 py-2 text-right text-xs font-medium",children:t("logs.table.columns.outputTokens")}),i.has("latency")&&e.jsx("th",{className:"px-3 py-2 text-right text-xs font-medium",children:t("logs.table.columns.latency")}),i.has("ttft")&&e.jsx("th",{className:"px-3 py-2 text-right text-xs font-medium",children:t("logs.table.columns.ttft")}),i.has("tpot")&&e.jsx("th",{className:"px-3 py-2 text-right text-xs font-medium",children:t("logs.table.columns.tpot")}),i.has("status")&&e.jsx("th",{className:"px-3 py-2 text-center text-xs font-medium",children:t("logs.table.columns.status")}),i.has("error")&&e.jsx("th",{className:"px-3 py-2 text-left text-xs font-medium",children:t("logs.table.columns.error")}),e.jsx("th",{className:"sticky right-0 z-20 bg-muted/95 px-3 py-2 text-center text-xs font-medium backdrop-blur",children:t("logs.table.columns.actions")})]})}),e.jsx("tbody",{className:"divide-y",children:r?Array.from({length:8}).map((w,b)=>e.jsx(xt,{columns:d},b)):l&&h.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:d,className:"px-3 py-6",children:e.jsx(xe,{compact:!0,tone:"danger",icon:e.jsx(Ye,{className:"h-5 w-5","aria-hidden":"true"}),title:t("logs.toast.listError.title"),description:l,action:e.jsxs("div",{className:"flex flex-wrap items-center justify-center gap-2",children:[e.jsx(C,{variant:"outline",size:"sm",onClick:u,children:t("common.actions.refresh")}),c>0?e.jsx(C,{variant:"ghost",size:"sm",onClick:j,children:t("common.actions.reset")}):null]})})})}):h.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:d,className:"px-3 py-8 text-center text-sm text-muted-foreground",children:e.jsxs("div",{className:"flex flex-col items-center gap-3 py-4",children:[e.jsx("span",{children:t("logs.table.empty")}),c>0&&e.jsx(C,{variant:"outline",size:"sm",onClick:j,children:t("common.actions.reset")})]})})}):h.map((w,b)=>e.jsx(Et,{record:w,providerLabelMap:y,apiKeyMap:n,onSelect:a,isEven:b%2===0,density:p,visibleColumnSet:i},w.id))})]})}),f&&e.jsx("div",{className:"table-scroll-hint"})]}),e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-4 border-t p-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:t("logs.table.pagination.perPage")}),e.jsxs(ee,{value:k.toString(),onValueChange:w=>P(Number(w)),children:[e.jsx(te,{className:"w-[80px]",children:e.jsx(se,{})}),e.jsx(le,{children:H.map(w=>e.jsx(F,{value:w.toString(),children:w},w))})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(C,{variant:"outline",size:"sm",onClick:()=>L(w=>Math.max(w-1,1)),disabled:T<=1,children:t("logs.table.pagination.previous")}),e.jsx("span",{className:"text-sm text-muted-foreground",children:t("logs.table.pagination.pageLabel",{page:_===0?0:T,total:_})}),e.jsx(C,{variant:"outline",size:"sm",onClick:()=>L(w=>_===0?w:Math.min(w+1,_)),disabled:_===0||T>=_,children:t("logs.table.pagination.next")})]})]})]})})}function Tt({exportTimeoutMs:s,queryParams:t,total:o}){const{t:i}=R(),{pushToast:d}=ge(),[l,r]=g.useState(!1),h=g.useCallback(async()=>{if(!l){r(!0);try{const c=o>0?Math.min(o,5e3):1e3,j={...t,limit:c,offset:0},u=await he.exportArchive(j,s),y=new Date().toISOString().replace(/[:.]/g,"-"),n=URL.createObjectURL(u),a=document.createElement("a");a.href=n,a.download=`cc-gw-logs-${y}.zip`,document.body.appendChild(a),a.click(),a.remove(),URL.revokeObjectURL(n),d({title:i("logs.toast.exportSuccess.title"),description:i("logs.toast.exportSuccess.desc"),variant:"success"})}catch(c){const j=st(c);d({title:i("logs.toast.exportError.title"),description:i("logs.toast.exportError.desc",{message:j.message}),variant:"error"})}finally{r(!1)}}},[s,l,d,t,i,o]);return{exporting:l,handleExport:h}}function Ft(){const s=g.useRef(null),[t,o]=g.useState(!1),i=g.useCallback(()=>{const d=s.current;if(!d)return;const l=d.scrollWidth-d.scrollLeft-d.clientWidth>1;o(l)},[]);return g.useEffect(()=>{const d=s.current;if(!d)return;i(),d.addEventListener("scroll",i,{passive:!0});const l=new ResizeObserver(i);return l.observe(d),()=>{d.removeEventListener("scroll",i),l.disconnect()}},[i]),{scrollRef:s,showScrollHint:t,updateScrollHint:i}}function Rt(){const[s,t]=D(S.logs.density,wt,{serialize:u=>u,deserialize:u=>u==="compact"?"compact":"comfortable"}),[o,i]=D(S.logs.visibleColumns,Nt),{scrollRef:d,showScrollHint:l}=Ft(),r=g.useMemo(()=>new Set(o),[o]),h=o.length+2,c=g.useCallback(u=>{i(y=>{if(y.includes(u))return y.length===1?y:y.filter(a=>a!==u);const n=[...y,u];return n.sort((a,p)=>ae.indexOf(a)-ae.indexOf(p)),n})},[]);return{resetVisibleColumns:g.useCallback(()=>{i(I)},[]),rowDensity:s,setRowDensity:t,showScrollHint:l,tableScrollRef:d,toggleColumn:c,visibleColumnCount:h,visibleColumns:o,visibleColumnSet:r}}function Lt(){var je,ve,Ne,we,ke;const{t:s}=R(),{pushToast:t}=ge(),[o,i]=D(S.logs.providerFilter,"all"),[d,l]=D(S.logs.endpointFilter,"all"),[r,h]=D(S.logs.modelFilter,""),[c,j]=D(S.logs.statusFilter,"all"),[u,y]=D(S.logs.fromDate,""),[n,a]=D(S.logs.toDate,""),[p,f]=g.useState(1),[k,P]=D(S.logs.pageSize,kt,{serialize:m=>String(m),deserialize:m=>{const N=Number(m);return H.includes(N)?N:H[0]}}),[T,_]=g.useState(null),[L,w]=g.useState(!1),[b,B]=D(S.logs.selectedApiKeys,St),[re,oe]=D(S.logs.filtersExpanded,!1),{resetVisibleColumns:W,rowDensity:x,setRowDensity:G,showScrollHint:Te,tableScrollRef:Fe,toggleColumn:Re,visibleColumnCount:Le,visibleColumns:Me,visibleColumnSet:Ke}=Rt();g.useEffect(()=>{f(1)},[o,d,r,c,u,n,k,b]);const ne=g.useMemo(()=>{const m={limit:k,offset:(p-1)*k};o!=="all"&&(m.provider=o),d!=="all"&&(m.endpoint=d),r.trim().length>0&&(m.model=r.trim()),c!=="all"&&(m.status=c);const N=Ce(u),q=Ce(n,!0);return N!==void 0&&(m.from=N),q!==void 0&&(m.to=q),b.length>0&&(m.apiKeys=b.join(",")),m},[d,u,r,p,k,o,b,c,n]),A=V(U.logs.list(ne),he.listRequest(ne)),Q=V(U.providers.all(),Se.providersRequest()),fe=V(U.apiKeys.all(),{url:"/api/keys",method:"GET"}),ie=V(U.customEndpoints.all(),{url:"/api/custom-endpoints",method:"GET"}),be=V(U.config.exportTimeout(),Se.configRequest());g.useEffect(()=>{!A.isError||!A.error||t({title:s("logs.toast.listError.title"),description:s("logs.toast.listError.desc",{message:A.error.message}),variant:"error"})},[A.error,A.isError,t,s]),g.useEffect(()=>{!Q.isError||!Q.error||t({title:s("logs.toast.providerError.title"),description:s("logs.toast.providerError.desc",{message:Q.error.message}),variant:"error"})},[Q.error,Q.isError,t,s]);const Y=((je=A.data)==null?void 0:je.total)??0,J=Y>0?Math.ceil(Y/k):0,Pe=((ve=A.data)==null?void 0:ve.items)??[],Ae=g.useMemo(()=>{var N;const m=(N=be.data)==null?void 0:N.logExportTimeoutSeconds;return typeof m=="number"&&Number.isFinite(m)?Math.min(Math.max(Math.round(m),5),600)*1e3:6e4},[(Ne=be.data)==null?void 0:Ne.logExportTimeoutSeconds]);g.useEffect(()=>{J>0&&p>J&&f(J)},[p,J]);const de=Q.data??[],ce=g.useMemo(()=>{const m=new Map;for(const N of de)N.id&&m.set(N.id,N.label??N.id);return m},[de]),ye=g.useMemo(()=>{var N;const m=new Map;m.set("anthropic",s("logs.filters.endpointAnthropic")),m.set("openai",s("logs.filters.endpointOpenAI"));for(const q of((N=ie.data)==null?void 0:N.endpoints)??[])m.set(q.id,q.label||q.id);return m},[(we=ie.data)==null?void 0:we.endpoints,s]),Oe=g.useMemo(()=>{const m=[];if(o!=="all"){const N=ce.get(o)??o;m.push({key:"provider",label:`${s("logs.filters.provider")}: ${N}`,onRemove:()=>i("all")})}if(d!=="all"){const N=ye.get(d)??d;m.push({key:"endpoint",label:`${s("logs.filters.endpoint")}: ${N}`,onRemove:()=>l("all")})}if(r.trim()&&m.push({key:"model",label:`${s("logs.filters.modelId")}: ${r.trim()}`,onRemove:()=>h("")}),c!=="all"){const N=s(c==="success"?"logs.filters.statusSuccess":"logs.filters.statusError");m.push({key:"status",label:`${s("logs.filters.status")}: ${N}`,onRemove:()=>j("all")})}return u&&m.push({key:"from",label:`${s("logs.filters.startDate")}: ${u}`,onRemove:()=>y("")}),n&&m.push({key:"to",label:`${s("logs.filters.endDate")}: ${n}`,onRemove:()=>a("")}),b.length>0&&m.push({key:"apiKeys",label:s("logs.filters.apiKeySelected",{count:b.length}),onRemove:()=>B([])}),m},[d,ye,u,r,o,ce,b.length,c,s,n]),me=fe.data??[],ze=g.useMemo(()=>{const m=new Map;for(const N of me)m.set(N.id,N);return m},[me]),qe=g.useMemo(()=>ae.map(m=>({id:m,label:s(`logs.table.columns.${m}`)})),[s]),X=g.useMemo(()=>new Date().toISOString().slice(0,10),[]),$e=g.useMemo(()=>o==="all"&&d==="all"&&r.trim()===""&&c==="all"&&u===""&&n===""&&b.length===0?"all":c==="error"&&d==="all"&&o==="all"&&r.trim()===""&&u===""&&n===""&&b.length===0?"errors":Ct(u,n,X)&&d==="all"&&o==="all"&&r.trim()===""&&c==="all"&&b.length===0?"today":d==="anthropic"&&o==="all"&&r.trim()===""&&c==="all"&&u===""&&n===""&&b.length===0?"anthropic":d==="openai"&&o==="all"&&r.trim()===""&&c==="all"&&u===""&&n===""&&b.length===0?"openai":null,[d,u,r,o,b.length,c,n,X]),pe=g.useCallback(()=>{i("all"),h(""),l("all"),j("all"),y(""),a(""),B([])},[]),Ie=g.useCallback(m=>{if(f(1),pe(),m!=="all"){if(m==="errors"){j("error");return}if(m==="today"){y(X),a(X);return}if(m==="anthropic"){l("anthropic");return}m==="openai"&&l("openai")}},[pe,X]),{exporting:Qe,handleExport:Ve}=Tt({exportTimeoutMs:Ae,queryParams:ne,total:Y}),Ue=g.useCallback(m=>{_(m),w(!0)},[]),He=g.useCallback(()=>{w(!1),_(null)},[]);return{activeFilters:Oe,activeQuickView:$e,apiKeyMap:ze,apiKeys:me,apiKeysQuery:fe,applyQuickView:Ie,columnOptions:qe,customEndpoints:(ke=ie.data)==null?void 0:ke.endpoints,endpointFilter:d,exporting:Qe,filtersExpanded:re,fromDate:u,handleCloseDetail:He,handleExport:Ve,handleOpenDetail:Ue,handleResetFilters:pe,isDetailOpen:L,items:Pe,logsQuery:A,modelFilter:r,page:p,pageSize:k,providerFilter:o,providerLabelMap:ce,providerOptions:de,rowDensity:x,resetVisibleColumns:W,selectedApiKeys:b,selectedLogId:T,setEndpointFilter:l,setFiltersExpanded:oe,setFromDate:y,setModelFilter:h,setPage:f,setPageSize:P,setProviderFilter:i,setRowDensity:G,setSelectedApiKeys:B,setStatusFilter:j,setToDate:a,showScrollHint:Te,statusFilter:c,tableScrollRef:Fe,toDate:n,toggleColumn:Re,total:Y,totalPages:J,visibleColumnCount:Le,visibleColumns:Me,visibleColumnSet:Ke}}function Yt(){var o;const{t:s}=R(),t=Lt();return e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx(et,{icon:e.jsx(Ze,{className:"h-5 w-5","aria-hidden":"true"}),title:s("logs.title"),description:s("logs.description"),eyebrow:"Traffic Explorer",breadcrumb:"Gateway / Logs",helper:s("logs.filtersDescription"),badge:t.total>0?s("logs.summary.total",{value:t.total.toLocaleString()}):void 0,actions:e.jsx(_t,{columnOptions:t.columnOptions,exporting:t.exporting,onExport:()=>void t.handleExport(),onRefresh:()=>void t.logsQuery.refetch(),onResetColumns:t.resetVisibleColumns,onSetDensity:t.setRowDensity,onToggleColumn:t.toggleColumn,refreshing:t.logsQuery.isFetching,rowDensity:t.rowDensity,total:t.total,visibleColumns:t.visibleColumns,visibleColumnSet:t.visibleColumnSet})}),e.jsx(ht,{total:t.total,activeFilters:t.activeFilters,filtersExpanded:t.filtersExpanded,setFiltersExpanded:t.setFiltersExpanded,handleResetFilters:t.handleResetFilters,activeQuickView:t.activeQuickView,applyQuickView:t.applyQuickView,providerFilter:t.providerFilter,setProviderFilter:t.setProviderFilter,endpointFilter:t.endpointFilter,setEndpointFilter:t.setEndpointFilter,selectedApiKeys:t.selectedApiKeys,setSelectedApiKeys:t.setSelectedApiKeys,modelFilter:t.modelFilter,setModelFilter:t.setModelFilter,statusFilter:t.statusFilter,setStatusFilter:t.setStatusFilter,fromDate:t.fromDate,setFromDate:t.setFromDate,toDate:t.toDate,setToDate:t.setToDate,providerOptions:t.providerOptions,apiKeys:t.apiKeys,apiKeysLoading:t.apiKeysQuery.isLoading,customEndpoints:t.customEndpoints}),e.jsx(Dt,{tableScrollRef:t.tableScrollRef,visibleColumnSet:t.visibleColumnSet,visibleColumnCount:t.visibleColumnCount,logsError:t.logsQuery.isError?((o=t.logsQuery.error)==null?void 0:o.message)??null:null,logsPending:t.logsQuery.isPending,items:t.items,activeFiltersCount:t.activeFilters.length,handleResetFilters:t.handleResetFilters,handleRetry:()=>void t.logsQuery.refetch(),providerLabelMap:t.providerLabelMap,apiKeyMap:t.apiKeyMap,handleOpenDetail:t.handleOpenDetail,rowDensity:t.rowDensity,showScrollHint:t.showScrollHint,pageSize:t.pageSize,setPageSize:t.setPageSize,page:t.page,totalPages:t.totalPages,setPage:t.setPage}),e.jsx(jt,{open:t.isDetailOpen,logId:t.selectedLogId,onClose:t.handleCloseDetail,providerLabelMap:t.providerLabelMap,apiKeyMap:t.apiKeyMap})]})}export{Yt as default};