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
@@ -2,6 +2,7 @@
2
2
  * OpenAI (Plus/Pro) provider wrapper.
3
3
  */
4
4
  import { OPENAI_CREDITS_ROW_KEY, OPENAI_CREDITS_ROW_LABEL, OPENAI_CREDITS_ROW_RESULT_TYPE, OPENAI_RESETS_ROW_KEY, OPENAI_RESETS_ROW_LABEL, OPENAI_RESETS_ROW_RESULT_TYPE, } from "../contracts/openai-quota.js";
5
+ import { windowSemantic } from "../lib/entries.js";
5
6
  import { DEFAULT_OPENAI_AUTH_CACHE_MAX_AGE_MS, hasOpenAIOAuthCached, OPENAI_AUTH_SOURCE_KEYS, queryOpenAIQuota, resolveOpenAIOAuth, } from "../lib/openai.js";
6
7
  import { credentialRowAuthEntry, formatCredentialDisplayNames, readCredentialRows, } from "../lib/opencode-auth.js";
7
8
  import { isCanonicalProviderAvailable } from "../lib/provider-availability.js";
@@ -17,23 +18,6 @@ const TOKEN_SHARING_METHOD_ID = "chatgpt-token-sharing";
17
18
  function isTokenSharingLogin(row) {
18
19
  return row.value.methodID === TOKEN_SHARING_METHOD_ID;
19
20
  }
20
- const OPENAI_WINDOW_ROW_KEYS = {
21
- "5h:": "window:five_hour",
22
- "Weekly:": "window:week",
23
- "Monthly:": "window:month",
24
- "Code Review:": "window:code_review",
25
- };
26
- /**
27
- * Percent-only window rows carry no typed `semantic`, so they get stable
28
- * explicit `rowKey`s by window (the fallback aggregate row when no window
29
- * exists); labels themselves are never used as ids.
30
- */
31
- function withOpenAiWindowRowKeys(entries) {
32
- return entries.map((entry) => ({
33
- ...entry,
34
- rowKey: (entry.label ? OPENAI_WINDOW_ROW_KEYS[entry.label] : undefined) ?? "aggregate",
35
- }));
36
- }
37
21
  const OPENAI_OPTIONAL_ACCOUNTING = {
38
22
  acquisitionMethod: "remote_api",
39
23
  ownership: "maintained",
@@ -172,7 +156,7 @@ export const openaiProvider = {
172
156
  credits: result.credits,
173
157
  bankedResets: result.bankedResets,
174
158
  });
