tokentracker-cli 1.3.3 → 1.3.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (187) hide show
  1. package/README.de.md +5 -5
  2. package/README.ja.md +3 -3
  3. package/README.ko.md +3 -3
  4. package/README.md +6 -5
  5. package/README.zh-CN.md +3 -3
  6. package/THIRD_PARTY_NOTICES.md +92 -0
  7. package/dashboard/dist/THIRD_PARTY_NOTICES.txt +92 -0
  8. package/dashboard/dist/assets/AchievementBadge-Dazs3pEa.js +1 -0
  9. package/dashboard/dist/assets/AchievementsPage-LWnxZvmw.js +2 -0
  10. package/dashboard/dist/assets/{AchievementsSection-CDUUEfIi.js → AchievementsSection-BLqczmU9.js} +1 -1
  11. package/dashboard/dist/assets/BadgeDetailModal-B_n4aj2S.js +1 -0
  12. package/dashboard/dist/assets/{BotAnimated-Dx_vvTtC.js → BotAnimated-KDWI_YcZ.js} +1 -1
  13. package/dashboard/dist/assets/Card-BYoxd4OC.js +1 -0
  14. package/dashboard/dist/assets/CloudCheckoutPage-BR2_B03P.js +1 -0
  15. package/dashboard/dist/assets/CloudPage-DL5RkJKK.js +1 -0
  16. package/dashboard/dist/assets/CloudUsageExport-C_DqZKo1.js +4 -0
  17. package/dashboard/dist/assets/CommandPalette-DkCaIQI4.js +1 -0
  18. package/dashboard/dist/assets/CommunityStatsModal-pX9OePi4.js +1 -0
  19. package/dashboard/dist/assets/{ConfirmModal-BQ-xB1S_.js → ConfirmModal-tkgZwz4u.js} +1 -1
  20. package/dashboard/dist/assets/Controls-MTUhGWy8.js +1 -0
  21. package/dashboard/dist/assets/DashboardPage-SOx-A7lH.js +1 -0
  22. package/dashboard/dist/assets/DateRangePopover-B-BMOm3O.js +1 -0
  23. package/dashboard/dist/assets/{DevicePage-Dg6XkIaY.js → DevicePage-DSK9lm7v.js} +1 -1
  24. package/dashboard/dist/assets/DialogClose-uVUNu4rg.js +1 -0
  25. package/dashboard/dist/assets/DialogDescription-DBqGGWNj.js +1 -0
  26. package/dashboard/dist/assets/DialogTitle-B-VifiA3.js +1 -0
  27. package/dashboard/dist/assets/{FadeIn-ChVf45WW.js → FadeIn-B6lrj4uo.js} +1 -1
  28. package/dashboard/dist/assets/{HeaderGithubStar-B740_G7a.js → HeaderGithubStar-Cx5zOhXa.js} +1 -1
  29. package/dashboard/dist/assets/{HoverTooltip-BzP5FudR.js → HoverTooltip-DY1ENf69.js} +1 -1
  30. package/dashboard/dist/assets/{IpCheckPage-BuZH3F14.js → IpCheckPage-D6TEq64d.js} +1 -1
  31. package/dashboard/dist/assets/LandingPage-OdZUfq--.js +2 -0
  32. package/dashboard/dist/assets/LeaderboardPage-DCK5xcAt.js +2 -0
  33. package/dashboard/dist/assets/LeaderboardProBadge-CBXJ1u_m.js +1 -0
  34. package/dashboard/dist/assets/{LeaderboardProfileModal-OUZvO6u-.js → LeaderboardProfileModal-Ccdzb7QK.js} +4 -4
  35. package/dashboard/dist/assets/{LeaderboardProfilePage-bHI1oTEK.js → LeaderboardProfilePage-CFXlZ0fL.js} +2 -2
  36. package/dashboard/dist/assets/LimitsPage-5krjm-g9.js +9 -0
  37. package/dashboard/dist/assets/{LocalOnlyNotice-BaEq6qN7.js → LocalOnlyNotice-Rk1B8PaZ.js} +1 -1
  38. package/dashboard/dist/assets/LoginCard-DTTIm8vk.js +1 -0
  39. package/dashboard/dist/assets/LoginModal-BNcDdjfr.js +1 -0
  40. package/dashboard/dist/assets/LoginPage-CQgXP7Ee.js +1 -0
  41. package/dashboard/dist/assets/{PetPage-BPBsUHyL.js → PetPage-Cw_kAPRs.js} +1 -1
  42. package/dashboard/dist/assets/PopoverPopup-NYiGE8A2.js +1 -0
  43. package/dashboard/dist/assets/{ProviderIcon-BshO2uER.js → ProviderIcon-Bp7iFJ_m.js} +1 -1
  44. package/dashboard/dist/assets/{ResetPasswordPage-RTFTD8Dr.js → ResetPasswordPage-Cf9kAWDW.js} +1 -1
  45. package/dashboard/dist/assets/Select-kIcvQFAo.js +1 -0
  46. package/dashboard/dist/assets/SelectItemText-BpIsAg3b.js +1 -0
  47. package/dashboard/dist/assets/{SelfHostPage-BlwTt8XM.js → SelfHostPage-Ch2vvSwI.js} +1 -1
  48. package/dashboard/dist/assets/{ServiceStatusPage-BkIcJpYK.js → ServiceStatusPage-hoYBvGbu.js} +1 -1
  49. package/dashboard/dist/assets/SessionsPage-BzRB6q-Z.js +3 -0
  50. package/dashboard/dist/assets/SessionsPage-GV2fuNmd.css +1 -0
  51. package/dashboard/dist/assets/SettingsPage-DRl2uX-i.js +2 -0
  52. package/dashboard/dist/assets/SkillsPage-CkqThTZL.js +1 -0
  53. package/dashboard/dist/assets/{TokenGalaxy-DiXUpXKF.js → TokenGalaxy-eLG-UIZY.js} +1 -1
  54. package/dashboard/dist/assets/TooltipPopup-bnMJyilQ.js +1 -0
  55. package/dashboard/dist/assets/TrendMonitor-X7-aGzIv.js +19 -0
  56. package/dashboard/dist/assets/WidgetsPage-CGznIzrW.js +1 -0
  57. package/dashboard/dist/assets/{WrappedPage-ClEo-RmR.js → WrappedPage-p31-uUoF.js} +1 -1
  58. package/dashboard/dist/assets/__vite-browser-external-2g_4s3ot.js +45 -0
  59. package/dashboard/dist/assets/__vite-browser-external-LpFw4zXh.css +1 -0
  60. package/dashboard/dist/assets/agent-logos-2TVT3fIE.js +1 -0
  61. package/dashboard/dist/assets/arrow-left-DL0hAp_7.js +1 -0
  62. package/dashboard/dist/assets/{arrow-right-CwBz5dwb.js → arrow-right-DFCpnV_9.js} +1 -1
  63. package/dashboard/dist/assets/{arrow-up-right-jPmRN562.js → arrow-up-right-DLvfE0Wu.js} +1 -1
  64. package/dashboard/dist/assets/calendar-days-B0aDoKSG.js +1 -0
  65. package/dashboard/dist/assets/{check-CKwHc4Hv.js → check-C_cfrxiz.js} +1 -1
  66. package/dashboard/dist/assets/chevron-down-Ck8ml43e.js +1 -0
  67. package/dashboard/dist/assets/cloud-checkout-PYnwNfdH.js +1 -0
  68. package/dashboard/dist/assets/composite-INW-ELWX.js +1 -0
  69. package/dashboard/dist/assets/download-B7uokeIo.js +1 -0
  70. package/dashboard/dist/assets/{external-link-B5yXxdPy.js → external-link-CI3crg4K.js} +1 -1
  71. package/dashboard/dist/assets/{flame-CKjAluj_.js → flame-DCzvFKV1.js} +1 -1
  72. package/dashboard/dist/assets/{format-tokens-mk49THtv.js → format-tokens-CSTEYK2m.js} +1 -1
  73. package/dashboard/dist/assets/gift-dEHDFMc6.js +1 -0
  74. package/dashboard/dist/assets/{host-mode-efKlSYjX.js → host-mode-r2SW9Mdv.js} +1 -1
  75. package/dashboard/dist/assets/{icons-ZB1ZthjH.js → icons-q-3zvEkh.js} +1 -1
  76. package/dashboard/dist/assets/{index-BImBG3eS.js → index-BV7qwUw4.js} +1 -1
  77. package/dashboard/dist/assets/{index-BgdM7kBl.js → index-BbrsgHf4.js} +1 -1
  78. package/dashboard/dist/assets/{index-DweUMAUD.js → index-CyHYj9XI.js} +1 -1
  79. package/dashboard/dist/assets/info-BBdY9hV4.js +1 -0
  80. package/dashboard/dist/assets/{link-2-Dn2soiyd.js → link-2-CLPePfXs.js} +1 -1
  81. package/dashboard/dist/assets/{loader-circle-CNT630zn.js → loader-circle-ETrjzfmn.js} +1 -1
  82. package/dashboard/dist/assets/{modifiers.esm-WPx0bc2K.js → modifiers.esm-DHqnp2ol.js} +1 -1
  83. package/dashboard/dist/assets/module-BNnaKM__.js +3 -0
  84. package/dashboard/dist/assets/monitor-smartphone-D1kdzrdb.js +1 -0
  85. package/dashboard/dist/assets/play-Cxp-ronD.js +1 -0
  86. package/dashboard/dist/assets/plus-4n94VzDK.js +1 -0
  87. package/dashboard/dist/assets/provider-display-CRlbeO7t.js +42 -0
  88. package/dashboard/dist/assets/{react-B7SkZTgg.js → react-DlHjGQFN.js} +1 -1
  89. package/dashboard/dist/assets/safePolygon-CVZ27a2_.js +1 -0
  90. package/dashboard/dist/assets/{search-Ol3OZBm4.js → search-BDPr56_h.js} +1 -1
  91. package/dashboard/dist/assets/{server-DFCbznC7.js → server-Bm7fHvVa.js} +1 -1
  92. package/dashboard/dist/assets/{shield-check-YcmLwVZ6.js → shield-check-DtT8ACzI.js} +1 -1
  93. package/dashboard/dist/assets/{skills-api-C-9vK884.js → skills-api-Dc1-2qu6.js} +1 -1
  94. package/dashboard/dist/assets/{sortable.esm-CKC9NuR-.js → sortable.esm-B-qN-Xk2.js} +1 -1
  95. package/dashboard/dist/assets/store-gHeBU8dQ.js +1 -0
  96. package/dashboard/dist/assets/{terminal-B3_fCLFs.js → terminal-D4VZbvhg.js} +1 -1
  97. package/dashboard/dist/assets/{trash-CZGfgbFa.js → trash-BZtLAFQy.js} +1 -1
  98. package/dashboard/dist/assets/{use-community-stats-CW-qkYn7.js → use-community-stats-BdqndrbB.js} +1 -1
  99. package/dashboard/dist/assets/{use-latest-request-guard-DHv7vfFE.js → use-latest-request-guard-DhGg1cDS.js} +1 -1
  100. package/dashboard/dist/assets/use-limits-display-prefs-D3HOcRFv.js +1 -0
  101. package/dashboard/dist/assets/{use-native-settings-CWiLqfZh.js → use-native-settings-BniKwA_n.js} +1 -1
  102. package/dashboard/dist/assets/{use-ordered-list-Df8pw-WJ.js → use-ordered-list-b09H7EHq.js} +1 -1
  103. package/dashboard/dist/assets/use-pet-settings-CPZdlq_e.js +2 -0
  104. package/dashboard/dist/assets/use-reduced-motion-D1gcKJUo.js +1 -0
  105. package/dashboard/dist/assets/{use-transform-BHwEAfmO.js → use-transform-CIdxjmI8.js} +1 -1
  106. package/dashboard/dist/assets/use-usage-limits-eJlU65yY.js +1 -0
  107. package/dashboard/dist/assets/{useCurrency-pwClnCZ5.js → useCurrency-CM22CmAq.js} +1 -1
  108. package/dashboard/dist/assets/usePositioner-B3l2ulTw.js +1 -0
  109. package/dashboard/dist/assets/{useTokenFormat-BMvVAe6V.js → useTokenFormat-D7nzgxKw.js} +1 -1
  110. package/dashboard/dist/assets/zap-Daxct1WV.js +1 -0
  111. package/dashboard/dist/index.html +14 -12
  112. package/dashboard/dist/ip-check.html +2 -2
  113. package/dashboard/dist/leaderboard.html +2 -2
  114. package/dashboard/dist/llms.txt +2 -2
  115. package/dashboard/dist/share.html +2 -2
  116. package/package.json +3 -2
  117. package/src/commands/init.js +43 -1
  118. package/src/commands/status.js +27 -0
  119. package/src/commands/sync.js +54 -4
  120. package/src/commands/uninstall.js +19 -0
  121. package/src/lib/claude-config.js +47 -15
  122. package/src/lib/codex-rollout-parser.js +11 -3
  123. package/src/lib/command-runner.js +15 -1
  124. package/src/lib/cursor-config.js +2 -1
  125. package/src/lib/gemini-config.js +3 -2
  126. package/src/lib/local-api.js +13 -3
  127. package/src/lib/notify-command.js +38 -0
  128. package/src/lib/openclaw-session-plugin.js +47 -14
  129. package/src/lib/passive-mode.js +12 -0
  130. package/src/lib/pricing/curated-overrides.json +42 -5
  131. package/src/lib/pricing/matcher.js +14 -5
  132. package/src/lib/pricing/seed-snapshot.json +1 -1
  133. package/src/lib/rollout.js +150 -28
  134. package/src/lib/session-analytics.js +108 -9
  135. package/src/lib/usage-limits.js +183 -20
  136. package/src/lib/zcode-limits.js +218 -18
  137. package/src/lib/zcode-reset-credits.js +66 -0
  138. package/dashboard/dist/assets/AchievementBadge-BaqdyZaV.js +0 -1
  139. package/dashboard/dist/assets/AchievementsPage-B4Ju0guv.js +0 -2
  140. package/dashboard/dist/assets/BadgeDetailModal-B-XMJAvL.js +0 -1
  141. package/dashboard/dist/assets/Card-D-5mABVt.js +0 -1
  142. package/dashboard/dist/assets/CloudCheckoutPage-BELoh56h.js +0 -1
  143. package/dashboard/dist/assets/CloudPage-CfBruNxe.js +0 -1
  144. package/dashboard/dist/assets/CloudUsageExport-BoFU7xCT.js +0 -4
  145. package/dashboard/dist/assets/CommandPalette-BmmKZWn-.js +0 -1
  146. package/dashboard/dist/assets/CommunityStatsModal-BF77zVhN.js +0 -1
  147. package/dashboard/dist/assets/Controls-BnTeX7T4.js +0 -1
  148. package/dashboard/dist/assets/DashboardPage-BWulHa5J.js +0 -1
  149. package/dashboard/dist/assets/DialogClose-DAyilsH-.js +0 -1
  150. package/dashboard/dist/assets/DialogDescription-j4XnRy6y.js +0 -1
  151. package/dashboard/dist/assets/DialogTitle-B1iNGD2S.js +0 -1
  152. package/dashboard/dist/assets/LandingPage-Dtgq_caz.js +0 -2
  153. package/dashboard/dist/assets/LeaderboardPage-Di1kEg2O.js +0 -2
  154. package/dashboard/dist/assets/LeaderboardProBadge-h8FfR0au.js +0 -1
  155. package/dashboard/dist/assets/LimitsPage-DKojB73_.js +0 -8
  156. package/dashboard/dist/assets/LoginCard-Dn5Xy4If.js +0 -1
  157. package/dashboard/dist/assets/LoginModal-C5h-5GOA.js +0 -1
  158. package/dashboard/dist/assets/LoginPage-BpX8Tgjj.js +0 -1
  159. package/dashboard/dist/assets/PopoverPopup-CVTiEVHs.js +0 -1
  160. package/dashboard/dist/assets/Select-CtTceC4T.js +0 -1
  161. package/dashboard/dist/assets/SelectItemText-C7xi8iGp.js +0 -1
  162. package/dashboard/dist/assets/SessionsPage-BngTWN7Q.css +0 -1
  163. package/dashboard/dist/assets/SessionsPage-okHobk_L.js +0 -3
  164. package/dashboard/dist/assets/SettingsPage-C-cc6wcF.js +0 -2
  165. package/dashboard/dist/assets/SkillsPage-D2LlKKJN.js +0 -1
  166. package/dashboard/dist/assets/TrendMonitor-C88S-5aa.js +0 -19
  167. package/dashboard/dist/assets/WidgetsPage-WsEFPNwp.js +0 -1
  168. package/dashboard/dist/assets/__vite-browser-external-DFRX9dp-.css +0 -1
  169. package/dashboard/dist/assets/__vite-browser-external-DUJeOWgd.js +0 -45
  170. package/dashboard/dist/assets/agent-logos-BM9jlReI.js +0 -1
  171. package/dashboard/dist/assets/arrow-left-BEM-HVmC.js +0 -1
  172. package/dashboard/dist/assets/cloud-checkout-nYNHDFoR.js +0 -1
  173. package/dashboard/dist/assets/composite-B4Z3F65o.js +0 -1
  174. package/dashboard/dist/assets/download-CJUnX1Bs.js +0 -1
  175. package/dashboard/dist/assets/info-CyDY7NYM.js +0 -1
  176. package/dashboard/dist/assets/module-WSx8viXK.js +0 -3
  177. package/dashboard/dist/assets/monitor-smartphone-C-qC0RAt.js +0 -1
  178. package/dashboard/dist/assets/plus-Cx82jb7o.js +0 -1
  179. package/dashboard/dist/assets/provider-display-CodMmiRb.js +0 -42
  180. package/dashboard/dist/assets/safePolygon-CKpREa4K.js +0 -1
  181. package/dashboard/dist/assets/store-C9yWYHfg.js +0 -1
  182. package/dashboard/dist/assets/use-limits-display-prefs-NZ-AAYD5.js +0 -1
  183. package/dashboard/dist/assets/use-pet-settings-Bg2CDprr.js +0 -2
  184. package/dashboard/dist/assets/use-reduced-motion-iDZEUyua.js +0 -1
  185. package/dashboard/dist/assets/use-usage-limits-CSxFFn3_.js +0 -1
  186. package/dashboard/dist/assets/usePositioner-B0j1orGj.js +0 -1
  187. package/dashboard/dist/assets/zap-DvX2aYx5.js +0 -1
