claude-codex-proxy 1.0.5-beta.7 → 1.0.5-beta.9

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-codex-proxy",
3
- "version": "1.0.5-beta.7",
3
+ "version": "1.0.5-beta.9",
4
4
  "description": "Multi-account proxy server for OpenAI Codex CLI with Claude API compatibility",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
package/public/index.html CHANGED
@@ -1,60 +1,60 @@
1
- <!DOCTYPE html>
2
- <html lang="en" data-theme="codex" class="dark">
3
- <head>
4
- <meta charset="UTF-8">
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title>Claude Codex Proxy</title>
7
- <link rel="icon" type="image/svg+xml" href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'><text y='.9em' font-size='90'>🚀</text></svg>">
8
- <script src="https://cdn.jsdelivr.net/npm/alpinejs@3.x.x/dist/cdn.min.js" defer></script>
9
- <link rel="stylesheet" href="/css/style.css">
10
- </head>
11
- <body class="bg-space-950 text-gray-300 font-sans antialiased min-h-screen selection:bg-neon-purple selection:text-white" x-data="app" x-init="init()">
12
- <div x-cloak class="fixed top-4 right-4 z-[100] flex flex-col gap-2 pointer-events-none">
13
- <template x-if="toast">
14
- <div class="alert shadow-lg border backdrop-blur-md pointer-events-auto min-w-[300px]" :class="{
15
- 'alert-info border-neon-cyan/20 bg-space-900/90 text-neon-cyan': toast.type === 'info',
16
- 'alert-success border-neon-green/20 bg-space-900/90 text-neon-green': toast.type === 'success',
17
- 'alert-error border-red-500/20 bg-space-900/90 text-red-400': toast.type === 'error',
18
- 'alert-warning border-yellow-500/20 bg-space-900/90 text-yellow-400': toast.type === 'warning'
19
- }"><span x-text="toast.message" class="font-mono text-sm"></span></div>
20
- </template>
21
- </div>
22
-
23
- <div x-cloak class="h-14 border-b border-space-border flex items-center px-4 lg:px-6 justify-between bg-space-900/50 backdrop-blur-md z-50 relative" x-show="isAuthenticated">
24
- <div class="flex items-center gap-3">
25
- <button @click="sidebarOpen = !sidebarOpen" class="text-gray-400 hover:text-white focus:outline-none p-1 transition-colors lg:hidden" aria-label="Toggle navigation">☰</button>
26
- <div class="w-8 h-8 rounded bg-gradient-to-br from-neon-purple to-blue-600 flex items-center justify-center text-white font-bold">CX</div>
27
- <div class="flex flex-col"><span class="text-sm font-bold tracking-wide text-white">CODEX PROXY</span><span class="text-[10px] text-gray-500 font-mono tracking-wider" x-text="version ? 'CLAUDE PROXY SYSTEM v' + version : 'CLAUDE PROXY SYSTEM'"></span></div>
28
- </div>
29
- <div class="flex items-center gap-4">
30
- <div class="flex items-center gap-2 px-3 py-1 rounded-full text-xs font-mono border" :class="connectionStatus === 'connected' ? 'bg-neon-green/10 border-neon-green/20 text-neon-green' : 'bg-red-500/10 border-red-500/20 text-red-500'"><span x-text="connectionStatus === 'connected' ? 'Online' : 'Offline'"></span></div>
31
- <button type="button" class="btn btn-ghost btn-xs text-gray-400 hover:text-white" @click="refreshAccounts()" :disabled="loading">Refresh</button>
32
- <button x-show="authRequired" type="button" class="btn btn-ghost btn-xs text-gray-400 hover:text-white" @click="logout()">Logout</button>
33
- </div>
34
- </div>
35
-
36
- <div x-cloak x-show="isAuthenticated" class="flex h-[calc(100vh-56px)] relative">
37
- <div x-show="sidebarOpen" @click="sidebarOpen = false" class="fixed inset-0 bg-black/50 z-40 lg:hidden" style="display: none;"></div>
38
- <aside class="fixed top-14 bottom-0 left-0 z-40 w-64 transform bg-space-900 border-r border-space-border transition-all duration-300 shadow-2xl overflow-hidden lg:static lg:h-auto lg:shadow-none lg:flex-shrink-0 lg:translate-x-0" :class="{'translate-x-0': sidebarOpen, '-translate-x-full': !sidebarOpen}">
39
- <div class="w-64 flex flex-col h-full sidebar-content">
40
- <div class="sidebar-section-title">Workspace</div>
41
- <nav class="sidebar-nav">
42
- <a href="/dashboard" class="nav-item" :class="{'active': activeTab === 'dashboard'}"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.8" d="M4 4h6v6H4V4zm10 0h6v6h-6V4zM4 14h6v6H4v-6zm10 0h6v6h-6v-6z"/></svg><span>Dashboard</span></a>
43
- <a href="/account-management" class="nav-item" :class="{'active': activeTab === 'accounts'}"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.8" d="M16 20v-1a4 4 0 00-4-4H7a4 4 0 00-4 4v1m6-9a4 4 0 100-8 4 4 0 000 8zm6 1a3 3 0 100-6m2 15v-1a4 4 0 00-3-3.87"/></svg><span>Accounts</span></a>
44
- </nav>
45
- <div class="sidebar-section-title">System</div>
46
- <nav class="sidebar-nav">
47
- <a href="/logs" class="nav-item" :class="{'active': activeTab === 'logs'}"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.8" d="M4 5a2 2 0 012-2h8l4 4v12a2 2 0 01-2 2H6a2 2 0 01-2-2V5zm4 7h8m-8 4h6"/></svg><span>Logs</span></a>
48
- <a href="/client-api-keys" class="nav-item" :class="{'active': activeTab === 'client-api-keys'}"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.8" d="M15 7a5 5 0 11-9.6 2H3v4h3v3h3v-3h2.4A5 5 0 0115 7zm0 0a1 1 0 100 2 1 1 0 000-2z"/></svg><span>Client API Keys</span></a>
49
- <a href="/settings" class="nav-item" :class="{'active': activeTab === 'settings'}"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.8" d="M12 15.5a3.5 3.5 0 100-7 3.5 3.5 0 000 7zm7.4-3.5a7.4 7.4 0 00-.1-1.1l2-1.5-2-3.4-2.4 1a8 8 0 00-1.8-1L14.8 3h-4l-.3 2.8a8 8 0 00-1.8 1l-2.4-1-2 3.4 2 1.5A7.4 7.4 0 006.6 12c0 .4 0 .7.1 1.1l-2 1.5 2 3.4 2.4-1a8 8 0 001.8 1l.3 2.8h4l.3-2.8a8 8 0 001.8-1l2.4 1 2-3.4-2-1.5c.1-.4.1-.7.1-1.1z"/></svg><span>Settings</span></a>
50
- </nav>
51
- <div class="sidebar-footer"><span class="sidebar-status-dot"></span><span x-text="connectionStatus === 'connected' ? 'Proxy connected' : 'Proxy offline'"></span></div>
52
- </div>
53
- </aside>
54
- <main id="view-content" class="flex-1 overflow-auto bg-space-950 relative custom-scrollbar" aria-live="polite"></main>
55
- </div>
56
-
57
- <div x-cloak id="modal-content"></div>
58
- <script src="/js/app.js"></script>
59
- </body>
60
- </html>
1
+ <!DOCTYPE html>
2
+ <html lang="en" data-theme="codex" class="dark">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Claude Codex Proxy</title>
7
+ <link rel="icon" type="image/svg+xml" href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'><text y='.9em' font-size='90'>🚀</text></svg>">
8
+ <script src="https://cdn.jsdelivr.net/npm/alpinejs@3.x.x/dist/cdn.min.js" defer></script>
9
+ <link rel="stylesheet" href="/css/style.css">
10
+ </head>
11
+ <body class="bg-space-950 text-gray-300 font-sans antialiased min-h-screen selection:bg-neon-purple selection:text-white" x-data="app" x-init="init()">
12
+ <div x-cloak class="fixed top-4 right-4 z-[100] flex flex-col gap-2 pointer-events-none">
13
+ <template x-if="toast">
14
+ <div class="alert shadow-lg border backdrop-blur-md pointer-events-auto min-w-[300px]" :class="{
15
+ 'alert-info border-neon-cyan/20 bg-space-900/90 text-neon-cyan': toast.type === 'info',
16
+ 'alert-success border-neon-green/20 bg-space-900/90 text-neon-green': toast.type === 'success',
17
+ 'alert-error border-red-500/20 bg-space-900/90 text-red-400': toast.type === 'error',
18
+ 'alert-warning border-yellow-500/20 bg-space-900/90 text-yellow-400': toast.type === 'warning'
19
+ }"><span x-text="toast.message" class="font-mono text-sm"></span></div>
20
+ </template>
21
+ </div>
22
+
23
+ <div x-cloak class="h-14 border-b border-space-border flex items-center px-4 lg:px-6 justify-between bg-space-900/50 backdrop-blur-md z-50 relative" x-show="isAuthenticated">
24
+ <div class="flex items-center gap-3">
25
+ <button @click="sidebarOpen = !sidebarOpen" class="text-gray-400 hover:text-white focus:outline-none p-1 transition-colors lg:hidden" aria-label="Toggle navigation">☰</button>
26
+ <div class="w-8 h-8 rounded bg-gradient-to-br from-neon-purple to-blue-600 flex items-center justify-center text-white font-bold">CX</div>
27
+ <div class="flex flex-col"><span class="text-sm font-bold tracking-wide text-white">CODEX PROXY</span><span class="text-[10px] text-gray-500 font-mono tracking-wider" x-text="version ? 'CLAUDE PROXY SYSTEM v' + version : 'CLAUDE PROXY SYSTEM'"></span></div>
28
+ </div>
29
+ <div class="flex items-center gap-4">
30
+ <div class="flex items-center gap-2 px-3 py-1 rounded-full text-xs font-mono border" :class="connectionStatus === 'connected' ? 'bg-neon-green/10 border-neon-green/20 text-neon-green' : 'bg-red-500/10 border-red-500/20 text-red-500'"><span x-text="connectionStatus === 'connected' ? 'Online' : 'Offline'"></span></div>
31
+ <button type="button" class="btn btn-ghost btn-xs text-gray-400 hover:text-white" @click="refreshAccounts()" :disabled="loading">Refresh</button>
32
+ <button x-show="authRequired" type="button" class="btn btn-ghost btn-xs text-gray-400 hover:text-white" @click="logout()">Logout</button>
33
+ </div>
34
+ </div>
35
+
36
+ <div x-cloak x-show="isAuthenticated" class="flex h-[calc(100vh-56px)] relative">
37
+ <div x-show="sidebarOpen" @click="sidebarOpen = false" class="fixed inset-0 bg-black/50 z-40 lg:hidden" style="display: none;"></div>
38
+ <aside class="fixed top-14 bottom-0 left-0 z-40 w-64 transform bg-space-900 border-r border-space-border transition-all duration-300 shadow-2xl overflow-hidden lg:static lg:h-auto lg:shadow-none lg:flex-shrink-0 lg:translate-x-0" :class="{'translate-x-0': sidebarOpen, '-translate-x-full': !sidebarOpen}">
39
+ <div class="w-64 flex flex-col h-full sidebar-content">
40
+ <div class="sidebar-section-title">Workspace</div>
41
+ <nav class="sidebar-nav">
42
+ <a href="/dashboard" class="nav-item" :class="{'active': activeTab === 'dashboard'}"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.8" d="M4 4h6v6H4V4zm10 0h6v6h-6V4zM4 14h6v6H4v-6zm10 0h6v6h-6v-6z"/></svg><span>Dashboard</span></a>
43
+ <a href="/account-management" class="nav-item" :class="{'active': activeTab === 'accounts'}"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.8" d="M16 20v-1a4 4 0 00-4-4H7a4 4 0 00-4 4v1m6-9a4 4 0 100-8 4 4 0 000 8zm6 1a3 3 0 100-6m2 15v-1a4 4 0 00-3-3.87"/></svg><span>Accounts</span></a>
44
+ </nav>
45
+ <div class="sidebar-section-title">System</div>
46
+ <nav class="sidebar-nav">
47
+ <a href="/logs" class="nav-item" :class="{'active': activeTab === 'logs'}"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.8" d="M4 5a2 2 0 012-2h8l4 4v12a2 2 0 01-2 2H6a2 2 0 01-2-2V5zm4 7h8m-8 4h6"/></svg><span>Logs</span></a>
48
+ <a href="/client-api-keys" class="nav-item" :class="{'active': activeTab === 'client-api-keys'}"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.8" d="M15 7a5 5 0 11-9.6 2H3v4h3v3h3v-3h2.4A5 5 0 0115 7zm0 0a1 1 0 100 2 1 1 0 000-2z"/></svg><span>Client API Keys</span></a>
49
+ <a href="/settings" class="nav-item" :class="{'active': activeTab === 'settings'}"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.8" d="M12 15.5a3.5 3.5 0 100-7 3.5 3.5 0 000 7zm7.4-3.5a7.4 7.4 0 00-.1-1.1l2-1.5-2-3.4-2.4 1a8 8 0 00-1.8-1L14.8 3h-4l-.3 2.8a8 8 0 00-1.8 1l-2.4-1-2 3.4 2 1.5A7.4 7.4 0 006.6 12c0 .4 0 .7.1 1.1l-2 1.5 2 3.4 2.4-1a8 8 0 001.8 1l.3 2.8h4l.3-2.8a8 8 0 001.8-1l2.4 1 2-3.4-2-1.5c.1-.4.1-.7.1-1.1z"/></svg><span>Settings</span></a>
50
+ </nav>
51
+ <div class="sidebar-footer"><span class="sidebar-status-dot"></span><span x-text="connectionStatus === 'connected' ? 'Proxy connected' : 'Proxy offline'"></span></div>
52
+ </div>
53
+ </aside>
54
+ <main id="view-content" class="flex-1 overflow-auto bg-space-950 relative custom-scrollbar" aria-live="polite"></main>
55
+ </div>
56
+
57
+ <div x-cloak id="modal-content"></div>
58
+ <script src="/js/app.js"></script>
59
+ </body>
60
+ </html>
package/public/js/app.js CHANGED
@@ -11,7 +11,7 @@ document.addEventListener('alpine:init', () => {
11
11
  showAddModal: false, showDeleteModal: false, deleteTarget: '', showQuotaModalView: false, selectedAccount: null,
12
12
  oauthManualMode: false, oauthManualUrl: '', oauthManualVerifier: '', oauthManualCode: '',
13
13
  testPrompt: 'Say hello', testResponse: '', testing: false, configPath: '~/.claude-codex-proxy/accounts.json',
14
- serverUrl: window.location.origin, logs: [], logSearchQuery: '',
14
+ serverUrl: window.location.origin, logs: [], logSearchQuery: '', logPage: 1, logPageSize: 30, logTotal: 0, logTotalPages: 0, logLoading: false,
15
15
  logFilters: { INFO: true, SUCCESS: true, WARN: true, ERROR: true, DEBUG: false }, logEventSource: null,
16
16
 
17
17
  get isAuthenticated() { return !this.authRequired || Boolean(this.apiKey); },
@@ -111,6 +111,6 @@ document.addEventListener('alpine:init', () => {
111
111
  async createClientApiKey() { if (this.clientApiKeySaving) return; const weeklyLimitUsd = Number(this.clientApiKeyWeeklyLimitUsd); if (!Number.isFinite(weeklyLimitUsd) || weeklyLimitUsd < 0) { this.showToast('Weekly limit must be a non-negative USD amount.', 'error'); return; } this.clientApiKeySaving = true; const { ok, data } = await this.api('/settings/client-api-keys', { method: 'POST', body: JSON.stringify({ name: this.clientApiKeyName, remark: this.clientApiKeyRemark, weeklyLimitUsd }) }); this.clientApiKeySaving = false; if (ok && data?.clientApiKey?.key) { this.revealedClientApiKey = data.clientApiKey.key; this.clientApiKeyName = ''; this.clientApiKeyRemark = ''; this.clientApiKeyWeeklyLimitUsd = 50; this.showCreateClientApiKeyModal = false; await Promise.all([this.loadClientApiKeys(), this.loadClientProxyConfig()]); } else this.showToast(data?.error || 'Failed to create client API key', 'error'); },
112
112
  async loadClientProxyConfig() { const { ok, data } = await this.api('/claude/config/proxy', { method: 'POST' }); if (ok && data?.success && data?.env) this.clientProxyConfig = data; }, async copyClientText(text, successMessage) { if (!text) return; try { if (navigator.clipboard?.writeText && window.isSecureContext) await navigator.clipboard.writeText(text); else { const textarea = document.createElement('textarea'); textarea.value = text; textarea.setAttribute('readonly', ''); textarea.style.cssText = 'position:absolute;opacity:0;left:-999999px;top:-999999px'; document.body.appendChild(textarea); textarea.focus(); textarea.select(); const copied = document.execCommand('copy'); textarea.remove(); if (!copied) throw new Error('Clipboard copy was rejected'); } this.showToast(successMessage, 'success'); } catch { this.showToast('Copy failed. Select and copy the value manually.', 'error'); } }, copyClientApiKey() { return this.copyClientText(this.revealedClientApiKey, 'Client API key copied'); }, copyClientProxyCommands() { const commands = this.clientProxyConfig?.commands?.powershell; return Array.isArray(commands) ? this.copyClientText(commands.map(command => command.replace('<client-api-key>', this.revealedClientApiKey)).join('\n'), 'Claude Code configuration commands copied') : undefined; },
113
113
  async updateClientApiKey(clientApiKey) { if (this.clientApiKeySaving) return; const weeklyLimitUsd = Number(clientApiKey.weeklyLimitUsd); if (!Number.isFinite(weeklyLimitUsd) || weeklyLimitUsd < 0) { this.showToast('Weekly limit must be a non-negative USD amount.', 'error'); return; } this.clientApiKeySaving = true; const { ok, data } = await this.api(`/settings/client-api-keys/${encodeURIComponent(clientApiKey.id)}`, { method: 'PUT', body: JSON.stringify({ name: clientApiKey.name, remark: clientApiKey.remark, weeklyLimitUsd }) }); this.clientApiKeySaving = false; if (ok) await this.loadClientApiKeys(); else this.showToast(data?.error || 'Failed to update client API key', 'error'); }, async deleteClientApiKey(clientApiKey) { if (!confirm(`Delete the key for "${clientApiKey.name || clientApiKey.remark || 'this client'}"? Connected clients will lose access immediately.`)) return; this.clientApiKeySaving = true; const { ok, data } = await this.api(`/settings/client-api-keys/${encodeURIComponent(clientApiKey.id)}`, { method: 'DELETE' }); this.clientApiKeySaving = false; if (ok) await this.loadClientApiKeys(); else this.showToast(data?.error || 'Failed to delete client API key', 'error'); },
114
- showToast(message, type = 'success') { this.toast = { message, type }; setTimeout(() => { this.toast = null; }, 3000); }, startLogStream() { if (!this.isAuthenticated) return; this.logEventSource?.close(); const params = new URLSearchParams({ history: 'true' }); if (this.apiKey) params.set('api_key', this.apiKey); this.logEventSource = new EventSource(`/api/logs/stream?${params}`); this.logEventSource.onmessage = event => { try { this.logs.unshift(JSON.parse(event.data)); this.logs = this.logs.slice(0, 500); } catch {} }; this.logEventSource.onerror = () => setTimeout(() => this.startLogStream(), 3000); }, clearLogs() { this.logs = []; }, formatLogMessage(message) { return message?.replace(/^\[(\w+)\]\s*/, '') || ''; }, getLogDetails(message) { if (!message) return null; const details = {}; for (const [key, pattern] of [['model', /model=([^\s|,]+)/], ['account', /account=([^\s|,]+)/], ['stream', /stream=(true|false)/], ['messages', /messages=(\d+)/], ['tools', /tools=(\d+)/], ['tokens', /tokens=(\d+)/], ['duration', /(\d+)ms/], ['status', /status=(\d+)/], ['error', /error=([^\s|]+)/]]) { const match = message.match(pattern); if (match) details[key] = match[1]; } return Object.keys(details).length ? details : null; }
114
+ showToast(message, type = 'success') { this.toast = { message, type }; setTimeout(() => { this.toast = null; }, 3000); }, async loadLogs(page = 1) { if (this.logLoading) return; this.logLoading = true; const { ok, data } = await this.api(`/api/logs?page=${page}&pageSize=${this.logPageSize}`); this.logLoading = false; if (!ok || !Array.isArray(data?.logs)) { this.showToast(data?.error || 'Failed to load logs', 'error'); return; } this.logs = data.logs; this.logPage = data.page; this.logTotal = data.total; this.logTotalPages = data.totalPages; }, async changeLogPage(page) { if (page < 1 || page > this.logTotalPages || page === this.logPage) return; await this.loadLogs(page); }, startLogStream() { if (!this.isAuthenticated) return; this.loadLogs(); this.logEventSource?.close(); const params = new URLSearchParams(); if (this.apiKey) params.set('api_key', this.apiKey); this.logEventSource = new EventSource(`/api/logs/stream?${params}`); this.logEventSource.onmessage = event => { try { this.logTotal += 1; this.logTotalPages = Math.ceil(this.logTotal / this.logPageSize); if (this.logPage === 1) this.logs = [JSON.parse(event.data), ...this.logs].slice(0, this.logPageSize); } catch {} }; this.logEventSource.onerror = () => setTimeout(() => this.startLogStream(), 3000); }, clearLogs() { this.logs = []; this.logTotal = 0; this.logTotalPages = 0; }, formatLogMessage(message) { return message?.replace(/^\[(\w+)\]\s*/, '') || ''; }, getLogDetails(message) { if (!message) return null; const details = {}; for (const [key, pattern] of [['model', /model=([^\s|,]+)/], ['account', /account=([^\s|,]+)/], ['stream', /stream=(true|false)/], ['messages', /messages=(\d+)/], ['tools', /tools=(\d+)/], ['tokens', /tokens=(\d+)/], ['duration', /(\d+)ms/], ['status', /status=(\d+)/], ['error', /error=([^\s|]+)/]]) { const match = message.match(pattern); if (match) details[key] = match[1]; } return Object.keys(details).length ? details : null; }
115
115
  }));
116
116
  });
