claude-codex-proxy 1.0.5-beta.2 → 1.0.5-beta.20

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.
Files changed (42) hide show
  1. package/README.md +0 -272
  2. package/bin/cli.js +37 -2
  3. package/package.json +1 -1
  4. package/public/css/style.css +210 -9
  5. package/public/index.html +32 -926
  6. package/public/js/app.js +168 -737
  7. package/public/login.html +32 -0
  8. package/public/views/accounts-modals.html +218 -0
  9. package/public/views/accounts.html +202 -0
  10. package/public/views/client-api-keys-modals.html +55 -0
  11. package/public/views/client-api-keys.html +69 -0
  12. package/public/views/dashboard.html +90 -0
  13. package/public/views/empty.html +0 -0
  14. package/public/views/logs.html +99 -0
  15. package/public/views/settings.html +123 -0
  16. package/src/account-manager.js +34 -3
  17. package/src/account-rotation/rate-limits.js +4 -26
  18. package/src/account-rotation/strategies/base-strategy.js +4 -0
  19. package/src/account-rotation/strategies/sticky-strategy.js +7 -0
  20. package/src/admin-path.js +33 -0
  21. package/src/claude-config.js +0 -18
  22. package/src/client-key-usage.js +125 -0
  23. package/src/deployment.js +49 -49
  24. package/src/direct-api.js +16 -13
  25. package/src/format-converter.js +77 -48
  26. package/src/index.js +13 -4
  27. package/src/middleware/auth.js +46 -11
  28. package/src/middleware/credentials.js +13 -3
  29. package/src/model-api.js +60 -0
  30. package/src/model-pricing.js +127 -0
  31. package/src/response-streamer.js +17 -7
  32. package/src/routes/accounts-route.js +106 -2
  33. package/src/routes/api-routes.js +61 -35
  34. package/src/routes/chat-route.js +25 -4
  35. package/src/routes/claude-config-route.js +22 -15
  36. package/src/routes/client-quota-route.js +25 -0
  37. package/src/routes/logs-route.js +21 -2
  38. package/src/routes/messages-route.js +45 -14
  39. package/src/routes/settings-route.js +36 -5
  40. package/src/server-settings.js +18 -2
  41. package/src/utils/logger.js +18 -0
  42. package/src/utils/proxy-logging.js +5 -0