@@ -2,6 +2,7 @@ const fs = require("node:fs");
2
2
  const crypto = require("node:crypto");
3
3
  const os = require("node:os");
4
4
  const path = require("node:path");
5
+ const { fetchZcodeResetCredits } = require("./zcode-reset-credits");
5
6
 
6
7
  const DEFAULT_BILLING_BASE_URL = "https://zcode.z.ai/api/v1/zcode-plan";
7
8
  const DEFAULT_ZAI_MONITOR_BASE_URL = "https://api.z.ai";
@@ -248,14 +249,15 @@ function resolveZcodeCredentialAuth(providerKey, { home, env } = {}) {
248
249
  * account-provider:coding-plan:account:<family>-individual-coding-plan:account:<id>:api-key
249
250
  * account-provider:team:<providerId>:<productId>:<orgId>:<projectId>:account:<id>:api-key
250
251
  * Team segments are URI-encoded by ZCode. Start-plan balances use the zcodejwttoken instead.
251
- * @returns {{ providerKey: string, teamContext: { organizationId: string, projectId: string } | null } | null}
252
+ * @returns {{ providerKey: string, accountId: string, teamContext: { organizationId: string, projectId: string } | null } | null}
252
253
  */
253
254
  function parseZcodeAccountProviderCredentialName(name) {
254
- const match = typeof name === "string" ? name.match(/^account-provider:(.+):account:[^:]+:api-key$/) : null;
255
+ const match = typeof name === "string" ? name.match(/^account-provider:(.+):account:([^:]+):api-key$/) : null;
255
256
  if (!match) return null;
256
257
  const scope = match[1];
258
+ const accountId = match[2];
257
259
  const individual = scope.match(/^coding-plan:account:(bigmodel|zai)-individual-coding-plan$/);
258
- if (individual) return { providerKey: `builtin:${individual[1]}-coding-plan`, teamContext: null };
260
+ if (individual) return { providerKey: `builtin:${individual[1]}-coding-plan`, accountId, teamContext: null };
259
261
  if (!scope.startsWith("team:")) return null;
260
262
  const parts = scope.slice("team:".length).split(":");
261
263
  if (parts.length !== 4) return null;
@@ -263,7 +265,47 @@ function parseZcodeAccountProviderCredentialName(name) {
263
265
  const [providerId, productId, organizationId, projectId] = parts.map((part) => decodeURIComponent(part).trim());
264
266
  const team = providerId.match(/^account:(bigmodel|zai)-team-coding-plan$/);
265
267
  if (!team || !productId || !organizationId || !projectId) return null;
266
- return { providerKey: `builtin:${team[1]}-coding-plan`, teamContext: { organizationId, projectId } };
268
+ return { providerKey: `builtin:${team[1]}-coding-plan`, accountId, teamContext: { organizationId, projectId } };
269
+ } catch (_error) {
270
+ return null;
271
+ }
272
+ }
273
+
274
+ /** Region ("bigmodel" | "zai") a built-in plan provider belongs to. */
275
+ function zcodeProviderFamily(providerKey) {
276
+ return providerKey === "builtin:zai-coding-plan" || providerKey === "builtin:zai-start-plan" ? "zai" : "bigmodel";
277
+ }
278
+
279
+ /**
280
+ * Region whose plan should be served first. The model settings' domain is the
281
+ * region the user actually picked, so it wins; the OAuth login region only
282
+ * backs installs that never recorded a domain (API-key-only setups).
283
+ */
284
+ function loadZcodeActiveRegion({ home, env } = {}) {
285
+ try {
286
+ const settingPath = path.join(resolveZcodeHome({ home, env }), "v2", "setting.json");
287
+ if (fs.existsSync(settingPath)) {
288
+ const setting = JSON.parse(fs.readFileSync(settingPath, "utf8"));
289
+ const domain = typeof setting?.providerFamilyDomain === "string" ? setting.providerFamilyDomain.trim() : "";
290
+ if (domain === "bigmodel" || domain === "zai") return domain;
291
+ }
292
+ } catch (_error) {
293
+ // Fall through to the login region below.
294
+ }
295
+ const active = loadZcodeActiveProvider({ home, env });
296
+ return active === "bigmodel" || active === "zai" ? active : "";
297
+ }
298
+
299
+ /**
300
+ * Account id of the signed-in login for a region, from `oauth:<family>:user_info`.
301
+ * Reset cards and Start Plan grants are personal to this login, so their
302
+ * credentials may only ride along with quota keys that provably share it.
303
+ */
304
+ function loadZcodeLoginAccountId(family, { home, env } = {}) {
305
+ const raw = loadZcodeCredential(`oauth:${family}:user_info`, { home, env });
306
+ try {
307
+ const id = JSON.parse(raw)?.id;
308
+ return typeof id === "string" && id.trim() ? id.trim() : null;
267
309
  } catch (_error) {
268
310
  return null;
269
311
  }
@@ -279,7 +321,7 @@ function loadZcodeAccountProviderAuths({ home, env } = {}) {
279
321
  const decrypted = decryptZcodeCredentialValue(credentials[name], { home, env });
280
322
  const apiKey = typeof decrypted === "string" ? decrypted.trim() : "";
281
323
  if (!apiKey) continue;
282
- (out[parsed.providerKey] ||= []).push({ apiKey, teamContext: parsed.teamContext });
324
+ (out[parsed.providerKey] ||= []).push({ apiKey, accountId: parsed.accountId, teamContext: parsed.teamContext });
283
325
  }
284
326
  return out;
285
327
  }
@@ -346,8 +388,11 @@ function resolveZcodeProviderQuotaUrl(providerKey, provider, env = process.env)
346
388
 
347
389
  /**
348
390
  * Build quota/billing candidates from enabled providers and their existing keys.
349
- * Selected plans take precedence; team scope stays attached to its own provider.
350
- * ZCode 3.14+ dropped v2/config.json: there, candidates come from credentials.json
391
+ * Coding plans precede promotional Start Plan grants, and within each plan kind
392
+ * the active region's providers come first so switching regions never keeps
393
+ * serving the previously saved other-region plan. Selected plans take
394
+ * precedence; team scope stays attached to its own provider. ZCode 3.14+
395
+ * dropped v2/config.json: there, candidates come from credentials.json
351
396
  * alone (the active family's zcodejwttoken for start plans, per-account coding-plan keys).
352
397
  */
353
398
  function loadZcodeAuthCandidates({ home, env } = {}) {
@@ -358,8 +403,11 @@ function loadZcodeAuthCandidates({ home, env } = {}) {
358
403
  const config = hasConfig ? JSON.parse(fs.readFileSync(configPath, "utf8")) : {};
359
404
  if (!config || typeof config !== "object") return [];
360
405
  const providers = config.provider || {};
361
- // Per-account keys are a 3.14+ concept; a legacy config.json stays the only key source there.
362
- const accountAuths = hasConfig ? {} : loadZcodeAccountProviderAuths({ home, env });
406
+ // Per-account keys are a 3.14+ concept; a legacy config.json stays the only
407
+ // quota-key source there. The account keys are still read in mixed layouts
408
+ // (config.json + newer credentials.json) purely to prove key ownership.
409
+ const accountAuths = loadZcodeAccountProviderAuths({ home, env });
410
+ const accountAuthsAsKeys = hasConfig ? {} : accountAuths;
363
411
  const defaultCandidates = [
364
412
  "builtin:bigmodel-start-plan",
365
413
  "builtin:zai-start-plan",
@@ -372,11 +420,16 @@ function loadZcodeAuthCandidates({ home, env } = {}) {
372
420
  const selectedCandidates = selectedPlans.map((plan) => plan.providerKey)
373
421
  .filter((key) => defaultCandidates.includes(key));
374
422
  const availableCandidates = defaultCandidates.filter((key) => availability?.[key]?.status === "available");
423
+ const activeFamily = loadZcodeActiveRegion({ home, env });
424
+ const regionRank = (key) => activeFamily && zcodeProviderFamily(key) === activeFamily ? 0 : 1;
375
425
  const candidates = [
376
426
  ...selectedCandidates,
377
427
  ...availableCandidates,
378
428
  ...defaultCandidates,
379
- ].filter((key, index, all) => all.indexOf(key) === index);
429
+ ].filter((key, index, all) => all.indexOf(key) === index)
430
+ .sort((a, b) =>
431
+ (Number(isZcodeCodingPlanProvider(b)) - Number(isZcodeCodingPlanProvider(a)))
432
+ || (regionRank(a) - regionRank(b)));
380
433
  const auths = [];
381
434
  for (const key of candidates) {
382
435
  const configured = providers[key];
@@ -389,15 +442,36 @@ function loadZcodeAuthCandidates({ home, env } = {}) {
389
442
  const teamContext = selectedPlans.find((plan) => plan.providerKey === key)?.teamContext;
390
443
  // Legacy layouts only trust the shared JWT for providers config.json still lists.
391
444
  const credentialApiKey = provider || !hasConfig ? resolveZcodeCredentialAuth(key, { home, env }) : "";
392
- const accountEntries = (accountAuths[key] || []).map((entry) => ({
393
- apiKey: entry.apiKey,
394
- authSource: "credential:account-provider",
395
- teamContext: entry.teamContext,
396
- }));
445
+ // A config.json key that byte-equals a per-account credential inherits
446
+ // that credential's account identity, so ownership stays provable for
447
+ // keys the ZCode app wrote into config.json for the current login.
448
+ const owningAccount = Object.values(accountAuths).flat()
449
+ .find((entry) => entry.apiKey === apiKey) || null;
450
+ // Leftover keys from previously signed-in accounts stay as fallbacks but
451
+ // never outrank the current login's key, so the primary window cannot
452
+ // show account A's quota while login-scoped extras show account B's.
453
+ const family = zcodeProviderFamily(key);
454
+ const loginAccountId = loadZcodeLoginAccountId(family, { home, env });
455
+ const accountEntries = (accountAuthsAsKeys[key] || [])
456
+ .slice()
457
+ .sort((a, b) => (loginAccountId
458
+ ? Number(a.accountId !== loginAccountId) - Number(b.accountId !== loginAccountId)
459
+ : 0))
460
+ .map((entry) => ({
461
+ apiKey: entry.apiKey,
462
+ authSource: "credential:account-provider",
463
+ teamContext: entry.teamContext,
464
+ accountId: entry.accountId,
465
+ }));
397
466
  const authEntries = [
398
467
  credentialApiKey ? { apiKey: credentialApiKey, authSource: "credential:zcodejwttoken", teamContext } : null,
399
468
  ...accountEntries,
400
- apiKey ? { apiKey, authSource: "provider:config", teamContext } : null,
469
+ apiKey ? {
470
+ apiKey,
471
+ authSource: "provider:config",
472
+ teamContext,
473
+ ...(owningAccount ? { accountId: owningAccount.accountId } : {}),
474
+ } : null,
401
475
  ].filter(Boolean);
402
476
  const seenKeys = new Set();
403
477
  for (const entry of authEntries) {
@@ -412,6 +486,7 @@ function loadZcodeAuthCandidates({ home, env } = {}) {
412
486
  billingBaseUrl,
413
487
  quotaUrl,
414
488
  ...(entry.teamContext ? { teamContext: entry.teamContext } : {}),
489
+ ...(entry.accountId ? { accountId: entry.accountId } : {}),
415
490
  availability: availability?.[key]?.status || null,
416
491
  });
417
492
  }
@@ -599,7 +674,7 @@ function normalizeZcodeBalanceResponse(body) {
599
674
  };
600
675
  }
601
676
 
602
- async function fetchZcodeBilling(apiKey, { fetchImpl = fetch, baseUrl, env, home } = {}) {
677
+ async function fetchZcodeBilling(apiKey, { fetchImpl = fetch, baseUrl, env, home, signal } = {}) {
603
678
  const root = (baseUrl || resolveZcodeBillingBaseUrl(env)).replace(/\/$/, "");
604
679
  const url = new URL(`${root}/billing/balance`);
605
680
  const appVersion = resolveZcodeAppVersion({ home, env });
@@ -614,6 +689,7 @@ async function fetchZcodeBilling(apiKey, { fetchImpl = fetch, baseUrl, env, home
614
689
  const res = await fetchImpl(url.toString(), {
615
690
  method: "GET",
616
691
  headers,
692
+ signal,
617
693
  });
618
694
  if (res.status === 401 || res.status === 403) {
619
695
  throw new Error("Not authenticated with ZCode. Run `zcode` in Terminal to log in.");
@@ -635,6 +711,43 @@ async function fetchZcodeBilling(apiKey, { fetchImpl = fetch, baseUrl, env, home
635
711
  return res.json();
636
712
  }
637
713
 
714
+ /**
715
+ * Read the signed-in login's Start Plan grants (bonus buckets) from billing/balance.
716
+ * Read-only; a timed-out request aborts its connection so the optional read
717
+ * never drags on the primary quota windows.
718
+ */
719
+ async function fetchZcodeStartPlanGrants({ zcodeToken, fetchImpl = fetch, env, home, timeoutMs = 2000 } = {}) {
720
+ const controller = new AbortController();
721
+ let timer;
722
+ try {
723
+ return await Promise.race([
724
+ (async () => {
725
+ const body = await fetchZcodeBilling(zcodeToken, {
726
+ fetchImpl,
727
+ baseUrl: resolveZcodeBillingBaseUrl(env),
728
+ env,
729
+ home,
730
+ signal: controller.signal,
731
+ });
732
+ // An HTTP 200 with a nonzero business code and empty data must surface
733
+ // as a failed read, not silently pose as "no grants".
734
+ if (body && typeof body.code === "number" && body.code !== 0) {
735
+ throw new Error(`ZCode start plan grants API error: code=${body.code} msg=${body?.msg || "unknown"}`);
736
+ }
737
+ return normalizeZcodeBalanceResponse(body);
738
+ })(),
739
+ new Promise((_, reject) => {
740
+ timer = setTimeout(() => {
741
+ controller.abort();
742
+ reject(new Error("ZCode start plan grants request timed out"));
743
+ }, timeoutMs);
744
+ }),
745
+ ]);
746
+ } finally {
747
+ clearTimeout(timer);
748
+ }
749
+ }
750
+
638
751
  /**
639
752
  * Fetch quota using the existing provider key and optional team routing metadata.
640
753
  * Organization/project IDs select the subscription at the resolved provider URL;
@@ -880,11 +993,39 @@ function zcodeLogFallbackResult(logRecord, errors = []) {
880
993
  };
881
994
  }
882
995
 
996
+ /**
997
+ * Login tokens for reset cards / Start Plan grants, or null when the quota key
998
+ * cannot be proven to belong to the signed-in login. Both extras are personal
999
+ * to the current login. Any key carrying an account id (per-account
1000
+ * credentials, or config.json keys that byte-equal one) must match the login's
1001
+ * id. Once a login identity exists, an unprovable key (a config.json key no
1002
+ * account credential vouches for — e.g. left over from a switched account)
1003
+ * never merges its quota with this login's cards. When the login identity
1004
+ * itself is unreadable (user_info missing or unparseable) nothing can prove
1005
+ * the key belongs to the signed-in account either, so the extras are skipped
1006
+ * and only the main plan quota stays.
1007
+ */
1008
+ function loadZcodeLoginScopedTokens(family, auth, { home, env } = {}) {
1009
+ if (loadZcodeActiveProvider({ home, env }) !== family) return null;
1010
+ const loginAccountId = loadZcodeLoginAccountId(family, { home, env });
1011
+ if (!loginAccountId) return null;
1012
+ if (auth.accountId) {
1013
+ if (auth.accountId !== loginAccountId) return null;
1014
+ } else if (auth.auth_source === "credential:account-provider" || auth.auth_source === "provider:config") {
1015
+ return null;
1016
+ }
1017
+ const zcodeToken = loadZcodeCredential("zcodejwttoken", { home, env });
1018
+ if (!zcodeToken) return null;
1019
+ const codingPlanToken = loadZcodeCredential(`oauth:${family}:access_token`, { home, env });
1020
+ return { zcodeToken, codingPlanToken };
1021
+ }
1022
+
883
1023
  /**
884
1024
  * Return normalized quota windows, trying eligible providers and recent billing logs.
885
1025
  * Credentials and internal team routing identifiers are omitted from the result.
886
1026
  */
887
- async function fetchZcodeLimits({ home, env, fetchImpl = fetch, nowMs = Date.now() } = {}) {
1027
+ async function fetchZcodeLimits({ home, env, fetchImpl = fetch, nowMs = Date.now(), providerTimeoutMs } = {}) {
1028
+ const startedAt = Date.now();
888
1029
  if (!isZcodeInstalled({ home, env })) {
889
1030
  return { configured: false };
890
1031
  }
@@ -929,6 +1070,62 @@ async function fetchZcodeLimits({ home, env, fetchImpl = fetch, nowMs = Date.now
929
1070
  emptySuccess = emptySuccess || result;
930
1071
  continue;
931
1072
  }
1073
+ if (auth.planKind === "coding-plan") {
1074
+ const family = zcodeProviderFamily(auth.providerKey);
1075
+ const tokens = loadZcodeLoginScopedTokens(family, auth, { home, env });
1076
+ if (tokens) {
1077
+ const remainingMs = providerTimeoutMs > 0 ? providerTimeoutMs - (Date.now() - startedAt) - 100 : 4000;
1078
+ if (remainingMs <= 0) {
1079
+ result.reset_credits = { error: "ZCode reset credits: provider time budget exhausted" };
1080
+ result.start_plan = { configured: true, error: "ZCode start plan grants: provider time budget exhausted" };
1081
+ } else {
1082
+ const timeoutMs = Math.min(2000, remainingMs);
1083
+ // Reset cards additionally need the region's login token; without
1084
+ // it the status endpoint cannot identify a coding plan, so the
1085
+ // inventory stays absent instead of surfacing a blocking error.
1086
+ await Promise.all([
1087
+ (tokens.codingPlanToken
1088
+ ? fetchZcodeResetCredits({
1089
+ zcodeToken: tokens.zcodeToken,
1090
+ codingPlanToken: tokens.codingPlanToken,
1091
+ teamContext: auth.teamContext,
1092
+ fetchImpl,
1093
+ nowMs,
1094
+ timeoutMs,
1095
+ })
1096
+ : Promise.resolve(null)
1097
+ ).then(
1098
+ (value) => {
1099
+ if (value) result.reset_credits = value;
1100
+ },
1101
+ (reason) => {
1102
+ result.reset_credits = { error: reason?.message || "Could not read ZCode reset credits" };
1103
+ },
1104
+ ),
1105
+ fetchZcodeStartPlanGrants({
1106
+ zcodeToken: tokens.zcodeToken,
1107
+ fetchImpl,
1108
+ env,
1109
+ home,
1110
+ timeoutMs,
1111
+ }).then(
1112
+ (value) => {
1113
+ // No grants on the login → no section, instead of an empty card.
1114
+ if (Array.isArray(value.buckets) && value.buckets.length) {
1115
+ result.start_plan = { configured: true, error: null, ...value };
1116
+ }
1117
+ },
1118
+ (reason) => {
1119
+ result.start_plan = {
1120
+ configured: true,
1121
+ error: reason?.message || "Could not read ZCode start plan grants",
1122
+ };
1123
+ },
1124
+ ),
1125
+ ]);
1126
+ }
1127
+ }
1128
+ }
932
1129
  return result;
933
1130
  } catch (error) {
934
1131
  errors.push(`${auth.providerKey}: ${error?.message || "Unknown error"}`);
@@ -958,6 +1155,8 @@ module.exports = {
958
1155
  loadZcodeProviderAvailability,
959
1156
  loadZcodeSelectedPlanProviderKeys,
960
1157
  loadZcodeCredential,
1158
+ loadZcodeLoginAccountId,
1159
+ zcodeProviderFamily,
961
1160
  loadLatestZcodeBalanceFromLogs,
962
1161
  resolveZcodeProviderBillingBaseUrl,
963
1162
  resolveZcodeProviderQuotaUrl,
@@ -968,5 +1167,6 @@ module.exports = {
968
1167
  normalizeZcodeCodingPlanQuotaResponse,
969
1168
  fetchZcodeBilling,
970
1169
  fetchZcodeCodingPlanQuota,
1170
+ fetchZcodeStartPlanGrants,
971
1171
  fetchZcodeLimits,
972
1172
  };
@@ -0,0 +1,66 @@
1
+ const ZCODE_RESET_STATUS_URL = "https://zcode.z.ai/api/v1/coding-plan/reset/status";
2
+
3
+ function normalizeZcodeResetCredits(body, { nowMs = Date.now() } = {}) {
4
+ if (body?.code !== 0 || !body.data) {
5
+ throw new Error("Could not parse ZCode reset credits: invalid response");
6
+ }
7
+ const result = {};
8
+ for (const [key, field] of [
9
+ ["five_hour", "available_five_hour_resets"],
10
+ ["weekly", "available_week_resets"],
11
+ ]) {
12
+ if (!Array.isArray(body.data[field])) {
13
+ throw new Error("Could not parse ZCode reset credits: missing card list");
14
+ }
15
+ result[key] = body.data[field].map((card) => {
16
+ const expiresMs = card?.expire_at;
17
+ if (typeof expiresMs !== "number" || !Number.isFinite(expiresMs) || expiresMs <= 0
18
+ || !Number.isFinite(new Date(expiresMs).getTime())) {
19
+ throw new Error("Could not parse ZCode reset credits: invalid expiry");
20
+ }
21
+ return { expires_at: new Date(expiresMs).toISOString() };
22
+ }).filter((card) => Date.parse(card.expires_at) > nowMs)
23
+ .sort((a, b) => Date.parse(a.expires_at) - Date.parse(b.expires_at));
24
+ }
25
+ return result;
26
+ }
27
+
28
+ /** Read inventory only; send the two login tokens exclusively to ZCode's fixed status endpoint. */
29
+ async function fetchZcodeResetCredits({
30
+ zcodeToken, codingPlanToken, teamContext, fetchImpl = fetch, nowMs = Date.now(), timeoutMs = 2000,
31
+ }) {
32
+ const headers = {
33
+ Authorization: /^Bearer\s/i.test(zcodeToken) ? zcodeToken : `Bearer ${zcodeToken}`,
34
+ "X-Bigmodel-Authorization": codingPlanToken,
35
+ "Bigmodel-Target-Type": teamContext ? "TEAM" : "PERSONAL",
36
+ Accept: "application/json",
37
+ };
38
+ if (teamContext) {
39
+ headers["Bigmodel-Organization"] = teamContext.organizationId;
40
+ headers["Bigmodel-Project"] = teamContext.projectId;
41
+ }
42
+ const controller = new AbortController();
43
+ let timer;
44
+ try {
45
+ const request = Promise.resolve().then(async () => {
46
+ const response = await fetchImpl(ZCODE_RESET_STATUS_URL, {
47
+ // Custom auth headers survive cross-origin redirects; never forward them.
48
+ method: "GET", headers, signal: controller.signal, redirect: "error",
49
+ });
50
+ if (!response.ok) throw new Error(`ZCode reset credits API returned HTTP ${response.status}`);
51
+ const body = await response.json();
52
+ if (body?.code !== 0) throw new Error(`ZCode reset credits API error: code=${body?.code ?? "unknown"}`);
53
+ return normalizeZcodeResetCredits(body, { nowMs });
54
+ });
55
+ return await Promise.race([request, new Promise((_, reject) => {
56
+ timer = setTimeout(() => {
57
+ controller.abort();
58
+ reject(new Error("ZCode reset credits request timed out"));
59
+ }, timeoutMs);
60
+ })]);
61
+ } finally {
62
+ clearTimeout(timer);
63
+ }
64
+ }
65
+
66
+ module.exports = { fetchZcodeResetCredits, normalizeZcodeResetCredits };
@@ -1 +0,0 @@
1
- import{A as n,a6 as R,j as i}from"./__vite-browser-external-DUJeOWgd.js";import{Z as F}from"./zap-DvX2aYx5.js";import{F as I}from"./flame-CKjAluj_.js";import{S as G}from"./shield-check-YcmLwVZ6.js";const u={name:"blocks",size:24,node:[["path",{d:"M10 22V7a1 1 0 0 0-1-1H4a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-5a1 1 0 0 0-1-1H2",key:"1ah6g2"}],["rect",{x:"14",y:"2",width:"8",height:"8",rx:"1",key:"88lufb"}]]};u.node;const N=n(u);const k={name:"brain",size:24,node:[["path",{d:"M12 18V5",key:"adv99a"}],["path",{d:"M15 13a4.17 4.17 0 0 1-3-4 4.17 4.17 0 0 1-3 4",key:"1e3is1"}],["path",{d:"M17.598 6.5A3 3 0 1 0 12 5a3 3 0 1 0-5.598 1.5",key:"1gqd8o"}],["path",{d:"M17.997 5.125a4 4 0 0 1 2.526 5.77",key:"iwvgf7"}],["path",{d:"M18 18a4 4 0 0 0 2-7.464",key:"efp6ie"}],["path",{d:"M19.967 17.483A4 4 0 1 1 12 18a4 4 0 1 1-7.967-.517",key:"1gq6am"}],["path",{d:"M6 18a4 4 0 0 1-2-7.464",key:"k1g0md"}],["path",{d:"M6.003 5.125a4 4 0 0 0-2.526 5.77",key:"q97ue3"}]]};k.node;const S=n(k);const v={name:"calendar-days",size:24,node:[["path",{d:"M8 2v3",key:"1ioesn"}],["path",{d:"M16 2v3",key:"otl347"}],["rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",key:"h1oib"}],["path",{d:"M3 9h18",key:"1pudct"}],["path",{d:"M8 13h.01",key:"1sbv64"}],["path",{d:"M12 13h.01",key:"y0uutt"}],["path",{d:"M16 13h.01",key:"wip0gl"}],["path",{d:"M8 17h.01",key:"p3bg7i"}],["path",{d:"M12 17h.01",key:"p32p05"}],["path",{d:"M16 17h.01",key:"ql8jdd"}]]};v.node;const V=n(v);const M={name:"crown",size:24,node:[["path",{d:"M11.562 3.266a.5.5 0 0 1 .876 0L15.39 8.87a1 1 0 0 0 1.516.294L21.183 5.5a.5.5 0 0 1 .798.519l-2.834 10.246a1 1 0 0 1-.956.734H5.81a1 1 0 0 1-.957-.734L2.02 6.02a.5.5 0 0 1 .798-.519l4.276 3.664a1 1 0 0 0 1.516-.294z",key:"1vdc57"}],["path",{d:"M5 21h14",key:"11awu3"}]]};M.node;const Z=n(M);const b={name:"feather",size:24,node:[["path",{d:"M14.086 18.412A2 2 0 0112.67 19H5v-7.672a2 2 0 01.586-1.414L11.75 3.75a6 6 0 118.49 8.49z",key:"1nq9jb"}],["path",{d:"M16 8 2 22",key:"vp34q"}],["path",{d:"M17.488 15H9",key:"16yirz"}]]};b.node;const O=n(b);const _={name:"folder-git-2",size:24,node:[["path",{d:"M18 19a5 5 0 0 1-5-5v8",key:"sz5oeg"}],["path",{d:"M9 20H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H20a2 2 0 0 1 2 2v5",key:"1w6njk"}],["circle",{cx:"13",cy:"12",r:"2",key:"1j92g6"}],["circle",{cx:"20",cy:"19",r:"2",key:"1obnsp"}]]};_.node;const P=n(_);const x={name:"footprints",size:24,node:[["path",{d:"M4 16v-2.38C4 11.5 2.97 10.5 3 8c.03-2.72 1.49-6 4.5-6C9.37 2 10 3.8 10 5.5c0 3.11-2 5.66-2 8.68V16a2 2 0 1 1-4 0Z",key:"1dudjm"}],["path",{d:"M20 20v-2.38c0-2.12 1.03-3.12 1-5.62-.03-2.72-1.49-6-4.5-6C14.63 6 14 7.8 14 9.5c0 3.11 2 5.66 2 8.68V20a2 2 0 1 0 4 0Z",key:"l2t8xc"}],["path",{d:"M16 17h4",key:"1dejxt"}],["path",{d:"M4 13h4",key:"1bwh8b"}]]};x.node;const X=n(x);const w={name:"heart",size:24,node:[["path",{d:"M2 9.5a5.5 5.5 0 0 1 9.591-3.676.56.56 0 0 0 .818 0A5.49 5.49 0 0 1 22 9.5c0 2.29-1.5 4-3 5.5l-5.492 5.313a2 2 0 0 1-3 .019L5 15c-1.5-1.5-3-3.2-3-5.5",key:"mvr1a0"}]]};w.node;const K=n(w);const z={name:"medal",size:24,node:[["path",{d:"M7.21 15 2.66 7.14a2 2 0 0 1 .13-2.2L4.4 2.8A2 2 0 0 1 6 2h12a2 2 0 0 1 1.6.8l1.6 2.14a2 2 0 0 1 .14 2.2L16.79 15",key:"143lza"}],["path",{d:"M11 12 5.12 2.2",key:"qhuxz6"}],["path",{d:"m13 12 5.88-9.8",key:"hbye0f"}],["path",{d:"M8 7h8",key:"i86dvs"}],["circle",{cx:"12",cy:"17",r:"5",key:"qbz8iq"}],["path",{d:"M12 18v-2h-.5",key:"fawc4q"}]]};z.node;const U=n(z);const A={name:"moon-star",size:24,node:[["path",{d:"M18 5h4",key:"1lhgn2"}],["path",{d:"M20 3v4",key:"1olli1"}],["path",{d:"M20.985 12.486a9 9 0 1 1-9.473-9.472c.405-.022.617.46.402.803a6 6 0 0 0 8.268 8.268c.344-.215.825-.004.803.401",key:"kfwtm"}]]};A.node;const W=n(A);const D={name:"rocket",size:24,node:[["path",{d:"M12 15v5s3.03-.55 4-2c1.08-1.62 0-5 0-5",key:"qeys4"}],["path",{d:"M4.5 16.5c-1.5 1.26-2 5-2 5s3.74-.5 5-2c.71-.84.7-2.13-.09-2.91a2.18 2.18 0 0 0-2.91-.09",key:"u4xsad"}],["path",{d:"M9 12a22 22 0 0 1 2-3.95A12.88 12.88 0 0 1 22 2c0 2.72-.78 7.5-6 11a22.4 22.4 0 0 1-4 2z",key:"676m9"}],["path",{d:"M9 12H4s.55-3.03 2-4c1.62-1.08 5 .05 5 .05",key:"92ym6u"}]]};D.node;const Y=n(D);const $={name:"trending-up",size:24,node:[["path",{d:"M16 7h6v6",key:"box55l"}],["path",{d:"m22 7-8.5 8.5-5-5L2 17",key:"1t1m79"}]]};$.node;const J=n($),j=[{id:"token_titan",scope:"cloud",icon:Z,format:"tokens",art:"/achievements/token-titan.png"},{id:"big_day",scope:"cloud",icon:F,format:"tokens",art:"/achievements/big-day.png"},{id:"wordsmith",scope:"cloud",icon:O,format:"tokens",art:"/achievements/wordsmith.png"},{id:"marathoner",scope:"cloud",icon:X,format:"days",art:"/achievements/marathoner.png"},{id:"streak",scope:"cloud",icon:I,format:"days",art:"/achievements/streak.png"},{id:"weekend_warrior",scope:"cloud",icon:V,format:"days",art:"/achievements/weekend-warrior.png"},{id:"momentum",scope:"cloud",icon:J,format:"multiplier",art:"/achievements/momentum.png"},{id:"polyglot",scope:"cloud",icon:S,format:"count",art:"/achievements/polyglot.png"},{id:"trendsetter",scope:"cloud",icon:Y,format:"count",art:"/achievements/trendsetter.png"},{id:"multitool",scope:"cloud",icon:N,format:"count",art:"/achievements/multitool.png"},{id:"podium",scope:"cloud",icon:U,format:"rank",art:"/achievements/podium.png"},{id:"veteran",scope:"cloud",icon:G,format:"days",art:"/achievements/veteran.png"},{id:"project_hopper",scope:"local",icon:P,format:"count",art:"/achievements/project-hopper.png"},{id:"project_devotion",scope:"local",icon:K,format:"tokens",art:"/achievements/project-devotion.png"},{id:"night_owl",scope:"local",icon:W,format:"count",art:"/achievements/night-owl.png"}],E=new Map(j.map(e=>[e.id,e])),m=new Map(j.map((e,a)=>[e.id,a]));function de(e,a){return`achievements.badge.${e}.${a}`}function Q(e){return[...e||[]].sort((a,t)=>{const c=(t?.tier||0)-(a?.tier||0);return c!==0?c:(m.get(a?.id)??99)-(m.get(t?.id)??99)})}function ie(e){const a=(e||[]).filter(t=>t&&(t.tier||0)>=1&&E.has(t.id));return a.length===0?null:Q(a)[0]}const L={1:"bronze",2:"silver",3:"gold",4:"diamond"},re=["bronze","silver","gold","diamond"],ee={bronze:{rim:["#a06a44","#5c3a22"],face:["#d29a6c","#96602f"],glyph:"#3f2817",ring:"#e8c3a0",sheen:"rgba(255, 236, 220, 0.45)",label:"#a06a44"},silver:{rim:["#aab3bb","#67707b"],face:["#dde2e7","#9ba5ae"],glyph:"#39424b",ring:"#f2f5f7",sheen:"rgba(255, 255, 255, 0.55)",label:"#8b959f"},gold:{rim:["#c9971c","#8a6508"],face:["#f2ca52","#cf9c26"],glyph:"#5c430e",ring:"#ffe9a8",sheen:"rgba(255, 248, 214, 0.55)",label:"#b8860b"},diamond:{rim:["#62b1e0","#7c6fd9"],face:["#c8ecf6","#84b4ea"],glyph:"#27496d",ring:"#eafcff",sheen:"rgba(255, 255, 255, 0.65)",label:"#5a9bd8"}},g={rim:["#a8ada9","#7c817d"],face:["#cdd2ce","#a3a8a4"],glyph:"#6a706c",ring:"#dde1de",sheen:"rgba(255, 255, 255, 0.25)",label:"#8b908c"};function ae(e,a=!1){return a||!e||e<1?g:ee[L[Math.min(e,4)]]||g}function se(e){return L[e]||null}const y={xs:18,sm:24,md:44,xl:88,lg:108},f={xs:.75,sm:1,md:1.5,xl:2,lg:2};function le({badgeId:e,tier:a=0,size:t="md",locked:c=!1,label:r,className:T=""}){const s=E.get(e),h=c||!a||a<1,o=ae(a,h),d=t==="fill",l=d?"100%":y[t]||y.md,q=d?4:f[t]||f.md,[B,C]=R.useState(!1),p=s?.icon||null,H=!!s?.art&&!B;return i.jsx("span",{role:r?"img":void 0,"aria-label":r||void 0,"aria-hidden":r?void 0:!0,className:`inline-flex shrink-0 rounded-full ${T}`,style:{width:l,height:l,padding:q,background:`linear-gradient(135deg, ${o.rim[0]} 0%, ${o.ring} 42%, ${o.rim[1]} 100%)`,boxShadow:d||t==="md"||t==="xl"||t==="lg"?"0 0 0 1px rgba(10, 15, 12, 0.06), 0 1px 2px rgba(10, 15, 12, 0.08)":void 0},children:H?i.jsx("img",{src:s.art,alt:"",draggable:!1,loading:"lazy",onError:()=>C(!0),className:"h-full w-full rounded-full object-cover",style:h?{filter:"grayscale(1)",opacity:.55}:void 0}):i.jsx("span",{className:"flex h-full w-full items-center justify-center rounded-full",style:{background:`linear-gradient(145deg, ${o.face[0]}, ${o.face[1]})`},children:p?i.jsx(p,{size:d?64:Math.round(l*.5),color:o.glyph,strokeWidth:2}):null})})}export{le as A,j as B,K as H,J as T,ee as a,de as b,E as c,re as d,ie as h,ae as p,Q as s,se as t};
@@ -1,2 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/BadgeDetailModal-B-XMJAvL.js","assets/__vite-browser-external-DUJeOWgd.js","assets/__vite-browser-external-DFRX9dp-.css","assets/react-B7SkZTgg.js","assets/AchievementBadge-BaqdyZaV.js","assets/zap-DvX2aYx5.js","assets/flame-CKjAluj_.js","assets/shield-check-YcmLwVZ6.js","assets/use-transform-BHwEAfmO.js","assets/use-reduced-motion-iDZEUyua.js","assets/AchievementsSection-CDUUEfIi.js","assets/format-tokens-mk49THtv.js","assets/DialogTitle-B1iNGD2S.js","assets/composite-B4Z3F65o.js","assets/store-C9yWYHfg.js"])))=>i.map(i=>d[i]);
2
- import{r as l,a3 as h,a4 as f,a5 as p,j as e,c,L as v,a6 as g,a as y,a7 as b,a8 as k,a9 as j}from"./__vite-browser-external-DUJeOWgd.js";import{A as w}from"./AchievementsSection-CDUUEfIi.js";import{B as x}from"./AchievementBadge-BaqdyZaV.js";import"./react-B7SkZTgg.js";import"./format-tokens-mk49THtv.js";import"./use-reduced-motion-iDZEUyua.js";import"./zap-DvX2aYx5.js";import"./flame-CKjAluj_.js";import"./shield-check-YcmLwVZ6.js";function N({enabled:a=!0}={}){const[r,t]=l.useState({status:"loading",achievements:[],error:null}),s=l.useMemo(()=>h(),[]);return l.useEffect(()=>{if(!a){t({status:"disabled",achievements:[],error:null});return}let i=!1;return t(n=>({...n,status:"loading"})),f({timeZone:s,tzOffsetMinutes:p()}).then(n=>{i||t({status:"ready",achievements:Array.isArray(n?.achievements)?n.achievements:[],error:null})}).catch(n=>{i||t({status:"error",achievements:[],error:n})}),()=>{i=!0}},[a,s]),r}const A=g.lazy(()=>j(()=>import("./BadgeDetailModal-B-XMJAvL.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14])));function I({authLoading:a,authEnabled:r,authUserId:t,mockEnabled:s}){if(s)return{authLoading:!1,signedIn:!0,userId:"mock-user"};const i=!!(r&&t);return{authLoading:!!a,signedIn:i,userId:i?t:null}}function B(){const a=y(),[r,t]=l.useState({status:"loading",achievements:[],userId:null}),s=b(),{authLoading:i,signedIn:n,userId:o}=I({authLoading:a?.loading,authEnabled:a?.enabled,authUserId:a?.user?.id,mockEnabled:s});return l.useEffect(()=>{if(i){t({status:"loading",achievements:[],userId:null});return}if(!n){t({status:"signed-out",achievements:[],userId:null});return}let d=!1;return t({status:"loading",achievements:[],userId:o}),(async()=>{try{const u=s?null:await a.getAccessToken?.(),m=await k({accessToken:u,userId:o});if(d)return;t({status:"ready",achievements:Array.isArray(m?.badges)?m.badges:[],userId:o})}catch{d||t({status:"error",achievements:[],userId:o})}})(),()=>{d=!0}},[i,s,n,o]),{...r,signedIn:n,settled:_({authLoading:i,signedIn:n,userId:o,state:r})}}function _({authLoading:a,signedIn:r,userId:t,state:s}){return a?!1:r?s.userId===t&&(s.status==="ready"||s.status==="error"):s.status==="signed-out"}function S(){return e.jsx("div",{className:"mx-0 grid animate-pulse grid-cols-[repeat(3,max-content)] justify-between gap-y-7 sm:-mx-2 sm:grid-cols-[repeat(4,max-content)] lg:grid-cols-[repeat(5,max-content)]","aria-hidden":!0,children:Array.from({length:x.length}).map((a,r)=>e.jsxs("div",{className:"flex w-[6.75rem] flex-col items-center px-0 pb-3 pt-4 sm:w-[7.75rem]",children:[e.jsx("div",{className:"h-[108px] w-[108px] rounded-full bg-oai-gray-200 dark:bg-oai-gray-800"}),e.jsx("div",{className:"mt-3 h-3 w-16 rounded bg-oai-gray-200 dark:bg-oai-gray-800"}),e.jsx("div",{className:"mt-2 h-2 w-10 rounded bg-oai-gray-100 dark:bg-oai-gray-800/60"})]},r))})}function P(){const a=N(),r=B(),[t,s]=l.useState(null),i=a.status==="loading"||!r.settled,n=l.useMemo(()=>[...r.achievements||[],...a.achievements||[]],[r.achievements,a.achievements]),o=l.useMemo(()=>n.filter(u=>(u?.tier||0)>=1).length,[n]),d=x.length;return e.jsxs("div",{className:"flex flex-1 flex-col font-oai text-oai-black antialiased dark:text-oai-white",children:[e.jsx("main",{className:"flex-1 pb-12 pt-8 sm:pb-16 sm:pt-10",children:e.jsxs("div",{className:"mx-auto max-w-4xl px-4 sm:px-6",children:[e.jsxs("div",{className:"mb-7 flex items-baseline justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("h1",{className:"text-3xl font-semibold tracking-tight text-oai-black dark:text-white sm:text-4xl",children:c("achievements.page.title")}),e.jsx("p",{className:"mt-1.5 text-sm text-oai-gray-500 dark:text-oai-gray-400",children:c("achievements.page.local_note")})]}),!i&&e.jsxs("div",{className:"shrink-0 text-right",children:[e.jsxs("div",{className:"font-mono text-2xl font-semibold leading-none tabular-nums text-oai-black dark:text-white",children:[o,e.jsxs("span",{className:"text-oai-gray-400 dark:text-oai-gray-600",children:["/",d]})]}),e.jsx("div",{className:"mt-2 h-1 w-24 overflow-hidden rounded-full bg-oai-gray-200 dark:bg-oai-gray-800",children:e.jsx("div",{className:"h-full rounded-full bg-oai-brand-600 transition-[width] duration-500",style:{width:`${Math.round(o/d*100)}%`}})})]})]}),!r.signedIn&&!i&&e.jsxs("div",{className:"mb-6 flex flex-wrap items-center justify-between gap-x-4 gap-y-2 rounded-xl border border-oai-gray-200 bg-oai-gray-50 px-4 py-3 dark:border-oai-gray-800 dark:bg-oai-gray-900/60",children:[e.jsx("p",{className:"text-sm text-oai-gray-600 dark:text-oai-gray-300",children:c("achievements.signin.prompt")}),e.jsx(v,{to:"/login",className:"shrink-0 rounded-lg bg-oai-brand-600 px-3 py-1.5 text-sm font-medium text-white transition-colors duration-200 hover:bg-oai-brand-700 active:scale-[0.98]",children:c("achievements.signin.action")})]}),i?e.jsx(S,{}):e.jsxs(e.Fragment,{children:[e.jsx(w,{achievements:n,isOwn:!0,columns:"wide",size:"lg",animateIn:!0,onSelect:s}),e.jsxs("p",{className:"mt-10 text-center text-xs text-oai-gray-400 dark:text-oai-gray-500",children:[c("achievements.page.suggest")," ",e.jsx("a",{href:"https://github.com/xiufengsun/TokenTracker/issues",target:"_blank",rel:"noopener noreferrer",className:"underline decoration-oai-gray-300 underline-offset-2 transition-colors hover:text-oai-gray-700 hover:decoration-oai-gray-500 dark:decoration-oai-gray-600 dark:hover:text-oai-gray-300",children:c("achievements.page.suggest_link")})]})]})]})}),t&&e.jsx(g.Suspense,{fallback:null,children:e.jsx(A,{badge:t,onClose:()=>s(null)})})]})}export{_ as cloudBadgesSettled,P as default,I as resolveCloudBadgeIdentity};
@@ -1 +0,0 @@
1
- import{r as L,j as a,H as De,c as h,J as ye,X as Ie}from"./__vite-browser-external-DUJeOWgd.js";import{k as _e,V as Me,l as Ve,r as Te,n as $e,o as be,q as ve,s as Oe,t as Re,v as Be,w as Pe,x as Ke,y as Ce,z as Fe,A as Le,B as Xe,S as Ge,H as We,C as G,D as ze,E as He,e as Ue,F as Ye,m as C}from"./react-B7SkZTgg.js";import{c as je,A as Ze,p as qe,b as H,t as le,a as T,d as Je}from"./AchievementBadge-BaqdyZaV.js";import{u as Qe,a as z}from"./use-transform-BHwEAfmO.js";import{u as et}from"./use-reduced-motion-iDZEUyua.js";import{l as ce,f as ue,b as tt}from"./AchievementsSection-CDUUEfIi.js";import{D as nt,a as rt,b as at,c as st,d as it,e as ot}from"./DialogTitle-B1iNGD2S.js";import"./zap-DvX2aYx5.js";import"./flame-CKjAluj_.js";import"./shield-check-YcmLwVZ6.js";import"./format-tokens-mk49THtv.js";import"./composite-B4Z3F65o.js";import"./store-C9yWYHfg.js";const lt=(e,t,n)=>{const r=t-e;return((n-e)%r+r)%r+e};function Ne(e,t){return _e(e)?e[lt(0,e.length,t)]:e}class ct{constructor(t){this.stop=()=>this.runAll("stop"),this.animations=t.filter(Boolean)}get finished(){return Promise.all(this.animations.map(t=>t.finished))}getAll(t){return this.animations[0][t]}setAll(t,n){for(let r=0;r<this.animations.length;r++)this.animations[r][t]=n}attachTimeline(t){const n=this.animations.map(r=>r.attachTimeline(t));return()=>{n.forEach((r,s)=>{r&&r(),this.animations[s].stop()})}}get time(){return this.getAll("time")}set time(t){this.setAll("time",t)}get speed(){return this.getAll("speed")}set speed(t){this.setAll("speed",t)}get state(){return this.getAll("state")}get startTime(){return this.getAll("startTime")}get duration(){return de(this.animations,"duration")}get iterationDuration(){return de(this.animations,"iterationDuration")}runAll(t){this.animations.forEach(n=>n[t]())}play(){this.runAll("play")}pause(){this.runAll("pause")}cancel(){this.runAll("cancel")}complete(){this.runAll("complete")}}function de(e,t){let n=0;for(let r=0;r<e.length;r++){const s=e[r][t];s!==null&&s>n&&(n=s)}return n}class ut extends ct{then(t,n){return this.finished.finally(t).then(()=>{})}}function dt(e,t){return e in t}class mt extends Me{constructor(){super(...arguments),this.type="object"}readValueFromInstance(t,n){if(dt(n,t)){const r=t[n];if(typeof r=="string"||typeof r=="number")return r}}getBaseTargetFromProps(){}removeValueFromRenderState(t,n){delete n.output[t]}measureInstanceViewportBox(){return Ve()}build(t,n){Object.assign(t.output,n)}renderInstance(t,{output:n}){Object.assign(t,n)}sortInstanceNodePosition(){return 0}}function U(e){return typeof e=="object"&&!Array.isArray(e)}function ke(e,t,n,r){return e==null?[]:typeof e=="string"&&U(t)?Te(e,n,r):e instanceof NodeList?Array.from(e):Array.isArray(e)?e.filter(s=>s!=null):[e]}function ft(e,t,n){return e*(t+1)+n*t}function me(e,t,n,r){return typeof t=="number"?t:t.startsWith("-")||t.startsWith("+")?Math.max(0,e+parseFloat(t)):t==="<"?n:t.startsWith("<")?Math.max(0,n+parseFloat(t.slice(1))):r.get(t)??e}function pt(e,t,n){for(let r=0;r<e.length;r++){const s=e[r];s.at>t&&s.at<n&&(be(e,s),r--)}}function ht(e,t,n,r,s,c){pt(e,s,c);for(let i=0;i<t.length;i++)e.push({value:t[i],at:$e(s,c,r[i]),easing:Ne(n,i)})}function gt(e,t,n=0){const r=t+1+t*n;for(let s=0;s<e.length;s++)e[s]=e[s]/r}function xt(e,t){return e.at===t.at?e.value===null?1:t.value===null?-1:0:e.at-t.at}const yt="easeInOut",bt=20;function vt(e,{defaultTransition:t={},...n}={},r,s){const c=t.duration||.3,i=new Map,f=new Map,m={},p=new Map;let g=0,u=0,x=0;for(let N=0;N<e.length;N++){const k=e[N];if(typeof k=="string"){p.set(k,u);continue}else if(!Array.isArray(k)){p.set(k.name,me(u,k.at,g,p));continue}let[E,b,v={}]=k;v.at!==void 0&&(u=me(u,v.at,g,p));let j=0;const _=(w,M,A,o=0,l=0)=>{const d=jt(w),{delay:D=0,times:y=Oe(d),type:R=t.type||"keyframes",repeat:B,repeatType:W,repeatDelay:Y=0,...Se}=M;let{ease:I=t.ease||"easeOut",duration:S}=M;const Z=typeof D=="function"?D(o,l):D,q=d.length,J=Ke(R)?R:s?.[R||"keyframes"];if(q<=2&&J){let $=100;if(q===2&&wt(d)){const P=d[1]-d[0];$=Math.abs(P)}const O={...t,...Se};S!==void 0&&(O.duration=Ce(S));const X=Re(O,$,J);I=X.ease,S=X.duration}S??(S=c);const Q=u+Z;y.length===1&&y[0]===0&&(y[1]=1);const ee=y.length-d.length;if(ee>0&&Be(y,ee),d.length===1&&d.unshift(null),B&&B<bt){const $=S>0?Y/S:0;S=ft(S,B,Y);const O=[...d],X=[...y];I=Array.isArray(I)?[...I]:[I];const P=[...I],ne=W==="reverse"||W==="mirror";let re=O,ae=P;ne&&(re=[...O].reverse(),W==="reverse"&&(ae=[...P].reverse().map(V=>typeof V=="function"?Pe(V):V)));for(let V=0;V<B;V++){const se=ne&&V%2===0,ie=se?re:O,Ee=se?ae:P,oe=(V+1)*(1+$);$>0&&(d.push(d[d.length-1]),y.push(oe),I.push("linear")),d.push(...ie);for(let K=0;K<ie.length;K++)y.push(X[K]+oe),I.push(K===0?"linear":Ne(Ee,K-1))}gt(y,B,$)}const te=Q+S;ht(A,d,I,y,Q,te),j=Math.max(Z+S,j),x=Math.max(te,x)};if(ve(E)){const w=fe(E,f);_(b,v,pe("default",w))}else{const w=ke(E,b,r,m),M=w.length;for(let A=0;A<M;A++){b=b,v=v;const o=w[A],l=fe(o,f);for(const d in b)_(b[d],Nt(v,d),pe(d,l),A,M)}}g=u,u+=j}return f.forEach((N,k)=>{for(const E in N){const b=N[E];b.sort(xt);const v=[],j=[],_=[];for(let o=0;o<b.length;o++){const{at:l,value:d,easing:D}=b[o];v.push(d),j.push(Fe(0,x,l)),_.push(D||"easeOut")}j[0]!==0&&(j.unshift(0),v.unshift(v[0]),_.unshift(yt)),j[j.length-1]!==1&&(j.push(1),v.push(null)),i.has(k)||i.set(k,{keyframes:{},transition:{}});const w=i.get(k);w.keyframes[E]=v;const{type:M,...A}=t;w.transition[E]={...A,duration:x,ease:_,times:j,...n}}}),i}function fe(e,t){return!t.has(e)&&t.set(e,{}),t.get(e)}function pe(e,t){return t[e]||(t[e]=[]),t[e]}function jt(e){return Array.isArray(e)?e:[e]}function Nt(e,t){return e&&e[t]?{...e,...e[t]}:{...e}}const kt=e=>typeof e=="number",wt=e=>e.every(kt);function At(e){const t={presenceContext:null,props:{},visualState:{renderState:{transform:{},transformOrigin:{},style:{},vars:{},attrs:{}},latestValues:{}}},n=Le(e)&&!Xe(e)?new Ge(t):new We(t);n.mount(e),G.set(e,n)}function St(e){const t={presenceContext:null,props:{},visualState:{renderState:{output:{}},latestValues:{}}},n=new mt(t);n.mount(e),G.set(e,n)}function Et(e,t){return ve(e)||typeof e=="number"||typeof e=="string"&&!U(t)}function we(e,t,n,r){const s=[];if(Et(e,t))s.push(ze(e,U(t)&&t.default||t,n&&(n.default||n)));else{if(e==null)return s;const c=ke(e,t,r),i=c.length;for(let f=0;f<i;f++){const m=c[f],p=m instanceof Element?At:St;G.has(m)||p(m);const g=G.get(m),u={...n};"delay"in u&&typeof u.delay=="function"&&(u.delay=u.delay(f,i)),s.push(...He(g,{...t,transition:u},{}))}}return s}function Dt(e,t,n){const r=[],s=e.map(i=>{if(Array.isArray(i)&&typeof i[0]=="function"){const f=i[0],m=Ue(0);return m.on("change",f),i.length===1?[m,[0,1]]:i.length===2?[m,[0,1],i[1]]:[m,i[1],i[2]]}return i});return vt(s,t,n,{spring:Ye}).forEach(({keyframes:i,transition:f},m)=>{r.push(...we(m,i,f))}),r}function It(e){return Array.isArray(e)&&e.some(Array.isArray)}function _t(e={}){const{scope:t,reduceMotion:n,skipAnimations:r}=e;function s(c,i,f){let m=[],p;const g={};if(n!==void 0&&(g.reduceMotion=n),r!==void 0&&(g.skipAnimations=r),It(c)){const{onComplete:x,...N}=i||{};typeof x=="function"&&(p=x),m=Dt(c,{...g,...N},t)}else{const{onComplete:x,...N}=f||{};typeof x=="function"&&(p=x),m=we(c,i,{...g,...N},t)}const u=new ut(m);return p&&u.finished.then(p),t&&(t.animations.push(u),u.finished.then(()=>{be(t.animations,u)})),u}return s}const F=_t(),he=8;function Mt({badgeId:e,tier:t,locked:n=!1,size:r=176,backLines:s=[],label:c}){const i=Qe(0),f=et(),m=L.useRef(null),p=L.useRef(null),g=L.useRef(!1),u=qe(t,n),x=je.get(e)?.icon||null,N=z(i,o=>`${(o%360+360)%360/360*160-80}%`),k=z(i,o=>`${80-(o%360+360)%360/360*160}%`),E=z(i,o=>{const l=Math.abs(Math.sin(o*Math.PI/180));return Math.max(0,(l-.35)/.65)*.3}),b=()=>{p.current?.stop?.(),p.current=null};L.useEffect(()=>{if(f||g.current)return;let o=!1;i.set(-360);const l=F(i,0,{duration:.9,ease:[.16,1,.3,1]});return p.current=l,l.then(()=>{o||g.current||(p.current=F(i,[0,-14,14,0],{duration:4.5,repeat:1/0,ease:"easeInOut"}))}),()=>{o=!0,b()}},[f,i]);const v=o=>{const l=i.get();if(f){const y=Math.round(l/180)*180;p.current=F(i,y,{duration:.2,ease:"easeOut"});return}const d=l+o*.35,D=Math.round(d/180)*180;p.current=F(i,D,{type:"spring",velocity:o,stiffness:58,damping:13.5,mass:1})},j=o=>{g.current=!0,b(),o.currentTarget.setPointerCapture?.(o.pointerId),m.current={pointerId:o.pointerId,startX:o.clientX,startRot:i.get(),samples:[{t:o.timeStamp,x:o.clientX}]}},_=o=>{const l=m.current;!l||l.pointerId!==o.pointerId||(i.set(l.startRot+(o.clientX-l.startX)*.55),l.samples.push({t:o.timeStamp,x:o.clientX}),l.samples.length>5&&l.samples.shift())},w=o=>{const l=m.current;if(!l||l.pointerId!==o.pointerId)return;m.current=null;const d=l.samples[0],D=l.samples[l.samples.length-1],y=D.t-d.t,R=y>0?(D.x-d.x)*.55*1e3/y:0;v(R)},M=o=>{if(o.key!=="ArrowLeft"&&o.key!=="ArrowRight")return;o.preventDefault(),g.current=!0,b();const l=o.key==="ArrowRight"?30:-30;p.current=F(i,i.get()+l,{duration:.15,ease:"easeOut"})},A={backfaceVisibility:"hidden",WebkitBackfaceVisibility:"hidden"};return a.jsx("div",{role:"img","aria-label":c,tabIndex:0,onPointerDown:j,onPointerMove:_,onPointerUp:w,onPointerCancel:w,onKeyDown:M,className:"inline-flex cursor-grab select-none items-center justify-center outline-none focus-visible:ring-2 focus-visible:ring-oai-brand/60 rounded-full active:cursor-grabbing",style:{perspective:900,touchAction:"pan-y"},children:a.jsxs("div",{className:"relative",style:{transform:"rotateX(-8deg)",transformStyle:"preserve-3d"},children:[a.jsxs(C.div,{className:"relative",style:{rotateY:i,transformStyle:"preserve-3d",width:r,height:r},children:[[-3,-1.5,0,1.5,3].map(o=>a.jsx("div",{"aria-hidden":!0,className:"absolute inset-0 rounded-full",style:{transform:`translateZ(${o}px)`,background:u.rim[1]}},o)),a.jsxs("div",{className:"absolute inset-0 overflow-hidden rounded-full",style:{...A,transform:`translateZ(${he/2}px)`},children:[a.jsx(Ze,{badgeId:e,tier:t,locked:n,size:"fill",className:"brightness-105 saturate-[1.08]"}),a.jsx("div",{"aria-hidden":!0,className:"pointer-events-none absolute inset-0 rounded-full",style:{background:"radial-gradient(circle at 30% 20%, rgba(255,255,255,0.45), rgba(255,255,255,0) 42%), linear-gradient(172deg, rgba(255,255,255,0.14) 0%, rgba(255,255,255,0) 38%, rgba(0,0,0,0.08) 100%)",boxShadow:"inset 0 3px 7px rgba(255,255,255,0.5), inset 0 -3px 8px rgba(0,0,0,0.15)"}}),a.jsx(C.div,{"aria-hidden":!0,className:"pointer-events-none absolute inset-0",style:{x:N,background:"linear-gradient(105deg, transparent 34%, rgba(255,255,255,0.5) 50%, transparent 66%)"}}),a.jsx(C.div,{"aria-hidden":!0,className:"pointer-events-none absolute inset-0 rounded-full",style:{opacity:E,background:"rgba(8, 12, 10, 0.9)"}})]}),a.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center gap-1 overflow-hidden rounded-full px-6 text-center",style:{...A,transform:`rotateY(180deg) translateZ(${he/2}px)`,background:`linear-gradient(145deg, ${u.face[0]}, ${u.face[1]})`,boxShadow:`inset 0 0 0 6px ${u.rim[1]}, inset 0 0 0 7.5px rgba(255,255,255,0.22), inset 0 3px 7px rgba(255,255,255,0.4), inset 0 -4px 12px rgba(0,0,0,0.22)`},children:[a.jsx("div",{"aria-hidden":!0,className:"pointer-events-none absolute inset-0 rounded-full",style:{background:"repeating-radial-gradient(circle at 50% 50%, rgba(255,255,255,0.06) 0px, rgba(255,255,255,0.06) 1px, transparent 1px, transparent 4px)"}}),x?a.jsx(x,{"aria-hidden":!0,size:Math.round(r*.62),strokeWidth:1.1,color:u.glyph,className:"pointer-events-none absolute opacity-[0.13]",style:{filter:"drop-shadow(0 1px 0 rgba(255,255,255,0.3)) drop-shadow(0 -1px 0 rgba(0,0,0,0.35))"}}):null,a.jsx("div",{"aria-hidden":!0,className:"pointer-events-none absolute inset-0 rounded-full",style:{background:"radial-gradient(circle at 70% 20%, rgba(255,255,255,0.4), rgba(255,255,255,0) 44%), linear-gradient(188deg, rgba(255,255,255,0.12) 0%, rgba(255,255,255,0) 38%, rgba(0,0,0,0.10) 100%)"}}),s.map((o,l)=>a.jsx("div",{className:`font-mono tabular-nums ${l===0?"text-[10px] uppercase tracking-[0.18em]":l===1?"text-lg font-bold":"text-[11px]"}`,style:{color:u.glyph,textShadow:"0 1px 0 rgba(255,255,255,0.28), 0 -1px 0 rgba(0,0,0,0.3)"},children:o},`${l}-${o}`)),a.jsx(C.div,{"aria-hidden":!0,className:"pointer-events-none absolute inset-0",style:{x:k,background:"linear-gradient(105deg, transparent 34%, rgba(255,255,255,0.45) 50%, transparent 66%)"}}),a.jsx(C.div,{"aria-hidden":!0,className:"pointer-events-none absolute inset-0 rounded-full",style:{opacity:E,background:"rgba(8, 12, 10, 0.9)"}})]})]}),a.jsx("div",{"aria-hidden":!0,className:"absolute left-1/2 h-3 w-3/5 rounded-[100%] bg-black/20 blur-md dark:bg-black/45",style:{bottom:-20,transform:"translateX(-50%)"}})]})})}function Ae(e){if(!e)return null;const t=Date.parse(e);return Number.isFinite(t)?new Date(t).toLocaleDateString():null}function Vt(e){const t=Number(e);return!Number.isSafeInteger(t)||t<1?null:String(t).padStart(6,"0")}function Tt(e,t,n){if(t?.scope!=="cloud"||!n)return null;const r=Number(e?.serials?.[n]);return Number.isSafeInteger(r)&&r>=1?r:null}function $t({badge:e}){return a.jsx("div",{className:"flex items-center gap-1",children:Je.map((t,n)=>{const r=(e.tier||0)>=n+1,s=Ae(e.achieved?.[t]),c=T[t];return a.jsx("span",{title:s?`${h(`achievements.tier.${t}`)} · ${s}`:h(`achievements.tier.${t}`),className:"inline-flex h-2 w-8 rounded-full",style:r?{background:`linear-gradient(120deg, ${c.rim[0]} 0%, ${c.ring} 55%, ${c.rim[1]} 100%)`,boxShadow:"inset 0 1px 1px rgba(255,255,255,0.4), 0 0 0 1px rgba(10,15,12,0.05)"}:void 0,children:!r&&a.jsx("span",{className:"h-full w-full rounded-full bg-oai-gray-200 dark:bg-oai-gray-800"})},t)})})}function ge({badge:e,onClose:t}){const n=je.get(e.id),r=h(H(e.id,"name")),s=(e.tier||0)>=1,c=s?le(e.tier):null,i=Ae(s?e.achieved?.[c]||(ce(e)?new Date(ce(e)).toISOString():null):null),f=ue(n?.format,e.metric_value),m=tt(e),p=e.tier<4?le((e.tier||0)+1):null,g=Tt(e,n,c),u=Vt(g),x=u?[h("achievements.modal.achieved_label"),h("achievements.modal.issue_number",{number:u}),i||r]:[s?h("achievements.modal.achieved_label"):h("achievements.modal.locked"),s?f:"···",s&&i?i:r];return a.jsxs("div",{className:"flex flex-col items-center px-6 pb-6 pt-5 text-center",children:[a.jsxs("div",{className:"flex w-full items-start justify-between gap-3",children:[a.jsxs("div",{className:"min-w-0 flex-1 text-left",children:[a.jsx("h2",{className:"truncate text-lg font-semibold tracking-tight text-oai-black dark:text-white",children:r}),a.jsx("p",{className:"mt-0.5 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:h(H(e.id,"desc"))})]}),a.jsx("button",{type:"button",onClick:t,"aria-label":h("achievements.modal.close"),className:"shrink-0 rounded-md p-1.5 text-oai-gray-400 transition-colors hover:bg-oai-gray-100 hover:text-oai-gray-700 dark:hover:bg-oai-gray-900 dark:hover:text-oai-gray-200",children:a.jsx(Ie,{size:16})})]}),a.jsx("div",{className:"mt-5 mb-7",children:a.jsx(Mt,{badgeId:e.id,tier:e.tier,locked:!s,backLines:x,label:h("achievements.modal.coin_aria",{name:r})})}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("span",{className:"rounded-full px-2.5 py-0.5 text-[11px] font-semibold uppercase tracking-wide",style:s?{background:`linear-gradient(120deg, ${T[c].rim[0]} 0%, ${T[c].ring} 55%, ${T[c].rim[1]} 100%)`,color:T[c].glyph,textShadow:"0 1px 0 rgba(255,255,255,0.35)",boxShadow:"inset 0 1px 1px rgba(255,255,255,0.4), 0 0 0 1px rgba(10,15,12,0.06)"}:{background:"rgba(128,134,130,0.75)",color:"rgba(250,250,250,0.95)"},children:s?h(`achievements.tier.${c}`):h("achievements.modal.locked")}),s&&i?a.jsx("span",{className:"text-xs tabular-nums text-oai-gray-500 dark:text-oai-gray-400",children:i}):null]}),a.jsxs("dl",{className:"mt-5 w-full space-y-3 border-t border-oai-gray-200/70 pt-4 text-left dark:border-oai-gray-800/60",children:[a.jsxs("div",{className:"flex items-baseline justify-between gap-3 text-sm",children:[a.jsx("dt",{className:"text-oai-gray-500 dark:text-oai-gray-400",children:h("achievements.modal.value_label")}),a.jsx("dd",{className:"font-mono font-semibold tabular-nums text-oai-black dark:text-white",children:f})]}),a.jsxs("div",{children:[a.jsxs("div",{className:"flex items-baseline justify-between gap-3 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:[a.jsx("span",{children:e.tier>=4?h("achievements.modal.max_tier"):h("achievements.modal.progress_to_next",{tier:h(`achievements.tier.${p}`)})}),e.tier<4&&e.next_threshold!=null?a.jsxs("span",{className:"font-mono tabular-nums",children:[f," ",e.lower_is_better?"→":"/"," ",ue(n?.format,e.next_threshold)]}):null]}),a.jsx("div",{className:"mt-1.5 h-1.5 w-full overflow-hidden rounded-full bg-oai-gray-200 dark:bg-oai-gray-800",children:a.jsx("div",{className:"h-full rounded-full transition-[width] duration-500",style:{width:`${Math.round((e.tier>=4?1:m)*100)}%`,background:s?`linear-gradient(90deg, ${T[c].rim[0]} 0%, ${T[c].ring} 55%, ${T[c].rim[1]} 100%)`:"rgba(128,134,130,0.75)",boxShadow:s?"inset 0 1px 1px rgba(255,255,255,0.35)":void 0}})})]}),a.jsxs("div",{className:"flex items-center justify-between gap-3 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:[a.jsx("span",{children:h("achievements.modal.tier_history")}),a.jsx($t,{badge:e})]})]})]})}const xe=ye("relative w-full max-w-[380px] flex flex-col","rounded-2xl bg-white dark:bg-oai-gray-950","shadow-[0_20px_60px_-20px_rgba(0,0,0,0.25)] dark:shadow-[0_20px_60px_-10px_rgba(0,0,0,0.65)]","ring-1 ring-oai-gray-200 dark:ring-oai-gray-800 overflow-hidden","dark:border-t dark:border-white/[0.08]");function Ut({badge:e,onClose:t}){const n=De(),r=!!e;return L.useEffect(()=>{if(!n||!r)return;const s=c=>{c.key==="Escape"&&(c.stopPropagation(),t?.())};return window.addEventListener("keydown",s,!0),()=>window.removeEventListener("keydown",s,!0)},[n,r,t]),r?n?a.jsxs("div",{className:"fixed inset-0 z-[120] flex items-center justify-center p-4",children:[a.jsx("div",{className:"absolute inset-0 bg-black/40 backdrop-blur-[2px]",onClick:t,"aria-hidden":!0}),a.jsx("div",{className:xe,children:a.jsx(ge,{badge:e,onClose:t})})]}):a.jsx(nt,{open:!0,onOpenChange:s=>{s||t?.()},children:a.jsxs(rt,{children:[a.jsx(at,{className:"cost-modal-backdrop z-[110]"}),a.jsx(st,{className:"fixed inset-0 z-[120] flex items-center justify-center p-4",children:a.jsxs(it,{className:ye("cost-modal-popup",xe),children:[a.jsx(ot,{render:a.jsx("h2",{className:"sr-only"}),children:h(H(e.id,"name"))}),a.jsx(ge,{badge:e,onClose:t})]})})]})}):null}export{Ut as BadgeDetailModal,Tt as currentBadgeIssueNumber,Ut as default,Vt as formatIssueNumber};
@@ -1 +0,0 @@
1
- import{j as r,J as e}from"./__vite-browser-external-DUJeOWgd.js";function n({children:i,title:a,subtitle:o,className:s="",bodyClassName:d=""}){return r.jsxs("div",{className:e("rounded-xl border border-oai-gray-200 dark:border-oai-gray-800 bg-white dark:bg-oai-gray-900 transition-colors duration-200",s),children:[(a||o)&&r.jsxs("div",{className:"px-5 py-4 border-b border-oai-gray-200 dark:border-oai-gray-800 transition-colors duration-200",children:[a&&r.jsx("h3",{className:"text-sm font-medium text-oai-gray-500 dark:text-oai-gray-300 uppercase tracking-wide transition-colors duration-200",children:a}),o&&r.jsx("p",{className:"text-sm text-oai-gray-500 dark:text-oai-gray-300 mt-1 transition-colors duration-200",children:o})]}),r.jsx("div",{className:`p-5 ${d}`,children:i})]})}export{n as C};
@@ -1 +0,0 @@
1
- import{A as Be,d as De,e as Te,r as o,o as Ue,p as $e,t as ze,G as Me,H as He,E as Fe,ab as U,c as t,j as e,B as l,L as u,x as te,z as p,v as ge,ac as Ge,ad as We,S as Je,C as Ke,y as Qe}from"./__vite-browser-external-DUJeOWgd.js";import{c as G,r as fe,C as _e,a as Ve,g as Xe,s as ye,b as Ye,o as Ze}from"./cloud-checkout-nYNHDFoR.js";import{d as et}from"./os-DMmhX9tk.js";import{C as ke}from"./Card-D-5mABVt.js";import{L as tt}from"./loader-circle-CNT630zn.js";import{S as rt}from"./shield-check-YcmLwVZ6.js";import{E as at}from"./external-link-B5yXxdPy.js";import{A as st}from"./arrow-left-BEM-HVmC.js";const ve={name:"circle-check",size:24,node:[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m16 9-5.5 5.5L8 12",key:"xofnsj"}]],aliases:["check-circle-2"]};ve.node;const ct=Be(ve);function xt(){const be=De(),[g,$]=Te();o.useEffect(()=>{if(!g.has("_ptxn"))return;const s=new URLSearchParams(g);s.delete("_ptxn"),$(s,{replace:!0})},[g,$]);const{catalog:m,loading:I,error:j,refresh:je}=Ue(),{account:f,auth:S,refresh:z}=$e(),n=g.get("order")||"",v=g.get("intent")==="trial",we=g.get("sku"),[re,M]=o.useState(null),[_,ae]=o.useState(!1),[W,J]=o.useState(!!n),[se,L]=o.useState(null),[ce,Ne]=o.useState(null),[K,Q]=o.useState(null),[Ce,ne]=o.useState(!1),V=o.useRef(!1),q=o.useRef(0),X=o.useRef(null),y=o.useRef(!0),r=S?.signedIn?S.user?.id:null,ie=o.useRef(n);ie.current=n;const k=o.useRef(r);k.current=r;const oe=re?.ownerId===r?re:null,le=ce?.ownerId===r?ce:null,Re=K?.ownerId===r&&K?.orderId===n?K.error:null,h=se||Re,a=oe?.order,A=le||oe?.membership||f?.membership,P=m?.policy?.hosting_mode==="self_hosted"||A?.status==="self_hosted",O=a?.sku||we,w=m?.prices?.find(s=>s.sku===O),B=a?.currency||w?.currency,Y=a?.amount_cents??w?.amount_cents,N=a?.billing_mode||w?.billing_mode,de=a?.term_months||w?.term_months,H=a?.provider||"waffo",i=le?"trial_success":_&&!a?"creating":G(a,A),b=ze(m),F=!!m?.providers?.[H],D=!!(a?.retry_payment_conflict_at||[...f?.conflict_orders||[],...f?.pending_orders||[]].some(s=>s.retry_payment_conflict_at)),ue=A?.has_gift===!0||f?.membership?.has_gift===!0||f?.gifts?.some(s=>["active","pending"].includes(s.state)),Ee=a?.provider==="waffo"&&a.payment_state==="unpaid"&&a.status!=="paid"&&["awaiting","expired","canceled"].includes(i)&&b&&F&&!D&&!ue,C=S?.getAccessToken,d=fe(r),me=`/login?next=${encodeURIComponent(`/billing/checkout?${g}`)}`,he=m?.environment==="live"&&!v&&g.getAll("order").length===1&&_e.test(n)&&["mac","windows"].includes(et())&&!(navigator.platform==="MacIntel"&&navigator.maxTouchPoints>1)&&!Me()&&!He()&&!Fe()?`tokentracker://billing/return?order=${n.toLowerCase()}`:null;o.useEffect(()=>(y.current=!0,()=>{y.current=!1}),[]);const R=o.useCallback(async()=>{if(P||!n||!r||k.current!==r)return null;if(!_e.test(n))return L({code:"order_not_found"}),J(!1),null;const s=++q.current;try{const c=await U("order",{auth:C,params:{id:n}});if(s!==q.current||k.current!==r)return null;M({...c,ownerId:r}),L(null);const ee=G(c.order,c.membership);if(ee==="success"&&Q(null),["success","refunded"].includes(ee)){const E=`${r}:${n}:${ee}`;X.current!==E&&(X.current=E,z())}if(["success","expired","canceled","refunded"].includes(G(c.order,c.membership))){const E=fe(r),Oe=c.order.payment_state==="unpaid"&&c.order.status!=="paid"&&["expired","canceled"].includes(G(c.order,c.membership))&&E?.retry_order_id===n&&E?.retry_request_id;E?.order_id===n&&!Oe&&Ve(r)}return c}catch(c){return s===q.current&&L(c),null}finally{s===q.current&&J(!1)}},[n,r,C,P,z]);o.useEffect(()=>(M(null),L(null),X.current=null,J(!!(n&&r)),R(),()=>{q.current+=1}),[R,n,r]),o.useEffect(()=>{if(P||!n||!r||["success","canceled","expired","refunded"].includes(i))return;const s=()=>{document.visibilityState==="visible"&&R()},c=window.setInterval(s,5e3);return window.addEventListener("focus",s),document.addEventListener("visibilitychange",s),()=>{window.clearInterval(c),window.removeEventListener("focus",s),document.removeEventListener("visibilitychange",s)}},[n,r,i,R,P]);const T=async s=>{if(!V.current){V.current=!0,ae(!0),L(null),Q(null);try{await s()}catch(c){y.current&&k.current===r&&Q({ownerId:r,orderId:n,error:c})}finally{V.current=!1,ae(!1)}}},Ie=()=>T(async()=>{const s=Xe(r,O,H),c=await U("checkout",{auth:C,body:{sku:O,provider:H,request_id:s.request_id,mobile:window.matchMedia("(max-width: 640px)").matches}});ye(r,{...s,order_id:c.order.id}),!(!y.current||k.current!==r)&&(M({...c,ownerId:r,order:{...w,provider:H,...c.order}}),$({order:c.order.id},{replace:!0}))}),Se=()=>T(async()=>{const s=await U("trial",{auth:C,body:{}});!y.current||k.current!==r||(Ne({...s.membership,ownerId:r}),z())}),xe=()=>T(async()=>{await U("reconcile",{auth:C,body:{id:n}}),!(!y.current||k.current!==r)&&(await R(),await z())}),Le=()=>T(async()=>{const s=Ye(r,a);ne(!0);try{const c=await U("restart-checkout",{auth:C,body:{id:a.id,request_id:s.retry_request_id}});if(ye(r,{sku:a.sku,provider:a.provider,request_id:s.retry_request_id,order_id:c.order.id}),!y.current||k.current!==r||ie.current!==a.id)return;M({...c,ownerId:r}),$({order:c.order.id},{replace:!0})}finally{y.current&&ne(!1)}}),qe=()=>T(async()=>{await Ze(a.checkout_url)}),Z=m?.limits?.trial_days||7,Ae=new Date(Date.now()+Z*864e5).toISOString(),pe=v?t("cloud.checkout.starting_trial"):t("cloud.checkout.creating"),Pe={review:v?t("cloud.checkout.trial_title"):t("cloud.checkout.title"),creating:pe,awaiting:t("cloud.checkout.awaiting"),activating:t("cloud.checkout.activating"),success:t("cloud.checkout.success"),canceled:t("cloud.checkout.canceled"),expired:a?.status==="paid"?t("cloud.checkout.term_ended"):t("cloud.checkout.expired"),refunded:t("cloud.checkout.refunded"),trial_success:t("cloud.checkout.trial_success")};let x=null;if(!r)x=e.jsxs("div",{className:"space-y-5",children:[e.jsx("p",{className:"text-sm leading-6 text-oai-gray-500 dark:text-oai-gray-400",children:t("cloud.checkout.sign_in")}),e.jsx(l,{as:u,to:me,className:"w-full no-underline",disabled:S?.loading,children:t("cloud.action.sign_in_continue")})]});else if(W||_&&!a)x=e.jsxs("p",{role:"status",className:"flex items-center gap-2 text-sm",children:[e.jsx(tt,{className:"motion-safe:animate-spin",size:17,"aria-hidden":!0}),W?t("cloud.checkout.loading"):pe]});else if(i==="trial_success"||i==="success")x=e.jsxs("div",{className:"space-y-5",children:[e.jsx(ct,{size:32,className:"text-oai-gray-700 dark:text-oai-gray-200","aria-hidden":!0}),e.jsx("p",{className:"text-sm leading-6",children:i==="trial_success"?t("cloud.trial.ends",{date:te(A.trial_ends_at)}):t("cloud.membership.expires",{date:te(A.expires_at)})}),e.jsx(l,{as:u,to:"/dashboard",className:"w-full no-underline",children:t("cloud.action.open_dashboard")}),e.jsx(u,{to:"/settings?section=account",className:"flex min-h-10 items-center justify-center text-sm underline underline-offset-4",children:t("cloud.action.manage_membership")})]});else if(i==="review"&&!n&&ue)x=e.jsxs("div",{className:"space-y-5",children:[e.jsx(p,{children:t("cloud.gift.error_active")}),e.jsx(l,{as:u,to:"/settings?section=account",variant:"secondary",className:"w-full no-underline",children:t("cloud.action.manage_membership")})]});else if(i==="review"&&!n&&v)x=e.jsxs("div",{className:"space-y-5",children:[e.jsx("p",{className:"text-sm leading-6",children:t("cloud.trial.disclosure",{days:Z,date:te(Ae)})}),e.jsx("p",{className:"text-sm leading-6 text-oai-gray-500 dark:text-oai-gray-400",children:t("cloud.trial.expiry")}),f?.membership&&!f.membership.trial_available?e.jsx(p,{children:t("cloud.error.trial")}):null,e.jsx(l,{onClick:Se,disabled:_||!b||!f?.membership?.trial_available,className:"w-full",children:t("cloud.action.start_trial",{days:Z})})]});else if(i==="review"&&!n&&w)x=e.jsxs("div",{className:"space-y-5",children:[e.jsx("p",{className:"text-sm leading-6",children:t("cloud.checkout.review")}),e.jsxs("p",{className:"inline-flex items-center gap-2 text-sm",children:[e.jsx(rt,{size:16,"aria-hidden":!0}),t("cloud.checkout.waffo")]}),N?e.jsx("p",{className:"text-sm leading-6 text-oai-gray-500 dark:text-oai-gray-400",children:N==="fixed"?t("cloud.checkout.methods_fixed"):t("cloud.checkout.methods_recurring")}):null,N?e.jsx("p",{className:"text-sm leading-6 text-oai-gray-500 dark:text-oai-gray-400",children:N==="fixed"?t("cloud.renewal.manual"):t("cloud.renewal.auto")}):null,d?.order_id?e.jsx(l,{as:u,to:`/billing/checkout?order=${encodeURIComponent(d.order_id)}`,className:"w-full no-underline",children:t("cloud.action.resume_order")}):null,d?.request_id&&!d.order_id&&d.sku!==O?e.jsx(l,{as:u,to:`/billing/checkout?sku=${encodeURIComponent(d.sku)}`,className:"w-full no-underline",children:t("cloud.action.resume_purchase")}):null,!d?.order_id&&!(d?.request_id&&d.sku!==O)?e.jsx(l,{onClick:Ie,disabled:_||!b||!F||!N||!!d?.order_id||D,className:"w-full",children:t("cloud.action.create_checkout",{amount:ge(Y,B)})}):null]});else if(a){const s={creating:t("cloud.checkout.pending_creation"),awaiting:t("cloud.checkout.pending_payment"),activating:t("cloud.checkout.received"),expired:a?.status==="paid"?t("cloud.checkout.term_ended_detail"):t("cloud.checkout.expired_detail"),canceled:t("cloud.checkout.canceled_detail"),refunded:t("cloud.checkout.refunded_detail")};x=e.jsxs("div",{className:"space-y-5",children:[e.jsx("p",{className:"text-sm leading-6 text-oai-gray-500 dark:text-oai-gray-400",children:s[i]}),i==="awaiting"&&a.checkout_url&&b&&F&&!D?e.jsxs(l,{onClick:qe,disabled:_,className:"w-full",children:[t("cloud.action.open_payment"),e.jsx(at,{size:15,className:"ml-2","aria-hidden":!0})]}):null,i!=="refunded"?e.jsxs(e.Fragment,{children:[e.jsx(l,{onClick:xe,disabled:_,variant:"ghost",className:"mx-auto flex underline underline-offset-4",children:_?t("cloud.action.checking"):t("cloud.action.check_payment")}),e.jsx("p",{className:"text-xs leading-5 text-oai-gray-500 dark:text-oai-gray-400",children:t("cloud.checkout.recovery_hint")})]}):null,Ee?e.jsxs("details",{open:i!=="awaiting",className:"border-t border-oai-gray-200 pt-4 dark:border-oai-gray-800",children:[e.jsx("summary",{className:"min-h-10 cursor-pointer text-sm font-medium leading-10 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2",children:t("cloud.checkout.help_title")}),e.jsxs("div",{className:"space-y-3 pt-2",children:[e.jsx("p",{className:"text-xs leading-5 text-oai-gray-500 dark:text-oai-gray-400",children:t("cloud.checkout.restart_detail")}),e.jsx(l,{onClick:Le,disabled:_,variant:i==="awaiting"?"secondary":"primary",className:"w-full",children:Ce?t("cloud.action.restarting_checkout"):t("cloud.action.restart_checkout")})]})]}):null,["canceled","expired"].includes(i)&&!D?e.jsx(u,{to:"/cloud",className:"flex min-h-10 items-center justify-center text-sm underline underline-offset-4",children:a.status==="paid"?t("cloud.action.renew"):t("cloud.action.choose_plan")}):null,i==="refunded"?e.jsx(l,{as:u,to:"/settings?section=account",className:"w-full no-underline",children:t("cloud.action.manage_membership")}):null,e.jsxs("details",{className:"border-t border-oai-gray-200 pt-4 dark:border-oai-gray-800",children:[e.jsxs("summary",{className:"min-h-10 cursor-pointer text-xs leading-10 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2",children:[t("cloud.checkout.order_id")," · ",a.id.slice(0,8)]}),e.jsx("p",{className:"mb-2 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:Ge(a.provider)}),e.jsx("p",{className:"text-xs text-oai-gray-500 dark:text-oai-gray-400",children:t("cloud.checkout.order_id")}),e.jsx("p",{className:"mt-1 break-all font-mono text-xs select-all",children:a.id}),a.status!=="paid"&&a.expires_at?e.jsx("p",{className:"mt-2 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:t("cloud.checkout.expires",{date:We(a.expires_at)})}):null]})]})}else x=e.jsx(p,{children:n?t("cloud.error.order_not_found"):t("cloud.checkout.choose_plan")});return P?e.jsx(Je,{}):e.jsx("div",{className:"tt-cloud-theme flex flex-1 flex-col font-oai text-oai-black dark:text-oai-white",children:e.jsxs("main",{className:"mx-auto w-full max-w-4xl px-4 py-8 sm:px-6 sm:py-12",children:[e.jsxs(u,{to:"/cloud",className:"mb-7 inline-flex min-h-10 items-center gap-2 text-sm text-oai-gray-500 dark:text-oai-gray-400 hover:text-oai-brand focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand",children:[e.jsx(st,{size:16,"aria-hidden":!0}),t("cloud.checkout.back")]}),e.jsx("h1",{className:"text-3xl font-semibold tracking-tight","aria-live":"polite",children:W?t("cloud.checkout.loading"):Pe[i]}),e.jsx("p",{className:"mt-3 text-sm leading-6 text-oai-gray-500 dark:text-oai-gray-400",children:t("cloud.checkout.local_free")}),m?.environment==="sandbox"&&!v?e.jsx("p",{className:"mt-2 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:t("cloud.price.draft")}):null,D?e.jsx("div",{className:"mt-5",children:e.jsx(Ke,{})}):null,e.jsxs("div",{className:"mt-7 grid items-start gap-5 md:grid-cols-[minmax(0,1fr)_18rem]",children:[e.jsxs(ke,{bodyClassName:"sm:p-7",children:[x,he?e.jsxs("div",{className:"mt-5 space-y-3 border-t border-oai-gray-200 pt-5 dark:border-oai-gray-800",children:[e.jsx("p",{className:"text-sm leading-6 text-oai-gray-500 dark:text-oai-gray-400",children:t("cloud.checkout.return_app_hint")}),e.jsx("a",{href:he,className:"inline-flex min-h-10 items-center text-sm underline underline-offset-4",children:t("cloud.action.open_app")})]}):null]}),e.jsxs(ke,{children:[e.jsx("h2",{className:"text-sm font-semibold",children:t("cloud.checkout.summary")}),v?e.jsx("p",{className:"mt-3 text-sm text-oai-gray-500 dark:text-oai-gray-400",children:t("cloud.trial.no_card")}):e.jsxs("div",{className:"mt-4 border-b border-oai-gray-200 pb-4 dark:border-oai-gray-800",children:[e.jsx("p",{className:"text-2xl font-semibold tabular-nums",children:Y!=null&&B?ge(Y,B):t(I?"cloud.catalog.loading":"cloud.price.pending")}),de?e.jsx("p",{className:"mt-1 text-xs leading-5 text-oai-gray-500 dark:text-oai-gray-400",children:de===12?t("cloud.price.per_year"):t("cloud.price.per_month")}):null,N&&B?e.jsx("p",{className:"mt-2 text-xs leading-5 text-oai-gray-500 dark:text-oai-gray-400",children:B==="USD"?t("cloud.checkout.tax"):t("cloud.renewal.manual")}):null]}),e.jsx("div",{className:"mt-5",children:e.jsx(Qe,{limits:m?.limits})})]})]}),e.jsxs("div",{className:"mt-5 space-y-3",children:[h?e.jsx(p,{error:h,onRetry:n?se?R:xe:void 0}):null,h&&["subscription_already_exists","fixed_term_still_active","checkout_request_conflict","pending_checkout_exists","gift_membership_active"].includes(h.code||h.message)?e.jsx(l,{as:u,to:"/settings?section=account",variant:"secondary",className:"no-underline",children:t("cloud.action.manage_membership")}):null,h&&["authentication_required","invalid_token","invalid_authentication"].includes(h.code||h.message)?e.jsx(l,{onClick:async()=>{await S?.signOut?.(),be(me)},variant:"secondary",children:t("cloud.action.sign_in_continue")}):null,j?e.jsx(p,{error:j,onRetry:je}):null,!j&&I?e.jsx(p,{children:t("cloud.catalog.loading")}):null,!j&&!I&&!b?e.jsx(p,{children:t("cloud.catalog.preview")}):null,!j&&!I&&b&&!v&&!h&&!F&&["review","creating","awaiting"].includes(i)?e.jsx(p,{children:t("cloud.catalog.provider_unavailable")}):null,!j&&!I&&b&&m?.environment==="sandbox"?e.jsx(p,{children:t("cloud.catalog.sandbox")}):null]})]})})}export{xt as CloudCheckoutPage};
@@ -1 +0,0 @@
1
- import{r as N,d as Q,o as V,p as W,q as X,t as Y,c as a,j as e,S as Z,C as ee,M as ae,B as m,L as _,v as y,w as te,x as E,y as se,z as x}from"./__vite-browser-external-DUJeOWgd.js";import{S as le}from"./Controls-BnTeX7T4.js";import{C as U}from"./Card-D-5mABVt.js";import{C as I}from"./check-CKwHc4Hv.js";import{A as L}from"./arrow-right-CwBz5dwb.js";import{S as re}from"./server-DFCbznC7.js";function xe(){const z=N.useRef(null);N.useLayoutEffect(()=>{const t=z.current?.parentElement;t&&(t.scrollTop=0)},[]);const T=Q(),{catalog:r,loading:n,error:o,refresh:$}=V(),{account:u,auth:b,loading:D,error:v,refresh:F}=W(),[i,G]=N.useState("recurring"),[c,H]=N.useState(12),l=r?.prices?.find(t=>t.billing_mode===i&&t.term_months===c),J=r?.prices?.find(t=>t.billing_mode===i&&t.term_months===1),K=r?.prices?.find(t=>t.billing_mode===i&&t.term_months===12),g=l?.currency||"USD",A=X(J,K),h=Y(r),M=r?.providers?.waffo,s=u?.membership,j=s?.has_gift===!0||u?.gifts?.some(t=>["active","pending"].includes(t.state)),k=[...u?.conflict_orders||[],...u?.pending_orders||[]].some(t=>t.retry_payment_conflict_at),p=s&&["active","trial","transition","legacy_free"].includes(s.status),f=u?.subscriptions?.some(t=>["active","trialing","past_due","paused"].includes(t.status)&&!t.cancel_at_period_end),w=s?.trial_available===!1,R=!b?.signedIn||s?.trial_available===!0,C=!!(b?.loading||b?.signedIn&&(D||v||!s)),d=s?.status==="active"||f||j,S=!p&&!f&&!j&&!w,P=a(i==="fixed"?"cloud.action.buy_pro":"cloud.action.subscribe"),B=!l||!h||n||o||C||!M||k,q=(t=!1)=>{const O=t?new URLSearchParams({intent:"trial"}):new URLSearchParams({sku:l.sku});T(`/billing/checkout?${O}`)};return r?.policy?.hosting_mode==="self_hosted"||s?.status==="self_hosted"?e.jsx(Z,{}):e.jsx("div",{ref:z,className:"tt-cloud-theme flex flex-1 flex-col font-oai text-oai-black dark:text-oai-white",children:e.jsxs("main",{className:"mx-auto w-full max-w-5xl px-4 py-7 sm:px-6 sm:py-9",children:[e.jsxs("div",{className:"mb-8 max-w-2xl",children:[e.jsx("h1",{className:"text-balance text-3xl font-semibold tracking-tight",children:a("cloud.page.title")}),e.jsx("p",{className:"mt-3 text-base leading-7 text-oai-gray-500 dark:text-oai-gray-400",children:a("cloud.page.subtitle")}),r?.environment==="sandbox"?e.jsx("p",{className:"mt-3 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:a("cloud.price.draft")}):null]}),k?e.jsx("div",{className:"mb-6",children:e.jsx(ee,{})}):null,e.jsxs("div",{className:"grid items-start gap-5 md:grid-cols-2",children:[e.jsxs(U,{className:"order-2 md:order-1",bodyClassName:"flex flex-col sm:p-6",children:[e.jsxs("div",{className:"mb-2 flex min-h-11 items-center gap-2",children:[e.jsx(ae,{size:19,className:"text-oai-gray-500 dark:text-oai-gray-400","aria-hidden":!0}),e.jsx("h2",{className:"text-lg font-semibold",children:a("cloud.free.title")})]}),e.jsx("p",{className:"text-sm leading-6 text-oai-gray-500 dark:text-oai-gray-400 md:min-h-12",children:a("cloud.free.subtitle")}),e.jsxs("div",{className:"my-6",children:[e.jsx("p",{className:"text-3xl font-semibold tracking-tight",children:a("cloud.free.price")}),e.jsx("p",{className:"mt-2 text-sm text-oai-gray-500 dark:text-oai-gray-400",children:a("cloud.free.forever")})]}),e.jsx(m,{as:_,to:b?.signedIn?"/dashboard":"/landing#download",variant:"secondary",className:"w-full no-underline",children:a("cloud.free.cta")}),e.jsx("div",{className:"mt-7 border-t border-oai-gray-200 pt-6 dark:border-oai-gray-800",children:e.jsx("ul",{className:"space-y-3 text-sm",children:[a("cloud.free.tracking"),a("cloud.free.limits"),a("cloud.free.desktop"),a("cloud.free.exports"),a("cloud.free.community")].map(t=>e.jsxs("li",{className:"flex gap-3",children:[e.jsx(I,{size:16,className:"mt-0.5 shrink-0 text-oai-gray-500 dark:text-oai-gray-400","aria-hidden":!0}),t]},t))})}),e.jsx("p",{className:"pt-6 text-xs leading-5 text-oai-gray-500 dark:text-oai-gray-400",children:a("cloud.free.installations")})]}),e.jsxs(U,{className:"order-1 border-oai-gray-300 dark:border-oai-gray-600 md:order-2",bodyClassName:"sm:p-6",children:[e.jsxs("div",{className:"mb-2 flex flex-wrap items-center justify-between gap-x-4 gap-y-1",children:[e.jsx("h2",{className:"text-lg font-semibold",children:a("cloud.plan.title")}),e.jsx("div",{role:"group","aria-label":a("cloud.selector.term"),className:"tt-pro-period-control shrink-0",children:e.jsx(le,{options:[{value:1,label:a("cloud.term.monthly")},{value:12,label:a("cloud.term.yearly")}],value:c,onChange:H})})]}),e.jsx("p",{className:"text-sm leading-6 text-oai-gray-500 dark:text-oai-gray-400 md:min-h-12",children:a("cloud.plan.subtitle")}),e.jsxs("div",{className:"mb-4 mt-5","aria-live":"polite",children:[e.jsxs("p",{className:"flex flex-wrap items-baseline gap-2",children:[e.jsx("span",{className:"text-4xl font-semibold tracking-tight tabular-nums",children:l?y(l.amount_cents,g):a("cloud.price.pending")}),e.jsx("span",{className:"text-sm text-oai-gray-500 dark:text-oai-gray-400",children:c===12?a("cloud.price.per_year"):a("cloud.price.per_month")})]}),e.jsx("p",{className:"mt-2 text-sm leading-6 text-oai-gray-500 dark:text-oai-gray-400",children:l?i==="fixed"?a(c===12?"cloud.price.fixed_annual_total":"cloud.price.fixed_monthly_total",{equivalent:y(Math.round(l.amount_cents/12),g)}):c===12?a("cloud.price.annual_total",{total:y(l.amount_cents,g),equivalent:y(Math.round(l.amount_cents/12),g)}):a("cloud.price.monthly_total",{total:y(l.amount_cents,g)}):a("cloud.price.waiting")}),c===12&&A!==0?e.jsx("p",{className:"mt-1 text-xs leading-5 text-oai-gray-600 dark:text-oai-gray-300",children:a("cloud.price.savings",{percent:A})}):null]}),e.jsxs("div",{className:"mb-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsx("label",{htmlFor:"pro-renewal-toggle",className:"cursor-pointer text-sm font-medium",children:a("cloud.billing_mode.recurring")}),e.jsx("button",{id:"pro-renewal-toggle",type:"button",role:"switch","aria-checked":i==="recurring","aria-label":a("cloud.billing_mode.recurring"),"aria-describedby":"pro-renewal-description",onClick:()=>G(t=>t==="recurring"?"fixed":"recurring"),className:"flex h-11 w-11 shrink-0 items-center justify-center rounded-md",children:e.jsx("span",{"aria-hidden":!0,className:`relative inline-flex h-5 w-9 items-center rounded-full transition-colors ${i==="recurring"?"bg-oai-gray-900 dark:bg-oai-gray-100":"bg-oai-gray-300 dark:bg-oai-gray-700"}`,children:e.jsx("span",{className:`h-3.5 w-3.5 rounded-full transition-transform motion-reduce:transition-none ${i==="recurring"?"translate-x-[19px] bg-white dark:bg-oai-gray-900":"translate-x-[3px] bg-white"}`})})})]}),e.jsx("p",{id:"pro-renewal-description",className:"text-xs leading-5 text-oai-gray-600 dark:text-oai-gray-300",children:a(i==="recurring"?"cloud.renewal.auto":"cloud.renewal.manual")})]}),d?e.jsx(m,{as:_,to:"/settings?section=account",className:"w-full no-underline",children:a("cloud.action.manage_membership")}):null,!d&&S?e.jsxs(m,{type:"button",onClick:()=>q(!0),disabled:!h||n||o||C||!R||k,className:"w-full",children:[a("cloud.action.try",{days:r?.limits?.trial_days||7}),e.jsx(L,{size:16,className:"ml-2","aria-hidden":!0})]}):null,!d&&!S?e.jsxs(m,{type:"button",onClick:()=>q(),disabled:B,className:"w-full",children:[P,e.jsx(L,{size:16,className:"ml-2","aria-hidden":!0})]}):null,p||f||w&&!p||R&&!C?e.jsx("p",{className:"mt-2 text-center text-xs leading-5 text-oai-gray-500 dark:text-oai-gray-400",children:p||f?te(s?.status):w?a("cloud.error.trial"):a("cloud.trial.no_card")}):null,p&&!d?e.jsxs("p",{className:"mt-2 text-center text-xs leading-5 text-oai-gray-600 dark:text-oai-gray-300",children:[s?.status==="transition"&&s.transition_ends_at?a("cloud.membership.expires",{date:E(s.transition_ends_at)}):s?.status==="trial"&&s.trial_ends_at?a("cloud.membership.expires",{date:E(s.trial_ends_at)}):null,e.jsx(_,{to:"/settings?section=account",className:"ml-2 inline-flex min-h-8 items-center underline underline-offset-4",children:a("cloud.action.manage_membership")})]}):null,!f&&!j&&(S||d&&i==="fixed")?e.jsx(m,{type:"button",variant:"ghost",onClick:()=>q(),disabled:B,className:"mx-auto mt-1 !flex w-fit underline underline-offset-4",children:d?a("cloud.action.renew"):P}):null,j?e.jsx("p",{className:"mt-3 text-xs leading-5 text-oai-gray-600 dark:text-oai-gray-300",children:a("cloud.gift.error_active")}):null,l?e.jsx("p",{className:"mt-2 text-xs leading-5 text-oai-gray-500 dark:text-oai-gray-400",children:a("cloud.checkout.tax")}):null,e.jsxs("div",{className:"mt-6 border-t border-oai-gray-200 pt-6 dark:border-oai-gray-800",children:[e.jsx(se,{limits:r?.limits}),e.jsxs("p",{className:"mt-4 flex items-start gap-3 text-sm leading-6",children:[e.jsx(I,{size:17,className:"mt-1 shrink-0 text-oai-gray-600 dark:text-oai-gray-300","aria-hidden":!0}),a("cloud.feature.pro_identity")]})]}),e.jsx("p",{className:"mt-5 text-xs leading-5 text-oai-gray-500 dark:text-oai-gray-400",children:a("cloud.feature.privacy_detail")})]})]}),e.jsxs("div",{className:"mt-5",children:[v?e.jsx(x,{error:v,context:"account",onRetry:F}):null,o?e.jsx(x,{error:o,onRetry:$}):null,!o&&n?e.jsx(x,{children:a("cloud.catalog.loading")}):null,!o&&!n&&!h?e.jsx(x,{children:a("cloud.catalog.preview")}):null,!o&&!n&&h&&!M?e.jsx(x,{children:a("cloud.catalog.provider_unavailable")}):null,!o&&!n&&h&&r?.environment==="sandbox"?e.jsx(x,{children:a("cloud.catalog.sandbox")}):null]}),e.jsxs("section",{className:"mt-8 flex flex-col gap-5 rounded-xl border border-oai-gray-200 p-5 dark:border-oai-gray-800 sm:flex-row sm:items-center sm:justify-between sm:p-7",children:[e.jsxs("div",{className:"max-w-2xl",children:[e.jsxs("h2",{className:"flex items-center gap-2 text-base font-semibold",children:[e.jsx(re,{size:18,"aria-hidden":!0}),a("cloud.self_host.title")]}),e.jsx("p",{className:"mt-2 text-sm leading-6 text-oai-gray-600 dark:text-oai-gray-300",children:a("cloud.self_host.body")})]}),e.jsxs(m,{as:_,to:"/self-host",variant:"secondary",className:"shrink-0 self-start no-underline sm:self-auto",children:[a("cloud.self_host.cta"),e.jsx(L,{size:16,className:"ml-2","aria-hidden":!0})]})]}),e.jsxs("div",{className:"mt-10 grid gap-7 border-t border-oai-gray-200 pt-7 dark:border-oai-gray-800 sm:grid-cols-2",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-sm font-semibold",children:a("cloud.faq.cost_title")}),e.jsx("p",{className:"mt-2 text-sm leading-6 text-oai-gray-500 dark:text-oai-gray-400",children:a("cloud.faq.cost_body")})]}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-sm font-semibold",children:a("cloud.faq.local_title")}),e.jsx("p",{className:"mt-2 text-sm leading-6 text-oai-gray-500 dark:text-oai-gray-400",children:a("cloud.faq.local_body")})]}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-sm font-semibold",children:a("cloud.faq.expiry_title")}),e.jsx("p",{className:"mt-2 text-sm leading-6 text-oai-gray-500 dark:text-oai-gray-400",children:a("cloud.faq.expiry_body")})]}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-sm font-semibold",children:a("cloud.faq.existing_title")}),e.jsx("p",{className:"mt-2 text-sm leading-6 text-oai-gray-500 dark:text-oai-gray-400",children:a("cloud.faq.existing_body")})]}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-sm font-semibold",children:a("cloud.faq.platform_title")}),e.jsx("p",{className:"mt-2 text-sm leading-6 text-oai-gray-500 dark:text-oai-gray-400",children:a("cloud.faq.platform_body")})]})]})]})})}export{xe as CloudPage};