tokentracker-cli 0.93.7 → 0.94.0
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 +1 -1
- package/README.ja.md +1 -1
- package/README.ko.md +1 -1
- package/README.md +1 -1
- package/README.zh-CN.md +1 -1
- package/dashboard/dist/assets/{AchievementBadge-DqvblIQY.js → AchievementBadge-DPqwk2zI.js} +1 -1
- package/dashboard/dist/assets/{AchievementsPage-C-xm27pB.js → AchievementsPage-CELHoMQt.js} +2 -2
- package/dashboard/dist/assets/{AchievementsSection-D8Oe2FGJ.js → AchievementsSection-DdAC0VCb.js} +1 -1
- package/dashboard/dist/assets/{BadgeDetailModal-BJOcOnHo.js → BadgeDetailModal-Dd4I1SpM.js} +1 -1
- package/dashboard/dist/assets/{BotAnimated-6fB046ld.js → BotAnimated-DL2-4mnm.js} +1 -1
- package/dashboard/dist/assets/{Card-BKbWtBaL.js → Card-B_MpSRse.js} +1 -1
- package/dashboard/dist/assets/{ClawdAnimated-DbpeAldp.js → ClawdAnimated-BLZZ4rG6.js} +2 -2
- package/dashboard/dist/assets/{CommandPalette-Jte7TBon.js → CommandPalette-B-vfdIbH.js} +1 -1
- package/dashboard/dist/assets/{CommunityStatsModal-DDm7tCXO.js → CommunityStatsModal-aAico565.js} +1 -1
- package/dashboard/dist/assets/{ConfirmModal-CrIjcrpZ.js → ConfirmModal-DLnRwUXC.js} +1 -1
- package/dashboard/dist/assets/{Controls-BWJtMkIy.js → Controls-FZ8wEN5w.js} +1 -1
- package/dashboard/dist/assets/{DashboardPage-Bcq4EwG5.js → DashboardPage-BByRBsbt.js} +1 -1
- package/dashboard/dist/assets/{DevicePage-C9NcPZGX.js → DevicePage-D2IzPc5o.js} +1 -1
- package/dashboard/dist/assets/{DialogClose-CY-LguUG.js → DialogClose-BaqQaUUk.js} +1 -1
- package/dashboard/dist/assets/DialogDescription-BUrh0Jod.js +1 -0
- package/dashboard/dist/assets/{DialogTitle-BkAmJrQ_.js → DialogTitle-DrbKjtuS.js} +1 -1
- package/dashboard/dist/assets/{FadeIn-U-bxcM-y.js → FadeIn-GddKDE8i.js} +1 -1
- package/dashboard/dist/assets/{HeaderGithubStar-4HUCxVhg.js → HeaderGithubStar-DUu-Z5mE.js} +1 -1
- package/dashboard/dist/assets/{HoverTooltip-BXcXOCs8.js → HoverTooltip-BmDkY35A.js} +1 -1
- package/dashboard/dist/assets/{IpCheckPage-Cppkc-gE.js → IpCheckPage-CGJyqWk2.js} +1 -1
- package/dashboard/dist/assets/{LandingPage-D3KXfYKE.js → LandingPage-Bd91ALUj.js} +2 -2
- package/dashboard/dist/assets/{LeaderboardAvatar-CdsHg6L0.js → LeaderboardAvatar-BGGUwXFd.js} +1 -1
- package/dashboard/dist/assets/{LeaderboardPage-niat0TZW.js → LeaderboardPage-BMEqHwif.js} +2 -2
- package/dashboard/dist/assets/{LeaderboardProfileModal-DgjhhEbB.js → LeaderboardProfileModal-BSweJqm2.js} +3 -3
- package/dashboard/dist/assets/{LeaderboardProfilePage-CZej8gpc.js → LeaderboardProfilePage-CRrI3RFz.js} +1 -1
- package/dashboard/dist/assets/LimitsPage-XIRDv46K.js +5 -0
- package/dashboard/dist/assets/{LocalOnlyNotice-DQswDMSD.js → LocalOnlyNotice-CCD-lGWG.js} +1 -1
- package/dashboard/dist/assets/{LoginCard-glPyVqYh.js → LoginCard-lDuqSv4f.js} +1 -1
- package/dashboard/dist/assets/{LoginModal-slsdEXC7.js → LoginModal-DStt5VXN.js} +1 -1
- package/dashboard/dist/assets/{LoginPage-DX5QT917.js → LoginPage-dmVPSL72.js} +1 -1
- package/dashboard/dist/assets/{PetPage-B8U3CJwt.js → PetPage-ybcZRctF.js} +1 -1
- package/dashboard/dist/assets/{PopoverPopup-BVPcQAio.js → PopoverPopup-Dar_UjxF.js} +1 -1
- package/dashboard/dist/assets/{ProviderIcon-CljIacVj.js → ProviderIcon-Ct9tILpz.js} +1 -1
- package/dashboard/dist/assets/{ResetPasswordPage-DTBmQk2y.js → ResetPasswordPage-B4yLh5zx.js} +1 -1
- package/dashboard/dist/assets/{SegmentedControl-C6npelCT.js → SegmentedControl-BOE1CEzq.js} +1 -1
- package/dashboard/dist/assets/{Select-D1elkRBG.js → Select-D-bSh7Zz.js} +1 -1
- package/dashboard/dist/assets/{SelectItemText-3N-hvYuD.js → SelectItemText-DMYjXXq4.js} +1 -1
- package/dashboard/dist/assets/{ServiceStatusPage-C5ZK9X2o.js → ServiceStatusPage-CaleS-6_.js} +1 -1
- package/dashboard/dist/assets/SessionsPage-DOaY6_E9.js +2 -0
- package/dashboard/dist/assets/SettingsPage-iJH0Yyah.js +2 -0
- package/dashboard/dist/assets/{SkillsPage-Cwkevv29.js → SkillsPage-BkzJOBLk.js} +1 -1
- package/dashboard/dist/assets/{TokenGalaxy-a1-E6_jp.js → TokenGalaxy-CuXKoMPg.js} +1 -1
- package/dashboard/dist/assets/{ToolbarRootContext-Cm5cQb9Z.js → ToolbarRootContext-Dx5GB7F5.js} +1 -1
- package/dashboard/dist/assets/{TrendMonitor-DoNDyarF.js → TrendMonitor-BuKmsznP.js} +1 -1
- package/dashboard/dist/assets/{WidgetsPage-QMTmKnRl.js → WidgetsPage-DUaIyGtu.js} +1 -1
- package/dashboard/dist/assets/{WrappedPage-C9rJcY2o.js → WrappedPage-BzqlcAUC.js} +1 -1
- package/dashboard/dist/assets/__vite-browser-external-BHz2N7Ih.css +1 -0
- package/dashboard/dist/assets/{__vite-browser-external-CsbVaBbw.js → __vite-browser-external-CVIGknXl.js} +3 -3
- package/dashboard/dist/assets/{agent-logos-B39DKy3X.js → agent-logos-BdWWxza6.js} +1 -1
- package/dashboard/dist/assets/{arrow-up-right-Cw5mMBik.js → arrow-up-right-CANSzmm-.js} +1 -1
- package/dashboard/dist/assets/{check-DrQztnq1.js → check-BnJpzXRZ.js} +1 -1
- package/dashboard/dist/assets/{chevron-right-CEelysET.js → chevron-right-DJm0mbG0.js} +1 -1
- package/dashboard/dist/assets/{composite-MhgOkYfv.js → composite-Ccj6KQmh.js} +1 -1
- package/dashboard/dist/assets/{copy-Bouz-qQR.js → copy-C2Yc8Evu.js} +1 -1
- package/dashboard/dist/assets/{download-BugS2cl5.js → download-B52JTk6Y.js} +1 -1
- package/dashboard/dist/assets/{external-link-Ceqto-f4.js → external-link-DayTwZx-.js} +1 -1
- package/dashboard/dist/assets/{flame-B67y0kLz.js → flame-B8GEX2yT.js} +1 -1
- package/dashboard/dist/assets/{format-tokens-CR8njNJs.js → format-tokens-mhkbohkb.js} +1 -1
- package/dashboard/dist/assets/{icons-DFj5ctTx.js → icons-o8bPXqRP.js} +1 -1
- package/dashboard/dist/assets/{index-CrymIhtC.js → index-Bp0ZHDtz.js} +1 -1
- package/dashboard/dist/assets/{index-Bx6EP36K.js → index-CK_CduLm.js} +1 -1
- package/dashboard/dist/assets/{index-ZGfRrxuq.js → index-MBVWUKpA.js} +1 -1
- package/dashboard/dist/assets/{info-C6XoktLa.js → info-D94QM_vX.js} +1 -1
- package/dashboard/dist/assets/{limits-providers-B9L6hIZT.js → limits-providers-BLzMyCiy.js} +1 -1
- package/dashboard/dist/assets/{link-2-DKG2j43e.js → link-2-CqBmFaDI.js} +1 -1
- package/dashboard/dist/assets/{loader-circle-DB2txq05.js → loader-circle-SaxUpDR6.js} +1 -1
- package/dashboard/dist/assets/{maximize-2-3-dz0brp.js → maximize-2-BoXqARks.js} +1 -1
- package/dashboard/dist/assets/{modifiers.esm-D0KjKi1o.js → modifiers.esm-Conh_-BD.js} +1 -1
- package/dashboard/dist/assets/{monitor-smartphone-Ds8H_QW9.js → monitor-smartphone-D6qLR9qd.js} +1 -1
- package/dashboard/dist/assets/{plus-BDsmAe4Z.js → plus-D51mjIc2.js} +1 -1
- package/dashboard/dist/assets/{provider-display-DRz643iD.js → provider-display-DpHPjd_s.js} +1 -1
- package/dashboard/dist/assets/{react-D3Afmy9b.js → react-D_AcI466.js} +1 -1
- package/dashboard/dist/assets/{search-CO2Xf-Kg.js → search-CwLcNdvZ.js} +1 -1
- package/dashboard/dist/assets/{skills-api-C1BZuUIq.js → skills-api-Dqi7Mjgo.js} +1 -1
- package/dashboard/dist/assets/{sortable.esm-DutNEc4F.js → sortable.esm-BPDlUxPb.js} +1 -1
- package/dashboard/dist/assets/{store-a-oUpY-g.js → store-ikeRIRGd.js} +1 -1
- package/dashboard/dist/assets/{terminal-DAePk67T.js → terminal-BfeX3L5T.js} +1 -1
- package/dashboard/dist/assets/{trash-2-bnFmtRSG.js → trash-2-5_Qlp1k7.js} +1 -1
- package/dashboard/dist/assets/{use-community-stats-PJBeXyek.js → use-community-stats-D90Fy2_j.js} +1 -1
- package/dashboard/dist/assets/use-limits-display-prefs-D4BYFaa-.js +1 -0
- package/dashboard/dist/assets/{use-ordered-list-BaVvCzZ9.js → use-ordered-list-DJxLNdXY.js} +1 -1
- package/dashboard/dist/assets/use-reduced-motion-yE3T3cat.js +1 -0
- package/dashboard/dist/assets/{use-session-efficiency-pref-COTG-zJs.js → use-session-efficiency-pref-CAX_GqXc.js} +1 -1
- package/dashboard/dist/assets/{use-transform-BQEPyChL.js → use-transform-CeW6Z5R0.js} +1 -1
- package/dashboard/dist/assets/{use-usage-limits-LR2gHJJn.js → use-usage-limits-5HP8k9a3.js} +1 -1
- package/dashboard/dist/assets/{useCurrency-CeqKrzFz.js → useCurrency-BarGeFyK.js} +1 -1
- package/dashboard/dist/assets/{useTokenFormat-D0IMlZlO.js → useTokenFormat-DUJ9iT9H.js} +1 -1
- package/dashboard/dist/assets/{zap-BBn6G5_E.js → zap--m0IWoI3.js} +1 -1
- package/dashboard/dist/index.html +2 -2
- package/dashboard/dist/ip-check.html +2 -2
- package/dashboard/dist/leaderboard.html +2 -2
- package/dashboard/dist/share.html +2 -2
- package/package.json +1 -1
- package/src/commands/status.js +3 -1
- package/src/commands/sync.js +8 -3
- package/src/lib/codex-rollout-parser.js +35 -4
- package/src/lib/pricing/seed-snapshot.json +1 -1
- package/src/lib/rollout.js +758 -195
- package/src/lib/session-analytics.js +205 -10
- package/src/lib/telemetry.js +2 -2
- package/src/lib/usage-limits.js +20 -10
- package/dashboard/dist/assets/DialogDescription-DPyhpdeR.js +0 -1
- package/dashboard/dist/assets/LimitsPage-BXzzX87I.js +0 -5
- package/dashboard/dist/assets/SessionsPage-CJ0JvE8-.js +0 -2
- package/dashboard/dist/assets/SettingsPage-C32uYzqG.js +0 -2
- package/dashboard/dist/assets/__vite-browser-external-D95WhsZe.css +0 -1
- package/dashboard/dist/assets/use-limits-display-prefs-Blvn-7CB.js +0 -1
- package/dashboard/dist/assets/use-reduced-motion-f51jgK_S.js +0 -1
|
@@ -54,7 +54,9 @@ const wsl = require("./wsl-probe");
|
|
|
54
54
|
// stay valid while Grok entries appear on the next full rebuild.
|
|
55
55
|
// v11 groups native/WSL copies of one logical Claude/Codex session and scans
|
|
56
56
|
// their union, deduping shared records while retaining divergent tails.
|
|
57
|
-
|
|
57
|
+
// v12 retains Codex parent/subagent metadata locally and derives exact child
|
|
58
|
+
// token totals from observed child rollouts instead of spawn-call estimates.
|
|
59
|
+
const SIDECAR_VERSION = 12;
|
|
58
60
|
const EDIT_TOOLS = new Set([
|
|
59
61
|
"apply_patch",
|
|
60
62
|
"edit",
|
|
@@ -511,6 +513,18 @@ async function scanCodexSession(filePath) {
|
|
|
511
513
|
version: SIDECAR_VERSION,
|
|
512
514
|
session_hash: sessionHash("codex", parsed.sessionId || primaryFilePath),
|
|
513
515
|
session_id: parsed.sessionId || null,
|
|
516
|
+
// Local-only lineage. Codex v2 normally writes forked_from_id; keep
|
|
517
|
+
// parent_thread_id as a compatibility fallback, but reject disagreement.
|
|
518
|
+
parent_session_id: parsed.forkedFromId || parsed.parentThreadId || null,
|
|
519
|
+
parent_link_conflict: Boolean(
|
|
520
|
+
parsed.forkedFromId
|
|
521
|
+
&& parsed.parentThreadId
|
|
522
|
+
&& parsed.forkedFromId !== parsed.parentThreadId
|
|
523
|
+
),
|
|
524
|
+
forked_from_id: parsed.forkedFromId || null,
|
|
525
|
+
thread_source: typeof parsed.threadSource === "string" ? parsed.threadSource : null,
|
|
526
|
+
agent_nickname: typeof parsed.agentNickname === "string" ? parsed.agentNickname : null,
|
|
527
|
+
agent_role: typeof parsed.agentRole === "string" ? parsed.agentRole : null,
|
|
514
528
|
// Local-only: stripped in summarizeSessions before any cloud/CSV export.
|
|
515
529
|
title,
|
|
516
530
|
source: "codex",
|
|
@@ -829,7 +843,14 @@ function providerRoots(home, providerDir, env, deps = {}) {
|
|
|
829
843
|
const discoverWslHome = deps.discoverWslHome || wsl.discoverWslHome;
|
|
830
844
|
const roots = [];
|
|
831
845
|
if (platform !== "win32" || wsl.shouldProbeNative(env)) {
|
|
832
|
-
|
|
846
|
+
const useProcessCodexHome = providerDir === ".codex"
|
|
847
|
+
&& path.resolve(home) === path.resolve(homedir())
|
|
848
|
+
&& typeof env?.CODEX_HOME === "string"
|
|
849
|
+
&& env.CODEX_HOME.trim();
|
|
850
|
+
const nativeRoot = useProcessCodexHome
|
|
851
|
+
? path.resolve(env.CODEX_HOME.trim())
|
|
852
|
+
: path.join(home, providerDir);
|
|
853
|
+
roots.push(nativeRoot);
|
|
833
854
|
}
|
|
834
855
|
// Only the machine's own home has a WSL sibling worth probing.
|
|
835
856
|
// discoverWslHome resolves \\wsl$ independently of `home`, so probing for an
|
|
@@ -1029,10 +1050,15 @@ function sessionFileStatKey(filePath) {
|
|
|
1029
1050
|
const codexTitleIndexCache = new Map();
|
|
1030
1051
|
|
|
1031
1052
|
function codexTitleIndexPathFor(filePath) {
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1053
|
+
let current = path.dirname(path.resolve(filePath));
|
|
1054
|
+
while (true) {
|
|
1055
|
+
if (["sessions", "archived_sessions"].includes(path.basename(current))) {
|
|
1056
|
+
return path.join(path.dirname(current), "session_index.jsonl");
|
|
1057
|
+
}
|
|
1058
|
+
const parent = path.dirname(current);
|
|
1059
|
+
if (parent === current) return null;
|
|
1060
|
+
current = parent;
|
|
1061
|
+
}
|
|
1036
1062
|
}
|
|
1037
1063
|
|
|
1038
1064
|
function loadCodexTitleIndex(filePath) {
|
|
@@ -1239,7 +1265,9 @@ function withinDayRange(row, from, to) {
|
|
|
1239
1265
|
}
|
|
1240
1266
|
|
|
1241
1267
|
function summarizeSessions(sessions, { from = "", to = "", includeSessions = true } = {}) {
|
|
1242
|
-
const filtered = (sessions || [])
|
|
1268
|
+
const filtered = annotateCodexThreadUsage((sessions || [])
|
|
1269
|
+
.filter((row) => withinDayRange(row, from, to))
|
|
1270
|
+
.map((row) => ({ ...row })));
|
|
1243
1271
|
const byModel = new Map();
|
|
1244
1272
|
const subagents = new Map();
|
|
1245
1273
|
for (const row of filtered) {
|
|
@@ -1268,6 +1296,26 @@ function summarizeSessions(sessions, { from = "", to = "", includeSessions = tru
|
|
|
1268
1296
|
agg.edit_cost_usd += finite(row.cost_usd);
|
|
1269
1297
|
}
|
|
1270
1298
|
byModel.set(key, agg);
|
|
1299
|
+
if (row.source === "codex" && row.parent_session_hash) {
|
|
1300
|
+
const name = row.agent_role || row.agent_nickname || "subagent";
|
|
1301
|
+
const sub = subagents.get(name) || {
|
|
1302
|
+
name,
|
|
1303
|
+
calls: 0,
|
|
1304
|
+
sessions: 0,
|
|
1305
|
+
total_tokens: 0,
|
|
1306
|
+
cost_usd: 0,
|
|
1307
|
+
attribution: "observed-child-session",
|
|
1308
|
+
};
|
|
1309
|
+
sub.calls += 1;
|
|
1310
|
+
sub.sessions += 1;
|
|
1311
|
+
sub.total_tokens += finite(row.total_tokens);
|
|
1312
|
+
sub.cost_usd += finite(row.cost_usd);
|
|
1313
|
+
subagents.set(name, sub);
|
|
1314
|
+
continue;
|
|
1315
|
+
}
|
|
1316
|
+
// Codex child rollouts are first-class rows. A spawn call in the parent is
|
|
1317
|
+
// a control-plane event, not token usage, so do not mix in an estimate.
|
|
1318
|
+
if (row.source === "codex") continue;
|
|
1271
1319
|
for (const [name, calls] of Object.entries(row.subagent_types || {})) {
|
|
1272
1320
|
const sub = subagents.get(name) || { name, calls: 0, sessions: 0, total_tokens: 0, cost_usd: 0 };
|
|
1273
1321
|
sub.calls += finite(calls);
|
|
@@ -1301,7 +1349,22 @@ function summarizeSessions(sessions, { from = "", to = "", includeSessions = tru
|
|
|
1301
1349
|
// Git attribution and the local-only session browser, but never leave the
|
|
1302
1350
|
// Node process through API/CSV payloads.
|
|
1303
1351
|
sessions: includeSessions
|
|
1304
|
-
? filtered.map(({
|
|
1352
|
+
? filtered.map(({
|
|
1353
|
+
project_ref: _projectRef,
|
|
1354
|
+
session_id: _sessionId,
|
|
1355
|
+
parent_session_id: _parentSessionId,
|
|
1356
|
+
forked_from_id: _forkedFromId,
|
|
1357
|
+
parent_session_hash: _parentSessionHash,
|
|
1358
|
+
root_session_hash: _rootSessionHash,
|
|
1359
|
+
agent_nickname: _agentNickname,
|
|
1360
|
+
agent_role: _agentRole,
|
|
1361
|
+
thread_source: _threadSource,
|
|
1362
|
+
parent_link_conflict: _parentLinkConflict,
|
|
1363
|
+
orphaned_subagent: _orphanedSubagent,
|
|
1364
|
+
title: _title,
|
|
1365
|
+
_cache_key: _cacheKey,
|
|
1366
|
+
...row
|
|
1367
|
+
}) => row)
|
|
1305
1368
|
: [],
|
|
1306
1369
|
session_count: filtered.length,
|
|
1307
1370
|
summary: {
|
|
@@ -1350,6 +1413,14 @@ function toSessionBrowserRow(row) {
|
|
|
1350
1413
|
return {
|
|
1351
1414
|
session_hash: row.session_hash,
|
|
1352
1415
|
session_id: row.session_id || null,
|
|
1416
|
+
parent_session_id: row.parent_session_id || null,
|
|
1417
|
+
parent_session_hash: row.parent_session_hash || null,
|
|
1418
|
+
root_session_hash: row.root_session_hash || row.session_hash,
|
|
1419
|
+
thread_kind: row.parent_session_id ? "subagent" : "root",
|
|
1420
|
+
agent_nickname: row.agent_nickname || null,
|
|
1421
|
+
agent_role: row.agent_role || null,
|
|
1422
|
+
orphaned_subagent: Boolean(row.orphaned_subagent),
|
|
1423
|
+
parent_link_conflict: Boolean(row.parent_link_conflict),
|
|
1353
1424
|
title: row.title || null,
|
|
1354
1425
|
source: row.source,
|
|
1355
1426
|
project_key: row.project_key,
|
|
@@ -1364,7 +1435,15 @@ function toSessionBrowserRow(row) {
|
|
|
1364
1435
|
edit_turns: finite(row.edit_turns),
|
|
1365
1436
|
retry_turns: finite(row.retry_turns),
|
|
1366
1437
|
subagent_calls: finite(row.subagent_calls),
|
|
1438
|
+
direct_subagent_count: finite(row.direct_subagent_count),
|
|
1439
|
+
descendant_subagent_count: finite(row.descendant_subagent_count),
|
|
1440
|
+
own_total_tokens: finite(row.total_tokens),
|
|
1441
|
+
subagent_total_tokens: finite(row.subagent_total_tokens),
|
|
1442
|
+
combined_total_tokens: finite(row.combined_total_tokens || row.total_tokens),
|
|
1367
1443
|
total_tokens: finite(row.total_tokens),
|
|
1444
|
+
own_cost_usd: finite(row.cost_usd),
|
|
1445
|
+
subagent_cost_usd: finite(row.subagent_cost_usd),
|
|
1446
|
+
combined_cost_usd: finite(row.combined_cost_usd || row.cost_usd),
|
|
1368
1447
|
cost_usd: finite(row.cost_usd),
|
|
1369
1448
|
productive: Boolean(row.productive),
|
|
1370
1449
|
first_pass: Boolean(row.first_pass ?? row.one_shot),
|
|
@@ -1396,6 +1475,14 @@ function mergeSessionFragments(rows) {
|
|
|
1396
1475
|
cur.productive = Boolean(cur.productive) || Boolean(row.productive);
|
|
1397
1476
|
cur.active_ms = finite(cur.active_ms) + finite(row.active_ms);
|
|
1398
1477
|
if (!cur.title && row.title) cur.title = row.title;
|
|
1478
|
+
if (!cur.parent_session_id && row.parent_session_id) cur.parent_session_id = row.parent_session_id;
|
|
1479
|
+
if (cur.parent_session_id && row.parent_session_id && cur.parent_session_id !== row.parent_session_id) {
|
|
1480
|
+
cur.parent_session_id = null;
|
|
1481
|
+
cur.parent_link_conflict = true;
|
|
1482
|
+
}
|
|
1483
|
+
if (!cur.forked_from_id && row.forked_from_id) cur.forked_from_id = row.forked_from_id;
|
|
1484
|
+
if (!cur.agent_nickname && row.agent_nickname) cur.agent_nickname = row.agent_nickname;
|
|
1485
|
+
if (!cur.agent_role && row.agent_role) cur.agent_role = row.agent_role;
|
|
1399
1486
|
// Representative model/project comes from the busiest fragment (most
|
|
1400
1487
|
// tokens) so a tiny sidechain cannot overwrite the real coding model.
|
|
1401
1488
|
if (finite(row.total_tokens) > finite(cur._repr_tokens)) {
|
|
@@ -1427,19 +1514,127 @@ function mergeSessionFragments(rows) {
|
|
|
1427
1514
|
return merged;
|
|
1428
1515
|
}
|
|
1429
1516
|
|
|
1517
|
+
// Attach exact Codex parent/child usage without changing the authoritative
|
|
1518
|
+
// per-session total_tokens field. Combined fields are derived views only, so
|
|
1519
|
+
// summing total_tokens across all rows still equals the global usage ledger.
|
|
1520
|
+
function annotateCodexThreadUsage(rows) {
|
|
1521
|
+
const byId = new Map();
|
|
1522
|
+
const childrenById = new Map();
|
|
1523
|
+
const linkedParentById = new Map();
|
|
1524
|
+
|
|
1525
|
+
for (const row of rows || []) {
|
|
1526
|
+
if (row?.source !== "codex" || typeof row.session_id !== "string" || !row.session_id) continue;
|
|
1527
|
+
const existing = byId.get(row.session_id);
|
|
1528
|
+
if (existing && existing !== row) {
|
|
1529
|
+
existing.parent_link_conflict = true;
|
|
1530
|
+
row.parent_link_conflict = true;
|
|
1531
|
+
continue;
|
|
1532
|
+
}
|
|
1533
|
+
byId.set(row.session_id, row);
|
|
1534
|
+
}
|
|
1535
|
+
|
|
1536
|
+
function hasParentCycle(start) {
|
|
1537
|
+
const seen = new Set();
|
|
1538
|
+
let current = start;
|
|
1539
|
+
while (current?.parent_session_id && byId.has(current.parent_session_id)) {
|
|
1540
|
+
if (seen.has(current.session_id) || current.parent_session_id === current.session_id) return true;
|
|
1541
|
+
seen.add(current.session_id);
|
|
1542
|
+
current = byId.get(current.parent_session_id);
|
|
1543
|
+
}
|
|
1544
|
+
return false;
|
|
1545
|
+
}
|
|
1546
|
+
|
|
1547
|
+
for (const row of byId.values()) {
|
|
1548
|
+
const parentId = typeof row.parent_session_id === "string" ? row.parent_session_id.trim() : "";
|
|
1549
|
+
if (!parentId) continue;
|
|
1550
|
+
if (row.parent_link_conflict || hasParentCycle(row)) {
|
|
1551
|
+
row.parent_link_conflict = true;
|
|
1552
|
+
continue;
|
|
1553
|
+
}
|
|
1554
|
+
if (!byId.has(parentId)) {
|
|
1555
|
+
row.orphaned_subagent = true;
|
|
1556
|
+
continue;
|
|
1557
|
+
}
|
|
1558
|
+
const children = childrenById.get(parentId) || [];
|
|
1559
|
+
children.push(row);
|
|
1560
|
+
childrenById.set(parentId, children);
|
|
1561
|
+
linkedParentById.set(row.session_id, parentId);
|
|
1562
|
+
}
|
|
1563
|
+
|
|
1564
|
+
const memo = new Map();
|
|
1565
|
+
function aggregate(row, visiting = new Set()) {
|
|
1566
|
+
if (memo.has(row.session_id)) return memo.get(row.session_id);
|
|
1567
|
+
if (visiting.has(row.session_id)) {
|
|
1568
|
+
row.parent_link_conflict = true;
|
|
1569
|
+
return { count: 0, tokens: 0, cost: 0 };
|
|
1570
|
+
}
|
|
1571
|
+
const nextVisiting = new Set(visiting);
|
|
1572
|
+
nextVisiting.add(row.session_id);
|
|
1573
|
+
let count = 0;
|
|
1574
|
+
let tokens = 0;
|
|
1575
|
+
let cost = 0;
|
|
1576
|
+
for (const child of childrenById.get(row.session_id) || []) {
|
|
1577
|
+
const nested = aggregate(child, nextVisiting);
|
|
1578
|
+
count += 1 + nested.count;
|
|
1579
|
+
tokens += finite(child.total_tokens) + nested.tokens;
|
|
1580
|
+
cost += finite(child.cost_usd) + nested.cost;
|
|
1581
|
+
}
|
|
1582
|
+
const result = { count, tokens, cost };
|
|
1583
|
+
memo.set(row.session_id, result);
|
|
1584
|
+
return result;
|
|
1585
|
+
}
|
|
1586
|
+
|
|
1587
|
+
function rootFor(row) {
|
|
1588
|
+
const seen = new Set([row.session_id]);
|
|
1589
|
+
let current = row;
|
|
1590
|
+
while (current && linkedParentById.has(current.session_id)) {
|
|
1591
|
+
const linkedParentId = linkedParentById.get(current.session_id);
|
|
1592
|
+
if (seen.has(linkedParentId)) {
|
|
1593
|
+
row.parent_link_conflict = true;
|
|
1594
|
+
break;
|
|
1595
|
+
}
|
|
1596
|
+
seen.add(linkedParentId);
|
|
1597
|
+
current = byId.get(linkedParentId);
|
|
1598
|
+
}
|
|
1599
|
+
return current || row;
|
|
1600
|
+
}
|
|
1601
|
+
|
|
1602
|
+
for (const row of rows || []) {
|
|
1603
|
+
row.own_total_tokens = finite(row.total_tokens);
|
|
1604
|
+
row.own_cost_usd = finite(row.cost_usd);
|
|
1605
|
+
row.direct_subagent_count = row.source === "codex" && row.session_id
|
|
1606
|
+
? (childrenById.get(row.session_id) || []).length
|
|
1607
|
+
: 0;
|
|
1608
|
+
const nested = row.source === "codex" && row.session_id
|
|
1609
|
+
? aggregate(row)
|
|
1610
|
+
: { count: 0, tokens: 0, cost: 0 };
|
|
1611
|
+
row.descendant_subagent_count = nested.count;
|
|
1612
|
+
row.subagent_total_tokens = nested.tokens;
|
|
1613
|
+
row.subagent_cost_usd = nested.cost;
|
|
1614
|
+
row.combined_total_tokens = finite(row.total_tokens) + nested.tokens;
|
|
1615
|
+
row.combined_cost_usd = finite(row.cost_usd) + nested.cost;
|
|
1616
|
+
if (row.source === "codex" && row.session_id) {
|
|
1617
|
+
const parent = byId.get(linkedParentById.get(row.session_id));
|
|
1618
|
+
row.parent_session_hash = parent?.session_hash || null;
|
|
1619
|
+
row.root_session_hash = rootFor(row).session_hash || row.session_hash;
|
|
1620
|
+
}
|
|
1621
|
+
}
|
|
1622
|
+
return rows;
|
|
1623
|
+
}
|
|
1624
|
+
|
|
1430
1625
|
// Local-only session list for the dashboard session browser. Unlike
|
|
1431
1626
|
// summarizeSessions (cloud/CSV safe), this retains session_id + project_ref so
|
|
1432
1627
|
// the UI can offer one-click resume. Callers must only expose it over the
|
|
1433
1628
|
// local API.
|
|
1434
1629
|
function listSessionsForBrowser(sessions, { from = "", to = "", limit = 0 } = {}) {
|
|
1435
|
-
const filtered = mergeSessionFragments(sessions)
|
|
1630
|
+
const filtered = annotateCodexThreadUsage(mergeSessionFragments(sessions)
|
|
1436
1631
|
// Only sessions that actually spent tokens are worth listing. This drops
|
|
1437
1632
|
// two kinds of noise: non-session logs under ~/.claude/projects
|
|
1438
1633
|
// (skill-injections.jsonl, journal.jsonl, …), and sessions abandoned before
|
|
1439
1634
|
// the model replied. Both render as "unknown · 0 tokens · $0.00" rows with
|
|
1440
1635
|
// no model, no cost and nothing to analyze.
|
|
1441
1636
|
.filter((row) => finite(row.total_tokens) > 0)
|
|
1442
|
-
.filter((row) => withinDayRange(row, from, to));
|
|
1637
|
+
.filter((row) => withinDayRange(row, from, to)));
|
|
1443
1638
|
filtered.sort((a, b) => String(b.ended_at || "").localeCompare(String(a.ended_at || "")));
|
|
1444
1639
|
const cap = Number(limit) > 0 ? Number(limit) : 0;
|
|
1445
1640
|
const limited = cap > 0 ? filtered.slice(0, cap) : filtered;
|
package/src/lib/telemetry.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* Privacy contract (documented in README "Privacy" section — keep in sync):
|
|
7
7
|
* the payload carries exactly four fields — a one-way sha256 hash of the
|
|
8
8
|
* machine id, the app version, `process.platform`, and the app shell
|
|
9
|
-
* (cli / macos / windows). No token counts, no model names, no usernames,
|
|
9
|
+
* (cli / macos / windows / linux). No token counts, no model names, no usernames,
|
|
10
10
|
* no paths. Opt out with TOKENTRACKER_NO_TELEMETRY=1, the DO_NOT_TRACK
|
|
11
11
|
* standard, or `"telemetry": false` in config.json.
|
|
12
12
|
*/
|
|
@@ -35,7 +35,7 @@ const MACHINE_HASH_NAMESPACE = "tokentracker-telemetry-v1:";
|
|
|
35
35
|
// cloud host; sync awaits this at most once per day so the worst-case stall
|
|
36
36
|
// is bounded and rare.
|
|
37
37
|
const DEFAULT_TIMEOUT_MS = 10_000;
|
|
38
|
-
const VALID_SHELLS = new Set(["cli", "macos", "windows"]);
|
|
38
|
+
const VALID_SHELLS = new Set(["cli", "macos", "windows", "linux"]);
|
|
39
39
|
|
|
40
40
|
const THROTTLE_CONFIG = {
|
|
41
41
|
intervalMs: HEARTBEAT_INTERVAL_MS,
|
package/src/lib/usage-limits.js
CHANGED
|
@@ -1882,20 +1882,30 @@ function describeCopilotOtelStatus({ home, env = process.env } = {}) {
|
|
|
1882
1882
|
const explicitPath = typeof env.COPILOT_OTEL_FILE_EXPORTER_PATH === "string"
|
|
1883
1883
|
? env.COPILOT_OTEL_FILE_EXPORTER_PATH
|
|
1884
1884
|
: "";
|
|
1885
|
-
const
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1885
|
+
const defaultDirs = [
|
|
1886
|
+
path.join(resolvedHome, ".copilot", "otel"),
|
|
1887
|
+
path.join(resolvedHome, ".copilot-otel"),
|
|
1888
|
+
];
|
|
1889
|
+
const detectedPaths = [];
|
|
1890
|
+
for (const defaultDir of defaultDirs) {
|
|
1891
|
+
try {
|
|
1892
|
+
if (!fs.existsSync(defaultDir)) continue;
|
|
1893
|
+
for (const entry of fs.readdirSync(defaultDir)) {
|
|
1894
|
+
if (entry.endsWith(".jsonl")) {
|
|
1895
|
+
detectedPaths.push(path.join(defaultDir, entry));
|
|
1896
|
+
}
|
|
1897
|
+
}
|
|
1898
|
+
} catch (_e) {}
|
|
1899
|
+
}
|
|
1900
|
+
if (explicitPath && fs.existsSync(explicitPath)) detectedPaths.push(explicitPath);
|
|
1893
1901
|
return {
|
|
1894
1902
|
otel_enabled: enabled && (exporterType === "" || exporterType === "file"),
|
|
1895
1903
|
otel_exporter_type: exporterType || null,
|
|
1896
1904
|
otel_path: explicitPath || null,
|
|
1897
|
-
otel_default_dir:
|
|
1898
|
-
|
|
1905
|
+
otel_default_dir: defaultDirs[0],
|
|
1906
|
+
otel_default_dirs: defaultDirs,
|
|
1907
|
+
otel_detected_paths: detectedPaths,
|
|
1908
|
+
otel_has_files: detectedPaths.length > 0,
|
|
1899
1909
|
};
|
|
1900
1910
|
}
|
|
1901
1911
|
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{r as n,z as a}from"./__vite-browser-external-CsbVaBbw.js";import{u as p}from"./DialogTitle-BkAmJrQ_.js";import{u as c}from"./composite-MhgOkYfv.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,5 +0,0 @@
|
|
|
1
|
-
import{m as z,j as e,e as Me,c as i,k as te,r as x,Q as Ve,B as G,aw as Ke,d as P,J as be,L as Xe,ax as Je,q as Qe,ac as Ze}from"./__vite-browser-external-CsbVaBbw.js";import{m as ye}from"./react-D3Afmy9b.js";import{P as me,c as et,r as ae,a as tt,u as at,b as rt,s as it}from"./use-usage-limits-LR2gHJJn.js";import{L as j,u as nt}from"./use-limits-display-prefs-Blvn-7CB.js";import{C as Se}from"./Card-BKbWtBaL.js";import{F as st}from"./FadeIn-U-bxcM-y.js";import{L as Ce,l as Z,a as Pe}from"./limits-providers-B9L6hIZT.js";import{P as Te}from"./ProviderIcon-CljIacVj.js";import{H as ot}from"./HoverTooltip-BXcXOCs8.js";import{C as lt}from"./ConfirmModal-CrIjcrpZ.js";import{I as ve,L as ct}from"./LocalOnlyNotice-DQswDMSD.js";import{S as le}from"./Select-D1elkRBG.js";import{P as dt}from"./plus-BDsmAe4Z.js";import{P as ut,a as mt,b as xt,c as pt,d as gt}from"./PopoverPopup-BVPcQAio.js";import{u as ft}from"./use-reduced-motion-f51jgK_S.js";import"./DialogTitle-BkAmJrQ_.js";import"./composite-MhgOkYfv.js";import"./store-a-oUpY-g.js";import"./DialogDescription-DPyhpdeR.js";import"./arrow-up-right-Cw5mMBik.js";import"./download-BugS2cl5.js";import"./ToolbarRootContext-Cm5cQb9Z.js";import"./check-DrQztnq1.js";import"./SelectItemText-3N-hvYuD.js";const ht=[["path",{d:"M10.268 21a2 2 0 0 0 3.464 0",key:"vwvbt9"}],["path",{d:"M17 17H4a1 1 0 0 1-.74-1.673C4.59 13.956 6 12.499 6 8a6 6 0 0 1 .258-1.742",key:"178tsu"}],["path",{d:"m2 2 20 20",key:"1ooewy"}],["path",{d:"M8.668 3.01A6 6 0 0 1 18 8c0 2.687.77 4.653 1.707 6.05",key:"1hqiys"}]],bt=z("bell-off",ht);const yt=[["path",{d:"M10.268 21a2 2 0 0 0 3.464 0",key:"vwvbt9"}],["path",{d:"M3.262 15.326A1 1 0 0 0 4 17h16a1 1 0 0 0 .74-1.673C19.41 13.956 18 12.499 18 8A6 6 0 0 0 6 8c0 4.499-1.411 5.956-2.738 7.326",key:"11g9vi"}]],vt=z("bell",yt);const kt=[["path",{d:"M16 14v2.2l1.6 1",key:"fo4ql5"}],["path",{d:"M16 2v3",key:"otl347"}],["path",{d:"M21 7.338V5a2 2 0 00-2-2H5a2 2 0 00-2 2v14a2 2 0 002 2h2.338",key:"7hb8p4"}],["path",{d:"M3 9h5.859",key:"numkqi"}],["path",{d:"M8 2v3",key:"1ioesn"}],["circle",{cx:"16",cy:"16",r:"6",key:"qoo3c4"}]],De=z("calendar-clock",kt);const jt=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 6v6l4 2",key:"mmk7yg"}]],wt=z("clock",jt);const Nt=[["path",{d:"M6 16c5 0 7-8 12-8a4 4 0 0 1 0 8c-5 0-7-8-12-8a4 4 0 1 0 0 8",key:"18ogeb"}]],_t=z("infinity",Nt),Mt=[3,2,3,3,2,2,3];function T({className:t}){return e.jsx("div",{className:Me("rounded bg-oai-gray-200/70 dark:bg-oai-gray-800/70 animate-pulse",t)})}function St(){return e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(T,{className:"h-3 w-12 shrink-0"}),e.jsx(T,{className:"flex-1 h-1.5 rounded-full min-w-0"}),e.jsx(T,{className:"h-3 w-[30px] shrink-0"}),e.jsx(T,{className:"h-3 w-6 shrink-0"})]})}function Ct({bars:t,index:a}){const r=a%3===0?"w-24":a%3===1?"w-20":"w-[4.5rem]";return e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(T,{className:"h-[14px] w-[14px] rounded shrink-0"}),e.jsx(T,{className:Me("h-4",r)})]}),Array.from({length:t},(s,n)=>e.jsx(St,{},n))]})}function Pt(){return e.jsx(Se,{children:e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx(T,{className:"h-3.5 w-28"}),Mt.map((t,a)=>e.jsx(Ct,{bars:t,index:a},a))]})})}const xe=100;function ke(t){const a=Date.parse(t);return Number.isFinite(a)?a:null}function Tt(t){return Math.max(0,Math.min(xe,Math.round(t)))}function Dt(t){return new Intl.DateTimeFormat(te(),{month:"numeric",day:"numeric",hour:"2-digit",minute:"2-digit",hour12:!1}).format(new Date(t))}function Et(t,a,r){if(t==null||t>=a)return xe;const s=a-t,n=a-r;return Tt(n/s*xe)}function It(t){const a=t.available_count;return a===null?null:Number.isInteger(a)&&a>=0?a:void 0}function At(t,{now:a}={}){if(!t||typeof t!="object")return null;const r=It(t);if(r===void 0)return null;const s=Array.isArray(t.credits)?t.credits:[],n=a instanceof Date?a.getTime():Number(a??Date.now()),o=[];for(const l of s){const c=ke(l?.expires_at);if(c==null)continue;const d=o.length+1;o.push({key:`reset-${d}`,label:i("limits.codex_reset_bank.row_label",{index:d}),expiresAt:Dt(c),expiresMs:c,percent:Et(ke(l?.granted_at),c,n)})}return r===0?null:o.length>0?{kind:"rows",availableCount:r??o.length,rows:o}:r>0?{kind:"count_only",availableCount:r,rows:[]}:null}const q=864e5;function D(t,a){const r=new Date(t),s=r.getUTCDate(),n=new Date(Date.UTC(r.getUTCFullYear(),r.getUTCMonth()+a,1,r.getUTCHours(),r.getUTCMinutes())),o=new Date(Date.UTC(n.getUTCFullYear(),n.getUTCMonth()+1,0)).getUTCDate();return n.setUTCDate(Math.min(s,o)),n.getTime()}function Ee(t,a){if(a==="weekly")return t-7*q;if(a==="yearly")return D(t,-12);const r=new Date(t),s=new Date(Date.UTC(r.getUTCFullYear(),r.getUTCMonth(),0)).getUTCDate(),n=new Date(Date.UTC(r.getUTCFullYear(),r.getUTCMonth()-1,1,r.getUTCHours(),r.getUTCMinutes()));return n.setUTCDate(Math.min(r.getUTCDate(),s)),n.getTime()}function Ie(t,a){return a==="weekly"?t+7*q:a==="yearly"?D(t,12):D(t,1)}function Rt(t){if(t.startedAt!=null){const a=new Date(t.startedAt).getTime();if(Number.isFinite(a))return a}return Ee(new Date(t.nextBillingAt).getTime(),t.cycle)}function Ot(t,a,r){if(t.startedAt!=null){const s=new Date(t.startedAt).getTime();if(Number.isFinite(s))return s}return Ee(r,a)}function Ft(t,a,r){if(a==="weekly"){const c=7*q,d=r<=t?0:Math.floor((r-t)/c);return{startMs:t+d*c,endMs:t+(d+1)*c}}const s=a==="yearly"?12:1,n=s*30.436875*q;let o=r<=t?0:Math.floor((r-t)/n);for(;o>0&&D(t,o*s)>r;)o-=1;let l=0;for(;D(t,(o+1)*s)<=r&&l<12e3;)o+=1,l+=1;return{startMs:D(t,o*s),endMs:D(t,(o+1)*s)}}function pe(t,a){const r=new Date(t.nextBillingAt).getTime();if(!Number.isFinite(r))return null;const s=["weekly","monthly","yearly"].includes(t.cycle)?t.cycle:"monthly",n=Ot(t,s,r);if(!Number.isFinite(n))return null;let o,l,c=!1;t.autoRenew?{startMs:o,endMs:l}=Ft(n,s,a):t.startedAt!=null?(o=n,l=Ie(n,s),c=l<=a):(o=n,l=r,c=l<=a);const d=Math.max(1,l-o),m=c?1:Math.max(0,Math.min(1,(a-o)/d));return{endMs:l,startMs:o,progress:m,cycleDays:Math.max(1,Math.round(d/q)),expired:c}}function Ae(t,a){const r=t-a;if(r<=0)return i("subscriptions.expired");const s=Math.ceil(r/6e4);if(s<60)return`${s}m`;const n=Math.floor(s/60);return n<24?`${n}h`:`${Math.floor(n/24)}d`}function Re(t,a){const r=t-a;if(r<=0)return i("subscriptions.expired");const s=Math.floor(r/6e4),n=Math.floor(s/1440),o=Math.floor(s%1440/60),l=s%60;return i("subscriptions.countdown",{days:n,hours:o,minutes:l})}const Lt="shrink-0 text-oai-black dark:text-oai-white";function $t(t){const a=ae(t);if(!Number.isFinite(a))return null;const r=a-Date.now();if(r<=0)return i("shared.time.now");const s=Math.floor(r/6e4);if(s<60)return`${s}m`;const n=Math.floor(s/60);return n<24?`${n}h`:`${Math.floor(n/24)}d`}function Ht(t,a){const r=a===j.REMAINING?100-t:t;return r>=90?"bg-red-500":r>=70?"bg-amber-500":"bg-emerald-500"}function ee(t,a="used_percent"){return t?a==="utilization"?t.utilization:t.used_percent:null}function re(t,a="reset_at"){return t?a==="resets_at"?t.resets_at:t.reset_at:null}function ce(t){const a=Math.max(0,Math.min(100,Number(t)||0)),r=Math.round(a);return a>0&&r===0?i("limits.bar.sub_one_percent"):String(r)}function Q(t,{useGrouping:a=!0,maximumFractionDigits:r}={}){const s=Number(t);return Number.isFinite(s)?new Intl.NumberFormat(void 0,{minimumFractionDigits:0,maximumFractionDigits:r??(s>=100?0:2),useGrouping:a}).format(s):null}function Ut(t){if(!t||typeof t!="object"||!(Number(t.limit_credits)>0))return null;const a={useGrouping:t.unit!=="calls"},r=Q(t.used_credits,a),s=Q(t.limit_credits,a),n=Q(t.remaining_credits,a);if(!r||!s||!n)return null;const o=t.unit==="calls"?"limits.qoder_calls.detail":"limits.codex_credits.detail";return i(o,{used:r,limit:s,remaining:n})}function Bt(t,a){return et({usedPercent:ee(t.window,t.pctField),windowSeconds:tt(t,t.window),resetMs:ae(re(t.window,t.resetField)),mode:a})}function Oe(t){return Number.isFinite(t)?new Intl.DateTimeFormat(te(),{month:"numeric",day:"numeric",hour:"2-digit",minute:"2-digit",hour12:!1}).format(new Date(t)):null}function Gt(t,a,r){const s=[Le(t,a,r)],n=ae(re(t.window,t.resetField)),o=Oe(n);o&&s.push(i(t.timeKind==="expiry"?"limits.hover.expires_at":"limits.hover.resets_at",{time:o}));const l=Ut(t.window);return l&&s.push(l),s.join(`
|
|
2
|
-
`)}const Fe=ot;function Wt({label:t,pct:a,reset:r,mode:s=j.USED,pacePercent:n=null,paceOver:o=!1,title:l=null}){const c=Math.max(0,Math.min(100,Number(a)||0)),d=s===j.REMAINING?100-c:c,m=Math.round(d),g=d>0&&m===0?Math.max(d,.35):d;let f=String(m);d>0&&m===0&&(f=i("limits.bar.sub_one_percent"));const h=n==null?null:Math.max(0,Math.min(100,n));return e.jsxs("div",{className:"group relative flex items-center gap-2",children:[e.jsx(Fe,{text:l}),e.jsx("span",{"data-limit-label":"",className:"text-[11px] text-oai-gray-500 dark:text-oai-gray-400 shrink-0 whitespace-nowrap",style:{width:"var(--tt-limits-label-w)"},children:t}),e.jsxs("div",{className:"relative flex-1 bg-oai-gray-100 dark:bg-oai-gray-700/50 rounded-full h-1.5 overflow-hidden",children:[e.jsx("div",{className:`${Ht(d,s)} rounded-full h-full transition-[width] duration-500 ease-out`,style:{width:`${g}%`,minWidth:d>0?"3px":0}}),h!=null&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"absolute top-0 h-full bg-oai-gray-100 dark:bg-oai-gray-700/50",style:{left:`calc(${h}% - 3px)`,width:"6px"}}),e.jsx("div",{className:`absolute top-0 h-full ${o?"bg-red-500":"bg-emerald-500"}`,style:{left:`calc(${h}% - 1px)`,width:"2px"}})]})]}),e.jsxs("span",{className:"text-[11px] tabular-nums text-oai-gray-500 dark:text-oai-gray-400 w-9 text-right shrink-0 whitespace-nowrap",children:[f,"%"]}),r&&e.jsx("span",{className:"text-[10px] text-oai-gray-400 dark:text-oai-gray-500 w-6 text-right shrink-0",children:r})]})}function Le(t,a,r){const s=t.label??i(t.labelKey),n=r===j.REMAINING,o=d=>n?100-d:d;if(a.expectedPercent==null){const d=Math.max(0,Math.min(100,Number(ee(t.window,t.pctField))||0)),m=ce(o(d));return n?i("limits.explain.remaining",{label:s,used:m}):i("limits.explain.used",{label:s,used:m})}if(a.paceOver){if(a.runsOutEta)return i("limits.explain.ahead_eta",{label:s,eta:a.runsOutEta});const d=ce(o(a.projectedEnd??100));return i(n?"limits.explain.ahead_pct_remaining":"limits.explain.ahead_pct",{label:s,pct:d})}const l=Math.max(0,Math.min(100,Number(ee(t.window,t.pctField))||0)),c=ce(o(a.projectedEnd??l));return i(n?"limits.explain.on_track_remaining":"limits.explain.on_track",{label:s,pct:c})}function qt({pace:t}){return t.pacePercent!=null}function zt({rows:t,mode:a,now:r=Date.now()}){if(t.length===0)return null;const s=a===j.REMAINING,n=t.some(qt);return e.jsxs("div",{className:"mt-1 flex flex-col gap-1",children:[t.map(({spec:o,pace:l})=>{const c=Oe(ae(re(o.window,o.resetField)));return e.jsxs("div",{className:"text-[11px] leading-snug text-oai-gray-600 dark:text-oai-gray-300",children:[Le(o,l,a),c?e.jsxs("span",{className:"text-oai-gray-400 dark:text-oai-gray-500",children:[" · ",i(o.timeKind==="expiry"?"limits.hover.expires_at":"limits.hover.resets_at",{time:c})]}):null]},o.key)}),n?e.jsx("div",{className:"mt-1 pt-1.5 border-t border-oai-gray-200/70 dark:border-oai-gray-700/50 text-[10.5px] leading-snug text-oai-gray-400 dark:text-oai-gray-500",children:i(s?"limits.explain.body_remaining":"limits.explain.body")}):null]})}function J(t){if(!t)return null;const a=Date.now()-new Date(t).getTime();if(a<0)return null;const r=Math.floor(a/6e4);if(r<1)return i("shared.time.now");if(r<60)return i("shared.time.m_ago",{n:r});const s=Math.floor(r/60);if(s<24)return i("shared.time.h_ago",{n:s});const n=Math.floor(s/24);return i("shared.time.d_ago",{n})}const je={live:{surface:"bg-oai-gray-50 dark:bg-oai-gray-800 border-oai-gray-200/60 dark:border-oai-gray-700/60 text-oai-gray-500 dark:text-oai-gray-400",dot:"bg-emerald-500",pulse:"bg-emerald-400"},stale:{surface:"bg-oai-gray-50 dark:bg-oai-gray-800 border-oai-gray-200/60 dark:border-oai-gray-700/60 text-oai-gray-500 dark:text-oai-gray-400",dot:"bg-amber-500",pulse:"bg-amber-400"},cached:{surface:"bg-oai-gray-50 dark:bg-oai-gray-800 border-oai-gray-200/60 dark:border-oai-gray-700/60 text-oai-gray-500 dark:text-oai-gray-400",dot:"bg-amber-500",pulse:"bg-amber-400"}},Yt={claude:"claude",codex:"codex"};function W({label:t,age:a=null,tone:r="live",tooltip:s=null}){const n=je[r]||je.live,o=r==="live";return e.jsxs("div",{className:"relative inline-flex items-center group cursor-help ml-1",onClick:l=>l.stopPropagation(),children:[e.jsxs("span",{className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded-full text-[9px] font-semibold uppercase tracking-wider border leading-normal ${n.surface}`,children:[o?e.jsxs("span",{className:"relative flex h-1.5 w-1.5",children:[e.jsx("span",{className:`animate-ping absolute inline-flex h-full w-full rounded-full ${n.pulse} opacity-75`}),e.jsx("span",{className:`relative inline-flex rounded-full h-1.5 w-1.5 ${n.dot}`})]}):e.jsx("span",{className:`h-1.5 w-1.5 rounded-full ${n.dot}`}),t,a?e.jsxs(e.Fragment,{children:[" · ",a]}):null]}),s?e.jsxs("span",{className:"pointer-events-none absolute left-1/2 bottom-full z-20 mb-2 -translate-x-1/2 w-48 rounded-md bg-oai-gray-900 dark:bg-oai-gray-800 px-2.5 py-1.5 text-[10px] font-normal text-white text-center opacity-0 scale-95 translate-y-1 group-hover:opacity-100 group-hover:scale-100 group-hover:translate-y-0 transition-all duration-200 cubic-bezier(0.16, 1, 0.3, 1) leading-normal shadow-lg origin-bottom border border-oai-gray-800 dark:border-oai-gray-700",children:[s,e.jsx("span",{className:"absolute left-1/2 top-full -translate-x-1/2 border-4 border-transparent border-t-oai-gray-900 dark:border-t-oai-gray-800"})]}):null]})}function $e({name:t,providerId:a,children:r,expandable:s=!1,expanded:n=!1,onToggle:o,badge:l=null,rightAdornment:c=null}){const d=Pe(a),m=e.jsxs("div",{className:"flex items-center gap-1.5",children:[d?e.jsx(Te,{provider:d,size:14,className:Lt}):null,e.jsx("span",{className:"text-sm font-medium text-oai-black dark:text-oai-white",children:t}),l,c?e.jsx("span",{className:"ml-auto shrink-0",children:c}):null]});return s?e.jsxs("div",{role:"button",tabIndex:0,"aria-expanded":n,onClick:o,onKeyDown:g=>{(g.key==="Enter"||g.key===" ")&&(g.preventDefault(),o?.())},className:"flex flex-col gap-1.5 -mx-1.5 px-1.5 py-1 rounded-lg cursor-pointer transition-colors hover:bg-oai-gray-50 dark:hover:bg-oai-gray-800/40 aria-expanded:bg-oai-gray-50 dark:aria-expanded:bg-oai-gray-800/40",children:[m,r]}):e.jsxs("div",{className:"flex flex-col gap-1.5",children:[m,r]})}function He({subscription:t}){const a=t.autoRenew?i("subscriptions.badge.auto_renew"):i("subscriptions.badge.stops"),r=t.autoRenew?_t:wt;return e.jsx("span",{role:"img","aria-label":a,title:a,className:`inline-flex translate-y-px ${t.autoRenew?"text-oai-brand-600 dark:text-oai-brand-400":"text-blue-600 dark:text-blue-400"}`,children:e.jsx(r,{size:14,strokeWidth:2,"aria-hidden":!0})})}function Ue({subscription:t,now:a}){const r=pe(t,a);if(!r)return null;const{endMs:s,expired:n}=r,o=!n&&s-a<=3*864e5,l=n?100:r.progress*100,c=Math.round(l),d=l>0&&c===0?i("limits.bar.sub_one_percent"):`${c}%`;return e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[11px] text-oai-gray-500 dark:text-oai-gray-400 shrink-0 whitespace-nowrap",style:{width:"var(--tt-limits-label-w)"},children:i("subscriptions.inline.label")}),e.jsx("div",{className:"relative flex-1 bg-oai-gray-100 dark:bg-oai-gray-700/50 rounded-full h-1.5 overflow-hidden",children:e.jsx("div",{className:`${n?"bg-red-500":o?"bg-amber-500":"bg-oai-brand-500"} rounded-full h-full block transition-[width] duration-500 ease-out`,style:{width:`${l}%`,minWidth:l>0?"3px":0}})}),e.jsx("span",{className:"text-[11px] tabular-nums text-oai-gray-500 dark:text-oai-gray-400 w-9 text-right shrink-0 whitespace-nowrap",children:d}),e.jsx("span",{className:`text-[10px] tabular-nums shrink-0 whitespace-nowrap w-6 text-right ${n?"text-oai-error":"text-oai-gray-400 dark:text-oai-gray-500"}`,children:Ae(s,a)})]})}function Be({subscription:t,now:a}){const r=pe(t,a);if(!r)return null;const s=new Intl.DateTimeFormat(te(),{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"});return e.jsxs("div",{className:"text-[11px] leading-snug text-oai-gray-500 dark:text-oai-gray-400",children:[e.jsx("span",{children:i("subscriptions.inline.label")}),e.jsx("span",{className:"text-oai-gray-300 dark:text-oai-gray-600",children:":"}),e.jsx("span",{children:t.autoRenew?i("subscriptions.label.renews_at"):i("subscriptions.label.expires_at")}),e.jsx("span",{children:" "}),e.jsx("span",{className:"font-mono tabular-nums",children:s.format(new Date(r.endMs))}),e.jsx("span",{className:"text-oai-gray-300 dark:text-oai-gray-600",children:" · "}),e.jsx("span",{className:r.expired?"text-oai-error":void 0,children:Re(r.endMs,a)}),e.jsx("span",{className:"text-oai-gray-300 dark:text-oai-gray-600",children:" · "}),e.jsx("span",{children:t.autoRenew?i("subscriptions.status.auto_renew"):i("subscriptions.status.manual")})]})}const Vt=Ce;function E({children:t,tone:a="neutral"}){const r=a==="error"?"text-red-600 dark:text-red-400":"text-oai-gray-500 dark:text-oai-gray-400";return e.jsx("div",{className:`text-[11px] leading-snug ${r}`,children:t})}function Kt({rows:t,mode:a,extra:r=null}){const s=t.length===0&&!r;return e.jsxs(e.Fragment,{children:[t.map(({spec:n,pace:o})=>e.jsx(Wt,{label:n.label??i(n.labelKey),pct:ee(n.window,n.pctField),reset:$t(re(n.window,n.resetField)),mode:a,pacePercent:o.pacePercent,paceOver:o.paceOver,title:Gt(n,o,a)},n.key)),s?e.jsx(E,{children:i("limits.status.no_data")}):null,r]})}function Xt(t){if(!Number.isFinite(t.expiresMs))return null;const a=Math.floor((t.expiresMs-Date.now())/864e5);return a<0?null:a===0?i("limits.reset_bank.hover_detail_today",{date:t.expiresAt}):i("limits.reset_bank.hover_detail",{date:t.expiresAt,days:a})}function Jt({row:t}){const a=Math.max(0,Math.min(100,Number(t.percent)||0));return e.jsxs("div",{className:"group relative flex items-center gap-2","data-reset-bank-row":"",children:[e.jsx(Fe,{text:Xt(t)}),e.jsx("span",{"data-limit-label":"",className:"text-[11px] text-oai-gray-500 dark:text-oai-gray-400 shrink-0 whitespace-nowrap",style:{width:"var(--tt-limits-label-w)"},children:t.label}),e.jsx("div",{className:"relative flex-1 bg-oai-gray-100 dark:bg-oai-gray-700/50 rounded-full h-1.5 overflow-hidden",children:e.jsx("div",{className:"bg-oai-gray-400 dark:bg-oai-gray-500 rounded-full h-full transition-[width] duration-500 ease-out",style:{width:`${a}%`,minWidth:a>0?"3px":0}})}),e.jsx("span",{className:"text-[10px] tabular-nums text-oai-gray-400 dark:text-oai-gray-500 w-[4.25rem] text-right shrink-0 whitespace-nowrap",children:t.expiresAt})]})}function Qt({model:t}){const a=t.kind==="count_only"?i("limits.codex_reset_bank.count_only",{count:t.availableCount}):null;return e.jsxs("div",{className:"mt-1 flex flex-col gap-1","data-reset-bank-section":t.kind,children:[e.jsx("div",{className:"text-[10.5px] font-medium uppercase tracking-wide text-oai-gray-400 dark:text-oai-gray-500",children:i("limits.codex_reset_bank.title")}),a?e.jsx("div",{className:"text-[11px] leading-snug text-oai-gray-500 dark:text-oai-gray-400",children:a}):t.rows.map(r=>e.jsx(Jt,{row:r},r.key))]})}function Ge(t,a){if(t==="codex_meta"){const r=At(a.reset_credits);return r?e.jsx(Qt,{model:r}):null}if(t==="kimi_parallel"&&a.parallel_limit)return e.jsx(E,{children:i("limits.label.kimi_parallel",{count:a.parallel_limit})});if(t==="kiro_credits"&&Number.isFinite(Number(a.tracked_credits))&&Number(a.tracked_credit_records)>0){const r=Q(a.tracked_credits,{maximumFractionDigits:2});return e.jsx(E,{children:i("limits.label.kiro_tracked_credits",{credits:r,count:Number(a.tracked_credit_records)})})}return t==="copilot_otel"&&!a.otel_has_files&&!a.otel_enabled?e.jsx(ta,{defaultDir:a.otel_default_dir}):null}function Zt(t,a,r,s,n,o,l=null,c=null,d=Date.now()){const m=me[t];if(!m)return null;const g=m.windows(a).filter(h=>h.window).map(h=>({spec:h,pace:Bt(h,s)})),f=Ge(m.extra,a);return e.jsxs($e,{name:r,providerId:t,expandable:g.length>0||!!c,expanded:n,onToggle:o,badge:l,rightAdornment:c?e.jsx(He,{subscription:c}):null,children:[e.jsx(Kt,{mode:s,rows:g,extra:f}),c?e.jsx(Ue,{subscription:c,now:d}):null,n?e.jsx(zt,{rows:g,mode:s,now:d}):null,n&&c?e.jsx(Be,{subscription:c,now:d}):null]},t)}function de(t,a,r,s,n=null,o=Date.now()){const l=!!n;return e.jsxs($e,{name:Z(t),providerId:t,expandable:l,expanded:r,onToggle:s,rightAdornment:l?e.jsx(He,{subscription:n}):null,children:[a,l?e.jsx(Ue,{subscription:n,now:o}):null,l&&r?e.jsx("div",{className:"mt-1",children:e.jsx(Be,{subscription:n,now:o})}):null]},t)}function ea(t,a,r,s,n,o=null,l=Date.now()){if(!me[t])return null;if(!a?.configured)return de(t,e.jsxs(e.Fragment,{children:[e.jsx(E,{children:i("limits.status.not_connected")}),t==="opencodeGo"?e.jsx(we,{}):null,t==="codingPlan"?e.jsx(Ne,{}):null]}),s,n,o,l);if(t==="opencodeGo"&&a.subscription_status==="inactive")return de(t,e.jsx(E,{children:i("limits.opencodeGo.status.inactive")}),s,n,o,l);if(a.error)return de(t,e.jsxs(e.Fragment,{children:[e.jsx(E,{tone:"error",children:i("shared.error.prefix",{error:a.error})}),t==="kiro"?Ge(me.kiro.extra,a):null,t==="opencodeGo"?e.jsx(we,{}):null,t==="codingPlan"?e.jsx(Ne,{}):null]}),s,n,o,l);const c=Z(t),d=a.plan_label?`${c} ${a.plan_label}`:c;let m=null;if(t==="antigravity")if(a.cached){const f=J(a.cached_at);m=e.jsx(W,{label:i("limits.label.antigravity_cached"),age:f,tone:"cached",tooltip:i("limits.tooltip.antigravity_cached")})}else m=e.jsx(W,{label:i("limits.label.antigravity_live"),tone:"live",tooltip:i("limits.tooltip.antigravity_live")});if((t==="qoder"||t==="qoderCn"||t==="codingPlan")&&a.cached&&(m=e.jsx(W,{label:i("limits.label.antigravity_cached"),age:J(a.cached_at),tone:"cached",tooltip:i("limits.tooltip.qoder_cached")})),!m&&a.auth_action_required==="reauth"){const f=Yt[t];m=e.jsx(W,{label:i("limits.reauth.badge"),age:J(a.cached_at),tone:"stale",tooltip:f?i("limits.reauth.tooltip",{command:f}):null})}const g=a.provenance;return g?.stale&&!m&&(m=e.jsx(W,{label:i("limits.provenance.stale"),age:J(g.captured_at),tone:"stale",tooltip:i("limits.provenance.tooltip",{source:g.source,confidence:g.confidence})})),Zt(t,a,d,r,s,n,m,o,l)}function ta({defaultDir:t}){const[a,r]=x.useState(!1),n=["export COPILOT_OTEL_ENABLED=true","export COPILOT_OTEL_EXPORTER_TYPE=file",`export COPILOT_OTEL_FILE_EXPORTER_PATH="${t||"$HOME/.copilot/otel"}/copilot-otel-$(date +%Y%m%d).jsonl"`].join(`
|
|
3
|
-
`),o=async l=>{l.stopPropagation();try{await navigator.clipboard.writeText(n),r(!0),setTimeout(()=>r(!1),1600)}catch{}};return e.jsxs("div",{className:"mt-1 rounded-md border border-amber-300/60 dark:border-amber-700/40 bg-amber-50/50 dark:bg-amber-900/10 px-2.5 py-2 text-[11px] text-oai-gray-600 dark:text-oai-gray-300",children:[e.jsx("div",{className:"font-medium text-oai-gray-700 dark:text-oai-gray-200",children:i("limits.copilot.otelHint.title")}),e.jsx("div",{className:"mt-0.5 leading-snug",children:i("limits.copilot.otelHint.body")}),e.jsx("pre",{className:"mt-1.5 overflow-x-auto rounded bg-oai-gray-100 dark:bg-oai-gray-900/60 px-2 py-1.5 font-mono text-[10.5px] leading-tight whitespace-pre",children:n}),e.jsx("button",{type:"button",onClick:o,className:"mt-1 inline-flex items-center gap-1 rounded border border-oai-gray-300 dark:border-oai-gray-700 px-1.5 py-0.5 text-[10.5px] text-oai-gray-700 dark:text-oai-gray-200 hover:bg-oai-gray-100 dark:hover:bg-oai-gray-800 transition-colors",children:a?i("limits.copilot.otelHint.copied"):i("limits.copilot.otelHint.copy")})]})}function O({n:t,children:a}){return e.jsxs("li",{className:"flex gap-2.5",children:[e.jsx("span",{className:"mt-[1px] flex h-4 w-4 shrink-0 items-center justify-center rounded-full bg-oai-brand/15 text-[9px] font-semibold text-oai-brand",children:t}),e.jsx("div",{className:"min-w-0 flex-1 leading-snug",children:a})]})}function We(){return e.jsx("svg",{viewBox:"0 0 12 12","aria-hidden":"true",className:"h-2.5 w-2.5",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("path",{d:"M4.5 2.75h4.75V7.5M9.25 2.75 3 9"})})}function we(){const[t,a]=x.useState(!1),r=["read -r -s OPENCODE_GO_API_KEY","export OPENCODE_GO_API_KEY",'launchctl setenv OPENCODE_GO_API_KEY "$OPENCODE_GO_API_KEY"'].join(`
|
|
4
|
-
`),s=async n=>{n.stopPropagation();try{await navigator.clipboard.writeText(r),a(!0),setTimeout(()=>a(!1),1600)}catch{}};return e.jsxs("div",{className:"mt-1.5 rounded-lg border border-oai-gray-200 dark:border-oai-gray-700/60 bg-oai-gray-50/50 dark:bg-oai-gray-900/20 p-3 text-[11px] text-oai-gray-600 dark:text-oai-gray-300",children:[e.jsx("div",{className:"text-[12px] font-semibold text-oai-gray-800 dark:text-oai-gray-100",children:i("limits.opencodeGo.setupHint.title")}),e.jsx("div",{className:"mt-0.5 leading-snug text-oai-gray-500 dark:text-oai-gray-400",children:i("limits.opencodeGo.setupHint.subtitle")}),e.jsxs("ol",{className:"mt-2.5 space-y-2.5",children:[e.jsxs(O,{n:"1",children:[e.jsx("div",{children:i("limits.opencodeGo.setupHint.step1")}),e.jsxs("a",{href:"https://opencode.ai",target:"_blank",rel:"noreferrer",onClick:n=>n.stopPropagation(),className:"mt-1 inline-flex items-center gap-1 rounded-md bg-oai-brand/10 px-2 py-1 font-medium text-oai-brand hover:bg-oai-brand/15 transition-colors",children:[i("limits.opencodeGo.setupHint.cta"),e.jsx(We,{})]})]}),e.jsx(O,{n:"2",children:e.jsx("div",{children:i("limits.opencodeGo.setupHint.step2")})}),e.jsxs(O,{n:"3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{children:i("limits.opencodeGo.setupHint.step3")}),e.jsx("button",{type:"button",onClick:s,className:"shrink-0 rounded-md border border-oai-gray-300 dark:border-oai-gray-700 px-2 py-0.5 text-[10.5px] text-oai-gray-700 dark:text-oai-gray-200 hover:bg-oai-gray-100 dark:hover:bg-oai-gray-800 transition-colors",children:t?i("limits.opencodeGo.setupHint.copied"):i("limits.opencodeGo.setupHint.copy")})]}),e.jsx("pre",{className:"mt-1.5 overflow-x-auto rounded-md bg-oai-gray-100 dark:bg-oai-gray-900/60 px-2 py-1.5 font-mono text-[10.5px] leading-relaxed whitespace-pre",children:r}),e.jsx("div",{className:"mt-1 text-[10px] text-oai-gray-400 dark:text-oai-gray-500",children:i("limits.opencodeGo.setupHint.note_app")})]})]})]})}function Ne(){const[t,a]=x.useState(!1),r=["npm install -g @volcengine/ark-cli","arkcli auth login volc-sso # browser SSO (recommended)","arkcli auth status # verify the session"].join(`
|
|
5
|
-
`),s=async n=>{n.stopPropagation();try{await navigator.clipboard.writeText(r),a(!0),setTimeout(()=>a(!1),1600)}catch{}};return e.jsxs("div",{className:"mt-1.5 rounded-lg border border-oai-gray-200 dark:border-oai-gray-700/60 bg-oai-gray-50/50 dark:bg-oai-gray-900/20 p-3 text-[11px] text-oai-gray-600 dark:text-oai-gray-300",children:[e.jsx("div",{className:"text-[12px] font-semibold text-oai-gray-800 dark:text-oai-gray-100",children:i("limits.codingPlan.setupHint.title")}),e.jsx("div",{className:"mt-0.5 leading-snug text-oai-gray-500 dark:text-oai-gray-400",children:i("limits.codingPlan.setupHint.subtitle")}),e.jsxs("ol",{className:"mt-2.5 space-y-2.5",children:[e.jsxs(O,{n:"1",children:[e.jsx("div",{children:i("limits.codingPlan.setupHint.step1")}),e.jsxs("a",{href:"https://www.volcengine.com/docs/82379/2536875",target:"_blank",rel:"noreferrer",onClick:n=>n.stopPropagation(),className:"mt-1 inline-flex items-center gap-1 rounded-md bg-oai-brand/10 px-2 py-1 font-medium text-oai-brand hover:bg-oai-brand/15 transition-colors",children:[i("limits.codingPlan.setupHint.cta"),e.jsx(We,{})]})]}),e.jsxs(O,{n:"2",children:[e.jsx("div",{children:i("limits.codingPlan.setupHint.step2")}),e.jsx("div",{className:"mt-0.5 text-oai-gray-500 dark:text-oai-gray-400",children:i("limits.codingPlan.setupHint.step2_remote")})]}),e.jsxs(O,{n:"3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{children:i("limits.codingPlan.setupHint.step3")}),e.jsx("button",{type:"button",onClick:s,className:"shrink-0 rounded-md border border-oai-gray-300 dark:border-oai-gray-700 px-2 py-0.5 text-[10.5px] text-oai-gray-700 dark:text-oai-gray-200 hover:bg-oai-gray-100 dark:hover:bg-oai-gray-800 transition-colors",children:t?i("limits.codingPlan.setupHint.copied"):i("limits.codingPlan.setupHint.copy")})]}),e.jsx("pre",{className:"mt-1.5 overflow-x-auto rounded-md bg-oai-gray-100 dark:bg-oai-gray-900/60 px-2 py-1.5 font-mono text-[10.5px] leading-relaxed whitespace-pre",children:r}),e.jsx("div",{className:"mt-1 text-[10px] text-oai-gray-400 dark:text-oai-gray-500",children:i("limits.codingPlan.setupHint.note_app")})]})]})]})}function aa(t){const[a,r]=x.useState(0);return x.useLayoutEffect(()=>{const s=t.current;if(!s)return;const n=s.querySelectorAll("[data-limit-label]");let o=0,l=null;if(n.length>0)try{l=document.createElement("canvas").getContext("2d")}catch{l=null}if(l){const d=window.getComputedStyle(n[0]);l.font=`${d.fontStyle} ${d.fontWeight} ${d.fontSize} ${d.fontFamily}`;for(const m of n)o=Math.max(o,l.measureText(m.textContent).width)}const c=Math.ceil(o);r(d=>d===c?d:c)}),a}function ra({claude:t,codex:a,cursor:r,gemini:s,kimi:n,kiro:o,grok:l,antigravity:c,copilot:d,zcode:m,opencodeGo:g,qoder:f,qoderCn:h,codingPlan:v,order:w,visibility:k,displayMode:M,subscriptions:F=[]}){const ie={claude:t,codex:a,cursor:r,gemini:s,kimi:n,kiro:o,grok:l,antigravity:c,copilot:d,zcode:m,opencodeGo:g,qoder:f,qoderCn:h,codingPlan:v},L=x.useRef(null),Y=aa(L),[$,ne]=x.useState(null),[H,I]=x.useState(()=>Date.now()),se=Array.isArray(w)&&w.length>0?w:Vt,U=M===j.REMAINING?j.REMAINING:j.USED,S=U===j.REMAINING?i("limits.settings.display_mode_remaining"):i("limits.settings.display_mode_used");x.useEffect(()=>{const p=setInterval(()=>I(Date.now()),6e4);return()=>clearInterval(p)},[]);const C=new Map;for(const p of F||[]){if(!p?.provider)continue;const N=new Date(p.nextBillingAt).getTime();if(!Number.isFinite(N))continue;const K=C.get(p.provider);if(!K){C.set(p.provider,p);continue}const B=new Date(K.nextBillingAt).getTime(),A=N>H,X=B>H;(A&&(!X||B>N)||!A&&!X&&N>B)&&C.set(p.provider,p)}const V=se.filter(p=>!k||k[p]!==!1||C.has(p)).map(p=>ea(p,ie[p],U,$===p,()=>ne(N=>N===p?null:p),C.get(p)||null,H)).filter(Boolean);return e.jsx(st,{delay:.15,children:e.jsx(Se,{children:e.jsxs("div",{ref:L,className:"flex flex-col gap-3",style:Y>0?{"--tt-limits-label-w":`${Y}px`}:void 0,children:[e.jsxs("h3",{className:"text-sm font-medium text-oai-gray-500 dark:text-oai-gray-300 uppercase tracking-wide",children:[i("limits.panel.title"),i("limits.panel.mode_separator"),S]}),V.length>0?V:e.jsx(E,{children:i("limits.status.all_hidden")})]})})})}async function qe(t){const a=await t.json().catch(()=>null);if(!t.ok||a?.ok===!1)throw new Error(a?.error||`Subscription request failed with HTTP ${t.status}`);return a}async function ia(){const t=await fetch("/functions/tokentracker-subscription-manager",{headers:{Accept:"application/json"},cache:"no-store"}),a=await qe(t);return Array.isArray(a.subscriptions)?a.subscriptions:[]}async function ge(t){const a=await Ve();return qe(await fetch("/functions/tokentracker-subscription-manager",{method:"POST",headers:{Accept:"application/json","Content-Type":"application/json",...a},cache:"no-store",body:JSON.stringify(t)}))}function na(t){return ge({action:"create",subscription:t})}function sa(t,a){return ge({action:"update",id:t,subscription:a})}function oa(t){return ge({action:"delete",id:t})}const ue={plan:"",provider:"",cycle:"monthly",autoRenew:!0,startedAt:""};function la(t){const a=new Date(t);if(Number.isNaN(a.getTime()))return"";const r=s=>String(s).padStart(2,"0");return`${a.getFullYear()}-${r(a.getMonth()+1)}-${r(a.getDate())}T${r(a.getHours())}:${r(a.getMinutes())}`}function ca({subscriptions:t,onChanged:a}){const[r,s]=x.useState(!1),[n,o]=x.useState(null),[l,c]=x.useState(ue),[d,m]=x.useState(!1),[g,f]=x.useState(!1),[h,v]=x.useState(!1),[w,k]=x.useState(!1),[M,F]=x.useState(null),[ie,L]=x.useState(!1),[Y,$]=x.useState(!1),[ne,H]=x.useState(null),[I,se]=x.useState(()=>Date.now()),U=x.useRef(null),S=te(),C=x.useMemo(()=>new Intl.DateTimeFormat(S,{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"}),[S]);x.useEffect(()=>{const u=setInterval(()=>se(Date.now()),6e4);return()=>clearInterval(u)},[]),x.useEffect(()=>{if(!r)return;const u=window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;U.current?.scrollIntoView?.({behavior:u?"auto":"smooth",block:"nearest"})},[r,n]);const V=x.useMemo(()=>Ce.map(u=>{const _=(t||[]).some(y=>y.provider===u&&y.id!==n),b=Z(u);return{value:u,label:_?`${b} ${i("subscriptions.form.provider_taken_suffix")}`:b,disabled:_}}),[S,t,n]),p=x.useMemo(()=>[{value:"weekly",label:i("subscriptions.form.cycle_weekly")},{value:"monthly",label:i("subscriptions.form.cycle_monthly")},{value:"yearly",label:i("subscriptions.form.cycle_yearly")}],[S]),N=x.useMemo(()=>[{value:"true",label:i("subscriptions.form.auto_renew_on")},{value:"false",label:i("subscriptions.form.auto_renew_off")}],[S]),K=x.useCallback(()=>{c(ue),o(null),f(!1),v(!1),k(!1),s(!0)},[]),B=x.useCallback(u=>{c({plan:u.plan||"",provider:u.provider||"",cycle:u.cycle||"monthly",autoRenew:u.autoRenew,startedAt:la(new Date(Rt(u)).toISOString())}),o(u.id),f(!1),v(!1),k(!1),s(!0)},[]),A=x.useCallback(()=>{s(!1),o(null),c(ue),f(!1),v(!1),k(!1)},[]),X=x.useCallback(async u=>{if(u.preventDefault(),f(!1),!l.provider){v(!0);return}if((t||[]).some(R=>R.provider===l.provider&&R.id!==n)){k(!0);return}const b=new Date(l.startedAt).getTime();if(!Number.isFinite(b)){f(!0);return}const y={service:Z(l.provider),plan:l.plan,provider:l.provider||null,autoRenew:l.autoRenew,cycle:l.cycle,startedAt:b,nextBillingAt:Ie(b,l.cycle)};m(!0);try{n?await sa(n,y):await na(y),A(),await a?.()}catch{f(!0)}finally{m(!1)}},[A,n,l,a,t]),ze=x.useCallback(async()=>{if(M){L(!0),$(!1);try{await oa(M.id),F(null),await a?.()}catch{$(!0)}finally{L(!1)}}},[a,M]),fe=t||[],he=()=>e.jsxs("form",{ref:U,onSubmit:X,className:"grid grid-cols-1 gap-3 px-3 py-3 text-left sm:grid-cols-2",children:[e.jsx("div",{className:"flex items-center justify-between sm:col-span-2",children:e.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide text-oai-gray-500 dark:text-oai-gray-400",children:n?i("subscriptions.edit"):i("subscriptions.add")})}),e.jsxs("div",{className:"flex flex-col sm:col-span-1",children:[e.jsx("label",{htmlFor:"subscription-provider",className:"block text-sm font-medium text-oai-gray-700 dark:text-oai-gray-300 mb-1.5",children:i("subscriptions.form.provider")}),e.jsx(le,{id:"subscription-provider",value:l.provider,onValueChange:u=>c({...l,provider:String(u)}),options:V,matchTriggerWidth:!0,className:"h-10 w-full px-3 text-sm"})]}),e.jsx("div",{className:"sm:col-span-1",children:e.jsx(ve,{label:i("subscriptions.form.plan"),value:l.plan,maxLength:120,placeholder:i("subscriptions.form.plan_placeholder"),onChange:u=>c({...l,plan:u.target.value})})}),e.jsxs("div",{className:"flex flex-col sm:col-span-1",children:[e.jsx("label",{htmlFor:"subscription-cycle",className:"block text-sm font-medium text-oai-gray-700 dark:text-oai-gray-300 mb-1.5",children:i("subscriptions.form.cycle")}),e.jsx(le,{id:"subscription-cycle",value:l.cycle,onValueChange:u=>c({...l,cycle:String(u)}),options:p,matchTriggerWidth:!0,className:"h-10 w-full px-3 text-sm"})]}),e.jsxs("div",{className:"flex flex-col sm:col-span-1",children:[e.jsx("label",{htmlFor:"subscription-auto-renew",className:"block text-sm font-medium text-oai-gray-700 dark:text-oai-gray-300 mb-1.5",children:i("subscriptions.form.auto_renew")}),e.jsx(le,{id:"subscription-auto-renew",value:String(l.autoRenew),onValueChange:u=>c({...l,autoRenew:u==="true"}),options:N,matchTriggerWidth:!0,className:"h-10 w-full px-3 text-sm"})]}),e.jsx("div",{className:"sm:col-span-2",children:e.jsx(ve,{label:i("subscriptions.form.started_at"),type:"datetime-local",value:l.startedAt,required:!0,onChange:u=>c({...l,startedAt:u.target.value})})}),e.jsxs("div",{className:"flex items-center justify-end gap-2 sm:col-span-2",children:[h?e.jsx("p",{className:"mr-auto text-sm text-oai-error",role:"alert",children:i("subscriptions.form.provider_required")}):null,w?e.jsx("p",{className:"mr-auto text-sm text-oai-error",role:"alert",children:i("subscriptions.form.provider_taken")}):null,g?e.jsx("p",{className:"mr-auto text-sm text-oai-error",role:"alert",children:i("subscriptions.form.error")}):null,e.jsx(G,{type:"button",variant:"secondary",size:"sm",onClick:A,children:i("shared.action.cancel")}),e.jsx(G,{type:"submit",size:"sm",disabled:d,children:i("subscriptions.save")})]})]});return e.jsxs("div",{className:"flex max-h-[min(80vh,42rem)] w-[min(92vw,32rem)] flex-col gap-3 overflow-y-auto rounded-xl border border-oai-gray-200 bg-white p-4 shadow-lg dark:border-oai-gray-700 dark:bg-oai-gray-900",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("div",{className:"min-w-0",children:e.jsx("span",{className:"block truncate text-sm font-semibold text-oai-black dark:text-white",children:i("limits.page.openSubscriptions")})}),e.jsxs(G,{type:"button",size:"sm",onClick:K,className:"shrink-0 gap-1.5",children:[e.jsx(dt,{size:14,strokeWidth:2,"aria-hidden":!0}),e.jsx("span",{children:i("subscriptions.add")})]})]}),fe.length===0&&!(r&&!n)?e.jsxs("div",{className:"flex flex-col items-center justify-center gap-1 rounded-lg border border-dashed border-oai-gray-200 px-4 py-10 text-center dark:border-oai-gray-700",children:[e.jsx(De,{className:"h-6 w-6 text-oai-gray-300 dark:text-oai-gray-600 mb-2","aria-hidden":!0}),e.jsx("p",{className:"text-sm font-medium text-oai-black dark:text-white",children:i("subscriptions.empty.title")}),e.jsx("p",{className:"text-xs text-oai-gray-500 dark:text-oai-gray-400",children:i("subscriptions.empty.body")})]}):e.jsxs("ul",{className:"flex flex-col gap-1.5",children:[fe.map(u=>{const _=pe(u,I);if(!_)return null;const{endMs:b,expired:y}=_,R=y?100:_.progress*100,Ye=!y&&b-I<=3*864e5,oe=ne===u.id;return e.jsxs("li",{className:"rounded-lg border border-oai-gray-100 dark:border-oai-gray-800",children:[e.jsxs("button",{type:"button",onClick:()=>H(oe?null:u.id),"aria-expanded":oe,className:"w-full flex flex-col gap-1.5 px-3 py-2.5 text-left cursor-pointer hover:bg-oai-gray-50 dark:hover:bg-oai-gray-800/40 rounded-lg transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand-500",children:[e.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[e.jsx(Te,{provider:Pe(u.provider)||"OTHER",size:14}),e.jsx("span",{className:"text-sm font-medium text-oai-black dark:text-white truncate",children:u.service}),u.plan?e.jsx("span",{className:"text-xs rounded-full border border-oai-gray-200 dark:border-oai-gray-700 px-2 py-0.5 text-oai-gray-500 dark:text-oai-gray-400 shrink-0",children:u.plan}):null]}),e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[10px] text-oai-gray-500 dark:text-oai-gray-400 shrink-0",children:i("shared.time.d_ago",{n:_.cycleDays})}),e.jsx("span",{className:"relative flex-1 bg-oai-gray-100 dark:bg-oai-gray-700/50 rounded-full h-1 overflow-hidden",children:e.jsx("span",{className:`${y?"bg-red-500":Ye?"bg-amber-500":"bg-oai-brand-500"} rounded-full h-full block transition-[width] duration-500 ease-out`,style:{width:`${R}%`,minWidth:R>0?"3px":0}})}),e.jsx("span",{className:`text-[10px] tabular-nums shrink-0 ${y?"text-oai-error":"text-oai-gray-400 dark:text-oai-gray-500"}`,children:Ae(b,I)})]})]}),n===u.id?e.jsx("div",{className:"border-t border-oai-gray-100 dark:border-oai-gray-800",children:he()}):null,n!==u.id&&oe?e.jsxs("div",{className:"px-3 pb-3 flex flex-col gap-2 border-t border-oai-gray-100 dark:border-oai-gray-800",children:[e.jsxs("p",{className:"pt-2 text-xs text-oai-gray-600 dark:text-oai-gray-300",children:[e.jsx("span",{className:"text-oai-gray-400 dark:text-oai-gray-500",children:u.autoRenew?i("subscriptions.label.renews_at"):i("subscriptions.label.expires_at")})," ",e.jsx("span",{className:"font-mono tabular-nums",children:C.format(new Date(b))})," · ",e.jsx("span",{className:y?"text-oai-error":void 0,children:Re(b,I)})," · ",e.jsx("span",{children:u.autoRenew?i("subscriptions.status.auto_renew"):i("subscriptions.status.manual")})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(G,{type:"button",variant:"secondary",size:"sm",onClick:()=>B(u),children:i("subscriptions.edit")}),e.jsx(G,{type:"button",variant:"secondary",size:"sm",onClick:()=>F(u),className:"!text-red-600 dark:!text-red-400",children:i("subscriptions.delete")})]})]}):null]},u.id)}),r&&!n?e.jsx("li",{className:"rounded-lg border border-oai-gray-100 dark:border-oai-gray-800",children:he()}):null]}),e.jsx(lt,{open:!!M,title:i("subscriptions.confirm_delete_title"),description:M?.service||"",error:Y?i("subscriptions.delete_error"):null,confirmLabel:i("subscriptions.delete"),cancelLabel:i("shared.action.cancel"),destructive:!0,busy:ie,onCancel:()=>{F(null),$(!1)},onConfirm:ze})]})}const _e=typeof window<"u"&&(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1"),da="x-apple.systempreferences:com.apple.preference.notifications";function ua(){const t=ft(),a=Qe(),r=i("limits.alert.blocked"),s=a?ye.button:ye.div;return e.jsxs(s,{type:a?"button":void 0,onClick:a?()=>Ze({type:"action",name:"openURL",value:da}):void 0,initial:t?!1:{opacity:0,x:14,scale:.9},animate:{opacity:1,x:0,scale:1},transition:{type:"spring",stiffness:320,damping:18},title:r,className:`relative hidden sm:inline-flex min-w-0 max-w-[360px] items-center gap-1.5 rounded-full border border-amber-300/70 bg-amber-50 px-3 py-1.5 text-xs text-amber-700 dark:border-amber-500/30 dark:bg-amber-500/10 dark:text-amber-300 ${a?"cursor-pointer transition-colors hover:bg-amber-100 dark:hover:bg-amber-500/20 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-amber-500/60":""}`,children:[e.jsxs("span",{className:"relative flex h-1.5 w-1.5 shrink-0",children:[e.jsx("span",{className:"absolute inline-flex h-full w-full animate-ping rounded-full bg-amber-400 opacity-75"}),e.jsx("span",{className:"relative inline-flex h-1.5 w-1.5 rounded-full bg-amber-500"})]}),e.jsx("span",{className:"truncate",children:r}),e.jsx("span",{"aria-hidden":!0,className:"absolute left-full top-1/2 -translate-y-1/2 border-[5px] border-transparent border-l-amber-300/80 dark:border-l-amber-500/40"})]})}function Oa(){const t=Ke(),{data:a,error:r,isLoading:s}=at(t?{initialRefresh:!0,initialState:t,publishToPreloadCache:!0}:{initialRefresh:!0,publishToPreloadCache:!0}),n=nt(),o=rt(),[l,c]=P.useState([]),[d,m]=P.useState(!1),[g,f]=P.useState(!1),h=P.useRef(0),v=P.useCallback(async()=>{if(!_e&&!be())return;const w=++h.current;try{const k=await ia();if(w!==h.current)return;c(k),m(!1)}catch{if(w!==h.current)return;m(!0)}},[]);return P.useEffect(()=>{v()},[v]),P.useEffect(()=>{o.enabled&&a&&it(a)},[o.enabled,a]),!_e&&!be()?e.jsx("div",{className:"flex flex-col flex-1 text-oai-black dark:text-oai-white font-oai antialiased",children:e.jsx(ct,{})}):e.jsx("div",{className:"flex flex-col flex-1 text-oai-black dark:text-oai-white font-oai antialiased",children:e.jsx("main",{className:"flex-1 pt-8 sm:pt-10 pb-12 sm:pb-16",children:e.jsxs("div",{className:"mx-auto max-w-6xl px-4 sm:px-6",children:[e.jsxs("div",{className:"flex flex-row items-start justify-between gap-4 mb-8",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("h1",{className:"text-3xl sm:text-4xl font-semibold tracking-tight text-oai-black dark:text-white mb-3",children:i("nav.limits")}),e.jsx("p",{className:"text-oai-gray-500 dark:text-oai-gray-400 text-sm sm:text-base",children:i("limits.page.subtitle")})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[o.enabled&&o.permissionBlocked?e.jsx(ua,{}):null,e.jsxs(ut,{open:g,onOpenChange:f,children:[e.jsx(mt,{"aria-label":i("limits.page.openSubscriptions"),title:i("limits.page.openSubscriptions"),className:"shrink-0 inline-flex h-9 w-9 items-center justify-center rounded-lg border border-oai-gray-200 dark:border-oai-gray-800 text-oai-gray-600 dark:text-oai-gray-400 hover:bg-oai-gray-100 dark:hover:bg-oai-gray-800 hover:text-oai-black dark:hover:text-white transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand-500",children:e.jsx(De,{className:"h-4 w-4","aria-hidden":!0})}),e.jsx(xt,{children:e.jsx(pt,{side:"bottom",align:"end",sideOffset:8,className:"z-50",children:e.jsx(gt,{children:e.jsx(ca,{subscriptions:l,onChanged:v})})})})]}),e.jsx("button",{type:"button",onClick:()=>{o.setEnabled(!o.enabled)},"aria-label":o.enabled?i("limits.alert.disable"):i("limits.alert.enable"),title:o.enabled?i("limits.alert.disable"):i("limits.alert.enable"),className:`inline-flex h-9 w-9 items-center justify-center rounded-lg border border-oai-gray-200 dark:border-oai-gray-800 hover:bg-oai-gray-100 dark:hover:bg-oai-gray-800 transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand-500 ${o.enabled&&o.permissionBlocked?"text-amber-600 dark:text-amber-400":"text-oai-gray-600 dark:text-oai-gray-400 hover:text-oai-black dark:hover:text-white"}`,children:o.enabled?e.jsx(vt,{className:"h-4 w-4","aria-hidden":!0}):e.jsx(bt,{className:"h-4 w-4","aria-hidden":!0})}),e.jsx(Xe,{to:"/settings?section=limits","aria-label":i("limits.page.openSettings"),title:i("limits.page.openSettings"),className:"shrink-0 inline-flex h-9 w-9 items-center justify-center rounded-lg border border-oai-gray-200 dark:border-oai-gray-800 text-oai-gray-600 dark:text-oai-gray-400 hover:bg-oai-gray-100 dark:hover:bg-oai-gray-800 hover:text-oai-black dark:hover:text-white transition-colors no-underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand-500",children:e.jsx(Je,{className:"h-4 w-4","aria-hidden":!0})})]})]}),s?e.jsx(Pt,{}):e.jsxs(e.Fragment,{children:[r?e.jsx("p",{className:"mb-4 text-sm text-red-500 dark:text-red-400",children:i("shared.error.prefix",{error:r})}):null,d?e.jsx("p",{className:"mb-4 text-sm text-amber-600 dark:text-amber-400",children:i("subscriptions.load_error")}):null,e.jsx(ra,{claude:a?.claude,codex:a?.codex,cursor:a?.cursor,gemini:a?.gemini,kimi:a?.kimi,kiro:a?.kiro,grok:a?.grok,antigravity:a?.antigravity,copilot:a?.copilot,zcode:a?.zcode,opencodeGo:a?.opencodeGo,qoder:a?.qoder,qoderCn:a?.qoderCn,codingPlan:a?.codingPlan,order:n.order,visibility:n.visibility,displayMode:n.displayMode,subscriptions:l})]})]})})})}export{Oa as LimitsPage};
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{m as K,r as o,j as e,e as E,c as a,M as W,J as H,R as X,X as Y,d as ee,l as $,a4 as te,a5 as R}from"./__vite-browser-external-CsbVaBbw.js";import{L as ae,I as re}from"./LocalOnlyNotice-DQswDMSD.js";import{S as U}from"./SegmentedControl-C6npelCT.js";import{C as se}from"./ToolbarRootContext-Cm5cQb9Z.js";import{S as z}from"./search-CO2Xf-Kg.js";import{C as oe}from"./check-DrQztnq1.js";import{P as ie,a as ne,b as le,c as ce,d as de}from"./PopoverPopup-BVPcQAio.js";import{P as ue}from"./ProviderIcon-CljIacVj.js";import{H as xe}from"./HoverTooltip-BXcXOCs8.js";import{u as me}from"./useCurrency-CeqKrzFz.js";import{i as he}from"./host-mode-Bc_iTzHk.js";import{L as fe}from"./loader-circle-DB2txq05.js";import{T as pe}from"./terminal-DAePk67T.js";import"./arrow-up-right-Cw5mMBik.js";import"./download-BugS2cl5.js";import"./composite-MhgOkYfv.js";import"./store-a-oUpY-g.js";const ge=[["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"}]],ye=K("calendar",ge);const be=[["path",{d:"M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z",key:"1kt360"}]],ke=K("folder",be),ve="flex w-full items-center gap-2 rounded px-2 py-1.5 text-left text-sm text-oai-black outline-none hover:bg-oai-gray-100 dark:text-white dark:hover:bg-oai-gray-800";function je({options:r,value:t,onChange:s,allValue:d="all",allLabel:h,searchPlaceholder:k,emptyLabel:S,ariaLabel:u,disabled:x=!1,className:T=""}){const[p,D]=o.useState(!1),[g,w]=o.useState(""),[c,m]=o.useState(-1),F=o.useRef(null),C=`${o.useId()}-listbox`,I=t===d?h:r.find(n=>n.value===t)?.label??t,N=g.trim().toLowerCase(),v=o.useMemo(()=>N?r.filter(n=>n.label.toLowerCase().includes(N)):r,[r,N]),y=o.useMemo(()=>[{value:d,label:h},...v],[d,h,v]),O=c>=0&&c<y.length?y[c]:null,P=n=>{s(n),D(!1),w(""),m(-1)};o.useEffect(()=>{p&&F.current?.querySelector('[data-active="true"]')?.scrollIntoView?.({block:"nearest"})},[p,c]);const L=n=>{if(n.key==="ArrowDown"||n.key==="ArrowUp"){n.preventDefault();const f=n.key==="ArrowDown";m(_=>{const M=y.length;return M?f?_>=M-1?0:_+1:_<=0?M-1:_-1:-1});return}if(n.key==="Enter"){const f=O||(N&&v.length?v[0]:null);if(!f)return;n.preventDefault(),P(f.value)}};return e.jsxs(ie,{open:p,onOpenChange:n=>{D(n),m(-1),n||w("")},children:[e.jsxs(ne,{disabled:x,"aria-label":u,className:E("inline-flex h-8 max-w-[12rem] shrink-0 items-center gap-1.5 rounded-md border border-oai-gray-200 bg-oai-white px-2.5 text-xs font-medium transition hover:border-oai-gray-300 focus:outline-none focus:ring-2 focus:ring-oai-gray-400/30 disabled:opacity-60 data-[popup-open]:border-oai-gray-300 dark:border-oai-gray-800 dark:bg-oai-gray-900 dark:hover:border-oai-gray-700",t!==d?"text-oai-black dark:text-white":"text-oai-gray-700 dark:text-oai-gray-200",T),children:[e.jsx(ke,{className:"h-3.5 w-3.5 shrink-0 text-oai-gray-400","aria-hidden":!0}),e.jsx("span",{className:"truncate",children:I}),e.jsx(se,{className:"h-3.5 w-3.5 shrink-0 text-oai-gray-400","aria-hidden":!0})]}),e.jsx(le,{children:e.jsx(ce,{sideOffset:4,side:"bottom",align:"start",className:"z-[60]",children:e.jsxs(de,{className:"w-56 overflow-hidden rounded-md border border-oai-gray-200 bg-white p-1 shadow-[0_12px_32px_-12px_rgba(0,0,0,0.18)] outline-none dark:border-oai-gray-800 dark:bg-oai-gray-950 dark:shadow-[0_12px_32px_-12px_rgba(0,0,0,0.6)]",children:[e.jsxs("div",{className:"relative mb-1",children:[e.jsx(z,{className:"pointer-events-none absolute left-2.5 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-oai-gray-400","aria-hidden":!0}),e.jsx("input",{type:"text",role:"combobox","aria-expanded":!0,"aria-controls":C,"aria-activedescendant":O?`${C}-${c}`:void 0,value:g,onChange:n=>{w(n.target.value),m(-1)},onKeyDown:L,placeholder:k,className:"h-8 w-full rounded border border-oai-gray-200 bg-transparent pl-8 pr-2 text-xs text-oai-black outline-none placeholder:text-oai-gray-400 focus:border-oai-gray-400 dark:border-oai-gray-800 dark:text-white dark:focus:border-oai-gray-500"})]}),e.jsxs("div",{ref:F,id:C,role:"listbox","aria-label":u,className:"max-h-64 overflow-y-auto",children:[y.map((n,f)=>e.jsxs("button",{id:`${C}-${f}`,type:"button",role:"option","aria-selected":t===n.value,"data-active":f===c?"true":void 0,onMouseEnter:()=>m(f),onClick:()=>P(n.value),className:E(ve,t===n.value&&"bg-oai-gray-100 dark:bg-oai-gray-800",f===c&&"ring-1 ring-inset ring-oai-gray-300 dark:ring-oai-gray-600"),children:[e.jsx("span",{className:"flex-1 truncate",children:n.label}),t===n.value?e.jsx(oe,{className:"h-3.5 w-3.5 shrink-0","aria-hidden":!0}):null]},n.value)),v.length===0?e.jsx("div",{className:"px-2 py-3 text-center text-xs text-oai-gray-400 dark:text-oai-gray-500",children:S}):null]})]})})})]})}const we="tokentracker-sessions";async function Ne(r={}){const t=new URL(`/functions/${we}`,window.location.origin);r.from&&t.searchParams.set("from",r.from),r.to&&t.searchParams.set("to",r.to),r.limit&&t.searchParams.set("limit",String(r.limit)),r.refresh&&t.searchParams.set("refresh","1");const s=await fetch(t.toString(),{headers:{Accept:"application/json"},cache:"no-store"}),d=await s.json().catch(()=>null);if(!s.ok){const h=s.status===404?a("sessions.error.outdated_app"):`Request failed with HTTP ${s.status}`,k=new Error(d?.error||h);throw k.status=s.status,k}return d}const G=he(),_e=[],A=100,Se=[{id:"all",label:()=>a("sessions.filter.source_all")},{id:"claude",label:()=>"Claude Code"},{id:"codex",label:()=>"Codex"},{id:"grok",label:()=>"Grok"}],Z=[{id:"all",days:0,label:()=>a("sessions.filter.range_all")},{id:"7d",days:7,label:()=>a("sessions.filter.range_7d")},{id:"30d",days:30,label:()=>a("sessions.filter.range_30d")},{id:"90d",days:90,label:()=>a("sessions.filter.range_90d")}];function Ce(r){const t=Z.find(d=>d.id===r)?.days||0;if(!t)return 0;const s=new Date;return s.setDate(s.getDate()-(t-1)),s.setHours(0,0,0,0),s.getTime()}function Le(r,t){if(!t)return!0;const s=Date.parse(r.ended_at||r.started_at||"");return Number.isFinite(s)?s>=t:!0}function Me(r,t){if(!r)return"—";const s=Date.parse(r);if(!Number.isFinite(s))return"—";try{return new Date(s).toLocaleString(t||void 0,{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}catch{return new Date(s).toISOString().slice(0,16).replace("T"," ")}}function De(r){const t=Number(r);if(!Number.isFinite(t)||t<=0)return null;const s=Math.round(t/6e4);if(s<60)return a("sessions.duration.minutes",{minutes:s});const d=Math.floor(s/60),h=s%60;return a("sessions.duration.hours",{hours:d,minutes:h})}async function Q(r){if(navigator?.clipboard?.writeText)return await navigator.clipboard.writeText(r),!0;const t=document.createElement("textarea");t.value=r,t.style.position="fixed",t.style.opacity="0",document.body.appendChild(t),t.select();const s=document.execCommand("copy");return document.body.removeChild(t),s}const Ie=ee.memo(function({session:t,locale:s}){const{currency:d,rate:h}=me(),k=String(t.source||"").toUpperCase(),S=De(t.duration_ms),u=t.resume_command,x=t.project_key||a("sessions.project.unknown"),T=t.title||x,p=!!(t.title&&t.project_key),D=t.project_ref?`${t.project_ref}
|
|
2
|
-
${a("sessions.project.copy_hint")}`:void 0,g=async()=>{if(t.project_ref)try{await Q(t.project_ref)?R({title:a("sessions.project.copied")}):R({title:a("sessions.project.copy_failed")})}catch{R({title:a("sessions.project.copy_failed")})}},w=m=>e.jsxs("span",{className:"group relative inline-flex min-w-0 max-w-full",children:[e.jsx(xe,{text:D,placement:"bottom"}),e.jsx("button",{type:"button",onClick:g,"aria-label":a("sessions.project.copy_aria",{project:x}),className:E("max-w-full truncate rounded text-left underline decoration-dotted decoration-oai-gray-300 underline-offset-4 hover:decoration-oai-gray-500 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand-500 dark:decoration-oai-gray-600 dark:hover:decoration-oai-gray-400",m),children:x})]}),c=async()=>{if(u)try{await Q(u)?R({title:a("sessions.resume.copied")}):R({title:a("sessions.resume.copy_failed")})}catch{R({title:a("sessions.resume.copy_failed")})}};return e.jsxs("li",{className:"flex flex-col gap-3 py-4 sm:flex-row sm:items-start",children:[e.jsxs("div",{className:"flex min-w-0 flex-1 items-start gap-2.5",children:[e.jsx("span",{className:"mt-0.5 shrink-0 text-oai-gray-400 dark:text-oai-gray-500",children:e.jsx(ue,{provider:k,size:20})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[!t.title&&t.project_ref?w("font-medium text-oai-black dark:text-white"):e.jsx("span",{className:"truncate font-medium text-oai-black dark:text-white",children:T}),t.first_pass?e.jsx("span",{className:"inline-flex items-center rounded-full bg-emerald-50 px-2 py-0.5 text-[11px] font-medium text-emerald-700 dark:bg-emerald-500/10 dark:text-emerald-300",children:a("sessions.badge.first_pass")}):null]}),e.jsxs("div",{className:"mt-0.5 flex flex-wrap items-center gap-x-2 gap-y-0.5 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:[p?e.jsxs(e.Fragment,{children:[t.project_ref?w("hover:text-oai-black dark:hover:text-white"):e.jsx("span",{className:"truncate",children:x}),e.jsx("span",{"aria-hidden":!0,children:"·"})]}):null,e.jsx("span",{className:"truncate",children:t.model||a("sessions.model.unknown")}),e.jsx("span",{"aria-hidden":!0,children:"·"}),e.jsx("span",{className:"tabular-nums",children:Me(t.started_at,s)}),S?e.jsxs(e.Fragment,{children:[e.jsx("span",{"aria-hidden":!0,children:"·"}),e.jsx("span",{className:"tabular-nums",children:S})]}):null]})]})]}),e.jsxs("div",{className:"flex items-start gap-5 pl-[30px] sm:pl-0",children:[e.jsxs("dl",{className:"flex items-start gap-6 text-right",children:[e.jsxs("div",{className:"flex w-16 flex-col-reverse",children:[e.jsx("dt",{className:"text-[11px] text-oai-gray-400 dark:text-oai-gray-500",children:a("sessions.col.tokens")}),e.jsx("dd",{className:"tabular-nums text-sm font-medium text-oai-black dark:text-white",children:$(t.total_tokens)})]}),e.jsxs("div",{className:"flex w-16 flex-col-reverse",children:[e.jsx("dt",{className:"text-[11px] text-oai-gray-400 dark:text-oai-gray-500",children:a("sessions.col.cost")}),e.jsx("dd",{className:"tabular-nums text-sm font-medium text-oai-black dark:text-white",children:te(t.cost_usd,{currency:d,rate:h})})]}),e.jsxs("div",{className:"hidden w-10 flex-col-reverse sm:flex",children:[e.jsx("dt",{className:"text-[11px] text-oai-gray-400 dark:text-oai-gray-500",children:a("sessions.col.turns")}),e.jsx("dd",{className:"tabular-nums text-sm font-medium text-oai-black dark:text-white",children:$(t.turns)})]}),e.jsxs("div",{className:"hidden w-10 flex-col-reverse sm:flex",children:[e.jsx("dt",{className:"text-[11px] text-oai-gray-400 dark:text-oai-gray-500",children:a("sessions.col.edits")}),e.jsx("dd",{className:"tabular-nums text-sm font-medium text-oai-black dark:text-white",children:$(t.edit_turns)})]})]}),e.jsxs("button",{type:"button",onClick:c,disabled:!u,title:u||a("sessions.resume.unavailable"),"aria-label":u?a("sessions.resume.copy_aria",{command:u}):a("sessions.resume.unavailable"),className:E("-mt-0.5 inline-flex h-8 shrink-0 items-center gap-1.5 rounded-md px-2.5 text-xs font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand-500",u?"text-oai-gray-500 hover:bg-oai-gray-100 hover:text-oai-black dark:text-oai-gray-400 dark:hover:bg-oai-gray-800 dark:hover:text-white":"cursor-not-allowed text-oai-gray-300 dark:text-oai-gray-600"),children:[e.jsx(pe,{className:"h-3.5 w-3.5","aria-hidden":!0}),e.jsx("span",{className:"hidden sm:inline",children:a("sessions.resume.copy")})]})]})]})});function Je(){const[r,t]=o.useState(null),[s,d]=o.useState(null),[h,k]=o.useState(!0),[S,u]=o.useState(!1),[x,T]=o.useState("all"),[p,D]=o.useState("all"),[g,w]=o.useState("all"),[c,m]=o.useState(""),[F,C]=o.useState(A),I=o.useRef(0),{resolvedLocale:N}=W(),v=o.useCallback(async(i=!1)=>{const b=++I.current;i?u(!0):k(!0),d(null);try{const l=await Ne({refresh:i});b===I.current&&t(l)}catch(l){b===I.current&&d(l?.message||String(l))}finally{b===I.current&&(k(!1),u(!1))}},[]);o.useEffect(()=>{G||H()?v(!1):k(!1)},[v]);const y=r?.sessions||_e,O=o.useMemo(()=>{const i=new Set,b=[];for(const l of y){const j=l.project_key;!j||i.has(j)||(i.add(j),b.push({value:j,label:j}))}return b.sort((l,j)=>l.label.localeCompare(j.label))},[y]),P=o.useDeferredValue(c),L=o.useMemo(()=>{const i=P.trim().toLowerCase(),b=Ce(p);return y.filter(l=>x!=="all"&&l.source!==x||g!=="all"&&l.project_key!==g||!Le(l,b)?!1:i?`${l.title||""} ${l.project_key||""} ${l.model||""} ${l.project_ref||""} ${l.session_id||""}`.toLowerCase().includes(i):!0)},[y,x,g,p,P]),n=x!=="all"||p!=="all"||g!=="all"||c.trim()!=="";o.useEffect(()=>{C(A)},[x,g,p,P,y]);const f=o.useMemo(()=>L.slice(0,F),[L,F]),_=L.length>f.length,M=o.useCallback(()=>C(i=>i+A),[]),q=o.useRef(null);o.useEffect(()=>{if(!_||typeof IntersectionObserver>"u")return;const i=q.current;if(!i)return;const b=new IntersectionObserver(l=>{l.some(j=>j.isIntersecting)&&M()},{rootMargin:"400px"});return b.observe(i),()=>b.disconnect()},[_,M]);const B=o.useMemo(()=>Se.map(i=>({id:i.id,label:i.label()})),[N]),J=o.useMemo(()=>Z.map(i=>({id:i.id,label:i.label()})),[N]),V=Number(r?.session_count)>Number(r?.returned_count);return!G&&!H()?e.jsx("div",{className:"flex flex-col flex-1 text-oai-black dark:text-oai-white font-oai antialiased",children:e.jsx(ae,{})}):e.jsx("div",{className:"flex flex-col flex-1 text-oai-black dark:text-oai-white font-oai antialiased",children:e.jsx("main",{className:"flex-1 pt-8 sm:pt-10 pb-12 sm:pb-16",children:e.jsxs("div",{className:"mx-auto max-w-6xl px-4 sm:px-6",children:[e.jsxs("div",{className:"mb-8 flex flex-row items-start justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("h1",{className:"mb-3 text-3xl font-semibold tracking-tight text-oai-black dark:text-white sm:text-4xl",children:a("nav.sessions")}),e.jsx("p",{className:"text-sm text-oai-gray-500 dark:text-oai-gray-400 sm:text-base",children:a("sessions.page.subtitle")})]}),e.jsx("button",{type:"button",onClick:()=>{v(!0)},disabled:S||h,"aria-label":a("sessions.page.refresh"),title:a("sessions.page.refresh"),className:"inline-flex h-9 w-9 shrink-0 items-center justify-center rounded-lg border border-oai-gray-200 text-oai-gray-600 transition-colors hover:bg-oai-gray-100 hover:text-oai-black focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand-500 disabled:opacity-50 dark:border-oai-gray-800 dark:text-oai-gray-400 dark:hover:bg-oai-gray-800 dark:hover:text-white",children:e.jsx(X,{className:E("h-4 w-4",S&&"animate-spin"),"aria-hidden":!0})})]}),e.jsxs("div",{className:"mb-2 flex flex-wrap items-center gap-2 pt-1 text-xs text-oai-gray-600 dark:text-oai-gray-300",children:[e.jsx(U,{ariaLabel:a("sessions.filter.source_aria"),options:B,value:x,onChange:T}),e.jsx(U,{className:"pl-2",ariaLabel:a("sessions.filter.range_aria"),leading:e.jsx(ye,{className:"h-3.5 w-3.5 shrink-0 text-oai-gray-400","aria-hidden":!0}),options:J,value:p,onChange:D}),e.jsx(je,{options:O,value:g,onChange:w,allLabel:a("sessions.filter.project_all"),searchPlaceholder:a("sessions.filter.project_search"),emptyLabel:a("sessions.filter.project_empty"),ariaLabel:a("sessions.filter.project_aria")}),e.jsxs("div",{className:"relative w-72 max-w-full",children:[e.jsx(z,{className:"pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-oai-gray-400","aria-hidden":!0}),e.jsx(re,{type:"search",value:c,onChange:i=>m(i.target.value),onKeyDown:i=>{i.key==="Escape"&&c&&(i.preventDefault(),m(""))},"aria-label":a("sessions.action.search_aria"),placeholder:a("sessions.search.placeholder"),className:"h-8 pl-9 pr-8 !border-oai-gray-200 dark:!border-oai-gray-800 focus:!border-oai-gray-400 focus:!ring-oai-gray-400/20 dark:focus:!border-oai-gray-500 dark:focus:!ring-oai-gray-500/20 [&::-webkit-search-cancel-button]:appearance-none"}),e.jsx("button",{type:"button",onMouseDown:i=>i.preventDefault(),onClick:()=>m(""),"aria-label":a("sessions.action.search_clear"),"aria-hidden":!c,tabIndex:c?0:-1,className:E("absolute right-2 top-1/2 flex h-6 w-6 -translate-y-1/2 items-center justify-center rounded-full text-oai-gray-400 transition duration-150 ease-out hover:bg-oai-gray-100 hover:text-oai-gray-600 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-gray-400/40 dark:hover:bg-oai-gray-800 dark:hover:text-oai-gray-200",c?"scale-100 opacity-100":"pointer-events-none scale-90 opacity-0"),children:e.jsx(Y,{className:"h-3.5 w-3.5","aria-hidden":!0})})]}),e.jsx("span",{className:"ml-auto shrink-0 tabular-nums text-oai-gray-500 dark:text-oai-gray-400",children:a("sessions.filter.result_count",{filtered:L.length,total:y.length})})]}),V?e.jsx("p",{className:"mb-4 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:a("sessions.truncated",{shown:r.returned_count,total:r.session_count})}):null,s&&!r?e.jsxs("div",{className:"rounded-xl border border-dashed border-red-300 py-16 text-center dark:border-red-500/40",children:[e.jsx("p",{className:"text-sm font-medium text-oai-black dark:text-white",children:a("sessions.error.title")}),e.jsx("p",{className:"mt-1 text-sm text-oai-gray-500 dark:text-oai-gray-400",children:s}),e.jsx("button",{type:"button",onClick:()=>{v(!1)},className:"mt-4 inline-flex h-8 items-center rounded-md border border-oai-gray-200 px-3 text-xs font-medium text-oai-gray-700 transition-colors hover:bg-oai-gray-100 hover:text-oai-black focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand-500 dark:border-oai-gray-800 dark:text-oai-gray-200 dark:hover:bg-oai-gray-800 dark:hover:text-white",children:a("sessions.error.retry")})]}):h?e.jsxs("div",{className:"flex items-center gap-2 py-16 text-sm text-oai-gray-500 dark:text-oai-gray-400",children:[e.jsx(fe,{className:"h-4 w-4 animate-spin","aria-hidden":!0}),a("sessions.loading")]}):L.length===0?e.jsxs("div",{className:"rounded-xl border border-dashed border-oai-gray-200 py-16 text-center dark:border-oai-gray-800",children:[e.jsx("p",{className:"text-sm font-medium text-oai-black dark:text-white",children:n?a("sessions.empty.filtered_title"):a("sessions.empty.title")}),e.jsx("p",{className:"mt-1 text-sm text-oai-gray-500 dark:text-oai-gray-400",children:n?a("sessions.empty.filtered_body"):a("sessions.empty.body")})]}):e.jsxs(e.Fragment,{children:[s?e.jsx("p",{className:"mb-4 text-sm text-red-500 dark:text-red-400",children:a("shared.error.prefix",{error:s})}):null,e.jsx("ul",{className:"divide-y divide-oai-gray-200/70 dark:divide-oai-gray-800/70",children:f.map(i=>e.jsx(Ie,{session:i,locale:N},i.session_hash))}),_?e.jsx("div",{ref:q,className:"flex justify-center pt-6",children:e.jsx("button",{type:"button",onClick:M,className:"inline-flex h-8 items-center rounded-md border border-oai-gray-200 px-3 text-xs font-medium text-oai-gray-600 transition-colors hover:bg-oai-gray-100 hover:text-oai-black focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand-500 dark:border-oai-gray-800 dark:text-oai-gray-300 dark:hover:bg-oai-gray-800 dark:hover:text-white",children:a("sessions.action.load_more")})}):null]}),e.jsx("p",{className:"mt-6 text-xs text-oai-gray-400 dark:text-oai-gray-500",children:a("sessions.privacy")})]})})})}export{Je as SessionsPage};
|