@@ -0,0 +1,90 @@
1
+ <div x-show="activeTab === 'dashboard'" x-transition class="view-container">
2
+ <div class="flex items-center justify-between gap-4 mb-6">
3
+ <div class="flex flex-wrap items-center gap-4">
4
+ <h1 class="text-2xl font-bold text-white tracking-tight">Dashboard</h1>
5
+ <div class="flex items-center h-6 px-3 rounded-full bg-space-800/80 border border-space-border/50 shadow-sm backdrop-blur-sm">
6
+ <span class="text-[10px] font-mono text-gray-400 uppercase tracking-wider">CHATGPT PROXY SYSTEM</span>
7
+ </div>
8
+ </div>
9
+ <div class="flex items-center gap-2 px-2.5 py-1.5 rounded-lg bg-space-900/60 border border-space-border/40 whitespace-nowrap flex-shrink-0">
10
+ <div class="relative flex items-center justify-center">
11
+ <span class="absolute w-1.5 h-1.5 bg-neon-green rounded-full animate-ping opacity-75"></span>
12
+ <span class="relative w-1.5 h-1.5 bg-neon-green rounded-full"></span>
13
+ </div>
14
+ <span class="text-[10px] font-mono text-gray-500 uppercase tracking-wider">Live</span>
15
+ <span class="text-gray-700">•</span>
16
+ <span class="text-[10px] font-mono text-gray-400 tabular-nums" x-text="currentTime"></span>
17
+ </div>
18
+ </div>
19
+
20
+ <div class="grid grid-cols-2 sm:grid-cols-4 gap-2 lg:gap-3 mb-6">
21
+ <div class="stat bg-space-900/40 border border-space-border/30 rounded-xl p-3 lg:p-4 hover:border-cyan-500/30 hover:bg-cyan-500/5 transition-all duration-300 group relative cursor-pointer min-w-0">
22
+ <div class="absolute top-3 right-3 text-gray-700/40 group-hover:text-cyan-400/70 transition-colors">
23
+ <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" class="w-4 h-4 sm:w-5 sm:h-5 stroke-current">
24
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17 20h5v-2a3 3 0 00-5.356-1.857M17 20H7m10 0v-2c0-.656-.126-1.283-.356-1.857M7 20H2v-2a3 3 0 015.356-1.857M7 20v-2c0-.656.126-1.283.356-1.857m0 0a5.002 5.002 0 019.288 0M15 7a3 3 0 11-6 0 3 3 0 016 0zm6 3a2 2 0 11-4 0 2 2 0 014 0z"></path>
25
+ </svg>
26
+ </div>
27
+ <div class="stat-value text-white font-mono text-2xl lg:text-3xl font-bold mb-1 truncate" x-text="stats.total"></div>
28
+ <div class="stat-title text-gray-500 font-mono text-[10px] uppercase tracking-wider truncate">Total Accounts</div>
29
+ <div class="stat-desc text-cyan-400/60 text-[10px] truncate">Linked accounts</div>
30
+ </div>
31
+
32
+ <div class="stat bg-space-900/40 border border-space-border/30 rounded-xl p-3 lg:p-4 hover:border-green-500/30 hover:bg-green-500/5 transition-all duration-300 group relative cursor-pointer min-w-0">
33
+ <div class="absolute top-3 right-3 text-gray-700/40 group-hover:text-green-400/70 transition-colors">
34
+ <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" class="w-4 h-4 sm:w-5 sm:h-5 stroke-current">
35
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"></path>
36
+ </svg>
37
+ </div>
38
+ <div class="stat-value text-white font-mono text-2xl lg:text-3xl font-bold mb-1 truncate" x-text="stats.active"></div>
39
+ <div class="stat-title text-gray-500 font-mono text-[10px] uppercase tracking-wider truncate">Active</div>
40
+ <div class="stat-desc text-green-400/60 text-[10px] truncate">Operational</div>
41
+ </div>
42
+
43
+ <div class="stat bg-space-900/40 border border-space-border/30 rounded-xl p-3 lg:p-4 hover:border-yellow-500/30 hover:bg-yellow-500/5 transition-all duration-300 group relative cursor-pointer min-w-0">
44
+ <div class="absolute top-3 right-3 text-gray-700/40 group-hover:text-yellow-400/70 transition-colors">
45
+ <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" class="w-4 h-4 sm:w-5 sm:h-5 stroke-current">
46
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"></path>
47
+ </svg>
48
+ </div>
49
+ <div class="stat-value text-white font-mono text-2xl lg:text-3xl font-bold mb-1 truncate" x-text="stats.expired"></div>
50
+ <div class="stat-title text-gray-500 font-mono text-[10px] uppercase tracking-wider truncate">Token Expired</div>
51
+ <div class="stat-desc text-yellow-400/60 text-[10px] truncate">Needs refresh</div>
52
+ </div>
53
+
54
+ <div class="stat bg-space-900/40 border border-space-border/30 rounded-xl p-3 lg:p-4 hover:border-purple-500/30 hover:bg-purple-500/5 transition-all duration-300 group relative cursor-pointer min-w-0">
55
+ <div class="absolute top-3 right-3 text-gray-700/40 group-hover:text-purple-400/70 transition-colors">
56
+ <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" class="w-4 h-4 sm:w-5 sm:h-5 stroke-current">
57
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 3v4M3 5h4M6 17v4m-2-2h4m5-16l2.286 6.857L21 12l-5.714 2.143L13 21l-2.286-6.857L5 12l5.714-2.143L13 3z"></path>
58
+ </svg>
59
+ </div>
60
+ <div class="stat-value text-white font-mono text-2xl lg:text-3xl font-bold mb-1 truncate" x-text="stats.planType"></div>
61
+ <div class="stat-title text-gray-500 font-mono text-[10px] uppercase tracking-wider truncate">Active Plan</div>
62
+ <div class="stat-desc text-purple-400/60 text-[10px] truncate">Current tier</div>
63
+ </div>
64
+ </div>
65
+
66
+ <div class="view-card">
67
+ <div class="flex items-center gap-2.5 mb-4">
68
+ <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" class="w-4 h-4 text-neon-purple">
69
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 10V3L4 14h7v7l9-11h-7z"></path>
70
+ </svg>
71
+ <h3 class="text-xs font-mono text-gray-400 uppercase tracking-widest">Quick Test</h3>
72
+ </div>
73
+ <div class="flex gap-3">
74
+ <input type="text" x-model="testPrompt" placeholder="Enter a test prompt..."
75
+ class="input flex-1 bg-space-800 border-space-border text-white font-mono text-sm">
76
+ <button class="btn bg-neon-purple hover:bg-purple-600 border-none text-white btn-sm gap-2"
77
+ @click="testChat()" :disabled="testing">
78
+ <svg class="w-4 h-4" :class="{'animate-spin': testing}" fill="none" stroke="currentColor" viewBox="0 0 24 24">
79
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M14.752 11.168l-3.197-2.132A1 1 0 0010 9.87v4.263a1 1 0 001.555.832l3.197-2.132a1 1 0 000-1.664z"></path>
80
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path>
81
+ </svg>
82
+ <span>Test</span>
83
+ </button>
84
+ </div>
85
+ <div x-show="testResponse" class="mt-4 p-3 rounded-lg bg-space-800/50 border border-space-border/30">
86
+ <pre class="text-xs font-mono text-gray-300 whitespace-pre-wrap" x-text="testResponse"></pre>
87
+ </div>
88
+ </div>
89
+
90
+ </div>
File without changes
@@ -0,0 +1,99 @@
1
+ <div x-show="activeTab === 'logs'" x-transition class="view-container h-full flex flex-col">
2
+ <div class="flex items-center justify-between gap-4 mb-6">
3
+ <div class="flex flex-wrap items-center gap-4">
4
+ <h1 class="text-2xl font-bold text-white tracking-tight">Server Logs</h1>
5
+ <div class="flex items-center h-6 px-3 rounded-full bg-space-800/80 border border-space-border/50 shadow-sm backdrop-blur-sm">
6
+ <span class="text-[10px] font-mono text-gray-400 uppercase tracking-wider">Real-time log stream</span>
7
+ </div>
8
+ </div>
9
+ <div class="flex items-center gap-3">
10
+ <div class="text-[10px] font-mono text-gray-600">
11
+ <span x-text="logTotal"></span> entries
12
+ </div>
13
+ <button class="btn btn-xs btn-ghost text-gray-400 hover:text-white" @click="clearLogs()" title="Clear logs">
14
+ <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
15
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16" />
16
+ </svg>
17
+ </button>
18
+ </div>
19
+ </div>
20
+
21
+ <div class="view-card !p-0 flex flex-col flex-1 min-h-0">
22
+ <div class="bg-space-900 flex items-center p-2 px-4 border-b border-space-border gap-4">
23
+ <div class="flex gap-2">
24
+ <div class="w-3 h-3 rounded-full bg-red-500/20 border border-red-500/50"></div>
25
+ <div class="w-3 h-3 rounded-full bg-yellow-500/20 border border-yellow-500/50"></div>
26
+ <div class="w-3 h-3 rounded-full bg-green-500/20 border border-green-500/50"></div>
27
+ </div>
28
+ <span class="text-xs font-mono text-gray-500 hidden sm:inline-block">~/logs</span>
29
+
30
+ <div class="flex-1 flex items-center justify-center gap-4">
31
+ <div class="relative w-full max-w-xs">
32
+ <input type="text" x-model="logSearchQuery" placeholder="Search logs..."
33
+ class="w-full h-7 bg-space-950 border border-space-border rounded text-xs font-mono pl-7 pr-2 focus:border-neon-purple focus:outline-none transition-colors placeholder-gray-700 text-gray-300">
34
+ <svg class="w-3 h-3 absolute left-2.5 top-2 text-gray-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
35
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z" />
36
+ </svg>
37
+ </div>
38
+
39
+ <div class="hidden md:flex gap-3 text-[10px] font-mono font-bold uppercase select-none">
40
+ <label class="flex items-center gap-1.5 cursor-pointer text-blue-400 opacity-50 hover:opacity-100 transition-opacity" :class="{'opacity-100': logFilters.INFO}">
41
+ <input type="checkbox" class="checkbox checkbox-xs rounded-[2px] w-3 h-3" x-model="logFilters.INFO"> INFO
42
+ </label>
43
+ <label class="flex items-center gap-1.5 cursor-pointer text-green-400 opacity-50 hover:opacity-100 transition-opacity" :class="{'opacity-100': logFilters.SUCCESS}">
44
+ <input type="checkbox" class="checkbox checkbox-xs rounded-[2px] w-3 h-3" x-model="logFilters.SUCCESS"> SUCCESS
45
+ </label>
46
+ <label class="flex items-center gap-1.5 cursor-pointer text-yellow-400 opacity-50 hover:opacity-100 transition-opacity" :class="{'opacity-100': logFilters.WARN}">
47
+ <input type="checkbox" class="checkbox checkbox-xs rounded-[2px] w-3 h-3" x-model="logFilters.WARN"> WARN
48
+ </label>
49
+ <label class="flex items-center gap-1.5 cursor-pointer text-red-500 opacity-50 hover:opacity-100 transition-opacity" :class="{'opacity-100': logFilters.ERROR}">
50
+ <input type="checkbox" class="checkbox checkbox-xs rounded-[2px] w-3 h-3" x-model="logFilters.ERROR"> ERROR
51
+ </label>
52
+ </div>
53
+ </div>
54
+ </div>
55
+
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="`${log.timestamp}-${idx}`">
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
+ <span class="text-zinc-600 w-16 shrink-0 select-none group-hover:text-zinc-500 transition-colors"
60
+ x-text="new Date(log.timestamp).toLocaleTimeString([], {hour12:false})"></span>
61
+ <div class="w-16 shrink-0 flex items-center">
62
+ <span class="px-1.5 py-0.5 rounded-[2px] text-[10px] font-bold uppercase tracking-wider leading-none border"
63
+ :class="{
64
+ 'bg-blue-500/10 text-blue-400 border-blue-500/20': log.level === 'INFO',
65
+ 'bg-yellow-500/10 text-yellow-400 border-yellow-500/20': log.level === 'WARN',
66
+ 'bg-red-500/10 text-red-500 border-red-500/20': log.level === 'ERROR',
67
+ 'bg-emerald-500/10 text-emerald-400 border-emerald-500/20': log.level === 'SUCCESS',
68
+ 'bg-purple-500/10 text-purple-400 border-purple-500/20': log.level === 'DEBUG'
69
+ }" x-text="log.level"></span>
70
+ </div>
71
+ <div class="flex-1 flex flex-col gap-0.5 min-w-0">
72
+ <span class="text-zinc-200 break-all group-hover:text-white transition-colors"
73
+ x-text="formatLogMessage(log.message)"></span>
74
+ <template x-if="getLogDetails(log.message)">
75
+ <div class="flex flex-wrap gap-2 text-[10px] text-zinc-500 mt-0.5">
76
+ <template x-for="(detail, key) in getLogDetails(log.message)" :key="key">
77
+ <span class="px-1.5 py-0.5 bg-space-800/50 rounded border border-space-border/30">
78
+ <span class="text-zinc-600" x-text="key"></span>=<span class="text-zinc-400" x-text="detail"></span>
79
+ </span>
80
+ </template>
81
+ </div>
82
+ </template>
83
+ </div>
84
+ </div>
85
+ </template>
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
+ <div x-show="filteredLogs.length === 0 && logs.length > 0" class="text-zinc-700 italic mt-8 text-center">
88
+ No logs match filter
89
+ </div>
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>
98
+ </div>
99
+ </div>
@@ -0,0 +1,123 @@
1
+ <div x-show="activeTab === 'settings'" x-transition class="view-container">
2
+ <div class="flex items-center justify-between gap-4 mb-6">
3
+ <div class="flex flex-wrap items-center gap-4">
4
+ <h1 class="text-2xl font-bold text-white tracking-tight">Settings</h1>
5
+ <div class="flex items-center h-6 px-3 rounded-full bg-space-800/80 border border-space-border/50 shadow-sm backdrop-blur-sm">
6
+ <span class="text-[10px] font-mono text-gray-400 uppercase tracking-wider">Server configuration</span>
7
+ </div>
8
+ </div>
9
+ </div>
10
+
11
+ <div class="view-card">
12
+ <div class="flex items-center gap-2.5 mb-4">
13
+ <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" class="w-4 h-4 text-neon-cyan">
14
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"></path>
15
+ </svg>
16
+ <h3 class="text-xs font-mono text-gray-400 uppercase tracking-widest">Server Info</h3>
17
+ </div>
18
+ <div class="space-y-3">
19
+ <div class="flex items-center justify-between py-2 border-b border-space-border/30">
20
+ <span class="text-sm text-gray-400">Server URL</span>
21
+ <span class="font-mono text-sm text-white" x-text="serverUrl"></span>
22
+ </div>
23
+ <div class="flex items-center justify-between py-2 border-b border-space-border/30">
24
+ <span class="text-sm text-gray-400">Config Path</span>
25
+ <span class="font-mono text-sm text-white" x-text="configPath"></span>
26
+ </div>
27
+ <div class="flex items-center justify-between py-2">
28
+ <span class="text-sm text-gray-400">Auto Token Refresh</span>
29
+ <span class="text-xs font-mono text-neon-green">Every 55 minutes</span>
30
+ </div>
31
+ </div>
32
+ </div>
33
+
34
+ <div class="view-card mt-6">
35
+ <div class="flex items-center gap-2.5 mb-4">
36
+ <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" class="w-4 h-4 text-yellow-400">
37
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"></path>
38
+ </svg>
39
+ <h3 class="text-xs font-mono text-gray-400 uppercase tracking-widest">Raw Proxy Payload Logs</h3>
40
+ </div>
41
+ <div class="flex flex-wrap items-center justify-between gap-4">
42
+ <div>
43
+ <div class="text-sm text-gray-300">Capture raw request/response payloads</div>
44
+ <div class="text-xs text-gray-500 font-mono">Logs Claude Code requests, OpenAI/Codex upstream requests, completed responses, and upstream errors. May include prompts and tool results.</div>
45
+ </div>
46
+ <label class="flex items-center gap-3 cursor-pointer select-none">
47
+ <span class="text-xs font-mono" :class="logRawProxyPayloads ? 'text-yellow-400' : 'text-gray-500'" x-text="logRawProxyPayloads ? 'ENABLED' : 'DISABLED'"></span>
48
+ <input type="checkbox" class="toggle toggle-warning" :checked="logRawProxyPayloads" @change="setRawProxyLogs($event.target.checked)" :disabled="rawProxyLogsSaving">
49
+ </label>
50
+ </div>
51
+ </div>
52
+
53
+ <div class="view-card mt-6">
54
+ <div class="flex flex-wrap items-center justify-between gap-4 mb-4">
55
+ <div class="flex items-center gap-2.5">
56
+ <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" class="w-4 h-4 text-neon-cyan">
57
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 7h5l2 3h11M3 17h5l2-3h11M14 4l3 3-3 3M14 20l3-3-3-3"></path>
58
+ </svg>
59
+ <h3 class="text-xs font-mono text-gray-400 uppercase tracking-widest">Model Mapping</h3>
60
+ </div>
61
+ <div class="flex flex-wrap items-center gap-2">
62
+ <button class="btn btn-xs btn-outline text-gray-400" @click="resetModelMapSetting()" :disabled="modelMapSaving">Reset Defaults</button>
63
+ <button class="btn btn-xs bg-neon-purple hover:bg-purple-600 border-none text-white" @click="saveModelMapSetting()" :disabled="modelMapSaving">Save Mapping</button>
64
+ </div>
65
+ </div>
66
+
67
+ <template x-if="modelMapLoading">
68
+ <div class="text-xs text-gray-500 font-mono">Loading model mapping...</div>
69
+ </template>
70
+
71
+ <div class="grid gap-3">
72
+ <div class="grid grid-cols-1 md:grid-cols-[160px_1fr] gap-2 md:items-center">
73
+ <div>
74
+ <div class="text-sm text-gray-300">Claude Opus</div>
75
+ <div class="text-xs text-gray-500 font-mono">opus</div>
76
+ </div>
77
+ <input type="text" x-model="modelMappings.opus" placeholder="gpt-5.5"
78
+ class="input bg-space-800 border-space-border text-white font-mono text-sm">
79
+ </div>
80
+
81
+ <div class="grid grid-cols-1 md:grid-cols-[160px_1fr] gap-2 md:items-center">
82
+ <div>
83
+ <div class="text-sm text-gray-300">Claude Sonnet</div>
84
+ <div class="text-xs text-gray-500 font-mono">sonnet</div>
85
+ </div>
86
+ <input type="text" x-model="modelMappings.sonnet" placeholder="gpt-5.5"
87
+ class="input bg-space-800 border-space-border text-white font-mono text-sm">
88
+ </div>
89
+
90
+ <div class="grid grid-cols-1 md:grid-cols-[160px_1fr] gap-2 md:items-center">
91
+ <div>
92
+ <div class="text-sm text-gray-300">Claude Haiku</div>
93
+ <div class="text-xs text-gray-500 font-mono">haiku</div>
94
+ </div>
95
+ <input type="text" x-model="modelMappings.haiku" placeholder="gpt-5.4-mini"
96
+ class="input bg-space-800 border-space-border text-white font-mono text-sm">
97
+ </div>
98
+
99
+ <div class="text-xs text-gray-500 font-mono">Map each Claude family to a GPT/Codex model available to your ChatGPT account.</div>
100
+ </div>
101
+ </div>
102
+
103
+ <div class="view-card mt-6">
104
+ <div class="flex items-center gap-2.5 mb-4">
105
+ <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" class="w-4 h-4 text-neon-purple">
106
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 7h12m0 0l-4-4m4 4l-4 4m0 6H4m0 0l4 4m-4-4l4-4"></path>
107
+ </svg>
108
+ <h3 class="text-xs font-mono text-gray-400 uppercase tracking-widest">Account Selection Strategy</h3>
109
+ </div>
110
+ <div class="flex flex-wrap items-center justify-between gap-4">
111
+ <div>
112
+ <div class="text-sm text-gray-300">Strategy</div>
113
+ <div class="text-xs text-gray-500 font-mono">How accounts are selected when rate-limited</div>
114
+ </div>
115
+ <div class="inline-flex items-center gap-2">
116
+ <button class="btn btn-xs" :class="accountStrategy === 'sticky' ? 'bg-neon-purple text-white' : 'btn-outline text-gray-400'"
117
+ @click="setAccountStrategy('sticky')" :disabled="strategySaving">Sticky</button>
118
+ <button class="btn btn-xs" :class="accountStrategy === 'round-robin' ? 'bg-neon-purple text-white' : 'btn-outline text-gray-400'"
119
+ @click="setAccountStrategy('round-robin')" :disabled="strategySaving">Round-Robin</button>
120
+ </div>
121
+ </div>
122
+ </div>
123
+ </div>
@@ -98,6 +98,25 @@ function getActiveAccount() {
98
98
  return data.accounts.find(a => a.email === data.activeAccount) || null;
99
99
  }
