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.
Files changed (155) hide show
  1. package/README.md +16 -12
  2. package/dist/contracts/build-identity.js +1 -1
  3. package/dist/contracts/card-order.d.ts +2 -0
  4. package/dist/contracts/card-order.js +2 -2
  5. package/dist/contracts/card-visibility.d.ts +2 -1
  6. package/dist/contracts/card-visibility.js +2 -1
  7. package/dist/contracts/dashboard.d.ts +87 -5
  8. package/dist/contracts/dashboard.js +10 -0
  9. package/dist/contracts/dto-guards.d.ts +4 -0
  10. package/dist/contracts/dto-guards.js +29 -7
  11. package/dist/contracts/guards.js +3 -1
  12. package/dist/contracts/identity.d.ts +37 -5
  13. package/dist/contracts/identity.js +43 -0
  14. package/dist/contracts/provider-auto-resume.d.ts +9 -0
  15. package/dist/contracts/provider-auto-resume.js +24 -0
  16. package/dist/contracts/provider-failure.d.ts +22 -0
  17. package/dist/contracts/provider-failure.js +25 -1
  18. package/dist/contracts/row-order.d.ts +13 -0
  19. package/dist/contracts/row-order.js +34 -0
  20. package/dist/contracts/row-visibility.d.ts +53 -0
  21. package/dist/contracts/row-visibility.js +130 -0
  22. package/dist/data/modelsdev-pricing.min.json +1 -1
  23. package/dist/data/modelsdev-temporal.min.json +3 -634
  24. package/dist/gui/aggregation.d.ts +29 -1
  25. package/dist/gui/aggregation.js +157 -4
  26. package/dist/gui/analytics-bridge.d.ts +8 -9
  27. package/dist/gui/analytics-bridge.js +197 -54
  28. package/dist/gui/analytics-engine.d.ts +7 -15
  29. package/dist/gui/analytics-engine.js +246 -106
  30. package/dist/gui/analytics-model.d.ts +7 -0
  31. package/dist/gui/analytics-model.js +75 -9
  32. package/dist/gui/analytics-pricing-upkeep.d.ts +21 -0
  33. package/dist/gui/analytics-pricing-upkeep.js +23 -0
  34. package/dist/gui/analytics-protocol.d.ts +17 -7
  35. package/dist/gui/analytics-protocol.js +1 -0
  36. package/dist/gui/analytics-service.d.ts +10 -0
  37. package/dist/gui/analytics-service.js +30 -9
  38. package/dist/gui/analytics-state.d.ts +30 -5
  39. package/dist/gui/analytics-state.js +46 -7
  40. package/dist/gui/analytics-worker-runtime.d.ts +5 -0
  41. package/dist/gui/analytics-worker-runtime.js +9 -1
  42. package/dist/gui/analytics-worker.js +11 -0
  43. package/dist/gui/config.d.ts +2 -2
  44. package/dist/gui/config.js +46 -5
  45. package/dist/gui/identity.d.ts +6 -20
  46. package/dist/gui/identity.js +6 -54
  47. package/dist/gui/primary-quota-windows.js +55 -34
  48. package/dist/gui/provider-cards.d.ts +12 -8
  49. package/dist/gui/provider-cards.js +12 -53
  50. package/dist/gui/quota-notification-detector.d.ts +25 -2
  51. package/dist/gui/quota-notification-detector.js +60 -5
  52. package/dist/gui/quota-notification-observer.d.ts +1 -1
  53. package/dist/gui/quota-notification-observer.js +5 -1
  54. package/dist/gui/quota-observation.d.ts +4 -0
  55. package/dist/gui/quota-observation.js +18 -0
  56. package/dist/gui/rpc.js +3 -0
  57. package/dist/gui/server.js +6 -1
  58. package/dist/gui/snapshot-service.d.ts +3 -17
  59. package/dist/gui/snapshot-service.js +159 -9
  60. package/dist/gui/sources.js +84 -11
  61. package/dist/gui/temporal-status.d.ts +3 -2
  62. package/dist/gui/temporal-status.js +10 -6
  63. package/dist/gui-experimental.cjs +228 -228
  64. package/dist/lib/accounting-format.d.ts +8 -0
  65. package/dist/lib/accounting-format.js +12 -2
  66. package/dist/lib/anthropic-api-auth.d.ts +7 -0
  67. package/dist/lib/anthropic-api-auth.js +27 -0
  68. package/dist/lib/anthropic-api-rate-limits.d.ts +47 -0
  69. package/dist/lib/anthropic-api-rate-limits.js +92 -0
  70. package/dist/lib/anthropic-oauth-throttle.d.ts +76 -0
  71. package/dist/lib/anthropic-oauth-throttle.js +379 -0
  72. package/dist/lib/anthropic.d.ts +22 -4
  73. package/dist/lib/anthropic.js +498 -180
  74. package/dist/lib/cache-observer-ingestion.js +27 -0
  75. package/dist/lib/cache-observer.d.ts +3 -0
  76. package/dist/lib/cache-observer.js +9 -3
  77. package/dist/lib/cli-show.d.ts +5 -0
  78. package/dist/lib/cli-show.js +16 -5
  79. package/dist/lib/cli-status.js +3 -6
  80. package/dist/lib/config.d.ts +1 -1
  81. package/dist/lib/config.js +64 -2
  82. package/dist/lib/dashboard-visibility.d.ts +5 -0
  83. package/dist/lib/dashboard-visibility.js +11 -10
  84. package/dist/lib/display-sanitize.js +1 -0
  85. package/dist/lib/entries.d.ts +10 -1
  86. package/dist/lib/entries.js +4 -0
  87. package/dist/lib/grouped-entry-normalization.js +1 -1
  88. package/dist/lib/maintainer-announcements.js +2 -2
  89. package/dist/lib/modelsdev-pricing.d.ts +74 -2
  90. package/dist/lib/modelsdev-pricing.js +457 -63
  91. package/dist/lib/modelsdev-temporal.d.ts +6 -0
  92. package/dist/lib/modelsdev-temporal.js +16 -2
  93. package/dist/lib/opencode-config-providers.js +2 -2
  94. package/dist/lib/opencode-storage.d.ts +20 -0
  95. package/dist/lib/opencode-storage.js +89 -2
  96. package/dist/lib/opencode-version-core.d.ts +7 -0
  97. package/dist/lib/opencode-version-core.js +10 -0
  98. package/dist/lib/opencode-warming-refresh.d.ts +19 -0
  99. package/dist/lib/opencode-warming-refresh.js +95 -0
  100. package/dist/lib/provider-metadata.d.ts +11 -3
  101. package/dist/lib/provider-metadata.js +20 -2
  102. package/dist/lib/provider-registration.d.ts +342 -3
  103. package/dist/lib/provider-registration.js +409 -27
  104. package/dist/lib/quota-auto-resume.d.ts +74 -0
  105. package/dist/lib/quota-auto-resume.js +539 -0
  106. package/dist/lib/quota-command-format.js +22 -9
  107. package/dist/lib/quota-identity.d.ts +64 -0
  108. package/dist/lib/quota-identity.js +111 -0
  109. package/dist/lib/quota-providers.js +2 -2
  110. package/dist/lib/quota-render-data.js +2 -2
  111. package/dist/lib/quota-reset-notifications.js +11 -155
  112. package/dist/lib/quota-retry-wait.d.ts +106 -5
  113. package/dist/lib/quota-retry-wait.js +301 -34
  114. package/dist/lib/quota-runtime-context.js +1 -0
  115. package/dist/lib/quota-state-codec.d.ts +2 -0
  116. package/dist/lib/quota-state-codec.js +14 -1
  117. package/dist/lib/quota-state.d.ts +1 -1
  118. package/dist/lib/quota-state.js +60 -28
  119. package/dist/lib/quota-stats.d.ts +26 -0
  120. package/dist/lib/quota-stats.js +19 -1
  121. package/dist/lib/quota-surface-data.js +18 -3
  122. package/dist/lib/quota-telemetry.js +2 -2
  123. package/dist/lib/resolved-auth-identity.d.ts +19 -0
  124. package/dist/lib/resolved-auth-identity.js +44 -0
  125. package/dist/lib/state-file-lock.d.ts +26 -0
  126. package/dist/lib/state-file-lock.js +205 -0
  127. package/dist/lib/toast-format-grouped.js +7 -4
  128. package/dist/lib/tui-compact-format.js +29 -16
  129. package/dist/lib/types.d.ts +20 -0
  130. package/dist/lib/types.js +4 -1
  131. package/dist/plugin.js +67 -1
  132. package/dist/providers/alibaba-coding-plan.js +21 -3
  133. package/dist/providers/alibaba-token-plan.js +9 -5
  134. package/dist/providers/anthropic.d.ts +6 -2
  135. package/dist/providers/anthropic.js +123 -14
  136. package/dist/providers/chutes.js +2 -0
  137. package/dist/providers/claude-agent.js +24 -5
  138. package/dist/providers/copilot.js +5 -4
  139. package/dist/providers/glm-coding-plan-provider.js +30 -23
  140. package/dist/providers/ollama-cloud.js +10 -0
  141. package/dist/providers/openai.js +24 -23
  142. package/dist/providers/opencode-go.js +7 -6
  143. package/dist/providers/opencode-zen.js +1 -1
  144. package/dist/providers/result-helpers.d.ts +4 -2
  145. package/dist/providers/result-helpers.js +5 -1
  146. package/dist/providers/synthetic.js +4 -0
  147. package/dist/providers/xai.js +9 -8
  148. package/dist/rpc.d.ts +8 -0
  149. package/dist/rpc.js +15 -2
  150. package/dist/ui/assets/{index-BcueIm3Z.css → index-6_g1FHs-.css} +1 -1
  151. package/dist/ui/assets/index-sZnGUuML.js +10 -0
  152. package/dist/ui/assets/{popover-4bFSvRZ7.js → popover-C4ZLYe9E.js} +1 -1
  153. package/dist/ui/index.html +2 -2
  154. package/package.json +3 -3
  155. package/dist/ui/assets/index-C6qRSoh8.js +0 -10
