@kaitranntt/ccs 8.1.1 → 8.1.2-dev.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (158) hide show
  1. package/dist/channels/official-channels-runtime.js +1 -1
  2. package/dist/channels/official-channels-runtime.js.map +1 -1
  3. package/dist/cliproxy/ai-providers/codex-reasoning-proxy.d.ts.map +1 -1
  4. package/dist/cliproxy/ai-providers/codex-reasoning-proxy.js +88 -11
  5. package/dist/cliproxy/ai-providers/codex-reasoning-proxy.js.map +1 -1
  6. package/dist/cliproxy/auth/auth-types.d.ts +2 -0
  7. package/dist/cliproxy/auth/auth-types.d.ts.map +1 -1
  8. package/dist/cliproxy/auth/oauth-handler.d.ts.map +1 -1
  9. package/dist/cliproxy/auth/oauth-handler.js +12 -6
  10. package/dist/cliproxy/auth/oauth-handler.js.map +1 -1
  11. package/dist/cliproxy/auth/oauth-trace/redactor.d.ts.map +1 -1
  12. package/dist/cliproxy/auth/oauth-trace/redactor.js +1 -0
  13. package/dist/cliproxy/auth/oauth-trace/redactor.js.map +1 -1
  14. package/dist/cliproxy/proxy/proxy-config-resolver.d.ts.map +1 -1
  15. package/dist/cliproxy/proxy/proxy-config-resolver.js +11 -1
  16. package/dist/cliproxy/proxy/proxy-config-resolver.js.map +1 -1
  17. package/dist/cliproxy/proxy/tool-sanitization-proxy.d.ts.map +1 -1
  18. package/dist/cliproxy/proxy/tool-sanitization-proxy.js +160 -8
  19. package/dist/cliproxy/proxy/tool-sanitization-proxy.js.map +1 -1
  20. package/dist/cliproxy/proxy/upstream-response-timeout.d.ts +14 -0
  21. package/dist/cliproxy/proxy/upstream-response-timeout.d.ts.map +1 -0
  22. package/dist/cliproxy/proxy/upstream-response-timeout.js +72 -0
  23. package/dist/cliproxy/proxy/upstream-response-timeout.js.map +1 -0
  24. package/dist/codex-auth/codex-config-symlink.js +21 -4
  25. package/dist/codex-auth/codex-config-symlink.js.map +1 -1
  26. package/dist/commands/config-channels-command.d.ts +1 -4
  27. package/dist/commands/config-channels-command.d.ts.map +1 -1
  28. package/dist/commands/config-channels-command.js +20 -24
  29. package/dist/commands/config-channels-command.js.map +1 -1
  30. package/dist/cursor/cursor-daemon-auth.d.ts +2 -0
  31. package/dist/cursor/cursor-daemon-auth.d.ts.map +1 -0
  32. package/dist/cursor/cursor-daemon-auth.js +49 -0
  33. package/dist/cursor/cursor-daemon-auth.js.map +1 -0
  34. package/dist/cursor/cursor-daemon-entry.d.ts.map +1 -1
  35. package/dist/cursor/cursor-daemon-entry.js +44 -0
  36. package/dist/cursor/cursor-daemon-entry.js.map +1 -1
  37. package/dist/cursor/cursor-daemon.d.ts +2 -1
  38. package/dist/cursor/cursor-daemon.d.ts.map +1 -1
  39. package/dist/cursor/cursor-daemon.js +21 -5
  40. package/dist/cursor/cursor-daemon.js.map +1 -1
  41. package/dist/cursor/cursor-models.d.ts.map +1 -1
  42. package/dist/cursor/cursor-models.js +2 -1
  43. package/dist/cursor/cursor-models.js.map +1 -1
  44. package/dist/cursor/cursor-profile-executor.d.ts +1 -1
  45. package/dist/cursor/cursor-profile-executor.d.ts.map +1 -1
  46. package/dist/cursor/cursor-profile-executor.js +7 -4
  47. package/dist/cursor/cursor-profile-executor.js.map +1 -1
  48. package/dist/cursor/cursor-runtime-probe.d.ts.map +1 -1
  49. package/dist/cursor/cursor-runtime-probe.js +4 -2
  50. package/dist/cursor/cursor-runtime-probe.js.map +1 -1
  51. package/dist/cursor/types.d.ts +1 -0
  52. package/dist/cursor/types.d.ts.map +1 -1
  53. package/dist/dispatcher/profile-resolver.d.ts +16 -0
  54. package/dist/dispatcher/profile-resolver.d.ts.map +1 -1
  55. package/dist/dispatcher/profile-resolver.js +49 -3
  56. package/dist/dispatcher/profile-resolver.js.map +1 -1
  57. package/dist/docker/docker-key-rotation.d.ts +2 -0
  58. package/dist/docker/docker-key-rotation.d.ts.map +1 -1
  59. package/dist/docker/docker-key-rotation.js +9 -1
  60. package/dist/docker/docker-key-rotation.js.map +1 -1
  61. package/dist/glmt/sse-parser.d.ts +1 -0
  62. package/dist/glmt/sse-parser.d.ts.map +1 -1
  63. package/dist/glmt/sse-parser.js +13 -1
  64. package/dist/glmt/sse-parser.js.map +1 -1
  65. package/dist/proxy/server/messages-route.d.ts.map +1 -1
  66. package/dist/proxy/server/messages-route.js +69 -3
  67. package/dist/proxy/server/messages-route.js.map +1 -1
  68. package/dist/proxy/transformers/request-transformer.d.ts.map +1 -1
  69. package/dist/proxy/transformers/request-transformer.js +9 -2
  70. package/dist/proxy/transformers/request-transformer.js.map +1 -1
  71. package/dist/shared/claude-extension-setup.d.ts.map +1 -1
  72. package/dist/shared/claude-extension-setup.js +2 -1
  73. package/dist/shared/claude-extension-setup.js.map +1 -1
  74. package/dist/targets/codex-adapter.js +1 -1
  75. package/dist/targets/codex-adapter.js.map +1 -1
  76. package/dist/ui/assets/{Trans-DyZQZ3e2.js → Trans-BIQ-yfAc.js} +1 -1
  77. package/dist/ui/assets/accounts-bN7DnjXo.js +1 -0
  78. package/dist/ui/assets/{alert-dialog-DWHL-dqd.js → alert-dialog-D0yey0YJ.js} +1 -1
  79. package/dist/ui/assets/api-CEtMc2bM.js +4 -0
  80. package/dist/ui/assets/{auth-section-B4o90dwz.js → auth-section-BHZUn2Hv.js} +1 -1
  81. package/dist/ui/assets/{backups-section-1AsdSIJO.js → backups-section-BNVlJSV3.js} +1 -1
  82. package/dist/ui/assets/{channels-CU4Zdsc_.js → channels-BOB1P4Kt.js} +1 -1
  83. package/dist/ui/assets/{checkbox-CbCKGH8I.js → checkbox-Bt-F3GmI.js} +1 -1
  84. package/dist/ui/assets/claude-extension-AzKgsH0H.js +1 -0
  85. package/dist/ui/assets/cliproxy-C1liaQi8.js +4 -0
  86. package/dist/ui/assets/{cliproxy-ai-providers-Dr4L5NRY.js → cliproxy-ai-providers-CzyaYfYI.js} +6 -6
  87. package/dist/ui/assets/cliproxy-control-panel-DmkEW68l.js +1 -0
  88. package/dist/ui/assets/codex-B2FLnjZI.js +30 -0
  89. package/dist/ui/assets/{confirm-dialog-b5Dahgnk.js → confirm-dialog-CYvBJC0z.js} +1 -1
  90. package/dist/ui/assets/{copilot-B1Ojakbt.js → copilot-Csab21fh.js} +2 -2
  91. package/dist/ui/assets/{cursor-PUtNVPx1.js → cursor-fOpftodW.js} +1 -1
  92. package/dist/ui/assets/{droid-S2gclncb.js → droid-FIcjtOf-.js} +1 -1
  93. package/dist/ui/assets/{globalenv-section-7wKSmNSG.js → globalenv-section-CpIAk36Y.js} +1 -1
  94. package/dist/ui/assets/{health-hMLN_gyw.js → health-D0HvHNud.js} +1 -1
  95. package/dist/ui/assets/{index-Cx0dmbiQ.js → index-BTPa3KEN.js} +1 -1
  96. package/dist/ui/assets/{index-Coc3_ABK.js → index-Cr4G276q.js} +1 -1
  97. package/dist/ui/assets/{index-BWboJia4.js → index-D0VoBTF3.js} +1 -1
  98. package/dist/ui/assets/{index-CxvNNHgE.js → index-D5G9mVmP.js} +1 -1
  99. package/dist/ui/assets/{index-DkR2KVhF.js → index-Dm_QojrJ.js} +1 -1
  100. package/dist/ui/assets/index-G3mgTfgR.css +1 -0
  101. package/dist/ui/assets/index-N35Xkk8N.js +1 -0
  102. package/dist/ui/assets/{index-CcGVqYOy.js → index-sIfjKy42.js} +18 -18
  103. package/dist/ui/assets/{logs-BRFVfyLc.js → logs-B33n-VaM.js} +1 -1
  104. package/dist/ui/assets/{masked-input-4L9CIZGb.js → masked-input-BrUE6z_f.js} +1 -1
  105. package/dist/ui/assets/proxy-status-widget-Dm2ziI5D.js +1 -0
  106. package/dist/ui/assets/{raw-json-settings-editor-panel-DXh8c8rA.js → raw-json-settings-editor-panel-DZRtQXbD.js} +1 -1
  107. package/dist/ui/assets/{searchable-select-CtvEQrMo.js → searchable-select-D2smFEI5.js} +1 -1
  108. package/dist/ui/assets/{separator-E0ISp1SN.js → separator-BvoSJCHW.js} +1 -1
  109. package/dist/ui/assets/{shared-BeYwHeNS.js → shared-qKNFwLmT.js} +2 -2
  110. package/dist/ui/assets/{table-BBslZvNP.js → table-DYyc1gJc.js} +1 -1
  111. package/dist/ui/assets/updates-XXi3TQNZ.js +1 -0
  112. package/dist/ui/assets/{use-accounts-BdalFsdY.js → use-accounts-BR64_yUk.js} +1 -1
  113. package/dist/ui/index.html +2 -2
  114. package/dist/utils/browser/browser-settings.d.ts.map +1 -1
  115. package/dist/utils/browser/browser-settings.js +13 -3
  116. package/dist/utils/browser/browser-settings.js.map +1 -1
  117. package/dist/utils/glmt-deprecation.d.ts.map +1 -1
  118. package/dist/utils/glmt-deprecation.js +1 -3
  119. package/dist/utils/glmt-deprecation.js.map +1 -1
  120. package/dist/web-server/index.d.ts.map +1 -1
  121. package/dist/web-server/index.js +0 -9
  122. package/dist/web-server/index.js.map +1 -1
  123. package/dist/web-server/middleware/auth-middleware.d.ts.map +1 -1
  124. package/dist/web-server/middleware/auth-middleware.js +26 -4
  125. package/dist/web-server/middleware/auth-middleware.js.map +1 -1
  126. package/dist/web-server/routes/cliproxy-auth-routes.d.ts +10 -0
  127. package/dist/web-server/routes/cliproxy-auth-routes.d.ts.map +1 -1
  128. package/dist/web-server/routes/cliproxy-auth-routes.js +45 -13
  129. package/dist/web-server/routes/cliproxy-auth-routes.js.map +1 -1
  130. package/dist/web-server/routes/cliproxy-local-proxy.d.ts.map +1 -1
  131. package/dist/web-server/routes/cliproxy-local-proxy.js +25 -8
  132. package/dist/web-server/routes/cliproxy-local-proxy.js.map +1 -1
  133. package/dist/web-server/routes/cursor-routes.d.ts.map +1 -1
  134. package/dist/web-server/routes/cursor-routes.js +6 -1
  135. package/dist/web-server/routes/cursor-routes.js.map +1 -1
  136. package/dist/web-server/routes/image-analysis-routes.d.ts.map +1 -1
  137. package/dist/web-server/routes/image-analysis-routes.js +7 -0
  138. package/dist/web-server/routes/image-analysis-routes.js.map +1 -1
  139. package/dist/web-server/routes/settings-routes.d.ts.map +1 -1
  140. package/dist/web-server/routes/settings-routes.js +10 -1
  141. package/dist/web-server/routes/settings-routes.js.map +1 -1
  142. package/dist/web-server/services/claude-extension-settings-service.d.ts.map +1 -1
  143. package/dist/web-server/services/claude-extension-settings-service.js +5 -1
  144. package/dist/web-server/services/claude-extension-settings-service.js.map +1 -1
  145. package/lib/mcp/ccs-browser-server.cjs +24 -13
  146. package/package.json +1 -1
  147. package/scripts/github/stable-release-issue-cleanup-lib.mjs +113 -0
  148. package/scripts/github/stable-release-issue-cleanup.mjs +134 -0
  149. package/dist/ui/assets/accounts-BPJltru3.js +0 -1
  150. package/dist/ui/assets/api-BxPN-zy4.js +0 -4
  151. package/dist/ui/assets/claude-extension-CWpjmIGt.js +0 -1
  152. package/dist/ui/assets/cliproxy-K6eBb5VO.js +0 -4
  153. package/dist/ui/assets/cliproxy-control-panel-Cz5r7kHP.js +0 -1
  154. package/dist/ui/assets/codex-0HdbW8NR.js +0 -30
  155. package/dist/ui/assets/index-BMoGhs28.css +0 -1
  156. package/dist/ui/assets/index-COt1pbk-.js +0 -1
  157. package/dist/ui/assets/proxy-status-widget-s1UWOE23.js +0 -1
  158. package/dist/ui/assets/updates-CDrm903n.js +0 -1
