tokentracker-cli 1.3.4 → 1.3.5

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 (145) hide show
  1. package/README.de.md +5 -5
  2. package/README.ja.md +3 -3
  3. package/README.ko.md +3 -3
  4. package/README.md +6 -5
  5. package/README.zh-CN.md +3 -3
  6. package/dashboard/dist/assets/{AchievementBadge-CKjtQp-U.js → AchievementBadge-Dazs3pEa.js} +1 -1
  7. package/dashboard/dist/assets/{AchievementsPage-DpOXrabE.js → AchievementsPage-LWnxZvmw.js} +2 -2
  8. package/dashboard/dist/assets/{AchievementsSection-DiXyIoa0.js → AchievementsSection-BLqczmU9.js} +1 -1
  9. package/dashboard/dist/assets/{BadgeDetailModal-CILTTkPF.js → BadgeDetailModal-B_n4aj2S.js} +1 -1
  10. package/dashboard/dist/assets/{BotAnimated-CrBHWiRi.js → BotAnimated-KDWI_YcZ.js} +1 -1
  11. package/dashboard/dist/assets/{Card-DUItW3xI.js → Card-BYoxd4OC.js} +1 -1
  12. package/dashboard/dist/assets/{CloudCheckoutPage-C_t_PDlG.js → CloudCheckoutPage-BR2_B03P.js} +1 -1
  13. package/dashboard/dist/assets/{CloudPage-pvJUrhya.js → CloudPage-DL5RkJKK.js} +1 -1
  14. package/dashboard/dist/assets/{CloudUsageExport-DQbDwiyk.js → CloudUsageExport-C_DqZKo1.js} +1 -1
  15. package/dashboard/dist/assets/{CommandPalette-BvHilrbV.js → CommandPalette-DkCaIQI4.js} +1 -1
  16. package/dashboard/dist/assets/{CommunityStatsModal-CizxEYv-.js → CommunityStatsModal-pX9OePi4.js} +1 -1
  17. package/dashboard/dist/assets/{ConfirmModal-h9nISVy7.js → ConfirmModal-tkgZwz4u.js} +1 -1
  18. package/dashboard/dist/assets/{Controls-BjdIonTX.js → Controls-MTUhGWy8.js} +1 -1
  19. package/dashboard/dist/assets/{DashboardPage-Bxryr4qp.js → DashboardPage-SOx-A7lH.js} +1 -1
  20. package/dashboard/dist/assets/{DateRangePopover-DpKh-0l8.js → DateRangePopover-B-BMOm3O.js} +1 -1
  21. package/dashboard/dist/assets/{DevicePage-DUJR9hJC.js → DevicePage-DSK9lm7v.js} +1 -1
  22. package/dashboard/dist/assets/{DialogClose-BmVAmN-o.js → DialogClose-uVUNu4rg.js} +1 -1
  23. package/dashboard/dist/assets/DialogDescription-DBqGGWNj.js +1 -0
  24. package/dashboard/dist/assets/{DialogTitle-BsaIbN8k.js → DialogTitle-B-VifiA3.js} +1 -1
  25. package/dashboard/dist/assets/{FadeIn-BpSt2P_W.js → FadeIn-B6lrj4uo.js} +1 -1
  26. package/dashboard/dist/assets/{HeaderGithubStar-Cc_VHB0R.js → HeaderGithubStar-Cx5zOhXa.js} +1 -1
  27. package/dashboard/dist/assets/{HoverTooltip-WFd21iP9.js → HoverTooltip-DY1ENf69.js} +1 -1
  28. package/dashboard/dist/assets/{IpCheckPage-C_mUPSRB.js → IpCheckPage-D6TEq64d.js} +1 -1
  29. package/dashboard/dist/assets/{LandingPage-DVR8ClZO.js → LandingPage-OdZUfq--.js} +2 -2
  30. package/dashboard/dist/assets/LeaderboardPage-DCK5xcAt.js +2 -0
  31. package/dashboard/dist/assets/{LeaderboardProBadge-BjX4EFl2.js → LeaderboardProBadge-CBXJ1u_m.js} +1 -1
  32. package/dashboard/dist/assets/{LeaderboardProfileModal-vbPMNn7W.js → LeaderboardProfileModal-Ccdzb7QK.js} +4 -4
  33. package/dashboard/dist/assets/{LeaderboardProfilePage-CqClmuA-.js → LeaderboardProfilePage-CFXlZ0fL.js} +1 -1
  34. package/dashboard/dist/assets/LimitsPage-5krjm-g9.js +9 -0
  35. package/dashboard/dist/assets/{LocalOnlyNotice-B6nDke_u.js → LocalOnlyNotice-Rk1B8PaZ.js} +1 -1
  36. package/dashboard/dist/assets/{LoginCard-C28QVjd7.js → LoginCard-DTTIm8vk.js} +1 -1
  37. package/dashboard/dist/assets/{LoginModal-Bx1btNhH.js → LoginModal-BNcDdjfr.js} +1 -1
  38. package/dashboard/dist/assets/{LoginPage-DVOGNGYI.js → LoginPage-CQgXP7Ee.js} +1 -1
  39. package/dashboard/dist/assets/{PetPage-nOKryTde.js → PetPage-Cw_kAPRs.js} +1 -1
  40. package/dashboard/dist/assets/{PopoverPopup-Ch6NLnu6.js → PopoverPopup-NYiGE8A2.js} +1 -1
  41. package/dashboard/dist/assets/{ProviderIcon-BRY2br-g.js → ProviderIcon-Bp7iFJ_m.js} +1 -1
  42. package/dashboard/dist/assets/{ResetPasswordPage-ko1OQecQ.js → ResetPasswordPage-Cf9kAWDW.js} +1 -1
  43. package/dashboard/dist/assets/{Select-Q8mS3_od.js → Select-kIcvQFAo.js} +1 -1
  44. package/dashboard/dist/assets/{SelectItemText-C1id8GDj.js → SelectItemText-BpIsAg3b.js} +1 -1
  45. package/dashboard/dist/assets/{SelfHostPage-Dzb2bDiM.js → SelfHostPage-Ch2vvSwI.js} +1 -1
  46. package/dashboard/dist/assets/{ServiceStatusPage-ewFwz29J.js → ServiceStatusPage-hoYBvGbu.js} +1 -1
  47. package/dashboard/dist/assets/SessionsPage-BzRB6q-Z.js +3 -0
  48. package/dashboard/dist/assets/SettingsPage-DRl2uX-i.js +2 -0
  49. package/dashboard/dist/assets/{SkillsPage-CcG77tqU.js → SkillsPage-CkqThTZL.js} +1 -1
  50. package/dashboard/dist/assets/{TokenGalaxy-D2HDrbQR.js → TokenGalaxy-eLG-UIZY.js} +1 -1
  51. package/dashboard/dist/assets/{TooltipPopup-C_bF2ZwO.js → TooltipPopup-bnMJyilQ.js} +1 -1
  52. package/dashboard/dist/assets/{TrendMonitor-BcyoN5ns.js → TrendMonitor-X7-aGzIv.js} +1 -1
  53. package/dashboard/dist/assets/{WidgetsPage-BirK0U_N.js → WidgetsPage-CGznIzrW.js} +1 -1
  54. package/dashboard/dist/assets/{WrappedPage-thsXBuw6.js → WrappedPage-p31-uUoF.js} +1 -1
  55. package/dashboard/dist/assets/{__vite-browser-external-Bq8nj-JV.js → __vite-browser-external-2g_4s3ot.js} +12 -12
  56. package/dashboard/dist/assets/__vite-browser-external-LpFw4zXh.css +1 -0
  57. package/dashboard/dist/assets/agent-logos-2TVT3fIE.js +1 -0
  58. package/dashboard/dist/assets/{arrow-left-c_NOSfoq.js → arrow-left-DL0hAp_7.js} +1 -1
  59. package/dashboard/dist/assets/{arrow-right-CP7drKCT.js → arrow-right-DFCpnV_9.js} +1 -1
  60. package/dashboard/dist/assets/{arrow-up-right-DQ6QfCpo.js → arrow-up-right-DLvfE0Wu.js} +1 -1
  61. package/dashboard/dist/assets/{calendar-days-D_pxFQvT.js → calendar-days-B0aDoKSG.js} +1 -1
  62. package/dashboard/dist/assets/{check-HAS31kTT.js → check-C_cfrxiz.js} +1 -1
  63. package/dashboard/dist/assets/{chevron-down-BIMuk6oN.js → chevron-down-Ck8ml43e.js} +1 -1
  64. package/dashboard/dist/assets/{cloud-checkout-COmDwrUT.js → cloud-checkout-PYnwNfdH.js} +1 -1
  65. package/dashboard/dist/assets/{composite-kLwqpqEk.js → composite-INW-ELWX.js} +1 -1
  66. package/dashboard/dist/assets/{download-9RgsZIiH.js → download-B7uokeIo.js} +1 -1
  67. package/dashboard/dist/assets/{external-link-C_gYjHGF.js → external-link-CI3crg4K.js} +1 -1
  68. package/dashboard/dist/assets/{flame-BSsCvgT8.js → flame-DCzvFKV1.js} +1 -1
  69. package/dashboard/dist/assets/{format-tokens-N22Wqv1X.js → format-tokens-CSTEYK2m.js} +1 -1
  70. package/dashboard/dist/assets/gift-dEHDFMc6.js +1 -0
  71. package/dashboard/dist/assets/{host-mode-JzrhHX7F.js → host-mode-r2SW9Mdv.js} +1 -1
  72. package/dashboard/dist/assets/{icons-pK99mIMv.js → icons-q-3zvEkh.js} +1 -1
  73. package/dashboard/dist/assets/{index-CmD84EJi.js → index-BV7qwUw4.js} +1 -1
  74. package/dashboard/dist/assets/{index-Dk43KNa6.js → index-BbrsgHf4.js} +1 -1
  75. package/dashboard/dist/assets/{index-BhviBroj.js → index-CyHYj9XI.js} +1 -1
  76. package/dashboard/dist/assets/{info-D-RLFnSK.js → info-BBdY9hV4.js} +1 -1
  77. package/dashboard/dist/assets/{link-2-BiKXW9mV.js → link-2-CLPePfXs.js} +1 -1
  78. package/dashboard/dist/assets/{loader-circle-KVUaEKV2.js → loader-circle-ETrjzfmn.js} +1 -1
  79. package/dashboard/dist/assets/{modifiers.esm-5NK8j3mT.js → modifiers.esm-DHqnp2ol.js} +1 -1
  80. package/dashboard/dist/assets/module-BNnaKM__.js +3 -0
  81. package/dashboard/dist/assets/{monitor-smartphone-u9yr-_Es.js → monitor-smartphone-D1kdzrdb.js} +1 -1
  82. package/dashboard/dist/assets/{play-D0MaDCOx.js → play-Cxp-ronD.js} +1 -1
  83. package/dashboard/dist/assets/{plus-DTJVtoAJ.js → plus-4n94VzDK.js} +1 -1
  84. package/dashboard/dist/assets/{provider-display-YhtG0I9Y.js → provider-display-CRlbeO7t.js} +1 -1
  85. package/dashboard/dist/assets/{react-gIVxucOB.js → react-DlHjGQFN.js} +1 -1
  86. package/dashboard/dist/assets/{safePolygon-C_sPnJ1L.js → safePolygon-CVZ27a2_.js} +1 -1
  87. package/dashboard/dist/assets/{search-DdQRwFYV.js → search-BDPr56_h.js} +1 -1
  88. package/dashboard/dist/assets/{server-M0rmbGWy.js → server-Bm7fHvVa.js} +1 -1
  89. package/dashboard/dist/assets/{shield-check-9-sqQKdD.js → shield-check-DtT8ACzI.js} +1 -1
  90. package/dashboard/dist/assets/{skills-api-B0qBWnuK.js → skills-api-Dc1-2qu6.js} +1 -1
  91. package/dashboard/dist/assets/{sortable.esm-iqbm7x5D.js → sortable.esm-B-qN-Xk2.js} +1 -1
  92. package/dashboard/dist/assets/{store-DstuWd4a.js → store-gHeBU8dQ.js} +1 -1
  93. package/dashboard/dist/assets/{terminal-Dz0MxHNG.js → terminal-D4VZbvhg.js} +1 -1
  94. package/dashboard/dist/assets/{trash-DBMFOFVz.js → trash-BZtLAFQy.js} +1 -1
  95. package/dashboard/dist/assets/{use-community-stats-CacbAcUR.js → use-community-stats-BdqndrbB.js} +1 -1
  96. package/dashboard/dist/assets/{use-latest-request-guard-nBuQVZOR.js → use-latest-request-guard-DhGg1cDS.js} +1 -1
  97. package/dashboard/dist/assets/use-limits-display-prefs-D3HOcRFv.js +1 -0
  98. package/dashboard/dist/assets/{use-native-settings-EAqAFx2x.js → use-native-settings-BniKwA_n.js} +1 -1
  99. package/dashboard/dist/assets/{use-ordered-list-DGLjjU6Q.js → use-ordered-list-b09H7EHq.js} +1 -1
  100. package/dashboard/dist/assets/{use-pet-settings-C5MzWHE7.js → use-pet-settings-CPZdlq_e.js} +2 -2
  101. package/dashboard/dist/assets/use-reduced-motion-D1gcKJUo.js +1 -0
  102. package/dashboard/dist/assets/{use-transform-C25eCuz_.js → use-transform-CIdxjmI8.js} +1 -1
  103. package/dashboard/dist/assets/use-usage-limits-eJlU65yY.js +1 -0
  104. package/dashboard/dist/assets/{useCurrency-t3PYQi1l.js → useCurrency-CM22CmAq.js} +1 -1
  105. package/dashboard/dist/assets/{usePositioner-C59mj6kG.js → usePositioner-B3l2ulTw.js} +1 -1
  106. package/dashboard/dist/assets/{useTokenFormat-C0xQsBGf.js → useTokenFormat-D7nzgxKw.js} +1 -1
  107. package/dashboard/dist/assets/{zap-CyH0tvKM.js → zap-Daxct1WV.js} +1 -1
  108. package/dashboard/dist/index.html +14 -12
  109. package/dashboard/dist/ip-check.html +2 -2
  110. package/dashboard/dist/leaderboard.html +2 -2
  111. package/dashboard/dist/llms.txt +2 -2
  112. package/dashboard/dist/share.html +2 -2
  113. package/package.json +2 -2
  114. package/src/commands/init.js +43 -1
  115. package/src/commands/status.js +27 -0
  116. package/src/commands/sync.js +54 -4
  117. package/src/commands/uninstall.js +19 -0
  118. package/src/lib/claude-config.js +47 -15
  119. package/src/lib/codex-rollout-parser.js +11 -3
  120. package/src/lib/command-runner.js +15 -1
  121. package/src/lib/cursor-config.js +2 -1
  122. package/src/lib/gemini-config.js +3 -2
  123. package/src/lib/local-api.js +13 -3
  124. package/src/lib/notify-command.js +38 -0
  125. package/src/lib/openclaw-session-plugin.js +47 -14
  126. package/src/lib/passive-mode.js +12 -0
  127. package/src/lib/pricing/curated-overrides.json +42 -5
  128. package/src/lib/pricing/matcher.js +14 -5
  129. package/src/lib/pricing/seed-snapshot.json +1 -1
  130. package/src/lib/rollout.js +150 -28
  131. package/src/lib/session-analytics.js +108 -9
  132. package/src/lib/usage-limits.js +183 -20
  133. package/src/lib/zcode-limits.js +218 -18
  134. package/src/lib/zcode-reset-credits.js +66 -0
  135. package/dashboard/dist/assets/DialogDescription-C0Cgq67g.js +0 -1
  136. package/dashboard/dist/assets/LeaderboardPage-D8ydzVpn.js +0 -2
  137. package/dashboard/dist/assets/LimitsPage-DaRggHge.js +0 -8
  138. package/dashboard/dist/assets/SessionsPage-C6Y8kbnM.js +0 -3
  139. package/dashboard/dist/assets/SettingsPage-nztCXEPs.js +0 -2
  140. package/dashboard/dist/assets/__vite-browser-external-BwmeEfv7.css +0 -1
  141. package/dashboard/dist/assets/agent-logos-CK6SzhI7.js +0 -1
  142. package/dashboard/dist/assets/module-WSx8viXK.js +0 -3
  143. package/dashboard/dist/assets/use-limits-display-prefs-fqg8hs6b.js +0 -1
  144. package/dashboard/dist/assets/use-reduced-motion-DK2oZ2uC.js +0 -1
  145. package/dashboard/dist/assets/use-usage-limits-BhqnEai3.js +0 -1
