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,215 @@
1
+ /**
2
+ * Claude Agent provider: OpenCode's native Claude Agent integration, backed by the installed Claude
3
+ * CLI login. It is independent of OpenCode's Anthropic logins (see `./anthropic.ts`); it is the
4
+ * only provider that launches the Claude CLI.
5
+ */
6
+ import { CLAUDE_AGENT_RESETS_ROW_KEY } from "../contracts/openai-quota.js";
7
+ import { getAnthropicDiagnostics, hasAnthropicCredentialsConfigured } from "../lib/anthropic.js";
8
+ import { QUOTA_FORCE_REFRESH } from "../lib/entries.js";
9
+ import { isAnyProviderIdAvailable } from "../lib/provider-availability.js";
10
+ import { resolveQuotaProviderSessionModelIdentity } from "../lib/quota-providers.js";
11
+ import { anthropicQuotaEntries } from "./anthropic.js";
12
+ import { attemptedErrorResult, attemptedResult, statusDetailsFromRecord, withStatusDetails, } from "./result-helpers.js";
13
+ /** `claude-agent` is OpenCode's native integration; `claude-code` is its legacy runtime alias. */
14
+ export const CLAUDE_AGENT_RUNTIME_IDS = ["claude-agent", "claude-code"];
15
+ const CLAUDE_AGENT_GROUP = "Claude Agent";
16
+ /** Always the OAuth-reported value: even beside CLI-local windows, resets come from the usage API. */
17
+ function claudeAgentResetsEntry(resets, observedAtMs) {
18
+ return {
19
+ kind: "value",
20
+ accounting: {
21
+ resultType: "status",
22
+ acquisitionMethod: "remote_api",
23
+ ownership: "maintained",
24
+ authority: "provider_reported",
25
+ ...(observedAtMs !== undefined
26
+ ? { observedAtIso: new Date(observedAtMs).toISOString() }
27
+ : {}),
28
+ },
29
+ name: `${CLAUDE_AGENT_GROUP} Resets`,
30
+ group: CLAUDE_AGENT_GROUP,
31
+ label: "Resets:",
32
+ rowKey: CLAUDE_AGENT_RESETS_ROW_KEY,
33
+ value: `${resets.availableCount} available`,
34
+ bankedResets: {
35
+ availableCount: resets.availableCount,
36
+ credits: resets.credits.map((credit) => ({
37
+ ...(credit.expiresAtIso !== undefined ? { expiresAtIso: credit.expiresAtIso } : {}),
38
+ })),
39
+ },
40
+ };
41
+ }
42
+ export function getClaudeAgentNoDataMessage() {
43
+ return "Quota unavailable via local Claude CLI";
44
+ }
45
+ function safeDiagnosticMessage(diagnostics) {
46
+ // A probe that timed out says nothing about the login; keep the token and the card, show the error.
47
+ if (diagnostics.probeFailure === true && diagnostics.quotaSource === "none")
48
+ return "Claude CLI did not respond. Retry.";
49
+ if (diagnostics.failureCategory === "provider_api")
50
+ return "Claude quota request failed.";
51
+ if (diagnostics.storedAccessTokenExpired)
52
+ return "Claude's stored access token has expired. Run any `claude` command to refresh it, then Retry.";
53
+ // "credentials" is only assigned after the CLI reported a verified login, so this is the usage
54
+ // endpoint rejecting the stored token, not proof that the login is invalid.
55
+ if (diagnostics.failureCategory === "credentials")
56
+ return "Claude CLI reports you are signed in, but the usage request was rejected. Retry; if it persists, run `claude auth login`.";
57
+ if (!diagnostics.installed)
58
+ return "Claude CLI is unavailable.";
59
+ if (diagnostics.authStatus === "unauthenticated")
60
+ return "Claude is not authenticated. Run `claude auth login` and try again.";
61
+ if (diagnostics.authStatus === "unknown")
62
+ return "Claude authentication could not be verified. Retry; if it persists, run `claude auth login`.";
63
+ return "Claude Agent usage is unavailable.";
64
+ }
65
+ /** The Claude Agent route selected by `onlyCurrentModel`, if any. */
66
+ export function getClaudeAgentRuntimeProviderId(ctx) {
67
+ if (ctx.config?.onlyCurrentModel !== true)
68
+ return undefined;
69
+ const currentProviderId = (ctx.config?.currentProviderID ??
70
+ resolveQuotaProviderSessionModelIdentity({ currentModel: ctx.config?.currentModel ?? "" })
71
+ ?.providerId)
72
+ ?.trim()
73
+ .toLowerCase();
74
+ return currentProviderId &&
75
+ CLAUDE_AGENT_RUNTIME_IDS.includes(currentProviderId)
76
+ ? currentProviderId
77
+ : undefined;
78
+ }
79
+ /**
80
+ * OpenCode registers Claude Agent independently of the external login; provider presence alone
81
+ * cannot report its auth or quota. The independent CLI probe supplies what it can; it does not
82
+ * establish account equivalence from a matching email or plan.
83
+ */
84
+ export async function isClaudeAgentRuntimeDetected(ctx) {
85
+ if (ctx.client?.integration) {
86
+ try {
87
+ const { data } = await ctx.client.integration.list();
88
+ if (Array.isArray(data)) {
89
+ const agent = data.find((integration) => integration.id === "claude-agent");
90
+ if (agent && Array.isArray(agent.connections)) {
91
+ if (agent.connections.some((connection) => connection.type === "credential" && connection.method === "external")) {
92
+ return true;
93
+ }
94
+ return await isAnyProviderIdAvailable({
95
+ ctx,
96
+ candidateIds: ["claude-code"],
97
+ fallbackOnError: false,
98
+ });
99
+ }
100
+ }
101
+ }
102
+ catch {
103
+ // Older hosts or an unavailable integration service use legacy provider detection.
104
+ }
105
+ }
106
+ return await isAnyProviderIdAvailable({
107
+ ctx,
108
+ candidateIds: CLAUDE_AGENT_RUNTIME_IDS,
109
+ fallbackOnError: false,
110
+ });
111
+ }
112
+ export const claudeAgentProvider = {
113
+ id: "claude-agent",
114
+ async isAvailable(ctx) {
115
+ if (ctx.config?.onlyCurrentModel === true) {
116
+ // A selected Claude Agent route stays visible; its CLI probe runs in fetch, so a missing or
117
+ // signed-out CLI shows as an error instead of disappearing.
118
+ return getClaudeAgentRuntimeProviderId(ctx) !== undefined;
119
+ }
120
+ const runtimeAvailable = await isAnyProviderIdAvailable({
121
+ ctx,
122
+ candidateIds: CLAUDE_AGENT_RUNTIME_IDS,
123
+ fallbackOnError: false,
124
+ });
125
+ if (!runtimeAvailable)
126
+ return false;
127
+ // A probe that cannot report a status must not hide a detected runtime: fetch then shows the
128
+ // error row (and a genuine sign-out still hides it). Only a confirmed sign-out is unavailable.
129
+ return await hasAnthropicCredentialsConfigured({
130
+ binaryPath: ctx.config?.anthropicBinaryPath,
131
+ operationCache: ctx.operationCache,
132
+ }, { treatUnverifiedAsConfigured: true });
133
+ },
134
+ async isDiscovered(ctx) {
135
+ // Dashboard-only: a detected Claude Agent runtime stays visible while its CLI is not ready, and
136
+ // fetch says why.
137
+ if (ctx.config?.onlyCurrentModel === true)
138
+ return false;
139
+ return await isClaudeAgentRuntimeDetected(ctx);
140
+ },
141
+ matchesCurrentModel(model) {
142
+ const normalized = model.toLowerCase();
143
+ return CLAUDE_AGENT_RUNTIME_IDS.some((id) => normalized.startsWith(`${id}/`));
144
+ },
145
+ async fetch(ctx) {
146
+ const forceRefresh = ctx.operationCache?.get(QUOTA_FORCE_REFRESH) === true;
147
+ let diagnostics;
148
+ try {
149
+ diagnostics = await getAnthropicDiagnostics({
150
+ binaryPath: ctx.config?.anthropicBinaryPath,
151
+ ...(ctx.operationCache ? { operationCache: ctx.operationCache } : {}),
152
+ requestTimeoutMs: ctx.config?.requestTimeoutMs,
153
+ pollIntervalMs: ctx.config?.claudeAgentPollIntervalMs,
154
+ ...(forceRefresh ? { forceRefresh: true } : {}),
155
+ });
156
+ }
157
+ catch {
158
+ return withStatusDetails(attemptedErrorResult(CLAUDE_AGENT_GROUP, "Claude CLI probe failed."), statusDetailsFromRecord({ cli_installed: "false", message: "Failed to probe Claude CLI." }));
159
+ }
160
+ const statusDetails = statusDetailsFromRecord({
161
+ cli_installed: diagnostics.installed ? "true" : "false",
162
+ cli_version: diagnostics.version && /^\d+\.\d+\.\d+$/.test(diagnostics.version)
163
+ ? diagnostics.version
164
+ : "(none)",
165
+ binary_path: diagnostics.binaryPath ? "(detected)" : "(none)",
166
+ auth_status: diagnostics.authStatus,
167
+ quota_supported: diagnostics.quotaSupported ? "true" : "false",
168
+ quota_source: diagnostics.quotaSource === "none" ? "(none)" : diagnostics.quotaSource,
169
+ oauth_credential_source: diagnostics.oauthCredentialSource ?? "(none)",
170
+ checked_commands: diagnostics.checkedCommands.length ? "(checked)" : "(none)",
171
+ message: diagnostics.message === undefined ? undefined : safeDiagnosticMessage(diagnostics),
172
+ five_hour_remaining: diagnostics.quota?.five_hour
173
+ ? `${diagnostics.quota.five_hour.percentRemaining}% reset_at=${diagnostics.quota.five_hour.resetTimeIso ?? "(none)"}`
174
+ : undefined,
175
+ seven_day_remaining: diagnostics.quota?.seven_day
176
+ ? `${diagnostics.quota.seven_day.percentRemaining}% reset_at=${diagnostics.quota.seven_day.resetTimeIso ?? "(none)"}`
177
+ : undefined,
178
+ fable_weekly_remaining: diagnostics.quota?.fable_weekly
179
+ ? `${diagnostics.quota.fable_weekly.percentRemaining}% reset_at=${diagnostics.quota.fable_weekly.resetTimeIso ?? "(none)"}`
180
+ : undefined,
181
+ });
182
+ if (diagnostics.quotaSupported && diagnostics.quota) {
183
+ const acquisitionMethod = diagnostics.quotaSource === "claude-auth-status-json" ? "local_cli" : "remote_api";
184
+ const credits = diagnostics.quota.saved_resets?.credits.filter((credit) => credit.expiresAtIso == null || Date.parse(credit.expiresAtIso) > Date.now());
185
+ const savedResets = credits?.length ? { availableCount: credits.length, credits } : undefined;
186
+ const result = attemptedResult([
187
+ ...anthropicQuotaEntries(diagnostics.quota, {
188
+ group: CLAUDE_AGENT_GROUP,
189
+ acquisitionMethod,
190
+ ...(diagnostics.quotaMeasuredAtMs !== undefined
191
+ ? { observedAtMs: diagnostics.quotaMeasuredAtMs }
192
+ : {}),
193
+ }),
194
+ ...(savedResets && savedResets.availableCount > 0
195
+ ? [claudeAgentResetsEntry(savedResets, diagnostics.quotaMeasuredAtMs)]
196
+ : []),
197
+ ]);
198
+ return withStatusDetails(diagnostics.planLabel === undefined
199
+ ? result
200
+ : { ...result, planLabel: diagnostics.planLabel }, statusDetails);
201
+ }
202
+ return withStatusDetails(attemptedErrorResult(CLAUDE_AGENT_GROUP, safeDiagnosticMessage(diagnostics), {
203
+ ...(diagnostics.failureCategory !== undefined
204
+ ? { failureCategory: diagnostics.failureCategory }
205
+ : {}),
206
+ ...(diagnostics.attemptOutcome !== undefined
207
+ ? { attemptOutcome: diagnostics.attemptOutcome }
208
+ : {}),
209
+ ...(diagnostics.retryAtMs !== undefined
210
+ ? { retryable: true, retryAtMs: diagnostics.retryAtMs }
211
+ : {}),
212
+ }), statusDetails);
213
+ },
214
+ };
215
+ //# sourceMappingURL=claude-agent.js.map
@@ -5,6 +5,7 @@
5
5
  * into the shared provider/result boundary.
