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.
Files changed (238) hide show
  1. package/README.md +34 -20
  2. package/dist/bin/opencode-quota-gui.js +0 -0
  3. package/dist/contracts/build-identity.js +1 -1
  4. package/dist/contracts/card-order.d.ts +2 -0
  5. package/dist/contracts/card-order.js +2 -2
  6. package/dist/contracts/card-visibility.d.ts +2 -1
  7. package/dist/contracts/card-visibility.js +2 -1
  8. package/dist/contracts/dashboard.d.ts +95 -6
  9. package/dist/contracts/dashboard.js +10 -0
  10. package/dist/contracts/dto-guards.d.ts +4 -0
  11. package/dist/contracts/dto-guards.js +31 -7
  12. package/dist/contracts/guards.js +3 -1
  13. package/dist/contracts/identity.d.ts +37 -5
  14. package/dist/contracts/identity.js +43 -0
  15. package/dist/contracts/openai-quota.d.ts +3 -0
  16. package/dist/contracts/openai-quota.js +3 -0
  17. package/dist/contracts/provider-auto-resume.d.ts +9 -0
  18. package/dist/contracts/provider-auto-resume.js +24 -0
  19. package/dist/contracts/provider-failure.d.ts +22 -0
  20. package/dist/contracts/provider-failure.js +25 -1
  21. package/dist/contracts/row-order.d.ts +13 -0
  22. package/dist/contracts/row-order.js +34 -0
  23. package/dist/contracts/row-visibility.d.ts +53 -0
  24. package/dist/contracts/row-visibility.js +130 -0
  25. package/dist/data/modelsdev-pricing.min.json +1 -1
  26. package/dist/data/modelsdev-temporal.min.json +60 -634
  27. package/dist/gui/aggregation.d.ts +29 -1
  28. package/dist/gui/aggregation.js +157 -4
  29. package/dist/gui/analytics-bridge.d.ts +8 -9
  30. package/dist/gui/analytics-bridge.js +197 -54
  31. package/dist/gui/analytics-engine.d.ts +7 -15
  32. package/dist/gui/analytics-engine.js +246 -106
  33. package/dist/gui/analytics-model.d.ts +7 -0
  34. package/dist/gui/analytics-model.js +75 -9
  35. package/dist/gui/analytics-pricing-upkeep.d.ts +21 -0
  36. package/dist/gui/analytics-pricing-upkeep.js +23 -0
  37. package/dist/gui/analytics-protocol.d.ts +17 -7
  38. package/dist/gui/analytics-protocol.js +1 -0
  39. package/dist/gui/analytics-service.d.ts +10 -0
  40. package/dist/gui/analytics-service.js +30 -9
  41. package/dist/gui/analytics-state.d.ts +30 -5
  42. package/dist/gui/analytics-state.js +46 -7
  43. package/dist/gui/analytics-worker-runtime.d.ts +5 -0
  44. package/dist/gui/analytics-worker-runtime.js +9 -1
  45. package/dist/gui/analytics-worker.js +11 -0
  46. package/dist/gui/config.d.ts +3 -3
  47. package/dist/gui/config.js +77 -7
  48. package/dist/gui/identity.d.ts +6 -20
  49. package/dist/gui/identity.js +6 -54
  50. package/dist/gui/lifecycle.d.ts +5 -3
  51. package/dist/gui/lifecycle.js +3 -3
  52. package/dist/gui/primary-quota-windows.js +67 -44
  53. package/dist/gui/provider-cards.d.ts +20 -8
  54. package/dist/gui/provider-cards.js +42 -55
  55. package/dist/gui/quota-notification-detector.d.ts +29 -6
  56. package/dist/gui/quota-notification-detector.js +136 -47
  57. package/dist/gui/quota-notification-observer.d.ts +3 -4
  58. package/dist/gui/quota-notification-observer.js +73 -20
  59. package/dist/gui/quota-observation.d.ts +4 -0
  60. package/dist/gui/quota-observation.js +18 -0
  61. package/dist/gui/rpc.d.ts +2 -0
  62. package/dist/gui/rpc.js +14 -3
  63. package/dist/gui/server.js +17 -3
  64. package/dist/gui/snapshot-service.d.ts +3 -15
  65. package/dist/gui/snapshot-service.js +281 -23
  66. package/dist/gui/sources.js +179 -64
  67. package/dist/gui/temporal-status.d.ts +3 -2
  68. package/dist/gui/temporal-status.js +10 -6
  69. package/dist/gui-experimental.cjs +230 -225
  70. package/dist/lib/accounting-format.d.ts +8 -0
  71. package/dist/lib/accounting-format.js +20 -2
  72. package/dist/lib/alibaba-coding-plan-cli.d.ts +79 -0
  73. package/dist/lib/alibaba-coding-plan-cli.js +539 -0
  74. package/dist/lib/anthropic-api-auth.d.ts +7 -0
  75. package/dist/lib/anthropic-api-auth.js +27 -0
  76. package/dist/lib/anthropic-api-rate-limits.d.ts +47 -0
  77. package/dist/lib/anthropic-api-rate-limits.js +92 -0
  78. package/dist/lib/anthropic-auth.d.ts +2 -3
  79. package/dist/lib/anthropic-auth.js +2 -3
  80. package/dist/lib/anthropic-oauth-throttle.d.ts +76 -0
  81. package/dist/lib/anthropic-oauth-throttle.js +379 -0
  82. package/dist/lib/anthropic.d.ts +68 -14
  83. package/dist/lib/anthropic.js +1016 -363
  84. package/dist/lib/api-key-retry-after.d.ts +7 -0
  85. package/dist/lib/api-key-retry-after.js +62 -0
  86. package/dist/lib/atomic-json.d.ts +2 -0
  87. package/dist/lib/atomic-json.js +1 -0
  88. package/dist/lib/cache-observer-ingestion.d.ts +90 -0
  89. package/dist/lib/cache-observer-ingestion.js +1008 -0
  90. package/dist/lib/cache-observer.d.ts +141 -0
  91. package/dist/lib/cache-observer.js +323 -0
  92. package/dist/lib/canonical-config-lock.d.ts +9 -0
  93. package/dist/lib/canonical-config-lock.js +36 -0
  94. package/dist/lib/chutes.js +62 -51
  95. package/dist/lib/claude-agent-transcript-ttl.d.ts +48 -0
  96. package/dist/lib/claude-agent-transcript-ttl.js +154 -0
  97. package/dist/lib/claude-agent-ttl-tracker.d.ts +21 -0
  98. package/dist/lib/claude-agent-ttl-tracker.js +152 -0
  99. package/dist/lib/cli-show.d.ts +5 -0
  100. package/dist/lib/cli-show.js +21 -8
  101. package/dist/lib/cli-status.js +3 -6
  102. package/dist/lib/config-write-target.d.ts +1 -1
  103. package/dist/lib/config-write-target.js +5 -2
  104. package/dist/lib/config.d.ts +2 -1
  105. package/dist/lib/config.js +257 -4
  106. package/dist/lib/copilot.js +171 -86
  107. package/dist/lib/dashboard-visibility.d.ts +5 -0
  108. package/dist/lib/dashboard-visibility.js +11 -10
  109. package/dist/lib/dashboard-web-policy.d.ts +4 -4
  110. package/dist/lib/dashboard-web-policy.js +2 -2
  111. package/dist/lib/deepseek.js +25 -13
  112. package/dist/lib/display-sanitize.js +2 -0
  113. package/dist/lib/entries.d.ts +33 -1
  114. package/dist/lib/entries.js +6 -0
  115. package/dist/lib/glm-coding-plan.js +98 -74
  116. package/dist/lib/google-agy.js +90 -12
  117. package/dist/lib/google-gemini-cli.js +84 -11
  118. package/dist/lib/grouped-entry-normalization.js +1 -1
  119. package/dist/lib/http.d.ts +4 -0
  120. package/dist/lib/http.js +16 -2
  121. package/dist/lib/init-installer.js +5 -3
  122. package/dist/lib/kilo.js +37 -18
  123. package/dist/lib/kimi.js +35 -18
  124. package/dist/lib/maintainer-announcements.js +2 -2
  125. package/dist/lib/mimo.d.ts +2 -0
  126. package/dist/lib/mimo.js +36 -0
  127. package/dist/lib/modelsdev-pricing.d.ts +74 -2
  128. package/dist/lib/modelsdev-pricing.js +457 -63
  129. package/dist/lib/modelsdev-temporal.d.ts +6 -0
  130. package/dist/lib/modelsdev-temporal.js +16 -2
  131. package/dist/lib/nanogpt.d.ts +1 -0
  132. package/dist/lib/nanogpt.js +26 -3
  133. package/dist/lib/ollama-cloud.d.ts +1 -1
  134. package/dist/lib/ollama-cloud.js +48 -35
  135. package/dist/lib/openai.js +84 -38
  136. package/dist/lib/opencode-auth-sqlite.d.ts +2 -2
  137. package/dist/lib/opencode-auth-sqlite.js +2 -2
  138. package/dist/lib/opencode-config-editor.d.ts +1 -0
  139. package/dist/lib/opencode-config-editor.js +6 -1
  140. package/dist/lib/opencode-config-providers.js +2 -2
  141. package/dist/lib/opencode-go.js +29 -2
  142. package/dist/lib/opencode-storage.d.ts +20 -0
  143. package/dist/lib/opencode-storage.js +89 -2
  144. package/dist/lib/opencode-version-core.d.ts +30 -0
  145. package/dist/lib/opencode-version-core.js +59 -0
  146. package/dist/lib/opencode-version.d.ts +2 -22
  147. package/dist/lib/opencode-version.js +4 -48
  148. package/dist/lib/opencode-warming-refresh.d.ts +19 -0
  149. package/dist/lib/opencode-warming-refresh.js +95 -0
  150. package/dist/lib/opencode-zen.d.ts +3 -0
  151. package/dist/lib/opencode-zen.js +71 -5
  152. package/dist/lib/provider-add.js +5 -2
  153. package/dist/lib/provider-metadata.d.ts +11 -3
  154. package/dist/lib/provider-metadata.js +20 -2
  155. package/dist/lib/provider-registration.d.ts +358 -9
  156. package/dist/lib/provider-registration.js +423 -30
  157. package/dist/lib/quota-auto-resume.d.ts +74 -0
  158. package/dist/lib/quota-auto-resume.js +539 -0
  159. package/dist/lib/quota-command-format.js +23 -10
  160. package/dist/lib/quota-exhaustion-projection.d.ts +11 -0
  161. package/dist/lib/quota-exhaustion-projection.js +25 -0
  162. package/dist/lib/quota-identity.d.ts +64 -0
  163. package/dist/lib/quota-identity.js +111 -0
  164. package/dist/lib/quota-providers-remote.d.ts +2 -1
  165. package/dist/lib/quota-providers-remote.js +59 -3
  166. package/dist/lib/quota-providers.d.ts +1 -1
  167. package/dist/lib/quota-providers.js +14 -37
  168. package/dist/lib/quota-render-data.d.ts +6 -0
  169. package/dist/lib/quota-render-data.js +45 -19
  170. package/dist/lib/quota-reset-notifications.js +11 -155
  171. package/dist/lib/quota-retry-wait.d.ts +106 -5
  172. package/dist/lib/quota-retry-wait.js +301 -34
  173. package/dist/lib/quota-runtime-context.js +1 -0
  174. package/dist/lib/quota-state-codec.d.ts +2 -0
  175. package/dist/lib/quota-state-codec.js +31 -2
  176. package/dist/lib/quota-state.d.ts +8 -2
  177. package/dist/lib/quota-state.js +253 -47
  178. package/dist/lib/quota-stats.d.ts +26 -0
  179. package/dist/lib/quota-stats.js +40 -1
  180. package/dist/lib/quota-status.js +3 -51
  181. package/dist/lib/quota-surface-data.js +18 -3
  182. package/dist/lib/quota-telemetry.js +2 -2
  183. package/dist/lib/resolved-auth-identity.d.ts +19 -0
  184. package/dist/lib/resolved-auth-identity.js +44 -0
  185. package/dist/lib/scoped-update.d.ts +1 -1
  186. package/dist/lib/state-file-lock.d.ts +26 -0
  187. package/dist/lib/state-file-lock.js +205 -0
  188. package/dist/lib/synthetic.js +65 -54
  189. package/dist/lib/toast-format-grouped.js +7 -4
  190. package/dist/lib/tui-compact-format.js +29 -16
  191. package/dist/lib/types.d.ts +51 -1
  192. package/dist/lib/types.js +17 -1
  193. package/dist/lib/xai.js +48 -22
  194. package/dist/plugin.js +328 -14
  195. package/dist/provider-logos/NOTICE.md +1 -1
  196. package/dist/provider-logos/OPENCODE-NOTICE.md +4 -3
  197. package/dist/providers/alibaba-coding-plan.js +125 -104
  198. package/dist/providers/alibaba-token-plan.js +9 -5
  199. package/dist/providers/anthropic.d.ts +16 -3
  200. package/dist/providers/anthropic.js +172 -220
  201. package/dist/providers/cache-policies.d.ts +11 -4
  202. package/dist/providers/cache-policies.js +19 -13
  203. package/dist/providers/chutes.js +2 -0
  204. package/dist/providers/claude-agent.d.ts +19 -0
  205. package/dist/providers/claude-agent.js +215 -0
  206. package/dist/providers/copilot.js +7 -4
  207. package/dist/providers/glm-coding-plan-provider.d.ts +1 -0
  208. package/dist/providers/glm-coding-plan-provider.js +30 -23
  209. package/dist/providers/google-account-format.js +1 -0
  210. package/dist/providers/google-agy.d.ts +6 -5
  211. package/dist/providers/google-agy.js +43 -15
  212. package/dist/providers/google-gemini-cli.js +1 -0
  213. package/dist/providers/kilo.js +1 -0
  214. package/dist/providers/kimi-code.js +2 -0
  215. package/dist/providers/mimo.js +1 -0
  216. package/dist/providers/nanogpt.js +1 -0
  217. package/dist/providers/ollama-cloud.js +10 -0
  218. package/dist/providers/openai.js +24 -23
  219. package/dist/providers/opencode-go.js +10 -6
  220. package/dist/providers/opencode-zen.js +3 -1
  221. package/dist/providers/openrouter.js +1 -0
  222. package/dist/providers/quota-providers.js +16 -5
  223. package/dist/providers/registry.js +2 -0
  224. package/dist/providers/result-helpers.d.ts +6 -2
  225. package/dist/providers/result-helpers.js +7 -1
  226. package/dist/providers/synthetic.js +4 -0
  227. package/dist/providers/xai.js +9 -8
  228. package/dist/rpc.d.ts +129 -8
  229. package/dist/rpc.js +219 -14
  230. package/dist/ui/assets/{index-cDd9jUVY.css → index-6_g1FHs-.css} +1 -1
  231. package/dist/ui/assets/index-sZnGUuML.js +10 -0
  232. package/dist/ui/assets/{popover-BGkgv9s0.js → popover-C4ZLYe9E.js} +1 -1
  233. package/dist/ui/assets/providers/claude-agent.svg +3 -0
  234. package/dist/ui/index.html +2 -2
  235. package/package.json +45 -46
  236. package/dist/lib/alibaba-coding-plan-local-quota.d.ts +0 -47
  237. package/dist/lib/alibaba-coding-plan-local-quota.js +0 -146
  238. package/dist/ui/assets/index-DLHeXYff.js +0 -9