100
100
 
101
+ function isAccountExpired(account, now = Date.now()) {
102
+ if (!account?.accountExpiresAt) return false;
103
+ const expiresAt = Date.parse(account.accountExpiresAt);
104
+ return Number.isFinite(expiresAt) && expiresAt <= now;
105
+ }
106
+
107
+ function updateAccountExpiration(email, accountExpiresAt) {
108
+ const data = loadAccounts();
109
+ const account = data.accounts.find(a => a.email === email);
110
+
111
+ if (!account) {
112
+ return { success: false, message: `Account not found: ${email}` };
113
+ }
114
+
115
+ account.accountExpiresAt = accountExpiresAt;
116
+ saveAccounts(data);
117
+ return { success: true, message: `Account expiration updated: ${email}` };
118
+ }
119
+
101
120
  function updateAccountAuth(account) {
102
121
  if (!account) return;
103
122
 
@@ -131,11 +150,15 @@ function updateAccountAuth(account) {
131
150
  function setActiveAccount(email) {
132
151
  const data = loadAccounts();
133
152
  const account = data.accounts.find(a => a.email === email);
134
-
153
+
135
154
  if (!account) {
136
155
  return { success: false, message: `Account not found: ${email}` };
137
156
  }
138
-
157
+
158
+ if (isAccountExpired(account)) {
159
+ return { success: false, message: `Account has expired: ${email}` };
160
+ }
161
+
139
162
  data.activeAccount = email;
140
163
  saveAccounts(data);
141
164
 
@@ -190,6 +213,8 @@ function listAccounts() {
190
213
  lastUsed: account.lastUsed,
191
214
  isActive: account.email === data.activeAccount,
192
215
  tokenExpired: info?.expiresAt ? info.expiresAt < Date.now() : false,
216
+ accountExpiresAt: account.accountExpiresAt || null,
217
+ accountExpired: isAccountExpired(account),
193
218
  quota: account.quota || null
194
219
  };
195
220
  });
@@ -476,7 +501,7 @@ function importFromCodex() {
476
501
 
477
502
  const existingIndex = data.accounts.findIndex(a => a.email === newAccount.email);
478
503
  if (existingIndex >= 0) {
479
- data.accounts[existingIndex] = newAccount;
504
+ data.accounts[existingIndex] = { ...data.accounts[existingIndex], ...newAccount };
480
505
  } else {
481
506
  data.accounts.push(newAccount);
482
507
  }
@@ -507,6 +532,8 @@ function getStatus() {
507
532
  isActive: a.email === data.activeAccount,
508
533
  quota: a.quota || null,
509
534
  tokenExpired: info?.expiresAt ? info.expiresAt < Date.now() : false,
535
+ accountExpiresAt: a.accountExpiresAt || null,
536
+ accountExpired: isAccountExpired(a),
510
537
  lastUsed: a.lastUsed
511
538
  };
512
539
  });