@@ -1,13 +1,16 @@
1
+ import { OPENAI_RESETS_ROW_KEY, OPENAI_RESETS_ROW_RESULT_TYPE } from "../contracts/openai-quota.js";
2
+ import { isTransientProviderFailureCategory } from "../contracts/provider-failure.js";
1
3
  import { createLoadConfigMeta, loadConfig } from "../lib/config.js";
2
4
  import { rawAssistantRowHasTokenUsage } from "../lib/opencode-storage.js";
3
5
  import { collectQuotaDashboardProviderResults, } from "../lib/quota-render-data.js";
4
6
  import { withoutClaudeAgentSavedResets } from "../lib/quota-state.js";
5
7
  import { getProviders } from "../providers/registry.js";
6
- import { AnalyticsNotFoundError, createUsageAnalytics, } from "./aggregation.js";
8
+ import { AnalyticsNotFoundError, createUsageAnalytics, messagePositionMs, } from "./aggregation.js";
7
9
  import { createAnalyticsModel } from "./analytics-model.js";
8
10
  import { createAnalyticsReadService } from "./analytics-service.js";
9
11
  import { buildCardId, hashQuotaCardIdentity } from "./identity.js";
10
- import { buildProviderCards, cardSourceKey, openAiOptionalVisibilityRows, UNSCOPED, } from "./provider-cards.js";
12
+ import { buildProviderCards, cardSourceKey, optionalValueRowId, UNSCOPED, } from "./provider-cards.js";
13
+ import { markQuotaObservationLive } from "./quota-observation.js";
11
14
  import { TEMPORAL_QUOTA_POLICIES } from "./temporal-quota-policy-data.js";
