tokentracker-cli 1.3.8 → 1.3.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (129) hide show
  1. package/README.de.md +7 -6
  2. package/README.ja.md +6 -5
  3. package/README.ko.md +6 -5
  4. package/README.md +7 -6
  5. package/README.zh-CN.md +6 -5
  6. package/dashboard/dist/assets/{AchievementBadge-BqLeP5y3.js → AchievementBadge-vU4Dwu_p.js} +1 -1
  7. package/dashboard/dist/assets/{AchievementsPage-BwVkM45R.js → AchievementsPage-C8LspyPK.js} +2 -2
  8. package/dashboard/dist/assets/{AchievementsSection-CglgOcQ1.js → AchievementsSection-CP8J07fV.js} +1 -1
  9. package/dashboard/dist/assets/{BadgeDetailModal-IurF0cmo.js → BadgeDetailModal-Ci1egHvR.js} +1 -1
  10. package/dashboard/dist/assets/{BotAnimated-C4_NxPuy.js → BotAnimated-CMXILM_h.js} +1 -1
  11. package/dashboard/dist/assets/{Card-C-UuIN42.js → Card-BHHCCnqR.js} +1 -1
  12. package/dashboard/dist/assets/{CloudCheckoutPage-CrMDquLi.js → CloudCheckoutPage-BY9Hsbix.js} +1 -1
  13. package/dashboard/dist/assets/{CloudPage-D6xTPnMs.js → CloudPage-Y6JgOXcJ.js} +2 -2
  14. package/dashboard/dist/assets/{CommandPalette-8LFLY-LQ.js → CommandPalette-BRWQFJwy.js} +1 -1
  15. package/dashboard/dist/assets/CommunityStatsModal-krT4ZZX9.js +1 -0
  16. package/dashboard/dist/assets/{ConfirmModal-St89kP59.js → ConfirmModal-ZvPOJ0he.js} +1 -1
  17. package/dashboard/dist/assets/Controls-CQlxw03i.js +1 -0
  18. package/dashboard/dist/assets/{DashboardPage-BvGqFvP7.js → DashboardPage-Dbi0d2JY.js} +1 -1
  19. package/dashboard/dist/assets/{DateRangePopover-Cbd1idiF.js → DateRangePopover-DJ8RpQfV.js} +1 -1
  20. package/dashboard/dist/assets/DevicePage-C4_cbw3M.js +1 -0
  21. package/dashboard/dist/assets/{DialogClose-Cb1-Hd8P.js → DialogClose-Dx5AqmUG.js} +1 -1
  22. package/dashboard/dist/assets/DialogDescription-LvhfT1Ox.js +1 -0
  23. package/dashboard/dist/assets/{DialogTitle-VXrHY7H0.js → DialogTitle-Cro2S8s8.js} +1 -1
  24. package/dashboard/dist/assets/{ElectricLogo-DmQqYnSD.js → ElectricLogo-gqnBCtSG.js} +1 -1
  25. package/dashboard/dist/assets/{FadeIn-BEieTXMD.js → FadeIn-B9oATcDZ.js} +1 -1
  26. package/dashboard/dist/assets/{HeaderGithubStar-BlYC_PSb.js → HeaderGithubStar-CYa94wna.js} +1 -1
  27. package/dashboard/dist/assets/{HoverTooltip-C5Pe7iBz.js → HoverTooltip-BJ4qLyuS.js} +1 -1
  28. package/dashboard/dist/assets/{IpCheckPage-Diln3EdG.js → IpCheckPage-Clpq3jdY.js} +1 -1
  29. package/dashboard/dist/assets/{LandingPage-BzGYuAO7.js → LandingPage-CuazuOAo.js} +2 -2
  30. package/dashboard/dist/assets/{LeaderboardPage-Bn-ehU5S.js → LeaderboardPage-BSF1Lbtq.js} +2 -2
  31. package/dashboard/dist/assets/{LeaderboardProBadge-SovdGwYs.js → LeaderboardProBadge-K32gY52s.js} +1 -1
  32. package/dashboard/dist/assets/{LeaderboardProfileModal-BhxmTcHh.js → LeaderboardProfileModal-D5gpn7pP.js} +3 -3
  33. package/dashboard/dist/assets/{LeaderboardProfilePage-3iAYvoTb.js → LeaderboardProfilePage-BmO9nIi-.js} +1 -1
  34. package/dashboard/dist/assets/{LimitsPage-DHxFAdqK.js → LimitsPage-D9ZJ1TeK.js} +1 -1
  35. package/dashboard/dist/assets/{LocalOnlyNotice-HlGfiiI3.js → LocalOnlyNotice-BkzysTS7.js} +1 -1
  36. package/dashboard/dist/assets/{LoginCard-CamUYmiF.js → LoginCard-Do3SNJFU.js} +1 -1
  37. package/dashboard/dist/assets/{LoginModal-CcmYUJ45.js → LoginModal-hph1i_YK.js} +1 -1
  38. package/dashboard/dist/assets/{LoginPage-DMNNmZwr.js → LoginPage-DXYAaFjJ.js} +1 -1
  39. package/dashboard/dist/assets/{PetPage-D6xFX8QA.js → PetPage-D1Pk4OKI.js} +2 -2
  40. package/dashboard/dist/assets/{PopoverPopup-CKKgItAT.js → PopoverPopup-CAIuP_a5.js} +1 -1
  41. package/dashboard/dist/assets/{ProviderIcon-B-uS3pJ3.js → ProviderIcon-R6Bsj81X.js} +1 -1
  42. package/dashboard/dist/assets/{ResetPasswordPage-DX4RJjX0.js → ResetPasswordPage-BR3GTF-3.js} +1 -1
  43. package/dashboard/dist/assets/{Select-Dcg7FYAt.js → Select-38Dh-OWv.js} +1 -1
  44. package/dashboard/dist/assets/{SelectItemText-4vuj6xMs.js → SelectItemText-90n7jKbI.js} +1 -1
  45. package/dashboard/dist/assets/{SelfHostPage-ButVBgE7.js → SelfHostPage-BKVYkHI6.js} +1 -1
  46. package/dashboard/dist/assets/{ServiceStatusPage-DJDDO6lV.js → ServiceStatusPage-PBmBn29J.js} +1 -1
  47. package/dashboard/dist/assets/{SessionsPage-CiUirFMD.js → SessionsPage-58MfDHhe.js} +3 -3
  48. package/dashboard/dist/assets/SettingsPage-BNLHbZUQ.js +5 -0
  49. package/dashboard/dist/assets/{SkillsPage-D2tfFFY8.js → SkillsPage-DMMTk4jD.js} +1 -1
  50. package/dashboard/dist/assets/{TokenGalaxy-TQ-eWK8P.js → TokenGalaxy-BdPETjru.js} +1 -1
  51. package/dashboard/dist/assets/{TooltipPopup-BhSCJqFR.js → TooltipPopup-BXl-vM4L.js} +1 -1
  52. package/dashboard/dist/assets/{TrendMonitor-CP6ZZ53c.js → TrendMonitor-wPfTlX-7.js} +1 -1
  53. package/dashboard/dist/assets/{WidgetsPage-BdeR7P8D.js → WidgetsPage-CuwRMWka.js} +1 -1
  54. package/dashboard/dist/assets/{WrappedPage-OqcqupRE.js → WrappedPage-DOpA9kkg.js} +1 -1
  55. package/dashboard/dist/assets/{__vite-browser-external-BXwSXUpN.js → __vite-browser-external-Go6WKt6Z.js} +3 -3
  56. package/dashboard/dist/assets/__vite-browser-external-kAUz3kFs.css +1 -0
  57. package/dashboard/dist/assets/{agent-logos-E6GfkcgD.js → agent-logos-D7eMvAlk.js} +1 -1
  58. package/dashboard/dist/assets/{arrow-left-D_ufthLH.js → arrow-left--eOVP_Dk.js} +1 -1
  59. package/dashboard/dist/assets/{arrow-right-CgV_OrFz.js → arrow-right-DJYhwBMz.js} +1 -1
  60. package/dashboard/dist/assets/{arrow-up-right-CzeEeXRz.js → arrow-up-right-DhDvpd-S.js} +1 -1
  61. package/dashboard/dist/assets/{calendar-days-BQdTF7ec.js → calendar-days-BuOFlNcJ.js} +1 -1
  62. package/dashboard/dist/assets/{check-C--D8Lze.js → check-UztXSVYi.js} +1 -1
  63. package/dashboard/dist/assets/{chevron-down-BzkceD4z.js → chevron-down-CbJ2QGDU.js} +1 -1
  64. package/dashboard/dist/assets/{cloud-checkout-m1Yllbij.js → cloud-checkout-CoRQjKEu.js} +1 -1
  65. package/dashboard/dist/assets/{composite-7DhFi6TA.js → composite-PlKvZfdM.js} +1 -1
  66. package/dashboard/dist/assets/{download-BSyGLtfW.js → download-McE9gFto.js} +1 -1
  67. package/dashboard/dist/assets/{external-link-KzFbueBT.js → external-link-DZWnR9gS.js} +1 -1
  68. package/dashboard/dist/assets/{flame-DlPM_oaj.js → flame-0xjueXt4.js} +1 -1
  69. package/dashboard/dist/assets/{format-tokens-BHBaWyA3.js → format-tokens-CZoG68uJ.js} +1 -1
  70. package/dashboard/dist/assets/{gift-BhWBQnun.js → gift-pKc80Nqb.js} +1 -1
  71. package/dashboard/dist/assets/{host-mode--iIPGrkN.js → host-mode-99_v1j5J.js} +1 -1
  72. package/dashboard/dist/assets/{icons-COEaSBYi.js → icons-BtfYKSGC.js} +1 -1
  73. package/dashboard/dist/assets/{index-Cf4HcmLp.js → index-Cgthm7BO.js} +1 -1
  74. package/dashboard/dist/assets/{index-Bo8CSxCq.js → index-CyZxN1O0.js} +1 -1
  75. package/dashboard/dist/assets/{index-CW6A_Ff_.js → index-DuaQmNZo.js} +1 -1
  76. package/dashboard/dist/assets/{info-D1gOdsM_.js → info-C8vkxwsO.js} +1 -1
  77. package/dashboard/dist/assets/{link-2-CXDnDOK4.js → link-2-CQzIW5b6.js} +1 -1
  78. package/dashboard/dist/assets/{loader-circle-DWeQPecG.js → loader-circle-B9GqzQyC.js} +1 -1
  79. package/dashboard/dist/assets/{modifiers.esm-BljqMT7V.js → modifiers.esm-ChkCUrZp.js} +1 -1
  80. package/dashboard/dist/assets/{monitor-smartphone-DpkdtOjk.js → monitor-smartphone-DQjBY1W3.js} +1 -1
  81. package/dashboard/dist/assets/{play-BlGNrekI.js → play-qC6xc6fe.js} +1 -1
  82. package/dashboard/dist/assets/{plus-CpYVQ_t-.js → plus-CoNHx5Og.js} +1 -1
  83. package/dashboard/dist/assets/{provider-display-D6Blvktj.js → provider-display-x2EG6zAY.js} +1 -1
  84. package/dashboard/dist/assets/{react-BMJ2wuz1.js → react-EctmAw3f.js} +1 -1
  85. package/dashboard/dist/assets/{safePolygon-BFHXICk1.js → safePolygon-DlSbLtZC.js} +1 -1
  86. package/dashboard/dist/assets/{search-0NxXkytY.js → search-CBcpAj9I.js} +1 -1
  87. package/dashboard/dist/assets/{server-GHkrUKSI.js → server-DtMUoEq0.js} +1 -1
  88. package/dashboard/dist/assets/{shield-check-C16cbx1z.js → shield-check-ByUPtUmu.js} +1 -1
  89. package/dashboard/dist/assets/{skills-api-DAm1fFB4.js → skills-api-BD9VNRej.js} +1 -1
  90. package/dashboard/dist/assets/{sortable.esm-CkOax8h0.js → sortable.esm-B6qEViGJ.js} +1 -1
  91. package/dashboard/dist/assets/{store-DR444-5P.js → store-BgW2uBRe.js} +1 -1
  92. package/dashboard/dist/assets/{terminal-BpvNaIz9.js → terminal-DWPNkr2L.js} +1 -1
  93. package/dashboard/dist/assets/{trash-DX8LwOmN.js → trash-DdbRpgD1.js} +1 -1
  94. package/dashboard/dist/assets/{use-community-stats-BFW4-DYG.js → use-community-stats-43ySv9uM.js} +1 -1
  95. package/dashboard/dist/assets/{use-latest-request-guard-Cpcl08EJ.js → use-latest-request-guard-BuezAv4k.js} +1 -1
  96. package/dashboard/dist/assets/{use-limits-display-prefs-BqixyeAa.js → use-limits-display-prefs-Yi0Hznar.js} +1 -1
  97. package/dashboard/dist/assets/{use-native-settings-BSx7lGEK.js → use-native-settings-BaSrhrM8.js} +1 -1
  98. package/dashboard/dist/assets/{use-ordered-list-UCjB0_zK.js → use-ordered-list-CBD-EIBf.js} +1 -1
  99. package/dashboard/dist/assets/use-reduced-motion-ObUuoXUE.js +1 -0
  100. package/dashboard/dist/assets/{use-session-efficiency-pref-BgOJaGEy.js → use-session-efficiency-pref-CwaFIkE5.js} +1 -1
  101. package/dashboard/dist/assets/{use-transform-Y98QifnQ.js → use-transform-Dea4uz8K.js} +1 -1
  102. package/dashboard/dist/assets/{use-usage-limits-DJGO-Kxv.js → use-usage-limits-DxkYcUIR.js} +1 -1
  103. package/dashboard/dist/assets/{useCurrency-DL458pqS.js → useCurrency-CcZktkbA.js} +1 -1
  104. package/dashboard/dist/assets/{usePositioner-DnCQwlVT.js → usePositioner-BLGIGihf.js} +1 -1
  105. package/dashboard/dist/assets/{useTokenFormat-CYLt9pgs.js → useTokenFormat--dhm3nNf.js} +1 -1
  106. package/dashboard/dist/assets/{zap-BW6E_Jv3.js → zap-CWTmP6Zw.js} +1 -1
  107. package/dashboard/dist/index.html +14 -12
  108. package/dashboard/dist/ip-check.html +2 -2
  109. package/dashboard/dist/leaderboard.html +2 -2
  110. package/dashboard/dist/llms.txt +3 -2
  111. package/dashboard/dist/share.html +2 -2
  112. package/package.json +2 -2
  113. package/src/commands/init.js +9 -0
  114. package/src/commands/status.js +11 -0
  115. package/src/commands/sync.js +197 -122
  116. package/src/lib/dumate.js +95 -0
  117. package/src/lib/pricing/seed-snapshot.json +1 -1
  118. package/src/lib/qoder-cn-cli-limits.js +117 -0
  119. package/src/lib/qoder-limits.js +24 -11
  120. package/src/lib/rollout.js +12 -9
  121. package/src/lib/session-analytics.js +210 -19
  122. package/src/lib/upload-queue.js +134 -0
  123. package/dashboard/dist/assets/CommunityStatsModal-DYTjxABN.js +0 -1
  124. package/dashboard/dist/assets/Controls-BJAwM2gB.js +0 -1
  125. package/dashboard/dist/assets/DevicePage-BcSU0xgf.js +0 -1
  126. package/dashboard/dist/assets/DialogDescription-DQvYzWMp.js +0 -1
  127. package/dashboard/dist/assets/SettingsPage-CB4CML8u.js +0 -5
  128. package/dashboard/dist/assets/__vite-browser-external-DvNSoTb8.css +0 -1
  129. package/dashboard/dist/assets/use-reduced-motion-C6zOHbfR.js +0 -1
