@hienlh/ppm 0.19.4 → 0.19.6
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 +17 -0
- package/README.md +54 -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 +6 -1
- package/dist/web/assets/accounts-settings-section-DGsB-ynw.js +1 -0
- package/dist/web/assets/{ai-resource-editor-BTWds-aC.js → ai-resource-editor-BeoI2Jp8.js} +1 -1
- package/dist/web/assets/{ai-settings-section-CmoBsSpY.js → ai-settings-section-Bc91w0K4.js} +1 -1
- package/dist/web/assets/{ai-settings-section-DjbYj4wK.js → ai-settings-section-edmjpNtG.js} +1 -1
- package/dist/web/assets/{appearance-settings-section-vLmakLtA.js → appearance-settings-section-CvX5XncT.js} +1 -1
- package/dist/web/assets/{chat-tab-CLRlS8Jc.js → chat-tab-BHO6ceZp.js} +3 -3
- package/dist/web/assets/{code-editor-CCwVu5F5.js → code-editor-1ZV6iSCc.js} +2 -2
- package/dist/web/assets/{conflict-editor-CvWYcbwD.js → conflict-editor-Dwogm7g8.js} +1 -1
- package/dist/web/assets/{csv-preview-DzuDuyE_.js → csv-preview-CcgWfErD.js} +1 -1
- package/dist/web/assets/{database-viewer-D4XGEDHm.js → database-viewer-DXlx5CrZ.js} +1 -1
- package/dist/web/assets/{diff-viewer-B5N1X61R.js → diff-viewer-tYKO0wXX.js} +1 -1
- package/dist/web/assets/{explorer-body-BxLLjthF.js → explorer-body-BPnA8ztG.js} +1 -1
- package/dist/web/assets/{explorer-window-content-CL1Cipj3.js → explorer-window-content-BMPhgAnl.js} +1 -1
- package/dist/web/assets/{extension-manager-section-BpyGq15A.js → extension-manager-section-Cepy9w0W.js} +1 -1
- package/dist/web/assets/{extension-webview-BM8FXhuN.js → extension-webview-83orjfAz.js} +1 -1
- package/dist/web/assets/{files-settings-section-B0_aR1nL.js → files-settings-section-A_5QWv4b.js} +1 -1
- package/dist/web/assets/{general-settings-section-C1EJzjhU.js → general-settings-section-CFDRUc2E.js} +1 -1
- package/dist/web/assets/{git-log-panel-D1yGTUE_.js → git-log-panel-D9iuuwL4.js} +1 -1
- package/dist/web/assets/{glide-data-grid-Cu0STKML.js → glide-data-grid-Ch5Ap1WP.js} +1 -1
- package/dist/web/assets/{group-chat-tab-BfcvkRX5.js → group-chat-tab-CfTivWze.js} +1 -1
- package/dist/web/assets/{index-B1bzKRjJ.js → index-LEL-8oU_.js} +4 -4
- package/dist/web/assets/{jira-watcher-section-DZh-Z2MK.js → jira-watcher-section-DznCP9IR.js} +1 -1
- package/dist/web/assets/{keybindings-store-CFwgcnpZ.js → keybindings-store-BUeQf1S6.js} +1 -1
- package/dist/web/assets/{keyboard-shortcuts-section-JBtcJGM3.js → keyboard-shortcuts-section-C-BeYTwO.js} +1 -1
- package/dist/web/assets/{markdown-renderer-Bo8GgGXl.js → markdown-renderer-B47WcMMs.js} +1 -1
- package/dist/web/assets/{markdown-renderer-DY60UZNW.js → markdown-renderer-Dcq0J7Yw.js} +1 -1
- package/dist/web/assets/{mobile-explorer-sheet-C59rPw7Z.js → mobile-explorer-sheet-RG64iGIe.js} +1 -1
- package/dist/web/assets/{notification-store-Bd6L0K_Q.js → notification-store-CmvMzpl2.js} +1 -1
- package/dist/web/assets/{notifications-settings-section-ARQlF-6E.js → notifications-settings-section--zzeoLfi.js} +1 -1
- package/dist/web/assets/{pdf-preview-CRShdbBS.js → pdf-preview-CGn99JWL.js} +1 -1
- package/dist/web/assets/{postgres-viewer-BNT-4yYl.js → postgres-viewer-D-mPRQRC.js} +1 -1
- package/dist/web/assets/{ppmbot-settings-section-Bq4YAcFW.js → ppmbot-settings-section-Dy1CBG9d.js} +1 -1
- package/dist/web/assets/{process-table-CjiXW0rg.js → process-table-DSLrAJC5.js} +1 -1
- package/dist/web/assets/proxy-settings-section-COr2LOQV.js +1 -0
- package/dist/web/assets/{query-audit-section-C5RmhRSu.js → query-audit-section-CShd9Vo1.js} +1 -1
- package/dist/web/assets/{remote-desktop-mobile-sheet-BF-75_03.js → remote-desktop-mobile-sheet-yFKdq8Cb.js} +2 -2
- package/dist/web/assets/{remote-desktop-mobile-view-C9KR9I9G.js → remote-desktop-mobile-view-Dj3n_7MA.js} +1 -1
- package/dist/web/assets/{remote-desktop-readiness-gate-BnKJicB2.js → remote-desktop-readiness-gate-CR2jZ4pW.js} +1 -1
- package/dist/web/assets/{remote-desktop-window-content-awXsNw_R.js → remote-desktop-window-content-BhQizWi0.js} +1 -1
- package/dist/web/assets/{schedules-settings-section-BOecKJzl.js → schedules-settings-section-f6VP9Mde.js} +1 -1
- package/dist/web/assets/{settings-body-DGi5DXY6.js → settings-body-BRJapYD0.js} +2 -2
- package/dist/web/assets/{settings-tab-GM9zTRul.js → settings-tab-hHtSuYDb.js} +1 -1
- package/dist/web/assets/{settings-window-content-Dvhxo4_H.js → settings-window-content-CUrGhhKI.js} +1 -1
- package/dist/web/assets/{sql-query-editor-BmkGFzcL.js → sql-query-editor-DxS_r9dM.js} +1 -1
- package/dist/web/assets/{sqlite-viewer-DbziVQXQ.js → sqlite-viewer-Gi8hYwKJ.js} +1 -1
- package/dist/web/assets/{system-monitor-body-CbHW5aYm.js → system-monitor-body-CdWv_LBB.js} +2 -2
- package/dist/web/assets/{system-monitor-tab-C7EZLMIo.js → system-monitor-tab-DBMjRETL.js} +1 -1
- package/dist/web/assets/{system-monitor-window-content-C_w4w81e.js → system-monitor-window-content-BUHL5rX-.js} +1 -1
- package/dist/web/assets/{tab-host-window-content-BSP1SEXS.js → tab-host-window-content-2gwUy-OA.js} +1 -1
- package/dist/web/assets/{team-member-sheet-C9N0iA1-.js → team-member-sheet-B-3ri_oc.js} +2 -2
- package/dist/web/assets/{team-member-window-content-CM2QFv-s.js → team-member-window-content-BvqhkPjH.js} +1 -1
- package/dist/web/assets/{terminal-tab-jWYELm8y.js → terminal-tab-CbHDqCBe.js} +1 -1
- package/dist/web/assets/{tool-cards-jefdOWVJ.js → tool-cards-DIoAqDka.js} +2 -2
- package/dist/web/assets/{use-accounts-data-MhMl0Y4Z.js → use-accounts-data-B8ltBkBj.js} +1 -1
- package/dist/web/assets/{use-monaco-theme-BbAd7DXr.js → use-monaco-theme-2YgX5HEz.js} +1 -1
- package/dist/web/assets/{use-remote-desktop-display-choice-DlfMIWq3.js → use-remote-desktop-display-choice--W-pnzPS.js} +1 -1
- package/dist/web/assets/{use-websocket-Bq8X_SUI.js → use-websocket-Dek_fwOD.js} +1 -1
- package/dist/web/assets/{video-preview-BGh3B0Lu.js → video-preview-DijwhDXk.js} +1 -1
- package/dist/web/index.html +1 -1
- package/dist/web/sw.js +1 -1
- package/package.json +1 -1
- package/src/providers/codex-app-server/codex-event-mapper.ts +42 -1
- package/src/providers/codex-app-server/codex-provider.ts +22 -4
- package/src/server/routes/proxy.ts +66 -4
- package/src/services/codex-account.service.ts +4 -2
- package/src/services/edge-forwarder.ts +191 -191
- package/src/services/proxy-agent-anthropic-bridge.ts +14 -3
- package/src/services/proxy-agent-bridge.ts +51 -4
- package/src/services/proxy-agent-turn.ts +12 -1
- package/src/services/proxy-image-bridge.ts +186 -0
- package/src/services/proxy-openai-bridge.ts +4 -38
- package/src/services/proxy-openai-format.ts +29 -3
- package/src/services/proxy.service.ts +54 -0
- package/src/services/windows-process-tree.ts +351 -351
- package/src/web/components/settings/accounts/account-bucket-row.tsx +4 -4
- package/src/web/components/settings/accounts/codex-accounts-section.tsx +2 -8
- package/src/web/components/settings/accounts/codex-usage-rows.tsx +26 -0
- package/src/web/components/settings/accounts/use-codex-accounts.ts +12 -1
- package/src/web/components/settings/proxy-settings-section.tsx +73 -27
- package/src/web/components/settings/proxy-test-section.tsx +45 -17
- package/src/web/lib/proxy-endpoints.ts +39 -0
- package/dist/web/assets/accounts-settings-section-CCFQV-RB.js +0 -1
- package/dist/web/assets/proxy-settings-section-wRbiyQiA.js +0 -3
- 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
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The usage bar, and the rate-limit-bucket adapter over it.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
4
|
+
* `AccountUsageBar` is the shared visual, so Claude and Codex rows read the same; it takes
|
|
5
|
+
* the reset text already formatted, because a caller may hold a percentage whose bucket is
|
|
6
|
+
* missing and must render the bar without inventing a reset time. `AccountBucketRow` is the
|
|
7
|
+
* adapter for callers that do have a whole bucket, and it drops the row when they do not.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import type { LimitBucket } from "../../../../types/chat";
|
|
@@ -10,15 +10,12 @@ import { useState } from "react";
|
|
|
10
10
|
import { Download, KeyRound, Loader2, Plus, Settings, Trash2, Upload } from "lucide-react";
|
|
11
11
|
import { Button } from "@/components/ui/button";
|
|
12
12
|
import { AccountCardRow, AccountCardShell, AccountsPaneHeader, AccountsPaneMessage } from "./accounts-pane-header";
|
|
13
|
-
import { AccountUsageBar } from "./account-bucket-row";
|
|
14
13
|
import { CodexAddAccountDialog } from "./codex-add-account-dialog";
|
|
15
14
|
import { CodexBackupDialog } from "./codex-backup-dialog";
|
|
16
15
|
import { CodexRotationDialog } from "./codex-rotation-dialog";
|
|
16
|
+
import { CodexUsageRows } from "./codex-usage-rows";
|
|
17
17
|
import { useCodexAccounts } from "./use-codex-accounts";
|
|
18
18
|
|
|
19
|
-
/** Usage arrives as a 0-1 fraction; the shared bar wants whole percent. */
|
|
20
|
-
function toPct(v?: number): number | null { return v != null ? Math.round(v * 100) : null; }
|
|
21
|
-
|
|
22
19
|
/** Codex multi-account management, separate from Claude accounts because codex auth is owned
|
|
23
20
|
* by the app-server per CODEX_HOME. Added by API key or ChatGPT device code. */
|
|
24
21
|
export function CodexAccountsSection() {
|
|
@@ -98,10 +95,7 @@ export function CodexAccountsSection() {
|
|
|
98
95
|
<Trash2 className="size-4" />
|
|
99
96
|
</button>
|
|
100
97
|
</div>
|
|
101
|
-
<
|
|
102
|
-
<AccountUsageBar label="5-Hour Session" pct={toPct(u.fiveHour)} />
|
|
103
|
-
<AccountUsageBar label="Weekly" pct={toPct(u.sevenDay)} />
|
|
104
|
-
</div>
|
|
98
|
+
<CodexUsageRows usage={u} />
|
|
105
99
|
</AccountCardShell>
|
|
106
100
|
);
|
|
107
101
|
})}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The two quota rows of a Codex account card.
|
|
3
|
+
*
|
|
4
|
+
* Split out so the wiring is testable on its own: the reset clock is the part that keeps
|
|
5
|
+
* getting dropped, because the percentages render fine without it.
|
|
6
|
+
*
|
|
7
|
+
* Unlike the Claude card's `AccountBucketRow`, a row here stays on screen with an em dash
|
|
8
|
+
* when the quota read failed instead of disappearing — a card that silently loses half its
|
|
9
|
+
* height reads as a broken account rather than as missing data.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { AccountUsageBar } from "./account-bucket-row";
|
|
13
|
+
import { formatResetTime } from "./account-usage-format";
|
|
14
|
+
import type { Usage } from "./use-codex-accounts";
|
|
15
|
+
|
|
16
|
+
/** Usage arrives as a 0-1 fraction; the shared bar wants whole percent. */
|
|
17
|
+
function toPct(v?: number): number | null { return v != null ? Math.round(v * 100) : null; }
|
|
18
|
+
|
|
19
|
+
export function CodexUsageRows({ usage }: { usage: Usage }) {
|
|
20
|
+
return (
|
|
21
|
+
<div className="space-y-2">
|
|
22
|
+
<AccountUsageBar label="5-Hour Session" pct={toPct(usage.fiveHour)} reset={formatResetTime(usage.session)} />
|
|
23
|
+
<AccountUsageBar label="Weekly" pct={toPct(usage.sevenDay)} reset={formatResetTime(usage.weekly)} />
|
|
24
|
+
</div>
|
|
25
|
+
);
|
|
26
|
+
}
|
|
@@ -11,11 +11,22 @@
|
|
|
11
11
|
|
|
12
12
|
import { useCallback, useEffect, useRef, useState } from "react";
|
|
13
13
|
import { api, getAuthToken } from "@/lib/api-client";
|
|
14
|
+
import type { LimitBucket } from "../../../../types/chat";
|
|
14
15
|
import type { CodexStrategy } from "./codex-rotation-dialog";
|
|
15
16
|
|
|
16
17
|
export type Strategy = CodexStrategy;
|
|
17
18
|
export interface CodexAccount { id: string; label: string; type: string; planType?: string | null }
|
|
18
|
-
|
|
19
|
+
/**
|
|
20
|
+
* One account's quota. The two percentages are what the bars read; the buckets carry the
|
|
21
|
+
* reset clock the server already sends, so the Codex card can show "resets in" the way the
|
|
22
|
+
* Claude card does.
|
|
23
|
+
*/
|
|
24
|
+
export interface Usage {
|
|
25
|
+
fiveHour?: number;
|
|
26
|
+
sevenDay?: number;
|
|
27
|
+
session?: LimitBucket;
|
|
28
|
+
weekly?: LimitBucket;
|
|
29
|
+
}
|
|
19
30
|
interface DevicePending { id: string; userCode: string; verificationUrl: string }
|
|
20
31
|
type DeviceStatus = { state: "pending" } | { state: "done" } | { state: "error"; error: string };
|
|
21
32
|
|
|
@@ -4,11 +4,23 @@ import { Button } from "@/components/ui/button";
|
|
|
4
4
|
import { Input } from "@/components/ui/input";
|
|
5
5
|
import { Label } from "@/components/ui/label";
|
|
6
6
|
import { Switch } from "@/components/ui/switch";
|
|
7
|
-
import { getProxySettings, updateProxySettings, type ProxySettings } from "@/lib/api-settings";
|
|
7
|
+
import { getProxySettings, updateProxySettings, getAISettings, type ProxySettings } from "@/lib/api-settings";
|
|
8
8
|
import { copyToClipboard } from "@/lib/clipboard";
|
|
9
9
|
import { ProxyTestButton } from "./proxy-test-section";
|
|
10
|
+
import { proxyEndpoints } from "@/lib/proxy-endpoints";
|
|
10
11
|
|
|
11
12
|
export function ProxySettingsSection() {
|
|
13
|
+
/** Provider the connection info targets; "" is the unscoped Claude path. */
|
|
14
|
+
const [provider, setProvider] = useState("");
|
|
15
|
+
/** Providers reachable as agents, minus the internal mock. */
|
|
16
|
+
const [agentProviders, setAgentProviders] = useState<string[]>([]);
|
|
17
|
+
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
getAISettings()
|
|
20
|
+
.then((s) => setAgentProviders(Object.keys(s.providers ?? {}).filter((id) => id !== "mock" && id !== "claude")))
|
|
21
|
+
.catch(() => setAgentProviders([]));
|
|
22
|
+
}, []);
|
|
23
|
+
|
|
12
24
|
const [settings, setSettings] = useState<ProxySettings | null>(null);
|
|
13
25
|
const [loading, setLoading] = useState(true);
|
|
14
26
|
const [saving, setSaving] = useState(false);
|
|
@@ -59,12 +71,22 @@ export function ProxySettingsSection() {
|
|
|
59
71
|
const localEndpoint = settings.localEndpoint;
|
|
60
72
|
const localBaseUrl = localEndpoint.replace(/\/proxy\/v1\/messages$/, "");
|
|
61
73
|
|
|
74
|
+
// Every URL below comes from the shared helper, which the Test dialog also
|
|
75
|
+
// uses — that is what keeps the card and the request it fires in agreement.
|
|
76
|
+
const ep = proxyEndpoints(hasTunnel ? settings.tunnelUrl! : localBaseUrl, provider);
|
|
77
|
+
const anthropicEndpoint = ep.anthropicMessages;
|
|
78
|
+
const openAiEndpoint = ep.openAiChatCompletions;
|
|
79
|
+
const anthropicEnv = `ANTHROPIC_BASE_URL=${ep.anthropicBase}\nANTHROPIC_API_KEY=${settings.authKey}`;
|
|
80
|
+
const openAiEnv = `OPENAI_BASE_URL=${ep.openAiBase}\nOPENAI_API_KEY=${settings.authKey}`;
|
|
81
|
+
|
|
62
82
|
return (
|
|
63
83
|
<div className="space-y-4">
|
|
64
84
|
<div className="space-y-1.5">
|
|
65
85
|
<p className="text-[11px] text-muted-foreground">
|
|
66
|
-
Expose your
|
|
67
|
-
|
|
86
|
+
Expose your accounts as an API that speaks both the Anthropic and OpenAI
|
|
87
|
+
formats, so most SDKs need only a new base URL. The default path answers
|
|
88
|
+
from your Claude accounts; pick a provider below to run its agent instead,
|
|
89
|
+
which also unlocks image generation.
|
|
68
90
|
</p>
|
|
69
91
|
</div>
|
|
70
92
|
|
|
@@ -73,7 +95,7 @@ export function ProxySettingsSection() {
|
|
|
73
95
|
<div className="space-y-0.5">
|
|
74
96
|
<Label className="text-xs">Enable Proxy</Label>
|
|
75
97
|
<p className="text-[11px] text-muted-foreground">
|
|
76
|
-
Accept API requests
|
|
98
|
+
Accept API requests under /proxy
|
|
77
99
|
</p>
|
|
78
100
|
</div>
|
|
79
101
|
<Switch
|
|
@@ -132,7 +154,32 @@ export function ProxySettingsSection() {
|
|
|
132
154
|
<div className="space-y-2 rounded-md border p-3 bg-muted/30">
|
|
133
155
|
<div className="flex items-center justify-between">
|
|
134
156
|
<h4 className="text-[11px] font-medium">Connection Info</h4>
|
|
135
|
-
<ProxyTestButton authKey={settings.authKey!} baseUrl={window.location.origin} />
|
|
157
|
+
<ProxyTestButton authKey={settings.authKey!} baseUrl={window.location.origin} provider={provider} />
|
|
158
|
+
</div>
|
|
159
|
+
|
|
160
|
+
{/* Target provider — the only thing that differs between the two
|
|
161
|
+
dialects below, so both are derived from one prefix. */}
|
|
162
|
+
<div className="space-y-1">
|
|
163
|
+
<Label className="text-[10px] text-muted-foreground">Provider</Label>
|
|
164
|
+
<div className="flex flex-wrap gap-1.5">
|
|
165
|
+
{[{ id: "", label: "Claude (default)" }, ...agentProviders.map((id) => ({ id, label: id }))].map((p) => (
|
|
166
|
+
<button
|
|
167
|
+
key={p.id || "default"}
|
|
168
|
+
type="button"
|
|
169
|
+
onClick={() => setProvider(p.id)}
|
|
170
|
+
className={`text-[10px] px-2.5 min-h-[36px] rounded-md border transition-colors cursor-pointer ${
|
|
171
|
+
provider === p.id ? "border-primary bg-primary/15" : "border-border bg-muted/40 hover:bg-muted"
|
|
172
|
+
}`}
|
|
173
|
+
>
|
|
174
|
+
{p.label}
|
|
175
|
+
</button>
|
|
176
|
+
))}
|
|
177
|
+
</div>
|
|
178
|
+
{provider && (
|
|
179
|
+
<p className="text-[10px] text-muted-foreground">
|
|
180
|
+
Runs the {provider} agent per request (read-only sandbox, one turn). Slower than the default path.
|
|
181
|
+
</p>
|
|
182
|
+
)}
|
|
136
183
|
</div>
|
|
137
184
|
|
|
138
185
|
{/* Anthropic endpoint */}
|
|
@@ -140,13 +187,13 @@ export function ProxySettingsSection() {
|
|
|
140
187
|
<Label className="text-[10px] text-muted-foreground">Anthropic Endpoint</Label>
|
|
141
188
|
<div className="flex gap-1.5 items-center">
|
|
142
189
|
<code className="text-[10px] font-mono bg-muted px-1.5 py-0.5 rounded flex-1 truncate">
|
|
143
|
-
{
|
|
190
|
+
{anthropicEndpoint}
|
|
144
191
|
</code>
|
|
145
192
|
<Button
|
|
146
193
|
variant="ghost"
|
|
147
194
|
size="sm"
|
|
148
195
|
className="h-6 px-1.5 cursor-pointer shrink-0"
|
|
149
|
-
onClick={() => handleCopy(
|
|
196
|
+
onClick={() => handleCopy(anthropicEndpoint, "anthropic")}
|
|
150
197
|
>
|
|
151
198
|
{copied === "anthropic" ? "Copied!" : <Copy className="size-3" />}
|
|
152
199
|
</Button>
|
|
@@ -158,21 +205,32 @@ export function ProxySettingsSection() {
|
|
|
158
205
|
<Label className="text-[10px] text-muted-foreground">OpenAI-Compatible Endpoint</Label>
|
|
159
206
|
<div className="flex gap-1.5 items-center">
|
|
160
207
|
<code className="text-[10px] font-mono bg-muted px-1.5 py-0.5 rounded flex-1 truncate">
|
|
161
|
-
{
|
|
208
|
+
{openAiEndpoint}
|
|
162
209
|
</code>
|
|
163
210
|
<Button
|
|
164
211
|
variant="ghost"
|
|
165
212
|
size="sm"
|
|
166
213
|
className="h-6 px-1.5 cursor-pointer shrink-0"
|
|
167
|
-
onClick={() => handleCopy(
|
|
168
|
-
hasTunnel ? settings.openAiEndpoint! : settings.localOpenAiEndpoint, "openai",
|
|
169
|
-
)}
|
|
214
|
+
onClick={() => handleCopy(openAiEndpoint, "openai")}
|
|
170
215
|
>
|
|
171
216
|
{copied === "openai" ? "Copied!" : <Copy className="size-3" />}
|
|
172
217
|
</Button>
|
|
173
218
|
</div>
|
|
174
219
|
</div>
|
|
175
220
|
|
|
221
|
+
{/* Images live only under a provider — the unscoped path has no such route. */}
|
|
222
|
+
{ep.imagesGenerations && ep.imagesEdits && (
|
|
223
|
+
<div className="space-y-1">
|
|
224
|
+
<Label className="text-[10px] text-muted-foreground">Image Endpoints</Label>
|
|
225
|
+
<code className="block text-[10px] font-mono bg-muted px-1.5 py-0.5 rounded truncate">
|
|
226
|
+
{ep.imagesGenerations}
|
|
227
|
+
</code>
|
|
228
|
+
<code className="block text-[10px] font-mono bg-muted px-1.5 py-0.5 rounded truncate">
|
|
229
|
+
{ep.imagesEdits}
|
|
230
|
+
</code>
|
|
231
|
+
</div>
|
|
232
|
+
)}
|
|
233
|
+
|
|
176
234
|
{!hasTunnel && (
|
|
177
235
|
<p className="text-[10px] text-muted-foreground">
|
|
178
236
|
Start a Cloudflare tunnel (Share) to get a public URL.
|
|
@@ -183,18 +241,12 @@ export function ProxySettingsSection() {
|
|
|
183
241
|
<div className="space-y-1 pt-1">
|
|
184
242
|
<Label className="text-[10px] text-muted-foreground">Anthropic Format</Label>
|
|
185
243
|
<div className="relative">
|
|
186
|
-
<pre className="text-[9px] font-mono bg-muted p-2 rounded overflow-x-auto whitespace-pre">
|
|
187
|
-
{`ANTHROPIC_BASE_URL=${hasTunnel ? settings.tunnelUrl + "/proxy" : localBaseUrl + "/proxy"}
|
|
188
|
-
ANTHROPIC_API_KEY=${settings.authKey}`}
|
|
189
|
-
</pre>
|
|
244
|
+
<pre className="text-[9px] font-mono bg-muted p-2 rounded overflow-x-auto whitespace-pre">{anthropicEnv}</pre>
|
|
190
245
|
<Button
|
|
191
246
|
variant="ghost"
|
|
192
247
|
size="sm"
|
|
193
248
|
className="absolute top-1 right-1 h-5 px-1 cursor-pointer"
|
|
194
|
-
onClick={() => handleCopy(
|
|
195
|
-
`ANTHROPIC_BASE_URL=${hasTunnel ? settings.tunnelUrl + "/proxy" : localBaseUrl + "/proxy"}\nANTHROPIC_API_KEY=${settings.authKey}`,
|
|
196
|
-
"anthropic-env",
|
|
197
|
-
)}
|
|
249
|
+
onClick={() => handleCopy(anthropicEnv, "anthropic-env")}
|
|
198
250
|
>
|
|
199
251
|
{copied === "anthropic-env" ? "Copied!" : <Copy className="size-2.5" />}
|
|
200
252
|
</Button>
|
|
@@ -204,18 +256,12 @@ ANTHROPIC_API_KEY=${settings.authKey}`}
|
|
|
204
256
|
<div className="space-y-1">
|
|
205
257
|
<Label className="text-[10px] text-muted-foreground">OpenAI Format</Label>
|
|
206
258
|
<div className="relative">
|
|
207
|
-
<pre className="text-[9px] font-mono bg-muted p-2 rounded overflow-x-auto whitespace-pre">
|
|
208
|
-
{`OPENAI_BASE_URL=${hasTunnel ? settings.tunnelUrl + "/proxy/v1" : localBaseUrl + "/proxy/v1"}
|
|
209
|
-
OPENAI_API_KEY=${settings.authKey}`}
|
|
210
|
-
</pre>
|
|
259
|
+
<pre className="text-[9px] font-mono bg-muted p-2 rounded overflow-x-auto whitespace-pre">{openAiEnv}</pre>
|
|
211
260
|
<Button
|
|
212
261
|
variant="ghost"
|
|
213
262
|
size="sm"
|
|
214
263
|
className="absolute top-1 right-1 h-5 px-1 cursor-pointer"
|
|
215
|
-
onClick={() => handleCopy(
|
|
216
|
-
`OPENAI_BASE_URL=${hasTunnel ? settings.tunnelUrl + "/proxy/v1" : localBaseUrl + "/proxy/v1"}\nOPENAI_API_KEY=${settings.authKey}`,
|
|
217
|
-
"openai-env",
|
|
218
|
-
)}
|
|
264
|
+
onClick={() => handleCopy(openAiEnv, "openai-env")}
|
|
219
265
|
>
|
|
220
266
|
{copied === "openai-env" ? "Copied!" : <Copy className="size-2.5" />}
|
|
221
267
|
</Button>
|
|
@@ -4,6 +4,7 @@ import { Button } from "@/components/ui/button";
|
|
|
4
4
|
import { Input } from "@/components/ui/input";
|
|
5
5
|
import { Label } from "@/components/ui/label";
|
|
6
6
|
import { CLAUDE_MODELS } from "../../../types/claude-models";
|
|
7
|
+
import { proxyEndpoints } from "@/lib/proxy-endpoints";
|
|
7
8
|
import {
|
|
8
9
|
Dialog, DialogContent, DialogHeader, DialogTitle, DialogDescription, DialogTrigger,
|
|
9
10
|
} from "@/components/ui/dialog";
|
|
@@ -16,6 +17,8 @@ type EndpointFormat = "anthropic" | "openai";
|
|
|
16
17
|
interface ProxyTestDialogProps {
|
|
17
18
|
authKey: string;
|
|
18
19
|
baseUrl: string;
|
|
20
|
+
/** Provider prefix to test; empty means the unscoped Claude path. */
|
|
21
|
+
provider?: string;
|
|
19
22
|
}
|
|
20
23
|
|
|
21
24
|
export function ProxyTestButton(props: ProxyTestDialogProps) {
|
|
@@ -42,10 +45,12 @@ export function ProxyTestButton(props: ProxyTestDialogProps) {
|
|
|
42
45
|
);
|
|
43
46
|
}
|
|
44
47
|
|
|
45
|
-
function ProxyTestForm({ authKey, baseUrl }: ProxyTestDialogProps) {
|
|
48
|
+
function ProxyTestForm({ authKey, baseUrl, provider }: ProxyTestDialogProps) {
|
|
46
49
|
const [format, setFormat] = useState<EndpointFormat>("anthropic");
|
|
47
50
|
const [message, setMessage] = useState(DEFAULT_MESSAGE);
|
|
48
|
-
|
|
51
|
+
// Only the unscoped path is Claude's. Another provider rejects a Claude model
|
|
52
|
+
// name outright, so the test starts with none and lets that provider choose.
|
|
53
|
+
const [model, setModel] = useState(provider ? "" : DEFAULT_MODEL);
|
|
49
54
|
const [streaming, setStreaming] = useState(true);
|
|
50
55
|
const [testing, setTesting] = useState(false);
|
|
51
56
|
const [output, setOutput] = useState<string | null>(null);
|
|
@@ -75,11 +80,18 @@ function ProxyTestForm({ authKey, baseUrl }: ProxyTestDialogProps) {
|
|
|
75
80
|
const start = Date.now();
|
|
76
81
|
|
|
77
82
|
const isOpenAi = format === "openai";
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
83
|
+
// Same helper the Connection Info card uses. Testing the unscoped path while
|
|
84
|
+
// the card showed a provider was exactly the bug: the answer came back from
|
|
85
|
+
// Claude and looked like the proxy returning the wrong thing.
|
|
86
|
+
const ep = proxyEndpoints(baseUrl, provider);
|
|
87
|
+
const endpoint = isOpenAi ? ep.openAiChatCompletions : ep.anthropicMessages;
|
|
81
88
|
|
|
82
|
-
const body = JSON.stringify({
|
|
89
|
+
const body = JSON.stringify({
|
|
90
|
+
...(model ? { model } : {}),
|
|
91
|
+
max_tokens: 256,
|
|
92
|
+
stream: streaming,
|
|
93
|
+
messages: [{ role: "user", content: message }],
|
|
94
|
+
});
|
|
83
95
|
|
|
84
96
|
const headers: Record<string, string> = { "Content-Type": "application/json" };
|
|
85
97
|
if (isOpenAi) {
|
|
@@ -147,23 +159,39 @@ function ProxyTestForm({ authKey, baseUrl }: ProxyTestDialogProps) {
|
|
|
147
159
|
</button>
|
|
148
160
|
))}
|
|
149
161
|
</div>
|
|
150
|
-
<p className="text-[9px] text-muted-foreground">
|
|
162
|
+
<p className="text-[9px] text-muted-foreground break-all">
|
|
151
163
|
{format === "anthropic" ? "x-api-key header" : "Authorization: Bearer header"}
|
|
164
|
+
{" · "}
|
|
165
|
+
<code>{`/proxy${provider ? `/${provider}` : ""}/v1/${format === "anthropic" ? "messages" : "chat/completions"}`}</code>
|
|
152
166
|
</p>
|
|
153
167
|
</div>
|
|
154
168
|
|
|
155
|
-
{/* Model */}
|
|
169
|
+
{/* Model — the Claude list only applies to the unscoped path. */}
|
|
156
170
|
<div className="space-y-1.5">
|
|
157
171
|
<Label className="text-[11px]">Model</Label>
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
172
|
+
{provider ? (
|
|
173
|
+
<>
|
|
174
|
+
<Input
|
|
175
|
+
value={model}
|
|
176
|
+
onChange={(e) => setModel(e.target.value)}
|
|
177
|
+
placeholder="leave empty to let the provider choose"
|
|
178
|
+
className="h-8 text-[11px] font-mono"
|
|
179
|
+
/>
|
|
180
|
+
<p className="text-[9px] text-muted-foreground">
|
|
181
|
+
Names come from <code>GET /proxy/{provider}/v1/models</code>.
|
|
182
|
+
</p>
|
|
183
|
+
</>
|
|
184
|
+
) : (
|
|
185
|
+
<select
|
|
186
|
+
value={model}
|
|
187
|
+
onChange={(e) => setModel(e.target.value)}
|
|
188
|
+
className="h-8 w-full rounded-md border bg-background px-2 text-[11px]"
|
|
189
|
+
>
|
|
190
|
+
{CLAUDE_MODELS.map((m) => (
|
|
191
|
+
<option key={m.value} value={m.value}>{m.value}</option>
|
|
192
|
+
))}
|
|
193
|
+
</select>
|
|
194
|
+
)}
|
|
167
195
|
</div>
|
|
168
196
|
|
|
169
197
|
{/* Streaming toggle */}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one place that knows how a proxy URL is shaped.
|
|
3
|
+
*
|
|
4
|
+
* The Connection Info card and the Test dialog both need these. They used to
|
|
5
|
+
* build them separately, and the Test dialog never learned about provider
|
|
6
|
+
* prefixes — so picking a provider showed one set of URLs while Test quietly
|
|
7
|
+
* called another, and the answer came back from the wrong engine.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/** `<root>/proxy` for the default Claude path, `<root>/proxy/<provider>` otherwise. */
|
|
11
|
+
export function proxyPrefix(root: string, provider?: string): string {
|
|
12
|
+
return `${root}/proxy${provider ? `/${provider}` : ""}`;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface ProxyEndpoints {
|
|
16
|
+
/** Anthropic SDK base — the SDK appends `/v1/messages` itself. */
|
|
17
|
+
anthropicBase: string;
|
|
18
|
+
/** OpenAI SDK base — the SDK appends `/chat/completions` itself. */
|
|
19
|
+
openAiBase: string;
|
|
20
|
+
anthropicMessages: string;
|
|
21
|
+
openAiChatCompletions: string;
|
|
22
|
+
models: string;
|
|
23
|
+
/** Images live only under a provider; the default path has no such route. */
|
|
24
|
+
imagesGenerations: string | null;
|
|
25
|
+
imagesEdits: string | null;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function proxyEndpoints(root: string, provider?: string): ProxyEndpoints {
|
|
29
|
+
const prefix = proxyPrefix(root, provider);
|
|
30
|
+
return {
|
|
31
|
+
anthropicBase: prefix,
|
|
32
|
+
openAiBase: `${prefix}/v1`,
|
|
33
|
+
anthropicMessages: `${prefix}/v1/messages`,
|
|
34
|
+
openAiChatCompletions: `${prefix}/v1/chat/completions`,
|
|
35
|
+
models: `${prefix}/v1/models`,
|
|
36
|
+
imagesGenerations: provider ? `${prefix}/v1/images/generations` : null,
|
|
37
|
+
imagesEdits: provider ? `${prefix}/v1/images/edits` : null,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
@@ -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-YDu4m2Iq.js";import{n as l,r as u}from"./api-client-oY1tC3tM.js";import{n as d}from"./utils-C9OjCrou.js";import"./portal-container-context-a399Hd9F.js";import{n as f}from"./use-is-mobile-CYW3FJFE.js";import{n as p,t as m}from"./button-BZtEJcUv.js";import{t as h}from"./mobile-bottom-sheet-BD5b7KJF.js";import"./use-visual-viewport-rnvuooQZ.js";import{$t as g,B as _,Cr as v,H as y,J as b,Jn as x,Jt as S,Pn as C,Qt as w,U as T,V as E,Vn as D,W as O,Xt as k,Y as A,Yt as j,Zt as M,ar as N,er as P,j as F,jn as I,tn as ee,z as te}from"./index-B1bzKRjJ.js";import{addAccount as L,deleteAccount as ne,exchangeOAuthCode as re,getAISettings as ie,getAccountSettings as ae,getOAuthUrl as oe,getUsageHistory as se,importAccounts as ce,patchAccount as le,testAccountToken as ue,testExport as de,testRawToken as fe,updateAccountSettings as R}from"./api-settings-CTMdz_VF.js";import{a as z,c as B,i as V,l as pe,n as me,o as H,r as U,t as he}from"./use-accounts-data-MhMl0Y4Z.js";var W=e(t(),1),G=n(),K=[`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`,`Sun`],q=Array.from({length:24},(e,t)=>t);function ge(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 _e(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 ve(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 J(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 ye(e){return e<.3?`bg-success`:e<.7?`bg-warning`:`bg-error`}function be({accountId:e}){let[t,n]=(0,W.useState)(null),[r,i]=(0,W.useState)(!0),[a,o]=(0,W.useState)(`5h`);(0,W.useEffect)(()=>{i(!0),se(e).then(n).catch(()=>n([])).finally(()=>i(!1))},[e]);let c=(0,W.useMemo)(()=>t?ge(t,a):null,[t,a]),l=(0,W.useMemo)(()=>c?_e(c):[],[c]),u=(0,W.useMemo)(()=>c?ve(c):[],[c]),d=Math.max(...l,.01);if(Math.max(...u,.01),r)return(0,G.jsx)(`div`,{className:`flex items-center justify-center py-3`,children:(0,G.jsx)(s,{className:`size-3 animate-spin text-text-subtle`})});if(!t||t.length===0)return(0,G.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,G.jsxs)(`div`,{className:`mt-2 space-y-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`span`,{className:`text-[10px] font-medium text-text-subtle`,children:`Usage Pattern (7d)`}),(0,G.jsxs)(`div`,{className:`flex gap-0.5 text-[9px]`,children:[(0,G.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,G.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,G.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,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-[9px] text-text-subtle`,children:`Avg usage by day of week`}),(0,G.jsx)(`div`,{className:`flex flex-col gap-[2px] mt-0.5`,children:K.map((e,t)=>{let n=l[t]??0;return(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(`span`,{className:`text-[8px] text-text-subtle w-5 shrink-0 text-right tabular-nums`,children:e}),(0,G.jsx)(`div`,{className:`flex-1 h-2.5 bg-surface-elevated rounded-sm overflow-hidden`,children:(0,G.jsx)(`div`,{className:`h-full rounded-sm transition-all ${ye(n)}`,style:{width:`${Math.round(n/d*100)}%`}})}),(0,G.jsxs)(`span`,{className:`text-[8px] text-text-subtle w-6 shrink-0 text-right tabular-nums`,children:[Math.round(n*100),`%`]})]},e)})})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-[9px] text-text-subtle`,children:`Avg usage by hour (0h-23h)`}),(0,G.jsx)(`div`,{className:`flex gap-[1px] mt-0.5`,children:q.map(e=>{let t=u[e]??0;return(0,G.jsxs)(`div`,{className:`flex-1 flex flex-col items-center gap-[1px]`,children:[(0,G.jsx)(`div`,{className:`w-full aspect-square rounded-[2px] ${J(t)}`,title:`${e}:00 — avg ${Math.round(t*100)}% usage`}),e%6==0&&(0,G.jsx)(`span`,{className:`text-[7px] text-text-subtle tabular-nums`,children:e})]},e)})})]}),c&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-[9px] text-text-subtle`,children:`Day x Hour heatmap`}),(0,G.jsxs)(`div`,{className:`flex flex-col gap-[1px] mt-0.5`,children:[K.map((e,t)=>(0,G.jsxs)(`div`,{className:`flex items-center gap-[1px]`,children:[(0,G.jsx)(`span`,{className:`text-[7px] text-text-subtle w-4 shrink-0 text-right`,children:e.charAt(0)}),q.map(n=>{let r=c[t][n];return(0,G.jsx)(`div`,{className:`flex-1 aspect-square rounded-[1px] ${J(r.avg)}`,title:`${e} ${n}:00 — ${r.count>0?`avg ${Math.round(r.avg*100)}% (${r.count} samples)`:`no data`}`},n)})]},e)),(0,G.jsxs)(`div`,{className:`flex items-center gap-[1px]`,children:[(0,G.jsx)(`span`,{className:`w-4 shrink-0`}),q.map(e=>(0,G.jsx)(`div`,{className:`flex-1 text-center`,children:e%6==0&&(0,G.jsx)(`span`,{className:`text-[7px] text-text-subtle tabular-nums`,children:e})},e))]})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[8px] text-text-subtle`,children:[(0,G.jsx)(`span`,{children:`Low`}),(0,G.jsxs)(`div`,{className:`flex gap-[2px]`,children:[(0,G.jsx)(`div`,{className:`size-2 rounded-[1px] bg-success/30`}),(0,G.jsx)(`div`,{className:`size-2 rounded-[1px] bg-success/60`}),(0,G.jsx)(`div`,{className:`size-2 rounded-[1px] bg-warning/50`}),(0,G.jsx)(`div`,{className:`size-2 rounded-[1px] bg-warning/80`}),(0,G.jsx)(`div`,{className:`size-2 rounded-[1px] bg-error/80`})]}),(0,G.jsx)(`span`,{children:`High`}),(0,G.jsx)(`span`,{className:`ml-1`,children:`|`}),(0,G.jsx)(`div`,{className:`size-2 rounded-[1px] bg-surface-elevated border border-border/30`}),(0,G.jsx)(`span`,{children:`No data`})]})]})}function xe({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,G.jsxs)(`section`,{className:`space-y-2 border-t border-border pt-3`,"data-testid":`account-profile-panel`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`h3`,{className:`text-sm font-medium`,children:`Profile`}),(0,G.jsx)(`button`,{className:`p-2 text-muted-foreground hover:text-foreground cursor-pointer`,onClick:n,"aria-label":`Close profile`,children:(0,G.jsx)(c,{className:`size-4`})})]}),(0,G.jsx)(`div`,{className:`grid grid-cols-[80px_1fr] gap-x-3 gap-y-1 text-xs`,children:r.map(([e,t])=>t?(0,G.jsxs)(`span`,{className:`contents`,children:[(0,G.jsx)(`span`,{className:`text-muted-foreground`,children:e}),(0,G.jsx)(`span`,{className:`break-all`,children:t})]},e):null)}),(0,G.jsx)(be,{accountId:t})]})}function Se({display:e,onConfirm:t,onCancel:n}){let r=f(),i=(0,G.jsxs)(`div`,{className:`space-y-4`,"data-testid":`account-delete-confirm`,children:[(0,G.jsxs)(`p`,{className:`text-sm`,children:[`Remove `,(0,G.jsx)(`span`,{className:`font-medium`,children:e}),`?`]}),(0,G.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,G.jsxs)(`div`,{className:`flex flex-col-reverse md:flex-row gap-2 md:justify-end pt-2`,children:[(0,G.jsx)(m,{variant:`outline`,onClick:n,className:`min-h-11`,children:`Cancel`}),(0,G.jsx)(m,{variant:`destructive`,autoFocus:!1,onClick:t,className:`min-h-11`,children:`Remove account`})]})]});return r?(0,G.jsx)(h,{open:!0,onClose:n,children:(0,G.jsxs)(`div`,{className:`px-4 pb-4`,children:[(0,G.jsx)(`h2`,{className:`text-base font-semibold mb-3`,children:`Remove account`}),i]})}):(0,G.jsx)(S,{open:!0,onOpenChange:e=>{e||n()},children:(0,G.jsxs)(j,{className:`sm:max-w-sm`,children:[(0,G.jsx)(w,{children:(0,G.jsx)(g,{className:`text-sm`,children:`Remove account`})}),i]})})}function Ce({open:e,onOpenChange:t,onSuccess:n}){let[r,i]=(0,W.useState)(``),[a,o]=(0,W.useState)(``),[c,l]=(0,W.useState)(!1),[u,d]=(0,W.useState)(null),[f,p]=(0,W.useState)(null),[h,_]=(0,W.useState)(``),[v,y]=(0,W.useState)(!1),[x,C]=(0,W.useState)(`idle`);function T(){p(null),_(``),C(`idle`),d(null)}function E(){t(!1),T(),i(``),o(``),d(null)}async function D(){y(!0),d(null);try{let{url:e,state:t}=await oe();p(t),C(`waiting`),window.open(e,`_blank`)}catch(e){d(e.message)}y(!1)}async function O(){if(!(!h.trim()||!f)){y(!0),d(null);try{let e=h.trim();e.includes(`#`)&&(e=e.split(`#`)[0]??e);let t=await re(e,f);E(),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 N(){if(r.trim()){l(!0),d(null);try{let e=await L({apiKey:r.trim(),label:a.trim()||void 0});E(),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 P=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,G.jsx)(S,{open:e,onOpenChange:e=>{e||E()},children:(0,G.jsxs)(j,{className:`sm:max-w-md`,children:[(0,G.jsxs)(w,{children:[(0,G.jsx)(g,{className:`text-sm`,children:`Add Claude Account`}),(0,G.jsx)(k,{className:`text-xs leading-relaxed`,children:`Connect via OAuth (recommended) or paste a token manually.`})]}),(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{className:`rounded-md border p-3 space-y-2`,children:[(0,G.jsx)(`p`,{className:`text-[11px] font-medium`,children:`Recommended: Login with Claude`}),x===`idle`?(0,G.jsx)(m,{size:`sm`,className:`w-full h-8 text-xs`,onClick:D,disabled:v,children:v?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(s,{className:`size-3 animate-spin mr-1`}),` Opening...`]}):`Login with Claude`}):(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:`Authorize in the opened tab, then paste the code:`}),(0,G.jsx)(A,{placeholder:`Paste code here...`,value:h,onChange:e=>_(e.target.value),className:`text-xs h-8 font-mono`,autoFocus:!0}),(0,G.jsxs)(`div`,{className:`flex gap-1.5`,children:[(0,G.jsx)(m,{size:`sm`,className:`flex-1 h-7 text-xs`,onClick:O,disabled:!h.trim()||v,children:v?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(s,{className:`size-3 animate-spin mr-1`}),` Connecting...`]}):`Connect`}),(0,G.jsx)(m,{size:`sm`,variant:`ghost`,className:`h-7 text-xs`,onClick:T,children:`Cancel`})]})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`div`,{className:`flex-1 border-t`}),(0,G.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`or paste token`}),(0,G.jsx)(`div`,{className:`flex-1 border-t`})]}),(0,G.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,G.jsx)(b,{htmlFor:`add-token`,className:`text-xs`,children:`Token`}),(0,G.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`}),P&&(0,G.jsxs)(`p`,{className:`text-[10px] text-muted-foreground`,children:[`Detected: `,P]})]}),(0,G.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,G.jsx)(b,{htmlFor:`add-label`,className:`text-xs`,children:`Label (optional)`}),(0,G.jsx)(A,{id:`add-label`,placeholder:`e.g. Personal, Work`,value:a,onChange:e=>o(e.target.value),className:`text-xs h-8`})]})]}),u&&(0,G.jsx)(`div`,{className:`text-[11px] p-2 rounded bg-error/10 text-error`,children:u}),(0,G.jsxs)(M,{children:[(0,G.jsx)(m,{size:`sm`,variant:`outline`,className:`text-xs h-7`,onClick:E,children:`Cancel`}),(0,G.jsx)(m,{size:`sm`,className:`text-xs h-7`,onClick:N,disabled:!r.trim()||c,children:c?`Adding...`:`Add Token`})]})]})})}function we(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 Te({open:e,onOpenChange:t,accounts:n,preselectId:a,onMessage:o}){let c=n.filter(e=>e.hasRefreshToken),[l,d]=(0,W.useState)(new Set),[f,p]=(0,W.useState)(``),[h,_]=(0,W.useState)(!1),[v,y]=(0,W.useState)(!1),[x,C]=(0,W.useState)(!1),[T,E]=(0,W.useState)(!1);e&&!T&&(d(a?new Set([a]):new Set(c.map(e=>e.id))),E(!0)),!e&&T&&E(!1);function D(){t(!1),p(``),_(!1),y(!1)}async function O(e){if(l.size===0)return;C(!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 ee(a)?o?.(`Backup copied to clipboard!`):(we(a),o?.(`Backup downloaded.`)),D()}catch{}C(!1)}let P=l.size>0&&!x;return(0,G.jsx)(S,{open:e,onOpenChange:e=>{e||D()},children:(0,G.jsxs)(j,{className:`sm:max-w-md`,children:[(0,G.jsxs)(w,{children:[(0,G.jsxs)(g,{className:`text-sm flex items-center gap-1.5`,children:[(0,G.jsx)(N,{className:`size-3.5`}),` Export Accounts`]}),(0,G.jsx)(k,{className:`text-xs`,children:`Select accounts and set a password to protect the backup.`})]}),(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{className:`space-y-1`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-1`,children:[(0,G.jsx)(`p`,{className:`text-[11px] font-medium text-muted-foreground`,children:`Accounts to export`}),(0,G.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,G.jsx)(`p`,{className:`text-[10px] text-muted-foreground p-2 border rounded`,children:`No exportable accounts.`}):(0,G.jsx)(`div`,{className:`max-h-36 overflow-y-auto space-y-1 border rounded p-2`,children:c.map(e=>(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.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,G.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,G.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,G.jsxs)(b,{className:`text-xs`,children:[`Password `,(0,G.jsx)(`span`,{className:`text-muted-foreground font-normal`,children:`(optional)`})]}),(0,G.jsx)(A,{type:`password`,placeholder:`Leave empty for default`,value:f,onChange:e=>p(e.target.value),className:`text-xs h-8`,autoComplete:`new-password`})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`input`,{type:`checkbox`,id:`exp-full`,checked:h,onChange:e=>_(e.target.checked),className:`size-3.5 accent-primary cursor-pointer`}),(0,G.jsx)(`label`,{htmlFor:`exp-full`,className:`text-[11px] cursor-pointer`,children:`Include refresh tokens (full transfer)`})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`input`,{type:`checkbox`,id:`exp-refresh`,checked:v,onChange:e=>y(e.target.checked),className:`size-3.5 accent-primary cursor-pointer`}),(0,G.jsx)(`label`,{htmlFor:`exp-refresh`,className:`text-[11px] cursor-pointer`,children:`Refresh tokens before export`})]}),h?(0,G.jsxs)(`div`,{className:`rounded-md border border-error/30 bg-error/5 p-2.5`,children:[(0,G.jsx)(`p`,{className:`text-[10px] font-medium text-error`,children:`Full transfer — source accounts will expire`}),(0,G.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:`Refresh tokens included. Source machine expires in ~1h after target refreshes.`})]}):v?(0,G.jsx)(`div`,{className:`rounded-md border border-warning/30 bg-warning/5 p-2.5`,children:(0,G.jsx)(`p`,{className:`text-[10px] font-medium text-warning`,children:`Refresh before export — invalidates previous shares`})}):(0,G.jsx)(`div`,{className:`rounded-md border border-success/30 bg-success/5 p-2.5`,children:(0,G.jsx)(`p`,{className:`text-[10px] font-medium text-success`,children:`Share current token (safe)`})}),(0,G.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:`Encrypted with AES-256-GCM + scrypt.`})]}),(0,G.jsxs)(M,{className:`gap-1.5 flex-col sm:flex-row`,children:[(0,G.jsx)(m,{size:`sm`,variant:`outline`,className:`text-xs h-7 cursor-pointer`,onClick:D,children:`Cancel`}),(0,G.jsxs)(m,{size:`sm`,variant:`outline`,className:`text-xs h-7 cursor-pointer`,disabled:!P,onClick:()=>O(!0),children:[(0,G.jsx)(r,{className:`size-3 mr-1`}),` Copy`]}),(0,G.jsx)(m,{size:`sm`,className:`text-xs h-7 cursor-pointer`,disabled:!P,onClick:()=>O(!1),children:x?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(s,{className:`size-3 animate-spin mr-1`}),` Exporting...`]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(i,{className:`size-3 mr-1`}),` Download`]})})]})]})})}function Ee({open:e,onOpenChange:t,onSuccess:n}){let[r,i]=(0,W.useState)(``),[a,o]=(0,W.useState)(``),[c,l]=(0,W.useState)(!1),[u,d]=(0,W.useState)(null);function f(){t(!1),i(``),o(``),d(null)}async function p(){if(r.trim()){l(!0),d(null);try{let e=await ce({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,G.jsx)(S,{open:e,onOpenChange:e=>{e||f()},children:(0,G.jsxs)(j,{className:`sm:max-w-md`,children:[(0,G.jsxs)(w,{children:[(0,G.jsxs)(g,{className:`text-sm flex items-center gap-1.5`,children:[(0,G.jsx)(N,{className:`size-3.5`}),` Import Accounts`]}),(0,G.jsx)(k,{className:`text-xs`,children:`Paste backup data and enter the export password. Imported accounts are temporary (~1h).`})]}),(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,G.jsx)(b,{className:`text-xs`,children:`Backup data`}),(0,G.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,G.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,G.jsxs)(b,{className:`text-xs`,children:[`Password `,(0,G.jsx)(`span`,{className:`text-muted-foreground font-normal`,children:`(optional)`})]}),(0,G.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`})]})]}),u&&(0,G.jsx)(`div`,{className:`text-[11px] p-2 rounded bg-error/10 text-error`,children:u}),(0,G.jsxs)(M,{children:[(0,G.jsx)(m,{size:`sm`,variant:`outline`,className:`text-xs h-7 cursor-pointer`,onClick:f,children:`Cancel`}),(0,G.jsx)(m,{size:`sm`,className:`text-xs h-7 cursor-pointer`,disabled:!r.trim()||c,onClick:p,children:c?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(s,{className:`size-3 animate-spin mr-1`}),` Importing...`]}):`Import`})]})]})})}var Y=typeof window<`u`?window.matchMedia(`(min-width: 768px)`):null;function De(e){return Y?.addEventListener(`change`,e),()=>Y?.removeEventListener(`change`,e)}function Oe(){return Y?.matches??!0}function X(){let[e,t]=(0,W.useState)(null),[n,r]=(0,W.useState)(!0);return(0,W.useEffect)(()=>{r(!0),ae().then(t).finally(()=>r(!1))},[]),n?(0,G.jsx)(`p`,{className:`text-xs text-text-subtle py-4 text-center`,children:`Loading...`}):e?(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,G.jsx)(`label`,{className:`text-xs font-medium text-text-primary`,children:`Rotation Strategy`}),(0,G.jsxs)(te,{value:e.strategy,onValueChange:async e=>{t(await R({strategy:e}))},children:[(0,G.jsx)(y,{className:`w-full h-9 text-xs`,children:(0,G.jsx)(T,{})}),(0,G.jsxs)(_,{children:[(0,G.jsx)(E,{value:`round-robin`,children:`Round-robin`}),(0,G.jsx)(E,{value:`fill-first`,children:`Fill-first`}),(0,G.jsx)(E,{value:`lowest-usage`,children:`Lowest usage`})]})]}),(0,G.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,G.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,G.jsx)(`label`,{className:`text-xs font-medium text-text-primary`,children:`Max Retry`}),(0,G.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 R({maxRetry:n}))}}),(0,G.jsx)(`p`,{className:`text-[10px] text-text-subtle`,children:`How many accounts to try on failure. 0 = try all available accounts.`})]}),(0,G.jsxs)(`div`,{className:`space-y-1.5 border-t border-border pt-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`label`,{className:`text-xs font-medium text-text-primary`,children:`Cooldown parking`}),(0,G.jsx)(O,{checked:e.cooldownEnabled,onCheckedChange:async e=>{t(await R({cooldownEnabled:e}))}})]}),(0,G.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,G.jsxs)(`div`,{className:`flex items-center justify-between text-xs border-t border-border pt-3`,children:[(0,G.jsx)(`span`,{className:`text-text-subtle`,children:`Active accounts`}),(0,G.jsx)(`span`,{className:`font-medium text-text-primary`,children:e.activeCount})]})]}):(0,G.jsx)(`p`,{className:`text-xs text-text-subtle py-4 text-center`,children:`Failed to load settings`})}function ke({open:e,onOpenChange:t}){let n=(0,W.useSyncExternalStore)(De,Oe);return e?n?(0,G.jsx)(S,{open:e,onOpenChange:t,children:(0,G.jsxs)(j,{className:`sm:max-w-sm`,children:[(0,G.jsx)(w,{children:(0,G.jsxs)(g,{className:`text-sm flex items-center gap-2`,children:[(0,G.jsx)(D,{className:`size-4`}),` Rotation & Retry`]})}),(0,G.jsx)(X,{})]})}):(0,G.jsxs)(G.Fragment,{children:[(0,G.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,G.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,G.jsx)(`div`,{className:`flex justify-center pt-3 pb-1`,children:(0,G.jsx)(`div`,{className:`w-10 h-1 rounded-full bg-border`})}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-2 border-b border-border`,children:[(0,G.jsxs)(`span`,{className:`text-sm font-semibold flex items-center gap-2`,children:[(0,G.jsx)(D,{className:`size-4`}),` Rotation & Retry`]}),(0,G.jsx)(`button`,{onClick:()=>t(!1),className:`flex items-center justify-center size-7 rounded-md hover:bg-surface-elevated transition-colors`,children:(0,G.jsx)(c,{className:`size-4`})})]}),(0,G.jsx)(`div`,{className:`px-4 py-4 pb-8`,children:(0,G.jsx)(X,{})})]})]}):null}var Ae=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 Z({className:e,variant:t,...n}){return(0,G.jsx)(`div`,{className:d(Ae({variant:t}),e),...n})}function je(e){let t=Math.floor(Date.now()/1e3);return e>t?`${Math.floor((e-t)/60)}m`:`exp`}function Me({accounts:e}){let[t,n]=(0,W.useState)([]),[r,i]=(0,W.useState)(!1),[a,o]=(0,W.useState)(!1),[c,l]=(0,W.useState)(new Map),u=e.filter(e=>e.hasRefreshToken);async function d(){if(u.length!==0){i(!0);try{let e=await de(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 fe(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,G.jsxs)(`section`,{className:`border-t pt-4 space-y-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,G.jsx)(`p`,{className:`text-xs font-medium`,children:`Simulate export`}),t.length>0&&(0,G.jsxs)(`span`,{className:`text-[10px] text-muted-foreground`,children:[t.length,` round(s)`]})]}),(0,G.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,G.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`No OAuth account with a refresh token to export.`}):(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,G.jsx)(O,{id:`sim-include-refresh`,checked:a,onCheckedChange:o,className:`cursor-pointer`}),(0,G.jsx)(b,{htmlFor:`sim-include-refresh`,className:`text-[11px] cursor-pointer`,children:`Include refresh tokens`})]}),(0,G.jsx)(m,{size:`sm`,className:`h-7 text-xs cursor-pointer`,disabled:r,onClick:()=>void d(),children:r?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(s,{className:`size-3 animate-spin mr-1`}),` Exporting...`]}):`Run export #${t.length+1}`})]}),t.length>0&&(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.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,G.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(`p`,{className:`text-xs font-medium text-primary`,children:[`Round #`,e.round]}),(0,G.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:e.time}),(0,G.jsx)(Z,{variant:e.includeRefresh?`destructive`:`secondary`,className:`text-[9px] px-1 py-0`,children:e.includeRefresh?`with refresh`:`access only`})]}),e.items.map(t=>(0,G.jsxs)(`div`,{className:`p-2 rounded-lg border bg-card space-y-1.5`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-[11px] font-medium`,children:t.label??t.email??t.id.slice(0,8)}),t.tokenChanged&&(0,G.jsx)(Z,{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,G.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px]`,children:[(0,G.jsx)(`span`,{className:`w-20 shrink-0 text-muted-foreground text-[10px]`,children:e.label}),(0,G.jsx)(`code`,{className:`flex-1 truncate font-mono text-[10px] bg-muted px-1 rounded`,children:e.preview??`N/A`}),e.expires&&(0,G.jsx)(`span`,{className:`text-[10px] text-muted-foreground shrink-0`,children:je(e.expires)}),e.token?(0,G.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,G.jsx)(s,{className:`size-3 animate-spin`}):`Test`}):(0,G.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`-`}),t&&!t.loading&&(0,G.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 Ne(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 Pe({open:e,onOpenChange:t,accounts:n}){let[r,i]=(0,W.useState)(new Map),[o,c]=(0,W.useState)(!1);async function l(e){i(t=>new Map(t).set(e,{loading:!0}));try{let t=await ue(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,G.jsx)(S,{open:e,onOpenChange:t,children:(0,G.jsxs)(j,{className:`sm:max-w-xl max-h-[85vh] flex flex-col`,children:[(0,G.jsxs)(w,{children:[(0,G.jsxs)(g,{className:`text-sm flex items-center gap-1.5`,children:[(0,G.jsx)(a,{className:`size-4`}),` Token Test`]}),(0,G.jsx)(k,{className:`text-xs`,children:`Probe stored tokens for validity. Nothing is modified.`})]}),(0,G.jsxs)(`div`,{className:`space-y-4 overflow-y-auto flex-1 pr-1`,children:[(0,G.jsxs)(`section`,{className:`space-y-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,G.jsx)(`p`,{className:`text-xs font-medium`,children:`Current tokens`}),(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,G.jsx)(O,{id:`token-test-refresh`,checked:o,onCheckedChange:c,className:`cursor-pointer`}),(0,G.jsx)(b,{htmlFor:`token-test-refresh`,className:`text-[11px] cursor-pointer`,children:`Also test refresh`})]}),(0,G.jsx)(m,{size:`sm`,variant:`outline`,className:`h-7 text-xs cursor-pointer`,onClick:u,children:`Test all`})]})]}),n.length===0&&(0,G.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`No accounts to test.`}),(0,G.jsx)(`div`,{className:`space-y-1.5`,children:n.map(e=>{let t=r.get(e.id),n=t?.result?.accessToken.status;return(0,G.jsxs)(`div`,{className:`p-2 rounded border bg-card space-y-1`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,G.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,G.jsx)(`span`,{className:`text-xs font-medium truncate block`,children:e.label??e.email??e.id.slice(0,8)}),e.expiresAt&&(0,G.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:Ne(e.expiresAt)})]}),(0,G.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,G.jsx)(s,{className:`size-3 animate-spin`}):`Test`})]}),t&&!t.loading&&(0,G.jsxs)(`div`,{className:`text-[11px] pl-2 border-l-2 border-muted`,children:[t.error&&(0,G.jsx)(`p`,{className:`text-error`,children:t.error}),n&&(0,G.jsxs)(`span`,{className:n.startsWith(`valid`)?`text-success`:`text-error`,children:[n,t.result?.accessToken.code?` (${t.result.accessToken.code})`:``]})]})]},e.id)})})]}),(0,G.jsx)(Me,{accounts:n})]}),(0,G.jsx)(M,{children:(0,G.jsx)(m,{size:`sm`,variant:`outline`,className:`text-xs cursor-pointer`,onClick:()=>t(!1),children:`Close`})})]})})}function Fe(){let{usages:e,accounts:t,activeAccountId:n,initialLoading:r,refreshing:c,flashIds:l,reload:u}=he(),[d,f]=(0,W.useState)(null),[p,h]=(0,W.useState)(null),[g,_]=(0,W.useState)(null),[v,y]=(0,W.useState)(null),[b,S]=(0,W.useState)(null),[C,w]=(0,W.useState)(null);function T(e){u(),e&&f(e)}async function E(e,t){h(e);try{await le(e,{status:t===`disabled`?`active`:`disabled`})}catch(e){f(e.message)}h(null),u()}async function O(){if(g){try{await ne(g.id),f(`Account "${g.display}" removed.`),u()}catch(e){f(`Failed to remove: ${e.message}`)}_(null)}}let k=new Map(t.map(e=>[e.id,e])),A=e[0]?.usage.lastFetchedAt;return(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsx)(z,{description:`Connect multiple Claude accounts. PPM rotates between them automatically to avoid rate limits.`,onRefresh:()=>void u(),refreshing:c,disabled:r,actions:(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(m,{size:`sm`,className:`cursor-pointer gap-1.5`,onClick:()=>w(`add`),children:[(0,G.jsx)(x,{className:`size-4`}),` Add account`]}),(0,G.jsxs)(m,{size:`sm`,variant:`outline`,className:`cursor-pointer gap-1.5`,onClick:()=>{S(null),w(`export`)},children:[(0,G.jsx)(i,{className:`size-4`}),` Export`]}),(0,G.jsxs)(m,{size:`sm`,variant:`outline`,className:`cursor-pointer gap-1.5`,onClick:()=>w(`import`),children:[(0,G.jsx)(I,{className:`size-4`}),` Import`]}),(0,G.jsxs)(m,{size:`sm`,variant:`outline`,className:`cursor-pointer gap-1.5`,onClick:()=>w(`rotation`),children:[(0,G.jsx)(D,{className:`size-4`}),` Rotation`]}),(0,G.jsxs)(m,{size:`sm`,variant:`outline`,className:`cursor-pointer gap-1.5`,onClick:()=>w(`token-test`),children:[(0,G.jsx)(a,{className:`size-4`}),` Token test`]})]})}),(0,G.jsx)(H,{message:d,onDismiss:()=>f(null)}),(0,G.jsxs)(`section`,{className:`space-y-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`h3`,{className:`text-sm font-medium`,children:`Accounts`}),A&&(0,G.jsxs)(`span`,{className:`text-[10px] text-muted-foreground`,children:[`usage `,pe(new Date(A).getTime())]})]}),r?(0,G.jsxs)(`div`,{className:`flex items-center gap-2 py-6 text-xs text-muted-foreground`,children:[(0,G.jsx)(s,{className:`size-4 animate-spin`}),` Loading accounts...`]}):e.length===0?(0,G.jsxs)(`div`,{className:`flex flex-col items-center gap-2 py-8 text-center`,children:[(0,G.jsx)(o,{className:`size-5 text-muted-foreground`}),(0,G.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`No accounts connected yet.`}),(0,G.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Add one to start using PPM.`})]}):(0,G.jsx)(U,{children:e.map(e=>(0,G.jsx)(me,{layout:`strip`,entry:e,isActive:e.accountId===n,accountInfo:k.get(e.accountId),onToggle:E,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,G.jsx)(xe,{profile:v.profile,accountId:v.accountId,onClose:()=>y(null)}),g&&(0,G.jsx)(Se,{display:g.display,onConfirm:()=>void O(),onCancel:()=>_(null)}),(0,G.jsx)(Ce,{open:C===`add`,onOpenChange:e=>w(e?`add`:null),onSuccess:T}),(0,G.jsx)(Te,{open:C===`export`,onOpenChange:e=>{w(e?`export`:null),e||S(null)},accounts:t,preselectId:b,onMessage:f}),(0,G.jsx)(Ee,{open:C===`import`,onOpenChange:e=>w(e?`import`:null),onSuccess:T}),(0,G.jsx)(ke,{open:C===`rotation`,onOpenChange:e=>w(e?`rotation`:null)}),(0,G.jsx)(Pe,{open:C===`token-test`,onOpenChange:e=>w(e?`token-test`:null),accounts:t})]})}function Q({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,G.jsx)(S,{open:e,onOpenChange:t,children:(0,G.jsxs)(j,{className:`sm:max-w-md`,children:[(0,G.jsxs)(w,{children:[(0,G.jsx)(g,{className:`text-sm`,children:`Add Codex Account`}),(0,G.jsxs)(k,{className:`text-xs leading-relaxed`,children:[`Each account keeps its own login (its own `,(0,G.jsx)(`code`,{children:`CODEX_HOME`}),`).`]})]}),(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{className:`rounded-md border p-3 space-y-2`,children:[(0,G.jsx)(`p`,{className:`text-[11px] font-medium`,children:`Recommended: sign in with ChatGPT`}),(0,G.jsx)(m,{size:`sm`,className:`w-full cursor-pointer gap-1.5`,onClick:d,disabled:u,children:u?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(s,{className:`size-4 animate-spin`}),` Waiting for authorization...`]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(P,{className:`size-4`}),` Sign in with ChatGPT`]})}),f&&(0,G.jsxs)(`div`,{className:`rounded-md border border-primary/40 bg-primary/10 p-2.5 space-y-1.5`,children:[(0,G.jsx)(`p`,{className:`text-[11px]`,children:`Enter this code to authorize:`}),(0,G.jsx)(`div`,{className:`font-mono text-lg tracking-widest`,children:f.userCode}),(0,G.jsxs)(`a`,{href:f.verificationUrl,target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1 text-primary hover:underline text-[11px]`,children:[(0,G.jsx)(v,{className:`size-3`}),` `,f.verificationUrl]})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`div`,{className:`flex-1 border-t`}),(0,G.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`or paste an API key`}),(0,G.jsx)(`div`,{className:`flex-1 border-t`})]}),(0,G.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,G.jsx)(b,{htmlFor:`codex-api-key`,className:`text-xs`,children:`OpenAI API key`}),(0,G.jsx)(A,{id:`codex-api-key`,type:`password`,placeholder:`sk-...`,value:i,onChange:e=>a(e.target.value),className:`text-xs font-mono`})]}),(0,G.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,G.jsx)(b,{htmlFor:`codex-label`,className:`text-xs`,children:`Label (optional)`}),(0,G.jsx)(A,{id:`codex-label`,placeholder:`e.g. Personal, Work`,value:n,onChange:e=>r(e.target.value),className:`text-xs`})]})]}),p&&(0,G.jsx)(`div`,{className:`text-[11px] p-2 rounded bg-error/10 text-error`,children:p}),(0,G.jsxs)(M,{children:[(0,G.jsx)(m,{size:`sm`,variant:`outline`,className:`text-xs cursor-pointer`,onClick:()=>t(!1),children:`Cancel`}),(0,G.jsxs)(m,{size:`sm`,className:`text-xs cursor-pointer gap-1.5`,onClick:l,disabled:!i.trim()||c,children:[c?(0,G.jsx)(s,{className:`size-3.5 animate-spin`}):(0,G.jsx)(o,{className:`size-3.5`}),`Add key`]})]})]})})}function Ie({mode:e,onOpenChange:t,password:n,onPasswordChange:r,busy:a,onExport:o,onImport:c,error:l}){let u=(0,W.useRef)(null),d=e===`export`;return(0,G.jsx)(S,{open:e!==null,onOpenChange:t,children:(0,G.jsxs)(j,{className:`sm:max-w-md`,children:[(0,G.jsxs)(w,{children:[(0,G.jsxs)(g,{className:`text-sm flex items-center gap-1.5`,children:[(0,G.jsx)(N,{className:`size-4`}),` `,d?`Export Codex Accounts`:`Import Codex Accounts`]}),(0,G.jsx)(k,{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,G.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,G.jsx)(b,{htmlFor:`codex-backup-password`,className:`text-xs`,children:`Password`}),(0,G.jsx)(A,{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,G.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:`A backup holds full logins — keep the file and its password together.`})]}),l&&(0,G.jsx)(`div`,{className:`text-[11px] p-2 rounded bg-error/10 text-error`,children:l}),(0,G.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,G.jsxs)(M,{children:[(0,G.jsx)(m,{size:`sm`,variant:`outline`,className:`text-xs cursor-pointer`,onClick:()=>t(!1),children:`Cancel`}),(0,G.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,G.jsx)(s,{className:`size-3.5 animate-spin`}):d?(0,G.jsx)(i,{className:`size-3.5`}):(0,G.jsx)(I,{className:`size-3.5`}),d?`Download backup`:`Choose file`]})]})]})})}var Le=[{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 Re({open:e,onOpenChange:t,strategy:n,onChange:r}){return(0,G.jsx)(S,{open:e,onOpenChange:t,children:(0,G.jsxs)(j,{className:`sm:max-w-md`,children:[(0,G.jsxs)(w,{children:[(0,G.jsx)(g,{className:`text-sm`,children:`Codex Rotation`}),(0,G.jsx)(k,{className:`text-xs leading-relaxed`,children:`How a new chat chooses among your Codex accounts.`})]}),(0,G.jsx)(`div`,{className:`space-y-2`,children:Le.map(e=>(0,G.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,G.jsx)(`p`,{className:`text-sm font-medium`,children:e.label}),(0,G.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e.hint})]},e.value))}),(0,G.jsx)(M,{children:(0,G.jsx)(m,{size:`sm`,variant:`outline`,className:`text-xs cursor-pointer`,onClick:()=>t(!1),children:`Done`})})]})})}var ze=2e3,Be=21e4;function Ve(e){let[t,n]=(0,W.useState)([]),[r,i]=(0,W.useState)(`round-robin`),[a,o]=(0,W.useState)({}),[s,c]=(0,W.useState)(!1),[d,f]=(0,W.useState)(``),[p,m]=(0,W.useState)(``),[h,g]=(0,W.useState)(!1),[_,v]=(0,W.useState)(null),[y,b]=(0,W.useState)(null),[x,S]=(0,W.useState)(!1),[C,w]=(0,W.useState)(``),[T,E]=(0,W.useState)(!1),[D,O]=(0,W.useState)(!1),[k,A]=(0,W.useState)(null),j=(0,W.useRef)(null),M=(0,W.useRef)(null),N=(0,W.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,W.useEffect)(()=>{N()},[N]);let P=async()=>{if(d.trim()){g(!0),v(null);try{await l.post(`/api/codex-accounts/api-key`,{apiKey:d.trim(),label:p.trim()||void 0}),f(``),m(``),e(),await N()}catch(e){v(e.message)}finally{g(!1)}}},F=(0,W.useCallback)(t=>{let n=Date.now()+Be,r=!1;j.current=()=>{r=!0};let i=e=>{r=!0,j.current=null,M.current=null,e&&v(e),b(null),S(!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(),m(``),e(),await N();return}if(o?.state===`error`){i(o.error);return}if(Date.now()>n){i(`Device login timed out.`);return}setTimeout(a,ze)}};a()},[N]);return(0,W.useEffect)(()=>()=>{j.current?.();let e=M.current;e&&l.del(`/api/codex-accounts/device-login/${e}`).catch(()=>{})},[]),{accounts:t,strategy:r,usages:a,loading:s,apiKey:d,setApiKey:f,label:p,setLabel:m,adding:h,err:_,setErr:v,device:y,deviceWaiting:x,backupPassword:C,setBackupPassword:w,exporting:T,importing:D,msg:k,setMsg:A,load:N,addApiKey:P,startDevice:async()=>{v(null);try{let e=await l.post(`/api/codex-accounts/device-login`,{label:p.trim()||void 0});b(e),S(!0),M.current=e.id,F(e.id)}catch(e){v(e.message)}},remove:async e=>{await l.del(`/api/codex-accounts/${e}`),await N()},changeStrategy:async e=>{i(e);try{await l.put(`/api/codex-accounts/strategy`,{strategy:e})}catch{}},doExport:async()=>{if(!C.trim()){v(`Set a backup password first.`);return}E(!0),v(null),A(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:C})});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),A(`Backup downloaded.`),e()}catch(e){v(e.message)}finally{E(!1)}},doImport:async t=>{if(!C.trim()){v(`Enter the backup password first.`);return}O(!0),v(null),A(null);try{let n=await t.text(),r=await l.post(`/api/codex-accounts/import`,{data:n,password:C});A(`Imported ${r.imported}${r.skipped?`, skipped ${r.skipped}`:``}.`),e(),await N()}catch(e){v(e.message)}finally{O(!1)}}}}function $(e){return e==null?null:Math.round(e*100)}function He(){let[e,t]=(0,W.useState)(null),n=Ve(()=>t(null));return(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsx)(z,{description:(0,G.jsxs)(G.Fragment,{children:[`Each Codex account keeps its own login (`,(0,G.jsx)(`code`,{children:`CODEX_HOME`}),`). One is picked per chat by the rotation setting.`]}),onRefresh:()=>void n.load(),refreshing:n.loading,actions:(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(m,{size:`sm`,className:`cursor-pointer gap-1.5`,onClick:()=>t(`add`),children:[(0,G.jsx)(x,{className:`size-4`}),` Add account`]}),(0,G.jsxs)(m,{size:`sm`,variant:`outline`,className:`cursor-pointer gap-1.5`,onClick:()=>t(`export`),children:[(0,G.jsx)(i,{className:`size-4`}),` Export`]}),(0,G.jsxs)(m,{size:`sm`,variant:`outline`,className:`cursor-pointer gap-1.5`,onClick:()=>t(`import`),children:[(0,G.jsx)(I,{className:`size-4`}),` Import`]}),(0,G.jsxs)(m,{size:`sm`,variant:`outline`,className:`cursor-pointer gap-1.5`,onClick:()=>t(`rotation`),children:[(0,G.jsx)(D,{className:`size-4`}),` Rotation`]})]})}),(0,G.jsx)(H,{message:n.msg??n.err,onDismiss:()=>{n.setMsg(null),n.setErr(null)}}),(0,G.jsxs)(`section`,{className:`space-y-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`h3`,{className:`text-sm font-medium`,children:`Codex Accounts`}),(0,G.jsx)(`span`,{className:`text-[10px] text-muted-foreground capitalize`,children:n.strategy.replace(`-`,` `)})]}),n.loading&&n.accounts.length===0?(0,G.jsxs)(`div`,{className:`flex items-center gap-2 py-6 text-xs text-muted-foreground`,children:[(0,G.jsx)(s,{className:`size-4 animate-spin`}),` Loading accounts...`]}):n.accounts.length===0?(0,G.jsxs)(`div`,{className:`flex flex-col items-center gap-2 py-8 text-center`,children:[(0,G.jsx)(o,{className:`size-5 text-muted-foreground`}),(0,G.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`No Codex accounts yet.`}),(0,G.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Chats use your default `,(0,G.jsx)(`code`,{children:`~/.codex`}),` login until you add one.`]})]}):(0,G.jsx)(U,{children:n.accounts.map(e=>{let t=n.usages[e.id]??{};return(0,G.jsxs)(V,{dense:!0,className:`min-w-[300px] shrink-0 snap-start`,"data-testid":`account-card`,"data-account-id":e.id,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-sm font-medium truncate flex-1 min-w-0`,children:e.label}),(0,G.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,G.jsx)(`span`,{className:`text-[10px] text-text-subtle shrink-0`,children:e.planType}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>void n.remove(e.id),title:`Remove account`,"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,G.jsx)(C,{className:`size-4`})})]}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(B,{label:`5-Hour Session`,pct:$(t.fiveHour)}),(0,G.jsx)(B,{label:`Weekly`,pct:$(t.sevenDay)})]})]},e.id)})})]}),(0,G.jsx)(Q,{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,G.jsx)(Ie,{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,G.jsx)(Re,{open:e===`rotation`,onOpenChange:e=>t(e?`rotation`:null),strategy:n.strategy,onChange:e=>void n.changeStrategy(e)})]})}var Ue=[{id:`claude`,label:`Claude`},{id:`codex`,label:`Codex`}];function We(){let[e,t]=(0,W.useState)(null),[n,r]=(0,W.useState)(`claude`);(0,W.useEffect)(()=>{let e=!1;return ie().then(n=>{e||t(new Set(Object.keys(n.providers??{})))}).catch(()=>{e||t(new Set([`claude`]))}),()=>{e=!0}},[]);let i=Ue.filter(t=>t.id===`claude`||e?.has(t.id)),a=i.length>1;return(0,G.jsxs)(`div`,{className:`space-y-4`,"data-testid":`accounts-pane`,"data-provider":n,children:[a&&(0,G.jsx)(`div`,{className:`flex gap-1 border-b border-border/50`,children:i.map(e=>(0,G.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,G.jsx)(F,{providerId:e.id}),e.label]},e.id))}),e===null&&!a&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-muted-foreground`,children:[(0,G.jsx)(s,{className:`size-3 animate-spin`}),` Checking configured providers...`]}),n===`claude`?(0,G.jsx)(Fe,{}):(0,G.jsx)(He,{})]})}export{We as AccountsSettingsSection};
|
|
@@ -1,3 +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"./flask-conical-tp8gyZGh.js";import{t as a}from"./loader-circle-DPMrnLQ2.js";import"./api-client-oY1tC3tM.js";import"./portal-container-context-a399Hd9F.js";import{t as o}from"./button-BZtEJcUv.js";import{$t as s,J as c,Jt as l,Kn as u,Qt as d,W as f,Xt as p,Y as m,Yn as h,Yt as g,en as _,tn as v}from"./index-B1bzKRjJ.js";import{getProxySettings as y,updateProxySettings as b}from"./api-settings-CTMdz_VF.js";var x=e(t(),1),S=[{value:`claude-opus-5`,label:`Claude Opus 5`,hint:`most powerful`},{value:`claude-fable-5-1`,label:`Claude Fable 5.1`,hint:`flagship`},{value:`claude-fable-5`,label:`Claude Fable 5`,hint:`flagship`},{value:`claude-opus-4-8`,label:`Claude Opus 4.8`,hint:`powerful`},{value:`claude-opus-4-7`,label:`Claude Opus 4.7`,hint:`powerful`},{value:`claude-opus-4-6`,label:`Claude Opus 4.6`,hint:`powerful`},{value:`claude-sonnet-5`,label:`Claude Sonnet 5`,hint:`fast`},{value:`claude-sonnet-4-6`,label:`Claude Sonnet 4.6`,hint:`fast`},{value:`claude-haiku-4-5`,label:`Claude Haiku 4.5`,hint:`cheap`}];S.map(e=>e.value);var C=n(),w=`Hello! Reply briefly.`,T=`claude-opus-5`;function E(e){let[t,n]=(0,x.useState)(!1);return(0,C.jsxs)(l,{open:t,onOpenChange:n,children:[(0,C.jsx)(_,{asChild:!0,children:(0,C.jsxs)(o,{variant:`outline`,size:`sm`,className:`h-7 text-[11px] gap-1.5 cursor-pointer`,children:[(0,C.jsx)(i,{className:`size-3`}),`Test`]})}),(0,C.jsxs)(g,{className:`sm:max-w-md max-h-[85vh] overflow-y-auto`,children:[(0,C.jsxs)(d,{children:[(0,C.jsx)(s,{className:`text-sm`,children:`Test Proxy`}),(0,C.jsx)(p,{className:`text-[11px]`,children:`Send a test request and inspect the raw response.`})]}),t&&(0,C.jsx)(D,{...e})]})]})}function D({authKey:e,baseUrl:t}){let[n,r]=(0,x.useState)(`anthropic`),[i,s]=(0,x.useState)(w),[l,u]=(0,x.useState)(T),[d,f]=(0,x.useState)(!0),[p,g]=(0,x.useState)(!1),[_,v]=(0,x.useState)(null),[y,b]=(0,x.useState)(null),[E,D]=(0,x.useState)(null),O=(0,x.useRef)(null),k=(0,x.useRef)(null);(0,x.useEffect)(()=>{O.current?.select()},[]),(0,x.useEffect)(()=>{k.current&&(k.current.scrollTop=k.current.scrollHeight)},[_]);let A=e=>{r(e),v(null),b(null),D(null)},j=async()=>{g(!0),v(null),b(null),D(null);let r=Date.now(),a=n===`openai`,o=a?`${t}/proxy/v1/chat/completions`:`${t}/proxy/v1/messages`,s=JSON.stringify({model:l,max_tokens:256,stream:d,messages:[{role:`user`,content:i}]}),c={"Content-Type":`application/json`};a?c.Authorization=`Bearer ${e}`:(c[`x-api-key`]=e,c[`anthropic-version`]=`2023-06-01`);try{let e=await fetch(o,{method:`POST`,headers:c,body:s});if(!e.ok){let t=await e.text();b(`HTTP ${e.status}: ${t}`),g(!1),D(Date.now()-r);return}if(d){let t=e.body?.getReader();if(!t){b(`No response body`),g(!1);return}let n=new TextDecoder,i=``;for(;;){let{done:e,value:r}=await t.read();if(e)break;i+=n.decode(r,{stream:!0}),v(i)}D(Date.now()-r)}else{let t=await e.text();try{v(JSON.stringify(JSON.parse(t),null,2))}catch{v(t)}D(Date.now()-r)}}catch(e){b(e.message)}finally{g(!1),D(e=>e??Date.now()-r)}};return(0,C.jsxs)(`div`,{className:`space-y-3 min-w-0`,children:[(0,C.jsxs)(`div`,{className:`space-y-1.5 min-w-0`,children:[(0,C.jsx)(c,{className:`text-[11px]`,children:`Auth Style`}),(0,C.jsx)(`div`,{className:`flex gap-1`,children:[`anthropic`,`openai`].map(e=>(0,C.jsx)(`button`,{onClick:()=>A(e),className:`flex-1 h-8 rounded-md text-[11px] font-medium border transition-colors cursor-pointer ${n===e?`bg-primary text-primary-foreground border-primary`:`bg-muted text-muted-foreground border-transparent hover:bg-muted/80`}`,children:e===`anthropic`?`Anthropic`:`OpenAI`},e))}),(0,C.jsx)(`p`,{className:`text-[9px] text-muted-foreground`,children:n===`anthropic`?`x-api-key header`:`Authorization: Bearer header`})]}),(0,C.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,C.jsx)(c,{className:`text-[11px]`,children:`Model`}),(0,C.jsx)(`select`,{value:l,onChange:e=>u(e.target.value),className:`h-8 w-full rounded-md border bg-background px-2 text-[11px]`,children:S.map(e=>(0,C.jsx)(`option`,{value:e.value,children:e.value},e.value))})]}),(0,C.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,C.jsx)(c,{className:`text-[11px]`,children:`Streaming`}),(0,C.jsx)(`div`,{className:`flex gap-1`,children:[!0,!1].map(e=>(0,C.jsx)(`button`,{onClick:()=>f(e),className:`h-7 px-3 rounded-md text-[11px] font-medium border transition-colors cursor-pointer ${d===e?`bg-primary text-primary-foreground border-primary`:`bg-muted text-muted-foreground border-transparent hover:bg-muted/80`}`,children:e?`Stream`:`JSON`},String(e)))})]}),(0,C.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,C.jsx)(c,{className:`text-[11px]`,children:`Message`}),(0,C.jsxs)(`div`,{className:`flex gap-1.5`,children:[(0,C.jsx)(m,{ref:O,value:i,onChange:e=>s(e.target.value),placeholder:`Type a test message...`,className:`h-9 text-[11px] flex-1 min-w-0`,onKeyDown:e=>{e.key===`Enter`&&!p&&j()}}),(0,C.jsxs)(o,{size:`sm`,className:`h-9 px-3 cursor-pointer shrink-0`,onClick:j,disabled:p||!i.trim(),children:[p?(0,C.jsx)(a,{className:`size-3.5 animate-spin`}):(0,C.jsx)(h,{className:`size-3.5`}),(0,C.jsx)(`span`,{className:`ml-1 text-[11px]`,children:p?`...`:`Send`})]})]})]}),(_||y)&&(0,C.jsxs)(`div`,{className:`space-y-1 min-w-0`,children:[(0,C.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,C.jsx)(c,{className:`text-[10px] text-muted-foreground`,children:`Raw Response`}),E!=null&&(0,C.jsxs)(`span`,{className:`text-[9px] font-mono text-muted-foreground`,children:[(E/1e3).toFixed(1),`s`]})]}),y?(0,C.jsx)(`pre`,{className:`text-[9px] font-mono bg-error/10 text-error p-2 rounded overflow-auto max-h-52 whitespace-pre-wrap break-all`,children:y}):(0,C.jsx)(`pre`,{ref:k,className:`text-[9px] font-mono bg-muted p-2 rounded overflow-auto max-h-52 whitespace-pre-wrap break-all`,children:_})]})]})}function O(){let[e,t]=(0,x.useState)(null),[n,i]=(0,x.useState)(!0),[a,s]=(0,x.useState)(!1),[l,d]=(0,x.useState)(null),[p,h]=(0,x.useState)(null);(0,x.useEffect)(()=>{i(!0),y().then(t).catch(e=>d(e.message)).finally(()=>i(!1))},[]);let g=async e=>{s(!0),d(null);try{t(await b(e))}catch(e){d(e.message)}finally{s(!1)}},_=(e,t)=>{v(e),h(t),setTimeout(()=>h(null),2e3)};if(n||!e)return(0,C.jsxs)(`div`,{className:`space-y-2`,children:[(0,C.jsx)(`h3`,{className:`text-xs font-medium text-text-secondary`,children:`API Proxy`}),(0,C.jsx)(`p`,{className:`text-[11px] text-text-subtle`,children:l?`Error: ${l}`:`Loading...`})]});let S=!!e.authKey,w=!!e.tunnelUrl,T=e.localEndpoint,D=T.replace(/\/proxy\/v1\/messages$/,``);return(0,C.jsxs)(`div`,{className:`space-y-4`,children:[(0,C.jsx)(`div`,{className:`space-y-1.5`,children:(0,C.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:`Expose your Claude accounts as an Anthropic-compatible API endpoint. External tools (OpenCode, Cursor, etc.) can use your accounts via this proxy.`})}),(0,C.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,C.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,C.jsx)(c,{className:`text-xs`,children:`Enable Proxy`}),(0,C.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:`Accept API requests on /proxy/v1/messages`})]}),(0,C.jsx)(f,{checked:e.enabled,onCheckedChange:e=>g({enabled:e}),disabled:a})]}),(0,C.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,C.jsx)(c,{className:`text-[11px]`,children:`Auth Key`}),S?(0,C.jsxs)(`div`,{className:`flex gap-1.5`,children:[(0,C.jsx)(m,{readOnly:!0,value:e.authKey,className:`h-7 text-[11px] font-mono flex-1`}),(0,C.jsx)(o,{variant:`outline`,size:`sm`,className:`h-7 px-2 cursor-pointer shrink-0`,onClick:()=>_(e.authKey,`key`),children:p===`key`?`Copied!`:(0,C.jsx)(r,{className:`size-3`})}),(0,C.jsx)(o,{variant:`outline`,size:`sm`,className:`h-7 px-2 cursor-pointer shrink-0`,onClick:()=>g({generateKey:!0}),disabled:a,children:(0,C.jsx)(u,{className:`size-3`})})]}):(0,C.jsx)(o,{variant:`outline`,size:`sm`,className:`h-7 text-xs cursor-pointer`,onClick:()=>g({generateKey:!0}),disabled:a,children:`Generate Auth Key`}),(0,C.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:`Use as Bearer token or x-api-key when calling the proxy.`})]}),e.enabled&&S&&(0,C.jsxs)(`div`,{className:`space-y-2 rounded-md border p-3 bg-muted/30`,children:[(0,C.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,C.jsx)(`h4`,{className:`text-[11px] font-medium`,children:`Connection Info`}),(0,C.jsx)(E,{authKey:e.authKey,baseUrl:window.location.origin})]}),(0,C.jsxs)(`div`,{className:`space-y-1`,children:[(0,C.jsx)(c,{className:`text-[10px] text-muted-foreground`,children:`Anthropic Endpoint`}),(0,C.jsxs)(`div`,{className:`flex gap-1.5 items-center`,children:[(0,C.jsx)(`code`,{className:`text-[10px] font-mono bg-muted px-1.5 py-0.5 rounded flex-1 truncate`,children:w?e.proxyEndpoint:T}),(0,C.jsx)(o,{variant:`ghost`,size:`sm`,className:`h-6 px-1.5 cursor-pointer shrink-0`,onClick:()=>_(w?e.proxyEndpoint:T,`anthropic`),children:p===`anthropic`?`Copied!`:(0,C.jsx)(r,{className:`size-3`})})]})]}),(0,C.jsxs)(`div`,{className:`space-y-1`,children:[(0,C.jsx)(c,{className:`text-[10px] text-muted-foreground`,children:`OpenAI-Compatible Endpoint`}),(0,C.jsxs)(`div`,{className:`flex gap-1.5 items-center`,children:[(0,C.jsx)(`code`,{className:`text-[10px] font-mono bg-muted px-1.5 py-0.5 rounded flex-1 truncate`,children:w?e.openAiEndpoint:e.localOpenAiEndpoint}),(0,C.jsx)(o,{variant:`ghost`,size:`sm`,className:`h-6 px-1.5 cursor-pointer shrink-0`,onClick:()=>_(w?e.openAiEndpoint:e.localOpenAiEndpoint,`openai`),children:p===`openai`?`Copied!`:(0,C.jsx)(r,{className:`size-3`})})]})]}),!w&&(0,C.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:`Start a Cloudflare tunnel (Share) to get a public URL.`}),(0,C.jsxs)(`div`,{className:`space-y-1 pt-1`,children:[(0,C.jsx)(c,{className:`text-[10px] text-muted-foreground`,children:`Anthropic Format`}),(0,C.jsxs)(`div`,{className:`relative`,children:[(0,C.jsx)(`pre`,{className:`text-[9px] font-mono bg-muted p-2 rounded overflow-x-auto whitespace-pre`,children:`ANTHROPIC_BASE_URL=${w?e.tunnelUrl+`/proxy`:D+`/proxy`}
|
|
2
|
-
ANTHROPIC_API_KEY=${e.authKey}`}),(0,C.jsx)(o,{variant:`ghost`,size:`sm`,className:`absolute top-1 right-1 h-5 px-1 cursor-pointer`,onClick:()=>_(`ANTHROPIC_BASE_URL=${w?e.tunnelUrl+`/proxy`:D+`/proxy`}\nANTHROPIC_API_KEY=${e.authKey}`,`anthropic-env`),children:p===`anthropic-env`?`Copied!`:(0,C.jsx)(r,{className:`size-2.5`})})]})]}),(0,C.jsxs)(`div`,{className:`space-y-1`,children:[(0,C.jsx)(c,{className:`text-[10px] text-muted-foreground`,children:`OpenAI Format`}),(0,C.jsxs)(`div`,{className:`relative`,children:[(0,C.jsx)(`pre`,{className:`text-[9px] font-mono bg-muted p-2 rounded overflow-x-auto whitespace-pre`,children:`OPENAI_BASE_URL=${w?e.tunnelUrl+`/proxy/v1`:D+`/proxy/v1`}
|
|
3
|
-
OPENAI_API_KEY=${e.authKey}`}),(0,C.jsx)(o,{variant:`ghost`,size:`sm`,className:`absolute top-1 right-1 h-5 px-1 cursor-pointer`,onClick:()=>_(`OPENAI_BASE_URL=${w?e.tunnelUrl+`/proxy/v1`:D+`/proxy/v1`}\nOPENAI_API_KEY=${e.authKey}`,`openai-env`),children:p===`openai-env`?`Copied!`:(0,C.jsx)(r,{className:`size-2.5`})})]})]}),(0,C.jsx)(`div`,{className:`flex items-center gap-3 pt-1`,children:(0,C.jsxs)(`span`,{className:`text-[10px] text-muted-foreground`,children:[`Requests served: `,(0,C.jsx)(`span`,{className:`font-mono`,children:e.requestCount})]})})]}),a&&(0,C.jsx)(`p`,{className:`text-[11px] text-text-subtle`,children:`Saving...`}),l&&(0,C.jsx)(`p`,{className:`text-[11px] text-error`,children:l})]})}export{O as ProxySettingsSection};
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|