@chenpu17/cc-gw 0.13.0 → 0.17.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/README.md +2 -0
  2. package/package.json +7 -7
  3. package/src/web/dist/assets/About-DmIV-sHO.js +1 -0
  4. package/src/web/dist/assets/ApiKeys-BNr4zbD6.js +1 -0
  5. package/src/web/dist/assets/{ConfirmDialog-BOe5HI56.js → ConfirmDialog-_CIYYtzo.js} +1 -1
  6. package/src/web/dist/assets/Dashboard-Hg4OZNAc.js +1 -0
  7. package/src/web/dist/assets/DialogShell-D1T4HXtd.js +1 -0
  8. package/src/web/dist/assets/Events-CO2wWiEK.js +1 -0
  9. package/src/web/dist/assets/Help-CafNfXfx.js +4 -0
  10. package/src/web/dist/assets/Login-C04-poiG.js +1 -0
  11. package/src/web/dist/assets/Logs-CqaIXvR0.js +1 -0
  12. package/src/web/dist/assets/PageSection-Dd2-9G6C.js +1 -0
  13. package/src/web/dist/assets/PageState-Bbhr4fy6.js +1 -0
  14. package/src/web/dist/assets/PageToolbar-GyUQBhmq.js +1 -0
  15. package/src/web/dist/assets/ProvidersPage-CHvyCANH.js +1 -0
  16. package/src/web/dist/assets/RoutingPage-fVr25VKF.js +1 -0
  17. package/src/web/dist/assets/Settings-DfaIYHsa.js +1 -0
  18. package/src/web/dist/assets/Setup-DUEpie5k.js +2 -0
  19. package/src/web/dist/assets/TargetCombobox-CSnHZqDY.js +1 -0
  20. package/src/web/dist/assets/apiKeys-B5Os17Qm.js +1 -0
  21. package/src/web/dist/assets/app-DZpd2fu9.js +61 -0
  22. package/src/web/dist/assets/badge-CWbm9P64.js +1 -0
  23. package/src/web/dist/assets/chartTheme-ChTod603.js +1 -0
  24. package/src/web/dist/assets/{charts-core-DlIzYcw_.js → charts-core-BuoE1ECx.js} +1 -1
  25. package/src/web/dist/assets/{charts-engine-C14rMTiz.js → charts-engine-DHIzBJl6.js} +1 -1
  26. package/src/web/dist/assets/{charts-react-Bz6GVFr3.js → charts-react-BLOapElb.js} +1 -1
  27. package/src/web/dist/assets/clipboard-DqvcglYs.js +1 -0
  28. package/src/web/dist/assets/currency-DffG4uWM.js +3 -0
  29. package/src/web/dist/assets/disclosure-W_XtxMJz.js +1 -0
  30. package/src/web/dist/assets/{gateway-DxCj_uok.js → gateway-DxaHzVOF.js} +1 -1
  31. package/src/web/dist/assets/{global-CJOj9WGx.js → global-BCYo_xAt.js} +1 -1
  32. package/src/web/dist/assets/global-CP6wBbWu.css +1 -0
  33. package/src/web/dist/assets/{i18n-Dp-o1LhZ.js → i18n-ClvfZhYc.js} +1 -1
  34. package/src/web/dist/assets/{label-Da-JMxO2.js → label-09axTkPo.js} +1 -1
  35. package/src/web/dist/assets/{landing-BuuM1jg8.js → landing-BsX2AKvc.js} +5 -5
  36. package/src/web/dist/assets/modelManagement-Dc7L1tJw.js +1 -0
  37. package/src/web/dist/assets/package-DgoCoO-z.js +1 -0
  38. package/src/web/dist/assets/popover-CX5HRHKk.js +1 -0
  39. package/src/web/dist/assets/{query-DVc6ZTRQ.js → query-1Ng1fzmE.js} +1 -1
  40. package/src/web/dist/assets/{radix-B9EIjzyN.js → radix-DONH6gHT.js} +2 -2
  41. package/src/web/dist/assets/router-Bkbjq53m.js +19 -0
  42. package/src/web/dist/assets/segmented-control-Cxe6ZLHe.js +1 -0
  43. package/src/web/dist/assets/shared-DG0AgdnU.js +1 -0
  44. package/src/web/dist/assets/switch-C58zWdHT.js +1 -0
  45. package/src/web/dist/assets/tabs-BIz291zK.js +1 -0
  46. package/src/web/dist/assets/{types-DYz12j32.js → types-BT3gK5lJ.js} +1 -1
  47. package/src/web/dist/assets/useAppMutation-CsoNTPQ7.js +1 -0
  48. package/src/web/dist/assets/{useEventStream-CQTreYBE.js → useEventStream-CvopQT4p.js} +1 -1
  49. package/src/web/dist/assets/useProviderForm-B_wmywxX.js +1 -0
  50. package/src/web/dist/assets/vendor-C-lQMZp3.js +455 -0
  51. package/src/web/dist/index.html +32 -10
  52. package/src/web/dist/landing.html +7 -7
  53. package/src/web/dist/assets/About-BJbSQIDc.js +0 -1
  54. package/src/web/dist/assets/ApiKeys-C8I9ti-a.js +0 -1
  55. package/src/web/dist/assets/Dashboard-C7n9KzBy.js +0 -1
  56. package/src/web/dist/assets/DialogShell-BbpG8sot.js +0 -1
  57. package/src/web/dist/assets/Events-BGfmA69d.js +0 -1
  58. package/src/web/dist/assets/Help-DUrs56_n.js +0 -4
  59. package/src/web/dist/assets/Login-Dxeq-BfV.js +0 -1
  60. package/src/web/dist/assets/Logs-VRdCNMkl.js +0 -1
  61. package/src/web/dist/assets/PageSection-Bv6dZZwN.js +0 -1
  62. package/src/web/dist/assets/PageState-U6DpaNu4.js +0 -1
  63. package/src/web/dist/assets/PageToolbar-BnDacS2l.js +0 -1
  64. package/src/web/dist/assets/ProvidersWorkbench-DOGrU9Xl.js +0 -1
  65. package/src/web/dist/assets/Settings-CGxWfI_h.js +0 -1
  66. package/src/web/dist/assets/Setup-yKUdrXJQ.js +0 -2
  67. package/src/web/dist/assets/apiKeys-B-WRyKci.js +0 -1
  68. package/src/web/dist/assets/app-BnQl39hq.js +0 -61
  69. package/src/web/dist/assets/badge-RZTsODn-.js +0 -1
  70. package/src/web/dist/assets/card-DhuLMeO9.js +0 -1
  71. package/src/web/dist/assets/clipboard-BnAnBk_-.js +0 -1
  72. package/src/web/dist/assets/disclosure-CJdf1-ap.js +0 -1
  73. package/src/web/dist/assets/global-CWlBZlIY.css +0 -1
  74. package/src/web/dist/assets/metric-card-B_6litu2.js +0 -1
  75. package/src/web/dist/assets/package-CKkVmaOi.js +0 -1
  76. package/src/web/dist/assets/popover-JpUYyIhi.js +0 -1
  77. package/src/web/dist/assets/router-CUBM_FND.js +0 -19
  78. package/src/web/dist/assets/segmented-control-D80bc13p.js +0 -1
  79. package/src/web/dist/assets/select-BTwqvh0l.js +0 -1
  80. package/src/web/dist/assets/shared-DHBfRHZV.js +0 -1
  81. package/src/web/dist/assets/switch-CeKtgMDT.js +0 -1
  82. package/src/web/dist/assets/table-rPjqxS-f.js +0 -1
  83. package/src/web/dist/assets/tabs-DYNHHISl.js +0 -1
  84. package/src/web/dist/assets/useAppMutation-Cix9n50u.js +0 -1
  85. package/src/web/dist/assets/useProviderForm-CsPV2Cqr.js +0 -1
  86. package/src/web/dist/assets/utils-HY2ZFw0f.js +0 -3
  87. package/src/web/dist/assets/vendor-D2wC0h2o.js +0 -409
package/README.md CHANGED
@@ -72,6 +72,7 @@ Web console: http://127.0.0.1:4100/ui
72
72
  - npm 安装默认分发预编译原生二进制,普通用户不需要本机 Rust 环境
73
73
  - Web 控制台、CLI 命令习惯、配置文件路径与 SQLite 数据格式继续兼容
74
74
  - 聚合模型:一个虚拟模型名挂多个后端(可跨供应商、跨模型名),按优先级自动降级,配额用完不再手动切流量
75
+ - 统一货币计费:内置常见模型价格表、可按模型覆盖,成本按展示货币实时铺满仪表盘 / 日志 / 维度统计,改价即全量重算
75
76
 
76
77
  ## 控制台预览
77
78
 
@@ -134,6 +135,7 @@ http://127.0.0.1:4100/ui
134
135
  - 已实现 Anthropic / OpenAI Chat / OpenAI Responses 的代理与流式转换
135
136
  - 已实现 API Key、日志、事件、统计、路由预设、自定义端点和 SQLite 兼容迁移
136
137
  - 已实现聚合模型(虚拟供应商 + 成员链串行优先级降级、冷却自动恢复与后端健康观测),详见 [`docs/aggregate-models.md`](docs/aggregate-models.md)
138
+ - 已实现统一货币计费(内置价格表 + 用户覆盖 + 汇率换算,查询期实时计价不落库),详见 [`docs/billing.md`](docs/billing.md)
137
139
 
138
140
  ## 本地开发
139
141
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chenpu17/cc-gw",
3
- "version": "0.13.0",
3
+ "version": "0.17.1",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "Local-first AI gateway for personal developers and small software teams, with web console and CLI daemon.",
@@ -34,10 +34,10 @@
34
34
  "README.md"
35
35
  ],
36
36
  "optionalDependencies": {
37
- "@chenpu17/cc-gw-darwin-arm64": "0.13.0",
38
- "@chenpu17/cc-gw-linux-arm64": "0.13.0",
39
- "@chenpu17/cc-gw-win32-x64": "0.13.0",
40
- "@chenpu17/cc-gw-linux-x64": "0.13.0"
37
+ "@chenpu17/cc-gw-linux-arm64": "0.17.1",
38
+ "@chenpu17/cc-gw-win32-x64": "0.17.1",
39
+ "@chenpu17/cc-gw-darwin-arm64": "0.17.1",
40
+ "@chenpu17/cc-gw-linux-x64": "0.17.1"
41
41
  },
42
42
  "dependencies": {
43
43
  "colorette": "^2.0.20",
@@ -65,10 +65,10 @@
65
65
  "pack:dry-run": "pnpm run build:package && node scripts/pack-root-package.mjs",
66
66
  "publish:packed": "node scripts/publish-artifacts.mjs",
67
67
  "test:e2e:web": "pnpm build && playwright test",
68
- "test:e2e:web:core": "pnpm build && playwright test tests/playwright/aggregate-models.spec.ts tests/playwright/landing.spec.ts tests/playwright/pages.spec.ts tests/playwright/auth.spec.ts tests/playwright/logs.spec.ts tests/playwright/dashboard.spec.ts tests/playwright/events.spec.ts tests/playwright/model-management.spec.ts tests/playwright/settings.spec.ts tests/playwright/api-keys.spec.ts tests/playwright/provider-rpm.spec.ts --reporter=line",
68
+ "test:e2e:web:core": "pnpm build && playwright test tests/playwright/aggregate-models.spec.ts tests/playwright/landing.spec.ts tests/playwright/pages.spec.ts tests/playwright/theme-families.spec.ts tests/playwright/auth.spec.ts tests/playwright/logs.spec.ts tests/playwright/dashboard.spec.ts tests/playwright/events.spec.ts tests/playwright/model-management.spec.ts tests/playwright/settings.spec.ts tests/playwright/billing.spec.ts tests/playwright/api-keys.spec.ts tests/playwright/provider-rpm.spec.ts tests/playwright/provider-endpoints-keys.spec.ts tests/playwright/absolute-url.spec.ts tests/playwright/stream-usage.spec.ts tests/playwright/setup-wizard.spec.ts --reporter=line",
69
69
  "test:e2e:web:visual": "pnpm build && playwright test tests/playwright/visual.spec.ts tests/playwright/visual.overlays.spec.ts tests/playwright/visual.data.spec.ts --reporter=line",
70
70
  "test:e2e:web:hardening": "pnpm build && playwright test tests/playwright/hardening.spec.ts --reporter=line",
71
- "test:e2e:web:update-snapshots": "pnpm build && playwright test tests/playwright/visual.spec.ts tests/playwright/visual.overlays.spec.ts tests/playwright/visual.data.spec.ts --update-snapshots --reporter=line",
71
+ "test:e2e:web:update-snapshots": "pnpm build && playwright test tests/playwright/visual.spec.ts tests/playwright/visual.overlays.spec.ts tests/playwright/visual.data.spec.ts --update-snapshots=all --reporter=line",
72
72
  "typecheck": "pnpm --filter @cc-gw/cli exec tsc --noEmit && pnpm --filter @cc-gw/web exec tsc --noEmit"
73
73
  }
74
74
  }
