claude-codex-proxy 1.0.5-beta.19 → 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.
- package/package.json +1 -1
- package/public/js/app.js +37 -2
- package/public/views/accounts-modals.html +9 -6
- package/src/direct-api.js +5 -2
package/package.json
CHANGED
package/public/js/app.js
CHANGED
|
@@ -13,7 +13,7 @@ document.addEventListener('alpine:init', () => {
|
|
|
13
13
|
clientApiKeySaving: false, revealedClientApiKey: '', clientProxyConfig: null, showCreateClientApiKeyModal: false,
|
|
14
14
|
showAddModal: false, showDeleteModal: false, deleteTarget: '', showQuotaModalView: false, selectedAccount: null,
|
|
15
15
|
showAccountExpirationModalView: false, expirationTarget: null, accountExpirationInput: '', accountExpirationSaving: false,
|
|
16
|
-
resetCreditsLoading: false, resetCreditsRedeeming: false, resetCredits: [], resetCreditsAccountEmail: '', resetCreditRedeemRequestId: '',
|
|
16
|
+
resetCreditsLoading: false, resetCreditsRedeeming: false, resetCreditsRefreshPending: false, resetCredits: [], resetCreditsAccountEmail: '', resetCreditRedeemRequestId: '',
|
|
17
17
|
oauthManualMode: false, oauthManualUrl: '', oauthManualVerifier: '', oauthManualCode: '',
|
|
18
18
|
testPrompt: 'Say hello', testResponse: '', testing: false, configPath: '~/.claude-codex-proxy/accounts.json',
|
|
19
19
|
serverUrl: window.location.origin, logs: [], logSearchQuery: '', logPage: 1, logPageSize: 30, logTotal: 0, logTotalPages: 0, logLoading: false,
|
|
@@ -142,7 +142,42 @@ document.addEventListener('alpine:init', () => {
|
|
|
142
142
|
hex.slice(10, 16).join('')
|
|
143
143
|
].join('-');
|
|
144
144
|
},
|
|
145
|
-
async redeemRateLimitResetCredit(creditId = null) {
|
|
145
|
+
async redeemRateLimitResetCredit(creditId = null) {
|
|
146
|
+
if (!this.selectedAccount || this.resetCreditsRedeeming) return;
|
|
147
|
+
const email = this.selectedAccount.email;
|
|
148
|
+
this.resetCreditsRedeeming = true;
|
|
149
|
+
this.resetCreditsRefreshPending = false;
|
|
150
|
+
try {
|
|
151
|
+
if (!this.resetCreditRedeemRequestId) this.resetCreditRedeemRequestId = this.generateUUID();
|
|
152
|
+
const { ok, data } = await this.api('/accounts/rate-limit-reset-credits/consume', {
|
|
153
|
+
method: 'POST',
|
|
154
|
+
body: JSON.stringify({ email, creditId: creditId || undefined, redeemRequestId: this.resetCreditRedeemRequestId })
|
|
155
|
+
});
|
|
156
|
+
if (!ok || !data?.success) {
|
|
157
|
+
this.showToast(data?.error || 'Failed to redeem reset credit', 'error');
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
this.resetCreditRedeemRequestId = '';
|
|
162
|
+
this.resetCreditsRefreshPending = true;
|
|
163
|
+
await this.loadRateLimitResetCredits(email);
|
|
164
|
+
await new Promise(resolve => setTimeout(resolve, 3000));
|
|
165
|
+
const { ok: quotaOk, data: quotaData } = await this.api(`/accounts/quota?email=${encodeURIComponent(email)}&refresh=true`);
|
|
166
|
+
if (!quotaOk || !quotaData?.quota) {
|
|
167
|
+
this.showToast(quotaData?.error || 'Quota reset succeeded, but quota refresh failed', 'error');
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
this.accounts = this.accounts.map(account => account.email === email ? { ...account, quota: quotaData.quota } : account);
|
|
172
|
+
if (this.selectedAccount?.email === email) {
|
|
173
|
+
this.selectedAccount = { ...this.selectedAccount, quota: quotaData.quota };
|
|
174
|
+
}
|
|
175
|
+
this.showToast('Quota reset and refreshed', 'success');
|
|
176
|
+
} finally {
|
|
177
|
+
this.resetCreditsRefreshPending = false;
|
|
178
|
+
this.resetCreditsRedeeming = false;
|
|
179
|
+
}
|
|
180
|
+
},
|
|
146
181
|
async testChat() { if (!this.testPrompt.trim()) return; this.testing = true; this.testResponse = ''; const { ok, data } = await this.api('/v1/chat/completions', { method: 'POST', body: JSON.stringify({ model: this.modelMappings?.sonnet || 'gpt-5.5', messages: [{ role: 'user', content: this.testPrompt }] }) }); this.testing = false; this.testResponse = ok && data.choices ? data.choices[0]?.message?.content || `[Empty response]\n\n${JSON.stringify(data, null, 2)}` : data?.error?.message || data?.error || 'Request failed'; },
|
|
147
182
|
async loadAccountStrategySetting() { const { ok, data } = await this.api('/settings/account-strategy'); if (ok && data?.accountStrategy) this.accountStrategy = data.accountStrategy; }, async setAccountStrategy(strategy) { if (this.strategySaving || this.accountStrategy === strategy) return; this.strategySaving = true; const { ok, data } = await this.api('/settings/account-strategy', { method: 'POST', body: JSON.stringify({ accountStrategy: strategy }) }); this.strategySaving = false; if (ok && data?.accountStrategy) this.accountStrategy = data.accountStrategy; else this.showToast(data?.error || 'Failed to update strategy', 'error'); },
|
|
148
183
|
async loadRawProxyLogsSetting() { const { ok, data } = await this.api('/settings/raw-proxy-logs'); if (ok && typeof data?.logRawProxyPayloads === 'boolean') this.logRawProxyPayloads = data.logRawProxyPayloads; }, async setRawProxyLogs(enabled) { if (this.rawProxyLogsSaving || this.logRawProxyPayloads === enabled) return; this.rawProxyLogsSaving = true; const { ok, data } = await this.api('/settings/raw-proxy-logs', { method: 'POST', body: JSON.stringify({ enabled }) }); this.rawProxyLogsSaving = false; if (ok && typeof data?.logRawProxyPayloads === 'boolean') this.logRawProxyPayloads = data.logRawProxyPayloads; else this.showToast(data?.error || 'Failed to update raw proxy logging', 'error'); },
|
|
@@ -128,7 +128,7 @@
|
|
|
128
128
|
</div>
|
|
129
129
|
|
|
130
130
|
<div x-show="showQuotaModalView" x-transition class="fixed inset-0 z-50 flex items-center justify-center p-4" style="display: none;">
|
|
131
|
-
<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>
|
|
132
132
|
<div class="relative bg-space-900 border border-space-border rounded-xl shadow-2xl max-w-lg w-full p-6">
|
|
133
133
|
<h3 class="font-bold text-lg text-white mb-2 flex items-center gap-2">
|
|
134
134
|
<svg class="w-6 h-6 text-neon-cyan" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
@@ -179,13 +179,16 @@
|
|
|
179
179
|
</div>
|
|
180
180
|
<button class="btn btn-xs btn-outline text-gray-400" @click="loadRateLimitResetCredits(selectedAccount.email)" :disabled="resetCreditsLoading || resetCreditsRedeeming">Refresh</button>
|
|
181
181
|
</div>
|
|
182
|
-
<template x-if="
|
|
182
|
+
<template x-if="resetCreditsRefreshPending">
|
|
183
|
+
<p class="text-xs text-neon-cyan">Reset complete. Refreshing quota in 3 seconds...</p>
|
|
184
|
+
</template>
|
|
185
|
+
<template x-if="resetCreditsLoading && !resetCreditsRefreshPending">
|
|
183
186
|
<p class="text-xs text-gray-500">Loading reset credits...</p>
|
|
184
187
|
</template>
|
|
185
|
-
<template x-if="!resetCreditsLoading && !availableRateLimitResetCredits().length">
|
|
188
|
+
<template x-if="!resetCreditsLoading && !resetCreditsRefreshPending && !availableRateLimitResetCredits().length">
|
|
186
189
|
<p class="text-xs text-gray-500">No available reset credits.</p>
|
|
187
190
|
</template>
|
|
188
|
-
<template x-if="!resetCreditsLoading && availableRateLimitResetCredits().length">
|
|
191
|
+
<template x-if="!resetCreditsLoading && !resetCreditsRefreshPending && availableRateLimitResetCredits().length">
|
|
189
192
|
<div class="space-y-2">
|
|
190
193
|
<template x-for="credit in availableRateLimitResetCredits()" :key="credit.id">
|
|
191
194
|
<div class="flex items-center justify-between gap-4 rounded-lg border border-space-border/30 bg-space-900/40 p-3">
|
|
@@ -201,7 +204,7 @@
|
|
|
201
204
|
<span class="font-mono text-gray-400" x-text="resetCreditExpiryLabel(credit)"></span>
|
|
202
205
|
</div>
|
|
203
206
|
</div>
|
|
204
|
-
<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="resetCreditsRedeeming ? 'Resetting...' : 'Reset quota'"></button>
|
|
207
|
+
<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>
|
|
205
208
|
</div>
|
|
206
209
|
</template>
|
|
207
210
|
</div>
|
|
@@ -209,7 +212,7 @@
|
|
|
209
212
|
</div>
|
|
210
213
|
|
|
211
214
|
<div class="mt-6 flex justify-end">
|
|
212
|
-
<button class="btn btn-outline btn-sm text-gray-400" @click="showQuotaModalView = false"
|
|
215
|
+
<button class="btn btn-outline btn-sm text-gray-400" @click="showQuotaModalView = false" :disabled="resetCreditsRedeeming" x-text="resetCreditsRefreshPending ? 'Refreshing quota...' : 'Close'"></button>
|
|
213
216
|
</div>
|
|
214
217
|
</div>
|
|
215
218
|
</div>
|
package/src/direct-api.js
CHANGED
|
@@ -14,6 +14,7 @@ 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
|
+
const UPSTREAM_REQUEST_TIMEOUT_MS = 4 * 60 * 1000;
|
|
17
18
|
|
|
18
19
|
function createAnthropicUsage(upstreamUsage = {}) {
|
|
19
20
|
const usage = {
|
|
@@ -128,7 +129,8 @@ async function createResponsesAPIStreamResponse(anthropicRequest, accessToken, a
|
|
|
128
129
|
const response = await fetch(API_URL, {
|
|
129
130
|
method: 'POST',
|
|
130
131
|
headers: buildOpencodeHeaders(accessToken, accountId, context),
|
|
131
|
-
body: JSON.stringify(request)
|
|
132
|
+
body: JSON.stringify(request),
|
|
133
|
+
signal: AbortSignal.timeout(UPSTREAM_REQUEST_TIMEOUT_MS)
|
|
132
134
|
});
|
|
133
135
|
|
|
134
136
|
if (response.ok) return response;
|
|
@@ -195,7 +197,8 @@ export async function sendMessage(anthropicRequest, accessToken, accountId, cont
|
|
|
195
197
|
const response = await fetch(API_URL, {
|
|
196
198
|
method: 'POST',
|
|
197
199
|
headers: buildOpencodeHeaders(accessToken, accountId, context),
|
|
198
|
-
body: JSON.stringify(request)
|
|
200
|
+
body: JSON.stringify(request),
|
|
201
|
+
signal: AbortSignal.timeout(UPSTREAM_REQUEST_TIMEOUT_MS)
|
|
199
202
|
});
|
|
200
203
|
|
|
201
204
|
if (!response.ok) {
|