@chenpu17/cc-gw 0.8.13 → 0.8.14

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 (54) hide show
  1. package/package.json +5 -5
  2. package/src/web/dist/assets/{About-BtrUwqVl.js → About-pcECYYVj.js} +1 -1
  3. package/src/web/dist/assets/{ApiKeys-BgtU9Z5t.js → ApiKeys-IDt4ZfLj.js} +1 -1
  4. package/src/web/dist/assets/{ConfirmDialog-BHrsB4gR.js → ConfirmDialog-oYHVEpGJ.js} +1 -1
  5. package/src/web/dist/assets/{Dashboard-DIguazuF.js → Dashboard-BiCTswfM.js} +1 -1
  6. package/src/web/dist/assets/{DialogShell-DcG-SXEV.js → DialogShell-DcOGCV8m.js} +1 -1
  7. package/src/web/dist/assets/{Events-mZNIWc7c.js → Events-CCYCOF1f.js} +1 -1
  8. package/src/web/dist/assets/{Help-BHbnZJeo.js → Help-BW1R1cf1.js} +2 -2
  9. package/src/web/dist/assets/{Login-DugtPFxy.js → Login-Dn8fbfFq.js} +1 -1
  10. package/src/web/dist/assets/{Logs-BJBm-efJ.js → Logs-D2FFPpBP.js} +1 -1
  11. package/src/web/dist/assets/{ModelManagement-C32W7nDe.js → ModelManagement-BHSUJ4Dg.js} +1 -1
  12. package/src/web/dist/assets/{PageHeader--Lg_YQVw.js → PageHeader-DCqHI67a.js} +1 -1
  13. package/src/web/dist/assets/{PageSection-DIAhP18t.js → PageSection-CuZMzA0E.js} +1 -1
  14. package/src/web/dist/assets/{PageState-DKba6Ew1.js → PageState-B03H5AV0.js} +1 -1
  15. package/src/web/dist/assets/{Profiler-DTPqRwx7.js → Profiler-CEpu2dMu.js} +1 -1
  16. package/src/web/dist/assets/{RoutingManagement-B9Z0l4LZ.js → RoutingManagement-DahJxjA7.js} +1 -1
  17. package/src/web/dist/assets/{Settings-Ddx0C5eQ.js → Settings-Vp7jGxIW.js} +1 -1
  18. package/src/web/dist/assets/{Skeleton-cyuMRxwQ.js → Skeleton-i1PjWApN.js} +1 -1
  19. package/src/web/dist/assets/{app-BG16DmZH.js → app-COiQeF3y.js} +3 -3
  20. package/src/web/dist/assets/{card-CwTuH2Iq.js → card-ChFVaqLf.js} +1 -1
  21. package/src/web/dist/assets/{charts-core-D9OugzV_.js → charts-core-DzWzxST6.js} +1 -1
  22. package/src/web/dist/assets/{charts-engine-DleyglMn.js → charts-engine-Ds7lwC51.js} +1 -1
  23. package/src/web/dist/assets/{charts-react-BqhUp1x_.js → charts-react-D0nWbUCA.js} +1 -1
  24. package/src/web/dist/assets/{gateway-CExOTXeI.js → gateway-BU3dR2tm.js} +1 -1
  25. package/src/web/dist/assets/{global-CKvMKvrn.js → global-B-NXh5qD.js} +1 -1
  26. package/src/web/dist/assets/global-B_hBylxt.css +1 -0
  27. package/src/web/dist/assets/{i18n-B3N4Df3E.js → i18n-Bl2BcCDG.js} +1 -1
  28. package/src/web/dist/assets/{input-scp9nKJc.js → input-DW7jGTgj.js} +1 -1
  29. package/src/web/dist/assets/{label-fMXEnAEx.js → label-Ci1io7XA.js} +1 -1
  30. package/src/web/dist/assets/landing-BMe5-cHU.js +17 -0
  31. package/src/web/dist/assets/live-en-api-keys-Bx8N-eoh.png +0 -0
  32. package/src/web/dist/assets/live-en-dashboard-CJoX7IQT.png +0 -0
  33. package/src/web/dist/assets/live-en-events-DJwaP-WW.png +0 -0
  34. package/src/web/dist/assets/live-en-logs-BGGL53ab.png +0 -0
  35. package/src/web/dist/assets/live-en-model-management-BpjNblfR.png +0 -0
  36. package/src/web/dist/assets/package-D5lk1iqk.js +1 -0
  37. package/src/web/dist/assets/{popover-BGSWKBlu.js → popover-CQHCVE2z.js} +1 -1
  38. package/src/web/dist/assets/{query-Cpxr1dul.js → query-BbGWgOFk.js} +1 -1
  39. package/src/web/dist/assets/{queryKeys-DTnZc8Yy.js → queryKeys-ucXCzh0P.js} +1 -1
  40. package/src/web/dist/assets/{radix-bG5h1Ymq.js → radix-mHySgtou.js} +1 -1
  41. package/src/web/dist/assets/{router-DspBTS8b.js → router-CL3rf_uf.js} +1 -1
  42. package/src/web/dist/assets/{select-BjYpeVvo.js → select-BchX45jJ.js} +1 -1
  43. package/src/web/dist/assets/{switch-CgwYcn5P.js → switch-CT24uL_Q.js} +1 -1
  44. package/src/web/dist/assets/{table-BtnjYcvG.js → table-DdvG93mx.js} +1 -1
  45. package/src/web/dist/assets/{useApiQuery-jSeDDFuv.js → useApiQuery-tbd4JJaZ.js} +1 -1
  46. package/src/web/dist/assets/{useAppMutation-ChCrgiP6.js → useAppMutation-SONU2xFC.js} +1 -1
  47. package/src/web/dist/assets/useModelManagementState-DcQ0Ac-x.js +1 -0
  48. package/src/web/dist/assets/{vendor-LWJeAdU1.js → vendor-z22RpOY0.js} +86 -66
  49. package/src/web/dist/index.html +8 -8
  50. package/src/web/dist/landing.html +11 -11
  51. package/src/web/dist/assets/global-CUpRxoFd.css +0 -1
  52. package/src/web/dist/assets/landing-CHY6qfgq.js +0 -5
  53. package/src/web/dist/assets/package-BMIMFcQR.js +0 -1
  54. package/src/web/dist/assets/useModelManagementState-9RhvWh8Y.js +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chenpu17/cc-gw",
3
- "version": "0.8.13",
3
+ "version": "0.8.14",
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.8.13",
38
- "@chenpu17/cc-gw-linux-arm64": "0.8.13",
39
- "@chenpu17/cc-gw-linux-x64": "0.8.13",
40
- "@chenpu17/cc-gw-win32-x64": "0.8.13"
37
+ "@chenpu17/cc-gw-darwin-arm64": "0.8.14",
38
+ "@chenpu17/cc-gw-linux-arm64": "0.8.14",
39
+ "@chenpu17/cc-gw-linux-x64": "0.8.14",
40
+ "@chenpu17/cc-gw-win32-x64": "0.8.14"
41
41
  },
