tokentracker-cli 0.95.2 → 0.96.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (118) hide show
  1. package/README.md +2 -0
  2. package/README.zh-CN.md +1 -1
  3. package/dashboard/dist/assets/{AchievementBadge-DtB1MwFe.js → AchievementBadge-DKyElm0T.js} +1 -1
  4. package/dashboard/dist/assets/{AchievementsPage--vddu0dC.js → AchievementsPage-BvCx3wND.js} +2 -2
  5. package/dashboard/dist/assets/{AchievementsSection-CDl9hsbj.js → AchievementsSection-DN69LzXX.js} +1 -1
  6. package/dashboard/dist/assets/{BadgeDetailModal-C7WsIRy9.js → BadgeDetailModal-DGiKdZfz.js} +1 -1
  7. package/dashboard/dist/assets/{BotAnimated-CmXyzIhX.js → BotAnimated-zN8rH7_K.js} +1 -1
  8. package/dashboard/dist/assets/{Card-SUbC3VNS.js → Card-COWo-ClV.js} +1 -1
  9. package/dashboard/dist/assets/{ClawdAnimated-BdEbs8Me.js → ClawdAnimated-BWsB7Eat.js} +2 -2
  10. package/dashboard/dist/assets/{CommandPalette-D1RLLeHB.js → CommandPalette-BfvIwuoJ.js} +1 -1
  11. package/dashboard/dist/assets/{CommunityStatsModal-5ESGJgZQ.js → CommunityStatsModal-BQWg7R_y.js} +1 -1
  12. package/dashboard/dist/assets/{ConfirmModal-DsCd51b2.js → ConfirmModal-C7ABSI-O.js} +1 -1
  13. package/dashboard/dist/assets/{Controls-BVrLC_QD.js → Controls-vMzEZzej.js} +1 -1
  14. package/dashboard/dist/assets/DashboardPage-QBhbCMZF.js +1 -0
  15. package/dashboard/dist/assets/{DevicePage-zYjj-m5V.js → DevicePage-3ejUBLWM.js} +1 -1
  16. package/dashboard/dist/assets/{DialogClose-D66yBqkd.js → DialogClose-D_dvtfGV.js} +1 -1
  17. package/dashboard/dist/assets/DialogDescription-ryGYdQjX.js +1 -0
  18. package/dashboard/dist/assets/{DialogTitle-C4ia00lc.js → DialogTitle-_ahf0z8b.js} +1 -1
  19. package/dashboard/dist/assets/{FadeIn-DF2c8XaR.js → FadeIn-D7Jcfz1N.js} +1 -1
  20. package/dashboard/dist/assets/{HeaderGithubStar-Cnr3aqcX.js → HeaderGithubStar-D--Rx5BS.js} +1 -1
  21. package/dashboard/dist/assets/{HoverTooltip-DBOpxlH7.js → HoverTooltip-n1W0z3Wr.js} +1 -1
  22. package/dashboard/dist/assets/{IpCheckPage-CUY6KBaV.js → IpCheckPage-D202tl9B.js} +1 -1
  23. package/dashboard/dist/assets/{LandingPage-DKL8hZEq.js → LandingPage-D6yL2EZo.js} +2 -2
  24. package/dashboard/dist/assets/{LeaderboardAvatar-DRYeMNlq.js → LeaderboardAvatar-ChFg2mtA.js} +1 -1
  25. package/dashboard/dist/assets/{LeaderboardPage-DpD9Az3k.js → LeaderboardPage-BXHwGs8r.js} +2 -2
  26. package/dashboard/dist/assets/{LeaderboardProfileModal-Dfg0V13F.js → LeaderboardProfileModal-B5LoOpCk.js} +3 -3
  27. package/dashboard/dist/assets/{LeaderboardProfilePage-DH-jcVDu.js → LeaderboardProfilePage-jsukhRz8.js} +1 -1
  28. package/dashboard/dist/assets/LimitsPage-PvqkOOwp.js +6 -0
  29. package/dashboard/dist/assets/{LocalOnlyNotice-Bj_m0hw7.js → LocalOnlyNotice-Du0lz657.js} +1 -1
  30. package/dashboard/dist/assets/{LoginCard-BVKvtx60.js → LoginCard-BFEX9x7-.js} +1 -1
  31. package/dashboard/dist/assets/{LoginModal-mUGiSIJN.js → LoginModal-DqC7_d35.js} +1 -1
  32. package/dashboard/dist/assets/{LoginPage-BORCuCUt.js → LoginPage-Dzx8N7HE.js} +1 -1
  33. package/dashboard/dist/assets/{PetPage-D1JfEOVA.js → PetPage-CNlWHF4z.js} +1 -1
  34. package/dashboard/dist/assets/{PopoverPopup-DK3et-HG.js → PopoverPopup-D9jadD3j.js} +1 -1
  35. package/dashboard/dist/assets/{ProviderIcon-By8FAjxR.js → ProviderIcon-Caz5PuAm.js} +1 -1
  36. package/dashboard/dist/assets/{ResetPasswordPage-DPa81jqa.js → ResetPasswordPage-x_GR79sR.js} +1 -1
  37. package/dashboard/dist/assets/{SegmentedControl-DLzS-2eZ.js → SegmentedControl-BxDiDV4R.js} +1 -1
  38. package/dashboard/dist/assets/{Select-C05W6XEM.js → Select-B5o-1sEl.js} +1 -1
  39. package/dashboard/dist/assets/{SelectItemText-CcfB3blP.js → SelectItemText-CiA6L7Wk.js} +1 -1
  40. package/dashboard/dist/assets/{ServiceStatusPage-ByqLbHv1.js → ServiceStatusPage-BVQuVdjg.js} +1 -1
  41. package/dashboard/dist/assets/SessionsPage-DE39wNIO.js +2 -0
  42. package/dashboard/dist/assets/SettingsPage-DJrb_fsK.js +2 -0
  43. package/dashboard/dist/assets/{SkillsPage-BuuqQuNU.js → SkillsPage-COk-YQQ5.js} +1 -1
  44. package/dashboard/dist/assets/{TokenGalaxy-DzccxkXW.js → TokenGalaxy-BPM779Wb.js} +1 -1
  45. package/dashboard/dist/assets/{ToolbarRootContext-XUDMp5uy.js → ToolbarRootContext-CozJT6Vs.js} +1 -1
  46. package/dashboard/dist/assets/{TrendMonitor-B-yYabbz.js → TrendMonitor-BkNy-o1D.js} +1 -1
  47. package/dashboard/dist/assets/{WidgetsPage-CwUDjEFo.js → WidgetsPage-Bpg6H-ZB.js} +1 -1
  48. package/dashboard/dist/assets/{WrappedPage-Dr9ow3gH.js → WrappedPage-C6-NM-RO.js} +1 -1
  49. package/dashboard/dist/assets/__vite-browser-external-BGnq8Ebm.js +45 -0
  50. package/dashboard/dist/assets/__vite-browser-external-CvMMIjhi.css +1 -0
  51. package/dashboard/dist/assets/{agent-logos-Cqc_suYk.js → agent-logos-DpbkRqXT.js} +1 -1
  52. package/dashboard/dist/assets/{arrow-up-right-DSsR3Ntr.js → arrow-up-right-BjOtWUVs.js} +1 -1
  53. package/dashboard/dist/assets/{check-Cy35lAKh.js → check-BlxnX5jZ.js} +1 -1
  54. package/dashboard/dist/assets/{composite-BDwOlhhX.js → composite-Dxmivlk4.js} +1 -1
  55. package/dashboard/dist/assets/{copy-4szu5cYh.js → copy-CIsWjLY5.js} +1 -1
  56. package/dashboard/dist/assets/{download-DdGW6Krz.js → download-QDaQbQdd.js} +1 -1
  57. package/dashboard/dist/assets/{external-link-DwSt83cq.js → external-link-DPV4VU3m.js} +1 -1
  58. package/dashboard/dist/assets/{flame-DubukWqK.js → flame-B_X-7VNp.js} +1 -1
  59. package/dashboard/dist/assets/{format-tokens-B70EdQcN.js → format-tokens-DEx2TJj8.js} +1 -1
  60. package/dashboard/dist/assets/{icons-B86TLdAj.js → icons-983RyGSl.js} +1 -1
  61. package/dashboard/dist/assets/{index-B_KMoBeK.js → index-BONYA8HZ.js} +1 -1
  62. package/dashboard/dist/assets/{index-DI-W-pun.js → index-Cjs5stC0.js} +1 -1
  63. package/dashboard/dist/assets/{index-DzEMcUwI.js → index-qtonw_x4.js} +1 -1
  64. package/dashboard/dist/assets/{info-BzFpLbl6.js → info-DpVOhXZI.js} +1 -1
  65. package/dashboard/dist/assets/limits-providers-BUoquSA-.js +1 -0
  66. package/dashboard/dist/assets/{link-2-BQp7-3T7.js → link-2-CBro-upz.js} +1 -1
  67. package/dashboard/dist/assets/{loader-circle-lrDmbIg5.js → loader-circle-wYFdSyOd.js} +1 -1
  68. package/dashboard/dist/assets/{maximize-2-Cnd_Oth8.js → maximize-2-DhTyQ4ly.js} +1 -1
  69. package/dashboard/dist/assets/{modifiers.esm-CPTpZdHU.js → modifiers.esm-CPljwVhN.js} +1 -1
  70. package/dashboard/dist/assets/{monitor-smartphone-C7UY1zRx.js → monitor-smartphone-D_wr-HOR.js} +1 -1
  71. package/dashboard/dist/assets/{plus-Bglp9N_7.js → plus-BNjfkBEF.js} +1 -1
  72. package/dashboard/dist/assets/{provider-display-CGsFySs6.js → provider-display-BOBtUyFi.js} +1 -1
  73. package/dashboard/dist/assets/{react-DKXriBSF.js → react-yHv9MTUA.js} +1 -1
  74. package/dashboard/dist/assets/{search-D_LLDRdU.js → search-Dfak92ZA.js} +1 -1
  75. package/dashboard/dist/assets/{skills-api-CJWjKIco.js → skills-api-By2PdNa1.js} +1 -1
  76. package/dashboard/dist/assets/{sortable.esm-zlY09tye.js → sortable.esm-B9xy66_v.js} +1 -1
  77. package/dashboard/dist/assets/{store-8e16Ac2h.js → store-oQZR4d9M.js} +1 -1
  78. package/dashboard/dist/assets/{terminal-CR228ekj.js → terminal-pbXWBmZM.js} +1 -1
  79. package/dashboard/dist/assets/{trash-2-BjLWewOp.js → trash-2-CboDPwbW.js} +1 -1
  80. package/dashboard/dist/assets/{use-community-stats-DhOJPaVg.js → use-community-stats-D6HTdnHq.js} +1 -1
  81. package/dashboard/dist/assets/{use-latest-request-guard-lcGhb-NC.js → use-latest-request-guard-hwSr9Cam.js} +1 -1
  82. package/dashboard/dist/assets/{use-limits-display-prefs-DJIImtLN.js → use-limits-display-prefs-B-pbwUS8.js} +1 -1
  83. package/dashboard/dist/assets/{use-ordered-list-BJZfZuoJ.js → use-ordered-list-OtfOqrNb.js} +1 -1
  84. package/dashboard/dist/assets/use-reduced-motion-DGXcZBX3.js +1 -0
  85. package/dashboard/dist/assets/{use-session-efficiency-pref-C-l4b1cD.js → use-session-efficiency-pref-BScvtS8F.js} +1 -1
  86. package/dashboard/dist/assets/{use-transform-UjIt477N.js → use-transform-Cy1ykjEs.js} +1 -1
  87. package/dashboard/dist/assets/{use-usage-limits-DqoTZrqT.js → use-usage-limits-CSMb2zYW.js} +1 -1
  88. package/dashboard/dist/assets/{useCurrency-CnM8aB4v.js → useCurrency-VqF3cy1C.js} +1 -1
  89. package/dashboard/dist/assets/{useTokenFormat-D4pAK2ld.js → useTokenFormat-Cgub4MXu.js} +1 -1
  90. package/dashboard/dist/assets/{zap-Du1IyEtj.js → zap-DStzvQJI.js} +1 -1
  91. package/dashboard/dist/index.html +2 -2
  92. package/dashboard/dist/ip-check.html +2 -2
  93. package/dashboard/dist/leaderboard.html +2 -2
  94. package/dashboard/dist/share.html +2 -2
  95. package/package.json +1 -1
  96. package/src/commands/status.js +4 -4
  97. package/src/commands/sync.js +5 -3
  98. package/src/lib/ark-agent-plan-limits.js +438 -0
  99. package/src/lib/ark-coding-plan-limits.js +103 -28
  100. package/src/lib/codex-model-attribution.js +128 -0
  101. package/src/lib/codex-rollout-parser.js +98 -4
  102. package/src/lib/command-runner.js +13 -0
  103. package/src/lib/local-api.js +3 -0
  104. package/src/lib/pricing/curated-overrides.json +6 -6
  105. package/src/lib/pricing/index.js +38 -1
  106. package/src/lib/pricing/seed-snapshot.json +1 -1
  107. package/src/lib/rollout.js +67 -14
  108. package/src/lib/session-analytics.js +374 -110
  109. package/src/lib/usage-limits.js +130 -18
  110. package/dashboard/dist/assets/DashboardPage-DtUOG6og.js +0 -1
  111. package/dashboard/dist/assets/DialogDescription-BVlaoajd.js +0 -1
  112. package/dashboard/dist/assets/LimitsPage-CVCKPScf.js +0 -5
  113. package/dashboard/dist/assets/SessionsPage-CEDv1thj.js +0 -2
  114. package/dashboard/dist/assets/SettingsPage-DAcndJZQ.js +0 -2
  115. package/dashboard/dist/assets/__vite-browser-external-CCMdjCX2.css +0 -1
  116. package/dashboard/dist/assets/__vite-browser-external-DPOlUkcY.js +0 -45
  117. package/dashboard/dist/assets/limits-providers-DxZOjiXQ.js +0 -1
  118. package/dashboard/dist/assets/use-reduced-motion-DdpxZQoh.js +0 -1
