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
|
@@ -18,11 +18,13 @@
|
|
|
18
18
|
*/
|
|
19
19
|
import { readFile } from "node:fs/promises";
|
|
20
20
|
import { writeJsonAtomic } from "../lib/atomic-json.js";
|
|
21
|
+
import { isValidDuplicateCooldownMinutes, isValidLowQuotaThresholdRemainingPercent, isValidNativeQuotaNotificationPolicy, } from "../lib/config.js";
|
|
21
22
|
import { formatResetCountdown } from "../lib/format-utils.js";
|
|
22
23
|
import { getGuiPrivateStatePath } from "../lib/private-state-paths.js";
|
|
23
|
-
import { DEFAULT_CONFIG } from "../lib/types.js";
|
|
24
|
+
import { DEFAULT_CONFIG, } from "../lib/types.js";
|
|
24
25
|
import { createGuiLogger } from "./log.js";
|
|
25
26
|
import { detectQuotaNotifications, QUOTA_NOTIFICATION_DETECTOR_STATE_VERSION, } from "./quota-notification-detector.js";
|
|
27
|
+
import { isLiveQuotaObservation } from "./quota-observation.js";
|
|
26
28
|
const PERSISTED_STATE_VERSION = 1;
|
|
27
29
|
const DEFAULT_STATE_FILE = "quota-notifications.json";
|
|
28
30
|
const MAX_LABEL_LENGTH = 80;
|
|
@@ -33,15 +35,6 @@ function isRecord(value) {
|
|
|
33
35
|
function isFiniteNumber(value) {
|
|
34
36
|
return typeof value === "number" && Number.isFinite(value);
|
|
35
37
|
}
|
|
36
|
-
function numberSetting(values, key, fallback, min, max) {
|
|
37
|
-
const value = values[key];
|
|
38
|
-
if (value === undefined || value === null)
|
|
39
|
-
return fallback;
|
|
40
|
-
if (!isFiniteNumber(value) || value < min || value > max) {
|
|
41
|
-
throw new Error(CONFIG_UNAVAILABLE);
|
|
42
|
-
}
|
|
43
|
-
return value;
|
|
44
|
-
}
|
|
45
38
|
function displayModeSetting(values) {
|
|
46
39
|
const value = values.percentDisplayMode;
|
|
47
40
|
if (value === undefined || value === null)
|
|
@@ -62,6 +55,64 @@ function hiddenIds(value) {
|
|
|
62
55
|
}
|
|
63
56
|
return result;
|
|
64
57
|
}
|
|
58
|
+
function nativeQuotaNotificationPolicyFromValues(values) {
|
|
59
|
+
const rawPolicy = values.nativeQuotaNotifications;
|
|
60
|
+
if (rawPolicy !== undefined && !isRecord(rawPolicy))
|
|
61
|
+
throw new Error(CONFIG_UNAVAILABLE);
|
|
62
|
+
const fields = isRecord(rawPolicy) ? rawPolicy : {};
|
|
63
|
+
const defaults = DEFAULT_CONFIG.nativeQuotaNotifications;
|
|
64
|
+
const candidate = {
|
|
65
|
+
...defaults,
|
|
66
|
+
...fields,
|
|
67
|
+
low: Object.hasOwn(fields, "low")
|
|
68
|
+
? isRecord(fields.low)
|
|
69
|
+
? { ...defaults.low, ...fields.low }
|
|
70
|
+
: fields.low
|
|
71
|
+
: { ...defaults.low },
|
|
72
|
+
exhausted: Object.hasOwn(fields, "exhausted")
|
|
73
|
+
? isRecord(fields.exhausted)
|
|
74
|
+
? { ...defaults.exhausted, ...fields.exhausted }
|
|
75
|
+
: fields.exhausted
|
|
76
|
+
: { ...defaults.exhausted },
|
|
77
|
+
reset: Object.hasOwn(fields, "reset")
|
|
78
|
+
? isRecord(fields.reset)
|
|
79
|
+
? { ...defaults.reset, ...fields.reset }
|
|
80
|
+
: fields.reset
|
|
81
|
+
: { ...defaults.reset, windows: [...defaults.reset.windows] },
|
|
82
|
+
providerError: Object.hasOwn(fields, "providerError")
|
|
83
|
+
? isRecord(fields.providerError)
|
|
84
|
+
? { ...defaults.providerError, ...fields.providerError }
|
|
85
|
+
: fields.providerError
|
|
86
|
+
: { ...defaults.providerError },
|
|
87
|
+
};
|
|
88
|
+
if (!isValidNativeQuotaNotificationPolicy(candidate))
|
|
89
|
+
throw new Error(CONFIG_UNAVAILABLE);
|
|
90
|
+
const policy = {
|
|
91
|
+
...candidate,
|
|
92
|
+
low: { ...candidate.low },
|
|
93
|
+
exhausted: { ...candidate.exhausted },
|
|
94
|
+
reset: { ...candidate.reset, windows: [...candidate.reset.windows] },
|
|
95
|
+
providerError: { ...candidate.providerError },
|
|
96
|
+
};
|
|
97
|
+
const hasCanonicalLowThreshold = isRecord(fields.low) && Object.hasOwn(fields.low, "thresholdRemainingPercent");
|
|
98
|
+
const legacyLowThreshold = values.lowQuotaThresholdRemainingPercent;
|
|
99
|
+
if (!hasCanonicalLowThreshold &&
|
|
100
|
+
legacyLowThreshold !== undefined &&
|
|
101
|
+
legacyLowThreshold !== null) {
|
|
102
|
+
if (!isValidLowQuotaThresholdRemainingPercent(legacyLowThreshold)) {
|
|
103
|
+
throw new Error(CONFIG_UNAVAILABLE);
|
|
104
|
+
}
|
|
105
|
+
policy.low.thresholdRemainingPercent = legacyLowThreshold;
|
|
106
|
+
}
|
|
107
|
+
const hasCanonicalCooldown = Object.hasOwn(fields, "duplicateCooldownMinutes");
|
|
108
|
+
const legacyCooldown = values.duplicateCooldownMinutes;
|
|
109
|
+
if (!hasCanonicalCooldown && legacyCooldown !== undefined && legacyCooldown !== null) {
|
|
110
|
+
if (!isValidDuplicateCooldownMinutes(legacyCooldown))
|
|
111
|
+
throw new Error(CONFIG_UNAVAILABLE);
|
|
112
|
+
policy.duplicateCooldownMinutes = legacyCooldown;
|
|
113
|
+
}
|
|
114
|
+
return policy;
|
|
115
|
+
}
|
|
65
116
|
/**
|
|
66
117
|
* Maps the canonical settings snapshot to the observer's effective values.
|
|
67
118
|
* Missing keys use the product defaults; malformed values and malformed or
|
|
@@ -73,10 +124,9 @@ export function quotaNotificationSettingsFromSnapshot(snapshot) {
|
|
|
73
124
|
throw new Error(CONFIG_UNAVAILABLE);
|
|
74
125
|
if (!isRecord(snapshot.visibility))
|
|
75
126
|
throw new Error(CONFIG_UNAVAILABLE);
|
|
76
|
-
const
|
|
127
|
+
const policy = nativeQuotaNotificationPolicyFromValues(snapshot.values);
|
|
77
128
|
return {
|
|
78
|
-
|
|
79
|
-
cooldownMs: cooldownMinutes * 60_000,
|
|
129
|
+
policy,
|
|
80
130
|
hiddenCards: hiddenIds(snapshot.visibility.hiddenCards),
|
|
81
131
|
hiddenRows: hiddenIds(snapshot.visibility.hiddenRows),
|
|
82
132
|
percentDisplayMode: displayModeSetting(snapshot.values),
|
|
@@ -260,7 +310,10 @@ export function createQuotaNotificationObserver(options) {
|
|
|
260
310
|
async function observeNow(snapshot, epoch) {
|
|
261
311
|
if (closed || epoch !== sourceEpoch)
|
|
262
312
|
return;
|
|
263
|
-
|
|
313
|
+
// Cached replays are synthesized from an earlier snapshot and carry no live
|
|
314
|
+
// observation. A stale live cycle still carries fresh error observations and
|
|
315
|
+
// retained rows; the detector excludes those rows from transitions.
|
|
316
|
+
if (snapshot.stale === true && !isLiveQuotaObservation(snapshot))
|
|
264
317
|
return;
|
|
265
318
|
let settings;
|
|
266
319
|
try {
|
|
@@ -274,17 +327,18 @@ export function createQuotaNotificationObserver(options) {
|
|
|
274
327
|
if (closed || epoch !== sourceEpoch)
|
|
275
328
|
return;
|
|
276
329
|
const nowMs = now();
|
|
330
|
+
const cooldownMs = settings.policy.duplicateCooldownMinutes * 60_000;
|
|
277
331
|
if (!cooldownsLoaded) {
|
|
278
332
|
cooldowns = mergeCooldowns(cooldowns, await readCooldowns(statePath));
|
|
279
333
|
cooldownsLoaded = true;
|
|
280
334
|
if (closed || epoch !== sourceEpoch)
|
|
281
335
|
return;
|
|
282
336
|
}
|
|
283
|
-
const prunedCooldowns = pruneCooldowns(cooldowns, nowMs,
|
|
337
|
+
const prunedCooldowns = pruneCooldowns(cooldowns, nowMs, cooldownMs);
|
|
284
338
|
const cooldownsWerePruned = !sameCooldowns(cooldowns, prunedCooldowns);
|
|
285
339
|
cooldowns = prunedCooldowns;
|
|
286
340
|
if (cooldownsWerePruned) {
|
|
287
|
-
const persisted = await persist(cooldowns, nowMs,
|
|
341
|
+
const persisted = await persist(cooldowns, nowMs, cooldownMs);
|
|
288
342
|
cooldowns = persisted ?? cooldowns;
|
|
289
343
|
if (closed || epoch !== sourceEpoch)
|
|
290
344
|
return;
|
|
@@ -296,8 +350,7 @@ export function createQuotaNotificationObserver(options) {
|
|
|
296
350
|
...(needsBaseline || detectorState === undefined ? {} : { state: detectorState }),
|
|
297
351
|
cooldowns,
|
|
298
352
|
nowMs,
|
|
299
|
-
|
|
300
|
-
cooldownMs: settings.cooldownMs,
|
|
353
|
+
policy: settings.policy,
|
|
301
354
|
});
|
|
302
355
|
if (closed || epoch !== sourceEpoch)
|
|
303
356
|
return;
|
|
@@ -307,10 +360,10 @@ export function createQuotaNotificationObserver(options) {
|
|
|
307
360
|
providers: result.state.providers,
|
|
308
361
|
};
|
|
309
362
|
needsBaseline = false;
|
|
310
|
-
cooldowns = pruneCooldowns(result.cooldowns, nowMs,
|
|
363
|
+
cooldowns = pruneCooldowns(result.cooldowns, nowMs, cooldownMs);
|
|
311
364
|
if (result.notifications.length === 0)
|
|
312
365
|
return;
|
|
313
|
-
const persisted = await persist(cooldowns, nowMs,
|
|
366
|
+
const persisted = await persist(cooldowns, nowMs, cooldownMs);
|
|
314
367
|
cooldowns = persisted ?? cooldowns;
|
|
315
368
|
// A handoff can land while the cooldown write is in flight. Fence before
|
|
316
369
|
// publishing so the old source's event never reaches the new generation.
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { QuotaSnapshot } from "../contracts/dashboard.js";
|
|
2
|
+
export declare function markQuotaObservationLive(snapshot: QuotaSnapshot): QuotaSnapshot;
|
|
3
|
+
export declare function isLiveQuotaObservation(snapshot: QuotaSnapshot): boolean;
|
|
4
|
+
//# sourceMappingURL=quota-observation.d.ts.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Live-cycle identity for quota observations.
|
|
3
|
+
*
|
|
4
|
+
* The notification observer must tell a just-finished source cycle from a
|
|
5
|
+
* cached replay of an earlier snapshot. A live cycle can be marked
|
|
6
|
+
* `stale: true` because it retained last-good rows; a cached replay is
|
|
7
|
+
* synthesized separately and is never registered here. WeakSet membership
|
|
8
|
+
* keeps this internal signal out of the DTO and never survives serialization.
|
|
9
|
+
*/
|
|
10
|
+
const liveQuotaObservations = new WeakSet();
|
|
11
|
+
export function markQuotaObservationLive(snapshot) {
|
|
12
|
+
liveQuotaObservations.add(snapshot);
|
|
13
|
+
return snapshot;
|
|
14
|
+
}
|
|
15
|
+
export function isLiveQuotaObservation(snapshot) {
|
|
16
|
+
return liveQuotaObservations.has(snapshot);
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=quota-observation.js.map
|
package/dist/gui/rpc.d.ts
CHANGED
|
@@ -38,6 +38,8 @@ export interface DashboardRpcLocation {
|
|
|
38
38
|
}
|
|
39
39
|
export interface RegisterDashboardRpcOptions {
|
|
40
40
|
logger?: GuiLogger;
|
|
41
|
+
/** Enqueues a source-state snapshot through this registration's owner relay. */
|
|
42
|
+
onWatchSnapshot?: (attemptNonce: string) => void;
|
|
41
43
|
/**
|
|
42
44
|
* The complete location this setup serves. OpenCode's event bus filters on
|
|
43
45
|
* both `directory` and `workspaceID`, so sharing is keyed by both: setups at
|
package/dist/gui/rpc.js
CHANGED
|
@@ -89,6 +89,9 @@ function mapRpcError(error) {
|
|
|
89
89
|
details: sanitizeDashboardErrorDetails(safeCode, errorDetails(error)) ?? {},
|
|
90
90
|
};
|
|
91
91
|
}
|
|
92
|
+
// The analytics worker's own `timeout`, `unavailable`, and `closed` codes land
|
|
93
|
+
// here as `internal`: they are terminal for that worker read, not the host's
|
|
94
|
+
// transport deadline, so a client must not re-join them as a timed-out RPC.
|
|
92
95
|
return {
|
|
93
96
|
code: "internal",
|
|
94
97
|
message: DASHBOARD_ERROR_MESSAGES.internal,
|
|
@@ -132,10 +135,18 @@ function waitForAbort(signal, onStop) {
|
|
|
132
135
|
signal.addEventListener("abort", finish, { once: true });
|
|
133
136
|
});
|
|
134
137
|
}
|
|
135
|
-
function createHandlers(runtime, heldWatches) {
|
|
138
|
+
function createHandlers(runtime, heldWatches, onWatchSnapshot) {
|
|
136
139
|
async function watch(input, context) {
|
|
137
140
|
return guard(context, async () => {
|
|
138
141
|
const viewer = runtime.snapshots.addScopedViewer(input.scope);
|
|
142
|
+
if (!context.signal.aborted && input.attemptNonce !== undefined) {
|
|
143
|
+
try {
|
|
144
|
+
onWatchSnapshot?.(input.attemptNonce);
|
|
145
|
+
}
|
|
146
|
+
catch {
|
|
147
|
+
// Snapshot relay failure cannot interrupt this held viewer's lifecycle.
|
|
148
|
+
}
|
|
149
|
+
}
|
|
139
150
|
let stopped = false;
|
|
140
151
|
let stop = () => { };
|
|
141
152
|
await waitForAbort(context.signal, (finish) => {
|
|
@@ -159,7 +170,7 @@ function createHandlers(runtime, heldWatches) {
|
|
|
159
170
|
version: BUILD_IDENTITY.version,
|
|
160
171
|
build: BUILD_IDENTITY.build,
|
|
161
172
|
}),
|
|
162
|
-
quota: (
|
|
173
|
+
quota: (input, context) => guard(context, () => runtime.snapshots.quota(input)),
|
|
163
174
|
home: (input, context) => guard(context, () => runtime.snapshots.home(input)),
|
|
164
175
|
groups: (input, context) => guard(context, () => runtime.snapshots.groups(input)),
|
|
165
176
|
project: (input, context) => guard(context, () => runtime.snapshots.project(input)),
|
|
@@ -278,7 +289,7 @@ export async function registerDashboardRpc(rpc, runtime, options = {}) {
|
|
|
278
289
|
const logger = options.logger ?? createGuiLogger();
|
|
279
290
|
const key = locationKey(options.location);
|
|
280
291
|
const heldWatches = new Set();
|
|
281
|
-
const registration = await rpc.register(DashboardRpc, createHandlers(runtime, heldWatches));
|
|
292
|
+
const registration = await rpc.register(DashboardRpc, createHandlers(runtime, heldWatches, options.onWatchSnapshot));
|
|
282
293
|
const member = { registration, heldWatches, alive: true };
|
|
283
294
|
const entry = joinSharedEntry(runtime.snapshots, key, member, runtime.quotaNotifications);
|
|
284
295
|
let disposed = false;
|
package/dist/gui/server.js
CHANGED
|
@@ -426,11 +426,20 @@ export function createDashboardServer(options) {
|
|
|
426
426
|
return;
|
|
427
427
|
}
|
|
428
428
|
if (rest.length === 1 && rest[0] === "quota") {
|
|
429
|
-
if (!requireMethods(req, res, ["GET", "HEAD"]))
|
|
429
|
+
if (!requireMethods(req, res, ["GET", "HEAD", "POST"]))
|
|
430
430
|
return;
|
|
431
|
+
if (method === "POST") {
|
|
432
|
+
const parsed = await readWriteJson(req, res);
|
|
433
|
+
if (!parsed.ok)
|
|
434
|
+
return;
|
|
435
|
+
if (!isRecord(parsed.value) || !hasExactKeys(parsed.value, [])) {
|
|
436
|
+
sendError(res, "bad-request");
|
|
437
|
+
return;
|
|
438
|
+
}
|
|
439
|
+
}
|
|
431
440
|
// Inference only; an explicit PUT /api/v1/view signal wins.
|
|
432
441
|
snapshots.setViewScope("quota", "request");
|
|
433
|
-
sendJson(res, 200, await snapshots.quota());
|
|
442
|
+
sendJson(res, 200, await snapshots.quota(req.method === "POST" ? { refresh: true } : undefined));
|
|
434
443
|
return;
|
|
435
444
|
}
|
|
436
445
|
if (rest.length === 1 && rest[0] === "home") {
|
|
@@ -442,7 +451,12 @@ export function createDashboardServer(options) {
|
|
|
442
451
|
return;
|
|
443
452
|
}
|
|
444
453
|
snapshots.setViewScope("analytics", "request");
|
|
445
|
-
|
|
454
|
+
const background = url.searchParams.get("background");
|
|
455
|
+
if (background !== null && background !== "true" && background !== "false") {
|
|
456
|
+
sendError(res, "bad-request");
|
|
457
|
+
return;
|
|
458
|
+
}
|
|
459
|
+
sendJson(res, 200, await snapshots.home({ range, ...(background === "true" ? { background: true } : {}) }));
|
|
446
460
|
return;
|
|
447
461
|
}
|
|
448
462
|
if (rest.length === 2 && rest[0] === "projects") {
|
|
@@ -40,8 +40,7 @@
|
|
|
40
40
|
*
|
|
41
41
|
* No TTL, sequence, watermark, or budget machinery exists (R9).
|
|
42
42
|
*/
|
|
43
|
-
import type {
|
|
44
|
-
import type { RangeKey } from "../contracts/ranges.js";
|
|
43
|
+
import type { DashboardDataSource, DashboardEvent } from "../contracts/dashboard.js";
|
|
45
44
|
import { type GuiLogger } from "./log.js";
|
|
46
45
|
/** Default quota/provider poll interval (spec §4.2; existing config overrides). */
|
|
47
46
|
export declare const DEFAULT_QUOTA_INTERVAL_MS = 60000;
|
|
@@ -67,6 +66,7 @@ export declare const MAX_TRACKED_PAGES = 16;
|
|
|
67
66
|
* `refreshAnalytics` is an optional shared worker refresh seam, and `close` is
|
|
68
67
|
* closed by the lifecycle when the last lease disposes, not by this service.
|
|
69
68
|
*/
|
|
69
|
+
/** Same-key home reads must coalesce, including foreground priority joins. */
|
|
70
70
|
export type SnapshotSource = Pick<DashboardDataSource, "home" | "project" | "session"> & {
|
|
71
71
|
quota?: DashboardDataSource["quota"];
|
|
72
72
|
groups?: DashboardDataSource["groups"];
|
|
@@ -102,19 +102,7 @@ export type SnapshotViewScope = "analytics" | "quota";
|
|
|
102
102
|
export interface SnapshotViewer {
|
|
103
103
|
release(): void;
|
|
104
104
|
}
|
|
105
|
-
export interface SnapshotService {
|
|
106
|
-
home(input: {
|
|
107
|
-
range: RangeKey;
|
|
108
|
-
}): Promise<HomeSnapshot>;
|
|
109
|
-
quota(): Promise<QuotaSnapshot>;
|
|
110
|
-
project(input: {
|
|
111
|
-
projectId: string;
|
|
112
|
-
range: RangeKey;
|
|
113
|
-
}): Promise<ProjectSnapshot>;
|
|
114
|
-
session(input: {
|
|
115
|
-
sessionId: string;
|
|
116
|
-
}): Promise<SessionSnapshot>;
|
|
117
|
-
groups(query: AnalyticsGroupQuery): Promise<AnalyticsGroupSnapshot>;
|
|
105
|
+
export interface SnapshotService extends Pick<DashboardDataSource, "home" | "quota" | "project" | "session" | "groups"> {
|
|
118
106
|
/** Invalidations broadcast over SSE (three topics, never raw snapshots). */
|
|
119
107
|
subscribe(listener: (event: DashboardEvent) => void): () => void;
|
|
120
108
|
/**
|