12
15
  import { buildTemporalStatus, listTemporalProviderSources, readBundledTemporalCatalog, } from "./temporal-status.js";
13
16
  import { resolveHostTimeZone } from "./time-zone.js";
@@ -34,10 +37,17 @@ function translateAnalyticsError(error) {
34
37
  /**
35
38
  * The production default. Creating the service starts no worker and performs
36
39
  * no read; the worker is built lazily by the service on the first analytics
37
- * request (analytics-api contract).
40
+ * request (analytics-api contract). The worker receives the owner's pricing
41
+ * snapshot policy; a config read failure keeps safe defaults.
38
42
  */
39
- function createDefaultAnalyticsService() {
40
- return createAnalyticsReadService();
43
+ async function createDefaultAnalyticsService(loadConfigForService) {
44
+ try {
45
+ const config = await loadConfigForService();
46
+ return createAnalyticsReadService({ pricingSnapshot: config.pricingSnapshot });
47
+ }
48
+ catch {
49
+ return createAnalyticsReadService();
50
+ }
41
51
  }
42
52
  /**
43
53
  * A readable Console login whose workspace has no Go entitlement is a valid
@@ -72,8 +82,8 @@ export function createOpenAiResetDetailsVisibility(config) {
72
82
  const cardId = buildCardId("openai", sourceId);
73
83
  if (hiddenCards.has(cardId))
74
84
  return false;
75
- const [resetsRow] = openAiOptionalVisibilityRows(cardId);
76
- return resetsRow !== undefined && !hiddenRows.has(resetsRow.rowId);
85
+ const resetsRowId = optionalValueRowId(cardId, OPENAI_RESETS_ROW_KEY, OPENAI_RESETS_ROW_RESULT_TYPE);
86
+ return !hiddenRows.has(resetsRowId);
77
87
  };
78
88
  }
79
89
  /**
@@ -113,6 +123,7 @@ function cardPreferences(config) {
113
123
  accountingDetail: config.accountingDetail,
114
124
  providerOrder: config.dashboard.providerOrder,
115
125
  cardOrder: config.dashboard.cardOrder,
126
+ rowOrder: config.dashboard.rowOrder,
116
127
  };
117
128
  if (config.resetTimeDecimals !== undefined) {
118
129
  preferences.resetTimeDecimals = config.resetTimeDecimals;
@@ -163,6 +174,9 @@ export function createDashboardReadSource(options) {
163
174
  const usageDataset = (dataset) => ({
164
175
  ...dataset,
165
176
  messages: dataset.messages.filter(rawAssistantRowHasTokenUsage),
177
+ excluded: dataset.messages
178
+ .filter((row) => !rawAssistantRowHasTokenUsage(row))
179
+ .map((row) => ({ sessionId: row.sessionID, atMs: messagePositionMs(row) })),
166
180
  });
167
181
  return {
168
182
  async home({ range }) {
@@ -225,7 +239,7 @@ export function createDashboardReadSource(options) {
225
239
  created = Promise.resolve(createLegacyAnalyticsService());
226
240
  }
227
241
  else {
228
- created = Promise.resolve(createDefaultAnalyticsService());
242
+ created = createDefaultAnalyticsService(loadDashboardConfig);
229
243
  }
230
244
  }
231
245
  catch (error) {
@@ -314,12 +328,45 @@ export function createDashboardReadSource(options) {
314
328
  const rateLimited = new Set(errors
315
329
  .filter((error) => error.retryAtMs !== undefined)
316
330
  .map((error) => cardSourceKey(error.sourceId, accountIds)));
317
- const freshKeys = [...entries.keys()].filter((key) => !rateLimited.has(key));
331
+ // A transient failure key that still carries entries is treated as a quota-state last-good
332
+ // snapshot: those rows were measured before the failure, so they are retained and marked
333
+ // stale, never fresh. Other errors can accompany genuinely fresh entries and do not imply
334
+ // retention.
335
+ const keyHasLastGood = (key) => (store?.bySource.get(key)?.length ?? 0) > 0;
336
+ const explicitTransientKeys = new Set(errors
337
+ .filter((error) => isTransientProviderFailureCategory(error.failureCategory) ||
338
+ error.attemptOutcome === "transient" ||
339
+ error.attemptOutcome === "cooldown")
340
+ .map((error) => cardSourceKey(error.sourceId, accountIds)));
341
+ // A provider that previously produced rows for this key keeps them when a later attempt
342
+ // fails in an unclassified way: an unknown category is treated as transient instead of
343
+ // purging a valid measurement, and is normalized so the card mutes it. If this probe also
344
+ // carries entries for the key, those are the measurement; the error stays visible. Credential
345
+ // rejections still prove the account changed and never retain.
346
+ const unknownRetainedKeys = new Set(errors
347
+ .filter((error) => {
348
+ const key = cardSourceKey(error.sourceId, accountIds);
349
+ if (entries.has(key) || rateLimited.has(key) || explicitTransientKeys.has(key))
350
+ return false;
351
+ if (error.failureCategory === "credentials" || error.attemptOutcome === "credentials")
352
+ return false;
353
+ return keyHasLastGood(key);
354
+ })
355
+ .map((error) => cardSourceKey(error.sourceId, accountIds)));
356
+ const transientKeys = new Set([...explicitTransientKeys, ...unknownRetainedKeys]);
357
+ const retainedEntryKeys = [...entries.keys()].filter((key) => transientKeys.has(key) && !rateLimited.has(key));
358
+ const freshKeys = [...entries.keys()].filter((key) => !rateLimited.has(key) && !transientKeys.has(key));
318
359
  anyFresh ||= freshKeys.length > 0;
319
360
  const next = new Map();
320
361
  const retained = new Set();
321
362
  for (const key of freshKeys)
322
363
  next.set(key, entries.get(key));
364
+ for (const key of retainedEntryKeys) {
365
+ const safe = withoutClaudeAgentSavedResets(entries.get(key));
366
+ entries.set(key, safe);
367
+ next.set(key, safe);
368
+ retained.add(key);
369
+ }
323
370
  for (const key of rateLimited)
324
371
  if (entries.has(key)) {
325
372
  retained.add(key);
@@ -328,6 +375,13 @@ export function createDashboardReadSource(options) {
328
375
  if (old.length > 0)
329
376
  next.set(key, old);
330
377
  }
378
+ // A failure that is neither transient nor rate-limited (a credential rejection) proves the
379
+ // account may have changed. It must not reattach the old measurement, and the stored copy is
380
+ // purged so a later empty result cannot bring it back.
381
+ for (const key of failed) {
382
+ if (!transientKeys.has(key) && !rateLimited.has(key))
383
+ store?.bySource.delete(key);
384
+ }
331
385
  for (const [key, old] of store?.bySource ?? []) {
332
386
  if (entries.has(key) || (freshKeys.length > 0 && !failed.has(key)))
333
387
  continue;
@@ -343,9 +397,28 @@ export function createDashboardReadSource(options) {
343
397
  if (probe.cacheScope)
344
398
  lastGoodProbes.set(probe.providerId, { cacheScope: probe.cacheScope, bySource: next });
345
399
  anyRetained ||= retained.size > 0;
400
+ const normalizedErrors = errors.map((error) => {
401
+ const key = cardSourceKey(error.sourceId, accountIds);
402
+ const normalized = unknownRetainedKeys.has(key)
403
+ ? { ...error, failureCategory: "provider_api" }
404
+ : error;
405
+ // A retained non-credential failure is a last-good measurement with a
406
+ // recoverable error. Mark an unspecified outcome so the card mutes it
407
+ // instead of leaving a red provider error over valid retained rows.
408
+ if (retained.has(key) &&
409
+ normalized.failureCategory !== "credentials" &&
410
+ normalized.attemptOutcome === undefined) {
411
+ return { ...normalized, attemptOutcome: "transient" };
412
+ }
413
+ return normalized;
414
+ });
346
415
  merged.push({
347
416
  ...probe,
348
- result: { ...probe.result, entries: [...entries.values()].flat() },
417
+ result: {
418
+ ...probe.result,
419
+ errors: normalizedErrors,
420
+ entries: [...entries.values()].flat(),
421
+ },
349
422
  retainedSourceIds: new Set([...retained].filter((key) => key !== UNSCOPED)),
350
423
  retainedUnscoped: retained.has(UNSCOPED),
351
424
  });
@@ -391,7 +464,7 @@ export function createDashboardReadSource(options) {
391
464
  if (temporal)
392
465
  snapshot.temporal = temporal;
393
466
  lastQuotaSnapshot = snapshot;
394
- return snapshot;
467
+ return markQuotaObservationLive(snapshot);
395
468
  }
396
469
  catch (error) {
397
470
  if (lastQuotaSnapshot) {
@@ -31,8 +31,9 @@ export interface BuildTemporalStatusInput {
31
31
  /** Holiday calendars referenced by the bundled snapshot. */
32
32
  holidays?: readonly TemporalHolidayInterval[];
33
33
  /**
34
- * Test/embedding seam only. Production reads the active pricing snapshot so
35
- * an override can be compared with the same base it replaces.
34
+ * Fallback base-rate lookup for policies without a captured source base
35
+ * (multiplier-only policies and test/embedding seams). Production prefers
36
+ * the base bundled with an absolute-override policy.
36
37
  */
37
38
  baseRates?: (providerId: string, modelId: string) => TemporalRates | null;
38
39
  /** Provider-maintained quota policies; defaults to the bundled data module. */
@@ -723,7 +723,13 @@ export function buildTemporalStatus(input) {
723
723
  const policy = getTemporalPolicy(provider.providerId, modelId);
724
724
  if (!policy)
725
725
  continue;
726
- models.push(modelStatus(provider.providerId, modelId, input.nowMs, resolveBase));
726
+ // Absolute overrides are meaningful only against their source's own base.
727
+ // The pricing snapshot's api.json cost can be a derived/current price, so
728
+ // prefer the base captured with the temporal policy when present.
729
+ const base = policy.status === "supported"
730
+ ? (policy.base ?? resolveBase(provider.providerId, modelId))
731
+ : null;
732
+ models.push(modelStatus(provider.providerId, modelId, input.nowMs, base));
727
733
  for (const jurisdiction of holidayJurisdictions(policy))
728
734
  jurisdictions.add(jurisdiction);
729
735
  }
@@ -750,12 +756,11 @@ export function buildTemporalStatus(input) {
750
756
  },
751
757
  };
752
758
  }
