@hienlh/ppm 0.20.0 → 0.20.2
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/CHANGELOG.md +21 -0
- package/CLAUDE.md +1 -0
- package/assets/skills/ppm/SKILL.md +1 -1
- package/assets/skills/ppm/references/http-api.md +5 -1
- package/dist/web/assets/accounts-settings-section-DzDmIsPe.js +1 -0
- package/dist/web/assets/{ai-resource-editor-BgYIPGVP.js → ai-resource-editor-D7C9wmwA.js} +1 -1
- package/dist/web/assets/{ai-settings-section-iBRCQvBR.js → ai-settings-section-BW5a07-Z.js} +1 -1
- package/dist/web/assets/{ai-settings-section-Cywmtnps.js → ai-settings-section-DZuwllLy.js} +1 -1
- package/dist/web/assets/{appearance-settings-section-mhu9T6Fk.js → appearance-settings-section-RfH2N1rj.js} +1 -1
- package/dist/web/assets/chat-tab-Bz0pk0_E.js +15 -0
- package/dist/web/assets/{code-editor-Cv_pzHo7.js → code-editor-C4o1SyuO.js} +2 -2
- package/dist/web/assets/{conflict-editor-BnWaMSEa.js → conflict-editor-Dk65mBIe.js} +1 -1
- package/dist/web/assets/{csv-preview-DG4YAabr.js → csv-preview-DENi3CFz.js} +1 -1
- package/dist/web/assets/{database-viewer-B-wA2qT-.js → database-viewer-BiBC7ulB.js} +1 -1
- package/dist/web/assets/{diff-viewer-DRtzdfXk.js → diff-viewer-CSvZJHak.js} +1 -1
- package/dist/web/assets/{edit-diff-preview-6tzdk7Pn.js → edit-diff-preview-xdDQvPhs.js} +1 -1
- package/dist/web/assets/{explorer-body-uh8oJp6J.js → explorer-body-QXS0h4AF.js} +1 -1
- package/dist/web/assets/{explorer-window-content-DLn_4egF.js → explorer-window-content-CQgqoRsj.js} +1 -1
- package/dist/web/assets/{extension-manager-section-C_ZGYvWf.js → extension-manager-section-CyC7wX35.js} +1 -1
- package/dist/web/assets/{extension-webview-DbFWxJpj.js → extension-webview-Da8SIlRa.js} +1 -1
- package/dist/web/assets/{files-settings-section-BrUbJglA.js → files-settings-section-D8cebM51.js} +1 -1
- package/dist/web/assets/{general-settings-section-B9ZPZVso.js → general-settings-section-1HVTvlIw.js} +1 -1
- package/dist/web/assets/{git-log-panel-C0jnhmgC.js → git-log-panel-C7a4rp8f.js} +1 -1
- package/dist/web/assets/{glide-data-grid-CZVKIum-.js → glide-data-grid-BT9p_4AN.js} +1 -1
- package/dist/web/assets/{group-chat-tab-DnPtmbPc.js → group-chat-tab-BUHGnUyW.js} +1 -1
- package/dist/web/assets/index-CuYtJ5xF.css +2 -0
- package/dist/web/assets/{index-CHQAPZIX.js → index-kGmcC9cb.js} +5 -5
- package/dist/web/assets/{jira-watcher-section-Bjldyhru.js → jira-watcher-section-BxzwW4uQ.js} +1 -1
- package/dist/web/assets/{keybindings-store-DBVXZKp8.js → keybindings-store-DjJum4OS.js} +1 -1
- package/dist/web/assets/{keyboard-shortcuts-section-D7jaCPrv.js → keyboard-shortcuts-section-DDKG3BU1.js} +1 -1
- package/dist/web/assets/{markdown-renderer-B4B5oxQS.js → markdown-renderer-dHeak2mE.js} +2 -2
- package/dist/web/assets/{markdown-renderer-DwHh-jd_.js → markdown-renderer-iBw1fCI_.js} +1 -1
- package/dist/web/assets/{mobile-explorer-sheet-JJxZYWkV.js → mobile-explorer-sheet-CzL8SLtz.js} +1 -1
- package/dist/web/assets/{notification-store-CCWNUHsS.js → notification-store-DVi6Ds71.js} +1 -1
- package/dist/web/assets/{notifications-settings-section-DbbX7-Qp.js → notifications-settings-section-shQ-ugKh.js} +1 -1
- package/dist/web/assets/{pdf-preview-DxNjWa1v.js → pdf-preview-DB26KSzm.js} +1 -1
- package/dist/web/assets/{postgres-viewer-BScvk5ev.js → postgres-viewer-CJe2meyF.js} +1 -1
- package/dist/web/assets/{ppmbot-settings-section-jFA9Ncgo.js → ppmbot-settings-section-Ba4c9AI9.js} +1 -1
- package/dist/web/assets/{process-table-BexeYWQm.js → process-table-PXwLsMuG.js} +1 -1
- package/dist/web/assets/{proxy-settings-section-C_seKq56.js → proxy-settings-section-BHBhK6HC.js} +1 -1
- package/dist/web/assets/{query-audit-section-BWXJmPDV.js → query-audit-section-BD5ZVqDz.js} +1 -1
- package/dist/web/assets/{remote-desktop-mobile-sheet-B--PeL5i.js → remote-desktop-mobile-sheet-Di4QG8VX.js} +2 -2
- package/dist/web/assets/{remote-desktop-mobile-view-jgn8nmQa.js → remote-desktop-mobile-view-DzoZvAqc.js} +1 -1
- package/dist/web/assets/{remote-desktop-readiness-gate-CjDth-W_.js → remote-desktop-readiness-gate-CHO-KJ9Z.js} +1 -1
- package/dist/web/assets/{remote-desktop-window-content-CrHAUA03.js → remote-desktop-window-content-X324gYbW.js} +1 -1
- package/dist/web/assets/{schedules-settings-section-DMFn3mYL.js → schedules-settings-section-a4-h6THc.js} +1 -1
- package/dist/web/assets/{settings-body-Dz2vPTEP.js → settings-body-Fq7BVDw2.js} +2 -2
- package/dist/web/assets/{settings-tab-B5QbsvS4.js → settings-tab-CVLQy-ie.js} +1 -1
- package/dist/web/assets/{settings-window-content-iM2bPoX5.js → settings-window-content-Bi7M0iaZ.js} +1 -1
- package/dist/web/assets/{sql-query-editor-C0mGgLfX.js → sql-query-editor-D1r265fl.js} +1 -1
- package/dist/web/assets/{sqlite-viewer-Bs3RKf1X.js → sqlite-viewer-DHkIotRl.js} +1 -1
- package/dist/web/assets/{system-monitor-body-DvUmEdNe.js → system-monitor-body-y6VUkYTL.js} +2 -2
- package/dist/web/assets/{system-monitor-tab-CHZ5F_ZE.js → system-monitor-tab-DRAOejhk.js} +1 -1
- package/dist/web/assets/{system-monitor-window-content-DjzqoeCN.js → system-monitor-window-content-B5i57xHD.js} +1 -1
- package/dist/web/assets/{tab-host-window-content-DKeAr5mD.js → tab-host-window-content-SkyPFFlc.js} +1 -1
- package/dist/web/assets/{team-member-sheet-Cl9ZB3dl.js → team-member-sheet-BB63u-Lf.js} +2 -2
- package/dist/web/assets/{team-member-window-content-DfP7WdFD.js → team-member-window-content-D6tVTXuV.js} +1 -1
- package/dist/web/assets/{terminal-tab-J1Fqa_rm.js → terminal-tab-BYaHAkI5.js} +1 -1
- package/dist/web/assets/{tool-cards-DQghSuKX.js → tool-cards-DRJu20sL.js} +3 -3
- package/dist/web/assets/use-accounts-data-Ba1_uvEE.js +1 -0
- package/dist/web/assets/{use-monaco-theme-aa4-wjKQ.js → use-monaco-theme-Uakgj3hJ.js} +1 -1
- package/dist/web/assets/{use-remote-desktop-display-choice-B-TpQ-Ua.js → use-remote-desktop-display-choice-Cd3Xalca.js} +1 -1
- package/dist/web/assets/{use-websocket-BBslmv3D.js → use-websocket-BC_EGf5q.js} +1 -1
- package/dist/web/assets/{video-preview-Bd0lcK3d.js → video-preview-BUb43zWb.js} +1 -1
- package/dist/web/index.html +2 -2
- package/dist/web/sw.js +1 -1
- package/docs/deployment-guide.md +10 -0
- package/package.json +1 -1
- package/src/providers/codex-app-server/codex-event-mapper.ts +11 -0
- package/src/providers/codex-app-server/codex-history.ts +118 -45
- package/src/providers/codex-app-server/codex-provider.ts +277 -15
- package/src/providers/codex-app-server/codex-rollout-header.ts +99 -0
- package/src/providers/codex-app-server/codex-rollout-items.ts +6 -0
- package/src/providers/codex-app-server/codex-rollout-transfer.ts +58 -0
- package/src/providers/codex-app-server/codex-subagent-thread.ts +103 -0
- package/src/providers/codex-app-server/codex-usage-limit.ts +69 -0
- package/src/providers/codex-app-server/codex-usage-parser.ts +31 -14
- package/src/server/routes/chat.ts +23 -2
- package/src/server/routes/codex-accounts.ts +32 -3
- package/src/server/ws/chat.ts +15 -11
- package/src/services/codex-account-cooldown.ts +56 -0
- package/src/services/codex-account-login.ts +109 -34
- package/src/services/codex-account.service.ts +56 -10
- package/src/services/codex-login-callback.ts +57 -0
- package/src/web/components/chat/chat-tab.tsx +8 -2
- package/src/web/components/chat/codex-usage-panel.tsx +129 -165
- package/src/web/components/chat/edit-diff-preview.tsx +14 -7
- package/src/web/components/chat/usage-badge.tsx +38 -129
- package/src/web/components/chat/usage-panel-shell.tsx +153 -0
- package/src/web/components/settings/accounts/account-card.tsx +20 -3
- package/src/web/components/settings/accounts/codex-accounts-section.tsx +9 -2
- package/src/web/components/settings/accounts/codex-add-account-dialog.tsx +47 -27
- package/src/web/components/settings/accounts/codex-usage-rows.tsx +17 -6
- package/src/web/components/settings/accounts/use-codex-accounts.ts +90 -44
- package/src/web/components/shared/markdown-code-block.tsx +10 -5
- package/src/web/components/ui/tooltip.tsx +14 -1
- package/src/web/hooks/use-usage.ts +13 -1
- package/dist/web/assets/accounts-settings-section-BQyru31C.js +0 -1
- package/dist/web/assets/chat-tab-Bs9OD6ss.js +0 -15
- package/dist/web/assets/index-CoaVwAF6.css +0 -2
- package/dist/web/assets/use-accounts-data-KWcMgRlc.js +0 -1
|
@@ -1,13 +1,4 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* State and requests for the Codex accounts pane.
|
|
3
|
-
*
|
|
4
|
-
* Split from the pane the way `use-accounts-data` is on the Claude side, so both panes are
|
|
5
|
-
* render-only and the two providers stay comparable.
|
|
6
|
-
*
|
|
7
|
-
* The device-code login is the reason the cleanup here matters: it holds a server-side
|
|
8
|
-
* app-server until it resolves, so leaving the pane has to release it rather than let it age
|
|
9
|
-
* out. That cleanup belongs to the pane's lifetime, not to a dialog being closed.
|
|
10
|
-
*/
|
|
1
|
+
/** State and requests for the Codex accounts pane, including cancellable login flows. */
|
|
11
2
|
|
|
12
3
|
import { useCallback, useEffect, useRef, useState } from "react";
|
|
13
4
|
import { api, getAuthToken } from "@/lib/api-client";
|
|
@@ -28,6 +19,8 @@ export interface Usage {
|
|
|
28
19
|
weekly?: LimitBucket;
|
|
29
20
|
}
|
|
30
21
|
interface DevicePending { id: string; userCode: string; verificationUrl: string }
|
|
22
|
+
interface BrowserPending { id: string; authUrl: string }
|
|
23
|
+
type LoginMethod = "device" | "browser";
|
|
31
24
|
type DeviceStatus = { state: "pending" } | { state: "done" } | { state: "error"; error: string };
|
|
32
25
|
|
|
33
26
|
/** Gap between status polls. Each poll answers immediately, so a request lost to
|
|
@@ -48,13 +41,23 @@ export function useCodexAccounts(onDone: () => void) {
|
|
|
48
41
|
const [err, setErr] = useState<string | null>(null);
|
|
49
42
|
const [device, setDevice] = useState<DevicePending | null>(null);
|
|
50
43
|
const [deviceWaiting, setDeviceWaiting] = useState(false);
|
|
44
|
+
const [browser, setBrowser] = useState<BrowserPending | null>(null);
|
|
45
|
+
const [loginStarting, setLoginStarting] = useState(false);
|
|
46
|
+
const [callbackUrl, setCallbackUrl] = useState("");
|
|
47
|
+
const [submittingCallback, setSubmittingCallback] = useState(false);
|
|
51
48
|
const [backupPassword, setBackupPassword] = useState("");
|
|
52
49
|
const [exporting, setExporting] = useState(false);
|
|
53
50
|
const [importing, setImporting] = useState(false);
|
|
54
51
|
const [msg, setMsg] = useState<string | null>(null);
|
|
55
52
|
const stopPollRef = useRef<(() => void) | null>(null);
|
|
56
53
|
/** Id of the login still owed a result, so unmount can release it. */
|
|
57
|
-
const
|
|
54
|
+
const pendingLoginRef = useRef<{ id: string; method: LoginMethod } | null>(null);
|
|
55
|
+
const loginGenerationRef = useRef(0);
|
|
56
|
+
const startingRef = useRef(false);
|
|
57
|
+
const addingRef = useRef(false);
|
|
58
|
+
const submittingRef = useRef(false);
|
|
59
|
+
const onDoneRef = useRef(onDone);
|
|
60
|
+
onDoneRef.current = onDone;
|
|
58
61
|
|
|
59
62
|
const load = useCallback(async () => {
|
|
60
63
|
setLoading(true);
|
|
@@ -68,53 +71,95 @@ export function useCodexAccounts(onDone: () => void) {
|
|
|
68
71
|
useEffect(() => { load(); }, [load]);
|
|
69
72
|
|
|
70
73
|
const addApiKey = async () => {
|
|
71
|
-
if (!apiKey.trim()) return;
|
|
74
|
+
if (!apiKey.trim() || addingRef.current || startingRef.current || pendingLoginRef.current) return;
|
|
75
|
+
addingRef.current = true;
|
|
72
76
|
setAdding(true); setErr(null);
|
|
73
77
|
try {
|
|
74
78
|
await api.post("/api/codex-accounts/api-key", { apiKey: apiKey.trim(), label: label.trim() || undefined });
|
|
75
79
|
setApiKey(""); setLabel(""); onDone(); await load();
|
|
76
|
-
} catch (e) { setErr((e as Error).message); } finally { setAdding(false); }
|
|
80
|
+
} catch (e) { setErr((e as Error).message); } finally { addingRef.current = false; setAdding(false); }
|
|
77
81
|
};
|
|
78
82
|
|
|
79
|
-
const
|
|
80
|
-
|
|
83
|
+
const releaseLogin = useCallback(() => {
|
|
84
|
+
loginGenerationRef.current += 1;
|
|
85
|
+
startingRef.current = false;
|
|
86
|
+
submittingRef.current = false;
|
|
87
|
+
stopPollRef.current?.();
|
|
88
|
+
stopPollRef.current = null;
|
|
89
|
+
const pending = pendingLoginRef.current;
|
|
90
|
+
pendingLoginRef.current = null;
|
|
91
|
+
if (pending) void api.del(`/api/codex-accounts/${pending.method}-login/${pending.id}`).catch(() => {});
|
|
92
|
+
}, []);
|
|
93
|
+
|
|
94
|
+
const cancelLogin = useCallback(() => {
|
|
95
|
+
releaseLogin();
|
|
96
|
+
setDevice(null); setDeviceWaiting(false); setBrowser(null);
|
|
97
|
+
setLoginStarting(false); setCallbackUrl(""); setSubmittingCallback(false);
|
|
98
|
+
}, [releaseLogin]);
|
|
99
|
+
|
|
100
|
+
const pollLogin = useCallback((id: string, method: LoginMethod) => {
|
|
101
|
+
const deadline = Date.now() + (method === "browser" ? 610_000 : DEVICE_POLL_DEADLINE_MS);
|
|
81
102
|
let stopped = false;
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
stopped = true; stopPollRef.current = null; devicePendingIdRef.current = null;
|
|
85
|
-
if (message) setErr(message);
|
|
86
|
-
setDevice(null); setDeviceWaiting(false);
|
|
87
|
-
};
|
|
103
|
+
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
104
|
+
stopPollRef.current = () => { stopped = true; clearTimeout(timer); };
|
|
88
105
|
const tick = async () => {
|
|
89
106
|
if (stopped) return;
|
|
90
|
-
let
|
|
91
|
-
//
|
|
92
|
-
|
|
93
|
-
try { s = await api.get<DeviceStatus>(`/api/codex-accounts/device-login/${id}/status`); } catch { /* retry */ }
|
|
107
|
+
let status: DeviceStatus | null = null;
|
|
108
|
+
// Transient network failures must not discard an authorization in progress.
|
|
109
|
+
try { status = await api.get<DeviceStatus>(`/api/codex-accounts/${method}-login/${id}/status`); } catch { /* retry */ }
|
|
94
110
|
if (stopped) return;
|
|
95
|
-
if (
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
111
|
+
if (status?.state === "done") {
|
|
112
|
+
cancelLogin(); setLabel(""); onDoneRef.current(); await load(); return;
|
|
113
|
+
}
|
|
114
|
+
if (status?.state === "error" || Date.now() > deadline) {
|
|
115
|
+
cancelLogin();
|
|
116
|
+
setErr(status?.state === "error" ? status.error : `${method === "browser" ? "Browser" : "Device"} login timed out.`);
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
timer = setTimeout(tick, DEVICE_POLL_MS);
|
|
99
120
|
};
|
|
100
121
|
void tick();
|
|
101
|
-
}, [load]);
|
|
122
|
+
}, [cancelLogin, load]);
|
|
102
123
|
|
|
103
|
-
|
|
104
|
-
// server-side app-server instead of leaving it to age out.
|
|
105
|
-
useEffect(() => () => {
|
|
106
|
-
stopPollRef.current?.();
|
|
107
|
-
const id = devicePendingIdRef.current;
|
|
108
|
-
if (id) api.del(`/api/codex-accounts/device-login/${id}`).catch(() => {});
|
|
109
|
-
}, []);
|
|
124
|
+
useEffect(() => releaseLogin, [releaseLogin]);
|
|
110
125
|
|
|
111
|
-
const
|
|
112
|
-
|
|
126
|
+
const startLogin = async (method: LoginMethod) => {
|
|
127
|
+
if (startingRef.current || pendingLoginRef.current || addingRef.current) return;
|
|
128
|
+
startingRef.current = true;
|
|
129
|
+
const generation = ++loginGenerationRef.current;
|
|
130
|
+
setLoginStarting(true); setErr(null);
|
|
113
131
|
try {
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
132
|
+
const result = await api.post<DevicePending | BrowserPending>(`/api/codex-accounts/${method}-login`, { label: label.trim() || undefined });
|
|
133
|
+
// Closing the dialog while startup is in flight still owes the server a cancel.
|
|
134
|
+
if (generation !== loginGenerationRef.current) {
|
|
135
|
+
void api.del(`/api/codex-accounts/${method}-login/${result.id}`).catch(() => {});
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
pendingLoginRef.current = { id: result.id, method };
|
|
139
|
+
if (method === "device") { setDevice(result as DevicePending); setDeviceWaiting(true); }
|
|
140
|
+
else setBrowser(result as BrowserPending);
|
|
141
|
+
pollLogin(result.id, method);
|
|
142
|
+
} catch (e) {
|
|
143
|
+
if (generation === loginGenerationRef.current) setErr((e as Error).message);
|
|
144
|
+
} finally {
|
|
145
|
+
if (generation === loginGenerationRef.current) { startingRef.current = false; setLoginStarting(false); }
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
const submitCallback = async () => {
|
|
150
|
+
const pending = pendingLoginRef.current;
|
|
151
|
+
if (pending?.method !== "browser" || !callbackUrl.trim() || submittingRef.current) return;
|
|
152
|
+
const generation = loginGenerationRef.current;
|
|
153
|
+
submittingRef.current = true; setSubmittingCallback(true); setErr(null);
|
|
154
|
+
const submittedUrl = callbackUrl.trim();
|
|
155
|
+
setCallbackUrl("");
|
|
156
|
+
try {
|
|
157
|
+
await api.post(`/api/codex-accounts/browser-login/${pending.id}/callback`, { callbackUrl: submittedUrl });
|
|
158
|
+
} catch (e) {
|
|
159
|
+
if (generation === loginGenerationRef.current) setErr((e as Error).message);
|
|
160
|
+
} finally {
|
|
161
|
+
if (generation === loginGenerationRef.current) { submittingRef.current = false; setSubmittingCallback(false); }
|
|
162
|
+
}
|
|
118
163
|
};
|
|
119
164
|
|
|
120
165
|
const remove = async (id: string) => { await api.del(`/api/codex-accounts/${id}`); await load(); };
|
|
@@ -179,6 +224,7 @@ export function useCodexAccounts(onDone: () => void) {
|
|
|
179
224
|
err, setErr, device, deviceWaiting, backupPassword, setBackupPassword,
|
|
180
225
|
exporting, importing, msg, setMsg,
|
|
181
226
|
toggling,
|
|
182
|
-
load, addApiKey, startDevice
|
|
227
|
+
load, addApiKey, startDevice: () => startLogin("device"), startBrowser: () => startLogin("browser"),
|
|
228
|
+
browser, loginStarting, callbackUrl, setCallbackUrl, submittingCallback, submitCallback, cancelLogin, remove, toggle, changeStrategy, doExport, doImport,
|
|
183
229
|
};
|
|
184
230
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useState, useEffect, useRef, type ReactNode } from "react";
|
|
1
|
+
import { useState, useEffect, useMemo, useRef, type ReactNode } from "react";
|
|
2
2
|
import { useMdContext, FILE_EXT_RE, GLOB_CHARS_RE } from "./markdown-context";
|
|
3
3
|
import { highlightToHtml, highlightSync, getActiveShikiTheme } from "@/theme/adapters/shiki-adapter";
|
|
4
4
|
import { copyToClipboard } from "@/lib/clipboard";
|
|
@@ -80,11 +80,14 @@ export function MdPre({ children, node, ...rest }: any) {
|
|
|
80
80
|
// Highlight once the block is done streaming; render raw code until then to
|
|
81
81
|
// avoid re-highlighting on every token (and Shiki being async).
|
|
82
82
|
const shikiHtml = useShikiHtml(text, lang, !isStreaming);
|
|
83
|
+
// Stable object: React 19 re-sets innerHTML whenever this prop's identity changes, which
|
|
84
|
+
// would rebuild the highlighted subtree on every re-render of the surrounding message.
|
|
85
|
+
const shikiProp = useMemo(() => (shikiHtml ? { __html: shikiHtml } : null), [shikiHtml]);
|
|
83
86
|
|
|
84
87
|
return (
|
|
85
88
|
<div className="relative group">
|
|
86
|
-
{
|
|
87
|
-
? <div className="shiki-block" dangerouslySetInnerHTML={
|
|
89
|
+
{shikiProp
|
|
90
|
+
? <div className="shiki-block" dangerouslySetInnerHTML={shikiProp} />
|
|
88
91
|
: <pre {...rest}>{children}</pre>}
|
|
89
92
|
{codeActions && (
|
|
90
93
|
<div className="code-actions absolute top-1 right-1 flex gap-1">
|
|
@@ -151,6 +154,8 @@ export function MdCode({ className, children, node, ...rest }: any) {
|
|
|
151
154
|
function MermaidDiagram({ source }: { source: string }) {
|
|
152
155
|
const { openDiagramOverlay } = useMdContext();
|
|
153
156
|
const [svg, setSvg] = useState<string | null>(null);
|
|
157
|
+
// Same identity rule as the Shiki block: a fresh `{ __html }` per render re-parses the SVG.
|
|
158
|
+
const svgProp = useMemo(() => (svg ? { __html: svg } : null), [svg]);
|
|
154
159
|
|
|
155
160
|
useEffect(() => {
|
|
156
161
|
let cancelled = false;
|
|
@@ -174,14 +179,14 @@ function MermaidDiagram({ source }: { source: string }) {
|
|
|
174
179
|
};
|
|
175
180
|
}, [source]);
|
|
176
181
|
|
|
177
|
-
if (!svg) return <pre><code>{source}</code></pre>;
|
|
182
|
+
if (!svg || !svgProp) return <pre><code>{source}</code></pre>;
|
|
178
183
|
|
|
179
184
|
return (
|
|
180
185
|
<div
|
|
181
186
|
className="mermaid-diagram group relative cursor-pointer rounded-lg border border-border bg-white dark:bg-panel-2 p-3 overflow-x-auto my-2"
|
|
182
187
|
onClick={() => openDiagramOverlay(svg)}
|
|
183
188
|
>
|
|
184
|
-
<div dangerouslySetInnerHTML={
|
|
189
|
+
<div dangerouslySetInnerHTML={svgProp} />
|
|
185
190
|
<div className="absolute top-2 right-2 flex items-center gap-1 px-2 py-1 rounded bg-black/60 text-white text-xs can-hover:opacity-0 can-hover:group-hover:opacity-100 transition-opacity pointer-events-none">
|
|
186
191
|
Click to expand
|
|
187
192
|
</div>
|
|
@@ -19,10 +19,23 @@ function TooltipProvider({
|
|
|
19
19
|
)
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
+
/**
|
|
23
|
+
* Carries its own provider, so a tooltip works wherever it is rendered.
|
|
24
|
+
*
|
|
25
|
+
* Radix throws outright — not a warning, a thrown error — when a Tooltip has no provider
|
|
26
|
+
* above it. That made any component holding one unrenderable outside the app shell: three
|
|
27
|
+
* component tests went red the moment a shared usage bar gained a tooltip, and nothing about
|
|
28
|
+
* the failure pointed at the tooltip. Nesting is cheap and supported; an outer provider still
|
|
29
|
+
* governs timing for everything beneath it.
|
|
30
|
+
*/
|
|
22
31
|
function Tooltip({
|
|
23
32
|
...props
|
|
24
33
|
}: React.ComponentProps<typeof TooltipPrimitive.Root>) {
|
|
25
|
-
return
|
|
34
|
+
return (
|
|
35
|
+
<TooltipProvider>
|
|
36
|
+
<TooltipPrimitive.Root data-slot="tooltip" {...props} />
|
|
37
|
+
</TooltipProvider>
|
|
38
|
+
)
|
|
26
39
|
}
|
|
27
40
|
|
|
28
41
|
function TooltipTrigger({
|
|
@@ -10,6 +10,16 @@ interface UseUsageReturn {
|
|
|
10
10
|
/** ISO timestamp from BE — when usage was actually fetched. */
|
|
11
11
|
lastFetchedAt: string | null;
|
|
12
12
|
refreshUsage: () => void;
|
|
13
|
+
/**
|
|
14
|
+
* Re-read without forcing the provider to go back to its source.
|
|
15
|
+
*
|
|
16
|
+
* For the caller that has just changed WHICH account this session reports on, rather than
|
|
17
|
+
* wanting fresher numbers for the same one. The new account's quota is already cached —
|
|
18
|
+
* it is what the account panel was showing a moment ago — so `refresh=1` would drop every
|
|
19
|
+
* account's cached value and re-read them all to display one figure that was already
|
|
20
|
+
* known.
|
|
21
|
+
*/
|
|
22
|
+
reloadUsage: () => void;
|
|
13
23
|
}
|
|
14
24
|
|
|
15
25
|
/**
|
|
@@ -61,8 +71,10 @@ export function useUsage(projectName: string, providerId = "claude", sessionId?:
|
|
|
61
71
|
|
|
62
72
|
/** Manual refresh — asks BE for fresh usage. */
|
|
63
73
|
const refreshUsage = useCallback(() => doFetch(true), [doFetch]);
|
|
74
|
+
/** Re-read the cached value, for when the session's account changed underneath it. */
|
|
75
|
+
const reloadUsage = useCallback(() => doFetch(), [doFetch]);
|
|
64
76
|
|
|
65
77
|
// Hide the previous scope synchronously, before the new effect runs.
|
|
66
78
|
const current = snapshot?.scope === scope ? snapshot : null;
|
|
67
|
-
return { usageInfo: current?.usage ?? {}, usageLoading, lastFetchedAt: current?.fetchedAt ?? null, refreshUsage };
|
|
79
|
+
return { usageInfo: current?.usage ?? {}, usageLoading, lastFetchedAt: current?.fetchedAt ?? null, refreshUsage, reloadUsage };
|
|
68
80
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{o as e}from"./rolldown-runtime-FhOqtrmT.js";import{S as t,x as n}from"./vendor-markdown-Ls5AcU91.js";import"./vendor-ui-CaeeFO0B.js";import{t as r}from"./copy-BewHj66E.js";import{t as i}from"./download-DG3_9xXy.js";import{t as a}from"./flask-conical-tp8gyZGh.js";import{t as o}from"./key-round-CQpDrDxg.js";import{t as s}from"./loader-circle-DPMrnLQ2.js";import{t as c}from"./x-CxoBA0po.js";import{n as l,r as u}from"./api-client-CEYCBt_0.js";import{n as d}from"./utils-IrnQujwR.js";import"./portal-container-context-DKymYOY-.js";import{n as f}from"./use-is-mobile-D1weanbj.js";import{n as p,t as m}from"./button-DX32ffge.js";import{t as h}from"./mobile-bottom-sheet-CmySDB6I.js";import"./use-visual-viewport-Bfl3Bxxb.js";import{$t as g,B as _,Dn as v,Dr as y,G as b,Gn as x,H as S,Ln as C,M as w,On as T,Pn as E,Qn as D,Qt as O,U as k,V as A,W as j,X as M,Xt as N,Y as P,Yt as F,Zt as I,en as L,ir as ee,kn as te,lr as R,nn as ne}from"./index-CHQAPZIX.js";import{addAccount as re,deleteAccount as ie,exchangeOAuthCode as ae,getAISettings as oe,getAccountSettings as se,getOAuthUrl as ce,getUsageHistory as le,importAccounts as ue,patchAccount as de,testAccountToken as fe,testExport as pe,testRawToken as me,updateAccountSettings as z}from"./api-settings-D18Q4Ocp.js";import{a as B,c as V,i as he,l as ge,n as _e,o as H,r as U,t as ve,u as W}from"./use-accounts-data-KWcMgRlc.js";var G=e(t(),1),K=n(),q=[`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`,`Sun`],J=Array.from({length:24},(e,t)=>t);function ye(e,t){let n=Array.from({length:7},()=>Array.from({length:24},()=>({sum:0,count:0,avg:0})));for(let r of e){let e=t===`5h`?r.five_hour_util:r.weekly_util;if(e==null)continue;let i=new Date(r.recorded_at+(r.recorded_at.endsWith(`Z`)?``:`Z`)),a=(i.getDay()+6)%7,o=i.getHours();n[a][o].sum+=e,n[a][o].count+=1}for(let e of n)for(let t of e)t.avg=t.count>0?t.sum/t.count:0;return n}function be(e){return e.map(e=>{let t=e.reduce((e,t)=>e+t.sum,0),n=e.reduce((e,t)=>e+t.count,0);return n>0?t/n:0})}function xe(e){return J.map(t=>{let n=0,r=0;for(let i of e)n+=i[t].sum,r+=i[t].count;return r>0?n/r:0})}function Y(e){return e===0?`bg-surface-elevated`:e<.3?`bg-success/30`:e<.5?`bg-success/60`:e<.7?`bg-warning/50`:e<.9?`bg-warning/80`:`bg-error/80`}function Se(e){return e<.3?`bg-success`:e<.7?`bg-warning`:`bg-error`}function Ce({accountId:e}){let[t,n]=(0,G.useState)(null),[r,i]=(0,G.useState)(!0),[a,o]=(0,G.useState)(`5h`);(0,G.useEffect)(()=>{i(!0),le(e).then(n).catch(()=>n([])).finally(()=>i(!1))},[e]);let c=(0,G.useMemo)(()=>t?ye(t,a):null,[t,a]),l=(0,G.useMemo)(()=>c?be(c):[],[c]),u=(0,G.useMemo)(()=>c?xe(c):[],[c]),d=Math.max(...l,.01);if(Math.max(...u,.01),r)return(0,K.jsx)(`div`,{className:`flex items-center justify-center py-3`,children:(0,K.jsx)(s,{className:`size-3 animate-spin text-text-subtle`})});if(!t||t.length===0)return(0,K.jsx)(`div`,{className:`text-[10px] text-text-subtle py-2 text-center`,children:`No usage history yet`});let f=t.length,p=new Set(t.map(e=>new Date(e.recorded_at+(e.recorded_at.endsWith(`Z`)?``:`Z`)).toDateString())).size;return(0,K.jsxs)(`div`,{className:`mt-2 space-y-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsx)(`span`,{className:`text-[10px] font-medium text-text-subtle`,children:`Usage Pattern (7d)`}),(0,K.jsxs)(`div`,{className:`flex gap-0.5 text-[9px]`,children:[(0,K.jsx)(`button`,{onClick:()=>o(`5h`),className:`px-1.5 py-0.5 rounded cursor-pointer transition-colors ${a===`5h`?`bg-primary/15 text-primary`:`text-text-subtle hover:text-text-secondary`}`,title:`5-hour rolling window limit — resets every 5 hours`,children:`5h`}),(0,K.jsx)(`button`,{onClick:()=>o(`weekly`),className:`px-1.5 py-0.5 rounded cursor-pointer transition-colors ${a===`weekly`?`bg-primary/15 text-primary`:`text-text-subtle hover:text-text-secondary`}`,title:`Weekly limit — resets every 7 days`,children:`Wk`})]})]}),(0,K.jsxs)(`p`,{className:`text-[9px] text-text-subtle leading-tight`,children:[`Avg `,a===`5h`?`5-hour`:`weekly`,` limit usage over `,p,`d (`,f,` samples). Higher % = closer to rate limit. Hover cells for details.`]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`span`,{className:`text-[9px] text-text-subtle`,children:`Avg usage by day of week`}),(0,K.jsx)(`div`,{className:`flex flex-col gap-[2px] mt-0.5`,children:q.map((e,t)=>{let n=l[t]??0;return(0,K.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(`span`,{className:`text-[8px] text-text-subtle w-5 shrink-0 text-right tabular-nums`,children:e}),(0,K.jsx)(`div`,{className:`flex-1 h-2.5 bg-surface-elevated rounded-sm overflow-hidden`,children:(0,K.jsx)(`div`,{className:`h-full rounded-sm transition-all ${Se(n)}`,style:{width:`${Math.round(n/d*100)}%`}})}),(0,K.jsxs)(`span`,{className:`text-[8px] text-text-subtle w-6 shrink-0 text-right tabular-nums`,children:[Math.round(n*100),`%`]})]},e)})})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`span`,{className:`text-[9px] text-text-subtle`,children:`Avg usage by hour (0h-23h)`}),(0,K.jsx)(`div`,{className:`flex gap-[1px] mt-0.5`,children:J.map(e=>{let t=u[e]??0;return(0,K.jsxs)(`div`,{className:`flex-1 flex flex-col items-center gap-[1px]`,children:[(0,K.jsx)(`div`,{className:`w-full aspect-square rounded-[2px] ${Y(t)}`,title:`${e}:00 — avg ${Math.round(t*100)}% usage`}),e%6==0&&(0,K.jsx)(`span`,{className:`text-[7px] text-text-subtle tabular-nums`,children:e})]},e)})})]}),c&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`span`,{className:`text-[9px] text-text-subtle`,children:`Day x Hour heatmap`}),(0,K.jsxs)(`div`,{className:`flex flex-col gap-[1px] mt-0.5`,children:[q.map((e,t)=>(0,K.jsxs)(`div`,{className:`flex items-center gap-[1px]`,children:[(0,K.jsx)(`span`,{className:`text-[7px] text-text-subtle w-4 shrink-0 text-right`,children:e.charAt(0)}),J.map(n=>{let r=c[t][n];return(0,K.jsx)(`div`,{className:`flex-1 aspect-square rounded-[1px] ${Y(r.avg)}`,title:`${e} ${n}:00 — ${r.count>0?`avg ${Math.round(r.avg*100)}% (${r.count} samples)`:`no data`}`},n)})]},e)),(0,K.jsxs)(`div`,{className:`flex items-center gap-[1px]`,children:[(0,K.jsx)(`span`,{className:`w-4 shrink-0`}),J.map(e=>(0,K.jsx)(`div`,{className:`flex-1 text-center`,children:e%6==0&&(0,K.jsx)(`span`,{className:`text-[7px] text-text-subtle tabular-nums`,children:e})},e))]})]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[8px] text-text-subtle`,children:[(0,K.jsx)(`span`,{children:`Low`}),(0,K.jsxs)(`div`,{className:`flex gap-[2px]`,children:[(0,K.jsx)(`div`,{className:`size-2 rounded-[1px] bg-success/30`}),(0,K.jsx)(`div`,{className:`size-2 rounded-[1px] bg-success/60`}),(0,K.jsx)(`div`,{className:`size-2 rounded-[1px] bg-warning/50`}),(0,K.jsx)(`div`,{className:`size-2 rounded-[1px] bg-warning/80`}),(0,K.jsx)(`div`,{className:`size-2 rounded-[1px] bg-error/80`})]}),(0,K.jsx)(`span`,{children:`High`}),(0,K.jsx)(`span`,{className:`ml-1`,children:`|`}),(0,K.jsx)(`div`,{className:`size-2 rounded-[1px] bg-surface-elevated border border-border/30`}),(0,K.jsx)(`span`,{children:`No data`})]})]})}function we({profile:e,accountId:t,onClose:n}){let r=[[`Name`,e.account?.display_name],[`Email`,e.account?.email],[`Org`,e.organization?.name],[`Type`,e.organization?.organization_type],[`Tier`,e.organization?.rate_limit_tier],[`Status`,e.organization?.subscription_status]];return(0,K.jsxs)(`section`,{className:`space-y-2 border-t border-border pt-3`,"data-testid":`account-profile-panel`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsx)(`h3`,{className:`text-sm font-medium`,children:`Profile`}),(0,K.jsx)(`button`,{className:`p-2 text-muted-foreground hover:text-foreground cursor-pointer`,onClick:n,"aria-label":`Close profile`,children:(0,K.jsx)(c,{className:`size-4`})})]}),(0,K.jsx)(`div`,{className:`grid grid-cols-[80px_1fr] gap-x-3 gap-y-1 text-xs`,children:r.map(([e,t])=>t?(0,K.jsxs)(`span`,{className:`contents`,children:[(0,K.jsx)(`span`,{className:`text-muted-foreground`,children:e}),(0,K.jsx)(`span`,{className:`break-all`,children:t})]},e):null)}),(0,K.jsx)(Ce,{accountId:t})]})}function Te({display:e,onConfirm:t,onCancel:n}){let r=f(),i=(0,K.jsxs)(`div`,{className:`space-y-4`,"data-testid":`account-delete-confirm`,children:[(0,K.jsxs)(`p`,{className:`text-sm`,children:[`Remove `,(0,K.jsx)(`span`,{className:`font-medium`,children:e}),`?`]}),(0,K.jsx)(`p`,{className:`text-xs text-text-subtle`,children:`The stored token is deleted from this machine. Any export you already made keeps working.`}),(0,K.jsxs)(`div`,{className:`flex flex-col-reverse md:flex-row gap-2 md:justify-end pt-2`,children:[(0,K.jsx)(m,{variant:`outline`,onClick:n,className:`min-h-11`,children:`Cancel`}),(0,K.jsx)(m,{variant:`destructive`,autoFocus:!1,onClick:t,className:`min-h-11`,children:`Remove account`})]})]});return r?(0,K.jsx)(h,{open:!0,onClose:n,children:(0,K.jsxs)(`div`,{className:`px-4 pb-4`,children:[(0,K.jsx)(`h2`,{className:`text-base font-semibold mb-3`,children:`Remove account`}),i]})}):(0,K.jsx)(F,{open:!0,onOpenChange:e=>{e||n()},children:(0,K.jsxs)(N,{className:`sm:max-w-sm`,children:[(0,K.jsx)(g,{children:(0,K.jsx)(L,{className:`text-sm`,children:`Remove account`})}),i]})})}function Ee({open:e,onOpenChange:t,onSuccess:n}){let[r,i]=(0,G.useState)(``),[a,o]=(0,G.useState)(``),[c,l]=(0,G.useState)(!1),[u,d]=(0,G.useState)(null),[f,p]=(0,G.useState)(null),[h,_]=(0,G.useState)(``),[v,y]=(0,G.useState)(!1),[b,x]=(0,G.useState)(`idle`);function S(){p(null),_(``),x(`idle`),d(null)}function C(){t(!1),S(),i(``),o(``),d(null)}async function w(){y(!0),d(null);try{let{url:e,state:t}=await ce();p(t),x(`waiting`),window.open(e,`_blank`)}catch(e){d(e.message)}y(!1)}async function T(){if(!(!h.trim()||!f)){y(!0),d(null);try{let e=h.trim();e.includes(`#`)&&(e=e.split(`#`)[0]??e);let t=await ae(e,f);C(),n(t?.status===`disabled`?`Signed in. This account is still disabled — enable it to use it.`:`Account connected via OAuth!`)}catch(e){d(e.message)}y(!1)}}async function E(){if(r.trim()){l(!0),d(null);try{let e=await re({apiKey:r.trim(),label:a.trim()||void 0});C(),n(e?.status===`disabled`?`Token updated. This account is still disabled — enable it to use it.`:`Account added!`)}catch(e){d(e.message)}l(!1)}}let D=r.trim()?r.trim().startsWith(`sk-ant-oat`)?`OAuth token (Claude Max/Pro)`:r.trim().startsWith(`sk-ant-api`)?`API key`:`Unknown format`:``;return(0,K.jsx)(F,{open:e,onOpenChange:e=>{e||C()},children:(0,K.jsxs)(N,{className:`sm:max-w-md`,children:[(0,K.jsxs)(g,{children:[(0,K.jsx)(L,{className:`text-sm`,children:`Add Claude Account`}),(0,K.jsx)(I,{className:`text-xs leading-relaxed`,children:`Connect via OAuth (recommended) or paste a token manually.`})]}),(0,K.jsxs)(`div`,{className:`space-y-3`,children:[(0,K.jsxs)(`div`,{className:`rounded-md border p-3 space-y-2`,children:[(0,K.jsx)(`p`,{className:`text-[11px] font-medium`,children:`Recommended: Login with Claude`}),b===`idle`?(0,K.jsx)(m,{size:`sm`,className:`w-full h-8 text-xs`,onClick:w,disabled:v,children:v?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(s,{className:`size-3 animate-spin mr-1`}),` Opening...`]}):`Login with Claude`}):(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:`Authorize in the opened tab, then paste the code:`}),(0,K.jsx)(M,{placeholder:`Paste code here...`,value:h,onChange:e=>_(e.target.value),className:`text-xs h-8 font-mono`,autoFocus:!0}),(0,K.jsxs)(`div`,{className:`flex gap-1.5`,children:[(0,K.jsx)(m,{size:`sm`,className:`flex-1 h-7 text-xs`,onClick:T,disabled:!h.trim()||v,children:v?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(s,{className:`size-3 animate-spin mr-1`}),` Connecting...`]}):`Connect`}),(0,K.jsx)(m,{size:`sm`,variant:`ghost`,className:`h-7 text-xs`,onClick:S,children:`Cancel`})]})]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`div`,{className:`flex-1 border-t`}),(0,K.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`or paste token`}),(0,K.jsx)(`div`,{className:`flex-1 border-t`})]}),(0,K.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,K.jsx)(P,{htmlFor:`add-token`,className:`text-xs`,children:`Token`}),(0,K.jsx)(M,{id:`add-token`,type:`password`,placeholder:`sk-ant-...`,value:r,onChange:e=>i(e.target.value),className:`text-xs h-8 font-mono`}),D&&(0,K.jsxs)(`p`,{className:`text-[10px] text-muted-foreground`,children:[`Detected: `,D]})]}),(0,K.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,K.jsx)(P,{htmlFor:`add-label`,className:`text-xs`,children:`Label (optional)`}),(0,K.jsx)(M,{id:`add-label`,placeholder:`e.g. Personal, Work`,value:a,onChange:e=>o(e.target.value),className:`text-xs h-8`})]})]}),u&&(0,K.jsx)(`div`,{className:`text-[11px] p-2 rounded bg-error/10 text-error`,children:u}),(0,K.jsxs)(O,{children:[(0,K.jsx)(m,{size:`sm`,variant:`outline`,className:`text-xs h-7`,onClick:C,children:`Cancel`}),(0,K.jsx)(m,{size:`sm`,className:`text-xs h-7`,onClick:E,disabled:!r.trim()||c,children:c?`Adding...`:`Add Token`})]})]})})}function De(e){let t=new Blob([e],{type:`application/json`}),n=document.createElement(`a`);n.href=URL.createObjectURL(t),n.download=`ppm-accounts-backup.json`,n.click(),URL.revokeObjectURL(n.href)}function Oe({open:e,onOpenChange:t,accounts:n,preselectId:a,onMessage:o}){let c=n.filter(e=>e.hasRefreshToken),[l,d]=(0,G.useState)(new Set),[f,p]=(0,G.useState)(``),[h,_]=(0,G.useState)(!1),[v,y]=(0,G.useState)(!1),[b,x]=(0,G.useState)(!1),[S,C]=(0,G.useState)(!1);e&&!S&&(d(a?new Set([a]):new Set(c.map(e=>e.id))),C(!0)),!e&&S&&C(!1);function w(){t(!1),p(``),_(!1),y(!1)}async function T(e){if(l.size===0)return;x(!0);let t=f.trim()||`ppm-hienlh`;try{let n={"Content-Type":`application/json`},r=u();r&&(n.Authorization=`Bearer ${r}`);let i=await fetch(`/api/accounts/export`,{method:`POST`,headers:n,body:JSON.stringify({password:t,accountIds:[...l],includeRefreshToken:h,refreshBeforeExport:v})});if(!i.ok){let e=await i.json();throw Error(e.error??`Export failed: ${i.status}`)}let a=await i.text();e&&await ne(a)?o?.(`Backup copied to clipboard!`):(De(a),o?.(`Backup downloaded.`)),w()}catch{}x(!1)}let E=l.size>0&&!b;return(0,K.jsx)(F,{open:e,onOpenChange:e=>{e||w()},children:(0,K.jsxs)(N,{className:`sm:max-w-md`,children:[(0,K.jsxs)(g,{children:[(0,K.jsxs)(L,{className:`text-sm flex items-center gap-1.5`,children:[(0,K.jsx)(R,{className:`size-3.5`}),` Export Accounts`]}),(0,K.jsx)(I,{className:`text-xs`,children:`Select accounts and set a password to protect the backup.`})]}),(0,K.jsxs)(`div`,{className:`space-y-3`,children:[(0,K.jsxs)(`div`,{className:`space-y-1`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-1`,children:[(0,K.jsx)(`p`,{className:`text-[11px] font-medium text-muted-foreground`,children:`Accounts to export`}),(0,K.jsx)(`button`,{className:`text-[10px] text-primary hover:underline cursor-pointer`,onClick:()=>d(l.size===c.length?new Set:new Set(c.map(e=>e.id))),children:l.size===c.length?`Deselect all`:`Select all`})]}),c.length===0?(0,K.jsx)(`p`,{className:`text-[10px] text-muted-foreground p-2 border rounded`,children:`No exportable accounts.`}):(0,K.jsx)(`div`,{className:`max-h-36 overflow-y-auto space-y-1 border rounded p-2`,children:c.map(e=>(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`input`,{type:`checkbox`,id:`exp-${e.id}`,checked:l.has(e.id),onChange:t=>{let n=new Set(l);t.target.checked?n.add(e.id):n.delete(e.id),d(n)},className:`size-3.5 accent-primary cursor-pointer`}),(0,K.jsx)(`label`,{htmlFor:`exp-${e.id}`,className:`text-xs cursor-pointer truncate`,children:e.label??e.email??e.id.slice(0,8)})]},e.id))})]}),(0,K.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,K.jsxs)(P,{className:`text-xs`,children:[`Password `,(0,K.jsx)(`span`,{className:`text-muted-foreground font-normal`,children:`(optional)`})]}),(0,K.jsx)(M,{type:`password`,placeholder:`Leave empty for default`,value:f,onChange:e=>p(e.target.value),className:`text-xs h-8`,autoComplete:`new-password`})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`input`,{type:`checkbox`,id:`exp-full`,checked:h,onChange:e=>_(e.target.checked),className:`size-3.5 accent-primary cursor-pointer`}),(0,K.jsx)(`label`,{htmlFor:`exp-full`,className:`text-[11px] cursor-pointer`,children:`Include refresh tokens (full transfer)`})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`input`,{type:`checkbox`,id:`exp-refresh`,checked:v,onChange:e=>y(e.target.checked),className:`size-3.5 accent-primary cursor-pointer`}),(0,K.jsx)(`label`,{htmlFor:`exp-refresh`,className:`text-[11px] cursor-pointer`,children:`Refresh tokens before export`})]}),h?(0,K.jsxs)(`div`,{className:`rounded-md border border-error/30 bg-error/5 p-2.5`,children:[(0,K.jsx)(`p`,{className:`text-[10px] font-medium text-error`,children:`Full transfer — source accounts will expire`}),(0,K.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:`Refresh tokens included. Source machine expires in ~1h after target refreshes.`})]}):v?(0,K.jsx)(`div`,{className:`rounded-md border border-warning/30 bg-warning/5 p-2.5`,children:(0,K.jsx)(`p`,{className:`text-[10px] font-medium text-warning`,children:`Refresh before export — invalidates previous shares`})}):(0,K.jsx)(`div`,{className:`rounded-md border border-success/30 bg-success/5 p-2.5`,children:(0,K.jsx)(`p`,{className:`text-[10px] font-medium text-success`,children:`Share current token (safe)`})}),(0,K.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:`Encrypted with AES-256-GCM + scrypt.`})]}),(0,K.jsxs)(O,{className:`gap-1.5 flex-col sm:flex-row`,children:[(0,K.jsx)(m,{size:`sm`,variant:`outline`,className:`text-xs h-7 cursor-pointer`,onClick:w,children:`Cancel`}),(0,K.jsxs)(m,{size:`sm`,variant:`outline`,className:`text-xs h-7 cursor-pointer`,disabled:!E,onClick:()=>T(!0),children:[(0,K.jsx)(r,{className:`size-3 mr-1`}),` Copy`]}),(0,K.jsx)(m,{size:`sm`,className:`text-xs h-7 cursor-pointer`,disabled:!E,onClick:()=>T(!1),children:b?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(s,{className:`size-3 animate-spin mr-1`}),` Exporting...`]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(i,{className:`size-3 mr-1`}),` Download`]})})]})]})})}function ke({open:e,onOpenChange:t,onSuccess:n}){let[r,i]=(0,G.useState)(``),[a,o]=(0,G.useState)(``),[c,l]=(0,G.useState)(!1),[u,d]=(0,G.useState)(null);function f(){t(!1),i(``),o(``),d(null)}async function p(){if(r.trim()){l(!0),d(null);try{let e=await ue({data:r.trim(),password:a.trim()||`ppm-hienlh`});f(),n(`Imported ${e.imported} account(s)`)}catch(e){d(e.message||`Import failed`)}l(!1)}}return(0,K.jsx)(F,{open:e,onOpenChange:e=>{e||f()},children:(0,K.jsxs)(N,{className:`sm:max-w-md`,children:[(0,K.jsxs)(g,{children:[(0,K.jsxs)(L,{className:`text-sm flex items-center gap-1.5`,children:[(0,K.jsx)(R,{className:`size-3.5`}),` Import Accounts`]}),(0,K.jsx)(I,{className:`text-xs`,children:`Paste backup data and enter the export password. Imported accounts are temporary (~1h).`})]}),(0,K.jsxs)(`div`,{className:`space-y-3`,children:[(0,K.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,K.jsx)(P,{className:`text-xs`,children:`Backup data`}),(0,K.jsx)(`textarea`,{value:r,onChange:e=>i(e.target.value),placeholder:`Paste backup JSON here...`,rows:4,className:`w-full text-xs p-2 rounded border border-border bg-background font-mono resize-none focus:outline-none focus:ring-1 focus:ring-primary`})]}),(0,K.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,K.jsxs)(P,{className:`text-xs`,children:[`Password `,(0,K.jsx)(`span`,{className:`text-muted-foreground font-normal`,children:`(optional)`})]}),(0,K.jsx)(M,{type:`password`,placeholder:`Leave empty for default`,value:a,onChange:e=>o(e.target.value),className:`text-xs h-8`,autoComplete:`current-password`})]})]}),u&&(0,K.jsx)(`div`,{className:`text-[11px] p-2 rounded bg-error/10 text-error`,children:u}),(0,K.jsxs)(O,{children:[(0,K.jsx)(m,{size:`sm`,variant:`outline`,className:`text-xs h-7 cursor-pointer`,onClick:f,children:`Cancel`}),(0,K.jsx)(m,{size:`sm`,className:`text-xs h-7 cursor-pointer`,disabled:!r.trim()||c,onClick:p,children:c?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(s,{className:`size-3 animate-spin mr-1`}),` Importing...`]}):`Import`})]})]})})}var X=typeof window<`u`?window.matchMedia(`(min-width: 768px)`):null;function Ae(e){return X?.addEventListener(`change`,e),()=>X?.removeEventListener(`change`,e)}function je(){return X?.matches??!0}function Z(){let[e,t]=(0,G.useState)(null),[n,r]=(0,G.useState)(!0);return(0,G.useEffect)(()=>{r(!0),se().then(t).finally(()=>r(!1))},[]),n?(0,K.jsx)(`p`,{className:`text-xs text-text-subtle py-4 text-center`,children:`Loading...`}):e?(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,K.jsx)(`label`,{className:`text-xs font-medium text-text-primary`,children:`Rotation Strategy`}),(0,K.jsxs)(_,{value:e.strategy,onValueChange:async e=>{t(await z({strategy:e}))},children:[(0,K.jsx)(k,{className:`w-full h-9 text-xs`,children:(0,K.jsx)(j,{})}),(0,K.jsxs)(A,{children:[(0,K.jsx)(S,{value:`round-robin`,children:`Round-robin`}),(0,K.jsx)(S,{value:`fill-first`,children:`Fill-first`}),(0,K.jsx)(S,{value:`lowest-usage`,children:`Lowest usage`})]})]}),(0,K.jsxs)(`p`,{className:`text-[10px] text-text-subtle`,children:[e.strategy===`round-robin`&&`Cycles through accounts evenly`,e.strategy===`fill-first`&&`Uses one account until its limit, then moves on`,e.strategy===`lowest-usage`&&`Picks the account with the lowest current usage`]})]}),(0,K.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,K.jsx)(`label`,{className:`text-xs font-medium text-text-primary`,children:`Max Retry`}),(0,K.jsx)(`input`,{type:`number`,min:0,value:e.maxRetry,className:`w-full h-9 text-xs border rounded-md px-3 bg-background`,onChange:async e=>{let n=parseInt(e.target.value,10);!isNaN(n)&&n>=0&&t(await z({maxRetry:n}))}}),(0,K.jsx)(`p`,{className:`text-[10px] text-text-subtle`,children:`How many accounts to try on failure. 0 = try all available accounts.`})]}),(0,K.jsxs)(`div`,{className:`space-y-1.5 border-t border-border pt-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsx)(`label`,{className:`text-xs font-medium text-text-primary`,children:`Cooldown parking`}),(0,K.jsx)(b,{checked:e.cooldownEnabled,onCheckedChange:async e=>{t(await z({cooldownEnabled:e}))}})]}),(0,K.jsx)(`p`,{className:`text-[10px] text-text-subtle`,children:`Park a failing account (rate limit / usage limit / auth error) until it recovers. Off: accounts stay selectable — rotation still skips accounts already ≥95% on the 5-hour limit.`})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between text-xs border-t border-border pt-3`,children:[(0,K.jsx)(`span`,{className:`text-text-subtle`,children:`Active accounts`}),(0,K.jsx)(`span`,{className:`font-medium text-text-primary`,children:e.activeCount})]})]}):(0,K.jsx)(`p`,{className:`text-xs text-text-subtle py-4 text-center`,children:`Failed to load settings`})}function Me({open:e,onOpenChange:t}){let n=(0,G.useSyncExternalStore)(Ae,je);return e?n?(0,K.jsx)(F,{open:e,onOpenChange:t,children:(0,K.jsxs)(N,{className:`sm:max-w-sm`,children:[(0,K.jsx)(g,{children:(0,K.jsxs)(L,{className:`text-sm flex items-center gap-2`,children:[(0,K.jsx)(x,{className:`size-4`}),` Rotation & Retry`]})}),(0,K.jsx)(Z,{})]})}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`fixed inset-0 z-50 transition-opacity duration-200 opacity-100`,onClick:()=>t(!1),style:{backgroundColor:`rgba(0,0,0,0.5)`}}),(0,K.jsxs)(`div`,{className:d(`fixed bottom-0 left-0 right-0 z-50 bg-background rounded-t-2xl border-t border-border shadow-2xl`,`transition-transform duration-300 ease-out max-h-[85vh] overflow-y-auto`,`translate-y-0`),children:[(0,K.jsx)(`div`,{className:`flex justify-center pt-3 pb-1`,children:(0,K.jsx)(`div`,{className:`w-10 h-1 rounded-full bg-border`})}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-2 border-b border-border`,children:[(0,K.jsxs)(`span`,{className:`text-sm font-semibold flex items-center gap-2`,children:[(0,K.jsx)(x,{className:`size-4`}),` Rotation & Retry`]}),(0,K.jsx)(`button`,{onClick:()=>t(!1),className:`flex items-center justify-center size-7 rounded-md hover:bg-surface-elevated transition-colors`,children:(0,K.jsx)(c,{className:`size-4`})})]}),(0,K.jsx)(`div`,{className:`px-4 py-4 pb-8`,children:(0,K.jsx)(Z,{})})]})]}):null}var Ne=p(`inline-flex items-center rounded-md border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2`,{variants:{variant:{default:`border-transparent bg-primary text-primary-foreground shadow`,secondary:`border-transparent bg-secondary text-secondary-foreground`,destructive:`border-transparent bg-destructive text-destructive-foreground shadow`,outline:`text-foreground`}},defaultVariants:{variant:`default`}});function Q({className:e,variant:t,...n}){return(0,K.jsx)(`div`,{className:d(Ne({variant:t}),e),...n})}function Pe(e){let t=Math.floor(Date.now()/1e3);return e>t?`${Math.floor((e-t)/60)}m`:`exp`}function Fe({accounts:e}){let[t,n]=(0,G.useState)([]),[r,i]=(0,G.useState)(!1),[a,o]=(0,G.useState)(!1),[c,l]=(0,G.useState)(new Map),u=e.filter(e=>e.hasRefreshToken);async function d(){if(u.length!==0){i(!0);try{let e=await pe(u.map(e=>e.id),a);n(t=>[...t,{round:t.length+1,time:new Date().toLocaleTimeString(),includeRefresh:a,items:e}])}catch{}i(!1)}}async function f(e,t){l(t=>new Map(t).set(e,{loading:!0}));try{let n=await me(t);l(t=>new Map(t).set(e,{loading:!1,...n}))}catch(t){l(n=>new Map(n).set(e,{loading:!1,status:`error`,error:t.message}))}}function p(e,t){return[{key:`r${e.round}-pre-${t.id}`,label:`Pre-export`,token:t.preExportTokenFull,preview:t.preExportToken,expires:t.preExportExpires},{key:`r${e.round}-exp-${t.id}`,label:`Exported`,token:t.exportedTokenFull,preview:t.exportedToken,expires:t.exportedExpires},{key:`r${e.round}-post-${t.id}`,label:`Post-export`,token:t.postExportTokenFull,preview:t.postExportToken,expires:t.postExportExpires}]}function h(){for(let e of t)for(let t of e.items)for(let n of p(e,t))n.token&&f(n.key,n.token)}return(0,K.jsxs)(`section`,{className:`border-t pt-4 space-y-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,K.jsx)(`p`,{className:`text-xs font-medium`,children:`Simulate export`}),t.length>0&&(0,K.jsxs)(`span`,{className:`text-[10px] text-muted-foreground`,children:[t.length,` round(s)`]})]}),(0,K.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:`Every run appends a round. Earlier rounds are kept so tokens can be compared across runs.`}),u.length===0?(0,K.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`No OAuth account with a refresh token to export.`}):(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,K.jsx)(b,{id:`sim-include-refresh`,checked:a,onCheckedChange:o,className:`cursor-pointer`}),(0,K.jsx)(P,{htmlFor:`sim-include-refresh`,className:`text-[11px] cursor-pointer`,children:`Include refresh tokens`})]}),(0,K.jsx)(m,{size:`sm`,className:`h-7 text-xs cursor-pointer`,disabled:r,onClick:()=>void d(),children:r?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(s,{className:`size-3 animate-spin mr-1`}),` Exporting...`]}):`Run export #${t.length+1}`})]}),t.length>0&&(0,K.jsxs)(`div`,{className:`space-y-3`,children:[(0,K.jsxs)(m,{size:`sm`,variant:`outline`,className:`w-full h-7 text-[11px] cursor-pointer`,onClick:h,children:[`Test all tokens (`,t.reduce((e,t)=>e+t.items.length*3,0),`)`]}),t.map(e=>(0,K.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsxs)(`p`,{className:`text-xs font-medium text-primary`,children:[`Round #`,e.round]}),(0,K.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:e.time}),(0,K.jsx)(Q,{variant:e.includeRefresh?`destructive`:`secondary`,className:`text-[9px] px-1 py-0`,children:e.includeRefresh?`with refresh`:`access only`})]}),e.items.map(t=>(0,K.jsxs)(`div`,{className:`p-2 rounded-lg border bg-card space-y-1.5`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`text-[11px] font-medium`,children:t.label??t.email??t.id.slice(0,8)}),t.tokenChanged&&(0,K.jsx)(Q,{variant:`secondary`,className:`text-[9px] px-1 py-0`,children:`DB token changed`})]}),p(e,t).map(e=>{let t=c.get(e.key);return(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px]`,children:[(0,K.jsx)(`span`,{className:`w-20 shrink-0 text-muted-foreground text-[10px]`,children:e.label}),(0,K.jsx)(`code`,{className:`flex-1 truncate font-mono text-[10px] bg-muted px-1 rounded`,children:e.preview??`N/A`}),e.expires&&(0,K.jsx)(`span`,{className:`text-[10px] text-muted-foreground shrink-0`,children:Pe(e.expires)}),e.token?(0,K.jsx)(m,{size:`sm`,variant:`outline`,className:`h-6 text-[10px] px-1.5 cursor-pointer shrink-0`,disabled:t?.loading,onClick:()=>void f(e.key,e.token),children:t?.loading?(0,K.jsx)(s,{className:`size-3 animate-spin`}):`Test`}):(0,K.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`-`}),t&&!t.loading&&(0,K.jsx)(`span`,{className:`text-[10px] font-medium shrink-0 ${t.status?.startsWith(`valid`)?`text-success`:`text-error`}`,children:t.status})]},e.key)})]},`r${e.round}-${t.id}`))]},e.round))]})]})}function Ie(e){let t=Math.floor(Date.now()/1e3),n=Math.floor(Math.abs(e-t)/60);return e>t?`${n}m left`:`expired ${n}m ago`}function Le({open:e,onOpenChange:t,accounts:n}){let[r,i]=(0,G.useState)(new Map),[o,c]=(0,G.useState)(!1);async function l(e){i(t=>new Map(t).set(e,{loading:!0}));try{let t=await fe(e,o);i(n=>new Map(n).set(e,{loading:!1,result:t}))}catch(t){i(n=>new Map(n).set(e,{loading:!1,error:t.message}))}}function u(){for(let e of n.filter(e=>e.expiresAt!==null))l(e.id)}return(0,K.jsx)(F,{open:e,onOpenChange:t,children:(0,K.jsxs)(N,{className:`sm:max-w-xl max-h-[85vh] flex flex-col`,children:[(0,K.jsxs)(g,{children:[(0,K.jsxs)(L,{className:`text-sm flex items-center gap-1.5`,children:[(0,K.jsx)(a,{className:`size-4`}),` Token Test`]}),(0,K.jsx)(I,{className:`text-xs`,children:`Probe stored tokens for validity. Nothing is modified.`})]}),(0,K.jsxs)(`div`,{className:`space-y-4 overflow-y-auto flex-1 pr-1`,children:[(0,K.jsxs)(`section`,{className:`space-y-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,K.jsx)(`p`,{className:`text-xs font-medium`,children:`Current tokens`}),(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,K.jsx)(b,{id:`token-test-refresh`,checked:o,onCheckedChange:c,className:`cursor-pointer`}),(0,K.jsx)(P,{htmlFor:`token-test-refresh`,className:`text-[11px] cursor-pointer`,children:`Also test refresh`})]}),(0,K.jsx)(m,{size:`sm`,variant:`outline`,className:`h-7 text-xs cursor-pointer`,onClick:u,children:`Test all`})]})]}),n.length===0&&(0,K.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`No accounts to test.`}),(0,K.jsx)(`div`,{className:`space-y-1.5`,children:n.map(e=>{let t=r.get(e.id),n=t?.result?.accessToken.status;return(0,K.jsxs)(`div`,{className:`p-2 rounded border bg-card space-y-1`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,K.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,K.jsx)(`span`,{className:`text-xs font-medium truncate block`,children:e.label??e.email??e.id.slice(0,8)}),e.expiresAt&&(0,K.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:Ie(e.expiresAt)})]}),(0,K.jsx)(m,{size:`sm`,variant:`outline`,className:`h-7 text-xs cursor-pointer shrink-0`,disabled:t?.loading,onClick:()=>void l(e.id),children:t?.loading?(0,K.jsx)(s,{className:`size-3 animate-spin`}):`Test`})]}),t&&!t.loading&&(0,K.jsxs)(`div`,{className:`text-[11px] pl-2 border-l-2 border-muted`,children:[t.error&&(0,K.jsx)(`p`,{className:`text-error`,children:t.error}),n&&(0,K.jsxs)(`span`,{className:n.startsWith(`valid`)?`text-success`:`text-error`,children:[n,t.result?.accessToken.code?` (${t.result.accessToken.code})`:``]})]})]},e.id)})})]}),(0,K.jsx)(Fe,{accounts:n})]}),(0,K.jsx)(O,{children:(0,K.jsx)(m,{size:`sm`,variant:`outline`,className:`text-xs cursor-pointer`,onClick:()=>t(!1),children:`Close`})})]})})}function Re(){let{usages:e,accounts:t,activeAccountId:n,initialLoading:r,refreshing:c,flashIds:l,reload:u}=ve(),[d,f]=(0,G.useState)(null),[p,h]=(0,G.useState)(null),[g,_]=(0,G.useState)(null),[v,y]=(0,G.useState)(null),[b,S]=(0,G.useState)(null),[C,w]=(0,G.useState)(null);function T(e){u(),e&&f(e)}async function O(e,t){h(e);try{await de(e,{status:t===`disabled`?`active`:`disabled`})}catch(e){f(e.message)}h(null),u()}async function k(){if(g){try{await ie(g.id),f(`Account "${g.display}" removed.`),u()}catch(e){f(`Failed to remove: ${e.message}`)}_(null)}}let A=new Map(t.map(e=>[e.id,e])),j=e[0]?.usage.lastFetchedAt;return(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsx)(B,{description:`Connect multiple Claude accounts. PPM rotates between them automatically to avoid rate limits.`,onRefresh:()=>void u(),refreshing:c,disabled:r,actions:(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(m,{size:`sm`,className:`cursor-pointer gap-1.5`,onClick:()=>w(`add`),children:[(0,K.jsx)(D,{className:`size-4`}),` Add account`]}),(0,K.jsxs)(m,{size:`sm`,variant:`outline`,className:`cursor-pointer gap-1.5`,onClick:()=>{S(null),w(`export`)},children:[(0,K.jsx)(i,{className:`size-4`}),` Export`]}),(0,K.jsxs)(m,{size:`sm`,variant:`outline`,className:`cursor-pointer gap-1.5`,onClick:()=>w(`import`),children:[(0,K.jsx)(E,{className:`size-4`}),` Import`]}),(0,K.jsxs)(m,{size:`sm`,variant:`outline`,className:`cursor-pointer gap-1.5`,onClick:()=>w(`rotation`),children:[(0,K.jsx)(x,{className:`size-4`}),` Rotation`]}),(0,K.jsxs)(m,{size:`sm`,variant:`outline`,className:`cursor-pointer gap-1.5`,onClick:()=>w(`token-test`),children:[(0,K.jsx)(a,{className:`size-4`}),` Token test`]})]})}),(0,K.jsx)(H,{message:d,onDismiss:()=>f(null)}),(0,K.jsxs)(`section`,{className:`space-y-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsx)(`h3`,{className:`text-sm font-medium`,children:`Accounts`}),j&&(0,K.jsxs)(`span`,{className:`text-[10px] text-muted-foreground`,children:[`usage `,ge(new Date(j).getTime())]})]}),r?(0,K.jsxs)(`div`,{className:`flex items-center gap-2 py-6 text-xs text-muted-foreground`,children:[(0,K.jsx)(s,{className:`size-4 animate-spin`}),` Loading accounts...`]}):e.length===0?(0,K.jsxs)(`div`,{className:`flex flex-col items-center gap-2 py-8 text-center`,children:[(0,K.jsx)(o,{className:`size-5 text-muted-foreground`}),(0,K.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`No accounts connected yet.`}),(0,K.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Add one to start using PPM.`})]}):(0,K.jsx)(U,{children:e.map(e=>(0,K.jsx)(_e,{layout:`strip`,entry:e,isActive:e.accountId===n,accountInfo:A.get(e.accountId),onToggle:O,toggling:p===e.accountId,onDelete:(e,t)=>_({id:e,display:t}),onExport:e=>{S(e),w(`export`)},onViewProfile:(e,t)=>y({profile:e,accountId:t}),flash:l.has(e.accountId)},e.accountId))})]}),v&&(0,K.jsx)(we,{profile:v.profile,accountId:v.accountId,onClose:()=>y(null)}),g&&(0,K.jsx)(Te,{display:g.display,onConfirm:()=>void k(),onCancel:()=>_(null)}),(0,K.jsx)(Ee,{open:C===`add`,onOpenChange:e=>w(e?`add`:null),onSuccess:T}),(0,K.jsx)(Oe,{open:C===`export`,onOpenChange:e=>{w(e?`export`:null),e||S(null)},accounts:t,preselectId:b,onMessage:f}),(0,K.jsx)(ke,{open:C===`import`,onOpenChange:e=>w(e?`import`:null),onSuccess:T}),(0,K.jsx)(Me,{open:C===`rotation`,onOpenChange:e=>w(e?`rotation`:null)}),(0,K.jsx)(Le,{open:C===`token-test`,onOpenChange:e=>w(e?`token-test`:null),accounts:t})]})}function ze({open:e,onOpenChange:t,label:n,onLabelChange:r,apiKey:i,onApiKeyChange:a,adding:c,onAddApiKey:l,deviceWaiting:u,onStartDevice:d,device:f,error:p}){return(0,K.jsx)(F,{open:e,onOpenChange:t,children:(0,K.jsxs)(N,{className:`sm:max-w-md`,children:[(0,K.jsxs)(g,{children:[(0,K.jsx)(L,{className:`text-sm`,children:`Add Codex Account`}),(0,K.jsxs)(I,{className:`text-xs leading-relaxed`,children:[`Each account keeps its own login (its own `,(0,K.jsx)(`code`,{children:`CODEX_HOME`}),`).`]})]}),(0,K.jsxs)(`div`,{className:`space-y-3`,children:[(0,K.jsxs)(`div`,{className:`rounded-md border p-3 space-y-2`,children:[(0,K.jsx)(`p`,{className:`text-[11px] font-medium`,children:`Recommended: sign in with ChatGPT`}),(0,K.jsx)(m,{size:`sm`,className:`w-full cursor-pointer gap-1.5`,onClick:d,disabled:u,children:u?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(s,{className:`size-4 animate-spin`}),` Waiting for authorization...`]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(ee,{className:`size-4`}),` Sign in with ChatGPT`]})}),f&&(0,K.jsxs)(`div`,{className:`rounded-md border border-primary/40 bg-primary/10 p-2.5 space-y-1.5`,children:[(0,K.jsx)(`p`,{className:`text-[11px]`,children:`Enter this code to authorize:`}),(0,K.jsx)(`div`,{className:`font-mono text-lg tracking-widest`,children:f.userCode}),(0,K.jsxs)(`a`,{href:f.verificationUrl,target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1 text-primary hover:underline text-[11px]`,children:[(0,K.jsx)(y,{className:`size-3`}),` `,f.verificationUrl]})]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`div`,{className:`flex-1 border-t`}),(0,K.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`or paste an API key`}),(0,K.jsx)(`div`,{className:`flex-1 border-t`})]}),(0,K.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,K.jsx)(P,{htmlFor:`codex-api-key`,className:`text-xs`,children:`OpenAI API key`}),(0,K.jsx)(M,{id:`codex-api-key`,type:`password`,placeholder:`sk-...`,value:i,onChange:e=>a(e.target.value),className:`text-xs font-mono`})]}),(0,K.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,K.jsx)(P,{htmlFor:`codex-label`,className:`text-xs`,children:`Label (optional)`}),(0,K.jsx)(M,{id:`codex-label`,placeholder:`e.g. Personal, Work`,value:n,onChange:e=>r(e.target.value),className:`text-xs`})]})]}),p&&(0,K.jsx)(`div`,{className:`text-[11px] p-2 rounded bg-error/10 text-error`,children:p}),(0,K.jsxs)(O,{children:[(0,K.jsx)(m,{size:`sm`,variant:`outline`,className:`text-xs cursor-pointer`,onClick:()=>t(!1),children:`Cancel`}),(0,K.jsxs)(m,{size:`sm`,className:`text-xs cursor-pointer gap-1.5`,onClick:l,disabled:!i.trim()||c,children:[c?(0,K.jsx)(s,{className:`size-3.5 animate-spin`}):(0,K.jsx)(o,{className:`size-3.5`}),`Add key`]})]})]})})}function Be({mode:e,onOpenChange:t,password:n,onPasswordChange:r,busy:a,onExport:o,onImport:c,error:l}){let u=(0,G.useRef)(null),d=e===`export`;return(0,K.jsx)(F,{open:e!==null,onOpenChange:t,children:(0,K.jsxs)(N,{className:`sm:max-w-md`,children:[(0,K.jsxs)(g,{children:[(0,K.jsxs)(L,{className:`text-sm flex items-center gap-1.5`,children:[(0,K.jsx)(R,{className:`size-4`}),` `,d?`Export Codex Accounts`:`Import Codex Accounts`]}),(0,K.jsx)(I,{className:`text-xs leading-relaxed`,children:d?`Writes a password-encrypted file containing each account's login.`:`Reads a backup file. The password must be the one it was exported with.`})]}),(0,K.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,K.jsx)(P,{htmlFor:`codex-backup-password`,className:`text-xs`,children:`Password`}),(0,K.jsx)(M,{id:`codex-backup-password`,type:`password`,placeholder:d?`Choose a password`:`Password used for the export`,value:n,onChange:e=>r(e.target.value),className:`text-xs`,autoComplete:d?`new-password`:`current-password`}),(0,K.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:`A backup holds full logins — keep the file and its password together.`})]}),l&&(0,K.jsx)(`div`,{className:`text-[11px] p-2 rounded bg-error/10 text-error`,children:l}),(0,K.jsx)(`input`,{ref:u,type:`file`,accept:`application/json,.json`,className:`hidden`,onChange:e=>{let t=e.target.files?.[0];e.target.value=``,t&&c(t)}}),(0,K.jsxs)(O,{children:[(0,K.jsx)(m,{size:`sm`,variant:`outline`,className:`text-xs cursor-pointer`,onClick:()=>t(!1),children:`Cancel`}),(0,K.jsxs)(m,{size:`sm`,className:`text-xs cursor-pointer gap-1.5`,disabled:!n.trim()||a,onClick:()=>d?o():u.current?.click(),children:[a?(0,K.jsx)(s,{className:`size-3.5 animate-spin`}):d?(0,K.jsx)(i,{className:`size-3.5`}):(0,K.jsx)(E,{className:`size-3.5`}),d?`Download backup`:`Choose file`]})]})]})})}var Ve=[{value:`round-robin`,label:`Round-robin`,hint:`Take the next account each time.`},{value:`fill-first`,label:`Fill-first`,hint:`Stay on one account until it runs out.`},{value:`lowest-usage`,label:`Lowest usage`,hint:`Pick whichever has the most left.`}];function He({open:e,onOpenChange:t,strategy:n,onChange:r}){return(0,K.jsx)(F,{open:e,onOpenChange:t,children:(0,K.jsxs)(N,{className:`sm:max-w-md`,children:[(0,K.jsxs)(g,{children:[(0,K.jsx)(L,{className:`text-sm`,children:`Codex Rotation`}),(0,K.jsx)(I,{className:`text-xs leading-relaxed`,children:`How a new chat chooses among your Codex accounts.`})]}),(0,K.jsx)(`div`,{className:`space-y-2`,children:Ve.map(e=>(0,K.jsxs)(`button`,{type:`button`,onClick:()=>r(e.value),"aria-current":n===e.value?`true`:void 0,className:d(`w-full text-left rounded-md border px-3 py-2.5 min-h-11 cursor-pointer transition-colors`,n===e.value?`border-primary bg-primary/10`:`border-border hover:bg-accent/50 active:bg-accent`),children:[(0,K.jsx)(`p`,{className:`text-sm font-medium`,children:e.label}),(0,K.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e.hint})]},e.value))}),(0,K.jsx)(O,{children:(0,K.jsx)(m,{size:`sm`,variant:`outline`,className:`text-xs cursor-pointer`,onClick:()=>t(!1),children:`Done`})})]})})}function $(e){return e==null?null:Math.round(e*100)}function Ue({usage:e}){return(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsx)(V,{label:`5-Hour Session`,pct:$(e.fiveHour),reset:W(e.session),resetsAt:e.session?.resetsAt}),(0,K.jsx)(V,{label:`Weekly`,pct:$(e.sevenDay),reset:W(e.weekly),resetsAt:e.weekly?.resetsAt})]})}var We=2e3,Ge=21e4;function Ke(e){let[t,n]=(0,G.useState)([]),[r,i]=(0,G.useState)(`round-robin`),[a,o]=(0,G.useState)({}),[s,c]=(0,G.useState)(!1),[d,f]=(0,G.useState)(new Set),[p,m]=(0,G.useState)(``),[h,g]=(0,G.useState)(``),[_,v]=(0,G.useState)(!1),[y,b]=(0,G.useState)(null),[x,S]=(0,G.useState)(null),[C,w]=(0,G.useState)(!1),[T,E]=(0,G.useState)(``),[D,O]=(0,G.useState)(!1),[k,A]=(0,G.useState)(!1),[j,M]=(0,G.useState)(null),N=(0,G.useRef)(null),P=(0,G.useRef)(null),F=(0,G.useCallback)(async()=>{c(!0);try{let e=await l.get(`/api/codex-accounts`);n(e.accounts),i(e.strategy),l.get(`/api/codex-accounts/usage`).then(o).catch(()=>{})}finally{c(!1)}},[]);(0,G.useEffect)(()=>{F()},[F]);let I=async()=>{if(p.trim()){v(!0),b(null);try{await l.post(`/api/codex-accounts/api-key`,{apiKey:p.trim(),label:h.trim()||void 0}),m(``),g(``),e(),await F()}catch(e){b(e.message)}finally{v(!1)}}},L=(0,G.useCallback)(t=>{let n=Date.now()+Ge,r=!1;N.current=()=>{r=!0};let i=e=>{r=!0,N.current=null,P.current=null,e&&b(e),S(null),w(!1)},a=async()=>{if(r)return;let o=null;try{o=await l.get(`/api/codex-accounts/device-login/${t}/status`)}catch{}if(!r){if(o?.state===`done`){i(),g(``),e(),await F();return}if(o?.state===`error`){i(o.error);return}if(Date.now()>n){i(`Device login timed out.`);return}setTimeout(a,We)}};a()},[F]);return(0,G.useEffect)(()=>()=>{N.current?.();let e=P.current;e&&l.del(`/api/codex-accounts/device-login/${e}`).catch(()=>{})},[]),{accounts:t,strategy:r,usages:a,loading:s,apiKey:p,setApiKey:m,label:h,setLabel:g,adding:_,err:y,setErr:b,device:x,deviceWaiting:C,backupPassword:T,setBackupPassword:E,exporting:D,importing:k,msg:j,setMsg:M,toggling:d,load:F,addApiKey:I,startDevice:async()=>{b(null);try{let e=await l.post(`/api/codex-accounts/device-login`,{label:h.trim()||void 0});S(e),w(!0),P.current=e.id,L(e.id)}catch(e){b(e.message)}},remove:async e=>{await l.del(`/api/codex-accounts/${e}`),await F()},toggle:async(e,t)=>{let n=t===`disabled`?`active`:`disabled`;f(t=>new Set(t).add(e)),b(null);try{await l.patch(`/api/codex-accounts/${e}`,{status:n}),await F()}catch(e){b(e.message||`Could not change the account`)}finally{f(t=>{let n=new Set(t);return n.delete(e),n})}},changeStrategy:async e=>{i(e);try{await l.put(`/api/codex-accounts/strategy`,{strategy:e})}catch{}},doExport:async()=>{if(!T.trim()){b(`Set a backup password first.`);return}O(!0),b(null),M(null);try{let t={"Content-Type":`application/json`},n=u();n&&(t.Authorization=`Bearer ${n}`);let r=await fetch(`/api/codex-accounts/export`,{method:`POST`,headers:t,body:JSON.stringify({password:T})});if(!r.ok){let e=await r.json().catch(()=>({}));throw Error(e.error??`Export failed: ${r.status}`)}let i=await r.text(),a=new Blob([i],{type:`application/json`}),o=document.createElement(`a`);o.href=URL.createObjectURL(a),o.download=`ppm-codex-accounts-backup.json`,o.click(),URL.revokeObjectURL(o.href),M(`Backup downloaded.`),e()}catch(e){b(e.message)}finally{O(!1)}},doImport:async t=>{if(!T.trim()){b(`Enter the backup password first.`);return}A(!0),b(null),M(null);try{let n=await t.text(),r=await l.post(`/api/codex-accounts/import`,{data:n,password:T});M(`Imported ${r.imported}${r.skipped?`, skipped ${r.skipped}`:``}.`),e(),await F()}catch(e){b(e.message)}finally{A(!1)}}}}function qe(){let[e,t]=(0,G.useState)(null),n=Ke(()=>t(null));return(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsx)(B,{description:(0,K.jsxs)(K.Fragment,{children:[`Each Codex account keeps its own login (`,(0,K.jsx)(`code`,{children:`CODEX_HOME`}),`). One is picked per chat by the rotation setting.`]}),onRefresh:()=>void n.load(),refreshing:n.loading,actions:(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(m,{size:`sm`,className:`cursor-pointer gap-1.5`,onClick:()=>t(`add`),children:[(0,K.jsx)(D,{className:`size-4`}),` Add account`]}),(0,K.jsxs)(m,{size:`sm`,variant:`outline`,className:`cursor-pointer gap-1.5`,onClick:()=>t(`export`),children:[(0,K.jsx)(i,{className:`size-4`}),` Export`]}),(0,K.jsxs)(m,{size:`sm`,variant:`outline`,className:`cursor-pointer gap-1.5`,onClick:()=>t(`import`),children:[(0,K.jsx)(E,{className:`size-4`}),` Import`]}),(0,K.jsxs)(m,{size:`sm`,variant:`outline`,className:`cursor-pointer gap-1.5`,onClick:()=>t(`rotation`),children:[(0,K.jsx)(x,{className:`size-4`}),` Rotation`]})]})}),(0,K.jsx)(H,{message:n.msg??n.err,onDismiss:()=>{n.setMsg(null),n.setErr(null)}}),(0,K.jsxs)(`section`,{className:`space-y-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsx)(`h3`,{className:`text-sm font-medium`,children:`Codex Accounts`}),(0,K.jsx)(`span`,{className:`text-[10px] text-muted-foreground capitalize`,children:n.strategy.replace(`-`,` `)})]}),n.loading&&n.accounts.length===0?(0,K.jsxs)(`div`,{className:`flex items-center gap-2 py-6 text-xs text-muted-foreground`,children:[(0,K.jsx)(s,{className:`size-4 animate-spin`}),` Loading accounts...`]}):n.accounts.length===0?(0,K.jsxs)(`div`,{className:`flex flex-col items-center gap-2 py-8 text-center`,children:[(0,K.jsx)(o,{className:`size-5 text-muted-foreground`}),(0,K.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`No Codex accounts yet.`}),(0,K.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Chats use your default `,(0,K.jsx)(`code`,{children:`~/.codex`}),` login until you add one.`]})]}):(0,K.jsx)(U,{children:n.accounts.map(e=>{let t=n.usages[e.id]??{};return(0,K.jsxs)(he,{dense:!0,className:`min-w-[300px] shrink-0 snap-start`,"data-testid":`account-card`,"data-account-id":e.id,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`text-sm font-medium truncate flex-1 min-w-0`,children:e.label}),(0,K.jsx)(`span`,{className:`text-[10px] uppercase tracking-wide text-text-subtle border border-border rounded px-1 shrink-0`,children:e.type}),e.planType&&(0,K.jsx)(`span`,{className:`text-[10px] text-text-subtle shrink-0`,children:e.planType}),(0,K.jsx)(b,{checked:e.status!==`disabled`,onCheckedChange:()=>void n.toggle(e.id,e.status??`active`),disabled:n.toggling.has(e.id),"aria-label":e.status===`disabled`?`Enable account`:`Disable account`,className:`cursor-pointer shrink-0`}),(0,K.jsxs)(v,{children:[(0,K.jsx)(te,{asChild:!0,children:(0,K.jsx)(`button`,{type:`button`,onClick:()=>void n.remove(e.id),"aria-label":`Remove account`,className:`p-2 rounded cursor-pointer text-text-subtle hover:text-error hover:bg-surface-elevated transition-colors shrink-0`,children:(0,K.jsx)(C,{className:`size-4`})})}),(0,K.jsx)(T,{side:`top`,children:`Remove account`})]})]}),(0,K.jsx)(Ue,{usage:t})]},e.id)})})]}),(0,K.jsx)(ze,{open:e===`add`,onOpenChange:e=>t(e?`add`:null),label:n.label,onLabelChange:n.setLabel,apiKey:n.apiKey,onApiKeyChange:n.setApiKey,adding:n.adding,onAddApiKey:()=>void n.addApiKey(),deviceWaiting:n.deviceWaiting,onStartDevice:()=>void n.startDevice(),device:n.device,error:n.err}),(0,K.jsx)(Be,{mode:e===`export`?`export`:e===`import`?`import`:null,onOpenChange:e=>{e||t(null)},password:n.backupPassword,onPasswordChange:n.setBackupPassword,busy:n.exporting||n.importing,onExport:()=>void n.doExport(),onImport:e=>void n.doImport(e),error:n.err}),(0,K.jsx)(He,{open:e===`rotation`,onOpenChange:e=>t(e?`rotation`:null),strategy:n.strategy,onChange:e=>void n.changeStrategy(e)})]})}var Je=[{id:`claude`,label:`Claude`},{id:`codex`,label:`Codex`}];function Ye(){let[e,t]=(0,G.useState)(null),[n,r]=(0,G.useState)(`claude`);(0,G.useEffect)(()=>{let e=!1;return oe().then(n=>{e||t(new Set(Object.keys(n.providers??{})))}).catch(()=>{e||t(new Set([`claude`]))}),()=>{e=!0}},[]);let i=Je.filter(t=>t.id===`claude`||e?.has(t.id)),a=i.length>1;return(0,K.jsxs)(`div`,{className:`space-y-4`,"data-testid":`accounts-pane`,"data-provider":n,children:[a&&(0,K.jsx)(`div`,{className:`flex gap-1 border-b border-border/50`,children:i.map(e=>(0,K.jsxs)(`button`,{onClick:()=>r(e.id),"data-testid":`accounts-tab-${e.id}`,"aria-current":n===e.id?`page`:void 0,className:`flex items-center gap-1.5 px-3 py-2 text-xs rounded-t transition-colors cursor-pointer ${n===e.id?`text-primary border-b-2 border-primary font-medium`:`text-text-subtle hover:text-text-secondary`}`,children:[(0,K.jsx)(w,{providerId:e.id}),e.label]},e.id))}),e===null&&!a&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-muted-foreground`,children:[(0,K.jsx)(s,{className:`size-3 animate-spin`}),` Checking configured providers...`]}),n===`claude`?(0,K.jsx)(Re,{}):(0,K.jsx)(qe,{})]})}export{Ye as AccountsSettingsSection};
|