6
6
  */
7
7
  import { COPILOT_AUTH_KEYS, getCopilotQuotaAuthDiagnostics, hasCopilotQuotaRuntimeAvailable, queryCopilotQuota, } from "../lib/copilot.js";
8
+ import { windowSemantic } from "../lib/entries.js";
8
9
  import { credentialRowAuthEntry, formatCredentialDisplayNames, readAuthFileCached, readCredentialRows, } from "../lib/opencode-auth.js";
9
10
  import { isCanonicalProviderAvailable } from "../lib/provider-availability.js";
10
11
  import { modelIncludesAny, modelProviderIncludesAny } from "../lib/provider-model-matching.js";
@@ -118,7 +119,7 @@ function personalEntries(result) {
118
119
  name,
119
120
  group,
120
121
  label: "Quota:",
121
- rowKey: "window:month",
122
+ semantic: windowSemantic("month"),
122
123
  value: "Unlimited",
123
124
  resetTimeIso: result.resetTimeIso,
124
125
  },
@@ -131,7 +132,7 @@ function personalEntries(result) {
131
132
  name,
132
133
  group,
133
134
  label: result.unit === "ai_credits" ? "Credits:" : "Quota:",
134
- rowKey: "window:month",
135
+ semantic: windowSemantic("month"),
135
136
  right: `${formatNumber(result.used)}/${formatNumber(result.total)}`,
136
137
  percentRemaining: result.percentRemaining,
137
138
  resetTimeIso: result.resetTimeIso,
@@ -144,7 +145,7 @@ function personalEntries(result) {
144
145
  name,
145
146
  group,
146
147
  label: result.unit === "ai_credits" ? "Credits:" : "Usage:",
147
- rowKey: "window:month",
148
+ semantic: windowSemantic("month", "supplementary"),
148
149
  value: result.unit === "ai_credits"
149
150
  ? formatAiCreditUsageValue(result)
150
151
  : `Used ${formatNumber(result.used)}`,
@@ -207,7 +208,7 @@ function managedEntries(result) {
207
208
  name: "Copilot AI Credits",
208
209
  group,
209
210
  label: "Credits:",
210
- rowKey: "window:month",
211
+ semantic: windowSemantic("month", "supplementary"),
211
212
  value: formatAiCreditUsageValue(result),
212
213
  resetTimeIso: result.resetTimeIso,
213
214
  },
@@ -279,6 +280,7 @@ export const copilotProvider = {
279
280
  message: result.error,
280
281
  sourceId: row.id,
281
282
  failureCategory: result.failureCategory,
283
+ ...(result.retryAtMs !== undefined ? { retryAtMs: result.retryAtMs } : {}),
282
284
  });
283
285
  continue;
284
286
  }
