claude-codex-proxy 1.0.5-beta.13 → 1.0.5-beta.3
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/README.md +272 -0
- package/bin/cli.js +2 -37
- package/package.json +1 -1
- package/public/css/style.css +0 -127
- package/public/index.html +60 -60
- package/public/js/app.js +116 -133
- package/public/login.html +32 -32
- package/public/views/accounts-modals.html +0 -56
- package/public/views/accounts.html +10 -29
- package/public/views/client-api-keys-modals.html +1 -6
- package/public/views/client-api-keys.html +31 -54
- package/public/views/logs.html +3 -10
- package/src/account-manager.js +3 -34
- package/src/account-rotation/rate-limits.js +0 -4
- package/src/account-rotation/strategies/base-strategy.js +0 -4
- package/src/account-rotation/strategies/sticky-strategy.js +0 -7
- package/src/deployment.js +49 -49
- package/src/direct-api.js +13 -12
- package/src/index.js +4 -13
- package/src/middleware/auth.js +11 -46
- package/src/middleware/credentials.js +3 -13
- package/src/model-api.js +0 -60
- package/src/response-streamer.js +5 -5
- package/src/routes/accounts-route.js +2 -106
- package/src/routes/api-routes.js +42 -59
- package/src/routes/chat-route.js +4 -25
- package/src/routes/claude-config-route.js +10 -19
- package/src/routes/logs-route.js +2 -21
- package/src/routes/messages-route.js +13 -39
- package/src/routes/settings-route.js +5 -36
- package/src/server-settings.js +2 -18
- package/src/utils/logger.js +0 -18
- package/src/admin-path.js +0 -33
- package/src/client-key-usage.js +0 -125
- package/src/model-pricing.js +0 -96
- package/src/routes/client-quota-route.js +0 -25
- package/src/utils/proxy-logging.js +0 -5
|
@@ -39,22 +39,21 @@
|
|
|
39
39
|
</div>
|
|
40
40
|
|
|
41
41
|
<div class="view-card !p-0 overflow-x-auto">
|
|
42
|
-
<table class="w-full min-w-[
|
|
42
|
+
<table class="w-full min-w-[860px]">
|
|
43
43
|
<thead x-show="filteredAccounts.length > 0">
|
|
44
44
|
<tr class="bg-space-900/50 border-b border-space-border/50">
|
|
45
45
|
<th class="py-3 text-left text-[10px] font-bold text-gray-500 uppercase tracking-wider w-20">Status</th>
|
|
46
|
-
<th class="
|
|
46
|
+
<th class="py-3 text-center text-[10px] font-bold text-gray-500 uppercase tracking-wider flex-1 min-w-[200px]">Account (Email)</th>
|
|
47
47
|
<th class="py-3 text-left text-[10px] font-bold text-gray-500 uppercase tracking-wider w-20">Plan</th>
|
|
48
48
|
<th class="py-3 text-left text-[10px] font-bold text-gray-500 uppercase tracking-wider w-32">Token</th>
|
|
49
49
|
<th class="py-3 text-left text-[10px] font-bold text-gray-500 uppercase tracking-wider w-24">Quota</th>
|
|
50
|
-
<th class="w-52 min-w-[13rem] py-3 text-center text-[10px] font-bold text-gray-500 uppercase tracking-wider">Account Expiry</th>
|
|
51
50
|
<th class="py-3 pr-6 text-right text-[10px] font-bold text-gray-500 uppercase tracking-wider w-40">Operations</th>
|
|
52
51
|
</tr>
|
|
53
52
|
</thead>
|
|
54
53
|
<tbody>
|
|
55
54
|
<template x-if="filteredAccounts.length === 0 && accounts.length === 0">
|
|
56
55
|
<tr>
|
|
57
|
-
<td colspan="
|
|
56
|
+
<td colspan="6" class="py-16 text-center flex justify-center">
|
|
58
57
|
<div class="flex flex-col items-center gap-4 max-w-lg mx-auto">
|
|
59
58
|
<svg class="w-20 h-20 text-gray-700" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
60
59
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" 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 0zM7 10a2 2 0 11-4 0 2 2 0 014 0z" />
|
|
@@ -84,16 +83,16 @@
|
|
|
84
83
|
<td class="py-4 pl-6">
|
|
85
84
|
<div class="flex items-center gap-2">
|
|
86
85
|
<div class="w-2 h-2 rounded-full flex-shrink-0"
|
|
87
|
-
:class="acc.
|
|
86
|
+
:class="acc.isActive ? 'bg-neon-green shadow-[0_0_8px_rgba(34,197,94,0.6)] animate-pulse' : 'bg-gray-500'">
|
|
88
87
|
</div>
|
|
89
88
|
<span class="text-xs font-mono font-semibold"
|
|
90
|
-
:class="acc.
|
|
91
|
-
x-text="acc.
|
|
89
|
+
:class="acc.isActive ? 'text-neon-green' : 'text-gray-500'"
|
|
90
|
+
x-text="acc.isActive ? 'ACTIVE' : 'IDLE'">
|
|
92
91
|
</span>
|
|
93
92
|
</div>
|
|
94
93
|
</td>
|
|
95
|
-
<td class="
|
|
96
|
-
<span class="
|
|
94
|
+
<td class="py-4 text-center">
|
|
95
|
+
<span class="font-mono text-sm text-gray-300 truncate max-w-[320px] inline-block group-hover:text-white transition-colors"
|
|
97
96
|
x-text="acc.email"></span>
|
|
98
97
|
</td>
|
|
99
98
|
<td class="py-4">
|
|
@@ -147,27 +146,9 @@
|
|
|
147
146
|
<span class="text-xs text-gray-600">-</span>
|
|
148
147
|
</template>
|
|
149
148
|
</td>
|
|
150
|
-
<td class="w-52 min-w-[13rem] py-4 text-center">
|
|
151
|
-
<div class="inline-flex items-center justify-center gap-1">
|
|
152
|
-
<div>
|
|
153
|
-
<span class="block whitespace-nowrap text-xs font-mono"
|
|
154
|
-
:class="acc.accountExpired ? 'text-red-400' : acc.accountExpiresAt ? 'text-gray-300' : 'text-gray-500'"
|
|
155
|
-
x-text="accountExpirationLabel(acc)"></span>
|
|
156
|
-
<span class="mt-1 block text-[10px]"
|
|
157
|
-
:class="acc.accountExpired ? 'text-red-500/70' : 'text-gray-600'"
|
|
158
|
-
x-text="acc.accountExpired ? 'Expired' : acc.accountExpiresAt ? 'Local time' : 'Not set'"></span>
|
|
159
|
-
</div>
|
|
160
|
-
<button class="btn btn-xs btn-ghost shrink-0 rounded p-1.5 text-gray-600 transition-colors hover:bg-white/10 hover:text-neon-cyan"
|
|
161
|
-
@click="showAccountExpirationModal(acc)" title="Configure account expiration">
|
|
162
|
-
<svg class="h-3.5 w-3.5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
163
|
-
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15.232 5.232l3.536 3.536M9 11l6.232-6.232a2.5 2.5 0 013.536 3.536L12.536 14.536 9 15l.464-3.536zM5 19h14" />
|
|
164
|
-
</svg>
|
|
165
|
-
</button>
|
|
166
|
-
</div>
|
|
167
|
-
</td>
|
|
168
149
|
<td class="py-4 pr-6">
|
|
169
150
|
<div class="flex justify-end gap-2">
|
|
170
|
-
<button x-show="!acc.isActive
|
|
151
|
+
<button x-show="!acc.isActive"
|
|
171
152
|
class="cursor-pointer px-3 py-1 text-[10px] font-bold font-mono uppercase tracking-wider rounded bg-neon-purple/10 text-neon-purple hover:bg-neon-purple/20 border border-neon-purple/30 hover:border-neon-purple/50 transition-all"
|
|
172
153
|
@click="switchAccount(acc.email)">
|
|
173
154
|
SWITCH
|
|
@@ -185,7 +166,7 @@
|
|
|
185
166
|
|
|
186
167
|
<template x-if="accounts.length > 0 && filteredAccounts.length === 0">
|
|
187
168
|
<tr>
|
|
188
|
-
<td colspan="
|
|
169
|
+
<td colspan="6" class="py-12 text-center">
|
|
189
170
|
<div class="flex flex-col items-center gap-3">
|
|
190
171
|
<svg class="w-12 h-12 text-gray-700" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
191
172
|
<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" />
|
|
@@ -14,11 +14,6 @@
|
|
|
14
14
|
<input type="text" x-model="clientApiKeyRemark" placeholder="Optional note"
|
|
15
15
|
class="input w-full bg-space-800 border-space-border text-white font-mono text-sm" @keydown.enter="createClientApiKey()">
|
|
16
16
|
</label>
|
|
17
|
-
<label class="block">
|
|
18
|
-
<span class="block text-xs text-gray-400 mb-2">Weekly limit (USD)</span>
|
|
19
|
-
<input type="number" min="0" step="0.01" x-model="clientApiKeyWeeklyLimitUsd"
|
|
20
|
-
class="input w-full bg-space-800 border-space-border text-white font-mono text-sm" @keydown.enter="createClientApiKey()">
|
|
21
|
-
</label>
|
|
22
17
|
</div>
|
|
23
18
|
<div class="mt-6 flex justify-end gap-2">
|
|
24
19
|
<button class="btn btn-outline btn-sm text-gray-400" @click="showCreateClientApiKeyModal = false" :disabled="clientApiKeySaving">Cancel</button>
|
|
@@ -40,8 +35,8 @@
|
|
|
40
35
|
<p class="text-xs font-semibold uppercase tracking-wider text-gray-400">Claude Code configuration</p>
|
|
41
36
|
<div class="rounded-lg border border-space-border bg-space-800 p-3 font-mono text-xs text-gray-300 space-y-2">
|
|
42
37
|
<div><span class="text-gray-500">ANTHROPIC_BASE_URL=</span><span class="break-all" x-text="clientProxyConfig.env.ANTHROPIC_BASE_URL"></span></div>
|
|
43
|
-
<div><span class="text-gray-500">ANTHROPIC_AUTH_TOKEN=</span><span class="break-all" x-text="revealedClientApiKey"></span></div>
|
|
44
38
|
<div><span class="text-gray-500">ANTHROPIC_API_KEY=</span><span class="break-all" x-text="revealedClientApiKey"></span></div>
|
|
39
|
+
<div><span class="text-gray-500">CLAUDE_CODE_AUTO_COMPACT_WINDOW=</span><span x-text="clientProxyConfig.env.CLAUDE_CODE_AUTO_COMPACT_WINDOW"></span></div>
|
|
45
40
|
</div>
|
|
46
41
|
<p class="text-xs text-gray-500" x-text="clientProxyConfig.message"></p>
|
|
47
42
|
<button class="btn btn-outline btn-sm text-gray-300" @click="copyClientProxyCommands()">Copy PowerShell Commands</button>
|
|
@@ -8,62 +8,39 @@
|
|
|
8
8
|
</div>
|
|
9
9
|
</div>
|
|
10
10
|
|
|
11
|
-
<div class="
|
|
12
|
-
<div class="
|
|
13
|
-
<
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
</
|
|
17
|
-
<div class="client-keys-toolbar-actions">
|
|
18
|
-
<div x-show="clientApiKeys.length" class="client-keys-reset">
|
|
19
|
-
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" aria-hidden="true"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.8" d="M12 8v4l2.5 2.5M21 12a9 9 0 11-2.64-6.36M21 4v5h-5"/></svg>
|
|
20
|
-
<div><span>Next weekly reset</span><strong x-text="clientApiKeys[0]?.quota?.nextPeriodStart ? new Date(clientApiKeys[0].quota.nextPeriodStart).toLocaleString() : '-'"></strong></div>
|
|
21
|
-
</div>
|
|
22
|
-
<button class="client-keys-new" @click="revealedClientApiKey = ''; clientProxyConfig = null; showCreateClientApiKeyModal = true">
|
|
23
|
-
<span>+</span> New API Key
|
|
24
|
-
</button>
|
|
25
|
-
</div>
|
|
11
|
+
<div class="view-card !p-0 overflow-x-auto">
|
|
12
|
+
<div class="flex items-center justify-between gap-4 px-6 py-4 border-b border-space-border/50">
|
|
13
|
+
<h2 class="text-sm font-semibold text-gray-200">Client API Keys</h2>
|
|
14
|
+
<button class="btn btn-sm bg-neon-purple hover:bg-purple-600 border-none text-white" @click="revealedClientApiKey = ''; clientProxyConfig = null; showCreateClientApiKeyModal = true">
|
|
15
|
+
New API Key
|
|
16
|
+
</button>
|
|
26
17
|
</div>
|
|
27
|
-
|
|
28
18
|
<template x-if="clientApiKeysLoading">
|
|
29
|
-
<div class="
|
|
19
|
+
<div class="text-xs text-gray-500 font-mono py-8 text-center">Loading client API keys...</div>
|
|
30
20
|
</template>
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
<
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
<div class="
|
|
47
|
-
<
|
|
48
|
-
<
|
|
49
|
-
</div>
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
<div class="client-key-meta"><span>Created</span><strong x-text="new Date(clientApiKey.createdAt).toLocaleDateString()"></strong><small x-text="new Date(clientApiKey.createdAt).toLocaleTimeString()"></small></div>
|
|
57
|
-
|
|
58
|
-
<div class="client-key-actions">
|
|
59
|
-
<button class="client-key-save" @click="updateClientApiKey(clientApiKey)" :disabled="clientApiKeySaving">Save changes</button>
|
|
60
|
-
<button class="client-key-delete" @click="deleteClientApiKey(clientApiKey)" :disabled="clientApiKeySaving" aria-label="Delete API key" title="Delete">
|
|
61
|
-
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.8" d="M4 7h16M9 7V4h6v3m-8 0 1 13h8l1-13M10 11v5m4-5v5"/></svg>
|
|
62
|
-
</button>
|
|
63
|
-
</div>
|
|
64
|
-
</article>
|
|
65
|
-
</template>
|
|
66
|
-
</div>
|
|
67
|
-
<div x-show="!clientApiKeysLoading && !clientApiKeys.length" class="client-keys-empty">No client API keys. Create one to connect Claude Code clients.</div>
|
|
21
|
+
<table class="w-full min-w-[760px]" x-show="!clientApiKeysLoading && clientApiKeys.length">
|
|
22
|
+
<thead>
|
|
23
|
+
<tr class="bg-space-900/50 border-b border-space-border/50">
|
|
24
|
+
<th class="py-3 pl-6 text-left text-[10px] font-bold text-gray-500 uppercase tracking-wider">Client Name</th>
|
|
25
|
+
<th class="py-3 text-left text-[10px] font-bold text-gray-500 uppercase tracking-wider">Remark</th>
|
|
26
|
+
<th class="py-3 text-left text-[10px] font-bold text-gray-500 uppercase tracking-wider">Created</th>
|
|
27
|
+
<th class="py-3 pr-6 text-right text-[10px] font-bold text-gray-500 uppercase tracking-wider">Operations</th>
|
|
28
|
+
</tr>
|
|
29
|
+
</thead>
|
|
30
|
+
<tbody>
|
|
31
|
+
<template x-for="clientApiKey in clientApiKeys" :key="clientApiKey.id">
|
|
32
|
+
<tr class="border-b border-space-border/30 last:border-0 hover:bg-white/5 transition-colors">
|
|
33
|
+
<td class="py-3 pl-6"><input type="text" x-model="clientApiKey.name" placeholder="Unnamed" class="input input-sm w-48 bg-space-800 border-space-border text-white"></td>
|
|
34
|
+
<td class="py-3"><input type="text" x-model="clientApiKey.remark" placeholder="No remark" class="input input-sm w-48 bg-space-800 border-space-border text-white"></td>
|
|
35
|
+
<td class="py-3 text-xs font-mono text-gray-500 whitespace-nowrap" x-text="new Date(clientApiKey.createdAt).toLocaleString()"></td>
|
|
36
|
+
<td class="py-3 pr-6"><div class="flex justify-end gap-2 whitespace-nowrap">
|
|
37
|
+
<button class="btn btn-xs btn-outline text-gray-300" @click="updateClientApiKey(clientApiKey)" :disabled="clientApiKeySaving">Save</button>
|
|
38
|
+
<button class="btn btn-xs btn-outline text-red-400" @click="deleteClientApiKey(clientApiKey)" :disabled="clientApiKeySaving">Delete</button>
|
|
39
|
+
</div></td>
|
|
40
|
+
</tr>
|
|
41
|
+
</template>
|
|
42
|
+
</tbody>
|
|
43
|
+
</table>
|
|
44
|
+
<div x-show="!clientApiKeysLoading && !clientApiKeys.length" class="text-sm text-gray-500 font-mono py-16 text-center">No client API keys. Create one to connect Claude Code clients.</div>
|
|
68
45
|
</div>
|
|
69
46
|
</div>
|
package/public/views/logs.html
CHANGED
|
@@ -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="
|
|
11
|
+
<span x-text="logs.length"></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="
|
|
57
|
+
<template x-for="(log, idx) in filteredLogs" :key="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,17 +83,10 @@
|
|
|
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="
|
|
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>
|
|
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>
|
|
98
91
|
</div>
|
|
99
92
|
</div>
|
package/src/account-manager.js
CHANGED
|
@@ -98,25 +98,6 @@ 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
|
-
|
|
120
101
|
function updateAccountAuth(account) {
|
|
121
102
|
if (!account) return;
|
|
122
103
|
|
|
@@ -150,15 +131,11 @@ function updateAccountAuth(account) {
|
|
|
150
131
|
function setActiveAccount(email) {
|
|
151
132
|
const data = loadAccounts();
|
|
152
133
|
const account = data.accounts.find(a => a.email === email);
|
|
153
|
-
|
|
134
|
+
|
|
154
135
|
if (!account) {
|
|
155
136
|
return { success: false, message: `Account not found: ${email}` };
|
|
156
137
|
}
|
|
157
|
-
|
|
158
|
-
if (isAccountExpired(account)) {
|
|
159
|
-
return { success: false, message: `Account has expired: ${email}` };
|
|
160
|
-
}
|
|
161
|
-
|
|
138
|
+
|
|
162
139
|
data.activeAccount = email;
|
|
163
140
|
saveAccounts(data);
|
|
164
141
|
|
|
@@ -213,8 +190,6 @@ function listAccounts() {
|
|
|
213
190
|
lastUsed: account.lastUsed,
|
|
214
191
|
isActive: account.email === data.activeAccount,
|
|
215
192
|
tokenExpired: info?.expiresAt ? info.expiresAt < Date.now() : false,
|
|
216
|
-
accountExpiresAt: account.accountExpiresAt || null,
|
|
217
|
-
accountExpired: isAccountExpired(account),
|
|
218
193
|
quota: account.quota || null
|
|
219
194
|
};
|
|
220
195
|
});
|
|
@@ -501,7 +476,7 @@ function importFromCodex() {
|
|
|
501
476
|
|
|
502
477
|
const existingIndex = data.accounts.findIndex(a => a.email === newAccount.email);
|
|
503
478
|
if (existingIndex >= 0) {
|
|
504
|
-
data.accounts[existingIndex] =
|
|
479
|
+
data.accounts[existingIndex] = newAccount;
|
|
505
480
|
} else {
|
|
506
481
|
data.accounts.push(newAccount);
|
|
507
482
|
}
|
|
@@ -532,8 +507,6 @@ function getStatus() {
|
|
|
532
507
|
isActive: a.email === data.activeAccount,
|
|
533
508
|
quota: a.quota || null,
|
|
534
509
|
tokenExpired: info?.expiresAt ? info.expiresAt < Date.now() : false,
|
|
535
|
-
accountExpiresAt: a.accountExpiresAt || null,
|
|
536
|
-
accountExpired: isAccountExpired(a),
|
|
537
510
|
lastUsed: a.lastUsed
|
|
538
511
|
};
|
|
539
512
|
});
|
|
@@ -575,8 +548,6 @@ export {
|
|
|
575
548
|
ensureAccountsPersist,
|
|
576
549
|
updateAccountQuota,
|
|
577
550
|
getAccountQuota,
|
|
578
|
-
updateAccountExpiration,
|
|
579
|
-
isAccountExpired,
|
|
580
551
|
startAutoRefresh,
|
|
581
552
|
stopAutoRefresh,
|
|
582
553
|
isTokenExpiredOrExpiringSoon,
|
|
@@ -603,8 +574,6 @@ export default {
|
|
|
603
574
|
ensureAccountsPersist,
|
|
604
575
|
updateAccountQuota,
|
|
605
576
|
getAccountQuota,
|
|
606
|
-
updateAccountExpiration,
|
|
607
|
-
isAccountExpired,
|
|
608
577
|
startAutoRefresh,
|
|
609
578
|
stopAutoRefresh,
|
|
610
579
|
isTokenExpiredOrExpiringSoon,
|
|
@@ -33,10 +33,6 @@ 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
|
-
}
|
|
40
36
|
if (isAccountCoolingDown(account)) return false;
|
|
41
37
|
if (isQuotaLimitReached(account)) return false;
|
|
42
38
|
const rateLimit = account.modelRateLimits?.[modelId];
|
|
@@ -23,10 +23,6 @@ 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
|
-
}
|
|
30
26
|
if (isAccountCoolingDown(account)) return false;
|
|
31
27
|
if (isQuotaLimitReached(account)) return false;
|
|
32
28
|
|
|
@@ -56,13 +56,6 @@ 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
|
-
|
|
66
59
|
// Check model-specific rate limit
|
|
67
60
|
if (modelId && account.modelRateLimits && account.modelRateLimits[modelId]) {
|
|
68
61
|
const limit = account.modelRateLimits[modelId];
|
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 };
|
package/src/direct-api.js
CHANGED
|
@@ -7,14 +7,17 @@ import os from 'os';
|
|
|
7
7
|
import { createRequire } from 'module';
|
|
8
8
|
import { convertAnthropicToResponsesAPI, convertOutputToAnthropic, generateMessageId } from './format-converter.js';
|
|
9
9
|
import { streamResponsesAPI, parseResponsesAPIResponse, createResponsesAPIError } from './response-streamer.js';
|
|
10
|
+
import { getServerSettings } from './server-settings.js';
|
|
10
11
|
import { logger } from './utils/logger.js';
|
|
11
|
-
import { shouldLogRawProxyPayloads } from './utils/proxy-logging.js';
|
|
12
12
|
|
|
13
13
|
const require = createRequire(import.meta.url);
|
|
14
14
|
const packageJson = require('../package.json');
|
|
15
15
|
const API_URL = 'https://chatgpt.com/backend-api/codex/responses';
|
|
16
16
|
const APP_VERSION = packageJson.version;
|
|
17
|
-
|
|
17
|
+
|
|
18
|
+
function shouldLogRawProxyPayloads() {
|
|
19
|
+
return getServerSettings().logRawProxyPayloads === true;
|
|
20
|
+
}
|
|
18
21
|
|
|
19
22
|
function createAnthropicUsage(upstreamUsage = {}) {
|
|
20
23
|
const usage = {
|
|
@@ -27,10 +30,6 @@ function createAnthropicUsage(upstreamUsage = {}) {
|
|
|
27
30
|
value: upstreamUsage.cache_read_input_tokens || upstreamUsage.input_tokens_details?.cached_tokens || 0,
|
|
28
31
|
enumerable: false
|
|
29
32
|
});
|
|
30
|
-
Object.defineProperty(usage, 'upstreamCacheWriteInputTokens', {
|
|
31
|
-
value: upstreamUsage.input_tokens_details?.cache_write_tokens || 0,
|
|
32
|
-
enumerable: false
|
|
33
|
-
});
|
|
34
33
|
return usage;
|
|
35
34
|
}
|
|
36
35
|
|
|
@@ -129,14 +128,15 @@ async function createResponsesAPIStreamResponse(anthropicRequest, accessToken, a
|
|
|
129
128
|
const response = await fetch(API_URL, {
|
|
130
129
|
method: 'POST',
|
|
131
130
|
headers: buildOpencodeHeaders(accessToken, accountId, context),
|
|
132
|
-
body: JSON.stringify(request)
|
|
133
|
-
signal: AbortSignal.timeout(UPSTREAM_REQUEST_TIMEOUT_MS)
|
|
131
|
+
body: JSON.stringify(request)
|
|
134
132
|
});
|
|
135
133
|
|
|
136
134
|
if (response.ok) return response;
|
|
137
135
|
|
|
138
136
|
const errorText = await response.text();
|
|
139
|
-
|
|
137
|
+
if (shouldLogRawProxyPayloads()) {
|
|
138
|
+
logger.info('[OpenAI Error]', { status: response.status, body: errorText });
|
|
139
|
+
}
|
|
140
140
|
|
|
141
141
|
if (response.status === 401) {
|
|
142
142
|
if (accountRotator && currentEmail) {
|
|
@@ -197,13 +197,14 @@ export async function sendMessage(anthropicRequest, accessToken, accountId, cont
|
|
|
197
197
|
const response = await fetch(API_URL, {
|
|
198
198
|
method: 'POST',
|
|
199
199
|
headers: buildOpencodeHeaders(accessToken, accountId, context),
|
|
200
|
-
body: JSON.stringify(request)
|
|
201
|
-
signal: AbortSignal.timeout(UPSTREAM_REQUEST_TIMEOUT_MS)
|
|
200
|
+
body: JSON.stringify(request)
|
|
202
201
|
});
|
|
203
202
|
|
|
204
203
|
if (!response.ok) {
|
|
205
204
|
const errorText = await response.text();
|
|
206
|
-
|
|
205
|
+
if (shouldLogRawProxyPayloads()) {
|
|
206
|
+
logger.info('[OpenAI Error]', { status: response.status, body: errorText });
|
|
207
|
+
}
|
|
207
208
|
|
|
208
209
|
if (response.status === 401) {
|
|
209
210
|
throw createHTTPError('AUTH_EXPIRED: Token expired or revoked. Please re-authenticate.', 401, 'authentication_error', response.status);
|
package/src/index.js
CHANGED
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
|
|
6
6
|
import { createRequire } from 'module';
|
|
7
7
|
import { getDeploymentMode, getLocalBaseUrl, getServerHost } from './deployment.js';
|
|
8
|
-
import { getAdminPath } from './admin-path.js';
|
|
9
8
|
import { startServer } from './server.js';
|
|
10
9
|
import { logger } from './utils/logger.js';
|
|
11
10
|
import { getStatus, ACCOUNTS_FILE } from './account-manager.js';
|
|
@@ -22,14 +21,6 @@ try {
|
|
|
22
21
|
}
|
|
23
22
|
const HOST = getServerHost();
|
|
24
23
|
const BASE_URL = getLocalBaseUrl(PORT);
|
|
25
|
-
let ADMIN_PATH;
|
|
26
|
-
try {
|
|
27
|
-
ADMIN_PATH = getAdminPath();
|
|
28
|
-
} catch (error) {
|
|
29
|
-
console.error(error.message);
|
|
30
|
-
process.exit(1);
|
|
31
|
-
}
|
|
32
|
-
const ADMIN_URL = `${BASE_URL}${ADMIN_PATH}`;
|
|
33
24
|
const BANNER_WIDTH = 62;
|
|
34
25
|
|
|
35
26
|
if (DEPLOYMENT_MODE === 'public' && !process.env.PROXY_ADMIN_KEY) {
|
|
@@ -54,10 +45,10 @@ console.log(`
|
|
|
54
45
|
╠══════════════════════════════════════════════════════════════╣
|
|
55
46
|
${bannerLine('Host:', HOST)}
|
|
56
47
|
${bannerLine('Server:', BASE_URL)}
|
|
57
|
-
${bannerLine('WebUI:',
|
|
48
|
+
${bannerLine('WebUI:', BASE_URL)}
|
|
58
49
|
${bannerLine('Health:', `${BASE_URL}/health`)}
|
|
59
|
-
${bannerLine('Accounts:', `${
|
|
60
|
-
${bannerLine('Logs:', `${
|
|
50
|
+
${bannerLine('Accounts:', `${BASE_URL}/accounts`)}
|
|
51
|
+
${bannerLine('Logs:', `${BASE_URL}/api/logs/stream`)}
|
|
61
52
|
╠══════════════════════════════════════════════════════════════╣
|
|
62
53
|
║ Features: ║
|
|
63
54
|
║ ✓ Native tool calling support ║
|
|
@@ -75,7 +66,7 @@ const status = getStatus();
|
|
|
75
66
|
logger.info(`Accounts: ${status.total} total, Active: ${status.active || 'None'}`);
|
|
76
67
|
|
|
77
68
|
if (status.total === 0) {
|
|
78
|
-
logger.warn(`No accounts configured. Open ${
|
|
69
|
+
logger.warn(`No accounts configured. Open ${BASE_URL} to add one.`);
|
|
79
70
|
}
|
|
80
71
|
|
|
81
72
|
// Expose config path in logs for convenience
|