package/public/login.html CHANGED
@@ -1,32 +1,32 @@
1
- <!DOCTYPE html>
2
- <html lang="en" data-theme="codex" class="dark">
3
- <head>
4
- <meta charset="UTF-8">
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title>Sign in · Claude Codex Proxy</title>
7
- <script src="https://cdn.jsdelivr.net/npm/alpinejs@3.x.x/dist/cdn.min.js" defer></script>
8
- <link rel="stylesheet" href="/css/style.css">
9
- </head>
10
- <body class="bg-space-950 text-gray-300 font-sans antialiased min-h-screen" x-data="app" x-init="init()">
11
- <main x-cloak x-show="authChecked" class="min-h-screen flex items-center justify-center px-4">
12
- <div class="w-full max-w-md bg-space-900/70 border border-space-border rounded-2xl p-6 shadow-2xl backdrop-blur-md">
13
- <div class="flex items-center gap-3 mb-6">
14
- <div class="w-10 h-10 rounded bg-gradient-to-br from-neon-purple to-blue-600 flex items-center justify-center text-white font-bold">CX</div>
15
- <div>
16
- <h1 class="text-xl font-bold text-white">Access Required</h1>
17
- <p class="text-sm text-gray-500">Enter the server access key to open the management UI.</p>
18
- </div>
19
- </div>
20
- <form @submit.prevent="login" class="space-y-4">
21
- <label class="form-control w-full">
22
- <span class="label-text text-gray-400 mb-1">Access Key</span>
23
- <input type="password" x-model="loginApiKey" class="input input-bordered w-full bg-space-950 border-space-border text-white" placeholder="Enter access key" autocomplete="current-password" autofocus>
24
- </label>
25
- <p x-show="loginError" x-text="loginError" class="text-sm text-red-400"></p>
26
- <button type="submit" class="btn w-full bg-neon-purple hover:bg-purple-600 border-0 text-white">Unlock UI</button>
27
- </form>
28
- </div>
29
- </main>
30
- <script src="/js/app.js"></script>
31
- </body>
32
- </html>
1
+ <!DOCTYPE html>
2
+ <html lang="en" data-theme="codex" class="dark">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Sign in · Claude Codex Proxy</title>
7
+ <script src="https://cdn.jsdelivr.net/npm/alpinejs@3.x.x/dist/cdn.min.js" defer></script>
8
+ <link rel="stylesheet" href="/css/style.css">
9
+ </head>
10
+ <body class="bg-space-950 text-gray-300 font-sans antialiased min-h-screen" x-data="app" x-init="init()">
11
+ <main x-cloak x-show="authChecked" class="min-h-screen flex items-center justify-center px-4">
12
+ <div class="w-full max-w-md bg-space-900/70 border border-space-border rounded-2xl p-6 shadow-2xl backdrop-blur-md">
13
+ <div class="flex items-center gap-3 mb-6">
14
+ <div class="w-10 h-10 rounded bg-gradient-to-br from-neon-purple to-blue-600 flex items-center justify-center text-white font-bold">CX</div>
15
+ <div>
16
+ <h1 class="text-xl font-bold text-white">Access Required</h1>
17
+ <p class="text-sm text-gray-500">Enter the server access key to open the management UI.</p>
18
+ </div>
19
+ </div>
20
+ <form @submit.prevent="login" class="space-y-4">
21
+ <label class="form-control w-full">
22
+ <span class="label-text text-gray-400 mb-1">Access Key</span>
23
+ <input type="password" x-model="loginApiKey" class="input input-bordered w-full bg-space-950 border-space-border text-white" placeholder="Enter access key" autocomplete="current-password" autofocus>
24
+ </label>
25
+ <p x-show="loginError" x-text="loginError" class="text-sm text-red-400"></p>
26
+ <button type="submit" class="btn w-full bg-neon-purple hover:bg-purple-600 border-0 text-white">Unlock UI</button>
27
+ </form>
28
+ </div>
29
+ </main>
30
+ <script src="/js/app.js"></script>
31
+ </body>
32
+ </html>
@@ -8,7 +8,7 @@
8
8
  </div>
