@chenpu17/cc-gw 0.4.1 → 0.4.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.
Files changed (23) hide show
  1. package/package.json +1 -1
  2. package/src/server/dist/index.js +164 -80
  3. package/src/web/dist/assets/{About-DpeHLv4-.js → About-BWcLLdLY.js} +2 -2
  4. package/src/web/dist/assets/{ApiKeys-CTR9Ynaf.js → ApiKeys-DsYmx21U.js} +1 -1
  5. package/src/web/dist/assets/{Button-CkW8jVT-.js → Button-CZXniSHM.js} +1 -1
  6. package/src/web/dist/assets/Dashboard-H7fcVgwO.js +16 -0
  7. package/src/web/dist/assets/{FormField-CsiVhN9M.js → FormField-SZpxR702.js} +1 -1
  8. package/src/web/dist/assets/{Help-CSSGZPF_.js → Help-CgWIUFIO.js} +1 -1
  9. package/src/web/dist/assets/{Input-jZIOmpmG.js → Input-BdyQWPOU.js} +1 -1
  10. package/src/web/dist/assets/{Login-D577Po2d.js → Login-0_Y4Go8x.js} +1 -1
  11. package/src/web/dist/assets/{Logs-DNLLeIq-.js → Logs-MTopPD6L.js} +1 -1
  12. package/src/web/dist/assets/{ModelManagement-BazsfV0F.js → ModelManagement-DBVBITho.js} +1 -1
  13. package/src/web/dist/assets/{PageSection-BbmHOMiD.js → PageSection-B08EcVAN.js} +1 -1
  14. package/src/web/dist/assets/{Settings-Btmf5gPD.js → Settings-DEloCGp7.js} +1 -1
  15. package/src/web/dist/assets/{StatusBadge-DCmNAKwK.js → StatusBadge-8KAMZvYW.js} +1 -1
  16. package/src/web/dist/assets/{copy-D50F736h.js → copy-BdNskWTP.js} +1 -1
  17. package/src/web/dist/assets/{index-But5PyJC.css → index-BFd07aus.css} +1 -1
  18. package/src/web/dist/assets/{index-B-8NzzZq.js → index-BK1UNVMz.js} +5 -5
  19. package/src/web/dist/assets/{index-BuSvAxno.js → index-CyrAg0Ev.js} +1 -1
  20. package/src/web/dist/assets/{info-B7P9oOld.js → info-BTcWJb9B.js} +1 -1
  21. package/src/web/dist/assets/{useApiQuery-DZHaAgf7.js → useApiQuery-BNTE55UK.js} +1 -1
  22. package/src/web/dist/index.html +2 -2
  23. package/src/web/dist/assets/Dashboard-D1jcy7qj.js +0 -16