@@ -0,0 +1 @@
1
+ import{r as n,j as t,ab as C,b9 as v,aE as E,a0 as S}from"./vendor-C-lQMZp3.js";import{P}from"./PageToolbar-GyUQBhmq.js";import{P as l}from"./PageSection-Dd2-9G6C.js";import{P as A,a as j}from"./PageState-Bbhr4fy6.js";import{u as V}from"./useAppMutation-CsoNTPQ7.js";import{u as L,b as q,B as c,C as k,c as y,q as F,r as M}from"./app-DZpd2fu9.js";import{p as z}from"./package-DgoCoO-z.js";import{u as B}from"./i18n-ClvfZhYc.js";import"./global-BCYo_xAt.js";import"./router-Bkbjq53m.js";import"./query-1Ng1fzmE.js";import"./radix-DONH6gHT.js";function X(){var p,b,x,h,g;const{t:e}=B(),{pushToast:r}=L(),[o,w]=n.useState(null),a=q(F.status.gateway(),{url:"/api/status",method:"GET"},{staleTime:6e4});n.useEffect(()=>{a.isError&&a.error&&r({title:e("about.toast.statusError.title"),description:a.error.message,variant:"error"})},[r,a.error,a.isError,e]);const i=V({mutationFn:async()=>M({url:"/api/version/check",method:"GET"}),successToast:s=>s.updateAvailable?{title:e("about.toast.updateAvailable.title",{version:s.latestVersion}),description:e("about.toast.updateAvailable.description",{packageName:s.packageName})}:{title:e("about.toast.upToDate.title",{version:s.currentVersion}),description:e("about.toast.upToDate.description")},errorToast:s=>({title:e("about.toast.updateError.title"),description:s.message}),onSuccess:async s=>{w(s)}}),u=z.version,d="2026-10-22T12:53:17.350Z",T=n.useMemo(()=>{var s,f;return[{label:e("about.app.labels.name"),value:t.jsx("span",{className:"font-mono",children:"cc-gw"})},{label:e("about.app.labels.version"),value:t.jsxs("span",{"data-visual-volatile":"true",className:"font-mono text-foreground",children:["v",u]})},{label:e("about.app.labels.buildTime"),value:t.jsx("span",{"data-visual-volatile":"true",children:d}),hint:e("about.app.hint.buildTime")},{label:e("about.app.labels.runtime"),value:t.jsx("span",{className:"font-mono",children:((s=a.data)==null?void 0:s.runtime)??"rust"})},{label:e("about.app.labels.backendVersion"),value:t.jsx("span",{"data-visual-volatile":"true",className:"font-mono",children:((f=a.data)==null?void 0:f.backendVersion)??"-"})}]},[u,d,(p=a.data)==null?void 0:p.backendVersion,(b=a.data)==null?void 0:b.runtime,e]),m=n.useMemo(()=>{var s;return a.data?[{label:e("about.status.labels.providers"),value:a.data.providers.toLocaleString()},{label:e("about.status.labels.active"),value:(a.data.activeRequests??0).toLocaleString(),hint:e("about.status.hint.active")},{label:e("about.status.labels.platform"),value:a.data.platform??"-"},{label:e("about.status.labels.pid"),value:t.jsx("span",{"data-visual-volatile":"true",children:((s=a.data.pid)==null?void 0:s.toLocaleString())??"-"})}]:[]},[a.data,e]);return t.jsxs("div",{className:"flex flex-col gap-6",children:[t.jsx(P,{actions:t.jsxs(c,{onClick:()=>i.mutate(),disabled:i.isPending,size:"sm",children:[t.jsx(C,{className:`mr-2 h-4 w-4${i.isPending?" animate-spin":""}`,"aria-hidden":"true"}),i.isPending?e("about.support.actions.checkingUpdates"):e("about.support.actions.checkUpdates")]})}),t.jsx(k,{className:"overflow-hidden",children:t.jsxs(y,{className:"space-y-4 p-5",children:[t.jsxs("div",{children:[t.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-[0.16em] text-muted-foreground",children:e("about.gateway.address")}),t.jsxs("p",{"data-visual-volatile":"true",className:"metric-number mt-1 truncate text-4xl font-semibold tracking-tight text-foreground",children:["http://",((x=a.data)==null?void 0:x.host)??"127.0.0.1",":",((h=a.data)==null?void 0:h.port)??"-"]})]}),o?t.jsxs("div",{className:"rounded-lg bg-secondary px-4 py-3 text-sm text-muted-foreground",children:[t.jsx("p",{className:"font-medium text-foreground",children:o.updateAvailable?e("about.update.available",{version:o.latestVersion}):e("about.update.current",{version:o.currentVersion})}),t.jsxs("p",{className:"mt-1",children:[e("about.update.channel",{channel:o.channel}),o.publishedAt?` · ${new Date(o.publishedAt).toLocaleString()}`:""]})]}):null]})}),t.jsxs("div",{className:"grid gap-6 lg:grid-cols-2",children:[t.jsx(l,{title:e("about.app.title"),description:e("about.app.subtitle"),children:t.jsx(N,{items:T})}),t.jsx(l,{title:e("about.status.title"),description:e("about.status.subtitle"),actions:t.jsxs(c,{variant:"outline",size:"sm",onClick:()=>void a.refetch(),disabled:a.isFetching,children:[t.jsx(E,{className:D(a.isFetching),"aria-hidden":"true"}),a.isFetching?e("common.actions.refreshing"):e("common.actions.refresh")]}),children:a.isLoading?t.jsx(A,{compact:!0,label:e("about.status.loading")}):a.isError?t.jsx(j,{compact:!0,tone:"danger",icon:t.jsx(v,{className:"h-5 w-5","aria-hidden":"true"}),title:e("common.status.error"),description:((g=a.error)==null?void 0:g.message)??e("common.unknownError"),action:t.jsx(c,{variant:"outline",size:"sm",onClick:()=>void a.refetch(),children:e("common.actions.refresh")})}):m.length>0?t.jsx(N,{items:m}):t.jsx(j,{compact:!0,tone:"primary",icon:t.jsx(v,{className:"h-5 w-5","aria-hidden":"true"}),title:e("about.status.empty"),description:e("common.actions.refresh")})})]}),t.jsx(l,{title:e("about.support.title"),description:t.jsxs("span",{className:"space-y-1",children:[t.jsx("span",{className:"block text-sm font-medium text-foreground",children:e("about.support.subtitle")}),t.jsx("span",{children:e("about.support.description")})]}),children:t.jsxs("div",{className:"flex flex-col gap-4 md:flex-row md:items-start md:justify-between",children:[t.jsxs("div",{className:"flex items-start gap-4 rounded-lg bg-secondary p-4",children:[t.jsx("div",{className:"flex h-11 w-11 items-center justify-center rounded-xl bg-background text-foreground",children:t.jsx(S,{className:"h-5 w-5","aria-hidden":"true"})}),t.jsx("p",{className:"max-w-2xl text-sm text-muted-foreground",children:e("about.support.tip")})]}),t.jsx("code",{className:"inline-flex self-start rounded-lg bg-secondary px-3 py-2 text-xs font-medium",children:"~/.cc-gw/config.json"})]})})]})}function N({items:e}){return e.length===0?null:t.jsx("dl",{className:"grid gap-3 sm:grid-cols-2",children:e.map(r=>t.jsx(k,{className:"rounded-xl border border-border bg-secondary shadow-none",children:t.jsxs(y,{className:"p-4",children:[t.jsx("dt",{className:"text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:r.label}),t.jsx("dd",{className:"metric-number mt-2 text-sm font-semibold text-foreground",children:r.value}),r.hint?t.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:r.hint}):null]})},r.label))})}function D(e){return`mr-2 h-4 w-4${e?" animate-spin":""}`}export{X as default};
@@ -0,0 +1 @@
1
+ import{r as p,j as e,a4 as xs,ay as ie,Z as De,b3 as B,aX as ne,aG as us,b4 as fe,b5 as ms,aY as Te,b1 as ke,a$ as hs}from"./vendor-C-lQMZp3.js";import{a as ae,P as gs}from"./PageState-Bbhr4fy6.js";import{P as ys}from"./PageToolbar-GyUQBhmq.js";import{B as m,C as G,c as Ae,u as js,a as O,b as Z,s as R,q as K}from"./app-DZpd2fu9.js";import{T as bs,a as vs,b as Ne,c as we}from"./tabs-BIz291zK.js";import{C as Ks}from"./ConfirmDialog-_CIYYtzo.js";import{D as le,A as re,a as ce,b as oe,c as Me,d as de,e as pe}from"./DialogShell-D1T4HXtd.js";import{L as V,I as U}from"./label-09axTkPo.js";import{c as fs}from"./global-BCYo_xAt.js";import{E as We,R as ze,u as Ns}from"./shared-DG0AgdnU.js";import{u as f}from"./i18n-ClvfZhYc.js";import{L as ws}from"./router-Bkbjq53m.js";import{M as J,T as Cs,a as Es,b as Ce,c as z,d as Ds,e as q,E as Ts,u as ks}from"./chartTheme-ChTod603.js";import{P as qe}from"./PageSection-Dd2-9G6C.js";import{B as A}from"./badge-CWbm9P64.js";import{S as te}from"./segmented-control-Cxe6ZLHe.js";import{e as As}from"./charts-core-BuoE1ECx.js";import{u as S}from"./useAppMutation-CsoNTPQ7.js";import{a as F}from"./apiKeys-B5Os17Qm.js";import{c as Ms}from"./clipboard-DqvcglYs.js";import"./query-1Ng1fzmE.js";import"./radix-DONH6gHT.js";import"./charts-react-BLOapElb.js";import"./charts-engine-DHIzBJl6.js";const Fe=p.forwardRef(({className:a,...s},o)=>e.jsx("textarea",{className:fs("flex min-h-[80px] w-full rounded-xl border border-border bg-card px-3 py-2.5 text-sm text-foreground ring-offset-background placeholder:text-muted-foreground/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",a),ref:o,...s}));Fe.displayName="Textarea";function Ws({availableEndpoints:a,isOpen:s,keyDescription:o,keyName:n,maxConcurrency:r,onDescriptionChange:x,onEndpointsChange:b,onKeyNameChange:j,onMaxConcurrencyChange:u,onOpenChange:d,onSubmit:g,selectedEndpoints:i}){const{t:l}=f();return e.jsx(le,{open:s,onOpenChange:d,children:e.jsxs(re,{className:"max-w-2xl",children:[e.jsxs(ce,{children:[e.jsx(oe,{children:l("apiKeys.createNew")}),e.jsx(Me,{children:l("apiKeys.createDescription")})]}),e.jsxs(de,{className:"space-y-4",children:[e.jsx("div",{className:"rounded-lg border border-border bg-secondary px-4 py-3 text-xs text-muted-foreground",children:l("apiKeys.selectEndpoints")}),e.jsxs("div",{className:"grid gap-3 md:grid-cols-3",children:[e.jsxs("div",{className:"rounded-lg border border-border bg-secondary px-3 py-3 text-xs text-foreground",children:[e.jsx("p",{className:"font-semibold",children:"Restricted"}),e.jsx("p",{className:"mt-1 opacity-80",children:"Select explicit endpoints before saving."})]}),e.jsxs("div",{className:"rounded-lg border border-warning/30 bg-warning-bg px-3 py-3 text-xs text-warning",children:[e.jsx("p",{className:"font-semibold",children:"Unrestricted"}),e.jsx("p",{className:"mt-1 opacity-80",children:"Leave endpoint selection empty for broad access."})]}),e.jsxs("div",{className:"rounded-lg border border-destructive/20 bg-destructive/5 px-3 py-3 text-xs text-destructive",children:[e.jsx("p",{className:"font-semibold",children:"Wildcard"}),e.jsx("p",{className:"mt-1 opacity-80",children:"Special-case key with the highest blast radius."})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(V,{htmlFor:"keyName",children:[l("apiKeys.keyNamePlaceholder")," *"]}),e.jsx(U,{id:"keyName",value:n,onChange:h=>j(h.target.value),placeholder:l("apiKeys.keyNamePlaceholder"),onKeyDown:h=>{h.key==="Enter"&&(h.preventDefault(),g())}})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(V,{htmlFor:"keyDescription",children:l("apiKeys.descriptionLabel")}),e.jsx(Fe,{id:"keyDescription",value:o,onChange:h=>x(h.target.value),placeholder:l("apiKeys.keyDescriptionPlaceholder"),rows:3})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(V,{children:l("apiKeys.allowedEndpoints")}),e.jsx(We,{available:a,selected:i,onChange:b,hint:l("apiKeys.selectEndpoints")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(V,{htmlFor:"maxConcurrency",children:l("apiKeys.maxConcurrency")}),e.jsx(U,{id:"maxConcurrency",type:"number",min:"0",value:r,onChange:h=>u(h.target.value),placeholder:l("apiKeys.maxConcurrencyPlaceholder")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:l("apiKeys.maxConcurrencyHelper")})]})]}),e.jsxs(pe,{children:[e.jsx(m,{variant:"outline",onClick:()=>d(!1),children:l("common.actions.cancel")}),e.jsx(m,{onClick:g,children:l("apiKeys.createAction")})]})]})})}function zs({createdKey:a,onClose:s,onCopy:o}){const{t:n}=f();return e.jsx(le,{open:!!a,onOpenChange:r=>{r||s()},children:e.jsxs(re,{className:"max-w-xl",children:[e.jsx(ce,{children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex h-10 w-10 items-center justify-center rounded-lg bg-success-bg text-success",children:e.jsx(xs,{className:"h-5 w-5","aria-hidden":"true"})}),e.jsx(oe,{children:n("apiKeys.keyCreated")})]})}),e.jsxs(de,{className:"space-y-4",children:[e.jsx("p",{className:"text-sm font-medium text-warning",children:n("apiKeys.saveKeyWarning")}),e.jsx("div",{className:"rounded-lg border border-border bg-secondary px-4 py-3 font-mono text-sm",children:a==null?void 0:a.key}),a!=null&&a.description?e.jsx("p",{className:"whitespace-pre-wrap text-sm text-muted-foreground",children:a.description}):null]}),e.jsxs(pe,{children:[e.jsxs(m,{onClick:()=>o((a==null?void 0:a.key)??""),children:[e.jsx(ie,{className:"mr-2 h-4 w-4","aria-hidden":"true"}),n("common.actions.copy")]}),e.jsx(m,{variant:"outline",onClick:s,children:n("common.actions.close")})]})]})})}function qs({apiKey:a,availableEndpoints:s,maxConcurrency:o,onClose:n,onEndpointsChange:r,onMaxConcurrencyChange:x,onSave:b,selectedEndpoints:j}){const{t:u}=f();return e.jsx(le,{open:!!a,onOpenChange:d=>{d||n()},children:e.jsxs(re,{className:"max-w-2xl",children:[e.jsxs(ce,{children:[e.jsx(oe,{children:u("apiKeys.editEndpoints")}),e.jsx(Me,{children:a==null?void 0:a.name})]}),e.jsxs(de,{className:"space-y-4",children:[!(a!=null&&a.isWildcard)&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"rounded-lg border border-warning/30 bg-warning-bg px-4 py-3 text-xs text-warning",children:u("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(We,{available:s,selected:j,onChange:r,hint:u("apiKeys.selectEndpoints")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(V,{htmlFor:"editMaxConcurrency",children:u("apiKeys.maxConcurrency")}),e.jsx(U,{id:"editMaxConcurrency",type:"number",min:"0",value:o,onChange:d=>x(d.target.value),placeholder:u("apiKeys.maxConcurrencyPlaceholder")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:u("apiKeys.maxConcurrencyHelper")})]})]}),e.jsxs(pe,{children:[e.jsx(m,{variant:"outline",onClick:n,children:u("common.actions.cancel")}),e.jsx(m,{onClick:b,children:u("common.save")})]})]})})}function Fs({deleteTarget:a,isDeleting:s,onConfirm:o,onOpenChange:n}){const{t:r}=f();return e.jsx(Ks,{open:!!a,onOpenChange:n,title:r("apiKeys.deleteDialogTitle"),description:r("apiKeys.confirmDelete"),confirmLabel:a&&s===a.id?r("common.actions.loading"):r("apiKeys.actions.delete"),cancelLabel:r("common.actions.cancel"),loading:a?s===a.id:!1,onConfirm:o,children:a?e.jsx("div",{className:"rounded-lg border border-destructive/20 bg-destructive/10 px-3 py-2 font-mono text-xs text-foreground",children:a.name}):null})}function Ls({onDismiss:a}){const{t:s}=f();return e.jsxs(G,{className:"relative p-3 sm:p-3.5",children:[e.jsxs("div",{className:"flex flex-col gap-3 lg:flex-row lg:items-center lg:justify-between",children:[e.jsxs("div",{className:"max-w-md space-y-1 pr-8",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-wider text-primary/75",children:"Recommended"}),e.jsx("h2",{className:"text-sm font-semibold text-foreground",children:s("apiKeys.quickStart.title")}),e.jsx("p",{className:"text-xs leading-5 text-muted-foreground",children:s("apiKeys.quickStart.description")})]}),e.jsx("div",{className:"-mx-1 overflow-x-auto pb-1 lg:mx-0 lg:overflow-visible lg:pb-0",children:e.jsxs("div",{className:"flex gap-2 px-1 md:grid md:grid-cols-3 md:px-0 lg:max-w-3xl",children:[e.jsx(ee,{icon:e.jsx(De,{className:"h-4 w-4","aria-hidden":"true"}),title:s("apiKeys.quickStart.create.title"),description:s("apiKeys.quickStart.create.description")}),e.jsx(ee,{icon:e.jsx(B,{className:"h-4 w-4","aria-hidden":"true"}),title:s("apiKeys.quickStart.restrict.title"),description:s("apiKeys.quickStart.restrict.description")}),e.jsx(ee,{icon:e.jsx(ne,{className:"h-4 w-4","aria-hidden":"true"}),title:s("apiKeys.quickStart.wildcard.title"),description:s("apiKeys.quickStart.wildcard.description")})]})})]}),a?e.jsx(m,{variant:"ghost",size:"icon",className:"absolute right-1.5 top-1.5 h-7 w-7 text-muted-foreground hover:bg-secondary hover:text-foreground",onClick:a,"aria-label":s("common.actions.close"),children:e.jsx(us,{className:"h-4 w-4","aria-hidden":"true"})}):null]})}function Os({activeKeysValue:a,enabledKeysValue:s,loading:o,onRangeChange:n,rangeDays:r,requestsChartOption:x,totalKeysValue:b,tokensChartOption:j,usageLength:u}){const{t:d}=f();return e.jsx(qe,{title:d("apiKeys.analytics.title"),description:d("apiKeys.analytics.description",{days:r}),actions:e.jsx(te,{className:"w-full overflow-x-auto sm:w-auto",value:r,onChange:n,options:ze.map(g=>({value:g.value,label:d(g.labelKey)}))}),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:d("apiKeys.analytics.cards.total"),value:b,size:"sm"}),e.jsx(J,{label:d("apiKeys.analytics.cards.enabled"),value:s,size:"sm"}),e.jsx(J,{label:d("apiKeys.analytics.cards.active",{days:r}),value:a,size:"sm"})]}),e.jsxs("div",{className:"grid gap-6 lg:grid-cols-2",children:[e.jsx(Ee,{title:d("apiKeys.analytics.charts.requests"),loading:o,empty:u===0,emptyText:d("apiKeys.analytics.empty"),option:x}),e.jsx(Ee,{title:d("apiKeys.analytics.charts.tokens"),loading:o,empty:u===0,emptyText:d("apiKeys.analytics.empty"),option:j})]})]})})}function Rs({filteredKeys:a,formatDate:s,hasWildcard:o,isDeleting:n,isRevealing:r,keys:x,onCopy:b,onDelete:j,onEditEndpoints:u,onFilterChange:d,onHide:g,onReveal:i,onStatusFilterChange:l,onToggleEnabled:h,revealedKeys:C,search:D,statusFilter:E,viewMode:N,onViewModeChange:M,onCreateKey:v}){const{t:y}=f();return e.jsx(qe,{title:y("apiKeys.list.title"),description:o?y("apiKeys.wildcardHint"):void 0,actions:e.jsxs("div",{className:"flex w-full flex-wrap items-center justify-between gap-2 sm:w-auto sm:justify-end",children:[e.jsx(te,{value:N,onChange:M,options:[{value:"cards",label:y("apiKeys.views.cards"),icon:e.jsx(fe,{className:"h-3.5 w-3.5","aria-hidden":"true"})},{value:"compact",label:y("apiKeys.views.compact"),icon:e.jsx(ms,{className:"h-3.5 w-3.5","aria-hidden":"true"})}]}),e.jsx("div",{className:"flex flex-wrap items-center gap-2",children:e.jsx(A,{variant:"outline",children:y("apiKeys.list.count",{shown:a.length,total:x.length})})})]}),children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid gap-3 rounded-xl bg-secondary p-4 sm:grid-cols-[minmax(0,1fr)_auto]",children:[e.jsx(U,{value:D,onChange:w=>d(w.target.value),placeholder:y("apiKeys.filters.searchPlaceholder")}),e.jsx(te,{value:E,onChange:l,className:"min-w-max overflow-x-auto bg-background sm:justify-self-end",options:[{value:"all",label:y("apiKeys.filters.all")},{value:"enabled",label:y("apiKeys.filters.enabled")},{value:"disabled",label:y("apiKeys.filters.disabled")}]})]}),x.length===0?e.jsx(ae,{compact:!0,tone:"primary",className:"rounded-xl border border-dashed border-border/40 bg-background",icon:e.jsx(De,{className:"h-5 w-5","aria-hidden":"true"}),title:y("apiKeys.list.emptyTitle"),description:y("apiKeys.list.empty"),action:e.jsx(m,{variant:"outline",size:"sm",onClick:v,children:y("apiKeys.createNew")})}):a.length===0?e.jsx(ae,{compact:!0,tone:"primary",className:"rounded-xl border border-dashed border-border/40 bg-background",icon:e.jsx(fe,{className:"h-5 w-5","aria-hidden":"true"}),title:y("apiKeys.list.emptyFilteredTitle"),description:y("apiKeys.list.emptyFiltered"),action:e.jsx(m,{variant:"outline",size:"sm",onClick:()=>{d(""),l("all")},children:y("common.actions.reset")})}):N==="compact"?e.jsx(Ps,{filteredKeys:a,formatDate:s,isDeleting:n,isRevealing:r,onCopy:b,onDelete:j,onEditEndpoints:u,onHide:g,onReveal:i,onToggleEnabled:h,revealedKeys:C}):e.jsx("div",{className:"grid gap-4",children:a.map(w=>e.jsx(Vs,{formatDate:s,isDeleting:n===w.id,isRevealing:r===w.id,keySummary:w,onCopy:b,onDelete:j,onEditEndpoints:u,onHide:g,onReveal:i,onToggleEnabled:h,revealedValue:C.get(w.id)},w.id))})]})})}function Ps({filteredKeys:a,formatDate:s,isDeleting:o,isRevealing:n,onCopy:r,onDelete:x,onEditEndpoints:b,onHide:j,onReveal:u,onToggleEnabled:d,revealedKeys:g}){const{t:i}=f();return e.jsx(G,{variant:"solid",className:"overflow-hidden",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs(Cs,{className:"min-w-[980px]",children:[e.jsx(Es,{children:e.jsxs(Ce,{className:"bg-secondary/45 hover:bg-secondary/45",children:[e.jsx(z,{children:i("apiKeys.table.name")}),e.jsx(z,{children:i("apiKeys.table.access")}),e.jsx(z,{className:"text-right",children:i("apiKeys.requestCount")}),e.jsx(z,{className:"text-right",children:i("apiKeys.totalTokens")}),e.jsx(z,{className:"text-right",children:i("apiKeys.maxConcurrency")}),e.jsx(z,{children:i("apiKeys.lastUsed")}),e.jsx(z,{className:"w-[132px] text-right",children:i("apiKeys.table.actions")})]})}),e.jsx(Ds,{children:a.map(l=>{var E,N,M;const h=g.get(l.id),C=(l.totalInputTokens+l.totalOutputTokens).toLocaleString(),D=l.isWildcard?i("apiKeys.wildcard"):(((E=l.allowedEndpoints)==null?void 0:E.length)??0)>0?(N=l.allowedEndpoints)==null?void 0:N.join(", "):i("apiKeys.allEndpoints");return e.jsxs(Ce,{children:[e.jsx(q,{className:"py-3",children:e.jsxs("div",{className:"min-w-0 space-y-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"font-semibold text-foreground",children:l.name}),l.isWildcard?e.jsx(A,{variant:"secondary",className:"text-[11px]",children:i("apiKeys.wildcard")}):null,e.jsx(A,{variant:l.enabled?"default":"outline",className:"text-[11px]",children:l.enabled?i("apiKeys.status.enabled"):i("apiKeys.status.disabled")})]}),l.isWildcard?null:e.jsxs("div",{className:"flex min-w-0 items-center gap-1.5",children:[e.jsx("code",{className:"max-w-[220px] truncate rounded-md bg-secondary px-2 py-1 font-mono text-xs",children:h??l.maskedKey??"********"}),h?e.jsxs(e.Fragment,{children:[e.jsx(m,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:()=>r(h),"aria-label":i("common.actions.copy"),children:e.jsx(ie,{className:"h-3.5 w-3.5","aria-hidden":"true"})}),e.jsx(m,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:()=>j(l.id),"aria-label":i("apiKeys.actions.hide"),children:e.jsx(ne,{className:"h-3.5 w-3.5","aria-hidden":"true"})})]}):e.jsx(m,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:()=>u(l.id),disabled:n===l.id,"aria-label":i("apiKeys.actions.reveal"),children:n===l.id?e.jsx("div",{className:"h-3.5 w-3.5 animate-spin rounded-full border-2 border-primary border-t-transparent"}):e.jsx(Te,{className:"h-3.5 w-3.5","aria-hidden":"true"})})]})]})}),e.jsx(q,{className:"py-3",children:e.jsxs("div",{className:"max-w-[180px]",children:[e.jsx("div",{className:"truncate text-sm text-foreground",title:D,children:D}),e.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:l.isWildcard?i("apiKeys.table.accessWildcard"):(((M=l.allowedEndpoints)==null?void 0:M.length)??0)>0?i("apiKeys.endpointRestricted"):i("apiKeys.table.accessOpen")})]})}),e.jsx(q,{className:"py-3 text-right font-medium",children:l.requestCount.toLocaleString()}),e.jsx(q,{className:"py-3 text-right font-medium",children:C}),e.jsx(q,{className:"py-3 text-right font-medium",children:l.maxConcurrency?String(l.maxConcurrency):"—"}),e.jsxs(q,{className:"py-3",children:[e.jsx("div",{"data-visual-volatile":"true",className:"text-sm font-medium text-foreground",children:s(l.lastUsedAt)}),e.jsx("div",{"data-visual-volatile":"true",className:"mt-1 text-xs text-muted-foreground",children:i("apiKeys.createdValue",{date:s(l.createdAt)})})]}),e.jsx(q,{className:"py-3",children:e.jsxs("div",{className:"flex justify-end gap-1",children:[e.jsx(m,{variant:"outline",size:"icon",onClick:()=>b(l),className:"h-8 w-8","aria-label":l.isWildcard?i("apiKeys.maxConcurrency"):i("apiKeys.editEndpoints"),title:l.isWildcard?i("apiKeys.maxConcurrency"):i("apiKeys.editEndpoints"),children:e.jsx(B,{className:"h-3.5 w-3.5","aria-hidden":"true"})}),e.jsx(m,{variant:"outline",size:"sm","data-testid":"api-key-toggle",onClick:()=>d(l.id,l.enabled),className:"h-8 px-2.5 text-xs",children:l.enabled?i("apiKeys.actions.disable"):i("apiKeys.actions.enable")}),l.isWildcard?null:e.jsx(m,{variant:"ghost",size:"icon",className:"h-8 w-8 text-destructive hover:bg-destructive/10 hover:text-destructive",onClick:()=>x(l),disabled:o===l.id,"aria-label":i("apiKeys.actions.delete"),children:e.jsx(ke,{className:"h-3.5 w-3.5","aria-hidden":"true"})})]})})]},l.id)})})]})})})}function ee({description:a,icon:s,title:o}){return e.jsxs("div",{className:"w-[220px] shrink-0 rounded-xl border border-border bg-card p-3 md:w-auto",children:[e.jsx("div",{className:"flex h-7 w-7 items-center justify-center rounded-lg bg-secondary text-foreground sm:h-8 sm:w-8 sm:rounded-lg",children:s}),e.jsx("p",{className:"mt-2 text-[12px] font-semibold leading-5 text-foreground sm:mt-2.5 sm:text-[13px]",children:o}),e.jsx("p",{className:"mt-1 line-clamp-2 text-[11px] leading-4.5 text-muted-foreground sm:text-xs sm:leading-5",children:a})]})}function Vs({formatDate:a,isDeleting:s,isRevealing:o,keySummary:n,onCopy:r,onDelete:x,onEditEndpoints:b,onHide:j,onReveal:u,onToggleEnabled:d,revealedValue:g}){var h,C,D;const{t:i}=f(),l=(n.totalInputTokens+n.totalOutputTokens).toLocaleString();return e.jsx(G,{"data-testid":"api-key-card",className:"overflow-hidden",children:e.jsx(Ae,{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:n.name}),n.isWildcard?e.jsx(A,{variant:"secondary",children:i("apiKeys.wildcard")}):null,e.jsx(A,{variant:n.enabled?"default":"outline",children:n.enabled?i("apiKeys.status.enabled"):i("apiKeys.status.disabled")}),n.isWildcard?null:e.jsx(A,{variant:"outline",className:"text-xs",children:(((h=n.allowedEndpoints)==null?void 0:h.length)??0)>0?i("apiKeys.endpointRestricted"):i("apiKeys.allEndpoints")}),!n.isWildcard&&n.allowedEndpoints&&n.allowedEndpoints.length>0?n.allowedEndpoints.map(E=>e.jsx(A,{variant:"outline",className:"text-xs",children:E},E)):n.isWildcard?null:e.jsx(A,{variant:"secondary",className:"text-xs opacity-60",children:i("apiKeys.allEndpoints")})]}),e.jsxs("div",{className:"grid gap-2 sm:grid-cols-3",children:[e.jsx(se,{label:i("apiKeys.requestCount"),value:n.requestCount.toLocaleString()}),e.jsx(se,{label:i("apiKeys.totalTokens"),value:l}),e.jsx(se,{label:i("apiKeys.maxConcurrency"),value:n.maxConcurrency?String(n.maxConcurrency):i("apiKeys.maxConcurrencyPlaceholder")})]}),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 bg-secondary px-3 py-1.5 font-mono text-sm",children:n.isWildcard?i("apiKeys.wildcard"):g??n.maskedKey??"********"}),n.isWildcard?null:e.jsx("div",{className:"flex items-center gap-1 self-start",children:g?e.jsxs(e.Fragment,{children:[e.jsx(m,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:()=>r(g),"aria-label":i("common.actions.copy"),title:i("common.actions.copy"),children:e.jsx(ie,{className:"h-4 w-4","aria-hidden":"true"})}),e.jsx(m,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:()=>j(n.id),"aria-label":i("apiKeys.actions.hide"),title:i("apiKeys.actions.hide"),children:e.jsx(ne,{className:"h-4 w-4","aria-hidden":"true"})})]}):e.jsx(m,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:()=>u(n.id),disabled:o,"aria-label":i("apiKeys.actions.reveal"),title:i("apiKeys.actions.reveal"),children:o?e.jsx("div",{className:"h-4 w-4 animate-spin rounded-full border-2 border-primary border-t-transparent"}):e.jsx(Te,{className:"h-4 w-4","aria-hidden":"true"})})})]}),n.isWildcard?e.jsx("p",{className:"text-sm text-muted-foreground",children:i("apiKeys.wildcardHint")}):n.description?e.jsx("p",{className:"whitespace-pre-wrap text-sm text-muted-foreground",children:n.description}):null,n.isWildcard?null:e.jsx("div",{className:"rounded-lg bg-secondary px-3 py-2 text-xs text-muted-foreground",children:(((C=n.allowedEndpoints)==null?void 0:C.length)??0)>0?`${i("apiKeys.allowedEndpoints")}: ${(D=n.allowedEndpoints)==null?void 0:D.join(", ")}`:i("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:i("apiKeys.created")}),e.jsx("p",{"data-visual-volatile":"true",className:"font-medium",children:a(n.createdAt)})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("span",{className:"text-xs font-medium uppercase tracking-wide text-muted-foreground",children:i("apiKeys.lastUsed")}),e.jsx("p",{"data-visual-volatile":"true",className:"font-medium",children:a(n.lastUsedAt)})]})]})]}),e.jsxs("div",{className:"grid gap-2 sm:grid-cols-2 lg:flex lg:flex-wrap lg:justify-end",children:[e.jsxs(m,{variant:"outline",size:"sm",onClick:()=>b(n),className:"w-full lg:w-auto",children:[e.jsx(B,{className:"mr-1 h-3.5 w-3.5","aria-hidden":"true"}),n.isWildcard?i("apiKeys.maxConcurrency"):i("apiKeys.editEndpoints")]}),e.jsx(m,{variant:"outline",size:"sm","data-testid":"api-key-toggle",onClick:()=>d(n.id,n.enabled),className:"w-full lg:w-auto",children:n.enabled?i("apiKeys.actions.disable"):i("apiKeys.actions.enable")}),n.isWildcard?null:e.jsx(m,{variant:"ghost",size:"icon",className:"h-9 w-full text-destructive hover:bg-destructive/10 hover:text-destructive sm:w-9",onClick:()=>x(n),disabled:s,"aria-label":i("apiKeys.actions.delete"),children:e.jsx(ke,{className:"h-4 w-4","aria-hidden":"true"})})]})]})})})}function se({label:a,value:s}){return e.jsxs("div",{className:"rounded-lg bg-secondary px-3 py-2",children:[e.jsx("p",{className:"text-[11px] font-medium uppercase tracking-wider text-muted-foreground",children:a}),e.jsx("p",{className:"mt-1 truncate text-sm font-medium",children:s})]})}function Ee({empty:a,emptyText:s,loading:o,option:n,title:r}){const{t:x}=f();return e.jsx(G,{children:e.jsxs(Ae,{className:"space-y-4 pt-4",children:[e.jsx("h3",{className:"text-base font-semibold",children:r}),o?e.jsx("div",{className:"flex h-[280px] items-center justify-center",children:e.jsx("span",{className:"text-sm text-muted-foreground",children:x("common.loadingShort")})}):a?e.jsx(ae,{compact:!0,className:"min-h-[280px] rounded-xl border border-dashed border-border/40 bg-background",icon:e.jsx(B,{className:"h-5 w-5","aria-hidden":"true"}),title:s,description:x("apiKeys.analytics.emptyHint"),action:e.jsx(m,{asChild:!0,variant:"ghost",size:"sm",children:e.jsx(ws,{to:"/logs",children:x("apiKeys.analytics.actions.logs")})})}):e.jsx(Ts,{echarts:As,option:n,style:{height:280},notMerge:!0,lazyUpdate:!0})]})})}function Is(){const{t:a}=f(),{pushToast:s}=js(),o=ks(),[n,r]=p.useState(!1),[x,b]=p.useState(""),[j,u]=p.useState(""),[d,g]=p.useState([]),[i,l]=p.useState(""),[h,C]=p.useState(null),[D,E]=p.useState(null),[N,M]=p.useState(null),[v,y]=O(R.apiKeys.rangeDays,7,{serialize:t=>String(t),deserialize:t=>{const c=Number(t);return ze.some(T=>T.value===c)?c:7}}),[w,xe]=p.useState(new Map),[Le,ue]=p.useState(null),[P,$]=p.useState(null),[I,me]=p.useState([]),[X,he]=p.useState(""),[_,Oe]=O(R.apiKeys.search,""),[Q,Re]=O(R.apiKeys.statusFilter,"all",{serialize:t=>t,deserialize:t=>t==="enabled"||t==="disabled"?t:"all"}),[Pe,Ve]=O(R.apiKeys.viewMode,()=>typeof window<"u"&&window.matchMedia("(max-width: 767px)").matches?"cards":"compact",{serialize:t=>t,deserialize:t=>t==="cards"?"cards":"compact"}),[Ie,Qe]=O(R.apiKeys.activeTab,"inventory",{serialize:t=>t,deserialize:t=>t==="analytics"?"analytics":"inventory"}),[He,Se]=O(R.apiKeys.quickStartDismissed,!1),Ue=Ns(),ge=Z(K.apiKeys.all(),F.listRequest()),Be=Z(K.apiKeys.overview(v),F.overviewRequest(v)),ye=Z(K.apiKeys.usage(v),F.usageRequest(v)),je=S({mutationFn:F.create,invalidateKeys:[K.apiKeys.all(),K.apiKeys.overview(v),K.apiKeys.usage(v)],successToast:()=>({title:a("apiKeys.toast.keyCreated")}),errorToast:t=>({title:a("apiKeys.toast.createFailure",{message:t.message})})}),H=S({mutationFn:({id:t,...c})=>F.update(t,c),invalidateKeys:[K.apiKeys.all(),K.apiKeys.overview(v),K.apiKeys.usage(v)],successToast:()=>({title:a("apiKeys.toast.keyUpdated")}),errorToast:t=>({title:a("apiKeys.toast.updateFailure",{message:t.message})})}),be=S({mutationFn:({id:t})=>F.delete(t),invalidateKeys:[K.apiKeys.all(),K.apiKeys.overview(v),K.apiKeys.usage(v)],successToast:()=>({title:a("apiKeys.toast.keyDeleted")}),errorToast:t=>({title:a("apiKeys.toast.deleteFailure",{message:t.message})})}),ve=S({mutationFn:({id:t})=>F.reveal(t),errorToast:t=>({title:a("apiKeys.toast.revealFailure"),description:t.message})}),W=ge.data??[],L=Be.data,k=ye.data??[],Ge=W.some(t=>t.isWildcard),$e=W.filter(t=>t.isWildcard).length,Xe=W.filter(t=>{var c;return!t.isWildcard&&(((c=t.allowedEndpoints)==null?void 0:c.length)??0)>0}).length,_e=W.filter(t=>{var c;return!t.isWildcard&&(((c=t.allowedEndpoints)==null?void 0:c.length)??0)===0}).length,Ye=L?L.totalKeys.toLocaleString():"-",Ze=L?L.enabledKeys.toLocaleString():"-",Je=L?L.activeKeys.toLocaleString():"-",es=p.useMemo(()=>W.filter(t=>{if(!(Q==="all"||(Q==="enabled"?t.enabled:!t.enabled)))return!1;const T=_.trim().toLowerCase();return T?[t.name,t.description??"",t.maskedKey??"",...t.allowedEndpoints??[]].join(" ").toLowerCase().includes(T):!0}),[W,_,Q]),ss=p.useMemo(()=>{const t=k.map(c=>c.apiKeyName??a("apiKeys.analytics.unknownKey"));return{tooltip:{trigger:"axis"},grid:{left:60,right:20,top:40,bottom:40},xAxis:{type:"category",data:t,axisLabel:{interval:0,rotate:20}},yAxis:{type:"value"},series:[{name:a("apiKeys.analytics.requestsSeries"),type:"bar",data:k.map(c=>c.requests),itemStyle:{color:o.palette[0]}}]}},[a,k,o]),as=p.useMemo(()=>{const t=k.map(c=>c.apiKeyName??a("apiKeys.analytics.unknownKey"));return{tooltip:{trigger:"axis"},legend:{data:[a("apiKeys.analytics.tokens.input"),a("apiKeys.analytics.tokens.output")]},grid:{left:60,right:20,top:50,bottom:40},xAxis:{type:"category",data:t,axisLabel:{interval:0,rotate:20}},yAxis:{type:"value"},series:[{name:a("apiKeys.analytics.tokens.input"),type:"bar",stack:"tokens",itemStyle:{color:o.palette[0]},data:k.map(c=>c.inputTokens)},{name:a("apiKeys.analytics.tokens.output"),type:"bar",stack:"tokens",itemStyle:{color:o.palette[2]},data:k.map(c=>c.outputTokens)}]}},[a,k,o]),Ke=p.useCallback(()=>{b(""),u(""),g([]),l("")},[]),Y=p.useCallback(t=>{r(t),t||Ke()},[Ke]),ts=p.useCallback(async()=>{if(!x.trim()){s({title:a("apiKeys.errors.nameRequired"),variant:"error"});return}const t=i.trim();if(t&&(!Number.isInteger(Number(t))||Number(t)<0)){s({title:a("apiKeys.errors.maxConcurrencyInvalid"),variant:"error"});return}try{const c=await je.mutateAsync({name:x.trim(),description:j.trim()||void 0,allowedEndpoints:d.length>0?d:void 0,maxConcurrency:Number(t)>0?Number(t):null});C(c),Y(!1)}catch{}},[je,Y,j,d,i,x,s,a]),is=p.useCallback(async(t,c)=>{try{await H.mutateAsync({id:t,enabled:!c})}catch{}},[H]),ns=p.useCallback(async()=>{if(N){E(N.id);try{await be.mutateAsync({id:N.id}),M(null)}catch{}finally{E(null)}}},[N,be]),ls=p.useCallback(async t=>{if(!w.has(t)){ue(t);try{const c=await ve.mutateAsync({id:t});xe(T=>new Map(T).set(t,c.key))}catch{}finally{ue(null)}}},[ve,w]),rs=p.useCallback(t=>{xe(c=>{const T=new Map(c);return T.delete(t),T})},[]),cs=p.useCallback(async t=>{try{await Ms(t),s({title:a("apiKeys.toast.keyCopied"),variant:"success"})}catch(c){s({title:a("apiKeys.toast.copyFailure"),description:c instanceof Error?c.message:a("common.unknownError"),variant:"error"})}},[s,a]),os=p.useCallback(t=>{$(t),me(t.allowedEndpoints??[]),he(t.maxConcurrency?String(t.maxConcurrency):"")},[]),ds=p.useCallback(async()=>{if(!P)return;const t=X.trim();if(t&&(!Number.isInteger(Number(t))||Number(t)<0)){s({title:a("apiKeys.errors.maxConcurrencyInvalid"),variant:"error"});return}try{await H.mutateAsync({id:P.id,...P.isWildcard?{}:{allowedEndpoints:I.length>0?I:null},maxConcurrency:Number(t)>0?Number(t):null}),$(null)}catch{}},[P,I,X,s,a,H]),ps=p.useCallback(t=>t?new Date(t).toLocaleString():a("common.noData"),[a]);return{activeKeysValue:Je,activeTab:Ie,availableEndpoints:Ue,deleteTarget:N,editEndpointsKey:P,editEndpointsSelection:I,editMaxConcurrency:X,enabledKeysValue:Ze,filteredKeys:es,formatDate:ps,handleCopyKey:cs,handleCreateDialogChange:Y,handleCreateKey:ts,handleDeleteKey:ns,handleHideKey:rs,handleOpenEditEndpoints:os,handleRevealKey:ls,handleSaveEndpoints:ds,handleToggleEnabled:is,hasWildcard:Ge,isCreateDialogOpen:n,isDeleting:D,isRevealing:Le,keys:W,keysQuery:ge,newKeyDescription:j,newKeyEndpoints:d,newKeyMaxConcurrency:i,newKeyName:x,newlyCreatedKey:h,quickStartDismissed:He,rangeDays:v,requestsChartOption:ss,restrictedCount:Xe,revealedKeys:w,search:_,setQuickStartDismissed:Se,setActiveTab:Qe,setDeleteTarget:M,setEditEndpointsKey:$,setEditEndpointsSelection:me,setEditMaxConcurrency:he,setNewKeyDescription:u,setNewKeyEndpoints:g,setNewKeyMaxConcurrency:l,setNewKeyName:b,setNewlyCreatedKey:C,setRangeDays:y,setSearch:Oe,setStatusFilter:Re,statusFilter:Q,tokensChartOption:as,totalKeysValue:Ye,unrestrictedCount:_e,usage:k,usageQuery:ye,viewMode:Pe,wildcardCount:$e,setViewMode:Ve}}function xa(){const{t:a}=f(),s=Is();if(s.keysQuery.isLoading)return e.jsx(gs,{label:a("common.loading")});const n=s.keys.filter(r=>!r.isWildcard).length===0&&!s.quickStartDismissed;return e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx(ys,{status:e.jsxs("span",{className:"text-xs text-muted-foreground",children:[a("apiKeys.summary.wildcard",{count:s.wildcardCount})," / ",a("apiKeys.summary.restricted",{count:s.restrictedCount})," / ",a("apiKeys.summary.unrestricted",{count:s.unrestrictedCount})]}),actions:e.jsxs(m,{size:"sm",onClick:()=>s.handleCreateDialogChange(!0),children:[e.jsx(hs,{className:"mr-2 h-4 w-4","aria-hidden":"true"}),a("apiKeys.createNew")]})}),n?e.jsx(Ls,{onDismiss:()=>s.setQuickStartDismissed(!0)}):null,e.jsxs(bs,{value:s.activeTab,onValueChange:r=>s.setActiveTab(r),children:[e.jsxs(vs,{children:[e.jsx(Ne,{value:"inventory",children:a("apiKeys.tabs.inventory")}),e.jsx(Ne,{value:"analytics",children:a("apiKeys.tabs.analytics")})]}),e.jsx(we,{value:"inventory",className:"mt-4",children:e.jsx(Rs,{filteredKeys:s.filteredKeys,formatDate:s.formatDate,hasWildcard:s.hasWildcard,isDeleting:s.isDeleting,isRevealing:s.isRevealing,keys:s.keys,onCopy:r=>void s.handleCopyKey(r),onDelete:s.setDeleteTarget,onEditEndpoints:s.handleOpenEditEndpoints,onFilterChange:s.setSearch,onHide:s.handleHideKey,onReveal:r=>void s.handleRevealKey(r),onStatusFilterChange:s.setStatusFilter,onToggleEnabled:(r,x)=>void s.handleToggleEnabled(r,x),revealedKeys:s.revealedKeys,search:s.search,statusFilter:s.statusFilter,viewMode:s.viewMode,onViewModeChange:s.setViewMode,onCreateKey:()=>s.handleCreateDialogChange(!0)})}),e.jsx(we,{value:"analytics",className:"mt-4",children:e.jsx(Os,{activeKeysValue:s.activeKeysValue,enabledKeysValue:s.enabledKeysValue,loading:s.usageQuery.isLoading,onRangeChange:s.setRangeDays,rangeDays:s.rangeDays,requestsChartOption:s.requestsChartOption,totalKeysValue:s.totalKeysValue,tokensChartOption:s.tokensChartOption,usageLength:s.usage.length})})]}),e.jsx(Ws,{availableEndpoints:s.availableEndpoints,isOpen:s.isCreateDialogOpen,keyDescription:s.newKeyDescription,keyName:s.newKeyName,maxConcurrency:s.newKeyMaxConcurrency,onDescriptionChange:s.setNewKeyDescription,onEndpointsChange:s.setNewKeyEndpoints,onKeyNameChange:s.setNewKeyName,onMaxConcurrencyChange:s.setNewKeyMaxConcurrency,onOpenChange:s.handleCreateDialogChange,onSubmit:()=>void s.handleCreateKey(),selectedEndpoints:s.newKeyEndpoints}),e.jsx(zs,{createdKey:s.newlyCreatedKey,onClose:()=>s.setNewlyCreatedKey(null),onCopy:r=>void s.handleCopyKey(r)}),e.jsx(qs,{apiKey:s.editEndpointsKey,availableEndpoints:s.availableEndpoints,maxConcurrency:s.editMaxConcurrency,onClose:()=>s.setEditEndpointsKey(null),onEndpointsChange:s.setEditEndpointsSelection,onMaxConcurrencyChange:s.setEditMaxConcurrency,onSave:()=>void s.handleSaveEndpoints(),selectedEndpoints:s.editEndpointsSelection}),e.jsx(Fs,{deleteTarget:s.deleteTarget,isDeleting:s.isDeleting,onConfirm:()=>void s.handleDeleteKey(),onOpenChange:r=>{!r&&s.isDeleting===null&&s.setDeleteTarget(null)}})]})}export{xa as default};
@@ -1 +1 @@
1
- import{j as s}from"./vendor-D2wC0h2o.js";import{D as m,A as p,a as j,b as u,c as D,d as f,e as g}from"./DialogShell-BbpG8sot.js";import{B as o}from"./app-BnQl39hq.js";function C({open:r,onOpenChange:a,title:t,description:i,confirmLabel:n,cancelLabel:d,onConfirm:c,loading:e=!1,confirmVariant:x="destructive",children:l}){return s.jsx(m,{open:r,onOpenChange:a,children:s.jsxs(p,{className:"max-w-md",children:[s.jsxs(j,{children:[s.jsx(u,{children:t}),i?s.jsx(D,{children:i}):null]}),s.jsx(f,{className:"space-y-4",children:l?s.jsx("div",{className:"text-sm text-muted-foreground",children:l}):null}),s.jsxs(g,{children:[s.jsx(o,{variant:"outline",onClick:()=>a(!1),disabled:e,children:d}),s.jsx(o,{variant:x,onClick:()=>void c(),disabled:e,children:n})]})]})})}export{C};
1
+ import{j as s}from"./vendor-C-lQMZp3.js";import{D as m,A as p,a as j,b as u,c as D,d as f,e as g}from"./DialogShell-D1T4HXtd.js";import{B as o}from"./app-DZpd2fu9.js";function C({open:r,onOpenChange:a,title:t,description:i,confirmLabel:n,cancelLabel:d,onConfirm:c,loading:e=!1,confirmVariant:x="destructive",children:l}){return s.jsx(m,{open:r,onOpenChange:a,children:s.jsxs(p,{className:"max-w-md",children:[s.jsxs(j,{children:[s.jsx(u,{children:t}),i?s.jsx(D,{children:i}):null]}),s.jsx(f,{className:"space-y-4",children:l?s.jsx("div",{className:"text-sm text-muted-foreground",children:l}):null}),s.jsxs(g,{children:[s.jsx(o,{variant:"outline",onClick:()=>a(!1),disabled:e,children:d}),s.jsx(o,{variant:x,onClick:()=>void c(),disabled:e,children:n})]})]})})}export{C};
@@ -0,0 +1 @@
1
+ import{r as N,j as e,aB as Ue,aC as ye,Y as Ne,U as $,aD as We,ar as Ge,aE as Qe}from"./vendor-C-lQMZp3.js";import{P as Ye}from"./PageToolbar-GyUQBhmq.js";import{P as H,a as A}from"./PageState-Bbhr4fy6.js";import{u as Je,a as G,b as K,q as P,s as Q,C as Se,c as Te,B as q}from"./app-DZpd2fu9.js";import{D as Le,S as Xe,a as Ze,b as es,c as ss,d as _}from"./disclosure-W_XtxMJz.js";import{c as ts}from"./global-BCYo_xAt.js";import{L as I}from"./router-Bkbjq53m.js";import{u as as,M as v,T as ee,a as se,b as O,c as p,d as te,e as b,E as Ce}from"./chartTheme-ChTod603.js";import{P as U}from"./PageSection-Dd2-9G6C.js";import{S as ns,C as rs,T as os,f as X,g as be}from"./currency-DffG4uWM.js";import{B as R}from"./badge-CWbm9P64.js";import{S as Re}from"./segmented-control-Cxe6ZLHe.js";import{u as is}from"./useEventStream-CvopQT4p.js";import{a as ge}from"./apiKeys-B5Os17Qm.js";import{g as ls}from"./gateway-DxaHzVOF.js";import{T as fe,L as ds,f as cs,a as F,b as je,c as ve}from"./types-BT3gK5lJ.js";import{u as g}from"./i18n-ClvfZhYc.js";import{e as we}from"./charts-core-BuoE1ECx.js";import"./query-1Ng1fzmE.js";import"./radix-DONH6gHT.js";import"./charts-react-BLOapElb.js";import"./charts-engine-DHIzBJl6.js";const us={dimensionRequest(a,t,s,n){return{url:`/api/stats/${a}`,method:"GET",params:{days:t,limit:s,...n?{endpoint:n}:{}}}}},ms=4,z=7,Y=10;function hs(a){var s;if(!a)return 0;let t=Object.keys(a.modelRoutes??{}).length;for(const n of Object.values(a.endpointRouting??{}))t+=Object.keys((n==null?void 0:n.modelRoutes)??{}).length;for(const n of a.customEndpoints??[])t+=Object.keys(((s=n.routing)==null?void 0:s.modelRoutes)??{}).length;return t}function xs(){var le,de,ce,ue,me,he,xe,pe;const{t:a}=g(),{pushToast:t}=Je(),s=as(),[n,r]=G(Q.dashboard.endpointFilter,"all"),i=n==="all"?void 0:n,d=K(P.dashboard.summary(n),{url:"/api/dashboard/summary",method:"GET",params:i?{endpoint:i}:void 0},{refetchInterval:ds}),h=K(P.customEndpoints.all(),{url:"/api/custom-endpoints",method:"GET"},{refetchInterval:fe}),[o,x]=G(Q.dashboard.usageDimension,"providers"),S=K(o==="apiKeys"?P.apiKeys.usage(z,n):P.stats.usageDimension(o,z,Y,n),o==="apiKeys"?ge.usageRequest(z,Y,i):us.dimensionRequest(o,z,Y,i),{refetchInterval:fe}),E=N.useMemo(()=>{const u=S.data??[];return o!=="apiKeys"?u:u.map(m=>({key:m.apiKeyName??(m.apiKeyId!=null?`#${m.apiKeyId}`:"—"),requests:m.requests,inputTokens:m.inputTokens,outputTokens:m.outputTokens,cacheReadTokens:m.cacheReadTokens??0,cacheCreationTokens:m.cacheCreationTokens??0,avgLatencyMs:m.avgLatencyMs??0,cost:m.cost??null,unpricedRequests:m.unpricedRequests??0}))},[S.data,o]),T=is({level:"warn,error",maxEvents:20}),l=N.useRef(!1);N.useEffect(()=>{var m;const u=d.error!=null;u&&!l.current&&(l.current=!0,t({title:a("dashboard.toast.overviewError"),description:((m=d.error)==null?void 0:m.message)??"",variant:"error"})),u||(l.current=!1)},[d.error,t,a]);const w=N.useCallback(async()=>{await Promise.all([d.refetch(),h.refetch(),S.refetch()])},[d,h,S]),c=d.data,k=c==null?void 0:c.overview,L=N.useMemo(()=>(c==null?void 0:c.daily)??[],[c]),j=N.useMemo(()=>(c==null?void 0:c.modelStats)??[],[c]),D=c==null?void 0:c.status,C=c==null?void 0:c.recentThroughput,M=N.useMemo(()=>(c==null?void 0:c.clientActivity)??[],[c]),Me=c==null?void 0:c.dbInfo,ae=(c==null?void 0:c.recentRequests.items)??[],B=((D==null?void 0:D.providers)??0)>0,ne=ae.length>0,re=K(P.config.full(),ls.configRequest(),{enabled:B}),W=N.useMemo(()=>hs(re.data),[re.data])>0,oe=(((le=K(P.apiKeys.all(),ge.listRequest(),{enabled:B&&W}).data)==null?void 0:le.length)??0)>0,Ie=B&&W&&oe&&ne,ke=[B,W,oe,ne].filter(Boolean).length,qe=N.useMemo(()=>{const u=(c==null?void 0:c.recentErrors)??[],m=new Set;return[...T.events,...u].filter(y=>!(m.has(y.id)||(m.add(y.id),i&&y.endpoint!==i))).slice(0,10)},[T.events,c,i]),Ae=n==="all"?a("dashboard.filters.endpointAll"):n==="anthropic"?a("dashboard.filters.endpointAnthropic"):n==="openai"?a("dashboard.filters.endpointOpenAI"):((ue=(ce=(de=h.data)==null?void 0:de.endpoints)==null?void 0:ce.find(u=>u.id===n))==null?void 0:ue.label)||n,Ee=j.filter(u=>u.avgTtftMs!=null&&u.avgTtftMs>0).sort((u,m)=>(u.avgTtftMs??Number.POSITIVE_INFINITY)-(m.avgTtftMs??Number.POSITIVE_INFINITY))[0],De=d.isFetching||h.isFetching,Pe=d.isPending,Oe=d.data?null:((me=d.error)==null?void 0:me.message)??null,Ke=d.data?((he=d.error)==null?void 0:he.message)??null:null,[ie,ze]=G(Q.dashboard.trendMode,"traffic"),Fe=N.useMemo(()=>{const u=a("dashboard.charts.barRequests"),m=a("dashboard.charts.latencyLabel");return{...s.base,color:s.palette,tooltip:{trigger:"axis",...s.base.tooltip},legend:{data:[u,m],...s.base.legend},grid:s.base.grid,xAxis:{type:"category",data:L.map(f=>f.date.slice(5)),axisLabel:{color:s.axis},axisLine:{lineStyle:{color:s.splitLine}}},yAxis:[{type:"value",name:u,nameTextStyle:{color:s.axis},axisLabel:{color:s.axis},splitLine:{lineStyle:{color:s.splitLine}}},{type:"value",name:m,nameTextStyle:{color:s.axis},axisLabel:{color:s.axis},splitLine:{show:!1}}],series:[{name:u,type:"bar",data:L.map(f=>f.requestCount),itemStyle:{color:s.palette[0],borderRadius:[4,4,0,0]},barMaxWidth:24},{name:m,type:"line",yAxisIndex:1,smooth:!0,showSymbol:!1,data:L.map(f=>Math.round(f.avgLatencyMs)),itemStyle:{color:s.palette[3]},lineStyle:{width:2}}]}},[L,s,a]),Be=N.useMemo(()=>{const u=a("dashboard.charts.barRequests"),m=a("dashboard.charts.costLabel");return{...s.base,color:s.palette,tooltip:{trigger:"axis",...s.base.tooltip},legend:{data:[u,m],...s.base.legend},grid:s.base.grid,xAxis:{type:"category",data:L.map(f=>f.date.slice(5)),axisLabel:{color:s.axis},axisLine:{lineStyle:{color:s.splitLine}}},yAxis:[{type:"value",name:u,nameTextStyle:{color:s.axis},axisLabel:{color:s.axis},splitLine:{lineStyle:{color:s.splitLine}}},{type:"value",name:m,nameTextStyle:{color:s.axis},axisLabel:{color:s.axis},splitLine:{show:!1}}],series:[{name:u,type:"bar",data:L.map(f=>f.requestCount),itemStyle:{color:s.palette[0],opacity:.35,borderRadius:[4,4,0,0]},barMaxWidth:24},{name:m,type:"line",yAxisIndex:1,smooth:!0,showSymbol:!1,data:L.map(f=>f.cost),itemStyle:{color:s.palette[1]},lineStyle:{width:2}}]}},[L,s,a]),Ve=ie==="cost"?Be:Fe,V=N.useCallback((u,m,f)=>({...s.base,tooltip:{trigger:"axis",...s.base.tooltip},grid:{...s.base.grid,bottom:24},xAxis:{type:"category",data:j.map(y=>`${y.provider}/${y.model}`),axisLabel:{color:s.axis,rotate:28},axisLine:{lineStyle:{color:s.splitLine}}},yAxis:{type:"value",name:u,nameTextStyle:{color:s.axis},axisLabel:{color:s.axis},splitLine:{lineStyle:{color:s.splitLine}}},series:[{name:u,type:"bar",data:j.map(m),itemStyle:{color:f,borderRadius:[4,4,0,0]},barMaxWidth:32}]}),[j,s]),_e=N.useMemo(()=>V(a("dashboard.charts.ttftAxis"),u=>u.avgTtftMs??0,s.palette[2]),[V,s,a]),$e=N.useMemo(()=>V(a("dashboard.charts.tpotAxis"),u=>u.avgTpotMs??0,s.palette[4]),[V,s,a]),He=N.useMemo(()=>{const u=a("dashboard.charts.barRequests"),m=a("dashboard.charts.lineInput"),f=a("dashboard.charts.lineOutput");return{...s.base,color:s.palette,tooltip:{trigger:"axis",...s.base.tooltip},legend:{data:[u,m,f],...s.base.legend},grid:{...s.base.grid,bottom:24},xAxis:{type:"category",data:j.map(y=>`${y.provider}/${y.model}`),axisLabel:{color:s.axis,rotate:28},axisLine:{lineStyle:{color:s.splitLine}}},yAxis:[{type:"value",name:u,nameTextStyle:{color:s.axis},axisLabel:{color:s.axis},splitLine:{lineStyle:{color:s.splitLine}}},{type:"value",name:a("dashboard.charts.axisTokens"),position:"right",nameTextStyle:{color:s.axis},axisLabel:{color:s.axis},splitLine:{show:!1}}],series:[{name:u,type:"bar",data:j.map(y=>y.requests),itemStyle:{color:s.palette[0],borderRadius:[4,4,0,0]},barMaxWidth:24},{name:m,type:"line",yAxisIndex:1,smooth:!0,showSymbol:!1,data:j.map(y=>y.inputTokens??0),itemStyle:{color:s.palette[1]},lineStyle:{width:2}},{name:f,type:"line",yAxisIndex:1,smooth:!0,showSymbol:!1,data:j.map(y=>y.outputTokens??0),itemStyle:{color:s.palette[2]},lineStyle:{width:2}}]}},[j,s,a]);return{attentionEvents:qe,customEndpoints:((xe=h.data)==null?void 0:xe.endpoints)??[],daily:L,dbInfo:Me,clientActivity:M,endpointFilter:n,fastestTtftModel:Ee,handleRefresh:w,bootstrapError:Oe,refreshError:Ke,isBootstrapping:Pe,isRefreshing:De,liveConnected:T.connected,liveFailed:T.failed,modelRequestsOption:He,models:j,overview:k,recentLogs:ae,recentThroughput:C,selectedEndpointLabel:Ae,setEndpointFilter:r,setupComplete:Ie,setupDoneCount:ke,status:D,summaryPending:d.isPending,trendMode:ie,setTrendMode:ze,trendOption:Ve,ttftOption:_e,tpotOption:$e,usageDimension:o,usageDimensionLoading:S.isPending,usageDimensionError:((pe=S.error)==null?void 0:pe.message)??null,refetchUsageDimension:()=>void S.refetch(),usageRows:E,setUsageDimension:x}}function ps(){return e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx("div",{className:"grid gap-3 sm:grid-cols-2 xl:grid-cols-6",children:Array.from({length:6}).map((a,t)=>e.jsx(ns,{},t))}),e.jsx(rs,{}),e.jsx("div",{className:"border border-border bg-card",children:e.jsx("table",{className:"w-full",children:e.jsx("tbody",{children:Array.from({length:5}).map((a,t)=>e.jsx(os,{columns:6},t))})})})]})}function bs({status:a,recentThroughput:t}){const{t:s}=g();return e.jsxs("div",{className:"space-y-3","data-testid":"dashboard-spotlight-grid",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1 text-sm","data-testid":"dashboard-overview-panel",children:[e.jsx("span",{className:"inline-flex items-center gap-1.5 rounded-md bg-success-bg px-1.5 py-0.5 text-[11px] font-medium text-success before:h-1.5 before:w-1.5 before:rounded-full before:bg-success before:animate-live-pulse",children:s("dashboard.status.listeningLabel")}),e.jsx("span",{"data-testid":"dashboard-runtime-address",className:"metric-number text-sm font-semibold tracking-tight text-foreground",children:e.jsxs("span",{"data-visual-volatile":"true",children:[(a==null?void 0:a.host)??"0.0.0.0",":",(a==null?void 0:a.port)??"-"]})}),e.jsx("span",{className:"text-xs text-muted-foreground",children:s("dashboard.status.providers",{value:(a==null?void 0:a.providers)??0})})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2 xl:grid-cols-6",children:[e.jsx(v,{size:"md",label:s("dashboard.labels.activeRequests"),value:((a==null?void 0:a.activeRequests)??0).toLocaleString(),rawValue:(a==null?void 0:a.activeRequests)??0,valueTestId:"dashboard-spotlight-value-active"}),e.jsx(v,{size:"md",label:s("dashboard.labels.requestsPerMinute"),value:((a==null?void 0:a.requestsPerMinute)??0).toLocaleString(),rawValue:(a==null?void 0:a.requestsPerMinute)??0,valueTestId:"dashboard-spotlight-value-rpm"}),e.jsx(v,{size:"md",label:s("dashboard.labels.inputTpm10m",{value:(t==null?void 0:t.windowMinutes)??10}),value:((t==null?void 0:t.inputTokensPerMinute)??0).toLocaleString(),rawValue:(t==null?void 0:t.inputTokensPerMinute)??0,valueTestId:"dashboard-spotlight-value-tpm-in"}),e.jsx(v,{size:"md",label:s("dashboard.labels.outputTpm10m",{value:(t==null?void 0:t.windowMinutes)??10}),value:((t==null?void 0:t.outputTokensPerMinute)??0).toLocaleString(),rawValue:(t==null?void 0:t.outputTokensPerMinute)??0,valueTestId:"dashboard-spotlight-value-tpm-out"}),e.jsx(v,{size:"md",label:s("dashboard.labels.uniqueClientAddressesLastHour"),value:((a==null?void 0:a.uniqueClientAddressesLastHour)??0).toLocaleString(),rawValue:(a==null?void 0:a.uniqueClientAddressesLastHour)??0}),e.jsx(v,{size:"md",label:s("dashboard.labels.cpu"),value:e.jsx("span",{"data-visual-volatile":"true",children:cs(a==null?void 0:a.cpuUsagePercent)}),valueTestId:"dashboard-spotlight-value-cpu"})]})]})}function gs(a){switch(a){case"error":return e.jsx(R,{variant:"destructive",children:"error"});case"warn":return e.jsx(R,{variant:"warning",children:"warn"});default:return e.jsx(R,{variant:"secondary",children:"info"})}}function Z(a,t){const s=new URLSearchParams;a&&a!=="all"&&s.set("endpoint",a),t&&s.set("status",t);const n=s.toString();return n?`/logs?${n}`:"/logs"}function fs({overview:a,endpointFilter:t}){const{t:s}=g(),n=a==null?void 0:a.today,r=a==null?void 0:a.yesterday,i=(n==null?void 0:n.requests)??0,d=(n==null?void 0:n.inputTokens)??0,h=(n==null?void 0:n.outputTokens)??0,o=(n==null?void 0:n.cacheReadTokens)??0,x=(n==null?void 0:n.errorCount)??0,S=a==null?void 0:a.costCurrency,E=(n==null?void 0:n.unpricedRequests)??0,T=i>0?x/i*100:0,l=r&&(r.requests??0)>0?r.errorCount/r.requests*100:void 0,w=o+d,c=w>0?o/w*100:0,k=(C,M)=>M!==void 0&&M>0?((C??0)-M)/M*100:void 0,L=C=>`${C>0?"+":""}${C.toFixed(1)}%`,j=(C,M=!1)=>C!==void 0&&Math.abs(C)>=.05?{value:C,invertColor:M,format:L}:void 0,D=i>0?k(T,l):void 0;return e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2 xl:grid-cols-6","data-testid":"dashboard-today-grid",children:[e.jsx(v,{size:"md",label:s("dashboard.cards.todayRequests"),value:i.toLocaleString(),rawValue:i,delta:j(k(i,r==null?void 0:r.requests)),hint:r&&r.requests>0?s("dashboard.cards.yesterdayHint",{value:r.requests.toLocaleString()}):void 0,valueTestId:"dashboard-today-value-requests"}),e.jsx(v,{size:"md",label:s("dashboard.cards.todayInput"),value:d.toLocaleString(),rawValue:d,suffix:s("common.units.token"),delta:j(k(d,r==null?void 0:r.inputTokens)),valueTestId:"dashboard-today-value-input"}),e.jsx(v,{size:"md",label:s("dashboard.cards.todayOutput"),value:h.toLocaleString(),rawValue:h,suffix:s("common.units.token"),delta:j(k(h,r==null?void 0:r.outputTokens)),valueTestId:"dashboard-today-value-output"}),e.jsx(v,{size:"md",label:s("dashboard.cards.todayCacheRead"),value:o.toLocaleString(),rawValue:o,suffix:s("common.units.token"),hint:w>0?s("dashboard.cards.cacheHitHint",{value:c.toFixed(1)}):void 0,valueTestId:"dashboard-today-value-cache-read"}),e.jsx(v,{size:"md",label:s("dashboard.cards.todayCost"),value:X(n==null?void 0:n.cost,S),delta:j(k((n==null?void 0:n.cost)??void 0,(r==null?void 0:r.cost)??void 0)),hint:E>0?s("dashboard.cards.unpricedHint",{count:E}):void 0,valueTestId:"dashboard-today-value-cost"}),e.jsx(v,{size:"md",label:s("dashboard.cards.todayErrorRate"),value:T>0?e.jsxs("span",{className:"text-destructive",children:[T.toFixed(1),"%"]}):`${T.toFixed(1)}%`,delta:j(D,!0),hint:x>0?e.jsxs("span",{className:"inline-flex flex-wrap items-center gap-1",children:[s("dashboard.cards.errorCountHint",{value:x}),e.jsx(I,{to:Z(t,"error"),className:"font-medium text-foreground underline decoration-muted-foreground/40 underline-offset-2 hover:decoration-foreground",children:s("dashboard.cards.viewErrors")})]}):void 0,valueTestId:"dashboard-today-value-error-rate"})]})}function js({status:a,entries:t}){const{t:s}=g();if(t.length===0)return null;const n=r=>r==="unknown"?s("dashboard.usage.clientKinds.unknown"):s(`dashboard.usage.clientKinds.${r}`,{defaultValue:r});return e.jsx("div",{"data-testid":"dashboard-client-activity",className:"grid gap-3 sm:grid-cols-2 xl:grid-cols-4",children:t.map(r=>{var d;const i=((d=a==null?void 0:a.activeByClientKind)==null?void 0:d[r.clientKind])??0;return e.jsxs("div",{"data-testid":"dashboard-client-activity-card",className:"rounded-lg border border-border bg-card px-4 py-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"truncate text-sm font-semibold text-foreground",children:n(r.clientKind)}),e.jsx("div",{className:"font-mono text-[10.5px] text-muted-foreground",children:r.clientKind})]}),e.jsx("span",{className:i>0?"inline-flex shrink-0 items-center gap-1 rounded-md bg-success-bg px-1.5 py-0.5 text-[11px] font-medium text-success before:h-1.5 before:w-1.5 before:rounded-full before:bg-success before:animate-live-pulse":"shrink-0 rounded-md bg-secondary px-1.5 py-0.5 text-[11px] font-medium text-muted-foreground",children:s("dashboard.clientActivity.active",{value:i})})]}),e.jsxs("dl",{className:"mt-2.5 grid grid-cols-2 gap-x-3 gap-y-1 text-[11px] tabular-nums text-muted-foreground",children:[e.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[e.jsx("dt",{children:s("dashboard.clientActivity.requests")}),e.jsx("dd",{className:"font-medium text-foreground",children:r.requests.toLocaleString()})]}),e.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[e.jsx("dt",{children:s("dashboard.clientActivity.sessions")}),e.jsx("dd",{className:"font-medium text-foreground",children:r.sessions.toLocaleString()})]}),e.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[e.jsx("dt",{children:s("dashboard.clientActivity.input")}),e.jsx("dd",{children:r.inputTokens.toLocaleString()})]}),e.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[e.jsx("dt",{children:s("dashboard.clientActivity.output")}),e.jsx("dd",{children:r.outputTokens.toLocaleString()})]})]})]},r.clientKind)})})}function vs({connected:a,failed:t,events:s}){const{t:n}=g();return s.length===0?null:e.jsx(U,{title:n("dashboard.attention.title"),description:n("dashboard.attention.subtitle"),actions:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:t?"inline-flex items-center gap-1 text-[11px] font-medium text-destructive before:h-1.5 before:w-1.5 before:rounded-full before:bg-destructive":a?"inline-flex items-center gap-1 text-[11px] font-medium text-success before:h-1.5 before:w-1.5 before:rounded-full before:bg-success before:animate-live-pulse":"inline-flex items-center gap-1 text-[11px] font-medium text-warning before:h-1.5 before:w-1.5 before:rounded-full before:bg-warning",children:n(t?"dashboard.attention.failed":a?"dashboard.attention.live":"dashboard.attention.reconnecting")}),e.jsx(q,{asChild:!0,variant:"ghost",size:"sm",className:"h-7",children:e.jsx(I,{to:"/events",children:n("dashboard.attention.viewAll")})})]}),children:e.jsx("ul",{className:"divide-y divide-border",children:e.jsx(Ue,{initial:!1,children:s.map(r=>e.jsxs(ye.li,{initial:{opacity:0,y:-8},animate:{opacity:1,y:0},exit:{opacity:0},transition:{duration:.18},className:"flex items-start gap-3 py-2.5 first:pt-0 last:pb-0",children:[e.jsx("div",{className:"pt-0.5",children:gs(r.level)}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"truncate text-sm font-medium text-foreground",children:r.title??r.type}),r.message?e.jsx("p",{className:"mt-0.5 line-clamp-1 text-xs text-muted-foreground",children:r.message}):null]}),e.jsx("span",{"data-visual-volatile":"true",className:"shrink-0 pt-0.5 text-[11px] tabular-nums text-muted-foreground/70",children:new Date(r.createdAt).toLocaleTimeString()})]},r.id))})})})}function ys({connected:a,failed:t}){const{t:s}=g();return e.jsxs(ye.div,{initial:{opacity:0,y:-4},animate:{opacity:1,y:0},transition:{duration:.18},"data-testid":"dashboard-all-clear",className:"flex h-8 flex-wrap items-center gap-x-2 gap-y-1 bg-success-bg px-3 text-xs text-success",children:[e.jsx(Ge,{className:"h-3.5 w-3.5 shrink-0","aria-hidden":"true"}),e.jsx("span",{className:"font-medium",children:s("dashboard.attention.allClear")}),e.jsx("span",{className:t?"ml-auto inline-flex items-center gap-1.5 text-[11px] font-medium text-destructive before:h-1.5 before:w-1.5 before:rounded-full before:bg-destructive":a?"ml-auto inline-flex items-center gap-1.5 text-[11px] font-medium before:h-1.5 before:w-1.5 before:rounded-full before:bg-success before:animate-live-pulse":"ml-auto inline-flex items-center gap-1.5 text-[11px] font-medium text-warning before:h-1.5 before:w-1.5 before:rounded-full before:bg-warning",children:s(t?"dashboard.attention.failed":a?"dashboard.attention.live":"dashboard.attention.reconnecting")}),e.jsx(I,{to:"/events",className:"shrink-0 underline-offset-2 hover:underline",children:s("dashboard.attention.viewAll")})]})}function Ns({empty:a,loading:t,option:s,mode:n,onModeChange:r}){const{t:i}=g();return e.jsx(ks,{title:i("dashboard.charts.trendTitle"),description:i(n==="cost"?"dashboard.charts.trendCostDesc":"dashboard.charts.trendDesc"),loading:t,option:s,empty:a,emptyText:i("dashboard.charts.empty"),actions:e.jsx(Re,{value:n,onChange:r,"aria-label":i("dashboard.charts.trendModeLabel"),options:[{value:"traffic",label:e.jsx("span",{"data-testid":"dashboard-trend-mode-traffic",children:i("dashboard.charts.trendModeTraffic")})},{value:"cost",label:e.jsx("span",{"data-testid":"dashboard-trend-mode-cost",children:i("dashboard.charts.trendModeCost")})}]})})}function Ss({daily:a,models:t}){const{t:s}=g();if(a.length===0&&t.length===0)return null;const n=a.reduce((o,x)=>o+x.requestCount,0),r=a.length>0?a.reduce((o,x)=>x.requestCount>o.requestCount?x:o,a[0]):null,i=t.length>0?t.reduce((o,x)=>x.requests>o.requests?x:o,t[0]):null,d=t.filter(o=>o.avgTtftMs!=null&&o.avgTtftMs>0).sort((o,x)=>(o.avgTtftMs??Number.POSITIVE_INFINITY)-(x.avgTtftMs??Number.POSITIVE_INFINITY))[0],h=[{label:s("dashboard.insights.totalRequests"),value:n>0?n.toLocaleString():"—",hint:n>0?s("dashboard.insights.totalRequestsHint"):void 0},{label:s("dashboard.insights.busiestDay"),value:r?r.date.slice(5):"—",hint:r?s("dashboard.insights.busiestDayHint",{value:r.requestCount.toLocaleString()}):void 0},{label:s("dashboard.insights.topModel"),value:i?i.model:"—",hint:i?s("dashboard.insights.topModelHint",{value:i.requests.toLocaleString()}):void 0},{label:s("dashboard.insights.fastestTtft"),value:d?d.model:"—",hint:d?s("dashboard.insights.fastestTtftHint",{value:Math.round(d.avgTtftMs??0)}):void 0}];return e.jsx("div",{className:"grid grid-cols-2 gap-3 xl:grid-cols-4","data-testid":"dashboard-insights-grid",children:h.map(o=>e.jsxs("div",{className:"rounded-lg border border-border bg-card px-4 py-3",children:[e.jsx("div",{className:"text-[10.5px] font-semibold uppercase tracking-[0.06em] text-muted-foreground",children:o.label}),e.jsx("div",{className:"metric-number mt-2 truncate text-base font-bold tracking-tight text-foreground",children:o.value}),o.hint?e.jsx("div",{className:"mt-0.5 text-[11px] text-muted-foreground",children:o.hint}):null]},o.label))})}function Ts({dimension:a,onDimensionChange:t,rows:s,loading:n,error:r,onRetry:i,customEndpoints:d,costCurrency:h}){const{t:o}=g(),x=[{value:"providers",label:o("dashboard.usage.tabs.providers")},{value:"endpoints",label:o("dashboard.usage.tabs.endpoints")},{value:"clients",label:o("dashboard.usage.tabs.clients")},{value:"apiKeys",label:o("dashboard.usage.tabs.apiKeys")}],S=l=>{var w;return l==="anthropic"?o("dashboard.filters.endpointAnthropic"):l==="openai"?o("dashboard.filters.endpointOpenAI"):((w=d.find(c=>c.id===l))==null?void 0:w.label)||l},E=l=>l==="unknown"?o("dashboard.usage.clientKinds.unknown"):o(`dashboard.usage.clientKinds.${l}`,{defaultValue:l}),T=l=>{switch(a){case"endpoints":return e.jsx(R,{variant:"outline",className:"text-[11px]",children:S(l.key)});case"clients":return e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"font-medium",children:E(l.key)}),e.jsx("span",{className:"font-mono text-[11px] text-muted-foreground",children:l.key})]});case"apiKeys":return e.jsx("span",{className:"font-medium",children:l.key});default:return e.jsx("span",{className:"font-mono text-[13px] font-medium",children:l.key})}};return e.jsx(U,{title:o("dashboard.usage.title"),description:o("dashboard.usage.description",{value:z}),actions:e.jsx(Re,{value:a,onChange:t,"aria-label":o("dashboard.usage.title"),options:x.map(l=>({value:l.value,label:e.jsx("span",{"data-testid":`dashboard-usage-tab-${l.value}`,children:l.label})}))}),children:n?e.jsx(H,{compact:!0,label:o("common.loadingShort")}):r&&s.length===0?e.jsx(A,{compact:!0,tone:"danger",icon:e.jsx(Ne,{className:"h-5 w-5","aria-hidden":"true"}),title:o("dashboard.usage.error"),description:r,action:i?e.jsx(q,{variant:"outline",size:"sm",onClick:i,children:o("common.actions.retry")}):void 0}):s.length===0?e.jsx(A,{inline:!0,icon:e.jsx($,{className:"h-3.5 w-3.5","aria-hidden":"true"}),title:o("dashboard.usage.empty")}):e.jsx("div",{className:"overflow-auto",children:e.jsxs(ee,{children:[e.jsx(se,{children:e.jsxs(O,{children:[e.jsx(p,{children:o("dashboard.usage.columns.dimension")}),e.jsx(p,{className:"text-right",children:o("dashboard.usage.columns.requests")}),e.jsx(p,{className:"text-right",children:o("dashboard.usage.columns.input")}),e.jsx(p,{className:"text-right",children:o("dashboard.usage.columns.output")}),e.jsx(p,{className:"text-right",children:o("dashboard.usage.columns.cacheRead")}),e.jsx(p,{className:"text-right",children:o("dashboard.usage.columns.cacheCreation")}),e.jsx(p,{className:"text-right",children:o("dashboard.usage.columns.cost")}),e.jsx(p,{className:"text-right",children:o("dashboard.usage.columns.latency")})]})}),e.jsx(te,{children:s.map(l=>e.jsxs(O,{"data-testid":"dashboard-usage-row",children:[e.jsx(b,{children:T(l)}),e.jsx(b,{className:"text-right font-medium",children:l.requests.toLocaleString()}),e.jsx(b,{className:"text-right",children:l.inputTokens.toLocaleString()}),e.jsx(b,{className:"text-right",children:l.outputTokens.toLocaleString()}),e.jsx(b,{className:"text-right",children:l.cacheReadTokens.toLocaleString()}),e.jsx(b,{className:"text-right",children:l.cacheCreationTokens.toLocaleString()}),e.jsx(b,{className:"text-right tabular-nums","data-testid":"dashboard-usage-cost",children:l.unpricedRequests>0?e.jsxs("span",{className:"inline-flex items-baseline gap-0.5",title:o("dashboard.usage.unpricedHint",{count:l.unpricedRequests}),children:[X(l.cost,h),e.jsx("span",{"aria-hidden":"true",children:"*"})]}):X(l.cost,h)}),e.jsx(b,{className:"text-right",children:e.jsx("span",{"data-visual-volatile":"true",children:F(l.avgLatencyMs,o("common.units.ms"))})})]},`${a}:${l.key}`))})]})})})}function Ls({modelRequestsOption:a,models:t,ttftOption:s,tpotOption:n}){const{t:r}=g();return e.jsxs(Le,{variant:"card",summaryClassName:"px-4 py-3",contentClassName:"border-t border-border px-4 py-4",summary:e.jsx("span",{className:"text-sm font-medium text-foreground",children:r("dashboard.sections.performance")}),children:[e.jsxs("div",{className:"grid gap-4 lg:grid-cols-3",children:[e.jsx(J,{title:r("dashboard.charts.modelTitle"),option:a,empty:!t.length}),e.jsx(J,{title:r("dashboard.charts.ttftTitle"),option:s,empty:!t.some(i=>i.avgTtftMs!=null&&i.avgTtftMs>0)}),e.jsx(J,{title:r("dashboard.charts.tpotTitle"),option:n,empty:!t.some(i=>i.avgTpotMs!=null&&i.avgTpotMs>0)})]}),e.jsx("div",{className:"mt-4",children:e.jsx(Ms,{models:t,embedded:!0})})]})}function Cs({dbInfo:a,dbSizeDisplay:t,memoryDisplay:s,status:n}){const{t:r}=g();return e.jsx(Le,{variant:"card",summaryClassName:"px-4 py-3",contentClassName:"border-t border-border px-4 py-4",summary:e.jsx("span",{className:"text-sm font-medium text-foreground",children:r("dashboard.cards.systemResources")}),badge:e.jsxs("span",{"data-visual-volatile":"true",className:"text-xs tabular-nums text-muted-foreground",children:[t," · ",s]}),children:e.jsxs("div",{className:"grid gap-2.5 sm:grid-cols-2 lg:grid-cols-4",children:[e.jsx(v,{size:"sm",label:r("dashboard.labels.networkIngress"),value:je(n==null?void 0:n.networkIngressBytesPerSecond),valueTestId:"dashboard-spotlight-value-ingress"}),e.jsx(v,{size:"sm",label:r("dashboard.labels.networkEgress"),value:je(n==null?void 0:n.networkEgressBytesPerSecond),valueTestId:"dashboard-spotlight-value-egress"}),e.jsx(v,{size:"sm",label:r("dashboard.labels.database"),value:t,valueTestId:"dashboard-spotlight-value-database"}),e.jsx(v,{size:"sm",label:r("dashboard.labels.memory"),value:s,valueTestId:"dashboard-spotlight-value-memory"})]})})}function Rs({doneCount:a,total:t}){const{t:s}=g(),n=Math.min(100,Math.round(a/t*100));return e.jsxs("div",{"data-testid":"dashboard-setup-progress",className:"flex flex-wrap items-center gap-x-3 gap-y-2 bg-secondary/60 px-4 py-2",children:[e.jsx("span",{className:"text-xs font-medium text-foreground",children:s("dashboard.setupProgress.label",{done:a,total:t})}),e.jsx("div",{className:"h-1.5 min-w-24 flex-1 overflow-hidden bg-border/60",children:e.jsx("div",{className:"h-1.5 bg-primary transition-all",style:{width:`${n}%`}})}),e.jsx(I,{to:"/setup",className:"shrink-0 text-xs font-medium text-foreground underline decoration-muted-foreground/40 underline-offset-2 hover:decoration-foreground",children:s("dashboard.setupProgress.cta")})]})}function ws({endpointCount:a,providerCount:t}){const{t:s}=g(),n=[{title:s("dashboard.guide.step1Title"),description:t>0?s("dashboard.guide.step1DescDone",{count:t}):s("dashboard.guide.step1Desc"),href:"/providers",cta:s("dashboard.guide.step1Cta")},{title:s("dashboard.guide.step2Title"),description:a>0?s("dashboard.guide.step2DescDone",{count:a}):s("dashboard.guide.step2Desc"),href:"/routing",cta:s("dashboard.guide.step2Cta")},{title:s("dashboard.guide.step3Title"),description:s("dashboard.guide.step3Desc"),href:"/api-keys",cta:s("dashboard.guide.step3Cta")}];return e.jsx(Se,{className:"relative overflow-hidden",children:e.jsxs(Te,{className:"space-y-5 pt-5",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("h3",{className:"text-base font-semibold text-foreground",children:s("dashboard.guide.title")}),e.jsx("p",{className:"text-sm leading-6 text-muted-foreground",children:s("dashboard.guide.subtitle")})]}),e.jsx(q,{asChild:!0,size:"sm",children:e.jsx(I,{to:"/setup",children:s("dashboard.guide.startWizard")})})]}),e.jsx("ol",{className:"grid gap-3 lg:grid-cols-3",children:n.map((r,i)=>e.jsxs("li",{className:"rounded-lg border border-border p-4",children:[e.jsx("span",{className:"metric-number text-xs font-semibold text-muted-foreground",children:String(i+1).padStart(2,"0")}),e.jsx("h4",{className:"mt-2 text-sm font-semibold text-foreground",children:r.title}),e.jsx("p",{className:"mt-1.5 text-xs leading-6 text-muted-foreground",children:r.description}),e.jsx(q,{asChild:!0,variant:"ghost",size:"sm",className:"mt-2 h-8 px-0 text-foreground underline decoration-muted-foreground/40 underline-offset-2 hover:bg-transparent hover:decoration-foreground",children:e.jsx(I,{to:r.href,children:r.cta})})]},r.title))})]})})}function Ms({models:a,loading:t,embedded:s}){const{t:n}=g(),r=t?e.jsx(H,{compact:!0,label:n("common.loadingShort")}):a.length===0?e.jsx(A,{inline:!0,icon:e.jsx($,{className:"h-3.5 w-3.5","aria-hidden":"true"}),title:n("dashboard.modelTable.empty")}):e.jsx("div",{className:"overflow-auto",children:e.jsxs(ee,{children:[e.jsx(se,{children:e.jsxs(O,{children:[e.jsx(p,{children:n("dashboard.modelTable.columns.model")}),e.jsx(p,{className:"text-right",children:n("dashboard.modelTable.columns.requests")}),e.jsx(p,{className:"text-right",children:n("dashboard.modelTable.columns.latency")}),e.jsx(p,{className:"text-right",children:n("dashboard.modelTable.columns.ttft")}),e.jsx(p,{className:"text-right",children:n("dashboard.modelTable.columns.tpot")})]})}),e.jsx(te,{children:a.map(i=>e.jsxs(O,{children:[e.jsx(b,{children:e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"font-medium",children:i.provider}),e.jsx("span",{className:"text-xs text-muted-foreground",children:i.model})]})}),e.jsx(b,{className:"text-right font-medium",children:i.requests.toLocaleString()}),e.jsx(b,{className:"text-right",children:e.jsx("span",{"data-visual-volatile":"true",children:F(i.avgLatencyMs,n("common.units.ms"))})}),e.jsx(b,{className:"text-right",children:e.jsx("span",{"data-visual-volatile":"true",children:F(i.avgTtftMs,n("common.units.ms"))})}),e.jsx(b,{className:"text-right",children:e.jsx("span",{"data-visual-volatile":"true",children:F(i.avgTpotMs,n("common.units.msPerToken"),{maximumFractionDigits:2})})})]},`${i.provider}/${i.model}`))})]})});return s?r:e.jsx(U,{title:n("dashboard.modelTable.title"),description:n("dashboard.modelTable.description"),children:r})}function Is({records:a,loading:t,endpointFilter:s}){const{t:n}=g(),r=a.map(o=>be(o,n)),i=r.filter(o=>o.tone==="success").length,d=r.filter(o=>o.tone==="error").length,h=r.filter(o=>o.tone==="pending").length;return e.jsx(U,{title:n("dashboard.recent.title"),description:n("dashboard.recent.subtitle",{count:5}),actions:a.length>0?e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(R,{variant:"secondary",children:a.length}),e.jsxs(R,{variant:"success",children:[n("common.status.success"),": ",i]}),e.jsxs(R,{variant:"outline",className:"border-destructive/30 bg-destructive/10 text-destructive",children:[n("common.status.error"),": ",d]}),h>0?e.jsxs(R,{variant:"warning",children:[n("common.status.pending"),": ",h]}):null,e.jsx(I,{to:Z(s),className:"ml-1 text-xs font-medium text-foreground underline decoration-muted-foreground/40 underline-offset-2 hover:decoration-foreground",children:n("dashboard.recent.viewAll")})]}):e.jsx(I,{to:Z(s),className:"text-xs font-medium text-foreground underline decoration-muted-foreground/40 underline-offset-2 hover:decoration-foreground",children:n("dashboard.recent.viewAll")}),children:t?e.jsx(H,{compact:!0,label:n("dashboard.recent.loading")}):a.length===0?e.jsx(A,{inline:!0,icon:e.jsx(We,{className:"h-3.5 w-3.5","aria-hidden":"true"}),title:n("dashboard.recent.empty")}):e.jsx("div",{className:"overflow-auto",children:e.jsxs(ee,{children:[e.jsx(se,{children:e.jsxs(O,{children:[e.jsx(p,{children:n("dashboard.recent.columns.time")}),e.jsx(p,{children:n("dashboard.recent.columns.endpoint")}),e.jsx(p,{children:n("dashboard.recent.columns.provider")}),e.jsx(p,{children:n("dashboard.recent.columns.route")}),e.jsx(p,{className:"text-right",children:n("dashboard.recent.columns.latency")}),e.jsx(p,{children:n("dashboard.recent.columns.status")})]})}),e.jsx(te,{children:a.map(o=>{const x=be(o,n);return e.jsxs(O,{children:[e.jsx(b,{children:e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{"data-visual-volatile":"true",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(R,{variant:"outline",className:"text-[11px]",children:o.endpoint==="anthropic"?n("logs.endpointAnthropic"):o.endpoint==="openai"?n("logs.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??n("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:e.jsx("span",{"data-visual-volatile":"true",children:F(o.latency_ms,n("common.units.ms"))})}),e.jsx(b,{children:e.jsx(R,{variant:x.variant,className:"min-w-14 justify-center",children:x.label})})]},o.id)})})]})})})}function J({empty:a,option:t,title:s}){const{t:n}=g();return e.jsxs("div",{className:"rounded-lg border border-border p-3",children:[e.jsx("p",{className:"mb-2 text-xs font-medium text-muted-foreground",children:s}),a?e.jsx(A,{inline:!0,icon:e.jsx($,{className:"h-3.5 w-3.5","aria-hidden":"true"}),title:n("dashboard.charts.empty")}):e.jsx(Ce,{echarts:we,option:t,className:"h-[220px]",notMerge:!0,lazyUpdate:!0})]})}function ks({description:a,empty:t,emptyText:s,loading:n,option:r,title:i,actions:d}){const{t:h}=g();return e.jsx(Se,{children:e.jsxs(Te,{className:"space-y-4 pt-5",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm font-semibold",children:i}),e.jsx("p",{className:"mt-0.5 text-xs text-muted-foreground/70",children:a})]}),d]}),n?e.jsx(H,{compact:!0,className:"min-h-[220px]",label:h("common.loadingShort")}):t?e.jsx(A,{inline:!0,icon:e.jsx($,{className:"h-3.5 w-3.5","aria-hidden":"true"}),title:s??h("dashboard.charts.empty")}):e.jsx("div",{className:"pt-2",children:e.jsx(Ce,{echarts:we,option:r,className:"h-[36vh] min-h-[260px] max-h-[400px]",notMerge:!0,lazyUpdate:!0})})]})})}function tt(){var r,i,d;const{t:a}=g(),t=xs(),s=t.dbInfo?ve(t.dbInfo.totalBytes??t.dbInfo.sizeBytes):"-",n=ve((r=t.dbInfo)==null?void 0:r.memoryRssBytes);return e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx(Ye,{actions:e.jsxs(e.Fragment,{children:[e.jsxs(Xe,{value:t.endpointFilter,onValueChange:t.setEndpointFilter,children:[e.jsx(Ze,{className:"h-8 w-[168px]",children:e.jsx(es,{})}),e.jsxs(ss,{children:[e.jsx(_,{value:"all",children:a("dashboard.filters.endpointAll")}),e.jsx(_,{value:"anthropic",children:a("dashboard.filters.endpointAnthropic")}),e.jsx(_,{value:"openai",children:a("dashboard.filters.endpointOpenAI")}),t.customEndpoints.map(h=>e.jsx(_,{value:h.id,children:h.label||h.id},h.id))]})]}),e.jsxs(q,{variant:"outline",size:"sm",onClick:()=>void t.handleRefresh(),disabled:t.isRefreshing,children:[e.jsx(Qe,{className:ts("mr-2 h-4 w-4",t.isRefreshing&&"animate-spin"),"aria-hidden":"true"}),t.isRefreshing?a("common.actions.refreshing"):a("common.actions.refresh")]})]})}),t.isBootstrapping?e.jsx(ps,{}):t.bootstrapError?e.jsx(A,{icon:e.jsx(Ne,{className:"h-5 w-5","aria-hidden":"true"}),tone:"danger",title:a("common.status.error"),description:t.bootstrapError,action:e.jsx(q,{variant:"outline",onClick:()=>void t.handleRefresh(),children:a("common.actions.refresh")})}):e.jsxs(e.Fragment,{children:[t.refreshError?e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 border border-warning/30 bg-warning-bg px-3 py-2 text-xs text-warning",children:[e.jsx("span",{children:a("dashboard.refreshFailed",{message:t.refreshError})}),e.jsx(q,{variant:"outline",size:"sm",onClick:()=>void t.handleRefresh(),disabled:t.isRefreshing,children:a("common.actions.refresh")})]}):null,t.setupComplete?null:e.jsx(ws,{endpointCount:t.customEndpoints.length,providerCount:((i=t.status)==null?void 0:i.providers)??0}),e.jsx(bs,{status:t.status,recentThroughput:t.recentThroughput}),t.attentionEvents.length>0?e.jsx(vs,{connected:t.liveConnected,failed:t.liveFailed,events:t.attentionEvents}):null,e.jsx(fs,{overview:t.overview,endpointFilter:t.endpointFilter}),e.jsx(js,{status:t.status,entries:t.clientActivity}),t.setupComplete?null:e.jsx(Rs,{doneCount:t.setupDoneCount,total:ms}),e.jsx(Ns,{empty:!t.daily.length,loading:t.summaryPending,option:t.trendOption,mode:t.trendMode,onModeChange:t.setTrendMode}),e.jsx(Ss,{daily:t.daily,models:t.models}),e.jsx(Ts,{dimension:t.usageDimension,onDimensionChange:t.setUsageDimension,rows:t.usageRows,loading:t.usageDimensionLoading,error:t.usageDimensionError,onRetry:t.refetchUsageDimension,customEndpoints:t.customEndpoints,costCurrency:(d=t.overview)==null?void 0:d.costCurrency}),e.jsx(Ls,{modelRequestsOption:t.modelRequestsOption,models:t.models,ttftOption:t.ttftOption,tpotOption:t.tpotOption}),e.jsx(Cs,{dbInfo:t.dbInfo,dbSizeDisplay:s,memoryDisplay:n,status:t.status}),e.jsx(Is,{records:t.recentLogs,loading:t.summaryPending,endpointFilter:t.endpointFilter}),t.attentionEvents.length>0?null:e.jsx(ys,{connected:t.liveConnected,failed:t.liveFailed})]})]})}export{tt as default};
@@ -0,0 +1 @@
1
+ import{r,j as s,aG as u}from"./vendor-C-lQMZp3.js";import{m as g,p as n,D as l,n as y,o as d,y as N,O as i}from"./radix-DONH6gHT.js";import{c as o}from"./global-BCYo_xAt.js";const k=g,b=y,c=r.forwardRef(({className:a,...e},t)=>s.jsx(i,{ref:t,className:o("fixed inset-0 z-50 bg-background/95 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,...t},x)=>s.jsxs(b,{children:[s.jsx(c,{}),s.jsxs(d,{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-xl border border-border bg-background/[var(--surface-alpha)] surface-blur p-6 shadow-[var(--surface-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),...t,children:[e,s.jsxs(N,{className:"absolute right-4 top-4 rounded-md p-1.5 text-muted-foreground opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none",children:[s.jsx(u,{className:"h-4 w-4"}),s.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));p.displayName=d.displayName;const f=({className:a,...e})=>s.jsx("div",{className:o("flex shrink-0 flex-col space-y-1.5 text-center sm:text-left",a),...e});f.displayName="DialogHeader";const m=({className:a,...e})=>s.jsx("div",{className:o("flex shrink-0 flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",a),...e});m.displayName="DialogFooter";const j=r.forwardRef(({className:a,...e},t)=>s.jsx(n,{ref:t,className:o("text-lg font-semibold leading-none tracking-[-0.02em]",a),...e}));j.displayName=n.displayName;const D=r.forwardRef(({className:a,...e},t)=>s.jsx(l,{ref:t,className:o("text-sm leading-6 text-muted-foreground",a),...e}));D.displayName=l.displayName;function R({children:a,className:e,...t}){return s.jsx(p,{className:o("gap-0 overflow-hidden p-0",e),...t,children:a})}function A({children:a,className:e}){return s.jsx("div",{className:o("border-b border-border bg-secondary/40 px-6 py-5",e),children:s.jsx(f,{children:a})})}function C({children:a,className:e}){return s.jsx("div",{className:o("min-h-0 overflow-y-auto px-6 py-5",e),children:a})}function z({children:a,className:e}){return s.jsx(m,{className:o("border-t border-border bg-secondary/40 px-6 py-4",e),children:a})}export{R as A,k as D,A as a,j as b,D as c,C as d,z as e};
@@ -0,0 +1 @@
1
+ import{r as c,j as e,aJ as $,a3 as U,Y,aK as _,aB as H,aC as W}from"./vendor-C-lQMZp3.js";import{L as X}from"./router-Bkbjq53m.js";import{P as Z}from"./PageToolbar-GyUQBhmq.js";import{P as ee,a as z}from"./PageState-Bbhr4fy6.js";import{u as se,b as F,B as x,q as B,C as te,c as ae}from"./app-DZpd2fu9.js";import{u as re}from"./useEventStream-CvopQT4p.js";import{c as E}from"./global-BCYo_xAt.js";import{i as ne,u as K}from"./i18n-ClvfZhYc.js";import{B as y}from"./badge-CWbm9P64.js";import{S as le,a as oe,b as ie,c as ce,d as D,D as de}from"./disclosure-W_XtxMJz.js";import{S as ue}from"./segmented-control-Cxe6ZLHe.js";import"./query-1Ng1fzmE.js";import"./radix-DONH6gHT.js";function me(s){const r=Date.now()-s,l=Math.abs(r),o=60*1e3,f=60*o,d=24*f,m=new Intl.RelativeTimeFormat(ne.language||"en",{numeric:"auto"});if(l<o){const a=Math.max(Math.round(l/1e3),1);return m.format(r>=0?-a:a,"second")}if(l<f){const a=Math.round(l/o);return m.format(r>=0?-a:a,"minute")}if(l<d){const a=Math.round(l/f);return m.format(r>=0?-a:a,"hour")}const h=Math.round(l/d);return m.format(r>=0?-h:h,"day")}function xe(s){return new Date(s).toLocaleString()}const fe={info:"secondary",warn:"outline",error:"destructive"};function Ae(){var L,A,M,k,I,P,R;const{t:s}=K(),{pushToast:n}=se(),[r,l]=c.useState(null),[o,f]=c.useState(""),[d,m]=c.useState(""),h=c.useMemo(()=>({limit:50,cursor:r??void 0,level:o||void 0,type:d||void 0}),[r,o,d]),a=F(B.events.list(h),{url:"/api/events",method:"GET",params:h}),u=F(B.events.stats(),{url:"/api/events/stats",method:"GET"},{refetchInterval:15e3}),V=((L=u.data)==null?void 0:L.error)??0,q=((A=u.data)==null?void 0:A.warn)??0,O=((M=u.data)==null?void 0:M.info)??0,Q=((k=u.data)==null?void 0:k.total)??0,i=re({level:o||void 0,type:d||void 0,maxEvents:50,enabled:r===null}),N=c.useRef(!1);c.useEffect(()=>{const t=a.isError;t&&a.error&&!N.current&&(N.current=!0,n({title:s("events.toast.loadFailure",{message:a.error.message}),variant:"error"})),t||(N.current=!1)},[a.error,a.isError,n,s]);const C=c.useRef(!1);c.useEffect(()=>{const t=u.isError;t&&u.error&&!C.current&&(C.current=!0,n({title:s("events.toast.statsLoadFailure",{message:u.error.message}),variant:"error"})),t||(C.current=!1)},[u.error,u.isError,n,s]);const S=()=>{l(null),f(""),m("")},v=((I=a.data)==null?void 0:I.events)??[],T=((P=a.data)==null?void 0:P.nextCursor)??null,G=a.isLoading,b=c.useMemo(()=>{if(r!==null)return v;const t=new Set;return[...i.events,...v].filter(p=>t.has(p.id)?!1:(t.add(p.id),!0)).slice(0,50)},[r,i.events,v]),J=c.useMemo(()=>{const t=new Set;return v.forEach(p=>t.add(p.type)),i.events.forEach(p=>t.add(p.type)),Array.from(t).sort()},[v,i.events]),g=c.useMemo(()=>{const t=[];return o&&t.push(s(`events.levels.${o}`)),d&&t.push(d),t},[o,d,s]);return e.jsxs("div",{className:"flex flex-col gap-5",children:[e.jsx(Z,{status:r===null?e.jsxs("span",{className:E("inline-flex items-center gap-1.5 text-xs font-medium",i.connected?"text-success":i.failed?"text-destructive":"text-warning"),children:[e.jsx("span",{"aria-hidden":"true",className:E("h-1.5 w-1.5 rounded-full",i.connected?"bg-success animate-live-pulse":i.failed?"bg-destructive":"bg-warning")}),i.connected?s("events.live"):i.failed?s("events.failed"):s("events.reconnecting")]}):e.jsx("span",{className:"text-xs text-muted-foreground",children:s("events.actions.older")}),actions:e.jsxs("div",{className:"flex items-center gap-2",children:[!i.connected&&r===null?e.jsx(x,{variant:"outline",size:"sm",onClick:()=>void a.refetch(),children:s("common.actions.refresh")}):null,e.jsxs("div",{className:"flex items-center gap-2 border border-border bg-secondary px-2 py-1.5",children:[e.jsxs(x,{variant:"outline",size:"sm",disabled:!r,onClick:()=>l(null),children:[e.jsx($,{className:"mr-1 h-4 w-4","aria-hidden":"true"}),s("events.actions.newest")]}),b.length>0?e.jsx("span",{className:"metric-number px-1 text-sm text-muted-foreground",children:s("events.pageCount",{count:b.length})}):null,e.jsxs(x,{variant:"outline",size:"sm",disabled:!T,onClick:()=>l(T),children:[s("events.actions.older"),e.jsx(U,{className:"ml-1 h-4 w-4","aria-hidden":"true"})]})]})]})}),e.jsxs("div",{className:"flex flex-col gap-3 md:flex-row md:flex-wrap md:items-center","data-testid":"events-filters-card",children:[e.jsx(ue,{value:o,onChange:t=>{l(null),f(t)},className:"min-w-max overflow-x-auto",options:[{value:"",label:e.jsx(w,{label:s("events.filters.allLevels"),count:Q,testId:"events-stat-total"})},{value:"info",label:e.jsx(w,{label:s("events.levels.info"),count:O,testId:"events-stat-info"})},{value:"warn",label:e.jsx(w,{label:s("events.levels.warn"),count:q,testId:"events-stat-warn"})},{value:"error",label:e.jsx(w,{label:s("events.levels.error"),count:V,testId:"events-stat-error"})}],"aria-label":s("events.filters.title")}),e.jsxs(le,{value:d||"all",onValueChange:t=>{l(null),m(t==="all"?"":t)},children:[e.jsx(oe,{className:"h-8 w-full md:w-[200px]",children:e.jsx(ie,{})}),e.jsxs(ce,{children:[e.jsx(D,{value:"all",children:s("events.filters.allTypes")}),J.map(t=>e.jsx(D,{value:t,children:t},t))]})]}),g.length>0?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex flex-wrap gap-2",children:g.map(t=>e.jsx(y,{variant:"secondary",children:t},t))}),e.jsx(x,{variant:"ghost",size:"sm",onClick:S,className:"h-8 px-3 text-xs",children:s("common.actions.reset")})]}):null]}),G?e.jsx(ee,{label:s("common.loading")}):a.isError?e.jsx(z,{icon:e.jsx(Y,{className:"h-5 w-5","aria-hidden":"true"}),tone:"danger",title:s("common.status.error"),description:s("events.toast.loadFailure",{message:((R=a.error)==null?void 0:R.message)??s("common.unknownError")}),action:e.jsx(x,{variant:"outline",size:"sm",onClick:()=>void a.refetch(),children:s("common.actions.refresh")})}):b.length===0?e.jsx(z,{icon:e.jsx(_,{className:"h-5 w-5","aria-hidden":"true"}),tone:"primary",title:g.length>0?s("events.empty.filteredTitle"):s("events.empty.title"),description:g.length>0?s("events.empty.filteredSubtitle"):s("events.empty.subtitle"),action:e.jsxs("div",{className:"flex flex-wrap items-center justify-center gap-2",children:[g.length>0?e.jsx(x,{variant:"outline",size:"sm",onClick:S,children:s("common.actions.reset")}):null,e.jsx(x,{asChild:!0,variant:"ghost",size:"sm",children:e.jsx(X,{to:"/logs",children:s("events.empty.actions.logs")})})]})}):e.jsx("div",{className:"grid gap-3",children:e.jsx(H,{initial:!1,children:b.map(t=>e.jsx(W.div,{layout:!0,initial:{opacity:0,y:-12},animate:{opacity:1,y:0},exit:{opacity:0},transition:{duration:.18},children:e.jsx(pe,{event:t})},t.id))})})]})}function w({label:s,count:n,testId:r}){return e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[s,e.jsx("span",{className:"tabular-nums opacity-60","data-testid":r,children:n.toLocaleString()})]})}function pe({event:s}){const{t:n}=K(),r=s.level==="error"?"border-l-error":s.level==="warn"?"border-l-warning":"border-l-success";return e.jsx(te,{className:E("overflow-hidden border-l-2 hover:bg-muted/30",r),children:e.jsxs(ae,{className:"space-y-3 p-4",children:[e.jsxs("div",{className:"flex flex-col gap-2 lg:flex-row lg:items-start lg:justify-between",children:[e.jsxs("div",{className:"min-w-0 space-y-1.5",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(y,{variant:fe[s.level]||"secondary",className:"text-[10px]",children:n(`events.levels.${s.level}`)}),e.jsxs(y,{variant:"outline",className:"text-[10px]",children:["#",s.id]}),s.mode?e.jsx(y,{variant:"secondary",className:"text-[10px]",children:s.mode}):null,s.endpoint?e.jsx(y,{variant:"outline",className:"text-[10px]",children:s.endpoint}):null]}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h3",{className:"truncate text-[15px] font-semibold tracking-[-0.01em]",children:s.title||n("events.defaultTitle")}),e.jsx("p",{className:"mt-1 line-clamp-2 break-words text-sm leading-5 text-muted-foreground [overflow-wrap:anywhere]",children:s.message||n("events.defaultMessage")})]})]}),e.jsxs("div",{className:"shrink-0 space-y-0.5 text-xs text-muted-foreground lg:text-right",children:[e.jsx("p",{"data-visual-volatile":"true",children:xe(s.createdAt)}),e.jsx("p",{"data-visual-volatile":"true",children:me(s.createdAt)})]})]}),e.jsxs("div",{className:"flex flex-wrap gap-2 text-sm",children:[e.jsx(j,{label:"Type",value:s.type}),e.jsx(j,{label:"Source",value:s.source}),e.jsx(j,{label:"IP",value:s.ipAddress}),e.jsx(j,{label:"API Key",value:s.apiKeyName}),e.jsx(j,{label:"User Agent",value:s.userAgent})]}),s.details?e.jsx(de,{summary:n("events.details"),className:"rounded-lg bg-secondary px-3 py-2 text-sm",summaryClassName:"px-0 py-0 text-xs font-medium text-foreground underline decoration-muted-foreground/40 underline-offset-2 hover:decoration-foreground",contentClassName:"mt-2.5",children:e.jsx("pre",{className:"overflow-x-auto rounded-lg bg-secondary p-3 text-xs leading-6",children:JSON.stringify(s.details,null,2)})}):null]})})}function j({label:s,value:n}){return n?e.jsxs("div",{className:"inline-flex max-w-full items-center gap-1.5 border border-border/60 bg-secondary/55 px-2.5 py-1 text-[11px] text-muted-foreground",children:[e.jsxs("span",{className:"font-medium",children:[s,":"]}),e.jsx("span",{className:"truncate text-foreground",title:n,children:n})]}):null}export{Ae as default};
@@ -0,0 +1,4 @@
1
+ import{r as u,j as e}from"./vendor-C-lQMZp3.js";import{P as b}from"./PageToolbar-GyUQBhmq.js";import{P as c}from"./PageSection-Dd2-9G6C.js";import{c as N}from"./clipboard-DqvcglYs.js";import{c as x}from"./global-BCYo_xAt.js";import{B as y}from"./app-DZpd2fu9.js";import{u as g}from"./i18n-ClvfZhYc.js";import"./router-Bkbjq53m.js";import"./query-1Ng1fzmE.js";import"./radix-DONH6gHT.js";function E(){const{t}=g(),r=u.useMemo(()=>[{id:"tour",title:t("help.sections.consoleTour.title"),items:t("help.sections.consoleTour.items",{returnObjects:!0})},{id:"configuration",title:t("help.sections.configuration.title"),items:t("help.sections.configuration.items",{returnObjects:!0})},{id:"claude",title:t("help.sections.claudeCodeConfig.title"),items:t("help.sections.claudeCodeConfig.items",{returnObjects:!0})},{id:"codex",title:t("help.sections.codexConfig.title"),items:t("help.sections.codexConfig.items",{returnObjects:!0})},{id:"usage",title:t("help.sections.usage.title"),items:t("help.sections.usage.items",{returnObjects:!0})},{id:"tips",title:t("help.sections.tips.title"),items:t("help.sections.tips.items",{returnObjects:!0})}],[t]),i=t("help.faq.items",{returnObjects:!0}),l=u.useMemo(()=>[...r.map(o=>({id:o.id,title:o.title})),{id:"faq",title:t("help.faq.title")}],[r,t]);return e.jsxs("div",{className:"space-y-4",children:[e.jsx(b,{info:e.jsx("span",{className:"bg-secondary px-2.5 py-1 text-xs text-muted-foreground",children:t("help.meta.guides",{count:r.length})})}),e.jsxs("div",{className:"rounded-lg border border-border/60 bg-card px-4 py-3 text-sm text-muted-foreground",children:[e.jsx("p",{className:"font-medium text-foreground",children:t("help.note")}),e.jsx("p",{className:"mt-1 text-xs leading-5",children:t("help.helper")})]}),e.jsxs("div",{className:"grid gap-5 xl:grid-cols-[208px_minmax(0,1fr)] xl:items-start",children:[e.jsx("aside",{className:"hidden xl:sticky xl:top-4 xl:block",children:e.jsxs("nav",{"aria-label":t("help.meta.tocTitle"),className:"rounded-lg border border-border/60 bg-card p-3",children:[e.jsx("p",{className:"mb-2 px-1 text-[11px] font-semibold uppercase tracking-wide text-muted-foreground",children:t("help.meta.tocTitle")}),e.jsx("ol",{className:"space-y-0.5 text-sm",children:l.map(o=>e.jsx("li",{children:e.jsx("a",{href:`#help-${o.id}`,className:"block truncate rounded-md px-2 py-1.5 text-muted-foreground transition hover:bg-accent hover:text-foreground",children:o.title})},o.id))})]})}),e.jsxs("div",{className:"min-w-0 space-y-5",children:[e.jsx("div",{id:"help-tour",children:e.jsx(c,{title:r[0].title,children:e.jsx(a,{items:r[0].items,compact:!0})})}),e.jsx("div",{id:"help-configuration",children:e.jsx(c,{title:r[1].title,children:e.jsx(a,{items:r[1].items})})}),e.jsxs("div",{className:"grid gap-5 lg:grid-cols-2",children:[e.jsx("div",{id:"help-claude",children:e.jsx(c,{title:r[2].title,description:t("help.meta.claudeWorkflow"),children:e.jsx(a,{items:r[2].items})})}),e.jsx("div",{id:"help-codex",children:e.jsx(c,{title:r[3].title,description:t("help.meta.codexWorkflow"),children:e.jsx(a,{items:r[3].items})})})]}),e.jsx("div",{id:"help-usage",children:e.jsx(c,{title:r[4].title,children:e.jsx(a,{items:r[4].items})})}),e.jsx("div",{id:"help-tips",children:e.jsx(c,{title:r[5].title,children:e.jsx(a,{items:r[5].items})})}),e.jsx("div",{id:"help-faq",children:e.jsx(c,{title:t("help.faq.title"),children:e.jsx(w,{items:i})})})]})]})]})}function a({items:t,compact:r=!1}){return e.jsx("ol",{className:x("flex flex-col",r?"gap-2":"gap-2.5"),children:t.map((i,l)=>e.jsxs("li",{className:x("flex gap-3 rounded-lg border border-border/50 bg-card",r?"p-3":"p-3.5"),children:[e.jsx("span",{className:x("flex shrink-0 items-center justify-center rounded-md bg-foreground text-xs font-semibold text-background",r?"h-6 w-6 text-[11px]":"h-7 w-7"),children:l+1}),e.jsx("div",{className:"min-w-0 flex-1 text-sm text-muted-foreground",children:e.jsx(f,{content:i})})]},`${l}-${i}`))})}function f({content:t}){const{t:r}=g(),i=t.split("```"),[l,o]=u.useState(null),m=async(d,s)=>{try{await N(s),o(d),window.setTimeout(()=>o(n=>n===d?null:n),1500)}catch{}};return e.jsx("div",{className:"space-y-3",children:i.map((d,s)=>{if(!d.trim())return null;if(s%2===1){const[n,...j]=d.split(`
2
+ `),h=j.join(`
3
+ `).trim();return e.jsxs("div",{className:"overflow-hidden rounded-md border border-border/55 bg-secondary",children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-border/55 px-3 py-1.5",children:[e.jsx("span",{className:"text-[11px] font-semibold uppercase tracking-wide text-muted-foreground",children:n||"bash"}),e.jsx(y,{variant:"ghost",size:"sm",className:"h-6 rounded px-2 text-[11px] text-muted-foreground hover:text-foreground",onClick:()=>void m(s,h),children:r(l===s?"common.actions.copied":"common.actions.copy")})]}),e.jsx("pre",{className:"overflow-x-auto px-3 py-2.5 font-mono text-[12px] leading-6 text-foreground",children:e.jsx("code",{className:"block min-w-full whitespace-pre",children:h})})]},s)}return e.jsx(v,{content:d},s)})})}function v({content:t}){const r=t.split(`
4
+ `).map(s=>s.trimEnd()).filter(s=>s.trim().length>0);if(r.length===0)return null;const i=r.filter(s=>/^[-•*]\s+/.test(s.trim())),l=r.filter(s=>/^\d+[).]\s+/.test(s.trim())),o=r.filter(s=>!/^([-•*]|\d+[).])\s+/.test(s.trim())),m=i.map(s=>s.replace(/^[-•*]\s+/,"")),d=l.map(s=>{const n=s.trim().match(/^(\d+)[).]\s+(.*)$/);return{index:(n==null?void 0:n[1])??"",text:(n==null?void 0:n[2])??s.trim()}});return e.jsxs("div",{className:"space-y-2",children:[o.length>0?e.jsx("div",{className:"space-y-1.5",children:o.map((s,n)=>e.jsx("p",{className:"leading-6",children:p(s)},`${s}-${n}`))}):null,m.length>0?e.jsx("ul",{className:"space-y-1.5 rounded-md bg-secondary px-3 py-2",children:m.map((s,n)=>e.jsxs("li",{className:"flex gap-2 text-sm leading-6",children:[e.jsx("span",{className:"mt-2 h-1.5 w-1.5 shrink-0 rounded-full bg-muted-foreground"}),e.jsx("span",{children:p(s)})]},`${s}-${n}`))}):null,d.length>0?e.jsx("ol",{className:"space-y-1.5 rounded-md bg-secondary px-3 py-2",children:d.map(s=>e.jsxs("li",{className:"flex gap-2.5 text-sm leading-6",children:[e.jsx("span",{className:"mt-0.5 flex h-5 min-w-5 items-center justify-center bg-secondary px-1.5 text-[11px] font-semibold text-foreground",children:s.index}),e.jsx("span",{children:p(s.text)})]},`${s.index}-${s.text}`))}):null]})}function p(t){return t.split(/(`[^`]+`|\*\*[^*]+\*\*)/g).map((i,l)=>i.startsWith("`")&&i.endsWith("`")?e.jsx("code",{className:"rounded bg-secondary px-1.5 py-0.5 text-[0.95em] text-foreground",children:i.slice(1,-1)},l):i.startsWith("**")&&i.endsWith("**")?e.jsx("strong",{className:"font-medium text-foreground",children:i.slice(2,-2)},l):e.jsx("span",{children:i},l))}function w({items:t}){return t.length===0?null:e.jsx("dl",{className:"space-y-2",children:t.map((r,i)=>e.jsxs("details",{className:"group overflow-hidden rounded-lg border border-border/50 bg-card",children:[e.jsxs("summary",{className:"flex cursor-pointer list-none items-center justify-between gap-3 px-4 py-2.5 text-sm font-medium text-foreground",children:[e.jsx("span",{children:r.q}),e.jsx("span",{className:"bg-secondary px-2 py-0.5 text-[11px] text-muted-foreground transition group-open:bg-secondary group-open:text-foreground",children:i+1})]}),e.jsx("div",{className:"border-t border-border/50 px-4 py-3",children:e.jsx("dd",{className:"text-sm text-muted-foreground",children:e.jsx(f,{content:r.a})})})]},r.q))})}export{E as default};
@@ -0,0 +1 @@
1
+ import{r as i,j as e,ba as E,bb as k}from"./vendor-C-lQMZp3.js";import{p as F,C as j,c as b,L,l as S,m as P,n as T,B as A,v as B}from"./app-DZpd2fu9.js";import{L as N,I as v}from"./label-09axTkPo.js";import{u as D}from"./i18n-ClvfZhYc.js";import{a as I,b as q}from"./router-Bkbjq53m.js";import"./global-BCYo_xAt.js";import"./query-1Ng1fzmE.js";import"./radix-DONH6gHT.js";function z(){const{t:s}=D(),r=I(),l=q(),{authEnabled:o,isAuthenticated:u,loading:c,login:y,error:x}=F(),[n,p]=i.useState({username:"",password:""}),[g,m]=i.useState(null),[h,f]=i.useState(!1),d=i.useMemo(()=>{var a;const t=l.state;return((a=t==null?void 0:t.from)==null?void 0:a.pathname)??"/"},[l.state]);i.useEffect(()=>{if(!o&&!c){r(d,{replace:!0});return}o&&u&&!c&&r(d,{replace:!0})},[o,d,u,c,r]),i.useEffect(()=>{document.title=`${s("login.title")} · cc-gw`},[s]);const C=async t=>{if(t.preventDefault(),m(null),!n.username.trim()||!n.password){m(s("login.validation.required"));return}f(!0);try{await y(n.username.trim(),n.password),r(d,{replace:!0})}catch(a){m(a instanceof Error?a.message:s("login.validation.failed"))}finally{f(!1)}};return c?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(L,{})})})}):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-lg bg-secondary px-3 py-1 text-xs font-semibold text-foreground",children:s("login.badge")}),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(w,{icon:e.jsx(E,{className:"h-5 w-5","aria-hidden":"true"}),title:s("login.hint"),description:s("about.support.tip")}),e.jsx(w,{icon:e.jsx(k,{className:"h-5 w-5","aria-hidden":"true"}),title:s("login.sessionProtected"),description:s("help.note")})]})]})}),e.jsxs(j,{className:"w-full",children:[e.jsxs(S,{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(P,{className:"text-xl",children:s("login.title")}),e.jsx(T,{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(N,{htmlFor:"username",children:s("login.fields.username")}),e.jsx(v,{id:"username",value:n.username,autoComplete:"username",autoFocus:!0,onChange:t=>p(a=>({...a,username:t.target.value})),placeholder:s("login.fields.usernamePlaceholder")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(N,{htmlFor:"password",children:s("login.fields.password")}),e.jsx(v,{id:"password",type:"password",value:n.password,autoComplete:"current-password",onChange:t=>p(a=>({...a,password:t.target.value})),placeholder:s("login.fields.passwordPlaceholder")})]}),g||x?e.jsx("div",{role:"alert",className:"rounded-lg bg-destructive/10 px-4 py-3 text-sm text-destructive",children:g||x}):null,e.jsx(A,{type:"submit",className:"w-full",disabled:h,children:s(h?"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 w({description:s,icon:r,title:l}){return e.jsxs("div",{className:"rounded-lg bg-card/[var(--surface-alpha)] surface-blur px-4 py-4 shadow-[var(--surface-shadow)]",children:[e.jsx("div",{className:"flex h-9 w-9 items-center justify-center rounded-lg bg-secondary text-foreground",children:r}),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{z as default};
@@ -0,0 +1 @@
1
+ import{r as d,j as e,t as Qt,aF as Bt,ax as Wt,aG as Gt,ay as Xe,aH as Ze,aE as Jt,aI as Yt,a3 as et,Y as Xt,V as Zt,aJ as es}from"./vendor-C-lQMZp3.js";import{P as ts}from"./PageToolbar-GyUQBhmq.js";import{s as O,C as tt,c as st,B as T,d as ss,u as _e,b as ne,q as se,t as ls,a as $}from"./app-DZpd2fu9.js";import{B as te}from"./badge-CWbm9P64.js";import{L as Z,I as be}from"./label-09axTkPo.js";import{S as lt}from"./segmented-control-Cxe6ZLHe.js";import{S as pe,a as xe,b as ge,c as he,d as B,D as as}from"./disclosure-W_XtxMJz.js";import{c as C}from"./global-BCYo_xAt.js";import{u as H}from"./i18n-ClvfZhYc.js";import{D as ns,A as os,a as rs,b as is,c as cs,d as ds}from"./DialogShell-D1T4HXtd.js";import{P as us,a as re}from"./PageState-Bbhr4fy6.js";import{T as at,a as nt,b as ot,c as rt}from"./tabs-BIz291zK.js";import{c as ms}from"./clipboard-DqvcglYs.js";import{a as ps,g as Ee,b as it,c as W,d as Le,e as P,f as ee,h as Se,p as ct,i as dt,j as ut,k as xs,l as gs,T as hs}from"./currency-DffG4uWM.js";import{P as fs,a as bs,b as ys}from"./popover-CX5HRHKk.js";import{S as js}from"./switch-C58zWdHT.js";import{L as mt,u as vs}from"./router-Bkbjq53m.js";import{a as Ns}from"./query-1Ng1fzmE.js";import{g as We}from"./gateway-DxaHzVOF.js";import"./radix-DONH6gHT.js";function ws({apiKeys:t,selected:l,onChange:i,disabled:a,className:o}){const{t:s}=H(),r=d.useId(),[u,x]=d.useState(!1),[f,b]=d.useState(null),N=d.useRef(null),j=d.useRef(null),v=d.useRef(null),g=()=>{const y=j.current;if(!y)return;const p=y.getBoundingClientRect(),S=Math.max(p.width,256),m=window.innerWidth-12;b({left:Math.min(p.left,m-S),top:p.bottom+8,width:S})};d.useEffect(()=>{if(!u)return;const y=S=>{var D,R;const m=S.target;!((D=N.current)!=null&&D.contains(m))&&!((R=v.current)!=null&&R.contains(m))&&x(!1)},p=S=>{var m;S.key==="Escape"&&(x(!1),(m=j.current)==null||m.focus())};return window.addEventListener("mousedown",y),window.addEventListener("keydown",p),()=>{window.removeEventListener("mousedown",y),window.removeEventListener("keydown",p)}},[u]),d.useEffect(()=>{if(u)return g(),window.addEventListener("resize",g),window.addEventListener("scroll",g,!0),()=>{window.removeEventListener("resize",g),window.removeEventListener("scroll",g,!0)}},[u]);const n=d.useMemo(()=>{if(l.length===0)return[];const y=new Map;for(const p of t)y.set(p.id,p);return l.map(p=>{const S=y.get(p);return S?S.isWildcard?s("apiKeys.wildcard"):S.name:null}).filter(p=>!!p)},[t,l,s]),w=l.length===0?s("logs.filters.apiKeyAll"):s("logs.filters.apiKeySelected",{count:l.length}),h=y=>{l.includes(y)?i(l.filter(p=>p!==y)):i([...l,y])};return e.jsxs("div",{className:C("relative space-y-2",o),ref:N,children:[e.jsx(Z,{htmlFor:r,children:s("logs.filters.apiKey")}),e.jsxs("button",{ref:j,id:r,type:"button",onClick:()=>{g(),x(y=>!y)},disabled:a||t.length===0,title:s("logs.filters.apiKeyHint"),className:C("flex h-10 w-full items-center justify-between rounded-lg 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",l.length>0&&"border-foreground",u&&"ring-2 ring-ring ring-offset-2"),children:[e.jsxs("span",{className:"truncate",children:[w,n.length>0&&e.jsx("span",{className:"ml-1 text-xs text-muted-foreground",children:n.join(", ")})]}),e.jsx("svg",{className:C("h-4 w-4 opacity-50 transition-transform",u&&"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"})})]}),u&&f&&Qt.createPortal(e.jsxs("div",{ref:v,className:"fixed z-50 rounded-lg border bg-popover p-2 shadow-[var(--surface-shadow-lg)]",style:f,children:[e.jsxs("div",{className:"flex items-center justify-between rounded-lg bg-secondary px-3 py-2 text-xs",children:[e.jsx("span",{children:w}),e.jsx("button",{type:"button",onClick:()=>i([]),disabled:l.length===0,className:"text-foreground underline decoration-muted-foreground/40 underline-offset-2 hover:decoration-foreground disabled:opacity-40",children:s("common.actions.reset")})]}),e.jsxs("div",{className:"max-h-56 overflow-y-auto py-2",children:[t.map(y=>{const p=y.isWildcard?s("apiKeys.wildcard"):y.name,S=l.includes(y.id);return e.jsxs("label",{className:C("flex cursor-pointer items-center gap-3 rounded-xl px-3 py-2 text-sm transition hover:bg-accent",S&&"bg-secondary text-foreground"),children:[e.jsx("input",{type:"checkbox",className:"h-4 w-4 rounded border-border",checked:S,onChange:()=>h(y.id)}),e.jsx("span",{className:"truncate",children:p})]},y.id)}),t.length===0&&e.jsx("p",{className:"px-2 py-2 text-xs text-muted-foreground",children:s("logs.filters.apiKeyAll")})]})]}),document.body)]})}const oe=[20,50,100],ks=["all","errors","today","anthropic","openai"],Cs=["claude-code","codex","opencode","gemini-cli","cline","roo-code","cursor","crush","aider","kilo-code","droid","copilot","anthropic-compatible","openai-compatible"],J=["endpoint","provider","client","requestedModel","routedModel","apiKey","tokens","cost","duration","status","error"],le=["endpoint","provider","client","requestedModel","routedModel","apiKey","tokens","cost","duration","status","error"];function Ss(){return typeof window>"u"?"comfortable":window.localStorage.getItem(O.logs.density)==="compact"?"compact":"comfortable"}function _s(){if(typeof window>"u")return oe[0];const t=window.localStorage.getItem(O.logs.pageSize),l=Number(t);return oe.includes(l)?l:oe[0]}function Ge(t,l=!1){if(!t)return;const i=l?`${t}T23:59:59.999`:`${t}T00:00:00.000`,a=Date.parse(i);return Number.isFinite(a)?a:void 0}function Es(t,l,i){return t===i&&l===i}function Ls(t){const{t:l}=H(),{activeFilters:i,filtersExpanded:a,setFiltersExpanded:o,handleResetFilters:s,activeQuickView:r,applyQuickView:u,providerFilter:x,setProviderFilter:f,endpointFilter:b,setEndpointFilter:N,selectedApiKeys:j,setSelectedApiKeys:v,modelFilter:g,setModelFilter:n,clientKindFilter:w,setClientKindFilter:h,sessionFilter:y,setSessionFilter:p,statusFilter:S,setStatusFilter:m,fromDate:D,setFromDate:R,toDate:M,setToDate:_,providerOptions:F,apiKeys:U,apiKeysLoading:L,customEndpoints:A}=t;return e.jsx(tt,{"data-testid":"logs-filters-card",className:"overflow-hidden",children:e.jsxs(st,{className:"space-y-3 p-4",children:[e.jsxs("div",{className:"flex flex-col gap-3",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:l("logs.filtersTitle")}),i.length>0&&e.jsx(te,{variant:"outline",className:"border-transparent bg-secondary px-2.5 py-0.5 text-[11px] font-semibold text-foreground",children:l("common.filters.activeCount",{count:i.length})})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:l("logs.filtersDescription")})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[i.length>0&&e.jsx(T,{variant:"ghost",size:"sm",onClick:s,className:"h-8 px-3 text-xs",children:l("common.actions.reset")}),e.jsx(T,{variant:"ghost",size:"sm",onClick:()=>o(k=>!k),className:"h-8 px-3 text-xs",children:a?e.jsxs(e.Fragment,{children:[l("common.filters.collapse"),e.jsx(Bt,{className:"ml-1 h-4 w-4"})]}):e.jsxs(e.Fragment,{children:[l("common.filters.expand"),e.jsx(Wt,{className:"ml-1 h-4 w-4"})]})})]})]}),i.length>0?e.jsx("div",{className:"flex min-h-10 flex-wrap items-center gap-2 rounded-lg bg-secondary px-3 py-2",children:i.map(k=>e.jsxs(te,{variant:"outline",role:"button",tabIndex:0,className:"flex cursor-pointer items-center gap-1 border border-border bg-card px-2.5 py-1 text-[11px] font-semibold text-foreground/90 transition hover:bg-secondary",onClick:k.onRemove,onKeyDown:ie=>{(ie.key==="Enter"||ie.key===" ")&&(ie.preventDefault(),k.onRemove())},children:[k.label,e.jsx(Gt,{className:"h-3 w-3","aria-hidden":"true"})]},k.key))}):null,e.jsx(lt,{value:r,onChange:u,className:"flex-wrap","aria-label":l("logs.filtersTitle"),options:ks.map(k=>({value:k,label:l(`logs.quickViews.${k}`)}))})]}),a&&e.jsxs("div",{className:"mt-3 grid gap-3 rounded-xl bg-secondary p-3 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(Z,{children:l("logs.filters.provider")}),e.jsxs(pe,{value:x,onValueChange:f,children:[e.jsx(xe,{children:e.jsx(ge,{})}),e.jsxs(he,{children:[e.jsx(B,{value:"all",children:l("logs.filters.providerAll")}),F.map(k=>e.jsx(B,{value:k.id,children:k.label??k.id},k.id))]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Z,{children:l("logs.filters.endpoint")}),e.jsxs(pe,{value:b,onValueChange:N,children:[e.jsx(xe,{children:e.jsx(ge,{})}),e.jsxs(he,{children:[e.jsx(B,{value:"all",children:l("logs.filters.endpointAll")}),e.jsx(B,{value:"anthropic",children:l("logs.filters.endpointAnthropic")}),e.jsx(B,{value:"openai",children:l("logs.filters.endpointOpenAI")}),A==null?void 0:A.map(k=>e.jsx(B,{value:k.id,children:k.label||k.id},k.id))]})]})]}),e.jsx(ws,{className:"md:col-span-2",apiKeys:U,selected:j,disabled:L,onChange:v}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Z,{children:l("logs.filters.modelId")}),e.jsx(be,{value:g,onChange:k=>n(k.target.value),placeholder:l("logs.filters.modelPlaceholder")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Z,{children:l("logs.filters.clientKind")}),e.jsxs(pe,{value:w,onValueChange:h,children:[e.jsx(xe,{children:e.jsx(ge,{})}),e.jsxs(he,{children:[e.jsx(B,{value:"all",children:l("logs.filters.clientKindAll")}),Cs.map(k=>e.jsx(B,{value:k,children:l(`dashboard.usage.clientKinds.${k}`,{defaultValue:k})},k))]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Z,{children:l("logs.filters.status")}),e.jsxs(pe,{value:S,onValueChange:k=>m(k),children:[e.jsx(xe,{children:e.jsx(ge,{})}),e.jsxs(he,{children:[e.jsx(B,{value:"all",children:l("logs.filters.statusAll")}),e.jsx(B,{value:"success",children:l("logs.filters.statusSuccess")}),e.jsx(B,{value:"error",children:l("logs.filters.statusError")})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Z,{children:l("logs.filters.startDate")}),e.jsx(be,{type:"date",value:D,onChange:k=>R(k.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Z,{children:l("logs.filters.endDate")}),e.jsx(be,{type:"date",value:M,onChange:k=>_(k.target.value)})]}),e.jsxs("div",{className:"space-y-2 md:col-span-2",children:[e.jsx(Z,{htmlFor:"logs-session-filter",children:l("logs.filters.session")}),e.jsx(be,{id:"logs-session-filter",value:y,onChange:k=>p(k.target.value),placeholder:l("logs.filters.sessionPlaceholder"),className:"font-mono"})]})]})]})})}const Re={listRequest(t){return{url:"/api/logs",method:"GET",params:t}},detailRequest(t){return{url:t===null?"":`/api/logs/${t}`,method:"GET"}},async exportArchive(t,l){const i=await ss.post("/api/logs/export",t,{responseType:"blob",timeout:l});return new Blob([i.data],{type:"application/zip"})}};function pt({apiKeyMap:t,logId:l,open:i,providerLabelMap:a}){var g;const{t:o}=H(),{pushToast:s}=_e(),r=ne(se.logs.detail(l),Re.detailRequest(l),{enabled:i&&l!==null,staleTime:3e4,gcTime:15e3,placeholderData:void 0});d.useEffect(()=>{!r.isError||!r.error||s({title:o("logs.detail.loadError"),description:r.error.message,variant:"error"})},[r.error,r.isError,s,o]);const u=d.useCallback(async(n,w,h)=>{if(!w){s({title:o("logs.detail.copy.empty",{label:n}),variant:"info"});return}try{await ms(w),s({title:o(h),variant:"success"})}catch(y){s({title:o("logs.detail.copy.failure"),description:y instanceof Error?y.message:o("logs.detail.copy.failureFallback"),variant:"error"})}},[s,o]),x=d.useCallback((n,w)=>{if(!w){s({title:o("logs.detail.copy.empty",{label:n}),variant:"info"});return}const h=new Blob([w],{type:"application/json;charset=utf-8"}),y=URL.createObjectURL(h),p=document.createElement("a"),S=new Date().toISOString().replace(/[:.]/g,"-"),m=n.trim().toLowerCase().replace(/[^a-z0-9\u4e00-\u9fa5]+/gi,"-").replace(/^-+|-+$/g,"")||"payload";p.href=y,p.download=`cc-gw-log-${l??"payload"}-${m}-${S}.json`,document.body.appendChild(p),p.click(),document.body.removeChild(p),URL.revokeObjectURL(y)},[l,s,o]),f=r.data,b=f?a.get(f.provider)??f.provider:"",N=f&&f.api_key_id!=null?t.get(f.api_key_id):void 0,j=f?ps(f,o):null,v=f?Ee(f,o):null;return{apiKeyMeta:N,errorSourceMeta:j,errorMessage:r.isError?((g=r.error)==null?void 0:g.message)??null:null,handleCopy:u,handleDownloadPayload:x,isError:r.isError,isPending:r.isPending,providerLabel:b,refetch:r.refetch,record:f,statusMeta:v}}function xt({detail:t,compact:l=!1}){var r;const{t:i}=H(),a=u=>i(`logs.detail.errorDetail.stages.${u}`,{defaultValue:u}),o=e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[t.stage?e.jsx("span",{className:"border border-border bg-secondary px-1.5 py-0.5 text-[11px] font-medium text-foreground",children:a(t.stage)}):null,t.upstreamStatus!=null?e.jsxs("span",{className:"border border-destructive/40 bg-destructive/10 px-1.5 py-0.5 text-[11px] font-semibold tabular-nums text-destructive",children:["HTTP ",t.upstreamStatus]}):null,(r=t.failoverAttempts)!=null&&r.length?e.jsx("span",{className:"text-[11px] text-muted-foreground",children:i("logs.detail.errorDetail.attemptsCount",{count:t.failoverAttempts.length})}):null]}),s=t.failoverAttempts??[];return e.jsx(as,{defaultOpen:!0,summaryClassName:"px-1 py-1",contentClassName:C("mt-1 space-y-2",l&&"text-[11px]"),summary:e.jsx("span",{className:C("text-xs font-medium text-foreground",l&&"text-[11px]"),children:i("logs.detail.errorDetail.title")}),children:e.jsxs("div",{className:"space-y-2","data-testid":"log-error-detail",children:[o,t.message?e.jsx("p",{className:C("whitespace-pre-wrap break-all border-l-2 border-destructive/50 bg-destructive/5 px-2.5 py-1.5 font-mono",l?"text-[10.5px] leading-[1.55]":"text-[11px] leading-[1.6]"),children:t.message}):null,s.length>0?e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-[11px]",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-border text-left text-muted-foreground",children:[e.jsx("th",{className:"py-1 pr-3 font-medium",children:i("logs.detail.errorDetail.attemptBackend")}),e.jsx("th",{className:"py-1 pr-3 font-medium",children:i("logs.detail.errorDetail.attemptOutcome")}),e.jsx("th",{className:"py-1 pr-3 text-right font-medium",children:i("logs.detail.errorDetail.attemptStatus")}),e.jsx("th",{className:"py-1 text-right font-medium",children:i("logs.detail.errorDetail.attemptLatency")})]})}),e.jsx("tbody",{className:"tabular-nums",children:s.map((u,x)=>e.jsxs("tr",{className:"border-b border-border/50 last:border-b-0",children:[e.jsxs("td",{className:"py-1 pr-3",children:[e.jsx("span",{className:"font-medium",children:u.provider??"—"}),e.jsxs("span",{className:"text-muted-foreground",children:[" / ",u.model??"—"]})]}),e.jsx("td",{className:"py-1 pr-3 text-muted-foreground",children:u.outcome??"—"}),e.jsx("td",{className:"py-1 pr-3 text-right",children:u.status!=null?e.jsx("span",{className:u.status>=400?"text-destructive":"text-foreground",children:u.status}):"—"}),e.jsx("td",{className:"py-1 text-right text-muted-foreground",children:u.latencyMs!=null?`${u.latencyMs} ms`:"—"})]},x))})]})}):null,t.upstreamBody?e.jsxs("div",{className:"space-y-0.5",children:[e.jsx("p",{className:C("text-muted-foreground",l?"text-[10.5px]":"text-[11px]"),children:i("logs.detail.errorDetail.upstreamBody")}),e.jsx("pre",{className:C("m-0 max-h-[180px] overflow-auto whitespace-pre-wrap border border-border bg-secondary/50 p-2 font-mono text-muted-foreground",l?"text-[10.5px] leading-[1.55]":"text-[11px] leading-[1.6]"),children:t.upstreamBody})]}):null]})})}function Rs({open:t,logId:l,onClose:i,providerLabelMap:a,apiKeyMap:o}){var y,p,S,m,D,R,M;const{t:s}=H(),{apiKeyMeta:r,errorSourceMeta:u,errorMessage:x,handleCopy:f,handleDownloadPayload:b,isError:N,isPending:j,providerLabel:v,refetch:g,record:n,statusMeta:w}=pt({apiKeyMap:o,logId:l,open:t,providerLabelMap:a}),h=d.useMemo(()=>{var F,U,L,A;return n?[{key:"client-request",title:s("logs.detail.payload.clientRequest"),value:((F=n.payload)==null?void 0:F.client_request)??null,emptyLabel:s("logs.detail.payload.emptyRequest"),copyToast:"logs.detail.copy.requestSuccess"},...(U=n.payload)!=null&&U.upstream_request?[{key:"upstream-request",title:s("logs.detail.payload.upstreamRequest"),value:n.payload.upstream_request,emptyLabel:s("logs.detail.payload.emptyRequest"),copyToast:"logs.detail.copy.requestSuccess"}]:[],...(L=n.payload)!=null&&L.upstream_response?[{key:"upstream-response",title:s("logs.detail.payload.upstreamResponse"),value:n.payload.upstream_response,emptyLabel:s("logs.detail.payload.emptyResponse"),copyToast:"logs.detail.copy.responseSuccess"}]:[],{key:"client-response",title:s("logs.detail.payload.clientResponse"),value:((A=n.payload)==null?void 0:A.client_response)??null,emptyLabel:s("logs.detail.payload.emptyResponse"),copyToast:"logs.detail.copy.responseSuccess"}].map(k=>({...k,display:it(k.value,k.emptyLabel)})):[]},[n,s]);return e.jsx(ns,{open:t,onOpenChange:_=>{_||i()},children:e.jsxs(os,{className:"w-[min(96vw,1200px)] max-w-[1200px]",children:[e.jsxs(rs,{className:"pr-14",children:[e.jsx(is,{children:s("logs.detail.title")}),e.jsx(cs,{children:n?s("logs.detail.id",{id:n.id}):s("logs.detail.loadError")})]}),e.jsx(ds,{className:"max-h-[78vh]",children:j?e.jsx(us,{compact:!0,className:"min-h-[240px]",label:s("common.loading")}):N?e.jsx(re,{compact:!0,className:"min-h-[240px]",tone:"danger",title:s("logs.detail.loadError"),description:x??s("common.unknownError"),action:e.jsx(T,{variant:"outline",onClick:()=>void g(),children:s("common.actions.refresh")})}):n?e.jsxs("div",{className:"space-y-6 text-sm",children:[e.jsxs("section",{className:"space-y-4 rounded-lg border bg-card p-4",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:s("logs.detail.infoSection")}),e.jsx("div",{className:"flex flex-wrap items-center gap-2 rounded-lg border bg-secondary p-3 text-xs",children:e.jsx("span",{className:"font-medium",children:s("logs.detail.summary.route",{from:n.client_model??s("logs.detail.info.noRequestedModel"),to:n.model})})})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(te,{variant:w==null?void 0:w.variant,children:(w==null?void 0:w.label)??"—"}),e.jsx(te,{variant:"outline",children:n.stream?s("logs.stream.streaming"):s("logs.stream.single")})]})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2 xl:grid-cols-4",children:[e.jsx(I,{label:s("logs.detail.info.latency"),value:W(n.latency_ms,s("common.units.ms"))}),e.jsx(I,{label:s("logs.detail.info.ttft"),value:W(n.ttft_ms,s("common.units.ms"))}),e.jsx(I,{label:s("logs.detail.info.tpot"),value:W(n.tpot_ms,s("common.units.msPerToken"))}),e.jsx(I,{label:s("logs.detail.info.errorSource"),value:(u==null?void 0:u.label)??"—"})]}),e.jsxs("dl",{className:"grid gap-x-4 gap-y-3 md:grid-cols-2 xl:grid-cols-4",children:[e.jsx(Q,{label:s("logs.detail.info.time"),value:Le(n.timestamp)}),e.jsx(Q,{label:s("logs.detail.info.sessionId"),value:n.session_id??"—"}),e.jsx(Q,{label:s("logs.detail.info.endpoint"),value:n.endpoint||"—"}),e.jsx(Q,{label:s("logs.detail.info.provider"),value:v}),e.jsx(Q,{label:s("logs.detail.info.client"),value:n.client_kind??"—"}),e.jsx(Q,{label:s("logs.detail.info.userAgent"),value:n.user_agent??"—"}),e.jsx(Q,{label:s("logs.detail.info.requestedModel"),value:n.client_model??s("logs.detail.info.noRequestedModel")}),e.jsx(Q,{label:s("logs.detail.info.model"),value:n.model})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2 xl:grid-cols-4",children:[e.jsx(I,{label:s("logs.detail.info.inputTokens"),value:P(n.input_tokens)}),e.jsx(I,{label:s("logs.detail.info.cacheReadTokens"),value:P(n.cache_read_tokens)}),e.jsx(I,{label:s("logs.detail.info.cacheCreationTokens"),value:P(n.cache_creation_tokens)}),e.jsx(I,{label:s("logs.detail.info.outputTokens"),value:P(n.output_tokens)})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2 xl:grid-cols-5","data-testid":"log-cost-breakdown",children:[e.jsx(I,{label:s("logs.detail.cost.title"),value:ee(n.cost,n.cost_currency)}),n.cost!=null?e.jsxs(e.Fragment,{children:[e.jsx(I,{label:s("logs.detail.cost.input"),value:ee(((y=n.cost_breakdown)==null?void 0:y.input)??null,n.cost_currency)}),e.jsx(I,{label:s("logs.detail.cost.output"),value:ee(((p=n.cost_breakdown)==null?void 0:p.output)??null,n.cost_currency)}),e.jsx(I,{label:s("logs.detail.cost.cacheRead"),value:ee(((S=n.cost_breakdown)==null?void 0:S.cacheRead)??null,n.cost_currency)}),e.jsx(I,{label:s("logs.detail.cost.cacheCreation"),value:ee(((m=n.cost_breakdown)==null?void 0:m.cacheCreation)??null,n.cost_currency)})]}):null]}),n.cost==null&&!Se(n)?e.jsx("p",{className:"text-xs text-muted-foreground/70",children:s("logs.detail.cost.unpricedHint")}):null,Se(n)?e.jsx("p",{className:"text-xs text-muted-foreground/70",children:s("logs.detail.tokensNoUsageHint")}):null,n.error?e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:s("logs.detail.info.error")}),e.jsx("p",{className:"rounded-xl border border-destructive/50 bg-destructive/10 p-3 text-xs text-destructive",children:n.error})]}):null,(()=>{const _=ct(n);return _?"raw"in _?e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:s("logs.detail.errorDetail.title")}),e.jsx("pre",{className:"m-0 max-h-[180px] overflow-auto whitespace-pre-wrap rounded-xl border border-border bg-secondary/50 p-3 font-mono text-[11px] leading-[1.6] text-muted-foreground",children:_.raw})]}):e.jsx(xt,{detail:_}):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 bg-card p-4",children:[e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:s("logs.detail.apiKey.title")}),e.jsxs("dl",{className:"grid gap-x-4 gap-y-3 sm:grid-cols-2",children:[e.jsx(Q,{label:s("logs.detail.apiKey.name"),value:n.api_key_id==null&&!n.api_key_name?s("logs.detail.apiKey.missing"):r!=null&&r.isWildcard?s("apiKeys.wildcard"):(r==null?void 0:r.name)??n.api_key_name??s("logs.detail.apiKey.missing")}),e.jsx(Q,{label:s("logs.detail.apiKey.identifier"),value:n.api_key_id??s("common.noData")}),e.jsx(Q,{label:s("logs.detail.apiKey.masked"),value:r!=null&&r.isWildcard?s("apiKeys.wildcard"):(r==null?void 0:r.maskedKey)??n.api_key_name??s("logs.detail.apiKey.maskedUnavailable")}),e.jsx(Q,{label:s("logs.detail.apiKey.lastUsed"),value:r!=null&&r.lastUsedAt?new Date(r.lastUsedAt).toLocaleString():s("common.noData")})]}),e.jsxs("div",{className:"rounded-lg border bg-secondary p-3 text-xs",children:[e.jsx("p",{className:"font-medium",children:s("logs.detail.apiKey.rawMasked")}),e.jsx("p",{className:"mt-1 break-all font-mono",children:n.api_key_value_available?n.api_key_value_masked??s("logs.detail.apiKey.rawUnavailable"):s("logs.detail.apiKey.rawUnavailable")}),e.jsx("p",{className:"mt-2 text-[11px] text-muted-foreground",children:s("logs.detail.apiKey.rawMaskedHint")})]})]}),e.jsxs("section",{className:"space-y-4 rounded-lg border bg-card p-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:s("logs.detail.payload.title")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:(D=n.payload)!=null&&D.upstream_request||(R=n.payload)!=null&&R.upstream_response?s("logs.detail.payload.helperWithUpstream"):s("logs.detail.payload.helperClientOnly")})]}),e.jsxs(at,{defaultValue:(M=h[0])==null?void 0:M.key,children:[e.jsx(nt,{className:"w-full justify-start overflow-x-auto",children:h.map(_=>e.jsx(ot,{value:_.key,children:_.title},_.key))}),h.map(_=>e.jsx(rt,{value:_.key,children:e.jsx(Fs,{title:_.title,display:_.display,onCopy:()=>f(_.title,_.value,_.copyToast),onDownload:()=>b(_.title,_.value),panelKey:_.key,t:s})},_.key))]})]})]})]}):e.jsx(re,{compact:!0,className:"min-h-[240px]",title:s("logs.detail.loadError"),description:s("common.noData")})})]})})}function I({label:t,value:l}){return e.jsxs("div",{className:"min-w-0 rounded-lg border bg-secondary px-3 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 break-all text-sm font-semibold leading-6",children:l})]})}function Q({label:t,value:l}){return e.jsxs("div",{className:"min-w-0 space-y-1",children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:t}),e.jsx("dd",{className:"min-w-0 break-all whitespace-pre-wrap text-sm font-medium leading-6 text-foreground",children:l??"—"})]})}function Fs({display:t,onCopy:l,onDownload:i,panelKey:a,title:o,t:s}){return e.jsxs("div",{className:"space-y-3 rounded-lg border bg-secondary/40 p-4","data-testid":`log-payload-${a}`,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.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(T,{variant:"outline",size:"sm",onClick:l,children:[e.jsx(Xe,{className:"mr-2 h-3.5 w-3.5"}),s("common.actions.copy")]}),e.jsxs(T,{variant:"outline",size:"sm",onClick:i,children:[e.jsx(Ze,{className:"mr-2 h-3.5 w-3.5"}),s("common.actions.download")]})]})]}),t.isTruncated?e.jsx("p",{className:"rounded-lg border border-warning/30 bg-warning-bg px-3 py-2 text-xs text-warning",children:s("logs.detail.payload.truncated",{shown:t.displayedLength.toLocaleString(),total:t.originalLength.toLocaleString()})}):null,e.jsx("pre",{className:"max-h-72 overflow-auto whitespace-pre rounded-lg border bg-secondary p-3 text-xs",children:t.text})]})}function Ds({autoRefresh:t,columnOptions:l,exporting:i,onExport:a,onRefresh:o,onResetColumns:s,onSetDensity:r,onToggleAutoRefresh:u,onToggleColumn:x,refreshing:f,rowDensity:b,visibleColumns:N,visibleColumnSet:j,autoHiddenColumns:v}){const{t:g}=H(),n=JSON.stringify(N)===JSON.stringify(J),w=new Set(v);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:"grid w-full grid-cols-2 gap-2 sm:flex sm:flex-row sm:flex-wrap sm:items-center xl:w-auto xl:flex-nowrap",children:[e.jsx(lt,{block:!0,className:"col-span-2 w-full overflow-x-auto sm:w-auto",value:b,onChange:r,options:[{value:"comfortable",label:g("logs.table.density.comfortable")},{value:"compact",label:g("logs.table.density.compact")}]}),e.jsxs(fs,{children:[e.jsx(bs,{asChild:!0,children:e.jsx(T,{variant:"outline",size:"sm",className:"w-full sm:w-auto",children:g("logs.actions.columns")})}),e.jsxs(ys,{align:"end",className:"w-64 p-3",children:[e.jsxs("div",{className:"mb-3 flex items-center justify-between",children:[e.jsx("p",{className:"text-sm font-semibold",children:g("logs.actions.columns")}),e.jsx(T,{variant:"ghost",size:"sm",onClick:s,disabled:n,children:g("common.actions.reset")})]}),e.jsx("div",{className:"grid gap-1.5",children:l.map(h=>{const y=j.has(h.id);return e.jsxs("label",{className:C("flex cursor-pointer items-center gap-3 rounded-xl px-3 py-2 text-sm transition hover:bg-accent",y&&"bg-secondary text-foreground"),children:[e.jsx("input",{type:"checkbox",checked:y,onChange:()=>x(h.id),className:"h-4 w-4 rounded border-border"}),e.jsx("span",{children:h.label}),w.has(h.id)?e.jsx("span",{className:"ml-auto rounded-sm bg-muted px-1.5 py-0.5 text-[10px] font-medium text-muted-foreground",children:g("logs.table.narrowHiddenPill")}):null]},h.id)})}),e.jsx("p",{className:"mt-3 text-[11px] leading-snug text-muted-foreground",children:g("logs.table.autoHiddenNote")})]})]}),e.jsxs(T,{variant:"outline",onClick:a,disabled:i,className:"w-full sm:w-auto",children:[e.jsx(Ze,{className:"mr-2 h-4 w-4"}),g(i?"logs.actions.exporting":"logs.actions.export")]})]}),e.jsxs("div",{className:"flex w-full items-center gap-3 xl:w-auto",children:[e.jsxs("label",{className:"flex shrink-0 cursor-pointer items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(js,{checked:t,onCheckedChange:u,"aria-label":g("logs.actions.autoRefresh")}),g("logs.actions.autoRefresh")]}),e.jsxs(T,{variant:"outline",size:"sm",onClick:o,disabled:f,className:"shrink-0",children:[e.jsx(Jt,{className:C("mr-2 h-4 w-4",f&&"animate-spin")}),g(f?"common.actions.refreshing":"logs.actions.manualRefresh")]})]})]})}function Ts({record:t,providerLabelMap:l,onSelect:i,costCurrency:a}){const{t:o}=H(),s=Ee(t,o),r=l.get(t.provider)??t.provider,u=dt(t.session_id),x=u==null?void 0:u.accentStyle;return e.jsxs("button",{type:"button","data-session-id":u==null?void 0:u.sessionId,"data-session-color":u==null?void 0:u.colorKey,style:x,onClick:()=>i(t.id),className:"w-full space-y-2 border-b border-border/50 px-4 py-3 text-left transition-colors hover:bg-muted/50",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:Le(t.timestamp)}),e.jsx(te,{variant:s.variant,className:"text-xs",children:s.label})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3 text-xs",children:[e.jsx("span",{className:"min-w-0 truncate font-medium",title:r,children:r}),e.jsx("span",{className:"min-w-0 truncate text-muted-foreground",title:t.model,children:t.model})]}),t.client_kind?e.jsx("div",{className:"text-[11px] text-muted-foreground/80",title:t.user_agent??void 0,children:t.client_kind}):null,e.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1 text-xs tabular-nums text-muted-foreground",children:[e.jsx("span",{children:W(t.latency_ms,o("common.units.ms"))}),t.ttft_ms!=null?e.jsxs("span",{children:[o("logs.table.columns.latencyTtft")," ",W(t.ttft_ms,o("common.units.ms"))]}):null,t.tpot_ms!=null?e.jsxs("span",{children:[o("logs.table.columns.latencyTpot")," ",W(t.tpot_ms,o("common.units.msPerToken"))]}):null,t.cost!=null?e.jsx("span",{children:ee(t.cost,a)}):null]}),t.cache_read_tokens!=null||t.cache_creation_tokens!=null?e.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px] tabular-nums text-muted-foreground/80",children:[e.jsxs("span",{children:[o("logs.table.columns.tokenCacheRead")," ",P(t.cache_read_tokens??t.cached_tokens)]}),e.jsxs("span",{children:[o("logs.table.columns.tokenCacheWrite")," ",P(t.cache_creation_tokens)]})]}):null]})}const Je={accent:"bg-foreground",ok:"bg-success",warn:"bg-warning",error:"bg-destructive"};function Ks({logId:t,providerLabelMap:l,apiKeyMap:i}){const{t:a}=H(),{record:o,isPending:s,isError:r,errorMessage:u,statusMeta:x,providerLabel:f,handleCopy:b,refetch:N}=pt({apiKeyMap:i,logId:t,open:!0,providerLabelMap:l}),j=d.useMemo(()=>{var D,R,M,_;if(!o)return[];const m=[{key:"client-request",title:a("logs.detail.payload.clientRequest"),value:((D=o.payload)==null?void 0:D.client_request)??null,emptyLabel:a("logs.detail.payload.emptyRequest"),copyToast:"logs.detail.copy.requestSuccess"}];return(R=o.payload)!=null&&R.upstream_request&&m.push({key:"upstream-request",title:a("logs.detail.payload.upstreamRequest"),value:o.payload.upstream_request,emptyLabel:a("logs.detail.payload.emptyRequest"),copyToast:"logs.detail.copy.requestSuccess"}),(M=o.payload)!=null&&M.upstream_response&&m.push({key:"upstream-response",title:a("logs.detail.payload.upstreamResponse"),value:o.payload.upstream_response,emptyLabel:a("logs.detail.payload.emptyResponse"),copyToast:"logs.detail.copy.responseSuccess"}),m.push({key:"client-response",title:a("logs.detail.payload.clientResponse"),value:((_=o.payload)==null?void 0:_.client_response)??null,emptyLabel:a("logs.detail.payload.emptyResponse"),copyToast:"logs.detail.copy.responseSuccess"}),m.map(F=>({...F,display:it(F.value,F.emptyLabel)}))},[o,a]),[v,g]=d.useState("client-request"),n=j.find(m=>m.key===v)??j[0];if(s)return e.jsx("div",{className:"py-3",children:e.jsx(ut,{className:"h-28 w-full"})});if(r)return e.jsx(re,{compact:!0,tone:"danger",title:a("logs.detail.loadError"),description:u??a("common.unknownError"),action:e.jsx(T,{variant:"outline",size:"sm",onClick:()=>void N(),children:a("common.actions.refresh")})});if(!o)return e.jsx(re,{compact:!0,title:a("logs.detail.loadError"),description:a("common.noData")});const w=xs(o,f,a),h=a("common.units.ms"),y=[{label:a("logs.detail.info.status"),value:(x==null?void 0:x.label)??"—"},{label:a("logs.detail.info.latency"),value:W(o.latency_ms,h)},{label:a("logs.detail.info.ttft"),value:W(o.ttft_ms,h)},{label:a("logs.detail.info.tpot"),value:W(o.tpot_ms,a("common.units.msPerToken"))},{label:a("logs.detail.info.inputTokens"),value:P(o.input_tokens)},{label:a("logs.detail.info.outputTokens"),value:P(o.output_tokens)},{label:a("logs.detail.info.cacheReadTokens"),value:P(o.cache_read_tokens??o.cached_tokens)},{label:a("logs.detail.info.cacheCreationTokens"),value:P(o.cache_creation_tokens)},{label:a("logs.detail.info.cost"),value:ee(o.cost,o.cost_currency)}],p=o.ttft_ms!=null,S=o.session_id;return e.jsxs("div",{"data-testid":"log-row-expanded",className:"grid gap-5 py-1 xl:grid-cols-[minmax(0,1.15fr)_minmax(0,1fr)]",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"mb-3 text-[10.5px] font-semibold uppercase tracking-[0.06em] text-muted-foreground",children:a("logs.detail.trace.title")}),e.jsx("ol",{"data-testid":"log-trace-timeline",className:"flex flex-col",children:w.map((m,D)=>e.jsxs("li",{className:"grid grid-cols-[14px_1fr] gap-3",children:[e.jsxs("div",{className:"flex flex-col items-center","aria-hidden":"true",children:[e.jsx("span",{className:C("mt-1 h-[9px] w-[9px] rounded-full",Je[m.tone])}),D<w.length-1?e.jsx("span",{className:"mt-[3px] w-px flex-1 bg-border"}):null]}),e.jsxs("div",{className:"pb-3.5",children:[e.jsxs("div",{className:"flex items-baseline gap-2.5",children:[e.jsx("span",{className:"text-xs font-semibold",children:m.title}),m.atLabel?e.jsx("span",{className:"text-[10.5px] tabular-nums text-muted-foreground",children:m.atLabel}):null,m.durLabel?e.jsx("span",{className:"ml-auto text-[10.5px] tabular-nums text-muted-foreground",children:m.durLabel}):null]}),m.detail?e.jsx("div",{className:"mt-1 text-[11px] leading-[1.55] text-muted-foreground",children:m.detail}):null,e.jsx("div",{className:"mt-1.5 h-1 w-full max-w-[220px] bg-secondary",children:e.jsx("div",{className:C("h-full",Je[m.tone]),style:{width:`${m.barPct}%`}})})]})]},m.id))}),p?null:e.jsx("p",{className:"mt-1 text-[10.5px] text-muted-foreground/70",children:a("logs.detail.trace.degraded")}),(()=>{const m=ct(o);return!m||"raw"in m?null:e.jsx("div",{className:"mt-2 border-t border-border pt-2",children:e.jsx(xt,{detail:m,compact:!0})})})()]}),e.jsxs("div",{className:"flex min-w-0 flex-col gap-3",children:[e.jsx("div",{className:"grid grid-cols-3 gap-2",children:y.map(m=>e.jsxs("div",{className:"border border-border bg-card px-2.5 py-2",children:[e.jsx("div",{className:"text-[10.5px] text-muted-foreground",children:m.label}),e.jsx("div",{className:"mt-0.5 text-[13px] font-semibold tabular-nums",children:m.value})]},m.label))}),Se(o)?e.jsx("p",{className:"text-[11px] text-muted-foreground/70",children:a("logs.detail.tokensNoUsageHint")}):null,e.jsx("div",{className:"border border-border bg-card",children:e.jsxs(at,{value:n==null?void 0:n.key,onValueChange:g,children:[e.jsx(nt,{className:"w-full justify-start overflow-x-auto",children:j.map(m=>e.jsx(ot,{value:m.key,className:"px-2.5 text-[10.5px]",children:m.title},m.key))}),j.map(m=>e.jsx(rt,{value:m.key,className:"mt-0",children:e.jsx("pre",{"data-testid":`log-payload-${m.key}`,className:"m-0 max-h-[172px] overflow-auto whitespace-pre-wrap p-3 font-mono text-[10.5px] leading-[1.65] text-muted-foreground",children:m.display.text||a("logs.detail.payload.emptyRequest")})},m.key))]})}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs(T,{variant:"outline",size:"sm",className:"h-[30px] flex-1",onClick:()=>{n&&b(n.title,n.value,n.copyToast)},children:[e.jsx(Xe,{className:"mr-1.5 h-3.5 w-3.5","aria-hidden":"true"}),a("logs.detail.inline.copyRequest")]}),S?e.jsx(T,{variant:"outline",size:"sm",className:"h-[30px] flex-1",onClick:()=>b(a("logs.detail.inline.copySession"),S,"logs.detail.inline.sessionCopied"),children:a("logs.detail.inline.copySession")}):null,e.jsx(T,{asChild:!0,variant:"outline",size:"sm",className:"h-[30px] flex-1",children:e.jsxs(mt,{to:"/providers?tab=routing",children:[a("logs.detail.inline.viewRule"),e.jsx(Yt,{className:"ml-1.5 h-3.5 w-3.5","aria-hidden":"true"})]})})]})]})]})}function Ms({record:t,providerLabelMap:l,apiKeyMap:i,onSelect:a,isExpanded:o,onToggleExpand:s,isEven:r,density:u,visibleColumnSet:x,costCurrency:f}){const{t:b}=H(),N=l.get(t.provider)??t.provider,j=t.endpoint||"—",v=Ee(t,b),g=t.client_model??b("logs.table.requestedModelFallback"),n=t.api_key_id!=null?i.get(t.api_key_id):void 0,w=t.api_key_id==null?b("logs.table.apiKeyUnknown"):n!=null&&n.isWildcard?b("apiKeys.wildcard"):n!=null&&n.name?n.name:t.api_key_name?t.api_key_name:b("logs.table.apiKeyUnknown"),h=u==="compact"?"px-1.5 py-1.5":"px-1.5 py-2",y=r?"bg-muted/30":"bg-background",p=dt(t.session_id),S=p==null?void 0:p.accentStyle,m=x.size+2,D=b(o?"logs.detail.inline.collapse":"logs.detail.inline.expand");return e.jsxs(e.Fragment,{children:[e.jsxs("tr",{"data-log-id":t.id,"data-session-id":p==null?void 0:p.sessionId,"data-session-color":p==null?void 0:p.colorKey,className:C("transition-colors duration-160 ease-surface",r?"bg-muted/30":"",o?"bg-muted/50":"hover:bg-muted/50"),children:[e.jsx("td",{className:C("sticky left-0 z-10 text-xs",h,y),style:S,children:e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("button",{type:"button","aria-expanded":o,"aria-label":D,onClick:()=>s(t.id),className:"-ml-0.5 inline-flex h-5 w-5 shrink-0 items-center justify-center rounded-sm text-muted-foreground transition-colors hover:bg-secondary hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",children:e.jsx(et,{className:C("h-3.5 w-3.5 transition-transform duration-160 ease-surface",o&&"rotate-90"),"aria-hidden":"true"})}),e.jsx("span",{"data-visual-volatile":"true",className:"metric-number whitespace-nowrap",title:Le(t.timestamp),children:gs(t.timestamp)})]})}),x.has("endpoint")&&e.jsx("td",{className:C(h,"text-xs"),children:e.jsx("div",{className:"max-w-[120px] truncate",title:j,children:j})}),x.has("provider")&&e.jsx("td",{className:C(h,"text-xs"),children:e.jsx("div",{className:"max-w-[100px] truncate",title:N,children:N})}),x.has("client")&&e.jsx("td",{className:C(h,"text-xs text-muted-foreground"),children:e.jsx("div",{className:"max-w-[110px] truncate",title:t.user_agent??t.client_kind??"",children:t.client_kind??"—"})}),x.has("requestedModel")&&e.jsx("td",{className:C(h,"text-xs text-muted-foreground"),children:e.jsx("div",{className:"max-w-[100px] truncate",title:g,children:g})}),x.has("routedModel")&&e.jsx("td",{className:C(h,"text-xs"),children:e.jsx("div",{className:"max-w-[100px] truncate",title:t.model,children:t.model})}),x.has("apiKey")&&e.jsx("td",{className:C(h,"text-xs text-muted-foreground"),children:e.jsx("div",{className:"max-w-[90px] truncate",title:w,children:w})}),x.has("tokens")&&e.jsx("td",{className:C(h,"text-right text-xs tabular-nums"),children:t.input_tokens==null&&t.output_tokens==null?e.jsx("span",{className:"whitespace-nowrap text-muted-foreground/70",children:b("logs.table.tokensNoUsage")}):e.jsxs("div",{className:"flex flex-col items-end gap-0.5",children:[e.jsxs("span",{"data-visual-volatile":"true",className:"whitespace-nowrap",children:[b("logs.table.columns.tokenInShort")," ",P(t.input_tokens),e.jsx("span",{className:"mx-1 text-muted-foreground/50",children:"·"}),b("logs.table.columns.tokenOutShort")," ",P(t.output_tokens)]}),e.jsxs("span",{"data-visual-volatile":"true",className:"whitespace-nowrap text-[10.5px] leading-tight text-muted-foreground",title:`${b("logs.table.columns.tokenCacheRead")} ${P(t.cache_read_tokens??t.cached_tokens)} · ${b("logs.table.columns.tokenCacheWrite")} ${P(t.cache_creation_tokens)}`,children:[b("logs.table.columns.tokenCacheReadShort")," ",P(t.cache_read_tokens??t.cached_tokens),e.jsx("span",{className:"mx-1 text-muted-foreground/40",children:"·"}),b("logs.table.columns.tokenCacheWriteShort")," ",P(t.cache_creation_tokens)]})]})}),x.has("cost")&&e.jsx("td",{className:C(h,"text-right text-xs tabular-nums align-top"),children:e.jsx("span",{className:"whitespace-nowrap",title:t.cost==null?b("logs.table.costUnpricedHint"):void 0,"data-testid":`log-cost-${t.id}`,children:ee(t.cost,f)})}),x.has("duration")&&e.jsx("td",{className:C(h,"text-right text-xs tabular-nums"),children:e.jsxs("div",{className:"flex flex-col items-end gap-0.5",children:[e.jsx("span",{"data-visual-volatile":"true",className:"whitespace-nowrap",children:W(t.latency_ms,"ms")}),e.jsxs("span",{"data-visual-volatile":"true",className:"whitespace-nowrap text-[10.5px] leading-tight text-muted-foreground",title:`${b("logs.table.columns.latencyTtft")} ${W(t.ttft_ms,"ms")} · ${b("logs.table.columns.latencyTpot")} ${W(t.tpot_ms,b("common.units.msPerToken"))}`,children:[b("logs.table.columns.latencyTtft")," ",P(t.ttft_ms),e.jsx("span",{className:"mx-1 text-muted-foreground/40",children:"·"}),b("logs.table.columns.latencyTpot")," ",P(t.tpot_ms)]})]})}),x.has("status")&&e.jsx("td",{className:C(h,"text-center"),children:e.jsx(te,{variant:v.variant,className:"text-xs",children:v.label})}),x.has("error")&&e.jsx("td",{className:C(h,"text-xs text-muted-foreground"),children:e.jsx("div",{className:"max-w-[60px] truncate",title:t.error??"",children:t.error?t.error:"—"})}),e.jsx("td",{className:C("sticky right-0 z-10 text-center",h,y),children:e.jsx(T,{variant:"outline",size:"sm",onClick:()=>a(t.id),children:b("logs.actions.detail")})})]}),o?e.jsx("tr",{"data-testid":`log-row-expanded-wrapper-${t.id}`,children:e.jsx("td",{colSpan:m,className:"border-t border-border bg-secondary/30 p-0",children:e.jsx("div",{className:"px-5 pb-5 pt-3",children:e.jsx(Ks,{logId:t.id,providerLabelMap:l,apiKeyMap:i})})})}):null]})}const V="whitespace-nowrap px-1.5 py-2.5 text-xs font-semibold text-muted-foreground";function Ps(t){const{t:l}=H(),{tableScrollRef:i,visibleColumnSet:a,visibleColumnCount:o,autoHiddenColumns:s,logsError:r,logsPending:u,items:x,costCurrency:f,activeFiltersCount:b,total:N,handleResetFilters:j,handleRetry:v,providerLabelMap:g,apiKeyMap:n,handleOpenDetail:w,expandedLogId:h,onToggleExpand:y,rowDensity:p,showScrollHint:S,pageSize:m,setPageSize:D,page:R,totalPages:M,setPage:_}=t,F=e.jsx(re,{compact:!0,tone:"danger",icon:e.jsx(Xt,{className:"h-5 w-5","aria-hidden":"true"}),title:l("logs.toast.listError.title"),description:r,action:e.jsxs("div",{className:"flex flex-wrap items-center justify-center gap-2",children:[e.jsx(T,{variant:"outline",size:"sm",onClick:v,children:l("common.actions.refresh")}),b>0?e.jsx(T,{variant:"ghost",size:"sm",onClick:j,children:l("common.actions.reset")}):null]})}),U=e.jsx(re,{compact:!0,tone:"primary",icon:e.jsx(Zt,{className:"h-5 w-5","aria-hidden":"true"}),title:b>0?l("logs.empty.filteredTitle"):l("logs.empty.title"),description:b>0?l("logs.empty.filteredSubtitle"):l("logs.empty.subtitle"),action:e.jsxs("div",{className:"flex flex-wrap items-center justify-center gap-2",children:[b>0?e.jsx(T,{variant:"outline",size:"sm",onClick:j,children:l("logs.empty.actions.reset")}):null,e.jsx(T,{asChild:!0,variant:"ghost",size:"sm",children:e.jsx(mt,{to:"/api-keys",children:l("logs.empty.actions.apiKeys")})})]})});return e.jsx(tt,{variant:"solid",className:"overflow-hidden bg-card shadow-[var(--surface-shadow)]",children:e.jsxs(st,{className:"p-0",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 bg-secondary/50 px-4 py-3 border-b border-border",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-sm font-semibold",children:l("logs.title")}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[e.jsx("span",{className:"metric-number",children:l("logs.summary.total",{value:N.toLocaleString()})}),e.jsx("span",{className:"mx-1.5 text-muted-foreground/50",children:"·"}),l("logs.table.visibleColumns",{count:o})]})]}),s.length>0||S?e.jsxs("div",{className:"hidden items-center gap-2 md:flex",children:[s.length>0?e.jsx(te,{variant:"outline",className:"bg-background text-muted-foreground",title:l("logs.table.autoHiddenHint",{columns:s.map(L=>l(`logs.table.columns.${L}`)).join(" · ")}),children:l("logs.table.autoHiddenColumns",{count:s.length})}):null,e.jsx(te,{variant:"outline",className:"bg-background text-muted-foreground",children:l(p==="compact"?"logs.table.density.compact":"logs.table.density.comfortable")})]}):null]}),e.jsxs("div",{className:"relative hidden md:block",children:[e.jsx("div",{ref:i,className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"border-b border-border/50 bg-secondary/50",children:e.jsxs("tr",{children:[e.jsx("th",{className:C(V,"sticky left-0 z-20 bg-secondary text-left"),children:l("logs.table.columns.time")}),a.has("endpoint")&&e.jsx("th",{className:C(V,"text-left"),children:l("logs.table.columns.endpoint")}),a.has("provider")&&e.jsx("th",{className:C(V,"text-left"),children:l("logs.table.columns.provider")}),a.has("client")&&e.jsx("th",{className:C(V,"text-left"),children:l("logs.table.columns.client")}),a.has("requestedModel")&&e.jsx("th",{className:C(V,"text-left"),children:l("logs.table.columns.requestedModel")}),a.has("routedModel")&&e.jsx("th",{className:C(V,"text-left"),children:l("logs.table.columns.routedModel")}),a.has("apiKey")&&e.jsx("th",{className:C(V,"text-left"),children:l("logs.table.columns.apiKey")}),a.has("tokens")&&e.jsx("th",{className:C(V,"text-right"),title:l("logs.table.tokensHeaderHint"),children:l("logs.table.columns.tokens")}),a.has("cost")&&e.jsx("th",{className:C(V,"text-right"),children:l("logs.table.columns.cost")}),a.has("duration")&&e.jsx("th",{className:C(V,"text-right"),title:l("logs.table.durationHeaderHint"),children:l("logs.table.columns.duration")}),a.has("status")&&e.jsx("th",{className:C(V,"text-center"),children:l("logs.table.columns.status")}),a.has("error")&&e.jsx("th",{className:C(V,"text-left"),children:l("logs.table.columns.error")}),e.jsx("th",{className:C(V,"sticky right-0 z-20 bg-secondary text-center"),children:l("logs.table.columns.actions")})]})}),e.jsx("tbody",{className:"divide-y divide-border/50",children:u?Array.from({length:8}).map((L,A)=>e.jsx(hs,{columns:o},A)):r&&x.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:o,className:"px-3 py-6",children:F})}):x.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:o,className:"px-3 py-8 text-center text-sm text-muted-foreground",children:U})}):x.map((L,A)=>e.jsx(Ms,{record:L,providerLabelMap:g,apiKeyMap:n,onSelect:w,isExpanded:L.id===h,onToggleExpand:y,isEven:A%2===0,density:p,visibleColumnSet:a,costCurrency:f},L.id))})]})}),S&&e.jsx("div",{className:"table-scroll-hint"})]}),e.jsx("div",{className:"md:hidden",children:u?e.jsx("div",{className:"space-y-3 p-4",children:Array.from({length:5}).map((L,A)=>e.jsx(ut,{className:"h-20 w-full"},A))}):r&&x.length===0?e.jsx("div",{className:"px-3 py-6",children:F}):x.length===0?e.jsx("div",{className:"px-3 py-8",children:U}):x.map(L=>e.jsx(Ts,{record:L,providerLabelMap:g,onSelect:w,costCurrency:f},L.id))}),e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-4 bg-secondary/50 p-4 border-t border-border",children:[e.jsxs("div",{className:"flex items-center gap-2 border border-border bg-secondary px-3 py-1.5",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:l("logs.table.pagination.perPage")}),e.jsxs(pe,{value:m.toString(),onValueChange:L=>D(Number(L)),children:[e.jsx(xe,{className:"h-8 w-[80px] bg-background",children:e.jsx(ge,{})}),e.jsx(he,{children:oe.map(L=>e.jsx(B,{value:L.toString(),children:L},L))})]})]}),e.jsxs("div",{className:"flex items-center gap-2 border border-border bg-secondary px-2 py-1.5",children:[e.jsxs(T,{variant:"outline",size:"sm",onClick:()=>_(L=>Math.max(L-1,1)),disabled:R<=1,children:[e.jsx(es,{className:"mr-1 h-4 w-4","aria-hidden":"true"}),l("logs.table.pagination.previous")]}),e.jsx("span",{className:"metric-number px-1 text-sm text-muted-foreground",children:l("logs.table.pagination.pageLabel",{page:M===0?0:R,total:M})}),e.jsxs(T,{variant:"outline",size:"sm",onClick:()=>_(L=>M===0?L:Math.min(L+1,M)),disabled:M===0||R>=M,children:[l("logs.table.pagination.next"),e.jsx(et,{className:"ml-1 h-4 w-4","aria-hidden":"true"})]})]})]})]})})}function As({exportTimeoutMs:t,queryParams:l,total:i}){const{t:a}=H(),{pushToast:o}=_e(),[s,r]=d.useState(!1),u=d.useCallback(async()=>{if(!s){r(!0);try{const x=i>0?Math.min(i,5e3):1e3,f={...l,limit:x,offset:0},b=await Re.exportArchive(f,t),N=new Date().toISOString().replace(/[:.]/g,"-"),j=URL.createObjectURL(b),v=document.createElement("a");v.href=j,v.download=`cc-gw-logs-${N}.zip`,document.body.appendChild(v),v.click(),v.remove(),URL.revokeObjectURL(j),o({title:a("logs.toast.exportSuccess.title"),description:a("logs.toast.exportSuccess.desc"),variant:"success"})}catch(x){const f=ls(x);o({title:a("logs.toast.exportError.title"),description:a("logs.toast.exportError.desc",{message:f.message}),variant:"error"})}finally{r(!1)}}},[t,s,o,l,a,i]);return{exporting:s,handleExport:u}}function Os(){const t=d.useRef(null),[l,i]=d.useState(!1),a=d.useCallback(()=>{const o=t.current;if(!o)return;const s=o.scrollWidth-o.scrollLeft-o.clientWidth>1;i(s)},[]);return d.useEffect(()=>{const o=t.current;if(!o)return;a(),o.addEventListener("scroll",a,{passive:!0});const s=new ResizeObserver(a);return s.observe(o),()=>{o.removeEventListener("scroll",a),s.disconnect()}},[a]),{scrollRef:t,showScrollHint:l,updateScrollHint:a}}const Ye=["error","client","apiKey","requestedModel","routedModel"],qs=[{below:1140,hidden:1},{below:1080,hidden:2},{below:1020,hidden:3},{below:960,hidden:4},{below:920,hidden:5}],zs=[];function Is(t){if(!Number.isFinite(t)||t<=0)return 0;let l=0;for(const i of qs)t<i.below&&(l=i.hidden);return l}function Vs(t,l){const{i18n:i}=H(),a=i.resolvedLanguage??i.language,[o,s]=d.useState(0),r=d.useRef(o);r.current=o;const u=d.useRef(0);d.useEffect(()=>{const N=t.current;if(!N)return;let j=0,v=0,g=r.current;u.current=-1;const n=()=>{if(j=0,v>0&&(v-=1,v>0)){w();return}const p=N.clientWidth;if(!Number.isFinite(p)||p<=0){g=0,r.current=0,u.current=p,s(0);return}const S=N.firstElementChild,m=!!(S!=null&&S.querySelector("tbody tr[data-log-id]")),D=Ye.filter(F=>l.includes(F)).length,R=Is(p),M=!!(S&&m&&S.scrollWidth>p+1),_=F=>F===g?!1:(g=F,r.current=F,s(F),v=2,w(),!0);Math.abs(p-u.current)>1&&(u.current=p,_(R))||M&&g<D&&_(g+1)},w=()=>{j===0&&(j=window.requestAnimationFrame(n))};n();const h=new ResizeObserver(w);h.observe(N);const y=N.firstElementChild;return y&&h.observe(y),window.addEventListener("resize",w),()=>{j!==0&&window.cancelAnimationFrame(j),h.disconnect(),window.removeEventListener("resize",w)}},[t,a,l]);const x=d.useMemo(()=>o===0?zs:Ye.filter(N=>l.includes(N)).slice(0,o),[o,l]),f=d.useMemo(()=>{if(x.length===0)return l;const N=new Set(x);return l.filter(j=>!N.has(j))},[x,l]),b=d.useMemo(()=>new Set(f),[f]);return{autoHiddenColumns:x,effectiveVisibleColumns:f,effectiveVisibleColumnSet:b,effectiveVisibleColumnCount:f.length+2}}const $s="cc-gw.logs.visible-columns-v2";function Hs(){if(typeof window>"u")return J;const t=window.localStorage.getItem($s);if(!t)return J;try{const l=JSON.parse(t);if(!Array.isArray(l))return J;const i=l.filter(a=>le.includes(a));return i.length===0?J:(i.includes("cost")||i.push("cost"),i.sort((a,o)=>le.indexOf(a)-le.indexOf(o)))}catch{return J}}function Us(){const[t,l]=$(O.logs.density,Ss,{serialize:N=>N,deserialize:N=>N==="compact"?"compact":"comfortable"}),[i,a]=$(O.logs.visibleColumns,Hs,{serialize:JSON.stringify,deserialize:N=>{try{const j=JSON.parse(N);if(!Array.isArray(j))return J;const v=j.filter(g=>le.includes(g));return v.length>0?v:J}catch{return J}}}),{scrollRef:o,showScrollHint:s}=Os(),r=Vs(o,i),u=d.useMemo(()=>new Set(i),[i]),x=i.length+2,f=d.useCallback(N=>{a(j=>{if(j.includes(N))return j.length===1?j:j.filter(g=>g!==N);const v=[...j,N];return v.sort((g,n)=>le.indexOf(g)-le.indexOf(n)),v})},[]),b=d.useCallback(()=>{a(J)},[]);return{autoHiddenColumns:r.autoHiddenColumns,effectiveVisibleColumns:r.effectiveVisibleColumns,effectiveVisibleColumnCount:r.effectiveVisibleColumnCount,effectiveVisibleColumnSet:r.effectiveVisibleColumnSet,resetVisibleColumns:b,rowDensity:t,setRowDensity:l,showScrollHint:s,tableScrollRef:o,toggleColumn:f,visibleColumnCount:x,visibleColumns:i,visibleColumnSet:u}}const Qs=3e3,Bs=200;function Ws(){var Pe,Ae,Oe,qe,ze,Ie;const{t}=H(),{pushToast:l}=_e(),i=Ns(),[a,o]=$(O.logs.providerFilter,"all"),[s,r]=$(O.logs.endpointFilter,"all"),[u,x]=$(O.logs.modelFilter,""),[f,b]=$(O.logs.clientKindFilter,"all"),[N,j]=$(O.logs.sessionFilter,""),[v,g]=$(O.logs.statusFilter,"all"),[n,w]=$(O.logs.fromDate,""),[h,y]=$(O.logs.toDate,""),[p,S]=d.useState(1),[m,D]=$(O.logs.autoRefresh,!0),[R,M]=$(O.logs.pageSize,_s,{serialize:c=>String(c),deserialize:c=>{const E=Number(c);return oe.includes(E)?E:oe[0]}}),[_,F]=d.useState(null),[U,L]=d.useState(!1),[A,k]=d.useState(null),[ie,gt]=d.useState(!1);d.useEffect(()=>{const c=document.querySelector('[data-testid="app-scroll"]'),E=()=>c?c.scrollTop:window.scrollY,K=()=>{gt(E()>=Bs)};K();const me=c??window;return me.addEventListener("scroll",K,{passive:!0}),()=>me.removeEventListener("scroll",K)},[]);const[q,ce]=$(O.logs.selectedApiKeys,[],{serialize:JSON.stringify,deserialize:c=>{try{const E=JSON.parse(c);return Array.isArray(E)?E.map(K=>Number(K)).filter(K=>Number.isInteger(K)&&K>0):[]}catch{return[]}}}),[ht,ft]=d.useState(()=>typeof window>"u"||window.matchMedia("(min-width: 768px)").matches),{resetVisibleColumns:bt,rowDensity:yt,setRowDensity:jt,showScrollHint:vt,tableScrollRef:Nt,toggleColumn:wt,visibleColumnCount:kt,visibleColumns:Ct,visibleColumnSet:St,autoHiddenColumns:_t,effectiveVisibleColumns:Et,effectiveVisibleColumnCount:Lt,effectiveVisibleColumnSet:Rt}=Us(),[G,Fe]=vs(),De=d.useRef(!1);d.useEffect(()=>{if(De.current)return;const c=["status","endpoint","provider","model","clientKind","session","from","to"];if(!c.some(Ce=>G.has(Ce)))return;De.current=!0,o("all"),r("all"),x(""),b("all"),j(""),g("all"),w(""),y(""),ce([]);const E=G.get("status");(E==="success"||E==="error")&&g(E);const K=G.get("endpoint");K&&r(K);const me=G.get("provider");me&&o(me);const Ve=G.get("model");Ve&&x(Ve);const $e=G.get("clientKind");$e&&b($e);const He=G.get("session");He&&j(He);const Ue=G.get("from");Ue&&w(Ue);const Qe=G.get("to");Qe&&y(Qe);const Be=new URLSearchParams(G);for(const Ce of c)Be.delete(Ce);Fe(Be,{replace:!0})},[G,b,r,w,x,o,Fe,ce,j,g,y]);const Ft=d.useDeferredValue(u),z=u===""?"":Ft,Dt=d.useDeferredValue(N),Y=N===""?"":Dt;d.useEffect(()=>{S(1),k(null)},[a,s,z,f,Y,v,n,h,R,q]);const ye=d.useMemo(()=>{const c={limit:R,offset:(p-1)*R};a!=="all"&&(c.provider=a),s!=="all"&&(c.endpoint=s),z.trim().length>0&&(c.model=z.trim()),f!=="all"&&(c.clientKind=f),Y.trim().length>0&&(c.session=Y.trim()),v!=="all"&&(c.status=v);const E=Ge(n),K=Ge(h,!0);return E!==void 0&&(c.from=E),K!==void 0&&(c.to=K),q.length>0&&(c.apiKeys=q.join(",")),c},[z,Y,f,s,n,p,R,a,q,v,h]),X=ne(se.logs.list(ye),Re.listRequest(ye),{gcTime:6e4,refetchInterval:m&&p===1&&A===null&&!U&&!ie?Qs:!1}),ae=ne(se.providers.all(),We.providersRequest()),Te=ne(se.apiKeys.all(),{url:"/api/keys",method:"GET"}),je=ne(se.customEndpoints.all(),{url:"/api/custom-endpoints",method:"GET"}),Ke=ne(se.config.exportTimeout(),We.configRequest());d.useEffect(()=>{!X.isError||!X.error||l({title:t("logs.toast.listError.title"),description:t("logs.toast.listError.desc",{message:X.error.message}),variant:"error"})},[X.error,X.isError,l,t]),d.useEffect(()=>{!ae.isError||!ae.error||l({title:t("logs.toast.providerError.title"),description:t("logs.toast.providerError.desc",{message:ae.error.message}),variant:"error"})},[ae.error,ae.isError,l,t]);const fe=((Pe=X.data)==null?void 0:Pe.total)??0,de=fe>0?Math.ceil(fe/R):0,Tt=((Ae=X.data)==null?void 0:Ae.items)??[],Kt=(Oe=X.data)==null?void 0:Oe.cost_currency,Mt=d.useMemo(()=>{var E;const c=(E=Ke.data)==null?void 0:E.logExportTimeoutSeconds;return typeof c=="number"&&Number.isFinite(c)?Math.min(Math.max(Math.round(c),5),600)*1e3:6e4},[(qe=Ke.data)==null?void 0:qe.logExportTimeoutSeconds]);d.useEffect(()=>{de>0&&p>de&&S(de)},[p,de]);const ve=ae.data??[],Ne=d.useMemo(()=>{const c=new Map;for(const E of ve)E.id&&c.set(E.id,E.label??E.id);return c},[ve]),Me=d.useMemo(()=>{var E;const c=new Map;c.set("anthropic",t("logs.filters.endpointAnthropic")),c.set("openai",t("logs.filters.endpointOpenAI"));for(const K of((E=je.data)==null?void 0:E.endpoints)??[])c.set(K.id,K.label||K.id);return c},[(ze=je.data)==null?void 0:ze.endpoints,t]),Pt=d.useMemo(()=>{const c=[];if(a!=="all"){const E=Ne.get(a)??a;c.push({key:"provider",label:`${t("logs.filters.provider")}: ${E}`,onRemove:()=>o("all")})}if(s!=="all"){const E=Me.get(s)??s;c.push({key:"endpoint",label:`${t("logs.filters.endpoint")}: ${E}`,onRemove:()=>r("all")})}if(z.trim()&&c.push({key:"model",label:`${t("logs.filters.modelId")}: ${z.trim()}`,onRemove:()=>x("")}),f!=="all"&&c.push({key:"clientKind",label:`${t("logs.filters.clientKind")}: ${t(`dashboard.usage.clientKinds.${f}`,{defaultValue:f})}`,onRemove:()=>b("all")}),Y.trim()&&c.push({key:"session",label:`${t("logs.filters.session")}: ${Y.trim()}`,onRemove:()=>j("")}),v!=="all"){const E=t(v==="success"?"logs.filters.statusSuccess":"logs.filters.statusError");c.push({key:"status",label:`${t("logs.filters.status")}: ${E}`,onRemove:()=>g("all")})}return n&&c.push({key:"from",label:`${t("logs.filters.startDate")}: ${n}`,onRemove:()=>w("")}),h&&c.push({key:"to",label:`${t("logs.filters.endDate")}: ${h}`,onRemove:()=>y("")}),q.length>0&&c.push({key:"apiKeys",label:t("logs.filters.apiKeySelected",{count:q.length}),onRemove:()=>ce([])}),c},[z,Y,f,s,Me,n,a,Ne,q.length,v,t,h]),we=Te.data??[],At=d.useMemo(()=>{const c=new Map;for(const E of we)c.set(E.id,E);return c},[we]),Ot=d.useMemo(()=>le.map(c=>({id:c,label:t(`logs.table.columns.${c}`)})),[t]),ue=d.useMemo(()=>{const c=new Date;return`${c.getFullYear()}-${String(c.getMonth()+1).padStart(2,"0")}-${String(c.getDate()).padStart(2,"0")}`},[]),qt=d.useMemo(()=>f!=="all"||Y.trim()!==""?null:a==="all"&&s==="all"&&z.trim()===""&&v==="all"&&n===""&&h===""&&q.length===0?"all":v==="error"&&s==="all"&&a==="all"&&z.trim()===""&&n===""&&h===""&&q.length===0?"errors":Es(n,h,ue)&&s==="all"&&a==="all"&&z.trim()===""&&v==="all"&&q.length===0?"today":s==="anthropic"&&a==="all"&&z.trim()===""&&v==="all"&&n===""&&h===""&&q.length===0?"anthropic":s==="openai"&&a==="all"&&z.trim()===""&&v==="all"&&n===""&&h===""&&q.length===0?"openai":null,[z,Y,f,s,n,a,q.length,v,h,ue]),ke=d.useCallback(()=>{o("all"),x(""),b("all"),j(""),r("all"),g("all"),w(""),y(""),ce([])},[]),zt=d.useCallback(c=>{if(S(1),ke(),c!=="all"){if(c==="errors"){g("error");return}if(c==="today"){w(ue),y(ue);return}if(c==="anthropic"){r("anthropic");return}c==="openai"&&r("openai")}},[ke,ue]),{exporting:It,handleExport:Vt}=As({exportTimeoutMs:Mt,queryParams:ye,total:fe}),$t=d.useCallback(c=>{i.removeQueries({queryKey:["logs","detail"],type:"inactive"}),F(c),L(!0)},[i]),Ht=d.useCallback(()=>{L(!1)},[]),Ut=d.useCallback(c=>{k(E=>E===c?null:c)},[]);return d.useEffect(()=>{U||_===null||(i.removeQueries({queryKey:se.logs.detail(_),exact:!0}),F(null))},[U,i,_]),{activeFilters:Pt,activeQuickView:qt,apiKeyMap:At,apiKeys:we,apiKeysQuery:Te,applyQuickView:zt,autoRefresh:m,clientKindFilter:f,columnOptions:Ot,customEndpoints:(Ie=je.data)==null?void 0:Ie.endpoints,endpointFilter:s,exporting:It,expandedLogId:A,filtersExpanded:ht,fromDate:n,handleCloseDetail:Ht,handleExport:Vt,handleOpenDetail:$t,handleResetFilters:ke,handleToggleExpand:Ut,isDetailOpen:U,items:Tt,costCurrency:Kt,logsQuery:X,modelFilter:u,page:p,pageSize:R,providerFilter:a,providerLabelMap:Ne,providerOptions:ve,rowDensity:yt,resetVisibleColumns:bt,selectedApiKeys:q,selectedLogId:_,sessionFilter:N,setAutoRefresh:D,setClientKindFilter:b,setEndpointFilter:r,setFiltersExpanded:ft,setFromDate:w,setModelFilter:x,setPage:S,setPageSize:M,setProviderFilter:o,setRowDensity:jt,setSelectedApiKeys:ce,setSessionFilter:j,setStatusFilter:g,setToDate:y,showScrollHint:vt,statusFilter:v,tableScrollRef:Nt,toDate:h,toggleColumn:wt,total:fe,totalPages:de,autoHiddenColumns:_t,effectiveVisibleColumns:Et,effectiveVisibleColumnCount:Lt,effectiveVisibleColumnSet:Rt,visibleColumnCount:kt,visibleColumns:Ct,visibleColumnSet:St}}function gl(){var l;const t=Ws();return e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsx(ts,{actions:e.jsx(Ds,{autoRefresh:t.autoRefresh,columnOptions:t.columnOptions,exporting:t.exporting,onExport:()=>void t.handleExport(),onRefresh:()=>void t.logsQuery.refetch(),onResetColumns:t.resetVisibleColumns,onSetDensity:t.setRowDensity,onToggleAutoRefresh:t.setAutoRefresh,onToggleColumn:t.toggleColumn,refreshing:t.logsQuery.isFetching,rowDensity:t.rowDensity,visibleColumns:t.visibleColumns,visibleColumnSet:t.visibleColumnSet,autoHiddenColumns:t.autoHiddenColumns})}),e.jsx(Ls,{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,clientKindFilter:t.clientKindFilter,setClientKindFilter:t.setClientKindFilter,sessionFilter:t.sessionFilter,setSessionFilter:t.setSessionFilter,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(Ps,{tableScrollRef:t.tableScrollRef,visibleColumnSet:t.effectiveVisibleColumnSet,visibleColumnCount:t.effectiveVisibleColumnCount,autoHiddenColumns:t.autoHiddenColumns,logsError:t.logsQuery.isError?((l=t.logsQuery.error)==null?void 0:l.message)??null:null,logsPending:t.logsQuery.isPending,items:t.items,costCurrency:t.costCurrency,activeFiltersCount:t.activeFilters.length,total:t.total,handleResetFilters:t.handleResetFilters,handleRetry:()=>void t.logsQuery.refetch(),providerLabelMap:t.providerLabelMap,apiKeyMap:t.apiKeyMap,handleOpenDetail:t.handleOpenDetail,expandedLogId:t.expandedLogId,onToggleExpand:t.handleToggleExpand,rowDensity:t.rowDensity,showScrollHint:t.showScrollHint,pageSize:t.pageSize,setPageSize:t.setPageSize,page:t.page,totalPages:t.totalPages,setPage:t.setPage}),e.jsx(Rs,{open:t.isDetailOpen,logId:t.selectedLogId,onClose:t.handleCloseDetail,providerLabelMap:t.providerLabelMap,apiKeyMap:t.apiKeyMap})]})}export{gl as default};
@@ -0,0 +1 @@
1
+ import{j as s}from"./vendor-C-lQMZp3.js";import{j as d}from"./app-DZpd2fu9.js";import{c as l}from"./global-BCYo_xAt.js";function p({title:a,description:e,eyebrow:t,actions:r,className:x,contentClassName:n,children:c}){const m=a||e||t||r;return s.jsxs("div",{className:l(d({variant:"default"}),x),children:[m&&s.jsxs("div",{className:"flex flex-col gap-4 p-6 pb-0 sm:flex-row sm:items-start sm:justify-between",children:[s.jsxs("div",{className:"min-w-0 space-y-1.5",children:[t?s.jsx("div",{className:"text-[11px] font-semibold uppercase tracking-[0.16em] text-primary/80",children:t}):null,typeof a=="string"?s.jsx("h2",{className:"text-base font-semibold text-foreground",children:a}):a,e&&(typeof e=="string"?s.jsx("p",{className:"text-sm text-muted-foreground/70",children:e}):s.jsx("div",{className:"text-sm text-muted-foreground/70",children:e}))]}),r&&s.jsx("div",{className:"w-full shrink-0 sm:w-auto",children:r})]}),s.jsx("div",{className:l("p-6",!m&&"pt-6",n),children:c})]})}export{p as P};
@@ -0,0 +1 @@
1
+ import{j as e,T as u}from"./vendor-C-lQMZp3.js";import{c as n}from"./global-BCYo_xAt.js";const x={default:"border-border/30 bg-card",primary:"border-foreground/10 bg-card",danger:"border-destructive/15 bg-card"},c={default:"bg-secondary text-muted-foreground",primary:"bg-secondary text-foreground",danger:"bg-destructive/10 text-destructive"};function o({icon:r,title:t,description:s,action:a,className:l,compact:i=!1,inline:m=!1,tone:d="default"}){return m?e.jsxs("div",{className:n("flex flex-wrap items-center justify-center gap-x-2.5 gap-y-1.5 rounded-lg border border-dashed px-4 py-3 text-center",x[d],l),children:[r?e.jsx("span",{className:n("flex h-6 w-6 shrink-0 items-center justify-center rounded-md",c[d]),children:r}):null,e.jsx("span",{className:"text-sm font-medium text-foreground",children:t}),s?e.jsx("span",{className:"text-sm text-muted-foreground",children:s}):null,a?e.jsx("span",{className:"flex flex-wrap items-center gap-2",children:a}):null]}):e.jsxs("div",{className:n("flex flex-col items-center justify-center rounded-xl border-2 border-dashed px-6 text-center",i?"min-h-[180px] py-8":"min-h-[260px] py-12",x[d],l),children:[r?e.jsx("div",{className:n("mb-4 flex h-12 w-12 items-center justify-center rounded-2xl",c[d]),children:r}):null,e.jsxs("div",{className:"max-w-xl space-y-1.5",children:[e.jsx("div",{className:"text-base font-semibold tracking-[-0.01em]",children:t}),s?e.jsx("div",{className:"text-sm text-muted-foreground",children:s}):null]}),a?e.jsx("div",{className:"mt-5 flex flex-wrap items-center justify-center gap-2",children:a}):null]})}function g({label:r,className:t,compact:s=!1}){return e.jsx(o,{className:t,compact:s,tone:"primary",icon:e.jsx(u,{className:"h-5 w-5 animate-spin","aria-hidden":"true"}),title:r})}export{g as P,o as a};
@@ -0,0 +1 @@
1
+ import{r as x,j as r}from"./vendor-C-lQMZp3.js";import{c as d}from"./global-BCYo_xAt.js";import{o as u}from"./app-DZpd2fu9.js";import{u as f}from"./i18n-ClvfZhYc.js";import{b as p}from"./router-Bkbjq53m.js";function g(){var s;const{t:l}=f(),i=p(),e=(s=u(i.pathname))==null?void 0:s.nav,t=e?l(e.titleKey??e.labelKey):"";return x.useEffect(()=>{document.title=t?`${t} · cc-gw`:"cc-gw"},[t]),{title:t,description:e!=null&&e.descriptionKey?l(e.descriptionKey):""}}function y({title:l,description:i,info:e,status:t,actions:s,className:m}){const c=g(),n=l??c.title,o=i??c.description,a=t||e;return!n&&!a&&!s?null:r.jsxs("div",{className:d("flex flex-col gap-3",m),children:[(n||s)&&r.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-end sm:justify-between",children:[r.jsxs("div",{className:"min-w-0 space-y-1",children:[n?r.jsx("h1",{className:"truncate text-xl text-foreground",children:n}):null,o?r.jsx("p",{className:"text-sm leading-6 text-muted-foreground",children:o}):null]}),s?r.jsx("div",{className:"flex shrink-0 flex-wrap items-center gap-2",children:s}):null]}),a?r.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-2 text-xs text-muted-foreground",children:[t,e]}):null]})}export{y as P};