@chenpu17/cc-gw 0.9.0-beta.0 → 0.9.0
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.
- package/package.json +5 -5
- package/src/web/dist/assets/{About-DY21fypB.js → About-DhB_6utk.js} +1 -1
- package/src/web/dist/assets/{ApiKeys-FWkRLPTy.js → ApiKeys-Cx4kYUfE.js} +1 -1
- package/src/web/dist/assets/{ConfirmDialog-CyTpXZeT.js → ConfirmDialog-CgKijCNt.js} +1 -1
- package/src/web/dist/assets/Dashboard-CyjVgsnF.js +1 -0
- package/src/web/dist/assets/{Events-x_fSf1mz.js → Events-CWvgjYnj.js} +1 -1
- package/src/web/dist/assets/{Help-BMgllYJq.js → Help-CLGrjSta.js} +1 -1
- package/src/web/dist/assets/{Login-DrtDFqbk.js → Login-j6M7LsIk.js} +1 -1
- package/src/web/dist/assets/{Logs-18flgbiW.js → Logs-lC0QWlZz.js} +1 -1
- package/src/web/dist/assets/{ProvidersWorkbench-aHO5-ApY.js → ProvidersWorkbench-CXS-UBtR.js} +1 -1
- package/src/web/dist/assets/Settings-bJkZ6l1O.js +1 -0
- package/src/web/dist/assets/{Setup-B1j2zExa.js → Setup-BIEy_Ywx.js} +1 -1
- package/src/web/dist/assets/{apiKeys-k1jIJuDa.js → apiKeys-DngGSX7O.js} +1 -1
- package/src/web/dist/assets/app-vWIA9Pq_.js +61 -0
- package/src/web/dist/assets/{gateway-i49olSPp.js → gateway-B7Y2AqSU.js} +1 -1
- package/src/web/dist/assets/{landing-W4f2Nx8j.js → landing-Dj8Ojphq.js} +1 -1
- package/src/web/dist/assets/package-BBDLwVNt.js +1 -0
- package/src/web/dist/assets/{shared-Cuakym23.js → shared-D9r3kFnp.js} +1 -1
- package/src/web/dist/assets/{useAppMutation-CEN5Oa4S.js → useAppMutation-DJ2QsEsU.js} +1 -1
- package/src/web/dist/assets/{useProviderForm-DZEYuRhD.js → useProviderForm-eK2SFp4F.js} +1 -1
- package/src/web/dist/index.html +1 -1
- package/src/web/dist/landing.html +2 -2
- package/src/web/dist/assets/Dashboard-FKM-9UNt.js +0 -1
- package/src/web/dist/assets/Settings-iEjCAGgm.js +0 -1
- package/src/web/dist/assets/app-Citq5KW4.js +0 -61
- package/src/web/dist/assets/package-B2CgmdJ7.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as x,j as e,o as is,ar as ds,aj as cs,as as ms,ak as Re,at as De,aq as us,au as ps,Z as xs,T as gs,P as fs}from"./vendor-CITafuNQ.js";import{P as hs}from"./PageToolbar-CWw40AFL.js";import{c as E}from"./global-BCehxTGJ.js";import{B as R,d as ys,a as ge,c as G,q as H,s as q,t as bs,b as $}from"./app-Citq5KW4.js";import{B as V}from"./badge-DpUlf_NW.js";import{C as Fe,a as Te}from"./card-D4YOc5eB.js";import{L as B,I as pe}from"./label-DSVzZIex.js";import{S as te,a as le,b as ae,c as re,d as I}from"./select-sOwKYsgI.js";import{u as O}from"./i18n-PeX9kBVO.js";import{D as js,A as vs,a as Ns,b as ws,c as ks,d as Ss}from"./DialogShell-CM92wXHo.js";import{P as Cs,a as X}from"./PageState-CFLrRswm.js";import{T as Ls,a as _s,b as Es,c as Rs}from"./tabs-UWyz9J_W.js";import{c as Ds}from"./clipboard-BnAnBk_-.js";import{a as Fs,g as fe,b as Ke,f as A,c as he,d as Ts,e as M,h as Me,i as Pe,j as Ks,T as Ms}from"./utils-B_Q3Hhgb.js";import{P as Ps,a as qs,b as zs}from"./popover-QZXvcPr8.js";import{S as As}from"./segmented-control-13KTib6k.js";import{L as qe}from"./router-BoBrmro7.js";import{a as Os}from"./query-DZF7K6hv.js";import{g as Le}from"./gateway-i49olSPp.js";import"./radix-Bux_1C5J.js";function Is({apiKeys:s,selected:l,onChange:p,disabled:a,className:o}){const{t}=O(),i=x.useId(),[y,b]=x.useState(!1),[d,v]=x.useState(null),u=x.useRef(null),N=x.useRef(null),f=x.useRef(null),w=()=>{const g=N.current;if(!g)return;const j=g.getBoundingClientRect(),k=Math.max(j.width,256),n=window.innerWidth-12;v({left:Math.min(j.left,n-k),top:j.bottom+8,width:k})};x.useEffect(()=>{if(!y)return;const g=k=>{var C,D;const n=k.target;!((C=u.current)!=null&&C.contains(n))&&!((D=f.current)!=null&&D.contains(n))&&b(!1)},j=k=>{var n;k.key==="Escape"&&(b(!1),(n=N.current)==null||n.focus())};return window.addEventListener("mousedown",g),window.addEventListener("keydown",j),()=>{window.removeEventListener("mousedown",g),window.removeEventListener("keydown",j)}},[y]),x.useEffect(()=>{if(y)return w(),window.addEventListener("resize",w),window.addEventListener("scroll",w,!0),()=>{window.removeEventListener("resize",w),window.removeEventListener("scroll",w,!0)}},[y]);const r=x.useMemo(()=>{if(l.length===0)return[];const g=new Map;for(const j of s)g.set(j.id,j);return l.map(j=>{const k=g.get(j);return k?k.isWildcard?t("apiKeys.wildcard"):k.name:null}).filter(j=>!!j)},[s,l,t]),h=l.length===0?t("logs.filters.apiKeyAll"):t("logs.filters.apiKeySelected",{count:l.length}),L=g=>{l.includes(g)?p(l.filter(j=>j!==g)):p([...l,g])};return e.jsxs("div",{className:E("relative space-y-2",o),ref:u,children:[e.jsx(B,{htmlFor:i,children:t("logs.filters.apiKey")}),e.jsxs("button",{ref:N,id:i,type:"button",onClick:()=>{w(),b(g=>!g)},disabled:a||s.length===0,title:t("logs.filters.apiKeyHint"),className:E("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-primary",y&&"ring-2 ring-ring ring-offset-2"),children:[e.jsxs("span",{className:"truncate",children:[h,r.length>0&&e.jsx("span",{className:"ml-1 text-xs text-muted-foreground",children:r.join(", ")})]}),e.jsx("svg",{className:E("h-4 w-4 opacity-50 transition-transform",y&&"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"})})]}),y&&d&&is.createPortal(e.jsxs("div",{ref:f,className:"fixed z-50 rounded-lg border bg-popover p-2 shadow-[var(--surface-shadow-lg)]",style:d,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:h}),e.jsx("button",{type:"button",onClick:()=>p([]),disabled:l.length===0,className:"text-primary hover:underline disabled:opacity-40",children:t("common.actions.reset")})]}),e.jsxs("div",{className:"max-h-56 overflow-y-auto py-2",children:[s.map(g=>{const j=g.isWildcard?t("apiKeys.wildcard"):g.name,k=l.includes(g.id);return e.jsxs("label",{className:E("flex cursor-pointer items-center gap-3 rounded-xl px-3 py-2 text-sm transition hover:bg-primary/5",k&&"bg-primary/10 text-primary"),children:[e.jsx("input",{type:"checkbox",className:"h-4 w-4 rounded border-border",checked:k,onChange:()=>L(g.id)}),e.jsx("span",{className:"truncate",children:j})]},g.id)}),s.length===0&&e.jsx("p",{className:"px-2 py-2 text-xs text-muted-foreground",children:t("logs.filters.apiKeyAll")})]})]}),document.body)]})}function $s(s){const{t:l}=O(),{activeFilters:p,filtersExpanded:a,setFiltersExpanded:o,handleResetFilters:t,activeQuickView:i,applyQuickView:y,providerFilter:b,setProviderFilter:d,endpointFilter:v,setEndpointFilter:u,selectedApiKeys:N,setSelectedApiKeys:f,modelFilter:w,setModelFilter:r,statusFilter:h,setStatusFilter:L,fromDate:g,setFromDate:j,toDate:k,setToDate:n,providerOptions:C,apiKeys:D,apiKeysLoading:F,customEndpoints:_}=s;return e.jsx(Fe,{"data-testid":"logs-filters-card",className:"overflow-hidden",children:e.jsxs(Te,{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")}),p.length>0&&e.jsx(V,{variant:"outline",className:"rounded-full border-transparent bg-primary/10 px-2.5 py-0.5 text-[11px] font-semibold text-primary",children:l("common.filters.activeCount",{count:p.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:[p.length>0&&e.jsx(R,{variant:"ghost",size:"sm",onClick:t,className:"h-8 rounded-full px-3 text-xs",children:l("common.actions.reset")}),e.jsx(R,{variant:"ghost",size:"sm",onClick:()=>o(c=>!c),className:"h-8 rounded-full px-3 text-xs",children:a?e.jsxs(e.Fragment,{children:[l("common.filters.collapse"),e.jsx(ds,{className:"ml-1 h-4 w-4"})]}):e.jsxs(e.Fragment,{children:[l("common.filters.expand"),e.jsx(cs,{className:"ml-1 h-4 w-4"})]})})]})]}),e.jsxs("div",{className:"grid gap-2 lg:grid-cols-[minmax(0,1fr)_auto]",children:[e.jsx("div",{className:"flex min-h-10 items-center rounded-lg bg-secondary px-3 py-2",children:p.length>0?e.jsx("div",{className:"flex flex-wrap items-center gap-2",children:p.map(c=>e.jsxs(V,{variant:"outline",role:"button",tabIndex:0,className:"flex cursor-pointer items-center gap-1 rounded-full border border-border bg-card px-2.5 py-1 text-[11px] font-semibold text-foreground/90 transition hover:bg-secondary",onClick:c.onRemove,onKeyDown:z=>{(z.key==="Enter"||z.key===" ")&&(z.preventDefault(),c.onRemove())},children:[c.label,e.jsx(ms,{className:"h-3 w-3","aria-hidden":"true"})]},c.key))}):e.jsx("span",{className:"text-xs text-muted-foreground",children:l("common.filters.allRequests")})}),e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 lg:justify-end",children:[e.jsx(xe,{label:l("logs.filters.apiKey"),value:N.length.toString()}),e.jsx(xe,{label:l("logs.filters.provider"),value:b==="all"?"0":"1"}),e.jsx(xe,{label:l("logs.filters.endpoint"),value:v==="all"?"0":"1"})]})]}),e.jsx("div",{className:"flex flex-wrap items-center gap-1.5 rounded-lg bg-secondary px-2 py-1.5",children:["all","errors","today","anthropic","openai"].map(c=>e.jsx(R,{variant:"ghost",size:"sm",className:E("h-7 rounded-full px-3 text-[11px] font-semibold transition-colors",i===c?"bg-card text-foreground shadow-[var(--surface-shadow)]":"text-muted-foreground"),onClick:()=>y(c),children:l(`logs.quickViews.${c}`)},c))})]}),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(B,{children:l("logs.filters.provider")}),e.jsxs(te,{value:b,onValueChange:d,children:[e.jsx(le,{children:e.jsx(ae,{})}),e.jsxs(re,{children:[e.jsx(I,{value:"all",children:l("logs.filters.providerAll")}),C.map(c=>e.jsx(I,{value:c.id,children:c.label??c.id},c.id))]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(B,{children:l("logs.filters.endpoint")}),e.jsxs(te,{value:v,onValueChange:u,children:[e.jsx(le,{children:e.jsx(ae,{})}),e.jsxs(re,{children:[e.jsx(I,{value:"all",children:l("logs.filters.endpointAll")}),e.jsx(I,{value:"anthropic",children:l("logs.filters.endpointAnthropic")}),e.jsx(I,{value:"openai",children:l("logs.filters.endpointOpenAI")}),_==null?void 0:_.map(c=>e.jsx(I,{value:c.id,children:c.label||c.id},c.id))]})]})]}),e.jsx(Is,{className:"md:col-span-2",apiKeys:D,selected:N,disabled:F,onChange:f}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(B,{children:l("logs.filters.modelId")}),e.jsx(pe,{value:w,onChange:c=>r(c.target.value),placeholder:l("logs.filters.modelPlaceholder")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(B,{children:l("logs.filters.status")}),e.jsxs(te,{value:h,onValueChange:c=>L(c),children:[e.jsx(le,{children:e.jsx(ae,{})}),e.jsxs(re,{children:[e.jsx(I,{value:"all",children:l("logs.filters.statusAll")}),e.jsx(I,{value:"success",children:l("logs.filters.statusSuccess")}),e.jsx(I,{value:"error",children:l("logs.filters.statusError")})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(B,{children:l("logs.filters.startDate")}),e.jsx(pe,{type:"date",value:g,onChange:c=>j(c.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(B,{children:l("logs.filters.endDate")}),e.jsx(pe,{type:"date",value:k,onChange:c=>n(c.target.value)})]})]})]})})}function xe({label:s,value:l}){return e.jsxs("div",{className:"inline-flex items-center gap-1.5 rounded-full border border-border/60 bg-card px-2.5 py-1 text-[11px] text-muted-foreground",children:[e.jsx("span",{children:s}),e.jsx("span",{className:"metric-number font-semibold text-foreground",children:l})]})}const ye={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 p=await ys.post("/api/logs/export",s,{responseType:"blob",timeout:l});return new Blob([p.data],{type:"application/zip"})}};function ze({apiKeyMap:s,logId:l,open:p,providerLabelMap:a}){var w;const{t:o}=O(),{pushToast:t}=ge(),i=G(H.logs.detail(l),ye.detailRequest(l),{enabled:p&&l!==null,staleTime:3e4,gcTime:15e3,placeholderData:void 0});x.useEffect(()=>{!i.isError||!i.error||t({title:o("logs.detail.loadError"),description:i.error.message,variant:"error"})},[i.error,i.isError,t,o]);const y=x.useCallback(async(r,h,L)=>{if(!h){t({title:o("logs.detail.copy.empty",{label:r}),variant:"info"});return}try{await Ds(h),t({title:o(L),variant:"success"})}catch(g){t({title:o("logs.detail.copy.failure"),description:g instanceof Error?g.message:o("logs.detail.copy.failureFallback"),variant:"error"})}},[t,o]),b=x.useCallback((r,h)=>{if(!h){t({title:o("logs.detail.copy.empty",{label:r}),variant:"info"});return}const L=new Blob([h],{type:"application/json;charset=utf-8"}),g=URL.createObjectURL(L),j=document.createElement("a"),k=new Date().toISOString().replace(/[:.]/g,"-"),n=r.trim().toLowerCase().replace(/[^a-z0-9\u4e00-\u9fa5]+/gi,"-").replace(/^-+|-+$/g,"")||"payload";j.href=g,j.download=`cc-gw-log-${l??"payload"}-${n}-${k}.json`,document.body.appendChild(j),j.click(),document.body.removeChild(j),URL.revokeObjectURL(g)},[l,t,o]),d=i.data,v=d?a.get(d.provider)??d.provider:"",u=d&&d.api_key_id!=null?s.get(d.api_key_id):void 0,N=d?Fs(d,o):null,f=d?fe(d,o):null;return{apiKeyMeta:u,errorSourceMeta:N,errorMessage:i.isError?((w=i.error)==null?void 0:w.message)??null:null,handleCopy:y,handleDownloadPayload:b,isError:i.isError,isPending:i.isPending,providerLabel:v,refetch:i.refetch,record:d,statusMeta:f}}function Qs({open:s,logId:l,onClose:p,providerLabelMap:a,apiKeyMap:o}){var g,j,k;const{t}=O(),{apiKeyMeta:i,errorSourceMeta:y,errorMessage:b,handleCopy:d,handleDownloadPayload:v,isError:u,isPending:N,providerLabel:f,refetch:w,record:r,statusMeta:h}=ze({apiKeyMap:o,logId:l,open:s,providerLabelMap:a}),L=x.useMemo(()=>{var C,D,F,_;return r?[{key:"client-request",title:t("logs.detail.payload.clientRequest"),value:((C=r.payload)==null?void 0:C.client_request)??null,emptyLabel:t("logs.detail.payload.emptyRequest"),copyToast:"logs.detail.copy.requestSuccess"},...(D=r.payload)!=null&&D.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"}]:[],...(F=r.payload)!=null&&F.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:((_=r.payload)==null?void 0:_.client_response)??null,emptyLabel:t("logs.detail.payload.emptyResponse"),copyToast:"logs.detail.copy.responseSuccess"}].map(c=>({...c,display:Ke(c.value,c.emptyLabel)})):[]},[r,t]);return e.jsx(js,{open:s,onOpenChange:n=>{n||p()},children:e.jsxs(vs,{className:"w-[min(96vw,1200px)] max-w-[1200px]",children:[e.jsxs(Ns,{className:"pr-14",children:[e.jsx(ws,{children:t("logs.detail.title")}),e.jsx(ks,{children:r?t("logs.detail.id",{id:r.id}):t("logs.detail.loadError")})]}),e.jsx(Ss,{className:"max-h-[78vh]",children:N?e.jsx(Cs,{compact:!0,className:"min-h-[240px]",label:t("common.loading")}):u?e.jsx(X,{compact:!0,className:"min-h-[240px]",tone:"danger",title:t("logs.detail.loadError"),description:b??t("common.unknownError"),action:e.jsx(R,{variant:"outline",onClick:()=>void w(),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.jsxs("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.jsx("span",{className:"text-muted-foreground",children:t("logs.detail.summary.latency",{value:A(r.latency_ms,t("common.units.ms"))})}),r.ttft_ms!==null?e.jsxs("span",{className:"text-muted-foreground",children:["TTFT: ",A(r.ttft_ms,t("common.units.ms"))]}):null]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(V,{variant:h==null?void 0:h.variant,children:(h==null?void 0:h.label)??"-"}),e.jsx(V,{variant:"outline",children:r.stream?t("logs.stream.streaming"):t("logs.stream.single")})]})]}),e.jsxs("div",{className:"grid gap-3 md:grid-cols-5",children:[e.jsx(Q,{label:t("logs.detail.info.latency"),value:A(r.latency_ms,t("common.units.ms"))}),e.jsx(Q,{label:t("logs.detail.info.ttft"),value:A(r.ttft_ms,t("common.units.ms"))}),e.jsx(Q,{label:t("logs.detail.info.tpot"),value:A(r.tpot_ms,t("common.units.msPerToken"))}),e.jsx(Q,{label:t("logs.detail.info.status"),value:(h==null?void 0:h.label)??"-"}),e.jsx(Q,{label:t("logs.detail.info.errorSource"),value:(y==null?void 0:y.label)??"-"})]}),e.jsxs("dl",{className:"grid gap-x-4 gap-y-3 md:grid-cols-2 xl:grid-cols-4",children:[e.jsx(K,{label:t("logs.detail.info.time"),value:he(r.timestamp)}),e.jsx(K,{label:t("logs.detail.info.sessionId"),value:r.session_id??"-"}),e.jsx(K,{label:t("logs.detail.info.endpoint"),value:r.endpoint||"-"}),e.jsx(K,{label:t("logs.detail.info.provider"),value:f}),e.jsx(K,{label:t("logs.detail.info.requestedModel"),value:r.client_model??t("logs.detail.info.noRequestedModel")}),e.jsx(K,{label:t("logs.detail.info.model"),value:r.model}),e.jsx(K,{label:t("logs.detail.info.stream"),value:Ts(r.stream)}),e.jsx(K,{label:t("logs.detail.info.status"),value:(h==null?void 0:h.label)??"-"}),e.jsx(K,{label:t("logs.detail.info.errorSource"),value:(y==null?void 0:y.label)??"-"})]}),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:M(r.input_tokens)}),e.jsx(Q,{label:t("logs.detail.info.cacheReadTokens"),value:M(r.cache_read_tokens)}),e.jsx(Q,{label:t("logs.detail.info.cacheCreationTokens"),value:M(r.cache_creation_tokens)}),e.jsx(Q,{label:t("logs.detail.info.outputTokens"),value:M(r.output_tokens)})]}),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]}),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(K,{label:t("logs.detail.apiKey.name"),value:r.api_key_id==null&&!r.api_key_name?t("logs.detail.apiKey.missing"):i!=null&&i.isWildcard?t("apiKeys.wildcard"):(i==null?void 0:i.name)??r.api_key_name??t("logs.detail.apiKey.missing")}),e.jsx(K,{label:t("logs.detail.apiKey.identifier"),value:r.api_key_id??t("common.noData")}),e.jsx(K,{label:t("logs.detail.apiKey.masked"),value:i!=null&&i.isWildcard?t("apiKeys.wildcard"):(i==null?void 0:i.maskedKey)??r.api_key_name??t("logs.detail.apiKey.maskedUnavailable")}),e.jsx(K,{label:t("logs.detail.apiKey.lastUsed"),value:i!=null&&i.lastUsedAt?new Date(i.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:(g=r.payload)!=null&&g.upstream_request||(j=r.payload)!=null&&j.upstream_response?t("logs.detail.payload.helperWithUpstream"):t("logs.detail.payload.helperClientOnly")})]}),e.jsxs(Ls,{defaultValue:(k=L[0])==null?void 0:k.key,children:[e.jsx(_s,{className:"w-full justify-start overflow-x-auto",children:L.map(n=>e.jsx(Es,{value:n.key,children:n.title},n.key))}),L.map(n=>e.jsx(Rs,{value:n.key,children:e.jsx(Vs,{title:n.title,display:n.display,onCopy:()=>d(n.title,n.value,n.copyToast),onDownload:()=>v(n.title,n.value),panelKey:n.key,t})},n.key))]})]})]})]}):e.jsx(X,{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 K({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 Vs({display:s,onCopy:l,onDownload:p,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(R,{variant:"outline",size:"sm",onClick:l,children:[e.jsx(Re,{className:"mr-2 h-3.5 w-3.5"}),t("common.actions.copy")]}),e.jsxs(R,{variant:"outline",size:"sm",onClick:p,children:[e.jsx(De,{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})]})}const Z=[20,50,100],J=["endpoint","provider","requestedModel","routedModel","apiKey","tokens","duration","status","error"],oe=["endpoint","provider","requestedModel","routedModel","apiKey","tokens","duration","status","error"];function Us(){return typeof window>"u"?"comfortable":window.localStorage.getItem(q.logs.density)==="compact"?"compact":"comfortable"}function Hs(){if(typeof window>"u")return Z[0];const s=window.localStorage.getItem(q.logs.pageSize),l=Number(s);return Z.includes(l)?l:Z[0]}function _e(s,l=!1){if(!s)return;const p=l?`${s}T23:59:59.999`:`${s}T00:00:00.000`,a=Date.parse(p);return Number.isFinite(a)?a:void 0}function Bs(s,l,p){return s===p&&l===p}function Ws({columnOptions:s,exporting:l,onExport:p,onRefresh:a,onResetColumns:o,onSetDensity:t,onToggleColumn:i,refreshing:y,rowDensity:b,visibleColumns:d,visibleColumnSet:v}){const{t:u}=O(),N=JSON.stringify(d)===JSON.stringify(J);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.jsx(As,{block:!0,className:"w-full overflow-x-auto sm:w-auto",value:b,onChange:t,options:[{value:"comfortable",label:u("logs.table.density.comfortable")},{value:"compact",label:u("logs.table.density.compact")}]}),e.jsxs(Ps,{children:[e.jsx(qs,{asChild:!0,children:e.jsx(R,{variant:"outline",size:"sm",className:"w-full sm:w-auto",children:u("logs.actions.columns")})}),e.jsxs(zs,{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:u("logs.actions.columns")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:u("logs.actions.visibleCount",{count:d.length})})]}),e.jsx(R,{variant:"ghost",size:"sm",onClick:o,disabled:N,children:u("common.actions.reset")})]}),e.jsx("div",{className:"grid gap-1.5",children:s.map(f=>{const w=v.has(f.id);return e.jsxs("label",{className:E("flex cursor-pointer items-center gap-3 rounded-xl px-3 py-2 text-sm transition hover:bg-accent",w&&"bg-primary/10 text-primary"),children:[e.jsx("input",{type:"checkbox",checked:w,onChange:()=>i(f.id),className:"h-4 w-4 rounded border-border"}),e.jsx("span",{children:f.label})]},f.id)})})]})]}),e.jsxs(R,{onClick:p,disabled:l,className:"w-full sm:w-auto",children:[e.jsx(De,{className:"mr-2 h-4 w-4"}),u(l?"logs.actions.exporting":"logs.actions.export")]})]}),e.jsx("div",{className:"flex w-full items-center xl:w-auto",children:e.jsxs(R,{variant:"outline",size:"sm",onClick:a,disabled:y,className:"shrink-0",children:[e.jsx(us,{className:E("mr-2 h-4 w-4",y&&"animate-spin")}),u(y?"common.actions.refreshing":"logs.actions.manualRefresh")]})})]})}function Gs({record:s,providerLabelMap:l,onSelect:p}){const{t:a}=O(),o=fe(s,a),t=l.get(s.provider)??s.provider,i=Me(s.session_id),y=i==null?void 0:i.accentStyle;return e.jsxs("button",{type:"button","data-session-id":i==null?void 0:i.sessionId,"data-session-color":i==null?void 0:i.colorKey,style:y,onClick:()=>p(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:he(s.timestamp)}),e.jsx(V,{variant:o.variant,className:"text-xs",children:o.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:t,children:t}),e.jsx("span",{className:"min-w-0 truncate text-muted-foreground",title:s.model,children:s.model})]}),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:A(s.latency_ms,a("common.units.ms"))}),s.ttft_ms!=null?e.jsxs("span",{children:[a("logs.table.columns.latencyTtft")," ",M(s.ttft_ms)]}):null]})]})}const Ee={accent:"bg-primary",ok:"bg-success",warn:"bg-warning",error:"bg-destructive"};function Js({logId:s,providerLabelMap:l,apiKeyMap:p}){const{t:a}=O(),{record:o,isPending:t,isError:i,errorMessage:y,statusMeta:b,providerLabel:d,handleCopy:v,refetch:u}=ze({apiKeyMap:p,logId:s,open:!0,providerLabelMap:l}),N=x.useMemo(()=>{var C,D,F,_;if(!o)return[];const n=[{key:"client-request",title:a("logs.detail.payload.clientRequest"),value:((C=o.payload)==null?void 0:C.client_request)??null,emptyLabel:a("logs.detail.payload.emptyRequest"),copyToast:"logs.detail.copy.requestSuccess"}];return(D=o.payload)!=null&&D.upstream_request&&n.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"}),(F=o.payload)!=null&&F.upstream_response&&n.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"}),n.push({key:"client-response",title:a("logs.detail.payload.clientResponse"),value:((_=o.payload)==null?void 0:_.client_response)??null,emptyLabel:a("logs.detail.payload.emptyResponse"),copyToast:"logs.detail.copy.responseSuccess"}),n.map(c=>({...c,display:Ke(c.value,c.emptyLabel)}))},[o,a]),[f,w]=x.useState("client-request"),r=N.find(n=>n.key===f)??N[0];if(t)return e.jsx("div",{className:"py-3",children:e.jsx(Pe,{className:"h-28 w-full"})});if(i)return e.jsx(X,{compact:!0,tone:"danger",title:a("logs.detail.loadError"),description:y??a("common.unknownError"),action:e.jsx(R,{variant:"outline",size:"sm",onClick:()=>void u(),children:a("common.actions.refresh")})});if(!o)return e.jsx(X,{compact:!0,title:a("logs.detail.loadError"),description:a("common.noData")});const h=Ks(o,d,a),L=a("common.units.ms"),g=[{label:a("logs.detail.info.status"),value:(b==null?void 0:b.label)??"-"},{label:a("logs.detail.info.latency"),value:A(o.latency_ms,L)},{label:a("logs.detail.info.ttft"),value:A(o.ttft_ms,L)},{label:a("logs.detail.info.inputTokens"),value:M(o.input_tokens)},{label:a("logs.detail.info.outputTokens"),value:M(o.output_tokens)},{label:a("logs.detail.info.cacheReadTokens"),value:M(o.cache_read_tokens)}],j=o.ttft_ms!=null,k=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:h.map((n,C)=>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:E("mt-1 h-[9px] w-[9px] rounded-full",Ee[n.tone])}),C<h.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:n.title}),n.atLabel?e.jsx("span",{className:"text-[10.5px] tabular-nums text-muted-foreground",children:n.atLabel}):null,n.durLabel?e.jsx("span",{className:"ml-auto text-[10.5px] tabular-nums text-muted-foreground",children:n.durLabel}):null]}),n.detail?e.jsx("div",{className:"mt-1 text-[11px] leading-[1.55] text-muted-foreground",children:n.detail}):null,e.jsx("div",{className:"mt-1.5 h-1 w-full max-w-[220px] bg-secondary",children:e.jsx("div",{className:E("h-full",Ee[n.tone]),style:{width:`${n.barPct}%`}})})]})]},n.id))}),j?null:e.jsx("p",{className:"mt-1 text-[10.5px] text-muted-foreground/70",children:a("logs.detail.trace.degraded")})]}),e.jsxs("div",{className:"flex min-w-0 flex-col gap-3",children:[e.jsx("div",{className:"grid grid-cols-3 gap-2",children:g.map(n=>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:n.label}),e.jsx("div",{className:"mt-0.5 text-[13px] font-semibold tabular-nums",children:n.value})]},n.label))}),e.jsxs("div",{className:"border border-border bg-card",children:[e.jsx("div",{className:"flex gap-0.5 border-b border-border bg-secondary/50 p-1.5",role:"tablist",children:N.map(n=>{const C=n.key===(r==null?void 0:r.key);return e.jsx("button",{type:"button",role:"tab","aria-selected":C,onClick:()=>w(n.key),className:E("px-2.5 py-1 text-[10.5px] font-medium transition-colors",C?"bg-card text-foreground":"text-muted-foreground hover:text-foreground"),children:n.title},n.key)})}),e.jsx("pre",{"data-testid":`log-payload-${(r==null?void 0:r.key)??"none"}`,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:(r==null?void 0:r.display.text)||a("logs.detail.payload.emptyRequest")})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs(R,{variant:"outline",size:"sm",className:"h-[30px] flex-1",onClick:()=>{r&&v(r.title,r.value,r.copyToast)},children:[e.jsx(Re,{className:"mr-1.5 h-3.5 w-3.5","aria-hidden":"true"}),a("logs.detail.inline.copyRequest")]}),k?e.jsx(R,{variant:"outline",size:"sm",className:"h-[30px] flex-1",onClick:()=>v(a("logs.detail.inline.copySession"),k,"logs.detail.inline.sessionCopied"),children:a("logs.detail.inline.copySession")}):null,e.jsx(R,{asChild:!0,variant:"outline",size:"sm",className:"h-[30px] flex-1",children:e.jsxs(qe,{to:"/providers?tab=routing",children:[a("logs.detail.inline.viewRule"),e.jsx(ps,{className:"ml-1.5 h-3.5 w-3.5","aria-hidden":"true"})]})})]})]})]})}function Zs({record:s,providerLabelMap:l,apiKeyMap:p,onSelect:a,isExpanded:o,onToggleExpand:t,isEven:i,density:y,visibleColumnSet:b}){const{t:d}=O(),v=l.get(s.provider)??s.provider,u=s.endpoint||"-",N=fe(s,d),f=s.client_model??d("logs.table.requestedModelFallback"),w=s.api_key_id!=null?p.get(s.api_key_id):void 0,r=s.api_key_id==null?d("logs.table.apiKeyUnknown"):w!=null&&w.isWildcard?d("apiKeys.wildcard"):w!=null&&w.name?w.name:s.api_key_name?s.api_key_name:d("logs.table.apiKeyUnknown"),h=y==="compact"?"px-3 py-1.5":"px-3 py-2",L=i?"bg-muted/30":"bg-background",g=Me(s.session_id),j=g==null?void 0:g.accentStyle,k=b.size+2,n=d(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":g==null?void 0:g.sessionId,"data-session-color":g==null?void 0:g.colorKey,className:E("transition-colors duration-160 ease-surface",i?"bg-muted/30":"",o?"bg-muted/50":"hover:bg-muted/50"),children:[e.jsx("td",{className:E("sticky left-0 z-10 text-xs",h,L),style:j,children:e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("button",{type:"button","aria-expanded":o,"aria-label":n,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(xs,{className:E("h-3.5 w-3.5 transition-transform duration-160 ease-surface",o&&"rotate-90"),"aria-hidden":"true"})}),e.jsx("span",{className:"metric-number",children:he(s.timestamp)})]})}),b.has("endpoint")&&e.jsx("td",{className:E(h,"text-xs"),children:u}),b.has("provider")&&e.jsx("td",{className:E(h,"text-xs"),children:e.jsx("div",{className:"max-w-[100px] truncate",title:v,children:v})}),b.has("requestedModel")&&e.jsx("td",{className:E(h,"text-xs text-muted-foreground"),children:e.jsx("div",{className:"max-w-[120px] truncate",title:f,children:f})}),b.has("routedModel")&&e.jsx("td",{className:E(h,"text-xs"),children:e.jsx("div",{className:"max-w-[120px] truncate",title:s.model,children:s.model})}),b.has("apiKey")&&e.jsx("td",{className:E(h,"text-xs text-muted-foreground"),children:e.jsx("div",{className:"max-w-[90px] truncate",title:r,children:r})}),b.has("tokens")&&e.jsx("td",{className:E(h,"text-right text-xs tabular-nums align-top"),children:e.jsxs("span",{className:"inline-flex flex-col items-end gap-0.5",children:[e.jsxs("span",{className:"whitespace-nowrap",children:[d("logs.table.columns.tokenIn")," ",M(s.input_tokens),e.jsx("span",{className:"mx-1 text-muted-foreground/50",children:"·"}),d("logs.table.columns.tokenOut")," ",M(s.output_tokens)]}),(()=>{const C=(s.cache_read_tokens??0)+(s.cache_creation_tokens??0);return C>0?e.jsxs("span",{className:"whitespace-nowrap text-[11px] text-muted-foreground/70",children:[d("logs.table.columns.tokenCache")," ",M(C)]}):null})()]})}),b.has("duration")&&e.jsx("td",{className:E(h,"text-right text-xs tabular-nums align-top"),children:e.jsxs("span",{className:"inline-flex flex-col items-end gap-0.5",children:[e.jsx("span",{className:"whitespace-nowrap",children:A(s.latency_ms,"ms")}),(s.ttft_ms!=null||s.tpot_ms!=null)&&e.jsxs("span",{className:"whitespace-nowrap text-[11px] text-muted-foreground/70",title:`${d("logs.table.columns.latencyTtft")} ${A(s.ttft_ms,"ms")} · ${d("logs.table.columns.latencyTpot")} ${A(s.tpot_ms,"ms/tk")}`,children:[d("logs.table.columns.latencyTtft")," ",M(s.ttft_ms),e.jsx("span",{className:"mx-1 text-muted-foreground/50",children:"·"}),d("logs.table.columns.latencyTpot")," ",M(s.tpot_ms)]})]})}),b.has("status")&&e.jsx("td",{className:E(h,"text-center"),children:e.jsx(V,{variant:N.variant,className:"text-xs",children:N.label})}),b.has("error")&&e.jsx("td",{className:E(h,"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:E("sticky right-0 z-10 text-center",h,L),children:e.jsx(R,{variant:"outline",size:"sm",onClick:()=>a(s.id),children:d("logs.actions.detail")})})]}),o?e.jsx("tr",{"data-testid":`log-row-expanded-wrapper-${s.id}`,children:e.jsx("td",{colSpan:k,className:"border-t border-border bg-secondary/30 p-0",children:e.jsx("div",{className:"px-5 pb-5 pt-3",children:e.jsx(Js,{logId:s.id,providerLabelMap:l,apiKeyMap:p})})})}):null]})}function Xs(s){const{t:l}=O(),{tableScrollRef:p,visibleColumnSet:a,visibleColumnCount:o,logsError:t,logsPending:i,items:y,activeFiltersCount:b,total:d,handleResetFilters:v,handleRetry:u,providerLabelMap:N,apiKeyMap:f,handleOpenDetail:w,expandedLogId:r,onToggleExpand:h,rowDensity:L,showScrollHint:g,pageSize:j,setPageSize:k,page:n,totalPages:C,setPage:D}=s,F=e.jsx(X,{compact:!0,tone:"danger",icon:e.jsx(gs,{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(R,{variant:"outline",size:"sm",onClick:u,children:l("common.actions.refresh")}),b>0?e.jsx(R,{variant:"ghost",size:"sm",onClick:v,children:l("common.actions.reset")}):null]})}),_=e.jsx(X,{compact:!0,tone:"primary",icon:e.jsx(fs,{className:"h-5 w-5","aria-hidden":"true"}),title:b>0?l("logs.empty.filteredTitle"):l("logs.empty.title"),description:b>0?l("logs.empty.filteredSubtitle"):l("logs.empty.subtitle"),action:e.jsxs("div",{className:"flex flex-wrap items-center justify-center gap-2",children:[b>0?e.jsx(R,{variant:"outline",size:"sm",onClick:v,children:l("logs.empty.actions.reset")}):null,e.jsx(R,{asChild:!0,variant:"ghost",size:"sm",children:e.jsx(qe,{to:"/api-keys",children:l("logs.empty.actions.apiKeys")})})]})});return e.jsx(Fe,{className:"overflow-hidden bg-card shadow-[var(--surface-shadow)]",children:e.jsxs(Te,{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:d.toLocaleString()})}),e.jsx("span",{className:"mx-1.5 text-muted-foreground/50",children:"·"}),l("logs.actions.visibleCount",{count:o-2})]})]}),e.jsxs("div",{className:"hidden md:flex flex-wrap items-center gap-2",children:[e.jsx(V,{variant:"secondary",children:"Wide Table"}),e.jsx(V,{variant:"outline",className:"bg-background",children:l(L==="compact"?"logs.table.density.compact":"logs.table.density.comfortable")}),g?e.jsx(V,{variant:"warning",children:"Scroll for more"}):null]})]}),e.jsxs("div",{className:"relative hidden md:block",children:[e.jsx("div",{ref:p,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:"sticky left-0 z-20 bg-secondary px-3 py-2.5 text-left text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:l("logs.table.columns.time")}),a.has("endpoint")&&e.jsx("th",{className:"px-3 py-2.5 text-left text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:l("logs.table.columns.endpoint")}),a.has("provider")&&e.jsx("th",{className:"px-3 py-2.5 text-left text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:l("logs.table.columns.provider")}),a.has("requestedModel")&&e.jsx("th",{className:"px-3 py-2.5 text-left text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:l("logs.table.columns.requestedModel")}),a.has("routedModel")&&e.jsx("th",{className:"px-3 py-2.5 text-left text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:l("logs.table.columns.routedModel")}),a.has("apiKey")&&e.jsx("th",{className:"px-3 py-2.5 text-left text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:l("logs.table.columns.apiKey")}),a.has("tokens")&&e.jsx("th",{className:"px-3 py-2.5 text-right text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:l("logs.table.columns.tokens")}),a.has("duration")&&e.jsx("th",{className:"px-3 py-2.5 text-right text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:l("logs.table.columns.duration")}),a.has("status")&&e.jsx("th",{className:"px-3 py-2.5 text-center text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:l("logs.table.columns.status")}),a.has("error")&&e.jsx("th",{className:"px-3 py-2.5 text-left text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:l("logs.table.columns.error")}),e.jsx("th",{className:"sticky right-0 z-20 bg-secondary px-3 py-2.5 text-center text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:l("logs.table.columns.actions")})]})}),e.jsx("tbody",{className:"divide-y divide-border/50",children:i?Array.from({length:8}).map((c,z)=>e.jsx(Ms,{columns:o},z)):t&&y.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:o,className:"px-3 py-6",children:F})}):y.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:o,className:"px-3 py-8 text-center text-sm text-muted-foreground",children:_})}):y.map((c,z)=>e.jsx(Zs,{record:c,providerLabelMap:N,apiKeyMap:f,onSelect:w,isExpanded:c.id===r,onToggleExpand:h,isEven:z%2===0,density:L,visibleColumnSet:a},c.id))})]})}),g&&e.jsx("div",{className:"table-scroll-hint"})]}),e.jsx("div",{className:"md:hidden",children:i?e.jsx("div",{className:"space-y-3 p-4",children:Array.from({length:5}).map((c,z)=>e.jsx(Pe,{className:"h-20 w-full"},z))}):t&&y.length===0?e.jsx("div",{className:"px-3 py-6",children:F}):y.length===0?e.jsx("div",{className:"px-3 py-8",children:_}):y.map(c=>e.jsx(Gs,{record:c,providerLabelMap:N,onSelect:w},c.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 rounded-full bg-secondary px-3 py-2",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:l("logs.table.pagination.perPage")}),e.jsxs(te,{value:j.toString(),onValueChange:c=>k(Number(c)),children:[e.jsx(le,{className:"h-8 w-[80px] bg-background",children:e.jsx(ae,{})}),e.jsx(re,{children:Z.map(c=>e.jsx(I,{value:c.toString(),children:c},c))})]})]}),e.jsxs("div",{className:"flex items-center gap-2 rounded-full bg-secondary px-2 py-2",children:[e.jsx(R,{variant:"outline",size:"sm",onClick:()=>D(c=>Math.max(c-1,1)),disabled:n<=1,children: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:C===0?0:n,total:C})}),e.jsx(R,{variant:"outline",size:"sm",onClick:()=>D(c=>C===0?c:Math.min(c+1,C)),disabled:C===0||n>=C,children:l("logs.table.pagination.next")})]})]})]})})}function Ys({exportTimeoutMs:s,queryParams:l,total:p}){const{t:a}=O(),{pushToast:o}=ge(),[t,i]=x.useState(!1),y=x.useCallback(async()=>{if(!t){i(!0);try{const b=p>0?Math.min(p,5e3):1e3,d={...l,limit:b,offset:0},v=await ye.exportArchive(d,s),u=new Date().toISOString().replace(/[:.]/g,"-"),N=URL.createObjectURL(v),f=document.createElement("a");f.href=N,f.download=`cc-gw-logs-${u}.zip`,document.body.appendChild(f),f.click(),f.remove(),URL.revokeObjectURL(N),o({title:a("logs.toast.exportSuccess.title"),description:a("logs.toast.exportSuccess.desc"),variant:"success"})}catch(b){const d=bs(b);o({title:a("logs.toast.exportError.title"),description:a("logs.toast.exportError.desc",{message:d.message}),variant:"error"})}finally{i(!1)}}},[s,t,o,l,a,p]);return{exporting:t,handleExport:y}}function et(){const s=x.useRef(null),[l,p]=x.useState(!1),a=x.useCallback(()=>{const o=s.current;if(!o)return;const t=o.scrollWidth-o.scrollLeft-o.clientWidth>1;p(t)},[]);return x.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}}function st(){const[s,l]=$(q.logs.density,Us,{serialize:v=>v,deserialize:v=>v==="compact"?"compact":"comfortable"}),[p,a]=$(q.logs.visibleColumns,J,{serialize:JSON.stringify,deserialize:v=>{try{const u=JSON.parse(v);if(!Array.isArray(u))return J;const N=u.filter(f=>oe.includes(f));return N.length>0?N:J}catch{return J}}}),{scrollRef:o,showScrollHint:t}=et(),i=x.useMemo(()=>new Set(p),[p]),y=p.length+2,b=x.useCallback(v=>{a(u=>{if(u.includes(v))return u.length===1?u:u.filter(f=>f!==v);const N=[...u,v];return N.sort((f,w)=>oe.indexOf(f)-oe.indexOf(w)),N})},[]);return{resetVisibleColumns:x.useCallback(()=>{a(J)},[]),rowDensity:s,setRowDensity:l,showScrollHint:t,tableScrollRef:o,toggleColumn:b,visibleColumnCount:y,visibleColumns:p,visibleColumnSet:i}}function tt(){var Ne,we,ke,Se,Ce;const{t:s}=O(),{pushToast:l}=ge(),p=Os(),[a,o]=$(q.logs.providerFilter,"all"),[t,i]=$(q.logs.endpointFilter,"all"),[y,b]=$(q.logs.modelFilter,""),[d,v]=$(q.logs.statusFilter,"all"),[u,N]=$(q.logs.fromDate,""),[f,w]=$(q.logs.toDate,""),[r,h]=x.useState(1),[L,g]=$(q.logs.pageSize,Hs,{serialize:m=>String(m),deserialize:m=>{const S=Number(m);return Z.includes(S)?S:Z[0]}}),[j,k]=x.useState(null),[n,C]=x.useState(!1),[D,F]=x.useState(null),[_,c]=$(q.logs.selectedApiKeys,[],{serialize:JSON.stringify,deserialize:m=>{try{const S=JSON.parse(m);return Array.isArray(S)?S.map(P=>Number(P)).filter(P=>Number.isInteger(P)&&P>0):[]}catch{return[]}}}),[z,Ae]=x.useState(!0),{resetVisibleColumns:Oe,rowDensity:Ie,setRowDensity:$e,showScrollHint:Qe,tableScrollRef:Ve,toggleColumn:Ue,visibleColumnCount:He,visibleColumns:Be,visibleColumnSet:We}=st(),Ge=x.useDeferredValue(y),T=y===""?"":Ge;x.useEffect(()=>{h(1),F(null)},[a,t,T,d,u,f,L,_]);const ne=x.useMemo(()=>{const m={limit:L,offset:(r-1)*L};a!=="all"&&(m.provider=a),t!=="all"&&(m.endpoint=t),T.trim().length>0&&(m.model=T.trim()),d!=="all"&&(m.status=d);const S=_e(u),P=_e(f,!0);return S!==void 0&&(m.from=S),P!==void 0&&(m.to=P),_.length>0&&(m.apiKeys=_.join(",")),m},[T,t,u,r,L,a,_,d,f]),U=G(H.logs.list(ne),ye.listRequest(ne),{gcTime:6e4}),W=G(H.providers.all(),Le.providersRequest()),be=G(H.apiKeys.all(),{url:"/api/keys",method:"GET"}),ie=G(H.customEndpoints.all(),{url:"/api/custom-endpoints",method:"GET"}),je=G(H.config.exportTimeout(),Le.configRequest());x.useEffect(()=>{!U.isError||!U.error||l({title:s("logs.toast.listError.title"),description:s("logs.toast.listError.desc",{message:U.error.message}),variant:"error"})},[U.error,U.isError,l,s]),x.useEffect(()=>{!W.isError||!W.error||l({title:s("logs.toast.providerError.title"),description:s("logs.toast.providerError.desc",{message:W.error.message}),variant:"error"})},[W.error,W.isError,l,s]);const se=((Ne=U.data)==null?void 0:Ne.total)??0,Y=se>0?Math.ceil(se/L):0,Je=((we=U.data)==null?void 0:we.items)??[],Ze=x.useMemo(()=>{var S;const m=(S=je.data)==null?void 0:S.logExportTimeoutSeconds;return typeof m=="number"&&Number.isFinite(m)?Math.min(Math.max(Math.round(m),5),600)*1e3:6e4},[(ke=je.data)==null?void 0:ke.logExportTimeoutSeconds]);x.useEffect(()=>{Y>0&&r>Y&&h(Y)},[r,Y]);const de=W.data??[],ce=x.useMemo(()=>{const m=new Map;for(const S of de)S.id&&m.set(S.id,S.label??S.id);return m},[de]),ve=x.useMemo(()=>{var S;const m=new Map;m.set("anthropic",s("logs.filters.endpointAnthropic")),m.set("openai",s("logs.filters.endpointOpenAI"));for(const P of((S=ie.data)==null?void 0:S.endpoints)??[])m.set(P.id,P.label||P.id);return m},[(Se=ie.data)==null?void 0:Se.endpoints,s]),Xe=x.useMemo(()=>{const m=[];if(a!=="all"){const S=ce.get(a)??a;m.push({key:"provider",label:`${s("logs.filters.provider")}: ${S}`,onRemove:()=>o("all")})}if(t!=="all"){const S=ve.get(t)??t;m.push({key:"endpoint",label:`${s("logs.filters.endpoint")}: ${S}`,onRemove:()=>i("all")})}if(T.trim()&&m.push({key:"model",label:`${s("logs.filters.modelId")}: ${T.trim()}`,onRemove:()=>b("")}),d!=="all"){const S=s(d==="success"?"logs.filters.statusSuccess":"logs.filters.statusError");m.push({key:"status",label:`${s("logs.filters.status")}: ${S}`,onRemove:()=>v("all")})}return u&&m.push({key:"from",label:`${s("logs.filters.startDate")}: ${u}`,onRemove:()=>N("")}),f&&m.push({key:"to",label:`${s("logs.filters.endDate")}: ${f}`,onRemove:()=>w("")}),_.length>0&&m.push({key:"apiKeys",label:s("logs.filters.apiKeySelected",{count:_.length}),onRemove:()=>c([])}),m},[T,t,ve,u,a,ce,_.length,d,s,f]),me=be.data??[],Ye=x.useMemo(()=>{const m=new Map;for(const S of me)m.set(S.id,S);return m},[me]),es=x.useMemo(()=>oe.map(m=>({id:m,label:s(`logs.table.columns.${m}`)})),[s]),ee=x.useMemo(()=>{const m=new Date;return`${m.getFullYear()}-${String(m.getMonth()+1).padStart(2,"0")}-${String(m.getDate()).padStart(2,"0")}`},[]),ss=x.useMemo(()=>a==="all"&&t==="all"&&T.trim()===""&&d==="all"&&u===""&&f===""&&_.length===0?"all":d==="error"&&t==="all"&&a==="all"&&T.trim()===""&&u===""&&f===""&&_.length===0?"errors":Bs(u,f,ee)&&t==="all"&&a==="all"&&T.trim()===""&&d==="all"&&_.length===0?"today":t==="anthropic"&&a==="all"&&T.trim()===""&&d==="all"&&u===""&&f===""&&_.length===0?"anthropic":t==="openai"&&a==="all"&&T.trim()===""&&d==="all"&&u===""&&f===""&&_.length===0?"openai":null,[T,t,u,a,_.length,d,f,ee]),ue=x.useCallback(()=>{o("all"),b(""),i("all"),v("all"),N(""),w(""),c([])},[]),ts=x.useCallback(m=>{if(h(1),ue(),m!=="all"){if(m==="errors"){v("error");return}if(m==="today"){N(ee),w(ee);return}if(m==="anthropic"){i("anthropic");return}m==="openai"&&i("openai")}},[ue,ee]),{exporting:ls,handleExport:as}=Ys({exportTimeoutMs:Ze,queryParams:ne,total:se}),rs=x.useCallback(m=>{p.removeQueries({queryKey:["logs","detail"],type:"inactive"}),k(m),C(!0)},[p]),os=x.useCallback(()=>{C(!1)},[]),ns=x.useCallback(m=>{F(S=>S===m?null:m)},[]);return x.useEffect(()=>{n||j===null||(p.removeQueries({queryKey:H.logs.detail(j),exact:!0}),k(null))},[n,p,j]),{activeFilters:Xe,activeQuickView:ss,apiKeyMap:Ye,apiKeys:me,apiKeysQuery:be,applyQuickView:ts,columnOptions:es,customEndpoints:(Ce=ie.data)==null?void 0:Ce.endpoints,endpointFilter:t,exporting:ls,expandedLogId:D,filtersExpanded:z,fromDate:u,handleCloseDetail:os,handleExport:as,handleOpenDetail:rs,handleResetFilters:ue,handleToggleExpand:ns,isDetailOpen:n,items:Je,logsQuery:U,modelFilter:y,page:r,pageSize:L,providerFilter:a,providerLabelMap:ce,providerOptions:de,rowDensity:Ie,resetVisibleColumns:Oe,selectedApiKeys:_,selectedLogId:j,setEndpointFilter:i,setFiltersExpanded:Ae,setFromDate:N,setModelFilter:b,setPage:h,setPageSize:g,setProviderFilter:o,setRowDensity:$e,setSelectedApiKeys:c,setStatusFilter:v,setToDate:w,showScrollHint:Qe,statusFilter:d,tableScrollRef:Ve,toDate:f,toggleColumn:Ue,total:se,totalPages:Y,visibleColumnCount:He,visibleColumns:Be,visibleColumnSet:We}}function wt(){var l;const s=tt();return e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsx(hs,{actions:e.jsx(Ws,{columnOptions:s.columnOptions,exporting:s.exporting,onExport:()=>void s.handleExport(),onRefresh:()=>void s.logsQuery.refetch(),onResetColumns:s.resetVisibleColumns,onSetDensity:s.setRowDensity,onToggleColumn:s.toggleColumn,refreshing:s.logsQuery.isFetching,rowDensity:s.rowDensity,visibleColumns:s.visibleColumns,visibleColumnSet:s.visibleColumnSet})}),e.jsx($s,{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,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(Xs,{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,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(Qs,{open:s.isDetailOpen,logId:s.selectedLogId,onClose:s.handleCloseDetail,providerLabelMap:s.providerLabelMap,apiKeyMap:s.apiKeyMap})]})}export{wt as default};
|
|
1
|
+
import{r as x,j as e,o as is,ar as ds,aj as cs,as as ms,ak as Re,at as De,aq as us,au as ps,Z as xs,T as gs,P as fs}from"./vendor-CITafuNQ.js";import{P as hs}from"./PageToolbar-CWw40AFL.js";import{c as E}from"./global-BCehxTGJ.js";import{B as R,d as ys,a as ge,c as G,q as H,s as q,t as bs,b as $}from"./app-vWIA9Pq_.js";import{B as V}from"./badge-DpUlf_NW.js";import{C as Fe,a as Te}from"./card-D4YOc5eB.js";import{L as B,I as pe}from"./label-DSVzZIex.js";import{S as te,a as le,b as ae,c as re,d as I}from"./select-sOwKYsgI.js";import{u as O}from"./i18n-PeX9kBVO.js";import{D as js,A as vs,a as Ns,b as ws,c as ks,d as Ss}from"./DialogShell-CM92wXHo.js";import{P as Cs,a as X}from"./PageState-CFLrRswm.js";import{T as Ls,a as _s,b as Es,c as Rs}from"./tabs-UWyz9J_W.js";import{c as Ds}from"./clipboard-BnAnBk_-.js";import{a as Fs,g as fe,b as Ke,f as A,c as he,d as Ts,e as M,h as Me,i as Pe,j as Ks,T as Ms}from"./utils-B_Q3Hhgb.js";import{P as Ps,a as qs,b as zs}from"./popover-QZXvcPr8.js";import{S as As}from"./segmented-control-13KTib6k.js";import{L as qe}from"./router-BoBrmro7.js";import{a as Os}from"./query-DZF7K6hv.js";import{g as Le}from"./gateway-B7Y2AqSU.js";import"./radix-Bux_1C5J.js";function Is({apiKeys:s,selected:l,onChange:p,disabled:a,className:o}){const{t}=O(),i=x.useId(),[y,b]=x.useState(!1),[d,v]=x.useState(null),u=x.useRef(null),N=x.useRef(null),f=x.useRef(null),w=()=>{const g=N.current;if(!g)return;const j=g.getBoundingClientRect(),k=Math.max(j.width,256),n=window.innerWidth-12;v({left:Math.min(j.left,n-k),top:j.bottom+8,width:k})};x.useEffect(()=>{if(!y)return;const g=k=>{var C,D;const n=k.target;!((C=u.current)!=null&&C.contains(n))&&!((D=f.current)!=null&&D.contains(n))&&b(!1)},j=k=>{var n;k.key==="Escape"&&(b(!1),(n=N.current)==null||n.focus())};return window.addEventListener("mousedown",g),window.addEventListener("keydown",j),()=>{window.removeEventListener("mousedown",g),window.removeEventListener("keydown",j)}},[y]),x.useEffect(()=>{if(y)return w(),window.addEventListener("resize",w),window.addEventListener("scroll",w,!0),()=>{window.removeEventListener("resize",w),window.removeEventListener("scroll",w,!0)}},[y]);const r=x.useMemo(()=>{if(l.length===0)return[];const g=new Map;for(const j of s)g.set(j.id,j);return l.map(j=>{const k=g.get(j);return k?k.isWildcard?t("apiKeys.wildcard"):k.name:null}).filter(j=>!!j)},[s,l,t]),h=l.length===0?t("logs.filters.apiKeyAll"):t("logs.filters.apiKeySelected",{count:l.length}),L=g=>{l.includes(g)?p(l.filter(j=>j!==g)):p([...l,g])};return e.jsxs("div",{className:E("relative space-y-2",o),ref:u,children:[e.jsx(B,{htmlFor:i,children:t("logs.filters.apiKey")}),e.jsxs("button",{ref:N,id:i,type:"button",onClick:()=>{w(),b(g=>!g)},disabled:a||s.length===0,title:t("logs.filters.apiKeyHint"),className:E("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-primary",y&&"ring-2 ring-ring ring-offset-2"),children:[e.jsxs("span",{className:"truncate",children:[h,r.length>0&&e.jsx("span",{className:"ml-1 text-xs text-muted-foreground",children:r.join(", ")})]}),e.jsx("svg",{className:E("h-4 w-4 opacity-50 transition-transform",y&&"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"})})]}),y&&d&&is.createPortal(e.jsxs("div",{ref:f,className:"fixed z-50 rounded-lg border bg-popover p-2 shadow-[var(--surface-shadow-lg)]",style:d,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:h}),e.jsx("button",{type:"button",onClick:()=>p([]),disabled:l.length===0,className:"text-primary hover:underline disabled:opacity-40",children:t("common.actions.reset")})]}),e.jsxs("div",{className:"max-h-56 overflow-y-auto py-2",children:[s.map(g=>{const j=g.isWildcard?t("apiKeys.wildcard"):g.name,k=l.includes(g.id);return e.jsxs("label",{className:E("flex cursor-pointer items-center gap-3 rounded-xl px-3 py-2 text-sm transition hover:bg-primary/5",k&&"bg-primary/10 text-primary"),children:[e.jsx("input",{type:"checkbox",className:"h-4 w-4 rounded border-border",checked:k,onChange:()=>L(g.id)}),e.jsx("span",{className:"truncate",children:j})]},g.id)}),s.length===0&&e.jsx("p",{className:"px-2 py-2 text-xs text-muted-foreground",children:t("logs.filters.apiKeyAll")})]})]}),document.body)]})}function $s(s){const{t:l}=O(),{activeFilters:p,filtersExpanded:a,setFiltersExpanded:o,handleResetFilters:t,activeQuickView:i,applyQuickView:y,providerFilter:b,setProviderFilter:d,endpointFilter:v,setEndpointFilter:u,selectedApiKeys:N,setSelectedApiKeys:f,modelFilter:w,setModelFilter:r,statusFilter:h,setStatusFilter:L,fromDate:g,setFromDate:j,toDate:k,setToDate:n,providerOptions:C,apiKeys:D,apiKeysLoading:F,customEndpoints:_}=s;return e.jsx(Fe,{"data-testid":"logs-filters-card",className:"overflow-hidden",children:e.jsxs(Te,{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")}),p.length>0&&e.jsx(V,{variant:"outline",className:"rounded-full border-transparent bg-primary/10 px-2.5 py-0.5 text-[11px] font-semibold text-primary",children:l("common.filters.activeCount",{count:p.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:[p.length>0&&e.jsx(R,{variant:"ghost",size:"sm",onClick:t,className:"h-8 rounded-full px-3 text-xs",children:l("common.actions.reset")}),e.jsx(R,{variant:"ghost",size:"sm",onClick:()=>o(c=>!c),className:"h-8 rounded-full px-3 text-xs",children:a?e.jsxs(e.Fragment,{children:[l("common.filters.collapse"),e.jsx(ds,{className:"ml-1 h-4 w-4"})]}):e.jsxs(e.Fragment,{children:[l("common.filters.expand"),e.jsx(cs,{className:"ml-1 h-4 w-4"})]})})]})]}),e.jsxs("div",{className:"grid gap-2 lg:grid-cols-[minmax(0,1fr)_auto]",children:[e.jsx("div",{className:"flex min-h-10 items-center rounded-lg bg-secondary px-3 py-2",children:p.length>0?e.jsx("div",{className:"flex flex-wrap items-center gap-2",children:p.map(c=>e.jsxs(V,{variant:"outline",role:"button",tabIndex:0,className:"flex cursor-pointer items-center gap-1 rounded-full border border-border bg-card px-2.5 py-1 text-[11px] font-semibold text-foreground/90 transition hover:bg-secondary",onClick:c.onRemove,onKeyDown:z=>{(z.key==="Enter"||z.key===" ")&&(z.preventDefault(),c.onRemove())},children:[c.label,e.jsx(ms,{className:"h-3 w-3","aria-hidden":"true"})]},c.key))}):e.jsx("span",{className:"text-xs text-muted-foreground",children:l("common.filters.allRequests")})}),e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 lg:justify-end",children:[e.jsx(xe,{label:l("logs.filters.apiKey"),value:N.length.toString()}),e.jsx(xe,{label:l("logs.filters.provider"),value:b==="all"?"0":"1"}),e.jsx(xe,{label:l("logs.filters.endpoint"),value:v==="all"?"0":"1"})]})]}),e.jsx("div",{className:"flex flex-wrap items-center gap-1.5 rounded-lg bg-secondary px-2 py-1.5",children:["all","errors","today","anthropic","openai"].map(c=>e.jsx(R,{variant:"ghost",size:"sm",className:E("h-7 rounded-full px-3 text-[11px] font-semibold transition-colors",i===c?"bg-card text-foreground shadow-[var(--surface-shadow)]":"text-muted-foreground"),onClick:()=>y(c),children:l(`logs.quickViews.${c}`)},c))})]}),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(B,{children:l("logs.filters.provider")}),e.jsxs(te,{value:b,onValueChange:d,children:[e.jsx(le,{children:e.jsx(ae,{})}),e.jsxs(re,{children:[e.jsx(I,{value:"all",children:l("logs.filters.providerAll")}),C.map(c=>e.jsx(I,{value:c.id,children:c.label??c.id},c.id))]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(B,{children:l("logs.filters.endpoint")}),e.jsxs(te,{value:v,onValueChange:u,children:[e.jsx(le,{children:e.jsx(ae,{})}),e.jsxs(re,{children:[e.jsx(I,{value:"all",children:l("logs.filters.endpointAll")}),e.jsx(I,{value:"anthropic",children:l("logs.filters.endpointAnthropic")}),e.jsx(I,{value:"openai",children:l("logs.filters.endpointOpenAI")}),_==null?void 0:_.map(c=>e.jsx(I,{value:c.id,children:c.label||c.id},c.id))]})]})]}),e.jsx(Is,{className:"md:col-span-2",apiKeys:D,selected:N,disabled:F,onChange:f}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(B,{children:l("logs.filters.modelId")}),e.jsx(pe,{value:w,onChange:c=>r(c.target.value),placeholder:l("logs.filters.modelPlaceholder")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(B,{children:l("logs.filters.status")}),e.jsxs(te,{value:h,onValueChange:c=>L(c),children:[e.jsx(le,{children:e.jsx(ae,{})}),e.jsxs(re,{children:[e.jsx(I,{value:"all",children:l("logs.filters.statusAll")}),e.jsx(I,{value:"success",children:l("logs.filters.statusSuccess")}),e.jsx(I,{value:"error",children:l("logs.filters.statusError")})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(B,{children:l("logs.filters.startDate")}),e.jsx(pe,{type:"date",value:g,onChange:c=>j(c.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(B,{children:l("logs.filters.endDate")}),e.jsx(pe,{type:"date",value:k,onChange:c=>n(c.target.value)})]})]})]})})}function xe({label:s,value:l}){return e.jsxs("div",{className:"inline-flex items-center gap-1.5 rounded-full border border-border/60 bg-card px-2.5 py-1 text-[11px] text-muted-foreground",children:[e.jsx("span",{children:s}),e.jsx("span",{className:"metric-number font-semibold text-foreground",children:l})]})}const ye={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 p=await ys.post("/api/logs/export",s,{responseType:"blob",timeout:l});return new Blob([p.data],{type:"application/zip"})}};function ze({apiKeyMap:s,logId:l,open:p,providerLabelMap:a}){var w;const{t:o}=O(),{pushToast:t}=ge(),i=G(H.logs.detail(l),ye.detailRequest(l),{enabled:p&&l!==null,staleTime:3e4,gcTime:15e3,placeholderData:void 0});x.useEffect(()=>{!i.isError||!i.error||t({title:o("logs.detail.loadError"),description:i.error.message,variant:"error"})},[i.error,i.isError,t,o]);const y=x.useCallback(async(r,h,L)=>{if(!h){t({title:o("logs.detail.copy.empty",{label:r}),variant:"info"});return}try{await Ds(h),t({title:o(L),variant:"success"})}catch(g){t({title:o("logs.detail.copy.failure"),description:g instanceof Error?g.message:o("logs.detail.copy.failureFallback"),variant:"error"})}},[t,o]),b=x.useCallback((r,h)=>{if(!h){t({title:o("logs.detail.copy.empty",{label:r}),variant:"info"});return}const L=new Blob([h],{type:"application/json;charset=utf-8"}),g=URL.createObjectURL(L),j=document.createElement("a"),k=new Date().toISOString().replace(/[:.]/g,"-"),n=r.trim().toLowerCase().replace(/[^a-z0-9\u4e00-\u9fa5]+/gi,"-").replace(/^-+|-+$/g,"")||"payload";j.href=g,j.download=`cc-gw-log-${l??"payload"}-${n}-${k}.json`,document.body.appendChild(j),j.click(),document.body.removeChild(j),URL.revokeObjectURL(g)},[l,t,o]),d=i.data,v=d?a.get(d.provider)??d.provider:"",u=d&&d.api_key_id!=null?s.get(d.api_key_id):void 0,N=d?Fs(d,o):null,f=d?fe(d,o):null;return{apiKeyMeta:u,errorSourceMeta:N,errorMessage:i.isError?((w=i.error)==null?void 0:w.message)??null:null,handleCopy:y,handleDownloadPayload:b,isError:i.isError,isPending:i.isPending,providerLabel:v,refetch:i.refetch,record:d,statusMeta:f}}function Qs({open:s,logId:l,onClose:p,providerLabelMap:a,apiKeyMap:o}){var g,j,k;const{t}=O(),{apiKeyMeta:i,errorSourceMeta:y,errorMessage:b,handleCopy:d,handleDownloadPayload:v,isError:u,isPending:N,providerLabel:f,refetch:w,record:r,statusMeta:h}=ze({apiKeyMap:o,logId:l,open:s,providerLabelMap:a}),L=x.useMemo(()=>{var C,D,F,_;return r?[{key:"client-request",title:t("logs.detail.payload.clientRequest"),value:((C=r.payload)==null?void 0:C.client_request)??null,emptyLabel:t("logs.detail.payload.emptyRequest"),copyToast:"logs.detail.copy.requestSuccess"},...(D=r.payload)!=null&&D.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"}]:[],...(F=r.payload)!=null&&F.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:((_=r.payload)==null?void 0:_.client_response)??null,emptyLabel:t("logs.detail.payload.emptyResponse"),copyToast:"logs.detail.copy.responseSuccess"}].map(c=>({...c,display:Ke(c.value,c.emptyLabel)})):[]},[r,t]);return e.jsx(js,{open:s,onOpenChange:n=>{n||p()},children:e.jsxs(vs,{className:"w-[min(96vw,1200px)] max-w-[1200px]",children:[e.jsxs(Ns,{className:"pr-14",children:[e.jsx(ws,{children:t("logs.detail.title")}),e.jsx(ks,{children:r?t("logs.detail.id",{id:r.id}):t("logs.detail.loadError")})]}),e.jsx(Ss,{className:"max-h-[78vh]",children:N?e.jsx(Cs,{compact:!0,className:"min-h-[240px]",label:t("common.loading")}):u?e.jsx(X,{compact:!0,className:"min-h-[240px]",tone:"danger",title:t("logs.detail.loadError"),description:b??t("common.unknownError"),action:e.jsx(R,{variant:"outline",onClick:()=>void w(),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.jsxs("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.jsx("span",{className:"text-muted-foreground",children:t("logs.detail.summary.latency",{value:A(r.latency_ms,t("common.units.ms"))})}),r.ttft_ms!==null?e.jsxs("span",{className:"text-muted-foreground",children:["TTFT: ",A(r.ttft_ms,t("common.units.ms"))]}):null]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(V,{variant:h==null?void 0:h.variant,children:(h==null?void 0:h.label)??"-"}),e.jsx(V,{variant:"outline",children:r.stream?t("logs.stream.streaming"):t("logs.stream.single")})]})]}),e.jsxs("div",{className:"grid gap-3 md:grid-cols-5",children:[e.jsx(Q,{label:t("logs.detail.info.latency"),value:A(r.latency_ms,t("common.units.ms"))}),e.jsx(Q,{label:t("logs.detail.info.ttft"),value:A(r.ttft_ms,t("common.units.ms"))}),e.jsx(Q,{label:t("logs.detail.info.tpot"),value:A(r.tpot_ms,t("common.units.msPerToken"))}),e.jsx(Q,{label:t("logs.detail.info.status"),value:(h==null?void 0:h.label)??"-"}),e.jsx(Q,{label:t("logs.detail.info.errorSource"),value:(y==null?void 0:y.label)??"-"})]}),e.jsxs("dl",{className:"grid gap-x-4 gap-y-3 md:grid-cols-2 xl:grid-cols-4",children:[e.jsx(K,{label:t("logs.detail.info.time"),value:he(r.timestamp)}),e.jsx(K,{label:t("logs.detail.info.sessionId"),value:r.session_id??"-"}),e.jsx(K,{label:t("logs.detail.info.endpoint"),value:r.endpoint||"-"}),e.jsx(K,{label:t("logs.detail.info.provider"),value:f}),e.jsx(K,{label:t("logs.detail.info.requestedModel"),value:r.client_model??t("logs.detail.info.noRequestedModel")}),e.jsx(K,{label:t("logs.detail.info.model"),value:r.model}),e.jsx(K,{label:t("logs.detail.info.stream"),value:Ts(r.stream)}),e.jsx(K,{label:t("logs.detail.info.status"),value:(h==null?void 0:h.label)??"-"}),e.jsx(K,{label:t("logs.detail.info.errorSource"),value:(y==null?void 0:y.label)??"-"})]}),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:M(r.input_tokens)}),e.jsx(Q,{label:t("logs.detail.info.cacheReadTokens"),value:M(r.cache_read_tokens)}),e.jsx(Q,{label:t("logs.detail.info.cacheCreationTokens"),value:M(r.cache_creation_tokens)}),e.jsx(Q,{label:t("logs.detail.info.outputTokens"),value:M(r.output_tokens)})]}),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]}),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(K,{label:t("logs.detail.apiKey.name"),value:r.api_key_id==null&&!r.api_key_name?t("logs.detail.apiKey.missing"):i!=null&&i.isWildcard?t("apiKeys.wildcard"):(i==null?void 0:i.name)??r.api_key_name??t("logs.detail.apiKey.missing")}),e.jsx(K,{label:t("logs.detail.apiKey.identifier"),value:r.api_key_id??t("common.noData")}),e.jsx(K,{label:t("logs.detail.apiKey.masked"),value:i!=null&&i.isWildcard?t("apiKeys.wildcard"):(i==null?void 0:i.maskedKey)??r.api_key_name??t("logs.detail.apiKey.maskedUnavailable")}),e.jsx(K,{label:t("logs.detail.apiKey.lastUsed"),value:i!=null&&i.lastUsedAt?new Date(i.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:(g=r.payload)!=null&&g.upstream_request||(j=r.payload)!=null&&j.upstream_response?t("logs.detail.payload.helperWithUpstream"):t("logs.detail.payload.helperClientOnly")})]}),e.jsxs(Ls,{defaultValue:(k=L[0])==null?void 0:k.key,children:[e.jsx(_s,{className:"w-full justify-start overflow-x-auto",children:L.map(n=>e.jsx(Es,{value:n.key,children:n.title},n.key))}),L.map(n=>e.jsx(Rs,{value:n.key,children:e.jsx(Vs,{title:n.title,display:n.display,onCopy:()=>d(n.title,n.value,n.copyToast),onDownload:()=>v(n.title,n.value),panelKey:n.key,t})},n.key))]})]})]})]}):e.jsx(X,{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 K({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 Vs({display:s,onCopy:l,onDownload:p,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(R,{variant:"outline",size:"sm",onClick:l,children:[e.jsx(Re,{className:"mr-2 h-3.5 w-3.5"}),t("common.actions.copy")]}),e.jsxs(R,{variant:"outline",size:"sm",onClick:p,children:[e.jsx(De,{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})]})}const Z=[20,50,100],J=["endpoint","provider","requestedModel","routedModel","apiKey","tokens","duration","status","error"],oe=["endpoint","provider","requestedModel","routedModel","apiKey","tokens","duration","status","error"];function Us(){return typeof window>"u"?"comfortable":window.localStorage.getItem(q.logs.density)==="compact"?"compact":"comfortable"}function Hs(){if(typeof window>"u")return Z[0];const s=window.localStorage.getItem(q.logs.pageSize),l=Number(s);return Z.includes(l)?l:Z[0]}function _e(s,l=!1){if(!s)return;const p=l?`${s}T23:59:59.999`:`${s}T00:00:00.000`,a=Date.parse(p);return Number.isFinite(a)?a:void 0}function Bs(s,l,p){return s===p&&l===p}function Ws({columnOptions:s,exporting:l,onExport:p,onRefresh:a,onResetColumns:o,onSetDensity:t,onToggleColumn:i,refreshing:y,rowDensity:b,visibleColumns:d,visibleColumnSet:v}){const{t:u}=O(),N=JSON.stringify(d)===JSON.stringify(J);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.jsx(As,{block:!0,className:"w-full overflow-x-auto sm:w-auto",value:b,onChange:t,options:[{value:"comfortable",label:u("logs.table.density.comfortable")},{value:"compact",label:u("logs.table.density.compact")}]}),e.jsxs(Ps,{children:[e.jsx(qs,{asChild:!0,children:e.jsx(R,{variant:"outline",size:"sm",className:"w-full sm:w-auto",children:u("logs.actions.columns")})}),e.jsxs(zs,{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:u("logs.actions.columns")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:u("logs.actions.visibleCount",{count:d.length})})]}),e.jsx(R,{variant:"ghost",size:"sm",onClick:o,disabled:N,children:u("common.actions.reset")})]}),e.jsx("div",{className:"grid gap-1.5",children:s.map(f=>{const w=v.has(f.id);return e.jsxs("label",{className:E("flex cursor-pointer items-center gap-3 rounded-xl px-3 py-2 text-sm transition hover:bg-accent",w&&"bg-primary/10 text-primary"),children:[e.jsx("input",{type:"checkbox",checked:w,onChange:()=>i(f.id),className:"h-4 w-4 rounded border-border"}),e.jsx("span",{children:f.label})]},f.id)})})]})]}),e.jsxs(R,{onClick:p,disabled:l,className:"w-full sm:w-auto",children:[e.jsx(De,{className:"mr-2 h-4 w-4"}),u(l?"logs.actions.exporting":"logs.actions.export")]})]}),e.jsx("div",{className:"flex w-full items-center xl:w-auto",children:e.jsxs(R,{variant:"outline",size:"sm",onClick:a,disabled:y,className:"shrink-0",children:[e.jsx(us,{className:E("mr-2 h-4 w-4",y&&"animate-spin")}),u(y?"common.actions.refreshing":"logs.actions.manualRefresh")]})})]})}function Gs({record:s,providerLabelMap:l,onSelect:p}){const{t:a}=O(),o=fe(s,a),t=l.get(s.provider)??s.provider,i=Me(s.session_id),y=i==null?void 0:i.accentStyle;return e.jsxs("button",{type:"button","data-session-id":i==null?void 0:i.sessionId,"data-session-color":i==null?void 0:i.colorKey,style:y,onClick:()=>p(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:he(s.timestamp)}),e.jsx(V,{variant:o.variant,className:"text-xs",children:o.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:t,children:t}),e.jsx("span",{className:"min-w-0 truncate text-muted-foreground",title:s.model,children:s.model})]}),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:A(s.latency_ms,a("common.units.ms"))}),s.ttft_ms!=null?e.jsxs("span",{children:[a("logs.table.columns.latencyTtft")," ",M(s.ttft_ms)]}):null]})]})}const Ee={accent:"bg-primary",ok:"bg-success",warn:"bg-warning",error:"bg-destructive"};function Js({logId:s,providerLabelMap:l,apiKeyMap:p}){const{t:a}=O(),{record:o,isPending:t,isError:i,errorMessage:y,statusMeta:b,providerLabel:d,handleCopy:v,refetch:u}=ze({apiKeyMap:p,logId:s,open:!0,providerLabelMap:l}),N=x.useMemo(()=>{var C,D,F,_;if(!o)return[];const n=[{key:"client-request",title:a("logs.detail.payload.clientRequest"),value:((C=o.payload)==null?void 0:C.client_request)??null,emptyLabel:a("logs.detail.payload.emptyRequest"),copyToast:"logs.detail.copy.requestSuccess"}];return(D=o.payload)!=null&&D.upstream_request&&n.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"}),(F=o.payload)!=null&&F.upstream_response&&n.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"}),n.push({key:"client-response",title:a("logs.detail.payload.clientResponse"),value:((_=o.payload)==null?void 0:_.client_response)??null,emptyLabel:a("logs.detail.payload.emptyResponse"),copyToast:"logs.detail.copy.responseSuccess"}),n.map(c=>({...c,display:Ke(c.value,c.emptyLabel)}))},[o,a]),[f,w]=x.useState("client-request"),r=N.find(n=>n.key===f)??N[0];if(t)return e.jsx("div",{className:"py-3",children:e.jsx(Pe,{className:"h-28 w-full"})});if(i)return e.jsx(X,{compact:!0,tone:"danger",title:a("logs.detail.loadError"),description:y??a("common.unknownError"),action:e.jsx(R,{variant:"outline",size:"sm",onClick:()=>void u(),children:a("common.actions.refresh")})});if(!o)return e.jsx(X,{compact:!0,title:a("logs.detail.loadError"),description:a("common.noData")});const h=Ks(o,d,a),L=a("common.units.ms"),g=[{label:a("logs.detail.info.status"),value:(b==null?void 0:b.label)??"-"},{label:a("logs.detail.info.latency"),value:A(o.latency_ms,L)},{label:a("logs.detail.info.ttft"),value:A(o.ttft_ms,L)},{label:a("logs.detail.info.inputTokens"),value:M(o.input_tokens)},{label:a("logs.detail.info.outputTokens"),value:M(o.output_tokens)},{label:a("logs.detail.info.cacheReadTokens"),value:M(o.cache_read_tokens)}],j=o.ttft_ms!=null,k=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:h.map((n,C)=>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:E("mt-1 h-[9px] w-[9px] rounded-full",Ee[n.tone])}),C<h.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:n.title}),n.atLabel?e.jsx("span",{className:"text-[10.5px] tabular-nums text-muted-foreground",children:n.atLabel}):null,n.durLabel?e.jsx("span",{className:"ml-auto text-[10.5px] tabular-nums text-muted-foreground",children:n.durLabel}):null]}),n.detail?e.jsx("div",{className:"mt-1 text-[11px] leading-[1.55] text-muted-foreground",children:n.detail}):null,e.jsx("div",{className:"mt-1.5 h-1 w-full max-w-[220px] bg-secondary",children:e.jsx("div",{className:E("h-full",Ee[n.tone]),style:{width:`${n.barPct}%`}})})]})]},n.id))}),j?null:e.jsx("p",{className:"mt-1 text-[10.5px] text-muted-foreground/70",children:a("logs.detail.trace.degraded")})]}),e.jsxs("div",{className:"flex min-w-0 flex-col gap-3",children:[e.jsx("div",{className:"grid grid-cols-3 gap-2",children:g.map(n=>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:n.label}),e.jsx("div",{className:"mt-0.5 text-[13px] font-semibold tabular-nums",children:n.value})]},n.label))}),e.jsxs("div",{className:"border border-border bg-card",children:[e.jsx("div",{className:"flex gap-0.5 border-b border-border bg-secondary/50 p-1.5",role:"tablist",children:N.map(n=>{const C=n.key===(r==null?void 0:r.key);return e.jsx("button",{type:"button",role:"tab","aria-selected":C,onClick:()=>w(n.key),className:E("px-2.5 py-1 text-[10.5px] font-medium transition-colors",C?"bg-card text-foreground":"text-muted-foreground hover:text-foreground"),children:n.title},n.key)})}),e.jsx("pre",{"data-testid":`log-payload-${(r==null?void 0:r.key)??"none"}`,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:(r==null?void 0:r.display.text)||a("logs.detail.payload.emptyRequest")})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs(R,{variant:"outline",size:"sm",className:"h-[30px] flex-1",onClick:()=>{r&&v(r.title,r.value,r.copyToast)},children:[e.jsx(Re,{className:"mr-1.5 h-3.5 w-3.5","aria-hidden":"true"}),a("logs.detail.inline.copyRequest")]}),k?e.jsx(R,{variant:"outline",size:"sm",className:"h-[30px] flex-1",onClick:()=>v(a("logs.detail.inline.copySession"),k,"logs.detail.inline.sessionCopied"),children:a("logs.detail.inline.copySession")}):null,e.jsx(R,{asChild:!0,variant:"outline",size:"sm",className:"h-[30px] flex-1",children:e.jsxs(qe,{to:"/providers?tab=routing",children:[a("logs.detail.inline.viewRule"),e.jsx(ps,{className:"ml-1.5 h-3.5 w-3.5","aria-hidden":"true"})]})})]})]})]})}function Zs({record:s,providerLabelMap:l,apiKeyMap:p,onSelect:a,isExpanded:o,onToggleExpand:t,isEven:i,density:y,visibleColumnSet:b}){const{t:d}=O(),v=l.get(s.provider)??s.provider,u=s.endpoint||"-",N=fe(s,d),f=s.client_model??d("logs.table.requestedModelFallback"),w=s.api_key_id!=null?p.get(s.api_key_id):void 0,r=s.api_key_id==null?d("logs.table.apiKeyUnknown"):w!=null&&w.isWildcard?d("apiKeys.wildcard"):w!=null&&w.name?w.name:s.api_key_name?s.api_key_name:d("logs.table.apiKeyUnknown"),h=y==="compact"?"px-3 py-1.5":"px-3 py-2",L=i?"bg-muted/30":"bg-background",g=Me(s.session_id),j=g==null?void 0:g.accentStyle,k=b.size+2,n=d(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":g==null?void 0:g.sessionId,"data-session-color":g==null?void 0:g.colorKey,className:E("transition-colors duration-160 ease-surface",i?"bg-muted/30":"",o?"bg-muted/50":"hover:bg-muted/50"),children:[e.jsx("td",{className:E("sticky left-0 z-10 text-xs",h,L),style:j,children:e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("button",{type:"button","aria-expanded":o,"aria-label":n,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(xs,{className:E("h-3.5 w-3.5 transition-transform duration-160 ease-surface",o&&"rotate-90"),"aria-hidden":"true"})}),e.jsx("span",{className:"metric-number",children:he(s.timestamp)})]})}),b.has("endpoint")&&e.jsx("td",{className:E(h,"text-xs"),children:u}),b.has("provider")&&e.jsx("td",{className:E(h,"text-xs"),children:e.jsx("div",{className:"max-w-[100px] truncate",title:v,children:v})}),b.has("requestedModel")&&e.jsx("td",{className:E(h,"text-xs text-muted-foreground"),children:e.jsx("div",{className:"max-w-[120px] truncate",title:f,children:f})}),b.has("routedModel")&&e.jsx("td",{className:E(h,"text-xs"),children:e.jsx("div",{className:"max-w-[120px] truncate",title:s.model,children:s.model})}),b.has("apiKey")&&e.jsx("td",{className:E(h,"text-xs text-muted-foreground"),children:e.jsx("div",{className:"max-w-[90px] truncate",title:r,children:r})}),b.has("tokens")&&e.jsx("td",{className:E(h,"text-right text-xs tabular-nums align-top"),children:e.jsxs("span",{className:"inline-flex flex-col items-end gap-0.5",children:[e.jsxs("span",{className:"whitespace-nowrap",children:[d("logs.table.columns.tokenIn")," ",M(s.input_tokens),e.jsx("span",{className:"mx-1 text-muted-foreground/50",children:"·"}),d("logs.table.columns.tokenOut")," ",M(s.output_tokens)]}),(()=>{const C=(s.cache_read_tokens??0)+(s.cache_creation_tokens??0);return C>0?e.jsxs("span",{className:"whitespace-nowrap text-[11px] text-muted-foreground/70",children:[d("logs.table.columns.tokenCache")," ",M(C)]}):null})()]})}),b.has("duration")&&e.jsx("td",{className:E(h,"text-right text-xs tabular-nums align-top"),children:e.jsxs("span",{className:"inline-flex flex-col items-end gap-0.5",children:[e.jsx("span",{className:"whitespace-nowrap",children:A(s.latency_ms,"ms")}),(s.ttft_ms!=null||s.tpot_ms!=null)&&e.jsxs("span",{className:"whitespace-nowrap text-[11px] text-muted-foreground/70",title:`${d("logs.table.columns.latencyTtft")} ${A(s.ttft_ms,"ms")} · ${d("logs.table.columns.latencyTpot")} ${A(s.tpot_ms,"ms/tk")}`,children:[d("logs.table.columns.latencyTtft")," ",M(s.ttft_ms),e.jsx("span",{className:"mx-1 text-muted-foreground/50",children:"·"}),d("logs.table.columns.latencyTpot")," ",M(s.tpot_ms)]})]})}),b.has("status")&&e.jsx("td",{className:E(h,"text-center"),children:e.jsx(V,{variant:N.variant,className:"text-xs",children:N.label})}),b.has("error")&&e.jsx("td",{className:E(h,"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:E("sticky right-0 z-10 text-center",h,L),children:e.jsx(R,{variant:"outline",size:"sm",onClick:()=>a(s.id),children:d("logs.actions.detail")})})]}),o?e.jsx("tr",{"data-testid":`log-row-expanded-wrapper-${s.id}`,children:e.jsx("td",{colSpan:k,className:"border-t border-border bg-secondary/30 p-0",children:e.jsx("div",{className:"px-5 pb-5 pt-3",children:e.jsx(Js,{logId:s.id,providerLabelMap:l,apiKeyMap:p})})})}):null]})}function Xs(s){const{t:l}=O(),{tableScrollRef:p,visibleColumnSet:a,visibleColumnCount:o,logsError:t,logsPending:i,items:y,activeFiltersCount:b,total:d,handleResetFilters:v,handleRetry:u,providerLabelMap:N,apiKeyMap:f,handleOpenDetail:w,expandedLogId:r,onToggleExpand:h,rowDensity:L,showScrollHint:g,pageSize:j,setPageSize:k,page:n,totalPages:C,setPage:D}=s,F=e.jsx(X,{compact:!0,tone:"danger",icon:e.jsx(gs,{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(R,{variant:"outline",size:"sm",onClick:u,children:l("common.actions.refresh")}),b>0?e.jsx(R,{variant:"ghost",size:"sm",onClick:v,children:l("common.actions.reset")}):null]})}),_=e.jsx(X,{compact:!0,tone:"primary",icon:e.jsx(fs,{className:"h-5 w-5","aria-hidden":"true"}),title:b>0?l("logs.empty.filteredTitle"):l("logs.empty.title"),description:b>0?l("logs.empty.filteredSubtitle"):l("logs.empty.subtitle"),action:e.jsxs("div",{className:"flex flex-wrap items-center justify-center gap-2",children:[b>0?e.jsx(R,{variant:"outline",size:"sm",onClick:v,children:l("logs.empty.actions.reset")}):null,e.jsx(R,{asChild:!0,variant:"ghost",size:"sm",children:e.jsx(qe,{to:"/api-keys",children:l("logs.empty.actions.apiKeys")})})]})});return e.jsx(Fe,{className:"overflow-hidden bg-card shadow-[var(--surface-shadow)]",children:e.jsxs(Te,{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:d.toLocaleString()})}),e.jsx("span",{className:"mx-1.5 text-muted-foreground/50",children:"·"}),l("logs.actions.visibleCount",{count:o-2})]})]}),e.jsxs("div",{className:"hidden md:flex flex-wrap items-center gap-2",children:[e.jsx(V,{variant:"secondary",children:"Wide Table"}),e.jsx(V,{variant:"outline",className:"bg-background",children:l(L==="compact"?"logs.table.density.compact":"logs.table.density.comfortable")}),g?e.jsx(V,{variant:"warning",children:"Scroll for more"}):null]})]}),e.jsxs("div",{className:"relative hidden md:block",children:[e.jsx("div",{ref:p,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:"sticky left-0 z-20 bg-secondary px-3 py-2.5 text-left text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:l("logs.table.columns.time")}),a.has("endpoint")&&e.jsx("th",{className:"px-3 py-2.5 text-left text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:l("logs.table.columns.endpoint")}),a.has("provider")&&e.jsx("th",{className:"px-3 py-2.5 text-left text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:l("logs.table.columns.provider")}),a.has("requestedModel")&&e.jsx("th",{className:"px-3 py-2.5 text-left text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:l("logs.table.columns.requestedModel")}),a.has("routedModel")&&e.jsx("th",{className:"px-3 py-2.5 text-left text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:l("logs.table.columns.routedModel")}),a.has("apiKey")&&e.jsx("th",{className:"px-3 py-2.5 text-left text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:l("logs.table.columns.apiKey")}),a.has("tokens")&&e.jsx("th",{className:"px-3 py-2.5 text-right text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:l("logs.table.columns.tokens")}),a.has("duration")&&e.jsx("th",{className:"px-3 py-2.5 text-right text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:l("logs.table.columns.duration")}),a.has("status")&&e.jsx("th",{className:"px-3 py-2.5 text-center text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:l("logs.table.columns.status")}),a.has("error")&&e.jsx("th",{className:"px-3 py-2.5 text-left text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:l("logs.table.columns.error")}),e.jsx("th",{className:"sticky right-0 z-20 bg-secondary px-3 py-2.5 text-center text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:l("logs.table.columns.actions")})]})}),e.jsx("tbody",{className:"divide-y divide-border/50",children:i?Array.from({length:8}).map((c,z)=>e.jsx(Ms,{columns:o},z)):t&&y.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:o,className:"px-3 py-6",children:F})}):y.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:o,className:"px-3 py-8 text-center text-sm text-muted-foreground",children:_})}):y.map((c,z)=>e.jsx(Zs,{record:c,providerLabelMap:N,apiKeyMap:f,onSelect:w,isExpanded:c.id===r,onToggleExpand:h,isEven:z%2===0,density:L,visibleColumnSet:a},c.id))})]})}),g&&e.jsx("div",{className:"table-scroll-hint"})]}),e.jsx("div",{className:"md:hidden",children:i?e.jsx("div",{className:"space-y-3 p-4",children:Array.from({length:5}).map((c,z)=>e.jsx(Pe,{className:"h-20 w-full"},z))}):t&&y.length===0?e.jsx("div",{className:"px-3 py-6",children:F}):y.length===0?e.jsx("div",{className:"px-3 py-8",children:_}):y.map(c=>e.jsx(Gs,{record:c,providerLabelMap:N,onSelect:w},c.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 rounded-full bg-secondary px-3 py-2",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:l("logs.table.pagination.perPage")}),e.jsxs(te,{value:j.toString(),onValueChange:c=>k(Number(c)),children:[e.jsx(le,{className:"h-8 w-[80px] bg-background",children:e.jsx(ae,{})}),e.jsx(re,{children:Z.map(c=>e.jsx(I,{value:c.toString(),children:c},c))})]})]}),e.jsxs("div",{className:"flex items-center gap-2 rounded-full bg-secondary px-2 py-2",children:[e.jsx(R,{variant:"outline",size:"sm",onClick:()=>D(c=>Math.max(c-1,1)),disabled:n<=1,children: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:C===0?0:n,total:C})}),e.jsx(R,{variant:"outline",size:"sm",onClick:()=>D(c=>C===0?c:Math.min(c+1,C)),disabled:C===0||n>=C,children:l("logs.table.pagination.next")})]})]})]})})}function Ys({exportTimeoutMs:s,queryParams:l,total:p}){const{t:a}=O(),{pushToast:o}=ge(),[t,i]=x.useState(!1),y=x.useCallback(async()=>{if(!t){i(!0);try{const b=p>0?Math.min(p,5e3):1e3,d={...l,limit:b,offset:0},v=await ye.exportArchive(d,s),u=new Date().toISOString().replace(/[:.]/g,"-"),N=URL.createObjectURL(v),f=document.createElement("a");f.href=N,f.download=`cc-gw-logs-${u}.zip`,document.body.appendChild(f),f.click(),f.remove(),URL.revokeObjectURL(N),o({title:a("logs.toast.exportSuccess.title"),description:a("logs.toast.exportSuccess.desc"),variant:"success"})}catch(b){const d=bs(b);o({title:a("logs.toast.exportError.title"),description:a("logs.toast.exportError.desc",{message:d.message}),variant:"error"})}finally{i(!1)}}},[s,t,o,l,a,p]);return{exporting:t,handleExport:y}}function et(){const s=x.useRef(null),[l,p]=x.useState(!1),a=x.useCallback(()=>{const o=s.current;if(!o)return;const t=o.scrollWidth-o.scrollLeft-o.clientWidth>1;p(t)},[]);return x.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}}function st(){const[s,l]=$(q.logs.density,Us,{serialize:v=>v,deserialize:v=>v==="compact"?"compact":"comfortable"}),[p,a]=$(q.logs.visibleColumns,J,{serialize:JSON.stringify,deserialize:v=>{try{const u=JSON.parse(v);if(!Array.isArray(u))return J;const N=u.filter(f=>oe.includes(f));return N.length>0?N:J}catch{return J}}}),{scrollRef:o,showScrollHint:t}=et(),i=x.useMemo(()=>new Set(p),[p]),y=p.length+2,b=x.useCallback(v=>{a(u=>{if(u.includes(v))return u.length===1?u:u.filter(f=>f!==v);const N=[...u,v];return N.sort((f,w)=>oe.indexOf(f)-oe.indexOf(w)),N})},[]);return{resetVisibleColumns:x.useCallback(()=>{a(J)},[]),rowDensity:s,setRowDensity:l,showScrollHint:t,tableScrollRef:o,toggleColumn:b,visibleColumnCount:y,visibleColumns:p,visibleColumnSet:i}}function tt(){var Ne,we,ke,Se,Ce;const{t:s}=O(),{pushToast:l}=ge(),p=Os(),[a,o]=$(q.logs.providerFilter,"all"),[t,i]=$(q.logs.endpointFilter,"all"),[y,b]=$(q.logs.modelFilter,""),[d,v]=$(q.logs.statusFilter,"all"),[u,N]=$(q.logs.fromDate,""),[f,w]=$(q.logs.toDate,""),[r,h]=x.useState(1),[L,g]=$(q.logs.pageSize,Hs,{serialize:m=>String(m),deserialize:m=>{const S=Number(m);return Z.includes(S)?S:Z[0]}}),[j,k]=x.useState(null),[n,C]=x.useState(!1),[D,F]=x.useState(null),[_,c]=$(q.logs.selectedApiKeys,[],{serialize:JSON.stringify,deserialize:m=>{try{const S=JSON.parse(m);return Array.isArray(S)?S.map(P=>Number(P)).filter(P=>Number.isInteger(P)&&P>0):[]}catch{return[]}}}),[z,Ae]=x.useState(!0),{resetVisibleColumns:Oe,rowDensity:Ie,setRowDensity:$e,showScrollHint:Qe,tableScrollRef:Ve,toggleColumn:Ue,visibleColumnCount:He,visibleColumns:Be,visibleColumnSet:We}=st(),Ge=x.useDeferredValue(y),T=y===""?"":Ge;x.useEffect(()=>{h(1),F(null)},[a,t,T,d,u,f,L,_]);const ne=x.useMemo(()=>{const m={limit:L,offset:(r-1)*L};a!=="all"&&(m.provider=a),t!=="all"&&(m.endpoint=t),T.trim().length>0&&(m.model=T.trim()),d!=="all"&&(m.status=d);const S=_e(u),P=_e(f,!0);return S!==void 0&&(m.from=S),P!==void 0&&(m.to=P),_.length>0&&(m.apiKeys=_.join(",")),m},[T,t,u,r,L,a,_,d,f]),U=G(H.logs.list(ne),ye.listRequest(ne),{gcTime:6e4}),W=G(H.providers.all(),Le.providersRequest()),be=G(H.apiKeys.all(),{url:"/api/keys",method:"GET"}),ie=G(H.customEndpoints.all(),{url:"/api/custom-endpoints",method:"GET"}),je=G(H.config.exportTimeout(),Le.configRequest());x.useEffect(()=>{!U.isError||!U.error||l({title:s("logs.toast.listError.title"),description:s("logs.toast.listError.desc",{message:U.error.message}),variant:"error"})},[U.error,U.isError,l,s]),x.useEffect(()=>{!W.isError||!W.error||l({title:s("logs.toast.providerError.title"),description:s("logs.toast.providerError.desc",{message:W.error.message}),variant:"error"})},[W.error,W.isError,l,s]);const se=((Ne=U.data)==null?void 0:Ne.total)??0,Y=se>0?Math.ceil(se/L):0,Je=((we=U.data)==null?void 0:we.items)??[],Ze=x.useMemo(()=>{var S;const m=(S=je.data)==null?void 0:S.logExportTimeoutSeconds;return typeof m=="number"&&Number.isFinite(m)?Math.min(Math.max(Math.round(m),5),600)*1e3:6e4},[(ke=je.data)==null?void 0:ke.logExportTimeoutSeconds]);x.useEffect(()=>{Y>0&&r>Y&&h(Y)},[r,Y]);const de=W.data??[],ce=x.useMemo(()=>{const m=new Map;for(const S of de)S.id&&m.set(S.id,S.label??S.id);return m},[de]),ve=x.useMemo(()=>{var S;const m=new Map;m.set("anthropic",s("logs.filters.endpointAnthropic")),m.set("openai",s("logs.filters.endpointOpenAI"));for(const P of((S=ie.data)==null?void 0:S.endpoints)??[])m.set(P.id,P.label||P.id);return m},[(Se=ie.data)==null?void 0:Se.endpoints,s]),Xe=x.useMemo(()=>{const m=[];if(a!=="all"){const S=ce.get(a)??a;m.push({key:"provider",label:`${s("logs.filters.provider")}: ${S}`,onRemove:()=>o("all")})}if(t!=="all"){const S=ve.get(t)??t;m.push({key:"endpoint",label:`${s("logs.filters.endpoint")}: ${S}`,onRemove:()=>i("all")})}if(T.trim()&&m.push({key:"model",label:`${s("logs.filters.modelId")}: ${T.trim()}`,onRemove:()=>b("")}),d!=="all"){const S=s(d==="success"?"logs.filters.statusSuccess":"logs.filters.statusError");m.push({key:"status",label:`${s("logs.filters.status")}: ${S}`,onRemove:()=>v("all")})}return u&&m.push({key:"from",label:`${s("logs.filters.startDate")}: ${u}`,onRemove:()=>N("")}),f&&m.push({key:"to",label:`${s("logs.filters.endDate")}: ${f}`,onRemove:()=>w("")}),_.length>0&&m.push({key:"apiKeys",label:s("logs.filters.apiKeySelected",{count:_.length}),onRemove:()=>c([])}),m},[T,t,ve,u,a,ce,_.length,d,s,f]),me=be.data??[],Ye=x.useMemo(()=>{const m=new Map;for(const S of me)m.set(S.id,S);return m},[me]),es=x.useMemo(()=>oe.map(m=>({id:m,label:s(`logs.table.columns.${m}`)})),[s]),ee=x.useMemo(()=>{const m=new Date;return`${m.getFullYear()}-${String(m.getMonth()+1).padStart(2,"0")}-${String(m.getDate()).padStart(2,"0")}`},[]),ss=x.useMemo(()=>a==="all"&&t==="all"&&T.trim()===""&&d==="all"&&u===""&&f===""&&_.length===0?"all":d==="error"&&t==="all"&&a==="all"&&T.trim()===""&&u===""&&f===""&&_.length===0?"errors":Bs(u,f,ee)&&t==="all"&&a==="all"&&T.trim()===""&&d==="all"&&_.length===0?"today":t==="anthropic"&&a==="all"&&T.trim()===""&&d==="all"&&u===""&&f===""&&_.length===0?"anthropic":t==="openai"&&a==="all"&&T.trim()===""&&d==="all"&&u===""&&f===""&&_.length===0?"openai":null,[T,t,u,a,_.length,d,f,ee]),ue=x.useCallback(()=>{o("all"),b(""),i("all"),v("all"),N(""),w(""),c([])},[]),ts=x.useCallback(m=>{if(h(1),ue(),m!=="all"){if(m==="errors"){v("error");return}if(m==="today"){N(ee),w(ee);return}if(m==="anthropic"){i("anthropic");return}m==="openai"&&i("openai")}},[ue,ee]),{exporting:ls,handleExport:as}=Ys({exportTimeoutMs:Ze,queryParams:ne,total:se}),rs=x.useCallback(m=>{p.removeQueries({queryKey:["logs","detail"],type:"inactive"}),k(m),C(!0)},[p]),os=x.useCallback(()=>{C(!1)},[]),ns=x.useCallback(m=>{F(S=>S===m?null:m)},[]);return x.useEffect(()=>{n||j===null||(p.removeQueries({queryKey:H.logs.detail(j),exact:!0}),k(null))},[n,p,j]),{activeFilters:Xe,activeQuickView:ss,apiKeyMap:Ye,apiKeys:me,apiKeysQuery:be,applyQuickView:ts,columnOptions:es,customEndpoints:(Ce=ie.data)==null?void 0:Ce.endpoints,endpointFilter:t,exporting:ls,expandedLogId:D,filtersExpanded:z,fromDate:u,handleCloseDetail:os,handleExport:as,handleOpenDetail:rs,handleResetFilters:ue,handleToggleExpand:ns,isDetailOpen:n,items:Je,logsQuery:U,modelFilter:y,page:r,pageSize:L,providerFilter:a,providerLabelMap:ce,providerOptions:de,rowDensity:Ie,resetVisibleColumns:Oe,selectedApiKeys:_,selectedLogId:j,setEndpointFilter:i,setFiltersExpanded:Ae,setFromDate:N,setModelFilter:b,setPage:h,setPageSize:g,setProviderFilter:o,setRowDensity:$e,setSelectedApiKeys:c,setStatusFilter:v,setToDate:w,showScrollHint:Qe,statusFilter:d,tableScrollRef:Ve,toDate:f,toggleColumn:Ue,total:se,totalPages:Y,visibleColumnCount:He,visibleColumns:Be,visibleColumnSet:We}}function wt(){var l;const s=tt();return e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsx(hs,{actions:e.jsx(Ws,{columnOptions:s.columnOptions,exporting:s.exporting,onExport:()=>void s.handleExport(),onRefresh:()=>void s.logsQuery.refetch(),onResetColumns:s.resetVisibleColumns,onSetDensity:s.setRowDensity,onToggleColumn:s.toggleColumn,refreshing:s.logsQuery.isFetching,rowDensity:s.rowDensity,visibleColumns:s.visibleColumns,visibleColumnSet:s.visibleColumnSet})}),e.jsx($s,{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,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(Xs,{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,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(Qs,{open:s.isDetailOpen,logId:s.selectedLogId,onClose:s.handleCloseDetail,providerLabelMap:s.providerLabelMap,apiKeyMap:s.apiKeyMap})]})}export{wt as default};
|