@@ -1,5 +0,0 @@
1
- import{m as G,j as e,e as Se,c as i,k as re,r as x,Q as Xe,B as H,aw as Je,d as D,h as Qe,J as ye,L as Ze,ax as et,q as tt,ac as at}from"./__vite-browser-external-DPOlUkcY.js";import{m as ve}from"./react-DKXriBSF.js";import{P as xe,c as rt,r as ie,a as it,u as nt,b as st,s as ot}from"./use-usage-limits-DqoTZrqT.js";import{L as k,u as lt}from"./use-limits-display-prefs-DJIImtLN.js";import{C as Pe}from"./Card-SUbC3VNS.js";import{F as ct}from"./FadeIn-DF2c8XaR.js";import{L as Ce,l as ee,a as De}from"./limits-providers-DxZOjiXQ.js";import{P as Ee}from"./ProviderIcon-By8FAjxR.js";import{H as dt}from"./HoverTooltip-DBOpxlH7.js";import{C as ut}from"./ConfirmModal-DsCd51b2.js";import{I as ke,L as mt}from"./LocalOnlyNotice-Bj_m0hw7.js";import{S as ce}from"./Select-C05W6XEM.js";import{P as xt}from"./plus-Bglp9N_7.js";import{P as pt,a as gt,b as ft,c as ht,d as bt}from"./PopoverPopup-DK3et-HG.js";import{u as yt}from"./use-reduced-motion-DdpxZQoh.js";import"./use-latest-request-guard-lcGhb-NC.js";import"./DialogTitle-C4ia00lc.js";import"./composite-BDwOlhhX.js";import"./store-8e16Ac2h.js";import"./DialogDescription-BVlaoajd.js";import"./arrow-up-right-DSsR3Ntr.js";import"./download-DdGW6Krz.js";import"./ToolbarRootContext-XUDMp5uy.js";import"./check-Cy35lAKh.js";import"./SelectItemText-CcfB3blP.js";const vt=[["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"}]],kt=G("bell-off",vt);const jt=[["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"}]],wt=G("bell",jt);const Nt=[["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"}]],Te=G("calendar-clock",Nt);const _t=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 6v6l4 2",key:"mmk7yg"}]],Ie=G("clock",_t);const Mt=[["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"}]],Re=G("infinity",Mt),St=[3,2,3,3,2,2,3];function T({className:t}){return e.jsx("div",{className:Se("rounded bg-oai-gray-200/70 dark:bg-oai-gray-800/70 animate-pulse",t)})}function Pt(){return e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(T,{className:"h-3 w-12 shrink-0"}),e.jsx(T,{className:"flex-1 h-1.5 rounded-full min-w-0"}),e.jsx(T,{className:"h-3 w-[30px] shrink-0"}),e.jsx(T,{className:"h-3 w-6 shrink-0"})]})}function Ct({bars:t,index:a}){const r=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(T,{className:"h-[14px] w-[14px] rounded shrink-0"}),e.jsx(T,{className:Se("h-4",r)})]}),Array.from({length:t},(s,n)=>e.jsx(Pt,{},n))]})}function Dt(){return e.jsx(Pe,{children:e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx(T,{className:"h-3.5 w-28"}),St.map((t,a)=>e.jsx(Ct,{bars:t,index:a},a))]})})}const pe=100;function je(t){const a=Date.parse(t);return Number.isFinite(a)?a:null}function Et(t){return Math.max(0,Math.min(pe,Math.round(t)))}function Tt(t){return new Intl.DateTimeFormat(re(),{month:"numeric",day:"numeric",hour:"2-digit",minute:"2-digit",hour12:!1}).format(new Date(t))}function It(t,a,r){if(t==null||t>=a)return pe;const s=a-t,n=a-r;return Et(n/s*pe)}function Rt(t){const a=t.available_count;return a===null?null:Number.isInteger(a)&&a>=0?a:void 0}function At(t,{now:a}={}){if(!t||typeof t!="object")return null;const r=Rt(t);if(r===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=je(l?.expires_at);if(c==null)continue;const d=o.length+1;o.push({key:`reset-${d}`,label:i("limits.codex_reset_bank.row_label",{index:d}),expiresAt:Tt(c),expiresMs:c,percent:It(je(l?.granted_at),c,n)})}return r===0?null:o.length>0?{kind:"rows",availableCount:r??o.length,rows:o}:r>0?{kind:"count_only",availableCount:r,rows:[]}:null}const B=864e5;function I(t,a){const r=new Date(t),s=r.getUTCDate(),n=new Date(Date.UTC(r.getUTCFullYear(),r.getUTCMonth()+a,1,r.getUTCHours(),r.getUTCMinutes())),o=new Date(Date.UTC(n.getUTCFullYear(),n.getUTCMonth()+1,0)).getUTCDate();return n.setUTCDate(Math.min(s,o)),n.getTime()}function Ae(t,a){if(a==="weekly")return t-7*B;if(a==="yearly")return I(t,-12);const r=new Date(t),s=new Date(Date.UTC(r.getUTCFullYear(),r.getUTCMonth(),0)).getUTCDate(),n=new Date(Date.UTC(r.getUTCFullYear(),r.getUTCMonth()-1,1,r.getUTCHours(),r.getUTCMinutes()));return n.setUTCDate(Math.min(r.getUTCDate(),s)),n.getTime()}function Oe(t,a){return a==="weekly"?t+7*B:a==="yearly"?I(t,12):I(t,1)}function Ot(t){if(t.startedAt!=null){const a=new Date(t.startedAt).getTime();if(Number.isFinite(a))return a}return Ae(new Date(t.nextBillingAt).getTime(),t.cycle)}function Ft(t,a,r){if(t.startedAt!=null){const s=new Date(t.startedAt).getTime();if(Number.isFinite(s))return s}return Ae(r,a)}function Lt(t,a,r){if(a==="weekly"){const c=7*B,d=r<=t?0:Math.floor((r-t)/c);return{startMs:t+d*c,endMs:t+(d+1)*c}}const s=a==="yearly"?12:1,n=s*30.436875*B;let o=r<=t?0:Math.floor((r-t)/n);for(;o>0&&I(t,o*s)>r;)o-=1;let l=0;for(;I(t,(o+1)*s)<=r&&l<12e3;)o+=1,l+=1;return{startMs:I(t,o*s),endMs:I(t,(o+1)*s)}}function te(t,a){const r=new Date(t.nextBillingAt).getTime();if(!Number.isFinite(r))return null;const s=["weekly","monthly","yearly"].includes(t.cycle)?t.cycle:"monthly",n=Ft(t,s,r);if(!Number.isFinite(n))return null;let o,l,c=!1;t.autoRenew?{startMs:o,endMs:l}=Lt(n,s,a):t.startedAt!=null?(o=n,l=Oe(n,s),c=l<=a):(o=n,l=r,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/B)),expired:c}}function Fe(t,a){const r=t-a;if(r<=0)return i("subscriptions.expired");const s=Math.ceil(r/6e4);if(s<60)return`${s}m`;const n=Math.floor(s/60);return n<24?`${n}h`:`${Math.floor(n/24)}d`}function ge(t,a){const r=t-a;if(r<=0)return i("subscriptions.expired");const s=Math.floor(r/6e4),n=Math.floor(s/1440),o=Math.floor(s%1440/60),l=s%60;return i("subscriptions.countdown",{days:n,hours:o,minutes:l})}const $t="shrink-0 text-oai-black dark:text-oai-white";function Ht(t){const a=ie(t);if(!Number.isFinite(a))return null;const r=a-Date.now();if(r<=0)return i("shared.time.now");const s=Math.floor(r/6e4);if(s<60)return`${s}m`;const n=Math.floor(s/60);return n<24?`${n}h`:`${Math.floor(n/24)}d`}function Ut(t,a){const r=a===k.REMAINING?100-t:t;return r>=90?"bg-red-500":r>=70?"bg-amber-500":"bg-emerald-500"}function ae(t,a="used_percent"){return t?a==="utilization"?t.utilization:t.used_percent:null}function ne(t,a="reset_at"){return t?a==="resets_at"?t.resets_at:t.reset_at:null}function de(t){const a=Math.max(0,Math.min(100,Number(t)||0)),r=Math.round(a);return a>0&&r===0?i("limits.bar.sub_one_percent"):String(r)}function Z(t,{useGrouping:a=!0,maximumFractionDigits:r}={}){const s=Number(t);return Number.isFinite(s)?new Intl.NumberFormat(void 0,{minimumFractionDigits:0,maximumFractionDigits:r??(s>=100?0:2),useGrouping:a}).format(s):null}function Bt(t){if(!t||typeof t!="object"||!(Number(t.limit_credits)>0))return null;const a={useGrouping:t.unit!=="calls"},r=Z(t.used_credits,a),s=Z(t.limit_credits,a),n=Z(t.remaining_credits,a);if(!r||!s||!n)return null;const o=t.unit==="calls"?"limits.qoder_calls.detail":"limits.codex_credits.detail";return i(o,{used:r,limit:s,remaining:n})}function Gt(t,a){return rt({usedPercent:ae(t.window,t.pctField),windowSeconds:it(t,t.window),resetMs:ie(ne(t.window,t.resetField)),mode:a})}function Le(t){return Number.isFinite(t)?new Intl.DateTimeFormat(re(),{month:"numeric",day:"numeric",hour:"2-digit",minute:"2-digit",hour12:!1}).format(new Date(t)):null}function Wt(t,a,r){const s=[He(t,a,r)],n=ie(ne(t.window,t.resetField)),o=Le(n);o&&s.push(i(t.timeKind==="expiry"?"limits.hover.expires_at":"limits.hover.resets_at",{time:o}));const l=Bt(t.window);return l&&s.push(l),s.join(`
2
- `)}const $e=dt;function qt({label:t,pct:a,reset:r,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),g=d>0&&m===0?Math.max(d,.35):d;let f=String(m);d>0&&m===0&&(f=i("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($e,{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:`${Ut(d,s)} rounded-full h-full transition-[width] duration-500 ease-out`,style:{width:`${g}%`,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,"%"]}),r&&e.jsx("span",{className:"text-[10px] text-oai-gray-400 dark:text-oai-gray-500 w-6 text-right shrink-0",children:r})]})}function He(t,a,r){const s=t.label??i(t.labelKey),n=r===k.REMAINING,o=d=>n?100-d:d;if(a.expectedPercent==null){const d=Math.max(0,Math.min(100,Number(ae(t.window,t.pctField))||0)),m=de(o(d));return n?i("limits.explain.remaining",{label:s,used:m}):i("limits.explain.used",{label:s,used:m})}if(a.paceOver){if(a.runsOutEta)return i("limits.explain.ahead_eta",{label:s,eta:a.runsOutEta});const d=de(o(a.projectedEnd??100));return i(n?"limits.explain.ahead_pct_remaining":"limits.explain.ahead_pct",{label:s,pct:d})}const l=Math.max(0,Math.min(100,Number(ae(t.window,t.pctField))||0)),c=de(o(a.projectedEnd??l));return i(n?"limits.explain.on_track_remaining":"limits.explain.on_track",{label:s,pct:c})}function zt({pace:t}){return t.pacePercent!=null}function Vt({rows:t,mode:a,now:r=Date.now()}){if(t.length===0)return null;const s=a===k.REMAINING,n=t.some(zt);return e.jsxs("div",{className:"mt-1 flex flex-col gap-1",children:[t.map(({spec:o,pace:l})=>{const c=Le(ie(ne(o.window,o.resetField)));return e.jsxs("div",{className:"text-[11px] leading-snug text-oai-gray-600 dark:text-oai-gray-300",children:[He(o,l,a),c?e.jsxs("span",{className:"text-oai-gray-400 dark:text-oai-gray-500",children:[" · ",i(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:i(s?"limits.explain.body_remaining":"limits.explain.body")}):null]})}function Q(t){if(!t)return null;const a=Date.now()-new Date(t).getTime();if(a<0)return null;const r=Math.floor(a/6e4);if(r<1)return i("shared.time.now");if(r<60)return i("shared.time.m_ago",{n:r});const s=Math.floor(r/60);if(s<24)return i("shared.time.h_ago",{n:s});const n=Math.floor(s/24);return i("shared.time.d_ago",{n})}const we={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"}},Yt={claude:"claude",codex:"codex"};function U({label:t,age:a=null,tone:r="live",tooltip:s=null}){const n=we[r]||we.live,o=r==="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 Ue({name:t,providerId:a,children:r,expandable:s=!1,expanded:n=!1,onToggle:o,badge:l=null,rightAdornment:c=null}){const d=De(a),m=e.jsxs("div",{className:"flex items-center gap-1.5",children:[d?e.jsx(Ee,{provider:d,size:14,className:$t}):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:g=>{(g.key==="Enter"||g.key===" ")&&(g.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,r]}):e.jsxs("div",{className:"flex flex-col gap-1.5",children:[m,r]})}function Be({subscription:t}){const a=t.autoRenew?i("subscriptions.badge.auto_renew"):i("subscriptions.badge.stops"),r=t.autoRenew?Re:Ie;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(r,{size:14,strokeWidth:2,"aria-hidden":!0})})}function Ge({subscription:t,now:a,mode:r=k.USED}){const s=te(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=r===k.REMAINING?100-c:c,m=o?100:Math.max(0,Math.min(100,d)),g=Math.round(m),f=m>0&&g===0?i("limits.bar.sub_one_percent"):`${g}%`;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:i("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:Fe(n,a)})]})}function We({subscription:t,now:a}){const r=te(t,a);if(!r)return null;const s=new Intl.DateTimeFormat(re(),{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:i("subscriptions.inline.label")}),e.jsx("span",{className:"text-oai-gray-300 dark:text-oai-gray-600",children:":"}),e.jsx("span",{children:t.autoRenew?i("subscriptions.label.renews_at"):i("subscriptions.label.expires_at")}),e.jsx("span",{children:" "}),e.jsx("span",{className:"font-mono tabular-nums",children:s.format(new Date(r.endMs))}),e.jsx("span",{className:"text-oai-gray-300 dark:text-oai-gray-600",children:" · "}),e.jsx("span",{className:r.expired?"text-oai-error":void 0,children:ge(r.endMs,a)}),e.jsx("span",{className:"text-oai-gray-300 dark:text-oai-gray-600",children:" · "}),e.jsx("span",{children:t.autoRenew?i("subscriptions.status.auto_renew"):i("subscriptions.status.manual")})]})}const Kt=Ce;function R({children:t,tone:a="neutral"}){const r=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 ${r}`,children:t})}function Xt({rows:t,mode:a,extra:r=null}){const s=t.length===0&&!r;return e.jsxs(e.Fragment,{children:[t.map(({spec:n,pace:o})=>e.jsx(qt,{label:n.label??i(n.labelKey),pct:ae(n.window,n.pctField),reset:Ht(ne(n.window,n.resetField)),mode:a,pacePercent:o.pacePercent,paceOver:o.paceOver,title:Wt(n,o,a)},n.key)),s?e.jsx(R,{children:i("limits.status.no_data")}):null,r]})}function Jt(t){if(!Number.isFinite(t.expiresMs))return null;const a=Math.floor((t.expiresMs-Date.now())/864e5);return a<0?null:a===0?i("limits.reset_bank.hover_detail_today",{date:t.expiresAt}):i("limits.reset_bank.hover_detail",{date:t.expiresAt,days:a})}function Qt({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($e,{text:Jt(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 Zt({model:t}){const a=t.kind==="count_only"?i("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:i("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(r=>e.jsx(Qt,{row:r},r.key))]})}function qe(t,a){if(t==="codex_meta"){const r=At(a.reset_credits);return r?e.jsx(Zt,{model:r}):null}if(t==="kimi_parallel"&&a.parallel_limit)return e.jsx(R,{children:i("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 r=Z(a.tracked_credits,{maximumFractionDigits:2});return e.jsx(R,{children:i("limits.label.kiro_tracked_credits",{credits:r,count:Number(a.tracked_credit_records)})})}return t==="copilot_otel"&&!a.otel_has_files&&!a.otel_enabled?e.jsx(aa,{defaultDir:a.otel_default_dir}):null}function ea(t,a,r,s,n,o,l=null,c=null,d=Date.now()){const m=xe[t];if(!m)return null;const g=m.windows(a).filter(b=>b.window).map(b=>({spec:b,pace:Gt(b,s)})),f=qe(m.extra,a);return e.jsxs(Ue,{name:r,providerId:t,expandable:g.length>0||!!c,expanded:n,onToggle:o,badge:l,rightAdornment:c?e.jsx(Be,{subscription:c}):null,children:[e.jsx(Xt,{mode:s,rows:g,extra:f}),c?e.jsx(Ge,{subscription:c,now:d,mode:s}):null,n?e.jsx(Vt,{rows:g,mode:s,now:d}):null,n&&c?e.jsx(We,{subscription:c,now:d}):null]},t)}function ue(t,a,r,s,n=null,o=Date.now(),l=k.USED){const c=!!n;return e.jsxs(Ue,{name:ee(t),providerId:t,expandable:c,expanded:r,onToggle:s,rightAdornment:c?e.jsx(Be,{subscription:n}):null,children:[a,c?e.jsx(Ge,{subscription:n,now:o,mode:l}):null,c&&r?e.jsx("div",{className:"mt-1",children:e.jsx(We,{subscription:n,now:o})}):null]},t)}function ta(t,a,r,s,n,o=null,l=Date.now()){if(!xe[t])return null;if(!a?.configured)return ue(t,e.jsxs(e.Fragment,{children:[e.jsx(R,{children:i("limits.status.not_connected")}),t==="opencodeGo"?e.jsx(Ne,{}):null,t==="codingPlan"?e.jsx(_e,{}):null]}),s,n,o,l,r);if(t==="opencodeGo"&&a.subscription_status==="inactive")return ue(t,e.jsx(R,{children:i("limits.opencodeGo.status.inactive")}),s,n,o,l,r);if(a.error)return ue(t,e.jsxs(e.Fragment,{children:[e.jsx(R,{tone:"error",children:i("shared.error.prefix",{error:a.error})}),t==="kiro"?qe(xe.kiro.extra,a):null,t==="opencodeGo"?e.jsx(Ne,{}):null,t==="codingPlan"?e.jsx(_e,{}):null]}),s,n,o,l,r);const c=ee(t),d=a.plan_label?`${c} ${a.plan_label}`:c;let m=null;if(t==="antigravity")if(a.cached){const f=Q(a.cached_at);m=e.jsx(U,{label:i("limits.label.antigravity_cached"),age:f,tone:"cached",tooltip:i("limits.tooltip.antigravity_cached")})}else m=e.jsx(U,{label:i("limits.label.antigravity_live"),tone:"live",tooltip:i("limits.tooltip.antigravity_live")});if((t==="qoder"||t==="qoderCn"||t==="codingPlan")&&a.cached&&(m=e.jsx(U,{label:i("limits.label.antigravity_cached"),age:Q(a.cached_at),tone:"cached",tooltip:i("limits.tooltip.qoder_cached")})),!m&&a.auth_action_required==="reauth"){const f=Yt[t];m=e.jsx(U,{label:i("limits.reauth.badge"),age:Q(a.cached_at),tone:"stale",tooltip:f?i("limits.reauth.tooltip",{command:f}):null})}const g=a.provenance;return g?.stale&&!m&&(m=e.jsx(U,{label:i("limits.provenance.stale"),age:Q(g.captured_at),tone:"stale",tooltip:i("limits.provenance.tooltip",{source:g.source,confidence:g.confidence})})),ea(t,a,d,r,s,n,m,o,l)}function aa({defaultDir:t}){const[a,r]=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),r(!0),setTimeout(()=>r(!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:i("limits.copilot.otelHint.title")}),e.jsx("div",{className:"mt-0.5 leading-snug",children:i("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?i("limits.copilot.otelHint.copied"):i("limits.copilot.otelHint.copy")})]})}function F({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 ze(){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 Ne(){const[t,a]=x.useState(!1),r=["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(r),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:i("limits.opencodeGo.setupHint.title")}),e.jsx("div",{className:"mt-0.5 leading-snug text-oai-gray-500 dark:text-oai-gray-400",children:i("limits.opencodeGo.setupHint.subtitle")}),e.jsxs("ol",{className:"mt-2.5 space-y-2.5",children:[e.jsxs(F,{n:"1",children:[e.jsx("div",{children:i("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:[i("limits.opencodeGo.setupHint.cta"),e.jsx(ze,{})]})]}),e.jsx(F,{n:"2",children:e.jsx("div",{children:i("limits.opencodeGo.setupHint.step2")})}),e.jsxs(F,{n:"3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{children:i("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?i("limits.opencodeGo.setupHint.copied"):i("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:r}),e.jsx("div",{className:"mt-1 text-[10px] text-oai-gray-400 dark:text-oai-gray-500",children:i("limits.opencodeGo.setupHint.note_app")})]})]})]})}function _e(){const[t,a]=x.useState(!1),r=["npm install -g @volcengine/ark-cli","arkcli auth login volc-sso # browser SSO (recommended)","arkcli auth status # verify the session"].join(`
5
- `),s=async n=>{n.stopPropagation();try{await navigator.clipboard.writeText(r),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:i("limits.codingPlan.setupHint.title")}),e.jsx("div",{className:"mt-0.5 leading-snug text-oai-gray-500 dark:text-oai-gray-400",children:i("limits.codingPlan.setupHint.subtitle")}),e.jsxs("ol",{className:"mt-2.5 space-y-2.5",children:[e.jsxs(F,{n:"1",children:[e.jsx("div",{children:i("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:[i("limits.codingPlan.setupHint.cta"),e.jsx(ze,{})]})]}),e.jsxs(F,{n:"2",children:[e.jsx("div",{children:i("limits.codingPlan.setupHint.step2")}),e.jsx("div",{className:"mt-0.5 text-oai-gray-500 dark:text-oai-gray-400",children:i("limits.codingPlan.setupHint.step2_remote")})]}),e.jsxs(F,{n:"3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{children:i("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?i("limits.codingPlan.setupHint.copied"):i("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:r}),e.jsx("div",{className:"mt-1 text-[10px] text-oai-gray-400 dark:text-oai-gray-500",children:i("limits.codingPlan.setupHint.note_app")})]})]})]})}function ra(t){const[a,r]=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);r(d=>d===c?d:c)}),a}function ia({claude:t,codex:a,cursor:r,gemini:s,kimi:n,kiro:o,grok:l,antigravity:c,copilot:d,zcode:m,opencodeGo:g,qoder:f,qoderCn:b,codingPlan:w,order:M,visibility:N,displayMode:j,subscriptions:L=[],showSubscriptions:se=!0}){const W={claude:t,codex:a,cursor:r,gemini:s,kimi:n,kiro:o,grok:l,antigravity:c,copilot:d,zcode:m,opencodeGo:g,qoder:f,qoderCn:b,codingPlan:w},q=x.useRef(null),A=ra(q),[oe,he]=x.useState(null),[_,le]=x.useState(()=>Date.now()),z=Array.isArray(M)&&M.length>0?M:Kt,P=j===k.REMAINING?k.REMAINING:k.USED,V=P===k.REMAINING?i("limits.settings.display_mode_remaining"):i("limits.settings.display_mode_used");x.useEffect(()=>{const h=setInterval(()=>le(Date.now()),6e4);return()=>clearInterval(h)},[]);const E=new Map;if(se)for(const h of L||[]){if(!h?.provider)continue;const C=new Date(h.nextBillingAt).getTime();if(!Number.isFinite(C))continue;const $=E.get(h.provider);if(!$){E.set(h.provider,h);continue}const S=new Date($.nextBillingAt).getTime(),K=C>_,X=S>_;(K&&(!X||S>C)||!K&&!X&&C>S)&&E.set(h.provider,h)}const Y=z.filter(h=>!N||N[h]!==!1||E.has(h)).map(h=>ta(h,W[h],P,oe===h,()=>he(C=>C===h?null:h),E.get(h)||null,_)).filter(Boolean);return e.jsx(ct,{delay:.15,children:e.jsx(Pe,{children:e.jsxs("div",{ref:q,className:"flex flex-col gap-3",style:A>0?{"--tt-limits-label-w":`${A}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:[i("limits.panel.title"),i("limits.panel.mode_separator"),V]}),Y.length>0?Y:e.jsx(R,{children:i("limits.status.all_hidden")})]})})})}async function Ve(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 na(){const t=await fetch("/functions/tokentracker-subscription-manager",{headers:{Accept:"application/json"},cache:"no-store"}),a=await Ve(t);return Array.isArray(a.subscriptions)?a.subscriptions:[]}async function fe(t){const a=await Xe();return Ve(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 sa(t){return fe({action:"create",subscription:t})}function oa(t,a){return fe({action:"update",id:t,subscription:a})}function la(t){return fe({action:"delete",id:t})}const me={plan:"",provider:"",cycle:"monthly",autoRenew:!0,startedAt:""};function ca(t){const a=new Date(t);if(Number.isNaN(a.getTime()))return"";const r=s=>String(s).padStart(2,"0");return`${a.getFullYear()}-${r(a.getMonth()+1)}-${r(a.getDate())}T${r(a.getHours())}:${r(a.getMinutes())}`}function da({subscriptions:t,onChanged:a}){const[r,s]=x.useState(!1),[n,o]=x.useState(null),[l,c]=x.useState(me),[d,m]=x.useState(!1),[g,f]=x.useState(!1),[b,w]=x.useState(!1),[M,N]=x.useState(!1),[j,L]=x.useState(null),[se,W]=x.useState(!1),[q,A]=x.useState(!1),[oe,he]=x.useState(null),[_,le]=x.useState(()=>Date.now()),z=x.useRef(null),P=re(),V=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(!r)return;const u=window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;z.current?.scrollIntoView?.({behavior:u?"auto":"smooth",block:"nearest"})},[r,n]);const E=x.useMemo(()=>Ce.map(u=>{const v=(t||[]).some(y=>y.provider===u&&y.id!==n),p=ee(u);return{value:u,label:v?`${p} ${i("subscriptions.form.provider_taken_suffix")}`:p,disabled:v}}),[P,t,n]),Y=x.useMemo(()=>[{value:"weekly",label:i("subscriptions.form.cycle_weekly")},{value:"monthly",label:i("subscriptions.form.cycle_monthly")},{value:"yearly",label:i("subscriptions.form.cycle_yearly")}],[P]),h=x.useMemo(()=>[{value:"true",label:i("subscriptions.form.auto_renew_on")},{value:"false",label:i("subscriptions.form.auto_renew_off")}],[P]),C=x.useCallback(()=>{c(me),o(null),f(!1),w(!1),N(!1),s(!0)},[]),$=x.useCallback(u=>{c({plan:u.plan||"",provider:u.provider||"",cycle:u.cycle||"monthly",autoRenew:u.autoRenew,startedAt:ca(new Date(Ot(u)).toISOString())}),o(u.id),f(!1),w(!1),N(!1),s(!0)},[]),S=x.useCallback(()=>{s(!1),o(null),c(me),f(!1),w(!1),N(!1)},[]),K=x.useCallback(async u=>{if(u.preventDefault(),f(!1),!l.provider){w(!0);return}if((t||[]).some(O=>O.provider===l.provider&&O.id!==n)){N(!0);return}const p=new Date(l.startedAt).getTime();if(!Number.isFinite(p)){f(!0);return}const y={service:ee(l.provider),plan:l.plan,provider:l.provider||null,autoRenew:l.autoRenew,cycle:l.cycle,startedAt:p,nextBillingAt:Oe(p,l.cycle)};m(!0);try{n?await oa(n,y):await sa(y),S(),await a?.()}catch{f(!0)}finally{m(!1)}},[S,n,l,a,t]),X=x.useCallback(async()=>{if(j){W(!0),A(!1);try{await la(j.id),j.id===n&&S(),L(null),await a?.()}catch{A(!0)}finally{W(!1)}}},[S,n,a,j]),J=t||[],be=()=>{const u=n?J.find(p=>p.id===n):null,v=u?te(u,_):null;return e.jsxs("form",{ref:z,onSubmit:K,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?i("subscriptions.edit"):i("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?i("subscriptions.label.renews_at"):i("subscriptions.label.expires_at")})," ",e.jsx("span",{className:"font-mono tabular-nums",children:V.format(new Date(v.endMs))})," · ",e.jsx("span",{className:v.expired?"text-oai-error":void 0,children:ge(v.endMs,_)})]}):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:i("subscriptions.form.provider")}),e.jsx(ce,{id:"subscription-provider",value:l.provider,onValueChange:p=>c({...l,provider:String(p)}),options:E,matchTriggerWidth:!0,className:"h-10 w-full px-3 text-sm"})]}),e.jsx("div",{className:"sm:col-span-1",children:e.jsx(ke,{label:i("subscriptions.form.plan"),value:l.plan,maxLength:120,placeholder:i("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:i("subscriptions.form.cycle")}),e.jsx(ce,{id:"subscription-cycle",value:l.cycle,onValueChange:p=>c({...l,cycle:String(p)}),options:Y,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:i("subscriptions.form.auto_renew")}),e.jsx(ce,{id:"subscription-auto-renew",value:String(l.autoRenew),onValueChange:p=>c({...l,autoRenew:p==="true"}),options:h,matchTriggerWidth:!0,className:"h-10 w-full px-3 text-sm"})]}),e.jsx("div",{className:"sm:col-span-2",children:e.jsx(ke,{label:i("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(H,{type:"button",variant:"secondary",size:"sm",onClick:()=>{const p=J.find(y=>y.id===n);p&&L(p)},className:"!text-red-600 dark:!text-red-400 mr-auto",children:i("subscriptions.delete")}):null,b?e.jsx("p",{className:"mr-auto text-sm text-oai-error",role:"alert",children:i("subscriptions.form.provider_required")}):null,M?e.jsx("p",{className:"mr-auto text-sm text-oai-error",role:"alert",children:i("subscriptions.form.provider_taken")}):null,g?e.jsx("p",{className:"mr-auto text-sm text-oai-error",role:"alert",children:i("subscriptions.form.error")}):null,e.jsx(H,{type:"button",variant:"secondary",size:"sm",onClick:S,children:i("shared.action.cancel")}),e.jsx(H,{type:"submit",size:"sm",disabled:d,children:i("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:i("limits.page.openSubscriptions")})}),e.jsxs(H,{type:"button",size:"sm",onClick:C,className:"shrink-0 gap-1.5",children:[e.jsx(xt,{size:14,strokeWidth:2,"aria-hidden":!0}),e.jsx("span",{children:i("subscriptions.add")})]})]}),J.length===0&&!(r&&!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(Te,{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:i("subscriptions.empty.title")}),e.jsx("p",{className:"text-xs text-oai-gray-500 dark:text-oai-gray-400",children:i("subscriptions.empty.body")})]}):e.jsxs("ul",{className:"flex flex-col gap-1.5",children:[J.map(u=>{const v=te(u,_);if(!v)return null;const{endMs:p,expired:y}=v,O=y?100:v.progress*100,Ye=!y&&p-_<=3*864e5,Ke=oe===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":`${i("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(Ee,{provider:De(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?i("subscriptions.badge.auto_renew"):i("subscriptions.badge.stops"),title:u.autoRenew?i("subscriptions.badge.auto_renew"):i("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(Re,{size:14,strokeWidth:2,"aria-hidden":!0}):e.jsx(Ie,{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:i("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":Ye?"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:Fe(p,_)})]})]}),n===u.id?e.jsx("div",{className:"border-t border-oai-gray-100 dark:border-oai-gray-800",children:be()}):null,n!==u.id&&Ke?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?i("subscriptions.label.renews_at"):i("subscriptions.label.expires_at")})," ",e.jsx("span",{className:"font-mono tabular-nums",children:V.format(new Date(p))})," · ",e.jsx("span",{className:y?"text-oai-error":void 0,children:ge(p,_)})," · ",e.jsx("span",{children:u.autoRenew?i("subscriptions.status.auto_renew"):i("subscriptions.status.manual")})]}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(H,{type:"button",variant:"secondary",size:"sm",onClick:()=>$(u),children:i("subscriptions.edit")})})]}):null]},u.id)}),r&&!n?e.jsx("li",{className:"rounded-lg border border-oai-gray-100 dark:border-oai-gray-800",children:be()}):null]}),e.jsx(ut,{open:!!j,title:i("subscriptions.confirm_delete_title"),description:j?.service||"",error:q?i("subscriptions.delete_error"):null,confirmLabel:i("subscriptions.delete"),cancelLabel:i("shared.action.cancel"),destructive:!0,busy:se,onCancel:()=>{L(null),A(!1)},onConfirm:X})]})}const Me=typeof window<"u"&&(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1"),ua="x-apple.systempreferences:com.apple.preference.notifications";function ma(){const t=yt(),a=tt(),r=i("limits.alert.blocked"),s=a?ve.button:ve.div;return e.jsxs(s,{type:a?"button":void 0,onClick:a?()=>at({type:"action",name:"openURL",value:ua}):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:r,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:r}),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 La(){const t=Je(),{data:a,error:r,isLoading:s}=nt(t?{initialRefresh:!0,initialState:t,publishToPreloadCache:!0}:{initialRefresh:!0,publishToPreloadCache:!0}),n=lt(),o=st(),[l,c]=D.useState([]),[d,m]=D.useState(!1),[g,f]=D.useState(!1),[b]=Qe(),w=D.useRef(0),M=D.useCallback(async()=>{if(!Me&&!ye())return;const N=++w.current;try{const j=await na();if(N!==w.current)return;c(j),m(!1)}catch{if(N!==w.current)return;m(!0)}},[]);return D.useEffect(()=>{M()},[M]),D.useEffect(()=>{b.get("openSubscriptions")==="1"&&f(!0)},[b]),D.useEffect(()=>{o.enabled&&a&&ot(a)},[o.enabled,a]),!Me&&!ye()?e.jsx("div",{className:"flex flex-col flex-1 text-oai-black dark:text-oai-white font-oai antialiased",children:e.jsx(mt,{})}):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:i("nav.limits")}),e.jsx("p",{className:"text-oai-gray-500 dark:text-oai-gray-400 text-sm sm:text-base",children:i("limits.page.subtitle")})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[o.enabled&&o.permissionBlocked?e.jsx(ma,{}):null,e.jsxs(pt,{open:g,onOpenChange:f,children:[e.jsx(gt,{"aria-label":i("limits.page.openSubscriptions"),title:i("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(Te,{className:"h-4 w-4","aria-hidden":!0})}),e.jsx(ft,{children:e.jsx(ht,{side:"bottom",align:"end",sideOffset:8,className:"z-50",children:e.jsx(bt,{children:e.jsx(da,{subscriptions:l,onChanged:M})})})})]}),e.jsx("button",{type:"button",onClick:()=>{o.setEnabled(!o.enabled)},"aria-label":o.enabled?i("limits.alert.disable"):i("limits.alert.enable"),title:o.enabled?i("limits.alert.disable"):i("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(wt,{className:"h-4 w-4","aria-hidden":!0}):e.jsx(kt,{className:"h-4 w-4","aria-hidden":!0})}),e.jsx(Ze,{to:"/settings?section=limits","aria-label":i("limits.page.openSettings"),title:i("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(et,{className:"h-4 w-4","aria-hidden":!0})})]})]}),s?e.jsx(Dt,{}):e.jsxs(e.Fragment,{children:[r?e.jsx("p",{className:"mb-4 text-sm text-red-500 dark:text-red-400",children:i("shared.error.prefix",{error:r})}):null,d?e.jsx("p",{className:"mb-4 text-sm text-amber-600 dark:text-amber-400",children:i("subscriptions.load_error")}):null,e.jsx(ia,{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,qoder:a?.qoder,qoderCn:a?.qoderCn,codingPlan:a?.codingPlan,order:n.order,visibility:n.visibility,displayMode:n.displayMode,subscriptions:l,showSubscriptions:n.showSubscriptions!==!1})]})]})})})}export{La as LimitsPage};
@@ -1,2 +0,0 @@
1
- import{m as Y,r as i,j as e,e as P,c as a,M as ce,J as W,R as de,X as ue,d as ee,l as m,a4 as xe,a5 as U}from"./__vite-browser-external-DPOlUkcY.js";import{L as me,I as he}from"./LocalOnlyNotice-Bj_m0hw7.js";import{S as Z}from"./SegmentedControl-DLzS-2eZ.js";import{C as ge}from"./ToolbarRootContext-XUDMp5uy.js";import{S as te}from"./search-D_LLDRdU.js";import{C as pe}from"./check-Cy35lAKh.js";import{P as fe,a as be,b as ye,c as ke,d as _e}from"./PopoverPopup-DK3et-HG.js";import{P as ve}from"./ProviderIcon-By8FAjxR.js";import{H as je}from"./HoverTooltip-DBOpxlH7.js";import{u as we}from"./useCurrency-CnM8aB4v.js";import{i as Ne}from"./host-mode-Bc_iTzHk.js";import{L as Ce}from"./loader-circle-lrDmbIg5.js";import{T as Se}from"./terminal-CR228ekj.js";import"./arrow-up-right-DSsR3Ntr.js";import"./download-DdGW6Krz.js";import"./composite-BDwOlhhX.js";import"./store-8e16Ac2h.js";const Me=[["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"}]],Le=Y("calendar",Me);const Te=[["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"}]],Re=Y("folder",Te),De="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 Ie({options:s,value:t,onChange:o,allValue:x="all",allLabel:g,searchPlaceholder:k,emptyLabel:u,ariaLabel:w,disabled:p=!1,className:_=""}){const[b,f]=i.useState(!1),[y,R]=i.useState(""),[h,v]=i.useState(-1),N=i.useRef(null),C=`${i.useId()}-listbox`,A=t===x?g:s.find(l=>l.value===t)?.label??t,S=y.trim().toLowerCase(),D=i.useMemo(()=>S?s.filter(l=>l.label.toLowerCase().includes(S)):s,[s,S]),I=i.useMemo(()=>[{value:x,label:g},...D],[x,g,D]),M=h>=0&&h<I.length?I[h]:null,E=l=>{o(l),f(!1),R(""),v(-1)};i.useEffect(()=>{b&&N.current?.querySelector('[data-active="true"]')?.scrollIntoView?.({block:"nearest"})},[b,h]);const L=l=>{if(l.key==="ArrowDown"||l.key==="ArrowUp"){l.preventDefault();const j=l.key==="ArrowDown";v(F=>{const T=I.length;return T?j?F>=T-1?0:F+1:F<=0?T-1:F-1:-1});return}if(l.key==="Enter"){const j=M||(S&&D.length?D[0]:null);if(!j)return;l.preventDefault(),E(j.value)}};return e.jsxs(fe,{open:b,onOpenChange:l=>{f(l),v(-1),l||R("")},children:[e.jsxs(be,{disabled:p,"aria-label":w,className:P("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!==x?"text-oai-black dark:text-white":"text-oai-gray-700 dark:text-oai-gray-200",_),children:[e.jsx(Re,{className:"h-3.5 w-3.5 shrink-0 text-oai-gray-400","aria-hidden":!0}),e.jsx("span",{className:"truncate",children:A}),e.jsx(ge,{className:"h-3.5 w-3.5 shrink-0 text-oai-gray-400","aria-hidden":!0})]}),e.jsx(ye,{children:e.jsx(ke,{sideOffset:4,side:"bottom",align:"start",className:"z-[60]",children:e.jsxs(_e,{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(te,{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":M?`${C}-${h}`:void 0,value:y,onChange:l=>{R(l.target.value),v(-1)},onKeyDown:L,placeholder:k,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:N,id:C,role:"listbox","aria-label":w,className:"max-h-64 overflow-y-auto",children:[I.map((l,j)=>e.jsxs("button",{id:`${C}-${j}`,type:"button",role:"option","aria-selected":t===l.value,"data-active":j===h?"true":void 0,onMouseEnter:()=>v(j),onClick:()=>E(l.value),className:P(De,t===l.value&&"bg-oai-gray-100 dark:bg-oai-gray-800",j===h&&"ring-1 ring-inset ring-oai-gray-300 dark:ring-oai-gray-600"),children:[e.jsx("span",{className:"flex-1 truncate",children:l.label}),t===l.value?e.jsx(pe,{className:"h-3.5 w-3.5 shrink-0","aria-hidden":!0}):null]},l.value)),D.length===0?e.jsx("div",{className:"px-2 py-3 text-center text-xs text-oai-gray-400 dark:text-oai-gray-500",children:u}):null]})]})})})]})}const Ee="tokentracker-sessions";async function Pe(s={}){const t=new URL(`/functions/${Ee}`,window.location.origin);s.from&&t.searchParams.set("from",s.from),s.to&&t.searchParams.set("to",s.to),s.limit&&t.searchParams.set("limit",String(s.limit)),s.refresh&&t.searchParams.set("refresh","1");const o=await fetch(t.toString(),{headers:{Accept:"application/json"},cache:"no-store"}),x=await o.json().catch(()=>null);if(!o.ok){const g=o.status===404?a("sessions.error.outdated_app"):`Request failed with HTTP ${o.status}`,k=new Error(x?.error||g);throw k.status=o.status,k}return x}const J=Ne(),Fe=[],G=100,$e=[{id:"all",label:()=>a("sessions.filter.source_all")},{id:"claude",label:()=>"Claude Code"},{id:"codex",label:()=>"Codex"},{id:"grok",label:()=>"Grok"}],ae=[{id:"all",days:0,label:()=>a("sessions.filter.range_all")},{id:"7d",days:7,label:()=>a("sessions.filter.range_7d")},{id:"30d",days:30,label:()=>a("sessions.filter.range_30d")},{id:"90d",days:90,label:()=>a("sessions.filter.range_90d")}];function Oe(s){const t=ae.find(x=>x.id===s)?.days||0;if(!t)return 0;const o=new Date;return o.setDate(o.getDate()-(t-1)),o.setHours(0,0,0,0),o.getTime()}function Ae(s,t){if(!t)return!0;const o=Date.parse(s.ended_at||s.started_at||"");return Number.isFinite(o)?o>=t:!0}function qe(s,t){if(!s)return"—";const o=Date.parse(s);if(!Number.isFinite(o))return"—";try{return new Date(o).toLocaleString(t||void 0,{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}catch{return new Date(o).toISOString().slice(0,16).replace("T"," ")}}function Ue(s){const t=Number(s);if(!Number.isFinite(t)||t<=0)return null;const o=Math.round(t/6e4);if(o<60)return a("sessions.duration.minutes",{minutes:o});const x=Math.floor(o/60),g=o%60;return a("sessions.duration.hours",{hours:x,minutes:g})}async function V(s){if(navigator?.clipboard?.writeText)return await navigator.clipboard.writeText(s),!0;const t=document.createElement("textarea");t.value=s,t.style.position="fixed",t.style.opacity="0",document.body.appendChild(t),t.select();const o=document.execCommand("copy");return document.body.removeChild(t),o}const X=ee.memo(function({session:t,locale:o,nested:x=!1,childCount:g=0,expanded:k=!1,onToggle:u}){const{currency:w,rate:p}=we(),_=String(t.source||"").toUpperCase(),b=Ue(t.duration_ms),f=t.resume_command,y=t.project_key||a("sessions.project.unknown"),R=x||t.thread_kind==="subagent",h=R?t.agent_nickname||t.agent_role||t.title||y:t.title||y,v=!!(t.title&&t.project_key),N=String(t.source||"").toLowerCase()==="grok",C=N&&t.usage_precision?a("sessions.grok.token_breakdown",{input:m(t.input_tokens),cacheRead:m(t.cached_input_tokens),cacheWrite:m(t.cache_creation_input_tokens),output:m(t.output_tokens),reasoning:m(t.reasoning_output_tokens)}):null,A=N&&t.usage_precision?a("sessions.grok.runtime_breakdown",{calls:m(t.model_calls),seconds:(Number(t.api_duration_ms||0)/1e3).toFixed(1),tools:m(t.tool_calls),errors:m(t.error_count)}):null,S=N&&Number(t.context_window_tokens)>0?a("sessions.grok.context_breakdown",{used:m(t.context_tokens_used),window:m(t.context_window_tokens),percent:Number(t.context_usage_percent||0).toFixed(0)}):null,D=t.project_ref?`${t.project_ref}
2
- ${a("sessions.project.copy_hint")}`:void 0,I=async()=>{if(t.project_ref)try{await V(t.project_ref)?U({title:a("sessions.project.copied")}):U({title:a("sessions.project.copy_failed")})}catch{U({title:a("sessions.project.copy_failed")})}},M=L=>e.jsxs("span",{className:"group relative inline-flex min-w-0 max-w-full",children:[e.jsx(je,{text:D,placement:"bottom"}),e.jsx("button",{type:"button",onClick:I,"aria-label":a("sessions.project.copy_aria",{project:y}),className:P("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",L),children:y})]}),E=async()=>{if(f)try{await V(f)?U({title:a("sessions.resume.copied")}):U({title:a("sessions.resume.copy_failed")})}catch{U({title:a("sessions.resume.copy_failed")})}};return e.jsxs("li",{className:P("flex flex-col gap-3 py-4 sm:flex-row sm:items-start",x&&"ml-6 border-l-2 border-oai-gray-200 pl-4 dark:border-oai-gray-800"),children:[e.jsxs("div",{className:"flex min-w-0 flex-1 items-start gap-2.5",children:[e.jsx("span",{className:"mt-0.5 shrink-0 text-oai-gray-400 dark:text-oai-gray-500",children:e.jsx(ve,{provider:_,size:20})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[!R&&!t.title&&t.project_ref?M("font-medium text-oai-black dark:text-white"):e.jsx("span",{className:"truncate font-medium text-oai-black dark:text-white",children:h}),R?e.jsxs("span",{className:"inline-flex items-center rounded-full bg-sky-50 px-2 py-0.5 text-[11px] font-medium text-sky-700 dark:bg-sky-500/10 dark:text-sky-300",children:[a("sessions.badge.subagent"),t.agent_role?` · ${t.agent_role}`:""]}):null,t.first_pass?e.jsx("span",{className:"inline-flex items-center rounded-full bg-emerald-50 px-2 py-0.5 text-[11px] font-medium text-emerald-700 dark:bg-emerald-500/10 dark:text-emerald-300",children:a("sessions.badge.first_pass")}):null,N&&t.usage_precision?e.jsx("span",{className:P("inline-flex items-center rounded-full px-2 py-0.5 text-[11px] font-medium",t.usage_is_incomplete||t.cost_is_partial?"bg-amber-50 text-amber-700 dark:bg-amber-500/10 dark:text-amber-300":"bg-sky-50 text-sky-700 dark:bg-sky-500/10 dark:text-sky-300"),children:t.usage_is_incomplete||t.cost_is_partial?a("sessions.badge.partial_usage"):t.cost_source==="provider_reported"?a("sessions.badge.reported_cost"):a("sessions.badge.reported_usage")}):null,g?e.jsx("button",{type:"button",onClick:u,"aria-expanded":k,className:"inline-flex items-center rounded-full border border-oai-gray-200 px-2 py-0.5 text-[11px] 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-700 dark:text-oai-gray-300 dark:hover:bg-oai-gray-800 dark:hover:text-white",children:k?a("sessions.thread.collapse",{count:g}):a("sessions.thread.expand",{count:g})}):null]}),e.jsxs("div",{className:"mt-0.5 flex flex-wrap items-center gap-x-2 gap-y-0.5 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:[v?e.jsxs(e.Fragment,{children:[t.project_ref?M("hover:text-oai-black dark:hover:text-white"):e.jsx("span",{className:"truncate",children:y}),e.jsx("span",{"aria-hidden":!0,children:"·"})]}):null,e.jsx("span",{className:"truncate",children:t.model||a("sessions.model.unknown")}),e.jsx("span",{"aria-hidden":!0,children:"·"}),e.jsx("span",{className:"tabular-nums",children:qe(t.started_at,o)}),b?e.jsxs(e.Fragment,{children:[e.jsx("span",{"aria-hidden":!0,children:"·"}),e.jsx("span",{className:"tabular-nums",children:b})]}):null]}),C?e.jsx("div",{className:"mt-1 text-[11px] tabular-nums text-oai-gray-500 dark:text-oai-gray-400",children:C}):null,A?e.jsxs("div",{className:"mt-0.5 flex flex-wrap items-center gap-x-2 text-[11px] tabular-nums text-oai-gray-400 dark:text-oai-gray-500",children:[e.jsx("span",{children:A}),S?e.jsxs(e.Fragment,{children:[e.jsx("span",{"aria-hidden":!0,children:"·"}),e.jsx("span",{children:S})]}):null]}):null]})]}),e.jsxs("div",{className:"flex items-start gap-5 pl-[30px] sm:pl-0",children:[e.jsxs("dl",{className:"flex items-start gap-6 text-right",children:[e.jsxs("div",{className:"flex w-16 flex-col-reverse",children:[e.jsx("dt",{className:"text-[11px] text-oai-gray-400 dark:text-oai-gray-500",children:a("sessions.col.tokens")}),e.jsxs("dd",{title:Number(t.subagent_total_tokens)?a("sessions.thread.tokens_summary",{own:m(t.own_total_tokens),subagents:m(t.subagent_total_tokens),combined:m(t.combined_total_tokens)}):void 0,className:"tabular-nums text-sm font-medium text-oai-black dark:text-white",children:[m(t.total_tokens),Number(t.subagent_total_tokens)?e.jsxs("span",{className:"block text-[9px] font-normal text-oai-gray-400 dark:text-oai-gray-500",children:["Σ ",m(t.combined_total_tokens)]}):null]})]}),e.jsxs("div",{className:"flex w-16 flex-col-reverse",children:[e.jsx("dt",{className:"text-[11px] text-oai-gray-400 dark:text-oai-gray-500",children:a("sessions.col.cost")}),e.jsx("dd",{className:"tabular-nums text-sm font-medium text-oai-black dark:text-white",children:xe(t.cost_usd,{currency:w,rate:p})})]}),e.jsxs("div",{className:"hidden w-10 flex-col-reverse sm:flex",children:[e.jsx("dt",{className:"text-[11px] text-oai-gray-400 dark:text-oai-gray-500",children:a("sessions.col.turns")}),e.jsx("dd",{className:"tabular-nums text-sm font-medium text-oai-black dark:text-white",children:m(t.turns)})]}),e.jsxs("div",{className:"hidden w-10 flex-col-reverse sm:flex",children:[e.jsx("dt",{className:"text-[11px] text-oai-gray-400 dark:text-oai-gray-500",children:a("sessions.col.edits")}),e.jsx("dd",{className:"tabular-nums text-sm font-medium text-oai-black dark:text-white",children:m(t.edit_turns)})]})]}),e.jsxs("button",{type:"button",onClick:E,disabled:!f,title:f||a("sessions.resume.unavailable"),"aria-label":f?a("sessions.resume.copy_aria",{command:f}):a("sessions.resume.unavailable"),className:P("-mt-0.5 inline-flex h-8 shrink-0 items-center gap-1.5 rounded-md px-2.5 text-xs font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand-500",f?"text-oai-gray-500 hover:bg-oai-gray-100 hover:text-oai-black dark:text-oai-gray-400 dark:hover:bg-oai-gray-800 dark:hover:text-white":"cursor-not-allowed text-oai-gray-300 dark:text-oai-gray-600"),children:[e.jsx(Se,{className:"h-3.5 w-3.5","aria-hidden":!0}),e.jsx("span",{className:"hidden sm:inline",children:a("sessions.resume.copy")})]})]})]})});function Be({sessions:s,selectedModel:t,onSelect:o}){const{groups:x,totalTokens:g}=i.useMemo(()=>{const u=new Map;let w=0;for(const p of s){const _=p.model||a("sessions.model.unknown"),b=Number(p.own_total_tokens||p.total_tokens||0),f=u.get(_)||{model:_,count:0,tokens:0};f.count+=1,f.tokens+=b,w+=b,u.set(_,f)}return{groups:[...u.values()].sort((p,_)=>_.tokens-p.tokens),totalTokens:w}},[s]);function k(u){return P("rounded-full border px-2.5 py-1 text-xs tabular-nums transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand-500",u?"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:"ml-6 border-l-2 border-oai-gray-200 py-3 pl-4 dark:border-oai-gray-800",children:e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"mr-1 text-xs font-medium text-oai-gray-500 dark:text-oai-gray-400",children:a("sessions.thread.model_usage")}),e.jsx("button",{type:"button","aria-pressed":t==="all",onClick:()=>o("all"),className:k(t==="all"),children:a("sessions.thread.model_all",{count:s.length,tokens:m(g)})}),x.map(u=>e.jsx("button",{type:"button","aria-pressed":t===u.model,onClick:()=>o(u.model),className:k(t===u.model),children:a("sessions.thread.model_item",{model:u.model,count:u.count,tokens:m(u.tokens)})},u.model))]})})}function nt(){const[s,t]=i.useState(null),[o,x]=i.useState(null),[g,k]=i.useState(!0),[u,w]=i.useState(!1),[p,_]=i.useState("all"),[b,f]=i.useState("all"),[y,R]=i.useState("all"),[h,v]=i.useState(""),[N,C]=i.useState(G),[A,S]=i.useState(()=>new Set),[D,I]=i.useState(()=>new Map),M=i.useRef(0),{resolvedLocale:E}=ce(),L=i.useCallback(async(r=!1)=>{const c=++M.current;r?w(!0):k(!0),x(null);try{const n=await Pe({refresh:r});c===M.current&&t(n)}catch(n){c===M.current&&x(n?.message||String(n))}finally{c===M.current&&(k(!1),w(!1))}},[]);i.useEffect(()=>{J||W()?L(!1):k(!1)},[L]);const l=s?.sessions||Fe,j=i.useMemo(()=>{const r=new Set,c=[];for(const n of l){const d=n.project_key;!d||r.has(d)||(r.add(d),c.push({value:d,label:d}))}return c.sort((n,d)=>n.label.localeCompare(d.label))},[l]),F=i.useDeferredValue(h),T=i.useMemo(()=>{const r=F.trim().toLowerCase(),c=Oe(b);return l.filter(n=>p!=="all"&&n.source!==p||y!=="all"&&n.project_key!==y||!Ae(n,c)?!1:r?`${n.title||""} ${n.project_key||""} ${n.model||""} ${n.agent_nickname||""} ${n.agent_role||""} ${n.project_ref||""} ${n.session_id||""}`.toLowerCase().includes(r):!0)},[l,p,y,b,F]),O=i.useMemo(()=>{const r=new Set(T.map(d=>d.session_hash)),c=new Map,n=[];for(const d of T){const q=d.root_session_hash||d.parent_session_hash;if(d.parent_session_hash&&q&&r.has(q)){const $=c.get(q)||[];$.push(d),c.set(q,$)}else n.push(d)}return{roots:n,childrenByRoot:c,foldedCount:T.length-n.length}},[T]),Q=p!=="all"||b!=="all"||y!=="all"||h.trim()!=="";i.useEffect(()=>{C(G),S(new Set),I(new Map)},[p,y,b,F,l]);const K=i.useMemo(()=>O.roots.slice(0,N),[O.roots,N]),B=O.roots.length>K.length,H=i.useCallback(()=>C(r=>r+G),[]),re=i.useCallback(r=>{S(c=>{const n=new Set(c);return n.has(r)?n.delete(r):n.add(r),n})},[]),se=i.useCallback((r,c)=>{I(n=>{const d=new Map(n);return c==="all"?d.delete(r):d.set(r,c),d})},[]),z=i.useRef(null);i.useEffect(()=>{if(!B||typeof IntersectionObserver>"u")return;const r=z.current;if(!r)return;const c=new IntersectionObserver(n=>{n.some(d=>d.isIntersecting)&&H()},{rootMargin:"400px"});return c.observe(r),()=>c.disconnect()},[B,H]);const oe=i.useMemo(()=>$e.map(r=>({id:r.id,label:r.label()})),[E]),ne=i.useMemo(()=>ae.map(r=>({id:r.id,label:r.label()})),[E]),ie=Number(s?.session_count)>Number(s?.returned_count);return!J&&!W()?e.jsx("div",{className:"flex flex-col flex-1 text-oai-black dark:text-oai-white font-oai antialiased",children:e.jsx(me,{})}):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:"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:a("nav.sessions")}),e.jsx("p",{className:"text-sm text-oai-gray-500 dark:text-oai-gray-400 sm:text-base",children:a("sessions.page.subtitle")})]}),e.jsx("button",{type:"button",onClick:()=>{L(!0)},disabled:u||g,"aria-label":a("sessions.page.refresh"),title:a("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(de,{className:P("h-4 w-4",u&&"animate-spin"),"aria-hidden":!0})})]}),e.jsxs("div",{className:"mb-2 flex flex-wrap items-center gap-2 pt-1 text-xs text-oai-gray-600 dark:text-oai-gray-300",children:[e.jsx(Z,{ariaLabel:a("sessions.filter.source_aria"),options:oe,value:p,onChange:_}),e.jsx(Z,{className:"pl-2",ariaLabel:a("sessions.filter.range_aria"),leading:e.jsx(Le,{className:"h-3.5 w-3.5 shrink-0 text-oai-gray-400","aria-hidden":!0}),options:ne,value:b,onChange:f}),e.jsx(Ie,{options:j,value:y,onChange:R,allLabel:a("sessions.filter.project_all"),searchPlaceholder:a("sessions.filter.project_search"),emptyLabel:a("sessions.filter.project_empty"),ariaLabel:a("sessions.filter.project_aria")}),e.jsxs("div",{className:"relative w-72 max-w-full",children:[e.jsx(te,{className:"pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-oai-gray-400","aria-hidden":!0}),e.jsx(he,{type:"search",value:h,onChange:r=>v(r.target.value),onKeyDown:r=>{r.key==="Escape"&&h&&(r.preventDefault(),v(""))},"aria-label":a("sessions.action.search_aria"),placeholder:a("sessions.search.placeholder"),className:"h-8 pl-9 pr-8 !border-oai-gray-200 dark:!border-oai-gray-800 focus:!border-oai-gray-400 focus:!ring-oai-gray-400/20 dark:focus:!border-oai-gray-500 dark:focus:!ring-oai-gray-500/20 [&::-webkit-search-cancel-button]:appearance-none"}),e.jsx("button",{type:"button",onMouseDown:r=>r.preventDefault(),onClick:()=>v(""),"aria-label":a("sessions.action.search_clear"),"aria-hidden":!h,tabIndex:h?0:-1,className:P("absolute right-2 top-1/2 flex h-6 w-6 -translate-y-1/2 items-center justify-center rounded-full text-oai-gray-400 transition duration-150 ease-out hover:bg-oai-gray-100 hover:text-oai-gray-600 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-gray-400/40 dark:hover:bg-oai-gray-800 dark:hover:text-oai-gray-200",h?"scale-100 opacity-100":"pointer-events-none scale-90 opacity-0"),children:e.jsx(ue,{className:"h-3.5 w-3.5","aria-hidden":!0})})]}),e.jsx("span",{className:"ml-auto shrink-0 tabular-nums text-oai-gray-500 dark:text-oai-gray-400",children:O.foldedCount>0?a("sessions.thread.result_count",{roots:O.roots.length,subagents:O.foldedCount}):a("sessions.filter.result_count",{filtered:T.length,total:l.length})})]}),ie?e.jsx("p",{className:"mb-4 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:a("sessions.truncated",{shown:s.returned_count,total:s.session_count})}):null,o&&!s?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:a("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:()=>{L(!1)},className:"mt-4 inline-flex h-8 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:a("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(Ce,{className:"h-4 w-4 animate-spin","aria-hidden":!0}),a("sessions.loading")]}):T.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:Q?a("sessions.empty.filtered_title"):a("sessions.empty.title")}),e.jsx("p",{className:"mt-1 text-sm text-oai-gray-500 dark:text-oai-gray-400",children:Q?a("sessions.empty.filtered_body"):a("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:a("shared.error.prefix",{error:o})}):null,e.jsx("ul",{className:"divide-y divide-oai-gray-200/70 dark:divide-oai-gray-800/70",children:K.map(r=>{const c=O.childrenByRoot.get(r.session_hash)||[],n=A.has(r.session_hash),d=D.get(r.session_hash)||"all",q=d==="all"?c:c.filter(function(le){return(le.model||a("sessions.model.unknown"))===d});return e.jsxs(ee.Fragment,{children:[e.jsx(X,{session:r,locale:E,childCount:c.length,expanded:n,onToggle:()=>re(r.session_hash)}),n&&c.length?e.jsx(Be,{sessions:c,selectedModel:d,onSelect:$=>se(r.session_hash,$)}):null,n?q.map($=>e.jsx(X,{session:$,locale:E,nested:!0},$.session_hash)):null]},r.session_hash)})}),B?e.jsx("div",{ref:z,className:"flex justify-center pt-6",children:e.jsx("button",{type:"button",onClick:H,className:"inline-flex h-8 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:a("sessions.action.load_more")})}):null]}),e.jsx("p",{className:"mt-6 text-xs text-oai-gray-400 dark:text-oai-gray-500",children:a("sessions.privacy")})]})})})}export{nt as SessionsPage};
@@ -1,2 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/__vite-browser-external-DPOlUkcY.js","assets/__vite-browser-external-CCMdjCX2.css"])))=>i.map(i=>d[i]);
2
- import{m as O,j as t,e as L,c as n,a as ce,r as g,ao as ue,aU as de,au as ge,av as pe,a8 as W,aV as he,aW as me,u as be,d as R,a0 as fe,M as Z,n as M,aX as xe,aY as ye,U as Y,aZ as ve,x as ke,a_ as je,a$ as Se,b0 as we,b1 as Ne,b2 as Ce,b3 as Ee,b4 as Ae,L as Le,R as Oe,b5 as Pe,b6 as _e,a5 as H,_ as Te,h as Ie,f as Ge,b7 as Re,b8 as Ue,ax as De}from"./__vite-browser-external-DPOlUkcY.js";import{a as Me,b as F,s as He,K as Fe,P as $e,D as Be,c as Ve,S as Ke,v as ze,u as qe,C as We}from"./sortable.esm-zlY09tye.js";import{a as Ze}from"./modifiers.esm-CPTpZdHU.js";import{u as Ye,L as $}from"./use-limits-display-prefs-DJIImtLN.js";import{P as Je}from"./ProviderIcon-By8FAjxR.js";import{a as B,l as V}from"./limits-providers-DxZOjiXQ.js";import{m as J}from"./react-DKXriBSF.js";import{a as A,T as j,b,S as _,u as T}from"./Controls-BVrLC_QD.js";import{P as Xe,u as Qe,a as et}from"./use-session-efficiency-pref-C-l4b1cD.js";import{C as tt}from"./check-Cy35lAKh.js";import{C as nt}from"./copy-4szu5cYh.js";import{A as X}from"./index-DI-W-pun.js";import{u as at}from"./useCurrency-CnM8aB4v.js";import{u as st}from"./useTokenFormat-D4pAK2ld.js";import{S as U}from"./Select-C05W6XEM.js";import{I as it}from"./info-BzFpLbl6.js";import{C as ot}from"./ConfirmModal-DsCd51b2.js";import{A as rt}from"./arrow-up-right-DSsR3Ntr.js";import{D as lt}from"./download-DdGW6Krz.js";import{i as ct}from"./host-mode-Bc_iTzHk.js";import"./Card-SUbC3VNS.js";import"./ToolbarRootContext-XUDMp5uy.js";import"./composite-BDwOlhhX.js";import"./SelectItemText-CcfB3blP.js";import"./DialogTitle-C4ia00lc.js";import"./store-8e16Ac2h.js";import"./DialogDescription-BVlaoajd.js";const ut=[["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"}]],dt=O("flask-conical",ut);const gt=[["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"}]],pt=O("grip-vertical",gt);const ht=[["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"}]],mt=O("languages",ht);const bt=[["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"}]],ft=O("log-out",bt);const xt=[["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"}]],yt=O("palette",xt);const vt=[["circle",{cx:"12",cy:"8",r:"5",key:"1hypcn"}],["path",{d:"M20 21a8 8 0 0 0-16 0",key:"rfgkzh"}]],kt=O("user-round",vt),jt="shrink-0 text-oai-gray-900 dark:text-oai-gray-200";function St({checked:e,onChange:a,ariaLabel:s}){return t.jsx("button",{type:"button",role:"switch","aria-checked":e,"aria-label":s,onClick:a,className:L("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",e?"bg-oai-brand-500":"bg-oai-gray-300 dark:bg-oai-gray-700"),children:t.jsx("span",{className:L("inline-block h-3.5 w-3.5 rounded-full bg-white transition-transform",e?"translate-x-[18px]":"translate-x-[3px]")})})}function wt({id:e,visible:a,onToggle:s}){const{attributes:i,listeners:o,setNodeRef:r,transform:l,transition:c,isDragging:u}=qe({id:e}),p={transform:We.Transform.toString(l)||void 0,transition:c,zIndex:u?20:void 0};return t.jsxs("div",{ref:r,style:p,className:L("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",u&&"relative bg-oai-gray-100 dark:bg-oai-gray-800"),...i,...o,children:[t.jsx(pt,{className:"h-4 w-4 shrink-0 text-oai-gray-400 dark:text-oai-gray-500",strokeWidth:1.75,"aria-hidden":!0}),B(e)?t.jsx(Je,{provider:B(e),size:18,className:L("pointer-events-none",jt)}):null,t.jsx("span",{className:"flex-1 text-sm text-oai-gray-900 dark:text-oai-gray-200",children:V(e)}),t.jsx("div",{onPointerDown:h=>h.stopPropagation(),children:t.jsx(St,{checked:a,onChange:s,ariaLabel:`${n("limits.settings.toggle_visible")}: ${V(e)}`})})]})}function Nt({prefs:e}){const{order:a,visibility:s,toggle:i,moveToward:o}=e,r=Me(F($e,{activationConstraint:{distance:6}}),F(Fe,{coordinateGetter:He})),l=({active:c,over:u})=>{u&&c.id!==u.id&&o(c.id,u.id)};return t.jsx(Be,{sensors:r,collisionDetection:Ve,modifiers:[Ze],onDragEnd:l,children:t.jsx(Ke,{items:a,strategy:ze,children:t.jsx("div",{className:"flex flex-col",children:a.map(c=>t.jsx(wt,{id:c,visible:s[c]!==!1,onToggle:()=>i(c)},c))})})})}function Ct(e){if(!e||typeof e!="object")return"";const a=e.user_metadata&&typeof e.user_metadata=="object"?e.user_metadata:{},s=e.profile&&typeof e.profile=="object"?e.profile:{},i=a.full_name||a.name||s.name||a.user_name||a.preferred_username;return typeof i=="string"&&i.trim()?i.trim():typeof e.email=="string"&&e.email.includes("@")?e.email.split("@")[0].trim()||e.email.trim():typeof e.email=="string"?e.email.trim():""}function Et(e){return!e||typeof e!="object"?"":typeof e.email=="string"?e.email.trim():""}function At(e){const a=typeof e=="string"?e.trim():"";if(!a)return null;const s=a.match(/^@?([A-Za-z0-9][A-Za-z0-9-]{0,38})$/),i=a.match(/^https:\/\/github\.com\/([A-Za-z0-9][A-Za-z0-9-]{0,38})\/?$/i),o=s?.[1]||i?.[1];return o?`https://github.com/${o}`:null}function D(e,a){console.warn(`[tokentracker] settings ${e}:`,a)}function Lt(e,a,s){const[i,o]=g.useState(()=>ue()),r=a&&s&&de(),l=g.useCallback(async()=>{const c=!i;if(ge(c),o(c),!!c)try{await pe(()=>e())}catch(u){D("cloud sync",u)}},[i,e]);return{cloudSyncOn:i,handleCloudSyncToggle:l,showLocalCloudSync:r}}function Ot(e){const[a,s]=g.useState(!1),[i,o]=g.useState(!1),[r,l]=g.useState(!1),[c,u]=g.useState(!1),[p,h]=g.useState(null),[d,y]=g.useState(!1),[x,S]=g.useState(""),[k,m]=g.useState(!1),[v,C]=g.useState(""),[N,P]=g.useState(""),[I,f]=g.useState(!1),[E,se]=g.useState(null),ie=g.useMemo(()=>Ct(e),[e]),oe=g.useMemo(()=>Et(e),[e]),re=g.useMemo(()=>typeof e?.id=="string"?e.id.trim():"",[e]),le=g.useMemo(()=>({setAnonymousOn:o,setCustomDisplayName:h,setGithubUrl:C,setProfileLoading:l,setPublicProfileOn:s,setShowGithubOn:m}),[]);return{anonymousOn:i,customDisplayName:p,displayName:ie,editingGithub:I,editingName:d,email:oe,githubError:E,githubInput:N,githubUrl:v,loadSetters:le,nameInput:x,profileLoading:r,profileSaving:c,publicProfileOn:a,setAnonymousOn:o,setCustomDisplayName:h,setEditingGithub:f,setEditingName:y,setGithubError:se,setGithubInput:P,setGithubUrl:C,setNameInput:S,setProfileLoading:l,setProfileSaving:u,setPublicProfileOn:s,setShowGithubOn:m,showGithubOn:k,userId:re}}function Pt(e,a,s){g.useEffect(()=>{if(!a)return;let i=!0;return s.setProfileLoading(!0),(async()=>{try{const o=await W({getAccessToken:e});if(!i||!o)return;const r=await he({accessToken:o});if(!i)return;s.setPublicProfileOn(!!r?.enabled),s.setAnonymousOn(!!r?.anonymous),r?.display_name&&s.setCustomDisplayName(r.display_name),s.setShowGithubOn(!!r?.show_github_url),s.setGithubUrl(r?.github_url||"")}catch(o){D("load public profile",o)}finally{i&&s.setProfileLoading(!1)}})(),()=>{i=!1}},[e,a,s])}function _t(e,a){return g.useCallback(async(s,{label:i,onError:o,onSuccess:r}={})=>{if(a.profileSaving)return!1;a.setProfileSaving(!0);try{const l=await W({getAccessToken:e});if(!l)return!1;const c=await me({accessToken:l,...s});return r?.(c),!0}catch(l){return o?o(l):D(i||"mutate profile",l),!1}finally{a.setProfileSaving(!1)}},[e,a])}function Tt(e,a){return{anonymousOn:e.anonymousOn,customDisplayName:e.customDisplayName,displayName:e.displayName,editingName:e.editingName,handleAnonymousToggle:a.handleAnonymousToggle,handleSaveName:a.handleSaveName,nameInput:e.nameInput,profileLoading:e.profileLoading,profileSaving:e.profileSaving,setEditingName:e.setEditingName,setNameInput:e.setNameInput,startEditingName:a.startEditingName}}function It(e,a){return{editingGithub:e.editingGithub,githubError:e.githubError,githubInput:e.githubInput,githubUrl:e.githubUrl,handleSaveGithub:a.handleSaveGithub,handleShowGithubToggle:a.handleShowGithubToggle,profileLoading:e.profileLoading,profileSaving:e.profileSaving,setEditingGithub:e.setEditingGithub,setGithubError:e.setGithubError,setGithubInput:e.setGithubInput,showGithubOn:e.showGithubOn,startEditingGithub:a.startEditingGithub}}function Gt(e,a){const s=g.useCallback(async()=>{const o=!e.publicProfileOn;await a({enabled:o},{label:"toggle public profile",onSuccess:()=>e.setPublicProfileOn(o)})},[a,e]);return{handleAnonymousToggle:g.useCallback(async()=>{const o=!e.anonymousOn;await a({anonymous:o},{label:"toggle anonymous",onSuccess:()=>e.setAnonymousOn(o)})},[a,e]),handlePublicProfileToggle:s}}function Rt(e,a,s){const i=g.useCallback(async()=>{const r=e.nameInput.trim().slice(0,50);r&&await a({display_name:r},{label:"save display name",onSuccess:()=>{e.setCustomDisplayName(r),e.setEditingName(!1),s?.()}})},[a,e,s]),o=g.useCallback(()=>{e.setNameInput(e.customDisplayName||e.displayName),e.setEditingName(!0)},[e]);return{handleSaveName:i,startEditingName:o}}function Ut(e,a){const s=g.useCallback(async()=>{if(!e.showGithubOn&&!e.githubUrl){e.setEditingGithub(!0),e.setGithubInput(""),e.setGithubError(null);return}const r=!e.showGithubOn;await a({show_github_url:r},{label:"toggle GitHub profile",onSuccess:()=>e.setShowGithubOn(r)})},[a,e]),i=g.useCallback(async()=>{const r=At(e.githubInput);if(e.githubInput.trim()&&!r){e.setGithubError(n("settings.account.githubUrlInvalid"));return}e.setGithubError(null),await a({github_url:r,show_github_url:!!r},{label:"save GitHub profile",onError:l=>e.setGithubError(l?.message||n("settings.account.githubUrlInvalid")),onSuccess:l=>{e.setGithubUrl(l?.github_url||r||""),e.setShowGithubOn(!!r),e.setEditingGithub(!1)}})},[a,e]),o=g.useCallback(()=>{e.setGithubInput(e.githubUrl),e.setGithubError(null),e.setEditingGithub(!0)},[e]);return{handleSaveGithub:i,handleShowGithubToggle:s,startEditingGithub:o}}function Dt(){const e=ce(),a=Ot(e.user),s=Lt(e.getAccessToken,e.enabled,e.signedIn);Pt(e.getAccessToken,e.signedIn,a.loadSetters);const i=_t(e.getAccessToken,a),o=Gt(a,i),r=Rt(a,i,e.refreshDisplayName),l=Ut(a,i);return{...e,...s,email:a.email,handlePublicProfileToggle:o.handlePublicProfileToggle,userId:a.userId,name:Tt(a,{...o,...r}),github:It(a,l),profileLoading:a.profileLoading,profileSaving:a.profileSaving,publicProfileOn:a.publicProfileOn}}function Q({disabled:e,onCancel:a,onSave:s,saveLabel:i=n("settings.account.save")}){return t.jsxs(t.Fragment,{children:[t.jsx("button",{type:"button",onClick:s,disabled:e,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:i}),t.jsx("button",{type:"button",onClick:a,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:n("settings.account.cancel")})]})}function Mt({nameInput:e,setEditingName:a,setNameInput:s,profileSaving:i,handleSaveName:o}){return t.jsxs("div",{className:"mt-2 flex items-center gap-2",children:[t.jsx("input",{type:"text",value:e,onChange:r=>s(r.target.value),onKeyDown:r=>{r.key==="Enter"&&o(),r.key==="Escape"&&a(!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:n("settings.account.displayName")}),t.jsx(Q,{disabled:i||!e.trim(),onCancel:()=>a(!1),onSave:o,saveLabel:i?n("settings.account.saving"):void 0})]})}function Ht({githubError:e,githubInput:a,handleSaveGithub:s,profileSaving:i,setEditingGithub:o,setGithubError:r,setGithubInput:l}){return t.jsxs("div",{className:"mt-2",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("input",{type:"text",value:a,onChange:c=>{l(c.target.value),e&&r(null)},onKeyDown:c=>{c.key==="Enter"&&s(),c.key==="Escape"&&(o(!1),r(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:n("settings.account.githubUrlPlaceholder")}),t.jsx(Q,{disabled:i,onCancel:()=>{o(!1),r(null)},onSave:s,saveLabel:i?n("settings.account.saving"):void 0})]}),e?t.jsx("div",{className:"mt-1.5 text-xs text-red-600 dark:text-red-400",children:e}):null]})}function ee({disabled:e=!1,label:a,onClick:s,title:i}){return t.jsxs("button",{type:"button",onClick:s,disabled:e,title:i,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:[t.jsx(Xe,{className:"h-3.5 w-3.5","aria-hidden":!0}),a]})}function te({actions:e,editing:a,editor:s,hint:i,label:o}){return t.jsx("div",{className:"py-3",children:t.jsxs("div",{className:"flex items-start justify-between gap-4",children:[t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsx("div",{className:"text-sm text-oai-gray-900 dark:text-oai-gray-200",children:o}),a?s:t.jsx("div",{className:"mt-0.5 truncate text-xs text-oai-gray-500 dark:text-oai-gray-400",children:i})]}),a?null:e]})})}function Ft({name:e}){const a=e.anonymousOn?n("settings.account.displayNameDisabledWhileAnon"):void 0;return t.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[t.jsx(ee,{disabled:e.anonymousOn,label:n("settings.account.edit"),onClick:e.startEditingName,title:a}),t.jsx(j,{checked:!e.anonymousOn,onChange:e.handleAnonymousToggle,disabled:e.profileLoading||e.profileSaving,ariaLabel:n("settings.account.displayName")})]})}function $t({name:e}){const{anonymousOn:a,customDisplayName:s,displayName:i,editingName:o,handleAnonymousToggle:r,handleSaveName:l,nameInput:c,profileLoading:u,profileSaving:p,setEditingName:h,setNameInput:d,startEditingName:y}=e,x=a?n("settings.account.displayNameAnonymousHint"):s||i;return t.jsx(te,{label:n("settings.account.displayName"),editing:o,hint:x,editor:t.jsx(Mt,{nameInput:c,setEditingName:h,setNameInput:d,profileSaving:p,handleSaveName:l}),actions:t.jsx(Ft,{name:e})})}function Bt({github:e}){const{editingGithub:a,githubError:s,githubInput:i,githubUrl:o,handleSaveGithub:r,handleShowGithubToggle:l,profileLoading:c,profileSaving:u,setEditingGithub:p,setGithubError:h,setGithubInput:d,showGithubOn:y,startEditingGithub:x}=e;return t.jsx(t.Fragment,{children:t.jsx(te,{label:n("settings.account.githubUrl"),editing:a,hint:o||n("settings.account.githubUrlHint"),editor:t.jsx(Ht,{githubError:s,githubInput:i,handleSaveGithub:r,profileSaving:u,setEditingGithub:p,setGithubError:h,setGithubInput:d}),actions:t.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[t.jsx(ee,{label:n("settings.account.edit"),onClick:x}),t.jsx(j,{checked:y,onChange:l,disabled:c||u,ariaLabel:n("settings.account.githubUrl")})]})})})}function Vt(){const{openLoginModal:e}=be();return t.jsx(A,{title:n("settings.section.account"),children:t.jsxs("div",{className:"flex items-center justify-between gap-4 py-3",children:[t.jsx("p",{className:"text-sm text-oai-gray-500 dark:text-oai-gray-400",children:n("settings.account.signedOutHint")}),t.jsx("button",{type:"button",onClick:e,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:n("settings.account.signIn")})]})})}function Kt({name:e,github:a}){return t.jsxs(t.Fragment,{children:[t.jsx($t,{name:e}),t.jsx(Bt,{github:a})]})}function zt(){const e=Dt();return e.enabled?e.signedIn?t.jsxs(A,{title:n("settings.section.account"),subtitle:e.email||e.name.customDisplayName||e.name.displayName,action:t.jsx(Wt,{onSignOut:e.signOut}),children:[t.jsx(qt,{userId:e.userId}),t.jsx(Zt,{settings:e}),t.jsx(Yt,{checked:e.publicProfileOn,disabled:e.profileLoading||e.profileSaving,onChange:e.handlePublicProfileToggle}),t.jsx(Jt,{visible:e.publicProfileOn,name:e.name,github:e.github})]}):t.jsx(Vt,{}):null}function qt({userId:e}){const[a,s]=R.useState(!1);if(!e)return null;const i=async()=>{try{if(typeof navigator>"u"||!navigator.clipboard?.writeText)return;await navigator.clipboard.writeText(e),s(!0),globalThis.setTimeout(()=>s(!1),1200)}catch{s(!1)}};return t.jsxs("div",{className:"flex items-center justify-between gap-4 py-3",children:[t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsx("div",{className:"text-sm text-oai-gray-900 dark:text-oai-gray-200",children:n("settings.account.userId")}),t.jsx("div",{className:"mt-0.5 truncate font-mono text-xs text-oai-gray-500 dark:text-oai-gray-400",children:e})]}),t.jsxs("button",{type:"button",onClick:i,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":n("settings.account.copyUserId"),children:[a?t.jsx(tt,{className:"h-3.5 w-3.5","aria-hidden":!0}):t.jsx(nt,{className:"h-3.5 w-3.5","aria-hidden":!0}),a?n("settings.account.copied"):n("settings.account.copy")]})]})}function Wt({onSignOut:e}){return t.jsxs("button",{type:"button",onClick:()=>e(),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:[t.jsx(ft,{className:"h-3.5 w-3.5","aria-hidden":!0}),n("settings.account.signOut")]})}function Zt({settings:e}){return e.showLocalCloudSync?t.jsx(b,{label:n("settings.account.cloudSync"),hint:n("settings.account.cloudSyncHint"),control:t.jsx(j,{checked:e.cloudSyncOn,onChange:e.handleCloudSyncToggle,ariaLabel:n("settings.account.cloudSync")})}):null}function Yt({checked:e,disabled:a,onChange:s}){return t.jsx(b,{label:n("settings.account.publicProfile"),hint:n("settings.account.publicProfileHint"),control:t.jsx(j,{checked:e,onChange:s,disabled:a,ariaLabel:n("settings.account.publicProfile")})})}function Jt({visible:e,name:a,github:s}){return t.jsx(X,{initial:!1,children:e?t.jsx(J.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:t.jsx(Kt,{name:a,github:s})},"public-profile-fields"):null})}function Xt(){return[{value:"light",label:n("settings.appearance.theme.light"),Icon:xe},{value:"dark",label:n("settings.appearance.theme.dark"),Icon:ye},{value:"system",label:n("settings.appearance.theme.system"),Icon:Y}]}function Qt(){return[{value:je,label:n("settings.appearance.language.system")},{value:Se,label:n("settings.appearance.language.english")},{value:we,label:n("settings.appearance.language.chinese")},{value:Ne,label:n("settings.appearance.language.traditional_chinese")},{value:Ce,label:n("settings.appearance.language.japanese")},{value:Ee,label:n("settings.appearance.language.korean")},{value:Ae,label:n("settings.appearance.language.german")}]}function en(e){if(!e)return null;try{const a=new Date(e);return Number.isNaN(a.getTime())?null:a.toLocaleString()}catch{return null}}function tn(e,a){const s=n(`settings.appearance.currency.rate_source.${e}`),i=en(a),o=i?n("settings.appearance.currency.rate_updated",{when:i}):n("settings.appearance.currency.rate_never");return`${s} · ${o}`}function nn({locale:e,setLocale:a}){const s=Qt();return t.jsx(U,{value:e,onValueChange:a,options:s,ariaLabel:n("settings.appearance.language.label"),className:"px-2.5 py-1.5 text-xs font-medium",leadingIcon:t.jsx(mt,{className:"h-3.5 w-3.5 text-oai-gray-500 dark:text-oai-gray-400","aria-hidden":!0})})}function an({currency:e,setCurrency:a}){const s=ve().map(i=>({value:i.code,label:n(i.labelKey)}));return t.jsx(U,{value:e,onValueChange:a,options:s,ariaLabel:n("settings.appearance.currency.label"),className:"px-3 py-1.5 text-xs font-medium"})}function sn({currency:e,rate:a,rateSource:s,rateFetchedAt:i}){if(e===ke)return t.jsx(t.Fragment,{children:n("settings.appearance.currency.hint")});const o=tn(s,i);return t.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[t.jsx("span",{children:`1 USD = ${a.toFixed(4)} ${e}`}),t.jsx("span",{role:"img","aria-label":o,title:o,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:t.jsx(it,{className:"h-3.5 w-3.5","aria-hidden":!0})})]})}function on(){const{theme:e,setTheme:a}=fe(),{locale:s,setLocale:i}=Z(),{currency:o,rate:r,rateSource:l,rateFetchedAt:c,setCurrency:u}=at(),{mode:p,setMode:h}=st();return t.jsxs(A,{title:n("settings.section.appearance"),children:[t.jsx(b,{label:n("settings.appearance.theme.label"),hint:n("settings.appearance.theme.hint"),control:t.jsx(_,{options:Xt(),value:e,onChange:a})}),t.jsx(b,{label:n("settings.appearance.language.label"),hint:n("settings.appearance.language.hint"),control:t.jsx(nn,{locale:s,setLocale:i})}),t.jsx(b,{label:n("settings.appearance.currency.label"),hint:t.jsx(sn,{currency:o,rate:r,rateSource:l,rateFetchedAt:c}),control:t.jsx(an,{currency:o,setCurrency:u})}),t.jsx(b,{label:n("settings.appearance.token_format.label"),hint:n("settings.appearance.token_format.hint"),control:t.jsx(_,{options:[{value:M.COMPACT,label:n("settings.appearance.token_format.compact")},{value:M.FULL,label:n("settings.appearance.token_format.full")}],value:p,onChange:h})})]})}function G({labelKey:e}){return t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("span",{children:n(e)}),t.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:n("qpd.card.badge")})]})}function rn(){const{enabled:e,toggle:a}=Qe(),{enabled:s,toggle:i}=et(),{available:o,settings:r,setSetting:l}=T(),c=o&&!!r?.dynamicIslandSupported,u=!!r?.dynamicIslandEnabled;return t.jsxs(A,{title:n("settings.section.labs"),children:[c&&t.jsxs(t.Fragment,{children:[t.jsx(b,{label:t.jsx(G,{labelKey:"settings.labs.island.label"}),hint:n("settings.labs.island.hint"),control:t.jsx(j,{checked:u,onChange:()=>l("dynamicIslandEnabled",!u),ariaLabel:n("settings.labs.island.aria")})}),u&&t.jsx(b,{label:n("settings.labs.island_hide_menubar.label"),hint:n("settings.labs.island_hide_menubar.hint"),control:t.jsx(j,{checked:!!r?.hideMenuBarIcon,onChange:()=>l("hideMenuBarIcon",!r?.hideMenuBarIcon),ariaLabel:n("settings.labs.island_hide_menubar.aria")})})]}),t.jsx(b,{label:t.jsx(G,{labelKey:"settings.labs.qpd.label"}),hint:n("settings.labs.qpd.hint"),control:t.jsx(j,{checked:e,onChange:a,ariaLabel:n("settings.labs.qpd.aria")})}),t.jsx(b,{label:t.jsx(G,{labelKey:"settings.labs.sessions.label"}),hint:n("settings.labs.sessions.hint"),control:t.jsx(j,{checked:s,onChange:i,ariaLabel:n("settings.labs.sessions.aria")})})]})}function ln(){const{available:e,settings:a,setSetting:s,runAction:i}=T();if(!e)return null;const o=!!a?.launchAtLogin,r=a?.toastOnReset!==!1,l=a?.confettiOnReset!==!1,c=a?.launchAtLoginSupported!==!1,u=a?.autoUpdateEnabled!==!1,p=a?.updateStatus||null,h=!!a?.updateBusy,d=!!a?.isSyncing;return t.jsxs(A,{title:n("settings.section.menubar"),children:[t.jsx(b,{label:n("settings.menubar.appearance"),hint:n("settings.menubar.appearanceHint"),control:t.jsxs(Le,{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:[n("settings.menubar.appearanceLink"),t.jsx(rt,{className:"h-3.5 w-3.5","aria-hidden":!0})]})}),t.jsx(b,{label:n("settings.menubar.toastOnReset"),hint:n("settings.menubar.toastOnResetHint"),control:t.jsx(j,{checked:r,onChange:()=>s("toastOnReset",!r),ariaLabel:n("settings.menubar.toastOnReset")})}),t.jsx(b,{label:n("settings.menubar.confettiOnReset"),hint:n("settings.menubar.confettiOnResetHint"),control:t.jsx(j,{checked:l,onChange:()=>s("confettiOnReset",!l),ariaLabel:n("settings.menubar.confettiOnReset")})}),c?t.jsx(b,{label:n("settings.menubar.launchAtLogin"),hint:n("settings.menubar.launchAtLoginHint"),control:t.jsx(j,{checked:o,onChange:()=>s("launchAtLogin",!o),ariaLabel:n("settings.menubar.launchAtLogin")})}):null,t.jsx(b,{label:n("settings.menubar.syncNow"),hint:n("settings.menubar.syncNowHint"),control:t.jsxs("button",{type:"button",onClick:()=>i("syncNow"),disabled:d,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:[t.jsx(Oe,{className:L("h-3.5 w-3.5",d&&"animate-spin"),"aria-hidden":!0}),d?n("settings.menubar.syncing"):n("settings.menubar.syncNow")]})}),t.jsx(b,{label:n("settings.menubar.autoUpdate"),hint:n("settings.menubar.autoUpdateHint"),control:t.jsx(j,{checked:u,onChange:()=>s("autoUpdateEnabled",!u),ariaLabel:n("settings.menubar.autoUpdate")})}),t.jsx(b,{label:n("settings.menubar.updates"),hint:p||void 0,control:t.jsxs("button",{type:"button",onClick:()=>i("checkForUpdates"),disabled:h,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:[t.jsx(lt,{className:"h-3.5 w-3.5","aria-hidden":!0}),n("settings.menubar.checkUpdates")]})})]})}function cn(e,a){function s(r){return r.replace(/^v/,"").split(".").map(Number)}const i=s(e),o=s(a);for(let r=0;r<Math.max(i.length,o.length);r++){const l=i[r]||0,c=o[r]||0;if(l<c)return!0;if(l>c)return!1}return!1}function un(){const{available:e,settings:a,runAction:s}=T(),i=e&&a?.version,[o,r]=R.useState(!1),[l,c]=R.useState({open:!1,latestVersion:"",htmlUrl:""}),{resolvedLocale:u}=Z(),p="0.95.2",h=async()=>{r(!0);try{const k=await fetch("https://api.github.com/repos/xiufengsun/TokenTracker/releases/latest");if(!k.ok)throw new Error("Failed to fetch");const m=await k.json(),v=m.tag_name;cn(p,v)?c({open:!0,latestVersion:v,htmlUrl:m.html_url}):H({title:n("settings.menubar.updates.upToDate")})}catch(k){console.error("Check updates failed:",k),H({title:n("settings.menubar.updates.failed")})}finally{r(!1)}},d=n("settings.menubar.updates.modalTitle"),y=n("settings.menubar.updates.modalDescription",{version:l.latestVersion}),x=n("settings.menubar.updates.modalConfirm"),S=n("settings.menubar.updates.modalCancel");return t.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:[t.jsxs("div",{className:"flex flex-wrap items-center justify-center gap-2",children:[i?t.jsxs(t.Fragment,{children:[t.jsx("span",{children:n("settings.menubar.updates.footerCombined",{barVersion:a.version,coreVersion:p})}),t.jsx("span",{"aria-hidden":!0,children:"·"}),t.jsx("button",{type:"button",onClick:()=>s("openAbout"),className:"underline-offset-2 transition-colors hover:text-oai-gray-700 hover:underline dark:hover:text-oai-gray-300",children:"GitHub"}),t.jsx("span",{"aria-hidden":!0,children:"·"})]}):t.jsxs(t.Fragment,{children:[t.jsx("span",{children:n("settings.menubar.updates.footerCore",{version:p})}),t.jsx("span",{"aria-hidden":!0,children:"·"}),t.jsx("button",{type:"button",onClick:h,disabled:o,className:"underline-offset-2 transition-colors hover:text-oai-gray-700 hover:underline dark:hover:text-oai-gray-300 disabled:opacity-50",children:o?n("settings.menubar.updates.checking"):n("settings.menubar.checkUpdates")}),t.jsx("span",{"aria-hidden":!0,children:"·"})]}),t.jsxs("a",{href:Pe,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:[t.jsx(_e,{className:"h-3.5 w-3.5","aria-hidden":!0}),n("settings.footer.statusPage")]})]}),t.jsx(ot,{open:l.open,title:d,description:y,confirmLabel:x,cancelLabel:S,onConfirm:()=>{window.open(l.htmlUrl,"_blank"),c(k=>({...k,open:!1}))},onCancel:()=>c(k=>({...k,open:!1}))})]})}const dn=()=>[{value:"system",label:n("settings.network.mode.system")},{value:"manual",label:n("settings.network.mode.manual")},{value:"off",label:n("settings.network.mode.off")}],gn=()=>[{value:"http",label:n("settings.network.protocol.http")},{value:"https",label:n("settings.network.protocol.https")},{value:"socks5",label:n("settings.network.protocol.socks5")}],K="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 z(e){const a={},s=String(e.host||"").trim();(!s||/:\/\//.test(s)||s.includes("/"))&&(a.host=n("settings.network.error.host"));const i=String(e.port??"").trim(),o=Number(i);return(!i||!/^\d+$/.test(i)||!Number.isInteger(o)||o<1||o>65535)&&(a.port=n("settings.network.error.port")),a}function pn({proxySettings:e}){const{config:a,save:s,testConnection:i}=e,[o,r]=g.useState(()=>({mode:a.mode,protocol:a.protocol||"http",host:a.host||"",port:a.port||""})),[l,c]=g.useState({}),[u,p]=g.useState(!1),[h,d]=g.useState(""),[y,x]=g.useState(null),[S,k]=g.useState(!1),[m,v]=g.useState(null);g.useEffect(()=>{r({mode:a.mode,protocol:a.protocol||"http",host:a.host||"",port:a.port||""})},[a.mode,a.protocol,a.host,a.port]);const C=g.useMemo(()=>a.effective==="manual"?n("settings.network.effective.manual"):a.effective==="env"?n("settings.network.effective.env"):a.effective==="system"?n("settings.network.effective.system"):a.effective==="blocked"?n("settings.network.effective.blocked"):n("settings.network.effective.none"),[a.effective]),N=f=>{r(E=>({...E,...f})),c({}),d(""),x(null),v(null)},P=async()=>{if(o.mode==="manual"){const f=z(o);if(Object.keys(f).length){c(f);return}}p(!0),d(""),x(null);try{await s(o),d("saved")}catch(f){d("error"),x(f)}finally{p(!1)}},I=async()=>{const f=z(o);if(Object.keys(f).length){c(f);return}k(!0),v(null);try{const E=await i(o);v(E)}catch(E){v({ok:!1,error:E?.message||String(E)})}finally{k(!1)}};return t.jsxs(A,{title:n("settings.section.network"),subtitle:C,children:[a.applyError?t.jsx("p",{role:"alert",className:"mb-3 text-xs text-red-600 dark:text-red-400",children:n("settings.network.apply_error",{error:a.applyError})}):null,t.jsx(b,{label:n("settings.network.mode.label"),hint:n("settings.network.mode.hint"),control:t.jsx(_,{options:dn(),value:o.mode,onChange:f=>N({mode:f})})}),t.jsx(X,{initial:!1,children:o.mode==="manual"?t.jsxs(J.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:[t.jsx(b,{label:n("settings.network.protocol.label"),control:t.jsx(U,{value:o.protocol,onValueChange:f=>N({protocol:f}),options:gn(),ariaLabel:n("settings.network.protocol.label"),className:"px-2.5 py-1.5 text-xs font-medium"})}),t.jsx(b,{label:n("settings.network.host.label"),hint:l.host,control:t.jsx("input",{type:"text",value:o.host,onChange:f=>N({host:f.target.value}),placeholder:n("settings.network.host.placeholder"),autoComplete:"off",spellCheck:!1,"aria-invalid":l.host?!0:void 0,"aria-label":n("settings.network.host.label"),className:K})}),t.jsx(b,{label:n("settings.network.port.label"),hint:l.port,control:t.jsx("input",{type:"text",inputMode:"numeric",value:o.port,onChange:f=>N({port:f.target.value}),placeholder:n("settings.network.port.placeholder"),autoComplete:"off",spellCheck:!1,"aria-invalid":l.port?!0:void 0,"aria-label":n("settings.network.port.label"),className:K})}),t.jsxs("div",{className:"flex flex-wrap items-center justify-end gap-2 py-3",children:[t.jsx("button",{type:"button",onClick:I,disabled:S||u,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:S?n("settings.network.test.testing"):n("settings.network.test")}),t.jsx("button",{type:"button",onClick:P,disabled:u||S,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:u?n("settings.network.saving"):n("settings.network.save")})]}),m?t.jsx("p",{className:"py-2 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:m.ok?n("settings.network.test.ok",{status:String(m.status??"")}):n("settings.network.test.fail",{error:m.error||""})}):null]},"manual-proxy-fields"):t.jsx("div",{className:"flex justify-end py-3",children:t.jsx("button",{type:"button",onClick:P,disabled:u,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:u?n("settings.network.saving"):n("settings.network.save")})},"non-manual-save")}),h==="saved"?t.jsx("p",{className:"py-2 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:n("settings.network.saved")}):null,h==="error"?t.jsx("p",{role:"alert",className:"py-2 text-xs text-red-600 dark:text-red-400",children:y?.unprotected?n("settings.network.save_error_unprotected",{error:y?.message||String(y||"")}):n("settings.network.save_error",{error:y?.message||String(y||"")})}):null]})}const ne="/functions/tokentracker-proxy-config",hn="/functions/tokentracker-proxy-test",mn={mode:"system",protocol:"http",host:"",port:"",effective:"none",applyError:null};function ae(e){return!e||typeof e.mode!="string"?null:{mode:e.mode,protocol:typeof e.protocol=="string"?e.protocol:"http",host:typeof e.host=="string"?e.host:"",port:e.port==null||e.port===0?"":String(e.port),effective:typeof e.effective=="string"?e.effective:"none",applyError:typeof e.applyError=="string"&&e.applyError.trim()?e.applyError:null}}async function bn(){const e=await fetch(ne,{method:"GET",headers:{Accept:"application/json"},cache:"no-store"});if(!e.ok)return null;const a=await e.json().catch(()=>null);return ae(a)}async function q(){const{getLocalApiAuthHeaders:e}=await Te(async()=>{const{getLocalApiAuthHeaders:a}=await import("./__vite-browser-external-DPOlUkcY.js").then(s=>s.d8);return{getLocalApiAuthHeaders:a}},__vite__mapDeps([0,1]));return e()}function fn(){const[e,a]=g.useState(!1),[s,i]=g.useState(!0),[o,r]=g.useState(mn);g.useEffect(()=>{if(!ct()){a(!1),i(!1);return}let u=!1;return(async()=>{try{const p=await bn();if(u)return;if(!p){a(!1),i(!1);return}r(p),a(!0),i(!1)}catch{u||(a(!1),i(!1))}})(),()=>{u=!0}},[]);const l=g.useCallback(async u=>{const p=await q(),h=await fetch(ne,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json",...p},cache:"no-store",body:JSON.stringify({mode:u.mode,protocol:u.protocol,host:u.host,port:u.port===""?0:Number(u.port)})}),d=await h.json().catch(()=>null);if(!h.ok){const x=d&&typeof d.error=="string"?d.error:`HTTP ${h.status}`;throw new Error(x)}const y=ae(d);if(y&&r(y),d&&d.ok===!1){const x=d&&typeof d.applyError=="string"&&d.applyError||d&&typeof d.error=="string"&&d.error||`HTTP ${h.status}`,S=new Error(x);throw d.unprotected===!0&&(S.unprotected=!0),S}return y||d},[]),c=g.useCallback(async u=>{const p=await q(),h=await fetch(hn,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json",...p},cache:"no-store",body:JSON.stringify({protocol:u.protocol,host:u.host,port:u.port===""?0:Number(u.port)})}),d=await h.json().catch(()=>null);if(!d||typeof d.ok!="boolean")throw new Error(d&&typeof d.error=="string"?d.error:`HTTP ${h.status}`);return d},[]);return{available:e,loading:s,config:o,save:l,testConnection:c}}const w={APPEARANCE:"appearance",NATIVE_APP:"native-app",NETWORK:"network",ACCOUNT:"account",LIMITS:"limits",LABS:"labs"};function xn({prefs:e}){return t.jsx(_,{options:[{value:$.USED,label:n("limits.settings.display_mode_used")},{value:$.REMAINING,label:n("limits.settings.display_mode_remaining")}],value:e.displayMode,onChange:e.setDisplayMode})}function zn(){const e=Ye(),{available:a,settings:s,setSetting:i}=T(),o=fn(),{available:r}=o,l=s?.toastOnReset!==!1,c=s?.confettiOnReset!==!1,[u,p]=Ie(),h=Ge(),d=u.get("section"),x=Object.values(w).includes(d)&&(d!==w.NATIVE_APP||a)&&(d!==w.NETWORK||r)?d:w.APPEARANCE,S=m=>{const v=new URLSearchParams(u);m===w.APPEARANCE?v.delete("section"):v.set("section",m),p(v,{replace:!0})},k=[{id:w.APPEARANCE,label:n("settings.section.appearance"),Icon:yt,content:t.jsx(on,{})},...a?[{id:w.NATIVE_APP,label:n("settings.section.menubar"),Icon:Y,content:t.jsx(ln,{})}]:[],...r?[{id:w.NETWORK,label:n("settings.section.network"),Icon:Re,content:t.jsx(pn,{proxySettings:o})}]:[],{id:w.ACCOUNT,label:n("settings.section.account"),Icon:kt,content:t.jsx(zt,{})},{id:w.LIMITS,label:n("settings.section.limits"),Icon:Ue,content:t.jsxs("div",{className:"space-y-4",children:[t.jsxs(A,{title:n("settings.section.limits"),children:[t.jsx(b,{label:n("limits.settings.display_mode_label"),control:t.jsx(xn,{prefs:e})}),t.jsx(b,{label:n("settings.menubar.toastOnReset"),hint:n("settings.menubar.toastOnResetHint"),control:t.jsx(j,{checked:l,disabled:!a,onChange:()=>i("toastOnReset",!l),ariaLabel:n("settings.menubar.toastOnReset")})}),t.jsx(b,{label:n("settings.menubar.confettiOnReset"),hint:n("settings.menubar.confettiOnResetHint"),control:t.jsx(j,{checked:c,disabled:!a,onChange:()=>i("confettiOnReset",!c),ariaLabel:n("settings.menubar.confettiOnReset")})}),t.jsx(b,{label:n("settings.limits.showSubscriptions"),hint:n("settings.limits.showSubscriptionsHint"),control:t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx("button",{type:"button",onClick:()=>h("/limits?openSubscriptions=1"),"aria-label":n("limits.page.openSubscriptions"),title:n("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:t.jsx(De,{size:14,"aria-hidden":!0})}),t.jsx(j,{checked:e.showSubscriptions!==!1,onChange:()=>e.setShowSubscriptions(!e.showSubscriptions),ariaLabel:n("settings.limits.showSubscriptions")})]})})]}),t.jsx(A,{title:n("settings.limits.providers"),children:t.jsx(Nt,{prefs:e})})]})},{id:w.LABS,label:n("settings.section.labs"),Icon:dt,content:t.jsx(rn,{})}];return t.jsx("div",{className:"flex flex-1 flex-col font-oai text-oai-black antialiased dark:text-oai-white",children:t.jsx("main",{className:"flex-1 pb-12 pt-8 sm:pb-16 sm:pt-10",children:t.jsxs("div",{className:"mx-auto w-full max-w-5xl px-4 sm:px-6",children:[t.jsx("div",{className:"mb-7",children:t.jsx("h1",{className:"text-3xl font-semibold tracking-tight text-oai-black dark:text-white sm:text-4xl",children:n("settings.page.title")})}),t.jsxs("div",{className:"grid min-w-0 gap-6 md:grid-cols-[12rem_minmax(0,1fr)] md:gap-8 lg:grid-cols-[13.5rem_minmax(0,1fr)]",children:[t.jsx("aside",{className:"min-w-0 border-b border-oai-gray-200 pb-3 dark:border-oai-gray-800 md:border-b-0 md:border-r md:pb-0 md:pr-5",children:t.jsx("nav",{"aria-label":n("settings.page.title"),className:"flex gap-0 overflow-x-auto [scrollbar-width:none] [&::-webkit-scrollbar]:hidden md:sticky md:top-6 md:flex-col md:gap-1 md:overflow-visible",children:k.map(({id:m,label:v,Icon:C})=>{const N=x===m;return t.jsxs("button",{id:`settings-nav-${m}`,type:"button","aria-current":N?"page":void 0,"aria-controls":`settings-panel-${m}`,onClick:()=>S(m),className:L("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",N?"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:[t.jsx(C,{className:L("h-4 w-4 shrink-0",N?"text-oai-black dark:text-white":"text-oai-gray-400 dark:text-oai-gray-500"),"aria-hidden":!0}),t.jsx("span",{className:"truncate",children:v})]},m)})})}),t.jsxs("div",{className:"min-w-0",children:[k.map(({id:m,label:v,content:C})=>t.jsx("section",{id:`settings-panel-${m}`,"aria-labelledby":`settings-nav-${m}`,"aria-label":v,"data-settings-panel":m,hidden:x!==m,children:C},m)),t.jsx(un,{})]})]})]})})})}export{zn as SettingsPage};