tokentracker-cli 1.3.8 → 1.3.10
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 +7 -6
- package/README.ja.md +6 -5
- package/README.ko.md +6 -5
- package/README.md +7 -6
- package/README.zh-CN.md +6 -5
- package/dashboard/dist/assets/{AchievementBadge-BqLeP5y3.js → AchievementBadge-vU4Dwu_p.js} +1 -1
- package/dashboard/dist/assets/{AchievementsPage-BwVkM45R.js → AchievementsPage-C8LspyPK.js} +2 -2
- package/dashboard/dist/assets/{AchievementsSection-CglgOcQ1.js → AchievementsSection-CP8J07fV.js} +1 -1
- package/dashboard/dist/assets/{BadgeDetailModal-IurF0cmo.js → BadgeDetailModal-Ci1egHvR.js} +1 -1
- package/dashboard/dist/assets/{BotAnimated-C4_NxPuy.js → BotAnimated-CMXILM_h.js} +1 -1
- package/dashboard/dist/assets/{Card-C-UuIN42.js → Card-BHHCCnqR.js} +1 -1
- package/dashboard/dist/assets/{CloudCheckoutPage-CrMDquLi.js → CloudCheckoutPage-BY9Hsbix.js} +1 -1
- package/dashboard/dist/assets/{CloudPage-D6xTPnMs.js → CloudPage-Y6JgOXcJ.js} +2 -2
- package/dashboard/dist/assets/{CommandPalette-8LFLY-LQ.js → CommandPalette-BRWQFJwy.js} +1 -1
- package/dashboard/dist/assets/CommunityStatsModal-krT4ZZX9.js +1 -0
- package/dashboard/dist/assets/{ConfirmModal-St89kP59.js → ConfirmModal-ZvPOJ0he.js} +1 -1
- package/dashboard/dist/assets/Controls-CQlxw03i.js +1 -0
- package/dashboard/dist/assets/{DashboardPage-BvGqFvP7.js → DashboardPage-Dbi0d2JY.js} +1 -1
- package/dashboard/dist/assets/{DateRangePopover-Cbd1idiF.js → DateRangePopover-DJ8RpQfV.js} +1 -1
- package/dashboard/dist/assets/DevicePage-C4_cbw3M.js +1 -0
- package/dashboard/dist/assets/{DialogClose-Cb1-Hd8P.js → DialogClose-Dx5AqmUG.js} +1 -1
- package/dashboard/dist/assets/DialogDescription-LvhfT1Ox.js +1 -0
- package/dashboard/dist/assets/{DialogTitle-VXrHY7H0.js → DialogTitle-Cro2S8s8.js} +1 -1
- package/dashboard/dist/assets/{ElectricLogo-DmQqYnSD.js → ElectricLogo-gqnBCtSG.js} +1 -1
- package/dashboard/dist/assets/{FadeIn-BEieTXMD.js → FadeIn-B9oATcDZ.js} +1 -1
- package/dashboard/dist/assets/{HeaderGithubStar-BlYC_PSb.js → HeaderGithubStar-CYa94wna.js} +1 -1
- package/dashboard/dist/assets/{HoverTooltip-C5Pe7iBz.js → HoverTooltip-BJ4qLyuS.js} +1 -1
- package/dashboard/dist/assets/{IpCheckPage-Diln3EdG.js → IpCheckPage-Clpq3jdY.js} +1 -1
- package/dashboard/dist/assets/{LandingPage-BzGYuAO7.js → LandingPage-CuazuOAo.js} +2 -2
- package/dashboard/dist/assets/{LeaderboardPage-Bn-ehU5S.js → LeaderboardPage-BSF1Lbtq.js} +2 -2
- package/dashboard/dist/assets/{LeaderboardProBadge-SovdGwYs.js → LeaderboardProBadge-K32gY52s.js} +1 -1
- package/dashboard/dist/assets/{LeaderboardProfileModal-BhxmTcHh.js → LeaderboardProfileModal-D5gpn7pP.js} +3 -3
- package/dashboard/dist/assets/{LeaderboardProfilePage-3iAYvoTb.js → LeaderboardProfilePage-BmO9nIi-.js} +1 -1
- package/dashboard/dist/assets/{LimitsPage-DHxFAdqK.js → LimitsPage-D9ZJ1TeK.js} +1 -1
- package/dashboard/dist/assets/{LocalOnlyNotice-HlGfiiI3.js → LocalOnlyNotice-BkzysTS7.js} +1 -1
- package/dashboard/dist/assets/{LoginCard-CamUYmiF.js → LoginCard-Do3SNJFU.js} +1 -1
- package/dashboard/dist/assets/{LoginModal-CcmYUJ45.js → LoginModal-hph1i_YK.js} +1 -1
- package/dashboard/dist/assets/{LoginPage-DMNNmZwr.js → LoginPage-DXYAaFjJ.js} +1 -1
- package/dashboard/dist/assets/{PetPage-D6xFX8QA.js → PetPage-D1Pk4OKI.js} +2 -2
- package/dashboard/dist/assets/{PopoverPopup-CKKgItAT.js → PopoverPopup-CAIuP_a5.js} +1 -1
- package/dashboard/dist/assets/{ProviderIcon-B-uS3pJ3.js → ProviderIcon-R6Bsj81X.js} +1 -1
- package/dashboard/dist/assets/{ResetPasswordPage-DX4RJjX0.js → ResetPasswordPage-BR3GTF-3.js} +1 -1
- package/dashboard/dist/assets/{Select-Dcg7FYAt.js → Select-38Dh-OWv.js} +1 -1
- package/dashboard/dist/assets/{SelectItemText-4vuj6xMs.js → SelectItemText-90n7jKbI.js} +1 -1
- package/dashboard/dist/assets/{SelfHostPage-ButVBgE7.js → SelfHostPage-BKVYkHI6.js} +1 -1
- package/dashboard/dist/assets/{ServiceStatusPage-DJDDO6lV.js → ServiceStatusPage-PBmBn29J.js} +1 -1
- package/dashboard/dist/assets/{SessionsPage-CiUirFMD.js → SessionsPage-58MfDHhe.js} +3 -3
- package/dashboard/dist/assets/SettingsPage-BNLHbZUQ.js +5 -0
- package/dashboard/dist/assets/{SkillsPage-D2tfFFY8.js → SkillsPage-DMMTk4jD.js} +1 -1
- package/dashboard/dist/assets/{TokenGalaxy-TQ-eWK8P.js → TokenGalaxy-BdPETjru.js} +1 -1
- package/dashboard/dist/assets/{TooltipPopup-BhSCJqFR.js → TooltipPopup-BXl-vM4L.js} +1 -1
- package/dashboard/dist/assets/{TrendMonitor-CP6ZZ53c.js → TrendMonitor-wPfTlX-7.js} +1 -1
- package/dashboard/dist/assets/{WidgetsPage-BdeR7P8D.js → WidgetsPage-CuwRMWka.js} +1 -1
- package/dashboard/dist/assets/{WrappedPage-OqcqupRE.js → WrappedPage-DOpA9kkg.js} +1 -1
- package/dashboard/dist/assets/{__vite-browser-external-BXwSXUpN.js → __vite-browser-external-Go6WKt6Z.js} +3 -3
- package/dashboard/dist/assets/__vite-browser-external-kAUz3kFs.css +1 -0
- package/dashboard/dist/assets/{agent-logos-E6GfkcgD.js → agent-logos-D7eMvAlk.js} +1 -1
- package/dashboard/dist/assets/{arrow-left-D_ufthLH.js → arrow-left--eOVP_Dk.js} +1 -1
- package/dashboard/dist/assets/{arrow-right-CgV_OrFz.js → arrow-right-DJYhwBMz.js} +1 -1
- package/dashboard/dist/assets/{arrow-up-right-CzeEeXRz.js → arrow-up-right-DhDvpd-S.js} +1 -1
- package/dashboard/dist/assets/{calendar-days-BQdTF7ec.js → calendar-days-BuOFlNcJ.js} +1 -1
- package/dashboard/dist/assets/{check-C--D8Lze.js → check-UztXSVYi.js} +1 -1
- package/dashboard/dist/assets/{chevron-down-BzkceD4z.js → chevron-down-CbJ2QGDU.js} +1 -1
- package/dashboard/dist/assets/{cloud-checkout-m1Yllbij.js → cloud-checkout-CoRQjKEu.js} +1 -1
- package/dashboard/dist/assets/{composite-7DhFi6TA.js → composite-PlKvZfdM.js} +1 -1
- package/dashboard/dist/assets/{download-BSyGLtfW.js → download-McE9gFto.js} +1 -1
- package/dashboard/dist/assets/{external-link-KzFbueBT.js → external-link-DZWnR9gS.js} +1 -1
- package/dashboard/dist/assets/{flame-DlPM_oaj.js → flame-0xjueXt4.js} +1 -1
- package/dashboard/dist/assets/{format-tokens-BHBaWyA3.js → format-tokens-CZoG68uJ.js} +1 -1
- package/dashboard/dist/assets/{gift-BhWBQnun.js → gift-pKc80Nqb.js} +1 -1
- package/dashboard/dist/assets/{host-mode--iIPGrkN.js → host-mode-99_v1j5J.js} +1 -1
- package/dashboard/dist/assets/{icons-COEaSBYi.js → icons-BtfYKSGC.js} +1 -1
- package/dashboard/dist/assets/{index-Cf4HcmLp.js → index-Cgthm7BO.js} +1 -1
- package/dashboard/dist/assets/{index-Bo8CSxCq.js → index-CyZxN1O0.js} +1 -1
- package/dashboard/dist/assets/{index-CW6A_Ff_.js → index-DuaQmNZo.js} +1 -1
- package/dashboard/dist/assets/{info-D1gOdsM_.js → info-C8vkxwsO.js} +1 -1
- package/dashboard/dist/assets/{link-2-CXDnDOK4.js → link-2-CQzIW5b6.js} +1 -1
- package/dashboard/dist/assets/{loader-circle-DWeQPecG.js → loader-circle-B9GqzQyC.js} +1 -1
- package/dashboard/dist/assets/{modifiers.esm-BljqMT7V.js → modifiers.esm-ChkCUrZp.js} +1 -1
- package/dashboard/dist/assets/{monitor-smartphone-DpkdtOjk.js → monitor-smartphone-DQjBY1W3.js} +1 -1
- package/dashboard/dist/assets/{play-BlGNrekI.js → play-qC6xc6fe.js} +1 -1
- package/dashboard/dist/assets/{plus-CpYVQ_t-.js → plus-CoNHx5Og.js} +1 -1
- package/dashboard/dist/assets/{provider-display-D6Blvktj.js → provider-display-x2EG6zAY.js} +1 -1
- package/dashboard/dist/assets/{react-BMJ2wuz1.js → react-EctmAw3f.js} +1 -1
- package/dashboard/dist/assets/{safePolygon-BFHXICk1.js → safePolygon-DlSbLtZC.js} +1 -1
- package/dashboard/dist/assets/{search-0NxXkytY.js → search-CBcpAj9I.js} +1 -1
- package/dashboard/dist/assets/{server-GHkrUKSI.js → server-DtMUoEq0.js} +1 -1
- package/dashboard/dist/assets/{shield-check-C16cbx1z.js → shield-check-ByUPtUmu.js} +1 -1
- package/dashboard/dist/assets/{skills-api-DAm1fFB4.js → skills-api-BD9VNRej.js} +1 -1
- package/dashboard/dist/assets/{sortable.esm-CkOax8h0.js → sortable.esm-B6qEViGJ.js} +1 -1
- package/dashboard/dist/assets/{store-DR444-5P.js → store-BgW2uBRe.js} +1 -1
- package/dashboard/dist/assets/{terminal-BpvNaIz9.js → terminal-DWPNkr2L.js} +1 -1
- package/dashboard/dist/assets/{trash-DX8LwOmN.js → trash-DdbRpgD1.js} +1 -1
- package/dashboard/dist/assets/{use-community-stats-BFW4-DYG.js → use-community-stats-43ySv9uM.js} +1 -1
- package/dashboard/dist/assets/{use-latest-request-guard-Cpcl08EJ.js → use-latest-request-guard-BuezAv4k.js} +1 -1
- package/dashboard/dist/assets/{use-limits-display-prefs-BqixyeAa.js → use-limits-display-prefs-Yi0Hznar.js} +1 -1
- package/dashboard/dist/assets/{use-native-settings-BSx7lGEK.js → use-native-settings-BaSrhrM8.js} +1 -1
- package/dashboard/dist/assets/{use-ordered-list-UCjB0_zK.js → use-ordered-list-CBD-EIBf.js} +1 -1
- package/dashboard/dist/assets/use-reduced-motion-ObUuoXUE.js +1 -0
- package/dashboard/dist/assets/{use-session-efficiency-pref-BgOJaGEy.js → use-session-efficiency-pref-CwaFIkE5.js} +1 -1
- package/dashboard/dist/assets/{use-transform-Y98QifnQ.js → use-transform-Dea4uz8K.js} +1 -1
- package/dashboard/dist/assets/{use-usage-limits-DJGO-Kxv.js → use-usage-limits-DxkYcUIR.js} +1 -1
- package/dashboard/dist/assets/{useCurrency-DL458pqS.js → useCurrency-CcZktkbA.js} +1 -1
- package/dashboard/dist/assets/{usePositioner-DnCQwlVT.js → usePositioner-BLGIGihf.js} +1 -1
- package/dashboard/dist/assets/{useTokenFormat-CYLt9pgs.js → useTokenFormat--dhm3nNf.js} +1 -1
- package/dashboard/dist/assets/{zap-BW6E_Jv3.js → zap-CWTmP6Zw.js} +1 -1
- package/dashboard/dist/index.html +14 -12
- package/dashboard/dist/ip-check.html +2 -2
- package/dashboard/dist/leaderboard.html +2 -2
- package/dashboard/dist/llms.txt +3 -2
- package/dashboard/dist/share.html +2 -2
- package/package.json +2 -2
- package/src/commands/init.js +9 -0
- package/src/commands/status.js +11 -0
- package/src/commands/sync.js +197 -122
- package/src/lib/dumate.js +95 -0
- package/src/lib/pricing/seed-snapshot.json +1 -1
- package/src/lib/qoder-cn-cli-limits.js +117 -0
- package/src/lib/qoder-limits.js +24 -11
- package/src/lib/rollout.js +12 -9
- package/src/lib/session-analytics.js +210 -19
- package/src/lib/upload-queue.js +134 -0
- package/dashboard/dist/assets/CommunityStatsModal-DYTjxABN.js +0 -1
- package/dashboard/dist/assets/Controls-BJAwM2gB.js +0 -1
- package/dashboard/dist/assets/DevicePage-BcSU0xgf.js +0 -1
- package/dashboard/dist/assets/DialogDescription-DQvYzWMp.js +0 -1
- package/dashboard/dist/assets/SettingsPage-CB4CML8u.js +0 -5
- package/dashboard/dist/assets/__vite-browser-external-DvNSoTb8.css +0 -1
- package/dashboard/dist/assets/use-reduced-motion-C6zOHbfR.js +0 -1
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
const fs = require("node:fs/promises");
|
|
2
|
+
const crypto = require("node:crypto");
|
|
3
|
+
const { isUtf8 } = require("node:buffer");
|
|
4
|
+
|
|
5
|
+
const BACKLOG_BYTES = 1_000_000;
|
|
6
|
+
const CHUNK_BYTES = 64 * 1024;
|
|
7
|
+
const { TOKEN_COLUMNS } = require("./account-usage-dedup");
|
|
8
|
+
|
|
9
|
+
function sessionSnapshotMs(row) {
|
|
10
|
+
const verifiedMs = Date.parse(row?.snapshot_verified_at);
|
|
11
|
+
if (typeof row?.source !== "string" || row.source.trim().toLowerCase() !== "trae-cn" ||
|
|
12
|
+
typeof row.session_id !== "string" || !row.session_id.trim() || row.session_id.trim().length > 256 ||
|
|
13
|
+
typeof row.model !== "string" || !row.model.trim() || row.model.trim().length > 200 ||
|
|
14
|
+
!Number.isFinite(Date.parse(row.bucket_start)) || !Number.isFinite(verifiedMs) ||
|
|
15
|
+
TOKEN_COLUMNS.some((column) => !Number.isSafeInteger(Number(row[column])) || Number(row[column]) < 0) ||
|
|
16
|
+
Number(row.total_tokens) !== Number(row.input_tokens) + Number(row.output_tokens) + Number(row.cached_input_tokens) + Number(row.cache_creation_input_tokens)) return null;
|
|
17
|
+
return verifiedMs;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// Keep raw bytes, including CRLF and incomplete tails. Upload offsets are
|
|
21
|
+
// byte positions, not JavaScript string lengths.
|
|
22
|
+
async function* iterateQueueLines(handle, start, end) {
|
|
23
|
+
let position = start;
|
|
24
|
+
let lineStart = start;
|
|
25
|
+
let carry = Buffer.alloc(0);
|
|
26
|
+
while (position < end) {
|
|
27
|
+
const chunk = Buffer.allocUnsafe(Math.min(CHUNK_BYTES, end - position));
|
|
28
|
+
const { bytesRead } = await handle.read(chunk, 0, chunk.length, position);
|
|
29
|
+
if (!bytesRead) throw new Error("Queue changed while reading");
|
|
30
|
+
position += bytesRead;
|
|
31
|
+
const data = carry.length ? Buffer.concat([carry, chunk.subarray(0, bytesRead)]) : chunk.subarray(0, bytesRead);
|
|
32
|
+
let consumed = 0;
|
|
33
|
+
let newline;
|
|
34
|
+
while ((newline = data.indexOf(10, consumed)) !== -1) {
|
|
35
|
+
const bytes = data.subarray(consumed, newline + 1);
|
|
36
|
+
yield { bytes, start: lineStart, complete: true };
|
|
37
|
+
lineStart += bytes.length;
|
|
38
|
+
consumed = newline + 1;
|
|
39
|
+
}
|
|
40
|
+
carry = Buffer.from(data.subarray(consumed));
|
|
41
|
+
}
|
|
42
|
+
if (carry.length) yield { bytes: carry, start: lineStart, complete: false };
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function snapshotKey(bytes) {
|
|
46
|
+
if (!isUtf8(bytes)) return null;
|
|
47
|
+
let row;
|
|
48
|
+
try { row = JSON.parse(bytes.toString("utf8")); } catch { return null; }
|
|
49
|
+
if (!row || typeof row !== "object" || Array.isArray(row)) return null;
|
|
50
|
+
if (row.kind === "account_session_state") {
|
|
51
|
+
const verifiedMs = sessionSnapshotMs(row);
|
|
52
|
+
if (verifiedMs === null) return null;
|
|
53
|
+
return { key: JSON.stringify(["session", row.source.trim().toLowerCase(), row.session_id.trim()]), verifiedMs };
|
|
54
|
+
}
|
|
55
|
+
// Preserve unknown control records even when they happen to carry a bucket.
|
|
56
|
+
if (Object.hasOwn(row, "kind") || typeof row.hour_start !== "string" || !Number.isFinite(Date.parse(row.hour_start))) return null;
|
|
57
|
+
const source = (typeof row.source === "string" ? row.source.trim().toLowerCase() : "") || "codex";
|
|
58
|
+
const model = (typeof row.model === "string" ? row.model.trim() : "") || "unknown";
|
|
59
|
+
return { key: JSON.stringify(["hourly", source, model, row.hour_start]), verifiedMs: null };
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Caller holds sync.lock. Only rewrite pending snapshots; uploaded history and
|
|
63
|
+
// queue.state.json stay byte-for-byte unchanged across an atomic replacement.
|
|
64
|
+
async function compactPendingQueue({ queuePath, offset = 0, minPendingBytes = BACKLOG_BYTES }) {
|
|
65
|
+
let input;
|
|
66
|
+
let output;
|
|
67
|
+
let temporary;
|
|
68
|
+
try {
|
|
69
|
+
input = await fs.open(queuePath, "r");
|
|
70
|
+
const before = await input.stat();
|
|
71
|
+
const pendingBytesBefore = Math.max(0, before.size - offset);
|
|
72
|
+
const unchanged = { compacted: false, removedRecords: 0, pendingBytesBefore, pendingBytesAfter: pendingBytesBefore };
|
|
73
|
+
if (!before.isFile() || !Number.isSafeInteger(offset) || offset < 0 || offset >= before.size || pendingBytesBefore < minPendingBytes) return unchanged;
|
|
74
|
+
if (offset > 0) {
|
|
75
|
+
const boundary = Buffer.alloc(1);
|
|
76
|
+
await input.read(boundary, 0, 1, offset - 1);
|
|
77
|
+
if (boundary[0] !== 10) return unchanged;
|
|
78
|
+
}
|
|
79
|
+
const latest = new Map();
|
|
80
|
+
let removedRecords = 0;
|
|
81
|
+
for await (const line of iterateQueueLines(input, offset, before.size)) {
|
|
82
|
+
const snapshot = line.complete ? snapshotKey(line.bytes) : null;
|
|
83
|
+
if (snapshot == null) continue;
|
|
84
|
+
const previous = latest.get(snapshot.key);
|
|
85
|
+
if (previous) removedRecords += 1;
|
|
86
|
+
// Account truth uses a strictly newer fetch stamp; equal stamps retain
|
|
87
|
+
// the first observation, even after a replay or local clock rollback.
|
|
88
|
+
if (!previous || snapshot.verifiedMs === null || snapshot.verifiedMs > previous.verifiedMs) {
|
|
89
|
+
latest.set(snapshot.key, { start: line.start, verifiedMs: snapshot.verifiedMs });
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if (!removedRecords) return unchanged;
|
|
93
|
+
|
|
94
|
+
temporary = `${queuePath}.compact.${crypto.randomUUID()}`;
|
|
95
|
+
output = await fs.open(temporary, "wx", before.mode & 0o777);
|
|
96
|
+
await output.chmod(before.mode & 0o777);
|
|
97
|
+
for (let position = 0; position < offset;) {
|
|
98
|
+
const chunk = Buffer.allocUnsafe(Math.min(CHUNK_BYTES, offset - position));
|
|
99
|
+
const { bytesRead } = await input.read(chunk, 0, chunk.length, position);
|
|
100
|
+
if (!bytesRead) throw new Error("Queue changed while copying uploaded history");
|
|
101
|
+
await output.writeFile(chunk.subarray(0, bytesRead));
|
|
102
|
+
position += bytesRead;
|
|
103
|
+
}
|
|
104
|
+
let pendingBytesAfter = 0;
|
|
105
|
+
for await (const line of iterateQueueLines(input, offset, before.size)) {
|
|
106
|
+
const snapshot = line.complete ? snapshotKey(line.bytes) : null;
|
|
107
|
+
if (snapshot != null && latest.get(snapshot.key).start !== line.start) continue;
|
|
108
|
+
await output.writeFile(line.bytes);
|
|
109
|
+
pendingBytesAfter += line.bytes.length;
|
|
110
|
+
}
|
|
111
|
+
await output.sync();
|
|
112
|
+
await output.close();
|
|
113
|
+
output = null;
|
|
114
|
+
// Windows cannot replace the destination while our read handle is open.
|
|
115
|
+
await input.close();
|
|
116
|
+
input = null;
|
|
117
|
+
const current = await fs.stat(queuePath);
|
|
118
|
+
if (current.ino !== before.ino || current.size !== before.size || current.mtimeMs !== before.mtimeMs) {
|
|
119
|
+
throw new Error("Queue changed during pending compaction");
|
|
120
|
+
}
|
|
121
|
+
await fs.rename(temporary, queuePath);
|
|
122
|
+
temporary = null;
|
|
123
|
+
return { compacted: true, removedRecords, pendingBytesBefore, pendingBytesAfter };
|
|
124
|
+
} catch (error) {
|
|
125
|
+
if (error.code === "ENOENT" && !input) return { compacted: false, removedRecords: 0, pendingBytesBefore: 0, pendingBytesAfter: 0 };
|
|
126
|
+
throw error;
|
|
127
|
+
} finally {
|
|
128
|
+
await input?.close();
|
|
129
|
+
await output?.close();
|
|
130
|
+
if (temporary) await fs.unlink(temporary).catch(() => {});
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
module.exports = { BACKLOG_BYTES, compactPendingQueue, iterateQueueLines, sessionSnapshotMs };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{o as R,j as e,an as P,l as z,r as D,c as n,X as S,i as K}from"./__vite-browser-external-BXwSXUpN.js";import{m as M}from"./react-BMJ2wuz1.js";import{A as U,W as B}from"./icons-COEaSBYi.js";import{u as F}from"./useTokenFormat-CYLt9pgs.js";import{P as G}from"./ProviderIcon-B-uS3pJ3.js";import{T as W}from"./TrendMonitor-CP6ZZ53c.js";import{T as V}from"./AchievementBadge-BqLeP5y3.js";import{T as X}from"./terminal-BpvNaIz9.js";import{D as Y,a as Z,b as H,c as q,d as J,e as Q}from"./DialogTitle-VXrHY7H0.js";import{D as ee}from"./DialogDescription-DQvYzWMp.js";import{D as ae}from"./DialogClose-Cb1-Hd8P.js";import"./useCurrency-DL458pqS.js";import"./DateRangePopover-Cbd1idiF.js";import"./use-latest-request-guard-Cpcl08EJ.js";import"./PopoverPopup-CKKgItAT.js";import"./store-DR444-5P.js";import"./composite-7DhFi6TA.js";import"./SelectItemText-4vuj6xMs.js";import"./usePositioner-DnCQwlVT.js";import"./safePolygon-BFHXICk1.js";import"./use-reduced-motion-C6zOHbfR.js";import"./zap-BW6E_Jv3.js";import"./flame-DlPM_oaj.js";import"./calendar-days-BQdTF7ec.js";import"./shield-check-C16cbx1z.js";const C={name:"trending-down",size:24,node:[["path",{d:"M16 17h6v-6",key:"t6n2it"}],["path",{d:"m22 17-8.5-8.5-5 5L2 7",key:"x473p"}]]};C.node;const te=R(C),O=10,_={input:"var(--community-token-input)",cache_read:"var(--community-token-cache-read)",cache_write:"var(--community-token-cache-write)",output:"var(--community-token-output)",reasoning:"var(--community-token-reasoning)"},re={CLAUDE:"var(--community-claude)",CODEX:"var(--community-codex)",GEMINI:"var(--community-gemini)",CURSOR:"var(--community-cursor)",OPENCODE:"var(--community-opencode)",HERMES:"var(--community-hermes)",KIMI:"var(--community-kimi)",MIMO:"var(--community-mimo)",COPILOT:"var(--community-copilot)",KIRO:"var(--community-kiro)",GROK:"var(--community-grok)",DEEPSEEK:"var(--community-deepseek)",ZCODE:"var(--community-zcode)",WORKBUDDY:"var(--community-workbuddy)",MINIMAX:"var(--community-minimax)",DROID:"var(--community-droid)"};function ie(t){return re[String(t||"").toUpperCase()]||"var(--community-muted)"}const se=[[/claude|fable|opus|sonnet|haiku/,"CLAUDE"],[/gpt|codex|o3|o4/,"CODEX"],[/gemini/,"GEMINI"],[/composer|cursor/,"CURSOR"],[/kimi/,"KIMI"],[/mimo/,"MIMO"],[/copilot/,"COPILOT"],[/kiro/,"KIRO"],[/grok/,"GROK"],[/deepseek/,"DEEPSEEK"],[/glm/,"ZCODE"],[/hy3/,"WORKBUDDY"],[/minimax/,"MINIMAX"]],g=["overview","providers","community","models"];function oe(t){const s=String(t||"").toLowerCase(),a=se.find(([i])=>i.test(s));return a?a[1]:""}function u(t){const s=Number(t);return Number.isFinite(s)?`${s.toFixed(1)}%`:"—"}function p(t){return K(Number(t)||0)}function ne(t){return t?new Date(`${t}T00:00:00Z`).toLocaleDateString(void 0,{month:"short",day:"numeric",timeZone:"UTC"}):""}function k(){return e.jsx("div",{className:"flex h-full min-h-40 items-center justify-center text-xs text-oai-gray-400",children:n("leaderboard.community.modal.no_data")})}function b({children:t,detail:s}){return e.jsxs("div",{className:"mb-3 flex items-baseline justify-between gap-4",children:[e.jsx("h3",{className:"text-xs font-medium uppercase tracking-wide text-oai-gray-500 dark:text-oai-gray-400",children:t}),s?e.jsx("span",{className:"text-xs text-oai-gray-400",children:s}):null]})}function I({value:t,label:s}){const a=Number(t);if(!Number.isFinite(a))return null;const i=Math.sign(a)!==-1,r=i?V:te;return e.jsxs("span",{className:`inline-flex items-center gap-1 text-xs font-medium tabular-nums ${i?"text-emerald-600 dark:text-emerald-400":"text-rose-600 dark:text-rose-400"}`,title:s,children:[e.jsx(r,{className:"size-3","aria-hidden":"true"}),i?"+":"",a.toFixed(1),"%"]})}function j({label:t,value:s,title:a,delta:i,deltaLabel:r}){return e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"truncate text-xs font-medium text-oai-gray-500 dark:text-oai-gray-400",children:t}),e.jsxs("div",{className:"mt-1 flex min-w-0 items-baseline gap-2",children:[e.jsx("span",{className:"truncate text-xl font-semibold leading-none tracking-tight text-oai-black tabular-nums dark:text-white",title:a,children:s}),e.jsx(I,{value:i,label:r})]})]})}function A({fillWidth:t,share:s,color:a="var(--oai-blue)",ariaLabel:i,dataAttrs:r,children:o}){return e.jsxs("div",{...r,className:"group relative grid min-h-11 grid-cols-[minmax(0,1fr)_auto] items-center gap-3 overflow-hidden px-2.5 transition-colors hover:bg-oai-gray-50 dark:hover:bg-oai-gray-900/60",children:[e.jsx("div",{className:"pointer-events-none absolute inset-y-0 left-0 opacity-[0.15] transition-opacity group-hover:opacity-[0.22] dark:opacity-[0.24] dark:group-hover:opacity-[0.32]",style:{width:`${t}%`,backgroundColor:a},role:"progressbar","aria-label":i,"aria-valuemin":"0","aria-valuemax":"100","aria-valuenow":Number(s)||0}),o]})}function T({rank:t,provider:s,name:a,fillWidth:i,share:r,tokens:o,tokensTitle:l,dataAttrs:c}){return e.jsxs(A,{fillWidth:i,share:r,color:ie(s),ariaLabel:`${a} ${u(r)}`,dataAttrs:c,children:[e.jsxs("div",{className:"relative flex min-w-0 items-center gap-2.5",children:[e.jsx("span",{className:`w-5 shrink-0 text-xs tabular-nums ${t<=3?"font-semibold text-oai-gray-700 dark:text-oai-gray-200":"text-oai-gray-400"}`,children:t}),e.jsx("span",{className:"grid size-6 shrink-0 place-items-center text-oai-gray-700 dark:text-oai-gray-200",children:e.jsx(G,{provider:s,size:15})}),e.jsx("span",{className:"truncate text-xs font-medium text-oai-gray-700 dark:text-oai-gray-200",title:a,children:a})]}),e.jsxs("div",{className:"relative min-w-[4.5rem] text-right",children:[e.jsx("div",{className:"text-xs font-semibold text-oai-black tabular-nums dark:text-white",title:l,children:o}),e.jsx("div",{className:"text-xs text-oai-gray-500 tabular-nums dark:text-oai-gray-400",children:u(r)})]})]})}function le({rows:t,formatTokensTooltip:s}){return t.length?e.jsxs("div",{className:"mt-7",children:[e.jsx(b,{children:n("leaderboard.community.modal.token_mix")}),e.jsx("div",{className:"flex h-1.5 overflow-hidden bg-oai-gray-100 dark:bg-oai-gray-800",children:t.map(a=>e.jsx("div",{style:{width:`${Math.max(Number(a.share)||0,0)}%`,backgroundColor:_[a.key]||"var(--community-muted)"},title:`${n(`leaderboard.community.modal.token_mix.${a.key}`)} · ${u(a.share)}`},a.key))}),e.jsx("div",{className:"mt-3 flex flex-wrap gap-x-5 gap-y-1.5",children:t.map(a=>e.jsxs("span",{className:"inline-flex items-center gap-1.5 text-xs text-oai-gray-500 dark:text-oai-gray-400",title:s(a.tokens),children:[e.jsx("span",{className:"size-2",style:{backgroundColor:_[a.key]||"var(--community-muted)"}}),n(`leaderboard.community.modal.token_mix.${a.key}`),e.jsx("span",{className:"tabular-nums text-oai-gray-700 dark:text-oai-gray-200",children:u(a.share)})]},a.key))})]}):null}function f({label:t,value:s,title:a,delta:i,deltaLabel:r,className:o=""}){return e.jsxs("div",{className:`min-w-0 ${o}`,children:[e.jsx("div",{className:"truncate text-xs text-oai-gray-500 dark:text-oai-gray-400",children:t}),e.jsxs("div",{className:"mt-1 flex min-w-0 items-baseline gap-2",children:[e.jsx("span",{className:"truncate text-base font-semibold leading-none tracking-tight tabular-nums text-oai-black dark:text-white",title:a,children:s}),e.jsx(I,{value:i,label:r})]})]})}function de({trendRows:t,activeDevelopers30d:s,developerGrowthPct:a,formatTokens:i,formatTokensTooltip:r}){if(!t.length)return null;const o=t.reduce((m,h)=>m+h.value,0),l=t.reduce((m,h)=>m.value<h.value?h:m,t[0]),c=o/t.length;return e.jsxs("div",{className:"mt-5 grid grid-cols-3 divide-x divide-oai-gray-100 border-y border-oai-gray-100 py-3.5 dark:divide-oai-gray-800/80 dark:border-oai-gray-800/80",children:[e.jsx(f,{className:"pr-4",label:n("leaderboard.community.modal.daily_average"),value:i(c),title:r(c)}),e.jsx(f,{className:"px-4",label:`${n("leaderboard.community.modal.peak_day")} · ${l.day}`,value:i(l.value),title:r(l.value)}),e.jsx(f,{className:"pl-4",label:n("leaderboard.community.modal.active_30d"),value:p(s),title:Number(s).toLocaleString(),delta:a,deltaLabel:n("leaderboard.community.modal.vs_previous_week")})]})}function me({trendRows:t,mix:s,activeDevelopers30d:a,developerGrowthPct:i,formatTokens:r,formatTokensTooltip:o}){return!t.length&&!s.length?e.jsx(k,{}):e.jsxs("div",{children:[e.jsx(b,{detail:n("leaderboard.community.modal.utc_note"),children:n("leaderboard.community.modal.community_activity")}),e.jsx(W,{embedded:!0,rows:t,from:t[0]?.day,to:t.at(-1)?.day,chartHeightClass:"h-44"}),e.jsx(de,{trendRows:t,activeDevelopers30d:a,developerGrowthPct:i,formatTokens:r,formatTokensTooltip:o}),e.jsx(le,{rows:s,formatTokensTooltip:o})]})}function ce({rows:t,maxShare:s,formatTokens:a,formatTokensTooltip:i}){return t.length?e.jsx("div",{className:"space-y-0.5",children:t.map((r,o)=>e.jsx(T,{rank:o+1,dataAttrs:{"data-provider-rank":o+1,"data-provider-name":r.name},provider:String(r.name).toUpperCase(),name:r.name,fillWidth:Math.max((Number(r.share)||0)/s*100,2),share:r.share,tokens:a(r.tokens),tokensTitle:i(r.tokens)},r.name))}):e.jsx(k,{})}function xe({rows:t,maxShare:s,formatTokens:a,formatTokensTooltip:i}){return t.length?e.jsx("div",{className:"space-y-0.5",children:t.map((r,o)=>{const l=Number(r.share)||0;return e.jsx(T,{rank:o+1,dataAttrs:{"data-model-rank":o+1,"data-model-name":r.name},provider:oe(r.name),name:r.name,fillWidth:Math.max(l/s*100,2),share:l,tokens:a(r.tokens),tokensTitle:i(r.tokens)},r.name)})}):e.jsx(k,{})}function ue({name:t}){const s=String(t||"").toLowerCase();return s==="darwin"?e.jsx(U,{className:"size-3.5"}):s==="win32"?e.jsx(B,{className:"size-3.5"}):e.jsx(X,{className:"size-4","aria-hidden":"true"})}const he=.175,ye=.3;function ge({bands:t,formatTokensTooltip:s}){const a=t.reduce((r,o)=>Math.max(r,Number(o.developer_share)||0),0)||1,i=r=>`${n(`leaderboard.community.modal.band.${r.key}`)} · ${n("leaderboard.community.modal.developer_count",{count:p(r.developers)})} (${s(r.tokens)})`;return e.jsxs("div",{children:[e.jsx("div",{className:"flex gap-2 border-b border-oai-gray-200 dark:border-oai-gray-800",children:t.map((r,o)=>{const l=Number(r.developer_share)||0,c=Math.max(l/a*80,2);return e.jsxs("div",{className:"relative h-32 min-w-0 flex-1",title:i(r),children:[e.jsx("div",{role:"progressbar","aria-label":n("leaderboard.community.modal.developer_share_title",{share:u(l)}),"aria-valuemin":"0","aria-valuemax":"100","aria-valuenow":l,className:"absolute inset-x-0 bottom-0",style:{height:`${c}%`,backgroundColor:"var(--oai-blue)",opacity:ye+o*he}}),e.jsx("div",{className:"absolute inset-x-0 text-center text-xs font-medium tabular-nums text-oai-gray-700 dark:text-oai-gray-200",style:{bottom:`calc(${c}% + 4px)`},children:u(l)})]},r.key)})}),e.jsx("div",{className:"mt-2 flex gap-2",children:t.map(r=>e.jsxs("div",{className:"min-w-0 flex-1 text-center",title:i(r),children:[e.jsx("div",{className:"truncate text-xs font-medium text-oai-gray-700 dark:text-oai-gray-200",children:n(`leaderboard.community.modal.band.${r.key}`)}),e.jsx("div",{className:"truncate text-xs tabular-nums text-oai-gray-500 dark:text-oai-gray-400",children:p(r.developers)})]},r.key))})]})}function pe({bands:t,platforms:s,formatTokensTooltip:a}){return!t.length&&!s.length?e.jsx(k,{}):e.jsxs("div",{className:"space-y-8",children:[t.length?e.jsxs("div",{children:[e.jsx(b,{children:n("leaderboard.community.modal.usage_distribution")}),e.jsx(ge,{bands:t,formatTokensTooltip:a})]}):null,s.length?e.jsxs("div",{children:[e.jsx(b,{children:n("leaderboard.community.modal.platforms")}),e.jsx("div",{className:"space-y-0.5",children:s.map(i=>e.jsxs(A,{fillWidth:Math.max(Number(i.share)||0,1),share:i.share,ariaLabel:`${n(`leaderboard.community.modal.platform.${i.name}`)} ${u(i.share)}`,children:[e.jsxs("div",{className:"relative flex min-w-0 items-center gap-2.5",children:[e.jsx("span",{className:"grid size-6 shrink-0 place-items-center text-oai-gray-700 dark:text-oai-gray-200",children:e.jsx(ue,{name:i.name})}),e.jsx("span",{className:"truncate text-xs font-medium text-oai-gray-700 dark:text-oai-gray-200",children:n(`leaderboard.community.modal.platform.${i.name}`)})]}),e.jsxs("div",{className:"relative min-w-[4.5rem] text-right",children:[e.jsx("div",{className:"text-xs font-semibold text-oai-black tabular-nums dark:text-white",children:u(i.share)}),e.jsx("div",{className:"text-xs text-oai-gray-500 tabular-nums dark:text-oai-gray-400",title:Number(i.machines||0).toLocaleString(),children:n("leaderboard.community.modal.machine_count",{count:p(i.machines)})})]})]},i.name))})]}):null]})}function ve({isOpen:t,onClose:s,communityStats:a}){const{formatTokens:i,formatTokensTooltip:r}=F(),[o,l]=D.useState("overview"),c=a?.status==="ready",m=D.useMemo(()=>{if(!c)return null;const d=(Array.isArray(a.providers)?a.providers:[]).slice(0,O),x=(Array.isArray(a.topModels)?a.topModels:[]).slice(0,O),y=v=>v.reduce(($,L)=>Math.max($,Number(L.share)||0),0)||1;return{providers:d,models:x,providersMaxShare:y(d),modelsMaxShare:y(x),trendRows:(Array.isArray(a.dailyGrowth)?a.dailyGrowth:[]).map(v=>({day:ne(v.day),value:Number(v.tokens)||0})),mix:Array.isArray(a.tokenMix)?a.tokenMix:[],bands:Array.isArray(a.userDistribution)?a.userDistribution:[],platforms:Array.isArray(a.platforms)?a.platforms:[]}},[c,a]);if(!m)return null;const h=Number(a.tokenFloor)||0,N=Number(a.activeDevelopersTotal)||Number(a.totalEntries)||0,w=Number(a.tokens30d)||0,E=d=>{if(d.key!=="ArrowRight"&&d.key!=="ArrowLeft")return;d.preventDefault();const x=d.key==="ArrowRight"?1:-1,y=g[(g.indexOf(o)+x+g.length)%g.length];l(y),d.currentTarget.querySelector(`[data-tab-id="${y}"]`)?.focus()};return e.jsx(Y,{open:t,onOpenChange:d=>!d&&s(),children:e.jsxs(Z,{children:[e.jsx(H,{className:"fixed inset-0 z-[100] bg-black/50 backdrop-blur-[3px] transition-opacity duration-200 ease-out data-[ending-style]:opacity-0 data-[starting-style]:opacity-0"}),e.jsx(q,{className:"fixed inset-0 z-[101] flex items-center justify-center p-2 sm:p-5",children:e.jsxs(J,{className:"relative flex h-[min(42rem,92vh)] w-full max-w-xl flex-col overflow-hidden rounded-2xl bg-white shadow-2xl ring-1 ring-black/10 transition-[opacity,transform] duration-[220ms] ease-[cubic-bezier(0.16,1,0.3,1)] data-[ending-style]:translate-y-3 data-[ending-style]:scale-[0.98] data-[ending-style]:opacity-0 data-[starting-style]:translate-y-3 data-[starting-style]:scale-[0.98] data-[starting-style]:opacity-0 dark:bg-oai-gray-950 dark:ring-white/10",children:[e.jsxs("header",{"data-testid":"community-metrics-header",className:"shrink-0 px-5 pt-5 sm:px-6",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx(Q,{className:"text-lg font-semibold tracking-[-0.02em] text-oai-black dark:text-white",children:n("leaderboard.community.modal.title")}),e.jsx(ee,{className:"sr-only",children:n("leaderboard.community.modal.description")})]}),e.jsx(ae,{className:"-mr-1 -mt-1 grid size-8 place-items-center rounded-full text-oai-gray-400 transition-colors hover:bg-black/5 hover:text-oai-black dark:hover:bg-white/10 dark:hover:text-white","aria-label":n("shared.dialog.close"),children:e.jsx(S,{className:"size-4"})})]}),e.jsxs("div",{className:"mt-4 grid grid-cols-3 gap-x-5",children:[e.jsx(j,{label:n("leaderboard.community.modal.total_tokens"),value:i(h),title:r(h)}),e.jsx(j,{label:n("leaderboard.community.modal.tokens_30d"),value:i(w),title:r(w),delta:a.tokenGrowthPct,deltaLabel:n("leaderboard.community.modal.vs_previous_week")}),e.jsx(j,{label:n("leaderboard.community.modal.contributors"),value:p(N),title:N.toLocaleString()})]}),e.jsx("div",{className:"mt-4 flex items-end overflow-x-auto border-b border-oai-gray-100 dark:border-oai-gray-900",role:"tablist","aria-label":n("leaderboard.community.modal.views"),onKeyDown:E,children:g.map(d=>{const x=o===d;return e.jsxs("button",{type:"button",role:"tab","data-tab-id":d,"aria-selected":x,tabIndex:x?0:-1,onClick:()=>l(d),className:`relative mr-5 h-10 shrink-0 text-sm font-medium transition-colors last:mr-0 ${x?"text-oai-black dark:text-white":"text-oai-gray-500 hover:text-oai-gray-700 dark:text-oai-gray-400 dark:hover:text-oai-gray-200"}`,children:[n(`leaderboard.community.modal.tab.${d}`),x?e.jsx(M.span,{layoutId:"community-metrics-tab-underline",className:"absolute inset-x-0 -bottom-px h-0.5 rounded-full bg-oai-black dark:bg-white",transition:{type:"spring",stiffness:420,damping:34}}):null]},d)})})]}),e.jsx("div",{"data-testid":"community-metrics-content",className:"min-h-0 flex-1 overflow-y-auto px-5 py-5 sm:px-6",children:e.jsxs(M.div,{initial:{opacity:0,y:4},animate:{opacity:1,y:0},transition:{duration:.18,ease:[.16,1,.3,1]},className:"h-full",children:[o==="overview"?e.jsx(me,{trendRows:m.trendRows,mix:m.mix,activeDevelopers30d:Number(a.activeDevelopers30d)||0,developerGrowthPct:a.developerGrowthPct,formatTokens:i,formatTokensTooltip:r}):null,o==="providers"?e.jsx(ce,{rows:m.providers,maxShare:m.providersMaxShare,formatTokens:i,formatTokensTooltip:r}):null,o==="community"?e.jsx(pe,{bands:m.bands,platforms:m.platforms,formatTokensTooltip:r}):null,o==="models"?e.jsx(xe,{rows:m.models,maxShare:m.modelsMaxShare,formatTokens:i,formatTokensTooltip:r}):null]},o)})]})})]})})}function Ge(t){return e.jsx(P,{mode:z.COMPACT,children:e.jsx(ve,{...t})})}export{Ge as CommunityStatsModal};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{j as e,y as n}from"./__vite-browser-external-BXwSXUpN.js";import{C as c}from"./Card-C-UuIN42.js";function g({checked:a,onChange:s,disabled:i,ariaLabel:r,id:t}){return e.jsx("button",{type:"button",id:t,role:"switch","aria-checked":a,"aria-label":r,onClick:s,disabled:i,className:"relative inline-flex h-11 w-11 min-h-11 min-w-11 shrink-0 items-center justify-center rounded-full bg-transparent p-0 focus:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand-500 disabled:cursor-not-allowed disabled:opacity-50",children:e.jsx("span",{"aria-hidden":"true",className:n("tt-toggle-track relative inline-flex h-5 w-9 shrink-0 items-center rounded-full transition-colors",a?"bg-oai-brand-500":"bg-oai-gray-300 dark:bg-oai-gray-700"),children:e.jsx("span",{className:n("tt-toggle-thumb inline-block h-3.5 w-3.5 rounded-full bg-white transition-transform",a?"translate-x-[18px]":"translate-x-[3px]")})})})}function u({label:a,hint:s,control:i}){return e.jsxs("div",{className:"flex flex-col gap-2 py-3 sm:flex-row sm:items-center sm:justify-between sm:gap-4",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-sm text-oai-gray-900 dark:text-oai-gray-200",children:a}),s?e.jsx("div",{className:"mt-0.5 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:s}):null]}),e.jsx("div",{className:"self-end sm:shrink-0 sm:self-auto",children:i})]})}function h({title:a,subtitle:s,action:i,children:r}){return e.jsxs(c,{className:"rounded-lg",children:[e.jsxs("div",{className:"mb-3 flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("h2",{className:"text-sm font-medium text-oai-gray-500 dark:text-oai-gray-300 uppercase tracking-wide",children:a}),s?e.jsx("p",{className:"mt-1 truncate text-xs text-oai-gray-500 dark:text-oai-gray-400",children:s}):null]}),i?e.jsx("div",{className:"shrink-0",children:i}):null]}),e.jsx("div",{className:"-mb-3 divide-y divide-oai-gray-200/60 dark:divide-oai-gray-800/60",children:r})]})}function b({options:a,value:s,onChange:i,disabled:r=!1}){return e.jsx("div",{className:"inline-flex items-center rounded-lg border border-oai-gray-200 bg-oai-gray-50 p-0.5 dark:border-oai-gray-800 dark:bg-oai-gray-900",children:a.map(({value:t,label:o,Icon:l})=>{const d=s===t;return e.jsxs("button",{type:"button",onClick:()=>i(t),"aria-pressed":d,disabled:r,className:n("inline-flex items-center gap-1.5 rounded-md px-3 py-1.5 text-xs font-medium transition-colors disabled:cursor-not-allowed disabled:opacity-50",d?"bg-white text-oai-black shadow-sm dark:bg-oai-gray-800 dark:text-white":"text-oai-gray-500 hover:text-oai-black dark:text-oai-gray-400 dark:hover:text-white"),children:[l?e.jsx(l,{className:"h-3.5 w-3.5","aria-hidden":!0}):null,e.jsx("span",{children:o})]},t)})})}export{b as S,g as T,u as a,h as b};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a as b,r as l,j as r,c as e,f as v}from"./__vite-browser-external-BXwSXUpN.js";const x={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1,VITE_APP_VERSION:"1.3.8",VITE_INSFORGE_ANON_KEY:"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3OC0xMjM0LTU2NzgtOTBhYi1jZGVmMTIzNDU2NzgiLCJlbWFpbCI6ImFub25AaW5zZm9yZ2UuY29tIiwicm9sZSI6ImFub24iLCJpYXQiOjE3ODExNDU5NDd9.T0auta_IrVIh0uXW1bob5QSnzvsnJmN28r5XkSGEuQY",VITE_INSFORGE_BASE_URL:"https://srctyff5.us-east.insforge.app"};function f(){return v(),`${(x&&"https://srctyff5.us-east.insforge.app"||"https://srctyff5.us-east.insforge.app").replace(/\/$/,"")}/functions/tokentracker-device-flow-grant`}function p(s){return(s||"").toUpperCase().replace(/\s+/g,"").replace(/[^A-Z0-9-]/g,"")}function h(){const s=b(),[m,g]=l.useState(""),[i,a]=l.useState({kind:"idle",message:""});l.useEffect(()=>{try{const d=new URLSearchParams(window.location.search).get("user_code");d&&g(p(d))}catch{}},[]);async function u(c){if(c?.preventDefault?.(),!s?.signedIn){a({kind:"error",message:e("device.approval.error.sign_in")});return}const d=p(m);if(!/^[A-HJKMNP-Z2-9]{4}-[A-HJKMNP-Z2-9]{4}$/.test(d)){a({kind:"error",message:e("device.approval.error.invalid_code")});return}a({kind:"working",message:e("device.approval.action.approving")});try{const n=await s.getAccessToken?.();if(!n){a({kind:"error",message:e("device.approval.error.no_token")});return}const o=await fetch(f(),{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n}`},body:JSON.stringify({user_code:d})}),t=await o.json().catch(()=>({}));o.ok?a({kind:"success",message:t.status==="already_approved"?t.client_info?e("device.approval.success.already_client",{client:t.client_info}):e("device.approval.success.already"):t.client_info?e("device.approval.success.approved_client",{client:t.client_info}):e("device.approval.success.approved")}):o.status===404?a({kind:"error",message:e("device.approval.error.not_found")}):o.status===410?a({kind:"error",message:e("device.approval.error.expired")}):o.status===401?a({kind:"error",message:e("device.approval.error.session_expired")}):a({kind:"error",message:t?.error?e("device.approval.error.server_detail",{message:t.error}):e("device.approval.error.server",{status:o.status})})}catch(n){a({kind:"error",message:e("device.approval.error.network",{message:n?.message||n})})}}return r.jsx("div",{className:"min-h-screen flex items-center justify-center bg-white dark:bg-oai-gray-950 px-6 py-12",children:r.jsxs("div",{className:"w-full max-w-md rounded-xl border border-oai-gray-200 dark:border-oai-gray-800 bg-white dark:bg-oai-gray-900 p-8",children:[r.jsx("h1",{className:"text-2xl font-semibold text-oai-gray-900 dark:text-white mb-2",children:e("device.approval.title")}),r.jsx("p",{className:"text-sm text-oai-gray-500 dark:text-oai-gray-400 mb-6",children:e("device.approval.description")}),s?.signedIn?null:r.jsx("div",{className:"rounded-md border border-amber-200 bg-amber-50 dark:bg-amber-900/20 dark:border-amber-800 p-4 mb-4",children:r.jsx("p",{className:"text-sm text-amber-700 dark:text-amber-300",children:e("device.approval.sign_in_banner")})}),r.jsxs("form",{onSubmit:u,className:"space-y-4",children:[r.jsxs("label",{className:"block",children:[r.jsx("span",{className:"block text-xs font-medium uppercase tracking-wide text-oai-gray-500 dark:text-oai-gray-400 mb-1",children:e("device.approval.code_label")}),r.jsx("input",{type:"text",value:m,onChange:c=>g(p(c.target.value)),placeholder:"XXXX-XXXX",spellCheck:!1,autoCapitalize:"characters",maxLength:9,className:"w-full font-mono text-xl tracking-widest text-center rounded-md border border-oai-gray-300 dark:border-oai-gray-700 bg-white dark:bg-oai-gray-900 text-oai-gray-900 dark:text-white px-4 py-3 focus:outline-none focus:ring-inset focus:ring-2 focus:ring-emerald-600"})]}),r.jsx("button",{type:"submit",disabled:i.kind==="working"||!s?.signedIn,className:"w-full rounded-md bg-emerald-600 hover:bg-emerald-500 disabled:bg-oai-gray-300 disabled:cursor-not-allowed text-white font-medium py-3 transition-colors",children:i.kind==="working"?e("device.approval.action.approving"):e("device.approval.action.approve")})]}),i.kind==="success"&&r.jsx("div",{className:"mt-4 rounded-md border border-emerald-200 bg-emerald-50 dark:bg-emerald-900/20 dark:border-emerald-800 p-4",children:r.jsx("p",{className:"text-sm text-emerald-700 dark:text-emerald-300",children:i.message})}),i.kind==="error"&&r.jsx("div",{className:"mt-4 rounded-md border border-red-200 bg-red-50 dark:bg-red-900/20 dark:border-red-800 p-4",children:r.jsx("p",{className:"text-sm text-red-700 dark:text-red-300",children:i.message})})]})})}export{h as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{r as n,K as a}from"./__vite-browser-external-BXwSXUpN.js";import{u as p}from"./DialogTitle-VXrHY7H0.js";import{u as c}from"./composite-7DhFi6TA.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
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/__vite-browser-external-BXwSXUpN.js","assets/__vite-browser-external-DvNSoTb8.css"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{o as ie,by as Rt,bm as It,r as o,M as Dt,K as Ut,bz as Gt,j as e,c as a,y as ae,a as rt,cK as Mt,cL as zt,cM as $t,cN as Ft,a7 as ge,cO as ze,bi as Bt,cP as Ht,bh as $e,cQ as je,aP as ot,cR as Vt,cS as qt,ag as lt,u as ct,V as Ee,aM as dt,X as Kt,x as Pe,B as I,a8 as B,cT as Wt,a9 as Q,ar as ut,cU as _e,a5 as ce,aB as gt,ai as Fe,cV as Yt,ak as Zt,aj as Jt,ah as Xt,cW as Be,cX as Qt,a1 as ea,af as ta,au as fe,R as Te,cY as aa,L as be,av as sa,al as na,am as Re,ac as ia,d as mt,aa as Oe,ab as pt,cZ as He,c_ as Ve,c$ as qe,d0 as ra,d1 as oa,ao as la,Z as ht,l as we,d2 as Ke,k as We,d3 as ca,d4 as da,d5 as ua,z as ga,d6 as ma,d7 as pa,d8 as ha,d9 as fa,da as xa,db as ba,dc as ya,v as ft,cn as va,dd as ka,bj as Ye,_ as ja,e as _a,de as wa,df as Na,bl as Sa}from"./__vite-browser-external-BXwSXUpN.js";import{a as Ca,b as Ze,s as Ea,K as Pa,P as Oa,D as La,c as Aa,S as Ta,v as Ra,u as Ia,C as Da}from"./sortable.esm-CkOax8h0.js";import{a as Ua}from"./modifiers.esm-BljqMT7V.js";import{d as Je,l as Xe,u as Ga,b as Qe}from"./use-limits-display-prefs-BqixyeAa.js";import{P as Ma}from"./ProviderIcon-B-uS3pJ3.js";import{a as A,S as ne,b as se,T as z}from"./Controls-BJAwM2gB.js";import{m as xt}from"./react-BMJ2wuz1.js";import{P as za,u as $a,a as Fa}from"./use-session-efficiency-pref-BgOJaGEy.js";import{C as Ba}from"./check-C--D8Lze.js";import{C as Ha,i as Va}from"./host-mode--iIPGrkN.js";import{A as bt}from"./index-CW6A_Ff_.js";import{r as qa,C as Ne,o as Ka}from"./cloud-checkout-m1Yllbij.js";import{u as Wa,D as Ya,a as Za,b as Ja,c as Xa,d as Qa,e as es}from"./DialogTitle-VXrHY7H0.js";import{u as ts,p as as,t as ss}from"./composite-7DhFi6TA.js";import{k as ns,l as is}from"./SelectItemText-4vuj6xMs.js";import{u as rs}from"./safePolygon-BFHXICk1.js";import{D as os}from"./DialogClose-Cb1-Hd8P.js";import{G as et}from"./gift-BhWBQnun.js";import{C as Le}from"./chevron-down-BzkceD4z.js";import{D as ls}from"./DateRangePopover-Cbd1idiF.js";import{C as cs}from"./calendar-days-BQdTF7ec.js";import{D as Ae}from"./download-BSyGLtfW.js";import{P as ds,a as us,b as gs,c as ms,d as ps}from"./PopoverPopup-CKKgItAT.js";import{C as Se}from"./Card-C-UuIN42.js";import{E as tt}from"./external-link-KzFbueBT.js";import{a as hs,P as fs}from"./play-BlGNrekI.js";import{I as yt}from"./info-D1gOdsM_.js";import{a as xs,b as bs,c as ys,d as vs,e as ks}from"./TooltipPopup-BhSCJqFR.js";import{L as js}from"./loader-circle-DWeQPecG.js";import{u as _s}from"./useCurrency-DL458pqS.js";import{u as ws}from"./useTokenFormat-CYLt9pgs.js";import{S as Ie}from"./Select-Dcg7FYAt.js";import{u as ye}from"./use-native-settings-BSx7lGEK.js";import{C as Ns}from"./ConfirmModal-St89kP59.js";import{A as Ss}from"./arrow-up-right-CzeEeXRz.js";import"./store-DR444-5P.js";import"./usePositioner-DnCQwlVT.js";import"./DialogDescription-DQvYzWMp.js";const vt={name:"credit-card",size:24,node:[["rect",{width:"20",height:"14",x:"2",y:"5",rx:"2",key:"ynyp8z"}],["line",{x1:"2",x2:"22",y1:"10",y2:"10",key:"1b3vmo"}],["path",{d:"M6 14h2",key:"mk7k0u"}]]};vt.node;const Cs=ie(vt);const kt={name:"flask-conical",size:24,node:[["path",{d:"M14 2v6a2 2 0 0 0 .245.96l5.51 10.08A2 2 0 0 1 18 22H6a2 2 0 0 1-1.755-2.96l5.51-10.08A2 2 0 0 0 10 8V2",key:"18mbvz"}],["path",{d:"M6.453 15h11.094",key:"3shlmq"}],["path",{d:"M8.5 2h7",key:"csnxdl"}]]};kt.node;const Es=ie(kt);const jt={name:"grip-vertical",size:24,node:[["circle",{cx:"9",cy:"12",r:"1",key:"1vctgf"}],["circle",{cx:"9",cy:"5",r:"1",key:"hp0tcf"}],["circle",{cx:"9",cy:"19",r:"1",key:"fkjjf6"}],["circle",{cx:"15",cy:"12",r:"1",key:"1tmaij"}],["circle",{cx:"15",cy:"5",r:"1",key:"19l28e"}],["circle",{cx:"15",cy:"19",r:"1",key:"f4zoj3"}]]};jt.node;const Ps=ie(jt);const _t={name:"languages",size:24,node:[["path",{d:"m5 8 6 6",key:"1wu5hv"}],["path",{d:"m4 14 6-6 2-3",key:"1k1g8d"}],["path",{d:"M2 5h12",key:"or177f"}],["path",{d:"M7 2h1",key:"1t2jsx"}],["path",{d:"m22 22-5-10-5 10",key:"don7ne"}],["path",{d:"M14 18h6",key:"1m8k6r"}]]};_t.node;const Os=ie(_t);const wt={name:"log-out",size:24,node:[["path",{d:"m16 17 5-5-5-5",key:"1bji2h"}],["path",{d:"M21 12H9",key:"dn1m92"}],["path",{d:"M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4",key:"1uf3rs"}]]};wt.node;const Ls=ie(wt);const Nt={name:"palette",size:24,node:[["path",{d:"M12 22a1 1 0 0 1 0-20 10 9 0 0 1 10 9 5 5 0 0 1-5 5h-2.25a1.75 1.75 0 0 0-1.4 2.8l.3.4a1.75 1.75 0 0 1-1.4 2.8z",key:"e79jfc"}],["circle",{cx:"13.5",cy:"6.5",r:".5",fill:"currentColor",key:"1okk4w"}],["circle",{cx:"17.5",cy:"10.5",r:".5",fill:"currentColor",key:"f64h9f"}],["circle",{cx:"6.5",cy:"12.5",r:".5",fill:"currentColor",key:"qy21gx"}],["circle",{cx:"8.5",cy:"7.5",r:".5",fill:"currentColor",key:"fotxhn"}]]};Nt.node;const As=ie(Nt);const St={name:"user-round",size:24,node:[["circle",{cx:"12",cy:"8",r:"5",key:"1hypcn"}],["path",{d:"M20 21a8 8 0 0 0-16 0",key:"rfgkzh"}]],aliases:["user-2"]};St.node;const Ts=ie(St),Rs=Rt(function(s,n){const{render:i,className:r,style:c,disabled:m=!1,nativeButton:l=!0,id:d,payload:p,handle:h,...g}=s,v=Wa(!0),x=rs(h)??v;if(!x)throw new Error(It(79));const k=ts(d),b=x.useState("floatingRootContext"),u=x.useState("isOpenedByTrigger",k),y=x.useState("triggerPopupId",k),C=o.useRef(null),{registerTrigger:f,isMountedByThisTrigger:_}=as(k,C,x,{payload:p}),{getButtonProps:w,buttonRef:j}=Dt({disabled:m,native:l}),E=ns(b),O=is(()=>x.select("open"),$=>{x.set("openMethod",$)}),N={disabled:m,open:u},P=x.useState("triggerProps",_);return Ut("button",s,{state:N,ref:[j,n,f,C],props:[E.reference,P,O,{[Gt]:"",id:k,"aria-haspopup":"dialog","aria-expanded":u,"aria-controls":y},g,w],stateAttributesMapping:ss})}),Is="shrink-0 text-oai-gray-900 dark:text-oai-gray-200";function Ds({checked:t,onChange:s,ariaLabel:n}){return e.jsx("button",{type:"button",role:"switch","aria-checked":t,"aria-label":n,onClick:s,className:ae("relative inline-flex h-5 w-9 shrink-0 items-center rounded-full transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand-500",t?"bg-oai-brand-500":"bg-oai-gray-300 dark:bg-oai-gray-700"),children:e.jsx("span",{className:ae("inline-block h-3.5 w-3.5 rounded-full bg-white transition-transform",t?"translate-x-[18px]":"translate-x-[3px]")})})}function Us({id:t,visible:s,onToggle:n}){const{attributes:i,listeners:r,setNodeRef:c,transform:m,transition:l,isDragging:d}=Ia({id:t}),p={transform:Da.Transform.toString(m)||void 0,transition:l,zIndex:d?20:void 0};return e.jsxs("div",{ref:c,style:p,className:ae("flex items-center gap-3 py-2 rounded-md select-none touch-none","cursor-grab active:cursor-grabbing","hover:bg-oai-gray-100/60 dark:hover:bg-oai-gray-800/60","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand-500",d&&"relative bg-oai-gray-100 dark:bg-oai-gray-800"),...i,...r,children:[e.jsx(Ps,{className:"h-4 w-4 shrink-0 text-oai-gray-400 dark:text-oai-gray-500",strokeWidth:1.75,"aria-hidden":!0}),Je(t)?e.jsx(Ma,{provider:Je(t),size:18,className:ae("pointer-events-none",Is)}):null,e.jsx("span",{className:"flex-1 text-sm text-oai-gray-900 dark:text-oai-gray-200",children:Xe(t)}),e.jsx("div",{onPointerDown:h=>h.stopPropagation(),children:e.jsx(Ds,{checked:s,onChange:n,ariaLabel:`${a("limits.settings.toggle_visible")}: ${Xe(t)}`})})]})}function Gs({prefs:t}){const{order:s,visibility:n,toggle:i,setAllVisible:r,moveToward:c}=t,m=s.every(g=>n[g]!==!1),l=s.every(g=>n[g]===!1),d=s.filter(g=>n[g]!==!1).length,p=Ca(Ze(Oa,{activationConstraint:{distance:6}}),Ze(Pa,{coordinateGetter:Ea})),h=({active:g,over:v})=>{v&&g.id!==v.id&&c(g.id,v.id)};return e.jsxs(e.Fragment,{children:[e.jsx(A,{label:a("limits.settings.bulk_visibility"),hint:a("limits.settings.enabled_count",{enabled:d,total:s.length}),control:e.jsx(ne,{options:[{value:"enabled",label:a("limits.settings.enable_all")},{value:"disabled",label:a("limits.settings.disable_all")}],value:m?"enabled":l?"disabled":null,onChange:g=>r(g==="enabled")})}),e.jsx(La,{sensors:p,collisionDetection:Aa,modifiers:[Ua],onDragEnd:h,children:e.jsx(Ta,{items:s,strategy:Ra,children:e.jsx("div",{className:"flex flex-col",children:s.map(g=>e.jsx(Us,{id:g,visible:n[g]!==!1,onToggle:()=>i(g)},g))})})})]})}function Ms(t){if(!t||typeof t!="object")return"";const s=t.user_metadata&&typeof t.user_metadata=="object"?t.user_metadata:{},n=t.profile&&typeof t.profile=="object"?t.profile:{},i=s.full_name||s.name||n.name||s.user_name||s.preferred_username;return typeof i=="string"&&i.trim()?i.trim():typeof t.email=="string"&&t.email.includes("@")?t.email.split("@")[0].trim()||t.email.trim():typeof t.email=="string"?t.email.trim():""}function zs(t){return!t||typeof t!="object"?"":typeof t.email=="string"?t.email.trim():""}function $s(t){const s=typeof t=="string"?t.trim():"";if(!s)return null;const n=s.match(/^@?([A-Za-z0-9][A-Za-z0-9-]{0,38})$/),i=s.match(/^https:\/\/github\.com\/([A-Za-z0-9][A-Za-z0-9-]{0,38})\/?$/i),r=n?.[1]||i?.[1];return r?`https://github.com/${r}`:null}function De(t,s){console.warn(`[tokentracker] settings ${t}:`,s)}function Fs(t,s,n,i){const[r,c]=o.useState(()=>ge()),m=s&&n&<(),l=o.useMemo(()=>({active:!0,busy:!1}),[t,s,n,i]),d=o.useRef(l);d.current=l;const[p,h]=o.useState(null),g=p?.scope===l?p:null;o.useEffect(()=>{l.active=!0;const k=()=>{const u=ge();c(u),u||h(y=>y?.scope===l?{...y,error:null}:y)},b=()=>{h(u=>u?.scope===l?{...u,error:null}:u),je(i,"cloud-sync")};return k(),window.addEventListener("tt.cloudSyncChanged",k),window.addEventListener("storage",k),window.addEventListener(ze,b),()=>{l.active=!1,window.removeEventListener("tt.cloudSyncChanged",k),window.removeEventListener("storage",k),window.removeEventListener(ze,b)}},[l,i]);const v=o.useCallback(async()=>{if(!m||!ge()||l.busy||!l.active||d.current!==l)return;l.busy=!0,h({scope:l,pending:!0,error:null});const k=()=>l.active&&d.current===l&&ge();try{await Bt(()=>t())}catch(b){if(!k())return;["cloud_membership_required","cloud_read_only_expired","cloud_history_window_exceeded","cloud_machine_limit","machine_limit_exceeded","cloud_machine_paused"].includes(b?.code)?Ht(i,b.code,b.membership,"cloud-sync"):h({scope:l,pending:!0,error:{code:"billing_network_error"}}),De("cloud sync",b)}finally{l.busy=!1,l.active&&d.current===l&&h(b=>b?.scope===l?{...b,pending:!1}:b)}},[m,l,t,i]),S=o.useCallback(async()=>{if(!m||l.busy||!l.active||d.current!==l)return;const k=!ge();h({scope:l,pending:!1,error:null}),$e(k),c(k),k?await v():je(i,"cloud-sync")},[m,l,v,i]),x=o.useCallback(()=>{!m||!l.active||d.current!==l||($e(!1),c(!1),h(k=>k?.scope===l?{...k,error:null}:k),je(i,"cloud-sync"))},[m,l,i]);return{cloudSyncOn:r,cloudSyncPending:!!g?.pending,cloudSyncError:g?.error,handleCloudSyncToggle:S,handleCloudSyncRetry:v,handleCloudSyncDisable:x,showLocalCloudSync:m}}function Bs(t){const[s,n]=o.useState(!1),[i,r]=o.useState(!1),[c,m]=o.useState(!1),[l,d]=o.useState(!1),[p,h]=o.useState(null),[g,v]=o.useState(!1),[S,x]=o.useState(""),[k,b]=o.useState(!1),[u,y]=o.useState(""),[C,f]=o.useState(""),[_,w]=o.useState(!1),[j,E]=o.useState(null),O=o.useMemo(()=>Ms(t),[t]),N=o.useMemo(()=>zs(t),[t]),P=o.useMemo(()=>typeof t?.id=="string"?t.id.trim():"",[t]),$=o.useMemo(()=>({setAnonymousOn:r,setCustomDisplayName:h,setGithubUrl:y,setProfileLoading:m,setPublicProfileOn:n,setShowGithubOn:b}),[]);return{anonymousOn:i,customDisplayName:p,displayName:O,editingGithub:_,editingName:g,email:N,githubError:j,githubInput:C,githubUrl:u,loadSetters:$,nameInput:S,profileLoading:c,profileSaving:l,publicProfileOn:s,setAnonymousOn:r,setCustomDisplayName:h,setEditingGithub:w,setEditingName:v,setGithubError:E,setGithubInput:f,setGithubUrl:y,setNameInput:x,setProfileLoading:m,setProfileSaving:d,setPublicProfileOn:n,setShowGithubOn:b,showGithubOn:k,userId:P}}function Hs(t,s,n){o.useEffect(()=>{if(!s)return;let i=!0;return n.setProfileLoading(!0),(async()=>{try{const r=await ot({getAccessToken:t});if(!i||!r)return;const c=await Vt({accessToken:r});if(!i)return;n.setPublicProfileOn(!!c?.enabled),n.setAnonymousOn(!!c?.anonymous),c?.display_name&&n.setCustomDisplayName(c.display_name),n.setShowGithubOn(!!c?.show_github_url),n.setGithubUrl(c?.github_url||"")}catch(r){De("load public profile",r)}finally{i&&n.setProfileLoading(!1)}})(),()=>{i=!1}},[t,s,n])}function Vs(t,s,n){return o.useCallback(async(i,{label:r,onError:c,onSuccess:m}={})=>{if(!n||s.profileSaving)return!1;s.setProfileSaving(!0);try{const l=await ot({getAccessToken:t});if(!l)return!1;const d=await qt({accessToken:l,...i});return m?.(d),!0}catch(l){return c?c(l):De(r||"mutate profile",l),!1}finally{s.setProfileSaving(!1)}},[t,s,n])}function qs(t,s){return{anonymousOn:t.anonymousOn,customDisplayName:t.customDisplayName,displayName:t.displayName,editingName:t.editingName,handleAnonymousToggle:s.handleAnonymousToggle,handleSaveName:s.handleSaveName,nameInput:t.nameInput,profileLoading:t.profileLoading,profileSaving:t.profileSaving,setEditingName:t.setEditingName,setNameInput:t.setNameInput,startEditingName:s.startEditingName}}function Ks(t,s){return{editingGithub:t.editingGithub,githubError:t.githubError,githubInput:t.githubInput,githubUrl:t.githubUrl,handleSaveGithub:s.handleSaveGithub,handleShowGithubToggle:s.handleShowGithubToggle,profileLoading:t.profileLoading,profileSaving:t.profileSaving,setEditingGithub:t.setEditingGithub,setGithubError:t.setGithubError,setGithubInput:t.setGithubInput,showGithubOn:t.showGithubOn,startEditingGithub:s.startEditingGithub}}function Ws(t,s){const n=o.useCallback(async()=>{const r=!t.publicProfileOn;await s({enabled:r},{label:"toggle public profile",onSuccess:()=>t.setPublicProfileOn(r)})},[s,t]);return{handleAnonymousToggle:o.useCallback(async()=>{const r=!t.anonymousOn;await s({anonymous:r},{label:"toggle anonymous",onSuccess:()=>t.setAnonymousOn(r)})},[s,t]),handlePublicProfileToggle:n}}function Ys(t,s,n){const i=o.useCallback(async()=>{const c=t.nameInput.trim().slice(0,50);c&&await s({display_name:c},{label:"save display name",onSuccess:()=>{t.setCustomDisplayName(c),t.setEditingName(!1),n?.()}})},[s,t,n]),r=o.useCallback(()=>{t.setNameInput(t.customDisplayName||t.displayName),t.setEditingName(!0)},[t]);return{handleSaveName:i,startEditingName:r}}function Zs(t,s){const n=o.useCallback(async()=>{if(!t.showGithubOn&&!t.githubUrl){t.setEditingGithub(!0),t.setGithubInput(""),t.setGithubError(null);return}const c=!t.showGithubOn;await s({show_github_url:c},{label:"toggle GitHub profile",onSuccess:()=>t.setShowGithubOn(c)})},[s,t]),i=o.useCallback(async()=>{const c=$s(t.githubInput);if(t.githubInput.trim()&&!c){t.setGithubError(a("settings.account.githubUrlInvalid"));return}t.setGithubError(null),await s({github_url:c,show_github_url:!!c},{label:"save GitHub profile",onError:m=>t.setGithubError(m?.message||a("settings.account.githubUrlInvalid")),onSuccess:m=>{t.setGithubUrl(m?.github_url||c||""),t.setShowGithubOn(!!c),t.setEditingGithub(!1)}})},[s,t]),r=o.useCallback(()=>{t.setGithubInput(t.githubUrl),t.setGithubError(null),t.setEditingGithub(!0)},[t]);return{handleSaveGithub:i,handleShowGithubToggle:n,startEditingGithub:r}}function Ue(){const t=rt();o.useSyncExternalStore(Mt,zt,()=>0);const s=$t(t.user?.id),i=!(s.membership?.status==="self_hosted"||s.catalog?.policy?.hosting_mode==="self_hosted")&&(Ft()||s.membership?.hosting_mode==="hosted"),r=Bs(t.user),c=Fs(t.getAccessToken,t.enabled,t.signedIn,t.user?.id);Hs(t.getAccessToken,t.signedIn&&i,r.loadSetters);const m=Vs(t.getAccessToken,r,i),l=Ws(r,m),d=Ys(r,m,t.refreshDisplayName),p=Zs(r,m);return{...t,...c,email:r.email,handlePublicProfileToggle:l.handlePublicProfileToggle,userId:r.userId,name:qs(r,{...l,...d}),github:Ks(r,p),profileLoading:r.profileLoading,profileSaving:r.profileSaving,publicProfileOn:i&&r.publicProfileOn,publicProfileAvailable:i}}function Ct({disabled:t,onCancel:s,onSave:n,saveLabel:i=a("settings.account.save")}){return e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:n,disabled:t,className:"rounded-md bg-oai-brand-500 px-3 py-1.5 text-xs font-medium text-white transition-colors hover:bg-oai-brand-600 disabled:opacity-50",children:i}),e.jsx("button",{type:"button",onClick:s,className:"rounded-md px-2 py-1.5 text-xs text-oai-gray-500 transition-colors hover:text-oai-gray-700 dark:hover:text-oai-gray-300",children:a("settings.account.cancel")})]})}function Js({nameInput:t,setEditingName:s,setNameInput:n,profileSaving:i,handleSaveName:r}){return e.jsxs("div",{className:"mt-2 flex items-center gap-2",children:[e.jsx("input",{type:"text",value:t,onChange:c=>n(c.target.value),onKeyDown:c=>{c.key==="Enter"&&r(),c.key==="Escape"&&s(!1)},maxLength:50,autoFocus:!0,className:"flex-1 rounded-md border border-oai-gray-300 bg-transparent px-2.5 py-1.5 text-sm text-oai-black outline-none focus:border-oai-brand-500 focus:ring-1 focus:ring-inset focus:ring-oai-brand-500 dark:border-oai-gray-700 dark:text-white",placeholder:a("settings.account.displayName")}),e.jsx(Ct,{disabled:i||!t.trim(),onCancel:()=>s(!1),onSave:r,saveLabel:i?a("settings.account.saving"):void 0})]})}function Xs({githubError:t,githubInput:s,handleSaveGithub:n,profileSaving:i,setEditingGithub:r,setGithubError:c,setGithubInput:m}){return e.jsxs("div",{className:"mt-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"text",value:s,onChange:l=>{m(l.target.value),t&&c(null)},onKeyDown:l=>{l.key==="Enter"&&n(),l.key==="Escape"&&(r(!1),c(null))},maxLength:100,autoFocus:!0,className:"flex-1 rounded-md border border-oai-gray-300 bg-transparent px-2.5 py-1.5 text-sm text-oai-black outline-none focus:border-oai-brand-500 focus:ring-1 focus:ring-inset focus:ring-oai-brand-500 dark:border-oai-gray-700 dark:text-white",placeholder:a("settings.account.githubUrlPlaceholder")}),e.jsx(Ct,{disabled:i,onCancel:()=>{r(!1),c(null)},onSave:n,saveLabel:i?a("settings.account.saving"):void 0})]}),t?e.jsx("div",{className:"mt-1.5 text-xs text-red-600 dark:text-red-400",children:t}):null]})}function Et({disabled:t=!1,label:s,onClick:n,title:i}){return e.jsxs("button",{type:"button",onClick:n,disabled:t,title:i,className:"inline-flex h-8 shrink-0 items-center gap-1.5 rounded-md border border-oai-gray-200 px-3 text-xs font-medium text-oai-gray-700 transition-colors hover:bg-oai-gray-100 disabled:cursor-not-allowed disabled:opacity-40 dark:border-oai-gray-800 dark:text-oai-gray-300 dark:hover:bg-oai-gray-800",children:[e.jsx(za,{className:"h-3.5 w-3.5","aria-hidden":!0}),s]})}function Pt({actions:t,editing:s,editor:n,hint:i,label:r}){return e.jsx("div",{className:"py-3",children:e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-sm text-oai-gray-900 dark:text-oai-gray-200",children:r}),s?n:e.jsx("div",{className:"mt-0.5 truncate text-xs text-oai-gray-500 dark:text-oai-gray-400",children:i})]}),s?null:t]})})}function Qs({name:t}){const s=t.anonymousOn?a("settings.account.displayNameDisabledWhileAnon"):void 0;return e.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[e.jsx(Et,{disabled:t.anonymousOn,label:a("settings.account.edit"),onClick:t.startEditingName,title:s}),e.jsx(z,{checked:!t.anonymousOn,onChange:t.handleAnonymousToggle,disabled:t.profileLoading||t.profileSaving,ariaLabel:a("settings.account.displayName")})]})}function en({name:t}){const{anonymousOn:s,customDisplayName:n,displayName:i,editingName:r,handleAnonymousToggle:c,handleSaveName:m,nameInput:l,profileLoading:d,profileSaving:p,setEditingName:h,setNameInput:g,startEditingName:v}=t,S=s?a("settings.account.displayNameAnonymousHint"):n||i;return e.jsx(Pt,{label:a("settings.account.displayName"),editing:r,hint:S,editor:e.jsx(Js,{nameInput:l,setEditingName:h,setNameInput:g,profileSaving:p,handleSaveName:m}),actions:e.jsx(Qs,{name:t})})}function tn({github:t}){const{editingGithub:s,githubError:n,githubInput:i,githubUrl:r,handleSaveGithub:c,handleShowGithubToggle:m,profileLoading:l,profileSaving:d,setEditingGithub:p,setGithubError:h,setGithubInput:g,showGithubOn:v,startEditingGithub:S}=t;return e.jsx(e.Fragment,{children:e.jsx(Pt,{label:a("settings.account.githubUrl"),editing:s,hint:r||a("settings.account.githubUrlHint"),editor:e.jsx(Xs,{githubError:n,githubInput:i,handleSaveGithub:c,profileSaving:d,setEditingGithub:p,setGithubError:h,setGithubInput:g}),actions:e.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[e.jsx(Et,{label:a("settings.account.edit"),onClick:S}),e.jsx(z,{checked:v,onChange:m,disabled:l||d,ariaLabel:a("settings.account.githubUrl")})]})})})}function an(){const{openLoginModal:t}=ct();return e.jsx(se,{title:a("settings.section.account"),children:e.jsxs("div",{className:"flex items-center justify-between gap-4 py-3",children:[e.jsx("p",{className:"text-sm text-oai-gray-500 dark:text-oai-gray-400",children:a("settings.account.signedOutHint")}),e.jsx("button",{type:"button",onClick:t,className:"inline-flex h-8 shrink-0 items-center justify-center rounded-md bg-oai-gray-900 px-4 text-xs font-medium text-white transition-colors hover:bg-oai-gray-800 dark:bg-white dark:text-oai-gray-900 dark:hover:bg-oai-gray-100",children:a("settings.account.signIn")})]})})}function sn({name:t,github:s}){return e.jsxs(e.Fragment,{children:[e.jsx(en,{name:t}),e.jsx(tn,{github:s})]})}function nn({settings:t}={}){return t?e.jsx(Ot,{settings:t}):e.jsx(rn,{})}function rn(){const t=Ue();return e.jsx(Ot,{settings:t})}function Ot({settings:t}){return t.enabled?t.signedIn?e.jsxs(se,{title:a("settings.section.account"),subtitle:t.email||t.name.customDisplayName||t.name.displayName,action:e.jsx(ln,{onSignOut:t.signOut}),children:[e.jsx(on,{userId:t.userId}),e.jsx(cn,{checked:t.publicProfileOn,disabled:t.profileLoading||t.profileSaving||t.publicProfileAvailable===!1,onChange:t.handlePublicProfileToggle,unavailable:t.publicProfileAvailable===!1}),e.jsx(dn,{visible:t.publicProfileOn,name:t.name,github:t.github})]}):e.jsx(an,{}):null}function on({userId:t}){const[s,n]=Ee.useState(!1);if(!t)return null;const i=async()=>{try{if(typeof navigator>"u"||!navigator.clipboard?.writeText)return;await navigator.clipboard.writeText(t),n(!0),globalThis.setTimeout(()=>n(!1),1200)}catch{n(!1)}};return e.jsxs("div",{className:"flex items-center justify-between gap-4 py-3",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-sm text-oai-gray-900 dark:text-oai-gray-200",children:a("settings.account.userId")}),e.jsx("div",{className:"mt-0.5 truncate font-mono text-xs text-oai-gray-500 dark:text-oai-gray-400",children:t})]}),e.jsxs("button",{type:"button",onClick:i,className:"inline-flex h-8 shrink-0 items-center gap-1.5 rounded-md border border-oai-gray-200 px-3 text-xs font-medium text-oai-gray-700 transition-colors hover:bg-oai-gray-100 dark:border-oai-gray-800 dark:text-oai-gray-300 dark:hover:bg-oai-gray-800","aria-label":a("settings.account.copyUserId"),children:[s?e.jsx(Ba,{className:"h-3.5 w-3.5","aria-hidden":!0}):e.jsx(Ha,{className:"h-3.5 w-3.5","aria-hidden":!0}),s?a("settings.account.copied"):a("settings.account.copy")]})]})}function ln({onSignOut:t}){return e.jsxs("button",{type:"button",onClick:()=>t(),className:"inline-flex h-7 items-center gap-1.5 text-xs font-medium text-oai-gray-500 transition-colors hover:text-oai-gray-700 dark:hover:text-oai-gray-300",children:[e.jsx(Ls,{className:"h-3.5 w-3.5","aria-hidden":!0}),a("settings.account.signOut")]})}function cn({checked:t,disabled:s,onChange:n,unavailable:i}){return e.jsx(A,{label:a("settings.account.publicProfile"),hint:a(i?"cloud.self_host.public_profile_disabled":"settings.account.publicProfileHint"),control:e.jsx(z,{checked:t,onChange:n,disabled:s,ariaLabel:a("settings.account.publicProfile")})})}function dn({visible:t,name:s,github:n}){return e.jsx(bt,{initial:!1,children:t?e.jsx(xt.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},transition:{height:{duration:.28,ease:[.22,1,.36,1]},opacity:{duration:.2,ease:[.22,1,.36,1]}},style:{overflow:"hidden"},className:"divide-y divide-oai-gray-200/60 dark:divide-oai-gray-800/60",children:e.jsx(sn,{name:s,github:n})},"public-profile-fields"):null})}function Ge({open:t,onOpenChange:s,title:n,triggerLabel:i=n,icon:r,wide:c=!1,preventClose:m=!1,initialFocus:l,children:d}){return e.jsxs(Ya,{open:t,onOpenChange:(p,h)=>{if(!p&&m){h.cancel();return}s(p)},children:[e.jsxs(Rs,{className:"inline-flex h-11 w-full items-center gap-3 rounded-md border-0 bg-transparent p-0 text-left text-sm font-medium text-oai-black transition-colors hover:bg-oai-gray-100 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-oai-gray-500 dark:text-oai-white dark:hover:bg-oai-gray-800",children:[r?e.jsx(r,{size:16,className:"shrink-0","aria-hidden":!0}):null,e.jsx("span",{className:"min-w-0 flex-1",children:i}),e.jsx(dt,{size:16,className:"shrink-0 text-oai-gray-500 dark:text-oai-gray-400","aria-hidden":!0})]}),e.jsxs(Za,{children:[e.jsx(Ja,{className:"tt-cloud-action-backdrop fixed inset-0 z-[100] bg-black/40 dark:bg-black/60"}),e.jsx(Xa,{className:"tt-cloud-settings fixed inset-0 z-[101] flex items-center justify-center overflow-y-auto overscroll-contain p-4",children:e.jsxs(Qa,{initialFocus:l,"aria-modal":"true",className:`tt-cloud-action-popup tt-cloud-theme relative max-h-[calc(100dvh-2rem)] w-full ${c?"max-w-2xl":"max-w-lg"} overflow-y-auto overscroll-contain rounded-xl bg-white p-5 shadow-xl outline-none dark:bg-oai-gray-900`,children:[e.jsxs("div",{className:"mb-3 flex min-h-11 items-center justify-between gap-4",children:[e.jsx(es,{className:"min-w-0 text-lg font-semibold text-oai-black dark:text-oai-white",children:n}),e.jsx(os,{disabled:m,"aria-label":a("shared.dialog.close"),className:"inline-flex size-11 min-h-11 min-w-11 shrink-0 items-center justify-center rounded-md border-0 bg-transparent p-0 text-oai-gray-500 transition-colors hover:bg-oai-gray-100 hover:text-oai-black focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-oai-gray-500 disabled:cursor-wait disabled:opacity-40 dark:text-oai-gray-400 dark:hover:bg-oai-gray-800 dark:hover:text-oai-white",children:e.jsx(Kt,{size:18,"aria-hidden":!0})})]}),e.jsx("div",{"data-settings-panel":"cloud",className:"min-w-0",children:d})]})})]})]})}function he(t){return t.replace(/[\t\n\r\f\v -]/g,"").toUpperCase()}function un({account:t,auth:s,refresh:n,compact:i=!1,panelContainer:r=null,layout:c="default",dialogOpen:m,onDialogOpenChange:l}){const d=c==="settings-row",[p,h]=o.useState(!1),g=d&&typeof m=="boolean"?m:p,[v,S]=o.useState(""),[x,k]=o.useState(!1),[b,u]=o.useState(null),[y,C]=o.useState(null),[f,_]=o.useState(!1),w=o.useId(),j=o.useRef(null),E=o.useRef(null),O=o.useRef(!1),N=o.useRef(!1),P=o.useRef(0),$=`${Pe()}.${t?.environment||"unknown"}.${s?.signedIn?s.user?.id:""}`,G=o.useRef($);G.current=$,o.useEffect(()=>(N.current=!0,P.current+=1,E.current=null,O.current=!1,h(!1),S(""),k(!1),u(null),C(null),_(!1),()=>{N.current=!1,P.current+=1}),[$]);const Z=t?.membership?.status==="self_hosted"||t?.membership?.hosting_mode==="self_hosted",H=t?.gift_redemption_available===!0,ee=d?t?.gifts||[]:[];if(!s?.signedIn||Z||!H&&!ee.length)return null;const K=t.redemption_restriction,F=T=>{!T&&O.current||(typeof m!="boolean"&&h(T),l?.(T))},L=async(T,re)=>{const oe=await n();re()&&_(!!oe?.gifts?.some(W=>W.id===T?.id))},V=async T=>{if(O.current||T&&(!H||!v.trim()))return;if(T&&K&&K!=="gift_checkout_pending"){u(new _e(K));return}O.current=!0;const re=++P.current,oe=$,W=()=>N.current&&P.current===re&&G.current===oe;k(!0),u(null);try{if(T){const te=v.trim();(!E.current||he(E.current.code)!==he(te))&&(E.current={code:te,request_id:crypto.randomUUID()});const le=await ce("redeem-gift",{auth:async()=>{const de=await gt(s.getAccessToken);if(!W())throw new _e("authentication_required",401);return de},body:E.current});if(!W())return;if(!le?.gift?.id)throw new _e("billing_operation_failed");C(le),_(!1),S(""),E.current=null,await L(le.gift,W)}else await L(y?.gift,W)}catch(te){W()&&u(te)}finally{W()&&(O.current=!1,k(!1))}};let q=null;return(d||g)&&(q=e.jsxs("div",{id:`${w}-panel`,className:d?"space-y-3":i?"w-full space-y-3 rounded-lg bg-oai-gray-50 p-4 dark:bg-oai-gray-950/50":"mt-3 space-y-3",children:[H?e.jsxs(e.Fragment,{children:[e.jsx("p",{id:`${w}-detail`,className:d?"sr-only":"text-xs leading-5 text-oai-gray-600 dark:text-oai-gray-300",children:a("cloud.gift.detail")}),y?e.jsxs("div",{role:"status",className:"space-y-2 text-sm leading-6",children:[d&&f?null:e.jsx("p",{children:a(f?y.already_redeemed?"cloud.gift.already_redeemed":"cloud.gift.redeemed":"cloud.gift.refresh_needed")}),y.gift?d&&f?e.jsxs("div",{className:"py-1",children:[e.jsx("p",{className:"text-base font-medium text-oai-black dark:text-oai-white",children:a("cloud.gift.duration",{days:y.gift.duration_days})}),e.jsx("p",{className:"mt-1 text-sm text-oai-gray-500 dark:text-oai-gray-400",children:a("cloud.history.term",{start:B(y.gift.starts_at),end:B(y.gift.ends_at)})})]}):e.jsx("p",{className:"text-xs text-oai-gray-600 dark:text-oai-gray-300",children:a("cloud.gift.term",{days:y.gift.duration_days,start:B(y.gift.starts_at),end:B(y.gift.ends_at)})}):null,f?e.jsxs("div",{className:"flex flex-wrap justify-end gap-2 pt-3",children:[e.jsx(I,{type:"button",variant:"secondary",size:"sm",onClick:()=>{C(null),_(!1),requestAnimationFrame(()=>j.current?.focus())},children:a("cloud.gift.redeem_another")}),d?e.jsx(I,{type:"button",size:"sm",className:"min-w-20",disabled:x,onClick:()=>F(!1),children:a("cloud.gift.done")}):null]}):e.jsx(I,{type:"button",variant:"secondary",disabled:x,onClick:()=>{V(!1)},children:a("cloud.action.refresh_membership")})]}):e.jsxs("form",{onSubmit:T=>{T.preventDefault(),V(!0)},"aria-busy":x,children:[e.jsx("label",{htmlFor:w,className:d?"sr-only":"text-sm font-medium",children:a("cloud.gift.code_label")}),e.jsxs("div",{className:"mt-2 flex flex-col gap-2 sm:flex-row",children:[e.jsx("input",{id:w,ref:j,value:v,disabled:x,maxLength:128,autoComplete:"off",spellCheck:!1,autoCapitalize:"characters","data-ph-no-capture":"true","aria-describedby":`${w}-detail${b?` ${w}-error`:""}`,"aria-invalid":!!b,onChange:T=>{he(T.target.value)!==he(v)&&(E.current=null),S(T.target.value),u(null)},className:"min-h-10 min-w-0 flex-1 rounded-md border border-oai-gray-300 bg-transparent px-3 font-mono text-sm outline-none focus:border-oai-brand focus:ring-2 focus:ring-inset focus:ring-oai-brand/30 dark:border-oai-gray-700"}),e.jsx(I,{type:"submit",variant:"secondary",disabled:x||!v.trim(),children:a(x?"cloud.gift.redeeming":"cloud.gift.confirm")})]})]}),b?e.jsx("div",{id:`${w}-error`,children:["gift_checkout_pending","gift_requires_renewal_cancel"].includes(b.code)?e.jsx("p",{role:"alert",className:"text-xs leading-5 text-oai-gray-600 dark:text-oai-gray-300",children:Wt(b,"gift")}):e.jsx(Q,{error:b,context:"gift"})}):null]}):null,ee.length&&!y?e.jsx("ul",{"aria-label":a("cloud.gift.history_title"),className:"divide-y divide-oai-gray-200 dark:divide-oai-gray-800",children:ee.map(T=>e.jsxs("li",{className:"py-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 text-sm",children:[e.jsx("span",{children:a("cloud.gift.duration",{days:T.duration_days})}),e.jsx("span",{children:a(["active","pending","expired","revoked"].includes(T.state)?`cloud.gift.state_${T.state}`:"cloud.status.unknown")})]}),e.jsx("p",{className:"mt-1 text-xs leading-5 text-oai-gray-600 dark:text-oai-gray-300",children:a("cloud.history.term",{start:B(T.starts_at),end:B(T.ends_at)})})]},T.id))}):null]})),d?e.jsx(Ge,{open:g,onOpenChange:F,title:a(y&&f?"cloud.gift.redeemed":H?"cloud.gift.redeem_action":"cloud.gift.history_title"),triggerLabel:a(H?"cloud.gift.redeem_action":"cloud.gift.history_title"),icon:et,preventClose:x,initialFocus:H&&!y?j:void 0,children:q}):e.jsxs("div",{className:d?void 0:i?"contents":"mt-4",children:[e.jsxs(I,{type:"button",variant:"ghost",size:i||d?"sm":"md",className:d?"!h-11 !w-full !justify-start !px-0 !text-oai-black dark:!text-oai-white hover:!bg-oai-gray-100 dark:hover:!bg-oai-gray-800 active:!scale-100":i?"!h-10 !px-0":void 0,"aria-expanded":g,"aria-controls":d||g?`${w}-panel`:void 0,onClick:()=>h(T=>!T),disabled:x,children:[i||d?e.jsx(et,{size:16,className:`${d?"mr-3":"mr-2"} shrink-0`,"aria-hidden":!0}):null,a(H?"cloud.gift.redeem_action":"cloud.gift.history_title"),d?e.jsx(Le,{size:16,className:`ml-auto shrink-0 transition-transform motion-reduce:transition-none ${g?"rotate-180":""}`,"aria-hidden":!0}):null]}),!d&&r&&q?ut.createPortal(q,r):q]})}const xe=["total_tokens","billable_total_tokens","input_tokens","output_tokens","cached_input_tokens","cache_creation_input_tokens","reasoning_output_tokens","conversation_count","total_cost_usd"];class U extends Error{constructor(s,n=0){super(s),this.code=s,this.status=n}code;status}function me(t){return typeof t=="string"&&/^\d{4}-\d{2}-\d{2}$/.test(t)&&Number.isFinite(Date.parse(t+"T00:00:00Z"))&&new Date(t+"T00:00:00Z").toISOString().slice(0,10)===t}function gn(t,s){if(!Xt(t))throw new U("export_auth_required",401);try{const n=t.split(".")[1].replace(/-/g,"+").replace(/_/g,"/"),i=JSON.parse(atob(n.padEnd(Math.ceil(n.length/4)*4,"=")));if((i.sub||i.user_id)!==s||i.role!=="authenticated"||!Number.isFinite(i.exp)||i.exp*1e3<=Date.now())throw Error()}catch{throw new U("export_auth_required",401)}}function at(t){if(typeof t?.membership?.can_read_cloud!="boolean")throw new U("export_invalid_data",503);if(!t.membership.can_read_cloud)throw new U("export_access_denied",402);const s=t.membership;return JSON.stringify([t.environment,s.phase,s.status,s.hosting_mode,s.expires_at,s.trial_ends_at,s.transition_ends_at,s.read_only_until])}async function mn({userId:t,auth:s,from:n,to:i,deviceId:r=null,signal:c,assertCurrent:m=()=>{},fetchImpl:l=fetch}){if(!me(n)||!me(i)||n>i)throw new U("export_invalid_dates",400);if(typeof s!="function")throw new U("export_auth_required",401);if(!t||r&&!/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(r))throw new U("export_invalid_scope",400);const d=Pe(),p=Fe();if(!d)throw new U("export_instance_changed",409);const h=()=>{if(c?.aborted)throw new U("export_cancelled",409);if(m(),d!==Pe()||p!==Fe())throw new U("export_instance_changed",409)};async function g(u,y){h();const C=await gt(s);h(),gn(C||"",t);const f=new URL(Zt(d,u));for(const[E,O]of Object.entries(y))f.searchParams.set(E,O);const _=new AbortController,w=()=>_.abort();c?.addEventListener("abort",w,{once:!0});const j=setTimeout(w,25e3);try{const E=await Jt(f.toString(),{method:"GET",cache:"no-store",redirect:"error",signal:_.signal,headers:{Accept:"application/json",Authorization:"Bearer "+C,...p?{apikey:p}:{}}},l);if(h(),!E.ok)throw new U(E.status===401?"export_auth_required":E.status===402||E.status===403?"export_access_denied":"export_failed",E.status);const O=await E.json();return h(),O}finally{clearTimeout(j),c?.removeEventListener("abort",w)}}const v=at(await g("tokentracker-billing",{action:"account"})),S={from:n,to:i,tz_offset_minutes:"0",...r?{device_id:r}:{}};if(await g("tokentracker-account-daily",S),at(await g("tokentracker-billing",{action:"account"}))!==v)throw new U("export_access_changed",409);const x=await g("tokentracker-account-daily",S);if(!me(x?.from)||!me(x?.to)||x.from<n||x.to>i||x.from>x.to||!Array.isArray(x.data)||x.data.length>1096)throw new U("export_invalid_data",503);const k=new Set,b=x.data.map(u=>{if(!me(u?.day)||u.day<x.from||u.day>x.to||k.has(u.day))throw new U("export_invalid_data",503);k.add(u.day);const y={day:u.day};for(const C of xe){const f=u[C];if(typeof f!="number"||!Number.isFinite(f)||f<0||C!=="total_cost_usd"&&!Number.isSafeInteger(f))throw new U("export_invalid_data",503);y[C==="total_cost_usd"?"estimated_cost_usd":C]=f}return y}).sort((u,y)=>u.day.localeCompare(y.day));return h(),{schema:"tokentracker.cloud-usage.v1",metadata:{source:"cloud",backend_origin:new URL(d).origin,exported_at:new Date().toISOString(),timezone:"UTC",requested_range:{from:n,to:i},effective_range:{from:x.from,to:x.to},device_scope:r?"selected":"all",aggregation:"daily_all_providers",cost_currency:"USD",cost_basis:"estimated",row_count:b.length},rows:b}}function pn(t){const s=String(t??"");return'"'+(/^[\s]*[=+\-@]/.test(s)?"'"+s:s).replace(/"/g,'""')+'"'}function hn(t,s){if(s==="json")return JSON.stringify(t,null,2)+`
|
|
3
|
-
`;const n=t.metadata,i=["row_type","source","backend_origin","exported_at","timezone","cost_currency","cost_basis","requested_from","requested_to","effective_from","effective_to","device_scope","aggregation","row_count","day",...xe.map(c=>c==="total_cost_usd"?"estimated_cost_usd":c)],r=[n.source,n.backend_origin,n.exported_at,n.timezone,n.cost_currency,n.cost_basis,n.requested_range.from,n.requested_range.to,n.effective_range.from,n.effective_range.to,n.device_scope,n.aggregation,n.row_count];return[i,["metadata",...r,"",...xe.map(()=>"")],...t.rows.map(c=>["usage",...r,c.day,...xe.map(m=>c[m==="total_cost_usd"?"estimated_cost_usd":m])])].map(c=>c.map(pn).join(",")).join(`\r
|
|
4
|
-
`)+`\r
|
|
5
|
-
`}async function fn(t,s,{signal:n,assertCurrent:i=()=>{}}={}){const r=hn(t,s),c=`tokentracker-cloud-usage-${t.metadata.effective_range.from}-${t.metadata.effective_range.to}.${s}`,m=()=>{if(n?.aborted)throw new U("export_cancelled",409);i()};m();const l=await Yt({filename:c,content:r,format:s,signal:n});if(m(),l?.saved===!0)return;if(l!==null)throw new U("export_failed",503);const d=new Blob([r],{type:s==="csv"?"text/csv;charset=utf-8":"application/json;charset=utf-8"}),p=URL.createObjectURL(d);try{const h=document.createElement("a");h.href=p,h.download=c,document.body.appendChild(h);try{h.click()}finally{h.remove()}}finally{setTimeout(()=>URL.revokeObjectURL(p),1e3)}}function xn(t){return t?.status===401?a("cloud.export.error_auth"):t?.status===402||t?.status===403?a("cloud.export.error_access"):t?.code==="export_invalid_dates"?a("cloud.export.error_dates"):t?.status===409?a("cloud.export.error_changed"):a("cloud.export.error_failed")}function bn({from:t,to:s,deviceId:n=null,auth:i,compact:r=!1,panelContainer:c=null,layout:m="default",dialogOpen:l,onDialogOpenChange:d}){const p=m==="settings-row",h=rt(),g=i||h,v=g?.signedIn?g.user?.id:null,S=new Date().toISOString().slice(0,10),x=new Date(Date.now()-29*864e5).toISOString().slice(0,10),[k,b]=o.useState(t||x),[u,y]=o.useState(s||S),[C,f]=o.useState(!1),_=p&&typeof l=="boolean"?l:C,[w,j]=o.useState(!1),[E,O]=o.useState(null),[N,P]=o.useState(null),[$,G]=o.useState(!1),[Z,H]=o.useState(2),ee=o.useId(),K=o.useRef(null),F=o.useRef(0),L=o.useRef(null),V=o.useRef(!1),q=o.useRef(!1),T=o.useRef(_);T.current=_;const re=o.useRef(_);if(K.current={userId:v,client:g?.client,start:k,end:u,deviceId:n,from:t,to:s},o.useEffect(()=>{q.current=!0;const R=()=>{++F.current,L.current?.abort(),V.current=!1,j(!1),P(null),O(null),G(!1)};return window.addEventListener(Be,R),()=>{q.current=!1,++F.current,L.current?.abort(),window.removeEventListener(Be,R)}},[]),o.useEffect(()=>{++F.current,L.current?.abort(),V.current=!1,j(!1),O(null),P(null),G(!1),t&&b(t),s&&y(s)},[v,g?.client,t,s,n]),o.useEffect(()=>{p&&re.current&&!_&&oe(),re.current=_},[_,p]),o.useEffect(()=>{const R=window.matchMedia?.("(max-width: 639px)");if(!R)return;const D=()=>H(R.matches?1:2);return D(),R.addEventListener("change",D),()=>R.removeEventListener("change",D)},[]),!v||g?.enabled===!1)return null;function oe(){++F.current,L.current?.abort(),V.current=!1,j(!1),O(null),P(null),G(!1)}function W(R){R||oe(),typeof l!="boolean"&&f(R),d?.(R)}function te(R,D){++F.current,L.current?.abort(),V.current=!1,j(!1),O(null),P(null),R(D)}async function le(R){if(V.current)return;V.current=!0;const D=K.current,ve=++F.current,ke=new AbortController;L.current=ke,j(!0),O(null),P(null);const pe=()=>{const J=K.current;if(!q.current||ve!==F.current||p&&!T.current||!J||Object.keys(D).some(X=>D[X]!==J[X])||D.client&&!Qt(D.client))throw new U("export_cancelled",409)};try{const J=await mn({userId:D.userId,auth:g.getAccessToken,from:D.start,to:D.end,deviceId:D.deviceId,signal:ke.signal,assertCurrent:pe});pe(),await fn(J,R,{signal:ke.signal,assertCurrent:pe}),pe();const X=J.metadata.effective_range,Me=J.rows.length?a("cloud.export.success",{count:J.rows.length,from:X.from,to:X.to}):a("cloud.export.empty");P(X.from!==D.start||X.to!==D.end?`${Me} ${a("cloud.export.truncated",{from:X.from,to:X.to})}`:Me)}catch(J){q.current&&ve===F.current&&O(xn(J))}finally{ve===F.current&&(V.current=!1,q.current&&j(!1))}}const de="hover:!text-oai-black dark:hover:!text-oai-white hover:!bg-oai-gray-100 dark:hover:!bg-oai-gray-800 focus:!ring-oai-gray-500/40";let ue=null;return(p||_)&&(ue=e.jsxs("div",{id:ee,className:p?void 0:r?"w-full rounded-lg bg-oai-gray-50 p-4 dark:bg-oai-gray-950/50":"mt-2 border-l-2 border-oai-gray-200 pl-3 dark:border-oai-gray-700","aria-busy":w,children:[p?null:e.jsx("p",{className:"text-xs leading-5 text-oai-gray-600 dark:text-oai-gray-300",children:a("cloud.export.description")}),e.jsxs("div",{className:p?"space-y-4":"mt-3 flex flex-wrap items-end gap-3",children:[p?e.jsxs(ds,{open:$,onOpenChange:G,children:[e.jsxs(us,{disabled:w,"aria-label":a("trend.zoom.pick_range"),className:"inline-flex h-10 min-h-10 w-full items-center gap-2 rounded-md border border-oai-gray-300 bg-transparent px-3 text-sm text-oai-black transition-colors hover:bg-oai-gray-50 focus-visible:outline focus-visible:outline-2 focus-visible:outline-oai-gray-500 disabled:opacity-50 dark:border-oai-gray-700 dark:text-oai-white dark:hover:bg-oai-gray-800",children:[e.jsx(cs,{size:16,className:"shrink-0 text-oai-gray-500","aria-hidden":!0}),e.jsxs("span",{className:"flex-1 text-left tabular-nums",children:[k," → ",u]}),e.jsx(Le,{size:14,className:"shrink-0 text-oai-gray-500","aria-hidden":!0})]}),e.jsx(gs,{children:e.jsx(ms,{sideOffset:8,side:"bottom",align:"start",className:"z-[110]",children:e.jsx(ps,{className:"max-w-[calc(100vw-2rem)] rounded-xl border border-oai-gray-200 bg-white shadow-lg outline-none dark:border-oai-gray-700 dark:bg-oai-gray-900",children:e.jsx(ls,{from:k,to:u,numberOfMonths:Z,onApply:(R,D)=>{te(b,R),y(D),G(!1)},onCancel:()=>G(!1)})})})})]}):e.jsxs(e.Fragment,{children:[e.jsxs("label",{className:"min-w-0 text-xs text-oai-gray-700 dark:text-oai-gray-200",children:[a("cloud.export.from"),e.jsx("input",{type:"date",value:k,onChange:R=>te(b,R.target.value),className:`${p?"min-h-10 min-w-0 w-full ":""}mt-1 block rounded-md border border-oai-gray-300 bg-white px-2 py-1.5 text-sm text-oai-black focus:outline-none focus:ring-2 focus:ring-inset focus:ring-oai-gray-500/40 dark:border-oai-gray-700 dark:bg-oai-gray-900 dark:text-oai-white`})]}),e.jsxs("label",{className:"min-w-0 text-xs text-oai-gray-700 dark:text-oai-gray-200",children:[a("cloud.export.to"),e.jsx("input",{type:"date",value:u,onChange:R=>te(y,R.target.value),className:`${p?"min-h-10 min-w-0 w-full ":""}mt-1 block rounded-md border border-oai-gray-300 bg-white px-2 py-1.5 text-sm text-oai-black focus:outline-none focus:ring-2 focus:ring-inset focus:ring-oai-gray-500/40 dark:border-oai-gray-700 dark:bg-oai-gray-900 dark:text-oai-white`})]})]}),e.jsxs("div",{className:p?"flex justify-end gap-2":"flex gap-2",children:[e.jsx(I,{type:"button",variant:p?"secondary":"ghost",size:"sm",className:`${de} ${p?"!min-h-8 !h-8":""}`,disabled:w,onClick:()=>le("csv"),children:a("cloud.export.csv")}),e.jsx(I,{type:"button",variant:p?"secondary":"ghost",size:"sm",className:`${de} ${p?"!min-h-8 !h-8":""}`,disabled:w,onClick:()=>le("json"),children:a("cloud.export.json")})]})]}),w?e.jsx("p",{role:"status",className:"mt-2 text-xs text-oai-gray-600 dark:text-oai-gray-300",children:a("cloud.export.busy")}):null,E?e.jsx("p",{role:"alert",className:"mt-2 text-xs text-red-700 dark:text-red-300",children:E}):null,N?e.jsx("p",{role:"status",className:"mt-2 text-xs text-oai-gray-600 dark:text-oai-gray-300",children:N}):null]})),p?e.jsx(Ge,{open:_,onOpenChange:W,title:a("cloud.export.open"),icon:Ae,children:ue}):e.jsxs("section",{className:r&&!p?"tt-cloud-theme contents":"tt-cloud-theme","aria-label":a("cloud.export.open"),children:[e.jsxs(I,{type:"button",variant:"ghost",size:"sm",className:`${de} ${p?"!h-11 !w-full !justify-start !px-0 !text-oai-black dark:!text-oai-white active:!scale-100":r?"!h-10 !px-0":""}`,"aria-expanded":_,"aria-controls":ee,onClick:()=>f(R=>!R),children:[e.jsx(Ae,{className:`${p?"mr-3":"mr-2"} h-4 w-4 shrink-0`,"aria-hidden":"true"}),a("cloud.export.open"),p?e.jsx(Le,{size:16,className:`ml-auto shrink-0 transition-transform motion-reduce:transition-none ${_?"rotate-180":""}`,"aria-hidden":!0}):null]}),!p&&c&&ue?ut.createPortal(ue,c):ue]})}function yn({text:t,label:s}){const[n,i]=o.useState(!1);return e.jsxs(xs,{open:n,onOpenChange:i,children:[e.jsx(bs,{delay:0,closeOnClick:!1,"aria-label":s,onClick:()=>i(!0),className:"inline-flex size-8 shrink-0 items-center justify-center rounded-md text-oai-gray-400 transition-colors hover:bg-oai-gray-100 hover:text-oai-gray-700 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-gray-500/40 dark:hover:bg-oai-gray-800 dark:hover:text-oai-gray-200",children:e.jsx(yt,{size:14,"aria-hidden":!0})}),e.jsx(ys,{children:e.jsx(vs,{side:"bottom",sideOffset:6,className:"z-[110]",children:e.jsx(ks,{role:"tooltip",className:"max-w-[min(320px,calc(100vw-2rem))] rounded-lg border border-oai-gray-200 bg-white px-3 py-2 text-xs leading-5 text-oai-gray-600 shadow-lg dark:border-oai-gray-700 dark:bg-oai-gray-900 dark:text-oai-gray-300",children:t})})})]})}function vn(t){return typeof t!="string"||!t.trim()?a("cloud.devices.platform_unknown"):/^(mac|darwin)/i.test(t)?a("leaderboard.community.modal.platform.darwin"):/^win/i.test(t)?a("leaderboard.community.modal.platform.win32"):/^linux/i.test(t)?a("leaderboard.community.modal.platform.linux"):t}function kn(t,s){if(!t)return null;const n=t.status==="active"&&t.access_source==="gift";if(s&&Number.isFinite(Date.parse(s))){const i=t.status==="transition"?"cloud.membership.transition_until":t.status==="trial"?"cloud.membership.trial_until":t.status==="active"?n?"cloud.membership.gift_until":"cloud.membership.active_until":t.status==="expired"&&Date.parse(s)<=Date.now()?"cloud.membership.expired_on":null;if(i)return a(i,{date:B(s)})}return n?a("cloud.gift.membership_label"):sa(t.status)}function jn({auth:t,machineLimit:s,accountRevision:n,selfHosted:i=!1}){const[r,c]=o.useState(null),[m,l]=o.useState(null),[d,p]=o.useState(null),[h,g]=o.useState(!1),[v,S]=o.useState(null),x=o.useRef(!1),k=o.useRef(0),b=o.useRef(!0),u=t?.user?.id,y=t?.getAccessToken,C=o.useCallback(async()=>{const N=++k.current;try{let P;if(lt())try{const G=await na(),Z=await fetch("/functions/tokentracker-machine-id",{headers:G});Z.ok&&(P=(await Z.json())?.machineId)}catch{}const $=await ce("devices",{auth:y,params:P?{current_machine_id:P}:{}});N===k.current&&(c($),l(null))}catch(P){N===k.current&&l({...P,code:"billing_devices_unavailable"})}},[y,u]);o.useEffect(()=>(b.current=!0,C(),()=>{b.current=!1,k.current+=1}),[C,n]);const f=async N=>{if(!x.current){x.current=!0,g(!0),l(null),S(null);try{if(await ce("remove-device",{auth:y,body:{machine_id:N}}),!b.current)return;r?.machines?.find(P=>P.machine_id===N)?.is_current&&Ve(),p(null),await C()}catch(P){b.current&&l(P)}finally{x.current=!1,g(!1)}}},_=async N=>{if(!x.current){x.current=!0,g(!0),l(null),S(null);try{if(await ce("resume-device",{auth:y,body:{machine_id:N.machine_id}}),!b.current)return;N.is_current&&Ve(),S(a("cloud.devices.resumed")),await C()}catch(P){b.current&&l(P)}finally{x.current=!1,g(!1)}}},w=r?.machines||[],j=r?.machine_count??w.filter(N=>N.status!=="paused").length,E=r?.machine_limit??s,O=E==null||j<E;return e.jsxs("div",{children:[e.jsxs("div",{className:"mb-1 flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-1",children:[e.jsx("h3",{className:"text-sm font-semibold",children:a("cloud.devices.title")}),e.jsx(yn,{label:a("cloud.devices.detail"),text:a("cloud.devices.detail")})]}),e.jsx("span",{className:"text-xs text-oai-gray-500 dark:text-oai-gray-400 tabular-nums",children:r?E==null?a(i?"cloud.devices.unlimited_self_hosted":"cloud.devices.unlimited",{count:j}):a("cloud.devices.count",{count:j,limit:E}):m?a("cloud.devices.count_unknown"):a("cloud.catalog.loading")})]}),r?.over_machine_limit||E!=null&&E<j?e.jsx("div",{className:"mb-4",children:e.jsx(Q,{children:a("cloud.devices.over_limit")})}):null,m?e.jsx(Q,{error:m,onRetry:C,context:"account"}):null,v?e.jsx("div",{className:"mb-3",children:e.jsx(Q,{children:v})}):null,!m&&r&&w.length===0?e.jsx("p",{className:"text-sm text-oai-gray-500 dark:text-oai-gray-400",children:a("cloud.devices.empty")}):null,w.length!==0?e.jsx("ul",{className:"divide-y divide-oai-gray-200 dark:divide-oai-gray-800",children:w.map(N=>e.jsxs("li",{className:"py-1.5",children:[e.jsxs("div",{className:"grid grid-cols-[17px_minmax(0,1fr)_auto] items-center gap-x-3 gap-y-1",children:[e.jsx(Re,{size:17,className:"col-start-1 row-start-1 text-oai-gray-500 dark:text-oai-gray-400","aria-hidden":!0}),e.jsx("p",{title:N.name||a("cloud.devices.unnamed"),className:"col-start-2 row-start-1 min-w-0 truncate text-sm font-medium",children:N.name||a("cloud.devices.unnamed")}),e.jsxs("div",{className:"col-span-2 col-start-2 row-start-2 flex min-w-0 flex-wrap items-center gap-x-2 gap-y-1 text-xs text-oai-gray-500 dark:text-oai-gray-400 sm:col-span-1 sm:col-start-2",children:[e.jsx("span",{children:vn(N.platform)}),e.jsx("span",{"aria-hidden":!0,children:"·"}),e.jsx("span",{children:N.last_seen_at?a("cloud.devices.last_seen",{date:ia(N.last_seen_at)}):a("cloud.devices.last_seen_unknown")}),N.is_current?e.jsxs(e.Fragment,{children:[e.jsx("span",{"aria-hidden":!0,children:"·"}),e.jsx("span",{children:a("cloud.devices.current")})]}):null,N.status==="paused"?e.jsxs(e.Fragment,{children:[e.jsx("span",{"aria-hidden":!0,children:"·"}),e.jsx("span",{children:a("cloud.devices.paused")})]}):null]}),N.status==="paused"&&!O?e.jsx("p",{className:"col-start-2 row-start-3 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:a("cloud.devices.no_slot")}):null,e.jsxs(I,{variant:"ghost",size:"sm",className:"col-start-3 row-start-1 !min-h-10 !px-2 sm:row-span-2","aria-expanded":N.status!=="paused"?d===N.machine_id:void 0,"aria-controls":d===N.machine_id?`cloud-machine-confirm-${N.machine_id}`:void 0,onClick:()=>N.status==="paused"?_(N):p(P=>P===N.machine_id?null:N.machine_id),disabled:h||N.status==="paused"&&!O,children:[N.status==="paused"?e.jsx(hs,{size:14,className:"mr-1.5 shrink-0","aria-hidden":!0}):e.jsx(fs,{size:14,className:"mr-1.5 shrink-0","aria-hidden":!0}),N.status==="paused"?a("cloud.devices.resume"):a("cloud.devices.remove")]})]}),d===N.machine_id?e.jsxs("div",{id:`cloud-machine-confirm-${N.machine_id}`,className:"mt-3 rounded-lg bg-oai-gray-50 p-3 dark:bg-oai-gray-800",children:[e.jsx("p",{className:"text-xs leading-5",children:a("cloud.devices.remove_detail")}),e.jsxs("div",{className:"mt-3 flex gap-2",children:[e.jsx(I,{variant:"secondary",onClick:()=>f(N.machine_id),disabled:h,children:a("cloud.devices.confirm_remove")}),e.jsx(I,{variant:"ghost",onClick:()=>p(null),disabled:h,children:a("cloud.action.keep")})]})]}):null]},N.machine_id))}):null]})}function _n({recent:t,pendingOrders:s,conflictOrders:n,userId:i,payments:r=[],footerActions:c}){const m=mt(),[l,d]=o.useState(t?.order_id&&Ne.test(t.order_id)?t.order_id:""),[p,h]=o.useState(!1),[g,v]=o.useState(!1),S=o.useId(),x=o.useRef(null);o.useEffect(()=>{g&&x.current?.focus()},[g]);const k=new Set([...r.map(u=>u.order_id).filter(u=>typeof u=="string"),...(s||[]).filter(u=>u.status==="paid"||["paid","partially_refunded","refunded"].includes(u.payment_state)).map(u=>u.id)].map(u=>u.toLowerCase())),b=[...n||[],...(s||[]).filter(u=>u.retry_payment_conflict_at||!k.has(u.id.toLowerCase()))].filter((u,y,C)=>C.findIndex(f=>f.id===u.id)===y);return e.jsxs("div",{className:"mt-2 space-y-3",children:[t?.request_id&&!t.order_id?e.jsx(be,{to:`/billing/checkout?sku=${encodeURIComponent(t.sku)}`,className:"mt-3 inline-flex min-h-10 items-center text-sm text-oai-brand underline underline-offset-4",children:a("cloud.action.resume_purchase")}):null,b.length||r.length?e.jsxs("div",{className:"sm:grid sm:grid-cols-[minmax(0,1fr)_auto_minmax(7rem,auto)] sm:gap-x-4",children:[e.jsxs("div",{"aria-hidden":!0,className:"hidden gap-x-4 pb-1 text-xs text-oai-gray-500 dark:text-oai-gray-400 sm:col-span-3 sm:grid sm:grid-cols-subgrid",children:[e.jsx("span",{children:a("cloud.history.date")}),e.jsx("span",{className:"text-right",children:a("cloud.history.amount")}),e.jsx("span",{className:"text-right",children:a("cloud.history.status")})]}),e.jsxs("ul",{className:"divide-y divide-oai-gray-200 dark:divide-oai-gray-800 sm:col-span-3 sm:grid sm:grid-cols-subgrid",children:[b.map(u=>{const y=typeof u.created_at=="string"&&Number.isFinite(Date.parse(u.created_at))?B(u.created_at):null;let C=null;Number.isInteger(u.amount_cents)&&u.amount_cents>=0&&["USD","CNY"].includes(u.currency)&&(C=Oe(u.amount_cents,u.currency));const f=a(u.retry_payment_conflict_at?"cloud.action.review_duplicate_payment":"cloud.history.pending");return e.jsxs("li",{className:"grid grid-cols-[minmax(0,1fr)_auto] items-center gap-x-4 gap-y-1 py-3 sm:col-span-3 sm:grid-cols-subgrid",children:[e.jsx("p",{className:"col-start-1 row-start-1 text-sm tabular-nums",children:y||f}),e.jsx("p",{className:"col-start-2 row-start-1 text-right text-sm font-medium tabular-nums",children:C}),u.provider||y?e.jsxs("div",{className:"col-start-1 row-start-2 flex min-w-0 flex-wrap items-center gap-x-2 gap-y-1 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:[u.provider?e.jsx("span",{children:pt(u.provider)}):null,y?e.jsxs(e.Fragment,{children:[u.provider?e.jsx("span",{"aria-hidden":!0,children:"·"}):null,e.jsx("span",{children:f})]}):null]}):null,e.jsx(be,{to:`/billing/checkout?order=${encodeURIComponent(u.id)}`,onClick:_=>{u.retry_payment_conflict_at||_.button!==0||_.metaKey||_.ctrlKey||_.shiftKey||_.altKey||!Ne.test(u.id)||(_.preventDefault(),m(He({orderId:u.id,userId:i})))},className:"col-start-2 row-start-2 inline-flex min-h-10 items-center justify-end rounded-sm text-right text-sm underline-offset-4 hover:underline focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 sm:col-start-3 sm:row-span-2 sm:row-start-1 sm:self-start sm:items-start",children:e.jsx("span",{children:u.retry_payment_conflict_at?a("cloud.action.review_duplicate_payment"):a("cloud.action.resume_order")})})]},u.id)}),e.jsx(wn,{payments:r})]})]}):e.jsx(e.Fragment,{children:(!t?.request_id||t.order_id)&&e.jsx("p",{className:"py-2 text-sm text-oai-gray-500 dark:text-oai-gray-400",children:a("cloud.history.empty")})}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-x-4 gap-y-1",children:[e.jsx(I,{variant:"ghost",size:"sm",className:"!h-10 !px-0","aria-expanded":g,"aria-controls":`${S}-panel`,onClick:()=>v(u=>!u),children:a("cloud.restore.title")}),c]}),g?e.jsxs("div",{id:`${S}-panel`,className:"mt-2",children:[e.jsx("p",{className:"text-xs leading-5 text-oai-gray-500 dark:text-oai-gray-400",children:a("cloud.restore.detail")}),e.jsxs("form",{className:"mt-4",onSubmit:u=>{if(u.preventDefault(),!Ne.test(l.trim())){h(!0);return}const y=l.trim(),C=b.some(f=>f.id.toLowerCase()===y.toLowerCase()&&f.retry_payment_conflict_at);m(C?`/billing/checkout?order=${encodeURIComponent(y)}`:He({orderId:y,userId:i}))},children:[e.jsx("label",{htmlFor:`${S}-input`,className:"text-xs text-oai-gray-500 dark:text-oai-gray-400",children:a("cloud.checkout.order_id")}),e.jsxs("div",{className:"mt-2 flex flex-col gap-2 sm:flex-row",children:[e.jsx("input",{id:`${S}-input`,ref:x,value:l,onChange:u=>{d(u.target.value),h(!1)},placeholder:a("cloud.restore.placeholder"),className:"min-h-10 min-w-0 flex-1 rounded-md border border-oai-gray-300 bg-transparent px-3 text-sm outline-none focus:border-oai-brand focus:ring-2 focus:ring-inset focus:ring-oai-brand/30 dark:border-oai-gray-700","aria-invalid":p,"aria-describedby":p?`${S}-error`:void 0}),e.jsx(I,{type:"submit",variant:"secondary",children:a("cloud.action.restore")})]}),p?e.jsx("p",{id:`${S}-error`,role:"alert",className:"mt-2 text-xs text-red-600 dark:text-red-400",children:a("cloud.restore.invalid")}):null]})]}):null]})]})}function wn({payments:t}){return e.jsx(e.Fragment,{children:t.map(s=>e.jsxs("li",{className:"grid grid-cols-[minmax(0,1fr)_auto] items-center gap-x-4 gap-y-1 py-3 sm:col-span-3 sm:grid-cols-subgrid",children:[e.jsx("p",{className:"col-start-1 row-start-1 text-sm tabular-nums",children:B(s.paid_at)}),e.jsx("p",{className:"col-start-2 row-start-1 text-right text-sm font-medium tabular-nums",children:Oe(s.amount_cents,s.currency)}),e.jsxs("div",{className:"col-start-1 row-start-2 flex min-w-0 flex-wrap items-center gap-x-2 gap-y-1 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:[e.jsx("span",{children:pt(s.provider)}),e.jsx("span",{"aria-hidden":!0,children:"·"}),e.jsx("span",{children:a("cloud.history.term",{start:B(s.starts_at),end:B(s.ends_at)})})]}),e.jsx("p",{className:`col-start-2 row-start-2 text-right text-sm font-medium sm:col-start-3 sm:row-span-1 sm:row-start-1 sm:self-start ${s.refunded_cents>0?"text-amber-700 dark:text-amber-400":"text-oai-gray-600 dark:text-oai-gray-300"}`,children:s.refunded_cents>0?a("cloud.history.refunded",{amount:Oe(s.refunded_cents,s.currency)}):a("cloud.history.paid")})]},s.id))})}function Nn({showTitle:t=!0,heading:s,syncControl:n,active:i=!0}){const r=ea();return e.jsx(Sn,{showTitle:t,heading:s,syncControl:n,active:i,...r},r.auth?.signedIn?r.auth.user?.id:"signed-out")}function Sn({account:t,auth:s,loading:n,error:i,refresh:r,showTitle:c,heading:m,syncControl:l,active:d=!0}){const{openLoginModal:p}=ct(),[h,g]=o.useState(null),[v,S]=o.useState(null),[x,k]=o.useState(!1),[b,u]=o.useState(null),y=o.useRef(!1),C=o.useRef(!0);o.useEffect(()=>{d||g(null)},[d]),o.useEffect(()=>(C.current=!0,()=>{C.current=!1}),[]);const f=t?.membership,_=f?.status==="self_hosted"||f?.hosting_mode==="self_hosted",w=[...t?.conflict_orders||[],...t?.pending_orders||[]].some(L=>L.retry_payment_conflict_at),j=!_&&t?.subscriptions?.find(L=>["active","trialing","past_due","paused","canceling"].includes(L.status)),E=!_&&(j?j.provider==="waffo":t?.payments?.some(L=>L.provider==="waffo")),O=j&&!j.cancel_at_period_end&&j.status!=="canceling",N=O&&j.status!=="paused",P=j?.next_billed_at,$=P&&Number.isFinite(Date.parse(P));o.useEffect(()=>{b&&t&&!O&&(u(null),S(null))},[t,b,O]);const G=_?null:f?.status==="trial"?f.trial_ends_at:f?.status==="transition"?f.transition_ends_at:f?.expires_at,Z=async L=>{if(!y.current){y.current=!0,k(!0),S(null);try{await L()}catch(V){C.current&&S(V)}finally{y.current=!1,k(!1)}}},H=()=>Z(async()=>{const L=await ce("portal",{auth:s.getAccessToken,body:j?{subscription_id:j.provider_subscription_id}:{}});C.current&&await Ka(L.url||L.portal_url)}),ee=()=>Z(async()=>{await ce("cancel",{auth:s.getAccessToken,body:{subscription_id:b}}),C.current&&(u(null),await r())}),K=kn(f,G),F=E&&!j||f?.can_read_cloud||!_&&t?.gift_redemption_available===!0;return s?.signedIn?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("section",{"aria-label":a("cloud.membership.title"),className:"tt-cloud-theme space-y-3",children:[t?.environment==="sandbox"?e.jsx(Q,{children:a("cloud.catalog.sandbox")}):null,w?e.jsx(ta,{showBillingLink:!1}):null,e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex min-w-0 flex-wrap items-baseline gap-x-3 gap-y-2",children:[m?e.jsx("h2",{className:"shrink-0 !text-2xl font-semibold",children:m}):null,!m&&c?e.jsxs("h2",{className:"inline-flex items-center gap-2 text-base font-semibold",children:[e.jsx(fe,{size:18,className:"text-oai-gray-500 dark:text-oai-gray-400","aria-hidden":!0}),a("cloud.membership.title")]}):null,K?e.jsx("span",{className:"text-sm text-oai-gray-500 dark:text-oai-gray-400",children:K}):null]}),e.jsx(I,{onClick:r,variant:"ghost",size:"sm",className:"!size-10 shrink-0 !p-0",disabled:n,"aria-label":a("cloud.action.refresh_membership"),children:e.jsx(Te,{size:15,className:n?"motion-safe:animate-spin":void 0,"aria-hidden":!0})})]}),f?.status==="expired"?e.jsx("p",{className:"mt-3 max-w-2xl text-xs leading-5 text-oai-gray-500 dark:text-oai-gray-400",children:f.can_read_cloud?a("cloud.membership.read_only",{date:B(f.read_only_until)}):a("cloud.membership.expired_detail")}):null,f?e.jsx(aa,{userId:s.user?.id,membership:f,subscriptions:t?.subscriptions,className:"mt-3"}):null,!f&&n?e.jsx("p",{role:"status",className:"mt-3 text-sm text-oai-gray-500 dark:text-oai-gray-400",children:a("cloud.catalog.loading")}):null,j?e.jsx("div",{className:"mt-4 flex flex-wrap items-center justify-between gap-3",children:j?e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-x-3 gap-y-1",children:[e.jsx("p",{className:"text-xs leading-5 text-oai-gray-500 dark:text-oai-gray-400",children:j.status==="paused"?a("cloud.membership.renewal_paused"):j.status==="past_due"?a("cloud.membership.payment_due"):N?$?a("cloud.membership.renews",{date:B(P)}):a("cloud.membership.renewal_unknown"):a("cloud.membership.renewal_off")}),O?e.jsx(I,{"aria-expanded":!!b,"aria-controls":b?"cloud-cancel-confirm":void 0,onClick:()=>u(L=>L===j.provider_subscription_id?null:j.provider_subscription_id),variant:"ghost",size:"sm",className:"!h-10 !px-2",disabled:x,children:a("cloud.action.cancel_renewal")}):null]}):null}):null,b?e.jsxs("div",{id:"cloud-cancel-confirm",className:"mt-4 rounded-lg border border-oai-gray-200 p-4 dark:border-oai-gray-800",children:[e.jsx("p",{className:"text-sm leading-6",children:G?a("cloud.cancel.detail",{date:B(G)}):a("cloud.cancel.no_term")}),e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2",children:[e.jsx(I,{onClick:ee,variant:"secondary",disabled:x,children:a("cloud.cancel.confirm")}),e.jsx(I,{onClick:()=>u(null),variant:"ghost",disabled:x,children:a("cloud.action.keep")})]})]}):null,i?e.jsx("div",{className:"mt-4",children:e.jsx(Q,{error:i,onRetry:r,context:"account"})}):null,v&&h!=="billing"?e.jsx("div",{className:"mt-4",children:e.jsx(Q,{error:v,context:"account"})}):null]})]}),f?e.jsx(Se,{className:"tt-cloud-theme !rounded-lg",bodyClassName:"!py-3",children:e.jsx(jn,{auth:s,machineLimit:f.machine_limit,accountRevision:t,selfHosted:_})}):null,F||t&&!_||l?e.jsx(Se,{className:"tt-cloud-theme !rounded-lg",bodyClassName:"!py-2",children:e.jsxs("section",{"aria-label":a("cloud.membership.tools_title"),className:"divide-y divide-oai-gray-200 dark:divide-oai-gray-800",children:[_?null:j?e.jsxs("button",{type:"button",onClick:H,disabled:x,className:"inline-flex h-11 w-full items-center gap-3 rounded-md border-0 bg-transparent p-0 text-left text-sm font-medium text-oai-black transition-colors hover:bg-oai-gray-100 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-oai-gray-500 disabled:opacity-50 dark:text-oai-white dark:hover:bg-oai-gray-800",children:[e.jsx(fe,{size:16,className:"shrink-0","aria-hidden":!0}),e.jsx("span",{className:"min-w-0 flex-1",children:a("cloud.action.manage_subscription")}),e.jsx(tt,{size:16,className:"shrink-0 text-oai-gray-500 dark:text-oai-gray-400","aria-hidden":!0})]}):e.jsxs(be,{to:"/cloud",className:"inline-flex h-11 w-full items-center gap-3 rounded-md border-0 bg-transparent p-0 text-left text-sm font-medium text-oai-black transition-colors hover:bg-oai-gray-100 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-oai-gray-500 dark:text-oai-white dark:hover:bg-oai-gray-800",children:[e.jsx(fe,{size:16,className:"shrink-0","aria-hidden":!0}),e.jsx("span",{className:"min-w-0 flex-1",children:a("cloud.action.subscribe")}),e.jsx(dt,{size:16,className:"shrink-0 text-oai-gray-500 dark:text-oai-gray-400","aria-hidden":!0})]}),t&&!_?e.jsxs(Ge,{open:h==="billing",onOpenChange:L=>g(L?"billing":null),title:a("cloud.billing.title"),icon:Cs,wide:!0,children:[v?e.jsx("div",{className:"mb-3",children:e.jsx(Q,{error:v,context:"account"})}):null,e.jsx(_n,{userId:s.user?.id,recent:qa(s.user?.id),pendingOrders:t?.pending_orders,conflictOrders:t?.conflict_orders,payments:t.payments,footerActions:E&&!j?e.jsx("div",{className:"flex items-center gap-0.5",children:e.jsxs(I,{onClick:H,variant:"ghost",size:"sm",className:"!h-10 !px-0",disabled:x,children:[a("cloud.action.view_bills"),e.jsx(tt,{size:14,className:"ml-2","aria-hidden":!0})]})}):null})]}):null,f?.can_read_cloud?e.jsx(bn,{auth:s,layout:"settings-row",dialogOpen:h==="export",onDialogOpenChange:L=>g(L?"export":null)}):null,e.jsx(un,{account:t,auth:s,refresh:r,layout:"settings-row",dialogOpen:h==="redeem",onDialogOpenChange:L=>g(L?"redeem":null)}),l?e.jsx("section",{children:l}):null]})}):null]}):e.jsxs("div",{className:"space-y-4",children:[m?e.jsx("h2",{className:"shrink-0 !text-2xl font-semibold",children:m}):null,e.jsxs(Se,{className:"tt-cloud-theme",children:[!m&&c?e.jsx("h2",{className:"text-base font-semibold",children:a("cloud.membership.title")}):null,e.jsx("p",{className:`${!m&&c?"mt-2 ":""}text-sm leading-6 text-oai-gray-500 dark:text-oai-gray-400`,children:a("cloud.membership.signed_out")}),e.jsx("div",{className:"mt-4 flex flex-wrap items-center gap-2",children:e.jsx(I,{onClick:()=>p({subtitle:a("cloud.membership.signed_out")}),children:a("cloud.action.sign_in_continue")})})]})]})}function Cn({settings:t,active:s=!0}={}){return t?e.jsx(Lt,{settings:t,active:s}):e.jsx(En,{active:s})}function En({active:t}){const s=Ue();return e.jsx(Lt,{settings:s,active:t})}function Lt({settings:t,active:s}){return e.jsx(Nn,{showTitle:!1,heading:a("settings.section.cloud"),active:s,syncControl:t.showLocalCloudSync?e.jsx(Pn,{settings:t}):null})}function Pn({settings:t}){return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex min-h-11 items-center justify-between gap-3",children:[e.jsxs("span",{className:"inline-flex min-w-0 items-center gap-3 text-sm font-medium",children:[e.jsx(Te,{size:16,className:"shrink-0","aria-hidden":!0}),a("settings.account.cloudSync")]}),e.jsx("span",{className:"tt-cloud-theme tt-cloud-sync-control inline-flex","aria-busy":t.cloudSyncPending||void 0,children:e.jsx(z,{checked:t.cloudSyncOn,disabled:t.cloudSyncPending,onChange:()=>(t.cloudSyncOn?qe(t.userId):ra(t.userId,"sync"),t.handleCloudSyncToggle()),ariaLabel:a("settings.account.cloudSync")})})]}),t.cloudSyncOn&&t.cloudSyncPending?e.jsxs("p",{role:"status",className:"flex items-center gap-2 py-3 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:[e.jsx(js,{size:14,className:"motion-safe:animate-spin","aria-hidden":!0}),a("settings.account.cloudSyncPending")]}):null,t.cloudSyncOn&&t.cloudSyncError&&!t.cloudSyncPending?e.jsx("div",{className:"tt-cloud-theme py-3",children:e.jsx(Q,{role:"alert",onRetry:t.handleCloudSyncRetry,children:a("settings.account.cloudSyncError")})}):null,e.jsx(oa,{userId:t.userId,panel:"sync",localHost:!0,className:"py-3",onContinueLocal:()=>{qe(t.userId),t.cloudSyncOn&&t.handleCloudSyncDisable()}})]})}function On(){return[{value:"light",label:a("settings.appearance.theme.light"),Icon:ca},{value:"dark",label:a("settings.appearance.theme.dark"),Icon:da},{value:"system",label:a("settings.appearance.theme.system"),Icon:Re}]}function Ln(){return[{value:ma,label:a("settings.appearance.language.system")},{value:pa,label:a("settings.appearance.language.english")},{value:ha,label:a("settings.appearance.language.chinese")},{value:fa,label:a("settings.appearance.language.traditional_chinese")},{value:xa,label:a("settings.appearance.language.japanese")},{value:ba,label:a("settings.appearance.language.korean")},{value:ya,label:a("settings.appearance.language.german")}]}function An(t){if(!t)return null;try{const s=new Date(t);return Number.isNaN(s.getTime())?null:s.toLocaleString()}catch{return null}}function Tn(t,s){const n=a(`settings.appearance.currency.rate_source.${t}`),i=An(s),r=i?a("settings.appearance.currency.rate_updated",{when:i}):a("settings.appearance.currency.rate_never");return`${n} · ${r}`}function Rn({locale:t,setLocale:s}){const n=Ln();return e.jsx(Ie,{value:t,onValueChange:s,options:n,ariaLabel:a("settings.appearance.language.label"),className:"px-2.5 py-1.5 text-xs font-medium",leadingIcon:e.jsx(Os,{className:"h-3.5 w-3.5 text-oai-gray-500 dark:text-oai-gray-400","aria-hidden":!0})})}function In({currency:t,setCurrency:s}){const n=ua().map(i=>({value:i.code,label:a(i.labelKey)}));return e.jsx(Ie,{value:t,onValueChange:s,options:n,ariaLabel:a("settings.appearance.currency.label"),className:"px-3 py-1.5 text-xs font-medium"})}function Dn({currency:t,rate:s,rateSource:n,rateFetchedAt:i}){if(t===ga)return e.jsx(e.Fragment,{children:a("settings.appearance.currency.hint")});const r=Tn(n,i);return e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx("span",{children:`1 USD = ${s.toFixed(4)} ${t}`}),e.jsx("span",{role:"img","aria-label":r,title:r,className:"inline-flex h-4 w-4 cursor-help items-center justify-center text-oai-gray-400 hover:text-oai-gray-600 dark:text-oai-gray-500 dark:hover:text-oai-gray-300",children:e.jsx(yt,{className:"h-3.5 w-3.5","aria-hidden":!0})})]})}function Un(){const{theme:t,setTheme:s}=la(),{locale:n,setLocale:i}=ht(),{currency:r,rate:c,rateSource:m,rateFetchedAt:l,setCurrency:d}=_s(),{mode:p,setMode:h,unitSystem:g,setUnitSystem:v,grouping:S,setGrouping:x}=ws();return e.jsxs(se,{title:a("settings.section.appearance"),children:[e.jsx(A,{label:a("settings.appearance.theme.label"),hint:a("settings.appearance.theme.hint"),control:e.jsx(ne,{options:On(),value:t,onChange:s})}),e.jsx(A,{label:a("settings.appearance.language.label"),hint:a("settings.appearance.language.hint"),control:e.jsx(Rn,{locale:n,setLocale:i})}),e.jsx(A,{label:a("settings.appearance.currency.label"),hint:e.jsx(Dn,{currency:r,rate:c,rateSource:m,rateFetchedAt:l}),control:e.jsx(In,{currency:r,setCurrency:d})}),e.jsx(A,{label:a("settings.appearance.token_format.label"),hint:a("settings.appearance.token_format.hint"),control:e.jsx(ne,{options:[{value:we.COMPACT,label:a("settings.appearance.token_format.compact")},{value:we.FULL,label:a("settings.appearance.token_format.full")}],value:p,onChange:h})}),e.jsx(A,{label:a("settings.appearance.token_unit.label"),hint:a("settings.appearance.token_unit.hint"),control:e.jsx(ne,{disabled:p!==we.COMPACT,options:[{value:Ke.ENGLISH,label:a("settings.appearance.token_unit.english")},{value:Ke.CHINESE,label:a("settings.appearance.token_unit.chinese")}],value:g,onChange:v})}),e.jsx(A,{label:a("settings.appearance.token_grouping.label"),hint:a("settings.appearance.token_grouping.hint"),control:e.jsx(ne,{options:[{value:We.THOUSAND,label:a("settings.appearance.token_grouping.thousand")},{value:We.WAN,label:a("settings.appearance.token_grouping.wan")}],value:S,onChange:x})})]})}function Ce({labelKey:t}){return e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{children:a(t)}),e.jsx("span",{className:"px-1.5 py-0.5 text-[8px] font-semibold tracking-wider text-oai-gray-500 bg-oai-gray-100 dark:text-oai-gray-400 dark:bg-oai-gray-800/80 rounded uppercase scale-90 origin-left",children:a("qpd.card.badge")})]})}function Gn(){const{enabled:t,toggle:s}=$a(),{enabled:n,toggle:i}=Fa(),{available:r,settings:c,setSetting:m}=ye(),l=r&&!!c?.dynamicIslandSupported,d=!!c?.dynamicIslandEnabled;return e.jsxs(se,{title:a("settings.section.labs"),children:[l&&e.jsxs(e.Fragment,{children:[e.jsx(A,{label:e.jsx(Ce,{labelKey:"settings.labs.island.label"}),hint:a("settings.labs.island.hint"),control:e.jsx(z,{checked:d,onChange:()=>m("dynamicIslandEnabled",!d),ariaLabel:a("settings.labs.island.aria")})}),d&&e.jsx(A,{label:a("settings.labs.island_hide_menubar.label"),hint:a("settings.labs.island_hide_menubar.hint"),control:e.jsx(z,{checked:!!c?.hideMenuBarIcon,onChange:()=>m("hideMenuBarIcon",!c?.hideMenuBarIcon),ariaLabel:a("settings.labs.island_hide_menubar.aria")})})]}),e.jsx(A,{label:e.jsx(Ce,{labelKey:"settings.labs.qpd.label"}),hint:a("settings.labs.qpd.hint"),control:e.jsx(z,{checked:t,onChange:s,ariaLabel:a("settings.labs.qpd.aria")})}),e.jsx(A,{label:e.jsx(Ce,{labelKey:"settings.labs.sessions.label"}),hint:a("settings.labs.sessions.hint"),control:e.jsx(z,{checked:n,onChange:i,ariaLabel:a("settings.labs.sessions.aria")})})]})}function Mn(){const{available:t,settings:s,setSetting:n,runAction:i}=ye();if(!t)return null;const r=ft(),c=!!s?.launchAtLogin,m=s?.toastOnReset!==!1,l=s?.confettiOnReset!==!1,d=s?.launchAtLoginSupported!==!1,p=s?.autoUpdateEnabled!==!1,h=s?.updateStatus||null,g=!!s?.updateBusy,v=!!s?.isSyncing;return e.jsxs(se,{title:a("settings.section.menubar"),children:[r?null:e.jsxs(e.Fragment,{children:[e.jsx(A,{label:a("settings.menubar.appearance"),hint:a("settings.menubar.appearanceHint"),control:e.jsxs(be,{to:"/widgets",className:"inline-flex h-8 items-center gap-1.5 rounded-md border border-oai-gray-200 px-3 text-xs font-medium text-oai-gray-700 no-underline transition-colors hover:bg-oai-gray-100 dark:border-oai-gray-800 dark:text-oai-gray-300 dark:hover:bg-oai-gray-800",children:[a("settings.menubar.appearanceLink"),e.jsx(Ss,{className:"h-3.5 w-3.5","aria-hidden":!0})]})}),e.jsx(A,{label:a("settings.menubar.toastOnReset"),hint:a("settings.menubar.toastOnResetHint"),control:e.jsx(z,{checked:m,onChange:()=>n("toastOnReset",!m),ariaLabel:a("settings.menubar.toastOnReset")})}),e.jsx(A,{label:a("settings.menubar.confettiOnReset"),hint:a("settings.menubar.confettiOnResetHint"),control:e.jsx(z,{checked:l,onChange:()=>n("confettiOnReset",!l),ariaLabel:a("settings.menubar.confettiOnReset")})})]}),d?e.jsx(A,{label:a("settings.menubar.launchAtLogin"),hint:a("settings.menubar.launchAtLoginHint"),control:e.jsx(z,{checked:c,onChange:()=>n("launchAtLogin",!c),ariaLabel:a("settings.menubar.launchAtLogin")})}):null,e.jsx(A,{label:a("settings.menubar.syncNow"),hint:a("settings.menubar.syncNowHint"),control:e.jsxs("button",{type:"button",onClick:()=>i("syncNow"),disabled:v,className:"inline-flex h-8 items-center gap-1.5 rounded-md border border-oai-gray-200 px-3 text-xs font-medium text-oai-gray-700 transition-colors hover:bg-oai-gray-100 disabled:cursor-not-allowed disabled:opacity-50 dark:border-oai-gray-800 dark:text-oai-gray-300 dark:hover:bg-oai-gray-800",children:[e.jsx(Te,{className:ae("h-3.5 w-3.5",v&&"animate-spin"),"aria-hidden":!0}),v?a("settings.menubar.syncing"):a("settings.menubar.syncNow")]})}),e.jsx(A,{label:a("settings.menubar.autoUpdate"),hint:a("settings.menubar.autoUpdateHint"),control:e.jsx(z,{checked:p,onChange:()=>n("autoUpdateEnabled",!p),ariaLabel:a("settings.menubar.autoUpdate")})}),e.jsx(A,{label:a("settings.menubar.updates"),hint:h||void 0,control:e.jsxs("button",{type:"button",onClick:()=>i("checkForUpdates"),disabled:g,className:"inline-flex h-8 items-center gap-1.5 rounded-md border border-oai-gray-200 px-3 text-xs font-medium text-oai-gray-700 transition-colors hover:bg-oai-gray-100 disabled:cursor-not-allowed disabled:opacity-50 dark:border-oai-gray-800 dark:text-oai-gray-300 dark:hover:bg-oai-gray-800",children:[e.jsx(Ae,{className:"h-3.5 w-3.5","aria-hidden":!0}),a("settings.menubar.checkUpdates")]})})]})}function zn(t,s){function n(c){return c.replace(/^v/,"").split(".").map(Number)}const i=n(t),r=n(s);for(let c=0;c<Math.max(i.length,r.length);c++){const m=i[c]||0,l=r[c]||0;if(m<l)return!0;if(m>l)return!1}return!1}function $n(){const{available:t,settings:s,runAction:n}=ye(),i=t&&s?.version,r=s?.platform||"macos",[c,m]=Ee.useState(!1),[l,d]=Ee.useState({open:!1,latestVersion:"",htmlUrl:""}),{resolvedLocale:p}=ht(),h="1.3.8",g=async()=>{m(!0);try{const b=await fetch("https://api.github.com/repos/xiufengsun/TokenTracker/releases/latest");if(!b.ok)throw new Error("Failed to fetch");const u=await b.json(),y=u.tag_name;zn(h,y)?d({open:!0,latestVersion:y,htmlUrl:u.html_url}):Ye({title:a("settings.menubar.updates.upToDate")})}catch(b){console.error("Check updates failed:",b),Ye({title:a("settings.menubar.updates.failed")})}finally{m(!1)}},v=a("settings.menubar.updates.modalTitle"),S=a("settings.menubar.updates.modalDescription",{version:l.latestVersion}),x=a("settings.menubar.updates.modalConfirm"),k=a("settings.menubar.updates.modalCancel");return e.jsxs("div",{className:"mt-6 flex flex-col items-center justify-center gap-4 text-xs text-oai-gray-500 dark:text-oai-gray-500",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-center gap-2",children:[i?e.jsxs(e.Fragment,{children:[e.jsx("span",{children:r==="windows"?a("settings.menubar.updates.footerCore",{version:s.version}):a("settings.menubar.updates.footerCombined",{barVersion:s.version,coreVersion:h})}),e.jsx("span",{"aria-hidden":!0,children:"·"}),e.jsx("button",{type:"button",onClick:()=>n("openAbout"),className:"underline-offset-2 transition-colors hover:text-oai-gray-700 hover:underline dark:hover:text-oai-gray-300",children:"GitHub"}),e.jsx("span",{"aria-hidden":!0,children:"·"})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{children:a("settings.menubar.updates.footerCore",{version:h})}),e.jsx("span",{"aria-hidden":!0,children:"·"}),e.jsx("button",{type:"button",onClick:g,disabled:c,className:"underline-offset-2 transition-colors hover:text-oai-gray-700 hover:underline dark:hover:text-oai-gray-300 disabled:opacity-50",children:c?a("settings.menubar.updates.checking"):a("settings.menubar.checkUpdates")}),e.jsx("span",{"aria-hidden":!0,children:"·"})]}),e.jsxs("a",{href:va,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1.5 underline-offset-2 transition-colors hover:text-oai-gray-700 hover:underline dark:hover:text-oai-gray-300",children:[e.jsx(ka,{className:"h-3.5 w-3.5","aria-hidden":!0}),a("settings.footer.statusPage")]})]}),e.jsx(Ns,{open:l.open,title:v,description:S,confirmLabel:x,cancelLabel:k,onConfirm:()=>{window.open(l.htmlUrl,"_blank"),d(b=>({...b,open:!1}))},onCancel:()=>d(b=>({...b,open:!1}))})]})}const Fn=()=>[{value:"system",label:a("settings.network.mode.system")},{value:"manual",label:a("settings.network.mode.manual")},{value:"off",label:a("settings.network.mode.off")}],Bn=()=>[{value:"http",label:a("settings.network.protocol.http")},{value:"https",label:a("settings.network.protocol.https")},{value:"socks5",label:a("settings.network.protocol.socks5")}],st="w-full rounded-md border border-oai-gray-300 bg-transparent px-2.5 py-1.5 text-sm text-oai-black outline-none focus:border-oai-brand-500 focus:ring-1 focus:ring-inset focus:ring-oai-brand-500 dark:border-oai-gray-700 dark:text-white";function nt(t){const s={},n=String(t.host||"").trim();(!n||/:\/\//.test(n)||n.includes("/"))&&(s.host=a("settings.network.error.host"));const i=String(t.port??"").trim(),r=Number(i);return(!i||!/^\d+$/.test(i)||!Number.isInteger(r)||r<1||r>65535)&&(s.port=a("settings.network.error.port")),s}function Hn({proxySettings:t}){const{config:s,save:n,testConnection:i}=t,[r,c]=o.useState(()=>({mode:s.mode,protocol:s.protocol||"http",host:s.host||"",port:s.port||""})),[m,l]=o.useState({}),[d,p]=o.useState(!1),[h,g]=o.useState(""),[v,S]=o.useState(null),[x,k]=o.useState(!1),[b,u]=o.useState(null);o.useEffect(()=>{c({mode:s.mode,protocol:s.protocol||"http",host:s.host||"",port:s.port||""})},[s.mode,s.protocol,s.host,s.port]);const y=o.useMemo(()=>s.effective==="manual"?a("settings.network.effective.manual"):s.effective==="env"?a("settings.network.effective.env"):s.effective==="system"?a("settings.network.effective.system"):s.effective==="blocked"?a("settings.network.effective.blocked"):a("settings.network.effective.none"),[s.effective]),C=w=>{c(j=>({...j,...w})),l({}),g(""),S(null),u(null)},f=async()=>{if(r.mode==="manual"){const w=nt(r);if(Object.keys(w).length){l(w);return}}p(!0),g(""),S(null);try{await n(r),g("saved")}catch(w){g("error"),S(w)}finally{p(!1)}},_=async()=>{const w=nt(r);if(Object.keys(w).length){l(w);return}k(!0),u(null);try{const j=await i(r);u(j)}catch(j){u({ok:!1,error:j?.message||String(j)})}finally{k(!1)}};return e.jsxs(se,{title:a("settings.section.network"),subtitle:y,children:[s.applyError?e.jsx("p",{role:"alert",className:"mb-3 text-xs text-red-600 dark:text-red-400",children:a("settings.network.apply_error",{error:s.applyError})}):null,e.jsx(A,{label:a("settings.network.mode.label"),hint:a("settings.network.mode.hint"),control:e.jsx(ne,{options:Fn(),value:r.mode,onChange:w=>C({mode:w})})}),e.jsx(bt,{initial:!1,children:r.mode==="manual"?e.jsxs(xt.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},transition:{height:{duration:.28,ease:[.22,1,.36,1]},opacity:{duration:.2,ease:[.22,1,.36,1]}},style:{overflow:"hidden"},className:"divide-y divide-oai-gray-200/60 dark:divide-oai-gray-800/60",children:[e.jsx(A,{label:a("settings.network.protocol.label"),control:e.jsx(Ie,{value:r.protocol,onValueChange:w=>C({protocol:w}),options:Bn(),ariaLabel:a("settings.network.protocol.label"),className:"px-2.5 py-1.5 text-xs font-medium"})}),e.jsx(A,{label:a("settings.network.host.label"),hint:m.host,control:e.jsx("input",{type:"text",value:r.host,onChange:w=>C({host:w.target.value}),placeholder:a("settings.network.host.placeholder"),autoComplete:"off",spellCheck:!1,"aria-invalid":m.host?!0:void 0,"aria-label":a("settings.network.host.label"),className:st})}),e.jsx(A,{label:a("settings.network.port.label"),hint:m.port,control:e.jsx("input",{type:"text",inputMode:"numeric",value:r.port,onChange:w=>C({port:w.target.value}),placeholder:a("settings.network.port.placeholder"),autoComplete:"off",spellCheck:!1,"aria-invalid":m.port?!0:void 0,"aria-label":a("settings.network.port.label"),className:st})}),e.jsxs("div",{className:"flex flex-wrap items-center justify-end gap-2 py-3",children:[e.jsx("button",{type:"button",onClick:_,disabled:x||d,className:"rounded-md border border-oai-gray-200 px-3 py-1.5 text-xs font-medium text-oai-gray-700 transition-colors hover:bg-oai-gray-100 disabled:opacity-50 dark:border-oai-gray-800 dark:text-oai-gray-300 dark:hover:bg-oai-gray-800",children:x?a("settings.network.test.testing"):a("settings.network.test")}),e.jsx("button",{type:"button",onClick:f,disabled:d||x,className:"rounded-md bg-oai-brand-500 px-3 py-1.5 text-xs font-medium text-white transition-colors hover:bg-oai-brand-600 disabled:opacity-50",children:d?a("settings.network.saving"):a("settings.network.save")})]}),b?e.jsx("p",{className:"py-2 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:b.ok?a("settings.network.test.ok",{status:String(b.status??"")}):a("settings.network.test.fail",{error:b.error||""})}):null]},"manual-proxy-fields"):e.jsx("div",{className:"flex justify-end py-3",children:e.jsx("button",{type:"button",onClick:f,disabled:d,className:"rounded-md bg-oai-brand-500 px-3 py-1.5 text-xs font-medium text-white transition-colors hover:bg-oai-brand-600 disabled:opacity-50",children:d?a("settings.network.saving"):a("settings.network.save")})},"non-manual-save")}),h==="saved"?e.jsx("p",{className:"py-2 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:a("settings.network.saved")}):null,h==="error"?e.jsx("p",{role:"alert",className:"py-2 text-xs text-red-600 dark:text-red-400",children:v?.unprotected?a("settings.network.save_error_unprotected",{error:v?.message||String(v||"")}):a("settings.network.save_error",{error:v?.message||String(v||"")})}):null]})}const At="/functions/tokentracker-proxy-config",Vn="/functions/tokentracker-proxy-test",qn={mode:"system",protocol:"http",host:"",port:"",effective:"none",applyError:null};function Tt(t){return!t||typeof t.mode!="string"?null:{mode:t.mode,protocol:typeof t.protocol=="string"?t.protocol:"http",host:typeof t.host=="string"?t.host:"",port:t.port==null||t.port===0?"":String(t.port),effective:typeof t.effective=="string"?t.effective:"none",applyError:typeof t.applyError=="string"&&t.applyError.trim()?t.applyError:null}}async function Kn(){const t=await fetch(At,{method:"GET",headers:{Accept:"application/json"},cache:"no-store"});if(!t.ok)return null;const s=await t.json().catch(()=>null);return Tt(s)}async function it(){const{getLocalApiAuthHeaders:t}=await ja(async()=>{const{getLocalApiAuthHeaders:s}=await import("./__vite-browser-external-BXwSXUpN.js").then(n=>n.dY);return{getLocalApiAuthHeaders:s}},__vite__mapDeps([0,1]));return t()}function Wn(){const[t,s]=o.useState(!1),[n,i]=o.useState(!0),[r,c]=o.useState(qn);o.useEffect(()=>{if(!Va()){s(!1),i(!1);return}let d=!1;return(async()=>{try{const p=await Kn();if(d)return;if(!p){s(!1),i(!1);return}c(p),s(!0),i(!1)}catch{d||(s(!1),i(!1))}})(),()=>{d=!0}},[]);const m=o.useCallback(async d=>{const p=await it(),h=await fetch(At,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json",...p},cache:"no-store",body:JSON.stringify({mode:d.mode,protocol:d.protocol,host:d.host,port:d.port===""?0:Number(d.port)})}),g=await h.json().catch(()=>null);if(!h.ok){const S=g&&typeof g.error=="string"?g.error:`HTTP ${h.status}`;throw new Error(S)}const v=Tt(g);if(v&&c(v),g&&g.ok===!1){const S=g&&typeof g.applyError=="string"&&g.applyError||g&&typeof g.error=="string"&&g.error||`HTTP ${h.status}`,x=new Error(S);throw g.unprotected===!0&&(x.unprotected=!0),x}return v||g},[]),l=o.useCallback(async d=>{const p=await it(),h=await fetch(Vn,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json",...p},cache:"no-store",body:JSON.stringify({protocol:d.protocol,host:d.host,port:d.port===""?0:Number(d.port)})}),g=await h.json().catch(()=>null);if(!g||typeof g.ok!="boolean")throw new Error(g&&typeof g.error=="string"?g.error:`HTTP ${h.status}`);return g},[]);return{available:t,loading:n,config:r,save:m,testConnection:l}}const M={APPEARANCE:"appearance",NATIVE_APP:"native-app",NETWORK:"network",ACCOUNT:"account",CLOUD:"cloud",LIMITS:"limits",LABS:"labs"},Y={PERSONAL:"personal",APP:"app",DEVELOPER:"developer"};function Yn({prefs:t}){return e.jsx(ne,{options:[{value:Qe.USED,label:a("limits.settings.display_mode_used")},{value:Qe.REMAINING,label:a("limits.settings.display_mode_remaining")}],value:t.displayMode,onChange:t.setDisplayMode})}function Ri(){const t=Ue(),s=Ga(),{available:n,settings:i,setSetting:r}=ye(),c=Wn(),{available:m}=c,l=i?.toastOnReset!==!1,d=i?.confettiOnReset!==!1,p=ft()||i?.platform==="windows",[h,g]=_a(),v=mt(),S=h.get("section"),k=Object.values(M).includes(S)&&(S!==M.NATIVE_APP||n)&&(S!==M.NETWORK||m)?S:M.APPEARANCE,b=f=>{const _=new URLSearchParams(h);f===M.APPEARANCE?_.delete("section"):_.set("section",f),g(_,{replace:!0})},u=[{id:M.APPEARANCE,label:a("settings.section.appearance"),description:a("settings.section.appearance.description"),group:Y.PERSONAL,Icon:As,content:e.jsx(Un,{})},...n?[{id:M.NATIVE_APP,label:a("settings.section.menubar"),description:a("settings.section.menubar.description"),group:Y.APP,Icon:Re,content:e.jsx(Mn,{})}]:[],...m?[{id:M.NETWORK,label:a("settings.section.network"),description:a("settings.section.network.description"),group:Y.APP,Icon:wa,content:e.jsx(Hn,{proxySettings:c})}]:[],{id:M.ACCOUNT,label:a("settings.section.account"),description:a("settings.section.account.description"),group:Y.PERSONAL,Icon:Ts,content:e.jsx(nn,{settings:t})},{id:M.CLOUD,label:a("settings.section.cloud"),description:a("settings.section.cloud.description"),group:Y.PERSONAL,Icon:fe,content:e.jsx(Cn,{settings:t,active:k===M.CLOUD})},{id:M.LIMITS,label:a("settings.section.limits"),description:a("settings.section.limits.description"),group:Y.APP,Icon:Na,content:e.jsxs("div",{className:"space-y-4",children:[e.jsxs(se,{title:a("settings.section.limits"),children:[e.jsx(A,{label:a("limits.settings.display_mode_label"),control:e.jsx(Yn,{prefs:s})}),p?null:e.jsxs(e.Fragment,{children:[e.jsx(A,{label:a("settings.menubar.toastOnReset"),hint:a("settings.menubar.toastOnResetHint"),control:e.jsx(z,{checked:l,disabled:!n,onChange:()=>r("toastOnReset",!l),ariaLabel:a("settings.menubar.toastOnReset")})}),e.jsx(A,{label:a("settings.menubar.confettiOnReset"),hint:a("settings.menubar.confettiOnResetHint"),control:e.jsx(z,{checked:d,disabled:!n,onChange:()=>r("confettiOnReset",!d),ariaLabel:a("settings.menubar.confettiOnReset")})})]}),e.jsx(A,{label:a("settings.limits.showSubscriptions"),hint:a("settings.limits.showSubscriptionsHint"),control:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("button",{type:"button",onClick:()=>v("/limits?openSubscriptions=1"),"aria-label":a("limits.page.openSubscriptions"),title:a("limits.page.openSubscriptions"),className:"inline-flex h-7 w-7 items-center justify-center rounded-md border border-oai-gray-200 dark:border-oai-gray-700 bg-white dark:bg-oai-gray-900 text-oai-gray-500 dark:text-oai-gray-400 hover:bg-oai-gray-100 dark:hover:bg-oai-gray-800 hover:text-oai-black dark:hover:text-white transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand-500",children:e.jsx(Sa,{size:14,"aria-hidden":!0})}),e.jsx(z,{checked:s.showSubscriptions!==!1,onChange:()=>s.setShowSubscriptions(!s.showSubscriptions),ariaLabel:a("settings.limits.showSubscriptions")})]})})]}),e.jsx(se,{title:a("settings.limits.providers"),children:e.jsx(Gs,{prefs:s})})]})},{id:M.LABS,label:a("settings.section.labs"),description:a("settings.section.labs.description"),group:Y.DEVELOPER,Icon:Es,content:e.jsx(Gn,{})}],y=[{id:Y.PERSONAL,label:a("settings.nav.group.personal")},{id:Y.APP,label:a("settings.nav.group.app")},{id:Y.DEVELOPER,label:a("settings.nav.group.developer")}].map(f=>({...f,sections:u.filter(_=>_.group===f.id)})).filter(f=>f.sections.length>0);let C=u[0];for(const f of u)if(f.id===k){C=f;break}return e.jsx("div",{className:ae("flex flex-1 flex-col font-oai text-oai-black antialiased dark:text-oai-white",k===M.CLOUD&&"tt-cloud-settings"),children:e.jsx("main",{className:"flex-1 pb-12 pt-8 sm:pb-16 sm:pt-10",children:e.jsxs("div",{className:"mx-auto w-full max-w-5xl px-4 sm:px-6",children:[e.jsxs("div",{className:"mb-7 max-w-2xl",children:[e.jsx("h1",{className:"text-3xl font-semibold tracking-tight text-oai-black dark:text-white sm:text-4xl",children:a("settings.page.title")}),e.jsx("p",{className:"mt-2 text-sm leading-6 text-oai-gray-500 dark:text-oai-gray-400 sm:text-base",children:a("settings.page.subtitle")})]}),e.jsxs("div",{className:"tt-settings-sections grid min-w-0 gap-6 md:grid-cols-[11rem_minmax(0,1fr)] md:gap-8",children:[e.jsx("aside",{className:"min-w-0 rounded-xl border border-oai-gray-200 bg-oai-gray-50/70 p-2 dark:border-oai-gray-800 dark:bg-oai-gray-900/60 md:border-0 md:bg-transparent md:p-0 md:dark:bg-transparent",children:e.jsx("nav",{"aria-label":a("settings.page.title"),className:"flex gap-1 overflow-x-auto [scrollbar-width:none] [&::-webkit-scrollbar]:hidden md:sticky md:top-6 md:flex-col md:gap-4 md:overflow-visible",children:y.map(({id:f,label:_,sections:w})=>e.jsxs("div",{className:"flex shrink-0 gap-1 md:block",children:[e.jsx("div",{className:"hidden px-3 pb-1 text-[10px] font-semibold uppercase tracking-[0.16em] text-oai-gray-400 dark:text-oai-gray-500 md:block",children:_}),e.jsx("div",{className:"flex gap-1 md:flex-col",children:w.map(({id:j,label:E,Icon:O})=>{const N=k===j;return e.jsxs("button",{id:`settings-nav-${j}`,type:"button","aria-current":N?"page":void 0,"aria-controls":`settings-panel-${j}`,onClick:()=>b(j),className:ae("inline-flex min-h-10 min-w-max shrink-0 items-center gap-1.5 rounded-md px-2 py-2 text-left text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-oai-brand-500 md:w-full md:min-w-0 md:gap-2 md:px-3",N?"bg-oai-gray-100 text-oai-black dark:bg-oai-gray-800 dark:text-white":"text-oai-gray-500 hover:bg-oai-gray-50 hover:text-oai-gray-900 dark:text-oai-gray-400 dark:hover:bg-oai-gray-900 dark:hover:text-oai-gray-200"),children:[e.jsx(O,{className:ae("h-4 w-4 shrink-0",N?"text-oai-black dark:text-white":"text-oai-gray-400 dark:text-oai-gray-500"),"aria-hidden":!0}),e.jsx("span",{className:"truncate",children:E})]},j)})})]},f))})}),e.jsxs("div",{className:"min-w-0",children:[k!==M.CLOUD?e.jsxs("div",{className:"mb-4 border-b border-oai-gray-200 pb-4 dark:border-oai-gray-800",children:[e.jsx("h2",{className:"text-xl font-semibold tracking-tight text-oai-black dark:text-white",children:C.label}),e.jsx("p",{className:"mt-1 text-sm leading-5 text-oai-gray-500 dark:text-oai-gray-400",children:C.description})]}):null,u.map(({id:f,label:_,content:w})=>e.jsx("section",{id:`settings-panel-${f}`,"aria-labelledby":`settings-nav-${f}`,"aria-label":_,"data-settings-panel":f,hidden:k!==f,children:w},f)),e.jsx($n,{})]})]})]})})})}export{Ri as SettingsPage};
|