175
- const windowEntries = withOpenAiWindowRowKeys(groupedPercentWindowEntries({
159
+ const windowEntries = groupedPercentWindowEntries({
176
160
  group,
177
161
  accounting: {
178
162
  resultType: "rate_limit",
@@ -182,17 +166,34 @@ export const openaiProvider = {
182
166
  ...(options.sourceId ? { sourceId: options.sourceId } : {}),
183
167
  },
184
168
  windows: [
185
- { window: result.windows.hourly, suffix: "5h", label: "5h:" },
186
- { window: result.windows.weekly, suffix: "Weekly", label: "Weekly:" },
187
- { window: result.windows.monthly, suffix: "Monthly", label: "Monthly:" },
169
+ {
170
+ window: result.windows.hourly,
171
+ suffix: "5h",
172
+ label: "5h:",
173
+ semantic: windowSemantic("five_hour"),
174
+ },
175
+ {
176
+ window: result.windows.weekly,
177
+ suffix: "Weekly",
178
+ label: "Weekly:",
179
+ semantic: windowSemantic("week"),
180
+ },
181
+ {
182
+ window: result.windows.monthly,
183
+ suffix: "Monthly",
184
+ label: "Monthly:",
185
+ semantic: windowSemantic("month"),
186
+ },
188
187
  {
189
188
  window: result.windows.codeReview,
190
189
  suffix: "Code Review",
191
190
  label: "Code Review:",
191
+ semantic: windowSemantic("code_review"),
192
192
  },
193
193
  ],
194
- fallbackWhenEmpty: optionalEntries.length === 0,
195
- }));
194
+ // A successful response with no reported window is not a 0% quota.
195
+ fallbackWhenEmpty: false,
196
+ });
196
197
  return attemptedResult([...windowEntries, ...optionalEntries], [], {
197
198
  singleWindowDisplayName: group,
198
199
  });
@@ -1,4 +1,5 @@
1
1
  import { createHash } from "node:crypto";
2
+ import { windowSemantic } from "../lib/entries.js";
2
3
  import { credentialRowAuthEntry, formatCredentialDisplayNames, readCredentialRows, scrubCredentialErrorText, selectConnectionCredentialRows, } from "../lib/opencode-auth.js";
3
4
  import { consoleBaseUrl, consoleUnexpectedErrorText, resolveOpenCodeConsoleAuthAccounts, } from "../lib/opencode-console-auth.js";
4
5
  import { queryOpenCodeGoConsoleStatus, queryOpenCodeGoQuota } from "../lib/opencode-go.js";
@@ -13,11 +14,11 @@ const OPENCODE_GO_WINDOW_LABELS = {
13
14
  weekly: { name: `${OPENCODE_GO_PROVIDER_LABEL} Weekly`, label: "Weekly:" },
14
15
  monthly: { name: `${OPENCODE_GO_PROVIDER_LABEL} Monthly`, label: "Monthly:" },
15
16
  };
16
- /** Stable explicit row keys (metric + window) for the percent-only window rows. */
17
- const OPENCODE_GO_WINDOW_ROW_KEYS = {
18
- rolling: "window:five_hour",
19
- weekly: "window:week",
20
- monthly: "window:month",
17
+ /** Typed window metrics for the percent-only window rows. */
18
+ const OPENCODE_GO_WINDOW_METRICS = {
19
+ rolling: "five_hour",
20
+ weekly: "week",
21
+ monthly: "month",
21
22
  };
22
23
  const notSubscribedCredentialFingerprints = new Set();
23
24
  export function __resetOpenCodeGoNotSubscribedForTests() {
@@ -60,7 +61,7 @@ function buildOpenCodeGoEntries(result, selectedWindows, group = OPENCODE_GO_PRO
60
61
  name: `${group} ${labels.label.slice(0, -1)}`,
61
62
  group,
62
63
  label: labels.label,
63
- rowKey: OPENCODE_GO_WINDOW_ROW_KEYS[window],
64
+ semantic: windowSemantic(OPENCODE_GO_WINDOW_METRICS[window]),
64
65
  percentRemaining: usage.percentRemaining,
65
66
  ...(usage.resetTimeIso !== undefined ? { resetTimeIso: usage.resetTimeIso } : {}),
66
67
  });
@@ -192,6 +193,7 @@ async function fetchOpenCodeGoConsoleAccounts(ctx, windows, consoleAccounts) {
192
193
  retryable: result.retryable,
193
194
  sourceId: account.sourceId,
194
195
  failureCategory: result.failureCategory,
196
+ ...(result.retryAtMs !== undefined ? { retryAtMs: result.retryAtMs } : {}),
195
197
  });
196
198
  fetchErrorsBySourceId.set(account.sourceId, result.error);
197
199
  accounts.push(consoleAccountDescriptor(account));
@@ -352,6 +354,7 @@ async function fetchOpenCodeGoLegacy(ctx, diagnostics, statusDetails) {
352
354
  retryable: result.retryable,
353
355
  sourceId: row.id,
354
356
  failureCategory: result.failureCategory,
357
+ ...(result.retryAtMs !== undefined ? { retryAtMs: result.retryAtMs } : {}),
355
358
  });
356
359
  }