@@ -0,0 +1 @@
1
+ import{j as e}from"./radix-ui-nu4wz29m.js";import{r as f,E as Te}from"./react-vendor-Bjx91N7w.js";import{u as U,a as P,C as N,b,S as p,c as x,P as k,B as _,d as Le,e as X,f as de,g as $e,h as ue,i as Re,j as Pe,k as Fe,l as Me,m as De,n as Ae,T as Be,o as Ie,p as Oe,q as Ue,r as xe,s as v,t as R,v as qe,w as Ee,x as Ke,y as _e}from"./index-sIfjKy42.js";import{a3 as We,am as me,an as se,ao as he,a1 as fe,aa as Ge,G as He,ap as ze,_ as Ve,R as Ye,$ as ne,U as Qe,Z as pe,v as Ze,ae as Q,aq as Xe,Y as Je,C as es,ar as ss,as as ts}from"./icons-DzKUh8vG.js";import{a as as,u as q}from"./tanstack-bhJxV1h8.js";import{u as ns}from"./use-accounts-BR64_yUk.js";import{K as B,f as L,H as rs,L as ls}from"./utils-CzKF5WmX.js";import{R as ge,A as os,C as is,X as cs,Y as re,T as je,b as le,P as ds,c as us,d as xs}from"./charts-eIPy2oG6.js";import"./notifications-B4_o8bcr.js";import"./form-utils-CuHzLhJZ.js";function ms({data:s,isLoading:t}){const{privacyMode:a}=U(),{t:n}=P(),i=s?.totalTokens??0,r=s?.totalInputTokens??0,o=s?.totalOutputTokens??0,u=s?.totalCacheTokens??0,l=r+o;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(h=>e.jsx(N,{children:e.jsx(b,{className:"p-6",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(p,{className:"h-4 w-[100px]"}),e.jsx(p,{className:"h-8 w-[80px]"})]}),e.jsx(p,{className:"h-8 w-8 rounded-lg"})]})})},h))});const c=(s?.tokenBreakdown?.cacheCreation?.cost??0)+(s?.tokenBreakdown?.cacheRead?.cost??0),m=s?.totalCost?Math.round(c/s.totalCost*100):0,d=u>0&&i>l,g=u>0&&!d?"Total Tokens (I/O)":n("analyticsSummary.totalTokens"),S=d?`${$(r)} in / ${$(o)} out / ${$(u)} cache`:n("analyticsSummary.totalTokensSubtitle",{input:$(r),output:$(o)}),C=[{title:g,value:i,icon:We,format:h=>$(h),color:"text-blue-600",bgColor:"bg-blue-100 dark:bg-blue-900/20",subtitle:S},{title:n("analyticsSummary.totalCost"),value:s?.totalCost??0,icon:me,format:h=>`$${h.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:se,format:h=>$(h),color:"text-cyan-600",bgColor:"bg-cyan-100 dark:bg-cyan-900/20",subtitle:n("analyticsSummary.cacheTokensSubtitle",{cost:c.toFixed(2),percent:m})},{title:n("analyticsSummary.inputCost"),value:s?.tokenBreakdown?.input?.cost??0,icon:he,format:h=>`$${h.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:fe,format:h=>`$${h.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:C.map((h,y)=>{const T=h.icon;return e.jsx(N,{className:"hover:shadow-md transition-shadow",children:e.jsx(b,{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:h.title}),e.jsx("p",{className:x("text-xl font-bold truncate",a&&k),children:h.format(h.value)}),h.subtitle&&e.jsx("p",{className:x("text-[10px] text-muted-foreground truncate",a&&k),children:h.subtitle})]}),e.jsx("div",{className:x("p-2 rounded-lg shrink-0",h.bgColor),children:e.jsx(T,{className:x("h-4 w-4",h.color)})})]})})},y)})})}function $(s){return s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toLocaleString()}function hs({model:s}){const{privacyMode:t}=U(),{t:a}=P(),n=fs(s.ioRatio),r=s.cacheCreationTokens+s.cacheReadTokens>0?"All Tokens":a("analyticsCards.totalTokens");return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ge,{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(_,{variant:"secondary",className:"text-[10px] h-5 px-1.5",children:[s.percentage.toFixed(1),"% usage"]}),e.jsxs(_,{variant:n.variant,className:"text-[10px] h-5 px-1.5",children:[s.ioRatio.toFixed(0),":1 I/O"]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("div",{className:"p-2 rounded-md bg-muted/50 border text-center",children:[e.jsxs("p",{className:x("text-lg font-bold",t&&k),children:["$",s.cost.toFixed(2)]}),e.jsx("p",{className:"text-[10px] text-muted-foreground uppercase tracking-wider",children:a("analyticsCards.totalCost")})]}),e.jsxs("div",{className:"p-2 rounded-md bg-muted/50 border text-center",children:[e.jsx("p",{className:x("text-lg font-bold",t&&k),children:gs(s.tokens)}),e.jsx("p",{className:"text-[10px] text-muted-foreground uppercase tracking-wider",children:r})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h5",{className:"text-[11px] font-medium text-muted-foreground uppercase tracking-wider",children:"Token Breakdown"}),e.jsxs("div",{className:x("space-y-1",t&&k),children:[e.jsx(Z,{label:"Input",tokens:s.inputTokens,cost:s.costBreakdown.input.cost,color:"#335c67",icon:he}),e.jsx(Z,{label:"Output",tokens:s.outputTokens,cost:s.costBreakdown.output.cost,color:"#fff3b0",icon:fe}),e.jsx(Z,{label:"Cache Write",tokens:s.cacheCreationTokens,cost:s.costBreakdown.cacheCreation.cost,color:"#e09f3e",icon:se}),e.jsx(Z,{label:"Cache Read",tokens:s.cacheReadTokens,cost:s.costBreakdown.cacheRead.cost,color:"#9e2a2b",icon:se})]})]}),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(He,{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:i}){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(i,{className:"h-3 w-3 shrink-0"}),e.jsx("span",{children:ps(t)})]})]})]})}function fs(s){return s>=200?{variant:"destructive",description:"Extended thinking or large context loading. Expected for reasoning models."}:s>=50?{variant:"secondary",description:"More input than output. Typical for analysis tasks."}:s>=5?{variant:"outline",description:"Balanced input/output ratio for typical coding tasks."}:{variant:"default",description:"More output than input. Generation-heavy workload."}}function ps(s){return s.toLocaleString()}function gs(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 js="/api";function oe(s){const t=s.getFullYear(),a=String(s.getMonth()+1).padStart(2,"0"),n=String(s.getDate()).padStart(2,"0");return`${t}${a}${n}`}function M(s,t){const a=t.toString();return a?`${s}?${a}`:s}function D(s,t){t?.startDate&&s.append("since",oe(t.startDate)),t?.endDate&&s.append("until",oe(t.endDate))}function A(s,t){t?.profile&&s.append("profile",t.profile)}const I={summary:s=>{const t=new URLSearchParams;return D(t,s),A(t,s),F(M("/usage/summary",t))},trends:s=>{const t=new URLSearchParams;return D(t,s),A(t,s),F(M("/usage/daily",t))},hourly:s=>{const t=new URLSearchParams;return D(t,s),A(t,s),F(M("/usage/hourly",t))},models:s=>{const t=new URLSearchParams;return D(t,s),A(t,s),F(M("/usage/models",t))},sessions:s=>{const t=new URLSearchParams;return D(t,s),s?.limit&&t.append("limit",s.limit.toString()),s?.offset&&t.append("offset",s.offset.toString()),A(t,s),F(M("/usage/sessions",t))},monthly:s=>{const t=new URLSearchParams;return D(t,s),A(t,s),F(M("/usage/monthly",t))},refresh:async()=>{if(!(await fetch(`${js}/usage/refresh`,{method:"POST",headers:{"Content-Type":"application/json"}})).ok)throw new Error("Failed to refresh usage cache")},status:()=>F("/usage/status"),insights:s=>{const t=new URLSearchParams;return D(t,s),A(t,s),F(M("/usage/insights",t))}};async function F(s){const a=await fetch(`/api${s}`,{headers:{"Content-Type":"application/json"}});if(!a.ok){const i=await a.json().catch(()=>({error:"Unknown error"}));throw new Error(i.error||a.statusText)}const n=await a.json();return n.data||n}function ys(s){return q({queryKey:["usage","summary",s],queryFn:()=>I.summary(s),staleTime:60*1e3})}function Ns(s){return q({queryKey:["usage","trends",s],queryFn:()=>I.trends(s),staleTime:60*1e3})}function bs(s){return q({queryKey:["usage","hourly",s],queryFn:()=>I.hourly(s),staleTime:60*1e3})}function ws(s){return q({queryKey:["usage","models",s],queryFn:()=>I.models(s),staleTime:60*1e3})}function vs(){const s=as();return f.useCallback(async()=>{await I.refresh(),await s.invalidateQueries({queryKey:["usage"]})},[s])}function ks(){return q({queryKey:["usage","status"],queryFn:()=>I.status(),staleTime:10*1e3,refetchInterval:30*1e3})}function Cs(s){return q({queryKey:["usage","sessions",s],queryFn:()=>I.sessions(s),staleTime:60*1e3})}function Ss(s){const t=Math.max(1,Math.floor((Date.now()-s.getTime())/1e3));if(t<60)return`${t}s ago`;const a=Math.floor(t/60);if(a<60)return`${a}m ago`;const n=Math.floor(a/60);return n<24?`${n}h ago`:`${Math.floor(n/24)}d ago`}const Ts=50,te="ccs.analytics.selectedProfile",W="all";function Ls(){if(typeof globalThis.localStorage>"u")return W;const s=globalThis.localStorage.getItem(te);return!s||s.startsWith("unsupported:")?W:s}function $s(s){if(!(typeof globalThis.localStorage>"u")){if(s===W){globalThis.localStorage.removeItem(te);return}globalThis.localStorage.setItem(te,s)}}function Rs(){const[s,t]=f.useState({from:B(new Date,30),to:new Date}),[a,n]=f.useState(!1),[i,r]=f.useState(null),[o,u]=f.useState(Ls),[l,c]=f.useState(null),[m,d]=f.useState("daily"),{data:g}=ns(),{data:S}=Le(),C=vs(),h=f.useCallback(async()=>{n(!0);try{await C()}finally{n(!1)}},[C]),y=f.useMemo(()=>({startDate:s?.from,endDate:s?.to,profile:o===W?void 0:o}),[s?.from,s?.to,o]),T=f.useMemo(()=>{const w=new Set(g?.accounts.map(j=>j.name)??[]),Y=[{value:W,label:"All profiles",description:"Includes all analytics sources.",supported:!0},{value:"default",label:"Default Claude",description:"Profile-scoped Claude JSONL data.",supported:!0},...Array.from(w).sort((j,Se)=>j.localeCompare(Se)).map(j=>({value:j,label:j,description:"Profile-scoped account data.",supported:!0}))];for(const j of S?.profiles??[])w.has(j.name)||j.name==="default"||Y.push({value:`unsupported:${j.name}`,label:j.name,description:"API profile usage is not yet attributed by stable profile.",supported:!1});return Y},[g?.accounts,S?.profiles]),{data:E,isLoading:O}=ys(y),{data:J,isLoading:G}=Ns(y),{data:K,isLoading:H}=bs(y),{data:ee,isLoading:z}=ws(y),{data:ye,isLoading:ae}=Cs({...y,limit:Ts}),{data:V}=ks(),Ne=f.useCallback(()=>{const w=new Date;t({from:B(w,1),to:w}),d("hourly")},[]),be=f.useCallback(w=>{t(w),d("daily")},[]),we=f.useCallback(w=>{w.startsWith("unsupported:")||(u(w),$s(w))},[]),ve=f.useMemo(()=>V?.lastFetch?Ss(new Date(V.lastFetch)):null,[V?.lastFetch]),ke=f.useCallback((w,Y)=>{const j=Y.currentTarget.getBoundingClientRect();c({x:j.left+j.width/2,y:j.top+j.height/2}),r(w)},[]),Ce=f.useCallback(()=>{r(null),c(null)},[]);return{dateRange:s,isRefreshing:a,viewMode:m,selectedProfile:o,profileOptions:T,selectedModel:i,popoverPosition:l,summary:E,trends:J,hourlyData:K,models:ee,sessions:ye,status:V,isSummaryLoading:O,isTrendsLoading:G,isHourlyLoading:H,isModelsLoading:z,isSessionsLoading:ae,isLoading:O||G||z||ae,handleRefresh:h,handleTodayClick:Ne,handleDateRangeChange:be,handleProfileChange:we,handleModelClick:ke,handlePopoverClose:Ce,lastUpdatedText:ve}}function Ps({value:s,onChange:t,presets:a=[{label:"Last 7 days",range:{from:B(new Date,7),to:new Date}},{label:"Last 30 days",range:{from:B(new Date,30),to:new Date}},{label:"Last 90 days",range:{from:B(new Date,90),to:new Date}}],className:n}){const[i,r]=Te.useState(!1),{t:o}=P(),u=l=>!s||!s.from||!s.to||!l.from||!l.to?!1:L(s.from,"yyyy-MM-dd")===L(l.from,"yyyy-MM-dd")&&L(s.to,"yyyy-MM-dd")===L(l.to,"yyyy-MM-dd");return e.jsxs("div",{className:x("flex flex-wrap items-center gap-2",n),children:[a.map(l=>e.jsx(X,{variant:u(l.range)?"default":"outline",size:"sm",onClick:()=>t(l.range),children:l.label},l.label)),e.jsxs(de,{open:i,onOpenChange:r,children:[e.jsx($e,{asChild:!0,children:e.jsxs(X,{id:"date",variant:"outline",className:x("w-auto min-w-[200px] sm:min-w-[240px] justify-start text-left font-normal",!s&&"text-muted-foreground"),children:[e.jsx(ze,{className:"mr-2 h-4 w-4"}),s?.from?s.to?e.jsxs(e.Fragment,{children:[L(s.from,"LLL dd, y")," - ",L(s.to,"LLL dd, y")]}):L(s.from,"LLL dd, y"):e.jsx("span",{children:o("dateRangeFilter.pickADate")})]})}),e.jsx(ue,{className:"w-auto p-0",align:"end",children:e.jsx(Re,{initialFocus:!0,mode:"range",defaultMonth:s?.from,selected:s,onSelect:t,numberOfMonths:2})})]})]})}function Fs({dateRange:s,onDateRangeChange:t,onTodayClick:a,onRefresh:n,isRefreshing:i,lastUpdatedText:r,viewMode:o,selectedProfile:u,profileOptions:l,onProfileChange:c}){const{t:m}=P();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("div",{className:"inline-flex items-center gap-1 shrink-0",children:[e.jsxs(Pe,{value:u,onValueChange:c,children:[e.jsx(Fe,{className:"h-8 w-[170px]","aria-label":"Analytics profile",children:e.jsx(Me,{placeholder:"All profiles",children:l.find(d=>d.value===u)?.label??"All profiles"})}),e.jsx(De,{children:l.map(d=>e.jsx(Ae,{value:d.value,disabled:!d.supported,children:e.jsxs("span",{className:"flex flex-col",children:[e.jsx("span",{children:d.label}),e.jsx("span",{className:"text-xs text-muted-foreground",children:d.description})]})},d.value))})]}),u!=="all"&&e.jsx(Be,{delayDuration:150,children:e.jsxs(Ie,{children:[e.jsx(Oe,{asChild:!0,children:e.jsx("button",{type:"button","aria-label":"Selected-profile analytics scope",className:"inline-flex size-7 items-center justify-center rounded-md text-muted-foreground hover:bg-accent hover:text-foreground",children:e.jsx(Ve,{className:"size-4","aria-hidden":"true"})})}),e.jsx(Ue,{side:"bottom",align:"start",className:"max-w-xs text-xs",children:"Selected-profile analytics include only default/account data with stable profile attribution. CLIProxy and native runtime snapshots remain in All profiles."})]})})]}),e.jsx(X,{variant:o==="hourly"?"default":"outline",size:"sm",className:"h-8",onClick:a,children:"24H"}),e.jsx(Ps,{className:"flex-wrap",value:s,onChange:t,presets:[{label:"7D",range:{from:B(new Date,7),to:new Date}},{label:"30D",range:{from:B(new Date,30),to:new Date}},{label:m("analytics.month"),range:{from:rs(new Date),to:new Date}},{label:m("analytics.allTime"),range:{from:void 0,to:new Date}}]}),r&&e.jsx("span",{className:"text-xs text-muted-foreground whitespace-nowrap font-mono",title:m("analytics.updated",{value:r}),children:r}),e.jsx(X,{variant:"outline",size:"sm",className:"gap-2 h-8",onClick:n,disabled:i,children:e.jsx(Ye,{className:`w-3.5 h-3.5 ${i?"animate-spin":""}`})})]})]})}function Ms({data:s,isLoading:t,granularity:a="daily",className:n}){const{privacyMode:i}=U(),{t:r}=P(),o=f.useMemo(()=>!s||s.length===0?[]:s.map(c=>{const m="hour"in c?c.hour:c.date;return{...c,dateFormatted:Ds(m,a),costRounded:Number(c.cost.toFixed(4))}}),[s,a]);if(t)return e.jsx(p,{className:x("h-full w-full",n)});if(!s||s.length===0)return e.jsx("div",{className:x("h-full flex items-center justify-center",n),children:e.jsx("p",{className:"text-muted-foreground",children:r(a==="hourly"?"analytics.noDailyUsage":"analytics.noUsageData")})});const u=({x:l,y:c,payload:m,isRight:d})=>{const g=d?`$${m.value}`:ie(Number(m.value));return e.jsx("text",{x:l,y:c,dy:4,textAnchor:d?"start":"end",fontSize:12,fill:"currentColor",className:x("fill-muted-foreground",i&&"blur-[4px]"),children:g})};return e.jsx("div",{className:x("w-full h-full",n),children:e.jsx(ge,{width:"100%",height:"100%",children:e.jsxs(os,{data:o,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(is,{strokeDasharray:"3 3",className:"stroke-muted"}),e.jsx(cs,{dataKey:"dateFormatted",tick:{fontSize:12},tickLine:!1,axisLine:{className:"stroke-muted"}}),e.jsx(re,{yAxisId:"left",orientation:"left",tick:l=>e.jsx(u,{...l,isRight:!1}),tickLine:!1,axisLine:{className:"stroke-muted"}}),e.jsx(re,{yAxisId:"right",orientation:"right",tick:l=>e.jsx(u,{...l,isRight:!0}),tickLine:!1,axisLine:{className:"stroke-muted"}}),e.jsx(je,{content:({active:l,payload:c,label:m})=>!l||!c||!c.length?null:e.jsxs("div",{className:"rounded-lg border bg-background p-3 shadow-lg",children:[e.jsx("p",{className:"font-medium mb-2",children:m}),c.map((d,g)=>e.jsxs("p",{className:x("text-sm",i&&k),style:{color:d.color},children:[d.name,":"," ",d.name==="Tokens"?ie(Number(d.value)||0):`$${d.value}`]},g))]})}),e.jsx(le,{yAxisId:"left",type:"monotone",dataKey:"tokens",stroke:"#0080FF",strokeWidth:2,fillOpacity:1,fill:"url(#tokenGradient)",name:"Tokens"}),e.jsx(le,{yAxisId:"right",type:"monotone",dataKey:"costRounded",stroke:"#00C49F",strokeWidth:2,fillOpacity:1,fill:"url(#costGradient)",name:"Cost"})]})})})}function Ds(s,t){if(t==="hourly"){const[n,i]=s.split(" ");if(n&&i){const r=new Date(`${n}T${i}:00Z`);return L(r,"HH:mm")}return s}const a=new Date(s);return t==="monthly"?L(a,"MMM yyyy"):L(a,"MMM dd")}function ie(s){return s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toLocaleString()}function As({data:s,isLoading:t,className:a}){const{privacyMode:n}=U(),{t:i}=P(),r=f.useMemo(()=>!s||s.length===0?[]:s.map(l=>({name:l.model,value:l.tokens,cost:l.cost,percentage:l.percentage,fill:xe(l.model)})),[s]);if(t)return e.jsx(p,{className:x("h-full min-h-[100px] w-full",a)});if(!s||s.length===0)return e.jsx("div",{className:x("h-full min-h-[100px] flex items-center justify-center",a),children:e.jsx("p",{className:"text-muted-foreground",children:i("analyticsCards.noModelData")})});const o=({active:l,payload:c})=>{if(!l||!c)return null;const m=c;if(!m.length)return null;const d=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:d.name}),e.jsxs("p",{className:x("text-muted-foreground",n&&k),children:[Bs(d.value)," (",d.percentage.toFixed(1),"%)"]}),e.jsxs("p",{className:x("text-muted-foreground",n&&k),children:["$",d.cost.toFixed(4)]})]})},u=l=>l.percentage>5?`${l.percentage.toFixed(1)}%`:"";return e.jsx("div",{className:x("w-full h-full min-h-[100px]",a),children:e.jsx(ge,{width:"100%",height:"100%",children:e.jsxs(ds,{children:[e.jsx(us,{data:r,cx:"50%",cy:"50%",labelLine:!1,label:u,innerRadius:50,outerRadius:70,paddingAngle:2,dataKey:"value",children:r.map((l,c)=>e.jsx(xs,{fill:l.fill,strokeWidth:1},`cell-${c}`))}),e.jsx(je,{content:o})]})})})}function Bs(s){return s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toLocaleString()}function Is(s){if(!s)return"";const a=s.replace(/^\/|\/$/g,"").split("/").filter(n=>n.length>0);return a[a.length-1]||""}function Os({data:s,isLoading:t,className:a}){const{privacyMode:n}=U(),{t:i}=P(),r=f.useMemo(()=>{if(!s?.sessions||s.sessions.length===0)return null;const o=s.sessions,u=s.total,l=o.length,c=s.hasMore||s.offset>0,d=o.reduce((g,S)=>g+S.cost,0)/o.length;return{displayedSessions:c?l:u,totalSessions:u,avgCost:d,hasPartialSample:c,recentSessions:o.slice(0,3)}},[s]);return t?e.jsxs(N,{className:x("flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0",a),children:[e.jsx(v,{className:"px-3 py-2",children:e.jsx(p,{className:"h-5 w-32"})}),e.jsx(b,{className:"px-3 pb-3 pt-0 flex-1",children:e.jsx(p,{className:"h-full w-full"})})]}):r?e.jsxs(N,{className:x("flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0 shadow-sm",a),children:[e.jsx(v,{className:"px-3 py-2",children:e.jsxs(R,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(ne,{className:"w-4 h-4"}),"Session Stats"]})}),e.jsxs(b,{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(Qe,{className:"w-4 h-4"}),e.jsx("span",{className:"text-xl font-bold",children:r.displayedSessions})]}),e.jsx("p",{className:"text-[10px] text-muted-foreground uppercase tracking-wider mt-0.5",children:r.hasPartialSample?"Sampled Sessions":"Total Sessions"}),r.hasPartialSample&&e.jsxs("p",{className:"text-[10px] text-muted-foreground mt-0.5",children:[r.totalSessions," total"]})]}),e.jsxs("div",{className:"p-2 rounded-md bg-muted/50 border text-center",children:[e.jsxs("div",{className:"flex items-center justify-center gap-1.5 text-green-600 dark:text-green-400",children:[e.jsx(pe,{className:"w-4 h-4"}),e.jsxs("span",{className:x("text-xl font-bold",n&&k),children:["$",r.avgCost.toFixed(2)]})]}),e.jsx("p",{className:"text-[10px] text-muted-foreground uppercase tracking-wider mt-0.5",children:r.hasPartialSample?"Recent Avg Cost":"Avg Cost/Session"})]})]}),e.jsxs("div",{className:"flex-1 min-h-0 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-1 text-xs text-muted-foreground font-medium mb-1",children:[e.jsx(Ze,{className:"w-3 h-3"}),"Recent Activity"]}),e.jsx("div",{className:"space-y-1.5 max-h-full overflow-y-auto pr-1",children:r.recentSessions.map(o=>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:o.projectPath,children:Is(o.projectPath)}),(o.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:o.target})]}),e.jsx("span",{className:"text-[10px] text-muted-foreground",children:ls(new Date(o.lastActivity),{addSuffix:!0})})]}),e.jsxs("div",{className:x("text-right shrink-0 ml-2",n&&k),children:[e.jsxs("div",{className:"font-mono",children:["$",o.cost.toFixed(2)]}),e.jsxs("div",{className:"text-[10px] text-muted-foreground",children:[Us(o.tokens??o.inputTokens+o.outputTokens)," ","toks"]})]})]},o.sessionId))})]})]})]}):e.jsxs(N,{className:x("flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0",a),children:[e.jsx(v,{className:"px-3 py-2",children:e.jsxs(R,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(ne,{className:"w-4 h-4"}),"Session Stats"]})}),e.jsx(b,{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:i("analyticsCards.noSessionData")})})]})}function Us(s){return s>=1e9?`${(s/1e9).toFixed(1)}B`:s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toString()}function qs({className:s,isLoading:t}){const{data:a,isLoading:n}=qe(),{data:i,isLoading:r,error:o}=Ee(a?.running),{t:u}=P();if(t||n||a?.running&&r)return e.jsxs(N,{className:x("flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0",s),children:[e.jsx(v,{className:"px-3 py-2",children:e.jsxs(R,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(Q,{className:"h-4 w-4"}),"CLIProxy Stats"]})}),e.jsx(b,{className:"px-3 pb-3 pt-0 flex-1",children:e.jsxs("div",{className:"space-y-3",children:[e.jsx(p,{className:"h-4 w-[100px]"}),e.jsx(p,{className:"h-16 w-full"})]})})]});if(!a?.running)return e.jsxs(N,{className:x("flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0 border-dashed",s),children:[e.jsx(v,{className:"px-3 py-2",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(R,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(Q,{className:"h-4 w-4 text-muted-foreground"}),"CLIProxy Stats"]}),e.jsx(_,{variant:"secondary",className:"text-[10px] h-5",children:u("cliproxyStatsOverview.offline")})]})}),e.jsx(b,{className:"px-3 pb-3 pt-0 flex-1 flex items-center justify-center",children:e.jsx("p",{className:"text-xs text-muted-foreground text-center",children:u("cliproxyStatsOverview.noActiveSessionHint")})})]});if(o)return e.jsxs(N,{className:x("flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0 border-destructive/50",s),children:[e.jsx(v,{className:"px-3 py-2",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(R,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(Q,{className:"h-4 w-4"}),"CLIProxy Stats"]}),e.jsx(_,{variant:"destructive",className:"text-[10px] h-5",children:"Error"})]})}),e.jsx(b,{className:"px-3 pb-3 pt-0 flex-1",children:e.jsx("p",{className:"text-xs text-destructive",children:o.message})})]});const c=i?.totalRequests??0,m=i?.quotaExceededCount??0,d=c-m,g=c>0?Math.round(d/c*100):100,S=i?.tokens?.total??0,C=Object.entries(i?.requestsByModel??{}).sort((y,T)=>T[1]-y[1]).slice(0,4),h=C.length>0?C[0][1]:1;return e.jsxs(N,{className:x("flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0",s),children:[e.jsx(v,{className:"px-3 py-2 border-b bg-muted/5",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(R,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(Q,{className:"h-4 w-4"}),"CLIProxy Stats"]}),e.jsxs(_,{variant:"outline",className:"text-[10px] h-5 text-green-600 border-green-200 bg-green-50 dark:bg-green-900/10 dark:border-green-800",children:[e.jsx(pe,{className:"h-3 w-3 mr-0.5"}),u("cliproxyStatsOverview.running")]})]})}),e.jsx(b,{className:"p-0 flex-1 min-h-0",children:e.jsx(Ke,{className:"h-full",children:e.jsxs("div",{className:"p-3 space-y-3",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2 p-2 rounded-lg bg-muted/30",children:[e.jsxs("div",{className:"relative",children:[e.jsxs("svg",{className:"w-10 h-10 -rotate-90",viewBox:"0 0 36 36",children:[e.jsx("circle",{cx:"18",cy:"18",r:"14",fill:"none",stroke:"currentColor",strokeWidth:"3",className:"text-muted/30"}),e.jsx("circle",{cx:"18",cy:"18",r:"14",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeDasharray:`${g*.88} 88`,strokeLinecap:"round",className:g>=90?"text-green-500":"text-amber-500"})]}),e.jsxs("span",{className:"absolute inset-0 flex items-center justify-center text-[8px] font-bold",children:[g,"%"]})]}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-lg font-bold leading-none",children:ce(c)}),e.jsx("div",{className:"text-[9px] text-muted-foreground mt-0.5",children:m>0?`${m} failed`:"All success"})]})]}),e.jsxs("div",{className:"flex items-center gap-2 p-2 rounded-lg bg-muted/30",children:[e.jsx("div",{className:"p-1.5 rounded-md bg-purple-100 dark:bg-purple-900/20",children:e.jsx(Xe,{className:"h-4 w-4 text-purple-600"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-lg font-bold leading-none",children:ce(S)}),e.jsx("div",{className:"text-[9px] text-muted-foreground mt-0.5",children:u("cliproxyStatsOverview.totalTokens")})]})]})]}),C.length>0&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] font-medium text-muted-foreground",children:[e.jsx(Je,{className:"h-3 w-3"}),u("cliproxyStatsOverview.modelsUsed")]}),e.jsx("div",{className:"space-y-1",children:C.map(([y,T])=>{const E=Math.round(T/h*100),O=Es(y);return e.jsxs("div",{className:"group",children:[e.jsxs("div",{className:"flex items-center justify-between text-[10px] mb-0.5",children:[e.jsx("span",{className:"truncate font-medium",title:y,children:O}),e.jsx("span",{className:"text-muted-foreground shrink-0 ml-2",children:T})]}),e.jsx("div",{className:"h-1 bg-muted/50 rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full bg-accent/70 rounded-full transition-all",style:{width:`${E}%`}})})]},y)})})]})]})})})]})}function ce(s){return s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toLocaleString()}function Es(s){let t=s.replace(/^gemini-claude-/,"").replace(/^gemini-/,"").replace(/^claude-/,"").replace(/^anthropic\./,"").replace(/-thinking$/," Thinking");return t=t.split(/[-_]/).map(a=>a.charAt(0).toUpperCase()+a.slice(1)).join(" "),t.length>20&&(t=t.slice(0,18)+"..."),t}function Ks(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 _s({models:s,isLoading:t,onModelClick:a,privacyMode:n}){const{t:i}=P();return e.jsxs(N,{className:"flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0 shadow-sm lg:col-span-4",children:[e.jsx(v,{className:"px-3 py-2",children:e.jsxs(R,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(me,{className:"w-4 h-4"}),i("analyticsPages.costByModel")]})}),e.jsx(b,{className:"px-2 pb-2 pt-0 flex-1 min-h-0 overflow-y-auto",children:t?e.jsx(p,{className:"h-full w-full"}):e.jsxs("div",{className:"space-y-0.5",children:[[...s||[]].sort((r,o)=>o.cost-r.cost).map(r=>e.jsxs("button",{className:"group flex items-center text-xs w-full hover:bg-muted/50 rounded px-2 py-1.5 transition-colors cursor-pointer gap-3",onClick:o=>a(r,o),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:xe(r.model)}}),e.jsx("span",{className:"font-medium truncate group-hover:underline underline-offset-2",children:r.model})]}),e.jsx(Ws,{model:r}),e.jsx("span",{className:x("text-[10px] text-muted-foreground w-14 text-right shrink-0",n&&k),children:Ks(r.tokens)}),e.jsxs("span",{className:x("font-mono font-medium w-16 text-right shrink-0",n&&k),children:["$",r.cost.toFixed(2)]}),e.jsx(es,{className:"w-3 h-3 opacity-0 group-hover:opacity-50 transition-opacity shrink-0"})]},r.model)),e.jsx(Gs,{})]})})]})}function Ws({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 Gs(){const s=[{color:"#335c67",label:"Input"},{color:"#fff3b0",label:"Output",hasBorder:!0},{color:"#e09f3e",label:"Cache Write"},{color:"#9e2a2b",label:"Cache Read"}];return e.jsx("div",{className:"flex items-center gap-3 pt-2 px-2 text-[10px] text-muted-foreground border-t mt-2",children:s.map(({color:t,label:a,hasBorder:n})=>e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("div",{className:x("w-2 h-2 rounded-full",n&&"border border-muted-foreground/30"),style:{backgroundColor:t}}),a]},a))})}function Hs({viewMode:s,trends:t,hourlyData:a,models:n,sessions:i,isTrendsLoading:r,isHourlyLoading:o,isModelsLoading:u,isSessionsLoading:l,isSummaryLoading:c,onModelClick:m}){const{privacyMode:d}=U();return e.jsxs("div",{className:"min-h-0 grid gap-4 lg:grid-rows-[minmax(260px,1.2fr)_minmax(220px,0.9fr)]",children:[e.jsxs(N,{className:"flex flex-col h-full min-h-[220px] lg:min-h-[240px] overflow-hidden gap-0 py-0 shadow-sm",children:[e.jsx(v,{className:"px-3 py-2 shrink-0",children:e.jsxs(R,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(ss,{className:"w-4 h-4"}),s==="hourly"?"Last 24 Hours":"Usage Trends"]})}),e.jsx(b,{className:"px-3 pb-3 pt-0 flex-1 min-h-0",children:e.jsx(Ms,{data:s==="hourly"?a||[]:t||[],isLoading:s==="hourly"?o:r,granularity:s==="hourly"?"hourly":"daily"})})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-10 gap-4 h-auto min-h-[220px] lg:h-full lg:min-h-[220px] lg:grid-rows-[minmax(0,1fr)] lg:[&>*]:min-h-0",children:[e.jsx(_s,{models:n,isLoading:u,onModelClick:m,privacyMode:d}),e.jsxs(N,{className:"flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0 shadow-sm lg:col-span-2",children:[e.jsx(v,{className:"px-3 py-2",children:e.jsxs(R,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(ts,{className:"w-4 h-4"}),"Model Usage"]})}),e.jsx(b,{className:"px-2 pb-2 pt-0 flex-1 min-h-0 flex items-center justify-center",children:e.jsx(As,{data:n||[],isLoading:u,className:"h-full w-full"})})]}),e.jsx(Os,{data:i,isLoading:l,className:"lg:col-span-2"}),e.jsx(qs,{isLoading:c,className:"lg:col-span-2"})]})]})}function at(){return e.jsxs("div",{className:"space-y-4 h-full overflow-hidden",children:[e.jsxs(N,{className:"flex flex-col min-h-[300px]",children:[e.jsx(v,{className:"p-4 pb-2",children:e.jsx(p,{className:"h-4 w-32"})}),e.jsx(b,{className:"p-4 pt-0 flex-1",children:e.jsx(p,{className:"h-full w-full"})})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-4",children:[e.jsxs(N,{className:"flex flex-col min-h-[250px]",children:[e.jsx(v,{className:"p-4 pb-2",children:e.jsx(p,{className:"h-4 w-28"})}),e.jsx(b,{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(p,{className:"w-2.5 h-2.5 rounded-full"}),e.jsx(p,{className:"h-3 w-24"})]}),e.jsx(p,{className:"h-3 w-16"})]},s))})})]}),e.jsxs(N,{className:"flex flex-col min-h-[250px]",children:[e.jsx(v,{className:"p-4 pb-2",children:e.jsx(p,{className:"h-4 w-28"})}),e.jsx(b,{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(p,{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(p,{className:"w-2 h-2 rounded-full"}),e.jsx(p,{className:"h-3 w-20"})]},s))})]})})]})]})]})}function nt(){const s=f.useRef(null),{dateRange:t,handleDateRangeChange:a,handleTodayClick:n,handleRefresh:i,isRefreshing:r,lastUpdatedText:o,viewMode:u,selectedProfile:l,profileOptions:c,summary:m,isSummaryLoading:d,trends:g,hourlyData:S,models:C,sessions:h,isTrendsLoading:y,isHourlyLoading:T,isModelsLoading:E,isSessionsLoading:O,handleModelClick:J,handleProfileChange:G,selectedModel:K,popoverPosition:H,handlePopoverClose:ee}=Rs();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(Fs,{dateRange:t,onDateRangeChange:a,onTodayClick:n,onRefresh:i,isRefreshing:r,lastUpdatedText:o,viewMode:u,selectedProfile:l,profileOptions:c,onProfileChange:G}),e.jsx(ms,{data:m,isLoading:d}),e.jsx(Hs,{viewMode:u,trends:g,hourlyData:S,models:C,sessions:h,isTrendsLoading:y,isHourlyLoading:T,isModelsLoading:E,isSessionsLoading:O,isSummaryLoading:d,onModelClick:J}),e.jsxs(de,{open:!!K,onOpenChange:z=>!z&&ee(),children:[e.jsx(_e,{asChild:!0,children:e.jsx("div",{ref:s,className:"fixed pointer-events-none",style:{left:H?.x??0,top:H?.y??0,width:1,height:1}})}),e.jsx(ue,{className:"w-80 p-3",side:"top",align:"center",children:K&&e.jsx(hs,{model:K})})]})]})}export{nt as AnalyticsPage,at as AnalyticsSkeleton};