icebear commited on
Commit
38e103b
·
unverified ·
2 Parent(s): c3eb32a50ae780

Merge pull request #7 from icebear0828/refactor/cleanup-dead-code

Browse files

refactor: remove dead code, unused config, and fix type violations

.gitignore CHANGED
@@ -1,8 +1,7 @@
1
  node_modules/
2
  dist/
3
  data/
4
- public/assets/
5
- public/index.html
6
  docs/
7
  bin/
8
  .env
 
1
  node_modules/
2
  dist/
3
  data/
4
+ public/
 
5
  docs/
6
  bin/
7
  .env
config/default.yaml CHANGED
@@ -30,10 +30,6 @@ server:
30
  port: 8080
31
  proxy_api_key: "pwd"
32
 
33
- environment:
34
- default_id: null
35
- default_branch: "main"
36
-
37
  session:
38
  ttl_minutes: 60
39
  cleanup_interval_minutes: 5
@@ -49,11 +45,3 @@ tls:
49
  # HTTP/SOCKS5 proxy for curl requests to chatgpt.com
50
  # Example: "http://127.0.0.1:7890" Also respects HTTPS_PROXY env var
51
  proxy_url: null
52
-
53
- streaming:
54
- status_as_content: false
55
- chunk_size: 100
56
- chunk_delay_ms: 10
57
- heartbeat_interval_s: 15
58
- poll_interval_s: 2
59
- timeout_s: 300
 
30
  port: 8080
31
  proxy_api_key: "pwd"
32
 
 
 
 
 
33
  session:
34
  ttl_minutes: 60
35
  cleanup_interval_minutes: 5
 
45
  # HTTP/SOCKS5 proxy for curl requests to chatgpt.com
46
  # Example: "http://127.0.0.1:7890" Also respects HTTPS_PROXY env var
47
  proxy_url: null
 
 
 
 
 
 
 
 