@@ -1,3 +1,3 @@
1
- import{o as Re,r as i,j as e,y as Q,c as s,Z as Oe,X as Ee,i as N,az as ke,W as we,R as ls,V as ye,aM as cs,bj as Y}from"./__vite-browser-external-BXwSXUpN.js";import{L as ds,I as us}from"./LocalOnlyNotice-HlGfiiI3.js";import{S as ie}from"./Select-Dcg7FYAt.js";import{C as ms}from"./chevron-down-BzkceD4z.js";import{S as $e}from"./search-0NxXkytY.js";import{C as xs}from"./check-C--D8Lze.js";import{P as gs,a as hs,b as ps,c as fs,d as bs}from"./PopoverPopup-CKKgItAT.js";import{P as Pe}from"./ProviderIcon-B-uS3pJ3.js";import{H as ys}from"./HoverTooltip-C5Pe7iBz.js";import{u as je}from"./useCurrency-DL458pqS.js";import{i as _s,C as ks}from"./host-mode--iIPGrkN.js";import{L as js}from"./loader-circle-DWeQPecG.js";import{I as vs}from"./info-D1gOdsM_.js";import{a as ws,b as Ns,c as Ss,d as Cs,e as Ms}from"./TooltipPopup-BhSCJqFR.js";import"./arrow-up-right-CzeEeXRz.js";import"./download-BSyGLtfW.js";import"./SelectItemText-4vuj6xMs.js";import"./composite-7DhFi6TA.js";import"./usePositioner-DnCQwlVT.js";import"./store-DR444-5P.js";import"./safePolygon-BFHXICk1.js";const Ae={name:"calendar",size:24,node:[["path",{d:"M8 2v3",key:"1ioesn"}],["path",{d:"M16 2v3",key:"otl347"}],["rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",key:"h1oib"}],["path",{d:"M3 9h18",key:"1pudct"}]]};Ae.node;const Ts=Re(Ae);const qe={name:"folder",size:24,node:[["path",{d:"M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z",key:"1kt360"}]]};qe.node;const Ds=Re(qe),Ls="flex w-full items-center gap-2 rounded px-2 py-1.5 text-left text-sm text-oai-black outline-none hover:bg-oai-gray-100 dark:text-white dark:hover:bg-oai-gray-800";function Ne({options:a,value:t,onChange:r,allValue:o="all",allLabel:u,searchPlaceholder:p,emptyLabel:n,ariaLabel:f,disabled:k=!1,className:j=""}){const[v,w]=i.useState(!1),[x,g]=i.useState(""),[b,y]=i.useState(-1),L=i.useRef(null),S=`${i.useId()}-listbox`,P=t===o?u:a.find(h=>h.value===t)?.label??t,M=x.trim().toLowerCase(),D=i.useMemo(()=>M?a.filter(h=>h.label.toLowerCase().includes(M)):a,[a,M]),C=i.useMemo(()=>[{value:o,label:u},...D],[o,u,D]),R=b>=0&&b<C.length?C[b]:null,A=h=>{r(h),w(!1),g(""),y(-1)};i.useEffect(()=>{v&&L.current?.querySelector('[data-active="true"]')?.scrollIntoView?.({block:"nearest"})},[v,b]);const J=h=>{if(h.key==="ArrowDown"||h.key==="ArrowUp"){h.preventDefault();const T=h.key==="ArrowDown";y(I=>{const c=C.length;return c?T?I>=c-1?0:I+1:I<=0?c-1:I-1:-1});return}if(h.key==="Enter"){const T=R||(M&&D.length?D[0]:null);if(!T)return;h.preventDefault(),A(T.value)}};return e.jsxs(gs,{open:v,onOpenChange:h=>{w(h),y(-1),h||g("")},children:[e.jsxs(hs,{disabled:k,"aria-label":f,className:Q("inline-flex h-8 max-w-[12rem] shrink-0 items-center gap-1.5 rounded-md border border-oai-gray-200 bg-oai-white px-2.5 text-xs font-medium transition hover:border-oai-gray-300 focus:outline-none focus:ring-2 focus:ring-oai-gray-400/30 disabled:opacity-60 data-[popup-open]:border-oai-gray-300 dark:border-oai-gray-800 dark:bg-oai-gray-900 dark:hover:border-oai-gray-700",t!==o?"text-oai-black dark:text-white":"text-oai-gray-700 dark:text-oai-gray-200",j),children:[e.jsx(Ds,{className:"h-3.5 w-3.5 shrink-0 text-oai-gray-400","aria-hidden":!0}),e.jsx("span",{className:"truncate",children:P}),e.jsx(ms,{className:"h-3.5 w-3.5 shrink-0 text-oai-gray-400","aria-hidden":!0})]}),e.jsx(ps,{children:e.jsx(fs,{sideOffset:4,side:"bottom",align:"start",className:"z-[60]",children:e.jsxs(bs,{className:"w-56 overflow-hidden rounded-md border border-oai-gray-200 bg-white p-1 shadow-[0_12px_32px_-12px_rgba(0,0,0,0.18)] outline-none dark:border-oai-gray-800 dark:bg-oai-gray-950 dark:shadow-[0_12px_32px_-12px_rgba(0,0,0,0.6)]",children:[e.jsxs("div",{className:"relative mb-1",children:[e.jsx($e,{className:"pointer-events-none absolute left-2.5 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-oai-gray-400","aria-hidden":!0}),e.jsx("input",{type:"text",role:"combobox","aria-expanded":!0,"aria-controls":S,"aria-activedescendant":R?`${S}-${b}`:void 0,value:x,onChange:h=>{g(h.target.value),y(-1)},onKeyDown:J,placeholder:p,className:"h-8 w-full rounded border border-oai-gray-200 bg-transparent pl-8 pr-2 text-xs text-oai-black outline-none placeholder:text-oai-gray-400 focus:border-oai-gray-400 dark:border-oai-gray-800 dark:text-white dark:focus:border-oai-gray-500"})]}),e.jsxs("div",{ref:L,id:S,role:"listbox","aria-label":f,className:"max-h-64 overflow-y-auto",children:[C.map((h,T)=>e.jsxs("button",{id:`${S}-${T}`,type:"button",role:"option","aria-selected":t===h.value,"data-active":T===b?"true":void 0,onMouseEnter:()=>y(T),onClick:()=>A(h.value),className:Q(Ls,t===h.value&&"bg-oai-gray-100 dark:bg-oai-gray-800",T===b&&"ring-1 ring-inset ring-oai-gray-300 dark:ring-oai-gray-600"),children:[e.jsx("span",{className:"flex-1 truncate",children:h.label}),t===h.value?e.jsx(xs,{className:"h-3.5 w-3.5 shrink-0","aria-hidden":!0}):null]},h.value)),D.length===0?e.jsx("div",{className:"px-2 py-3 text-center text-xs text-oai-gray-400 dark:text-oai-gray-500",children:n}):null]})]})})})]})}const Fs="tokentracker-sessions";async function Is(a={}){const t=new URL(`/functions/${Fs}`,window.location.origin);a.from&&t.searchParams.set("from",a.from),a.to&&t.searchParams.set("to",a.to),a.limit&&t.searchParams.set("limit",String(a.limit)),a.refresh&&t.searchParams.set("refresh","1");const r=await fetch(t.toString(),{headers:{Accept:"application/json"},cache:"no-store"}),o=await r.json().catch(()=>null);if(!r.ok){const u=r.status===404?s("sessions.error.outdated_app"):`Request failed with HTTP ${r.status}`,p=new Error(o?.error||u);throw p.status=r.status,p}return o}function ze(a,t,{timeOnly:r=!1}={}){if(!a)return"—";const o=Date.parse(a);if(!Number.isFinite(o))return"—";const u=r?{hour:"2-digit",minute:"2-digit"}:{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"};try{return new Date(o).toLocaleString(t||void 0,u)}catch{const p=new Date(o).toISOString();return r?p.slice(11,16):p.slice(0,16).replace("T"," ")}}function Ge(a){const t=Number(a);if(!Number.isFinite(t)||t<=0)return null;const r=Math.round(t/6e4);if(r<60)return s("sessions.duration.minutes",{minutes:r});const o=Math.floor(r/60),u=r%60;return s("sessions.duration.hours",{hours:o,minutes:u})}function W(a){return E(a?.own_total_tokens??a?.total_tokens)}function Rs(a,t=0,r=1/0){if(!t&&r===1/0)return a;const o=a.map(n=>{if(!Array.isArray(n.usage_buckets))return{...n};const f=n.usage_buckets.filter(x=>{const g=Date.parse(x.timestamp);return g>=t&&g<=r}),k=new Map,j=Object.fromEntries([...ce,...fe].map(x=>[x,0]));let v=0,w=0;for(const x of f){v+=E(x.total_tokens),w+=E(x.cost_usd);const g=k.get(x.model)||{...(n.model_usage||[]).find(b=>b.model===x.model),model:x.model,...Object.fromEntries([...ce,...fe].map(b=>[b,0])),cost_usd:0,selected_models:[],reroute_reasons:[],model_attribution:"selected"};for(const b of[...ce,...fe]){const y=E(x[b]);j[b]+=y,g[b]+=y}g.cost_usd+=E(x.cost_usd);for(const b of["selected_models","reroute_reasons"])Array.isArray(x[b])&&(g[b]=[...new Set([...g[b],...x[b]])]);x.model_attribution==="effective"&&(g.model_attribution="effective"),k.set(x.model,g)}return{...n,...j,total_tokens:v,own_total_tokens:v,cost_usd:w,own_cost_usd:w,model_usage:[...k.values()]}}).filter(n=>!Array.isArray(n.usage_buckets)||W(n)>0),u=new Map;for(const n of o){if(!n.parent_session_hash)continue;const f=u.get(n.parent_session_hash)||[];f.push(n),u.set(n.parent_session_hash,f)}const p=(n,f=new Set)=>{if(f.has(n.session_hash))return{tokens:0,cost:0};const k=new Set(f).add(n.session_hash);let j=W(n),v=Z(n);for(const w of u.get(n.session_hash)||[]){const x=p(w,k);j+=x.tokens,v+=x.cost}return{tokens:j,cost:v}};for(const n of o){const f=p(n);n.combined_total_tokens=f.tokens,n.combined_cost_usd=f.cost,n.subagent_total_tokens=f.tokens-W(n),n.subagent_cost_usd=f.cost-Z(n)}return o}function Z(a){return E(a?.own_cost_usd??a?.cost_usd)}function E(a){const t=Number(a);return Number.isFinite(t)&&t>=0?t:0}const ce=["input_tokens","output_tokens","cached_input_tokens","cache_creation_input_tokens","reasoning_output_tokens","total_tokens"],fe=["long_context_","priority_","priority_long_context_"].flatMap(a=>ce.filter(t=>t!=="total_tokens").map(t=>a+t));function B(a){const t=Array.isArray(a?.model_usage)?a.model_usage.filter(r=>r&&typeof r.model=="string"&&r.model):[];return t.length?t:[{model:a?.model||"",total_tokens:W(a),cost_usd:Z(a),performance:a?.performance}]}function Os(a){const t={estimated_output_tokens:0,estimated_duration_ms:0,estimated_request_count:0,estimated_tokens_per_second:null,first_response_total_ms:0,first_response_sample_count:0,first_response_ms:null};for(const r of a){const o=r?.performance;if(!o)continue;const u=E(o.estimated_duration_ms),p=E(o.estimated_output_tokens),n=E(o.estimated_request_count);u>0&&p>0&&n>0&&(t.estimated_output_tokens+=p,t.estimated_duration_ms+=u,t.estimated_request_count+=n);const f=E(o.first_response_sample_count),k=E(o.first_response_total_ms);f>0&&k>0&&(t.first_response_total_ms+=k,t.first_response_sample_count+=f)}return t.estimated_duration_ms>0&&(t.estimated_tokens_per_second=t.estimated_output_tokens*1e3/t.estimated_duration_ms),t.first_response_sample_count>0&&(t.first_response_ms=t.first_response_total_ms/t.first_response_sample_count),t}function Ke(a){const t=new Set,r=a.filter(o=>t.has(o.session_hash)?!1:(t.add(o.session_hash),!0));return{count:r.length,tokens:r.reduce((o,u)=>o+W(u),0),cost:r.reduce((o,u)=>o+Z(u),0),costIsPartial:r.some(o=>o.cost_is_partial),performance:Os(r)}}function _e(a){const t=Date.parse(a?.ended_at||a?.started_at||"");return Number.isFinite(t)?t:0}function Es(a,t){return[...a].sort((r,o)=>(t==="cost"?Z(o)-Z(r):t==="tokens"?W(o)-W(r):0)||_e(o)-_e(r))}function de(a){const t=_e(a);if(!t)return"";const r=new Date(t);return`${r.getFullYear()}-${String(r.getMonth()+1).padStart(2,"0")}-${String(r.getDate()).padStart(2,"0")}`}function $s(a,t){const r=new Map;for(const o of a){const u=t==="project"?o.project_key||"":de(o),p=r.get(u)||{key:u,sessions:[]};p.sessions.push(o),r.set(u,p)}return[...r.values()]}function Ps(a){const t=new URLSearchParams(a),r=t.get("source"),o=n=>{const f=t.get(n)||"";if(!/^\d{4}-\d{2}-\d{2}$/.test(f))return"";const k=new Date(`${f}T00:00:00`);return Number.isFinite(k.getTime())&&de({ended_at:k.toISOString()})===f?f:""},u=o("from"),p=o("to");return{source:["claude","codex","grok","zcode"].includes(r)?r:"all",model:t.get("model")||"all",from:u,to:p}}function As(a,t,r){let o=t?new Date(`${t}T00:00:00`).getTime():0,u=r?new Date(`${r}T23:59:59.999`).getTime():1/0;o>u&&(o=new Date(`${r}T00:00:00`).getTime(),u=new Date(`${t}T23:59:59.999`).getTime());const p=Date.parse(a.ended_at||a.started_at||""),n=Date.parse(a.started_at||a.ended_at||"");return(!Number.isFinite(p)||p>=o)&&(!Number.isFinite(n)||n<=u)}function ae({performance:a,className:t=""}){const r=Number(a?.estimated_tokens_per_second),o=Number(a?.estimated_request_count||0);return!Number.isFinite(r)||r<=0||o<=0?null:e.jsx("span",{className:t,title:`${s("sessions.performance.samples",{count:o})}
2
- ${s("sessions.performance.method")}`,children:s("sessions.performance.speed",{speed:Number(r.toFixed(1))})})}const qs=[{key:"input_tokens",label:()=>s("dashboard.projects.detail.comp_input")},{key:"cached_input_tokens",label:()=>s("dashboard.projects.detail.comp_cached")},{key:"cache_creation_input_tokens",label:()=>s("dashboard.projects.detail.comp_cache_write")},{key:"output_tokens",label:()=>s("dashboard.projects.detail.comp_output")},{key:"reasoning_output_tokens",label:()=>s("dashboard.projects.detail.comp_reasoning")}],zs=[{key:"turns",label:()=>s("sessions.col.turns")},{key:"edit_turns",label:()=>s("sessions.col.edits")},{key:"retry_turns",label:()=>s("sessions.detail.retries")},{key:"subagent_calls",label:()=>s("sessions.card.subagents")},{key:"tool_calls",grokOnly:!0,label:()=>s("sessions.detail.tools")},{key:"tool_failures",grokOnly:!0,label:()=>s("sessions.detail.tool_failures")},{key:"error_count",grokOnly:!0,label:()=>s("sessions.detail.errors")},{key:"model_calls",grokOnly:!0,label:()=>s("sessions.detail.model_calls")},{key:"compaction_count",grokOnly:!0,label:()=>s("sessions.detail.compactions")}];function Gs(a){return a==="provider_reported"?s("sessions.detail.cost_reported"):a==="model_pricing"?s("sessions.detail.cost_estimated"):a==="mixed"?s("sessions.detail.cost_mixed"):s("sessions.detail.cost_unknown")}function Se(a){return String(a||"").startsWith("litellm")?s("sessions.detail.pricing_litellm"):String(a||"").startsWith("curated")?s("sessions.detail.pricing_curated"):null}function Ks(a,t){return t||Number(a)>0}function Ce({label:a,children:t}){return e.jsxs("div",{className:"flex min-w-0 items-baseline justify-between gap-4",children:[e.jsx("dt",{className:"text-sm text-oai-gray-600 dark:text-oai-gray-300",children:a}),e.jsx("dd",{className:"min-w-0 break-words text-right text-sm tabular-nums text-oai-black dark:text-white",children:t})]})}function le({label:a,title:t,className:r="",children:o}){return e.jsxs("div",{className:`min-w-0 border-oai-gray-200 px-3 py-2.5 dark:border-oai-gray-800 ${r}`,title:t,children:[e.jsx("dt",{className:"truncate text-xs text-oai-gray-500 dark:text-oai-gray-400",children:a}),e.jsx("dd",{className:"mt-0.5 truncate text-base font-medium tabular-nums text-oai-black dark:text-white",children:o})]})}function Us({session:a,subagents:t=[],onClose:r}){const o=i.useRef(null),u=i.useRef(null),{currency:p,rate:n}=je(),{resolvedLocale:f}=Oe(),k=c=>ke(c,{currency:p,rate:n}),j=B(a),v=i.useMemo(()=>Ke(t),[t]),w=W(a),x=Z(a),g=Number(a.subagent_total_tokens??v.tokens),b=Number(a.subagent_cost_usd??v.cost),y=a.performance,L=Number(y?.estimated_tokens_per_second)>0&&Number(y?.estimated_request_count)>0,S=Number(y?.first_response_sample_count)>0&&y?.first_response_ms!=null&&Number.isFinite(Number(y.first_response_ms)),P=S?{seconds:(Number(y.first_response_ms)/1e3).toFixed(2),count:y.first_response_sample_count}:null,M=Number(a.reasoning_output_tokens)>0,D=a.source==="grok",C=D&&Number(a.context_window_tokens)>0;i.useEffect(()=>{const c=document.activeElement,O=document.body.style.overflow;document.body.style.overflow="hidden",o.current?.focus();const $=F=>{if(F.key==="Escape"&&(F.preventDefault(),r()),F.key!=="Tab")return;const z=Array.from(u.current?.querySelectorAll('button:not([disabled]), a[href], input:not([disabled]), summary, [tabindex="0"]')||[]),ee=z[0],se=z[z.length-1];ee?F.shiftKey&&(document.activeElement===ee||!u.current?.contains(document.activeElement))?(F.preventDefault(),se.focus()):!F.shiftKey&&(document.activeElement===se||!u.current?.contains(document.activeElement))&&(F.preventDefault(),ee.focus()):(F.preventDefault(),u.current?.focus())};return window.addEventListener("keydown",$),()=>{window.removeEventListener("keydown",$),document.body.style.overflow=O,c instanceof HTMLElement&&c.isConnected&&c.focus()}},[r]);const R=g>0||b>0,A=a.cost_is_partial||R&&v.costIsPartial,J=[{label:s("sessions.detail.own"),tokens:w,cost:x,partial:a.cost_is_partial},{label:s("sessions.detail.subagents"),tokens:g,cost:b,partial:v.costIsPartial}],h=a.agent_nickname||a.title||a.project_key||s("sessions.project.unknown"),T=Ge(a.duration_ms),I=[a.project_key&&a.project_key!==h?a.project_key:null,ze(a.started_at,f),T].filter(Boolean);return e.jsx("div",{className:"fixed inset-0 z-50 flex justify-end bg-black/20 dark:bg-black/40",onClick:c=>{c.target===c.currentTarget&&r()},children:e.jsxs("div",{ref:u,role:"dialog","aria-modal":"true","aria-label":s("sessions.detail.title"),tabIndex:-1,className:"flex h-full w-full max-w-[36rem] flex-col border-l border-oai-gray-200 bg-white dark:border-oai-gray-800 dark:bg-oai-gray-950",children:[e.jsxs("div",{className:"flex shrink-0 items-start gap-3 border-b border-oai-gray-200 px-5 py-4 dark:border-oai-gray-800",children:[e.jsx("span",{className:"shrink-0 pt-0.5 text-oai-gray-600 dark:text-oai-gray-300",children:e.jsx(Pe,{provider:String(a.source||"").toUpperCase(),size:20})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("h2",{className:"break-words text-base font-semibold leading-6 text-oai-black dark:text-white",children:h}),e.jsx("p",{className:"mt-0.5 break-words text-xs tabular-nums text-oai-gray-500 dark:text-oai-gray-400",children:I.join(" · ")})]}),e.jsx("button",{ref:o,type:"button",onClick:r,"aria-label":s("sessions.detail.close"),className:"-mr-2 -mt-1 flex h-11 w-11 shrink-0 items-center justify-center rounded-md text-oai-gray-500 hover:bg-oai-gray-100 hover:text-oai-black focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand-500 dark:text-oai-gray-400 dark:hover:bg-oai-gray-800 dark:hover:text-white sm:h-9 sm:w-9",children:e.jsx(Ee,{size:18,"aria-hidden":!0})})]}),e.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto overscroll-contain px-5 py-5",children:[e.jsxs("section",{"aria-label":s("sessions.detail.consumption"),children:[e.jsxs("dl",{className:"grid grid-cols-2 overflow-hidden rounded-lg border border-oai-gray-200 dark:border-oai-gray-800",children:[e.jsx(le,{label:s("sessions.col.tokens"),children:N(w+g)}),e.jsxs(le,{label:s("sessions.col.cost"),className:"border-l",children:[A?"≥":"",k(x+b)]}),e.jsx(le,{label:s("sessions.summary.speed"),className:"border-t",title:L?s("sessions.performance.samples",{count:y.estimated_request_count}):s("sessions.detail.no_speed"),children:L?e.jsx(ae,{performance:y}):"—"}),e.jsx(le,{label:s("sessions.performance.first_response"),className:"border-l border-t",title:s("sessions.performance.first_response_method"),children:S?Number(y.first_response_sample_count)===1?s("sessions.performance.first_response_value_single",P):s("sessions.performance.first_response_value",P):"—"})]}),R?e.jsx("dl",{className:"mt-3 space-y-1.5",children:J.map(c=>e.jsxs("div",{className:"grid grid-cols-[minmax(0,1fr)_80px_88px] items-baseline gap-3 text-sm",children:[e.jsx("dt",{className:"text-oai-gray-600 dark:text-oai-gray-300",children:c.label}),e.jsx("dd",{className:"text-right tabular-nums",children:N(c.tokens)}),e.jsxs("dd",{className:"text-right tabular-nums",children:[c.partial?"≥":"",k(c.cost)]})]},c.label))}):null,e.jsxs("p",{className:"mt-3 text-xs leading-5 text-oai-gray-500 dark:text-oai-gray-400",children:[s("sessions.detail.cost_source")," · ",Gs(a.cost_source),a.cost_is_partial?e.jsxs("span",{className:"text-amber-700 dark:text-amber-300",children:[" · ",s("sessions.cost.partial_title")]}):null,a.usage_is_incomplete?e.jsxs("span",{className:"text-amber-700 dark:text-amber-300",children:[" · ",s("sessions.badge.partial_usage")]}):null]})]}),e.jsxs("section",{className:"mt-6",children:[e.jsx("h3",{className:"text-sm font-medium text-oai-black dark:text-white",children:s("sessions.detail.tokens")}),e.jsx("dl",{className:"mt-2 grid grid-cols-1 gap-x-8 gap-y-1.5 sm:grid-cols-2",children:qs.map(({key:c,label:O})=>e.jsx(Ce,{label:O(),children:a[c]==null?"—":N(a[c])},c))})]}),e.jsxs("section",{className:"mt-6",children:[e.jsxs("div",{className:"grid grid-cols-[minmax(0,1fr)_80px_88px] items-baseline gap-3",children:[e.jsx("h3",{className:"text-sm font-medium text-oai-black dark:text-white",children:s("sessions.detail.models")}),e.jsx("span",{className:"text-right text-xs text-oai-gray-500 dark:text-oai-gray-400","aria-hidden":!0,children:s("sessions.col.tokens")}),e.jsx("span",{className:"text-right text-xs text-oai-gray-500 dark:text-oai-gray-400","aria-hidden":!0,children:s("sessions.col.cost")})]}),e.jsx("ul",{className:"mt-1 divide-y divide-oai-gray-100 dark:divide-oai-gray-800/70",children:j.map(c=>{const O=c.pricing?.status==="unpriced",$=a.cost_source==="provider_reported"&&j.length===1,F=$?x:c.cost_usd,z=Ks(F,$);return e.jsxs("li",{className:"py-2.5",children:[e.jsxs("div",{className:"grid grid-cols-[minmax(0,1fr)_80px_88px] items-baseline gap-3 text-sm",children:[e.jsx("span",{className:"min-w-0 break-words text-oai-black dark:text-white",children:c.model||s("sessions.model.unknown")}),e.jsx("span",{className:"text-right tabular-nums",children:N(c.total_tokens)}),e.jsx("span",{className:"text-right tabular-nums",children:O&&!z?"—":k(F)})]}),c.pricing?e.jsxs("details",{className:"group text-xs text-oai-gray-500 dark:text-oai-gray-400",children:[e.jsxs("summary",{className:"flex min-h-10 cursor-pointer list-none items-center gap-2 rounded focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand-500 sm:min-h-0 sm:pt-1 [&::-webkit-details-marker]:hidden",children:[e.jsx(ae,{performance:c.performance,className:"tabular-nums"}),e.jsx("span",{className:"underline decoration-dotted underline-offset-4 group-open:no-underline",children:s("sessions.detail.pricing_details")})]}),e.jsxs("div",{className:"space-y-1 pt-1.5 leading-5",children:[O?e.jsx("p",{children:s("sessions.detail.pricing_unpriced")}):null,c.pricing.status==="free"?e.jsx("p",{children:s("sessions.detail.pricing_free")}):null,c.pricing.status==="priced"?e.jsx("p",{children:s("sessions.detail.pricing_rates",{input:c.pricing.input,output:c.pricing.output,cacheRead:c.pricing.cache_read,cacheWrite:c.pricing.cache_write})}):null,Se(c.pricing.source)?e.jsx("p",{children:Se(c.pricing.source)}):null]})]}):e.jsx(ae,{performance:c.performance,className:"block pt-1 text-xs tabular-nums text-oai-gray-500 dark:text-oai-gray-400"})]},c.model)})})]}),e.jsxs("details",{className:"mt-5 border-t border-oai-gray-200 dark:border-oai-gray-800",children:[e.jsx("summary",{className:"flex min-h-11 cursor-pointer items-center rounded text-sm font-medium text-oai-black focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand-500 dark:text-white",children:s("sessions.detail.signals")}),e.jsx("dl",{className:"grid grid-cols-1 gap-x-8 gap-y-1.5 pb-4 sm:grid-cols-2",children:zs.map(({key:c,label:O,grokOnly:$})=>e.jsx(Ce,{label:O(),children:typeof a[c]=="number"&&(!$||D)?N(a[c]):s("sessions.detail.not_recorded")},c))}),D&&a.usage_precision?e.jsx("p",{className:"pb-3 text-xs leading-5 text-oai-gray-500 dark:text-oai-gray-400",children:s("sessions.grok.runtime_breakdown",{calls:N(a.model_calls),seconds:(Number(a.api_duration_ms||0)/1e3).toFixed(1),tools:N(a.tool_calls),errors:N(a.error_count)})}):null,C?e.jsx("p",{className:"pb-3 text-xs leading-5 text-oai-gray-500 dark:text-oai-gray-400",children:s("sessions.grok.context_breakdown",{used:N(a.context_tokens_used),window:N(a.context_window_tokens),percent:Number(a.context_usage_percent||0).toFixed(0)})}):null]}),e.jsxs("details",{className:"border-t border-oai-gray-200 dark:border-oai-gray-800",children:[e.jsx("summary",{className:"flex min-h-11 cursor-pointer items-center rounded text-sm font-medium text-oai-black focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand-500 dark:text-white",children:s("sessions.detail.identifiers")}),e.jsxs("dl",{className:"space-y-3 pb-4",children:[e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-oai-gray-600 dark:text-oai-gray-300",children:s("sessions.detail.session_id")}),e.jsx("dd",{className:"mt-1 break-all font-mono text-xs leading-5",children:a.session_id||a.session_hash})]}),a.project_ref?e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-oai-gray-600 dark:text-oai-gray-300",children:s("sessions.detail.local_path")}),e.jsx("dd",{className:"mt-1 break-all font-mono text-xs leading-5",children:a.project_ref})]}):null,a.resume_command?e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-oai-gray-600 dark:text-oai-gray-300",children:s("sessions.detail.resume_command")}),e.jsx("dd",{className:"mt-1 break-all font-mono text-xs leading-5",children:a.resume_command})]}):null]})]}),e.jsxs("div",{className:"mt-2 space-y-1.5 border-t border-oai-gray-200 pt-4 text-xs leading-5 text-oai-gray-500 dark:border-oai-gray-800 dark:text-oai-gray-400",children:[L?e.jsx("p",{children:s("sessions.performance.method")}):null,M?e.jsx("p",{children:s("sessions.detail.reasoning_note")}):null,e.jsx("p",{children:s("sessions.privacy")})]})]})]})})}const Me=_s(),Te=[],be=100,Ws=[{id:"all",label:()=>s("usage.filter.source_all")},{id:"claude",label:()=>"Claude Code"},{id:"codex",label:()=>"Codex"},{id:"grok",label:()=>"Grok"},{id:"zcode",label:()=>"ZCode"}],Ue=[{id:"all",days:0,label:()=>s("sessions.filter.range_label_all")},{id:"7d",days:7,label:()=>s("sessions.filter.range_7d")},{id:"30d",days:30,label:()=>s("sessions.filter.range_30d")},{id:"90d",days:90,label:()=>s("sessions.filter.range_90d")}];function De(a){const t=Ue.find(o=>o.id===a)?.days||0;if(!t)return 0;const r=new Date;return r.setDate(r.getDate()-(t-1)),r.setHours(0,0,0,0),r.getTime()}function Hs(a,t){if(!t)return!0;const r=Date.parse(a.ended_at||a.started_at||"");return Number.isFinite(r)?r>=t:!0}function Vs(a){const t=Date.parse(a.started_at||"");return!Number.isFinite(t)||de({started_at:a.started_at})===de(a)}function Le(a){const t=B(a);return t.length===1?t[0].model||s("sessions.model.unknown"):t.map(r=>`${r.model} ${N(Number(r.total_tokens||0))}`).join(" · ")}async function Fe(a){if(navigator?.clipboard?.writeText)return await navigator.clipboard.writeText(a),!0;const t=document.createElement("textarea");t.value=a,t.style.position="fixed",t.style.opacity="0",document.body.appendChild(t),t.select();const r=document.execCommand("copy");return document.body.removeChild(t),r}function Bs(){const[a,t]=i.useState(!1),r=i.useId();return e.jsxs(ws,{open:a,onOpenChange:t,children:[e.jsx(Ns,{delay:150,closeDelay:100,closeOnClick:!1,onClick:()=>t(!0),"aria-label":s("sessions.summary.scope_help"),"aria-describedby":a?r:void 0,className:"sessions-summary-help relative inline-flex h-4 w-4 shrink-0 items-center justify-center rounded text-oai-gray-500 hover:text-oai-black dark:text-oai-gray-400 dark:hover:text-white before:absolute before:-inset-2 before:content-['']",children:e.jsx(vs,{className:"h-3.5 w-3.5","aria-hidden":!0})}),e.jsx(Ss,{children:e.jsx(Cs,{side:"bottom",align:"end",sideOffset:12,className:"z-[60]",children:e.jsx(Ms,{id:r,role:"tooltip",className:"max-w-xs rounded-lg border border-oai-gray-200 bg-white p-4 text-sm leading-6 text-oai-gray-700 outline-none dark:border-oai-gray-700 dark:bg-oai-gray-900 dark:text-oai-gray-200",children:s("sessions.summary.scope")})})})]})}const Ie=ye.memo(function({session:t,locale:r,nested:o=!1,timeOnly:u=!1,childCount:p=0,expanded:n=!1,onToggle:f,onDetail:k}){const{currency:j,rate:v}=je(),w=String(t.source||"").toUpperCase(),x=Ge(t.duration_ms),g=t.resume_command,b=t.project_key||s("sessions.project.unknown"),y=o||t.thread_kind==="subagent",L=y?t.agent_nickname||t.agent_role||t.title||b:t.title||b,S=t.usage_is_incomplete?s("sessions.badge.partial_usage"):t.cost_is_partial?s("sessions.badge.partial_cost"):null,P=t.project_ref?`${t.project_ref}
3
- ${s("sessions.project.copy_hint")}`:void 0,M=async()=>{if(t.project_ref)try{await Fe(t.project_ref)?Y({title:s("sessions.project.copied")}):Y({title:s("sessions.project.copy_failed")})}catch{Y({title:s("sessions.project.copy_failed")})}},D=R=>e.jsxs("span",{className:"group relative inline-flex min-w-0 max-w-full",children:[e.jsx(ys,{text:P,placement:"bottom"}),e.jsx("button",{type:"button",onClick:M,"aria-label":s("sessions.project.copy_aria",{project:b}),className:Q("max-w-full truncate rounded text-left underline decoration-dotted decoration-oai-gray-300 underline-offset-4 hover:decoration-oai-gray-500 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand-500 dark:decoration-oai-gray-600 dark:hover:decoration-oai-gray-400",R),children:b})]}),C=async()=>{if(g)try{await Fe(g)?Y({title:s("sessions.resume.copied")}):Y({title:s("sessions.resume.copy_failed")})}catch{Y({title:s("sessions.resume.copy_failed")})}};return e.jsxs("li",{className:Q("sessions-row sessions-row-grid py-3",o&&"sessions-row-nested"),children:[e.jsxs("div",{className:"sessions-row-identity min-w-0",children:[e.jsx("span",{className:"sessions-row-provider inline-flex items-center justify-center text-oai-gray-600 dark:text-oai-gray-300","aria-hidden":"true",children:e.jsx(Pe,{provider:w,size:o?16:18})}),e.jsxs("div",{className:"contents",children:[e.jsx("button",{type:"button",onClick:()=>k(t),"aria-label":s("sessions.detail.open_aria",{title:L}),title:L,className:"sessions-row-title block min-h-9 min-w-0 max-w-full truncate rounded text-left text-sm font-medium text-oai-black underline-offset-4 hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand-500 dark:text-white md:min-h-5",children:L}),e.jsxs("div",{className:"sessions-row-meta flex min-w-0 flex-wrap items-center gap-y-1 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:[e.jsx("span",{className:"sessions-meta-item min-w-0 max-w-full",children:t.project_ref?D("min-h-6 inline-flex items-center md:min-h-0"):e.jsx("span",{className:"truncate",children:b})}),e.jsx("span",{className:"sessions-meta-item min-w-0 max-w-full truncate",title:Le(t),children:Le(t)}),e.jsx("span",{className:"sessions-meta-item tabular-nums",children:ze(t.started_at,r,{timeOnly:u&&Vs(t)})}),x?e.jsx("span",{className:"sessions-meta-item tabular-nums",children:x}):null,Number.isFinite(t.session_store_bytes)?e.jsx("span",{className:"sessions-meta-item tabular-nums",title:s("sessions.storage.tooltip",{metric:s(t.session_store_metric==="allocated"?"sessions.storage.allocated":"sessions.storage.logical"),ratio:Math.round(t.bytes_per_1k_tokens||0).toLocaleString(r)}),children:s("sessions.storage.label",{size:s("sessions.storage.size",{value:(t.session_store_bytes/1024/1024).toLocaleString(r,{maximumFractionDigits:2})})})}):null,y?e.jsxs("span",{className:"sessions-meta-item",children:[s("sessions.badge.subagent"),t.agent_role?` · ${t.agent_role}`:""]}):null,t.first_pass?e.jsx("span",{className:"sessions-meta-item text-emerald-700 dark:text-emerald-300",children:s("sessions.badge.first_pass")}):null,S?e.jsx("span",{className:"sessions-meta-item text-amber-700 dark:text-amber-300",children:S}):null,t.cost_source==="provider_reported"?e.jsx("span",{className:"sessions-meta-item",children:s("sessions.badge.reported_cost")}):null,p?e.jsxs("button",{type:"button",onClick:()=>f(t.session_hash),"aria-expanded":n,className:"-mx-1.5 inline-flex min-h-8 items-center md:-my-1 md:ml-2 md:mr-0 gap-0.5 rounded px-1.5 font-medium text-oai-gray-700 hover:bg-oai-gray-100 hover:text-oai-black focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand-500 dark:text-oai-gray-200 dark:hover:bg-oai-gray-800 dark:hover:text-white md:min-h-6",children:[e.jsx(cs,{className:Q("h-3.5 w-3.5 transition-transform",n&&"rotate-90"),"aria-hidden":!0}),n?s("sessions.thread.collapse",{count:p}):s("sessions.thread.expand",{count:p})]}):null]})]})]}),e.jsxs("dl",{className:"sessions-row-metrics",children:[e.jsxs("div",{className:"sessions-row-value",children:[e.jsx("dt",{className:"text-xs text-oai-gray-600 dark:text-oai-gray-300 md:sr-only",children:s("sessions.col.tokens")}),e.jsxs("dd",{title:Number(t.subagent_total_tokens)?s("sessions.thread.tokens_summary",{own:N(t.own_total_tokens),subagents:N(t.subagent_total_tokens),combined:N(t.combined_total_tokens)}):void 0,className:"mt-1 text-sm tabular-nums text-oai-black dark:text-white md:mt-0",children:[N(t.total_tokens),Number(t.subagent_total_tokens)?e.jsxs("span",{className:"mt-0.5 block text-xs text-oai-gray-500 dark:text-oai-gray-400",children:["Σ ",N(t.combined_total_tokens)]}):null]})]}),e.jsxs("div",{className:"sessions-row-value",children:[e.jsx("dt",{className:"text-xs text-oai-gray-600 dark:text-oai-gray-300 md:sr-only",children:s("sessions.col.cost")}),e.jsxs("dd",{className:"mt-1 text-sm tabular-nums text-oai-black dark:text-white md:mt-0",title:t.cost_is_partial?s("sessions.cost.partial_title"):void 0,children:[t.cost_is_partial?"≥":"",ke(t.cost_usd,{currency:j,rate:v})]})]}),e.jsxs("div",{className:"sessions-row-value",children:[e.jsx("dt",{className:"text-xs text-oai-gray-600 dark:text-oai-gray-300 md:sr-only",children:s("sessions.col.speed")}),e.jsx("dd",{className:"mt-1 min-h-5 text-sm tabular-nums text-oai-gray-600 dark:text-oai-gray-300 md:mt-0",children:e.jsx(ae,{performance:t.performance})})]})]}),e.jsx("button",{type:"button",onClick:C,disabled:!g,title:g||s("sessions.resume.unavailable"),"aria-label":g?s("sessions.resume.copy_aria",{command:g}):s("sessions.resume.unavailable"),className:"sessions-row-action inline-flex h-11 w-11 shrink-0 items-center justify-center rounded-md text-oai-gray-500 transition hover:bg-oai-gray-100 hover:text-oai-black focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand-500 disabled:cursor-not-allowed dark:text-oai-gray-400 dark:hover:bg-oai-gray-800 dark:hover:text-white md:h-8 md:w-8",children:e.jsx(ks,{className:"h-4 w-4","aria-hidden":!0})})]})});function Qs({sessions:a,selectedModel:t,onSelect:r}){const{groups:o,totalTokens:u}=i.useMemo(()=>{const n=new Map;let f=0;for(const k of a)for(const j of B(k)){const v=j.model||s("sessions.model.unknown"),w=Number(j.total_tokens||0),x=n.get(v)||{model:v,count:0,tokens:0};x.count+=1,x.tokens+=w,f+=w,n.set(v,x)}return{groups:[...n.values()].sort((k,j)=>j.tokens-k.tokens),totalTokens:f}},[a]);function p(n){return Q("min-h-10 rounded-md border px-2.5 text-xs tabular-nums transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand-500 md:min-h-7",n?"border-oai-brand-500 bg-oai-brand-50 text-oai-brand-700 dark:bg-oai-brand-500/10 dark:text-oai-brand-300":"border-oai-gray-200 text-oai-gray-600 hover:bg-oai-gray-100 dark:border-oai-gray-700 dark:text-oai-gray-300 dark:hover:bg-oai-gray-800")}return e.jsx("li",{className:"sessions-thread-models py-2.5",children:e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[e.jsx("span",{className:"mr-1 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:s("sessions.thread.model_usage")}),e.jsx("button",{type:"button","aria-pressed":t==="all",onClick:()=>r("all"),className:p(t==="all"),children:s("sessions.thread.model_all",{count:a.length,tokens:N(u)})}),o.map(n=>e.jsx("button",{type:"button","aria-pressed":t===n.model,onClick:()=>r(n.model),className:p(t===n.model),children:s("sessions.thread.model_item",{model:n.model,count:n.count,tokens:N(n.tokens)})},n.model))]})})}function ft(){const[a]=i.useState(()=>Ps(window.location.search)),[t,r]=i.useState(null),[o,u]=i.useState(null),[p,n]=i.useState(!0),[f,k]=i.useState(!1),[j,v]=i.useState(a.source),[w,x]=i.useState(a.model),[g,b]=i.useState(a.from||a.to?"custom":"all"),[y,L]=i.useState(a.from),[S,P]=i.useState(a.to),[M,D]=i.useState("all"),[C,R]=i.useState("time"),[A,J]=i.useState("recent"),[h,T]=i.useState(null),[I,c]=i.useState(""),[O,$]=i.useState(be),[F,z]=i.useState(()=>new Set),[ee,se]=i.useState(()=>new Map),re=i.useRef(0),{resolvedLocale:H}=Oe(),{currency:We,rate:He}=je(),oe=i.useCallback(async(l=!1)=>{const m=++re.current;l?k(!0):n(!0),u(null);try{const d=await Is({refresh:l});m===re.current&&r(d)}catch(d){m===re.current&&u(d?.message||String(d))}finally{m===re.current&&(n(!1),k(!1))}},[]);i.useEffect(()=>{Me||we()?oe(!1):n(!1)},[oe]);const G=t?.sessions||Te,Ve=i.useMemo(()=>{const l=new Set,m=[];for(const d of G){const _=d.project_key;!_||l.has(_)||(l.add(_),m.push({value:_,label:_}))}return m.sort((d,_)=>d.label.localeCompare(_.label))},[G]),Be=i.useMemo(()=>{const l=new Set;for(const m of G)for(const d of B(m))d.model&&l.add(d.model);return[...l].sort().map(m=>({value:m,label:m}))},[G]),ue=i.useDeferredValue(I),ne=i.useMemo(()=>{let m=De(g),d=1/0;return g==="custom"&&(m=y?new Date(`${y}T00:00:00`).getTime():0,d=S?new Date(`${S}T23:59:59.999`).getTime():1/0,m>d&&(m=new Date(`${S}T00:00:00`).getTime(),d=new Date(`${y}T23:59:59.999`).getTime())),Rs(G,m,d)},[G,g,y,S]),K=i.useMemo(()=>{const l=ue.trim().toLowerCase(),m=De(g);return ne.filter(d=>{if(j!=="all"&&d.source!==j||M!=="all"&&d.project_key!==M||w!=="all"&&!B(d).some(U=>U.model===w))return!1;if(g==="custom"){if(!As(d,y,S))return!1}else if(!Hs(d,m))return!1;if(!l)return!0;const _=B(d).map(U=>U.model).join(" ");return`${d.title||""} ${d.project_key||""} ${_} ${d.agent_nickname||""} ${d.agent_role||""} ${d.project_ref||""} ${d.session_id||""}`.toLowerCase().includes(l)})},[ne,j,M,w,g,y,S,ue]),X=i.useMemo(()=>Ke(K),[K]),V=i.useMemo(()=>{const l=new Set(K.map(_=>_.session_hash)),m=new Map,d=[];for(const _ of Es(K,A)){const q=_.root_session_hash||_.parent_session_hash;if(_.parent_session_hash&&q&&l.has(q)){const U=m.get(q)||[];U.push(_),m.set(q,U)}else d.push(_)}return{roots:d,childrenByRoot:m,foldedCount:K.length-d.length}},[K,A]),me=j!=="all"||w!=="all"||g!=="all"||M!=="all"||I.trim()!=="";i.useEffect(()=>{$(be),z(new Set),se(new Map)},[j,M,w,g,y,S,ue,A,C,G]);const xe=i.useMemo(()=>V.roots.slice(0,O),[V.roots,O]),Qe=i.useMemo(()=>$s(xe,C),[xe,C]),Ze=i.useMemo(()=>h?ne.filter(l=>l.session_hash!==h.session_hash&&(l.root_session_hash===h.session_hash||l.parent_session_hash===h.session_hash)):Te,[ne,h]),Xe=i.useCallback(()=>T(null),[]),ge=i.useCallback(l=>{b(l),l!=="custom"&&(L(""),P(""))},[]),Ye=i.useCallback(()=>{v("all"),x("all"),D("all"),c(""),ge("all")},[ge]),he=V.roots.length>xe.length,pe=i.useCallback(()=>$(l=>l+be),[]),Je=i.useCallback(l=>{z(m=>{const d=new Set(m);return d.has(l)?d.delete(l):d.add(l),d})},[]),es=i.useCallback((l,m)=>{se(d=>{const _=new Map(d);return m==="all"?_.delete(l):_.set(l,m),_})},[]),ve=i.useRef(null);i.useEffect(()=>{if(!he||typeof IntersectionObserver>"u")return;const l=ve.current;if(!l)return;const m=new IntersectionObserver(d=>{d.some(_=>_.isIntersecting)&&pe()},{rootMargin:"400px"});return m.observe(l),()=>m.disconnect()},[he,pe]);const ss=i.useMemo(()=>Ws.map(l=>({value:l.id,label:l.label()})),[H]),ts=i.useMemo(()=>[...Ue.map(l=>({value:l.id,label:l.label()})),{value:"custom",label:s("sessions.filter.range_custom")}],[H]),as=i.useMemo(()=>[{value:"time",label:s("sessions.group.time")},{value:"project",label:s("sessions.group.project")}],[H]),rs=i.useMemo(()=>[{value:"recent",label:s("sessions.sort.recent")},{value:"cost",label:s("sessions.sort.cost")},{value:"tokens",label:s("sessions.sort.tokens")}],[H]),os=Number(t?.session_count)>Number(t?.returned_count);return!Me&&!we()?e.jsx("div",{className:"flex flex-col flex-1 text-oai-black dark:text-oai-white font-oai antialiased",children:e.jsx(ds,{})}):e.jsxs("div",{className:"flex flex-col flex-1 text-oai-black dark:text-oai-white font-oai antialiased",children:[e.jsx("main",{className:"flex-1 pt-8 sm:pt-10 pb-12 sm:pb-16",children:e.jsxs("div",{className:"mx-auto max-w-6xl px-4 sm:px-6",children:[e.jsxs("div",{className:"mb-8 flex flex-row items-start justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("h1",{className:"mb-3 text-3xl font-semibold tracking-tight text-oai-black dark:text-white sm:text-4xl",children:s("nav.sessions")}),e.jsx("p",{className:"text-sm text-oai-gray-500 dark:text-oai-gray-400 sm:text-base",children:s("sessions.page.summary")})]}),e.jsx("button",{type:"button",onClick:()=>{oe(!0)},disabled:f||p,"aria-label":s("sessions.page.refresh"),title:s("sessions.page.refresh"),className:"inline-flex h-9 w-9 shrink-0 items-center justify-center rounded-lg border border-oai-gray-200 text-oai-gray-600 transition-colors hover:bg-oai-gray-100 hover:text-oai-black focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand-500 disabled:opacity-50 dark:border-oai-gray-800 dark:text-oai-gray-400 dark:hover:bg-oai-gray-800 dark:hover:text-white",children:e.jsx(ls,{className:Q("h-4 w-4",f&&"animate-spin"),"aria-hidden":!0})})]}),e.jsxs("div",{className:"mb-6 space-y-3",children:[e.jsxs("div",{className:"sessions-toolbar",children:[e.jsxs("div",{className:"sessions-toolbar-search relative",children:[e.jsx($e,{className:"pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-oai-gray-500 dark:text-oai-gray-400","aria-hidden":!0}),e.jsx(us,{type:"search",value:I,onChange:l=>c(l.target.value),onKeyDown:l=>{l.key==="Escape"&&I&&(l.preventDefault(),c(""))},"aria-label":s("sessions.action.search_aria"),placeholder:s("sessions.search.placeholder"),className:"h-11 pl-10 pr-12 text-sm !bg-white dark:!bg-oai-gray-900 !border-oai-gray-200 placeholder:!text-oai-gray-500 dark:!border-oai-gray-800 dark:placeholder:!text-oai-gray-400 sm:h-9 [&::-webkit-search-cancel-button]:appearance-none"}),I?e.jsx("button",{type:"button",onMouseDown:l=>l.preventDefault(),onClick:()=>c(""),"aria-label":s("sessions.action.search_clear"),className:"absolute right-0 top-0 flex h-11 w-11 items-center justify-center rounded-md text-oai-gray-600 hover:bg-oai-gray-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand-500 dark:text-oai-gray-300 dark:hover:bg-oai-gray-800 sm:h-9 sm:w-9",children:e.jsx(Ee,{className:"h-4 w-4","aria-hidden":!0})}):null]}),e.jsx(ie,{ariaLabel:s("sessions.filter.source_aria"),options:ss,value:j,onValueChange:v,className:"sessions-filter-trigger h-11 min-w-0 px-3 text-sm sm:h-9",matchTriggerWidth:!0}),e.jsx(ie,{ariaLabel:s("sessions.filter.range_aria"),options:ts,value:g,onValueChange:ge,leadingIcon:e.jsx(Ts,{className:"h-3.5 w-3.5 shrink-0 text-oai-gray-500 dark:text-oai-gray-400","aria-hidden":!0}),className:"sessions-filter-trigger h-11 min-w-0 px-3 text-sm sm:h-9",matchTriggerWidth:!0}),e.jsx(Ne,{options:Ve,value:M,onChange:D,allLabel:s("sessions.filter.project_all"),searchPlaceholder:s("sessions.filter.project_search"),emptyLabel:s("sessions.filter.project_empty"),ariaLabel:s("sessions.filter.project_aria"),className:"sessions-filter-trigger !h-11 !w-full !max-w-none !px-3 !text-sm !font-normal sm:!h-9 !bg-white !text-oai-black dark:!bg-oai-gray-900 dark:!text-white [&>svg]:!text-oai-gray-500 dark:[&>svg]:!text-oai-gray-400"}),e.jsx(Ne,{options:Be,value:w,onChange:x,allLabel:s("sessions.filter.model_all"),searchPlaceholder:s("sessions.filter.model_search"),emptyLabel:s("sessions.filter.model_empty"),ariaLabel:s("sessions.filter.model_aria"),className:"sessions-filter-trigger sessions-model-filter !h-11 !w-full !max-w-none !px-3 !text-sm !font-normal sm:!h-9 !bg-white !text-oai-black dark:!bg-oai-gray-900 dark:!text-white [&>svg]:!text-oai-gray-500 dark:[&>svg]:!text-oai-gray-400"})]}),g==="custom"?e.jsxs("div",{className:"grid max-w-lg grid-cols-2 gap-3",children:[e.jsxs("label",{className:"min-w-0 text-xs text-oai-gray-600 dark:text-oai-gray-300",children:[e.jsx("span",{className:"mb-1 block",children:s("sessions.filter.from")}),e.jsx("input",{type:"date","aria-label":s("sessions.filter.from"),value:y,onChange:l=>L(l.target.value),className:"h-11 w-full min-w-0 rounded-md border border-oai-gray-200 bg-white px-3 text-sm outline-none focus:ring-2 focus:ring-oai-brand-500 dark:border-oai-gray-800 dark:bg-oai-gray-900 sm:h-10"})]}),e.jsxs("label",{className:"min-w-0 text-xs text-oai-gray-600 dark:text-oai-gray-300",children:[e.jsx("span",{className:"mb-1 block",children:s("sessions.filter.to")}),e.jsx("input",{type:"date","aria-label":s("sessions.filter.to"),value:S,onChange:l=>P(l.target.value),className:"h-11 w-full min-w-0 rounded-md border border-oai-gray-200 bg-white px-3 text-sm outline-none focus:ring-2 focus:ring-oai-brand-500 dark:border-oai-gray-800 dark:bg-oai-gray-900 sm:h-10"})]})]}):null]}),!p&&t?e.jsx("section",{className:"mb-6 flex items-start gap-3 rounded-lg border border-oai-gray-200 px-4 py-3 dark:border-oai-gray-800",children:e.jsxs("dl",{className:"sessions-kpis grid min-w-0 flex-1 grid-cols-2 gap-y-3 sm:grid-cols-4",children:[e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-oai-gray-500 dark:text-oai-gray-400",children:s("sessions.summary.count")}),e.jsx("dd",{className:"mt-1 text-lg font-medium tabular-nums",children:N(X.count)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-oai-gray-500 dark:text-oai-gray-400",children:s("sessions.col.tokens")}),e.jsx("dd",{className:"mt-1 text-lg font-medium tabular-nums",children:N(X.tokens)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-oai-gray-500 dark:text-oai-gray-400",children:s("sessions.col.cost")}),e.jsxs("dd",{className:"mt-1 text-lg font-medium tabular-nums",children:[X.costIsPartial?"≥":"",ke(X.cost,{currency:We,rate:He})]})]}),e.jsxs("div",{children:[e.jsxs("dt",{className:"flex items-center gap-1.5 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:[e.jsx("span",{children:s("sessions.summary.speed")}),e.jsx(Bs,{})]}),e.jsxs("dd",{className:"mt-1 text-lg font-medium tabular-nums",children:[e.jsx(ae,{performance:X.performance}),X.performance.estimated_tokens_per_second==null?"—":null]})]})]})}):null,e.jsxs("div",{className:"mb-2 flex flex-wrap items-center justify-between gap-x-3 gap-y-2",children:[e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-x-3 text-xs tabular-nums text-oai-gray-500 dark:text-oai-gray-400",children:[e.jsx("span",{children:V.foldedCount>0?s("sessions.thread.result_count",{roots:V.roots.length,subagents:V.foldedCount}):s("sessions.filter.result_count",{filtered:K.length,total:G.length})}),me?e.jsx("button",{type:"button",onClick:Ye,className:"inline-flex min-h-10 items-center rounded text-oai-gray-700 underline decoration-oai-gray-300 underline-offset-4 hover:text-oai-black focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand-500 dark:text-oai-gray-200 dark:decoration-oai-gray-600 dark:hover:text-white sm:min-h-0",children:s("sessions.filter.clear")}):null]}),e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx(ie,{ariaLabel:s("sessions.group.aria"),options:as,value:C,onValueChange:R,className:"sessions-filter-trigger h-11 min-w-0 max-w-40 px-2.5 text-xs sm:h-8"}),e.jsx(ie,{ariaLabel:s("sessions.sort.aria"),options:rs,value:A,onValueChange:J,className:"sessions-filter-trigger h-11 min-w-0 max-w-44 px-2.5 text-xs sm:h-8",align:"end"})]})]}),os?e.jsx("p",{className:"mb-4 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:s("sessions.truncated",{shown:t.returned_count,total:t.session_count})}):null,o&&!t?e.jsxs("div",{className:"rounded-xl border border-dashed border-red-300 py-16 text-center dark:border-red-500/40",children:[e.jsx("p",{className:"text-sm font-medium text-oai-black dark:text-white",children:s("sessions.error.title")}),e.jsx("p",{className:"mt-1 text-sm text-oai-gray-500 dark:text-oai-gray-400",children:o}),e.jsx("button",{type:"button",onClick:()=>{oe(!1)},className:"mt-4 inline-flex h-11 items-center rounded-md border border-oai-gray-200 px-3 text-xs font-medium text-oai-gray-700 transition-colors hover:bg-oai-gray-100 hover:text-oai-black focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand-500 dark:border-oai-gray-800 dark:text-oai-gray-200 dark:hover:bg-oai-gray-800 dark:hover:text-white",children:s("sessions.error.retry")})]}):p?e.jsxs("div",{className:"flex items-center gap-2 py-16 text-sm text-oai-gray-500 dark:text-oai-gray-400",children:[e.jsx(js,{className:"h-4 w-4 animate-spin","aria-hidden":!0}),s("sessions.loading")]}):K.length===0?e.jsxs("div",{className:"rounded-xl border border-dashed border-oai-gray-200 py-16 text-center dark:border-oai-gray-800",children:[e.jsx("p",{className:"text-sm font-medium text-oai-black dark:text-white",children:me?s("sessions.empty.filtered_title"):s("sessions.empty.title")}),e.jsx("p",{className:"mt-1 text-sm text-oai-gray-500 dark:text-oai-gray-400",children:me?s("sessions.empty.filtered_body"):s("sessions.empty.body")})]}):e.jsxs(e.Fragment,{children:[o?e.jsx("p",{className:"mb-4 text-sm text-red-500 dark:text-red-400",children:s("shared.error.prefix",{error:o})}):null,e.jsxs("div",{className:"sessions-row-grid sessions-list-header border-b border-oai-gray-200 py-2 text-xs text-oai-gray-500 dark:border-oai-gray-800 dark:text-oai-gray-400","aria-hidden":!0,children:[e.jsx("span",{children:s("sessions.col.session")}),e.jsx("span",{className:"text-right",children:s("sessions.col.tokens")}),e.jsx("span",{className:"text-right",children:s("sessions.col.cost")}),e.jsx("span",{className:"text-right",children:s("sessions.col.speed")}),e.jsx("span",{className:"sr-only",children:s("sessions.col.actions")})]}),e.jsx("ul",{className:"divide-y divide-oai-gray-200 dark:divide-oai-gray-800",children:Qe.map(l=>e.jsxs(ye.Fragment,{children:[e.jsx("li",{className:"pb-2 pt-5",children:e.jsx("h2",{className:"break-words text-xs font-medium text-oai-gray-900 dark:text-oai-gray-100",children:C==="project"?l.key||s("sessions.project.unknown"):l.key?new Date(`${l.key}T12:00:00`).toLocaleDateString(H||void 0,{year:"numeric",month:"short",day:"numeric"}):s("sessions.group.unknown_date")})}),l.sessions.map(m=>{const d=V.childrenByRoot.get(m.session_hash)||[],_=F.has(m.session_hash),q=ee.get(m.session_hash)||"all",U=q==="all"?d:d.filter(function(ns){return B(ns).some(is=>is.model===q)});return e.jsxs(ye.Fragment,{children:[e.jsx(Ie,{session:m,locale:H,timeOnly:C==="time",childCount:d.length,expanded:_,onToggle:Je,onDetail:T}),_&&d.length?e.jsx(Qs,{sessions:d,selectedModel:q,onSelect:te=>es(m.session_hash,te)}):null,_?U.map(te=>e.jsx(Ie,{session:te,locale:H,nested:!0,timeOnly:C==="time",onDetail:T},te.session_hash)):null]},m.session_hash)})]},l.key))}),he?e.jsx("div",{ref:ve,className:"flex justify-center pt-6",children:e.jsx("button",{type:"button",onClick:pe,className:"inline-flex h-11 items-center rounded-md border border-oai-gray-200 px-3 text-xs font-medium text-oai-gray-600 transition-colors hover:bg-oai-gray-100 hover:text-oai-black focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand-500 dark:border-oai-gray-800 dark:text-oai-gray-300 dark:hover:bg-oai-gray-800 dark:hover:text-white",children:s("sessions.action.load_more")})}):null]}),e.jsx("p",{className:"mt-8 max-w-3xl text-xs leading-5 text-oai-gray-600 dark:text-oai-gray-300",children:s("sessions.privacy")})]})}),h?e.jsx(Us,{session:h,subagents:Ze,onClose:Xe}):null]})}export{ft as SessionsPage};
1
+ import{o as Oe,r as i,j as e,y as Q,c as s,Z as Re,X as Ee,i as N,az as ke,W as we,R as ls,V as ye,aM as cs,bj as Y}from"./__vite-browser-external-Go6WKt6Z.js";import{L as ds,I as us}from"./LocalOnlyNotice-BkzysTS7.js";import{S as ie}from"./Select-38Dh-OWv.js";import{C as ms}from"./chevron-down-CbJ2QGDU.js";import{S as $e}from"./search-CBcpAj9I.js";import{C as xs}from"./check-UztXSVYi.js";import{P as gs,a as hs,b as ps,c as fs,d as bs}from"./PopoverPopup-CAIuP_a5.js";import{P as Pe}from"./ProviderIcon-R6Bsj81X.js";import{H as ys}from"./HoverTooltip-BJ4qLyuS.js";import{u as je}from"./useCurrency-CcZktkbA.js";import{i as _s,C as ks}from"./host-mode-99_v1j5J.js";import{L as js}from"./loader-circle-B9GqzQyC.js";import{I as vs}from"./info-C8vkxwsO.js";import{a as ws,b as Ns,c as Ss,d as Cs,e as Ms}from"./TooltipPopup-BXl-vM4L.js";import"./arrow-up-right-DhDvpd-S.js";import"./download-McE9gFto.js";import"./SelectItemText-90n7jKbI.js";import"./composite-PlKvZfdM.js";import"./usePositioner-BLGIGihf.js";import"./store-BgW2uBRe.js";import"./safePolygon-DlSbLtZC.js";const Ae={name:"calendar",size:24,node:[["path",{d:"M8 2v3",key:"1ioesn"}],["path",{d:"M16 2v3",key:"otl347"}],["rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",key:"h1oib"}],["path",{d:"M3 9h18",key:"1pudct"}]]};Ae.node;const Ts=Oe(Ae);const qe={name:"folder",size:24,node:[["path",{d:"M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z",key:"1kt360"}]]};qe.node;const Ds=Oe(qe),Ls="flex w-full items-center gap-2 rounded px-2 py-1.5 text-left text-sm text-oai-black outline-none hover:bg-oai-gray-100 dark:text-white dark:hover:bg-oai-gray-800";function Ne({options:a,value:t,onChange:r,allValue:o="all",allLabel:u,searchPlaceholder:p,emptyLabel:n,ariaLabel:f,disabled:k=!1,className:j=""}){const[v,w]=i.useState(!1),[x,g]=i.useState(""),[b,y]=i.useState(-1),L=i.useRef(null),S=`${i.useId()}-listbox`,P=t===o?u:a.find(h=>h.value===t)?.label??t,M=x.trim().toLowerCase(),D=i.useMemo(()=>M?a.filter(h=>h.label.toLowerCase().includes(M)):a,[a,M]),C=i.useMemo(()=>[{value:o,label:u},...D],[o,u,D]),O=b>=0&&b<C.length?C[b]:null,A=h=>{r(h),w(!1),g(""),y(-1)};i.useEffect(()=>{v&&L.current?.querySelector('[data-active="true"]')?.scrollIntoView?.({block:"nearest"})},[v,b]);const J=h=>{if(h.key==="ArrowDown"||h.key==="ArrowUp"){h.preventDefault();const T=h.key==="ArrowDown";y(I=>{const c=C.length;return c?T?I>=c-1?0:I+1:I<=0?c-1:I-1:-1});return}if(h.key==="Enter"){const T=O||(M&&D.length?D[0]:null);if(!T)return;h.preventDefault(),A(T.value)}};return e.jsxs(gs,{open:v,onOpenChange:h=>{w(h),y(-1),h||g("")},children:[e.jsxs(hs,{disabled:k,"aria-label":f,className:Q("inline-flex h-8 max-w-[12rem] shrink-0 items-center gap-1.5 rounded-md border border-oai-gray-200 bg-oai-white px-2.5 text-xs font-medium transition hover:border-oai-gray-300 focus:outline-none focus:ring-2 focus:ring-oai-gray-400/30 disabled:opacity-60 data-[popup-open]:border-oai-gray-300 dark:border-oai-gray-800 dark:bg-oai-gray-900 dark:hover:border-oai-gray-700",t!==o?"text-oai-black dark:text-white":"text-oai-gray-700 dark:text-oai-gray-200",j),children:[e.jsx(Ds,{className:"h-3.5 w-3.5 shrink-0 text-oai-gray-400","aria-hidden":!0}),e.jsx("span",{className:"truncate",children:P}),e.jsx(ms,{className:"h-3.5 w-3.5 shrink-0 text-oai-gray-400","aria-hidden":!0})]}),e.jsx(ps,{children:e.jsx(fs,{sideOffset:4,side:"bottom",align:"start",className:"z-[60]",children:e.jsxs(bs,{className:"w-56 overflow-hidden rounded-md border border-oai-gray-200 bg-white p-1 shadow-[0_12px_32px_-12px_rgba(0,0,0,0.18)] outline-none dark:border-oai-gray-800 dark:bg-oai-gray-950 dark:shadow-[0_12px_32px_-12px_rgba(0,0,0,0.6)]",children:[e.jsxs("div",{className:"relative mb-1",children:[e.jsx($e,{className:"pointer-events-none absolute left-2.5 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-oai-gray-400","aria-hidden":!0}),e.jsx("input",{type:"text",role:"combobox","aria-expanded":!0,"aria-controls":S,"aria-activedescendant":O?`${S}-${b}`:void 0,value:x,onChange:h=>{g(h.target.value),y(-1)},onKeyDown:J,placeholder:p,className:"h-8 w-full rounded border border-oai-gray-200 bg-transparent pl-8 pr-2 text-xs text-oai-black outline-none placeholder:text-oai-gray-400 focus:border-oai-gray-400 dark:border-oai-gray-800 dark:text-white dark:focus:border-oai-gray-500"})]}),e.jsxs("div",{ref:L,id:S,role:"listbox","aria-label":f,className:"max-h-64 overflow-y-auto",children:[C.map((h,T)=>e.jsxs("button",{id:`${S}-${T}`,type:"button",role:"option","aria-selected":t===h.value,"data-active":T===b?"true":void 0,onMouseEnter:()=>y(T),onClick:()=>A(h.value),className:Q(Ls,t===h.value&&"bg-oai-gray-100 dark:bg-oai-gray-800",T===b&&"ring-1 ring-inset ring-oai-gray-300 dark:ring-oai-gray-600"),children:[e.jsx("span",{className:"flex-1 truncate",children:h.label}),t===h.value?e.jsx(xs,{className:"h-3.5 w-3.5 shrink-0","aria-hidden":!0}):null]},h.value)),D.length===0?e.jsx("div",{className:"px-2 py-3 text-center text-xs text-oai-gray-400 dark:text-oai-gray-500",children:n}):null]})]})})})]})}const Fs="tokentracker-sessions";async function Is(a={}){const t=new URL(`/functions/${Fs}`,window.location.origin);a.from&&t.searchParams.set("from",a.from),a.to&&t.searchParams.set("to",a.to),a.limit&&t.searchParams.set("limit",String(a.limit)),a.refresh&&t.searchParams.set("refresh","1");const r=await fetch(t.toString(),{headers:{Accept:"application/json"},cache:"no-store"}),o=await r.json().catch(()=>null);if(!r.ok){const u=r.status===404?s("sessions.error.outdated_app"):`Request failed with HTTP ${r.status}`,p=new Error(o?.error||u);throw p.status=r.status,p}return o}function ze(a,t,{timeOnly:r=!1}={}){if(!a)return"—";const o=Date.parse(a);if(!Number.isFinite(o))return"—";const u=r?{hour:"2-digit",minute:"2-digit"}:{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"};try{return new Date(o).toLocaleString(t||void 0,u)}catch{const p=new Date(o).toISOString();return r?p.slice(11,16):p.slice(0,16).replace("T"," ")}}function Ge(a){const t=Number(a);if(!Number.isFinite(t)||t<=0)return null;const r=Math.round(t/6e4);if(r<60)return s("sessions.duration.minutes",{minutes:r});const o=Math.floor(r/60),u=r%60;return s("sessions.duration.hours",{hours:o,minutes:u})}function W(a){return E(a?.own_total_tokens??a?.total_tokens)}function Os(a,t=0,r=1/0){if(!t&&r===1/0)return a;const o=a.map(n=>{if(!Array.isArray(n.usage_buckets))return{...n};const f=n.usage_buckets.filter(x=>{const g=Date.parse(x.timestamp);return g>=t&&g<=r}),k=new Map,j=Object.fromEntries([...ce,...fe].map(x=>[x,0]));let v=0,w=0;for(const x of f){v+=E(x.total_tokens),w+=E(x.cost_usd);const g=k.get(x.model)||{...(n.model_usage||[]).find(b=>b.model===x.model),model:x.model,...Object.fromEntries([...ce,...fe].map(b=>[b,0])),cost_usd:0,selected_models:[],reroute_reasons:[],model_attribution:"selected"};for(const b of[...ce,...fe]){const y=E(x[b]);j[b]+=y,g[b]+=y}g.cost_usd+=E(x.cost_usd);for(const b of["selected_models","reroute_reasons"])Array.isArray(x[b])&&(g[b]=[...new Set([...g[b],...x[b]])]);x.model_attribution==="effective"&&(g.model_attribution="effective"),k.set(x.model,g)}return{...n,...j,total_tokens:v,own_total_tokens:v,cost_usd:w,own_cost_usd:w,model_usage:[...k.values()]}}).filter(n=>!Array.isArray(n.usage_buckets)||W(n)>0),u=new Map;for(const n of o){if(!n.parent_session_hash)continue;const f=u.get(n.parent_session_hash)||[];f.push(n),u.set(n.parent_session_hash,f)}const p=(n,f=new Set)=>{if(f.has(n.session_hash))return{tokens:0,cost:0};const k=new Set(f).add(n.session_hash);let j=W(n),v=Z(n);for(const w of u.get(n.session_hash)||[]){const x=p(w,k);j+=x.tokens,v+=x.cost}return{tokens:j,cost:v}};for(const n of o){const f=p(n);n.combined_total_tokens=f.tokens,n.combined_cost_usd=f.cost,n.subagent_total_tokens=f.tokens-W(n),n.subagent_cost_usd=f.cost-Z(n)}return o}function Z(a){return E(a?.own_cost_usd??a?.cost_usd)}function E(a){const t=Number(a);return Number.isFinite(t)&&t>=0?t:0}const ce=["input_tokens","output_tokens","cached_input_tokens","cache_creation_input_tokens","reasoning_output_tokens","total_tokens"],fe=["long_context_","priority_","priority_long_context_"].flatMap(a=>ce.filter(t=>t!=="total_tokens").map(t=>a+t));function B(a){const t=Array.isArray(a?.model_usage)?a.model_usage.filter(r=>r&&typeof r.model=="string"&&r.model):[];return t.length?t:[{model:a?.model||"",total_tokens:W(a),cost_usd:Z(a),performance:a?.performance}]}function Rs(a){const t={estimated_output_tokens:0,estimated_duration_ms:0,estimated_request_count:0,estimated_tokens_per_second:null,first_response_total_ms:0,first_response_sample_count:0,first_response_ms:null};for(const r of a){const o=r?.performance;if(!o)continue;const u=E(o.estimated_duration_ms),p=E(o.estimated_output_tokens),n=E(o.estimated_request_count);u>0&&p>0&&n>0&&(t.estimated_output_tokens+=p,t.estimated_duration_ms+=u,t.estimated_request_count+=n);const f=E(o.first_response_sample_count),k=E(o.first_response_total_ms);f>0&&k>0&&(t.first_response_total_ms+=k,t.first_response_sample_count+=f)}return t.estimated_duration_ms>0&&(t.estimated_tokens_per_second=t.estimated_output_tokens*1e3/t.estimated_duration_ms),t.first_response_sample_count>0&&(t.first_response_ms=t.first_response_total_ms/t.first_response_sample_count),t}function Ke(a){const t=new Set,r=a.filter(o=>t.has(o.session_hash)?!1:(t.add(o.session_hash),!0));return{count:r.length,tokens:r.reduce((o,u)=>o+W(u),0),cost:r.reduce((o,u)=>o+Z(u),0),costIsPartial:r.some(o=>o.cost_is_partial),performance:Rs(r)}}function _e(a){const t=Date.parse(a?.ended_at||a?.started_at||"");return Number.isFinite(t)?t:0}function Es(a,t){return[...a].sort((r,o)=>(t==="cost"?Z(o)-Z(r):t==="tokens"?W(o)-W(r):0)||_e(o)-_e(r))}function de(a){const t=_e(a);if(!t)return"";const r=new Date(t);return`${r.getFullYear()}-${String(r.getMonth()+1).padStart(2,"0")}-${String(r.getDate()).padStart(2,"0")}`}function $s(a,t){const r=new Map;for(const o of a){const u=t==="project"?o.project_key||"":de(o),p=r.get(u)||{key:u,sessions:[]};p.sessions.push(o),r.set(u,p)}return[...r.values()]}function Ps(a){const t=new URLSearchParams(a),r=t.get("source"),o=n=>{const f=t.get(n)||"";if(!/^\d{4}-\d{2}-\d{2}$/.test(f))return"";const k=new Date(`${f}T00:00:00`);return Number.isFinite(k.getTime())&&de({ended_at:k.toISOString()})===f?f:""},u=o("from"),p=o("to");return{source:["claude","codex","grok","zcode","opencode"].includes(r)?r:"all",model:t.get("model")||"all",from:u,to:p}}function As(a,t,r){let o=t?new Date(`${t}T00:00:00`).getTime():0,u=r?new Date(`${r}T23:59:59.999`).getTime():1/0;o>u&&(o=new Date(`${r}T00:00:00`).getTime(),u=new Date(`${t}T23:59:59.999`).getTime());const p=Date.parse(a.ended_at||a.started_at||""),n=Date.parse(a.started_at||a.ended_at||"");return(!Number.isFinite(p)||p>=o)&&(!Number.isFinite(n)||n<=u)}function ae({performance:a,className:t=""}){const r=Number(a?.estimated_tokens_per_second),o=Number(a?.estimated_request_count||0);return!Number.isFinite(r)||r<=0||o<=0?null:e.jsx("span",{className:t,title:`${s("sessions.performance.samples",{count:o})}
2
+ ${s("sessions.performance.method")}`,children:s("sessions.performance.speed",{speed:Number(r.toFixed(1))})})}const qs=[{key:"input_tokens",label:()=>s("dashboard.projects.detail.comp_input")},{key:"cached_input_tokens",label:()=>s("dashboard.projects.detail.comp_cached")},{key:"cache_creation_input_tokens",label:()=>s("dashboard.projects.detail.comp_cache_write")},{key:"output_tokens",label:()=>s("dashboard.projects.detail.comp_output")},{key:"reasoning_output_tokens",label:()=>s("dashboard.projects.detail.comp_reasoning")}],zs=[{key:"turns",label:()=>s("sessions.col.turns")},{key:"edit_turns",label:()=>s("sessions.col.edits")},{key:"retry_turns",label:()=>s("sessions.detail.retries")},{key:"subagent_calls",label:()=>s("sessions.card.subagents")},{key:"tool_calls",grokOnly:!0,label:()=>s("sessions.detail.tools")},{key:"tool_failures",grokOnly:!0,label:()=>s("sessions.detail.tool_failures")},{key:"error_count",grokOnly:!0,label:()=>s("sessions.detail.errors")},{key:"model_calls",grokOnly:!0,label:()=>s("sessions.detail.model_calls")},{key:"compaction_count",grokOnly:!0,label:()=>s("sessions.detail.compactions")}];function Gs(a){return a==="provider_reported"?s("sessions.detail.cost_reported"):a==="model_pricing"?s("sessions.detail.cost_estimated"):a==="mixed"?s("sessions.detail.cost_mixed"):s("sessions.detail.cost_unknown")}function Se(a){return String(a||"").startsWith("litellm")?s("sessions.detail.pricing_litellm"):String(a||"").startsWith("curated")?s("sessions.detail.pricing_curated"):null}function Ks(a,t){return t||Number(a)>0}function Ce({label:a,children:t}){return e.jsxs("div",{className:"flex min-w-0 items-baseline justify-between gap-4",children:[e.jsx("dt",{className:"text-sm text-oai-gray-600 dark:text-oai-gray-300",children:a}),e.jsx("dd",{className:"min-w-0 break-words text-right text-sm tabular-nums text-oai-black dark:text-white",children:t})]})}function le({label:a,title:t,className:r="",children:o}){return e.jsxs("div",{className:`min-w-0 border-oai-gray-200 px-3 py-2.5 dark:border-oai-gray-800 ${r}`,title:t,children:[e.jsx("dt",{className:"truncate text-xs text-oai-gray-500 dark:text-oai-gray-400",children:a}),e.jsx("dd",{className:"mt-0.5 truncate text-base font-medium tabular-nums text-oai-black dark:text-white",children:o})]})}function Us({session:a,subagents:t=[],onClose:r}){const o=i.useRef(null),u=i.useRef(null),{currency:p,rate:n}=je(),{resolvedLocale:f}=Re(),k=c=>ke(c,{currency:p,rate:n}),j=B(a),v=i.useMemo(()=>Ke(t),[t]),w=W(a),x=Z(a),g=Number(a.subagent_total_tokens??v.tokens),b=Number(a.subagent_cost_usd??v.cost),y=a.performance,L=Number(y?.estimated_tokens_per_second)>0&&Number(y?.estimated_request_count)>0,S=Number(y?.first_response_sample_count)>0&&y?.first_response_ms!=null&&Number.isFinite(Number(y.first_response_ms)),P=S?{seconds:(Number(y.first_response_ms)/1e3).toFixed(2),count:y.first_response_sample_count}:null,M=Number(a.reasoning_output_tokens)>0,D=a.source==="grok",C=D&&Number(a.context_window_tokens)>0;i.useEffect(()=>{const c=document.activeElement,R=document.body.style.overflow;document.body.style.overflow="hidden",o.current?.focus();const $=F=>{if(F.key==="Escape"&&(F.preventDefault(),r()),F.key!=="Tab")return;const z=Array.from(u.current?.querySelectorAll('button:not([disabled]), a[href], input:not([disabled]), summary, [tabindex="0"]')||[]),ee=z[0],se=z[z.length-1];ee?F.shiftKey&&(document.activeElement===ee||!u.current?.contains(document.activeElement))?(F.preventDefault(),se.focus()):!F.shiftKey&&(document.activeElement===se||!u.current?.contains(document.activeElement))&&(F.preventDefault(),ee.focus()):(F.preventDefault(),u.current?.focus())};return window.addEventListener("keydown",$),()=>{window.removeEventListener("keydown",$),document.body.style.overflow=R,c instanceof HTMLElement&&c.isConnected&&c.focus()}},[r]);const O=g>0||b>0,A=a.cost_is_partial||O&&v.costIsPartial,J=[{label:s("sessions.detail.own"),tokens:w,cost:x,partial:a.cost_is_partial},{label:s("sessions.detail.subagents"),tokens:g,cost:b,partial:v.costIsPartial}],h=a.agent_nickname||a.title||a.project_key||s("sessions.project.unknown"),T=Ge(a.duration_ms),I=[a.project_key&&a.project_key!==h?a.project_key:null,ze(a.started_at,f),T].filter(Boolean);return e.jsx("div",{className:"fixed inset-0 z-50 flex justify-end bg-black/20 dark:bg-black/40",onClick:c=>{c.target===c.currentTarget&&r()},children:e.jsxs("div",{ref:u,role:"dialog","aria-modal":"true","aria-label":s("sessions.detail.title"),tabIndex:-1,className:"flex h-full w-full max-w-[36rem] flex-col border-l border-oai-gray-200 bg-white dark:border-oai-gray-800 dark:bg-oai-gray-950",children:[e.jsxs("div",{className:"flex shrink-0 items-start gap-3 border-b border-oai-gray-200 px-5 py-4 dark:border-oai-gray-800",children:[e.jsx("span",{className:"shrink-0 pt-0.5 text-oai-gray-600 dark:text-oai-gray-300",children:e.jsx(Pe,{provider:String(a.source||"").toUpperCase(),size:20})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("h2",{className:"break-words text-base font-semibold leading-6 text-oai-black dark:text-white",children:h}),e.jsx("p",{className:"mt-0.5 break-words text-xs tabular-nums text-oai-gray-500 dark:text-oai-gray-400",children:I.join(" · ")})]}),e.jsx("button",{ref:o,type:"button",onClick:r,"aria-label":s("sessions.detail.close"),className:"-mr-2 -mt-1 flex h-11 w-11 shrink-0 items-center justify-center rounded-md text-oai-gray-500 hover:bg-oai-gray-100 hover:text-oai-black focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand-500 dark:text-oai-gray-400 dark:hover:bg-oai-gray-800 dark:hover:text-white sm:h-9 sm:w-9",children:e.jsx(Ee,{size:18,"aria-hidden":!0})})]}),e.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto overscroll-contain px-5 py-5",children:[e.jsxs("section",{"aria-label":s("sessions.detail.consumption"),children:[e.jsxs("dl",{className:"grid grid-cols-2 overflow-hidden rounded-lg border border-oai-gray-200 dark:border-oai-gray-800",children:[e.jsx(le,{label:s("sessions.col.tokens"),children:N(w+g)}),e.jsxs(le,{label:s("sessions.col.cost"),className:"border-l",children:[A?"≥":"",k(x+b)]}),e.jsx(le,{label:s("sessions.summary.speed"),className:"border-t",title:L?s("sessions.performance.samples",{count:y.estimated_request_count}):s("sessions.detail.no_speed"),children:L?e.jsx(ae,{performance:y}):"—"}),e.jsx(le,{label:s("sessions.performance.first_response"),className:"border-l border-t",title:s("sessions.performance.first_response_method"),children:S?Number(y.first_response_sample_count)===1?s("sessions.performance.first_response_value_single",P):s("sessions.performance.first_response_value",P):"—"})]}),O?e.jsx("dl",{className:"mt-3 space-y-1.5",children:J.map(c=>e.jsxs("div",{className:"grid grid-cols-[minmax(0,1fr)_80px_88px] items-baseline gap-3 text-sm",children:[e.jsx("dt",{className:"text-oai-gray-600 dark:text-oai-gray-300",children:c.label}),e.jsx("dd",{className:"text-right tabular-nums",children:N(c.tokens)}),e.jsxs("dd",{className:"text-right tabular-nums",children:[c.partial?"≥":"",k(c.cost)]})]},c.label))}):null,e.jsxs("p",{className:"mt-3 text-xs leading-5 text-oai-gray-500 dark:text-oai-gray-400",children:[s("sessions.detail.cost_source")," · ",Gs(a.cost_source),a.cost_is_partial?e.jsxs("span",{className:"text-amber-700 dark:text-amber-300",children:[" · ",s("sessions.cost.partial_title")]}):null,a.usage_is_incomplete?e.jsxs("span",{className:"text-amber-700 dark:text-amber-300",children:[" · ",s("sessions.badge.partial_usage")]}):null]})]}),e.jsxs("section",{className:"mt-6",children:[e.jsx("h3",{className:"text-sm font-medium text-oai-black dark:text-white",children:s("sessions.detail.tokens")}),e.jsx("dl",{className:"mt-2 grid grid-cols-1 gap-x-8 gap-y-1.5 sm:grid-cols-2",children:qs.map(({key:c,label:R})=>e.jsx(Ce,{label:R(),children:a[c]==null?"—":N(a[c])},c))})]}),e.jsxs("section",{className:"mt-6",children:[e.jsxs("div",{className:"grid grid-cols-[minmax(0,1fr)_80px_88px] items-baseline gap-3",children:[e.jsx("h3",{className:"text-sm font-medium text-oai-black dark:text-white",children:s("sessions.detail.models")}),e.jsx("span",{className:"text-right text-xs text-oai-gray-500 dark:text-oai-gray-400","aria-hidden":!0,children:s("sessions.col.tokens")}),e.jsx("span",{className:"text-right text-xs text-oai-gray-500 dark:text-oai-gray-400","aria-hidden":!0,children:s("sessions.col.cost")})]}),e.jsx("ul",{className:"mt-1 divide-y divide-oai-gray-100 dark:divide-oai-gray-800/70",children:j.map(c=>{const R=c.pricing?.status==="unpriced",$=a.cost_source==="provider_reported"&&j.length===1,F=$?x:c.cost_usd,z=Ks(F,$);return e.jsxs("li",{className:"py-2.5",children:[e.jsxs("div",{className:"grid grid-cols-[minmax(0,1fr)_80px_88px] items-baseline gap-3 text-sm",children:[e.jsx("span",{className:"min-w-0 break-words text-oai-black dark:text-white",children:c.model||s("sessions.model.unknown")}),e.jsx("span",{className:"text-right tabular-nums",children:N(c.total_tokens)}),e.jsx("span",{className:"text-right tabular-nums",children:R&&!z?"—":k(F)})]}),c.pricing?e.jsxs("details",{className:"group text-xs text-oai-gray-500 dark:text-oai-gray-400",children:[e.jsxs("summary",{className:"flex min-h-10 cursor-pointer list-none items-center gap-2 rounded focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand-500 sm:min-h-0 sm:pt-1 [&::-webkit-details-marker]:hidden",children:[e.jsx(ae,{performance:c.performance,className:"tabular-nums"}),e.jsx("span",{className:"underline decoration-dotted underline-offset-4 group-open:no-underline",children:s("sessions.detail.pricing_details")})]}),e.jsxs("div",{className:"space-y-1 pt-1.5 leading-5",children:[R?e.jsx("p",{children:s("sessions.detail.pricing_unpriced")}):null,c.pricing.status==="free"?e.jsx("p",{children:s("sessions.detail.pricing_free")}):null,c.pricing.status==="priced"?e.jsx("p",{children:s("sessions.detail.pricing_rates",{input:c.pricing.input,output:c.pricing.output,cacheRead:c.pricing.cache_read,cacheWrite:c.pricing.cache_write})}):null,Se(c.pricing.source)?e.jsx("p",{children:Se(c.pricing.source)}):null]})]}):e.jsx(ae,{performance:c.performance,className:"block pt-1 text-xs tabular-nums text-oai-gray-500 dark:text-oai-gray-400"})]},c.model)})})]}),e.jsxs("details",{className:"mt-5 border-t border-oai-gray-200 dark:border-oai-gray-800",children:[e.jsx("summary",{className:"flex min-h-11 cursor-pointer items-center rounded text-sm font-medium text-oai-black focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand-500 dark:text-white",children:s("sessions.detail.signals")}),e.jsx("dl",{className:"grid grid-cols-1 gap-x-8 gap-y-1.5 pb-4 sm:grid-cols-2",children:zs.map(({key:c,label:R,grokOnly:$})=>e.jsx(Ce,{label:R(),children:typeof a[c]=="number"&&(!$||D)?N(a[c]):s("sessions.detail.not_recorded")},c))}),D&&a.usage_precision?e.jsx("p",{className:"pb-3 text-xs leading-5 text-oai-gray-500 dark:text-oai-gray-400",children:s("sessions.grok.runtime_breakdown",{calls:N(a.model_calls),seconds:(Number(a.api_duration_ms||0)/1e3).toFixed(1),tools:N(a.tool_calls),errors:N(a.error_count)})}):null,C?e.jsx("p",{className:"pb-3 text-xs leading-5 text-oai-gray-500 dark:text-oai-gray-400",children:s("sessions.grok.context_breakdown",{used:N(a.context_tokens_used),window:N(a.context_window_tokens),percent:Number(a.context_usage_percent||0).toFixed(0)})}):null]}),e.jsxs("details",{className:"border-t border-oai-gray-200 dark:border-oai-gray-800",children:[e.jsx("summary",{className:"flex min-h-11 cursor-pointer items-center rounded text-sm font-medium text-oai-black focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand-500 dark:text-white",children:s("sessions.detail.identifiers")}),e.jsxs("dl",{className:"space-y-3 pb-4",children:[e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-oai-gray-600 dark:text-oai-gray-300",children:s("sessions.detail.session_id")}),e.jsx("dd",{className:"mt-1 break-all font-mono text-xs leading-5",children:a.session_id||a.session_hash})]}),a.project_ref?e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-oai-gray-600 dark:text-oai-gray-300",children:s("sessions.detail.local_path")}),e.jsx("dd",{className:"mt-1 break-all font-mono text-xs leading-5",children:a.project_ref})]}):null,a.resume_command?e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-oai-gray-600 dark:text-oai-gray-300",children:s("sessions.detail.resume_command")}),e.jsx("dd",{className:"mt-1 break-all font-mono text-xs leading-5",children:a.resume_command})]}):null]})]}),e.jsxs("div",{className:"mt-2 space-y-1.5 border-t border-oai-gray-200 pt-4 text-xs leading-5 text-oai-gray-500 dark:border-oai-gray-800 dark:text-oai-gray-400",children:[L?e.jsx("p",{children:s("sessions.performance.method")}):null,M?e.jsx("p",{children:s("sessions.detail.reasoning_note")}):null,e.jsx("p",{children:s("sessions.privacy")})]})]})]})})}const Me=_s(),Te=[],be=100,Ws=[{id:"all",label:()=>s("usage.filter.source_all")},{id:"claude",label:()=>"Claude Code"},{id:"codex",label:()=>"Codex"},{id:"opencode",label:()=>"OpenCode"},{id:"grok",label:()=>"Grok"},{id:"zcode",label:()=>"ZCode"}],Ue=[{id:"all",days:0,label:()=>s("sessions.filter.range_label_all")},{id:"7d",days:7,label:()=>s("sessions.filter.range_7d")},{id:"30d",days:30,label:()=>s("sessions.filter.range_30d")},{id:"90d",days:90,label:()=>s("sessions.filter.range_90d")}];function De(a){const t=Ue.find(o=>o.id===a)?.days||0;if(!t)return 0;const r=new Date;return r.setDate(r.getDate()-(t-1)),r.setHours(0,0,0,0),r.getTime()}function Hs(a,t){if(!t)return!0;const r=Date.parse(a.ended_at||a.started_at||"");return Number.isFinite(r)?r>=t:!0}function Vs(a){const t=Date.parse(a.started_at||"");return!Number.isFinite(t)||de({started_at:a.started_at})===de(a)}function Le(a){const t=B(a);return t.length===1?t[0].model||s("sessions.model.unknown"):t.map(r=>`${r.model} ${N(Number(r.total_tokens||0))}`).join(" · ")}async function Fe(a){if(navigator?.clipboard?.writeText)return await navigator.clipboard.writeText(a),!0;const t=document.createElement("textarea");t.value=a,t.style.position="fixed",t.style.opacity="0",document.body.appendChild(t),t.select();const r=document.execCommand("copy");return document.body.removeChild(t),r}function Bs(){const[a,t]=i.useState(!1),r=i.useId();return e.jsxs(ws,{open:a,onOpenChange:t,children:[e.jsx(Ns,{delay:150,closeDelay:100,closeOnClick:!1,onClick:()=>t(!0),"aria-label":s("sessions.summary.scope_help"),"aria-describedby":a?r:void 0,className:"sessions-summary-help relative inline-flex h-4 w-4 shrink-0 items-center justify-center rounded text-oai-gray-500 hover:text-oai-black dark:text-oai-gray-400 dark:hover:text-white before:absolute before:-inset-2 before:content-['']",children:e.jsx(vs,{className:"h-3.5 w-3.5","aria-hidden":!0})}),e.jsx(Ss,{children:e.jsx(Cs,{side:"bottom",align:"end",sideOffset:12,className:"z-[60]",children:e.jsx(Ms,{id:r,role:"tooltip",className:"max-w-xs rounded-lg border border-oai-gray-200 bg-white p-4 text-sm leading-6 text-oai-gray-700 outline-none dark:border-oai-gray-700 dark:bg-oai-gray-900 dark:text-oai-gray-200",children:s("sessions.summary.scope")})})})]})}const Ie=ye.memo(function({session:t,locale:r,nested:o=!1,timeOnly:u=!1,childCount:p=0,expanded:n=!1,onToggle:f,onDetail:k}){const{currency:j,rate:v}=je(),w=String(t.source||"").toUpperCase(),x=Ge(t.duration_ms),g=t.resume_command,b=t.project_key||s("sessions.project.unknown"),y=o||t.thread_kind==="subagent",L=y?t.agent_nickname||t.agent_role||t.title||b:t.title||b,S=t.usage_is_incomplete?s("sessions.badge.partial_usage"):t.cost_is_partial?s("sessions.badge.partial_cost"):null,P=t.project_ref?`${t.project_ref}
3
+ ${s("sessions.project.copy_hint")}`:void 0,M=async()=>{if(t.project_ref)try{await Fe(t.project_ref)?Y({title:s("sessions.project.copied")}):Y({title:s("sessions.project.copy_failed")})}catch{Y({title:s("sessions.project.copy_failed")})}},D=O=>e.jsxs("span",{className:"group relative inline-flex min-w-0 max-w-full",children:[e.jsx(ys,{text:P,placement:"bottom"}),e.jsx("button",{type:"button",onClick:M,"aria-label":s("sessions.project.copy_aria",{project:b}),className:Q("max-w-full truncate rounded text-left underline decoration-dotted decoration-oai-gray-300 underline-offset-4 hover:decoration-oai-gray-500 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand-500 dark:decoration-oai-gray-600 dark:hover:decoration-oai-gray-400",O),children:b})]}),C=async()=>{if(g)try{await Fe(g)?Y({title:s("sessions.resume.copied")}):Y({title:s("sessions.resume.copy_failed")})}catch{Y({title:s("sessions.resume.copy_failed")})}};return e.jsxs("li",{className:Q("sessions-row sessions-row-grid py-3",o&&"sessions-row-nested"),children:[e.jsxs("div",{className:"sessions-row-identity min-w-0",children:[e.jsx("span",{className:"sessions-row-provider inline-flex items-center justify-center text-oai-gray-600 dark:text-oai-gray-300","aria-hidden":"true",children:e.jsx(Pe,{provider:w,size:o?16:18})}),e.jsxs("div",{className:"contents",children:[e.jsx("button",{type:"button",onClick:()=>k(t),"aria-label":s("sessions.detail.open_aria",{title:L}),title:L,className:"sessions-row-title block min-h-9 min-w-0 max-w-full truncate rounded text-left text-sm font-medium text-oai-black underline-offset-4 hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand-500 dark:text-white md:min-h-5",children:L}),e.jsxs("div",{className:"sessions-row-meta flex min-w-0 flex-wrap items-center gap-y-1 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:[e.jsx("span",{className:"sessions-meta-item min-w-0 max-w-full",children:t.project_ref?D("min-h-6 inline-flex items-center md:min-h-0"):e.jsx("span",{className:"truncate",children:b})}),e.jsx("span",{className:"sessions-meta-item min-w-0 max-w-full truncate",title:Le(t),children:Le(t)}),e.jsx("span",{className:"sessions-meta-item tabular-nums",children:ze(t.started_at,r,{timeOnly:u&&Vs(t)})}),x?e.jsx("span",{className:"sessions-meta-item tabular-nums",children:x}):null,Number.isFinite(t.session_store_bytes)?e.jsx("span",{className:"sessions-meta-item tabular-nums",title:s("sessions.storage.tooltip",{metric:s(t.session_store_metric==="allocated"?"sessions.storage.allocated":"sessions.storage.logical"),ratio:Math.round(t.bytes_per_1k_tokens||0).toLocaleString(r)}),children:s("sessions.storage.label",{size:s("sessions.storage.size",{value:(t.session_store_bytes/1024/1024).toLocaleString(r,{maximumFractionDigits:2})})})}):null,y?e.jsxs("span",{className:"sessions-meta-item",children:[s("sessions.badge.subagent"),t.agent_role?` · ${t.agent_role}`:""]}):null,t.first_pass?e.jsx("span",{className:"sessions-meta-item text-emerald-700 dark:text-emerald-300",children:s("sessions.badge.first_pass")}):null,S?e.jsx("span",{className:"sessions-meta-item text-amber-700 dark:text-amber-300",children:S}):null,t.cost_source==="provider_reported"?e.jsx("span",{className:"sessions-meta-item",children:s("sessions.badge.reported_cost")}):null,p?e.jsxs("button",{type:"button",onClick:()=>f(t.session_hash),"aria-expanded":n,className:"-mx-1.5 inline-flex min-h-8 items-center md:-my-1 md:ml-2 md:mr-0 gap-0.5 rounded px-1.5 font-medium text-oai-gray-700 hover:bg-oai-gray-100 hover:text-oai-black focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand-500 dark:text-oai-gray-200 dark:hover:bg-oai-gray-800 dark:hover:text-white md:min-h-6",children:[e.jsx(cs,{className:Q("h-3.5 w-3.5 transition-transform",n&&"rotate-90"),"aria-hidden":!0}),n?s("sessions.thread.collapse",{count:p}):s("sessions.thread.expand",{count:p})]}):null]})]})]}),e.jsxs("dl",{className:"sessions-row-metrics",children:[e.jsxs("div",{className:"sessions-row-value",children:[e.jsx("dt",{className:"text-xs text-oai-gray-600 dark:text-oai-gray-300 md:sr-only",children:s("sessions.col.tokens")}),e.jsxs("dd",{title:Number(t.subagent_total_tokens)?s("sessions.thread.tokens_summary",{own:N(t.own_total_tokens),subagents:N(t.subagent_total_tokens),combined:N(t.combined_total_tokens)}):void 0,className:"mt-1 text-sm tabular-nums text-oai-black dark:text-white md:mt-0",children:[N(t.total_tokens),Number(t.subagent_total_tokens)?e.jsxs("span",{className:"mt-0.5 block text-xs text-oai-gray-500 dark:text-oai-gray-400",children:["Σ ",N(t.combined_total_tokens)]}):null]})]}),e.jsxs("div",{className:"sessions-row-value",children:[e.jsx("dt",{className:"text-xs text-oai-gray-600 dark:text-oai-gray-300 md:sr-only",children:s("sessions.col.cost")}),e.jsxs("dd",{className:"mt-1 text-sm tabular-nums text-oai-black dark:text-white md:mt-0",title:t.cost_is_partial?s("sessions.cost.partial_title"):void 0,children:[t.cost_is_partial?"≥":"",ke(t.cost_usd,{currency:j,rate:v})]})]}),e.jsxs("div",{className:"sessions-row-value",children:[e.jsx("dt",{className:"text-xs text-oai-gray-600 dark:text-oai-gray-300 md:sr-only",children:s("sessions.col.speed")}),e.jsx("dd",{className:"mt-1 min-h-5 text-sm tabular-nums text-oai-gray-600 dark:text-oai-gray-300 md:mt-0",children:e.jsx(ae,{performance:t.performance})})]})]}),e.jsx("button",{type:"button",onClick:C,disabled:!g,title:g||s("sessions.resume.unavailable"),"aria-label":g?s("sessions.resume.copy_aria",{command:g}):s("sessions.resume.unavailable"),className:"sessions-row-action inline-flex h-11 w-11 shrink-0 items-center justify-center rounded-md text-oai-gray-500 transition hover:bg-oai-gray-100 hover:text-oai-black focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand-500 disabled:cursor-not-allowed dark:text-oai-gray-400 dark:hover:bg-oai-gray-800 dark:hover:text-white md:h-8 md:w-8",children:e.jsx(ks,{className:"h-4 w-4","aria-hidden":!0})})]})});function Qs({sessions:a,selectedModel:t,onSelect:r}){const{groups:o,totalTokens:u}=i.useMemo(()=>{const n=new Map;let f=0;for(const k of a)for(const j of B(k)){const v=j.model||s("sessions.model.unknown"),w=Number(j.total_tokens||0),x=n.get(v)||{model:v,count:0,tokens:0};x.count+=1,x.tokens+=w,f+=w,n.set(v,x)}return{groups:[...n.values()].sort((k,j)=>j.tokens-k.tokens),totalTokens:f}},[a]);function p(n){return Q("min-h-10 rounded-md border px-2.5 text-xs tabular-nums transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand-500 md:min-h-7",n?"border-oai-brand-500 bg-oai-brand-50 text-oai-brand-700 dark:bg-oai-brand-500/10 dark:text-oai-brand-300":"border-oai-gray-200 text-oai-gray-600 hover:bg-oai-gray-100 dark:border-oai-gray-700 dark:text-oai-gray-300 dark:hover:bg-oai-gray-800")}return e.jsx("li",{className:"sessions-thread-models py-2.5",children:e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[e.jsx("span",{className:"mr-1 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:s("sessions.thread.model_usage")}),e.jsx("button",{type:"button","aria-pressed":t==="all",onClick:()=>r("all"),className:p(t==="all"),children:s("sessions.thread.model_all",{count:a.length,tokens:N(u)})}),o.map(n=>e.jsx("button",{type:"button","aria-pressed":t===n.model,onClick:()=>r(n.model),className:p(t===n.model),children:s("sessions.thread.model_item",{model:n.model,count:n.count,tokens:N(n.tokens)})},n.model))]})})}function ft(){const[a]=i.useState(()=>Ps(window.location.search)),[t,r]=i.useState(null),[o,u]=i.useState(null),[p,n]=i.useState(!0),[f,k]=i.useState(!1),[j,v]=i.useState(a.source),[w,x]=i.useState(a.model),[g,b]=i.useState(a.from||a.to?"custom":"all"),[y,L]=i.useState(a.from),[S,P]=i.useState(a.to),[M,D]=i.useState("all"),[C,O]=i.useState("time"),[A,J]=i.useState("recent"),[h,T]=i.useState(null),[I,c]=i.useState(""),[R,$]=i.useState(be),[F,z]=i.useState(()=>new Set),[ee,se]=i.useState(()=>new Map),re=i.useRef(0),{resolvedLocale:H}=Re(),{currency:We,rate:He}=je(),oe=i.useCallback(async(l=!1)=>{const m=++re.current;l?k(!0):n(!0),u(null);try{const d=await Is({refresh:l});m===re.current&&r(d)}catch(d){m===re.current&&u(d?.message||String(d))}finally{m===re.current&&(n(!1),k(!1))}},[]);i.useEffect(()=>{Me||we()?oe(!1):n(!1)},[oe]);const G=t?.sessions||Te,Ve=i.useMemo(()=>{const l=new Set,m=[];for(const d of G){const _=d.project_key;!_||l.has(_)||(l.add(_),m.push({value:_,label:_}))}return m.sort((d,_)=>d.label.localeCompare(_.label))},[G]),Be=i.useMemo(()=>{const l=new Set;for(const m of G)for(const d of B(m))d.model&&l.add(d.model);return[...l].sort().map(m=>({value:m,label:m}))},[G]),ue=i.useDeferredValue(I),ne=i.useMemo(()=>{let m=De(g),d=1/0;return g==="custom"&&(m=y?new Date(`${y}T00:00:00`).getTime():0,d=S?new Date(`${S}T23:59:59.999`).getTime():1/0,m>d&&(m=new Date(`${S}T00:00:00`).getTime(),d=new Date(`${y}T23:59:59.999`).getTime())),Os(G,m,d)},[G,g,y,S]),K=i.useMemo(()=>{const l=ue.trim().toLowerCase(),m=De(g);return ne.filter(d=>{if(j!=="all"&&d.source!==j||M!=="all"&&d.project_key!==M||w!=="all"&&!B(d).some(U=>U.model===w))return!1;if(g==="custom"){if(!As(d,y,S))return!1}else if(!Hs(d,m))return!1;if(!l)return!0;const _=B(d).map(U=>U.model).join(" ");return`${d.title||""} ${d.project_key||""} ${_} ${d.agent_nickname||""} ${d.agent_role||""} ${d.project_ref||""} ${d.session_id||""}`.toLowerCase().includes(l)})},[ne,j,M,w,g,y,S,ue]),X=i.useMemo(()=>Ke(K),[K]),V=i.useMemo(()=>{const l=new Set(K.map(_=>_.session_hash)),m=new Map,d=[];for(const _ of Es(K,A)){const q=_.root_session_hash||_.parent_session_hash;if(_.parent_session_hash&&q&&l.has(q)){const U=m.get(q)||[];U.push(_),m.set(q,U)}else d.push(_)}return{roots:d,childrenByRoot:m,foldedCount:K.length-d.length}},[K,A]),me=j!=="all"||w!=="all"||g!=="all"||M!=="all"||I.trim()!=="";i.useEffect(()=>{$(be),z(new Set),se(new Map)},[j,M,w,g,y,S,ue,A,C,G]);const xe=i.useMemo(()=>V.roots.slice(0,R),[V.roots,R]),Qe=i.useMemo(()=>$s(xe,C),[xe,C]),Ze=i.useMemo(()=>h?ne.filter(l=>l.session_hash!==h.session_hash&&(l.root_session_hash===h.session_hash||l.parent_session_hash===h.session_hash)):Te,[ne,h]),Xe=i.useCallback(()=>T(null),[]),ge=i.useCallback(l=>{b(l),l!=="custom"&&(L(""),P(""))},[]),Ye=i.useCallback(()=>{v("all"),x("all"),D("all"),c(""),ge("all")},[ge]),he=V.roots.length>xe.length,pe=i.useCallback(()=>$(l=>l+be),[]),Je=i.useCallback(l=>{z(m=>{const d=new Set(m);return d.has(l)?d.delete(l):d.add(l),d})},[]),es=i.useCallback((l,m)=>{se(d=>{const _=new Map(d);return m==="all"?_.delete(l):_.set(l,m),_})},[]),ve=i.useRef(null);i.useEffect(()=>{if(!he||typeof IntersectionObserver>"u")return;const l=ve.current;if(!l)return;const m=new IntersectionObserver(d=>{d.some(_=>_.isIntersecting)&&pe()},{rootMargin:"400px"});return m.observe(l),()=>m.disconnect()},[he,pe]);const ss=i.useMemo(()=>Ws.map(l=>({value:l.id,label:l.label()})),[H]),ts=i.useMemo(()=>[...Ue.map(l=>({value:l.id,label:l.label()})),{value:"custom",label:s("sessions.filter.range_custom")}],[H]),as=i.useMemo(()=>[{value:"time",label:s("sessions.group.time")},{value:"project",label:s("sessions.group.project")}],[H]),rs=i.useMemo(()=>[{value:"recent",label:s("sessions.sort.recent")},{value:"cost",label:s("sessions.sort.cost")},{value:"tokens",label:s("sessions.sort.tokens")}],[H]),os=Number(t?.session_count)>Number(t?.returned_count);return!Me&&!we()?e.jsx("div",{className:"flex flex-col flex-1 text-oai-black dark:text-oai-white font-oai antialiased",children:e.jsx(ds,{})}):e.jsxs("div",{className:"flex flex-col flex-1 text-oai-black dark:text-oai-white font-oai antialiased",children:[e.jsx("main",{className:"flex-1 pt-8 sm:pt-10 pb-12 sm:pb-16",children:e.jsxs("div",{className:"mx-auto max-w-6xl px-4 sm:px-6",children:[e.jsxs("div",{className:"mb-8 flex flex-row items-start justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("h1",{className:"mb-3 text-3xl font-semibold tracking-tight text-oai-black dark:text-white sm:text-4xl",children:s("nav.sessions")}),e.jsx("p",{className:"text-sm text-oai-gray-500 dark:text-oai-gray-400 sm:text-base",children:s("sessions.page.summary")})]}),e.jsx("button",{type:"button",onClick:()=>{oe(!0)},disabled:f||p,"aria-label":s("sessions.page.refresh"),title:s("sessions.page.refresh"),className:"inline-flex h-9 w-9 shrink-0 items-center justify-center rounded-lg border border-oai-gray-200 text-oai-gray-600 transition-colors hover:bg-oai-gray-100 hover:text-oai-black focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand-500 disabled:opacity-50 dark:border-oai-gray-800 dark:text-oai-gray-400 dark:hover:bg-oai-gray-800 dark:hover:text-white",children:e.jsx(ls,{className:Q("h-4 w-4",f&&"animate-spin"),"aria-hidden":!0})})]}),e.jsxs("div",{className:"mb-6 space-y-3",children:[e.jsxs("div",{className:"sessions-toolbar",children:[e.jsxs("div",{className:"sessions-toolbar-search relative",children:[e.jsx($e,{className:"pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-oai-gray-500 dark:text-oai-gray-400","aria-hidden":!0}),e.jsx(us,{type:"search",value:I,onChange:l=>c(l.target.value),onKeyDown:l=>{l.key==="Escape"&&I&&(l.preventDefault(),c(""))},"aria-label":s("sessions.action.search_aria"),placeholder:s("sessions.search.placeholder"),className:"h-11 pl-10 pr-12 text-sm !bg-white dark:!bg-oai-gray-900 !border-oai-gray-200 placeholder:!text-oai-gray-500 dark:!border-oai-gray-800 dark:placeholder:!text-oai-gray-400 sm:h-9 [&::-webkit-search-cancel-button]:appearance-none"}),I?e.jsx("button",{type:"button",onMouseDown:l=>l.preventDefault(),onClick:()=>c(""),"aria-label":s("sessions.action.search_clear"),className:"absolute right-0 top-0 flex h-11 w-11 items-center justify-center rounded-md text-oai-gray-600 hover:bg-oai-gray-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand-500 dark:text-oai-gray-300 dark:hover:bg-oai-gray-800 sm:h-9 sm:w-9",children:e.jsx(Ee,{className:"h-4 w-4","aria-hidden":!0})}):null]}),e.jsx(ie,{ariaLabel:s("sessions.filter.source_aria"),options:ss,value:j,onValueChange:v,className:"sessions-filter-trigger h-11 min-w-0 px-3 text-sm sm:h-9",matchTriggerWidth:!0}),e.jsx(ie,{ariaLabel:s("sessions.filter.range_aria"),options:ts,value:g,onValueChange:ge,leadingIcon:e.jsx(Ts,{className:"h-3.5 w-3.5 shrink-0 text-oai-gray-500 dark:text-oai-gray-400","aria-hidden":!0}),className:"sessions-filter-trigger h-11 min-w-0 px-3 text-sm sm:h-9",matchTriggerWidth:!0}),e.jsx(Ne,{options:Ve,value:M,onChange:D,allLabel:s("sessions.filter.project_all"),searchPlaceholder:s("sessions.filter.project_search"),emptyLabel:s("sessions.filter.project_empty"),ariaLabel:s("sessions.filter.project_aria"),className:"sessions-filter-trigger !h-11 !w-full !max-w-none !px-3 !text-sm !font-normal sm:!h-9 !bg-white !text-oai-black dark:!bg-oai-gray-900 dark:!text-white [&>svg]:!text-oai-gray-500 dark:[&>svg]:!text-oai-gray-400"}),e.jsx(Ne,{options:Be,value:w,onChange:x,allLabel:s("sessions.filter.model_all"),searchPlaceholder:s("sessions.filter.model_search"),emptyLabel:s("sessions.filter.model_empty"),ariaLabel:s("sessions.filter.model_aria"),className:"sessions-filter-trigger sessions-model-filter !h-11 !w-full !max-w-none !px-3 !text-sm !font-normal sm:!h-9 !bg-white !text-oai-black dark:!bg-oai-gray-900 dark:!text-white [&>svg]:!text-oai-gray-500 dark:[&>svg]:!text-oai-gray-400"})]}),g==="custom"?e.jsxs("div",{className:"grid max-w-lg grid-cols-2 gap-3",children:[e.jsxs("label",{className:"min-w-0 text-xs text-oai-gray-600 dark:text-oai-gray-300",children:[e.jsx("span",{className:"mb-1 block",children:s("sessions.filter.from")}),e.jsx("input",{type:"date","aria-label":s("sessions.filter.from"),value:y,onChange:l=>L(l.target.value),className:"h-11 w-full min-w-0 rounded-md border border-oai-gray-200 bg-white px-3 text-sm outline-none focus:ring-2 focus:ring-oai-brand-500 dark:border-oai-gray-800 dark:bg-oai-gray-900 sm:h-10"})]}),e.jsxs("label",{className:"min-w-0 text-xs text-oai-gray-600 dark:text-oai-gray-300",children:[e.jsx("span",{className:"mb-1 block",children:s("sessions.filter.to")}),e.jsx("input",{type:"date","aria-label":s("sessions.filter.to"),value:S,onChange:l=>P(l.target.value),className:"h-11 w-full min-w-0 rounded-md border border-oai-gray-200 bg-white px-3 text-sm outline-none focus:ring-2 focus:ring-oai-brand-500 dark:border-oai-gray-800 dark:bg-oai-gray-900 sm:h-10"})]})]}):null]}),!p&&t?e.jsx("section",{className:"mb-6 flex items-start gap-3 rounded-lg border border-oai-gray-200 px-4 py-3 dark:border-oai-gray-800",children:e.jsxs("dl",{className:"sessions-kpis grid min-w-0 flex-1 grid-cols-2 gap-y-3 sm:grid-cols-4",children:[e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-oai-gray-500 dark:text-oai-gray-400",children:s("sessions.summary.count")}),e.jsx("dd",{className:"mt-1 text-lg font-medium tabular-nums",children:N(X.count)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-oai-gray-500 dark:text-oai-gray-400",children:s("sessions.col.tokens")}),e.jsx("dd",{className:"mt-1 text-lg font-medium tabular-nums",children:N(X.tokens)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-oai-gray-500 dark:text-oai-gray-400",children:s("sessions.col.cost")}),e.jsxs("dd",{className:"mt-1 text-lg font-medium tabular-nums",children:[X.costIsPartial?"≥":"",ke(X.cost,{currency:We,rate:He})]})]}),e.jsxs("div",{children:[e.jsxs("dt",{className:"flex items-center gap-1.5 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:[e.jsx("span",{children:s("sessions.summary.speed")}),e.jsx(Bs,{})]}),e.jsxs("dd",{className:"mt-1 text-lg font-medium tabular-nums",children:[e.jsx(ae,{performance:X.performance}),X.performance.estimated_tokens_per_second==null?"—":null]})]})]})}):null,e.jsxs("div",{className:"mb-2 flex flex-wrap items-center justify-between gap-x-3 gap-y-2",children:[e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-x-3 text-xs tabular-nums text-oai-gray-500 dark:text-oai-gray-400",children:[e.jsx("span",{children:V.foldedCount>0?s("sessions.thread.result_count",{roots:V.roots.length,subagents:V.foldedCount}):s("sessions.filter.result_count",{filtered:K.length,total:G.length})}),me?e.jsx("button",{type:"button",onClick:Ye,className:"inline-flex min-h-10 items-center rounded text-oai-gray-700 underline decoration-oai-gray-300 underline-offset-4 hover:text-oai-black focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand-500 dark:text-oai-gray-200 dark:decoration-oai-gray-600 dark:hover:text-white sm:min-h-0",children:s("sessions.filter.clear")}):null]}),e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx(ie,{ariaLabel:s("sessions.group.aria"),options:as,value:C,onValueChange:O,className:"sessions-filter-trigger h-11 min-w-0 max-w-40 px-2.5 text-xs sm:h-8"}),e.jsx(ie,{ariaLabel:s("sessions.sort.aria"),options:rs,value:A,onValueChange:J,className:"sessions-filter-trigger h-11 min-w-0 max-w-44 px-2.5 text-xs sm:h-8",align:"end"})]})]}),os?e.jsx("p",{className:"mb-4 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:s("sessions.truncated",{shown:t.returned_count,total:t.session_count})}):null,o&&!t?e.jsxs("div",{className:"rounded-xl border border-dashed border-red-300 py-16 text-center dark:border-red-500/40",children:[e.jsx("p",{className:"text-sm font-medium text-oai-black dark:text-white",children:s("sessions.error.title")}),e.jsx("p",{className:"mt-1 text-sm text-oai-gray-500 dark:text-oai-gray-400",children:o}),e.jsx("button",{type:"button",onClick:()=>{oe(!1)},className:"mt-4 inline-flex h-11 items-center rounded-md border border-oai-gray-200 px-3 text-xs font-medium text-oai-gray-700 transition-colors hover:bg-oai-gray-100 hover:text-oai-black focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand-500 dark:border-oai-gray-800 dark:text-oai-gray-200 dark:hover:bg-oai-gray-800 dark:hover:text-white",children:s("sessions.error.retry")})]}):p?e.jsxs("div",{className:"flex items-center gap-2 py-16 text-sm text-oai-gray-500 dark:text-oai-gray-400",children:[e.jsx(js,{className:"h-4 w-4 animate-spin","aria-hidden":!0}),s("sessions.loading")]}):K.length===0?e.jsxs("div",{className:"rounded-xl border border-dashed border-oai-gray-200 py-16 text-center dark:border-oai-gray-800",children:[e.jsx("p",{className:"text-sm font-medium text-oai-black dark:text-white",children:me?s("sessions.empty.filtered_title"):s("sessions.empty.title")}),e.jsx("p",{className:"mt-1 text-sm text-oai-gray-500 dark:text-oai-gray-400",children:me?s("sessions.empty.filtered_body"):s("sessions.empty.body")})]}):e.jsxs(e.Fragment,{children:[o?e.jsx("p",{className:"mb-4 text-sm text-red-500 dark:text-red-400",children:s("shared.error.prefix",{error:o})}):null,e.jsxs("div",{className:"sessions-row-grid sessions-list-header border-b border-oai-gray-200 py-2 text-xs text-oai-gray-500 dark:border-oai-gray-800 dark:text-oai-gray-400","aria-hidden":!0,children:[e.jsx("span",{children:s("sessions.col.session")}),e.jsx("span",{className:"text-right",children:s("sessions.col.tokens")}),e.jsx("span",{className:"text-right",children:s("sessions.col.cost")}),e.jsx("span",{className:"text-right",children:s("sessions.col.speed")}),e.jsx("span",{className:"sr-only",children:s("sessions.col.actions")})]}),e.jsx("ul",{className:"divide-y divide-oai-gray-200 dark:divide-oai-gray-800",children:Qe.map(l=>e.jsxs(ye.Fragment,{children:[e.jsx("li",{className:"pb-2 pt-5",children:e.jsx("h2",{className:"break-words text-xs font-medium text-oai-gray-900 dark:text-oai-gray-100",children:C==="project"?l.key||s("sessions.project.unknown"):l.key?new Date(`${l.key}T12:00:00`).toLocaleDateString(H||void 0,{year:"numeric",month:"short",day:"numeric"}):s("sessions.group.unknown_date")})}),l.sessions.map(m=>{const d=V.childrenByRoot.get(m.session_hash)||[],_=F.has(m.session_hash),q=ee.get(m.session_hash)||"all",U=q==="all"?d:d.filter(function(ns){return B(ns).some(is=>is.model===q)});return e.jsxs(ye.Fragment,{children:[e.jsx(Ie,{session:m,locale:H,timeOnly:C==="time",childCount:d.length,expanded:_,onToggle:Je,onDetail:T}),_&&d.length?e.jsx(Qs,{sessions:d,selectedModel:q,onSelect:te=>es(m.session_hash,te)}):null,_?U.map(te=>e.jsx(Ie,{session:te,locale:H,nested:!0,timeOnly:C==="time",onDetail:T},te.session_hash)):null]},m.session_hash)})]},l.key))}),he?e.jsx("div",{ref:ve,className:"flex justify-center pt-6",children:e.jsx("button",{type:"button",onClick:pe,className:"inline-flex h-11 items-center rounded-md border border-oai-gray-200 px-3 text-xs font-medium text-oai-gray-600 transition-colors hover:bg-oai-gray-100 hover:text-oai-black focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand-500 dark:border-oai-gray-800 dark:text-oai-gray-300 dark:hover:bg-oai-gray-800 dark:hover:text-white",children:s("sessions.action.load_more")})}):null]}),e.jsx("p",{className:"mt-8 max-w-3xl text-xs leading-5 text-oai-gray-600 dark:text-oai-gray-300",children:s("sessions.privacy")})]})}),h?e.jsx(Us,{session:h,subagents:Ze,onClose:Xe}):null]})}export{ft as SessionsPage};
@@ -0,0 +1,5 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/__vite-browser-external-Go6WKt6Z.js","assets/__vite-browser-external-kAUz3kFs.css"])))=>i.map(i=>d[i]);
2
+ import{o as ne,by as Dt,bm as Ut,r as o,M as zt,K as Gt,bz as Mt,j as e,c as a,y as le,a as lt,cK as $t,cL as Ft,cM as Bt,cN as Ht,a7 as me,cO as Be,bi as Vt,cP as qt,bh as He,cQ as we,aP as ct,cR as Kt,cS as Wt,ag as dt,u as ut,B as A,V as Pe,aM as mt,X as Yt,x as Oe,a8 as H,cT as Zt,a9 as ee,ar as gt,cU as Ne,a5 as ce,aB as pt,ai as Ve,cV as Jt,ak as Xt,aj as Qt,ah as ea,cW as qe,cX as ta,a1 as aa,af as sa,au as fe,av as Ae,cY as na,R as De,L as ye,al as ia,am as Ue,ac as ra,d as ht,aa as Le,ab as ft,cZ as Ke,c_ as We,c$ as Ye,d0 as oa,d1 as la,ao as ca,Z as xt,l as Se,d2 as Ze,k as Je,d3 as da,d4 as ua,d5 as ma,z as ga,d6 as pa,d7 as ha,d8 as fa,d9 as xa,da as ba,db as ya,dc as va,v as bt,cn as ja,dd as ka,bj as Xe,_ as _a,e as wa,de as Na,df as Sa,bl as Ca}from"./__vite-browser-external-Go6WKt6Z.js";import{a as Ea,b as Qe,s as Pa,K as Oa,P as Aa,D as La,c as Ta,S as Ra,v as Ia,u as Da,C as Ua}from"./sortable.esm-B6qEViGJ.js";import{a as za}from"./modifiers.esm-ChkCUrZp.js";import{d as et,l as tt,u as Ga,b as at}from"./use-limits-display-prefs-Yi0Hznar.js";import{P as Ma}from"./ProviderIcon-R6Bsj81X.js";import{a as R,S as se,T as z,b as Z,c as ve}from"./Controls-CQlxw03i.js";import{m as yt}from"./react-EctmAw3f.js";import{P as $a,u as Fa,a as Ba}from"./use-session-efficiency-pref-CwaFIkE5.js";import{C as Ha}from"./check-UztXSVYi.js";import{C as Va,i as qa}from"./host-mode-99_v1j5J.js";import{A as vt}from"./index-DuaQmNZo.js";import{r as Ka,C as Ce,o as Wa}from"./cloud-checkout-CoRQjKEu.js";import{u as Ya,D as Za,a as Ja,b as Xa,c as Qa,d as es,e as ts}from"./DialogTitle-Cro2S8s8.js";import{u as as,p as ss,t as ns}from"./composite-PlKvZfdM.js";import{k as is,l as rs}from"./SelectItemText-90n7jKbI.js";import{u as os}from"./safePolygon-DlSbLtZC.js";import{D as ls}from"./DialogClose-Dx5AqmUG.js";import{G as Te}from"./gift-pKc80Nqb.js";import{C as Re}from"./chevron-down-CbJ2QGDU.js";import{D as cs}from"./DateRangePopover-DJ8RpQfV.js";import{C as ds}from"./calendar-days-BuOFlNcJ.js";import{D as Ie}from"./download-McE9gFto.js";import{P as us,a as ms,b as gs,c as ps,d as hs}from"./PopoverPopup-CAIuP_a5.js";import{C as st}from"./Card-BHHCCnqR.js";import{E as nt}from"./external-link-DZWnR9gS.js";import{a as fs,P as xs}from"./play-qC6xc6fe.js";import{I as jt}from"./info-C8vkxwsO.js";import{a as bs,b as ys,c as vs,d as js,e as ks}from"./TooltipPopup-BXl-vM4L.js";import{L as xe}from"./loader-circle-B9GqzQyC.js";import{u as _s}from"./useCurrency-CcZktkbA.js";import{u as ws}from"./useTokenFormat--dhm3nNf.js";import{S as ze}from"./Select-38Dh-OWv.js";import{u as je}from"./use-native-settings-BaSrhrM8.js";import{C as Ns}from"./ConfirmModal-ZvPOJ0he.js";import{A as Ss}from"./arrow-up-right-DhDvpd-S.js";import"./store-BgW2uBRe.js";import"./usePositioner-BLGIGihf.js";import"./DialogDescription-LvhfT1Ox.js";const kt={name:"credit-card",size:24,node:[["rect",{width:"20",height:"14",x:"2",y:"5",rx:"2",key:"ynyp8z"}],["line",{x1:"2",x2:"22",y1:"10",y2:"10",key:"1b3vmo"}],["path",{d:"M6 14h2",key:"mk7k0u"}]]};kt.node;const Cs=ne(kt);const _t={name:"flask-conical",size:24,node:[["path",{d:"M14 2v6a2 2 0 0 0 .245.96l5.51 10.08A2 2 0 0 1 18 22H6a2 2 0 0 1-1.755-2.96l5.51-10.08A2 2 0 0 0 10 8V2",key:"18mbvz"}],["path",{d:"M6.453 15h11.094",key:"3shlmq"}],["path",{d:"M8.5 2h7",key:"csnxdl"}]]};_t.node;const Es=ne(_t);const wt={name:"grip-vertical",size:24,node:[["circle",{cx:"9",cy:"12",r:"1",key:"1vctgf"}],["circle",{cx:"9",cy:"5",r:"1",key:"hp0tcf"}],["circle",{cx:"9",cy:"19",r:"1",key:"fkjjf6"}],["circle",{cx:"15",cy:"12",r:"1",key:"1tmaij"}],["circle",{cx:"15",cy:"5",r:"1",key:"19l28e"}],["circle",{cx:"15",cy:"19",r:"1",key:"f4zoj3"}]]};wt.node;const Ps=ne(wt);const Nt={name:"languages",size:24,node:[["path",{d:"m5 8 6 6",key:"1wu5hv"}],["path",{d:"m4 14 6-6 2-3",key:"1k1g8d"}],["path",{d:"M2 5h12",key:"or177f"}],["path",{d:"M7 2h1",key:"1t2jsx"}],["path",{d:"m22 22-5-10-5 10",key:"don7ne"}],["path",{d:"M14 18h6",key:"1m8k6r"}]]};Nt.node;const Os=ne(Nt);const St={name:"log-out",size:24,node:[["path",{d:"m16 17 5-5-5-5",key:"1bji2h"}],["path",{d:"M21 12H9",key:"dn1m92"}],["path",{d:"M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4",key:"1uf3rs"}]]};St.node;const As=ne(St);const Ct={name:"palette",size:24,node:[["path",{d:"M12 22a1 1 0 0 1 0-20 10 9 0 0 1 10 9 5 5 0 0 1-5 5h-2.25a1.75 1.75 0 0 0-1.4 2.8l.3.4a1.75 1.75 0 0 1-1.4 2.8z",key:"e79jfc"}],["circle",{cx:"13.5",cy:"6.5",r:".5",fill:"currentColor",key:"1okk4w"}],["circle",{cx:"17.5",cy:"10.5",r:".5",fill:"currentColor",key:"f64h9f"}],["circle",{cx:"6.5",cy:"12.5",r:".5",fill:"currentColor",key:"qy21gx"}],["circle",{cx:"8.5",cy:"7.5",r:".5",fill:"currentColor",key:"fotxhn"}]]};Ct.node;const Ls=ne(Ct);const Et={name:"user-round",size:24,node:[["circle",{cx:"12",cy:"8",r:"5",key:"1hypcn"}],["path",{d:"M20 21a8 8 0 0 0-16 0",key:"rfgkzh"}]],aliases:["user-2"]};Et.node;const Ts=ne(Et),Rs=Dt(function(s,n){const{render:r,className:i,style:c,disabled:g=!1,nativeButton:l=!0,id:d,payload:p,handle:h,...m}=s,j=Ya(!0),x=os(h)??j;if(!x)throw new Error(Ut(79));const _=as(d),b=x.useState("floatingRootContext"),u=x.useState("isOpenedByTrigger",_),y=x.useState("triggerPopupId",_),k=o.useRef(null),{registerTrigger:f,isMountedByThisTrigger:N}=ss(_,k,x,{payload:p}),{getButtonProps:E,buttonRef:v}=zt({disabled:g,native:l}),C=is(b),O=rs(()=>x.select("open"),M=>{x.set("openMethod",M)}),S={disabled:g,open:u},P=x.useState("triggerProps",N);return Gt("button",s,{state:S,ref:[v,n,f,k],props:[C.reference,P,O,{[Mt]:"",id:_,"aria-haspopup":"dialog","aria-expanded":u,"aria-controls":y},m,E],stateAttributesMapping:ns})}),Is="shrink-0 text-oai-gray-900 dark:text-oai-gray-200";function Ds({id:t,visible:s,onToggle:n}){const{attributes:r,listeners:i,setNodeRef:c,transform:g,transition:l,isDragging:d}=Da({id:t}),p={transform:Ua.Transform.toString(g)||void 0,transition:l,zIndex:d?20:void 0};return e.jsxs("div",{ref:c,style:p,className:le("flex items-center gap-3 py-2 rounded-md select-none touch-none","cursor-grab active:cursor-grabbing","hover:bg-oai-gray-100/60 dark:hover:bg-oai-gray-800/60","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand-500",d&&"relative bg-oai-gray-100 dark:bg-oai-gray-800"),...r,...i,children:[e.jsx(Ps,{className:"h-4 w-4 shrink-0 text-oai-gray-400 dark:text-oai-gray-500",strokeWidth:1.75,"aria-hidden":!0}),et(t)?e.jsx(Ma,{provider:et(t),size:18,className:le("pointer-events-none",Is)}):null,e.jsx("span",{className:"flex-1 text-sm text-oai-gray-900 dark:text-oai-gray-200",children:tt(t)}),e.jsx("div",{onPointerDown:h=>h.stopPropagation(),children:e.jsx(z,{checked:s,onChange:n,ariaLabel:`${a("limits.settings.toggle_visible")}: ${tt(t)}`})})]})}function Us({prefs:t}){const{order:s,visibility:n,toggle:r,setAllVisible:i,moveToward:c}=t,g=s.every(m=>n[m]!==!1),l=s.every(m=>n[m]===!1),d=s.filter(m=>n[m]!==!1).length,p=Ea(Qe(Aa,{activationConstraint:{distance:6}}),Qe(Oa,{coordinateGetter:Pa})),h=({active:m,over:j})=>{j&&m.id!==j.id&&c(m.id,j.id)};return e.jsxs(e.Fragment,{children:[e.jsx(R,{label:a("limits.settings.bulk_visibility"),hint:a("limits.settings.enabled_count",{enabled:d,total:s.length}),control:e.jsx(se,{options:[{value:"enabled",label:a("limits.settings.enable_all")},{value:"disabled",label:a("limits.settings.disable_all")}],value:g?"enabled":l?"disabled":null,onChange:m=>i(m==="enabled")})}),e.jsx(La,{sensors:p,collisionDetection:Ta,modifiers:[za],onDragEnd:h,children:e.jsx(Ra,{items:s,strategy:Ia,children:e.jsx("div",{className:"flex flex-col",children:s.map(m=>e.jsx(Ds,{id:m,visible:n[m]!==!1,onToggle:()=>r(m)},m))})})})]})}function zs(t){if(!t||typeof t!="object")return"";const s=t.user_metadata&&typeof t.user_metadata=="object"?t.user_metadata:{},n=t.profile&&typeof t.profile=="object"?t.profile:{},r=s.full_name||s.name||n.name||s.user_name||s.preferred_username;return typeof r=="string"&&r.trim()?r.trim():typeof t.email=="string"&&t.email.includes("@")?t.email.split("@")[0].trim()||t.email.trim():typeof t.email=="string"?t.email.trim():""}function Gs(t){return!t||typeof t!="object"?"":typeof t.email=="string"?t.email.trim():""}function Ms(t){const s=typeof t=="string"?t.trim():"";if(!s)return null;const n=s.match(/^@?([A-Za-z0-9][A-Za-z0-9-]{0,38})$/),r=s.match(/^https:\/\/github\.com\/([A-Za-z0-9][A-Za-z0-9-]{0,38})\/?$/i),i=n?.[1]||r?.[1];return i?`https://github.com/${i}`:null}function Ge(t,s){console.warn(`[tokentracker] settings ${t}:`,s)}function $s(t,s,n,r){const[i,c]=o.useState(()=>me()),g=s&&n&&dt(),l=o.useMemo(()=>({active:!0,busy:!1}),[t,s,n,r]),d=o.useRef(l);d.current=l;const[p,h]=o.useState(null),m=p?.scope===l?p:null;o.useEffect(()=>{l.active=!0;const _=()=>{const u=me();c(u),u||h(y=>y?.scope===l?{...y,error:null}:y)},b=()=>{h(u=>u?.scope===l?{...u,error:null}:u),we(r,"cloud-sync")};return _(),window.addEventListener("tt.cloudSyncChanged",_),window.addEventListener("storage",_),window.addEventListener(Be,b),()=>{l.active=!1,window.removeEventListener("tt.cloudSyncChanged",_),window.removeEventListener("storage",_),window.removeEventListener(Be,b)}},[l,r]);const j=o.useCallback(async()=>{if(!g||!me()||l.busy||!l.active||d.current!==l)return;l.busy=!0,h({scope:l,pending:!0,error:null});const _=()=>l.active&&d.current===l&&me();try{await Vt(()=>t())}catch(b){if(!_())return;["cloud_membership_required","cloud_read_only_expired","cloud_history_window_exceeded","cloud_machine_limit","machine_limit_exceeded","cloud_machine_paused"].includes(b?.code)?qt(r,b.code,b.membership,"cloud-sync"):h({scope:l,pending:!0,error:{code:"billing_network_error"}}),Ge("cloud sync",b)}finally{l.busy=!1,l.active&&d.current===l&&h(b=>b?.scope===l?{...b,pending:!1}:b)}},[g,l,t,r]),w=o.useCallback(async()=>{if(!g||l.busy||!l.active||d.current!==l)return;const _=!me();h({scope:l,pending:!1,error:null}),He(_),c(_),_?await j():we(r,"cloud-sync")},[g,l,j,r]),x=o.useCallback(()=>{!g||!l.active||d.current!==l||(He(!1),c(!1),h(_=>_?.scope===l?{..._,error:null}:_),we(r,"cloud-sync"))},[g,l,r]);return{cloudSyncOn:i,cloudSyncPending:!!m?.pending,cloudSyncError:m?.error,handleCloudSyncToggle:w,handleCloudSyncRetry:j,handleCloudSyncDisable:x,showLocalCloudSync:g}}function Fs(t){const[s,n]=o.useState(!1),[r,i]=o.useState(!1),[c,g]=o.useState(!1),[l,d]=o.useState(!1),[p,h]=o.useState(null),[m,j]=o.useState(!1),[w,x]=o.useState(""),[_,b]=o.useState(!1),[u,y]=o.useState(""),[k,f]=o.useState(""),[N,E]=o.useState(!1),[v,C]=o.useState(null),O=o.useMemo(()=>zs(t),[t]),S=o.useMemo(()=>Gs(t),[t]),P=o.useMemo(()=>typeof t?.id=="string"?t.id.trim():"",[t]),M=o.useMemo(()=>({setAnonymousOn:i,setCustomDisplayName:h,setGithubUrl:y,setProfileLoading:g,setPublicProfileOn:n,setShowGithubOn:b}),[]);return{anonymousOn:r,customDisplayName:p,displayName:O,editingGithub:N,editingName:m,email:S,githubError:v,githubInput:k,githubUrl:u,loadSetters:M,nameInput:w,profileLoading:c,profileSaving:l,publicProfileOn:s,setAnonymousOn:i,setCustomDisplayName:h,setEditingGithub:E,setEditingName:j,setGithubError:C,setGithubInput:f,setGithubUrl:y,setNameInput:x,setProfileLoading:g,setProfileSaving:d,setPublicProfileOn:n,setShowGithubOn:b,showGithubOn:_,userId:P}}function Bs(t,s,n){o.useEffect(()=>{if(!s)return;let r=!0;return n.setProfileLoading(!0),(async()=>{try{const i=await ct({getAccessToken:t});if(!r||!i)return;const c=await Kt({accessToken:i});if(!r)return;n.setPublicProfileOn(!!c?.enabled),n.setAnonymousOn(!!c?.anonymous),c?.display_name&&n.setCustomDisplayName(c.display_name),n.setShowGithubOn(!!c?.show_github_url),n.setGithubUrl(c?.github_url||"")}catch(i){Ge("load public profile",i)}finally{r&&n.setProfileLoading(!1)}})(),()=>{r=!1}},[t,s,n])}function Hs(t,s,n){return o.useCallback(async(r,{label:i,onError:c,onSuccess:g}={})=>{if(!n||s.profileSaving)return!1;s.setProfileSaving(!0);try{const l=await ct({getAccessToken:t});if(!l)return!1;const d=await Wt({accessToken:l,...r});return g?.(d),!0}catch(l){return c?c(l):Ge(i||"mutate profile",l),!1}finally{s.setProfileSaving(!1)}},[t,s,n])}function Vs(t,s){return{anonymousOn:t.anonymousOn,customDisplayName:t.customDisplayName,displayName:t.displayName,editingName:t.editingName,handleAnonymousToggle:s.handleAnonymousToggle,handleSaveName:s.handleSaveName,nameInput:t.nameInput,profileLoading:t.profileLoading,profileSaving:t.profileSaving,setEditingName:t.setEditingName,setNameInput:t.setNameInput,startEditingName:s.startEditingName}}function qs(t,s){return{editingGithub:t.editingGithub,githubError:t.githubError,githubInput:t.githubInput,githubUrl:t.githubUrl,handleSaveGithub:s.handleSaveGithub,handleShowGithubToggle:s.handleShowGithubToggle,profileLoading:t.profileLoading,profileSaving:t.profileSaving,setEditingGithub:t.setEditingGithub,setGithubError:t.setGithubError,setGithubInput:t.setGithubInput,showGithubOn:t.showGithubOn,startEditingGithub:s.startEditingGithub}}function Ks(t,s){const n=o.useCallback(async()=>{const i=!t.publicProfileOn;await s({enabled:i},{label:"toggle public profile",onSuccess:()=>t.setPublicProfileOn(i)})},[s,t]);return{handleAnonymousToggle:o.useCallback(async()=>{const i=!t.anonymousOn;await s({anonymous:i},{label:"toggle anonymous",onSuccess:()=>t.setAnonymousOn(i)})},[s,t]),handlePublicProfileToggle:n}}function Ws(t,s,n){const r=o.useCallback(async()=>{const c=t.nameInput.trim().slice(0,50);c&&await s({display_name:c},{label:"save display name",onSuccess:()=>{t.setCustomDisplayName(c),t.setEditingName(!1),n?.()}})},[s,t,n]),i=o.useCallback(()=>{t.setNameInput(t.customDisplayName||t.displayName),t.setEditingName(!0)},[t]);return{handleSaveName:r,startEditingName:i}}function Ys(t,s){const n=o.useCallback(async()=>{if(!t.showGithubOn&&!t.githubUrl){t.setEditingGithub(!0),t.setGithubInput(""),t.setGithubError(null);return}const c=!t.showGithubOn;await s({show_github_url:c},{label:"toggle GitHub profile",onSuccess:()=>t.setShowGithubOn(c)})},[s,t]),r=o.useCallback(async()=>{const c=Ms(t.githubInput);if(t.githubInput.trim()&&!c){t.setGithubError(a("settings.account.githubUrlInvalid"));return}t.setGithubError(null),await s({github_url:c,show_github_url:!!c},{label:"save GitHub profile",onError:g=>t.setGithubError(g?.message||a("settings.account.githubUrlInvalid")),onSuccess:g=>{t.setGithubUrl(g?.github_url||c||""),t.setShowGithubOn(!!c),t.setEditingGithub(!1)}})},[s,t]),i=o.useCallback(()=>{t.setGithubInput(t.githubUrl),t.setGithubError(null),t.setEditingGithub(!0)},[t]);return{handleSaveGithub:r,handleShowGithubToggle:n,startEditingGithub:i}}function Me(){const t=lt();o.useSyncExternalStore($t,Ft,()=>0);const s=Bt(t.user?.id),r=!(s.membership?.status==="self_hosted"||s.catalog?.policy?.hosting_mode==="self_hosted")&&(Ht()||s.membership?.hosting_mode==="hosted"),i=Fs(t.user),c=$s(t.getAccessToken,t.enabled,t.signedIn,t.user?.id);Bs(t.getAccessToken,t.signedIn&&r,i.loadSetters);const g=Hs(t.getAccessToken,i,r),l=Ks(i,g),d=Ws(i,g,t.refreshDisplayName),p=Ys(i,g);return{...t,...c,email:i.email,handlePublicProfileToggle:l.handlePublicProfileToggle,userId:i.userId,name:Vs(i,{...l,...d}),github:qs(i,p),profileLoading:i.profileLoading,profileSaving:i.profileSaving,publicProfileOn:r&&i.publicProfileOn,publicProfileAvailable:r}}function Pt({disabled:t,onCancel:s,onSave:n,saveLabel:r=a("settings.account.save")}){return e.jsxs(e.Fragment,{children:[e.jsx(A,{variant:"primary",size:"sm",onClick:n,disabled:t,children:r}),e.jsx(A,{variant:"ghost",size:"sm",onClick:s,className:"text-oai-gray-500 hover:text-oai-gray-700 dark:hover:text-oai-gray-300",children:a("settings.account.cancel")})]})}function Zs({nameInput:t,setEditingName:s,setNameInput:n,profileSaving:r,handleSaveName:i}){return e.jsxs("div",{className:"mt-2 flex items-center gap-2",children:[e.jsx("input",{type:"text",value:t,onChange:c=>n(c.target.value),onKeyDown:c=>{c.key==="Enter"&&i(),c.key==="Escape"&&s(!1)},maxLength:50,autoFocus:!0,className:`flex-1 ${ve}`,placeholder:a("settings.account.displayName")}),e.jsx(Pt,{disabled:r||!t.trim(),onCancel:()=>s(!1),onSave:i,saveLabel:r?a("settings.account.saving"):void 0})]})}function Js({githubError:t,githubInput:s,handleSaveGithub:n,profileSaving:r,setEditingGithub:i,setGithubError:c,setGithubInput:g}){return e.jsxs("div",{className:"mt-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"text",value:s,onChange:l=>{g(l.target.value),t&&c(null)},onKeyDown:l=>{l.key==="Enter"&&n(),l.key==="Escape"&&(i(!1),c(null))},maxLength:100,autoFocus:!0,className:`flex-1 ${ve}`,placeholder:a("settings.account.githubUrlPlaceholder")}),e.jsx(Pt,{disabled:r,onCancel:()=>{i(!1),c(null)},onSave:n,saveLabel:r?a("settings.account.saving"):void 0})]}),t?e.jsx("div",{className:"mt-1.5 text-xs text-red-600 dark:text-red-400",children:t}):null]})}function Ot({disabled:t=!1,label:s,onClick:n,title:r}){return e.jsxs(A,{variant:"secondary",size:"sm",onClick:n,disabled:t,title:r,className:"gap-1.5",children:[e.jsx($a,{className:"h-3.5 w-3.5","aria-hidden":!0}),e.jsx("span",{children:s})]})}function At({actions:t,editing:s,editor:n,hint:r,label:i}){return e.jsx("div",{className:"py-3",children:e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-sm text-oai-gray-900 dark:text-oai-gray-200",children:i}),s?n:e.jsx("div",{className:"mt-0.5 truncate text-xs text-oai-gray-500 dark:text-oai-gray-400",children:r})]}),s?null:t]})})}function Xs({name:t}){const s=t.anonymousOn?a("settings.account.displayNameDisabledWhileAnon"):void 0;return e.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[e.jsx(Ot,{disabled:t.anonymousOn,label:a("settings.account.edit"),onClick:t.startEditingName,title:s}),e.jsx(z,{checked:!t.anonymousOn,onChange:t.handleAnonymousToggle,disabled:t.profileLoading||t.profileSaving,ariaLabel:a("settings.account.displayName")})]})}function Qs({name:t}){const{anonymousOn:s,customDisplayName:n,displayName:r,editingName:i,handleAnonymousToggle:c,handleSaveName:g,nameInput:l,profileLoading:d,profileSaving:p,setEditingName:h,setNameInput:m,startEditingName:j}=t,w=s?a("settings.account.displayNameAnonymousHint"):n||r;return e.jsx(At,{label:a("settings.account.displayName"),editing:i,hint:w,editor:e.jsx(Zs,{nameInput:l,setEditingName:h,setNameInput:m,profileSaving:p,handleSaveName:g}),actions:e.jsx(Xs,{name:t})})}function en({github:t}){const{editingGithub:s,githubError:n,githubInput:r,githubUrl:i,handleSaveGithub:c,handleShowGithubToggle:g,profileLoading:l,profileSaving:d,setEditingGithub:p,setGithubError:h,setGithubInput:m,showGithubOn:j,startEditingGithub:w}=t;return e.jsx(e.Fragment,{children:e.jsx(At,{label:a("settings.account.githubUrl"),editing:s,hint:i||a("settings.account.githubUrlHint"),editor:e.jsx(Js,{githubError:n,githubInput:r,handleSaveGithub:c,profileSaving:d,setEditingGithub:p,setGithubError:h,setGithubInput:m}),actions:e.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[e.jsx(Ot,{label:a("settings.account.edit"),onClick:w}),e.jsx(z,{checked:j,onChange:g,disabled:l||d,ariaLabel:a("settings.account.githubUrl")})]})})})}function tn(){const{openLoginModal:t}=ut();return e.jsx(Z,{title:a("settings.section.account"),children:e.jsxs("div",{className:"flex flex-col gap-3 py-3 sm:flex-row sm:items-center sm:justify-between sm:gap-4",children:[e.jsx("p",{className:"text-sm text-oai-gray-500 dark:text-oai-gray-400",children:a("settings.account.signedOutHint")}),e.jsx(A,{variant:"primary",size:"sm",onClick:t,children:a("settings.account.signIn")})]})})}function an({name:t,github:s}){return e.jsxs(e.Fragment,{children:[e.jsx(Qs,{name:t}),e.jsx(en,{github:s})]})}function sn({settings:t}={}){return t?e.jsx(Lt,{settings:t}):e.jsx(nn,{})}function nn(){const t=Me();return e.jsx(Lt,{settings:t})}function Lt({settings:t}){return t.enabled?t.signedIn?e.jsxs(Z,{title:a("settings.section.account"),subtitle:t.email||t.name.customDisplayName||t.name.displayName,action:e.jsx(on,{onSignOut:t.signOut}),children:[e.jsx(rn,{userId:t.userId}),e.jsx(ln,{checked:t.publicProfileOn,disabled:t.profileLoading||t.profileSaving||t.publicProfileAvailable===!1,onChange:t.handlePublicProfileToggle,unavailable:t.publicProfileAvailable===!1}),e.jsx(cn,{visible:t.publicProfileOn,name:t.name,github:t.github})]}):e.jsx(tn,{}):null}function rn({userId:t}){const[s,n]=Pe.useState(!1);if(!t)return null;const r=async()=>{try{if(typeof navigator>"u"||!navigator.clipboard?.writeText)return;await navigator.clipboard.writeText(t),n(!0),globalThis.setTimeout(()=>n(!1),1200)}catch{n(!1)}};return e.jsx(R,{label:a("settings.account.userId"),hint:e.jsx("span",{className:"font-mono",children:t}),control:e.jsxs(A,{variant:"secondary",size:"sm",onClick:r,"aria-label":a("settings.account.copyUserId"),className:"gap-1.5",children:[s?e.jsx(Ha,{className:"h-3.5 w-3.5","aria-hidden":!0}):e.jsx(Va,{className:"h-3.5 w-3.5","aria-hidden":!0}),e.jsx("span",{children:s?a("settings.account.copied"):a("settings.account.copy")})]})})}function on({onSignOut:t}){return e.jsxs(A,{variant:"ghost",size:"sm",onClick:()=>t(),className:"!h-7 !px-2 text-xs text-oai-gray-500 hover:text-oai-gray-700 dark:hover:text-oai-gray-300",children:[e.jsx(As,{className:"h-3.5 w-3.5 mr-1.5","aria-hidden":!0}),e.jsx("span",{children:a("settings.account.signOut")})]})}function ln({checked:t,disabled:s,onChange:n,unavailable:r}){return e.jsx(R,{label:a("settings.account.publicProfile"),hint:a(r?"cloud.self_host.public_profile_disabled":"settings.account.publicProfileHint"),control:e.jsx(z,{checked:t,onChange:n,disabled:s,ariaLabel:a("settings.account.publicProfile")})})}function cn({visible:t,name:s,github:n}){return e.jsx(vt,{initial:!1,children:t?e.jsx(yt.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},transition:{height:{duration:.28,ease:[.22,1,.36,1]},opacity:{duration:.2,ease:[.22,1,.36,1]}},style:{overflow:"hidden"},className:"divide-y divide-oai-gray-200/60 dark:divide-oai-gray-800/60",children:e.jsx(an,{name:s,github:n})},"public-profile-fields"):null})}function $e({open:t,onOpenChange:s,title:n,triggerLabel:r=n,icon:i,wide:c=!1,preventClose:g=!1,initialFocus:l,children:d}){return e.jsxs(Za,{open:t,onOpenChange:(p,h)=>{if(!p&&g){h.cancel();return}s(p)},children:[e.jsxs(Rs,{className:"inline-flex h-11 w-full items-center gap-3 rounded-md border-0 bg-transparent p-0 text-left text-sm font-medium text-oai-black transition-colors hover:bg-oai-gray-100 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-oai-gray-500 dark:text-oai-white dark:hover:bg-oai-gray-800",children:[i?e.jsx(i,{size:16,className:"shrink-0","aria-hidden":!0}):null,e.jsx("span",{className:"min-w-0 flex-1",children:r}),e.jsx(mt,{size:16,className:"shrink-0 text-oai-gray-500 dark:text-oai-gray-400","aria-hidden":!0})]}),e.jsxs(Ja,{children:[e.jsx(Xa,{className:"tt-cloud-action-backdrop fixed inset-0 z-[100] bg-black/40 dark:bg-black/60"}),e.jsx(Qa,{className:"tt-cloud-settings fixed inset-0 z-[101] flex items-center justify-center overflow-y-auto overscroll-contain p-4",children:e.jsxs(es,{initialFocus:l,"aria-modal":"true",className:`tt-cloud-action-popup tt-cloud-theme relative max-h-[calc(100dvh-2rem)] w-full ${c?"max-w-2xl":"max-w-lg"} overflow-y-auto overscroll-contain rounded-xl bg-white p-5 shadow-xl outline-none dark:bg-oai-gray-900`,children:[e.jsxs("div",{className:"mb-3 flex min-h-11 items-center justify-between gap-4",children:[e.jsx(ts,{className:"min-w-0 text-lg font-semibold text-oai-black dark:text-oai-white",children:n}),e.jsx(ls,{disabled:g,"aria-label":a("shared.dialog.close"),className:"inline-flex size-11 min-h-11 min-w-11 shrink-0 items-center justify-center rounded-md border-0 bg-transparent p-0 text-oai-gray-500 transition-colors hover:bg-oai-gray-100 hover:text-oai-black focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-oai-gray-500 disabled:cursor-wait disabled:opacity-40 dark:text-oai-gray-400 dark:hover:bg-oai-gray-800 dark:hover:text-oai-white",children:e.jsx(Yt,{size:18,"aria-hidden":!0})})]}),e.jsx("div",{"data-settings-panel":"cloud",className:"min-w-0",children:d})]})})]})]})}function he(t){return t.replace(/[\t\n\r\f\v -]/g,"").toUpperCase()}function dn({account:t,auth:s,refresh:n,compact:r=!1,panelContainer:i=null,layout:c="default",dialogOpen:g,onDialogOpenChange:l}){const d=c==="settings-row",[p,h]=o.useState(!1),m=d&&typeof g=="boolean"?g:p,[j,w]=o.useState(""),[x,_]=o.useState(!1),[b,u]=o.useState(null),[y,k]=o.useState(null),[f,N]=o.useState(!1),E=o.useId(),v=o.useRef(null),C=o.useRef(null),O=o.useRef(!1),S=o.useRef(!1),P=o.useRef(0),M=`${Oe()}.${t?.environment||"unknown"}.${s?.signedIn?s.user?.id:""}`,G=o.useRef(M);G.current=M,o.useEffect(()=>(S.current=!0,P.current+=1,C.current=null,O.current=!1,h(!1),w(""),_(!1),u(null),k(null),N(!1),()=>{S.current=!1,P.current+=1}),[M]);const J=t?.membership?.status==="self_hosted"||t?.membership?.hosting_mode==="self_hosted",V=t?.gift_redemption_available===!0,te=d?t?.gifts||[]:[];if(!s?.signedIn||J||!V&&!te.length)return null;const $=t.redemption_restriction,F=T=>{!T&&O.current||(typeof g!="boolean"&&h(T),l?.(T))},K=async(T,ie)=>{const re=await n();ie()&&N(!!re?.gifts?.some(W=>W.id===T?.id))},q=async T=>{if(O.current||T&&(!V||!j.trim()))return;if(T&&$&&$!=="gift_checkout_pending"){u(new Ne($));return}O.current=!0;const ie=++P.current,re=M,W=()=>S.current&&P.current===ie&&G.current===re;_(!0),u(null);try{if(T){const ae=j.trim();(!C.current||he(C.current.code)!==he(ae))&&(C.current={code:ae,request_id:crypto.randomUUID()});const oe=await ce("redeem-gift",{auth:async()=>{const de=await pt(s.getAccessToken);if(!W())throw new Ne("authentication_required",401);return de},body:C.current});if(!W())return;if(!oe?.gift?.id)throw new Ne("billing_operation_failed");k(oe),N(!1),w(""),C.current=null,await K(oe.gift,W)}else await K(y?.gift,W)}catch(ae){W()&&u(ae)}finally{W()&&(O.current=!1,_(!1))}};let L=null;return(d||m)&&(L=e.jsxs("div",{id:`${E}-panel`,className:d?"space-y-3":r?"w-full space-y-3 rounded-lg bg-oai-gray-50 p-4 dark:bg-oai-gray-950/50":"mt-3 space-y-3",children:[V?e.jsxs(e.Fragment,{children:[e.jsx("p",{id:`${E}-detail`,className:d?"sr-only":"text-xs leading-5 text-oai-gray-600 dark:text-oai-gray-300",children:a("cloud.gift.detail")}),y?e.jsxs("div",{role:"status",className:"space-y-2 text-sm leading-6",children:[d&&f?null:e.jsx("p",{children:a(f?y.already_redeemed?"cloud.gift.already_redeemed":"cloud.gift.redeemed":"cloud.gift.refresh_needed")}),y.gift?d&&f?e.jsxs("div",{className:"py-1",children:[e.jsx("p",{className:"text-base font-medium text-oai-black dark:text-oai-white",children:a("cloud.gift.duration",{days:y.gift.duration_days})}),e.jsx("p",{className:"mt-1 text-sm text-oai-gray-500 dark:text-oai-gray-400",children:a("cloud.history.term",{start:H(y.gift.starts_at),end:H(y.gift.ends_at)})})]}):e.jsx("p",{className:"text-xs text-oai-gray-600 dark:text-oai-gray-300",children:a("cloud.gift.term",{days:y.gift.duration_days,start:H(y.gift.starts_at),end:H(y.gift.ends_at)})}):null,f?e.jsxs("div",{className:"flex flex-wrap justify-end gap-2 pt-3",children:[e.jsx(A,{type:"button",variant:"secondary",size:"sm",onClick:()=>{k(null),N(!1),requestAnimationFrame(()=>v.current?.focus())},children:a("cloud.gift.redeem_another")}),d?e.jsx(A,{type:"button",size:"sm",className:"min-w-20",disabled:x,onClick:()=>F(!1),children:a("cloud.gift.done")}):null]}):e.jsx(A,{type:"button",variant:"secondary",disabled:x,onClick:()=>{q(!1)},children:a("cloud.action.refresh_membership")})]}):e.jsxs("form",{onSubmit:T=>{T.preventDefault(),q(!0)},"aria-busy":x,children:[e.jsx("label",{htmlFor:E,className:d?"sr-only":"text-sm font-medium",children:a("cloud.gift.code_label")}),e.jsxs("div",{className:"mt-2 flex flex-col gap-2 sm:flex-row",children:[e.jsx("input",{id:E,ref:v,value:j,disabled:x,maxLength:128,autoComplete:"off",spellCheck:!1,autoCapitalize:"characters","data-ph-no-capture":"true","aria-describedby":`${E}-detail${b?` ${E}-error`:""}`,"aria-invalid":!!b,onChange:T=>{he(T.target.value)!==he(j)&&(C.current=null),w(T.target.value),u(null)},className:"min-h-10 min-w-0 flex-1 rounded-md border border-oai-gray-300 bg-transparent px-3 font-mono text-sm outline-none focus:border-oai-brand focus:ring-2 focus:ring-inset focus:ring-oai-brand/30 dark:border-oai-gray-700"}),e.jsx(A,{type:"submit",variant:"secondary",disabled:x||!j.trim(),children:a(x?"cloud.gift.redeeming":"cloud.gift.confirm")})]})]}),b?e.jsx("div",{id:`${E}-error`,children:["gift_checkout_pending","gift_requires_renewal_cancel"].includes(b.code)?e.jsx("p",{role:"alert",className:"text-xs leading-5 text-oai-gray-600 dark:text-oai-gray-300",children:Zt(b,"gift")}):e.jsx(ee,{error:b,context:"gift"})}):null]}):null,te.length&&!y?e.jsx("ul",{"aria-label":a("cloud.gift.history_title"),className:"divide-y divide-oai-gray-200 dark:divide-oai-gray-800",children:te.map(T=>e.jsxs("li",{className:"py-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 text-sm",children:[e.jsx("span",{children:a("cloud.gift.duration",{days:T.duration_days})}),e.jsx("span",{children:a(["active","pending","expired","revoked"].includes(T.state)?`cloud.gift.state_${T.state}`:"cloud.status.unknown")})]}),e.jsx("p",{className:"mt-1 text-xs leading-5 text-oai-gray-600 dark:text-oai-gray-300",children:a("cloud.history.term",{start:H(T.starts_at),end:H(T.ends_at)})})]},T.id))}):null]})),d?e.jsx($e,{open:m,onOpenChange:F,title:a(y&&f?"cloud.gift.redeemed":V?"cloud.gift.redeem_action":"cloud.gift.history_title"),triggerLabel:a(V?"cloud.gift.redeem_action":"cloud.gift.history_title"),icon:Te,preventClose:x,initialFocus:V&&!y?v:void 0,children:L}):e.jsxs("div",{className:d?void 0:r?"contents":"mt-4",children:[e.jsxs(A,{type:"button",variant:"ghost",size:r||d?"sm":"md",className:d?"!h-11 !w-full !justify-start !px-0 !text-oai-black dark:!text-oai-white hover:!bg-oai-gray-100 dark:hover:!bg-oai-gray-800 active:!scale-100":r?"!h-10 !px-0":void 0,"aria-expanded":m,"aria-controls":d||m?`${E}-panel`:void 0,onClick:()=>h(T=>!T),disabled:x,children:[r||d?e.jsx(Te,{size:16,className:`${d?"mr-3":"mr-2"} shrink-0`,"aria-hidden":!0}):null,a(V?"cloud.gift.redeem_action":"cloud.gift.history_title"),d?e.jsx(Re,{size:16,className:`ml-auto shrink-0 transition-transform motion-reduce:transition-none ${m?"rotate-180":""}`,"aria-hidden":!0}):null]}),!d&&i&&L?gt.createPortal(L,i):L]})}const be=["total_tokens","billable_total_tokens","input_tokens","output_tokens","cached_input_tokens","cache_creation_input_tokens","reasoning_output_tokens","conversation_count","total_cost_usd"];class U extends Error{constructor(s,n=0){super(s),this.code=s,this.status=n}code;status}function ge(t){return typeof t=="string"&&/^\d{4}-\d{2}-\d{2}$/.test(t)&&Number.isFinite(Date.parse(t+"T00:00:00Z"))&&new Date(t+"T00:00:00Z").toISOString().slice(0,10)===t}function un(t,s){if(!ea(t))throw new U("export_auth_required",401);try{const n=t.split(".")[1].replace(/-/g,"+").replace(/_/g,"/"),r=JSON.parse(atob(n.padEnd(Math.ceil(n.length/4)*4,"=")));if((r.sub||r.user_id)!==s||r.role!=="authenticated"||!Number.isFinite(r.exp)||r.exp*1e3<=Date.now())throw Error()}catch{throw new U("export_auth_required",401)}}function it(t){if(typeof t?.membership?.can_read_cloud!="boolean")throw new U("export_invalid_data",503);if(!t.membership.can_read_cloud)throw new U("export_access_denied",402);const s=t.membership;return JSON.stringify([t.environment,s.phase,s.status,s.hosting_mode,s.expires_at,s.trial_ends_at,s.transition_ends_at,s.read_only_until])}async function mn({userId:t,auth:s,from:n,to:r,deviceId:i=null,signal:c,assertCurrent:g=()=>{},fetchImpl:l=fetch}){if(!ge(n)||!ge(r)||n>r)throw new U("export_invalid_dates",400);if(typeof s!="function")throw new U("export_auth_required",401);if(!t||i&&!/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(i))throw new U("export_invalid_scope",400);const d=Oe(),p=Ve();if(!d)throw new U("export_instance_changed",409);const h=()=>{if(c?.aborted)throw new U("export_cancelled",409);if(g(),d!==Oe()||p!==Ve())throw new U("export_instance_changed",409)};async function m(u,y){h();const k=await pt(s);h(),un(k||"",t);const f=new URL(Xt(d,u));for(const[C,O]of Object.entries(y))f.searchParams.set(C,O);const N=new AbortController,E=()=>N.abort();c?.addEventListener("abort",E,{once:!0});const v=setTimeout(E,25e3);try{const C=await Qt(f.toString(),{method:"GET",cache:"no-store",redirect:"error",signal:N.signal,headers:{Accept:"application/json",Authorization:"Bearer "+k,...p?{apikey:p}:{}}},l);if(h(),!C.ok)throw new U(C.status===401?"export_auth_required":C.status===402||C.status===403?"export_access_denied":"export_failed",C.status);const O=await C.json();return h(),O}finally{clearTimeout(v),c?.removeEventListener("abort",E)}}const j=it(await m("tokentracker-billing",{action:"account"})),w={from:n,to:r,tz_offset_minutes:"0",...i?{device_id:i}:{}};if(await m("tokentracker-account-daily",w),it(await m("tokentracker-billing",{action:"account"}))!==j)throw new U("export_access_changed",409);const x=await m("tokentracker-account-daily",w);if(!ge(x?.from)||!ge(x?.to)||x.from<n||x.to>r||x.from>x.to||!Array.isArray(x.data)||x.data.length>1096)throw new U("export_invalid_data",503);const _=new Set,b=x.data.map(u=>{if(!ge(u?.day)||u.day<x.from||u.day>x.to||_.has(u.day))throw new U("export_invalid_data",503);_.add(u.day);const y={day:u.day};for(const k of be){const f=u[k];if(typeof f!="number"||!Number.isFinite(f)||f<0||k!=="total_cost_usd"&&!Number.isSafeInteger(f))throw new U("export_invalid_data",503);y[k==="total_cost_usd"?"estimated_cost_usd":k]=f}return y}).sort((u,y)=>u.day.localeCompare(y.day));return h(),{schema:"tokentracker.cloud-usage.v1",metadata:{source:"cloud",backend_origin:new URL(d).origin,exported_at:new Date().toISOString(),timezone:"UTC",requested_range:{from:n,to:r},effective_range:{from:x.from,to:x.to},device_scope:i?"selected":"all",aggregation:"daily_all_providers",cost_currency:"USD",cost_basis:"estimated",row_count:b.length},rows:b}}function gn(t){const s=String(t??"");return'"'+(/^[\s]*[=+\-@]/.test(s)?"'"+s:s).replace(/"/g,'""')+'"'}function pn(t,s){if(s==="json")return JSON.stringify(t,null,2)+`
3
+ `;const n=t.metadata,r=["row_type","source","backend_origin","exported_at","timezone","cost_currency","cost_basis","requested_from","requested_to","effective_from","effective_to","device_scope","aggregation","row_count","day",...be.map(c=>c==="total_cost_usd"?"estimated_cost_usd":c)],i=[n.source,n.backend_origin,n.exported_at,n.timezone,n.cost_currency,n.cost_basis,n.requested_range.from,n.requested_range.to,n.effective_range.from,n.effective_range.to,n.device_scope,n.aggregation,n.row_count];return[r,["metadata",...i,"",...be.map(()=>"")],...t.rows.map(c=>["usage",...i,c.day,...be.map(g=>c[g==="total_cost_usd"?"estimated_cost_usd":g])])].map(c=>c.map(gn).join(",")).join(`\r
4
+ `)+`\r
5
+ `}async function hn(t,s,{signal:n,assertCurrent:r=()=>{}}={}){const i=pn(t,s),c=`tokentracker-cloud-usage-${t.metadata.effective_range.from}-${t.metadata.effective_range.to}.${s}`,g=()=>{if(n?.aborted)throw new U("export_cancelled",409);r()};g();const l=await Jt({filename:c,content:i,format:s,signal:n});if(g(),l?.saved===!0)return;if(l!==null)throw new U("export_failed",503);const d=new Blob([i],{type:s==="csv"?"text/csv;charset=utf-8":"application/json;charset=utf-8"}),p=URL.createObjectURL(d);try{const h=document.createElement("a");h.href=p,h.download=c,document.body.appendChild(h);try{h.click()}finally{h.remove()}}finally{setTimeout(()=>URL.revokeObjectURL(p),1e3)}}function fn(t){return t?.status===401?a("cloud.export.error_auth"):t?.status===402||t?.status===403?a("cloud.export.error_access"):t?.code==="export_invalid_dates"?a("cloud.export.error_dates"):t?.status===409?a("cloud.export.error_changed"):a("cloud.export.error_failed")}function xn({from:t,to:s,deviceId:n=null,auth:r,compact:i=!1,panelContainer:c=null,layout:g="default",dialogOpen:l,onDialogOpenChange:d}){const p=g==="settings-row",h=lt(),m=r||h,j=m?.signedIn?m.user?.id:null,w=new Date().toISOString().slice(0,10),x=new Date(Date.now()-29*864e5).toISOString().slice(0,10),[_,b]=o.useState(t||x),[u,y]=o.useState(s||w),[k,f]=o.useState(!1),N=p&&typeof l=="boolean"?l:k,[E,v]=o.useState(!1),[C,O]=o.useState(null),[S,P]=o.useState(null),[M,G]=o.useState(!1),[J,V]=o.useState(2),te=o.useId(),$=o.useRef(null),F=o.useRef(0),K=o.useRef(null),q=o.useRef(!1),L=o.useRef(!1),T=o.useRef(N);T.current=N;const ie=o.useRef(N);if($.current={userId:j,client:m?.client,start:_,end:u,deviceId:n,from:t,to:s},o.useEffect(()=>{L.current=!0;const I=()=>{++F.current,K.current?.abort(),q.current=!1,v(!1),P(null),O(null),G(!1)};return window.addEventListener(qe,I),()=>{L.current=!1,++F.current,K.current?.abort(),window.removeEventListener(qe,I)}},[]),o.useEffect(()=>{++F.current,K.current?.abort(),q.current=!1,v(!1),O(null),P(null),G(!1),t&&b(t),s&&y(s)},[j,m?.client,t,s,n]),o.useEffect(()=>{p&&ie.current&&!N&&re(),ie.current=N},[N,p]),o.useEffect(()=>{const I=window.matchMedia?.("(max-width: 639px)");if(!I)return;const D=()=>V(I.matches?1:2);return D(),I.addEventListener("change",D),()=>I.removeEventListener("change",D)},[]),!j||m?.enabled===!1)return null;function re(){++F.current,K.current?.abort(),q.current=!1,v(!1),O(null),P(null),G(!1)}function W(I){I||re(),typeof l!="boolean"&&f(I),d?.(I)}function ae(I,D){++F.current,K.current?.abort(),q.current=!1,v(!1),O(null),P(null),I(D)}async function oe(I){if(q.current)return;q.current=!0;const D=$.current,ke=++F.current,_e=new AbortController;K.current=_e,v(!0),O(null),P(null);const pe=()=>{const X=$.current;if(!L.current||ke!==F.current||p&&!T.current||!X||Object.keys(D).some(Q=>D[Q]!==X[Q])||D.client&&!ta(D.client))throw new U("export_cancelled",409)};try{const X=await mn({userId:D.userId,auth:m.getAccessToken,from:D.start,to:D.end,deviceId:D.deviceId,signal:_e.signal,assertCurrent:pe});pe(),await hn(X,I,{signal:_e.signal,assertCurrent:pe}),pe();const Q=X.metadata.effective_range,Fe=X.rows.length?a("cloud.export.success",{count:X.rows.length,from:Q.from,to:Q.to}):a("cloud.export.empty");P(Q.from!==D.start||Q.to!==D.end?`${Fe} ${a("cloud.export.truncated",{from:Q.from,to:Q.to})}`:Fe)}catch(X){L.current&&ke===F.current&&O(fn(X))}finally{ke===F.current&&(q.current=!1,L.current&&v(!1))}}const de="hover:!text-oai-black dark:hover:!text-oai-white hover:!bg-oai-gray-100 dark:hover:!bg-oai-gray-800 focus:!ring-oai-gray-500/40";let ue=null;return(p||N)&&(ue=e.jsxs("div",{id:te,className:p?void 0:i?"w-full rounded-lg bg-oai-gray-50 p-4 dark:bg-oai-gray-950/50":"mt-2 border-l-2 border-oai-gray-200 pl-3 dark:border-oai-gray-700","aria-busy":E,children:[p?null:e.jsx("p",{className:"text-xs leading-5 text-oai-gray-600 dark:text-oai-gray-300",children:a("cloud.export.description")}),e.jsxs("div",{className:p?"space-y-4":"mt-3 flex flex-wrap items-end gap-3",children:[p?e.jsxs(us,{open:M,onOpenChange:G,children:[e.jsxs(ms,{disabled:E,"aria-label":a("trend.zoom.pick_range"),className:"inline-flex h-10 min-h-10 w-full items-center gap-2 rounded-md border border-oai-gray-300 bg-transparent px-3 text-sm text-oai-black transition-colors hover:bg-oai-gray-50 focus-visible:outline focus-visible:outline-2 focus-visible:outline-oai-gray-500 disabled:opacity-50 dark:border-oai-gray-700 dark:text-oai-white dark:hover:bg-oai-gray-800",children:[e.jsx(ds,{size:16,className:"shrink-0 text-oai-gray-500","aria-hidden":!0}),e.jsxs("span",{className:"flex-1 text-left tabular-nums",children:[_," → ",u]}),e.jsx(Re,{size:14,className:"shrink-0 text-oai-gray-500","aria-hidden":!0})]}),e.jsx(gs,{children:e.jsx(ps,{sideOffset:8,side:"bottom",align:"start",className:"z-[110]",children:e.jsx(hs,{className:"max-w-[calc(100vw-2rem)] rounded-xl border border-oai-gray-200 bg-white shadow-lg outline-none dark:border-oai-gray-700 dark:bg-oai-gray-900",children:e.jsx(cs,{from:_,to:u,numberOfMonths:J,onApply:(I,D)=>{ae(b,I),y(D),G(!1)},onCancel:()=>G(!1)})})})})]}):e.jsxs(e.Fragment,{children:[e.jsxs("label",{className:"min-w-0 text-xs text-oai-gray-700 dark:text-oai-gray-200",children:[a("cloud.export.from"),e.jsx("input",{type:"date",value:_,onChange:I=>ae(b,I.target.value),className:`${p?"min-h-10 min-w-0 w-full ":""}mt-1 block rounded-md border border-oai-gray-300 bg-white px-2 py-1.5 text-sm text-oai-black focus:outline-none focus:ring-2 focus:ring-inset focus:ring-oai-gray-500/40 dark:border-oai-gray-700 dark:bg-oai-gray-900 dark:text-oai-white`})]}),e.jsxs("label",{className:"min-w-0 text-xs text-oai-gray-700 dark:text-oai-gray-200",children:[a("cloud.export.to"),e.jsx("input",{type:"date",value:u,onChange:I=>ae(y,I.target.value),className:`${p?"min-h-10 min-w-0 w-full ":""}mt-1 block rounded-md border border-oai-gray-300 bg-white px-2 py-1.5 text-sm text-oai-black focus:outline-none focus:ring-2 focus:ring-inset focus:ring-oai-gray-500/40 dark:border-oai-gray-700 dark:bg-oai-gray-900 dark:text-oai-white`})]})]}),e.jsxs("div",{className:p?"flex justify-end gap-2":"flex gap-2",children:[e.jsx(A,{type:"button",variant:p?"secondary":"ghost",size:"sm",className:`${de} ${p?"!min-h-8 !h-8":""}`,disabled:E,onClick:()=>oe("csv"),children:a("cloud.export.csv")}),e.jsx(A,{type:"button",variant:p?"secondary":"ghost",size:"sm",className:`${de} ${p?"!min-h-8 !h-8":""}`,disabled:E,onClick:()=>oe("json"),children:a("cloud.export.json")})]})]}),E?e.jsx("p",{role:"status",className:"mt-2 text-xs text-oai-gray-600 dark:text-oai-gray-300",children:a("cloud.export.busy")}):null,C?e.jsx("p",{role:"alert",className:"mt-2 text-xs text-red-700 dark:text-red-300",children:C}):null,S?e.jsx("p",{role:"status",className:"mt-2 text-xs text-oai-gray-600 dark:text-oai-gray-300",children:S}):null]})),p?e.jsx($e,{open:N,onOpenChange:W,title:a("cloud.export.open"),icon:Ie,children:ue}):e.jsxs("section",{className:i&&!p?"tt-cloud-theme contents":"tt-cloud-theme","aria-label":a("cloud.export.open"),children:[e.jsxs(A,{type:"button",variant:"ghost",size:"sm",className:`${de} ${p?"!h-11 !w-full !justify-start !px-0 !text-oai-black dark:!text-oai-white active:!scale-100":i?"!h-10 !px-0":""}`,"aria-expanded":N,"aria-controls":te,onClick:()=>f(I=>!I),children:[e.jsx(Ie,{className:`${p?"mr-3":"mr-2"} h-4 w-4 shrink-0`,"aria-hidden":"true"}),a("cloud.export.open"),p?e.jsx(Re,{size:16,className:`ml-auto shrink-0 transition-transform motion-reduce:transition-none ${N?"rotate-180":""}`,"aria-hidden":!0}):null]}),!p&&c&&ue?gt.createPortal(ue,c):ue]})}function bn({text:t,label:s}){const[n,r]=o.useState(!1);return e.jsxs(bs,{open:n,onOpenChange:r,children:[e.jsx(ys,{delay:0,closeOnClick:!1,"aria-label":s,onClick:()=>r(!0),className:"inline-flex size-8 shrink-0 items-center justify-center rounded-md text-oai-gray-400 transition-colors hover:bg-oai-gray-100 hover:text-oai-gray-700 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-gray-500/40 dark:hover:bg-oai-gray-800 dark:hover:text-oai-gray-200",children:e.jsx(jt,{size:14,"aria-hidden":!0})}),e.jsx(vs,{children:e.jsx(js,{side:"bottom",sideOffset:6,className:"z-[110]",children:e.jsx(ks,{role:"tooltip",className:"max-w-[min(320px,calc(100vw-2rem))] rounded-lg border border-oai-gray-200 bg-white px-3 py-2 text-xs leading-5 text-oai-gray-600 shadow-lg dark:border-oai-gray-700 dark:bg-oai-gray-900 dark:text-oai-gray-300",children:t})})})]})}function yn(t){return typeof t!="string"||!t.trim()?a("cloud.devices.platform_unknown"):/^(mac|darwin)/i.test(t)?a("leaderboard.community.modal.platform.darwin"):/^win/i.test(t)?a("leaderboard.community.modal.platform.win32"):/^linux/i.test(t)?a("leaderboard.community.modal.platform.linux"):t}function vn(t,s){if(!t)return null;const n=t.status==="active"&&t.access_source==="gift";if(s&&Number.isFinite(Date.parse(s))){const r=t.status==="transition"?"cloud.membership.transition_until":t.status==="trial"?"cloud.membership.trial_until":t.status==="active"?n?"cloud.membership.gift_until":"cloud.membership.active_until":t.status==="expired"&&Date.parse(s)<=Date.now()?"cloud.membership.expired_on":null;if(r)return a(r,{date:H(s)})}return n?a("cloud.gift.membership_label"):Ae(t.status)}function jn({auth:t,machineLimit:s,accountRevision:n,selfHosted:r=!1}){const[i,c]=o.useState(null),[g,l]=o.useState(null),[d,p]=o.useState(null),[h,m]=o.useState(!1),[j,w]=o.useState(null),x=o.useRef(!1),_=o.useRef(0),b=o.useRef(!0),u=t?.user?.id,y=t?.getAccessToken,k=o.useCallback(async()=>{const S=++_.current;try{let P;if(dt())try{const G=await ia(),J=await fetch("/functions/tokentracker-machine-id",{headers:G});J.ok&&(P=(await J.json())?.machineId)}catch{}const M=await ce("devices",{auth:y,params:P?{current_machine_id:P}:{}});S===_.current&&(c(M),l(null))}catch(P){S===_.current&&l({...P,code:"billing_devices_unavailable"})}},[y,u]);o.useEffect(()=>(b.current=!0,k(),()=>{b.current=!1,_.current+=1}),[k,n]);const f=async S=>{if(!x.current){x.current=!0,m(!0),l(null),w(null);try{if(await ce("remove-device",{auth:y,body:{machine_id:S}}),!b.current)return;i?.machines?.find(P=>P.machine_id===S)?.is_current&&We(),p(null),await k()}catch(P){b.current&&l(P)}finally{x.current=!1,m(!1)}}},N=async S=>{if(!x.current){x.current=!0,m(!0),l(null),w(null);try{if(await ce("resume-device",{auth:y,body:{machine_id:S.machine_id}}),!b.current)return;S.is_current&&We(),w(a("cloud.devices.resumed")),await k()}catch(P){b.current&&l(P)}finally{x.current=!1,m(!1)}}},E=i?.machines||[],v=i?.machine_count??E.filter(S=>S.status!=="paused").length,C=i?.machine_limit??s,O=C==null||v<C;return e.jsxs("div",{children:[e.jsxs("div",{className:"mb-1 flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-1",children:[e.jsx("h3",{className:"text-sm font-semibold",children:a("cloud.devices.title")}),e.jsx(bn,{label:a("cloud.devices.detail"),text:a("cloud.devices.detail")})]}),e.jsx("span",{className:"text-xs text-oai-gray-500 dark:text-oai-gray-400 tabular-nums",children:i?C==null?a(r?"cloud.devices.unlimited_self_hosted":"cloud.devices.unlimited",{count:v}):a("cloud.devices.count",{count:v,limit:C}):g?a("cloud.devices.count_unknown"):a("cloud.catalog.loading")})]}),i?.over_machine_limit||C!=null&&C<v?e.jsx("div",{className:"mb-4",children:e.jsx(ee,{children:a("cloud.devices.over_limit")})}):null,g?e.jsx(ee,{error:g,onRetry:k,context:"account"}):null,j?e.jsx("div",{className:"mb-3",children:e.jsx(ee,{children:j})}):null,!g&&i&&E.length===0?e.jsx("p",{className:"text-sm text-oai-gray-500 dark:text-oai-gray-400",children:a("cloud.devices.empty")}):null,E.length!==0?e.jsx("ul",{className:"divide-y divide-oai-gray-200 dark:divide-oai-gray-800",children:E.map(S=>e.jsxs("li",{className:"py-1.5",children:[e.jsxs("div",{className:"grid grid-cols-[17px_minmax(0,1fr)_auto] items-center gap-x-3 gap-y-1",children:[e.jsx(Ue,{size:17,className:"col-start-1 row-start-1 text-oai-gray-500 dark:text-oai-gray-400","aria-hidden":!0}),e.jsx("p",{title:S.name||a("cloud.devices.unnamed"),className:"col-start-2 row-start-1 min-w-0 truncate text-sm font-medium",children:S.name||a("cloud.devices.unnamed")}),e.jsxs("div",{className:"col-span-2 col-start-2 row-start-2 flex min-w-0 flex-wrap items-center gap-x-2 gap-y-1 text-xs text-oai-gray-500 dark:text-oai-gray-400 sm:col-span-1 sm:col-start-2",children:[e.jsx("span",{children:yn(S.platform)}),e.jsx("span",{"aria-hidden":!0,children:"·"}),e.jsx("span",{children:S.last_seen_at?a("cloud.devices.last_seen",{date:ra(S.last_seen_at)}):a("cloud.devices.last_seen_unknown")}),S.is_current?e.jsxs(e.Fragment,{children:[e.jsx("span",{"aria-hidden":!0,children:"·"}),e.jsx("span",{children:a("cloud.devices.current")})]}):null,S.status==="paused"?e.jsxs(e.Fragment,{children:[e.jsx("span",{"aria-hidden":!0,children:"·"}),e.jsx("span",{children:a("cloud.devices.paused")})]}):null]}),S.status==="paused"&&!O?e.jsx("p",{className:"col-start-2 row-start-3 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:a("cloud.devices.no_slot")}):null,e.jsxs(A,{variant:"ghost",size:"sm",className:"col-start-3 row-start-1 !min-h-10 !px-2 sm:row-span-2","aria-expanded":S.status!=="paused"?d===S.machine_id:void 0,"aria-controls":d===S.machine_id?`cloud-machine-confirm-${S.machine_id}`:void 0,onClick:()=>S.status==="paused"?N(S):p(P=>P===S.machine_id?null:S.machine_id),disabled:h||S.status==="paused"&&!O,children:[S.status==="paused"?e.jsx(fs,{size:14,className:"mr-1.5 shrink-0","aria-hidden":!0}):e.jsx(xs,{size:14,className:"mr-1.5 shrink-0","aria-hidden":!0}),S.status==="paused"?a("cloud.devices.resume"):a("cloud.devices.remove")]})]}),d===S.machine_id?e.jsxs("div",{id:`cloud-machine-confirm-${S.machine_id}`,className:"mt-3 rounded-lg bg-oai-gray-50 p-3 dark:bg-oai-gray-800",children:[e.jsx("p",{className:"text-xs leading-5",children:a("cloud.devices.remove_detail")}),e.jsxs("div",{className:"mt-3 flex gap-2",children:[e.jsx(A,{variant:"secondary",onClick:()=>f(S.machine_id),disabled:h,children:a("cloud.devices.confirm_remove")}),e.jsx(A,{variant:"ghost",onClick:()=>p(null),disabled:h,children:a("cloud.action.keep")})]})]}):null]},S.machine_id))}):null]})}function kn({recent:t,pendingOrders:s,conflictOrders:n,userId:r,payments:i=[],footerActions:c}){const g=ht(),[l,d]=o.useState(t?.order_id&&Ce.test(t.order_id)?t.order_id:""),[p,h]=o.useState(!1),[m,j]=o.useState(!1),w=o.useId(),x=o.useRef(null);o.useEffect(()=>{m&&x.current?.focus()},[m]);const _=new Set([...i.map(u=>u.order_id).filter(u=>typeof u=="string"),...(s||[]).filter(u=>u.status==="paid"||["paid","partially_refunded","refunded"].includes(u.payment_state)).map(u=>u.id)].map(u=>u.toLowerCase())),b=[...n||[],...(s||[]).filter(u=>u.retry_payment_conflict_at||!_.has(u.id.toLowerCase()))].filter((u,y,k)=>k.findIndex(f=>f.id===u.id)===y);return e.jsxs("div",{className:"mt-2 space-y-3",children:[t?.request_id&&!t.order_id?e.jsx(ye,{to:`/billing/checkout?sku=${encodeURIComponent(t.sku)}`,className:"mt-3 inline-flex min-h-10 items-center text-sm text-oai-brand underline underline-offset-4",children:a("cloud.action.resume_purchase")}):null,b.length||i.length?e.jsxs("div",{className:"sm:grid sm:grid-cols-[minmax(0,1fr)_auto_minmax(7rem,auto)] sm:gap-x-4",children:[e.jsxs("div",{"aria-hidden":!0,className:"hidden gap-x-4 pb-1 text-xs text-oai-gray-500 dark:text-oai-gray-400 sm:col-span-3 sm:grid sm:grid-cols-subgrid",children:[e.jsx("span",{children:a("cloud.history.date")}),e.jsx("span",{className:"text-right",children:a("cloud.history.amount")}),e.jsx("span",{className:"text-right",children:a("cloud.history.status")})]}),e.jsxs("ul",{className:"divide-y divide-oai-gray-200 dark:divide-oai-gray-800 sm:col-span-3 sm:grid sm:grid-cols-subgrid",children:[b.map(u=>{const y=typeof u.created_at=="string"&&Number.isFinite(Date.parse(u.created_at))?H(u.created_at):null;let k=null;Number.isInteger(u.amount_cents)&&u.amount_cents>=0&&["USD","CNY"].includes(u.currency)&&(k=Le(u.amount_cents,u.currency));const f=a(u.retry_payment_conflict_at?"cloud.action.review_duplicate_payment":"cloud.history.pending");return e.jsxs("li",{className:"grid grid-cols-[minmax(0,1fr)_auto] items-center gap-x-4 gap-y-1 py-3 sm:col-span-3 sm:grid-cols-subgrid",children:[e.jsx("p",{className:"col-start-1 row-start-1 text-sm tabular-nums",children:y||f}),e.jsx("p",{className:"col-start-2 row-start-1 text-right text-sm font-medium tabular-nums",children:k}),u.provider||y?e.jsxs("div",{className:"col-start-1 row-start-2 flex min-w-0 flex-wrap items-center gap-x-2 gap-y-1 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:[u.provider?e.jsx("span",{children:ft(u.provider)}):null,y?e.jsxs(e.Fragment,{children:[u.provider?e.jsx("span",{"aria-hidden":!0,children:"·"}):null,e.jsx("span",{children:f})]}):null]}):null,e.jsx(ye,{to:`/billing/checkout?order=${encodeURIComponent(u.id)}`,onClick:N=>{u.retry_payment_conflict_at||N.button!==0||N.metaKey||N.ctrlKey||N.shiftKey||N.altKey||!Ce.test(u.id)||(N.preventDefault(),g(Ke({orderId:u.id,userId:r})))},className:"col-start-2 row-start-2 inline-flex min-h-10 items-center justify-end rounded-sm text-right text-sm underline-offset-4 hover:underline focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 sm:col-start-3 sm:row-span-2 sm:row-start-1 sm:self-start sm:items-start",children:e.jsx("span",{children:u.retry_payment_conflict_at?a("cloud.action.review_duplicate_payment"):a("cloud.action.resume_order")})})]},u.id)}),e.jsx(_n,{payments:i})]})]}):e.jsx(e.Fragment,{children:(!t?.request_id||t.order_id)&&e.jsx("p",{className:"py-2 text-sm text-oai-gray-500 dark:text-oai-gray-400",children:a("cloud.history.empty")})}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-x-4 gap-y-1",children:[e.jsx(A,{variant:"ghost",size:"sm",className:"!h-10 !px-0","aria-expanded":m,"aria-controls":`${w}-panel`,onClick:()=>j(u=>!u),children:a("cloud.restore.title")}),c]}),m?e.jsxs("div",{id:`${w}-panel`,className:"mt-2",children:[e.jsx("p",{className:"text-xs leading-5 text-oai-gray-500 dark:text-oai-gray-400",children:a("cloud.restore.detail")}),e.jsxs("form",{className:"mt-4",onSubmit:u=>{if(u.preventDefault(),!Ce.test(l.trim())){h(!0);return}const y=l.trim(),k=b.some(f=>f.id.toLowerCase()===y.toLowerCase()&&f.retry_payment_conflict_at);g(k?`/billing/checkout?order=${encodeURIComponent(y)}`:Ke({orderId:y,userId:r}))},children:[e.jsx("label",{htmlFor:`${w}-input`,className:"text-xs text-oai-gray-500 dark:text-oai-gray-400",children:a("cloud.checkout.order_id")}),e.jsxs("div",{className:"mt-2 flex flex-col gap-2 sm:flex-row",children:[e.jsx("input",{id:`${w}-input`,ref:x,value:l,onChange:u=>{d(u.target.value),h(!1)},placeholder:a("cloud.restore.placeholder"),className:"min-h-10 min-w-0 flex-1 rounded-md border border-oai-gray-300 bg-transparent px-3 text-sm outline-none focus:border-oai-brand focus:ring-2 focus:ring-inset focus:ring-oai-brand/30 dark:border-oai-gray-700","aria-invalid":p,"aria-describedby":p?`${w}-error`:void 0}),e.jsx(A,{type:"submit",variant:"secondary",children:a("cloud.action.restore")})]}),p?e.jsx("p",{id:`${w}-error`,role:"alert",className:"mt-2 text-xs text-red-600 dark:text-red-400",children:a("cloud.restore.invalid")}):null]})]}):null]})]})}function _n({payments:t}){return e.jsx(e.Fragment,{children:t.map(s=>e.jsxs("li",{className:"grid grid-cols-[minmax(0,1fr)_auto] items-center gap-x-4 gap-y-1 py-3 sm:col-span-3 sm:grid-cols-subgrid",children:[e.jsx("p",{className:"col-start-1 row-start-1 text-sm tabular-nums",children:H(s.paid_at)}),e.jsx("p",{className:"col-start-2 row-start-1 text-right text-sm font-medium tabular-nums",children:Le(s.amount_cents,s.currency)}),e.jsxs("div",{className:"col-start-1 row-start-2 flex min-w-0 flex-wrap items-center gap-x-2 gap-y-1 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:[e.jsx("span",{children:ft(s.provider)}),e.jsx("span",{"aria-hidden":!0,children:"·"}),e.jsx("span",{children:a("cloud.history.term",{start:H(s.starts_at),end:H(s.ends_at)})})]}),e.jsx("p",{className:`col-start-2 row-start-2 text-right text-sm font-medium sm:col-start-3 sm:row-span-1 sm:row-start-1 sm:self-start ${s.refunded_cents>0?"text-amber-700 dark:text-amber-400":"text-oai-gray-600 dark:text-oai-gray-300"}`,children:s.refunded_cents>0?a("cloud.history.refunded",{amount:Le(s.refunded_cents,s.currency)}):a("cloud.history.paid")})]},s.id))})}function wn({showTitle:t=!0,heading:s,syncControl:n,active:r=!0}){const i=aa();return e.jsx(Nn,{showTitle:t,heading:s,syncControl:n,active:r,...i},i.auth?.signedIn?i.auth.user?.id:"signed-out")}function Nn({account:t,auth:s,loading:n,error:r,refresh:i,showTitle:c,heading:g,syncControl:l,active:d=!0}){const{openLoginModal:p}=ut(),[h,m]=o.useState(null),[j,w]=o.useState(null),[x,_]=o.useState(!1),[b,u]=o.useState(null),y=o.useRef(!1),k=o.useRef(!0);o.useEffect(()=>{d||m(null)},[d]),o.useEffect(()=>(k.current=!0,()=>{k.current=!1}),[]);const f=t?.membership,N=f?.status==="self_hosted"||f?.hosting_mode==="self_hosted",E=[...t?.conflict_orders||[],...t?.pending_orders||[]].some(L=>L.retry_payment_conflict_at),v=!N&&t?.subscriptions?.find(L=>["active","trialing","past_due","paused","canceling"].includes(L.status)),C=!N&&(v?v.provider==="waffo":t?.payments?.some(L=>L.provider==="waffo")),O=v&&!v.cancel_at_period_end&&v.status!=="canceling",S=O&&v.status!=="paused",P=v?.next_billed_at,M=P&&Number.isFinite(Date.parse(P));o.useEffect(()=>{b&&t&&!O&&(u(null),w(null))},[t,b,O]);const G=N?null:f?.status==="trial"?f.trial_ends_at:f?.status==="transition"?f.transition_ends_at:f?.expires_at,J=async L=>{if(!y.current){y.current=!0,_(!0),w(null);try{await L()}catch(T){k.current&&w(T)}finally{y.current=!1,_(!1)}}},V=()=>J(async()=>{const L=await ce("portal",{auth:s.getAccessToken,body:v?{subscription_id:v.provider_subscription_id}:{}});k.current&&await Wa(L.url||L.portal_url)}),te=()=>J(async()=>{await ce("cancel",{auth:s.getAccessToken,body:{subscription_id:b}}),k.current&&(u(null),await i())}),$=vn(f,G),F=f?.status==="active"&&f?.access_source==="gift",K=C&&!v||f?.can_read_cloud||!N&&t?.gift_redemption_available===!0;if(!s?.signedIn)return e.jsx("div",{className:"space-y-4",children:e.jsx(Z,{title:g||(c?a("cloud.membership.title"):a("settings.section.cloud")),children:e.jsxs("div",{className:"flex flex-col gap-3 py-3 sm:flex-row sm:items-center sm:justify-between sm:gap-4",children:[e.jsx("p",{className:"text-sm text-oai-gray-500 dark:text-oai-gray-400",children:a("cloud.membership.signed_out")}),e.jsx(A,{variant:"primary",size:"sm",onClick:()=>p({subtitle:a("cloud.membership.signed_out")}),children:a("cloud.action.sign_in_continue")})]})})});const q=g||(c?a("cloud.membership.title"):a("settings.section.cloud"));return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("section",{"aria-label":a("cloud.membership.title"),className:"tt-cloud-theme space-y-3",children:[t?.environment==="sandbox"?e.jsx(ee,{children:a("cloud.catalog.sandbox")}):null,E?e.jsx(sa,{showBillingLink:!1}):null,e.jsxs(Z,{title:q,action:e.jsx(A,{onClick:i,variant:"ghost",size:"sm",className:"!h-8 !w-8 shrink-0 !p-0 text-oai-gray-500 hover:text-oai-black dark:text-oai-gray-400 dark:hover:text-white",disabled:n,"aria-label":a("cloud.action.refresh_membership"),children:e.jsx(De,{size:14,className:n?"motion-safe:animate-spin":void 0,"aria-hidden":!0})}),children:[e.jsx("div",{className:"pt-0.5 pb-2.5",children:F?e.jsxs("div",{className:"flex items-center gap-3.5",children:[e.jsx("div",{className:"flex h-11 w-11 shrink-0 items-center justify-center rounded-lg border border-oai-gray-200 bg-oai-gray-50 text-oai-gray-700 dark:border-oai-gray-800 dark:bg-oai-gray-800/60 dark:text-oai-gray-300",children:e.jsx(Te,{className:"h-[30px] w-[30px]","aria-hidden":!0})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"text-sm font-semibold text-oai-black dark:text-white",children:a("cloud.gift.membership_label")}),e.jsxs("span",{className:"inline-flex items-center gap-1.5 rounded-full border border-oai-gray-200 bg-oai-gray-50 px-2 py-0.5 text-[11px] font-medium text-oai-gray-700 dark:border-oai-gray-800 dark:bg-oai-gray-800/60 dark:text-oai-gray-300",children:[e.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-emerald-500 dark:bg-emerald-400"}),a("cloud.gift.state_active")]})]}),$&&$!==a("cloud.gift.membership_label")?e.jsx("p",{className:"mt-1 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:$}):null]})]}):e.jsxs("div",{className:"flex items-center gap-3.5",children:[e.jsx("div",{className:"flex h-11 w-11 shrink-0 items-center justify-center rounded-lg border border-oai-gray-200 bg-oai-gray-50 text-oai-gray-700 dark:border-oai-gray-800 dark:bg-oai-gray-800/60 dark:text-oai-gray-300",children:e.jsx(fe,{className:"h-[30px] w-[30px]","aria-hidden":!0})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"text-sm font-semibold text-oai-black dark:text-white",children:Ae(f?.status)}),f?.status==="active"?e.jsxs("span",{className:"inline-flex items-center gap-1.5 rounded-full border border-oai-gray-200 bg-oai-gray-50 px-2 py-0.5 text-[11px] font-medium text-oai-gray-700 dark:border-oai-gray-800 dark:bg-oai-gray-800/60 dark:text-oai-gray-300",children:[e.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-emerald-500 dark:bg-emerald-400"}),a("cloud.gift.state_active")]}):null]}),$&&$!==Ae(f?.status)?e.jsx("p",{className:"mt-1 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:$}):null]})]})}),f?.status==="expired"?e.jsx("p",{className:"py-2.5 text-xs leading-5 text-oai-gray-500 dark:text-oai-gray-400",children:f.can_read_cloud?a("cloud.membership.read_only",{date:H(f.read_only_until)}):a("cloud.membership.expired_detail")}):null,f?e.jsx(na,{userId:s.user?.id,membership:f,subscriptions:t?.subscriptions,className:"py-2.5"}):null,!f&&n?e.jsx("p",{role:"status",className:"py-2.5 text-sm text-oai-gray-500 dark:text-oai-gray-400",children:a("cloud.catalog.loading")}):null,v?e.jsx("div",{className:"flex flex-wrap items-center justify-between gap-3 py-2.5",children:e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-x-3 gap-y-1",children:[e.jsx("p",{className:"text-xs leading-5 text-oai-gray-500 dark:text-oai-gray-400",children:v.status==="paused"?a("cloud.membership.renewal_paused"):v.status==="past_due"?a("cloud.membership.payment_due"):S?M?a("cloud.membership.renews",{date:H(P)}):a("cloud.membership.renewal_unknown"):a("cloud.membership.renewal_off")}),O?e.jsx(A,{"aria-expanded":!!b,"aria-controls":b?"cloud-cancel-confirm":void 0,onClick:()=>u(L=>L===v.provider_subscription_id?null:v.provider_subscription_id),variant:"ghost",size:"sm",className:"!h-8 !px-2 text-xs",disabled:x,children:a("cloud.action.cancel_renewal")}):null]})}):null,b?e.jsxs("div",{id:"cloud-cancel-confirm",className:"my-3 rounded-lg border border-oai-gray-200 p-4 dark:border-oai-gray-800",children:[e.jsx("p",{className:"text-sm leading-6",children:G?a("cloud.cancel.detail",{date:H(G)}):a("cloud.cancel.no_term")}),e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2",children:[e.jsx(A,{onClick:te,variant:"secondary",disabled:x,children:a("cloud.cancel.confirm")}),e.jsx(A,{onClick:()=>u(null),variant:"ghost",disabled:x,children:a("cloud.action.keep")})]})]}):null,r?e.jsx("div",{className:"py-2.5",children:e.jsx(ee,{error:r,onRetry:i,context:"account"})}):null,j&&h!=="billing"?e.jsx("div",{className:"py-2.5",children:e.jsx(ee,{error:j,context:"account"})}):null]})]}),f?e.jsx(st,{className:"tt-cloud-theme !rounded-lg",bodyClassName:"!py-3",children:e.jsx(jn,{auth:s,machineLimit:f.machine_limit,accountRevision:t,selfHosted:N})}):null,K||t&&!N||l?e.jsx(st,{className:"tt-cloud-theme !rounded-lg",bodyClassName:"!py-2",children:e.jsxs("section",{"aria-label":a("cloud.membership.tools_title"),className:"divide-y divide-oai-gray-200 dark:divide-oai-gray-800",children:[N?null:v?e.jsxs("button",{type:"button",onClick:V,disabled:x,className:"inline-flex h-11 w-full items-center gap-3 rounded-md border-0 bg-transparent p-0 text-left text-sm font-medium text-oai-black transition-colors hover:bg-oai-gray-100 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-oai-gray-500 disabled:opacity-50 dark:text-oai-white dark:hover:bg-oai-gray-800",children:[e.jsx(fe,{size:16,className:"shrink-0","aria-hidden":!0}),e.jsx("span",{className:"min-w-0 flex-1",children:a("cloud.action.manage_subscription")}),e.jsx(nt,{size:16,className:"shrink-0 text-oai-gray-500 dark:text-oai-gray-400","aria-hidden":!0})]}):e.jsxs(ye,{to:"/cloud",className:"inline-flex h-11 w-full items-center gap-3 rounded-md border-0 bg-transparent p-0 text-left text-sm font-medium text-oai-black transition-colors hover:bg-oai-gray-100 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-oai-gray-500 dark:text-oai-white dark:hover:bg-oai-gray-800",children:[e.jsx(fe,{size:16,className:"shrink-0","aria-hidden":!0}),e.jsx("span",{className:"min-w-0 flex-1",children:a("cloud.action.subscribe")}),e.jsx(mt,{size:16,className:"shrink-0 text-oai-gray-500 dark:text-oai-gray-400","aria-hidden":!0})]}),t&&!N?e.jsxs($e,{open:h==="billing",onOpenChange:L=>m(L?"billing":null),title:a("cloud.billing.title"),icon:Cs,wide:!0,children:[j?e.jsx("div",{className:"mb-3",children:e.jsx(ee,{error:j,context:"account"})}):null,e.jsx(kn,{userId:s.user?.id,recent:Ka(s.user?.id),pendingOrders:t?.pending_orders,conflictOrders:t?.conflict_orders,payments:t.payments,footerActions:C&&!v?e.jsx("div",{className:"flex items-center gap-0.5",children:e.jsxs(A,{onClick:V,variant:"ghost",size:"sm",className:"!h-10 !px-0",disabled:x,children:[a("cloud.action.view_bills"),e.jsx(nt,{size:14,className:"ml-2","aria-hidden":!0})]})}):null})]}):null,f?.can_read_cloud?e.jsx(xn,{auth:s,layout:"settings-row",dialogOpen:h==="export",onDialogOpenChange:L=>m(L?"export":null)}):null,e.jsx(dn,{account:t,auth:s,refresh:i,layout:"settings-row",dialogOpen:h==="redeem",onDialogOpenChange:L=>m(L?"redeem":null)}),l?e.jsx("section",{children:l}):null]})}):null]})}function Sn({settings:t,active:s=!0}={}){return t?e.jsx(Tt,{settings:t,active:s}):e.jsx(Cn,{active:s})}function Cn({active:t}){const s=Me();return e.jsx(Tt,{settings:s,active:t})}function Tt({settings:t,active:s}){return e.jsx(wn,{showTitle:!1,active:s,syncControl:t.showLocalCloudSync?e.jsx(En,{settings:t}):null})}function En({settings:t}){return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex min-h-11 items-center justify-between gap-3",children:[e.jsxs("span",{className:"inline-flex min-w-0 items-center gap-3 text-sm font-medium",children:[e.jsx(De,{size:16,className:"shrink-0","aria-hidden":!0}),a("settings.account.cloudSync")]}),e.jsx("span",{className:"tt-cloud-theme tt-cloud-sync-control inline-flex","aria-busy":t.cloudSyncPending||void 0,children:e.jsx(z,{checked:t.cloudSyncOn,disabled:t.cloudSyncPending,onChange:()=>(t.cloudSyncOn?Ye(t.userId):oa(t.userId,"sync"),t.handleCloudSyncToggle()),ariaLabel:a("settings.account.cloudSync")})})]}),t.cloudSyncOn&&t.cloudSyncPending?e.jsxs("p",{role:"status",className:"flex items-center gap-2 py-3 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:[e.jsx(xe,{size:14,className:"motion-safe:animate-spin","aria-hidden":!0}),a("settings.account.cloudSyncPending")]}):null,t.cloudSyncOn&&t.cloudSyncError&&!t.cloudSyncPending?e.jsx("div",{className:"tt-cloud-theme py-3",children:e.jsx(ee,{role:"alert",onRetry:t.handleCloudSyncRetry,children:a("settings.account.cloudSyncError")})}):null,e.jsx(la,{userId:t.userId,panel:"sync",localHost:!0,className:"py-3",onContinueLocal:()=>{Ye(t.userId),t.cloudSyncOn&&t.handleCloudSyncDisable()}})]})}function Pn(){return[{value:"light",label:a("settings.appearance.theme.light"),Icon:da},{value:"dark",label:a("settings.appearance.theme.dark"),Icon:ua},{value:"system",label:a("settings.appearance.theme.system"),Icon:Ue}]}function On(){return[{value:pa,label:a("settings.appearance.language.system")},{value:ha,label:a("settings.appearance.language.english")},{value:fa,label:a("settings.appearance.language.chinese")},{value:xa,label:a("settings.appearance.language.traditional_chinese")},{value:ba,label:a("settings.appearance.language.japanese")},{value:ya,label:a("settings.appearance.language.korean")},{value:va,label:a("settings.appearance.language.german")}]}function An(t){if(!t)return null;try{const s=new Date(t);return Number.isNaN(s.getTime())?null:s.toLocaleString()}catch{return null}}function Ln(t,s){const n=a(`settings.appearance.currency.rate_source.${t}`),r=An(s),i=r?a("settings.appearance.currency.rate_updated",{when:r}):a("settings.appearance.currency.rate_never");return`${n} · ${i}`}function Tn({locale:t,setLocale:s}){const n=On();return e.jsx(ze,{value:t,onValueChange:s,options:n,ariaLabel:a("settings.appearance.language.label"),className:"px-2.5 py-1.5 text-xs font-medium",leadingIcon:e.jsx(Os,{className:"h-3.5 w-3.5 text-oai-gray-500 dark:text-oai-gray-400","aria-hidden":!0})})}function Rn({currency:t,setCurrency:s}){const n=ma().map(r=>({value:r.code,label:a(r.labelKey)}));return e.jsx(ze,{value:t,onValueChange:s,options:n,ariaLabel:a("settings.appearance.currency.label"),className:"px-3 py-1.5 text-xs font-medium"})}function In({currency:t,rate:s,rateSource:n,rateFetchedAt:r}){if(t===ga)return e.jsx(e.Fragment,{children:a("settings.appearance.currency.hint")});const i=Ln(n,r);return e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx("span",{children:`1 USD = ${s.toFixed(4)} ${t}`}),e.jsx("span",{role:"img","aria-label":i,title:i,className:"inline-flex h-4 w-4 cursor-help items-center justify-center text-oai-gray-400 hover:text-oai-gray-600 dark:text-oai-gray-500 dark:hover:text-oai-gray-300",children:e.jsx(jt,{className:"h-3.5 w-3.5","aria-hidden":!0})})]})}function Dn(){const{theme:t,setTheme:s}=ca(),{locale:n,setLocale:r}=xt(),{currency:i,rate:c,rateSource:g,rateFetchedAt:l,setCurrency:d}=_s(),{mode:p,setMode:h,unitSystem:m,setUnitSystem:j,grouping:w,setGrouping:x}=ws();return e.jsxs(Z,{title:a("settings.section.appearance"),children:[e.jsx(R,{label:a("settings.appearance.theme.label"),hint:a("settings.appearance.theme.hint"),control:e.jsx(se,{options:Pn(),value:t,onChange:s})}),e.jsx(R,{label:a("settings.appearance.language.label"),hint:a("settings.appearance.language.hint"),control:e.jsx(Tn,{locale:n,setLocale:r})}),e.jsx(R,{label:a("settings.appearance.currency.label"),hint:e.jsx(In,{currency:i,rate:c,rateSource:g,rateFetchedAt:l}),control:e.jsx(Rn,{currency:i,setCurrency:d})}),e.jsx(R,{label:a("settings.appearance.token_format.label"),hint:a("settings.appearance.token_format.hint"),control:e.jsx(se,{options:[{value:Se.COMPACT,label:a("settings.appearance.token_format.compact")},{value:Se.FULL,label:a("settings.appearance.token_format.full")}],value:p,onChange:h})}),e.jsx(R,{label:a("settings.appearance.token_unit.label"),hint:a("settings.appearance.token_unit.hint"),control:e.jsx(se,{disabled:p!==Se.COMPACT,options:[{value:Ze.ENGLISH,label:a("settings.appearance.token_unit.english")},{value:Ze.CHINESE,label:a("settings.appearance.token_unit.chinese")}],value:m,onChange:j})}),e.jsx(R,{label:a("settings.appearance.token_grouping.label"),hint:a("settings.appearance.token_grouping.hint"),control:e.jsx(se,{options:[{value:Je.THOUSAND,label:a("settings.appearance.token_grouping.thousand")},{value:Je.WAN,label:a("settings.appearance.token_grouping.wan")}],value:w,onChange:x})})]})}function Ee({labelKey:t}){return e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{children:a(t)}),e.jsx("span",{className:"px-1.5 py-0.5 text-[8px] font-semibold tracking-wider text-oai-gray-500 bg-oai-gray-100 dark:text-oai-gray-400 dark:bg-oai-gray-800/80 rounded uppercase scale-90 origin-left",children:a("qpd.card.badge")})]})}function Un(){const{enabled:t,toggle:s}=Fa(),{enabled:n,toggle:r}=Ba(),{available:i,settings:c,setSetting:g}=je(),l=i&&!!c?.dynamicIslandSupported,d=!!c?.dynamicIslandEnabled;return e.jsxs(Z,{title:a("settings.section.labs"),children:[l&&e.jsxs(e.Fragment,{children:[e.jsx(R,{label:e.jsx(Ee,{labelKey:"settings.labs.island.label"}),hint:a("settings.labs.island.hint"),control:e.jsx(z,{checked:d,onChange:()=>g("dynamicIslandEnabled",!d),ariaLabel:a("settings.labs.island.aria")})}),d&&e.jsx(R,{label:a("settings.labs.island_hide_menubar.label"),hint:a("settings.labs.island_hide_menubar.hint"),control:e.jsx(z,{checked:!!c?.hideMenuBarIcon,onChange:()=>g("hideMenuBarIcon",!c?.hideMenuBarIcon),ariaLabel:a("settings.labs.island_hide_menubar.aria")})})]}),e.jsx(R,{label:e.jsx(Ee,{labelKey:"settings.labs.qpd.label"}),hint:a("settings.labs.qpd.hint"),control:e.jsx(z,{checked:t,onChange:s,ariaLabel:a("settings.labs.qpd.aria")})}),e.jsx(R,{label:e.jsx(Ee,{labelKey:"settings.labs.sessions.label"}),hint:a("settings.labs.sessions.hint"),control:e.jsx(z,{checked:n,onChange:r,ariaLabel:a("settings.labs.sessions.aria")})})]})}function zn(){const{available:t,settings:s,setSetting:n,runAction:r}=je();if(!t)return null;const i=bt(),c=!!s?.launchAtLogin,g=s?.toastOnReset!==!1,l=s?.confettiOnReset!==!1,d=s?.launchAtLoginSupported!==!1,p=s?.autoUpdateEnabled!==!1,h=s?.updateStatus||null,m=!!s?.updateBusy,j=!!s?.isSyncing;return e.jsxs(Z,{title:a("settings.section.menubar"),children:[i?null:e.jsxs(e.Fragment,{children:[e.jsx(R,{label:a("settings.menubar.appearance"),hint:a("settings.menubar.appearanceHint"),control:e.jsxs(A,{as:ye,to:"/widgets",variant:"secondary",size:"sm",className:"gap-1.5 no-underline",children:[e.jsx("span",{children:a("settings.menubar.appearanceLink")}),e.jsx(Ss,{className:"h-3.5 w-3.5","aria-hidden":!0})]})}),e.jsx(R,{label:a("settings.menubar.toastOnReset"),hint:a("settings.menubar.toastOnResetHint"),control:e.jsx(z,{checked:g,onChange:()=>n("toastOnReset",!g),ariaLabel:a("settings.menubar.toastOnReset")})}),e.jsx(R,{label:a("settings.menubar.confettiOnReset"),hint:a("settings.menubar.confettiOnResetHint"),control:e.jsx(z,{checked:l,onChange:()=>n("confettiOnReset",!l),ariaLabel:a("settings.menubar.confettiOnReset")})})]}),d?e.jsx(R,{label:a("settings.menubar.launchAtLogin"),hint:a("settings.menubar.launchAtLoginHint"),control:e.jsx(z,{checked:c,onChange:()=>n("launchAtLogin",!c),ariaLabel:a("settings.menubar.launchAtLogin")})}):null,e.jsx(R,{label:a("settings.menubar.syncNow"),hint:a("settings.menubar.syncNowHint"),control:e.jsxs(A,{variant:"secondary",size:"sm",onClick:()=>r("syncNow"),disabled:j,className:"gap-1.5",children:[e.jsx(De,{className:le("h-3.5 w-3.5",j&&"animate-spin"),"aria-hidden":!0}),e.jsx("span",{children:j?a("settings.menubar.syncing"):a("settings.menubar.syncNow")})]})}),e.jsx(R,{label:a("settings.menubar.autoUpdate"),hint:a("settings.menubar.autoUpdateHint"),control:e.jsx(z,{checked:p,onChange:()=>n("autoUpdateEnabled",!p),ariaLabel:a("settings.menubar.autoUpdate")})}),e.jsx(R,{label:a("settings.menubar.updates"),hint:h||void 0,control:e.jsxs(A,{variant:"secondary",size:"sm",onClick:()=>r("checkForUpdates"),disabled:m,className:"gap-1.5",children:[e.jsx(Ie,{className:"h-3.5 w-3.5","aria-hidden":!0}),e.jsx("span",{children:a("settings.menubar.checkUpdates")})]})})]})}function Gn(t,s){function n(c){return c.replace(/^v/,"").split(".").map(Number)}const r=n(t),i=n(s);for(let c=0;c<Math.max(r.length,i.length);c++){const g=r[c]||0,l=i[c]||0;if(g<l)return!0;if(g>l)return!1}return!1}function Mn(){const{available:t,settings:s,runAction:n}=je(),r=t&&s?.version,i=s?.platform||"macos",[c,g]=Pe.useState(!1),[l,d]=Pe.useState({open:!1,latestVersion:"",htmlUrl:""}),{resolvedLocale:p}=xt(),h="1.3.10",m=async()=>{g(!0);try{const b=await fetch("https://api.github.com/repos/xiufengsun/TokenTracker/releases/latest");if(!b.ok)throw new Error("Failed to fetch");const u=await b.json(),y=u.tag_name;Gn(h,y)?d({open:!0,latestVersion:y,htmlUrl:u.html_url}):Xe({title:a("settings.menubar.updates.upToDate")})}catch(b){console.error("Check updates failed:",b),Xe({title:a("settings.menubar.updates.failed")})}finally{g(!1)}},j=a("settings.menubar.updates.modalTitle"),w=a("settings.menubar.updates.modalDescription",{version:l.latestVersion}),x=a("settings.menubar.updates.modalConfirm"),_=a("settings.menubar.updates.modalCancel");return e.jsxs("div",{className:"mt-6 flex flex-col items-center justify-center gap-4 text-xs text-oai-gray-500 dark:text-oai-gray-500",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-center gap-2",children:[r?e.jsxs(e.Fragment,{children:[e.jsx("span",{children:i==="windows"?a("settings.menubar.updates.footerCore",{version:s.version}):a("settings.menubar.updates.footerCombined",{barVersion:s.version,coreVersion:h})}),e.jsx("span",{"aria-hidden":!0,children:"·"}),e.jsx("button",{type:"button",onClick:()=>n("openAbout"),className:"underline-offset-2 transition-colors hover:text-oai-gray-700 hover:underline dark:hover:text-oai-gray-300",children:"GitHub"}),e.jsx("span",{"aria-hidden":!0,children:"·"})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{children:a("settings.menubar.updates.footerCore",{version:h})}),e.jsx("span",{"aria-hidden":!0,children:"·"}),e.jsx("button",{type:"button",onClick:m,disabled:c,className:"underline-offset-2 transition-colors hover:text-oai-gray-700 hover:underline dark:hover:text-oai-gray-300 disabled:opacity-50",children:c?a("settings.menubar.updates.checking"):a("settings.menubar.checkUpdates")}),e.jsx("span",{"aria-hidden":!0,children:"·"})]}),e.jsxs("a",{href:ja,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1.5 underline-offset-2 transition-colors hover:text-oai-gray-700 hover:underline dark:hover:text-oai-gray-300",children:[e.jsx(ka,{className:"h-3.5 w-3.5","aria-hidden":!0}),a("settings.footer.statusPage")]})]}),e.jsx(Ns,{open:l.open,title:j,description:w,confirmLabel:x,cancelLabel:_,onConfirm:()=>{window.open(l.htmlUrl,"_blank"),d(b=>({...b,open:!1}))},onCancel:()=>d(b=>({...b,open:!1}))})]})}const $n=()=>[{value:"system",label:a("settings.network.mode.system")},{value:"manual",label:a("settings.network.mode.manual")},{value:"off",label:a("settings.network.mode.off")}],Fn=()=>[{value:"http",label:a("settings.network.protocol.http")},{value:"https",label:a("settings.network.protocol.https")},{value:"socks5",label:a("settings.network.protocol.socks5")}];function rt(t){const s={},n=String(t.host||"").trim();(!n||/:\/\//.test(n)||n.includes("/"))&&(s.host=a("settings.network.error.host"));const r=String(t.port??"").trim(),i=Number(r);return(!r||!/^\d+$/.test(r)||!Number.isInteger(i)||i<1||i>65535)&&(s.port=a("settings.network.error.port")),s}function Bn({proxySettings:t}){const{config:s,save:n,testConnection:r}=t,[i,c]=o.useState(()=>({mode:s.mode,protocol:s.protocol||"http",host:s.host||"",port:s.port||""})),[g,l]=o.useState({}),[d,p]=o.useState(!1),[h,m]=o.useState(""),[j,w]=o.useState(null),[x,_]=o.useState(!1),[b,u]=o.useState(null);o.useEffect(()=>{c({mode:s.mode,protocol:s.protocol||"http",host:s.host||"",port:s.port||""})},[s.mode,s.protocol,s.host,s.port]);const y=o.useMemo(()=>s.effective==="manual"?a("settings.network.effective.manual"):s.effective==="env"?a("settings.network.effective.env"):s.effective==="system"?a("settings.network.effective.system"):s.effective==="blocked"?a("settings.network.effective.blocked"):a("settings.network.effective.none"),[s.effective]),k=o.useMemo(()=>i.mode!==s.mode?!0:i.mode==="manual"?(i.protocol||"http")!==(s.protocol||"http")||(i.host||"")!==(s.host||"")||String(i.port??"")!==String(s.port??""):!1,[i,s]),f=v=>{c(C=>({...C,...v})),l({}),m(""),w(null),u(null)},N=async()=>{if(i.mode==="manual"){const v=rt(i);if(Object.keys(v).length){l(v);return}}p(!0),m(""),w(null);try{await n(i),m("saved")}catch(v){m("error"),w(v)}finally{p(!1)}},E=async()=>{const v=rt(i);if(Object.keys(v).length){l(v);return}_(!0),u(null);try{const C=await r(i);u(C)}catch(C){u({ok:!1,error:C?.message||String(C)})}finally{_(!1)}};return e.jsxs(Z,{title:a("settings.section.network"),subtitle:y,children:[s.applyError?e.jsx("p",{role:"alert",className:"mb-3 text-xs text-red-600 dark:text-red-400",children:a("settings.network.apply_error",{error:s.applyError})}):null,e.jsx(R,{label:a("settings.network.mode.label"),hint:a("settings.network.mode.hint"),control:e.jsx(se,{options:$n(),value:i.mode,onChange:v=>f({mode:v})})}),e.jsx(vt,{initial:!1,children:i.mode==="manual"?e.jsxs(yt.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},transition:{height:{duration:.28,ease:[.22,1,.36,1]},opacity:{duration:.2,ease:[.22,1,.36,1]}},style:{overflow:"hidden"},className:"divide-y divide-oai-gray-200/60 dark:divide-oai-gray-800/60",children:[e.jsx(R,{label:a("settings.network.protocol.label"),control:e.jsx(ze,{value:i.protocol,onValueChange:v=>f({protocol:v}),options:Fn(),ariaLabel:a("settings.network.protocol.label"),className:"px-2.5 py-1.5 text-xs font-medium"})}),e.jsx(R,{label:a("settings.network.host.label"),hint:g.host,control:e.jsx("input",{type:"text",value:i.host,onChange:v=>f({host:v.target.value}),placeholder:a("settings.network.host.placeholder"),autoComplete:"off",spellCheck:!1,"aria-invalid":g.host?!0:void 0,"aria-label":a("settings.network.host.label"),className:ve})}),e.jsx(R,{label:a("settings.network.port.label"),hint:g.port,control:e.jsx("input",{type:"text",inputMode:"numeric",value:i.port,onChange:v=>f({port:v.target.value}),placeholder:a("settings.network.port.placeholder"),autoComplete:"off",spellCheck:!1,"aria-invalid":g.port?!0:void 0,"aria-label":a("settings.network.port.label"),className:ve})}),e.jsxs("div",{className:"flex flex-wrap items-center justify-end gap-2 py-3",children:[e.jsx(A,{variant:"secondary",size:"sm",onClick:E,disabled:x||d,className:"gap-1.5",children:x?e.jsxs(e.Fragment,{children:[e.jsx(xe,{className:"h-3.5 w-3.5 animate-spin","aria-hidden":!0}),e.jsx("span",{children:a("settings.network.test.testing")})]}):a("settings.network.test")}),e.jsx(A,{variant:"primary",size:"sm",onClick:N,disabled:d||x,className:"gap-1.5",children:d?e.jsxs(e.Fragment,{children:[e.jsx(xe,{className:"h-3.5 w-3.5 animate-spin","aria-hidden":!0}),e.jsx("span",{children:a("settings.network.saving")})]}):a("settings.network.save")})]}),b?e.jsx("p",{className:"py-2 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:b.ok?a("settings.network.test.ok",{status:String(b.status??"")}):a("settings.network.test.fail",{error:b.error||""})}):null]},"manual-proxy-fields"):null}),i.mode!=="manual"&&(k||d)?e.jsx("div",{className:"flex justify-end py-3",children:e.jsx(A,{variant:"primary",size:"sm",onClick:N,disabled:d,className:"gap-1.5",children:d?e.jsxs(e.Fragment,{children:[e.jsx(xe,{className:"h-3.5 w-3.5 animate-spin","aria-hidden":!0}),e.jsx("span",{children:a("settings.network.saving")})]}):a("settings.network.save")})},"non-manual-save"):null,h==="saved"?e.jsx("p",{className:"py-2 text-xs text-emerald-600 dark:text-emerald-400",children:a("settings.network.saved")}):null,h==="error"?e.jsx("p",{role:"alert",className:"py-2 text-xs text-red-600 dark:text-red-400",children:j?.unprotected?a("settings.network.save_error_unprotected",{error:j?.message||String(j||"")}):a("settings.network.save_error",{error:j?.message||String(j||"")})}):null]})}const Rt="/functions/tokentracker-proxy-config",Hn="/functions/tokentracker-proxy-test",Vn={mode:"system",protocol:"http",host:"",port:"",effective:"none",applyError:null};function It(t){return!t||typeof t.mode!="string"?null:{mode:t.mode,protocol:typeof t.protocol=="string"?t.protocol:"http",host:typeof t.host=="string"?t.host:"",port:t.port==null||t.port===0?"":String(t.port),effective:typeof t.effective=="string"?t.effective:"none",applyError:typeof t.applyError=="string"&&t.applyError.trim()?t.applyError:null}}async function qn(){const t=await fetch(Rt,{method:"GET",headers:{Accept:"application/json"},cache:"no-store"});if(!t.ok)return null;const s=await t.json().catch(()=>null);return It(s)}async function ot(){const{getLocalApiAuthHeaders:t}=await _a(async()=>{const{getLocalApiAuthHeaders:s}=await import("./__vite-browser-external-Go6WKt6Z.js").then(n=>n.dY);return{getLocalApiAuthHeaders:s}},__vite__mapDeps([0,1]));return t()}function Kn(){const[t,s]=o.useState(!1),[n,r]=o.useState(!0),[i,c]=o.useState(Vn);o.useEffect(()=>{if(!qa()){s(!1),r(!1);return}let d=!1;return(async()=>{try{const p=await qn();if(d)return;if(!p){s(!1),r(!1);return}c(p),s(!0),r(!1)}catch{d||(s(!1),r(!1))}})(),()=>{d=!0}},[]);const g=o.useCallback(async d=>{const p=await ot(),h=await fetch(Rt,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json",...p},cache:"no-store",body:JSON.stringify({mode:d.mode,protocol:d.protocol,host:d.host,port:d.port===""?0:Number(d.port)})}),m=await h.json().catch(()=>null);if(!h.ok){const w=m&&typeof m.error=="string"?m.error:`HTTP ${h.status}`;throw new Error(w)}const j=It(m);if(j&&c(j),m&&m.ok===!1){const w=m&&typeof m.applyError=="string"&&m.applyError||m&&typeof m.error=="string"&&m.error||`HTTP ${h.status}`,x=new Error(w);throw m.unprotected===!0&&(x.unprotected=!0),x}return j||m},[]),l=o.useCallback(async d=>{const p=await ot(),h=await fetch(Hn,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json",...p},cache:"no-store",body:JSON.stringify({protocol:d.protocol,host:d.host,port:d.port===""?0:Number(d.port)})}),m=await h.json().catch(()=>null);if(!m||typeof m.ok!="boolean")throw new Error(m&&typeof m.error=="string"?m.error:`HTTP ${h.status}`);return m},[]);return{available:t,loading:n,config:i,save:g,testConnection:l}}const B={APPEARANCE:"appearance",NATIVE_APP:"native-app",NETWORK:"network",ACCOUNT:"account",CLOUD:"cloud",LIMITS:"limits",LABS:"labs"},Y={PERSONAL:"personal",APP:"app",DEVELOPER:"developer"};function Wn({prefs:t}){return e.jsx(se,{options:[{value:at.USED,label:a("limits.settings.display_mode_used")},{value:at.REMAINING,label:a("limits.settings.display_mode_remaining")}],value:t.displayMode,onChange:t.setDisplayMode})}function Ti(){const t=Me(),s=Ga(),{available:n,settings:r,setSetting:i}=je(),c=Kn(),{available:g}=c,l=r?.toastOnReset!==!1,d=r?.confettiOnReset!==!1,p=bt()||r?.platform==="windows",[h,m]=wa(),j=ht(),w=h.get("section"),_=Object.values(B).includes(w)&&(w!==B.NATIVE_APP||n)&&(w!==B.NETWORK||g)?w:B.APPEARANCE,b=k=>{const f=new URLSearchParams(h);k===B.APPEARANCE?f.delete("section"):f.set("section",k),m(f,{replace:!0})},u=[{id:B.APPEARANCE,label:a("settings.section.appearance"),description:a("settings.section.appearance.description"),group:Y.PERSONAL,Icon:Ls,content:e.jsx(Dn,{})},...n?[{id:B.NATIVE_APP,label:a("settings.section.menubar"),description:a("settings.section.menubar.description"),group:Y.APP,Icon:Ue,content:e.jsx(zn,{})}]:[],...g?[{id:B.NETWORK,label:a("settings.section.network"),description:a("settings.section.network.description"),group:Y.APP,Icon:Na,content:e.jsx(Bn,{proxySettings:c})}]:[],{id:B.ACCOUNT,label:a("settings.section.account"),description:a("settings.section.account.description"),group:Y.PERSONAL,Icon:Ts,content:e.jsx(sn,{settings:t})},{id:B.CLOUD,label:a("settings.section.cloud"),description:a("settings.section.cloud.description"),group:Y.PERSONAL,Icon:fe,content:e.jsx(Sn,{settings:t,active:_===B.CLOUD})},{id:B.LIMITS,label:a("settings.section.limits"),description:a("settings.section.limits.description"),group:Y.APP,Icon:Sa,content:e.jsxs("div",{className:"space-y-4",children:[e.jsxs(Z,{title:a("settings.section.limits"),children:[e.jsx(R,{label:a("limits.settings.display_mode_label"),control:e.jsx(Wn,{prefs:s})}),p?null:e.jsxs(e.Fragment,{children:[e.jsx(R,{label:a("settings.menubar.toastOnReset"),hint:a("settings.menubar.toastOnResetHint"),control:e.jsx(z,{checked:l,disabled:!n,onChange:()=>i("toastOnReset",!l),ariaLabel:a("settings.menubar.toastOnReset")})}),e.jsx(R,{label:a("settings.menubar.confettiOnReset"),hint:a("settings.menubar.confettiOnResetHint"),control:e.jsx(z,{checked:d,disabled:!n,onChange:()=>i("confettiOnReset",!d),ariaLabel:a("settings.menubar.confettiOnReset")})})]}),e.jsx(R,{label:a("settings.limits.showSubscriptions"),hint:a("settings.limits.showSubscriptionsHint"),control:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(A,{variant:"secondary",size:"sm",onClick:()=>j("/limits?openSubscriptions=1"),"aria-label":a("limits.page.openSubscriptions"),title:a("limits.page.openSubscriptions"),className:"!h-7 !w-7 !p-0 text-oai-gray-500 hover:text-oai-black dark:text-oai-gray-400 dark:hover:text-white",children:e.jsx(Ca,{size:14,"aria-hidden":!0})}),e.jsx(z,{checked:s.showSubscriptions!==!1,onChange:()=>s.setShowSubscriptions(!s.showSubscriptions),ariaLabel:a("settings.limits.showSubscriptions")})]})})]}),e.jsx(Z,{title:a("settings.limits.providers"),children:e.jsx(Us,{prefs:s})})]})},{id:B.LABS,label:a("settings.section.labs"),description:a("settings.section.labs.description"),group:Y.DEVELOPER,Icon:Es,content:e.jsx(Un,{})}],y=[{id:Y.PERSONAL,label:a("settings.nav.group.personal")},{id:Y.APP,label:a("settings.nav.group.app")},{id:Y.DEVELOPER,label:a("settings.nav.group.developer")}].map(k=>({...k,sections:u.filter(f=>f.group===k.id)})).filter(k=>k.sections.length>0);return e.jsx("div",{className:le("flex flex-1 flex-col font-oai text-oai-black antialiased dark:text-oai-white",_===B.CLOUD&&"tt-cloud-settings"),children:e.jsx("main",{className:"flex-1 pb-12 pt-8 sm:pb-16 sm:pt-10",children:e.jsxs("div",{className:"mx-auto w-full max-w-5xl px-4 sm:px-6",children:[e.jsxs("div",{className:"mb-7 max-w-2xl",children:[e.jsx("h1",{className:"text-3xl font-semibold tracking-tight text-oai-black dark:text-white sm:text-4xl",children:a("settings.page.title")}),e.jsx("p",{className:"mt-2 text-sm leading-6 text-oai-gray-500 dark:text-oai-gray-400 sm:text-base",children:a("settings.page.subtitle")})]}),e.jsxs("div",{className:"tt-settings-sections grid min-w-0 gap-6 md:grid-cols-[11rem_minmax(0,1fr)] md:gap-8",children:[e.jsx("aside",{className:"min-w-0 rounded-xl border border-oai-gray-200 bg-oai-gray-50/70 p-2 dark:border-oai-gray-800 dark:bg-oai-gray-900/60 md:border-0 md:bg-transparent md:p-0 md:dark:bg-transparent",children:e.jsx("nav",{"aria-label":a("settings.page.title"),className:"flex gap-1 overflow-x-auto [scrollbar-width:none] [&::-webkit-scrollbar]:hidden md:sticky md:top-6 md:flex-col md:gap-4 md:overflow-visible",children:y.map(({id:k,label:f,sections:N})=>e.jsxs("div",{className:"flex shrink-0 gap-1 md:block",children:[e.jsx("div",{className:"hidden px-3 pb-1 text-[10px] font-semibold uppercase tracking-[0.16em] text-oai-gray-400 dark:text-oai-gray-500 md:block",children:f}),e.jsx("div",{className:"flex gap-1 md:flex-col",children:N.map(({id:E,label:v,Icon:C})=>{const O=_===E;return e.jsxs("button",{id:`settings-nav-${E}`,type:"button","aria-current":O?"page":void 0,"aria-controls":`settings-panel-${E}`,onClick:()=>b(E),className:le("inline-flex min-h-10 min-w-max shrink-0 items-center gap-1.5 rounded-md px-2 py-2 text-left text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-oai-brand-500 md:w-full md:min-w-0 md:gap-2 md:px-3",O?"bg-oai-gray-100 text-oai-black dark:bg-oai-gray-800 dark:text-white":"text-oai-gray-500 hover:bg-oai-gray-50 hover:text-oai-gray-900 dark:text-oai-gray-400 dark:hover:bg-oai-gray-900 dark:hover:text-oai-gray-200"),children:[e.jsx(C,{className:le("h-4 w-4 shrink-0",O?"text-oai-black dark:text-white":"text-oai-gray-400 dark:text-oai-gray-500"),"aria-hidden":!0}),e.jsx("span",{className:"truncate",children:v})]},E)})})]},k))})}),e.jsxs("div",{className:"min-w-0",children:[u.map(({id:k,label:f,content:N})=>e.jsx("section",{id:`settings-panel-${k}`,"aria-labelledby":`settings-nav-${k}`,"aria-label":f,"data-settings-panel":k,hidden:_!==k,children:N},k)),e.jsx(Mn,{})]})]})]})})})}export{Ti as SettingsPage};