@hienlh/ppm 0.22.0 → 0.22.1
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 +9 -0
- package/CLAUDE.md +1 -1
- package/assets/skills/ppm/SKILL.md +1 -1
- package/assets/skills/ppm/references/cli-reference.md +4 -4
- package/assets/skills/ppm/references/http-api.md +1 -1
- package/dist/web/assets/accounts-settings-section-D3BylchP.js +1 -0
- package/dist/web/assets/{ai-resource-editor-CdDpOwjh.js → ai-resource-editor-BLPcnhTM.js} +1 -1
- package/dist/web/assets/{ai-settings-section-X2UOfSaS.js → ai-settings-section-BtR7rF-T.js} +1 -1
- package/dist/web/assets/{ai-settings-section-B1hQyjAd.js → ai-settings-section-r9JctHNM.js} +1 -1
- package/dist/web/assets/{appearance-settings-section-DLoPK0LD.js → appearance-settings-section-CiMdk3sb.js} +1 -1
- package/dist/web/assets/{branch-review-tab-G84Ojzae.js → branch-review-tab-B1pFjlKM.js} +1 -1
- package/dist/web/assets/chat-tab-DZagX06m.js +15 -0
- package/dist/web/assets/{code-editor-D04iUPsZ.js → code-editor-BJhOEsnZ.js} +4 -4
- package/dist/web/assets/{codex-daily-guard-BSccLRGT.js → codex-daily-guard-CaCQJ4r_.js} +1 -1
- package/dist/web/assets/{conflict-editor-C4ay676e.js → conflict-editor-B7u_p49h.js} +3 -3
- package/dist/web/assets/{csv-preview-DbwEmG7o.js → csv-preview-CttjJU1e.js} +1 -1
- package/dist/web/assets/{database-viewer-S6LsALjX.js → database-viewer-Ca4HxIfx.js} +1 -1
- package/dist/web/assets/{diff-viewer-3oBA7vgQ.js → diff-viewer-9-XjLIwa.js} +1 -1
- package/dist/web/assets/{editor-language-service-DJmaKVY0.js → editor-language-service-D0DuEOs_.js} +1 -1
- package/dist/web/assets/{explorer-body-BQ0jyAGv.js → explorer-body-VdCBqcZu.js} +2 -2
- package/dist/web/assets/{explorer-window-content-jdkWt34J.js → explorer-window-content-BIsbl7Th.js} +1 -1
- package/dist/web/assets/extension-manager-section-HkY7geS5.js +1 -0
- package/dist/web/assets/{extension-webview-BGSDUbdK.js → extension-webview-DZG8YHX9.js} +1 -1
- package/dist/web/assets/{files-settings-section-Gnyd7han.js → files-settings-section-qnRtkX05.js} +1 -1
- package/dist/web/assets/{general-settings-section-V6Khh15V.js → general-settings-section-BAFSZmCE.js} +1 -1
- package/dist/web/assets/{git-log-panel-Bi513qjT.js → git-log-panel-2sGpfEla.js} +1 -1
- package/dist/web/assets/{glide-data-grid-DnQwYSmQ.js → glide-data-grid-f0hyITiF.js} +1 -1
- package/dist/web/assets/{group-chat-tab-DpczdwyV.js → group-chat-tab-Ck6sk7yY.js} +1 -1
- package/dist/web/assets/index-CEZVxM4G.js +52 -0
- package/dist/web/assets/{jira-watcher-section-f2HUbGDY.js → jira-watcher-section-CeLmhvu1.js} +1 -1
- package/dist/web/assets/keybindings-store-C_3ChOEf.js +1 -0
- package/dist/web/assets/{keyboard-shortcuts-section-BpvVEw_Y.js → keyboard-shortcuts-section-PVz6kuh2.js} +1 -1
- package/dist/web/assets/markdown-renderer-C140Ijk0.js +3 -0
- package/dist/web/assets/{markdown-renderer-Bcaf9_bA.js → markdown-renderer-Dz7-DYUg.js} +1 -1
- package/dist/web/assets/{mobile-explorer-sheet-Bol3XAO1.js → mobile-explorer-sheet-CUG_owdf.js} +1 -1
- package/dist/web/assets/notification-store-6vib1ISy.js +1 -0
- package/dist/web/assets/{ppmbot-settings-section-DKJUA3Kq.js → ppmbot-settings-section-Cji-Mil-.js} +1 -1
- package/dist/web/assets/{problems-panel-CFcoUx8h.js → problems-panel-a6_hrWvl.js} +1 -1
- package/dist/web/assets/{process-table-EKr2dqG6.js → process-table-CiIqlOIK.js} +1 -1
- package/dist/web/assets/{proxy-settings-section-B7qRVl8w.js → proxy-settings-section-BjI4IFgp.js} +1 -1
- package/dist/web/assets/{remote-desktop-clipboard-notice-0WDYsyCA.js → remote-desktop-clipboard-notice-eXYvwgx7.js} +1 -1
- package/dist/web/assets/{remote-desktop-mobile-sheet-COYDg16H.js → remote-desktop-mobile-sheet-Doh-fci-.js} +2 -2
- package/dist/web/assets/{remote-desktop-mobile-view-2DqSuS2U.js → remote-desktop-mobile-view-Dt8Akc3p.js} +1 -1
- package/dist/web/assets/{remote-desktop-readiness-gate-Dm_qMJMH.js → remote-desktop-readiness-gate-t83fqbID.js} +1 -1
- package/dist/web/assets/{remote-desktop-window-content-UodhsF7W.js → remote-desktop-window-content-CguhZMmx.js} +1 -1
- package/dist/web/assets/{schedules-settings-section-bG2lYfGv.js → schedules-settings-section-BVkpW5ms.js} +1 -1
- package/dist/web/assets/{settings-body-C06bFarv.js → settings-body-CoIxYAh6.js} +2 -2
- package/dist/web/assets/{settings-tab-34RSaASd.js → settings-tab-7DKVUTbM.js} +1 -1
- package/dist/web/assets/{settings-window-content-Dr_2lmHH.js → settings-window-content-3_39TeX-.js} +1 -1
- package/dist/web/assets/{sql-query-editor-BgRH0cHD.js → sql-query-editor-CQB7Yp7U.js} +1 -1
- package/dist/web/assets/{sqlite-viewer-DUxGslpa.js → sqlite-viewer-Bd7rjr1D.js} +1 -1
- package/dist/web/assets/{system-monitor-body-IZuLn7Qh.js → system-monitor-body-DsRXeMyU.js} +2 -2
- package/dist/web/assets/{system-monitor-tab-DiSA490Z.js → system-monitor-tab-DdSZgux3.js} +1 -1
- package/dist/web/assets/{system-monitor-window-content-CEaFISgj.js → system-monitor-window-content-ClPo4-El.js} +1 -1
- package/dist/web/assets/{tab-host-window-content-D0TN8Wrq.js → tab-host-window-content-d2TAD4PU.js} +1 -1
- package/dist/web/assets/{team-member-sheet-DDPNcCjd.js → team-member-sheet-7d2Qp-ie.js} +2 -2
- package/dist/web/assets/{team-member-window-content-DCiW_1-E.js → team-member-window-content-Bctg2gmg.js} +1 -1
- package/dist/web/assets/{terminal-tab-4ypP0NDY.js → terminal-tab-0HQic25V.js} +3 -3
- package/dist/web/assets/{tool-cards-Dd6E7Q3k.js → tool-cards-CmLLRACd.js} +2 -2
- package/dist/web/assets/{use-inline-blame-vrfFHuaR.js → use-inline-blame-sDMjcz1-.js} +3 -3
- package/dist/web/assets/{use-lsp-CsuZu49X.js → use-lsp-CBgID-EU.js} +1 -1
- package/dist/web/assets/{use-monaco-theme-BIVYJBIn.js → use-monaco-theme-gvhJ_jZh.js} +1 -1
- package/dist/web/assets/{use-websocket-BMbufhX7.js → use-websocket-C9wlRliB.js} +1 -1
- package/dist/web/assets/{video-preview-Byj8P_jA.js → video-preview-CSDK5j6H.js} +1 -1
- package/dist/web/index.html +1 -1
- package/dist/web/sw.js +1 -1
- package/docs/architecture/ai-chat-and-providers.md +9 -0
- package/package.json +1 -1
- package/packages/ext-git-graph/src/webview-html.test.ts +30 -5
- package/packages/ext-git-graph/src/webview-html.ts +99 -31
- package/src/services/edge-forwarder.ts +191 -191
- package/src/services/windows-process-tree.ts +351 -351
- package/src/shared/codex-daily-guard.ts +12 -5
- package/src/web/components/extensions/extension-tree-view.tsx +4 -11
- package/src/web/components/layout/command-palette.tsx +2 -18
- package/src/web/components/settings/accounts/account-card.tsx +2 -2
- package/src/web/components/settings/accounts/codex-accounts-section.tsx +4 -4
- package/src/web/components/settings/extension-manager-section.tsx +8 -1
- package/src/web/lib/extension-icons.ts +70 -0
- package/src/web/lib/tab-type-icons.ts +14 -0
- package/dist/web/assets/accounts-settings-section-BVr9-FZJ.js +0 -1
- package/dist/web/assets/chat-tab-DQJfjm8E.js +0 -15
- package/dist/web/assets/extension-manager-section-DG1guILi.js +0 -1
- package/dist/web/assets/index-DU68xk06.js +0 -52
- package/dist/web/assets/keybindings-store-DCRsnKg5.js +0 -1
- package/dist/web/assets/markdown-renderer-DGJp8HC3.js +0 -3
- package/dist/web/assets/notification-store-BXt54VIn.js +0 -1
- package/packages/vscode-compat/node_modules/.bin/tsc.bunx +0 -0
- package/packages/vscode-compat/node_modules/.bin/tsc.exe +0 -0
- package/packages/vscode-compat/node_modules/.bin/tsserver.bunx +0 -0
- package/packages/vscode-compat/node_modules/.bin/tsserver.exe +0 -0
- package/src/web/hooks/use-delayed-flag.ts +0 -35
|
@@ -2,6 +2,7 @@ import type { LimitBucket } from "../types/chat.ts";
|
|
|
2
2
|
|
|
3
3
|
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
4
4
|
const WEEK_DAYS = 7;
|
|
5
|
+
const WORK_DAYS = 5;
|
|
5
6
|
|
|
6
7
|
export interface DailyGuardState {
|
|
7
8
|
day: number;
|
|
@@ -10,18 +11,24 @@ export interface DailyGuardState {
|
|
|
10
11
|
blocked: boolean;
|
|
11
12
|
}
|
|
12
13
|
|
|
13
|
-
/**
|
|
14
|
+
/** Five weekday envelopes, using reset-anchored 24h slots and UTC weekdays on every client. */
|
|
14
15
|
export function dailyGuardState(bucket: LimitBucket | undefined, now = Date.now()): DailyGuardState | null {
|
|
15
16
|
if (!bucket || bucket.windowHours !== 168) return null;
|
|
16
17
|
const resetsAt = new Date(bucket.resetsAt).getTime();
|
|
17
|
-
if (!Number.isFinite(resetsAt) || resetsAt <= now) return null;
|
|
18
|
+
if (!Number.isFinite(now) || !Number.isFinite(resetsAt) || resetsAt <= now) return null;
|
|
18
19
|
|
|
19
20
|
const startedAt = resetsAt - WEEK_DAYS * DAY_MS;
|
|
20
|
-
|
|
21
|
-
const
|
|
21
|
+
if (now < startedAt) return null;
|
|
22
|
+
const elapsedSlot = Math.min(WEEK_DAYS - 1, Math.floor((now - startedAt) / DAY_MS));
|
|
23
|
+
let day = 0;
|
|
24
|
+
for (let slot = 0; slot <= elapsedSlot; slot++) {
|
|
25
|
+
const weekday = new Date(startedAt + slot * DAY_MS).getUTCDay();
|
|
26
|
+
if (weekday !== 0 && weekday !== 6) day++;
|
|
27
|
+
}
|
|
28
|
+
const cap = day / WORK_DAYS;
|
|
22
29
|
return { day, cap, used: bucket.utilization, blocked: bucket.utilization >= cap };
|
|
23
30
|
}
|
|
24
31
|
|
|
25
32
|
export function dailyGuardMessage(state: DailyGuardState): string {
|
|
26
|
-
return `Daily guard reached: ${Math.round(state.used * 100)}% used;
|
|
33
|
+
return `Daily guard reached: ${Math.round(state.used * 100)}% used; weekday ${state.day}/5 allows ${Math.round(state.cap * 100)}%. The cap increases on weekdays only. Turn off Daily guard on this account to continue.`;
|
|
27
34
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { useCallback, useState, useRef, useMemo } from "react";
|
|
2
|
-
import { ChevronRight, ChevronDown, RefreshCw
|
|
2
|
+
import { ChevronRight, ChevronDown, RefreshCw } from "@/lib/icons";
|
|
3
3
|
import { useExtensionStore, type TreeItemUI, type TreeItemAction } from "@/stores/extension-store";
|
|
4
|
+
import { extensionIcon } from "@/lib/extension-icons";
|
|
4
5
|
import { cn } from "@/lib/utils";
|
|
5
6
|
|
|
6
7
|
interface ExtensionTreeViewProps {
|
|
@@ -22,14 +23,6 @@ function executeCommand(command: string, args?: unknown[]) {
|
|
|
22
23
|
}));
|
|
23
24
|
}
|
|
24
25
|
|
|
25
|
-
const ACTION_ICONS: Record<string, React.ElementType> = {
|
|
26
|
-
refresh: RefreshCw,
|
|
27
|
-
edit: Pencil,
|
|
28
|
-
trash: Trash2,
|
|
29
|
-
plus: Plus,
|
|
30
|
-
search: Search,
|
|
31
|
-
};
|
|
32
|
-
|
|
33
26
|
/** Generic TreeView renderer for extension-contributed tree data */
|
|
34
27
|
export function ExtensionTreeView({ viewId, className }: ExtensionTreeViewProps) {
|
|
35
28
|
const items = useExtensionStore((s) => s.treeViews[viewId]) ?? [];
|
|
@@ -75,7 +68,7 @@ export function ExtensionTreeView({ viewId, className }: ExtensionTreeViewProps)
|
|
|
75
68
|
<div className="flex items-center gap-0.5">
|
|
76
69
|
{viewMeta.headerActions.map((action) => {
|
|
77
70
|
const iconName = action.icon ?? inferIcon(action.command);
|
|
78
|
-
const Icon =
|
|
71
|
+
const Icon = extensionIcon(iconName) ?? RefreshCw;
|
|
79
72
|
return (
|
|
80
73
|
<button
|
|
81
74
|
key={action.command}
|
|
@@ -213,7 +206,7 @@ function TreeNode({ item, depth, viewId }: { item: TreeItemUI; depth: number; vi
|
|
|
213
206
|
|
|
214
207
|
function ActionButton({ action }: { action: TreeItemAction }) {
|
|
215
208
|
const [spinning, setSpinning] = useState(false);
|
|
216
|
-
const Icon =
|
|
209
|
+
const Icon = extensionIcon(action.icon) ?? RefreshCw;
|
|
217
210
|
const isTrash = action.icon === "trash";
|
|
218
211
|
|
|
219
212
|
const handleClick = useCallback((e: React.MouseEvent) => {
|
|
@@ -3,19 +3,15 @@ import {
|
|
|
3
3
|
Terminal,
|
|
4
4
|
MessageSquare,
|
|
5
5
|
GitCommitHorizontal,
|
|
6
|
-
GitBranch,
|
|
7
6
|
Puzzle,
|
|
8
7
|
Settings,
|
|
9
8
|
Database,
|
|
10
9
|
Search,
|
|
11
|
-
FileCode,
|
|
12
10
|
FilePlus,
|
|
13
11
|
FolderOpen,
|
|
14
12
|
Loader2,
|
|
15
13
|
Globe,
|
|
16
14
|
Mic,
|
|
17
|
-
RefreshCw,
|
|
18
|
-
Plus,
|
|
19
15
|
Columns2,
|
|
20
16
|
Cloud,
|
|
21
17
|
AppWindow,
|
|
@@ -33,6 +29,7 @@ import { useIsTouchOnly } from "@/hooks/use-is-touch-only";
|
|
|
33
29
|
import { useKeybindingsStore } from "@/stores/keybindings-store";
|
|
34
30
|
import { useFileStore, type FileNode } from "@/stores/file-store";
|
|
35
31
|
import { useExtensionStore } from "@/stores/extension-store";
|
|
32
|
+
import { extensionIcon } from "@/lib/extension-icons";
|
|
36
33
|
import { useCompareStore } from "@/stores/compare-store";
|
|
37
34
|
import { usePanelStore } from "@/stores/panel-store";
|
|
38
35
|
import { api } from "@/lib/api-client";
|
|
@@ -61,19 +58,6 @@ interface CommandItem {
|
|
|
61
58
|
|
|
62
59
|
const isMac = typeof navigator !== "undefined" && /Mac|iPhone|iPad/.test(navigator.userAgent);
|
|
63
60
|
|
|
64
|
-
/** Map extension icon string names to lucide components */
|
|
65
|
-
const EXT_ICON_MAP: Record<string, React.ElementType> = {
|
|
66
|
-
"git-branch": GitBranch,
|
|
67
|
-
"database": Database,
|
|
68
|
-
"refresh": RefreshCw,
|
|
69
|
-
"plus": Plus,
|
|
70
|
-
"terminal": Terminal,
|
|
71
|
-
"settings": Settings,
|
|
72
|
-
"search": Search,
|
|
73
|
-
"file-code": FileCode,
|
|
74
|
-
"globe": Globe,
|
|
75
|
-
};
|
|
76
|
-
|
|
77
61
|
/** Format a keybinding combo for display (e.g. "Mod+G" → "⌘G" on Mac, "Ctrl+G" on others) */
|
|
78
62
|
function formatShortcut(combo: string): string {
|
|
79
63
|
if (!combo) return "";
|
|
@@ -296,7 +280,7 @@ export function CommandPalette({ open, onClose, initialQuery = "" }: { open: boo
|
|
|
296
280
|
id: `ext:${cmd.command}`,
|
|
297
281
|
label: cmd.title,
|
|
298
282
|
hint: cmd.category,
|
|
299
|
-
icon: (cmd.icon
|
|
283
|
+
icon: extensionIcon(cmd.icon) ?? Puzzle,
|
|
300
284
|
group: "action" as const,
|
|
301
285
|
keywords: `extension ${cmd.command} ${cmd.category ?? ""}`,
|
|
302
286
|
shortcut: shortcutCombo ? formatShortcut(shortcutCombo) : undefined,
|
|
@@ -278,14 +278,14 @@ export function AccountCard({
|
|
|
278
278
|
</button>
|
|
279
279
|
</TooltipTrigger>
|
|
280
280
|
<TooltipContent side="top" className="max-w-64 text-xs leading-relaxed">
|
|
281
|
-
|
|
281
|
+
Spreads the weekly quota across five weekdays, adding 20% per weekday. Weekend slots keep the previous cap; unused allowance carries forward. Daily slots start at the reset time and use UTC weekdays.
|
|
282
282
|
</TooltipContent>
|
|
283
283
|
</Tooltip>
|
|
284
284
|
</div>
|
|
285
285
|
<p className={`text-[10px] tabular-nums ${dailyGuard.enabled && dailyGuard.state.blocked ? "text-error" : "text-text-subtle"}`}>
|
|
286
286
|
{dailyGuard.enabled && dailyGuard.state.blocked
|
|
287
287
|
? `${Math.round(dailyGuard.state.used * 100)}% used / ${Math.round(dailyGuard.state.cap * 100)}% daily cap. New turns paused.`
|
|
288
|
-
: `
|
|
288
|
+
: `Weekday ${dailyGuard.state.day}/5, ${Math.round(dailyGuard.state.cap * 100)}% daily cap`}
|
|
289
289
|
</p>
|
|
290
290
|
</div>
|
|
291
291
|
{onDailyGuardToggle && (
|
|
@@ -138,18 +138,18 @@ export function CodexAccountsSection() {
|
|
|
138
138
|
</button>
|
|
139
139
|
</TooltipTrigger>
|
|
140
140
|
<TooltipContent side="top" className="max-w-64 text-xs leading-relaxed">
|
|
141
|
-
|
|
141
|
+
Spreads the weekly quota across five weekdays, adding 20% per weekday. Weekend slots keep the previous cap; unused allowance carries forward. Daily slots start at the reset time and use UTC weekdays. Turn it off any time to use the remaining quota freely.
|
|
142
142
|
</TooltipContent>
|
|
143
143
|
</Tooltip>
|
|
144
144
|
</div>
|
|
145
145
|
<p className={`text-[10px] tabular-nums ${a.dailyGuardEnabled && guard.blocked ? "text-error" : "text-text-subtle"}`}>
|
|
146
146
|
{a.dailyGuardEnabled && guard.blocked
|
|
147
147
|
? `${Math.round(guard.used * 100)}% used / ${Math.round(guard.cap * 100)}% daily cap. New turns paused.`
|
|
148
|
-
: `
|
|
148
|
+
: `Weekday ${guard.day}/5, ${Math.round(guard.cap * 100)}% daily cap`}
|
|
149
149
|
</p>
|
|
150
150
|
</div>
|
|
151
|
-
<span className="hidden" title={`
|
|
152
|
-
Daily guard {a.dailyGuardEnabled ? `·
|
|
151
|
+
<span className="hidden" title={`Weekday ${guard.day}/5: hold weekly usage at or below ${Math.round(guard.cap * 100)}% to last until reset.`}>
|
|
152
|
+
Daily guard {a.dailyGuardEnabled ? `· Weekday ${guard.day}/5 cap ${Math.round(guard.cap * 100)}%` : ""}
|
|
153
153
|
</span>
|
|
154
154
|
<Switch
|
|
155
155
|
checked={!!a.dailyGuardEnabled}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { useState, useEffect, useCallback } from "react";
|
|
2
2
|
import { Plus, Trash2, Power, PowerOff, Puzzle, FolderSymlink, Loader2 } from "@/lib/icons";
|
|
3
|
+
import { extensionIcon } from "@/lib/extension-icons";
|
|
3
4
|
import { Button } from "@/components/ui/button";
|
|
4
5
|
import { Input } from "@/components/ui/input";
|
|
5
6
|
import { api } from "@/lib/api-client";
|
|
@@ -165,7 +166,13 @@ export function ExtensionManagerSection() {
|
|
|
165
166
|
className="flex items-center gap-2 px-2.5 py-2 rounded-lg bg-muted/50 hover:bg-muted transition-colors"
|
|
166
167
|
>
|
|
167
168
|
<div className="size-8 rounded-md bg-background flex items-center justify-center shrink-0">
|
|
168
|
-
|
|
169
|
+
{/* The manifest's own icon, the same one its panels' tabs get.
|
|
170
|
+
A list of puzzle pieces distinguishes nothing, and the
|
|
171
|
+
field has been on the API all along. */}
|
|
172
|
+
{(() => {
|
|
173
|
+
const Icon = extensionIcon(ext.icon) ?? Puzzle;
|
|
174
|
+
return <Icon className="size-4 text-muted-foreground" />;
|
|
175
|
+
})()}
|
|
169
176
|
</div>
|
|
170
177
|
<div className="flex-1 min-w-0">
|
|
171
178
|
<p className="text-xs font-medium truncate">{ext.displayName || ext.id}</p>
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The icons an extension may ask for by name, and the glyph each name draws.
|
|
3
|
+
*
|
|
4
|
+
* A manifest names an icon the way VS Code's does — `{ "command":
|
|
5
|
+
* "git-graph.view", "icon": "git-branch" }` — and without a table like this one
|
|
6
|
+
* the name is inert: every panel an extension opens falls back to the generic
|
|
7
|
+
* puzzle piece, so a strip holding the graph, a blame, a file history and a
|
|
8
|
+
* rebase shows four identical tabs.
|
|
9
|
+
*
|
|
10
|
+
* Kebab-case, the way a manifest writes it. A name with no entry here is not an
|
|
11
|
+
* error — the caller's fallback draws instead — but `tests/unit/web/
|
|
12
|
+
* extension-icons.test.ts` fails when a *bundled* extension asks for one,
|
|
13
|
+
* because that is the case where the puzzle piece is a bug rather than a
|
|
14
|
+
* default.
|
|
15
|
+
*/
|
|
16
|
+
import {
|
|
17
|
+
Database, FileCode, FileDiff, GitBranch, GitCommitHorizontal, Globe, History, ListOrdered, Pencil,
|
|
18
|
+
Plus, RefreshCw, Search, Settings, Terminal, Trash2, Users,
|
|
19
|
+
} from "@/lib/icons";
|
|
20
|
+
import type { ElementType } from "react";
|
|
21
|
+
import type { ExtensionContributes } from "../../types/extension.ts";
|
|
22
|
+
|
|
23
|
+
export const EXTENSION_ICONS: Record<string, ElementType> = {
|
|
24
|
+
// Named by the panels the bundled Git Graph contributes.
|
|
25
|
+
"git-branch": GitBranch,
|
|
26
|
+
"git-commit": GitCommitHorizontal,
|
|
27
|
+
// Fluent draws no compare glyph and PPM re-exports no lucide one, so a
|
|
28
|
+
// comparison of two refs wears the same icon as any other diff in the app.
|
|
29
|
+
"git-compare": FileDiff,
|
|
30
|
+
history: History,
|
|
31
|
+
users: Users,
|
|
32
|
+
"list-ordered": ListOrdered,
|
|
33
|
+
// Named by tree-view item actions.
|
|
34
|
+
refresh: RefreshCw,
|
|
35
|
+
edit: Pencil,
|
|
36
|
+
trash: Trash2,
|
|
37
|
+
plus: Plus,
|
|
38
|
+
search: Search,
|
|
39
|
+
// General-purpose names an extension is likely to reach for.
|
|
40
|
+
database: Database,
|
|
41
|
+
terminal: Terminal,
|
|
42
|
+
settings: Settings,
|
|
43
|
+
"file-code": FileCode,
|
|
44
|
+
globe: Globe,
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/** The glyph for a manifest icon name, or undefined for one nothing draws. */
|
|
48
|
+
export function extensionIcon(name: string | undefined | null): ElementType | undefined {
|
|
49
|
+
return name ? EXTENSION_ICONS[name] : undefined;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* The icon of the command that opens a panel.
|
|
54
|
+
*
|
|
55
|
+
* A panel's viewType *is* its command id — `registerViewCommand` requires the
|
|
56
|
+
* two to match, because the frontend pairs them by slug — so the manifest entry
|
|
57
|
+
* that names the command already names the panel, and an extension needs no
|
|
58
|
+
* second place to declare one. The tab carries the slug (a trailing `.view`
|
|
59
|
+
* stripped), so both forms are compared.
|
|
60
|
+
*/
|
|
61
|
+
export function viewTypeIcon(
|
|
62
|
+
contributions: ExtensionContributes | null | undefined,
|
|
63
|
+
viewType: string | undefined,
|
|
64
|
+
): ElementType | undefined {
|
|
65
|
+
if (!contributions?.commands || !viewType) return undefined;
|
|
66
|
+
const command = contributions.commands.find(
|
|
67
|
+
(c) => c.command === viewType || c.command.replace(/\.view$/, "") === viewType,
|
|
68
|
+
);
|
|
69
|
+
return extensionIcon(command?.icon);
|
|
70
|
+
}
|
|
@@ -14,6 +14,8 @@ import type { ElementType } from "react";
|
|
|
14
14
|
import type { TabType } from "@/stores/tab-store";
|
|
15
15
|
import { fileIconElement } from "@/lib/file-icons";
|
|
16
16
|
import { PROVIDER_LOGOS } from "@/lib/provider-logos";
|
|
17
|
+
import { viewTypeIcon } from "@/lib/extension-icons";
|
|
18
|
+
import { useExtensionStore } from "@/stores/extension-store";
|
|
17
19
|
|
|
18
20
|
export const TAB_TYPE_ICONS: Record<TabType, LucideIcon> = {
|
|
19
21
|
terminal: Terminal,
|
|
@@ -70,5 +72,17 @@ export function getTabIcon(tab: TabIconSubject): ElementType {
|
|
|
70
72
|
const logo = PROVIDER_LOGOS[(tab.metadata?.providerId as string | undefined) ?? "claude"];
|
|
71
73
|
if (logo) return logo;
|
|
72
74
|
}
|
|
75
|
+
// A panel an extension opened is labelled with the icon its manifest gave the
|
|
76
|
+
// command that opens it — read here rather than stored on the tab, so a tab
|
|
77
|
+
// that was already open when the extension declared one picks it up too.
|
|
78
|
+
// Falls back to the puzzle piece, which is the honest answer for a panel
|
|
79
|
+
// whose extension has not said what it is.
|
|
80
|
+
if (tab.type === "extension" || tab.type === "extension-webview") {
|
|
81
|
+
const contributed = viewTypeIcon(
|
|
82
|
+
useExtensionStore.getState().contributions,
|
|
83
|
+
tab.metadata?.viewType as string | undefined,
|
|
84
|
+
);
|
|
85
|
+
if (contributed) return contributed;
|
|
86
|
+
}
|
|
73
87
|
return getTabTypeIcon(tab.type);
|
|
74
88
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{o as e}from"./rolldown-runtime-FhOqtrmT.js";import{C as t,S as n}from"./vendor-markdown-CuWCHIVb.js";import"./vendor-ui-DmZ-Mb-H.js";import{Br as r,Tn as i,V as a,Xt as o,ct as s,dn as c,kr as l,ln as u,nt as d,or as f,qn as p,st as m,wr as h,xt as g}from"./icons-DQjqk0lJ.js";import{n as _,r as v}from"./api-client-C1ZwRL4Y.js";import{n as y}from"./utils-Bmf_8h7Y.js";import"./portal-container-context-BarKmT4S.js";import{n as b}from"./use-is-mobile-TkcwP1Gx.js";import{n as x,t as S}from"./button-B9CTrsEf.js";import{a as C,i as w,n as T,o as E,r as D,t as O}from"./dialog-B84_DJQ8.js";import{t as k}from"./mobile-bottom-sheet-C3TniEP-.js";import"./use-visual-viewport-Lp878uzs.js";import{t as A}from"./input-C7Q8FxeL.js";import{Cn as j,G as M,J as N,K as P,Qt as ee,Sn as F,W as te,Y as I,dn as ne,q as L,rt as R,wn as z}from"./index-DU68xk06.js";import{addAccount as B,deleteAccount as V,exchangeOAuthCode as H,getAISettings as U,getAccountSettings as W,getOAuthUrl as G,getUsageHistory as re,importAccounts as K,patchAccount as q,testAccountToken as ie,testExport as J,testRawToken as ae,updateAccountSettings as Y}from"./api-settings-_7Q-ULxp.js";import{a as oe,c as se,d as ce,f as le,i as ue,n as de,o as fe,r as pe,s as me,t as he,u as ge}from"./codex-daily-guard-BSccLRGT.js";var X=e(t(),1),Z=n(),_e=[`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`,`Sun`],Q=Array.from({length:24},(e,t)=>t);function ve(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 ye(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 be(e){return Q.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 xe(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,X.useState)(null),[r,i]=(0,X.useState)(!0),[a,o]=(0,X.useState)(`5h`);(0,X.useEffect)(()=>{i(!0),re(e).then(n).catch(()=>n([])).finally(()=>i(!1))},[e]);let s=(0,X.useMemo)(()=>t?ve(t,a):null,[t,a]),c=(0,X.useMemo)(()=>s?ye(s):[],[s]),l=(0,X.useMemo)(()=>s?be(s):[],[s]),d=Math.max(...c,.01);if(Math.max(...l,.01),r)return(0,Z.jsx)(`div`,{className:`flex items-center justify-center py-3`,children:(0,Z.jsx)(u,{className:`size-3 animate-spin text-text-subtle`})});if(!t||t.length===0)return(0,Z.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,Z.jsxs)(`div`,{className:`mt-2 space-y-2`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Z.jsx)(`span`,{className:`text-[10px] font-medium text-text-subtle`,children:`Usage Pattern (7d)`}),(0,Z.jsxs)(`div`,{className:`flex gap-0.5 text-[9px]`,children:[(0,Z.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,Z.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,Z.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,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`span`,{className:`text-[9px] text-text-subtle`,children:`Avg usage by day of week`}),(0,Z.jsx)(`div`,{className:`flex flex-col gap-[2px] mt-0.5`,children:_e.map((e,t)=>{let n=c[t]??0;return(0,Z.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,Z.jsx)(`span`,{className:`text-[8px] text-text-subtle w-5 shrink-0 text-right tabular-nums`,children:e}),(0,Z.jsx)(`div`,{className:`flex-1 h-2.5 bg-surface-elevated rounded-sm overflow-hidden`,children:(0,Z.jsx)(`div`,{className:`h-full rounded-sm transition-all ${Se(n)}`,style:{width:`${Math.round(n/d*100)}%`}})}),(0,Z.jsxs)(`span`,{className:`text-[8px] text-text-subtle w-6 shrink-0 text-right tabular-nums`,children:[Math.round(n*100),`%`]})]},e)})})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`span`,{className:`text-[9px] text-text-subtle`,children:`Avg usage by hour (0h-23h)`}),(0,Z.jsx)(`div`,{className:`flex gap-[1px] mt-0.5`,children:Q.map(e=>{let t=l[e]??0;return(0,Z.jsxs)(`div`,{className:`flex-1 flex flex-col items-center gap-[1px]`,children:[(0,Z.jsx)(`div`,{className:`w-full aspect-square rounded-[2px] ${xe(t)}`,title:`${e}:00 — avg ${Math.round(t*100)}% usage`}),e%6==0&&(0,Z.jsx)(`span`,{className:`text-[7px] text-text-subtle tabular-nums`,children:e})]},e)})})]}),s&&(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`span`,{className:`text-[9px] text-text-subtle`,children:`Day x Hour heatmap`}),(0,Z.jsxs)(`div`,{className:`flex flex-col gap-[1px] mt-0.5`,children:[_e.map((e,t)=>(0,Z.jsxs)(`div`,{className:`flex items-center gap-[1px]`,children:[(0,Z.jsx)(`span`,{className:`text-[7px] text-text-subtle w-4 shrink-0 text-right`,children:e.charAt(0)}),Q.map(n=>{let r=s[t][n];return(0,Z.jsx)(`div`,{className:`flex-1 aspect-square rounded-[1px] ${xe(r.avg)}`,title:`${e} ${n}:00 — ${r.count>0?`avg ${Math.round(r.avg*100)}% (${r.count} samples)`:`no data`}`},n)})]},e)),(0,Z.jsxs)(`div`,{className:`flex items-center gap-[1px]`,children:[(0,Z.jsx)(`span`,{className:`w-4 shrink-0`}),Q.map(e=>(0,Z.jsx)(`div`,{className:`flex-1 text-center`,children:e%6==0&&(0,Z.jsx)(`span`,{className:`text-[7px] text-text-subtle tabular-nums`,children:e})},e))]})]})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[8px] text-text-subtle`,children:[(0,Z.jsx)(`span`,{children:`Low`}),(0,Z.jsxs)(`div`,{className:`flex gap-[2px]`,children:[(0,Z.jsx)(`div`,{className:`size-2 rounded-[1px] bg-success/30`}),(0,Z.jsx)(`div`,{className:`size-2 rounded-[1px] bg-success/60`}),(0,Z.jsx)(`div`,{className:`size-2 rounded-[1px] bg-warning/50`}),(0,Z.jsx)(`div`,{className:`size-2 rounded-[1px] bg-warning/80`}),(0,Z.jsx)(`div`,{className:`size-2 rounded-[1px] bg-error/80`})]}),(0,Z.jsx)(`span`,{children:`High`}),(0,Z.jsx)(`span`,{className:`ml-1`,children:`|`}),(0,Z.jsx)(`div`,{className:`size-2 rounded-[1px] bg-surface-elevated border border-border/30`}),(0,Z.jsx)(`span`,{children:`No data`})]})]})}function we({profile:e,accountId:t,onClose:n}){let i=[[`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,Z.jsxs)(`section`,{className:`space-y-2 border-t border-border pt-3`,"data-testid":`account-profile-panel`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Z.jsx)(`h3`,{className:`text-sm font-medium`,children:`Profile`}),(0,Z.jsx)(`button`,{className:`p-2 text-muted-foreground hover:text-foreground cursor-pointer`,onClick:n,"aria-label":`Close profile`,children:(0,Z.jsx)(r,{className:`size-4`})})]}),(0,Z.jsx)(`div`,{className:`grid grid-cols-[80px_1fr] gap-x-3 gap-y-1 text-xs`,children:i.map(([e,t])=>t?(0,Z.jsxs)(`span`,{className:`contents`,children:[(0,Z.jsx)(`span`,{className:`text-muted-foreground`,children:e}),(0,Z.jsx)(`span`,{className:`break-all`,children:t})]},e):null)}),(0,Z.jsx)(Ce,{accountId:t})]})}function Te({display:e,onConfirm:t,onCancel:n}){let r=b(),i=(0,Z.jsxs)(`div`,{className:`space-y-4`,"data-testid":`account-delete-confirm`,children:[(0,Z.jsxs)(`p`,{className:`text-sm`,children:[`Remove `,(0,Z.jsx)(`span`,{className:`font-medium`,children:e}),`?`]}),(0,Z.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,Z.jsxs)(`div`,{className:`flex flex-col-reverse md:flex-row gap-2 md:justify-end pt-2`,children:[(0,Z.jsx)(S,{variant:`outline`,onClick:n,className:`min-h-11`,children:`Cancel`}),(0,Z.jsx)(S,{variant:`destructive`,autoFocus:!1,onClick:t,className:`min-h-11`,children:`Remove account`})]})]});return r?(0,Z.jsx)(k,{open:!0,onClose:n,children:(0,Z.jsxs)(`div`,{className:`px-4 pb-4`,children:[(0,Z.jsx)(`h2`,{className:`text-base font-semibold mb-3`,children:`Remove account`}),i]})}):(0,Z.jsx)(O,{open:!0,onOpenChange:e=>{e||n()},children:(0,Z.jsxs)(T,{className:`sm:max-w-sm`,children:[(0,Z.jsx)(C,{children:(0,Z.jsx)(E,{className:`text-sm`,children:`Remove account`})}),i]})})}function Ee({open:e,onOpenChange:t,onSuccess:n}){let[r,i]=(0,X.useState)(``),[a,o]=(0,X.useState)(``),[s,c]=(0,X.useState)(!1),[l,d]=(0,X.useState)(null),[f,p]=(0,X.useState)(null),[m,h]=(0,X.useState)(``),[g,_]=(0,X.useState)(!1),[v,y]=(0,X.useState)(`idle`);function b(){p(null),h(``),y(`idle`),d(null)}function x(){t(!1),b(),i(``),o(``),d(null)}async function k(){_(!0),d(null);try{let{url:e,state:t}=await G();p(t),y(`waiting`),window.open(e,`_blank`)}catch(e){d(e.message)}_(!1)}async function j(){if(!(!m.trim()||!f)){_(!0),d(null);try{let e=m.trim();e.includes(`#`)&&(e=e.split(`#`)[0]??e);let t=await H(e,f);x(),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)}_(!1)}}async function M(){if(r.trim()){c(!0),d(null);try{let e=await B({apiKey:r.trim(),label:a.trim()||void 0});x(),n(e?.status===`disabled`?`Token updated. This account is still disabled — enable it to use it.`:`Account added!`)}catch(e){d(e.message)}c(!1)}}let N=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,Z.jsx)(O,{open:e,onOpenChange:e=>{e||x()},children:(0,Z.jsxs)(T,{className:`sm:max-w-md`,children:[(0,Z.jsxs)(C,{children:[(0,Z.jsx)(E,{className:`text-sm`,children:`Add Claude Account`}),(0,Z.jsx)(D,{className:`text-xs leading-relaxed`,children:`Connect via OAuth (recommended) or paste a token manually.`})]}),(0,Z.jsxs)(`div`,{className:`space-y-3`,children:[(0,Z.jsxs)(`div`,{className:`rounded-md border p-3 space-y-2`,children:[(0,Z.jsx)(`p`,{className:`text-[11px] font-medium`,children:`Recommended: Login with Claude`}),v===`idle`?(0,Z.jsx)(S,{size:`sm`,className:`w-full h-8 text-xs`,onClick:k,disabled:g,children:g?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(u,{className:`size-3 animate-spin mr-1`}),` Opening...`]}):`Login with Claude`}):(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[(0,Z.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:`Authorize in the opened tab, then paste the code:`}),(0,Z.jsx)(A,{placeholder:`Paste code here...`,value:m,onChange:e=>h(e.target.value),className:`text-xs h-8 font-mono`,autoFocus:!0}),(0,Z.jsxs)(`div`,{className:`flex gap-1.5`,children:[(0,Z.jsx)(S,{size:`sm`,className:`flex-1 h-7 text-xs`,onClick:j,disabled:!m.trim()||g,children:g?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(u,{className:`size-3 animate-spin mr-1`}),` Connecting...`]}):`Connect`}),(0,Z.jsx)(S,{size:`sm`,variant:`ghost`,className:`h-7 text-xs`,onClick:b,children:`Cancel`})]})]})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(`div`,{className:`flex-1 border-t`}),(0,Z.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`or paste token`}),(0,Z.jsx)(`div`,{className:`flex-1 border-t`})]}),(0,Z.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Z.jsx)(R,{htmlFor:`add-token`,className:`text-xs`,children:`Token`}),(0,Z.jsx)(A,{id:`add-token`,type:`password`,placeholder:`sk-ant-...`,value:r,onChange:e=>i(e.target.value),className:`text-xs h-8 font-mono`}),N&&(0,Z.jsxs)(`p`,{className:`text-[10px] text-muted-foreground`,children:[`Detected: `,N]})]}),(0,Z.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Z.jsx)(R,{htmlFor:`add-label`,className:`text-xs`,children:`Label (optional)`}),(0,Z.jsx)(A,{id:`add-label`,placeholder:`e.g. Personal, Work`,value:a,onChange:e=>o(e.target.value),className:`text-xs h-8`})]})]}),l&&(0,Z.jsx)(`div`,{className:`text-[11px] p-2 rounded bg-error/10 text-error`,children:l}),(0,Z.jsxs)(w,{children:[(0,Z.jsx)(S,{size:`sm`,variant:`outline`,className:`text-xs h-7`,onClick:x,children:`Cancel`}),(0,Z.jsx)(S,{size:`sm`,className:`text-xs h-7`,onClick:M,disabled:!r.trim()||s,children:s?`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:r,onMessage:i}){let a=n.filter(e=>e.hasRefreshToken),[o,s]=(0,X.useState)(new Set),[l,f]=(0,X.useState)(``),[p,h]=(0,X.useState)(!1),[g,_]=(0,X.useState)(!1),[y,b]=(0,X.useState)(!1),[x,k]=(0,X.useState)(!1);e&&!x&&(s(r?new Set([r]):new Set(a.map(e=>e.id))),k(!0)),!e&&x&&k(!1);function j(){t(!1),f(``),h(!1),_(!1)}async function M(e){if(o.size===0)return;b(!0);let t=l.trim()||`ppm-hienlh`;try{let n={"Content-Type":`application/json`},r=v();r&&(n.Authorization=`Bearer ${r}`);let a=await fetch(`/api/accounts/export`,{method:`POST`,headers:n,body:JSON.stringify({password:t,accountIds:[...o],includeRefreshToken:p,refreshBeforeExport:g})});if(!a.ok){let e=await a.json();throw Error(e.error??`Export failed: ${a.status}`)}let s=await a.text();e&&await ee(s)?i?.(`Backup copied to clipboard!`):(De(s),i?.(`Backup downloaded.`)),j()}catch{}b(!1)}let N=o.size>0&&!y;return(0,Z.jsx)(O,{open:e,onOpenChange:e=>{e||j()},children:(0,Z.jsxs)(T,{className:`sm:max-w-md`,children:[(0,Z.jsxs)(C,{children:[(0,Z.jsxs)(E,{className:`text-sm flex items-center gap-1.5`,children:[(0,Z.jsx)(c,{className:`size-3.5`}),` Export Accounts`]}),(0,Z.jsx)(D,{className:`text-xs`,children:`Select accounts and set a password to protect the backup.`})]}),(0,Z.jsxs)(`div`,{className:`space-y-3`,children:[(0,Z.jsxs)(`div`,{className:`space-y-1`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between mb-1`,children:[(0,Z.jsx)(`p`,{className:`text-[11px] font-medium text-muted-foreground`,children:`Accounts to export`}),(0,Z.jsx)(`button`,{className:`text-[10px] text-primary hover:underline cursor-pointer`,onClick:()=>s(o.size===a.length?new Set:new Set(a.map(e=>e.id))),children:o.size===a.length?`Deselect all`:`Select all`})]}),a.length===0?(0,Z.jsx)(`p`,{className:`text-[10px] text-muted-foreground p-2 border rounded`,children:`No exportable accounts.`}):(0,Z.jsx)(`div`,{className:`max-h-36 overflow-y-auto space-y-1 border rounded p-2`,children:a.map(e=>(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,id:`exp-${e.id}`,checked:o.has(e.id),onChange:t=>{let n=new Set(o);t.target.checked?n.add(e.id):n.delete(e.id),s(n)},className:`size-3.5 accent-primary cursor-pointer`}),(0,Z.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,Z.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Z.jsxs)(R,{className:`text-xs`,children:[`Password `,(0,Z.jsx)(`span`,{className:`text-muted-foreground font-normal`,children:`(optional)`})]}),(0,Z.jsx)(A,{type:`password`,placeholder:`Leave empty for default`,value:l,onChange:e=>f(e.target.value),className:`text-xs h-8`,autoComplete:`new-password`})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,id:`exp-full`,checked:p,onChange:e=>h(e.target.checked),className:`size-3.5 accent-primary cursor-pointer`}),(0,Z.jsx)(`label`,{htmlFor:`exp-full`,className:`text-[11px] cursor-pointer`,children:`Include refresh tokens (full transfer)`})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,id:`exp-refresh`,checked:g,onChange:e=>_(e.target.checked),className:`size-3.5 accent-primary cursor-pointer`}),(0,Z.jsx)(`label`,{htmlFor:`exp-refresh`,className:`text-[11px] cursor-pointer`,children:`Refresh tokens before export`})]}),p?(0,Z.jsxs)(`div`,{className:`rounded-md border border-error/30 bg-error/5 p-2.5`,children:[(0,Z.jsx)(`p`,{className:`text-[10px] font-medium text-error`,children:`Full transfer — source accounts will expire`}),(0,Z.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:`Refresh tokens included. Source machine expires in ~1h after target refreshes.`})]}):g?(0,Z.jsx)(`div`,{className:`rounded-md border border-warning/30 bg-warning/5 p-2.5`,children:(0,Z.jsx)(`p`,{className:`text-[10px] font-medium text-warning`,children:`Refresh before export — invalidates previous shares`})}):(0,Z.jsx)(`div`,{className:`rounded-md border border-success/30 bg-success/5 p-2.5`,children:(0,Z.jsx)(`p`,{className:`text-[10px] font-medium text-success`,children:`Share current token (safe)`})}),(0,Z.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:`Encrypted with AES-256-GCM + scrypt.`})]}),(0,Z.jsxs)(w,{className:`gap-1.5 flex-col sm:flex-row`,children:[(0,Z.jsx)(S,{size:`sm`,variant:`outline`,className:`text-xs h-7 cursor-pointer`,onClick:j,children:`Cancel`}),(0,Z.jsxs)(S,{size:`sm`,variant:`outline`,className:`text-xs h-7 cursor-pointer`,disabled:!N,onClick:()=>M(!0),children:[(0,Z.jsx)(d,{className:`size-3 mr-1`}),` Copy`]}),(0,Z.jsx)(S,{size:`sm`,className:`text-xs h-7 cursor-pointer`,disabled:!N,onClick:()=>M(!1),children:y?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(u,{className:`size-3 animate-spin mr-1`}),` Exporting...`]}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(m,{className:`size-3 mr-1`}),` Download`]})})]})]})})}function ke({open:e,onOpenChange:t,onSuccess:n}){let[r,i]=(0,X.useState)(``),[a,o]=(0,X.useState)(``),[s,l]=(0,X.useState)(!1),[d,f]=(0,X.useState)(null);function p(){t(!1),i(``),o(``),f(null)}async function m(){if(r.trim()){l(!0),f(null);try{let e=await K({data:r.trim(),password:a.trim()||`ppm-hienlh`});p(),n(`Imported ${e.imported} account(s)`)}catch(e){f(e.message||`Import failed`)}l(!1)}}return(0,Z.jsx)(O,{open:e,onOpenChange:e=>{e||p()},children:(0,Z.jsxs)(T,{className:`sm:max-w-md`,children:[(0,Z.jsxs)(C,{children:[(0,Z.jsxs)(E,{className:`text-sm flex items-center gap-1.5`,children:[(0,Z.jsx)(c,{className:`size-3.5`}),` Import Accounts`]}),(0,Z.jsx)(D,{className:`text-xs`,children:`Paste backup data and enter the export password. Imported accounts are temporary (~1h).`})]}),(0,Z.jsxs)(`div`,{className:`space-y-3`,children:[(0,Z.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Z.jsx)(R,{className:`text-xs`,children:`Backup data`}),(0,Z.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,Z.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Z.jsxs)(R,{className:`text-xs`,children:[`Password `,(0,Z.jsx)(`span`,{className:`text-muted-foreground font-normal`,children:`(optional)`})]}),(0,Z.jsx)(A,{type:`password`,placeholder:`Leave empty for default`,value:a,onChange:e=>o(e.target.value),className:`text-xs h-8`,autoComplete:`current-password`})]})]}),d&&(0,Z.jsx)(`div`,{className:`text-[11px] p-2 rounded bg-error/10 text-error`,children:d}),(0,Z.jsxs)(w,{children:[(0,Z.jsx)(S,{size:`sm`,variant:`outline`,className:`text-xs h-7 cursor-pointer`,onClick:p,children:`Cancel`}),(0,Z.jsx)(S,{size:`sm`,className:`text-xs h-7 cursor-pointer`,disabled:!r.trim()||s,onClick:m,children:s?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(u,{className:`size-3 animate-spin mr-1`}),` Importing...`]}):`Import`})]})]})})}var $=typeof window<`u`?window.matchMedia(`(min-width: 768px)`):null;function Ae(e){return $?.addEventListener(`change`,e),()=>$?.removeEventListener(`change`,e)}function je(){return $?.matches??!0}function Me(){let[e,t]=(0,X.useState)(null),[n,r]=(0,X.useState)(!0);return(0,X.useEffect)(()=>{r(!0),W().then(t).finally(()=>r(!1))},[]),n?(0,Z.jsx)(`p`,{className:`text-xs text-text-subtle py-4 text-center`,children:`Loading...`}):e?(0,Z.jsxs)(`div`,{className:`space-y-4`,children:[(0,Z.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Z.jsx)(`label`,{className:`text-xs font-medium text-text-primary`,children:`Rotation Strategy`}),(0,Z.jsxs)(te,{value:e.strategy,onValueChange:async e=>{t(await Y({strategy:e}))},children:[(0,Z.jsx)(L,{className:`w-full h-9 text-xs`,children:(0,Z.jsx)(N,{})}),(0,Z.jsxs)(M,{children:[(0,Z.jsx)(P,{value:`round-robin`,children:`Round-robin`}),(0,Z.jsx)(P,{value:`fill-first`,children:`Fill-first`}),(0,Z.jsx)(P,{value:`lowest-usage`,children:`Lowest usage`})]})]}),(0,Z.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,Z.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Z.jsx)(`label`,{className:`text-xs font-medium text-text-primary`,children:`Max Retry`}),(0,Z.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 Y({maxRetry:n}))}}),(0,Z.jsx)(`p`,{className:`text-[10px] text-text-subtle`,children:`How many accounts to try on failure. 0 = try all available accounts.`})]}),(0,Z.jsxs)(`div`,{className:`space-y-1.5 border-t border-border pt-3`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Z.jsx)(`label`,{className:`text-xs font-medium text-text-primary`,children:`Cooldown parking`}),(0,Z.jsx)(I,{checked:e.cooldownEnabled,onCheckedChange:async e=>{t(await Y({cooldownEnabled:e}))}})]}),(0,Z.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,Z.jsxs)(`div`,{className:`flex items-center justify-between text-xs border-t border-border pt-3`,children:[(0,Z.jsx)(`span`,{className:`text-text-subtle`,children:`Active accounts`}),(0,Z.jsx)(`span`,{className:`font-medium text-text-primary`,children:e.activeCount})]})]}):(0,Z.jsx)(`p`,{className:`text-xs text-text-subtle py-4 text-center`,children:`Failed to load settings`})}function Ne({open:e,onOpenChange:t}){let n=(0,X.useSyncExternalStore)(Ae,je);return e?n?(0,Z.jsx)(O,{open:e,onOpenChange:t,children:(0,Z.jsxs)(T,{className:`sm:max-w-sm`,children:[(0,Z.jsx)(C,{children:(0,Z.jsxs)(E,{className:`text-sm flex items-center gap-2`,children:[(0,Z.jsx)(f,{className:`size-4`}),` Rotation & Retry`]})}),(0,Z.jsx)(Me,{})]})}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.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,Z.jsxs)(`div`,{className:y(`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,Z.jsx)(`div`,{className:`flex justify-center pt-3 pb-1`,children:(0,Z.jsx)(`div`,{className:`w-10 h-1 rounded-full bg-border`})}),(0,Z.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-2 border-b border-border`,children:[(0,Z.jsxs)(`span`,{className:`text-sm font-semibold flex items-center gap-2`,children:[(0,Z.jsx)(f,{className:`size-4`}),` Rotation & Retry`]}),(0,Z.jsx)(`button`,{onClick:()=>t(!1),className:`flex items-center justify-center size-7 rounded-md hover:bg-surface-elevated transition-colors`,children:(0,Z.jsx)(r,{className:`size-4`})})]}),(0,Z.jsx)(`div`,{className:`px-4 py-4 pb-8`,children:(0,Z.jsx)(Me,{})})]})]}):null}var Pe=x(`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 Fe({className:e,variant:t,...n}){return(0,Z.jsx)(`div`,{className:y(Pe({variant:t}),e),...n})}function Ie(e){let t=Math.floor(Date.now()/1e3);return e>t?`${Math.floor((e-t)/60)}m`:`exp`}function Le({accounts:e}){let[t,n]=(0,X.useState)([]),[r,i]=(0,X.useState)(!1),[a,o]=(0,X.useState)(!1),[s,c]=(0,X.useState)(new Map),l=e.filter(e=>e.hasRefreshToken);async function d(){if(l.length!==0){i(!0);try{let e=await J(l.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){c(t=>new Map(t).set(e,{loading:!0}));try{let n=await ae(t);c(t=>new Map(t).set(e,{loading:!1,...n}))}catch(t){c(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 m(){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,Z.jsxs)(`section`,{className:`border-t pt-4 space-y-2`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,Z.jsx)(`p`,{className:`text-xs font-medium`,children:`Simulate export`}),t.length>0&&(0,Z.jsxs)(`span`,{className:`text-[10px] text-muted-foreground`,children:[t.length,` round(s)`]})]}),(0,Z.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.`}),l.length===0?(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`No OAuth account with a refresh token to export.`}):(0,Z.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Z.jsx)(I,{id:`sim-include-refresh`,checked:a,onCheckedChange:o,className:`cursor-pointer`}),(0,Z.jsx)(R,{htmlFor:`sim-include-refresh`,className:`text-[11px] cursor-pointer`,children:`Include refresh tokens`})]}),(0,Z.jsx)(S,{size:`sm`,className:`h-7 text-xs cursor-pointer`,disabled:r,onClick:()=>void d(),children:r?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(u,{className:`size-3 animate-spin mr-1`}),` Exporting...`]}):`Run export #${t.length+1}`})]}),t.length>0&&(0,Z.jsxs)(`div`,{className:`space-y-3`,children:[(0,Z.jsxs)(S,{size:`sm`,variant:`outline`,className:`w-full h-7 text-[11px] cursor-pointer`,onClick:m,children:[`Test all tokens (`,t.reduce((e,t)=>e+t.items.length*3,0),`)`]}),t.map(e=>(0,Z.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsxs)(`p`,{className:`text-xs font-medium text-primary`,children:[`Round #`,e.round]}),(0,Z.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:e.time}),(0,Z.jsx)(Fe,{variant:e.includeRefresh?`destructive`:`secondary`,className:`text-[9px] px-1 py-0`,children:e.includeRefresh?`with refresh`:`access only`})]}),e.items.map(t=>(0,Z.jsxs)(`div`,{className:`p-2 rounded-lg border bg-card space-y-1.5`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(`span`,{className:`text-[11px] font-medium`,children:t.label??t.email??t.id.slice(0,8)}),t.tokenChanged&&(0,Z.jsx)(Fe,{variant:`secondary`,className:`text-[9px] px-1 py-0`,children:`DB token changed`})]}),p(e,t).map(e=>{let t=s.get(e.key);return(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px]`,children:[(0,Z.jsx)(`span`,{className:`w-20 shrink-0 text-muted-foreground text-[10px]`,children:e.label}),(0,Z.jsx)(`code`,{className:`flex-1 truncate font-mono text-[10px] bg-muted px-1 rounded`,children:e.preview??`N/A`}),e.expires&&(0,Z.jsx)(`span`,{className:`text-[10px] text-muted-foreground shrink-0`,children:Ie(e.expires)}),e.token?(0,Z.jsx)(S,{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,Z.jsx)(u,{className:`size-3 animate-spin`}):`Test`}):(0,Z.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`-`}),t&&!t.loading&&(0,Z.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 Re(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 ze({open:e,onOpenChange:t,accounts:n}){let[r,i]=(0,X.useState)(new Map),[a,o]=(0,X.useState)(!1);async function s(e){i(t=>new Map(t).set(e,{loading:!0}));try{let t=await ie(e,a);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 c(){for(let e of n.filter(e=>e.expiresAt!==null))s(e.id)}return(0,Z.jsx)(O,{open:e,onOpenChange:t,children:(0,Z.jsxs)(T,{className:`sm:max-w-xl max-h-[85vh] flex flex-col`,children:[(0,Z.jsxs)(C,{children:[(0,Z.jsxs)(E,{className:`text-sm flex items-center gap-1.5`,children:[(0,Z.jsx)(g,{className:`size-4`}),` Token Test`]}),(0,Z.jsx)(D,{className:`text-xs`,children:`Probe stored tokens for validity. Nothing is modified.`})]}),(0,Z.jsxs)(`div`,{className:`space-y-4 overflow-y-auto flex-1 pr-1`,children:[(0,Z.jsxs)(`section`,{className:`space-y-2`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,Z.jsx)(`p`,{className:`text-xs font-medium`,children:`Current tokens`}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Z.jsx)(I,{id:`token-test-refresh`,checked:a,onCheckedChange:o,className:`cursor-pointer`}),(0,Z.jsx)(R,{htmlFor:`token-test-refresh`,className:`text-[11px] cursor-pointer`,children:`Also test refresh`})]}),(0,Z.jsx)(S,{size:`sm`,variant:`outline`,className:`h-7 text-xs cursor-pointer`,onClick:c,children:`Test all`})]})]}),n.length===0&&(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`No accounts to test.`}),(0,Z.jsx)(`div`,{className:`space-y-1.5`,children:n.map(e=>{let t=r.get(e.id),n=t?.result?.accessToken.status;return(0,Z.jsxs)(`div`,{className:`p-2 rounded border bg-card space-y-1`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Z.jsx)(`span`,{className:`text-xs font-medium truncate block`,children:e.label??e.email??e.id.slice(0,8)}),e.expiresAt&&(0,Z.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:Re(e.expiresAt)})]}),(0,Z.jsx)(S,{size:`sm`,variant:`outline`,className:`h-7 text-xs cursor-pointer shrink-0`,disabled:t?.loading,onClick:()=>void s(e.id),children:t?.loading?(0,Z.jsx)(u,{className:`size-3 animate-spin`}):`Test`})]}),t&&!t.loading&&(0,Z.jsxs)(`div`,{className:`text-[11px] pl-2 border-l-2 border-muted`,children:[t.error&&(0,Z.jsx)(`p`,{className:`text-error`,children:t.error}),n&&(0,Z.jsxs)(`span`,{className:n.startsWith(`valid`)?`text-success`:`text-error`,children:[n,t.result?.accessToken.code?` (${t.result.accessToken.code})`:``]})]})]},e.id)})})]}),(0,Z.jsx)(Le,{accounts:n})]}),(0,Z.jsx)(w,{children:(0,Z.jsx)(S,{size:`sm`,variant:`outline`,className:`text-xs cursor-pointer`,onClick:()=>t(!1),children:`Close`})})]})})}function Be(){let{usages:e,accounts:t,activeAccountId:n,initialLoading:r,refreshing:i,flashIds:a,reload:s}=pe(),[c,d]=(0,X.useState)(null),[h,_]=(0,X.useState)(null),[v,y]=(0,X.useState)(null),[b,x]=(0,X.useState)(null),[C,w]=(0,X.useState)(null),[T,E]=(0,X.useState)(null);function D(e){s(),e&&d(e)}async function O(e,t){_(e);try{await q(e,{status:t===`disabled`?`active`:`disabled`})}catch(e){d(e.message)}_(null),s()}async function k(){if(v){try{await V(v.id),d(`Account "${v.display}" removed.`),s()}catch(e){d(`Failed to remove: ${e.message}`)}y(null)}}let A=new Map(t.map(e=>[e.id,e])),j=e[0]?.usage.lastFetchedAt;return(0,Z.jsxs)(`div`,{className:`space-y-4`,children:[(0,Z.jsx)(me,{description:`Connect multiple Claude accounts. PPM rotates between them automatically to avoid rate limits.`,onRefresh:()=>void s(),refreshing:i,disabled:r,actions:(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(S,{size:`sm`,className:`cursor-pointer gap-1.5`,onClick:()=>E(`add`),children:[(0,Z.jsx)(p,{className:`size-4`}),` Add account`]}),(0,Z.jsxs)(S,{size:`sm`,variant:`outline`,className:`cursor-pointer gap-1.5`,onClick:()=>{w(null),E(`export`)},children:[(0,Z.jsx)(m,{className:`size-4`}),` Export`]}),(0,Z.jsxs)(S,{size:`sm`,variant:`outline`,className:`cursor-pointer gap-1.5`,onClick:()=>E(`import`),children:[(0,Z.jsx)(l,{className:`size-4`}),` Import`]}),(0,Z.jsxs)(S,{size:`sm`,variant:`outline`,className:`cursor-pointer gap-1.5`,onClick:()=>E(`rotation`),children:[(0,Z.jsx)(f,{className:`size-4`}),` Rotation`]}),(0,Z.jsxs)(S,{size:`sm`,variant:`outline`,className:`cursor-pointer gap-1.5`,onClick:()=>E(`token-test`),children:[(0,Z.jsx)(g,{className:`size-4`}),` Token test`]})]})}),(0,Z.jsx)(se,{message:c,onDismiss:()=>d(null)}),(0,Z.jsxs)(`section`,{className:`space-y-2`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Z.jsx)(`h3`,{className:`text-sm font-medium`,children:`Accounts`}),j&&(0,Z.jsxs)(`span`,{className:`text-[10px] text-muted-foreground`,children:[`usage `,ce(new Date(j).getTime())]})]}),r?(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 py-6 text-xs text-muted-foreground`,children:[(0,Z.jsx)(u,{className:`size-4 animate-spin`}),` Loading accounts...`]}):e.length===0?(0,Z.jsxs)(`div`,{className:`flex flex-col items-center gap-2 py-8 text-center`,children:[(0,Z.jsx)(o,{className:`size-5 text-muted-foreground`}),(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`No accounts connected yet.`}),(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Add one to start using PPM.`})]}):(0,Z.jsx)(oe,{children:e.map(e=>(0,Z.jsx)(ue,{layout:`strip`,entry:e,isActive:e.accountId===n,accountInfo:A.get(e.accountId),onToggle:O,toggling:h===e.accountId,onDelete:(e,t)=>y({id:e,display:t}),onExport:e=>{w(e),E(`export`)},onViewProfile:(e,t)=>x({profile:e,accountId:t}),flash:a.has(e.accountId)},e.accountId))})]}),b&&(0,Z.jsx)(we,{profile:b.profile,accountId:b.accountId,onClose:()=>x(null)}),v&&(0,Z.jsx)(Te,{display:v.display,onConfirm:()=>void k(),onCancel:()=>y(null)}),(0,Z.jsx)(Ee,{open:T===`add`,onOpenChange:e=>E(e?`add`:null),onSuccess:D}),(0,Z.jsx)(Oe,{open:T===`export`,onOpenChange:e=>{E(e?`export`:null),e||w(null)},accounts:t,preselectId:C,onMessage:d}),(0,Z.jsx)(ke,{open:T===`import`,onOpenChange:e=>E(e?`import`:null),onSuccess:D}),(0,Z.jsx)(Ne,{open:T===`rotation`,onOpenChange:e=>E(e?`rotation`:null)}),(0,Z.jsx)(ze,{open:T===`token-test`,onOpenChange:e=>E(e?`token-test`:null),accounts:t})]})}function Ve({open:e,onOpenChange:t,label:n,onLabelChange:r,apiKey:a,onApiKeyChange:c,adding:l,onAddApiKey:d,deviceWaiting:f,onStartDevice:p,device:m,error:h,browser:g,onStartBrowser:_,loginStarting:v,callbackUrl:y,onCallbackUrlChange:b,submittingCallback:x,onSubmitCallback:k}){let j=v||f||!!g||l;return(0,Z.jsx)(O,{open:e,onOpenChange:t,children:(0,Z.jsxs)(T,{className:`sm:max-w-md max-h-[90dvh] overflow-y-auto`,children:[(0,Z.jsxs)(C,{children:[(0,Z.jsx)(E,{className:`text-sm`,children:`Add Codex Account`}),(0,Z.jsx)(D,{className:`text-xs leading-relaxed`,children:`Choose browser login, a device code, or an OpenAI API key.`})]}),(0,Z.jsxs)(`div`,{className:`space-y-3`,children:[(0,Z.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Z.jsx)(R,{htmlFor:`codex-label`,className:`text-xs`,children:`Label (optional)`}),(0,Z.jsx)(A,{id:`codex-label`,placeholder:`e.g. Personal, Work`,value:n,onChange:e=>r(e.target.value),disabled:j,className:`text-xs`})]}),(0,Z.jsxs)(`div`,{className:`rounded-md border p-3 space-y-2`,children:[(0,Z.jsx)(`p`,{className:`text-[11px] font-medium`,children:`Browser login`}),(0,Z.jsxs)(S,{size:`sm`,className:`w-full cursor-pointer gap-1.5`,onClick:_,disabled:j,children:[(0,Z.jsx)(s,{className:`size-4`}),` Sign in with browser`]}),g&&(0,Z.jsxs)(`div`,{className:`space-y-2 text-xs`,children:[(0,Z.jsxs)(`a`,{href:g.authUrl,target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1 text-primary hover:underline`,children:[(0,Z.jsx)(s,{className:`size-3`}),` Open ChatGPT sign-in`]}),(0,Z.jsx)(`p`,{children:`Sign in, then copy the full localhost callback URL from the address bar and paste it below. On a phone, copy it even if the page fails to load.`}),(0,Z.jsx)(R,{htmlFor:`codex-callback-url`,children:`Callback URL`}),(0,Z.jsx)(A,{id:`codex-callback-url`,type:`password`,autoComplete:`off`,spellCheck:!1,placeholder:`http://localhost:.../auth/callback?...`,value:y,onChange:e=>b(e.target.value),disabled:x}),(0,Z.jsxs)(S,{size:`sm`,onClick:k,disabled:!y.trim()||x,children:[x&&(0,Z.jsx)(u,{className:`size-3 animate-spin`}),` Submit callback URL`]}),(0,Z.jsxs)(`p`,{role:`status`,className:`flex items-center gap-1.5 text-muted-foreground`,children:[(0,Z.jsx)(u,{className:`size-3 animate-spin`}),` Waiting for authorization. This may complete automatically on this computer.`]})]})]}),(0,Z.jsxs)(`div`,{className:`rounded-md border p-3 space-y-2`,children:[(0,Z.jsx)(`p`,{className:`text-[11px] font-medium`,children:`Device code`}),(0,Z.jsx)(S,{size:`sm`,className:`w-full cursor-pointer gap-1.5`,onClick:p,disabled:j,children:f?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(u,{className:`size-4 animate-spin`}),` Waiting for authorization...`]}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(i,{className:`size-4`}),` Sign in with device code`]})}),m&&(0,Z.jsxs)(`div`,{className:`rounded-md border border-primary/40 bg-primary/10 p-2.5 space-y-1.5`,children:[(0,Z.jsx)(`p`,{className:`text-[11px]`,children:`Enter this code to authorize:`}),(0,Z.jsx)(`div`,{className:`font-mono text-lg tracking-widest`,children:m.userCode}),(0,Z.jsxs)(`a`,{href:m.verificationUrl,target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1 text-primary hover:underline text-[11px]`,children:[(0,Z.jsx)(s,{className:`size-3`}),` `,m.verificationUrl]})]})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(`div`,{className:`flex-1 border-t`}),(0,Z.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`or paste an API key`}),(0,Z.jsx)(`div`,{className:`flex-1 border-t`})]}),(0,Z.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Z.jsx)(R,{htmlFor:`codex-api-key`,className:`text-xs`,children:`OpenAI API key`}),(0,Z.jsx)(A,{id:`codex-api-key`,type:`password`,placeholder:`sk-...`,value:a,onChange:e=>c(e.target.value),className:`text-xs font-mono`})]})]}),v&&(0,Z.jsx)(`p`,{role:`status`,className:`text-xs`,children:`Starting login...`}),h&&(0,Z.jsx)(`div`,{role:`alert`,className:`text-[11px] p-2 rounded bg-error/10 text-error`,children:h}),(0,Z.jsxs)(w,{children:[(0,Z.jsx)(S,{size:`sm`,variant:`outline`,className:`text-xs cursor-pointer`,onClick:()=>t(!1),children:`Cancel`}),(0,Z.jsxs)(S,{size:`sm`,className:`text-xs cursor-pointer gap-1.5`,onClick:d,disabled:!a.trim()||j,children:[l?(0,Z.jsx)(u,{className:`size-3.5 animate-spin`}):(0,Z.jsx)(o,{className:`size-3.5`}),`Add key`]})]})]})})}function He({mode:e,onOpenChange:t,password:n,onPasswordChange:r,busy:i,onExport:a,onImport:o,error:s}){let d=(0,X.useRef)(null),f=e===`export`;return(0,Z.jsx)(O,{open:e!==null,onOpenChange:t,children:(0,Z.jsxs)(T,{className:`sm:max-w-md`,children:[(0,Z.jsxs)(C,{children:[(0,Z.jsxs)(E,{className:`text-sm flex items-center gap-1.5`,children:[(0,Z.jsx)(c,{className:`size-4`}),` `,f?`Export Codex Accounts`:`Import Codex Accounts`]}),(0,Z.jsx)(D,{className:`text-xs leading-relaxed`,children:f?`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,Z.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Z.jsx)(R,{htmlFor:`codex-backup-password`,className:`text-xs`,children:`Password`}),(0,Z.jsx)(A,{id:`codex-backup-password`,type:`password`,placeholder:f?`Choose a password`:`Password used for the export`,value:n,onChange:e=>r(e.target.value),className:`text-xs`,autoComplete:f?`new-password`:`current-password`}),(0,Z.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:`A backup holds full logins — keep the file and its password together.`})]}),s&&(0,Z.jsx)(`div`,{className:`text-[11px] p-2 rounded bg-error/10 text-error`,children:s}),(0,Z.jsx)(`input`,{ref:d,type:`file`,accept:`application/json,.json`,className:`hidden`,onChange:e=>{let t=e.target.files?.[0];e.target.value=``,t&&o(t)}}),(0,Z.jsxs)(w,{children:[(0,Z.jsx)(S,{size:`sm`,variant:`outline`,className:`text-xs cursor-pointer`,onClick:()=>t(!1),children:`Cancel`}),(0,Z.jsxs)(S,{size:`sm`,className:`text-xs cursor-pointer gap-1.5`,disabled:!n.trim()||i,onClick:()=>f?a():d.current?.click(),children:[i?(0,Z.jsx)(u,{className:`size-3.5 animate-spin`}):f?(0,Z.jsx)(m,{className:`size-3.5`}):(0,Z.jsx)(l,{className:`size-3.5`}),f?`Download backup`:`Choose file`]})]})]})})}var Ue=[{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 We({open:e,onOpenChange:t,strategy:n,onChange:r}){return(0,Z.jsx)(O,{open:e,onOpenChange:t,children:(0,Z.jsxs)(T,{className:`sm:max-w-md`,children:[(0,Z.jsxs)(C,{children:[(0,Z.jsx)(E,{className:`text-sm`,children:`Codex Rotation`}),(0,Z.jsx)(D,{className:`text-xs leading-relaxed`,children:`How a new chat chooses among your Codex accounts.`})]}),(0,Z.jsx)(`div`,{className:`space-y-2`,children:Ue.map(e=>(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>r(e.value),"aria-current":n===e.value?`true`:void 0,className:y(`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,Z.jsx)(`p`,{className:`text-sm font-medium`,children:e.label}),(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e.hint})]},e.value))}),(0,Z.jsx)(w,{children:(0,Z.jsx)(S,{size:`sm`,variant:`outline`,className:`text-xs cursor-pointer`,onClick:()=>t(!1),children:`Done`})})]})})}function Ge(e){return e==null?null:Math.round(e*100)}function Ke({usage:e}){let t=e.session==null&&e.weekly==null;return(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[(t||e.session!=null)&&(0,Z.jsx)(ge,{label:`5-Hour Session`,pct:Ge(e.fiveHour),reset:le(e.session),resetsAt:e.session?.resetsAt}),(t||e.weekly!=null)&&(0,Z.jsx)(ge,{label:`Weekly`,pct:Ge(e.sevenDay),reset:le(e.weekly),resetsAt:e.weekly?.resetsAt})]})}var qe=2e3,Je=21e4;function Ye(e){let[t,n]=(0,X.useState)([]),[r,i]=(0,X.useState)(`round-robin`),[a,o]=(0,X.useState)({}),[s,c]=(0,X.useState)(!1),[l,u]=(0,X.useState)(new Set),[d,f]=(0,X.useState)(``),[p,m]=(0,X.useState)(``),[h,g]=(0,X.useState)(!1),[y,b]=(0,X.useState)(null),[x,S]=(0,X.useState)(null),[C,w]=(0,X.useState)(!1),[T,E]=(0,X.useState)(null),[D,O]=(0,X.useState)(!1),[k,A]=(0,X.useState)(``),[j,M]=(0,X.useState)(!1),[N,P]=(0,X.useState)(``),[ee,F]=(0,X.useState)(!1),[te,I]=(0,X.useState)(!1),[ne,L]=(0,X.useState)(null),R=(0,X.useRef)(null),z=(0,X.useRef)(null),B=(0,X.useRef)(0),V=(0,X.useRef)(!1),H=(0,X.useRef)(!1),U=(0,X.useRef)(!1),W=(0,X.useRef)(e);W.current=e;let G=(0,X.useCallback)(async()=>{c(!0);try{let e=await _.get(`/api/codex-accounts`);n(e.accounts),i(e.strategy),_.get(`/api/codex-accounts/usage`).then(o).catch(()=>{})}finally{c(!1)}},[]);(0,X.useEffect)(()=>{G()},[G]);let re=async()=>{if(!(!d.trim()||H.current||V.current||z.current)){H.current=!0,g(!0),b(null);try{await _.post(`/api/codex-accounts/api-key`,{apiKey:d.trim(),label:p.trim()||void 0}),f(``),m(``),e(),await G()}catch(e){b(e.message)}finally{H.current=!1,g(!1)}}},K=(0,X.useCallback)(()=>{B.current+=1,V.current=!1,U.current=!1,R.current?.(),R.current=null;let e=z.current;z.current=null,e&&_.del(`/api/codex-accounts/${e.method}-login/${e.id}`).catch(()=>{})},[]),q=(0,X.useCallback)(()=>{K(),S(null),w(!1),E(null),O(!1),A(``),M(!1)},[K]),ie=(0,X.useCallback)((e,t)=>{let n=Date.now()+(t===`browser`?61e4:Je),r=!1,i;R.current=()=>{r=!0,clearTimeout(i)};let a=async()=>{if(r)return;let o=null;try{o=await _.get(`/api/codex-accounts/${t}-login/${e}/status`)}catch{}if(!r){if(o?.state===`done`){q(),m(``),W.current(),await G();return}if(o?.state===`error`||Date.now()>n){q(),b(o?.state===`error`?o.error:`${t===`browser`?`Browser`:`Device`} login timed out.`);return}i=setTimeout(a,qe)}};a()},[q,G]);(0,X.useEffect)(()=>K,[K]);let J=async e=>{if(V.current||z.current||H.current)return;V.current=!0;let t=++B.current;O(!0),b(null);try{let n=await _.post(`/api/codex-accounts/${e}-login`,{label:p.trim()||void 0});if(t!==B.current){_.del(`/api/codex-accounts/${e}-login/${n.id}`).catch(()=>{});return}z.current={id:n.id,method:e},e===`device`?(S(n),w(!0)):E(n),ie(n.id,e)}catch(e){t===B.current&&b(e.message)}finally{t===B.current&&(V.current=!1,O(!1))}};return{accounts:t,strategy:r,usages:a,loading:s,apiKey:d,setApiKey:f,label:p,setLabel:m,adding:h,err:y,setErr:b,device:x,deviceWaiting:C,backupPassword:N,setBackupPassword:P,exporting:ee,importing:te,msg:ne,setMsg:L,toggling:l,load:G,addApiKey:re,startDevice:()=>J(`device`),startBrowser:()=>J(`browser`),browser:T,loginStarting:D,callbackUrl:k,setCallbackUrl:A,submittingCallback:j,submitCallback:async()=>{let e=z.current;if(e?.method!==`browser`||!k.trim()||U.current)return;let t=B.current;U.current=!0,M(!0),b(null);let n=k.trim();A(``);try{await _.post(`/api/codex-accounts/browser-login/${e.id}/callback`,{callbackUrl:n})}catch(e){t===B.current&&b(e.message)}finally{t===B.current&&(U.current=!1,M(!1))}},cancelLogin:q,remove:async e=>{await _.del(`/api/codex-accounts/${e}`),await G()},toggle:async(e,t)=>{let n=t===`disabled`?`active`:`disabled`;u(t=>new Set(t).add(e)),b(null);try{await _.patch(`/api/codex-accounts/${e}`,{status:n}),await G()}catch(e){b(e.message||`Could not change the account`)}finally{u(t=>{let n=new Set(t);return n.delete(e),n})}},toggleDailyGuard:async(e,t)=>{u(t=>new Set(t).add(e)),b(null);try{await _.patch(`/api/codex-accounts/${e}`,{dailyGuardEnabled:!t}),await G()}catch(e){b(e.message||`Could not change Daily guard`)}finally{u(t=>{let n=new Set(t);return n.delete(e),n})}},changeStrategy:async e=>{i(e);try{await _.put(`/api/codex-accounts/strategy`,{strategy:e})}catch{}},doExport:async()=>{if(!N.trim()){b(`Set a backup password first.`);return}F(!0),b(null),L(null);try{let t={"Content-Type":`application/json`},n=v();n&&(t.Authorization=`Bearer ${n}`);let r=await fetch(`/api/codex-accounts/export`,{method:`POST`,headers:t,body:JSON.stringify({password:N})});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),L(`Backup downloaded.`),e()}catch(e){b(e.message)}finally{F(!1)}},doImport:async t=>{if(!N.trim()){b(`Enter the backup password first.`);return}I(!0),b(null),L(null);try{let n=await t.text(),r=await _.post(`/api/codex-accounts/import`,{data:n,password:N});L(`Imported ${r.imported}${r.skipped?`, skipped ${r.skipped}`:``}.`),e(),await G()}catch(e){b(e.message)}finally{I(!1)}}}}function Xe(){let[e,t]=(0,X.useState)(null),n=Ye(()=>t(null));return(0,Z.jsxs)(`div`,{className:`space-y-4`,children:[(0,Z.jsx)(me,{description:(0,Z.jsxs)(Z.Fragment,{children:[`Each Codex account keeps its own login (`,(0,Z.jsx)(`code`,{children:`CODEX_HOME`}),`). One is picked per chat by the rotation setting.`]}),onRefresh:()=>void n.load(),refreshing:n.loading,actions:(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(S,{size:`sm`,className:`cursor-pointer gap-1.5`,onClick:()=>t(`add`),children:[(0,Z.jsx)(p,{className:`size-4`}),` Add account`]}),(0,Z.jsxs)(S,{size:`sm`,variant:`outline`,className:`cursor-pointer gap-1.5`,onClick:()=>t(`export`),children:[(0,Z.jsx)(m,{className:`size-4`}),` Export`]}),(0,Z.jsxs)(S,{size:`sm`,variant:`outline`,className:`cursor-pointer gap-1.5`,onClick:()=>t(`import`),children:[(0,Z.jsx)(l,{className:`size-4`}),` Import`]}),(0,Z.jsxs)(S,{size:`sm`,variant:`outline`,className:`cursor-pointer gap-1.5`,onClick:()=>t(`rotation`),children:[(0,Z.jsx)(f,{className:`size-4`}),` Rotation`]})]})}),(0,Z.jsx)(se,{message:n.msg??n.err,onDismiss:()=>{n.setMsg(null),n.setErr(null)}}),(0,Z.jsxs)(`section`,{className:`space-y-2`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Z.jsx)(`h3`,{className:`text-sm font-medium`,children:`Codex Accounts`}),(0,Z.jsx)(`span`,{className:`text-[10px] text-muted-foreground capitalize`,children:n.strategy.replace(`-`,` `)})]}),n.loading&&n.accounts.length===0?(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 py-6 text-xs text-muted-foreground`,children:[(0,Z.jsx)(u,{className:`size-4 animate-spin`}),` Loading accounts...`]}):n.accounts.length===0?(0,Z.jsxs)(`div`,{className:`flex flex-col items-center gap-2 py-8 text-center`,children:[(0,Z.jsx)(o,{className:`size-5 text-muted-foreground`}),(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`No Codex accounts yet.`}),(0,Z.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Chats use your default `,(0,Z.jsx)(`code`,{children:`~/.codex`}),` login until you add one.`]})]}):(0,Z.jsx)(oe,{children:n.accounts.map(e=>{let t=n.usages[e.id]??{};return(0,Z.jsxs)(fe,{dense:!0,className:`min-w-[300px] shrink-0 snap-start`,"data-testid":`account-card`,"data-account-id":e.id,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(`span`,{className:`text-sm font-medium truncate flex-1 min-w-0`,children:e.label}),(0,Z.jsx)(`span`,{className:`text-[10px] uppercase tracking-wide text-text-subtle border border-border rounded px-1 shrink-0`,children:e.type}),de(e.planType)&&(0,Z.jsx)(`span`,{className:`text-[10px] text-text-subtle shrink-0`,children:de(e.planType)}),(0,Z.jsx)(I,{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,Z.jsxs)(F,{children:[(0,Z.jsx)(z,{asChild:!0,children:(0,Z.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,Z.jsx)(h,{className:`size-4`})})}),(0,Z.jsx)(j,{side:`top`,children:`Remove account`})]})]}),(0,Z.jsx)(Ke,{usage:t}),t.session==null&&(()=>{let r=he(t.weekly);return r?(0,Z.jsxs)(`div`,{className:`flex min-h-12 items-center justify-between gap-3 rounded-md border px-2.5 py-1.5 ${e.dailyGuardEnabled&&r.blocked?`border-error/40 bg-error/5`:`border-border/50 bg-surface/40`}`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0 space-y-0.5`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5 text-xs font-medium ${e.dailyGuardEnabled&&r.blocked?`text-error`:`text-text-secondary`}`,children:[(0,Z.jsx)(`span`,{children:`Daily guard`}),(0,Z.jsxs)(F,{children:[(0,Z.jsx)(z,{asChild:!0,children:(0,Z.jsx)(`button`,{type:`button`,"aria-label":`About Daily guard`,className:`text-text-subtle hover:text-text-primary cursor-help`,children:(0,Z.jsx)(a,{className:`size-3.5`})})}),(0,Z.jsx)(j,{side:`top`,className:`max-w-64 text-xs leading-relaxed`,children:`Keeps a weekly-only Codex account on pace to last until its reset. Each day adds one seventh of the weekly quota. When usage reaches that day's cap, PPM pauses new turns until the next day. Turn it off any time to use the remaining quota freely.`})]})]}),(0,Z.jsx)(`p`,{className:`text-[10px] tabular-nums ${e.dailyGuardEnabled&&r.blocked?`text-error`:`text-text-subtle`}`,children:e.dailyGuardEnabled&&r.blocked?`${Math.round(r.used*100)}% used / ${Math.round(r.cap*100)}% daily cap. New turns paused.`:`Day ${r.day}/7, ${Math.round(r.cap*100)}% daily cap`})]}),(0,Z.jsxs)(`span`,{className:`hidden`,title:`Day ${r.day}/7: hold weekly usage at or below ${Math.round(r.cap*100)}% to last until reset.`,children:[`Daily guard `,e.dailyGuardEnabled?`· Day ${r.day}/7 cap ${Math.round(r.cap*100)}%`:``]}),(0,Z.jsx)(I,{checked:!!e.dailyGuardEnabled,onCheckedChange:()=>void n.toggleDailyGuard(e.id,!!e.dailyGuardEnabled),disabled:n.toggling.has(e.id),"aria-label":e.dailyGuardEnabled?`Disable Daily guard`:`Enable Daily guard`,className:`cursor-pointer shrink-0`})]}):null})()]},e.id)})})]}),(0,Z.jsx)(Ve,{open:e===`add`,onOpenChange:e=>{e||n.cancelLogin(),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,browser:n.browser,onStartBrowser:()=>void n.startBrowser(),loginStarting:n.loginStarting,callbackUrl:n.callbackUrl,onCallbackUrlChange:n.setCallbackUrl,submittingCallback:n.submittingCallback,onSubmitCallback:()=>void n.submitCallback(),error:n.err}),(0,Z.jsx)(He,{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,Z.jsx)(We,{open:e===`rotation`,onOpenChange:e=>t(e?`rotation`:null),strategy:n.strategy,onChange:e=>void n.changeStrategy(e)})]})}var Ze=[{id:`claude`,label:`Claude`},{id:`codex`,label:`Codex`}];function Qe(){let[e,t]=(0,X.useState)(null),[n,r]=(0,X.useState)(`claude`);(0,X.useEffect)(()=>{let e=!1;return U().then(n=>{e||t(new Set(Object.keys(n.providers??{})))}).catch(()=>{e||t(new Set([`claude`]))}),()=>{e=!0}},[]);let i=Ze.filter(t=>t.id===`claude`||e?.has(t.id)),a=i.length>1;return(0,Z.jsxs)(`div`,{className:`space-y-4`,"data-testid":`accounts-pane`,"data-provider":n,children:[a&&(0,Z.jsx)(`div`,{className:`flex gap-1 border-b border-border/50`,children:i.map(e=>(0,Z.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,Z.jsx)(ne,{providerId:e.id}),e.label]},e.id))}),e===null&&!a&&(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-muted-foreground`,children:[(0,Z.jsx)(u,{className:`size-3 animate-spin`}),` Checking configured providers...`]}),n===`claude`?(0,Z.jsx)(Be,{}):(0,Z.jsx)(Xe,{})]})}export{Qe as AccountsSettingsSection};
|