@@ -0,0 +1,64 @@
1
+ import type { ProviderCard } from "../contracts/dashboard.js";
2
+ import type { CardId } from "../contracts/identity.js";
3
+ import { type QuotaRowIdentityEntry } from "../contracts/identity.js";
4
+ /**
5
+ * Server-side card identity and entry visibility.
6
+ *
7
+ * The browser-safe row-key/id builders live in `src/contracts/identity.ts`;
8
+ * this module adds the `node:crypto` card hash and the visibility predicate so
9
+ * both `src/lib` and `src/gui` consume one implementation without importing
10
+ * each other.
11
+ */
12
+ /**
13
+ * Reserved identity key for the provider-scope card (entries/errors that no
14
+ * discovered account owns). It is a scope marker, never an account id.
15
+ */
16
+ export declare const PROVIDER_SCOPE_IDENTITY_KEY = "provider";
17
+ /** The minimal provider-result fields row visibility needs. */
18
+ export interface QuotaVisibilityProviderResult {
19
+ readonly accounts?: readonly {
20
+ readonly sourceId: string;
21
+ readonly identityKey?: string;
22
+ }[];
23
+ /** Emitted entries, in emission order, for legacy aggregate-id resolution. */
24
+ readonly entries?: readonly QuotaVisibilityEntry[];
25
+ }
26
+ /** An entry plus the account attribution row visibility needs. */
27
+ export type QuotaVisibilityEntry = QuotaRowIdentityEntry & {
28
+ readonly accounting: {
29
+ readonly resultType: QuotaRowIdentityEntry["accounting"]["resultType"];
30
+ readonly sourceId?: string;
31
+ };
32
+ };
33
+ /** Deterministic sha256 hex of the domain-separated (providerId, identityKey) pair. */
34
+ export declare function hashQuotaCardIdentity(providerId: string, identityKey: string): string;
35
+ /** Opaque card id: provider namespace + server-side hash; raw identities never appear. */
36
+ export declare function buildCardId(providerId: string, identityKey: string): CardId;
37
+ /** The provider-scope card id (unscoped rows/errors, or no discovered accounts). */
38
+ export declare function buildProviderScopeCardId(providerId: string): CardId;
39
+ /**
40
+ * Persistent Settings controls from the provider registration table.
41
+ *
42
+ * The control id is always the declared field id, so it stays stable when the
43
+ * provider renders the field in another shape. Every supported alternate shape
44
+ * (declared explicitly, plus any live emitted shape when the rowKey has one
45
+ * declaration) is an alias of that control. Emitted row ids never change.
46
+ */
47
+ export declare function optionalVisibilityRowsFor(providerId: string, cardId: CardId, rows?: readonly {
48
+ rowId: string;
49
+ }[]): ProviderCard["visibilityRows"];
50
+ /**
51
+ * Whether one entry's live row is hidden by the effective card/row settings
52
+ * the browser and native surfaces use. Shared by dashboard cards and the
53
+ * retained legacy reset notice path so a hidden field is silent everywhere.
54
+ * A saved pre-window aggregate id resolves against the emitted entries to the
55
+ * first row it used to match; a declared control resolves through its aliases.
56
+ */
57
+ export declare function quotaEntryIsHidden(params: {
58
+ providerId: string;
59
+ result: QuotaVisibilityProviderResult;
60
+ entry: QuotaVisibilityEntry;
61
+ hiddenCards?: readonly string[];
62
+ hiddenRows?: readonly string[];
63
+ }): boolean;
64
+ //# sourceMappingURL=quota-identity.d.ts.map
@@ -0,0 +1,111 @@
1
+ import { createHash } from "node:crypto";
2
+ import { isCardHidden } from "../contracts/card-visibility.js";
3
+ import { optionalRowId, rowFieldKey, rowIdForEntry, } from "../contracts/identity.js";
4
+ import { effectiveHiddenRowIds } from "../contracts/row-visibility.js";
5
+ import { getQuotaProviderRegistration } from "./provider-metadata.js";
6
+ /**
7
+ * Server-side card identity and entry visibility.
8
+ *
9
+ * The browser-safe row-key/id builders live in `src/contracts/identity.ts`;
10
+ * this module adds the `node:crypto` card hash and the visibility predicate so
11
+ * both `src/lib` and `src/gui` consume one implementation without importing
12
+ * each other.
13
+ */
14
+ /**
15
+ * Reserved identity key for the provider-scope card (entries/errors that no
16
+ * discovered account owns). It is a scope marker, never an account id.
17
+ */
18
+ export const PROVIDER_SCOPE_IDENTITY_KEY = "provider";
19
+ const CARD_HASH_DOMAIN = "ocq-card-v1";
20
+ /** Deterministic sha256 hex of the domain-separated (providerId, identityKey) pair. */
21
+ export function hashQuotaCardIdentity(providerId, identityKey) {
22
+ return createHash("sha256")
23
+ .update(`${CARD_HASH_DOMAIN}\0${providerId}\0${identityKey}`, "utf8")
24
+ .digest("hex");
25
+ }
26
+ /** Opaque card id: provider namespace + server-side hash; raw identities never appear. */
27
+ export function buildCardId(providerId, identityKey) {
28
+ // SAFETY: CardId is the opaque brand of exactly `<providerId>:<sha256>`; this
29
+ // builder is its only producer and the hash covers both raw inputs.
30
+ return `${providerId}:${hashQuotaCardIdentity(providerId, identityKey)}`;
31
+ }
32
+ /** The provider-scope card id (unscoped rows/errors, or no discovered accounts). */
33
+ export function buildProviderScopeCardId(providerId) {
34
+ return buildCardId(providerId, PROVIDER_SCOPE_IDENTITY_KEY);
35
+ }
36
+ /** The card a row belongs to: its account card, or the provider-scope card. */
37
+ function cardIdForEntry(providerId, result, entry) {
38
+ const account = (result.accounts ?? []).find((candidate) => candidate.sourceId === entry.accounting.sourceId);
39
+ return account
40
+ ? buildCardId(providerId, account.identityKey?.trim() ? account.identityKey : account.sourceId)
41
+ : buildProviderScopeCardId(providerId);
42
+ }
43
+ /**
44
+ * Persistent Settings controls from the provider registration table.
45
+ *
46
+ * The control id is always the declared field id, so it stays stable when the
47
+ * provider renders the field in another shape. Every supported alternate shape
48
+ * (declared explicitly, plus any live emitted shape when the rowKey has one
49
+ * declaration) is an alias of that control. Emitted row ids never change.
50
+ */
51
+ export function optionalVisibilityRowsFor(providerId, cardId, rows = []) {
52
+ const declared = getQuotaProviderRegistration(providerId)?.optionalVisibilityRows;
53
+ if (!declared || declared.length === 0)
54
+ return undefined;
55
+ const declarationsByField = new Map();
56
+ for (const row of declared) {
57
+ declarationsByField.set(row.rowKey, (declarationsByField.get(row.rowKey) ?? 0) + 1);
58
+ }
59
+ return declared.map((row) => {
60
+ const rowId = optionalRowId(cardId, row.rowKey, row.resultType, row.kind);
61
+ const aliases = new Set();
62
+ for (const shape of row.alternateShapes ?? []) {
63
+ const alias = optionalRowId(cardId, row.rowKey, shape.resultType, shape.kind);
64
+ if (alias !== rowId)
65
+ aliases.add(alias);
66
+ }
67
+ // A rowKey with one declaration names one field: keep any live emitted
68
+ // shape of that field on the same control. Duplicate declarations are two
69
+ // distinct fields (for example a budget and a spend month), so only their
70
+ // exact ids may match.
71
+ if (declarationsByField.get(row.rowKey) === 1) {
72
+ for (const entry of rows) {
73
+ if (entry.rowId !== rowId && rowFieldKey(entry.rowId) === row.rowKey) {
74
+ aliases.add(entry.rowId);
75
+ }
76
+ }
77
+ }
78
+ return {
79
+ rowId,
80
+ label: row.label,
81
+ info: row.info,
82
+ ...(aliases.size > 0 ? { aliases: [...aliases] } : {}),
83
+ };
84
+ });
85
+ }
86
+ /**
87
+ * Whether one entry's live row is hidden by the effective card/row settings
88
+ * the browser and native surfaces use. Shared by dashboard cards and the
89
+ * retained legacy reset notice path so a hidden field is silent everywhere.
90
+ * A saved pre-window aggregate id resolves against the emitted entries to the
91
+ * first row it used to match; a declared control resolves through its aliases.
92
+ */
93
+ export function quotaEntryIsHidden(params) {
94
+ const cardId = cardIdForEntry(params.providerId, params.result, params.entry);
95
+ if (isCardHidden({
96
+ cardId,
97
+ providerId: params.providerId,
98
+ providerScopeHash: hashQuotaCardIdentity(params.providerId, PROVIDER_SCOPE_IDENTITY_KEY),
99
+ }, new Set(params.hiddenCards ?? []))) {
100
+ return true;
101
+ }
102
+ const hiddenRows = params.hiddenRows ?? [];
103
+ if (hiddenRows.length === 0)
104
+ return false;
105
+ const cardRowIds = (params.result.entries ?? [params.entry])
106
+ .filter((entry) => cardIdForEntry(params.providerId, params.result, entry) === cardId)
107
+ .map((entry) => rowIdForEntry(cardId, entry));
108
+ const controls = optionalVisibilityRowsFor(params.providerId, cardId, cardRowIds.map((rowId) => ({ rowId })));
109
+ return effectiveHiddenRowIds(cardRowIds, hiddenRows, controls).has(rowIdForEntry(cardId, params.entry));
110
+ }
111
+ //# sourceMappingURL=quota-identity.js.map
@@ -23,7 +23,8 @@ export type RemoteQuotaProviderResult = {
23
23
  success: false;
24
24
  error: string;
25
25
  failureCategory?: ProviderFailureCategory;
26
+ retryAtMs?: number;
26
27
  };
