opencode-quota-gui 1.3.0 → 1.3.2
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 +34 -20
- package/dist/bin/opencode-quota-gui.js +0 -0
- package/dist/contracts/build-identity.js +1 -1
- package/dist/contracts/card-order.d.ts +2 -0
- package/dist/contracts/card-order.js +2 -2
- package/dist/contracts/card-visibility.d.ts +2 -1
- package/dist/contracts/card-visibility.js +2 -1
- package/dist/contracts/dashboard.d.ts +95 -6
- package/dist/contracts/dashboard.js +10 -0
- package/dist/contracts/dto-guards.d.ts +4 -0
- package/dist/contracts/dto-guards.js +31 -7
- package/dist/contracts/guards.js +3 -1
- package/dist/contracts/identity.d.ts +37 -5
- package/dist/contracts/identity.js +43 -0
- package/dist/contracts/openai-quota.d.ts +3 -0
- package/dist/contracts/openai-quota.js +3 -0
- package/dist/contracts/provider-auto-resume.d.ts +9 -0
- package/dist/contracts/provider-auto-resume.js +24 -0
- package/dist/contracts/provider-failure.d.ts +22 -0
- package/dist/contracts/provider-failure.js +25 -1
- package/dist/contracts/row-order.d.ts +13 -0
- package/dist/contracts/row-order.js +34 -0
- package/dist/contracts/row-visibility.d.ts +53 -0
- package/dist/contracts/row-visibility.js +130 -0
- package/dist/data/modelsdev-pricing.min.json +1 -1
- package/dist/data/modelsdev-temporal.min.json +60 -634
- package/dist/gui/aggregation.d.ts +29 -1
- package/dist/gui/aggregation.js +157 -4
- package/dist/gui/analytics-bridge.d.ts +8 -9
- package/dist/gui/analytics-bridge.js +197 -54
- package/dist/gui/analytics-engine.d.ts +7 -15
- package/dist/gui/analytics-engine.js +246 -106
- package/dist/gui/analytics-model.d.ts +7 -0
- package/dist/gui/analytics-model.js +75 -9
- package/dist/gui/analytics-pricing-upkeep.d.ts +21 -0
- package/dist/gui/analytics-pricing-upkeep.js +23 -0
- package/dist/gui/analytics-protocol.d.ts +17 -7
- package/dist/gui/analytics-protocol.js +1 -0
- package/dist/gui/analytics-service.d.ts +10 -0
- package/dist/gui/analytics-service.js +30 -9
- package/dist/gui/analytics-state.d.ts +30 -5
- package/dist/gui/analytics-state.js +46 -7
- package/dist/gui/analytics-worker-runtime.d.ts +5 -0
- package/dist/gui/analytics-worker-runtime.js +9 -1
- package/dist/gui/analytics-worker.js +11 -0
- package/dist/gui/config.d.ts +3 -3
- package/dist/gui/config.js +77 -7
- package/dist/gui/identity.d.ts +6 -20
- package/dist/gui/identity.js +6 -54
- package/dist/gui/lifecycle.d.ts +5 -3
- package/dist/gui/lifecycle.js +3 -3
- package/dist/gui/primary-quota-windows.js +67 -44
- package/dist/gui/provider-cards.d.ts +20 -8
- package/dist/gui/provider-cards.js +42 -55
- package/dist/gui/quota-notification-detector.d.ts +29 -6
- package/dist/gui/quota-notification-detector.js +136 -47
- package/dist/gui/quota-notification-observer.d.ts +3 -4
- package/dist/gui/quota-notification-observer.js +73 -20
- package/dist/gui/quota-observation.d.ts +4 -0
- package/dist/gui/quota-observation.js +18 -0
- package/dist/gui/rpc.d.ts +2 -0
- package/dist/gui/rpc.js +14 -3
- package/dist/gui/server.js +17 -3
- package/dist/gui/snapshot-service.d.ts +3 -15
- package/dist/gui/snapshot-service.js +281 -23
- package/dist/gui/sources.js +179 -64
- package/dist/gui/temporal-status.d.ts +3 -2
- package/dist/gui/temporal-status.js +10 -6
- package/dist/gui-experimental.cjs +230 -225
- package/dist/lib/accounting-format.d.ts +8 -0
- package/dist/lib/accounting-format.js +20 -2
- package/dist/lib/alibaba-coding-plan-cli.d.ts +79 -0
- package/dist/lib/alibaba-coding-plan-cli.js +539 -0
- package/dist/lib/anthropic-api-auth.d.ts +7 -0
- package/dist/lib/anthropic-api-auth.js +27 -0
- package/dist/lib/anthropic-api-rate-limits.d.ts +47 -0
- package/dist/lib/anthropic-api-rate-limits.js +92 -0
- package/dist/lib/anthropic-auth.d.ts +2 -3
- package/dist/lib/anthropic-auth.js +2 -3
- package/dist/lib/anthropic-oauth-throttle.d.ts +76 -0
- package/dist/lib/anthropic-oauth-throttle.js +379 -0
- package/dist/lib/anthropic.d.ts +68 -14
- package/dist/lib/anthropic.js +1016 -363
- package/dist/lib/api-key-retry-after.d.ts +7 -0
- package/dist/lib/api-key-retry-after.js +62 -0
- package/dist/lib/atomic-json.d.ts +2 -0
- package/dist/lib/atomic-json.js +1 -0
- package/dist/lib/cache-observer-ingestion.d.ts +90 -0
- package/dist/lib/cache-observer-ingestion.js +1008 -0
- package/dist/lib/cache-observer.d.ts +141 -0
- package/dist/lib/cache-observer.js +323 -0
- package/dist/lib/canonical-config-lock.d.ts +9 -0
- package/dist/lib/canonical-config-lock.js +36 -0
- package/dist/lib/chutes.js +62 -51
- package/dist/lib/claude-agent-transcript-ttl.d.ts +48 -0
- package/dist/lib/claude-agent-transcript-ttl.js +154 -0
- package/dist/lib/claude-agent-ttl-tracker.d.ts +21 -0
- package/dist/lib/claude-agent-ttl-tracker.js +152 -0
- package/dist/lib/cli-show.d.ts +5 -0
- package/dist/lib/cli-show.js +21 -8
- package/dist/lib/cli-status.js +3 -6
- package/dist/lib/config-write-target.d.ts +1 -1
- package/dist/lib/config-write-target.js +5 -2
- package/dist/lib/config.d.ts +2 -1
- package/dist/lib/config.js +257 -4
- package/dist/lib/copilot.js +171 -86
- package/dist/lib/dashboard-visibility.d.ts +5 -0
- package/dist/lib/dashboard-visibility.js +11 -10
- package/dist/lib/dashboard-web-policy.d.ts +4 -4
- package/dist/lib/dashboard-web-policy.js +2 -2
- package/dist/lib/deepseek.js +25 -13
- package/dist/lib/display-sanitize.js +2 -0
- package/dist/lib/entries.d.ts +33 -1
- package/dist/lib/entries.js +6 -0
- package/dist/lib/glm-coding-plan.js +98 -74
- package/dist/lib/google-agy.js +90 -12
- package/dist/lib/google-gemini-cli.js +84 -11
- package/dist/lib/grouped-entry-normalization.js +1 -1
- package/dist/lib/http.d.ts +4 -0
- package/dist/lib/http.js +16 -2
- package/dist/lib/init-installer.js +5 -3
- package/dist/lib/kilo.js +37 -18
- package/dist/lib/kimi.js +35 -18
- package/dist/lib/maintainer-announcements.js +2 -2
- package/dist/lib/mimo.d.ts +2 -0
- package/dist/lib/mimo.js +36 -0
- package/dist/lib/modelsdev-pricing.d.ts +74 -2
- package/dist/lib/modelsdev-pricing.js +457 -63
- package/dist/lib/modelsdev-temporal.d.ts +6 -0
- package/dist/lib/modelsdev-temporal.js +16 -2
- package/dist/lib/nanogpt.d.ts +1 -0
- package/dist/lib/nanogpt.js +26 -3
- package/dist/lib/ollama-cloud.d.ts +1 -1
- package/dist/lib/ollama-cloud.js +48 -35
- package/dist/lib/openai.js +84 -38
- package/dist/lib/opencode-auth-sqlite.d.ts +2 -2
- package/dist/lib/opencode-auth-sqlite.js +2 -2
- package/dist/lib/opencode-config-editor.d.ts +1 -0
- package/dist/lib/opencode-config-editor.js +6 -1
- package/dist/lib/opencode-config-providers.js +2 -2
- package/dist/lib/opencode-go.js +29 -2
- package/dist/lib/opencode-storage.d.ts +20 -0
- package/dist/lib/opencode-storage.js +89 -2
- package/dist/lib/opencode-version-core.d.ts +30 -0
- package/dist/lib/opencode-version-core.js +59 -0
- package/dist/lib/opencode-version.d.ts +2 -22
- package/dist/lib/opencode-version.js +4 -48
- package/dist/lib/opencode-warming-refresh.d.ts +19 -0
- package/dist/lib/opencode-warming-refresh.js +95 -0
- package/dist/lib/opencode-zen.d.ts +3 -0
- package/dist/lib/opencode-zen.js +71 -5
- package/dist/lib/provider-add.js +5 -2
- package/dist/lib/provider-metadata.d.ts +11 -3
- package/dist/lib/provider-metadata.js +20 -2
- package/dist/lib/provider-registration.d.ts +358 -9
- package/dist/lib/provider-registration.js +423 -30
- package/dist/lib/quota-auto-resume.d.ts +74 -0
- package/dist/lib/quota-auto-resume.js +539 -0
- package/dist/lib/quota-command-format.js +23 -10
- package/dist/lib/quota-exhaustion-projection.d.ts +11 -0
- package/dist/lib/quota-exhaustion-projection.js +25 -0
- package/dist/lib/quota-identity.d.ts +64 -0
- package/dist/lib/quota-identity.js +111 -0
- package/dist/lib/quota-providers-remote.d.ts +2 -1
- package/dist/lib/quota-providers-remote.js +59 -3
- package/dist/lib/quota-providers.d.ts +1 -1
- package/dist/lib/quota-providers.js +14 -37
- package/dist/lib/quota-render-data.d.ts +6 -0
- package/dist/lib/quota-render-data.js +45 -19
- package/dist/lib/quota-reset-notifications.js +11 -155
- package/dist/lib/quota-retry-wait.d.ts +106 -5
- package/dist/lib/quota-retry-wait.js +301 -34
- package/dist/lib/quota-runtime-context.js +1 -0
- package/dist/lib/quota-state-codec.d.ts +2 -0
- package/dist/lib/quota-state-codec.js +31 -2
- package/dist/lib/quota-state.d.ts +8 -2
- package/dist/lib/quota-state.js +253 -47
- package/dist/lib/quota-stats.d.ts +26 -0
- package/dist/lib/quota-stats.js +40 -1
- package/dist/lib/quota-status.js +3 -51
- package/dist/lib/quota-surface-data.js +18 -3
- package/dist/lib/quota-telemetry.js +2 -2
- package/dist/lib/resolved-auth-identity.d.ts +19 -0
- package/dist/lib/resolved-auth-identity.js +44 -0
- package/dist/lib/scoped-update.d.ts +1 -1
- package/dist/lib/state-file-lock.d.ts +26 -0
- package/dist/lib/state-file-lock.js +205 -0
- package/dist/lib/synthetic.js +65 -54
- package/dist/lib/toast-format-grouped.js +7 -4
- package/dist/lib/tui-compact-format.js +29 -16
- package/dist/lib/types.d.ts +51 -1
- package/dist/lib/types.js +17 -1
- package/dist/lib/xai.js +48 -22
- package/dist/plugin.js +328 -14
- package/dist/provider-logos/NOTICE.md +1 -1
- package/dist/provider-logos/OPENCODE-NOTICE.md +4 -3
- package/dist/providers/alibaba-coding-plan.js +125 -104
- package/dist/providers/alibaba-token-plan.js +9 -5
- package/dist/providers/anthropic.d.ts +16 -3
- package/dist/providers/anthropic.js +172 -220
- package/dist/providers/cache-policies.d.ts +11 -4
- package/dist/providers/cache-policies.js +19 -13
- package/dist/providers/chutes.js +2 -0
- package/dist/providers/claude-agent.d.ts +19 -0
- package/dist/providers/claude-agent.js +215 -0
- package/dist/providers/copilot.js +7 -4
- package/dist/providers/glm-coding-plan-provider.d.ts +1 -0
- package/dist/providers/glm-coding-plan-provider.js +30 -23
- package/dist/providers/google-account-format.js +1 -0
- package/dist/providers/google-agy.d.ts +6 -5
- package/dist/providers/google-agy.js +43 -15
- package/dist/providers/google-gemini-cli.js +1 -0
- package/dist/providers/kilo.js +1 -0
- package/dist/providers/kimi-code.js +2 -0
- package/dist/providers/mimo.js +1 -0
- package/dist/providers/nanogpt.js +1 -0
- package/dist/providers/ollama-cloud.js +10 -0
- package/dist/providers/openai.js +24 -23
- package/dist/providers/opencode-go.js +10 -6
- package/dist/providers/opencode-zen.js +3 -1
- package/dist/providers/openrouter.js +1 -0
- package/dist/providers/quota-providers.js +16 -5
- package/dist/providers/registry.js +2 -0
- package/dist/providers/result-helpers.d.ts +6 -2
- package/dist/providers/result-helpers.js +7 -1
- package/dist/providers/synthetic.js +4 -0
- package/dist/providers/xai.js +9 -8
- package/dist/rpc.d.ts +129 -8
- package/dist/rpc.js +219 -14
- package/dist/ui/assets/{index-cDd9jUVY.css → index-6_g1FHs-.css} +1 -1
- package/dist/ui/assets/index-sZnGUuML.js +10 -0
- package/dist/ui/assets/{popover-BGkgv9s0.js → popover-C4ZLYe9E.js} +1 -1
- package/dist/ui/assets/providers/claude-agent.svg +3 -0
- package/dist/ui/index.html +2 -2
- package/package.json +45 -46
- package/dist/lib/alibaba-coding-plan-local-quota.d.ts +0 -47
- package/dist/lib/alibaba-coding-plan-local-quota.js +0 -146
- package/dist/ui/assets/index-DLHeXYff.js +0 -9
package/dist/gui/sources.js
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
|
+
import { OPENAI_RESETS_ROW_KEY, OPENAI_RESETS_ROW_RESULT_TYPE } from "../contracts/openai-quota.js";
|
|
2
|
+
import { isTransientProviderFailureCategory } from "../contracts/provider-failure.js";
|
|
1
3
|
import { createLoadConfigMeta, loadConfig } from "../lib/config.js";
|
|
2
4
|
import { rawAssistantRowHasTokenUsage } from "../lib/opencode-storage.js";
|
|
3
5
|
import { collectQuotaDashboardProviderResults, } from "../lib/quota-render-data.js";
|
|
6
|
+
import { withoutClaudeAgentSavedResets } from "../lib/quota-state.js";
|
|
4
7
|
import { getProviders } from "../providers/registry.js";
|
|
5
|
-
import { AnalyticsNotFoundError, createUsageAnalytics, } from "./aggregation.js";
|
|
8
|
+
import { AnalyticsNotFoundError, createUsageAnalytics, messagePositionMs, } from "./aggregation.js";
|
|
6
9
|
import { createAnalyticsModel } from "./analytics-model.js";
|
|
7
10
|
import { createAnalyticsReadService } from "./analytics-service.js";
|
|
8
11
|
import { buildCardId, hashQuotaCardIdentity } from "./identity.js";
|
|
9
|
-
import { buildProviderCards,
|
|
12
|
+
import { buildProviderCards, cardSourceKey, optionalValueRowId, UNSCOPED, } from "./provider-cards.js";
|
|
13
|
+
import { markQuotaObservationLive } from "./quota-observation.js";
|
|
10
14
|
import { TEMPORAL_QUOTA_POLICIES } from "./temporal-quota-policy-data.js";
|
|
11
15
|
import { buildTemporalStatus, listTemporalProviderSources, readBundledTemporalCatalog, } from "./temporal-status.js";
|
|
12
16
|
import { resolveHostTimeZone } from "./time-zone.js";
|
|
@@ -33,17 +37,17 @@ function translateAnalyticsError(error) {
|
|
|
33
37
|
/**
|
|
34
38
|
* The production default. Creating the service starts no worker and performs
|
|
35
39
|
* no read; the worker is built lazily by the service on the first analytics
|
|
36
|
-
* request (analytics-api contract).
|
|
40
|
+
* request (analytics-api contract). The worker receives the owner's pricing
|
|
41
|
+
* snapshot policy; a config read failure keeps safe defaults.
|
|
37
42
|
*/
|
|
38
|
-
function createDefaultAnalyticsService() {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
return probe.result.entries.length > 0;
|
|
43
|
+
async function createDefaultAnalyticsService(loadConfigForService) {
|
|
44
|
+
try {
|
|
45
|
+
const config = await loadConfigForService();
|
|
46
|
+
return createAnalyticsReadService({ pricingSnapshot: config.pricingSnapshot });
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
return createAnalyticsReadService();
|
|
50
|
+
}
|
|
47
51
|
}
|
|
48
52
|
/**
|
|
49
53
|
* A readable Console login whose workspace has no Go entitlement is a valid
|
|
@@ -78,8 +82,8 @@ export function createOpenAiResetDetailsVisibility(config) {
|
|
|
78
82
|
const cardId = buildCardId("openai", sourceId);
|
|
79
83
|
if (hiddenCards.has(cardId))
|
|
80
84
|
return false;
|
|
81
|
-
const
|
|
82
|
-
return
|
|
85
|
+
const resetsRowId = optionalValueRowId(cardId, OPENAI_RESETS_ROW_KEY, OPENAI_RESETS_ROW_RESULT_TYPE);
|
|
86
|
+
return !hiddenRows.has(resetsRowId);
|
|
83
87
|
};
|
|
84
88
|
}
|
|
85
89
|
/**
|
|
@@ -119,9 +123,8 @@ function cardPreferences(config) {
|
|
|
119
123
|
accountingDetail: config.accountingDetail,
|
|
120
124
|
providerOrder: config.dashboard.providerOrder,
|
|
121
125
|
cardOrder: config.dashboard.cardOrder,
|
|
126
|
+
rowOrder: config.dashboard.rowOrder,
|
|
122
127
|
};
|
|
123
|
-
if (config.quotaProjection !== undefined)
|
|
124
|
-
preferences.quotaProjection = config.quotaProjection;
|
|
125
128
|
if (config.resetTimeDecimals !== undefined) {
|
|
126
129
|
preferences.resetTimeDecimals = config.resetTimeDecimals;
|
|
127
130
|
}
|
|
@@ -171,6 +174,9 @@ export function createDashboardReadSource(options) {
|
|
|
171
174
|
const usageDataset = (dataset) => ({
|
|
172
175
|
...dataset,
|
|
173
176
|
messages: dataset.messages.filter(rawAssistantRowHasTokenUsage),
|
|
177
|
+
excluded: dataset.messages
|
|
178
|
+
.filter((row) => !rawAssistantRowHasTokenUsage(row))
|
|
179
|
+
.map((row) => ({ sessionId: row.sessionID, atMs: messagePositionMs(row) })),
|
|
174
180
|
});
|
|
175
181
|
return {
|
|
176
182
|
async home({ range }) {
|
|
@@ -233,7 +239,7 @@ export function createDashboardReadSource(options) {
|
|
|
233
239
|
created = Promise.resolve(createLegacyAnalyticsService());
|
|
234
240
|
}
|
|
235
241
|
else {
|
|
236
|
-
created =
|
|
242
|
+
created = createDefaultAnalyticsService(loadDashboardConfig);
|
|
237
243
|
}
|
|
238
244
|
}
|
|
239
245
|
catch (error) {
|
|
@@ -259,7 +265,7 @@ export function createDashboardReadSource(options) {
|
|
|
259
265
|
globalConfigDir: options.configDir,
|
|
260
266
|
});
|
|
261
267
|
}
|
|
262
|
-
async function collect(config, nowMs, providers) {
|
|
268
|
+
async function collect(config, nowMs, providers, refresh = false) {
|
|
263
269
|
const openaiResetDetailsVisible = createOpenAiResetDetailsVisibility(config);
|
|
264
270
|
if (options.collectProviderResults) {
|
|
265
271
|
return options.collectProviderResults({
|
|
@@ -276,22 +282,11 @@ export function createDashboardReadSource(options) {
|
|
|
276
282
|
config,
|
|
277
283
|
workspaceRoot: options.workspaceRoot,
|
|
278
284
|
providers,
|
|
285
|
+
forceProviderRefresh: refresh,
|
|
279
286
|
openaiResetDetailsVisible,
|
|
280
287
|
});
|
|
281
288
|
}
|
|
282
|
-
/**
|
|
283
|
-
* Merge one cycle with the per-provider last-good map (checkpoint review
|
|
284
|
-
* finding 9):
|
|
285
|
-
*
|
|
286
|
-
* - New entries are the only successful measurement; refreshed accounts are
|
|
287
|
-
* taken from the measurement snapshot, never from a descriptor-only result.
|
|
288
|
-
* - A provider without new measurements keeps its last-good entries/accounts
|
|
289
|
-
* but surfaces the *current* cycle's errors.
|
|
290
|
-
* - A selected provider missing from the cycle (slow/unavailable probe) keeps
|
|
291
|
-
* its last-good probe.
|
|
292
|
-
* - Any substitution is reported so the snapshot can be marked stale and the
|
|
293
|
-
* last successful poll timestamp is not advanced.
|
|
294
|
-
*/
|
|
289
|
+
/** Keep last-good entries scoped to the current credential and card identity. */
|
|
295
290
|
function mergeProviderResults(probes, selected) {
|
|
296
291
|
const selectedIds = new Set(selected.map((provider) => provider.id));
|
|
297
292
|
for (const providerId of lastGoodProbes.keys()) {
|
|
@@ -300,66 +295,161 @@ export function createDashboardReadSource(options) {
|
|
|
300
295
|
}
|
|
301
296
|
const merged = [];
|
|
302
297
|
const seen = new Set();
|
|
303
|
-
let
|
|
298
|
+
let anyFresh = false;
|
|
299
|
+
let anyError = false;
|
|
300
|
+
let dropped = false;
|
|
301
|
+
let anyRetained = false;
|
|
304
302
|
for (const probe of probes) {
|
|
305
303
|
seen.add(probe.providerId);
|
|
306
|
-
if (hasMeasurements(probe)) {
|
|
307
|
-
lastGoodProbes.set(probe.providerId, probe);
|
|
308
|
-
merged.push(probe);
|
|
309
|
-
continue;
|
|
310
|
-
}
|
|
311
304
|
if (hasRevokedOpenCodeGoEntitlement(probe)) {
|
|
312
305
|
// A revoked entitlement replaces the measurement instead of falling
|
|
313
306
|
// back to it; the current result (possibly descriptor-only) is fresh.
|
|
314
307
|
lastGoodProbes.delete(probe.providerId);
|
|
308
|
+
anyFresh = true;
|
|
315
309
|
merged.push(probe);
|
|
316
310
|
continue;
|
|
317
311
|
}
|
|
318
|
-
|
|
319
|
-
if (!
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
312
|
+
let store = lastGoodProbes.get(probe.providerId);
|
|
313
|
+
if (!probe.cacheScope || store?.cacheScope !== probe.cacheScope) {
|
|
314
|
+
lastGoodProbes.delete(probe.providerId);
|
|
315
|
+
store = undefined;
|
|
316
|
+
}
|
|
317
|
+
const accountIds = new Set((probe.result.accounts ?? []).map((account) => account.sourceId));
|
|
318
|
+
const entries = new Map();
|
|
319
|
+
for (const entry of probe.result.entries) {
|
|
320
|
+
const key = cardSourceKey(entry.accounting.sourceId, accountIds);
|
|
321
|
+
const group = entries.get(key) ?? [];
|
|
322
|
+
group.push(entry);
|
|
323
|
+
entries.set(key, group);
|
|
324
324
|
}
|
|
325
|
-
|
|
325
|
+
const errors = probe.result.errors.filter((error) => error.kind !== "intentional-filter");
|
|
326
|
+
anyError ||= errors.length > 0;
|
|
327
|
+
const failed = new Set(errors.map((error) => cardSourceKey(error.sourceId, accountIds)));
|
|
328
|
+
const rateLimited = new Set(errors
|
|
329
|
+
.filter((error) => error.retryAtMs !== undefined)
|
|
330
|
+
.map((error) => cardSourceKey(error.sourceId, accountIds)));
|
|
331
|
+
// A transient failure key that still carries entries is treated as a quota-state last-good
|
|
332
|
+
// snapshot: those rows were measured before the failure, so they are retained and marked
|
|
333
|
+
// stale, never fresh. Other errors can accompany genuinely fresh entries and do not imply
|
|
334
|
+
// retention.
|
|
335
|
+
const keyHasLastGood = (key) => (store?.bySource.get(key)?.length ?? 0) > 0;
|
|
336
|
+
const explicitTransientKeys = new Set(errors
|
|
337
|
+
.filter((error) => isTransientProviderFailureCategory(error.failureCategory) ||
|
|
338
|
+
error.attemptOutcome === "transient" ||
|
|
339
|
+
error.attemptOutcome === "cooldown")
|
|
340
|
+
.map((error) => cardSourceKey(error.sourceId, accountIds)));
|
|
341
|
+
// A provider that previously produced rows for this key keeps them when a later attempt
|
|
342
|
+
// fails in an unclassified way: an unknown category is treated as transient instead of
|
|
343
|
+
// purging a valid measurement, and is normalized so the card mutes it. If this probe also
|
|
344
|
+
// carries entries for the key, those are the measurement; the error stays visible. Credential
|
|
345
|
+
// rejections still prove the account changed and never retain.
|
|
346
|
+
const unknownRetainedKeys = new Set(errors
|
|
347
|
+
.filter((error) => {
|
|
348
|
+
const key = cardSourceKey(error.sourceId, accountIds);
|
|
349
|
+
if (entries.has(key) || rateLimited.has(key) || explicitTransientKeys.has(key))
|
|
350
|
+
return false;
|
|
351
|
+
if (error.failureCategory === "credentials" || error.attemptOutcome === "credentials")
|
|
352
|
+
return false;
|
|
353
|
+
return keyHasLastGood(key);
|
|
354
|
+
})
|
|
355
|
+
.map((error) => cardSourceKey(error.sourceId, accountIds)));
|
|
356
|
+
const transientKeys = new Set([...explicitTransientKeys, ...unknownRetainedKeys]);
|
|
357
|
+
const retainedEntryKeys = [...entries.keys()].filter((key) => transientKeys.has(key) && !rateLimited.has(key));
|
|
358
|
+
const freshKeys = [...entries.keys()].filter((key) => !rateLimited.has(key) && !transientKeys.has(key));
|
|
359
|
+
anyFresh ||= freshKeys.length > 0;
|
|
360
|
+
const next = new Map();
|
|
361
|
+
const retained = new Set();
|
|
362
|
+
for (const key of freshKeys)
|
|
363
|
+
next.set(key, entries.get(key));
|
|
364
|
+
for (const key of retainedEntryKeys) {
|
|
365
|
+
const safe = withoutClaudeAgentSavedResets(entries.get(key));
|
|
366
|
+
entries.set(key, safe);
|
|
367
|
+
next.set(key, safe);
|
|
368
|
+
retained.add(key);
|
|
369
|
+
}
|
|
370
|
+
for (const key of rateLimited)
|
|
371
|
+
if (entries.has(key)) {
|
|
372
|
+
retained.add(key);
|
|
373
|
+
// A failed refresh proves neither eligibility nor expiry, so retained rows drop saved resets.
|
|
374
|
+
const old = withoutClaudeAgentSavedResets(store?.bySource.get(key) ?? []);
|
|
375
|
+
if (old.length > 0)
|
|
376
|
+
next.set(key, old);
|
|
377
|
+
}
|
|
378
|
+
// A failure that is neither transient nor rate-limited (a credential rejection) proves the
|
|
379
|
+
// account may have changed. It must not reattach the old measurement, and the stored copy is
|
|
380
|
+
// purged so a later empty result cannot bring it back.
|
|
381
|
+
for (const key of failed) {
|
|
382
|
+
if (!transientKeys.has(key) && !rateLimited.has(key))
|
|
383
|
+
store?.bySource.delete(key);
|
|
384
|
+
}
|
|
385
|
+
for (const [key, old] of store?.bySource ?? []) {
|
|
386
|
+
if (entries.has(key) || (freshKeys.length > 0 && !failed.has(key)))
|
|
387
|
+
continue;
|
|
388
|
+
if (key !== UNSCOPED && !accountIds.has(key))
|
|
389
|
+
continue;
|
|
390
|
+
const safe = withoutClaudeAgentSavedResets(old).filter((entry) => cardSourceKey(entry.accounting.sourceId, accountIds) === key);
|
|
391
|
+
if (safe.length === 0)
|
|
392
|
+
continue;
|
|
393
|
+
entries.set(key, safe);
|
|
394
|
+
next.set(key, safe);
|
|
395
|
+
retained.add(key);
|
|
396
|
+
}
|
|
397
|
+
if (probe.cacheScope)
|
|
398
|
+
lastGoodProbes.set(probe.providerId, { cacheScope: probe.cacheScope, bySource: next });
|
|
399
|
+
anyRetained ||= retained.size > 0;
|
|
400
|
+
const normalizedErrors = errors.map((error) => {
|
|
401
|
+
const key = cardSourceKey(error.sourceId, accountIds);
|
|
402
|
+
const normalized = unknownRetainedKeys.has(key)
|
|
403
|
+
? { ...error, failureCategory: "provider_api" }
|
|
404
|
+
: error;
|
|
405
|
+
// A retained non-credential failure is a last-good measurement with a
|
|
406
|
+
// recoverable error. Mark an unspecified outcome so the card mutes it
|
|
407
|
+
// instead of leaving a red provider error over valid retained rows.
|
|
408
|
+
if (retained.has(key) &&
|
|
409
|
+
normalized.failureCategory !== "credentials" &&
|
|
410
|
+
normalized.attemptOutcome === undefined) {
|
|
411
|
+
return { ...normalized, attemptOutcome: "transient" };
|
|
412
|
+
}
|
|
413
|
+
return normalized;
|
|
414
|
+
});
|
|
326
415
|
merged.push({
|
|
327
|
-
|
|
328
|
-
result: {
|
|
416
|
+
...probe,
|
|
417
|
+
result: {
|
|
418
|
+
...probe.result,
|
|
419
|
+
errors: normalizedErrors,
|
|
420
|
+
entries: [...entries.values()].flat(),
|
|
421
|
+
},
|
|
422
|
+
retainedSourceIds: new Set([...retained].filter((key) => key !== UNSCOPED)),
|
|
423
|
+
retainedUnscoped: retained.has(UNSCOPED),
|
|
329
424
|
});
|
|
330
425
|
}
|
|
331
426
|
for (const provider of selected) {
|
|
332
427
|
if (seen.has(provider.id))
|
|
333
428
|
continue;
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
continue;
|
|
337
|
-
substituted = true;
|
|
338
|
-
merged.push(lastGood);
|
|
429
|
+
lastGoodProbes.delete(provider.id);
|
|
430
|
+
dropped = true;
|
|
339
431
|
}
|
|
340
|
-
return { probes: merged, substituted };
|
|
432
|
+
return { probes: merged, substituted: !anyFresh && (anyRetained || anyError || dropped) };
|
|
341
433
|
}
|
|
342
|
-
async function runQuotaCycle() {
|
|
434
|
+
async function runQuotaCycle(refresh = false) {
|
|
343
435
|
const nowMs = now();
|
|
344
436
|
try {
|
|
345
437
|
const config = await loadDashboardConfig();
|
|
346
438
|
const allProviders = options.providers ?? getProviders();
|
|
347
439
|
const selected = selectQuotaProviders(config, allProviders);
|
|
348
|
-
const probes = await collect(config, nowMs, selected);
|
|
440
|
+
const probes = await collect(config, nowMs, selected, refresh);
|
|
349
441
|
const merged = mergeProviderResults(probes, selected);
|
|
442
|
+
// OpenAI's observation timestamp is captured after its usage body is
|
|
443
|
+
// consumed. Project and timestamp the completed collection together.
|
|
444
|
+
const projectionNowMs = now();
|
|
350
445
|
// No hidden-card id filters this list: hidden cards remain collected and
|
|
351
446
|
// are hidden by the browser. Ordering is still applied to assembled cards.
|
|
352
447
|
const cards = buildProviderCards({
|
|
353
448
|
probes: merged.probes,
|
|
354
449
|
preferences: cardPreferences(config),
|
|
355
|
-
nowMs,
|
|
450
|
+
nowMs: projectionNowMs,
|
|
356
451
|
providerLabel: options.providerLabel,
|
|
357
452
|
});
|
|
358
|
-
// A substituted provider is cached data: mark the snapshot stale and do
|
|
359
|
-
// not advance the successful poll timestamp (checkpoint review finding 9).
|
|
360
|
-
const polledAtMs = merged.substituted
|
|
361
|
-
? (lastQuotaSnapshot?.providers.polledAtMs ?? nowMs)
|
|
362
|
-
: nowMs;
|
|
363
453
|
const snapshot = {
|
|
364
454
|
generatedAtMs: nowMs,
|
|
365
455
|
stale: merged.substituted,
|
|
@@ -367,24 +457,49 @@ export function createDashboardReadSource(options) {
|
|
|
367
457
|
providers: {
|
|
368
458
|
cards,
|
|
369
459
|
enabledProviders: config.enabledProviders,
|
|
370
|
-
polledAtMs,
|
|
460
|
+
polledAtMs: projectionNowMs,
|
|
371
461
|
},
|
|
372
462
|
};
|
|
373
463
|
const temporal = temporalStatusForCards(cards, nowMs);
|
|
374
464
|
if (temporal)
|
|
375
465
|
snapshot.temporal = temporal;
|
|
376
466
|
lastQuotaSnapshot = snapshot;
|
|
377
|
-
return snapshot;
|
|
467
|
+
return markQuotaObservationLive(snapshot);
|
|
378
468
|
}
|
|
379
469
|
catch (error) {
|
|
380
470
|
if (lastQuotaSnapshot) {
|
|
381
|
-
return {
|
|
471
|
+
return {
|
|
472
|
+
...lastQuotaSnapshot,
|
|
473
|
+
generatedAtMs: nowMs,
|
|
474
|
+
stale: true,
|
|
475
|
+
temporal: undefined,
|
|
476
|
+
providers: { ...lastQuotaSnapshot.providers, cards: [] },
|
|
477
|
+
};
|
|
382
478
|
}
|
|
383
479
|
throw error;
|
|
384
480
|
}
|
|
385
481
|
}
|
|
386
|
-
|
|
482
|
+
let quotaRefresh;
|
|
483
|
+
function quota(input) {
|
|
484
|
+
if (input?.refresh) {
|
|
485
|
+
if (quotaRefresh)
|
|
486
|
+
return quotaRefresh;
|
|
487
|
+
const refresh = (async () => {
|
|
488
|
+
await quotaCycle?.catch(() => undefined);
|
|
489
|
+
return runQuotaCycle(true);
|
|
490
|
+
})();
|
|
491
|
+
quotaRefresh = refresh;
|
|
492
|
+
void refresh
|
|
493
|
+
.finally(() => {
|
|
494
|
+
if (quotaRefresh === refresh)
|
|
495
|
+
quotaRefresh = undefined;
|
|
496
|
+
})
|
|
497
|
+
.catch(() => undefined);
|
|
498
|
+
return refresh;
|
|
499
|
+
}
|
|
387
500
|
// Every selected provider starts in one cycle; concurrent readers share it.
|
|
501
|
+
if (quotaRefresh)
|
|
502
|
+
return quotaRefresh;
|
|
388
503
|
if (quotaCycle)
|
|
389
504
|
return quotaCycle;
|
|
390
505
|
const cycle = runQuotaCycle().finally(() => {
|
|
@@ -31,8 +31,9 @@ export interface BuildTemporalStatusInput {
|
|
|
31
31
|
/** Holiday calendars referenced by the bundled snapshot. */
|
|
32
32
|
holidays?: readonly TemporalHolidayInterval[];
|
|
33
33
|
/**
|
|
34
|
-
*
|
|
35
|
-
*
|
|
34
|
+
* Fallback base-rate lookup for policies without a captured source base
|
|
35
|
+
* (multiplier-only policies and test/embedding seams). Production prefers
|
|
36
|
+
* the base bundled with an absolute-override policy.
|
|
36
37
|
*/
|
|
37
38
|
baseRates?: (providerId: string, modelId: string) => TemporalRates | null;
|
|
38
39
|
/** Provider-maintained quota policies; defaults to the bundled data module. */
|
|
@@ -723,7 +723,13 @@ export function buildTemporalStatus(input) {
|
|
|
723
723
|
const policy = getTemporalPolicy(provider.providerId, modelId);
|
|
724
724
|
if (!policy)
|
|
725
725
|
continue;
|
|
726
|
-
|
|
726
|
+
// Absolute overrides are meaningful only against their source's own base.
|
|
727
|
+
// The pricing snapshot's api.json cost can be a derived/current price, so
|
|
728
|
+
// prefer the base captured with the temporal policy when present.
|
|
729
|
+
const base = policy.status === "supported"
|
|
730
|
+
? (policy.base ?? resolveBase(provider.providerId, modelId))
|
|
731
|
+
: null;
|
|
732
|
+
models.push(modelStatus(provider.providerId, modelId, input.nowMs, base));
|
|
727
733
|
for (const jurisdiction of holidayJurisdictions(policy))
|
|
728
734
|
jurisdictions.add(jurisdiction);
|
|
729
735
|
}
|
|
@@ -750,12 +756,11 @@ export function buildTemporalStatus(input) {
|
|
|
750
756
|
},
|
|
751
757
|
};
|
|
752
758
|
}
|
|
753
|
-
function modelStatus(providerId, modelId, nowMs,
|
|
759
|
+
function modelStatus(providerId, modelId, nowMs, base) {
|
|
754
760
|
const policy = getTemporalPolicy(providerId, modelId);
|
|
755
|
-
const base = baseRates(providerId, modelId);
|
|
756
761
|
const state = getTemporalInstantState(providerId, modelId, nowMs);
|
|
757
762
|
const current = classifyInstant(policy, state, base);
|
|
758
|
-
const intervals = projectIntervals(providerId, modelId, nowMs,
|
|
763
|
+
const intervals = projectIntervals(providerId, modelId, nowMs, base);
|
|
759
764
|
const weekly = policyWeeklySchedule(policy, base);
|
|
760
765
|
// The preview is deliberately short, so its last interval ends at the horizon
|
|
761
766
|
// rather than at a proved transition. Ask the core evaluator for the real
|
|
@@ -779,11 +784,10 @@ function modelStatus(providerId, modelId, nowMs, baseRates) {
|
|
|
779
784
|
status.reason = state.reason;
|
|
780
785
|
return status;
|
|
781
786
|
}
|
|
782
|
-
function projectIntervals(providerId, modelId, nowMs,
|
|
787
|
+
function projectIntervals(providerId, modelId, nowMs, base) {
|
|
783
788
|
const policy = getTemporalPolicy(providerId, modelId);
|
|
784
789
|
if (!policy || policy.status === "unsupported")
|
|
785
790
|
return [];
|
|
786
|
-
const base = baseRates(providerId, modelId);
|
|
787
791
|
const rawIntervals = listTemporalIntervals(providerId, modelId, nowMs, nowMs + TEMPORAL_SCHEDULE_HORIZON_MS, base ?? undefined);
|
|
788
792
|
const projected = [];
|
|
789
793
|
for (const interval of rawIntervals) {
|