claude-codex-proxy 1.0.5-beta.4 → 1.0.5-beta.40
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/js/app.js +105 -26
- package/public/views/accounts-modals.html +90 -29
- package/public/views/accounts.html +29 -10
- package/public/views/client-api-keys-modals.html +10 -1
- package/public/views/client-api-keys.html +68 -39
- package/public/views/logs.html +10 -3
- package/public/views/settings.html +11 -1
- package/src/account-manager.js +34 -3
- package/src/account-rotation/index.js +6 -0
- package/src/account-rotation/rate-limits.js +4 -0
- package/src/account-rotation/strategies/base-strategy.js +4 -0
- package/src/account-rotation/strategies/round-robin-strategy.js +78 -3
- package/src/account-rotation/strategies/sticky-strategy.js +7 -0
- package/src/admin-path.js +33 -0
- package/src/client-key-usage.js +193 -125
- package/src/daily-anchor-ping.js +149 -0
- package/src/direct-api.js +6 -5
- package/src/format-converter.js +83 -48
- package/src/index.js +13 -4
- package/src/middleware/auth.js +23 -20
- package/src/middleware/credentials.js +17 -7
- package/src/middleware/sse.js +72 -30
- package/src/model-api.js +86 -13
- package/src/model-pricing.js +187 -96
- package/src/response-streamer.js +18 -2
- package/src/routes/accounts-route.js +106 -2
- package/src/routes/api-routes.js +59 -42
- package/src/routes/chat-route.js +5 -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 +135 -55
- package/src/routes/models-route.js +5 -0
- package/src/routes/settings-route.js +40 -10
- package/src/server-settings.js +9 -2
- package/src/server.js +4 -0
- package/src/utils/logger.js +34 -2
- package/src/utils/proxy-logging.js +5 -5
package/public/js/app.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
const adminPath = window.__PROXY_ADMIN_PATH__ || '/admin';
|
|
2
|
+
const adminUrl = (path) => `${adminPath}${path}`;
|
|
3
|
+
|
|
1
4
|
document.addEventListener('alpine:init', () => {
|
|
2
5
|
Alpine.data('app', () => ({
|
|
3
6
|
version: '', connectionStatus: 'connecting', activeTab: '', sidebarOpen: window.innerWidth >= 1024,
|
|
@@ -6,12 +9,15 @@ document.addEventListener('alpine:init', () => {
|
|
|
6
9
|
accounts: [], searchQuery: '', stats: { total: 0, active: 0, expired: 0, planType: '-' },
|
|
7
10
|
accountStrategy: 'sticky', modelMappings: { sonnet: '', opus: '', haiku: '' }, modelMapLoading: false,
|
|
8
11
|
modelMapSaving: false, strategySaving: false, logRawProxyPayloads: false, rawProxyLogsSaving: false,
|
|
9
|
-
clientApiKeys: [], clientApiKeyName: '', clientApiKeyRemark: '', clientApiKeyWeeklyLimitUsd: 50,
|
|
12
|
+
clientApiKeys: [], clientApiKeyName: '', clientApiKeyRemark: '', clientApiKeyWeeklyLimitUsd: 50,
|
|
13
|
+
clientApiKeyFiveHourLimitEnabled: false, clientApiKeyFiveHourLimitUsd: 0, clientApiKeysLoading: false,
|
|
10
14
|
clientApiKeySaving: false, revealedClientApiKey: '', clientProxyConfig: null, showCreateClientApiKeyModal: false,
|
|
11
15
|
showAddModal: false, showDeleteModal: false, deleteTarget: '', showQuotaModalView: false, selectedAccount: null,
|
|
16
|
+
showAccountExpirationModalView: false, expirationTarget: null, accountExpirationInput: '', accountExpirationSaving: false,
|
|
17
|
+
resetCreditsLoading: false, resetCreditsRedeeming: false, resetCreditsRefreshPending: false, resetCredits: [], resetCreditsAccountEmail: '', resetCreditRedeemRequestId: '',
|
|
12
18
|
oauthManualMode: false, oauthManualUrl: '', oauthManualVerifier: '', oauthManualCode: '',
|
|
13
19
|
testPrompt: 'Say hello', testResponse: '', testing: false, configPath: '~/.claude-codex-proxy/accounts.json',
|
|
14
|
-
serverUrl: window.location.origin, logs: [], logSearchQuery: '',
|
|
20
|
+
serverUrl: window.location.origin, logs: [], logSearchQuery: '', logPage: 1, logPageSize: 30, logTotal: 0, logTotalPages: 0, logLoading: false,
|
|
15
21
|
logFilters: { INFO: true, SUCCESS: true, WARN: true, ERROR: true, DEBUG: false }, logEventSource: null,
|
|
16
22
|
|
|
17
23
|
get isAuthenticated() { return !this.authRequired || Boolean(this.apiKey); },
|
|
@@ -22,10 +28,10 @@ document.addEventListener('alpine:init', () => {
|
|
|
22
28
|
await this.checkHealth();
|
|
23
29
|
this.authChecked = true;
|
|
24
30
|
if (this.isLoginPage()) {
|
|
25
|
-
if (this.isAuthenticated) window.location.replace('/dashboard');
|
|
31
|
+
if (this.isAuthenticated) window.location.replace(adminUrl('/dashboard'));
|
|
26
32
|
return;
|
|
27
33
|
}
|
|
28
|
-
if (!this.isAuthenticated) { window.location.replace('/login'); return; }
|
|
34
|
+
if (!this.isAuthenticated) { window.location.replace(adminUrl('/login')); return; }
|
|
29
35
|
await this.loadCurrentView();
|
|
30
36
|
this.updateTime();
|
|
31
37
|
setInterval(() => this.updateTime(), 1000);
|
|
@@ -34,18 +40,18 @@ document.addEventListener('alpine:init', () => {
|
|
|
34
40
|
window.addEventListener('message', event => { if (event.data?.type === 'oauth-success') { this.showToast(`Account ${event.data.email} added!`, 'success'); this.showAddModal = false; this.refreshAccounts(); } });
|
|
35
41
|
},
|
|
36
42
|
|
|
37
|
-
isLoginPage() { return window.location.pathname === '/login' || window.location.pathname === '/login.html'; },
|
|
43
|
+
isLoginPage() { return window.location.pathname === adminUrl('/login') || window.location.pathname === adminUrl('/login.html'); },
|
|
38
44
|
async loadCurrentView() {
|
|
39
|
-
const route = window.location.pathname.replace(/^\//, '').replace(/\.html$/, '') || 'dashboard';
|
|
45
|
+
const route = window.location.pathname.slice(adminPath.length).replace(/^\//, '').replace(/\.html$/, '') || 'dashboard';
|
|
40
46
|
const tab = route === 'account-management' ? 'accounts' : route;
|
|
41
47
|
const validTabs = ['dashboard', 'accounts', 'logs', 'client-api-keys', 'settings'];
|
|
42
48
|
this.activeTab = validTabs.includes(tab) ? tab : 'dashboard';
|
|
43
|
-
if (this.activeTab !== tab) { window.location.replace('/dashboard'); return; }
|
|
49
|
+
if (this.activeTab !== tab) { window.location.replace(adminUrl('/dashboard')); return; }
|
|
44
50
|
const [viewResponse, modalResponse] = await Promise.all([
|
|
45
|
-
fetch(`/views/${this.activeTab}.html`),
|
|
46
|
-
fetch(this.activeTab === 'accounts' ? '/views/accounts-modals.html' : this.activeTab === 'client-api-keys' ? '/views/client-api-keys-modals.html' : '/views/empty.html')
|
|
51
|
+
fetch(adminUrl(`/views/${this.activeTab}.html`)),
|
|
52
|
+
fetch(adminUrl(this.activeTab === 'accounts' ? '/views/accounts-modals.html' : this.activeTab === 'client-api-keys' ? '/views/client-api-keys-modals.html' : '/views/empty.html'))
|
|
47
53
|
]);
|
|
48
|
-
if (!viewResponse.ok) { window.location.replace('/dashboard'); return; }
|
|
54
|
+
if (!viewResponse.ok) { window.location.replace(adminUrl('/dashboard')); return; }
|
|
49
55
|
document.querySelector('#view-content').innerHTML = await viewResponse.text();
|
|
50
56
|
document.querySelector('#modal-content').innerHTML = modalResponse.ok ? await modalResponse.text() : '';
|
|
51
57
|
Alpine.initTree(document.querySelector('#view-content'));
|
|
@@ -66,7 +72,8 @@ document.addEventListener('alpine:init', () => {
|
|
|
66
72
|
try {
|
|
67
73
|
const headers = { 'Content-Type': 'application/json', ...(options.headers || {}) };
|
|
68
74
|
if (this.apiKey) headers.Authorization = `Bearer ${this.apiKey}`;
|
|
69
|
-
const
|
|
75
|
+
const url = endpoint.startsWith('/v1/') ? endpoint : adminUrl(endpoint);
|
|
76
|
+
const response = await fetch(url, { ...options, headers });
|
|
70
77
|
const data = await response.json();
|
|
71
78
|
if (response.status === 401 && endpoint !== '/health') this.logout(false);
|
|
72
79
|
return { ok: response.ok, data };
|
|
@@ -79,28 +86,100 @@ document.addEventListener('alpine:init', () => {
|
|
|
79
86
|
const { ok } = await this.api('/settings/account-strategy');
|
|
80
87
|
if (!ok) { this.apiKey = ''; this.loginError = 'Access key is invalid or expired'; return; }
|
|
81
88
|
localStorage.setItem('codexProxyApiKey', key);
|
|
82
|
-
window.location.replace('/dashboard');
|
|
89
|
+
window.location.replace(adminUrl('/dashboard'));
|
|
83
90
|
},
|
|
84
|
-
logout(showMessage = true) { this.apiKey = ''; this.loginApiKey = ''; localStorage.removeItem('codexProxyApiKey'); this.logEventSource?.close(); this.logEventSource = null; if (showMessage) window.location.replace('/login'); },
|
|
85
|
-
async checkHealth() {
|
|
91
|
+
logout(showMessage = true) { this.apiKey = ''; this.loginApiKey = ''; localStorage.removeItem('codexProxyApiKey'); this.logEventSource?.close(); this.logEventSource = null; if (showMessage) window.location.replace(adminUrl('/login')); },
|
|
92
|
+
async checkHealth() { try { const response = await fetch('/health'); const data = await response.json(); this.connectionStatus = response.ok ? 'connected' : 'disconnected'; if (response.ok && data?.version) this.version = data.version; if (response.ok && typeof data?.publicMode === 'boolean') this.authRequired = data.publicMode; } catch { this.connectionStatus = 'disconnected'; } },
|
|
86
93
|
async refreshAccounts() { this.loading = true; const { ok, data } = await this.api('/accounts'); if (ok && data.accounts) { this.accounts = data.accounts; this.stats = { total: data.total || data.accounts.length, active: data.accounts.filter(a => a.isActive).length, expired: data.accounts.filter(a => a.tokenExpired).length, planType: data.accounts.find(a => a.isActive)?.planType || '-' }; await this.refreshAllQuotaData(); } this.loading = false; },
|
|
87
94
|
async refreshAllQuotaData() { if (!this.accounts.length) return; const { ok, data } = await this.api('/accounts/quota/all'); if (!ok || !data?.accounts) return; const quotaMap = new Map(data.accounts.map(entry => [entry.email, entry.quota || null])); this.accounts = this.accounts.map(account => ({ ...account, quota: quotaMap.has(account.email) ? quotaMap.get(account.email) : account.quota })); if (this.selectedAccount?.email) this.selectedAccount = this.accounts.find(account => account.email === this.selectedAccount.email) || this.selectedAccount; },
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
+
getQuotaWindow(account, windowName = 'primary') { const usage = account?.quota?.usage; if (!usage) return null; const normalized = usage[`${windowName}Window`]; if (normalized) return normalized; return usage?.raw?.rate_limit?.[`${windowName}_window`] || null; },
|
|
96
|
+
getRemainingPercentage(account, windowName = 'primary') { const usage = account?.quota?.usage, window = this.getQuotaWindow(account, windowName); if (!window) return null; const values = [Number(window.remainingPercent), Number.isFinite(Number(window.usedPercent)) ? 100 - Number(window.usedPercent) : NaN, Number.isFinite(Number(window.used_percent)) ? 100 - Number(window.used_percent) : NaN, Number.isFinite(Number(window.remaining)) ? Number(window.remaining) : NaN, windowName === 'primary' && Number.isFinite(Number(usage.remaining)) ? Number(usage.remaining) : NaN]; const remaining = values.find(Number.isFinite); if (!Number.isFinite(remaining)) return windowName === 'primary' && (usage.limitReached === true || usage.allowed === false) ? 0 : null; return Math.max(0, Math.round(Math.min(100, remaining))); },
|
|
97
|
+
isQuotaExhausted(account, windowName = 'primary') { const remaining = this.getRemainingPercentage(account, windowName); return remaining !== null && (remaining <= 0 || (windowName === 'primary' && (account?.quota?.usage?.limitReached === true || account?.quota?.usage?.allowed === false))); },
|
|
98
|
+
quotaBarClass(account, windowName = 'primary') { const remaining = this.getRemainingPercentage(account, windowName); return remaining === null ? 'bg-gray-500' : remaining > 50 ? 'bg-neon-green' : remaining > 20 ? 'bg-yellow-500' : 'bg-red-500'; },
|
|
99
|
+
quotaTextClass(account, windowName = 'primary') { const remaining = this.getRemainingPercentage(account, windowName); return remaining === null ? 'text-gray-500' : remaining <= 20 ? 'text-red-400' : 'text-gray-400'; }, quotaLabel(account, windowName = 'primary') { const remaining = this.getRemainingPercentage(account, windowName); return remaining === null ? '-' : `${remaining}%`; },
|
|
100
|
+
getQuotaResetAt(account, windowName = 'primary') { const window = this.getQuotaWindow(account, windowName); if (!window) return null; if (window.resetAt) return window.resetAt; const epoch = Number(window.reset_at); if (Number.isFinite(epoch) && epoch > 0) return new Date(epoch * 1000).toISOString(); const resetAfter = Number(window.resetAfterSeconds ?? window.reset_after_seconds); return Number.isFinite(resetAfter) && resetAfter > 0 ? new Date(Date.now() + resetAfter * 1000).toISOString() : null; },
|
|
101
|
+
quotaResetAtLabel(account, windowName = 'primary') { const resetAt = this.getQuotaResetAt(account, windowName); const date = resetAt && new Date(resetAt); return date && !Number.isNaN(date.getTime()) ? date.toLocaleString() : null; },
|
|
102
|
+
quotaResetSummary(account, windowName = 'primary') { const resetAt = this.getQuotaResetAt(account, windowName); if (!resetAt) return null; const seconds = Math.max(0, Math.floor((new Date(resetAt).getTime() - Date.now()) / 1000)); if (!seconds) return 'Reset due now'; const days = Math.floor(seconds / 86400), hours = Math.floor((seconds % 86400) / 3600), minutes = Math.floor((seconds % 3600) / 60); return days ? `Resets in ${days}d ${hours}h` : hours ? `Resets in ${hours}h ${minutes}m` : `Resets in ${minutes}m`; },
|
|
95
103
|
async startOAuth() { await this.api('/accounts/oauth/cleanup', { method: 'POST' }); const { ok, data } = await this.api('/accounts/add', { method: 'POST' }); if (ok && data.oauth_url) window.open(data.oauth_url, 'ChatGPT Login', 'width=500,height=700'); else this.showToast(data?.message || 'Failed to start OAuth', 'error'); },
|
|
96
104
|
async startManualOAuth() { await this.api('/accounts/oauth/cleanup', { method: 'POST' }); const { ok, data } = await this.api('/accounts/add', { method: 'POST' }); if (ok && data.oauth_url) { this.oauthManualUrl = data.oauth_url; this.oauthManualVerifier = data.verifier; this.oauthManualCode = ''; this.oauthManualMode = true; } else this.showToast(data?.message || 'Failed to start OAuth', 'error'); },
|
|
97
105
|
async submitManualOAuth() { if (!this.oauthManualCode) return; const { ok, data } = await this.api('/accounts/add/manual', { method: 'POST', body: JSON.stringify({ code: this.oauthManualCode, verifier: this.oauthManualVerifier }) }); if (ok && data.success) { this.showAddModal = false; this.oauthManualMode = false; this.refreshAccounts(); } else this.showToast(data?.error || 'Failed to add account', 'error'); },
|
|
98
106
|
async copyToClipboard(text) { try { await navigator.clipboard.writeText(text); this.showToast('Copied to clipboard', 'success'); } catch { this.showToast('Failed to copy', 'error'); } },
|
|
99
107
|
async importFromCodex() { const { ok, data } = await this.api('/accounts/import', { method: 'POST' }); if (ok && data.success) { this.showAddModal = false; this.refreshAccounts(); } else this.showToast(data?.message || 'Import failed', 'error'); },
|
|
100
108
|
async switchAccount(email) { const { ok, data } = await this.api('/accounts/switch', { method: 'POST', body: JSON.stringify({ email }) }); if (ok && data.success) this.refreshAccounts(); else this.showToast(data?.message || 'Failed to switch', 'error'); },
|
|
109
|
+
accountExpirationLabel(account) { if (!account?.accountExpiresAt) return 'Never'; const date = new Date(account.accountExpiresAt); if (Number.isNaN(date.getTime())) return 'Never'; return date.toLocaleString([], { year: '2-digit', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit' }); },
|
|
110
|
+
showAccountExpirationModal(account) { this.expirationTarget = account; const date = account?.accountExpiresAt ? new Date(account.accountExpiresAt) : null; if (date && !Number.isNaN(date.getTime())) { const local = new Date(date.getTime() - date.getTimezoneOffset() * 60000); this.accountExpirationInput = local.toISOString().slice(0, 16); } else this.accountExpirationInput = ''; this.showAccountExpirationModalView = true; },
|
|
111
|
+
closeAccountExpirationModal() { if (this.accountExpirationSaving) return; this.showAccountExpirationModalView = false; this.expirationTarget = null; this.accountExpirationInput = ''; },
|
|
112
|
+
async updateAccountExpiration(accountExpiresAt) { if (!this.expirationTarget || this.accountExpirationSaving) return; this.accountExpirationSaving = true; const { ok, data } = await this.api(`/accounts/${encodeURIComponent(this.expirationTarget.email)}/expiration`, { method: 'PUT', body: JSON.stringify({ accountExpiresAt }) }); this.accountExpirationSaving = false; if (ok && data?.success) { this.closeAccountExpirationModal(); await this.refreshAccounts(); this.showToast(accountExpiresAt ? 'Account expiration updated' : 'Account expiration cleared', 'success'); } else this.showToast(data?.message || 'Failed to update account expiration', 'error'); },
|
|
113
|
+
saveAccountExpiration() { if (!this.accountExpirationInput) return; const expiresAt = new Date(this.accountExpirationInput); if (Number.isNaN(expiresAt.getTime())) { this.showToast('Enter a valid expiration time', 'error'); return; } return this.updateAccountExpiration(expiresAt.toISOString()); },
|
|
114
|
+
clearAccountExpiration() { return this.updateAccountExpiration(null); },
|
|
101
115
|
async refreshToken(email) { if (this.refreshingTokenEmails.includes(email)) return; this.refreshingTokenEmails.push(email); try { const { ok, data } = await this.api(`/accounts/${encodeURIComponent(email)}/refresh`, { method: 'POST' }); if (ok && data.success) await this.refreshAccounts(); else this.showToast(data?.message || 'Refresh failed', 'error'); } finally { this.refreshingTokenEmails = this.refreshingTokenEmails.filter(item => item !== email); } },
|
|
102
116
|
async refreshAllTokens() { const { ok, data } = await this.api('/accounts/refresh/all', { method: 'POST' }); if (ok) this.refreshAccounts(); else this.showToast(data?.message || 'Failed', 'error'); }, confirmDelete(email) { this.deleteTarget = email; this.showDeleteModal = true; },
|
|
103
|
-
async executeDelete() { const { ok, data } = await this.api(`/accounts/${encodeURIComponent(this.deleteTarget)}`, { method: 'DELETE' }); this.showDeleteModal = false; if (ok && data.success) this.refreshAccounts(); else this.showToast(data?.message || 'Delete failed', 'error'); }, showQuotaModal(acc) { this.selectedAccount = acc; this.showQuotaModalView = true; },
|
|
117
|
+
async executeDelete() { const { ok, data } = await this.api(`/accounts/${encodeURIComponent(this.deleteTarget)}`, { method: 'DELETE' }); this.showDeleteModal = false; if (ok && data.success) this.refreshAccounts(); else this.showToast(data?.message || 'Delete failed', 'error'); }, async showQuotaModal(acc) { this.selectedAccount = acc; this.showQuotaModalView = true; await this.loadRateLimitResetCredits(acc.email); },
|
|
118
|
+
normalizeRateLimitResetCredits(payload) { if (Array.isArray(payload)) return payload; for (const key of ['credits', 'items', 'data']) { if (Array.isArray(payload?.[key])) return payload[key]; } return []; },
|
|
119
|
+
async loadRateLimitResetCredits(email) { this.resetCreditsLoading = true; this.resetCredits = []; this.resetCreditsAccountEmail = email; this.resetCreditRedeemRequestId = ''; const { ok, data } = await this.api(`/accounts/rate-limit-reset-credits?email=${encodeURIComponent(email)}`); this.resetCreditsLoading = false; if (this.resetCreditsAccountEmail !== email) return; if (ok) this.resetCredits = this.normalizeRateLimitResetCredits(data?.credits); else this.showToast(data?.error || 'Failed to load reset credits', 'error'); },
|
|
120
|
+
availableRateLimitResetCredits() { return this.resetCredits.filter(credit => credit?.status === 'available').sort((a, b) => new Date(b.expires_at || 0).getTime() - new Date(a.expires_at || 0).getTime()); },
|
|
121
|
+
resetCreditExpiryLabel(credit) { const date = credit?.expires_at && new Date(credit.expires_at); return date && !Number.isNaN(date.getTime()) ? date.toLocaleString() : '-'; },
|
|
122
|
+
generateUUID() {
|
|
123
|
+
if (typeof globalThis.crypto?.randomUUID === 'function') {
|
|
124
|
+
return globalThis.crypto.randomUUID();
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const bytes = new Uint8Array(16);
|
|
128
|
+
globalThis.crypto.getRandomValues(bytes);
|
|
129
|
+
|
|
130
|
+
// UUID v4
|
|
131
|
+
bytes[6] = (bytes[6] & 0x0f) | 0x40;
|
|
132
|
+
bytes[8] = (bytes[8] & 0x3f) | 0x80;
|
|
133
|
+
|
|
134
|
+
const hex = Array.from(
|
|
135
|
+
bytes,
|
|
136
|
+
byte => byte.toString(16).padStart(2, '0')
|
|
137
|
+
);
|
|
138
|
+
|
|
139
|
+
return [
|
|
140
|
+
hex.slice(0, 4).join(''),
|
|
141
|
+
hex.slice(4, 6).join(''),
|
|
142
|
+
hex.slice(6, 8).join(''),
|
|
143
|
+
hex.slice(8, 10).join(''),
|
|
144
|
+
hex.slice(10, 16).join('')
|
|
145
|
+
].join('-');
|
|
146
|
+
},
|
|
147
|
+
async redeemRateLimitResetCredit(creditId = null) {
|
|
148
|
+
if (!this.selectedAccount || this.resetCreditsRedeeming) return;
|
|
149
|
+
const email = this.selectedAccount.email;
|
|
150
|
+
this.resetCreditsRedeeming = true;
|
|
151
|
+
this.resetCreditsRefreshPending = false;
|
|
152
|
+
try {
|
|
153
|
+
if (!this.resetCreditRedeemRequestId) this.resetCreditRedeemRequestId = this.generateUUID();
|
|
154
|
+
const { ok, data } = await this.api('/accounts/rate-limit-reset-credits/consume', {
|
|
155
|
+
method: 'POST',
|
|
156
|
+
body: JSON.stringify({ email, creditId: creditId || undefined, redeemRequestId: this.resetCreditRedeemRequestId })
|
|
157
|
+
});
|
|
158
|
+
if (!ok || !data?.success) {
|
|
159
|
+
this.showToast(data?.error || 'Failed to redeem reset credit', 'error');
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
this.resetCreditRedeemRequestId = '';
|
|
164
|
+
this.resetCreditsRefreshPending = true;
|
|
165
|
+
await this.loadRateLimitResetCredits(email);
|
|
166
|
+
await new Promise(resolve => setTimeout(resolve, 3000));
|
|
167
|
+
const { ok: quotaOk, data: quotaData } = await this.api(`/accounts/quota?email=${encodeURIComponent(email)}&refresh=true`);
|
|
168
|
+
if (!quotaOk || !quotaData?.quota) {
|
|
169
|
+
this.showToast(quotaData?.error || 'Quota reset succeeded, but quota refresh failed', 'error');
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
this.accounts = this.accounts.map(account => account.email === email ? { ...account, quota: quotaData.quota } : account);
|
|
174
|
+
if (this.selectedAccount?.email === email) {
|
|
175
|
+
this.selectedAccount = { ...this.selectedAccount, quota: quotaData.quota };
|
|
176
|
+
}
|
|
177
|
+
this.showToast('Quota reset and refreshed', 'success');
|
|
178
|
+
} finally {
|
|
179
|
+
this.resetCreditsRefreshPending = false;
|
|
180
|
+
this.resetCreditsRedeeming = false;
|
|
181
|
+
}
|
|
182
|
+
},
|
|
104
183
|
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'; },
|
|
105
184
|
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'); },
|
|
106
185
|
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'); },
|
|
@@ -108,9 +187,9 @@ document.addEventListener('alpine:init', () => {
|
|
|
108
187
|
async saveModelMapSetting() { if (this.modelMapSaving) return; const modelMap = Object.fromEntries(Object.entries(this.modelMappings).map(([key, value]) => [key, value.trim()])); if (Object.values(modelMap).some(value => !value)) { this.showToast('All Claude model mappings are required.', 'error'); return; } this.modelMapSaving = true; const { ok, data } = await this.api('/settings/model-map', { method: 'POST', body: JSON.stringify({ modelMap, reset: true }) }); this.modelMapSaving = false; if (ok && data?.modelMap) this.modelMappings = data.modelMap; else this.showToast(data?.error || 'Failed to update model mapping', 'error'); },
|
|
109
188
|
async resetModelMapSetting() { if (this.modelMapSaving) return; this.modelMapSaving = true; const { ok, data } = await this.api('/settings/model-map', { method: 'POST', body: JSON.stringify({ reset: true }) }); this.modelMapSaving = false; if (ok && data?.modelMap) this.modelMappings = data.modelMap; else this.showToast(data?.error || 'Failed to reset model mapping', 'error'); },
|
|
110
189
|
async loadClientApiKeys() { this.clientApiKeysLoading = true; const { ok, data } = await this.api('/settings/client-api-keys'); this.clientApiKeysLoading = false; if (ok && Array.isArray(data?.clientApiKeys)) this.clientApiKeys = data.clientApiKeys; else this.showToast(data?.error || 'Failed to load client API keys', 'error'); },
|
|
111
|
-
async createClientApiKey() { if (this.clientApiKeySaving) return; const weeklyLimitUsd = Number(this.clientApiKeyWeeklyLimitUsd); if (!Number.isFinite(weeklyLimitUsd) || weeklyLimitUsd < 0) { this.showToast('Weekly limit must be a non-negative USD amount.', 'error'); return; } this.clientApiKeySaving = true; const { ok, data } = await this.api('/settings/client-api-keys', { method: 'POST', body: JSON.stringify({ name: this.clientApiKeyName, remark: this.clientApiKeyRemark, weeklyLimitUsd }) }); this.clientApiKeySaving = false; if (ok && data?.clientApiKey?.key) { this.revealedClientApiKey = data.clientApiKey.key; this.clientApiKeyName = ''; this.clientApiKeyRemark = ''; this.clientApiKeyWeeklyLimitUsd = 50; this.showCreateClientApiKeyModal = false; await Promise.all([this.loadClientApiKeys(), this.loadClientProxyConfig()]); } else this.showToast(data?.error || 'Failed to create client API key', 'error'); },
|
|
112
|
-
async loadClientProxyConfig() {
|
|
113
|
-
async updateClientApiKey(clientApiKey) { if (this.clientApiKeySaving) return; const weeklyLimitUsd = Number(clientApiKey.weeklyLimitUsd); if (!Number.isFinite(weeklyLimitUsd) || weeklyLimitUsd < 0) { this.showToast('Weekly limit must be a non-negative USD amount.', 'error'); return; } this.clientApiKeySaving = true; const { ok, data } = await this.api(`/settings/client-api-keys/${encodeURIComponent(clientApiKey.id)}`, { method: 'PUT', body: JSON.stringify({ name: clientApiKey.name, remark: clientApiKey.remark, weeklyLimitUsd }) }); this.clientApiKeySaving = false; if (ok) await this.loadClientApiKeys(); else this.showToast(data?.error || 'Failed to update client API key', 'error'); }, async deleteClientApiKey(clientApiKey) { if (!confirm(`Delete the key for "${clientApiKey.name || clientApiKey.remark || 'this client'}"? Connected clients will lose access immediately.`)) return; this.clientApiKeySaving = true; const { ok, data } = await this.api(`/settings/client-api-keys/${encodeURIComponent(clientApiKey.id)}`, { method: 'DELETE' }); this.clientApiKeySaving = false; if (ok) await this.loadClientApiKeys(); else this.showToast(data?.error || 'Failed to delete client API key', 'error'); },
|
|
114
|
-
showToast(message, type = 'success') { this.toast = { message, type }; setTimeout(() => { this.toast = null; }, 3000); }, startLogStream() { if (!this.isAuthenticated) return; this.logEventSource?.close(); const params = new URLSearchParams(
|
|
190
|
+
async createClientApiKey() { if (this.clientApiKeySaving) return; const weeklyLimitUsd = Number(this.clientApiKeyWeeklyLimitUsd); const fiveHourLimitUsd = Number(this.clientApiKeyFiveHourLimitUsd); if (!Number.isFinite(weeklyLimitUsd) || weeklyLimitUsd < 0) { this.showToast('Weekly limit must be a non-negative USD amount.', 'error'); return; } if (!Number.isFinite(fiveHourLimitUsd) || fiveHourLimitUsd < 0) { this.showToast('5-hour limit must be a non-negative USD amount.', 'error'); return; } this.clientApiKeySaving = true; const { ok, data } = await this.api('/settings/client-api-keys', { method: 'POST', body: JSON.stringify({ name: this.clientApiKeyName, remark: this.clientApiKeyRemark, weeklyLimitUsd, fiveHourLimitEnabled: this.clientApiKeyFiveHourLimitEnabled, fiveHourLimitUsd }) }); this.clientApiKeySaving = false; if (ok && data?.clientApiKey?.key) { this.revealedClientApiKey = data.clientApiKey.key; this.clientApiKeyName = ''; this.clientApiKeyRemark = ''; this.clientApiKeyWeeklyLimitUsd = 50; this.clientApiKeyFiveHourLimitEnabled = false; this.clientApiKeyFiveHourLimitUsd = 0; this.showCreateClientApiKeyModal = false; await Promise.all([this.loadClientApiKeys(), this.loadClientProxyConfig()]); } else this.showToast(data?.error || 'Failed to create client API key', 'error'); },
|
|
191
|
+
async loadClientProxyConfig() { try { const response = await fetch('/claude/config/proxy', { method: 'POST', headers: { 'Content-Type': 'application/json' } }); const data = await response.json(); if (response.ok && data?.success && data?.env) this.clientProxyConfig = data; } catch {} }, async copyClientText(text, successMessage) { if (!text) return; try { if (navigator.clipboard?.writeText && window.isSecureContext) await navigator.clipboard.writeText(text); else { const textarea = document.createElement('textarea'); textarea.value = text; textarea.setAttribute('readonly', ''); textarea.style.cssText = 'position:absolute;opacity:0;left:-999999px;top:-999999px'; document.body.appendChild(textarea); textarea.focus(); textarea.select(); const copied = document.execCommand('copy'); textarea.remove(); if (!copied) throw new Error('Clipboard copy was rejected'); } this.showToast(successMessage, 'success'); } catch { this.showToast('Copy failed. Select and copy the value manually.', 'error'); } }, copyClientApiKey() { return this.copyClientText(this.revealedClientApiKey, 'Client API key copied'); }, copyClientProxyCommands() { const configureCommands = this.clientProxyConfig?.commands?.powershell; const clearCommands = this.clientProxyConfig?.commands?.clear?.powershell; const commands = [...(Array.isArray(configureCommands) ? configureCommands : []), ...(Array.isArray(clearCommands) ? clearCommands : [])]; return commands.length ? this.copyClientText(commands.map(command => command.replace('<client-api-key>', this.revealedClientApiKey)).join('\n'), 'Claude Code configuration commands copied') : undefined; },
|
|
192
|
+
async updateClientApiKey(clientApiKey) { if (this.clientApiKeySaving) return; const weeklyLimitUsd = Number(clientApiKey.weeklyLimitUsd); const fiveHourLimitUsd = Number(clientApiKey.fiveHourLimitUsd); if (!Number.isFinite(weeklyLimitUsd) || weeklyLimitUsd < 0) { this.showToast('Weekly limit must be a non-negative USD amount.', 'error'); return; } if (!Number.isFinite(fiveHourLimitUsd) || fiveHourLimitUsd < 0) { this.showToast('5-hour limit must be a non-negative USD amount.', 'error'); return; } this.clientApiKeySaving = true; const { ok, data } = await this.api(`/settings/client-api-keys/${encodeURIComponent(clientApiKey.id)}`, { method: 'PUT', body: JSON.stringify({ name: clientApiKey.name, remark: clientApiKey.remark, weeklyLimitUsd, fiveHourLimitEnabled: clientApiKey.fiveHourLimitEnabled === true, fiveHourLimitUsd }) }); this.clientApiKeySaving = false; if (ok) await this.loadClientApiKeys(); else this.showToast(data?.error || 'Failed to update client API key', 'error'); }, async deleteClientApiKey(clientApiKey) { if (!confirm(`Delete the key for "${clientApiKey.name || clientApiKey.remark || 'this client'}"? Connected clients will lose access immediately.`)) return; this.clientApiKeySaving = true; const { ok, data } = await this.api(`/settings/client-api-keys/${encodeURIComponent(clientApiKey.id)}`, { method: 'DELETE' }); this.clientApiKeySaving = false; if (ok) await this.loadClientApiKeys(); else this.showToast(data?.error || 'Failed to delete client API key', 'error'); },
|
|
193
|
+
showToast(message, type = 'success') { this.toast = { message, type }; setTimeout(() => { this.toast = null; }, 3000); }, async loadLogs(page = 1) { if (this.logLoading) return; this.logLoading = true; const { ok, data } = await this.api(`/api/logs?page=${page}&pageSize=${this.logPageSize}`); this.logLoading = false; if (!ok || !Array.isArray(data?.logs)) { this.showToast(data?.error || 'Failed to load logs', 'error'); return; } this.logs = data.logs; this.logPage = data.page; this.logTotal = data.total; this.logTotalPages = data.totalPages; }, async changeLogPage(page) { if (page < 1 || page > this.logTotalPages || page === this.logPage) return; await this.loadLogs(page); }, startLogStream() { if (!this.isAuthenticated) return; this.loadLogs(); this.logEventSource?.close(); const params = new URLSearchParams(); if (this.apiKey) params.set('api_key', this.apiKey); this.logEventSource = new EventSource(adminUrl(`/api/logs/stream?${params}`)); this.logEventSource.onmessage = event => { try { this.logTotal += 1; this.logTotalPages = Math.ceil(this.logTotal / this.logPageSize); if (this.logPage === 1) this.logs = [JSON.parse(event.data), ...this.logs].slice(0, this.logPageSize); } catch {} }; this.logEventSource.onerror = () => setTimeout(() => this.startLogStream(), 3000); }, clearLogs() { this.logs = []; this.logTotal = 0; this.logTotalPages = 0; }, formatLogMessage(message) { return message?.replace(/^\[(\w+)\]\s*/, '') || ''; }, getLogDetails(message) { if (!message) return null; const details = {}; for (const [key, pattern] of [['model', /model=([^\s|,]+)/], ['account', /account=([^\s|,]+)/], ['stream', /stream=(true|false)/], ['messages', /messages=(\d+)/], ['tools', /tools=(\d+)/], ['tokens', /tokens=(\d+)/], ['duration', /(\d+)ms/], ['status', /status=(\d+)/], ['error', /error=([^\s|]+)/]]) { const match = message.match(pattern); if (match) details[key] = match[1]; } return Object.keys(details).length ? details : null; }
|
|
115
194
|
}));
|
|
116
195
|
});
|
|
@@ -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" />
|
|
@@ -19,6 +19,15 @@
|
|
|
19
19
|
<input type="number" min="0" step="0.01" x-model="clientApiKeyWeeklyLimitUsd"
|
|
20
20
|
class="input w-full bg-space-800 border-space-border text-white font-mono text-sm" @keydown.enter="createClientApiKey()">
|
|
21
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>
|
|
22
31
|
</div>
|
|
23
32
|
<div class="mt-6 flex justify-end gap-2">
|
|
24
33
|
<button class="btn btn-outline btn-sm text-gray-400" @click="showCreateClientApiKeyModal = false" :disabled="clientApiKeySaving">Cancel</button>
|
|
@@ -40,8 +49,8 @@
|
|
|
40
49
|
<p class="text-xs font-semibold uppercase tracking-wider text-gray-400">Claude Code configuration</p>
|
|
41
50
|
<div class="rounded-lg border border-space-border bg-space-800 p-3 font-mono text-xs text-gray-300 space-y-2">
|
|
42
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>
|
|
43
53
|
<div><span class="text-gray-500">ANTHROPIC_API_KEY=</span><span class="break-all" x-text="revealedClientApiKey"></span></div>
|
|
44
|
-
<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
54
|
</div>
|
|
46
55
|
<p class="text-xs text-gray-500" x-text="clientProxyConfig.message"></p>
|
|
47
56
|
<button class="btn btn-outline btn-sm text-gray-300" @click="copyClientProxyCommands()">Copy PowerShell Commands</button>
|