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
@@ -7,6 +7,11 @@ import { type AnalyticsEngine } from "./analytics-engine.js";
7
7
  import type { AnalyticsInitOptions, AnalyticsWorkerCommand, AnalyticsWorkerResult } from "./analytics-protocol.js";
8
8
  export interface AnalyticsWorkerRuntime {
9
9
  handle(command: AnalyticsWorkerCommand): Promise<AnalyticsWorkerResult>;
10
+ /** Routes the live model could not price, for the worker's pricing upkeep. */
11
+ unpricedRoutes(): Array<{
12
+ providerID?: string;
13
+ modelID?: string;
14
+ }>;
10
15
  close(): Promise<void>;
11
16
  }
12
17
  export declare function createAnalyticsWorkerRuntime(options?: {
@@ -5,6 +5,7 @@
5
5
  */
6
6
  import { isAnalyticsGroupQuery } from "../contracts/analytics-entity.js";
7
7
  import { isRangeKey } from "../contracts/ranges.js";
8
+ import { setPricingSnapshotAutoRefresh, setPricingSnapshotSelection, } from "../lib/modelsdev-pricing.js";
8
9
  import { createAnalyticsEngine } from "./analytics-engine.js";
9
10
  import { AnalyticsReadError } from "./analytics-protocol.js";
10
11
  const ERROR_CODES = new Set([
@@ -38,6 +39,10 @@ export function createAnalyticsWorkerRuntime(options = {}) {
38
39
  let closed = false;
39
40
  async function handle(command) {
40
41
  if (command.kind === "init") {
42
+ if (command.options.pricingSnapshot) {
43
+ setPricingSnapshotAutoRefresh(command.options.pricingSnapshot.autoRefresh);
44
+ setPricingSnapshotSelection(command.options.pricingSnapshot.source);
45
+ }
41
46
  if (!engine)
42
47
  engine = createEngine(command.options);
43
48
  return undefined;
@@ -54,7 +59,7 @@ export function createAnalyticsWorkerRuntime(options = {}) {
54
59
  if (command.kind === "home") {
55
60
  if (!isRangeKey(command.range))
56
61
  throw new AnalyticsReadError("bad-request");
57
- return await engine.home(command.range);
62
+ return await engine.home(command.range, command.exact);
58
63
  }
59
64
  if (command.kind === "project") {
60
65
  if (!isRangeKey(command.range) || !command.projectId) {
@@ -93,6 +98,9 @@ export function createAnalyticsWorkerRuntime(options = {}) {
93
98
  throw new AnalyticsReadError(errorCodeOf(error));
94
99
  }
95
100
  },
101
+ unpricedRoutes() {
102
+ return engine?.unpricedRoutes() ?? [];
103
+ },
96
104
  async close() {
97
105
  closed = true;
98
106
  if (engine)
@@ -5,6 +5,7 @@
5
5
  * It owns all storage reads, the compact index, persistence, and aggregation;
6
6
  * only protocol frames and finished DTOs cross back to the host.
7
7
  */
8
+ import { createAnalyticsPricingUpkeep } from "./analytics-pricing-upkeep.js";
8
9
  import { AnalyticsReadError } from "./analytics-protocol.js";
9
10
  import { createAnalyticsWorkerRuntime } from "./analytics-worker-runtime.js";
10
11
  function isRequest(value) {
@@ -37,10 +38,20 @@ async function main() {
37
38
  port.postMessage({ type: "analytics-generation", generation });
38
39
  },
39
40
  });
41
+ const pricingUpkeep = createAnalyticsPricingUpkeep({
42
+ postMessage: (message) => port.postMessage(message),
43
+ routes: () => runtime.unpricedRoutes(),
44
+ });
40
45
  const respond = (request) => {
41
46
  void (async () => {
42
47
  try {
43
48
  const result = await runtime.handle(request.command);
49
+ const upkeep = request.command.kind !== "init" && request.command.kind !== "close"
50
+ ? pricingUpkeep
51
+ : null;
52
+ // Advertise upkeep before the reply frame: the refresh itself starts
53
+ // after it, so a slow models.dev response never delays the read path.
54
+ upkeep?.begin();
44
55
  port.postMessage({ id: request.id, ok: true, result });
45
56
  }
46
57
  catch (error) {
@@ -13,14 +13,14 @@ import type { GuiSettingsStore } from "../contracts/dashboard.js";
13
13
  import type { OpenCodeVersion } from "../lib/opencode-version-core.js";
14
14
  import { type SettingsFileOpener } from "./settings-file-opener.js";
15
15
  /** Writable GUI settings keys (spec §5.4 table order plus the web switch; port excluded). */
16
- export declare const GUI_SETTINGS_WRITABLE_KEYS: readonly ["formatStyle", "percentDisplayMode", "percentLabelStyle", "quotaProjection", "resetTimeDecimals", "resetTimeSpaced", "waitForQuotaReset", "enabledProviders", "minIntervalMs", "requestTimeoutMs", "accountingDetail", "lowQuotaThresholdRemainingPercent", "duplicateCooldownMinutes", "nativeQuotaNotifications", "opencodeGoWindows", "opencodeMonthlyLimit", "dashboard.hiddenCards", "dashboard.hiddenRows", "dashboard.providerOrder", "dashboard.cardOrder", "dashboard.temporalProviderOverrides", "dashboard.enabled"];
16
+ export declare const GUI_SETTINGS_WRITABLE_KEYS: readonly ["formatStyle", "percentDisplayMode", "percentLabelStyle", "quotaProjection", "resetTimeDecimals", "resetTimeSpaced", "waitForQuotaReset", "autoResumeOnQuotaRecovery", "enabledProviders", "minIntervalMs", "claudeAgentPollIntervalMs", "requestTimeoutMs", "accountingDetail", "lowQuotaThresholdRemainingPercent", "duplicateCooldownMinutes", "nativeQuotaNotifications", "opencodeGoWindows", "opencodeMonthlyLimit", "dashboard.hiddenCards", "dashboard.hiddenRows", "dashboard.providerOrder", "dashboard.cardOrder", "dashboard.rowOrder", "dashboard.temporalProviderOverrides", "dashboard.enabled"];
17
17
  /**
18
18
  * Read-only GUI settings keys: the port needs a restart, and the hidden-card
19
19
  * semantics marker is server-managed after an automatic write stamp.
20
20
  */
21
21
  export declare const GUI_SETTINGS_READ_ONLY_KEYS: readonly ["dashboard.port", "dashboard.hiddenCardsVersion"];
22
22
  /** Every GUI-exposed settings key (spec §5.4), in table order. */
23
- export declare const GUI_SETTINGS_KEYS: readonly ["formatStyle", "percentDisplayMode", "percentLabelStyle", "quotaProjection", "resetTimeDecimals", "resetTimeSpaced", "waitForQuotaReset", "enabledProviders", "minIntervalMs", "requestTimeoutMs", "accountingDetail", "lowQuotaThresholdRemainingPercent", "duplicateCooldownMinutes", "nativeQuotaNotifications", "opencodeGoWindows", "opencodeMonthlyLimit", "dashboard.hiddenCards", "dashboard.hiddenRows", "dashboard.providerOrder", "dashboard.cardOrder", "dashboard.temporalProviderOverrides", "dashboard.enabled", "dashboard.port", "dashboard.hiddenCardsVersion"];
23
+ export declare const GUI_SETTINGS_KEYS: readonly ["formatStyle", "percentDisplayMode", "percentLabelStyle", "quotaProjection", "resetTimeDecimals", "resetTimeSpaced", "waitForQuotaReset", "autoResumeOnQuotaRecovery", "enabledProviders", "minIntervalMs", "claudeAgentPollIntervalMs", "requestTimeoutMs", "accountingDetail", "lowQuotaThresholdRemainingPercent", "duplicateCooldownMinutes", "nativeQuotaNotifications", "opencodeGoWindows", "opencodeMonthlyLimit", "dashboard.hiddenCards", "dashboard.hiddenRows", "dashboard.providerOrder", "dashboard.cardOrder", "dashboard.rowOrder", "dashboard.temporalProviderOverrides", "dashboard.enabled", "dashboard.port", "dashboard.hiddenCardsVersion"];
24
24
  export type GuiSettingsKey = (typeof GUI_SETTINGS_KEYS)[number];
25
25
  export type GuiSettingsErrorCode = "config-read-error" | "config-changed" | "config-target-error" | "config-write-error" | "unknown-setting" | "invalid-setting";
26
26
  export interface GuiSettingsErrorDetails {
@@ -13,7 +13,9 @@ import { createHash } from "node:crypto";
13
13
  import { existsSync } from "node:fs";
14
14
  import { readFile } from "node:fs/promises";
15
15
  import { resolve } from "node:path";
16
+ import { isRecord, isText } from "../contracts/dto-guards.js";
16
17
  import { LEGACY_IMPORT_KEYS } from "../contracts/settings.js";
18
+ import { ANTHROPIC_OAUTH_MIN_POLL_INTERVAL_MS } from "../lib/anthropic-oauth-throttle.js";
17
19
  import { withCanonicalConfigLock } from "../lib/canonical-config-lock.js";
18
20
  import { buildConfigLayerCandidates, createLoadConfigMeta, GUI_CONFIG_RELATIVE_PATH, GUI_CONFIG_SIBLING_JSON_RELATIVE_PATH, getGuiConfigPath, getGuiConfigSiblingJsonPath, isPositiveNumber, isValidDuplicateCooldownMinutes, isValidLowQuotaThresholdRemainingPercent, isValidNativeQuotaNotificationPolicy, isValidOpenCodeGoWindows, loadConfig, loadConfigLayered, normalizeEnabledProviders, } from "../lib/config.js";
19
21
  import { ConfigWriteTargetError, } from "../lib/config-write-target.js";
@@ -34,8 +36,10 @@ export const GUI_SETTINGS_WRITABLE_KEYS = [
34
36
  "resetTimeDecimals",
35
37
  "resetTimeSpaced",
36
38
  "waitForQuotaReset",
39
+ "autoResumeOnQuotaRecovery",
37
40
  "enabledProviders",
38
41
  "minIntervalMs",
42
+ "claudeAgentPollIntervalMs",
39
43
  "requestTimeoutMs",
40
44
  "accountingDetail",
41
45
  "lowQuotaThresholdRemainingPercent",
@@ -47,6 +51,7 @@ export const GUI_SETTINGS_WRITABLE_KEYS = [
47
51
  "dashboard.hiddenRows",
48
52
  "dashboard.providerOrder",
49
53
  "dashboard.cardOrder",
54
+ "dashboard.rowOrder",
50
55
  "dashboard.temporalProviderOverrides",
51
56
  "dashboard.enabled",
52
57
  ];
@@ -112,9 +117,6 @@ export function getGuiDashboardEnabled(config) {
112
117
  export function resolveGuiDashboardUrl(port) {
113
118
  return `http://127.0.0.1:${getGuiDashboardPort({ dashboard: { port } })}`;
114
119
  }
115
- function isPlainObject(value) {
116
- return Boolean(value) && typeof value === "object" && !Array.isArray(value);
117
- }
118
120
  /** Strict finite-number check: `Number.isFinite` coerces nothing, so it implies a number primitive. */
119
121
  function isFiniteNumber(value) {
120
122
  return Number.isFinite(value);
@@ -211,12 +213,16 @@ export function createGuiSettingsStore(options) {
211
213
  return config.resetTimeSpaced ?? null;
212
214
  case "waitForQuotaReset":
213
215
  return config.waitForQuotaReset;
216
+ case "autoResumeOnQuotaRecovery":
217
+ return config.autoResumeOnQuotaRecovery;
214
218
  case "enabledProviders":
215
219
  return Array.isArray(config.enabledProviders)
216
220
  ? [...config.enabledProviders]
217
221
  : config.enabledProviders;
218
222
  case "minIntervalMs":
219
223
  return config.minIntervalMs;
224
+ case "claudeAgentPollIntervalMs":
225
+ return config.claudeAgentPollIntervalMs;
220
226
  case "requestTimeoutMs":
221
227
  return config.requestTimeoutMs;
222
228
  case "accountingDetail":
@@ -252,6 +258,8 @@ export function createGuiSettingsStore(options) {
252
258
  return [...config.dashboard.providerOrder];
253
259
  case "dashboard.cardOrder":
254
260
  return [...config.dashboard.cardOrder];
261
+ case "dashboard.rowOrder":
262
+ return Object.fromEntries(Object.entries(config.dashboard.rowOrder).map(([cardId, ids]) => [cardId, [...ids]]));
255
263
  case "dashboard.temporalProviderOverrides":
256
264
  return { ...config.dashboard.temporalProviderOverrides };
257
265
  case "dashboard.enabled":
@@ -392,6 +400,7 @@ export function createGuiSettingsStore(options) {
392
400
  return value;
393
401
  case "resetTimeSpaced":
394
402
  case "waitForQuotaReset":
403
+ case "autoResumeOnQuotaRecovery":
395
404
  if (value !== true && value !== false) {
396
405
  throw invalidSetting(key, "expected boolean");
397
406
  }
@@ -418,6 +427,11 @@ export function createGuiSettingsStore(options) {
418
427
  throw invalidSetting(key, "expected a finite number greater than 0");
419
428
  }
420
429
  return value;
430
+ case "claudeAgentPollIntervalMs":
431
+ if (!isPositiveNumber(value) || value < ANTHROPIC_OAUTH_MIN_POLL_INTERVAL_MS) {
432
+ throw invalidSetting(key, `expected a finite number of at least ${ANTHROPIC_OAUTH_MIN_POLL_INTERVAL_MS}`);
433
+ }
434
+ return value;
421
435
  case "accountingDetail":
422
436
  if (value !== "summary" && value !== "detailed") {
423
437
  throw invalidSetting(key, 'expected "summary" or "detailed"');
@@ -476,7 +490,7 @@ export function createGuiSettingsStore(options) {
476
490
  return [...new Set(ids)];
477
491
  }
478
492
  case "dashboard.temporalProviderOverrides": {
479
- if (!isPlainObject(value)) {
493
+ if (!isRecord(value)) {
480
494
  throw invalidSetting(key, "expected an object of provider ids mapped to booleans");
481
495
  }
482
496
  const entries = Object.entries(value);
@@ -490,6 +504,33 @@ export function createGuiSettingsStore(options) {
490
504
  }
491
505
  return Object.fromEntries(entries);
492
506
  }
507
+ case "dashboard.rowOrder": {
508
+ if (!isRecord(value)) {
509
+ throw invalidSetting(key, "expected an object of card ids mapped to row-id lists");
510
+ }
511
+ const entries = Object.entries(value);
512
+ if (entries.length > DASHBOARD_HIDDEN_ID_LIMIT) {
513
+ throw invalidSetting(key, `expected at most ${DASHBOARD_HIDDEN_ID_LIMIT} cards`);
514
+ }
515
+ const rowOrder = [];
516
+ for (const [cardId, ids] of entries) {
517
+ if (cardId.length === 0 || cardId.length > 512 || !Array.isArray(ids)) {
518
+ throw invalidSetting(key, "expected an object of card ids mapped to row-id lists");
519
+ }
520
+ const normalized = [];
521
+ for (const id of ids) {
522
+ if (!isText(id) || id.length === 0 || id.length > 512) {
523
+ throw invalidSetting(key, "expected an object of card ids mapped to row-id lists");
524
+ }
525
+ normalized.push(id);
526
+ }
527
+ if (normalized.length > DASHBOARD_HIDDEN_ID_LIMIT) {
528
+ throw invalidSetting(key, `expected at most ${DASHBOARD_HIDDEN_ID_LIMIT} row ids per card`);
529
+ }
530
+ rowOrder.push([cardId, [...new Set(normalized)]]);
531
+ }
532
+ return Object.fromEntries(rowOrder);
533
+ }
493
534
  case "dashboard.port":
494
535
  throw invalidSetting(key, "this setting is read-only; edit the canonical file and restart");
495
536
  case "dashboard.enabled":
@@ -542,7 +583,7 @@ export function createGuiSettingsStore(options) {
542
583
  let node = target;
543
584
  for (const part of parts.slice(0, -1)) {
544
585
  const child = node[part];
545
- if (isPlainObject(child)) {
586
+ if (isRecord(child)) {
546
587
  node = child;
547
588
  }
548
589
  else {
@@ -1,23 +1,9 @@
1
- import type { CardId, RowId, RowKey } from "../contracts/identity.js";
2
- import type { QuotaToastEntry } from "../lib/entries.js";
3
1
  /**
4
- * Reserved identity key for the provider-scope card (entries/errors that no
5
- * discovered account owns). It is a scope marker, never an account id.
2
+ * Compatibility re-export. The shared identity helpers live in
3
+ * `src/contracts/identity.ts` (pure) and `src/contracts/quota-identity.ts`
4
+ * (server-side hash + visibility) so the lib and GUI layers share one
5
+ * implementation without importing each other.
6
6
  */
7
- export declare const PROVIDER_SCOPE_IDENTITY_KEY = "provider";
8
- /** Deterministic sha256 hex of the domain-separated (providerId, identityKey) pair. */
9
- export declare function hashQuotaCardIdentity(providerId: string, identityKey: string): string;
10
- /** Opaque card id: provider namespace + server-side hash; raw identities never appear. */
11
- export declare function buildCardId(providerId: string, identityKey: string): CardId;
12
- /** The provider-scope card id (unscoped rows/errors, or no discovered accounts). */
13
- export declare function buildProviderScopeCardId(providerId: string): CardId;
14
- /**
15
- * Stable typed row key: the entry's semantic metric (window/component/named) or
16
- * its provider-supplied `rowKey`, plus the `resultType:kind` discriminator so
17
- * rows that share a metric but mean different things stay distinct. Never a
18
- * display label or an ordinal, so a rename cannot change a row id.
19
- */
20
- export declare function rowKeyForEntry(entry: QuotaToastEntry): RowKey;
21
- /** `rowId = cardId + "#" + rowKey` (R20). */
22
- export declare function rowIdForEntry(cardId: CardId, entry: QuotaToastEntry): RowId;
7
+ export { rowIdForEntry, rowKeyForEntry } from "../contracts/identity.js";
8
+ export { buildCardId, buildProviderScopeCardId, hashQuotaCardIdentity, PROVIDER_SCOPE_IDENTITY_KEY, } from "../lib/quota-identity.js";
23
9
  //# sourceMappingURL=identity.d.ts.map
@@ -1,57 +1,9 @@
1
1
  /**
2
- * Server-side card/row identity (design spec §8 R20, plan P3 step 1).
3
- *
4
- * The only place raw account identities are hashed: `CardId` is
5
- * `<providerId>:<sha256>` and `RowId` is `cardId + "#" + rowKey`. Raw source
6
- * ids, identity keys, and `rai1_` values are hash inputs and never outputs;
7
- * nothing here is imported by the browser (`src/contracts/identity.ts` holds
8
- * the opaque types only).
2
+ * Compatibility re-export. The shared identity helpers live in
3
+ * `src/contracts/identity.ts` (pure) and `src/contracts/quota-identity.ts`
4
+ * (server-side hash + visibility) so the lib and GUI layers share one
5
+ * implementation without importing each other.
9
6
  */
10
- import { createHash } from "node:crypto";
11
- import { buildRowKey, composeRowId } from "../contracts/identity.js";
12
- import { isPercentEntry } from "../lib/entries.js";
13
- /**
14
- * Reserved identity key for the provider-scope card (entries/errors that no
15
- * discovered account owns). It is a scope marker, never an account id.
16
- */
17
- export const PROVIDER_SCOPE_IDENTITY_KEY = "provider";
18
- const CARD_HASH_DOMAIN = "ocq-card-v1";
19
- /** Deterministic sha256 hex of the domain-separated (providerId, identityKey) pair. */
20
- export function hashQuotaCardIdentity(providerId, identityKey) {
21
- return createHash("sha256")
22
- .update(`${CARD_HASH_DOMAIN}\0${providerId}\0${identityKey}`, "utf8")
23
- .digest("hex");
24
- }
25
- /** Opaque card id: provider namespace + server-side hash; raw identities never appear. */
26
- export function buildCardId(providerId, identityKey) {
27
- // SAFETY: CardId is the opaque brand of exactly `<providerId>:<sha256>`; this
28
- // builder is its only producer and the hash covers both raw inputs.
29
- return `${providerId}:${hashQuotaCardIdentity(providerId, identityKey)}`;
30
- }
31
- /** The provider-scope card id (unscoped rows/errors, or no discovered accounts). */
32
- export function buildProviderScopeCardId(providerId) {
33
- return buildCardId(providerId, PROVIDER_SCOPE_IDENTITY_KEY);
34
- }
35
- function baseRowKeyOf(entry) {
36
- if (entry.semantic)
37
- return buildRowKey(entry.semantic.metric);
38
- if (entry.rowKey)
39
- return buildRowKey({ kind: "explicit", key: entry.rowKey });
40
- return buildRowKey({ kind: "aggregate" });
41
- }
42
- /**
43
- * Stable typed row key: the entry's semantic metric (window/component/named) or
44
- * its provider-supplied `rowKey`, plus the `resultType:kind` discriminator so
45
- * rows that share a metric but mean different things stay distinct. Never a
46
- * display label or an ordinal, so a rename cannot change a row id.
47
- */
48
- export function rowKeyForEntry(entry) {
49
- const base = baseRowKeyOf(entry);
50
- const kind = isPercentEntry(entry) ? "percent" : entry.kind;
51
- return buildRowKey({ kind: "explicit", key: `${base}|${entry.accounting.resultType}:${kind}` });
52
- }
53
- /** `rowId = cardId + "#" + rowKey` (R20). */
54
- export function rowIdForEntry(cardId, entry) {
55
- return composeRowId(cardId, rowKeyForEntry(entry));
56
- }
7
+ export { rowIdForEntry, rowKeyForEntry } from "../contracts/identity.js";
8
+ export { buildCardId, buildProviderScopeCardId, hashQuotaCardIdentity, PROVIDER_SCOPE_IDENTITY_KEY, } from "../lib/quota-identity.js";
57
9
  //# sourceMappingURL=identity.js.map
@@ -1,11 +1,25 @@
1
1
  import { isPercentEntry } from "../lib/entries.js";
2
2
  const ANTHROPIC_SUBSCRIPTION_WINDOWS = {
3
- rowKeys: [
4
- { value: "window:five_hour", slot: 0 },
5
- { value: "window:week", slot: 1 },
6
- ],
3
+ ...windowRule([
4
+ ["five_hour", 0],
5
+ ["week", 1],
6
+ ]),
7
7
  namedMetrics: [{ value: "Fable weekly", slot: 2 }],
8
8
  };
9
+ /**
10
+ * One typed window list generates both identities: the semantic window the
11
+ * provider emits now and the explicit `rowKey` an entry cached before that
12
+ * migration still carries.
13
+ */
14
+ function windowRule(windows, extraRowKeys = []) {
15
+ return {
16
+ rowKeys: [
17
+ ...windows.map(([value, slot]) => ({ value: `window:${value}`, slot })),
18
+ ...extraRowKeys,
19
+ ],
20
+ windows: windows.map(([value, slot]) => ({ value, slot })),
21
+ };
22
+ }
9
23
  /**
10
24
  * Explicit, evidence-backed mapping. Omitted providers intentionally have no
11
25
  * defensible primary/auxiliary split in their current source (see the Stage 6
@@ -18,40 +32,42 @@ const PRIMARY_QUOTA_WINDOW_RULES = {
18
32
  // Claude Agent emits the same subscription rows from its Claude CLI login.
19
33
  "claude-agent": ANTHROPIC_SUBSCRIPTION_WINDOWS,
20
34
  // 5h/weekly/monthly ChatGPT windows; Code Review is a special secondary
21
- // window (`src/providers/openai.ts` 56-75, 239-261).
35
+ // window. `rowKeys` stays for entries cached before typed window semantics.
22
36
  openai: {
23
- rowKeys: [
24
- { value: "window:five_hour", slot: 0 },
25
- { value: "window:week", slot: 1 },
26
- { value: "window:month", slot: 2 },
27
- ],
37
+ ...windowRule([
38
+ ["five_hour", 0],
39
+ ["week", 1],
40
+ ["month", 2],
41
+ ]),
28
42
  },
29
43
  // GLM five-hour/weekly plan windows; MCP is a tool-specific allowance
30
- // (`src/providers/glm-coding-plan-provider.ts` 40-79).
44
+ // (`src/providers/glm-coding-plan-provider.ts`).
31
45
  zai: {
32
- rowKeys: [
33
- { value: "window:five_hour", slot: 0 },
34
- { value: "window:week", slot: 1 },
35
- ],
46
+ ...windowRule([
47
+ ["five_hour", 0],
48
+ ["week", 1],
49
+ ]),
36
50
  },
37
51
  zhipu: {
38
- rowKeys: [
39
- { value: "window:five_hour", slot: 0 },
40
- { value: "window:week", slot: 1 },
41
- ],
52
+ ...windowRule([
53
+ ["five_hour", 0],
54
+ ["week", 1],
55
+ ]),
42
56
  },
43
- // Rolling/weekly/monthly Go plan windows (`src/providers/opencode-go.ts` 44-55).
57
+ // Rolling/weekly/monthly Go plan windows (`src/providers/opencode-go.ts`).
44
58
  "opencode-go": {
45
- rowKeys: [
46
- { value: "window:five_hour", slot: 0 },
47
- { value: "window:week", slot: 1 },
48
- { value: "window:month", slot: 2 },
49
- ],
59
+ ...windowRule([
60
+ ["five_hour", 0],
61
+ ["week", 1],
62
+ ["month", 2],
63
+ ]),
50
64
  },
51
65
  // The plan entitlement is Copilot's only primary window, so it occupies the
52
66
  // outer slot; the additional-usage row is a budget percent
53
- // (`src/providers/copilot.ts` 109-142, 185-215).
54
- copilot: { rowKeys: [{ value: "window:month", slot: 0 }] },
67
+ // (`src/providers/copilot.ts`).
68
+ copilot: {
69
+ ...windowRule([["month", 0]]),
70
+ },
55
71
  // Daily/monthly subscription limits are the provider's two-window family in
56
72
  // full-card order (`src/providers/nanogpt.ts` 70-105).
57
73
  nanogpt: {
@@ -84,14 +100,19 @@ const PRIMARY_QUOTA_WINDOW_RULES = {
84
100
  kilo: { components: [{ value: "remaining_credits", slot: 0 }] },
85
101
  // xAI always emits exactly one provider-supplied period row, so any valid
86
102
  // period identity occupies the same outer slot even when the response-defined
87
- // period changes (`src/providers/xai.ts` 29-40, 92-153).
103
+ // period changes (`src/providers/xai.ts`).
88
104
  xai: {
89
- rowKeys: [
90
- { value: "window:day", slot: 0 },
91
- { value: "window:week", slot: 0 },
92
- { value: "window:month", slot: 0 },
93
- { value: "named:period", slot: 0 },
94
- ],
105
+ ...windowRule([
106
+ ["day", 0],
107
+ ["week", 0],
108
+ ["month", 0],
109
+ ], [{ value: "named:period", slot: 0 }]),
110
+ namedMetrics: [{ value: "period", slot: 0 }],
111
+ },
112
+ // Zen's monthly budget/quota is the subscription's primary window; spend,
113
+ // balance and auto-reload stay supplementary (`src/providers/opencode-zen.ts`).
114
+ opencode: {
115
+ ...windowRule([["month", 0]]),
95
116
  },
96
117
  // These provider cards compact their quota entries into one aggregate row.
97
118
  // Synthetic returns 5h before weekly; Bailian CLI Coding Plan may return any
@@ -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). */
@@ -29,6 +30,13 @@ export interface ProviderCardPreferences {
29
30
  * independent. Affects presentation only.
30
31
  */
31
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[]>>;
32
40
  }
33
41
  export declare const UNSCOPED: unique symbol;
34
42
  export type SourceKey = string | typeof UNSCOPED;
@@ -44,13 +52,9 @@ export interface BuildProviderCardsInput {
44
52
  /** Provider display label resolver; defaults to the registration table. */
45
53
  providerLabel?: (providerId: string) => string;
46
54
  }
47
- /**
48
- * Persistent Resets/Credits choices for an OpenAI card. These are metadata for
49
- * the Settings eyes only; they never create a zero/empty Quota data row.
50
- */
51
- export declare function openAiOptionalVisibilityRows(cardId: CardId): NonNullable<ProviderCard["visibilityRows"]>;
52
- /** Persistent Resets choice for a Claude Agent card (no Credits row). */
53
- export declare function claudeAgentOptionalVisibilityRows(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 };
54
58
  /**
55
59
  * One card per discovered account (zero-entry and failed ones included) plus a
56
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 { CLAUDE_AGENT_RESETS_INFO, CLAUDE_AGENT_RESETS_ROW_KEY, OPENAI_CREDITS_INFO, OPENAI_CREDITS_ROW_KEY, OPENAI_CREDITS_ROW_LABEL, OPENAI_CREDITS_ROW_RESULT_TYPE, OPENAI_RESETS_INFO, OPENAI_RESETS_ROW_KEY, OPENAI_RESETS_ROW_LABEL, OPENAI_RESETS_ROW_RESULT_TYPE, } from "../contracts/openai-quota.js";
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,7 +19,7 @@ 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, rowIdForEntry, } from "./identity.js";
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.";
@@ -83,6 +83,8 @@ function mapProviderError(error, secrets) {
83
83
  mapped.retryable = true;
84
84
  if (error.retryAtMs !== undefined)
85
85
  mapped.retryAtMs = error.retryAtMs;
86
+ if (error.attemptOutcome !== undefined)
87
+ mapped.attemptOutcome = error.attemptOutcome;
86
88
  if (error.kind !== undefined)
87
89
  mapped.kind = error.kind;
88
90
  if (error.failureCategory !== undefined)
@@ -219,60 +221,18 @@ function mapEntryRows(params) {
219
221
  windowsBySlot.set(slot, { rowId: row.rowId, slot });
220
222
  }
221
223
  }
224
+ const visibilityRows = optionalVisibilityRowsFor(params.providerId, params.cardId, rows);
222
225
  return {
223
226
  rows,
224
227
  primaryQuotaWindows: [...windowsBySlot.values()].sort((left, right) => left.slot - right.slot),
228
+ visibilityRows,
225
229
  };
226
230
  }
227
- const OPENAI_OPTIONAL_ROW_ACCOUNTING = {
228
- acquisitionMethod: "remote_api",
229
- ownership: "maintained",
230
- authority: "provider_reported",
231
- };
232
- function optionalValueRowId(cardId, rowKey, resultType) {
233
- return rowIdForEntry(cardId, {
234
- kind: "value",
235
- name: "",
236
- value: "",
237
- rowKey,
238
- accounting: { ...OPENAI_OPTIONAL_ROW_ACCOUNTING, resultType },
239
- });
240
- }
241
- /**
242
- * Persistent Resets/Credits choices for an OpenAI card. These are metadata for
243
- * the Settings eyes only; they never create a zero/empty Quota data row.
244
- */
245
- export function openAiOptionalVisibilityRows(cardId) {
246
- return [
247
- {
248
- rowId: optionalValueRowId(cardId, OPENAI_RESETS_ROW_KEY, OPENAI_RESETS_ROW_RESULT_TYPE),
249
- label: OPENAI_RESETS_ROW_LABEL,
250
- info: OPENAI_RESETS_INFO,
251
- },
252
- {
253
- rowId: optionalValueRowId(cardId, OPENAI_CREDITS_ROW_KEY, OPENAI_CREDITS_ROW_RESULT_TYPE),
254
- label: OPENAI_CREDITS_ROW_LABEL,
255
- info: OPENAI_CREDITS_INFO,
256
- },
257
- ];
258
- }
259
- /** Persistent Resets choice for a Claude Agent card (no Credits row). */
260
- export function claudeAgentOptionalVisibilityRows(cardId) {
261
- return [
262
- {
263
- rowId: optionalValueRowId(cardId, CLAUDE_AGENT_RESETS_ROW_KEY, OPENAI_RESETS_ROW_RESULT_TYPE),
264
- label: OPENAI_RESETS_ROW_LABEL,
265
- info: CLAUDE_AGENT_RESETS_INFO,
266
- },
267
- ];
268
- }
269
- function optionalVisibilityRowsFor(providerId, cardId) {
270
- if (providerId === "openai")
271
- return openAiOptionalVisibilityRows(cardId);
272
- if (providerId === "claude-agent")
273
- return claudeAgentOptionalVisibilityRows(cardId);
274
- return undefined;
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");
275
234
  }
235
+ export { quotaEntryIsHidden };
276
236
  function latestObservedAtIso(entries) {
277
237
  let latest;
278
238
  let latestMs = Number.NEGATIVE_INFINITY;
@@ -313,9 +273,8 @@ function finishCard(card, mapped, entries) {
313
273
  if (mapped.primaryQuotaWindows.length > 0) {
314
274
  card.primaryQuotaWindows = mapped.primaryQuotaWindows;
315
275
  }
316
- const optionalRows = optionalVisibilityRowsFor(card.providerId, card.cardId);
317
- if (optionalRows)
318
- card.visibilityRows = optionalRows;
276
+ if (mapped.visibilityRows)
277
+ card.visibilityRows = mapped.visibilityRows;
319
278
  const observedAtIso = latestObservedAtIso(entries);
320
279
  if (observedAtIso)
321
280
  card.observedAtIso = observedAtIso;