@chenpu17/cc-gw 0.8.0 → 0.8.2

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 (42) hide show
  1. package/README.md +3 -3
  2. package/package.json +5 -5
  3. package/src/web/dist/assets/{About-DockN9He.js → About-BCHV3wbt.js} +1 -1
  4. package/src/web/dist/assets/ApiKeys-Do48QVpZ.js +1 -0
  5. package/src/web/dist/assets/Dashboard-BizLDn_V.js +1 -0
  6. package/src/web/dist/assets/{DialogShell-BKB8x8Yv.js → DialogShell-CiIvBp8J.js} +1 -1
  7. package/src/web/dist/assets/EChart-VRAvk6sX.js +1 -0
  8. package/src/web/dist/assets/{Events-CmUNBQ-L.js → Events-DpPg8dt0.js} +1 -1
  9. package/src/web/dist/assets/{Help-Bo6GcOG7.js → Help-B9ewdIkl.js} +1 -1
  10. package/src/web/dist/assets/{Login-uKKAO1uN.js → Login-5O2Xtr5G.js} +1 -1
  11. package/src/web/dist/assets/{Logs-ChD1V5Mf.js → Logs-D29vlNyO.js} +1 -1
  12. package/src/web/dist/assets/{ModelManagement-DTlt9WMp.js → ModelManagement-CrmNhCAh.js} +1 -1
  13. package/src/web/dist/assets/{PageHeader-DWkUnwoU.js → PageHeader-CSF0BWul.js} +1 -1
  14. package/src/web/dist/assets/{PageSection-9-z2ysug.js → PageSection-Bp_SuEp0.js} +1 -1
  15. package/src/web/dist/assets/{PageState-5sxEzXut.js → PageState-BeXrzVEe.js} +1 -1
  16. package/src/web/dist/assets/{Profiler-DBeKtgDs.js → Profiler-Cwuq3cjV.js} +1 -1
  17. package/src/web/dist/assets/{Settings-YMHmPlBz.js → Settings-Q6TBItFQ.js} +1 -1
  18. package/src/web/dist/assets/{Skeleton-CvBK2w-C.js → Skeleton-8j6Dxod1.js} +1 -1
  19. package/src/web/dist/assets/{badge-tREH_88e.js → badge-BvMdmUqJ.js} +1 -1
  20. package/src/web/dist/assets/{card-yK3LQB_K.js → card-CjhYPqKk.js} +1 -1
  21. package/src/web/dist/assets/{charts-core-vuhzGmuT.js → charts-core-C-3-Lo7l.js} +1 -1
  22. package/src/web/dist/assets/{charts-engine-BJQRnjQ_.js → charts-engine-BI1CmRJo.js} +1 -1
  23. package/src/web/dist/assets/{charts-react-BeVWPrMt.js → charts-react-DJ_0LNAP.js} +1 -1
  24. package/src/web/dist/assets/{gateway-D-NOc-e6.js → gateway-B0gBBN92.js} +1 -1
  25. package/src/web/dist/assets/{i18n-CfLThlXq.js → i18n-C7VVFIdN.js} +1 -1
  26. package/src/web/dist/assets/index-BzuBtvAC.js +61 -0
  27. package/src/web/dist/assets/{input-CXrASgDm.js → input-BnFZKjRM.js} +1 -1
  28. package/src/web/dist/assets/{label-CzHv4dNP.js → label-i5-Lf72z.js} +1 -1
  29. package/src/web/dist/assets/{popover-C-WmNbKp.js → popover-EFz6sQ7C.js} +1 -1
  30. package/src/web/dist/assets/{query-D3IfCUhp.js → query-DxhDvnDC.js} +1 -1
  31. package/src/web/dist/assets/{radix-54BMi3RD.js → radix-CmyU-WBH.js} +1 -1
  32. package/src/web/dist/assets/{router-CmaL1NgV.js → router-D8u_RlVh.js} +1 -1
  33. package/src/web/dist/assets/{select-DH6I1mKJ.js → select-KdDvaKo4.js} +1 -1
  34. package/src/web/dist/assets/{switch-IXq8M3lq.js → switch-BVWWsjy3.js} +1 -1
  35. package/src/web/dist/assets/{useApiQuery-CCy5_Mc8.js → useApiQuery-fBWRSgFK.js} +1 -1
  36. package/src/web/dist/assets/{useAppMutation-COEUmNH4.js → useAppMutation-Cd6HN12q.js} +1 -1
  37. package/src/web/dist/assets/{vendor-CjJPKsTb.js → vendor-5iCEqDpV.js} +1 -1
  38. package/src/web/dist/index.html +6 -6
  39. package/src/web/dist/assets/ApiKeys-Fx_SaOSe.js +0 -1
  40. package/src/web/dist/assets/Dashboard-De61szKh.js +0 -1
  41. package/src/web/dist/assets/EChart-Dqa_Xbrn.js +0 -1
  42. package/src/web/dist/assets/index-BiTh8byX.js +0 -61
