@georgedong32/ccs 8.0.2 → 8.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ui/assets/{accounts-CQD3g_kc.js → accounts-DY2qc1Fj.js} +1 -1
- package/dist/ui/assets/{alert-dialog-DEtONzN3.js → alert-dialog-DxSEXEYT.js} +1 -1
- package/dist/ui/assets/{api-B9Cfd3jR.js → api-BuQsvzTw.js} +1 -1
- package/dist/ui/assets/{auth-section-C1vDzDw1.js → auth-section-BaOzwIQC.js} +1 -1
- package/dist/ui/assets/{backups-section-BUhH7VtX.js → backups-section-CtCPd8ZP.js} +1 -1
- package/dist/ui/assets/{channels-D6WkjmPo.js → channels-Dc9yAiRV.js} +1 -1
- package/dist/ui/assets/{checkbox-B7zva2TJ.js → checkbox-PmhTRKMJ.js} +1 -1
- package/dist/ui/assets/{claude-extension-ezpSC4Lf.js → claude-extension-BmrRz66m.js} +1 -1
- package/dist/ui/assets/{cliproxy-Br_wjWvV.js → cliproxy-CisEtPs4.js} +1 -1
- package/dist/ui/assets/{cliproxy-ai-providers-Ct8SWsdd.js → cliproxy-ai-providers-CuUlJ9io.js} +1 -1
- package/dist/ui/assets/{cliproxy-control-panel-UDei2RV8.js → cliproxy-control-panel-yiOrEg3N.js} +1 -1
- package/dist/ui/assets/{codex-BT9Yw44z.js → codex-EjebSo8c.js} +1 -1
- package/dist/ui/assets/{confirm-dialog-w1OUy2tj.js → confirm-dialog-BIPtmVJj.js} +1 -1
- package/dist/ui/assets/{copilot-cSpRj87f.js → copilot-BSZD1eVg.js} +1 -1
- package/dist/ui/assets/{cursor-DwOVGqTq.js → cursor-BVhDG7IA.js} +1 -1
- package/dist/ui/assets/{droid-CvcaIUwN.js → droid-2Cn2gExW.js} +1 -1
- package/dist/ui/assets/{globalenv-section-u9D6mVBj.js → globalenv-section-DdDcVEM8.js} +1 -1
- package/dist/ui/assets/{health-CANaS83m.js → health-DMpTU0-S.js} +1 -1
- package/dist/ui/assets/{index-Dal0dW0L.js → index-B9Ty7Irs.js} +1 -1
- package/dist/ui/assets/{index-DWXxyg1S.js → index-CUg_ifEj.js} +1 -1
- package/dist/ui/assets/index-CvcrgRX9.js +1 -0
- package/dist/ui/assets/{index-CYxZm5ai.js → index-DJ7By7qi.js} +1 -1
- package/dist/ui/assets/{index-DO7BjG3E.js → index-DObHizqD.js} +1 -1
- package/dist/ui/assets/{index-0eUwteKg.js → index-DcAGM-vb.js} +1 -1
- package/dist/ui/assets/{index-BjjduukP.js → index-Dm0Cx9St.js} +2 -2
- package/dist/ui/assets/{logs-UAxhvSHg.js → logs-CgJ-0Ohj.js} +1 -1
- package/dist/ui/assets/{masked-input-bcWAQ9xJ.js → masked-input-Bvcx7hT9.js} +1 -1
- package/dist/ui/assets/{proxy-status-widget-Bk-8lUri.js → proxy-status-widget-DgakK820.js} +1 -1
- package/dist/ui/assets/{raw-json-settings-editor-panel-C2vJUFOx.js → raw-json-settings-editor-panel-DJc8S7Hd.js} +1 -1
- package/dist/ui/assets/{searchable-select-DZ-PpJI1.js → searchable-select-ycZJ7HQQ.js} +1 -1
- package/dist/ui/assets/{separator-qf7RWsl-.js → separator-F5z10x_U.js} +1 -1
- package/dist/ui/assets/{shared-Dk1xUFxk.js → shared-CHO8lnK0.js} +1 -1
- package/dist/ui/assets/{table-1tRW7-Y4.js → table-DzcQUkAB.js} +1 -1
- package/dist/ui/assets/{updates-CaTV1fNN.js → updates-FFYZ3hbq.js} +1 -1
- package/dist/ui/assets/{use-accounts-C5vt1fQQ.js → use-accounts-CfYoYSF6.js} +1 -1
- package/dist/ui/index.html +1 -1
- package/package.json +1 -1
- package/dist/ui/assets/index-a5K20f1J.js +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{j as e}from"./radix-ui-DvRtHWGI.js";import{r as h,E as Ie}from"./react-vendor-Bjx91N7w.js";import{u as A,a as L,C as D,b as T,S as j,c as f,P as C,B as ae,d as Ae,e as K,f as ge,g as Be,h as ye,i as qe,D as Ue,j as Ke,k as Oe,l as Ee,m as _e,n as He,o as We,p as Qe,q as Ge,r as Ve,s as Ye,t as je,v as P,w as _,x as ne,I as ze,y as Ze}from"./index-BjjduukP.js";import{a2 as Ne,al as J,am as H,an as we,a0 as ve,a9 as Je,G as Xe,ao as le,L as es,ap as ss,w as ts,v as as,aq as ns,R as rs,_ as ue,U as ls,Z as os,u as is,ar as cs,as as ds,at as be,C as us,au as xs}from"./icons-bxdfpJdB.js";import{a as X,u as F,k as Q,b as ie}from"./tanstack-Dg84L5cM.js";import{u as ms}from"./use-accounts-C5vt1fQQ.js";import{K as O,L as Ce,f as M,H as hs}from"./utils-CzKF5WmX.js";import{R as ke,A as fs,C as ps,X as gs,Y as xe,T as Se,b as me,P as ys,c as js,d as Ns}from"./charts-eIPy2oG6.js";import"./notifications-B4_o8bcr.js";import"./form-utils-CuHzLhJZ.js";function ws({data:s,isLoading:t}){const{privacyMode:a}=A(),{t:n}=L(),l=s?.totalTokens??0,o=s?.totalInputTokens??0,c=s?.totalOutputTokens??0,d=s?.totalCacheTokens??0,r=o+c;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(i=>e.jsx(D,{children:e.jsx(T,{className:"p-6",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(j,{className:"h-4 w-[100px]"}),e.jsx(j,{className:"h-8 w-[80px]"})]}),e.jsx(j,{className:"h-8 w-8 rounded-lg"})]})})},i))});const u=(s?.tokenBreakdown?.cacheCreation?.cost??0)+(s?.tokenBreakdown?.cacheRead?.cost??0),m=s?.totalCost?Math.round(u/s.totalCost*100):0,x=d>0&&l>r,y=d>0&&!x?"Total Tokens (I/O)":n("analyticsSummary.totalTokens"),w=x?`${$(o)} in / ${$(c)} out / ${$(d)} cache`:n("analyticsSummary.totalTokensSubtitle",{input:$(o),output:$(c)}),k=[{title:y,value:l,icon:Ne,format:i=>$(i),color:"text-blue-600",bgColor:"bg-blue-100 dark:bg-blue-900/20",subtitle:w},{title:n("analyticsSummary.totalCost"),value:s?.totalCost??0,icon:J,format:i=>`$${i.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:H,format:i=>$(i),color:"text-cyan-600",bgColor:"bg-cyan-100 dark:bg-cyan-900/20",subtitle:n("analyticsSummary.cacheTokensSubtitle",{cost:u.toFixed(2),percent:m})},{title:n("analyticsSummary.inputCost"),value:s?.tokenBreakdown?.input?.cost??0,icon:we,format:i=>`$${i.toFixed(2)}`,color:"text-purple-600",bgColor:"bg-purple-100 dark:bg-purple-900/20",subtitle:n("analyticsSummary.tokensSubtitle",{value:$(s?.tokenBreakdown?.input?.tokens??0)})},{title:n("analyticsSummary.outputCost"),value:s?.tokenBreakdown?.output?.cost??0,icon:ve,format:i=>`$${i.toFixed(2)}`,color:"text-orange-600",bgColor:"bg-orange-100 dark:bg-orange-900/20",subtitle:n("analyticsSummary.tokensSubtitle",{value:$(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((i,p)=>{const g=i.icon;return e.jsx(D,{className:"hover:shadow-md transition-shadow",children:e.jsx(T,{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:i.title}),e.jsx("p",{className:f("text-xl font-bold truncate",a&&C),children:i.format(i.value)}),i.subtitle&&e.jsx("p",{className:f("text-[10px] text-muted-foreground truncate",a&&C),children:i.subtitle})]}),e.jsx("div",{className:f("p-2 rounded-lg shrink-0",i.bgColor),children:e.jsx(g,{className:f("h-4 w-4",i.color)})})]})})},p)})})}function $(s){return s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toLocaleString()}function vs({model:s}){const{privacyMode:t}=A(),{t:a}=L(),n=Cs(s.ioRatio,a),o=s.cacheCreationTokens+s.cacheReadTokens>0?a("analyticsCards.allTokens"):a("analyticsCards.totalTokens"),c=s.cacheReadTokens>0?s.cacheReadTokens/(s.inputTokens+s.cacheReadTokens)*100:0,d=c>0?bs(c):null;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(Je,{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(ae,{variant:"secondary",className:"text-[10px] h-5 px-1.5",children:[s.percentage.toFixed(1),"% usage"]}),e.jsxs(ae,{variant:n.variant,className:"text-[10px] h-5 px-1.5",children:[s.ioRatio.toFixed(0),":1 I/O"]}),d&&e.jsxs(ae,{variant:d,className:"text-[10px] h-5 px-1.5",children:[c.toFixed(0),"% ",a("analyticsCards.hitRate")]})]})]}),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:f("text-lg font-bold",t&&C),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:f("text-lg font-bold",t&&C),children:Ss(s.tokens)}),e.jsx("p",{className:"text-[10px] text-muted-foreground uppercase tracking-wider",children:o})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h5",{className:"text-[11px] font-medium text-muted-foreground uppercase tracking-wider",children:a("analyticsCards.tokenBreakdown")}),e.jsxs("div",{className:f("space-y-1",t&&C),children:[e.jsx(Z,{label:a("analyticsCards.input"),tokens:s.inputTokens,cost:s.costBreakdown.input.cost,color:"#335c67",icon:we}),e.jsx(Z,{label:a("analyticsCards.output"),tokens:s.outputTokens,cost:s.costBreakdown.output.cost,color:"#fff3b0",icon:ve}),e.jsx(Z,{label:a("analyticsCards.cacheWrite"),tokens:s.cacheCreationTokens,cost:s.costBreakdown.cacheCreation.cost,color:"#e09f3e",icon:H}),e.jsx(Z,{label:a("analyticsCards.cacheRead"),tokens:s.cacheReadTokens,cost:s.costBreakdown.cacheRead.cost,color:"#9e2a2b",icon:H})]})]}),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(Xe,{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 Z({label:s,tokens:t,cost:a,color:n,icon:l}){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(l,{className:"h-3 w-3 shrink-0"}),e.jsx("span",{children:ks(t)})]})]})]})}function bs(s){return s>=50?"success":s>=20?"secondary":"outline"}function Cs(s,t){return s>=200?{variant:"destructive",description:t("analyticsCards.extendedThinkingHint")}:s>=50?{variant:"secondary",description:t("analyticsCards.analysisTaskHint")}:s>=5?{variant:"outline",description:t("analyticsCards.balancedRatioHint")}:{variant:"default",description:t("analyticsCards.generationHeavyHint")}}function ks(s){return s.toLocaleString()}function Ss(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 he="/api";function fe(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 B(s,t){const a=t.toString();return a?`${s}?${a}`:s}function q(s,t){t?.startDate&&s.append("since",fe(t.startDate)),t?.endDate&&s.append("until",fe(t.endDate))}function U(s,t){t?.profile&&s.append("profile",t.profile)}const R={summary:s=>{const t=new URLSearchParams;return q(t,s),U(t,s),I(B("/usage/summary",t))},trends:s=>{const t=new URLSearchParams;return q(t,s),U(t,s),I(B("/usage/daily",t))},hourly:s=>{const t=new URLSearchParams;return q(t,s),U(t,s),I(B("/usage/hourly",t))},models:s=>{const t=new URLSearchParams;return q(t,s),U(t,s),I(B("/usage/models",t))},sessions:s=>{const t=new URLSearchParams;return q(t,s),s?.limit&&t.append("limit",s.limit.toString()),s?.offset&&t.append("offset",s.offset.toString()),U(t,s),I(B("/usage/sessions",t))},monthly:s=>{const t=new URLSearchParams;return q(t,s),U(t,s),I(B("/usage/monthly",t))},refresh:async()=>{if(!(await fetch(`${he}/usage/refresh`,{method:"POST",headers:{"Content-Type":"application/json"}})).ok)throw new Error("Failed to refresh usage cache");const t=1500,a=3e4,n=Date.now();for(;Date.now()-n<a;){await new Promise(l=>setTimeout(l,t));try{const l=await fetch(`${he}/usage/refresh-status`);if(!l.ok)continue;if(!(await l.json()).data?.refreshing)return}catch{}}},status:()=>I("/usage/status"),insights:s=>{const t=new URLSearchParams;return q(t,s),U(t,s),I(B("/usage/insights",t))},cursorImport:async s=>{const t=new FormData;t.append("file",s);const a=await fetch("/api/usage/cursor/import",{method:"POST",body:t});if(!a.ok){const l=await a.json().catch(()=>({error:"Upload failed"}));throw new Error(l.error||"Failed to import Cursor usage data")}return(await a.json()).data},cursorStatus:async()=>{const s=await fetch("/api/usage/cursor/status");if(!s.ok)throw new Error("Failed to fetch Cursor status");return(await s.json()).data},cursorDataClear:async()=>{const s=await fetch("/api/usage/cursor/clear",{method:"POST"});if(!s.ok)throw new Error("Failed to clear Cursor data");return(await s.json()).data}};async function I(s){const a=await fetch(`/api${s}`,{headers:{"Content-Type":"application/json"}});if(!a.ok){const l=await a.json().catch(()=>({error:"Unknown error"}));throw new Error(l.error||a.statusText)}const n=await a.json();return n.data||n}function Ds(s){return F({queryKey:["usage","summary",s],queryFn:()=>R.summary(s),staleTime:60*1e3,placeholderData:Q})}function Ts(s){return F({queryKey:["usage","trends",s],queryFn:()=>R.trends(s),staleTime:60*1e3,placeholderData:Q})}function Ls(s){return F({queryKey:["usage","hourly",s],queryFn:()=>R.hourly(s),staleTime:60*1e3,placeholderData:Q})}function Fs(s){return F({queryKey:["usage","models",s],queryFn:()=>R.models(s),staleTime:60*1e3,placeholderData:Q})}function Ps(){const s=X();return h.useCallback(async()=>{await R.refresh(),await s.invalidateQueries({queryKey:["usage"]})},[s])}function Ms(){return F({queryKey:["usage","status"],queryFn:()=>R.status(),staleTime:10*1e3,refetchInterval:30*1e3})}function Rs(s){return F({queryKey:["usage","sessions",s],queryFn:()=>R.sessions(s),staleTime:60*1e3,placeholderData:Q})}const $s=50,oe="ccs.analytics.selectedProfile",W="all";function Is(){if(typeof globalThis.localStorage>"u")return W;const s=globalThis.localStorage.getItem(oe);return!s||s.startsWith("unsupported:")?W:s}function As(s){if(!(typeof globalThis.localStorage>"u")){if(s===W){globalThis.localStorage.removeItem(oe);return}globalThis.localStorage.setItem(oe,s)}}function Bs(){const[s,t]=h.useState({from:O(new Date,30),to:new Date}),[a,n]=h.useState(!1),[l,o]=h.useState(null),[c,d]=h.useState(Is),[r,u]=h.useState(null),[m,x]=h.useState("daily"),{t:y}=L(),{data:w}=ms(),{data:k}=Ae(),i=Ps(),p=h.useCallback(async()=>{n(!0);try{await i()}finally{n(!1)}},[i]),g=h.useMemo(()=>({startDate:s?.from,endDate:s?.to,profile:c===W?void 0:c}),[s?.from,s?.to,c]),v=h.useMemo(()=>{const S=new Set(w?.accounts.map(b=>b.name)??[]),z=[{value:W,label:y("analyticsCards.allProfiles"),description:y("analyticsCards.allProfilesDesc"),supported:!0},{value:"default",label:y("analyticsCards.defaultClaude"),description:y("analyticsCards.defaultClaudeDesc"),supported:!0},...Array.from(S).sort((b,$e)=>b.localeCompare($e)).map(b=>({value:b,label:b,description:"Profile-scoped account data.",supported:!0}))];for(const b of k?.profiles??[])S.has(b.name)||b.name==="default"||z.push({value:`unsupported:${b.name}`,label:b.name,description:"API profile usage is not yet attributed by stable profile.",supported:!1});return z},[w?.accounts,k?.profiles]),{data:N,isLoading:G}=Ds(g),{data:ee,isLoading:E}=Ts(g),{data:V,isLoading:se}=Ls(g),{data:te,isLoading:ce}=Fs(g),{data:De,isLoading:de}=Rs({...g,limit:$s}),{data:Y}=Ms(),Te=h.useCallback(()=>{const S=new Date;t({from:O(S,1),to:S}),x("hourly")},[]),Le=h.useCallback(S=>{t(S),x("daily")},[]),Fe=h.useCallback(S=>{S.startsWith("unsupported:")||(d(S),As(S))},[]),Pe=h.useMemo(()=>Y?.lastFetch?Ce(new Date(Y.lastFetch),{addSuffix:!0}):null,[Y?.lastFetch]),Me=h.useCallback((S,z)=>{const b=z.currentTarget.getBoundingClientRect();u({x:b.left+b.width/2,y:b.top+b.height/2}),o(S)},[]),Re=h.useCallback(()=>{o(null),u(null)},[]);return{dateRange:s,isRefreshing:a,viewMode:m,selectedProfile:c,profileOptions:v,selectedModel:l,popoverPosition:r,summary:N,trends:ee,hourlyData:V,models:te,sessions:De,status:Y,isSummaryLoading:G,isTrendsLoading:E,isHourlyLoading:se,isModelsLoading:ce,isSessionsLoading:de,isLoading:G||E||ce||de,handleRefresh:p,handleTodayClick:Te,handleDateRangeChange:Le,handleProfileChange:Fe,handleModelClick:Me,handlePopoverClose:Re,lastUpdatedText:Pe}}function qs({value:s,onChange:t,presets:a=[{label:"Last 7 days",range:{from:O(new Date,7),to:new Date}},{label:"Last 30 days",range:{from:O(new Date,30),to:new Date}},{label:"Last 90 days",range:{from:O(new Date,90),to:new Date}}],className:n}){const[l,o]=Ie.useState(!1),{t:c}=L(),d=r=>!s||!s.from||!s.to||!r.from||!r.to?!1:M(s.from,"yyyy-MM-dd")===M(r.from,"yyyy-MM-dd")&&M(s.to,"yyyy-MM-dd")===M(r.to,"yyyy-MM-dd");return e.jsxs("div",{className:f("flex flex-wrap items-center gap-2",n),children:[a.map(r=>e.jsx(K,{variant:d(r.range)?"default":"outline",size:"sm",onClick:()=>t(r.range),children:r.label},r.label)),e.jsxs(ge,{open:l,onOpenChange:o,children:[e.jsx(Be,{asChild:!0,children:e.jsxs(K,{id:"date",variant:"outline",className:f("w-auto min-w-[200px] sm:min-w-[240px] justify-start text-left font-normal",!s&&"text-muted-foreground"),children:[e.jsx(le,{className:"mr-2 h-4 w-4"}),s?.from?s.to?e.jsxs(e.Fragment,{children:[M(s.from,"LLL dd, y")," - ",M(s.to,"LLL dd, y")]}):M(s.from,"LLL dd, y"):e.jsx("span",{children:c("dateRangeFilter.pickADate")})]})}),e.jsx(ye,{className:"w-auto p-0",align:"end",children:e.jsx(qe,{initialFocus:!0,mode:"range",defaultMonth:s?.from,selected:s,onSelect:t,numberOfMonths:2})})]})]})}function Us(){const s=X();return ie({mutationFn:t=>R.cursorImport(t),onSuccess:()=>{s.invalidateQueries({queryKey:["usage"]}),s.invalidateQueries({queryKey:["cursor-status"]})}})}function Ks(){return F({queryKey:["cursor-status"],queryFn:()=>R.cursorStatus(),staleTime:30*1e3})}function Os(){const s=X();return ie({mutationFn:()=>R.cursorDataClear(),onSuccess:()=>{s.invalidateQueries({queryKey:["usage"]}),s.invalidateQueries({queryKey:["cursor-status"]})}})}function Es(){const{t:s}=L(),{privacyMode:t}=A(),a=h.useRef(null),[n,l]=h.useState(!1),[o,c]=h.useState(null),d=Us(),{data:r,isLoading:u}=Ks(),m=Os(),x=async i=>{const p=i.target.files?.[0];if(p){c(null);try{await d.mutateAsync(p)}catch(g){c(g instanceof Error?g.message:s("analyticsCursor.errorMessage"))}a.current&&(a.current.value="")}},y=async()=>{if(window.confirm(s("analyticsCursor.clearConfirm")))try{await m.mutateAsync()}catch{c(s("analyticsCursor.errorMessage"))}},w=i=>i>=1e6?`${(i/1e6).toFixed(1)}M`:i.toLocaleString(),k=i=>!i||i.length<8?i:`${i.slice(0,4)}-${i.slice(4,6)}-${i.slice(6,8)}`;return e.jsxs(Ue,{open:n,onOpenChange:l,children:[e.jsx(Ke,{asChild:!0,children:e.jsxs(K,{variant:"outline",size:"sm",className:"gap-2 h-8",children:[e.jsx(H,{className:"w-3.5 h-3.5"}),e.jsx("span",{className:"hidden sm:inline",children:s("analytics.importData")})]})}),e.jsxs(Oe,{className:"sm:max-w-md",children:[e.jsxs(Ee,{children:[e.jsxs(_e,{className:"flex items-center gap-2",children:[e.jsx(H,{className:"w-4 h-4"}),s("analytics.importData")]}),e.jsx(He,{children:s("analyticsCursor.fileHint")})]}),e.jsx("div",{className:"space-y-4",children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-medium",children:[e.jsx(Ne,{className:"w-4 h-4"}),s("cursorIde")]}),e.jsx("input",{ref:a,type:"file",accept:".csv",className:"hidden",onChange:x}),e.jsx(K,{variant:"outline",size:"sm",className:"w-full",disabled:d.isPending,onClick:()=>a.current?.click(),children:d.isPending?e.jsxs(e.Fragment,{children:[e.jsx(es,{className:"w-3.5 h-3.5 mr-2 animate-spin"}),s("analyticsCursor.importing")]}):e.jsxs(e.Fragment,{children:[e.jsx(ss,{className:"w-3.5 h-3.5 mr-2"}),s("analyticsCursor.importButton")]})}),d.isSuccess&&e.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-green-600",children:[e.jsx(ts,{className:"w-3.5 h-3.5 shrink-0"}),e.jsx("span",{children:s("analyticsCursor.successMessage")})]}),o&&e.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-destructive",children:[e.jsx(as,{className:"w-3.5 h-3.5 shrink-0"}),e.jsx("span",{className:"truncate",children:o})]}),u?null:r?.hasData?e.jsxs("div",{className:"rounded-md border bg-muted/30 p-3 text-xs space-y-1.5",children:[r.dateRange&&e.jsxs("div",{className:"text-muted-foreground",children:[k(r.dateRange.from)," ~ ",k(r.dateRange.to)]}),e.jsxs("div",{className:f(t&&C),children:[w(r.totalTokens)," tokens · ",r.totalEvents," events"]}),r.models.length>0&&e.jsx("div",{className:"text-muted-foreground truncate",children:r.models.join(", ")})]}):e.jsx("p",{className:"text-xs text-muted-foreground",children:s("analyticsCursor.fileHint")}),r?.hasData&&e.jsxs(K,{variant:"ghost",size:"sm",className:"w-full text-xs text-muted-foreground hover:text-destructive",disabled:m.isPending,onClick:y,children:[e.jsx(ns,{className:"w-3 h-3 mr-1"}),s("analyticsCursor.clearButton")]})]})})]})]})}function _s({dateRange:s,onDateRangeChange:t,onTodayClick:a,onRefresh:n,isRefreshing:l,lastUpdatedText:o,viewMode:c,selectedProfile:d,profileOptions:r,onProfileChange:u}){const{t:m}=L();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:m("analytics.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:m("analytics.subtitle")})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 xl:justify-end",children:[e.jsxs(We,{value:d,onValueChange:u,children:[e.jsx(Qe,{className:"h-8 w-[200px] min-w-0","aria-label":m("analyticsCards.allProfiles"),children:e.jsx(Ge,{placeholder:m("analyticsCards.allProfiles"),children:r.find(x=>x.value===d)?.label})}),e.jsx(Ve,{className:"min-w-[260px]",children:r.map(x=>e.jsx(Ye,{value:x.value,disabled:!x.supported,children:e.jsxs("span",{className:"flex flex-col gap-0.5 py-0.5",children:[e.jsx("span",{className:"font-medium text-sm",children:x.label}),e.jsx("span",{className:"text-xs text-muted-foreground leading-tight",children:x.description})]})},x.value))})]}),e.jsx(K,{variant:c==="hourly"?"default":"outline",size:"sm",className:"h-8",onClick:a,children:"24H"}),e.jsx(qs,{className:"flex-wrap",value:s,onChange:t,presets:[{label:"7D",range:{from:O(new Date,7),to:new Date}},{label:"30D",range:{from:O(new Date,30),to:new Date}},{label:m("analytics.month"),range:{from:hs(new Date),to:new Date}},{label:m("analytics.allTime"),range:{from:void 0,to:new Date}}]}),o&&e.jsx("span",{className:"text-xs text-muted-foreground whitespace-nowrap",children:m("analytics.updated",{value:o})}),e.jsx(K,{variant:"outline",size:"sm",className:"gap-2 h-8",onClick:n,disabled:l,children:e.jsx(rs,{className:`w-3.5 h-3.5 ${l?"animate-spin":""}`})}),e.jsx(Es,{})]}),d!=="all"&&e.jsx("p",{className:"text-xs text-muted-foreground xl:text-right",children:"Selected-profile analytics include only default/account data with stable profile attribution. CLIProxy and native runtime snapshots remain in All profiles."})]})}function Hs({data:s,isLoading:t,granularity:a="daily",className:n}){const{privacyMode:l}=A(),{t:o}=L(),c=h.useMemo(()=>!s||s.length===0?[]:s.map(u=>{const m="hour"in u?u.hour:u.date;return{...u,dateFormatted:Ws(m,a),costRounded:Number(u.cost.toFixed(4))}}),[s,a]);if(t)return e.jsx(j,{className:f("h-full w-full",n)});if(!s||s.length===0)return e.jsx("div",{className:f("h-full flex items-center justify-center",n),children:e.jsx("p",{className:"text-muted-foreground",children:o(a==="hourly"?"analytics.noDailyUsage":"analytics.noUsageData")})});const d=({x:r,y:u,payload:m,isRight:x})=>{const y=x?`$${m.value}`:pe(Number(m.value));return e.jsx("text",{x:r,y:u,dy:4,textAnchor:x?"start":"end",fontSize:12,fill:"currentColor",className:f("fill-muted-foreground",l&&"blur-[4px]"),children:y})};return e.jsx("div",{className:f("w-full h-full",n),children:e.jsx(ke,{width:"100%",height:"100%",children:e.jsxs(fs,{data:c,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(ps,{strokeDasharray:"3 3",className:"stroke-muted"}),e.jsx(gs,{dataKey:"dateFormatted",tick:{fontSize:12},tickLine:!1,axisLine:{className:"stroke-muted"}}),e.jsx(xe,{yAxisId:"left",orientation:"left",tick:r=>e.jsx(d,{...r,isRight:!1}),tickLine:!1,axisLine:{className:"stroke-muted"}}),e.jsx(xe,{yAxisId:"right",orientation:"right",tick:r=>e.jsx(d,{...r,isRight:!0}),tickLine:!1,axisLine:{className:"stroke-muted"}}),e.jsx(Se,{content:({active:r,payload:u,label:m})=>!r||!u||!u.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:m}),u.map((x,y)=>e.jsxs("p",{className:f("text-sm",l&&C),style:{color:x.color},children:[x.name,":"," ",x.name==="Tokens"?pe(Number(x.value)||0):`$${x.value}`]},y))]})}),e.jsx(me,{yAxisId:"left",type:"monotone",dataKey:"tokens",stroke:"#0080FF",strokeWidth:2,fillOpacity:1,fill:"url(#tokenGradient)",name:"Tokens"}),e.jsx(me,{yAxisId:"right",type:"monotone",dataKey:"costRounded",stroke:"#00C49F",strokeWidth:2,fillOpacity:1,fill:"url(#costGradient)",name:"Cost"})]})})})}function Ws(s,t){if(t==="hourly"){const[n,l]=s.split(" ");if(n&&l){const o=new Date(`${n}T${l}:00Z`);return M(o,"HH:mm")}return s}const a=new Date(s);return t==="monthly"?M(a,"MMM yyyy"):M(a,"MMM dd")}function pe(s){return s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toLocaleString()}function Qs({data:s,isLoading:t,className:a}){const{privacyMode:n}=A(),{t:l}=L(),o=h.useMemo(()=>!s||s.length===0?[]:s.map(r=>({name:r.model,value:r.tokens,cost:r.cost,percentage:r.percentage,fill:je(r.model)})),[s]);if(t)return e.jsx(j,{className:f("h-full min-h-[100px] w-full",a)});if(!s||s.length===0)return e.jsx("div",{className:f("h-full min-h-[100px] flex items-center justify-center",a),children:e.jsx("p",{className:"text-muted-foreground",children:l("analyticsCards.noModelData")})});const c=({active:r,payload:u})=>{if(!r||!u)return null;const m=u;if(!m.length)return null;const x=m[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:x.name}),e.jsxs("p",{className:f("text-muted-foreground",n&&C),children:[Gs(x.value)," (",x.percentage.toFixed(1),"%)"]}),e.jsxs("p",{className:f("text-muted-foreground",n&&C),children:["$",x.cost.toFixed(4)]})]})},d=r=>r.percentage>5?`${r.percentage.toFixed(1)}%`:"";return e.jsx("div",{className:f("w-full h-full min-h-[100px]",a),children:e.jsx(ke,{width:"100%",height:"100%",children:e.jsxs(ys,{children:[e.jsx(js,{data:o,cx:"50%",cy:"50%",labelLine:!1,label:d,innerRadius:50,outerRadius:70,paddingAngle:2,dataKey:"value",children:o.map((r,u)=>e.jsx(Ns,{fill:r.fill,strokeWidth:1},`cell-${u}`))}),e.jsx(Se,{content:c})]})})})}function Gs(s){return s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toLocaleString()}function Vs(s){if(!s)return"";const a=s.replace(/^\/|\/$/g,"").split("/").filter(n=>n.length>0);return a[a.length-1]||""}function Ys({data:s,isLoading:t,className:a}){const{privacyMode:n}=A(),{t:l}=L(),o=h.useMemo(()=>{if(!s?.sessions||s.sessions.length===0)return null;const c=s.sessions,d=s.total,r=c.length,u=s.hasMore||s.offset>0,x=c.reduce((y,w)=>y+w.cost,0)/c.length;return{displayedSessions:u?r:d,totalSessions:d,avgCost:x,hasPartialSample:u,recentSessions:c.slice(0,3)}},[s]);return t?e.jsxs(D,{className:f("flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0",a),children:[e.jsx(P,{className:"px-3 py-2",children:e.jsx(j,{className:"h-5 w-32"})}),e.jsx(T,{className:"px-3 pb-3 pt-0 flex-1",children:e.jsx(j,{className:"h-full w-full"})})]}):o?e.jsxs(D,{className:f("flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0 shadow-sm",a),children:[e.jsx(P,{className:"px-3 py-2",children:e.jsxs(_,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(ue,{className:"w-4 h-4"}),l("analyticsCards.sessionStats")]})}),e.jsxs(T,{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(ls,{className:"w-4 h-4"}),e.jsx("span",{className:"text-xl font-bold",children:o.displayedSessions})]}),e.jsx("p",{className:"text-[10px] text-muted-foreground uppercase tracking-wider mt-0.5",children:o.hasPartialSample?l("analyticsCards.sampledSessions"):l("analyticsCards.totalSessions")}),o.hasPartialSample&&e.jsxs("p",{className:"text-[10px] text-muted-foreground mt-0.5",children:[o.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(os,{className:"w-4 h-4"}),e.jsxs("span",{className:f("text-xl font-bold",n&&C),children:["$",o.avgCost.toFixed(2)]})]}),e.jsx("p",{className:"text-[10px] text-muted-foreground uppercase tracking-wider mt-0.5",children:o.hasPartialSample?l("analyticsCards.recentAvgCost"):l("analyticsCards.avgCostPerSession")})]})]}),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(is,{className:"w-3 h-3"}),l("analyticsCards.recentActivity")]}),e.jsx("div",{className:"space-y-1.5 max-h-full overflow-y-auto pr-1",children:o.recentSessions.map(c=>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:c.projectPath,children:Vs(c.projectPath)}),(c.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:c.target})]}),e.jsx("span",{className:"text-[10px] text-muted-foreground",children:Ce(new Date(c.lastActivity),{addSuffix:!0})})]}),e.jsxs("div",{className:f("text-right shrink-0 ml-2",n&&C),children:[e.jsxs("div",{className:"font-mono",children:["$",c.cost.toFixed(2)]}),e.jsxs("div",{className:"text-[10px] text-muted-foreground",children:[zs(c.tokens??c.inputTokens+c.outputTokens)," ","toks"]})]})]},c.sessionId))})]})]})]}):e.jsxs(D,{className:f("flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0",a),children:[e.jsx(P,{className:"px-3 py-2",children:e.jsxs(_,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(ue,{className:"w-4 h-4"}),l("analyticsCards.sessionStats")]})}),e.jsx(T,{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:l("analyticsCards.noSessionData")})})]})}function zs(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()}async function re(s,t){try{const a=new URLSearchParams,n=d=>{const r=d.getFullYear(),u=String(d.getMonth()+1).padStart(2,"0"),m=String(d.getDate()).padStart(2,"0");return`${r}${u}${m}`};a.append("since",n(s)),a.append("until",n(t));const l=await fetch(`/api/usage/summary?${a}`,{headers:{"Content-Type":"application/json"}});if(!l.ok)return 0;const o=await l.json();return(o.data||o).totalCost||0}catch{return 0}}function Zs(){const s=new Date;return new Date(s.getFullYear(),s.getMonth()+1,0).getDate()}function Js(){return new Date().getDate()}function Xs(s,t){return t<=0?"N/A":`${(s/t).toFixed(2)}x`}function et(s,t){return t<=0?null:s/t}function st(){const s=X(),t=F({queryKey:["cost-leverage-config"],queryFn:async()=>{const g=(await ne.config.get()).preferences?.baseline_cost_30d;return typeof g=="number"?g:void 0},staleTime:30*1e3}),a=t.data,n=h.useMemo(()=>new Date,[]),l=h.useMemo(()=>{const i=new Date(n),p=new Date(n);return p.setDate(p.getDate()-6),{start:p,end:i}},[n]),o=h.useMemo(()=>{const i=new Date(n),p=new Date(n);return p.setDate(p.getDate()-29),{start:p,end:i}},[n]),c=h.useMemo(()=>{const i=new Date(n.getFullYear(),n.getMonth(),1),p=new Date(n);return{start:i,end:p}},[n]),d=F({queryKey:["cost-leverage","7d"],queryFn:()=>re(l.start,l.end),staleTime:60*1e3}),r=F({queryKey:["cost-leverage","30d"],queryFn:()=>re(o.start,o.end),staleTime:60*1e3}),u=F({queryKey:["cost-leverage","month"],queryFn:()=>re(c.start,c.end),staleTime:60*1e3}),m=ie({mutationFn:async i=>{const p=await ne.config.get(),v={...p.preferences||{}};i==null?delete v.baseline_cost_30d:v.baseline_cost_30d=i;const N=typeof p.version=="number"?p.version:12;return ne.config.update({version:N,preferences:v})},onSuccess:()=>{s.invalidateQueries({queryKey:["cost-leverage-config"]})}}),x=h.useMemo(()=>{const i=Js(),p=Zs();return[{label:"7d",cost:d.data??0,windowDays:7,scaleDays:7},{label:"30d",cost:r.data??0,windowDays:30,scaleDays:30},{label:"Month",cost:u.data??0,windowDays:i,scaleDays:p}].map(v=>{const N=a?a*v.scaleDays/30:0;return{label:v.label,estimatedCost:v.cost,scaledBaseline:N,ratio:et(v.cost,N),ratioDisplay:Xs(v.cost,N),windowDays:v.windowDays}})},[a,d.data,r.data,u.data]),y=h.useCallback(i=>{const p=i.trim();if(p==="")return m.mutate(void 0),{valid:!0};const g=Number(p);return isNaN(g)||g<=0?{valid:!1,error:"invalid"}:(m.mutate(g),{valid:!0})},[m]),w=t.isLoading||d.isLoading&&r.isLoading&&u.isLoading,k=t.error?.message||m.error?.message||null;return{baselineCost:a,windows:x,isLoading:w,isSaving:m.isPending,error:k,saveBaseline:y,cost7d:d.data,cost30d:r.data,costMonth:u.data}}function tt({className:s,isLoading:t}){const{privacyMode:a}=A(),{t:n}=L(),{baselineCost:l,windows:o,isLoading:c,isSaving:d,error:r,saveBaseline:u}=st(),[m,x]=h.useState(l!==void 0?String(l):""),[y,w]=h.useState(null),[k,i]=h.useState(!1);l!==void 0&&!k&&(x(String(l)),i(!0)),l===void 0&&k&&i(!1);const p=h.useCallback(()=>{u(m).valid?(w(null),m.trim()===""&&(x(""),i(!1))):w(n("analyticsCostLeverage.invalidInput"))},[m,u,n]),g=h.useCallback(N=>{N.key==="Enter"&&(N.preventDefault(),p())},[p]),v=l!==void 0&&l>0;return c||t?e.jsxs(D,{className:f("flex flex-col h-full",s),children:[e.jsx(P,{className:"px-3 py-2",children:e.jsx(j,{className:"h-5 w-36"})}),e.jsx(T,{className:"px-3 pb-3 pt-0 flex-1",children:e.jsx(j,{className:"h-full w-full"})})]}):e.jsxs(D,{className:f("flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0 shadow-sm",s),children:[e.jsx(P,{className:"px-3 py-2 shrink-0",children:e.jsxs(_,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(cs,{className:"w-4 h-4"}),n("analyticsCostLeverage.title")]})}),e.jsxs(T,{className:"px-3 pb-3 pt-0 flex-1 min-h-0 flex flex-col gap-2",children:[v?e.jsx("div",{className:"flex-1 flex flex-col gap-2 justify-center min-h-0",children:o.map(N=>e.jsx(at,{window:N,privacyMode:a,t:n},N.label))}):e.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center gap-2",children:[e.jsx("div",{className:"w-10 h-10 rounded-full bg-muted/50 flex items-center justify-center",children:e.jsx(J,{className:"w-5 h-5 text-muted-foreground"})}),e.jsx("p",{className:"text-xs text-muted-foreground text-center leading-relaxed max-w-[180px]",children:n("analyticsCostLeverage.noBaseline")})]}),e.jsxs("div",{className:"shrink-0 pt-2 mt-auto border-t",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(J,{className:"w-3.5 h-3.5 text-muted-foreground shrink-0"}),e.jsx(ze,{type:"text",inputMode:"decimal",value:m,onChange:N=>{x(N.target.value),w(null)},onBlur:p,onKeyDown:g,placeholder:n("analyticsCostLeverage.baselinePlaceholder"),disabled:d,className:f("h-7 text-xs",y&&"border-destructive focus-visible:ring-destructive")}),d&&e.jsx("span",{className:"text-[10px] text-muted-foreground animate-pulse",children:n("analyticsCostLeverage.saving")})]}),y&&e.jsx("p",{className:"text-[10px] text-destructive mt-1",children:y}),r&&e.jsxs("p",{className:"text-[10px] text-destructive mt-1",children:[n("analyticsCostLeverage.saveError"),": ",r]})]})]})]})}function at({window:s,privacyMode:t,t:a}){const n=s.label==="7d"?"analyticsCostLeverage.window7d":s.label==="30d"?"analyticsCostLeverage.window30d":"analyticsCostLeverage.windowMonth",l=s.label==="7d"?le:s.label==="30d"?ds:le,o=s.ratio===null?"text-muted-foreground":s.ratio<2.5?"text-red-600 dark:text-red-400":s.ratio<10?"text-amber-600 dark:text-amber-400":"text-emerald-600 dark:text-emerald-400",c=s.ratio===null?"bg-muted/30":s.ratio<2.5?"bg-red-100/30 dark:bg-red-950/30":s.ratio<10?"bg-amber-100/30 dark:bg-amber-950/30":"bg-emerald-100/30 dark:bg-emerald-950/30";return e.jsxs("div",{className:f("flex items-center gap-2 px-2.5 py-2 rounded-lg border transition-colors",c),children:[e.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[e.jsx(l,{className:"w-3.5 h-3.5 text-muted-foreground"}),e.jsx("span",{className:"text-xs text-muted-foreground font-medium",children:a(n)})]}),e.jsxs("span",{className:f("text-xs text-muted-foreground font-mono",t&&C),children:["$",s.estimatedCost.toFixed(2)]}),e.jsx("div",{className:"flex-1 border-t border-dashed border-muted-foreground/30"}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[s.ratio!==null&&s.ratio>=10&&e.jsx(be,{className:"w-3.5 h-3.5 text-emerald-500"}),e.jsx("span",{className:f("text-lg font-bold tabular-nums min-w-[56px] text-right",o,t&&C),children:s.ratioDisplay})]})]})}function nt(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 rt({models:s,isLoading:t,onModelClick:a,privacyMode:n}){const{t:l}=L();return e.jsxs(D,{className:"flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0 shadow-sm lg:col-span-4",children:[e.jsx(P,{className:"px-3 py-2",children:e.jsxs(_,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(J,{className:"w-4 h-4"}),l("analyticsPages.costByModel")]})}),e.jsx(T,{className:"px-2 pb-2 pt-0 flex-1 min-h-0 overflow-y-auto",children:t?e.jsx(j,{className:"h-full w-full"}):e.jsxs("div",{className:"space-y-0.5",children:[[...s||[]].sort((o,c)=>c.cost-o.cost).map(o=>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:c=>a(o,c),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:je(o.model)}}),e.jsx("span",{className:"font-medium truncate group-hover:underline underline-offset-2",children:o.model})]}),e.jsx(lt,{model:o}),e.jsx("span",{className:f("text-[10px] text-muted-foreground w-14 text-right shrink-0",n&&C),children:nt(o.tokens)}),e.jsxs("span",{className:f("font-mono font-medium w-16 text-right shrink-0",n&&C),children:["$",o.cost.toFixed(2)]}),e.jsx(us,{className:"w-3 h-3 opacity-0 group-hover:opacity-50 transition-opacity shrink-0"})]},o.model)),e.jsx(ot,{})]})})]})}function lt({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 ot(){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:f("w-2 h-2 rounded-full",n&&"border border-muted-foreground/30"),style:{backgroundColor:t}}),a]},a))})}function it({viewMode:s,trends:t,hourlyData:a,models:n,sessions:l,isTrendsLoading:o,isHourlyLoading:c,isModelsLoading:d,isSessionsLoading:r,onModelClick:u}){const{privacyMode:m}=A(),{t:x}=L();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(D,{className:"flex flex-col h-full min-h-[220px] lg:min-h-[240px] overflow-hidden gap-0 py-0 shadow-sm",children:[e.jsx(P,{className:"px-3 py-2 shrink-0",children:e.jsxs(_,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(be,{className:"w-4 h-4"}),x(s==="hourly"?"analyticsPages.last24Hours":"analyticsPages.usageTrends")]})}),e.jsx(T,{className:"px-3 pb-3 pt-0 flex-1 min-h-0",children:e.jsx(Hs,{data:s==="hourly"?a||[]:t||[],isLoading:s==="hourly"?c:o,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(rt,{models:n,isLoading:d,onModelClick:u,privacyMode:m}),e.jsxs(D,{className:"flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0 shadow-sm lg:col-span-2",children:[e.jsx(P,{className:"px-3 py-2",children:e.jsxs(_,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(xs,{className:"w-4 h-4"}),x("analyticsPages.modelUsage")]})}),e.jsx(T,{className:"px-2 pb-2 pt-0 flex-1 min-h-0 flex items-center justify-center",children:e.jsx(Qs,{data:n||[],isLoading:d,className:"h-full w-full"})})]}),e.jsx(Ys,{data:l,isLoading:r,className:"lg:col-span-2"}),e.jsx(tt,{className:"lg:col-span-2"})]})]})}function jt(){return e.jsxs("div",{className:"space-y-4 h-full overflow-hidden",children:[e.jsxs(D,{className:"flex flex-col min-h-[300px]",children:[e.jsx(P,{className:"p-4 pb-2",children:e.jsx(j,{className:"h-4 w-32"})}),e.jsx(T,{className:"p-4 pt-0 flex-1",children:e.jsx(j,{className:"h-full w-full"})})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-4",children:[e.jsxs(D,{className:"flex flex-col min-h-[250px]",children:[e.jsx(P,{className:"p-4 pb-2",children:e.jsx(j,{className:"h-4 w-28"})}),e.jsx(T,{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(j,{className:"w-2.5 h-2.5 rounded-full"}),e.jsx(j,{className:"h-3 w-24"})]}),e.jsx(j,{className:"h-3 w-16"})]},s))})})]}),e.jsxs(D,{className:"flex flex-col min-h-[250px]",children:[e.jsx(P,{className:"p-4 pb-2",children:e.jsx(j,{className:"h-4 w-28"})}),e.jsx(T,{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(j,{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(j,{className:"w-2 h-2 rounded-full"}),e.jsx(j,{className:"h-3 w-20"})]},s))})]})})]})]})]})}function Nt(){const s=h.useRef(null),{dateRange:t,handleDateRangeChange:a,handleTodayClick:n,handleRefresh:l,isRefreshing:o,lastUpdatedText:c,viewMode:d,selectedProfile:r,profileOptions:u,summary:m,isSummaryLoading:x,trends:y,hourlyData:w,models:k,sessions:i,isTrendsLoading:p,isHourlyLoading:g,isModelsLoading:v,isSessionsLoading:N,handleModelClick:G,handleProfileChange:ee,selectedModel:E,popoverPosition:V,handlePopoverClose:se}=Bs();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(_s,{dateRange:t,onDateRangeChange:a,onTodayClick:n,onRefresh:l,isRefreshing:o,lastUpdatedText:c,viewMode:d,selectedProfile:r,profileOptions:u,onProfileChange:ee}),e.jsx(ws,{data:m,isLoading:x}),e.jsx(it,{viewMode:d,trends:y,hourlyData:w,models:k,sessions:i,isTrendsLoading:p,isHourlyLoading:g,isModelsLoading:v,isSessionsLoading:N,onModelClick:G}),e.jsxs(ge,{open:!!E,onOpenChange:te=>!te&&se(),children:[e.jsx(Ze,{asChild:!0,children:e.jsx("div",{ref:s,className:"fixed pointer-events-none",style:{left:V?.x??0,top:V?.y??0,width:1,height:1}})}),e.jsx(ye,{className:"w-80 p-3",side:"top",align:"center",children:E&&e.jsx(vs,{model:E})})]})]})}export{Nt as AnalyticsPage,jt as AnalyticsSkeleton};
|