@@ -1,8 +0,0 @@
1
- import{o as z,j as e,y as Te,c as r,h as ae,r as x,al as ot,B,bv as lt,V as D,e as ct,W as ve,L as dt,bw as ut,t as mt,w as xt}from"./__vite-browser-external-Bq8nj-JV.js";import{m as ke}from"./react-gIVxucOB.js";import{P as ge,c as pt,r as re,a as gt,u as ht,b as ft,s as bt}from"./use-usage-limits-BhqnEai3.js";import{b as k,c as Ee,l as Z,d as He,u as yt}from"./use-limits-display-prefs-fqg8hs6b.js";import{C as Ie}from"./Card-DUItW3xI.js";import{F as vt}from"./FadeIn-BpSt2P_W.js";import{P as Ae}from"./ProviderIcon-BRY2br-g.js";import{H as kt}from"./HoverTooltip-WFd21iP9.js";import{C as jt}from"./ConfirmModal-h9nISVy7.js";import{I as je,L as wt}from"./LocalOnlyNotice-B6nDke_u.js";import{S as ue}from"./Select-Q8mS3_od.js";import{P as Nt}from"./plus-DTJVtoAJ.js";import{P as _t,a as Ct,b as Pt,c as Mt,d as St}from"./PopoverPopup-Ch6NLnu6.js";import{u as Dt}from"./use-reduced-motion-DK2oZ2uC.js";import"./use-latest-request-guard-nBuQVZOR.js";import"./DialogTitle-BsaIbN8k.js";import"./composite-kLwqpqEk.js";import"./store-DstuWd4a.js";import"./DialogDescription-C0Cgq67g.js";import"./arrow-up-right-DQ6QfCpo.js";import"./download-9RgsZIiH.js";import"./chevron-down-BIMuk6oN.js";import"./check-HAS31kTT.js";import"./SelectItemText-C1id8GDj.js";import"./usePositioner-C59mj6kG.js";import"./safePolygon-C_sPnJ1L.js";const Re={name:"bell-off",size:24,node:[["path",{d:"M10.268 21a2 2 0 0 0 3.464 0",key:"vwvbt9"}],["path",{d:"M17 17H4a1 1 0 0 1-.74-1.673C4.59 13.956 6 12.499 6 8a6 6 0 0 1 .258-1.742",key:"178tsu"}],["path",{d:"m2 2 20 20",key:"1ooewy"}],["path",{d:"M8.668 3.01A6 6 0 0 1 18 8c0 2.687.77 4.653 1.707 6.05",key:"1hqiys"}]]};Re.node;const Tt=z(Re);const Oe={name:"bell",size:24,node:[["path",{d:"M10.268 21a2 2 0 0 0 3.464 0",key:"vwvbt9"}],["path",{d:"M3.262 15.326A1 1 0 0 0 4 17h16a1 1 0 0 0 .74-1.673C19.41 13.956 18 12.499 18 8A6 6 0 0 0 6 8c0 4.499-1.411 5.956-2.738 7.326",key:"11g9vi"}]]};Oe.node;const Et=z(Oe);const Le={name:"calendar-clock",size:24,node:[["path",{d:"M16 14v2.2l1.6 1",key:"fo4ql5"}],["path",{d:"M16 2v3",key:"otl347"}],["path",{d:"M21 7.338V5a2 2 0 00-2-2H5a2 2 0 00-2 2v14a2 2 0 002 2h2.338",key:"7hb8p4"}],["path",{d:"M3 9h5.859",key:"numkqi"}],["path",{d:"M8 2v3",key:"1ioesn"}],["circle",{cx:"16",cy:"16",r:"6",key:"qoo3c4"}]]};Le.node;const Fe=z(Le);const $e={name:"clock",size:24,node:[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 6v6l4 2",key:"mmk7yg"}]]};$e.node;const Ue=z($e);const Be={name:"infinity",size:24,node:[["path",{d:"M6 16c5 0 7-8 12-8a4 4 0 0 1 0 8c-5 0-7-8-12-8a4 4 0 1 0 0 8",key:"18ogeb"}]]};Be.node;const Ge=z(Be),Ht=[3,2,3,3,2,2,3];function I({className:t}){return e.jsx("div",{className:Te("rounded bg-oai-gray-200/70 dark:bg-oai-gray-800/70 animate-pulse",t)})}function It(){return e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(I,{className:"h-3 w-12 shrink-0"}),e.jsx(I,{className:"flex-1 h-1.5 rounded-full min-w-0"}),e.jsx(I,{className:"h-3 w-[30px] shrink-0"}),e.jsx(I,{className:"h-3 w-6 shrink-0"})]})}function At({bars:t,index:a}){const i=a%3===0?"w-24":a%3===1?"w-20":"w-[4.5rem]";return e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(I,{className:"h-[14px] w-[14px] rounded shrink-0"}),e.jsx(I,{className:Te("h-4",i)})]}),Array.from({length:t},(s,n)=>e.jsx(It,{},n))]})}function Rt(){return e.jsx(Ie,{children:e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx(I,{className:"h-3.5 w-28"}),Ht.map((t,a)=>e.jsx(At,{bars:t,index:a},a))]})})}const he=100;function we(t){const a=Date.parse(t);return Number.isFinite(a)?a:null}function Ot(t){return Math.max(0,Math.min(he,Math.round(t)))}function Lt(t){return new Intl.DateTimeFormat(ae(),{month:"numeric",day:"numeric",hour:"2-digit",minute:"2-digit",hour12:!1}).format(new Date(t))}function Ft(t,a,i){if(t==null||t>=a)return he;const s=a-t,n=a-i;return Ot(n/s*he)}function $t(t){const a=t.available_count;return a===null?null:Number.isInteger(a)&&a>=0?a:void 0}function Ut(t,{now:a}={}){if(!t||typeof t!="object")return null;const i=$t(t);if(i===void 0)return null;const s=Array.isArray(t.credits)?t.credits:[],n=a instanceof Date?a.getTime():Number(a??Date.now()),o=[];for(const l of s){const c=we(l?.expires_at);if(c==null)continue;const d=o.length+1;o.push({key:`reset-${d}`,label:r("limits.codex_reset_bank.row_label",{index:d}),expiresAt:Lt(c),expiresMs:c,percent:Ft(we(l?.granted_at),c,n)})}return i===0?null:o.length>0?{kind:"rows",availableCount:i??o.length,rows:o}:i>0?{kind:"count_only",availableCount:i,rows:[]}:null}const W=864e5;function A(t,a){const i=new Date(t),s=i.getUTCDate(),n=new Date(Date.UTC(i.getUTCFullYear(),i.getUTCMonth()+a,1,i.getUTCHours(),i.getUTCMinutes())),o=new Date(Date.UTC(n.getUTCFullYear(),n.getUTCMonth()+1,0)).getUTCDate();return n.setUTCDate(Math.min(s,o)),n.getTime()}function We(t,a){if(a==="weekly")return t-7*W;if(a==="yearly")return A(t,-12);const i=new Date(t),s=new Date(Date.UTC(i.getUTCFullYear(),i.getUTCMonth(),0)).getUTCDate(),n=new Date(Date.UTC(i.getUTCFullYear(),i.getUTCMonth()-1,1,i.getUTCHours(),i.getUTCMinutes()));return n.setUTCDate(Math.min(i.getUTCDate(),s)),n.getTime()}function ze(t,a){return a==="weekly"?t+7*W:a==="yearly"?A(t,12):A(t,1)}function Bt(t){if(t.startedAt!=null){const a=new Date(t.startedAt).getTime();if(Number.isFinite(a))return a}return We(new Date(t.nextBillingAt).getTime(),t.cycle)}function Gt(t,a,i){if(t.startedAt!=null){const s=new Date(t.startedAt).getTime();if(Number.isFinite(s))return s}return We(i,a)}function Wt(t,a,i){if(a==="weekly"){const c=7*W,d=i<=t?0:Math.floor((i-t)/c);return{startMs:t+d*c,endMs:t+(d+1)*c}}const s=a==="yearly"?12:1,n=s*30.436875*W;let o=i<=t?0:Math.floor((i-t)/n);for(;o>0&&A(t,o*s)>i;)o-=1;let l=0;for(;A(t,(o+1)*s)<=i&&l<12e3;)o+=1,l+=1;return{startMs:A(t,o*s),endMs:A(t,(o+1)*s)}}function ee(t,a){const i=new Date(t.nextBillingAt).getTime();if(!Number.isFinite(i))return null;const s=["weekly","monthly","yearly"].includes(t.cycle)?t.cycle:"monthly",n=Gt(t,s,i);if(!Number.isFinite(n))return null;let o,l,c=!1;t.autoRenew?{startMs:o,endMs:l}=Wt(n,s,a):t.startedAt!=null?(o=n,l=ze(n,s),c=l<=a):(o=n,l=i,c=l<=a);const d=Math.max(1,l-o),m=c?1:Math.max(0,Math.min(1,(a-o)/d));return{endMs:l,startMs:o,progress:m,cycleDays:Math.max(1,Math.round(d/W)),expired:c}}function qe(t,a){const i=t-a;if(i<=0)return r("subscriptions.expired");const s=Math.ceil(i/6e4);if(s<60)return`${s}m`;const n=Math.floor(s/60);return n<24?`${n}h`:`${Math.floor(n/24)}d`}function fe(t,a){const i=t-a;if(i<=0)return r("subscriptions.expired");const s=Math.floor(i/6e4),n=Math.floor(s/1440),o=Math.floor(s%1440/60),l=s%60;return r("subscriptions.countdown",{days:n,hours:o,minutes:l})}const zt="shrink-0 text-oai-black dark:text-oai-white";function Ve(){const t=typeof navigator>"u"?"":navigator.userAgent||"";return/Windows/i.test(t)?"windows":/Linux/i.test(t)?"linux":"macos"}function Ye(){return Ve()==="windows"?r("limits.commandCode.setupHint.snippet_login_windows"):r("limits.commandCode.setupHint.snippet_login")}function Ke(){return r("limits.devin.setupHint.snippet_login")}function qt(t){const a=re(t);if(!Number.isFinite(a))return null;const i=a-Date.now();if(i<=0)return r("shared.time.now");const s=Math.floor(i/6e4);if(s<60)return`${s}m`;const n=Math.floor(s/60);return n<24?`${n}h`:`${Math.floor(n/24)}d`}function Vt(t,a){const i=a===k.REMAINING?100-t:t;return i>=90?"bg-red-500":i>=70?"bg-amber-500":"bg-emerald-500"}function te(t,a="used_percent"){return t?a==="utilization"?t.utilization:t.used_percent:null}function ie(t,a="reset_at"){return t?a==="resets_at"?t.resets_at:t.reset_at:null}function me(t){const a=Math.max(0,Math.min(100,Number(t)||0)),i=Math.round(a);return a>0&&i===0?r("limits.bar.sub_one_percent"):String(i)}function Q(t,{useGrouping:a=!0,maximumFractionDigits:i}={}){const s=Number(t);return Number.isFinite(s)?new Intl.NumberFormat(void 0,{minimumFractionDigits:0,maximumFractionDigits:i??(s>=100?0:2),useGrouping:a}).format(s):null}function Yt(t){if(!t||typeof t!="object"||!(Number(t.limit_credits)>0))return null;const a={useGrouping:t.unit!=="calls"},i=Q(t.used_credits,a),s=Q(t.limit_credits,a),n=Q(t.remaining_credits,a);if(!i||!s||!n)return null;const o=t.unit==="calls"?"limits.qoder_calls.detail":"limits.codex_credits.detail";return r(o,{used:i,limit:s,remaining:n})}function Kt(t,a,i){return pt({usedPercent:te(t.window,t.pctField),windowSeconds:gt(t,t.window),resetMs:re(ie(t.window,t.resetField)),mode:a,now:i})}function Xe(t){return Number.isFinite(t)?new Intl.DateTimeFormat(ae(),{month:"numeric",day:"numeric",hour:"2-digit",minute:"2-digit",hour12:!1}).format(new Date(t)):null}function Xt(t,a,i){const s=[Qe(t,a,i)],n=re(ie(t.window,t.resetField)),o=Xe(n);o&&s.push(r(t.timeKind==="expiry"?"limits.hover.expires_at":"limits.hover.resets_at",{time:o}));const l=Yt(t.window);return l&&s.push(l),s.join(`
2
- `)}const Je=kt;function Jt({label:t,pct:a,reset:i,mode:s=k.USED,pacePercent:n=null,paceOver:o=!1,title:l=null}){const c=Math.max(0,Math.min(100,Number(a)||0)),d=s===k.REMAINING?100-c:c,m=Math.round(d),h=d>0&&m===0?Math.max(d,.35):d;let f=String(m);d>0&&m===0&&(f=r("limits.bar.sub_one_percent"));const b=n==null?null:Math.max(0,Math.min(100,n));return e.jsxs("div",{className:"group relative flex items-center gap-2",children:[e.jsx(Je,{text:l}),e.jsx("span",{"data-limit-label":"",className:"text-[11px] text-oai-gray-500 dark:text-oai-gray-400 shrink-0 whitespace-nowrap",style:{width:"var(--tt-limits-label-w)"},children:t}),e.jsxs("div",{className:"relative flex-1 bg-oai-gray-100 dark:bg-oai-gray-700/50 rounded-full h-1.5 overflow-hidden",children:[e.jsx("div",{className:`${Vt(d,s)} rounded-full h-full transition-[width] duration-500 ease-out`,style:{width:`${h}%`,minWidth:d>0?"3px":0}}),b!=null&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"absolute top-0 h-full bg-oai-gray-100 dark:bg-oai-gray-700/50",style:{left:`calc(${b}% - 3px)`,width:"6px"}}),e.jsx("div",{className:`absolute top-0 h-full ${o?"bg-red-500":"bg-emerald-500"}`,style:{left:`calc(${b}% - 1px)`,width:"2px"}})]})]}),e.jsxs("span",{className:"text-[11px] tabular-nums text-oai-gray-500 dark:text-oai-gray-400 w-9 text-right shrink-0 whitespace-nowrap",children:[f,"%"]}),i&&e.jsx("span",{className:"text-[10px] text-oai-gray-400 dark:text-oai-gray-500 w-6 text-right shrink-0",children:i})]})}function Qe(t,a,i){const s=t.label??r(t.labelKey),n=i===k.REMAINING,o=d=>n?100-d:d;if(a.expectedPercent==null){const d=Math.max(0,Math.min(100,Number(te(t.window,t.pctField))||0)),m=me(o(d));return n?r("limits.explain.remaining",{label:s,used:m}):r("limits.explain.used",{label:s,used:m})}if(a.paceOver){if(a.runsOutEta)return r("limits.explain.ahead_eta",{label:s,eta:a.runsOutEta});const d=me(o(a.projectedEnd??100));return r(n?"limits.explain.ahead_pct_remaining":"limits.explain.ahead_pct",{label:s,pct:d})}const l=Math.max(0,Math.min(100,Number(te(t.window,t.pctField))||0)),c=me(o(a.projectedEnd??l));return r(n?"limits.explain.on_track_remaining":"limits.explain.on_track",{label:s,pct:c})}function Qt({pace:t}){return t.pacePercent!=null}function Zt({rows:t,mode:a,now:i=Date.now()}){if(t.length===0)return null;const s=a===k.REMAINING,n=t.some(Qt);return e.jsxs("div",{className:"mt-1 flex flex-col gap-1",children:[t.map(({spec:o,pace:l})=>{const c=Xe(re(ie(o.window,o.resetField)));return e.jsxs("div",{className:"text-[11px] leading-snug text-oai-gray-600 dark:text-oai-gray-300",children:[Qe(o,l,a),c?e.jsxs("span",{className:"text-oai-gray-400 dark:text-oai-gray-500",children:[" · ",r(o.timeKind==="expiry"?"limits.hover.expires_at":"limits.hover.resets_at",{time:c})]}):null]},o.key)}),n?e.jsx("div",{className:"mt-1 pt-1.5 border-t border-oai-gray-200/70 dark:border-oai-gray-700/50 text-[10.5px] leading-snug text-oai-gray-400 dark:text-oai-gray-500",children:r(s?"limits.explain.body_remaining":"limits.explain.body")}):null]})}function G(t){if(!t)return null;const a=Date.now()-new Date(t).getTime();if(a<0)return null;const i=Math.floor(a/6e4);if(i<1)return r("shared.time.now");if(i<60)return r("shared.time.m_ago",{n:i});const s=Math.floor(i/60);if(s<24)return r("shared.time.h_ago",{n:s});const n=Math.floor(s/24);return r("shared.time.d_ago",{n})}const Ne={live:{surface:"bg-oai-gray-50 dark:bg-oai-gray-800 border-oai-gray-200/60 dark:border-oai-gray-700/60 text-oai-gray-500 dark:text-oai-gray-400",dot:"bg-emerald-500",pulse:"bg-emerald-400"},stale:{surface:"bg-oai-gray-50 dark:bg-oai-gray-800 border-oai-gray-200/60 dark:border-oai-gray-700/60 text-oai-gray-500 dark:text-oai-gray-400",dot:"bg-amber-500",pulse:"bg-amber-400"},cached:{surface:"bg-oai-gray-50 dark:bg-oai-gray-800 border-oai-gray-200/60 dark:border-oai-gray-700/60 text-oai-gray-500 dark:text-oai-gray-400",dot:"bg-amber-500",pulse:"bg-amber-400"}},ea={claude:"claude",codex:"codex",antigravity:"agy"};function L({label:t,age:a=null,tone:i="live",tooltip:s=null}){const n=Ne[i]||Ne.live,o=i==="live";return e.jsxs("div",{className:"relative inline-flex items-center group cursor-help ml-1",onClick:l=>l.stopPropagation(),children:[e.jsxs("span",{className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded-full text-[9px] font-semibold uppercase tracking-wider border leading-normal ${n.surface}`,children:[o?e.jsxs("span",{className:"relative flex h-1.5 w-1.5",children:[e.jsx("span",{className:`animate-ping absolute inline-flex h-full w-full rounded-full ${n.pulse} opacity-75`}),e.jsx("span",{className:`relative inline-flex rounded-full h-1.5 w-1.5 ${n.dot}`})]}):e.jsx("span",{className:`h-1.5 w-1.5 rounded-full ${n.dot}`}),t,a?e.jsxs(e.Fragment,{children:[" · ",a]}):null]}),s?e.jsxs("span",{className:"pointer-events-none absolute left-1/2 bottom-full z-20 mb-2 -translate-x-1/2 w-48 rounded-md bg-oai-gray-900 dark:bg-oai-gray-800 px-2.5 py-1.5 text-[10px] font-normal text-white text-center opacity-0 scale-95 translate-y-1 group-hover:opacity-100 group-hover:scale-100 group-hover:translate-y-0 transition-all duration-200 cubic-bezier(0.16, 1, 0.3, 1) leading-normal shadow-lg origin-bottom border border-oai-gray-800 dark:border-oai-gray-700",children:[s,e.jsx("span",{className:"absolute left-1/2 top-full -translate-x-1/2 border-4 border-transparent border-t-oai-gray-900 dark:border-t-oai-gray-800"})]}):null]})}function Ze({name:t,providerId:a,children:i,expandable:s=!1,expanded:n=!1,onToggle:o,badge:l=null,rightAdornment:c=null}){const d=He(a),m=e.jsxs("div",{className:"flex items-center gap-1.5",children:[d?e.jsx(Ae,{provider:d,size:14,className:zt}):null,e.jsx("span",{className:"text-sm font-medium text-oai-black dark:text-oai-white",children:t}),c?e.jsx("span",{className:"shrink-0",children:c}):null,l]});return s?e.jsxs("div",{role:"button",tabIndex:0,"aria-expanded":n,onClick:o,onKeyDown:h=>{(h.key==="Enter"||h.key===" ")&&(h.preventDefault(),o?.())},className:"flex flex-col gap-1.5 -mx-1.5 px-1.5 py-1 rounded-lg cursor-pointer transition-colors hover:bg-oai-gray-50 dark:hover:bg-oai-gray-800/40 aria-expanded:bg-oai-gray-50 dark:aria-expanded:bg-oai-gray-800/40",children:[m,i]}):e.jsxs("div",{className:"flex flex-col gap-1.5",children:[m,i]})}function et({subscription:t}){const a=t.autoRenew?r("subscriptions.badge.auto_renew"):r("subscriptions.badge.stops"),i=t.autoRenew?Ge:Ue;return e.jsx("span",{role:"img","aria-label":a,title:a,className:`inline-flex translate-y-px ${t.autoRenew?"text-oai-brand-600 dark:text-oai-brand-400":"text-blue-600 dark:text-blue-400"}`,children:e.jsx(i,{size:14,strokeWidth:2,"aria-hidden":!0})})}function tt({subscription:t,now:a,mode:i=k.USED}){const s=ee(t,a);if(!s)return null;const{endMs:n,expired:o}=s,l=!o&&n-a<=3*864e5,c=o?100:s.progress*100,d=i===k.REMAINING?100-c:c,m=o?100:Math.max(0,Math.min(100,d)),h=Math.round(m),f=m>0&&h===0?r("limits.bar.sub_one_percent"):`${h}%`;return e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[11px] text-oai-gray-500 dark:text-oai-gray-400 shrink-0 whitespace-nowrap",style:{width:"var(--tt-limits-label-w)"},children:r("subscriptions.inline.label")}),e.jsx("div",{className:"relative flex-1 bg-oai-gray-100 dark:bg-oai-gray-700/50 rounded-full h-1.5 overflow-hidden",children:e.jsx("div",{className:`${o?"bg-red-500":l?"bg-amber-500":"bg-blue-500"} rounded-full h-full block motion-safe:transition-[width] motion-safe:duration-500 ease-out motion-reduce:transition-none`,style:{width:`${m}%`,minWidth:m>0?"3px":0}})}),e.jsx("span",{className:"text-[11px] tabular-nums text-oai-gray-500 dark:text-oai-gray-400 w-9 text-right shrink-0 whitespace-nowrap",children:f}),e.jsx("span",{className:`text-[10px] tabular-nums shrink-0 whitespace-nowrap w-6 text-right ${o?"text-oai-error":"text-oai-gray-400 dark:text-oai-gray-500"}`,children:qe(n,a)})]})}function at({subscription:t,now:a}){const i=ee(t,a);if(!i)return null;const s=new Intl.DateTimeFormat(ae(),{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"});return e.jsxs("div",{className:"text-[11px] leading-snug text-oai-gray-500 dark:text-oai-gray-400",children:[e.jsx("span",{children:r("subscriptions.inline.label")}),e.jsx("span",{className:"text-oai-gray-300 dark:text-oai-gray-600",children:":"}),e.jsx("span",{children:t.autoRenew?r("subscriptions.label.renews_at"):r("subscriptions.label.expires_at")}),e.jsx("span",{children:" "}),e.jsx("span",{className:"font-mono tabular-nums",children:s.format(new Date(i.endMs))}),e.jsx("span",{className:"text-oai-gray-300 dark:text-oai-gray-600",children:" · "}),e.jsx("span",{className:i.expired?"text-oai-error":void 0,children:fe(i.endMs,a)}),e.jsx("span",{className:"text-oai-gray-300 dark:text-oai-gray-600",children:" · "}),e.jsx("span",{children:t.autoRenew?r("subscriptions.status.auto_renew"):r("subscriptions.status.manual")})]})}const ta=Ee;function R({children:t,tone:a="neutral"}){const i=a==="error"?"text-red-600 dark:text-red-400":"text-oai-gray-500 dark:text-oai-gray-400";return e.jsx("div",{className:`text-[11px] leading-snug ${i}`,children:t})}function aa({rows:t,mode:a,extra:i=null}){const s=t.length===0&&!i;return e.jsxs(e.Fragment,{children:[t.map(({spec:n,pace:o})=>e.jsx(Jt,{label:n.label??r(n.labelKey),pct:te(n.window,n.pctField),reset:qt(ie(n.window,n.resetField)),mode:a,pacePercent:o.pacePercent,paceOver:o.paceOver,title:Xt(n,o,a)},n.key)),s?e.jsx(R,{children:r("limits.status.no_data")}):null,i]})}function ra(t){if(!Number.isFinite(t.expiresMs))return null;const a=Math.floor((t.expiresMs-Date.now())/864e5);return a<0?null:a===0?r("limits.reset_bank.hover_detail_today",{date:t.expiresAt}):r("limits.reset_bank.hover_detail",{date:t.expiresAt,days:a})}function ia({row:t}){const a=Math.max(0,Math.min(100,Number(t.percent)||0));return e.jsxs("div",{className:"group relative flex items-center gap-2","data-reset-bank-row":"",children:[e.jsx(Je,{text:ra(t)}),e.jsx("span",{"data-limit-label":"",className:"text-[11px] text-oai-gray-500 dark:text-oai-gray-400 shrink-0 whitespace-nowrap",style:{width:"var(--tt-limits-label-w)"},children:t.label}),e.jsx("div",{className:"relative flex-1 bg-oai-gray-100 dark:bg-oai-gray-700/50 rounded-full h-1.5 overflow-hidden",children:e.jsx("div",{className:"bg-oai-gray-400 dark:bg-oai-gray-500 rounded-full h-full transition-[width] duration-500 ease-out",style:{width:`${a}%`,minWidth:a>0?"3px":0}})}),e.jsx("span",{className:"text-[10px] tabular-nums text-oai-gray-400 dark:text-oai-gray-500 w-[4.25rem] text-right shrink-0 whitespace-nowrap",children:t.expiresAt})]})}function na({model:t}){const a=t.kind==="count_only"?r("limits.codex_reset_bank.count_only",{count:t.availableCount}):null;return e.jsxs("div",{className:"mt-1 flex flex-col gap-1","data-reset-bank-section":t.kind,children:[e.jsx("div",{className:"text-[10.5px] font-medium uppercase tracking-wide text-oai-gray-400 dark:text-oai-gray-500",children:r("limits.codex_reset_bank.title")}),a?e.jsx("div",{className:"text-[11px] leading-snug text-oai-gray-500 dark:text-oai-gray-400",children:a}):t.rows.map(i=>e.jsx(ia,{row:i},i.key))]})}function rt(t,a){if(t==="codex_meta"){const i=Ut(a.reset_credits);return i?e.jsx(na,{model:i}):null}if(t==="kimi_parallel"&&a.parallel_limit)return e.jsx(R,{children:r("limits.label.kimi_parallel",{count:a.parallel_limit})});if(t==="kiro_credits"&&Number.isFinite(Number(a.tracked_credits))&&Number(a.tracked_credit_records)>0){const i=Q(a.tracked_credits,{maximumFractionDigits:2});return e.jsx(R,{children:r("limits.label.kiro_tracked_credits",{credits:i,count:Number(a.tracked_credit_records)})})}return t==="copilot_otel"&&!a.otel_has_files&&!a.otel_enabled?e.jsx(la,{defaultDir:a.otel_default_dir}):null}function sa(t,a,i,s,n,o,l=null,c=null,d=Date.now()){const m=ge[t];if(!m)return null;const h=m.windows(a).filter(b=>b.window).map(b=>({spec:b,pace:Kt(b,s,d)})),f=rt(m.extra,a);return e.jsxs(Ze,{name:i,providerId:t,expandable:h.length>0||!!c,expanded:n,onToggle:o,badge:l,rightAdornment:c?e.jsx(et,{subscription:c}):null,children:[e.jsx(aa,{mode:s,rows:h,extra:f}),c?e.jsx(tt,{subscription:c,now:d,mode:s}):null,n?e.jsx(Zt,{rows:h,mode:s,now:d}):null,n&&c?e.jsx(at,{subscription:c,now:d}):null]},t)}function xe(t,a,i,s,n=null,o=Date.now(),l=k.USED){const c=!!n;return e.jsxs(Ze,{name:Z(t),providerId:t,expandable:c,expanded:i,onToggle:s,rightAdornment:c?e.jsx(et,{subscription:n}):null,children:[a,c?e.jsx(tt,{subscription:n,now:o,mode:l}):null,c&&i?e.jsx("div",{className:"mt-1",children:e.jsx(at,{subscription:n,now:o})}):null]},t)}function oa(t,a,i,s,n,o=null,l=Date.now()){if(!ge[t])return null;if(!a?.configured)return xe(t,e.jsxs(e.Fragment,{children:[e.jsx(R,{children:r("limits.status.not_connected")}),t==="opencodeGo"?e.jsx(_e,{}):null,t==="commandCode"?e.jsx(Ce,{}):null,t==="codingPlan"?e.jsx(Me,{}):null,t==="agentPlan"?e.jsx(Se,{}):null,t==="devin"?e.jsx(Pe,{}):null]}),s,n,o,l,i);if(t==="opencodeGo"&&a.subscription_status==="inactive")return xe(t,e.jsx(R,{children:r("limits.opencodeGo.status.inactive")}),s,n,o,l,i);if(a.error)return xe(t,e.jsxs(e.Fragment,{children:[e.jsx(R,{tone:"error",children:r("shared.error.prefix",{error:a.error})}),t==="kiro"?rt(ge.kiro.extra,a):null,t==="opencodeGo"?e.jsx(_e,{}):null,t==="commandCode"?e.jsx(Ce,{}):null,t==="codingPlan"?e.jsx(Me,{}):null,t==="agentPlan"?e.jsx(Se,{}):null,t==="devin"?e.jsx(Pe,{}):null]}),s,n,o,l,i);const c=Z(t),d=a.plan_label?`${c} ${a.plan_label}`:c;let m=null;if(a.auth_action_required==="reauth"){const f=t==="commandCode"?Ye():t==="devin"?Ke():ea[t];m=e.jsx(L,{label:r("limits.reauth.badge"),age:G(a.cached_at),tone:"stale",tooltip:f?r("limits.reauth.tooltip",{command:f}):null})}if(!m&&t==="antigravity")if(a.cached){const f=G(a.cached_at);m=e.jsx(L,{label:r("limits.label.antigravity_cached"),age:f,tone:"cached",tooltip:r("limits.tooltip.antigravity_cached")})}else m=e.jsx(L,{label:r("limits.label.antigravity_live"),tone:"live",tooltip:r("limits.tooltip.antigravity_live")});!m&&(t==="qoder"||t==="qoderCn")&&a.cached&&(m=e.jsx(L,{label:r("limits.label.antigravity_cached"),age:G(a.cached_at),tone:"cached",tooltip:r("limits.tooltip.qoder_cached")})),!m&&(t==="codingPlan"||t==="agentPlan")&&a.cached&&(m=e.jsx(L,{label:r("limits.label.antigravity_cached"),age:G(a.cached_at),tone:"cached",tooltip:r("limits.tooltip.ark_cached")}));const h=a.provenance;return h?.stale&&!m&&(m=e.jsx(L,{label:r("limits.provenance.stale"),age:G(h.captured_at),tone:"stale",tooltip:r("limits.provenance.tooltip",{source:h.source,confidence:h.confidence})})),sa(t,a,d,i,s,n,m,o,l)}function la({defaultDir:t}){const[a,i]=x.useState(!1),n=["export COPILOT_OTEL_ENABLED=true","export COPILOT_OTEL_EXPORTER_TYPE=file",`export COPILOT_OTEL_FILE_EXPORTER_PATH="${t||"$HOME/.copilot/otel"}/copilot-otel-$(date +%Y%m%d).jsonl"`].join(`
3
- `),o=async l=>{l.stopPropagation();try{await navigator.clipboard.writeText(n),i(!0),setTimeout(()=>i(!1),1600)}catch{}};return e.jsxs("div",{className:"mt-1 rounded-md border border-amber-300/60 dark:border-amber-700/40 bg-amber-50/50 dark:bg-amber-900/10 px-2.5 py-2 text-[11px] text-oai-gray-600 dark:text-oai-gray-300",children:[e.jsx("div",{className:"font-medium text-oai-gray-700 dark:text-oai-gray-200",children:r("limits.copilot.otelHint.title")}),e.jsx("div",{className:"mt-0.5 leading-snug",children:r("limits.copilot.otelHint.body")}),e.jsx("pre",{className:"mt-1.5 overflow-x-auto rounded bg-oai-gray-100 dark:bg-oai-gray-900/60 px-2 py-1.5 font-mono text-[10.5px] leading-tight whitespace-pre",children:n}),e.jsx("button",{type:"button",onClick:o,className:"mt-1 inline-flex items-center gap-1 rounded border border-oai-gray-300 dark:border-oai-gray-700 px-1.5 py-0.5 text-[10.5px] text-oai-gray-700 dark:text-oai-gray-200 hover:bg-oai-gray-100 dark:hover:bg-oai-gray-800 transition-colors",children:a?r("limits.copilot.otelHint.copied"):r("limits.copilot.otelHint.copy")})]})}function j({n:t,children:a}){return e.jsxs("li",{className:"flex gap-2.5",children:[e.jsx("span",{className:"mt-[1px] flex h-4 w-4 shrink-0 items-center justify-center rounded-full bg-oai-brand/15 text-[9px] font-semibold text-oai-brand",children:t}),e.jsx("div",{className:"min-w-0 flex-1 leading-snug",children:a})]})}function be(){return e.jsx("svg",{viewBox:"0 0 12 12","aria-hidden":"true",className:"h-2.5 w-2.5",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("path",{d:"M4.5 2.75h4.75V7.5M9.25 2.75 3 9"})})}function _e(){const[t,a]=x.useState(!1),i=["read -r -s OPENCODE_GO_API_KEY","export OPENCODE_GO_API_KEY",'launchctl setenv OPENCODE_GO_API_KEY "$OPENCODE_GO_API_KEY"'].join(`
4
- `),s=async n=>{n.stopPropagation();try{await navigator.clipboard.writeText(i),a(!0),setTimeout(()=>a(!1),1600)}catch{}};return e.jsxs("div",{className:"mt-1.5 rounded-lg border border-oai-gray-200 dark:border-oai-gray-700/60 bg-oai-gray-50/50 dark:bg-oai-gray-900/20 p-3 text-[11px] text-oai-gray-600 dark:text-oai-gray-300",children:[e.jsx("div",{className:"text-[12px] font-semibold text-oai-gray-800 dark:text-oai-gray-100",children:r("limits.opencodeGo.setupHint.title")}),e.jsx("div",{className:"mt-0.5 leading-snug text-oai-gray-500 dark:text-oai-gray-400",children:r("limits.opencodeGo.setupHint.subtitle")}),e.jsxs("ol",{className:"mt-2.5 space-y-2.5",children:[e.jsxs(j,{n:"1",children:[e.jsx("div",{children:r("limits.opencodeGo.setupHint.step1")}),e.jsxs("a",{href:"https://opencode.ai",target:"_blank",rel:"noreferrer",onClick:n=>n.stopPropagation(),className:"mt-1 inline-flex items-center gap-1 rounded-md bg-oai-brand/10 px-2 py-1 font-medium text-oai-brand hover:bg-oai-brand/15 transition-colors",children:[r("limits.opencodeGo.setupHint.cta"),e.jsx(be,{})]})]}),e.jsx(j,{n:"2",children:e.jsx("div",{children:r("limits.opencodeGo.setupHint.step2")})}),e.jsxs(j,{n:"3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{children:r("limits.opencodeGo.setupHint.step3")}),e.jsx("button",{type:"button",onClick:s,className:"shrink-0 rounded-md border border-oai-gray-300 dark:border-oai-gray-700 px-2 py-0.5 text-[10.5px] text-oai-gray-700 dark:text-oai-gray-200 hover:bg-oai-gray-100 dark:hover:bg-oai-gray-800 transition-colors",children:t?r("limits.opencodeGo.setupHint.copied"):r("limits.opencodeGo.setupHint.copy")})]}),e.jsx("pre",{className:"mt-1.5 overflow-x-auto rounded-md bg-oai-gray-100 dark:bg-oai-gray-900/60 px-2 py-1.5 font-mono text-[10.5px] leading-relaxed whitespace-pre",children:i}),e.jsx("div",{className:"mt-1 text-[10px] text-oai-gray-400 dark:text-oai-gray-500",children:r("limits.opencodeGo.setupHint.note_app")})]})]})]})}function Ce(){const[t,a]=x.useState(!1),i=Ve(),s=Ye(),n=i==="windows"?r("limits.commandCode.setupHint.snippet_env_windows").replaceAll("\\n",`
5
- `):[r("limits.commandCode.setupHint.snippet_read"),r("limits.commandCode.setupHint.snippet_export"),...i==="macos"?[r("limits.commandCode.setupHint.snippet_setenv")]:[]].join(`
6
- `),o=async l=>{l.stopPropagation();try{await navigator.clipboard.writeText(n),a(!0),setTimeout(()=>a(!1),1600)}catch{}};return e.jsxs("div",{className:"mt-1.5 rounded-lg border border-oai-gray-200 dark:border-oai-gray-700/60 bg-oai-gray-50/50 dark:bg-oai-gray-900/20 p-3 text-[11px] text-oai-gray-600 dark:text-oai-gray-300",children:[e.jsx("div",{className:"text-[12px] font-semibold text-oai-gray-800 dark:text-oai-gray-100",children:r("limits.commandCode.setupHint.title")}),e.jsx("div",{className:"mt-0.5 leading-snug text-oai-gray-500 dark:text-oai-gray-400",children:r("limits.commandCode.setupHint.subtitle")}),e.jsxs("ol",{className:"mt-2.5 space-y-2.5",children:[e.jsxs(j,{n:"1",children:[e.jsx("div",{children:r("limits.commandCode.setupHint.step1")}),e.jsx("pre",{className:"mt-1.5 overflow-x-auto rounded-md bg-oai-gray-100 dark:bg-oai-gray-900/60 px-2 py-1.5 font-mono text-[10.5px] leading-relaxed whitespace-pre",children:s})]}),e.jsxs(j,{n:"2",children:[e.jsx("div",{children:r("limits.commandCode.setupHint.step2")}),e.jsx("div",{className:"mt-1.5 flex items-center gap-2",children:e.jsx("button",{type:"button",onClick:o,className:"shrink-0 rounded-md border border-oai-gray-300 dark:border-oai-gray-700 px-2 py-0.5 text-[10.5px] text-oai-gray-700 dark:text-oai-gray-200 hover:bg-oai-gray-100 dark:hover:bg-oai-gray-800 transition-colors",children:t?r("limits.commandCode.setupHint.copied"):r("limits.commandCode.setupHint.copy")})}),e.jsx("pre",{className:"mt-1.5 overflow-x-auto rounded-md bg-oai-gray-100 dark:bg-oai-gray-900/60 px-2 py-1.5 font-mono text-[10.5px] leading-relaxed whitespace-pre",children:n}),e.jsx("div",{className:"mt-1 text-[10px] text-oai-gray-400 dark:text-oai-gray-500",children:i==="windows"?r("limits.commandCode.setupHint.note_windows"):i==="linux"?r("limits.commandCode.setupHint.note_linux"):r("limits.commandCode.setupHint.note_app")})]})]})]})}function Pe(){const t=Ke();return e.jsxs("div",{className:"mt-1.5 rounded-lg border border-oai-gray-200 dark:border-oai-gray-700/60 bg-oai-gray-50/50 dark:bg-oai-gray-900/20 p-3 text-[11px] text-oai-gray-600 dark:text-oai-gray-300",children:[e.jsx("div",{className:"text-[12px] font-semibold text-oai-gray-800 dark:text-oai-gray-100",children:r("limits.devin.setupHint.title")}),e.jsx("div",{className:"mt-0.5 leading-snug text-oai-gray-500 dark:text-oai-gray-400",children:r("limits.devin.setupHint.subtitle")}),e.jsx("ol",{className:"mt-2.5 space-y-2.5",children:e.jsxs(j,{n:"1",children:[e.jsx("div",{children:r("limits.devin.setupHint.step1")}),e.jsx("pre",{className:"mt-1.5 overflow-x-auto rounded-md bg-oai-gray-100 dark:bg-oai-gray-900/60 px-2 py-1.5 font-mono text-[10.5px] leading-relaxed whitespace-pre",children:t}),e.jsx("div",{className:"mt-1 text-[10px] text-oai-gray-400 dark:text-oai-gray-500",children:r("limits.devin.setupHint.note")})]})})]})}function Me(){const[t,a]=x.useState(!1),i=["npm install -g @volcengine/ark-cli","arkcli auth login volc-sso # browser SSO (recommended)","arkcli auth status # verify the session"].join(`
7
- `),s=async n=>{n.stopPropagation();try{await navigator.clipboard.writeText(i),a(!0),setTimeout(()=>a(!1),1600)}catch{}};return e.jsxs("div",{className:"mt-1.5 rounded-lg border border-oai-gray-200 dark:border-oai-gray-700/60 bg-oai-gray-50/50 dark:bg-oai-gray-900/20 p-3 text-[11px] text-oai-gray-600 dark:text-oai-gray-300",children:[e.jsx("div",{className:"text-[12px] font-semibold text-oai-gray-800 dark:text-oai-gray-100",children:r("limits.codingPlan.setupHint.title")}),e.jsx("div",{className:"mt-0.5 leading-snug text-oai-gray-500 dark:text-oai-gray-400",children:r("limits.codingPlan.setupHint.subtitle")}),e.jsxs("ol",{className:"mt-2.5 space-y-2.5",children:[e.jsxs(j,{n:"1",children:[e.jsx("div",{children:r("limits.codingPlan.setupHint.step1")}),e.jsxs("a",{href:"https://www.volcengine.com/docs/82379/2536875",target:"_blank",rel:"noreferrer",onClick:n=>n.stopPropagation(),className:"mt-1 inline-flex items-center gap-1 rounded-md bg-oai-brand/10 px-2 py-1 font-medium text-oai-brand hover:bg-oai-brand/15 transition-colors",children:[r("limits.codingPlan.setupHint.cta"),e.jsx(be,{})]})]}),e.jsxs(j,{n:"2",children:[e.jsx("div",{children:r("limits.codingPlan.setupHint.step2")}),e.jsx("div",{className:"mt-0.5 text-oai-gray-500 dark:text-oai-gray-400",children:r("limits.codingPlan.setupHint.step2_remote")})]}),e.jsxs(j,{n:"3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{children:r("limits.codingPlan.setupHint.step3")}),e.jsx("button",{type:"button",onClick:s,className:"shrink-0 rounded-md border border-oai-gray-300 dark:border-oai-gray-700 px-2 py-0.5 text-[10.5px] text-oai-gray-700 dark:text-oai-gray-200 hover:bg-oai-gray-100 dark:hover:bg-oai-gray-800 transition-colors",children:t?r("limits.codingPlan.setupHint.copied"):r("limits.codingPlan.setupHint.copy")})]}),e.jsx("pre",{className:"mt-1.5 overflow-x-auto rounded-md bg-oai-gray-100 dark:bg-oai-gray-900/60 px-2 py-1.5 font-mono text-[10.5px] leading-relaxed whitespace-pre",children:i}),e.jsx("div",{className:"mt-1 text-[10px] text-oai-gray-400 dark:text-oai-gray-500",children:r("limits.codingPlan.setupHint.note_app")})]})]})]})}function Se(){const[t,a]=x.useState(!1),i=[r("limits.agentPlan.setupHint.snippet_install"),r("limits.agentPlan.setupHint.snippet_login"),r("limits.agentPlan.setupHint.snippet_status")].join(`
8
- `),s=async n=>{n.stopPropagation();try{await navigator.clipboard.writeText(i),a(!0),setTimeout(()=>a(!1),1600)}catch{}};return e.jsxs("div",{className:"mt-1.5 rounded-lg border border-oai-gray-200 dark:border-oai-gray-700/60 bg-oai-gray-50/50 dark:bg-oai-gray-900/20 p-3 text-[11px] text-oai-gray-600 dark:text-oai-gray-300",children:[e.jsx("div",{className:"text-[12px] font-semibold text-oai-gray-800 dark:text-oai-gray-100",children:r("limits.agentPlan.setupHint.title")}),e.jsx("div",{className:"mt-0.5 leading-snug text-oai-gray-500 dark:text-oai-gray-400",children:r("limits.agentPlan.setupHint.subtitle")}),e.jsxs("ol",{className:"mt-2.5 space-y-2.5",children:[e.jsxs(j,{n:"1",children:[e.jsx("div",{children:r("limits.agentPlan.setupHint.step1")}),e.jsxs("a",{href:"https://www.volcengine.com/docs/82379/2536875",target:"_blank",rel:"noreferrer",onClick:n=>n.stopPropagation(),className:"mt-1 inline-flex items-center gap-1 rounded-md bg-oai-brand/10 px-2 py-1 font-medium text-oai-brand hover:bg-oai-brand/15 transition-colors",children:[r("limits.agentPlan.setupHint.cta"),e.jsx(be,{})]})]}),e.jsxs(j,{n:"2",children:[e.jsx("div",{children:r("limits.agentPlan.setupHint.step2")}),e.jsx("div",{className:"mt-0.5 text-oai-gray-500 dark:text-oai-gray-400",children:r("limits.agentPlan.setupHint.step2_remote")})]}),e.jsxs(j,{n:"3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{children:r("limits.agentPlan.setupHint.step3")}),e.jsx("button",{type:"button",onClick:s,className:"shrink-0 rounded-md border border-oai-gray-300 dark:border-oai-gray-700 px-2 py-0.5 text-[10.5px] text-oai-gray-700 dark:text-oai-gray-200 hover:bg-oai-gray-100 dark:hover:bg-oai-gray-800 transition-colors",children:t?r("limits.agentPlan.setupHint.copied"):r("limits.agentPlan.setupHint.copy")})]}),e.jsx("pre",{className:"mt-1.5 overflow-x-auto rounded-md bg-oai-gray-100 dark:bg-oai-gray-900/60 px-2 py-1.5 font-mono text-[10.5px] leading-relaxed whitespace-pre",children:i}),e.jsx("div",{className:"mt-1 text-[10px] text-oai-gray-400 dark:text-oai-gray-500",children:r("limits.agentPlan.setupHint.note_app")})]})]})]})}function ca(t){const[a,i]=x.useState(0);return x.useLayoutEffect(()=>{const s=t.current;if(!s)return;const n=s.querySelectorAll("[data-limit-label]");let o=0,l=null;if(n.length>0)try{l=document.createElement("canvas").getContext("2d")}catch{l=null}if(l){const d=window.getComputedStyle(n[0]);l.font=`${d.fontStyle} ${d.fontWeight} ${d.fontSize} ${d.fontFamily}`;for(const m of n)o=Math.max(o,l.measureText(m.textContent).width)}const c=Math.ceil(o);i(d=>d===c?d:c)}),a}function da({claude:t,codex:a,cursor:i,gemini:s,kimi:n,kiro:o,grok:l,antigravity:c,copilot:d,zcode:m,opencodeGo:h,commandCode:f,qoder:b,qoderCn:N,codingPlan:T,agentPlan:_,devin:w,order:E,visibility:q,displayMode:V,subscriptions:ne=[],showSubscriptions:F=!0}){const se={claude:t,codex:a,cursor:i,gemini:s,kimi:n,kiro:o,grok:l,antigravity:c,copilot:d,zcode:m,opencodeGo:h,commandCode:f,qoder:b,qoderCn:N,codingPlan:T,agentPlan:_,devin:w},oe=x.useRef(null),C=ca(oe),[le,Y]=x.useState(null),[P,K]=x.useState(()=>Date.now()),ce=Array.isArray(E)&&E.length>0?E:ta,X=V===k.REMAINING?k.REMAINING:k.USED,de=X===k.REMAINING?r("limits.settings.display_mode_remaining"):r("limits.settings.display_mode_used");x.useEffect(()=>{const g=setInterval(()=>K(Date.now()),6e4);return()=>clearInterval(g)},[]);const H=new Map;if(F)for(const g of ne||[]){if(!g?.provider)continue;const M=new Date(g.nextBillingAt).getTime();if(!Number.isFinite(M))continue;const J=H.get(g.provider);if(!J){H.set(g.provider,g);continue}const S=new Date(J.nextBillingAt).getTime(),U=M>P,u=S>P;(U&&(!u||S>M)||!U&&!u&&M>S)&&H.set(g.provider,g)}const $=ce.filter(g=>!q||q[g]!==!1||H.has(g)).map(g=>oa(g,se[g],X,le===g,()=>Y(M=>M===g?null:g),H.get(g)||null,P)).filter(Boolean);return e.jsx(vt,{delay:.15,children:e.jsx(Ie,{children:e.jsxs("div",{ref:oe,className:"flex flex-col gap-3",style:C>0?{"--tt-limits-label-w":`${C}px`}:void 0,children:[e.jsxs("h3",{className:"text-sm font-medium text-oai-gray-500 dark:text-oai-gray-300 uppercase tracking-wide",children:[r("limits.panel.title"),r("limits.panel.mode_separator"),de]}),$.length>0?$:e.jsx(R,{children:r("limits.status.all_hidden")})]})})})}async function it(t){const a=await t.json().catch(()=>null);if(!t.ok||a?.ok===!1)throw new Error(a?.error||`Subscription request failed with HTTP ${t.status}`);return a}async function ua(){const t=await fetch("/functions/tokentracker-subscription-manager",{headers:{Accept:"application/json"},cache:"no-store"}),a=await it(t);return Array.isArray(a.subscriptions)?a.subscriptions:[]}async function ye(t){const a=await ot();return it(await fetch("/functions/tokentracker-subscription-manager",{method:"POST",headers:{Accept:"application/json","Content-Type":"application/json",...a},cache:"no-store",body:JSON.stringify(t)}))}function ma(t){return ye({action:"create",subscription:t})}function xa(t,a){return ye({action:"update",id:t,subscription:a})}function pa(t){return ye({action:"delete",id:t})}const pe={plan:"",provider:"",cycle:"monthly",autoRenew:!0,startedAt:""};function ga(t){const a=new Date(t);if(Number.isNaN(a.getTime()))return"";const i=s=>String(s).padStart(2,"0");return`${a.getFullYear()}-${i(a.getMonth()+1)}-${i(a.getDate())}T${i(a.getHours())}:${i(a.getMinutes())}`}function ha({subscriptions:t,onChanged:a}){const[i,s]=x.useState(!1),[n,o]=x.useState(null),[l,c]=x.useState(pe),[d,m]=x.useState(!1),[h,f]=x.useState(!1),[b,N]=x.useState(!1),[T,_]=x.useState(!1),[w,E]=x.useState(null),[q,V]=x.useState(!1),[ne,F]=x.useState(!1),[se,oe]=x.useState(null),[C,le]=x.useState(()=>Date.now()),Y=x.useRef(null),P=ae(),K=x.useMemo(()=>new Intl.DateTimeFormat(P,{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"}),[P]);x.useEffect(()=>{const u=setInterval(()=>le(Date.now()),6e4);return()=>clearInterval(u)},[]),x.useEffect(()=>{if(!i)return;const u=window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;Y.current?.scrollIntoView?.({behavior:u?"auto":"smooth",block:"nearest"})},[i,n]);const ce=x.useMemo(()=>Ee.map(u=>{const v=(t||[]).some(y=>y.provider===u&&y.id!==n),p=Z(u);return{value:u,label:v?`${p} ${r("subscriptions.form.provider_taken_suffix")}`:p,disabled:v}}),[P,t,n]),X=x.useMemo(()=>[{value:"weekly",label:r("subscriptions.form.cycle_weekly")},{value:"monthly",label:r("subscriptions.form.cycle_monthly")},{value:"yearly",label:r("subscriptions.form.cycle_yearly")}],[P]),de=x.useMemo(()=>[{value:"true",label:r("subscriptions.form.auto_renew_on")},{value:"false",label:r("subscriptions.form.auto_renew_off")}],[P]),H=x.useCallback(()=>{c(pe),o(null),f(!1),N(!1),_(!1),s(!0)},[]),$=x.useCallback(u=>{c({plan:u.plan||"",provider:u.provider||"",cycle:u.cycle||"monthly",autoRenew:u.autoRenew,startedAt:ga(new Date(Bt(u)).toISOString())}),o(u.id),f(!1),N(!1),_(!1),s(!0)},[]),g=x.useCallback(()=>{s(!1),o(null),c(pe),f(!1),N(!1),_(!1)},[]),M=x.useCallback(async u=>{if(u.preventDefault(),f(!1),!l.provider){N(!0);return}if((t||[]).some(O=>O.provider===l.provider&&O.id!==n)){_(!0);return}const p=new Date(l.startedAt).getTime();if(!Number.isFinite(p)){f(!0);return}const y={service:Z(l.provider),plan:l.plan,provider:l.provider||null,autoRenew:l.autoRenew,cycle:l.cycle,startedAt:p,nextBillingAt:ze(p,l.cycle)};m(!0);try{n?await xa(n,y):await ma(y),g(),await a?.()}catch{f(!0)}finally{m(!1)}},[g,n,l,a,t]),J=x.useCallback(async()=>{if(w){V(!0),F(!1);try{await pa(w.id),w.id===n&&g(),E(null),await a?.()}catch{F(!0)}finally{V(!1)}}},[g,n,a,w]),S=t||[],U=()=>{const u=n?S.find(p=>p.id===n):null,v=u?ee(u,C):null;return e.jsxs("form",{ref:Y,onSubmit:M,className:"grid grid-cols-1 gap-3 px-3 py-3 text-left sm:grid-cols-2",children:[e.jsx("div",{className:"flex items-center justify-between sm:col-span-2",children:e.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide text-oai-gray-500 dark:text-oai-gray-400",children:n?r("subscriptions.edit"):r("subscriptions.add")})}),v?e.jsxs("div",{className:"sm:col-span-2 rounded-md bg-oai-gray-50 dark:bg-oai-gray-800/50 px-2.5 py-2 text-xs text-oai-gray-600 dark:text-oai-gray-300",children:[e.jsx("span",{className:"text-oai-gray-400 dark:text-oai-gray-500",children:u.autoRenew?r("subscriptions.label.renews_at"):r("subscriptions.label.expires_at")})," ",e.jsx("span",{className:"font-mono tabular-nums",children:K.format(new Date(v.endMs))})," · ",e.jsx("span",{className:v.expired?"text-oai-error":void 0,children:fe(v.endMs,C)})]}):null,e.jsxs("div",{className:"flex flex-col sm:col-span-1",children:[e.jsx("label",{htmlFor:"subscription-provider",className:"block text-sm font-medium text-oai-gray-700 dark:text-oai-gray-300 mb-1.5",children:r("subscriptions.form.provider")}),e.jsx(ue,{id:"subscription-provider",value:l.provider,onValueChange:p=>c({...l,provider:String(p)}),options:ce,matchTriggerWidth:!0,className:"h-10 w-full px-3 text-sm"})]}),e.jsx("div",{className:"sm:col-span-1",children:e.jsx(je,{label:r("subscriptions.form.plan"),value:l.plan,maxLength:120,placeholder:r("subscriptions.form.plan_placeholder"),onChange:p=>c({...l,plan:p.target.value})})}),e.jsxs("div",{className:"flex flex-col sm:col-span-1",children:[e.jsx("label",{htmlFor:"subscription-cycle",className:"block text-sm font-medium text-oai-gray-700 dark:text-oai-gray-300 mb-1.5",children:r("subscriptions.form.cycle")}),e.jsx(ue,{id:"subscription-cycle",value:l.cycle,onValueChange:p=>c({...l,cycle:String(p)}),options:X,matchTriggerWidth:!0,className:"h-10 w-full px-3 text-sm"})]}),e.jsxs("div",{className:"flex flex-col sm:col-span-1",children:[e.jsx("label",{htmlFor:"subscription-auto-renew",className:"block text-sm font-medium text-oai-gray-700 dark:text-oai-gray-300 mb-1.5",children:r("subscriptions.form.auto_renew")}),e.jsx(ue,{id:"subscription-auto-renew",value:String(l.autoRenew),onValueChange:p=>c({...l,autoRenew:p==="true"}),options:de,matchTriggerWidth:!0,className:"h-10 w-full px-3 text-sm"})]}),e.jsx("div",{className:"sm:col-span-2",children:e.jsx(je,{label:r("subscriptions.form.started_at"),type:"datetime-local",value:l.startedAt,required:!0,onChange:p=>c({...l,startedAt:p.target.value})})}),e.jsxs("div",{className:"flex items-center justify-end gap-2 sm:col-span-2",children:[n?e.jsx(B,{type:"button",variant:"secondary",size:"sm",onClick:()=>{const p=S.find(y=>y.id===n);p&&E(p)},className:"!text-red-600 dark:!text-red-400 mr-auto",children:r("subscriptions.delete")}):null,b?e.jsx("p",{className:"mr-auto text-sm text-oai-error",role:"alert",children:r("subscriptions.form.provider_required")}):null,T?e.jsx("p",{className:"mr-auto text-sm text-oai-error",role:"alert",children:r("subscriptions.form.provider_taken")}):null,h?e.jsx("p",{className:"mr-auto text-sm text-oai-error",role:"alert",children:r("subscriptions.form.error")}):null,e.jsx(B,{type:"button",variant:"secondary",size:"sm",onClick:g,children:r("shared.action.cancel")}),e.jsx(B,{type:"submit",size:"sm",disabled:d,children:r("subscriptions.save")})]})]})};return e.jsxs("div",{className:"flex max-h-[min(80vh,42rem)] w-[min(92vw,32rem)] flex-col gap-3 overflow-y-auto rounded-xl border border-oai-gray-200 bg-white p-4 shadow-lg dark:border-oai-gray-700 dark:bg-oai-gray-900",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("div",{className:"min-w-0",children:e.jsx("span",{className:"block truncate text-sm font-semibold text-oai-black dark:text-white",children:r("limits.page.openSubscriptions")})}),e.jsxs(B,{type:"button",size:"sm",onClick:H,className:"shrink-0 gap-1.5",children:[e.jsx(Nt,{size:14,strokeWidth:2,"aria-hidden":!0}),e.jsx("span",{children:r("subscriptions.add")})]})]}),S.length===0&&!(i&&!n)?e.jsxs("div",{className:"flex flex-col items-center justify-center gap-1 rounded-lg border border-dashed border-oai-gray-200 px-4 py-10 text-center dark:border-oai-gray-700",children:[e.jsx(Fe,{className:"h-6 w-6 text-oai-gray-300 dark:text-oai-gray-600 mb-2","aria-hidden":!0}),e.jsx("p",{className:"text-sm font-medium text-oai-black dark:text-white",children:r("subscriptions.empty.title")}),e.jsx("p",{className:"text-xs text-oai-gray-500 dark:text-oai-gray-400",children:r("subscriptions.empty.body")})]}):e.jsxs("ul",{className:"flex flex-col gap-1.5",children:[S.map(u=>{const v=ee(u,C);if(!v)return null;const{endMs:p,expired:y}=v,O=y?100:v.progress*100,nt=!y&&p-C<=3*864e5,st=se===u.id;return e.jsxs("li",{className:"rounded-lg border border-oai-gray-100 dark:border-oai-gray-800",children:[e.jsxs("button",{type:"button",onClick:()=>$(u),"aria-label":`${r("subscriptions.edit")} ${u.service}`,"aria-expanded":n===u.id,className:"w-full flex flex-col gap-1.5 px-3 py-2.5 text-left cursor-pointer hover:bg-oai-gray-50 dark:hover:bg-oai-gray-800/40 rounded-lg transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand-500",children:[e.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[e.jsx(Ae,{provider:He(u.provider)||"OTHER",size:14}),e.jsx("span",{className:"text-sm font-medium text-oai-black dark:text-white truncate",children:u.service}),e.jsx("span",{role:"img","aria-label":u.autoRenew?r("subscriptions.badge.auto_renew"):r("subscriptions.badge.stops"),title:u.autoRenew?r("subscriptions.badge.auto_renew"):r("subscriptions.badge.stops"),className:`inline-flex shrink-0 translate-y-px ${u.autoRenew?"text-oai-brand-600 dark:text-oai-brand-400":"text-blue-600 dark:text-blue-400"}`,children:u.autoRenew?e.jsx(Ge,{size:14,strokeWidth:2,"aria-hidden":!0}):e.jsx(Ue,{size:14,strokeWidth:2,"aria-hidden":!0})}),u.plan?e.jsx("span",{className:"text-xs rounded-full border border-oai-gray-200 dark:border-oai-gray-700 px-2 py-0.5 text-oai-gray-500 dark:text-oai-gray-400 shrink-0",children:u.plan}):null]}),e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[10px] text-oai-gray-500 dark:text-oai-gray-400 shrink-0",children:r("subscriptions.inline.label")}),e.jsx("span",{className:"relative flex-1 bg-oai-gray-100 dark:bg-oai-gray-700/50 rounded-full h-1 overflow-hidden",children:e.jsx("span",{className:`${y?"bg-red-500":nt?"bg-amber-500":"bg-blue-500"} rounded-full h-full block transition-[width] duration-500 ease-out`,style:{width:`${O}%`,minWidth:O>0?"3px":0}})}),e.jsx("span",{className:`text-[10px] tabular-nums shrink-0 ${y?"text-oai-error":"text-oai-gray-400 dark:text-oai-gray-500"}`,children:qe(p,C)})]})]}),n===u.id?e.jsx("div",{className:"border-t border-oai-gray-100 dark:border-oai-gray-800",children:U()}):null,n!==u.id&&st?e.jsxs("div",{className:"px-3 pb-3 flex flex-col gap-2 border-t border-oai-gray-100 dark:border-oai-gray-800",children:[e.jsxs("p",{className:"pt-2 text-xs text-oai-gray-600 dark:text-oai-gray-300",children:[e.jsx("span",{className:"text-oai-gray-400 dark:text-oai-gray-500",children:u.autoRenew?r("subscriptions.label.renews_at"):r("subscriptions.label.expires_at")})," ",e.jsx("span",{className:"font-mono tabular-nums",children:K.format(new Date(p))})," · ",e.jsx("span",{className:y?"text-oai-error":void 0,children:fe(p,C)})," · ",e.jsx("span",{children:u.autoRenew?r("subscriptions.status.auto_renew"):r("subscriptions.status.manual")})]}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(B,{type:"button",variant:"secondary",size:"sm",onClick:()=>$(u),children:r("subscriptions.edit")})})]}):null]},u.id)}),i&&!n?e.jsx("li",{className:"rounded-lg border border-oai-gray-100 dark:border-oai-gray-800",children:U()}):null]}),e.jsx(jt,{open:!!w,title:r("subscriptions.confirm_delete_title"),description:w?.service||"",error:ne?r("subscriptions.delete_error"):null,confirmLabel:r("subscriptions.delete"),cancelLabel:r("shared.action.cancel"),destructive:!0,busy:q,onCancel:()=>{E(null),F(!1)},onConfirm:J})]})}const De=typeof window<"u"&&(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1"),fa="x-apple.systempreferences:com.apple.preference.notifications";function ba(){const t=Dt(),a=mt(),i=r("limits.alert.blocked"),s=a?ke.button:ke.div;return e.jsxs(s,{type:a?"button":void 0,onClick:a?()=>xt({type:"action",name:"openURL",value:fa}):void 0,initial:t?!1:{opacity:0,x:14,scale:.9},animate:{opacity:1,x:0,scale:1},transition:{type:"spring",stiffness:320,damping:18},title:i,className:`relative hidden sm:inline-flex min-w-0 max-w-[360px] items-center gap-1.5 rounded-full border border-amber-300/70 bg-amber-50 px-3 py-1.5 text-xs text-amber-700 dark:border-amber-500/30 dark:bg-amber-500/10 dark:text-amber-300 ${a?"cursor-pointer transition-colors hover:bg-amber-100 dark:hover:bg-amber-500/20 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-amber-500/60":""}`,children:[e.jsxs("span",{className:"relative flex h-1.5 w-1.5 shrink-0",children:[e.jsx("span",{className:"absolute inline-flex h-full w-full animate-ping rounded-full bg-amber-400 opacity-75"}),e.jsx("span",{className:"relative inline-flex h-1.5 w-1.5 rounded-full bg-amber-500"})]}),e.jsx("span",{className:"truncate",children:i}),e.jsx("span",{"aria-hidden":!0,className:"absolute left-full top-1/2 -translate-y-1/2 border-[5px] border-transparent border-l-amber-300/80 dark:border-l-amber-500/40"})]})}function za(){const t=lt(),{data:a,error:i,isLoading:s}=ht(t?{initialRefresh:!0,initialState:t,publishToPreloadCache:!0}:{initialRefresh:!0,publishToPreloadCache:!0}),n=yt(),o=ft(),[l,c]=D.useState([]),[d,m]=D.useState(!1),[h,f]=D.useState(!1),[b]=ct(),N=D.useRef(0),T=D.useCallback(async()=>{if(!De&&!ve())return;const _=++N.current;try{const w=await ua();if(_!==N.current)return;c(w),m(!1)}catch{if(_!==N.current)return;m(!0)}},[]);return D.useEffect(()=>{T()},[T]),D.useEffect(()=>{b.get("openSubscriptions")==="1"&&f(!0)},[b]),D.useEffect(()=>{o.enabled&&a&&bt(a)},[o.enabled,a]),!De&&!ve()?e.jsx("div",{className:"flex flex-col flex-1 text-oai-black dark:text-oai-white font-oai antialiased",children:e.jsx(wt,{})}):e.jsx("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:"flex flex-row items-start justify-between gap-4 mb-8",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("h1",{className:"text-3xl sm:text-4xl font-semibold tracking-tight text-oai-black dark:text-white mb-3",children:r("nav.limits")}),e.jsx("p",{className:"text-oai-gray-500 dark:text-oai-gray-400 text-sm sm:text-base",children:r("limits.page.subtitle")})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[o.enabled&&o.permissionBlocked?e.jsx(ba,{}):null,e.jsxs(_t,{open:h,onOpenChange:f,children:[e.jsx(Ct,{"aria-label":r("limits.page.openSubscriptions"),title:r("limits.page.openSubscriptions"),className:"shrink-0 inline-flex h-9 w-9 items-center justify-center rounded-lg border border-oai-gray-200 dark:border-oai-gray-800 text-oai-gray-600 dark:text-oai-gray-400 hover:bg-oai-gray-100 dark:hover:bg-oai-gray-800 hover:text-oai-black dark:hover:text-white transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand-500",children:e.jsx(Fe,{className:"h-4 w-4","aria-hidden":!0})}),e.jsx(Pt,{children:e.jsx(Mt,{side:"bottom",align:"end",sideOffset:8,className:"z-50",children:e.jsx(St,{children:e.jsx(ha,{subscriptions:l,onChanged:T})})})})]}),e.jsx("button",{type:"button",onClick:()=>{o.setEnabled(!o.enabled)},"aria-label":o.enabled?r("limits.alert.disable"):r("limits.alert.enable"),title:o.enabled?r("limits.alert.disable"):r("limits.alert.enable"),className:`inline-flex h-9 w-9 items-center justify-center rounded-lg border border-oai-gray-200 dark:border-oai-gray-800 hover:bg-oai-gray-100 dark:hover:bg-oai-gray-800 transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand-500 ${o.enabled&&o.permissionBlocked?"text-amber-600 dark:text-amber-400":"text-oai-gray-600 dark:text-oai-gray-400 hover:text-oai-black dark:hover:text-white"}`,children:o.enabled?e.jsx(Et,{className:"h-4 w-4","aria-hidden":!0}):e.jsx(Tt,{className:"h-4 w-4","aria-hidden":!0})}),e.jsx(dt,{to:"/settings?section=limits","aria-label":r("limits.page.openSettings"),title:r("limits.page.openSettings"),className:"shrink-0 inline-flex h-9 w-9 items-center justify-center rounded-lg border border-oai-gray-200 dark:border-oai-gray-800 text-oai-gray-600 dark:text-oai-gray-400 hover:bg-oai-gray-100 dark:hover:bg-oai-gray-800 hover:text-oai-black dark:hover:text-white transition-colors no-underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand-500",children:e.jsx(ut,{className:"h-4 w-4","aria-hidden":!0})})]})]}),s?e.jsx(Rt,{}):e.jsxs(e.Fragment,{children:[i?e.jsx("p",{className:"mb-4 text-sm text-red-500 dark:text-red-400",children:r("shared.error.prefix",{error:i})}):null,d?e.jsx("p",{className:"mb-4 text-sm text-amber-600 dark:text-amber-400",children:r("subscriptions.load_error")}):null,e.jsx(da,{claude:a?.claude,codex:a?.codex,cursor:a?.cursor,gemini:a?.gemini,kimi:a?.kimi,kiro:a?.kiro,grok:a?.grok,antigravity:a?.antigravity,copilot:a?.copilot,zcode:a?.zcode,opencodeGo:a?.opencodeGo,commandCode:a?.commandCode,qoder:a?.qoder,qoderCn:a?.qoderCn,codingPlan:a?.codingPlan,agentPlan:a?.agentPlan,devin:a?.devin,order:n.order,visibility:n.visibility,displayMode:n.displayMode,subscriptions:l,showSubscriptions:n.showSubscriptions!==!1})]})]})})})}export{za as LimitsPage};
@@ -1,3 +0,0 @@
1
- import{o as Te,r as n,j as e,y as B,c as s,Z as Le,X as Fe,i as k,az as be,W as _e,R as rs,V as pe,aM as os,bc as Z}from"./__vite-browser-external-Bq8nj-JV.js";import{L as ns,I as is}from"./LocalOnlyNotice-B6nDke_u.js";import{S as ne}from"./Select-Q8mS3_od.js";import{C as ls}from"./chevron-down-BIMuk6oN.js";import{S as Re}from"./search-DdQRwFYV.js";import{C as cs}from"./check-HAS31kTT.js";import{P as ds,a as us,b as ms,c as xs,d as gs}from"./PopoverPopup-Ch6NLnu6.js";import{P as Oe}from"./ProviderIcon-BRY2br-g.js";import{H as hs}from"./HoverTooltip-WFd21iP9.js";import{u as ye}from"./useCurrency-t3PYQi1l.js";import{i as ps,C as fs}from"./host-mode-JzrhHX7F.js";import{L as bs}from"./loader-circle-KVUaEKV2.js";import{I as ys}from"./info-D-RLFnSK.js";import{a as ks,b as _s,c as js,d as vs,e as ws}from"./TooltipPopup-C_bF2ZwO.js";import"./arrow-up-right-DQ6QfCpo.js";import"./download-9RgsZIiH.js";import"./SelectItemText-C1id8GDj.js";import"./composite-kLwqpqEk.js";import"./usePositioner-C59mj6kG.js";import"./store-DstuWd4a.js";import"./safePolygon-C_sPnJ1L.js";const Ie={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"}]]};Ie.node;const Ns=Te(Ie);const Pe={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"}]]};Pe.node;const Ss=Te(Pe),Cs="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 je({options:a,value:t,onChange:r,allValue:o="all",allLabel:d,searchPlaceholder:g,emptyLabel:m,ariaLabel:b,disabled:y=!1,className:j=""}){const[v,w]=n.useState(!1),[N,f]=n.useState(""),[_,p]=n.useState(-1),L=n.useRef(null),C=`${n.useId()}-listbox`,$=t===o?d:a.find(u=>u.value===t)?.label??t,M=N.trim().toLowerCase(),T=n.useMemo(()=>M?a.filter(u=>u.label.toLowerCase().includes(M)):a,[a,M]),S=n.useMemo(()=>[{value:o,label:d},...T],[o,d,T]),O=_>=0&&_<S.length?S[_]:null,A=u=>{r(u),w(!1),f(""),p(-1)};n.useEffect(()=>{v&&L.current?.querySelector('[data-active="true"]')?.scrollIntoView?.({block:"nearest"})},[v,_]);const X=u=>{if(u.key==="ArrowDown"||u.key==="ArrowUp"){u.preventDefault();const D=u.key==="ArrowDown";p(R=>{const l=S.length;return l?D?R>=l-1?0:R+1:R<=0?l-1:R-1:-1});return}if(u.key==="Enter"){const D=O||(M&&T.length?T[0]:null);if(!D)return;u.preventDefault(),A(D.value)}};return e.jsxs(ds,{open:v,onOpenChange:u=>{w(u),p(-1),u||f("")},children:[e.jsxs(us,{disabled:y,"aria-label":b,className:B("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(Ss,{className:"h-3.5 w-3.5 shrink-0 text-oai-gray-400","aria-hidden":!0}),e.jsx("span",{className:"truncate",children:$}),e.jsx(ls,{className:"h-3.5 w-3.5 shrink-0 text-oai-gray-400","aria-hidden":!0})]}),e.jsx(ms,{children:e.jsx(xs,{sideOffset:4,side:"bottom",align:"start",className:"z-[60]",children:e.jsxs(gs,{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(Re,{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":C,"aria-activedescendant":O?`${C}-${_}`:void 0,value:N,onChange:u=>{f(u.target.value),p(-1)},onKeyDown:X,placeholder:g,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:C,role:"listbox","aria-label":b,className:"max-h-64 overflow-y-auto",children:[S.map((u,D)=>e.jsxs("button",{id:`${C}-${D}`,type:"button",role:"option","aria-selected":t===u.value,"data-active":D===_?"true":void 0,onMouseEnter:()=>p(D),onClick:()=>A(u.value),className:B(Cs,t===u.value&&"bg-oai-gray-100 dark:bg-oai-gray-800",D===_&&"ring-1 ring-inset ring-oai-gray-300 dark:ring-oai-gray-600"),children:[e.jsx("span",{className:"flex-1 truncate",children:u.label}),t===u.value?e.jsx(cs,{className:"h-3.5 w-3.5 shrink-0","aria-hidden":!0}):null]},u.value)),T.length===0?e.jsx("div",{className:"px-2 py-3 text-center text-xs text-oai-gray-400 dark:text-oai-gray-500",children:m}):null]})]})})})]})}const Ms="tokentracker-sessions";async function Ds(a={}){const t=new URL(`/functions/${Ms}`,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 d=r.status===404?s("sessions.error.outdated_app"):`Request failed with HTTP ${r.status}`,g=new Error(o?.error||d);throw g.status=r.status,g}return o}function Ee(a,t,{timeOnly:r=!1}={}){if(!a)return"—";const o=Date.parse(a);if(!Number.isFinite(o))return"—";const d=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,d)}catch{const g=new Date(o).toISOString();return r?g.slice(11,16):g.slice(0,16).replace("T"," ")}}function $e(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),d=r%60;return s("sessions.duration.hours",{hours:o,minutes:d})}function te(a){return H(a?.own_total_tokens??a?.total_tokens)}function ae(a){return H(a?.own_cost_usd??a?.cost_usd)}function H(a){const t=Number(a);return Number.isFinite(t)&&t>=0?t:0}function V(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:te(a),cost_usd:ae(a),performance:a?.performance}]}function Ts(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 d=H(o.estimated_duration_ms),g=H(o.estimated_output_tokens),m=H(o.estimated_request_count);d>0&&g>0&&m>0&&(t.estimated_output_tokens+=g,t.estimated_duration_ms+=d,t.estimated_request_count+=m);const b=H(o.first_response_sample_count),y=H(o.first_response_total_ms);b>0&&y>0&&(t.first_response_total_ms+=y,t.first_response_sample_count+=b)}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 Ae(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,d)=>o+te(d),0),cost:r.reduce((o,d)=>o+ae(d),0),costIsPartial:r.some(o=>o.cost_is_partial),performance:Ts(r)}}function fe(a){const t=Date.parse(a?.ended_at||a?.started_at||"");return Number.isFinite(t)?t:0}function Ls(a,t){return[...a].sort((r,o)=>(t==="cost"?ae(o)-ae(r):t==="tokens"?te(o)-te(r):0)||fe(o)-fe(r))}function le(a){const t=fe(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 Fs(a,t){const r=new Map;for(const o of a){const d=t==="project"?o.project_key||"":le(o),g=r.get(d)||{key:d,sessions:[]};g.sessions.push(o),r.set(d,g)}return[...r.values()]}function Rs(a){const t=new URLSearchParams(a),r=t.get("source"),o=m=>{const b=t.get(m)||"";if(!/^\d{4}-\d{2}-\d{2}$/.test(b))return"";const y=new Date(`${b}T00:00:00`);return Number.isFinite(y.getTime())&&le({ended_at:y.toISOString()})===b?b:""},d=o("from"),g=o("to");return{source:["claude","codex","grok"].includes(r)?r:"all",model:t.get("model")||"all",from:d,to:g}}function Os(a,t,r){let o=t?new Date(`${t}T00:00:00`).getTime():0,d=r?new Date(`${r}T23:59:59.999`).getTime():1/0;o>d&&(o=new Date(`${r}T00:00:00`).getTime(),d=new Date(`${t}T23:59:59.999`).getTime());const g=Date.parse(a.ended_at||a.started_at||""),m=Date.parse(a.started_at||a.ended_at||"");return(!Number.isFinite(g)||g>=o)&&(!Number.isFinite(m)||m<=d)}function se({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 Is=[{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")}],Ps=[{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 Es(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 ve(a){return String(a||"").startsWith("litellm")?s("sessions.detail.pricing_litellm"):String(a||"").startsWith("curated")?s("sessions.detail.pricing_curated"):null}function $s(a,t){return t||Number(a)>0}function we({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 ie({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 As({session:a,subagents:t=[],onClose:r}){const o=n.useRef(null),d=n.useRef(null),{currency:g,rate:m}=ye(),{resolvedLocale:b}=Le(),y=l=>be(l,{currency:g,rate:m}),j=V(a),v=n.useMemo(()=>Ae(t),[t]),w=te(a),N=ae(a),f=Number(a.subagent_total_tokens??v.tokens),_=Number(a.subagent_cost_usd??v.cost),p=a.performance,L=Number(p?.estimated_tokens_per_second)>0&&Number(p?.estimated_request_count)>0,C=Number(p?.first_response_sample_count)>0&&p?.first_response_ms!=null&&Number.isFinite(Number(p.first_response_ms)),$=C?{seconds:(Number(p.first_response_ms)/1e3).toFixed(2),count:p.first_response_sample_count}:null,M=Number(a.reasoning_output_tokens)>0,T=a.source==="grok",S=T&&Number(a.context_window_tokens)>0;n.useEffect(()=>{const l=document.activeElement,I=document.body.style.overflow;document.body.style.overflow="hidden",o.current?.focus();const P=F=>{if(F.key==="Escape"&&(F.preventDefault(),r()),F.key!=="Tab")return;const K=Array.from(d.current?.querySelectorAll('button:not([disabled]), a[href], input:not([disabled]), summary, [tabindex="0"]')||[]),Y=K[0],J=K[K.length-1];Y?F.shiftKey&&(document.activeElement===Y||!d.current?.contains(document.activeElement))?(F.preventDefault(),J.focus()):!F.shiftKey&&(document.activeElement===J||!d.current?.contains(document.activeElement))&&(F.preventDefault(),Y.focus()):(F.preventDefault(),d.current?.focus())};return window.addEventListener("keydown",P),()=>{window.removeEventListener("keydown",P),document.body.style.overflow=I,l instanceof HTMLElement&&l.isConnected&&l.focus()}},[r]);const O=f>0||_>0,A=a.cost_is_partial||O&&v.costIsPartial,X=[{label:s("sessions.detail.own"),tokens:w,cost:N,partial:a.cost_is_partial},{label:s("sessions.detail.subagents"),tokens:f,cost:_,partial:v.costIsPartial}],u=a.agent_nickname||a.title||a.project_key||s("sessions.project.unknown"),D=$e(a.duration_ms),R=[a.project_key&&a.project_key!==u?a.project_key:null,Ee(a.started_at,b),D].filter(Boolean);return e.jsx("div",{className:"fixed inset-0 z-50 flex justify-end bg-black/20 dark:bg-black/40",onClick:l=>{l.target===l.currentTarget&&r()},children:e.jsxs("div",{ref:d,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(Oe,{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:u}),e.jsx("p",{className:"mt-0.5 break-words text-xs tabular-nums text-oai-gray-500 dark:text-oai-gray-400",children:R.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(Fe,{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(ie,{label:s("sessions.col.tokens"),children:k(w+f)}),e.jsxs(ie,{label:s("sessions.col.cost"),className:"border-l",children:[A?"≥":"",y(N+_)]}),e.jsx(ie,{label:s("sessions.summary.speed"),className:"border-t",title:L?s("sessions.performance.samples",{count:p.estimated_request_count}):s("sessions.detail.no_speed"),children:L?e.jsx(se,{performance:p}):"—"}),e.jsx(ie,{label:s("sessions.performance.first_response"),className:"border-l border-t",title:s("sessions.performance.first_response_method"),children:C?Number(p.first_response_sample_count)===1?s("sessions.performance.first_response_value_single",$):s("sessions.performance.first_response_value",$):"—"})]}),O?e.jsx("dl",{className:"mt-3 space-y-1.5",children:X.map(l=>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:l.label}),e.jsx("dd",{className:"text-right tabular-nums",children:k(l.tokens)}),e.jsxs("dd",{className:"text-right tabular-nums",children:[l.partial?"≥":"",y(l.cost)]})]},l.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")," · ",Es(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:Is.map(({key:l,label:I})=>e.jsx(we,{label:I(),children:a[l]==null?"—":k(a[l])},l))})]}),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(l=>{const I=l.pricing?.status==="unpriced",P=a.cost_source==="provider_reported"&&j.length===1,F=P?N:l.cost_usd,K=$s(F,P);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:l.model||s("sessions.model.unknown")}),e.jsx("span",{className:"text-right tabular-nums",children:k(l.total_tokens)}),e.jsx("span",{className:"text-right tabular-nums",children:I&&!K?"—":y(F)})]}),l.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(se,{performance:l.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:[I?e.jsx("p",{children:s("sessions.detail.pricing_unpriced")}):null,l.pricing.status==="free"?e.jsx("p",{children:s("sessions.detail.pricing_free")}):null,l.pricing.status==="priced"?e.jsx("p",{children:s("sessions.detail.pricing_rates",{input:l.pricing.input,output:l.pricing.output,cacheRead:l.pricing.cache_read,cacheWrite:l.pricing.cache_write})}):null,ve(l.pricing.source)?e.jsx("p",{children:ve(l.pricing.source)}):null]})]}):e.jsx(se,{performance:l.performance,className:"block pt-1 text-xs tabular-nums text-oai-gray-500 dark:text-oai-gray-400"})]},l.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:Ps.map(({key:l,label:I,grokOnly:P})=>e.jsx(we,{label:I(),children:typeof a[l]=="number"&&(!P||T)?k(a[l]):s("sessions.detail.not_recorded")},l))}),T&&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:k(a.model_calls),seconds:(Number(a.api_duration_ms||0)/1e3).toFixed(1),tools:k(a.tool_calls),errors:k(a.error_count)})}):null,S?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:k(a.context_tokens_used),window:k(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 Ne=ps(),Se=[],he=100,qs=[{id:"all",label:()=>s("usage.filter.source_all")},{id:"claude",label:()=>"Claude Code"},{id:"codex",label:()=>"Codex"},{id:"grok",label:()=>"Grok"}],qe=[{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 Ks(a){const t=qe.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 zs(a,t){if(!t)return!0;const r=Date.parse(a.ended_at||a.started_at||"");return Number.isFinite(r)?r>=t:!0}function Us(a){const t=Date.parse(a.started_at||"");return!Number.isFinite(t)||le({started_at:a.started_at})===le(a)}function Ce(a){const t=V(a);return t.length===1?t[0].model||s("sessions.model.unknown"):t.map(r=>`${r.model} ${k(Number(r.total_tokens||0))}`).join(" · ")}async function Me(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 Gs(){const[a,t]=n.useState(!1),r=n.useId();return e.jsxs(ks,{open:a,onOpenChange:t,children:[e.jsx(_s,{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(ys,{className:"h-3.5 w-3.5","aria-hidden":!0})}),e.jsx(js,{children:e.jsx(vs,{side:"bottom",align:"end",sideOffset:12,className:"z-[60]",children:e.jsx(ws,{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 De=pe.memo(function({session:t,locale:r,nested:o=!1,timeOnly:d=!1,childCount:g=0,expanded:m=!1,onToggle:b,onDetail:y}){const{currency:j,rate:v}=ye(),w=String(t.source||"").toUpperCase(),N=$e(t.duration_ms),f=t.resume_command,_=t.project_key||s("sessions.project.unknown"),p=o||t.thread_kind==="subagent",L=p?t.agent_nickname||t.agent_role||t.title||_:t.title||_,C=t.usage_is_incomplete?s("sessions.badge.partial_usage"):t.cost_is_partial?s("sessions.badge.partial_cost"):null,$=t.project_ref?`${t.project_ref}
3
- ${s("sessions.project.copy_hint")}`:void 0,M=async()=>{if(t.project_ref)try{await Me(t.project_ref)?Z({title:s("sessions.project.copied")}):Z({title:s("sessions.project.copy_failed")})}catch{Z({title:s("sessions.project.copy_failed")})}},T=O=>e.jsxs("span",{className:"group relative inline-flex min-w-0 max-w-full",children:[e.jsx(hs,{text:$,placement:"bottom"}),e.jsx("button",{type:"button",onClick:M,"aria-label":s("sessions.project.copy_aria",{project:_}),className:B("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:_})]}),S=async()=>{if(f)try{await Me(f)?Z({title:s("sessions.resume.copied")}):Z({title:s("sessions.resume.copy_failed")})}catch{Z({title:s("sessions.resume.copy_failed")})}};return e.jsxs("li",{className:B("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(Oe,{provider:w,size:o?16:18})}),e.jsxs("div",{className:"contents",children:[e.jsx("button",{type:"button",onClick:()=>y(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?T("min-h-6 inline-flex items-center md:min-h-0"):e.jsx("span",{className:"truncate",children:_})}),e.jsx("span",{className:"sessions-meta-item min-w-0 max-w-full truncate",title:Ce(t),children:Ce(t)}),e.jsx("span",{className:"sessions-meta-item tabular-nums",children:Ee(t.started_at,r,{timeOnly:d&&Us(t)})}),N?e.jsx("span",{className:"sessions-meta-item tabular-nums",children:N}):null,p?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,C?e.jsx("span",{className:"sessions-meta-item text-amber-700 dark:text-amber-300",children:C}):null,t.cost_source==="provider_reported"?e.jsx("span",{className:"sessions-meta-item",children:s("sessions.badge.reported_cost")}):null,g?e.jsxs("button",{type:"button",onClick:()=>b(t.session_hash),"aria-expanded":m,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(os,{className:B("h-3.5 w-3.5 transition-transform",m&&"rotate-90"),"aria-hidden":!0}),m?s("sessions.thread.collapse",{count:g}):s("sessions.thread.expand",{count:g})]}):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:k(t.own_total_tokens),subagents:k(t.subagent_total_tokens),combined:k(t.combined_total_tokens)}):void 0,className:"mt-1 text-sm tabular-nums text-oai-black dark:text-white md:mt-0",children:[k(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:["Σ ",k(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?"≥":"",be(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(se,{performance:t.performance})})]})]}),e.jsx("button",{type:"button",onClick:S,disabled:!f,title:f||s("sessions.resume.unavailable"),"aria-label":f?s("sessions.resume.copy_aria",{command:f}):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(fs,{className:"h-4 w-4","aria-hidden":!0})})]})});function Ws({sessions:a,selectedModel:t,onSelect:r}){const{groups:o,totalTokens:d}=n.useMemo(()=>{const m=new Map;let b=0;for(const y of a)for(const j of V(y)){const v=j.model||s("sessions.model.unknown"),w=Number(j.total_tokens||0),N=m.get(v)||{model:v,count:0,tokens:0};N.count+=1,N.tokens+=w,b+=w,m.set(v,N)}return{groups:[...m.values()].sort((y,j)=>j.tokens-y.tokens),totalTokens:b}},[a]);function g(m){return B("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",m?"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:g(t==="all"),children:s("sessions.thread.model_all",{count:a.length,tokens:k(d)})}),o.map(m=>e.jsx("button",{type:"button","aria-pressed":t===m.model,onClick:()=>r(m.model),className:g(t===m.model),children:s("sessions.thread.model_item",{model:m.model,count:m.count,tokens:k(m.tokens)})},m.model))]})})}function xt(){const[a]=n.useState(()=>Rs(window.location.search)),[t,r]=n.useState(null),[o,d]=n.useState(null),[g,m]=n.useState(!0),[b,y]=n.useState(!1),[j,v]=n.useState(a.source),[w,N]=n.useState(a.model),[f,_]=n.useState(a.from||a.to?"custom":"all"),[p,L]=n.useState(a.from),[C,$]=n.useState(a.to),[M,T]=n.useState("all"),[S,O]=n.useState("time"),[A,X]=n.useState("recent"),[u,D]=n.useState(null),[R,l]=n.useState(""),[I,P]=n.useState(he),[F,K]=n.useState(()=>new Set),[Y,J]=n.useState(()=>new Map),re=n.useRef(0),{resolvedLocale:G}=Le(),{currency:Ke,rate:ze}=ye(),oe=n.useCallback(async(i=!1)=>{const x=++re.current;i?y(!0):m(!0),d(null);try{const c=await Ds({refresh:i});x===re.current&&r(c)}catch(c){x===re.current&&d(c?.message||String(c))}finally{x===re.current&&(m(!1),y(!1))}},[]);n.useEffect(()=>{Ne||_e()?oe(!1):m(!1)},[oe]);const E=t?.sessions||Se,Ue=n.useMemo(()=>{const i=new Set,x=[];for(const c of E){const h=c.project_key;!h||i.has(h)||(i.add(h),x.push({value:h,label:h}))}return x.sort((c,h)=>c.label.localeCompare(h.label))},[E]),Ge=n.useMemo(()=>{const i=new Set;for(const x of E)for(const c of V(x))c.model&&i.add(c.model);return[...i].sort().map(x=>({value:x,label:x}))},[E]),ce=n.useDeferredValue(R),z=n.useMemo(()=>{const i=ce.trim().toLowerCase(),x=Ks(f);return E.filter(c=>{if(j!=="all"&&c.source!==j||M!=="all"&&c.project_key!==M||w!=="all"&&!V(c).some(U=>U.model===w))return!1;if(f==="custom"){if(!Os(c,p,C))return!1}else if(!zs(c,x))return!1;if(!i)return!0;const h=V(c).map(U=>U.model).join(" ");return`${c.title||""} ${c.project_key||""} ${h} ${c.agent_nickname||""} ${c.agent_role||""} ${c.project_ref||""} ${c.session_id||""}`.toLowerCase().includes(i)})},[E,j,M,w,f,p,C,ce]),Q=n.useMemo(()=>Ae(z),[z]),W=n.useMemo(()=>{const i=new Set(z.map(h=>h.session_hash)),x=new Map,c=[];for(const h of Ls(z,A)){const q=h.root_session_hash||h.parent_session_hash;if(h.parent_session_hash&&q&&i.has(q)){const U=x.get(q)||[];U.push(h),x.set(q,U)}else c.push(h)}return{roots:c,childrenByRoot:x,foldedCount:z.length-c.length}},[z,A]),de=j!=="all"||w!=="all"||f!=="all"||M!=="all"||R.trim()!=="";n.useEffect(()=>{P(he),K(new Set),J(new Map)},[j,M,w,f,p,C,ce,A,S,E]);const ue=n.useMemo(()=>W.roots.slice(0,I),[W.roots,I]),We=n.useMemo(()=>Fs(ue,S),[ue,S]),He=n.useMemo(()=>u?E.filter(i=>i.session_hash!==u.session_hash&&(i.root_session_hash===u.session_hash||i.parent_session_hash===u.session_hash)):Se,[E,u]),Ve=n.useCallback(()=>D(null),[]),me=n.useCallback(i=>{_(i),i!=="custom"&&(L(""),$(""))},[]),Be=n.useCallback(()=>{v("all"),N("all"),T("all"),l(""),me("all")},[me]),xe=W.roots.length>ue.length,ge=n.useCallback(()=>P(i=>i+he),[]),Qe=n.useCallback(i=>{K(x=>{const c=new Set(x);return c.has(i)?c.delete(i):c.add(i),c})},[]),Ze=n.useCallback((i,x)=>{J(c=>{const h=new Map(c);return x==="all"?h.delete(i):h.set(i,x),h})},[]),ke=n.useRef(null);n.useEffect(()=>{if(!xe||typeof IntersectionObserver>"u")return;const i=ke.current;if(!i)return;const x=new IntersectionObserver(c=>{c.some(h=>h.isIntersecting)&&ge()},{rootMargin:"400px"});return x.observe(i),()=>x.disconnect()},[xe,ge]);const Xe=n.useMemo(()=>qs.map(i=>({value:i.id,label:i.label()})),[G]),Ye=n.useMemo(()=>[...qe.map(i=>({value:i.id,label:i.label()})),{value:"custom",label:s("sessions.filter.range_custom")}],[G]),Je=n.useMemo(()=>[{value:"time",label:s("sessions.group.time")},{value:"project",label:s("sessions.group.project")}],[G]),es=n.useMemo(()=>[{value:"recent",label:s("sessions.sort.recent")},{value:"cost",label:s("sessions.sort.cost")},{value:"tokens",label:s("sessions.sort.tokens")}],[G]),ss=Number(t?.session_count)>Number(t?.returned_count);return!Ne&&!_e()?e.jsx("div",{className:"flex flex-col flex-1 text-oai-black dark:text-oai-white font-oai antialiased",children:e.jsx(ns,{})}):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:b||g,"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(rs,{className:B("h-4 w-4",b&&"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(Re,{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(is,{type:"search",value:R,onChange:i=>l(i.target.value),onKeyDown:i=>{i.key==="Escape"&&R&&(i.preventDefault(),l(""))},"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"}),R?e.jsx("button",{type:"button",onMouseDown:i=>i.preventDefault(),onClick:()=>l(""),"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(Fe,{className:"h-4 w-4","aria-hidden":!0})}):null]}),e.jsx(ne,{ariaLabel:s("sessions.filter.source_aria"),options:Xe,value:j,onValueChange:v,className:"sessions-filter-trigger h-11 min-w-0 px-3 text-sm sm:h-9",matchTriggerWidth:!0}),e.jsx(ne,{ariaLabel:s("sessions.filter.range_aria"),options:Ye,value:f,onValueChange:me,leadingIcon:e.jsx(Ns,{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(je,{options:Ue,value:M,onChange:T,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(je,{options:Ge,value:w,onChange:N,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"})]}),f==="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:p,onChange:i=>L(i.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:C,onChange:i=>$(i.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]}),!g&&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:k(Q.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:k(Q.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:[Q.costIsPartial?"≥":"",be(Q.cost,{currency:Ke,rate:ze})]})]}),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(Gs,{})]}),e.jsxs("dd",{className:"mt-1 text-lg font-medium tabular-nums",children:[e.jsx(se,{performance:Q.performance}),Q.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:W.foldedCount>0?s("sessions.thread.result_count",{roots:W.roots.length,subagents:W.foldedCount}):s("sessions.filter.result_count",{filtered:z.length,total:E.length})}),de?e.jsx("button",{type:"button",onClick:Be,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(ne,{ariaLabel:s("sessions.group.aria"),options:Je,value:S,onValueChange:O,className:"sessions-filter-trigger h-11 min-w-0 max-w-40 px-2.5 text-xs sm:h-8"}),e.jsx(ne,{ariaLabel:s("sessions.sort.aria"),options:es,value:A,onValueChange:X,className:"sessions-filter-trigger h-11 min-w-0 max-w-44 px-2.5 text-xs sm:h-8",align:"end"})]})]}),ss?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")})]}):g?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(bs,{className:"h-4 w-4 animate-spin","aria-hidden":!0}),s("sessions.loading")]}):z.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:de?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:de?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:We.map(i=>e.jsxs(pe.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:S==="project"?i.key||s("sessions.project.unknown"):i.key?new Date(`${i.key}T12:00:00`).toLocaleDateString(G||void 0,{year:"numeric",month:"short",day:"numeric"}):s("sessions.group.unknown_date")})}),i.sessions.map(x=>{const c=W.childrenByRoot.get(x.session_hash)||[],h=F.has(x.session_hash),q=Y.get(x.session_hash)||"all",U=q==="all"?c:c.filter(function(ts){return V(ts).some(as=>as.model===q)});return e.jsxs(pe.Fragment,{children:[e.jsx(De,{session:x,locale:G,timeOnly:S==="time",childCount:c.length,expanded:h,onToggle:Qe,onDetail:D}),h&&c.length?e.jsx(Ws,{sessions:c,selectedModel:q,onSelect:ee=>Ze(x.session_hash,ee)}):null,h?U.map(ee=>e.jsx(De,{session:ee,locale:G,nested:!0,timeOnly:S==="time",onDetail:D},ee.session_hash)):null]},x.session_hash)})]},i.key))}),xe?e.jsx("div",{ref:ke,className:"flex justify-center pt-6",children:e.jsx("button",{type:"button",onClick:ge,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")})]})}),u?e.jsx(As,{session:u,subagents:He,onClose:Ve}):null]})}export{xt as SessionsPage};
@@ -1,2 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/__vite-browser-external-Bq8nj-JV.js","assets/__vite-browser-external-BwmeEfv7.css"])))=>i.map(i=>d[i]);
2
- import{o as K,j as e,y as B,c as a,a as gt,r as l,ct as pt,cu as ht,cv as xt,cw as ft,a7 as X,cx as we,bu as bt,cy as yt,bt as Ne,cz as de,aP as $e,cA as vt,cB as jt,ag as ze,u as Fe,V as xe,x as kt,B as R,a8 as G,cC as wt,a9 as z,ax as Nt,cD as ue,a5 as Y,aB as _t,a1 as St,af as Ct,at as se,R as be,cE as Et,L as ne,aM as Pt,au as Ot,al as At,am as ye,ac as Lt,d as He,aa as fe,ab as Be,cF as _e,cG as Se,cH as Ce,cI as Tt,cJ as It,ao as Rt,Z as Ve,l as me,cK as Ee,k as Pe,cL as Dt,cM as Gt,cN as Ut,z as Mt,cO as $t,cP as zt,cQ as Ft,cR as Ht,cS as Bt,cT as Vt,cU as Kt,v as Ke,cq as qt,cV as Wt,bc as Oe,_ as Yt,e as Zt,cW as Jt,cX as Qt,bw as Xt}from"./__vite-browser-external-Bq8nj-JV.js";import{a as ea,b as Ae,s as ta,K as aa,P as sa,D as na,c as ia,S as ra,v as oa,u as la,C as ca}from"./sortable.esm-iqbm7x5D.js";import{a as da}from"./modifiers.esm-5NK8j3mT.js";import{d as Le,l as Te,u as ua,b as Ie}from"./use-limits-display-prefs-fqg8hs6b.js";import{P as ma}from"./ProviderIcon-BRY2br-g.js";import{m as qe}from"./react-gIVxucOB.js";import{a as V,T as D,b as E,S as W}from"./Controls-BjdIonTX.js";import{P as ga,C as We,a as pa,u as ha,b as xa}from"./CloudUsageExport-DQbDwiyk.js";import{C as fa}from"./check-HAS31kTT.js";import{C as ba,i as ya}from"./host-mode-JzrhHX7F.js";import{A as Ye}from"./index-CmD84EJi.js";import{r as va,C as ge,o as ja}from"./cloud-checkout-COmDwrUT.js";import{C as ka}from"./chevron-down-BIMuk6oN.js";import{C as pe}from"./Card-DUItW3xI.js";import{E as Re}from"./external-link-C_gYjHGF.js";import{a as wa,P as Na}from"./play-D0MaDCOx.js";import{I as Ze}from"./info-D-RLFnSK.js";import{a as _a,b as Sa,c as Ca,d as Ea,e as Pa}from"./TooltipPopup-C_bF2ZwO.js";import{L as Oa}from"./loader-circle-KVUaEKV2.js";import{u as Aa}from"./useCurrency-t3PYQi1l.js";import{u as La}from"./useTokenFormat-C0xQsBGf.js";import{S as ve}from"./Select-Q8mS3_od.js";import{u as ie}from"./use-native-settings-EAqAFx2x.js";import{C as Ta}from"./ConfirmModal-h9nISVy7.js";import{A as Ia}from"./arrow-up-right-DQ6QfCpo.js";import{D as Ra}from"./download-9RgsZIiH.js";import"./DialogTitle-BsaIbN8k.js";import"./composite-kLwqpqEk.js";import"./store-DstuWd4a.js";import"./SelectItemText-C1id8GDj.js";import"./usePositioner-C59mj6kG.js";import"./safePolygon-C_sPnJ1L.js";import"./DialogClose-BmVAmN-o.js";import"./DateRangePopover-DpKh-0l8.js";import"./calendar-days-D_pxFQvT.js";import"./PopoverPopup-Ch6NLnu6.js";import"./DialogDescription-C0Cgq67g.js";const Je={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"}]]};Je.node;const Da=K(Je);const Qe={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"}]]};Qe.node;const Ga=K(Qe);const Xe={name:"gift",size:24,node:[["path",{d:"M12 7v14",key:"1akyts"}],["path",{d:"M20 11v8a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2v-8",key:"1sqzm4"}],["path",{d:"M7.5 7a1 1 0 0 1 0-5A4.8 8 0 0 1 12 7a4.8 8 0 0 1 4.5-5 1 1 0 0 1 0 5",key:"kc0143"}],["rect",{x:"3",y:"7",width:"18",height:"4",rx:"1",key:"1hberx"}]]};Xe.node;const De=K(Xe);const et={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"}]]};et.node;const Ua=K(et);const tt={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"}]]};tt.node;const Ma=K(tt);const at={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"}]]};at.node;const $a=K(at);const st={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"}]]};st.node;const za=K(st);const nt={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"]};nt.node;const Fa=K(nt),Ha="shrink-0 text-oai-gray-900 dark:text-oai-gray-200";function Ba({checked:t,onChange:s,ariaLabel:r}){return e.jsx("button",{type:"button",role:"switch","aria-checked":t,"aria-label":r,onClick:s,className:B("relative inline-flex h-5 w-9 shrink-0 items-center rounded-full transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand-500",t?"bg-oai-brand-500":"bg-oai-gray-300 dark:bg-oai-gray-700"),children:e.jsx("span",{className:B("inline-block h-3.5 w-3.5 rounded-full bg-white transition-transform",t?"translate-x-[18px]":"translate-x-[3px]")})})}function Va({id:t,visible:s,onToggle:r}){const{attributes:n,listeners:i,setNodeRef:c,transform:m,transition:o,isDragging:d}=la({id:t}),y={transform:ca.Transform.toString(m)||void 0,transition:o,zIndex:d?20:void 0};return e.jsxs("div",{ref:c,style:y,className:B("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"),...n,...i,children:[e.jsx(Ua,{className:"h-4 w-4 shrink-0 text-oai-gray-400 dark:text-oai-gray-500",strokeWidth:1.75,"aria-hidden":!0}),Le(t)?e.jsx(ma,{provider:Le(t),size:18,className:B("pointer-events-none",Ha)}):null,e.jsx("span",{className:"flex-1 text-sm text-oai-gray-900 dark:text-oai-gray-200",children:Te(t)}),e.jsx("div",{onPointerDown:x=>x.stopPropagation(),children:e.jsx(Ba,{checked:s,onChange:r,ariaLabel:`${a("limits.settings.toggle_visible")}: ${Te(t)}`})})]})}function Ka({prefs:t}){const{order:s,visibility:r,toggle:n,moveToward:i}=t,c=ea(Ae(sa,{activationConstraint:{distance:6}}),Ae(aa,{coordinateGetter:ta})),m=({active:o,over:d})=>{d&&o.id!==d.id&&i(o.id,d.id)};return e.jsx(na,{sensors:c,collisionDetection:ia,modifiers:[da],onDragEnd:m,children:e.jsx(ra,{items:s,strategy:oa,children:e.jsx("div",{className:"flex flex-col",children:s.map(o=>e.jsx(Va,{id:o,visible:r[o]!==!1,onToggle:()=>n(o)},o))})})})}function qa(t){if(!t||typeof t!="object")return"";const s=t.user_metadata&&typeof t.user_metadata=="object"?t.user_metadata:{},r=t.profile&&typeof t.profile=="object"?t.profile:{},n=s.full_name||s.name||r.name||s.user_name||s.preferred_username;return typeof n=="string"&&n.trim()?n.trim():typeof t.email=="string"&&t.email.includes("@")?t.email.split("@")[0].trim()||t.email.trim():typeof t.email=="string"?t.email.trim():""}function Wa(t){return!t||typeof t!="object"?"":typeof t.email=="string"?t.email.trim():""}function Ya(t){const s=typeof t=="string"?t.trim():"";if(!s)return null;const r=s.match(/^@?([A-Za-z0-9][A-Za-z0-9-]{0,38})$/),n=s.match(/^https:\/\/github\.com\/([A-Za-z0-9][A-Za-z0-9-]{0,38})\/?$/i),i=r?.[1]||n?.[1];return i?`https://github.com/${i}`:null}function je(t,s){console.warn(`[tokentracker] settings ${t}:`,s)}function Za(t,s,r,n){const[i,c]=l.useState(()=>X()),m=s&&r&&ze(),o=l.useMemo(()=>({active:!0,busy:!1}),[t,s,r,n]),d=l.useRef(o);d.current=o;const[y,x]=l.useState(null),g=y?.scope===o?y:null;l.useEffect(()=>{o.active=!0;const j=()=>{const u=X();c(u),u||x(k=>k?.scope===o?{...k,error:null}:k)},p=()=>{x(u=>u?.scope===o?{...u,error:null}:u),de(n,"cloud-sync")};return j(),window.addEventListener("tt.cloudSyncChanged",j),window.addEventListener("storage",j),window.addEventListener(we,p),()=>{o.active=!1,window.removeEventListener("tt.cloudSyncChanged",j),window.removeEventListener("storage",j),window.removeEventListener(we,p)}},[o,n]);const b=l.useCallback(async()=>{if(!m||!X()||o.busy||!o.active||d.current!==o)return;o.busy=!0,x({scope:o,pending:!0,error:null});const j=()=>o.active&&d.current===o&&X();try{await bt(()=>t())}catch(p){if(!j())return;["cloud_membership_required","cloud_read_only_expired","cloud_history_window_exceeded","cloud_machine_limit","machine_limit_exceeded","cloud_machine_paused"].includes(p?.code)?yt(n,p.code,p.membership,"cloud-sync"):x({scope:o,pending:!0,error:{code:"billing_network_error"}}),je("cloud sync",p)}finally{o.busy=!1,o.active&&d.current===o&&x(p=>p?.scope===o?{...p,pending:!1}:p)}},[m,o,t,n]),v=l.useCallback(async()=>{if(!m||o.busy||!o.active||d.current!==o)return;const j=!X();x({scope:o,pending:!1,error:null}),Ne(j),c(j),j?await b():de(n,"cloud-sync")},[m,o,b,n]),N=l.useCallback(()=>{!m||!o.active||d.current!==o||(Ne(!1),c(!1),x(j=>j?.scope===o?{...j,error:null}:j),de(n,"cloud-sync"))},[m,o,n]);return{cloudSyncOn:i,cloudSyncPending:!!g?.pending,cloudSyncError:g?.error,handleCloudSyncToggle:v,handleCloudSyncRetry:b,handleCloudSyncDisable:N,showLocalCloudSync:m}}function Ja(t){const[s,r]=l.useState(!1),[n,i]=l.useState(!1),[c,m]=l.useState(!1),[o,d]=l.useState(!1),[y,x]=l.useState(null),[g,b]=l.useState(!1),[v,N]=l.useState(""),[j,p]=l.useState(!1),[u,k]=l.useState(""),[C,h]=l.useState(""),[S,_]=l.useState(!1),[w,A]=l.useState(null),T=l.useMemo(()=>qa(t),[t]),f=l.useMemo(()=>Wa(t),[t]),P=l.useMemo(()=>typeof t?.id=="string"?t.id.trim():"",[t]),U=l.useMemo(()=>({setAnonymousOn:i,setCustomDisplayName:x,setGithubUrl:k,setProfileLoading:m,setPublicProfileOn:r,setShowGithubOn:p}),[]);return{anonymousOn:n,customDisplayName:y,displayName:T,editingGithub:S,editingName:g,email:f,githubError:w,githubInput:C,githubUrl:u,loadSetters:U,nameInput:v,profileLoading:c,profileSaving:o,publicProfileOn:s,setAnonymousOn:i,setCustomDisplayName:x,setEditingGithub:_,setEditingName:b,setGithubError:A,setGithubInput:h,setGithubUrl:k,setNameInput:N,setProfileLoading:m,setProfileSaving:d,setPublicProfileOn:r,setShowGithubOn:p,showGithubOn:j,userId:P}}function Qa(t,s,r){l.useEffect(()=>{if(!s)return;let n=!0;return r.setProfileLoading(!0),(async()=>{try{const i=await $e({getAccessToken:t});if(!n||!i)return;const c=await vt({accessToken:i});if(!n)return;r.setPublicProfileOn(!!c?.enabled),r.setAnonymousOn(!!c?.anonymous),c?.display_name&&r.setCustomDisplayName(c.display_name),r.setShowGithubOn(!!c?.show_github_url),r.setGithubUrl(c?.github_url||"")}catch(i){je("load public profile",i)}finally{n&&r.setProfileLoading(!1)}})(),()=>{n=!1}},[t,s,r])}function Xa(t,s,r){return l.useCallback(async(n,{label:i,onError:c,onSuccess:m}={})=>{if(!r||s.profileSaving)return!1;s.setProfileSaving(!0);try{const o=await $e({getAccessToken:t});if(!o)return!1;const d=await jt({accessToken:o,...n});return m?.(d),!0}catch(o){return c?c(o):je(i||"mutate profile",o),!1}finally{s.setProfileSaving(!1)}},[t,s,r])}function es(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 ts(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 as(t,s){const r=l.useCallback(async()=>{const i=!t.publicProfileOn;await s({enabled:i},{label:"toggle public profile",onSuccess:()=>t.setPublicProfileOn(i)})},[s,t]);return{handleAnonymousToggle:l.useCallback(async()=>{const i=!t.anonymousOn;await s({anonymous:i},{label:"toggle anonymous",onSuccess:()=>t.setAnonymousOn(i)})},[s,t]),handlePublicProfileToggle:r}}function ss(t,s,r){const n=l.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),r?.()}})},[s,t,r]),i=l.useCallback(()=>{t.setNameInput(t.customDisplayName||t.displayName),t.setEditingName(!0)},[t]);return{handleSaveName:n,startEditingName:i}}function ns(t,s){const r=l.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]),n=l.useCallback(async()=>{const c=Ya(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:m=>t.setGithubError(m?.message||a("settings.account.githubUrlInvalid")),onSuccess:m=>{t.setGithubUrl(m?.github_url||c||""),t.setShowGithubOn(!!c),t.setEditingGithub(!1)}})},[s,t]),i=l.useCallback(()=>{t.setGithubInput(t.githubUrl),t.setGithubError(null),t.setEditingGithub(!0)},[t]);return{handleSaveGithub:n,handleShowGithubToggle:r,startEditingGithub:i}}function ke(){const t=gt();l.useSyncExternalStore(pt,ht,()=>0);const s=xt(t.user?.id),n=!(s.membership?.status==="self_hosted"||s.catalog?.policy?.hosting_mode==="self_hosted")&&(ft()||s.membership?.hosting_mode==="hosted"),i=Ja(t.user),c=Za(t.getAccessToken,t.enabled,t.signedIn,t.user?.id);Qa(t.getAccessToken,t.signedIn&&n,i.loadSetters);const m=Xa(t.getAccessToken,i,n),o=as(i,m),d=ss(i,m,t.refreshDisplayName),y=ns(i,m);return{...t,...c,email:i.email,handlePublicProfileToggle:o.handlePublicProfileToggle,userId:i.userId,name:es(i,{...o,...d}),github:ts(i,y),profileLoading:i.profileLoading,profileSaving:i.profileSaving,publicProfileOn:n&&i.publicProfileOn,publicProfileAvailable:n}}function it({disabled:t,onCancel:s,onSave:r,saveLabel:n=a("settings.account.save")}){return e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:r,disabled:t,className:"rounded-md bg-oai-brand-500 px-3 py-1.5 text-xs font-medium text-white transition-colors hover:bg-oai-brand-600 disabled:opacity-50",children:n}),e.jsx("button",{type:"button",onClick:s,className:"rounded-md px-2 py-1.5 text-xs text-oai-gray-500 transition-colors hover:text-oai-gray-700 dark:hover:text-oai-gray-300",children:a("settings.account.cancel")})]})}function is({nameInput:t,setEditingName:s,setNameInput:r,profileSaving:n,handleSaveName:i}){return e.jsxs("div",{className:"mt-2 flex items-center gap-2",children:[e.jsx("input",{type:"text",value:t,onChange:c=>r(c.target.value),onKeyDown:c=>{c.key==="Enter"&&i(),c.key==="Escape"&&s(!1)},maxLength:50,autoFocus:!0,className:"flex-1 rounded-md border border-oai-gray-300 bg-transparent px-2.5 py-1.5 text-sm text-oai-black outline-none focus:border-oai-brand-500 focus:ring-1 focus:ring-inset focus:ring-oai-brand-500 dark:border-oai-gray-700 dark:text-white",placeholder:a("settings.account.displayName")}),e.jsx(it,{disabled:n||!t.trim(),onCancel:()=>s(!1),onSave:i,saveLabel:n?a("settings.account.saving"):void 0})]})}function rs({githubError:t,githubInput:s,handleSaveGithub:r,profileSaving:n,setEditingGithub:i,setGithubError:c,setGithubInput:m}){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:o=>{m(o.target.value),t&&c(null)},onKeyDown:o=>{o.key==="Enter"&&r(),o.key==="Escape"&&(i(!1),c(null))},maxLength:100,autoFocus:!0,className:"flex-1 rounded-md border border-oai-gray-300 bg-transparent px-2.5 py-1.5 text-sm text-oai-black outline-none focus:border-oai-brand-500 focus:ring-1 focus:ring-inset focus:ring-oai-brand-500 dark:border-oai-gray-700 dark:text-white",placeholder:a("settings.account.githubUrlPlaceholder")}),e.jsx(it,{disabled:n,onCancel:()=>{i(!1),c(null)},onSave:r,saveLabel:n?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 rt({disabled:t=!1,label:s,onClick:r,title:n}){return e.jsxs("button",{type:"button",onClick:r,disabled:t,title:n,className:"inline-flex h-8 shrink-0 items-center gap-1.5 rounded-md border border-oai-gray-200 px-3 text-xs font-medium text-oai-gray-700 transition-colors hover:bg-oai-gray-100 disabled:cursor-not-allowed disabled:opacity-40 dark:border-oai-gray-800 dark:text-oai-gray-300 dark:hover:bg-oai-gray-800",children:[e.jsx(ga,{className:"h-3.5 w-3.5","aria-hidden":!0}),s]})}function ot({actions:t,editing:s,editor:r,hint:n,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?r:e.jsx("div",{className:"mt-0.5 truncate text-xs text-oai-gray-500 dark:text-oai-gray-400",children:n})]}),s?null:t]})})}function os({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(rt,{disabled:t.anonymousOn,label:a("settings.account.edit"),onClick:t.startEditingName,title:s}),e.jsx(D,{checked:!t.anonymousOn,onChange:t.handleAnonymousToggle,disabled:t.profileLoading||t.profileSaving,ariaLabel:a("settings.account.displayName")})]})}function ls({name:t}){const{anonymousOn:s,customDisplayName:r,displayName:n,editingName:i,handleAnonymousToggle:c,handleSaveName:m,nameInput:o,profileLoading:d,profileSaving:y,setEditingName:x,setNameInput:g,startEditingName:b}=t,v=s?a("settings.account.displayNameAnonymousHint"):r||n;return e.jsx(ot,{label:a("settings.account.displayName"),editing:i,hint:v,editor:e.jsx(is,{nameInput:o,setEditingName:x,setNameInput:g,profileSaving:y,handleSaveName:m}),actions:e.jsx(os,{name:t})})}function cs({github:t}){const{editingGithub:s,githubError:r,githubInput:n,githubUrl:i,handleSaveGithub:c,handleShowGithubToggle:m,profileLoading:o,profileSaving:d,setEditingGithub:y,setGithubError:x,setGithubInput:g,showGithubOn:b,startEditingGithub:v}=t;return e.jsx(e.Fragment,{children:e.jsx(ot,{label:a("settings.account.githubUrl"),editing:s,hint:i||a("settings.account.githubUrlHint"),editor:e.jsx(rs,{githubError:r,githubInput:n,handleSaveGithub:c,profileSaving:d,setEditingGithub:y,setGithubError:x,setGithubInput:g}),actions:e.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[e.jsx(rt,{label:a("settings.account.edit"),onClick:v}),e.jsx(D,{checked:b,onChange:m,disabled:o||d,ariaLabel:a("settings.account.githubUrl")})]})})})}function ds(){const{openLoginModal:t}=Fe();return e.jsx(V,{title:a("settings.section.account"),children:e.jsxs("div",{className:"flex items-center justify-between gap-4 py-3",children:[e.jsx("p",{className:"text-sm text-oai-gray-500 dark:text-oai-gray-400",children:a("settings.account.signedOutHint")}),e.jsx("button",{type:"button",onClick:t,className:"inline-flex h-8 shrink-0 items-center justify-center rounded-md bg-oai-gray-900 px-4 text-xs font-medium text-white transition-colors hover:bg-oai-gray-800 dark:bg-white dark:text-oai-gray-900 dark:hover:bg-oai-gray-100",children:a("settings.account.signIn")})]})})}function us({name:t,github:s}){return e.jsxs(e.Fragment,{children:[e.jsx(ls,{name:t}),e.jsx(cs,{github:s})]})}function ms({settings:t}={}){return t?e.jsx(lt,{settings:t}):e.jsx(gs,{})}function gs(){const t=ke();return e.jsx(lt,{settings:t})}function lt({settings:t}){return t.enabled?t.signedIn?e.jsxs(V,{title:a("settings.section.account"),subtitle:t.email||t.name.customDisplayName||t.name.displayName,action:e.jsx(hs,{onSignOut:t.signOut}),children:[e.jsx(ps,{userId:t.userId}),e.jsx(xs,{checked:t.publicProfileOn,disabled:t.profileLoading||t.profileSaving||t.publicProfileAvailable===!1,onChange:t.handlePublicProfileToggle,unavailable:t.publicProfileAvailable===!1}),e.jsx(fs,{visible:t.publicProfileOn,name:t.name,github:t.github})]}):e.jsx(ds,{}):null}function ps({userId:t}){const[s,r]=xe.useState(!1);if(!t)return null;const n=async()=>{try{if(typeof navigator>"u"||!navigator.clipboard?.writeText)return;await navigator.clipboard.writeText(t),r(!0),globalThis.setTimeout(()=>r(!1),1200)}catch{r(!1)}};return e.jsxs("div",{className:"flex items-center justify-between gap-4 py-3",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:a("settings.account.userId")}),e.jsx("div",{className:"mt-0.5 truncate font-mono text-xs text-oai-gray-500 dark:text-oai-gray-400",children:t})]}),e.jsxs("button",{type:"button",onClick:n,className:"inline-flex h-8 shrink-0 items-center gap-1.5 rounded-md border border-oai-gray-200 px-3 text-xs font-medium text-oai-gray-700 transition-colors hover:bg-oai-gray-100 dark:border-oai-gray-800 dark:text-oai-gray-300 dark:hover:bg-oai-gray-800","aria-label":a("settings.account.copyUserId"),children:[s?e.jsx(fa,{className:"h-3.5 w-3.5","aria-hidden":!0}):e.jsx(ba,{className:"h-3.5 w-3.5","aria-hidden":!0}),s?a("settings.account.copied"):a("settings.account.copy")]})]})}function hs({onSignOut:t}){return e.jsxs("button",{type:"button",onClick:()=>t(),className:"inline-flex h-7 items-center gap-1.5 text-xs font-medium text-oai-gray-500 transition-colors hover:text-oai-gray-700 dark:hover:text-oai-gray-300",children:[e.jsx($a,{className:"h-3.5 w-3.5","aria-hidden":!0}),a("settings.account.signOut")]})}function xs({checked:t,disabled:s,onChange:r,unavailable:n}){return e.jsx(E,{label:a("settings.account.publicProfile"),hint:a(n?"cloud.self_host.public_profile_disabled":"settings.account.publicProfileHint"),control:e.jsx(D,{checked:t,onChange:r,disabled:s,ariaLabel:a("settings.account.publicProfile")})})}function fs({visible:t,name:s,github:r}){return e.jsx(Ye,{initial:!1,children:t?e.jsx(qe.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(us,{name:s,github:r})},"public-profile-fields"):null})}function ae(t){return t.replace(/[\t\n\r\f\v -]/g,"").toUpperCase()}function bs({account:t,auth:s,refresh:r,compact:n=!1,panelContainer:i=null,layout:c="default",dialogOpen:m,onDialogOpenChange:o}){const d=c==="settings-row",[y,x]=l.useState(!1),g=d&&typeof m=="boolean"?m:y,[b,v]=l.useState(""),[N,j]=l.useState(!1),[p,u]=l.useState(null),[k,C]=l.useState(null),[h,S]=l.useState(!1),_=l.useId(),w=l.useRef(null),A=l.useRef(null),T=l.useRef(!1),f=l.useRef(!1),P=l.useRef(0),U=`${kt()}.${t?.environment||"unknown"}.${s?.signedIn?s.user?.id:""}`,F=l.useRef(U);F.current=U,l.useEffect(()=>(f.current=!0,P.current+=1,A.current=null,T.current=!1,x(!1),v(""),j(!1),u(null),C(null),S(!1),()=>{f.current=!1,P.current+=1}),[U]);const q=t?.membership?.status==="self_hosted"||t?.membership?.hosting_mode==="self_hosted",$=t?.gift_redemption_available===!0,Z=d?t?.gifts||[]:[];if(!s?.signedIn||q||!$&&!Z.length)return null;const J=t.redemption_restriction,re=O=>{!O&&T.current||(typeof m!="boolean"&&x(O),o?.(O))},L=async(O,oe)=>{const le=await r();oe()&&S(!!le?.gifts?.some(H=>H.id===O?.id))},ee=async O=>{if(T.current||O&&(!$||!b.trim()))return;if(O&&J){u(new ue(J));return}T.current=!0;const oe=++P.current,le=U,H=()=>f.current&&P.current===oe&&F.current===le;j(!0),u(null);try{if(O){const te=b.trim();(!A.current||ae(A.current.code)!==ae(te))&&(A.current={code:te,request_id:crypto.randomUUID()});const ce=await Y("redeem-gift",{auth:async()=>{const mt=await _t(s.getAccessToken);if(!H())throw new ue("authentication_required",401);return mt},body:A.current});if(!H())return;if(!ce?.gift?.id)throw new ue("billing_operation_failed");C(ce),S(!1),v(""),A.current=null,await L(ce.gift,H)}else await L(k?.gift,H)}catch(te){H()&&u(te)}finally{H()&&(T.current=!1,j(!1))}};let Q=null;return(d||g)&&(Q=e.jsxs("div",{id:`${_}-panel`,className:d?"space-y-3":n?"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:[$?e.jsxs(e.Fragment,{children:[e.jsx("p",{id:`${_}-detail`,className:d?"sr-only":"text-xs leading-5 text-oai-gray-600 dark:text-oai-gray-300",children:a("cloud.gift.detail")}),k?e.jsxs("div",{role:"status",className:"space-y-2 text-sm leading-6",children:[e.jsx("p",{children:a(h?k.already_redeemed?"cloud.gift.already_redeemed":"cloud.gift.redeemed":"cloud.gift.refresh_needed")}),k.gift?e.jsx("p",{className:"text-xs text-oai-gray-600 dark:text-oai-gray-300",children:a("cloud.gift.term",{days:k.gift.duration_days,start:G(k.gift.starts_at),end:G(k.gift.ends_at)})}):null,h?e.jsx(R,{type:"button",variant:"ghost",onClick:()=>{C(null),S(!1)},children:a("cloud.gift.redeem_another")}):e.jsx(R,{type:"button",variant:"secondary",disabled:N,onClick:()=>{ee(!1)},children:a("cloud.action.refresh_membership")})]}):e.jsxs("form",{onSubmit:O=>{O.preventDefault(),ee(!0)},"aria-busy":N,children:[e.jsx("label",{htmlFor:_,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:_,ref:w,value:b,disabled:N,maxLength:128,autoComplete:"off",spellCheck:!1,autoCapitalize:"characters","data-ph-no-capture":"true","aria-describedby":`${_}-detail${p?` ${_}-error`:""}`,"aria-invalid":!!p,onChange:O=>{ae(O.target.value)!==ae(b)&&(A.current=null),v(O.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(R,{type:"submit",variant:"secondary",disabled:N||!b.trim(),children:a(N?"cloud.gift.redeeming":"cloud.gift.confirm")})]})]}),p?e.jsx("div",{id:`${_}-error`,children:["gift_checkout_pending","gift_requires_renewal_cancel"].includes(p.code)?e.jsx("p",{role:"alert",className:"text-xs leading-5 text-oai-gray-600 dark:text-oai-gray-300",children:wt(p,"gift")}):e.jsx(z,{error:p,context:"gift"})}):null]}):null,Z.length?e.jsx("ul",{"aria-label":a("cloud.gift.history_title"),className:"divide-y divide-oai-gray-200 dark:divide-oai-gray-800",children:Z.map(O=>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:O.duration_days})}),e.jsx("span",{children:a(["active","pending","expired","revoked"].includes(O.state)?`cloud.gift.state_${O.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:G(O.starts_at),end:G(O.ends_at)})})]},O.id))}):null]})),d?e.jsx(We,{open:g,onOpenChange:re,title:a($?"cloud.gift.redeem_action":"cloud.gift.history_title"),icon:De,preventClose:N,initialFocus:$&&!k?w:void 0,children:Q}):e.jsxs("div",{className:d?void 0:n?"contents":"mt-4",children:[e.jsxs(R,{type:"button",variant:"ghost",size:n||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":n?"!h-10 !px-0":void 0,"aria-expanded":g,"aria-controls":d||g?`${_}-panel`:void 0,onClick:()=>x(O=>!O),disabled:N,children:[n||d?e.jsx(De,{size:16,className:`${d?"mr-3":"mr-2"} shrink-0`,"aria-hidden":!0}):null,a($?"cloud.gift.redeem_action":"cloud.gift.history_title"),d?e.jsx(ka,{size:16,className:`ml-auto shrink-0 transition-transform motion-reduce:transition-none ${g?"rotate-180":""}`,"aria-hidden":!0}):null]}),!d&&i&&Q?Nt.createPortal(Q,i):Q]})}function ys({text:t,label:s}){const[r,n]=l.useState(!1);return e.jsxs(_a,{open:r,onOpenChange:n,children:[e.jsx(Sa,{delay:0,closeOnClick:!1,"aria-label":s,onClick:()=>n(!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(Ze,{size:14,"aria-hidden":!0})}),e.jsx(Ca,{children:e.jsx(Ea,{side:"bottom",sideOffset:6,className:"z-[110]",children:e.jsx(Pa,{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 vs(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 js(t,s){if(!t)return null;const r=t.status==="active"&&t.access_source==="gift";if(s&&Number.isFinite(Date.parse(s))){const n=t.status==="transition"?"cloud.membership.transition_until":t.status==="trial"?"cloud.membership.trial_until":t.status==="active"?r?"cloud.membership.gift_until":"cloud.membership.active_until":t.status==="expired"&&Date.parse(s)<=Date.now()?"cloud.membership.expired_on":null;if(n)return a(n,{date:G(s)})}return r?a("cloud.gift.membership_label"):Ot(t.status)}function ks({auth:t,machineLimit:s,accountRevision:r,selfHosted:n=!1}){const[i,c]=l.useState(null),[m,o]=l.useState(null),[d,y]=l.useState(null),[x,g]=l.useState(!1),[b,v]=l.useState(null),N=l.useRef(!1),j=l.useRef(0),p=l.useRef(!0),u=t?.user?.id,k=t?.getAccessToken,C=l.useCallback(async()=>{const f=++j.current;try{let P;if(ze())try{const F=await At(),q=await fetch("/functions/tokentracker-machine-id",{headers:F});q.ok&&(P=(await q.json())?.machineId)}catch{}const U=await Y("devices",{auth:k,params:P?{current_machine_id:P}:{}});f===j.current&&(c(U),o(null))}catch(P){f===j.current&&o({...P,code:"billing_devices_unavailable"})}},[k,u]);l.useEffect(()=>(p.current=!0,C(),()=>{p.current=!1,j.current+=1}),[C,r]);const h=async f=>{if(!N.current){N.current=!0,g(!0),o(null),v(null);try{if(await Y("remove-device",{auth:k,body:{machine_id:f}}),!p.current)return;i?.machines?.find(P=>P.machine_id===f)?.is_current&&Se(),y(null),await C()}catch(P){p.current&&o(P)}finally{N.current=!1,g(!1)}}},S=async f=>{if(!N.current){N.current=!0,g(!0),o(null),v(null);try{if(await Y("resume-device",{auth:k,body:{machine_id:f.machine_id}}),!p.current)return;f.is_current&&Se(),v(a("cloud.devices.resumed")),await C()}catch(P){p.current&&o(P)}finally{N.current=!1,g(!1)}}},_=i?.machines||[],w=i?.machine_count??_.filter(f=>f.status!=="paused").length,A=i?.machine_limit??s,T=A==null||w<A;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(ys,{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?A==null?a(n?"cloud.devices.unlimited_self_hosted":"cloud.devices.unlimited",{count:w}):a("cloud.devices.count",{count:w,limit:A}):m?a("cloud.devices.count_unknown"):a("cloud.catalog.loading")})]}),i?.over_machine_limit||A!=null&&A<w?e.jsx("div",{className:"mb-4",children:e.jsx(z,{children:a("cloud.devices.over_limit")})}):null,m?e.jsx(z,{error:m,onRetry:C,context:"account"}):null,b?e.jsx("div",{className:"mb-3",children:e.jsx(z,{children:b})}):null,!m&&i&&_.length===0?e.jsx("p",{className:"text-sm text-oai-gray-500 dark:text-oai-gray-400",children:a("cloud.devices.empty")}):null,_.length!==0?e.jsx("ul",{className:"divide-y divide-oai-gray-200 dark:divide-oai-gray-800",children:_.map(f=>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(ye,{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:f.name||a("cloud.devices.unnamed"),className:"col-start-2 row-start-1 min-w-0 truncate text-sm font-medium",children:f.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:vs(f.platform)}),e.jsx("span",{"aria-hidden":!0,children:"·"}),e.jsx("span",{children:f.last_seen_at?a("cloud.devices.last_seen",{date:Lt(f.last_seen_at)}):a("cloud.devices.last_seen_unknown")}),f.is_current?e.jsxs(e.Fragment,{children:[e.jsx("span",{"aria-hidden":!0,children:"·"}),e.jsx("span",{children:a("cloud.devices.current")})]}):null,f.status==="paused"?e.jsxs(e.Fragment,{children:[e.jsx("span",{"aria-hidden":!0,children:"·"}),e.jsx("span",{children:a("cloud.devices.paused")})]}):null]}),f.status==="paused"&&!T?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(R,{variant:"ghost",size:"sm",className:"col-start-3 row-start-1 !min-h-10 !px-2 sm:row-span-2","aria-expanded":f.status!=="paused"?d===f.machine_id:void 0,"aria-controls":d===f.machine_id?`cloud-machine-confirm-${f.machine_id}`:void 0,onClick:()=>f.status==="paused"?S(f):y(P=>P===f.machine_id?null:f.machine_id),disabled:x||f.status==="paused"&&!T,children:[f.status==="paused"?e.jsx(wa,{size:14,className:"mr-1.5 shrink-0","aria-hidden":!0}):e.jsx(Na,{size:14,className:"mr-1.5 shrink-0","aria-hidden":!0}),f.status==="paused"?a("cloud.devices.resume"):a("cloud.devices.remove")]})]}),d===f.machine_id?e.jsxs("div",{id:`cloud-machine-confirm-${f.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(R,{variant:"secondary",onClick:()=>h(f.machine_id),disabled:x,children:a("cloud.devices.confirm_remove")}),e.jsx(R,{variant:"ghost",onClick:()=>y(null),disabled:x,children:a("cloud.action.keep")})]})]}):null]},f.machine_id))}):null]})}function ws({recent:t,pendingOrders:s,conflictOrders:r,userId:n,payments:i=[],footerActions:c}){const m=He(),[o,d]=l.useState(t?.order_id&&ge.test(t.order_id)?t.order_id:""),[y,x]=l.useState(!1),[g,b]=l.useState(!1),v=l.useId(),N=l.useRef(null);l.useEffect(()=>{g&&N.current?.focus()},[g]);const j=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())),p=[...r||[],...(s||[]).filter(u=>u.retry_payment_conflict_at||!j.has(u.id.toLowerCase()))].filter((u,k,C)=>C.findIndex(h=>h.id===u.id)===k);return e.jsxs("div",{className:"mt-2 space-y-3",children:[t?.request_id&&!t.order_id?e.jsx(ne,{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,p.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:[p.map(u=>{const k=typeof u.created_at=="string"&&Number.isFinite(Date.parse(u.created_at))?G(u.created_at):null;let C=null;Number.isInteger(u.amount_cents)&&u.amount_cents>=0&&["USD","CNY"].includes(u.currency)&&(C=fe(u.amount_cents,u.currency));const h=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:k||h}),e.jsx("p",{className:"col-start-2 row-start-1 text-right text-sm font-medium tabular-nums",children:C}),u.provider||k?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:Be(u.provider)}):null,k?e.jsxs(e.Fragment,{children:[u.provider?e.jsx("span",{"aria-hidden":!0,children:"·"}):null,e.jsx("span",{children:h})]}):null]}):null,e.jsx(ne,{to:`/billing/checkout?order=${encodeURIComponent(u.id)}`,onClick:S=>{u.retry_payment_conflict_at||S.button!==0||S.metaKey||S.ctrlKey||S.shiftKey||S.altKey||!ge.test(u.id)||(S.preventDefault(),m(_e({orderId:u.id,userId:n})))},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(Ns,{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(R,{variant:"ghost",size:"sm",className:"!h-10 !px-0","aria-expanded":g,"aria-controls":`${v}-panel`,onClick:()=>b(u=>!u),children:a("cloud.restore.title")}),c]}),g?e.jsxs("div",{id:`${v}-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(),!ge.test(o.trim())){x(!0);return}const k=o.trim(),C=p.some(h=>h.id.toLowerCase()===k.toLowerCase()&&h.retry_payment_conflict_at);m(C?`/billing/checkout?order=${encodeURIComponent(k)}`:_e({orderId:k,userId:n}))},children:[e.jsx("label",{htmlFor:`${v}-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:`${v}-input`,ref:N,value:o,onChange:u=>{d(u.target.value),x(!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":y,"aria-describedby":y?`${v}-error`:void 0}),e.jsx(R,{type:"submit",variant:"secondary",children:a("cloud.action.restore")})]}),y?e.jsx("p",{id:`${v}-error`,role:"alert",className:"mt-2 text-xs text-red-600 dark:text-red-400",children:a("cloud.restore.invalid")}):null]})]}):null]})]})}function Ns({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:G(s.paid_at)}),e.jsx("p",{className:"col-start-2 row-start-1 text-right text-sm font-medium tabular-nums",children:fe(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:Be(s.provider)}),e.jsx("span",{"aria-hidden":!0,children:"·"}),e.jsx("span",{children:a("cloud.history.term",{start:G(s.starts_at),end:G(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:fe(s.refunded_cents,s.currency)}):a("cloud.history.paid")})]},s.id))})}function _s({showTitle:t=!0,heading:s,syncControl:r,active:n=!0}){const i=St();return e.jsx(Ss,{showTitle:t,heading:s,syncControl:r,active:n,...i},i.auth?.signedIn?i.auth.user?.id:"signed-out")}function Ss({account:t,auth:s,loading:r,error:n,refresh:i,showTitle:c,heading:m,syncControl:o,active:d=!0}){const{openLoginModal:y}=Fe(),[x,g]=l.useState(null),[b,v]=l.useState(null),[N,j]=l.useState(!1),[p,u]=l.useState(null),k=l.useRef(!1),C=l.useRef(!0);l.useEffect(()=>{d||g(null)},[d]),l.useEffect(()=>(C.current=!0,()=>{C.current=!1}),[]);const h=t?.membership,S=h?.status==="self_hosted"||h?.hosting_mode==="self_hosted",_=[...t?.conflict_orders||[],...t?.pending_orders||[]].some(L=>L.retry_payment_conflict_at),w=!S&&t?.subscriptions?.find(L=>["active","trialing","past_due","paused","canceling"].includes(L.status)),A=!S&&(w?w.provider==="waffo":t?.payments?.some(L=>L.provider==="waffo")),T=w&&!w.cancel_at_period_end&&w.status!=="canceling",f=T&&w.status!=="paused",P=w?.next_billed_at,U=P&&Number.isFinite(Date.parse(P));l.useEffect(()=>{p&&t&&!T&&(u(null),v(null))},[t,p,T]);const F=S?null:h?.status==="trial"?h.trial_ends_at:h?.status==="transition"?h.transition_ends_at:h?.expires_at,q=async L=>{if(!k.current){k.current=!0,j(!0),v(null);try{await L()}catch(ee){C.current&&v(ee)}finally{k.current=!1,j(!1)}}},$=()=>q(async()=>{const L=await Y("portal",{auth:s.getAccessToken,body:w?{subscription_id:w.provider_subscription_id}:{}});C.current&&await ja(L.url||L.portal_url)}),Z=()=>q(async()=>{await Y("cancel",{auth:s.getAccessToken,body:{subscription_id:p}}),C.current&&(u(null),await i())}),J=js(h,F),re=A&&!w||h?.can_read_cloud||!S&&t?.gift_redemption_available===!0;return s?.signedIn?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(z,{children:a("cloud.catalog.sandbox")}):null,_?e.jsx(Ct,{showBillingLink:!1}):null,e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex min-w-0 flex-wrap items-baseline gap-x-3 gap-y-2",children:[m?e.jsx("h2",{className:"shrink-0 !text-2xl font-semibold",children:m}):null,!m&&c?e.jsxs("h2",{className:"inline-flex items-center gap-2 text-base font-semibold",children:[e.jsx(se,{size:18,className:"text-oai-gray-500 dark:text-oai-gray-400","aria-hidden":!0}),a("cloud.membership.title")]}):null,J?e.jsx("span",{className:"text-sm text-oai-gray-500 dark:text-oai-gray-400",children:J}):null]}),e.jsx(R,{onClick:i,variant:"ghost",size:"sm",className:"!size-10 shrink-0 !p-0",disabled:r,"aria-label":a("cloud.action.refresh_membership"),children:e.jsx(be,{size:15,className:r?"motion-safe:animate-spin":void 0,"aria-hidden":!0})})]}),h?.status==="expired"?e.jsx("p",{className:"mt-3 max-w-2xl text-xs leading-5 text-oai-gray-500 dark:text-oai-gray-400",children:h.can_read_cloud?a("cloud.membership.read_only",{date:G(h.read_only_until)}):a("cloud.membership.expired_detail")}):null,h?e.jsx(Et,{userId:s.user?.id,membership:h,subscriptions:t?.subscriptions,className:"mt-3"}):null,!h&&r?e.jsx("p",{role:"status",className:"mt-3 text-sm text-oai-gray-500 dark:text-oai-gray-400",children:a("cloud.catalog.loading")}):null,w?e.jsx("div",{className:"mt-4 flex flex-wrap items-center justify-between gap-3",children:w?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:w.status==="paused"?a("cloud.membership.renewal_paused"):w.status==="past_due"?a("cloud.membership.payment_due"):f?U?a("cloud.membership.renews",{date:G(P)}):a("cloud.membership.renewal_unknown"):a("cloud.membership.renewal_off")}),T?e.jsx(R,{"aria-expanded":!!p,"aria-controls":p?"cloud-cancel-confirm":void 0,onClick:()=>u(L=>L===w.provider_subscription_id?null:w.provider_subscription_id),variant:"ghost",size:"sm",className:"!h-10 !px-2",disabled:N,children:a("cloud.action.cancel_renewal")}):null]}):null}):null,p?e.jsxs("div",{id:"cloud-cancel-confirm",className:"mt-4 rounded-lg border border-oai-gray-200 p-4 dark:border-oai-gray-800",children:[e.jsx("p",{className:"text-sm leading-6",children:F?a("cloud.cancel.detail",{date:G(F)}):a("cloud.cancel.no_term")}),e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2",children:[e.jsx(R,{onClick:Z,variant:"secondary",disabled:N,children:a("cloud.cancel.confirm")}),e.jsx(R,{onClick:()=>u(null),variant:"ghost",disabled:N,children:a("cloud.action.keep")})]})]}):null,n?e.jsx("div",{className:"mt-4",children:e.jsx(z,{error:n,onRetry:i,context:"account"})}):null,b&&x!=="billing"?e.jsx("div",{className:"mt-4",children:e.jsx(z,{error:b,context:"account"})}):null]})]}),h?e.jsx(pe,{className:"tt-cloud-theme !rounded-lg",bodyClassName:"!py-3",children:e.jsx(ks,{auth:s,machineLimit:h.machine_limit,accountRevision:t,selfHosted:S})}):null,re||t&&!S||o?e.jsx(pe,{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:[S?null:w?e.jsxs("button",{type:"button",onClick:$,disabled:N,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(se,{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(Re,{size:16,className:"shrink-0 text-oai-gray-500 dark:text-oai-gray-400","aria-hidden":!0})]}):e.jsxs(ne,{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(se,{size:16,className:"shrink-0","aria-hidden":!0}),e.jsx("span",{className:"min-w-0 flex-1",children:a("cloud.action.subscribe")}),e.jsx(Pt,{size:16,className:"shrink-0 text-oai-gray-500 dark:text-oai-gray-400","aria-hidden":!0})]}),t&&!S?e.jsxs(We,{open:x==="billing",onOpenChange:L=>g(L?"billing":null),title:a("cloud.billing.title"),icon:Da,wide:!0,children:[b?e.jsx("div",{className:"mb-3",children:e.jsx(z,{error:b,context:"account"})}):null,e.jsx(ws,{userId:s.user?.id,recent:va(s.user?.id),pendingOrders:t?.pending_orders,conflictOrders:t?.conflict_orders,payments:t.payments,footerActions:A&&!w?e.jsx("div",{className:"flex items-center gap-0.5",children:e.jsxs(R,{onClick:$,variant:"ghost",size:"sm",className:"!h-10 !px-0",disabled:N,children:[a("cloud.action.view_bills"),e.jsx(Re,{size:14,className:"ml-2","aria-hidden":!0})]})}):null})]}):null,h?.can_read_cloud?e.jsx(pa,{auth:s,layout:"settings-row",dialogOpen:x==="export",onDialogOpenChange:L=>g(L?"export":null)}):null,e.jsx(bs,{account:t,auth:s,refresh:i,layout:"settings-row",dialogOpen:x==="redeem",onDialogOpenChange:L=>g(L?"redeem":null)}),o?e.jsx("section",{children:o}):null]})}):null]}):e.jsxs("div",{className:"space-y-4",children:[m?e.jsx("h2",{className:"shrink-0 !text-2xl font-semibold",children:m}):null,e.jsxs(pe,{className:"tt-cloud-theme",children:[!m&&c?e.jsx("h2",{className:"text-base font-semibold",children:a("cloud.membership.title")}):null,e.jsx("p",{className:`${!m&&c?"mt-2 ":""}text-sm leading-6 text-oai-gray-500 dark:text-oai-gray-400`,children:a("cloud.membership.signed_out")}),e.jsx("div",{className:"mt-4 flex flex-wrap items-center gap-2",children:e.jsx(R,{onClick:()=>y({subtitle:a("cloud.membership.signed_out")}),children:a("cloud.action.sign_in_continue")})})]})]})}function Cs({settings:t,active:s=!0}={}){return t?e.jsx(ct,{settings:t,active:s}):e.jsx(Es,{active:s})}function Es({active:t}){const s=ke();return e.jsx(ct,{settings:s,active:t})}function ct({settings:t,active:s}){return e.jsx(_s,{showTitle:!1,heading:a("settings.section.cloud"),active:s,syncControl:t.showLocalCloudSync?e.jsx(Ps,{settings:t}):null})}function Ps({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(be,{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(D,{checked:t.cloudSyncOn,disabled:t.cloudSyncPending,onChange:()=>(t.cloudSyncOn?Ce(t.userId):Tt(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(Oa,{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(z,{role:"alert",onRetry:t.handleCloudSyncRetry,children:a("settings.account.cloudSyncError")})}):null,e.jsx(It,{userId:t.userId,panel:"sync",localHost:!0,className:"py-3",onContinueLocal:()=>{Ce(t.userId),t.cloudSyncOn&&t.handleCloudSyncDisable()}})]})}function Os(){return[{value:"light",label:a("settings.appearance.theme.light"),Icon:Dt},{value:"dark",label:a("settings.appearance.theme.dark"),Icon:Gt},{value:"system",label:a("settings.appearance.theme.system"),Icon:ye}]}function As(){return[{value:$t,label:a("settings.appearance.language.system")},{value:zt,label:a("settings.appearance.language.english")},{value:Ft,label:a("settings.appearance.language.chinese")},{value:Ht,label:a("settings.appearance.language.traditional_chinese")},{value:Bt,label:a("settings.appearance.language.japanese")},{value:Vt,label:a("settings.appearance.language.korean")},{value:Kt,label:a("settings.appearance.language.german")}]}function Ls(t){if(!t)return null;try{const s=new Date(t);return Number.isNaN(s.getTime())?null:s.toLocaleString()}catch{return null}}function Ts(t,s){const r=a(`settings.appearance.currency.rate_source.${t}`),n=Ls(s),i=n?a("settings.appearance.currency.rate_updated",{when:n}):a("settings.appearance.currency.rate_never");return`${r} · ${i}`}function Is({locale:t,setLocale:s}){const r=As();return e.jsx(ve,{value:t,onValueChange:s,options:r,ariaLabel:a("settings.appearance.language.label"),className:"px-2.5 py-1.5 text-xs font-medium",leadingIcon:e.jsx(Ma,{className:"h-3.5 w-3.5 text-oai-gray-500 dark:text-oai-gray-400","aria-hidden":!0})})}function Rs({currency:t,setCurrency:s}){const r=Ut().map(n=>({value:n.code,label:a(n.labelKey)}));return e.jsx(ve,{value:t,onValueChange:s,options:r,ariaLabel:a("settings.appearance.currency.label"),className:"px-3 py-1.5 text-xs font-medium"})}function Ds({currency:t,rate:s,rateSource:r,rateFetchedAt:n}){if(t===Mt)return e.jsx(e.Fragment,{children:a("settings.appearance.currency.hint")});const i=Ts(r,n);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(Ze,{className:"h-3.5 w-3.5","aria-hidden":!0})})]})}function Gs(){const{theme:t,setTheme:s}=Rt(),{locale:r,setLocale:n}=Ve(),{currency:i,rate:c,rateSource:m,rateFetchedAt:o,setCurrency:d}=Aa(),{mode:y,setMode:x,unitSystem:g,setUnitSystem:b,grouping:v,setGrouping:N}=La();return e.jsxs(V,{title:a("settings.section.appearance"),children:[e.jsx(E,{label:a("settings.appearance.theme.label"),hint:a("settings.appearance.theme.hint"),control:e.jsx(W,{options:Os(),value:t,onChange:s})}),e.jsx(E,{label:a("settings.appearance.language.label"),hint:a("settings.appearance.language.hint"),control:e.jsx(Is,{locale:r,setLocale:n})}),e.jsx(E,{label:a("settings.appearance.currency.label"),hint:e.jsx(Ds,{currency:i,rate:c,rateSource:m,rateFetchedAt:o}),control:e.jsx(Rs,{currency:i,setCurrency:d})}),e.jsx(E,{label:a("settings.appearance.token_format.label"),hint:a("settings.appearance.token_format.hint"),control:e.jsx(W,{options:[{value:me.COMPACT,label:a("settings.appearance.token_format.compact")},{value:me.FULL,label:a("settings.appearance.token_format.full")}],value:y,onChange:x})}),e.jsx(E,{label:a("settings.appearance.token_unit.label"),hint:a("settings.appearance.token_unit.hint"),control:e.jsx(W,{disabled:y!==me.COMPACT,options:[{value:Ee.ENGLISH,label:a("settings.appearance.token_unit.english")},{value:Ee.CHINESE,label:a("settings.appearance.token_unit.chinese")}],value:g,onChange:b})}),e.jsx(E,{label:a("settings.appearance.token_grouping.label"),hint:a("settings.appearance.token_grouping.hint"),control:e.jsx(W,{options:[{value:Pe.THOUSAND,label:a("settings.appearance.token_grouping.thousand")},{value:Pe.WAN,label:a("settings.appearance.token_grouping.wan")}],value:v,onChange:N})})]})}function he({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 Us(){const{enabled:t,toggle:s}=ha(),{enabled:r,toggle:n}=xa(),{available:i,settings:c,setSetting:m}=ie(),o=i&&!!c?.dynamicIslandSupported,d=!!c?.dynamicIslandEnabled;return e.jsxs(V,{title:a("settings.section.labs"),children:[o&&e.jsxs(e.Fragment,{children:[e.jsx(E,{label:e.jsx(he,{labelKey:"settings.labs.island.label"}),hint:a("settings.labs.island.hint"),control:e.jsx(D,{checked:d,onChange:()=>m("dynamicIslandEnabled",!d),ariaLabel:a("settings.labs.island.aria")})}),d&&e.jsx(E,{label:a("settings.labs.island_hide_menubar.label"),hint:a("settings.labs.island_hide_menubar.hint"),control:e.jsx(D,{checked:!!c?.hideMenuBarIcon,onChange:()=>m("hideMenuBarIcon",!c?.hideMenuBarIcon),ariaLabel:a("settings.labs.island_hide_menubar.aria")})})]}),e.jsx(E,{label:e.jsx(he,{labelKey:"settings.labs.qpd.label"}),hint:a("settings.labs.qpd.hint"),control:e.jsx(D,{checked:t,onChange:s,ariaLabel:a("settings.labs.qpd.aria")})}),e.jsx(E,{label:e.jsx(he,{labelKey:"settings.labs.sessions.label"}),hint:a("settings.labs.sessions.hint"),control:e.jsx(D,{checked:r,onChange:n,ariaLabel:a("settings.labs.sessions.aria")})})]})}function Ms(){const{available:t,settings:s,setSetting:r,runAction:n}=ie();if(!t)return null;const i=Ke(),c=!!s?.launchAtLogin,m=s?.toastOnReset!==!1,o=s?.confettiOnReset!==!1,d=s?.launchAtLoginSupported!==!1,y=s?.autoUpdateEnabled!==!1,x=s?.updateStatus||null,g=!!s?.updateBusy,b=!!s?.isSyncing;return e.jsxs(V,{title:a("settings.section.menubar"),children:[i?null:e.jsxs(e.Fragment,{children:[e.jsx(E,{label:a("settings.menubar.appearance"),hint:a("settings.menubar.appearanceHint"),control:e.jsxs(ne,{to:"/widgets",className:"inline-flex h-8 items-center gap-1.5 rounded-md border border-oai-gray-200 px-3 text-xs font-medium text-oai-gray-700 no-underline transition-colors hover:bg-oai-gray-100 dark:border-oai-gray-800 dark:text-oai-gray-300 dark:hover:bg-oai-gray-800",children:[a("settings.menubar.appearanceLink"),e.jsx(Ia,{className:"h-3.5 w-3.5","aria-hidden":!0})]})}),e.jsx(E,{label:a("settings.menubar.toastOnReset"),hint:a("settings.menubar.toastOnResetHint"),control:e.jsx(D,{checked:m,onChange:()=>r("toastOnReset",!m),ariaLabel:a("settings.menubar.toastOnReset")})}),e.jsx(E,{label:a("settings.menubar.confettiOnReset"),hint:a("settings.menubar.confettiOnResetHint"),control:e.jsx(D,{checked:o,onChange:()=>r("confettiOnReset",!o),ariaLabel:a("settings.menubar.confettiOnReset")})})]}),d?e.jsx(E,{label:a("settings.menubar.launchAtLogin"),hint:a("settings.menubar.launchAtLoginHint"),control:e.jsx(D,{checked:c,onChange:()=>r("launchAtLogin",!c),ariaLabel:a("settings.menubar.launchAtLogin")})}):null,e.jsx(E,{label:a("settings.menubar.syncNow"),hint:a("settings.menubar.syncNowHint"),control:e.jsxs("button",{type:"button",onClick:()=>n("syncNow"),disabled:b,className:"inline-flex h-8 items-center gap-1.5 rounded-md border border-oai-gray-200 px-3 text-xs font-medium text-oai-gray-700 transition-colors hover:bg-oai-gray-100 disabled:cursor-not-allowed disabled:opacity-50 dark:border-oai-gray-800 dark:text-oai-gray-300 dark:hover:bg-oai-gray-800",children:[e.jsx(be,{className:B("h-3.5 w-3.5",b&&"animate-spin"),"aria-hidden":!0}),b?a("settings.menubar.syncing"):a("settings.menubar.syncNow")]})}),e.jsx(E,{label:a("settings.menubar.autoUpdate"),hint:a("settings.menubar.autoUpdateHint"),control:e.jsx(D,{checked:y,onChange:()=>r("autoUpdateEnabled",!y),ariaLabel:a("settings.menubar.autoUpdate")})}),e.jsx(E,{label:a("settings.menubar.updates"),hint:x||void 0,control:e.jsxs("button",{type:"button",onClick:()=>n("checkForUpdates"),disabled:g,className:"inline-flex h-8 items-center gap-1.5 rounded-md border border-oai-gray-200 px-3 text-xs font-medium text-oai-gray-700 transition-colors hover:bg-oai-gray-100 disabled:cursor-not-allowed disabled:opacity-50 dark:border-oai-gray-800 dark:text-oai-gray-300 dark:hover:bg-oai-gray-800",children:[e.jsx(Ra,{className:"h-3.5 w-3.5","aria-hidden":!0}),a("settings.menubar.checkUpdates")]})})]})}function $s(t,s){function r(c){return c.replace(/^v/,"").split(".").map(Number)}const n=r(t),i=r(s);for(let c=0;c<Math.max(n.length,i.length);c++){const m=n[c]||0,o=i[c]||0;if(m<o)return!0;if(m>o)return!1}return!1}function zs(){const{available:t,settings:s,runAction:r}=ie(),n=t&&s?.version,i=s?.platform||"macos",[c,m]=xe.useState(!1),[o,d]=xe.useState({open:!1,latestVersion:"",htmlUrl:""}),{resolvedLocale:y}=Ve(),x="1.3.4",g=async()=>{m(!0);try{const p=await fetch("https://api.github.com/repos/xiufengsun/TokenTracker/releases/latest");if(!p.ok)throw new Error("Failed to fetch");const u=await p.json(),k=u.tag_name;$s(x,k)?d({open:!0,latestVersion:k,htmlUrl:u.html_url}):Oe({title:a("settings.menubar.updates.upToDate")})}catch(p){console.error("Check updates failed:",p),Oe({title:a("settings.menubar.updates.failed")})}finally{m(!1)}},b=a("settings.menubar.updates.modalTitle"),v=a("settings.menubar.updates.modalDescription",{version:o.latestVersion}),N=a("settings.menubar.updates.modalConfirm"),j=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:[n?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:x})}),e.jsx("span",{"aria-hidden":!0,children:"·"}),e.jsx("button",{type:"button",onClick:()=>r("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:x})}),e.jsx("span",{"aria-hidden":!0,children:"·"}),e.jsx("button",{type:"button",onClick:g,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:qt,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(Wt,{className:"h-3.5 w-3.5","aria-hidden":!0}),a("settings.footer.statusPage")]})]}),e.jsx(Ta,{open:o.open,title:b,description:v,confirmLabel:N,cancelLabel:j,onConfirm:()=>{window.open(o.htmlUrl,"_blank"),d(p=>({...p,open:!1}))},onCancel:()=>d(p=>({...p,open:!1}))})]})}const Fs=()=>[{value:"system",label:a("settings.network.mode.system")},{value:"manual",label:a("settings.network.mode.manual")},{value:"off",label:a("settings.network.mode.off")}],Hs=()=>[{value:"http",label:a("settings.network.protocol.http")},{value:"https",label:a("settings.network.protocol.https")},{value:"socks5",label:a("settings.network.protocol.socks5")}],Ge="w-full rounded-md border border-oai-gray-300 bg-transparent px-2.5 py-1.5 text-sm text-oai-black outline-none focus:border-oai-brand-500 focus:ring-1 focus:ring-inset focus:ring-oai-brand-500 dark:border-oai-gray-700 dark:text-white";function Ue(t){const s={},r=String(t.host||"").trim();(!r||/:\/\//.test(r)||r.includes("/"))&&(s.host=a("settings.network.error.host"));const n=String(t.port??"").trim(),i=Number(n);return(!n||!/^\d+$/.test(n)||!Number.isInteger(i)||i<1||i>65535)&&(s.port=a("settings.network.error.port")),s}function Bs({proxySettings:t}){const{config:s,save:r,testConnection:n}=t,[i,c]=l.useState(()=>({mode:s.mode,protocol:s.protocol||"http",host:s.host||"",port:s.port||""})),[m,o]=l.useState({}),[d,y]=l.useState(!1),[x,g]=l.useState(""),[b,v]=l.useState(null),[N,j]=l.useState(!1),[p,u]=l.useState(null);l.useEffect(()=>{c({mode:s.mode,protocol:s.protocol||"http",host:s.host||"",port:s.port||""})},[s.mode,s.protocol,s.host,s.port]);const k=l.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]),C=_=>{c(w=>({...w,..._})),o({}),g(""),v(null),u(null)},h=async()=>{if(i.mode==="manual"){const _=Ue(i);if(Object.keys(_).length){o(_);return}}y(!0),g(""),v(null);try{await r(i),g("saved")}catch(_){g("error"),v(_)}finally{y(!1)}},S=async()=>{const _=Ue(i);if(Object.keys(_).length){o(_);return}j(!0),u(null);try{const w=await n(i);u(w)}catch(w){u({ok:!1,error:w?.message||String(w)})}finally{j(!1)}};return e.jsxs(V,{title:a("settings.section.network"),subtitle:k,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(E,{label:a("settings.network.mode.label"),hint:a("settings.network.mode.hint"),control:e.jsx(W,{options:Fs(),value:i.mode,onChange:_=>C({mode:_})})}),e.jsx(Ye,{initial:!1,children:i.mode==="manual"?e.jsxs(qe.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(E,{label:a("settings.network.protocol.label"),control:e.jsx(ve,{value:i.protocol,onValueChange:_=>C({protocol:_}),options:Hs(),ariaLabel:a("settings.network.protocol.label"),className:"px-2.5 py-1.5 text-xs font-medium"})}),e.jsx(E,{label:a("settings.network.host.label"),hint:m.host,control:e.jsx("input",{type:"text",value:i.host,onChange:_=>C({host:_.target.value}),placeholder:a("settings.network.host.placeholder"),autoComplete:"off",spellCheck:!1,"aria-invalid":m.host?!0:void 0,"aria-label":a("settings.network.host.label"),className:Ge})}),e.jsx(E,{label:a("settings.network.port.label"),hint:m.port,control:e.jsx("input",{type:"text",inputMode:"numeric",value:i.port,onChange:_=>C({port:_.target.value}),placeholder:a("settings.network.port.placeholder"),autoComplete:"off",spellCheck:!1,"aria-invalid":m.port?!0:void 0,"aria-label":a("settings.network.port.label"),className:Ge})}),e.jsxs("div",{className:"flex flex-wrap items-center justify-end gap-2 py-3",children:[e.jsx("button",{type:"button",onClick:S,disabled:N||d,className:"rounded-md border border-oai-gray-200 px-3 py-1.5 text-xs font-medium text-oai-gray-700 transition-colors hover:bg-oai-gray-100 disabled:opacity-50 dark:border-oai-gray-800 dark:text-oai-gray-300 dark:hover:bg-oai-gray-800",children:N?a("settings.network.test.testing"):a("settings.network.test")}),e.jsx("button",{type:"button",onClick:h,disabled:d||N,className:"rounded-md bg-oai-brand-500 px-3 py-1.5 text-xs font-medium text-white transition-colors hover:bg-oai-brand-600 disabled:opacity-50",children:d?a("settings.network.saving"):a("settings.network.save")})]}),p?e.jsx("p",{className:"py-2 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:p.ok?a("settings.network.test.ok",{status:String(p.status??"")}):a("settings.network.test.fail",{error:p.error||""})}):null]},"manual-proxy-fields"):e.jsx("div",{className:"flex justify-end py-3",children:e.jsx("button",{type:"button",onClick:h,disabled:d,className:"rounded-md bg-oai-brand-500 px-3 py-1.5 text-xs font-medium text-white transition-colors hover:bg-oai-brand-600 disabled:opacity-50",children:d?a("settings.network.saving"):a("settings.network.save")})},"non-manual-save")}),x==="saved"?e.jsx("p",{className:"py-2 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:a("settings.network.saved")}):null,x==="error"?e.jsx("p",{role:"alert",className:"py-2 text-xs text-red-600 dark:text-red-400",children:b?.unprotected?a("settings.network.save_error_unprotected",{error:b?.message||String(b||"")}):a("settings.network.save_error",{error:b?.message||String(b||"")})}):null]})}const dt="/functions/tokentracker-proxy-config",Vs="/functions/tokentracker-proxy-test",Ks={mode:"system",protocol:"http",host:"",port:"",effective:"none",applyError:null};function ut(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 qs(){const t=await fetch(dt,{method:"GET",headers:{Accept:"application/json"},cache:"no-store"});if(!t.ok)return null;const s=await t.json().catch(()=>null);return ut(s)}async function Me(){const{getLocalApiAuthHeaders:t}=await Yt(async()=>{const{getLocalApiAuthHeaders:s}=await import("./__vite-browser-external-Bq8nj-JV.js").then(r=>r.dZ);return{getLocalApiAuthHeaders:s}},__vite__mapDeps([0,1]));return t()}function Ws(){const[t,s]=l.useState(!1),[r,n]=l.useState(!0),[i,c]=l.useState(Ks);l.useEffect(()=>{if(!ya()){s(!1),n(!1);return}let d=!1;return(async()=>{try{const y=await qs();if(d)return;if(!y){s(!1),n(!1);return}c(y),s(!0),n(!1)}catch{d||(s(!1),n(!1))}})(),()=>{d=!0}},[]);const m=l.useCallback(async d=>{const y=await Me(),x=await fetch(dt,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json",...y},cache:"no-store",body:JSON.stringify({mode:d.mode,protocol:d.protocol,host:d.host,port:d.port===""?0:Number(d.port)})}),g=await x.json().catch(()=>null);if(!x.ok){const v=g&&typeof g.error=="string"?g.error:`HTTP ${x.status}`;throw new Error(v)}const b=ut(g);if(b&&c(b),g&&g.ok===!1){const v=g&&typeof g.applyError=="string"&&g.applyError||g&&typeof g.error=="string"&&g.error||`HTTP ${x.status}`,N=new Error(v);throw g.unprotected===!0&&(N.unprotected=!0),N}return b||g},[]),o=l.useCallback(async d=>{const y=await Me(),x=await fetch(Vs,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json",...y},cache:"no-store",body:JSON.stringify({protocol:d.protocol,host:d.host,port:d.port===""?0:Number(d.port)})}),g=await x.json().catch(()=>null);if(!g||typeof g.ok!="boolean")throw new Error(g&&typeof g.error=="string"?g.error:`HTTP ${x.status}`);return g},[]);return{available:t,loading:r,config:i,save:m,testConnection:o}}const I={APPEARANCE:"appearance",NATIVE_APP:"native-app",NETWORK:"network",ACCOUNT:"account",CLOUD:"cloud",LIMITS:"limits",LABS:"labs"},M={PERSONAL:"personal",APP:"app",DEVELOPER:"developer"};function Ys({prefs:t}){return e.jsx(W,{options:[{value:Ie.USED,label:a("limits.settings.display_mode_used")},{value:Ie.REMAINING,label:a("limits.settings.display_mode_remaining")}],value:t.displayMode,onChange:t.setDisplayMode})}function In(){const t=ke(),s=ua(),{available:r,settings:n,setSetting:i}=ie(),c=Ws(),{available:m}=c,o=n?.toastOnReset!==!1,d=n?.confettiOnReset!==!1,y=Ke()||n?.platform==="windows",[x,g]=Zt(),b=He(),v=x.get("section"),j=Object.values(I).includes(v)&&(v!==I.NATIVE_APP||r)&&(v!==I.NETWORK||m)?v:I.APPEARANCE,p=h=>{const S=new URLSearchParams(x);h===I.APPEARANCE?S.delete("section"):S.set("section",h),g(S,{replace:!0})},u=[{id:I.APPEARANCE,label:a("settings.section.appearance"),description:a("settings.section.appearance.description"),group:M.PERSONAL,Icon:za,content:e.jsx(Gs,{})},...r?[{id:I.NATIVE_APP,label:a("settings.section.menubar"),description:a("settings.section.menubar.description"),group:M.APP,Icon:ye,content:e.jsx(Ms,{})}]:[],...m?[{id:I.NETWORK,label:a("settings.section.network"),description:a("settings.section.network.description"),group:M.APP,Icon:Jt,content:e.jsx(Bs,{proxySettings:c})}]:[],{id:I.ACCOUNT,label:a("settings.section.account"),description:a("settings.section.account.description"),group:M.PERSONAL,Icon:Fa,content:e.jsx(ms,{settings:t})},{id:I.CLOUD,label:a("settings.section.cloud"),description:a("settings.section.cloud.description"),group:M.PERSONAL,Icon:se,content:e.jsx(Cs,{settings:t,active:j===I.CLOUD})},{id:I.LIMITS,label:a("settings.section.limits"),description:a("settings.section.limits.description"),group:M.APP,Icon:Qt,content:e.jsxs("div",{className:"space-y-4",children:[e.jsxs(V,{title:a("settings.section.limits"),children:[e.jsx(E,{label:a("limits.settings.display_mode_label"),control:e.jsx(Ys,{prefs:s})}),y?null:e.jsxs(e.Fragment,{children:[e.jsx(E,{label:a("settings.menubar.toastOnReset"),hint:a("settings.menubar.toastOnResetHint"),control:e.jsx(D,{checked:o,disabled:!r,onChange:()=>i("toastOnReset",!o),ariaLabel:a("settings.menubar.toastOnReset")})}),e.jsx(E,{label:a("settings.menubar.confettiOnReset"),hint:a("settings.menubar.confettiOnResetHint"),control:e.jsx(D,{checked:d,disabled:!r,onChange:()=>i("confettiOnReset",!d),ariaLabel:a("settings.menubar.confettiOnReset")})})]}),e.jsx(E,{label:a("settings.limits.showSubscriptions"),hint:a("settings.limits.showSubscriptionsHint"),control:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("button",{type:"button",onClick:()=>b("/limits?openSubscriptions=1"),"aria-label":a("limits.page.openSubscriptions"),title:a("limits.page.openSubscriptions"),className:"inline-flex h-7 w-7 items-center justify-center rounded-md border border-oai-gray-200 dark:border-oai-gray-700 bg-white dark:bg-oai-gray-900 text-oai-gray-500 dark:text-oai-gray-400 hover:bg-oai-gray-100 dark:hover:bg-oai-gray-800 hover:text-oai-black dark:hover:text-white transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand-500",children:e.jsx(Xt,{size:14,"aria-hidden":!0})}),e.jsx(D,{checked:s.showSubscriptions!==!1,onChange:()=>s.setShowSubscriptions(!s.showSubscriptions),ariaLabel:a("settings.limits.showSubscriptions")})]})})]}),e.jsx(V,{title:a("settings.limits.providers"),children:e.jsx(Ka,{prefs:s})})]})},{id:I.LABS,label:a("settings.section.labs"),description:a("settings.section.labs.description"),group:M.DEVELOPER,Icon:Ga,content:e.jsx(Us,{})}],k=[{id:M.PERSONAL,label:a("settings.nav.group.personal")},{id:M.APP,label:a("settings.nav.group.app")},{id:M.DEVELOPER,label:a("settings.nav.group.developer")}].map(h=>({...h,sections:u.filter(S=>S.group===h.id)})).filter(h=>h.sections.length>0);let C=u[0];for(const h of u)if(h.id===j){C=h;break}return e.jsx("div",{className:B("flex flex-1 flex-col font-oai text-oai-black antialiased dark:text-oai-white",j===I.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:k.map(({id:h,label:S,sections:_})=>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:S}),e.jsx("div",{className:"flex gap-1 md:flex-col",children:_.map(({id:w,label:A,Icon:T})=>{const f=j===w;return e.jsxs("button",{id:`settings-nav-${w}`,type:"button","aria-current":f?"page":void 0,"aria-controls":`settings-panel-${w}`,onClick:()=>p(w),className:B("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",f?"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(T,{className:B("h-4 w-4 shrink-0",f?"text-oai-black dark:text-white":"text-oai-gray-400 dark:text-oai-gray-500"),"aria-hidden":!0}),e.jsx("span",{className:"truncate",children:A})]},w)})})]},h))})}),e.jsxs("div",{className:"min-w-0",children:[j!==I.CLOUD?e.jsxs("div",{className:"mb-4 border-b border-oai-gray-200 pb-4 dark:border-oai-gray-800",children:[e.jsx("h2",{className:"text-xl font-semibold tracking-tight text-oai-black dark:text-white",children:C.label}),e.jsx("p",{className:"mt-1 text-sm leading-5 text-oai-gray-500 dark:text-oai-gray-400",children:C.description})]}):null,u.map(({id:h,label:S,content:_})=>e.jsx("section",{id:`settings-panel-${h}`,"aria-labelledby":`settings-nav-${h}`,"aria-label":S,"data-settings-panel":h,hidden:j!==h,children:_},h)),e.jsx(zs,{})]})]})]})})})}export{In as SettingsPage};