27
28
  export declare function resolveQuotaProviderApiKey(source: RemoteApiQuotaProviderDefinition): Promise<QuotaProviderAuthResolution>;
28
- export declare function fetchRemoteQuotaProvider(source: RemoteApiQuotaProviderDefinition, apiKey: string, requestTimeoutMs?: number): Promise<RemoteQuotaProviderResult>;
29
+ export declare function fetchRemoteQuotaProvider(source: RemoteApiQuotaProviderDefinition, apiKey: string | undefined, requestTimeoutMs?: number, fetcher?: typeof fetch): Promise<RemoteQuotaProviderResult>;
29
30
  //# sourceMappingURL=quota-providers-remote.d.ts.map
@@ -1,3 +1,4 @@
1
+ import { createHmac, randomBytes } from "node:crypto";
1
2
  import { providerFailureCategoryForHttpStatus, } from "../contracts/provider-failure.js";
2
3
  import { createProviderApiKeyResolver, getApiKeyCheckedPaths, getGlobalOpencodeConfigCandidatePaths, } from "./api-key-resolver.js";
3
4
  import { sanitizeSingleLineDisplayText } from "./display-sanitize.js";
@@ -753,17 +754,62 @@ function parseOpenRouterKeyV1(source, body) {
753
754
  entries: [openRouterSpendEntry(source, usage)],
754
755
  };