@@ -309,6 +311,7 @@ export const copilotProvider = {
309
311
  if (!result.success) {
310
312
  return withStatusDetails(attemptedErrorResult("Copilot", result.error, {
311
313
  failureCategory: result.failureCategory,
314
+ ...(result.retryAtMs !== undefined ? { retryAtMs: result.retryAtMs } : {}),
312
315
  }), statusDetails);
313
316
  }
314
317
  const entries = result.mode === "user_plan"
@@ -51,6 +51,7 @@ export declare function createGlmCodingPlanProvider(params: {
51
51
  success: false;
52
52
  error: string;
53
53
  failureCategory?: ProviderFailureCategory;
54
+ retryAtMs?: number;
54
55
  } | null>;
55
56
  matchesCurrentModel: (model: string) => boolean;
56
57
  }): QuotaProvider;
@@ -1,39 +1,46 @@
1
+ import { windowSemantic } from "../lib/entries.js";
1
2
  import { credentialRowAuthEntry, formatCredentialDisplayNames, readCredentialRows, } from "../lib/opencode-auth.js";
2
3
  import { isCanonicalProviderAvailable } from "../lib/provider-availability.js";
3
4
  import { apiKeyStatusDetails, attemptedResult, groupedPercentWindowEntries, mapNullableProviderResult, statusDetailsFromRecord, withStatusDetails, } from "./result-helpers.js";
