@kaitranntt/ccs 8.1.4-dev.4 → 8.1.4-dev.6
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/config/base-qoder.settings.json +10 -0
- package/dist/cliproxy/accounts/registry.d.ts.map +1 -1
- package/dist/cliproxy/accounts/registry.js +11 -4
- package/dist/cliproxy/accounts/registry.js.map +1 -1
- package/dist/cliproxy/ai-providers/codex-plan-compatibility.js +1 -1
- package/dist/cliproxy/ai-providers/codex-plan-compatibility.js.map +1 -1
- package/dist/cliproxy/auth/auth-types.d.ts.map +1 -1
- package/dist/cliproxy/auth/auth-types.js +7 -0
- package/dist/cliproxy/auth/auth-types.js.map +1 -1
- package/dist/cliproxy/auth/oauth-handler.d.ts.map +1 -1
- package/dist/cliproxy/auth/oauth-handler.js +7 -4
- package/dist/cliproxy/auth/oauth-handler.js.map +1 -1
- package/dist/cliproxy/auth/oauth-trace/trace-recorder.js +2 -2
- package/dist/cliproxy/auth/oauth-trace/trace-recorder.js.map +1 -1
- package/dist/cliproxy/executor/arg-parser.d.ts +8 -5
- package/dist/cliproxy/executor/arg-parser.d.ts.map +1 -1
- package/dist/cliproxy/executor/arg-parser.js +21 -10
- package/dist/cliproxy/executor/arg-parser.js.map +1 -1
- package/dist/cliproxy/executor/browser-launch-setup.d.ts +1 -0
- package/dist/cliproxy/executor/browser-launch-setup.d.ts.map +1 -1
- package/dist/cliproxy/executor/browser-launch-setup.js +4 -3
- package/dist/cliproxy/executor/browser-launch-setup.js.map +1 -1
- package/dist/cliproxy/executor/index.d.ts.map +1 -1
- package/dist/cliproxy/executor/index.js +15 -6
- package/dist/cliproxy/executor/index.js.map +1 -1
- package/dist/cliproxy/executor/proxy-resolver.d.ts +15 -9
- package/dist/cliproxy/executor/proxy-resolver.d.ts.map +1 -1
- package/dist/cliproxy/executor/proxy-resolver.js +14 -5
- package/dist/cliproxy/executor/proxy-resolver.js.map +1 -1
- package/dist/cliproxy/model-catalog.d.ts.map +1 -1
- package/dist/cliproxy/model-catalog.js +62 -0
- package/dist/cliproxy/model-catalog.js.map +1 -1
- package/dist/cliproxy/provider-capabilities.d.ts.map +1 -1
- package/dist/cliproxy/provider-capabilities.js +12 -0
- package/dist/cliproxy/provider-capabilities.js.map +1 -1
- package/dist/cliproxy/quota/quota-fetcher-codex.d.ts +2 -2
- package/dist/cliproxy/quota/quota-fetcher-codex.d.ts.map +1 -1
- package/dist/cliproxy/quota/quota-fetcher-codex.js +2 -4
- package/dist/cliproxy/quota/quota-fetcher-codex.js.map +1 -1
- package/dist/cliproxy/quota/quota-label-sanitizer.d.ts +10 -0
- package/dist/cliproxy/quota/quota-label-sanitizer.d.ts.map +1 -0
- package/dist/cliproxy/quota/quota-label-sanitizer.js +31 -0
- package/dist/cliproxy/quota/quota-label-sanitizer.js.map +1 -0
- package/dist/cliproxy/routing/routing-strategy-http.d.ts.map +1 -1
- package/dist/cliproxy/routing/routing-strategy-http.js +35 -26
- package/dist/cliproxy/routing/routing-strategy-http.js.map +1 -1
- package/dist/cliproxy/services/catalog-cache.d.ts.map +1 -1
- package/dist/cliproxy/services/catalog-cache.js +5 -3
- package/dist/cliproxy/services/catalog-cache.js.map +1 -1
- package/dist/cliproxy/types/provider-types.d.ts +1 -1
- package/dist/cliproxy/types/provider-types.d.ts.map +1 -1
- package/dist/cliproxy/types/provider-types.js +1 -0
- package/dist/cliproxy/types/provider-types.js.map +1 -1
- package/dist/codex-auth/commands/import-default-command.d.ts +1 -1
- package/dist/codex-auth/commands/import-default-command.d.ts.map +1 -1
- package/dist/codex-auth/commands/import-default-command.js +12 -25
- package/dist/codex-auth/commands/import-default-command.js.map +1 -1
- package/dist/commands/api-command/help.js +1 -1
- package/dist/commands/api-command/help.js.map +1 -1
- package/dist/commands/cleanup-command.d.ts.map +1 -1
- package/dist/commands/cleanup-command.js +99 -51
- package/dist/commands/cleanup-command.js.map +1 -1
- package/dist/commands/cliproxy/quota-subcommand.d.ts +10 -1
- package/dist/commands/cliproxy/quota-subcommand.d.ts.map +1 -1
- package/dist/commands/cliproxy/quota-subcommand.js +15 -6
- package/dist/commands/cliproxy/quota-subcommand.js.map +1 -1
- package/dist/commands/command-catalog.d.ts.map +1 -1
- package/dist/commands/command-catalog.js +1 -0
- package/dist/commands/command-catalog.js.map +1 -1
- package/dist/config/reserved-names.d.ts +1 -1
- package/dist/config/reserved-names.d.ts.map +1 -1
- package/dist/config/reserved-names.js +1 -0
- package/dist/config/reserved-names.js.map +1 -1
- package/dist/config/schemas/proxy-server.js +1 -1
- package/dist/management/shared-manager.d.ts.map +1 -1
- package/dist/management/shared-manager.js +9 -1
- package/dist/management/shared-manager.js.map +1 -1
- package/dist/proxy/proxy-daemon.js +1 -1
- package/dist/proxy/proxy-daemon.js.map +1 -1
- package/dist/shared/cliproxy-model-routing.d.ts.map +1 -1
- package/dist/shared/cliproxy-model-routing.js +1 -0
- package/dist/shared/cliproxy-model-routing.js.map +1 -1
- package/dist/shared/stale-codex-translator-settings.d.ts.map +1 -1
- package/dist/shared/stale-codex-translator-settings.js +48 -9
- package/dist/shared/stale-codex-translator-settings.js.map +1 -1
- package/dist/targets/codex-adapter.d.ts.map +1 -1
- package/dist/targets/codex-adapter.js +9 -7
- package/dist/targets/codex-adapter.js.map +1 -1
- package/dist/targets/target-metadata.js +1 -1
- package/dist/targets/target-metadata.js.map +1 -1
- package/dist/ui/assets/{Trans-Df0lQgo1.js → Trans-BwfEpDir.js} +1 -1
- package/dist/ui/assets/{accounts-uDG2wCfg.js → accounts-DfPnBEAC.js} +1 -1
- package/dist/ui/assets/{alert-dialog-DQe42wD6.js → alert-dialog-Bs5Zdxdb.js} +1 -1
- package/dist/ui/assets/{api-DH25HlA4.js → api-CXVd51ks.js} +1 -1
- package/dist/ui/assets/{auth-section-zxt2sskJ.js → auth-section-BklXpmG4.js} +1 -1
- package/dist/ui/assets/{backups-section-BrYde0eJ.js → backups-section-IEsgmzCD.js} +1 -1
- package/dist/ui/assets/{channels-CTXZ6tMv.js → channels-N6Z9kTVW.js} +1 -1
- package/dist/ui/assets/{checkbox-CO1YJz0m.js → checkbox-CbznCwaq.js} +1 -1
- package/dist/ui/assets/{claude-extension-B7xk4T-c.js → claude-extension-BSLuKQT8.js} +1 -1
- package/dist/ui/assets/cliproxy-3RE8DcQI.js +4 -0
- package/dist/ui/assets/{cliproxy-ai-providers-CyC9DsCc.js → cliproxy-ai-providers-DRzEL4wV.js} +1 -1
- package/dist/ui/assets/{cliproxy-control-panel-PcfdHgqW.js → cliproxy-control-panel-DsafUMUi.js} +1 -1
- package/dist/ui/assets/{codex-7Zn-T8Iv.js → codex-BeDYoV9L.js} +1 -1
- package/dist/ui/assets/{confirm-dialog-CJi2Ozyo.js → confirm-dialog-DTgwP_t3.js} +1 -1
- package/dist/ui/assets/{copilot-BIS0Bo_C.js → copilot-UYB62tKb.js} +1 -1
- package/dist/ui/assets/{cursor-DpsRjgla.js → cursor-Cf_jnk4d.js} +1 -1
- package/dist/ui/assets/{droid-C1KGkg1s.js → droid-CG6lk091.js} +1 -1
- package/dist/ui/assets/{globalenv-section-BHLHoNY1.js → globalenv-section-CA9GNF_Z.js} +1 -1
- package/dist/ui/assets/{health-C6J1ej6E.js → health-D8TgKd2I.js} +1 -1
- package/dist/ui/assets/{index-B7Y6GGMg.js → index-BD_9WFTr.js} +1 -1
- package/dist/ui/assets/{index-cq0gmTik.js → index-BJbh1RLB.js} +1 -1
- package/dist/ui/assets/{index-C0kVNF6l.js → index-Bm0-YJA9.js} +1 -1
- package/dist/ui/assets/{index-B_ZOVih3.js → index-BoxFkFUH.js} +36 -36
- package/dist/ui/assets/{index-CcgX4Ojr.js → index-CB8z9Frz.js} +1 -1
- package/dist/ui/assets/index-DOfPoKe_.css +1 -0
- package/dist/ui/assets/{index-EGWiz_HL.js → index-DstWl5oB.js} +1 -1
- package/dist/ui/assets/{index-DNB9YbQm.js → index-cqKRHSqD.js} +1 -1
- package/dist/ui/assets/logs-XneR9UoE.js +1 -0
- package/dist/ui/assets/{masked-input-B4_CdQDA.js → masked-input-BYgR6yDS.js} +1 -1
- package/dist/ui/assets/providers/qoder.svg +1 -0
- package/dist/ui/assets/{proxy-status-widget-CUJmlLx0.js → proxy-status-widget-Cz15mNtu.js} +1 -1
- package/dist/ui/assets/{raw-json-settings-editor-panel-LROBHrIM.js → raw-json-settings-editor-panel-CJDMt4AQ.js} +1 -1
- package/dist/ui/assets/{searchable-select-oR2bFaTZ.js → searchable-select-CcMW5M3I.js} +1 -1
- package/dist/ui/assets/{separator-B9aA8oAI.js → separator-HLaUDE7J.js} +1 -1
- package/dist/ui/assets/{shared-DXghwYkH.js → shared-CIzR881c.js} +1 -1
- package/dist/ui/assets/{table-C0iE8G26.js → table-DySVMX4I.js} +1 -1
- package/dist/ui/assets/{updates-BUgECZuY.js → updates-OHVutlI_.js} +1 -1
- package/dist/ui/assets/{use-accounts-HBNwogph.js → use-accounts-DPUOlbIz.js} +1 -1
- package/dist/ui/index.html +2 -2
- package/dist/utils/retry-strategy.js +1 -1
- package/dist/utils/retry-strategy.js.map +1 -1
- package/dist/web-server/model-pricing.d.ts.map +1 -1
- package/dist/web-server/model-pricing.js +6 -0
- package/dist/web-server/model-pricing.js.map +1 -1
- package/dist/web-server/models-dev/pricing-resolver.js +14 -14
- package/dist/web-server/models-dev/pricing-resolver.js.map +1 -1
- package/dist/web-server/routes/profile-routes.d.ts.map +1 -1
- package/dist/web-server/routes/profile-routes.js +6 -1
- package/dist/web-server/routes/profile-routes.js.map +1 -1
- package/dist/web-server/usage/cliproxy-usage-syncer.d.ts.map +1 -1
- package/dist/web-server/usage/cliproxy-usage-syncer.js +32 -11
- package/dist/web-server/usage/cliproxy-usage-syncer.js.map +1 -1
- package/dist/web-server/usage/cliproxy-usage-transformer.d.ts +1 -2
- package/dist/web-server/usage/cliproxy-usage-transformer.d.ts.map +1 -1
- package/dist/web-server/usage/cliproxy-usage-transformer.js +103 -16
- package/dist/web-server/usage/cliproxy-usage-transformer.js.map +1 -1
- package/dist/web-server/usage/codex-native-usage-collector.d.ts.map +1 -1
- package/dist/web-server/usage/codex-native-usage-collector.js +18 -2
- package/dist/web-server/usage/codex-native-usage-collector.js.map +1 -1
- package/dist/web-server/usage/profile-filter.d.ts +1 -1
- package/dist/web-server/usage/profile-filter.d.ts.map +1 -1
- package/dist/web-server/usage/profile-filter.js +6 -1
- package/dist/web-server/usage/profile-filter.js.map +1 -1
- package/lib/mcp/ccs-browser-server.cjs +7 -2
- package/package.json +1 -1
- package/scripts/completion/ccs.bash +0 -12
- package/scripts/completion/ccs.fish +0 -11
- package/scripts/completion/ccs.ps1 +0 -10
- package/scripts/completion/ccs.zsh +0 -13
- package/scripts/github/stable-release-issue-cleanup-lib.mjs +5 -3
- package/dist/ui/assets/cliproxy-FytnR9FR.js +0 -4
- package/dist/ui/assets/index-G3mgTfgR.css +0 -1
- package/dist/ui/assets/logs-azyJGb7Z.js +0 -1
|
@@ -1 +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-B_ZOVih3.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-HBNwogph.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};
|
|
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-BoxFkFUH.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-DPUOlbIz.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};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as e}from"./radix-ui-nu4wz29m.js";import{r as o}from"./react-vendor-Bjx91N7w.js";import{a as q,bi as J,bk as X,e as I,x as Y,L as A,j as R,k as M,l as K,m as B,n as E,I as F,aJ as Q}from"./index-B_ZOVih3.js";import{R as $,w as Z,x as ee,ad as se,_ as te,s as re}from"./icons-DzKUh8vG.js";import"./tanstack-bhJxV1h8.js";import"./notifications-B4_o8bcr.js";import"./utils-CzKF5WmX.js";import"./form-utils-CuHzLhJZ.js";import"./charts-eIPy2oG6.js";const z={mode:"auto",tier_defaults:{opus:"high",sonnet:"medium",haiku:"low"},show_warnings:!0},U=1e4;function ie(){const[t,i]=o.useState(null),[b,d]=o.useState(!0),[_,N]=o.useState(!1),[p,g]=o.useState(null),[P,y]=o.useState(!1),f=o.useRef(void 0),w=o.useRef(!1),k=o.useCallback(async()=>{const r=new AbortController,c=setTimeout(()=>r.abort(),U);try{d(!0),g(null);const n=await fetch("/api/thinking",{signal:r.signal});if(clearTimeout(c),!n.ok)throw n.headers.get("content-type")?.includes("text/html")?new Error(`Server error (${n.status})`):new Error("Failed to load Thinking config");const m=await n.json();i(m.config||z),f.current=m.lastModified,w.current=!0}catch(n){clearTimeout(c),n.name==="AbortError"?g("Request timeout - please try again"):g(n.message)}finally{d(!1)}return()=>r.abort()},[]),l=o.useCallback(async r=>{if(!w.current||t===null){g("Cannot save settings before they load. Click Refresh and try again.");return}const c=t,n={...c,...r.mode!==void 0?{mode:r.mode}:{},...r.tier_defaults!==void 0?{tier_defaults:r.tier_defaults}:{},...r.show_warnings!==void 0?{show_warnings:r.show_warnings}:{}};r.clear_override||r.override===null?delete n.override:r.override!==void 0&&(n.override=r.override),r.clear_provider_overrides||r.provider_overrides===null?delete n.provider_overrides:r.provider_overrides!==void 0&&(n.provider_overrides=r.provider_overrides),i(n);const m=new AbortController,h=setTimeout(()=>m.abort(),U);try{N(!0),g(null);const x={...n,lastModified:f.current},u=await fetch("/api/thinking",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(x),signal:m.signal});if(clearTimeout(h),!u.ok){if(u.headers.get("content-type")?.includes("text/html"))throw new Error(`Server error (${u.status})`);const s=await u.json();throw u.status===409?new Error("Config changed by another session. Refreshing..."):new Error(s.error||"Failed to save")}const v=await u.json();i(v.config),f.current=v.lastModified,y(!0),setTimeout(()=>y(!1),1500)}catch(x){clearTimeout(h),i(c),x.name==="AbortError"?g("Request timeout - please try again"):(g(x.message),x.message.includes("another session")&&setTimeout(()=>k(),1e3))}finally{N(!1)}},[t,k]),T=o.useCallback(r=>{l({mode:r})},[l]),C=o.useCallback((r,c)=>{const n=t?.tier_defaults||z.tier_defaults;l({tier_defaults:{...n,[r]:c}})},[t,l]),O=o.useCallback(r=>{l({show_warnings:r})},[l]),D=o.useCallback(r=>{if(r===void 0){l({override:null,clear_override:!0});return}l({override:r,clear_override:!1})},[l]),L=o.useCallback((r,c,n)=>{const m=t?.provider_overrides||{},h=m[r]||{};if(n===void 0){const{[c]:x,...u}=h,v=Object.keys(u).length>0?u:void 0,{[r]:S,...s}=m,a=v?{...s,[r]:v}:s;l({provider_overrides:Object.keys(a).length>0?a:null,clear_provider_overrides:Object.keys(a).length===0})}else l({provider_overrides:{...m,[r]:{...h,[c]:n}},clear_provider_overrides:!1})},[t,l]);return{config:t||z,loading:b,saving:_,error:p,success:P,fetchConfig:k,saveConfig:l,setMode:T,setTierDefault:C,setShowWarnings:O,setOverride:D,setProviderOverride:L}}const H=[{value:"minimal",label:"Minimal (512 tokens)"},{value:"low",label:"Low (1K tokens)"},{value:"medium",label:"Medium (8K tokens)"},{value:"high",label:"High (24K tokens)"},{value:"xhigh",label:"Extra High (32K tokens)"},{value:"max",label:"Max (adaptive ceiling)"},{value:"auto",label:"Auto (dynamic)"}],ne=[{value:"__none__",label:"None (use CLI flags only)"},...H,{value:"__custom__",label:"Custom budget (number)"},{value:"off",label:"Off (disable thinking)"}],ae=["agy","gemini","codex"],G=0,V=1e5;function fe(){const{t}=q(),{config:i,loading:b,saving:d,error:_,success:N,fetchConfig:p,setMode:g,setTierDefault:P,setShowWarnings:y,setOverride:f,setProviderOverride:w}=ie(),[k,l]=o.useState(null),[T,C]=o.useState(""),[O,D]=o.useState([]),[L,r]=o.useState(null),c=o.useMemo(()=>Array.from(new Set([...ae,...Object.keys(i.provider_overrides??{}),...O])),[O,i.provider_overrides]),n=i.override===void 0?"__none__":typeof i.override=="number"||/^\d+$/.test(String(i.override))?"__custom__":String(i.override),m=typeof i.override=="number"||/^\d+$/.test(String(i.override??""))?String(i.override):"",h=L??m,x=Object.keys(i.provider_overrides??{}).length>0,u=k??x;o.useEffect(()=>{p()},[p]);const v=()=>{const s=T.trim().toLowerCase();s&&(c.includes(s)||D(a=>[...a,s]),C(""),l(!0))},S=()=>{const s=h.trim();if(!s){f(void 0);return}const a=Number.parseInt(s,10);Number.isNaN(a)||a<G||a>V||!/^\d+$/.test(s)||f(a)};return b?e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"flex items-center gap-3 text-muted-foreground",children:[e.jsx($,{className:"w-5 h-5 animate-spin"}),e.jsx("span",{children:t("settings.loading")})]})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:`absolute left-5 right-5 top-20 z-10 transition-all duration-200 ease-out ${_||N?"opacity-100 translate-y-0":"opacity-0 -translate-y-2 pointer-events-none"}`,children:[_&&e.jsx(J,{variant:"destructive",className:"py-2 shadow-lg",children:e.jsxs("div",{className:"flex items-center justify-between w-full",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Z,{className:"h-4 w-4"}),e.jsx(X,{children:_})]}),e.jsxs(I,{variant:"outline",size:"sm",onClick:p,className:"h-7 px-2 text-xs border-destructive/50 hover:bg-destructive/10",children:[e.jsx($,{className:"w-3 h-3 mr-1"}),t("sharedPage.retry")]})]})}),N&&e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-md border border-green-200 bg-green-50 text-green-700 shadow-lg dark:border-green-900/50 dark:bg-green-900/90 dark:text-green-300",children:[e.jsx(ee,{className:"h-4 w-4 shrink-0"}),e.jsx("span",{className:"text-sm font-medium",children:t("settings.saved")})]})]}),e.jsx(Y,{className:"flex-1",children:e.jsxs("div",{className:"p-5 space-y-6",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(se,{className:"w-5 h-5 text-primary"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t("settingsThinking.description")})]}),e.jsxs("div",{className:"flex items-start gap-2 p-3 rounded-lg bg-blue-50 dark:bg-blue-900/20 border border-blue-200 dark:border-blue-800",children:[e.jsx(te,{className:"w-4 h-4 text-blue-600 dark:text-blue-400 shrink-0 mt-0.5"}),e.jsxs("div",{className:"text-sm text-blue-700 dark:text-blue-300",children:[e.jsx("p",{className:"font-medium",children:t("settingsThinking.supportedProviders")}),e.jsxs("ul",{className:"mt-1 space-y-0.5 text-blue-600 dark:text-blue-400",children:[e.jsxs("li",{children:[t("settingsThinking.supportLine1Prefix")," ",e.jsx("strong",{children:"agy"}),","," ",e.jsx("strong",{children:"gemini"})," ",t("settingsThinking.supportLine1Suffix")]}),e.jsxs("li",{children:[t("settingsThinking.supportLine2Prefix")," ",e.jsx("strong",{children:"codex"})," ",t("settingsThinking.supportLine2SuffixPrefix"),e.jsx("code",{children:"--effort"}),t("settingsThinking.supportLine2SuffixPostfix")]}),e.jsxs("li",{children:[t("settingsThinking.supportLine3Prefix")," ",e.jsx("code",{children:"-high"}),t("settingsThinking.supportLine3Suffix")]})]})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-base font-medium",children:t("settingsThinking.modeTitle")}),e.jsx("div",{className:"space-y-2",children:["auto","off","manual"].map(s=>e.jsxs("div",{className:`flex items-center justify-between p-4 rounded-lg cursor-pointer transition-colors ${i.mode===s?"bg-primary/10 border border-primary/30":"bg-muted/50 hover:bg-muted/80"} ${d?"opacity-70 pointer-events-none":""}`,onClick:()=>{d||g(s)},children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium capitalize",children:s}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:[s==="auto"&&t("settingsThinking.modeAutoDesc"),s==="off"&&t("settingsThinking.modeOffDesc"),s==="manual"&&t("settingsThinking.modeManualDesc")]})]}),e.jsx("div",{className:`w-4 h-4 rounded-full border-2 ${i.mode===s?"bg-primary border-primary":"border-muted-foreground/50"}`})]},s))})]}),i.mode==="auto"&&e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-base font-medium",children:t("settingsThinking.tierDefaults")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t("settingsThinking.tierDefaultsDesc")}),e.jsx("div",{className:"space-y-3",children:["opus","sonnet","haiku"].map(s=>e.jsxs("div",{className:"flex items-center gap-4 p-3 rounded-lg bg-muted/30",children:[e.jsx(A,{className:"w-20 capitalize font-medium",children:s}),e.jsxs(R,{value:i.tier_defaults[s],onValueChange:a=>P(s,a),disabled:d,children:[e.jsx(M,{className:"flex-1",children:e.jsx(K,{})}),e.jsx(B,{children:H.map(a=>e.jsx(E,{value:a.value,children:a.label},a.value))})]})]},s))})]}),i.mode==="manual"&&e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-base font-medium",children:t("settingsThinking.persistentOverride")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t("settingsThinking.persistentOverrideDesc")}),e.jsxs(R,{value:n,onValueChange:s=>{if(s==="__none__"){f(void 0);return}if(s==="__custom__"){h||r("8192");return}r(null),f(s)},disabled:d,children:[e.jsx(M,{children:e.jsx(K,{})}),e.jsx(B,{children:ne.map(s=>e.jsx(E,{value:s.value,children:s.label},s.value))})]}),n==="__custom__"&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(F,{type:"number",min:G,max:V,value:h,onChange:s=>r(s.target.value),onBlur:S,disabled:d,placeholder:t("settingsThinking.enterCustomBudget")}),e.jsx(I,{type:"button",size:"sm",variant:"outline",onClick:S,disabled:d,children:t("settingsThinking.apply")})]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Range: ",G," to ",V]})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("button",{type:"button",className:"flex items-center gap-2 text-base font-medium w-full text-left",onClick:()=>l(s=>!(s??x)),disabled:d,children:[e.jsx(re,{className:`w-4 h-4 transition-transform ${u?"rotate-0":"-rotate-90"}`}),t("settingsThinking.providerOverrides",{count:Object.keys(i.provider_overrides??{}).length})]}),u&&e.jsxs("div",{className:"space-y-3",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:t("settingsThinking.providerOverridesDesc")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(F,{value:T,onChange:s=>C(s.target.value),disabled:d,placeholder:t("settingsThinking.addProviderPlaceholder")}),e.jsx(I,{type:"button",size:"sm",variant:"outline",onClick:v,disabled:d,children:t("settingsGlobalEnv.add")})]}),c.map(s=>e.jsxs("div",{className:"space-y-2 p-3 rounded-lg bg-muted/30",children:[e.jsx(A,{className:"capitalize font-medium text-sm",children:s}),e.jsx("div",{className:"grid grid-cols-3 gap-2",children:["opus","sonnet","haiku"].map(a=>{const W=i.provider_overrides?.[s]?.[a]||"__default__";return e.jsxs("div",{className:"space-y-1",children:[e.jsx(A,{className:"text-xs text-muted-foreground capitalize",children:a}),e.jsxs(R,{value:W,onValueChange:j=>w(s,a,j==="__default__"?void 0:j),disabled:d,children:[e.jsx(M,{className:"h-8 text-xs",children:e.jsx(K,{})}),e.jsxs(B,{children:[e.jsx(E,{value:"__default__",children:t("cursorPage.default")}),H.map(j=>e.jsx(E,{value:j.value,children:j.label},j.value))]})]})]},a)})})]},s))]})]}),e.jsxs("div",{className:"flex items-center justify-between p-4 rounded-lg bg-muted/50",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:t("settingsThinking.showWarnings")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t("settingsThinking.showWarningsDesc")})]}),e.jsx(Q,{checked:i.show_warnings??!0,onCheckedChange:y,disabled:d})]}),e.jsxs("div",{className:"p-4 rounded-lg border bg-muted/30",children:[e.jsx("h4",{className:"text-sm font-medium mb-2",children:t("settingsThinking.cliEnvOverride")}),e.jsxs("p",{className:"text-sm text-muted-foreground mb-2",children:["Override per session with flags or"," ",e.jsx("code",{className:"px-1.5 py-0.5 rounded bg-muted",children:"CCS_THINKING"})," env var. Priority: flag > env > config."]}),e.jsxs("div",{className:"space-y-1 text-sm font-mono text-muted-foreground",children:[e.jsx("p",{children:"ccs gemini --thinking high"}),e.jsx("p",{children:"ccs codex --effort xhigh"}),e.jsx("p",{children:'CCS_THINKING=high ccs codex "debug this"'}),e.jsx("p",{children:"ccs config thinking --mode auto"})]})]})]})}),e.jsx("div",{className:"p-4 border-t bg-background",children:e.jsxs(I,{variant:"outline",size:"sm",onClick:p,disabled:b||d,className:"w-full",children:[e.jsx($,{className:`w-4 h-4 mr-2 ${b?"animate-spin":""}`}),t("settings.refresh")]})})]})}export{fe as default};
|
|
1
|
+
import{j as e}from"./radix-ui-nu4wz29m.js";import{r as o}from"./react-vendor-Bjx91N7w.js";import{a as q,bi as J,bk as X,e as I,x as Y,L as A,j as R,k as M,l as K,m as B,n as E,I as F,aJ as Q}from"./index-BoxFkFUH.js";import{R as $,w as Z,x as ee,ad as se,_ as te,s as re}from"./icons-DzKUh8vG.js";import"./tanstack-bhJxV1h8.js";import"./notifications-B4_o8bcr.js";import"./utils-CzKF5WmX.js";import"./form-utils-CuHzLhJZ.js";import"./charts-eIPy2oG6.js";const z={mode:"auto",tier_defaults:{opus:"high",sonnet:"medium",haiku:"low"},show_warnings:!0},U=1e4;function ie(){const[t,i]=o.useState(null),[b,d]=o.useState(!0),[_,N]=o.useState(!1),[p,g]=o.useState(null),[P,y]=o.useState(!1),f=o.useRef(void 0),w=o.useRef(!1),k=o.useCallback(async()=>{const r=new AbortController,c=setTimeout(()=>r.abort(),U);try{d(!0),g(null);const n=await fetch("/api/thinking",{signal:r.signal});if(clearTimeout(c),!n.ok)throw n.headers.get("content-type")?.includes("text/html")?new Error(`Server error (${n.status})`):new Error("Failed to load Thinking config");const m=await n.json();i(m.config||z),f.current=m.lastModified,w.current=!0}catch(n){clearTimeout(c),n.name==="AbortError"?g("Request timeout - please try again"):g(n.message)}finally{d(!1)}return()=>r.abort()},[]),l=o.useCallback(async r=>{if(!w.current||t===null){g("Cannot save settings before they load. Click Refresh and try again.");return}const c=t,n={...c,...r.mode!==void 0?{mode:r.mode}:{},...r.tier_defaults!==void 0?{tier_defaults:r.tier_defaults}:{},...r.show_warnings!==void 0?{show_warnings:r.show_warnings}:{}};r.clear_override||r.override===null?delete n.override:r.override!==void 0&&(n.override=r.override),r.clear_provider_overrides||r.provider_overrides===null?delete n.provider_overrides:r.provider_overrides!==void 0&&(n.provider_overrides=r.provider_overrides),i(n);const m=new AbortController,h=setTimeout(()=>m.abort(),U);try{N(!0),g(null);const x={...n,lastModified:f.current},u=await fetch("/api/thinking",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(x),signal:m.signal});if(clearTimeout(h),!u.ok){if(u.headers.get("content-type")?.includes("text/html"))throw new Error(`Server error (${u.status})`);const s=await u.json();throw u.status===409?new Error("Config changed by another session. Refreshing..."):new Error(s.error||"Failed to save")}const v=await u.json();i(v.config),f.current=v.lastModified,y(!0),setTimeout(()=>y(!1),1500)}catch(x){clearTimeout(h),i(c),x.name==="AbortError"?g("Request timeout - please try again"):(g(x.message),x.message.includes("another session")&&setTimeout(()=>k(),1e3))}finally{N(!1)}},[t,k]),T=o.useCallback(r=>{l({mode:r})},[l]),C=o.useCallback((r,c)=>{const n=t?.tier_defaults||z.tier_defaults;l({tier_defaults:{...n,[r]:c}})},[t,l]),O=o.useCallback(r=>{l({show_warnings:r})},[l]),D=o.useCallback(r=>{if(r===void 0){l({override:null,clear_override:!0});return}l({override:r,clear_override:!1})},[l]),L=o.useCallback((r,c,n)=>{const m=t?.provider_overrides||{},h=m[r]||{};if(n===void 0){const{[c]:x,...u}=h,v=Object.keys(u).length>0?u:void 0,{[r]:S,...s}=m,a=v?{...s,[r]:v}:s;l({provider_overrides:Object.keys(a).length>0?a:null,clear_provider_overrides:Object.keys(a).length===0})}else l({provider_overrides:{...m,[r]:{...h,[c]:n}},clear_provider_overrides:!1})},[t,l]);return{config:t||z,loading:b,saving:_,error:p,success:P,fetchConfig:k,saveConfig:l,setMode:T,setTierDefault:C,setShowWarnings:O,setOverride:D,setProviderOverride:L}}const H=[{value:"minimal",label:"Minimal (512 tokens)"},{value:"low",label:"Low (1K tokens)"},{value:"medium",label:"Medium (8K tokens)"},{value:"high",label:"High (24K tokens)"},{value:"xhigh",label:"Extra High (32K tokens)"},{value:"max",label:"Max (adaptive ceiling)"},{value:"auto",label:"Auto (dynamic)"}],ne=[{value:"__none__",label:"None (use CLI flags only)"},...H,{value:"__custom__",label:"Custom budget (number)"},{value:"off",label:"Off (disable thinking)"}],ae=["agy","gemini","codex"],G=0,V=1e5;function fe(){const{t}=q(),{config:i,loading:b,saving:d,error:_,success:N,fetchConfig:p,setMode:g,setTierDefault:P,setShowWarnings:y,setOverride:f,setProviderOverride:w}=ie(),[k,l]=o.useState(null),[T,C]=o.useState(""),[O,D]=o.useState([]),[L,r]=o.useState(null),c=o.useMemo(()=>Array.from(new Set([...ae,...Object.keys(i.provider_overrides??{}),...O])),[O,i.provider_overrides]),n=i.override===void 0?"__none__":typeof i.override=="number"||/^\d+$/.test(String(i.override))?"__custom__":String(i.override),m=typeof i.override=="number"||/^\d+$/.test(String(i.override??""))?String(i.override):"",h=L??m,x=Object.keys(i.provider_overrides??{}).length>0,u=k??x;o.useEffect(()=>{p()},[p]);const v=()=>{const s=T.trim().toLowerCase();s&&(c.includes(s)||D(a=>[...a,s]),C(""),l(!0))},S=()=>{const s=h.trim();if(!s){f(void 0);return}const a=Number.parseInt(s,10);Number.isNaN(a)||a<G||a>V||!/^\d+$/.test(s)||f(a)};return b?e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"flex items-center gap-3 text-muted-foreground",children:[e.jsx($,{className:"w-5 h-5 animate-spin"}),e.jsx("span",{children:t("settings.loading")})]})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:`absolute left-5 right-5 top-20 z-10 transition-all duration-200 ease-out ${_||N?"opacity-100 translate-y-0":"opacity-0 -translate-y-2 pointer-events-none"}`,children:[_&&e.jsx(J,{variant:"destructive",className:"py-2 shadow-lg",children:e.jsxs("div",{className:"flex items-center justify-between w-full",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Z,{className:"h-4 w-4"}),e.jsx(X,{children:_})]}),e.jsxs(I,{variant:"outline",size:"sm",onClick:p,className:"h-7 px-2 text-xs border-destructive/50 hover:bg-destructive/10",children:[e.jsx($,{className:"w-3 h-3 mr-1"}),t("sharedPage.retry")]})]})}),N&&e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-md border border-green-200 bg-green-50 text-green-700 shadow-lg dark:border-green-900/50 dark:bg-green-900/90 dark:text-green-300",children:[e.jsx(ee,{className:"h-4 w-4 shrink-0"}),e.jsx("span",{className:"text-sm font-medium",children:t("settings.saved")})]})]}),e.jsx(Y,{className:"flex-1",children:e.jsxs("div",{className:"p-5 space-y-6",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(se,{className:"w-5 h-5 text-primary"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t("settingsThinking.description")})]}),e.jsxs("div",{className:"flex items-start gap-2 p-3 rounded-lg bg-blue-50 dark:bg-blue-900/20 border border-blue-200 dark:border-blue-800",children:[e.jsx(te,{className:"w-4 h-4 text-blue-600 dark:text-blue-400 shrink-0 mt-0.5"}),e.jsxs("div",{className:"text-sm text-blue-700 dark:text-blue-300",children:[e.jsx("p",{className:"font-medium",children:t("settingsThinking.supportedProviders")}),e.jsxs("ul",{className:"mt-1 space-y-0.5 text-blue-600 dark:text-blue-400",children:[e.jsxs("li",{children:[t("settingsThinking.supportLine1Prefix")," ",e.jsx("strong",{children:"agy"}),","," ",e.jsx("strong",{children:"gemini"})," ",t("settingsThinking.supportLine1Suffix")]}),e.jsxs("li",{children:[t("settingsThinking.supportLine2Prefix")," ",e.jsx("strong",{children:"codex"})," ",t("settingsThinking.supportLine2SuffixPrefix"),e.jsx("code",{children:"--effort"}),t("settingsThinking.supportLine2SuffixPostfix")]}),e.jsxs("li",{children:[t("settingsThinking.supportLine3Prefix")," ",e.jsx("code",{children:"-high"}),t("settingsThinking.supportLine3Suffix")]})]})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-base font-medium",children:t("settingsThinking.modeTitle")}),e.jsx("div",{className:"space-y-2",children:["auto","off","manual"].map(s=>e.jsxs("div",{className:`flex items-center justify-between p-4 rounded-lg cursor-pointer transition-colors ${i.mode===s?"bg-primary/10 border border-primary/30":"bg-muted/50 hover:bg-muted/80"} ${d?"opacity-70 pointer-events-none":""}`,onClick:()=>{d||g(s)},children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium capitalize",children:s}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:[s==="auto"&&t("settingsThinking.modeAutoDesc"),s==="off"&&t("settingsThinking.modeOffDesc"),s==="manual"&&t("settingsThinking.modeManualDesc")]})]}),e.jsx("div",{className:`w-4 h-4 rounded-full border-2 ${i.mode===s?"bg-primary border-primary":"border-muted-foreground/50"}`})]},s))})]}),i.mode==="auto"&&e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-base font-medium",children:t("settingsThinking.tierDefaults")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t("settingsThinking.tierDefaultsDesc")}),e.jsx("div",{className:"space-y-3",children:["opus","sonnet","haiku"].map(s=>e.jsxs("div",{className:"flex items-center gap-4 p-3 rounded-lg bg-muted/30",children:[e.jsx(A,{className:"w-20 capitalize font-medium",children:s}),e.jsxs(R,{value:i.tier_defaults[s],onValueChange:a=>P(s,a),disabled:d,children:[e.jsx(M,{className:"flex-1",children:e.jsx(K,{})}),e.jsx(B,{children:H.map(a=>e.jsx(E,{value:a.value,children:a.label},a.value))})]})]},s))})]}),i.mode==="manual"&&e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-base font-medium",children:t("settingsThinking.persistentOverride")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t("settingsThinking.persistentOverrideDesc")}),e.jsxs(R,{value:n,onValueChange:s=>{if(s==="__none__"){f(void 0);return}if(s==="__custom__"){h||r("8192");return}r(null),f(s)},disabled:d,children:[e.jsx(M,{children:e.jsx(K,{})}),e.jsx(B,{children:ne.map(s=>e.jsx(E,{value:s.value,children:s.label},s.value))})]}),n==="__custom__"&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(F,{type:"number",min:G,max:V,value:h,onChange:s=>r(s.target.value),onBlur:S,disabled:d,placeholder:t("settingsThinking.enterCustomBudget")}),e.jsx(I,{type:"button",size:"sm",variant:"outline",onClick:S,disabled:d,children:t("settingsThinking.apply")})]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Range: ",G," to ",V]})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("button",{type:"button",className:"flex items-center gap-2 text-base font-medium w-full text-left",onClick:()=>l(s=>!(s??x)),disabled:d,children:[e.jsx(re,{className:`w-4 h-4 transition-transform ${u?"rotate-0":"-rotate-90"}`}),t("settingsThinking.providerOverrides",{count:Object.keys(i.provider_overrides??{}).length})]}),u&&e.jsxs("div",{className:"space-y-3",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:t("settingsThinking.providerOverridesDesc")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(F,{value:T,onChange:s=>C(s.target.value),disabled:d,placeholder:t("settingsThinking.addProviderPlaceholder")}),e.jsx(I,{type:"button",size:"sm",variant:"outline",onClick:v,disabled:d,children:t("settingsGlobalEnv.add")})]}),c.map(s=>e.jsxs("div",{className:"space-y-2 p-3 rounded-lg bg-muted/30",children:[e.jsx(A,{className:"capitalize font-medium text-sm",children:s}),e.jsx("div",{className:"grid grid-cols-3 gap-2",children:["opus","sonnet","haiku"].map(a=>{const W=i.provider_overrides?.[s]?.[a]||"__default__";return e.jsxs("div",{className:"space-y-1",children:[e.jsx(A,{className:"text-xs text-muted-foreground capitalize",children:a}),e.jsxs(R,{value:W,onValueChange:j=>w(s,a,j==="__default__"?void 0:j),disabled:d,children:[e.jsx(M,{className:"h-8 text-xs",children:e.jsx(K,{})}),e.jsxs(B,{children:[e.jsx(E,{value:"__default__",children:t("cursorPage.default")}),H.map(j=>e.jsx(E,{value:j.value,children:j.label},j.value))]})]})]},a)})})]},s))]})]}),e.jsxs("div",{className:"flex items-center justify-between p-4 rounded-lg bg-muted/50",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:t("settingsThinking.showWarnings")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t("settingsThinking.showWarningsDesc")})]}),e.jsx(Q,{checked:i.show_warnings??!0,onCheckedChange:y,disabled:d})]}),e.jsxs("div",{className:"p-4 rounded-lg border bg-muted/30",children:[e.jsx("h4",{className:"text-sm font-medium mb-2",children:t("settingsThinking.cliEnvOverride")}),e.jsxs("p",{className:"text-sm text-muted-foreground mb-2",children:["Override per session with flags or"," ",e.jsx("code",{className:"px-1.5 py-0.5 rounded bg-muted",children:"CCS_THINKING"})," env var. Priority: flag > env > config."]}),e.jsxs("div",{className:"space-y-1 text-sm font-mono text-muted-foreground",children:[e.jsx("p",{children:"ccs gemini --thinking high"}),e.jsx("p",{children:"ccs codex --effort xhigh"}),e.jsx("p",{children:'CCS_THINKING=high ccs codex "debug this"'}),e.jsx("p",{children:"ccs config thinking --mode auto"})]})]})]})}),e.jsx("div",{className:"p-4 border-t bg-background",children:e.jsxs(I,{variant:"outline",size:"sm",onClick:p,disabled:b||d,className:"w-full",children:[e.jsx($,{className:`w-4 h-4 mr-2 ${b?"animate-spin":""}`}),t("settings.refresh")]})})]})}export{fe as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{j as r}from"./radix-ui-nu4wz29m.js";import{r as O,E as F,f as ts}from"./react-vendor-Bjx91N7w.js";import{L as Te,aJ as kn,j as Tt,k as Ct,l as Nt,m as kt,n as qe,I as nt,e as ye,c as K,U as or,V as lr,W as it,X as at,x as Pt,a as ir,_ as Rt,O as ns,Q as rs,R as ss,ai as os,aj as ls,ak as is,al as as,am as cs,bm as us,bn as At,bo as Rn,bp as ds,bq as En,br as zn,bs as Hn,bt as Ln,bu as On,S as ze}from"./index-BoxFkFUH.js";import{au as ms,Q as ar,E as cr,aZ as hs,a_ as fs,a$ as gs,o as Xt,aL as ur,g as xs,s as dr,C as ps,T as vs,av as bs,X as js,d as ws,R as Ss,y as ys,e as Is,J as Ts,D as Cs,b0 as Ns}from"./icons-DzKUh8vG.js";import{u as Wt,a as ks,b as Rs,k as Es}from"./tanstack-bhJxV1h8.js";import{t as Bn}from"./notifications-B4_o8bcr.js";import"./utils-CzKF5WmX.js";import"./form-utils-CuHzLhJZ.js";import"./charts-eIPy2oG6.js";function Fn(e,t){const n=Number.parseInt(e,10);return Number.isNaN(n)?t:Math.max(0,n)}function zs({config:e,onSave:t,isPending:n}){const[s,o]=O.useState(e);O.useEffect(()=>{o(e)},[e]);const l=O.useMemo(()=>JSON.stringify(s)!==JSON.stringify(e),[e,s]);return r.jsxs("form",{className:"space-y-5",onSubmit:i=>{i.preventDefault(),t(s)},children:[r.jsxs("div",{className:"space-y-3",children:[r.jsxs("div",{className:"flex items-center justify-between gap-4 rounded border border-border bg-background px-3 py-2",children:[r.jsxs("div",{className:"space-y-0.5",children:[r.jsx(Te,{htmlFor:"logs-enabled",className:"text-sm font-medium",children:"Enabled"}),r.jsx("p",{className:"text-xs text-muted-foreground",children:"Capture structured log entries."})]}),r.jsx(kn,{id:"logs-enabled",checked:s.enabled,onCheckedChange:i=>o(a=>({...a,enabled:i}))})]}),r.jsxs("div",{className:"flex items-center justify-between gap-4 rounded border border-border bg-background px-3 py-2",children:[r.jsxs("div",{className:"space-y-0.5",children:[r.jsx(Te,{htmlFor:"logs-redact",className:"text-sm font-medium",children:"Redact sensitive values"}),r.jsx("p",{className:"text-xs text-muted-foreground",children:"Hide payload values until explicitly revealed."})]}),r.jsx(kn,{id:"logs-redact",checked:s.redact,onCheckedChange:i=>o(a=>({...a,redact:i}))})]})]}),r.jsxs("div",{className:"space-y-2",children:[r.jsx(Te,{htmlFor:"logs-config-level",className:"text-sm font-medium",children:"Minimum level"}),r.jsxs(Tt,{value:s.level,onValueChange:i=>o(a=>({...a,level:i})),children:[r.jsx(Ct,{id:"logs-config-level",className:"h-9",children:r.jsx(Nt,{})}),r.jsxs(kt,{children:[r.jsx(qe,{value:"error",children:"Error only"}),r.jsx(qe,{value:"warn",children:"Warn and above"}),r.jsx(qe,{value:"info",children:"Info and above"}),r.jsx(qe,{value:"debug",children:"Full debug"})]})]})]}),r.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[r.jsxs("div",{className:"space-y-2",children:[r.jsx(Te,{htmlFor:"logs-rotate-mb",className:"text-sm font-medium",children:"Rotation (MB)"}),r.jsx(nt,{id:"logs-rotate-mb",type:"number",min:1,value:s.rotate_mb,onChange:i=>o(a=>({...a,rotate_mb:Fn(i.target.value,a.rotate_mb)})),className:"h-9"})]}),r.jsxs("div",{className:"space-y-2",children:[r.jsx(Te,{htmlFor:"logs-retain-days",className:"text-sm font-medium",children:"Retention (days)"}),r.jsx(nt,{id:"logs-retain-days",type:"number",min:1,value:s.retain_days,onChange:i=>o(a=>({...a,retain_days:Fn(i.target.value,a.retain_days)})),className:"h-9"})]})]}),r.jsxs("div",{className:"flex items-center gap-2 border-t border-border pt-3",children:[r.jsxs(ye,{type:"submit",disabled:!l||n,size:"sm",className:"gap-1.5",children:[r.jsx(ms,{className:"h-3.5 w-3.5","aria-hidden":"true"}),"Save changes"]}),r.jsxs(ye,{type:"button",variant:"ghost",size:"sm",disabled:!l||n,onClick:()=>o(e),className:"gap-1.5",children:[r.jsx(ar,{className:"h-3.5 w-3.5","aria-hidden":"true"}),"Reset"]})]})]})}function Hs(e){if(!e)return"No activity yet";const t=new Date(e);return Number.isNaN(t.getTime())?e:t.toISOString()}function Ls(e){if(e==null)return"{}";try{return JSON.stringify(e,null,2)}catch{return String(e)}}function Os(e){switch(e){case"error":return"Error";case"warn":return"Warn";case"info":return"Info";case"debug":return"Debug"}}function mr(e,t){return e.module??t??e.source??"—"}function Bs(e){return e.stage??"—"}function hr(e,t={}){return e.requestId?t.short?e.requestId.slice(-8):e.requestId:"—"}function fr(e){return e.latencyMs===void 0||e.latencyMs===null?"—":`${e.latencyMs}ms`}const Fs={error:{bg:"bg-red-500/10",fg:"text-red-700 dark:text-red-300",border:"border-red-500/30",dot:"bg-red-500"},warn:{bg:"bg-amber-500/10",fg:"text-amber-800 dark:text-amber-200",border:"border-amber-500/30",dot:"bg-amber-500"},info:{bg:"bg-sky-500/10",fg:"text-sky-800 dark:text-sky-200",border:"border-sky-500/30",dot:"bg-sky-500"},debug:{bg:"bg-zinc-500/10",fg:"text-zinc-700 dark:text-zinc-300",border:"border-zinc-500/30",dot:"bg-zinc-500"}},gr={compact:"h-8 text-[12px]",cozy:"h-10 text-[13px]"},Ae="font-mono tabular-nums",xr="transition-colors hover:bg-muted/40 data-[selected=true]:bg-muted/60",ve="focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background";function an({level:e,className:t}){const n=Fs[e];return r.jsxs("span",{className:K("inline-flex items-center gap-1 rounded-full border px-2 py-0.5 text-[11px] font-medium",n.border,n.bg,n.fg,t),children:[r.jsx("span",{className:K("h-1.5 w-1.5 rounded-full",n.dot),"aria-hidden":"true"}),Os(e)]})}const Ms={selection:{title:"No entry selected",body:"Pick a row in the list to inspect its context. Use j/k to move and Enter to focus the detail.",icon:gs},noData:{title:"No log activity yet",body:"Once requests flow through the system, structured entries will appear here.",icon:fs},noResults:{title:"No entries match your filters",body:"Adjust source, level, search, or time window to see more entries.",icon:hs},selectionOutOfScope:{title:"Selected entry not visible under current filter",body:"Clear your filter or select another row to inspect details.",icon:cr}};function cn({variant:e,onClearFilters:t}){const{title:n,body:s,icon:o}=Ms[e],l=e==="selectionOutOfScope"||e==="noResults";return r.jsxs("div",{role:"status",className:"flex h-full flex-col items-center justify-center gap-3 px-6 py-10 text-center",children:[r.jsx("div",{className:"flex h-10 w-10 items-center justify-center rounded-full border border-border bg-muted/30 text-muted-foreground",children:r.jsx(o,{className:"h-5 w-5","aria-hidden":"true"})}),r.jsx("h3",{className:"text-sm font-semibold text-foreground",children:n}),r.jsx("p",{className:"max-w-xs text-[13px] leading-relaxed text-muted-foreground",children:s}),l&&t?r.jsx(ye,{variant:"outline",size:"sm",onClick:t,className:"mt-1",children:"Clear filters"}):null]})}function Ds(e,t){return[{label:"Time",value:Hs(e.timestamp),mono:!0},{label:"Level",value:e.level},{label:"Module",value:mr(e,t)},{label:"Stage",value:Bs(e)},{label:"Request ID",value:hr(e),mono:!0},{label:"Latency",value:fr(e),mono:!0},{label:"Source",value:t??e.source??"—"},{label:"Run ID",value:e.runId??"—",mono:!0},{label:"Process ID",value:e.processId??"—",mono:!0}]}function Zt({value:e,redact:t,depth:n=0}){const[s,o]=O.useState(!1);if(n>8)return r.jsx("span",{className:"text-muted-foreground",children:"…"});if(e==null)return r.jsx("span",{className:"text-muted-foreground",children:"null"});if(typeof e=="string"||typeof e=="number"||typeof e=="boolean")return t&&typeof e=="string"&&e.length>0&&!s?r.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[r.jsx("span",{className:"rounded bg-muted px-1.5 py-0.5 text-muted-foreground",children:"redacted"}),r.jsx("button",{type:"button",onClick:()=>o(!0),"aria-label":"Reveal value",className:K("rounded p-0.5 text-muted-foreground hover:text-foreground",ve),children:r.jsx(xs,{className:"h-3 w-3","aria-hidden":"true"})})]}):r.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[r.jsx("span",{className:K("text-foreground/90",typeof e!="string"&&Ae),children:String(e)}),t&&typeof e=="string"&&s?r.jsx("button",{type:"button",onClick:()=>o(!1),"aria-label":"Hide value",className:K("rounded p-0.5 text-muted-foreground hover:text-foreground",ve),children:r.jsx(cr,{className:"h-3 w-3","aria-hidden":"true"})}):null]});if(Array.isArray(e))return r.jsxs("ul",{className:"border-l border-border/60 pl-3",children:[e.slice(0,50).map((a,c)=>r.jsxs("li",{className:"text-[12px]",children:[r.jsxs("span",{className:"text-muted-foreground",children:["[",c,"]"]})," ",r.jsx(Zt,{value:a,redact:t,depth:n+1})]},c)),e.length>50?r.jsxs("li",{className:"text-[12px] text-muted-foreground",children:["… +",e.length-50," more"]}):null]});const l=e,i=Object.keys(l);return r.jsx("ul",{className:"border-l border-border/60 pl-3",children:i.map(a=>r.jsxs("li",{className:"text-[12px]",children:[r.jsx("span",{className:"font-medium text-foreground/80",children:a}),":"," ",r.jsx(Zt,{value:l[a],redact:t,depth:n+1})]},a))})}async function Mn(e){try{await navigator.clipboard.writeText(e)}catch{}}function Ps({entry:e,sourceLabel:t,onShowTrace:n,redact:s=!1}){const o=O.useMemo(()=>e?Ds(e,t):[],[e,t]);if(!e)return r.jsx(cn,{variant:"selection"});const l=Ls(e);return r.jsxs("div",{className:"flex h-full min-h-0 flex-col bg-background",children:[r.jsxs("header",{className:"flex shrink-0 flex-col gap-2 border-b border-border px-4 py-3",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(an,{level:e.level}),r.jsx("span",{className:"truncate text-[12px] text-muted-foreground",children:e.event})]}),r.jsx("p",{className:"truncate text-sm font-medium text-foreground",children:e.message}),r.jsxs("div",{className:"flex flex-wrap items-center gap-1",children:[r.jsxs(ye,{variant:"ghost",size:"sm",onClick:()=>void Mn(l),className:K("h-7 gap-1.5 px-2 text-xs",ve),children:[r.jsx(Xt,{className:"h-3 w-3","aria-hidden":"true"}),"Copy JSON"]}),e.requestId?r.jsxs(ye,{variant:"ghost",size:"sm",onClick:()=>e.requestId&&void Mn(e.requestId),className:K("h-7 gap-1.5 px-2 text-xs",ve),children:[r.jsx(Xt,{className:"h-3 w-3","aria-hidden":"true"}),"Copy requestId"]}):null,e.requestId&&n?r.jsxs(ye,{variant:"ghost",size:"sm",onClick:()=>e.requestId&&n(e.requestId),className:K("h-7 gap-1.5 px-2 text-xs",ve),children:[r.jsx(ur,{className:"h-3 w-3","aria-hidden":"true"}),"Show trace"]}):null]})]}),r.jsxs(or,{defaultValue:"overview",className:"flex min-h-0 flex-1 flex-col",children:[r.jsxs(lr,{className:"m-2 h-8 w-fit bg-muted/40",children:[r.jsx(it,{value:"overview",className:"text-xs",children:"Overview"}),r.jsx(it,{value:"context",className:"text-xs",children:"Context"}),r.jsx(it,{value:"raw",className:"text-xs",children:"Raw"})]}),r.jsx(at,{value:"overview",className:"m-0 min-h-0 flex-1",children:r.jsx(Pt,{className:"h-full",children:r.jsxs("dl",{className:"grid grid-cols-[120px_minmax(0,1fr)] gap-x-3 gap-y-2 px-4 pb-4",children:[o.map(i=>r.jsx(As,{...i},i.label)),e.error?r.jsxs("div",{className:"col-span-2 mt-2 rounded border border-red-500/30 bg-red-500/5 p-3",children:[r.jsxs("p",{className:"text-xs font-semibold text-red-700 dark:text-red-400",children:[e.error.code??"Error",": ",e.error.message]}),e.error.stack?r.jsx("pre",{className:"mt-2 max-h-40 overflow-auto whitespace-pre-wrap font-mono text-[11px] text-red-700/80 dark:text-red-300/80",children:e.error.stack}):null]}):null]})})}),r.jsx(at,{value:"context",className:"m-0 min-h-0 flex-1",children:r.jsx(Pt,{className:"h-full",children:r.jsx("div",{className:"px-4 pb-4 text-[12px] leading-relaxed",children:e.metadata&&Object.keys(e.metadata).length>0?r.jsx(Zt,{value:e.metadata,redact:s}):r.jsx("p",{className:"text-muted-foreground",children:"No structured metadata."})})})}),r.jsx(at,{value:"raw",className:"m-0 min-h-0 flex-1",children:r.jsx(Pt,{className:"h-full",children:r.jsx("pre",{className:K("m-0 px-4 pb-4 text-[12px] leading-relaxed text-foreground/90",Ae),children:l})})})]})]})}function As({label:e,value:t,mono:n}){return r.jsxs(r.Fragment,{children:[r.jsx("dt",{className:"text-[11px] uppercase tracking-wide text-muted-foreground",children:e}),r.jsx("dd",{className:K("truncate text-[13px] text-foreground/90",n&&Ae),title:t==null?void 0:String(t),children:t??"—"})]})}const Ot=0,Qe=1,ot=2,pr=4;function Dn(e){return()=>e}function Ws(e){e()}function vr(e,t){return n=>e(t(n))}function Pn(e,t){return()=>e(t)}function _s(e,t){return n=>e(t,n)}function un(e){return e!==void 0}function Vs(...e){return()=>{e.map(Ws)}}function lt(){}function Bt(e,t){return t(e),e}function qs(e,t){return t(e)}function se(...e){return e}function Y(e,t){return e(Qe,t)}function q(e,t){e(Ot,t)}function dn(e){e(ot)}function le(e){return e(pr)}function M(e,t){return Y(e,_s(t,Ot))}function Oe(e,t){const n=e(Qe,s=>{n(),t(s)});return n}function An(e){let t,n;return s=>o=>{t=o,n&&clearTimeout(n),n=setTimeout(()=>{s(t)},e)}}function br(e,t){return e===t}function re(e=br){let t;return n=>s=>{e(t,s)||(t=s,n(s))}}function A(e){return t=>n=>{e(n)&&t(n)}}function L(e){return t=>vr(t,e)}function De(e){return t=>()=>{t(e)}}function j(e,...t){const n=Gs(...t);return(s,o)=>{switch(s){case ot:dn(e);return;case Qe:return Y(e,n(o))}}}function Pe(e,t){return n=>s=>{n(t=e(t,s))}}function Xe(e){return t=>n=>{e>0?e--:t(n)}}function _e(e){let t=null,n;return s=>o=>{t=o,!n&&(n=setTimeout(()=>{n=void 0,s(t)},e))}}function G(...e){const t=new Array(e.length);let n=0,s=null;const o=Math.pow(2,e.length)-1;return e.forEach((l,i)=>{const a=Math.pow(2,i);Y(l,c=>{const u=n;n=n|a,t[i]=c,u!==o&&n===o&&s&&(s(),s=null)})}),l=>i=>{const a=()=>{l([i].concat(t))};n===o?a():s=a}}function Gs(...e){return t=>e.reduceRight(qs,t)}function Qs(e){let t,n;const s=()=>t?.();return function(o,l){switch(o){case Qe:return l?n===l?void 0:(s(),n=l,t=Y(e,l),t):(s(),lt);case ot:s(),n=null;return}}}function I(e){let t=e;const n=U();return(s,o)=>{switch(s){case Ot:t=o;break;case Qe:{o(t);break}case pr:return t}return n(s,o)}}function je(e,t){return Bt(I(t),n=>M(e,n))}function U(){const e=[];return(t,n)=>{switch(t){case Ot:e.slice().forEach(s=>{s(n)});return;case ot:e.splice(0,e.length);return;case Qe:return e.push(n),()=>{const s=e.indexOf(n);s>-1&&e.splice(s,1)}}}}function ke(e){return Bt(U(),t=>M(e,t))}function $(e,t=[],{singleton:n}={singleton:!0}){return{constructor:e,dependencies:t,id:Us(),singleton:n}}const Us=()=>Symbol();function Ks(e){const t=new Map,n=({constructor:s,dependencies:o,id:l,singleton:i})=>{if(i&&t.has(l))return t.get(l);const a=s(o.map(c=>n(c)));return i&&t.set(l,a),a};return n(e)}function de(...e){const t=U(),n=new Array(e.length);let s=0;const o=Math.pow(2,e.length)-1;return e.forEach((l,i)=>{const a=Math.pow(2,i);Y(l,c=>{n[i]=c,s=s|a,s===o&&q(t,n)})}),function(l,i){switch(l){case ot:{dn(t);return}case Qe:return s===o&&i(n),Y(t,i)}}}function P(e,t=br){return j(e,re(t))}function en(...e){return function(t,n){switch(t){case ot:return;case Qe:return Vs(...e.map(s=>Y(s,n)))}}}var Ce=(e=>(e[e.DEBUG=0]="DEBUG",e[e.INFO=1]="INFO",e[e.WARN=2]="WARN",e[e.ERROR=3]="ERROR",e))(Ce||{});const $s={0:"debug",3:"error",1:"log",2:"warn"},Js=()=>typeof globalThis>"u"?window:globalThis,Ue=$(()=>{const e=I(3);return{log:I((t,n,s=1)=>{var o;const l=(o=Js().VIRTUOSO_LOG_LEVEL)!=null?o:le(e);s>=l&&console[$s[s]]("%creact-virtuoso: %c%s %o","color: #0253b3; font-weight: bold","color: initial",t,n)}),logLevel:e}},[],{singleton:!0});function Ze(e,t,n){return mn(e,t,n).callbackRef}function mn(e,t,n){const s=F.useRef(null);let o=i=>{};const l=F.useMemo(()=>typeof ResizeObserver<"u"?new ResizeObserver(i=>{const a=()=>{const c=i[0].target;c.offsetParent!==null&&e(c)};n?a():requestAnimationFrame(a)}):null,[e,n]);return o=i=>{i&&t?(l?.observe(i),s.current=i):(s.current&&l?.unobserve(s.current),s.current=null)},{callbackRef:o,ref:s}}function Ys(e,t,n,s,o,l,i,a,c){const u=F.useCallback(f=>{const p=Xs(f.children,t,a?"offsetWidth":"offsetHeight",o);let x=f.parentElement;for(;!x.dataset.virtuosoScroller;)x=x.parentElement;const v=x.lastElementChild.dataset.viewportType==="window";let T;v&&(T=x.ownerDocument.defaultView);const k=i?a?i.scrollLeft:i.scrollTop:v?a?T.scrollX||T.document.documentElement.scrollLeft:T.scrollY||T.document.documentElement.scrollTop:a?x.scrollLeft:x.scrollTop,g=i?a?i.scrollWidth:i.scrollHeight:v?a?T.document.documentElement.scrollWidth:T.document.documentElement.scrollHeight:a?x.scrollWidth:x.scrollHeight,m=i?a?i.offsetWidth:i.offsetHeight:v?a?T.innerWidth:T.innerHeight:a?x.offsetWidth:x.offsetHeight;s({scrollHeight:g,scrollTop:Math.max(k,0),viewportHeight:m}),l?.(a?Wn("column-gap",getComputedStyle(f).columnGap,o):Wn("row-gap",getComputedStyle(f).rowGap,o)),p!==null&&e(p)},[e,t,o,l,i,s,a]);return mn(u,n,c)}function Xs(e,t,n,s){const o=e.length;if(o===0)return null;const l=[];for(let i=0;i<o;i++){const a=e.item(i);if(a.dataset.index===void 0)continue;const c=parseInt(a.dataset.index),u=parseFloat(a.dataset.knownSize),f=t(a,n);if(f===0&&s("Zero-sized element, this should not happen",{child:a},Ce.ERROR),f===u)continue;const p=l[l.length-1];l.length===0||p.size!==f||p.endIndex!==c-1?l.push({endIndex:c,size:f,startIndex:c}):l[l.length-1].endIndex++}return l}function Wn(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,Ce.WARN),t==="normal"?0:parseInt(t??"0",10)}function jr(e,t,n){const s=F.useRef(null),o=F.useCallback(c=>{if(!(c!=null&&c.offsetParent))return;const u=c.getBoundingClientRect(),f=u.width;let p,x;if(t){const v=t.getBoundingClientRect(),T=u.top-v.top;x=v.height-Math.max(0,T),p=T+t.scrollTop}else{const v=i.current.ownerDocument.defaultView;x=v.innerHeight-Math.max(0,u.top),p=u.top+v.scrollY}s.current={offsetTop:p,visibleHeight:x,visibleWidth:f},e(s.current)},[e,t]),{callbackRef:l,ref:i}=mn(o,!0,n),a=F.useCallback(()=>{o(i.current)},[o,i]);return F.useEffect(()=>{var c;if(t){t.addEventListener("scroll",a);const u=new ResizeObserver(()=>{requestAnimationFrame(a)});return u.observe(t),()=>{t.removeEventListener("scroll",a),u.unobserve(t)}}else{const u=(c=i.current)==null?void 0:c.ownerDocument.defaultView;return u?.addEventListener("scroll",a),u?.addEventListener("resize",a),()=>{u?.removeEventListener("scroll",a),u?.removeEventListener("resize",a)}}},[a,t,i]),l}const Ie=$(()=>{const e=U(),t=U(),n=I(0),s=U(),o=I(0),l=U(),i=U(),a=I(0),c=I(0),u=I(0),f=I(0),p=U(),x=U(),v=I(!1),T=I(!1),k=I(!1);return M(j(e,L(({scrollTop:g})=>g)),t),M(j(e,L(({scrollHeight:g})=>g)),i),M(t,o),{deviation:n,fixedFooterHeight:u,fixedHeaderHeight:c,footerHeight:f,headerHeight:a,horizontalDirection:T,scrollBy:x,scrollContainerState:e,scrollHeight:i,scrollingInProgress:v,scrollTo:p,scrollTop:t,skipAnimationFrameInResizeObserver:k,smoothScrollTargetReached:s,statefulScrollTop:o,viewportHeight:l}},[],{singleton:!0}),mt={lvl:0};function wr(e,t){const n=e.length;if(n===0)return[];let{index:s,value:o}=t(e[0]);const l=[];for(let i=1;i<n;i++){const{index:a,value:c}=t(e[i]);l.push({end:a-1,start:s,value:o}),s=a,o=c}return l.push({end:1/0,start:s,value:o}),l}function ee(e){return e===mt}function ht(e,t){if(!ee(e))return t===e.k?e.v:t<e.k?ht(e.l,t):ht(e.r,t)}function Be(e,t,n="k"){if(ee(e))return[-1/0,void 0];if(Number(e[n])===t)return[e.k,e.v];if(Number(e[n])<t){const s=Be(e.r,t,n);return s[0]===-1/0?[e.k,e.v]:s}return Be(e.l,t,n)}function Ne(e,t,n){return ee(e)?Ir(t,n,1):t===e.k?he(e,{k:t,v:n}):t<e.k?_n(he(e,{l:Ne(e.l,t,n)})):_n(he(e,{r:Ne(e.r,t,n)}))}function rt(){return mt}function st(e,t,n){if(ee(e))return[];const s=Be(e,t)[0];return Zs(nn(e,s,n))}function tn(e,t){if(ee(e))return mt;const{k:n,l:s,r:o}=e;if(t===n){if(ee(s))return o;if(ee(o))return s;{const[l,i]=yr(s);return Et(he(e,{k:l,l:Sr(s),v:i}))}}else return t<n?Et(he(e,{l:tn(s,t)})):Et(he(e,{r:tn(o,t)}))}function Ye(e){return ee(e)?[]:[...Ye(e.l),{k:e.k,v:e.v},...Ye(e.r)]}function nn(e,t,n){if(ee(e))return[];const{k:s,l:o,r:l,v:i}=e;let a=[];return s>t&&(a=a.concat(nn(o,t,n))),s>=t&&s<=n&&a.push({k:s,v:i}),s<=n&&(a=a.concat(nn(l,t,n))),a}function Et(e){const{l:t,lvl:n,r:s}=e;if(s.lvl>=n-1&&t.lvl>=n-1)return e;if(n>s.lvl+1){if(_t(t))return Tr(he(e,{lvl:n-1}));if(!ee(t)&&!ee(t.r))return he(t.r,{l:he(t,{r:t.r.l}),lvl:n,r:he(e,{l:t.r.r,lvl:n-1})});throw new Error("Unexpected empty nodes")}else{if(_t(e))return rn(he(e,{lvl:n-1}));if(!ee(s)&&!ee(s.l)){const o=s.l,l=_t(o)?s.lvl-1:s.lvl;return he(o,{l:he(e,{lvl:n-1,r:o.l}),lvl:o.lvl+1,r:rn(he(s,{l:o.r,lvl:l}))})}else throw new Error("Unexpected empty nodes")}}function he(e,t){return Ir(t.k!==void 0?t.k:e.k,t.v!==void 0?t.v:e.v,t.lvl!==void 0?t.lvl:e.lvl,t.l!==void 0?t.l:e.l,t.r!==void 0?t.r:e.r)}function Sr(e){return ee(e.r)?e.l:Et(he(e,{r:Sr(e.r)}))}function _t(e){return ee(e)||e.lvl>e.r.lvl}function yr(e){return ee(e.r)?[e.k,e.v]:yr(e.r)}function Ir(e,t,n,s=mt,o=mt){return{k:e,l:s,lvl:n,r:o,v:t}}function _n(e){return rn(Tr(e))}function Tr(e){const{l:t}=e;return!ee(t)&&t.lvl===e.lvl?he(t,{r:he(e,{l:t.r})}):e}function rn(e){const{lvl:t,r:n}=e;return!ee(n)&&!ee(n.r)&&n.lvl===t&&n.r.lvl===t?he(n,{l:he(e,{r:n.l}),lvl:t+1}):e}function Zs(e){return wr(e,({k:t,v:n})=>({index:t,value:n}))}function Cr(e,t){return!!(e&&e.startIndex===t.startIndex&&e.endIndex===t.endIndex)}function ft(e,t){return!!(e&&e[0]===t[0]&&e[1]===t[1])}const hn=$(()=>({recalcInProgress:I(!1)}),[],{singleton:!0});function Nr(e,t,n){return e[Ht(e,t,n)]}function Ht(e,t,n,s=0){let o=e.length-1;for(;s<=o;){const l=Math.floor((s+o)/2),i=e[l],a=n(i,t);if(a===0)return l;if(a===-1){if(o-s<2)return l-1;o=l-1}else{if(o===s)return l;s=l+1}}throw new Error(`Failed binary finding record in array - ${e.join(",")}, searched for ${t}`)}function eo(e,t,n,s){const o=Ht(e,t,s),l=Ht(e,n,s,o);return e.slice(o,l+1)}function Ge(e,t){return Math.round(e.getBoundingClientRect()[t])}function Ft(e){return!ee(e.groupOffsetTree)}function fn({index:e},t){return t===e?0:t<e?-1:1}function to(){return{groupIndices:[],groupOffsetTree:rt(),lastIndex:0,lastOffset:0,lastSize:0,offsetTree:[],sizeTree:rt()}}function no(e,t){let n=ee(e)?0:1/0;for(const s of t){const{endIndex:o,size:l,startIndex:i}=s;if(n=Math.min(n,i),ee(e)){e=Ne(e,0,l);continue}const a=st(e,i-1,o+1);if(a.some(co(s)))continue;let c=!1,u=!1;for(const{end:f,start:p,value:x}of a)c?(o>=p||l===x)&&(e=tn(e,p)):(u=x!==l,c=!0),f>o&&o>=p&&x!==l&&(e=Ne(e,o+1,x));u&&(e=Ne(e,i,l))}return[e,n]}function ro(e){return typeof e.groupIndex<"u"}function so({offset:e},t){return t===e?0:t<e?-1:1}function gt(e,t,n){if(t.length===0)return 0;const{index:s,offset:o,size:l}=Nr(t,e,fn),i=e-s,a=l*i+(i-1)*n+o;return a>0?a+n:a}function kr(e,t){if(!Ft(t))return e;let n=0;for(;t.groupIndices[n]<=e+n;)n++;return e+n}function Rr(e,t,n){if(ro(e))return t.groupIndices[e.groupIndex]+1;{const s=e.index==="LAST"?n:e.index;let o=kr(s,t);return o=Math.max(0,o,Math.min(n,o)),o}}function oo(e,t,n,s=0){return s>0&&(t=Math.max(t,Nr(e,s,fn).offset)),wr(eo(e,t,n,so),ao)}function lo(e,[t,n,s,o]){t.length>0&&s("received item sizes",t,Ce.DEBUG);const l=e.sizeTree;let i=l,a=0;if(n.length>0&&ee(l)&&t.length===2){const x=t[0].size,v=t[1].size;i=n.reduce((T,k)=>Ne(Ne(T,k,x),k+1,v),i)}else[i,a]=no(i,t);if(i===l)return e;const{lastIndex:c,lastOffset:u,lastSize:f,offsetTree:p}=sn(e.offsetTree,a,i,o);return{groupIndices:n,groupOffsetTree:n.reduce((x,v)=>Ne(x,v,gt(v,p,o)),rt()),lastIndex:c,lastOffset:u,lastSize:f,offsetTree:p,sizeTree:i}}function io(e){return Ye(e).map(({k:t,v:n},s,o)=>{const l=o[s+1];return{endIndex:l?l.k-1:1/0,size:n,startIndex:t}})}function Vn(e,t){let n=0,s=0;for(;n<e;)n+=t[s+1]-t[s]-1,s++;return s-(n===e?0:1)}function sn(e,t,n,s){let o=e,l=0,i=0,a=0,c=0;if(t!==0){c=Ht(o,t-1,fn),a=o[c].offset;const u=Be(n,t-1);l=u[0],i=u[1],o.length&&o[c].size===Be(n,t)[1]&&(c-=1),o=o.slice(0,c+1)}else o=[];for(const{start:u,value:f}of st(n,t,1/0)){const p=u-l,x=p*i+a+p*s;o.push({index:u,offset:x,size:f}),l=u,a=x,i=f}return{lastIndex:l,lastOffset:a,lastSize:i,offsetTree:o}}function ao(e){return{index:e.index,value:e}}function co(e){const{endIndex:t,size:n,startIndex:s}=e;return o=>o.start===s&&(o.end===t||o.end===1/0)&&o.value===n}const uo={offsetHeight:"height",offsetWidth:"width"},We=$(([{log:e},{recalcInProgress:t}])=>{const n=U(),s=U(),o=je(s,0),l=U(),i=U(),a=I(0),c=I([]),u=I(void 0),f=I(void 0),p=I(void 0),x=I(void 0),v=I((d,b)=>Ge(d,uo[b])),T=I(void 0),k=I(0),g=to(),m=je(j(n,G(c,e,k),Pe(lo,g),re()),g),h=je(j(c,re(),Pe((d,b)=>({current:b,prev:d.current}),{current:[],prev:[]}),L(({prev:d})=>d)),[]);M(j(c,A(d=>d.length>0),G(m,k),L(([d,b,y])=>{const z=d.reduce((S,C,D)=>Ne(S,C,gt(C,b.offsetTree,y)||D),rt());return{...b,groupIndices:d,groupOffsetTree:z}})),m),M(j(s,G(m),A(([d,{lastIndex:b}])=>d<b),L(([d,{lastIndex:b,lastSize:y}])=>[{endIndex:b,size:y,startIndex:d}])),n),M(u,f);const w=je(j(u,L(d=>d===void 0)),!0);M(j(f,A(d=>d!==void 0&&ee(le(m).sizeTree)),L(d=>{const b=le(p),y=le(c).length>0;return b?y?[{endIndex:0,size:b,startIndex:0},{endIndex:1,size:d,startIndex:1}]:[]:[{endIndex:0,size:d,startIndex:0}]})),n),M(j(x,A(d=>d!==void 0&&d.length>0&&ee(le(m).sizeTree)),L(d=>{const b=[];let y=d[0],z=0;for(let S=1;S<d.length;S++){const C=d[S];C!==y&&(b.push({endIndex:S-1,size:y,startIndex:z}),y=C,z=S)}return b.push({endIndex:d.length-1,size:y,startIndex:z}),b})),n),M(j(c,G(p,f),A(([,d,b])=>d!==void 0&&b!==void 0),L(([d,b,y])=>{const z=[];for(let S=0;S<d.length;S++){const C=d[S],D=d[S+1];z.push({startIndex:C,endIndex:C,size:b}),D!==void 0&&z.push({startIndex:C+1,endIndex:D-1,size:y})}return z})),n);const H=ke(j(n,G(m),Pe(({sizes:d},[b,y])=>({changed:y!==d,sizes:y}),{changed:!1,sizes:g}),L(d=>d.changed)));Y(j(a,Pe((d,b)=>({diff:d.prev-b,prev:b}),{diff:0,prev:0}),L(d=>d.diff)),d=>{const{groupIndices:b}=le(m);if(d>0)q(t,!0),q(l,d+Vn(d,b));else if(d<0){const y=le(h);y.length>0&&(d-=Vn(-d,y)),q(i,d)}}),Y(j(a,G(e)),([d,b])=>{d<0&&b("`firstItemIndex` prop should not be set to less than zero. If you don't know the total count, just use a very high value",{firstItemIndex:a},Ce.ERROR)});const E=ke(l);M(j(l,G(m),L(([d,b])=>{const y=b.groupIndices.length>0,z=[],S=b.lastSize;if(y){const C=ht(b.sizeTree,0);let D=0,B=0;for(;D<d;){const Q=b.groupIndices[B],X=b.groupIndices.length===B+1?1/0:b.groupIndices[B+1]-Q-1;z.push({endIndex:Q,size:C,startIndex:Q}),z.push({endIndex:Q+1+X-1,size:S,startIndex:Q+1}),B++,D+=X+1}const V=Ye(b.sizeTree);return D!==d&&V.shift(),V.reduce((Q,{k:X,v:ne})=>{let we=Q.ranges;return Q.prevSize!==0&&(we=[...Q.ranges,{endIndex:X+d-1,size:Q.prevSize,startIndex:Q.prevIndex}]),{prevIndex:X+d,prevSize:ne,ranges:we}},{prevIndex:d,prevSize:0,ranges:z}).ranges}return Ye(b.sizeTree).reduce((C,{k:D,v:B})=>({prevIndex:D+d,prevSize:B,ranges:[...C.ranges,{endIndex:D+d-1,size:C.prevSize,startIndex:C.prevIndex}]}),{prevIndex:0,prevSize:S,ranges:[]}).ranges})),n);const R=ke(j(i,G(m,k),L(([d,{offsetTree:b},y])=>{const z=-d;return gt(z,b,y)})));return M(j(i,G(m,k),L(([d,b,y])=>{if(b.groupIndices.length>0){if(ee(b.sizeTree))return b;let z=rt();const S=le(h);let C=0,D=0,B=0;for(;C<-d;){B=S[D];const V=S[D+1]-B-1;D++,C+=V+1}if(z=Ye(b.sizeTree).reduce((V,{k:Q,v:X})=>Ne(V,Math.max(0,Q+d),X),z),C!==-d){const V=ht(b.sizeTree,B);z=Ne(z,0,V);const Q=Be(b.sizeTree,-d+1)[1];z=Ne(z,1,Q)}return{...b,sizeTree:z,...sn(b.offsetTree,0,z,y)}}else{const z=Ye(b.sizeTree).reduce((S,{k:C,v:D})=>Ne(S,Math.max(0,C+d),D),rt());return{...b,sizeTree:z,...sn(b.offsetTree,0,z,y)}}})),m),{beforeUnshiftWith:E,data:T,defaultItemSize:f,firstItemIndex:a,fixedItemSize:u,fixedGroupSize:p,gap:k,groupIndices:c,heightEstimates:x,itemSize:v,listRefresh:H,shiftWith:i,shiftWithOffset:R,sizeRanges:n,sizes:m,statefulTotalCount:o,totalCount:s,trackItemSizes:w,unshiftWith:l}},se(Ue,hn),{singleton:!0});function mo(e){return e.reduce((t,n)=>(t.groupIndices.push(t.totalCount),t.totalCount+=n+1,t),{groupIndices:[],totalCount:0})}const Er=$(([{groupIndices:e,sizes:t,totalCount:n},{headerHeight:s,scrollTop:o}])=>{const l=U(),i=U(),a=ke(j(l,L(mo)));return M(j(a,L(c=>c.totalCount)),n),M(j(a,L(c=>c.groupIndices)),e),M(j(de(o,t,s),A(([c,u])=>Ft(u)),L(([c,u,f])=>Be(u.groupOffsetTree,Math.max(c-f,0),"v")[0]),re(),L(c=>[c])),i),{groupCounts:l,topItemsIndexes:i}},se(We,Ie)),Ke=$(([{log:e}])=>{const t=I(!1),n=ke(j(t,A(s=>s),re()));return Y(t,s=>{s&&le(e)("props updated",{},Ce.DEBUG)}),{didMount:n,propsReady:t}},se(Ue),{singleton:!0}),ho=typeof document<"u"&&"scrollBehavior"in document.documentElement.style;function zr(e){const t=typeof e=="number"?{index:e}:e;return t.align||(t.align="start"),(!t.behavior||!ho)&&(t.behavior="auto"),t.offset||(t.offset=0),t}const bt=$(([{gap:e,listRefresh:t,sizes:n,totalCount:s},{fixedFooterHeight:o,fixedHeaderHeight:l,footerHeight:i,headerHeight:a,scrollingInProgress:c,scrollTo:u,smoothScrollTargetReached:f,viewportHeight:p},{log:x}])=>{const v=U(),T=U(),k=I(0);let g=null,m=null,h=null;function w(){g&&(g(),g=null),h&&(h(),h=null),m&&(clearTimeout(m),m=null),q(c,!1)}return M(j(v,G(n,p,s,k,a,i,x),G(e,l,o),L(([[H,E,R,d,b,y,z,S],C,D,B])=>{const V=zr(H),{align:Q,behavior:X,offset:ne}=V,we=d-1,ge=Rr(V,E,we);let xe=gt(ge,E.offsetTree,C)+y;Q==="end"?(xe+=D+Be(E.sizeTree,ge)[1]-R+B,ge===we&&(xe+=z)):Q==="center"?xe+=(D+Be(E.sizeTree,ge)[1]-R+B)/2:xe-=b,ne&&(xe+=ne);const Re=Se=>{w(),Se?(S("retrying to scroll to",{location:H},Ce.DEBUG),q(v,H)):(q(T,!0),S("list did not change, scroll successful",{},Ce.DEBUG))};if(w(),X==="smooth"){let Se=!1;h=Y(t,Fe=>{Se=Se||Fe}),g=Oe(f,()=>{Re(Se)})}else g=Oe(j(t,fo(150)),Re);return m=setTimeout(()=>{w()},1200),q(c,!0),S("scrolling from index to",{behavior:X,index:ge,top:xe},Ce.DEBUG),{behavior:X,top:xe}})),u),{scrollTargetReached:T,scrollToIndex:v,topListHeight:k}},se(We,Ie,Ue),{singleton:!0});function fo(e){return t=>{const n=setTimeout(()=>{t(!1)},e);return s=>{s&&(t(!0),clearTimeout(n))}}}function gn(e,t){e==0?t():requestAnimationFrame(()=>{gn(e-1,t)})}function xn(e,t){const n=t-1;return typeof e=="number"?e:e.index==="LAST"?n:e.index}const jt=$(([{defaultItemSize:e,listRefresh:t,sizes:n},{scrollTop:s},{scrollTargetReached:o,scrollToIndex:l},{didMount:i}])=>{const a=I(!0),c=I(0),u=I(!0);return M(j(i,G(c),A(([f,p])=>!!p),De(!1)),a),M(j(i,G(c),A(([f,p])=>!!p),De(!1)),u),Y(j(de(t,i),G(a,n,e,u),A(([[,f],p,{sizeTree:x},v,T])=>f&&(!ee(x)||un(v))&&!p&&!T),G(c)),([,f])=>{Oe(o,()=>{q(u,!0)}),gn(4,()=>{Oe(s,()=>{q(a,!0)}),q(l,f)})}),{initialItemFinalLocationReached:u,initialTopMostItemIndex:c,scrolledToInitialItem:a}},se(We,Ie,bt,Ke),{singleton:!0});function Hr(e,t){return Math.abs(e-t)<1.01}const xt="up",ct="down",go="none",xo={atBottom:!1,notAtBottomBecause:"NOT_SHOWING_LAST_ITEM",state:{offsetBottom:0,scrollHeight:0,scrollTop:0,viewportHeight:0}},po=0,wt=$(([{footerHeight:e,headerHeight:t,scrollBy:n,scrollContainerState:s,scrollTop:o,viewportHeight:l}])=>{const i=I(!1),a=I(!0),c=U(),u=U(),f=I(4),p=I(po),x=je(j(en(j(P(o),Xe(1),De(!0)),j(P(o),Xe(1),De(!1),An(100))),re()),!1),v=je(j(en(j(n,De(!0)),j(n,De(!1),An(200))),re()),!1);M(j(de(P(o),P(p)),L(([h,w])=>h<=w),re()),a),M(j(a,_e(50)),u);const T=ke(j(de(s,P(l),P(t),P(e),P(f)),Pe((h,[{scrollHeight:w,scrollTop:H},E,R,d,b])=>{const y=H+E-w>-b,z={scrollHeight:w,scrollTop:H,viewportHeight:E};if(y){let C,D;return H>h.state.scrollTop?(C="SCROLLED_DOWN",D=h.state.scrollTop-H):(C="SIZE_DECREASED",D=h.state.scrollTop-H||h.scrollTopDelta),{atBottom:!0,atBottomBecause:C,scrollTopDelta:D,state:z}}let S;return z.scrollHeight>h.state.scrollHeight?S="SIZE_INCREASED":E<h.state.viewportHeight?S="VIEWPORT_HEIGHT_DECREASING":H<h.state.scrollTop?S="SCROLLING_UPWARDS":S="NOT_FULLY_SCROLLED_TO_LAST_ITEM_BOTTOM",{atBottom:!1,notAtBottomBecause:S,state:z}},xo),re((h,w)=>h&&h.atBottom===w.atBottom))),k=je(j(s,Pe((h,{scrollHeight:w,scrollTop:H,viewportHeight:E})=>{if(Hr(h.scrollHeight,w))return{changed:!1,jump:0,scrollHeight:w,scrollTop:H};{const R=w-(H+E)<1;return h.scrollTop!==H&&R?{changed:!0,jump:h.scrollTop-H,scrollHeight:w,scrollTop:H}:{changed:!0,jump:0,scrollHeight:w,scrollTop:H}}},{changed:!1,jump:0,scrollHeight:0,scrollTop:0}),A(h=>h.changed),L(h=>h.jump)),0);M(j(T,L(h=>h.atBottom)),i),M(j(i,_e(50)),c);const g=I(ct);M(j(s,L(({scrollTop:h})=>h),re(),Pe((h,w)=>le(v)?{direction:h.direction,prevScrollTop:w}:{direction:w<h.prevScrollTop?xt:ct,prevScrollTop:w},{direction:ct,prevScrollTop:0}),L(h=>h.direction)),g),M(j(s,_e(50),De(go)),g);const m=I(0);return M(j(x,A(h=>!h),De(0)),m),M(j(o,_e(100),G(x),A(([h,w])=>!!w),Pe(([h,w],[H])=>[w,H],[0,0]),L(([h,w])=>w-h)),m),{atBottomState:T,atBottomStateChange:c,atBottomThreshold:f,atTopStateChange:u,atTopThreshold:p,isAtBottom:i,isAtTop:a,isScrolling:x,lastJumpDueToItemResize:k,scrollDirection:g,scrollVelocity:m}},se(Ie)),pt="top",vt="bottom",qn="none";function Gn(e,t,n){return typeof e=="number"?n===xt&&t===pt||n===ct&&t===vt?e:0:n===xt?t===pt?e.main:e.reverse:t===vt?e.main:e.reverse}function Qn(e,t){var n;return typeof e=="number"?e:(n=e[t])!=null?n:0}const pn=$(([{deviation:e,fixedHeaderHeight:t,headerHeight:n,scrollTop:s,viewportHeight:o}])=>{const l=U(),i=I(0),a=I(0),c=I(0),u=je(j(de(P(s),P(o),P(n),P(l,ft),P(c),P(i),P(t),P(e),P(a)),L(([f,p,x,[v,T],k,g,m,h,w])=>{const H=f-h,E=g+m,R=Math.max(x-H,0);let d=qn;const b=Qn(w,pt),y=Qn(w,vt);return v-=h,v+=x+m,T+=x+m,T-=h,v>f+E-b&&(d=xt),T<f-R+p+y&&(d=ct),d!==qn?[Math.max(H-x-Gn(k,pt,d)-b,0),H-R-m+p+Gn(k,vt,d)+y]:null}),A(f=>f!=null),re(ft)),[0,0]);return{increaseViewportBy:a,listBoundary:l,overscan:c,topListHeight:i,visibleRange:u}},se(Ie),{singleton:!0});function vo(e,t,n){if(Ft(t)){const s=kr(e,t);return[{index:Be(t.groupOffsetTree,s)[0],offset:0,size:0},{data:n?.[0],index:s,offset:0,size:0}]}return[{data:n?.[0],index:e,offset:0,size:0}]}const Vt={bottom:0,firstItemIndex:0,items:[],offsetBottom:0,offsetTop:0,top:0,topItems:[],topListHeight:0,totalCount:0};function zt(e,t,n,s,o,l){const{lastIndex:i,lastOffset:a,lastSize:c}=o;let u=0,f=0;if(e.length>0){u=e[0].offset;const k=e[e.length-1];f=k.offset+k.size}const p=n-i,x=a+p*c+(p-1)*s,v=u,T=x-f;return{bottom:f,firstItemIndex:l,items:Un(e,o,l),offsetBottom:T,offsetTop:u,top:v,topItems:Un(t,o,l),topListHeight:t.reduce((k,g)=>g.size+k,0),totalCount:n}}function Lr(e,t,n,s,o,l){let i=0;if(n.groupIndices.length>0)for(const f of n.groupIndices){if(f-i>=e)break;i++}const a=e+i,c=xn(t,a),u=Array.from({length:a}).map((f,p)=>({data:l[p+c],index:p+c,offset:0,size:0}));return zt(u,[],a,o,n,s)}function Un(e,t,n){if(e.length===0)return[];if(!Ft(t))return e.map(u=>({...u,index:u.index+n,originalIndex:u.index}));const s=e[0].index,o=e[e.length-1].index,l=[],i=st(t.groupOffsetTree,s,o);let a,c=0;for(const u of e){(!a||a.end<u.index)&&(a=i.shift(),c=t.groupIndices.indexOf(a.start));let f;u.index===a.start?f={index:c,type:"group"}:f={groupIndex:c,index:u.index-(c+1)+n},l.push({...f,data:u.data,offset:u.offset,originalIndex:u.index,size:u.size})}return l}function Kn(e,t){var n;return e===void 0?0:typeof e=="number"?e:(n=e[t])!=null?n:0}const et=$(([{data:e,firstItemIndex:t,gap:n,sizes:s,totalCount:o},l,{listBoundary:i,topListHeight:a,visibleRange:c},{initialTopMostItemIndex:u,scrolledToInitialItem:f},{topListHeight:p},x,{didMount:v},{recalcInProgress:T}])=>{const k=I([]),g=I(0),m=U(),h=I(0);M(l.topItemsIndexes,k);const w=je(j(de(v,T,P(c,ft),P(o),P(s),P(u),f,P(k),P(t),P(n),P(h),e),A(([d,b,,y,,,,,,,,z])=>{const S=z&&z.length!==y;return d&&!b&&!S}),L(([,,[d,b],y,z,S,C,D,B,V,Q,X])=>{var ne,we,ge,xe;const Re=z,{offsetTree:Se,sizeTree:Fe}=Re,$e=le(g);if(y===0)return{...Vt,totalCount:y};if(d===0&&b===0)return $e===0?{...Vt,totalCount:y}:Lr($e,S,z,B,V,X||[]);if(ee(Fe))return $e>0?null:zt(vo(xn(S,y),Re,X),[],y,V,Re,B);const Ve=[];if(D.length>0){const ie=D[0],ae=D[D.length-1];let fe=0;for(const ue of st(Fe,ie,ae)){const Z=ue.value,te=Math.max(ue.start,ie),Ee=Math.min(ue.end,ae);for(let pe=te;pe<=Ee;pe++)Ve.push({data:X?.[pe],index:pe,offset:fe,size:Z}),fe+=Z}}if(!C)return zt([],Ve,y,V,Re,B);const Me=D.length>0?D[D.length-1]+1:0,N=oo(Se,d,b,Me);if(N.length===0)return null;const _=y-1,J=Bt([],ie=>{for(const ae of N){const fe=ae.value;let ue=fe.offset,Z=ae.start;const te=fe.size;if(fe.offset<d){Z+=Math.floor((d-fe.offset+V)/(te+V));const pe=Z-ae.start;ue+=pe*te+pe*V}Z<Me&&(ue+=(Me-Z)*te,Z=Me);const Ee=Math.min(ae.end,_);for(let pe=Z;pe<=Ee&&!(ue>=b);pe++)ie.push({data:X?.[pe],index:pe,offset:ue,size:te}),ue+=te+V}}),ce=Kn(Q,pt),me=Kn(Q,vt);if(J.length>0&&(ce>0||me>0)){const ie=J[0],ae=J[J.length-1];if(ce>0&&ie.index>Me){const fe=Math.min(ce,ie.index-Me),ue=[];let Z=ie.offset;for(let te=ie.index-1;te>=ie.index-fe;te--){const Ee=(we=(ne=st(Fe,te,te)[0])==null?void 0:ne.value)!=null?we:ie.size;Z-=Ee+V,ue.unshift({data:X?.[te],index:te,offset:Z,size:Ee})}J.unshift(...ue)}if(me>0&&ae.index<_){const fe=Math.min(me,_-ae.index);let ue=ae.offset+ae.size+V;for(let Z=ae.index+1;Z<=ae.index+fe;Z++){const te=(xe=(ge=st(Fe,Z,Z)[0])==null?void 0:ge.value)!=null?xe:ae.size;J.push({data:X?.[Z],index:Z,offset:ue,size:te}),ue+=te+V}}}return zt(J,Ve,y,V,Re,B)}),A(d=>d!==null),re()),Vt);M(j(e,A(un),L(d=>d?.length)),o),M(j(w,L(d=>d.topListHeight)),p),M(p,a),M(j(w,L(d=>[d.top,d.bottom])),i),M(j(w,L(d=>d.items)),m);const H=ke(j(w,A(({items:d})=>d.length>0),G(o,e),A(([{items:d},b])=>d[d.length-1].originalIndex===b-1),L(([,d,b])=>[d-1,b]),re(ft),L(([d])=>d))),E=ke(j(w,_e(200),A(({items:d,topItems:b})=>d.length>0&&d[0].originalIndex===b.length),L(({items:d})=>d[0].index),re())),R=ke(j(w,A(({items:d})=>d.length>0),L(({items:d})=>{let b=0,y=d.length-1;for(;d[b].type==="group"&&b<y;)b++;for(;d[y].type==="group"&&y>b;)y--;return{endIndex:d[y].index,startIndex:d[b].index}}),re(Cr)));return{endReached:H,initialItemCount:g,itemsRendered:m,listState:w,minOverscanItemCount:h,rangeChanged:R,startReached:E,topItemsIndexes:k,...x}},se(We,Er,pn,jt,bt,wt,Ke,hn),{singleton:!0}),Or=$(([{fixedFooterHeight:e,fixedHeaderHeight:t,footerHeight:n,headerHeight:s},{listState:o}])=>{const l=U(),i=je(j(de(n,e,s,t,o),L(([a,c,u,f,p])=>a+c+u+f+p.offsetBottom+p.bottom)),0);return M(P(i),l),{totalListHeight:i,totalListHeightChanged:l}},se(Ie,et),{singleton:!0}),bo=$(([{viewportHeight:e},{totalListHeight:t}])=>{const n=I(!1),s=je(j(de(n,e,t),A(([o])=>o),L(([,o,l])=>Math.max(0,o-l)),_e(0),re()),0);return{alignToBottom:n,paddingTopAddition:s}},se(Ie,Or),{singleton:!0}),Br=$(()=>({context:I(null)})),jo=({itemBottom:e,itemTop:t,locationParams:{align:n,behavior:s,...o},viewportBottom:l,viewportTop:i})=>t<i?{...o,align:n??"start",behavior:s}:e>l?{...o,align:n??"end",behavior:s}:null,Fr=$(([{gap:e,sizes:t,totalCount:n},{fixedFooterHeight:s,fixedHeaderHeight:o,headerHeight:l,scrollingInProgress:i,scrollTop:a,viewportHeight:c},{scrollToIndex:u}])=>{const f=U();return M(j(f,G(t,c,n,l,o,s,a),G(e),L(([[p,x,v,T,k,g,m,h],w])=>{const{align:H,behavior:E,calculateViewLocation:R=jo,done:d,...b}=p,y=Rr(p,x,T-1),z=gt(y,x.offsetTree,w)+k+g,S=z+Be(x.sizeTree,y)[1],C=h+g,D=h+v-m,B=R({itemBottom:S,itemTop:z,locationParams:{align:H,behavior:E,...b},viewportBottom:D,viewportTop:C});return B?d&&Oe(j(i,A(V=>!V),Xe(le(i)?1:2)),d):d&&d(),B}),A(p=>p!==null)),u),{scrollIntoView:f}},se(We,Ie,bt,et,Ue),{singleton:!0});function $n(e){return e?e==="smooth"?"smooth":"auto":!1}const wo=(e,t)=>typeof e=="function"?$n(e(t)):t&&$n(e),So=$(([{listRefresh:e,totalCount:t,fixedItemSize:n,data:s},{atBottomState:o,isAtBottom:l},{scrollToIndex:i},{scrolledToInitialItem:a},{didMount:c,propsReady:u},{log:f},{scrollingInProgress:p},{context:x},{scrollIntoView:v}])=>{const T=I(!1),k=U();let g=null;function m(E){q(i,{align:"end",behavior:E,index:"LAST"})}Y(j(de(j(P(t),Xe(1)),c),G(P(T),l,a,p),L(([[E,R],d,b,y,z])=>{let S=R&&y,C="auto";return S&&(C=wo(d,b||z),S=S&&!!C),{followOutputBehavior:C,shouldFollow:S,totalCount:E}}),A(({shouldFollow:E})=>E)),({followOutputBehavior:E,totalCount:R})=>{g&&(g(),g=null),le(n)?requestAnimationFrame(()=>{le(f)("following output to ",{totalCount:R},Ce.DEBUG),m(E)}):g=Oe(e,()=>{le(f)("following output to ",{totalCount:R},Ce.DEBUG),m(E),g=null})});function h(E){const R=Oe(o,d=>{E&&!d.atBottom&&d.notAtBottomBecause==="SIZE_INCREASED"&&!g&&(le(f)("scrolling to bottom due to increased size",{},Ce.DEBUG),m("auto"))});setTimeout(R,100)}Y(j(de(P(T),t,u),A(([E,,R])=>E&&R),Pe(({value:E},[,R])=>({refreshed:E===R,value:R}),{refreshed:!1,value:0}),A(({refreshed:E})=>E),G(T,t)),([,E])=>{le(a)&&h(E!==!1)}),Y(k,()=>{h(le(T)!==!1)}),Y(de(P(T),o),([E,R])=>{E&&!R.atBottom&&R.notAtBottomBecause==="VIEWPORT_HEIGHT_DECREASING"&&m("auto")});const w=I(null),H=U();return M(en(j(P(s),L(E=>{var R;return(R=E?.length)!=null?R:0})),j(P(t))),H),Y(j(de(j(H,Xe(1)),c),G(P(w),a,p,x),L(([[E,R],d,b,y,z])=>R&&b&&d?.({context:z,totalCount:E,scrollingInProgress:y})),A(E=>!!E),_e(0)),E=>{g&&(g(),g=null),le(n)?requestAnimationFrame(()=>{le(f)("scrolling into view",{}),q(v,E)}):g=Oe(e,()=>{le(f)("scrolling into view",{}),q(v,E),g=null})}),{autoscrollToBottom:k,followOutput:T,scrollIntoViewOnChange:w}},se(We,wt,bt,jt,Ke,Ue,Ie,Br,Fr)),yo=$(([{data:e,firstItemIndex:t,gap:n,sizes:s},{initialTopMostItemIndex:o},{initialItemCount:l,listState:i},{didMount:a}])=>(M(j(a,G(l),A(([,c])=>c!==0),G(o,s,t,n,e),L(([[,c],u,f,p,x,v=[]])=>Lr(c,u,f,p,x,v))),i),{}),se(We,jt,et,Ke),{singleton:!0}),Io=$(([{didMount:e},{scrollTo:t},{listState:n}])=>{const s=I(0);return Y(j(e,G(s),A(([,o])=>o!==0),L(([,o])=>({top:o}))),o=>{Oe(j(n,Xe(1),A(l=>l.items.length>1)),()=>{requestAnimationFrame(()=>{q(t,o)})})}),{initialScrollTop:s}},se(Ke,Ie,et),{singleton:!0}),Mr=$(([{scrollVelocity:e}])=>{const t=I(!1),n=U(),s=I(!1);return M(j(e,G(s,t,n),A(([o,l])=>!!l),L(([o,l,i,a])=>{const{enter:c,exit:u}=l;if(i){if(u(o,a))return!1}else if(c(o,a))return!0;return i}),re()),t),Y(j(de(t,e,n),G(s)),([[o,l,i],a])=>{o&&a&&a.change&&a.change(l,i)}),{isSeeking:t,scrollSeekConfiguration:s,scrollSeekRangeChanged:n,scrollVelocity:e}},se(wt),{singleton:!0}),vn=$(([{scrollContainerState:e,scrollTo:t}])=>{const n=U(),s=U(),o=U(),l=I(!1),i=I(void 0);return M(j(de(n,s),L(([{scrollHeight:a,scrollTop:c,viewportHeight:u},{offsetTop:f}])=>({scrollHeight:a,scrollTop:Math.max(0,c-f),viewportHeight:u}))),e),M(j(t,G(s),L(([a,{offsetTop:c}])=>({...a,top:a.top+c}))),o),{customScrollParent:i,useWindowScroll:l,windowScrollContainerState:n,windowScrollTo:o,windowViewportRect:s}},se(Ie)),To=$(([{sizeRanges:e,sizes:t},{headerHeight:n,scrollTop:s},{initialTopMostItemIndex:o},{didMount:l},{useWindowScroll:i,windowScrollContainerState:a,windowViewportRect:c}])=>{const u=U(),f=I(void 0),p=I(null),x=I(null);return M(a,p),M(c,x),Y(j(u,G(t,s,i,p,x,n)),([v,T,k,g,m,h,w])=>{const H=io(T.sizeTree);g&&m!==null&&h!==null&&(k=m.scrollTop-h.offsetTop),k-=w,v({ranges:H,scrollTop:k})}),M(j(f,A(un),L(Co)),o),M(j(l,G(f),A(([,v])=>v!==void 0),re(),L(([,v])=>v.ranges)),e),{getState:u,restoreStateFrom:f}},se(We,Ie,jt,Ke,vn));function Co(e){return{align:"start",index:0,offset:e.scrollTop}}const No=$(([{topItemsIndexes:e}])=>{const t=I(0);return M(j(t,A(n=>n>=0),L(n=>Array.from({length:n}).map((s,o)=>o))),e),{topItemCount:t}},se(et));function Dr(e){let t=!1,n;return()=>(t||(t=!0,n=e()),n)}const ko=Dr(()=>/iP(ad|od|hone)/i.test(navigator.userAgent)&&/WebKit/i.test(navigator.userAgent)),Ro=$(([{deviation:e,scrollBy:t,scrollingInProgress:n,scrollTop:s},{isAtBottom:o,isScrolling:l,lastJumpDueToItemResize:i,scrollDirection:a},{listState:c},{beforeUnshiftWith:u,gap:f,shiftWithOffset:p,sizes:x},{log:v},{recalcInProgress:T}])=>{const k=ke(j(c,G(i),Pe(([,m,h,w],[{bottom:H,items:E,offsetBottom:R,totalCount:d},b])=>{const y=H+R;let z=0;return h===d&&m.length>0&&E.length>0&&(E[0].originalIndex===0&&m[0].originalIndex===0||(z=y-w,z!==0&&(z+=b))),[z,E,d,y]},[0,[],0,0]),A(([m])=>m!==0),G(s,a,n,o,v,T),A(([,m,h,w,,,H])=>!H&&!w&&m!==0&&h===xt),L(([[m],,,,,h])=>(h("Upward scrolling compensation",{amount:m},Ce.DEBUG),m))));function g(m){m>0?(q(t,{behavior:"auto",top:-m}),q(e,0)):(q(e,0),q(t,{behavior:"auto",top:-m}))}return Y(j(k,G(e,l)),([m,h,w])=>{w&&ko()?q(e,h-m):g(-m)}),Y(j(de(je(l,!1),e,T),A(([m,h,w])=>!m&&!w&&h!==0),L(([m,h])=>h),_e(1)),g),M(j(p,L(m=>({top:-m}))),t),Y(j(u,G(x,f),L(([m,{groupIndices:h,lastSize:w,sizeTree:H},E])=>{function R(d){return d*(w+E)}if(h.length===0)return R(m);{let d=0;const b=ht(H,0);let y=0,z=0;for(;y<m;){y++,d+=b;let S=h.length===z+1?1/0:h[z+1]-h[z]-1;y+S>m&&(d-=b,S=m-y+1),y+=S,d+=R(S),z++}return d}})),m=>{q(e,m),requestAnimationFrame(()=>{q(t,{top:m}),requestAnimationFrame(()=>{q(e,0),q(T,!1)})})}),{deviation:e}},se(Ie,wt,et,We,Ue,hn)),Eo=$(([e,t,n,s,o,l,i,a,c,u,f])=>({...e,...t,...n,...s,...o,...l,...i,...a,...c,...u,...f}),se(pn,yo,Ke,Mr,Or,Io,bo,vn,Fr,Ue,Br)),Pr=$(([{data:e,defaultItemSize:t,firstItemIndex:n,fixedItemSize:s,fixedGroupSize:o,gap:l,groupIndices:i,heightEstimates:a,itemSize:c,sizeRanges:u,sizes:f,statefulTotalCount:p,totalCount:x,trackItemSizes:v},{initialItemFinalLocationReached:T,initialTopMostItemIndex:k,scrolledToInitialItem:g},m,h,w,H,{scrollToIndex:E},R,{topItemCount:d},{groupCounts:b},y])=>{const{listState:z,minOverscanItemCount:S,topItemsIndexes:C,rangeChanged:D,...B}=H;return M(D,y.scrollSeekRangeChanged),M(j(y.windowViewportRect,L(V=>V.visibleHeight)),m.viewportHeight),{data:e,defaultItemHeight:t,firstItemIndex:n,fixedItemHeight:s,fixedGroupHeight:o,gap:l,groupCounts:b,heightEstimates:a,initialItemFinalLocationReached:T,initialTopMostItemIndex:k,scrolledToInitialItem:g,sizeRanges:u,topItemCount:d,topItemsIndexes:C,totalCount:x,...w,groupIndices:i,itemSize:c,listState:z,minOverscanItemCount:S,scrollToIndex:E,statefulTotalCount:p,trackItemSizes:v,rangeChanged:D,...B,...y,...m,sizes:f,...h}},se(We,jt,Ie,To,So,et,bt,Ro,No,Er,Eo));function zo(e,t){const n={},s={};let o=0;const l=e.length;for(;o<l;)s[e[o]]=1,o+=1;for(const i in t)Object.hasOwn(s,i)||(n[i]=t[i]);return n}const yt=typeof document<"u"?F.useLayoutEffect:F.useEffect;function Ar(e,t,n){const s=Object.keys(t.required||{}),o=Object.keys(t.optional||{}),l=Object.keys(t.methods||{}),i=Object.keys(t.events||{}),a=F.createContext({});function c(g,m){g.propsReady&&q(g.propsReady,!1);for(const h of s){const w=g[t.required[h]];q(w,m[h])}for(const h of o)if(h in m){const w=g[t.optional[h]];q(w,m[h])}g.propsReady&&q(g.propsReady,!0)}function u(g){return l.reduce((m,h)=>(m[h]=w=>{const H=g[t.methods[h]];q(H,w)},m),{})}function f(g){return i.reduce((m,h)=>(m[h]=Qs(g[t.events[h]]),m),{})}const p=F.forwardRef((g,m)=>{const{children:h,...w}=g,[H]=F.useState(()=>Bt(Ks(e),d=>{c(d,w)})),[E]=F.useState(Pn(f,H));yt(()=>{for(const d of i)d in w&&Y(E[d],w[d]);return()=>{Object.values(E).map(dn)}},[w,E,H]),yt(()=>{c(H,w)}),F.useImperativeHandle(m,Dn(u(H)));const R=n;return r.jsx(a.Provider,{value:H,children:n?r.jsx(R,{...zo([...s,...o,...i],w),children:h}):h})}),x=g=>{const m=F.useContext(a);return F.useCallback(h=>{q(m[g],h)},[m,g])},v=g=>{const m=F.useContext(a)[g],h=F.useCallback(w=>Y(m,w),[m]);return F.useSyncExternalStore(h,()=>le(m),()=>le(m))},T=g=>{const m=F.useContext(a)[g],[h,w]=F.useState(Pn(le,m));return yt(()=>Y(m,H=>{H!==h&&w(Dn(H))}),[m,h]),h},k=F.version.startsWith("18")?v:T;return{Component:p,useEmitter:(g,m)=>{const h=F.useContext(a)[g];yt(()=>Y(h,m),[m,h])},useEmitterValue:k,usePublisher:x}}const Wr=F.createContext(void 0),_r=F.createContext(void 0),Vr=typeof document<"u"?F.useLayoutEffect:F.useEffect;function qt(e){return"self"in e}function Ho(e){return"body"in e}function qr(e,t,n,s=lt,o,l){const i=F.useRef(null),a=F.useRef(null),c=F.useRef(null),u=F.useCallback(x=>{let v,T,k;const g=x.target;if(Ho(g)||qt(g)){const h=qt(g)?g:g.defaultView;k=l?h.scrollX:h.scrollY,v=l?h.document.documentElement.scrollWidth:h.document.documentElement.scrollHeight,T=l?h.innerWidth:h.innerHeight}else k=l?g.scrollLeft:g.scrollTop,v=l?g.scrollWidth:g.scrollHeight,T=l?g.offsetWidth:g.offsetHeight;const m=()=>{e({scrollHeight:v,scrollTop:Math.max(k,0),viewportHeight:T})};x.suppressFlushSync?m():ts.flushSync(m),a.current!==null&&(k===a.current||k<=0||k===v-T)&&(a.current=null,t(!0),c.current&&(clearTimeout(c.current),c.current=null))},[e,t,l]);F.useEffect(()=>{const x=o||i.current;return s(o||i.current),u({suppressFlushSync:!0,target:x}),x.addEventListener("scroll",u,{passive:!0}),()=>{s(null),x.removeEventListener("scroll",u)}},[i,u,n,s,o]);function f(x){const v=i.current;if(!v||(l?"offsetWidth"in v&&v.offsetWidth===0:"offsetHeight"in v&&v.offsetHeight===0))return;const T=x.behavior==="smooth";let k,g,m;qt(v)?(g=Math.max(Ge(v.document.documentElement,l?"width":"height"),l?v.document.documentElement.scrollWidth:v.document.documentElement.scrollHeight),k=l?v.innerWidth:v.innerHeight,m=l?window.scrollX:window.scrollY):(g=v[l?"scrollWidth":"scrollHeight"],k=Ge(v,l?"width":"height"),m=v[l?"scrollLeft":"scrollTop"]);const h=g-k;if(x.top=Math.ceil(Math.max(Math.min(h,x.top),0)),Hr(k,g)||x.top===m){e({scrollHeight:g,scrollTop:m,viewportHeight:k}),T&&t(!0);return}T?(a.current=x.top,c.current&&clearTimeout(c.current),c.current=setTimeout(()=>{c.current=null,a.current=null,t(!0)},1e3)):a.current=null,l&&(x={behavior:x.behavior,left:x.top}),v.scrollTo(x)}function p(x){l&&(x={behavior:x.behavior,left:x.top}),i.current.scrollBy(x)}return{scrollByCallback:p,scrollerRef:i,scrollToCallback:f}}const Gt="-webkit-sticky",Jn="sticky",bn=Dr(()=>{if(typeof document>"u")return Jn;const e=document.createElement("div");return e.style.position=Gt,e.style.position===Gt?Gt:Jn});function jn(e){return e}const Lo=$(()=>{const e=I(a=>`Item ${a}`),t=I(a=>`Group ${a}`),n=I({}),s=I(jn),o=I("div"),l=I(lt),i=(a,c=null)=>je(j(n,L(u=>u[a]),re()),c);return{components:n,computeItemKey:s,EmptyPlaceholder:i("EmptyPlaceholder"),FooterComponent:i("Footer"),GroupComponent:i("Group","div"),groupContent:t,HeaderComponent:i("Header"),HeaderFooterTag:o,ItemComponent:i("Item","div"),itemContent:e,ListComponent:i("List","div"),ScrollerComponent:i("Scroller","div"),scrollerRef:l,ScrollSeekPlaceholder:i("ScrollSeekPlaceholder"),TopItemListComponent:i("TopItemList")}}),Oo=$(([e,t])=>({...e,...t}),se(Pr,Lo)),Bo=({height:e})=>r.jsx("div",{style:{height:e}}),Fo={overflowAnchor:"none",position:bn(),zIndex:1},Gr={overflowAnchor:"none"},Mo={...Gr,display:"inline-block",height:"100%"},Yn=F.memo(function({showTopList:e=!1}){const t=W("listState"),n=He("sizeRanges"),s=W("useWindowScroll"),o=W("customScrollParent"),l=He("windowScrollContainerState"),i=He("scrollContainerState"),a=o||s?l:i,c=W("itemContent"),u=W("context"),f=W("groupContent"),p=W("trackItemSizes"),x=W("itemSize"),v=W("log"),T=He("gap"),k=W("horizontalDirection"),{callbackRef:g}=Ys(n,x,p,e?lt:a,v,T,o,k,W("skipAnimationFrameInResizeObserver")),[m,h]=F.useState(0);wn("deviation",B=>{m!==B&&h(B)});const w=W("EmptyPlaceholder"),H=W("ScrollSeekPlaceholder")||Bo,E=W("ListComponent"),R=W("ItemComponent"),d=W("GroupComponent"),b=W("computeItemKey"),y=W("isSeeking"),z=W("groupIndices").length>0,S=W("alignToBottom"),C=W("initialItemFinalLocationReached"),D=e?{}:{boxSizing:"border-box",...k?{display:"inline-block",height:"100%",marginLeft:m!==0?m:S?"auto":0,paddingLeft:t.offsetTop,paddingRight:t.offsetBottom,whiteSpace:"nowrap"}:{marginTop:m!==0?m:S?"auto":0,paddingBottom:t.offsetBottom,paddingTop:t.offsetTop},...C?{}:{visibility:"hidden"}};return!e&&t.totalCount===0&&w?r.jsx(w,{...be(w,u)}):r.jsx(E,{...be(E,u),"data-testid":e?"virtuoso-top-item-list":"virtuoso-item-list",ref:g,style:D,children:(e?t.topItems:t.items).map(B=>{const V=B.originalIndex,Q=b(V+t.firstItemIndex,B.data,u);return y?O.createElement(H,{...be(H,u),height:B.size,index:B.index,key:Q,type:B.type||"item",...B.type==="group"?{}:{groupIndex:B.groupIndex}}):B.type==="group"?O.createElement(d,{...be(d,u),"data-index":V,"data-item-index":B.index,"data-known-size":B.size,key:Q,style:Fo},f(B.index,u)):O.createElement(R,{...be(R,u),...Wo(R,B.data),"data-index":V,"data-item-group-index":B.groupIndex,"data-item-index":B.index,"data-known-size":B.size,key:Q,style:k?Mo:Gr},z?c(B.index,B.groupIndex,B.data,u):c(B.index,B.data,u))})})}),Do={height:"100%",outline:"none",overflowY:"auto",position:"relative",WebkitOverflowScrolling:"touch"},Po={outline:"none",overflowX:"auto",position:"relative"},Mt=e=>({height:"100%",position:"absolute",top:0,width:"100%",...e?{display:"flex",flexDirection:"column"}:{}}),Ao={position:bn(),top:0,width:"100%",zIndex:1};function be(e,t){if(typeof e!="string")return{context:t}}function Wo(e,t){return{item:typeof e=="string"?void 0:t}}const _o=F.memo(function(){const e=W("HeaderComponent"),t=He("headerHeight"),n=W("HeaderFooterTag"),s=Ze(F.useMemo(()=>l=>{t(Ge(l,"height"))},[t]),!0,W("skipAnimationFrameInResizeObserver")),o=W("context");return e?r.jsx(n,{ref:s,children:r.jsx(e,{...be(e,o)})}):null}),Vo=F.memo(function(){const e=W("FooterComponent"),t=He("footerHeight"),n=W("HeaderFooterTag"),s=Ze(F.useMemo(()=>l=>{t(Ge(l,"height"))},[t]),!0,W("skipAnimationFrameInResizeObserver")),o=W("context");return e?r.jsx(n,{ref:s,children:r.jsx(e,{...be(e,o)})}):null});function Qr({useEmitter:e,useEmitterValue:t,usePublisher:n}){return F.memo(function({children:s,style:o,context:l,...i}){const a=n("scrollContainerState"),c=t("ScrollerComponent"),u=n("smoothScrollTargetReached"),f=t("scrollerRef"),p=t("horizontalDirection")||!1,{scrollByCallback:x,scrollerRef:v,scrollToCallback:T}=qr(a,u,c,f,void 0,p);return e("scrollTo",T),e("scrollBy",x),r.jsx(c,{"data-testid":"virtuoso-scroller","data-virtuoso-scroller":!0,ref:v,style:{...p?Po:Do,...o},tabIndex:0,...i,...be(c,l),children:s})})}function Ur({useEmitter:e,useEmitterValue:t,usePublisher:n}){return F.memo(function({children:s,style:o,context:l,...i}){const a=n("windowScrollContainerState"),c=t("ScrollerComponent"),u=n("smoothScrollTargetReached"),f=t("totalListHeight"),p=t("deviation"),x=t("customScrollParent"),v=F.useRef(null),T=t("scrollerRef"),{scrollByCallback:k,scrollerRef:g,scrollToCallback:m}=qr(a,u,c,T,x);return Vr(()=>{var h;return g.current=x||((h=v.current)==null?void 0:h.ownerDocument.defaultView),()=>{g.current=null}},[g,x]),e("windowScrollTo",m),e("scrollBy",k),r.jsx(c,{ref:v,"data-virtuoso-scroller":!0,style:{position:"relative",...o,...f!==0?{height:f+p}:{}},...i,...be(c,l),children:s})})}const qo=({children:e})=>{const t=F.useContext(Wr),n=He("viewportHeight"),s=He("fixedItemHeight"),o=W("alignToBottom"),l=W("horizontalDirection"),i=F.useMemo(()=>vr(n,c=>Ge(c,l?"width":"height")),[n,l]),a=Ze(i,!0,W("skipAnimationFrameInResizeObserver"));return F.useEffect(()=>{t&&(n(t.viewportHeight),s(t.itemHeight))},[t,n,s]),r.jsx("div",{"data-viewport-type":"element",ref:a,style:Mt(o),children:e})},Go=({children:e})=>{const t=F.useContext(Wr),n=He("windowViewportRect"),s=He("fixedItemHeight"),o=W("customScrollParent"),l=jr(n,o,W("skipAnimationFrameInResizeObserver")),i=W("alignToBottom");return F.useEffect(()=>{t&&(s(t.itemHeight),n({offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:100}))},[t,n,s]),r.jsx("div",{"data-viewport-type":"window",ref:l,style:Mt(i),children:e})},Qo=({children:e})=>{const t=W("TopItemListComponent")||"div",n=W("headerHeight"),s={...Ao,marginTop:`${n}px`},o=W("context");return r.jsx(t,{style:s,...be(t,o),children:e})},Uo=F.memo(function(e){const t=W("useWindowScroll"),n=W("topItemsIndexes").length>0,s=W("customScrollParent"),o=W("context");return r.jsxs(s||t?Jo:$o,{...e,context:o,children:[n&&r.jsx(Qo,{children:r.jsx(Yn,{showTopList:!0})}),r.jsxs(s||t?Go:qo,{children:[r.jsx(_o,{}),r.jsx(Yn,{}),r.jsx(Vo,{})]})]})}),{Component:Ko,useEmitter:wn,useEmitterValue:W,usePublisher:He}=Ar(Oo,{required:{},optional:{restoreStateFrom:"restoreStateFrom",context:"context",followOutput:"followOutput",scrollIntoViewOnChange:"scrollIntoViewOnChange",itemContent:"itemContent",groupContent:"groupContent",overscan:"overscan",increaseViewportBy:"increaseViewportBy",minOverscanItemCount:"minOverscanItemCount",totalCount:"totalCount",groupCounts:"groupCounts",topItemCount:"topItemCount",firstItemIndex:"firstItemIndex",initialTopMostItemIndex:"initialTopMostItemIndex",components:"components",atBottomThreshold:"atBottomThreshold",atTopThreshold:"atTopThreshold",computeItemKey:"computeItemKey",defaultItemHeight:"defaultItemHeight",fixedGroupHeight:"fixedGroupHeight",fixedItemHeight:"fixedItemHeight",heightEstimates:"heightEstimates",itemSize:"itemSize",scrollSeekConfiguration:"scrollSeekConfiguration",headerFooterTag:"HeaderFooterTag",data:"data",initialItemCount:"initialItemCount",initialScrollTop:"initialScrollTop",alignToBottom:"alignToBottom",useWindowScroll:"useWindowScroll",customScrollParent:"customScrollParent",scrollerRef:"scrollerRef",logLevel:"logLevel",horizontalDirection:"horizontalDirection",skipAnimationFrameInResizeObserver:"skipAnimationFrameInResizeObserver"},methods:{scrollToIndex:"scrollToIndex",scrollIntoView:"scrollIntoView",scrollTo:"scrollTo",scrollBy:"scrollBy",autoscrollToBottom:"autoscrollToBottom",getState:"getState"},events:{isScrolling:"isScrolling",endReached:"endReached",startReached:"startReached",rangeChanged:"rangeChanged",atBottomStateChange:"atBottomStateChange",atTopStateChange:"atTopStateChange",totalListHeightChanged:"totalListHeightChanged",itemsRendered:"itemsRendered",groupIndices:"groupIndices"}},Uo),$o=Qr({useEmitter:wn,useEmitterValue:W,usePublisher:He}),Jo=Ur({useEmitter:wn,useEmitterValue:W,usePublisher:He}),Yo=Ko,Xo=$(()=>{const e=I(u=>r.jsxs("td",{children:["Item $",u]})),t=I(null),n=I(u=>r.jsxs("td",{colSpan:1e3,children:["Group ",u]})),s=I(null),o=I(null),l=I({}),i=I(jn),a=I(lt),c=(u,f=null)=>je(j(l,L(p=>p[u]),re()),f);return{components:l,computeItemKey:i,context:t,EmptyPlaceholder:c("EmptyPlaceholder"),FillerRow:c("FillerRow"),fixedFooterContent:o,fixedHeaderContent:s,itemContent:e,groupContent:n,ScrollerComponent:c("Scroller","div"),scrollerRef:a,ScrollSeekPlaceholder:c("ScrollSeekPlaceholder"),TableBodyComponent:c("TableBody","tbody"),TableComponent:c("Table","table"),TableFooterComponent:c("TableFoot","tfoot"),TableHeadComponent:c("TableHead","thead"),TableRowComponent:c("TableRow","tr"),GroupComponent:c("Group","tr")}});se(Pr,Xo);bn();const Xn={bottom:0,itemHeight:0,items:[],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},Zo={bottom:0,itemHeight:0,items:[{index:0}],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},{ceil:Zn,floor:Lt,max:ut,min:Qt,round:er}=Math;function tr(e,t,n){return Array.from({length:t-e+1}).map((s,o)=>({data:n===null?null:n[o+e],index:o+e}))}function el(e){return{...Zo,items:e}}function It(e,t){return e&&e.width===t.width&&e.height===t.height}function tl(e,t){return e&&e.column===t.column&&e.row===t.row}const nl=$(([{increaseViewportBy:e,listBoundary:t,overscan:n,visibleRange:s},{footerHeight:o,headerHeight:l,scrollBy:i,scrollContainerState:a,scrollTo:c,scrollTop:u,smoothScrollTargetReached:f,viewportHeight:p},x,v,{didMount:T,propsReady:k},{customScrollParent:g,useWindowScroll:m,windowScrollContainerState:h,windowScrollTo:w,windowViewportRect:H},E])=>{const R=I(0),d=I(0),b=I(Xn),y=I({height:0,width:0}),z=I({height:0,width:0}),S=U(),C=U(),D=I(0),B=I(null),V=I({column:0,row:0}),Q=U(),X=U(),ne=I(!1),we=I(0),ge=I(!0),xe=I(!1),Re=I(!1);Y(j(T,G(we),A(([N,_])=>!!_)),()=>{q(ge,!1)}),Y(j(de(T,ge,z,y,we,xe),A(([N,_,J,ce,,me])=>N&&!_&&J.height!==0&&ce.height!==0&&!me)),([,,,,N])=>{q(xe,!0),gn(1,()=>{q(S,N)}),Oe(j(u),()=>{q(t,[0,0]),q(ge,!0)})}),M(j(X,A(N=>N!=null&&N.scrollTop>0),De(0)),d),Y(j(T,G(X),A(([,N])=>N!=null)),([,N])=>{N&&(q(y,N.viewport),q(z,N.item),q(V,N.gap),N.scrollTop>0&&(q(ne,!0),Oe(j(u,Xe(1)),_=>{q(ne,!1)}),q(c,{top:N.scrollTop})))}),M(j(y,L(({height:N})=>N)),p),M(j(de(P(y,It),P(z,It),P(V,(N,_)=>N&&N.column===_.column&&N.row===_.row),P(u)),L(([N,_,J,ce])=>({gap:J,item:_,scrollTop:ce,viewport:N}))),Q),M(j(de(P(R),s,P(V,tl),P(z,It),P(y,It),P(B),P(d),P(ne),P(ge),P(we)),A(([,,,,,,,N])=>!N),L(([N,[_,J],ce,me,ie,ae,fe,,ue,Z])=>{const{column:te,row:Ee}=ce,{height:pe,width:Dt}=me,{width:Sn}=ie;if(fe===0&&(N===0||Sn===0))return Xn;if(Dt===0){const Nn=xn(Z,N),es=Nn+Math.max(fe-1,0);return el(tr(Nn,es,ae))}const St=Kr(Sn,Dt,te);let tt,Je;ue?_===0&&J===0&&fe>0?(tt=0,Je=fe-1):(tt=St*Lt((_+Ee)/(pe+Ee)),Je=St*Zn((J+Ee)/(pe+Ee))-1,Je=Qt(N-1,ut(Je,St-1)),tt=Qt(Je,ut(0,tt))):(tt=0,Je=-1);const yn=tr(tt,Je,ae),{bottom:In,top:Tn}=nr(ie,ce,me,yn),Cn=Zn(N/St),Zr=Cn*pe+(Cn-1)*Ee-In;return{bottom:In,itemHeight:pe,items:yn,itemWidth:Dt,offsetBottom:Zr,offsetTop:Tn,top:Tn}})),b),M(j(B,A(N=>N!==null),L(N=>N.length)),R),M(j(de(y,z,b,V),A(([N,_,{items:J}])=>J.length>0&&_.height!==0&&N.height!==0),L(([N,_,{items:J},ce])=>{const{bottom:me,top:ie}=nr(N,ce,_,J);return[ie,me]}),re(ft)),t);const Se=I(!1);M(j(u,G(Se),L(([N,_])=>_||N!==0)),Se);const Fe=ke(j(de(b,R),A(([{items:N}])=>N.length>0),G(Se),A(([[N,_],J])=>{const ce=N.items[N.items.length-1].index===_-1;return(J||N.bottom>0&&N.itemHeight>0&&N.offsetBottom===0&&N.items.length===_)&&ce}),L(([[,N]])=>N-1),re())),$e=ke(j(P(b),A(({items:N})=>N.length>0&&N[0].index===0),De(0),re())),Ve=ke(j(P(b),G(ne),A(([{items:N},_])=>N.length>0&&!_),L(([{items:N}])=>({endIndex:N[N.length-1].index,startIndex:N[0].index})),re(Cr),_e(0)));M(Ve,v.scrollSeekRangeChanged),M(j(S,G(y,z,R,V),L(([N,_,J,ce,me])=>{const ie=zr(N),{align:ae,behavior:fe,offset:ue}=ie;let Z=ie.index;Z==="LAST"&&(Z=ce-1),Z=ut(0,Z,Qt(ce-1,Z));let te=on(_,me,J,Z);return ae==="end"?te=er(te-_.height+J.height):ae==="center"&&(te=er(te-_.height/2+J.height/2)),ue&&(te+=ue),{behavior:fe,top:te}})),c);const Me=je(j(b,L(N=>N.offsetBottom+N.bottom)),0);return M(j(H,L(N=>({height:N.visibleHeight,width:N.visibleWidth}))),y),{customScrollParent:g,data:B,deviation:D,footerHeight:o,gap:V,headerHeight:l,increaseViewportBy:e,initialItemCount:d,itemDimensions:z,overscan:n,restoreStateFrom:X,scrollBy:i,scrollContainerState:a,scrollHeight:C,scrollTo:c,scrollToIndex:S,scrollTop:u,smoothScrollTargetReached:f,totalCount:R,useWindowScroll:m,viewportDimensions:y,windowScrollContainerState:h,windowScrollTo:w,windowViewportRect:H,...v,gridState:b,horizontalDirection:Re,initialTopMostItemIndex:we,totalListHeight:Me,...x,endReached:Fe,propsReady:k,rangeChanged:Ve,startReached:$e,stateChanged:Q,stateRestoreInProgress:ne,...E}},se(pn,Ie,wt,Mr,Ke,vn,Ue));function Kr(e,t,n){return ut(1,Lt((e+n)/(Lt(t)+n)))}function nr(e,t,n,s){const{height:o}=n;if(o===void 0||s.length===0)return{bottom:0,top:0};const l=on(e,t,n,s[0].index);return{bottom:on(e,t,n,s[s.length-1].index)+o,top:l}}function on(e,t,n,s){const o=Kr(e.width,n.width,t.column),l=Lt(s/o),i=l*n.height+ut(0,l-1)*t.row;return i>0?i+t.row:i}const rl=$(()=>{const e=I(p=>`Item ${p}`),t=I({}),n=I(null),s=I("virtuoso-grid-item"),o=I("virtuoso-grid-list"),l=I(jn),i=I("div"),a=I(lt),c=(p,x=null)=>je(j(t,L(v=>v[p]),re()),x),u=I(!1),f=I(!1);return M(P(f),u),{components:t,computeItemKey:l,context:n,FooterComponent:c("Footer"),HeaderComponent:c("Header"),headerFooterTag:i,itemClassName:s,ItemComponent:c("Item","div"),itemContent:e,listClassName:o,ListComponent:c("List","div"),readyStateChanged:u,reportReadyState:f,ScrollerComponent:c("Scroller","div"),scrollerRef:a,ScrollSeekPlaceholder:c("ScrollSeekPlaceholder","div")}}),sl=$(([e,t])=>({...e,...t}),se(nl,rl)),ol=F.memo(function(){const e=oe("gridState"),t=oe("listClassName"),n=oe("itemClassName"),s=oe("itemContent"),o=oe("computeItemKey"),l=oe("isSeeking"),i=Le("scrollHeight"),a=oe("ItemComponent"),c=oe("ListComponent"),u=oe("ScrollSeekPlaceholder"),f=oe("context"),p=Le("itemDimensions"),x=Le("gap"),v=oe("log"),T=oe("stateRestoreInProgress"),k=Le("reportReadyState"),g=Ze(F.useMemo(()=>m=>{const h=m.parentElement.parentElement.scrollHeight;i(h);const w=m.firstChild;if(w){const{height:H,width:E}=w.getBoundingClientRect();p({height:H,width:E})}x({column:rr("column-gap",getComputedStyle(m).columnGap,v),row:rr("row-gap",getComputedStyle(m).rowGap,v)})},[i,p,x,v]),!0,!1);return Vr(()=>{e.itemHeight>0&&e.itemWidth>0&&k(!0)},[e]),T?null:r.jsx(c,{className:t,ref:g,...be(c,f),"data-testid":"virtuoso-item-list",style:{paddingBottom:e.offsetBottom,paddingTop:e.offsetTop},children:e.items.map(m=>{const h=o(m.index,m.data,f);return l?r.jsx(u,{...be(u,f),height:e.itemHeight,index:m.index,width:e.itemWidth},h):O.createElement(a,{...be(a,f),className:n,"data-index":m.index,key:h},s(m.index,m.data,f))})})}),ll=F.memo(function(){const e=oe("HeaderComponent"),t=Le("headerHeight"),n=oe("headerFooterTag"),s=Ze(F.useMemo(()=>l=>{t(Ge(l,"height"))},[t]),!0,!1),o=oe("context");return e?r.jsx(n,{ref:s,children:r.jsx(e,{...be(e,o)})}):null}),il=F.memo(function(){const e=oe("FooterComponent"),t=Le("footerHeight"),n=oe("headerFooterTag"),s=Ze(F.useMemo(()=>l=>{t(Ge(l,"height"))},[t]),!0,!1),o=oe("context");return e?r.jsx(n,{ref:s,children:r.jsx(e,{...be(e,o)})}):null}),al=({children:e})=>{const t=F.useContext(_r),n=Le("itemDimensions"),s=Le("viewportDimensions"),o=Ze(F.useMemo(()=>l=>{s(l.getBoundingClientRect())},[s]),!0,!1);return F.useEffect(()=>{t&&(s({height:t.viewportHeight,width:t.viewportWidth}),n({height:t.itemHeight,width:t.itemWidth}))},[t,s,n]),r.jsx("div",{ref:o,style:Mt(!1),children:e})},cl=({children:e})=>{const t=F.useContext(_r),n=Le("windowViewportRect"),s=Le("itemDimensions"),o=oe("customScrollParent"),l=jr(n,o,!1);return F.useEffect(()=>{t&&(s({height:t.itemHeight,width:t.itemWidth}),n({offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:t.viewportWidth}))},[t,n,s]),r.jsx("div",{ref:l,style:Mt(!1),children:e})},ul=F.memo(function({...e}){const t=oe("useWindowScroll"),n=oe("customScrollParent"),s=n||t?ml:dl,o=n||t?cl:al,l=oe("context");return r.jsx(s,{...e,...be(s,l),children:r.jsxs(o,{children:[r.jsx(ll,{}),r.jsx(ol,{}),r.jsx(il,{})]})})}),{useEmitter:$r,useEmitterValue:oe,usePublisher:Le}=Ar(sl,{optional:{context:"context",totalCount:"totalCount",overscan:"overscan",itemContent:"itemContent",components:"components",computeItemKey:"computeItemKey",data:"data",initialItemCount:"initialItemCount",scrollSeekConfiguration:"scrollSeekConfiguration",headerFooterTag:"headerFooterTag",listClassName:"listClassName",itemClassName:"itemClassName",useWindowScroll:"useWindowScroll",customScrollParent:"customScrollParent",scrollerRef:"scrollerRef",logLevel:"logLevel",restoreStateFrom:"restoreStateFrom",initialTopMostItemIndex:"initialTopMostItemIndex",increaseViewportBy:"increaseViewportBy"},methods:{scrollTo:"scrollTo",scrollBy:"scrollBy",scrollToIndex:"scrollToIndex"},events:{isScrolling:"isScrolling",endReached:"endReached",startReached:"startReached",rangeChanged:"rangeChanged",atBottomStateChange:"atBottomStateChange",atTopStateChange:"atTopStateChange",stateChanged:"stateChanged",readyStateChanged:"readyStateChanged"}},ul),dl=Qr({useEmitter:$r,useEmitterValue:oe,usePublisher:Le}),ml=Ur({useEmitter:$r,useEmitterValue:oe,usePublisher:Le});function rr(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,Ce.WARN),t==="normal"?0:parseInt(t??"0",10)}function hl(e){const t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleTimeString(void 0,{hour12:!1,hour:"2-digit",minute:"2-digit",second:"2-digit"})}async function fl(e){try{return await navigator.clipboard.writeText(e),!0}catch{return!1}}function gl({entry:e,isSelected:t,density:n,sourceLabel:s,onSelect:o,indent:l=0,stageHint:i,repeatCount:a}){const[c,u]=O.useState(!1),f=mr(e,s),p=fr(e),x=hr(e,{short:!0}),v=()=>o(e.id),T=g=>{g.target===g.currentTarget&&(g.key==="Enter"||g.key===" ")&&(g.preventDefault(),v())},k=async g=>{g.stopPropagation(),!(!e.requestId||!await fl(e.requestId))&&(u(!0),window.setTimeout(()=>u(!1),1200))};return r.jsxs("div",{role:"row",tabIndex:0,"aria-selected":t,"data-selected":t,onClick:v,onKeyDown:T,style:{paddingLeft:12+l},className:K("group flex w-full cursor-pointer items-center gap-3 border-b border-border/50 pr-3 text-left",gr[n],xr,ve,t&&"bg-muted/60 shadow-[inset_2px_0_0_var(--ring)]"),children:[r.jsx("span",{className:"w-4 shrink-0","aria-hidden":"true"}),r.jsx("span",{role:"cell",className:K("w-[88px] shrink-0 truncate text-[12px] text-muted-foreground",Ae),children:hl(e.timestamp)}),r.jsx("span",{role:"cell",className:"flex w-[64px] shrink-0 items-center",children:r.jsx(an,{level:e.level})}),r.jsx("span",{role:"cell",className:"w-[120px] shrink-0 truncate text-[12px] font-medium text-foreground/80",children:f}),r.jsxs("span",{role:"cell",className:"flex min-w-0 flex-1 items-center gap-2 truncate text-[13px] text-foreground/90",children:[i?r.jsx("span",{className:"inline-flex shrink-0 items-center rounded border border-border bg-muted/30 px-1.5 py-0.5 text-[11px] uppercase tracking-wide text-muted-foreground",children:i}):null,r.jsx("span",{className:"min-w-0 truncate",children:e.message}),a&&a>1?r.jsxs("span",{className:"ml-1 inline-flex shrink-0 items-center rounded bg-muted px-1.5 py-0.5 text-[11px] font-medium text-muted-foreground",title:`${a} consecutive identical entries`,children:["×",a]}):null]}),r.jsx("span",{role:"cell",className:K("hidden w-[64px] shrink-0 truncate text-right text-[12px] text-muted-foreground sm:inline-block",Ae),children:p==="—"?"":p}),r.jsx("span",{role:"cell",className:K("hidden w-[100px] shrink-0 items-center justify-end gap-1 text-right text-[12px] text-muted-foreground/80 lg:inline-flex",Ae),children:e.requestId?r.jsxs(r.Fragment,{children:[r.jsx("span",{className:"truncate",children:x}),r.jsx("button",{type:"button","aria-label":c?"Copied requestId":"Copy requestId",title:c?"Copied":"Copy requestId",onClick:k,className:K("inline-flex h-5 w-5 shrink-0 items-center justify-center rounded text-muted-foreground/50 opacity-0 transition-opacity hover:bg-muted hover:text-foreground focus-visible:opacity-100 group-hover:opacity-100",ve,c&&"text-emerald-600 opacity-100"),children:r.jsx(Xt,{className:"h-3 w-3","aria-hidden":"true"})})]}):null})]})}const Jr=O.memo(gl,(e,t)=>e.entry.id===t.entry.id&&e.isSelected===t.isSelected&&e.density===t.density&&e.indent===t.indent&&e.stageHint===t.stageHint&&e.sourceLabel===t.sourceLabel&&e.repeatCount===t.repeatCount),sr={debug:0,info:1,warn:2,error:3};function dt(e){return e===void 0?"":e===null||typeof e!="object"?JSON.stringify(e):Array.isArray(e)?`[${e.map(t=>dt(t)).join(",")}]`:`{${Object.entries(e).sort(([t],[n])=>t.localeCompare(n)).map(([t,n])=>`${JSON.stringify(t)}:${dt(n)}`).join(",")}}`}function xl(e){return JSON.stringify([e.event??"",e.message??"",e.stage??"",e.module??e.source??"",e.level,e.requestId??"",e.source??"",e.runId??"",String(e.processId??""),String(e.latencyMs??""),dt(e.context),dt(e.metadata),dt(e.error)])}function pl(e){if(e.stage&&e.stage.length>0)return e.stage;if(e.event&&e.event.length>0)return(e.event.split(".").pop()??e.event).slice(0,12)}function vl(e){const t=[],n=new Map;let s=-1,o="";for(const l of e)if(l.requestId){const i=n.get(l.requestId);if(i!==void 0)t[i].children.push(l);else{const a={kind:"trace",requestId:l.requestId,module:l.module??l.source,source:l.source,ts:l.timestamp,maxLevel:l.level,totalLatencyMs:0,children:[l]};t.push(a),n.set(l.requestId,t.length-1)}s=-1,o=""}else{const i=xl(l);if(s>=0&&i===o){const a=t[s];a.repeatCount=(a.repeatCount??1)+1,a.collapsedRange={fromTs:a.collapsedRange?.fromTs??a.entry.timestamp,toTs:l.timestamp}}else{const a={kind:"leaf",entry:l};t.push(a),s=t.length-1,o=i}}for(const l of t)if(l.kind==="trace"){l.children.sort((u,f)=>u.timestamp.localeCompare(f.timestamp));let i="debug",a=0;for(const u of l.children)sr[u.level]>sr[i]&&(i=u.level),typeof u.latencyMs=="number"&&(a+=u.latencyMs);l.maxLevel=i,l.totalLatencyMs=a;const c=l.children[0];c&&(l.ts=c.timestamp)}return t.sort((l,i)=>{const a=l.kind==="trace"?l.ts:l.entry.timestamp;return(i.kind==="trace"?i.ts:i.entry.timestamp).localeCompare(a)})}function bl(e){const t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleTimeString(void 0,{hour12:!1,hour:"2-digit",minute:"2-digit",second:"2-digit"})}function jl({group:e,isExpanded:t,selectedEntryId:n,density:s,sourceLabel:o,onToggle:l,onSelect:i}){const a=t?dr:ps;return r.jsxs("div",{role:"rowgroup",className:"border-b border-border/50",children:[r.jsxs("button",{type:"button",role:"row","aria-expanded":t,onClick:()=>l(e.requestId),className:K("flex w-full items-center gap-3 pl-3 pr-3 text-left",gr[s],xr,ve),children:[r.jsx("span",{className:"flex w-4 shrink-0 items-center justify-center","aria-hidden":"true",children:r.jsx(a,{className:"h-3.5 w-3.5 text-muted-foreground"})}),r.jsx("span",{role:"cell",className:K("w-[88px] shrink-0 truncate text-[12px] text-muted-foreground",Ae),children:bl(e.ts)}),r.jsx("span",{role:"cell",className:"flex w-[64px] shrink-0 items-center",children:r.jsx(an,{level:e.maxLevel})}),r.jsxs("span",{role:"cell",className:"flex w-[120px] shrink-0 items-center gap-1.5 truncate text-[12px] font-medium text-foreground/80",children:[r.jsx(ur,{className:"h-3 w-3 text-muted-foreground","aria-hidden":"true"}),e.module]}),r.jsx("span",{role:"cell",className:"min-w-0 flex-1 truncate text-[13px] text-foreground/90",children:r.jsxs("span",{className:"text-muted-foreground",children:["trace · ",e.children.length," stages"]})}),r.jsx("span",{role:"cell",className:K("hidden w-[64px] shrink-0 truncate text-right text-[12px] text-muted-foreground sm:inline-block",Ae),children:e.totalLatencyMs>0?`${e.totalLatencyMs}ms`:""}),r.jsx("span",{role:"cell",className:K("hidden w-[100px] shrink-0 truncate text-right text-[12px] text-muted-foreground lg:inline-block",Ae),children:e.requestId.slice(-8)})]}),t?e.children.map(c=>r.jsx(Jr,{entry:c,isSelected:c.id===n,density:s,sourceLabel:o,onSelect:i,indent:20,stageHint:pl(c)},c.id)):null]})}const wl=O.memo(jl),Sl="grid grid-cols-[16px_88px_64px_120px_minmax(0,1fr)_64px_100px] items-center gap-3 px-3";function yl({entries:e,selectedEntryId:t,onSelect:n,sourceLabels:s,isLoading:o,isFetching:l,liveTailSlot:i,density:a="cozy"}){const c=O.useMemo(()=>vl(e),[e]),[u,f]=O.useState(new Set),[p,x]=O.useState(new Set),v=O.useMemo(()=>{if(!t)return null;const m=c.find(h=>h.kind==="trace"&&h.children.some(w=>w.id===t));return m&&m.kind==="trace"?m.requestId:null},[c,t]),T=O.useCallback(m=>{const h=v===m,w=u.has(m),H=p.has(m);w||h&&!H?(f(R=>{if(!R.has(m))return R;const d=new Set(R);return d.delete(m),d}),x(R=>{if(R.has(m))return R;const d=new Set(R);return d.add(m),d})):(f(R=>{if(R.has(m))return R;const d=new Set(R);return d.add(m),d}),x(R=>{if(!R.has(m))return R;const d=new Set(R);return d.delete(m),d}))},[v,u,p]),k=O.useMemo(()=>{const m=new Set(u);return v&&!p.has(v)&&m.add(v),m},[u,p,v]),g=O.useCallback((m,h)=>h.kind==="trace"?r.jsx(wl,{group:h,isExpanded:k.has(h.requestId),selectedEntryId:t,density:a,sourceLabel:s[h.source]??h.source,onToggle:T,onSelect:n}):r.jsx(Jr,{entry:h.entry,isSelected:h.entry.id===t,density:a,sourceLabel:s[h.entry.source]??h.entry.source,onSelect:n,repeatCount:h.repeatCount}),[a,k,n,t,s,T]);return r.jsxs("div",{className:"flex min-h-0 flex-1 flex-col bg-background",children:[r.jsxs("div",{role:"row",className:K(Sl,"h-9 shrink-0 border-b border-border bg-muted/30 text-[12px] font-medium uppercase tracking-wide text-muted-foreground"),children:[r.jsx("span",{role:"columnheader","aria-hidden":"true"}),r.jsx("span",{role:"columnheader",children:"Time"}),r.jsx("span",{role:"columnheader",children:"Level"}),r.jsx("span",{role:"columnheader",children:"Module"}),r.jsx("span",{role:"columnheader",children:"Message"}),r.jsx("span",{role:"columnheader",className:"text-right",children:"Latency"}),r.jsx("span",{role:"columnheader",className:"text-right",children:"Request"})]}),i?r.jsx("div",{className:"flex h-9 shrink-0 items-center justify-between border-b border-border bg-background px-3",children:i}):null,r.jsx("div",{role:"grid",className:"min-h-0 flex-1",children:o?r.jsx("div",{className:"space-y-1 p-2",children:Array.from({length:14}).map((m,h)=>r.jsx("div",{className:"h-9 w-full animate-pulse rounded border border-border/40 bg-muted/30"},h))}):c.length===0?r.jsx(cn,{variant:"noResults"}):r.jsx(Yo,{data:c,itemContent:g,increaseViewportBy:{top:200,bottom:400},followOutput:m=>m?"auto":!1,computeItemKey:(m,h)=>h.kind==="trace"?`t:${h.requestId}`:`l:${h.entry.id}`})})]})}function Il({error:e,onRetry:t}){const n=e?.message??"Unknown error fetching logs.";return r.jsxs("div",{role:"alert",className:"flex h-full flex-col items-center justify-center gap-3 px-6 py-10 text-center",children:[r.jsx("div",{className:"flex h-10 w-10 items-center justify-center rounded-full border border-red-500/30 bg-red-500/10 text-red-600 dark:text-red-400",children:r.jsx(vs,{className:"h-5 w-5","aria-hidden":"true"})}),r.jsx("h3",{className:"text-sm font-semibold text-foreground",children:"Could not load logs"}),r.jsx("p",{className:"max-w-sm text-[13px] leading-relaxed text-muted-foreground",children:n}),r.jsxs(ye,{variant:"outline",size:"sm",onClick:t,className:"gap-2",children:[r.jsx(ar,{className:"h-3.5 w-3.5","aria-hidden":"true"}),"Retry"]})]})}function Tl(){return!1}const Yr=["logs","config"],Xr=["logs","sources"],Cl=150,Nl=1e4,Ut=250;function Kt(e,t){const[n,s]=O.useState(e);return O.useEffect(()=>{const o=window.setTimeout(()=>s(e),t);return()=>window.clearTimeout(o)},[e,t]),n}function kl(){const[e,t]=O.useState(()=>typeof document>"u"?!0:document.visibilityState!=="hidden");return O.useEffect(()=>{if(typeof document>"u")return;const n=()=>t(document.visibilityState!=="hidden");return document.addEventListener("visibilitychange",n),()=>document.removeEventListener("visibilitychange",n)},[]),e}function Rl(e){switch(e){case"5m":return 5*6e4;case"15m":return 15*6e4;case"1h":return 60*6e4;case"24h":return 1440*6e4;default:return null}}function El(){const[e,t]=O.useState("all"),[n,s]=O.useState("all"),[o,l]=O.useState(""),[i,a]=O.useState(""),[c,u]=O.useState(""),[f,p]=O.useState(""),[x,v]=O.useState("all"),[T,k]=O.useState(Cl),[g,m]=O.useState(null),[h,w]=O.useState(!1),[H,E]=O.useState(!1),R=O.useRef(new Set),d=O.useDeferredValue(o.trim()),b=Kt(i.trim(),Ut),y=Kt(c.trim(),Ut),z=Kt(f.trim(),Ut),S=kl(),C=Wt({queryKey:Yr,queryFn:async()=>(await Rt.logs.getConfig()).logging,refetchInterval:3e4}),D=Wt({queryKey:Xr,queryFn:async()=>(await Rt.logs.getSources()).sources,refetchInterval:15e3}),B=Tl(),Q=Wt({queryKey:["logs","entries",e,n,d,b,y,z,x,T,H?"hide-internals":"show-internals",B?"mock":"live"],queryFn:async()=>{let N;N=(await Rt.logs.getEntries({source:e==="all"?void 0:e,level:n==="all"?void 0:n,search:d||void 0,limit:T})).entries;const _=Rl(x),J=Date.now(),ce=N.filter(me=>{if(b&&!(me.module??"").includes(b)||y&&(me.stage??"")!==y||z&&!(me.requestId??"").includes(z))return!1;if(_!==null){const ie=Date.parse(me.timestamp);if(Number.isFinite(ie)&&J-ie>_)return!1}return!(H&&/^web-server:/i.test(me.source))});return ce[0],ce},placeholderData:Es,refetchInterval:h||!S?!1:Nl,refetchOnWindowFocus:!0}),X=Q.data,ne=O.useMemo(()=>X??[],[X]),we=O.useMemo(()=>{if(!h)return 0;const N=R.current;let _=0;for(const J of ne)N.has(J.id)||(_+=1);return _},[ne,h]),ge=O.useCallback(()=>{R.current=new Set(ne.map(N=>N.id)),w(!0)},[ne]),xe=O.useCallback(()=>{R.current=new Set,w(!1),Q.refetch()},[Q]),Re=O.useCallback(()=>{h?xe():ge()},[h,ge,xe]),Se=O.useMemo(()=>ne.length===0?null:g&&ne.some(N=>N.id===g)?g:ne[0]?.id??null,[ne,g]),Fe=O.useMemo(()=>ne.find(N=>N.id===Se)??null,[Se,ne]),$e=!!(g&&!ne.some(N=>N.id===g)),Ve=O.useMemo(()=>(D.data??[]).map(_=>_.lastTimestamp).filter(_=>!!_).sort((_,J)=>J.localeCompare(_))[0]??null,[D.data]),Me=O.useCallback(()=>{l(""),s("all"),t("all"),a(""),u(""),p(""),v("all"),E(!1)},[]);return{configQuery:C,sourcesQuery:D,entriesQuery:Q,selectedSource:e,setSelectedSource:t,selectedLevel:n,setSelectedLevel:s,search:o,setSearch:l,moduleFilter:i,setModuleFilter:a,stageFilter:c,setStageFilter:u,requestIdFilter:f,setRequestIdFilter:p,timeWindow:x,setTimeWindow:v,hideDashboardInternals:H,setHideDashboardInternals:E,limit:T,setLimit:k,selectedEntryId:Se,setSelectedEntryId:m,selectedEntry:Fe,isSelectionOutOfScope:$e,latestTimestamp:Ve,isInitialLoading:!C.data&&C.isLoading||!D.data&&D.isLoading||!Q.data&&Q.isLoading,liveTail:{isPaused:h,pendingCount:we,pause:ge,resume:xe,togglePause:Re},clearAdvancedFilters:Me}}function zl(){const e=ks(),{t}=ir();return Rs({mutationFn:n=>Rt.logs.updateConfig(n),onSuccess:async()=>{await Promise.all([e.invalidateQueries({queryKey:Yr}),e.invalidateQueries({queryKey:Xr}),e.invalidateQueries({queryKey:["logs","entries"]})]),Bn.success(t("toasts.loggingConfigSaved"))},onError:n=>{Bn.error(n.message||t("toasts.loggingConfigSaveFailed"))}})}function Hl(){return[{value:"all",label:"All levels"},{value:"error",label:"Errors"},{value:"warn",label:"Warnings"},{value:"info",label:"Info"},{value:"debug",label:"Debug"}]}function Ll(){return[{value:"all",label:"All time"},{value:"5m",label:"Last 5m"},{value:"15m",label:"Last 15m"},{value:"1h",label:"Last 1h"},{value:"24h",label:"Last 24h"}]}function Ol(e){return Object.fromEntries(e.map(t=>[t.source,t.label]))}function Bl({label:e,onRemove:t}){return r.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full border border-border bg-muted/40 px-2 py-0.5 text-[11px] text-foreground/80",children:[e,r.jsx("button",{type:"button",onClick:t,"aria-label":`Remove ${e}`,className:K("rounded-full p-0.5 hover:bg-muted",ve),children:r.jsx(js,{className:"h-3 w-3","aria-hidden":"true"})})]})}function Fl({sources:e,selectedSource:t,onSourceChange:n,selectedLevel:s,onLevelChange:o,search:l,onSearchChange:i,limit:a,onLimitChange:c,onRefresh:u,isRefreshing:f,moduleFilter:p="",onModuleChange:x,stageFilter:v="",onStageChange:T,requestIdFilter:k="",onRequestIdChange:g,timeWindow:m="all",onTimeWindowChange:h,hideDashboardInternals:w=!1,onHideDashboardInternalsChange:H,onClearAll:E}){const[R,d]=O.useState(!1),b=Hl(),y=[50,100,150,250],z=Ll(),S=[];if(s!=="all"&&S.push({key:"level",label:`level: ${s}`,clear:()=>o("all")}),t!=="all"){const C=e.find(D=>D.source===t)?.label??t;S.push({key:"source",label:`source: ${C}`,clear:()=>n("all")})}return l.trim()&&S.push({key:"search",label:`search: ${l}`,clear:()=>i("")}),p&&S.push({key:"module",label:`module: ${p}`,clear:()=>x?.("")}),v&&S.push({key:"stage",label:`stage: ${v}`,clear:()=>T?.("")}),k&&S.push({key:"requestId",label:`requestId: ${k}`,clear:()=>g?.("")}),m!=="all"&&S.push({key:"timeWindow",label:`time: ${m}`,clear:()=>h?.("all")}),r.jsxs("div",{className:"flex flex-col gap-4",children:[r.jsxs("div",{className:"space-y-2",children:[r.jsx(Te,{htmlFor:"logs-search",className:"text-[11px] uppercase tracking-wide text-muted-foreground",children:"Search"}),r.jsxs("div",{className:"relative",children:[r.jsx(bs,{className:"pointer-events-none absolute left-2.5 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground","aria-hidden":"true"}),r.jsx(nt,{id:"logs-search",value:l,onChange:C=>i(C.target.value),placeholder:"Search message, event, module",className:"h-9 pl-8"})]})]}),r.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[r.jsxs("div",{className:"space-y-2",children:[r.jsx(Te,{htmlFor:"logs-level",className:"text-[11px] uppercase tracking-wide text-muted-foreground",children:"Level"}),r.jsxs(Tt,{value:s,onValueChange:C=>o(C),children:[r.jsx(Ct,{id:"logs-level",className:"h-9",children:r.jsx(Nt,{})}),r.jsx(kt,{children:b.map(C=>r.jsx(qe,{value:C.value,children:C.label},C.value))})]})]}),r.jsxs("div",{className:"space-y-2",children:[r.jsx(Te,{htmlFor:"logs-source",className:"text-[11px] uppercase tracking-wide text-muted-foreground",children:"Source"}),r.jsxs(Tt,{value:t,onValueChange:C=>n(C),children:[r.jsx(Ct,{id:"logs-source",className:"h-9",children:r.jsx(Nt,{})}),r.jsxs(kt,{children:[r.jsx(qe,{value:"all",children:"All sources"}),e.map(C=>r.jsx(qe,{value:C.source,children:C.label},C.source))]})]})]})]}),r.jsxs(ns,{open:R,onOpenChange:d,children:[r.jsx(rs,{asChild:!0,children:r.jsxs(ye,{variant:"ghost",size:"sm",className:K("h-7 w-full justify-between px-2 text-xs font-medium",ve),"aria-expanded":R,children:["Advanced filters",r.jsx(dr,{className:K("h-3.5 w-3.5 transition-transform",R&&"rotate-180"),"aria-hidden":"true"})]})}),r.jsxs(ss,{className:"mt-2 space-y-2",children:[x?r.jsxs("div",{className:"space-y-1",children:[r.jsx(Te,{htmlFor:"logs-module",className:"text-[11px] uppercase tracking-wide text-muted-foreground",children:"Module"}),r.jsx(nt,{id:"logs-module",value:p,onChange:C=>x(C.target.value),placeholder:"e.g. cliproxy.router",className:"h-9"})]}):null,T?r.jsxs("div",{className:"space-y-1",children:[r.jsx(Te,{htmlFor:"logs-stage",className:"text-[11px] uppercase tracking-wide text-muted-foreground",children:"Stage"}),r.jsx(nt,{id:"logs-stage",value:v,onChange:C=>T(C.target.value),placeholder:"e.g. handler",className:"h-9"})]}):null,g?r.jsxs("div",{className:"space-y-1",children:[r.jsx(Te,{htmlFor:"logs-request-id",className:"text-[11px] uppercase tracking-wide text-muted-foreground",children:"Request ID"}),r.jsx(nt,{id:"logs-request-id",value:k,onChange:C=>g(C.target.value),placeholder:"req_…",className:"h-9 font-mono"})]}):null,h?r.jsxs("div",{className:"space-y-1",children:[r.jsx(Te,{htmlFor:"logs-time-window",className:"text-[11px] uppercase tracking-wide text-muted-foreground",children:"Time window"}),r.jsxs(Tt,{value:m,onValueChange:C=>h(C),children:[r.jsx(Ct,{id:"logs-time-window",className:"h-9",children:r.jsx(Nt,{})}),r.jsx(kt,{children:z.map(C=>r.jsx(qe,{value:C.value,children:C.label},C.value))})]})]}):null,H?r.jsxs("div",{className:"flex items-start justify-between gap-3 rounded border border-border/60 bg-muted/20 p-2",children:[r.jsxs("div",{className:"space-y-0.5",children:[r.jsx(Te,{htmlFor:"logs-hide-internals",className:"block text-[12px] font-medium text-foreground",children:"Hide dashboard web-server logs"}),r.jsx("p",{className:"text-[11px] text-muted-foreground",children:"Optional noise reduction. Audit entries are visible by default."})]}),r.jsx("input",{id:"logs-hide-internals",type:"checkbox",role:"switch",checked:w,onChange:C=>H(C.target.checked),className:K("mt-0.5 h-4 w-4 cursor-pointer accent-foreground",ve),"aria-label":"Hide dashboard web-server logs"})]}):null]})]}),r.jsxs("div",{className:"space-y-2",children:[r.jsx(Te,{className:"text-[11px] uppercase tracking-wide text-muted-foreground",children:"Visible entries"}),r.jsx("div",{className:"grid grid-cols-4 gap-1",children:y.map(C=>r.jsx(ye,{type:"button",variant:a===C?"default":"outline",size:"sm",className:"h-8 text-xs",onClick:()=>c(C),children:C},C))})]}),S.length>0?r.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 border-t border-border pt-3",children:[r.jsx("span",{className:"text-[11px] uppercase tracking-wide text-muted-foreground",children:"Active:"}),S.map(C=>r.jsx(Bl,{label:C.label,onRemove:C.clear},C.key)),E?r.jsx(ye,{variant:"ghost",size:"sm",onClick:E,className:"h-7 px-2 text-[11px] text-muted-foreground",children:"Clear all"}):null]}):null]})}function Ml({isFetching:e,hasError:t,capturedCount:n,stats:s,onRefresh:o,onOpenSettings:l,onOpenShortcuts:i}){const a=t?"error":e?"syncing":"live",c=a==="error"?"Disconnected":a==="syncing"?"Syncing":"Live",u=a==="error"?"bg-red-500":a==="syncing"?"bg-amber-500":"bg-emerald-500";return r.jsxs("div",{className:"shrink-0 border-b border-border bg-background",children:[r.jsxs("div",{className:"flex h-14 items-center justify-between gap-4 px-4",children:[r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx(ws,{className:"h-4 w-4 text-foreground/70","aria-hidden":"true"}),r.jsx("span",{className:"text-[11px] font-mono uppercase tracking-[0.18em] text-muted-foreground",children:"LOGS.STREAM"}),r.jsx("h1",{className:"text-base font-semibold tracking-tight text-foreground",children:"Live activity"}),r.jsxs("span",{role:"status","aria-live":"polite",className:"ml-2 inline-flex items-center gap-1.5 rounded-full border border-border bg-muted/40 px-2.5 py-0.5 text-[12px] font-medium text-foreground/80",children:[r.jsx("span",{className:K("h-1.5 w-1.5 rounded-full",u),"aria-hidden":"true"}),c]})]}),r.jsxs("div",{className:"flex items-center gap-1.5",children:[r.jsxs(ye,{variant:"ghost",size:"sm",onClick:o,"aria-label":"Refresh logs",className:K("h-8 gap-2 px-2.5 text-xs font-medium",ve),children:[r.jsx(Ss,{className:K("h-3.5 w-3.5",e&&"animate-spin"),"aria-hidden":"true"}),"Refresh"]}),r.jsx(ye,{variant:"ghost",size:"icon",onClick:i,"aria-label":"Show keyboard shortcuts",title:"Keyboard shortcuts (?)",className:K("h-8 w-8",ve),children:r.jsx(ys,{className:"h-4 w-4","aria-hidden":"true"})}),r.jsx(ye,{variant:"ghost",size:"icon",onClick:l,"aria-label":"Open logging settings",className:K("h-8 w-8",ve),children:r.jsx(Is,{className:"h-4 w-4","aria-hidden":"true"})})]})]}),r.jsxs("div",{className:"flex items-center gap-6 border-t border-border/60 bg-muted/20 px-4 py-2",children:[r.jsx($t,{label:"Entries",value:n,fallback:`${n}`}),s?r.jsxs(r.Fragment,{children:[r.jsx($t,{label:"Traces",value:s.traces,fallback:`${s.traces}`}),r.jsx($t,{label:"Errors",value:s.errors,fallback:`${s.errors}`,tone:s.errors>0?"error":"neutral"})]}):null]})]})}function $t({label:e,value:t,fallback:n,tone:s="neutral"}){return r.jsxs("div",{className:"flex items-baseline gap-2",children:[r.jsx("span",{className:"text-[10px] font-mono uppercase tracking-[0.14em] text-muted-foreground",children:e}),r.jsx("span",{className:K("text-[14px] font-semibold tabular-nums",s==="error"?"text-red-600 dark:text-red-400":"text-foreground",Ae),title:String(t),children:n})]})}function Dl({isPaused:e,pendingCount:t,onTogglePause:n,onJumpToBottom:s}){return r.jsxs("div",{className:"flex w-full items-center justify-between gap-2",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsxs(ye,{variant:"ghost",size:"sm","aria-pressed":e,onClick:n,className:K("h-7 gap-1.5 px-2 text-xs font-medium",ve),children:[e?r.jsx(Ts,{className:"h-3.5 w-3.5","aria-hidden":"true"}):r.jsx(Cs,{className:"h-3.5 w-3.5","aria-hidden":"true"}),e?"Resume tail":"Pause tail"]}),e&&t>0?r.jsxs("button",{type:"button",onClick:n,"aria-live":"polite",className:K("inline-flex h-7 items-center gap-1.5 rounded-full border border-amber-500/40 bg-amber-500/10 px-2 text-[11px] font-medium text-amber-700 dark:text-amber-300",ve),children:[r.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-amber-500","aria-hidden":"true"}),t," new ",t===1?"entry":"entries"," · click to resume"]}):null]}),s?r.jsxs(ye,{variant:"ghost",size:"sm",onClick:s,className:K("h-7 gap-1.5 px-2 text-xs",ve),children:[r.jsx(Ns,{className:"h-3.5 w-3.5","aria-hidden":"true"}),"Jump to bottom"]}):null]})}const Pl=[{keys:["j","↓"],label:"Next entry"},{keys:["k","↑"],label:"Previous entry"},{keys:["Enter"],label:"Focus detail"},{keys:["Esc"],label:"Close detail (mobile)"},{keys:["/"],label:"Focus search"},{keys:["Space"],label:"Pause / resume tail"},{keys:["?"],label:"Show this help"}];function Al({children:e}){return r.jsx("kbd",{className:"inline-flex h-5 min-w-[20px] items-center justify-center rounded border border-border bg-muted px-1.5 font-mono text-[11px] font-medium text-foreground",children:e})}function Wl({open:e,onOpenChange:t}){return r.jsx(os,{open:e,onOpenChange:t,children:r.jsxs(ls,{className:"max-w-md",children:[r.jsxs(is,{children:[r.jsx(as,{children:"Keyboard shortcuts"}),r.jsx(cs,{children:"Logs surface keybindings."})]}),r.jsx("ul",{className:"mt-2 space-y-2",children:Pl.map(n=>r.jsxs("li",{className:"flex items-center justify-between text-sm",children:[r.jsx("span",{className:"text-foreground/90",children:n.label}),r.jsx("span",{className:"flex items-center gap-1",children:n.keys.map(s=>r.jsx(Al,{children:s},s))})]},n.label))})]})})}function _l(e){if(!(e instanceof HTMLElement))return!1;const t=e.tagName;return t==="INPUT"||t==="TEXTAREA"||t==="SELECT"?!0:e.isContentEditable}function Vl({entryIds:e,selectedId:t,onSelect:n,onTogglePause:s,onFocusSearch:o,onOpenShortcuts:l,onCloseDetail:i,enabled:a=!0}){O.useEffect(()=>{if(!a)return;const c=u=>{if(!(u.metaKey||u.ctrlKey||u.altKey)){if(u.key==="/"){u.preventDefault(),o();return}if(u.key==="?"){u.preventDefault(),l();return}if(!_l(u.target)){if(u.key==="Escape"&&i){i();return}if(u.key===" "){u.preventDefault(),s();return}if(u.key==="j"||u.key==="ArrowDown"){if(u.preventDefault(),e.length===0)return;const f=t?e.indexOf(t):-1,p=e[Math.min(f+1,e.length-1)]??e[0];p&&n(p);return}if(u.key==="k"||u.key==="ArrowUp"){if(u.preventDefault(),e.length===0)return;const f=t?e.indexOf(t):0,p=e[Math.max(f-1,0)]??e[0];p&&n(p);return}}}};return window.addEventListener("keydown",c),()=>window.removeEventListener("keydown",c)},[a,e,t,n,s,o,l,i])}const ln="ccs.logs.layout.v1",Jt=1200,Yt={filters:22,list:52,detail:26};function ql(){if(typeof window>"u")return Yt;try{const e=window.localStorage.getItem(ln);if(!e)return Yt;const t=JSON.parse(e);if(typeof t.filters=="number"&&typeof t.list=="number"&&typeof t.detail=="number")return{filters:t.filters,list:t.list,detail:t.detail}}catch{}return Yt}function Gl(){const[e,t]=O.useState(()=>typeof window>"u"?!0:window.innerWidth>=Jt);return O.useEffect(()=>{if(typeof window>"u")return;const n=window.matchMedia(`(min-width: ${Jt}px)`),s=()=>t(window.innerWidth>=Jt);return s(),n.addEventListener("change",s),()=>n.removeEventListener("change",s)},[]),e}function Ql({workspace:e,updateConfig:t}){const n=Gl(),s=O.useMemo(()=>Ol(e.sourcesQuery.data??[]),[e.sourcesQuery.data]),[o,l]=O.useState(null),[i,a]=O.useState(ql),[c,u]=O.useState(!1),f=O.useRef(null),p=e.configQuery.data,x=O.useCallback(()=>{Promise.all([e.sourcesQuery.refetch(),e.entriesQuery.refetch()])},[e.entriesQuery,e.sourcesQuery]),v=O.useCallback(S=>{if(S.length!==3)return;const[C,D,B]=S,V={filters:C,list:D,detail:B};a(V);try{window.localStorage.setItem(ln,JSON.stringify(V))}catch{}},[]),T=O.useCallback(()=>l("settings"),[]),k=O.useCallback(()=>l("detail"),[]),g=O.useCallback(()=>l(null),[]),m=e.setSelectedEntryId,h=O.useCallback(S=>{m(S),!n&&S&&l("detail")},[m,n]),w=O.useCallback(S=>{e.setRequestIdFilter(S),e.setSearch("")},[e]),H=O.useMemo(()=>(e.entriesQuery.data??[]).map(S=>S.id),[e.entriesQuery.data]),E=O.useMemo(()=>{const S=e.entriesQuery.data??[],C=new Set;let D=0;for(const B of S)B.requestId&&C.add(B.requestId),B.level==="error"&&(D+=1);return{entries:S.length,traces:C.size,errors:D}},[e.entriesQuery.data]),R=O.useCallback(()=>{const S=document.getElementById("logs-search");S?(S.focus(),S.select()):f.current&&f.current.focus()},[]);if(Vl({entryIds:H,selectedId:e.selectedEntryId,onSelect:e.setSelectedEntryId,onTogglePause:e.liveTail.togglePause,onFocusSearch:R,onOpenShortcuts:()=>u(!0),onCloseDetail:!n&&o==="detail"?g:void 0}),!p)return null;const d=r.jsx(Fl,{sources:e.sourcesQuery.data??[],selectedSource:e.selectedSource,onSourceChange:e.setSelectedSource,selectedLevel:e.selectedLevel,onLevelChange:e.setSelectedLevel,search:e.search,onSearchChange:e.setSearch,limit:e.limit,onLimitChange:e.setLimit,onRefresh:x,isRefreshing:e.entriesQuery.isFetching||e.sourcesQuery.isFetching,moduleFilter:e.moduleFilter,onModuleChange:e.setModuleFilter,stageFilter:e.stageFilter,onStageChange:e.setStageFilter,requestIdFilter:e.requestIdFilter,onRequestIdChange:e.setRequestIdFilter,timeWindow:e.timeWindow,onTimeWindowChange:e.setTimeWindow,hideDashboardInternals:e.hideDashboardInternals,onHideDashboardInternalsChange:e.setHideDashboardInternals,onClearAll:e.clearAdvancedFilters}),b=r.jsx(Dl,{isPaused:e.liveTail.isPaused,pendingCount:e.liveTail.pendingCount,onTogglePause:e.liveTail.togglePause}),y=e.entriesQuery.error?r.jsx(Il,{error:e.entriesQuery.error,onRetry:()=>void e.entriesQuery.refetch()}):r.jsx(yl,{entries:e.entriesQuery.data??[],selectedEntryId:e.selectedEntryId,onSelect:h,sourceLabels:s,isLoading:e.entriesQuery.isLoading,isFetching:e.entriesQuery.isFetching,liveTailSlot:b}),z=e.isSelectionOutOfScope?r.jsx(cn,{variant:"selectionOutOfScope",onClearFilters:e.clearAdvancedFilters}):r.jsx(Ps,{entry:e.selectedEntry,sourceLabel:e.selectedEntry?s[e.selectedEntry.source]:void 0,onShowTrace:w,redact:!!p.redact});return r.jsxs("div",{className:"flex h-full min-h-0 flex-col bg-background text-foreground",children:[r.jsx(Ml,{isFetching:e.entriesQuery.isFetching||e.sourcesQuery.isFetching,hasError:!!e.entriesQuery.error,capturedCount:e.entriesQuery.data?.length??0,stats:E,onRefresh:x,onOpenSettings:T,onOpenShortcuts:()=>u(!0)}),r.jsxs(or,{defaultValue:"stream",className:"flex min-h-0 flex-1 flex-col overflow-hidden",children:[r.jsx("div",{className:"flex h-10 shrink-0 items-center border-b border-border bg-background px-4",children:r.jsxs(lr,{className:"h-8 bg-muted/40",children:[r.jsx(it,{value:"stream",className:"text-xs",children:"Stream"}),r.jsx(it,{value:"errors",className:"text-xs",children:"Upstream errors"})]})}),r.jsx(at,{value:"stream",className:"m-0 flex min-h-0 flex-1 overflow-hidden focus-visible:outline-none",children:n?r.jsxs(us,{direction:"horizontal",onLayout:v,className:"flex min-h-0 flex-1",autoSaveId:ln,children:[r.jsx(At,{defaultSize:i.filters,minSize:16,maxSize:36,order:1,children:r.jsx("div",{className:"flex h-full min-h-0 flex-col overflow-y-auto border-r border-border bg-background p-4",children:d})}),r.jsx(Rn,{className:"w-px bg-border transition-colors hover:bg-foreground/20 data-[resize-handle-active]:bg-foreground/30"}),r.jsx(At,{defaultSize:i.list,minSize:32,order:2,children:r.jsx("div",{className:"flex h-full min-h-0 flex-col overflow-hidden bg-background",children:y})}),r.jsx(Rn,{className:"w-px bg-border transition-colors hover:bg-foreground/20 data-[resize-handle-active]:bg-foreground/30"}),r.jsx(At,{defaultSize:i.detail,minSize:20,maxSize:42,order:3,children:r.jsx("div",{className:"flex h-full min-h-0 flex-col overflow-hidden border-l border-border bg-background",children:z})})]}):r.jsxs("div",{className:"flex min-h-0 flex-1 flex-col",children:[r.jsx("div",{className:"border-b border-border p-3",children:d}),r.jsx("div",{className:"flex min-h-0 flex-1 flex-col overflow-hidden",children:y})]})}),r.jsx(at,{value:"errors",className:"m-0 flex-1 overflow-y-auto p-4 focus-visible:outline-none",children:r.jsxs("div",{className:"mx-auto max-w-5xl space-y-4",children:[r.jsxs("header",{className:"space-y-1",children:[r.jsx("h2",{className:"text-base font-semibold text-foreground",children:"CLIProxy upstream errors"}),r.jsx("p",{className:"text-sm text-muted-foreground",children:"Historical failure stream from the upstream proxy. Distinct from the structured stream."})]}),r.jsx(ds,{})]})})]}),r.jsx(En,{open:o==="settings",onOpenChange:S=>S?T():g(),children:r.jsxs(zn,{side:"right",className:"w-full max-w-md",children:[r.jsxs(Hn,{children:[r.jsx(Ln,{children:"Logging settings"}),r.jsx(On,{children:"Configure retention, redaction, and sampling for the logs surface."})]}),r.jsx("div",{className:"mt-4 px-4 pb-6",children:r.jsx(zs,{config:p,onSave:S=>t.mutate(S),isPending:t.isPending})})]})}),r.jsx(Wl,{open:c,onOpenChange:u}),n?null:r.jsx(En,{open:o==="detail",onOpenChange:S=>S?k():g(),children:r.jsxs(zn,{side:"bottom",className:"h-[85vh]",children:[r.jsxs(Hn,{children:[r.jsx(Ln,{children:"Entry detail"}),r.jsx(On,{children:"Selected log entry context and raw payload."})]}),r.jsx("div",{className:"mt-2 flex min-h-0 flex-1 overflow-hidden",children:z})]})})]})}function Ul(){const{t:e}=ir();return r.jsxs("div",{className:"flex h-full min-h-0 flex-col bg-background","aria-busy":"true","aria-live":"polite","aria-label":e("logsPageSkeleton.loadingLogs"),children:[r.jsxs("div",{className:"flex h-12 items-center justify-between border-b border-border px-4",children:[r.jsx(ze,{className:"h-4 w-24"}),r.jsx(ze,{className:"h-6 w-28"})]}),r.jsx("div",{className:"flex h-10 items-center border-b border-border px-4",children:r.jsx(ze,{className:"h-6 w-40"})}),r.jsxs("div",{className:"grid min-h-0 flex-1 grid-cols-[22%_52%_26%] gap-px bg-border",children:[r.jsxs("div",{className:"space-y-3 bg-background p-4",children:[r.jsx(ze,{className:"h-8 w-full"}),r.jsx(ze,{className:"h-8 w-full"}),r.jsx(ze,{className:"h-8 w-full"}),r.jsx(ze,{className:"h-32 w-full"})]}),r.jsx("div",{className:"space-y-2 bg-background p-3",children:Array.from({length:12}).map((t,n)=>r.jsx(ze,{className:"h-8 w-full"},n))}),r.jsxs("div",{className:"space-y-3 bg-background p-4",children:[r.jsx(ze,{className:"h-6 w-32"}),r.jsx(ze,{className:"h-4 w-full"}),r.jsx(ze,{className:"h-4 w-3/4"}),r.jsx(ze,{className:"h-40 w-full"})]})]})]})}function ri(){const e=El(),t=zl();return e.isInitialLoading?r.jsx(Ul,{}):e.configQuery.data?r.jsx(Ql,{workspace:e,updateConfig:t}):null}export{ri as LogsPage};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as e}from"./radix-ui-nu4wz29m.js";import{r as o}from"./react-vendor-Bjx91N7w.js";import{I as l,c as d}from"./index-
|
|
1
|
+
import{j as e}from"./radix-ui-nu4wz29m.js";import{r as o}from"./react-vendor-Bjx91N7w.js";import{I as l,c as d}from"./index-BoxFkFUH.js";import{ak as m,E as u,g as x}from"./icons-DzKUh8vG.js";function j({label:t,hideSensitivePill:a=!1,className:i,...r}){const[s,c]=o.useState(!1);return e.jsxs("div",{className:"group/masked space-y-1.5",children:[t&&e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("label",{className:"flex items-center gap-1.5 text-sm font-medium",children:[e.jsx(m,{"aria-hidden":!0,className:"size-3 text-accent/70"}),t]}),!a&&e.jsx("span",{className:"rounded border border-accent/40 bg-accent/10 px-1.5 py-0.5 text-[9px] font-medium uppercase tracking-wider text-accent",children:"sensitive"})]}),e.jsxs("div",{className:"relative",children:[e.jsx(l,{...r,type:s?"text":"password",className:d("pr-9 font-mono transition-all","focus-visible:ring-1 focus-visible:ring-accent/40 focus-visible:border-accent/50",i)}),e.jsx("button",{type:"button",onClick:()=>c(n=>!n),"aria-label":s?"Hide value":"Reveal value","aria-pressed":s,className:"absolute right-1.5 top-1/2 flex size-7 -translate-y-1/2 items-center justify-center rounded text-muted-foreground transition-colors hover:bg-muted hover:text-accent focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-accent/60",children:s?e.jsx(u,{className:"size-3.5"}):e.jsx(x,{className:"size-3.5"})})]})]})}export{j as M};
|