@@ -1 +1 @@
1
- import{r as g,j as e,ak as Be,al as We,a8 as Ge,am as Je,aj as Xe,V as Ze,T as Ye}from"./vendor-CjJPKsTb.js";import{P as et}from"./PageHeader-DWkUnwoU.js";import{c as w,B as E,b as tt,u as ge,s as _,t as st,a as R}from"./index-BiTh8byX.js";import{B as K}from"./badge-tREH_88e.js";import{C as _e,a as Ee}from"./card-yK3LQB_K.js";import{I as ue}from"./input-CXrASgDm.js";import{L as I}from"./label-CzHv4dNP.js";import{S as ee,a as te,b as se,c as le,d as L}from"./select-DH6I1mKJ.js";import{u as M}from"./i18n-CfLThlXq.js";import{D as lt,A as at,a as rt,b as ot,c as it,d as nt}from"./DialogShell-BKB8x8Yv.js";import{P as dt,a as xe}from"./PageState-5sxEzXut.js";import{c as ct}from"./clipboard-CALi6bTW.js";import{u as $}from"./useApiQuery-CCy5_Mc8.js";import{q as U}from"./queryKeys-BMvyDTQS.js";import{f as O,a as De,b as mt,c as z,d as pt,g as ut}from"./utils-DQfq7gRo.js";import{P as xt,a as gt,b as ht}from"./popover-C-WmNbKp.js";import{T as ft}from"./Skeleton-CvBK2w-C.js";import{g as Se}from"./gateway-D-NOc-e6.js";import"./query-D3IfCUhp.js";import"./router-CmaL1NgV.js";import"./radix-54BMi3RD.js";function bt({apiKeys:l,selected:t,onChange:o,disabled:n,className:d}){const{t:s}=M(),[r,h]=g.useState(!1),c=g.useRef(null);g.useEffect(()=>{if(!r)return;const i=a=>{var p;(p=c.current)!=null&&p.contains(a.target)||h(!1)};return window.addEventListener("mousedown",i),()=>window.removeEventListener("mousedown",i)},[r]);const v=g.useMemo(()=>{if(t.length===0)return[];const i=new Map;for(const a of l)i.set(a.id,a);return t.map(a=>{const p=i.get(a);return p?p.isWildcard?s("apiKeys.wildcard"):p.name:null}).filter(a=>!!a)},[l,t,s]),u=t.length===0?s("logs.filters.apiKeyAll"):s("logs.filters.apiKeySelected",{count:t.length}),j=i=>{t.includes(i)?o(t.filter(a=>a!==i)):o([...t,i])};return e.jsxs("div",{className:w("relative space-y-2",d),ref:c,children:[e.jsx(I,{children:s("logs.filters.apiKey")}),e.jsxs("button",{type:"button",onClick:()=>h(i=>!i),disabled:n||l.length===0,title:s("logs.filters.apiKeyHint"),className:w("flex h-10 w-full items-center justify-between rounded-md border border-input bg-background px-3 text-sm ring-offset-background transition-all focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",t.length>0&&"border-primary",r&&"ring-2 ring-ring ring-offset-2"),children:[e.jsxs("span",{className:"truncate",children:[u,v.length>0&&e.jsx("span",{className:"ml-1 text-xs text-muted-foreground",children:v.join(", ")})]}),e.jsx("svg",{className:w("h-4 w-4 opacity-50 transition-transform",r&&"rotate-180"),viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M5.23 7.21a.75.75 0 011.06.02L10 10.94l3.71-3.71a.75.75 0 111.06 1.06l-4.24 4.25a.75.75 0 01-1.06 0L5.21 8.29a.75.75 0 01.02-1.08z",clipRule:"evenodd"})})]}),r&&e.jsxs("div",{className:"absolute left-0 top-full z-30 mt-2 w-64 rounded-md border bg-popover p-2 shadow-md",children:[e.jsxs("div",{className:"flex items-center justify-between rounded-md bg-secondary px-3 py-2 text-xs",children:[e.jsx("span",{children:u}),e.jsx("button",{type:"button",onClick:()=>o([]),disabled:t.length===0,className:"text-primary hover:underline disabled:opacity-40",children:s("common.actions.reset")})]}),e.jsxs("div",{className:"max-h-56 overflow-y-auto py-2",children:[l.map(i=>{const a=i.isWildcard?s("apiKeys.wildcard"):i.name,p=t.includes(i.id);return e.jsxs("label",{className:w("flex cursor-pointer items-center gap-2 rounded-xl px-3 py-2 text-sm transition hover:bg-primary/5",p&&"bg-primary/10 text-primary"),children:[e.jsx("input",{type:"checkbox",className:"h-4 w-4 rounded border-border",checked:p,onChange:()=>j(i.id)}),e.jsx("span",{className:"truncate",children:a})]},i.id)}),l.length===0&&e.jsx("p",{className:"px-2 py-2 text-xs text-muted-foreground",children:s("logs.filters.apiKeyAll")})]})]})]})}function yt(l){const{t}=M(),{total:o,activeFilters:n,filtersExpanded:d,setFiltersExpanded:s,handleResetFilters:r,activeQuickView:h,applyQuickView:c,providerFilter:v,setProviderFilter:u,endpointFilter:j,setEndpointFilter:i,selectedApiKeys:a,setSelectedApiKeys:p,modelFilter:f,setModelFilter:S,statusFilter:b,setStatusFilter:D,fromDate:C,setFromDate:T,toDate:N,setToDate:y,providerOptions:B,apiKeys:re,apiKeysLoading:oe,customEndpoints:W}=l;return e.jsx(_e,{"data-testid":"logs-filters-card",className:"overflow-hidden",children:e.jsxs(Ee,{className:"pt-4",children:[e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("p",{className:"text-sm font-semibold text-foreground",children:t("logs.filtersTitle")}),e.jsx(K,{variant:"outline",children:t("logs.summary.total",{value:o.toLocaleString()})}),n.length>0&&e.jsx(K,{variant:"secondary",children:t("common.filters.activeCount",{count:n.length})})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("logs.filtersDescription")})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[n.length>0&&e.jsx(E,{variant:"ghost",size:"sm",onClick:r,children:t("common.actions.reset")}),e.jsx(E,{variant:"ghost",size:"sm",onClick:()=>s(x=>!x),children:d?e.jsxs(e.Fragment,{children:[t("common.filters.collapse"),e.jsx(Be,{className:"ml-1 h-4 w-4"})]}):e.jsxs(e.Fragment,{children:[t("common.filters.expand"),e.jsx(We,{className:"ml-1 h-4 w-4"})]})})]})]}),e.jsxs("div",{className:"grid gap-3 lg:grid-cols-[minmax(0,1fr)_auto]",children:[e.jsx("div",{className:"flex min-h-[52px] items-center rounded-lg border border-border bg-secondary px-3 py-2",children:n.length>0?e.jsx("div",{className:"flex flex-wrap items-center gap-2",children:n.map(x=>e.jsxs(K,{variant:"secondary",role:"button",tabIndex:0,className:"cursor-pointer gap-1 border border-transparent bg-primary/10 text-primary hover:bg-destructive/10 hover:text-destructive",onClick:x.onRemove,onKeyDown:G=>{(G.key==="Enter"||G.key===" ")&&(G.preventDefault(),x.onRemove())},children:[x.label,e.jsx(Ge,{className:"h-3 w-3","aria-hidden":"true"})]},x.key))}):e.jsx("span",{className:"text-sm text-muted-foreground",children:t("common.filters.allRequests")})}),e.jsxs("div",{className:"grid grid-cols-2 gap-3 sm:grid-cols-4 lg:min-w-[360px]",children:[e.jsx(Y,{label:t("common.filters.activeCount",{count:n.length}),value:n.length.toString()}),e.jsx(Y,{label:t("logs.filters.apiKey"),value:a.length.toString()}),e.jsx(Y,{label:t("logs.filters.provider"),value:v==="all"?t("common.noData"):"1"}),e.jsx(Y,{label:t("logs.filters.endpoint"),value:j==="all"?t("common.noData"):"1"})]})]}),e.jsx("div",{className:"flex flex-wrap items-center gap-2 rounded-lg border border-border bg-secondary p-2",children:["all","errors","today","anthropic","openai"].map(x=>e.jsx(E,{variant:h===x?"default":"outline",size:"sm",className:w("rounded-full border-transparent",h===x&&x==="all"&&"bg-foreground text-background hover:bg-foreground/90",h===x&&x==="errors"&&"bg-rose-500 text-white hover:bg-rose-500/90",h===x&&x==="today"&&"bg-emerald-500 text-white hover:bg-emerald-500/90",h===x&&(x==="anthropic"||x==="openai")&&"bg-amber-500 text-white hover:bg-amber-500/90"),onClick:()=>c(x),children:t(`logs.quickViews.${x}`)},x))})]}),d&&e.jsxs("div",{className:"mt-4 grid gap-4 rounded-lg border border-border bg-secondary p-4 md:grid-cols-2 xl:grid-cols-4 animate-in fade-in slide-in-from-top-2 duration-200",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(I,{children:t("logs.filters.provider")}),e.jsxs(ee,{value:v,onValueChange:u,children:[e.jsx(te,{children:e.jsx(se,{})}),e.jsxs(le,{children:[e.jsx(L,{value:"all",children:t("logs.filters.providerAll")}),B.map(x=>e.jsx(L,{value:x.id,children:x.label??x.id},x.id))]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(I,{children:t("logs.filters.endpoint")}),e.jsxs(ee,{value:j,onValueChange:i,children:[e.jsx(te,{children:e.jsx(se,{})}),e.jsxs(le,{children:[e.jsx(L,{value:"all",children:t("logs.filters.endpointAll")}),e.jsx(L,{value:"anthropic",children:t("logs.filters.endpointAnthropic")}),e.jsx(L,{value:"openai",children:t("logs.filters.endpointOpenAI")}),W==null?void 0:W.map(x=>e.jsx(L,{value:x.id,children:x.label||x.id},x.id))]})]})]}),e.jsx(bt,{className:"md:col-span-2",apiKeys:re,selected:a,disabled:oe,onChange:p}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(I,{children:t("logs.filters.modelId")}),e.jsx(ue,{value:f,onChange:x=>S(x.target.value),placeholder:t("logs.filters.modelPlaceholder")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(I,{children:t("logs.filters.status")}),e.jsxs(ee,{value:b,onValueChange:x=>D(x),children:[e.jsx(te,{children:e.jsx(se,{})}),e.jsxs(le,{children:[e.jsx(L,{value:"all",children:t("logs.filters.statusAll")}),e.jsx(L,{value:"success",children:t("logs.filters.statusSuccess")}),e.jsx(L,{value:"error",children:t("logs.filters.statusError")})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(I,{children:t("logs.filters.startDate")}),e.jsx(ue,{type:"date",value:C,onChange:x=>T(x.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(I,{children:t("logs.filters.endDate")}),e.jsx(ue,{type:"date",value:N,onChange:x=>y(x.target.value)})]})]})]})})}function Y({label:l,value:t}){return e.jsxs("div",{className:"rounded-lg border border-border bg-card px-3 py-2",children:[e.jsx("p",{className:"text-[11px] text-muted-foreground",children:l}),e.jsx("p",{className:"mt-1 text-sm font-semibold text-foreground",children:t})]})}const he={listRequest(l){return{url:"/api/logs",method:"GET",params:l}},detailRequest(l){return{url:l===null?"":`/api/logs/${l}`,method:"GET"}},async exportArchive(l,t){const o=await tt.post("/api/logs/export",l,{responseType:"blob",timeout:t});return new Blob([o.data],{type:"application/zip"})}};function jt({apiKeyMap:l,logId:t,open:o,providerLabelMap:n}){var i;const{t:d}=M(),{pushToast:s}=ge(),r=$(U.logs.detail(t),he.detailRequest(t),{enabled:o&&t!==null,staleTime:3e4});g.useEffect(()=>{!r.isError||!r.error||s({title:d("logs.detail.loadError"),description:r.error.message,variant:"error"})},[r.error,r.isError,s,d]);const h=g.useCallback(async(a,p,f)=>{if(!p){s({title:d("logs.detail.copy.empty",{label:a}),variant:"info"});return}try{await ct(p),s({title:d(f),variant:"success"})}catch(S){s({title:d("logs.detail.copy.failure"),description:S instanceof Error?S.message:d("logs.detail.copy.failureFallback"),variant:"error"})}},[s,d]),c=r.data,v=c?n.get(c.provider)??c.provider:"",u=c&&c.api_key_id!=null?l.get(c.api_key_id):void 0,j=c?c.status_code??(c.error?500:200):null;return{apiKeyMeta:u,errorMessage:r.isError?((i=r.error)==null?void 0:i.message)??null:null,handleCopy:h,isError:r.isError,isPending:r.isPending,providerLabel:v,refetch:r.refetch,record:c,statusCode:j}}function vt({open:l,logId:t,onClose:o,providerLabelMap:n,apiKeyMap:d}){var S,b,D,C,T,N;const{t:s}=M(),{apiKeyMeta:r,errorMessage:h,handleCopy:c,isError:v,isPending:u,providerLabel:j,refetch:i,record:a,statusCode:p}=jt({apiKeyMap:d,logId:t,open:l,providerLabelMap:n}),f=a?[{key:"client-request",title:s("logs.detail.payload.clientRequest"),value:((S=a.payload)==null?void 0:S.client_request)??null,emptyLabel:s("logs.detail.payload.emptyRequest"),copyToast:"logs.detail.copy.requestSuccess"},...(b=a.payload)!=null&&b.upstream_request?[{key:"upstream-request",title:s("logs.detail.payload.upstreamRequest"),value:a.payload.upstream_request,emptyLabel:s("logs.detail.payload.emptyRequest"),copyToast:"logs.detail.copy.requestSuccess"}]:[],...(D=a.payload)!=null&&D.upstream_response?[{key:"upstream-response",title:s("logs.detail.payload.upstreamResponse"),value:a.payload.upstream_response,emptyLabel:s("logs.detail.payload.emptyResponse"),copyToast:"logs.detail.copy.responseSuccess"}]:[],{key:"client-response",title:s("logs.detail.payload.clientResponse"),value:((C=a.payload)==null?void 0:C.client_response)??null,emptyLabel:s("logs.detail.payload.emptyResponse"),copyToast:"logs.detail.copy.responseSuccess"}]:[];return e.jsx(lt,{open:l,onOpenChange:y=>{y||o()},children:e.jsxs(at,{className:"w-[min(96vw,1200px)] max-w-[1200px]",children:[e.jsxs(rt,{className:"pr-14",children:[e.jsx(ot,{children:s("logs.detail.title")}),e.jsx(it,{children:a?s("logs.detail.id",{id:a.id}):s("logs.detail.loadError")})]}),e.jsx(nt,{className:"max-h-[78vh]",children:u?e.jsx(dt,{compact:!0,className:"min-h-[240px]",label:s("common.loading")}):v?e.jsx(xe,{compact:!0,className:"min-h-[240px]",tone:"danger",title:s("logs.detail.loadError"),description:h??s("common.unknownError"),action:e.jsx(E,{variant:"outline",onClick:()=>void i(),children:s("common.actions.refresh")})}):a?e.jsxs("div",{className:"space-y-6 text-sm",children:[e.jsxs("section",{className:"space-y-4 rounded-lg border border-border bg-card p-5",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:s("logs.detail.infoSection")}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 rounded-lg border border-border bg-secondary p-3 text-xs",children:[e.jsx("span",{className:"font-medium",children:s("logs.detail.summary.route",{from:a.client_model??s("logs.detail.info.noRequestedModel"),to:a.model})}),e.jsx("span",{className:"text-muted-foreground",children:s("logs.detail.summary.latency",{value:O(a.latency_ms,s("common.units.ms"))})}),a.ttft_ms!==null?e.jsxs("span",{className:"text-muted-foreground",children:["TTFT: ",O(a.ttft_ms,s("common.units.ms"))]}):null]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(K,{variant:a.error?"destructive":"default",children:p==null?void 0:p.toString()}),e.jsx(K,{variant:"outline",children:a.stream?s("logs.stream.streaming"):s("logs.stream.single")})]})]}),e.jsxs("div",{className:"grid gap-3 md:grid-cols-4",children:[e.jsx(A,{label:s("logs.detail.info.latency"),value:O(a.latency_ms,s("common.units.ms"))}),e.jsx(A,{label:s("logs.detail.info.ttft"),value:O(a.ttft_ms,s("common.units.ms"))}),e.jsx(A,{label:s("logs.detail.info.tpot"),value:O(a.tpot_ms,s("common.units.msPerToken"))}),e.jsx(A,{label:s("logs.detail.info.status"),value:(p==null?void 0:p.toString())??"-"})]}),e.jsxs("dl",{className:"grid gap-x-4 gap-y-3 md:grid-cols-2 xl:grid-cols-4",children:[e.jsx(F,{label:s("logs.detail.info.time"),value:De(a.timestamp)}),e.jsx(F,{label:s("logs.detail.info.sessionId"),value:a.session_id??"-"}),e.jsx(F,{label:s("logs.detail.info.endpoint"),value:a.endpoint||"-"}),e.jsx(F,{label:s("logs.detail.info.provider"),value:j}),e.jsx(F,{label:s("logs.detail.info.requestedModel"),value:a.client_model??s("logs.detail.info.noRequestedModel")}),e.jsx(F,{label:s("logs.detail.info.model"),value:a.model}),e.jsx(F,{label:s("logs.detail.info.stream"),value:mt(a.stream)}),e.jsx(F,{label:s("logs.detail.info.status"),value:p})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2 xl:grid-cols-4",children:[e.jsx(A,{label:s("logs.detail.info.inputTokens"),value:z(a.input_tokens)}),e.jsx(A,{label:s("logs.detail.info.cacheReadTokens"),value:z(a.cache_read_tokens)}),e.jsx(A,{label:s("logs.detail.info.cacheCreationTokens"),value:z(a.cache_creation_tokens)}),e.jsx(A,{label:s("logs.detail.info.outputTokens"),value:z(a.output_tokens)})]}),a.error?e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:s("logs.detail.info.error")}),e.jsx("p",{className:"rounded-[1rem] border border-destructive/50 bg-destructive/10 p-3 text-xs text-destructive",children:a.error})]}):null]}),e.jsxs("div",{className:"grid gap-6 xl:grid-cols-[minmax(0,0.9fr)_minmax(0,1.1fr)]",children:[e.jsxs("section",{className:"space-y-3 rounded-lg border border-border bg-card p-5",children:[e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:s("logs.detail.apiKey.title")}),e.jsxs("dl",{className:"grid gap-x-4 gap-y-3 sm:grid-cols-2",children:[e.jsx(F,{label:s("logs.detail.apiKey.name"),value:a.api_key_id==null&&!a.api_key_name?s("logs.detail.apiKey.missing"):r!=null&&r.isWildcard?s("apiKeys.wildcard"):(r==null?void 0:r.name)??a.api_key_name??s("logs.detail.apiKey.missing")}),e.jsx(F,{label:s("logs.detail.apiKey.identifier"),value:a.api_key_id??s("common.noData")}),e.jsx(F,{label:s("logs.detail.apiKey.masked"),value:r!=null&&r.isWildcard?s("apiKeys.wildcard"):(r==null?void 0:r.maskedKey)??a.api_key_name??s("logs.detail.apiKey.maskedUnavailable")}),e.jsx(F,{label:s("logs.detail.apiKey.lastUsed"),value:r!=null&&r.lastUsedAt?new Date(r.lastUsedAt).toLocaleString():s("common.noData")})]}),e.jsxs("div",{className:"rounded-lg border border-border bg-secondary p-3 text-xs",children:[e.jsx("p",{className:"font-medium",children:s("logs.detail.apiKey.rawMasked")}),e.jsx("p",{className:"mt-1 break-all font-mono",children:a.api_key_value_available?a.api_key_value_masked??s("logs.detail.apiKey.rawUnavailable"):s("logs.detail.apiKey.rawUnavailable")}),e.jsx("p",{className:"mt-2 text-[11px] text-muted-foreground",children:s("logs.detail.apiKey.rawMaskedHint")})]})]}),e.jsxs("section",{className:"space-y-4 rounded-lg border border-border bg-card p-5",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:s("logs.detail.payload.title")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:(T=a.payload)!=null&&T.upstream_request||(N=a.payload)!=null&&N.upstream_response?s("logs.detail.payload.helperWithUpstream"):s("logs.detail.payload.helperClientOnly")})]}),e.jsx("div",{className:"grid gap-4 xl:grid-cols-2",children:f.map(y=>e.jsx(Nt,{title:y.title,value:y.value,emptyLabel:y.emptyLabel,onCopy:()=>c(y.title,y.value,y.copyToast),t:s},y.key))})]})]})]}):e.jsx(xe,{compact:!0,className:"min-h-[240px]",title:s("logs.detail.loadError"),description:s("common.noData")})})]})})}function A({label:l,value:t}){return e.jsxs("div",{className:"min-w-0 rounded-lg border border-border bg-secondary px-3 py-3",children:[e.jsx("p",{className:"text-[11px] font-medium uppercase tracking-[0.16em] text-muted-foreground",children:l}),e.jsx("p",{className:"mt-2 break-all text-sm font-semibold leading-6",children:t})]})}function F({label:l,value:t}){return e.jsxs("div",{className:"min-w-0 space-y-1",children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:l}),e.jsx("dd",{className:"min-w-0 break-all whitespace-pre-wrap text-sm font-medium leading-6 text-foreground",children:t??"-"})]})}function Nt({emptyLabel:l,onCopy:t,title:o,value:n,t:d}){return e.jsxs("div",{className:"space-y-3 rounded-lg border border-border bg-secondary/40 p-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsx("h4",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:o}),e.jsx(E,{variant:"outline",size:"sm",onClick:t,children:d("common.actions.copy")})]}),e.jsx("pre",{className:"max-h-72 overflow-auto whitespace-pre-wrap rounded-lg border border-border bg-secondary p-3 text-xs",children:pt(n,l)})]})}const H=[20,50,100],Q=["endpoint","provider","requestedModel","routedModel","apiKey","inputTokens","cacheReadTokens","cacheCreationTokens","outputTokens","latency","ttft","tpot","status","error"],ae=["endpoint","provider","requestedModel","routedModel","apiKey","inputTokens","cacheReadTokens","cacheCreationTokens","outputTokens","latency","ttft","tpot","status","error"];function wt(){if(typeof window>"u")return Q;try{const l=window.localStorage.getItem(_.logs.visibleColumns);if(!l)return Q;const t=JSON.parse(l);if(!Array.isArray(t))return Q;const o=t.filter(n=>ae.includes(n));return o.length>0?o:Q}catch{return Q}}function kt(){return typeof window>"u"?"comfortable":window.localStorage.getItem(_.logs.density)==="compact"?"compact":"comfortable"}function St(){if(typeof window>"u")return H[0];const l=window.localStorage.getItem(_.logs.pageSize),t=Number(l);return H.includes(t)?t:H[0]}function Ct(){if(typeof window>"u")return[];try{const l=window.localStorage.getItem(_.logs.selectedApiKeys);if(!l)return[];const t=JSON.parse(l);return Array.isArray(t)?t.map(o=>Number(o)).filter(o=>Number.isInteger(o)&&o>0):[]}catch{return[]}}function Ce(l,t=!1){if(!l)return;const o=t?`${l}T23:59:59.999`:`${l}T00:00:00.000`,n=Date.parse(o);return Number.isFinite(n)?n:void 0}function _t(l,t,o){return l===o&&t===o}function Et({columnOptions:l,exporting:t,onExport:o,onRefresh:n,onResetColumns:d,onSetDensity:s,onToggleColumn:r,refreshing:h,rowDensity:c,total:v,visibleColumns:u,visibleColumnSet:j}){const{t:i}=M(),a=JSON.stringify(u)===JSON.stringify(Q);return e.jsxs("div",{className:"flex w-full flex-col gap-3 xl:w-auto xl:flex-row xl:items-center",children:[e.jsxs("div",{className:"flex w-full flex-col gap-3 sm:flex-row sm:flex-wrap sm:items-center xl:w-auto xl:flex-nowrap",children:[e.jsxs("div",{className:"flex w-full items-center gap-1 overflow-x-auto rounded-full border border-border bg-secondary p-1 sm:w-auto",children:[e.jsx("button",{type:"button",onClick:()=>s("comfortable"),className:w("inline-flex h-8 flex-1 items-center justify-center whitespace-nowrap rounded-full px-3.5 text-xs font-medium transition-all sm:flex-none",c==="comfortable"?"bg-primary text-primary-foreground shadow-[0_8px_18px_-14px_rgba(59,130,246,0.7)]":"text-muted-foreground hover:bg-primary/5 hover:text-foreground"),children:i("logs.table.density.comfortable")}),e.jsx("button",{type:"button",onClick:()=>s("compact"),className:w("inline-flex h-8 flex-1 items-center justify-center whitespace-nowrap rounded-full px-3.5 text-xs font-medium transition-all sm:flex-none",c==="compact"?"bg-primary text-primary-foreground shadow-[0_8px_18px_-14px_rgba(59,130,246,0.7)]":"text-muted-foreground hover:bg-primary/5 hover:text-foreground"),children:i("logs.table.density.compact")})]}),e.jsxs(xt,{children:[e.jsx(gt,{asChild:!0,children:e.jsx(E,{variant:"outline",size:"sm",className:"w-full sm:w-auto",children:i("logs.actions.columns")})}),e.jsxs(ht,{align:"end",className:"w-64 p-3",children:[e.jsxs("div",{className:"mb-3 flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-semibold",children:i("logs.actions.columns")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:i("logs.actions.visibleCount",{count:u.length})})]}),e.jsx(E,{variant:"ghost",size:"sm",onClick:d,disabled:a,children:i("common.actions.reset")})]}),e.jsx("div",{className:"grid gap-1.5",children:l.map(p=>{const f=j.has(p.id);return e.jsxs("label",{className:w("flex cursor-pointer items-center gap-3 rounded-xl px-3 py-2 text-sm transition hover:bg-primary/5",f&&"bg-primary/10 text-primary"),children:[e.jsx("input",{type:"checkbox",checked:f,onChange:()=>r(p.id),className:"h-4 w-4 rounded border-border"}),e.jsx("span",{children:p.label})]},p.id)})})]})]}),e.jsxs(E,{onClick:o,disabled:t,className:"w-full sm:w-auto",children:[e.jsx(Je,{className:"mr-2 h-4 w-4"}),i(t?"logs.actions.exporting":"logs.actions.export")]})]}),e.jsxs("div",{className:"flex w-full items-center justify-between gap-3 xl:w-auto xl:justify-start",children:[e.jsx("span",{className:"text-xs text-muted-foreground sm:text-sm",children:i("logs.summary.total",{value:v.toLocaleString()})}),e.jsxs(E,{variant:"outline",size:"sm",onClick:n,disabled:h,className:"shrink-0",children:[e.jsx(Xe,{className:w("mr-2 h-4 w-4",h&&"animate-spin")}),i(h?"common.actions.refreshing":"logs.actions.manualRefresh")]})]})]})}function Dt({record:l,providerLabelMap:t,apiKeyMap:o,onSelect:n,isEven:d,density:s,visibleColumnSet:r}){const{t:h}=M(),c=t.get(l.provider)??l.provider,v=l.endpoint||"-",u=!!l.error,j=l.status_code,i=l.client_model??h("logs.table.requestedModelFallback"),a=l.api_key_id!=null?o.get(l.api_key_id):void 0,p=l.api_key_id==null?h("logs.table.apiKeyUnknown"):a!=null&&a.isWildcard?h("apiKeys.wildcard"):a!=null&&a.name?a.name:l.api_key_name?l.api_key_name:h("logs.table.apiKeyUnknown"),f=s==="compact"?"px-3 py-1.5":"px-3 py-2",S=d?"bg-muted/30":"bg-background",b=ut(l.session_id),D=b==null?void 0:b.rowStyle,C=b==null?void 0:b.stickyStyle,T=b?{...b.stickyStyle,...b.accentStyle}:void 0;return e.jsxs("tr",{"data-session-id":b==null?void 0:b.sessionId,"data-session-color":b==null?void 0:b.colorKey,className:w("transition-colors",b?"":d?"bg-muted/30":"",b?"":"hover:bg-muted/50"),style:D,onMouseEnter:N=>{b&&Object.assign(N.currentTarget.style,b.hoverStyle)},onMouseLeave:N=>{b&&Object.assign(N.currentTarget.style,b.rowStyle)},children:[e.jsx("td",{className:w("sticky left-0 z-10 text-xs",f,b?"":S),style:T,children:De(l.timestamp)}),r.has("endpoint")&&e.jsx("td",{className:w(f,"text-xs"),children:v}),r.has("provider")&&e.jsx("td",{className:w(f,"text-xs"),children:e.jsx("div",{className:"max-w-[100px] truncate",title:c,children:c})}),r.has("requestedModel")&&e.jsx("td",{className:w(f,"text-xs text-muted-foreground"),children:e.jsx("div",{className:"max-w-[120px] truncate",title:i,children:i})}),r.has("routedModel")&&e.jsx("td",{className:w(f,"text-xs"),children:e.jsx("div",{className:"max-w-[120px] truncate",title:l.model,children:l.model})}),r.has("apiKey")&&e.jsx("td",{className:w(f,"text-xs text-muted-foreground"),children:e.jsx("div",{className:"max-w-[90px] truncate",title:p,children:p})}),r.has("inputTokens")&&e.jsx("td",{className:w(f,"text-right text-xs tabular-nums"),children:z(l.input_tokens)}),r.has("cacheReadTokens")&&e.jsx("td",{className:w(f,"text-right text-xs tabular-nums"),children:z(l.cache_read_tokens)}),r.has("cacheCreationTokens")&&e.jsx("td",{className:w(f,"text-right text-xs tabular-nums"),children:z(l.cache_creation_tokens)}),r.has("outputTokens")&&e.jsx("td",{className:w(f,"text-right text-xs tabular-nums"),children:z(l.output_tokens)}),r.has("latency")&&e.jsx("td",{className:w(f,"text-right text-xs tabular-nums"),children:O(l.latency_ms,"ms")}),r.has("ttft")&&e.jsx("td",{className:w(f,"text-right text-xs tabular-nums"),children:O(l.ttft_ms,"ms")}),r.has("tpot")&&e.jsx("td",{className:w(f,"text-right text-xs tabular-nums"),children:O(l.tpot_ms,"ms/tk")}),r.has("status")&&e.jsx("td",{className:w(f,"text-center"),children:e.jsx(K,{variant:u?"destructive":"default",className:"text-xs",children:j??(u?500:200)})}),r.has("error")&&e.jsx("td",{className:w(f,"text-xs text-muted-foreground"),children:e.jsx("div",{className:"max-w-[100px] truncate",title:l.error??"",children:l.error?l.error:"-"})}),e.jsx("td",{className:w("sticky right-0 z-10 text-center",f,b?"":S),style:C,children:e.jsx(E,{variant:"outline",size:"sm",onClick:()=>n(l.id),children:h("logs.actions.detail")})})]})}function Ft(l){const{t}=M(),{tableScrollRef:o,visibleColumnSet:n,visibleColumnCount:d,logsError:s,logsPending:r,items:h,activeFiltersCount:c,handleResetFilters:v,handleRetry:u,providerLabelMap:j,apiKeyMap:i,handleOpenDetail:a,rowDensity:p,showScrollHint:f,pageSize:S,setPageSize:b,page:D,totalPages:C,setPage:T}=l;return e.jsx(_e,{className:"overflow-hidden",children:e.jsxs(Ee,{className:"p-0",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 border-b border-border bg-secondary px-4 py-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-sm font-semibold",children:t("logs.title")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("logs.actions.visibleCount",{count:d-2})})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(K,{variant:"secondary",children:"Wide Table"}),e.jsx(K,{variant:"outline",children:t(p==="compact"?"logs.table.density.compact":"logs.table.density.comfortable")}),f?e.jsx(K,{variant:"outline",className:"border-amber-200 bg-amber-50 text-amber-700 dark:border-amber-800 dark:bg-amber-950/30 dark:text-amber-300",children:"Scroll for more"}):null]})]}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{ref:o,className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full min-w-[1480px] text-sm",children:[e.jsx("thead",{className:"border-b bg-muted/50",children:e.jsxs("tr",{children:[e.jsx("th",{className:"sticky left-0 z-20 bg-muted/95 px-3 py-2 text-left text-xs font-medium backdrop-blur",children:t("logs.table.columns.time")}),n.has("endpoint")&&e.jsx("th",{className:"px-3 py-2 text-left text-xs font-medium",children:t("logs.table.columns.endpoint")}),n.has("provider")&&e.jsx("th",{className:"px-3 py-2 text-left text-xs font-medium",children:t("logs.table.columns.provider")}),n.has("requestedModel")&&e.jsx("th",{className:"px-3 py-2 text-left text-xs font-medium",children:t("logs.table.columns.requestedModel")}),n.has("routedModel")&&e.jsx("th",{className:"px-3 py-2 text-left text-xs font-medium",children:t("logs.table.columns.routedModel")}),n.has("apiKey")&&e.jsx("th",{className:"px-3 py-2 text-left text-xs font-medium",children:t("logs.table.columns.apiKey")}),n.has("inputTokens")&&e.jsx("th",{className:"px-3 py-2 text-right text-xs font-medium",children:t("logs.table.columns.inputTokens")}),n.has("cacheReadTokens")&&e.jsx("th",{className:"px-3 py-2 text-right text-xs font-medium",children:t("logs.table.columns.cacheReadTokens")}),n.has("cacheCreationTokens")&&e.jsx("th",{className:"px-3 py-2 text-right text-xs font-medium",children:t("logs.table.columns.cacheCreationTokens")}),n.has("outputTokens")&&e.jsx("th",{className:"px-3 py-2 text-right text-xs font-medium",children:t("logs.table.columns.outputTokens")}),n.has("latency")&&e.jsx("th",{className:"px-3 py-2 text-right text-xs font-medium",children:t("logs.table.columns.latency")}),n.has("ttft")&&e.jsx("th",{className:"px-3 py-2 text-right text-xs font-medium",children:t("logs.table.columns.ttft")}),n.has("tpot")&&e.jsx("th",{className:"px-3 py-2 text-right text-xs font-medium",children:t("logs.table.columns.tpot")}),n.has("status")&&e.jsx("th",{className:"px-3 py-2 text-center text-xs font-medium",children:t("logs.table.columns.status")}),n.has("error")&&e.jsx("th",{className:"px-3 py-2 text-left text-xs font-medium",children:t("logs.table.columns.error")}),e.jsx("th",{className:"sticky right-0 z-20 bg-muted/95 px-3 py-2 text-center text-xs font-medium backdrop-blur",children:t("logs.table.columns.actions")})]})}),e.jsx("tbody",{className:"divide-y",children:r?Array.from({length:8}).map((N,y)=>e.jsx(ft,{columns:d},y)):s&&h.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:d,className:"px-3 py-6",children:e.jsx(xe,{compact:!0,tone:"danger",icon:e.jsx(Ze,{className:"h-5 w-5","aria-hidden":"true"}),title:t("logs.toast.listError.title"),description:s,action:e.jsxs("div",{className:"flex flex-wrap items-center justify-center gap-2",children:[e.jsx(E,{variant:"outline",size:"sm",onClick:u,children:t("common.actions.refresh")}),c>0?e.jsx(E,{variant:"ghost",size:"sm",onClick:v,children:t("common.actions.reset")}):null]})})})}):h.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:d,className:"px-3 py-8 text-center text-sm text-muted-foreground",children:e.jsxs("div",{className:"flex flex-col items-center gap-3 py-4",children:[e.jsx("span",{children:t("logs.table.empty")}),c>0&&e.jsx(E,{variant:"outline",size:"sm",onClick:v,children:t("common.actions.reset")})]})})}):h.map((N,y)=>e.jsx(Dt,{record:N,providerLabelMap:j,apiKeyMap:i,onSelect:a,isEven:y%2===0,density:p,visibleColumnSet:n},N.id))})]})}),f&&e.jsx("div",{className:"table-scroll-hint"})]}),e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-4 border-t p-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:t("logs.table.pagination.perPage")}),e.jsxs(ee,{value:S.toString(),onValueChange:N=>b(Number(N)),children:[e.jsx(te,{className:"w-[80px]",children:e.jsx(se,{})}),e.jsx(le,{children:H.map(N=>e.jsx(L,{value:N.toString(),children:N},N))})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(E,{variant:"outline",size:"sm",onClick:()=>T(N=>Math.max(N-1,1)),disabled:D<=1,children:t("logs.table.pagination.previous")}),e.jsx("span",{className:"text-sm text-muted-foreground",children:t("logs.table.pagination.pageLabel",{page:C===0?0:D,total:C})}),e.jsx(E,{variant:"outline",size:"sm",onClick:()=>T(N=>C===0?N:Math.min(N+1,C)),disabled:C===0||D>=C,children:t("logs.table.pagination.next")})]})]})]})})}function Tt({exportTimeoutMs:l,queryParams:t,total:o}){const{t:n}=M(),{pushToast:d}=ge(),[s,r]=g.useState(!1),h=g.useCallback(async()=>{if(!s){r(!0);try{const c=o>0?Math.min(o,5e3):1e3,v={...t,limit:c,offset:0},u=await he.exportArchive(v,l),j=new Date().toISOString().replace(/[:.]/g,"-"),i=URL.createObjectURL(u),a=document.createElement("a");a.href=i,a.download=`cc-gw-logs-${j}.zip`,document.body.appendChild(a),a.click(),a.remove(),URL.revokeObjectURL(i),d({title:n("logs.toast.exportSuccess.title"),description:n("logs.toast.exportSuccess.desc"),variant:"success"})}catch(c){const v=st(c);d({title:n("logs.toast.exportError.title"),description:n("logs.toast.exportError.desc",{message:v.message}),variant:"error"})}finally{r(!1)}}},[l,s,d,t,n,o]);return{exporting:s,handleExport:h}}function Rt(){const l=g.useRef(null),[t,o]=g.useState(!1),n=g.useCallback(()=>{const d=l.current;if(!d)return;const s=d.scrollWidth-d.scrollLeft-d.clientWidth>1;o(s)},[]);return g.useEffect(()=>{const d=l.current;if(!d)return;n(),d.addEventListener("scroll",n,{passive:!0});const s=new ResizeObserver(n);return s.observe(d),()=>{d.removeEventListener("scroll",n),s.disconnect()}},[n]),{scrollRef:l,showScrollHint:t,updateScrollHint:n}}function Lt(){const[l,t]=R(_.logs.density,kt,{serialize:u=>u,deserialize:u=>u==="compact"?"compact":"comfortable"}),[o,n]=R(_.logs.visibleColumns,wt),{scrollRef:d,showScrollHint:s}=Rt(),r=g.useMemo(()=>new Set(o),[o]),h=o.length+2,c=g.useCallback(u=>{n(j=>{if(j.includes(u))return j.length===1?j:j.filter(a=>a!==u);const i=[...j,u];return i.sort((a,p)=>ae.indexOf(a)-ae.indexOf(p)),i})},[]);return{resetVisibleColumns:g.useCallback(()=>{n(Q)},[]),rowDensity:l,setRowDensity:t,showScrollHint:s,tableScrollRef:d,toggleColumn:c,visibleColumnCount:h,visibleColumns:o,visibleColumnSet:r}}function Mt(){var je,ve,Ne,we,ke;const{t:l}=M(),{pushToast:t}=ge(),[o,n]=R(_.logs.providerFilter,"all"),[d,s]=R(_.logs.endpointFilter,"all"),[r,h]=R(_.logs.modelFilter,""),[c,v]=R(_.logs.statusFilter,"all"),[u,j]=R(_.logs.fromDate,""),[i,a]=R(_.logs.toDate,""),[p,f]=g.useState(1),[S,b]=R(_.logs.pageSize,St,{serialize:m=>String(m),deserialize:m=>{const k=Number(m);return H.includes(k)?k:H[0]}}),[D,C]=g.useState(null),[T,N]=g.useState(!1),[y,B]=R(_.logs.selectedApiKeys,Ct),[re,oe]=R(_.logs.filtersExpanded,!1),{resetVisibleColumns:W,rowDensity:x,setRowDensity:G,showScrollHint:Fe,tableScrollRef:Te,toggleColumn:Re,visibleColumnCount:Le,visibleColumns:Me,visibleColumnSet:Ke}=Lt();g.useEffect(()=>{f(1)},[o,d,r,c,u,i,S,y]);const ie=g.useMemo(()=>{const m={limit:S,offset:(p-1)*S};o!=="all"&&(m.provider=o),d!=="all"&&(m.endpoint=d),r.trim().length>0&&(m.model=r.trim()),c!=="all"&&(m.status=c);const k=Ce(u),q=Ce(i,!0);return k!==void 0&&(m.from=k),q!==void 0&&(m.to=q),y.length>0&&(m.apiKeys=y.join(",")),m},[d,u,r,p,S,o,y,c,i]),P=$(U.logs.list(ie),he.listRequest(ie)),V=$(U.providers.all(),Se.providersRequest()),fe=$(U.apiKeys.all(),{url:"/api/keys",method:"GET"}),ne=$(U.customEndpoints.all(),{url:"/api/custom-endpoints",method:"GET"}),be=$(U.config.exportTimeout(),Se.configRequest());g.useEffect(()=>{!P.isError||!P.error||t({title:l("logs.toast.listError.title"),description:l("logs.toast.listError.desc",{message:P.error.message}),variant:"error"})},[P.error,P.isError,t,l]),g.useEffect(()=>{!V.isError||!V.error||t({title:l("logs.toast.providerError.title"),description:l("logs.toast.providerError.desc",{message:V.error.message}),variant:"error"})},[V.error,V.isError,t,l]);const Z=((je=P.data)==null?void 0:je.total)??0,J=Z>0?Math.ceil(Z/S):0,Pe=((ve=P.data)==null?void 0:ve.items)??[],Ae=g.useMemo(()=>{var k;const m=(k=be.data)==null?void 0:k.logExportTimeoutSeconds;return typeof m=="number"&&Number.isFinite(m)?Math.min(Math.max(Math.round(m),5),600)*1e3:6e4},[(Ne=be.data)==null?void 0:Ne.logExportTimeoutSeconds]);g.useEffect(()=>{J>0&&p>J&&f(J)},[p,J]);const de=V.data??[],ce=g.useMemo(()=>{const m=new Map;for(const k of de)k.id&&m.set(k.id,k.label??k.id);return m},[de]),ye=g.useMemo(()=>{var k;const m=new Map;m.set("anthropic",l("logs.filters.endpointAnthropic")),m.set("openai",l("logs.filters.endpointOpenAI"));for(const q of((k=ne.data)==null?void 0:k.endpoints)??[])m.set(q.id,q.label||q.id);return m},[(we=ne.data)==null?void 0:we.endpoints,l]),Oe=g.useMemo(()=>{const m=[];if(o!=="all"){const k=ce.get(o)??o;m.push({key:"provider",label:`${l("logs.filters.provider")}: ${k}`,onRemove:()=>n("all")})}if(d!=="all"){const k=ye.get(d)??d;m.push({key:"endpoint",label:`${l("logs.filters.endpoint")}: ${k}`,onRemove:()=>s("all")})}if(r.trim()&&m.push({key:"model",label:`${l("logs.filters.modelId")}: ${r.trim()}`,onRemove:()=>h("")}),c!=="all"){const k=l(c==="success"?"logs.filters.statusSuccess":"logs.filters.statusError");m.push({key:"status",label:`${l("logs.filters.status")}: ${k}`,onRemove:()=>v("all")})}return u&&m.push({key:"from",label:`${l("logs.filters.startDate")}: ${u}`,onRemove:()=>j("")}),i&&m.push({key:"to",label:`${l("logs.filters.endDate")}: ${i}`,onRemove:()=>a("")}),y.length>0&&m.push({key:"apiKeys",label:l("logs.filters.apiKeySelected",{count:y.length}),onRemove:()=>B([])}),m},[d,ye,u,r,o,ce,y.length,c,l,i]),me=fe.data??[],ze=g.useMemo(()=>{const m=new Map;for(const k of me)m.set(k.id,k);return m},[me]),qe=g.useMemo(()=>ae.map(m=>({id:m,label:l(`logs.table.columns.${m}`)})),[l]),X=g.useMemo(()=>new Date().toISOString().slice(0,10),[]),Ie=g.useMemo(()=>o==="all"&&d==="all"&&r.trim()===""&&c==="all"&&u===""&&i===""&&y.length===0?"all":c==="error"&&d==="all"&&o==="all"&&r.trim()===""&&u===""&&i===""&&y.length===0?"errors":_t(u,i,X)&&d==="all"&&o==="all"&&r.trim()===""&&c==="all"&&y.length===0?"today":d==="anthropic"&&o==="all"&&r.trim()===""&&c==="all"&&u===""&&i===""&&y.length===0?"anthropic":d==="openai"&&o==="all"&&r.trim()===""&&c==="all"&&u===""&&i===""&&y.length===0?"openai":null,[d,u,r,o,y.length,c,i,X]),pe=g.useCallback(()=>{n("all"),h(""),s("all"),v("all"),j(""),a(""),B([])},[]),Qe=g.useCallback(m=>{if(f(1),pe(),m!=="all"){if(m==="errors"){v("error");return}if(m==="today"){j(X),a(X);return}if(m==="anthropic"){s("anthropic");return}m==="openai"&&s("openai")}},[pe,X]),{exporting:Ve,handleExport:$e}=Tt({exportTimeoutMs:Ae,queryParams:ie,total:Z}),Ue=g.useCallback(m=>{C(m),N(!0)},[]),He=g.useCallback(()=>{N(!1),C(null)},[]);return{activeFilters:Oe,activeQuickView:Ie,apiKeyMap:ze,apiKeys:me,apiKeysQuery:fe,applyQuickView:Qe,columnOptions:qe,customEndpoints:(ke=ne.data)==null?void 0:ke.endpoints,endpointFilter:d,exporting:Ve,filtersExpanded:re,fromDate:u,handleCloseDetail:He,handleExport:$e,handleOpenDetail:Ue,handleResetFilters:pe,isDetailOpen:T,items:Pe,logsQuery:P,modelFilter:r,page:p,pageSize:S,providerFilter:o,providerLabelMap:ce,providerOptions:de,rowDensity:x,resetVisibleColumns:W,selectedApiKeys:y,selectedLogId:D,setEndpointFilter:s,setFiltersExpanded:oe,setFromDate:j,setModelFilter:h,setPage:f,setPageSize:b,setProviderFilter:n,setRowDensity:G,setSelectedApiKeys:B,setStatusFilter:v,setToDate:a,showScrollHint:Fe,statusFilter:c,tableScrollRef:Te,toDate:i,toggleColumn:Re,total:Z,totalPages:J,visibleColumnCount:Le,visibleColumns:Me,visibleColumnSet:Ke}}function ss(){var o;const{t:l}=M(),t=Mt();return e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx(et,{icon:e.jsx(Ye,{className:"h-5 w-5","aria-hidden":"true"}),title:l("logs.title"),description:l("logs.description"),eyebrow:"Traffic Explorer",breadcrumb:"Gateway / Logs",helper:l("logs.filtersDescription"),badge:t.total>0?l("logs.summary.total",{value:t.total.toLocaleString()}):void 0,actions:e.jsx(Et,{columnOptions:t.columnOptions,exporting:t.exporting,onExport:()=>void t.handleExport(),onRefresh:()=>void t.logsQuery.refetch(),onResetColumns:t.resetVisibleColumns,onSetDensity:t.setRowDensity,onToggleColumn:t.toggleColumn,refreshing:t.logsQuery.isFetching,rowDensity:t.rowDensity,total:t.total,visibleColumns:t.visibleColumns,visibleColumnSet:t.visibleColumnSet})}),e.jsx(yt,{total:t.total,activeFilters:t.activeFilters,filtersExpanded:t.filtersExpanded,setFiltersExpanded:t.setFiltersExpanded,handleResetFilters:t.handleResetFilters,activeQuickView:t.activeQuickView,applyQuickView:t.applyQuickView,providerFilter:t.providerFilter,setProviderFilter:t.setProviderFilter,endpointFilter:t.endpointFilter,setEndpointFilter:t.setEndpointFilter,selectedApiKeys:t.selectedApiKeys,setSelectedApiKeys:t.setSelectedApiKeys,modelFilter:t.modelFilter,setModelFilter:t.setModelFilter,statusFilter:t.statusFilter,setStatusFilter:t.setStatusFilter,fromDate:t.fromDate,setFromDate:t.setFromDate,toDate:t.toDate,setToDate:t.setToDate,providerOptions:t.providerOptions,apiKeys:t.apiKeys,apiKeysLoading:t.apiKeysQuery.isLoading,customEndpoints:t.customEndpoints}),e.jsx(Ft,{tableScrollRef:t.tableScrollRef,visibleColumnSet:t.visibleColumnSet,visibleColumnCount:t.visibleColumnCount,logsError:t.logsQuery.isError?((o=t.logsQuery.error)==null?void 0:o.message)??null:null,logsPending:t.logsQuery.isPending,items:t.items,activeFiltersCount:t.activeFilters.length,handleResetFilters:t.handleResetFilters,handleRetry:()=>void t.logsQuery.refetch(),providerLabelMap:t.providerLabelMap,apiKeyMap:t.apiKeyMap,handleOpenDetail:t.handleOpenDetail,rowDensity:t.rowDensity,showScrollHint:t.showScrollHint,pageSize:t.pageSize,setPageSize:t.setPageSize,page:t.page,totalPages:t.totalPages,setPage:t.setPage}),e.jsx(vt,{open:t.isDetailOpen,logId:t.selectedLogId,onClose:t.handleCloseDetail,providerLabelMap:t.providerLabelMap,apiKeyMap:t.apiKeyMap})]})}export{ss as default};
1
+ import{r as g,j as e,ak as Be,al as We,a8 as Ge,am as Je,aj as Xe,V as Ze,T as Ye}from"./vendor-5iCEqDpV.js";import{P as et}from"./PageHeader-CSF0BWul.js";import{c as w,B as E,b as tt,u as ge,s as _,t as st,a as R}from"./index-BzuBtvAC.js";import{B as K}from"./badge-BvMdmUqJ.js";import{C as _e,a as Ee}from"./card-CjhYPqKk.js";import{I as ue}from"./input-BnFZKjRM.js";import{L as I}from"./label-i5-Lf72z.js";import{S as ee,a as te,b as se,c as le,d as L}from"./select-KdDvaKo4.js";import{u as M}from"./i18n-C7VVFIdN.js";import{D as lt,A as at,a as rt,b as ot,c as it,d as nt}from"./DialogShell-CiIvBp8J.js";import{P as dt,a as xe}from"./PageState-BeXrzVEe.js";import{c as ct}from"./clipboard-CALi6bTW.js";import{u as $}from"./useApiQuery-fBWRSgFK.js";import{q as U}from"./queryKeys-BMvyDTQS.js";import{f as O,a as De,b as mt,c as z,d as pt,g as ut}from"./utils-DQfq7gRo.js";import{P as xt,a as gt,b as ht}from"./popover-EFz6sQ7C.js";import{T as ft}from"./Skeleton-8j6Dxod1.js";import{g as Se}from"./gateway-B0gBBN92.js";import"./query-DxhDvnDC.js";import"./router-D8u_RlVh.js";import"./radix-CmyU-WBH.js";function bt({apiKeys:l,selected:t,onChange:o,disabled:n,className:d}){const{t:s}=M(),[r,h]=g.useState(!1),c=g.useRef(null);g.useEffect(()=>{if(!r)return;const i=a=>{var p;(p=c.current)!=null&&p.contains(a.target)||h(!1)};return window.addEventListener("mousedown",i),()=>window.removeEventListener("mousedown",i)},[r]);const v=g.useMemo(()=>{if(t.length===0)return[];const i=new Map;for(const a of l)i.set(a.id,a);return t.map(a=>{const p=i.get(a);return p?p.isWildcard?s("apiKeys.wildcard"):p.name:null}).filter(a=>!!a)},[l,t,s]),u=t.length===0?s("logs.filters.apiKeyAll"):s("logs.filters.apiKeySelected",{count:t.length}),j=i=>{t.includes(i)?o(t.filter(a=>a!==i)):o([...t,i])};return e.jsxs("div",{className:w("relative space-y-2",d),ref:c,children:[e.jsx(I,{children:s("logs.filters.apiKey")}),e.jsxs("button",{type:"button",onClick:()=>h(i=>!i),disabled:n||l.length===0,title:s("logs.filters.apiKeyHint"),className:w("flex h-10 w-full items-center justify-between rounded-md border border-input bg-background px-3 text-sm ring-offset-background transition-all focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",t.length>0&&"border-primary",r&&"ring-2 ring-ring ring-offset-2"),children:[e.jsxs("span",{className:"truncate",children:[u,v.length>0&&e.jsx("span",{className:"ml-1 text-xs text-muted-foreground",children:v.join(", ")})]}),e.jsx("svg",{className:w("h-4 w-4 opacity-50 transition-transform",r&&"rotate-180"),viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M5.23 7.21a.75.75 0 011.06.02L10 10.94l3.71-3.71a.75.75 0 111.06 1.06l-4.24 4.25a.75.75 0 01-1.06 0L5.21 8.29a.75.75 0 01.02-1.08z",clipRule:"evenodd"})})]}),r&&e.jsxs("div",{className:"absolute left-0 top-full z-30 mt-2 w-64 rounded-md border bg-popover p-2 shadow-md",children:[e.jsxs("div",{className:"flex items-center justify-between rounded-md bg-secondary px-3 py-2 text-xs",children:[e.jsx("span",{children:u}),e.jsx("button",{type:"button",onClick:()=>o([]),disabled:t.length===0,className:"text-primary hover:underline disabled:opacity-40",children:s("common.actions.reset")})]}),e.jsxs("div",{className:"max-h-56 overflow-y-auto py-2",children:[l.map(i=>{const a=i.isWildcard?s("apiKeys.wildcard"):i.name,p=t.includes(i.id);return e.jsxs("label",{className:w("flex cursor-pointer items-center gap-2 rounded-xl px-3 py-2 text-sm transition hover:bg-primary/5",p&&"bg-primary/10 text-primary"),children:[e.jsx("input",{type:"checkbox",className:"h-4 w-4 rounded border-border",checked:p,onChange:()=>j(i.id)}),e.jsx("span",{className:"truncate",children:a})]},i.id)}),l.length===0&&e.jsx("p",{className:"px-2 py-2 text-xs text-muted-foreground",children:s("logs.filters.apiKeyAll")})]})]})]})}function yt(l){const{t}=M(),{total:o,activeFilters:n,filtersExpanded:d,setFiltersExpanded:s,handleResetFilters:r,activeQuickView:h,applyQuickView:c,providerFilter:v,setProviderFilter:u,endpointFilter:j,setEndpointFilter:i,selectedApiKeys:a,setSelectedApiKeys:p,modelFilter:f,setModelFilter:S,statusFilter:b,setStatusFilter:D,fromDate:C,setFromDate:T,toDate:N,setToDate:y,providerOptions:B,apiKeys:re,apiKeysLoading:oe,customEndpoints:W}=l;return e.jsx(_e,{"data-testid":"logs-filters-card",className:"overflow-hidden",children:e.jsxs(Ee,{className:"pt-4",children:[e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("p",{className:"text-sm font-semibold text-foreground",children:t("logs.filtersTitle")}),e.jsx(K,{variant:"outline",children:t("logs.summary.total",{value:o.toLocaleString()})}),n.length>0&&e.jsx(K,{variant:"secondary",children:t("common.filters.activeCount",{count:n.length})})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("logs.filtersDescription")})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[n.length>0&&e.jsx(E,{variant:"ghost",size:"sm",onClick:r,children:t("common.actions.reset")}),e.jsx(E,{variant:"ghost",size:"sm",onClick:()=>s(x=>!x),children:d?e.jsxs(e.Fragment,{children:[t("common.filters.collapse"),e.jsx(Be,{className:"ml-1 h-4 w-4"})]}):e.jsxs(e.Fragment,{children:[t("common.filters.expand"),e.jsx(We,{className:"ml-1 h-4 w-4"})]})})]})]}),e.jsxs("div",{className:"grid gap-3 lg:grid-cols-[minmax(0,1fr)_auto]",children:[e.jsx("div",{className:"flex min-h-[52px] items-center rounded-lg border border-border bg-secondary px-3 py-2",children:n.length>0?e.jsx("div",{className:"flex flex-wrap items-center gap-2",children:n.map(x=>e.jsxs(K,{variant:"secondary",role:"button",tabIndex:0,className:"cursor-pointer gap-1 border border-transparent bg-primary/10 text-primary hover:bg-destructive/10 hover:text-destructive",onClick:x.onRemove,onKeyDown:G=>{(G.key==="Enter"||G.key===" ")&&(G.preventDefault(),x.onRemove())},children:[x.label,e.jsx(Ge,{className:"h-3 w-3","aria-hidden":"true"})]},x.key))}):e.jsx("span",{className:"text-sm text-muted-foreground",children:t("common.filters.allRequests")})}),e.jsxs("div",{className:"grid grid-cols-2 gap-3 sm:grid-cols-4 lg:min-w-[360px]",children:[e.jsx(Y,{label:t("common.filters.activeCount",{count:n.length}),value:n.length.toString()}),e.jsx(Y,{label:t("logs.filters.apiKey"),value:a.length.toString()}),e.jsx(Y,{label:t("logs.filters.provider"),value:v==="all"?t("common.noData"):"1"}),e.jsx(Y,{label:t("logs.filters.endpoint"),value:j==="all"?t("common.noData"):"1"})]})]}),e.jsx("div",{className:"flex flex-wrap items-center gap-2 rounded-lg border border-border bg-secondary p-2",children:["all","errors","today","anthropic","openai"].map(x=>e.jsx(E,{variant:h===x?"default":"outline",size:"sm",className:w("rounded-full border-transparent",h===x&&x==="all"&&"bg-foreground text-background hover:bg-foreground/90",h===x&&x==="errors"&&"bg-rose-500 text-white hover:bg-rose-500/90",h===x&&x==="today"&&"bg-emerald-500 text-white hover:bg-emerald-500/90",h===x&&(x==="anthropic"||x==="openai")&&"bg-amber-500 text-white hover:bg-amber-500/90"),onClick:()=>c(x),children:t(`logs.quickViews.${x}`)},x))})]}),d&&e.jsxs("div",{className:"mt-4 grid gap-4 rounded-lg border border-border bg-secondary p-4 md:grid-cols-2 xl:grid-cols-4 animate-in fade-in slide-in-from-top-2 duration-200",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(I,{children:t("logs.filters.provider")}),e.jsxs(ee,{value:v,onValueChange:u,children:[e.jsx(te,{children:e.jsx(se,{})}),e.jsxs(le,{children:[e.jsx(L,{value:"all",children:t("logs.filters.providerAll")}),B.map(x=>e.jsx(L,{value:x.id,children:x.label??x.id},x.id))]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(I,{children:t("logs.filters.endpoint")}),e.jsxs(ee,{value:j,onValueChange:i,children:[e.jsx(te,{children:e.jsx(se,{})}),e.jsxs(le,{children:[e.jsx(L,{value:"all",children:t("logs.filters.endpointAll")}),e.jsx(L,{value:"anthropic",children:t("logs.filters.endpointAnthropic")}),e.jsx(L,{value:"openai",children:t("logs.filters.endpointOpenAI")}),W==null?void 0:W.map(x=>e.jsx(L,{value:x.id,children:x.label||x.id},x.id))]})]})]}),e.jsx(bt,{className:"md:col-span-2",apiKeys:re,selected:a,disabled:oe,onChange:p}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(I,{children:t("logs.filters.modelId")}),e.jsx(ue,{value:f,onChange:x=>S(x.target.value),placeholder:t("logs.filters.modelPlaceholder")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(I,{children:t("logs.filters.status")}),e.jsxs(ee,{value:b,onValueChange:x=>D(x),children:[e.jsx(te,{children:e.jsx(se,{})}),e.jsxs(le,{children:[e.jsx(L,{value:"all",children:t("logs.filters.statusAll")}),e.jsx(L,{value:"success",children:t("logs.filters.statusSuccess")}),e.jsx(L,{value:"error",children:t("logs.filters.statusError")})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(I,{children:t("logs.filters.startDate")}),e.jsx(ue,{type:"date",value:C,onChange:x=>T(x.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(I,{children:t("logs.filters.endDate")}),e.jsx(ue,{type:"date",value:N,onChange:x=>y(x.target.value)})]})]})]})})}function Y({label:l,value:t}){return e.jsxs("div",{className:"rounded-lg border border-border bg-card px-3 py-2",children:[e.jsx("p",{className:"text-[11px] text-muted-foreground",children:l}),e.jsx("p",{className:"mt-1 text-sm font-semibold text-foreground",children:t})]})}const he={listRequest(l){return{url:"/api/logs",method:"GET",params:l}},detailRequest(l){return{url:l===null?"":`/api/logs/${l}`,method:"GET"}},async exportArchive(l,t){const o=await tt.post("/api/logs/export",l,{responseType:"blob",timeout:t});return new Blob([o.data],{type:"application/zip"})}};function jt({apiKeyMap:l,logId:t,open:o,providerLabelMap:n}){var i;const{t:d}=M(),{pushToast:s}=ge(),r=$(U.logs.detail(t),he.detailRequest(t),{enabled:o&&t!==null,staleTime:3e4});g.useEffect(()=>{!r.isError||!r.error||s({title:d("logs.detail.loadError"),description:r.error.message,variant:"error"})},[r.error,r.isError,s,d]);const h=g.useCallback(async(a,p,f)=>{if(!p){s({title:d("logs.detail.copy.empty",{label:a}),variant:"info"});return}try{await ct(p),s({title:d(f),variant:"success"})}catch(S){s({title:d("logs.detail.copy.failure"),description:S instanceof Error?S.message:d("logs.detail.copy.failureFallback"),variant:"error"})}},[s,d]),c=r.data,v=c?n.get(c.provider)??c.provider:"",u=c&&c.api_key_id!=null?l.get(c.api_key_id):void 0,j=c?c.status_code??(c.error?500:200):null;return{apiKeyMeta:u,errorMessage:r.isError?((i=r.error)==null?void 0:i.message)??null:null,handleCopy:h,isError:r.isError,isPending:r.isPending,providerLabel:v,refetch:r.refetch,record:c,statusCode:j}}function vt({open:l,logId:t,onClose:o,providerLabelMap:n,apiKeyMap:d}){var S,b,D,C,T,N;const{t:s}=M(),{apiKeyMeta:r,errorMessage:h,handleCopy:c,isError:v,isPending:u,providerLabel:j,refetch:i,record:a,statusCode:p}=jt({apiKeyMap:d,logId:t,open:l,providerLabelMap:n}),f=a?[{key:"client-request",title:s("logs.detail.payload.clientRequest"),value:((S=a.payload)==null?void 0:S.client_request)??null,emptyLabel:s("logs.detail.payload.emptyRequest"),copyToast:"logs.detail.copy.requestSuccess"},...(b=a.payload)!=null&&b.upstream_request?[{key:"upstream-request",title:s("logs.detail.payload.upstreamRequest"),value:a.payload.upstream_request,emptyLabel:s("logs.detail.payload.emptyRequest"),copyToast:"logs.detail.copy.requestSuccess"}]:[],...(D=a.payload)!=null&&D.upstream_response?[{key:"upstream-response",title:s("logs.detail.payload.upstreamResponse"),value:a.payload.upstream_response,emptyLabel:s("logs.detail.payload.emptyResponse"),copyToast:"logs.detail.copy.responseSuccess"}]:[],{key:"client-response",title:s("logs.detail.payload.clientResponse"),value:((C=a.payload)==null?void 0:C.client_response)??null,emptyLabel:s("logs.detail.payload.emptyResponse"),copyToast:"logs.detail.copy.responseSuccess"}]:[];return e.jsx(lt,{open:l,onOpenChange:y=>{y||o()},children:e.jsxs(at,{className:"w-[min(96vw,1200px)] max-w-[1200px]",children:[e.jsxs(rt,{className:"pr-14",children:[e.jsx(ot,{children:s("logs.detail.title")}),e.jsx(it,{children:a?s("logs.detail.id",{id:a.id}):s("logs.detail.loadError")})]}),e.jsx(nt,{className:"max-h-[78vh]",children:u?e.jsx(dt,{compact:!0,className:"min-h-[240px]",label:s("common.loading")}):v?e.jsx(xe,{compact:!0,className:"min-h-[240px]",tone:"danger",title:s("logs.detail.loadError"),description:h??s("common.unknownError"),action:e.jsx(E,{variant:"outline",onClick:()=>void i(),children:s("common.actions.refresh")})}):a?e.jsxs("div",{className:"space-y-6 text-sm",children:[e.jsxs("section",{className:"space-y-4 rounded-lg border border-border bg-card p-5",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:s("logs.detail.infoSection")}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 rounded-lg border border-border bg-secondary p-3 text-xs",children:[e.jsx("span",{className:"font-medium",children:s("logs.detail.summary.route",{from:a.client_model??s("logs.detail.info.noRequestedModel"),to:a.model})}),e.jsx("span",{className:"text-muted-foreground",children:s("logs.detail.summary.latency",{value:O(a.latency_ms,s("common.units.ms"))})}),a.ttft_ms!==null?e.jsxs("span",{className:"text-muted-foreground",children:["TTFT: ",O(a.ttft_ms,s("common.units.ms"))]}):null]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(K,{variant:a.error?"destructive":"default",children:p==null?void 0:p.toString()}),e.jsx(K,{variant:"outline",children:a.stream?s("logs.stream.streaming"):s("logs.stream.single")})]})]}),e.jsxs("div",{className:"grid gap-3 md:grid-cols-4",children:[e.jsx(A,{label:s("logs.detail.info.latency"),value:O(a.latency_ms,s("common.units.ms"))}),e.jsx(A,{label:s("logs.detail.info.ttft"),value:O(a.ttft_ms,s("common.units.ms"))}),e.jsx(A,{label:s("logs.detail.info.tpot"),value:O(a.tpot_ms,s("common.units.msPerToken"))}),e.jsx(A,{label:s("logs.detail.info.status"),value:(p==null?void 0:p.toString())??"-"})]}),e.jsxs("dl",{className:"grid gap-x-4 gap-y-3 md:grid-cols-2 xl:grid-cols-4",children:[e.jsx(F,{label:s("logs.detail.info.time"),value:De(a.timestamp)}),e.jsx(F,{label:s("logs.detail.info.sessionId"),value:a.session_id??"-"}),e.jsx(F,{label:s("logs.detail.info.endpoint"),value:a.endpoint||"-"}),e.jsx(F,{label:s("logs.detail.info.provider"),value:j}),e.jsx(F,{label:s("logs.detail.info.requestedModel"),value:a.client_model??s("logs.detail.info.noRequestedModel")}),e.jsx(F,{label:s("logs.detail.info.model"),value:a.model}),e.jsx(F,{label:s("logs.detail.info.stream"),value:mt(a.stream)}),e.jsx(F,{label:s("logs.detail.info.status"),value:p})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2 xl:grid-cols-4",children:[e.jsx(A,{label:s("logs.detail.info.inputTokens"),value:z(a.input_tokens)}),e.jsx(A,{label:s("logs.detail.info.cacheReadTokens"),value:z(a.cache_read_tokens)}),e.jsx(A,{label:s("logs.detail.info.cacheCreationTokens"),value:z(a.cache_creation_tokens)}),e.jsx(A,{label:s("logs.detail.info.outputTokens"),value:z(a.output_tokens)})]}),a.error?e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:s("logs.detail.info.error")}),e.jsx("p",{className:"rounded-[1rem] border border-destructive/50 bg-destructive/10 p-3 text-xs text-destructive",children:a.error})]}):null]}),e.jsxs("div",{className:"grid gap-6 xl:grid-cols-[minmax(0,0.9fr)_minmax(0,1.1fr)]",children:[e.jsxs("section",{className:"space-y-3 rounded-lg border border-border bg-card p-5",children:[e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:s("logs.detail.apiKey.title")}),e.jsxs("dl",{className:"grid gap-x-4 gap-y-3 sm:grid-cols-2",children:[e.jsx(F,{label:s("logs.detail.apiKey.name"),value:a.api_key_id==null&&!a.api_key_name?s("logs.detail.apiKey.missing"):r!=null&&r.isWildcard?s("apiKeys.wildcard"):(r==null?void 0:r.name)??a.api_key_name??s("logs.detail.apiKey.missing")}),e.jsx(F,{label:s("logs.detail.apiKey.identifier"),value:a.api_key_id??s("common.noData")}),e.jsx(F,{label:s("logs.detail.apiKey.masked"),value:r!=null&&r.isWildcard?s("apiKeys.wildcard"):(r==null?void 0:r.maskedKey)??a.api_key_name??s("logs.detail.apiKey.maskedUnavailable")}),e.jsx(F,{label:s("logs.detail.apiKey.lastUsed"),value:r!=null&&r.lastUsedAt?new Date(r.lastUsedAt).toLocaleString():s("common.noData")})]}),e.jsxs("div",{className:"rounded-lg border border-border bg-secondary p-3 text-xs",children:[e.jsx("p",{className:"font-medium",children:s("logs.detail.apiKey.rawMasked")}),e.jsx("p",{className:"mt-1 break-all font-mono",children:a.api_key_value_available?a.api_key_value_masked??s("logs.detail.apiKey.rawUnavailable"):s("logs.detail.apiKey.rawUnavailable")}),e.jsx("p",{className:"mt-2 text-[11px] text-muted-foreground",children:s("logs.detail.apiKey.rawMaskedHint")})]})]}),e.jsxs("section",{className:"space-y-4 rounded-lg border border-border bg-card p-5",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:s("logs.detail.payload.title")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:(T=a.payload)!=null&&T.upstream_request||(N=a.payload)!=null&&N.upstream_response?s("logs.detail.payload.helperWithUpstream"):s("logs.detail.payload.helperClientOnly")})]}),e.jsx("div",{className:"grid gap-4 xl:grid-cols-2",children:f.map(y=>e.jsx(Nt,{title:y.title,value:y.value,emptyLabel:y.emptyLabel,onCopy:()=>c(y.title,y.value,y.copyToast),t:s},y.key))})]})]})]}):e.jsx(xe,{compact:!0,className:"min-h-[240px]",title:s("logs.detail.loadError"),description:s("common.noData")})})]})})}function A({label:l,value:t}){return e.jsxs("div",{className:"min-w-0 rounded-lg border border-border bg-secondary px-3 py-3",children:[e.jsx("p",{className:"text-[11px] font-medium uppercase tracking-[0.16em] text-muted-foreground",children:l}),e.jsx("p",{className:"mt-2 break-all text-sm font-semibold leading-6",children:t})]})}function F({label:l,value:t}){return e.jsxs("div",{className:"min-w-0 space-y-1",children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:l}),e.jsx("dd",{className:"min-w-0 break-all whitespace-pre-wrap text-sm font-medium leading-6 text-foreground",children:t??"-"})]})}function Nt({emptyLabel:l,onCopy:t,title:o,value:n,t:d}){return e.jsxs("div",{className:"space-y-3 rounded-lg border border-border bg-secondary/40 p-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsx("h4",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:o}),e.jsx(E,{variant:"outline",size:"sm",onClick:t,children:d("common.actions.copy")})]}),e.jsx("pre",{className:"max-h-72 overflow-auto whitespace-pre-wrap rounded-lg border border-border bg-secondary p-3 text-xs",children:pt(n,l)})]})}const H=[20,50,100],Q=["endpoint","provider","requestedModel","routedModel","apiKey","inputTokens","cacheReadTokens","cacheCreationTokens","outputTokens","latency","ttft","tpot","status","error"],ae=["endpoint","provider","requestedModel","routedModel","apiKey","inputTokens","cacheReadTokens","cacheCreationTokens","outputTokens","latency","ttft","tpot","status","error"];function wt(){if(typeof window>"u")return Q;try{const l=window.localStorage.getItem(_.logs.visibleColumns);if(!l)return Q;const t=JSON.parse(l);if(!Array.isArray(t))return Q;const o=t.filter(n=>ae.includes(n));return o.length>0?o:Q}catch{return Q}}function kt(){return typeof window>"u"?"comfortable":window.localStorage.getItem(_.logs.density)==="compact"?"compact":"comfortable"}function St(){if(typeof window>"u")return H[0];const l=window.localStorage.getItem(_.logs.pageSize),t=Number(l);return H.includes(t)?t:H[0]}function Ct(){if(typeof window>"u")return[];try{const l=window.localStorage.getItem(_.logs.selectedApiKeys);if(!l)return[];const t=JSON.parse(l);return Array.isArray(t)?t.map(o=>Number(o)).filter(o=>Number.isInteger(o)&&o>0):[]}catch{return[]}}function Ce(l,t=!1){if(!l)return;const o=t?`${l}T23:59:59.999`:`${l}T00:00:00.000`,n=Date.parse(o);return Number.isFinite(n)?n:void 0}function _t(l,t,o){return l===o&&t===o}function Et({columnOptions:l,exporting:t,onExport:o,onRefresh:n,onResetColumns:d,onSetDensity:s,onToggleColumn:r,refreshing:h,rowDensity:c,total:v,visibleColumns:u,visibleColumnSet:j}){const{t:i}=M(),a=JSON.stringify(u)===JSON.stringify(Q);return e.jsxs("div",{className:"flex w-full flex-col gap-3 xl:w-auto xl:flex-row xl:items-center",children:[e.jsxs("div",{className:"flex w-full flex-col gap-3 sm:flex-row sm:flex-wrap sm:items-center xl:w-auto xl:flex-nowrap",children:[e.jsxs("div",{className:"flex w-full items-center gap-1 overflow-x-auto rounded-full border border-border bg-secondary p-1 sm:w-auto",children:[e.jsx("button",{type:"button",onClick:()=>s("comfortable"),className:w("inline-flex h-8 flex-1 items-center justify-center whitespace-nowrap rounded-full px-3.5 text-xs font-medium transition-all sm:flex-none",c==="comfortable"?"bg-primary text-primary-foreground shadow-[0_8px_18px_-14px_rgba(59,130,246,0.7)]":"text-muted-foreground hover:bg-primary/5 hover:text-foreground"),children:i("logs.table.density.comfortable")}),e.jsx("button",{type:"button",onClick:()=>s("compact"),className:w("inline-flex h-8 flex-1 items-center justify-center whitespace-nowrap rounded-full px-3.5 text-xs font-medium transition-all sm:flex-none",c==="compact"?"bg-primary text-primary-foreground shadow-[0_8px_18px_-14px_rgba(59,130,246,0.7)]":"text-muted-foreground hover:bg-primary/5 hover:text-foreground"),children:i("logs.table.density.compact")})]}),e.jsxs(xt,{children:[e.jsx(gt,{asChild:!0,children:e.jsx(E,{variant:"outline",size:"sm",className:"w-full sm:w-auto",children:i("logs.actions.columns")})}),e.jsxs(ht,{align:"end",className:"w-64 p-3",children:[e.jsxs("div",{className:"mb-3 flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-semibold",children:i("logs.actions.columns")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:i("logs.actions.visibleCount",{count:u.length})})]}),e.jsx(E,{variant:"ghost",size:"sm",onClick:d,disabled:a,children:i("common.actions.reset")})]}),e.jsx("div",{className:"grid gap-1.5",children:l.map(p=>{const f=j.has(p.id);return e.jsxs("label",{className:w("flex cursor-pointer items-center gap-3 rounded-xl px-3 py-2 text-sm transition hover:bg-primary/5",f&&"bg-primary/10 text-primary"),children:[e.jsx("input",{type:"checkbox",checked:f,onChange:()=>r(p.id),className:"h-4 w-4 rounded border-border"}),e.jsx("span",{children:p.label})]},p.id)})})]})]}),e.jsxs(E,{onClick:o,disabled:t,className:"w-full sm:w-auto",children:[e.jsx(Je,{className:"mr-2 h-4 w-4"}),i(t?"logs.actions.exporting":"logs.actions.export")]})]}),e.jsxs("div",{className:"flex w-full items-center justify-between gap-3 xl:w-auto xl:justify-start",children:[e.jsx("span",{className:"text-xs text-muted-foreground sm:text-sm",children:i("logs.summary.total",{value:v.toLocaleString()})}),e.jsxs(E,{variant:"outline",size:"sm",onClick:n,disabled:h,className:"shrink-0",children:[e.jsx(Xe,{className:w("mr-2 h-4 w-4",h&&"animate-spin")}),i(h?"common.actions.refreshing":"logs.actions.manualRefresh")]})]})]})}function Dt({record:l,providerLabelMap:t,apiKeyMap:o,onSelect:n,isEven:d,density:s,visibleColumnSet:r}){const{t:h}=M(),c=t.get(l.provider)??l.provider,v=l.endpoint||"-",u=!!l.error,j=l.status_code,i=l.client_model??h("logs.table.requestedModelFallback"),a=l.api_key_id!=null?o.get(l.api_key_id):void 0,p=l.api_key_id==null?h("logs.table.apiKeyUnknown"):a!=null&&a.isWildcard?h("apiKeys.wildcard"):a!=null&&a.name?a.name:l.api_key_name?l.api_key_name:h("logs.table.apiKeyUnknown"),f=s==="compact"?"px-3 py-1.5":"px-3 py-2",S=d?"bg-muted/30":"bg-background",b=ut(l.session_id),D=b==null?void 0:b.rowStyle,C=b==null?void 0:b.stickyStyle,T=b?{...b.stickyStyle,...b.accentStyle}:void 0;return e.jsxs("tr",{"data-session-id":b==null?void 0:b.sessionId,"data-session-color":b==null?void 0:b.colorKey,className:w("transition-colors",b?"":d?"bg-muted/30":"",b?"":"hover:bg-muted/50"),style:D,onMouseEnter:N=>{b&&Object.assign(N.currentTarget.style,b.hoverStyle)},onMouseLeave:N=>{b&&Object.assign(N.currentTarget.style,b.rowStyle)},children:[e.jsx("td",{className:w("sticky left-0 z-10 text-xs",f,b?"":S),style:T,children:De(l.timestamp)}),r.has("endpoint")&&e.jsx("td",{className:w(f,"text-xs"),children:v}),r.has("provider")&&e.jsx("td",{className:w(f,"text-xs"),children:e.jsx("div",{className:"max-w-[100px] truncate",title:c,children:c})}),r.has("requestedModel")&&e.jsx("td",{className:w(f,"text-xs text-muted-foreground"),children:e.jsx("div",{className:"max-w-[120px] truncate",title:i,children:i})}),r.has("routedModel")&&e.jsx("td",{className:w(f,"text-xs"),children:e.jsx("div",{className:"max-w-[120px] truncate",title:l.model,children:l.model})}),r.has("apiKey")&&e.jsx("td",{className:w(f,"text-xs text-muted-foreground"),children:e.jsx("div",{className:"max-w-[90px] truncate",title:p,children:p})}),r.has("inputTokens")&&e.jsx("td",{className:w(f,"text-right text-xs tabular-nums"),children:z(l.input_tokens)}),r.has("cacheReadTokens")&&e.jsx("td",{className:w(f,"text-right text-xs tabular-nums"),children:z(l.cache_read_tokens)}),r.has("cacheCreationTokens")&&e.jsx("td",{className:w(f,"text-right text-xs tabular-nums"),children:z(l.cache_creation_tokens)}),r.has("outputTokens")&&e.jsx("td",{className:w(f,"text-right text-xs tabular-nums"),children:z(l.output_tokens)}),r.has("latency")&&e.jsx("td",{className:w(f,"text-right text-xs tabular-nums"),children:O(l.latency_ms,"ms")}),r.has("ttft")&&e.jsx("td",{className:w(f,"text-right text-xs tabular-nums"),children:O(l.ttft_ms,"ms")}),r.has("tpot")&&e.jsx("td",{className:w(f,"text-right text-xs tabular-nums"),children:O(l.tpot_ms,"ms/tk")}),r.has("status")&&e.jsx("td",{className:w(f,"text-center"),children:e.jsx(K,{variant:u?"destructive":"default",className:"text-xs",children:j??(u?500:200)})}),r.has("error")&&e.jsx("td",{className:w(f,"text-xs text-muted-foreground"),children:e.jsx("div",{className:"max-w-[100px] truncate",title:l.error??"",children:l.error?l.error:"-"})}),e.jsx("td",{className:w("sticky right-0 z-10 text-center",f,b?"":S),style:C,children:e.jsx(E,{variant:"outline",size:"sm",onClick:()=>n(l.id),children:h("logs.actions.detail")})})]})}function Ft(l){const{t}=M(),{tableScrollRef:o,visibleColumnSet:n,visibleColumnCount:d,logsError:s,logsPending:r,items:h,activeFiltersCount:c,handleResetFilters:v,handleRetry:u,providerLabelMap:j,apiKeyMap:i,handleOpenDetail:a,rowDensity:p,showScrollHint:f,pageSize:S,setPageSize:b,page:D,totalPages:C,setPage:T}=l;return e.jsx(_e,{className:"overflow-hidden",children:e.jsxs(Ee,{className:"p-0",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 border-b border-border bg-secondary px-4 py-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-sm font-semibold",children:t("logs.title")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("logs.actions.visibleCount",{count:d-2})})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(K,{variant:"secondary",children:"Wide Table"}),e.jsx(K,{variant:"outline",children:t(p==="compact"?"logs.table.density.compact":"logs.table.density.comfortable")}),f?e.jsx(K,{variant:"outline",className:"border-amber-200 bg-amber-50 text-amber-700 dark:border-amber-800 dark:bg-amber-950/30 dark:text-amber-300",children:"Scroll for more"}):null]})]}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{ref:o,className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full min-w-[1480px] text-sm",children:[e.jsx("thead",{className:"border-b bg-muted/50",children:e.jsxs("tr",{children:[e.jsx("th",{className:"sticky left-0 z-20 bg-muted/95 px-3 py-2 text-left text-xs font-medium backdrop-blur",children:t("logs.table.columns.time")}),n.has("endpoint")&&e.jsx("th",{className:"px-3 py-2 text-left text-xs font-medium",children:t("logs.table.columns.endpoint")}),n.has("provider")&&e.jsx("th",{className:"px-3 py-2 text-left text-xs font-medium",children:t("logs.table.columns.provider")}),n.has("requestedModel")&&e.jsx("th",{className:"px-3 py-2 text-left text-xs font-medium",children:t("logs.table.columns.requestedModel")}),n.has("routedModel")&&e.jsx("th",{className:"px-3 py-2 text-left text-xs font-medium",children:t("logs.table.columns.routedModel")}),n.has("apiKey")&&e.jsx("th",{className:"px-3 py-2 text-left text-xs font-medium",children:t("logs.table.columns.apiKey")}),n.has("inputTokens")&&e.jsx("th",{className:"px-3 py-2 text-right text-xs font-medium",children:t("logs.table.columns.inputTokens")}),n.has("cacheReadTokens")&&e.jsx("th",{className:"px-3 py-2 text-right text-xs font-medium",children:t("logs.table.columns.cacheReadTokens")}),n.has("cacheCreationTokens")&&e.jsx("th",{className:"px-3 py-2 text-right text-xs font-medium",children:t("logs.table.columns.cacheCreationTokens")}),n.has("outputTokens")&&e.jsx("th",{className:"px-3 py-2 text-right text-xs font-medium",children:t("logs.table.columns.outputTokens")}),n.has("latency")&&e.jsx("th",{className:"px-3 py-2 text-right text-xs font-medium",children:t("logs.table.columns.latency")}),n.has("ttft")&&e.jsx("th",{className:"px-3 py-2 text-right text-xs font-medium",children:t("logs.table.columns.ttft")}),n.has("tpot")&&e.jsx("th",{className:"px-3 py-2 text-right text-xs font-medium",children:t("logs.table.columns.tpot")}),n.has("status")&&e.jsx("th",{className:"px-3 py-2 text-center text-xs font-medium",children:t("logs.table.columns.status")}),n.has("error")&&e.jsx("th",{className:"px-3 py-2 text-left text-xs font-medium",children:t("logs.table.columns.error")}),e.jsx("th",{className:"sticky right-0 z-20 bg-muted/95 px-3 py-2 text-center text-xs font-medium backdrop-blur",children:t("logs.table.columns.actions")})]})}),e.jsx("tbody",{className:"divide-y",children:r?Array.from({length:8}).map((N,y)=>e.jsx(ft,{columns:d},y)):s&&h.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:d,className:"px-3 py-6",children:e.jsx(xe,{compact:!0,tone:"danger",icon:e.jsx(Ze,{className:"h-5 w-5","aria-hidden":"true"}),title:t("logs.toast.listError.title"),description:s,action:e.jsxs("div",{className:"flex flex-wrap items-center justify-center gap-2",children:[e.jsx(E,{variant:"outline",size:"sm",onClick:u,children:t("common.actions.refresh")}),c>0?e.jsx(E,{variant:"ghost",size:"sm",onClick:v,children:t("common.actions.reset")}):null]})})})}):h.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:d,className:"px-3 py-8 text-center text-sm text-muted-foreground",children:e.jsxs("div",{className:"flex flex-col items-center gap-3 py-4",children:[e.jsx("span",{children:t("logs.table.empty")}),c>0&&e.jsx(E,{variant:"outline",size:"sm",onClick:v,children:t("common.actions.reset")})]})})}):h.map((N,y)=>e.jsx(Dt,{record:N,providerLabelMap:j,apiKeyMap:i,onSelect:a,isEven:y%2===0,density:p,visibleColumnSet:n},N.id))})]})}),f&&e.jsx("div",{className:"table-scroll-hint"})]}),e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-4 border-t p-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:t("logs.table.pagination.perPage")}),e.jsxs(ee,{value:S.toString(),onValueChange:N=>b(Number(N)),children:[e.jsx(te,{className:"w-[80px]",children:e.jsx(se,{})}),e.jsx(le,{children:H.map(N=>e.jsx(L,{value:N.toString(),children:N},N))})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(E,{variant:"outline",size:"sm",onClick:()=>T(N=>Math.max(N-1,1)),disabled:D<=1,children:t("logs.table.pagination.previous")}),e.jsx("span",{className:"text-sm text-muted-foreground",children:t("logs.table.pagination.pageLabel",{page:C===0?0:D,total:C})}),e.jsx(E,{variant:"outline",size:"sm",onClick:()=>T(N=>C===0?N:Math.min(N+1,C)),disabled:C===0||D>=C,children:t("logs.table.pagination.next")})]})]})]})})}function Tt({exportTimeoutMs:l,queryParams:t,total:o}){const{t:n}=M(),{pushToast:d}=ge(),[s,r]=g.useState(!1),h=g.useCallback(async()=>{if(!s){r(!0);try{const c=o>0?Math.min(o,5e3):1e3,v={...t,limit:c,offset:0},u=await he.exportArchive(v,l),j=new Date().toISOString().replace(/[:.]/g,"-"),i=URL.createObjectURL(u),a=document.createElement("a");a.href=i,a.download=`cc-gw-logs-${j}.zip`,document.body.appendChild(a),a.click(),a.remove(),URL.revokeObjectURL(i),d({title:n("logs.toast.exportSuccess.title"),description:n("logs.toast.exportSuccess.desc"),variant:"success"})}catch(c){const v=st(c);d({title:n("logs.toast.exportError.title"),description:n("logs.toast.exportError.desc",{message:v.message}),variant:"error"})}finally{r(!1)}}},[l,s,d,t,n,o]);return{exporting:s,handleExport:h}}function Rt(){const l=g.useRef(null),[t,o]=g.useState(!1),n=g.useCallback(()=>{const d=l.current;if(!d)return;const s=d.scrollWidth-d.scrollLeft-d.clientWidth>1;o(s)},[]);return g.useEffect(()=>{const d=l.current;if(!d)return;n(),d.addEventListener("scroll",n,{passive:!0});const s=new ResizeObserver(n);return s.observe(d),()=>{d.removeEventListener("scroll",n),s.disconnect()}},[n]),{scrollRef:l,showScrollHint:t,updateScrollHint:n}}function Lt(){const[l,t]=R(_.logs.density,kt,{serialize:u=>u,deserialize:u=>u==="compact"?"compact":"comfortable"}),[o,n]=R(_.logs.visibleColumns,wt),{scrollRef:d,showScrollHint:s}=Rt(),r=g.useMemo(()=>new Set(o),[o]),h=o.length+2,c=g.useCallback(u=>{n(j=>{if(j.includes(u))return j.length===1?j:j.filter(a=>a!==u);const i=[...j,u];return i.sort((a,p)=>ae.indexOf(a)-ae.indexOf(p)),i})},[]);return{resetVisibleColumns:g.useCallback(()=>{n(Q)},[]),rowDensity:l,setRowDensity:t,showScrollHint:s,tableScrollRef:d,toggleColumn:c,visibleColumnCount:h,visibleColumns:o,visibleColumnSet:r}}function Mt(){var je,ve,Ne,we,ke;const{t:l}=M(),{pushToast:t}=ge(),[o,n]=R(_.logs.providerFilter,"all"),[d,s]=R(_.logs.endpointFilter,"all"),[r,h]=R(_.logs.modelFilter,""),[c,v]=R(_.logs.statusFilter,"all"),[u,j]=R(_.logs.fromDate,""),[i,a]=R(_.logs.toDate,""),[p,f]=g.useState(1),[S,b]=R(_.logs.pageSize,St,{serialize:m=>String(m),deserialize:m=>{const k=Number(m);return H.includes(k)?k:H[0]}}),[D,C]=g.useState(null),[T,N]=g.useState(!1),[y,B]=R(_.logs.selectedApiKeys,Ct),[re,oe]=R(_.logs.filtersExpanded,!1),{resetVisibleColumns:W,rowDensity:x,setRowDensity:G,showScrollHint:Fe,tableScrollRef:Te,toggleColumn:Re,visibleColumnCount:Le,visibleColumns:Me,visibleColumnSet:Ke}=Lt();g.useEffect(()=>{f(1)},[o,d,r,c,u,i,S,y]);const ie=g.useMemo(()=>{const m={limit:S,offset:(p-1)*S};o!=="all"&&(m.provider=o),d!=="all"&&(m.endpoint=d),r.trim().length>0&&(m.model=r.trim()),c!=="all"&&(m.status=c);const k=Ce(u),q=Ce(i,!0);return k!==void 0&&(m.from=k),q!==void 0&&(m.to=q),y.length>0&&(m.apiKeys=y.join(",")),m},[d,u,r,p,S,o,y,c,i]),P=$(U.logs.list(ie),he.listRequest(ie)),V=$(U.providers.all(),Se.providersRequest()),fe=$(U.apiKeys.all(),{url:"/api/keys",method:"GET"}),ne=$(U.customEndpoints.all(),{url:"/api/custom-endpoints",method:"GET"}),be=$(U.config.exportTimeout(),Se.configRequest());g.useEffect(()=>{!P.isError||!P.error||t({title:l("logs.toast.listError.title"),description:l("logs.toast.listError.desc",{message:P.error.message}),variant:"error"})},[P.error,P.isError,t,l]),g.useEffect(()=>{!V.isError||!V.error||t({title:l("logs.toast.providerError.title"),description:l("logs.toast.providerError.desc",{message:V.error.message}),variant:"error"})},[V.error,V.isError,t,l]);const Z=((je=P.data)==null?void 0:je.total)??0,J=Z>0?Math.ceil(Z/S):0,Pe=((ve=P.data)==null?void 0:ve.items)??[],Ae=g.useMemo(()=>{var k;const m=(k=be.data)==null?void 0:k.logExportTimeoutSeconds;return typeof m=="number"&&Number.isFinite(m)?Math.min(Math.max(Math.round(m),5),600)*1e3:6e4},[(Ne=be.data)==null?void 0:Ne.logExportTimeoutSeconds]);g.useEffect(()=>{J>0&&p>J&&f(J)},[p,J]);const de=V.data??[],ce=g.useMemo(()=>{const m=new Map;for(const k of de)k.id&&m.set(k.id,k.label??k.id);return m},[de]),ye=g.useMemo(()=>{var k;const m=new Map;m.set("anthropic",l("logs.filters.endpointAnthropic")),m.set("openai",l("logs.filters.endpointOpenAI"));for(const q of((k=ne.data)==null?void 0:k.endpoints)??[])m.set(q.id,q.label||q.id);return m},[(we=ne.data)==null?void 0:we.endpoints,l]),Oe=g.useMemo(()=>{const m=[];if(o!=="all"){const k=ce.get(o)??o;m.push({key:"provider",label:`${l("logs.filters.provider")}: ${k}`,onRemove:()=>n("all")})}if(d!=="all"){const k=ye.get(d)??d;m.push({key:"endpoint",label:`${l("logs.filters.endpoint")}: ${k}`,onRemove:()=>s("all")})}if(r.trim()&&m.push({key:"model",label:`${l("logs.filters.modelId")}: ${r.trim()}`,onRemove:()=>h("")}),c!=="all"){const k=l(c==="success"?"logs.filters.statusSuccess":"logs.filters.statusError");m.push({key:"status",label:`${l("logs.filters.status")}: ${k}`,onRemove:()=>v("all")})}return u&&m.push({key:"from",label:`${l("logs.filters.startDate")}: ${u}`,onRemove:()=>j("")}),i&&m.push({key:"to",label:`${l("logs.filters.endDate")}: ${i}`,onRemove:()=>a("")}),y.length>0&&m.push({key:"apiKeys",label:l("logs.filters.apiKeySelected",{count:y.length}),onRemove:()=>B([])}),m},[d,ye,u,r,o,ce,y.length,c,l,i]),me=fe.data??[],ze=g.useMemo(()=>{const m=new Map;for(const k of me)m.set(k.id,k);return m},[me]),qe=g.useMemo(()=>ae.map(m=>({id:m,label:l(`logs.table.columns.${m}`)})),[l]),X=g.useMemo(()=>new Date().toISOString().slice(0,10),[]),Ie=g.useMemo(()=>o==="all"&&d==="all"&&r.trim()===""&&c==="all"&&u===""&&i===""&&y.length===0?"all":c==="error"&&d==="all"&&o==="all"&&r.trim()===""&&u===""&&i===""&&y.length===0?"errors":_t(u,i,X)&&d==="all"&&o==="all"&&r.trim()===""&&c==="all"&&y.length===0?"today":d==="anthropic"&&o==="all"&&r.trim()===""&&c==="all"&&u===""&&i===""&&y.length===0?"anthropic":d==="openai"&&o==="all"&&r.trim()===""&&c==="all"&&u===""&&i===""&&y.length===0?"openai":null,[d,u,r,o,y.length,c,i,X]),pe=g.useCallback(()=>{n("all"),h(""),s("all"),v("all"),j(""),a(""),B([])},[]),Qe=g.useCallback(m=>{if(f(1),pe(),m!=="all"){if(m==="errors"){v("error");return}if(m==="today"){j(X),a(X);return}if(m==="anthropic"){s("anthropic");return}m==="openai"&&s("openai")}},[pe,X]),{exporting:Ve,handleExport:$e}=Tt({exportTimeoutMs:Ae,queryParams:ie,total:Z}),Ue=g.useCallback(m=>{C(m),N(!0)},[]),He=g.useCallback(()=>{N(!1),C(null)},[]);return{activeFilters:Oe,activeQuickView:Ie,apiKeyMap:ze,apiKeys:me,apiKeysQuery:fe,applyQuickView:Qe,columnOptions:qe,customEndpoints:(ke=ne.data)==null?void 0:ke.endpoints,endpointFilter:d,exporting:Ve,filtersExpanded:re,fromDate:u,handleCloseDetail:He,handleExport:$e,handleOpenDetail:Ue,handleResetFilters:pe,isDetailOpen:T,items:Pe,logsQuery:P,modelFilter:r,page:p,pageSize:S,providerFilter:o,providerLabelMap:ce,providerOptions:de,rowDensity:x,resetVisibleColumns:W,selectedApiKeys:y,selectedLogId:D,setEndpointFilter:s,setFiltersExpanded:oe,setFromDate:j,setModelFilter:h,setPage:f,setPageSize:b,setProviderFilter:n,setRowDensity:G,setSelectedApiKeys:B,setStatusFilter:v,setToDate:a,showScrollHint:Fe,statusFilter:c,tableScrollRef:Te,toDate:i,toggleColumn:Re,total:Z,totalPages:J,visibleColumnCount:Le,visibleColumns:Me,visibleColumnSet:Ke}}function ss(){var o;const{t:l}=M(),t=Mt();return e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx(et,{icon:e.jsx(Ye,{className:"h-5 w-5","aria-hidden":"true"}),title:l("logs.title"),description:l("logs.description"),eyebrow:"Traffic Explorer",breadcrumb:"Gateway / Logs",helper:l("logs.filtersDescription"),badge:t.total>0?l("logs.summary.total",{value:t.total.toLocaleString()}):void 0,actions:e.jsx(Et,{columnOptions:t.columnOptions,exporting:t.exporting,onExport:()=>void t.handleExport(),onRefresh:()=>void t.logsQuery.refetch(),onResetColumns:t.resetVisibleColumns,onSetDensity:t.setRowDensity,onToggleColumn:t.toggleColumn,refreshing:t.logsQuery.isFetching,rowDensity:t.rowDensity,total:t.total,visibleColumns:t.visibleColumns,visibleColumnSet:t.visibleColumnSet})}),e.jsx(yt,{total:t.total,activeFilters:t.activeFilters,filtersExpanded:t.filtersExpanded,setFiltersExpanded:t.setFiltersExpanded,handleResetFilters:t.handleResetFilters,activeQuickView:t.activeQuickView,applyQuickView:t.applyQuickView,providerFilter:t.providerFilter,setProviderFilter:t.setProviderFilter,endpointFilter:t.endpointFilter,setEndpointFilter:t.setEndpointFilter,selectedApiKeys:t.selectedApiKeys,setSelectedApiKeys:t.setSelectedApiKeys,modelFilter:t.modelFilter,setModelFilter:t.setModelFilter,statusFilter:t.statusFilter,setStatusFilter:t.setStatusFilter,fromDate:t.fromDate,setFromDate:t.setFromDate,toDate:t.toDate,setToDate:t.setToDate,providerOptions:t.providerOptions,apiKeys:t.apiKeys,apiKeysLoading:t.apiKeysQuery.isLoading,customEndpoints:t.customEndpoints}),e.jsx(Ft,{tableScrollRef:t.tableScrollRef,visibleColumnSet:t.visibleColumnSet,visibleColumnCount:t.visibleColumnCount,logsError:t.logsQuery.isError?((o=t.logsQuery.error)==null?void 0:o.message)??null:null,logsPending:t.logsQuery.isPending,items:t.items,activeFiltersCount:t.activeFilters.length,handleResetFilters:t.handleResetFilters,handleRetry:()=>void t.logsQuery.refetch(),providerLabelMap:t.providerLabelMap,apiKeyMap:t.apiKeyMap,handleOpenDetail:t.handleOpenDetail,rowDensity:t.rowDensity,showScrollHint:t.showScrollHint,pageSize:t.pageSize,setPageSize:t.setPageSize,page:t.page,totalPages:t.totalPages,setPage:t.setPage}),e.jsx(vt,{open:t.isDetailOpen,logId:t.selectedLogId,onClose:t.handleCloseDetail,providerLabelMap:t.providerLabelMap,apiKeyMap:t.apiKeyMap})]})}export{ss as default};