@@ -548,6 +575,8 @@ export {
548
575
  ensureAccountsPersist,
549
576
  updateAccountQuota,
550
577
  getAccountQuota,
578
+ updateAccountExpiration,
579
+ isAccountExpired,
551
580
  startAutoRefresh,
552
581
  stopAutoRefresh,
553
582
  isTokenExpiredOrExpiringSoon,
@@ -574,6 +603,8 @@ export default {
574
603
  ensureAccountsPersist,
575
604
  updateAccountQuota,
576
605
  getAccountQuota,
606
+ updateAccountExpiration,
607
+ isAccountExpired,
577
608
  startAutoRefresh,
578
609
  stopAutoRefresh,
579
610
  isTokenExpiredOrExpiringSoon,
@@ -33,6 +33,10 @@ export function getAvailableAccounts(accounts, modelId) {
33
33
  return accounts.filter(account => {
34
34
  if (account.isInvalid) return false;
35
35
  if (account.enabled === false) return false;
36
+ if (account.accountExpiresAt) {
37
+ const expiresAt = Date.parse(account.accountExpiresAt);
38
+ if (Number.isFinite(expiresAt) && expiresAt <= now) return false;
39
+ }
36
40
  if (isAccountCoolingDown(account)) return false;
37
41
  if (isQuotaLimitReached(account)) return false;
38
42
  const rateLimit = account.modelRateLimits?.[modelId];
@@ -117,18 +121,6 @@ export function clearExpiredLimits(accounts) {
117
121
  return clearedCount;
118
122
  }
119
123
 
120
- /**
121
- * Reset all rate limits for all accounts (optimistic retry)
122
- * @param {Array} accounts - Array of account objects
123
- */
124
- export function resetAllRateLimits(accounts) {
125
- if (!accounts || accounts.length === 0) return;
126
- for (const account of accounts) {
127
- account.modelRateLimits = {};
128
- }
129
- logger.info('Reset all rate limits for all accounts (optimistic retry)');
130
- }
131
-
132
124
  /**
133
125
  * Mark an account as rate-limited for a specific model
134
126
  * @param {Array} accounts - Array of account objects
@@ -235,20 +227,6 @@ export function getMinWaitTimeMs(accounts, modelId) {
235
227
  return minWait === Infinity ? 0 : minWait;
236
228
  }
237
229
 
238
- /**
239
- * Get rate limit info for a specific account and model
240
- * @param {Array} accounts - Array of account objects
241
- * @param {string} email - Account email
242
- * @param {string} modelId - Model identifier
243
- * @returns {Object|null} Rate limit info object or null
244
- */
245
- export function getRateLimitInfo(accounts, email, modelId) {
246
- const account = accounts?.find(a => a.email === email);
247
- if (!account) return null;
248
-
249
- return account.modelRateLimits?.[modelId] || null;
250
- }
251
-
252
230
  /**
253
231
  * Check if an account is currently cooling down
254
232
  * @param {Object} account - Account object
@@ -23,6 +23,10 @@ export class BaseStrategy {
23
23
  if (!account) return false;
24
24
  if (account.isInvalid) return false;
25
25
  if (account.enabled === false) return false;
26
+ if (account.accountExpiresAt) {
27
+ const expiresAt = Date.parse(account.accountExpiresAt);
28
+ if (Number.isFinite(expiresAt) && expiresAt <= Date.now()) return false;
29
+ }
26
30
  if (isAccountCoolingDown(account)) return false;
27
31
  if (isQuotaLimitReached(account)) return false;
28
32
 
@@ -56,6 +56,13 @@ export class StickyStrategy extends BaseStrategy {
56
56
  return { shouldWait: false, waitMs: 0 };
57
57
  }
58
58
 
59
+ if (account.accountExpiresAt) {
60
+ const expiresAt = Date.parse(account.accountExpiresAt);
61
+ if (Number.isFinite(expiresAt) && expiresAt <= Date.now()) {
62
+ return { shouldWait: false, waitMs: 0 };
63
+ }
64
+ }
65
+
59
66
  // Check model-specific rate limit
60
67
  if (modelId && account.modelRateLimits && account.modelRateLimits[modelId]) {
61
68
  const limit = account.modelRateLimits[modelId];
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Resolves the non-public prefix used for the management UI and its APIs.
3
+ */
4
+
5
+ const DEFAULT_ADMIN_PATH = '/admin';
6
+ const VALID_ADMIN_PATH = /^\/[A-Za-z0-9][A-Za-z0-9._-]*(?:\/[A-Za-z0-9][A-Za-z0-9._-]*)*$/;
7
+ const RESERVED_PATHS = ['/v1', '/health', '/claude'];
8
+
9
+ /**
10
+ * Returns the validated management UI path prefix.
11
+ * @returns {string}
12
+ */
13
+ export function getAdminPath() {
14
+ const adminPath = process.env.PROXY_ADMIN_PATH || DEFAULT_ADMIN_PATH;
15
+ if (!VALID_ADMIN_PATH.test(adminPath)) {
16
+ throw new Error(`Invalid PROXY_ADMIN_PATH "${adminPath}". Use an absolute path without trailing slashes, query strings, or ".." segments.`);
17
+ }
18
+
19
+ const overlapsReservedPath = RESERVED_PATHS.some((reservedPath) => (
20
+ adminPath === reservedPath
21
+ || adminPath.startsWith(`${reservedPath}/`)
22
+ || reservedPath.startsWith(`${adminPath}/`)
23
+ ));
24
+ if (overlapsReservedPath) {
25
+ throw new Error(`Invalid PROXY_ADMIN_PATH "${adminPath}". The path must not overlap reserved routes: ${RESERVED_PATHS.join(', ')}.`);
26
+ }
27
+
28
+ return adminPath;
29
+ }
30
+
31
+ export { DEFAULT_ADMIN_PATH };
32
+
33
+ export default { getAdminPath, DEFAULT_ADMIN_PATH };
@@ -75,23 +75,6 @@ export async function updateClaudeConfig(updates) {
75
75
  }
76
76
  }
77
77
 
78
- export async function setProxyMode(proxyUrl, models = {}) {
79
- const updates = {
80
- env: {
81
- ANTHROPIC_BASE_URL: proxyUrl,
82
- ANTHROPIC_API_KEY: 'sk-ant-proxy',
83
- ANTHROPIC_AUTH_TOKEN: undefined, // Explicitly unset to avoid conflict
84
- ANTHROPIC_DEFAULT_OPUS_MODEL: models.opus || 'claude-opus',
85
- ANTHROPIC_DEFAULT_SONNET_MODEL: models.sonnet || 'claude-sonnet',
86
- ANTHROPIC_DEFAULT_HAIKU_MODEL: models.haiku || 'claude-haiku',
87
- CLAUDE_CODE_AUTO_COMPACT_WINDOW: '258000'
88
- },
89
- autoCompactEnabled: true
90
- };
91
-
92
- return await updateClaudeConfig(updates);
93
- }
94
-
95
78
  export async function setDirectMode(apiKey) {
96
79
  const updates = {
97
80
  env: {
@@ -148,7 +131,6 @@ export default {
148
131
  readClaudeConfig,
149
132
  readClaudeConfigSync,
150
133
  updateClaudeConfig,
151
- setProxyMode,
152
134
  setDirectMode,
153
135
  setApiEndpoint
154
136
  };