753
- function modelStatus(providerId, modelId, nowMs, baseRates) {
759
+ function modelStatus(providerId, modelId, nowMs, base) {
754
760
  const policy = getTemporalPolicy(providerId, modelId);
755
- const base = baseRates(providerId, modelId);
756
761
  const state = getTemporalInstantState(providerId, modelId, nowMs);
757
762
  const current = classifyInstant(policy, state, base);
758
- const intervals = projectIntervals(providerId, modelId, nowMs, baseRates);
763
+ const intervals = projectIntervals(providerId, modelId, nowMs, base);
759
764
  const weekly = policyWeeklySchedule(policy, base);
760
765
  // The preview is deliberately short, so its last interval ends at the horizon
761
766
  // rather than at a proved transition. Ask the core evaluator for the real
@@ -779,11 +784,10 @@ function modelStatus(providerId, modelId, nowMs, baseRates) {
779
784
  status.reason = state.reason;
780
785
  return status;
781
786
  }
782
- function projectIntervals(providerId, modelId, nowMs, baseRates) {
787
+ function projectIntervals(providerId, modelId, nowMs, base) {
783
788
  const policy = getTemporalPolicy(providerId, modelId);
784
789
  if (!policy || policy.status === "unsupported")
785
790
  return [];
786
- const base = baseRates(providerId, modelId);
787
791
  const rawIntervals = listTemporalIntervals(providerId, modelId, nowMs, nowMs + TEMPORAL_SCHEDULE_HORIZON_MS, base ?? undefined);
788
792
  const projected = [];
789
793
  for (const interval of rawIntervals) {