9
9
  <div class="flex items-center gap-3">
10
10
  <div class="text-[10px] font-mono text-gray-600">
11
- <span x-text="logs.length"></span> entries
11
+ <span x-text="logTotal"></span> entries
12
12
  </div>
13
13
  <button class="btn btn-xs btn-ghost text-gray-400 hover:text-white" @click="clearLogs()" title="Clear logs">
14
14
  <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
@@ -54,7 +54,7 @@
54
54
  </div>
55
55
 
56
56
  <div id="logs-container" class="flex-1 overflow-auto p-4 font-mono text-[11px] leading-relaxed bg-space-950 custom-scrollbar">
57
- <template x-for="(log, idx) in filteredLogs" :key="idx">
57
+ <template x-for="(log, idx) in filteredLogs" :key="`${log.timestamp}-${idx}`">
58
58
  <div class="flex gap-3 px-2 py-1 -mx-2 hover:bg-white/[0.03] transition-colors group border-b border-space-border/10">
59
59
  <span class="text-zinc-600 w-16 shrink-0 select-none group-hover:text-zinc-500 transition-colors"
60
60
  x-text="new Date(log.timestamp).toLocaleTimeString([], {hour12:false})"></span>
@@ -83,10 +83,17 @@
83
83
  </div>
84
84
  </div>