4
- const GLM_WINDOW_ROW_KEYS = {
5
- fiveHour: "window:five_hour",
6
- weekly: "window:week",
7
- mcp: "window:mcp",
5
+ const GLM_WINDOW_METRICS = {
6
+ fiveHour: "five_hour",
7
+ weekly: "week",
8
+ mcp: "mcp",
8
9
  };
9
- /**
10
- * Percent-only window rows carry no typed `semantic`, so they get stable
11
- * explicit `rowKey`s (metric + window) instead of label-derived ids.
12
- */
13
- function windowEntriesWithRowKeys(params) {
10
+ /** Percent-only window rows carry typed window semantics instead of label-derived ids. */
11
+ function windowEntriesWithSemantics(params) {
14
12
  const specs = [];
15
- const rowKeys = [];
16
13
  if (params.windows.fiveHour) {
17
- specs.push({ window: params.windows.fiveHour, suffix: "5h", label: "5h:" });
18
- rowKeys.push(GLM_WINDOW_ROW_KEYS.fiveHour);
14
+ specs.push({
15
+ window: params.windows.fiveHour,
16
+ suffix: "5h",
17
+ label: "5h:",
18
+ semantic: windowSemantic(GLM_WINDOW_METRICS.fiveHour),
19
+ });
19
20
  }
20
21
  if (params.windows.weekly) {
21
- specs.push({ window: params.windows.weekly, suffix: "Weekly", label: "Weekly:" });
22
- rowKeys.push(GLM_WINDOW_ROW_KEYS.weekly);
22
+ specs.push({
23
+ window: params.windows.weekly,
24
+ suffix: "Weekly",
25
+ label: "Weekly:",
26
+ semantic: windowSemantic(GLM_WINDOW_METRICS.weekly),
27
+ });
23
28
  }
24
29
  if (params.windows.mcp) {
25
- specs.push({ window: params.windows.mcp, suffix: "MCP", label: "MCP:" });
26
- rowKeys.push(GLM_WINDOW_ROW_KEYS.mcp);
30
+ specs.push({
31
+ window: params.windows.mcp,
32
+ suffix: "MCP",
33
+ label: "MCP:",
34
+ semantic: windowSemantic(GLM_WINDOW_METRICS.mcp),
35
+ });
27
36
  }
28
37
  return groupedPercentWindowEntries({
29
38
  group: params.group,
30
39
  accounting: params.accounting,
31
40
  windows: specs,
32
- }).map((entry, index) => ({
33
- ...entry,
34
- // groupedPercentWindowEntries emits one aggregate fallback row when no window exists.
35
- rowKey: rowKeys[index] ?? "aggregate",
36
- }));
41
+ // No reported window is not a 0% quota.
42
+ fallbackWhenEmpty: false,
43
+ });
37
44
  }