755
756
  }
756
- export async function fetchRemoteQuotaProvider(source, apiKey, requestTimeoutMs) {
757
+ export async function fetchRemoteQuotaProvider(source, apiKey, requestTimeoutMs, fetcher = fetch) {
758
+ const identity = createHmac("sha256", remoteIdentityKey)
759
+ .update(JSON.stringify([source.url, apiKey ?? null]))
760
+ .digest("base64url");
761
+ const now = Date.now();
762
+ for (const [key, deadline] of remoteRetryDeadlines) {
763
+ if (deadline <= now)
764
+ remoteRetryDeadlines.delete(key);
765
+ }
766
+ const deadline = remoteRetryDeadlines.get(identity);
767
+ if (deadline !== undefined)
768
+ return {
769
+ success: false,
770
+ error: "HTTP 429",
771
+ failureCategory: "provider_api",
772
+ retryAtMs: deadline,
773
+ };
774
+ const previous = remoteInFlight.get(identity);
775
+ if (previous) {
776
+ if (previous.source === JSON.stringify(source) &&
777
+ previous.fetcher === fetcher &&
778
+ previous.timeout === requestTimeoutMs) {
779
+ return structuredClone(await previous.request);
780
+ }
781
+ await previous.request;
782
+ return fetchRemoteQuotaProvider(source, apiKey, requestTimeoutMs, fetcher);
783
+ }
784
+ const request = fetchRemoteQuotaProviderUncached(source, apiKey, requestTimeoutMs, fetcher);
785
+ const pending = { request, source: JSON.stringify(source), fetcher, timeout: requestTimeoutMs };
786
+ remoteInFlight.set(identity, pending);
787
+ try {
788
+ const result = await request;
789
+ if (!result.success && result.retryAtMs !== undefined && result.retryAtMs > Date.now()) {
790
+ remoteRetryDeadlines.set(identity, result.retryAtMs);
791
+ }
792
+ return result;
793
+ }
794
+ finally {
795
+ if (remoteInFlight.get(identity) === pending)
796
+ remoteInFlight.delete(identity);
797
+ }
798
+ }
799
+ const remoteRetryDeadlines = new Map();
800
+ const remoteInFlight = new Map();
801
+ const remoteIdentityKey = randomBytes(32);
802
+ async function fetchRemoteQuotaProviderUncached(source, apiKey, requestTimeoutMs, fetcher = fetch) {
757
803
  const timeoutMs = requestTimeoutMs ?? REQUEST_TIMEOUT_MS;
758
804
  const controller = new AbortController();
759
805
  const timeoutId = setTimeout(() => controller.abort(), timeoutMs);
760
806
  try {
761
- const response = await fetch(source.url, {
807
+ const response = await fetcher(source.url, {
762
808
  method: "GET",
763
809
  redirect: "manual",
764
810
  signal: controller.signal,
765
811
  headers: {
766
- Authorization: `Bearer ${apiKey}`,
812
+ ...(apiKey ? { Authorization: `Bearer ${apiKey}` } : {}),
767
813
  Accept: "application/json",
768
814
  },
769
815
  });
@@ -771,10 +817,17 @@ export async function fetchRemoteQuotaProvider(source, apiKey, requestTimeoutMs)
771
817
  return { success: false, error: "Redirect rejected", failureCategory: "provider_api" };
772
818
  }
773
819
  if (!response.ok) {
820
+ const header = response.status === 429 ? response.headers.get("retry-after")?.trim() : undefined;
821
+ const retryAtMs = header && /^\d+$/.test(header)
822
+ ? Date.now() + Number(header) * 1000
823
+ : header && /^[A-Za-z]{3}, \d{2} [A-Za-z]{3} \d{4} \d{2}:\d{2}:\d{2} GMT$/.test(header)
824
+ ? Date.parse(header)
825
+ : NaN;
774
826
  return {
775
827
  success: false,
776
828
  error: `HTTP ${response.status}`,
777
829
  failureCategory: providerFailureCategoryForHttpStatus(response.status),
830
+ ...(Number.isSafeInteger(retryAtMs) && retryAtMs > Date.now() ? { retryAtMs } : {}),
778
831
  };
779
832
  }
780
833
  const body = await readBoundedJson(response);
@@ -788,6 +841,9 @@ export async function fetchRemoteQuotaProvider(source, apiKey, requestTimeoutMs)
788
841
  }
789
842
  }
790
843
  catch (error) {
844
+ if (error && typeof error === "object" && "code" in error && error.code === "unsafe-endpoint") {
845
+ return { success: false, error: "Unsafe provider endpoint", failureCategory: "provider_api" };
846
+ }
791
847
  if (controller.signal.aborted || (error instanceof Error && error.name === "AbortError")) {
792
848
  return {
793
849
  success: false,
@@ -3,7 +3,7 @@ export declare const QUOTA_PROVIDER_REMOTE_FORMATS: readonly ["quota-v1", "openr
3
3
  export declare const QUOTA_PROVIDER_MODES: readonly ["remote-api", "local-estimate"];
4
4
  export declare const QUOTA_PROVIDER_WINDOW_TYPES: readonly ["utc-day", "rolling"];
5
5
  export declare const QUOTA_PROVIDERS_AGGREGATE_ID = "quota-providers";
6
- export declare const MAINTAINED_LOCAL_ESTIMATE_IDS: readonly ["alibaba-coding-plan"];
6
+ export declare const MAINTAINED_LOCAL_ESTIMATE_IDS: readonly [];
7
7
  export declare function isMaintainedQuotaProviderTuning(definition: QuotaProviderDefinition): boolean;
8
8
  export declare function customQuotaProviderDefinitions(definitions: readonly QuotaProviderDefinition[]): QuotaProviderDefinition[];
9
9
  export declare function resolveQuotaProviderSessionModelIdentity(params: {
@@ -1,17 +1,25 @@
1
1
  import { isIP } from "node:net";
2
2
  import { lookupCost } from "./modelsdev-pricing.js";
3
- import { getQuotaProviderShape } from "./provider-metadata.js";
3
+ import { getQuotaProviderRegistration } from "./provider-metadata.js";
4
4
  import { resolvePricingKey } from "./quota-stats.js";
5
5
  export const QUOTA_PROVIDER_REMOTE_FORMATS = ["quota-v1", "openrouter-key-v1", "json-v1"];
6
6
  export const QUOTA_PROVIDER_MODES = ["remote-api", "local-estimate"];
7
7
  export const QUOTA_PROVIDER_WINDOW_TYPES = ["utc-day", "rolling"];
8
8
  export const QUOTA_PROVIDERS_AGGREGATE_ID = "quota-providers";
9
- export const MAINTAINED_LOCAL_ESTIMATE_IDS = ["alibaba-coding-plan"];
9
+ export const MAINTAINED_LOCAL_ESTIMATE_IDS = [];
10
+ const LOCAL_ESTIMATE_PROVIDER_IDS_WITHOUT_ESTIMATES = new Set(["alibaba", "alibaba-coding-plan"]);
11
+ function hasUnsupportedAlibabaLocalEstimate(definition) {
12
+ if (!isPlainObject(definition) || definition.mode !== "local-estimate")
13
+ return false;
14
+ const providerId = hasOwnKey(definition, "providerId") ? definition.providerId : definition.id;
15
+ return (typeof providerId === "string" && LOCAL_ESTIMATE_PROVIDER_IDS_WITHOUT_ESTIMATES.has(providerId));
16
+ }
10
17
  export function isMaintainedQuotaProviderTuning(definition) {
11
18
  return MAINTAINED_LOCAL_ESTIMATE_IDS.includes(definition.id);
12
19
  }
13
20
  export function customQuotaProviderDefinitions(definitions) {
14
- return definitions.filter((definition) => !isMaintainedQuotaProviderTuning(definition));
21
+ return definitions.filter((definition) => !isMaintainedQuotaProviderTuning(definition) &&
22
+ !hasUnsupportedAlibabaLocalEstimate(definition));
15
23
  }
16
24
  export function resolveQuotaProviderSessionModelIdentity(params) {
17
25
  if (params.currentProviderID) {
@@ -829,29 +837,6 @@ function validateWindows(raw, providerKey, issues) {
829
837
  }
830
838
  return windows.length === raw.length ? windows : undefined;
831
839
  }
832
- function validateMaintainedWindows(id, windows, providerKey, issues) {
833
- if (!windows || !MAINTAINED_LOCAL_ESTIMATE_IDS.includes(id))
834
- return;
835
- const expected = [
836
- { id: "five-hour", type: "rolling", durationMinutes: 300 },
837
- { id: "weekly", type: "rolling", durationMinutes: 10_080 },
838
- { id: "monthly", type: "rolling", durationMinutes: 43_200 },
839
- ];
840
- if (windows.length !== expected.length ||
841
- expected.some((item, index) => {
842
- const window = windows[index];
843
- return (!window ||
844
- window.id !== item.id ||
845
- window.type !== item.type ||
846
- window.durationMinutes !== item.durationMinutes ||
847
- window.usdBudget !== undefined);
848
- })) {
849
- issues.push({
850
- key: `${providerKey}.windows`,
851
- message: "alibaba-coding-plan tuning requires ordered five-hour, weekly, and monthly rolling request windows",
852
- });
853
- }
854
- }
855
840
  function validatePricingModelMap(raw, providerKey, providerId, issues) {
856
841
  if (raw === undefined)
857
842
  return undefined;
@@ -916,6 +901,8 @@ export function validateQuotaProviders(value) {
916
901
  issues.push({ key: providerKey, message: "expected an object" });
917
902
  continue;
918
903
  }
904
+ if (hasUnsupportedAlibabaLocalEstimate(raw))
905
+ continue;
919
906
  const issueStart = issues.length;
920
907
  const mode = raw.mode;
921
908
  const allowedFields = mode === "local-estimate"
@@ -951,7 +938,7 @@ export function validateQuotaProviders(value) {
951
938
  message: `"${QUOTA_PROVIDERS_AGGREGATE_ID}" is reserved for the aggregate provider`,
952
939
  });
953
940
  }
954
- const builtIn = getQuotaProviderShape(id);
941
+ const builtIn = getQuotaProviderRegistration(id);
955
942
  if (builtIn && !MAINTAINED_LOCAL_ESTIMATE_IDS.includes(id)) {
956
943
  issues.push({
957
944
  key: `${providerKey}.id`,
@@ -1005,14 +992,6 @@ export function validateQuotaProviders(value) {
1005
992
  const modelIds = validateModelIds({ raw, providerKey, providerId, issues });
1006
993
  const modelIdsValid = !hasOwnKey(raw, "modelIds") ||
1007
994
  (Array.isArray(raw.modelIds) && modelIds?.length === raw.modelIds.length);
1008
- if (idValid &&
1009
- MAINTAINED_LOCAL_ESTIMATE_IDS.includes(id) &&
1010
- mode !== "local-estimate") {
1011
- issues.push({
1012
- key: `${providerKey}.mode`,
1013
- message: `${id} tuning must use local-estimate mode`,
1014
- });
1015
- }
1016
995
  if (mode === "remote-api") {
1017
996
  for (const field of ["url", "format"]) {
1018
997
  if (!hasOwnKey(raw, field)) {
@@ -1104,8 +1083,6 @@ export function validateQuotaProviders(value) {
1104
1083
  issues.push({ key: `${providerKey}.windows`, message: "field is required" });
1105
1084
  }
1106
1085
  const windows = validateWindows(raw.windows, providerKey, issues);
1107
- if (idValid)
1108
- validateMaintainedWindows(id, windows, providerKey, issues);
1109
1086
  const pricingModelMap = providerId && hasOwnKey(raw, "pricingModelMap")
1110
1087
  ? validatePricingModelMap(raw.pricingModelMap, providerKey, providerId, issues)
1111
1088
  : undefined;
@@ -54,6 +54,8 @@ export type CollectQuotaRenderDataResult = {
54
54
  export type QuotaStatusLiveProbe = {
55
55
  providerId: string;
56
56
  result: QuotaProviderResult;
57
+ /** Server-only opaque scope, never projected into dashboard DTOs. */
58
+ cacheScope?: string;
57
59
  };
58
60
  export declare function matchesQuotaProviderCurrentSelection(params: {
59
61
  provider: QuotaProvider;
@@ -78,6 +80,7 @@ export declare function fetchProviderResults(params: {
78
80
  ctx: QuotaProviderContext;
79
81
  ttlMs: number;
80
82
  bypassCache?: boolean;
83
+ forceRefresh?: boolean;
81
84
  }): Promise<QuotaProviderResult[]>;
82
85
  export declare function collectQuotaStatusLiveProbes(params: {
83
86
  client: QuotaProviderContext["client"];
@@ -107,6 +110,7 @@ export declare function collectQuotaDashboardProviderResults(params: {
107
110
  configMeta?: Pick<LoadConfigMeta, "settingSources">;
108
111
  providers?: QuotaProvider[];
109
112
  bypassProviderCache?: boolean;
113
+ forceProviderRefresh?: boolean;
110
114
  resolveRuntimeProviderIds?: RuntimeProviderIdResolver;
111
115
  /** Dashboard-only OpenAI reset-detail visibility callback. */
112
116
  openaiResetDetailsVisible?: (sourceId?: string) => boolean;
@@ -120,6 +124,8 @@ export declare function collectQuotaRenderData(params: {
120
124
  formatStyle?: QuotaFormatStyle;
121
125
  configMeta?: Pick<LoadConfigMeta, "settingSources">;
122
126
  bypassProviderCache?: boolean;
127
+ forceProviderRefresh?: boolean;
128
+ includeProviderScope?: boolean;
123
129
  providers?: QuotaProvider[];
124
130
  includeAllWindowsData?: boolean;
125
131
  /**
@@ -1,10 +1,11 @@
1
1
  import { getAnthropicNoDataMessage } from "../providers/anthropic.js";
2
+ import { getClaudeAgentNoDataMessage } from "../providers/claude-agent.js";
2
3
  import { getProviders } from "../providers/registry.js";
3
4
  import { cloneQuotaToastEntry } from "./entries.js";
4
- import { getQuotaProviderDisplayLabel, getQuotaProviderIdsForRuntimeId, getQuotaProviderShape, } from "./provider-metadata.js";
5
+ import { getQuotaProviderDisplayLabel, getQuotaProviderIdsForRuntimeId, getQuotaProviderRegistration, } from "./provider-metadata.js";
5
6
  import { projectQuotaProviderResults } from "./quota-accounting-projection.js";
6
7
  import { createQuotaProviderRuntimeContext } from "./quota-runtime-context.js";
7
- import { fetchQuotaProviderResult } from "./quota-state.js";
8
+ import { fetchQuotaProviderResult, getQuotaProviderResultScope, QUOTA_FORCE_REFRESH, } from "./quota-state.js";
8
9
  import { retainQuotaTelemetryProviders } from "./quota-telemetry.js";
9
10
  import { createRuntimeProviderIdResolver, } from "./runtime-provider-ids.js";
10
11
  import { fetchSessionTokensForDisplay } from "./session-tokens.js";
@@ -61,7 +62,7 @@ export function matchesQuotaProviderCurrentSelection(params) {
61
62
  }
62
63
  if (params.currentProviderID) {
63
64
  const explicitId = params.currentProviderID.trim().toLowerCase();
64
- const catalogShape = getQuotaProviderShape(explicitId);
65
+ const catalogShape = getQuotaProviderRegistration(explicitId);
65
66
  if (catalogShape?.id === explicitId)
66
67
  return params.provider.id === catalogShape.id;
67
68
  const runtimeCandidates = getQuotaProviderIdsForRuntimeId(explicitId);
@@ -93,22 +94,25 @@ export async function resolveQuotaRenderSelection(params) {
93
94
  currentModel = request.sessionMeta.modelID;
94
95
  currentProviderID = request.sessionMeta.providerID;
95
96
  }
96
- const ctx = createQuotaProviderRuntimeContext({
97
- client,
98
- config,
99
- configMeta: params.configMeta,
100
- resolveRuntimeProviderIds: params.resolveRuntimeProviderIds ?? createRuntimeProviderIdResolver(client),
101
- workspaceRoot: params.workspaceRoot,
102
- ...(params.openaiResetDetailsVisible
103
- ? { openaiResetDetailsVisible: params.openaiResetDetailsVisible }
104
- : {}),
105
- session: {
106
- sessionMeta: {
107
- modelID: currentModel,
108
- providerID: currentProviderID,
97
+ const ctx = {
98
+ ...createQuotaProviderRuntimeContext({
99
+ client,
100
+ config,
101
+ configMeta: params.configMeta,
102
+ resolveRuntimeProviderIds: params.resolveRuntimeProviderIds ?? createRuntimeProviderIdResolver(client),
103
+ workspaceRoot: params.workspaceRoot,
104
+ ...(params.openaiResetDetailsVisible
105
+ ? { openaiResetDetailsVisible: params.openaiResetDetailsVisible }
106
+ : {}),
107
+ session: {
108
+ sessionMeta: {
109
+ modelID: currentModel,
110
+ providerID: currentProviderID,
111
+ },
109
112
  },
110
- },
111
- });
113
+ }),
114
+ operationCache: new Map(),
115
+ };
112
116
  if (!config.enabled)
113
117
  return null;
114
118
  const allProviders = params.providers ?? getProviders();
@@ -153,6 +157,7 @@ async function fetchProviderWithCache(params) {
153
157
  ctx,
154
158
  ttlMs,
155
159
  bypassCache: params.bypassCache,
160
+ forceRefresh: params.forceRefresh,
156
161
  });
157
162
  }
158
163
  function makeProviderFetchFailure(provider) {
@@ -174,6 +179,7 @@ export async function fetchProviderResults(params) {
174
179
  ctx: params.ctx,
175
180
  ttlMs: params.ttlMs,
176
181
  bypassCache: params.bypassCache,
182
+ forceRefresh: params.forceRefresh,
177
183
  })));
178
184
  return settled.map((result, index) => result.status === "fulfilled"
179
185
  ? result.value
@@ -256,6 +262,7 @@ export async function collectQuotaDashboardProviderResults(params) {
256
262
  config: { ...params.config, onlyCurrentModel: false },
257
263
  request: undefined,
258
264
  surfaceExplicitProviderIssues: false,
265
+ includeProviderScope: true,
259
266
  });
260
267
  return result.providerResults;
261
268
  }
@@ -266,6 +273,9 @@ function getExplicitNoDataMessage(provider) {
266
273
  if (provider.id === "anthropic") {
267
274
  return getAnthropicNoDataMessage();
268
275
  }
276
+ if (provider.id === "claude-agent") {
277
+ return getClaudeAgentNoDataMessage();
278
+ }
269
279
  return "Not configured";
270
280
  }
271
281
  function shouldSurfaceNoDataMessage(params) {
@@ -276,7 +286,8 @@ function shouldSurfaceNoDataMessage(params) {
276
286
  if (!isAutoMode) {
277
287
  return true;
278
288
  }
279
- return activeProviderCount === 1 && (provider.id === "anthropic" || provider.id === "cursor");
289
+ return (activeProviderCount === 1 &&
290
+ (provider.id === "anthropic" || provider.id === "claude-agent" || provider.id === "cursor"));
280
291
  }
281
292
  function buildExplicitProviderIssues(params) {
282
293
  if (!params.enabled || params.selection.isAutoMode)
@@ -332,6 +343,8 @@ export async function collectQuotaRenderData(params) {
332
343
  data: null,
333
344
  };
334
345
  }
346
+ if (params.forceProviderRefresh)
347
+ selection.ctx.operationCache?.set(QUOTA_FORCE_REFRESH, true);
335
348
  if (selection.waitingForCurrentSelection) {
336
349
  retainQuotaTelemetryProviders({
337
350
  token: selection.ctx.config.telemetryToken,
@@ -375,12 +388,22 @@ export async function collectQuotaRenderData(params) {
375
388
  data: packageQuotaRenderData({ entries: [], errors: explicitProviderIssues }),
376
389
  };
377
390
  }
391
+ const initialScopes = params.includeProviderScope
392
+ ? await Promise.all(active.map((provider) => getQuotaProviderResultScope(provider, selection.ctx)))
393
+ : [];
378
394
  const results = await fetchProviderResults({
379
395
  providers: active,
380
396
  ctx: selection.ctx,
381
397
  ttlMs: params.config.minIntervalMs,
382
398
  bypassCache: params.bypassProviderCache,
399
+ forceRefresh: params.forceProviderRefresh,
383
400
  });
401
+ const finalScopes = params.includeProviderScope
402
+ ? await Promise.all(active.map((provider) => getQuotaProviderResultScope(provider, provider.cachePolicy?.kind === "resolved-auth" &&
403
+ provider.cachePolicy.revalidateWithCycleCache
404
+ ? selection.ctx
405
+ : { ...selection.ctx, operationCache: undefined })))
406
+ : [];
384
407
  const style = params.formatStyle ?? params.config.formatStyle;
385
408
  const projectionOptions = {
386
409
  quotaProjection: params.config.quotaProjection,
@@ -450,6 +473,9 @@ export async function collectQuotaRenderData(params) {
450
473
  providerResults: active.map((provider, index) => ({
451
474
  providerId: provider.id,
452
475
  result: results[index],
476
+ ...(initialScopes[index] && initialScopes[index] === finalScopes[index]
477
+ ? { cacheScope: initialScopes[index] }
478
+ : {}),
453
479
  })),
454
480
  attemptedAny,
455
481
  hasExplicitProviderIssues,