85
85
  </template>
86
- <div class="h-3 w-1.5 bg-zinc-600 animate-pulse mt-1 inline-block" x-show="filteredLogs.length === logs.length && !logSearchQuery"></div>
86
+ <div class="h-3 w-1.5 bg-zinc-600 animate-pulse mt-1 inline-block" x-show="logPage === 1 && filteredLogs.length === logs.length && !logSearchQuery"></div>
87
87
  <div x-show="filteredLogs.length === 0 && logs.length > 0" class="text-zinc-700 italic mt-8 text-center">
88
88
  No logs match filter
89
89
  </div>
90
90
  </div>
91
+ <div class="flex items-center justify-between gap-3 px-4 py-3 border-t border-space-border bg-space-900/60 text-xs font-mono">
92
+ <span class="text-gray-500" x-text="logTotalPages ? `Page ${logPage} of ${logTotalPages} · 30 per page` : 'No logs' "></span>
93
+ <div class="flex items-center gap-2">
94
+ <button class="btn btn-xs btn-ghost" :disabled="logPage <= 1 || logLoading" @click="changeLogPage(logPage - 1)">Previous</button>
95
+ <button class="btn btn-xs btn-ghost" :disabled="logPage >= logTotalPages || logLoading" @click="changeLogPage(logPage + 1)">Next</button>
96
+ </div>
97
+ </div>
91
98
  </div>