public/dashboard.html DELETED
@@ -1,889 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en"><head>
3
- <meta charset="utf-8"/>
4
- <meta content="width=device-width, initial-scale=1.0" name="viewport"/>
5
- <title>Codex Proxy Developer Dashboard</title>
6
- <script src="https://cdn.tailwindcss.com?plugins=forms,container-queries"></script>
7
- <script>
8
- tailwind.config = {
9
- darkMode: "class",
10
- theme: {
11
- extend: {
12
- colors: {
13
- "primary": "rgb(var(--primary) / <alpha-value>)",
14
- "primary-hover": "rgb(var(--primary-hover) / <alpha-value>)",
15
- "bg-light": "#f6f8f6",
16
- "bg-dark": "#0d1117",
17
- "card-dark": "#161b22",
18
- "border-dark": "#30363d",
19
- "text-main": "#e6edf3",
20
- "text-dim": "#8b949e",
21
- },
22
- fontFamily: {
23
- "display": ["system-ui", "-apple-system", "BlinkMacSystemFont", "Segoe UI", "Roboto", "sans-serif"],
24
- "mono": ["ui-monospace", "SFMono-Regular", "SF Mono", "Menlo", "Consolas", "Liberation Mono", "monospace"],
25
- },
26
- borderRadius: {"DEFAULT": "0.25rem", "lg": "0.5rem", "xl": "0.75rem", "full": "9999px"},
27
- },
28
- },
29
- }
30
- </script>
31
- <style>
32
- :root { --primary: 16 162 53; --primary-hover: 14 140 46; }
33
- .dark { --primary: 16 163 127; --primary-hover: 14 140 108; }
34
-
35
- /* Dark scrollbar for code blocks */
36
- pre::-webkit-scrollbar { height: 8px; }
37
- pre::-webkit-scrollbar-track { background: #0d1117; }
38
- pre::-webkit-scrollbar-thumb { background: #30363d; border-radius: 4px; }
39
- pre::-webkit-scrollbar-thumb:hover { background: #8b949e; }
40
- </style>
41
- <!-- Prevent flash: apply theme before render -->
42
- <script>
43
- try {
44
- const t = localStorage.getItem('codex-proxy-theme');
45
- if (t === 'dark' || (!t && window.matchMedia('(prefers-color-scheme: dark)').matches))
46
- document.documentElement.classList.add('dark');
47
- } catch {}
48
- </script>
49
- </head>
50
- <body class="bg-bg-light dark:bg-bg-dark font-display text-slate-900 dark:text-text-main antialiased min-h-screen flex flex-col transition-colors">
51
- <!-- Top Navigation -->
52
- <header class="sticky top-0 z-50 w-full bg-white dark:bg-card-dark border-b border-gray-200 dark:border-border-dark shadow-sm transition-colors">
53
- <div class="px-4 md:px-8 lg:px-40 flex h-14 items-center justify-center">
54
- <div class="flex w-full max-w-[960px] items-center justify-between">
55
- <!-- Logo & Title -->
56
- <div class="flex items-center gap-3">
57
- <div class="flex items-center justify-center size-8 rounded-full bg-primary/10 text-primary border border-primary/20">
58
- <svg class="size-5" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M9 12.75L11.25 15 15 9.75M21 12a9 9 0 11-18 0 9 9 0 0118 0z"/></svg>
59
- </div>
60
- <h1 class="text-[0.9rem] font-bold tracking-tight">Codex Proxy</h1>
61
- </div>
62
- <!-- Actions -->
63
- <div class="flex items-center gap-3">
64
- <div class="hidden sm:flex items-center gap-2 px-3 py-1.5 rounded-full bg-primary/10 border border-primary/20" id="serverBadge">
65
- <span class="relative flex h-2.5 w-2.5">
66
- <span class="animate-ping absolute inline-flex h-full w-full rounded-full bg-primary opacity-75"></span>
67
- <span class="relative inline-flex rounded-full h-2.5 w-2.5 bg-primary"></span>
68
- </span>
69
- <span class="text-xs font-semibold text-primary" data-i18n="serverOnline">Server Online</span>
70
- </div>
71
- <!-- Language Toggle -->
72
- <button id="langToggle" onclick="toggleLang()" class="p-2 rounded-lg text-slate-500 dark:text-text-dim hover:bg-slate-100 dark:hover:bg-border-dark transition-colors" title="中/EN">
73
- <span class="text-xs font-bold">EN</span>
74
- </button>
75
- <!-- Theme Toggle -->
76
- <button id="themeToggle" onclick="toggleTheme()" class="p-2 rounded-lg text-slate-500 dark:text-text-dim hover:bg-slate-100 dark:hover:bg-border-dark transition-colors" data-i18n-title="toggleTheme" title="Toggle theme">
77
- <span id="themeIcon"><svg class="size-5" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5"><path stroke-linecap="round" stroke-linejoin="round" d="M21.752 15.002A9.72 9.72 0 0118 15.75c-5.385 0-9.75-4.365-9.75-9.75 0-1.33.266-2.597.748-3.752A9.753 9.753 0 003 11.25C3 16.635 7.365 21 12.75 21a9.753 9.753 0 009.002-5.998z"/></svg></span>
78
- </button>
79
- <button id="addAccountBtn" onclick="startAddAccount()" class="flex items-center gap-2 px-4 py-2 bg-primary hover:bg-primary-hover text-white text-xs font-semibold rounded-lg transition-colors shadow-sm active:scale-95">
80
- <svg class="size-3.5" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5"><path stroke-linecap="round" stroke-linejoin="round" d="M12 4.5v15m7.5-7.5h-15"/></svg>
81
- <span data-i18n="addAccount">Add Account</span>
82
- </button>
83
- </div>
84
- </div>
85
- </div>
86
- </header>
87
- <!-- Main Content -->
88
- <main class="flex-grow px-4 md:px-8 lg:px-40 py-8 flex justify-center">
89
- <div class="flex flex-col w-full max-w-[960px] gap-6">
90
-
91
- <!-- Add Account Section (hidden by default) -->
92
- <section id="addSection" class="hidden bg-white dark:bg-card-dark border border-gray-200 dark:border-border-dark rounded-xl p-5 shadow-sm transition-colors">
93
- <ol class="text-sm text-slate-500 dark:text-text-dim mb-4 space-y-1.5 list-decimal list-inside">
94
- <li data-i18n-html="addStep1">Complete the login in the popup window (if blocked, right-click "Add Account" and open the link in a new tab).</li>
95
- <li data-i18n-html="addStep2">After login, the browser will redirect to a <code class="text-xs bg-slate-100 dark:bg-bg-dark px-1.5 py-0.5 rounded">localhost:1455/auth/callback?...</code> page (it may show "unable to connect" — that's normal).</li>
96
- <li data-i18n-html="addStep3">Copy the <strong class="text-slate-700 dark:text-text-main">full URL</strong> from the address bar and paste it below.</li>
97
- </ol>
98
- <div class="flex gap-3">
99
- <input id="addCallbackInput" type="text" data-i18n-placeholder="pasteCallback" placeholder="Paste callback URL here" class="flex-1 px-3 py-2.5 bg-slate-50 dark:bg-bg-dark border border-gray-200 dark:border-border-dark rounded-lg text-sm font-mono text-slate-600 dark:text-text-main focus:ring-2 focus:ring-primary/50 focus:border-primary outline-none transition-colors"/>
100
- <button id="addRelayBtn" onclick="submitAddRelay()" class="px-4 py-2.5 bg-white dark:bg-card-dark border border-gray-200 dark:border-border-dark rounded-lg text-sm font-medium text-slate-700 dark:text-text-main hover:bg-slate-50 dark:hover:bg-border-dark transition-colors" data-i18n="submit">Submit</button>
101
- </div>
102
- <p id="addInfo" class="text-sm text-primary mt-2 hidden"></p>
103
- <p id="addError" class="text-sm text-red-500 mt-2 hidden"></p>
104
- </section>
105
-
106
- <!-- Section 1: Connected Accounts -->
107
- <section class="flex flex-col gap-4">
108
- <div class="flex items-end justify-between">
109
- <div class="flex flex-col gap-1">
110
- <h2 class="text-[0.95rem] font-bold tracking-tight" data-i18n="connectedAccounts">Connected Accounts</h2>
111
- <p class="text-slate-500 dark:text-text-dim text-[0.8rem]" data-i18n="connectedAccountsDesc">Manage your AI model proxy services and usage limits.</p>
112
- </div>
113
- </div>
114
- <div id="accountList" class="grid grid-cols-1 md:grid-cols-2 gap-4">
115
- <div class="md:col-span-2 text-center py-8 text-slate-400 dark:text-text-dim text-sm bg-white dark:bg-card-dark border border-gray-200 dark:border-border-dark rounded-xl transition-colors" data-i18n="loadingAccounts">Loading accounts...</div>
116
- </div>
117
- </section>
118
-
119
- <!-- Section 2: API Configuration -->
120
- <section class="bg-white dark:bg-card-dark border border-gray-200 dark:border-border-dark rounded-xl p-5 shadow-sm transition-colors">
121
- <div class="flex items-center justify-between mb-6 border-b border-slate-100 dark:border-border-dark pb-4">
122
- <div class="flex items-center gap-2">
123
- <svg class="size-5 text-primary" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5"><path stroke-linecap="round" stroke-linejoin="round" d="M9.594 3.94c.09-.542.56-.94 1.11-.94h2.593c.55 0 1.02.398 1.11.94l.213 1.281c.063.374.313.686.645.87.074.04.147.083.22.127.324.196.72.257 1.075.124l1.217-.456a1.125 1.125 0 011.37.49l1.296 2.247a1.125 1.125 0 01-.26 1.431l-1.003.827c-.293.241-.438.613-.43.992a7.723 7.723 0 010 .255c-.008.378.137.75.43.991l1.004.827c.424.35.534.955.26 1.43l-1.298 2.247a1.125 1.125 0 01-1.369.491l-1.217-.456c-.355-.133-.75-.072-1.076.124a6.47 6.47 0 01-.22.128c-.331.183-.581.495-.644.869l-.213 1.281c-.09.543-.56.94-1.11.94h-2.594c-.55 0-1.019-.398-1.11-.94l-.213-1.281c-.062-.374-.312-.686-.644-.87a6.52 6.52 0 01-.22-.127c-.325-.196-.72-.257-1.076-.124l-1.217.456a1.125 1.125 0 01-1.369-.49l-1.297-2.247a1.125 1.125 0 01.26-1.431l1.004-.827c.292-.24.437-.613.43-.991a6.932 6.932 0 010-.255c.007-.38-.138-.751-.43-.992l-1.004-.827a1.125 1.125 0 01-.26-1.43l1.297-2.247a1.125 1.125 0 011.37-.491l1.216.456c.356.133.751.072 1.076-.124.072-.044.146-.086.22-.128.332-.183.582-.495.644-.869l.214-1.28z"/><path stroke-linecap="round" stroke-linejoin="round" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"/></svg>
124
- <h2 class="text-[0.95rem] font-bold" data-i18n="apiConfig">API Configuration</h2>
125
- </div>
126
- </div>
127
- <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
128
- <!-- Base URL -->
129
- <div class="space-y-1.5">
130
- <label class="text-xs font-semibold text-slate-700 dark:text-text-main" data-i18n="baseProxyUrl">Base Proxy URL</label>
131
- <div class="relative flex items-center">
132
- <input id="baseUrl" class="w-full pl-3 pr-10 py-2.5 bg-slate-100 dark:bg-bg-dark border border-gray-200 dark:border-border-dark rounded-lg text-[0.78rem] font-mono text-slate-500 dark:text-text-dim outline-none cursor-default select-all" type="text" value="Loading..." readonly/>
133
- <button onclick="copyField('baseUrl', this)" class="absolute right-2 p-1.5 text-slate-400 dark:text-text-dim hover:text-primary transition-colors rounded-md hover:bg-slate-100 dark:hover:bg-border-dark" data-i18n-title="copyUrl" title="Copy URL">
134
- <svg class="size-[18px]" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5"><rect x="9" y="9" width="13" height="13" rx="2"/><path d="M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1"/></svg>
135
- </button>
136
- </div>
137
- </div>
138
- <!-- Default Model -->
139
- <div class="space-y-1.5">
140
- <label class="text-xs font-semibold text-slate-700 dark:text-text-main" data-i18n="defaultModel">Default Model</label>
141
- <div class="relative">
142
- <select id="defaultModel" class="w-full appearance-none pl-3 pr-10 py-2.5 bg-white dark:bg-bg-dark border border-gray-200 dark:border-border-dark rounded-lg text-[0.78rem] text-slate-700 dark:text-text-main font-medium focus:ring-1 focus:ring-primary focus:border-primary outline-none cursor-pointer transition-colors">
143
- <option value="codex">codex</option>
144
- </select>
145
- <div class="pointer-events-none absolute inset-y-0 right-0 flex items-center px-2 text-slate-500 dark:text-text-dim">
146
- <svg class="size-[18px]" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M19.5 8.25l-7.5 7.5-7.5-7.5"/></svg>
147
- </div>
148
- </div>
149
- </div>
150
- <!-- API Key -->
151
- <div class="space-y-1.5 md:col-span-2">
152
- <label class="text-xs font-semibold text-slate-700 dark:text-text-main" data-i18n="yourApiKey">Your API Key</label>
153
- <div class="relative flex items-center">
154
- <div class="absolute left-3 text-slate-400 dark:text-text-dim">
155
- <svg class="size-[18px]" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5"><path stroke-linecap="round" stroke-linejoin="round" d="M15.75 5.25a3 3 0 013 3m3 0a6 6 0 01-7.029 5.912c-.563-.097-1.159.026-1.563.43L10.5 17.25H8.25v2.25H6v2.25H2.25v-2.818c0-.597.237-1.17.659-1.591l6.499-6.499c.404-.404.527-1 .43-1.563A6 6 0 1121.75 8.25z"/></svg>
156
- </div>
157
- <input id="apiKey" class="w-full pl-10 pr-10 py-2.5 bg-slate-100 dark:bg-bg-dark border border-gray-200 dark:border-border-dark rounded-lg text-[0.78rem] font-mono text-slate-500 dark:text-text-dim outline-none cursor-default select-all tracking-wider" type="text" value="Loading..." readonly/>
158
- <button onclick="copyField('apiKey', this)" class="absolute right-2 p-1.5 text-slate-400 dark:text-text-dim hover:text-primary transition-colors rounded-md hover:bg-slate-100 dark:hover:bg-border-dark" data-i18n-title="copyApiKey" title="Copy API Key">
159
- <svg class="size-[18px]" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5"><rect x="9" y="9" width="13" height="13" rx="2"/><path d="M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1"/></svg>
160
- </button>
161
- </div>
162
- <p class="text-xs text-slate-400 dark:text-text-dim mt-1" data-i18n="apiKeyHint">Use this key to authenticate requests to the proxy. Do not share it.</p>
163
- </div>
164
- </div>
165
- </section>
166
-
167
- <!-- Section 3: Integration Examples -->
168
- <section class="flex flex-col gap-4">
169
- <h2 class="text-[0.95rem] font-bold" data-i18n="integrationExamples">Integration Examples</h2>
170
- <div class="bg-white dark:bg-card-dark border border-gray-200 dark:border-border-dark rounded-xl overflow-hidden shadow-sm transition-colors">
171
- <!-- Top Tabs: Providers -->
172
- <div id="protocolTabs" class="flex border-b border-gray-200 dark:border-border-dark bg-slate-50/50 dark:bg-bg-dark/30">
173
- <button onclick="switchProtocol('openai', this)" class="proto-tab px-6 py-3 text-[0.82rem] font-semibold text-primary border-b-2 border-primary bg-white dark:bg-card-dark transition-colors" data-proto="openai">OpenAI</button>
174
- <button onclick="switchProtocol('anthropic', this)" class="proto-tab px-6 py-3 text-[0.82rem] font-medium text-slate-500 dark:text-text-dim hover:text-slate-700 dark:hover:text-text-main hover:bg-slate-50 dark:hover:bg-[#21262d] border-b-2 border-transparent transition-colors" data-proto="anthropic">Anthropic</button>
175
- <button onclick="switchProtocol('gemini', this)" class="proto-tab px-6 py-3 text-[0.82rem] font-medium text-slate-500 dark:text-text-dim hover:text-slate-700 dark:hover:text-text-main hover:bg-slate-50 dark:hover:bg-[#21262d] border-b-2 border-transparent transition-colors" data-proto="gemini">Gemini</button>
176
- </div>
177
- <!-- Sub Tabs: Languages & Content -->
178
- <div class="p-5">
179
- <div class="flex items-center justify-between mb-4">
180
- <div id="langTabs" class="flex gap-2 p-1 bg-slate-100 dark:bg-bg-dark dark:border dark:border-border-dark rounded-lg">
181
- <button onclick="switchLang('python', this)" class="lang-tab px-3 py-1.5 text-xs font-semibold rounded bg-white dark:bg-[#21262d] text-slate-800 dark:text-text-main shadow-sm border border-transparent dark:border-border-dark transition-all" data-lang="python">Python</button>
182
- <button onclick="switchLang('node', this)" class="lang-tab px-3 py-1.5 text-xs font-medium rounded text-slate-500 dark:text-text-dim hover:text-slate-700 dark:hover:text-text-main hover:bg-white/50 dark:hover:bg-[#21262d] border border-transparent transition-all" data-lang="node">Node.js</button>
183
- <button onclick="switchLang('curl', this)" class="lang-tab px-3 py-1.5 text-xs font-medium rounded text-slate-500 dark:text-text-dim hover:text-slate-700 dark:hover:text-text-main hover:bg-white/50 dark:hover:bg-[#21262d] border border-transparent transition-all" data-lang="curl">cURL</button>
184
- </div>
185
- </div>
186
- <!-- Code Block -->
187
- <div id="codeContainer" class="relative group rounded-lg overflow-hidden bg-[#0d1117] text-slate-300 font-mono text-xs border border-slate-800 dark:border-border-dark">
188
- <div class="absolute right-2 top-2 z-10 opacity-0 group-hover:opacity-100 transition-opacity">
189
- <button onclick="copyCurrentCode()" class="flex items-center gap-1.5 px-3 py-1.5 bg-slate-700 hover:bg-slate-600 text-white rounded text-xs font-medium transition-colors">
190
- <svg class="size-3.5" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5"><rect x="9" y="9" width="13" height="13" rx="2"/><path d="M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1"/></svg> <span data-i18n="copy">Copy</span>
191
- </button>
192
- </div>
193
- <div class="p-4 overflow-x-auto">
194
- <pre class="m-0"><code id="codeBlock">Loading...</code></pre>
195
- </div>
196
- </div>
197
- </div>
198
- </div>
199
- </section>
200
- </div>
201
- </main>
202
- <!-- Footer -->
203
- <footer class="mt-auto border-t border-gray-200 dark:border-border-dark bg-white dark:bg-card-dark py-6 transition-colors">
204
- <div class="container mx-auto px-4 text-center">
205
- <p class="text-[0.8rem] text-slate-500 dark:text-text-dim" data-i18n="footer">&copy; 2025 Codex Proxy. All rights reserved.</p>
206
- </div>
207
- </footer>
208
-
209
- <script>
210
- // ── i18n ──────────────────────────────────────────────────────
211
- const LANG = {
212
- en: {
213
- serverOnline: "Server Online",
214
- addAccount: "Add Account",
215
- toggleTheme: "Toggle theme",
216
- connectedAccounts: "Connected Accounts",
217
- connectedAccountsDesc: "Manage your AI model proxy services and usage limits.",
218
- loadingAccounts: "Loading accounts...",
219
- noAccounts: 'No accounts connected. Click "Add Account" to get started.',
220
- deleteAccount: "Delete account",
221
- removeConfirm: "Remove this account?",
222
- accountAdded: "Account added successfully!",
223
- active: "Active",
224
- expired: "Expired",
225
- rateLimited: "Rate Limited",
226
- refreshing: "Refreshing",
227
- disabled: "Disabled",
228
- freeTier: "Free Tier",
229
- totalRequests: "Total Requests",
230
- tokensUsed: "Tokens Used",
231
- rateLimit: "Rate Limit",
232
- limitReached: "Limit Reached",
233
- used: "Used",
234
- ok: "OK",
235
- resetsAt: "Resets at",
236
- apiConfig: "API Configuration",
237
- baseProxyUrl: "Base Proxy URL",
238
- defaultModel: "Default Model",
239
- yourApiKey: "Your API Key",
240
- apiKeyHint: "Use this key to authenticate requests to the proxy. Do not share it.",
241
- copyUrl: "Copy URL",
242
- copyApiKey: "Copy API Key",
243
- integrationExamples: "Integration Examples",
244
- copy: "Copy",
245
- addStep1: 'Complete the login in the popup window (if blocked, right-click "Add Account" and open the link in a new tab).',
246
- addStep2: 'After login, the browser will redirect to a <code class="text-xs bg-slate-100 dark:bg-bg-dark px-1.5 py-0.5 rounded">localhost:1455/auth/callback?...</code> page (it may show "unable to connect" — that\'s normal).',
247
- addStep3: 'Copy the <strong class="text-slate-700 dark:text-text-main">full URL</strong> from the address bar and paste it below.',
248
- pasteCallback: "Paste callback URL here",
249
- submit: "Submit",
250
- submitting: "Submitting...",
251
- pleasePassCallback: "Please paste the callback URL",
252
- failedStartLogin: "Failed to start login",
253
- failedExchangeCode: "Failed to exchange code",
254
- failedDeleteAccount: "Failed to delete account.",
255
- networkError: "Network error: ",
256
- copied: "Copied!",
257
- copyFailed: "Failed",
258
- footer: "\u00a9 2025 Codex Proxy. All rights reserved.",
259
- },
260
- zh: {
261
- serverOnline: "\u670d\u52a1\u8fd0\u884c\u4e2d",
262
- addAccount: "\u6dfb\u52a0\u8d26\u6237",
263
- toggleTheme: "\u5207\u6362\u4e3b\u9898",
264
- connectedAccounts: "\u5df2\u8fde\u63a5\u8d26\u6237",
265
- connectedAccountsDesc: "\u7ba1\u7406\u4f60\u7684 AI \u6a21\u578b\u4ee3\u7406\u670d\u52a1\u548c\u7528\u91cf\u9650\u5236\u3002",
266
- loadingAccounts: "\u6b63\u5728\u52a0\u8f7d\u8d26\u6237...",
267
- noAccounts: "\u6682\u65e0\u5df2\u8fde\u63a5\u7684\u8d26\u6237\u3002\u70b9\u51fb\u300c\u6dfb\u52a0\u8d26\u6237\u300d\u5f00\u59cb\u4f7f\u7528\u3002",
268
- deleteAccount: "\u5220\u9664\u8d26\u6237",
269
- removeConfirm: "\u786e\u5b9a\u8981\u79fb\u9664\u6b64\u8d26\u6237\u5417\uff1f",
270
- accountAdded: "\u8d26\u6237\u6dfb\u52a0\u6210\u529f\uff01",
271
- active: "\u6d3b\u8dc3",
272
- expired: "\u5df2\u8fc7\u671f",
273
- rateLimited: "\u5df2\u9650\u901f",
274
- refreshing: "\u5237\u65b0\u4e2d",
275
- disabled: "\u5df2\u7981\u7528",
276
- freeTier: "\u514d\u8d39\u7248",
277
- totalRequests: "\u603b\u8bf7\u6c42\u6570",
278
- tokensUsed: "Token \u7528\u91cf",
279
- rateLimit: "\u901f\u7387\u9650\u5236",
280
- limitReached: "\u5df2\u8fbe\u4e0a\u9650",
281
- used: "\u5df2\u4f7f\u7528",
282
- ok: "\u6b63\u5e38",
283
- resetsAt: "\u91cd\u7f6e\u65f6\u95f4",
284
- apiConfig: "API \u914d\u7f6e",
285
- baseProxyUrl: "\u4ee3\u7406 URL",
286
- defaultModel: "\u9ed8\u8ba4\u6a21\u578b",
287
- yourApiKey: "API \u5bc6\u94a5",
288
- apiKeyHint: "\u4f7f\u7528\u6b64\u5bc6\u94a5\u5411\u4ee3\u7406\u53d1\u9001\u8ba4\u8bc1\u8bf7\u6c42\uff0c\u8bf7\u52ff\u6cc4\u9732\u3002",
289
- copyUrl: "\u590d\u5236 URL",
290
- copyApiKey: "\u590d\u5236 API \u5bc6\u94a5",
291
- integrationExamples: "\u96c6\u6210\u793a\u4f8b",
292
- copy: "\u590d\u5236",
293
- addStep1: "\u5728\u5f39\u51fa\u7684\u7a97\u53e3\u4e2d\u5b8c\u6210\u767b\u5f55\uff08\u5982\u5f39\u7a97\u88ab\u62e6\u622a\uff0c\u53f3\u952e\u300c\u6dfb\u52a0\u8d26\u6237\u300d\u6309\u94ae\u5728\u65b0\u6807\u7b7e\u9875\u6253\u5f00\u94fe\u63a5\uff09\u3002",
294
- addStep2: '\u767b\u5f55\u6210\u529f\u540e\uff0c\u6d4f\u89c8\u5668\u4f1a\u8df3\u8f6c\u5230 <code class="text-xs bg-slate-100 dark:bg-bg-dark px-1.5 py-0.5 rounded">localhost:1455/auth/callback?...</code> \u9875\u9762\uff08\u53ef\u80fd\u663e\u793a\u201c\u65e0\u6cd5\u8bbf\u95ee\u201d\u2014\u2014\u8fd9\u662f\u6b63\u5e38\u7684\uff09\u3002',
295
- addStep3: '\u590d\u5236\u5730\u5740\u680f\u4e2d\u7684<strong class="text-slate-700 dark:text-text-main">\u5b8c\u6574 URL</strong>\uff0c\u7c98\u8d34\u5230\u4e0b\u65b9\u8f93\u5165\u6846\u3002',
296
- pasteCallback: "\u7c98\u8d34\u56de\u8c03 URL",
297
- submit: "\u63d0\u4ea4",
298
- submitting: "\u63d0\u4ea4\u4e2d...",
299
- pleasePassCallback: "\u8bf7\u7c98\u8d34\u56de\u8c03 URL",
300
- failedStartLogin: "\u767b\u5f55\u542f\u52a8\u5931\u8d25",
301
- failedExchangeCode: "\u6388\u6743\u7801\u4ea4\u6362\u5931\u8d25",
302
- failedDeleteAccount: "\u5220\u9664\u8d26\u6237\u5931\u8d25\u3002",
303
- networkError: "\u7f51\u7edc\u9519\u8bef\uff1a",
304
- copied: "\u5df2\u590d\u5236\uff01",
305
- copyFailed: "\u5931\u8d25",
306
- footer: "\u00a9 2025 Codex Proxy\u3002\u4fdd\u7559\u6240\u6709\u6743\u5229\u3002",
307
- },
308
- };
309
-
310
- let currentLangCode = localStorage.getItem('codex-proxy-lang')
311
- || (navigator.language.startsWith('zh') ? 'zh' : 'en');
312
-
313
- function t(key) {
314
- return LANG[currentLangCode]?.[key] ?? LANG.en[key] ?? key;
315
- }
316
-
317
- function applyI18n() {
318
- document.querySelectorAll('[data-i18n]').forEach(el => {
319
- el.textContent = t(el.dataset.i18n);
320
- });
321
- document.querySelectorAll('[data-i18n-html]').forEach(el => {
322
- el.innerHTML = t(el.dataset.i18nHtml);
323
- });
324
- document.querySelectorAll('[data-i18n-placeholder]').forEach(el => {
325
- el.placeholder = t(el.dataset.i18nPlaceholder);
326
- });
327
- document.querySelectorAll('[data-i18n-title]').forEach(el => {
328
- el.title = t(el.dataset.i18nTitle);
329
- });
330
- }
331
-
332
- function toggleLang() {
333
- currentLangCode = currentLangCode === 'en' ? 'zh' : 'en';
334
- localStorage.setItem('codex-proxy-lang', currentLangCode);
335
- applyI18n();
336
- updateLangToggle();
337
- loadAccounts();
338
- }
339
-
340
- function updateLangToggle() {
341
- const el = document.getElementById('langToggle');
342
- if (el) el.querySelector('span').textContent = currentLangCode === 'en' ? 'EN' : '\u4e2d';
343
- }
344
-
345
- // ── State ──────────────────────────────────────────────────────
346
- let authData = null;
347
- let serverBaseUrl = '';
348
- let serverApiKey = '';
349
- let currentProtocol = 'openai';
350
- let currentLang = 'python';
351
- let addPollTimer = null;
352
-
353
- const avatarColors = [
354
- ['bg-purple-100 dark:bg-[#2a1a3f]', 'text-purple-600 dark:text-purple-400'],
355
- ['bg-amber-100 dark:bg-[#3d2c16]', 'text-amber-600 dark:text-amber-500'],
356
- ['bg-blue-100 dark:bg-[#1a2a3f]', 'text-blue-600 dark:text-blue-400'],
357
- ['bg-emerald-100 dark:bg-[#112a1f]', 'text-emerald-600 dark:text-emerald-400'],
358
- ['bg-red-100 dark:bg-[#3f1a1a]', 'text-red-600 dark:text-red-400'],
359
- ];
360
-
361
- // ── Theme Toggle ───────────────────────────────────────────────
362
- function toggleTheme() {
363
- const html = document.documentElement;
364
- const isDark = html.classList.toggle('dark');
365
- localStorage.setItem('codex-proxy-theme', isDark ? 'dark' : 'light');
366
- updateThemeIcon();
367
- }
368
-
369
- const SVG_MOON = '<svg class="size-5" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5"><path stroke-linecap="round" stroke-linejoin="round" d="M21.752 15.002A9.72 9.72 0 0118 15.75c-5.385 0-9.75-4.365-9.75-9.75 0-1.33.266-2.597.748-3.752A9.753 9.753 0 003 11.25C3 16.635 7.365 21 12.75 21a9.753 9.753 0 009.002-5.998z"/></svg>';
370
- const SVG_SUN = '<svg class="size-5" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5"><path stroke-linecap="round" stroke-linejoin="round" d="M12 3v2.25m6.364.386l-1.591 1.591M21 12h-2.25m-.386 6.364l-1.591-1.591M12 18.75V21m-4.773-4.227l-1.591 1.591M5.25 12H3m4.227-4.773L5.636 5.636M15.75 12a3.75 3.75 0 11-7.5 0 3.75 3.75 0 017.5 0z"/></svg>';
371
- const SVG_COPY = '<svg class="size-[18px]" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5"><rect x="9" y="9" width="13" height="13" rx="2"/><path d="M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1"/></svg>';
372
- const SVG_CHECK = '<svg class="size-[18px]" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"/></svg>';
373
-
374
- function updateThemeIcon() {
375
- const el = document.getElementById('themeIcon');
376
- if (!el) return;
377
- el.innerHTML = document.documentElement.classList.contains('dark') ? SVG_SUN : SVG_MOON;
378
- }
379
- updateThemeIcon();
380
-
381
- // ── Helpers ────────────────────────────────────────────────────
382
- function escapeHtml(str) {
383
- const div = document.createElement('div');
384
- div.textContent = str;
385
- return div.innerHTML;
386
- }
387
-
388
- function formatNumber(n) {
389
- if (n >= 1000000) return (n / 1000000).toFixed(1) + 'M';
390
- if (n >= 1000) return (n / 1000).toFixed(1) + 'k';
391
- return String(n);
392
- }
393
-
394
- function formatResetTime(unixSec) {
395
- const d = new Date(unixSec * 1000);
396
- const now = new Date();
397
- const time = d.toLocaleTimeString(undefined, { hour: '2-digit', minute: '2-digit', second: '2-digit' });
398
- // Same calendar day → just show time
399
- if (d.getFullYear() === now.getFullYear() && d.getMonth() === now.getMonth() && d.getDate() === now.getDate()) {
400
- return time;
401
- }
402
- // Tomorrow
403
- const tomorrow = new Date(now); tomorrow.setDate(tomorrow.getDate() + 1);
404
- if (d.getFullYear() === tomorrow.getFullYear() && d.getMonth() === tomorrow.getMonth() && d.getDate() === tomorrow.getDate()) {
405
- return (currentLangCode === 'zh' ? '明天 ' : 'Tomorrow ') + time;
406
- }
407
- // Other dates → full date + time
408
- const date = d.toLocaleDateString(undefined, { month: 'short', day: 'numeric' });
409
- return date + ' ' + time;
410
- }
411
-
412
- function statusBadge(status) {
413
- const map = {
414
- active: ['bg-green-100 text-green-700 border-green-200 dark:bg-[#11281d] dark:text-primary dark:border-[#1a442e]', 'active'],
415
- expired: ['bg-red-100 text-red-600 border-red-200 dark:bg-red-900/20 dark:text-red-400 dark:border-red-800/30', 'expired'],
416
- rate_limited: ['bg-amber-100 text-amber-700 border-amber-200 dark:bg-amber-900/20 dark:text-amber-400 dark:border-amber-800/30', 'rateLimited'],
417
- refreshing: ['bg-blue-100 text-blue-600 border-blue-200 dark:bg-blue-900/20 dark:text-blue-400 dark:border-blue-800/30', 'refreshing'],
418
- disabled: ['bg-slate-100 text-slate-500 border-slate-200 dark:bg-slate-800/30 dark:text-slate-400 dark:border-slate-700/30', 'disabled'],
419
- };
420
- const [cls, key] = map[status] || map.disabled;
421
- return `<span class="px-2.5 py-1 rounded-full ${cls} text-xs font-medium border">${escapeHtml(t(key))}</span>`;
422
- }
423
-
424
- // ── OAuth message listener ─────────────────────────────────────
425
- window.addEventListener('message', async (event) => {
426
- if (event.data?.type === 'oauth-callback-success') {
427
- if (addPollTimer) clearInterval(addPollTimer);
428
- document.getElementById('addSection').classList.add('hidden');
429
- showAddInfo(t('accountAdded'));
430
- await loadAccounts();
431
- await loadStatus();
432
- }
433
- });
434
-
435
- // ── Accounts ───────────────────────────────────────────────────
436
- async function loadAccounts() {
437
- try {
438
- const resp = await fetch('/auth/accounts?quota=true');
439
- const data = await resp.json();
440
- renderAccounts(data.accounts || []);
441
- } catch (err) {
442
- document.getElementById('accountList').innerHTML =
443
- `<div class="md:col-span-2 text-center py-8 text-red-400 text-sm bg-white dark:bg-card-dark border border-gray-200 dark:border-border-dark rounded-xl">${escapeHtml(err.message)}</div>`;
444
- }
445
- }
446
-
447
- function renderAccounts(accounts) {
448
- const container = document.getElementById('accountList');
449
-
450
- if (accounts.length === 0) {
451
- container.innerHTML = `<div class="md:col-span-2 text-center py-8 text-slate-400 dark:text-text-dim text-sm bg-white dark:bg-card-dark border border-gray-200 dark:border-border-dark rounded-xl">
452
- ${escapeHtml(t('noAccounts'))}
453
- </div>`;
454
- return;
455
- }
456
-
457
- container.innerHTML = accounts.map((acct, i) => {
458
- const usage = acct.usage || {};
459
- const email = acct.email || 'Unknown';
460
- const initial = email.charAt(0).toUpperCase();
461
- const [bgColor, textColor] = avatarColors[i % avatarColors.length];
462
- const requests = usage.request_count ?? 0;
463
- const tokens = (usage.input_tokens ?? 0) + (usage.output_tokens ?? 0);
464
- const plan = acct.planType || t('freeTier');
465
-
466
- // Quota bar
467
- let quotaHtml = '';
468
- const q = acct.quota;
469
- if (q && q.rate_limit) {
470
- const rl = q.rate_limit;
471
- const pct = rl.used_percent != null ? Math.round(rl.used_percent) : null;
472
- const barColor = pct == null ? 'bg-primary'
473
- : pct >= 90 ? 'bg-red-500'
474
- : pct >= 60 ? 'bg-amber-500'
475
- : 'bg-primary';
476
- const pctColor = pct == null ? 'text-primary'
477
- : pct >= 90 ? 'text-red-500'
478
- : pct >= 60 ? 'text-amber-600 dark:text-amber-500'
479
- : 'text-primary';
480
- const resetAt = rl.reset_at ? formatResetTime(rl.reset_at) : null;
481
-
482
- quotaHtml = `
483
- <div class="pt-3 mt-3 border-t border-slate-100 dark:border-border-dark">
484
- <div class="flex justify-between text-[0.78rem] mb-1.5">
485
- <span class="text-slate-500 dark:text-text-dim">${escapeHtml(t('rateLimit'))}</span>
486
- ${rl.limit_reached
487
- ? `<span class="px-2 py-0.5 rounded-full bg-red-100 dark:bg-red-900/20 text-red-600 dark:text-red-400 text-xs font-medium">${escapeHtml(t('limitReached'))}</span>`
488
- : pct != null
489
- ? `<span class="font-medium ${pctColor}">${pct}% ${escapeHtml(t('used'))}</span>`
490
- : `<span class="font-medium text-primary">${escapeHtml(t('ok'))}</span>`}
491
- </div>
492
- ${pct != null ? `
493
- <div class="w-full bg-slate-100 dark:bg-border-dark rounded-full h-2 overflow-hidden">
494
- <div class="${barColor} h-2 rounded-full transition-all" style="width: ${pct}%"></div>
495
- </div>` : ''}
496
- ${resetAt ? `<p class="text-xs text-slate-400 dark:text-text-dim mt-1">${escapeHtml(t('resetsAt'))} ${escapeHtml(resetAt)}</p>` : ''}
497
- </div>`;
498
- }
499
-
500
- return `
501
- <div class="group bg-white dark:bg-card-dark border border-gray-200 dark:border-border-dark rounded-xl p-4 shadow-sm hover:shadow-md transition-all hover:border-primary/30 dark:hover:border-primary/50 relative">
502
- <button onclick="deleteAccount('${escapeHtml(acct.id)}')" class="absolute top-3 right-3 opacity-0 group-hover:opacity-100 p-1.5 text-slate-300 dark:text-text-dim hover:text-red-500 transition-all rounded-md hover:bg-red-50 dark:hover:bg-red-900/20" title="${escapeHtml(t('deleteAccount'))}">
503
- <svg class="size-[18px]" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5"><path stroke-linecap="round" stroke-linejoin="round" d="M14.74 9l-.346 9m-4.788 0L9.26 9m9.968-3.21c.342.052.682.107 1.022.166m-1.022-.165L18.16 19.673a2.25 2.25 0 01-2.244 2.077H8.084a2.25 2.25 0 01-2.244-2.077L4.772 5.79m14.456 0a48.108 48.108 0 00-3.478-.397m-12 .562c.34-.059.68-.114 1.022-.165m0 0a48.11 48.11 0 013.478-.397m7.5 0v-.916c0-1.18-.91-2.164-2.09-2.201a51.964 51.964 0 00-3.32 0c-1.18.037-2.09 1.022-2.09 2.201v.916m7.5 0a48.667 48.667 0 00-7.5 0"/></svg>
504
- </button>
505
- <div class="flex justify-between items-start mb-4">
506
- <div class="flex items-center gap-3">
507
- <div class="size-10 rounded-full ${bgColor} ${textColor} flex items-center justify-center font-bold text-lg">${initial}</div>
508
- <div>
509
- <h3 class="text-[0.82rem] font-semibold leading-tight">${escapeHtml(email)}</h3>
510
- <p class="text-xs text-slate-500 dark:text-text-dim">${escapeHtml(plan)}</p>
511
- </div>
512
- </div>
513
- ${statusBadge(acct.status)}
514
- </div>
515
- <div class="space-y-2">
516
- <div class="flex justify-between text-[0.78rem]">
517
- <span class="text-slate-500 dark:text-text-dim">${escapeHtml(t('totalRequests'))}</span>
518
- <span class="font-medium">${formatNumber(requests)}</span>
519
- </div>
520
- <div class="flex justify-between text-[0.78rem]">
521
- <span class="text-slate-500 dark:text-text-dim">${escapeHtml(t('tokensUsed'))}</span>
522
- <span class="font-medium">${formatNumber(tokens)}</span>
523
- </div>
524
- </div>
525
- ${quotaHtml}
526
- </div>`;
527
- }).join('');
528
- }
529
-
530
- async function deleteAccount(id) {
531
- if (!confirm(t('removeConfirm'))) return;
532
- try {
533
- const resp = await fetch('/auth/accounts/' + encodeURIComponent(id), { method: 'DELETE' });
534
- if (!resp.ok) {
535
- const data = await resp.json();
536
- alert(data.error || t('failedDeleteAccount'));
537
- return;
538
- }
539
- await loadAccounts();
540
- await loadStatus();
541
- } catch (err) {
542
- alert(t('networkError') + err.message);
543
- }
544
- }
545
-
546
- // ── Add Account ────────────────────────────────────────────────
547
- function showAddInfo(msg) {
548
- const el = document.getElementById('addInfo');
549
- el.textContent = msg;
550
- el.classList.remove('hidden');
551
- document.getElementById('addError').classList.add('hidden');
552
- }
553
-
554
- function showAddError(msg) {
555
- const el = document.getElementById('addError');
556
- el.textContent = msg;
557
- el.classList.remove('hidden');
558
- document.getElementById('addInfo').classList.add('hidden');
559
- }
560
-
561
- async function startAddAccount() {
562
- const btn = document.getElementById('addAccountBtn');
563
- const infoEl = document.getElementById('addInfo');
564
- const errEl = document.getElementById('addError');
565
- infoEl.classList.add('hidden');
566
- errEl.classList.add('hidden');
567
- btn.disabled = true;
568
-
569
- try {
570
- const resp = await fetch('/auth/login-start', { method: 'POST' });
571
- const data = await resp.json();
572
-
573
- if (!resp.ok || !data.authUrl) {
574
- throw new Error(data.error || t('failedStartLogin'));
575
- }
576
-
577
- window.open(data.authUrl, 'oauth_add', 'width=600,height=700,scrollbars=yes');
578
- document.getElementById('addSection').classList.remove('hidden');
579
- btn.disabled = false;
580
-
581
- if (addPollTimer) clearInterval(addPollTimer);
582
- const prevCount = (await fetch('/auth/accounts').then(r => r.json())).accounts?.length || 0;
583
- addPollTimer = setInterval(async () => {
584
- try {
585
- const r = await fetch('/auth/accounts');
586
- const d = await r.json();
587
- if ((d.accounts?.length || 0) > prevCount) {
588
- clearInterval(addPollTimer);
589
- document.getElementById('addSection').classList.add('hidden');
590
- showAddInfo(t('accountAdded'));
591
- await loadAccounts();
592
- await loadStatus();
593
- }
594
- } catch {}
595
- }, 2000);
596
- setTimeout(() => { if (addPollTimer) clearInterval(addPollTimer); }, 5 * 60 * 1000);
597
-
598
- } catch (err) {
599
- btn.disabled = false;
600
- showAddError(err.message);
601
- }
602
- }
603
-
604
- async function submitAddRelay() {
605
- const callbackUrl = document.getElementById('addCallbackInput').value.trim();
606
- document.getElementById('addInfo').classList.add('hidden');
607
- document.getElementById('addError').classList.add('hidden');
608
-
609
- if (!callbackUrl) { showAddError(t('pleasePassCallback')); return; }
610
-
611
- const btn = document.getElementById('addRelayBtn');
612
- btn.disabled = true;
613
- btn.textContent = t('submitting');
614
-
615
- try {
616
- const resp = await fetch('/auth/code-relay', {
617
- method: 'POST',
618
- headers: { 'Content-Type': 'application/json' },
619
- body: JSON.stringify({ callbackUrl }),
620
- });
621
- const data = await resp.json();
622
-
623
- if (resp.ok && data.success) {
624
- if (addPollTimer) clearInterval(addPollTimer);
625
- document.getElementById('addSection').classList.add('hidden');
626
- document.getElementById('addCallbackInput').value = '';
627
- showAddInfo(t('accountAdded'));
628
- await loadAccounts();
629
- await loadStatus();
630
- } else {
631
- showAddError(data.error || t('failedExchangeCode'));
632
- }
633
- } catch (err) {
634
- showAddError(t('networkError') + err.message);
635
- } finally {
636
- btn.textContent = t('submit');
637
- btn.disabled = false;
638
- }
639
- }
640
-
641
- // ── Status & Config ────────────────────────────────────────────
642
- async function loadStatus() {
643
- try {
644
- const resp = await fetch('/auth/status');
645
- authData = await resp.json();
646
-
647
- if (!authData.authenticated) return;
648
-
649
- serverBaseUrl = `${window.location.origin}/v1`;
650
- serverApiKey = authData.proxy_api_key || 'any-string';
651
- document.getElementById('baseUrl').value = serverBaseUrl;
652
- document.getElementById('apiKey').value = serverApiKey;
653
-
654
- await populateModelDropdown();
655
- updateCodeExamples();
656
- } catch (err) {
657
- console.error('Status load error:', err);
658
- }
659
- }
660
-
661
- async function populateModelDropdown() {
662
- const sel = document.getElementById('defaultModel');
663
- try {
664
- const resp = await fetch('/v1/models');
665
- const data = await resp.json();
666
- const models = data.data.map(m => m.id);
667
- if (models.length > 0) {
668
- sel.innerHTML = '';
669
- models.forEach(id => {
670
- const opt = document.createElement('option');
671
- opt.value = id;
672
- opt.textContent = id;
673
- sel.appendChild(opt);
674
- });
675
- const preferred = models.find(n => n.includes('5.3-codex'));
676
- if (preferred) sel.value = preferred;
677
- }
678
- } catch {
679
- sel.innerHTML = '<option value="codex">codex</option>';
680
- }
681
- }
682
-
683
- // ── Code Examples ──────────────────────────────────────────────
684
- function updateCodeExamples() {
685
- const baseUrl = document.getElementById('baseUrl').value;
686
- const apiKey = document.getElementById('apiKey').value || 'any-string';
687
- const model = document.getElementById('defaultModel').value;
688
- const origin = window.location.origin;
689
-
690
- window._codeExamples = {
691
- 'openai-python': `from openai import OpenAI
692
-
693
- client = OpenAI(
694
- base_url="${baseUrl}",
695
- api_key="${apiKey}",
696
- )
697
-
698
- response = client.chat.completions.create(
699
- model="${model}",
700
- messages=[{"role": "user", "content": "Hello"}],
701
- )
702
- print(response.choices[0].message.content)`,
703
-
704
- 'openai-curl': `curl ${baseUrl}/chat/completions \\
705
- -H "Content-Type: application/json" \\
706
- -H "Authorization: Bearer ${apiKey}" \\
707
- -d '{
708
- "model": "${model}",
709
- "messages": [{"role": "user", "content": "Hello"}]
710
- }'`,
711
-
712
- 'openai-node': `import OpenAI from "openai";
713
-
714
- const client = new OpenAI({
715
- baseURL: "${baseUrl}",
716
- apiKey: "${apiKey}",
717
- });
718
-
719
- const stream = await client.chat.completions.create({
720
- model: "${model}",
721
- messages: [{ role: "user", content: "Hello" }],
722
- stream: true,
723
- });
724
- for await (const chunk of stream) {
725
- process.stdout.write(chunk.choices[0]?.delta?.content || "");
726
- }`,
727
-
728
- 'anthropic-python': `import anthropic
729
-
730
- client = anthropic.Anthropic(
731
- base_url="${origin}/v1",
732
- api_key="${apiKey}",
733
- )
734
-
735
- message = client.messages.create(
736
- model="claude-sonnet-4-20250514",
737
- max_tokens=1024,
738
- messages=[{"role": "user", "content": "Hello"}],
739
- )
740
- print(message.content[0].text)`,
741
-
742
- 'anthropic-curl': `curl ${origin}/v1/messages \\
743
- -H "Content-Type: application/json" \\
744
- -H "x-api-key: ${apiKey}" \\
745
- -H "anthropic-version: 2023-06-01" \\
746
- -d '{
747
- "model": "claude-sonnet-4-20250514",
748
- "max_tokens": 1024,
749
- "messages": [{"role": "user", "content": "Hello"}]
750
- }'`,
751
-
752
- 'anthropic-node': `import Anthropic from "@anthropic-ai/sdk";
753
-
754
- const client = new Anthropic({
755
- baseURL: "${origin}/v1",
756
- apiKey: "${apiKey}",
757
- });
758
-
759
- const message = await client.messages.create({
760
- model: "claude-sonnet-4-20250514",
761
- max_tokens: 1024,
762
- messages: [{ role: "user", content: "Hello" }],
763
- });
764
- console.log(message.content[0].text);`,
765
-
766
- 'gemini-python': `from google import genai
767
-
768
- client = genai.Client(
769
- api_key="${apiKey}",
770
- http_options={"base_url": "${origin}/v1beta"},
771
- )
772
-
773
- response = client.models.generate_content(
774
- model="gemini-2.5-pro",
775
- contents="Hello",
776
- )
777
- print(response.text)`,
778
-
779
- 'gemini-curl': `curl "${origin}/v1beta/models/gemini-2.5-pro:generateContent?key=${apiKey}" \\
780
- -H "Content-Type: application/json" \\
781
- -d '{
782
- "contents": [{"role": "user", "parts": [{"text": "Hello"}]}]
783
- }'`,
784
-
785
- 'gemini-node': `import { GoogleGenAI } from "@google/genai";
786
-
787
- const ai = new GoogleGenAI({
788
- apiKey: "${apiKey}",
789
- httpOptions: { baseUrl: "${origin}/v1beta" },
790
- });
791
-
792
- const response = await ai.models.generateContent({
793
- model: "gemini-2.5-pro",
794
- contents: "Hello",
795
- });
796
- console.log(response.text);`,
797
- };
798
-
799
- showCurrentCode();
800
- }
801
-
802
- function showCurrentCode() {
803
- const key = `${currentProtocol}-${currentLang}`;
804
- const code = (window._codeExamples && window._codeExamples[key]) || 'Loading...';
805
- document.getElementById('codeBlock').textContent = code;
806
- }
807
-
808
- // ── Tab Switching ──────────────────────────────────────────────
809
- const PROTO_ACTIVE = 'proto-tab px-6 py-3 text-[0.82rem] font-semibold text-primary border-b-2 border-primary bg-white dark:bg-card-dark transition-colors';
810
- const PROTO_INACTIVE = 'proto-tab px-6 py-3 text-[0.82rem] font-medium text-slate-500 dark:text-text-dim hover:text-slate-700 dark:hover:text-text-main hover:bg-slate-50 dark:hover:bg-[#21262d] border-b-2 border-transparent transition-colors';
811
- const LANG_ACTIVE = 'lang-tab px-3 py-1.5 text-xs font-semibold rounded bg-white dark:bg-[#21262d] text-slate-800 dark:text-text-main shadow-sm border border-transparent dark:border-border-dark transition-all';
812
- const LANG_INACTIVE = 'lang-tab px-3 py-1.5 text-xs font-medium rounded text-slate-500 dark:text-text-dim hover:text-slate-700 dark:hover:text-text-main hover:bg-white/50 dark:hover:bg-[#21262d] border border-transparent transition-all';
813
-
814
- function switchProtocol(proto, el) {
815
- currentProtocol = proto;
816
- document.querySelectorAll('.proto-tab').forEach(t => t.className = PROTO_INACTIVE);
817
- el.className = PROTO_ACTIVE;
818
- showCurrentCode();
819
- }
820
-
821
- function switchLang(lang, el) {
822
- currentLang = lang;
823
- document.querySelectorAll('.lang-tab').forEach(t => t.className = LANG_INACTIVE);
824
- el.className = LANG_ACTIVE;
825
- showCurrentCode();
826
- }
827
-
828
- // ── Copy ───────────────────────────────────────────────────────
829
- function fallbackCopy(text) {
830
- const ta = document.createElement('textarea');
831
- ta.value = text;
832
- ta.style.cssText = 'position:fixed;left:-9999px;opacity:0';
833
- document.body.appendChild(ta);
834
- ta.select();
835
- let ok = false;
836
- try { ok = document.execCommand('copy'); } catch {}
837
- document.body.removeChild(ta);
838
- return ok;
839
- }
840
-
841
- async function clipboardCopy(text) {
842
- if (navigator.clipboard?.writeText) {
843
- try { await navigator.clipboard.writeText(text); return true; } catch {}
844
- }
845
- return fallbackCopy(text);
846
- }
847
-
848
- async function copyField(id, btn) {
849
- const el = document.getElementById(id);
850
- const text = el.value !== undefined ? el.value : el.textContent;
851
- const ok = await clipboardCopy(text);
852
- btn.innerHTML = ok ? SVG_CHECK : '<svg class="size-[18px]" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M6 18L18 6M6 6l12 12"/></svg>';
853
- btn.classList.add(ok ? 'text-primary' : 'text-red-500');
854
- setTimeout(() => { btn.innerHTML = SVG_COPY; btn.classList.remove('text-primary', 'text-red-500'); }, 2000);
855
- }
856
-
857
- async function copyCurrentCode() {
858
- const key = `${currentProtocol}-${currentLang}`;
859
- const code = window._codeExamples?.[key] || '';
860
- const ok = await clipboardCopy(code);
861
- const btn = document.querySelector('#codeContainer button');
862
- if (!btn) return;
863
- const label = btn.querySelector('span');
864
- const svg = btn.querySelector('svg');
865
- if (ok) {
866
- if (label) label.textContent = t('copied');
867
- btn.classList.add('bg-primary', 'hover:bg-primary-hover');
868
- btn.classList.remove('bg-slate-700', 'hover:bg-slate-600');
869
- } else {
870
- if (label) label.textContent = t('copyFailed');
871
- btn.classList.add('bg-red-600', 'hover:bg-red-700');
872
- btn.classList.remove('bg-slate-700', 'hover:bg-slate-600');
873
- }
874
- setTimeout(() => {
875
- if (label) label.textContent = t('copy');
876
- btn.classList.remove('bg-primary', 'hover:bg-primary-hover', 'bg-red-600', 'hover:bg-red-700');
877
- btn.classList.add('bg-slate-700', 'hover:bg-slate-600');
878
- }, 2000);
879
- }
880
-
881
- // ── Init ───────────────────────────────────────────────────────
882
- try { localStorage.removeItem('codex-proxy-config-overrides'); } catch {}
883
- applyI18n();
884
- updateLangToggle();
885
- loadStatus();
886
- loadAccounts();
887
- document.getElementById('defaultModel').addEventListener('change', () => updateCodeExamples());
888
- </script>
889
- </body></html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
src/auth/oauth-pkce.ts CHANGED
@@ -393,6 +393,26 @@ export interface CliAuthJson {
393
  expires_at?: number;
394
  }
395
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
396
  /**
397
  * Read and parse the Codex CLI auth.json file.
398
  * Path: $CODEX_HOME/auth.json (default: ~/.codex/auth.json)
 
393
  expires_at?: number;
394
  }
395
 
396
+ /**
397
+ * Start an OAuth flow with callback server in one call.
398
+ * Combines createOAuthSession + startCallbackServer + account registration.
399
+ * Used by /auth/login, /auth/login-start, and /auth/accounts/login.
400
+ */
401
+ export function startOAuthFlow(
402
+ originalHost: string,
403
+ returnTo: "login" | "dashboard",
404
+ pool: { addAccount(accessToken: string, refreshToken?: string): string },
405
+ scheduler: { scheduleOne(entryId: string, accessToken: string): void },
406
+ ): { authUrl: string; state: string } {
407
+ const { authUrl, state, port } = createOAuthSession(originalHost, returnTo);
408
+ startCallbackServer(port, (accessToken, refreshToken) => {
409
+ const entryId = pool.addAccount(accessToken, refreshToken);
410
+ scheduler.scheduleOne(entryId, accessToken);
411
+ console.log(`[Auth] OAuth via callback server — account ${entryId} added`);
412
+ });
413
+ return { authUrl, state };
414
+ }
415
+
416
  /**
417
  * Read and parse the Codex CLI auth.json file.
418
  * Path: $CODEX_HOME/auth.json (default: ~/.codex/auth.json)
src/config.ts CHANGED
@@ -36,10 +36,6 @@ const ConfigSchema = z.object({
36
  port: z.number().min(1).max(65535).default(8080),
37
  proxy_api_key: z.string().nullable().default(null),
38
  }),
39
- environment: z.object({
40
- default_id: z.string().nullable().default(null),
41
- default_branch: z.string().default("main"),
42
- }),
43
  session: z.object({
44
  ttl_minutes: z.number().min(1).default(60),
45
  cleanup_interval_minutes: z.number().min(1).default(5),
@@ -50,14 +46,6 @@ const ConfigSchema = z.object({
50
  proxy_url: z.string().nullable().default(null),
51
  transport: z.enum(["auto", "curl-cli", "libcurl-ffi"]).default("auto"),
52
  }).default({}),
53
- streaming: z.object({
54
- status_as_content: z.boolean().default(false),
55
- chunk_size: z.number().default(100),
56
- chunk_delay_ms: z.number().default(10),
57
- heartbeat_interval_s: z.number().default(15),
58
- poll_interval_s: z.number().default(2),
59
- timeout_s: z.number().default(300),
60
- }),
61
  });
62
 
63
  export type AppConfig = z.infer<typeof ConfigSchema>;
 
36
  port: z.number().min(1).max(65535).default(8080),
37
  proxy_api_key: z.string().nullable().default(null),
38
  }),
 
 
 
 
39
  session: z.object({
40
  ttl_minutes: z.number().min(1).default(60),
41
  cleanup_interval_minutes: z.number().min(1).default(5),
 
46
  proxy_url: z.string().nullable().default(null),
47
  transport: z.enum(["auto", "curl-cli", "libcurl-ffi"]).default("auto"),
48
  }).default({}),
 
 
 
 
 
 
 
 
49
  });
50
 
51
  export type AppConfig = z.infer<typeof ConfigSchema>;
src/routes/accounts.ts CHANGED
@@ -17,7 +17,7 @@ import { Hono } from "hono";
17
  import type { AccountPool } from "../auth/account-pool.js";
18
  import type { RefreshScheduler } from "../auth/refresh-scheduler.js";
19
  import { validateManualToken } from "../auth/chatgpt-oauth.js";
20
- import { createOAuthSession, startCallbackServer } from "../auth/oauth-pkce.js";
21
  import { getConfig } from "../config.js";
22
  import { CodexApi } from "../proxy/codex-api.js";
23
  import type { CodexUsageResponse } from "../proxy/codex-api.js";
@@ -62,16 +62,7 @@ export function createAccountRoutes(
62
  app.get("/auth/accounts/login", (c) => {
63
  const config = getConfig();
64
  const originalHost = c.req.header("host") || `localhost:${config.server.port}`;
65
-
66
- const { authUrl, port } = createOAuthSession(originalHost, "dashboard");
67
-
68
- // Start temporary callback server for same-machine callback
69
- startCallbackServer(port, (accessToken, refreshToken) => {
70
- const entryId = pool.addAccount(accessToken, refreshToken);
71
- scheduler.scheduleOne(entryId, accessToken);
72
- console.log(`[Auth] OAuth via callback server — account ${entryId} added`);
73
- });
74
-
75
  return c.redirect(authUrl);
76
  });
77
 
 
17
  import type { AccountPool } from "../auth/account-pool.js";
18
  import type { RefreshScheduler } from "../auth/refresh-scheduler.js";
19
  import { validateManualToken } from "../auth/chatgpt-oauth.js";
20
+ import { startOAuthFlow } from "../auth/oauth-pkce.js";
21
  import { getConfig } from "../config.js";
22
  import { CodexApi } from "../proxy/codex-api.js";
23
  import type { CodexUsageResponse } from "../proxy/codex-api.js";
 
62
  app.get("/auth/accounts/login", (c) => {
63
  const config = getConfig();
64
  const originalHost = c.req.header("host") || `localhost:${config.server.port}`;
65
+ const { authUrl } = startOAuthFlow(originalHost, "dashboard", pool, scheduler);
 
 
 
 
 
 
 
 
 
66
  return c.redirect(authUrl);
67
  });
68
 
src/routes/auth.ts CHANGED
@@ -4,10 +4,9 @@ import type { RefreshScheduler } from "../auth/refresh-scheduler.js";
4
  import { validateManualToken } from "../auth/chatgpt-oauth.js";
5
  import { getConfig } from "../config.js";
6
  import {
7
- createOAuthSession,
8
  consumeSession,
9
  exchangeCode,
10
- startCallbackServer,
11
  requestDeviceCode,
12
  pollDeviceToken,
13
  importCliAuth,
@@ -38,16 +37,7 @@ export function createAuthRoutes(
38
  app.get("/auth/login", (c) => {
39
  const config = getConfig();
40
  const originalHost = c.req.header("host") || `localhost:${config.server.port}`;
41
-
42
- const { authUrl, port } = createOAuthSession(originalHost, "login");
43
-
44
- // Start temporary callback server for same-machine callback
45
- startCallbackServer(port, (accessToken, refreshToken) => {
46
- const entryId = pool.addAccount(accessToken, refreshToken);
47
- scheduler.scheduleOne(entryId, accessToken);
48
- console.log(`[Auth] OAuth via callback server — account ${entryId} added`);
49
- });
50
-
51
  return c.redirect(authUrl);
52
  });
53
 
@@ -55,16 +45,7 @@ export function createAuthRoutes(
55
  app.post("/auth/login-start", (c) => {
56
  const config = getConfig();
57
  const originalHost = c.req.header("host") || `localhost:${config.server.port}`;
58
-
59
- const { authUrl, state, port } = createOAuthSession(originalHost, "login");
60
-
61
- // Start temporary callback server for same-machine callback
62
- startCallbackServer(port, (accessToken, refreshToken) => {
63
- const entryId = pool.addAccount(accessToken, refreshToken);
64
- scheduler.scheduleOne(entryId, accessToken);
65
- console.log(`[Auth] OAuth via callback server — account ${entryId} added`);
66
- });
67
-
68
  return c.json({ authUrl, state });
69
  });
70
 
 
4
  import { validateManualToken } from "../auth/chatgpt-oauth.js";
5
  import { getConfig } from "../config.js";
6
  import {
7
+ startOAuthFlow,
8
  consumeSession,
9
  exchangeCode,
 
10
  requestDeviceCode,
11
  pollDeviceToken,
12
  importCliAuth,
 
37
  app.get("/auth/login", (c) => {
38
  const config = getConfig();
39
  const originalHost = c.req.header("host") || `localhost:${config.server.port}`;
40
+ const { authUrl } = startOAuthFlow(originalHost, "login", pool, scheduler);
 
 
 
 
 
 
 
 
 
41
  return c.redirect(authUrl);
42
  });
43
 
 
45
  app.post("/auth/login-start", (c) => {
46
  const config = getConfig();
47
  const originalHost = c.req.header("host") || `localhost:${config.server.port}`;
48
+ const { authUrl, state } = startOAuthFlow(originalHost, "login", pool, scheduler);
 
 
 
 
 
 
 
 
 
49
  return c.json({ authUrl, state });
50
  });
51
 
src/update-checker.ts CHANGED
@@ -64,9 +64,10 @@ function parseAppcast(xml: string): {
64
  }
65
 
66
  function applyVersionUpdate(version: string, build: string): void {
67
- mutateYaml(CONFIG_PATH, (data: any) => {
68
- data.client.app_version = version;
69
- data.client.build_number = build;
 
70
  });
71
  mutateClientConfig({ app_version: version, build_number: build });
72
  }
 
64
  }
65
 
66
  function applyVersionUpdate(version: string, build: string): void {
67
+ mutateYaml(CONFIG_PATH, (data) => {
68
+ const client = data.client as Record<string, unknown>;
69
+ client.app_version = version;
70
+ client.build_number = build;
71
  });
72
  mutateClientConfig({ app_version: version, build_number: build });
73
  }
src/utils/yaml-mutate.ts CHANGED
@@ -12,9 +12,9 @@ import yaml from "js-yaml";
12
  * Load a YAML file, apply a mutator function, and atomically write it back.
13
  * Uses tmp-file + rename for crash safety.
14
  */
15
- export function mutateYaml(filePath: string, mutator: (data: any) => void): void {
16
  const raw = readFileSync(filePath, "utf-8");
17
- const data = yaml.load(raw);
18
  mutator(data);
19
  const tmp = filePath + ".tmp";
20
  writeFileSync(tmp, yaml.dump(data, { lineWidth: -1, quotingType: '"' }), "utf-8");
 
12
  * Load a YAML file, apply a mutator function, and atomically write it back.
13
  * Uses tmp-file + rename for crash safety.
14
  */
15
+ export function mutateYaml(filePath: string, mutator: (data: Record<string, unknown>) => void): void {
16
  const raw = readFileSync(filePath, "utf-8");
17
+ const data = yaml.load(raw) as Record<string, unknown>;
18
  mutator(data);
19
  const tmp = filePath + ".tmp";
20
  writeFileSync(tmp, yaml.dump(data, { lineWidth: -1, quotingType: '"' }), "utf-8");
web/src/components/AccountCard.tsx CHANGED
@@ -1,6 +1,6 @@
1
  import { useCallback } from "preact/hooks";
2
- import { useT } from "../i18n/context";
3
- import { useI18n } from "../i18n/context";
4
  import { formatNumber, formatResetTime } from "../utils/format";
5
  import type { Account } from "../hooks/use-accounts";
6
 
@@ -91,7 +91,7 @@ export function AccountCard({ account, index, onDelete }: AccountCardProps) {
91
  </div>
92
  <div class="flex items-center gap-2">
93
  <span class={`px-2.5 py-1 rounded-full ${statusCls} text-xs font-medium border`}>
94
- {t(statusKey as any)}
95
  </span>
96
  <button
97
  onClick={handleDelete}
 
1
  import { useCallback } from "preact/hooks";
2
+ import { useT, useI18n } from "../i18n/context";
3
+ import type { TranslationKey } from "../i18n/translations";
4
  import { formatNumber, formatResetTime } from "../utils/format";
5
  import type { Account } from "../hooks/use-accounts";
6
 
 
91
  </div>
92
  <div class="flex items-center gap-2">
93
  <span class={`px-2.5 py-1 rounded-full ${statusCls} text-xs font-medium border`}>
94
+ {t(statusKey as TranslationKey)}
95
  </span>
96
  <button
97
  onClick={handleDelete}
web/src/components/AddAccount.tsx CHANGED
@@ -1,5 +1,6 @@
1
  import { useState, useCallback } from "preact/hooks";
2
  import { useT } from "../i18n/context";
 
3
 
4
  interface AddAccountProps {
5
  visible: boolean;
@@ -25,10 +26,10 @@ export function AddAccount({ visible, onSubmitRelay, addInfo, addError }: AddAcc
25
  return (
26
  <>
27
  {addInfo && (
28
- <p class="text-sm text-primary">{t(addInfo as any)}</p>
29
  )}
30
  {addError && (
31
- <p class="text-sm text-red-500">{t(addError as any)}</p>
32
  )}
33
  {visible && (
34
  <section class="bg-white dark:bg-card-dark border border-gray-200 dark:border-border-dark rounded-xl p-5 shadow-sm transition-colors">
 
1
  import { useState, useCallback } from "preact/hooks";
2
  import { useT } from "../i18n/context";
3
+ import type { TranslationKey } from "../i18n/translations";
4
 
5
  interface AddAccountProps {
6
  visible: boolean;
 
26
  return (
27
  <>
28
  {addInfo && (
29
+ <p class="text-sm text-primary">{t(addInfo as TranslationKey)}</p>
30
  )}
31
  {addError && (
32
+ <p class="text-sm text-red-500">{t(addError as TranslationKey)}</p>
33
  )}
34
  {visible && (
35
  <section class="bg-white dark:bg-card-dark border border-gray-200 dark:border-border-dark rounded-xl p-5 shadow-sm transition-colors">
web/src/components/CopyButton.tsx CHANGED
@@ -1,6 +1,7 @@
1
  import { useState, useCallback } from "preact/hooks";
2
  import { clipboardCopy } from "../utils/clipboard";
3
  import { useT } from "../i18n/context";
 
4
 
5
  interface CopyButtonProps {
6
  getText: () => string;
@@ -72,7 +73,7 @@ export function CopyButton({ getText, class: className, titleKey, variant = "ico
72
  ? "text-red-500"
73
  : "text-slate-400 dark:text-text-dim hover:text-primary"
74
  } ${className || ""}`}
75
- title={titleKey ? t(titleKey as any) : undefined}
76
  >
77
  {state === "ok" ? SVG_CHECK : state === "fail" ? SVG_FAIL : SVG_COPY}
78
  </button>
 
1
  import { useState, useCallback } from "preact/hooks";
2
  import { clipboardCopy } from "../utils/clipboard";
3
  import { useT } from "../i18n/context";
4
+ import type { TranslationKey } from "../i18n/translations";
5
 
6
  interface CopyButtonProps {
7
  getText: () => string;
 
73
  ? "text-red-500"
74
  : "text-slate-400 dark:text-text-dim hover:text-primary"
75
  } ${className || ""}`}
76
+ title={titleKey ? t(titleKey as TranslationKey) : undefined}
77
  >
78
  {state === "ok" ? SVG_CHECK : state === "fail" ? SVG_FAIL : SVG_COPY}
79
  </button>
web/vite.config.ts CHANGED
@@ -5,7 +5,7 @@ export default defineConfig({
5
  plugins: [preact()],
6
  build: {
7
  outDir: "../public",
8
- emptyOutDir: false,
9
  },
10
  server: {
11
  port: 5173,
 
5
  plugins: [preact()],
6
  build: {
7
  outDir: "../public",
8
+ emptyOutDir: true,
9
  },
10
  server: {
11
  port: 5173,