357
360
  const attemptedSourceIds = new Set([
@@ -401,6 +404,7 @@ async function fetchOpenCodeGoLegacy(ctx, diagnostics, statusDetails) {
401
404
  return withStatusDetails(attemptedErrorResult(OPENCODE_GO_PROVIDER_LABEL, result.error, {
402
405
  retryable: result.retryable,
403
406
  failureCategory: result.failureCategory,
407
+ ...(result.retryAtMs !== undefined ? { retryAtMs: result.retryAtMs } : {}),
404
408
  }), [...baseStatusDetails, { key: "live_fetch_error", value: result.error }]);
405
409
  }
406
410
  const liveDetails = OPENCODE_GO_WINDOW_ORDER.map((window) => {
@@ -98,7 +98,7 @@ function buildZenEntries(params) {
98
98
  info: "Workspace monthly spend (includes Go API equivalent)",
99
99
  semantic: {
100
100
  metric: { kind: "window", window: "month" },
101
- prominence: "primary",
101
+ prominence: "supplementary",
102
102
  },
103
103
  quantity: { decimal: zenUsdDecimal(monthlyUsageUsd), unit: USD_UNIT },
104
104
  });
@@ -208,6 +208,7 @@ async function fetchOpenCodeZenConsoleAccounts(ctx, consoleAccounts) {
208
208
  ...(result.failureCategory !== undefined
209
209
  ? { failureCategory: result.failureCategory }
210
210
  : {}),
211
+ ...(result.retryAtMs !== undefined ? { retryAtMs: result.retryAtMs } : {}),
211
212
  });
212
213
  statusDetails.push({
213
214
  key: `live_fetch_error:${account.sourceId}`,
@@ -230,6 +231,7 @@ async function fetchOpenCodeZenConsoleAccounts(ctx, consoleAccounts) {
230
231
  ...(optionalError.failureCategory !== undefined
231
232
  ? { failureCategory: optionalError.failureCategory }
232
233
  : {}),
234
+ ...(optionalError.retryAtMs !== undefined ? { retryAtMs: optionalError.retryAtMs } : {}),
233
235
  });
234
236
  }
235
237
  }
@@ -69,6 +69,7 @@ export const openRouterProvider = {
69
69
  errors.push({
70
70
  label: account.label,
71
71
  message: result.error,
72
+ ...(result.retryAtMs !== undefined ? { retryAtMs: result.retryAtMs } : {}),
72
73
  failureCategory: result.failureCategory,
73
74
  ...(account.sourceId ? { sourceId: account.sourceId } : {}),
74
75
  });
@@ -2,7 +2,7 @@ import { mapWithConcurrency } from "../lib/map-with-concurrency.js";
2
2
  import { customQuotaProviderDefinitions, QUOTA_PROVIDERS_AGGREGATE_ID, resolveQuotaProviderSessionModelIdentity, selectEligibleQuotaProviderDefinitions, } from "../lib/quota-providers.js";
3
3
  import { collectLocalQuotaProviderEstimate, inspectLocalQuotaProviderState, } from "../lib/quota-providers-local.js";
4
4
  import { fetchRemoteQuotaProvider, QUOTA_PROVIDER_CONCURRENCY, resolveQuotaProviderApiKey, } from "../lib/quota-providers-remote.js";
5
- import { fetchQuotaProviderResult } from "../lib/quota-state.js";
5
+ import { fetchQuotaProviderResult, QUOTA_FORCE_REFRESH } from "../lib/quota-state.js";
6
6
  import { resolveQuotaProviderDefinitionAuthIdentity } from "./cache-policies.js";
7
7
  export const QUOTA_PROVIDERS_PROVIDER_ID = QUOTA_PROVIDERS_AGGREGATE_ID;
8
8
  export const selectEligibleQuotaProviders = selectEligibleQuotaProviderDefinitions;
@@ -19,6 +19,12 @@ function matchesConfiguredCurrentSelection(model, context) {
19
19
  async function getAvailableProviderIds(ctx) {
20
20
  return ctx.resolveRuntimeProviderIds();
21
21
  }
22
+ function configuredDefinitions(ctx) {
23
+ return ctx.config.quotaProviders ?? [];
24
+ }
25
+ function selectedDefinitionsStillCurrent(selected, current) {
26
+ return selected.filter((definition) => current.some((candidate) => candidate.id === definition.id));
27
+ }
22
28
  function buildDiagnosticIdentity(definition) {
23
29
  return {
24
30
  sourceId: definition.id,
@@ -93,6 +99,7 @@ async function executeRemote(definition, requestTimeoutMs) {
93
99
  {
94
100
  label: definition.label,
95
101
  message: result.error,
102
+ ...(result.retryAtMs !== undefined ? { retryAtMs: result.retryAtMs } : {}),
96
103
  ...(result.failureCategory !== undefined
97
104
  ? { failureCategory: result.failureCategory }
98
105
  : {}),
@@ -135,7 +142,7 @@ async function executeRemoteWithCache(definition, ctx) {
135
142
  isAvailable: async () => true,
136
143
  cachePolicy: {
137
144
  kind: "resolved-auth",
138
- resolveIdentity: () => resolveQuotaProviderDefinitionAuthIdentity(definition),
145
+ resolveIdentity: (_cacheCtx) => resolveQuotaProviderDefinitionAuthIdentity(definition),
139
146
  },
140
147
  fetch: async () => {
141
148
  const result = await executeRemote(definition, ctx.config.requestTimeoutMs);
@@ -157,6 +164,7 @@ async function executeRemoteWithCache(definition, ctx) {
157
164
  },
158
165
  },
159
166
  ttlMs: ctx.config.providerCacheTtlMs ?? 0,
167
+ forceRefresh: ctx.operationCache?.get(QUOTA_FORCE_REFRESH) === true,
160
168
  });
161
169
  return {
162
170
  entries: result.entries,
@@ -227,7 +235,7 @@ async function executeDefinition(definition, ctx) {
227
235
  export const quotaProvidersProvider = {
228
236
  id: QUOTA_PROVIDERS_PROVIDER_ID,
229
237
  async isAvailable(ctx) {
230
- const definitions = ctx.config.quotaProviders ?? [];
238
+ const definitions = configuredDefinitions(ctx);
231
239
  if (customQuotaProviderDefinitions(definitions).length === 0)
232
240
  return false;
233
241
  const availableProviderIds = await getAvailableProviderIds(ctx);
@@ -243,12 +251,15 @@ export const quotaProvidersProvider = {
243
251
  return matchesConfiguredCurrentSelection(model, context);
244
252
  },
245
253
  async fetch(ctx, cacheContext) {
246
- const definitions = ctx.config.quotaProviders ?? [];
254
+ const definitions = configuredDefinitions(ctx);
247
255
  if (customQuotaProviderDefinitions(definitions).length === 0) {
248
256
  return { attempted: false, entries: [], errors: [] };
249
257
  }
250
258
  let selected = cacheContext?.runtimeEligibleQuotaProviders;
251
- if (!selected) {
259
+ if (selected) {
260
+ selected = selectedDefinitionsStillCurrent(selected, definitions);
261
+ }
262
+ else {
252
263
  let availableProviderIds;
253
264
  try {
254
265
  availableProviderIds = await getAvailableProviderIds(ctx);
@@ -10,6 +10,7 @@ import { alibabaTokenPlanProvider } from "./alibaba-token-plan.js";
10
10
  import { anthropicProvider } from "./anthropic.js";
11
11
  import { PROVIDER_CACHE_POLICIES } from "./cache-policies.js";
12
12
  import { chutesProvider } from "./chutes.js";
13
+ import { claudeAgentProvider } from "./claude-agent.js";
13
14
  import { copilotProvider } from "./copilot.js";
14
15
  import { cursorProvider } from "./cursor.js";
15
16
  import { deepseekProvider } from "./deepseek.js";
@@ -32,6 +33,7 @@ import { zaiProvider } from "./zai.js";
32
33
  import { zhipuProvider } from "./zhipu.js";
33
34
  const PROVIDERS_BY_ID = {
34
35
  anthropic: anthropicProvider,
36
+ "claude-agent": claudeAgentProvider,
35
37
  copilot: copilotProvider,
36
38
  openai: openaiProvider,
37
39
  openrouter: openRouterProvider,
@@ -1,10 +1,12 @@
1
- import type { ProviderFailureCategory } from "../contracts/provider-failure.js";
2
- import type { AccountingMetadata, FixedWindowProjectionEvidence, QuotaProviderPresentation, QuotaProviderResult, QuotaProviderStatusDetail, QuotaToastEntry, QuotaToastError } from "../lib/entries.js";
1
+ import type { ProviderFailureCategory, QuotaAttemptOutcome } from "../contracts/provider-failure.js";
2
+ import type { AccountingMetadata, AccountingSemantic, FixedWindowProjectionEvidence, QuotaProviderPresentation, QuotaProviderResult, QuotaProviderStatusDetail, QuotaToastEntry, QuotaToastError } from "../lib/entries.js";
3
3
  export declare function notAttemptedResult(): QuotaProviderResult;
4
4
  export declare function attemptedResult(entries: QuotaToastEntry[], errors?: QuotaToastError[], presentation?: QuotaProviderPresentation): QuotaProviderResult;
5
5
  export declare function attemptedErrorResult(label: string, message: string, options?: {
6
6
  retryable?: boolean;
7
7
  failureCategory?: ProviderFailureCategory;
8
+ retryAtMs?: number;
9
+ attemptOutcome?: QuotaAttemptOutcome;
8
10
  }): QuotaProviderResult;
9
11
  export declare function statusDetailsFromRecord(values: Readonly<Record<string, string | undefined>>): QuotaProviderStatusDetail[];
10
12
  export declare function configStatusDetails(diagnostics: {
@@ -40,6 +42,7 @@ export declare function mapNullableProviderResult<TResult extends {
40
42
  success: false;
41
43
  error: string;
42
44
  retryable?: boolean;
45
+ retryAtMs?: number;
43
46
  failureCategory?: ProviderFailureCategory;
44
47
  } | null>(result: TResult, params: {
45
48
  errorLabel: string;
@@ -59,6 +62,7 @@ export declare function groupedPercentWindowEntries(params: {
59
62
  };
60
63
  suffix: string;
61
64
  label: string;
65
+ semantic?: AccountingSemantic;
62
66
  }>;
63
67
  fallbackWhenEmpty?: boolean;
64
68
  }): QuotaToastEntry[];
@@ -17,6 +17,8 @@ export function attemptedErrorResult(label, message, options = {}) {
17
17
  label,
18
18
  message,
19
19
  ...(options.retryable === true ? { retryable: true } : {}),
20
+ ...(options.retryAtMs !== undefined ? { retryAtMs: options.retryAtMs } : {}),
21
+ ...(options.attemptOutcome !== undefined ? { attemptOutcome: options.attemptOutcome } : {}),
20
22
  ...(options.failureCategory !== undefined
21
23
  ? { failureCategory: options.failureCategory }
22
24
  : {}),
@@ -97,6 +99,7 @@ export function mapNullableProviderResult(result, params) {
97
99
  if (!result.success) {
98
100
  return attemptedErrorResult(params.errorLabel, result.error, {
99
101
  ...(result.retryable === true ? { retryable: true } : {}),
102
+ ...(result.retryAtMs !== undefined ? { retryAtMs: result.retryAtMs } : {}),
100
103
  ...((result.failureCategory ?? params.failureCategory) !== undefined
101
104
  ? { failureCategory: result.failureCategory ?? params.failureCategory }
102
105
  : {}),
@@ -106,7 +109,7 @@ export function mapNullableProviderResult(result, params) {
106
109
  }
107
110
  export function groupedPercentWindowEntries(params) {
108
111
  const entries = [];
109
- for (const { window, suffix, label } of params.windows) {
112
+ for (const { window, suffix, label, semantic } of params.windows) {
110
113
  if (!window)
111
114
  continue;
112
115
  entries.push({
@@ -114,6 +117,9 @@ export function groupedPercentWindowEntries(params) {
114
117
  name: `${params.group} ${suffix}`,
115
118
  group: params.group,
116
119
  label,
120
+ ...(semantic
121
+ ? { semantic: { metric: { ...semantic.metric }, prominence: semantic.prominence } }
122
+ : {}),
117
123
  percentRemaining: window.percentRemaining,
118
124
  resetTimeIso: window.resetTimeIso,
119
125
  ...(window.fixedWindow ? { fixedWindow: { ...window.fixedWindow } } : {}),
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * Synthetic provider wrapper.
3
3
  */
4
+ import { windowSemantic } from "../lib/entries.js";
4
5
  import { isCanonicalProviderAvailable } from "../lib/provider-availability.js";
5
6
  import { modelProviderIncludesAny } from "../lib/provider-model-matching.js";
6
7
  import { getSyntheticKeyDiagnostics, hasSyntheticApiKeyConfigured, querySyntheticQuota, } from "../lib/synthetic.js";
@@ -27,6 +28,7 @@ function toSyntheticEntry(params) {
27
28
  name: `Synthetic ${params.suffix}`,
28
29
  group: "Synthetic",
29
30
  label: params.label,
31
+ semantic: windowSemantic(params.semanticWindow),
30
32
  percentRemaining: params.window.percentRemaining,
31
33
  right,
32
34
  resetTimeIso: params.window.resetTimeIso,
@@ -61,11 +63,13 @@ export const syntheticProvider = {
61
63
  window: result.windows.fiveHour,
62
64
  suffix: "5h",
63
65
  label: "5h:",
66
+ semanticWindow: "five_hour",
64
67
  }),
65
68
  toSyntheticEntry({
66
69
  window: result.windows.weekly,
67
70
  suffix: "Weekly",
68
71
  label: "Weekly:",
72
+ semanticWindow: "week",
69
73
  currency: true,
70
74
  }),
71
75
  ], [], {
@@ -1,22 +1,23 @@
1
1
  /**
2
2
  * xAI SuperGrok provider wrapper.
3
3
  */
4
+ import { windowSemantic } from "../lib/entries.js";
4
5
  import { credentialRowAuthEntry, formatCredentialDisplayNames, readCredentialRows, } from "../lib/opencode-auth.js";
5
6
  import { isCanonicalProviderAvailable } from "../lib/provider-availability.js";
6
7
  import { modelProviderMatchesRuntimeId } from "../lib/provider-model-matching.js";
7
8
  import { DEFAULT_XAI_AUTH_CACHE_MAX_AGE_MS, hasXaiOAuthCached, periodKindLabel, queryXaiQuota, resolveXaiOAuth, } from "../lib/xai.js";
8
9
  import { attemptedResult, mapNullableProviderResult } from "./result-helpers.js";
9
- /** Stable explicit row key for the single percent row (never the display label). */
10
- function xaiWindowRowKey(kind) {
10
+ /** Typed identity for the single provider-defined period row (never its label). */
11
+ function xaiWindowSemantic(kind) {
11
12
  switch (kind) {
12
13
  case "weekly":
13
- return "window:week";
14
+ return windowSemantic("week");
14
15
  case "monthly":
15
- return "window:month";
16
+ return windowSemantic("month");
16
17
  case "daily":
17
- return "window:day";
18
+ return windowSemantic("day");
18
19
  default:
19
- return "named:period";
20
+ return { metric: { kind: "named", name: "period" }, prominence: "primary" };
20
21
  }
21
22
  }
22
23
  export const xaiProvider = {
@@ -79,7 +80,7 @@ export const xaiProvider = {
79
80
  name: `${group} ${period}`,
80
81
  group,
81
82
  label: `${period}:`,
82
- rowKey: xaiWindowRowKey(result.window.kind),
83
+ semantic: xaiWindowSemantic(result.window.kind),
83
84
  percentRemaining: result.window.percentRemaining,
84
85
  resetTimeIso: result.window.resetTimeIso,
85
86
  },
@@ -107,7 +108,7 @@ export const xaiProvider = {
107
108
  name: `${result.label} ${period}`,
108
109
  group: result.label,
109
110
  label: `${period}:`,
110
- rowKey: xaiWindowRowKey(result.window.kind),
111
+ semantic: xaiWindowSemantic(result.window.kind),
111
112
  percentRemaining: result.window.percentRemaining,
112
113
  resetTimeIso: result.window.resetTimeIso,
113
114
  ...(result.window.fixedWindow
package/dist/rpc.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
- * The plugin RPC definitions. `QuotaRpc` is the inherited TUI contract (still
3
- * used by the retained TUI source, but no longer registered by the GUI-only
4
- * server plugin). `DashboardRpc` is the Stage 3 typed dashboard contract the
2
+ * The plugin RPC definitions. `QuotaRpc` is a legacy terminal-client contract
3
+ * retained for compatibility, but is not registered by the GUI-only server
4
+ * plugin. `DashboardRpc` is the typed dashboard contract the
5
5
  * server plugin registers for native clients. Imports from `@opencode/*` stay
6
6
  * type-only, so loading this file loads no OpenCode package.
7
7
  */
@@ -106,6 +106,8 @@ export type DashboardRpcImportApplyInput = {
106
106
  };
107
107
  export type DashboardRpcWatchInput = {
108
108
  scope: DashboardRpcViewScope;
109
+ /** Optional for older callers; Native uses it to correlate the source cutover snapshot. */
110
+ attemptNonce?: string;
109
111
  };
110
112
  export type DashboardRpcWatchOutput = {
111
113
  active: boolean;
@@ -113,10 +115,120 @@ export type DashboardRpcWatchOutput = {
113
115
  export type DashboardRpcOpenSettingsOutput = {
114
116
  opened: true;
115
117
  };
118
+ export type DashboardRpcCacheObserverEvent = {
119
+ type: "session.step.started";
120
+ created: number;
121
+ data: {
122
+ sessionID: string;
123
+ assistantMessageID: string;
124
+ /** OpenCode's selected model identity, not the resolved HTTP request route. */
125
+ model: {
126
+ providerID: string;
127
+ id: string;
128
+ variant?: string;
129
+ };
130
+ /** Captured before `llm.stream`; event.created is emitted at first output instead. */
131
+ started?: number;
132
+ connectionMethod?: "oauth" | "key" | "external";
133
+ };
134
+ } | {
135
+ type: "session.step.ended";
136
+ created: number;
137
+ data: {
138
+ sessionID: string;
139
+ assistantMessageID: string;
140
+ tokens: {
141
+ input?: number;
142
+ cache?: {
143
+ read?: number;
144
+ write?: number;
145
+ };
146
+ };
147
+ };
148
+ } | {
149
+ /**
150
+ * One completed Claude Agent invocation whose cache writes were observed as 1-hour-only.
151
+ * Carries no transcript content, path or native id.
152
+ */
153
+ type: "session.cache.ttl";
154
+ created: number;
155
+ data: {
156
+ sessionID: string;
157
+ assistantMessageID: string;
158
+ ttlMs: 3_600_000;
159
+ };
160
+ } | {
161
+ type: "session.cache.warming";
162
+ data: {
163
+ sessionID: string;
164
+ dispatchMs: number;
165
+ evidence: "warming-inferred";
166
+ };
167
+ } | {
168
+ type: "session.created";
169
+ data: {
170
+ sessionID: string;
171
+ parentID: string;
172
+ };
173
+ } | {
174
+ type: "session.forked";
175
+ data: {
176
+ sessionID: string;
177
+ parentID?: string;
178
+ };
179
+ } | {
180
+ type: "session.compaction.ended" | "session.deleted";
181
+ data: {
182
+ sessionID: string;
183
+ };
184
+ } | {
185
+ /**
186
+ * Authoritative session execution state, projected from the host's own
187
+ * `session.status`, `session.idle` and `session.execution.*` events.
188
+ * Carries no message, error or credential content.
189
+ */
190
+ type: "session.status";
191
+ created: number;
192
+ data: {
193
+ sessionID: string;
194
+ state: "busy" | "idle";
195
+ };
196
+ } | {
197
+ /**
198
+ * Narrow session-identity update, projected from the host's own
199
+ * `session.renamed`, `session.agent.selected` and `session.model.selected`
200
+ * events. Only display-identity fields are carried, and only those the
201
+ * source event contains; `created` is the host timestamp that dates the
202
+ * change for recency ordering.
203
+ */
204
+ type: "session.metadata";
205
+ created: number;
206
+ data: {
207
+ sessionID: string;
208
+ title?: string;
209
+ agent?: string;
210
+ model?: {
211
+ providerID: string;
212
+ id: string;
213
+ variant?: string;
214
+ };
215
+ };
216
+ } | {
217
+ type: "source.status";
218
+ created: number;
219
+ data: {
220
+ state: "unverified" | "observed" | "unavailable" | "stopped";
221
+ /** Present only on a source snapshot requested by an active watch attempt. */
222
+ attemptNonce?: string;
223
+ /** Opaque identity of the setup-owned host-event source that emitted this state. */
224
+ sourceBinding?: string;
225
+ };
226
+ };
116
227
  export type DashboardRpcEventData = {
117
- topic: DashboardEventTopic;
228
+ topic: DashboardEventTopic | "cache.observer";
118
229
  at: number;
119
230
  scope?: "visibility";
231
+ cacheObserverEvent?: DashboardRpcCacheObserverEvent;
120
232
  };
121
233
  export type DashboardRpcQuotaNotificationKind = "low" | "exhausted" | "reset" | "provider-error";
122
234
  /**
@@ -153,9 +265,8 @@ declare const DASHBOARD_RPC_ERRORS: {
153
265
  export type DashboardRpcErrorCode = keyof typeof DASHBOARD_RPC_ERRORS;
154
266
  export type DashboardRpcMethod = (typeof DashboardRpc.methods)[keyof typeof DashboardRpc.methods];
155
267
  /**
156
- * The explicit typed dashboard RPC. Every method maps to one `DashboardDataSource`
157
- * operation (plus the transport-lifecycle `watch` method); there is deliberately
158
- * no generic dispatch/call method.
268
+ * The explicit typed dashboard RPC. Methods map to a dashboard data-source or
269
+ * user settings-store operation (plus `watch`); there is no generic dispatch.
159
270
  */
160
271
  export declare const DashboardRpc: {
161
272
  id: string;
@@ -185,7 +296,9 @@ export declare const DashboardRpc: {
185
296
  };
186
297
  };
187
298
  quota: {
188
- input: QuotaRpcSchema<DashboardRpcNoInput>;
299
+ input: QuotaRpcSchema<{
300
+ refresh?: boolean;
301
+ }>;
189
302
  output: QuotaRpcSchema<import("./contracts/dashboard.js").QuotaSnapshot>;
190
303
  errors: {
191
304
  readonly "bad-request": QuotaRpcSchema<DashboardRpcErrorDetails>;
@@ -203,6 +316,7 @@ export declare const DashboardRpc: {
203
316
  home: {
204
317
  input: QuotaRpcSchema<{
205
318
  range: RangeKey;
319
+ background?: boolean;
206
320
  }>;
207
321
  output: QuotaRpcSchema<import("./contracts/dashboard.js").HomeSnapshot>;
208
322
  errors: {
@@ -391,5 +505,12 @@ export declare const DASHBOARD_HEALTH: DashboardHealth;
391
505
  * unsafe payload is dropped before it can reach a window's presenter.
392
506
  */
393
507
  export declare function isDashboardRpcQuotaNotificationData(value: unknown): value is DashboardRpcQuotaNotificationData;
508
+ /** Strict runtime validation for the narrow, content-free cache observer event DTO. */
509
+ export declare function isDashboardRpcCacheObserverEvent(value: unknown): value is DashboardRpcCacheObserverEvent;
510
+ /** Strict guard for cache observer DTOs wrapped in the existing invalidation event envelope. */
511
+ export declare function isDashboardRpcCacheObserverEventData(value: unknown): value is DashboardRpcEventData & {
512
+ topic: "cache.observer";
513
+ cacheObserverEvent: DashboardRpcCacheObserverEvent;
514
+ };
394
515
  export {};
395
516
  //# sourceMappingURL=rpc.d.ts.map