opencode-quota-gui 1.3.1 → 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 +16 -12
- 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 +87 -5
- package/dist/contracts/dashboard.js +10 -0
- package/dist/contracts/dto-guards.d.ts +4 -0
- package/dist/contracts/dto-guards.js +29 -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/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 +3 -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 +2 -2
- package/dist/gui/config.js +46 -5
- package/dist/gui/identity.d.ts +6 -20
- package/dist/gui/identity.js +6 -54
- package/dist/gui/primary-quota-windows.js +55 -34
- package/dist/gui/provider-cards.d.ts +12 -8
- package/dist/gui/provider-cards.js +12 -53
- package/dist/gui/quota-notification-detector.d.ts +25 -2
- package/dist/gui/quota-notification-detector.js +60 -5
- package/dist/gui/quota-notification-observer.d.ts +1 -1
- package/dist/gui/quota-notification-observer.js +5 -1
- package/dist/gui/quota-observation.d.ts +4 -0
- package/dist/gui/quota-observation.js +18 -0
- package/dist/gui/rpc.js +3 -0
- package/dist/gui/server.js +6 -1
- package/dist/gui/snapshot-service.d.ts +3 -17
- package/dist/gui/snapshot-service.js +159 -9
- package/dist/gui/sources.js +84 -11
- package/dist/gui/temporal-status.d.ts +3 -2
- package/dist/gui/temporal-status.js +10 -6
- package/dist/gui-experimental.cjs +228 -228
- package/dist/lib/accounting-format.d.ts +8 -0
- package/dist/lib/accounting-format.js +12 -2
- 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-oauth-throttle.d.ts +76 -0
- package/dist/lib/anthropic-oauth-throttle.js +379 -0
- package/dist/lib/anthropic.d.ts +22 -4
- package/dist/lib/anthropic.js +498 -180
- package/dist/lib/cache-observer-ingestion.js +27 -0
- package/dist/lib/cache-observer.d.ts +3 -0
- package/dist/lib/cache-observer.js +9 -3
- package/dist/lib/cli-show.d.ts +5 -0
- package/dist/lib/cli-show.js +16 -5
- package/dist/lib/cli-status.js +3 -6
- package/dist/lib/config.d.ts +1 -1
- package/dist/lib/config.js +64 -2
- package/dist/lib/dashboard-visibility.d.ts +5 -0
- package/dist/lib/dashboard-visibility.js +11 -10
- package/dist/lib/display-sanitize.js +1 -0
- package/dist/lib/entries.d.ts +10 -1
- package/dist/lib/entries.js +4 -0
- package/dist/lib/grouped-entry-normalization.js +1 -1
- package/dist/lib/maintainer-announcements.js +2 -2
- 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/opencode-config-providers.js +2 -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 +7 -0
- package/dist/lib/opencode-version-core.js +10 -0
- package/dist/lib/opencode-warming-refresh.d.ts +19 -0
- package/dist/lib/opencode-warming-refresh.js +95 -0
- package/dist/lib/provider-metadata.d.ts +11 -3
- package/dist/lib/provider-metadata.js +20 -2
- package/dist/lib/provider-registration.d.ts +342 -3
- package/dist/lib/provider-registration.js +409 -27
- 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 +22 -9
- package/dist/lib/quota-identity.d.ts +64 -0
- package/dist/lib/quota-identity.js +111 -0
- package/dist/lib/quota-providers.js +2 -2
- package/dist/lib/quota-render-data.js +2 -2
- 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 +14 -1
- package/dist/lib/quota-state.d.ts +1 -1
- package/dist/lib/quota-state.js +60 -28
- package/dist/lib/quota-stats.d.ts +26 -0
- package/dist/lib/quota-stats.js +19 -1
- 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/state-file-lock.d.ts +26 -0
- package/dist/lib/state-file-lock.js +205 -0
- package/dist/lib/toast-format-grouped.js +7 -4
- package/dist/lib/tui-compact-format.js +29 -16
- package/dist/lib/types.d.ts +20 -0
- package/dist/lib/types.js +4 -1
- package/dist/plugin.js +67 -1
- package/dist/providers/alibaba-coding-plan.js +21 -3
- package/dist/providers/alibaba-token-plan.js +9 -5
- package/dist/providers/anthropic.d.ts +6 -2
- package/dist/providers/anthropic.js +123 -14
- package/dist/providers/chutes.js +2 -0
- package/dist/providers/claude-agent.js +24 -5
- package/dist/providers/copilot.js +5 -4
- package/dist/providers/glm-coding-plan-provider.js +30 -23
- package/dist/providers/ollama-cloud.js +10 -0
- package/dist/providers/openai.js +24 -23
- package/dist/providers/opencode-go.js +7 -6
- package/dist/providers/opencode-zen.js +1 -1
- package/dist/providers/result-helpers.d.ts +4 -2
- package/dist/providers/result-helpers.js +5 -1
- package/dist/providers/synthetic.js +4 -0
- package/dist/providers/xai.js +9 -8
- package/dist/rpc.d.ts +8 -0
- package/dist/rpc.js +15 -2
- package/dist/ui/assets/{index-BcueIm3Z.css → index-6_g1FHs-.css} +1 -1
- package/dist/ui/assets/index-sZnGUuML.js +10 -0
- package/dist/ui/assets/{popover-4bFSvRZ7.js → popover-C4ZLYe9E.js} +1 -1
- package/dist/ui/index.html +2 -2
- package/package.json +3 -3
- package/dist/ui/assets/index-C6qRSoh8.js +0 -10
|
@@ -9,20 +9,17 @@
|
|
|
9
9
|
* the heap.
|
|
10
10
|
*/
|
|
11
11
|
import { encodeAnalyticsGroupQueryKey } from "../contracts/analytics-entity.js";
|
|
12
|
-
import { AnalyticsReadError } from "./analytics-protocol.js";
|
|
12
|
+
import { ANALYTICS_DEFAULT_REQUEST_TIMEOUT_MS, AnalyticsReadError } from "./analytics-protocol.js";
|
|
13
13
|
import { createGuiLogger } from "./log.js";
|
|
14
|
-
|
|
15
|
-
* Cold 7d/30d/lifetime analytics catch-up reads the full source store and can
|
|
16
|
-
* legitimately take tens of seconds on a slow local disk; a foreground request
|
|
17
|
-
* queued behind one can add its own scoped read. The old 90 s budget retired
|
|
18
|
-
* healthy workers mid-read on measured sources. Keep a finite budget above the
|
|
19
|
-
* measured worst request (112.9 s on the reported source), so genuinely stuck
|
|
20
|
-
* workers are still retired and recovered on the next request.
|
|
21
|
-
*/
|
|
22
|
-
export const ANALYTICS_DEFAULT_REQUEST_TIMEOUT_MS = 180_000;
|
|
14
|
+
export { ANALYTICS_DEFAULT_REQUEST_TIMEOUT_MS };
|
|
23
15
|
const DEFAULT_RETRY_BASE_MS = 250;
|
|
24
16
|
const DEFAULT_MAX_RECOVERY_ATTEMPTS = 5;
|
|
25
17
|
const MAX_RETRY_DELAY_MS = 5_000;
|
|
18
|
+
/**
|
|
19
|
+
* Upper bound for worker-advertised pricing upkeep. It must outlive the 6 s
|
|
20
|
+
* refresh timeout, but a lost "inactive" frame must not pin the worker forever.
|
|
21
|
+
*/
|
|
22
|
+
const DEFAULT_UPKEEP_MAX_WAIT_MS = 30_000;
|
|
26
23
|
/** Pure mapping for the optional Node worker heap limit. */
|
|
27
24
|
export function workerResourceLimits(limitMb) {
|
|
28
25
|
if (limitMb === undefined || !Number.isFinite(limitMb) || limitMb <= 0)
|
|
@@ -56,7 +53,7 @@ async function createDefaultWorker(workerHeapLimitMb) {
|
|
|
56
53
|
function coalescedCommandKey(command) {
|
|
57
54
|
switch (command.kind) {
|
|
58
55
|
case "home":
|
|
59
|
-
return `home\u0000${command.range}`;
|
|
56
|
+
return `home\u0000${command.range}\u0000${command.exact === true}`;
|
|
60
57
|
case "project":
|
|
61
58
|
return `project\u0000${command.projectId}\u0000${command.range}`;
|
|
62
59
|
case "session":
|
|
@@ -87,14 +84,23 @@ export function createAnalyticsBridge(options = {}) {
|
|
|
87
84
|
options.maxRecoveryAttempts > 0
|
|
88
85
|
? Math.floor(options.maxRecoveryAttempts)
|
|
89
86
|
: DEFAULT_MAX_RECOVERY_ATTEMPTS;
|
|
87
|
+
const idleRetireMs = options.idleRetireMs !== undefined &&
|
|
88
|
+
Number.isFinite(options.idleRetireMs) &&
|
|
89
|
+
options.idleRetireMs >= 0
|
|
90
|
+
? Math.floor(options.idleRetireMs)
|
|
91
|
+
: 0;
|
|
90
92
|
let worker;
|
|
91
93
|
let workerPromise;
|
|
94
|
+
let draining;
|
|
95
|
+
let idleRetireTimer;
|
|
92
96
|
let initOptions = {};
|
|
93
97
|
let closed = false;
|
|
94
98
|
let broken = false;
|
|
95
99
|
let failures = 0;
|
|
96
100
|
let nextRetryAtMs = 0;
|
|
97
101
|
let nextRequestId = 1;
|
|
102
|
+
let upkeepActive = 0;
|
|
103
|
+
let upkeepWaitTimer;
|
|
98
104
|
const pending = new Map();
|
|
99
105
|
/**
|
|
100
106
|
* In-flight reads keyed by command identity. Identical reads from reconnect
|
|
@@ -104,6 +110,8 @@ export function createAnalyticsBridge(options = {}) {
|
|
|
104
110
|
* even if every original caller has gone away.
|
|
105
111
|
*/
|
|
106
112
|
const inFlightReads = new Map();
|
|
113
|
+
const queue = [];
|
|
114
|
+
let running = false;
|
|
107
115
|
const listeners = new Set();
|
|
108
116
|
const retiredInstances = new WeakSet();
|
|
109
117
|
function failPending(code) {
|
|
@@ -133,6 +141,8 @@ export function createAnalyticsBridge(options = {}) {
|
|
|
133
141
|
}
|
|
134
142
|
}
|
|
135
143
|
function retire(instance, code) {
|
|
144
|
+
cancelIdleRetire();
|
|
145
|
+
resetUpkeep();
|
|
136
146
|
if (instance !== undefined) {
|
|
137
147
|
retiredInstances.add(instance);
|
|
138
148
|
if (worker === instance) {
|
|
@@ -181,6 +191,10 @@ export function createAnalyticsBridge(options = {}) {
|
|
|
181
191
|
}
|
|
182
192
|
return;
|
|
183
193
|
}
|
|
194
|
+
if (record.type === "analytics-upkeep") {
|
|
195
|
+
setUpkeepActive(record.active === true);
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
184
198
|
const response = value;
|
|
185
199
|
if (typeof response.id !== "number")
|
|
186
200
|
return;
|
|
@@ -210,7 +224,7 @@ export function createAnalyticsBridge(options = {}) {
|
|
|
210
224
|
instance.onmessage = (event) => onMessage(event.data);
|
|
211
225
|
instance.onerror = onFailure;
|
|
212
226
|
}
|
|
213
|
-
function send(instance, command) {
|
|
227
|
+
function send(instance, command, graceful = false) {
|
|
214
228
|
const id = nextRequestId;
|
|
215
229
|
nextRequestId += 1;
|
|
216
230
|
return new Promise((resolve, reject) => {
|
|
@@ -218,9 +232,10 @@ export function createAnalyticsBridge(options = {}) {
|
|
|
218
232
|
pending.delete(id);
|
|
219
233
|
// A timed-out worker may still be alive but stuck (for example a
|
|
220
234
|
// deterministic OOM loop). Retire it so the next call starts clean.
|
|
221
|
-
|
|
235
|
+
if (!graceful)
|
|
236
|
+
retire(instance, "unavailable");
|
|
222
237
|
reject(new AnalyticsReadError("timeout"));
|
|
223
|
-
}, requestTimeoutMs);
|
|
238
|
+
}, graceful ? 2_500 : requestTimeoutMs);
|
|
224
239
|
const unref = timer.unref;
|
|
225
240
|
if (typeof unref === "function")
|
|
226
241
|
unref.call(timer);
|
|
@@ -231,7 +246,8 @@ export function createAnalyticsBridge(options = {}) {
|
|
|
231
246
|
catch {
|
|
232
247
|
pending.delete(id);
|
|
233
248
|
clearTimeout(timer);
|
|
234
|
-
|
|
249
|
+
if (!graceful)
|
|
250
|
+
retire(instance, "unavailable");
|
|
235
251
|
reject(new AnalyticsReadError("unavailable"));
|
|
236
252
|
}
|
|
237
253
|
});
|
|
@@ -241,6 +257,10 @@ export function createAnalyticsBridge(options = {}) {
|
|
|
241
257
|
throw new AnalyticsReadError("closed");
|
|
242
258
|
if (broken)
|
|
243
259
|
throw new AnalyticsReadError("unavailable");
|
|
260
|
+
if (draining)
|
|
261
|
+
await draining;
|
|
262
|
+
if (closed)
|
|
263
|
+
throw new AnalyticsReadError("closed");
|
|
244
264
|
if (worker)
|
|
245
265
|
return worker;
|
|
246
266
|
if (workerPromise)
|
|
@@ -303,29 +323,166 @@ export function createAnalyticsBridge(options = {}) {
|
|
|
303
323
|
workerPromise = creation;
|
|
304
324
|
return await creation;
|
|
305
325
|
}
|
|
306
|
-
async function
|
|
326
|
+
async function retireGracefully(instance) {
|
|
327
|
+
cancelIdleRetire();
|
|
328
|
+
try {
|
|
329
|
+
await send(instance, { kind: "close" }, true);
|
|
330
|
+
}
|
|
331
|
+
catch {
|
|
332
|
+
// Shutdown is best effort and must not affect recovery backoff.
|
|
333
|
+
}
|
|
334
|
+
finally {
|
|
335
|
+
retiredInstances.add(instance);
|
|
336
|
+
if (worker === instance)
|
|
337
|
+
worker = undefined;
|
|
338
|
+
try {
|
|
339
|
+
await instance.terminate();
|
|
340
|
+
}
|
|
341
|
+
catch {
|
|
342
|
+
// Best effort.
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
function drainIdleWorker(instance) {
|
|
347
|
+
const done = retireGracefully(instance);
|
|
348
|
+
draining = done.finally(() => {
|
|
349
|
+
draining = undefined;
|
|
350
|
+
pump();
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
function cancelIdleRetire() {
|
|
354
|
+
if (idleRetireTimer === undefined)
|
|
355
|
+
return;
|
|
356
|
+
clearTimeout(idleRetireTimer);
|
|
357
|
+
idleRetireTimer = undefined;
|
|
358
|
+
}
|
|
359
|
+
function clearUpkeepWait() {
|
|
360
|
+
if (upkeepWaitTimer === undefined)
|
|
361
|
+
return;
|
|
362
|
+
clearTimeout(upkeepWaitTimer);
|
|
363
|
+
upkeepWaitTimer = undefined;
|
|
364
|
+
}
|
|
365
|
+
function resetUpkeep() {
|
|
366
|
+
clearUpkeepWait();
|
|
367
|
+
upkeepActive = 0;
|
|
368
|
+
}
|
|
369
|
+
/**
|
|
370
|
+
* Track pricing upkeep the worker started after its last reply. Idle
|
|
371
|
+
* retirement waits for the matching "inactive" frame (or the safety cap), so
|
|
372
|
+
* a 6 s models.dev request is not cut off by the shorter idle grace.
|
|
373
|
+
*/
|
|
374
|
+
function setUpkeepActive(active) {
|
|
375
|
+
if (active) {
|
|
376
|
+
upkeepActive += 1;
|
|
377
|
+
if (upkeepActive === 1 && upkeepWaitTimer === undefined) {
|
|
378
|
+
upkeepWaitTimer = setTimeout(() => {
|
|
379
|
+
upkeepWaitTimer = undefined;
|
|
380
|
+
upkeepActive = 0;
|
|
381
|
+
pump();
|
|
382
|
+
}, DEFAULT_UPKEEP_MAX_WAIT_MS);
|
|
383
|
+
// SAFETY: the host Node timer owns `unref`; the browser/DOM timer shape
|
|
384
|
+
// simply omits it, which the optional call tolerates.
|
|
385
|
+
upkeepWaitTimer.unref?.();
|
|
386
|
+
}
|
|
387
|
+
return;
|
|
388
|
+
}
|
|
389
|
+
upkeepActive = Math.max(0, upkeepActive - 1);
|
|
390
|
+
if (upkeepActive > 0)
|
|
391
|
+
return;
|
|
392
|
+
clearUpkeepWait();
|
|
393
|
+
pump();
|
|
394
|
+
}
|
|
395
|
+
function retireWhenIdle(instance) {
|
|
396
|
+
if (upkeepActive > 0)
|
|
397
|
+
return;
|
|
398
|
+
if (idleRetireMs === 0) {
|
|
399
|
+
drainIdleWorker(instance);
|
|
400
|
+
return;
|
|
401
|
+
}
|
|
402
|
+
if (idleRetireTimer !== undefined)
|
|
403
|
+
return;
|
|
404
|
+
idleRetireTimer = setTimeout(() => {
|
|
405
|
+
idleRetireTimer = undefined;
|
|
406
|
+
if (closed ||
|
|
407
|
+
running ||
|
|
408
|
+
queue.length > 0 ||
|
|
409
|
+
pending.size > 0 ||
|
|
410
|
+
upkeepActive > 0 ||
|
|
411
|
+
draining ||
|
|
412
|
+
worker !== instance) {
|
|
413
|
+
return;
|
|
414
|
+
}
|
|
415
|
+
drainIdleWorker(instance);
|
|
416
|
+
}, idleRetireMs);
|
|
417
|
+
// SAFETY: the host Node timer owns `unref`; the browser/DOM timer shape
|
|
418
|
+
// simply omits it, which the optional call tolerates.
|
|
419
|
+
idleRetireTimer.unref?.();
|
|
420
|
+
}
|
|
421
|
+
function pump() {
|
|
422
|
+
if (running || closed)
|
|
423
|
+
return;
|
|
424
|
+
if (queue.length === 0) {
|
|
425
|
+
const instance = worker;
|
|
426
|
+
if (instance && !draining && pending.size === 0)
|
|
427
|
+
retireWhenIdle(instance);
|
|
428
|
+
return;
|
|
429
|
+
}
|
|
430
|
+
cancelIdleRetire();
|
|
431
|
+
const foreground = queue.findIndex((job) => !job.background);
|
|
432
|
+
const [job] = queue.splice(foreground < 0 ? 0 : foreground, 1);
|
|
433
|
+
if (!job)
|
|
434
|
+
return;
|
|
435
|
+
running = true;
|
|
436
|
+
void job.run().finally(() => {
|
|
437
|
+
running = false;
|
|
438
|
+
if (queue.length > 0)
|
|
439
|
+
pump();
|
|
440
|
+
else
|
|
441
|
+
setImmediate(pump);
|
|
442
|
+
});
|
|
443
|
+
}
|
|
444
|
+
async function call(command, background = false) {
|
|
445
|
+
if (closed)
|
|
446
|
+
throw new AnalyticsReadError("closed");
|
|
447
|
+
cancelIdleRetire();
|
|
307
448
|
const key = coalescedCommandKey(command);
|
|
308
449
|
if (key !== undefined) {
|
|
309
450
|
const existing = inFlightReads.get(key);
|
|
310
451
|
// SAFETY: the key covers every input of the command, and all callers of
|
|
311
452
|
// that key request the same result type.
|
|
312
|
-
if (existing !== undefined)
|
|
453
|
+
if (existing !== undefined) {
|
|
454
|
+
if (!background) {
|
|
455
|
+
const queued = queue.find((job) => job.key === key);
|
|
456
|
+
if (queued)
|
|
457
|
+
queued.background = false;
|
|
458
|
+
}
|
|
313
459
|
return existing;
|
|
460
|
+
}
|
|
314
461
|
}
|
|
315
|
-
const request = (
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
462
|
+
const request = new Promise((resolve, reject) => {
|
|
463
|
+
queue.push({
|
|
464
|
+
key,
|
|
465
|
+
background,
|
|
466
|
+
reject,
|
|
467
|
+
run: async () => {
|
|
468
|
+
try {
|
|
469
|
+
const instance = await ensureWorker();
|
|
470
|
+
if (closed)
|
|
471
|
+
throw new AnalyticsReadError("closed");
|
|
472
|
+
if (retiredInstances.has(instance))
|
|
473
|
+
throw new AnalyticsReadError("unavailable");
|
|
474
|
+
const response = await send(instance, command);
|
|
475
|
+
if (!response.ok)
|
|
476
|
+
throw new AnalyticsReadError(response.error.code);
|
|
477
|
+
resolve(response.result);
|
|
478
|
+
}
|
|
479
|
+
catch (error) {
|
|
480
|
+
reject(error);
|
|
481
|
+
}
|
|
482
|
+
},
|
|
483
|
+
});
|
|
484
|
+
queueMicrotask(pump);
|
|
485
|
+
});
|
|
329
486
|
if (key !== undefined) {
|
|
330
487
|
inFlightReads.set(key, request);
|
|
331
488
|
const clear = () => {
|
|
@@ -344,8 +501,9 @@ export function createAnalyticsBridge(options = {}) {
|
|
|
344
501
|
throw new AnalyticsReadError("closed");
|
|
345
502
|
initOptions = nextOptions;
|
|
346
503
|
await ensureWorker();
|
|
504
|
+
queueMicrotask(pump);
|
|
347
505
|
},
|
|
348
|
-
home: (range) => call({ kind: "home", range }),
|
|
506
|
+
home: (range, exact, background) => call({ kind: "home", range, ...(exact ? { exact } : {}) }, background),
|
|
349
507
|
project: (projectId, range) => call({ kind: "project", projectId, range }),
|
|
350
508
|
session: (sessionId) => call({ kind: "session", sessionId }),
|
|
351
509
|
groups: (query) => call({ kind: "groups", query }),
|
|
@@ -360,34 +518,19 @@ export function createAnalyticsBridge(options = {}) {
|
|
|
360
518
|
if (closed)
|
|
361
519
|
return;
|
|
362
520
|
closed = true;
|
|
521
|
+
cancelIdleRetire();
|
|
522
|
+
resetUpkeep();
|
|
523
|
+
for (const job of queue.splice(0))
|
|
524
|
+
job.reject(new AnalyticsReadError("closed"));
|
|
525
|
+
if (draining)
|
|
526
|
+
await draining;
|
|
363
527
|
const instance = worker;
|
|
364
528
|
worker = undefined;
|
|
365
529
|
workerPromise = undefined;
|
|
366
530
|
listeners.clear();
|
|
367
531
|
failPending("closed");
|
|
368
532
|
if (instance) {
|
|
369
|
-
|
|
370
|
-
// before the thread is terminated.
|
|
371
|
-
try {
|
|
372
|
-
await Promise.race([
|
|
373
|
-
send(instance, { kind: "close" }).catch(() => undefined),
|
|
374
|
-
new Promise((resolve) => {
|
|
375
|
-
const timer = setTimeout(resolve, 2_500);
|
|
376
|
-
const unref = timer.unref;
|
|
377
|
-
if (typeof unref === "function")
|
|
378
|
-
unref.call(timer);
|
|
379
|
-
}),
|
|
380
|
-
]);
|
|
381
|
-
}
|
|
382
|
-
catch {
|
|
383
|
-
// Close remains best effort.
|
|
384
|
-
}
|
|
385
|
-
try {
|
|
386
|
-
instance.terminate();
|
|
387
|
-
}
|
|
388
|
-
catch {
|
|
389
|
-
// Termination is best effort; pending callers were already rejected.
|
|
390
|
-
}
|
|
533
|
+
await retireGracefully(instance);
|
|
391
534
|
failPending("closed");
|
|
392
535
|
}
|
|
393
536
|
},
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import { type RangeKey } from "../contracts/ranges.js";
|
|
1
|
+
import type { AnalyticsRangeReader } from "../contracts/dashboard.js";
|
|
3
2
|
import type { AnalyticsPhaseMetrics } from "./analytics-protocol.js";
|
|
4
3
|
import { type AnalyticsReader } from "./analytics-reader.js";
|
|
5
4
|
import { type AnalyticsState, type WarmAnalyticsPresentation } from "./analytics-state.js";
|
|
@@ -8,12 +7,6 @@ export declare const ANALYTICS_REFRESH_INTERVAL_MS = 600000;
|
|
|
8
7
|
export declare const ANALYTICS_FULL_REPAIR_INTERVAL_MS: number;
|
|
9
8
|
/** Inclusive replay overlap for equal/late `time_updated` values (clock skew). */
|
|
10
9
|
export declare const ANALYTICS_SOURCE_CURSOR_OVERLAP_MS: number;
|
|
11
|
-
/**
|
|
12
|
-
* Idle grace before the automatic 7d -> 30d extension starts. A zero-delay
|
|
13
|
-
* timer only yields one event-loop turn and can immediately queue a long
|
|
14
|
-
* synchronous SQL read ahead of foreground navigation.
|
|
15
|
-
*/
|
|
16
|
-
export declare const ANALYTICS_THIRTY_DAY_EXTENSION_DELAY_MS = 2000;
|
|
17
10
|
export interface AnalyticsEngineOptions {
|
|
18
11
|
reader?: AnalyticsReader;
|
|
19
12
|
snapshotPath?: string;
|
|
@@ -47,16 +40,15 @@ export interface AnalyticsWorkerMemory {
|
|
|
47
40
|
*/
|
|
48
41
|
phases?: AnalyticsPhaseMetrics;
|
|
49
42
|
}
|
|
50
|
-
export interface AnalyticsEngine {
|
|
51
|
-
home(range: RangeKey): Promise<HomeSnapshot>;
|
|
52
|
-
project(projectId: string, range: RangeKey): Promise<ProjectSnapshot>;
|
|
53
|
-
session(sessionId: string): Promise<SessionSnapshot>;
|
|
54
|
-
/** One range-certified grouped model/provider read over the shared model. */
|
|
55
|
-
groups(query: AnalyticsGroupQuery): Promise<AnalyticsGroupSnapshot>;
|
|
56
|
-
refresh(): Promise<void>;
|
|
43
|
+
export interface AnalyticsEngine extends AnalyticsRangeReader {
|
|
57
44
|
stats(): Promise<AnalyticsWorkerMemory>;
|
|
58
45
|
/** Best-effort GC trigger; false when the runtime exposes no hook. */
|
|
59
46
|
gc(): Promise<boolean>;
|
|
47
|
+
/** Distinct analytics routes whose last pricing outcome had no cost. */
|
|
48
|
+
unpricedRoutes(): Array<{
|
|
49
|
+
providerID?: string;
|
|
50
|
+
modelID?: string;
|
|
51
|
+
}>;
|
|
60
52
|
close(): Promise<void>;
|
|
61
53
|
}
|
|
62
54
|
export declare function createAnalyticsEngine(options?: AnalyticsEngineOptions): AnalyticsEngine;
|