tokentracker-cli 1.3.4 → 1.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.de.md +5 -5
- package/README.ja.md +3 -3
- package/README.ko.md +3 -3
- package/README.md +6 -5
- package/README.zh-CN.md +3 -3
- package/dashboard/dist/assets/{AchievementBadge-CKjtQp-U.js → AchievementBadge-Dazs3pEa.js} +1 -1
- package/dashboard/dist/assets/{AchievementsPage-DpOXrabE.js → AchievementsPage-LWnxZvmw.js} +2 -2
- package/dashboard/dist/assets/{AchievementsSection-DiXyIoa0.js → AchievementsSection-BLqczmU9.js} +1 -1
- package/dashboard/dist/assets/{BadgeDetailModal-CILTTkPF.js → BadgeDetailModal-B_n4aj2S.js} +1 -1
- package/dashboard/dist/assets/{BotAnimated-CrBHWiRi.js → BotAnimated-KDWI_YcZ.js} +1 -1
- package/dashboard/dist/assets/{Card-DUItW3xI.js → Card-BYoxd4OC.js} +1 -1
- package/dashboard/dist/assets/{CloudCheckoutPage-C_t_PDlG.js → CloudCheckoutPage-BR2_B03P.js} +1 -1
- package/dashboard/dist/assets/{CloudPage-pvJUrhya.js → CloudPage-DL5RkJKK.js} +1 -1
- package/dashboard/dist/assets/{CloudUsageExport-DQbDwiyk.js → CloudUsageExport-C_DqZKo1.js} +1 -1
- package/dashboard/dist/assets/{CommandPalette-BvHilrbV.js → CommandPalette-DkCaIQI4.js} +1 -1
- package/dashboard/dist/assets/{CommunityStatsModal-CizxEYv-.js → CommunityStatsModal-pX9OePi4.js} +1 -1
- package/dashboard/dist/assets/{ConfirmModal-h9nISVy7.js → ConfirmModal-tkgZwz4u.js} +1 -1
- package/dashboard/dist/assets/{Controls-BjdIonTX.js → Controls-MTUhGWy8.js} +1 -1
- package/dashboard/dist/assets/{DashboardPage-Bxryr4qp.js → DashboardPage-SOx-A7lH.js} +1 -1
- package/dashboard/dist/assets/{DateRangePopover-DpKh-0l8.js → DateRangePopover-B-BMOm3O.js} +1 -1
- package/dashboard/dist/assets/{DevicePage-DUJR9hJC.js → DevicePage-DSK9lm7v.js} +1 -1
- package/dashboard/dist/assets/{DialogClose-BmVAmN-o.js → DialogClose-uVUNu4rg.js} +1 -1
- package/dashboard/dist/assets/DialogDescription-DBqGGWNj.js +1 -0
- package/dashboard/dist/assets/{DialogTitle-BsaIbN8k.js → DialogTitle-B-VifiA3.js} +1 -1
- package/dashboard/dist/assets/{FadeIn-BpSt2P_W.js → FadeIn-B6lrj4uo.js} +1 -1
- package/dashboard/dist/assets/{HeaderGithubStar-Cc_VHB0R.js → HeaderGithubStar-Cx5zOhXa.js} +1 -1
- package/dashboard/dist/assets/{HoverTooltip-WFd21iP9.js → HoverTooltip-DY1ENf69.js} +1 -1
- package/dashboard/dist/assets/{IpCheckPage-C_mUPSRB.js → IpCheckPage-D6TEq64d.js} +1 -1
- package/dashboard/dist/assets/{LandingPage-DVR8ClZO.js → LandingPage-OdZUfq--.js} +2 -2
- package/dashboard/dist/assets/LeaderboardPage-DCK5xcAt.js +2 -0
- package/dashboard/dist/assets/{LeaderboardProBadge-BjX4EFl2.js → LeaderboardProBadge-CBXJ1u_m.js} +1 -1
- package/dashboard/dist/assets/{LeaderboardProfileModal-vbPMNn7W.js → LeaderboardProfileModal-Ccdzb7QK.js} +4 -4
- package/dashboard/dist/assets/{LeaderboardProfilePage-CqClmuA-.js → LeaderboardProfilePage-CFXlZ0fL.js} +1 -1
- package/dashboard/dist/assets/LimitsPage-5krjm-g9.js +9 -0
- package/dashboard/dist/assets/{LocalOnlyNotice-B6nDke_u.js → LocalOnlyNotice-Rk1B8PaZ.js} +1 -1
- package/dashboard/dist/assets/{LoginCard-C28QVjd7.js → LoginCard-DTTIm8vk.js} +1 -1
- package/dashboard/dist/assets/{LoginModal-Bx1btNhH.js → LoginModal-BNcDdjfr.js} +1 -1
- package/dashboard/dist/assets/{LoginPage-DVOGNGYI.js → LoginPage-CQgXP7Ee.js} +1 -1
- package/dashboard/dist/assets/{PetPage-nOKryTde.js → PetPage-Cw_kAPRs.js} +1 -1
- package/dashboard/dist/assets/{PopoverPopup-Ch6NLnu6.js → PopoverPopup-NYiGE8A2.js} +1 -1
- package/dashboard/dist/assets/{ProviderIcon-BRY2br-g.js → ProviderIcon-Bp7iFJ_m.js} +1 -1
- package/dashboard/dist/assets/{ResetPasswordPage-ko1OQecQ.js → ResetPasswordPage-Cf9kAWDW.js} +1 -1
- package/dashboard/dist/assets/{Select-Q8mS3_od.js → Select-kIcvQFAo.js} +1 -1
- package/dashboard/dist/assets/{SelectItemText-C1id8GDj.js → SelectItemText-BpIsAg3b.js} +1 -1
- package/dashboard/dist/assets/{SelfHostPage-Dzb2bDiM.js → SelfHostPage-Ch2vvSwI.js} +1 -1
- package/dashboard/dist/assets/{ServiceStatusPage-ewFwz29J.js → ServiceStatusPage-hoYBvGbu.js} +1 -1
- package/dashboard/dist/assets/SessionsPage-BzRB6q-Z.js +3 -0
- package/dashboard/dist/assets/SettingsPage-DRl2uX-i.js +2 -0
- package/dashboard/dist/assets/{SkillsPage-CcG77tqU.js → SkillsPage-CkqThTZL.js} +1 -1
- package/dashboard/dist/assets/{TokenGalaxy-D2HDrbQR.js → TokenGalaxy-eLG-UIZY.js} +1 -1
- package/dashboard/dist/assets/{TooltipPopup-C_bF2ZwO.js → TooltipPopup-bnMJyilQ.js} +1 -1
- package/dashboard/dist/assets/{TrendMonitor-BcyoN5ns.js → TrendMonitor-X7-aGzIv.js} +1 -1
- package/dashboard/dist/assets/{WidgetsPage-BirK0U_N.js → WidgetsPage-CGznIzrW.js} +1 -1
- package/dashboard/dist/assets/{WrappedPage-thsXBuw6.js → WrappedPage-p31-uUoF.js} +1 -1
- package/dashboard/dist/assets/{__vite-browser-external-Bq8nj-JV.js → __vite-browser-external-2g_4s3ot.js} +12 -12
- package/dashboard/dist/assets/__vite-browser-external-LpFw4zXh.css +1 -0
- package/dashboard/dist/assets/agent-logos-2TVT3fIE.js +1 -0
- package/dashboard/dist/assets/{arrow-left-c_NOSfoq.js → arrow-left-DL0hAp_7.js} +1 -1
- package/dashboard/dist/assets/{arrow-right-CP7drKCT.js → arrow-right-DFCpnV_9.js} +1 -1
- package/dashboard/dist/assets/{arrow-up-right-DQ6QfCpo.js → arrow-up-right-DLvfE0Wu.js} +1 -1
- package/dashboard/dist/assets/{calendar-days-D_pxFQvT.js → calendar-days-B0aDoKSG.js} +1 -1
- package/dashboard/dist/assets/{check-HAS31kTT.js → check-C_cfrxiz.js} +1 -1
- package/dashboard/dist/assets/{chevron-down-BIMuk6oN.js → chevron-down-Ck8ml43e.js} +1 -1
- package/dashboard/dist/assets/{cloud-checkout-COmDwrUT.js → cloud-checkout-PYnwNfdH.js} +1 -1
- package/dashboard/dist/assets/{composite-kLwqpqEk.js → composite-INW-ELWX.js} +1 -1
- package/dashboard/dist/assets/{download-9RgsZIiH.js → download-B7uokeIo.js} +1 -1
- package/dashboard/dist/assets/{external-link-C_gYjHGF.js → external-link-CI3crg4K.js} +1 -1
- package/dashboard/dist/assets/{flame-BSsCvgT8.js → flame-DCzvFKV1.js} +1 -1
- package/dashboard/dist/assets/{format-tokens-N22Wqv1X.js → format-tokens-CSTEYK2m.js} +1 -1
- package/dashboard/dist/assets/gift-dEHDFMc6.js +1 -0
- package/dashboard/dist/assets/{host-mode-JzrhHX7F.js → host-mode-r2SW9Mdv.js} +1 -1
- package/dashboard/dist/assets/{icons-pK99mIMv.js → icons-q-3zvEkh.js} +1 -1
- package/dashboard/dist/assets/{index-CmD84EJi.js → index-BV7qwUw4.js} +1 -1
- package/dashboard/dist/assets/{index-Dk43KNa6.js → index-BbrsgHf4.js} +1 -1
- package/dashboard/dist/assets/{index-BhviBroj.js → index-CyHYj9XI.js} +1 -1
- package/dashboard/dist/assets/{info-D-RLFnSK.js → info-BBdY9hV4.js} +1 -1
- package/dashboard/dist/assets/{link-2-BiKXW9mV.js → link-2-CLPePfXs.js} +1 -1
- package/dashboard/dist/assets/{loader-circle-KVUaEKV2.js → loader-circle-ETrjzfmn.js} +1 -1
- package/dashboard/dist/assets/{modifiers.esm-5NK8j3mT.js → modifiers.esm-DHqnp2ol.js} +1 -1
- package/dashboard/dist/assets/module-BNnaKM__.js +3 -0
- package/dashboard/dist/assets/{monitor-smartphone-u9yr-_Es.js → monitor-smartphone-D1kdzrdb.js} +1 -1
- package/dashboard/dist/assets/{play-D0MaDCOx.js → play-Cxp-ronD.js} +1 -1
- package/dashboard/dist/assets/{plus-DTJVtoAJ.js → plus-4n94VzDK.js} +1 -1
- package/dashboard/dist/assets/{provider-display-YhtG0I9Y.js → provider-display-CRlbeO7t.js} +1 -1
- package/dashboard/dist/assets/{react-gIVxucOB.js → react-DlHjGQFN.js} +1 -1
- package/dashboard/dist/assets/{safePolygon-C_sPnJ1L.js → safePolygon-CVZ27a2_.js} +1 -1
- package/dashboard/dist/assets/{search-DdQRwFYV.js → search-BDPr56_h.js} +1 -1
- package/dashboard/dist/assets/{server-M0rmbGWy.js → server-Bm7fHvVa.js} +1 -1
- package/dashboard/dist/assets/{shield-check-9-sqQKdD.js → shield-check-DtT8ACzI.js} +1 -1
- package/dashboard/dist/assets/{skills-api-B0qBWnuK.js → skills-api-Dc1-2qu6.js} +1 -1
- package/dashboard/dist/assets/{sortable.esm-iqbm7x5D.js → sortable.esm-B-qN-Xk2.js} +1 -1
- package/dashboard/dist/assets/{store-DstuWd4a.js → store-gHeBU8dQ.js} +1 -1
- package/dashboard/dist/assets/{terminal-Dz0MxHNG.js → terminal-D4VZbvhg.js} +1 -1
- package/dashboard/dist/assets/{trash-DBMFOFVz.js → trash-BZtLAFQy.js} +1 -1
- package/dashboard/dist/assets/{use-community-stats-CacbAcUR.js → use-community-stats-BdqndrbB.js} +1 -1
- package/dashboard/dist/assets/{use-latest-request-guard-nBuQVZOR.js → use-latest-request-guard-DhGg1cDS.js} +1 -1
- package/dashboard/dist/assets/use-limits-display-prefs-D3HOcRFv.js +1 -0
- package/dashboard/dist/assets/{use-native-settings-EAqAFx2x.js → use-native-settings-BniKwA_n.js} +1 -1
- package/dashboard/dist/assets/{use-ordered-list-DGLjjU6Q.js → use-ordered-list-b09H7EHq.js} +1 -1
- package/dashboard/dist/assets/{use-pet-settings-C5MzWHE7.js → use-pet-settings-CPZdlq_e.js} +2 -2
- package/dashboard/dist/assets/use-reduced-motion-D1gcKJUo.js +1 -0
- package/dashboard/dist/assets/{use-transform-C25eCuz_.js → use-transform-CIdxjmI8.js} +1 -1
- package/dashboard/dist/assets/use-usage-limits-eJlU65yY.js +1 -0
- package/dashboard/dist/assets/{useCurrency-t3PYQi1l.js → useCurrency-CM22CmAq.js} +1 -1
- package/dashboard/dist/assets/{usePositioner-C59mj6kG.js → usePositioner-B3l2ulTw.js} +1 -1
- package/dashboard/dist/assets/{useTokenFormat-C0xQsBGf.js → useTokenFormat-D7nzgxKw.js} +1 -1
- package/dashboard/dist/assets/{zap-CyH0tvKM.js → zap-Daxct1WV.js} +1 -1
- package/dashboard/dist/index.html +14 -12
- package/dashboard/dist/ip-check.html +2 -2
- package/dashboard/dist/leaderboard.html +2 -2
- package/dashboard/dist/llms.txt +2 -2
- package/dashboard/dist/share.html +2 -2
- package/package.json +2 -2
- package/src/commands/init.js +43 -1
- package/src/commands/status.js +27 -0
- package/src/commands/sync.js +54 -4
- package/src/commands/uninstall.js +19 -0
- package/src/lib/claude-config.js +47 -15
- package/src/lib/codex-rollout-parser.js +11 -3
- package/src/lib/command-runner.js +15 -1
- package/src/lib/cursor-config.js +2 -1
- package/src/lib/gemini-config.js +3 -2
- package/src/lib/local-api.js +13 -3
- package/src/lib/notify-command.js +38 -0
- package/src/lib/openclaw-session-plugin.js +47 -14
- package/src/lib/passive-mode.js +12 -0
- package/src/lib/pricing/curated-overrides.json +42 -5
- package/src/lib/pricing/matcher.js +14 -5
- package/src/lib/pricing/seed-snapshot.json +1 -1
- package/src/lib/rollout.js +150 -28
- package/src/lib/session-analytics.js +108 -9
- package/src/lib/usage-limits.js +183 -20
- package/src/lib/zcode-limits.js +218 -18
- package/src/lib/zcode-reset-credits.js +66 -0
- package/dashboard/dist/assets/DialogDescription-C0Cgq67g.js +0 -1
- package/dashboard/dist/assets/LeaderboardPage-D8ydzVpn.js +0 -2
- package/dashboard/dist/assets/LimitsPage-DaRggHge.js +0 -8
- package/dashboard/dist/assets/SessionsPage-C6Y8kbnM.js +0 -3
- package/dashboard/dist/assets/SettingsPage-nztCXEPs.js +0 -2
- package/dashboard/dist/assets/__vite-browser-external-BwmeEfv7.css +0 -1
- package/dashboard/dist/assets/agent-logos-CK6SzhI7.js +0 -1
- package/dashboard/dist/assets/module-WSx8viXK.js +0 -3
- package/dashboard/dist/assets/use-limits-display-prefs-fqg8hs6b.js +0 -1
- package/dashboard/dist/assets/use-reduced-motion-DK2oZ2uC.js +0 -1
- package/dashboard/dist/assets/use-usage-limits-BhqnEai3.js +0 -1
package/src/lib/zcode-limits.js
CHANGED
|
@@ -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:[^:]
|
|
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
|
-
*
|
|
350
|
-
*
|
|
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
|
|
362
|
-
|
|
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
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
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 ? {
|
|
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{r as n,J as a}from"./__vite-browser-external-Bq8nj-JV.js";import{u as p}from"./DialogTitle-BsaIbN8k.js";import{u as c}from"./composite-kLwqpqEk.js";const x=n.forwardRef(function(e,r){const{render:l,className:u,style:m,id:s,...t}=e,i=p(),o=c(s);return i.useSyncedValueWithCleanup("descriptionElementId",o),a("p",e,{ref:r,props:[{id:o},t]})});export{x as D};
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/LeaderboardProfileModal-vbPMNn7W.js","assets/__vite-browser-external-Bq8nj-JV.js","assets/__vite-browser-external-BwmeEfv7.css","assets/provider-display-YhtG0I9Y.js","assets/useCurrency-t3PYQi1l.js","assets/useTokenFormat-C0xQsBGf.js","assets/terminal-Dz0MxHNG.js","assets/play-D0MaDCOx.js","assets/info-D-RLFnSK.js","assets/LeaderboardProBadge-BjX4EFl2.js","assets/TooltipPopup-C_bF2ZwO.js","assets/composite-kLwqpqEk.js","assets/store-DstuWd4a.js","assets/safePolygon-C_sPnJ1L.js","assets/usePositioner-C59mj6kG.js","assets/ProviderIcon-BRY2br-g.js","assets/AchievementBadge-CKjtQp-U.js","assets/zap-CyH0tvKM.js","assets/flame-BSsCvgT8.js","assets/calendar-days-D_pxFQvT.js","assets/shield-check-9-sqQKdD.js","assets/AchievementsSection-DiXyIoa0.js","assets/react-gIVxucOB.js","assets/format-tokens-N22Wqv1X.js","assets/use-reduced-motion-DK2oZ2uC.js","assets/arrow-up-right-DQ6QfCpo.js","assets/link-2-BiKXW9mV.js","assets/check-HAS31kTT.js","assets/DialogTitle-BsaIbN8k.js","assets/CommunityStatsModal-CizxEYv-.js","assets/icons-pK99mIMv.js","assets/TrendMonitor-BcyoN5ns.js","assets/DateRangePopover-DpKh-0l8.js","assets/use-latest-request-guard-nBuQVZOR.js","assets/PopoverPopup-Ch6NLnu6.js","assets/SelectItemText-C1id8GDj.js","assets/DialogDescription-C0Cgq67g.js","assets/DialogClose-BmVAmN-o.js"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{j as e,V as ua,c as s,y as c,r as d,ar as xa,d as pa,u as ba,a as ha,bn as ya,W as fa,aA as ka,a7 as wa,bo as Be,bp as va,bq as ie,g as ja,br as Na,L as _a,bs as Sa,i as Ca,bt as Aa,bu as La,aP as Ea,_ as Ge,h as Ta,z as Ma}from"./__vite-browser-external-Bq8nj-JV.js";import{S as Pa}from"./Select-Q8mS3_od.js";import{m as Ka}from"./react-gIVxucOB.js";import{u as Ra,C as Ia,a as za,b as De,D as Ba,c as Da,S as $a,h as Ua,s as Oa,K as Fa,P as Ga}from"./sortable.esm-iqbm7x5D.js";import{r as Ha}from"./modifiers.esm-5NK8j3mT.js";import{P as ye}from"./ProviderIcon-BRY2br-g.js";import{u as Wa}from"./useCurrency-t3PYQi1l.js";import{u as Q}from"./useTokenFormat-C0xQsBGf.js";import{L as q,a as ne}from"./LeaderboardProBadge-BjX4EFl2.js";import{s as Ya,c as Va,A as Ja,t as Za,b as qa}from"./AchievementBadge-CKjtQp-U.js";import{u as Xa}from"./use-ordered-list-DGLjjU6Q.js";import{A as Qa}from"./arrow-right-CP7drKCT.js";import{u as er}from"./use-community-stats-CacbAcUR.js";import"./chevron-down-BIMuk6oN.js";import"./check-HAS31kTT.js";import"./SelectItemText-C1id8GDj.js";import"./composite-kLwqpqEk.js";import"./usePositioner-C59mj6kG.js";import"./TooltipPopup-C_bF2ZwO.js";import"./store-DstuWd4a.js";import"./safePolygon-C_sPnJ1L.js";import"./zap-CyH0tvKM.js";import"./flame-BSsCvgT8.js";import"./calendar-days-D_pxFQvT.js";import"./shield-check-9-sqQKdD.js";function H(a,{min:r,max:o,fallback:i}){const l=Number(a);if(!Number.isFinite(l))return i;const n=Math.floor(l);return n<r?r:n>o?o:n}function ar(a,r){const o=H(r,{min:0,max:1e6,fallback:0}),i=H(a,{min:1,max:Math.max(1,o||1),fallback:1});if(o<=1)return[1];const l=new Set([1,o,i-2,i-1,i,i+1,i+2]),n=Array.from(l).filter(u=>Number.isInteger(u)&&u>=1&&u<=o).sort((u,h)=>u-h),m=[];let p=null;for(const u of n)p!=null&&u-p>1&&m.push(null),m.push(u),p=u;return m}function rr({page:a,totalPages:r}){const o=typeof r=="number"&&Number.isFinite(r)&&r>=0,i=o?H(r,{min:0,max:1e6,fallback:0}):null,l=H(a,{min:1,max:o?Math.max(1,i||1):1e6,fallback:1}),n=l>1,m=o?l<i:!0;return{canPrev:n,canNext:m,safePage:l,safeTotal:i}}function tr({entries:a,me:r,meLabel:o}){const i=Array.isArray(a)?a:[],l=r&&typeof r.rank=="number"?r.rank:null;return!l||i.some(m=>!!m?.is_me)?i:[{rank:l,is_me:!0,is_pinned:!0,user_id:r?.user_id??null,display_name:o,avatar_url:r?.avatar_url??null,pro_active:r?.pro_active===!0,github_url:null,is_public:!1,gpt_tokens:r?.gpt_tokens??"0",claude_tokens:r?.claude_tokens??"0",gemini_tokens:r?.gemini_tokens??"0",cursor_tokens:r?.cursor_tokens??"0",opencode_tokens:r?.opencode_tokens??"0",openclaw_tokens:r?.openclaw_tokens??"0",hermes_tokens:r?.hermes_tokens??"0",kiro_tokens:r?.kiro_tokens??"0",copilot_tokens:r?.copilot_tokens??"0",kimi_tokens:r?.kimi_tokens??"0",other_tokens:r?.other_tokens??"0",total_tokens:r?.total_tokens??"0",estimated_cost_usd:r?.estimated_cost_usd??null,badges:Array.isArray(r?.badges)?r.badges:[]},...i]}function or(a,r){const o=Number(a),i=Number(r);return!Number.isFinite(o)||o<1||!Number.isFinite(i)||i<1?null:Math.ceil(o/i)}const sr=new Set(["/brand-logos/cursor.svg","/brand-logos/kimi.svg","/brand-logos/kiro.svg","/brand-logos/copilot.svg","/brand-logos/hermes.svg"]);function ir({iconSrc:a,label:r}){return e.jsxs("span",{className:"inline-flex items-center gap-3",children:[a?e.jsx("img",{src:a,alt:"",width:16,height:16,className:`h-4 w-4 shrink-0 object-contain opacity-90 ${sr.has(a)?"dark:invert":""}`}):null,e.jsx("span",{className:"whitespace-nowrap",children:r})]})}const le=ua.memo(function({badges:r,max:o=3,className:i=""}){const l=Ya((r||[]).filter(n=>n&&Va.has(n.id)&&(n.tier||0)>=1)).slice(0,o);return l.length===0?null:e.jsx("span",{className:`pointer-events-none inline-flex shrink-0 items-center ${i}`,children:l.map((n,m)=>e.jsx("span",{title:s("achievements.mini.tooltip",{name:s(qa(n.id,"name")),tier:s(`achievements.tier.${Za(n.tier)}`)}),style:{zIndex:l.length-m},className:`pointer-events-auto relative inline-flex ${m>0?"-ml-1.5":""}`,children:e.jsx(Ja,{badgeId:n.id,tier:n.tier,size:"xs",className:"rounded-full ring-[1.5px] ring-white dark:ring-oai-gray-950"})},n.id))})}),X=[{key:"gpt_tokens",copyKey:"leaderboard.column.codex",icon:"/brand-logos/codex.svg"},{key:"claude_tokens",copyKey:"leaderboard.column.claude",icon:"/brand-logos/claude-code.svg"},{key:"gemini_tokens",copyKey:"leaderboard.column.gemini",icon:"/brand-logos/gemini.svg"},{key:"cursor_tokens",copyKey:"leaderboard.column.cursor",icon:"/brand-logos/cursor.svg"},{key:"kiro_tokens",copyKey:"leaderboard.column.kiro",icon:"/brand-logos/kiro.svg"},{key:"copilot_tokens",copyKey:"leaderboard.column.copilot",icon:"/brand-logos/copilot.svg"},{key:"kimi_tokens",copyKey:"leaderboard.column.kimi",icon:"/brand-logos/kimi.svg"},{key:"opencode_tokens",copyKey:"leaderboard.column.opencode",icon:"/brand-logos/opencode.svg"},{key:"openclaw_tokens",copyKey:"leaderboard.column.openclaw",icon:"/brand-logos/openclaw.svg"},{key:"hermes_tokens",copyKey:"leaderboard.column.hermes",icon:"/brand-logos/hermes.svg"},{key:"other_tokens",copyKey:"leaderboard.column.supplemental",icon:null}],He="sticky left-0 z-40 w-14 min-w-14 max-w-14 sm:w-[72px] sm:min-w-[72px] sm:max-w-[72px] bg-white dark:bg-oai-gray-950 px-2.5 sm:px-4 py-4 align-middle",We="sticky left-[55px] sm:left-[71px] z-40 min-w-[96px] sm:min-w-[200px] max-w-[170px] sm:max-w-[min(260px,45vw)] border-l border-r border-oai-gray-200 dark:border-oai-gray-800 bg-white dark:bg-oai-gray-950 px-3 sm:px-4 py-4 align-middle";function de(a){return c("sticky left-0 z-30 w-14 min-w-14 max-w-14 sm:w-[72px] sm:min-w-[72px] sm:max-w-[72px] px-2.5 sm:px-4 py-4 whitespace-nowrap",a?"bg-oai-gray-50 dark:bg-oai-gray-900":"bg-white dark:bg-oai-gray-950 group-hover:bg-oai-gray-50 dark:group-hover:bg-oai-gray-900")}function ce(a){return c("sticky left-[55px] sm:left-[71px] z-30 hover:z-50 min-w-[96px] sm:min-w-[200px] max-w-[170px] sm:max-w-[min(260px,45vw)] border-l border-r border-oai-gray-200 dark:border-oai-gray-800 px-3 sm:px-4 py-4 min-w-0",a?"bg-oai-gray-50 dark:bg-oai-gray-900":"bg-white dark:bg-oai-gray-950 group-hover:bg-oai-gray-50 dark:group-hover:bg-oai-gray-900")}function f({className:a}){return e.jsx("div",{className:c("rounded bg-oai-gray-200/70 dark:bg-oai-gray-800/70 animate-pulse",a)})}function nr({index:a}){const r=a<3?"w-24":a<8?"w-20":"w-16",o=a<3?"w-16":"w-12",i=a<5?"w-14":"w-10";return e.jsxs("tr",{className:"group",children:[e.jsx("td",{className:c(de(!1),"!group-hover:bg-transparent"),children:e.jsx(f,{className:"h-4 w-6"})}),e.jsx("td",{className:c(ce(!1),"!group-hover:bg-transparent"),children:e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(f,{className:"h-8 w-8 min-w-8 rounded-full"}),e.jsx(f,{className:c("h-4",r)})]})}),e.jsx("td",{className:"px-4 py-4 bg-white dark:bg-oai-gray-950",children:e.jsx(f,{className:c("h-4",o)})}),e.jsx("td",{className:"px-4 py-4 bg-white dark:bg-oai-gray-950",children:e.jsx(f,{className:"h-4 w-12"})}),X.map(l=>e.jsx("td",{className:"px-4 py-4 bg-white dark:bg-oai-gray-950",children:e.jsx(f,{className:c("h-4",i)})},l.key))]})}function lr({index:a}){const r=a<3?"w-24":a<8?"w-20":"w-16",o=a%3===0?3:a%3===1?2:1;return e.jsxs("div",{className:"mx-0 my-1 rounded-xl bg-white dark:bg-oai-gray-950 border border-oai-gray-100 dark:border-oai-gray-800/60 px-3.5 py-3 shadow-sm",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx(f,{className:"h-4 w-3 shrink-0 rounded"}),e.jsx(f,{className:"h-9 w-9 shrink-0 rounded-full"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx(f,{className:c("h-4",r)}),e.jsx(f,{className:"mt-2 h-3.5 w-20"})]}),e.jsxs("div",{className:"shrink-0 text-right",children:[e.jsx(f,{className:"ml-auto h-3 w-8"}),e.jsx(f,{className:"mt-1.5 ml-auto h-4 w-14"})]})]}),e.jsx("div",{className:"mt-3 flex flex-wrap items-center gap-2 border-t border-oai-gray-100 pt-2.5 dark:border-oai-gray-800/70",children:Array.from({length:o},(i,l)=>e.jsx(f,{className:"h-5 w-12 rounded-full"},l))})]})}function dr({rows:a=10}){return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"hidden w-full overflow-x-auto sm:block",children:e.jsxs("table",{className:"min-w-max w-full text-left text-sm",children:[e.jsx("thead",{className:"border-b border-oai-gray-200 dark:border-oai-gray-800",children:e.jsxs("tr",{children:[e.jsx("th",{className:c(He,"font-medium text-oai-gray-500 dark:text-oai-gray-400"),children:e.jsx(f,{className:"h-3.5 w-6"})}),e.jsx("th",{className:c(We,"font-medium text-oai-gray-500 dark:text-oai-gray-400"),children:e.jsx(f,{className:"h-3.5 w-12"})}),e.jsx("th",{className:"px-4 py-4",children:e.jsx(f,{className:"h-3.5 w-10"})}),e.jsx("th",{className:"px-4 py-4",children:e.jsx(f,{className:"h-3.5 w-14"})}),X.map(r=>e.jsx("th",{className:"px-4 py-4",children:e.jsx(f,{className:"h-3.5 w-12"})},r.key))]})}),e.jsx("tbody",{className:"divide-y divide-oai-gray-100 dark:divide-oai-gray-800/50",children:Array.from({length:a},(r,o)=>e.jsx(nr,{index:o},o))})]})}),e.jsx("div",{className:"flex flex-col py-1 sm:hidden",children:Array.from({length:a},(r,o)=>e.jsx(lr,{index:o},o))})]})}function cr({id:a,thClassName:r,children:o}){const{attributes:i,listeners:l,setNodeRef:n,transform:m,transition:p,isDragging:u}=Ra({id:a}),h=Ia.Transform.toString(m)||"";d.useLayoutEffect(()=>{const y=document.querySelectorAll(`td[data-column-key="${a}"]`),b="0 2px 10px rgba(15, 23, 42, 0.10), 0 1px 3px rgba(15, 23, 42, 0.06)";return y.forEach(x=>{x.style.transform=h,x.style.transition=p||"",x.style.zIndex=u?"20":"",x.style.position=h?"relative":"",x.style.boxShadow=u?b:""}),()=>{y.forEach(x=>{x.style.transform="",x.style.transition="",x.style.zIndex="",x.style.position="",x.style.boxShadow=""})}},[a,h,p,u]);const v={transform:h,transition:p,position:h?"relative":void 0,zIndex:u?20:void 0,boxShadow:u?"0 2px 10px rgba(15, 23, 42, 0.10), 0 1px 3px rgba(15, 23, 42, 0.06)":void 0};return e.jsx("th",{ref:n,style:v,className:c(r,"group/col select-none cursor-grab active:cursor-grabbing touch-none"),...i,...l,children:e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx("span",{"aria-hidden":"true",className:c("-mr-1 inline-flex h-4 w-3 shrink-0 items-center justify-center text-oai-gray-400 dark:text-oai-gray-600","opacity-0 transition-opacity duration-150 group-hover/col:opacity-100",u&&"opacity-100"),children:e.jsxs("svg",{viewBox:"0 0 8 14",width:"8",height:"14",fill:"currentColor","aria-hidden":"true",children:[e.jsx("circle",{cx:"2",cy:"2",r:"1"}),e.jsx("circle",{cx:"6",cy:"2",r:"1"}),e.jsx("circle",{cx:"2",cy:"7",r:"1"}),e.jsx("circle",{cx:"6",cy:"7",r:"1"}),e.jsx("circle",{cx:"2",cy:"12",r:"1"}),e.jsx("circle",{cx:"6",cy:"12",r:"1"})]})}),o]})})}const mr="tokentracker.leaderboard.columnOrder.v1";function gr(a){return Xa(mr,a)}const ur=50;function xr(a,r){const o=Number(a),i=Number(r);return!Number.isFinite(o)||o<1||!Number.isFinite(i)||i<1?null:Math.min(100,Math.max(1,Math.ceil(o/i*100)))}function Ye(a){return typeof a=="string"?a.trim():""}function pr(a){const r=Ye(a);return r?r.toLowerCase()==="anonymous":!0}function br({me:a,totalEntries:r,meLabel:o,onOpenProfile:i,onJumpToMe:l,canJump:n,className:m}){const p=a&&typeof a.rank=="number"?a.rank:null;if(!p)return null;const u=Number(r)||0,h=xr(p,u),v=Ye(a?.display_name),y=!v||pr(v)?o||"You":v,b=a?.user_id||y,x=i||(n?l:null),E=typeof x=="function",C=E?"button":"div",ee=E?{type:"button",onClick:x,"aria-label":s(i?"leaderboard.summary.view_profile":"leaderboard.summary.jump_to_me")}:{};return e.jsxs(C,{...ee,className:c("group inline-flex h-9 items-center gap-2.5 rounded-full border pl-1 pr-3.5 transition-all duration-300 select-none",E?"border-oai-gray-200 hover:border-oai-gray-400 dark:border-oai-gray-800 dark:hover:border-oai-gray-500/80 bg-oai-gray-50/50 dark:bg-white/[0.02] backdrop-blur-md hover:bg-oai-gray-100/40 dark:hover:bg-oai-gray-900/20 active:scale-[0.97] dark:ring-1 dark:ring-white/[0.04] dark:hover:ring-white/[0.08]":"border-oai-gray-100 dark:border-oai-gray-800/60 bg-oai-gray-50/20 dark:bg-white/[0.01] backdrop-blur-sm dark:ring-1 dark:ring-white/[0.02]",m),children:[e.jsx(q,{size:"sm",avatarUrl:a?.avatar_url,displayName:y,seed:b,proActive:a?.pro_active===!0}),e.jsx("span",{className:"hidden sm:inline max-w-[120px] truncate text-xs font-semibold text-oai-black dark:text-oai-gray-200 group-hover:text-oai-gray-800 dark:group-hover:text-oai-gray-100 transition-colors",children:y}),a?.pro_active===!0&&e.jsx("span",{className:"leaderboard-pro-badge",role:"img","aria-label":s("leaderboard.pro.badge_aria"),"aria-description":s("leaderboard.pro.tooltip"),children:s("leaderboard.pro.badge")}),e.jsxs("span",{className:"text-xs font-bold tabular-nums text-oai-gray-800 dark:text-white",children:["#",p.toLocaleString()]}),h!=null&&h<=ur&&e.jsx("span",{className:"hidden sm:inline-flex items-center rounded-full px-2 py-0.5 text-[9px] font-extrabold tracking-wider tabular-nums uppercase transition-colors duration-300 ring-1 bg-oai-gray-100 text-oai-gray-700 dark:bg-oai-gray-800 dark:text-oai-gray-300 ring-oai-gray-300/30 dark:ring-oai-gray-600/30",children:s("leaderboard.summary.percentile",{p:String(h)})}),E?e.jsx(Qa,{"aria-hidden":!0,className:"size-3 text-oai-gray-400 transition-all duration-300 group-hover:text-oai-gray-600 dark:text-oai-gray-500 group-hover:translate-x-0.5 group-hover:scale-110"}):e.jsxs("span",{className:"relative flex h-1.5 w-1.5 shrink-0 items-center justify-center ml-1",title:"You are here",children:[e.jsx("span",{className:"absolute inline-flex h-full w-full animate-ping rounded-full bg-oai-gray-400 opacity-75 duration-1000"}),e.jsx("span",{className:"relative inline-flex h-1.5 w-1.5 rounded-full bg-oai-gray-400 dark:bg-oai-gray-500"})]})]})}const hr=d.lazy(()=>Ge(()=>import("./LeaderboardProfileModal-vbPMNn7W.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28])).then(a=>({default:a.LeaderboardProfileModal}))),yr=d.lazy(()=>Ge(()=>import("./CommunityStatsModal-CizxEYv-.js"),__vite__mapDeps([29,1,2,22,30,5,15,31,4,32,33,6,34,12,11,35,14,13,24,16,17,18,19,20,28,36,37])).then(a=>({default:a.CommunityStatsModal}))),me=[10,20,50,100],ge=20,Ve="tokentracker:leaderboard:pageSize";function fr(){if(typeof window>"u")return ge;try{const a=window.localStorage.getItem(Ve),r=Number(a);if(me.includes(r))return r}catch{}return ge}function ue(a,r,o){const i=Number(a);if(!Number.isFinite(i)||i<=0)return"-";const l=Sa(r),n=r===Ma?i:i*o;return n>=1e3?`${l}${Math.round(n).toLocaleString()}`:n>=10?`${l}${Math.round(n)}`:`${l}${n.toFixed(2)}`}function kr(a){if(typeof a!="string"||!a.trim())return null;const r=new Date(a);if(!Number.isFinite(r.getTime()))return null;const o=Ta();return{dateTime:r.toISOString(),display:new Intl.DateTimeFormat(o,{dateStyle:"medium",timeStyle:"short"}).format(r),exact:new Intl.DateTimeFormat(o,{dateStyle:"full",timeStyle:"long"}).format(r)}}function xe({value:a}){const{formatTokens:r,formatTokensTooltip:o}=Q();return e.jsx("span",{title:o(a),children:r(a)})}function wr({communityStats:a,onClick:r}){const{formatTokens:o,formatTokensTooltip:i}=Q();return a.status!=="ready"?null:e.jsxs("button",{type:"button",onClick:r,className:"inline-flex min-w-0 max-w-full flex-1 items-center gap-1.5 whitespace-nowrap rounded-xl border border-oai-gray-200 bg-oai-gray-50/50 px-2.5 py-2 text-xs text-oai-gray-500 backdrop-blur-md transition-all duration-300 hover:border-oai-gray-400 hover:bg-oai-gray-100/40 active:scale-[0.97] dark:border-oai-gray-800 dark:bg-white/[0.02] dark:text-oai-gray-400 dark:hover:border-oai-gray-500/80 dark:hover:bg-oai-gray-900/20 sm:h-9 sm:flex-none sm:gap-2.5 sm:rounded-full sm:px-3.5 sm:py-0",title:s("leaderboard.community.view_stats"),children:[e.jsxs("span",{className:"relative flex h-1.5 w-1.5 shrink-0","aria-hidden":"true",children:[e.jsx("span",{className:"absolute inline-flex h-full w-full animate-ping rounded-full bg-oai-gray-400/80 opacity-75 duration-1000"}),e.jsx("span",{className:"relative inline-flex h-1.5 w-1.5 rounded-full bg-oai-gray-400 dark:bg-oai-gray-500"})]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"font-semibold text-oai-black dark:text-white tabular-nums",children:e.jsx("span",{title:i(a.tokenFloor),children:o(a.tokenFloor)})}),e.jsx("span",{className:"text-[10px] text-oai-gray-400 dark:text-oai-gray-500",children:s("leaderboard.community.tokens_chip")})]}),e.jsx("span",{className:"text-oai-gray-200 dark:text-oai-gray-800 select-none",children:"·"}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsxs("span",{className:"font-semibold text-oai-black dark:text-white tabular-nums",children:[e.jsx("span",{className:"sm:hidden",children:Ca(a.totalEntries)}),e.jsx("span",{className:"hidden sm:inline",children:(Number(a.totalEntries)||0).toLocaleString("en-US")})]}),e.jsx("span",{className:"text-[10px] text-oai-gray-400 dark:text-oai-gray-500",children:s("leaderboard.community.devs_chip")})]})]})}function $e({entry:a,isMe:r,orderedColumns:o}){const{formatTokens:i,formatTokensTooltip:l}=Q(),n=r?"text-oai-gray-700 dark:text-oai-gray-300":"text-oai-gray-500 dark:text-oai-gray-400",m=r?"bg-oai-gray-50 dark:bg-oai-gray-900":"bg-white dark:bg-oai-gray-950 group-hover:bg-oai-gray-50 dark:group-hover:bg-oai-gray-900";return o.map(p=>e.jsx("td",{"data-column-key":p.key,title:l(a?.[p.key]),className:c("hidden sm:table-cell px-3 sm:px-4 py-4 whitespace-nowrap text-right tabular-nums",n,m),children:i(a?.[p.key])},p.key))}function vr(a){return a?.key==="gpt_tokens"?"CODEX":a?.key==="claude_tokens"?"CLAUDE":(a?.icon?.split("/").pop()||"").replace(/\.svg$/i,"").toUpperCase()||"OTHER"}const jr={1:"ring-2 ring-amber-400 dark:ring-amber-500/80 shadow-[0_0_8px_rgba(245,158,11,0.25)]",2:"ring-2 ring-slate-350 dark:ring-slate-450 shadow-[0_0_8px_rgba(148,163,184,0.2)]",3:"ring-2 ring-orange-400 dark:ring-orange-500/70 shadow-[0_0_8px_rgba(249,115,22,0.25)]"};function Nr({rank:a,placeholder:r}){return a===1?e.jsx("span",{className:"text-base font-extrabold italic text-amber-500 dark:text-amber-400 tracking-tighter",children:"1"}):a===2?e.jsx("span",{className:"text-base font-extrabold italic text-slate-400 dark:text-slate-350 tracking-tighter",children:"2"}):a===3?e.jsx("span",{className:"text-base font-extrabold italic text-orange-500 dark:text-orange-400 tracking-tighter",children:"3"}):e.jsx("span",{className:"text-[13px] font-bold tabular-nums text-oai-gray-400 dark:text-oai-gray-500",children:a==null?r:`#${a}`})}function _r({githubUrl:a}){return e.jsx("a",{href:a,target:"_blank",rel:"noopener noreferrer",onClick:r=>r.stopPropagation(),"aria-label":"GitHub profile",className:"absolute bottom-0 right-0 translate-x-1 translate-y-1 flex h-4.5 w-4.5 items-center justify-center rounded-full bg-white dark:bg-oai-gray-950 text-oai-black dark:text-oai-gray-100 shadow border border-oai-gray-100 dark:border-oai-gray-800 transition-transform active:scale-110",children:e.jsx(ye,{provider:"GITHUB",size:11})})}function Sr({entry:a,orderedColumns:r}){const{formatTokens:o,formatTokensTooltip:i}=Q(),l=r.filter(n=>{const m=Number(a?.[n.key]);return Number.isFinite(m)&&m>0});return l.length===0?null:e.jsx("div",{className:"mt-3 flex flex-wrap items-center gap-x-1.5 gap-y-2 border-t border-oai-gray-100/70 pt-3 dark:border-oai-gray-800/60",children:l.map(n=>{const m=s(n.copyKey);return e.jsxs("span",{title:m,"aria-label":`${m}: ${i(a?.[n.key])}`,className:"inline-flex shrink-0 items-center gap-1 rounded-full bg-oai-gray-50/80 dark:bg-oai-gray-900/60 px-2 py-0.5 border border-oai-gray-100/80 dark:border-oai-gray-800/40 text-[10px] font-medium text-oai-gray-600 dark:text-oai-gray-300 transition-colors",children:[e.jsx(ye,{provider:vr(n),size:12,className:"shrink-0 opacity-90"}),e.jsx("span",{className:"tabular-nums",children:o(a?.[n.key])})]},n.key)})})}function Cr({entry:a,entryIdx:r,name:o,meLabel:i,currency:l,rate:n,orderedColumns:m,placeholder:p,onOpenProfile:u}){if(a?.is_ellipsis)return e.jsx("div",{"aria-hidden":"true",className:"px-4 py-2 text-center text-xs tracking-[0.4em] text-oai-gray-400 dark:text-oai-gray-600",children:"···"},`mobile-ellipsis-${r}`);const h=!!a?.is_me,v=!h&&be(a?.display_name),y=typeof a?.user_id=="string"?a.user_id:null,b=!!y,x=h?i:o,E=C=>{(C.key==="Enter"||C.key===" ")&&(C.preventDefault(),u(y))};return e.jsxs("div",{role:b?"button":void 0,tabIndex:b?0:void 0,onClick:b?()=>u(y):void 0,onKeyDown:b?E:void 0,"aria-label":b?s("leaderboard.profile_modal.row_aria",{name:x}):void 0,className:c("relative mx-0 my-1 rounded-xl px-3.5 py-3 transition-all duration-200 border shadow-sm select-none",h?"bg-oai-gray-50 dark:bg-oai-gray-900 border-oai-gray-300/60 dark:border-oai-gray-500/25":v?"bg-white/90 dark:bg-oai-gray-950/90 border-oai-gray-100/70 dark:border-oai-gray-800/40":"bg-white dark:bg-oai-gray-950 border-oai-gray-100 dark:border-oai-gray-800/60",b&&"cursor-pointer hover:border-oai-gray-200 dark:hover:border-oai-gray-700/80 active:scale-[0.985] active:bg-oai-gray-50/60 dark:active:bg-oai-gray-900/40 focus:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:ring-oai-gray-500/60"),children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[e.jsx("span",{className:"flex w-5 shrink-0 items-center justify-center",children:e.jsx(Nr,{rank:a?.rank,placeholder:p})}),e.jsxs("span",{className:"relative inline-flex shrink-0",children:[e.jsx("span",{className:c("inline-flex rounded-full p-0.5 transition-all duration-300",a?.pro_active!==!0&&(jr[a?.rank]||"ring-1 ring-oai-gray-200 dark:ring-oai-gray-800/80"),v&&"opacity-60 grayscale-[15%]"),children:e.jsx(q,{size:"md",avatarUrl:a?.avatar_url,displayName:x,seed:he(a,x),proActive:a?.pro_active===!0})}),a?.github_url&&e.jsx(_r,{githubUrl:a.github_url})]}),e.jsxs("div",{className:"min-w-0 flex-1 pl-1",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-1.5",children:[e.jsx("span",{className:c("min-w-0 truncate text-sm tracking-tight",h?"font-semibold text-oai-black dark:text-oai-white":v?"font-normal text-oai-gray-400 dark:text-oai-gray-500":"font-medium text-oai-gray-800 dark:text-oai-gray-200"),children:x}),e.jsx(ne,{proActive:a?.pro_active===!0}),e.jsx(le,{badges:a?.badges,className:"shrink-0 scale-95"})]}),e.jsxs("div",{className:"mt-1 text-[11px] text-oai-gray-400 dark:text-oai-gray-500",children:[e.jsx("span",{children:s("leaderboard.column.est_cost")}),e.jsx("span",{className:c("ml-1 tabular-nums font-medium",v?"text-oai-gray-400/80 dark:text-oai-gray-500/80":"text-oai-gray-600 dark:text-oai-gray-300"),children:ue(a?.estimated_cost_usd,l,n)})]})]}),e.jsxs("div",{className:"shrink-0 text-right",children:[e.jsx("div",{className:"text-[9px] font-semibold uppercase tracking-[0.08em] text-oai-gray-400 dark:text-oai-gray-500",children:s("leaderboard.column.total")}),e.jsx("div",{className:c("mt-0.5 text-sm font-semibold tabular-nums tracking-tight",h?"text-oai-black dark:text-oai-white":v?"text-oai-gray-400 dark:text-oai-gray-500":"text-oai-gray-800 dark:text-oai-gray-200"),children:e.jsx(xe,{value:a?.total_tokens})})]})]}),e.jsx(Sr,{entry:a,orderedColumns:m})]},`mobile-row-${a?.rank}-${x}`)}const Ar={1:{text:"text-amber-600 dark:text-amber-400",badge:"bg-amber-50 dark:bg-amber-900/20"},2:{text:"text-gray-500 dark:text-gray-300",badge:"bg-gray-50 dark:bg-gray-800/40"},3:{text:"text-orange-700 dark:text-orange-400",badge:"bg-orange-50 dark:bg-orange-900/20"}};function Ue({rank:a,placeholder:r}){const o=Ar[a];return o?e.jsx("span",{className:c("inline-flex items-center justify-center h-7 w-7 rounded-full text-xs font-bold",o.text,o.badge),children:a}):e.jsx("span",{className:"inline-flex items-center justify-center h-7 w-7 text-sm",children:a??r})}function Oe(a){if(typeof a!="string")return null;const r=a.trim().toLowerCase();return r==="week"||r==="month"||r==="total"?r:null}function Lr(a){if(!a)return s("shared.error.prefix",{error:s("leaderboard.error.unknown")});const r=a?.message||String(a),o=String(r||"").trim()||s("leaderboard.error.unknown");return s("shared.error.prefix",{error:o})}function pe(a){return typeof a!="string"?"":a.trim()}function be(a){const r=pe(a);return r?r.toLowerCase()==="anonymous":!0}function he(a,r){const o=typeof a?.user_id=="string"?a.user_id.trim():"";return o||`${a?.rank??""}:${r}`}function Fe({githubUrl:a}){return e.jsxs("span",{className:"absolute left-1/2 top-full -translate-x-1/2 -translate-y-1/2 inline-flex group/gh",children:[e.jsx("a",{href:a,target:"_blank",rel:"noopener noreferrer",onClick:r=>r.stopPropagation(),"aria-label":s("leaderboard.github.aria"),className:"flex h-4 w-4 items-center justify-center rounded-full bg-white dark:bg-oai-gray-950 text-oai-black dark:text-oai-gray-100 transition-transform hover:scale-110",children:e.jsx(ye,{provider:"GITHUB",size:14})}),e.jsxs("span",{role:"tooltip",className:"invisible opacity-0 group-hover/gh:visible group-hover/gh:opacity-100 absolute left-0 bottom-full mb-2 whitespace-nowrap rounded-md bg-oai-black dark:bg-oai-gray-700 px-2.5 py-1.5 text-[11px] leading-relaxed text-white shadow-lg transition-opacity duration-150 z-50 before:content-[''] before:absolute before:inset-x-0 before:top-full before:h-2.5",children:[e.jsx("span",{className:"block",children:s("leaderboard.github.tooltipAction")}),e.jsxs("span",{className:"block text-oai-gray-300 dark:text-oai-gray-400",children:[s("leaderboard.github.tooltipPrefix")," ",e.jsx(_a,{to:"/settings",onClick:r=>r.stopPropagation(),className:"text-white underline underline-offset-2 decoration-oai-gray-400 hover:text-oai-brand-300 hover:decoration-oai-brand-300",children:s("leaderboard.github.tooltipSettingsLink")})," ",s("leaderboard.github.tooltipSuffix")]})]})]})}function tt({auth:a,signedIn:r,sessionSoftExpired:o}){const i=xa(),l=pa(),{openLoginModal:n}=ba(),{signedIn:m,loading:p,user:u}=ha(),{currency:h,rate:v}=Wa(),y=d.useMemo(()=>ya(),[]),b=fa(),x=r&&!o,E=d.useMemo(()=>x&&(typeof a=="function"||typeof a=="string"||a&&typeof a=="object")?a:null,[a,x]),C=x?E:null,ee=x&&ka(C),ae=s("shared.placeholder.short"),Je=d.useMemo(()=>X.map(t=>t.key),[]),{order:re,reorder:fe}=gr(Je),ke=d.useMemo(()=>{const t=new Map;for(const g of X)t.set(g.key,g);return t},[]),B=d.useMemo(()=>re.map(t=>ke.get(t)).filter(Boolean),[re,ke]),Ze=za(De(Ga,{activationConstraint:{distance:6}}),De(Fa,{coordinateGetter:Oa})),qe=d.useCallback(t=>{const{active:g,over:w}=t;!w||g.id===w.id||fe(String(g.id),String(w.id))},[fe]),[te,M]=d.useState(1),[_,Xe]=d.useState(fr),[we,ve]=d.useState(null),[Qe,je]=d.useState(!1),W=d.useCallback(t=>{typeof t=="string"&&t.trim()&&ve(t.trim())},[]),ea=d.useCallback(()=>ve(null),[]),aa=d.useCallback(t=>{const g=me.includes(t)?t:ge;Xe(g),M(1);try{window.localStorage.setItem(Ve,String(g))}catch{}},[]),[Ne,ra]=d.useState(0),[ta,oa]=d.useState(()=>wa()),[_e,Se]=d.useState(!1);d.useEffect(()=>{if(typeof window>"u")return;const t=()=>{ra(g=>g+1)};return window.addEventListener(Be,t),()=>{window.removeEventListener(Be,t)}},[]);const N=d.useMemo(()=>{const t=new URLSearchParams(i?.search||"");return Oe(t.get("period"))||"total"},[i?.search]),sa=t=>{const g=Oe(t);if(!g||g===N)return;const w=new URLSearchParams(i?.search||"");w.set("period",g),M(1),l(`${i?.pathname||"/leaderboard"}?${w.toString()}`,{replace:!0})};d.useEffect(()=>{p||b||m||n()},[m,p,b,n]),d.useEffect(()=>{M(1)},[N]);const Y=d.useMemo(()=>(H(te,{min:1,max:1e6,fallback:1})-1)*_,[te,_]),R=d.useMemo(()=>b?"mock":p?"unavailable":m?"cloud":r?"local":y?"public":"unavailable",[p,m,y,b,r]),k=d.useMemo(()=>va({accessMode:R,baseUrl:y,mockEnabled:b,userId:u?.id||null,period:N,pageSize:_,offset:Y}),[u?.id,R,y,Y,b,_,N]),[D,$]=d.useState(()=>{const t=ie(k);return t?{loading:!1,error:null,data:t.data,contextKey:k}:{loading:!1,error:null,data:null,contextKey:null}});d.useEffect(()=>{if(!y&&!b||!b&&R==="unavailable"){$({loading:!1,error:null,data:null,contextKey:null});return}const t=ie(k);let g=!0;return $(t?{loading:!1,error:null,data:t.data,contextKey:k}:{loading:!0,error:null,data:null,contextKey:null}),(async()=>{const w=await ja({userId:u?.id||null,period:N,limit:_,offset:Y});g&&(Na(w,{activeContextKey:k,contextKey:k,source:Ne>0?"manual-refresh":"page-load"}),$({loading:!1,error:null,data:w,contextKey:k}))})().catch(w=>{if(!g)return;const T=Lr(w);$(F=>F.contextKey===k?{...F,loading:!1,error:T}:{loading:!1,error:T,data:null,contextKey:k})}),()=>{g=!1}},[y,R,u?.id,k,Y,Ne,b,N,_]);const oe=d.useMemo(()=>D.contextKey===k?null:ie(k),[k,D.contextKey]),j=d.useMemo(()=>D.contextKey===k?D:oe?{loading:!1,error:null,data:oe.data,contextKey:k}:{loading:!!(y||b)&&R!=="unavailable",error:null,data:null,contextKey:k},[R,y,k,D,b,oe]),S=j.data,U=S?.total_pages??null,ia=S?.total_entries??0,P=S?.page??te,na=d.useMemo(()=>ar(P,U),[P,U]),Ce=S?.from||null,Ae=S?.to||null,la=S?.generated_at||null,V=kr(la),Le=er(),K=S?.me||null,I=s("leaderboard.me_label"),Ee=s("leaderboard.anon_label"),Te=s("leaderboard.period.week"),Me=s("leaderboard.period.month"),Pe=s("leaderboard.period.total"),Ke=N==="month"?Me:N==="total"?Pe:Te,J=d.useMemo(()=>{const t=Array.isArray(S?.entries)?S.entries:[];return tr({entries:t,me:K,meLabel:I})},[S?.entries,K,I]),z=d.useMemo(()=>or(K?.rank,_),[K?.rank,_]),da=z!=null&&z===P,ca=d.useCallback(()=>{z!=null&&M(z)},[z]),ma=async()=>{Se(!0);try{Aa(!0),oa(!0),await La(()=>Ea(C))}catch(t){console.warn("[tokentracker] sync:",t)}finally{Se(!1)}},{canPrev:Re,canNext:Ie}=rr({page:P,totalPages:U}),Z=Array.isArray(J)&&J.length!==0;let O=null;j.loading&&!Z?O=e.jsx(dr,{rows:_}):j.error&&!Z?O=e.jsx("div",{className:"px-6 py-12 text-center",children:e.jsx("p",{className:"text-sm text-red-500 dark:text-red-400",children:j.error})}):Z?O=e.jsxs(Ba,{sensors:Ze,collisionDetection:Da,modifiers:[Ha],onDragEnd:qe,children:[e.jsx("div",{className:"hidden w-full overflow-x-auto sm:block",children:e.jsxs("table",{className:"min-w-full w-full text-left text-sm sm:min-w-max",children:[e.jsx("thead",{className:"border-b border-oai-gray-200 dark:border-oai-gray-800",children:e.jsxs("tr",{children:[e.jsx("th",{className:c(He,"text-[11px] font-semibold uppercase tracking-wider text-oai-gray-400 dark:text-oai-gray-500"),children:s("leaderboard.column.rank")}),e.jsx("th",{className:c(We,"text-[11px] font-semibold uppercase tracking-wider text-oai-gray-400 dark:text-oai-gray-500"),children:s("leaderboard.column.user")}),e.jsx("th",{className:"px-3 sm:px-4 py-4 text-[11px] font-semibold uppercase tracking-wider text-oai-gray-400 dark:text-oai-gray-500 whitespace-nowrap text-right align-middle",children:s("leaderboard.column.total")}),e.jsx("th",{className:"hidden sm:table-cell px-3 sm:px-4 py-4 text-[11px] font-semibold uppercase tracking-wider text-oai-gray-400 dark:text-oai-gray-500 whitespace-nowrap text-right align-middle",title:"Based on estimated API pricing, not actual billing",children:s("leaderboard.column.est_cost")}),e.jsx($a,{items:re,strategy:Ua,children:B.map(t=>e.jsx(cr,{id:t.key,thClassName:"hidden sm:table-cell px-3 sm:px-4 py-4 text-[11px] font-semibold uppercase tracking-wider text-oai-gray-400 dark:text-oai-gray-500 whitespace-nowrap align-middle",children:e.jsx(ir,{iconSrc:t.icon,label:s(t.copyKey)})},t.key))})]})}),e.jsx("tbody",{className:"divide-y divide-oai-gray-100 dark:divide-oai-gray-800/50",children:J.map((t,g)=>{if(t?.is_ellipsis){const L=4+B.length;return e.jsx("tr",{"aria-hidden":"true",children:e.jsx("td",{colSpan:L,className:"px-4 py-2 text-center text-oai-gray-400 dark:text-oai-gray-600 bg-white dark:bg-oai-gray-950 select-none tracking-[0.4em] text-xs",children:"···"})},`ellipsis-${g}`)}const w=!!t?.is_me,T=typeof t?.user_id=="string"?t.user_id:null,F=pe(t?.display_name),ga=be(F)?Ee:F,A=w?I:ga,G=!!T,ze=G?{role:"button",tabIndex:0,onClick:G?()=>W(T):void 0,onKeyDown:G?L=>{(L.key==="Enter"||L.key===" ")&&(L.preventDefault(),W(T))}:void 0,"aria-label":s("leaderboard.profile_modal.row_aria",{name:A})}:{};if(w){const L=!!t?.is_pinned;return e.jsxs("tr",{...ze,className:c("bg-oai-gray-50 dark:bg-oai-gray-900 transition-colors",L?"border-t border-b border-oai-gray-300/40 dark:border-oai-gray-500/20":"border-y border-oai-gray-300/40 dark:border-oai-gray-500/30",G&&"cursor-pointer focus:outline-none focus-visible:ring-2 focus-visible:ring-oai-gray-500/60"),children:[e.jsx("td",{className:c(de(!0),"font-semibold text-oai-gray-700 dark:text-oai-gray-300",L&&"before:absolute before:left-0 before:top-[15%] before:h-[70%] before:w-[3px] before:rounded-r before:bg-oai-gray-500 dark:before:bg-oai-gray-400"),children:e.jsx(Ue,{rank:t?.rank,placeholder:ae})}),e.jsx("td",{className:ce(!0),children:e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsxs("span",{className:c("relative inline-flex shrink-0 rounded-full p-[2px]",t?.github_url&&t?.pro_active!==!0&&"gh-avatar-frame"),children:[e.jsx("span",{className:c("inline-flex rounded-full p-px",t?.github_url&&t?.pro_active!==!0&&"bg-white dark:bg-oai-gray-950"),children:e.jsx(q,{avatarUrl:t?.avatar_url,displayName:A,seed:he(t,A),proActive:t?.pro_active===!0})}),t?.github_url&&e.jsx(Fe,{githubUrl:t.github_url})]}),e.jsx("span",{className:"truncate font-semibold text-oai-black dark:text-oai-white",children:A}),e.jsx(ne,{proActive:t?.pro_active===!0}),e.jsx(le,{badges:t?.badges,className:"hidden sm:inline-flex"})]})}),e.jsx("td",{className:"px-3 sm:px-4 py-4 font-medium text-oai-black dark:text-oai-white whitespace-nowrap text-right tabular-nums bg-oai-gray-50 dark:bg-oai-gray-900",children:e.jsx(xe,{value:t?.total_tokens})}),e.jsx("td",{className:"hidden sm:table-cell px-3 sm:px-4 py-4 font-medium text-oai-gray-700 dark:text-oai-gray-300 whitespace-nowrap text-right tabular-nums bg-oai-gray-50 dark:bg-oai-gray-900",title:"Based on estimated API pricing, not actual billing",children:ue(t?.estimated_cost_usd,h,v)}),e.jsx($e,{entry:t,isMe:!0,orderedColumns:B})]},`row-${t?.rank}-${A}${L?"-pin":""}`)}return e.jsxs("tr",{...ze,className:c("group transition-colors",G&&"cursor-pointer hover:bg-oai-gray-50 dark:hover:bg-oai-gray-900/60 focus:outline-none focus-visible:ring-2 focus-visible:ring-oai-gray-500/60"),children:[e.jsx("td",{className:c(de(!1),"font-medium text-oai-gray-500 dark:text-oai-gray-400"),children:e.jsx(Ue,{rank:t?.rank,placeholder:ae})}),e.jsx("td",{className:ce(!1),children:e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsxs("span",{className:c("relative inline-flex shrink-0 rounded-full p-[2px]",t?.github_url&&t?.pro_active!==!0&&"gh-avatar-frame"),children:[e.jsx("span",{className:c("inline-flex rounded-full p-px",t?.github_url&&t?.pro_active!==!0&&"bg-white dark:bg-oai-gray-950"),children:e.jsx(q,{avatarUrl:t?.avatar_url,displayName:A,seed:he(t,A),proActive:t?.pro_active===!0})}),t?.github_url&&e.jsx(Fe,{githubUrl:t.github_url})]}),e.jsx("span",{className:"truncate font-medium text-oai-gray-800 dark:text-oai-gray-200",children:A}),e.jsx(ne,{proActive:t?.pro_active===!0}),e.jsx(le,{badges:t?.badges,className:"hidden sm:inline-flex"})]})}),e.jsx("td",{className:"px-3 sm:px-4 py-4 font-semibold text-oai-gray-800 dark:text-oai-gray-200 whitespace-nowrap text-right tabular-nums bg-white dark:bg-oai-gray-950 group-hover:bg-oai-gray-50 dark:group-hover:bg-oai-gray-900/60",children:e.jsx(xe,{value:t?.total_tokens})}),e.jsx("td",{className:"hidden sm:table-cell px-3 sm:px-4 py-4 text-oai-gray-500 dark:text-oai-gray-400 whitespace-nowrap text-right tabular-nums bg-white dark:bg-oai-gray-950 group-hover:bg-oai-gray-50 dark:group-hover:bg-oai-gray-900/60",title:"Based on estimated API pricing, not actual billing",children:ue(t?.estimated_cost_usd,h,v)}),e.jsx($e,{entry:t,isMe:!1,orderedColumns:B})]},`row-${t?.rank}-${A}`)})})]})}),e.jsx("div",{className:"flex flex-col py-1.5 sm:hidden",children:J.map((t,g)=>{const w=pe(t?.display_name),T=be(w)?Ee:w;return e.jsx(Cr,{entry:t,entryIdx:g,name:t?.is_me?I:T,meLabel:I,currency:h,rate:v,orderedColumns:B,placeholder:ae,onOpenProfile:W},`mobile-${t?.rank??"ellipsis"}-${g}`)})})]}):O=e.jsx("div",{className:"px-6 py-12 text-center",children:e.jsx("p",{className:"text-sm text-oai-gray-500 dark:text-oai-gray-400",children:s("leaderboard.empty")})});let se=null;return typeof U=="number"?se=na.map((t,g)=>t==null?e.jsx("span",{className:"px-2 text-oai-gray-400 dark:text-oai-gray-500",children:s("leaderboard.pagination.ellipsis")},`ellipsis-${g}`):e.jsx("button",{className:c("flex h-8 w-8 items-center justify-center rounded-md text-sm font-medium transition-colors",t===P?"bg-oai-gray-200 dark:bg-oai-gray-800 text-oai-black dark:text-white":"text-oai-gray-500 dark:text-oai-gray-400 hover:bg-oai-gray-100 dark:hover:bg-oai-gray-800 hover:text-oai-black dark:hover:text-white"),onClick:()=>M(t),disabled:j.loading,children:String(t)},`page-${t}`)):se=e.jsx("span",{className:"text-sm text-oai-gray-500 dark:text-oai-gray-400",children:s("leaderboard.pagination.page_unknown",{page:String(P)})}),e.jsxs("div",{className:"flex flex-col flex-1 text-oai-black dark:text-oai-white font-oai antialiased",children:[e.jsx("main",{className:"flex-1 pt-8 sm:pt-10 pb-12 sm:pb-16",children:e.jsxs("div",{className:"mx-auto max-w-6xl px-4 sm:px-6",children:[e.jsxs("div",{className:"mb-4 grid grid-cols-[minmax(0,1fr)_auto] items-center gap-x-3 gap-y-3.5 sm:mb-8 sm:grid-cols-[minmax(0,1fr)_auto] sm:gap-4",children:[e.jsx("h1",{className:"col-start-1 row-start-1 min-w-0 whitespace-nowrap text-3xl font-semibold tracking-tight text-oai-black dark:text-white sm:col-span-2 sm:row-start-1 sm:text-4xl",children:s("leaderboard.title")}),e.jsxs("p",{className:"col-span-2 row-start-2 hidden text-sm text-oai-gray-500 dark:text-oai-gray-400 sm:block sm:row-start-2 sm:text-base",children:[N==="total"?s("leaderboard.range.total"):Ce&&Ae?s("leaderboard.range",{period:Ke,from:Ce,to:Ae}):s("leaderboard.range_loading",{period:Ke}),V&&e.jsx("time",{dateTime:V.dateTime,title:s("leaderboard.generated_at",{ts:V.exact}),className:"ml-2 hidden border-l border-oai-gray-200 pl-2 text-xs text-oai-gray-500 dark:border-oai-gray-800 dark:text-oai-gray-400 sm:inline-block",children:s("leaderboard.generated_at",{ts:V.display})})]}),e.jsx("div",{className:"col-start-2 row-start-1 inline-flex h-9 shrink-0 items-center rounded-full border border-oai-gray-200 p-1 dark:border-oai-gray-800 sm:col-start-1 sm:row-start-3 sm:justify-self-start",children:["week","month","total"].map(t=>{const g=N===t;return e.jsxs("button",{onClick:()=>sa(t),disabled:j.loading,className:c("px-3 sm:px-4 h-7 text-sm font-medium rounded-full flex items-center justify-center transition-colors relative",g?"text-oai-black dark:text-white":"text-oai-gray-500 dark:text-oai-gray-400 hover:text-oai-gray-800 dark:hover:text-oai-gray-200"),children:[e.jsx("span",{className:"relative z-10",children:t==="week"?Te:t==="month"?Me:Pe}),g&&e.jsx(Ka.div,{layoutId:"leaderboard-period-active-bg",className:"absolute inset-0 bg-oai-gray-200 dark:bg-oai-gray-800 rounded-full z-0",transition:{type:"spring",stiffness:380,damping:30}})]},t)})}),e.jsxs("div",{className:"col-span-2 row-start-2 mb-0 flex w-full min-w-0 items-center justify-between sm:justify-end gap-2.5 sm:col-span-1 sm:col-start-2 sm:row-start-3 sm:mb-0 sm:w-auto sm:shrink-0",children:[e.jsx(wr,{communityStats:Le,onClick:()=>je(!0)}),e.jsx(br,{me:K,totalEntries:ia,meLabel:I,onOpenProfile:K?.user_id?()=>W(K.user_id):void 0,onJumpToMe:ca,canJump:z!=null&&!da&&!j.loading,className:"shrink-0"})]})]}),!r&&e.jsxs("div",{className:"mb-6 flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between text-sm",children:[e.jsx("p",{className:"text-oai-gray-500 dark:text-oai-gray-400",children:s("leaderboard.signin_prompt")}),e.jsx("button",{onClick:n,className:"shrink-0 whitespace-nowrap self-start sm:self-auto px-3 py-1.5 text-sm font-medium text-oai-gray-600 dark:text-oai-gray-300 border border-oai-gray-300 dark:border-oai-gray-700 rounded-md hover:text-oai-black dark:hover:text-white hover:border-oai-gray-400 dark:hover:border-oai-gray-600 transition-colors",children:s("leaderboard.signin_button")})]}),x&&ee&&!ta&&e.jsxs("div",{className:"mb-6 flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between text-sm",children:[e.jsx("p",{className:"text-oai-gray-500 dark:text-oai-gray-400",children:s("leaderboard.sync_prompt")}),e.jsx("button",{onClick:ma,disabled:_e,className:"shrink-0 whitespace-nowrap self-start sm:self-auto px-3 py-1.5 text-sm font-medium text-oai-gray-600 dark:text-oai-gray-300 border border-oai-gray-300 dark:border-oai-gray-700 rounded-md hover:text-oai-black dark:hover:text-white hover:border-oai-gray-400 dark:hover:border-oai-gray-600 disabled:opacity-50 transition-colors",children:_e?s("leaderboard.sync_button.busy"):s("leaderboard.sync_button.idle")})]}),e.jsxs("div",{className:"sm:rounded-xl sm:border sm:border-oai-gray-200 sm:dark:border-oai-gray-800 sm:overflow-hidden border-none bg-transparent",children:[j.error&&Z?e.jsx("div",{className:"border-b border-oai-gray-200 dark:border-oai-gray-800 px-6 py-3",children:e.jsx("p",{className:"text-sm text-red-500 dark:text-red-400",children:j.error})}):null,O,e.jsxs("div",{className:"flex flex-col gap-3 sm:border-t border-oai-gray-200 px-4 py-3 sm:flex-row sm:items-center sm:justify-end sm:gap-x-4 sm:px-6 dark:border-oai-gray-800 border-none mt-2.5 sm:mt-0",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 text-sm text-oai-gray-500 dark:text-oai-gray-400 sm:justify-start",children:[e.jsx("label",{htmlFor:"leaderboard-page-size",className:"whitespace-nowrap",children:s("leaderboard.pagination.page_size_label")}),e.jsx(Pa,{id:"leaderboard-page-size",value:_,onValueChange:t=>aa(Number(t)),disabled:j.loading,ariaLabel:s("leaderboard.pagination.page_size_label"),options:me.map(t=>({value:t,label:String(t)})),align:"end",className:"px-3 py-1 text-oai-gray-700 dark:text-oai-gray-300"})]}),e.jsx("div",{className:"hidden h-5 w-px bg-oai-gray-200 dark:bg-oai-gray-800 sm:block","aria-hidden":"true"}),e.jsxs("div",{className:"flex w-full items-center justify-between sm:w-auto sm:justify-end gap-1.5",children:[e.jsx("button",{className:c("whitespace-nowrap rounded-xl border border-oai-gray-100 bg-oai-gray-50/50 px-3.5 py-2 text-xs font-medium text-oai-gray-500 dark:border-oai-gray-800/80 dark:bg-white/[0.01] dark:text-oai-gray-400 transition-all duration-200 active:scale-[0.97] sm:rounded-md sm:border-0 sm:bg-transparent sm:px-3 sm:py-1.5 sm:text-sm sm:font-medium sm:active:scale-100",Re&&!j.loading?"hover:bg-oai-gray-100 dark:hover:bg-oai-gray-800 hover:text-oai-black dark:hover:text-white":"opacity-50 cursor-not-allowed"),onClick:()=>M(t=>Math.max(1,t-1)),disabled:!Re||j.loading,children:s("leaderboard.pagination.prev")}),e.jsxs("span",{className:"text-xs font-semibold tabular-nums text-oai-gray-500 dark:text-oai-gray-455 px-2 sm:hidden",children:[P," / ",U||"?"]}),e.jsx("div",{className:"hidden sm:flex items-center gap-1",children:se}),e.jsx("button",{className:c("whitespace-nowrap rounded-xl border border-oai-gray-100 bg-oai-gray-50/50 px-3.5 py-2 text-xs font-medium text-oai-gray-500 dark:border-oai-gray-800/80 dark:bg-white/[0.01] dark:text-oai-gray-400 transition-all duration-200 active:scale-[0.97] sm:rounded-md sm:border-0 sm:bg-transparent sm:px-3 sm:py-1.5 sm:text-sm sm:font-medium sm:active:scale-100",Ie&&!j.loading?"hover:bg-oai-gray-100 dark:hover:bg-oai-gray-800 hover:text-oai-black dark:hover:text-white":"opacity-50 cursor-not-allowed"),onClick:()=>M(t=>t+1),disabled:!Ie||j.loading,children:s("leaderboard.pagination.next")})]})]})]})]})}),e.jsx("footer",{className:"border-t border-oai-gray-200 dark:border-oai-gray-900 py-8 transition-colors duration-200",children:e.jsxs("div",{className:"mx-auto flex max-w-6xl items-center justify-between px-4 sm:px-6 text-sm text-oai-gray-400 dark:text-oai-gray-500",children:[e.jsx("p",{children:s("landing.v2.footer.line")}),e.jsx("a",{href:"https://github.com/xiufengsun/TokenTracker",className:"text-oai-gray-400 dark:text-oai-gray-500 hover:text-oai-black dark:hover:text-white transition-colors",target:"_blank",rel:"noopener noreferrer",children:s("landing.v2.nav.github")})]})}),e.jsxs(d.Suspense,{fallback:null,children:[e.jsx(hr,{isOpen:!!we,userId:we,period:N,accessToken:C,onClose:ea}),e.jsx(yr,{isOpen:Qe,onClose:()=>je(!1),communityStats:Le})]})]})}export{tt as LeaderboardPage};
|