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
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { type ProviderCard } from "../contracts/dashboard.js";
|
|
1
|
+
import { type ProviderCard, type QuotaCardRow } from "../contracts/dashboard.js";
|
|
2
2
|
import type { CardId } from "../contracts/identity.js";
|
|
3
|
+
import { quotaEntryIsHidden } from "../lib/quota-identity.js";
|
|
3
4
|
import type { QuotaStatusLiveProbe } from "../lib/quota-render-data.js";
|
|
4
5
|
import type { QuotaToastConfig } from "../lib/types.js";
|
|
5
6
|
/** Controlled fallback for unknown/unsafe provider errors (spec §9 R38). */
|
|
@@ -13,7 +14,6 @@ export declare const PROVIDER_ERROR_GENERIC_LABEL = "Provider error";
|
|
|
13
14
|
*/
|
|
14
15
|
export interface ProviderCardPreferences {
|
|
15
16
|
accountingDetail: QuotaToastConfig["accountingDetail"];
|
|
16
|
-
quotaProjection?: QuotaToastConfig["quotaProjection"];
|
|
17
17
|
resetTimeDecimals?: QuotaToastConfig["resetTimeDecimals"];
|
|
18
18
|
resetTimeSpaced?: QuotaToastConfig["resetTimeSpaced"];
|
|
19
19
|
/**
|
|
@@ -30,19 +30,31 @@ export interface ProviderCardPreferences {
|
|
|
30
30
|
* independent. Affects presentation only.
|
|
31
31
|
*/
|
|
32
32
|
cardOrder?: readonly string[];
|
|
33
|
+
/**
|
|
34
|
+
* Sparse per-card row display order (`dashboard.rowOrder`) is presentation
|
|
35
|
+
* only and applied by the UI, native header and Settings surfaces. The card
|
|
36
|
+
* payload keeps provider emission order so legacy aggregate hidden ids keep
|
|
37
|
+
* resolving to the row that was emitted first.
|
|
38
|
+
*/
|
|
39
|
+
rowOrder?: Readonly<Record<string, readonly string[]>>;
|
|
33
40
|
}
|
|
41
|
+
export declare const UNSCOPED: unique symbol;
|
|
42
|
+
export type SourceKey = string | typeof UNSCOPED;
|
|
43
|
+
export declare function cardSourceKey(sourceId: string | undefined, accountSourceIds: ReadonlySet<string>): SourceKey;
|
|
44
|
+
export type MergedProbe = QuotaStatusLiveProbe & {
|
|
45
|
+
retainedSourceIds?: ReadonlySet<string>;
|
|
46
|
+
retainedUnscoped?: boolean;
|
|
47
|
+
};
|
|
34
48
|
export interface BuildProviderCardsInput {
|
|
35
|
-
probes: readonly
|
|
49
|
+
probes: readonly MergedProbe[];
|
|
36
50
|
preferences: ProviderCardPreferences;
|
|
37
51
|
nowMs: number;
|
|
38
52
|
/** Provider display label resolver; defaults to the registration table. */
|
|
39
53
|
providerLabel?: (providerId: string) => string;
|
|
40
54
|
}
|
|
41
|
-
/**
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
*/
|
|
45
|
-
export declare function openAiOptionalVisibilityRows(cardId: CardId): NonNullable<ProviderCard["visibilityRows"]>;
|
|
55
|
+
/** The stable row id an optional declared row carries once the provider emits it. */
|
|
56
|
+
export declare function optionalValueRowId(cardId: CardId, rowKey: string, resultType: QuotaCardRow["resultType"]): QuotaCardRow["rowId"];
|
|
57
|
+
export { quotaEntryIsHidden };
|
|
46
58
|
/**
|
|
47
59
|
* One card per discovered account (zero-entry and failed ones included) plus a
|
|
48
60
|
* provider-scope card for unscoped content or when no account was discovered.
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
*/
|
|
12
12
|
import { orderCardsByPreference } from "../contracts/card-order.js";
|
|
13
13
|
import { PRIMARY_QUOTA_WINDOW_LIMIT, } from "../contracts/dashboard.js";
|
|
14
|
-
import {
|
|
14
|
+
import { optionalRowId, rowIdForEntry } from "../contracts/identity.js";
|
|
15
15
|
import { formatAccountingQuantity, interpretAccountingRow, isCanonicalAccountingDecimal, } from "../lib/accounting-format.js";
|
|
16
16
|
import { sanitizeDisplayText, sanitizeQuotaToastEntry, sanitizeSingleLineDisplayText, } from "../lib/display-sanitize.js";
|
|
17
17
|
import { cloneBankedResetAvailability, isBooleanEntry, isPercentEntry, isQuantityEntry, isValueEntry, } from "../lib/entries.js";
|
|
@@ -19,12 +19,16 @@ import { formatResetCountdown, isResetTimeDecimals } from "../lib/format-utils.j
|
|
|
19
19
|
import { scrubCredentialErrorText } from "../lib/opencode-auth.js";
|
|
20
20
|
import { getQuotaProviderDisplayLabel } from "../lib/provider-metadata.js";
|
|
21
21
|
import { projectQuotaRunway } from "../lib/quota-exhaustion-projection.js";
|
|
22
|
-
import { buildCardId, buildProviderScopeCardId, hashQuotaCardIdentity, PROVIDER_SCOPE_IDENTITY_KEY,
|
|
22
|
+
import { buildCardId, buildProviderScopeCardId, hashQuotaCardIdentity, optionalVisibilityRowsFor, PROVIDER_SCOPE_IDENTITY_KEY, quotaEntryIsHidden, } from "../lib/quota-identity.js";
|
|
23
23
|
import { primaryQuotaWindowSlot } from "./primary-quota-windows.js";
|
|
24
24
|
/** Controlled fallback for unknown/unsafe provider errors (spec §9 R38). */
|
|
25
25
|
export const PROVIDER_ERROR_GENERIC_MESSAGE = "Provider request failed; check upstream quota diagnostics.";
|
|
26
26
|
/** Controlled fallback label when an error label itself is unredactable. */
|
|
27
27
|
export const PROVIDER_ERROR_GENERIC_LABEL = "Provider error";
|
|
28
|
+
export const UNSCOPED = Symbol("unscoped");
|
|
29
|
+
export function cardSourceKey(sourceId, accountSourceIds) {
|
|
30
|
+
return sourceId !== undefined && accountSourceIds.has(sourceId) ? sourceId : UNSCOPED;
|
|
31
|
+
}
|
|
28
32
|
// Raw identities shorter than this are not string-replaced (avoids gutting
|
|
29
33
|
// ordinary words); real OpenCode connection ids are longer.
|
|
30
34
|
const MIN_SECRET_LENGTH = 4;
|
|
@@ -77,6 +81,12 @@ function mapProviderError(error, secrets) {
|
|
|
77
81
|
};
|
|
78
82
|
if (error.retryable === true)
|
|
79
83
|
mapped.retryable = true;
|
|
84
|
+
if (error.retryAtMs !== undefined)
|
|
85
|
+
mapped.retryAtMs = error.retryAtMs;
|
|
86
|
+
if (error.attemptOutcome !== undefined)
|
|
87
|
+
mapped.attemptOutcome = error.attemptOutcome;
|
|
88
|
+
if (error.kind !== undefined)
|
|
89
|
+
mapped.kind = error.kind;
|
|
80
90
|
if (error.failureCategory !== undefined)
|
|
81
91
|
mapped.failureCategory = error.failureCategory;
|
|
82
92
|
return mapped;
|
|
@@ -161,8 +171,7 @@ function mapEntryRow(params) {
|
|
|
161
171
|
row.percentUsed = 100 - entry.percentRemaining;
|
|
162
172
|
}
|
|
163
173
|
applyResetFields(row, entry, preferences);
|
|
164
|
-
|
|
165
|
-
applyRunway(row, entry, nowMs);
|
|
174
|
+
applyRunway(row, entry, nowMs);
|
|
166
175
|
if (preferences.accountingDetail === "detailed" && entry.basis) {
|
|
167
176
|
const detailRows = detailRowsFor(entry.basis);
|
|
168
177
|
if (detailRows.length > 0)
|
|
@@ -212,43 +221,18 @@ function mapEntryRows(params) {
|
|
|
212
221
|
windowsBySlot.set(slot, { rowId: row.rowId, slot });
|
|
213
222
|
}
|
|
214
223
|
}
|
|
224
|
+
const visibilityRows = optionalVisibilityRowsFor(params.providerId, params.cardId, rows);
|
|
215
225
|
return {
|
|
216
226
|
rows,
|
|
217
227
|
primaryQuotaWindows: [...windowsBySlot.values()].sort((left, right) => left.slot - right.slot),
|
|
228
|
+
visibilityRows,
|
|
218
229
|
};
|
|
219
230
|
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
authority: "provider_reported",
|
|
224
|
-
};
|
|
225
|
-
function optionalValueRowId(cardId, rowKey, resultType) {
|
|
226
|
-
return rowIdForEntry(cardId, {
|
|
227
|
-
kind: "value",
|
|
228
|
-
name: "",
|
|
229
|
-
value: "",
|
|
230
|
-
rowKey,
|
|
231
|
-
accounting: { ...OPENAI_OPTIONAL_ROW_ACCOUNTING, resultType },
|
|
232
|
-
});
|
|
233
|
-
}
|
|
234
|
-
/**
|
|
235
|
-
* Persistent Resets/Credits choices for an OpenAI card. These are metadata for
|
|
236
|
-
* the Settings eyes only; they never create a zero/empty Quota data row.
|
|
237
|
-
*/
|
|
238
|
-
export function openAiOptionalVisibilityRows(cardId) {
|
|
239
|
-
return [
|
|
240
|
-
{
|
|
241
|
-
rowId: optionalValueRowId(cardId, OPENAI_RESETS_ROW_KEY, OPENAI_RESETS_ROW_RESULT_TYPE),
|
|
242
|
-
label: OPENAI_RESETS_ROW_LABEL,
|
|
243
|
-
info: OPENAI_RESETS_INFO,
|
|
244
|
-
},
|
|
245
|
-
{
|
|
246
|
-
rowId: optionalValueRowId(cardId, OPENAI_CREDITS_ROW_KEY, OPENAI_CREDITS_ROW_RESULT_TYPE),
|
|
247
|
-
label: OPENAI_CREDITS_ROW_LABEL,
|
|
248
|
-
info: OPENAI_CREDITS_INFO,
|
|
249
|
-
},
|
|
250
|
-
];
|
|
231
|
+
/** The stable row id an optional declared row carries once the provider emits it. */
|
|
232
|
+
export function optionalValueRowId(cardId, rowKey, resultType) {
|
|
233
|
+
return optionalRowId(cardId, rowKey, resultType, "value");
|
|
251
234
|
}
|
|
235
|
+
export { quotaEntryIsHidden };
|
|
252
236
|
function latestObservedAtIso(entries) {
|
|
253
237
|
let latest;
|
|
254
238
|
let latestMs = Number.NEGATIVE_INFINITY;
|
|
@@ -285,6 +269,17 @@ function pushInto(map, key, value) {
|
|
|
285
269
|
else
|
|
286
270
|
map.set(key, [value]);
|
|
287
271
|
}
|
|
272
|
+
function finishCard(card, mapped, entries) {
|
|
273
|
+
if (mapped.primaryQuotaWindows.length > 0) {
|
|
274
|
+
card.primaryQuotaWindows = mapped.primaryQuotaWindows;
|
|
275
|
+
}
|
|
276
|
+
if (mapped.visibilityRows)
|
|
277
|
+
card.visibilityRows = mapped.visibilityRows;
|
|
278
|
+
const observedAtIso = latestObservedAtIso(entries);
|
|
279
|
+
if (observedAtIso)
|
|
280
|
+
card.observedAtIso = observedAtIso;
|
|
281
|
+
return card;
|
|
282
|
+
}
|
|
288
283
|
function buildProviderCard(params) {
|
|
289
284
|
const cardId = buildProviderScopeCardId(params.providerId);
|
|
290
285
|
const mapped = mapEntryRows({
|
|
@@ -294,25 +289,19 @@ function buildProviderCard(params) {
|
|
|
294
289
|
preferences: params.preferences,
|
|
295
290
|
nowMs: params.nowMs,
|
|
296
291
|
});
|
|
292
|
+
const planLabel = params.planLabel ? sanitizeSingleLineDisplayText(params.planLabel).trim() : "";
|
|
297
293
|
const card = {
|
|
298
294
|
cardId,
|
|
299
295
|
providerId: params.providerId,
|
|
300
296
|
providerLabel: params.providerLabel,
|
|
301
297
|
providerScopeId: params.providerScopeId,
|
|
302
298
|
providerScopeHash: params.providerScopeHash,
|
|
299
|
+
...(planLabel ? { planLabel } : {}),
|
|
303
300
|
labelSource: "provider",
|
|
304
301
|
rows: mapped.rows,
|
|
305
302
|
errors: params.errors.map((error) => mapProviderError(error, params.secrets)),
|
|
306
303
|
};
|
|
307
|
-
|
|
308
|
-
card.primaryQuotaWindows = mapped.primaryQuotaWindows;
|
|
309
|
-
}
|
|
310
|
-
if (params.providerId === "openai")
|
|
311
|
-
card.visibilityRows = openAiOptionalVisibilityRows(cardId);
|
|
312
|
-
const observedAtIso = latestObservedAtIso(params.entries);
|
|
313
|
-
if (observedAtIso)
|
|
314
|
-
card.observedAtIso = observedAtIso;
|
|
315
|
-
return card;
|
|
304
|
+
return finishCard(card, mapped, params.entries);
|
|
316
305
|
}
|
|
317
306
|
function buildAccountCard(params) {
|
|
318
307
|
const identityKey = params.account.identityKey?.trim()
|
|
@@ -344,15 +333,7 @@ function buildAccountCard(params) {
|
|
|
344
333
|
rows: mapped.rows,
|
|
345
334
|
errors: params.errors.map((error) => mapProviderError(error, params.secrets)),
|
|
346
335
|
};
|
|
347
|
-
|
|
348
|
-
card.primaryQuotaWindows = mapped.primaryQuotaWindows;
|
|
349
|
-
}
|
|
350
|
-
if (params.providerId === "openai")
|
|
351
|
-
card.visibilityRows = openAiOptionalVisibilityRows(cardId);
|
|
352
|
-
const observedAtIso = latestObservedAtIso(params.entries);
|
|
353
|
-
if (observedAtIso)
|
|
354
|
-
card.observedAtIso = observedAtIso;
|
|
355
|
-
return card;
|
|
336
|
+
return finishCard(card, mapped, params.entries);
|
|
356
337
|
}
|
|
357
338
|
/**
|
|
358
339
|
* One card per discovered account (zero-entry and failed ones included) plus a
|
|
@@ -382,7 +363,7 @@ export function buildProviderCards(input) {
|
|
|
382
363
|
const unscopedErrors = [];
|
|
383
364
|
for (const entry of probe.result.entries) {
|
|
384
365
|
const sourceId = entry.accounting.sourceId;
|
|
385
|
-
if (sourceId !==
|
|
366
|
+
if (cardSourceKey(sourceId, accountSourceIds) !== UNSCOPED && sourceId !== undefined) {
|
|
386
367
|
pushInto(entriesBySource, sourceId, entry);
|
|
387
368
|
}
|
|
388
369
|
else {
|
|
@@ -391,7 +372,7 @@ export function buildProviderCards(input) {
|
|
|
391
372
|
}
|
|
392
373
|
for (const error of probe.result.errors) {
|
|
393
374
|
const sourceId = error.sourceId;
|
|
394
|
-
if (sourceId !==
|
|
375
|
+
if (cardSourceKey(sourceId, accountSourceIds) !== UNSCOPED && sourceId !== undefined) {
|
|
395
376
|
pushInto(errorsBySource, sourceId, error);
|
|
396
377
|
}
|
|
397
378
|
else {
|
|
@@ -405,12 +386,16 @@ export function buildProviderCards(input) {
|
|
|
405
386
|
providerLabel,
|
|
406
387
|
providerScopeId,
|
|
407
388
|
providerScopeHash,
|
|
389
|
+
// A plan belongs to this card only when the provider has no account cards of its own.
|
|
390
|
+
planLabel: accounts.length === 0 ? probe.result.planLabel : undefined,
|
|
408
391
|
entries: unscopedEntries,
|
|
409
392
|
errors: unscopedErrors,
|
|
410
393
|
secrets,
|
|
411
394
|
preferences,
|
|
412
395
|
nowMs,
|
|
413
396
|
});
|
|
397
|
+
if (probe.retainedUnscoped)
|
|
398
|
+
card.stale = true;
|
|
414
399
|
if (!seenCardIds.has(card.cardId)) {
|
|
415
400
|
seenCardIds.add(card.cardId);
|
|
416
401
|
cards.push(card);
|
|
@@ -430,6 +415,8 @@ export function buildProviderCards(input) {
|
|
|
430
415
|
preferences,
|
|
431
416
|
nowMs,
|
|
432
417
|
});
|
|
418
|
+
if (probe.retainedSourceIds?.has(account.sourceId))
|
|
419
|
+
card.stale = true;
|
|
433
420
|
if (seenCardIds.has(card.cardId))
|
|
434
421
|
continue;
|
|
435
422
|
seenCardIds.add(card.cardId);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { QuotaCardRow } from "../contracts/dashboard.js";
|
|
2
|
-
import type { ProviderFailureCategory } from "../contracts/provider-failure.js";
|
|
2
|
+
import type { ProviderFailureCategory, QuotaAttemptOutcome } from "../contracts/provider-failure.js";
|
|
3
3
|
import { type ResetObservation } from "../lib/quota-reset-notifications.js";
|
|
4
|
+
import type { NativeQuotaNotificationPolicy } from "../lib/types.js";
|
|
4
5
|
export declare const QUOTA_NOTIFICATION_DETECTOR_STATE_VERSION: 1;
|
|
5
6
|
/** Shared proven reset-transition age limit re-exported for detector consumers. */
|
|
6
7
|
export declare const RESET_TRANSITION_MAX_AGE_MS: number;
|
|
@@ -62,6 +63,7 @@ export interface QuotaNotificationRowObservation {
|
|
|
62
63
|
label: string;
|
|
63
64
|
kind: QuotaCardRow["kind"];
|
|
64
65
|
resultType: QuotaCardRow["resultType"];
|
|
66
|
+
metric?: QuotaCardRow["metric"];
|
|
65
67
|
percentRemaining?: number;
|
|
66
68
|
resetAtIso?: string;
|
|
67
69
|
}
|
|
@@ -76,14 +78,33 @@ export interface QuotaNotificationCardObservation {
|
|
|
76
78
|
accountLabel?: string;
|
|
77
79
|
/** Bare provider-scope hash used by normalized legacy hidden-card semantics. */
|
|
78
80
|
providerScopeHash?: string;
|
|
81
|
+
/**
|
|
82
|
+
* True when the card's rows are retained last-good data rather than this
|
|
83
|
+
* cycle's measurement. A transient failed poll never raises a provider-error
|
|
84
|
+
* notification for retained readings; the card still shows the error.
|
|
85
|
+
*/
|
|
86
|
+
stale?: boolean;
|
|
79
87
|
rows: readonly QuotaNotificationRowObservation[];
|
|
88
|
+
/**
|
|
89
|
+
* Declared optional-row controls. Their stable ids and aliases make a hidden
|
|
90
|
+
* field silent regardless of which shape the provider emitted this cycle.
|
|
91
|
+
*/
|
|
92
|
+
visibilityRows?: readonly {
|
|
93
|
+
rowId: string;
|
|
94
|
+
aliases?: readonly string[];
|
|
95
|
+
}[];
|
|
80
96
|
errors?: readonly QuotaNotificationProviderErrorObservation[];
|
|
81
97
|
}
|
|
82
98
|
/** Only the safe structured category is read; labels and messages are ignored. */
|
|
83
99
|
export interface QuotaNotificationProviderErrorObservation {
|
|
84
100
|
failureCategory?: ProviderFailureCategory;
|
|
101
|
+
/** A cooldown skip made no request and is never a failure observation. */
|
|
102
|
+
attemptOutcome?: QuotaAttemptOutcome;
|
|
85
103
|
}
|
|
86
|
-
/**
|
|
104
|
+
/**
|
|
105
|
+
* Unknown or absent categories are never notifiable. A cooldown skip is a
|
|
106
|
+
* timing decision, not a provider failure, so it is also not notifiable.
|
|
107
|
+
*/
|
|
87
108
|
export declare function isNotifiableProviderError(error: QuotaNotificationProviderErrorObservation): boolean;
|
|
88
109
|
/** Exact reset observation shared with the legacy notifier. */
|
|
89
110
|
export type QuotaNotificationResetObservation = ResetObservation;
|
|
@@ -98,6 +119,10 @@ export interface QuotaNotificationRowState {
|
|
|
98
119
|
export interface QuotaNotificationProviderState {
|
|
99
120
|
status: "healthy" | "error";
|
|
100
121
|
observedAtMs: number;
|
|
122
|
+
/** Consecutive observations that carried a notifiable provider error. */
|
|
123
|
+
consecutiveErrors?: number;
|
|
124
|
+
/** The latest error observation was suppressed because its rows were retained. */
|
|
125
|
+
staleError?: boolean;
|
|
101
126
|
}
|
|
102
127
|
/** Memory-only detector state. Do not persist rows/providers across restarts. */
|
|
103
128
|
export interface QuotaNotificationDetectorState {
|
|
@@ -117,10 +142,8 @@ export interface DetectQuotaNotificationsInput {
|
|
|
117
142
|
cooldowns?: Readonly<Record<string, number>>;
|
|
118
143
|
/** Injectable clock supplied by the caller. */
|
|
119
144
|
nowMs: number;
|
|
120
|
-
/**
|
|
121
|
-
|
|
122
|
-
/** Caller/settings-supplied cooldown. The detector owns no default. */
|
|
123
|
-
cooldownMs: number;
|
|
145
|
+
/** Canonical Native notification policy. The detector owns no settings defaults. */
|
|
146
|
+
policy: NativeQuotaNotificationPolicy;
|
|
124
147
|
}
|
|
125
148
|
export interface DetectQuotaNotificationsResult {
|
|
126
149
|
notifications: QuotaNotification[];
|
|
@@ -20,6 +20,9 @@
|
|
|
20
20
|
* - `provider-error`: a proven healthy -> error transition, only when the
|
|
21
21
|
* caller supplies safe structured failure provenance. Error labels and
|
|
22
22
|
* messages are never inspected.
|
|
23
|
+
* - Retained last-good rows (a `stale` card) keep their previous observation
|
|
24
|
+
* state and are never evaluated for low/exhausted/reset transitions; live
|
|
25
|
+
* provider errors on that card still count.
|
|
23
26
|
* - Cooldown always applies to the exact fingerprint and is never bypassed.
|
|
24
27
|
* - First startup and newly visible cards or rows silently baseline.
|
|
25
28
|
*
|
|
@@ -49,6 +52,7 @@
|
|
|
49
52
|
*/
|
|
50
53
|
import { createHash } from "node:crypto";
|
|
51
54
|
import { isCardHidden } from "../contracts/card-visibility.js";
|
|
55
|
+
import { effectiveHiddenRowIds } from "../contracts/row-visibility.js";
|
|
52
56
|
import { MAX_TRANSITION_AGE_MS, updateObservation as updateLegacyResetObservation, } from "../lib/quota-reset-notifications.js";
|
|
53
57
|
export const QUOTA_NOTIFICATION_DETECTOR_STATE_VERSION = 1;
|
|
54
58
|
/** Shared proven reset-transition age limit re-exported for detector consumers. */
|
|
@@ -59,8 +63,13 @@ export const RESET_TRANSITION_MAX_AGE_MS = MAX_TRANSITION_AGE_MS;
|
|
|
59
63
|
*/
|
|
60
64
|
export const QUOTA_NOTIFICATION_PROVIDER_ERROR_CATEGORY = "provider_api";
|
|
61
65
|
const FINGERPRINT_DOMAIN = "ocq-quota-notification-v1";
|
|
62
|
-
/**
|
|
66
|
+
/**
|
|
67
|
+
* Unknown or absent categories are never notifiable. A cooldown skip is a
|
|
68
|
+
* timing decision, not a provider failure, so it is also not notifiable.
|
|
69
|
+
*/
|
|
63
70
|
export function isNotifiableProviderError(error) {
|
|
71
|
+
if (error.attemptOutcome === "cooldown")
|
|
72
|
+
return false;
|
|
64
73
|
return error.failureCategory === QUOTA_NOTIFICATION_PROVIDER_ERROR_CATEGORY;
|
|
65
74
|
}
|
|
66
75
|
/**
|
|
@@ -127,19 +136,41 @@ function isEligiblePercentRow(row) {
|
|
|
127
136
|
typeof row.percentRemaining === "number" &&
|
|
128
137
|
Number.isFinite(row.percentRemaining));
|
|
129
138
|
}
|
|
139
|
+
function resetWindowForRow(row) {
|
|
140
|
+
if (row.metric?.kind !== "window")
|
|
141
|
+
return undefined;
|
|
142
|
+
switch (row.metric.window) {
|
|
143
|
+
case "five_hour":
|
|
144
|
+
return "fiveHour";
|
|
145
|
+
case "hour":
|
|
146
|
+
return "hourly";
|
|
147
|
+
case "day":
|
|
148
|
+
return "daily";
|
|
149
|
+
case "week":
|
|
150
|
+
return "weekly";
|
|
151
|
+
case "month":
|
|
152
|
+
return "monthly";
|
|
153
|
+
case "year":
|
|
154
|
+
return "yearly";
|
|
155
|
+
default:
|
|
156
|
+
return undefined;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
130
159
|
export function detectQuotaNotifications(input) {
|
|
131
160
|
const nowMs = input.nowMs;
|
|
132
161
|
const hiddenCards = new Set(input.hiddenCards ?? []);
|
|
133
|
-
const
|
|
162
|
+
const configuredHiddenRows = input.hiddenRows ?? [];
|
|
134
163
|
const previousState = input.state?.version === QUOTA_NOTIFICATION_DETECTOR_STATE_VERSION ? input.state : undefined;
|
|
135
164
|
const cooldowns = { ...(input.cooldowns ?? {}) };
|
|
136
165
|
const notifications = [];
|
|
166
|
+
const { policy } = input;
|
|
167
|
+
const cooldownMs = policy.duplicateCooldownMinutes * 60_000;
|
|
137
168
|
const nextRows = new Map();
|
|
138
169
|
const nextProviders = new Map();
|
|
139
170
|
const seenCards = new Set();
|
|
140
171
|
const emit = (fingerprint, notification) => {
|
|
141
172
|
const lastAtMs = cooldowns[fingerprint];
|
|
142
|
-
if (lastAtMs !== undefined && nowMs - lastAtMs <
|
|
173
|
+
if (lastAtMs !== undefined && nowMs - lastAtMs < cooldownMs)
|
|
143
174
|
return false;
|
|
144
175
|
notifications.push(notification);
|
|
145
176
|
cooldowns[fingerprint] = nowMs;
|
|
@@ -149,9 +180,26 @@ export function detectQuotaNotifications(input) {
|
|
|
149
180
|
if (seenCards.has(card.cardId) || isCardHidden(card, hiddenCards))
|
|
150
181
|
continue;
|
|
151
182
|
seenCards.add(card.cardId);
|
|
183
|
+
const hiddenRows = effectiveHiddenRowIds(card.rows.map((row) => row.rowId), configuredHiddenRows, card.visibilityRows ?? []);
|
|
184
|
+
const cardRowsRetained = card.stale === true;
|
|
185
|
+
if (cardRowsRetained) {
|
|
186
|
+
// Retained last-good rows stay out of threshold/reset evaluation. Keep
|
|
187
|
+
// their previous observation state so the next fresh reading still
|
|
188
|
+
// compares against the last real measurement.
|
|
189
|
+
const prefix = `${card.cardId}\u001f`;
|
|
190
|
+
for (const [key, state] of Object.entries(previousState?.rows ?? {})) {
|
|
191
|
+
if (!key.startsWith(prefix) || nextRows.has(key))
|
|
192
|
+
continue;
|
|
193
|
+
if (hiddenRows.has(key.slice(prefix.length)))
|
|
194
|
+
continue;
|
|
195
|
+
nextRows.set(key, cloneRowState(state));
|
|
196
|
+
}
|
|
197
|
+
}
|
|
152
198
|
for (const row of card.rows) {
|
|
153
199
|
if (hiddenRows.has(row.rowId))
|
|
154
200
|
continue;
|
|
201
|
+
if (cardRowsRetained)
|
|
202
|
+
continue;
|
|
155
203
|
if (!isEligiblePercentRow(row))
|
|
156
204
|
continue;
|
|
157
205
|
const key = rowStateKey(card.cardId, row.rowId);
|
|
@@ -198,42 +246,52 @@ export function detectQuotaNotifications(input) {
|
|
|
198
246
|
nextRows.set(key, makeRowState(currentPercent, nowMs, resetObservation));
|
|
199
247
|
if (resetEvent) {
|
|
200
248
|
const resetAtIso = new Date(resetEvent.resetAtMs).toISOString();
|
|
201
|
-
const
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
249
|
+
const resetWindow = resetWindowForRow(row);
|
|
250
|
+
if (policy.enabled &&
|
|
251
|
+
policy.reset.enabled &&
|
|
252
|
+
resetWindow !== undefined &&
|
|
253
|
+
policy.reset.windows.includes(resetWindow)) {
|
|
254
|
+
const fingerprint = quotaNotificationFingerprint({
|
|
255
|
+
kind: "reset",
|
|
256
|
+
cardId: card.cardId,
|
|
257
|
+
rowId: row.rowId,
|
|
258
|
+
resetAtIso,
|
|
259
|
+
});
|
|
260
|
+
emit(fingerprint, {
|
|
261
|
+
...notificationBase(card, fingerprint, nowMs),
|
|
262
|
+
kind: "reset",
|
|
263
|
+
rowId: row.rowId,
|
|
264
|
+
rowLabel: row.label,
|
|
265
|
+
percentRemaining: currentPercent,
|
|
266
|
+
resetAtIso,
|
|
267
|
+
previousResetAtIso: new Date(resetEvent.previousResetAtMs).toISOString(),
|
|
268
|
+
});
|
|
269
|
+
}
|
|
216
270
|
continue;
|
|
217
271
|
}
|
|
218
272
|
const previousPercent = previousRow.percentRemaining;
|
|
219
273
|
if (previousPercent > 0 && currentPercent <= 0) {
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
274
|
+
if (policy.enabled && policy.exhausted.enabled) {
|
|
275
|
+
const fingerprint = quotaNotificationFingerprint({
|
|
276
|
+
kind: "exhausted",
|
|
277
|
+
cardId: card.cardId,
|
|
278
|
+
rowId: row.rowId,
|
|
279
|
+
});
|
|
280
|
+
emit(fingerprint, {
|
|
281
|
+
...notificationBase(card, fingerprint, nowMs),
|
|
282
|
+
kind: "exhausted",
|
|
283
|
+
rowId: row.rowId,
|
|
284
|
+
rowLabel: row.label,
|
|
285
|
+
percentRemaining: currentPercent,
|
|
286
|
+
...(normalizedResetAtIso !== undefined ? { resetAtIso: normalizedResetAtIso } : {}),
|
|
287
|
+
});
|
|
288
|
+
}
|
|
233
289
|
continue;
|
|
234
290
|
}
|
|
235
|
-
if (
|
|
236
|
-
|
|
291
|
+
if (policy.enabled &&
|
|
292
|
+
policy.low.enabled &&
|
|
293
|
+
previousPercent > policy.low.thresholdRemainingPercent &&
|
|
294
|
+
currentPercent <= policy.low.thresholdRemainingPercent) {
|
|
237
295
|
const fingerprint = quotaNotificationFingerprint({
|
|
238
296
|
kind: "low",
|
|
239
297
|
cardId: card.cardId,
|
|
@@ -244,7 +302,7 @@ export function detectQuotaNotifications(input) {
|
|
|
244
302
|
kind: "low",
|
|
245
303
|
rowId: row.rowId,
|
|
246
304
|
rowLabel: row.label,
|
|
247
|
-
thresholdPercent:
|
|
305
|
+
thresholdPercent: policy.low.thresholdRemainingPercent,
|
|
248
306
|
percentRemaining: currentPercent,
|
|
249
307
|
...(normalizedResetAtIso !== undefined ? { resetAtIso: normalizedResetAtIso } : {}),
|
|
250
308
|
});
|
|
@@ -255,21 +313,52 @@ export function detectQuotaNotifications(input) {
|
|
|
255
313
|
nextProviders.set(card.cardId, { ...previousProvider });
|
|
256
314
|
continue;
|
|
257
315
|
}
|
|
258
|
-
const
|
|
259
|
-
|
|
260
|
-
|
|
316
|
+
const isError = card.errors?.some(isNotifiableProviderError) ?? false;
|
|
317
|
+
// A cooldown skip made no request: it is neither a failure observation nor
|
|
318
|
+
// a recovery, so an existing failure streak and its retained-error
|
|
319
|
+
// suppression stay intact until a real attempt reports.
|
|
320
|
+
const isCooldownSkip = !isError && (card.errors?.some((error) => error.attemptOutcome === "cooldown") ?? false);
|
|
321
|
+
if (isCooldownSkip && previousProvider !== undefined) {
|
|
322
|
+
nextProviders.set(card.cardId, { ...previousProvider });
|
|
323
|
+
continue;
|
|
324
|
+
}
|
|
325
|
+
const status = isError ? "error" : "healthy";
|
|
326
|
+
const consecutiveErrors = isError
|
|
327
|
+
? previousProvider?.status === "error"
|
|
328
|
+
? (previousProvider.consecutiveErrors ?? 1) + 1
|
|
329
|
+
: 1
|
|
330
|
+
: 0;
|
|
331
|
+
const providerState = { status, observedAtMs: nowMs };
|
|
332
|
+
if (isError) {
|
|
333
|
+
providerState.consecutiveErrors = consecutiveErrors;
|
|
334
|
+
providerState.staleError = card.stale === true;
|
|
335
|
+
}
|
|
336
|
+
nextProviders.set(card.cardId, providerState);
|
|
337
|
+
if (!previousProvider || status !== "error") {
|
|
338
|
+
continue;
|
|
339
|
+
}
|
|
340
|
+
// One transient poll failure on a card that still shows retained last-good
|
|
341
|
+
// rows is silent; the second consecutive failing observation is a proven
|
|
342
|
+
// persistent error and alerts. A fresh error without retained rows alerts
|
|
343
|
+
// immediately. The card shows the error either way.
|
|
344
|
+
const freshTransition = previousProvider.status === "healthy" && card.stale !== true;
|
|
345
|
+
const persistentAfterSuppressed = previousProvider.status === "error" &&
|
|
346
|
+
previousProvider.staleError === true &&
|
|
347
|
+
consecutiveErrors === 2;
|
|
348
|
+
if (!freshTransition && !persistentAfterSuppressed)
|
|
261
349
|
continue;
|
|
350
|
+
if (policy.enabled && policy.providerError.enabled) {
|
|
351
|
+
const fingerprint = quotaNotificationFingerprint({
|
|
352
|
+
kind: "provider-error",
|
|
353
|
+
cardId: card.cardId,
|
|
354
|
+
category: QUOTA_NOTIFICATION_PROVIDER_ERROR_CATEGORY,
|
|
355
|
+
});
|
|
356
|
+
emit(fingerprint, {
|
|
357
|
+
...notificationBase(card, fingerprint, nowMs),
|
|
358
|
+
kind: "provider-error",
|
|
359
|
+
category: QUOTA_NOTIFICATION_PROVIDER_ERROR_CATEGORY,
|
|
360
|
+
});
|
|
262
361
|
}
|
|
263
|
-
const fingerprint = quotaNotificationFingerprint({
|
|
264
|
-
kind: "provider-error",
|
|
265
|
-
cardId: card.cardId,
|
|
266
|
-
category: QUOTA_NOTIFICATION_PROVIDER_ERROR_CATEGORY,
|
|
267
|
-
});
|
|
268
|
-
emit(fingerprint, {
|
|
269
|
-
...notificationBase(card, fingerprint, nowMs),
|
|
270
|
-
kind: "provider-error",
|
|
271
|
-
category: QUOTA_NOTIFICATION_PROVIDER_ERROR_CATEGORY,
|
|
272
|
-
});
|
|
273
362
|
}
|
|
274
363
|
return {
|
|
275
364
|
notifications,
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import type { QuotaSnapshot, SettingsSnapshot } from "../contracts/dashboard.js";
|
|
2
|
-
import { type PercentDisplayMode } from "../lib/types.js";
|
|
2
|
+
import { type NativeQuotaNotificationPolicy, type PercentDisplayMode } from "../lib/types.js";
|
|
3
3
|
import type { DashboardRpcQuotaNotificationData } from "../rpc.js";
|
|
4
4
|
import { type GuiLogger } from "./log.js";
|
|
5
5
|
/** Effective settings for one observation. */
|
|
6
6
|
export interface QuotaNotificationSettings {
|
|
7
|
-
readonly
|
|
8
|
-
readonly cooldownMs: number;
|
|
7
|
+
readonly policy: NativeQuotaNotificationPolicy;
|
|
9
8
|
readonly hiddenCards: readonly string[];
|
|
10
9
|
readonly hiddenRows: readonly string[];
|
|
11
10
|
readonly percentDisplayMode: PercentDisplayMode;
|
|
@@ -23,7 +22,7 @@ export interface QuotaNotificationObserverOptions {
|
|
|
23
22
|
}
|
|
24
23
|
export interface QuotaNotificationObserver {
|
|
25
24
|
/**
|
|
26
|
-
* Queue one observation of a
|
|
25
|
+
* Queue one observation of a completed quota source cycle. A caller with an
|
|
27
26
|
* asynchronous source read must capture `epoch()` before that read and pass
|
|
28
27
|
* it here; an observation whose captured epoch no longer matches is dropped.
|
|
29
28
|
* Never rejects.
|