92
99
  </div>
package/src/deployment.js CHANGED
@@ -1,49 +1,49 @@
1
- /**
2
- * Deployment policy helpers shared by server, routes and auth middleware.
3
- */
4
-
5
- const VALID_DEPLOYMENT_MODES = new Set(['local', 'public']);
6
-
7
- /**
8
- * Returns the validated deployment mode, defaulting to local when unset.
9
- * @returns {'local'|'public'}
10
- */
11
- export function getDeploymentMode() {
12
- const mode = process.env.PROXY_DEPLOYMENT_MODE || 'local';
13
- if (!VALID_DEPLOYMENT_MODES.has(mode)) {
14
- throw new Error(`Invalid PROXY_DEPLOYMENT_MODE "${mode}". Expected "local" or "public".`);
15
- }
16
- return mode;
17
- }
18
-
19
- /**
20
- * Indicates whether the proxy is running in public deployment mode.
21
- * @returns {boolean}
22
- */
23
- export function isPublicDeployment() {
24
- return getDeploymentMode() === 'public';
25
- }
26
-
27
- /**
28
- * Returns the host address the main HTTP server should bind to.
29
- * @returns {string}
30
- */
31
- export function getServerHost() {
32
- if (process.env.HOST) {
33
- return process.env.HOST;
34
- }
35
- return isPublicDeployment() ? '0.0.0.0' : '127.0.0.1';
36
- }
37
-
38
- /**
39
- * Returns a display URL for logs and local helper responses.
40
- * @param {number|string} port
41
- * @returns {string}
42
- */
43
- export function getLocalBaseUrl(port) {
44
- const host = getServerHost();
45
- const displayHost = host === '0.0.0.0' || host === '::' ? 'localhost' : host;
46
- return `http://${displayHost}:${port}`;
47
- }
48
-
49
- export default { getDeploymentMode, isPublicDeployment, getServerHost, getLocalBaseUrl };
1
+ /**
2
+ * Deployment policy helpers shared by server, routes and auth middleware.
3
+ */
4
+
5
+ const VALID_DEPLOYMENT_MODES = new Set(['local', 'public']);
6
+
7
+ /**
8
+ * Returns the validated deployment mode, defaulting to local when unset.
9
+ * @returns {'local'|'public'}
10
+ */
11
+ export function getDeploymentMode() {
12
+ const mode = process.env.PROXY_DEPLOYMENT_MODE || 'local';
13
+ if (!VALID_DEPLOYMENT_MODES.has(mode)) {
14
+ throw new Error(`Invalid PROXY_DEPLOYMENT_MODE "${mode}". Expected "local" or "public".`);
15
+ }
16
+ return mode;
17
+ }
18
+
19
+ /**
20
+ * Indicates whether the proxy is running in public deployment mode.
21
+ * @returns {boolean}
22
+ */
23
+ export function isPublicDeployment() {
24
+ return getDeploymentMode() === 'public';
25
+ }
26
+
27
+ /**
28
+ * Returns the host address the main HTTP server should bind to.
29
+ * @returns {string}
30
+ */
31
+ export function getServerHost() {
32
+ if (process.env.HOST) {
33
+ return process.env.HOST;
34
+ }
35
+ return isPublicDeployment() ? '0.0.0.0' : '127.0.0.1';
36
+ }
37
+
38
+ /**
39
+ * Returns a display URL for logs and local helper responses.
40
+ * @param {number|string} port
41
+ * @returns {string}
42
+ */
43
+ export function getLocalBaseUrl(port) {
44
+ const host = getServerHost();
45
+ const displayHost = host === '0.0.0.0' || host === '::' ? 'localhost' : host;
46
+ return `http://${displayHost}:${port}`;
47
+ }
48
+
49
+ export default { getDeploymentMode, isPublicDeployment, getServerHost, getLocalBaseUrl };
@@ -58,17 +58,26 @@ export async function handleSetProxyMode(req, res, { port }) {
58
58
  try {
59
59
  const proxyUrl = getProxyConfigBaseUrl(req, port);
60
60
  const apiKeyPlaceholder = '<client-api-key>';
61
+ const clearEnvironmentVariables = [
62
+ 'ANTHROPIC_DEFAULT_HAIKU_MODEL',
63
+ 'ANTHROPIC_DEFAULT_OPUS_MODEL',
64
+ 'ANTHROPIC_DEFAULT_SONNET_MODEL',
65
+ 'ANTHROPIC_MODEL'
66
+ ];
67
+ const configureCommands = [
68
+ `cc config set env.ANTHROPIC_BASE_URL ${proxyUrl}`,
69
+ `cc config set env.ANTHROPIC_AUTH_TOKEN ${apiKeyPlaceholder}`,
70
+ `cc config set env.ANTHROPIC_API_KEY ${apiKeyPlaceholder}`,
71
+ 'cc config set env.CLAUDE_CODE_AUTO_COMPACT_WINDOW 258000'
72
+ ];
73
+ const clearCommands = clearEnvironmentVariables.map(variable => `cc config unset env.${variable}`);
61
74
  const commands = {
62
- bash: [
63
- `cc config set env.ANTHROPIC_BASE_URL ${proxyUrl}`,
64
- `cc config set env.ANTHROPIC_API_KEY ${apiKeyPlaceholder}`,
65
- 'cc config set env.CLAUDE_CODE_AUTO_COMPACT_WINDOW 258000'
66
- ],
67
- powershell: [
68
- `cc config set env.ANTHROPIC_BASE_URL ${proxyUrl}`,
69
- `cc config set env.ANTHROPIC_API_KEY ${apiKeyPlaceholder}`,
70
- 'cc config set env.CLAUDE_CODE_AUTO_COMPACT_WINDOW 258000'
71
- ]
75
+ bash: configureCommands,
76
+ powershell: configureCommands,
77
+ clear: {
78
+ bash: clearCommands,
79
+ powershell: clearCommands
80
+ }
72
81
  };
73
82
 
74
83
  res.json({
@@ -1,25 +1,25 @@
1
- import { DEFAULT_CLIENT_KEY_WEEKLY_LIMIT_USD } from '../server-settings.js';
2
-
3
- /**
4
- * Returns the authenticated client key's weekly quota using Claude Code's
5
- * utilization response shape, so the terminal can consume it directly.
6
- */
7
- export function handleGetClientQuota(req, res) {
8
- const quota = req.clientApiKeyQuota;
9
- const weeklyLimitUsd = quota?.weeklyLimitUsd ?? DEFAULT_CLIENT_KEY_WEEKLY_LIMIT_USD;
10
- const utilization = quota && weeklyLimitUsd > 0
11
- ? Math.min(100, Math.max(0, (quota.consumedUsd / weeklyLimitUsd) * 100))
12
- : null;
13
-
14
- return res.json({
15
- five_hour: null,
16
- seven_day: quota ? {
17
- utilization,
18
- resets_at: quota.nextPeriodStart
19
- } : null,
20
- seven_day_oauth_apps: null,
21
- seven_day_opus: null,
22
- seven_day_sonnet: null,
23
- extra_usage: null
24
- });
25
- }
1
+ import { DEFAULT_CLIENT_KEY_WEEKLY_LIMIT_USD } from '../server-settings.js';
2
+
3
+ /**
4
+ * Returns the authenticated client key's weekly quota using Claude Code's
5
+ * utilization response shape, so the terminal can consume it directly.
6
+ */
7
+ export function handleGetClientQuota(req, res) {
8
+ const quota = req.clientApiKeyQuota;
9
+ const weeklyLimitUsd = quota?.weeklyLimitUsd ?? DEFAULT_CLIENT_KEY_WEEKLY_LIMIT_USD;
10
+ const utilization = quota && weeklyLimitUsd > 0
11
+ ? Math.min(100, Math.max(0, (quota.consumedUsd / weeklyLimitUsd) * 100))
12
+ : null;
13
+
14
+ return res.json({
15
+ five_hour: null,
16
+ seven_day: quota ? {
17
+ utilization,
18
+ resets_at: quota.nextPeriodStart
19
+ } : null,
20
+ seven_day_oauth_apps: null,
21
+ seven_day_opus: null,
22
+ seven_day_sonnet: null,
23
+ extra_usage: null
24
+ });
25
+ }
@@ -7,12 +7,31 @@
7
7
 
8
8
  import { logger } from '../utils/logger.js';
9
9
 
10
+ const LOGS_PER_PAGE = 30;
11
+ const MAX_PAGE_SIZE = 100;
12
+
13
+ function parsePositiveInteger(value, fallback, maximum = Number.MAX_SAFE_INTEGER) {
14
+ const parsed = Number.parseInt(value, 10);
15
+ return Number.isInteger(parsed) && parsed > 0 ? Math.min(parsed, maximum) : fallback;
16
+ }
17
+
10
18
  /**
11
19
  * GET /api/logs
12
- * Returns the in-memory log history as JSON.
20
+ * Returns a newest-first page of in-memory log history.
13
21
  */
14
22
  export function handleGetLogs(req, res) {
15
- res.json({ status: 'ok', logs: logger.getHistory() });
23
+ const page = parsePositiveInteger(req.query.page, 1);
24
+ const pageSize = parsePositiveInteger(req.query.pageSize, LOGS_PER_PAGE, MAX_PAGE_SIZE);
25
+ const { logs, total } = logger.getHistoryPage(page, pageSize);
26
+
27
+ res.json({
28
+ status: 'ok',
29
+ logs,
30
+ page,
31
+ pageSize,
32
+ total,
33
+ totalPages: Math.ceil(total / pageSize)
34
+ });
16
35
  }
17
36
 
18
37
  /**
@@ -40,6 +40,24 @@ class Logger extends EventEmitter {
40
40
  return [...this.history];
41
41
  }
42
42
 
43
+ /**
44
+ * Returns a newest-first page of in-memory log entries.
45
+ *
46
+ * @param {number} page - One-based page number.
47
+ * @param {number} pageSize - Maximum number of entries per page.
48
+ * @returns {{ logs: object[], total: number }} Requested page and total entry count.
49
+ */
50
+ getHistoryPage(page, pageSize) {
51
+ const total = this.history.length;
52
+ const end = Math.max(0, total - (page - 1) * pageSize);
53
+ const start = Math.max(0, end - pageSize);
54
+
55
+ return {
56
+ logs: this.history.slice(start, end).reverse(),
57
+ total
58
+ };
59
+ }
60
+
43
61
  clear() {
44
62
  this.history = [];
45
63
  }