@chenpu17/cc-gw 0.17.0 → 0.17.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/package.json +5 -5
  2. package/src/web/dist/assets/{About-D2m94wu2.js → About-DmIV-sHO.js} +1 -1
  3. package/src/web/dist/assets/{ApiKeys-Bt-otGF_.js → ApiKeys-BNr4zbD6.js} +1 -1
  4. package/src/web/dist/assets/{ConfirmDialog-CRSbmgE7.js → ConfirmDialog-_CIYYtzo.js} +1 -1
  5. package/src/web/dist/assets/{Dashboard-81qp43jm.js → Dashboard-Hg4OZNAc.js} +1 -1
  6. package/src/web/dist/assets/{DialogShell-DxWKa5oR.js → DialogShell-D1T4HXtd.js} +1 -1
  7. package/src/web/dist/assets/Events-CO2wWiEK.js +1 -0
  8. package/src/web/dist/assets/{Help-XaAZ__Kz.js → Help-CafNfXfx.js} +1 -1
  9. package/src/web/dist/assets/{Login-atwWPGzz.js → Login-C04-poiG.js} +1 -1
  10. package/src/web/dist/assets/Logs-CqaIXvR0.js +1 -0
  11. package/src/web/dist/assets/{PageSection-CC5EhfMe.js → PageSection-Dd2-9G6C.js} +1 -1
  12. package/src/web/dist/assets/{PageState-XybOeENt.js → PageState-Bbhr4fy6.js} +1 -1
  13. package/src/web/dist/assets/{PageToolbar-CnLp4aWt.js → PageToolbar-GyUQBhmq.js} +1 -1
  14. package/src/web/dist/assets/{ProvidersPage-CFCY2xSG.js → ProvidersPage-CHvyCANH.js} +1 -1
  15. package/src/web/dist/assets/{RoutingPage-35o5ZSMg.js → RoutingPage-fVr25VKF.js} +1 -1
  16. package/src/web/dist/assets/{Settings-DC1TPeS9.js → Settings-DfaIYHsa.js} +1 -1
  17. package/src/web/dist/assets/{Setup-CnQPVK9X.js → Setup-DUEpie5k.js} +1 -1
  18. package/src/web/dist/assets/{TargetCombobox-DkVdA04_.js → TargetCombobox-CSnHZqDY.js} +1 -1
  19. package/src/web/dist/assets/{apiKeys-CMk2nxB_.js → apiKeys-B5Os17Qm.js} +1 -1
  20. package/src/web/dist/assets/app-DZpd2fu9.js +61 -0
  21. package/src/web/dist/assets/{badge-eRkhnmCs.js → badge-CWbm9P64.js} +1 -1
  22. package/src/web/dist/assets/{chartTheme-Cx-0Jiew.js → chartTheme-ChTod603.js} +1 -1
  23. package/src/web/dist/assets/{charts-core-BOHudNiN.js → charts-core-BuoE1ECx.js} +1 -1
  24. package/src/web/dist/assets/{charts-engine-BhFpDbO0.js → charts-engine-DHIzBJl6.js} +1 -1
  25. package/src/web/dist/assets/{charts-react-CPWg-GRD.js → charts-react-BLOapElb.js} +1 -1
  26. package/src/web/dist/assets/{currency-Bx141-XL.js → currency-DffG4uWM.js} +2 -2
  27. package/src/web/dist/assets/{disclosure-CU-KJc8C.js → disclosure-W_XtxMJz.js} +1 -1
  28. package/src/web/dist/assets/{gateway-DyhqzHSh.js → gateway-DxaHzVOF.js} +1 -1
  29. package/src/web/dist/assets/{global-BLUcvOa8.js → global-BCYo_xAt.js} +1 -1
  30. package/src/web/dist/assets/global-CP6wBbWu.css +1 -0
  31. package/src/web/dist/assets/{i18n-v60Yn7Ls.js → i18n-ClvfZhYc.js} +1 -1
  32. package/src/web/dist/assets/{label-CdbE1ezd.js → label-09axTkPo.js} +1 -1
  33. package/src/web/dist/assets/{landing-BQdbaG8s.js → landing-BsX2AKvc.js} +3 -3
  34. package/src/web/dist/assets/{modelManagement-DwdbGu0o.js → modelManagement-Dc7L1tJw.js} +1 -1
  35. package/src/web/dist/assets/package-DgoCoO-z.js +1 -0
  36. package/src/web/dist/assets/{popover-CuM9b3U7.js → popover-CX5HRHKk.js} +1 -1
  37. package/src/web/dist/assets/{query-CvboQrUT.js → query-1Ng1fzmE.js} +1 -1
  38. package/src/web/dist/assets/{radix-d0BukFWM.js → radix-DONH6gHT.js} +1 -1
  39. package/src/web/dist/assets/{router-CqUBCAsx.js → router-Bkbjq53m.js} +1 -1
  40. package/src/web/dist/assets/{segmented-control-5mZhY1KZ.js → segmented-control-Cxe6ZLHe.js} +1 -1
  41. package/src/web/dist/assets/{shared-zfHsnBTk.js → shared-DG0AgdnU.js} +1 -1
  42. package/src/web/dist/assets/{switch-CZn1nypU.js → switch-C58zWdHT.js} +1 -1
  43. package/src/web/dist/assets/{tabs-CrNMQMmG.js → tabs-BIz291zK.js} +1 -1
  44. package/src/web/dist/assets/{useAppMutation-B29oVzxS.js → useAppMutation-CsoNTPQ7.js} +1 -1
  45. package/src/web/dist/assets/{useEventStream-DN2DYBVS.js → useEventStream-CvopQT4p.js} +1 -1
  46. package/src/web/dist/assets/{useProviderForm-DIuM3Z2u.js → useProviderForm-B_wmywxX.js} +1 -1
  47. package/src/web/dist/assets/{vendor-JUtelXU0.js → vendor-C-lQMZp3.js} +94 -84
  48. package/src/web/dist/index.html +14 -11
  49. package/src/web/dist/landing.html +5 -5
  50. package/src/web/dist/assets/Events-BQ4Dkqon.js +0 -1
  51. package/src/web/dist/assets/Logs-BYFIK_hM.js +0 -1
  52. package/src/web/dist/assets/app-CRxPj2SJ.js +0 -61
  53. package/src/web/dist/assets/global-BQq8O0Tv.css +0 -1
  54. package/src/web/dist/assets/package-Dmrvm3RO.js +0 -1
@@ -1,5 +1,5 @@
1
1
  <!doctype html>
2
- <html lang="zh-CN" data-theme="light">
2
+ <html lang="zh-CN" data-theme="light" data-skin="minimal">
3
3
  <head>
4
4
  <meta charset="UTF-8" />
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no" />
@@ -19,7 +19,10 @@
19
19
  root.dataset.theme = dark ? 'dark' : 'light'
20
20
  root.classList.toggle('dark', dark)
21
21
  var skin = localStorage.getItem('cc-gw-skin')
22
- if (skin) root.dataset.skin = skin
22
+ // Always materialize the axis: unknown/stale values simply match no
23
+ // family block and fall back to :root (minimal) until ThemeProvider
24
+ // sanitizes the stored value after boot.
25
+ root.dataset.skin = skin || 'minimal'
23
26
  } catch (e) { /* storage 不可用:保持 HTML 上的默认属性 */ }
24
27
  })()
25
28
  </script>
@@ -29,18 +32,18 @@
29
32
  <link rel="preconnect" href="https://fonts.googleapis.com" />
30
33
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
31
34
  <link
32
- href="https://fonts.googleapis.com/css2?family=Archivo:wght@400;600;800&family=Inter:wght@400;500;600;700&family=Noto+Sans+SC:wght@400;500;700;900&family=Source+Serif+4:wght@600;700&display=swap"
35
+ href="https://fonts.googleapis.com/css2?family=Archivo:wght@400;600;800&family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;700&family=Noto+Sans+SC:wght@400;500;700;900&family=Noto+Serif+SC:wght@600&family=Source+Serif+4:wght@600;700&family=Space+Grotesk:wght@500;600;700&display=swap"
33
36
  rel="stylesheet"
34
37
  />
35
38
  <title>cc-gw 控制台</title>
36
- <script type="module" crossorigin src="/assets/app-CRxPj2SJ.js"></script>
37
- <link rel="modulepreload" crossorigin href="/assets/vendor-JUtelXU0.js">
38
- <link rel="modulepreload" crossorigin href="/assets/global-BLUcvOa8.js">
39
- <link rel="modulepreload" crossorigin href="/assets/query-CvboQrUT.js">
40
- <link rel="modulepreload" crossorigin href="/assets/i18n-v60Yn7Ls.js">
41
- <link rel="modulepreload" crossorigin href="/assets/router-CqUBCAsx.js">
42
- <link rel="modulepreload" crossorigin href="/assets/radix-d0BukFWM.js">
43
- <link rel="stylesheet" crossorigin href="/assets/global-BQq8O0Tv.css">
39
+ <script type="module" crossorigin src="/assets/app-DZpd2fu9.js"></script>
40
+ <link rel="modulepreload" crossorigin href="/assets/vendor-C-lQMZp3.js">
41
+ <link rel="modulepreload" crossorigin href="/assets/global-BCYo_xAt.js">
42
+ <link rel="modulepreload" crossorigin href="/assets/query-1Ng1fzmE.js">
43
+ <link rel="modulepreload" crossorigin href="/assets/i18n-ClvfZhYc.js">
44
+ <link rel="modulepreload" crossorigin href="/assets/router-Bkbjq53m.js">
45
+ <link rel="modulepreload" crossorigin href="/assets/radix-DONH6gHT.js">
46
+ <link rel="stylesheet" crossorigin href="/assets/global-CP6wBbWu.css">
44
47
  </head>
45
48
  <body class="bg-background text-foreground">
46
49
  <div id="root"></div>
@@ -42,12 +42,12 @@
42
42
  }
43
43
  </script>
44
44
  <title>cc-gw | 你的 API Key 不该躺在 30 个 .env 里 · local-first AI gateway</title>
45
- <script type="module" crossorigin src="/assets/landing-BQdbaG8s.js"></script>
46
- <link rel="modulepreload" crossorigin href="/assets/vendor-JUtelXU0.js">
47
- <link rel="modulepreload" crossorigin href="/assets/global-BLUcvOa8.js">
45
+ <script type="module" crossorigin src="/assets/landing-BsX2AKvc.js"></script>
46
+ <link rel="modulepreload" crossorigin href="/assets/vendor-C-lQMZp3.js">
47
+ <link rel="modulepreload" crossorigin href="/assets/global-BCYo_xAt.js">
48
48
  <link rel="modulepreload" crossorigin href="/assets/clipboard-DqvcglYs.js">
49
- <link rel="modulepreload" crossorigin href="/assets/package-Dmrvm3RO.js">
50
- <link rel="stylesheet" crossorigin href="/assets/global-BQq8O0Tv.css">
49
+ <link rel="modulepreload" crossorigin href="/assets/package-DgoCoO-z.js">
50
+ <link rel="stylesheet" crossorigin href="/assets/global-CP6wBbWu.css">
51
51
  </head>
52
52
  <body class="bg-slate-50 text-slate-900">
53
53
  <div id="landing-root"></div>
