claude-codex-proxy 1.0.5-beta.3 → 1.0.5-beta.31
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 +0 -272
- package/bin/cli.js +37 -2
- package/package.json +1 -1
- package/public/css/style.css +132 -0
- package/public/index.html +60 -60
- package/public/js/app.js +195 -116
- package/public/login.html +32 -32
- package/public/views/accounts-modals.html +90 -29
- package/public/views/accounts.html +29 -10
- package/public/views/client-api-keys-modals.html +15 -1
- package/public/views/client-api-keys.html +68 -31
- package/public/views/logs.html +10 -3
- package/src/account-manager.js +34 -3
- package/src/account-rotation/rate-limits.js +4 -0
- package/src/account-rotation/strategies/base-strategy.js +4 -0
- package/src/account-rotation/strategies/sticky-strategy.js +7 -0
- package/src/admin-path.js +33 -0
- package/src/client-key-usage.js +193 -0
- package/src/deployment.js +49 -49
- package/src/direct-api.js +11 -11
- package/src/format-converter.js +83 -48
- package/src/index.js +13 -4
- package/src/middleware/auth.js +54 -16
- package/src/middleware/credentials.js +17 -7
- package/src/middleware/sse.js +69 -29
- package/src/model-api.js +86 -13
- package/src/model-pricing.js +127 -0
- package/src/response-streamer.js +23 -7
- package/src/routes/accounts-route.js +106 -2
- package/src/routes/api-routes.js +59 -42
- package/src/routes/chat-route.js +25 -4
- package/src/routes/claude-config-route.js +19 -10
- package/src/routes/client-quota-route.js +31 -0
- package/src/routes/logs-route.js +21 -2
- package/src/routes/messages-route.js +100 -51
- package/src/routes/settings-route.js +66 -5
- package/src/server-settings.js +25 -2
- package/src/utils/logger.js +30 -0
- package/src/utils/proxy-logging.js +5 -0
|
@@ -86,6 +86,25 @@
|
|
|
86
86
|
</div>
|
|
87
87
|
</div>
|
|
88
88
|
|
|
89
|
+
<div x-show="showAccountExpirationModalView" x-transition class="fixed inset-0 z-50 flex items-center justify-center p-4" style="display: none;">
|
|
90
|
+
<div class="absolute inset-0 bg-black/70 backdrop-blur-sm" @click="closeAccountExpirationModal()"></div>
|
|
91
|
+
<div class="relative bg-space-900 border border-space-border rounded-xl shadow-2xl max-w-md w-full p-6">
|
|
92
|
+
<h3 class="font-bold text-lg text-white mb-2">Set Account Expiration</h3>
|
|
93
|
+
<p class="text-sm text-gray-500 font-mono mb-5" x-text="expirationTarget?.email"></p>
|
|
94
|
+
<label class="block text-xs font-semibold uppercase tracking-wider text-gray-500 mb-2" for="account-expiration">Expires at</label>
|
|
95
|
+
<input id="account-expiration" type="datetime-local" x-model="accountExpirationInput"
|
|
96
|
+
class="input w-full bg-space-800 border-space-border text-white font-mono text-sm">
|
|
97
|
+
<p class="mt-2 text-xs text-gray-500">The time uses your browser's local timezone. After expiration, this account will not participate in automatic account selection.</p>
|
|
98
|
+
<div class="mt-6 flex justify-between gap-2">
|
|
99
|
+
<button class="btn btn-ghost btn-sm text-gray-400 hover:text-white" @click="clearAccountExpiration()" :disabled="accountExpirationSaving || !expirationTarget?.accountExpiresAt">Clear Expiration</button>
|
|
100
|
+
<div class="flex gap-2">
|
|
101
|
+
<button class="btn btn-outline btn-sm text-gray-400" @click="closeAccountExpirationModal()">Cancel</button>
|
|
102
|
+
<button class="btn bg-neon-purple hover:bg-purple-600 border-none text-white btn-sm" @click="saveAccountExpiration()" :disabled="accountExpirationSaving || !accountExpirationInput" x-text="accountExpirationSaving ? 'Saving...' : 'Save'"></button>
|
|
103
|
+
</div>
|
|
104
|
+
</div>
|
|
105
|
+
</div>
|
|
106
|
+
</div>
|
|
107
|
+
|
|
89
108
|
<div x-show="showDeleteModal" x-transition class="fixed inset-0 z-50 flex items-center justify-center p-4" style="display: none;">
|
|
90
109
|
<div class="absolute inset-0 bg-black/70 backdrop-blur-sm" @click="showDeleteModal = false"></div>
|
|
91
110
|
<div class="relative bg-space-900 border-2 border-red-500/50 rounded-xl shadow-2xl max-w-md w-full p-6">
|
|
@@ -109,7 +128,7 @@
|
|
|
109
128
|
</div>
|
|
110
129
|
|
|
111
130
|
<div x-show="showQuotaModalView" x-transition class="fixed inset-0 z-50 flex items-center justify-center p-4" style="display: none;">
|
|
112
|
-
<div class="absolute inset-0 bg-black/70 backdrop-blur-sm" @click="showQuotaModalView = false"></div>
|
|
131
|
+
<div class="absolute inset-0 bg-black/70 backdrop-blur-sm" @click="if (!resetCreditsRedeeming) showQuotaModalView = false"></div>
|
|
113
132
|
<div class="relative bg-space-900 border border-space-border rounded-xl shadow-2xl max-w-lg w-full p-6">
|
|
114
133
|
<h3 class="font-bold text-lg text-white mb-2 flex items-center gap-2">
|
|
115
134
|
<svg class="w-6 h-6 text-neon-cyan" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
@@ -119,41 +138,83 @@
|
|
|
119
138
|
</h3>
|
|
120
139
|
<p class="text-sm text-gray-500 font-mono mb-4" x-text="selectedAccount?.email"></p>
|
|
121
140
|
|
|
122
|
-
<div class="space-y-3 max-h-[60vh] overflow-y-auto" x-show="
|
|
123
|
-
<
|
|
124
|
-
<div class="
|
|
125
|
-
<
|
|
126
|
-
|
|
127
|
-
<
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
<
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
<div class="
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
<div class="mt-3 pt-3 border-t border-space-border/30 space-y-1">
|
|
141
|
-
<div class="flex items-center justify-between text-xs">
|
|
142
|
-
<span class="text-gray-500">Reset window</span>
|
|
143
|
-
<span class="font-mono text-gray-300" x-text="quotaResetSummary(selectedAccount) || '-'"></span>
|
|
141
|
+
<div class="space-y-3 max-h-[60vh] overflow-y-auto" x-show="getQuotaWindow(selectedAccount, 'primary') || getQuotaWindow(selectedAccount, 'secondary')">
|
|
142
|
+
<template x-for="window in [{ name: 'primary', label: '5-hour usage' }, { name: 'secondary', label: 'Weekly usage' }]" :key="window.name">
|
|
143
|
+
<div x-show="getQuotaWindow(selectedAccount, window.name)" class="p-3 bg-space-800/50 border border-space-border/30 rounded-lg">
|
|
144
|
+
<div class="flex justify-between items-center mb-2">
|
|
145
|
+
<span class="text-sm font-semibold text-gray-200" x-text="window.label"></span>
|
|
146
|
+
<template x-if="!isQuotaExhausted(selectedAccount, window.name)">
|
|
147
|
+
<span class="text-xs font-mono"
|
|
148
|
+
:class="quotaTextClass(selectedAccount, window.name)"
|
|
149
|
+
x-text="quotaLabel(selectedAccount, window.name) + ' remaining'"></span>
|
|
150
|
+
</template>
|
|
151
|
+
<template x-if="isQuotaExhausted(selectedAccount, window.name)">
|
|
152
|
+
<span class="text-[10px] font-bold uppercase text-red-400 bg-red-500/10 px-2 py-0.5 rounded border border-red-500/30">QUOTA EXHAUSTED</span>
|
|
153
|
+
</template>
|
|
154
|
+
</div>
|
|
155
|
+
<div class="w-full bg-gray-700 rounded-full h-3 overflow-hidden">
|
|
156
|
+
<div class="h-full rounded-full transition-all"
|
|
157
|
+
:class="quotaBarClass(selectedAccount, window.name)"
|
|
158
|
+
:style="`width: ${getRemainingPercentage(selectedAccount, window.name)}%`"></div>
|
|
144
159
|
</div>
|
|
145
|
-
<
|
|
160
|
+
<div class="mt-3 pt-3 border-t border-space-border/30 space-y-1">
|
|
146
161
|
<div class="flex items-center justify-between text-xs">
|
|
147
|
-
<span class="text-gray-500">
|
|
148
|
-
<span class="font-mono text-gray-300" x-text="
|
|
162
|
+
<span class="text-gray-500">Reset window</span>
|
|
163
|
+
<span class="font-mono text-gray-300" x-text="quotaResetSummary(selectedAccount, window.name) || '-'"></span>
|
|
149
164
|
</div>
|
|
150
|
-
|
|
165
|
+
<template x-if="quotaResetAtLabel(selectedAccount, window.name)">
|
|
166
|
+
<div class="flex items-center justify-between text-xs">
|
|
167
|
+
<span class="text-gray-500">Resets at</span>
|
|
168
|
+
<span class="font-mono text-gray-300" x-text="quotaResetAtLabel(selectedAccount, window.name)"></span>
|
|
169
|
+
</div>
|
|
170
|
+
</template>
|
|
171
|
+
</div>
|
|
151
172
|
</div>
|
|
152
|
-
</
|
|
173
|
+
</template>
|
|
153
174
|
</div>
|
|
154
175
|
|
|
176
|
+
<div class="mt-4 p-3 bg-space-800/50 border border-space-border/30 rounded-lg">
|
|
177
|
+
<div class="flex items-center justify-between gap-3 mb-2">
|
|
178
|
+
<div>
|
|
179
|
+
<h4 class="text-sm font-semibold text-gray-200">Rate-limit reset credits</h4>
|
|
180
|
+
<p class="text-xs text-gray-500">Redeeming a credit resets this account's upstream quota.</p>
|
|
181
|
+
</div>
|
|
182
|
+
<button class="btn btn-xs btn-outline text-gray-400" @click="loadRateLimitResetCredits(selectedAccount.email)" :disabled="resetCreditsLoading || resetCreditsRedeeming">Refresh</button>
|
|
183
|
+
</div>
|
|
184
|
+
<template x-if="resetCreditsRefreshPending">
|
|
185
|
+
<p class="text-xs text-neon-cyan">Reset complete. Refreshing quota in 3 seconds...</p>
|
|
186
|
+
</template>
|
|
187
|
+
<template x-if="resetCreditsLoading && !resetCreditsRefreshPending">
|
|
188
|
+
<p class="text-xs text-gray-500">Loading reset credits...</p>
|
|
189
|
+
</template>
|
|
190
|
+
<template x-if="!resetCreditsLoading && !resetCreditsRefreshPending && !availableRateLimitResetCredits().length">
|
|
191
|
+
<p class="text-xs text-gray-500">No available reset credits.</p>
|
|
192
|
+
</template>
|
|
193
|
+
<template x-if="!resetCreditsLoading && !resetCreditsRefreshPending && availableRateLimitResetCredits().length">
|
|
194
|
+
<div class="space-y-2">
|
|
195
|
+
<template x-for="credit in availableRateLimitResetCredits()" :key="credit.id">
|
|
196
|
+
<div class="flex items-center justify-between gap-4 rounded-lg border border-space-border/30 bg-space-900/40 p-3">
|
|
197
|
+
<div class="min-w-0 flex-1">
|
|
198
|
+
<div class="flex items-center gap-2">
|
|
199
|
+
<span class="truncate text-sm font-semibold text-gray-200" x-text="credit.title || 'Full reset'"></span>
|
|
200
|
+
<span class="shrink-0 rounded border border-neon-green/30 bg-neon-green/10 px-1.5 py-0.5 text-[9px] font-bold uppercase text-neon-green">Available</span>
|
|
201
|
+
</div>
|
|
202
|
+
<p class="mt-1 truncate text-xs text-gray-500" x-text="credit.description || credit.id"></p>
|
|
203
|
+
<div class="mt-2 flex items-center gap-1.5 text-[10px] text-gray-500">
|
|
204
|
+
<svg class="h-3 w-3 shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4l3 2m6-2a9 9 0 11-18 0 9 9 0 0118 0z"/></svg>
|
|
205
|
+
<span>Expires</span>
|
|
206
|
+
<span class="font-mono text-gray-400" x-text="resetCreditExpiryLabel(credit)"></span>
|
|
207
|
+
</div>
|
|
208
|
+
</div>
|
|
209
|
+
<button class="btn btn-xs shrink-0 bg-neon-purple hover:bg-purple-600 border-none text-white" @click="redeemRateLimitResetCredit(credit.id)" :disabled="resetCreditsRedeeming" x-text="resetCreditsRefreshPending ? 'Refreshing quota...' : resetCreditsRedeeming ? 'Resetting...' : 'Reset quota'"></button>
|
|
210
|
+
</div>
|
|
211
|
+
</template>
|
|
212
|
+
</div>
|
|
213
|
+
</template>
|
|
214
|
+
</div>
|
|
215
|
+
|
|
155
216
|
<div class="mt-6 flex justify-end">
|
|
156
|
-
<button class="btn btn-outline btn-sm text-gray-400" @click="showQuotaModalView = false"
|
|
217
|
+
<button class="btn btn-outline btn-sm text-gray-400" @click="showQuotaModalView = false" :disabled="resetCreditsRedeeming" x-text="resetCreditsRefreshPending ? 'Refreshing quota...' : 'Close'"></button>
|
|
157
218
|
</div>
|
|
158
219
|
</div>
|
|
159
220
|
</div>
|
|
@@ -39,21 +39,22 @@
|
|
|
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-[980px]">
|
|
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="py-3 text-center text-[10px] font-bold text-gray-500 uppercase tracking-wider
|
|
46
|
+
<th class="w-56 py-3 text-center text-[10px] font-bold text-gray-500 uppercase tracking-wider">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>
|
|
50
51
|
<th class="py-3 pr-6 text-right text-[10px] font-bold text-gray-500 uppercase tracking-wider w-40">Operations</th>
|
|
51
52
|
</tr>
|
|
52
53
|
</thead>
|
|
53
54
|
<tbody>
|
|
54
55
|
<template x-if="filteredAccounts.length === 0 && accounts.length === 0">
|
|
55
56
|
<tr>
|
|
56
|
-
<td colspan="
|
|
57
|
+
<td colspan="7" class="py-16 text-center flex justify-center">
|
|
57
58
|
<div class="flex flex-col items-center gap-4 max-w-lg mx-auto">
|
|
58
59
|
<svg class="w-20 h-20 text-gray-700" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
59
60
|
<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" />
|
|
@@ -83,16 +84,16 @@
|
|
|
83
84
|
<td class="py-4 pl-6">
|
|
84
85
|
<div class="flex items-center gap-2">
|
|
85
86
|
<div class="w-2 h-2 rounded-full flex-shrink-0"
|
|
86
|
-
:class="acc.isActive ? 'bg-neon-green shadow-[0_0_8px_rgba(34,197,94,0.6)] animate-pulse' : 'bg-gray-500'">
|
|
87
|
+
:class="acc.accountExpired ? 'bg-red-500' : acc.isActive ? 'bg-neon-green shadow-[0_0_8px_rgba(34,197,94,0.6)] animate-pulse' : 'bg-gray-500'">
|
|
87
88
|
</div>
|
|
88
89
|
<span class="text-xs font-mono font-semibold"
|
|
89
|
-
:class="acc.isActive ? 'text-neon-green' : 'text-gray-500'"
|
|
90
|
-
x-text="acc.isActive ? 'ACTIVE' : 'IDLE'">
|
|
90
|
+
:class="acc.accountExpired ? 'text-red-400' : acc.isActive ? 'text-neon-green' : 'text-gray-500'"
|
|
91
|
+
x-text="acc.accountExpired ? 'EXPIRED' : acc.isActive ? 'ACTIVE' : 'IDLE'">
|
|
91
92
|
</span>
|
|
92
93
|
</div>
|
|
93
94
|
</td>
|
|
94
|
-
<td class="py-4 text-center">
|
|
95
|
-
<span class="font-mono text-sm text-gray-300
|
|
95
|
+
<td class="w-56 max-w-56 py-4 text-center">
|
|
96
|
+
<span class="inline-block max-w-[13rem] truncate font-mono text-sm text-gray-300 transition-colors group-hover:text-white"
|
|
96
97
|
x-text="acc.email"></span>
|
|
97
98
|
</td>
|
|
98
99
|
<td class="py-4">
|
|
@@ -146,9 +147,27 @@
|
|
|
146
147
|
<span class="text-xs text-gray-600">-</span>
|
|
147
148
|
</template>
|
|
148
149
|
</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>
|
|
149
168
|
<td class="py-4 pr-6">
|
|
150
169
|
<div class="flex justify-end gap-2">
|
|
151
|
-
<button x-show="!acc.isActive"
|
|
170
|
+
<button x-show="!acc.isActive && !acc.accountExpired"
|
|
152
171
|
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"
|
|
153
172
|
@click="switchAccount(acc.email)">
|
|
154
173
|
SWITCH
|
|
@@ -166,7 +185,7 @@
|
|
|
166
185
|
|
|
167
186
|
<template x-if="accounts.length > 0 && filteredAccounts.length === 0">
|
|
168
187
|
<tr>
|
|
169
|
-
<td colspan="
|
|
188
|
+
<td colspan="7" class="py-12 text-center">
|
|
170
189
|
<div class="flex flex-col items-center gap-3">
|
|
171
190
|
<svg class="w-12 h-12 text-gray-700" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
172
191
|
<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,6 +14,20 @@
|
|
|
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
|
+
<label class="flex items-center justify-between gap-4 rounded-lg border border-space-border bg-space-800 px-3 py-2.5">
|
|
23
|
+
<span class="text-xs text-gray-300">Enable fixed 5-hour limit</span>
|
|
24
|
+
<input type="checkbox" x-model="clientApiKeyFiveHourLimitEnabled" class="h-4 w-4 accent-purple-500">
|
|
25
|
+
</label>
|
|
26
|
+
<label class="block">
|
|
27
|
+
<span class="block text-xs text-gray-400 mb-2">5-hour limit (USD)</span>
|
|
28
|
+
<input type="number" min="0" step="0.01" x-model="clientApiKeyFiveHourLimitUsd" :disabled="!clientApiKeyFiveHourLimitEnabled"
|
|
29
|
+
class="input w-full bg-space-800 border-space-border text-white font-mono text-sm disabled:opacity-40" @keydown.enter="createClientApiKey()">
|
|
30
|
+
</label>
|
|
17
31
|
</div>
|
|
18
32
|
<div class="mt-6 flex justify-end gap-2">
|
|
19
33
|
<button class="btn btn-outline btn-sm text-gray-400" @click="showCreateClientApiKeyModal = false" :disabled="clientApiKeySaving">Cancel</button>
|
|
@@ -35,8 +49,8 @@
|
|
|
35
49
|
<p class="text-xs font-semibold uppercase tracking-wider text-gray-400">Claude Code configuration</p>
|
|
36
50
|
<div class="rounded-lg border border-space-border bg-space-800 p-3 font-mono text-xs text-gray-300 space-y-2">
|
|
37
51
|
<div><span class="text-gray-500">ANTHROPIC_BASE_URL=</span><span class="break-all" x-text="clientProxyConfig.env.ANTHROPIC_BASE_URL"></span></div>
|
|
52
|
+
<div><span class="text-gray-500">ANTHROPIC_AUTH_TOKEN=</span><span class="break-all" x-text="revealedClientApiKey"></span></div>
|
|
38
53
|
<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>
|
|
40
54
|
</div>
|
|
41
55
|
<p class="text-xs text-gray-500" x-text="clientProxyConfig.message"></p>
|
|
42
56
|
<button class="btn btn-outline btn-sm text-gray-300" @click="copyClientProxyCommands()">Copy PowerShell Commands</button>
|
|
@@ -8,39 +8,76 @@
|
|
|
8
8
|
</div>
|
|
9
9
|
</div>
|
|
10
10
|
|
|
11
|
-
<div class="
|
|
12
|
-
<div class="
|
|
13
|
-
<
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
</
|
|
11
|
+
<div class="client-keys-panel">
|
|
12
|
+
<div class="client-keys-toolbar">
|
|
13
|
+
<div>
|
|
14
|
+
<h2>Access keys</h2>
|
|
15
|
+
<p>Edit a key, then save its changes.</p>
|
|
16
|
+
</div>
|
|
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>
|
|
17
26
|
</div>
|
|
27
|
+
|
|
18
28
|
<template x-if="clientApiKeysLoading">
|
|
19
|
-
<div class="
|
|
29
|
+
<div class="client-keys-empty">Loading client API keys...</div>
|
|
20
30
|
</template>
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
<
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
<
|
|
37
|
-
<
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
31
|
+
|
|
32
|
+
<div class="client-keys-list" x-show="!clientApiKeysLoading && clientApiKeys.length">
|
|
33
|
+
<template x-for="clientApiKey in clientApiKeys" :key="clientApiKey.id">
|
|
34
|
+
<article class="client-key-card">
|
|
35
|
+
<div class="client-key-identity">
|
|
36
|
+
<div class="client-key-icon">
|
|
37
|
+
<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="M15 7a5 5 0 11-9.6 2H3v4h3v3h3v-3h2.4A5 5 0 0115 7z"/></svg>
|
|
38
|
+
</div>
|
|
39
|
+
<div class="client-key-fields">
|
|
40
|
+
<label><span>Client name</span><input type="text" x-model="clientApiKey.name" placeholder="Unnamed"></label>
|
|
41
|
+
<label><span>Remark</span><input type="text" x-model="clientApiKey.remark" placeholder="No remark"></label>
|
|
42
|
+
</div>
|
|
43
|
+
</div>
|
|
44
|
+
|
|
45
|
+
<div class="client-key-quotas">
|
|
46
|
+
<div class="client-key-quota">
|
|
47
|
+
<div class="client-key-quota-heading">
|
|
48
|
+
<span>Weekly usage</span>
|
|
49
|
+
<strong><span x-text="`$${(clientApiKey.quota?.consumedUsd ?? 0).toFixed(2)}`"></span><small x-text="` / $${Number(clientApiKey.weeklyLimitUsd || 0).toFixed(2)}`"></small></strong>
|
|
50
|
+
</div>
|
|
51
|
+
<div class="client-key-progress"><i :style="`width: ${Math.min(100, Math.max(0, ((clientApiKey.quota?.consumedUsd ?? 0) / Math.max(Number(clientApiKey.weeklyLimitUsd) || 0, 0.000001)) * 100))}%`"></i></div>
|
|
52
|
+
<div class="client-key-quota-foot"><span x-text="`$${(clientApiKey.quota?.remainingUsd ?? (Number(clientApiKey.weeklyLimitUsd) || 0)).toFixed(2)} remaining`"></span><span x-text="`${Math.min(100, Math.max(0, ((clientApiKey.quota?.consumedUsd ?? 0) / Math.max(Number(clientApiKey.weeklyLimitUsd) || 0, 0.000001)) * 100)).toFixed(1)}% used`"></span></div>
|
|
53
|
+
</div>
|
|
54
|
+
<div class="client-key-quota" :class="{ 'client-key-quota-disabled': !clientApiKey.fiveHourLimitEnabled }">
|
|
55
|
+
<div class="client-key-quota-heading">
|
|
56
|
+
<span>5-hour usage</span>
|
|
57
|
+
<strong x-text="clientApiKey.fiveHourLimitEnabled ? `$${(clientApiKey.quota?.fiveHourConsumedUsd ?? 0).toFixed(2)} / $${Number(clientApiKey.fiveHourLimitUsd || 0).toFixed(2)}` : 'Off'"></strong>
|
|
58
|
+
</div>
|
|
59
|
+
<div class="client-key-progress"><i :style="`width: ${clientApiKey.fiveHourLimitEnabled ? Math.min(100, Math.max(0, ((clientApiKey.quota?.fiveHourConsumedUsd ?? 0) / Math.max(Number(clientApiKey.fiveHourLimitUsd) || 0, 0.000001)) * 100)) : 0}%`"></i></div>
|
|
60
|
+
<div class="client-key-quota-foot"><span x-text="clientApiKey.fiveHourLimitEnabled ? `$${(clientApiKey.quota?.fiveHourRemainingUsd ?? (Number(clientApiKey.fiveHourLimitUsd) || 0)).toFixed(2)} remaining` : 'Limit disabled'"></span><span x-text="clientApiKey.fiveHourLimitEnabled && clientApiKey.quota?.nextFiveHourPeriodStart ? new Date(clientApiKey.quota.nextFiveHourPeriodStart).toLocaleTimeString() : ''"></span></div>
|
|
61
|
+
</div>
|
|
62
|
+
</div>
|
|
63
|
+
|
|
64
|
+
<div class="client-key-limits">
|
|
65
|
+
<label class="client-key-limit"><span>Weekly limit</span><div><b>$</b><input type="number" min="0" step="0.01" x-model="clientApiKey.weeklyLimitUsd"></div></label>
|
|
66
|
+
<label class="client-key-limit-toggle"><input type="checkbox" x-model="clientApiKey.fiveHourLimitEnabled"><span>5-hour limit</span></label>
|
|
67
|
+
<label class="client-key-limit"><div><b>$</b><input type="number" min="0" step="0.01" x-model="clientApiKey.fiveHourLimitUsd" :disabled="!clientApiKey.fiveHourLimitEnabled"></div></label>
|
|
68
|
+
</div>
|
|
69
|
+
|
|
70
|
+
<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>
|
|
71
|
+
|
|
72
|
+
<div class="client-key-actions">
|
|
73
|
+
<button class="client-key-save" @click="updateClientApiKey(clientApiKey)" :disabled="clientApiKeySaving">Save changes</button>
|
|
74
|
+
<button class="client-key-delete" @click="deleteClientApiKey(clientApiKey)" :disabled="clientApiKeySaving" aria-label="Delete API key" title="Delete">
|
|
75
|
+
<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>
|
|
76
|
+
</button>
|
|
77
|
+
</div>
|
|
78
|
+
</article>
|
|
79
|
+
</template>
|
|
80
|
+
</div>
|
|
81
|
+
<div x-show="!clientApiKeysLoading && !clientApiKeys.length" class="client-keys-empty">No client API keys. Create one to connect Claude Code clients.</div>
|
|
45
82
|
</div>
|
|
46
83
|
</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="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/account-manager.js
CHANGED
|
@@ -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];
|
|
@@ -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 };
|