@kaitranntt/ccs 7.77.1-dev.8 → 7.77.1-dev.9
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/dist/cliproxy/ai-providers/codex-plan-compatibility.d.ts.map +1 -1
- package/dist/cliproxy/ai-providers/codex-plan-compatibility.js +2 -2
- package/dist/cliproxy/ai-providers/codex-plan-compatibility.js.map +1 -1
- package/dist/cliproxy/ai-providers/codex-reasoning-proxy.d.ts +8 -2
- package/dist/cliproxy/ai-providers/codex-reasoning-proxy.d.ts.map +1 -1
- package/dist/cliproxy/ai-providers/codex-reasoning-proxy.js +82 -33
- package/dist/cliproxy/ai-providers/codex-reasoning-proxy.js.map +1 -1
- package/dist/cliproxy/ai-providers/model-id-normalizer.d.ts +1 -1
- package/dist/cliproxy/ai-providers/model-id-normalizer.d.ts.map +1 -1
- package/dist/cliproxy/ai-providers/model-id-normalizer.js +28 -11
- package/dist/cliproxy/ai-providers/model-id-normalizer.js.map +1 -1
- package/dist/cliproxy/config/thinking-config.d.ts.map +1 -1
- package/dist/cliproxy/config/thinking-config.js +9 -8
- package/dist/cliproxy/config/thinking-config.js.map +1 -1
- package/dist/cliproxy/model-catalog.d.ts +2 -0
- package/dist/cliproxy/model-catalog.d.ts.map +1 -1
- package/dist/cliproxy/model-catalog.js +2 -0
- package/dist/cliproxy/model-catalog.js.map +1 -1
- package/dist/commands/cliproxy/variant-subcommand.d.ts.map +1 -1
- package/dist/commands/cliproxy/variant-subcommand.js +44 -12
- package/dist/commands/cliproxy/variant-subcommand.js.map +1 -1
- package/dist/ui/assets/{accounts-lNkLHFUi.js → accounts-DkID6f81.js} +1 -1
- package/dist/ui/assets/{alert-dialog-BOlM9Aos.js → alert-dialog-BM9gIsRp.js} +1 -1
- package/dist/ui/assets/{api-BWy6e4S8.js → api-0YJdilQb.js} +1 -1
- package/dist/ui/assets/{auth-section-DAnXkqYR.js → auth-section-C1ljCo7W.js} +1 -1
- package/dist/ui/assets/{backups-section-D7XUs1JS.js → backups-section-C-iLf1kg.js} +1 -1
- package/dist/ui/assets/{channels-BKV3tSfv.js → channels-DDSqllsQ.js} +1 -1
- package/dist/ui/assets/{checkbox-D1-_INjR.js → checkbox-5R1YTubE.js} +1 -1
- package/dist/ui/assets/{claude-extension-BwjQl7ol.js → claude-extension-CEGefl3-.js} +1 -1
- package/dist/ui/assets/cliproxy-R4kPUeL-.js +3 -0
- package/dist/ui/assets/{cliproxy-ai-providers-DQMqXzRz.js → cliproxy-ai-providers-DVF3FnXM.js} +1 -1
- package/dist/ui/assets/{cliproxy-control-panel-CH75qKU4.js → cliproxy-control-panel-CIsKyGK6.js} +1 -1
- package/dist/ui/assets/{codex-ClRFRCla.js → codex-BiEEUC4Y.js} +1 -1
- package/dist/ui/assets/{confirm-dialog-DXJ0kUrp.js → confirm-dialog-BhJV4F_d.js} +1 -1
- package/dist/ui/assets/{copilot-CMc1hybe.js → copilot-DgRLuQfV.js} +1 -1
- package/dist/ui/assets/{cursor-CXlPaY62.js → cursor-BuOjfajj.js} +1 -1
- package/dist/ui/assets/{droid-D0o0ta28.js → droid-BPiviAW2.js} +1 -1
- package/dist/ui/assets/{globalenv-section-Crb3uFp7.js → globalenv-section-DAqbiNI1.js} +1 -1
- package/dist/ui/assets/{health-CD_qC6wG.js → health-B_CfF7J0.js} +1 -1
- package/dist/ui/assets/{index-CL6vCSY9.js → index-BEGD-4HR.js} +1 -1
- package/dist/ui/assets/{index-HwlgKSWH.js → index-BJl0cazY.js} +2 -2
- package/dist/ui/assets/{index-Dhaeoa8x.js → index-Bc-AbZRU.js} +1 -1
- package/dist/ui/assets/{index-Co9qZEzY.js → index-BqR6NZDE.js} +1 -1
- package/dist/ui/assets/{index-CvFZqcdh.js → index-Cj4mWFVK.js} +1 -1
- package/dist/ui/assets/{index-4oChbCyf.js → index-CzKdWNe5.js} +1 -1
- package/dist/ui/assets/{index-Dk0xIiPX.js → index-LJitUhfE.js} +1 -1
- package/dist/ui/assets/{logs-BnlWbg68.js → logs-Lqv-I3_T.js} +1 -1
- package/dist/ui/assets/{masked-input-CslqD0_2.js → masked-input-CgCDYXYf.js} +1 -1
- package/dist/ui/assets/{proxy-status-widget-YonTNEFL.js → proxy-status-widget-Df-4cfdm.js} +1 -1
- package/dist/ui/assets/{raw-json-settings-editor-panel-5LcbOkxh.js → raw-json-settings-editor-panel-BpXdUisD.js} +1 -1
- package/dist/ui/assets/{searchable-select-DgyFlHas.js → searchable-select-DCOfw3f0.js} +1 -1
- package/dist/ui/assets/{separator-cIuCN-Pq.js → separator-Ct6a34bG.js} +1 -1
- package/dist/ui/assets/{shared-CbYgYS7o.js → shared-D-JFc_Cw.js} +1 -1
- package/dist/ui/assets/{table-CtOCg1DT.js → table-DsU2UX-e.js} +1 -1
- package/dist/ui/assets/{updates-K_8t_A_F.js → updates-D-0gOqSU.js} +1 -1
- package/dist/ui/index.html +1 -1
- package/package.json +1 -1
- package/dist/ui/assets/cliproxy-Dq9zVZRT.js +0 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as e}from"./radix-ui-nu4wz29m.js";import{r as g,E as ge}from"./react-vendor-Bjx91N7w.js";import{u as U,a as $,C as j,b as y,S as f,c as x,P as v,B as K,d as z,e as se,f as je,g as te,h as ye,i as ae,j as w,k as L,l as Ne,m as we,n as be,o as ve}from"./index-HwlgKSWH.js";import{a3 as ke,am as ne,an as Q,ao as re,a1 as le,aa as Ce,G as Se,ap as De,R as Te,$ as V,U as Le,Z as ie,v as $e,ae as H,aq as Fe,Y as Re,C as Me,ar as Pe,as as Be}from"./icons-DIVjDO-z.js";import{a as Ae,u as O}from"./tanstack-bhJxV1h8.js";import{K as P,L as oe,f as S,H as Ue}from"./utils-CzKF5WmX.js";import{R as ce,A as Oe,C as Ie,X as qe,Y as Z,T as de,a as X,P as Ke,b as Ee,c as _e}from"./charts-CeK2xCSo.js";import"./notifications-B4_o8bcr.js";import"./form-utils-CuHzLhJZ.js";import"./code-highlight-D4E79GKQ.js";function Ge({data:s,isLoading:t}){const{privacyMode:a}=U(),{t:n}=$(),o=s?.totalTokens??0,r=s?.totalInputTokens??0,i=s?.totalOutputTokens??0,d=s?.totalCacheTokens??0,l=r+i;if(t)return e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-5 gap-4",children:[1,2,3,4,5].map(m=>e.jsx(j,{children:e.jsx(y,{className:"p-6",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(f,{className:"h-4 w-[100px]"}),e.jsx(f,{className:"h-8 w-[80px]"})]}),e.jsx(f,{className:"h-8 w-8 rounded-lg"})]})})},m))});const c=(s?.tokenBreakdown?.cacheCreation?.cost??0)+(s?.tokenBreakdown?.cacheRead?.cost??0),h=s?.totalCost?Math.round(c/s.totalCost*100):0,u=d>0&&o>l,p=d>0&&!u?"Total Tokens (I/O)":n("analyticsSummary.totalTokens"),D=u?`${T(r)} in / ${T(i)} out / ${T(d)} cache`:n("analyticsSummary.totalTokensSubtitle",{input:T(r),output:T(i)}),k=[{title:p,value:o,icon:ke,format:m=>T(m),color:"text-blue-600",bgColor:"bg-blue-100 dark:bg-blue-900/20",subtitle:D},{title:n("analyticsSummary.totalCost"),value:s?.totalCost??0,icon:ne,format:m=>`$${m.toFixed(2)}`,color:"text-green-600",bgColor:"bg-green-100 dark:bg-green-900/20",subtitle:n("analyticsSummary.totalCostSubtitle",{value:s?.averageCostPerDay?.toFixed(2)??"0.00"})},{title:n("analyticsSummary.cacheTokens"),value:s?.totalCacheTokens??0,icon:Q,format:m=>T(m),color:"text-cyan-600",bgColor:"bg-cyan-100 dark:bg-cyan-900/20",subtitle:n("analyticsSummary.cacheTokensSubtitle",{cost:c.toFixed(2),percent:h})},{title:n("analyticsSummary.inputCost"),value:s?.tokenBreakdown?.input?.cost??0,icon:re,format:m=>`$${m.toFixed(2)}`,color:"text-purple-600",bgColor:"bg-purple-100 dark:bg-purple-900/20",subtitle:n("analyticsSummary.tokensSubtitle",{value:T(s?.tokenBreakdown?.input?.tokens??0)})},{title:n("analyticsSummary.outputCost"),value:s?.tokenBreakdown?.output?.cost??0,icon:le,format:m=>`$${m.toFixed(2)}`,color:"text-orange-600",bgColor:"bg-orange-100 dark:bg-orange-900/20",subtitle:n("analyticsSummary.tokensSubtitle",{value:T(s?.tokenBreakdown?.output?.tokens??0)})}];return e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-5 gap-4",children:k.map((m,b)=>{const C=m.icon;return e.jsx(j,{className:"hover:shadow-md transition-shadow",children:e.jsx(y,{className:"p-4",children:e.jsxs("div",{className:"flex items-center justify-between space-x-2",children:[e.jsxs("div",{className:"space-y-1 min-w-0",children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground truncate",children:m.title}),e.jsx("p",{className:x("text-xl font-bold truncate",a&&v),children:m.format(m.value)}),m.subtitle&&e.jsx("p",{className:x("text-[10px] text-muted-foreground truncate",a&&v),children:m.subtitle})]}),e.jsx("div",{className:x("p-2 rounded-lg shrink-0",m.bgColor),children:e.jsx(C,{className:x("h-4 w-4",m.color)})})]})})},b)})})}function T(s){return s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toLocaleString()}function He({model:s}){const{privacyMode:t}=U(),{t:a}=$(),n=We(s.ioRatio),r=s.cacheCreationTokens+s.cacheReadTokens>0?"All Tokens":a("analyticsCards.totalTokens");return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ce,{className:"h-4 w-4 text-primary shrink-0"}),e.jsx("h4",{className:"font-semibold leading-none truncate",title:s.model,children:s.model})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs(K,{variant:"secondary",className:"text-[10px] h-5 px-1.5",children:[s.percentage.toFixed(1),"% usage"]}),e.jsxs(K,{variant:n.variant,className:"text-[10px] h-5 px-1.5",children:[s.ioRatio.toFixed(0),":1 I/O"]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("div",{className:"p-2 rounded-md bg-muted/50 border text-center",children:[e.jsxs("p",{className:x("text-lg font-bold",t&&v),children:["$",s.cost.toFixed(2)]}),e.jsx("p",{className:"text-[10px] text-muted-foreground uppercase tracking-wider",children:a("analyticsCards.totalCost")})]}),e.jsxs("div",{className:"p-2 rounded-md bg-muted/50 border text-center",children:[e.jsx("p",{className:x("text-lg font-bold",t&&v),children:Ye(s.tokens)}),e.jsx("p",{className:"text-[10px] text-muted-foreground uppercase tracking-wider",children:r})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h5",{className:"text-[11px] font-medium text-muted-foreground uppercase tracking-wider",children:"Token Breakdown"}),e.jsxs("div",{className:x("space-y-1",t&&v),children:[e.jsx(W,{label:"Input",tokens:s.inputTokens,cost:s.costBreakdown.input.cost,color:"#335c67",icon:re}),e.jsx(W,{label:"Output",tokens:s.outputTokens,cost:s.costBreakdown.output.cost,color:"#fff3b0",icon:le}),e.jsx(W,{label:"Cache Write",tokens:s.cacheCreationTokens,cost:s.costBreakdown.cacheCreation.cost,color:"#e09f3e",icon:Q}),e.jsx(W,{label:"Cache Read",tokens:s.cacheReadTokens,cost:s.costBreakdown.cacheRead.cost,color:"#9e2a2b",icon:Q})]})]}),e.jsxs("div",{className:"p-2.5 rounded-md border bg-muted/20 space-y-1.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Se,{className:"h-3.5 w-3.5 text-muted-foreground"}),e.jsx("span",{className:"text-xs font-medium",children:a("analyticsCards.inputOutputRatio")})]}),e.jsx("p",{className:"text-[11px] text-muted-foreground leading-snug",children:n.description})]})]})}function W({label:s,tokens:t,cost:a,color:n,icon:o}){return t===0?null:e.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[e.jsx("div",{className:"w-1 h-6 rounded-full shrink-0",style:{backgroundColor:n}}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"font-medium truncate",children:s}),e.jsxs("span",{className:"font-mono text-muted-foreground",children:["$",a.toFixed(3)]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 text-muted-foreground",children:[e.jsx(o,{className:"h-3 w-3 shrink-0"}),e.jsx("span",{children:ze(t)})]})]})]})}function We(s){return s>=200?{variant:"destructive",description:"Extended thinking or large context loading. Expected for reasoning models."}:s>=50?{variant:"secondary",description:"More input than output. Typical for analysis tasks."}:s>=5?{variant:"outline",description:"Balanced input/output ratio for typical coding tasks."}:{variant:"default",description:"More output than input. Generation-heavy workload."}}function ze(s){return s.toLocaleString()}function Ye(s){return s>=1e9?`${(s/1e9).toFixed(1)}B`:s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toString()}const Qe="/api";function N(s){const t=s.getFullYear(),a=String(s.getMonth()+1).padStart(2,"0"),n=String(s.getDate()).padStart(2,"0");return`${t}${a}${n}`}function M(s,t){const a=t.toString();return a?`${s}?${a}`:s}const B={summary:s=>{const t=new URLSearchParams;return s?.startDate&&t.append("since",N(s.startDate)),s?.endDate&&t.append("until",N(s.endDate)),F(M("/usage/summary",t))},trends:s=>{const t=new URLSearchParams;return s?.startDate&&t.append("since",N(s.startDate)),s?.endDate&&t.append("until",N(s.endDate)),F(M("/usage/daily",t))},hourly:s=>{const t=new URLSearchParams;return s?.startDate&&t.append("since",N(s.startDate)),s?.endDate&&t.append("until",N(s.endDate)),F(M("/usage/hourly",t))},models:s=>{const t=new URLSearchParams;return s?.startDate&&t.append("since",N(s.startDate)),s?.endDate&&t.append("until",N(s.endDate)),F(M("/usage/models",t))},sessions:s=>{const t=new URLSearchParams;return s?.startDate&&t.append("since",N(s.startDate)),s?.endDate&&t.append("until",N(s.endDate)),s?.limit&&t.append("limit",s.limit.toString()),s?.offset&&t.append("offset",s.offset.toString()),F(M("/usage/sessions",t))},monthly:s=>{const t=new URLSearchParams;return s?.startDate&&t.append("since",N(s.startDate)),s?.endDate&&t.append("until",N(s.endDate)),F(M("/usage/monthly",t))},refresh:async()=>{if(!(await fetch(`${Qe}/usage/refresh`,{method:"POST",headers:{"Content-Type":"application/json"}})).ok)throw new Error("Failed to refresh usage cache")},status:()=>F("/usage/status"),insights:s=>{const t=new URLSearchParams;return s?.startDate&&t.append("since",N(s.startDate)),s?.endDate&&t.append("until",N(s.endDate)),F(M("/usage/insights",t))}};async function F(s){const a=await fetch(`/api${s}`,{headers:{"Content-Type":"application/json"}});if(!a.ok){const o=await a.json().catch(()=>({error:"Unknown error"}));throw new Error(o.error||a.statusText)}const n=await a.json();return n.data||n}function Ve(s){return O({queryKey:["usage","summary",s],queryFn:()=>B.summary(s),staleTime:60*1e3})}function Ze(s){return O({queryKey:["usage","trends",s],queryFn:()=>B.trends(s),staleTime:60*1e3})}function Xe(s){return O({queryKey:["usage","hourly",s],queryFn:()=>B.hourly(s),staleTime:60*1e3})}function Je(s){return O({queryKey:["usage","models",s],queryFn:()=>B.models(s),staleTime:60*1e3})}function es(){const s=Ae();return g.useCallback(async()=>{await B.refresh(),await s.invalidateQueries({queryKey:["usage"]})},[s])}function ss(){return O({queryKey:["usage","status"],queryFn:()=>B.status(),staleTime:10*1e3,refetchInterval:30*1e3})}function ts(s){return O({queryKey:["usage","sessions",s],queryFn:()=>B.sessions(s),staleTime:60*1e3})}const as=50;function ns(){const[s,t]=g.useState({from:P(new Date,30),to:new Date}),[a,n]=g.useState(!1),[o,r]=g.useState(null),[i,d]=g.useState(null),[l,c]=g.useState("daily"),h=es(),u=g.useCallback(async()=>{n(!0);try{await h()}finally{n(!1)}},[h]),p=g.useMemo(()=>({startDate:s?.from,endDate:s?.to}),[s?.from,s?.to]),{data:D,isLoading:k}=Ve(p),{data:m,isLoading:b}=Ze(p),{data:C,isLoading:I}=Xe(p),{data:R,isLoading:q}=Je(p),{data:Y,isLoading:E}=ts({...p,limit:as}),{data:_}=ss(),xe=g.useCallback(()=>{const A=new Date;t({from:P(A,1),to:A}),c("hourly")},[]),ue=g.useCallback(A=>{t(A),c("daily")},[]),me=g.useMemo(()=>_?.lastFetch?oe(new Date(_.lastFetch),{addSuffix:!0}):null,[_?.lastFetch]),he=g.useCallback((A,pe)=>{const G=pe.currentTarget.getBoundingClientRect();d({x:G.left+G.width/2,y:G.top+G.height/2}),r(A)},[]),fe=g.useCallback(()=>{r(null),d(null)},[]);return{dateRange:s,isRefreshing:a,viewMode:l,selectedModel:o,popoverPosition:i,summary:D,trends:m,hourlyData:C,models:R,sessions:Y,status:_,isSummaryLoading:k,isTrendsLoading:b,isHourlyLoading:I,isModelsLoading:q,isSessionsLoading:E,isLoading:k||b||q||E,handleRefresh:u,handleTodayClick:xe,handleDateRangeChange:ue,handleModelClick:he,handlePopoverClose:fe,lastUpdatedText:me}}function rs({value:s,onChange:t,presets:a=[{label:"Last 7 days",range:{from:P(new Date,7),to:new Date}},{label:"Last 30 days",range:{from:P(new Date,30),to:new Date}},{label:"Last 90 days",range:{from:P(new Date,90),to:new Date}}],className:n}){const[o,r]=ge.useState(!1),{t:i}=$(),d=l=>!s||!s.from||!s.to||!l.from||!l.to?!1:S(s.from,"yyyy-MM-dd")===S(l.from,"yyyy-MM-dd")&&S(s.to,"yyyy-MM-dd")===S(l.to,"yyyy-MM-dd");return e.jsxs("div",{className:x("flex flex-wrap items-center gap-2",n),children:[a.map(l=>e.jsx(z,{variant:d(l.range)?"default":"outline",size:"sm",onClick:()=>t(l.range),children:l.label},l.label)),e.jsxs(se,{open:o,onOpenChange:r,children:[e.jsx(je,{asChild:!0,children:e.jsxs(z,{id:"date",variant:"outline",className:x("w-auto min-w-[200px] sm:min-w-[240px] justify-start text-left font-normal",!s&&"text-muted-foreground"),children:[e.jsx(De,{className:"mr-2 h-4 w-4"}),s?.from?s.to?e.jsxs(e.Fragment,{children:[S(s.from,"LLL dd, y")," - ",S(s.to,"LLL dd, y")]}):S(s.from,"LLL dd, y"):e.jsx("span",{children:i("dateRangeFilter.pickADate")})]})}),e.jsx(te,{className:"w-auto p-0",align:"end",children:e.jsx(ye,{initialFocus:!0,mode:"range",defaultMonth:s?.from,selected:s,onSelect:t,numberOfMonths:2})})]})]})}function ls({dateRange:s,onDateRangeChange:t,onTodayClick:a,onRefresh:n,isRefreshing:o,lastUpdatedText:r,viewMode:i}){const{t:d}=$();return e.jsxs("div",{className:"flex flex-col gap-3 shrink-0 xl:flex-row xl:items-center xl:justify-between",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-xl font-semibold",children:d("analytics.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:d("analytics.subtitle")})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 xl:justify-end",children:[e.jsx(z,{variant:i==="hourly"?"default":"outline",size:"sm",className:"h-8",onClick:a,children:"24H"}),e.jsx(rs,{className:"flex-wrap",value:s,onChange:t,presets:[{label:"7D",range:{from:P(new Date,7),to:new Date}},{label:"30D",range:{from:P(new Date,30),to:new Date}},{label:d("analytics.month"),range:{from:Ue(new Date),to:new Date}},{label:d("analytics.allTime"),range:{from:void 0,to:new Date}}]}),r&&e.jsx("span",{className:"text-xs text-muted-foreground whitespace-nowrap",children:d("analytics.updated",{value:r})}),e.jsx(z,{variant:"outline",size:"sm",className:"gap-2 h-8",onClick:n,disabled:o,children:e.jsx(Te,{className:`w-3.5 h-3.5 ${o?"animate-spin":""}`})})]})]})}function is({data:s,isLoading:t,granularity:a="daily",className:n}){const{privacyMode:o}=U(),{t:r}=$(),i=g.useMemo(()=>!s||s.length===0?[]:s.map(c=>{const h="hour"in c?c.hour:c.date;return{...c,dateFormatted:os(h,a),costRounded:Number(c.cost.toFixed(4))}}),[s,a]);if(t)return e.jsx(f,{className:x("h-full w-full",n)});if(!s||s.length===0)return e.jsx("div",{className:x("h-full flex items-center justify-center",n),children:e.jsx("p",{className:"text-muted-foreground",children:r(a==="hourly"?"analytics.noDailyUsage":"analytics.noUsageData")})});const d=({x:l,y:c,payload:h,isRight:u})=>{const p=u?`$${h.value}`:J(Number(h.value));return e.jsx("text",{x:l,y:c,dy:4,textAnchor:u?"start":"end",fontSize:12,fill:"currentColor",className:x("fill-muted-foreground",o&&"blur-[4px]"),children:p})};return e.jsx("div",{className:x("w-full h-full",n),children:e.jsx(ce,{width:"100%",height:"100%",children:e.jsxs(Oe,{data:i,margin:{top:5,right:30,left:20,bottom:5},children:[e.jsxs("defs",{children:[e.jsxs("linearGradient",{id:"tokenGradient",x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"5%",stopColor:"#0080FF",stopOpacity:.8}),e.jsx("stop",{offset:"95%",stopColor:"#0080FF",stopOpacity:.1})]}),e.jsxs("linearGradient",{id:"costGradient",x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"5%",stopColor:"#00C49F",stopOpacity:.8}),e.jsx("stop",{offset:"95%",stopColor:"#00C49F",stopOpacity:.1})]})]}),e.jsx(Ie,{strokeDasharray:"3 3",className:"stroke-muted"}),e.jsx(qe,{dataKey:"dateFormatted",tick:{fontSize:12},tickLine:!1,axisLine:{className:"stroke-muted"}}),e.jsx(Z,{yAxisId:"left",orientation:"left",tick:l=>e.jsx(d,{...l,isRight:!1}),tickLine:!1,axisLine:{className:"stroke-muted"}}),e.jsx(Z,{yAxisId:"right",orientation:"right",tick:l=>e.jsx(d,{...l,isRight:!0}),tickLine:!1,axisLine:{className:"stroke-muted"}}),e.jsx(de,{content:({active:l,payload:c,label:h})=>!l||!c||!c.length?null:e.jsxs("div",{className:"rounded-lg border bg-background p-3 shadow-lg",children:[e.jsx("p",{className:"font-medium mb-2",children:h}),c.map((u,p)=>e.jsxs("p",{className:x("text-sm",o&&v),style:{color:u.color},children:[u.name,":"," ",u.name==="Tokens"?J(Number(u.value)||0):`$${u.value}`]},p))]})}),e.jsx(X,{yAxisId:"left",type:"monotone",dataKey:"tokens",stroke:"#0080FF",strokeWidth:2,fillOpacity:1,fill:"url(#tokenGradient)",name:"Tokens"}),e.jsx(X,{yAxisId:"right",type:"monotone",dataKey:"costRounded",stroke:"#00C49F",strokeWidth:2,fillOpacity:1,fill:"url(#costGradient)",name:"Cost"})]})})})}function os(s,t){if(t==="hourly"){const[n,o]=s.split(" ");if(n&&o){const r=new Date(`${n}T${o}:00Z`);return S(r,"HH:mm")}return s}const a=new Date(s);return t==="monthly"?S(a,"MMM yyyy"):S(a,"MMM dd")}function J(s){return s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toLocaleString()}function cs({data:s,isLoading:t,className:a}){const{privacyMode:n}=U(),{t:o}=$(),r=g.useMemo(()=>!s||s.length===0?[]:s.map(l=>({name:l.model,value:l.tokens,cost:l.cost,percentage:l.percentage,fill:ae(l.model)})),[s]);if(t)return e.jsx(f,{className:x("h-full min-h-[100px] w-full",a)});if(!s||s.length===0)return e.jsx("div",{className:x("h-full min-h-[100px] flex items-center justify-center",a),children:e.jsx("p",{className:"text-muted-foreground",children:o("analyticsCards.noModelData")})});const i=({active:l,payload:c})=>{if(!l||!c)return null;const h=c;if(!h.length)return null;const u=h[0].payload;return e.jsxs("div",{className:"rounded-lg border bg-background p-2 shadow-lg text-xs",children:[e.jsx("p",{className:"font-medium mb-1",children:u.name}),e.jsxs("p",{className:x("text-muted-foreground",n&&v),children:[ds(u.value)," (",u.percentage.toFixed(1),"%)"]}),e.jsxs("p",{className:x("text-muted-foreground",n&&v),children:["$",u.cost.toFixed(4)]})]})},d=l=>l.percentage>5?`${l.percentage.toFixed(1)}%`:"";return e.jsx("div",{className:x("w-full h-full min-h-[100px]",a),children:e.jsx(ce,{width:"100%",height:"100%",children:e.jsxs(Ke,{children:[e.jsx(Ee,{data:r,cx:"50%",cy:"50%",labelLine:!1,label:d,innerRadius:50,outerRadius:70,paddingAngle:2,dataKey:"value",children:r.map((l,c)=>e.jsx(_e,{fill:l.fill,strokeWidth:1},`cell-${c}`))}),e.jsx(de,{content:i})]})})})}function ds(s){return s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toLocaleString()}function xs(s){if(!s)return"";const a=s.replace(/^\/|\/$/g,"").split("/").filter(n=>n.length>0);return a[a.length-1]||""}function us({data:s,isLoading:t,className:a}){const{privacyMode:n}=U(),{t:o}=$(),r=g.useMemo(()=>{if(!s?.sessions||s.sessions.length===0)return null;const i=s.sessions,d=s.total,l=i.length,c=s.hasMore||s.offset>0,u=i.reduce((p,D)=>p+D.cost,0)/i.length;return{displayedSessions:c?l:d,totalSessions:d,avgCost:u,hasPartialSample:c,recentSessions:i.slice(0,3)}},[s]);return t?e.jsxs(j,{className:x("flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0",a),children:[e.jsx(w,{className:"px-3 py-2",children:e.jsx(f,{className:"h-5 w-32"})}),e.jsx(y,{className:"px-3 pb-3 pt-0 flex-1",children:e.jsx(f,{className:"h-full w-full"})})]}):r?e.jsxs(j,{className:x("flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0 shadow-sm",a),children:[e.jsx(w,{className:"px-3 py-2",children:e.jsxs(L,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(V,{className:"w-4 h-4"}),"Session Stats"]})}),e.jsxs(y,{className:"px-3 pb-3 pt-0 flex-1 min-h-0 flex flex-col gap-3",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("div",{className:"p-2 rounded-md bg-muted/50 border text-center",children:[e.jsxs("div",{className:"flex items-center justify-center gap-1.5 text-blue-600 dark:text-blue-400",children:[e.jsx(Le,{className:"w-4 h-4"}),e.jsx("span",{className:"text-xl font-bold",children:r.displayedSessions})]}),e.jsx("p",{className:"text-[10px] text-muted-foreground uppercase tracking-wider mt-0.5",children:r.hasPartialSample?"Sampled Sessions":"Total Sessions"}),r.hasPartialSample&&e.jsxs("p",{className:"text-[10px] text-muted-foreground mt-0.5",children:[r.totalSessions," total"]})]}),e.jsxs("div",{className:"p-2 rounded-md bg-muted/50 border text-center",children:[e.jsxs("div",{className:"flex items-center justify-center gap-1.5 text-green-600 dark:text-green-400",children:[e.jsx(ie,{className:"w-4 h-4"}),e.jsxs("span",{className:x("text-xl font-bold",n&&v),children:["$",r.avgCost.toFixed(2)]})]}),e.jsx("p",{className:"text-[10px] text-muted-foreground uppercase tracking-wider mt-0.5",children:r.hasPartialSample?"Recent Avg Cost":"Avg Cost/Session"})]})]}),e.jsxs("div",{className:"flex-1 min-h-0 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-1 text-xs text-muted-foreground font-medium mb-1",children:[e.jsx($e,{className:"w-3 h-3"}),"Recent Activity"]}),e.jsx("div",{className:"space-y-1.5 max-h-full overflow-y-auto pr-1",children:r.recentSessions.map(i=>e.jsxs("div",{className:"flex items-center justify-between text-xs p-1.5 rounded bg-muted/30 hover:bg-muted/50 transition-colors",children:[e.jsxs("div",{className:"flex flex-col min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"font-medium truncate",title:i.projectPath,children:xs(i.projectPath)}),(i.target??"claude")!=="claude"&&e.jsx("span",{className:"shrink-0 px-1 py-0 text-[9px] font-medium rounded bg-purple-100 text-purple-700 dark:bg-purple-900/30 dark:text-purple-300 uppercase",children:i.target})]}),e.jsx("span",{className:"text-[10px] text-muted-foreground",children:oe(new Date(i.lastActivity),{addSuffix:!0})})]}),e.jsxs("div",{className:x("text-right shrink-0 ml-2",n&&v),children:[e.jsxs("div",{className:"font-mono",children:["$",i.cost.toFixed(2)]}),e.jsxs("div",{className:"text-[10px] text-muted-foreground",children:[ms(i.tokens??i.inputTokens+i.outputTokens)," ","toks"]})]})]},i.sessionId))})]})]})]}):e.jsxs(j,{className:x("flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0",a),children:[e.jsx(w,{className:"px-3 py-2",children:e.jsxs(L,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(V,{className:"w-4 h-4"}),"Session Stats"]})}),e.jsx(y,{className:"px-3 pb-3 pt-0 flex-1 flex items-center justify-center",children:e.jsx("p",{className:"text-sm text-muted-foreground text-center",children:o("analyticsCards.noSessionData")})})]})}function ms(s){return s>=1e9?`${(s/1e9).toFixed(1)}B`:s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toString()}function hs({className:s,isLoading:t}){const{data:a,isLoading:n}=Ne(),{data:o,isLoading:r,error:i}=we(a?.running),{t:d}=$();if(t||n||a?.running&&r)return e.jsxs(j,{className:x("flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0",s),children:[e.jsx(w,{className:"px-3 py-2",children:e.jsxs(L,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(H,{className:"h-4 w-4"}),"CLIProxy Stats"]})}),e.jsx(y,{className:"px-3 pb-3 pt-0 flex-1",children:e.jsxs("div",{className:"space-y-3",children:[e.jsx(f,{className:"h-4 w-[100px]"}),e.jsx(f,{className:"h-16 w-full"})]})})]});if(!a?.running)return e.jsxs(j,{className:x("flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0 border-dashed",s),children:[e.jsx(w,{className:"px-3 py-2",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(L,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(H,{className:"h-4 w-4 text-muted-foreground"}),"CLIProxy Stats"]}),e.jsx(K,{variant:"secondary",className:"text-[10px] h-5",children:d("cliproxyStatsOverview.offline")})]})}),e.jsx(y,{className:"px-3 pb-3 pt-0 flex-1 flex items-center justify-center",children:e.jsx("p",{className:"text-xs text-muted-foreground text-center",children:d("cliproxyStatsOverview.noActiveSessionHint")})})]});if(i)return e.jsxs(j,{className:x("flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0 border-destructive/50",s),children:[e.jsx(w,{className:"px-3 py-2",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(L,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(H,{className:"h-4 w-4"}),"CLIProxy Stats"]}),e.jsx(K,{variant:"destructive",className:"text-[10px] h-5",children:"Error"})]})}),e.jsx(y,{className:"px-3 pb-3 pt-0 flex-1",children:e.jsx("p",{className:"text-xs text-destructive",children:i.message})})]});const c=o?.totalRequests??0,h=o?.quotaExceededCount??0,u=c-h,p=c>0?Math.round(u/c*100):100,D=o?.tokens?.total??0,k=Object.entries(o?.requestsByModel??{}).sort((b,C)=>C[1]-b[1]).slice(0,4),m=k.length>0?k[0][1]:1;return e.jsxs(j,{className:x("flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0",s),children:[e.jsx(w,{className:"px-3 py-2 border-b bg-muted/5",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(L,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(H,{className:"h-4 w-4"}),"CLIProxy Stats"]}),e.jsxs(K,{variant:"outline",className:"text-[10px] h-5 text-green-600 border-green-200 bg-green-50 dark:bg-green-900/10 dark:border-green-800",children:[e.jsx(ie,{className:"h-3 w-3 mr-0.5"}),d("cliproxyStatsOverview.running")]})]})}),e.jsx(y,{className:"p-0 flex-1 min-h-0",children:e.jsx(be,{className:"h-full",children:e.jsxs("div",{className:"p-3 space-y-3",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2 p-2 rounded-lg bg-muted/30",children:[e.jsxs("div",{className:"relative",children:[e.jsxs("svg",{className:"w-10 h-10 -rotate-90",viewBox:"0 0 36 36",children:[e.jsx("circle",{cx:"18",cy:"18",r:"14",fill:"none",stroke:"currentColor",strokeWidth:"3",className:"text-muted/30"}),e.jsx("circle",{cx:"18",cy:"18",r:"14",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeDasharray:`${p*.88} 88`,strokeLinecap:"round",className:p>=90?"text-green-500":"text-amber-500"})]}),e.jsxs("span",{className:"absolute inset-0 flex items-center justify-center text-[8px] font-bold",children:[p,"%"]})]}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-lg font-bold leading-none",children:ee(c)}),e.jsx("div",{className:"text-[9px] text-muted-foreground mt-0.5",children:h>0?`${h} failed`:"All success"})]})]}),e.jsxs("div",{className:"flex items-center gap-2 p-2 rounded-lg bg-muted/30",children:[e.jsx("div",{className:"p-1.5 rounded-md bg-purple-100 dark:bg-purple-900/20",children:e.jsx(Fe,{className:"h-4 w-4 text-purple-600"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-lg font-bold leading-none",children:ee(D)}),e.jsx("div",{className:"text-[9px] text-muted-foreground mt-0.5",children:d("cliproxyStatsOverview.totalTokens")})]})]})]}),k.length>0&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] font-medium text-muted-foreground",children:[e.jsx(Re,{className:"h-3 w-3"}),d("cliproxyStatsOverview.modelsUsed")]}),e.jsx("div",{className:"space-y-1",children:k.map(([b,C])=>{const I=Math.round(C/m*100),R=fs(b);return e.jsxs("div",{className:"group",children:[e.jsxs("div",{className:"flex items-center justify-between text-[10px] mb-0.5",children:[e.jsx("span",{className:"truncate font-medium",title:b,children:R}),e.jsx("span",{className:"text-muted-foreground shrink-0 ml-2",children:C})]}),e.jsx("div",{className:"h-1 bg-muted/50 rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full bg-accent/70 rounded-full transition-all",style:{width:`${I}%`}})})]},b)})})]})]})})})]})}function ee(s){return s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toLocaleString()}function fs(s){let t=s.replace(/^gemini-claude-/,"").replace(/^gemini-/,"").replace(/^claude-/,"").replace(/^anthropic\./,"").replace(/-thinking$/," Thinking");return t=t.split(/[-_]/).map(a=>a.charAt(0).toUpperCase()+a.slice(1)).join(" "),t.length>20&&(t=t.slice(0,18)+"..."),t}function ps(s){return s>=1e9?`${(s/1e9).toFixed(1)}B`:s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(0)}K`:s.toString()}function gs({models:s,isLoading:t,onModelClick:a,privacyMode:n}){const{t:o}=$();return e.jsxs(j,{className:"flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0 shadow-sm lg:col-span-4",children:[e.jsx(w,{className:"px-3 py-2",children:e.jsxs(L,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(ne,{className:"w-4 h-4"}),o("analyticsPages.costByModel")]})}),e.jsx(y,{className:"px-2 pb-2 pt-0 flex-1 min-h-0 overflow-y-auto",children:t?e.jsx(f,{className:"h-full w-full"}):e.jsxs("div",{className:"space-y-0.5",children:[[...s||[]].sort((r,i)=>i.cost-r.cost).map(r=>e.jsxs("button",{className:"group flex items-center text-xs w-full hover:bg-muted/50 rounded px-2 py-1.5 transition-colors cursor-pointer gap-3",onClick:i=>a(r,i),title:"Click for details",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0 w-[180px] shrink-0",children:[e.jsx("div",{className:"w-2 h-2 rounded-full shrink-0",style:{backgroundColor:ae(r.model)}}),e.jsx("span",{className:"font-medium truncate group-hover:underline underline-offset-2",children:r.model})]}),e.jsx(js,{model:r}),e.jsx("span",{className:x("text-[10px] text-muted-foreground w-14 text-right shrink-0",n&&v),children:ps(r.tokens)}),e.jsxs("span",{className:x("font-mono font-medium w-16 text-right shrink-0",n&&v),children:["$",r.cost.toFixed(2)]}),e.jsx(Me,{className:"w-3 h-3 opacity-0 group-hover:opacity-50 transition-opacity shrink-0"})]},r.model)),e.jsx(ys,{})]})})]})}function js({model:s}){const t={input:"#335c67",output:"#fff3b0",cacheWrite:"#e09f3e",cacheRead:"#9e2a2b"},a=n=>s.cost>0?n/s.cost*100:0;return e.jsx("div",{className:"flex-1 flex items-center gap-1 min-w-0",children:e.jsxs("div",{className:"flex-1 h-2 bg-muted rounded-full overflow-hidden flex",children:[e.jsx("div",{className:"h-full",style:{backgroundColor:t.input,width:`${a(s.costBreakdown.input.cost)}%`},title:`Input: $${s.costBreakdown.input.cost.toFixed(2)}`}),e.jsx("div",{className:"h-full",style:{backgroundColor:t.output,width:`${a(s.costBreakdown.output.cost)}%`},title:`Output: $${s.costBreakdown.output.cost.toFixed(2)}`}),e.jsx("div",{className:"h-full",style:{backgroundColor:t.cacheWrite,width:`${a(s.costBreakdown.cacheCreation.cost)}%`},title:`Cache Write: $${s.costBreakdown.cacheCreation.cost.toFixed(2)}`}),e.jsx("div",{className:"h-full",style:{backgroundColor:t.cacheRead,width:`${a(s.costBreakdown.cacheRead.cost)}%`},title:`Cache Read: $${s.costBreakdown.cacheRead.cost.toFixed(2)}`})]})})}function ys(){const s=[{color:"#335c67",label:"Input"},{color:"#fff3b0",label:"Output",hasBorder:!0},{color:"#e09f3e",label:"Cache Write"},{color:"#9e2a2b",label:"Cache Read"}];return e.jsx("div",{className:"flex items-center gap-3 pt-2 px-2 text-[10px] text-muted-foreground border-t mt-2",children:s.map(({color:t,label:a,hasBorder:n})=>e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("div",{className:x("w-2 h-2 rounded-full",n&&"border border-muted-foreground/30"),style:{backgroundColor:t}}),a]},a))})}function Ns({viewMode:s,trends:t,hourlyData:a,models:n,sessions:o,isTrendsLoading:r,isHourlyLoading:i,isModelsLoading:d,isSessionsLoading:l,isSummaryLoading:c,onModelClick:h}){const{privacyMode:u}=U();return e.jsxs("div",{className:"min-h-0 grid gap-4 lg:grid-rows-[minmax(260px,1.2fr)_minmax(220px,0.9fr)]",children:[e.jsxs(j,{className:"flex flex-col h-full min-h-[220px] lg:min-h-[240px] overflow-hidden gap-0 py-0 shadow-sm",children:[e.jsx(w,{className:"px-3 py-2 shrink-0",children:e.jsxs(L,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(Pe,{className:"w-4 h-4"}),s==="hourly"?"Last 24 Hours":"Usage Trends"]})}),e.jsx(y,{className:"px-3 pb-3 pt-0 flex-1 min-h-0",children:e.jsx(is,{data:s==="hourly"?a||[]:t||[],isLoading:s==="hourly"?i:r,granularity:s==="hourly"?"hourly":"daily"})})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-10 gap-4 h-auto min-h-[220px] lg:h-full lg:min-h-[220px] lg:grid-rows-[minmax(0,1fr)] lg:[&>*]:min-h-0",children:[e.jsx(gs,{models:n,isLoading:d,onModelClick:h,privacyMode:u}),e.jsxs(j,{className:"flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0 shadow-sm lg:col-span-2",children:[e.jsx(w,{className:"px-3 py-2",children:e.jsxs(L,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(Be,{className:"w-4 h-4"}),"Model Usage"]})}),e.jsx(y,{className:"px-2 pb-2 pt-0 flex-1 min-h-0 flex items-center justify-center",children:e.jsx(cs,{data:n||[],isLoading:d,className:"h-full w-full"})})]}),e.jsx(us,{data:o,isLoading:l,className:"lg:col-span-2"}),e.jsx(hs,{isLoading:c,className:"lg:col-span-2"})]})]})}function Fs(){return e.jsxs("div",{className:"space-y-4 h-full overflow-hidden",children:[e.jsxs(j,{className:"flex flex-col min-h-[300px]",children:[e.jsx(w,{className:"p-4 pb-2",children:e.jsx(f,{className:"h-4 w-32"})}),e.jsx(y,{className:"p-4 pt-0 flex-1",children:e.jsx(f,{className:"h-full w-full"})})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-4",children:[e.jsxs(j,{className:"flex flex-col min-h-[250px]",children:[e.jsx(w,{className:"p-4 pb-2",children:e.jsx(f,{className:"h-4 w-28"})}),e.jsx(y,{className:"p-4 pt-2",children:e.jsx("div",{className:"space-y-3",children:[1,2,3,4,5].map(s=>e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(f,{className:"w-2.5 h-2.5 rounded-full"}),e.jsx(f,{className:"h-3 w-24"})]}),e.jsx(f,{className:"h-3 w-16"})]},s))})})]}),e.jsxs(j,{className:"flex flex-col min-h-[250px]",children:[e.jsx(w,{className:"p-4 pb-2",children:e.jsx(f,{className:"h-4 w-28"})}),e.jsx(y,{className:"p-4 pt-0 flex-1",children:e.jsxs("div",{className:"flex w-full h-full items-center",children:[e.jsx("div",{className:"flex-1 flex justify-center",children:e.jsx(f,{className:"h-[180px] w-[180px] rounded-full"})}),e.jsx("div",{className:"w-[140px] shrink-0 pl-2 space-y-2",children:[1,2,3,4].map(s=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(f,{className:"w-2 h-2 rounded-full"}),e.jsx(f,{className:"h-3 w-20"})]},s))})]})})]})]})]})}function Rs(){const s=g.useRef(null),{dateRange:t,handleDateRangeChange:a,handleTodayClick:n,handleRefresh:o,isRefreshing:r,lastUpdatedText:i,viewMode:d,summary:l,isSummaryLoading:c,trends:h,hourlyData:u,models:p,sessions:D,isTrendsLoading:k,isHourlyLoading:m,isModelsLoading:b,isSessionsLoading:C,handleModelClick:I,selectedModel:R,popoverPosition:q,handlePopoverClose:Y}=ns();return e.jsxs("div",{className:"grid h-full min-h-0 grid-rows-[auto_auto_minmax(0,1fr)] gap-4 overflow-y-auto px-4 py-4",children:[e.jsx(ls,{dateRange:t,onDateRangeChange:a,onTodayClick:n,onRefresh:o,isRefreshing:r,lastUpdatedText:i,viewMode:d}),e.jsx(Ge,{data:l,isLoading:c}),e.jsx(Ns,{viewMode:d,trends:h,hourlyData:u,models:p,sessions:D,isTrendsLoading:k,isHourlyLoading:m,isModelsLoading:b,isSessionsLoading:C,isSummaryLoading:c,onModelClick:I}),e.jsxs(se,{open:!!R,onOpenChange:E=>!E&&Y(),children:[e.jsx(ve,{asChild:!0,children:e.jsx("div",{ref:s,className:"fixed pointer-events-none",style:{left:q?.x??0,top:q?.y??0,width:1,height:1}})}),e.jsx(te,{className:"w-80 p-3",side:"top",align:"center",children:R&&e.jsx(He,{model:R})})]})]})}export{Rs as AnalyticsPage,Fs as AnalyticsSkeleton};
|
|
1
|
+
import{j as e}from"./radix-ui-nu4wz29m.js";import{r as g,E as ge}from"./react-vendor-Bjx91N7w.js";import{u as U,a as $,C as j,b as y,S as f,c as x,P as v,B as K,d as z,e as se,f as je,g as te,h as ye,i as ae,j as w,k as L,l as Ne,m as we,n as be,o as ve}from"./index-BJl0cazY.js";import{a3 as ke,am as ne,an as Q,ao as re,a1 as le,aa as Ce,G as Se,ap as De,R as Te,$ as V,U as Le,Z as ie,v as $e,ae as H,aq as Fe,Y as Re,C as Me,ar as Pe,as as Be}from"./icons-DIVjDO-z.js";import{a as Ae,u as O}from"./tanstack-bhJxV1h8.js";import{K as P,L as oe,f as S,H as Ue}from"./utils-CzKF5WmX.js";import{R as ce,A as Oe,C as Ie,X as qe,Y as Z,T as de,a as X,P as Ke,b as Ee,c as _e}from"./charts-CeK2xCSo.js";import"./notifications-B4_o8bcr.js";import"./form-utils-CuHzLhJZ.js";import"./code-highlight-D4E79GKQ.js";function Ge({data:s,isLoading:t}){const{privacyMode:a}=U(),{t:n}=$(),o=s?.totalTokens??0,r=s?.totalInputTokens??0,i=s?.totalOutputTokens??0,d=s?.totalCacheTokens??0,l=r+i;if(t)return e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-5 gap-4",children:[1,2,3,4,5].map(m=>e.jsx(j,{children:e.jsx(y,{className:"p-6",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(f,{className:"h-4 w-[100px]"}),e.jsx(f,{className:"h-8 w-[80px]"})]}),e.jsx(f,{className:"h-8 w-8 rounded-lg"})]})})},m))});const c=(s?.tokenBreakdown?.cacheCreation?.cost??0)+(s?.tokenBreakdown?.cacheRead?.cost??0),h=s?.totalCost?Math.round(c/s.totalCost*100):0,u=d>0&&o>l,p=d>0&&!u?"Total Tokens (I/O)":n("analyticsSummary.totalTokens"),D=u?`${T(r)} in / ${T(i)} out / ${T(d)} cache`:n("analyticsSummary.totalTokensSubtitle",{input:T(r),output:T(i)}),k=[{title:p,value:o,icon:ke,format:m=>T(m),color:"text-blue-600",bgColor:"bg-blue-100 dark:bg-blue-900/20",subtitle:D},{title:n("analyticsSummary.totalCost"),value:s?.totalCost??0,icon:ne,format:m=>`$${m.toFixed(2)}`,color:"text-green-600",bgColor:"bg-green-100 dark:bg-green-900/20",subtitle:n("analyticsSummary.totalCostSubtitle",{value:s?.averageCostPerDay?.toFixed(2)??"0.00"})},{title:n("analyticsSummary.cacheTokens"),value:s?.totalCacheTokens??0,icon:Q,format:m=>T(m),color:"text-cyan-600",bgColor:"bg-cyan-100 dark:bg-cyan-900/20",subtitle:n("analyticsSummary.cacheTokensSubtitle",{cost:c.toFixed(2),percent:h})},{title:n("analyticsSummary.inputCost"),value:s?.tokenBreakdown?.input?.cost??0,icon:re,format:m=>`$${m.toFixed(2)}`,color:"text-purple-600",bgColor:"bg-purple-100 dark:bg-purple-900/20",subtitle:n("analyticsSummary.tokensSubtitle",{value:T(s?.tokenBreakdown?.input?.tokens??0)})},{title:n("analyticsSummary.outputCost"),value:s?.tokenBreakdown?.output?.cost??0,icon:le,format:m=>`$${m.toFixed(2)}`,color:"text-orange-600",bgColor:"bg-orange-100 dark:bg-orange-900/20",subtitle:n("analyticsSummary.tokensSubtitle",{value:T(s?.tokenBreakdown?.output?.tokens??0)})}];return e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-5 gap-4",children:k.map((m,b)=>{const C=m.icon;return e.jsx(j,{className:"hover:shadow-md transition-shadow",children:e.jsx(y,{className:"p-4",children:e.jsxs("div",{className:"flex items-center justify-between space-x-2",children:[e.jsxs("div",{className:"space-y-1 min-w-0",children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground truncate",children:m.title}),e.jsx("p",{className:x("text-xl font-bold truncate",a&&v),children:m.format(m.value)}),m.subtitle&&e.jsx("p",{className:x("text-[10px] text-muted-foreground truncate",a&&v),children:m.subtitle})]}),e.jsx("div",{className:x("p-2 rounded-lg shrink-0",m.bgColor),children:e.jsx(C,{className:x("h-4 w-4",m.color)})})]})})},b)})})}function T(s){return s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toLocaleString()}function He({model:s}){const{privacyMode:t}=U(),{t:a}=$(),n=We(s.ioRatio),r=s.cacheCreationTokens+s.cacheReadTokens>0?"All Tokens":a("analyticsCards.totalTokens");return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ce,{className:"h-4 w-4 text-primary shrink-0"}),e.jsx("h4",{className:"font-semibold leading-none truncate",title:s.model,children:s.model})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs(K,{variant:"secondary",className:"text-[10px] h-5 px-1.5",children:[s.percentage.toFixed(1),"% usage"]}),e.jsxs(K,{variant:n.variant,className:"text-[10px] h-5 px-1.5",children:[s.ioRatio.toFixed(0),":1 I/O"]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("div",{className:"p-2 rounded-md bg-muted/50 border text-center",children:[e.jsxs("p",{className:x("text-lg font-bold",t&&v),children:["$",s.cost.toFixed(2)]}),e.jsx("p",{className:"text-[10px] text-muted-foreground uppercase tracking-wider",children:a("analyticsCards.totalCost")})]}),e.jsxs("div",{className:"p-2 rounded-md bg-muted/50 border text-center",children:[e.jsx("p",{className:x("text-lg font-bold",t&&v),children:Ye(s.tokens)}),e.jsx("p",{className:"text-[10px] text-muted-foreground uppercase tracking-wider",children:r})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h5",{className:"text-[11px] font-medium text-muted-foreground uppercase tracking-wider",children:"Token Breakdown"}),e.jsxs("div",{className:x("space-y-1",t&&v),children:[e.jsx(W,{label:"Input",tokens:s.inputTokens,cost:s.costBreakdown.input.cost,color:"#335c67",icon:re}),e.jsx(W,{label:"Output",tokens:s.outputTokens,cost:s.costBreakdown.output.cost,color:"#fff3b0",icon:le}),e.jsx(W,{label:"Cache Write",tokens:s.cacheCreationTokens,cost:s.costBreakdown.cacheCreation.cost,color:"#e09f3e",icon:Q}),e.jsx(W,{label:"Cache Read",tokens:s.cacheReadTokens,cost:s.costBreakdown.cacheRead.cost,color:"#9e2a2b",icon:Q})]})]}),e.jsxs("div",{className:"p-2.5 rounded-md border bg-muted/20 space-y-1.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Se,{className:"h-3.5 w-3.5 text-muted-foreground"}),e.jsx("span",{className:"text-xs font-medium",children:a("analyticsCards.inputOutputRatio")})]}),e.jsx("p",{className:"text-[11px] text-muted-foreground leading-snug",children:n.description})]})]})}function W({label:s,tokens:t,cost:a,color:n,icon:o}){return t===0?null:e.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[e.jsx("div",{className:"w-1 h-6 rounded-full shrink-0",style:{backgroundColor:n}}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"font-medium truncate",children:s}),e.jsxs("span",{className:"font-mono text-muted-foreground",children:["$",a.toFixed(3)]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 text-muted-foreground",children:[e.jsx(o,{className:"h-3 w-3 shrink-0"}),e.jsx("span",{children:ze(t)})]})]})]})}function We(s){return s>=200?{variant:"destructive",description:"Extended thinking or large context loading. Expected for reasoning models."}:s>=50?{variant:"secondary",description:"More input than output. Typical for analysis tasks."}:s>=5?{variant:"outline",description:"Balanced input/output ratio for typical coding tasks."}:{variant:"default",description:"More output than input. Generation-heavy workload."}}function ze(s){return s.toLocaleString()}function Ye(s){return s>=1e9?`${(s/1e9).toFixed(1)}B`:s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toString()}const Qe="/api";function N(s){const t=s.getFullYear(),a=String(s.getMonth()+1).padStart(2,"0"),n=String(s.getDate()).padStart(2,"0");return`${t}${a}${n}`}function M(s,t){const a=t.toString();return a?`${s}?${a}`:s}const B={summary:s=>{const t=new URLSearchParams;return s?.startDate&&t.append("since",N(s.startDate)),s?.endDate&&t.append("until",N(s.endDate)),F(M("/usage/summary",t))},trends:s=>{const t=new URLSearchParams;return s?.startDate&&t.append("since",N(s.startDate)),s?.endDate&&t.append("until",N(s.endDate)),F(M("/usage/daily",t))},hourly:s=>{const t=new URLSearchParams;return s?.startDate&&t.append("since",N(s.startDate)),s?.endDate&&t.append("until",N(s.endDate)),F(M("/usage/hourly",t))},models:s=>{const t=new URLSearchParams;return s?.startDate&&t.append("since",N(s.startDate)),s?.endDate&&t.append("until",N(s.endDate)),F(M("/usage/models",t))},sessions:s=>{const t=new URLSearchParams;return s?.startDate&&t.append("since",N(s.startDate)),s?.endDate&&t.append("until",N(s.endDate)),s?.limit&&t.append("limit",s.limit.toString()),s?.offset&&t.append("offset",s.offset.toString()),F(M("/usage/sessions",t))},monthly:s=>{const t=new URLSearchParams;return s?.startDate&&t.append("since",N(s.startDate)),s?.endDate&&t.append("until",N(s.endDate)),F(M("/usage/monthly",t))},refresh:async()=>{if(!(await fetch(`${Qe}/usage/refresh`,{method:"POST",headers:{"Content-Type":"application/json"}})).ok)throw new Error("Failed to refresh usage cache")},status:()=>F("/usage/status"),insights:s=>{const t=new URLSearchParams;return s?.startDate&&t.append("since",N(s.startDate)),s?.endDate&&t.append("until",N(s.endDate)),F(M("/usage/insights",t))}};async function F(s){const a=await fetch(`/api${s}`,{headers:{"Content-Type":"application/json"}});if(!a.ok){const o=await a.json().catch(()=>({error:"Unknown error"}));throw new Error(o.error||a.statusText)}const n=await a.json();return n.data||n}function Ve(s){return O({queryKey:["usage","summary",s],queryFn:()=>B.summary(s),staleTime:60*1e3})}function Ze(s){return O({queryKey:["usage","trends",s],queryFn:()=>B.trends(s),staleTime:60*1e3})}function Xe(s){return O({queryKey:["usage","hourly",s],queryFn:()=>B.hourly(s),staleTime:60*1e3})}function Je(s){return O({queryKey:["usage","models",s],queryFn:()=>B.models(s),staleTime:60*1e3})}function es(){const s=Ae();return g.useCallback(async()=>{await B.refresh(),await s.invalidateQueries({queryKey:["usage"]})},[s])}function ss(){return O({queryKey:["usage","status"],queryFn:()=>B.status(),staleTime:10*1e3,refetchInterval:30*1e3})}function ts(s){return O({queryKey:["usage","sessions",s],queryFn:()=>B.sessions(s),staleTime:60*1e3})}const as=50;function ns(){const[s,t]=g.useState({from:P(new Date,30),to:new Date}),[a,n]=g.useState(!1),[o,r]=g.useState(null),[i,d]=g.useState(null),[l,c]=g.useState("daily"),h=es(),u=g.useCallback(async()=>{n(!0);try{await h()}finally{n(!1)}},[h]),p=g.useMemo(()=>({startDate:s?.from,endDate:s?.to}),[s?.from,s?.to]),{data:D,isLoading:k}=Ve(p),{data:m,isLoading:b}=Ze(p),{data:C,isLoading:I}=Xe(p),{data:R,isLoading:q}=Je(p),{data:Y,isLoading:E}=ts({...p,limit:as}),{data:_}=ss(),xe=g.useCallback(()=>{const A=new Date;t({from:P(A,1),to:A}),c("hourly")},[]),ue=g.useCallback(A=>{t(A),c("daily")},[]),me=g.useMemo(()=>_?.lastFetch?oe(new Date(_.lastFetch),{addSuffix:!0}):null,[_?.lastFetch]),he=g.useCallback((A,pe)=>{const G=pe.currentTarget.getBoundingClientRect();d({x:G.left+G.width/2,y:G.top+G.height/2}),r(A)},[]),fe=g.useCallback(()=>{r(null),d(null)},[]);return{dateRange:s,isRefreshing:a,viewMode:l,selectedModel:o,popoverPosition:i,summary:D,trends:m,hourlyData:C,models:R,sessions:Y,status:_,isSummaryLoading:k,isTrendsLoading:b,isHourlyLoading:I,isModelsLoading:q,isSessionsLoading:E,isLoading:k||b||q||E,handleRefresh:u,handleTodayClick:xe,handleDateRangeChange:ue,handleModelClick:he,handlePopoverClose:fe,lastUpdatedText:me}}function rs({value:s,onChange:t,presets:a=[{label:"Last 7 days",range:{from:P(new Date,7),to:new Date}},{label:"Last 30 days",range:{from:P(new Date,30),to:new Date}},{label:"Last 90 days",range:{from:P(new Date,90),to:new Date}}],className:n}){const[o,r]=ge.useState(!1),{t:i}=$(),d=l=>!s||!s.from||!s.to||!l.from||!l.to?!1:S(s.from,"yyyy-MM-dd")===S(l.from,"yyyy-MM-dd")&&S(s.to,"yyyy-MM-dd")===S(l.to,"yyyy-MM-dd");return e.jsxs("div",{className:x("flex flex-wrap items-center gap-2",n),children:[a.map(l=>e.jsx(z,{variant:d(l.range)?"default":"outline",size:"sm",onClick:()=>t(l.range),children:l.label},l.label)),e.jsxs(se,{open:o,onOpenChange:r,children:[e.jsx(je,{asChild:!0,children:e.jsxs(z,{id:"date",variant:"outline",className:x("w-auto min-w-[200px] sm:min-w-[240px] justify-start text-left font-normal",!s&&"text-muted-foreground"),children:[e.jsx(De,{className:"mr-2 h-4 w-4"}),s?.from?s.to?e.jsxs(e.Fragment,{children:[S(s.from,"LLL dd, y")," - ",S(s.to,"LLL dd, y")]}):S(s.from,"LLL dd, y"):e.jsx("span",{children:i("dateRangeFilter.pickADate")})]})}),e.jsx(te,{className:"w-auto p-0",align:"end",children:e.jsx(ye,{initialFocus:!0,mode:"range",defaultMonth:s?.from,selected:s,onSelect:t,numberOfMonths:2})})]})]})}function ls({dateRange:s,onDateRangeChange:t,onTodayClick:a,onRefresh:n,isRefreshing:o,lastUpdatedText:r,viewMode:i}){const{t:d}=$();return e.jsxs("div",{className:"flex flex-col gap-3 shrink-0 xl:flex-row xl:items-center xl:justify-between",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-xl font-semibold",children:d("analytics.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:d("analytics.subtitle")})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 xl:justify-end",children:[e.jsx(z,{variant:i==="hourly"?"default":"outline",size:"sm",className:"h-8",onClick:a,children:"24H"}),e.jsx(rs,{className:"flex-wrap",value:s,onChange:t,presets:[{label:"7D",range:{from:P(new Date,7),to:new Date}},{label:"30D",range:{from:P(new Date,30),to:new Date}},{label:d("analytics.month"),range:{from:Ue(new Date),to:new Date}},{label:d("analytics.allTime"),range:{from:void 0,to:new Date}}]}),r&&e.jsx("span",{className:"text-xs text-muted-foreground whitespace-nowrap",children:d("analytics.updated",{value:r})}),e.jsx(z,{variant:"outline",size:"sm",className:"gap-2 h-8",onClick:n,disabled:o,children:e.jsx(Te,{className:`w-3.5 h-3.5 ${o?"animate-spin":""}`})})]})]})}function is({data:s,isLoading:t,granularity:a="daily",className:n}){const{privacyMode:o}=U(),{t:r}=$(),i=g.useMemo(()=>!s||s.length===0?[]:s.map(c=>{const h="hour"in c?c.hour:c.date;return{...c,dateFormatted:os(h,a),costRounded:Number(c.cost.toFixed(4))}}),[s,a]);if(t)return e.jsx(f,{className:x("h-full w-full",n)});if(!s||s.length===0)return e.jsx("div",{className:x("h-full flex items-center justify-center",n),children:e.jsx("p",{className:"text-muted-foreground",children:r(a==="hourly"?"analytics.noDailyUsage":"analytics.noUsageData")})});const d=({x:l,y:c,payload:h,isRight:u})=>{const p=u?`$${h.value}`:J(Number(h.value));return e.jsx("text",{x:l,y:c,dy:4,textAnchor:u?"start":"end",fontSize:12,fill:"currentColor",className:x("fill-muted-foreground",o&&"blur-[4px]"),children:p})};return e.jsx("div",{className:x("w-full h-full",n),children:e.jsx(ce,{width:"100%",height:"100%",children:e.jsxs(Oe,{data:i,margin:{top:5,right:30,left:20,bottom:5},children:[e.jsxs("defs",{children:[e.jsxs("linearGradient",{id:"tokenGradient",x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"5%",stopColor:"#0080FF",stopOpacity:.8}),e.jsx("stop",{offset:"95%",stopColor:"#0080FF",stopOpacity:.1})]}),e.jsxs("linearGradient",{id:"costGradient",x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"5%",stopColor:"#00C49F",stopOpacity:.8}),e.jsx("stop",{offset:"95%",stopColor:"#00C49F",stopOpacity:.1})]})]}),e.jsx(Ie,{strokeDasharray:"3 3",className:"stroke-muted"}),e.jsx(qe,{dataKey:"dateFormatted",tick:{fontSize:12},tickLine:!1,axisLine:{className:"stroke-muted"}}),e.jsx(Z,{yAxisId:"left",orientation:"left",tick:l=>e.jsx(d,{...l,isRight:!1}),tickLine:!1,axisLine:{className:"stroke-muted"}}),e.jsx(Z,{yAxisId:"right",orientation:"right",tick:l=>e.jsx(d,{...l,isRight:!0}),tickLine:!1,axisLine:{className:"stroke-muted"}}),e.jsx(de,{content:({active:l,payload:c,label:h})=>!l||!c||!c.length?null:e.jsxs("div",{className:"rounded-lg border bg-background p-3 shadow-lg",children:[e.jsx("p",{className:"font-medium mb-2",children:h}),c.map((u,p)=>e.jsxs("p",{className:x("text-sm",o&&v),style:{color:u.color},children:[u.name,":"," ",u.name==="Tokens"?J(Number(u.value)||0):`$${u.value}`]},p))]})}),e.jsx(X,{yAxisId:"left",type:"monotone",dataKey:"tokens",stroke:"#0080FF",strokeWidth:2,fillOpacity:1,fill:"url(#tokenGradient)",name:"Tokens"}),e.jsx(X,{yAxisId:"right",type:"monotone",dataKey:"costRounded",stroke:"#00C49F",strokeWidth:2,fillOpacity:1,fill:"url(#costGradient)",name:"Cost"})]})})})}function os(s,t){if(t==="hourly"){const[n,o]=s.split(" ");if(n&&o){const r=new Date(`${n}T${o}:00Z`);return S(r,"HH:mm")}return s}const a=new Date(s);return t==="monthly"?S(a,"MMM yyyy"):S(a,"MMM dd")}function J(s){return s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toLocaleString()}function cs({data:s,isLoading:t,className:a}){const{privacyMode:n}=U(),{t:o}=$(),r=g.useMemo(()=>!s||s.length===0?[]:s.map(l=>({name:l.model,value:l.tokens,cost:l.cost,percentage:l.percentage,fill:ae(l.model)})),[s]);if(t)return e.jsx(f,{className:x("h-full min-h-[100px] w-full",a)});if(!s||s.length===0)return e.jsx("div",{className:x("h-full min-h-[100px] flex items-center justify-center",a),children:e.jsx("p",{className:"text-muted-foreground",children:o("analyticsCards.noModelData")})});const i=({active:l,payload:c})=>{if(!l||!c)return null;const h=c;if(!h.length)return null;const u=h[0].payload;return e.jsxs("div",{className:"rounded-lg border bg-background p-2 shadow-lg text-xs",children:[e.jsx("p",{className:"font-medium mb-1",children:u.name}),e.jsxs("p",{className:x("text-muted-foreground",n&&v),children:[ds(u.value)," (",u.percentage.toFixed(1),"%)"]}),e.jsxs("p",{className:x("text-muted-foreground",n&&v),children:["$",u.cost.toFixed(4)]})]})},d=l=>l.percentage>5?`${l.percentage.toFixed(1)}%`:"";return e.jsx("div",{className:x("w-full h-full min-h-[100px]",a),children:e.jsx(ce,{width:"100%",height:"100%",children:e.jsxs(Ke,{children:[e.jsx(Ee,{data:r,cx:"50%",cy:"50%",labelLine:!1,label:d,innerRadius:50,outerRadius:70,paddingAngle:2,dataKey:"value",children:r.map((l,c)=>e.jsx(_e,{fill:l.fill,strokeWidth:1},`cell-${c}`))}),e.jsx(de,{content:i})]})})})}function ds(s){return s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toLocaleString()}function xs(s){if(!s)return"";const a=s.replace(/^\/|\/$/g,"").split("/").filter(n=>n.length>0);return a[a.length-1]||""}function us({data:s,isLoading:t,className:a}){const{privacyMode:n}=U(),{t:o}=$(),r=g.useMemo(()=>{if(!s?.sessions||s.sessions.length===0)return null;const i=s.sessions,d=s.total,l=i.length,c=s.hasMore||s.offset>0,u=i.reduce((p,D)=>p+D.cost,0)/i.length;return{displayedSessions:c?l:d,totalSessions:d,avgCost:u,hasPartialSample:c,recentSessions:i.slice(0,3)}},[s]);return t?e.jsxs(j,{className:x("flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0",a),children:[e.jsx(w,{className:"px-3 py-2",children:e.jsx(f,{className:"h-5 w-32"})}),e.jsx(y,{className:"px-3 pb-3 pt-0 flex-1",children:e.jsx(f,{className:"h-full w-full"})})]}):r?e.jsxs(j,{className:x("flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0 shadow-sm",a),children:[e.jsx(w,{className:"px-3 py-2",children:e.jsxs(L,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(V,{className:"w-4 h-4"}),"Session Stats"]})}),e.jsxs(y,{className:"px-3 pb-3 pt-0 flex-1 min-h-0 flex flex-col gap-3",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("div",{className:"p-2 rounded-md bg-muted/50 border text-center",children:[e.jsxs("div",{className:"flex items-center justify-center gap-1.5 text-blue-600 dark:text-blue-400",children:[e.jsx(Le,{className:"w-4 h-4"}),e.jsx("span",{className:"text-xl font-bold",children:r.displayedSessions})]}),e.jsx("p",{className:"text-[10px] text-muted-foreground uppercase tracking-wider mt-0.5",children:r.hasPartialSample?"Sampled Sessions":"Total Sessions"}),r.hasPartialSample&&e.jsxs("p",{className:"text-[10px] text-muted-foreground mt-0.5",children:[r.totalSessions," total"]})]}),e.jsxs("div",{className:"p-2 rounded-md bg-muted/50 border text-center",children:[e.jsxs("div",{className:"flex items-center justify-center gap-1.5 text-green-600 dark:text-green-400",children:[e.jsx(ie,{className:"w-4 h-4"}),e.jsxs("span",{className:x("text-xl font-bold",n&&v),children:["$",r.avgCost.toFixed(2)]})]}),e.jsx("p",{className:"text-[10px] text-muted-foreground uppercase tracking-wider mt-0.5",children:r.hasPartialSample?"Recent Avg Cost":"Avg Cost/Session"})]})]}),e.jsxs("div",{className:"flex-1 min-h-0 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-1 text-xs text-muted-foreground font-medium mb-1",children:[e.jsx($e,{className:"w-3 h-3"}),"Recent Activity"]}),e.jsx("div",{className:"space-y-1.5 max-h-full overflow-y-auto pr-1",children:r.recentSessions.map(i=>e.jsxs("div",{className:"flex items-center justify-between text-xs p-1.5 rounded bg-muted/30 hover:bg-muted/50 transition-colors",children:[e.jsxs("div",{className:"flex flex-col min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"font-medium truncate",title:i.projectPath,children:xs(i.projectPath)}),(i.target??"claude")!=="claude"&&e.jsx("span",{className:"shrink-0 px-1 py-0 text-[9px] font-medium rounded bg-purple-100 text-purple-700 dark:bg-purple-900/30 dark:text-purple-300 uppercase",children:i.target})]}),e.jsx("span",{className:"text-[10px] text-muted-foreground",children:oe(new Date(i.lastActivity),{addSuffix:!0})})]}),e.jsxs("div",{className:x("text-right shrink-0 ml-2",n&&v),children:[e.jsxs("div",{className:"font-mono",children:["$",i.cost.toFixed(2)]}),e.jsxs("div",{className:"text-[10px] text-muted-foreground",children:[ms(i.tokens??i.inputTokens+i.outputTokens)," ","toks"]})]})]},i.sessionId))})]})]})]}):e.jsxs(j,{className:x("flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0",a),children:[e.jsx(w,{className:"px-3 py-2",children:e.jsxs(L,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(V,{className:"w-4 h-4"}),"Session Stats"]})}),e.jsx(y,{className:"px-3 pb-3 pt-0 flex-1 flex items-center justify-center",children:e.jsx("p",{className:"text-sm text-muted-foreground text-center",children:o("analyticsCards.noSessionData")})})]})}function ms(s){return s>=1e9?`${(s/1e9).toFixed(1)}B`:s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toString()}function hs({className:s,isLoading:t}){const{data:a,isLoading:n}=Ne(),{data:o,isLoading:r,error:i}=we(a?.running),{t:d}=$();if(t||n||a?.running&&r)return e.jsxs(j,{className:x("flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0",s),children:[e.jsx(w,{className:"px-3 py-2",children:e.jsxs(L,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(H,{className:"h-4 w-4"}),"CLIProxy Stats"]})}),e.jsx(y,{className:"px-3 pb-3 pt-0 flex-1",children:e.jsxs("div",{className:"space-y-3",children:[e.jsx(f,{className:"h-4 w-[100px]"}),e.jsx(f,{className:"h-16 w-full"})]})})]});if(!a?.running)return e.jsxs(j,{className:x("flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0 border-dashed",s),children:[e.jsx(w,{className:"px-3 py-2",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(L,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(H,{className:"h-4 w-4 text-muted-foreground"}),"CLIProxy Stats"]}),e.jsx(K,{variant:"secondary",className:"text-[10px] h-5",children:d("cliproxyStatsOverview.offline")})]})}),e.jsx(y,{className:"px-3 pb-3 pt-0 flex-1 flex items-center justify-center",children:e.jsx("p",{className:"text-xs text-muted-foreground text-center",children:d("cliproxyStatsOverview.noActiveSessionHint")})})]});if(i)return e.jsxs(j,{className:x("flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0 border-destructive/50",s),children:[e.jsx(w,{className:"px-3 py-2",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(L,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(H,{className:"h-4 w-4"}),"CLIProxy Stats"]}),e.jsx(K,{variant:"destructive",className:"text-[10px] h-5",children:"Error"})]})}),e.jsx(y,{className:"px-3 pb-3 pt-0 flex-1",children:e.jsx("p",{className:"text-xs text-destructive",children:i.message})})]});const c=o?.totalRequests??0,h=o?.quotaExceededCount??0,u=c-h,p=c>0?Math.round(u/c*100):100,D=o?.tokens?.total??0,k=Object.entries(o?.requestsByModel??{}).sort((b,C)=>C[1]-b[1]).slice(0,4),m=k.length>0?k[0][1]:1;return e.jsxs(j,{className:x("flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0",s),children:[e.jsx(w,{className:"px-3 py-2 border-b bg-muted/5",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(L,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(H,{className:"h-4 w-4"}),"CLIProxy Stats"]}),e.jsxs(K,{variant:"outline",className:"text-[10px] h-5 text-green-600 border-green-200 bg-green-50 dark:bg-green-900/10 dark:border-green-800",children:[e.jsx(ie,{className:"h-3 w-3 mr-0.5"}),d("cliproxyStatsOverview.running")]})]})}),e.jsx(y,{className:"p-0 flex-1 min-h-0",children:e.jsx(be,{className:"h-full",children:e.jsxs("div",{className:"p-3 space-y-3",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2 p-2 rounded-lg bg-muted/30",children:[e.jsxs("div",{className:"relative",children:[e.jsxs("svg",{className:"w-10 h-10 -rotate-90",viewBox:"0 0 36 36",children:[e.jsx("circle",{cx:"18",cy:"18",r:"14",fill:"none",stroke:"currentColor",strokeWidth:"3",className:"text-muted/30"}),e.jsx("circle",{cx:"18",cy:"18",r:"14",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeDasharray:`${p*.88} 88`,strokeLinecap:"round",className:p>=90?"text-green-500":"text-amber-500"})]}),e.jsxs("span",{className:"absolute inset-0 flex items-center justify-center text-[8px] font-bold",children:[p,"%"]})]}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-lg font-bold leading-none",children:ee(c)}),e.jsx("div",{className:"text-[9px] text-muted-foreground mt-0.5",children:h>0?`${h} failed`:"All success"})]})]}),e.jsxs("div",{className:"flex items-center gap-2 p-2 rounded-lg bg-muted/30",children:[e.jsx("div",{className:"p-1.5 rounded-md bg-purple-100 dark:bg-purple-900/20",children:e.jsx(Fe,{className:"h-4 w-4 text-purple-600"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-lg font-bold leading-none",children:ee(D)}),e.jsx("div",{className:"text-[9px] text-muted-foreground mt-0.5",children:d("cliproxyStatsOverview.totalTokens")})]})]})]}),k.length>0&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] font-medium text-muted-foreground",children:[e.jsx(Re,{className:"h-3 w-3"}),d("cliproxyStatsOverview.modelsUsed")]}),e.jsx("div",{className:"space-y-1",children:k.map(([b,C])=>{const I=Math.round(C/m*100),R=fs(b);return e.jsxs("div",{className:"group",children:[e.jsxs("div",{className:"flex items-center justify-between text-[10px] mb-0.5",children:[e.jsx("span",{className:"truncate font-medium",title:b,children:R}),e.jsx("span",{className:"text-muted-foreground shrink-0 ml-2",children:C})]}),e.jsx("div",{className:"h-1 bg-muted/50 rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full bg-accent/70 rounded-full transition-all",style:{width:`${I}%`}})})]},b)})})]})]})})})]})}function ee(s){return s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toLocaleString()}function fs(s){let t=s.replace(/^gemini-claude-/,"").replace(/^gemini-/,"").replace(/^claude-/,"").replace(/^anthropic\./,"").replace(/-thinking$/," Thinking");return t=t.split(/[-_]/).map(a=>a.charAt(0).toUpperCase()+a.slice(1)).join(" "),t.length>20&&(t=t.slice(0,18)+"..."),t}function ps(s){return s>=1e9?`${(s/1e9).toFixed(1)}B`:s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(0)}K`:s.toString()}function gs({models:s,isLoading:t,onModelClick:a,privacyMode:n}){const{t:o}=$();return e.jsxs(j,{className:"flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0 shadow-sm lg:col-span-4",children:[e.jsx(w,{className:"px-3 py-2",children:e.jsxs(L,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(ne,{className:"w-4 h-4"}),o("analyticsPages.costByModel")]})}),e.jsx(y,{className:"px-2 pb-2 pt-0 flex-1 min-h-0 overflow-y-auto",children:t?e.jsx(f,{className:"h-full w-full"}):e.jsxs("div",{className:"space-y-0.5",children:[[...s||[]].sort((r,i)=>i.cost-r.cost).map(r=>e.jsxs("button",{className:"group flex items-center text-xs w-full hover:bg-muted/50 rounded px-2 py-1.5 transition-colors cursor-pointer gap-3",onClick:i=>a(r,i),title:"Click for details",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0 w-[180px] shrink-0",children:[e.jsx("div",{className:"w-2 h-2 rounded-full shrink-0",style:{backgroundColor:ae(r.model)}}),e.jsx("span",{className:"font-medium truncate group-hover:underline underline-offset-2",children:r.model})]}),e.jsx(js,{model:r}),e.jsx("span",{className:x("text-[10px] text-muted-foreground w-14 text-right shrink-0",n&&v),children:ps(r.tokens)}),e.jsxs("span",{className:x("font-mono font-medium w-16 text-right shrink-0",n&&v),children:["$",r.cost.toFixed(2)]}),e.jsx(Me,{className:"w-3 h-3 opacity-0 group-hover:opacity-50 transition-opacity shrink-0"})]},r.model)),e.jsx(ys,{})]})})]})}function js({model:s}){const t={input:"#335c67",output:"#fff3b0",cacheWrite:"#e09f3e",cacheRead:"#9e2a2b"},a=n=>s.cost>0?n/s.cost*100:0;return e.jsx("div",{className:"flex-1 flex items-center gap-1 min-w-0",children:e.jsxs("div",{className:"flex-1 h-2 bg-muted rounded-full overflow-hidden flex",children:[e.jsx("div",{className:"h-full",style:{backgroundColor:t.input,width:`${a(s.costBreakdown.input.cost)}%`},title:`Input: $${s.costBreakdown.input.cost.toFixed(2)}`}),e.jsx("div",{className:"h-full",style:{backgroundColor:t.output,width:`${a(s.costBreakdown.output.cost)}%`},title:`Output: $${s.costBreakdown.output.cost.toFixed(2)}`}),e.jsx("div",{className:"h-full",style:{backgroundColor:t.cacheWrite,width:`${a(s.costBreakdown.cacheCreation.cost)}%`},title:`Cache Write: $${s.costBreakdown.cacheCreation.cost.toFixed(2)}`}),e.jsx("div",{className:"h-full",style:{backgroundColor:t.cacheRead,width:`${a(s.costBreakdown.cacheRead.cost)}%`},title:`Cache Read: $${s.costBreakdown.cacheRead.cost.toFixed(2)}`})]})})}function ys(){const s=[{color:"#335c67",label:"Input"},{color:"#fff3b0",label:"Output",hasBorder:!0},{color:"#e09f3e",label:"Cache Write"},{color:"#9e2a2b",label:"Cache Read"}];return e.jsx("div",{className:"flex items-center gap-3 pt-2 px-2 text-[10px] text-muted-foreground border-t mt-2",children:s.map(({color:t,label:a,hasBorder:n})=>e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("div",{className:x("w-2 h-2 rounded-full",n&&"border border-muted-foreground/30"),style:{backgroundColor:t}}),a]},a))})}function Ns({viewMode:s,trends:t,hourlyData:a,models:n,sessions:o,isTrendsLoading:r,isHourlyLoading:i,isModelsLoading:d,isSessionsLoading:l,isSummaryLoading:c,onModelClick:h}){const{privacyMode:u}=U();return e.jsxs("div",{className:"min-h-0 grid gap-4 lg:grid-rows-[minmax(260px,1.2fr)_minmax(220px,0.9fr)]",children:[e.jsxs(j,{className:"flex flex-col h-full min-h-[220px] lg:min-h-[240px] overflow-hidden gap-0 py-0 shadow-sm",children:[e.jsx(w,{className:"px-3 py-2 shrink-0",children:e.jsxs(L,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(Pe,{className:"w-4 h-4"}),s==="hourly"?"Last 24 Hours":"Usage Trends"]})}),e.jsx(y,{className:"px-3 pb-3 pt-0 flex-1 min-h-0",children:e.jsx(is,{data:s==="hourly"?a||[]:t||[],isLoading:s==="hourly"?i:r,granularity:s==="hourly"?"hourly":"daily"})})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-10 gap-4 h-auto min-h-[220px] lg:h-full lg:min-h-[220px] lg:grid-rows-[minmax(0,1fr)] lg:[&>*]:min-h-0",children:[e.jsx(gs,{models:n,isLoading:d,onModelClick:h,privacyMode:u}),e.jsxs(j,{className:"flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0 shadow-sm lg:col-span-2",children:[e.jsx(w,{className:"px-3 py-2",children:e.jsxs(L,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(Be,{className:"w-4 h-4"}),"Model Usage"]})}),e.jsx(y,{className:"px-2 pb-2 pt-0 flex-1 min-h-0 flex items-center justify-center",children:e.jsx(cs,{data:n||[],isLoading:d,className:"h-full w-full"})})]}),e.jsx(us,{data:o,isLoading:l,className:"lg:col-span-2"}),e.jsx(hs,{isLoading:c,className:"lg:col-span-2"})]})]})}function Fs(){return e.jsxs("div",{className:"space-y-4 h-full overflow-hidden",children:[e.jsxs(j,{className:"flex flex-col min-h-[300px]",children:[e.jsx(w,{className:"p-4 pb-2",children:e.jsx(f,{className:"h-4 w-32"})}),e.jsx(y,{className:"p-4 pt-0 flex-1",children:e.jsx(f,{className:"h-full w-full"})})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-4",children:[e.jsxs(j,{className:"flex flex-col min-h-[250px]",children:[e.jsx(w,{className:"p-4 pb-2",children:e.jsx(f,{className:"h-4 w-28"})}),e.jsx(y,{className:"p-4 pt-2",children:e.jsx("div",{className:"space-y-3",children:[1,2,3,4,5].map(s=>e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(f,{className:"w-2.5 h-2.5 rounded-full"}),e.jsx(f,{className:"h-3 w-24"})]}),e.jsx(f,{className:"h-3 w-16"})]},s))})})]}),e.jsxs(j,{className:"flex flex-col min-h-[250px]",children:[e.jsx(w,{className:"p-4 pb-2",children:e.jsx(f,{className:"h-4 w-28"})}),e.jsx(y,{className:"p-4 pt-0 flex-1",children:e.jsxs("div",{className:"flex w-full h-full items-center",children:[e.jsx("div",{className:"flex-1 flex justify-center",children:e.jsx(f,{className:"h-[180px] w-[180px] rounded-full"})}),e.jsx("div",{className:"w-[140px] shrink-0 pl-2 space-y-2",children:[1,2,3,4].map(s=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(f,{className:"w-2 h-2 rounded-full"}),e.jsx(f,{className:"h-3 w-20"})]},s))})]})})]})]})]})}function Rs(){const s=g.useRef(null),{dateRange:t,handleDateRangeChange:a,handleTodayClick:n,handleRefresh:o,isRefreshing:r,lastUpdatedText:i,viewMode:d,summary:l,isSummaryLoading:c,trends:h,hourlyData:u,models:p,sessions:D,isTrendsLoading:k,isHourlyLoading:m,isModelsLoading:b,isSessionsLoading:C,handleModelClick:I,selectedModel:R,popoverPosition:q,handlePopoverClose:Y}=ns();return e.jsxs("div",{className:"grid h-full min-h-0 grid-rows-[auto_auto_minmax(0,1fr)] gap-4 overflow-y-auto px-4 py-4",children:[e.jsx(ls,{dateRange:t,onDateRangeChange:a,onTodayClick:n,onRefresh:o,isRefreshing:r,lastUpdatedText:i,viewMode:d}),e.jsx(Ge,{data:l,isLoading:c}),e.jsx(Ns,{viewMode:d,trends:h,hourlyData:u,models:p,sessions:D,isTrendsLoading:k,isHourlyLoading:m,isModelsLoading:b,isSessionsLoading:C,isSummaryLoading:c,onModelClick:I}),e.jsxs(se,{open:!!R,onOpenChange:E=>!E&&Y(),children:[e.jsx(ve,{asChild:!0,children:e.jsx("div",{ref:s,className:"fixed pointer-events-none",style:{left:q?.x??0,top:q?.y??0,width:1,height:1}})}),e.jsx(te,{className:"w-80 p-3",side:"top",align:"center",children:R&&e.jsx(He,{model:R})})]})]})}export{Rs as AnalyticsPage,Fs as AnalyticsSkeleton};
|