@@ -1 +1 @@
1
- import{j as s,d as c,J as i,E as p,k as b}from"./index-B-8NzzZq.js";function h({variant:n="subtle",size:o="md",children:a,loading:t,icon:e,className:l,disabled:r,...u}){const m={subtle:b,primary:p,danger:i}[n],x={sm:"h-8 px-3 text-xs",md:"h-10 px-4 text-sm",lg:"h-12 px-6 text-base"}[o];return s.jsx("button",{className:c(m,x,t&&"cursor-wait opacity-70",r&&"cursor-not-allowed opacity-50",l),disabled:r||t,...u,children:t?s.jsx("div",{className:"inline-block animate-spin rounded-full h-4 w-4 border-b-2 border-current"}):e?s.jsxs(s.Fragment,{children:[e,a]}):a})}export{h as B};
1
+ import{j as s,d as c,J as i,E as p,k as b}from"./index-BK1UNVMz.js";function h({variant:n="subtle",size:o="md",children:a,loading:t,icon:e,className:l,disabled:r,...u}){const m={subtle:b,primary:p,danger:i}[n],x={sm:"h-8 px-3 text-xs",md:"h-10 px-4 text-sm",lg:"h-12 px-6 text-base"}[o];return s.jsx("button",{className:c(m,x,t&&"cursor-wait opacity-70",r&&"cursor-not-allowed opacity-50",l),disabled:r||t,...u,children:t?s.jsx("div",{className:"inline-block animate-spin rounded-full h-4 w-4 border-b-2 border-current"}):e?s.jsxs(s.Fragment,{children:[e,a]}):a})}export{h as B};
@@ -0,0 +1,16 @@
1
+ import{c as O,u as q,a as te,r as h,b as se,t as ae,j as e,L as re,B,d as o,m as g,g as z,e as $,f as G,h as oe,l as _,s as le,i as M,k as ie,n as P}from"./index-BK1UNVMz.js";import{E as ne}from"./index-CyrAg0Ev.js";import{P as de,a as H}from"./PageSection-B08EcVAN.js";import{S as ce}from"./Input-BdyQWPOU.js";import{S as me}from"./StatusBadge-8KAMZvYW.js";import{u as C}from"./useApiQuery-BNTE55UK.js";/**
2
+ * @license lucide-react v0.344.0 - ISC
3
+ *
4
+ * This source code is licensed under the ISC license.
5
+ * See the LICENSE file in the root directory of this source tree.
6
+ */const D=O("Activity",[["path",{d:"M22 12h-4l-3 9L9 3l-3 9H2",key:"d5dnw9"}]]);/**
7
+ * @license lucide-react v0.344.0 - ISC
8
+ *
9
+ * This source code is licensed under the ISC license.
10
+ * See the LICENSE file in the root directory of this source tree.
11
+ */const xe=O("Timer",[["line",{x1:"10",x2:"14",y1:"2",y2:"2",key:"14vaq8"}],["line",{x1:"12",x2:"15",y1:"14",y2:"11",key:"17fdiu"}],["circle",{cx:"12",cy:"14",r:"8",key:"1e1u0o"}]]);/**
12
+ * @license lucide-react v0.344.0 - ISC
13
+ *
14
+ * This source code is licensed under the ISC license.
15
+ * See the LICENSE file in the root directory of this source tree.
16
+ */const he=O("TrendingUp",[["polyline",{points:"22 7 13.5 15.5 8.5 10.5 2 17",key:"126l90"}],["polyline",{points:"16 7 22 7 22 13",key:"kwv8wd"}]]);function w(t,a,s){return t==null?"-":`${t.toLocaleString(void 0,s)} ${a}`}function U(t){if(t==null)return"-";if(t<1024)return`${t} B`;const a=["KB","MB","GB","TB"];let s=t/1024,r=0;for(;s>=1024&&r<a.length-1;)s/=1024,r+=1;return`${s.toFixed(s>=100?0:s>=10?1:2)} ${a[r]}`}function ve(){var F;const{t}=q(),{pushToast:a}=te(),[s,r]=h.useState("all"),[n,L]=h.useState(!1),p=s==="all"?void 0:s,v=C(["stats","overview",s],{url:"/api/stats/overview",method:"GET",params:p?{endpoint:p}:void 0}),k=C(["stats","daily",14,s],{url:"/api/stats/daily",method:"GET",params:{days:14,...p?{endpoint:p}:{}}}),y=C(["stats","model",7,6,s],{url:"/api/stats/model",method:"GET",params:{days:7,limit:6,...p?{endpoint:p}:{}}}),S=C(["status"],{url:"/api/status",method:"GET"}),f=C(["db","info"],{url:"/api/db/info",method:"GET"}),Q=f.refetch??(async()=>{}),T=C(["logs","recent",s],{url:"/api/logs",method:"GET",params:{limit:5,...p?{endpoint:p}:{}}},{refetchInterval:3e4});h.useEffect(()=>{v.isError&&v.error&&a({title:t("dashboard.toast.overviewError"),description:v.error.message,variant:"error"})},[v.isError,v.error,a,t]),h.useEffect(()=>{k.isError&&k.error&&a({title:t("dashboard.toast.dailyError"),description:k.error.message,variant:"error"})},[k.isError,k.error,a,t]),h.useEffect(()=>{y.isError&&y.error&&a({title:t("dashboard.toast.modelError"),description:y.error.message,variant:"error"})},[y.isError,y.error,a,t]),h.useEffect(()=>{S.isError&&S.error&&a({title:t("dashboard.toast.statusError"),description:S.error.message,variant:"error"})},[S.isError,S.error,a,t]),h.useEffect(()=>{f.isError&&f.error&&a({title:t("dashboard.toast.dbError"),description:f.error.message,variant:"error"})},[f.isError,f.error,a,t]);const K=h.useCallback(async()=>{if(!n){L(!0);try{await se.post("/api/db/compact"),await Q(),a({title:t("dashboard.toast.compactSuccess.title"),description:t("dashboard.toast.compactSuccess.desc"),variant:"success"})}catch(d){const x=ae(d);a({title:t("dashboard.toast.compactError.title"),description:x.message,variant:"error"})}finally{L(!1)}}},[n,a,Q,t]);h.useEffect(()=>{T.isError&&T.error&&a({title:t("dashboard.toast.recentError"),description:T.error.message,variant:"error"})},[T.isError,T.error,a,t]);const i=v.data,j=k.data??[],c=y.data??[],A=S.data,I=f.data,V=((F=T.data)==null?void 0:F.items)??[],J=I?U(I.totalBytes??I.sizeBytes):"-",W=I?U(I.memoryRssBytes??0):"-",X=h.useMemo(()=>{const d=j.map(b=>b.date),x=t("dashboard.charts.barRequests"),l=t("dashboard.charts.lineInput"),u=t("dashboard.charts.lineOutput"),m=t("dashboard.charts.lineCacheRead"),N=t("dashboard.charts.lineCacheCreation");return{tooltip:{trigger:"axis",backgroundColor:"rgba(15, 23, 42, 0.9)",borderColor:"rgba(59, 130, 246, 0.3)",textStyle:{color:"#e2e8f0"}},legend:{data:[x,l,u,m,N],textStyle:{color:"#64748b"}},grid:{left:60,right:40,top:60,bottom:60},xAxis:{type:"category",data:d,axisLabel:{color:"#64748b"},axisLine:{lineStyle:{color:"#334155"}}},yAxis:{type:"value",axisLabel:{color:"#64748b"},axisLine:{lineStyle:{color:"#334155"}},splitLine:{lineStyle:{color:"#1e293b"}}},series:[{name:x,type:"bar",data:j.map(b=>b.requestCount),itemStyle:{color:"#3b82f6",borderRadius:[4,4,0,0]},emphasis:{itemStyle:{color:"#2563eb"}}},{name:l,type:"line",yAxisIndex:0,data:j.map(b=>b.inputTokens),smooth:!0,itemStyle:{color:"#10b981"},lineStyle:{width:3},symbol:"circle",symbolSize:6},{name:u,type:"line",yAxisIndex:0,data:j.map(b=>b.outputTokens),smooth:!0,itemStyle:{color:"#f59e0b"},lineStyle:{width:3},symbol:"circle",symbolSize:6},{name:m,type:"line",yAxisIndex:0,data:j.map(b=>b.cacheReadTokens),smooth:!0,itemStyle:{color:"#8b5cf6"},lineStyle:{width:3},symbol:"circle",symbolSize:6},{name:N,type:"line",yAxisIndex:0,data:j.map(b=>b.cacheCreationTokens),smooth:!0,itemStyle:{color:"#ec4899"},lineStyle:{width:3},symbol:"circle",symbolSize:6}]}},[j,t]),Y=h.useMemo(()=>{const d=c.map(m=>`${m.provider}/${m.model}`),x=t("dashboard.charts.barRequests"),l=t("dashboard.charts.lineInput"),u=t("dashboard.charts.lineOutput");return{tooltip:{trigger:"axis",backgroundColor:"rgba(15, 23, 42, 0.9)",borderColor:"rgba(59, 130, 246, 0.3)",textStyle:{color:"#e2e8f0"}},legend:{data:[x,l,u],textStyle:{color:"#64748b"}},grid:{left:80,right:60,top:60,bottom:100},xAxis:{type:"category",data:d,axisLabel:{rotate:30,color:"#64748b"},axisLine:{lineStyle:{color:"#334155"}}},yAxis:[{type:"value",name:x,axisLabel:{color:"#64748b"},axisLine:{lineStyle:{color:"#334155"}},splitLine:{lineStyle:{color:"#1e293b"}}},{type:"value",name:t("dashboard.charts.axisTokens"),position:"right",axisLabel:{color:"#64748b"},axisLine:{lineStyle:{color:"#334155"}}}],series:[{name:x,type:"bar",data:c.map(m=>m.requests),itemStyle:{color:"#6366f1",borderRadius:[4,4,0,0]},yAxisIndex:0},{name:l,type:"line",yAxisIndex:1,smooth:!0,data:c.map(m=>m.inputTokens??0),itemStyle:{color:"#10b981"},lineStyle:{width:3}},{name:u,type:"line",yAxisIndex:1,smooth:!0,data:c.map(m=>m.outputTokens??0),itemStyle:{color:"#f59e0b"},lineStyle:{width:3}}]}},[c,t]),Z=h.useMemo(()=>{const d=c.map(l=>`${l.provider}/${l.model}`),x=t("dashboard.charts.ttftLabel");return{tooltip:{trigger:"axis",backgroundColor:"rgba(15, 23, 42, 0.9)",borderColor:"rgba(59, 130, 246, 0.3)",textStyle:{color:"#e2e8f0"},formatter(l){var N;if(!Array.isArray(l)||l.length===0)return"";const u=((N=l[0])==null?void 0:N.dataIndex)??0,m=c[u];return m?`<strong>${d[u]}</strong><br/>${x}: ${w(m.avgTtftMs,t("common.units.ms"))}`:""}},grid:{left:80,right:50,top:60,bottom:100},xAxis:{type:"category",data:d,axisLabel:{rotate:30,color:"#64748b"},axisLine:{lineStyle:{color:"#334155"}}},yAxis:{type:"value",name:t("dashboard.charts.ttftAxis"),axisLabel:{color:"#64748b"},axisLine:{lineStyle:{color:"#334155"}},splitLine:{lineStyle:{color:"#1e293b"}}},series:[{name:x,type:"bar",data:c.map(l=>l.avgTtftMs??0),itemStyle:{color:"#3b82f6",borderRadius:[4,4,0,0]}}]}},[c,t]),ee=h.useMemo(()=>{const d=c.map(l=>`${l.provider}/${l.model}`),x=t("dashboard.charts.tpotLabel");return{tooltip:{trigger:"axis",backgroundColor:"rgba(15, 23, 42, 0.9)",borderColor:"rgba(59, 130, 246, 0.3)",textStyle:{color:"#e2e8f0"},formatter(l){var N;if(!Array.isArray(l)||l.length===0)return"";const u=((N=l[0])==null?void 0:N.dataIndex)??0,m=c[u];return m?`<strong>${d[u]}</strong><br/>${x}: ${w(m.avgTpotMs,t("common.units.msPerToken"),{maximumFractionDigits:2})}`:""}},grid:{left:80,right:50,top:60,bottom:100},xAxis:{type:"category",data:d,axisLabel:{rotate:30,color:"#64748b"},axisLine:{lineStyle:{color:"#334155"}}},yAxis:{type:"value",name:t("dashboard.charts.tpotAxis"),axisLabel:{color:"#64748b"},axisLine:{lineStyle:{color:"#334155"}},splitLine:{lineStyle:{color:"#1e293b"}}},series:[{name:x,type:"bar",data:c.map(l=>l.avgTpotMs??0),itemStyle:{color:"#f59e0b",borderRadius:[4,4,0,0]}}]}},[c,t]);return v.isPending||S.isPending||f.isPending?e.jsx(re,{}):e.jsxs("div",{className:"flex flex-col gap-8",children:[e.jsx(de,{icon:e.jsx(B,{className:"h-7 w-7","aria-hidden":"true"}),title:t("nav.dashboard"),description:t("dashboard.description"),actions:e.jsxs("div",{className:"flex items-center gap-4 rounded-2xl bg-white/90 px-4 py-3 shadow-lg shadow-slate-200/30 ring-1 ring-slate-200/40 backdrop-blur-lg dark:bg-slate-900/90 dark:shadow-xl dark:shadow-slate-900/30 dark:ring-slate-700/40",children:[e.jsx("label",{htmlFor:"dashboard-endpoint-filter",className:"text-xs font-bold uppercase tracking-[0.15em] text-slate-600 dark:text-slate-300",children:t("dashboard.filters.endpoint")}),e.jsx("div",{className:"relative",children:e.jsx(ce,{id:"dashboard-endpoint-filter",value:s,onChange:d=>r(d.target.value),options:[{value:"all",label:t("dashboard.filters.endpointAll")},{value:"anthropic",label:t("dashboard.filters.endpointAnthropic")},{value:"openai",label:t("dashboard.filters.endpointOpenAI")}]})})]})}),A?e.jsxs("section",{className:o(z,"flex flex-wrap items-center gap-4 text-sm leading-relaxed animate-slide-up"),"aria-live":"polite",children:[e.jsxs("span",{className:o(le.success,"inline-flex items-center gap-2 rounded-full px-4 py-2 font-semibold"),children:[e.jsx("span",{className:"h-2 w-2 rounded-full bg-current shadow-lg","aria-hidden":"true"}),t("dashboard.status.listening",{host:A.host??"0.0.0.0",port:A.port})]}),e.jsx("span",{className:o(M.default,"font-semibold"),children:t("dashboard.status.providers",{value:A.providers.toLocaleString()})}),e.jsx("span",{className:o(M.primary,"font-semibold"),children:t("dashboard.status.todayRequests",{value:((i==null?void 0:i.today.requests)??0).toLocaleString()})}),e.jsx("span",{className:o(M.default,"font-semibold"),children:t("dashboard.status.active",{value:(A.activeRequests??0).toLocaleString()})}),e.jsx("span",{className:o(M.default,"font-semibold"),children:t("dashboard.status.dbSize",{value:J})}),e.jsx("span",{className:o(M.default,"font-semibold"),children:t("dashboard.status.memory",{value:W})}),e.jsx("button",{type:"button",onClick:K,disabled:n,className:o(ie,"h-9 rounded-full px-4 text-xs font-semibold",n?"cursor-wait opacity-70":""),children:t(n?"dashboard.actions.compacting":"dashboard.actions.compact")})]}):null,e.jsxs("section",{className:o(P.auto,"gap-4 sm:gap-6"),children:[e.jsx(E,{icon:e.jsx(D,{className:"h-5 w-5"}),title:t("dashboard.cards.todayRequests"),value:(i==null?void 0:i.today.requests)??0,suffix:t("common.units.request"),trend:"+12%",trendDirection:"up"}),e.jsx(E,{icon:e.jsx(he,{className:"h-5 w-5"}),title:t("dashboard.cards.todayInput"),value:(i==null?void 0:i.today.inputTokens)??0,suffix:t("common.units.token"),trend:"+8%",trendDirection:"up"}),e.jsx(E,{icon:e.jsx(D,{className:"h-5 w-5"}),title:t("dashboard.cards.todayCacheRead"),value:(i==null?void 0:i.today.cacheReadTokens)??0,suffix:t("common.units.token")}),e.jsx(E,{icon:e.jsx(D,{className:"h-5 w-5"}),title:t("dashboard.cards.todayCacheCreation"),value:(i==null?void 0:i.today.cacheCreationTokens)??0,suffix:t("common.units.token")}),e.jsx(E,{icon:e.jsx(B,{className:"h-5 w-5"}),title:t("dashboard.cards.todayOutput"),value:(i==null?void 0:i.today.outputTokens)??0,suffix:t("common.units.token"),trend:"+15%",trendDirection:"up"}),e.jsx(E,{icon:e.jsx(xe,{className:"h-5 w-5"}),title:t("dashboard.cards.avgLatency"),value:(i==null?void 0:i.today.avgLatencyMs)??0,suffix:t("common.units.token"),trend:"-5%",trendDirection:"down"})]}),e.jsxs("div",{className:o(P.fixed[2],"gap-6 sm:gap-8"),children:[e.jsx(R,{title:t("dashboard.charts.requestsTitle"),description:t("dashboard.charts.requestsDesc"),loading:k.isPending,option:X,empty:!j.length,emptyText:t("dashboard.charts.empty")}),e.jsx(R,{title:t("dashboard.charts.modelTitle"),description:t("dashboard.charts.modelDesc"),loading:y.isPending,option:Y,empty:!c.length,emptyText:t("dashboard.charts.empty")})]}),e.jsxs("div",{className:o(P.fixed[2],"gap-6 sm:gap-8"),children:[e.jsx(R,{title:t("dashboard.charts.ttftTitle"),description:t("dashboard.charts.ttftDesc"),loading:y.isPending,option:Z,empty:!c.some(d=>d.avgTtftMs!=null&&d.avgTtftMs>0),emptyText:t("dashboard.charts.ttftEmpty")}),e.jsx(R,{title:t("dashboard.charts.tpotTitle"),description:t("dashboard.charts.tpotDesc"),loading:y.isPending,option:ee,empty:!c.some(d=>d.avgTpotMs!=null&&d.avgTpotMs>0),emptyText:t("dashboard.charts.tpotEmpty")})]}),e.jsx(pe,{models:c,loading:y.isPending}),e.jsx(ue,{loading:T.isPending,records:V})]})}function E({icon:t,title:a,value:s,suffix:r,trend:n,trendDirection:L}){return e.jsxs("div",{className:o(z,"group hover-lift animate-slide-up"),children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx("div",{className:o(g,"text-xs font-bold uppercase tracking-[0.15em]"),children:a}),t&&e.jsx("div",{className:"flex h-8 w-8 items-center justify-center rounded-xl bg-gradient-to-br from-blue-600/15 to-indigo-600/10 text-blue-600 ring-1 ring-blue-500/20 dark:from-blue-500/25 dark:to-indigo-500/15 dark:text-blue-200 dark:ring-blue-400/20",children:t})]}),e.jsx("div",{className:"flex items-end justify-between",children:e.jsxs("div",{children:[e.jsxs("p",{className:"text-3xl font-bold text-slate-900 dark:text-slate-50",children:[s.toLocaleString(),r?e.jsx("span",{className:o(g,"ml-2 text-base sm:text-lg font-medium"),children:r}):null]}),n&&e.jsxs("div",{className:o("mt-2 flex items-center gap-1 text-xs font-semibold",L==="up"?"text-emerald-600 dark:text-emerald-400":"text-red-600 dark:text-red-400"),children:[e.jsx("span",{children:n}),e.jsx("span",{className:"text-slate-500",children:"vs last period"})]})]})})]})}function R({title:t,description:a,option:s,loading:r,empty:n,emptyText:L}){const{t:p}=q();return e.jsxs("div",{className:o(z,"space-y-4 sm:space-y-6 hover-lift animate-slide-up"),children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xl font-bold text-slate-900 dark:text-slate-50",children:t}),e.jsx("p",{className:o(g,"mt-2 text-xs sm:text-sm leading-relaxed"),children:a})]}),r?e.jsx("div",{className:$.container,children:e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:$.spinner}),e.jsx("span",{className:o($.text),children:p("common.loadingShort")})]})}):n?e.jsx("div",{className:G,children:e.jsxs("div",{className:"text-center",children:[e.jsx(B,{className:"mx-auto h-12 w-12 text-slate-300 dark:text-slate-600 mb-4"}),e.jsx("span",{className:o(g,"text-sm"),children:L??p("dashboard.charts.empty")})]})}):e.jsx(ne,{option:s,style:{height:320},notMerge:!0,lazyUpdate:!0,theme:void 0,className:oe})]})}function pe({models:t,loading:a}){const{t:s}=q(),r=t.length>0;return e.jsx(H,{title:e.jsx("span",{className:"text-sm font-semibold text-slate-900 dark:text-slate-50",children:s("dashboard.modelTable.title")}),description:s("dashboard.modelTable.description"),contentClassName:"gap-0 overflow-hidden p-0",children:a?e.jsx("div",{className:_,children:e.jsx("span",{className:o(g,"text-sm"),children:s("common.loadingShort")})}):r?e.jsx("div",{className:"max-h-80 overflow-auto",children:e.jsxs("table",{className:"min-w-full divide-y divide-slate-200/70 text-sm dark:divide-slate-700/60",children:[e.jsx("caption",{className:"sr-only",children:s("dashboard.modelTable.title")}),e.jsx("thead",{className:"bg-slate-100/70 text-left text-xs font-semibold uppercase tracking-wide text-slate-500 dark:bg-slate-800/60 dark:text-slate-400",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-5 py-3 font-semibold",children:s("dashboard.modelTable.columns.model")}),e.jsx("th",{className:"px-5 py-3 text-right font-semibold",children:s("dashboard.modelTable.columns.requests")}),e.jsx("th",{className:"px-5 py-3 text-right font-semibold",children:s("dashboard.modelTable.columns.latency")}),e.jsx("th",{className:"px-5 py-3 text-right font-semibold",children:s("dashboard.modelTable.columns.ttft")}),e.jsx("th",{className:"px-5 py-3 text-right font-semibold",children:s("dashboard.modelTable.columns.tpot")})]})}),e.jsx("tbody",{className:"divide-y divide-slate-200/60 dark:divide-slate-800/60",children:t.map(n=>e.jsxs("tr",{className:"transition hover:bg-slate-50/70 dark:hover:bg-slate-800/40",children:[e.jsx("td",{className:"px-5 py-3",children:e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"font-semibold text-slate-800 dark:text-slate-50",children:n.provider}),e.jsx("span",{className:o(g,"text-xs"),children:n.model})]})}),e.jsx("td",{className:"px-5 py-3 text-right font-medium text-slate-800 dark:text-slate-50",children:n.requests.toLocaleString()}),e.jsx("td",{className:"px-5 py-3 text-right",children:w(n.avgLatencyMs,s("common.units.ms"))}),e.jsx("td",{className:"px-5 py-3 text-right",children:w(n.avgTtftMs,s("common.units.ms"))}),e.jsx("td",{className:"px-5 py-3 text-right",children:w(n.avgTpotMs,s("common.units.msPerToken"),{maximumFractionDigits:2})})]},`${n.provider}/${n.model}`))})]})}):e.jsx("div",{className:G,children:e.jsx("span",{className:o(g,"text-sm"),children:s("dashboard.modelTable.empty")})})})}function ue({records:t,loading:a}){const{t:s}=q();return e.jsx(H,{title:e.jsx("span",{className:"text-sm font-semibold text-slate-900 dark:text-slate-50",children:s("dashboard.recent.title")}),description:s("dashboard.recent.subtitle",{count:5}),contentClassName:"gap-0 overflow-hidden p-0",children:a?e.jsx("div",{className:_,children:e.jsx("span",{className:o(g,"text-sm"),children:s("dashboard.recent.loading")})}):t.length===0?e.jsx("div",{className:G,children:e.jsx("span",{className:o(g,"text-sm"),children:s("dashboard.recent.empty")})}):e.jsx("div",{className:"max-h-80 overflow-auto",children:e.jsxs("table",{className:"min-w-full divide-y divide-slate-200/70 text-sm dark:divide-slate-700/60",children:[e.jsx("caption",{className:"sr-only",children:s("dashboard.recent.title")}),e.jsx("thead",{className:"bg-slate-100/70 text-left text-xs font-semibold uppercase tracking-wide text-slate-500 dark:bg-slate-800/60 dark:text-slate-400",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-5 py-3 font-semibold",children:s("dashboard.recent.columns.time")}),e.jsx("th",{className:"px-5 py-3 font-semibold",children:s("dashboard.recent.columns.endpoint")}),e.jsx("th",{className:"px-5 py-3 font-semibold",children:s("dashboard.recent.columns.provider")}),e.jsx("th",{className:"px-5 py-3 font-semibold",children:s("dashboard.recent.columns.route")}),e.jsx("th",{className:"px-5 py-3 text-right font-semibold",children:s("dashboard.recent.columns.latency")}),e.jsx("th",{className:"px-5 py-3 text-left font-semibold",children:s("dashboard.recent.columns.status")})]})}),e.jsx("tbody",{className:"divide-y divide-slate-200/60 dark:divide-slate-800/60",children:t.map(r=>e.jsxs("tr",{className:"transition hover:bg-slate-50/70 dark:hover:bg-slate-800/40",children:[e.jsx("td",{className:"px-5 py-3 text-xs font-medium text-slate-600 dark:text-slate-300",children:new Date(r.timestamp).toLocaleString()}),e.jsx("td",{className:"px-5 py-3 text-xs text-slate-500 dark:text-slate-400",children:r.endpoint==="anthropic"?s("logs.table.endpointAnthropic"):r.endpoint==="openai"?s("logs.table.endpointOpenAI"):r.endpoint}),e.jsx("td",{className:"px-5 py-3 text-sm font-medium text-slate-800 dark:text-slate-50",children:r.provider}),e.jsx("td",{className:"px-5 py-3",children:e.jsxs("div",{className:"flex items-center gap-2 text-xs text-slate-500 dark:text-slate-400",children:[e.jsx("span",{children:r.client_model??s("dashboard.recent.routePlaceholder")}),e.jsx("span",{"aria-hidden":"true",className:"text-slate-400",children:"→"}),e.jsx("span",{className:"font-semibold text-slate-700 dark:text-slate-100",children:r.model})]})}),e.jsx("td",{className:"px-5 py-3 text-right text-sm font-medium text-slate-800 dark:text-slate-100",children:w(r.latency_ms,s("common.units.ms"))}),e.jsx("td",{className:"px-5 py-3",children:e.jsxs(me,{variant:r.error?"error":"success",children:[e.jsx("span",{className:"h-2 w-2 rounded-full bg-current","aria-hidden":"true"}),(r.status_code??(r.error?500:200)).toString(),e.jsx("span",{children:r.error?s("common.status.error"):s("common.status.success")})]})})]},r.id))})]})})})}export{ve as default};
@@ -1 +1 @@
1
- import{j as s,d,P as m,Q as x}from"./index-B-8NzzZq.js";function i({label:a,children:l,className:t,required:r,error:e}){return s.jsxs("div",{className:d(x,t),children:[s.jsxs("label",{className:m,children:[a,r&&s.jsx("span",{className:"text-red-500 ml-1",children:"*"})]}),l,e&&s.jsx("p",{className:"text-xs text-red-600 dark:text-red-400 mt-1",children:e})]})}export{i as F};
1
+ import{j as s,d,P as m,Q as x}from"./index-BK1UNVMz.js";function i({label:a,children:l,className:t,required:r,error:e}){return s.jsxs("div",{className:d(x,t),children:[s.jsxs("label",{className:m,children:[a,r&&s.jsx("span",{className:"text-red-500 ml-1",children:"*"})]}),l,e&&s.jsx("p",{className:"text-xs text-red-600 dark:text-red-400 mt-1",children:e})]})}export{i as F};
@@ -1,4 +1,4 @@
1
- import{c as u,u as p,r as b,j as e,d as x,m}from"./index-B-8NzzZq.js";import{P as g,a as o}from"./PageSection-BbmHOMiD.js";import{I as j}from"./info-B7P9oOld.js";/**
1
+ import{c as u,u as p,r as b,j as e,d as x,m}from"./index-BK1UNVMz.js";import{P as g,a as o}from"./PageSection-B08EcVAN.js";import{I as j}from"./info-BTcWJb9B.js";/**
2
2
  * @license lucide-react v0.344.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
@@ -1 +1 @@
1
- import{r as d,j as e,d as n,M as c,K as i}from"./index-B-8NzzZq.js";const f=d.forwardRef(({options:t,placeholder:s,className:r,...l},u)=>e.jsxs("select",{ref:u,className:n(c,r),...l,children:[s&&e.jsx("option",{value:"",disabled:!0,children:s}),t.map(a=>e.jsx("option",{value:a.value,disabled:a.disabled,children:a.label},a.value))]})),j=d.forwardRef(({variant:t="default",className:s,...r},l)=>e.jsx("input",{ref:l,className:n(i,s),...r}));export{j as I,f as S};
1
+ import{r as d,j as e,d as n,M as c,K as i}from"./index-BK1UNVMz.js";const f=d.forwardRef(({options:t,placeholder:s,className:r,...l},u)=>e.jsxs("select",{ref:u,className:n(c,r),...l,children:[s&&e.jsx("option",{value:"",disabled:!0,children:s}),t.map(a=>e.jsx("option",{value:a.value,disabled:a.disabled,children:a.label},a.value))]})),j=d.forwardRef(({variant:t="default",className:s,...r},l)=>e.jsx("input",{ref:l,className:n(i,s),...r}));export{j as I,f as S};
@@ -1 +1 @@
1
- import{u as y,a8 as E,a9 as C,aa as S,r as l,j as e,d,L as _,m as j,K as v,E as L}from"./index-B-8NzzZq.js";function P(){const{t:a}=y(),o=E(),m=C(),{authEnabled:n,isAuthenticated:x,loading:i,login:k,error:b}=S(),[r,h]=l.useState({username:"",password:""}),[f,u]=l.useState(null),[p,g]=l.useState(!1),c=l.useMemo(()=>{var t;const s=m.state;return((t=s==null?void 0:s.from)==null?void 0:t.pathname)??"/"},[m.state]);l.useEffect(()=>{if(!n&&!i){o(c,{replace:!0});return}n&&x&&!i&&o(c,{replace:!0})},[n,x,i,o,c]);const N=async s=>{if(s.preventDefault(),u(null),!r.username.trim()||!r.password){u(a("login.validation.required"));return}g(!0);try{await k(r.username.trim(),r.password),o(c,{replace:!0})}catch(t){u(t instanceof Error?t.message:a("login.validation.failed"))}finally{g(!1)}},w=s=>e.jsxs("div",{className:"relative flex min-h-screen items-center justify-center overflow-hidden bg-gradient-to-br from-slate-100 via-white to-slate-200 px-4 dark:from-slate-950/95 dark:via-slate-950 dark:to-slate-900",children:[e.jsxs("div",{className:"pointer-events-none absolute inset-0",children:[e.jsx("div",{className:"absolute left-10 top-20 h-48 w-48 rounded-full bg-slate-200/40 blur-3xl dark:bg-slate-700/30"}),e.jsx("div",{className:"absolute right-16 bottom-32 h-56 w-56 rounded-full bg-slate-300/35 blur-3xl dark:bg-slate-800/30"}),e.jsx("div",{className:"absolute inset-0 bg-[radial-gradient(circle_at_top,_rgba(15,23,42,0.08),_transparent_55%)]"})]}),e.jsx("div",{className:"relative z-10 w-full max-w-lg",children:s})]});return i?w(e.jsx("div",{className:"flex min-h-[320px] items-center justify-center rounded-3xl border border-blue-200/60 bg-white/90 shadow-2xl shadow-blue-200/50 backdrop-blur-xl dark:border-slate-800/50 dark:bg-slate-900/80 dark:shadow-slate-900/60",children:e.jsx(_,{})})):n?w(e.jsxs("main",{className:"rounded-3xl border border-slate-200/70 bg-white/95 px-8 pb-10 pt-9 shadow-2xl shadow-slate-200/40 backdrop-blur-xl dark:border-slate-800/60 dark:bg-slate-900/85 dark:shadow-slate-900/60",children:[e.jsxs("header",{className:"mb-8 flex flex-col items-center gap-3 text-center",children:[e.jsx("div",{className:"flex h-16 w-16 items-center justify-center rounded-2xl bg-gradient-to-br from-slate-900 via-slate-800 to-slate-700 text-xl font-bold text-white shadow-lg shadow-slate-400/30 dark:from-blue-500 dark:via-blue-600 dark:to-indigo-600 dark:shadow-blue-900/40",children:"GW"}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("h1",{className:"text-2xl font-semibold text-slate-900 dark:text-slate-50",children:a("login.title")}),e.jsx("p",{className:d(j,"text-sm leading-relaxed max-w-[360px]"),children:a("login.description")})]})]}),e.jsxs("form",{className:"space-y-5",onSubmit:N,children:[e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide text-slate-500 dark:text-slate-400",children:a("login.fields.username")}),e.jsx("input",{value:r.username,autoComplete:"username",autoFocus:!0,onChange:s=>h(t=>({...t,username:s.target.value})),placeholder:a("login.fields.usernamePlaceholder"),className:d(v,"h-11 font-medium")})]}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide text-slate-500 dark:text-slate-400",children:a("login.fields.password")}),e.jsx("input",{type:"password",value:r.password,autoComplete:"current-password",onChange:s=>h(t=>({...t,password:s.target.value})),placeholder:a("login.fields.passwordPlaceholder"),className:d(v,"h-11")})]}),f||b?e.jsx("div",{className:"rounded-2xl border border-red-200/70 bg-red-50/80 px-4 py-3 text-sm font-medium text-red-600 shadow-sm shadow-red-200/40 dark:border-red-500/40 dark:bg-red-500/15 dark:text-red-100",children:f||b}):null,e.jsx("button",{type:"submit",className:d(L,"w-full justify-center rounded-full py-3 text-sm font-semibold"),disabled:p,children:a(p?"common.actions.loading":"login.actions.submit")})]}),e.jsx("footer",{className:"mt-7 text-center text-xs",children:e.jsx("p",{className:d(j,"leading-relaxed"),children:a("login.hint")})})]})):null}export{P as default};
1
+ import{u as y,a8 as E,a9 as C,aa as S,r as l,j as e,d,L as _,m as j,K as v,E as L}from"./index-BK1UNVMz.js";function P(){const{t:a}=y(),o=E(),m=C(),{authEnabled:n,isAuthenticated:x,loading:i,login:k,error:b}=S(),[r,h]=l.useState({username:"",password:""}),[f,u]=l.useState(null),[p,g]=l.useState(!1),c=l.useMemo(()=>{var t;const s=m.state;return((t=s==null?void 0:s.from)==null?void 0:t.pathname)??"/"},[m.state]);l.useEffect(()=>{if(!n&&!i){o(c,{replace:!0});return}n&&x&&!i&&o(c,{replace:!0})},[n,x,i,o,c]);const N=async s=>{if(s.preventDefault(),u(null),!r.username.trim()||!r.password){u(a("login.validation.required"));return}g(!0);try{await k(r.username.trim(),r.password),o(c,{replace:!0})}catch(t){u(t instanceof Error?t.message:a("login.validation.failed"))}finally{g(!1)}},w=s=>e.jsxs("div",{className:"relative flex min-h-screen items-center justify-center overflow-hidden bg-gradient-to-br from-slate-100 via-white to-slate-200 px-4 dark:from-slate-950/95 dark:via-slate-950 dark:to-slate-900",children:[e.jsxs("div",{className:"pointer-events-none absolute inset-0",children:[e.jsx("div",{className:"absolute left-10 top-20 h-48 w-48 rounded-full bg-slate-200/40 blur-3xl dark:bg-slate-700/30"}),e.jsx("div",{className:"absolute right-16 bottom-32 h-56 w-56 rounded-full bg-slate-300/35 blur-3xl dark:bg-slate-800/30"}),e.jsx("div",{className:"absolute inset-0 bg-[radial-gradient(circle_at_top,_rgba(15,23,42,0.08),_transparent_55%)]"})]}),e.jsx("div",{className:"relative z-10 w-full max-w-lg",children:s})]});return i?w(e.jsx("div",{className:"flex min-h-[320px] items-center justify-center rounded-3xl border border-blue-200/60 bg-white/90 shadow-2xl shadow-blue-200/50 backdrop-blur-xl dark:border-slate-800/50 dark:bg-slate-900/80 dark:shadow-slate-900/60",children:e.jsx(_,{})})):n?w(e.jsxs("main",{className:"rounded-3xl border border-slate-200/70 bg-white/95 px-8 pb-10 pt-9 shadow-2xl shadow-slate-200/40 backdrop-blur-xl dark:border-slate-800/60 dark:bg-slate-900/85 dark:shadow-slate-900/60",children:[e.jsxs("header",{className:"mb-8 flex flex-col items-center gap-3 text-center",children:[e.jsx("div",{className:"flex h-16 w-16 items-center justify-center rounded-2xl bg-gradient-to-br from-slate-900 via-slate-800 to-slate-700 text-xl font-bold text-white shadow-lg shadow-slate-400/30 dark:from-blue-500 dark:via-blue-600 dark:to-indigo-600 dark:shadow-blue-900/40",children:"GW"}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("h1",{className:"text-2xl font-semibold text-slate-900 dark:text-slate-50",children:a("login.title")}),e.jsx("p",{className:d(j,"text-sm leading-relaxed max-w-[360px]"),children:a("login.description")})]})]}),e.jsxs("form",{className:"space-y-5",onSubmit:N,children:[e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide text-slate-500 dark:text-slate-400",children:a("login.fields.username")}),e.jsx("input",{value:r.username,autoComplete:"username",autoFocus:!0,onChange:s=>h(t=>({...t,username:s.target.value})),placeholder:a("login.fields.usernamePlaceholder"),className:d(v,"h-11 font-medium")})]}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide text-slate-500 dark:text-slate-400",children:a("login.fields.password")}),e.jsx("input",{type:"password",value:r.password,autoComplete:"current-password",onChange:s=>h(t=>({...t,password:s.target.value})),placeholder:a("login.fields.passwordPlaceholder"),className:d(v,"h-11")})]}),f||b?e.jsx("div",{className:"rounded-2xl border border-red-200/70 bg-red-50/80 px-4 py-3 text-sm font-medium text-red-600 shadow-sm shadow-red-200/40 dark:border-red-500/40 dark:bg-red-500/15 dark:text-red-100",children:f||b}):null,e.jsx("button",{type:"submit",className:d(L,"w-full justify-center rounded-full py-3 text-sm font-semibold"),disabled:p,children:a(p?"common.actions.loading":"login.actions.submit")})]}),e.jsx("footer",{className:"mt-7 text-center text-xs",children:e.jsx("p",{className:d(j,"leading-relaxed"),children:a("login.hint")})})]})):null}export{P as default};
@@ -1 +1 @@
1
- import{u as M,a as oe,r as i,b as be,t as je,j as e,d as y,k as te,F as ye,p as ke,o as Ne,m as A,q as ve,L as we}from"./index-B-8NzzZq.js";import{u as K}from"./useApiQuery-DZHaAgf7.js";import{P as _e,a as se}from"./PageSection-BbmHOMiD.js";import{F as T}from"./FormField-CsiVhN9M.js";import{S as I,I as W}from"./Input-jZIOmpmG.js";import{B as $}from"./Button-CkW8jVT-.js";import{S as de}from"./StatusBadge-DCmNAKwK.js";const ae=[20,50,100];function le(t,r=!1){if(!t)return;const n=r?`${t}T23:59:59.999`:`${t}T00:00:00.000`,b=Date.parse(n);return Number.isFinite(b)?b:void 0}function ne(t){const r=new Date(t);return`${r.getFullYear()}-${`${r.getMonth()+1}`.padStart(2,"0")}-${`${r.getDate()}`.padStart(2,"0")} ${`${r.getHours()}`.padStart(2,"0")}:${`${r.getMinutes()}`.padStart(2,"0")}:${`${r.getSeconds()}`.padStart(2,"0")}`}function _(t){return t==null?"-":t.toLocaleString()}function v(t,r){const n=_(t);return n==="-"?"-":`${n} ${r}`}function re(t){return t?"true":"false"}function ie(t,r){if(!t||t.trim().length===0)return r;try{const n=JSON.parse(t);return JSON.stringify(n,null,2)}catch{return t}}function Ke(){var Z,V;const{t}=M(),{pushToast:r}=oe(),[n,b]=i.useState("all"),[j,s]=i.useState("all"),[c,N]=i.useState(""),[u,h]=i.useState("all"),[g,a]=i.useState(""),[d,o]=i.useState(""),[x,w]=i.useState(1),[m,S]=i.useState(ae[0]),[O,L]=i.useState(null),[ce,G]=i.useState(!1),[D,Q]=i.useState([]),[q,H]=i.useState(!1);i.useEffect(()=>{w(1)},[n,j,c,u,g,d,m,D]);const R=i.useMemo(()=>{const l={limit:m,offset:(x-1)*m};n!=="all"&&(l.provider=n),j!=="all"&&(l.endpoint=j),c.trim().length>0&&(l.model=c.trim()),u!=="all"&&(l.status=u);const p=le(g),P=le(d,!0);return p!==void 0&&(l.from=p),P!==void 0&&(l.to=P),D.length>0&&(l.apiKeys=D.join(",")),l},[n,j,c,u,g,d,x,m,D]),f=K(["logs",R],{url:"/api/logs",method:"GET",params:R}),E=K(["providers","all"],{url:"/api/providers",method:"GET"}),J=K(["api-keys"],{url:"/api/keys",method:"GET"});i.useEffect(()=>{f.isError&&f.error&&r({title:t("logs.toast.listError.title"),description:t("logs.toast.listError.desc",{message:f.error.message}),variant:"error"})},[f.isError,f.error,r,t]),i.useEffect(()=>{E.isError&&E.error&&r({title:t("logs.toast.providerError.title"),description:t("logs.toast.providerError.desc",{message:E.error.message}),variant:"error"})},[E.isError,E.error,r,t]);const C=((Z=f.data)==null?void 0:Z.total)??0,k=C>0?Math.ceil(C/m):0,U=((V=f.data)==null?void 0:V.items)??[];i.useEffect(()=>{k>0&&x>k&&w(k)},[k,x]),i.useEffect(()=>{const l=document.querySelector(".table-container");l&&(l.style.overflow="hidden",setTimeout(()=>{l.style.overflow="auto"},10))},[U]);const z=E.data??[],Y=i.useMemo(()=>{const l=new Map;for(const p of z)p.id&&l.set(p.id,p.label??p.id);return l},[z]),B=J.data??[],X=i.useMemo(()=>{const l=new Map;for(const p of B)l.set(p.id,p);return l},[B]),xe=i.useMemo(()=>[{value:"all",label:t("logs.filters.statusAll")},{value:"success",label:t("logs.filters.statusSuccess")},{value:"error",label:t("logs.filters.statusError")}],[t]),me=()=>{b("all"),N(""),s("all"),h("all"),a(""),o(""),Q([])},pe=i.useCallback(async()=>{if(!q){H(!0);try{const l=C>0?Math.min(C,5e3):1e3,p={...R,limit:l,offset:0},P=await be.post("/api/logs/export",p,{responseType:"blob"}),ge=new Blob([P.data],{type:"application/zip"}),fe=new Date().toISOString().replace(/[:.]/g,"-"),ee=URL.createObjectURL(ge),F=document.createElement("a");F.href=ee,F.download=`cc-gw-logs-${fe}.zip`,document.body.appendChild(F),F.click(),F.remove(),URL.revokeObjectURL(ee),r({title:t("logs.toast.exportSuccess.title"),description:t("logs.toast.exportSuccess.desc"),variant:"success"})}catch(l){const p=je(l);r({title:t("logs.toast.exportError.title"),description:t("logs.toast.exportError.desc",{message:p.message}),variant:"error"})}finally{H(!1)}}},[q,r,R,t,C]),ue=i.useCallback(l=>{L(l),G(!0)},[]),he=i.useCallback(()=>{G(!1),L(null)},[]);return e.jsxs("div",{className:"flex flex-col gap-8",style:{width:"100%",maxWidth:"100%",overflow:"hidden"},children:[e.jsx(_e,{icon:e.jsx(ye,{className:"h-6 w-6","aria-hidden":"true"}),title:t("logs.title"),description:t("logs.description"),disableAnimation:!0,variant:"plain",className:"max-w-full",actions:e.jsxs("div",{className:"flex flex-wrap items-center gap-3 text-sm","aria-live":"polite",children:[e.jsx($,{variant:"primary",onClick:pe,loading:q,"aria-label":t("logs.actions.export"),className:"rounded-full",children:t("logs.actions.export")}),e.jsx("span",{className:y(A,"font-medium"),children:t("logs.summary.total",{value:C.toLocaleString()})}),e.jsx("button",{type:"button",onClick:()=>f.refetch(),disabled:f.isFetching,className:y(te,"h-10 rounded-full px-4",f.isFetching?"cursor-wait opacity-70":""),children:f.isFetching?t("common.actions.refreshing"):t("logs.actions.manualRefresh")})]})}),e.jsxs(se,{title:t("logs.filtersTitle"),description:t("logs.filtersDescription"),actions:e.jsx("button",{type:"button",onClick:me,className:y(te,"h-9 rounded-full px-4"),children:t("common.actions.reset")}),disableAnimation:!0,variant:"plain",className:"max-w-full",contentClassName:"grid w-full gap-3 md:grid-cols-2 xl:grid-cols-4",children:[e.jsx(T,{label:t("logs.filters.provider"),children:e.jsx(I,{value:n,onChange:l=>b(l.target.value),options:[{value:"all",label:t("logs.filters.providerAll")},...z.map(l=>({value:l.id,label:l.label??l.id}))]})}),e.jsx(T,{label:t("logs.filters.endpoint"),children:e.jsx(I,{value:j,onChange:l=>s(l.target.value),options:[{value:"all",label:t("logs.filters.endpointAll")},{value:"anthropic",label:t("logs.filters.endpointAnthropic")},{value:"openai",label:t("logs.filters.endpointOpenAI")}]})}),e.jsx(Ce,{className:"md:col-span-2",apiKeys:B,selected:D,disabled:J.isLoading,onChange:Q}),e.jsx(T,{label:t("logs.filters.modelId"),children:e.jsx(W,{value:c,onChange:l=>N(l.target.value),placeholder:t("logs.filters.modelPlaceholder")})}),e.jsx(T,{label:t("logs.filters.status"),children:e.jsx(I,{value:u,onChange:l=>h(l.target.value),options:xe})}),e.jsx(T,{label:t("logs.filters.startDate"),children:e.jsx(W,{type:"date",value:g,onChange:l=>a(l.target.value)})}),e.jsx(T,{label:t("logs.filters.endDate"),children:e.jsx(W,{type:"date",value:d,onChange:l=>o(l.target.value)})})]}),e.jsxs(se,{disableAnimation:!0,variant:"plain",className:"p-0 max-w-full",contentClassName:"gap-0",children:[e.jsx("div",{className:"w-full rounded-lg border border-slate-200 dark:border-slate-700",children:e.jsx("div",{className:"table-container",style:{overflowX:"auto",overflowY:"hidden",width:"100%"},children:e.jsx("div",{style:{width:"1270px",minWidth:"1270px"},children:e.jsxs("table",{className:"divide-y divide-slate-200 dark:divide-slate-700",style:{width:"100%",tableLayout:"fixed"},children:[e.jsxs("colgroup",{children:[e.jsx("col",{style:{width:"140px"}}),e.jsx("col",{style:{width:"80px"}}),e.jsx("col",{style:{width:"120px"}}),e.jsx("col",{style:{width:"130px"}}),e.jsx("col",{style:{width:"130px"}}),e.jsx("col",{style:{width:"100px"}}),e.jsx("col",{style:{width:"70px"}}),e.jsx("col",{style:{width:"70px"}}),e.jsx("col",{style:{width:"70px"}}),e.jsx("col",{style:{width:"70px"}}),e.jsx("col",{style:{width:"70px"}}),e.jsx("col",{style:{width:"80px"}}),e.jsx("col",{style:{width:"90px"}}),e.jsx("col",{style:{width:"120px"}}),e.jsx("col",{style:{width:"120px"}})]}),e.jsx("caption",{className:"sr-only",children:t("logs.title")}),e.jsx("thead",{className:"bg-gradient-to-b from-slate-100 to-slate-50 dark:from-slate-800 dark:to-slate-800/60 text-left font-bold uppercase tracking-wider text-slate-600 dark:text-slate-300 border-b-2 border-slate-200 dark:border-slate-700",style:{fontSize:"10px"},children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-3 py-2 text-left font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.time")}),e.jsx("th",{className:"px-3 py-2 text-left font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.endpoint")}),e.jsx("th",{className:"px-3 py-2 text-left font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.provider")}),e.jsx("th",{className:"px-3 py-2 text-left font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.requestedModel")}),e.jsx("th",{className:"px-3 py-2 text-left font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.routedModel")}),e.jsx("th",{className:"px-3 py-2 text-left font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.apiKey")}),e.jsx("th",{className:"px-3 py-2 text-right font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.inputTokens")}),e.jsx("th",{className:"px-3 py-2 text-right font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.cachedTokens")}),e.jsx("th",{className:"px-3 py-2 text-right font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.outputTokens")}),e.jsx("th",{className:"px-3 py-2 text-right font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.latency")}),e.jsx("th",{className:"px-3 py-2 text-right font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.ttft")}),e.jsx("th",{className:"px-3 py-2 text-right font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.tpot")}),e.jsx("th",{className:"px-3 py-2 text-center font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.status")}),e.jsx("th",{className:"px-3 py-2 text-left font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.error")}),e.jsx("th",{className:"px-3 py-2 text-center font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.actions")})]})}),e.jsx("tbody",{className:"divide-y divide-slate-200/80 bg-white dark:divide-slate-700/80 dark:bg-slate-900",children:f.isPending?e.jsx("tr",{children:e.jsx("td",{colSpan:15,className:"px-3 py-8 text-center text-xs text-slate-400 dark:text-slate-500",children:t("logs.table.loading")})}):U.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:15,className:"px-3 py-8 text-center text-xs text-slate-400 dark:text-slate-500",children:t("logs.table.empty")})}):U.map((l,p)=>e.jsx(Se,{record:l,providerLabelMap:Y,apiKeyMap:X,onSelect:ue,isEven:p%2===0},l.id))})]})})})}),e.jsxs("div",{className:ke,children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:y(A,"whitespace-nowrap"),children:t("logs.table.pagination.perPage")}),e.jsx("select",{value:m,onChange:l=>S(Number(l.target.value)),className:Ne,children:ae.map(l=>e.jsxs("option",{value:l,children:[l," ",t("logs.table.pagination.unit")]},l))})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx($,{onClick:()=>w(l=>Math.max(l-1,1)),disabled:x<=1,size:"sm",className:"rounded-full",children:t("logs.table.pagination.previous")}),e.jsx("span",{className:y(A,"font-medium"),children:t("logs.table.pagination.pageLabel",{page:k===0?0:x,total:k})}),e.jsx($,{onClick:()=>w(l=>k===0?l:Math.min(l+1,k)),disabled:k===0||x>=k,size:"sm",className:"rounded-full",children:t("logs.table.pagination.next")})]})]})]}),e.jsx(Ee,{open:ce,logId:O,onClose:he,providerLabelMap:Y,apiKeyMap:X})]})}function Se({record:t,providerLabelMap:r,apiKeyMap:n,onSelect:b,isEven:j}){const{t:s}=M(),c=r.get(t.provider)??t.provider,N=t.endpoint||"-",u=!!t.error,h=t.status_code,g=t.client_model??s("logs.table.requestedModelFallback"),a=t.api_key_id!=null?n.get(t.api_key_id):void 0,d=t.api_key_id==null?s("logs.table.apiKeyUnknown"):a!=null&&a.isWildcard?s("apiKeys.wildcard"):a!=null&&a.name?a.name:t.api_key_name?t.api_key_name:s("logs.table.apiKeyUnknown");return e.jsxs("tr",{className:y("transition-colors duration-150",j?"bg-slate-50/30 dark:bg-slate-800/20":"bg-white dark:bg-slate-900","hover:bg-blue-50/50 dark:hover:bg-blue-900/20"),children:[e.jsx("td",{className:"px-3 py-2.5 text-xs font-medium text-slate-700 dark:text-slate-100 whitespace-nowrap",children:ne(t.timestamp)}),e.jsx("td",{className:"px-3 py-2.5 text-xs text-slate-700 dark:text-slate-100 whitespace-nowrap",children:N}),e.jsx("td",{className:"px-3 py-2.5 text-xs text-slate-700 dark:text-slate-100",children:e.jsx("div",{className:"truncate",title:c,children:c})}),e.jsx("td",{className:"px-3 py-2.5 text-xs text-slate-600 dark:text-slate-200",children:e.jsx("div",{className:"truncate",title:g,children:g})}),e.jsx("td",{className:"px-3 py-2.5 text-xs text-slate-700 dark:text-slate-100",children:e.jsx("div",{className:"truncate",title:t.model,children:t.model})}),e.jsx("td",{className:"px-3 py-2.5",children:e.jsx("div",{className:y(A,"truncate text-xs"),title:d,children:d})}),e.jsx("td",{className:"px-3 py-2.5 text-right text-xs font-medium text-slate-700 dark:text-slate-100 tabular-nums",children:_(t.input_tokens)}),e.jsx("td",{className:"px-3 py-2.5 text-right text-xs font-medium text-slate-700 dark:text-slate-100 tabular-nums",children:_(t.cached_tokens)}),e.jsx("td",{className:"px-3 py-2.5 text-right text-xs font-medium text-slate-700 dark:text-slate-100 tabular-nums",children:_(t.output_tokens)}),e.jsx("td",{className:"px-3 py-2.5 text-right text-xs text-slate-700 dark:text-slate-100 tabular-nums whitespace-nowrap",children:v(t.latency_ms,"ms")}),e.jsx("td",{className:"px-3 py-2.5 text-right text-xs text-slate-700 dark:text-slate-100 tabular-nums whitespace-nowrap",children:v(t.ttft_ms,"ms")}),e.jsx("td",{className:"px-3 py-2.5 text-right text-xs text-slate-700 dark:text-slate-100 tabular-nums whitespace-nowrap",children:v(t.tpot_ms,"ms/tk")}),e.jsx("td",{className:"px-3 py-2.5 text-center",children:e.jsx(de,{variant:u?"error":"success",children:h??(u?500:200)})}),e.jsx("td",{className:"px-3 py-2.5 text-[10px] text-slate-500 dark:text-slate-400",children:e.jsx("div",{className:"truncate",title:t.error??"",children:t.error?t.error:"-"})}),e.jsx("td",{className:"px-3 py-2.5 text-center",children:e.jsx($,{onClick:()=>b(t.id),size:"sm",className:"rounded-full text-xs px-2 py-1",children:"详情"})})]})}function Ee({open:t,logId:r,onClose:n,providerLabelMap:b,apiKeyMap:j}){var x,w;const{t:s}=M(),{pushToast:c}=oe(),N=i.useRef(null),u=i.useRef(null),h=K(["log-detail",r],{url:`/api/logs/${r}`,method:"GET"},{enabled:t&&r!==null,staleTime:3e4});i.useEffect(()=>{h.isError&&h.error&&c({title:s("logs.detail.loadError"),description:h.error.message,variant:"error"})},[h.isError,h.error,c,s]),i.useEffect(()=>{if(!t)return;const m=S=>{S.key==="Escape"&&n()};return window.addEventListener("keydown",m),()=>window.removeEventListener("keydown",m)},[t,n]),i.useEffect(()=>{t&&u.current&&u.current.focus()},[t,r]);const g=i.useCallback(async(m,S,O)=>{if(!S){c({title:s("logs.detail.copy.empty",{label:m}),variant:"info"});return}try{await navigator.clipboard.writeText(S),c({title:s(O),variant:"success"})}catch(L){c({title:s("logs.detail.copy.failure"),description:L instanceof Error?L.message:s("logs.detail.copy.failureFallback"),variant:"error"})}},[c,s]);if(!t)return null;const a=h.data,d=a?b.get(a.provider)??a.provider:"",o=a&&a.api_key_id!=null?j.get(a.api_key_id):void 0;return typeof document>"u"?null:ve.createPortal(e.jsxs("div",{className:"fixed inset-0 z-50 flex",children:[e.jsx("div",{className:"flex-1 bg-slate-900/60",onClick:n,"aria-hidden":"true"}),e.jsxs("aside",{ref:N,role:"dialog","aria-modal":"true","aria-labelledby":"log-detail-title","aria-describedby":"log-detail-content",className:"flex h-full w-full max-w-xl flex-col border-l border-slate-200 bg-white shadow-xl transition-all dark:border-slate-800 dark:bg-slate-900",children:[e.jsxs("header",{className:"flex items-center justify-between border-b border-slate-200 px-6 py-4 dark:border-slate-800",children:[e.jsxs("div",{children:[e.jsx("h2",{id:"log-detail-title",className:"text-lg font-semibold",children:s("logs.detail.title")}),a?e.jsx("p",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.id",{id:a.id})}):null]}),e.jsx("button",{type:"button",ref:u,onClick:n,className:"rounded-md border border-slate-200 px-3 py-1 text-sm transition hover:bg-slate-100 dark:border-slate-700 dark:hover:bg-slate-800",children:s("common.actions.close")})]}),e.jsx("div",{id:"log-detail-content",className:"flex-1 overflow-y-auto",children:h.isPending?e.jsx(we,{}):a?e.jsxs("div",{className:"flex flex-col gap-6 px-6 py-5 text-sm",children:[e.jsxs("section",{className:"space-y-2",children:[e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wide text-slate-500 dark:text-slate-400",children:s("logs.detail.infoSection")}),e.jsxs("div",{className:"flex flex-wrap items-center gap-3 rounded-md bg-slate-100 px-3 py-2 text-xs text-slate-600 dark:bg-slate-800/60 dark:text-slate-300",children:[e.jsx("span",{className:"text-sm font-medium text-slate-700 dark:text-slate-100",children:s("logs.detail.summary.route",{from:a.client_model??s("logs.detail.info.noRequestedModel"),to:a.model})}),e.jsx("span",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.summary.latency",{value:v(a.latency_ms,s("common.units.ms"))})}),a.ttft_ms!==null?e.jsx("span",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.summary.ttft",{value:v(a.ttft_ms,s("common.units.ms"))})}):null,a.tpot_ms!==null?e.jsx("span",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.summary.tpot",{value:v(a.tpot_ms,s("common.units.msPerToken"))})}):null,e.jsx("span",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.summary.stream",{value:re(a.stream)})}),e.jsxs(de,{variant:a.error?"error":"success",children:[(a.status_code??(a.error?500:200)).toString(),e.jsx("span",{children:a.error?s("common.status.error"):s("common.status.success")})]})]}),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-slate-500 dark:text-slate-400",children:s("logs.detail.info.time")}),e.jsx("dd",{className:"font-medium",children:ne(a.timestamp)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.info.sessionId")}),e.jsx("dd",{className:"font-medium",children:a.session_id??"-"})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.info.endpoint")}),e.jsx("dd",{className:"font-medium",children:a.endpoint||"-"}),e.jsx("dt",{className:"mt-2 text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.info.provider")}),e.jsx("dd",{className:"font-medium",children:d})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.info.requestedModel")}),e.jsx("dd",{className:"font-medium",children:a.client_model??s("logs.detail.info.noRequestedModel")})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.info.model")}),e.jsx("dd",{className:"font-medium",children:a.model})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.info.stream")}),e.jsx("dd",{className:"font-medium",children:re(a.stream)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.info.inputTokens")}),e.jsx("dd",{className:"font-medium",children:_(a.input_tokens)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.info.cachedTokens")}),e.jsx("dd",{className:"font-medium",children:_(a.cached_tokens)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.info.outputTokens")}),e.jsx("dd",{className:"font-medium",children:_(a.output_tokens)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.info.ttft")}),e.jsx("dd",{className:"font-medium",children:v(a.ttft_ms,s("common.units.ms"))})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.info.tpot")}),e.jsx("dd",{className:"font-medium",children:v(a.tpot_ms,s("common.units.msPerToken"))})]})]}),a.error?e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.info.error")}),e.jsx("p",{className:"rounded-md border border-red-200 bg-red-50 p-3 text-xs leading-5 text-red-700 dark:border-red-800/70 dark:bg-red-900/40 dark:text-red-200",children:a.error})]}):null]}),e.jsxs("section",{className:"space-y-2",children:[e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wide text-slate-500 dark:text-slate-400",children:s("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-slate-500 dark:text-slate-400",children:s("logs.detail.apiKey.name")}),e.jsx("dd",{className:"font-medium",children:a.api_key_id==null&&!a.api_key_name?s("logs.detail.apiKey.missing"):o!=null&&o.isWildcard?s("apiKeys.wildcard"):(o==null?void 0:o.name)??a.api_key_name??s("logs.detail.apiKey.missing")})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.apiKey.identifier")}),e.jsx("dd",{className:"font-medium",children:a.api_key_id??s("common.noData")})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.apiKey.masked")}),e.jsx("dd",{className:"font-medium",children:o!=null&&o.isWildcard?s("apiKeys.wildcard"):(o==null?void 0:o.maskedKey)??a.api_key_name??s("logs.detail.apiKey.maskedUnavailable")})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.apiKey.lastUsed")}),e.jsx("dd",{className:"font-medium",children:o!=null&&o.lastUsedAt?new Date(o.lastUsedAt).toLocaleString():s("common.noData")})]})]}),e.jsxs("div",{className:"rounded-md border border-slate-200 bg-slate-50 px-3 py-3 text-xs text-slate-600 dark:border-slate-800 dark:bg-slate-800/60 dark:text-slate-300",children:[e.jsx("p",{className:"font-medium text-slate-700 dark:text-slate-200",children:s("logs.detail.apiKey.rawMasked")}),e.jsx("p",{className:"mt-1 break-all text-xs font-mono",children:a.api_key_value_available?a.api_key_value_masked??s("logs.detail.apiKey.rawUnavailable"):s("logs.detail.apiKey.rawUnavailable")}),e.jsx("p",{className:"mt-2 text-[11px] leading-relaxed text-slate-500 dark:text-slate-400",children:s("logs.detail.apiKey.rawMaskedHint")})]})]}),e.jsxs("section",{className:"space-y-2",children:[e.jsxs("header",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wide text-slate-500 dark:text-slate-400",children:s("logs.detail.payload.request")}),e.jsx("button",{type:"button",onClick:()=>{var m;return g(s("logs.detail.payload.request"),(m=a.payload)==null?void 0:m.prompt,"logs.detail.copy.requestSuccess")},className:"rounded-md border border-slate-200 px-2 py-1 text-xs transition hover:bg-slate-100 dark:border-slate-700 dark:hover:bg-slate-800",children:s("common.actions.copy")})]}),e.jsx("pre",{className:"max-h-64 overflow-auto whitespace-pre-wrap rounded-md border border-slate-200 bg-slate-50 p-3 text-xs leading-5 text-slate-700 dark:border-slate-800 dark:bg-slate-900/80 dark:text-slate-200",children:ie((x=a.payload)==null?void 0:x.prompt,s("logs.detail.payload.emptyRequest"))})]}),e.jsxs("section",{className:"space-y-2",children:[e.jsxs("header",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wide text-slate-500 dark:text-slate-400",children:s("logs.detail.payload.response")}),e.jsx("button",{type:"button",onClick:()=>{var m;return g(s("logs.detail.payload.response"),(m=a.payload)==null?void 0:m.response,"logs.detail.copy.responseSuccess")},className:"rounded-md border border-slate-200 px-2 py-1 text-xs transition hover:bg-slate-100 dark:border-slate-700 dark:hover:bg-slate-800",children:s("common.actions.copy")})]}),e.jsx("pre",{className:"max-h-64 overflow-auto whitespace-pre-wrap rounded-md border border-slate-200 bg-slate-50 p-3 text-xs leading-5 text-slate-700 dark:border-slate-800 dark:bg-slate-900/80 dark:text-slate-200",children:ie((w=a.payload)==null?void 0:w.response,s("logs.detail.payload.emptyResponse"))})]})]}):e.jsx("div",{className:"flex h-full items-center justify.center p-8 text-sm text-slate-500 dark:text-slate-400",children:s("logs.detail.loadError")})})]})]}),document.body)}function Ce({apiKeys:t,selected:r,onChange:n,disabled:b,className:j}){const{t:s}=M(),[c,N]=i.useState(!1),u=i.useRef(null);i.useEffect(()=>{if(!c)return;const d=o=>{var x;(x=u.current)!=null&&x.contains(o.target)||N(!1)};return window.addEventListener("mousedown",d),()=>window.removeEventListener("mousedown",d)},[c]);const h=i.useMemo(()=>{if(r.length===0)return[];const d=new Map;for(const o of t)d.set(o.id,o);return r.map(o=>{const x=d.get(o);return x?x.isWildcard?s("apiKeys.wildcard"):x.name:null}).filter(o=>!!o)},[t,r,s]),g=r.length===0?s("logs.filters.apiKeyAll"):s("logs.filters.apiKeySelected",{count:r.length}),a=d=>{r.includes(d)?n(r.filter(o=>o!==d)):n([...r,d])};return e.jsxs("div",{className:y("relative flex flex-col gap-2",j),ref:u,children:[e.jsx("label",{className:"text-xs font-semibold uppercase tracking-wide text-slate-500 dark:text-slate-400",children:s("logs.filters.apiKey")}),e.jsxs("button",{type:"button",onClick:()=>N(d=>!d),disabled:b||t.length===0,title:s("logs.filters.apiKeyHint"),className:y("flex h-10 w-full items-center justify-between rounded-xl border border-slate-200/70 bg-white/90 px-3 text-sm font-medium text-slate-600 shadow-sm shadow-slate-200/60 transition focus:outline-none focus:ring-2 focus:ring-blue-400/30 disabled:cursor-not-allowed disabled:opacity-50 dark:border-slate-700/60 dark:bg-slate-900/80 dark:text-slate-200",r.length>0?"border-blue-400 text-blue-700 dark:border-blue-400 dark:text-blue-200":"",c?"ring-2 ring-blue-400/30":""),"aria-haspopup":"listbox","aria-expanded":c,children:[e.jsxs("span",{className:"truncate",children:[g,h.length>0&&e.jsx("span",{className:"ml-1 text-xs text-slate-500 dark:text-slate-400",children:h.join(", ")})]}),e.jsx("svg",{className:y("h-4 w-4 text-slate-400 transition-all dark:text-slate-300",c?"rotate-180":""),viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true",children:e.jsx("path",{fillRule:"evenodd",d:"M5.23 7.21a.75.75 0 011.06.02L10 10.94l3.71-3.71a.75.75 0 111.06 1.06l-4.24 4.25a.75.75 0 01-1.06 0L5.21 8.29a.75.75 0 01.02-1.08z",clipRule:"evenodd"})})]}),c&&e.jsxs("div",{className:"absolute left-0 top-full z-30 mt-2 w-64 rounded-2xl border border-slate-200/70 bg-white p-2 shadow-lg shadow-slate-200/70 dark:border-slate-700/60 dark:bg-slate-900",children:[e.jsxs("div",{className:"flex items-center justify-between rounded-xl border border-slate-200/60 bg-slate-50/70 px-3 py-2 text-xs font-medium text-slate-500 dark:border-slate-700/50 dark:bg-slate-800/60 dark:text-slate-300",children:[e.jsx("span",{children:g}),e.jsx("button",{type:"button",onClick:()=>n([]),disabled:r.length===0,className:"text-blue-600 hover:underline disabled:opacity-40 dark:text-blue-400",children:s("common.actions.reset")})]}),e.jsxs("div",{className:"max-h-56 overflow-y-auto px-1 py-2",children:[t.map(d=>{const o=d.isWildcard?s("apiKeys.wildcard"):d.name,x=r.includes(d.id);return e.jsxs("label",{className:y("flex cursor-pointer items-center gap-2 rounded-xl px-3 py-2 text-sm transition hover:bg-slate-100 dark:hover:bg-slate-800",x?"bg-blue-50/70 text-blue-600 dark:bg-blue-900/30 dark:text-blue-200":"text-slate-600 dark:text-slate-200"),children:[e.jsx("input",{type:"checkbox",className:"h-4 w-4 rounded border-slate-300 text-blue-600 focus:ring-blue-400 dark:border-slate-600",checked:x,onChange:()=>a(d.id)}),e.jsx("span",{className:"truncate",children:o})]},d.id)}),t.length===0&&e.jsx("p",{className:"px-2 py-2 text-xs text-slate-500 dark:text-slate-400",children:s("logs.filters.apiKeyAll")})]})]})]})}export{Ke as default};
1
+ import{u as M,a as oe,r as i,b as be,t as je,j as e,d as y,k as te,F as ye,p as ke,o as Ne,m as A,q as ve,L as we}from"./index-BK1UNVMz.js";import{u as K}from"./useApiQuery-BNTE55UK.js";import{P as _e,a as se}from"./PageSection-B08EcVAN.js";import{F as T}from"./FormField-SZpxR702.js";import{S as I,I as W}from"./Input-BdyQWPOU.js";import{B as $}from"./Button-CZXniSHM.js";import{S as de}from"./StatusBadge-8KAMZvYW.js";const ae=[20,50,100];function le(t,r=!1){if(!t)return;const n=r?`${t}T23:59:59.999`:`${t}T00:00:00.000`,b=Date.parse(n);return Number.isFinite(b)?b:void 0}function ne(t){const r=new Date(t);return`${r.getFullYear()}-${`${r.getMonth()+1}`.padStart(2,"0")}-${`${r.getDate()}`.padStart(2,"0")} ${`${r.getHours()}`.padStart(2,"0")}:${`${r.getMinutes()}`.padStart(2,"0")}:${`${r.getSeconds()}`.padStart(2,"0")}`}function _(t){return t==null?"-":t.toLocaleString()}function v(t,r){const n=_(t);return n==="-"?"-":`${n} ${r}`}function re(t){return t?"true":"false"}function ie(t,r){if(!t||t.trim().length===0)return r;try{const n=JSON.parse(t);return JSON.stringify(n,null,2)}catch{return t}}function Ke(){var Z,V;const{t}=M(),{pushToast:r}=oe(),[n,b]=i.useState("all"),[j,s]=i.useState("all"),[c,N]=i.useState(""),[u,h]=i.useState("all"),[g,a]=i.useState(""),[d,o]=i.useState(""),[x,w]=i.useState(1),[m,S]=i.useState(ae[0]),[O,L]=i.useState(null),[ce,G]=i.useState(!1),[D,Q]=i.useState([]),[q,H]=i.useState(!1);i.useEffect(()=>{w(1)},[n,j,c,u,g,d,m,D]);const R=i.useMemo(()=>{const l={limit:m,offset:(x-1)*m};n!=="all"&&(l.provider=n),j!=="all"&&(l.endpoint=j),c.trim().length>0&&(l.model=c.trim()),u!=="all"&&(l.status=u);const p=le(g),P=le(d,!0);return p!==void 0&&(l.from=p),P!==void 0&&(l.to=P),D.length>0&&(l.apiKeys=D.join(",")),l},[n,j,c,u,g,d,x,m,D]),f=K(["logs",R],{url:"/api/logs",method:"GET",params:R}),E=K(["providers","all"],{url:"/api/providers",method:"GET"}),J=K(["api-keys"],{url:"/api/keys",method:"GET"});i.useEffect(()=>{f.isError&&f.error&&r({title:t("logs.toast.listError.title"),description:t("logs.toast.listError.desc",{message:f.error.message}),variant:"error"})},[f.isError,f.error,r,t]),i.useEffect(()=>{E.isError&&E.error&&r({title:t("logs.toast.providerError.title"),description:t("logs.toast.providerError.desc",{message:E.error.message}),variant:"error"})},[E.isError,E.error,r,t]);const C=((Z=f.data)==null?void 0:Z.total)??0,k=C>0?Math.ceil(C/m):0,U=((V=f.data)==null?void 0:V.items)??[];i.useEffect(()=>{k>0&&x>k&&w(k)},[k,x]),i.useEffect(()=>{const l=document.querySelector(".table-container");l&&(l.style.overflow="hidden",setTimeout(()=>{l.style.overflow="auto"},10))},[U]);const z=E.data??[],Y=i.useMemo(()=>{const l=new Map;for(const p of z)p.id&&l.set(p.id,p.label??p.id);return l},[z]),B=J.data??[],X=i.useMemo(()=>{const l=new Map;for(const p of B)l.set(p.id,p);return l},[B]),xe=i.useMemo(()=>[{value:"all",label:t("logs.filters.statusAll")},{value:"success",label:t("logs.filters.statusSuccess")},{value:"error",label:t("logs.filters.statusError")}],[t]),me=()=>{b("all"),N(""),s("all"),h("all"),a(""),o(""),Q([])},pe=i.useCallback(async()=>{if(!q){H(!0);try{const l=C>0?Math.min(C,5e3):1e3,p={...R,limit:l,offset:0},P=await be.post("/api/logs/export",p,{responseType:"blob"}),ge=new Blob([P.data],{type:"application/zip"}),fe=new Date().toISOString().replace(/[:.]/g,"-"),ee=URL.createObjectURL(ge),F=document.createElement("a");F.href=ee,F.download=`cc-gw-logs-${fe}.zip`,document.body.appendChild(F),F.click(),F.remove(),URL.revokeObjectURL(ee),r({title:t("logs.toast.exportSuccess.title"),description:t("logs.toast.exportSuccess.desc"),variant:"success"})}catch(l){const p=je(l);r({title:t("logs.toast.exportError.title"),description:t("logs.toast.exportError.desc",{message:p.message}),variant:"error"})}finally{H(!1)}}},[q,r,R,t,C]),ue=i.useCallback(l=>{L(l),G(!0)},[]),he=i.useCallback(()=>{G(!1),L(null)},[]);return e.jsxs("div",{className:"flex flex-col gap-8",style:{width:"100%",maxWidth:"100%",overflow:"hidden"},children:[e.jsx(_e,{icon:e.jsx(ye,{className:"h-6 w-6","aria-hidden":"true"}),title:t("logs.title"),description:t("logs.description"),disableAnimation:!0,variant:"plain",className:"max-w-full",actions:e.jsxs("div",{className:"flex flex-wrap items-center gap-3 text-sm","aria-live":"polite",children:[e.jsx($,{variant:"primary",onClick:pe,loading:q,"aria-label":t("logs.actions.export"),className:"rounded-full",children:t("logs.actions.export")}),e.jsx("span",{className:y(A,"font-medium"),children:t("logs.summary.total",{value:C.toLocaleString()})}),e.jsx("button",{type:"button",onClick:()=>f.refetch(),disabled:f.isFetching,className:y(te,"h-10 rounded-full px-4",f.isFetching?"cursor-wait opacity-70":""),children:f.isFetching?t("common.actions.refreshing"):t("logs.actions.manualRefresh")})]})}),e.jsxs(se,{title:t("logs.filtersTitle"),description:t("logs.filtersDescription"),actions:e.jsx("button",{type:"button",onClick:me,className:y(te,"h-9 rounded-full px-4"),children:t("common.actions.reset")}),disableAnimation:!0,variant:"plain",className:"max-w-full",contentClassName:"grid w-full gap-3 md:grid-cols-2 xl:grid-cols-4",children:[e.jsx(T,{label:t("logs.filters.provider"),children:e.jsx(I,{value:n,onChange:l=>b(l.target.value),options:[{value:"all",label:t("logs.filters.providerAll")},...z.map(l=>({value:l.id,label:l.label??l.id}))]})}),e.jsx(T,{label:t("logs.filters.endpoint"),children:e.jsx(I,{value:j,onChange:l=>s(l.target.value),options:[{value:"all",label:t("logs.filters.endpointAll")},{value:"anthropic",label:t("logs.filters.endpointAnthropic")},{value:"openai",label:t("logs.filters.endpointOpenAI")}]})}),e.jsx(Ce,{className:"md:col-span-2",apiKeys:B,selected:D,disabled:J.isLoading,onChange:Q}),e.jsx(T,{label:t("logs.filters.modelId"),children:e.jsx(W,{value:c,onChange:l=>N(l.target.value),placeholder:t("logs.filters.modelPlaceholder")})}),e.jsx(T,{label:t("logs.filters.status"),children:e.jsx(I,{value:u,onChange:l=>h(l.target.value),options:xe})}),e.jsx(T,{label:t("logs.filters.startDate"),children:e.jsx(W,{type:"date",value:g,onChange:l=>a(l.target.value)})}),e.jsx(T,{label:t("logs.filters.endDate"),children:e.jsx(W,{type:"date",value:d,onChange:l=>o(l.target.value)})})]}),e.jsxs(se,{disableAnimation:!0,variant:"plain",className:"p-0 max-w-full",contentClassName:"gap-0",children:[e.jsx("div",{className:"w-full rounded-lg border border-slate-200 dark:border-slate-700",children:e.jsx("div",{className:"table-container",style:{overflowX:"auto",overflowY:"hidden",width:"100%"},children:e.jsx("div",{style:{width:"1270px",minWidth:"1270px"},children:e.jsxs("table",{className:"divide-y divide-slate-200 dark:divide-slate-700",style:{width:"100%",tableLayout:"fixed"},children:[e.jsxs("colgroup",{children:[e.jsx("col",{style:{width:"140px"}}),e.jsx("col",{style:{width:"80px"}}),e.jsx("col",{style:{width:"120px"}}),e.jsx("col",{style:{width:"130px"}}),e.jsx("col",{style:{width:"130px"}}),e.jsx("col",{style:{width:"100px"}}),e.jsx("col",{style:{width:"70px"}}),e.jsx("col",{style:{width:"70px"}}),e.jsx("col",{style:{width:"70px"}}),e.jsx("col",{style:{width:"70px"}}),e.jsx("col",{style:{width:"70px"}}),e.jsx("col",{style:{width:"80px"}}),e.jsx("col",{style:{width:"90px"}}),e.jsx("col",{style:{width:"120px"}}),e.jsx("col",{style:{width:"120px"}})]}),e.jsx("caption",{className:"sr-only",children:t("logs.title")}),e.jsx("thead",{className:"bg-gradient-to-b from-slate-100 to-slate-50 dark:from-slate-800 dark:to-slate-800/60 text-left font-bold uppercase tracking-wider text-slate-600 dark:text-slate-300 border-b-2 border-slate-200 dark:border-slate-700",style:{fontSize:"10px"},children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-3 py-2 text-left font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.time")}),e.jsx("th",{className:"px-3 py-2 text-left font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.endpoint")}),e.jsx("th",{className:"px-3 py-2 text-left font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.provider")}),e.jsx("th",{className:"px-3 py-2 text-left font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.requestedModel")}),e.jsx("th",{className:"px-3 py-2 text-left font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.routedModel")}),e.jsx("th",{className:"px-3 py-2 text-left font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.apiKey")}),e.jsx("th",{className:"px-3 py-2 text-right font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.inputTokens")}),e.jsx("th",{className:"px-3 py-2 text-right font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.cachedTokens")}),e.jsx("th",{className:"px-3 py-2 text-right font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.outputTokens")}),e.jsx("th",{className:"px-3 py-2 text-right font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.latency")}),e.jsx("th",{className:"px-3 py-2 text-right font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.ttft")}),e.jsx("th",{className:"px-3 py-2 text-right font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.tpot")}),e.jsx("th",{className:"px-3 py-2 text-center font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.status")}),e.jsx("th",{className:"px-3 py-2 text-left font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.error")}),e.jsx("th",{className:"px-3 py-2 text-center font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.actions")})]})}),e.jsx("tbody",{className:"divide-y divide-slate-200/80 bg-white dark:divide-slate-700/80 dark:bg-slate-900",children:f.isPending?e.jsx("tr",{children:e.jsx("td",{colSpan:15,className:"px-3 py-8 text-center text-xs text-slate-400 dark:text-slate-500",children:t("logs.table.loading")})}):U.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:15,className:"px-3 py-8 text-center text-xs text-slate-400 dark:text-slate-500",children:t("logs.table.empty")})}):U.map((l,p)=>e.jsx(Se,{record:l,providerLabelMap:Y,apiKeyMap:X,onSelect:ue,isEven:p%2===0},l.id))})]})})})}),e.jsxs("div",{className:ke,children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:y(A,"whitespace-nowrap"),children:t("logs.table.pagination.perPage")}),e.jsx("select",{value:m,onChange:l=>S(Number(l.target.value)),className:Ne,children:ae.map(l=>e.jsxs("option",{value:l,children:[l," ",t("logs.table.pagination.unit")]},l))})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx($,{onClick:()=>w(l=>Math.max(l-1,1)),disabled:x<=1,size:"sm",className:"rounded-full",children:t("logs.table.pagination.previous")}),e.jsx("span",{className:y(A,"font-medium"),children:t("logs.table.pagination.pageLabel",{page:k===0?0:x,total:k})}),e.jsx($,{onClick:()=>w(l=>k===0?l:Math.min(l+1,k)),disabled:k===0||x>=k,size:"sm",className:"rounded-full",children:t("logs.table.pagination.next")})]})]})]}),e.jsx(Ee,{open:ce,logId:O,onClose:he,providerLabelMap:Y,apiKeyMap:X})]})}function Se({record:t,providerLabelMap:r,apiKeyMap:n,onSelect:b,isEven:j}){const{t:s}=M(),c=r.get(t.provider)??t.provider,N=t.endpoint||"-",u=!!t.error,h=t.status_code,g=t.client_model??s("logs.table.requestedModelFallback"),a=t.api_key_id!=null?n.get(t.api_key_id):void 0,d=t.api_key_id==null?s("logs.table.apiKeyUnknown"):a!=null&&a.isWildcard?s("apiKeys.wildcard"):a!=null&&a.name?a.name:t.api_key_name?t.api_key_name:s("logs.table.apiKeyUnknown");return e.jsxs("tr",{className:y("transition-colors duration-150",j?"bg-slate-50/30 dark:bg-slate-800/20":"bg-white dark:bg-slate-900","hover:bg-blue-50/50 dark:hover:bg-blue-900/20"),children:[e.jsx("td",{className:"px-3 py-2.5 text-xs font-medium text-slate-700 dark:text-slate-100 whitespace-nowrap",children:ne(t.timestamp)}),e.jsx("td",{className:"px-3 py-2.5 text-xs text-slate-700 dark:text-slate-100 whitespace-nowrap",children:N}),e.jsx("td",{className:"px-3 py-2.5 text-xs text-slate-700 dark:text-slate-100",children:e.jsx("div",{className:"truncate",title:c,children:c})}),e.jsx("td",{className:"px-3 py-2.5 text-xs text-slate-600 dark:text-slate-200",children:e.jsx("div",{className:"truncate",title:g,children:g})}),e.jsx("td",{className:"px-3 py-2.5 text-xs text-slate-700 dark:text-slate-100",children:e.jsx("div",{className:"truncate",title:t.model,children:t.model})}),e.jsx("td",{className:"px-3 py-2.5",children:e.jsx("div",{className:y(A,"truncate text-xs"),title:d,children:d})}),e.jsx("td",{className:"px-3 py-2.5 text-right text-xs font-medium text-slate-700 dark:text-slate-100 tabular-nums",children:_(t.input_tokens)}),e.jsx("td",{className:"px-3 py-2.5 text-right text-xs font-medium text-slate-700 dark:text-slate-100 tabular-nums",children:_(t.cached_tokens)}),e.jsx("td",{className:"px-3 py-2.5 text-right text-xs font-medium text-slate-700 dark:text-slate-100 tabular-nums",children:_(t.output_tokens)}),e.jsx("td",{className:"px-3 py-2.5 text-right text-xs text-slate-700 dark:text-slate-100 tabular-nums whitespace-nowrap",children:v(t.latency_ms,"ms")}),e.jsx("td",{className:"px-3 py-2.5 text-right text-xs text-slate-700 dark:text-slate-100 tabular-nums whitespace-nowrap",children:v(t.ttft_ms,"ms")}),e.jsx("td",{className:"px-3 py-2.5 text-right text-xs text-slate-700 dark:text-slate-100 tabular-nums whitespace-nowrap",children:v(t.tpot_ms,"ms/tk")}),e.jsx("td",{className:"px-3 py-2.5 text-center",children:e.jsx(de,{variant:u?"error":"success",children:h??(u?500:200)})}),e.jsx("td",{className:"px-3 py-2.5 text-[10px] text-slate-500 dark:text-slate-400",children:e.jsx("div",{className:"truncate",title:t.error??"",children:t.error?t.error:"-"})}),e.jsx("td",{className:"px-3 py-2.5 text-center",children:e.jsx($,{onClick:()=>b(t.id),size:"sm",className:"rounded-full text-xs px-2 py-1",children:"详情"})})]})}function Ee({open:t,logId:r,onClose:n,providerLabelMap:b,apiKeyMap:j}){var x,w;const{t:s}=M(),{pushToast:c}=oe(),N=i.useRef(null),u=i.useRef(null),h=K(["log-detail",r],{url:`/api/logs/${r}`,method:"GET"},{enabled:t&&r!==null,staleTime:3e4});i.useEffect(()=>{h.isError&&h.error&&c({title:s("logs.detail.loadError"),description:h.error.message,variant:"error"})},[h.isError,h.error,c,s]),i.useEffect(()=>{if(!t)return;const m=S=>{S.key==="Escape"&&n()};return window.addEventListener("keydown",m),()=>window.removeEventListener("keydown",m)},[t,n]),i.useEffect(()=>{t&&u.current&&u.current.focus()},[t,r]);const g=i.useCallback(async(m,S,O)=>{if(!S){c({title:s("logs.detail.copy.empty",{label:m}),variant:"info"});return}try{await navigator.clipboard.writeText(S),c({title:s(O),variant:"success"})}catch(L){c({title:s("logs.detail.copy.failure"),description:L instanceof Error?L.message:s("logs.detail.copy.failureFallback"),variant:"error"})}},[c,s]);if(!t)return null;const a=h.data,d=a?b.get(a.provider)??a.provider:"",o=a&&a.api_key_id!=null?j.get(a.api_key_id):void 0;return typeof document>"u"?null:ve.createPortal(e.jsxs("div",{className:"fixed inset-0 z-50 flex",children:[e.jsx("div",{className:"flex-1 bg-slate-900/60",onClick:n,"aria-hidden":"true"}),e.jsxs("aside",{ref:N,role:"dialog","aria-modal":"true","aria-labelledby":"log-detail-title","aria-describedby":"log-detail-content",className:"flex h-full w-full max-w-xl flex-col border-l border-slate-200 bg-white shadow-xl transition-all dark:border-slate-800 dark:bg-slate-900",children:[e.jsxs("header",{className:"flex items-center justify-between border-b border-slate-200 px-6 py-4 dark:border-slate-800",children:[e.jsxs("div",{children:[e.jsx("h2",{id:"log-detail-title",className:"text-lg font-semibold",children:s("logs.detail.title")}),a?e.jsx("p",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.id",{id:a.id})}):null]}),e.jsx("button",{type:"button",ref:u,onClick:n,className:"rounded-md border border-slate-200 px-3 py-1 text-sm transition hover:bg-slate-100 dark:border-slate-700 dark:hover:bg-slate-800",children:s("common.actions.close")})]}),e.jsx("div",{id:"log-detail-content",className:"flex-1 overflow-y-auto",children:h.isPending?e.jsx(we,{}):a?e.jsxs("div",{className:"flex flex-col gap-6 px-6 py-5 text-sm",children:[e.jsxs("section",{className:"space-y-2",children:[e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wide text-slate-500 dark:text-slate-400",children:s("logs.detail.infoSection")}),e.jsxs("div",{className:"flex flex-wrap items-center gap-3 rounded-md bg-slate-100 px-3 py-2 text-xs text-slate-600 dark:bg-slate-800/60 dark:text-slate-300",children:[e.jsx("span",{className:"text-sm font-medium text-slate-700 dark:text-slate-100",children:s("logs.detail.summary.route",{from:a.client_model??s("logs.detail.info.noRequestedModel"),to:a.model})}),e.jsx("span",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.summary.latency",{value:v(a.latency_ms,s("common.units.ms"))})}),a.ttft_ms!==null?e.jsx("span",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.summary.ttft",{value:v(a.ttft_ms,s("common.units.ms"))})}):null,a.tpot_ms!==null?e.jsx("span",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.summary.tpot",{value:v(a.tpot_ms,s("common.units.msPerToken"))})}):null,e.jsx("span",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.summary.stream",{value:re(a.stream)})}),e.jsxs(de,{variant:a.error?"error":"success",children:[(a.status_code??(a.error?500:200)).toString(),e.jsx("span",{children:a.error?s("common.status.error"):s("common.status.success")})]})]}),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-slate-500 dark:text-slate-400",children:s("logs.detail.info.time")}),e.jsx("dd",{className:"font-medium",children:ne(a.timestamp)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.info.sessionId")}),e.jsx("dd",{className:"font-medium",children:a.session_id??"-"})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.info.endpoint")}),e.jsx("dd",{className:"font-medium",children:a.endpoint||"-"}),e.jsx("dt",{className:"mt-2 text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.info.provider")}),e.jsx("dd",{className:"font-medium",children:d})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.info.requestedModel")}),e.jsx("dd",{className:"font-medium",children:a.client_model??s("logs.detail.info.noRequestedModel")})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.info.model")}),e.jsx("dd",{className:"font-medium",children:a.model})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.info.stream")}),e.jsx("dd",{className:"font-medium",children:re(a.stream)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.info.inputTokens")}),e.jsx("dd",{className:"font-medium",children:_(a.input_tokens)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.info.cachedTokens")}),e.jsx("dd",{className:"font-medium",children:_(a.cached_tokens)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.info.outputTokens")}),e.jsx("dd",{className:"font-medium",children:_(a.output_tokens)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.info.ttft")}),e.jsx("dd",{className:"font-medium",children:v(a.ttft_ms,s("common.units.ms"))})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.info.tpot")}),e.jsx("dd",{className:"font-medium",children:v(a.tpot_ms,s("common.units.msPerToken"))})]})]}),a.error?e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.info.error")}),e.jsx("p",{className:"rounded-md border border-red-200 bg-red-50 p-3 text-xs leading-5 text-red-700 dark:border-red-800/70 dark:bg-red-900/40 dark:text-red-200",children:a.error})]}):null]}),e.jsxs("section",{className:"space-y-2",children:[e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wide text-slate-500 dark:text-slate-400",children:s("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-slate-500 dark:text-slate-400",children:s("logs.detail.apiKey.name")}),e.jsx("dd",{className:"font-medium",children:a.api_key_id==null&&!a.api_key_name?s("logs.detail.apiKey.missing"):o!=null&&o.isWildcard?s("apiKeys.wildcard"):(o==null?void 0:o.name)??a.api_key_name??s("logs.detail.apiKey.missing")})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.apiKey.identifier")}),e.jsx("dd",{className:"font-medium",children:a.api_key_id??s("common.noData")})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.apiKey.masked")}),e.jsx("dd",{className:"font-medium",children:o!=null&&o.isWildcard?s("apiKeys.wildcard"):(o==null?void 0:o.maskedKey)??a.api_key_name??s("logs.detail.apiKey.maskedUnavailable")})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.apiKey.lastUsed")}),e.jsx("dd",{className:"font-medium",children:o!=null&&o.lastUsedAt?new Date(o.lastUsedAt).toLocaleString():s("common.noData")})]})]}),e.jsxs("div",{className:"rounded-md border border-slate-200 bg-slate-50 px-3 py-3 text-xs text-slate-600 dark:border-slate-800 dark:bg-slate-800/60 dark:text-slate-300",children:[e.jsx("p",{className:"font-medium text-slate-700 dark:text-slate-200",children:s("logs.detail.apiKey.rawMasked")}),e.jsx("p",{className:"mt-1 break-all text-xs font-mono",children:a.api_key_value_available?a.api_key_value_masked??s("logs.detail.apiKey.rawUnavailable"):s("logs.detail.apiKey.rawUnavailable")}),e.jsx("p",{className:"mt-2 text-[11px] leading-relaxed text-slate-500 dark:text-slate-400",children:s("logs.detail.apiKey.rawMaskedHint")})]})]}),e.jsxs("section",{className:"space-y-2",children:[e.jsxs("header",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wide text-slate-500 dark:text-slate-400",children:s("logs.detail.payload.request")}),e.jsx("button",{type:"button",onClick:()=>{var m;return g(s("logs.detail.payload.request"),(m=a.payload)==null?void 0:m.prompt,"logs.detail.copy.requestSuccess")},className:"rounded-md border border-slate-200 px-2 py-1 text-xs transition hover:bg-slate-100 dark:border-slate-700 dark:hover:bg-slate-800",children:s("common.actions.copy")})]}),e.jsx("pre",{className:"max-h-64 overflow-auto whitespace-pre-wrap rounded-md border border-slate-200 bg-slate-50 p-3 text-xs leading-5 text-slate-700 dark:border-slate-800 dark:bg-slate-900/80 dark:text-slate-200",children:ie((x=a.payload)==null?void 0:x.prompt,s("logs.detail.payload.emptyRequest"))})]}),e.jsxs("section",{className:"space-y-2",children:[e.jsxs("header",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wide text-slate-500 dark:text-slate-400",children:s("logs.detail.payload.response")}),e.jsx("button",{type:"button",onClick:()=>{var m;return g(s("logs.detail.payload.response"),(m=a.payload)==null?void 0:m.response,"logs.detail.copy.responseSuccess")},className:"rounded-md border border-slate-200 px-2 py-1 text-xs transition hover:bg-slate-100 dark:border-slate-700 dark:hover:bg-slate-800",children:s("common.actions.copy")})]}),e.jsx("pre",{className:"max-h-64 overflow-auto whitespace-pre-wrap rounded-md border border-slate-200 bg-slate-50 p-3 text-xs leading-5 text-slate-700 dark:border-slate-800 dark:bg-slate-900/80 dark:text-slate-200",children:ie((w=a.payload)==null?void 0:w.response,s("logs.detail.payload.emptyResponse"))})]})]}):e.jsx("div",{className:"flex h-full items-center justify.center p-8 text-sm text-slate-500 dark:text-slate-400",children:s("logs.detail.loadError")})})]})]}),document.body)}function Ce({apiKeys:t,selected:r,onChange:n,disabled:b,className:j}){const{t:s}=M(),[c,N]=i.useState(!1),u=i.useRef(null);i.useEffect(()=>{if(!c)return;const d=o=>{var x;(x=u.current)!=null&&x.contains(o.target)||N(!1)};return window.addEventListener("mousedown",d),()=>window.removeEventListener("mousedown",d)},[c]);const h=i.useMemo(()=>{if(r.length===0)return[];const d=new Map;for(const o of t)d.set(o.id,o);return r.map(o=>{const x=d.get(o);return x?x.isWildcard?s("apiKeys.wildcard"):x.name:null}).filter(o=>!!o)},[t,r,s]),g=r.length===0?s("logs.filters.apiKeyAll"):s("logs.filters.apiKeySelected",{count:r.length}),a=d=>{r.includes(d)?n(r.filter(o=>o!==d)):n([...r,d])};return e.jsxs("div",{className:y("relative flex flex-col gap-2",j),ref:u,children:[e.jsx("label",{className:"text-xs font-semibold uppercase tracking-wide text-slate-500 dark:text-slate-400",children:s("logs.filters.apiKey")}),e.jsxs("button",{type:"button",onClick:()=>N(d=>!d),disabled:b||t.length===0,title:s("logs.filters.apiKeyHint"),className:y("flex h-10 w-full items-center justify-between rounded-xl border border-slate-200/70 bg-white/90 px-3 text-sm font-medium text-slate-600 shadow-sm shadow-slate-200/60 transition focus:outline-none focus:ring-2 focus:ring-blue-400/30 disabled:cursor-not-allowed disabled:opacity-50 dark:border-slate-700/60 dark:bg-slate-900/80 dark:text-slate-200",r.length>0?"border-blue-400 text-blue-700 dark:border-blue-400 dark:text-blue-200":"",c?"ring-2 ring-blue-400/30":""),"aria-haspopup":"listbox","aria-expanded":c,children:[e.jsxs("span",{className:"truncate",children:[g,h.length>0&&e.jsx("span",{className:"ml-1 text-xs text-slate-500 dark:text-slate-400",children:h.join(", ")})]}),e.jsx("svg",{className:y("h-4 w-4 text-slate-400 transition-all dark:text-slate-300",c?"rotate-180":""),viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true",children:e.jsx("path",{fillRule:"evenodd",d:"M5.23 7.21a.75.75 0 011.06.02L10 10.94l3.71-3.71a.75.75 0 111.06 1.06l-4.24 4.25a.75.75 0 01-1.06 0L5.21 8.29a.75.75 0 01.02-1.08z",clipRule:"evenodd"})})]}),c&&e.jsxs("div",{className:"absolute left-0 top-full z-30 mt-2 w-64 rounded-2xl border border-slate-200/70 bg-white p-2 shadow-lg shadow-slate-200/70 dark:border-slate-700/60 dark:bg-slate-900",children:[e.jsxs("div",{className:"flex items-center justify-between rounded-xl border border-slate-200/60 bg-slate-50/70 px-3 py-2 text-xs font-medium text-slate-500 dark:border-slate-700/50 dark:bg-slate-800/60 dark:text-slate-300",children:[e.jsx("span",{children:g}),e.jsx("button",{type:"button",onClick:()=>n([]),disabled:r.length===0,className:"text-blue-600 hover:underline disabled:opacity-40 dark:text-blue-400",children:s("common.actions.reset")})]}),e.jsxs("div",{className:"max-h-56 overflow-y-auto px-1 py-2",children:[t.map(d=>{const o=d.isWildcard?s("apiKeys.wildcard"):d.name,x=r.includes(d.id);return e.jsxs("label",{className:y("flex cursor-pointer items-center gap-2 rounded-xl px-3 py-2 text-sm transition hover:bg-slate-100 dark:hover:bg-slate-800",x?"bg-blue-50/70 text-blue-600 dark:bg-blue-900/30 dark:text-blue-200":"text-slate-600 dark:text-slate-200"),children:[e.jsx("input",{type:"checkbox",className:"h-4 w-4 rounded border-slate-300 text-blue-600 focus:ring-blue-400 dark:border-slate-600",checked:x,onChange:()=>a(d.id)}),e.jsx("span",{className:"truncate",children:o})]},d.id)}),t.length===0&&e.jsx("p",{className:"px-2 py-2 text-xs text-slate-500 dark:text-slate-400",children:s("logs.filters.apiKeyAll")})]})]})]})}export{Ke as default};