@georgedong32/ccs 7.67.1 → 7.67.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/.claude/commands/opsx/apply.md +152 -0
- package/.claude/commands/opsx/archive.md +157 -0
- package/.claude/commands/opsx/continue.md +114 -0
- package/.claude/commands/opsx/explore.md +173 -0
- package/.claude/commands/opsx/ff.md +97 -0
- package/.claude/commands/opsx/new.md +69 -0
- package/.claude/commands/opsx/propose.md +106 -0
- package/.claude/commands/opsx/sync.md +134 -0
- package/.claude/commands/opsx/verify.md +164 -0
- package/.claude/settings.local.json +47 -1
- package/dist/auth/commands/create-command-env.d.ts +1 -0
- package/dist/auth/commands/create-command-env.d.ts.map +1 -1
- package/dist/channels/official-channels-runtime.d.ts +1 -0
- package/dist/channels/official-channels-runtime.d.ts.map +1 -1
- package/dist/channels/official-channels-store.d.ts +1 -0
- package/dist/channels/official-channels-store.d.ts.map +1 -1
- package/dist/cliproxy/base-config-loader.d.ts +1 -0
- package/dist/cliproxy/base-config-loader.d.ts.map +1 -1
- package/dist/cliproxy/config/env-builder.d.ts +1 -0
- package/dist/cliproxy/config/env-builder.d.ts.map +1 -1
- package/dist/cliproxy/config/extended-context-config.d.ts +1 -0
- package/dist/cliproxy/config/extended-context-config.d.ts.map +1 -1
- package/dist/cliproxy/config/thinking-config.d.ts +1 -0
- package/dist/cliproxy/config/thinking-config.d.ts.map +1 -1
- package/dist/cliproxy/model-id-normalizer.d.ts +1 -0
- package/dist/cliproxy/model-id-normalizer.d.ts.map +1 -1
- package/dist/cursor/cursor-anthropic-response.d.ts +1 -0
- package/dist/cursor/cursor-anthropic-response.d.ts.map +1 -1
- package/dist/cursor/cursor-executor.d.ts +1 -0
- package/dist/cursor/cursor-executor.d.ts.map +1 -1
- package/dist/docker/docker-executor.d.ts +1 -0
- package/dist/docker/docker-executor.d.ts.map +1 -1
- package/dist/targets/claude-adapter.d.ts +1 -0
- package/dist/targets/claude-adapter.d.ts.map +1 -1
- package/dist/targets/codex-adapter.d.ts +1 -0
- package/dist/targets/codex-adapter.d.ts.map +1 -1
- package/dist/targets/droid-adapter.d.ts +1 -0
- package/dist/targets/droid-adapter.d.ts.map +1 -1
- package/dist/targets/target-adapter.d.ts +1 -0
- package/dist/targets/target-adapter.d.ts.map +1 -1
- package/dist/types/cli.d.ts +1 -0
- package/dist/types/cli.d.ts.map +1 -1
- package/dist/ui/assets/{accounts-DhtktAIG.js → accounts-3AVm26OA.js} +1 -1
- package/dist/ui/assets/{alert-dialog-DQK2Jxfk.js → alert-dialog-DDRA-1Pt.js} +1 -1
- package/dist/ui/assets/{api-Den1YY2d.js → api-BPEl09Ob.js} +1 -1
- package/dist/ui/assets/{auth-section-BQitOLMK.js → auth-section-DoAPGxlq.js} +1 -1
- package/dist/ui/assets/{backups-section-BLGK5re-.js → backups-section-CyRRApPr.js} +1 -1
- package/dist/ui/assets/{channels-Dop1axTi.js → channels-CkgeG_Nr.js} +1 -1
- package/dist/ui/assets/{checkbox-DDrDuGxi.js → checkbox-2A_GWLUb.js} +1 -1
- package/dist/ui/assets/{claude-extension-6WjTc0o8.js → claude-extension-1rjZXaRt.js} +1 -1
- package/dist/ui/assets/{cliproxy-Ch7RdSMG.js → cliproxy-CMU0po64.js} +1 -1
- package/dist/ui/assets/{cliproxy-ai-providers-DjybBlb5.js → cliproxy-ai-providers-CRYD_2SS.js} +1 -1
- package/dist/ui/assets/{cliproxy-control-panel-DDif_QAT.js → cliproxy-control-panel-Bo9-0Mcr.js} +1 -1
- package/dist/ui/assets/{codex-DFAV50Ee.js → codex-DZCkRvut.js} +1 -1
- package/dist/ui/assets/{confirm-dialog-CP26_Zko.js → confirm-dialog-wFhgI3dr.js} +1 -1
- package/dist/ui/assets/{copilot-uZuyhqwv.js → copilot-Dd7oxTU-.js} +1 -1
- package/dist/ui/assets/{cursor-CuaM2FmN.js → cursor-CvA9T82x.js} +1 -1
- package/dist/ui/assets/{droid-DdjXJ2lF.js → droid-6r-EzLds.js} +1 -1
- package/dist/ui/assets/{globalenv-section-D5_-EIlf.js → globalenv-section-QTLjTpzK.js} +1 -1
- package/dist/ui/assets/{health-BHhVKLNR.js → health-580PHGfZ.js} +1 -1
- package/dist/ui/assets/index-BgDioiqT.js +1 -0
- package/dist/ui/assets/{index-B8bAYHAs.js → index-CNKKQedn.js} +1 -1
- package/dist/ui/assets/{index-Ba-43jCS.js → index-Cd_4MB83.js} +1 -1
- package/dist/ui/assets/{index-Bm09kGOw.js → index-CxcEG3G-.js} +1 -1
- package/dist/ui/assets/{index-TSYtCr3K.js → index-DI-8QF69.js} +3 -3
- package/dist/ui/assets/{index-DHY37v8a.js → index-ZXB5YY2K.js} +1 -1
- package/dist/ui/assets/{masked-input-CTkIqCMg.js → masked-input-DUhsSbtq.js} +1 -1
- package/dist/ui/assets/{proxy-status-widget-DPhKjJFl.js → proxy-status-widget-bxJaZJK2.js} +1 -1
- package/dist/ui/assets/{raw-json-settings-editor-panel-DQr_y0E4.js → raw-json-settings-editor-panel-BDlKTYzk.js} +1 -1
- package/dist/ui/assets/{searchable-select-C2sP7JW5.js → searchable-select-rg8_CopX.js} +1 -1
- package/dist/ui/assets/{separator-2lt47Sla.js → separator-DgIPRe__.js} +1 -1
- package/dist/ui/assets/{shared-DPKtsiFQ.js → shared-BiFfbORv.js} +1 -1
- package/dist/ui/assets/{table-DbsFACgT.js → table-7YfVdOmB.js} +1 -1
- package/dist/ui/assets/{updates-C5iL4KNn.js → updates-BsjUVKfy.js} +1 -1
- package/dist/ui/index.html +1 -1
- package/dist/utils/claude-detector.d.ts +1 -0
- package/dist/utils/claude-detector.d.ts.map +1 -1
- package/dist/utils/claude-spawner.d.ts +1 -0
- package/dist/utils/claude-spawner.d.ts.map +1 -1
- package/dist/utils/shell-executor.d.ts +1 -0
- package/dist/utils/shell-executor.d.ts.map +1 -1
- package/dist/utils/websearch/trace.d.ts +1 -0
- package/dist/utils/websearch/trace.d.ts.map +1 -1
- package/dist/web-server/model-pricing.d.ts.map +1 -1
- package/dist/web-server/model-pricing.js +85 -25
- package/dist/web-server/model-pricing.js.map +1 -1
- package/dist/web-server/services/codex-dashboard-service.d.ts +1 -0
- package/dist/web-server/services/codex-dashboard-service.d.ts.map +1 -1
- package/dist/web-server/services/droid-dashboard-service.d.ts +1 -0
- package/dist/web-server/services/droid-dashboard-service.d.ts.map +1 -1
- package/dist/web-server/usage/handlers.d.ts +5 -0
- package/dist/web-server/usage/handlers.d.ts.map +1 -1
- package/dist/web-server/usage/handlers.js +23 -15
- package/dist/web-server/usage/handlers.js.map +1 -1
- package/package.json +5 -6
- package/dist/ui/assets/index-DLCFe4s3.js +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{j as e}from"./radix-ui-BlliRfHq.js";import{r as h,c as Ne}from"./react-vendor-CNOkPC89.js";import{u as P,a as F,C,b as D,S as j,c as u,P as b,B as ee,d as B,e as re,f as we,g as le,h as ve,D as be,i as ke,j as Ce,k as De,l as Se,m as Me,n as oe,o as L,p as U,q as Y,I as Le,r as Fe}from"./index-TSYtCr3K.js";import{a0 as ie,ae as W,af as E,ag as ce,_ as de,a6 as Te,G as $e,ah as Z,L as Re,ai as Pe,v as Be,u as qe,aj as Ae,R as Ke,V as se,U as Ue,Z as Ie,t as Ee,ak as Oe,al as He,am as ue,C as _e,an as Qe}from"./icons-CQ3MLSan.js";import{a as G,u as M,b as J}from"./tanstack-BjiH4QZq.js";import{K as q,L as X,f as T,H as We}from"./utils-CzKF5WmX.js";import{R as xe,A as Ge,C as ze,X as Ye,Y as te,T as me,a as ae,P as Ve,b as Ze,c as Xe}from"./charts-BBPXh0Ar.js";import"./notifications-B2HqRBj7.js";import"./form-utils-Bcoyqxpq.js";import"./code-highlight-BRUf_pqB.js";function Je({data:s,isLoading:t}){const{privacyMode:a}=P(),{t:n}=F();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(r=>e.jsx(C,{children:e.jsx(D,{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"})]})})},r))});const l=(s?.tokenBreakdown?.cacheCreation?.cost??0)+(s?.tokenBreakdown?.cacheRead?.cost??0),c=s?.totalCost?Math.round(l/s.totalCost*100):0,i=[{title:n("analyticsSummary.totalTokens"),value:s?.totalTokens??0,icon:ie,format:r=>K(r),color:"text-blue-600",bgColor:"bg-blue-100 dark:bg-blue-900/20",subtitle:n("analyticsSummary.totalTokensSubtitle",{input:K(s?.totalInputTokens??0),output:K(s?.totalOutputTokens??0)})},{title:n("analyticsSummary.totalCost"),value:s?.totalCost??0,icon:W,format:r=>`$${r.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:E,format:r=>K(r),color:"text-cyan-600",bgColor:"bg-cyan-100 dark:bg-cyan-900/20",subtitle:n("analyticsSummary.cacheTokensSubtitle",{cost:l.toFixed(2),percent:c})},{title:n("analyticsSummary.inputCost"),value:s?.tokenBreakdown?.input?.cost??0,icon:ce,format:r=>`$${r.toFixed(2)}`,color:"text-purple-600",bgColor:"bg-purple-100 dark:bg-purple-900/20",subtitle:n("analyticsSummary.tokensSubtitle",{value:K(s?.tokenBreakdown?.input?.tokens??0)})},{title:n("analyticsSummary.outputCost"),value:s?.tokenBreakdown?.output?.cost??0,icon:de,format:r=>`$${r.toFixed(2)}`,color:"text-orange-600",bgColor:"bg-orange-100 dark:bg-orange-900/20",subtitle:n("analyticsSummary.tokensSubtitle",{value:K(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:i.map((r,o)=>{const x=r.icon;return e.jsx(C,{className:"hover:shadow-md transition-shadow",children:e.jsx(D,{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:r.title}),e.jsx("p",{className:u("text-xl font-bold truncate",a&&b),children:r.format(r.value)}),r.subtitle&&e.jsx("p",{className:u("text-[10px] text-muted-foreground truncate",a&&b),children:r.subtitle})]}),e.jsx("div",{className:u("p-2 rounded-lg shrink-0",r.bgColor),children:e.jsx(x,{className:u("h-4 w-4",r.color)})})]})})},o)})})}function K(s){return s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toLocaleString()}function es({model:s}){const{privacyMode:t}=P(),{t:a}=F(),n=ss(s.ioRatio,a);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(Te,{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.jsx(ee,{variant:"secondary",className:"text-[10px] h-5 px-1.5",children:a("analyticsModelDetail.percentUsage",{percent:s.percentage.toFixed(1)})}),e.jsx(ee,{variant:n.variant,className:"text-[10px] h-5 px-1.5",children:a("analyticsModelDetail.ioRatio",{ratio:s.ioRatio.toFixed(0)})})]})]}),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:u("text-lg font-bold",t&&b),children:["$",s.cost.toFixed(2)]}),e.jsx("p",{className:"text-[10px] text-muted-foreground uppercase tracking-wider",children:a("analyticsModelDetail.totalCost")})]}),e.jsxs("div",{className:"p-2 rounded-md bg-muted/50 border text-center",children:[e.jsx("p",{className:u("text-lg font-bold",t&&b),children:as(s.tokens)}),e.jsx("p",{className:"text-[10px] text-muted-foreground uppercase tracking-wider",children:a("analyticsModelDetail.totalTokens")})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h5",{className:"text-[11px] font-medium text-muted-foreground uppercase tracking-wider",children:a("analyticsModelDetail.tokenBreakdown")}),e.jsxs("div",{className:u("space-y-1",t&&b),children:[e.jsx(Q,{label:a("analyticsToken.input"),tokens:s.inputTokens,cost:s.costBreakdown.input.cost,color:"#335c67",icon:ce}),e.jsx(Q,{label:a("analyticsToken.output"),tokens:s.outputTokens,cost:s.costBreakdown.output.cost,color:"#fff3b0",icon:de}),e.jsx(Q,{label:a("analyticsToken.cacheWrite"),tokens:s.cacheCreationTokens,cost:s.costBreakdown.cacheCreation.cost,color:"#e09f3e",icon:E}),e.jsx(Q,{label:a("analyticsToken.cacheRead"),tokens:s.cacheReadTokens,cost:s.costBreakdown.cacheRead.cost,color:"#9e2a2b",icon:E})]})]}),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($e,{className:"h-3.5 w-3.5 text-muted-foreground"}),e.jsx("span",{className:"text-xs font-medium",children:a("analyticsModelDetail.ioRatioTitle")})]}),e.jsx("p",{className:"text-[11px] text-muted-foreground leading-snug",children:n.description})]})]})}function Q({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:ts(t)})]})]})]})}function ss(s,t){return s>=200?{variant:"destructive",description:t("analyticsModelDetail.ioDescHigh")}:s>=50?{variant:"secondary",description:t("analyticsModelDetail.ioDescMedHigh")}:s>=5?{variant:"outline",description:t("analyticsModelDetail.ioDescBalanced")}:{variant:"default",description:t("analyticsModelDetail.ioDescHighOutput")}}function ts(s){return s.toLocaleString()}function as(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 ns="/api";function S(s){const t=s.getFullYear(),a=String(s.getMonth()+1).padStart(2,"0"),n=String(s.getDate()).padStart(2,"0");return`${t}${a}${n}`}const $={summary:s=>{const t=new URLSearchParams;return s?.startDate&&t.append("since",S(s.startDate)),s?.endDate&&t.append("until",S(s.endDate)),s?.profile&&t.append("profile",s.profile),R(`/usage/summary?${t}`)},trends:s=>{const t=new URLSearchParams;return s?.startDate&&t.append("since",S(s.startDate)),s?.endDate&&t.append("until",S(s.endDate)),s?.profile&&t.append("profile",s.profile),R(`/usage/daily?${t}`)},hourly:s=>{const t=new URLSearchParams;return s?.startDate&&t.append("since",S(s.startDate)),s?.endDate&&t.append("until",S(s.endDate)),R(`/usage/hourly?${t}`)},models:s=>{const t=new URLSearchParams;return s?.startDate&&t.append("since",S(s.startDate)),s?.endDate&&t.append("until",S(s.endDate)),s?.profile&&t.append("profile",s.profile),R(`/usage/models?${t}`)},sessions:s=>{const t=new URLSearchParams;return s?.startDate&&t.append("since",S(s.startDate)),s?.endDate&&t.append("until",S(s.endDate)),s?.profile&&t.append("profile",s.profile),s?.limit&&t.append("limit",s.limit.toString()),s?.offset&&t.append("offset",s.offset.toString()),R(`/usage/sessions?${t}`)},monthly:(s,t)=>{const a=new URLSearchParams;return s&&a.append("months",s.toString()),t&&a.append("profile",t),R(`/usage/monthly?${a}`)},refresh:async()=>{if(!(await fetch(`${ns}/usage/refresh`,{method:"POST",headers:{"Content-Type":"application/json"}})).ok)throw new Error("Failed to refresh usage cache")},status:()=>R("/usage/status"),insights:s=>{const t=new URLSearchParams;return s?.startDate&&t.append("since",S(s.startDate)),s?.endDate&&t.append("until",S(s.endDate)),s?.profile&&t.append("profile",s.profile),R(`/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/data",{method:"DELETE"});if(!s.ok)throw new Error("Failed to clear Cursor data");return(await s.json()).data}};async function R(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 rs(s){return M({queryKey:["usage","summary",s],queryFn:()=>$.summary(s),staleTime:60*1e3})}function ls(s){return M({queryKey:["usage","trends",s],queryFn:()=>$.trends(s),staleTime:60*1e3})}function os(s){return M({queryKey:["usage","hourly",s],queryFn:()=>$.hourly(s),staleTime:60*1e3})}function is(s){return M({queryKey:["usage","models",s],queryFn:()=>$.models(s),staleTime:60*1e3})}function cs(){const s=G();return h.useCallback(async()=>{await $.refresh(),await s.invalidateQueries({queryKey:["usage"]})},[s])}function ds(){return M({queryKey:["usage","status"],queryFn:()=>$.status(),staleTime:10*1e3,refetchInterval:30*1e3})}function us(s){return M({queryKey:["usage","sessions",s],queryFn:()=>$.sessions(s),staleTime:60*1e3})}function xs(){const[s,t]=h.useState({from:q(new Date,30),to:new Date}),[a,n]=h.useState(!1),[l,c]=h.useState(null),[i,r]=h.useState(null),[o,x]=h.useState("daily"),m=cs(),p=h.useCallback(async()=>{n(!0);try{await m()}finally{n(!1)}},[m]),g=h.useMemo(()=>({startDate:s?.from,endDate:s?.to}),[s?.from,s?.to]),{data:k,isLoading:w}=rs(g),{data:d,isLoading:f}=ls(g),{data:N,isLoading:v}=os(g),{data:y,isLoading:I}=is(g),{data:z,isLoading:O}=us({...g,limit:3}),{data:H}=ds(),fe=h.useCallback(()=>{const A=new Date;t({from:q(A,1),to:A}),x("hourly")},[]),he=h.useCallback(A=>{t(A),x("daily")},[]),pe=h.useMemo(()=>H?.lastFetch?X(new Date(H.lastFetch),{addSuffix:!0}):null,[H?.lastFetch]),ge=h.useCallback((A,je)=>{const _=je.currentTarget.getBoundingClientRect();r({x:_.left+_.width/2,y:_.top+_.height/2}),c(A)},[]),ye=h.useCallback(()=>{c(null),r(null)},[]);return{dateRange:s,isRefreshing:a,viewMode:o,selectedModel:l,popoverPosition:i,summary:k,trends:d,hourlyData:N,models:y,sessions:z,status:H,isSummaryLoading:w,isTrendsLoading:f,isHourlyLoading:v,isModelsLoading:I,isSessionsLoading:O,isLoading:w||f||I||O,handleRefresh:p,handleTodayClick:fe,handleDateRangeChange:he,handleModelClick:ge,handlePopoverClose:ye,lastUpdatedText:pe}}function ms({value:s,onChange:t,presets:a=[{label:"Last 7 days",range:{from:q(new Date,7),to:new Date}},{label:"Last 30 days",range:{from:q(new Date,30),to:new Date}},{label:"Last 90 days",range:{from:q(new Date,90),to:new Date}}],className:n}){const[l,c]=Ne.useState(!1),i=r=>!s||!s.from||!s.to||!r.from||!r.to?!1:T(s.from,"yyyy-MM-dd")===T(r.from,"yyyy-MM-dd")&&T(s.to,"yyyy-MM-dd")===T(r.to,"yyyy-MM-dd");return e.jsxs("div",{className:u("flex flex-wrap items-center gap-2",n),children:[a.map(r=>e.jsx(B,{variant:i(r.range)?"default":"outline",size:"sm",onClick:()=>t(r.range),children:r.label},r.label)),e.jsxs(re,{open:l,onOpenChange:c,children:[e.jsx(we,{asChild:!0,children:e.jsxs(B,{id:"date",variant:"outline",className:u("w-auto min-w-[200px] sm:min-w-[240px] justify-start text-left font-normal",!s&&"text-muted-foreground"),children:[e.jsx(Z,{className:"mr-2 h-4 w-4"}),s?.from?s.to?e.jsxs(e.Fragment,{children:[T(s.from,"LLL dd, y")," - ",T(s.to,"LLL dd, y")]}):T(s.from,"LLL dd, y"):e.jsx("span",{children:"Pick a date"})]})}),e.jsx(le,{className:"w-auto p-0",align:"end",children:e.jsx(ve,{initialFocus:!0,mode:"range",defaultMonth:s?.from,selected:s,onSelect:t,numberOfMonths:2})})]})]})}function fs(){const s=G();return J({mutationFn:t=>$.cursorImport(t),onSuccess:()=>{s.invalidateQueries({queryKey:["usage"]}),s.invalidateQueries({queryKey:["cursor-status"]})}})}function hs(){return M({queryKey:["cursor-status"],queryFn:()=>$.cursorStatus(),staleTime:30*1e3})}function ps(){const s=G();return J({mutationFn:()=>$.cursorDataClear(),onSuccess:()=>{s.invalidateQueries({queryKey:["usage"]}),s.invalidateQueries({queryKey:["cursor-status"]})}})}function gs(){const{t:s}=F(),{privacyMode:t}=P(),a=h.useRef(null),[n,l]=h.useState(!1),[c,i]=h.useState(null),r=fs(),{data:o,isLoading:x}=hs(),m=ps(),p=async d=>{const f=d.target.files?.[0];if(f){i(null);try{await r.mutateAsync(f)}catch(N){i(N instanceof Error?N.message:s("analyticsCursor.errorMessage"))}a.current&&(a.current.value="")}},g=async()=>{if(window.confirm(s("analyticsCursor.clearConfirm")))try{await m.mutateAsync()}catch{i(s("analyticsCursor.errorMessage"))}},k=d=>d>=1e6?`${(d/1e6).toFixed(1)}M`:d.toLocaleString(),w=d=>!d||d.length<8?d:`${d.slice(0,4)}-${d.slice(4,6)}-${d.slice(6,8)}`;return e.jsxs(be,{open:n,onOpenChange:l,children:[e.jsx(ke,{asChild:!0,children:e.jsxs(B,{variant:"outline",size:"sm",className:"gap-2 h-8",children:[e.jsx(E,{className:"w-3.5 h-3.5"}),e.jsx("span",{className:"hidden sm:inline",children:s("analytics.importData")})]})}),e.jsxs(Ce,{className:"sm:max-w-md",children:[e.jsxs(De,{children:[e.jsxs(Se,{className:"flex items-center gap-2",children:[e.jsx(E,{className:"w-4 h-4"}),s("analytics.importData")]}),e.jsx(Me,{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(ie,{className:"w-4 h-4"}),"Cursor IDE"]}),e.jsx("input",{ref:a,type:"file",accept:".csv",className:"hidden",onChange:p}),e.jsx(B,{variant:"outline",size:"sm",className:"w-full",disabled:r.isPending,onClick:()=>a.current?.click(),children:r.isPending?e.jsxs(e.Fragment,{children:[e.jsx(Re,{className:"w-3.5 h-3.5 mr-2 animate-spin"}),s("analyticsCursor.importing")]}):e.jsxs(e.Fragment,{children:[e.jsx(Pe,{className:"w-3.5 h-3.5 mr-2"}),s("analyticsCursor.importButton")]})}),r.isSuccess&&e.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-green-600",children:[e.jsx(Be,{className:"w-3.5 h-3.5 shrink-0"}),e.jsx("span",{children:s("analyticsCursor.successMessage")})]}),c&&e.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-destructive",children:[e.jsx(qe,{className:"w-3.5 h-3.5 shrink-0"}),e.jsx("span",{className:"truncate",children:c})]}),x?null:o?.hasData?e.jsxs("div",{className:"rounded-md border bg-muted/30 p-3 text-xs space-y-1.5",children:[o.dateRange&&e.jsxs("div",{className:"text-muted-foreground",children:[w(o.dateRange.from)," ~ ",w(o.dateRange.to)]}),e.jsxs("div",{className:u(t&&b),children:[k(o.totalTokens)," tokens · ",o.totalEvents," events"]}),o.models.length>0&&e.jsx("div",{className:"text-muted-foreground truncate",children:o.models.join(", ")})]}):e.jsx("p",{className:"text-xs text-muted-foreground",children:s("analyticsCursor.fileHint")}),o?.hasData&&e.jsxs(B,{variant:"ghost",size:"sm",className:"w-full text-xs text-muted-foreground hover:text-destructive",disabled:m.isPending,onClick:g,children:[e.jsx(Ae,{className:"w-3 h-3 mr-1"}),s("analyticsCursor.clearButton")]})]})})]})]})}function ys({dateRange:s,onDateRangeChange:t,onTodayClick:a,onRefresh:n,isRefreshing:l,lastUpdatedText:c,viewMode:i}){const{t:r}=F();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:r("analytics.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:r("analytics.subtitle")})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 xl:justify-end",children:[e.jsx(B,{variant:i==="hourly"?"default":"outline",size:"sm",className:"h-8",onClick:a,children:"24H"}),e.jsx(ms,{className:"flex-wrap",value:s,onChange:t,presets:[{label:"7D",range:{from:q(new Date,7),to:new Date}},{label:"30D",range:{from:q(new Date,30),to:new Date}},{label:r("analytics.month"),range:{from:We(new Date),to:new Date}},{label:r("analytics.allTime"),range:{from:void 0,to:new Date}}]}),c&&e.jsx("span",{className:"text-xs text-muted-foreground whitespace-nowrap",children:r("analytics.updated",{value:c})}),e.jsx(B,{variant:"outline",size:"sm",className:"gap-2 h-8",onClick:n,disabled:l,children:e.jsx(Ke,{className:`w-3.5 h-3.5 ${l?"animate-spin":""}`})}),e.jsx(gs,{})]})]})}function js({data:s,isLoading:t,granularity:a="daily",className:n}){const{privacyMode:l}=P(),c=h.useMemo(()=>!s||s.length===0?[]:s.map(o=>{const x="hour"in o?o.hour:o.date;return{...o,dateFormatted:Ns(x,a),costRounded:Number(o.cost.toFixed(4))}}),[s,a]);if(t)return e.jsx(j,{className:u("h-full w-full",n)});if(!s||s.length===0)return e.jsx("div",{className:u("h-full flex items-center justify-center",n),children:e.jsx("p",{className:"text-muted-foreground",children:a==="hourly"?"No usage data for today":"No usage data available"})});const i=({x:r,y:o,payload:x,isRight:m})=>{const p=m?`$${x.value}`:ne(Number(x.value));return e.jsx("text",{x:r,y:o,dy:4,textAnchor:m?"start":"end",fontSize:12,fill:"currentColor",className:u("fill-muted-foreground",l&&"blur-[4px]"),children:p})};return e.jsx("div",{className:u("w-full h-full",n),children:e.jsx(xe,{width:"100%",height:"100%",children:e.jsxs(Ge,{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(ze,{strokeDasharray:"3 3",className:"stroke-muted"}),e.jsx(Ye,{dataKey:"dateFormatted",tick:{fontSize:12},tickLine:!1,axisLine:{className:"stroke-muted"}}),e.jsx(te,{yAxisId:"left",orientation:"left",tick:r=>e.jsx(i,{...r,isRight:!1}),tickLine:!1,axisLine:{className:"stroke-muted"}}),e.jsx(te,{yAxisId:"right",orientation:"right",tick:r=>e.jsx(i,{...r,isRight:!0}),tickLine:!1,axisLine:{className:"stroke-muted"}}),e.jsx(me,{content:({active:r,payload:o,label:x})=>{if(!r||!o||!o.length)return null;const m=o[0].payload;return e.jsxs("div",{className:"rounded-lg border bg-background p-3 shadow-lg",children:[e.jsx("p",{className:"font-medium mb-2",children:x}),o.map((p,g)=>e.jsxs("p",{className:u("text-sm",l&&b),style:{color:p.color},children:[p.name,":"," ",p.name==="Tokens"?ne(Number(p.value)||0):`$${p.value}`]},g)),"requests"in m&&e.jsxs("p",{className:u("text-sm text-muted-foreground mt-1",l&&b),children:["Requests: ",m.requests]})]})}}),e.jsx(ae,{yAxisId:"left",type:"monotone",dataKey:"tokens",stroke:"#0080FF",strokeWidth:2,fillOpacity:1,fill:"url(#tokenGradient)",name:"Tokens"}),e.jsx(ae,{yAxisId:"right",type:"monotone",dataKey:"costRounded",stroke:"#00C49F",strokeWidth:2,fillOpacity:1,fill:"url(#costGradient)",name:"Cost"})]})})})}function Ns(s,t){if(t==="hourly"){const[n,l]=s.split(" ");if(n&&l){const c=new Date(`${n}T${l}:00Z`);return T(c,"HH:mm")}return s}const a=new Date(s);return t==="monthly"?T(a,"MMM yyyy"):T(a,"MMM dd")}function ne(s){return s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toLocaleString()}function ws({data:s,isLoading:t,className:a}){const{privacyMode:n}=P(),{t:l}=F(),c=h.useMemo(()=>!s||s.length===0?[]:s.map(o=>({name:o.model,value:o.tokens,cost:o.cost,percentage:o.percentage,fill:oe(o.model)})),[s]);if(t)return e.jsx(j,{className:u("h-full min-h-[100px] w-full",a)});if(!s||s.length===0)return e.jsx("div",{className:u("h-full min-h-[100px] flex items-center justify-center",a),children:e.jsx("p",{className:"text-muted-foreground",children:l("analyticsModel.emptyState")})});const i=({active:o,payload:x})=>{if(!o||!x)return null;const m=x;if(!m.length)return null;const p=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:p.name}),e.jsxs("p",{className:u("text-muted-foreground",n&&b),children:[vs(p.value)," (",p.percentage.toFixed(1),"%)"]}),e.jsxs("p",{className:u("text-muted-foreground",n&&b),children:["$",p.cost.toFixed(4)]})]})},r=o=>o.percentage>5?`${o.percentage.toFixed(1)}%`:"";return e.jsx("div",{className:u("w-full h-full min-h-[100px]",a),children:e.jsx(xe,{width:"100%",height:"100%",children:e.jsxs(Ve,{children:[e.jsx(Ze,{data:c,cx:"50%",cy:"50%",labelLine:!1,label:r,innerRadius:50,outerRadius:70,paddingAngle:2,dataKey:"value",children:c.map((o,x)=>e.jsx(Xe,{fill:o.fill,strokeWidth:1},`cell-${x}`))}),e.jsx(me,{content:i})]})})})}function vs(s){return s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toLocaleString()}function bs(s){if(!s)return"";const a=s.replace(/^\/|\/$/g,"").split("/").filter(n=>n.length>0);return a[a.length-1]||""}function ks({data:s,isLoading:t,className:a}){const{privacyMode:n}=P(),{t:l}=F(),c=h.useMemo(()=>{if(!s?.sessions||s.sessions.length===0)return null;const i=s.sessions,r=s.total,o=i.reduce((w,d)=>w+(d.inputTokens+d.outputTokens),0),x=Math.round(o/i.length),p=i.reduce((w,d)=>w+d.cost,0)/i.length,g=i[0],k=g?X(new Date(g.lastActivity),{addSuffix:!0}):"N/A";return{totalSessions:r,avgTokens:x,avgCost:p,lastActive:k,recentSessions:i.slice(0,3)}},[s]);return t?e.jsxs(C,{className:u("flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0",a),children:[e.jsx(L,{className:"px-3 py-2",children:e.jsx(j,{className:"h-5 w-32"})}),e.jsx(D,{className:"px-3 pb-3 pt-0 flex-1",children:e.jsx(j,{className:"h-full w-full"})})]}):c?e.jsxs(C,{className:u("flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0 shadow-sm",a),children:[e.jsx(L,{className:"px-3 py-2",children:e.jsxs(U,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(se,{className:"w-4 h-4"}),l("analyticsSession.title")]})}),e.jsxs(D,{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(Ue,{className:"w-4 h-4"}),e.jsx("span",{className:"text-xl font-bold",children:c.totalSessions})]}),e.jsx("p",{className:"text-[10px] text-muted-foreground uppercase tracking-wider mt-0.5",children:l("analyticsSession.totalSessions")})]}),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:u("text-xl font-bold",n&&b),children:["$",c.avgCost.toFixed(2)]})]}),e.jsx("p",{className:"text-[10px] text-muted-foreground uppercase tracking-wider mt-0.5",children:l("analyticsSession.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(Ee,{className:"w-3 h-3"}),l("analyticsSession.recentActivity")]}),e.jsx("div",{className:"space-y-1.5 max-h-full overflow-y-auto pr-1",children:c.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:bs(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:X(new Date(i.lastActivity),{addSuffix:!0})})]}),e.jsxs("div",{className:u("text-right shrink-0 ml-2",n&&b),children:[e.jsxs("div",{className:"font-mono",children:["$",i.cost.toFixed(2)]}),e.jsxs("div",{className:"text-[10px] text-muted-foreground",children:[Cs(i.inputTokens+i.outputTokens)," toks"]})]})]},i.sessionId))})]})]})]}):e.jsxs(C,{className:u("flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0",a),children:[e.jsx(L,{className:"px-3 py-2",children:e.jsxs(U,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(se,{className:"w-4 h-4"}),l("analyticsSession.title")]})}),e.jsx(D,{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("analyticsSession.emptyState")})})]})}function Cs(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 V(s,t){try{const a=new URLSearchParams,n=r=>{const o=r.getFullYear(),x=String(r.getMonth()+1).padStart(2,"0"),m=String(r.getDate()).padStart(2,"0");return`${o}${x}${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 c=await l.json();return(c.data||c).totalCost||0}catch{return 0}}function Ds(){const s=new Date;return new Date(s.getFullYear(),s.getMonth()+1,0).getDate()}function Ss(){return new Date().getDate()}function Ms(s,t){return t<=0?"N/A":`${(s/t).toFixed(2)}x`}function Ls(s,t){return t<=0?null:s/t}function Fs(){const s=G(),t=M({queryKey:["cost-leverage-config"],queryFn:async()=>{const N=(await Y.config.get()).preferences?.baseline_cost_30d;return typeof N=="number"?N:void 0},staleTime:30*1e3}),a=t.data,n=h.useMemo(()=>new Date,[]),l=h.useMemo(()=>{const d=new Date(n),f=new Date(n);return f.setDate(f.getDate()-6),{start:f,end:d}},[n]),c=h.useMemo(()=>{const d=new Date(n),f=new Date(n);return f.setDate(f.getDate()-29),{start:f,end:d}},[n]),i=h.useMemo(()=>{const d=new Date(n.getFullYear(),n.getMonth(),1),f=new Date(n);return{start:d,end:f}},[n]),r=M({queryKey:["cost-leverage","7d"],queryFn:()=>V(l.start,l.end),staleTime:60*1e3}),o=M({queryKey:["cost-leverage","30d"],queryFn:()=>V(c.start,c.end),staleTime:60*1e3}),x=M({queryKey:["cost-leverage","month"],queryFn:()=>V(i.start,i.end),staleTime:60*1e3}),m=J({mutationFn:async d=>{const f=await Y.config.get(),v={...f.preferences||{}};d==null?delete v.baseline_cost_30d:v.baseline_cost_30d=d;const y=typeof f.version=="number"?f.version:12;return Y.config.update({version:y,preferences:v})},onSuccess:()=>{s.invalidateQueries({queryKey:["cost-leverage-config"]})}}),p=h.useMemo(()=>{const d=Ss(),f=Ds();return[{label:"7d",cost:r.data??0,windowDays:7,scaleDays:7},{label:"30d",cost:o.data??0,windowDays:30,scaleDays:30},{label:"Month",cost:x.data??0,windowDays:d,scaleDays:f}].map(v=>{const y=a?a*v.scaleDays/30:0;return{label:v.label,estimatedCost:v.cost,scaledBaseline:y,ratio:Ls(v.cost,y),ratioDisplay:Ms(v.cost,y),windowDays:v.windowDays}})},[a,r.data,o.data,x.data]),g=h.useCallback(d=>{const f=d.trim();if(f==="")return m.mutate(void 0),{valid:!0};const N=Number(f);return isNaN(N)||N<=0?{valid:!1,error:"invalid"}:(m.mutate(N),{valid:!0})},[m]),k=t.isLoading||r.isLoading&&o.isLoading&&x.isLoading,w=t.error?.message||m.error?.message||null;return{baselineCost:a,windows:p,isLoading:k,isSaving:m.isPending,error:w,saveBaseline:g,cost7d:r.data,cost30d:o.data,costMonth:x.data}}function Ts({className:s,isLoading:t}){const{privacyMode:a}=P(),{t:n}=F(),{baselineCost:l,windows:c,isLoading:i,isSaving:r,error:o,saveBaseline:x}=Fs(),[m,p]=h.useState(l!==void 0?String(l):""),[g,k]=h.useState(null),[w,d]=h.useState(!1);l!==void 0&&!w&&(p(String(l)),d(!0)),l===void 0&&w&&d(!1);const f=h.useCallback(()=>{x(m).valid?(k(null),m.trim()===""&&(p(""),d(!1))):k(n("analyticsCostLeverage.invalidInput"))},[m,x,n]),N=h.useCallback(y=>{y.key==="Enter"&&(y.preventDefault(),f())},[f]),v=l!==void 0&&l>0;return i||t?e.jsxs(C,{className:u("flex flex-col h-full",s),children:[e.jsx(L,{className:"px-3 py-2",children:e.jsx(j,{className:"h-5 w-36"})}),e.jsx(D,{className:"px-3 pb-3 pt-0 flex-1",children:e.jsx(j,{className:"h-full w-full"})})]}):e.jsxs(C,{className:u("flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0 shadow-sm",s),children:[e.jsx(L,{className:"px-3 py-2 shrink-0",children:e.jsxs(U,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(Oe,{className:"w-4 h-4"}),n("analyticsCostLeverage.title")]})}),e.jsxs(D,{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:c.map(y=>e.jsx($s,{window:y,privacyMode:a,t:n},y.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(W,{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(W,{className:"w-3.5 h-3.5 text-muted-foreground shrink-0"}),e.jsx(Le,{type:"text",inputMode:"decimal",value:m,onChange:y=>{p(y.target.value),k(null)},onBlur:f,onKeyDown:N,placeholder:n("analyticsCostLeverage.baselinePlaceholder"),disabled:r,className:u("h-7 text-xs",g&&"border-destructive focus-visible:ring-destructive")}),r&&e.jsx("span",{className:"text-[10px] text-muted-foreground animate-pulse",children:n("analyticsCostLeverage.saving")})]}),g&&e.jsx("p",{className:"text-[10px] text-destructive mt-1",children:g}),o&&e.jsxs("p",{className:"text-[10px] text-destructive mt-1",children:[n("analyticsCostLeverage.saveError"),": ",o]})]})]})]})}function $s({window:s,privacyMode:t,t:a}){const n=s.label==="7d"?"analyticsCostLeverage.window7d":s.label==="30d"?"analyticsCostLeverage.window30d":"analyticsCostLeverage.windowMonth",l=s.label==="7d"?Z:s.label==="30d"?He:Z,c=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",i=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:u("flex items-center gap-2 px-2.5 py-2 rounded-lg border transition-colors",i),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:u("text-xs text-muted-foreground font-mono",t&&b),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(ue,{className:"w-3.5 h-3.5 text-emerald-500"}),e.jsx("span",{className:u("text-lg font-bold tabular-nums min-w-[56px] text-right",c,t&&b),children:s.ratioDisplay})]})]})}function Rs(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 Ps({models:s,isLoading:t,onModelClick:a,privacyMode:n}){const{t:l}=F();return e.jsxs(C,{className:"flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0 shadow-sm lg:col-span-4",children:[e.jsx(L,{className:"px-3 py-2",children:e.jsxs(U,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(W,{className:"w-4 h-4"}),l("analyticsCostModel.title")]})}),e.jsx(D,{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((c,i)=>i.cost-c.cost).map(c=>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(c,i),title:l("analyticsCostModel.clickForDetails"),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:oe(c.model)}}),e.jsx("span",{className:"font-medium truncate group-hover:underline underline-offset-2",children:c.model})]}),e.jsx(Bs,{model:c}),e.jsx("span",{className:u("text-[10px] text-muted-foreground w-14 text-right shrink-0",n&&b),children:Rs(c.tokens)}),e.jsxs("span",{className:u("font-mono font-medium w-16 text-right shrink-0",n&&b),children:["$",c.cost.toFixed(2)]}),e.jsx(_e,{className:"w-3 h-3 opacity-0 group-hover:opacity-50 transition-opacity shrink-0"})]},c.model)),e.jsx(qs,{})]})})]})}function Bs({model:s}){const{t}=F(),a={input:"#335c67",output:"#fff3b0",cacheWrite:"#e09f3e",cacheRead:"#9e2a2b"},n=l=>s.cost>0?l/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:a.input,width:`${n(s.costBreakdown.input.cost)}%`},title:`${t("analyticsToken.input")}: $${s.costBreakdown.input.cost.toFixed(2)}`}),e.jsx("div",{className:"h-full",style:{backgroundColor:a.output,width:`${n(s.costBreakdown.output.cost)}%`},title:`${t("analyticsToken.output")}: $${s.costBreakdown.output.cost.toFixed(2)}`}),e.jsx("div",{className:"h-full",style:{backgroundColor:a.cacheWrite,width:`${n(s.costBreakdown.cacheCreation.cost)}%`},title:`${t("analyticsToken.cacheWrite")}: $${s.costBreakdown.cacheCreation.cost.toFixed(2)}`}),e.jsx("div",{className:"h-full",style:{backgroundColor:a.cacheRead,width:`${n(s.costBreakdown.cacheRead.cost)}%`},title:`${t("analyticsToken.cacheRead")}: $${s.costBreakdown.cacheRead.cost.toFixed(2)}`})]})})}function qs(){const{t:s}=F(),t=[{color:"#335c67",label:s("analyticsToken.input")},{color:"#fff3b0",label:s("analyticsToken.output"),hasBorder:!0},{color:"#e09f3e",label:s("analyticsToken.cacheWrite")},{color:"#9e2a2b",label:s("analyticsToken.cacheRead")}];return e.jsx("div",{className:"flex items-center gap-3 pt-2 px-2 text-[10px] text-muted-foreground border-t mt-2",children:t.map(({color:a,label:n,hasBorder:l})=>e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("div",{className:u("w-2 h-2 rounded-full",l&&"border border-muted-foreground/30"),style:{backgroundColor:a}}),n]},n))})}function As({viewMode:s,trends:t,hourlyData:a,models:n,sessions:l,isTrendsLoading:c,isHourlyLoading:i,isModelsLoading:r,isSessionsLoading:o,isSummaryLoading:x,onModelClick:m}){const{privacyMode:p}=P(),{t:g}=F();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(C,{className:"flex flex-col h-full min-h-[220px] lg:min-h-[240px] overflow-hidden gap-0 py-0 shadow-sm",children:[e.jsx(L,{className:"px-3 py-2 shrink-0",children:e.jsxs(U,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(ue,{className:"w-4 h-4"}),g(s==="hourly"?"analytics.last24Hours":"analytics.usageTrends")]})}),e.jsx(D,{className:"px-3 pb-3 pt-0 flex-1 min-h-0",children:e.jsx(js,{data:s==="hourly"?a||[]:t||[],isLoading:s==="hourly"?i:c,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(Ps,{models:n,isLoading:r,onModelClick:m,privacyMode:p}),e.jsxs(C,{className:"flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0 shadow-sm lg:col-span-2",children:[e.jsx(L,{className:"px-3 py-2",children:e.jsxs(U,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(Qe,{className:"w-4 h-4"}),g("analytics.modelUsage")]})}),e.jsx(D,{className:"px-2 pb-2 pt-0 flex-1 min-h-0 flex items-center justify-center",children:e.jsx(ws,{data:n||[],isLoading:r,className:"h-full w-full"})})]}),e.jsx(ks,{data:l,isLoading:o,className:"lg:col-span-2"}),e.jsx(Ts,{className:"lg:col-span-2"})]})]})}function zs(){return e.jsxs("div",{className:"space-y-4 h-full overflow-hidden",children:[e.jsxs(C,{className:"flex flex-col min-h-[300px]",children:[e.jsx(L,{className:"p-4 pb-2",children:e.jsx(j,{className:"h-4 w-32"})}),e.jsx(D,{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(C,{className:"flex flex-col min-h-[250px]",children:[e.jsx(L,{className:"p-4 pb-2",children:e.jsx(j,{className:"h-4 w-28"})}),e.jsx(D,{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(C,{className:"flex flex-col min-h-[250px]",children:[e.jsx(L,{className:"p-4 pb-2",children:e.jsx(j,{className:"h-4 w-28"})}),e.jsx(D,{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 Ys(){const s=h.useRef(null),{dateRange:t,handleDateRangeChange:a,handleTodayClick:n,handleRefresh:l,isRefreshing:c,lastUpdatedText:i,viewMode:r,summary:o,isSummaryLoading:x,trends:m,hourlyData:p,models:g,sessions:k,isTrendsLoading:w,isHourlyLoading:d,isModelsLoading:f,isSessionsLoading:N,handleModelClick:v,selectedModel:y,popoverPosition:I,handlePopoverClose:z}=xs();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(ys,{dateRange:t,onDateRangeChange:a,onTodayClick:n,onRefresh:l,isRefreshing:c,lastUpdatedText:i,viewMode:r}),e.jsx(Je,{data:o,isLoading:x}),e.jsx(As,{viewMode:r,trends:m,hourlyData:p,models:g,sessions:k,isTrendsLoading:w,isHourlyLoading:d,isModelsLoading:f,isSessionsLoading:N,isSummaryLoading:x,onModelClick:v}),e.jsxs(re,{open:!!y,onOpenChange:O=>!O&&z(),children:[e.jsx(Fe,{asChild:!0,children:e.jsx("div",{ref:s,className:"fixed pointer-events-none",style:{left:I?.x??0,top:I?.y??0,width:1,height:1}})}),e.jsx(le,{className:"w-80 p-3",side:"top",align:"center",children:y&&e.jsx(es,{model:y})})]})]})}export{Ys as AnalyticsPage,zs as AnalyticsSkeleton};
|