@chenpu17/cc-gw 0.8.0-alpha.2 → 0.8.0-alpha.3
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/README.md +2 -2
- package/package.json +5 -5
- package/src/web/dist/assets/{About-CiTmsH3_.js → About-BWDRyUez.js} +1 -1
- package/src/web/dist/assets/{ApiKeys-6rCCLhIC.js → ApiKeys-DkOlFxcs.js} +1 -1
- package/src/web/dist/assets/{ConfirmDialog-A9gywPpz.js → ConfirmDialog-DFy4NI8g.js} +1 -1
- package/src/web/dist/assets/{Dashboard-BoZHGcx0.js → Dashboard-Csl3HA0l.js} +1 -1
- package/src/web/dist/assets/{Events-DAiVr1Fh.js → Events-BKTkKtKe.js} +1 -1
- package/src/web/dist/assets/{Help-5dtFavzf.js → Help-BcryNGLt.js} +1 -1
- package/src/web/dist/assets/{Login-Bf2fjws1.js → Login-Bi-LLRbT.js} +1 -1
- package/src/web/dist/assets/{Logs-63hL3C0b.js → Logs-BcNmJUBA.js} +1 -1
- package/src/web/dist/assets/{ModelManagement-Sh2TbDu3.js → ModelManagement-BL2IOQpn.js} +1 -1
- package/src/web/dist/assets/{PageHeader-BfplRrls.js → PageHeader-Da1cmUY0.js} +1 -1
- package/src/web/dist/assets/{PageSection-DLrvM7lY.js → PageSection-Bf8b2jG0.js} +1 -1
- package/src/web/dist/assets/{Settings-I4pHQi8Z.js → Settings-BVKO0J1z.js} +1 -1
- package/src/web/dist/assets/{Skeleton-m_JcEeRW.js → Skeleton-CN-bCufq.js} +1 -1
- package/src/web/dist/assets/{card-pQJ3gJlC.js → card-BD2y3CjZ.js} +1 -1
- package/src/web/dist/assets/{index-CB0xlluu.js → index-BuTkie0t.js} +2 -2
- package/src/web/dist/assets/{input-DmlfmLRF.js → input-BHq9dQGf.js} +1 -1
- package/src/web/dist/assets/{label-WnrqWaUM.js → label-CUv6yhdE.js} +1 -1
- package/src/web/dist/assets/{popover-BGLA6gjb.js → popover-0Ho_T06s.js} +1 -1
- package/src/web/dist/assets/{select-f3RCxJ98.js → select-Dq7kCMCk.js} +1 -1
- package/src/web/dist/assets/{switch-BSgZEVkb.js → switch-NOIFebYg.js} +1 -1
- package/src/web/dist/assets/{useApiQuery-BGQDgPyp.js → useApiQuery-BkAH5SvI.js} +1 -1
- package/src/web/dist/index.html +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as o,f as e,ac as Ze,ad as Xe,Z as es,ae as ss,af as ts,a5 as Fe,h as as}from"./vendor-C92xTG6Z.js";import{u as Ke,a as ls,t as rs,c as h,B as y}from"./index-CB0xlluu.js";import{u as A}from"./useApiQuery-BGQDgPyp.js";import{T as os,a as Q}from"./Skeleton-m_JcEeRW.js";import{P as ns,B as P}from"./PageHeader-BfplRrls.js";import{c as is}from"./clipboard-CALi6bTW.js";import{I as me}from"./input-DmlfmLRF.js";import{L as O}from"./label-WnrqWaUM.js";import{C as Re,a as De}from"./card-pQJ3gJlC.js";import{S as Z,a as X,b as ee,c as se,d as T}from"./select-f3RCxJ98.js";import{P as ds,a as cs,b as ms}from"./popover-BGLA6gjb.js";import{u as ae}from"./i18n-CZ1qKIdj.js";import"./router-DjNibHfR.js";import"./radix-Ccu1urVd.js";import"./query-CDpWKdnY.js";const Me=[20,50,100],ze="cc-gw.logs.visible-columns",Ae="cc-gw.logs.density",$=["endpoint","provider","requestedModel","routedModel","apiKey","inputTokens","outputTokens","latency","status","error"],te=["endpoint","provider","requestedModel","routedModel","apiKey","inputTokens","cacheReadTokens","cacheCreationTokens","outputTokens","latency","ttft","tpot","status","error"];function xs(){if(typeof window>"u")return $;try{const s=window.localStorage.getItem(ze);if(!s)return $;const i=JSON.parse(s);if(!Array.isArray(i))return $;const c=i.filter(v=>te.includes(v));return c.length>0?c:$}catch{return $}}function us(){return typeof window>"u"?"comfortable":window.localStorage.getItem(Ae)==="compact"?"compact":"comfortable"}function Oe(s,i=!1){if(!s)return;const c=i?`${s}T23:59:59.999`:`${s}T00:00:00.000`,v=Date.parse(c);return Number.isFinite(v)?v:void 0}function Pe(s){const i=new Date(s);return`${i.getFullYear()}-${`${i.getMonth()+1}`.padStart(2,"0")}-${`${i.getDate()}`.padStart(2,"0")} ${`${i.getHours()}`.padStart(2,"0")}:${`${i.getMinutes()}`.padStart(2,"0")}:${`${i.getSeconds()}`.padStart(2,"0")}`}function L(s){return s==null?"-":s.toLocaleString()}function C(s,i){const c=L(s);return c==="-"?"-":`${c} ${i}`}function ps(s){return s?"true":"false"}function $e(s,i){if(!s||s.trim().length===0)return i;try{const c=JSON.parse(s);return JSON.stringify(c,null,2)}catch{return s}}function hs(s,i,c){return s===c&&i===c}function Os(){var ke,_e,Se,Ee,Te,Ce;const{t:s}=ae(),{pushToast:i}=Ke(),[c,v]=o.useState("all"),[g,a]=o.useState("all"),[d,j]=o.useState(""),[x,N]=o.useState("all"),[l,S]=o.useState(""),[r,m]=o.useState(""),[f,p]=o.useState(1),[u,F]=o.useState(Me[0]),[le,I]=o.useState(null),[Ie,xe]=o.useState(!1),[w,re]=o.useState([]),[H,ue]=o.useState(!1),[pe,qe]=o.useState(!1),[q,he]=o.useState(us),[R,fe]=o.useState(xs),[Ue,Ge]=o.useState(!1),oe=o.useRef(null);o.useEffect(()=>{typeof window>"u"||window.localStorage.setItem(Ae,q)},[q]),o.useEffect(()=>{typeof window>"u"||window.localStorage.setItem(ze,JSON.stringify(R))},[R]),o.useEffect(()=>{p(1)},[c,g,d,x,l,r,u,w]);const W=o.useMemo(()=>{const t={limit:u,offset:(f-1)*u};c!=="all"&&(t.provider=c),g!=="all"&&(t.endpoint=g),d.trim().length>0&&(t.model=d.trim()),x!=="all"&&(t.status=x);const n=Oe(l),_=Oe(r,!0);return n!==void 0&&(t.from=n),_!==void 0&&(t.to=_),w.length>0&&(t.apiKeys=w.join(",")),t},[c,g,d,x,l,r,f,u,w]),k=A(["logs",W],{url:"/api/logs",method:"GET",params:W}),K=A(["providers","all"],{url:"/api/providers",method:"GET"}),ge=A(["api-keys"],{url:"/api/keys",method:"GET"}),ne=A(["custom-endpoints"],{url:"/api/custom-endpoints",method:"GET"}),je=A(["config","export-timeout"],{url:"/api/config",method:"GET"});o.useEffect(()=>{k.isError&&k.error&&i({title:s("logs.toast.listError.title"),description:s("logs.toast.listError.desc",{message:k.error.message}),variant:"error"})},[k.isError,k.error,i,s]),o.useEffect(()=>{K.isError&&K.error&&i({title:s("logs.toast.providerError.title"),description:s("logs.toast.providerError.desc",{message:K.error.message}),variant:"error"})},[K.isError,K.error,i,s]);const D=((ke=k.data)==null?void 0:ke.total)??0,E=D>0?Math.ceil(D/u):0,be=((_e=k.data)==null?void 0:_e.items)??[],ye=o.useMemo(()=>{var n;const t=(n=je.data)==null?void 0:n.logExportTimeoutSeconds;return typeof t=="number"&&Number.isFinite(t)?Math.min(Math.max(Math.round(t),5),600)*1e3:6e4},[(Se=je.data)==null?void 0:Se.logExportTimeoutSeconds]);o.useEffect(()=>{E>0&&f>E&&p(E)},[E,f]);const ie=K.data??[],J=o.useMemo(()=>{const t=new Map;for(const n of ie)n.id&&t.set(n.id,n.label??n.id);return t},[ie]),ve=o.useMemo(()=>{var n;const t=new Map;t.set("anthropic",s("logs.filters.endpointAnthropic")),t.set("openai",s("logs.filters.endpointOpenAI"));for(const _ of((n=ne.data)==null?void 0:n.endpoints)??[])t.set(_.id,_.label||_.id);return t},[(Ee=ne.data)==null?void 0:Ee.endpoints,s]),z=o.useMemo(()=>{const t=[];if(c!=="all"){const n=J.get(c)??c;t.push({key:"provider",label:`${s("logs.filters.provider")}: ${n}`,onRemove:()=>v("all")})}if(g!=="all"){const n=ve.get(g)??g;t.push({key:"endpoint",label:`${s("logs.filters.endpoint")}: ${n}`,onRemove:()=>a("all")})}if(d.trim()&&t.push({key:"model",label:`${s("logs.filters.modelId")}: ${d.trim()}`,onRemove:()=>j("")}),x!=="all"){const n=s(x==="success"?"logs.filters.statusSuccess":"logs.filters.statusError");t.push({key:"status",label:`${s("logs.filters.status")}: ${n}`,onRemove:()=>N("all")})}return l&&t.push({key:"from",label:`${s("logs.filters.startDate")}: ${l}`,onRemove:()=>S("")}),r&&t.push({key:"to",label:`${s("logs.filters.endDate")}: ${r}`,onRemove:()=>m("")}),w.length>0&&t.push({key:"apiKeys",label:s("logs.filters.apiKeySelected",{count:w.length}),onRemove:()=>re([])}),t},[c,J,g,ve,d,x,l,r,w,s]),de=ge.data??[],Ne=o.useMemo(()=>{const t=new Map;for(const n of de)t.set(n.id,n);return t},[de]),b=o.useMemo(()=>new Set(R),[R]),Be=o.useMemo(()=>te.map(t=>({id:t,label:s(`logs.table.columns.${t}`)})),[s]),we=R.length+2,U=o.useMemo(()=>new Date().toISOString().slice(0,10),[]),Ve=o.useMemo(()=>c==="all"&&g==="all"&&d.trim()===""&&x==="all"&&l===""&&r===""&&w.length===0?"all":x==="error"&&g==="all"&&c==="all"&&d.trim()===""&&l===""&&r===""&&w.length===0?"errors":hs(l,r,U)&&g==="all"&&c==="all"&&d.trim()===""&&x==="all"&&w.length===0?"today":g==="anthropic"&&c==="all"&&d.trim()===""&&x==="all"&&l===""&&r===""&&w.length===0?"anthropic":g==="openai"&&c==="all"&&d.trim()===""&&x==="all"&&l===""&&r===""&&w.length===0?"openai":null,[g,l,d,c,w.length,x,r,U]),Qe=o.useCallback(t=>{fe(n=>{if(n.includes(t))return n.length===1?n:n.filter(B=>B!==t);const _=[...n,t];return _.sort((B,ce)=>te.indexOf(B)-te.indexOf(ce)),_})},[]),Y=o.useCallback(()=>{v("all"),j(""),a("all"),N("all"),S(""),m(""),re([])},[]),He=o.useCallback(t=>{if(p(1),Y(),t!=="all"){if(t==="errors"){N("error");return}if(t==="today"){S(U),m(U);return}if(t==="anthropic"){a("anthropic");return}t==="openai"&&a("openai")}},[Y,U]),We=o.useCallback(async()=>{if(!H){ue(!0);try{const t=D>0?Math.min(D,5e3):1e3,n={...W,limit:t,offset:0},_=await ls.post("/api/logs/export",n,{responseType:"blob",timeout:ye}),B=new Blob([_.data],{type:"application/zip"}),ce=new Date().toISOString().replace(/[:.]/g,"-"),Le=URL.createObjectURL(B),V=document.createElement("a");V.href=Le,V.download=`cc-gw-logs-${ce}.zip`,document.body.appendChild(V),V.click(),V.remove(),URL.revokeObjectURL(Le),i({title:s("logs.toast.exportSuccess.title"),description:s("logs.toast.exportSuccess.desc"),variant:"success"})}catch(t){const n=rs(t);i({title:s("logs.toast.exportError.title"),description:s("logs.toast.exportError.desc",{message:n.message}),variant:"error"})}finally{ue(!1)}}},[ye,H,i,W,s,D]),Je=o.useCallback(t=>{I(t),xe(!0)},[]),Ye=o.useCallback(()=>{xe(!1),I(null)},[]),G=o.useCallback(()=>{const t=oe.current;if(!t)return;const n=t.scrollWidth-t.scrollLeft-t.clientWidth>1;Ge(n)},[]);return o.useEffect(()=>{const t=oe.current;if(!t)return;G(),t.addEventListener("scroll",G,{passive:!0});const n=new ResizeObserver(G);return n.observe(t),()=>{t.removeEventListener("scroll",G),n.disconnect()}},[G]),e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx(ns,{icon:e.jsx(es,{className:"h-5 w-5","aria-hidden":"true"}),title:s("logs.title"),description:s("logs.description"),eyebrow:"Traffic Explorer",breadcrumb:"Gateway / Logs",helper:s("logs.filtersDescription"),actions:e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsxs("div",{className:"flex items-center gap-1 rounded-full border border-border/70 bg-background/80 p-1 shadow-[0_1px_2px_rgba(15,23,42,0.03)]",children:[e.jsx("button",{type:"button",onClick:()=>he("comfortable"),className:h("inline-flex h-8 items-center rounded-full px-3.5 text-xs font-medium transition-all",q==="comfortable"?"bg-primary text-primary-foreground shadow-[0_8px_18px_-14px_rgba(59,130,246,0.7)]":"text-muted-foreground hover:bg-primary/5 hover:text-foreground"),children:s("logs.table.density.comfortable")}),e.jsx("button",{type:"button",onClick:()=>he("compact"),className:h("inline-flex h-8 items-center rounded-full px-3.5 text-xs font-medium transition-all",q==="compact"?"bg-primary text-primary-foreground shadow-[0_8px_18px_-14px_rgba(59,130,246,0.7)]":"text-muted-foreground hover:bg-primary/5 hover:text-foreground"),children:s("logs.table.density.compact")})]}),e.jsxs(ds,{children:[e.jsx(cs,{asChild:!0,children:e.jsx(y,{variant:"outline",size:"sm",children:s("logs.actions.columns")})}),e.jsxs(ms,{align:"end",className:"w-64 rounded-[1.2rem] border-white/60 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:s("logs.actions.columns")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("logs.actions.visibleCount",{count:R.length})})]}),e.jsx(y,{variant:"ghost",size:"sm",onClick:()=>fe($),disabled:JSON.stringify(R)===JSON.stringify($),children:s("common.actions.reset")})]}),e.jsx("div",{className:"grid gap-1.5",children:Be.map(t=>{const n=b.has(t.id);return e.jsxs("label",{className:h("flex cursor-pointer items-center gap-3 rounded-xl px-3 py-2 text-sm transition hover:bg-primary/5",n&&"bg-primary/10 text-primary"),children:[e.jsx("input",{type:"checkbox",checked:n,onChange:()=>Qe(t.id),className:"h-4 w-4 rounded border-border"}),e.jsx("span",{children:t.label})]},t.id)})})]})]}),e.jsxs(y,{onClick:We,disabled:H,children:[e.jsx(Ze,{className:"mr-2 h-4 w-4"}),s(H?"common.actions.loading":"logs.actions.export")]}),e.jsx("span",{className:"text-sm text-muted-foreground",children:s("logs.summary.total",{value:D.toLocaleString()})}),e.jsxs(y,{variant:"outline",size:"sm",onClick:()=>k.refetch(),disabled:k.isFetching,children:[e.jsx(Xe,{className:h("mr-2 h-4 w-4",k.isFetching&&"animate-spin")}),k.isFetching?s("common.actions.refreshing"):s("logs.actions.manualRefresh")]})]})}),e.jsx(Re,{className:"sticky top-20 z-20 border-white/40 bg-card/90 backdrop-blur",children:e.jsxs(De,{className:"pt-4",children:[e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("p",{className:"text-sm font-semibold text-foreground",children:s("logs.filtersTitle")}),e.jsx(P,{variant:"outline",children:s("logs.summary.total",{value:D.toLocaleString()})}),z.length>0&&e.jsx(P,{variant:"secondary",children:s("common.filters.activeCount",{count:z.length})})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("logs.filtersDescription")})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[z.length>0&&e.jsx(y,{variant:"ghost",size:"sm",onClick:Y,children:s("common.actions.reset")}),e.jsx(y,{variant:"ghost",size:"sm",onClick:()=>qe(t=>!t),children:pe?e.jsxs(e.Fragment,{children:[s("common.filters.collapse"),e.jsx(ss,{className:"ml-1 h-4 w-4"})]}):e.jsxs(e.Fragment,{children:[s("common.filters.expand"),e.jsx(ts,{className:"ml-1 h-4 w-4"})]})})]})]}),e.jsx("div",{className:"flex items-center justify-between gap-3",children:e.jsx("div",{className:"flex flex-1 items-center gap-3 overflow-hidden",children:z.length>0?e.jsx("div",{className:"flex flex-wrap items-center gap-2",children:z.map(t=>e.jsxs(P,{variant:"secondary",role:"button",tabIndex:0,className:"cursor-pointer gap-1 hover:bg-destructive/10 hover:text-destructive",onClick:t.onRemove,onKeyDown:n=>{(n.key==="Enter"||n.key===" ")&&(n.preventDefault(),t.onRemove())},children:[t.label,e.jsx(Fe,{className:"h-3 w-3","aria-hidden":"true"})]},t.key))}):e.jsx("span",{className:"text-sm text-muted-foreground",children:s("common.filters.allRequests")})})}),e.jsx("div",{className:"flex flex-wrap items-center gap-2",children:["all","errors","today","anthropic","openai"].map(t=>e.jsx(y,{variant:Ve===t?"default":"outline",size:"sm",className:"rounded-full",onClick:()=>He(t),children:s(`logs.quickViews.${t}`)},t))})]}),pe&&e.jsxs("div",{className:"mt-4 grid gap-4 md:grid-cols-2 xl:grid-cols-4 animate-in fade-in slide-in-from-top-2 duration-200",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(O,{children:s("logs.filters.provider")}),e.jsxs(Z,{value:c,onValueChange:v,children:[e.jsx(X,{children:e.jsx(ee,{})}),e.jsxs(se,{children:[e.jsx(T,{value:"all",children:s("logs.filters.providerAll")}),ie.map(t=>e.jsx(T,{value:t.id,children:t.label??t.id},t.id))]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(O,{children:s("logs.filters.endpoint")}),e.jsxs(Z,{value:g,onValueChange:a,children:[e.jsx(X,{children:e.jsx(ee,{})}),e.jsxs(se,{children:[e.jsx(T,{value:"all",children:s("logs.filters.endpointAll")}),e.jsx(T,{value:"anthropic",children:s("logs.filters.endpointAnthropic")}),e.jsx(T,{value:"openai",children:s("logs.filters.endpointOpenAI")}),(Ce=(Te=ne.data)==null?void 0:Te.endpoints)==null?void 0:Ce.map(t=>e.jsx(T,{value:t.id,children:t.label||t.id},t.id))]})]})]}),e.jsx(js,{className:"md:col-span-2",apiKeys:de,selected:w,disabled:ge.isLoading,onChange:re}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(O,{children:s("logs.filters.modelId")}),e.jsx(me,{value:d,onChange:t=>j(t.target.value),placeholder:s("logs.filters.modelPlaceholder")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(O,{children:s("logs.filters.status")}),e.jsxs(Z,{value:x,onValueChange:t=>N(t),children:[e.jsx(X,{children:e.jsx(ee,{})}),e.jsxs(se,{children:[e.jsx(T,{value:"all",children:s("logs.filters.statusAll")}),e.jsx(T,{value:"success",children:s("logs.filters.statusSuccess")}),e.jsx(T,{value:"error",children:s("logs.filters.statusError")})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(O,{children:s("logs.filters.startDate")}),e.jsx(me,{type:"date",value:l,onChange:t=>S(t.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(O,{children:s("logs.filters.endDate")}),e.jsx(me,{type:"date",value:r,onChange:t=>m(t.target.value)})]})]})]})}),e.jsx(Re,{children:e.jsxs(De,{className:"p-0",children:[e.jsxs("div",{className:"relative",children:[e.jsx("div",{ref:oe,className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full min-w-[1200px] text-sm",children:[e.jsx("thead",{className:"border-b bg-muted/50",children:e.jsxs("tr",{children:[e.jsx("th",{className:"sticky left-0 z-20 bg-muted/95 px-3 py-2 text-left text-xs font-medium backdrop-blur",children:s("logs.table.columns.time")}),b.has("endpoint")&&e.jsx("th",{className:"px-3 py-2 text-left text-xs font-medium",children:s("logs.table.columns.endpoint")}),b.has("provider")&&e.jsx("th",{className:"px-3 py-2 text-left text-xs font-medium",children:s("logs.table.columns.provider")}),b.has("requestedModel")&&e.jsx("th",{className:"px-3 py-2 text-left text-xs font-medium",children:s("logs.table.columns.requestedModel")}),b.has("routedModel")&&e.jsx("th",{className:"px-3 py-2 text-left text-xs font-medium",children:s("logs.table.columns.routedModel")}),b.has("apiKey")&&e.jsx("th",{className:"px-3 py-2 text-left text-xs font-medium",children:s("logs.table.columns.apiKey")}),b.has("inputTokens")&&e.jsx("th",{className:"px-3 py-2 text-right text-xs font-medium",children:s("logs.table.columns.inputTokens")}),b.has("cacheReadTokens")&&e.jsx("th",{className:"px-3 py-2 text-right text-xs font-medium",children:s("logs.table.columns.cacheReadTokens")}),b.has("cacheCreationTokens")&&e.jsx("th",{className:"px-3 py-2 text-right text-xs font-medium",children:s("logs.table.columns.cacheCreationTokens")}),b.has("outputTokens")&&e.jsx("th",{className:"px-3 py-2 text-right text-xs font-medium",children:s("logs.table.columns.outputTokens")}),b.has("latency")&&e.jsx("th",{className:"px-3 py-2 text-right text-xs font-medium",children:s("logs.table.columns.latency")}),b.has("ttft")&&e.jsx("th",{className:"px-3 py-2 text-right text-xs font-medium",children:s("logs.table.columns.ttft")}),b.has("tpot")&&e.jsx("th",{className:"px-3 py-2 text-right text-xs font-medium",children:s("logs.table.columns.tpot")}),b.has("status")&&e.jsx("th",{className:"px-3 py-2 text-center text-xs font-medium",children:s("logs.table.columns.status")}),b.has("error")&&e.jsx("th",{className:"px-3 py-2 text-left text-xs font-medium",children:s("logs.table.columns.error")}),e.jsx("th",{className:"sticky right-0 z-20 bg-muted/95 px-3 py-2 text-center text-xs font-medium backdrop-blur",children:s("logs.table.columns.actions")})]})}),e.jsx("tbody",{className:"divide-y",children:k.isPending?Array.from({length:8}).map((t,n)=>e.jsx(os,{columns:we},n)):be.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:we,className:"px-3 py-8 text-center text-sm text-muted-foreground",children:e.jsxs("div",{className:"flex flex-col items-center gap-3 py-4",children:[e.jsx("span",{children:s("logs.table.empty")}),z.length>0&&e.jsx(y,{variant:"outline",size:"sm",onClick:Y,children:s("common.actions.reset")})]})})}):be.map((t,n)=>e.jsx(fs,{record:t,providerLabelMap:J,apiKeyMap:Ne,onSelect:Je,isEven:n%2===0,density:q,visibleColumnSet:b},t.id))})]})}),Ue&&e.jsx("div",{className:"table-scroll-hint"})]}),e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-4 border-t p-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:s("logs.table.pagination.perPage")}),e.jsxs(Z,{value:u.toString(),onValueChange:t=>F(Number(t)),children:[e.jsx(X,{className:"w-[80px]",children:e.jsx(ee,{})}),e.jsx(se,{children:Me.map(t=>e.jsx(T,{value:t.toString(),children:t},t))})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(y,{variant:"outline",size:"sm",onClick:()=>p(t=>Math.max(t-1,1)),disabled:f<=1,children:s("logs.table.pagination.previous")}),e.jsx("span",{className:"text-sm text-muted-foreground",children:s("logs.table.pagination.pageLabel",{page:E===0?0:f,total:E})}),e.jsx(y,{variant:"outline",size:"sm",onClick:()=>p(t=>E===0?t:Math.min(t+1,E)),disabled:E===0||f>=E,children:s("logs.table.pagination.next")})]})]})]})}),e.jsx(gs,{open:Ie,logId:le,onClose:Ye,providerLabelMap:J,apiKeyMap:Ne})]})}function fs({record:s,providerLabelMap:i,apiKeyMap:c,onSelect:v,isEven:g,density:a,visibleColumnSet:d}){const{t:j}=ae(),x=i.get(s.provider)??s.provider,N=s.endpoint||"-",l=!!s.error,S=s.status_code,r=s.client_model??j("logs.table.requestedModelFallback"),m=s.api_key_id!=null?c.get(s.api_key_id):void 0,f=s.api_key_id==null?j("logs.table.apiKeyUnknown"):m!=null&&m.isWildcard?j("apiKeys.wildcard"):m!=null&&m.name?m.name:s.api_key_name?s.api_key_name:j("logs.table.apiKeyUnknown"),p=a==="compact"?"px-3 py-1.5":"px-3 py-2",u=g?"bg-muted/30":"bg-background";return e.jsxs("tr",{className:h("transition-colors",g?"bg-muted/30":"","hover:bg-muted/50"),children:[e.jsx("td",{className:h("sticky left-0 z-10 text-xs",p,u),children:Pe(s.timestamp)}),d.has("endpoint")&&e.jsx("td",{className:h(p,"text-xs"),children:N}),d.has("provider")&&e.jsx("td",{className:h(p,"text-xs"),children:e.jsx("div",{className:"max-w-[100px] truncate",title:x,children:x})}),d.has("requestedModel")&&e.jsx("td",{className:h(p,"text-xs text-muted-foreground"),children:e.jsx("div",{className:"max-w-[120px] truncate",title:r,children:r})}),d.has("routedModel")&&e.jsx("td",{className:h(p,"text-xs"),children:e.jsx("div",{className:"max-w-[120px] truncate",title:s.model,children:s.model})}),d.has("apiKey")&&e.jsx("td",{className:h(p,"text-xs text-muted-foreground"),children:e.jsx("div",{className:"max-w-[90px] truncate",title:f,children:f})}),d.has("inputTokens")&&e.jsx("td",{className:h(p,"text-right text-xs tabular-nums"),children:L(s.input_tokens)}),d.has("cacheReadTokens")&&e.jsx("td",{className:h(p,"text-right text-xs tabular-nums"),children:L(s.cache_read_tokens)}),d.has("cacheCreationTokens")&&e.jsx("td",{className:h(p,"text-right text-xs tabular-nums"),children:L(s.cache_creation_tokens)}),d.has("outputTokens")&&e.jsx("td",{className:h(p,"text-right text-xs tabular-nums"),children:L(s.output_tokens)}),d.has("latency")&&e.jsx("td",{className:h(p,"text-right text-xs tabular-nums"),children:C(s.latency_ms,"ms")}),d.has("ttft")&&e.jsx("td",{className:h(p,"text-right text-xs tabular-nums"),children:C(s.ttft_ms,"ms")}),d.has("tpot")&&e.jsx("td",{className:h(p,"text-right text-xs tabular-nums"),children:C(s.tpot_ms,"ms/tk")}),d.has("status")&&e.jsx("td",{className:h(p,"text-center"),children:e.jsx(P,{variant:l?"destructive":"default",className:"text-xs",children:S??(l?500:200)})}),d.has("error")&&e.jsx("td",{className:h(p,"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:h("sticky right-0 z-10 text-center",p,u),children:e.jsx(y,{variant:"outline",size:"sm",onClick:()=>v(s.id),children:j("logs.actions.detail")})})]})}function gs({open:s,logId:i,onClose:c,providerLabelMap:v,apiKeyMap:g}){var f,p;const{t:a}=ae(),{pushToast:d}=Ke(),j=o.useRef(null),x=A(["log-detail",i],{url:`/api/logs/${i}`,method:"GET"},{enabled:s&&i!==null,staleTime:3e4});o.useEffect(()=>{x.isError&&x.error&&d({title:a("logs.detail.loadError"),description:x.error.message,variant:"error"})},[x.isError,x.error,d,a]),o.useEffect(()=>{if(!s)return;const u=F=>{F.key==="Escape"&&c()};return window.addEventListener("keydown",u),()=>window.removeEventListener("keydown",u)},[s,c]),o.useEffect(()=>{s&&j.current&&j.current.focus()},[s,i]);const N=o.useCallback(async(u,F,le)=>{if(!F){d({title:a("logs.detail.copy.empty",{label:u}),variant:"info"});return}try{await is(F),d({title:a(le),variant:"success"})}catch(I){d({title:a("logs.detail.copy.failure"),description:I instanceof Error?I.message:a("logs.detail.copy.failureFallback"),variant:"error"})}},[d,a]);if(!s)return null;const l=x.data,S=l?v.get(l.provider)??l.provider:"",r=l&&l.api_key_id!=null?g.get(l.api_key_id):void 0,m=l?l.status_code??(l.error?500:200):null;return typeof document>"u"?null:as.createPortal(e.jsxs("div",{className:"fixed inset-0 z-50 flex",children:[e.jsx("div",{className:"flex-1 bg-background/80 backdrop-blur-sm animate-in fade-in duration-200",onClick:c}),e.jsxs("aside",{role:"dialog","aria-modal":"true",className:"flex h-full w-full max-w-xl flex-col border-l bg-card shadow-xl animate-in slide-in-from-right duration-300",children:[e.jsxs("header",{className:"flex items-center justify-between border-b px-6 py-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-semibold",children:a("logs.detail.title")}),l&&e.jsx("p",{className:"text-xs text-muted-foreground",children:a("logs.detail.id",{id:l.id})})]}),e.jsxs(y,{ref:j,variant:"outline",size:"sm",onClick:c,children:[e.jsx(Fe,{className:"mr-2 h-4 w-4"}),a("common.actions.close")]})]}),e.jsx("div",{className:"flex-1 overflow-y-auto",children:x.isPending?e.jsxs("div",{className:"flex flex-col gap-4 p-6",children:[e.jsx(Q,{className:"h-5 w-40"}),e.jsx(Q,{className:"h-4 w-full"}),e.jsx(Q,{className:"h-4 w-3/4"}),e.jsx(Q,{className:"h-32 w-full"}),e.jsx(Q,{className:"h-4 w-1/2"})]}):l?e.jsxs("div",{className:"flex flex-col gap-6 px-6 py-5 text-sm",children:[e.jsxs("section",{className:"space-y-3",children:[e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:a("logs.detail.infoSection")}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 rounded-[1.15rem] border border-white/50 bg-background/70 p-3 text-xs shadow-[0_1px_2px_rgba(15,23,42,0.03)]",children:[e.jsx("span",{className:"font-medium",children:a("logs.detail.summary.route",{from:l.client_model??a("logs.detail.info.noRequestedModel"),to:l.model})}),e.jsx("span",{className:"text-muted-foreground",children:a("logs.detail.summary.latency",{value:C(l.latency_ms,a("common.units.ms"))})}),l.ttft_ms!==null&&e.jsxs("span",{className:"text-muted-foreground",children:["TTFT: ",C(l.ttft_ms,a("common.units.ms"))]}),e.jsx(P,{variant:l.error?"destructive":"default",children:m==null?void 0:m.toString()}),e.jsx(P,{variant:"outline",children:l.stream?a("logs.stream.streaming"):a("logs.stream.single")})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-3",children:[e.jsx(M,{label:a("logs.detail.info.latency"),value:C(l.latency_ms,a("common.units.ms"))}),e.jsx(M,{label:a("logs.detail.info.ttft"),value:C(l.ttft_ms,a("common.units.ms"))}),e.jsx(M,{label:a("logs.detail.info.tpot"),value:C(l.tpot_ms,a("common.units.msPerToken"))})]}),e.jsxs("dl",{className:"grid grid-cols-2 gap-x-4 gap-y-3",children:[e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:a("logs.detail.info.time")}),e.jsx("dd",{className:"font-medium",children:Pe(l.timestamp)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:a("logs.detail.info.sessionId")}),e.jsx("dd",{className:"font-medium",children:l.session_id??"-"})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:a("logs.detail.info.endpoint")}),e.jsx("dd",{className:"font-medium",children:l.endpoint||"-"})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:a("logs.detail.info.provider")}),e.jsx("dd",{className:"font-medium",children:S})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:a("logs.detail.info.requestedModel")}),e.jsx("dd",{className:"font-medium",children:l.client_model??a("logs.detail.info.noRequestedModel")})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:a("logs.detail.info.model")}),e.jsx("dd",{className:"font-medium",children:l.model})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:a("logs.detail.info.stream")}),e.jsx("dd",{className:"font-medium",children:ps(l.stream)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:a("logs.detail.info.status")}),e.jsx("dd",{className:"font-medium",children:m})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3 sm:grid-cols-4",children:[e.jsx(M,{label:a("logs.detail.info.inputTokens"),value:L(l.input_tokens)}),e.jsx(M,{label:a("logs.detail.info.cacheReadTokens"),value:L(l.cache_read_tokens)}),e.jsx(M,{label:a("logs.detail.info.cacheCreationTokens"),value:L(l.cache_creation_tokens)}),e.jsx(M,{label:a("logs.detail.info.outputTokens"),value:L(l.output_tokens)})]}),e.jsx("dl",{className:"grid grid-cols-2 gap-x-4 gap-y-3",children:e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:a("logs.detail.info.latency")}),e.jsx("dd",{className:"font-medium",children:C(l.latency_ms,a("common.units.ms"))})]})}),l.error&&e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:a("logs.detail.info.error")}),e.jsx("p",{className:"rounded-[1rem] border border-destructive/50 bg-destructive/10 p-3 text-xs text-destructive",children:l.error})]})]}),e.jsxs("section",{className:"space-y-3",children:[e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:a("logs.detail.apiKey.title")}),e.jsxs("dl",{className:"grid gap-x-4 gap-y-3 text-sm sm:grid-cols-2",children:[e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:a("logs.detail.apiKey.name")}),e.jsx("dd",{className:"font-medium",children:l.api_key_id==null&&!l.api_key_name?a("logs.detail.apiKey.missing"):r!=null&&r.isWildcard?a("apiKeys.wildcard"):(r==null?void 0:r.name)??l.api_key_name??a("logs.detail.apiKey.missing")})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:a("logs.detail.apiKey.identifier")}),e.jsx("dd",{className:"font-medium",children:l.api_key_id??a("common.noData")})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:a("logs.detail.apiKey.masked")}),e.jsx("dd",{className:"font-medium",children:r!=null&&r.isWildcard?a("apiKeys.wildcard"):(r==null?void 0:r.maskedKey)??l.api_key_name??a("logs.detail.apiKey.maskedUnavailable")})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:a("logs.detail.apiKey.lastUsed")}),e.jsx("dd",{className:"font-medium",children:r!=null&&r.lastUsedAt?new Date(r.lastUsedAt).toLocaleString():a("common.noData")})]})]}),e.jsxs("div",{className:"rounded-[1rem] border border-border/70 bg-background/70 p-3 text-xs",children:[e.jsx("p",{className:"font-medium",children:a("logs.detail.apiKey.rawMasked")}),e.jsx("p",{className:"mt-1 break-all font-mono",children:l.api_key_value_available?l.api_key_value_masked??a("logs.detail.apiKey.rawUnavailable"):a("logs.detail.apiKey.rawUnavailable")}),e.jsx("p",{className:"mt-2 text-[11px] text-muted-foreground",children:a("logs.detail.apiKey.rawMaskedHint")})]})]}),e.jsx("section",{className:"space-y-3",children:e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs(y,{variant:"outline",size:"sm",onClick:()=>{var u;return N(a("logs.detail.payload.request"),(u=l.payload)==null?void 0:u.prompt,"logs.detail.copy.requestSuccess")},children:[a("logs.detail.payload.request")," · ",a("common.actions.copy")]}),e.jsxs(y,{variant:"outline",size:"sm",onClick:()=>{var u;return N(a("logs.detail.payload.response"),(u=l.payload)==null?void 0:u.response,"logs.detail.copy.responseSuccess")},children:[a("logs.detail.payload.response")," · ",a("common.actions.copy")]})]})}),e.jsxs("section",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:a("logs.detail.payload.request")}),e.jsx(y,{variant:"outline",size:"sm",onClick:()=>{var u;return N(a("logs.detail.payload.request"),(u=l.payload)==null?void 0:u.prompt,"logs.detail.copy.requestSuccess")},children:a("common.actions.copy")})]}),e.jsx("pre",{className:"max-h-64 overflow-auto whitespace-pre-wrap rounded-[1rem] border border-border/70 bg-background/70 p-3 text-xs",children:$e((f=l.payload)==null?void 0:f.prompt,a("logs.detail.payload.emptyRequest"))})]}),e.jsxs("section",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:a("logs.detail.payload.response")}),e.jsx(y,{variant:"outline",size:"sm",onClick:()=>{var u;return N(a("logs.detail.payload.response"),(u=l.payload)==null?void 0:u.response,"logs.detail.copy.responseSuccess")},children:a("common.actions.copy")})]}),e.jsx("pre",{className:"max-h-64 overflow-auto whitespace-pre-wrap rounded-[1rem] border border-border/70 bg-background/70 p-3 text-xs",children:$e((p=l.payload)==null?void 0:p.response,a("logs.detail.payload.emptyResponse"))})]})]}):e.jsx("div",{className:"flex h-full items-center justify-center p-8 text-sm text-muted-foreground",children:a("logs.detail.loadError")})})]})]}),document.body)}function M({label:s,value:i}){return e.jsxs("div",{className:"rounded-xl border border-border/70 bg-background/60 px-3 py-3",children:[e.jsx("p",{className:"text-[11px] font-medium uppercase tracking-[0.16em] text-muted-foreground",children:s}),e.jsx("p",{className:"mt-2 text-sm font-semibold",children:i})]})}function js({apiKeys:s,selected:i,onChange:c,disabled:v,className:g}){const{t:a}=ae(),[d,j]=o.useState(!1),x=o.useRef(null);o.useEffect(()=>{if(!d)return;const r=m=>{var f;(f=x.current)!=null&&f.contains(m.target)||j(!1)};return window.addEventListener("mousedown",r),()=>window.removeEventListener("mousedown",r)},[d]);const N=o.useMemo(()=>{if(i.length===0)return[];const r=new Map;for(const m of s)r.set(m.id,m);return i.map(m=>{const f=r.get(m);return f?f.isWildcard?a("apiKeys.wildcard"):f.name:null}).filter(m=>!!m)},[s,i,a]),l=i.length===0?a("logs.filters.apiKeyAll"):a("logs.filters.apiKeySelected",{count:i.length}),S=r=>{i.includes(r)?c(i.filter(m=>m!==r)):c([...i,r])};return e.jsxs("div",{className:h("relative space-y-2",g),ref:x,children:[e.jsx(O,{children:a("logs.filters.apiKey")}),e.jsxs("button",{type:"button",onClick:()=>j(r=>!r),disabled:v||s.length===0,title:a("logs.filters.apiKeyHint"),className:h("flex h-11 w-full items-center justify-between rounded-2xl border border-border/80 bg-background/85 px-4 text-sm shadow-[0_1px_2px_rgba(15,23,42,0.03)] ring-offset-background transition-all duration-200 focus:outline-none focus:ring-2 focus:ring-ring/30 focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",i.length>0&&"border-primary",d&&"ring-2 ring-ring ring-offset-2"),children:[e.jsxs("span",{className:"truncate",children:[l,N.length>0&&e.jsx("span",{className:"ml-1 text-xs text-muted-foreground",children:N.join(", ")})]}),e.jsx("svg",{className:h("h-4 w-4 opacity-50 transition-transform",d&&"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"})})]}),d&&e.jsxs("div",{className:"absolute left-0 top-full z-30 mt-2 w-64 rounded-[1.2rem] border border-white/60 bg-popover/95 p-2 shadow-[0_16px_40px_-28px_rgba(15,23,42,0.45)] backdrop-blur",children:[e.jsxs("div",{className:"flex items-center justify-between rounded-xl bg-background/70 px-3 py-2 text-xs",children:[e.jsx("span",{children:l}),e.jsx("button",{type:"button",onClick:()=>c([]),disabled:i.length===0,className:"text-primary hover:underline disabled:opacity-40",children:a("common.actions.reset")})]}),e.jsxs("div",{className:"max-h-56 overflow-y-auto py-2",children:[s.map(r=>{const m=r.isWildcard?a("apiKeys.wildcard"):r.name,f=i.includes(r.id);return e.jsxs("label",{className:h("flex cursor-pointer items-center gap-2 rounded-xl px-3 py-2 text-sm transition hover:bg-primary/5",f&&"bg-primary/10 text-primary"),children:[e.jsx("input",{type:"checkbox",className:"h-4 w-4 rounded border-border",checked:f,onChange:()=>S(r.id)}),e.jsx("span",{className:"truncate",children:m})]},r.id)}),s.length===0&&e.jsx("p",{className:"px-2 py-2 text-xs text-muted-foreground",children:a("logs.filters.apiKeyAll")})]})]})]})}export{Os as default};
|
|
1
|
+
import{r as o,f as e,ac as Ze,ad as Xe,Z as es,ae as ss,af as ts,a5 as Fe,h as as}from"./vendor-C92xTG6Z.js";import{u as Ke,a as ls,t as rs,c as h,B as y}from"./index-BuTkie0t.js";import{u as A}from"./useApiQuery-BkAH5SvI.js";import{T as os,a as Q}from"./Skeleton-CN-bCufq.js";import{P as ns,B as P}from"./PageHeader-Da1cmUY0.js";import{c as is}from"./clipboard-CALi6bTW.js";import{I as me}from"./input-BHq9dQGf.js";import{L as O}from"./label-CUv6yhdE.js";import{C as Re,a as De}from"./card-BD2y3CjZ.js";import{S as Z,a as X,b as ee,c as se,d as T}from"./select-Dq7kCMCk.js";import{P as ds,a as cs,b as ms}from"./popover-0Ho_T06s.js";import{u as ae}from"./i18n-CZ1qKIdj.js";import"./router-DjNibHfR.js";import"./radix-Ccu1urVd.js";import"./query-CDpWKdnY.js";const Me=[20,50,100],ze="cc-gw.logs.visible-columns",Ae="cc-gw.logs.density",$=["endpoint","provider","requestedModel","routedModel","apiKey","inputTokens","outputTokens","latency","status","error"],te=["endpoint","provider","requestedModel","routedModel","apiKey","inputTokens","cacheReadTokens","cacheCreationTokens","outputTokens","latency","ttft","tpot","status","error"];function xs(){if(typeof window>"u")return $;try{const s=window.localStorage.getItem(ze);if(!s)return $;const i=JSON.parse(s);if(!Array.isArray(i))return $;const c=i.filter(v=>te.includes(v));return c.length>0?c:$}catch{return $}}function us(){return typeof window>"u"?"comfortable":window.localStorage.getItem(Ae)==="compact"?"compact":"comfortable"}function Oe(s,i=!1){if(!s)return;const c=i?`${s}T23:59:59.999`:`${s}T00:00:00.000`,v=Date.parse(c);return Number.isFinite(v)?v:void 0}function Pe(s){const i=new Date(s);return`${i.getFullYear()}-${`${i.getMonth()+1}`.padStart(2,"0")}-${`${i.getDate()}`.padStart(2,"0")} ${`${i.getHours()}`.padStart(2,"0")}:${`${i.getMinutes()}`.padStart(2,"0")}:${`${i.getSeconds()}`.padStart(2,"0")}`}function L(s){return s==null?"-":s.toLocaleString()}function C(s,i){const c=L(s);return c==="-"?"-":`${c} ${i}`}function ps(s){return s?"true":"false"}function $e(s,i){if(!s||s.trim().length===0)return i;try{const c=JSON.parse(s);return JSON.stringify(c,null,2)}catch{return s}}function hs(s,i,c){return s===c&&i===c}function Os(){var ke,_e,Se,Ee,Te,Ce;const{t:s}=ae(),{pushToast:i}=Ke(),[c,v]=o.useState("all"),[g,a]=o.useState("all"),[d,j]=o.useState(""),[x,N]=o.useState("all"),[l,S]=o.useState(""),[r,m]=o.useState(""),[f,p]=o.useState(1),[u,F]=o.useState(Me[0]),[le,I]=o.useState(null),[Ie,xe]=o.useState(!1),[w,re]=o.useState([]),[H,ue]=o.useState(!1),[pe,qe]=o.useState(!1),[q,he]=o.useState(us),[R,fe]=o.useState(xs),[Ue,Ge]=o.useState(!1),oe=o.useRef(null);o.useEffect(()=>{typeof window>"u"||window.localStorage.setItem(Ae,q)},[q]),o.useEffect(()=>{typeof window>"u"||window.localStorage.setItem(ze,JSON.stringify(R))},[R]),o.useEffect(()=>{p(1)},[c,g,d,x,l,r,u,w]);const W=o.useMemo(()=>{const t={limit:u,offset:(f-1)*u};c!=="all"&&(t.provider=c),g!=="all"&&(t.endpoint=g),d.trim().length>0&&(t.model=d.trim()),x!=="all"&&(t.status=x);const n=Oe(l),_=Oe(r,!0);return n!==void 0&&(t.from=n),_!==void 0&&(t.to=_),w.length>0&&(t.apiKeys=w.join(",")),t},[c,g,d,x,l,r,f,u,w]),k=A(["logs",W],{url:"/api/logs",method:"GET",params:W}),K=A(["providers","all"],{url:"/api/providers",method:"GET"}),ge=A(["api-keys"],{url:"/api/keys",method:"GET"}),ne=A(["custom-endpoints"],{url:"/api/custom-endpoints",method:"GET"}),je=A(["config","export-timeout"],{url:"/api/config",method:"GET"});o.useEffect(()=>{k.isError&&k.error&&i({title:s("logs.toast.listError.title"),description:s("logs.toast.listError.desc",{message:k.error.message}),variant:"error"})},[k.isError,k.error,i,s]),o.useEffect(()=>{K.isError&&K.error&&i({title:s("logs.toast.providerError.title"),description:s("logs.toast.providerError.desc",{message:K.error.message}),variant:"error"})},[K.isError,K.error,i,s]);const D=((ke=k.data)==null?void 0:ke.total)??0,E=D>0?Math.ceil(D/u):0,be=((_e=k.data)==null?void 0:_e.items)??[],ye=o.useMemo(()=>{var n;const t=(n=je.data)==null?void 0:n.logExportTimeoutSeconds;return typeof t=="number"&&Number.isFinite(t)?Math.min(Math.max(Math.round(t),5),600)*1e3:6e4},[(Se=je.data)==null?void 0:Se.logExportTimeoutSeconds]);o.useEffect(()=>{E>0&&f>E&&p(E)},[E,f]);const ie=K.data??[],J=o.useMemo(()=>{const t=new Map;for(const n of ie)n.id&&t.set(n.id,n.label??n.id);return t},[ie]),ve=o.useMemo(()=>{var n;const t=new Map;t.set("anthropic",s("logs.filters.endpointAnthropic")),t.set("openai",s("logs.filters.endpointOpenAI"));for(const _ of((n=ne.data)==null?void 0:n.endpoints)??[])t.set(_.id,_.label||_.id);return t},[(Ee=ne.data)==null?void 0:Ee.endpoints,s]),z=o.useMemo(()=>{const t=[];if(c!=="all"){const n=J.get(c)??c;t.push({key:"provider",label:`${s("logs.filters.provider")}: ${n}`,onRemove:()=>v("all")})}if(g!=="all"){const n=ve.get(g)??g;t.push({key:"endpoint",label:`${s("logs.filters.endpoint")}: ${n}`,onRemove:()=>a("all")})}if(d.trim()&&t.push({key:"model",label:`${s("logs.filters.modelId")}: ${d.trim()}`,onRemove:()=>j("")}),x!=="all"){const n=s(x==="success"?"logs.filters.statusSuccess":"logs.filters.statusError");t.push({key:"status",label:`${s("logs.filters.status")}: ${n}`,onRemove:()=>N("all")})}return l&&t.push({key:"from",label:`${s("logs.filters.startDate")}: ${l}`,onRemove:()=>S("")}),r&&t.push({key:"to",label:`${s("logs.filters.endDate")}: ${r}`,onRemove:()=>m("")}),w.length>0&&t.push({key:"apiKeys",label:s("logs.filters.apiKeySelected",{count:w.length}),onRemove:()=>re([])}),t},[c,J,g,ve,d,x,l,r,w,s]),de=ge.data??[],Ne=o.useMemo(()=>{const t=new Map;for(const n of de)t.set(n.id,n);return t},[de]),b=o.useMemo(()=>new Set(R),[R]),Be=o.useMemo(()=>te.map(t=>({id:t,label:s(`logs.table.columns.${t}`)})),[s]),we=R.length+2,U=o.useMemo(()=>new Date().toISOString().slice(0,10),[]),Ve=o.useMemo(()=>c==="all"&&g==="all"&&d.trim()===""&&x==="all"&&l===""&&r===""&&w.length===0?"all":x==="error"&&g==="all"&&c==="all"&&d.trim()===""&&l===""&&r===""&&w.length===0?"errors":hs(l,r,U)&&g==="all"&&c==="all"&&d.trim()===""&&x==="all"&&w.length===0?"today":g==="anthropic"&&c==="all"&&d.trim()===""&&x==="all"&&l===""&&r===""&&w.length===0?"anthropic":g==="openai"&&c==="all"&&d.trim()===""&&x==="all"&&l===""&&r===""&&w.length===0?"openai":null,[g,l,d,c,w.length,x,r,U]),Qe=o.useCallback(t=>{fe(n=>{if(n.includes(t))return n.length===1?n:n.filter(B=>B!==t);const _=[...n,t];return _.sort((B,ce)=>te.indexOf(B)-te.indexOf(ce)),_})},[]),Y=o.useCallback(()=>{v("all"),j(""),a("all"),N("all"),S(""),m(""),re([])},[]),He=o.useCallback(t=>{if(p(1),Y(),t!=="all"){if(t==="errors"){N("error");return}if(t==="today"){S(U),m(U);return}if(t==="anthropic"){a("anthropic");return}t==="openai"&&a("openai")}},[Y,U]),We=o.useCallback(async()=>{if(!H){ue(!0);try{const t=D>0?Math.min(D,5e3):1e3,n={...W,limit:t,offset:0},_=await ls.post("/api/logs/export",n,{responseType:"blob",timeout:ye}),B=new Blob([_.data],{type:"application/zip"}),ce=new Date().toISOString().replace(/[:.]/g,"-"),Le=URL.createObjectURL(B),V=document.createElement("a");V.href=Le,V.download=`cc-gw-logs-${ce}.zip`,document.body.appendChild(V),V.click(),V.remove(),URL.revokeObjectURL(Le),i({title:s("logs.toast.exportSuccess.title"),description:s("logs.toast.exportSuccess.desc"),variant:"success"})}catch(t){const n=rs(t);i({title:s("logs.toast.exportError.title"),description:s("logs.toast.exportError.desc",{message:n.message}),variant:"error"})}finally{ue(!1)}}},[ye,H,i,W,s,D]),Je=o.useCallback(t=>{I(t),xe(!0)},[]),Ye=o.useCallback(()=>{xe(!1),I(null)},[]),G=o.useCallback(()=>{const t=oe.current;if(!t)return;const n=t.scrollWidth-t.scrollLeft-t.clientWidth>1;Ge(n)},[]);return o.useEffect(()=>{const t=oe.current;if(!t)return;G(),t.addEventListener("scroll",G,{passive:!0});const n=new ResizeObserver(G);return n.observe(t),()=>{t.removeEventListener("scroll",G),n.disconnect()}},[G]),e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx(ns,{icon:e.jsx(es,{className:"h-5 w-5","aria-hidden":"true"}),title:s("logs.title"),description:s("logs.description"),eyebrow:"Traffic Explorer",breadcrumb:"Gateway / Logs",helper:s("logs.filtersDescription"),actions:e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsxs("div",{className:"flex items-center gap-1 rounded-full border border-border/70 bg-background/80 p-1 shadow-[0_1px_2px_rgba(15,23,42,0.03)]",children:[e.jsx("button",{type:"button",onClick:()=>he("comfortable"),className:h("inline-flex h-8 items-center rounded-full px-3.5 text-xs font-medium transition-all",q==="comfortable"?"bg-primary text-primary-foreground shadow-[0_8px_18px_-14px_rgba(59,130,246,0.7)]":"text-muted-foreground hover:bg-primary/5 hover:text-foreground"),children:s("logs.table.density.comfortable")}),e.jsx("button",{type:"button",onClick:()=>he("compact"),className:h("inline-flex h-8 items-center rounded-full px-3.5 text-xs font-medium transition-all",q==="compact"?"bg-primary text-primary-foreground shadow-[0_8px_18px_-14px_rgba(59,130,246,0.7)]":"text-muted-foreground hover:bg-primary/5 hover:text-foreground"),children:s("logs.table.density.compact")})]}),e.jsxs(ds,{children:[e.jsx(cs,{asChild:!0,children:e.jsx(y,{variant:"outline",size:"sm",children:s("logs.actions.columns")})}),e.jsxs(ms,{align:"end",className:"w-64 rounded-[1.2rem] border-white/60 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:s("logs.actions.columns")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("logs.actions.visibleCount",{count:R.length})})]}),e.jsx(y,{variant:"ghost",size:"sm",onClick:()=>fe($),disabled:JSON.stringify(R)===JSON.stringify($),children:s("common.actions.reset")})]}),e.jsx("div",{className:"grid gap-1.5",children:Be.map(t=>{const n=b.has(t.id);return e.jsxs("label",{className:h("flex cursor-pointer items-center gap-3 rounded-xl px-3 py-2 text-sm transition hover:bg-primary/5",n&&"bg-primary/10 text-primary"),children:[e.jsx("input",{type:"checkbox",checked:n,onChange:()=>Qe(t.id),className:"h-4 w-4 rounded border-border"}),e.jsx("span",{children:t.label})]},t.id)})})]})]}),e.jsxs(y,{onClick:We,disabled:H,children:[e.jsx(Ze,{className:"mr-2 h-4 w-4"}),s(H?"common.actions.loading":"logs.actions.export")]}),e.jsx("span",{className:"text-sm text-muted-foreground",children:s("logs.summary.total",{value:D.toLocaleString()})}),e.jsxs(y,{variant:"outline",size:"sm",onClick:()=>k.refetch(),disabled:k.isFetching,children:[e.jsx(Xe,{className:h("mr-2 h-4 w-4",k.isFetching&&"animate-spin")}),k.isFetching?s("common.actions.refreshing"):s("logs.actions.manualRefresh")]})]})}),e.jsx(Re,{className:"sticky top-20 z-20 border-white/40 bg-card/90 backdrop-blur",children:e.jsxs(De,{className:"pt-4",children:[e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("p",{className:"text-sm font-semibold text-foreground",children:s("logs.filtersTitle")}),e.jsx(P,{variant:"outline",children:s("logs.summary.total",{value:D.toLocaleString()})}),z.length>0&&e.jsx(P,{variant:"secondary",children:s("common.filters.activeCount",{count:z.length})})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("logs.filtersDescription")})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[z.length>0&&e.jsx(y,{variant:"ghost",size:"sm",onClick:Y,children:s("common.actions.reset")}),e.jsx(y,{variant:"ghost",size:"sm",onClick:()=>qe(t=>!t),children:pe?e.jsxs(e.Fragment,{children:[s("common.filters.collapse"),e.jsx(ss,{className:"ml-1 h-4 w-4"})]}):e.jsxs(e.Fragment,{children:[s("common.filters.expand"),e.jsx(ts,{className:"ml-1 h-4 w-4"})]})})]})]}),e.jsx("div",{className:"flex items-center justify-between gap-3",children:e.jsx("div",{className:"flex flex-1 items-center gap-3 overflow-hidden",children:z.length>0?e.jsx("div",{className:"flex flex-wrap items-center gap-2",children:z.map(t=>e.jsxs(P,{variant:"secondary",role:"button",tabIndex:0,className:"cursor-pointer gap-1 hover:bg-destructive/10 hover:text-destructive",onClick:t.onRemove,onKeyDown:n=>{(n.key==="Enter"||n.key===" ")&&(n.preventDefault(),t.onRemove())},children:[t.label,e.jsx(Fe,{className:"h-3 w-3","aria-hidden":"true"})]},t.key))}):e.jsx("span",{className:"text-sm text-muted-foreground",children:s("common.filters.allRequests")})})}),e.jsx("div",{className:"flex flex-wrap items-center gap-2",children:["all","errors","today","anthropic","openai"].map(t=>e.jsx(y,{variant:Ve===t?"default":"outline",size:"sm",className:"rounded-full",onClick:()=>He(t),children:s(`logs.quickViews.${t}`)},t))})]}),pe&&e.jsxs("div",{className:"mt-4 grid gap-4 md:grid-cols-2 xl:grid-cols-4 animate-in fade-in slide-in-from-top-2 duration-200",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(O,{children:s("logs.filters.provider")}),e.jsxs(Z,{value:c,onValueChange:v,children:[e.jsx(X,{children:e.jsx(ee,{})}),e.jsxs(se,{children:[e.jsx(T,{value:"all",children:s("logs.filters.providerAll")}),ie.map(t=>e.jsx(T,{value:t.id,children:t.label??t.id},t.id))]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(O,{children:s("logs.filters.endpoint")}),e.jsxs(Z,{value:g,onValueChange:a,children:[e.jsx(X,{children:e.jsx(ee,{})}),e.jsxs(se,{children:[e.jsx(T,{value:"all",children:s("logs.filters.endpointAll")}),e.jsx(T,{value:"anthropic",children:s("logs.filters.endpointAnthropic")}),e.jsx(T,{value:"openai",children:s("logs.filters.endpointOpenAI")}),(Ce=(Te=ne.data)==null?void 0:Te.endpoints)==null?void 0:Ce.map(t=>e.jsx(T,{value:t.id,children:t.label||t.id},t.id))]})]})]}),e.jsx(js,{className:"md:col-span-2",apiKeys:de,selected:w,disabled:ge.isLoading,onChange:re}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(O,{children:s("logs.filters.modelId")}),e.jsx(me,{value:d,onChange:t=>j(t.target.value),placeholder:s("logs.filters.modelPlaceholder")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(O,{children:s("logs.filters.status")}),e.jsxs(Z,{value:x,onValueChange:t=>N(t),children:[e.jsx(X,{children:e.jsx(ee,{})}),e.jsxs(se,{children:[e.jsx(T,{value:"all",children:s("logs.filters.statusAll")}),e.jsx(T,{value:"success",children:s("logs.filters.statusSuccess")}),e.jsx(T,{value:"error",children:s("logs.filters.statusError")})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(O,{children:s("logs.filters.startDate")}),e.jsx(me,{type:"date",value:l,onChange:t=>S(t.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(O,{children:s("logs.filters.endDate")}),e.jsx(me,{type:"date",value:r,onChange:t=>m(t.target.value)})]})]})]})}),e.jsx(Re,{children:e.jsxs(De,{className:"p-0",children:[e.jsxs("div",{className:"relative",children:[e.jsx("div",{ref:oe,className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full min-w-[1200px] text-sm",children:[e.jsx("thead",{className:"border-b bg-muted/50",children:e.jsxs("tr",{children:[e.jsx("th",{className:"sticky left-0 z-20 bg-muted/95 px-3 py-2 text-left text-xs font-medium backdrop-blur",children:s("logs.table.columns.time")}),b.has("endpoint")&&e.jsx("th",{className:"px-3 py-2 text-left text-xs font-medium",children:s("logs.table.columns.endpoint")}),b.has("provider")&&e.jsx("th",{className:"px-3 py-2 text-left text-xs font-medium",children:s("logs.table.columns.provider")}),b.has("requestedModel")&&e.jsx("th",{className:"px-3 py-2 text-left text-xs font-medium",children:s("logs.table.columns.requestedModel")}),b.has("routedModel")&&e.jsx("th",{className:"px-3 py-2 text-left text-xs font-medium",children:s("logs.table.columns.routedModel")}),b.has("apiKey")&&e.jsx("th",{className:"px-3 py-2 text-left text-xs font-medium",children:s("logs.table.columns.apiKey")}),b.has("inputTokens")&&e.jsx("th",{className:"px-3 py-2 text-right text-xs font-medium",children:s("logs.table.columns.inputTokens")}),b.has("cacheReadTokens")&&e.jsx("th",{className:"px-3 py-2 text-right text-xs font-medium",children:s("logs.table.columns.cacheReadTokens")}),b.has("cacheCreationTokens")&&e.jsx("th",{className:"px-3 py-2 text-right text-xs font-medium",children:s("logs.table.columns.cacheCreationTokens")}),b.has("outputTokens")&&e.jsx("th",{className:"px-3 py-2 text-right text-xs font-medium",children:s("logs.table.columns.outputTokens")}),b.has("latency")&&e.jsx("th",{className:"px-3 py-2 text-right text-xs font-medium",children:s("logs.table.columns.latency")}),b.has("ttft")&&e.jsx("th",{className:"px-3 py-2 text-right text-xs font-medium",children:s("logs.table.columns.ttft")}),b.has("tpot")&&e.jsx("th",{className:"px-3 py-2 text-right text-xs font-medium",children:s("logs.table.columns.tpot")}),b.has("status")&&e.jsx("th",{className:"px-3 py-2 text-center text-xs font-medium",children:s("logs.table.columns.status")}),b.has("error")&&e.jsx("th",{className:"px-3 py-2 text-left text-xs font-medium",children:s("logs.table.columns.error")}),e.jsx("th",{className:"sticky right-0 z-20 bg-muted/95 px-3 py-2 text-center text-xs font-medium backdrop-blur",children:s("logs.table.columns.actions")})]})}),e.jsx("tbody",{className:"divide-y",children:k.isPending?Array.from({length:8}).map((t,n)=>e.jsx(os,{columns:we},n)):be.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:we,className:"px-3 py-8 text-center text-sm text-muted-foreground",children:e.jsxs("div",{className:"flex flex-col items-center gap-3 py-4",children:[e.jsx("span",{children:s("logs.table.empty")}),z.length>0&&e.jsx(y,{variant:"outline",size:"sm",onClick:Y,children:s("common.actions.reset")})]})})}):be.map((t,n)=>e.jsx(fs,{record:t,providerLabelMap:J,apiKeyMap:Ne,onSelect:Je,isEven:n%2===0,density:q,visibleColumnSet:b},t.id))})]})}),Ue&&e.jsx("div",{className:"table-scroll-hint"})]}),e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-4 border-t p-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:s("logs.table.pagination.perPage")}),e.jsxs(Z,{value:u.toString(),onValueChange:t=>F(Number(t)),children:[e.jsx(X,{className:"w-[80px]",children:e.jsx(ee,{})}),e.jsx(se,{children:Me.map(t=>e.jsx(T,{value:t.toString(),children:t},t))})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(y,{variant:"outline",size:"sm",onClick:()=>p(t=>Math.max(t-1,1)),disabled:f<=1,children:s("logs.table.pagination.previous")}),e.jsx("span",{className:"text-sm text-muted-foreground",children:s("logs.table.pagination.pageLabel",{page:E===0?0:f,total:E})}),e.jsx(y,{variant:"outline",size:"sm",onClick:()=>p(t=>E===0?t:Math.min(t+1,E)),disabled:E===0||f>=E,children:s("logs.table.pagination.next")})]})]})]})}),e.jsx(gs,{open:Ie,logId:le,onClose:Ye,providerLabelMap:J,apiKeyMap:Ne})]})}function fs({record:s,providerLabelMap:i,apiKeyMap:c,onSelect:v,isEven:g,density:a,visibleColumnSet:d}){const{t:j}=ae(),x=i.get(s.provider)??s.provider,N=s.endpoint||"-",l=!!s.error,S=s.status_code,r=s.client_model??j("logs.table.requestedModelFallback"),m=s.api_key_id!=null?c.get(s.api_key_id):void 0,f=s.api_key_id==null?j("logs.table.apiKeyUnknown"):m!=null&&m.isWildcard?j("apiKeys.wildcard"):m!=null&&m.name?m.name:s.api_key_name?s.api_key_name:j("logs.table.apiKeyUnknown"),p=a==="compact"?"px-3 py-1.5":"px-3 py-2",u=g?"bg-muted/30":"bg-background";return e.jsxs("tr",{className:h("transition-colors",g?"bg-muted/30":"","hover:bg-muted/50"),children:[e.jsx("td",{className:h("sticky left-0 z-10 text-xs",p,u),children:Pe(s.timestamp)}),d.has("endpoint")&&e.jsx("td",{className:h(p,"text-xs"),children:N}),d.has("provider")&&e.jsx("td",{className:h(p,"text-xs"),children:e.jsx("div",{className:"max-w-[100px] truncate",title:x,children:x})}),d.has("requestedModel")&&e.jsx("td",{className:h(p,"text-xs text-muted-foreground"),children:e.jsx("div",{className:"max-w-[120px] truncate",title:r,children:r})}),d.has("routedModel")&&e.jsx("td",{className:h(p,"text-xs"),children:e.jsx("div",{className:"max-w-[120px] truncate",title:s.model,children:s.model})}),d.has("apiKey")&&e.jsx("td",{className:h(p,"text-xs text-muted-foreground"),children:e.jsx("div",{className:"max-w-[90px] truncate",title:f,children:f})}),d.has("inputTokens")&&e.jsx("td",{className:h(p,"text-right text-xs tabular-nums"),children:L(s.input_tokens)}),d.has("cacheReadTokens")&&e.jsx("td",{className:h(p,"text-right text-xs tabular-nums"),children:L(s.cache_read_tokens)}),d.has("cacheCreationTokens")&&e.jsx("td",{className:h(p,"text-right text-xs tabular-nums"),children:L(s.cache_creation_tokens)}),d.has("outputTokens")&&e.jsx("td",{className:h(p,"text-right text-xs tabular-nums"),children:L(s.output_tokens)}),d.has("latency")&&e.jsx("td",{className:h(p,"text-right text-xs tabular-nums"),children:C(s.latency_ms,"ms")}),d.has("ttft")&&e.jsx("td",{className:h(p,"text-right text-xs tabular-nums"),children:C(s.ttft_ms,"ms")}),d.has("tpot")&&e.jsx("td",{className:h(p,"text-right text-xs tabular-nums"),children:C(s.tpot_ms,"ms/tk")}),d.has("status")&&e.jsx("td",{className:h(p,"text-center"),children:e.jsx(P,{variant:l?"destructive":"default",className:"text-xs",children:S??(l?500:200)})}),d.has("error")&&e.jsx("td",{className:h(p,"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:h("sticky right-0 z-10 text-center",p,u),children:e.jsx(y,{variant:"outline",size:"sm",onClick:()=>v(s.id),children:j("logs.actions.detail")})})]})}function gs({open:s,logId:i,onClose:c,providerLabelMap:v,apiKeyMap:g}){var f,p;const{t:a}=ae(),{pushToast:d}=Ke(),j=o.useRef(null),x=A(["log-detail",i],{url:`/api/logs/${i}`,method:"GET"},{enabled:s&&i!==null,staleTime:3e4});o.useEffect(()=>{x.isError&&x.error&&d({title:a("logs.detail.loadError"),description:x.error.message,variant:"error"})},[x.isError,x.error,d,a]),o.useEffect(()=>{if(!s)return;const u=F=>{F.key==="Escape"&&c()};return window.addEventListener("keydown",u),()=>window.removeEventListener("keydown",u)},[s,c]),o.useEffect(()=>{s&&j.current&&j.current.focus()},[s,i]);const N=o.useCallback(async(u,F,le)=>{if(!F){d({title:a("logs.detail.copy.empty",{label:u}),variant:"info"});return}try{await is(F),d({title:a(le),variant:"success"})}catch(I){d({title:a("logs.detail.copy.failure"),description:I instanceof Error?I.message:a("logs.detail.copy.failureFallback"),variant:"error"})}},[d,a]);if(!s)return null;const l=x.data,S=l?v.get(l.provider)??l.provider:"",r=l&&l.api_key_id!=null?g.get(l.api_key_id):void 0,m=l?l.status_code??(l.error?500:200):null;return typeof document>"u"?null:as.createPortal(e.jsxs("div",{className:"fixed inset-0 z-50 flex",children:[e.jsx("div",{className:"flex-1 bg-background/80 backdrop-blur-sm animate-in fade-in duration-200",onClick:c}),e.jsxs("aside",{role:"dialog","aria-modal":"true",className:"flex h-full w-full max-w-xl flex-col border-l bg-card shadow-xl animate-in slide-in-from-right duration-300",children:[e.jsxs("header",{className:"flex items-center justify-between border-b px-6 py-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-semibold",children:a("logs.detail.title")}),l&&e.jsx("p",{className:"text-xs text-muted-foreground",children:a("logs.detail.id",{id:l.id})})]}),e.jsxs(y,{ref:j,variant:"outline",size:"sm",onClick:c,children:[e.jsx(Fe,{className:"mr-2 h-4 w-4"}),a("common.actions.close")]})]}),e.jsx("div",{className:"flex-1 overflow-y-auto",children:x.isPending?e.jsxs("div",{className:"flex flex-col gap-4 p-6",children:[e.jsx(Q,{className:"h-5 w-40"}),e.jsx(Q,{className:"h-4 w-full"}),e.jsx(Q,{className:"h-4 w-3/4"}),e.jsx(Q,{className:"h-32 w-full"}),e.jsx(Q,{className:"h-4 w-1/2"})]}):l?e.jsxs("div",{className:"flex flex-col gap-6 px-6 py-5 text-sm",children:[e.jsxs("section",{className:"space-y-3",children:[e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:a("logs.detail.infoSection")}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 rounded-[1.15rem] border border-white/50 bg-background/70 p-3 text-xs shadow-[0_1px_2px_rgba(15,23,42,0.03)]",children:[e.jsx("span",{className:"font-medium",children:a("logs.detail.summary.route",{from:l.client_model??a("logs.detail.info.noRequestedModel"),to:l.model})}),e.jsx("span",{className:"text-muted-foreground",children:a("logs.detail.summary.latency",{value:C(l.latency_ms,a("common.units.ms"))})}),l.ttft_ms!==null&&e.jsxs("span",{className:"text-muted-foreground",children:["TTFT: ",C(l.ttft_ms,a("common.units.ms"))]}),e.jsx(P,{variant:l.error?"destructive":"default",children:m==null?void 0:m.toString()}),e.jsx(P,{variant:"outline",children:l.stream?a("logs.stream.streaming"):a("logs.stream.single")})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-3",children:[e.jsx(M,{label:a("logs.detail.info.latency"),value:C(l.latency_ms,a("common.units.ms"))}),e.jsx(M,{label:a("logs.detail.info.ttft"),value:C(l.ttft_ms,a("common.units.ms"))}),e.jsx(M,{label:a("logs.detail.info.tpot"),value:C(l.tpot_ms,a("common.units.msPerToken"))})]}),e.jsxs("dl",{className:"grid grid-cols-2 gap-x-4 gap-y-3",children:[e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:a("logs.detail.info.time")}),e.jsx("dd",{className:"font-medium",children:Pe(l.timestamp)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:a("logs.detail.info.sessionId")}),e.jsx("dd",{className:"font-medium",children:l.session_id??"-"})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:a("logs.detail.info.endpoint")}),e.jsx("dd",{className:"font-medium",children:l.endpoint||"-"})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:a("logs.detail.info.provider")}),e.jsx("dd",{className:"font-medium",children:S})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:a("logs.detail.info.requestedModel")}),e.jsx("dd",{className:"font-medium",children:l.client_model??a("logs.detail.info.noRequestedModel")})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:a("logs.detail.info.model")}),e.jsx("dd",{className:"font-medium",children:l.model})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:a("logs.detail.info.stream")}),e.jsx("dd",{className:"font-medium",children:ps(l.stream)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:a("logs.detail.info.status")}),e.jsx("dd",{className:"font-medium",children:m})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3 sm:grid-cols-4",children:[e.jsx(M,{label:a("logs.detail.info.inputTokens"),value:L(l.input_tokens)}),e.jsx(M,{label:a("logs.detail.info.cacheReadTokens"),value:L(l.cache_read_tokens)}),e.jsx(M,{label:a("logs.detail.info.cacheCreationTokens"),value:L(l.cache_creation_tokens)}),e.jsx(M,{label:a("logs.detail.info.outputTokens"),value:L(l.output_tokens)})]}),e.jsx("dl",{className:"grid grid-cols-2 gap-x-4 gap-y-3",children:e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:a("logs.detail.info.latency")}),e.jsx("dd",{className:"font-medium",children:C(l.latency_ms,a("common.units.ms"))})]})}),l.error&&e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:a("logs.detail.info.error")}),e.jsx("p",{className:"rounded-[1rem] border border-destructive/50 bg-destructive/10 p-3 text-xs text-destructive",children:l.error})]})]}),e.jsxs("section",{className:"space-y-3",children:[e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:a("logs.detail.apiKey.title")}),e.jsxs("dl",{className:"grid gap-x-4 gap-y-3 text-sm sm:grid-cols-2",children:[e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:a("logs.detail.apiKey.name")}),e.jsx("dd",{className:"font-medium",children:l.api_key_id==null&&!l.api_key_name?a("logs.detail.apiKey.missing"):r!=null&&r.isWildcard?a("apiKeys.wildcard"):(r==null?void 0:r.name)??l.api_key_name??a("logs.detail.apiKey.missing")})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:a("logs.detail.apiKey.identifier")}),e.jsx("dd",{className:"font-medium",children:l.api_key_id??a("common.noData")})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:a("logs.detail.apiKey.masked")}),e.jsx("dd",{className:"font-medium",children:r!=null&&r.isWildcard?a("apiKeys.wildcard"):(r==null?void 0:r.maskedKey)??l.api_key_name??a("logs.detail.apiKey.maskedUnavailable")})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:a("logs.detail.apiKey.lastUsed")}),e.jsx("dd",{className:"font-medium",children:r!=null&&r.lastUsedAt?new Date(r.lastUsedAt).toLocaleString():a("common.noData")})]})]}),e.jsxs("div",{className:"rounded-[1rem] border border-border/70 bg-background/70 p-3 text-xs",children:[e.jsx("p",{className:"font-medium",children:a("logs.detail.apiKey.rawMasked")}),e.jsx("p",{className:"mt-1 break-all font-mono",children:l.api_key_value_available?l.api_key_value_masked??a("logs.detail.apiKey.rawUnavailable"):a("logs.detail.apiKey.rawUnavailable")}),e.jsx("p",{className:"mt-2 text-[11px] text-muted-foreground",children:a("logs.detail.apiKey.rawMaskedHint")})]})]}),e.jsx("section",{className:"space-y-3",children:e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs(y,{variant:"outline",size:"sm",onClick:()=>{var u;return N(a("logs.detail.payload.request"),(u=l.payload)==null?void 0:u.prompt,"logs.detail.copy.requestSuccess")},children:[a("logs.detail.payload.request")," · ",a("common.actions.copy")]}),e.jsxs(y,{variant:"outline",size:"sm",onClick:()=>{var u;return N(a("logs.detail.payload.response"),(u=l.payload)==null?void 0:u.response,"logs.detail.copy.responseSuccess")},children:[a("logs.detail.payload.response")," · ",a("common.actions.copy")]})]})}),e.jsxs("section",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:a("logs.detail.payload.request")}),e.jsx(y,{variant:"outline",size:"sm",onClick:()=>{var u;return N(a("logs.detail.payload.request"),(u=l.payload)==null?void 0:u.prompt,"logs.detail.copy.requestSuccess")},children:a("common.actions.copy")})]}),e.jsx("pre",{className:"max-h-64 overflow-auto whitespace-pre-wrap rounded-[1rem] border border-border/70 bg-background/70 p-3 text-xs",children:$e((f=l.payload)==null?void 0:f.prompt,a("logs.detail.payload.emptyRequest"))})]}),e.jsxs("section",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:a("logs.detail.payload.response")}),e.jsx(y,{variant:"outline",size:"sm",onClick:()=>{var u;return N(a("logs.detail.payload.response"),(u=l.payload)==null?void 0:u.response,"logs.detail.copy.responseSuccess")},children:a("common.actions.copy")})]}),e.jsx("pre",{className:"max-h-64 overflow-auto whitespace-pre-wrap rounded-[1rem] border border-border/70 bg-background/70 p-3 text-xs",children:$e((p=l.payload)==null?void 0:p.response,a("logs.detail.payload.emptyResponse"))})]})]}):e.jsx("div",{className:"flex h-full items-center justify-center p-8 text-sm text-muted-foreground",children:a("logs.detail.loadError")})})]})]}),document.body)}function M({label:s,value:i}){return e.jsxs("div",{className:"rounded-xl border border-border/70 bg-background/60 px-3 py-3",children:[e.jsx("p",{className:"text-[11px] font-medium uppercase tracking-[0.16em] text-muted-foreground",children:s}),e.jsx("p",{className:"mt-2 text-sm font-semibold",children:i})]})}function js({apiKeys:s,selected:i,onChange:c,disabled:v,className:g}){const{t:a}=ae(),[d,j]=o.useState(!1),x=o.useRef(null);o.useEffect(()=>{if(!d)return;const r=m=>{var f;(f=x.current)!=null&&f.contains(m.target)||j(!1)};return window.addEventListener("mousedown",r),()=>window.removeEventListener("mousedown",r)},[d]);const N=o.useMemo(()=>{if(i.length===0)return[];const r=new Map;for(const m of s)r.set(m.id,m);return i.map(m=>{const f=r.get(m);return f?f.isWildcard?a("apiKeys.wildcard"):f.name:null}).filter(m=>!!m)},[s,i,a]),l=i.length===0?a("logs.filters.apiKeyAll"):a("logs.filters.apiKeySelected",{count:i.length}),S=r=>{i.includes(r)?c(i.filter(m=>m!==r)):c([...i,r])};return e.jsxs("div",{className:h("relative space-y-2",g),ref:x,children:[e.jsx(O,{children:a("logs.filters.apiKey")}),e.jsxs("button",{type:"button",onClick:()=>j(r=>!r),disabled:v||s.length===0,title:a("logs.filters.apiKeyHint"),className:h("flex h-11 w-full items-center justify-between rounded-2xl border border-border/80 bg-background/85 px-4 text-sm shadow-[0_1px_2px_rgba(15,23,42,0.03)] ring-offset-background transition-all duration-200 focus:outline-none focus:ring-2 focus:ring-ring/30 focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",i.length>0&&"border-primary",d&&"ring-2 ring-ring ring-offset-2"),children:[e.jsxs("span",{className:"truncate",children:[l,N.length>0&&e.jsx("span",{className:"ml-1 text-xs text-muted-foreground",children:N.join(", ")})]}),e.jsx("svg",{className:h("h-4 w-4 opacity-50 transition-transform",d&&"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"})})]}),d&&e.jsxs("div",{className:"absolute left-0 top-full z-30 mt-2 w-64 rounded-[1.2rem] border border-white/60 bg-popover/95 p-2 shadow-[0_16px_40px_-28px_rgba(15,23,42,0.45)] backdrop-blur",children:[e.jsxs("div",{className:"flex items-center justify-between rounded-xl bg-background/70 px-3 py-2 text-xs",children:[e.jsx("span",{children:l}),e.jsx("button",{type:"button",onClick:()=>c([]),disabled:i.length===0,className:"text-primary hover:underline disabled:opacity-40",children:a("common.actions.reset")})]}),e.jsxs("div",{className:"max-h-56 overflow-y-auto py-2",children:[s.map(r=>{const m=r.isWildcard?a("apiKeys.wildcard"):r.name,f=i.includes(r.id);return e.jsxs("label",{className:h("flex cursor-pointer items-center gap-2 rounded-xl px-3 py-2 text-sm transition hover:bg-primary/5",f&&"bg-primary/10 text-primary"),children:[e.jsx("input",{type:"checkbox",className:"h-4 w-4 rounded border-border",checked:f,onChange:()=>S(r.id)}),e.jsx("span",{className:"truncate",children:m})]},r.id)}),s.length===0&&e.jsx("p",{className:"px-2 py-2 text-xs text-muted-foreground",children:a("logs.filters.apiKeyAll")})]})]})]})}export{Os as default};
|