42
42
  "dependencies": {
43
43
  "colorette": "^2.0.20",
@@ -1 +1 @@
1
- import{r as n,j as e,aj as _,aM as R,aN as m,at as B,Y as q}from"./vendor-LWJeAdU1.js";import{P as M}from"./PageHeader--Lg_YQVw.js";import{P as p}from"./PageSection-DIAhP18t.js";import{P as F,a as C}from"./PageState-DKba6Ew1.js";import{u as G}from"./useAppMutation-ChCrgiP6.js";import{u as I}from"./useApiQuery-jSeDDFuv.js";import{u as D,B as x,r as $}from"./app-BG16DmZH.js";import{B as P,q as z}from"./queryKeys-DTnZc8Yy.js";import{C as d,a as c}from"./card-CwTuH2Iq.js";import{p as J}from"./package-BMIMFcQR.js";import{u as Q}from"./i18n-B3N4Df3E.js";import"./global-CKvMKvrn.js";import"./query-Cpxr1dul.js";import"./router-DspBTS8b.js";import"./radix-bG5h1Ymq.js";function ne(){var h,f,g,v,j,N,w,y,k,S;const{t:a}=Q(),{pushToast:r}=D(),[i,L]=n.useState(null),t=I(z.status.gateway(),{url:"/api/status",method:"GET"},{staleTime:6e4});n.useEffect(()=>{t.isError&&t.error&&r({title:a("about.toast.statusError.title"),description:t.error.message,variant:"error"})},[r,t.error,t.isError,a]);const o=G({mutationFn:async()=>$({url:"/api/version/check",method:"GET"}),successToast:s=>s.updateAvailable?{title:a("about.toast.updateAvailable.title",{version:s.latestVersion}),description:a("about.toast.updateAvailable.description",{packageName:s.packageName})}:{title:a("about.toast.upToDate.title",{version:s.currentVersion}),description:a("about.toast.upToDate.description")},errorToast:s=>({title:a("about.toast.updateError.title"),description:s.message}),onSuccess:async s=>{L(s)}}),l=J.version,u="2026-04-20T13:11:57.730Z",V=n.useMemo(()=>{var s,T;return[{label:a("about.app.labels.name"),value:e.jsx("span",{className:"font-mono",children:"cc-gw"})},{label:a("about.app.labels.version"),value:e.jsxs("span",{"data-visual-volatile":"true",className:"font-mono text-primary",children:["v",l]})},{label:a("about.app.labels.buildTime"),value:e.jsx("span",{"data-visual-volatile":"true",children:u}),hint:a("about.app.hint.buildTime")},{label:a("about.app.labels.runtime"),value:e.jsx("span",{className:"font-mono",children:((s=t.data)==null?void 0:s.runtime)??"rust"})},{label:a("about.app.labels.backendVersion"),value:e.jsx("span",{"data-visual-volatile":"true",className:"font-mono",children:((T=t.data)==null?void 0:T.backendVersion)??"-"})}]},[l,u,(h=t.data)==null?void 0:h.backendVersion,(f=t.data)==null?void 0:f.runtime,a]),b=n.useMemo(()=>{var s;return t.data?[{label:a("about.status.labels.host"),value:t.data.host??"127.0.0.1"},{label:a("about.status.labels.port"),value:e.jsx("span",{"data-visual-volatile":"true",children:t.data.port.toLocaleString()})},{label:a("about.status.labels.providers"),value:t.data.providers.toLocaleString()},{label:a("about.status.labels.active"),value:(t.data.activeRequests??0).toLocaleString(),hint:a("about.status.hint.active")},{label:a("about.status.labels.platform"),value:t.data.platform??"-"},{label:a("about.status.labels.pid"),value:e.jsx("span",{"data-visual-volatile":"true",children:((s=t.data.pid)==null?void 0:s.toLocaleString())??"-"})}]:[]},[t.data,a]);return e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx(M,{icon:e.jsx(R,{className:"h-5 w-5","aria-hidden":"true"}),title:a("about.title"),description:a("about.description"),badge:e.jsxs("span",{"data-visual-volatile":"true",children:["v",l]}),eyebrow:"Runtime",breadcrumb:"Gateway / About",helper:a("about.support.description"),actions:e.jsxs("div",{className:"flex w-full flex-col gap-2 sm:w-auto sm:flex-row sm:flex-wrap sm:justify-end",children:[e.jsx("div",{className:"rounded-lg bg-secondary px-3 py-1.5 text-xs font-semibold text-muted-foreground",children:"manual refresh only"}),e.jsxs(x,{onClick:()=>o.mutate(),disabled:o.isPending,className:"w-full sm:w-auto",children:[e.jsx(_,{className:`mr-2 h-4 w-4${o.isPending?" animate-spin":""}`,"aria-hidden":"true"}),o.isPending?a("about.support.actions.checkingUpdates"):a("about.support.actions.checkUpdates")]})]})}),e.jsxs("div",{className:"grid gap-4 xl:grid-cols-[minmax(0,1.35fr)_minmax(320px,0.85fr)]",children:[e.jsx(d,{className:"overflow-hidden rounded-[1.25rem] border border-white/70 bg-card/95 shadow-[0_20px_50px_-42px_rgba(15,23,42,0.24)]",children:e.jsx(c,{className:"p-5",children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"inline-flex items-center gap-2 rounded-full bg-secondary px-3 py-1 text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:[e.jsx(m,{className:"h-3.5 w-3.5","aria-hidden":"true"}),"Runtime snapshot"]}),e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-end sm:justify-between",children:[e.jsxs("div",{className:"min-w-0 space-y-1",children:[e.jsxs("p",{"data-visual-volatile":"true",className:"metric-number truncate text-4xl font-semibold tracking-tight text-foreground",children:[((g=t.data)==null?void 0:g.host)??"127.0.0.1",":",((v=t.data)==null?void 0:v.port)??"-"]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:a("about.description")})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 text-xs sm:w-56",children:[e.jsx(A,{label:a("about.status.labels.providers"),value:((N=(j=t.data)==null?void 0:j.providers)==null?void 0:N.toLocaleString())??"-"}),e.jsx(A,{label:a("about.status.labels.active"),value:(((w=t.data)==null?void 0:w.activeRequests)??0).toLocaleString()})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(P,{variant:"outline",children:((y=t.data)==null?void 0:y.runtime)??"rust"}),e.jsx(P,{variant:"outline",children:((k=t.data)==null?void 0:k.platform)??"-"})]})]})})}),e.jsx(d,{className:"overflow-hidden rounded-[1.25rem] border border-white/70 bg-card/95 shadow-[0_20px_50px_-42px_rgba(15,23,42,0.24)]",children:e.jsx(c,{className:"p-5",children:e.jsxs("div",{className:"space-y-3",children:[e.jsx("p",{className:"text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:"Build"}),e.jsxs("div",{className:"flex flex-wrap items-baseline justify-between gap-2",children:[e.jsxs("p",{"data-visual-volatile":"true",className:"font-mono text-xl font-semibold text-primary",children:["v",l]}),e.jsx("p",{"data-visual-volatile":"true",className:"text-xs text-muted-foreground",children:u})]}),i?e.jsxs("div",{className:"rounded-lg bg-secondary px-4 py-3 text-sm text-muted-foreground",children:[e.jsx("p",{className:"font-medium text-foreground",children:i.updateAvailable?a("about.update.available",{version:i.latestVersion}):a("about.update.current",{version:i.currentVersion})}),e.jsxs("p",{className:"mt-1",children:[a("about.update.channel",{channel:i.channel}),i.publishedAt?` · ${new Date(i.publishedAt).toLocaleString()}`:""]})]}):null,e.jsx("div",{className:"rounded-[0.95rem] bg-secondary/65 px-3.5 py-3 text-sm text-muted-foreground",children:a("about.support.tip")})]})})})]}),e.jsxs("div",{className:"grid gap-6 lg:grid-cols-2",children:[e.jsx(p,{title:a("about.app.title"),description:a("about.app.subtitle"),children:e.jsx(E,{items:V})}),e.jsx(p,{title:a("about.status.title"),description:a("about.status.subtitle"),actions:e.jsxs(x,{variant:"outline",size:"sm",onClick:()=>void t.refetch(),disabled:t.isFetching,children:[e.jsx(B,{className:U(t.isFetching),"aria-hidden":"true"}),t.isFetching?a("common.actions.refreshing"):a("common.actions.refresh")]}),children:t.isLoading?e.jsx(F,{compact:!0,label:a("about.status.loading")}):t.isError?e.jsx(C,{compact:!0,tone:"danger",icon:e.jsx(m,{className:"h-5 w-5","aria-hidden":"true"}),title:a("common.status.error"),description:((S=t.error)==null?void 0:S.message)??a("common.unknownError"),action:e.jsx(x,{variant:"outline",size:"sm",onClick:()=>void t.refetch(),children:a("common.actions.refresh")})}):b.length>0?e.jsx(E,{items:b}):e.jsx(C,{compact:!0,tone:"primary",icon:e.jsx(m,{className:"h-5 w-5","aria-hidden":"true"}),title:a("about.status.empty"),description:a("common.actions.refresh")})})]}),e.jsx(p,{title:a("about.support.title"),description:e.jsxs("span",{className:"space-y-1",children:[e.jsx("span",{className:"block text-sm font-medium text-primary",children:a("about.support.subtitle")}),e.jsx("span",{children:a("about.support.description")})]}),children:e.jsx(d,{className:"rounded-xl bg-card shadow-[var(--surface-shadow)]",children:e.jsxs(c,{className:"flex flex-col gap-4 pt-5 md:flex-row md:items-start md:justify-between",children:[e.jsxs("div",{className:"flex items-start gap-4 rounded-lg bg-secondary p-4",children:[e.jsx("div",{className:"flex h-11 w-11 items-center justify-center rounded-xl bg-primary/10 text-primary",children:e.jsx(q,{className:"h-5 w-5","aria-hidden":"true"})}),e.jsx("p",{className:"max-w-2xl text-sm text-muted-foreground",children:a("about.support.tip")})]}),e.jsx("code",{className:"inline-flex self-start rounded-lg bg-secondary px-3 py-2 text-xs font-medium",children:"~/.cc-gw/config.json"})]})})})]})}function E({items:a}){return a.length===0?null:e.jsx("dl",{className:"grid gap-3 sm:grid-cols-2",children:a.map(r=>e.jsx(d,{className:"rounded-[1rem] border border-white/70 bg-secondary/45 shadow-none",children:e.jsxs(c,{className:"p-4",children:[e.jsx("dt",{className:"text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:r.label}),e.jsx("dd",{className:"metric-number mt-2 text-sm font-semibold text-foreground",children:r.value}),r.hint?e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:r.hint}):null]})},r.label))})}function A({label:a,value:r}){return e.jsxs("div",{className:"rounded-[0.9rem] bg-secondary/65 px-3 py-2 text-right",children:[e.jsx("p",{className:"text-[10px] font-semibold uppercase tracking-[0.16em] text-muted-foreground",children:a}),e.jsx("p",{className:"metric-number mt-1 text-sm font-semibold text-foreground",children:r})]})}function U(a){return`mr-2 h-4 w-4${a?" animate-spin":""}`}export{ne as default};
1
+ import{r as n,j as e,ap as _,aQ as R,aR as m,ax as B,Y as q}from"./vendor-z22RpOY0.js";import{P as F}from"./PageHeader-DCqHI67a.js";import{P as p}from"./PageSection-CuZMzA0E.js";import{P as G,a as C}from"./PageState-B03H5AV0.js";import{u as I}from"./useAppMutation-SONU2xFC.js";import{u as M}from"./useApiQuery-tbd4JJaZ.js";import{u as D,B as x,r as Q}from"./app-COiQeF3y.js";import{B as P,q as $}from"./queryKeys-ucXCzh0P.js";import{C as d,a as c}from"./card-ChFVaqLf.js";import{p as z}from"./package-D5lk1iqk.js";import{u as J}from"./i18n-Bl2BcCDG.js";import"./global-B-NXh5qD.js";import"./query-BbGWgOFk.js";import"./router-CL3rf_uf.js";import"./radix-mHySgtou.js";function ne(){var h,f,g,v,j,N,w,y,k,S;const{t:a}=J(),{pushToast:r}=D(),[i,L]=n.useState(null),t=M($.status.gateway(),{url:"/api/status",method:"GET"},{staleTime:6e4});n.useEffect(()=>{t.isError&&t.error&&r({title:a("about.toast.statusError.title"),description:t.error.message,variant:"error"})},[r,t.error,t.isError,a]);const o=I({mutationFn:async()=>Q({url:"/api/version/check",method:"GET"}),successToast:s=>s.updateAvailable?{title:a("about.toast.updateAvailable.title",{version:s.latestVersion}),description:a("about.toast.updateAvailable.description",{packageName:s.packageName})}:{title:a("about.toast.upToDate.title",{version:s.currentVersion}),description:a("about.toast.upToDate.description")},errorToast:s=>({title:a("about.toast.updateError.title"),description:s.message}),onSuccess:async s=>{L(s)}}),l=z.version,u="2026-04-25T08:15:57.406Z",V=n.useMemo(()=>{var s,T;return[{label:a("about.app.labels.name"),value:e.jsx("span",{className:"font-mono",children:"cc-gw"})},{label:a("about.app.labels.version"),value:e.jsxs("span",{"data-visual-volatile":"true",className:"font-mono text-primary",children:["v",l]})},{label:a("about.app.labels.buildTime"),value:e.jsx("span",{"data-visual-volatile":"true",children:u}),hint:a("about.app.hint.buildTime")},{label:a("about.app.labels.runtime"),value:e.jsx("span",{className:"font-mono",children:((s=t.data)==null?void 0:s.runtime)??"rust"})},{label:a("about.app.labels.backendVersion"),value:e.jsx("span",{"data-visual-volatile":"true",className:"font-mono",children:((T=t.data)==null?void 0:T.backendVersion)??"-"})}]},[l,u,(h=t.data)==null?void 0:h.backendVersion,(f=t.data)==null?void 0:f.runtime,a]),b=n.useMemo(()=>{var s;return t.data?[{label:a("about.status.labels.host"),value:t.data.host??"127.0.0.1"},{label:a("about.status.labels.port"),value:e.jsx("span",{"data-visual-volatile":"true",children:t.data.port.toLocaleString()})},{label:a("about.status.labels.providers"),value:t.data.providers.toLocaleString()},{label:a("about.status.labels.active"),value:(t.data.activeRequests??0).toLocaleString(),hint:a("about.status.hint.active")},{label:a("about.status.labels.platform"),value:t.data.platform??"-"},{label:a("about.status.labels.pid"),value:e.jsx("span",{"data-visual-volatile":"true",children:((s=t.data.pid)==null?void 0:s.toLocaleString())??"-"})}]:[]},[t.data,a]);return e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx(F,{icon:e.jsx(R,{className:"h-5 w-5","aria-hidden":"true"}),title:a("about.title"),description:a("about.description"),badge:e.jsxs("span",{"data-visual-volatile":"true",children:["v",l]}),eyebrow:"Runtime",breadcrumb:"Gateway / About",helper:a("about.support.description"),actions:e.jsxs("div",{className:"flex w-full flex-col gap-2 sm:w-auto sm:flex-row sm:flex-wrap sm:justify-end",children:[e.jsx("div",{className:"rounded-lg bg-secondary px-3 py-1.5 text-xs font-semibold text-muted-foreground",children:"manual refresh only"}),e.jsxs(x,{onClick:()=>o.mutate(),disabled:o.isPending,className:"w-full sm:w-auto",children:[e.jsx(_,{className:`mr-2 h-4 w-4${o.isPending?" animate-spin":""}`,"aria-hidden":"true"}),o.isPending?a("about.support.actions.checkingUpdates"):a("about.support.actions.checkUpdates")]})]})}),e.jsxs("div",{className:"grid gap-4 xl:grid-cols-[minmax(0,1.35fr)_minmax(320px,0.85fr)]",children:[e.jsx(d,{className:"overflow-hidden rounded-[1.25rem] border border-white/70 bg-card/95 shadow-[0_20px_50px_-42px_rgba(15,23,42,0.24)]",children:e.jsx(c,{className:"p-5",children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"inline-flex items-center gap-2 rounded-full bg-secondary px-3 py-1 text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:[e.jsx(m,{className:"h-3.5 w-3.5","aria-hidden":"true"}),"Runtime snapshot"]}),e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-end sm:justify-between",children:[e.jsxs("div",{className:"min-w-0 space-y-1",children:[e.jsxs("p",{"data-visual-volatile":"true",className:"metric-number truncate text-4xl font-semibold tracking-tight text-foreground",children:[((g=t.data)==null?void 0:g.host)??"127.0.0.1",":",((v=t.data)==null?void 0:v.port)??"-"]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:a("about.description")})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 text-xs sm:w-56",children:[e.jsx(A,{label:a("about.status.labels.providers"),value:((N=(j=t.data)==null?void 0:j.providers)==null?void 0:N.toLocaleString())??"-"}),e.jsx(A,{label:a("about.status.labels.active"),value:(((w=t.data)==null?void 0:w.activeRequests)??0).toLocaleString()})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(P,{variant:"outline",children:((y=t.data)==null?void 0:y.runtime)??"rust"}),e.jsx(P,{variant:"outline",children:((k=t.data)==null?void 0:k.platform)??"-"})]})]})})}),e.jsx(d,{className:"overflow-hidden rounded-[1.25rem] border border-white/70 bg-card/95 shadow-[0_20px_50px_-42px_rgba(15,23,42,0.24)]",children:e.jsx(c,{className:"p-5",children:e.jsxs("div",{className:"space-y-3",children:[e.jsx("p",{className:"text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:"Build"}),e.jsxs("div",{className:"flex flex-wrap items-baseline justify-between gap-2",children:[e.jsxs("p",{"data-visual-volatile":"true",className:"font-mono text-xl font-semibold text-primary",children:["v",l]}),e.jsx("p",{"data-visual-volatile":"true",className:"text-xs text-muted-foreground",children:u})]}),i?e.jsxs("div",{className:"rounded-lg bg-secondary px-4 py-3 text-sm text-muted-foreground",children:[e.jsx("p",{className:"font-medium text-foreground",children:i.updateAvailable?a("about.update.available",{version:i.latestVersion}):a("about.update.current",{version:i.currentVersion})}),e.jsxs("p",{className:"mt-1",children:[a("about.update.channel",{channel:i.channel}),i.publishedAt?` · ${new Date(i.publishedAt).toLocaleString()}`:""]})]}):null,e.jsx("div",{className:"rounded-[0.95rem] bg-secondary/65 px-3.5 py-3 text-sm text-muted-foreground",children:a("about.support.tip")})]})})})]}),e.jsxs("div",{className:"grid gap-6 lg:grid-cols-2",children:[e.jsx(p,{title:a("about.app.title"),description:a("about.app.subtitle"),children:e.jsx(E,{items:V})}),e.jsx(p,{title:a("about.status.title"),description:a("about.status.subtitle"),actions:e.jsxs(x,{variant:"outline",size:"sm",onClick:()=>void t.refetch(),disabled:t.isFetching,children:[e.jsx(B,{className:U(t.isFetching),"aria-hidden":"true"}),t.isFetching?a("common.actions.refreshing"):a("common.actions.refresh")]}),children:t.isLoading?e.jsx(G,{compact:!0,label:a("about.status.loading")}):t.isError?e.jsx(C,{compact:!0,tone:"danger",icon:e.jsx(m,{className:"h-5 w-5","aria-hidden":"true"}),title:a("common.status.error"),description:((S=t.error)==null?void 0:S.message)??a("common.unknownError"),action:e.jsx(x,{variant:"outline",size:"sm",onClick:()=>void t.refetch(),children:a("common.actions.refresh")})}):b.length>0?e.jsx(E,{items:b}):e.jsx(C,{compact:!0,tone:"primary",icon:e.jsx(m,{className:"h-5 w-5","aria-hidden":"true"}),title:a("about.status.empty"),description:a("common.actions.refresh")})})]}),e.jsx(p,{title:a("about.support.title"),description:e.jsxs("span",{className:"space-y-1",children:[e.jsx("span",{className:"block text-sm font-medium text-primary",children:a("about.support.subtitle")}),e.jsx("span",{children:a("about.support.description")})]}),children:e.jsx(d,{className:"rounded-xl bg-card shadow-[var(--surface-shadow)]",children:e.jsxs(c,{className:"flex flex-col gap-4 pt-5 md:flex-row md:items-start md:justify-between",children:[e.jsxs("div",{className:"flex items-start gap-4 rounded-lg bg-secondary p-4",children:[e.jsx("div",{className:"flex h-11 w-11 items-center justify-center rounded-xl bg-primary/10 text-primary",children:e.jsx(q,{className:"h-5 w-5","aria-hidden":"true"})}),e.jsx("p",{className:"max-w-2xl text-sm text-muted-foreground",children:a("about.support.tip")})]}),e.jsx("code",{className:"inline-flex self-start rounded-lg bg-secondary px-3 py-2 text-xs font-medium",children:"~/.cc-gw/config.json"})]})})})]})}function E({items:a}){return a.length===0?null:e.jsx("dl",{className:"grid gap-3 sm:grid-cols-2",children:a.map(r=>e.jsx(d,{className:"rounded-[1rem] border border-white/70 bg-secondary/45 shadow-none",children:e.jsxs(c,{className:"p-4",children:[e.jsx("dt",{className:"text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:r.label}),e.jsx("dd",{className:"metric-number mt-2 text-sm font-semibold text-foreground",children:r.value}),r.hint?e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:r.hint}):null]})},r.label))})}function A({label:a,value:r}){return e.jsxs("div",{className:"rounded-[0.9rem] bg-secondary/65 px-3 py-2 text-right",children:[e.jsx("p",{className:"text-[10px] font-semibold uppercase tracking-[0.16em] text-muted-foreground",children:a}),e.jsx("p",{className:"metric-number mt-1 text-sm font-semibold text-foreground",children:r})]})}function U(a){return`mr-2 h-4 w-4${a?" animate-spin":""}`}export{ne as default};
@@ -1 +1 @@
1
- import{r as x,j as e,a1 as os,ag as ce,V as de,aF as S,aG as pe,aH as ke,aI as cs,aJ as Ae,aK as Me,aD as ds}from"./vendor-LWJeAdU1.js";import{r as ps,g as ae,b as te,B as h,u as xs,a as G,s as Q,L as us}from"./app-BG16DmZH.js";import{P as ms}from"./PageHeader--Lg_YQVw.js";import{C as hs}from"./ConfirmDialog-BHrsB4gR.js";import{D as xe,A as ue,a as me,b as he,c as qe,d as ge,e as ye}from"./DialogShell-DcG-SXEV.js";import{I as J}from"./input-scp9nKJc.js";import{L as P}from"./label-fMXEnAEx.js";import{c as _}from"./global-CKvMKvrn.js";import{u as B}from"./useApiQuery-jSeDDFuv.js";import{q as N,B as C}from"./queryKeys-DTnZc8Yy.js";import{u as w}from"./i18n-B3N4Df3E.js";import{L as gs}from"./router-DspBTS8b.js";import{E as ys,T as bs,a as js,b as De,c as F,d as fs,e as L}from"./table-BtnjYcvG.js";import{P as We}from"./PageSection-DIAhP18t.js";import{a as oe}from"./PageState-DKba6Ew1.js";import{C as X,a as be}from"./card-CwTuH2Iq.js";import{e as vs}from"./charts-core-D9OugzV_.js";import{u as U}from"./useAppMutation-ChCrgiP6.js";import{c as Ks}from"./clipboard-CALi6bTW.js";import"./query-Cpxr1dul.js";import"./radix-bG5h1Ymq.js";import"./charts-react-BqhUp1x_.js";import"./charts-engine-DleyglMn.js";const Fe=x.forwardRef(({className:s,...a},l)=>e.jsx("textarea",{className:_("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",s),ref:l,...a}));Fe.displayName="Textarea";const M={listRequest(){return{url:"/api/keys",method:"GET"}},overviewRequest(s){return{url:"/api/stats/api-keys/overview",method:"GET",params:{days:s}}},usageRequest(s,a=10){return{url:"/api/stats/api-keys/usage",method:"GET",params:{days:s,limit:a}}},customEndpointOptionsRequest(){return{url:"/api/custom-endpoints",method:"GET"}},create:async s=>ae(te.post("/api/keys",s)),update:async(s,a)=>{await ae(te.patch(`/api/keys/${s}`,a))},delete:async s=>{await ae(te.delete(`/api/keys/${s}`))},reveal:async s=>ps({url:`/api/keys/${s}/reveal`,method:"GET"})},Le=[{value:1,labelKey:"apiKeys.analytics.range.today"},{value:7,labelKey:"apiKeys.analytics.range.week"},{value:30,labelKey:"apiKeys.analytics.range.month"}];function Ns(){var l;const s=[{id:"anthropic",label:"Anthropic"},{id:"openai",label:"OpenAI"}],a=B(N.customEndpoints.all(),M.customEndpointOptionsRequest());return x.useMemo(()=>{var o;const t=(((o=a.data)==null?void 0:o.endpoints)??[]).map(u=>({id:u.id,label:u.label||u.id}));return[...s,...t]},[(l=a.data)==null?void 0:l.endpoints])}function Re({available:s,hint:a,onChange:l,selected:t}){const{t:o}=w(),u=t.length===0,b=()=>{l([])},f=c=>{if(t.includes(c)){l(t.filter(p=>p!==c));return}l([...t,c])};return e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"rounded-lg border border-border bg-secondary px-3 py-3 text-xs text-muted-foreground",children:a}),e.jsxs("label",{className:"flex cursor-pointer items-center gap-2 rounded-lg border border-border bg-card px-3 py-2.5 transition-colors hover:border-primary/20 hover:bg-accent/50",children:[e.jsx("input",{type:"checkbox",checked:u,onChange:b,className:"h-4 w-4 rounded border-input accent-primary"}),e.jsx("span",{className:"text-sm font-medium",children:o("apiKeys.allEndpoints")})]}),e.jsx("div",{className:"grid max-h-40 gap-1 overflow-y-auto",children:s.map(c=>e.jsxs("label",{className:"flex cursor-pointer items-center gap-2 rounded-lg border border-border bg-card px-3 py-2.5 transition-colors hover:border-primary/20 hover:bg-accent/50",children:[e.jsx("input",{type:"checkbox",checked:!u&&t.includes(c.id),onChange:()=>f(c.id),className:"h-4 w-4 rounded border-input accent-primary"}),e.jsx("span",{className:"text-sm",children:c.label}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:["(",c.id,")"]})]},c.id))})]})}function ws({availableEndpoints:s,isOpen:a,keyDescription:l,keyName:t,maxConcurrency:o,onDescriptionChange:u,onEndpointsChange:b,onKeyNameChange:f,onMaxConcurrencyChange:c,onOpenChange:p,onSubmit:g,selectedEndpoints:n}){const{t:r}=w();return e.jsx(xe,{open:a,onOpenChange:p,children:e.jsxs(ue,{className:"max-w-2xl",children:[e.jsxs(me,{children:[e.jsx(he,{children:r("apiKeys.createNew")}),e.jsx(qe,{children:r("apiKeys.createDescription")})]}),e.jsxs(ge,{className:"space-y-4",children:[e.jsx("div",{className:"rounded-lg border border-primary/20 bg-accent px-4 py-3 text-xs text-primary",children:r("apiKeys.selectEndpoints")}),e.jsxs("div",{className:"grid gap-3 md:grid-cols-3",children:[e.jsxs("div",{className:"rounded-lg border border-primary/20 bg-primary/5 px-3 py-3 text-xs text-primary",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-amber-200 bg-amber-50 px-3 py-3 text-xs text-amber-800 dark:border-amber-800 dark:bg-amber-950/30 dark:text-amber-200",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(P,{htmlFor:"keyName",children:[r("apiKeys.keyNamePlaceholder")," *"]}),e.jsx(J,{id:"keyName",value:t,onChange:y=>f(y.target.value),placeholder:r("apiKeys.keyNamePlaceholder"),onKeyDown:y=>{y.key==="Enter"&&(y.preventDefault(),g())}})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(P,{htmlFor:"keyDescription",children:r("apiKeys.descriptionLabel")}),e.jsx(Fe,{id:"keyDescription",value:l,onChange:y=>u(y.target.value),placeholder:r("apiKeys.keyDescriptionPlaceholder"),rows:3})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(P,{children:r("apiKeys.allowedEndpoints")}),e.jsx(Re,{available:s,selected:n,onChange:b,hint:r("apiKeys.selectEndpoints")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(P,{htmlFor:"maxConcurrency",children:r("apiKeys.maxConcurrency")}),e.jsx(J,{id:"maxConcurrency",type:"number",min:"0",value:o,onChange:y=>c(y.target.value),placeholder:r("apiKeys.maxConcurrencyPlaceholder")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:r("apiKeys.maxConcurrencyHelper")})]})]}),e.jsxs(ye,{children:[e.jsx(h,{variant:"outline",onClick:()=>p(!1),children:r("common.actions.cancel")}),e.jsx(h,{onClick:g,children:r("apiKeys.createAction")})]})]})})}function Cs({createdKey:s,onClose:a,onCopy:l}){const{t}=w();return e.jsx(xe,{open:!!s,onOpenChange:o=>{o||a()},children:e.jsxs(ue,{className:"max-w-xl",children:[e.jsx(me,{children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex h-10 w-10 items-center justify-center rounded-full bg-emerald-500/10 text-emerald-600",children:e.jsx(os,{className:"h-5 w-5","aria-hidden":"true"})}),e.jsx(he,{children:t("apiKeys.keyCreated")})]})}),e.jsxs(ge,{className:"space-y-4",children:[e.jsx("p",{className:"text-sm font-medium text-amber-600 dark:text-amber-400",children:t("apiKeys.saveKeyWarning")}),e.jsx("div",{className:"rounded-lg border border-border bg-secondary px-4 py-3 font-mono text-sm",children:s==null?void 0:s.key}),s!=null&&s.description?e.jsx("p",{className:"whitespace-pre-wrap text-sm text-muted-foreground",children:s.description}):null]}),e.jsxs(ye,{children:[e.jsxs(h,{onClick:()=>l((s==null?void 0:s.key)??""),children:[e.jsx(ce,{className:"mr-2 h-4 w-4","aria-hidden":"true"}),t("common.actions.copy")]}),e.jsx(h,{variant:"outline",onClick:a,children:t("common.actions.close")})]})]})})}function Es({apiKey:s,availableEndpoints:a,maxConcurrency:l,onClose:t,onEndpointsChange:o,onMaxConcurrencyChange:u,onSave:b,selectedEndpoints:f}){const{t:c}=w();return e.jsx(xe,{open:!!s,onOpenChange:p=>{p||t()},children:e.jsxs(ue,{className:"max-w-2xl",children:[e.jsxs(me,{children:[e.jsx(he,{children:c("apiKeys.editEndpoints")}),e.jsx(qe,{children:s==null?void 0:s.name})]}),e.jsxs(ge,{className:"space-y-4",children:[!(s!=null&&s.isWildcard)&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"rounded-lg border border-amber-200 bg-amber-50 px-4 py-3 text-xs text-amber-800 dark:border-amber-800 dark:bg-amber-950/30 dark:text-amber-200",children:c("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(Re,{available:a,selected:f,onChange:o,hint:c("apiKeys.selectEndpoints")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(P,{htmlFor:"editMaxConcurrency",children:c("apiKeys.maxConcurrency")}),e.jsx(J,{id:"editMaxConcurrency",type:"number",min:"0",value:l,onChange:p=>u(p.target.value),placeholder:c("apiKeys.maxConcurrencyPlaceholder")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:c("apiKeys.maxConcurrencyHelper")})]})]}),e.jsxs(ye,{children:[e.jsx(h,{variant:"outline",onClick:t,children:c("common.actions.cancel")}),e.jsx(h,{onClick:b,children:c("common.save")})]})]})})}function ks({deleteTarget:s,isDeleting:a,onConfirm:l,onOpenChange:t}){const{t:o}=w();return e.jsx(hs,{open:!!s,onOpenChange:t,title:o("apiKeys.deleteDialogTitle"),description:o("apiKeys.confirmDelete"),confirmLabel:s&&a===s.id?o("common.actions.loading"):o("apiKeys.actions.delete"),cancelLabel:o("common.actions.cancel"),loading:s?a===s.id:!1,onConfirm:l,children:s?e.jsx("div",{className:"rounded-lg border border-destructive/20 bg-destructive/10 px-3 py-2 font-mono text-xs text-foreground",children:s.name}):null})}function Ds(){const{t:s}=w();return e.jsx("div",{className:"rounded-[1.15rem] border border-border/55 bg-card/92 p-3 shadow-[var(--surface-shadow)] 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",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(ie,{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(ie,{icon:e.jsx(S,{className:"h-4 w-4","aria-hidden":"true"}),title:s("apiKeys.quickStart.restrict.title"),description:s("apiKeys.quickStart.restrict.description")}),e.jsx(ie,{icon:e.jsx(pe,{className:"h-4 w-4","aria-hidden":"true"}),title:s("apiKeys.quickStart.wildcard.title"),description:s("apiKeys.quickStart.wildcard.description")})]})})]})})}function Ts({activeKeysValue:s,enabledKeysValue:a,loading:l,onRangeChange:t,rangeDays:o,requestsChartOption:u,totalKeysValue:b,tokensChartOption:f,usageLength:c}){const{t:p}=w();return e.jsx(We,{eyebrow:"Usage",title:p("apiKeys.analytics.title"),description:p("apiKeys.analytics.description",{days:o}),actions:e.jsx("div",{className:"flex w-full items-center gap-1 overflow-x-auto rounded-full bg-secondary p-1 sm:w-auto",children:Le.map(g=>{const n=o===g.value;return e.jsx("button",{type:"button",onClick:()=>t(g.value),className:_("inline-flex h-8 shrink-0 items-center rounded-full px-3.5 text-xs font-medium transition-all",n?"bg-primary text-primary-foreground":"text-muted-foreground hover:bg-primary/5 hover:text-foreground"),children:p(g.labelKey)},g.value)})}),children:e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2 xl:grid-cols-3",children:[e.jsx(ne,{label:p("apiKeys.analytics.cards.total"),value:b}),e.jsx(ne,{label:p("apiKeys.analytics.cards.enabled"),value:a}),e.jsx(ne,{label:p("apiKeys.analytics.cards.active",{days:o}),value:s})]}),e.jsxs("div",{className:"grid gap-6 lg:grid-cols-2",children:[e.jsx(Te,{title:p("apiKeys.analytics.charts.requests"),loading:l,empty:c===0,emptyText:p("apiKeys.analytics.empty"),option:u}),e.jsx(Te,{title:p("apiKeys.analytics.charts.tokens"),loading:l,empty:c===0,emptyText:p("apiKeys.analytics.empty"),option:f})]})]})})}function As({filteredKeys:s,formatDate:a,hasWildcard:l,isDeleting:t,isRevealing:o,keys:u,onCopy:b,onDelete:f,onEditEndpoints:c,onFilterChange:p,onHide:g,onReveal:n,onStatusFilterChange:r,onToggleEnabled:y,restrictedCount:E,revealedKeys:k,search:K,statusFilter:q,unrestrictedCount:v,viewMode:O,wildcardCount:T,onViewModeChange:z,onCreateKey:Y}){const{t:m}=w();return e.jsx(We,{eyebrow:"Inventory",title:m("apiKeys.list.title"),description:l?m("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.jsxs("div",{className:"flex items-center gap-2 rounded-full bg-secondary p-1",children:[e.jsxs("button",{type:"button",onClick:()=>z("cards"),className:_("inline-flex h-8 items-center gap-1.5 rounded-full px-3 text-xs font-medium transition-all",O==="cards"?"bg-primary text-primary-foreground":"text-muted-foreground hover:bg-primary/5 hover:text-foreground"),children:[e.jsx(ke,{className:"h-3.5 w-3.5","aria-hidden":"true"}),m("apiKeys.views.cards")]}),e.jsxs("button",{type:"button",onClick:()=>z("compact"),className:_("inline-flex h-8 items-center gap-1.5 rounded-full px-3 text-xs font-medium transition-all",O==="compact"?"bg-primary text-primary-foreground":"text-muted-foreground hover:bg-primary/5 hover:text-foreground"),children:[e.jsx(cs,{className:"h-3.5 w-3.5","aria-hidden":"true"}),m("apiKeys.views.compact")]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(C,{variant:"outline",children:`${s.length}/${u.length}`}),e.jsx(C,{variant:"outline",children:m("apiKeys.summary.wildcard",{count:T})}),e.jsx(C,{variant:"outline",children:m("apiKeys.summary.restricted",{count:E})})]})]}),children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid gap-4 md:grid-cols-3",children:[e.jsx(re,{label:m("apiKeys.list.title"),value:`${s.length}/${u.length}`,helper:m("apiKeys.filters.searchPlaceholder")}),e.jsx(re,{label:m("apiKeys.summary.wildcard",{count:T}),value:String(T),helper:m("apiKeys.wildcardHint")}),e.jsx(re,{label:m("apiKeys.summary.restricted",{count:E}),value:String(E),helper:m("apiKeys.summary.unrestricted",{count:v})})]}),e.jsxs("div",{className:"grid gap-3 rounded-xl bg-secondary p-4 lg:grid-cols-[minmax(0,0.82fr)_auto] xl:grid-cols-[minmax(0,0.95fr)_auto_auto]",children:[e.jsx(J,{value:K,onChange:j=>p(j.target.value),placeholder:m("apiKeys.filters.searchPlaceholder"),className:"lg:max-w-[680px]"}),e.jsx("div",{className:"flex min-w-max items-center gap-1 overflow-x-auto rounded-full bg-background p-1 lg:justify-self-start xl:justify-self-center",children:["all","enabled","disabled"].map(j=>e.jsx("button",{type:"button",onClick:()=>r(j),className:_("inline-flex h-8 shrink-0 items-center rounded-full px-3.5 text-xs font-medium transition-all",q===j?"bg-primary text-primary-foreground":"text-muted-foreground hover:bg-primary/5 hover:text-foreground"),children:m(`apiKeys.filters.${j}`)},j))}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 lg:col-span-2 xl:col-span-1 xl:justify-self-end",children:[e.jsx(C,{variant:"secondary",children:m("apiKeys.summary.wildcard",{count:T})}),e.jsx(C,{variant:"secondary",children:m("apiKeys.summary.restricted",{count:E})})]})]}),u.length===0?e.jsx(oe,{compact:!0,tone:"primary",className:"rounded-[1.2rem] border-border/30 bg-background/50",icon:e.jsx(de,{className:"h-5 w-5","aria-hidden":"true"}),title:m("apiKeys.list.emptyTitle"),description:m("apiKeys.list.empty"),action:e.jsx(h,{size:"sm",onClick:Y,children:m("apiKeys.createNew")})}):s.length===0?e.jsx(oe,{compact:!0,tone:"primary",className:"rounded-[1.2rem] border-border/30 bg-background/50",icon:e.jsx(ke,{className:"h-5 w-5","aria-hidden":"true"}),title:m("apiKeys.list.emptyFilteredTitle"),description:m("apiKeys.list.emptyFiltered"),action:e.jsx(h,{variant:"outline",size:"sm",onClick:()=>{p(""),r("all")},children:m("common.actions.reset")})}):O==="compact"?e.jsx(Ms,{filteredKeys:s,formatDate:a,isDeleting:t,isRevealing:o,onCopy:b,onDelete:f,onEditEndpoints:c,onHide:g,onReveal:n,onToggleEnabled:y,revealedKeys:k}):e.jsx("div",{className:"grid gap-4",children:s.map(j=>e.jsx(qs,{formatDate:a,isDeleting:t===j.id,isRevealing:o===j.id,keySummary:j,onCopy:b,onDelete:f,onEditEndpoints:c,onHide:g,onReveal:n,onToggleEnabled:y,revealedValue:k.get(j.id)},j.id))})]})})}function Ms({filteredKeys:s,formatDate:a,isDeleting:l,isRevealing:t,onCopy:o,onDelete:u,onEditEndpoints:b,onHide:f,onReveal:c,onToggleEnabled:p,revealedKeys:g}){const{t:n}=w();return e.jsx(X,{className:"overflow-hidden border border-border/65 bg-card/96 shadow-[0_18px_42px_rgba(15,23,42,0.06)] ring-1 ring-white/70",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs(bs,{className:"min-w-[980px]",children:[e.jsx(js,{children:e.jsxs(De,{className:"bg-secondary/45 hover:bg-secondary/45",children:[e.jsx(F,{children:n("apiKeys.table.name")}),e.jsx(F,{children:n("apiKeys.table.access")}),e.jsx(F,{className:"text-right",children:n("apiKeys.requestCount")}),e.jsx(F,{className:"text-right",children:n("apiKeys.totalTokens")}),e.jsx(F,{className:"text-right",children:n("apiKeys.maxConcurrency")}),e.jsx(F,{children:n("apiKeys.lastUsed")}),e.jsx(F,{className:"w-[132px] text-right",children:n("apiKeys.table.actions")})]})}),e.jsx(fs,{children:s.map(r=>{var K,q,v;const y=g.get(r.id),E=(r.totalInputTokens+r.totalOutputTokens).toLocaleString(),k=r.isWildcard?n("apiKeys.wildcard"):(((K=r.allowedEndpoints)==null?void 0:K.length)??0)>0?(q=r.allowedEndpoints)==null?void 0:q.join(", "):n("apiKeys.allEndpoints");return e.jsxs(De,{children:[e.jsx(L,{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:r.name}),r.isWildcard?e.jsx(C,{variant:"secondary",className:"text-[11px]",children:n("apiKeys.wildcard")}):null,e.jsx(C,{variant:r.enabled?"default":"outline",className:"text-[11px]",children:r.enabled?n("apiKeys.status.enabled"):n("apiKeys.status.disabled")})]}),r.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:y??r.maskedKey??"********"}),y?e.jsxs(e.Fragment,{children:[e.jsx(h,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:()=>o(y),"aria-label":n("common.actions.copy"),children:e.jsx(ce,{className:"h-3.5 w-3.5","aria-hidden":"true"})}),e.jsx(h,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:()=>f(r.id),"aria-label":n("apiKeys.actions.hide"),children:e.jsx(pe,{className:"h-3.5 w-3.5","aria-hidden":"true"})})]}):e.jsx(h,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:()=>c(r.id),disabled:t===r.id,"aria-label":n("apiKeys.actions.reveal"),children:t===r.id?e.jsx("div",{className:"h-3.5 w-3.5 animate-spin rounded-full border-2 border-primary border-t-transparent"}):e.jsx(Ae,{className:"h-3.5 w-3.5","aria-hidden":"true"})})]})]})}),e.jsx(L,{className:"py-3",children:e.jsxs("div",{className:"max-w-[180px]",children:[e.jsx("div",{className:"truncate text-sm text-foreground",title:k,children:k}),e.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:r.isWildcard?n("apiKeys.table.accessWildcard"):(((v=r.allowedEndpoints)==null?void 0:v.length)??0)>0?n("apiKeys.endpointRestricted"):n("apiKeys.table.accessOpen")})]})}),e.jsx(L,{className:"py-3 text-right font-medium",children:r.requestCount.toLocaleString()}),e.jsx(L,{className:"py-3 text-right font-medium",children:E}),e.jsx(L,{className:"py-3 text-right font-medium",children:r.maxConcurrency?String(r.maxConcurrency):"—"}),e.jsxs(L,{className:"py-3",children:[e.jsx("div",{className:"text-sm font-medium text-foreground",children:a(r.lastUsedAt)}),e.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:a(r.createdAt)})]}),e.jsx(L,{className:"py-3",children:e.jsxs("div",{className:"flex justify-end gap-1",children:[e.jsx(h,{variant:"outline",size:"icon",onClick:()=>b(r),className:"h-8 w-8","aria-label":r.isWildcard?n("apiKeys.maxConcurrency"):n("apiKeys.editEndpoints"),title:r.isWildcard?n("apiKeys.maxConcurrency"):n("apiKeys.editEndpoints"),children:e.jsx(S,{className:"h-3.5 w-3.5","aria-hidden":"true"})}),e.jsx(h,{variant:r.enabled?"outline":"default",size:"sm",onClick:()=>p(r.id,r.enabled),className:"h-8 px-2.5 text-xs",children:r.enabled?n("apiKeys.actions.disable"):n("apiKeys.actions.enable")}),r.isWildcard?null:e.jsx(h,{variant:"ghost",size:"icon",className:"h-8 w-8 text-destructive hover:bg-destructive/10 hover:text-destructive",onClick:()=>u(r),disabled:l===r.id,"aria-label":n("apiKeys.actions.delete"),children:e.jsx(Me,{className:"h-3.5 w-3.5","aria-hidden":"true"})})]})})]},r.id)})})]})})})}function ie({description:s,icon:a,title:l}){return e.jsxs("div",{className:"w-[220px] shrink-0 rounded-[1rem] border border-border/45 bg-secondary/72 p-3 shadow-[inset_0_1px_0_rgba(255,255,255,0.6)] dark:border-white/10 dark:bg-slate-900/[0.52] dark:shadow-[inset_0_1px_0_rgba(255,255,255,0.04)] md:w-auto",children:[e.jsx("div",{className:"flex h-7 w-7 items-center justify-center rounded-[0.8rem] bg-background/85 text-primary dark:bg-slate-950/[0.62] sm:h-8 sm:w-8 sm:rounded-[0.85rem]",children:a}),e.jsx("p",{className:"mt-2 text-[12px] font-semibold leading-5 text-foreground sm:mt-2.5 sm:text-[13px]",children:l}),e.jsx("p",{className:"mt-1 line-clamp-2 text-[11px] leading-4.5 text-muted-foreground sm:text-xs sm:leading-5",children:s})]})}function qs({formatDate:s,isDeleting:a,isRevealing:l,keySummary:t,onCopy:o,onDelete:u,onEditEndpoints:b,onHide:f,onReveal:c,onToggleEnabled:p,revealedValue:g}){var y,E,k;const{t:n}=w(),r=(t.totalInputTokens+t.totalOutputTokens).toLocaleString();return e.jsx(X,{"data-testid":"api-key-card",className:"overflow-hidden border border-border/65 bg-card/96 shadow-[0_18px_42px_rgba(15,23,42,0.06)] ring-1 ring-white/70",children:e.jsx(be,{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:t.name}),t.isWildcard?e.jsx(C,{variant:"secondary",children:n("apiKeys.wildcard")}):null,e.jsx(C,{variant:t.enabled?"default":"outline",children:t.enabled?n("apiKeys.status.enabled"):n("apiKeys.status.disabled")}),t.isWildcard?null:e.jsx(C,{variant:"outline",className:"text-xs",children:(((y=t.allowedEndpoints)==null?void 0:y.length)??0)>0?n("apiKeys.endpointRestricted"):n("apiKeys.allEndpoints")}),!t.isWildcard&&t.allowedEndpoints&&t.allowedEndpoints.length>0?t.allowedEndpoints.map(K=>e.jsx(C,{variant:"outline",className:"text-xs",children:K},K)):t.isWildcard?null:e.jsx(C,{variant:"secondary",className:"text-xs opacity-60",children:n("apiKeys.allEndpoints")})]}),e.jsxs("div",{className:"grid gap-2 sm:grid-cols-3",children:[e.jsx(le,{label:n("apiKeys.requestCount"),value:t.requestCount.toLocaleString()}),e.jsx(le,{label:n("apiKeys.totalTokens"),value:r}),e.jsx(le,{label:n("apiKeys.maxConcurrency"),value:t.maxConcurrency?String(t.maxConcurrency):n("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:t.isWildcard?n("apiKeys.wildcard"):g??t.maskedKey??"********"}),t.isWildcard?null:e.jsx("div",{className:"flex items-center gap-1 self-start",children:g?e.jsxs(e.Fragment,{children:[e.jsx(h,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:()=>o(g),"aria-label":n("common.actions.copy"),title:n("common.actions.copy"),children:e.jsx(ce,{className:"h-4 w-4","aria-hidden":"true"})}),e.jsx(h,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:()=>f(t.id),"aria-label":n("apiKeys.actions.hide"),title:n("apiKeys.actions.hide"),children:e.jsx(pe,{className:"h-4 w-4","aria-hidden":"true"})})]}):e.jsx(h,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:()=>c(t.id),disabled:l,"aria-label":n("apiKeys.actions.reveal"),title:n("apiKeys.actions.reveal"),children:l?e.jsx("div",{className:"h-4 w-4 animate-spin rounded-full border-2 border-primary border-t-transparent"}):e.jsx(Ae,{className:"h-4 w-4","aria-hidden":"true"})})})]}),t.isWildcard?e.jsx("p",{className:"text-sm text-muted-foreground",children:n("apiKeys.wildcardHint")}):t.description?e.jsx("p",{className:"whitespace-pre-wrap text-sm text-muted-foreground",children:t.description}):null,t.isWildcard?null:e.jsx("div",{className:"rounded-lg bg-secondary px-3 py-2 text-xs text-muted-foreground",children:(((E=t.allowedEndpoints)==null?void 0:E.length)??0)>0?`${n("apiKeys.allowedEndpoints")}: ${(k=t.allowedEndpoints)==null?void 0:k.join(", ")}`:n("apiKeys.allEndpoints")}),e.jsxs("div",{className:"grid gap-3 text-sm sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("span",{className:"text-xs font-medium uppercase tracking-wide text-muted-foreground",children:n("apiKeys.created")}),e.jsx("p",{className:"font-medium",children:s(t.createdAt)})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("span",{className:"text-xs font-medium uppercase tracking-wide text-muted-foreground",children:n("apiKeys.lastUsed")}),e.jsx("p",{className:"font-medium",children:s(t.lastUsedAt)})]})]})]}),e.jsxs("div",{className:"grid gap-2 sm:grid-cols-2 lg:flex lg:flex-wrap lg:justify-end",children:[e.jsxs(h,{variant:"outline",size:"sm",onClick:()=>b(t),className:"w-full lg:w-auto",children:[e.jsx(S,{className:"mr-1 h-3.5 w-3.5","aria-hidden":"true"}),t.isWildcard?n("apiKeys.maxConcurrency"):n("apiKeys.editEndpoints")]}),e.jsx(h,{variant:t.enabled?"outline":"default",size:"sm",onClick:()=>p(t.id,t.enabled),className:"w-full lg:w-auto",children:t.enabled?n("apiKeys.actions.disable"):n("apiKeys.actions.enable")}),t.isWildcard?null:e.jsx(h,{variant:"ghost",size:"icon",className:"h-9 w-full text-destructive hover:bg-destructive/10 hover:text-destructive sm:w-9",onClick:()=>u(t),disabled:a,"aria-label":n("apiKeys.actions.delete"),children:e.jsx(Me,{className:"h-4 w-4","aria-hidden":"true"})})]})]})})})}function ne({label:s,value:a}){return e.jsx(X,{className:"border border-border/70 bg-secondary/70 shadow-none ring-1 ring-white/70",children:e.jsxs(be,{className:"pt-4",children:[e.jsx("p",{className:"text-xs font-medium uppercase tracking-wider text-muted-foreground",children:s}),e.jsx("p",{className:"metric-number mt-2 text-3xl font-semibold text-foreground",children:a})]})})}function re({helper:s,label:a,value:l}){return e.jsxs("div",{className:"rounded-xl bg-card px-4 py-3 shadow-[var(--surface-shadow)]",children:[e.jsx("p",{className:"text-[11px] font-medium uppercase tracking-wider text-muted-foreground",children:a}),e.jsx("p",{className:"metric-number mt-2 text-xl font-semibold text-foreground",children:l}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:s})]})}function le({label:s,value:a}){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:s}),e.jsx("p",{className:"mt-1 truncate text-sm font-medium",children:a})]})}function Te({empty:s,emptyText:a,loading:l,option:t,title:o}){const{t:u}=w();return e.jsx(X,{children:e.jsxs(be,{className:"space-y-4 pt-4",children:[e.jsx("h3",{className:"text-base font-semibold",children:o}),l?e.jsx("div",{className:"flex h-[280px] items-center justify-center",children:e.jsx("span",{className:"text-sm text-muted-foreground",children:u("common.loadingShort")})}):s?e.jsx(oe,{compact:!0,className:"min-h-[280px] rounded-[1.1rem] border-border/30 bg-background/50",icon:e.jsx(S,{className:"h-5 w-5","aria-hidden":"true"}),title:a,description:u("apiKeys.analytics.emptyHint"),action:e.jsx(h,{asChild:!0,variant:"ghost",size:"sm",children:e.jsx(gs,{to:"/logs",children:u("apiKeys.analytics.actions.logs")})})}):e.jsx(ys,{echarts:vs,option:t,style:{height:280},notMerge:!0,lazyUpdate:!0})]})})}function Ws(){const{t:s}=w(),{pushToast:a}=xs(),[l,t]=x.useState(!1),[o,u]=x.useState(""),[b,f]=x.useState(""),[c,p]=x.useState([]),[g,n]=x.useState(""),[r,y]=x.useState(null),[E,k]=x.useState(null),[K,q]=x.useState(null),[v,O]=G(Q.apiKeys.rangeDays,7,{serialize:i=>String(i),deserialize:i=>{const d=Number(i);return Le.some(D=>D.value===d)?d:7}}),[T,z]=x.useState(new Map),[Y,m]=x.useState(null),[j,Z]=x.useState(null),[I,je]=x.useState([]),[H,fe]=x.useState(""),[ee,Oe]=G(Q.apiKeys.search,""),[V,ze]=G(Q.apiKeys.statusFilter,"all",{serialize:i=>i,deserialize:i=>i==="enabled"||i==="disabled"?i:"all"}),[Pe,_e]=G(Q.apiKeys.viewMode,"compact",{serialize:i=>i,deserialize:i=>i==="cards"?"cards":"compact"}),Ie=Ns(),ve=B(N.apiKeys.all(),M.listRequest()),He=B(N.apiKeys.overview(v),M.overviewRequest(v)),Ke=B(N.apiKeys.usage(v),M.usageRequest(v)),Ne=U({mutationFn:M.create,invalidateKeys:[N.apiKeys.all(),N.apiKeys.overview(v),N.apiKeys.usage(v)],successToast:()=>({title:s("apiKeys.toast.keyCreated")}),errorToast:i=>({title:s("apiKeys.toast.createFailure",{message:i.message})})}),$=U({mutationFn:({id:i,...d})=>M.update(i,d),invalidateKeys:[N.apiKeys.all(),N.apiKeys.overview(v),N.apiKeys.usage(v)],successToast:()=>({title:s("apiKeys.toast.keyUpdated")}),errorToast:i=>({title:s("apiKeys.toast.updateFailure",{message:i.message})})}),we=U({mutationFn:({id:i})=>M.delete(i),invalidateKeys:[N.apiKeys.all(),N.apiKeys.overview(v),N.apiKeys.usage(v)],successToast:()=>({title:s("apiKeys.toast.keyDeleted")}),errorToast:i=>({title:s("apiKeys.toast.deleteFailure",{message:i.message})})}),Ce=U({mutationFn:({id:i})=>M.reveal(i),errorToast:i=>({title:s("apiKeys.toast.revealFailure"),description:i.message})}),W=ve.data??[],R=He.data,A=Ke.data??[],Ve=W.some(i=>i.isWildcard),$e=W.filter(i=>i.isWildcard).length,Ge=W.filter(i=>{var d;return!i.isWildcard&&(((d=i.allowedEndpoints)==null?void 0:d.length)??0)>0}).length,Qe=W.filter(i=>{var d;return!i.isWildcard&&(((d=i.allowedEndpoints)==null?void 0:d.length)??0)===0}).length,Ue=R?R.totalKeys.toLocaleString():"-",Be=R?R.enabledKeys.toLocaleString():"-",Je=R?R.activeKeys.toLocaleString():"-",Se=x.useMemo(()=>W.filter(i=>{if(!(V==="all"||(V==="enabled"?i.enabled:!i.enabled)))return!1;const D=ee.trim().toLowerCase();return D?[i.name,i.description??"",i.maskedKey??"",...i.allowedEndpoints??[]].join(" ").toLowerCase().includes(D):!0}),[W,ee,V]),Xe=x.useMemo(()=>{const i=A.map(d=>d.apiKeyName??s("apiKeys.analytics.unknownKey"));return{tooltip:{trigger:"axis"},grid:{left:60,right:20,top:40,bottom:40},xAxis:{type:"category",data:i,axisLabel:{interval:0,rotate:20}},yAxis:{type:"value"},series:[{name:s("apiKeys.analytics.requestsSeries"),type:"bar",data:A.map(d=>d.requests),itemStyle:{color:"hsl(var(--primary))"}}]}},[s,A]),Ye=x.useMemo(()=>{const i=A.map(d=>d.apiKeyName??s("apiKeys.analytics.unknownKey"));return{tooltip:{trigger:"axis"},legend:{data:[s("apiKeys.analytics.tokens.input"),s("apiKeys.analytics.tokens.output")]},grid:{left:60,right:20,top:50,bottom:40},xAxis:{type:"category",data:i,axisLabel:{interval:0,rotate:20}},yAxis:{type:"value"},series:[{name:s("apiKeys.analytics.tokens.input"),type:"bar",stack:"tokens",itemStyle:{color:"#22c55e"},data:A.map(d=>d.inputTokens)},{name:s("apiKeys.analytics.tokens.output"),type:"bar",stack:"tokens",itemStyle:{color:"#0ea5e9"},data:A.map(d=>d.outputTokens)}]}},[s,A]),Ee=x.useCallback(()=>{u(""),f(""),p([]),n("")},[]),se=x.useCallback(i=>{t(i),i||Ee()},[Ee]),Ze=x.useCallback(async()=>{if(!o.trim()){a({title:s("apiKeys.errors.nameRequired"),variant:"error"});return}try{const i=await Ne.mutateAsync({name:o.trim(),description:b.trim()||void 0,allowedEndpoints:c.length>0?c:void 0,maxConcurrency:g?Number(g):null});y(i),se(!1)}catch{}},[Ne,se,b,c,g,o,a,s]),es=x.useCallback(async(i,d)=>{try{await $.mutateAsync({id:i,enabled:!d})}catch{}},[$]),ss=x.useCallback(async()=>{if(K){k(K.id);try{await we.mutateAsync({id:K.id}),q(null)}catch{}finally{k(null)}}},[K,we]),as=x.useCallback(async i=>{if(!T.has(i)){m(i);try{const d=await Ce.mutateAsync({id:i});z(D=>new Map(D).set(i,d.key))}catch{}finally{m(null)}}},[Ce,T]),ts=x.useCallback(i=>{z(d=>{const D=new Map(d);return D.delete(i),D})},[]),is=x.useCallback(async i=>{try{await Ks(i),a({title:s("apiKeys.toast.keyCopied"),variant:"success"})}catch(d){a({title:s("apiKeys.toast.copyFailure"),description:d instanceof Error?d.message:s("common.unknownError"),variant:"error"})}},[a,s]),ns=x.useCallback(i=>{Z(i),je(i.allowedEndpoints??[]),fe(i.maxConcurrency?String(i.maxConcurrency):"")},[]),rs=x.useCallback(async()=>{if(j)try{await $.mutateAsync({id:j.id,...j.isWildcard?{}:{allowedEndpoints:I.length>0?I:null},maxConcurrency:H?Number(H):null}),Z(null)}catch{}},[j,I,H,$]),ls=x.useCallback(i=>i?new Date(i).toLocaleString():s("common.noData"),[s]);return{activeKeysValue:Je,availableEndpoints:Ie,deleteTarget:K,editEndpointsKey:j,editEndpointsSelection:I,editMaxConcurrency:H,enabledKeysValue:Be,filteredKeys:Se,formatDate:ls,handleCopyKey:is,handleCreateDialogChange:se,handleCreateKey:Ze,handleDeleteKey:ss,handleHideKey:ts,handleOpenEditEndpoints:ns,handleRevealKey:as,handleSaveEndpoints:rs,handleToggleEnabled:es,hasWildcard:Ve,isCreateDialogOpen:l,isDeleting:E,isRevealing:Y,keys:W,keysQuery:ve,newKeyDescription:b,newKeyEndpoints:c,newKeyMaxConcurrency:g,newKeyName:o,newlyCreatedKey:r,rangeDays:v,requestsChartOption:Xe,restrictedCount:Ge,revealedKeys:T,search:ee,setDeleteTarget:q,setEditEndpointsKey:Z,setEditEndpointsSelection:je,setEditMaxConcurrency:fe,setNewKeyDescription:f,setNewKeyEndpoints:p,setNewKeyMaxConcurrency:n,setNewKeyName:u,setNewlyCreatedKey:y,setRangeDays:O,setSearch:Oe,setStatusFilter:ze,statusFilter:V,tokensChartOption:Ye,totalKeysValue:Ue,unrestrictedCount:Qe,usage:A,usageQuery:Ke,viewMode:Pe,wildcardCount:$e,setViewMode:_e}}function ta(){const{t:s}=w(),a=Ws(),l=s("apiKeys.summary.totalCount",{count:a.keys.length});return a.keysQuery.isLoading?e.jsx(us,{}):e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx(ms,{icon:e.jsx(de,{className:"h-5 w-5","aria-hidden":"true"}),title:s("apiKeys.title"),description:s("apiKeys.description"),eyebrow:"Access Control",breadcrumb:"Gateway / API Keys",helper:s("apiKeys.helper"),badge:l,actions:e.jsxs("div",{className:"flex w-full flex-col gap-2 sm:w-auto sm:flex-row sm:flex-wrap sm:justify-end",children:[e.jsxs("div",{className:"rounded-full bg-secondary px-3.5 py-2 text-xs text-muted-foreground",children:[s("apiKeys.summary.wildcard",{count:a.wildcardCount})," / ",s("apiKeys.summary.restricted",{count:a.restrictedCount})," / ",s("apiKeys.summary.unrestricted",{count:a.unrestrictedCount})]}),e.jsxs(h,{onClick:()=>a.handleCreateDialogChange(!0),className:"w-full sm:w-auto",children:[e.jsx(ds,{className:"mr-2 h-4 w-4","aria-hidden":"true"}),s("apiKeys.createNew")]})]})}),e.jsx(Ds,{}),e.jsx(Ts,{activeKeysValue:a.activeKeysValue,enabledKeysValue:a.enabledKeysValue,loading:a.usageQuery.isLoading,onRangeChange:a.setRangeDays,rangeDays:a.rangeDays,requestsChartOption:a.requestsChartOption,totalKeysValue:a.totalKeysValue,tokensChartOption:a.tokensChartOption,usageLength:a.usage.length}),e.jsx(As,{filteredKeys:a.filteredKeys,formatDate:a.formatDate,hasWildcard:a.hasWildcard,isDeleting:a.isDeleting,isRevealing:a.isRevealing,keys:a.keys,onCopy:t=>void a.handleCopyKey(t),onDelete:a.setDeleteTarget,onEditEndpoints:a.handleOpenEditEndpoints,onFilterChange:a.setSearch,onHide:a.handleHideKey,onReveal:t=>void a.handleRevealKey(t),onStatusFilterChange:a.setStatusFilter,onToggleEnabled:(t,o)=>void a.handleToggleEnabled(t,o),restrictedCount:a.restrictedCount,revealedKeys:a.revealedKeys,search:a.search,statusFilter:a.statusFilter,unrestrictedCount:a.unrestrictedCount,viewMode:a.viewMode,wildcardCount:a.wildcardCount,onViewModeChange:a.setViewMode,onCreateKey:()=>a.handleCreateDialogChange(!0)}),e.jsx(ws,{availableEndpoints:a.availableEndpoints,isOpen:a.isCreateDialogOpen,keyDescription:a.newKeyDescription,keyName:a.newKeyName,maxConcurrency:a.newKeyMaxConcurrency,onDescriptionChange:a.setNewKeyDescription,onEndpointsChange:a.setNewKeyEndpoints,onKeyNameChange:a.setNewKeyName,onMaxConcurrencyChange:a.setNewKeyMaxConcurrency,onOpenChange:a.handleCreateDialogChange,onSubmit:()=>void a.handleCreateKey(),selectedEndpoints:a.newKeyEndpoints}),e.jsx(Cs,{createdKey:a.newlyCreatedKey,onClose:()=>a.setNewlyCreatedKey(null),onCopy:t=>void a.handleCopyKey(t)}),e.jsx(Es,{apiKey:a.editEndpointsKey,availableEndpoints:a.availableEndpoints,maxConcurrency:a.editMaxConcurrency,onClose:()=>a.setEditEndpointsKey(null),onEndpointsChange:a.setEditEndpointsSelection,onMaxConcurrencyChange:a.setEditMaxConcurrency,onSave:()=>void a.handleSaveEndpoints(),selectedEndpoints:a.editEndpointsSelection}),e.jsx(ks,{deleteTarget:a.deleteTarget,isDeleting:a.isDeleting,onConfirm:()=>void a.handleDeleteKey(),onOpenChange:t=>{!t&&a.isDeleting===null&&a.setDeleteTarget(null)}})]})}export{ta as default};
1
+ import{r as x,j as e,a1 as os,am as ce,V as de,aJ as S,aK as pe,aL as ke,aM as cs,aN as Ae,aO as Me,aH as ds}from"./vendor-z22RpOY0.js";import{r as ps,g as ae,b as te,B as h,u as xs,a as Q,s as G,L as us}from"./app-COiQeF3y.js";import{P as ms}from"./PageHeader-DCqHI67a.js";import{C as hs}from"./ConfirmDialog-oYHVEpGJ.js";import{D as xe,A as ue,a as me,b as he,c as qe,d as ge,e as ye}from"./DialogShell-DcOGCV8m.js";import{I as J}from"./input-DW7jGTgj.js";import{L as P}from"./label-Ci1io7XA.js";import{c as _}from"./global-B-NXh5qD.js";import{u as B}from"./useApiQuery-tbd4JJaZ.js";import{q as N,B as C}from"./queryKeys-ucXCzh0P.js";import{u as w}from"./i18n-Bl2BcCDG.js";import{L as gs}from"./router-CL3rf_uf.js";import{E as ys,T as bs,a as js,b as De,c as L,d as fs,e as F}from"./table-DdvG93mx.js";import{P as We}from"./PageSection-CuZMzA0E.js";import{a as oe}from"./PageState-B03H5AV0.js";import{C as X,a as be}from"./card-ChFVaqLf.js";import{e as vs}from"./charts-core-DzWzxST6.js";import{u as U}from"./useAppMutation-SONU2xFC.js";import{c as Ks}from"./clipboard-CALi6bTW.js";import"./query-BbGWgOFk.js";import"./radix-mHySgtou.js";import"./charts-react-D0nWbUCA.js";import"./charts-engine-Ds7lwC51.js";const Le=x.forwardRef(({className:s,...a},l)=>e.jsx("textarea",{className:_("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",s),ref:l,...a}));Le.displayName="Textarea";const M={listRequest(){return{url:"/api/keys",method:"GET"}},overviewRequest(s){return{url:"/api/stats/api-keys/overview",method:"GET",params:{days:s}}},usageRequest(s,a=10){return{url:"/api/stats/api-keys/usage",method:"GET",params:{days:s,limit:a}}},customEndpointOptionsRequest(){return{url:"/api/custom-endpoints",method:"GET"}},create:async s=>ae(te.post("/api/keys",s)),update:async(s,a)=>{await ae(te.patch(`/api/keys/${s}`,a))},delete:async s=>{await ae(te.delete(`/api/keys/${s}`))},reveal:async s=>ps({url:`/api/keys/${s}/reveal`,method:"GET"})},Fe=[{value:1,labelKey:"apiKeys.analytics.range.today"},{value:7,labelKey:"apiKeys.analytics.range.week"},{value:30,labelKey:"apiKeys.analytics.range.month"}];function Ns(){var l;const s=[{id:"anthropic",label:"Anthropic"},{id:"openai",label:"OpenAI"}],a=B(N.customEndpoints.all(),M.customEndpointOptionsRequest());return x.useMemo(()=>{var o;const t=(((o=a.data)==null?void 0:o.endpoints)??[]).map(u=>({id:u.id,label:u.label||u.id}));return[...s,...t]},[(l=a.data)==null?void 0:l.endpoints])}function Oe({available:s,hint:a,onChange:l,selected:t}){const{t:o}=w(),u=t.length===0,b=()=>{l([])},f=c=>{if(t.includes(c)){l(t.filter(p=>p!==c));return}l([...t,c])};return e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"rounded-lg border border-border bg-secondary px-3 py-3 text-xs text-muted-foreground",children:a}),e.jsxs("label",{className:"flex cursor-pointer items-center gap-2 rounded-lg border border-border bg-card px-3 py-2.5 transition-colors hover:border-primary/20 hover:bg-accent/50",children:[e.jsx("input",{type:"checkbox",checked:u,onChange:b,className:"h-4 w-4 rounded border-input accent-primary"}),e.jsx("span",{className:"text-sm font-medium",children:o("apiKeys.allEndpoints")})]}),e.jsx("div",{className:"grid max-h-40 gap-1 overflow-y-auto",children:s.map(c=>e.jsxs("label",{className:"flex cursor-pointer items-center gap-2 rounded-lg border border-border bg-card px-3 py-2.5 transition-colors hover:border-primary/20 hover:bg-accent/50",children:[e.jsx("input",{type:"checkbox",checked:!u&&t.includes(c.id),onChange:()=>f(c.id),className:"h-4 w-4 rounded border-input accent-primary"}),e.jsx("span",{className:"text-sm",children:c.label}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:["(",c.id,")"]})]},c.id))})]})}function ws({availableEndpoints:s,isOpen:a,keyDescription:l,keyName:t,maxConcurrency:o,onDescriptionChange:u,onEndpointsChange:b,onKeyNameChange:f,onMaxConcurrencyChange:c,onOpenChange:p,onSubmit:g,selectedEndpoints:n}){const{t:r}=w();return e.jsx(xe,{open:a,onOpenChange:p,children:e.jsxs(ue,{className:"max-w-2xl",children:[e.jsxs(me,{children:[e.jsx(he,{children:r("apiKeys.createNew")}),e.jsx(qe,{children:r("apiKeys.createDescription")})]}),e.jsxs(ge,{className:"space-y-4",children:[e.jsx("div",{className:"rounded-lg border border-primary/20 bg-accent px-4 py-3 text-xs text-primary",children:r("apiKeys.selectEndpoints")}),e.jsxs("div",{className:"grid gap-3 md:grid-cols-3",children:[e.jsxs("div",{className:"rounded-lg border border-primary/20 bg-primary/5 px-3 py-3 text-xs text-primary",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-amber-200 bg-amber-50 px-3 py-3 text-xs text-amber-800 dark:border-amber-800 dark:bg-amber-950/30 dark:text-amber-200",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(P,{htmlFor:"keyName",children:[r("apiKeys.keyNamePlaceholder")," *"]}),e.jsx(J,{id:"keyName",value:t,onChange:y=>f(y.target.value),placeholder:r("apiKeys.keyNamePlaceholder"),onKeyDown:y=>{y.key==="Enter"&&(y.preventDefault(),g())}})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(P,{htmlFor:"keyDescription",children:r("apiKeys.descriptionLabel")}),e.jsx(Le,{id:"keyDescription",value:l,onChange:y=>u(y.target.value),placeholder:r("apiKeys.keyDescriptionPlaceholder"),rows:3})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(P,{children:r("apiKeys.allowedEndpoints")}),e.jsx(Oe,{available:s,selected:n,onChange:b,hint:r("apiKeys.selectEndpoints")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(P,{htmlFor:"maxConcurrency",children:r("apiKeys.maxConcurrency")}),e.jsx(J,{id:"maxConcurrency",type:"number",min:"0",value:o,onChange:y=>c(y.target.value),placeholder:r("apiKeys.maxConcurrencyPlaceholder")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:r("apiKeys.maxConcurrencyHelper")})]})]}),e.jsxs(ye,{children:[e.jsx(h,{variant:"outline",onClick:()=>p(!1),children:r("common.actions.cancel")}),e.jsx(h,{onClick:g,children:r("apiKeys.createAction")})]})]})})}function Cs({createdKey:s,onClose:a,onCopy:l}){const{t}=w();return e.jsx(xe,{open:!!s,onOpenChange:o=>{o||a()},children:e.jsxs(ue,{className:"max-w-xl",children:[e.jsx(me,{children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex h-10 w-10 items-center justify-center rounded-full bg-emerald-500/10 text-emerald-600",children:e.jsx(os,{className:"h-5 w-5","aria-hidden":"true"})}),e.jsx(he,{children:t("apiKeys.keyCreated")})]})}),e.jsxs(ge,{className:"space-y-4",children:[e.jsx("p",{className:"text-sm font-medium text-amber-600 dark:text-amber-400",children:t("apiKeys.saveKeyWarning")}),e.jsx("div",{className:"rounded-lg border border-border bg-secondary px-4 py-3 font-mono text-sm",children:s==null?void 0:s.key}),s!=null&&s.description?e.jsx("p",{className:"whitespace-pre-wrap text-sm text-muted-foreground",children:s.description}):null]}),e.jsxs(ye,{children:[e.jsxs(h,{onClick:()=>l((s==null?void 0:s.key)??""),children:[e.jsx(ce,{className:"mr-2 h-4 w-4","aria-hidden":"true"}),t("common.actions.copy")]}),e.jsx(h,{variant:"outline",onClick:a,children:t("common.actions.close")})]})]})})}function Es({apiKey:s,availableEndpoints:a,maxConcurrency:l,onClose:t,onEndpointsChange:o,onMaxConcurrencyChange:u,onSave:b,selectedEndpoints:f}){const{t:c}=w();return e.jsx(xe,{open:!!s,onOpenChange:p=>{p||t()},children:e.jsxs(ue,{className:"max-w-2xl",children:[e.jsxs(me,{children:[e.jsx(he,{children:c("apiKeys.editEndpoints")}),e.jsx(qe,{children:s==null?void 0:s.name})]}),e.jsxs(ge,{className:"space-y-4",children:[!(s!=null&&s.isWildcard)&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"rounded-lg border border-amber-200 bg-amber-50 px-4 py-3 text-xs text-amber-800 dark:border-amber-800 dark:bg-amber-950/30 dark:text-amber-200",children:c("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(Oe,{available:a,selected:f,onChange:o,hint:c("apiKeys.selectEndpoints")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(P,{htmlFor:"editMaxConcurrency",children:c("apiKeys.maxConcurrency")}),e.jsx(J,{id:"editMaxConcurrency",type:"number",min:"0",value:l,onChange:p=>u(p.target.value),placeholder:c("apiKeys.maxConcurrencyPlaceholder")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:c("apiKeys.maxConcurrencyHelper")})]})]}),e.jsxs(ye,{children:[e.jsx(h,{variant:"outline",onClick:t,children:c("common.actions.cancel")}),e.jsx(h,{onClick:b,children:c("common.save")})]})]})})}function ks({deleteTarget:s,isDeleting:a,onConfirm:l,onOpenChange:t}){const{t:o}=w();return e.jsx(hs,{open:!!s,onOpenChange:t,title:o("apiKeys.deleteDialogTitle"),description:o("apiKeys.confirmDelete"),confirmLabel:s&&a===s.id?o("common.actions.loading"):o("apiKeys.actions.delete"),cancelLabel:o("common.actions.cancel"),loading:s?a===s.id:!1,onConfirm:l,children:s?e.jsx("div",{className:"rounded-lg border border-destructive/20 bg-destructive/10 px-3 py-2 font-mono text-xs text-foreground",children:s.name}):null})}function Ds(){const{t:s}=w();return e.jsx("div",{className:"rounded-[1.15rem] border border-border/55 bg-card/92 p-3 shadow-[var(--surface-shadow)] 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",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(ie,{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(ie,{icon:e.jsx(S,{className:"h-4 w-4","aria-hidden":"true"}),title:s("apiKeys.quickStart.restrict.title"),description:s("apiKeys.quickStart.restrict.description")}),e.jsx(ie,{icon:e.jsx(pe,{className:"h-4 w-4","aria-hidden":"true"}),title:s("apiKeys.quickStart.wildcard.title"),description:s("apiKeys.quickStart.wildcard.description")})]})})]})})}function Ts({activeKeysValue:s,enabledKeysValue:a,loading:l,onRangeChange:t,rangeDays:o,requestsChartOption:u,totalKeysValue:b,tokensChartOption:f,usageLength:c}){const{t:p}=w();return e.jsx(We,{eyebrow:"Usage",title:p("apiKeys.analytics.title"),description:p("apiKeys.analytics.description",{days:o}),actions:e.jsx("div",{className:"flex w-full items-center gap-1 overflow-x-auto rounded-full bg-secondary p-1 sm:w-auto",children:Fe.map(g=>{const n=o===g.value;return e.jsx("button",{type:"button",onClick:()=>t(g.value),className:_("inline-flex h-8 shrink-0 items-center rounded-full px-3.5 text-xs font-medium transition-all",n?"bg-primary text-primary-foreground":"text-muted-foreground hover:bg-primary/5 hover:text-foreground"),children:p(g.labelKey)},g.value)})}),children:e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2 xl:grid-cols-3",children:[e.jsx(ne,{label:p("apiKeys.analytics.cards.total"),value:b}),e.jsx(ne,{label:p("apiKeys.analytics.cards.enabled"),value:a}),e.jsx(ne,{label:p("apiKeys.analytics.cards.active",{days:o}),value:s})]}),e.jsxs("div",{className:"grid gap-6 lg:grid-cols-2",children:[e.jsx(Te,{title:p("apiKeys.analytics.charts.requests"),loading:l,empty:c===0,emptyText:p("apiKeys.analytics.empty"),option:u}),e.jsx(Te,{title:p("apiKeys.analytics.charts.tokens"),loading:l,empty:c===0,emptyText:p("apiKeys.analytics.empty"),option:f})]})]})})}function As({filteredKeys:s,formatDate:a,hasWildcard:l,isDeleting:t,isRevealing:o,keys:u,onCopy:b,onDelete:f,onEditEndpoints:c,onFilterChange:p,onHide:g,onReveal:n,onStatusFilterChange:r,onToggleEnabled:y,restrictedCount:E,revealedKeys:k,search:K,statusFilter:q,unrestrictedCount:v,viewMode:R,wildcardCount:T,onViewModeChange:z,onCreateKey:Y}){const{t:m}=w();return e.jsx(We,{eyebrow:"Inventory",title:m("apiKeys.list.title"),description:l?m("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.jsxs("div",{className:"flex items-center gap-2 rounded-full bg-secondary p-1",children:[e.jsxs("button",{type:"button",onClick:()=>z("cards"),className:_("inline-flex h-8 items-center gap-1.5 rounded-full px-3 text-xs font-medium transition-all",R==="cards"?"bg-primary text-primary-foreground":"text-muted-foreground hover:bg-primary/5 hover:text-foreground"),children:[e.jsx(ke,{className:"h-3.5 w-3.5","aria-hidden":"true"}),m("apiKeys.views.cards")]}),e.jsxs("button",{type:"button",onClick:()=>z("compact"),className:_("inline-flex h-8 items-center gap-1.5 rounded-full px-3 text-xs font-medium transition-all",R==="compact"?"bg-primary text-primary-foreground":"text-muted-foreground hover:bg-primary/5 hover:text-foreground"),children:[e.jsx(cs,{className:"h-3.5 w-3.5","aria-hidden":"true"}),m("apiKeys.views.compact")]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(C,{variant:"outline",children:`${s.length}/${u.length}`}),e.jsx(C,{variant:"outline",children:m("apiKeys.summary.wildcard",{count:T})}),e.jsx(C,{variant:"outline",children:m("apiKeys.summary.restricted",{count:E})})]})]}),children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid gap-4 md:grid-cols-3",children:[e.jsx(re,{label:m("apiKeys.list.title"),value:`${s.length}/${u.length}`,helper:m("apiKeys.filters.searchPlaceholder")}),e.jsx(re,{label:m("apiKeys.summary.wildcard",{count:T}),value:String(T),helper:m("apiKeys.wildcardHint")}),e.jsx(re,{label:m("apiKeys.summary.restricted",{count:E}),value:String(E),helper:m("apiKeys.summary.unrestricted",{count:v})})]}),e.jsxs("div",{className:"grid gap-3 rounded-xl bg-secondary p-4 lg:grid-cols-[minmax(0,0.82fr)_auto] xl:grid-cols-[minmax(0,0.95fr)_auto_auto]",children:[e.jsx(J,{value:K,onChange:j=>p(j.target.value),placeholder:m("apiKeys.filters.searchPlaceholder"),className:"lg:max-w-[680px]"}),e.jsx("div",{className:"flex min-w-max items-center gap-1 overflow-x-auto rounded-full bg-background p-1 lg:justify-self-start xl:justify-self-center",children:["all","enabled","disabled"].map(j=>e.jsx("button",{type:"button",onClick:()=>r(j),className:_("inline-flex h-8 shrink-0 items-center rounded-full px-3.5 text-xs font-medium transition-all",q===j?"bg-primary text-primary-foreground":"text-muted-foreground hover:bg-primary/5 hover:text-foreground"),children:m(`apiKeys.filters.${j}`)},j))}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 lg:col-span-2 xl:col-span-1 xl:justify-self-end",children:[e.jsx(C,{variant:"secondary",children:m("apiKeys.summary.wildcard",{count:T})}),e.jsx(C,{variant:"secondary",children:m("apiKeys.summary.restricted",{count:E})})]})]}),u.length===0?e.jsx(oe,{compact:!0,tone:"primary",className:"rounded-[1.2rem] border-border/30 bg-background/50",icon:e.jsx(de,{className:"h-5 w-5","aria-hidden":"true"}),title:m("apiKeys.list.emptyTitle"),description:m("apiKeys.list.empty"),action:e.jsx(h,{size:"sm",onClick:Y,children:m("apiKeys.createNew")})}):s.length===0?e.jsx(oe,{compact:!0,tone:"primary",className:"rounded-[1.2rem] border-border/30 bg-background/50",icon:e.jsx(ke,{className:"h-5 w-5","aria-hidden":"true"}),title:m("apiKeys.list.emptyFilteredTitle"),description:m("apiKeys.list.emptyFiltered"),action:e.jsx(h,{variant:"outline",size:"sm",onClick:()=>{p(""),r("all")},children:m("common.actions.reset")})}):R==="compact"?e.jsx(Ms,{filteredKeys:s,formatDate:a,isDeleting:t,isRevealing:o,onCopy:b,onDelete:f,onEditEndpoints:c,onHide:g,onReveal:n,onToggleEnabled:y,revealedKeys:k}):e.jsx("div",{className:"grid gap-4",children:s.map(j=>e.jsx(qs,{formatDate:a,isDeleting:t===j.id,isRevealing:o===j.id,keySummary:j,onCopy:b,onDelete:f,onEditEndpoints:c,onHide:g,onReveal:n,onToggleEnabled:y,revealedValue:k.get(j.id)},j.id))})]})})}function Ms({filteredKeys:s,formatDate:a,isDeleting:l,isRevealing:t,onCopy:o,onDelete:u,onEditEndpoints:b,onHide:f,onReveal:c,onToggleEnabled:p,revealedKeys:g}){const{t:n}=w();return e.jsx(X,{className:"overflow-hidden border border-border/65 bg-card/96 shadow-[0_18px_42px_rgba(15,23,42,0.06)] ring-1 ring-white/70",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs(bs,{className:"min-w-[980px]",children:[e.jsx(js,{children:e.jsxs(De,{className:"bg-secondary/45 hover:bg-secondary/45",children:[e.jsx(L,{children:n("apiKeys.table.name")}),e.jsx(L,{children:n("apiKeys.table.access")}),e.jsx(L,{className:"text-right",children:n("apiKeys.requestCount")}),e.jsx(L,{className:"text-right",children:n("apiKeys.totalTokens")}),e.jsx(L,{className:"text-right",children:n("apiKeys.maxConcurrency")}),e.jsx(L,{children:n("apiKeys.lastUsed")}),e.jsx(L,{className:"w-[132px] text-right",children:n("apiKeys.table.actions")})]})}),e.jsx(fs,{children:s.map(r=>{var K,q,v;const y=g.get(r.id),E=(r.totalInputTokens+r.totalOutputTokens).toLocaleString(),k=r.isWildcard?n("apiKeys.wildcard"):(((K=r.allowedEndpoints)==null?void 0:K.length)??0)>0?(q=r.allowedEndpoints)==null?void 0:q.join(", "):n("apiKeys.allEndpoints");return e.jsxs(De,{children:[e.jsx(F,{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:r.name}),r.isWildcard?e.jsx(C,{variant:"secondary",className:"text-[11px]",children:n("apiKeys.wildcard")}):null,e.jsx(C,{variant:r.enabled?"default":"outline",className:"text-[11px]",children:r.enabled?n("apiKeys.status.enabled"):n("apiKeys.status.disabled")})]}),r.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:y??r.maskedKey??"********"}),y?e.jsxs(e.Fragment,{children:[e.jsx(h,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:()=>o(y),"aria-label":n("common.actions.copy"),children:e.jsx(ce,{className:"h-3.5 w-3.5","aria-hidden":"true"})}),e.jsx(h,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:()=>f(r.id),"aria-label":n("apiKeys.actions.hide"),children:e.jsx(pe,{className:"h-3.5 w-3.5","aria-hidden":"true"})})]}):e.jsx(h,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:()=>c(r.id),disabled:t===r.id,"aria-label":n("apiKeys.actions.reveal"),children:t===r.id?e.jsx("div",{className:"h-3.5 w-3.5 animate-spin rounded-full border-2 border-primary border-t-transparent"}):e.jsx(Ae,{className:"h-3.5 w-3.5","aria-hidden":"true"})})]})]})}),e.jsx(F,{className:"py-3",children:e.jsxs("div",{className:"max-w-[180px]",children:[e.jsx("div",{className:"truncate text-sm text-foreground",title:k,children:k}),e.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:r.isWildcard?n("apiKeys.table.accessWildcard"):(((v=r.allowedEndpoints)==null?void 0:v.length)??0)>0?n("apiKeys.endpointRestricted"):n("apiKeys.table.accessOpen")})]})}),e.jsx(F,{className:"py-3 text-right font-medium",children:r.requestCount.toLocaleString()}),e.jsx(F,{className:"py-3 text-right font-medium",children:E}),e.jsx(F,{className:"py-3 text-right font-medium",children:r.maxConcurrency?String(r.maxConcurrency):"—"}),e.jsxs(F,{className:"py-3",children:[e.jsx("div",{className:"text-sm font-medium text-foreground",children:a(r.lastUsedAt)}),e.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:a(r.createdAt)})]}),e.jsx(F,{className:"py-3",children:e.jsxs("div",{className:"flex justify-end gap-1",children:[e.jsx(h,{variant:"outline",size:"icon",onClick:()=>b(r),className:"h-8 w-8","aria-label":r.isWildcard?n("apiKeys.maxConcurrency"):n("apiKeys.editEndpoints"),title:r.isWildcard?n("apiKeys.maxConcurrency"):n("apiKeys.editEndpoints"),children:e.jsx(S,{className:"h-3.5 w-3.5","aria-hidden":"true"})}),e.jsx(h,{variant:r.enabled?"outline":"default",size:"sm",onClick:()=>p(r.id,r.enabled),className:"h-8 px-2.5 text-xs",children:r.enabled?n("apiKeys.actions.disable"):n("apiKeys.actions.enable")}),r.isWildcard?null:e.jsx(h,{variant:"ghost",size:"icon",className:"h-8 w-8 text-destructive hover:bg-destructive/10 hover:text-destructive",onClick:()=>u(r),disabled:l===r.id,"aria-label":n("apiKeys.actions.delete"),children:e.jsx(Me,{className:"h-3.5 w-3.5","aria-hidden":"true"})})]})})]},r.id)})})]})})})}function ie({description:s,icon:a,title:l}){return e.jsxs("div",{className:"w-[220px] shrink-0 rounded-[1rem] border border-border/45 bg-secondary/72 p-3 shadow-[inset_0_1px_0_rgba(255,255,255,0.6)] dark:border-white/10 dark:bg-slate-900/[0.52] dark:shadow-[inset_0_1px_0_rgba(255,255,255,0.04)] md:w-auto",children:[e.jsx("div",{className:"flex h-7 w-7 items-center justify-center rounded-[0.8rem] bg-background/85 text-primary dark:bg-slate-950/[0.62] sm:h-8 sm:w-8 sm:rounded-[0.85rem]",children:a}),e.jsx("p",{className:"mt-2 text-[12px] font-semibold leading-5 text-foreground sm:mt-2.5 sm:text-[13px]",children:l}),e.jsx("p",{className:"mt-1 line-clamp-2 text-[11px] leading-4.5 text-muted-foreground sm:text-xs sm:leading-5",children:s})]})}function qs({formatDate:s,isDeleting:a,isRevealing:l,keySummary:t,onCopy:o,onDelete:u,onEditEndpoints:b,onHide:f,onReveal:c,onToggleEnabled:p,revealedValue:g}){var y,E,k;const{t:n}=w(),r=(t.totalInputTokens+t.totalOutputTokens).toLocaleString();return e.jsx(X,{"data-testid":"api-key-card",className:"overflow-hidden border border-border/65 bg-card/96 shadow-[0_18px_42px_rgba(15,23,42,0.06)] ring-1 ring-white/70",children:e.jsx(be,{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:t.name}),t.isWildcard?e.jsx(C,{variant:"secondary",children:n("apiKeys.wildcard")}):null,e.jsx(C,{variant:t.enabled?"default":"outline",children:t.enabled?n("apiKeys.status.enabled"):n("apiKeys.status.disabled")}),t.isWildcard?null:e.jsx(C,{variant:"outline",className:"text-xs",children:(((y=t.allowedEndpoints)==null?void 0:y.length)??0)>0?n("apiKeys.endpointRestricted"):n("apiKeys.allEndpoints")}),!t.isWildcard&&t.allowedEndpoints&&t.allowedEndpoints.length>0?t.allowedEndpoints.map(K=>e.jsx(C,{variant:"outline",className:"text-xs",children:K},K)):t.isWildcard?null:e.jsx(C,{variant:"secondary",className:"text-xs opacity-60",children:n("apiKeys.allEndpoints")})]}),e.jsxs("div",{className:"grid gap-2 sm:grid-cols-3",children:[e.jsx(le,{label:n("apiKeys.requestCount"),value:t.requestCount.toLocaleString()}),e.jsx(le,{label:n("apiKeys.totalTokens"),value:r}),e.jsx(le,{label:n("apiKeys.maxConcurrency"),value:t.maxConcurrency?String(t.maxConcurrency):n("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:t.isWildcard?n("apiKeys.wildcard"):g??t.maskedKey??"********"}),t.isWildcard?null:e.jsx("div",{className:"flex items-center gap-1 self-start",children:g?e.jsxs(e.Fragment,{children:[e.jsx(h,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:()=>o(g),"aria-label":n("common.actions.copy"),title:n("common.actions.copy"),children:e.jsx(ce,{className:"h-4 w-4","aria-hidden":"true"})}),e.jsx(h,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:()=>f(t.id),"aria-label":n("apiKeys.actions.hide"),title:n("apiKeys.actions.hide"),children:e.jsx(pe,{className:"h-4 w-4","aria-hidden":"true"})})]}):e.jsx(h,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:()=>c(t.id),disabled:l,"aria-label":n("apiKeys.actions.reveal"),title:n("apiKeys.actions.reveal"),children:l?e.jsx("div",{className:"h-4 w-4 animate-spin rounded-full border-2 border-primary border-t-transparent"}):e.jsx(Ae,{className:"h-4 w-4","aria-hidden":"true"})})})]}),t.isWildcard?e.jsx("p",{className:"text-sm text-muted-foreground",children:n("apiKeys.wildcardHint")}):t.description?e.jsx("p",{className:"whitespace-pre-wrap text-sm text-muted-foreground",children:t.description}):null,t.isWildcard?null:e.jsx("div",{className:"rounded-lg bg-secondary px-3 py-2 text-xs text-muted-foreground",children:(((E=t.allowedEndpoints)==null?void 0:E.length)??0)>0?`${n("apiKeys.allowedEndpoints")}: ${(k=t.allowedEndpoints)==null?void 0:k.join(", ")}`:n("apiKeys.allEndpoints")}),e.jsxs("div",{className:"grid gap-3 text-sm sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("span",{className:"text-xs font-medium uppercase tracking-wide text-muted-foreground",children:n("apiKeys.created")}),e.jsx("p",{className:"font-medium",children:s(t.createdAt)})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("span",{className:"text-xs font-medium uppercase tracking-wide text-muted-foreground",children:n("apiKeys.lastUsed")}),e.jsx("p",{className:"font-medium",children:s(t.lastUsedAt)})]})]})]}),e.jsxs("div",{className:"grid gap-2 sm:grid-cols-2 lg:flex lg:flex-wrap lg:justify-end",children:[e.jsxs(h,{variant:"outline",size:"sm",onClick:()=>b(t),className:"w-full lg:w-auto",children:[e.jsx(S,{className:"mr-1 h-3.5 w-3.5","aria-hidden":"true"}),t.isWildcard?n("apiKeys.maxConcurrency"):n("apiKeys.editEndpoints")]}),e.jsx(h,{variant:t.enabled?"outline":"default",size:"sm",onClick:()=>p(t.id,t.enabled),className:"w-full lg:w-auto",children:t.enabled?n("apiKeys.actions.disable"):n("apiKeys.actions.enable")}),t.isWildcard?null:e.jsx(h,{variant:"ghost",size:"icon",className:"h-9 w-full text-destructive hover:bg-destructive/10 hover:text-destructive sm:w-9",onClick:()=>u(t),disabled:a,"aria-label":n("apiKeys.actions.delete"),children:e.jsx(Me,{className:"h-4 w-4","aria-hidden":"true"})})]})]})})})}function ne({label:s,value:a}){return e.jsx(X,{className:"border border-border/70 bg-secondary/70 shadow-none ring-1 ring-white/70",children:e.jsxs(be,{className:"pt-4",children:[e.jsx("p",{className:"text-xs font-medium uppercase tracking-wider text-muted-foreground",children:s}),e.jsx("p",{className:"metric-number mt-2 text-3xl font-semibold text-foreground",children:a})]})})}function re({helper:s,label:a,value:l}){return e.jsxs("div",{className:"rounded-xl bg-card px-4 py-3 shadow-[var(--surface-shadow)]",children:[e.jsx("p",{className:"text-[11px] font-medium uppercase tracking-wider text-muted-foreground",children:a}),e.jsx("p",{className:"metric-number mt-2 text-xl font-semibold text-foreground",children:l}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:s})]})}function le({label:s,value:a}){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:s}),e.jsx("p",{className:"mt-1 truncate text-sm font-medium",children:a})]})}function Te({empty:s,emptyText:a,loading:l,option:t,title:o}){const{t:u}=w();return e.jsx(X,{children:e.jsxs(be,{className:"space-y-4 pt-4",children:[e.jsx("h3",{className:"text-base font-semibold",children:o}),l?e.jsx("div",{className:"flex h-[280px] items-center justify-center",children:e.jsx("span",{className:"text-sm text-muted-foreground",children:u("common.loadingShort")})}):s?e.jsx(oe,{compact:!0,className:"min-h-[280px] rounded-[1.1rem] border-border/30 bg-background/50",icon:e.jsx(S,{className:"h-5 w-5","aria-hidden":"true"}),title:a,description:u("apiKeys.analytics.emptyHint"),action:e.jsx(h,{asChild:!0,variant:"ghost",size:"sm",children:e.jsx(gs,{to:"/logs",children:u("apiKeys.analytics.actions.logs")})})}):e.jsx(ys,{echarts:vs,option:t,style:{height:280},notMerge:!0,lazyUpdate:!0})]})})}function Ws(){const{t:s}=w(),{pushToast:a}=xs(),[l,t]=x.useState(!1),[o,u]=x.useState(""),[b,f]=x.useState(""),[c,p]=x.useState([]),[g,n]=x.useState(""),[r,y]=x.useState(null),[E,k]=x.useState(null),[K,q]=x.useState(null),[v,R]=Q(G.apiKeys.rangeDays,7,{serialize:i=>String(i),deserialize:i=>{const d=Number(i);return Fe.some(D=>D.value===d)?d:7}}),[T,z]=x.useState(new Map),[Y,m]=x.useState(null),[j,Z]=x.useState(null),[I,je]=x.useState([]),[H,fe]=x.useState(""),[ee,Re]=Q(G.apiKeys.search,""),[V,ze]=Q(G.apiKeys.statusFilter,"all",{serialize:i=>i,deserialize:i=>i==="enabled"||i==="disabled"?i:"all"}),[Pe,_e]=Q(G.apiKeys.viewMode,"compact",{serialize:i=>i,deserialize:i=>i==="cards"?"cards":"compact"}),Ie=Ns(),ve=B(N.apiKeys.all(),M.listRequest()),He=B(N.apiKeys.overview(v),M.overviewRequest(v)),Ke=B(N.apiKeys.usage(v),M.usageRequest(v)),Ne=U({mutationFn:M.create,invalidateKeys:[N.apiKeys.all(),N.apiKeys.overview(v),N.apiKeys.usage(v)],successToast:()=>({title:s("apiKeys.toast.keyCreated")}),errorToast:i=>({title:s("apiKeys.toast.createFailure",{message:i.message})})}),$=U({mutationFn:({id:i,...d})=>M.update(i,d),invalidateKeys:[N.apiKeys.all(),N.apiKeys.overview(v),N.apiKeys.usage(v)],successToast:()=>({title:s("apiKeys.toast.keyUpdated")}),errorToast:i=>({title:s("apiKeys.toast.updateFailure",{message:i.message})})}),we=U({mutationFn:({id:i})=>M.delete(i),invalidateKeys:[N.apiKeys.all(),N.apiKeys.overview(v),N.apiKeys.usage(v)],successToast:()=>({title:s("apiKeys.toast.keyDeleted")}),errorToast:i=>({title:s("apiKeys.toast.deleteFailure",{message:i.message})})}),Ce=U({mutationFn:({id:i})=>M.reveal(i),errorToast:i=>({title:s("apiKeys.toast.revealFailure"),description:i.message})}),W=ve.data??[],O=He.data,A=Ke.data??[],Ve=W.some(i=>i.isWildcard),$e=W.filter(i=>i.isWildcard).length,Qe=W.filter(i=>{var d;return!i.isWildcard&&(((d=i.allowedEndpoints)==null?void 0:d.length)??0)>0}).length,Ge=W.filter(i=>{var d;return!i.isWildcard&&(((d=i.allowedEndpoints)==null?void 0:d.length)??0)===0}).length,Ue=O?O.totalKeys.toLocaleString():"-",Be=O?O.enabledKeys.toLocaleString():"-",Je=O?O.activeKeys.toLocaleString():"-",Se=x.useMemo(()=>W.filter(i=>{if(!(V==="all"||(V==="enabled"?i.enabled:!i.enabled)))return!1;const D=ee.trim().toLowerCase();return D?[i.name,i.description??"",i.maskedKey??"",...i.allowedEndpoints??[]].join(" ").toLowerCase().includes(D):!0}),[W,ee,V]),Xe=x.useMemo(()=>{const i=A.map(d=>d.apiKeyName??s("apiKeys.analytics.unknownKey"));return{tooltip:{trigger:"axis"},grid:{left:60,right:20,top:40,bottom:40},xAxis:{type:"category",data:i,axisLabel:{interval:0,rotate:20}},yAxis:{type:"value"},series:[{name:s("apiKeys.analytics.requestsSeries"),type:"bar",data:A.map(d=>d.requests),itemStyle:{color:"hsl(var(--primary))"}}]}},[s,A]),Ye=x.useMemo(()=>{const i=A.map(d=>d.apiKeyName??s("apiKeys.analytics.unknownKey"));return{tooltip:{trigger:"axis"},legend:{data:[s("apiKeys.analytics.tokens.input"),s("apiKeys.analytics.tokens.output")]},grid:{left:60,right:20,top:50,bottom:40},xAxis:{type:"category",data:i,axisLabel:{interval:0,rotate:20}},yAxis:{type:"value"},series:[{name:s("apiKeys.analytics.tokens.input"),type:"bar",stack:"tokens",itemStyle:{color:"#22c55e"},data:A.map(d=>d.inputTokens)},{name:s("apiKeys.analytics.tokens.output"),type:"bar",stack:"tokens",itemStyle:{color:"#0ea5e9"},data:A.map(d=>d.outputTokens)}]}},[s,A]),Ee=x.useCallback(()=>{u(""),f(""),p([]),n("")},[]),se=x.useCallback(i=>{t(i),i||Ee()},[Ee]),Ze=x.useCallback(async()=>{if(!o.trim()){a({title:s("apiKeys.errors.nameRequired"),variant:"error"});return}try{const i=await Ne.mutateAsync({name:o.trim(),description:b.trim()||void 0,allowedEndpoints:c.length>0?c:void 0,maxConcurrency:g?Number(g):null});y(i),se(!1)}catch{}},[Ne,se,b,c,g,o,a,s]),es=x.useCallback(async(i,d)=>{try{await $.mutateAsync({id:i,enabled:!d})}catch{}},[$]),ss=x.useCallback(async()=>{if(K){k(K.id);try{await we.mutateAsync({id:K.id}),q(null)}catch{}finally{k(null)}}},[K,we]),as=x.useCallback(async i=>{if(!T.has(i)){m(i);try{const d=await Ce.mutateAsync({id:i});z(D=>new Map(D).set(i,d.key))}catch{}finally{m(null)}}},[Ce,T]),ts=x.useCallback(i=>{z(d=>{const D=new Map(d);return D.delete(i),D})},[]),is=x.useCallback(async i=>{try{await Ks(i),a({title:s("apiKeys.toast.keyCopied"),variant:"success"})}catch(d){a({title:s("apiKeys.toast.copyFailure"),description:d instanceof Error?d.message:s("common.unknownError"),variant:"error"})}},[a,s]),ns=x.useCallback(i=>{Z(i),je(i.allowedEndpoints??[]),fe(i.maxConcurrency?String(i.maxConcurrency):"")},[]),rs=x.useCallback(async()=>{if(j)try{await $.mutateAsync({id:j.id,...j.isWildcard?{}:{allowedEndpoints:I.length>0?I:null},maxConcurrency:H?Number(H):null}),Z(null)}catch{}},[j,I,H,$]),ls=x.useCallback(i=>i?new Date(i).toLocaleString():s("common.noData"),[s]);return{activeKeysValue:Je,availableEndpoints:Ie,deleteTarget:K,editEndpointsKey:j,editEndpointsSelection:I,editMaxConcurrency:H,enabledKeysValue:Be,filteredKeys:Se,formatDate:ls,handleCopyKey:is,handleCreateDialogChange:se,handleCreateKey:Ze,handleDeleteKey:ss,handleHideKey:ts,handleOpenEditEndpoints:ns,handleRevealKey:as,handleSaveEndpoints:rs,handleToggleEnabled:es,hasWildcard:Ve,isCreateDialogOpen:l,isDeleting:E,isRevealing:Y,keys:W,keysQuery:ve,newKeyDescription:b,newKeyEndpoints:c,newKeyMaxConcurrency:g,newKeyName:o,newlyCreatedKey:r,rangeDays:v,requestsChartOption:Xe,restrictedCount:Qe,revealedKeys:T,search:ee,setDeleteTarget:q,setEditEndpointsKey:Z,setEditEndpointsSelection:je,setEditMaxConcurrency:fe,setNewKeyDescription:f,setNewKeyEndpoints:p,setNewKeyMaxConcurrency:n,setNewKeyName:u,setNewlyCreatedKey:y,setRangeDays:R,setSearch:Re,setStatusFilter:ze,statusFilter:V,tokensChartOption:Ye,totalKeysValue:Ue,unrestrictedCount:Ge,usage:A,usageQuery:Ke,viewMode:Pe,wildcardCount:$e,setViewMode:_e}}function ta(){const{t:s}=w(),a=Ws(),l=s("apiKeys.summary.totalCount",{count:a.keys.length});return a.keysQuery.isLoading?e.jsx(us,{}):e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx(ms,{icon:e.jsx(de,{className:"h-5 w-5","aria-hidden":"true"}),title:s("apiKeys.title"),description:s("apiKeys.description"),eyebrow:"Access Control",breadcrumb:"Gateway / API Keys",helper:s("apiKeys.helper"),badge:l,actions:e.jsxs("div",{className:"flex w-full flex-col gap-2 sm:w-auto sm:flex-row sm:flex-wrap sm:justify-end",children:[e.jsxs("div",{className:"rounded-full bg-secondary px-3.5 py-2 text-xs text-muted-foreground",children:[s("apiKeys.summary.wildcard",{count:a.wildcardCount})," / ",s("apiKeys.summary.restricted",{count:a.restrictedCount})," / ",s("apiKeys.summary.unrestricted",{count:a.unrestrictedCount})]}),e.jsxs(h,{onClick:()=>a.handleCreateDialogChange(!0),className:"w-full sm:w-auto",children:[e.jsx(ds,{className:"mr-2 h-4 w-4","aria-hidden":"true"}),s("apiKeys.createNew")]})]})}),e.jsx(Ds,{}),e.jsx(Ts,{activeKeysValue:a.activeKeysValue,enabledKeysValue:a.enabledKeysValue,loading:a.usageQuery.isLoading,onRangeChange:a.setRangeDays,rangeDays:a.rangeDays,requestsChartOption:a.requestsChartOption,totalKeysValue:a.totalKeysValue,tokensChartOption:a.tokensChartOption,usageLength:a.usage.length}),e.jsx(As,{filteredKeys:a.filteredKeys,formatDate:a.formatDate,hasWildcard:a.hasWildcard,isDeleting:a.isDeleting,isRevealing:a.isRevealing,keys:a.keys,onCopy:t=>void a.handleCopyKey(t),onDelete:a.setDeleteTarget,onEditEndpoints:a.handleOpenEditEndpoints,onFilterChange:a.setSearch,onHide:a.handleHideKey,onReveal:t=>void a.handleRevealKey(t),onStatusFilterChange:a.setStatusFilter,onToggleEnabled:(t,o)=>void a.handleToggleEnabled(t,o),restrictedCount:a.restrictedCount,revealedKeys:a.revealedKeys,search:a.search,statusFilter:a.statusFilter,unrestrictedCount:a.unrestrictedCount,viewMode:a.viewMode,wildcardCount:a.wildcardCount,onViewModeChange:a.setViewMode,onCreateKey:()=>a.handleCreateDialogChange(!0)}),e.jsx(ws,{availableEndpoints:a.availableEndpoints,isOpen:a.isCreateDialogOpen,keyDescription:a.newKeyDescription,keyName:a.newKeyName,maxConcurrency:a.newKeyMaxConcurrency,onDescriptionChange:a.setNewKeyDescription,onEndpointsChange:a.setNewKeyEndpoints,onKeyNameChange:a.setNewKeyName,onMaxConcurrencyChange:a.setNewKeyMaxConcurrency,onOpenChange:a.handleCreateDialogChange,onSubmit:()=>void a.handleCreateKey(),selectedEndpoints:a.newKeyEndpoints}),e.jsx(Cs,{createdKey:a.newlyCreatedKey,onClose:()=>a.setNewlyCreatedKey(null),onCopy:t=>void a.handleCopyKey(t)}),e.jsx(Es,{apiKey:a.editEndpointsKey,availableEndpoints:a.availableEndpoints,maxConcurrency:a.editMaxConcurrency,onClose:()=>a.setEditEndpointsKey(null),onEndpointsChange:a.setEditEndpointsSelection,onMaxConcurrencyChange:a.setEditMaxConcurrency,onSave:()=>void a.handleSaveEndpoints(),selectedEndpoints:a.editEndpointsSelection}),e.jsx(ks,{deleteTarget:a.deleteTarget,isDeleting:a.isDeleting,onConfirm:()=>void a.handleDeleteKey(),onOpenChange:t=>{!t&&a.isDeleting===null&&a.setDeleteTarget(null)}})]})}export{ta as default};
@@ -1 +1 @@
1
- import{j as s}from"./vendor-LWJeAdU1.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-DcG-SXEV.js";import{B as o}from"./app-BG16DmZH.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-z22RpOY0.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-DcOGCV8m.js";import{B as o}from"./app-COiQeF3y.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 +1 @@
1
- import{j as e,aj as Ce,ak as Re,W as Q,al as _e,am as Pe,an as qe,O as G,ao as Me,ap as Ae,aq as De,ar as ne,as as Be,r as u,at as Oe,U as Fe}from"./vendor-LWJeAdU1.js";import{P as $e}from"./PageHeader--Lg_YQVw.js";import{P as V,a as z}from"./PageState-DKba6Ew1.js";import{B,u as Ge,a as ze,b as He,t as Qe,s as Ue}from"./app-BG16DmZH.js";import{S as Ve,a as Ke,b as We,c as Ye,d as q}from"./select-BjYpeVvo.js";import{c as C}from"./global-CKvMKvrn.js";import{L as Ze}from"./router-DspBTS8b.js";import{T as ie,a as de,b as O,c as j,d as le,e as y,E as Je}from"./table-BtnjYcvG.js";import{P as ce}from"./PageSection-DIAhP18t.js";import{S as Xe,C as et,T as tt}from"./Skeleton-cyuMRxwQ.js";import{B as k,q as I}from"./queryKeys-DTnZc8Yy.js";import{C as F,a as $}from"./card-CwTuH2Iq.js";import{g as ae}from"./utils-DSaa7c6v.js";import{u as T}from"./i18n-B3N4Df3E.js";import{e as st}from"./charts-core-D9OugzV_.js";import{u as L}from"./useApiQuery-jSeDDFuv.js";import"./query-Cpxr1dul.js";import"./radix-bG5h1Ymq.js";import"./charts-react-BqhUp1x_.js";import"./charts-engine-DleyglMn.js";const M=15e3,H=6e4,S={requests:"#2563eb",input:"#059669",output:"#ea580c",cacheRead:"#7c3aed",cacheCreation:"#e11d48",latency:"#0891b2"};function R(s,t,a){return s==null?"-":`${s.toLocaleString(void 0,a)} ${t}`}function U(s){if(s==null)return"-";if(s<1024)return`${s} B`;const t=["KB","MB","GB","TB"];let a=s/1024,r=0;for(;a>=1024&&r<t.length-1;)a/=1024,r+=1;return`${a.toFixed(a>=100?0:a>=10?1:2)} ${t[r]}`}function re(s){if(s==null)return"-";const t=s<1?0:s;return t<1024?`${t.toLocaleString(void 0,{maximumFractionDigits:t>=100?0:t>=10?1:2})} B/s`:`${U(t)}/s`}function at(s){return s==null?"-":`${s.toLocaleString(void 0,{maximumFractionDigits:s>=10?0:1})}%`}function rt(){return e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx("div",{className:"h-20 animate-pulse rounded-xl bg-card shadow-[var(--surface-shadow)]"}),e.jsx("div",{className:"grid gap-4 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4",children:Array.from({length:12}).map((s,t)=>e.jsx(Xe,{},t))}),e.jsx("div",{className:"grid gap-6 lg:grid-cols-2",children:Array.from({length:4}).map((s,t)=>e.jsx(et,{},t))}),e.jsx("div",{className:"rounded-xl bg-card shadow-[var(--surface-shadow)]",children:e.jsx("table",{className:"w-full",children:e.jsx("tbody",{children:Array.from({length:5}).map((s,t)=>e.jsx(tt,{columns:6},t))})})})]})}function ot({selectedEndpointLabel:s,status:t,todayRequests:a}){const{t:r}=T();return e.jsxs("div",{className:"flex flex-col gap-4 rounded-xl bg-card p-6 shadow-[var(--surface-shadow)] sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"flex h-10 w-10 items-center justify-center rounded-lg bg-primary/10",children:e.jsx(Ce,{className:"h-5 w-5 text-primary","aria-hidden":"true"})}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h2",{className:"text-lg font-semibold text-foreground",children:s}),e.jsx(k,{variant:"success",children:r("dashboard.status.listeningLabel")})]}),e.jsxs("p",{className:"mt-0.5 text-sm text-muted-foreground",children:[(t==null?void 0:t.host)??"0.0.0.0",":",(t==null?void 0:t.port)??"-",e.jsx("span",{className:"mx-2 text-border",children:"·"}),r("dashboard.labels.todayRequests"),": ",a.toLocaleString(),e.jsx("span",{className:"mx-2 text-border",children:"·"}),r("dashboard.labels.providers"),": ",((t==null?void 0:t.providers)??0).toLocaleString()]})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-3 text-sm text-muted-foreground",children:[e.jsxs("span",{children:[r("dashboard.labels.activeClientAddresses"),": ",e.jsx("strong",{className:"text-foreground",children:((t==null?void 0:t.activeClientAddresses)??0).toLocaleString()})]}),e.jsx("span",{className:"text-border",children:"·"}),e.jsxs("span",{children:[r("dashboard.labels.activeClientSessions"),": ",e.jsx("strong",{className:"text-foreground",children:((t==null?void 0:t.activeClientSessions)??0).toLocaleString()})]})]})]})}function nt({dbSizeDisplay:s,memoryDisplay:t,overview:a,status:r}){const{t:o}=T(),c=[{icon:e.jsx(Re,{className:"h-4 w-4"}),label:o("dashboard.labels.activeRequests"),value:((r==null?void 0:r.activeRequests)??0).toLocaleString(),testId:"dashboard-spotlight-value-active"},{icon:e.jsx(Q,{className:"h-4 w-4"}),label:o("dashboard.labels.requestsPerMinute"),value:((r==null?void 0:r.requestsPerMinute)??0).toLocaleString(),testId:"dashboard-spotlight-value-rpm"},{icon:e.jsx(_e,{className:"h-4 w-4"}),label:o("dashboard.labels.outputTokensPerMinute"),value:((r==null?void 0:r.outputTokensPerMinute)??0).toLocaleString(),testId:"dashboard-spotlight-value-tpm"},{icon:e.jsx(Pe,{className:"h-4 w-4"}),label:o("dashboard.labels.cpu"),value:at(r==null?void 0:r.cpuUsagePercent),testId:"dashboard-spotlight-value-cpu"}],l=[{icon:e.jsx(Q,{className:"h-4 w-4"}),label:o("dashboard.cards.todayRequests"),value:((a==null?void 0:a.today.requests)??0).toLocaleString(),suffix:o("common.units.request")},{icon:e.jsx(qe,{className:"h-4 w-4"}),label:o("dashboard.cards.todayInput"),value:((a==null?void 0:a.today.inputTokens)??0).toLocaleString(),suffix:o("common.units.token")},{icon:e.jsx(G,{className:"h-4 w-4"}),label:o("dashboard.cards.todayOutput"),value:((a==null?void 0:a.today.outputTokens)??0).toLocaleString(),suffix:o("common.units.token")},{icon:e.jsx(Me,{className:"h-4 w-4"}),label:o("dashboard.cards.avgLatency"),value:R((a==null?void 0:a.today.avgLatencyMs)??0,o("common.units.ms"))},{icon:e.jsx(Ae,{className:"h-4 w-4"}),label:o("dashboard.labels.networkIngress"),value:re(r==null?void 0:r.networkIngressBytesPerSecond),testId:"dashboard-spotlight-value-ingress"},{icon:e.jsx(De,{className:"h-4 w-4"}),label:o("dashboard.labels.networkEgress"),value:re(r==null?void 0:r.networkEgressBytesPerSecond),testId:"dashboard-spotlight-value-egress"},{icon:e.jsx(ne,{className:"h-4 w-4"}),label:o("dashboard.labels.database"),value:s,testId:"dashboard-spotlight-value-database"},{icon:e.jsx(Be,{className:"h-4 w-4"}),label:o("dashboard.labels.memory"),value:t,testId:"dashboard-spotlight-value-memory"}];return e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"grid gap-3 md:grid-cols-2 xl:grid-cols-5",children:c.map((n,i)=>e.jsx(oe,{className:i===0?"md:col-span-2 xl:col-span-2":void 0,featured:i===0,icon:n.icon,label:n.label,value:n.value,valueTestId:n.testId},n.label))}),e.jsx("div",{className:"grid gap-2.5 sm:grid-cols-2 lg:grid-cols-4",children:l.map(n=>e.jsx(oe,{compact:!0,icon:n.icon,label:n.label,suffix:n.suffix,value:n.value,valueTestId:n.testId},n.label))})]})}function it({busiestDay:s,fastestTtftModel:t,topModel:a,totalRequestsInRange:r}){const{t:o}=T();return e.jsxs("div",{className:"grid gap-3 lg:grid-cols-[1.4fr_repeat(3,minmax(0,1fr))]",children:[e.jsx(A,{featured:!0,label:o("dashboard.insights.totalRequests"),value:r.toLocaleString(),hint:o("dashboard.insights.totalRequestsHint")}),e.jsx(A,{label:o("dashboard.insights.busiestDay"),value:s?s.date:"-",hint:s?o("dashboard.insights.busiestDayHint",{value:s.requestCount.toLocaleString()}):o("common.noData")}),e.jsx(A,{label:o("dashboard.insights.topModel"),value:a?`${a.provider}/${a.model}`:"-",hint:a?o("dashboard.insights.topModelHint",{value:a.requests.toLocaleString()}):o("common.noData")}),e.jsx(A,{label:o("dashboard.insights.fastestTtft"),value:t?`${t.provider}/${t.model}`:"-",hint:t?R(t.avgTtftMs,o("common.units.ms")):o("common.noData")})]})}function dt({endpointCount:s,providerCount:t,selectedEndpointLabel:a}){const r=[{title:"先配置 Provider",description:t>0?`当前已检测到 ${t} 个 Provider,可直接继续下一步。`:"先在模型供应商里接入至少 1 个上游模型服务。",href:"/models",cta:"去模型供应商",tone:"from-indigo-100 to-cyan-100"},{title:"确认默认路由入口",description:s>0?`当前已有 ${s} 个自定义端点,可继续检查默认映射是否合理。`:"把一个端点或默认路由配置清楚,后续客户端就能稳定接入。",href:"/routing",cta:"去路由管理",tone:"from-violet-100 to-fuchsia-100"},{title:"发起第一条真实请求",description:"创建 API Key,然后从常用客户端打进来一条请求,让日志、路由和延迟开始有数据。",href:"/api-keys",cta:"去 API 密钥",tone:"from-emerald-100 to-cyan-100"}];return e.jsxs("div",{className:"grid gap-4 xl:grid-cols-[minmax(0,1.2fr)_minmax(300px,0.8fr)]",children:[e.jsx(F,{className:"overflow-hidden border-white/80 bg-[linear-gradient(135deg,rgba(255,255,255,0.98),hsl(var(--primary)/0.08),rgba(236,253,245,0.8))] shadow-[0_22px_56px_-40px_rgba(15,23,42,0.24)]",children:e.jsxs($,{className:"space-y-5 pt-5",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"inline-flex items-center rounded-full bg-primary/10 px-3 py-1 text-[11px] font-semibold uppercase tracking-[0.16em] text-primary",children:"Cold Start Guide"}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold text-foreground",children:"当前还是冷启动状态,这是正常的"}),e.jsx("p",{className:"mt-1.5 text-sm leading-6 text-muted-foreground",children:"这个仪表盘会在第一条真实请求进来后明显更有价值。现在最适合做的是把 Provider、路由和 API Key 三件事顺次走通。"})]})]}),e.jsx("div",{className:"grid gap-3 lg:grid-cols-3",children:r.map((o,c)=>e.jsxs("div",{className:"rounded-[1.1rem] border border-white/70 bg-card/88 p-4 shadow-[0_16px_40px_-34px_rgba(15,23,42,0.18)]",children:[e.jsxs("div",{className:C("flex h-10 w-10 items-center justify-center rounded-2xl bg-gradient-to-br text-sm font-semibold text-primary",o.tone),children:["0",c+1]}),e.jsx("h4",{className:"mt-3 text-sm font-semibold text-foreground",children:o.title}),e.jsx("p",{className:"mt-1.5 text-xs leading-6 text-muted-foreground",children:o.description}),e.jsx(B,{asChild:!0,variant:"ghost",size:"sm",className:"mt-3 h-8 rounded-full px-0 text-primary hover:bg-transparent hover:text-primary/80",children:e.jsx(Ze,{to:o.href,children:o.cta})})]},o.title))})]})}),e.jsx(F,{className:"border-white/80 bg-card/96 shadow-[0_20px_48px_-40px_rgba(15,23,42,0.24)]",children:e.jsxs($,{className:"space-y-4 pt-5",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-[0.16em] text-muted-foreground/80",children:"Workspace Snapshot"}),e.jsx("h3",{className:"mt-2 text-base font-semibold text-foreground",children:a}),e.jsx("p",{className:"mt-1 text-xs leading-6 text-muted-foreground",children:"等第一批流量进来后,这里会逐步展示趋势、模型表现和最近请求。"})]}),e.jsx("div",{className:"grid gap-3 sm:grid-cols-3 xl:grid-cols-1",children:[{label:"已配置 Provider",value:String(t)},{label:"自定义端点",value:String(s)},{label:"建议下一步",value:"发起请求"}].map(o=>e.jsxs("div",{className:"rounded-[1rem] bg-secondary/45 px-4 py-3 ring-1 ring-white/70",children:[e.jsx("div",{className:"text-[11px] font-medium text-muted-foreground",children:o.label}),e.jsx("div",{className:"mt-1 text-lg font-semibold text-foreground",children:o.value})]},o.label))}),e.jsx("div",{className:"rounded-[1rem] border border-dashed border-border/45 bg-secondary/35 px-4 py-3",children:e.jsxs("p",{className:"text-xs leading-6 text-muted-foreground",children:["如果你还没确定从哪一步开始,优先去 ",e.jsx("span",{className:"font-medium text-foreground",children:"API 密钥"})," 创建一个客户端专用 key,再从常用工具发起一条最小请求。"]})})]})})]})}function lt({dailyEmpty:s,dailyOption:t,dailyPending:a,models:r,modelRequestsOption:o,modelUsagePending:c,ttftOption:l,tpotOption:n}){const{t:i}=T();return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid gap-6 lg:grid-cols-2",children:[e.jsx(D,{title:i("dashboard.charts.requestsTitle"),description:i("dashboard.charts.requestsDesc"),loading:a,option:t,empty:s,emptyText:i("dashboard.charts.empty")}),e.jsx(D,{title:i("dashboard.charts.modelTitle"),description:i("dashboard.charts.modelDesc"),loading:c,option:o,empty:!r.length,emptyText:i("dashboard.charts.empty")})]}),e.jsxs("div",{className:"grid gap-6 lg:grid-cols-2",children:[e.jsx(D,{title:i("dashboard.charts.ttftTitle"),description:i("dashboard.charts.ttftDesc"),loading:c,option:l,empty:!r.some(m=>m.avgTtftMs!=null&&m.avgTtftMs>0),emptyText:i("dashboard.charts.ttftEmpty")}),e.jsx(D,{title:i("dashboard.charts.tpotTitle"),description:i("dashboard.charts.tpotDesc"),loading:c,option:n,empty:!r.some(m=>m.avgTpotMs!=null&&m.avgTpotMs>0),emptyText:i("dashboard.charts.tpotEmpty")})]})]})}function ct({models:s,loading:t}){const{t:a}=T();return e.jsx(ce,{title:a("dashboard.modelTable.title"),description:a("dashboard.modelTable.description"),children:t?e.jsx(V,{compact:!0,label:a("common.loadingShort")}):s.length===0?e.jsx(z,{compact:!0,icon:e.jsx(G,{className:"h-5 w-5","aria-hidden":"true"}),title:a("dashboard.modelTable.empty")}):e.jsx("div",{className:"overflow-auto",children:e.jsxs(ie,{children:[e.jsx(de,{children:e.jsxs(O,{children:[e.jsx(j,{children:a("dashboard.modelTable.columns.model")}),e.jsx(j,{className:"text-right",children:a("dashboard.modelTable.columns.requests")}),e.jsx(j,{className:"text-right",children:a("dashboard.modelTable.columns.latency")}),e.jsx(j,{className:"text-right",children:a("dashboard.modelTable.columns.ttft")}),e.jsx(j,{className:"text-right",children:a("dashboard.modelTable.columns.tpot")})]})}),e.jsx(le,{children:s.map(r=>e.jsxs(O,{children:[e.jsx(y,{children:e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"font-medium",children:r.provider}),e.jsx("span",{className:"text-xs text-muted-foreground",children:r.model})]})}),e.jsx(y,{className:"text-right font-medium",children:r.requests.toLocaleString()}),e.jsx(y,{className:"text-right",children:R(r.avgLatencyMs,a("common.units.ms"))}),e.jsx(y,{className:"text-right",children:R(r.avgTtftMs,a("common.units.ms"))}),e.jsx(y,{className:"text-right",children:R(r.avgTpotMs,a("common.units.msPerToken"),{maximumFractionDigits:2})})]},`${r.provider}/${r.model}`))})]})})})}function mt({records:s,loading:t}){const{t:a}=T(),r=s.map(n=>ae(n,a)),o=r.filter(n=>n.tone==="success").length,c=r.filter(n=>n.tone==="error").length,l=r.filter(n=>n.tone==="pending").length;return e.jsx(ce,{title:a("dashboard.recent.title"),description:a("dashboard.recent.subtitle",{count:5}),actions:s.length>0?e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(k,{variant:"secondary",children:s.length}),e.jsxs(k,{variant:"success",children:[a("common.status.success"),": ",o]}),e.jsxs(k,{variant:"outline",className:"border-destructive/30 bg-destructive/10 text-destructive",children:[a("common.status.error"),": ",c]}),l>0?e.jsxs(k,{variant:"warning",children:[a("common.status.pending"),": ",l]}):null]}):null,children:t?e.jsx(V,{compact:!0,label:a("dashboard.recent.loading")}):s.length===0?e.jsx(z,{compact:!0,icon:e.jsx(Q,{className:"h-5 w-5","aria-hidden":"true"}),title:a("dashboard.recent.empty")}):e.jsx("div",{className:"overflow-auto",children:e.jsxs(ie,{children:[e.jsx(de,{children:e.jsxs(O,{children:[e.jsx(j,{children:a("dashboard.recent.columns.time")}),e.jsx(j,{children:a("dashboard.recent.columns.endpoint")}),e.jsx(j,{children:a("dashboard.recent.columns.provider")}),e.jsx(j,{children:a("dashboard.recent.columns.route")}),e.jsx(j,{className:"text-right",children:a("dashboard.recent.columns.latency")}),e.jsx(j,{children:a("dashboard.recent.columns.status")})]})}),e.jsx(le,{children:s.map(n=>{const i=ae(n,a);return e.jsxs(O,{children:[e.jsx(y,{children:e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"text-xs font-medium",children:new Date(n.timestamp).toLocaleString()}),e.jsxs("span",{className:"text-[11px] text-muted-foreground",children:["#",n.id]})]})}),e.jsx(y,{children:e.jsx(k,{variant:"outline",className:"text-[11px]",children:n.endpoint==="anthropic"?a("logs.endpointAnthropic"):n.endpoint==="openai"?a("logs.endpointOpenAI"):n.endpoint})}),e.jsx(y,{children:e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"font-medium",children:n.provider}),e.jsx("span",{className:"text-[11px] text-muted-foreground",children:n.stream?"stream":"sync"})]})}),e.jsx(y,{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:n.client_model??a("dashboard.recent.routePlaceholder")}),e.jsx("span",{children:"->"}),e.jsx("span",{className:"font-medium text-foreground",children:n.model})]}),n.error?e.jsx("span",{className:"truncate text-destructive",children:n.error}):null]})}),e.jsx(y,{className:"text-right font-medium",children:R(n.latency_ms,a("common.units.ms"))}),e.jsx(y,{children:e.jsx(k,{variant:i.variant,className:"min-w-14 justify-center",children:i.label})})]},n.id)})})]})})})}function oe({className:s,compact:t,featured:a,icon:r,label:o,value:c,suffix:l,valueTestId:n}){return e.jsxs("div",{className:C("group flex flex-col justify-between rounded-[1.15rem] border border-white/70 bg-card/95 shadow-[0_18px_42px_-36px_rgba(15,23,42,0.24)] transition-all hover:-translate-y-0.5 hover:shadow-[0_24px_48px_-38px_rgba(59,130,246,0.2)] dark:border-white/10 dark:bg-slate-950/90 dark:shadow-[0_18px_42px_-36px_rgba(0,0,0,0.72)] dark:hover:shadow-[0_24px_48px_-38px_rgba(59,130,246,0.28)]",a?"bg-[linear-gradient(135deg,hsl(var(--primary)/0.1),rgba(255,255,255,0.95)_46%,rgba(236,253,245,0.74))] p-5 dark:!bg-none dark:!bg-slate-950/90":t?"p-3.5":"p-5",s),children:[e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[e.jsx("span",{className:C("inline-flex h-7 w-7 items-center justify-center rounded-lg bg-primary/10 text-primary",t&&"h-6 w-6 rounded-md"),children:r}),e.jsx("span",{children:o})]}),e.jsxs("p",{className:C("metric-number mt-3 font-semibold tracking-tight text-foreground",a?"text-3xl":t?"text-lg":"text-2xl"),"data-testid":n,children:[c,l?e.jsx("span",{className:"ml-1 text-sm font-normal text-muted-foreground",children:l}):null]})]})}function A({featured:s,label:t,value:a,hint:r}){return e.jsx(F,{className:s?"overflow-hidden bg-[linear-gradient(135deg,rgba(255,255,255,0.98),hsl(var(--primary)/0.08))] dark:!bg-none dark:!bg-card dark:border-white/10 dark:shadow-[0_18px_42px_-36px_rgba(0,0,0,0.72)]":void 0,children:e.jsxs($,{className:C("pt-4",s&&"pb-4"),children:[e.jsx("p",{className:"text-[11px] font-medium uppercase tracking-wider text-muted-foreground",children:t}),e.jsx("p",{className:C("mt-2 line-clamp-1 font-semibold text-foreground",s?"metric-number text-2xl tracking-tight":"text-base"),children:a}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:r})]})})}function D({description:s,empty:t,emptyText:a,loading:r,option:o,title:c}){const{t:l}=T();return e.jsx(F,{children:e.jsxs($,{className:"space-y-4 pt-5",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-semibold",children:c}),e.jsx("p",{className:"mt-0.5 text-xs text-muted-foreground/70",children:s})]}),r?e.jsx(V,{compact:!0,className:"min-h-[220px]",label:l("common.loadingShort")}):t?e.jsx(z,{compact:!0,className:"min-h-[188px] rounded-[1rem] border border-dashed border-border/45 bg-secondary/35",icon:e.jsx(G,{className:"h-5 w-5","aria-hidden":"true"}),title:a??l("dashboard.charts.empty"),description:s}):e.jsx("div",{className:"pt-2",children:e.jsx(Je,{echarts:st,option:o,className:"h-[40vh] min-h-[280px] max-h-[420px]",notMerge:!0,lazyUpdate:!0})})]})})}function ht(){var K,W,Y,Z,J,X,ee,te;const{t:s}=T(),{pushToast:t}=Ge(),[a,r]=ze(Ue.dashboard.endpointFilter,"all"),[o,c]=u.useState(!1),l=a==="all"?void 0:a,n=L(I.customEndpoints.all(),{url:"/api/custom-endpoints",method:"GET"},{refetchInterval:H,refetchIntervalInBackground:!0}),i=L(I.stats.overview(a),{url:"/api/stats/overview",method:"GET",params:l?{endpoint:l}:void 0},{refetchInterval:M,refetchIntervalInBackground:!0}),m=L(I.stats.daily(14,a),{url:"/api/stats/daily",method:"GET",params:{days:14,...l?{endpoint:l}:{}}},{refetchInterval:H,refetchIntervalInBackground:!0}),v=L(I.stats.model(7,6,a),{url:"/api/stats/model",method:"GET",params:{days:7,limit:6,...l?{endpoint:l}:{}}},{refetchInterval:H,refetchIntervalInBackground:!0}),g=L(I.status.byEndpoint(a),{url:"/api/status",method:"GET",params:l?{endpoint:l}:void 0},{refetchInterval:M,refetchIntervalInBackground:!0}),x=L(I.db.info(),{url:"/api/db/info",method:"GET"},{refetchInterval:M,refetchIntervalInBackground:!0}),N=L(I.logs.recent(a),{url:"/api/logs",method:"GET",params:{limit:5,...l?{endpoint:l}:{}}},{refetchInterval:M,refetchIntervalInBackground:!0});u.useEffect(()=>{i.isError&&i.error&&t({title:s("dashboard.toast.overviewError"),description:i.error.message,variant:"error"})},[i.error,i.isError,t,s]),u.useEffect(()=>{m.isError&&m.error&&t({title:s("dashboard.toast.dailyError"),description:m.error.message,variant:"error"})},[m.error,m.isError,t,s]),u.useEffect(()=>{v.isError&&v.error&&t({title:s("dashboard.toast.modelError"),description:v.error.message,variant:"error"})},[v.error,v.isError,t,s]),u.useEffect(()=>{g.isError&&g.error&&t({title:s("dashboard.toast.statusError"),description:g.error.message,variant:"error"})},[g.error,g.isError,t,s]),u.useEffect(()=>{x.isError&&x.error&&t({title:s("dashboard.toast.dbError"),description:x.error.message,variant:"error"})},[x.error,x.isError,t,s]),u.useEffect(()=>{N.isError&&N.error&&t({title:s("dashboard.toast.recentError"),description:N.error.message,variant:"error"})},[N.error,N.isError,t,s]);const me=u.useCallback(async()=>{await Promise.all([n.refetch(),i.refetch(),m.refetch(),v.refetch(),g.refetch(),x.refetch(),N.refetch()])},[n,x,m,N,v,i,g]),he=u.useCallback(async()=>{if(!o){c(!0);try{await He.post("/api/db/compact"),await x.refetch(),t({title:s("dashboard.toast.compactSuccess.title"),description:s("dashboard.toast.compactSuccess.desc"),variant:"success"})}catch(d){const h=Qe(d);t({title:s("dashboard.toast.compactError.title"),description:h.message,variant:"error"})}finally{c(!1)}}},[o,x,t,s]),pe=i.data,w=m.data??[],p=v.data??[],xe=g.data,E=x.data,ue=((K=N.data)==null?void 0:K.items)??[],ge=a==="all"?s("dashboard.filters.endpointAll"):a==="anthropic"?s("dashboard.filters.endpointAnthropic"):a==="openai"?s("dashboard.filters.endpointOpenAI"):((Z=(Y=(W=n.data)==null?void 0:W.endpoints)==null?void 0:Y.find(d=>d.id===a))==null?void 0:Z.label)||a,be=w.reduce((d,h)=>d+h.requestCount,0),fe=w.reduce((d,h)=>!d||h.requestCount>d.requestCount?h:d,null),je=p[0],ye=p.filter(d=>d.avgTtftMs!=null&&d.avgTtftMs>0).sort((d,h)=>(d.avgTtftMs??Number.POSITIVE_INFINITY)-(h.avgTtftMs??Number.POSITIVE_INFINITY))[0],ve=n.isFetching||i.isFetching||m.isFetching||v.isFetching||g.isFetching||x.isFetching||N.isFetching,Ne=i.isPending||g.isPending||x.isPending,we=((J=i.error)==null?void 0:J.message)??((X=g.error)==null?void 0:X.message)??((ee=x.error)==null?void 0:ee.message)??null,Se=E?U(E.totalBytes??E.sizeBytes):"-",Te=U(E==null?void 0:E.memoryRssBytes),Ee=u.useMemo(()=>{const d=w.map(f=>f.date),h=s("dashboard.charts.barRequests"),_=s("dashboard.charts.lineInput"),P=s("dashboard.charts.lineOutput"),b=s("dashboard.charts.lineCacheRead"),se=s("dashboard.charts.lineCacheCreation");return{tooltip:{trigger:"axis"},legend:{data:[h,_,P,b,se]},grid:{left:56,right:28,top:56,bottom:54},xAxis:{type:"category",data:d},yAxis:{type:"value"},series:[{name:h,type:"bar",data:w.map(f=>f.requestCount),itemStyle:{color:S.requests,borderRadius:[6,6,0,0]}},{name:_,type:"line",smooth:!0,data:w.map(f=>f.inputTokens),itemStyle:{color:S.input},lineStyle:{width:2}},{name:P,type:"line",smooth:!0,data:w.map(f=>f.outputTokens),itemStyle:{color:S.output},lineStyle:{width:2}},{name:b,type:"line",smooth:!0,data:w.map(f=>f.cacheReadTokens),itemStyle:{color:S.cacheRead},lineStyle:{width:2}},{name:se,type:"line",smooth:!0,data:w.map(f=>f.cacheCreationTokens),itemStyle:{color:S.cacheCreation},lineStyle:{width:2}}]}},[w,s]),Ie=u.useMemo(()=>{const d=p.map(b=>`${b.provider}/${b.model}`),h=s("dashboard.charts.barRequests"),_=s("dashboard.charts.lineInput"),P=s("dashboard.charts.lineOutput");return{tooltip:{trigger:"axis"},legend:{data:[h,_,P]},grid:{left:72,right:52,top:56,bottom:96},xAxis:{type:"category",data:d,axisLabel:{rotate:28}},yAxis:[{type:"value",name:h},{type:"value",name:s("dashboard.charts.axisTokens"),position:"right"}],series:[{name:h,type:"bar",data:p.map(b=>b.requests),itemStyle:{color:S.requests,borderRadius:[6,6,0,0]}},{name:_,type:"line",yAxisIndex:1,smooth:!0,data:p.map(b=>b.inputTokens??0),itemStyle:{color:S.input}},{name:P,type:"line",yAxisIndex:1,smooth:!0,data:p.map(b=>b.outputTokens??0),itemStyle:{color:S.output}}]}},[p,s]),Le=u.useMemo(()=>({tooltip:{trigger:"axis"},grid:{left:72,right:40,top:56,bottom:96},xAxis:{type:"category",data:p.map(d=>`${d.provider}/${d.model}`),axisLabel:{rotate:28}},yAxis:{type:"value",name:s("dashboard.charts.ttftAxis")},series:[{name:s("dashboard.charts.ttftLabel"),type:"bar",data:p.map(d=>d.avgTtftMs??0),itemStyle:{color:S.latency,borderRadius:[6,6,0,0]}}]}),[p,s]),ke=u.useMemo(()=>({tooltip:{trigger:"axis"},grid:{left:72,right:40,top:56,bottom:96},xAxis:{type:"category",data:p.map(d=>`${d.provider}/${d.model}`),axisLabel:{rotate:28}},yAxis:{type:"value",name:s("dashboard.charts.tpotAxis")},series:[{name:s("dashboard.charts.tpotLabel"),type:"bar",data:p.map(d=>d.avgTpotMs??0),itemStyle:{color:S.output,borderRadius:[6,6,0,0]}}]}),[p,s]);return{compacting:o,customEndpoints:((te=n.data)==null?void 0:te.endpoints)??[],daily:w,dailyOption:Ee,dailyPending:m.isPending,dbInfo:E,dbSizeDisplay:Se,endpointFilter:a,fastestTtftModel:ye,handleCompact:he,handleRefresh:me,bootstrapError:we,isBootstrapping:Ne,isRefreshing:ve,latestLogsPending:N.isPending,memoryDisplay:Te,modelRequestsOption:Ie,modelUsagePending:v.isPending,models:p,overview:pe,recentLogs:ue,selectedEndpointLabel:ge,setEndpointFilter:r,status:xe,topModel:je,totalRequestsInRange:be,busiestDay:fe,ttftOption:Le,tpotOption:ke}}function Pt(){var r,o;const{t:s}=T(),t=ht(),a=t.recentLogs.length===0||t.models.length===0;return e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx($e,{icon:e.jsx(G,{className:"h-5 w-5","aria-hidden":"true"}),title:s("nav.dashboard"),description:s("dashboard.description"),badge:t.selectedEndpointLabel,eyebrow:"Operations",breadcrumb:"Gateway / Dashboard",helper:s("dashboard.charts.requestsDesc"),actions:e.jsxs("div",{className:"flex w-full flex-col gap-2 sm:w-auto sm:flex-row sm:flex-wrap sm:items-center sm:justify-end",children:[e.jsxs("div",{className:"text-xs text-muted-foreground/60",children:[s("dashboard.filters.endpoint")," · ",t.selectedEndpointLabel]}),e.jsxs(Ve,{value:t.endpointFilter,onValueChange:t.setEndpointFilter,children:[e.jsx(Ke,{className:"w-full sm:w-[168px]",children:e.jsx(We,{})}),e.jsxs(Ye,{children:[e.jsx(q,{value:"all",children:s("dashboard.filters.endpointAll")}),e.jsx(q,{value:"anthropic",children:s("dashboard.filters.endpointAnthropic")}),e.jsx(q,{value:"openai",children:s("dashboard.filters.endpointOpenAI")}),t.customEndpoints.map(c=>e.jsx(q,{value:c.id,children:c.label||c.id},c.id))]})]}),e.jsxs(B,{variant:"outline",size:"sm",onClick:()=>void t.handleRefresh(),disabled:t.isRefreshing,className:"w-full sm:w-auto",children:[e.jsx(Oe,{className:C("mr-2 h-4 w-4",t.isRefreshing&&"animate-spin"),"aria-hidden":"true"}),t.isRefreshing?s("common.actions.refreshing"):s("common.actions.refresh")]}),e.jsxs(B,{variant:"outline",size:"sm",onClick:()=>void t.handleCompact(),disabled:t.compacting,className:"w-full sm:w-auto",children:[e.jsx(ne,{className:"mr-2 h-4 w-4","aria-hidden":"true"}),t.compacting?s("dashboard.actions.compacting"):s("dashboard.actions.compact")]})]})}),t.isBootstrapping?e.jsx(rt,{}):t.bootstrapError?e.jsx(z,{icon:e.jsx(Fe,{className:"h-5 w-5","aria-hidden":"true"}),tone:"danger",title:s("common.status.error"),description:t.bootstrapError,action:e.jsx(B,{variant:"outline",onClick:()=>void t.handleRefresh(),children:s("common.actions.refresh")})}):e.jsxs(e.Fragment,{children:[e.jsx(ot,{selectedEndpointLabel:t.selectedEndpointLabel,status:t.status,todayRequests:((r=t.overview)==null?void 0:r.today.requests)??0}),a?e.jsx(dt,{endpointCount:t.customEndpoints.length,providerCount:((o=t.status)==null?void 0:o.providers)??0,selectedEndpointLabel:t.selectedEndpointLabel}):null,e.jsx(nt,{dbSizeDisplay:t.dbSizeDisplay,memoryDisplay:t.memoryDisplay,overview:t.overview,status:t.status}),e.jsx(it,{busiestDay:t.busiestDay,fastestTtftModel:t.fastestTtftModel,topModel:t.topModel,totalRequestsInRange:t.totalRequestsInRange}),e.jsx(lt,{dailyEmpty:!t.daily.length,dailyOption:t.dailyOption,dailyPending:t.dailyPending,models:t.models,modelRequestsOption:t.modelRequestsOption,modelUsagePending:t.modelUsagePending,ttftOption:t.ttftOption,tpotOption:t.tpotOption}),e.jsx(ct,{models:t.models,loading:t.modelUsagePending}),e.jsx(mt,{records:t.recentLogs,loading:t.latestLogsPending})]})]})}export{Pt as default};
1
+ import{j as e,ap as Ce,af as Re,W as Q,ak as _e,aq as Pe,ar as qe,O as G,as as Me,at as Ae,au as De,av as ne,aw as Be,r as u,ax as Oe,U as Fe}from"./vendor-z22RpOY0.js";import{P as $e}from"./PageHeader-DCqHI67a.js";import{P as V,a as z}from"./PageState-B03H5AV0.js";import{B,u as Ge,a as ze,b as He,t as Qe,s as Ue}from"./app-COiQeF3y.js";import{S as Ve,a as Ke,b as We,c as Ye,d as q}from"./select-BchX45jJ.js";import{c as C}from"./global-B-NXh5qD.js";import{L as Ze}from"./router-CL3rf_uf.js";import{T as ie,a as de,b as O,c as j,d as le,e as y,E as Je}from"./table-DdvG93mx.js";import{P as ce}from"./PageSection-CuZMzA0E.js";import{S as Xe,C as et,T as tt}from"./Skeleton-i1PjWApN.js";import{B as k,q as I}from"./queryKeys-ucXCzh0P.js";import{C as F,a as $}from"./card-ChFVaqLf.js";import{g as ae}from"./utils-DSaa7c6v.js";import{u as T}from"./i18n-Bl2BcCDG.js";import{e as st}from"./charts-core-DzWzxST6.js";import{u as L}from"./useApiQuery-tbd4JJaZ.js";import"./query-BbGWgOFk.js";import"./radix-mHySgtou.js";import"./charts-react-D0nWbUCA.js";import"./charts-engine-Ds7lwC51.js";const M=15e3,H=6e4,S={requests:"#2563eb",input:"#059669",output:"#ea580c",cacheRead:"#7c3aed",cacheCreation:"#e11d48",latency:"#0891b2"};function R(s,t,a){return s==null?"-":`${s.toLocaleString(void 0,a)} ${t}`}function U(s){if(s==null)return"-";if(s<1024)return`${s} B`;const t=["KB","MB","GB","TB"];let a=s/1024,r=0;for(;a>=1024&&r<t.length-1;)a/=1024,r+=1;return`${a.toFixed(a>=100?0:a>=10?1:2)} ${t[r]}`}function re(s){if(s==null)return"-";const t=s<1?0:s;return t<1024?`${t.toLocaleString(void 0,{maximumFractionDigits:t>=100?0:t>=10?1:2})} B/s`:`${U(t)}/s`}function at(s){return s==null?"-":`${s.toLocaleString(void 0,{maximumFractionDigits:s>=10?0:1})}%`}function rt(){return e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx("div",{className:"h-20 animate-pulse rounded-xl bg-card shadow-[var(--surface-shadow)]"}),e.jsx("div",{className:"grid gap-4 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4",children:Array.from({length:12}).map((s,t)=>e.jsx(Xe,{},t))}),e.jsx("div",{className:"grid gap-6 lg:grid-cols-2",children:Array.from({length:4}).map((s,t)=>e.jsx(et,{},t))}),e.jsx("div",{className:"rounded-xl bg-card shadow-[var(--surface-shadow)]",children:e.jsx("table",{className:"w-full",children:e.jsx("tbody",{children:Array.from({length:5}).map((s,t)=>e.jsx(tt,{columns:6},t))})})})]})}function ot({selectedEndpointLabel:s,status:t,todayRequests:a}){const{t:r}=T();return e.jsxs("div",{className:"flex flex-col gap-4 rounded-xl bg-card p-6 shadow-[var(--surface-shadow)] sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"flex h-10 w-10 items-center justify-center rounded-lg bg-primary/10",children:e.jsx(Ce,{className:"h-5 w-5 text-primary","aria-hidden":"true"})}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h2",{className:"text-lg font-semibold text-foreground",children:s}),e.jsx(k,{variant:"success",children:r("dashboard.status.listeningLabel")})]}),e.jsxs("p",{className:"mt-0.5 text-sm text-muted-foreground",children:[(t==null?void 0:t.host)??"0.0.0.0",":",(t==null?void 0:t.port)??"-",e.jsx("span",{className:"mx-2 text-border",children:"·"}),r("dashboard.labels.todayRequests"),": ",a.toLocaleString(),e.jsx("span",{className:"mx-2 text-border",children:"·"}),r("dashboard.labels.providers"),": ",((t==null?void 0:t.providers)??0).toLocaleString()]})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-3 text-sm text-muted-foreground",children:[e.jsxs("span",{children:[r("dashboard.labels.activeClientAddresses"),": ",e.jsx("strong",{className:"text-foreground",children:((t==null?void 0:t.activeClientAddresses)??0).toLocaleString()})]}),e.jsx("span",{className:"text-border",children:"·"}),e.jsxs("span",{children:[r("dashboard.labels.activeClientSessions"),": ",e.jsx("strong",{className:"text-foreground",children:((t==null?void 0:t.activeClientSessions)??0).toLocaleString()})]})]})]})}function nt({dbSizeDisplay:s,memoryDisplay:t,overview:a,status:r}){const{t:o}=T(),c=[{icon:e.jsx(Re,{className:"h-4 w-4"}),label:o("dashboard.labels.activeRequests"),value:((r==null?void 0:r.activeRequests)??0).toLocaleString(),testId:"dashboard-spotlight-value-active"},{icon:e.jsx(Q,{className:"h-4 w-4"}),label:o("dashboard.labels.requestsPerMinute"),value:((r==null?void 0:r.requestsPerMinute)??0).toLocaleString(),testId:"dashboard-spotlight-value-rpm"},{icon:e.jsx(_e,{className:"h-4 w-4"}),label:o("dashboard.labels.outputTokensPerMinute"),value:((r==null?void 0:r.outputTokensPerMinute)??0).toLocaleString(),testId:"dashboard-spotlight-value-tpm"},{icon:e.jsx(Pe,{className:"h-4 w-4"}),label:o("dashboard.labels.cpu"),value:at(r==null?void 0:r.cpuUsagePercent),testId:"dashboard-spotlight-value-cpu"}],l=[{icon:e.jsx(Q,{className:"h-4 w-4"}),label:o("dashboard.cards.todayRequests"),value:((a==null?void 0:a.today.requests)??0).toLocaleString(),suffix:o("common.units.request")},{icon:e.jsx(qe,{className:"h-4 w-4"}),label:o("dashboard.cards.todayInput"),value:((a==null?void 0:a.today.inputTokens)??0).toLocaleString(),suffix:o("common.units.token")},{icon:e.jsx(G,{className:"h-4 w-4"}),label:o("dashboard.cards.todayOutput"),value:((a==null?void 0:a.today.outputTokens)??0).toLocaleString(),suffix:o("common.units.token")},{icon:e.jsx(Me,{className:"h-4 w-4"}),label:o("dashboard.cards.avgLatency"),value:R((a==null?void 0:a.today.avgLatencyMs)??0,o("common.units.ms"))},{icon:e.jsx(Ae,{className:"h-4 w-4"}),label:o("dashboard.labels.networkIngress"),value:re(r==null?void 0:r.networkIngressBytesPerSecond),testId:"dashboard-spotlight-value-ingress"},{icon:e.jsx(De,{className:"h-4 w-4"}),label:o("dashboard.labels.networkEgress"),value:re(r==null?void 0:r.networkEgressBytesPerSecond),testId:"dashboard-spotlight-value-egress"},{icon:e.jsx(ne,{className:"h-4 w-4"}),label:o("dashboard.labels.database"),value:s,testId:"dashboard-spotlight-value-database"},{icon:e.jsx(Be,{className:"h-4 w-4"}),label:o("dashboard.labels.memory"),value:t,testId:"dashboard-spotlight-value-memory"}];return e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"grid gap-3 md:grid-cols-2 xl:grid-cols-5",children:c.map((n,i)=>e.jsx(oe,{className:i===0?"md:col-span-2 xl:col-span-2":void 0,featured:i===0,icon:n.icon,label:n.label,value:n.value,valueTestId:n.testId},n.label))}),e.jsx("div",{className:"grid gap-2.5 sm:grid-cols-2 lg:grid-cols-4",children:l.map(n=>e.jsx(oe,{compact:!0,icon:n.icon,label:n.label,suffix:n.suffix,value:n.value,valueTestId:n.testId},n.label))})]})}function it({busiestDay:s,fastestTtftModel:t,topModel:a,totalRequestsInRange:r}){const{t:o}=T();return e.jsxs("div",{className:"grid gap-3 lg:grid-cols-[1.4fr_repeat(3,minmax(0,1fr))]",children:[e.jsx(A,{featured:!0,label:o("dashboard.insights.totalRequests"),value:r.toLocaleString(),hint:o("dashboard.insights.totalRequestsHint")}),e.jsx(A,{label:o("dashboard.insights.busiestDay"),value:s?s.date:"-",hint:s?o("dashboard.insights.busiestDayHint",{value:s.requestCount.toLocaleString()}):o("common.noData")}),e.jsx(A,{label:o("dashboard.insights.topModel"),value:a?`${a.provider}/${a.model}`:"-",hint:a?o("dashboard.insights.topModelHint",{value:a.requests.toLocaleString()}):o("common.noData")}),e.jsx(A,{label:o("dashboard.insights.fastestTtft"),value:t?`${t.provider}/${t.model}`:"-",hint:t?R(t.avgTtftMs,o("common.units.ms")):o("common.noData")})]})}function dt({endpointCount:s,providerCount:t,selectedEndpointLabel:a}){const r=[{title:"先配置 Provider",description:t>0?`当前已检测到 ${t} 个 Provider,可直接继续下一步。`:"先在模型供应商里接入至少 1 个上游模型服务。",href:"/models",cta:"去模型供应商",tone:"from-indigo-100 to-cyan-100"},{title:"确认默认路由入口",description:s>0?`当前已有 ${s} 个自定义端点,可继续检查默认映射是否合理。`:"把一个端点或默认路由配置清楚,后续客户端就能稳定接入。",href:"/routing",cta:"去路由管理",tone:"from-violet-100 to-fuchsia-100"},{title:"发起第一条真实请求",description:"创建 API Key,然后从常用客户端打进来一条请求,让日志、路由和延迟开始有数据。",href:"/api-keys",cta:"去 API 密钥",tone:"from-emerald-100 to-cyan-100"}];return e.jsxs("div",{className:"grid gap-4 xl:grid-cols-[minmax(0,1.2fr)_minmax(300px,0.8fr)]",children:[e.jsx(F,{className:"overflow-hidden border-white/80 bg-[linear-gradient(135deg,rgba(255,255,255,0.98),hsl(var(--primary)/0.08),rgba(236,253,245,0.8))] shadow-[0_22px_56px_-40px_rgba(15,23,42,0.24)]",children:e.jsxs($,{className:"space-y-5 pt-5",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"inline-flex items-center rounded-full bg-primary/10 px-3 py-1 text-[11px] font-semibold uppercase tracking-[0.16em] text-primary",children:"Cold Start Guide"}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold text-foreground",children:"当前还是冷启动状态,这是正常的"}),e.jsx("p",{className:"mt-1.5 text-sm leading-6 text-muted-foreground",children:"这个仪表盘会在第一条真实请求进来后明显更有价值。现在最适合做的是把 Provider、路由和 API Key 三件事顺次走通。"})]})]}),e.jsx("div",{className:"grid gap-3 lg:grid-cols-3",children:r.map((o,c)=>e.jsxs("div",{className:"rounded-[1.1rem] border border-white/70 bg-card/88 p-4 shadow-[0_16px_40px_-34px_rgba(15,23,42,0.18)]",children:[e.jsxs("div",{className:C("flex h-10 w-10 items-center justify-center rounded-2xl bg-gradient-to-br text-sm font-semibold text-primary",o.tone),children:["0",c+1]}),e.jsx("h4",{className:"mt-3 text-sm font-semibold text-foreground",children:o.title}),e.jsx("p",{className:"mt-1.5 text-xs leading-6 text-muted-foreground",children:o.description}),e.jsx(B,{asChild:!0,variant:"ghost",size:"sm",className:"mt-3 h-8 rounded-full px-0 text-primary hover:bg-transparent hover:text-primary/80",children:e.jsx(Ze,{to:o.href,children:o.cta})})]},o.title))})]})}),e.jsx(F,{className:"border-white/80 bg-card/96 shadow-[0_20px_48px_-40px_rgba(15,23,42,0.24)]",children:e.jsxs($,{className:"space-y-4 pt-5",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-[0.16em] text-muted-foreground/80",children:"Workspace Snapshot"}),e.jsx("h3",{className:"mt-2 text-base font-semibold text-foreground",children:a}),e.jsx("p",{className:"mt-1 text-xs leading-6 text-muted-foreground",children:"等第一批流量进来后,这里会逐步展示趋势、模型表现和最近请求。"})]}),e.jsx("div",{className:"grid gap-3 sm:grid-cols-3 xl:grid-cols-1",children:[{label:"已配置 Provider",value:String(t)},{label:"自定义端点",value:String(s)},{label:"建议下一步",value:"发起请求"}].map(o=>e.jsxs("div",{className:"rounded-[1rem] bg-secondary/45 px-4 py-3 ring-1 ring-white/70",children:[e.jsx("div",{className:"text-[11px] font-medium text-muted-foreground",children:o.label}),e.jsx("div",{className:"mt-1 text-lg font-semibold text-foreground",children:o.value})]},o.label))}),e.jsx("div",{className:"rounded-[1rem] border border-dashed border-border/45 bg-secondary/35 px-4 py-3",children:e.jsxs("p",{className:"text-xs leading-6 text-muted-foreground",children:["如果你还没确定从哪一步开始,优先去 ",e.jsx("span",{className:"font-medium text-foreground",children:"API 密钥"})," 创建一个客户端专用 key,再从常用工具发起一条最小请求。"]})})]})})]})}function lt({dailyEmpty:s,dailyOption:t,dailyPending:a,models:r,modelRequestsOption:o,modelUsagePending:c,ttftOption:l,tpotOption:n}){const{t:i}=T();return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid gap-6 lg:grid-cols-2",children:[e.jsx(D,{title:i("dashboard.charts.requestsTitle"),description:i("dashboard.charts.requestsDesc"),loading:a,option:t,empty:s,emptyText:i("dashboard.charts.empty")}),e.jsx(D,{title:i("dashboard.charts.modelTitle"),description:i("dashboard.charts.modelDesc"),loading:c,option:o,empty:!r.length,emptyText:i("dashboard.charts.empty")})]}),e.jsxs("div",{className:"grid gap-6 lg:grid-cols-2",children:[e.jsx(D,{title:i("dashboard.charts.ttftTitle"),description:i("dashboard.charts.ttftDesc"),loading:c,option:l,empty:!r.some(m=>m.avgTtftMs!=null&&m.avgTtftMs>0),emptyText:i("dashboard.charts.ttftEmpty")}),e.jsx(D,{title:i("dashboard.charts.tpotTitle"),description:i("dashboard.charts.tpotDesc"),loading:c,option:n,empty:!r.some(m=>m.avgTpotMs!=null&&m.avgTpotMs>0),emptyText:i("dashboard.charts.tpotEmpty")})]})]})}function ct({models:s,loading:t}){const{t:a}=T();return e.jsx(ce,{title:a("dashboard.modelTable.title"),description:a("dashboard.modelTable.description"),children:t?e.jsx(V,{compact:!0,label:a("common.loadingShort")}):s.length===0?e.jsx(z,{compact:!0,icon:e.jsx(G,{className:"h-5 w-5","aria-hidden":"true"}),title:a("dashboard.modelTable.empty")}):e.jsx("div",{className:"overflow-auto",children:e.jsxs(ie,{children:[e.jsx(de,{children:e.jsxs(O,{children:[e.jsx(j,{children:a("dashboard.modelTable.columns.model")}),e.jsx(j,{className:"text-right",children:a("dashboard.modelTable.columns.requests")}),e.jsx(j,{className:"text-right",children:a("dashboard.modelTable.columns.latency")}),e.jsx(j,{className:"text-right",children:a("dashboard.modelTable.columns.ttft")}),e.jsx(j,{className:"text-right",children:a("dashboard.modelTable.columns.tpot")})]})}),e.jsx(le,{children:s.map(r=>e.jsxs(O,{children:[e.jsx(y,{children:e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"font-medium",children:r.provider}),e.jsx("span",{className:"text-xs text-muted-foreground",children:r.model})]})}),e.jsx(y,{className:"text-right font-medium",children:r.requests.toLocaleString()}),e.jsx(y,{className:"text-right",children:R(r.avgLatencyMs,a("common.units.ms"))}),e.jsx(y,{className:"text-right",children:R(r.avgTtftMs,a("common.units.ms"))}),e.jsx(y,{className:"text-right",children:R(r.avgTpotMs,a("common.units.msPerToken"),{maximumFractionDigits:2})})]},`${r.provider}/${r.model}`))})]})})})}function mt({records:s,loading:t}){const{t:a}=T(),r=s.map(n=>ae(n,a)),o=r.filter(n=>n.tone==="success").length,c=r.filter(n=>n.tone==="error").length,l=r.filter(n=>n.tone==="pending").length;return e.jsx(ce,{title:a("dashboard.recent.title"),description:a("dashboard.recent.subtitle",{count:5}),actions:s.length>0?e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(k,{variant:"secondary",children:s.length}),e.jsxs(k,{variant:"success",children:[a("common.status.success"),": ",o]}),e.jsxs(k,{variant:"outline",className:"border-destructive/30 bg-destructive/10 text-destructive",children:[a("common.status.error"),": ",c]}),l>0?e.jsxs(k,{variant:"warning",children:[a("common.status.pending"),": ",l]}):null]}):null,children:t?e.jsx(V,{compact:!0,label:a("dashboard.recent.loading")}):s.length===0?e.jsx(z,{compact:!0,icon:e.jsx(Q,{className:"h-5 w-5","aria-hidden":"true"}),title:a("dashboard.recent.empty")}):e.jsx("div",{className:"overflow-auto",children:e.jsxs(ie,{children:[e.jsx(de,{children:e.jsxs(O,{children:[e.jsx(j,{children:a("dashboard.recent.columns.time")}),e.jsx(j,{children:a("dashboard.recent.columns.endpoint")}),e.jsx(j,{children:a("dashboard.recent.columns.provider")}),e.jsx(j,{children:a("dashboard.recent.columns.route")}),e.jsx(j,{className:"text-right",children:a("dashboard.recent.columns.latency")}),e.jsx(j,{children:a("dashboard.recent.columns.status")})]})}),e.jsx(le,{children:s.map(n=>{const i=ae(n,a);return e.jsxs(O,{children:[e.jsx(y,{children:e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"text-xs font-medium",children:new Date(n.timestamp).toLocaleString()}),e.jsxs("span",{className:"text-[11px] text-muted-foreground",children:["#",n.id]})]})}),e.jsx(y,{children:e.jsx(k,{variant:"outline",className:"text-[11px]",children:n.endpoint==="anthropic"?a("logs.endpointAnthropic"):n.endpoint==="openai"?a("logs.endpointOpenAI"):n.endpoint})}),e.jsx(y,{children:e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"font-medium",children:n.provider}),e.jsx("span",{className:"text-[11px] text-muted-foreground",children:n.stream?"stream":"sync"})]})}),e.jsx(y,{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:n.client_model??a("dashboard.recent.routePlaceholder")}),e.jsx("span",{children:"->"}),e.jsx("span",{className:"font-medium text-foreground",children:n.model})]}),n.error?e.jsx("span",{className:"truncate text-destructive",children:n.error}):null]})}),e.jsx(y,{className:"text-right font-medium",children:R(n.latency_ms,a("common.units.ms"))}),e.jsx(y,{children:e.jsx(k,{variant:i.variant,className:"min-w-14 justify-center",children:i.label})})]},n.id)})})]})})})}function oe({className:s,compact:t,featured:a,icon:r,label:o,value:c,suffix:l,valueTestId:n}){return e.jsxs("div",{className:C("group flex flex-col justify-between rounded-[1.15rem] border border-white/70 bg-card/95 shadow-[0_18px_42px_-36px_rgba(15,23,42,0.24)] transition-all hover:-translate-y-0.5 hover:shadow-[0_24px_48px_-38px_rgba(59,130,246,0.2)] dark:border-white/10 dark:bg-slate-950/90 dark:shadow-[0_18px_42px_-36px_rgba(0,0,0,0.72)] dark:hover:shadow-[0_24px_48px_-38px_rgba(59,130,246,0.28)]",a?"bg-[linear-gradient(135deg,hsl(var(--primary)/0.1),rgba(255,255,255,0.95)_46%,rgba(236,253,245,0.74))] p-5 dark:!bg-none dark:!bg-slate-950/90":t?"p-3.5":"p-5",s),children:[e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[e.jsx("span",{className:C("inline-flex h-7 w-7 items-center justify-center rounded-lg bg-primary/10 text-primary",t&&"h-6 w-6 rounded-md"),children:r}),e.jsx("span",{children:o})]}),e.jsxs("p",{className:C("metric-number mt-3 font-semibold tracking-tight text-foreground",a?"text-3xl":t?"text-lg":"text-2xl"),"data-testid":n,children:[c,l?e.jsx("span",{className:"ml-1 text-sm font-normal text-muted-foreground",children:l}):null]})]})}function A({featured:s,label:t,value:a,hint:r}){return e.jsx(F,{className:s?"overflow-hidden bg-[linear-gradient(135deg,rgba(255,255,255,0.98),hsl(var(--primary)/0.08))] dark:!bg-none dark:!bg-card dark:border-white/10 dark:shadow-[0_18px_42px_-36px_rgba(0,0,0,0.72)]":void 0,children:e.jsxs($,{className:C("pt-4",s&&"pb-4"),children:[e.jsx("p",{className:"text-[11px] font-medium uppercase tracking-wider text-muted-foreground",children:t}),e.jsx("p",{className:C("mt-2 line-clamp-1 font-semibold text-foreground",s?"metric-number text-2xl tracking-tight":"text-base"),children:a}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:r})]})})}function D({description:s,empty:t,emptyText:a,loading:r,option:o,title:c}){const{t:l}=T();return e.jsx(F,{children:e.jsxs($,{className:"space-y-4 pt-5",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-semibold",children:c}),e.jsx("p",{className:"mt-0.5 text-xs text-muted-foreground/70",children:s})]}),r?e.jsx(V,{compact:!0,className:"min-h-[220px]",label:l("common.loadingShort")}):t?e.jsx(z,{compact:!0,className:"min-h-[188px] rounded-[1rem] border border-dashed border-border/45 bg-secondary/35",icon:e.jsx(G,{className:"h-5 w-5","aria-hidden":"true"}),title:a??l("dashboard.charts.empty"),description:s}):e.jsx("div",{className:"pt-2",children:e.jsx(Je,{echarts:st,option:o,className:"h-[40vh] min-h-[280px] max-h-[420px]",notMerge:!0,lazyUpdate:!0})})]})})}function ht(){var K,W,Y,Z,J,X,ee,te;const{t:s}=T(),{pushToast:t}=Ge(),[a,r]=ze(Ue.dashboard.endpointFilter,"all"),[o,c]=u.useState(!1),l=a==="all"?void 0:a,n=L(I.customEndpoints.all(),{url:"/api/custom-endpoints",method:"GET"},{refetchInterval:H,refetchIntervalInBackground:!0}),i=L(I.stats.overview(a),{url:"/api/stats/overview",method:"GET",params:l?{endpoint:l}:void 0},{refetchInterval:M,refetchIntervalInBackground:!0}),m=L(I.stats.daily(14,a),{url:"/api/stats/daily",method:"GET",params:{days:14,...l?{endpoint:l}:{}}},{refetchInterval:H,refetchIntervalInBackground:!0}),v=L(I.stats.model(7,6,a),{url:"/api/stats/model",method:"GET",params:{days:7,limit:6,...l?{endpoint:l}:{}}},{refetchInterval:H,refetchIntervalInBackground:!0}),g=L(I.status.byEndpoint(a),{url:"/api/status",method:"GET",params:l?{endpoint:l}:void 0},{refetchInterval:M,refetchIntervalInBackground:!0}),x=L(I.db.info(),{url:"/api/db/info",method:"GET"},{refetchInterval:M,refetchIntervalInBackground:!0}),N=L(I.logs.recent(a),{url:"/api/logs",method:"GET",params:{limit:5,...l?{endpoint:l}:{}}},{refetchInterval:M,refetchIntervalInBackground:!0});u.useEffect(()=>{i.isError&&i.error&&t({title:s("dashboard.toast.overviewError"),description:i.error.message,variant:"error"})},[i.error,i.isError,t,s]),u.useEffect(()=>{m.isError&&m.error&&t({title:s("dashboard.toast.dailyError"),description:m.error.message,variant:"error"})},[m.error,m.isError,t,s]),u.useEffect(()=>{v.isError&&v.error&&t({title:s("dashboard.toast.modelError"),description:v.error.message,variant:"error"})},[v.error,v.isError,t,s]),u.useEffect(()=>{g.isError&&g.error&&t({title:s("dashboard.toast.statusError"),description:g.error.message,variant:"error"})},[g.error,g.isError,t,s]),u.useEffect(()=>{x.isError&&x.error&&t({title:s("dashboard.toast.dbError"),description:x.error.message,variant:"error"})},[x.error,x.isError,t,s]),u.useEffect(()=>{N.isError&&N.error&&t({title:s("dashboard.toast.recentError"),description:N.error.message,variant:"error"})},[N.error,N.isError,t,s]);const me=u.useCallback(async()=>{await Promise.all([n.refetch(),i.refetch(),m.refetch(),v.refetch(),g.refetch(),x.refetch(),N.refetch()])},[n,x,m,N,v,i,g]),he=u.useCallback(async()=>{if(!o){c(!0);try{await He.post("/api/db/compact"),await x.refetch(),t({title:s("dashboard.toast.compactSuccess.title"),description:s("dashboard.toast.compactSuccess.desc"),variant:"success"})}catch(d){const h=Qe(d);t({title:s("dashboard.toast.compactError.title"),description:h.message,variant:"error"})}finally{c(!1)}}},[o,x,t,s]),pe=i.data,w=m.data??[],p=v.data??[],xe=g.data,E=x.data,ue=((K=N.data)==null?void 0:K.items)??[],ge=a==="all"?s("dashboard.filters.endpointAll"):a==="anthropic"?s("dashboard.filters.endpointAnthropic"):a==="openai"?s("dashboard.filters.endpointOpenAI"):((Z=(Y=(W=n.data)==null?void 0:W.endpoints)==null?void 0:Y.find(d=>d.id===a))==null?void 0:Z.label)||a,be=w.reduce((d,h)=>d+h.requestCount,0),fe=w.reduce((d,h)=>!d||h.requestCount>d.requestCount?h:d,null),je=p[0],ye=p.filter(d=>d.avgTtftMs!=null&&d.avgTtftMs>0).sort((d,h)=>(d.avgTtftMs??Number.POSITIVE_INFINITY)-(h.avgTtftMs??Number.POSITIVE_INFINITY))[0],ve=n.isFetching||i.isFetching||m.isFetching||v.isFetching||g.isFetching||x.isFetching||N.isFetching,Ne=i.isPending||g.isPending||x.isPending,we=((J=i.error)==null?void 0:J.message)??((X=g.error)==null?void 0:X.message)??((ee=x.error)==null?void 0:ee.message)??null,Se=E?U(E.totalBytes??E.sizeBytes):"-",Te=U(E==null?void 0:E.memoryRssBytes),Ee=u.useMemo(()=>{const d=w.map(f=>f.date),h=s("dashboard.charts.barRequests"),_=s("dashboard.charts.lineInput"),P=s("dashboard.charts.lineOutput"),b=s("dashboard.charts.lineCacheRead"),se=s("dashboard.charts.lineCacheCreation");return{tooltip:{trigger:"axis"},legend:{data:[h,_,P,b,se]},grid:{left:56,right:28,top:56,bottom:54},xAxis:{type:"category",data:d},yAxis:{type:"value"},series:[{name:h,type:"bar",data:w.map(f=>f.requestCount),itemStyle:{color:S.requests,borderRadius:[6,6,0,0]}},{name:_,type:"line",smooth:!0,data:w.map(f=>f.inputTokens),itemStyle:{color:S.input},lineStyle:{width:2}},{name:P,type:"line",smooth:!0,data:w.map(f=>f.outputTokens),itemStyle:{color:S.output},lineStyle:{width:2}},{name:b,type:"line",smooth:!0,data:w.map(f=>f.cacheReadTokens),itemStyle:{color:S.cacheRead},lineStyle:{width:2}},{name:se,type:"line",smooth:!0,data:w.map(f=>f.cacheCreationTokens),itemStyle:{color:S.cacheCreation},lineStyle:{width:2}}]}},[w,s]),Ie=u.useMemo(()=>{const d=p.map(b=>`${b.provider}/${b.model}`),h=s("dashboard.charts.barRequests"),_=s("dashboard.charts.lineInput"),P=s("dashboard.charts.lineOutput");return{tooltip:{trigger:"axis"},legend:{data:[h,_,P]},grid:{left:72,right:52,top:56,bottom:96},xAxis:{type:"category",data:d,axisLabel:{rotate:28}},yAxis:[{type:"value",name:h},{type:"value",name:s("dashboard.charts.axisTokens"),position:"right"}],series:[{name:h,type:"bar",data:p.map(b=>b.requests),itemStyle:{color:S.requests,borderRadius:[6,6,0,0]}},{name:_,type:"line",yAxisIndex:1,smooth:!0,data:p.map(b=>b.inputTokens??0),itemStyle:{color:S.input}},{name:P,type:"line",yAxisIndex:1,smooth:!0,data:p.map(b=>b.outputTokens??0),itemStyle:{color:S.output}}]}},[p,s]),Le=u.useMemo(()=>({tooltip:{trigger:"axis"},grid:{left:72,right:40,top:56,bottom:96},xAxis:{type:"category",data:p.map(d=>`${d.provider}/${d.model}`),axisLabel:{rotate:28}},yAxis:{type:"value",name:s("dashboard.charts.ttftAxis")},series:[{name:s("dashboard.charts.ttftLabel"),type:"bar",data:p.map(d=>d.avgTtftMs??0),itemStyle:{color:S.latency,borderRadius:[6,6,0,0]}}]}),[p,s]),ke=u.useMemo(()=>({tooltip:{trigger:"axis"},grid:{left:72,right:40,top:56,bottom:96},xAxis:{type:"category",data:p.map(d=>`${d.provider}/${d.model}`),axisLabel:{rotate:28}},yAxis:{type:"value",name:s("dashboard.charts.tpotAxis")},series:[{name:s("dashboard.charts.tpotLabel"),type:"bar",data:p.map(d=>d.avgTpotMs??0),itemStyle:{color:S.output,borderRadius:[6,6,0,0]}}]}),[p,s]);return{compacting:o,customEndpoints:((te=n.data)==null?void 0:te.endpoints)??[],daily:w,dailyOption:Ee,dailyPending:m.isPending,dbInfo:E,dbSizeDisplay:Se,endpointFilter:a,fastestTtftModel:ye,handleCompact:he,handleRefresh:me,bootstrapError:we,isBootstrapping:Ne,isRefreshing:ve,latestLogsPending:N.isPending,memoryDisplay:Te,modelRequestsOption:Ie,modelUsagePending:v.isPending,models:p,overview:pe,recentLogs:ue,selectedEndpointLabel:ge,setEndpointFilter:r,status:xe,topModel:je,totalRequestsInRange:be,busiestDay:fe,ttftOption:Le,tpotOption:ke}}function Pt(){var r,o;const{t:s}=T(),t=ht(),a=t.recentLogs.length===0||t.models.length===0;return e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx($e,{icon:e.jsx(G,{className:"h-5 w-5","aria-hidden":"true"}),title:s("nav.dashboard"),description:s("dashboard.description"),badge:t.selectedEndpointLabel,eyebrow:"Operations",breadcrumb:"Gateway / Dashboard",helper:s("dashboard.charts.requestsDesc"),actions:e.jsxs("div",{className:"flex w-full flex-col gap-2 sm:w-auto sm:flex-row sm:flex-wrap sm:items-center sm:justify-end",children:[e.jsxs("div",{className:"text-xs text-muted-foreground/60",children:[s("dashboard.filters.endpoint")," · ",t.selectedEndpointLabel]}),e.jsxs(Ve,{value:t.endpointFilter,onValueChange:t.setEndpointFilter,children:[e.jsx(Ke,{className:"w-full sm:w-[168px]",children:e.jsx(We,{})}),e.jsxs(Ye,{children:[e.jsx(q,{value:"all",children:s("dashboard.filters.endpointAll")}),e.jsx(q,{value:"anthropic",children:s("dashboard.filters.endpointAnthropic")}),e.jsx(q,{value:"openai",children:s("dashboard.filters.endpointOpenAI")}),t.customEndpoints.map(c=>e.jsx(q,{value:c.id,children:c.label||c.id},c.id))]})]}),e.jsxs(B,{variant:"outline",size:"sm",onClick:()=>void t.handleRefresh(),disabled:t.isRefreshing,className:"w-full sm:w-auto",children:[e.jsx(Oe,{className:C("mr-2 h-4 w-4",t.isRefreshing&&"animate-spin"),"aria-hidden":"true"}),t.isRefreshing?s("common.actions.refreshing"):s("common.actions.refresh")]}),e.jsxs(B,{variant:"outline",size:"sm",onClick:()=>void t.handleCompact(),disabled:t.compacting,className:"w-full sm:w-auto",children:[e.jsx(ne,{className:"mr-2 h-4 w-4","aria-hidden":"true"}),t.compacting?s("dashboard.actions.compacting"):s("dashboard.actions.compact")]})]})}),t.isBootstrapping?e.jsx(rt,{}):t.bootstrapError?e.jsx(z,{icon:e.jsx(Fe,{className:"h-5 w-5","aria-hidden":"true"}),tone:"danger",title:s("common.status.error"),description:t.bootstrapError,action:e.jsx(B,{variant:"outline",onClick:()=>void t.handleRefresh(),children:s("common.actions.refresh")})}):e.jsxs(e.Fragment,{children:[e.jsx(ot,{selectedEndpointLabel:t.selectedEndpointLabel,status:t.status,todayRequests:((r=t.overview)==null?void 0:r.today.requests)??0}),a?e.jsx(dt,{endpointCount:t.customEndpoints.length,providerCount:((o=t.status)==null?void 0:o.providers)??0,selectedEndpointLabel:t.selectedEndpointLabel}):null,e.jsx(nt,{dbSizeDisplay:t.dbSizeDisplay,memoryDisplay:t.memoryDisplay,overview:t.overview,status:t.status}),e.jsx(it,{busiestDay:t.busiestDay,fastestTtftModel:t.fastestTtftModel,topModel:t.topModel,totalRequestsInRange:t.totalRequestsInRange}),e.jsx(lt,{dailyEmpty:!t.daily.length,dailyOption:t.dailyOption,dailyPending:t.dailyPending,models:t.models,modelRequestsOption:t.modelRequestsOption,modelUsagePending:t.modelUsagePending,ttftOption:t.ttftOption,tpotOption:t.tpotOption}),e.jsx(ct,{models:t.models,loading:t.modelUsagePending}),e.jsx(mt,{records:t.recentLogs,loading:t.latestLogsPending})]})]})}export{Pt as default};
@@ -1 +1 @@
1
- import{r,j as s,a7 as g}from"./vendor-LWJeAdU1.js";import{F as u,G as d,H as n,J as y,K as l,M as b,O as i}from"./radix-bG5h1Ymq.js";import{c as o}from"./global-CKvMKvrn.js";const k=u,N=y,c=r.forwardRef(({className:a,...e},t)=>s.jsx(i,{ref:t,className:o("fixed inset-0 z-50 bg-background/80 backdrop-blur-sm data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",a),...e}));c.displayName=i.displayName;const p=r.forwardRef(({className:a,children:e,...t},x)=>s.jsxs(N,{children:[s.jsx(c,{}),s.jsxs(l,{ref:x,className:o("fixed left-[50%] top-[50%] z-50 flex max-h-[85vh] w-full max-w-lg translate-x-[-50%] translate-y-[-50%] flex-col gap-4 rounded-xl border border-border bg-background 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(b,{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(g,{className:"h-4 w-4"}),s.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));p.displayName=l.displayName;const m=({className:a,...e})=>s.jsx("div",{className:o("flex shrink-0 flex-col space-y-1.5 text-center sm:text-left",a),...e});m.displayName="DialogHeader";const f=({className:a,...e})=>s.jsx("div",{className:o("flex shrink-0 flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",a),...e});f.displayName="DialogFooter";const j=r.forwardRef(({className:a,...e},t)=>s.jsx(d,{ref:t,className:o("text-lg font-semibold leading-none tracking-[-0.02em]",a),...e}));j.displayName=d.displayName;const D=r.forwardRef(({className:a,...e},t)=>s.jsx(n,{ref:t,className:o("text-sm leading-6 text-muted-foreground",a),...e}));D.displayName=n.displayName;function R({children:a,className:e}){return s.jsx(p,{className:o("gap-0 overflow-hidden p-0",e),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(m,{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(f,{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};
1
+ import{r,j as s,a7 as g}from"./vendor-z22RpOY0.js";import{F as u,G as d,H as n,J as y,K as l,M as b,O as i}from"./radix-mHySgtou.js";import{c as o}from"./global-B-NXh5qD.js";const k=u,N=y,c=r.forwardRef(({className:a,...e},t)=>s.jsx(i,{ref:t,className:o("fixed inset-0 z-50 bg-background/80 backdrop-blur-sm data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",a),...e}));c.displayName=i.displayName;const p=r.forwardRef(({className:a,children:e,...t},x)=>s.jsxs(N,{children:[s.jsx(c,{}),s.jsxs(l,{ref:x,className:o("fixed left-[50%] top-[50%] z-50 flex max-h-[85vh] w-full max-w-lg translate-x-[-50%] translate-y-[-50%] flex-col gap-4 rounded-xl border border-border bg-background 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(b,{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(g,{className:"h-4 w-4"}),s.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));p.displayName=l.displayName;const m=({className:a,...e})=>s.jsx("div",{className:o("flex shrink-0 flex-col space-y-1.5 text-center sm:text-left",a),...e});m.displayName="DialogHeader";const f=({className:a,...e})=>s.jsx("div",{className:o("flex shrink-0 flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",a),...e});f.displayName="DialogFooter";const j=r.forwardRef(({className:a,...e},t)=>s.jsx(d,{ref:t,className:o("text-lg font-semibold leading-none tracking-[-0.02em]",a),...e}));j.displayName=d.displayName;const D=r.forwardRef(({className:a,...e},t)=>s.jsx(n,{ref:t,className:o("text-sm leading-6 text-muted-foreground",a),...e}));D.displayName=n.displayName;function R({children:a,className:e}){return s.jsx(p,{className:o("gap-0 overflow-hidden p-0",e),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(m,{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(f,{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};
@@ -1 +1 @@
1
- import{r as f,j as e,at as F,aw as k,ax as R,U as E,ay as I,az as B,aA as V,a0 as q}from"./vendor-LWJeAdU1.js";import{L as D}from"./router-DspBTS8b.js";import{P as K}from"./PageHeader--Lg_YQVw.js";import{P as G}from"./PageSection-DIAhP18t.js";import{P as Q,a as A}from"./PageState-DKba6Ew1.js";import{u as U}from"./useApiQuery-jSeDDFuv.js";import{c as _}from"./global-CKvMKvrn.js";import{u as H,B as c}from"./app-BG16DmZH.js";import{B as u,q as J}from"./queryKeys-DTnZc8Yy.js";import{C as N,a as y}from"./card-CwTuH2Iq.js";import{I as O}from"./input-scp9nKJc.js";import{S as W,a as X,b as Y,c as Z,d as g}from"./select-BjYpeVvo.js";import{u as P}from"./i18n-B3N4Df3E.js";import"./query-Cpxr1dul.js";import"./radix-bG5h1Ymq.js";function ee(s){const i=Date.now()-s,n=Math.abs(i),l=60*1e3,m=60*l,h=24*m;if(n<l){const o=Math.max(Math.round(n/1e3),1);return i>=0?`${o}s ago`:`in ${o}s`}if(n<m){const o=Math.round(n/l);return i>=0?`${o}m ago`:`in ${o}m`}if(n<h){const o=Math.round(n/m);return i>=0?`${o}h ago`:`in ${o}h`}const r=Math.round(n/h);return i>=0?`${r}d ago`:`in ${r}d`}function se(s){return new Date(s).toLocaleString()}const te={info:"secondary",warn:"outline",error:"destructive"};function je(){var C,S,L;const{t:s}=P(),{pushToast:a}=H(),[i,n]=f.useState(null),[l,m]=f.useState({level:"",type:""}),h=f.useMemo(()=>({limit:50,cursor:i??void 0,level:l.level||void 0,type:l.type.trim()||void 0}),[i,l.level,l.type]),r=U(J.events.list(h),{url:"/api/events",method:"GET",params:h});f.useEffect(()=>{r.isError&&r.error&&a({title:s("events.toast.loadFailure",{message:r.error.message}),variant:"error"})},[r.error,r.isError,a,s]);const o=()=>{n(null),m({level:"",type:""})},d=((C=r.data)==null?void 0:C.events)??[],b=((S=r.data)==null?void 0:S.nextCursor)??null,T=r.isLoading,v=r.isFetching&&!r.isLoading,x=f.useMemo(()=>{const t=[];return l.level&&t.push(s(`events.levels.${l.level}`)),l.type.trim()&&t.push(l.type.trim()),t},[l.level,l.type,s]),M=d.filter(t=>t.level==="info").length,$=d.filter(t=>t.level==="warn").length,z=d.filter(t=>t.level==="error").length;return e.jsxs("div",{className:"flex flex-col gap-5",children:[e.jsx(K,{icon:e.jsx(k,{className:"h-5 w-5","aria-hidden":"true"}),title:s("events.title"),description:s("events.description"),eyebrow:"Audit",breadcrumb:"Gateway / Events",helper:s("events.filters.title"),badge:d.length>0?`${d.length} events`:void 0,actions:e.jsxs("div",{className:"flex w-full flex-col gap-2 sm:w-auto sm:flex-row sm:flex-wrap sm:justify-end",children:[e.jsx("div",{className:"rounded-lg bg-secondary px-3 py-1.5 text-xs font-semibold text-muted-foreground",children:s(i?"events.actions.older":"events.actions.newest")}),e.jsxs(c,{variant:"outline",size:"sm",onClick:()=>void r.refetch(),disabled:v,className:"w-full sm:w-auto",children:[e.jsx(F,{className:_("mr-2 h-4 w-4",v&&"animate-spin"),"aria-hidden":"true"}),s(v?"common.actions.refreshing":"common.actions.refresh")]})]})}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-3",children:[e.jsx(w,{icon:e.jsx(R,{className:"h-4 w-4","aria-hidden":"true"}),title:s("events.levels.info"),value:M.toLocaleString(),tone:"emerald"}),e.jsx(w,{icon:e.jsx(E,{className:"h-4 w-4","aria-hidden":"true"}),title:s("events.levels.warn"),value:$.toLocaleString(),tone:"amber"}),e.jsx(w,{icon:e.jsx(I,{className:"h-4 w-4","aria-hidden":"true"}),title:s("events.levels.error"),value:z.toLocaleString(),tone:"rose"})]}),e.jsx(N,{"data-testid":"events-filters-card",className:"overflow-hidden rounded-[1.25rem] border border-white/70 bg-card/95 shadow-[0_20px_50px_-42px_rgba(15,23,42,0.24)]",children:e.jsx(y,{className:"space-y-3 p-4",children:e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsxs("div",{className:"flex flex-col gap-3 lg:flex-row lg:items-center lg:justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-semibold text-foreground",children:[e.jsx(B,{className:"h-4 w-4 text-primary","aria-hidden":"true"}),s("events.filters.title"),e.jsx(u,{variant:"outline",children:d.length})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("events.description")})]}),e.jsxs("div",{className:"grid gap-2 sm:flex sm:flex-wrap sm:items-center",children:[x.length>0?e.jsx(c,{variant:"ghost",size:"sm",onClick:o,className:"h-8 rounded-full px-3 text-xs sm:w-auto",children:s("common.actions.reset")}):null,e.jsxs(c,{variant:"outline",size:"sm",disabled:!i,onClick:()=>n(null),className:"h-8 rounded-full px-3 text-xs sm:w-auto",children:[e.jsx(V,{className:"mr-1 h-4 w-4","aria-hidden":"true"}),s("events.actions.newest")]}),e.jsxs(c,{variant:"outline",size:"sm",disabled:!b,onClick:()=>n(b),className:"h-8 rounded-full px-3 text-xs sm:w-auto",children:[s("events.actions.older"),e.jsx(q,{className:"ml-1 h-4 w-4","aria-hidden":"true"})]})]})]}),e.jsxs("div",{className:"flex flex-col gap-2 md:flex-row md:flex-wrap md:items-center",children:[e.jsxs(W,{value:l.level,onValueChange:t=>{n(null),m(j=>({...j,level:t==="all"?"":t}))},children:[e.jsx(X,{className:"w-full md:w-[160px]",children:e.jsx(Y,{placeholder:s("events.filters.allLevels")})}),e.jsxs(Z,{children:[e.jsx(g,{value:"all",children:s("events.filters.allLevels")}),e.jsx(g,{value:"info",children:s("events.levels.info")}),e.jsx(g,{value:"warn",children:s("events.levels.warn")}),e.jsx(g,{value:"error",children:s("events.levels.error")})]})]}),e.jsx(O,{className:"w-full md:w-[220px]",placeholder:s("events.filters.typePlaceholder"),value:l.type,onChange:t=>{n(null),m(j=>({...j,type:t.target.value}))}}),e.jsx(c,{variant:"ghost",size:"sm",onClick:o,disabled:x.length===0,className:"h-8 rounded-full px-3 text-xs md:w-auto",children:s("common.actions.reset")})]}),x.length>0?e.jsx("div",{className:"flex flex-wrap gap-2",children:x.map(t=>e.jsx(u,{variant:"secondary",children:t},t))}):null]})})}),e.jsx(G,{title:s("events.title"),description:s(i?"events.actions.older":"events.actions.newest"),children:T?e.jsx(Q,{label:s("common.loading")}):r.isError?e.jsx(A,{icon:e.jsx(E,{className:"h-5 w-5","aria-hidden":"true"}),tone:"danger",title:s("common.status.error"),description:s("events.toast.loadFailure",{message:((L=r.error)==null?void 0:L.message)??s("common.unknownError")}),action:e.jsx(c,{variant:"outline",size:"sm",onClick:()=>void r.refetch(),children:s("common.actions.refresh")})}):d.length===0?e.jsx(A,{icon:e.jsx(k,{className:"h-5 w-5","aria-hidden":"true"}),tone:"primary",title:x.length>0?s("events.empty.filteredTitle"):s("events.empty.title"),description:x.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:[x.length>0?e.jsx(c,{variant:"outline",size:"sm",onClick:o,children:s("common.actions.reset")}):null,e.jsx(c,{asChild:!0,variant:"ghost",size:"sm",children:e.jsx(D,{to:"/logs",children:s("events.empty.actions.logs")})})]})}):e.jsx("div",{className:"grid gap-3",children:d.map(t=>e.jsx(re,{event:t},t.id))})})]})}function w({icon:s,title:a,tone:i,value:n}){return e.jsx(N,{className:"rounded-[1.15rem] border border-white/70 bg-card/95 shadow-[0_18px_42px_-38px_rgba(15,23,42,0.22)]",children:e.jsxs(y,{className:"flex items-center justify-between gap-3 p-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:a}),e.jsx("p",{className:"metric-number mt-1 text-[1.85rem] font-bold tracking-tight text-foreground",children:n})]}),e.jsx("div",{className:"flex h-10 w-10 items-center justify-center rounded-xl bg-secondary text-muted-foreground",children:s})]})})}function re({event:s}){const{t:a}=P(),i=s.level==="error"?"border-l-destructive":s.level==="warn"?"border-l-amber-500":"border-l-emerald-500";return e.jsx(N,{className:_("overflow-hidden rounded-[1.05rem] border border-white/70 border-l-2 bg-card/96 shadow-[0_18px_38px_-34px_rgba(15,23,42,0.2)]",i),children:e.jsxs(y,{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(u,{variant:te[s.level]||"secondary",className:"rounded-full text-[10px]",children:a(`events.levels.${s.level}`)}),e.jsxs(u,{variant:"outline",className:"rounded-full text-[10px]",children:["#",s.id]}),s.mode?e.jsx(u,{variant:"secondary",className:"rounded-full text-[10px]",children:s.mode}):null,s.endpoint?e.jsx(u,{variant:"outline",className:"rounded-full 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||a("events.defaultTitle")}),e.jsx("p",{className:"mt-1 line-clamp-2 text-sm leading-5 text-muted-foreground",children:s.message||a("events.defaultMessage")})]})]}),e.jsxs("div",{className:"shrink-0 space-y-0.5 text-xs text-muted-foreground lg:text-right",children:[e.jsx("p",{children:se(s.createdAt)}),e.jsx("p",{children:ee(s.createdAt)})]})]}),e.jsxs("div",{className:"flex flex-wrap gap-2 text-sm",children:[e.jsx(p,{label:"Type",value:s.type}),e.jsx(p,{label:"Source",value:s.source}),e.jsx(p,{label:"IP",value:s.ipAddress}),e.jsx(p,{label:"API Key",value:s.apiKeyName}),e.jsx(p,{label:"User Agent",value:s.userAgent})]}),s.details?e.jsxs("details",{className:"rounded-[0.9rem] bg-secondary/50 px-3 py-2 text-sm",children:[e.jsx("summary",{className:"cursor-pointer text-xs font-medium text-primary",children:a("events.details")}),e.jsx("pre",{className:"mt-2.5 overflow-x-auto rounded-lg bg-secondary p-3 text-xs leading-6",children:JSON.stringify(s.details,null,2)})]}):null]})})}function p({label:s,value:a}){return a?e.jsxs("div",{className:"inline-flex max-w-full items-center gap-1.5 rounded-full 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:a,children:a})]}):null}export{je as default};
1
+ import{r as f,j as e,ax as F,aA as L,aB as R,U as k,aC as I,aD as B,aE as D,a0 as V}from"./vendor-z22RpOY0.js";import{L as q}from"./router-CL3rf_uf.js";import{P as K}from"./PageHeader-DCqHI67a.js";import{P as G}from"./PageSection-CuZMzA0E.js";import{P as Q,a as A}from"./PageState-B03H5AV0.js";import{u as U}from"./useApiQuery-tbd4JJaZ.js";import{c as _}from"./global-B-NXh5qD.js";import{u as H,B as c}from"./app-COiQeF3y.js";import{B as u,q as J}from"./queryKeys-ucXCzh0P.js";import{C as N,a as y}from"./card-ChFVaqLf.js";import{I as O}from"./input-DW7jGTgj.js";import{S as W,a as X,b as Y,c as Z,d as g}from"./select-BchX45jJ.js";import{u as P}from"./i18n-Bl2BcCDG.js";import"./query-BbGWgOFk.js";import"./radix-mHySgtou.js";function ee(s){const i=Date.now()-s,n=Math.abs(i),l=60*1e3,m=60*l,h=24*m;if(n<l){const o=Math.max(Math.round(n/1e3),1);return i>=0?`${o}s ago`:`in ${o}s`}if(n<m){const o=Math.round(n/l);return i>=0?`${o}m ago`:`in ${o}m`}if(n<h){const o=Math.round(n/m);return i>=0?`${o}h ago`:`in ${o}h`}const r=Math.round(n/h);return i>=0?`${r}d ago`:`in ${r}d`}function se(s){return new Date(s).toLocaleString()}const te={info:"secondary",warn:"outline",error:"destructive"};function je(){var C,S,E;const{t:s}=P(),{pushToast:a}=H(),[i,n]=f.useState(null),[l,m]=f.useState({level:"",type:""}),h=f.useMemo(()=>({limit:50,cursor:i??void 0,level:l.level||void 0,type:l.type.trim()||void 0}),[i,l.level,l.type]),r=U(J.events.list(h),{url:"/api/events",method:"GET",params:h});f.useEffect(()=>{r.isError&&r.error&&a({title:s("events.toast.loadFailure",{message:r.error.message}),variant:"error"})},[r.error,r.isError,a,s]);const o=()=>{n(null),m({level:"",type:""})},d=((C=r.data)==null?void 0:C.events)??[],b=((S=r.data)==null?void 0:S.nextCursor)??null,T=r.isLoading,v=r.isFetching&&!r.isLoading,x=f.useMemo(()=>{const t=[];return l.level&&t.push(s(`events.levels.${l.level}`)),l.type.trim()&&t.push(l.type.trim()),t},[l.level,l.type,s]),M=d.filter(t=>t.level==="info").length,$=d.filter(t=>t.level==="warn").length,z=d.filter(t=>t.level==="error").length;return e.jsxs("div",{className:"flex flex-col gap-5",children:[e.jsx(K,{icon:e.jsx(L,{className:"h-5 w-5","aria-hidden":"true"}),title:s("events.title"),description:s("events.description"),eyebrow:"Audit",breadcrumb:"Gateway / Events",helper:s("events.filters.title"),badge:d.length>0?`${d.length} events`:void 0,actions:e.jsxs("div",{className:"flex w-full flex-col gap-2 sm:w-auto sm:flex-row sm:flex-wrap sm:justify-end",children:[e.jsx("div",{className:"rounded-lg bg-secondary px-3 py-1.5 text-xs font-semibold text-muted-foreground",children:s(i?"events.actions.older":"events.actions.newest")}),e.jsxs(c,{variant:"outline",size:"sm",onClick:()=>void r.refetch(),disabled:v,className:"w-full sm:w-auto",children:[e.jsx(F,{className:_("mr-2 h-4 w-4",v&&"animate-spin"),"aria-hidden":"true"}),s(v?"common.actions.refreshing":"common.actions.refresh")]})]})}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-3",children:[e.jsx(w,{icon:e.jsx(R,{className:"h-4 w-4","aria-hidden":"true"}),title:s("events.levels.info"),value:M.toLocaleString(),tone:"emerald"}),e.jsx(w,{icon:e.jsx(k,{className:"h-4 w-4","aria-hidden":"true"}),title:s("events.levels.warn"),value:$.toLocaleString(),tone:"amber"}),e.jsx(w,{icon:e.jsx(I,{className:"h-4 w-4","aria-hidden":"true"}),title:s("events.levels.error"),value:z.toLocaleString(),tone:"rose"})]}),e.jsx(N,{"data-testid":"events-filters-card",className:"overflow-hidden rounded-[1.25rem] border border-white/70 bg-card/95 shadow-[0_20px_50px_-42px_rgba(15,23,42,0.24)]",children:e.jsx(y,{className:"space-y-3 p-4",children:e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsxs("div",{className:"flex flex-col gap-3 lg:flex-row lg:items-center lg:justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-semibold text-foreground",children:[e.jsx(B,{className:"h-4 w-4 text-primary","aria-hidden":"true"}),s("events.filters.title"),e.jsx(u,{variant:"outline",children:d.length})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("events.description")})]}),e.jsxs("div",{className:"grid gap-2 sm:flex sm:flex-wrap sm:items-center",children:[x.length>0?e.jsx(c,{variant:"ghost",size:"sm",onClick:o,className:"h-8 rounded-full px-3 text-xs sm:w-auto",children:s("common.actions.reset")}):null,e.jsxs(c,{variant:"outline",size:"sm",disabled:!i,onClick:()=>n(null),className:"h-8 rounded-full px-3 text-xs sm:w-auto",children:[e.jsx(D,{className:"mr-1 h-4 w-4","aria-hidden":"true"}),s("events.actions.newest")]}),e.jsxs(c,{variant:"outline",size:"sm",disabled:!b,onClick:()=>n(b),className:"h-8 rounded-full px-3 text-xs sm:w-auto",children:[s("events.actions.older"),e.jsx(V,{className:"ml-1 h-4 w-4","aria-hidden":"true"})]})]})]}),e.jsxs("div",{className:"flex flex-col gap-2 md:flex-row md:flex-wrap md:items-center",children:[e.jsxs(W,{value:l.level,onValueChange:t=>{n(null),m(j=>({...j,level:t==="all"?"":t}))},children:[e.jsx(X,{className:"w-full md:w-[160px]",children:e.jsx(Y,{placeholder:s("events.filters.allLevels")})}),e.jsxs(Z,{children:[e.jsx(g,{value:"all",children:s("events.filters.allLevels")}),e.jsx(g,{value:"info",children:s("events.levels.info")}),e.jsx(g,{value:"warn",children:s("events.levels.warn")}),e.jsx(g,{value:"error",children:s("events.levels.error")})]})]}),e.jsx(O,{className:"w-full md:w-[220px]",placeholder:s("events.filters.typePlaceholder"),value:l.type,onChange:t=>{n(null),m(j=>({...j,type:t.target.value}))}}),e.jsx(c,{variant:"ghost",size:"sm",onClick:o,disabled:x.length===0,className:"h-8 rounded-full px-3 text-xs md:w-auto",children:s("common.actions.reset")})]}),x.length>0?e.jsx("div",{className:"flex flex-wrap gap-2",children:x.map(t=>e.jsx(u,{variant:"secondary",children:t},t))}):null]})})}),e.jsx(G,{title:s("events.title"),description:s(i?"events.actions.older":"events.actions.newest"),children:T?e.jsx(Q,{label:s("common.loading")}):r.isError?e.jsx(A,{icon:e.jsx(k,{className:"h-5 w-5","aria-hidden":"true"}),tone:"danger",title:s("common.status.error"),description:s("events.toast.loadFailure",{message:((E=r.error)==null?void 0:E.message)??s("common.unknownError")}),action:e.jsx(c,{variant:"outline",size:"sm",onClick:()=>void r.refetch(),children:s("common.actions.refresh")})}):d.length===0?e.jsx(A,{icon:e.jsx(L,{className:"h-5 w-5","aria-hidden":"true"}),tone:"primary",title:x.length>0?s("events.empty.filteredTitle"):s("events.empty.title"),description:x.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:[x.length>0?e.jsx(c,{variant:"outline",size:"sm",onClick:o,children:s("common.actions.reset")}):null,e.jsx(c,{asChild:!0,variant:"ghost",size:"sm",children:e.jsx(q,{to:"/logs",children:s("events.empty.actions.logs")})})]})}):e.jsx("div",{className:"grid gap-3",children:d.map(t=>e.jsx(re,{event:t},t.id))})})]})}function w({icon:s,title:a,tone:i,value:n}){return e.jsx(N,{className:"rounded-[1.15rem] border border-white/70 bg-card/95 shadow-[0_18px_42px_-38px_rgba(15,23,42,0.22)]",children:e.jsxs(y,{className:"flex items-center justify-between gap-3 p-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:a}),e.jsx("p",{className:"metric-number mt-1 text-[1.85rem] font-bold tracking-tight text-foreground",children:n})]}),e.jsx("div",{className:"flex h-10 w-10 items-center justify-center rounded-xl bg-secondary text-muted-foreground",children:s})]})})}function re({event:s}){const{t:a}=P(),i=s.level==="error"?"border-l-destructive":s.level==="warn"?"border-l-amber-500":"border-l-emerald-500";return e.jsx(N,{className:_("overflow-hidden rounded-[1.05rem] border border-white/70 border-l-2 bg-card/96 shadow-[0_18px_38px_-34px_rgba(15,23,42,0.2)]",i),children:e.jsxs(y,{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(u,{variant:te[s.level]||"secondary",className:"rounded-full text-[10px]",children:a(`events.levels.${s.level}`)}),e.jsxs(u,{variant:"outline",className:"rounded-full text-[10px]",children:["#",s.id]}),s.mode?e.jsx(u,{variant:"secondary",className:"rounded-full text-[10px]",children:s.mode}):null,s.endpoint?e.jsx(u,{variant:"outline",className:"rounded-full 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||a("events.defaultTitle")}),e.jsx("p",{className:"mt-1 line-clamp-2 text-sm leading-5 text-muted-foreground",children:s.message||a("events.defaultMessage")})]})]}),e.jsxs("div",{className:"shrink-0 space-y-0.5 text-xs text-muted-foreground lg:text-right",children:[e.jsx("p",{children:se(s.createdAt)}),e.jsx("p",{children:ee(s.createdAt)})]})]}),e.jsxs("div",{className:"flex flex-wrap gap-2 text-sm",children:[e.jsx(p,{label:"Type",value:s.type}),e.jsx(p,{label:"Source",value:s.source}),e.jsx(p,{label:"IP",value:s.ipAddress}),e.jsx(p,{label:"API Key",value:s.apiKeyName}),e.jsx(p,{label:"User Agent",value:s.userAgent})]}),s.details?e.jsxs("details",{className:"rounded-[0.9rem] bg-secondary/50 px-3 py-2 text-sm",children:[e.jsx("summary",{className:"cursor-pointer text-xs font-medium text-primary",children:a("events.details")}),e.jsx("pre",{className:"mt-2.5 overflow-x-auto rounded-lg bg-secondary p-3 text-xs leading-6",children:JSON.stringify(s.details,null,2)})]}):null]})})}function p({label:s,value:a}){return a?e.jsxs("div",{className:"inline-flex max-w-full items-center gap-1.5 rounded-full 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:a,children:a})]}):null}export{je as default};