- Updated markAccountUnavailable function to accept resetsAtMs for precise cooldown management.

- Added email backfill functionality for Codex OAuth connections to improve account information accuracy.
This commit is contained in:
decolua
2026-04-24 11:36:16 +07:00
parent fd8163e26e
commit 030fb34f88
15 changed files with 628 additions and 132 deletions
+33
View File
@@ -703,6 +703,39 @@ export async function getUsageStats(period = "all") {
if (dateKey > (stats.byEndpoint[epKey].lastUsed || "")) stats.byEndpoint[epKey].lastUsed = dateKey;
}
}
// Overlay lastUsed with precise ISO timestamps from live history (dailySummary only has YYYY-MM-DD)
const overlayCutoff = maxDays ? Date.now() - maxDays * 86400000 : 0;
for (const entry of history) {
const ts = entry.timestamp;
if (!ts || new Date(ts).getTime() < overlayCutoff) continue;
const modelKey = entry.provider ? `${entry.model} (${entry.provider})` : entry.model;
if (stats.byModel[modelKey] && new Date(ts) > new Date(stats.byModel[modelKey].lastUsed)) {
stats.byModel[modelKey].lastUsed = ts;
}
if (entry.connectionId) {
const accountName = connectionMap[entry.connectionId] || `Account ${entry.connectionId.slice(0, 8)}...`;
const accountKey = `${entry.model} (${entry.provider} - ${accountName})`;
if (stats.byAccount[accountKey] && new Date(ts) > new Date(stats.byAccount[accountKey].lastUsed)) {
stats.byAccount[accountKey].lastUsed = ts;
}
}
const apiKeyKey = (entry.apiKey && typeof entry.apiKey === "string")
? `${entry.apiKey}|${entry.model}|${entry.provider || "unknown"}`
: "local-no-key";
if (stats.byApiKey[apiKeyKey] && new Date(ts) > new Date(stats.byApiKey[apiKeyKey].lastUsed)) {
stats.byApiKey[apiKeyKey].lastUsed = ts;
}
const endpoint = entry.endpoint || "Unknown";
const endpointKey = `${endpoint}|${entry.model}|${entry.provider || "unknown"}`;
if (stats.byEndpoint[endpointKey] && new Date(ts) > new Date(stats.byEndpoint[endpointKey].lastUsed)) {
stats.byEndpoint[endpointKey].lastUsed = ts;
}
}
} else {
// 24h: use live history (original logic)
const cutoff = Date.now() - PERIOD_MS["24h"];