@@ -1 +0,0 @@
1
- import{r as c,j as e,aG as H,a3 as J,Y as U,aH as Y,ay as _,az as W}from"./vendor-JUtelXU0.js";import{L as X}from"./router-CqUBCAsx.js";import{P as Z}from"./PageToolbar-CnLp4aWt.js";import{P as ee,a as z}from"./PageState-XybOeENt.js";import{u as se,b as F,B as x,q as D,C as te,c as ae}from"./app-CRxPj2SJ.js";import{u as re}from"./useEventStream-DN2DYBVS.js";import{c as E}from"./global-BLUcvOa8.js";import{i as ne,u as V}from"./i18n-v60Yn7Ls.js";import{B as y}from"./badge-eRkhnmCs.js";import{S as le,a as oe,b as ie,c as ce,d as B,D as de}from"./disclosure-CU-KJc8C.js";import{S as ue}from"./segmented-control-5mZhY1KZ.js";import"./query-CvboQrUT.js";import"./radix-d0BukFWM.js";function me(s){const r=Date.now()-s,l=Math.abs(r),o=60*1e3,f=60*o,d=24*f,m=new Intl.RelativeTimeFormat(ne.language||"en",{numeric:"auto"});if(l<o){const a=Math.max(Math.round(l/1e3),1);return m.format(r>=0?-a:a,"second")}if(l<f){const a=Math.round(l/o);return m.format(r>=0?-a:a,"minute")}if(l<d){const a=Math.round(l/f);return m.format(r>=0?-a:a,"hour")}const h=Math.round(l/d);return m.format(r>=0?-h:h,"day")}function xe(s){return new Date(s).toLocaleString()}const fe={info:"secondary",warn:"outline",error:"destructive"};function Ae(){var L,A,M,k,I,P,R;const{t:s}=V(),{pushToast:n}=se(),[r,l]=c.useState(null),[o,f]=c.useState(""),[d,m]=c.useState(""),h=c.useMemo(()=>({limit:50,cursor:r??void 0,level:o||void 0,type:d||void 0}),[r,o,d]),a=F(D.events.list(h),{url:"/api/events",method:"GET",params:h}),u=F(D.events.stats(),{url:"/api/events/stats",method:"GET"},{refetchInterval:15e3}),q=((L=u.data)==null?void 0:L.error)??0,G=((A=u.data)==null?void 0:A.warn)??0,K=((M=u.data)==null?void 0:M.info)??0,O=((k=u.data)==null?void 0:k.total)??0,i=re({level:o||void 0,type:d||void 0,maxEvents:50,enabled:r===null}),N=c.useRef(!1);c.useEffect(()=>{const t=a.isError;t&&a.error&&!N.current&&(N.current=!0,n({title:s("events.toast.loadFailure",{message:a.error.message}),variant:"error"})),t||(N.current=!1)},[a.error,a.isError,n,s]);const C=c.useRef(!1);c.useEffect(()=>{const t=u.isError;t&&u.error&&!C.current&&(C.current=!0,n({title:s("events.toast.statsLoadFailure",{message:u.error.message}),variant:"error"})),t||(C.current=!1)},[u.error,u.isError,n,s]);const S=()=>{l(null),f(""),m("")},v=((I=a.data)==null?void 0:I.events)??[],T=((P=a.data)==null?void 0:P.nextCursor)??null,Q=a.isLoading,b=c.useMemo(()=>{if(r!==null)return v;const t=new Set;return[...i.events,...v].filter(p=>t.has(p.id)?!1:(t.add(p.id),!0)).slice(0,50)},[r,i.events,v]),$=c.useMemo(()=>{const t=new Set;return v.forEach(p=>t.add(p.type)),i.events.forEach(p=>t.add(p.type)),Array.from(t).sort()},[v,i.events]),g=c.useMemo(()=>{const t=[];return o&&t.push(s(`events.levels.${o}`)),d&&t.push(d),t},[o,d,s]);return e.jsxs("div",{className:"flex flex-col gap-5",children:[e.jsx(Z,{status:r===null?e.jsxs("span",{className:E("inline-flex items-center gap-1.5 text-xs font-medium",i.connected?"text-success":i.failed?"text-destructive":"text-warning"),children:[e.jsx("span",{"aria-hidden":"true",className:E("h-1.5 w-1.5 rounded-full",i.connected?"bg-success animate-live-pulse":i.failed?"bg-destructive":"bg-warning")}),i.connected?s("events.live"):i.failed?s("events.failed"):s("events.reconnecting")]}):e.jsx("span",{className:"text-xs text-muted-foreground",children:s("events.actions.older")}),actions:e.jsxs("div",{className:"flex items-center gap-2",children:[!i.connected&&r===null?e.jsx(x,{variant:"outline",size:"sm",onClick:()=>void a.refetch(),children:s("common.actions.refresh")}):null,e.jsxs("div",{className:"flex items-center gap-2 border border-border bg-secondary px-2 py-1.5",children:[e.jsxs(x,{variant:"outline",size:"sm",disabled:!r,onClick:()=>l(null),children:[e.jsx(H,{className:"mr-1 h-4 w-4","aria-hidden":"true"}),s("events.actions.newest")]}),b.length>0?e.jsx("span",{className:"metric-number px-1 text-sm text-muted-foreground",children:s("events.pageCount",{count:b.length})}):null,e.jsxs(x,{variant:"outline",size:"sm",disabled:!T,onClick:()=>l(T),children:[s("events.actions.older"),e.jsx(J,{className:"ml-1 h-4 w-4","aria-hidden":"true"})]})]})]})}),e.jsxs("div",{className:"flex flex-col gap-3 md:flex-row md:flex-wrap md:items-center","data-testid":"events-filters-card",children:[e.jsx(ue,{value:o,onChange:t=>{l(null),f(t)},className:"min-w-max overflow-x-auto",options:[{value:"",label:e.jsx(w,{label:s("events.filters.allLevels"),count:O,testId:"events-stat-total"})},{value:"info",label:e.jsx(w,{label:s("events.levels.info"),count:K,testId:"events-stat-info"})},{value:"warn",label:e.jsx(w,{label:s("events.levels.warn"),count:G,testId:"events-stat-warn"})},{value:"error",label:e.jsx(w,{label:s("events.levels.error"),count:q,testId:"events-stat-error"})}],"aria-label":s("events.filters.title")}),e.jsxs(le,{value:d||"all",onValueChange:t=>{l(null),m(t==="all"?"":t)},children:[e.jsx(oe,{className:"h-8 w-full md:w-[200px]",children:e.jsx(ie,{})}),e.jsxs(ce,{children:[e.jsx(B,{value:"all",children:s("events.filters.allTypes")}),$.map(t=>e.jsx(B,{value:t,children:t},t))]})]}),g.length>0?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex flex-wrap gap-2",children:g.map(t=>e.jsx(y,{variant:"secondary",children:t},t))}),e.jsx(x,{variant:"ghost",size:"sm",onClick:S,className:"h-8 px-3 text-xs",children:s("common.actions.reset")})]}):null]}),Q?e.jsx(ee,{label:s("common.loading")}):a.isError?e.jsx(z,{icon:e.jsx(U,{className:"h-5 w-5","aria-hidden":"true"}),tone:"danger",title:s("common.status.error"),description:s("events.toast.loadFailure",{message:((R=a.error)==null?void 0:R.message)??s("common.unknownError")}),action:e.jsx(x,{variant:"outline",size:"sm",onClick:()=>void a.refetch(),children:s("common.actions.refresh")})}):b.length===0?e.jsx(z,{icon:e.jsx(Y,{className:"h-5 w-5","aria-hidden":"true"}),tone:"primary",title:g.length>0?s("events.empty.filteredTitle"):s("events.empty.title"),description:g.length>0?s("events.empty.filteredSubtitle"):s("events.empty.subtitle"),action:e.jsxs("div",{className:"flex flex-wrap items-center justify-center gap-2",children:[g.length>0?e.jsx(x,{variant:"outline",size:"sm",onClick:S,children:s("common.actions.reset")}):null,e.jsx(x,{asChild:!0,variant:"ghost",size:"sm",children:e.jsx(X,{to:"/logs",children:s("events.empty.actions.logs")})})]})}):e.jsx("div",{className:"grid gap-3",children:e.jsx(_,{initial:!1,children:b.map(t=>e.jsx(W.div,{layout:!0,initial:{opacity:0,y:-12},animate:{opacity:1,y:0},exit:{opacity:0},transition:{duration:.18},children:e.jsx(pe,{event:t})},t.id))})})]})}function w({label:s,count:n,testId:r}){return e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[s,e.jsx("span",{className:"tabular-nums opacity-60","data-testid":r,children:n.toLocaleString()})]})}function pe({event:s}){const{t:n}=V(),r=s.level==="error"?"border-l-error":s.level==="warn"?"border-l-warning":"border-l-success";return e.jsx(te,{className:E("overflow-hidden border-l-2 hover:bg-muted/30",r),children:e.jsxs(ae,{className:"space-y-3 p-4",children:[e.jsxs("div",{className:"flex flex-col gap-2 lg:flex-row lg:items-start lg:justify-between",children:[e.jsxs("div",{className:"min-w-0 space-y-1.5",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(y,{variant:fe[s.level]||"secondary",className:"text-[10px]",children:n(`events.levels.${s.level}`)}),e.jsxs(y,{variant:"outline",className:"text-[10px]",children:["#",s.id]}),s.mode?e.jsx(y,{variant:"secondary",className:"text-[10px]",children:s.mode}):null,s.endpoint?e.jsx(y,{variant:"outline",className:"text-[10px]",children:s.endpoint}):null]}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h3",{className:"truncate text-[15px] font-semibold tracking-[-0.01em]",children:s.title||n("events.defaultTitle")}),e.jsx("p",{className:"mt-1 line-clamp-2 break-words text-sm leading-5 text-muted-foreground [overflow-wrap:anywhere]",children:s.message||n("events.defaultMessage")})]})]}),e.jsxs("div",{className:"shrink-0 space-y-0.5 text-xs text-muted-foreground lg:text-right",children:[e.jsx("p",{"data-visual-volatile":"true",children:xe(s.createdAt)}),e.jsx("p",{"data-visual-volatile":"true",children:me(s.createdAt)})]})]}),e.jsxs("div",{className:"flex flex-wrap gap-2 text-sm",children:[e.jsx(j,{label:"Type",value:s.type}),e.jsx(j,{label:"Source",value:s.source}),e.jsx(j,{label:"IP",value:s.ipAddress}),e.jsx(j,{label:"API Key",value:s.apiKeyName}),e.jsx(j,{label:"User Agent",value:s.userAgent})]}),s.details?e.jsx(de,{summary:n("events.details"),className:"rounded-lg bg-secondary px-3 py-2 text-sm",summaryClassName:"px-0 py-0 text-xs font-medium text-foreground underline decoration-muted-foreground/40 underline-offset-2 hover:decoration-foreground",contentClassName:"mt-2.5",children:e.jsx("pre",{className:"overflow-x-auto rounded-lg bg-secondary p-3 text-xs leading-6",children:JSON.stringify(s.details,null,2)})}):null]})})}function j({label:s,value:n}){return n?e.jsxs("div",{className:"inline-flex max-w-full items-center gap-1.5 border border-border/60 bg-secondary/55 px-2.5 py-1 text-[11px] text-muted-foreground",children:[e.jsxs("span",{className:"font-medium",children:[s,":"]}),e.jsx("span",{className:"truncate text-foreground",title:n,children:n})]}):null}export{Ae as default};
@@ -1 +0,0 @@
1
- import{r as p,j as e,t as Is,aC as $s,au as Vs,aD as Us,av as Ye,aE as Xe,aB as Qs,aF as Hs,a3 as Ze,Y as Bs,V as Ws,aG as Gs}from"./vendor-JUtelXU0.js";import{P as Js}from"./PageToolbar-CnLp4aWt.js";import{s as K,C as es,c as ss,B as D,d as Ys,u as _e,b as re,q as se,t as Xs,a as I}from"./app-CRxPj2SJ.js";import{B as le}from"./badge-eRkhnmCs.js";import{L as X,I as ye}from"./label-CdbE1ezd.js";import{S as ts}from"./segmented-control-5mZhY1KZ.js";import{S as pe,a as xe,b as ge,c as he,d as U,D as Zs}from"./disclosure-CU-KJc8C.js";import{c as v}from"./global-BLUcvOa8.js";import{u as Q}from"./i18n-v60Yn7Ls.js";import{D as et,A as st,a as tt,b as lt,c as at,d as rt}from"./DialogShell-DxWKa5oR.js";import{P as ot,a as ne}from"./PageState-XybOeENt.js";import{T as ls,a as as,b as rs,c as os}from"./tabs-CrNMQMmG.js";import{c as nt}from"./clipboard-DqvcglYs.js";import{a as it,g as Le,b as ns,c as Z,d as Ee,e as W,f as ee,h as Ce,p as is,i as ds,j as cs,k as dt,T as ct}from"./currency-Bx141-XL.js";import{P as ut,a as mt,b as pt}from"./popover-CuM9b3U7.js";import{S as xt}from"./switch-CZn1nypU.js";import{L as us,u as gt}from"./router-CqUBCAsx.js";import{a as ht}from"./query-CvboQrUT.js";import{g as We}from"./gateway-DyhqzHSh.js";import"./radix-d0BukFWM.js";function ft({apiKeys:s,selected:l,onChange:i,disabled:a,className:o}){const{t}=Q(),d=p.useId(),[c,g]=p.useState(!1),[h,f]=p.useState(null),C=p.useRef(null),N=p.useRef(null),m=p.useRef(null),_=()=>{const y=N.current;if(!y)return;const x=y.getBoundingClientRect(),L=Math.max(x.width,256),u=window.innerWidth-12;f({left:Math.min(x.left,u-L),top:x.bottom+8,width:L})};p.useEffect(()=>{if(!c)return;const y=L=>{var F,R;const u=L.target;!((F=C.current)!=null&&F.contains(u))&&!((R=m.current)!=null&&R.contains(u))&&g(!1)},x=L=>{var u;L.key==="Escape"&&(g(!1),(u=N.current)==null||u.focus())};return window.addEventListener("mousedown",y),window.addEventListener("keydown",x),()=>{window.removeEventListener("mousedown",y),window.removeEventListener("keydown",x)}},[c]),p.useEffect(()=>{if(c)return _(),window.addEventListener("resize",_),window.addEventListener("scroll",_,!0),()=>{window.removeEventListener("resize",_),window.removeEventListener("scroll",_,!0)}},[c]);const r=p.useMemo(()=>{if(l.length===0)return[];const y=new Map;for(const x of s)y.set(x.id,x);return l.map(x=>{const L=y.get(x);return L?L.isWildcard?t("apiKeys.wildcard"):L.name:null}).filter(x=>!!x)},[s,l,t]),w=l.length===0?t("logs.filters.apiKeyAll"):t("logs.filters.apiKeySelected",{count:l.length}),b=y=>{l.includes(y)?i(l.filter(x=>x!==y)):i([...l,y])};return e.jsxs("div",{className:v("relative space-y-2",o),ref:C,children:[e.jsx(X,{htmlFor:d,children:t("logs.filters.apiKey")}),e.jsxs("button",{ref:N,id:d,type:"button",onClick:()=>{_(),g(y=>!y)},disabled:a||s.length===0,title:t("logs.filters.apiKeyHint"),className:v("flex h-10 w-full items-center justify-between rounded-lg border border-input bg-background px-3 text-sm ring-offset-background transition-all focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",l.length>0&&"border-foreground",c&&"ring-2 ring-ring ring-offset-2"),children:[e.jsxs("span",{className:"truncate",children:[w,r.length>0&&e.jsx("span",{className:"ml-1 text-xs text-muted-foreground",children:r.join(", ")})]}),e.jsx("svg",{className:v("h-4 w-4 opacity-50 transition-transform",c&&"rotate-180"),viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M5.23 7.21a.75.75 0 011.06.02L10 10.94l3.71-3.71a.75.75 0 111.06 1.06l-4.24 4.25a.75.75 0 01-1.06 0L5.21 8.29a.75.75 0 01.02-1.08z",clipRule:"evenodd"})})]}),c&&h&&Is.createPortal(e.jsxs("div",{ref:m,className:"fixed z-50 rounded-lg border bg-popover p-2 shadow-[var(--surface-shadow-lg)]",style:h,children:[e.jsxs("div",{className:"flex items-center justify-between rounded-lg bg-secondary px-3 py-2 text-xs",children:[e.jsx("span",{children:w}),e.jsx("button",{type:"button",onClick:()=>i([]),disabled:l.length===0,className:"text-foreground underline decoration-muted-foreground/40 underline-offset-2 hover:decoration-foreground disabled:opacity-40",children:t("common.actions.reset")})]}),e.jsxs("div",{className:"max-h-56 overflow-y-auto py-2",children:[s.map(y=>{const x=y.isWildcard?t("apiKeys.wildcard"):y.name,L=l.includes(y.id);return e.jsxs("label",{className:v("flex cursor-pointer items-center gap-3 rounded-xl px-3 py-2 text-sm transition hover:bg-accent",L&&"bg-secondary text-foreground"),children:[e.jsx("input",{type:"checkbox",className:"h-4 w-4 rounded border-border",checked:L,onChange:()=>b(y.id)}),e.jsx("span",{className:"truncate",children:x})]},y.id)}),s.length===0&&e.jsx("p",{className:"px-2 py-2 text-xs text-muted-foreground",children:t("logs.filters.apiKeyAll")})]})]}),document.body)]})}const oe=[20,50,100],yt=["all","errors","today","anthropic","openai"],bt=["claude-code","codex","opencode","gemini-cli","cline","roo-code","cursor","crush","aider","kilo-code","droid","copilot","anthropic-compatible","openai-compatible"],B=["endpoint","provider","client","requestedModel","routedModel","apiKey","tokens","cost","duration","status","error"],te=["endpoint","provider","client","requestedModel","routedModel","apiKey","tokens","cost","duration","status","error"];function jt(){return typeof window>"u"?"comfortable":window.localStorage.getItem(K.logs.density)==="compact"?"compact":"comfortable"}function vt(){if(typeof window>"u")return oe[0];const s=window.localStorage.getItem(K.logs.pageSize),l=Number(s);return oe.includes(l)?l:oe[0]}function Ge(s,l=!1){if(!s)return;const i=l?`${s}T23:59:59.999`:`${s}T00:00:00.000`,a=Date.parse(i);return Number.isFinite(a)?a:void 0}function Nt(s,l,i){return s===i&&l===i}function wt(s){const{t:l}=Q(),{activeFilters:i,filtersExpanded:a,setFiltersExpanded:o,handleResetFilters:t,activeQuickView:d,applyQuickView:c,providerFilter:g,setProviderFilter:h,endpointFilter:f,setEndpointFilter:C,selectedApiKeys:N,setSelectedApiKeys:m,modelFilter:_,setModelFilter:r,clientKindFilter:w,setClientKindFilter:b,sessionFilter:y,setSessionFilter:x,statusFilter:L,setStatusFilter:u,fromDate:F,setFromDate:R,toDate:$,setToDate:S,providerOptions:M,apiKeys:E,apiKeysLoading:A,customEndpoints:G}=s;return e.jsx(es,{"data-testid":"logs-filters-card",className:"overflow-hidden",children:e.jsxs(ss,{className:"space-y-3 p-4",children:[e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("p",{className:"text-sm font-semibold text-foreground",children:l("logs.filtersTitle")}),i.length>0&&e.jsx(le,{variant:"outline",className:"border-transparent bg-secondary px-2.5 py-0.5 text-[11px] font-semibold text-foreground",children:l("common.filters.activeCount",{count:i.length})})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:l("logs.filtersDescription")})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[i.length>0&&e.jsx(D,{variant:"ghost",size:"sm",onClick:t,className:"h-8 px-3 text-xs",children:l("common.actions.reset")}),e.jsx(D,{variant:"ghost",size:"sm",onClick:()=>o(j=>!j),className:"h-8 px-3 text-xs",children:a?e.jsxs(e.Fragment,{children:[l("common.filters.collapse"),e.jsx($s,{className:"ml-1 h-4 w-4"})]}):e.jsxs(e.Fragment,{children:[l("common.filters.expand"),e.jsx(Vs,{className:"ml-1 h-4 w-4"})]})})]})]}),i.length>0?e.jsx("div",{className:"flex min-h-10 flex-wrap items-center gap-2 rounded-lg bg-secondary px-3 py-2",children:i.map(j=>e.jsxs(le,{variant:"outline",role:"button",tabIndex:0,className:"flex cursor-pointer items-center gap-1 border border-border bg-card px-2.5 py-1 text-[11px] font-semibold text-foreground/90 transition hover:bg-secondary",onClick:j.onRemove,onKeyDown:ie=>{(ie.key==="Enter"||ie.key===" ")&&(ie.preventDefault(),j.onRemove())},children:[j.label,e.jsx(Us,{className:"h-3 w-3","aria-hidden":"true"})]},j.key))}):null,e.jsx(ts,{value:d,onChange:c,className:"flex-wrap","aria-label":l("logs.filtersTitle"),options:yt.map(j=>({value:j,label:l(`logs.quickViews.${j}`)}))})]}),a&&e.jsxs("div",{className:"mt-3 grid gap-3 rounded-xl bg-secondary p-3 md:grid-cols-2 xl:grid-cols-4 animate-in fade-in slide-in-from-top-2 duration-200",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(X,{children:l("logs.filters.provider")}),e.jsxs(pe,{value:g,onValueChange:h,children:[e.jsx(xe,{children:e.jsx(ge,{})}),e.jsxs(he,{children:[e.jsx(U,{value:"all",children:l("logs.filters.providerAll")}),M.map(j=>e.jsx(U,{value:j.id,children:j.label??j.id},j.id))]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(X,{children:l("logs.filters.endpoint")}),e.jsxs(pe,{value:f,onValueChange:C,children:[e.jsx(xe,{children:e.jsx(ge,{})}),e.jsxs(he,{children:[e.jsx(U,{value:"all",children:l("logs.filters.endpointAll")}),e.jsx(U,{value:"anthropic",children:l("logs.filters.endpointAnthropic")}),e.jsx(U,{value:"openai",children:l("logs.filters.endpointOpenAI")}),G==null?void 0:G.map(j=>e.jsx(U,{value:j.id,children:j.label||j.id},j.id))]})]})]}),e.jsx(ft,{className:"md:col-span-2",apiKeys:E,selected:N,disabled:A,onChange:m}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(X,{children:l("logs.filters.modelId")}),e.jsx(ye,{value:_,onChange:j=>r(j.target.value),placeholder:l("logs.filters.modelPlaceholder")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(X,{children:l("logs.filters.clientKind")}),e.jsxs(pe,{value:w,onValueChange:b,children:[e.jsx(xe,{children:e.jsx(ge,{})}),e.jsxs(he,{children:[e.jsx(U,{value:"all",children:l("logs.filters.clientKindAll")}),bt.map(j=>e.jsx(U,{value:j,children:l(`dashboard.usage.clientKinds.${j}`,{defaultValue:j})},j))]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(X,{children:l("logs.filters.status")}),e.jsxs(pe,{value:L,onValueChange:j=>u(j),children:[e.jsx(xe,{children:e.jsx(ge,{})}),e.jsxs(he,{children:[e.jsx(U,{value:"all",children:l("logs.filters.statusAll")}),e.jsx(U,{value:"success",children:l("logs.filters.statusSuccess")}),e.jsx(U,{value:"error",children:l("logs.filters.statusError")})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(X,{children:l("logs.filters.startDate")}),e.jsx(ye,{type:"date",value:F,onChange:j=>R(j.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(X,{children:l("logs.filters.endDate")}),e.jsx(ye,{type:"date",value:$,onChange:j=>S(j.target.value)})]}),e.jsxs("div",{className:"space-y-2 md:col-span-2",children:[e.jsx(X,{htmlFor:"logs-session-filter",children:l("logs.filters.session")}),e.jsx(ye,{id:"logs-session-filter",value:y,onChange:j=>x(j.target.value),placeholder:l("logs.filters.sessionPlaceholder"),className:"font-mono"})]})]})]})})}const Re={listRequest(s){return{url:"/api/logs",method:"GET",params:s}},detailRequest(s){return{url:s===null?"":`/api/logs/${s}`,method:"GET"}},async exportArchive(s,l){const i=await Ys.post("/api/logs/export",s,{responseType:"blob",timeout:l});return new Blob([i.data],{type:"application/zip"})}};function ms({apiKeyMap:s,logId:l,open:i,providerLabelMap:a}){var _;const{t:o}=Q(),{pushToast:t}=_e(),d=re(se.logs.detail(l),Re.detailRequest(l),{enabled:i&&l!==null,staleTime:3e4,gcTime:15e3,placeholderData:void 0});p.useEffect(()=>{!d.isError||!d.error||t({title:o("logs.detail.loadError"),description:d.error.message,variant:"error"})},[d.error,d.isError,t,o]);const c=p.useCallback(async(r,w,b)=>{if(!w){t({title:o("logs.detail.copy.empty",{label:r}),variant:"info"});return}try{await nt(w),t({title:o(b),variant:"success"})}catch(y){t({title:o("logs.detail.copy.failure"),description:y instanceof Error?y.message:o("logs.detail.copy.failureFallback"),variant:"error"})}},[t,o]),g=p.useCallback((r,w)=>{if(!w){t({title:o("logs.detail.copy.empty",{label:r}),variant:"info"});return}const b=new Blob([w],{type:"application/json;charset=utf-8"}),y=URL.createObjectURL(b),x=document.createElement("a"),L=new Date().toISOString().replace(/[:.]/g,"-"),u=r.trim().toLowerCase().replace(/[^a-z0-9\u4e00-\u9fa5]+/gi,"-").replace(/^-+|-+$/g,"")||"payload";x.href=y,x.download=`cc-gw-log-${l??"payload"}-${u}-${L}.json`,document.body.appendChild(x),x.click(),document.body.removeChild(x),URL.revokeObjectURL(y)},[l,t,o]),h=d.data,f=h?a.get(h.provider)??h.provider:"",C=h&&h.api_key_id!=null?s.get(h.api_key_id):void 0,N=h?it(h,o):null,m=h?Le(h,o):null;return{apiKeyMeta:C,errorSourceMeta:N,errorMessage:d.isError?((_=d.error)==null?void 0:_.message)??null:null,handleCopy:c,handleDownloadPayload:g,isError:d.isError,isPending:d.isPending,providerLabel:f,refetch:d.refetch,record:h,statusMeta:m}}function ps({detail:s,compact:l=!1}){var d;const{t:i}=Q(),a=c=>i(`logs.detail.errorDetail.stages.${c}`,{defaultValue:c}),o=e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.stage?e.jsx("span",{className:"border border-border bg-secondary px-1.5 py-0.5 text-[11px] font-medium text-foreground",children:a(s.stage)}):null,s.upstreamStatus!=null?e.jsxs("span",{className:"border border-destructive/40 bg-destructive/10 px-1.5 py-0.5 text-[11px] font-semibold tabular-nums text-destructive",children:["HTTP ",s.upstreamStatus]}):null,(d=s.failoverAttempts)!=null&&d.length?e.jsx("span",{className:"text-[11px] text-muted-foreground",children:i("logs.detail.errorDetail.attemptsCount",{count:s.failoverAttempts.length})}):null]}),t=s.failoverAttempts??[];return e.jsx(Zs,{defaultOpen:!0,summaryClassName:"px-1 py-1",contentClassName:v("mt-1 space-y-2",l&&"text-[11px]"),summary:e.jsx("span",{className:v("text-xs font-medium text-foreground",l&&"text-[11px]"),children:i("logs.detail.errorDetail.title")}),children:e.jsxs("div",{className:"space-y-2","data-testid":"log-error-detail",children:[o,s.message?e.jsx("p",{className:v("whitespace-pre-wrap break-all border-l-2 border-destructive/50 bg-destructive/5 px-2.5 py-1.5 font-mono",l?"text-[10.5px] leading-[1.55]":"text-[11px] leading-[1.6]"),children:s.message}):null,t.length>0?e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-[11px]",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-border text-left text-muted-foreground",children:[e.jsx("th",{className:"py-1 pr-3 font-medium",children:i("logs.detail.errorDetail.attemptBackend")}),e.jsx("th",{className:"py-1 pr-3 font-medium",children:i("logs.detail.errorDetail.attemptOutcome")}),e.jsx("th",{className:"py-1 pr-3 text-right font-medium",children:i("logs.detail.errorDetail.attemptStatus")}),e.jsx("th",{className:"py-1 text-right font-medium",children:i("logs.detail.errorDetail.attemptLatency")})]})}),e.jsx("tbody",{className:"tabular-nums",children:t.map((c,g)=>e.jsxs("tr",{className:"border-b border-border/50 last:border-b-0",children:[e.jsxs("td",{className:"py-1 pr-3",children:[e.jsx("span",{className:"font-medium",children:c.provider??"—"}),e.jsxs("span",{className:"text-muted-foreground",children:[" / ",c.model??"—"]})]}),e.jsx("td",{className:"py-1 pr-3 text-muted-foreground",children:c.outcome??"—"}),e.jsx("td",{className:"py-1 pr-3 text-right",children:c.status!=null?e.jsx("span",{className:c.status>=400?"text-destructive":"text-foreground",children:c.status}):"—"}),e.jsx("td",{className:"py-1 text-right text-muted-foreground",children:c.latencyMs!=null?`${c.latencyMs} ms`:"—"})]},g))})]})}):null,s.upstreamBody?e.jsxs("div",{className:"space-y-0.5",children:[e.jsx("p",{className:v("text-muted-foreground",l?"text-[10.5px]":"text-[11px]"),children:i("logs.detail.errorDetail.upstreamBody")}),e.jsx("pre",{className:v("m-0 max-h-[180px] overflow-auto whitespace-pre-wrap border border-border bg-secondary/50 p-2 font-mono text-muted-foreground",l?"text-[10.5px] leading-[1.55]":"text-[11px] leading-[1.6]"),children:s.upstreamBody})]}):null]})})}function kt({open:s,logId:l,onClose:i,providerLabelMap:a,apiKeyMap:o}){var y,x,L,u,F,R,$;const{t}=Q(),{apiKeyMeta:d,errorSourceMeta:c,errorMessage:g,handleCopy:h,handleDownloadPayload:f,isError:C,isPending:N,providerLabel:m,refetch:_,record:r,statusMeta:w}=ms({apiKeyMap:o,logId:l,open:s,providerLabelMap:a}),b=p.useMemo(()=>{var M,E,A,G;return r?[{key:"client-request",title:t("logs.detail.payload.clientRequest"),value:((M=r.payload)==null?void 0:M.client_request)??null,emptyLabel:t("logs.detail.payload.emptyRequest"),copyToast:"logs.detail.copy.requestSuccess"},...(E=r.payload)!=null&&E.upstream_request?[{key:"upstream-request",title:t("logs.detail.payload.upstreamRequest"),value:r.payload.upstream_request,emptyLabel:t("logs.detail.payload.emptyRequest"),copyToast:"logs.detail.copy.requestSuccess"}]:[],...(A=r.payload)!=null&&A.upstream_response?[{key:"upstream-response",title:t("logs.detail.payload.upstreamResponse"),value:r.payload.upstream_response,emptyLabel:t("logs.detail.payload.emptyResponse"),copyToast:"logs.detail.copy.responseSuccess"}]:[],{key:"client-response",title:t("logs.detail.payload.clientResponse"),value:((G=r.payload)==null?void 0:G.client_response)??null,emptyLabel:t("logs.detail.payload.emptyResponse"),copyToast:"logs.detail.copy.responseSuccess"}].map(j=>({...j,display:ns(j.value,j.emptyLabel)})):[]},[r,t]);return e.jsx(et,{open:s,onOpenChange:S=>{S||i()},children:e.jsxs(st,{className:"w-[min(96vw,1200px)] max-w-[1200px]",children:[e.jsxs(tt,{className:"pr-14",children:[e.jsx(lt,{children:t("logs.detail.title")}),e.jsx(at,{children:r?t("logs.detail.id",{id:r.id}):t("logs.detail.loadError")})]}),e.jsx(rt,{className:"max-h-[78vh]",children:N?e.jsx(ot,{compact:!0,className:"min-h-[240px]",label:t("common.loading")}):C?e.jsx(ne,{compact:!0,className:"min-h-[240px]",tone:"danger",title:t("logs.detail.loadError"),description:g??t("common.unknownError"),action:e.jsx(D,{variant:"outline",onClick:()=>void _(),children:t("common.actions.refresh")})}):r?e.jsxs("div",{className:"space-y-6 text-sm",children:[e.jsxs("section",{className:"space-y-4 rounded-lg border bg-card p-4",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:t("logs.detail.infoSection")}),e.jsx("div",{className:"flex flex-wrap items-center gap-2 rounded-lg border bg-secondary p-3 text-xs",children:e.jsx("span",{className:"font-medium",children:t("logs.detail.summary.route",{from:r.client_model??t("logs.detail.info.noRequestedModel"),to:r.model})})})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(le,{variant:w==null?void 0:w.variant,children:(w==null?void 0:w.label)??"—"}),e.jsx(le,{variant:"outline",children:r.stream?t("logs.stream.streaming"):t("logs.stream.single")})]})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2 xl:grid-cols-4",children:[e.jsx(q,{label:t("logs.detail.info.latency"),value:Z(r.latency_ms,t("common.units.ms"))}),e.jsx(q,{label:t("logs.detail.info.ttft"),value:Z(r.ttft_ms,t("common.units.ms"))}),e.jsx(q,{label:t("logs.detail.info.tpot"),value:Z(r.tpot_ms,t("common.units.msPerToken"))}),e.jsx(q,{label:t("logs.detail.info.errorSource"),value:(c==null?void 0:c.label)??"—"})]}),e.jsxs("dl",{className:"grid gap-x-4 gap-y-3 md:grid-cols-2 xl:grid-cols-4",children:[e.jsx(V,{label:t("logs.detail.info.time"),value:Ee(r.timestamp)}),e.jsx(V,{label:t("logs.detail.info.sessionId"),value:r.session_id??"—"}),e.jsx(V,{label:t("logs.detail.info.endpoint"),value:r.endpoint||"—"}),e.jsx(V,{label:t("logs.detail.info.provider"),value:m}),e.jsx(V,{label:t("logs.detail.info.client"),value:r.client_kind??"—"}),e.jsx(V,{label:t("logs.detail.info.userAgent"),value:r.user_agent??"—"}),e.jsx(V,{label:t("logs.detail.info.requestedModel"),value:r.client_model??t("logs.detail.info.noRequestedModel")}),e.jsx(V,{label:t("logs.detail.info.model"),value:r.model})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2 xl:grid-cols-4",children:[e.jsx(q,{label:t("logs.detail.info.inputTokens"),value:W(r.input_tokens)}),e.jsx(q,{label:t("logs.detail.info.cacheReadTokens"),value:W(r.cache_read_tokens)}),e.jsx(q,{label:t("logs.detail.info.cacheCreationTokens"),value:W(r.cache_creation_tokens)}),e.jsx(q,{label:t("logs.detail.info.outputTokens"),value:W(r.output_tokens)})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2 xl:grid-cols-5","data-testid":"log-cost-breakdown",children:[e.jsx(q,{label:t("logs.detail.cost.title"),value:ee(r.cost,r.cost_currency)}),r.cost!=null?e.jsxs(e.Fragment,{children:[e.jsx(q,{label:t("logs.detail.cost.input"),value:ee(((y=r.cost_breakdown)==null?void 0:y.input)??null,r.cost_currency)}),e.jsx(q,{label:t("logs.detail.cost.output"),value:ee(((x=r.cost_breakdown)==null?void 0:x.output)??null,r.cost_currency)}),e.jsx(q,{label:t("logs.detail.cost.cacheRead"),value:ee(((L=r.cost_breakdown)==null?void 0:L.cacheRead)??null,r.cost_currency)}),e.jsx(q,{label:t("logs.detail.cost.cacheCreation"),value:ee(((u=r.cost_breakdown)==null?void 0:u.cacheCreation)??null,r.cost_currency)})]}):null]}),r.cost==null&&!Ce(r)?e.jsx("p",{className:"text-xs text-muted-foreground/70",children:t("logs.detail.cost.unpricedHint")}):null,Ce(r)?e.jsx("p",{className:"text-xs text-muted-foreground/70",children:t("logs.detail.tokensNoUsageHint")}):null,r.error?e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:t("logs.detail.info.error")}),e.jsx("p",{className:"rounded-xl border border-destructive/50 bg-destructive/10 p-3 text-xs text-destructive",children:r.error})]}):null,(()=>{const S=is(r);return S?"raw"in S?e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:t("logs.detail.errorDetail.title")}),e.jsx("pre",{className:"m-0 max-h-[180px] overflow-auto whitespace-pre-wrap rounded-xl border border-border bg-secondary/50 p-3 font-mono text-[11px] leading-[1.6] text-muted-foreground",children:S.raw})]}):e.jsx(ps,{detail:S}):null})()]}),e.jsxs("div",{className:"grid gap-6 xl:grid-cols-[minmax(0,0.9fr)_minmax(0,1.1fr)]",children:[e.jsxs("section",{className:"space-y-3 rounded-lg border bg-card p-4",children:[e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:t("logs.detail.apiKey.title")}),e.jsxs("dl",{className:"grid gap-x-4 gap-y-3 sm:grid-cols-2",children:[e.jsx(V,{label:t("logs.detail.apiKey.name"),value:r.api_key_id==null&&!r.api_key_name?t("logs.detail.apiKey.missing"):d!=null&&d.isWildcard?t("apiKeys.wildcard"):(d==null?void 0:d.name)??r.api_key_name??t("logs.detail.apiKey.missing")}),e.jsx(V,{label:t("logs.detail.apiKey.identifier"),value:r.api_key_id??t("common.noData")}),e.jsx(V,{label:t("logs.detail.apiKey.masked"),value:d!=null&&d.isWildcard?t("apiKeys.wildcard"):(d==null?void 0:d.maskedKey)??r.api_key_name??t("logs.detail.apiKey.maskedUnavailable")}),e.jsx(V,{label:t("logs.detail.apiKey.lastUsed"),value:d!=null&&d.lastUsedAt?new Date(d.lastUsedAt).toLocaleString():t("common.noData")})]}),e.jsxs("div",{className:"rounded-lg border bg-secondary p-3 text-xs",children:[e.jsx("p",{className:"font-medium",children:t("logs.detail.apiKey.rawMasked")}),e.jsx("p",{className:"mt-1 break-all font-mono",children:r.api_key_value_available?r.api_key_value_masked??t("logs.detail.apiKey.rawUnavailable"):t("logs.detail.apiKey.rawUnavailable")}),e.jsx("p",{className:"mt-2 text-[11px] text-muted-foreground",children:t("logs.detail.apiKey.rawMaskedHint")})]})]}),e.jsxs("section",{className:"space-y-4 rounded-lg border bg-card p-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:t("logs.detail.payload.title")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:(F=r.payload)!=null&&F.upstream_request||(R=r.payload)!=null&&R.upstream_response?t("logs.detail.payload.helperWithUpstream"):t("logs.detail.payload.helperClientOnly")})]}),e.jsxs(ls,{defaultValue:($=b[0])==null?void 0:$.key,children:[e.jsx(as,{className:"w-full justify-start overflow-x-auto",children:b.map(S=>e.jsx(rs,{value:S.key,children:S.title},S.key))}),b.map(S=>e.jsx(os,{value:S.key,children:e.jsx(St,{title:S.title,display:S.display,onCopy:()=>h(S.title,S.value,S.copyToast),onDownload:()=>f(S.title,S.value),panelKey:S.key,t})},S.key))]})]})]})]}):e.jsx(ne,{compact:!0,className:"min-h-[240px]",title:t("logs.detail.loadError"),description:t("common.noData")})})]})})}function q({label:s,value:l}){return e.jsxs("div",{className:"min-w-0 rounded-lg border bg-secondary px-3 py-3",children:[e.jsx("p",{className:"text-[11px] font-medium uppercase tracking-wider text-muted-foreground",children:s}),e.jsx("p",{className:"mt-2 break-all text-sm font-semibold leading-6",children:l})]})}function V({label:s,value:l}){return e.jsxs("div",{className:"min-w-0 space-y-1",children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:s}),e.jsx("dd",{className:"min-w-0 break-all whitespace-pre-wrap text-sm font-medium leading-6 text-foreground",children:l??"—"})]})}function St({display:s,onCopy:l,onDownload:i,panelKey:a,title:o,t}){return e.jsxs("div",{className:"space-y-3 rounded-lg border bg-secondary/40 p-4","data-testid":`log-payload-${a}`,children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsx("h4",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:o}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(D,{variant:"outline",size:"sm",onClick:l,children:[e.jsx(Ye,{className:"mr-2 h-3.5 w-3.5"}),t("common.actions.copy")]}),e.jsxs(D,{variant:"outline",size:"sm",onClick:i,children:[e.jsx(Xe,{className:"mr-2 h-3.5 w-3.5"}),t("common.actions.download")]})]})]}),s.isTruncated?e.jsx("p",{className:"rounded-lg border border-warning/30 bg-warning-bg px-3 py-2 text-xs text-warning",children:t("logs.detail.payload.truncated",{shown:s.displayedLength.toLocaleString(),total:s.originalLength.toLocaleString()})}):null,e.jsx("pre",{className:"max-h-72 overflow-auto whitespace-pre rounded-lg border bg-secondary p-3 text-xs",children:s.text})]})}function Ct({autoRefresh:s,columnOptions:l,exporting:i,onExport:a,onRefresh:o,onResetColumns:t,onSetDensity:d,onToggleAutoRefresh:c,onToggleColumn:g,refreshing:h,rowDensity:f,visibleColumns:C,visibleColumnSet:N}){const{t:m}=Q(),_=JSON.stringify(C)===JSON.stringify(B);return e.jsxs("div",{className:"flex w-full flex-col gap-3 xl:w-auto xl:flex-row xl:items-center",children:[e.jsxs("div",{className:"grid w-full grid-cols-2 gap-2 sm:flex sm:flex-row sm:flex-wrap sm:items-center xl:w-auto xl:flex-nowrap",children:[e.jsx(ts,{block:!0,className:"col-span-2 w-full overflow-x-auto sm:w-auto",value:f,onChange:d,options:[{value:"comfortable",label:m("logs.table.density.comfortable")},{value:"compact",label:m("logs.table.density.compact")}]}),e.jsxs(ut,{children:[e.jsx(mt,{asChild:!0,children:e.jsx(D,{variant:"outline",size:"sm",className:"w-full sm:w-auto",children:m("logs.actions.columns")})}),e.jsxs(pt,{align:"end",className:"w-64 p-3",children:[e.jsxs("div",{className:"mb-3 flex items-center justify-between",children:[e.jsx("p",{className:"text-sm font-semibold",children:m("logs.actions.columns")}),e.jsx(D,{variant:"ghost",size:"sm",onClick:t,disabled:_,children:m("common.actions.reset")})]}),e.jsx("div",{className:"grid gap-1.5",children:l.map(r=>{const w=N.has(r.id);return e.jsxs("label",{className:v("flex cursor-pointer items-center gap-3 rounded-xl px-3 py-2 text-sm transition hover:bg-accent",w&&"bg-secondary text-foreground"),children:[e.jsx("input",{type:"checkbox",checked:w,onChange:()=>g(r.id),className:"h-4 w-4 rounded border-border"}),e.jsx("span",{children:r.label})]},r.id)})})]})]}),e.jsxs(D,{variant:"outline",onClick:a,disabled:i,className:"w-full sm:w-auto",children:[e.jsx(Xe,{className:"mr-2 h-4 w-4"}),m(i?"logs.actions.exporting":"logs.actions.export")]})]}),e.jsxs("div",{className:"flex w-full items-center gap-3 xl:w-auto",children:[e.jsxs("label",{className:"flex shrink-0 cursor-pointer items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(xt,{checked:s,onCheckedChange:c,"aria-label":m("logs.actions.autoRefresh")}),m("logs.actions.autoRefresh")]}),e.jsxs(D,{variant:"outline",size:"sm",onClick:o,disabled:h,className:"shrink-0",children:[e.jsx(Qs,{className:v("mr-2 h-4 w-4",h&&"animate-spin")}),m(h?"common.actions.refreshing":"logs.actions.manualRefresh")]})]})]})}function _t({record:s,providerLabelMap:l,onSelect:i,costCurrency:a}){const{t:o}=Q(),t=Le(s,o),d=l.get(s.provider)??s.provider,c=ds(s.session_id),g=c==null?void 0:c.accentStyle;return e.jsxs("button",{type:"button","data-session-id":c==null?void 0:c.sessionId,"data-session-color":c==null?void 0:c.colorKey,style:g,onClick:()=>i(s.id),className:"w-full space-y-2 border-b border-border/50 px-4 py-3 text-left transition-colors hover:bg-muted/50",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:Ee(s.timestamp)}),e.jsx(le,{variant:t.variant,className:"text-xs",children:t.label})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3 text-xs",children:[e.jsx("span",{className:"min-w-0 truncate font-medium",title:d,children:d}),e.jsx("span",{className:"min-w-0 truncate text-muted-foreground",title:s.model,children:s.model})]}),s.client_kind?e.jsx("div",{className:"text-[11px] text-muted-foreground/80",title:s.user_agent??void 0,children:s.client_kind}):null,e.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1 text-xs tabular-nums text-muted-foreground",children:[e.jsx("span",{children:Z(s.latency_ms,o("common.units.ms"))}),s.ttft_ms!=null?e.jsxs("span",{children:[o("logs.table.columns.latencyTtft")," ",W(s.ttft_ms)]}):null,s.cost!=null?e.jsx("span",{children:ee(s.cost,a)}):null]})]})}const Je={accent:"bg-foreground",ok:"bg-success",warn:"bg-warning",error:"bg-destructive"};function Lt({logId:s,providerLabelMap:l,apiKeyMap:i}){const{t:a}=Q(),{record:o,isPending:t,isError:d,errorMessage:c,statusMeta:g,providerLabel:h,handleCopy:f,refetch:C}=ms({apiKeyMap:i,logId:s,open:!0,providerLabelMap:l}),N=p.useMemo(()=>{var F,R,$,S;if(!o)return[];const u=[{key:"client-request",title:a("logs.detail.payload.clientRequest"),value:((F=o.payload)==null?void 0:F.client_request)??null,emptyLabel:a("logs.detail.payload.emptyRequest"),copyToast:"logs.detail.copy.requestSuccess"}];return(R=o.payload)!=null&&R.upstream_request&&u.push({key:"upstream-request",title:a("logs.detail.payload.upstreamRequest"),value:o.payload.upstream_request,emptyLabel:a("logs.detail.payload.emptyRequest"),copyToast:"logs.detail.copy.requestSuccess"}),($=o.payload)!=null&&$.upstream_response&&u.push({key:"upstream-response",title:a("logs.detail.payload.upstreamResponse"),value:o.payload.upstream_response,emptyLabel:a("logs.detail.payload.emptyResponse"),copyToast:"logs.detail.copy.responseSuccess"}),u.push({key:"client-response",title:a("logs.detail.payload.clientResponse"),value:((S=o.payload)==null?void 0:S.client_response)??null,emptyLabel:a("logs.detail.payload.emptyResponse"),copyToast:"logs.detail.copy.responseSuccess"}),u.map(M=>({...M,display:ns(M.value,M.emptyLabel)}))},[o,a]),[m,_]=p.useState("client-request"),r=N.find(u=>u.key===m)??N[0];if(t)return e.jsx("div",{className:"py-3",children:e.jsx(cs,{className:"h-28 w-full"})});if(d)return e.jsx(ne,{compact:!0,tone:"danger",title:a("logs.detail.loadError"),description:c??a("common.unknownError"),action:e.jsx(D,{variant:"outline",size:"sm",onClick:()=>void C(),children:a("common.actions.refresh")})});if(!o)return e.jsx(ne,{compact:!0,title:a("logs.detail.loadError"),description:a("common.noData")});const w=dt(o,h,a),b=a("common.units.ms"),y=[{label:a("logs.detail.info.status"),value:(g==null?void 0:g.label)??"—"},{label:a("logs.detail.info.latency"),value:Z(o.latency_ms,b)},{label:a("logs.detail.info.ttft"),value:Z(o.ttft_ms,b)},{label:a("logs.detail.info.inputTokens"),value:W(o.input_tokens)},{label:a("logs.detail.info.outputTokens"),value:W(o.output_tokens)},{label:a("logs.detail.info.cacheReadTokens"),value:W(o.cache_read_tokens)},{label:a("logs.detail.info.cost"),value:ee(o.cost,o.cost_currency)}],x=o.ttft_ms!=null,L=o.session_id;return e.jsxs("div",{"data-testid":"log-row-expanded",className:"grid gap-5 py-1 xl:grid-cols-[minmax(0,1.15fr)_minmax(0,1fr)]",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"mb-3 text-[10.5px] font-semibold uppercase tracking-[0.06em] text-muted-foreground",children:a("logs.detail.trace.title")}),e.jsx("ol",{"data-testid":"log-trace-timeline",className:"flex flex-col",children:w.map((u,F)=>e.jsxs("li",{className:"grid grid-cols-[14px_1fr] gap-3",children:[e.jsxs("div",{className:"flex flex-col items-center","aria-hidden":"true",children:[e.jsx("span",{className:v("mt-1 h-[9px] w-[9px] rounded-full",Je[u.tone])}),F<w.length-1?e.jsx("span",{className:"mt-[3px] w-px flex-1 bg-border"}):null]}),e.jsxs("div",{className:"pb-3.5",children:[e.jsxs("div",{className:"flex items-baseline gap-2.5",children:[e.jsx("span",{className:"text-xs font-semibold",children:u.title}),u.atLabel?e.jsx("span",{className:"text-[10.5px] tabular-nums text-muted-foreground",children:u.atLabel}):null,u.durLabel?e.jsx("span",{className:"ml-auto text-[10.5px] tabular-nums text-muted-foreground",children:u.durLabel}):null]}),u.detail?e.jsx("div",{className:"mt-1 text-[11px] leading-[1.55] text-muted-foreground",children:u.detail}):null,e.jsx("div",{className:"mt-1.5 h-1 w-full max-w-[220px] bg-secondary",children:e.jsx("div",{className:v("h-full",Je[u.tone]),style:{width:`${u.barPct}%`}})})]})]},u.id))}),x?null:e.jsx("p",{className:"mt-1 text-[10.5px] text-muted-foreground/70",children:a("logs.detail.trace.degraded")}),(()=>{const u=is(o);return!u||"raw"in u?null:e.jsx("div",{className:"mt-2 border-t border-border pt-2",children:e.jsx(ps,{detail:u,compact:!0})})})()]}),e.jsxs("div",{className:"flex min-w-0 flex-col gap-3",children:[e.jsx("div",{className:"grid grid-cols-3 gap-2",children:y.map(u=>e.jsxs("div",{className:"border border-border bg-card px-2.5 py-2",children:[e.jsx("div",{className:"text-[10.5px] text-muted-foreground",children:u.label}),e.jsx("div",{className:"mt-0.5 text-[13px] font-semibold tabular-nums",children:u.value})]},u.label))}),Ce(o)?e.jsx("p",{className:"text-[11px] text-muted-foreground/70",children:a("logs.detail.tokensNoUsageHint")}):null,e.jsx("div",{className:"border border-border bg-card",children:e.jsxs(ls,{value:r==null?void 0:r.key,onValueChange:_,children:[e.jsx(as,{className:"w-full justify-start overflow-x-auto",children:N.map(u=>e.jsx(rs,{value:u.key,className:"px-2.5 text-[10.5px]",children:u.title},u.key))}),N.map(u=>e.jsx(os,{value:u.key,className:"mt-0",children:e.jsx("pre",{"data-testid":`log-payload-${u.key}`,className:"m-0 max-h-[172px] overflow-auto whitespace-pre-wrap p-3 font-mono text-[10.5px] leading-[1.65] text-muted-foreground",children:u.display.text||a("logs.detail.payload.emptyRequest")})},u.key))]})}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs(D,{variant:"outline",size:"sm",className:"h-[30px] flex-1",onClick:()=>{r&&f(r.title,r.value,r.copyToast)},children:[e.jsx(Ye,{className:"mr-1.5 h-3.5 w-3.5","aria-hidden":"true"}),a("logs.detail.inline.copyRequest")]}),L?e.jsx(D,{variant:"outline",size:"sm",className:"h-[30px] flex-1",onClick:()=>f(a("logs.detail.inline.copySession"),L,"logs.detail.inline.sessionCopied"),children:a("logs.detail.inline.copySession")}):null,e.jsx(D,{asChild:!0,variant:"outline",size:"sm",className:"h-[30px] flex-1",children:e.jsxs(us,{to:"/providers?tab=routing",children:[a("logs.detail.inline.viewRule"),e.jsx(Hs,{className:"ml-1.5 h-3.5 w-3.5","aria-hidden":"true"})]})})]})]})]})}function Et({record:s,providerLabelMap:l,apiKeyMap:i,onSelect:a,isExpanded:o,onToggleExpand:t,isEven:d,density:c,visibleColumnSet:g,costCurrency:h}){const{t:f}=Q(),C=l.get(s.provider)??s.provider,N=s.endpoint||"—",m=Le(s,f),_=s.client_model??f("logs.table.requestedModelFallback"),r=s.api_key_id!=null?i.get(s.api_key_id):void 0,w=s.api_key_id==null?f("logs.table.apiKeyUnknown"):r!=null&&r.isWildcard?f("apiKeys.wildcard"):r!=null&&r.name?r.name:s.api_key_name?s.api_key_name:f("logs.table.apiKeyUnknown"),b=c==="compact"?"px-3 py-1.5":"px-3 py-2",y=d?"bg-muted/30":"bg-background",x=ds(s.session_id),L=x==null?void 0:x.accentStyle,u=g.size+2,F=f(o?"logs.detail.inline.collapse":"logs.detail.inline.expand");return e.jsxs(e.Fragment,{children:[e.jsxs("tr",{"data-log-id":s.id,"data-session-id":x==null?void 0:x.sessionId,"data-session-color":x==null?void 0:x.colorKey,className:v("transition-colors duration-160 ease-surface",d?"bg-muted/30":"",o?"bg-muted/50":"hover:bg-muted/50"),children:[e.jsx("td",{className:v("sticky left-0 z-10 text-xs",b,y),style:L,children:e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("button",{type:"button","aria-expanded":o,"aria-label":F,onClick:()=>t(s.id),className:"-ml-0.5 inline-flex h-5 w-5 shrink-0 items-center justify-center rounded-sm text-muted-foreground transition-colors hover:bg-secondary hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",children:e.jsx(Ze,{className:v("h-3.5 w-3.5 transition-transform duration-160 ease-surface",o&&"rotate-90"),"aria-hidden":"true"})}),e.jsx("span",{"data-visual-volatile":"true",className:"metric-number whitespace-nowrap",children:Ee(s.timestamp)})]})}),g.has("endpoint")&&e.jsx("td",{className:v(b,"text-xs"),children:N}),g.has("provider")&&e.jsx("td",{className:v(b,"text-xs"),children:e.jsx("div",{className:"max-w-[100px] truncate",title:C,children:C})}),g.has("client")&&e.jsx("td",{className:v(b,"text-xs text-muted-foreground"),children:e.jsx("div",{className:"max-w-[110px] truncate",title:s.user_agent??s.client_kind??"",children:s.client_kind??"—"})}),g.has("requestedModel")&&e.jsx("td",{className:v(b,"text-xs text-muted-foreground"),children:e.jsx("div",{className:"max-w-[120px] truncate",title:_,children:_})}),g.has("routedModel")&&e.jsx("td",{className:v(b,"text-xs"),children:e.jsx("div",{className:"max-w-[120px] truncate",title:s.model,children:s.model})}),g.has("apiKey")&&e.jsx("td",{className:v(b,"text-xs text-muted-foreground"),children:e.jsx("div",{className:"max-w-[90px] truncate",title:w,children:w})}),g.has("tokens")&&e.jsx("td",{className:v(b,"text-right text-xs tabular-nums"),children:s.input_tokens==null&&s.output_tokens==null?e.jsx("span",{className:"whitespace-nowrap text-muted-foreground/70",children:f("logs.table.tokensNoUsage")}):e.jsxs("span",{className:"whitespace-nowrap",children:[f("logs.table.columns.tokenIn")," ",W(s.input_tokens),e.jsx("span",{className:"mx-1 text-muted-foreground/50",children:"·"}),f("logs.table.columns.tokenOut")," ",W(s.output_tokens)]})}),g.has("cost")&&e.jsx("td",{className:v(b,"text-right text-xs tabular-nums align-top"),children:e.jsx("span",{className:"whitespace-nowrap",title:s.cost==null?f("logs.table.costUnpricedHint"):void 0,"data-testid":`log-cost-${s.id}`,children:ee(s.cost,h)})}),g.has("duration")&&e.jsx("td",{className:v(b,"text-right text-xs tabular-nums"),title:s.ttft_ms!=null||s.tpot_ms!=null?`${f("logs.table.columns.latencyTtft")} ${Z(s.ttft_ms,"ms")} · ${f("logs.table.columns.latencyTpot")} ${Z(s.tpot_ms,"ms/tk")}`:void 0,children:e.jsx("span",{"data-visual-volatile":"true",className:"whitespace-nowrap",children:Z(s.latency_ms,"ms")})}),g.has("status")&&e.jsx("td",{className:v(b,"text-center"),children:e.jsx(le,{variant:m.variant,className:"text-xs",children:m.label})}),g.has("error")&&e.jsx("td",{className:v(b,"text-xs text-muted-foreground"),children:e.jsx("div",{className:"max-w-[100px] truncate",title:s.error??"",children:s.error?s.error:"—"})}),e.jsx("td",{className:v("sticky right-0 z-10 text-center",b,y),children:e.jsx(D,{variant:"outline",size:"sm",onClick:()=>a(s.id),children:f("logs.actions.detail")})})]}),o?e.jsx("tr",{"data-testid":`log-row-expanded-wrapper-${s.id}`,children:e.jsx("td",{colSpan:u,className:"border-t border-border bg-secondary/30 p-0",children:e.jsx("div",{className:"px-5 pb-5 pt-3",children:e.jsx(Lt,{logId:s.id,providerLabelMap:l,apiKeyMap:i})})})}):null]})}const z="whitespace-nowrap px-3 py-2.5 text-xs font-semibold text-muted-foreground";function Rt(s){const{t:l}=Q(),{tableScrollRef:i,visibleColumnSet:a,visibleColumnCount:o,logsError:t,logsPending:d,items:c,costCurrency:g,activeFiltersCount:h,total:f,handleResetFilters:C,handleRetry:N,providerLabelMap:m,apiKeyMap:_,handleOpenDetail:r,expandedLogId:w,onToggleExpand:b,rowDensity:y,showScrollHint:x,pageSize:L,setPageSize:u,page:F,totalPages:R,setPage:$}=s,S=e.jsx(ne,{compact:!0,tone:"danger",icon:e.jsx(Bs,{className:"h-5 w-5","aria-hidden":"true"}),title:l("logs.toast.listError.title"),description:t,action:e.jsxs("div",{className:"flex flex-wrap items-center justify-center gap-2",children:[e.jsx(D,{variant:"outline",size:"sm",onClick:N,children:l("common.actions.refresh")}),h>0?e.jsx(D,{variant:"ghost",size:"sm",onClick:C,children:l("common.actions.reset")}):null]})}),M=e.jsx(ne,{compact:!0,tone:"primary",icon:e.jsx(Ws,{className:"h-5 w-5","aria-hidden":"true"}),title:h>0?l("logs.empty.filteredTitle"):l("logs.empty.title"),description:h>0?l("logs.empty.filteredSubtitle"):l("logs.empty.subtitle"),action:e.jsxs("div",{className:"flex flex-wrap items-center justify-center gap-2",children:[h>0?e.jsx(D,{variant:"outline",size:"sm",onClick:C,children:l("logs.empty.actions.reset")}):null,e.jsx(D,{asChild:!0,variant:"ghost",size:"sm",children:e.jsx(us,{to:"/api-keys",children:l("logs.empty.actions.apiKeys")})})]})});return e.jsx(es,{variant:"solid",className:"overflow-hidden bg-card shadow-[var(--surface-shadow)]",children:e.jsxs(ss,{className:"p-0",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 bg-secondary/50 px-4 py-3 border-b border-border",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-sm font-semibold",children:l("logs.title")}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[e.jsx("span",{className:"metric-number",children:l("logs.summary.total",{value:f.toLocaleString()})}),e.jsx("span",{className:"mx-1.5 text-muted-foreground/50",children:"·"}),l("logs.table.visibleColumns",{count:o})]})]}),x?e.jsx("div",{className:"hidden md:flex",children:e.jsx(le,{variant:"outline",className:"bg-background text-muted-foreground",children:l(y==="compact"?"logs.table.density.compact":"logs.table.density.comfortable")})}):null]}),e.jsxs("div",{className:"relative hidden md:block",children:[e.jsx("div",{ref:i,className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full min-w-[1180px] text-sm",children:[e.jsx("thead",{className:"border-b border-border/50 bg-secondary/50",children:e.jsxs("tr",{children:[e.jsx("th",{className:v(z,"sticky left-0 z-20 bg-secondary text-left"),children:l("logs.table.columns.time")}),a.has("endpoint")&&e.jsx("th",{className:v(z,"text-left"),children:l("logs.table.columns.endpoint")}),a.has("provider")&&e.jsx("th",{className:v(z,"text-left"),children:l("logs.table.columns.provider")}),a.has("client")&&e.jsx("th",{className:v(z,"text-left"),children:l("logs.table.columns.client")}),a.has("requestedModel")&&e.jsx("th",{className:v(z,"text-left"),children:l("logs.table.columns.requestedModel")}),a.has("routedModel")&&e.jsx("th",{className:v(z,"text-left"),children:l("logs.table.columns.routedModel")}),a.has("apiKey")&&e.jsx("th",{className:v(z,"text-left"),children:l("logs.table.columns.apiKey")}),a.has("tokens")&&e.jsx("th",{className:v(z,"text-right"),children:l("logs.table.columns.tokens")}),a.has("cost")&&e.jsx("th",{className:v(z,"text-right"),children:l("logs.table.columns.cost")}),a.has("duration")&&e.jsx("th",{className:v(z,"text-right"),children:l("logs.table.columns.duration")}),a.has("status")&&e.jsx("th",{className:v(z,"text-center"),children:l("logs.table.columns.status")}),a.has("error")&&e.jsx("th",{className:v(z,"text-left"),children:l("logs.table.columns.error")}),e.jsx("th",{className:v(z,"sticky right-0 z-20 bg-secondary text-center"),children:l("logs.table.columns.actions")})]})}),e.jsx("tbody",{className:"divide-y divide-border/50",children:d?Array.from({length:8}).map((E,A)=>e.jsx(ct,{columns:o},A)):t&&c.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:o,className:"px-3 py-6",children:S})}):c.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:o,className:"px-3 py-8 text-center text-sm text-muted-foreground",children:M})}):c.map((E,A)=>e.jsx(Et,{record:E,providerLabelMap:m,apiKeyMap:_,onSelect:r,isExpanded:E.id===w,onToggleExpand:b,isEven:A%2===0,density:y,visibleColumnSet:a,costCurrency:g},E.id))})]})}),x&&e.jsx("div",{className:"table-scroll-hint"})]}),e.jsx("div",{className:"md:hidden",children:d?e.jsx("div",{className:"space-y-3 p-4",children:Array.from({length:5}).map((E,A)=>e.jsx(cs,{className:"h-20 w-full"},A))}):t&&c.length===0?e.jsx("div",{className:"px-3 py-6",children:S}):c.length===0?e.jsx("div",{className:"px-3 py-8",children:M}):c.map(E=>e.jsx(_t,{record:E,providerLabelMap:m,onSelect:r,costCurrency:g},E.id))}),e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-4 bg-secondary/50 p-4 border-t border-border",children:[e.jsxs("div",{className:"flex items-center gap-2 border border-border bg-secondary px-3 py-1.5",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:l("logs.table.pagination.perPage")}),e.jsxs(pe,{value:L.toString(),onValueChange:E=>u(Number(E)),children:[e.jsx(xe,{className:"h-8 w-[80px] bg-background",children:e.jsx(ge,{})}),e.jsx(he,{children:oe.map(E=>e.jsx(U,{value:E.toString(),children:E},E))})]})]}),e.jsxs("div",{className:"flex items-center gap-2 border border-border bg-secondary px-2 py-1.5",children:[e.jsxs(D,{variant:"outline",size:"sm",onClick:()=>$(E=>Math.max(E-1,1)),disabled:F<=1,children:[e.jsx(Gs,{className:"mr-1 h-4 w-4","aria-hidden":"true"}),l("logs.table.pagination.previous")]}),e.jsx("span",{className:"metric-number px-1 text-sm text-muted-foreground",children:l("logs.table.pagination.pageLabel",{page:R===0?0:F,total:R})}),e.jsxs(D,{variant:"outline",size:"sm",onClick:()=>$(E=>R===0?E:Math.min(E+1,R)),disabled:R===0||F>=R,children:[l("logs.table.pagination.next"),e.jsx(Ze,{className:"ml-1 h-4 w-4","aria-hidden":"true"})]})]})]})]})})}function Ft({exportTimeoutMs:s,queryParams:l,total:i}){const{t:a}=Q(),{pushToast:o}=_e(),[t,d]=p.useState(!1),c=p.useCallback(async()=>{if(!t){d(!0);try{const g=i>0?Math.min(i,5e3):1e3,h={...l,limit:g,offset:0},f=await Re.exportArchive(h,s),C=new Date().toISOString().replace(/[:.]/g,"-"),N=URL.createObjectURL(f),m=document.createElement("a");m.href=N,m.download=`cc-gw-logs-${C}.zip`,document.body.appendChild(m),m.click(),m.remove(),URL.revokeObjectURL(N),o({title:a("logs.toast.exportSuccess.title"),description:a("logs.toast.exportSuccess.desc"),variant:"success"})}catch(g){const h=Xs(g);o({title:a("logs.toast.exportError.title"),description:a("logs.toast.exportError.desc",{message:h.message}),variant:"error"})}finally{d(!1)}}},[s,t,o,l,a,i]);return{exporting:t,handleExport:c}}function Dt(){const s=p.useRef(null),[l,i]=p.useState(!1),a=p.useCallback(()=>{const o=s.current;if(!o)return;const t=o.scrollWidth-o.scrollLeft-o.clientWidth>1;i(t)},[]);return p.useEffect(()=>{const o=s.current;if(!o)return;a(),o.addEventListener("scroll",a,{passive:!0});const t=new ResizeObserver(a);return t.observe(o),()=>{o.removeEventListener("scroll",a),t.disconnect()}},[a]),{scrollRef:s,showScrollHint:l,updateScrollHint:a}}const Tt="cc-gw.logs.visible-columns-v2";function Kt(){if(typeof window>"u")return B;const s=window.localStorage.getItem(Tt);if(!s)return B;try{const l=JSON.parse(s);if(!Array.isArray(l))return B;const i=l.filter(a=>te.includes(a));return i.length===0?B:(i.includes("cost")||i.push("cost"),i.sort((a,o)=>te.indexOf(a)-te.indexOf(o)))}catch{return B}}function Mt(){const[s,l]=I(K.logs.density,jt,{serialize:f=>f,deserialize:f=>f==="compact"?"compact":"comfortable"}),[i,a]=I(K.logs.visibleColumns,Kt,{serialize:JSON.stringify,deserialize:f=>{try{const C=JSON.parse(f);if(!Array.isArray(C))return B;const N=C.filter(m=>te.includes(m));return N.length>0?N:B}catch{return B}}}),{scrollRef:o,showScrollHint:t}=Dt(),d=p.useMemo(()=>new Set(i),[i]),c=i.length+2,g=p.useCallback(f=>{a(C=>{if(C.includes(f))return C.length===1?C:C.filter(m=>m!==f);const N=[...C,f];return N.sort((m,_)=>te.indexOf(m)-te.indexOf(_)),N})},[]);return{resetVisibleColumns:p.useCallback(()=>{a(B)},[]),rowDensity:s,setRowDensity:l,showScrollHint:t,tableScrollRef:o,toggleColumn:g,visibleColumnCount:c,visibleColumns:i,visibleColumnSet:d}}const Pt=3e3,At=200;function Ot(){var Pe,Ae,Oe,qe,ze,Ie;const{t:s}=Q(),{pushToast:l}=_e(),i=ht(),[a,o]=I(K.logs.providerFilter,"all"),[t,d]=I(K.logs.endpointFilter,"all"),[c,g]=I(K.logs.modelFilter,""),[h,f]=I(K.logs.clientKindFilter,"all"),[C,N]=I(K.logs.sessionFilter,""),[m,_]=I(K.logs.statusFilter,"all"),[r,w]=I(K.logs.fromDate,""),[b,y]=I(K.logs.toDate,""),[x,L]=p.useState(1),[u,F]=I(K.logs.autoRefresh,!0),[R,$]=I(K.logs.pageSize,vt,{serialize:n=>String(n),deserialize:n=>{const k=Number(n);return oe.includes(k)?k:oe[0]}}),[S,M]=p.useState(null),[E,A]=p.useState(!1),[G,j]=p.useState(null),[ie,xs]=p.useState(!1);p.useEffect(()=>{const n=document.querySelector('[data-testid="app-scroll"]'),k=()=>n?n.scrollTop:window.scrollY,T=()=>{xs(k()>=At)};T();const me=n??window;return me.addEventListener("scroll",T,{passive:!0}),()=>me.removeEventListener("scroll",T)},[]);const[P,de]=I(K.logs.selectedApiKeys,[],{serialize:JSON.stringify,deserialize:n=>{try{const k=JSON.parse(n);return Array.isArray(k)?k.map(T=>Number(T)).filter(T=>Number.isInteger(T)&&T>0):[]}catch{return[]}}}),[gs,hs]=p.useState(()=>typeof window>"u"||window.matchMedia("(min-width: 768px)").matches),{resetVisibleColumns:fs,rowDensity:ys,setRowDensity:bs,showScrollHint:js,tableScrollRef:vs,toggleColumn:Ns,visibleColumnCount:ws,visibleColumns:ks,visibleColumnSet:Ss}=Mt(),[H,Fe]=gt(),De=p.useRef(!1);p.useEffect(()=>{if(De.current)return;const n=["status","endpoint","provider","model","clientKind","session","from","to"];if(!n.some(Se=>H.has(Se)))return;De.current=!0,o("all"),d("all"),g(""),f("all"),N(""),_("all"),w(""),y(""),de([]);const k=H.get("status");(k==="success"||k==="error")&&_(k);const T=H.get("endpoint");T&&d(T);const me=H.get("provider");me&&o(me);const $e=H.get("model");$e&&g($e);const Ve=H.get("clientKind");Ve&&f(Ve);const Ue=H.get("session");Ue&&N(Ue);const Qe=H.get("from");Qe&&w(Qe);const He=H.get("to");He&&y(He);const Be=new URLSearchParams(H);for(const Se of n)Be.delete(Se);Fe(Be,{replace:!0})},[H,f,d,w,g,o,Fe,de,N,_,y]);const Cs=p.useDeferredValue(c),O=c===""?"":Cs,_s=p.useDeferredValue(C),J=C===""?"":_s;p.useEffect(()=>{L(1),j(null)},[a,t,O,h,J,m,r,b,R,P]);const be=p.useMemo(()=>{const n={limit:R,offset:(x-1)*R};a!=="all"&&(n.provider=a),t!=="all"&&(n.endpoint=t),O.trim().length>0&&(n.model=O.trim()),h!=="all"&&(n.clientKind=h),J.trim().length>0&&(n.session=J.trim()),m!=="all"&&(n.status=m);const k=Ge(r),T=Ge(b,!0);return k!==void 0&&(n.from=k),T!==void 0&&(n.to=T),P.length>0&&(n.apiKeys=P.join(",")),n},[O,J,h,t,r,x,R,a,P,m,b]),Y=re(se.logs.list(be),Re.listRequest(be),{gcTime:6e4,refetchInterval:u&&x===1&&G===null&&!E&&!ie?Pt:!1}),ae=re(se.providers.all(),We.providersRequest()),Te=re(se.apiKeys.all(),{url:"/api/keys",method:"GET"}),je=re(se.customEndpoints.all(),{url:"/api/custom-endpoints",method:"GET"}),Ke=re(se.config.exportTimeout(),We.configRequest());p.useEffect(()=>{!Y.isError||!Y.error||l({title:s("logs.toast.listError.title"),description:s("logs.toast.listError.desc",{message:Y.error.message}),variant:"error"})},[Y.error,Y.isError,l,s]),p.useEffect(()=>{!ae.isError||!ae.error||l({title:s("logs.toast.providerError.title"),description:s("logs.toast.providerError.desc",{message:ae.error.message}),variant:"error"})},[ae.error,ae.isError,l,s]);const fe=((Pe=Y.data)==null?void 0:Pe.total)??0,ce=fe>0?Math.ceil(fe/R):0,Ls=((Ae=Y.data)==null?void 0:Ae.items)??[],Es=(Oe=Y.data)==null?void 0:Oe.cost_currency,Rs=p.useMemo(()=>{var k;const n=(k=Ke.data)==null?void 0:k.logExportTimeoutSeconds;return typeof n=="number"&&Number.isFinite(n)?Math.min(Math.max(Math.round(n),5),600)*1e3:6e4},[(qe=Ke.data)==null?void 0:qe.logExportTimeoutSeconds]);p.useEffect(()=>{ce>0&&x>ce&&L(ce)},[x,ce]);const ve=ae.data??[],Ne=p.useMemo(()=>{const n=new Map;for(const k of ve)k.id&&n.set(k.id,k.label??k.id);return n},[ve]),Me=p.useMemo(()=>{var k;const n=new Map;n.set("anthropic",s("logs.filters.endpointAnthropic")),n.set("openai",s("logs.filters.endpointOpenAI"));for(const T of((k=je.data)==null?void 0:k.endpoints)??[])n.set(T.id,T.label||T.id);return n},[(ze=je.data)==null?void 0:ze.endpoints,s]),Fs=p.useMemo(()=>{const n=[];if(a!=="all"){const k=Ne.get(a)??a;n.push({key:"provider",label:`${s("logs.filters.provider")}: ${k}`,onRemove:()=>o("all")})}if(t!=="all"){const k=Me.get(t)??t;n.push({key:"endpoint",label:`${s("logs.filters.endpoint")}: ${k}`,onRemove:()=>d("all")})}if(O.trim()&&n.push({key:"model",label:`${s("logs.filters.modelId")}: ${O.trim()}`,onRemove:()=>g("")}),h!=="all"&&n.push({key:"clientKind",label:`${s("logs.filters.clientKind")}: ${s(`dashboard.usage.clientKinds.${h}`,{defaultValue:h})}`,onRemove:()=>f("all")}),J.trim()&&n.push({key:"session",label:`${s("logs.filters.session")}: ${J.trim()}`,onRemove:()=>N("")}),m!=="all"){const k=s(m==="success"?"logs.filters.statusSuccess":"logs.filters.statusError");n.push({key:"status",label:`${s("logs.filters.status")}: ${k}`,onRemove:()=>_("all")})}return r&&n.push({key:"from",label:`${s("logs.filters.startDate")}: ${r}`,onRemove:()=>w("")}),b&&n.push({key:"to",label:`${s("logs.filters.endDate")}: ${b}`,onRemove:()=>y("")}),P.length>0&&n.push({key:"apiKeys",label:s("logs.filters.apiKeySelected",{count:P.length}),onRemove:()=>de([])}),n},[O,J,h,t,Me,r,a,Ne,P.length,m,s,b]),we=Te.data??[],Ds=p.useMemo(()=>{const n=new Map;for(const k of we)n.set(k.id,k);return n},[we]),Ts=p.useMemo(()=>te.map(n=>({id:n,label:s(`logs.table.columns.${n}`)})),[s]),ue=p.useMemo(()=>{const n=new Date;return`${n.getFullYear()}-${String(n.getMonth()+1).padStart(2,"0")}-${String(n.getDate()).padStart(2,"0")}`},[]),Ks=p.useMemo(()=>h!=="all"||J.trim()!==""?null:a==="all"&&t==="all"&&O.trim()===""&&m==="all"&&r===""&&b===""&&P.length===0?"all":m==="error"&&t==="all"&&a==="all"&&O.trim()===""&&r===""&&b===""&&P.length===0?"errors":Nt(r,b,ue)&&t==="all"&&a==="all"&&O.trim()===""&&m==="all"&&P.length===0?"today":t==="anthropic"&&a==="all"&&O.trim()===""&&m==="all"&&r===""&&b===""&&P.length===0?"anthropic":t==="openai"&&a==="all"&&O.trim()===""&&m==="all"&&r===""&&b===""&&P.length===0?"openai":null,[O,J,h,t,r,a,P.length,m,b,ue]),ke=p.useCallback(()=>{o("all"),g(""),f("all"),N(""),d("all"),_("all"),w(""),y(""),de([])},[]),Ms=p.useCallback(n=>{if(L(1),ke(),n!=="all"){if(n==="errors"){_("error");return}if(n==="today"){w(ue),y(ue);return}if(n==="anthropic"){d("anthropic");return}n==="openai"&&d("openai")}},[ke,ue]),{exporting:Ps,handleExport:As}=Ft({exportTimeoutMs:Rs,queryParams:be,total:fe}),Os=p.useCallback(n=>{i.removeQueries({queryKey:["logs","detail"],type:"inactive"}),M(n),A(!0)},[i]),qs=p.useCallback(()=>{A(!1)},[]),zs=p.useCallback(n=>{j(k=>k===n?null:n)},[]);return p.useEffect(()=>{E||S===null||(i.removeQueries({queryKey:se.logs.detail(S),exact:!0}),M(null))},[E,i,S]),{activeFilters:Fs,activeQuickView:Ks,apiKeyMap:Ds,apiKeys:we,apiKeysQuery:Te,applyQuickView:Ms,autoRefresh:u,clientKindFilter:h,columnOptions:Ts,customEndpoints:(Ie=je.data)==null?void 0:Ie.endpoints,endpointFilter:t,exporting:Ps,expandedLogId:G,filtersExpanded:gs,fromDate:r,handleCloseDetail:qs,handleExport:As,handleOpenDetail:Os,handleResetFilters:ke,handleToggleExpand:zs,isDetailOpen:E,items:Ls,costCurrency:Es,logsQuery:Y,modelFilter:c,page:x,pageSize:R,providerFilter:a,providerLabelMap:Ne,providerOptions:ve,rowDensity:ys,resetVisibleColumns:fs,selectedApiKeys:P,selectedLogId:S,sessionFilter:C,setAutoRefresh:F,setClientKindFilter:f,setEndpointFilter:d,setFiltersExpanded:hs,setFromDate:w,setModelFilter:g,setPage:L,setPageSize:$,setProviderFilter:o,setRowDensity:bs,setSelectedApiKeys:de,setSessionFilter:N,setStatusFilter:_,setToDate:y,showScrollHint:js,statusFilter:m,tableScrollRef:vs,toDate:b,toggleColumn:Ns,total:fe,totalPages:ce,visibleColumnCount:ws,visibleColumns:ks,visibleColumnSet:Ss}}function rl(){var l;const s=Ot();return e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsx(Js,{actions:e.jsx(Ct,{autoRefresh:s.autoRefresh,columnOptions:s.columnOptions,exporting:s.exporting,onExport:()=>void s.handleExport(),onRefresh:()=>void s.logsQuery.refetch(),onResetColumns:s.resetVisibleColumns,onSetDensity:s.setRowDensity,onToggleAutoRefresh:s.setAutoRefresh,onToggleColumn:s.toggleColumn,refreshing:s.logsQuery.isFetching,rowDensity:s.rowDensity,visibleColumns:s.visibleColumns,visibleColumnSet:s.visibleColumnSet})}),e.jsx(wt,{activeFilters:s.activeFilters,filtersExpanded:s.filtersExpanded,setFiltersExpanded:s.setFiltersExpanded,handleResetFilters:s.handleResetFilters,activeQuickView:s.activeQuickView,applyQuickView:s.applyQuickView,providerFilter:s.providerFilter,setProviderFilter:s.setProviderFilter,endpointFilter:s.endpointFilter,setEndpointFilter:s.setEndpointFilter,selectedApiKeys:s.selectedApiKeys,setSelectedApiKeys:s.setSelectedApiKeys,modelFilter:s.modelFilter,setModelFilter:s.setModelFilter,clientKindFilter:s.clientKindFilter,setClientKindFilter:s.setClientKindFilter,sessionFilter:s.sessionFilter,setSessionFilter:s.setSessionFilter,statusFilter:s.statusFilter,setStatusFilter:s.setStatusFilter,fromDate:s.fromDate,setFromDate:s.setFromDate,toDate:s.toDate,setToDate:s.setToDate,providerOptions:s.providerOptions,apiKeys:s.apiKeys,apiKeysLoading:s.apiKeysQuery.isLoading,customEndpoints:s.customEndpoints}),e.jsx(Rt,{tableScrollRef:s.tableScrollRef,visibleColumnSet:s.visibleColumnSet,visibleColumnCount:s.visibleColumnCount,logsError:s.logsQuery.isError?((l=s.logsQuery.error)==null?void 0:l.message)??null:null,logsPending:s.logsQuery.isPending,items:s.items,costCurrency:s.costCurrency,activeFiltersCount:s.activeFilters.length,total:s.total,handleResetFilters:s.handleResetFilters,handleRetry:()=>void s.logsQuery.refetch(),providerLabelMap:s.providerLabelMap,apiKeyMap:s.apiKeyMap,handleOpenDetail:s.handleOpenDetail,expandedLogId:s.expandedLogId,onToggleExpand:s.handleToggleExpand,rowDensity:s.rowDensity,showScrollHint:s.showScrollHint,pageSize:s.pageSize,setPageSize:s.setPageSize,page:s.page,totalPages:s.totalPages,setPage:s.setPage}),e.jsx(kt,{open:s.isDetailOpen,logId:s.selectedLogId,onClose:s.handleCloseDetail,providerLabelMap:s.providerLabelMap,apiKeyMap:s.apiKeyMap})]})}export{rl as default};