38
45
  export function createGlmCodingPlanProvider(params) {
39
46
  return {
@@ -92,7 +99,7 @@ export function createGlmCodingPlanProvider(params) {
92
99
  const group = names[index] ?? params.errorLabel;
93
100
  const mapped = mapNullableProviderResult(result, {
94
101
  errorLabel: group,
95
- onSuccess: (quota) => attemptedResult(windowEntriesWithRowKeys({
102
+ onSuccess: (quota) => attemptedResult(windowEntriesWithSemantics({
96
103
  group,
97
104
  accounting: {
98
105
  resultType: "quota",
@@ -113,7 +120,7 @@ export function createGlmCodingPlanProvider(params) {
113
120
  const result = await params.queryQuota({ requestTimeoutMs: ctx.config?.requestTimeoutMs });
114
121
  const providerResult = mapNullableProviderResult(result, {
115
122
  errorLabel: params.errorLabel,
116
- onSuccess: (quota) => attemptedResult(windowEntriesWithRowKeys({
123
+ onSuccess: (quota) => attemptedResult(windowEntriesWithSemantics({
117
124
  group: quota.label,
118
125
  accounting: {
119
126
  resultType: "quota",
@@ -48,6 +48,7 @@ export function formatGoogleAccountErrors(errors, style, labels) {
48
48
  label: (error.email && labels?.get(error.email)) ?? formatGoogleAccountLabel(error.email, style),
49
49
  message: error.error,
50
50
  ...(error.failureCategory !== undefined ? { failureCategory: error.failureCategory } : {}),
51
+ ...(error.retryAtMs !== undefined ? { retryAtMs: error.retryAtMs } : {}),
51
52
  }));
52
53
  }
53
54
  //# sourceMappingURL=google-account-format.js.map
@@ -1,15 +1,16 @@
1
1
  import type { QuotaProvider, QuotaProviderAccount } from "../lib/entries.js";
2
- import type { GoogleAgyQuotaBucket } from "../lib/types.js";
2
+ import type { GoogleAccountError, GoogleAgyQuotaBucket } from "../lib/types.js";
3
3
  /** Stable explicit row key for one AGY bucket row (family + window; never the label). */
4
4
  export declare function agyBucketRowKey(bucket: Pick<GoogleAgyQuotaBucket, "family" | "window">): string;
5
5
  /**
6
- * Accounts of the legacy companion path (no `CredentialRow`). `sourceId` keeps
7
- * the historical `account-N` ordinal byte-identical for reset/cache
8
- * compatibility; when the bucket carries an email the descriptor adds a
9
- * server-only email digest as `identityKey`. No key is derived from an ordinal.
6
+ * Legacy companion accounts have no `CredentialRow`. `sourceId` keeps the
7
+ * historical `account-N` value for reset/cache compatibility; email-backed
8
+ * descriptors use a server-only digest identity, while missing emails retain
9
+ * the existing source-id identity fallback.
10
10
  */
11
11
  export declare function buildAgyLegacyAccounts(params: {
12
12
  buckets: readonly GoogleAgyQuotaBucket[];
13
+ errors?: readonly GoogleAccountError[];
13
14
  accountLabels: ReadonlyMap<string, string>;
14
15
  }): QuotaProviderAccount[];
15
16
  export declare function formatAgyCredentialGroup(credentialName: string, familyLabel: string): string;
@@ -72,25 +72,43 @@ export function agyBucketRowKey(bucket) {
72
72
  return `named:${bucket.family} ${bucket.window}`;
73
73
  }
74
74
  /**
75
- * Accounts of the legacy companion path (no `CredentialRow`). `sourceId` keeps
76
- * the historical `account-N` ordinal byte-identical for reset/cache
77
- * compatibility; when the bucket carries an email the descriptor adds a
78
- * server-only email digest as `identityKey`. No key is derived from an ordinal.
75
+ * Legacy companion accounts have no `CredentialRow`. `sourceId` keeps the
76
+ * historical `account-N` value for reset/cache compatibility; email-backed
77
+ * descriptors use a server-only digest identity, while missing emails retain
78
+ * the existing source-id identity fallback.
79
79
  */
80
80
  export function buildAgyLegacyAccounts(params) {
81
81
  const accounts = new Map();
82
82
  for (const bucket of [...params.buckets].sort(compareBuckets)) {
83
- const sourceId = `account-${bucket.accountIndex + 1}`;
84
- if (accounts.has(sourceId))
83
+ if (!accounts.has(bucket.accountIndex))
84
+ accounts.set(bucket.accountIndex, bucket);
85
+ }
86
+ for (const error of params.errors ?? []) {
87
+ const accountIndex = error.accountIndex;
88
+ if (accountIndex === undefined ||
89
+ !Number.isInteger(accountIndex) ||
90
+ accountIndex < 0 ||
91
+ accounts.has(accountIndex)) {
85
92
  continue;
86
- const email = bucket.accountEmail;
87
- accounts.set(sourceId, {
88
- sourceId,
89
- ...(email ? { identityKey: deriveStableAccountIdentityKey(email) } : {}),
90
- label: formatAgyAccountLabel(bucket, params.accountLabels),
93
+ }
94
+ accounts.set(accountIndex, {
95
+ ...(AGY_AUTH_KEYS.some((sourceKey) => sourceKey === error.email)
96
+ ? {}
97
+ : { accountEmail: error.email }),
98
+ accountIndex,
91
99
  });
92
100
  }
93
- return [...accounts.values()];
101
+ return [...accounts.values()]
102
+ .sort((left, right) => left.accountIndex - right.accountIndex)
103
+ .map((account) => {
104
+ const sourceId = `account-${account.accountIndex + 1}`;
105
+ const email = account.accountEmail;
106
+ return {
107
+ sourceId,
108
+ ...(email ? { identityKey: deriveStableAccountIdentityKey(email) } : {}),
109
+ label: formatAgyAccountLabel(account, params.accountLabels),
110
+ };
111
+ });
94
112
  }
95
113
  export function formatAgyCredentialGroup(credentialName, familyLabel) {
96
114
  const trimmed = credentialName.trim();
@@ -205,6 +223,7 @@ export const googleAgyProvider = {
205
223
  ...(error.failureCategory !== undefined
206
224
  ? { failureCategory: error.failureCategory }
207
225
  : {}),
226
+ ...(error.retryAtMs !== undefined ? { retryAtMs: error.retryAtMs } : {}),
208
227
  })));
209
228
  }
210
229
  return withStatusDetails({ ...attemptedResult(entries, errors, { singleWindowShowRight: true }), accounts }, statusDetails);
@@ -227,7 +246,11 @@ export const googleAgyProvider = {
227
246
  ...sortedBuckets.map((bucket) => bucket.accountEmail),
228
247
  ...(result.errors ?? []).map((error) => error.email),
229
248
  ], "domainHint");
230
- const legacyAccounts = buildAgyLegacyAccounts({ buckets: sortedBuckets, accountLabels });
249
+ const legacyAccounts = buildAgyLegacyAccounts({
250
+ buckets: sortedBuckets,
251
+ errors: result.errors,
252
+ accountLabels,
253
+ });
231
254
  const sourceIdByEmail = new Map(sortedBuckets.flatMap((bucket) => bucket.accountEmail
232
255
  ? [[bucket.accountEmail, `account-${bucket.accountIndex + 1}`]]
233
256
  : []));
@@ -253,8 +276,13 @@ export const googleAgyProvider = {
253
276
  };
254
277
  });
255
278
  const errors = formatGoogleAccountErrors(result.errors, "domainHint", accountLabels).map((error, index) => {
256
- const email = result.errors?.[index]?.email;
257
- const sourceId = email ? sourceIdByEmail.get(email) : undefined;
279
+ const failed = result.errors?.[index];
280
+ // Same `account-N` ids the entries use, so a failed account keeps its previous rows.
281
+ const sourceId = failed?.accountIndex !== undefined
282
+ ? `account-${failed.accountIndex + 1}`
283
+ : failed?.email
284
+ ? sourceIdByEmail.get(failed.email)
285
+ : undefined;
258
286
  return sourceId ? { ...error, sourceId } : error;
259
287
  });
260
288
  return withStatusDetails({
@@ -158,6 +158,7 @@ export const googleGeminiCliProvider = {
158
158
  ...(error.failureCategory !== undefined
159
159
  ? { failureCategory: error.failureCategory }
160
160
  : {}),
161
+ ...(error.retryAtMs !== undefined ? { retryAtMs: error.retryAtMs } : {}),
161
162
  })));
162
163
  }
163
164
  return withStatusDetails({
@@ -134,6 +134,7 @@ export const kiloProvider = {
134
134
  {
135
135
  label: "Kilo Gateway",
136
136
  message: stateResult.error,
137
+ ...(stateResult.retryAtMs !== undefined ? { retryAtMs: stateResult.retryAtMs } : {}),
137
138
  ...(stateResult.failureCategory !== undefined
138
139
  ? { failureCategory: stateResult.failureCategory }
139
140
  : {}),
@@ -92,6 +92,7 @@ function createKimiProvider(spec) {
92
92
  message: result.error,
93
93
  sourceId: row.id,
94
94
  failureCategory: result.failureCategory,
95
+ ...(result.retryAtMs !== undefined ? { retryAtMs: result.retryAtMs } : {}),
95
96
  });
96
97
  continue;
97
98
  }
@@ -127,6 +128,7 @@ function createKimiProvider(spec) {
127
128
  if (!result.success) {
128
129
  return withStatusDetails(attemptedErrorResult(spec.label, result.error, {
129
130
  failureCategory: result.failureCategory,
131
+ ...(result.retryAtMs !== undefined ? { retryAtMs: result.retryAtMs } : {}),
130
132
  }), [...authDetails, { key: "live_fetch_error", value: result.error }]);
131
133
  }
132
134
  const entries = result.windows.map((window) => ({
@@ -74,6 +74,7 @@ function endpointErrors(result) {
74
74
  label: MIMO_LABEL,
75
75
  message: endpoint.error,
76
76
  failureCategory: endpoint.failureCategory,
77
+ ...(endpoint.retryAtMs !== undefined ? { retryAtMs: endpoint.retryAtMs } : {}),
77
78
  });
78
79
  }
79
80
  }
@@ -66,6 +66,7 @@ function mapNanoGptSuccess(result) {
66
66
  const errors = result.endpointErrors?.map((entry) => ({
67
67
  label: entry.endpoint === "usage" ? "NanoGPT Usage" : "NanoGPT Balance",
68
68
  message: entry.message,
69
+ ...(entry.retryAtMs !== undefined ? { retryAtMs: entry.retryAtMs } : {}),
69
70
  ...(entry.failureCategory !== undefined ? { failureCategory: entry.failureCategory } : {}),
70
71
  })) ?? [];
71
72
  const subscription = result.subscription;
@@ -4,6 +4,7 @@
4
4
  * Queries the Ollama Cloud balance API and reports included credits or
5
5
  * session/weekly limits, plus purchased credits.
6
6
  */
7
+ import { windowSemantic } from "../lib/entries.js";
7
8
  import { queryOllamaCloudQuota } from "../lib/ollama-cloud.js";
8
9
  import { getOllamaCloudKeyDiagnostics, hasOllamaCloudApiKey } from "../lib/ollama-cloud-config.js";
9
10
  import { modelProviderMatchesRuntimeId } from "../lib/provider-model-matching.js";
@@ -25,6 +26,9 @@ function mapOllamaCloudSuccess(result) {
25
26
  name: `${OLLAMA_CLOUD_PROVIDER_LABEL} Session`,
26
27
  group: OLLAMA_CLOUD_PROVIDER_LABEL,
27
28
  label: "Session:",
29
+ // The API calls this a "session" limit without a documented fixed
30
+ // window, so it gets a stable named identity but stays reset-ineligible.
31
+ semantic: { metric: { kind: "named", name: "Session" }, prominence: "primary" },
28
32
  percentRemaining: result.session.percentRemaining,
29
33
  ...(result.session.resetTimeIso ? { resetTimeIso: result.session.resetTimeIso } : {}),
30
34
  });
@@ -38,6 +42,7 @@ function mapOllamaCloudSuccess(result) {
38
42
  name: `${OLLAMA_CLOUD_PROVIDER_LABEL} Weekly`,
39
43
  group: OLLAMA_CLOUD_PROVIDER_LABEL,
40
44
  label: "Weekly:",
45
+ semantic: windowSemantic("week"),
41
46
  percentRemaining: result.weekly.percentRemaining,
42
47
  ...(result.weekly.resetTimeIso ? { resetTimeIso: result.weekly.resetTimeIso } : {}),
43
48
  });
@@ -53,6 +58,7 @@ function mapOllamaCloudSuccess(result) {
53
58
  name: `${OLLAMA_CLOUD_PROVIDER_LABEL} Monthly`,
54
59
  group: OLLAMA_CLOUD_PROVIDER_LABEL,
55
60
  label: "Monthly:",
61
+ semantic: windowSemantic("month"),
56
62
  percentRemaining: included.percentRemaining,
57
63
  ...(included.resetTimeIso ? { resetTimeIso: included.resetTimeIso } : {}),
58
64
  });
@@ -68,6 +74,10 @@ function mapOllamaCloudSuccess(result) {
68
74
  name: `${OLLAMA_CLOUD_PROVIDER_LABEL} Purchased`,
69
75
  group: OLLAMA_CLOUD_PROVIDER_LABEL,
70
76
  label: "Purchased:",
77
+ semantic: {
78
+ metric: { kind: "component", component: "remaining_credits" },
79
+ prominence: "supplementary",
80
+ },
71
81
  value: `$${result.purchasedUsd.toFixed(2)} left`,
72
82
  });
73
83
  }