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
@@ -1,245 +1,197 @@
1
1
  /**
2
- * Anthropic Claude provider wrapper.
2
+ * Anthropic provider: the Anthropic API-key connection only.
3
3
  *
4
- * Normalizes Claude CLI-exposed quota windows into generic toast entries.
4
+ * Subscription quota belongs to Claude Agent. An ordinary API key exposes no spend, balance or
5
+ * quota endpoint, so this card shows only per-minute rate limits passively observed on real
6
+ * OpenCode API-key Messages traffic (see `../lib/anthropic-api-rate-limits.ts`).
5
7
  */
6
- import { getAnthropicDiagnostics, hasAnthropicCredentialsConfigured, queryAnthropicQuota, queryAnthropicQuotaWithOAuth, } from "../lib/anthropic.js";
7
- import { resolveAnthropicOAuth } from "../lib/anthropic-auth.js";
8
- import { sanitizeDisplayText } from "../lib/display-sanitize.js";
9
- import { credentialRowAuthEntry, formatCredentialDisplayNames, readCredentialRows, } from "../lib/opencode-auth.js";
10
- import { isCanonicalProviderAvailable } from "../lib/provider-availability.js";
8
+ import { resolveAnthropicApiKey } from "../lib/anthropic-api-auth.js";
9
+ import { ANTHROPIC_RATE_LIMIT_METERS, digestAnthropicApiKey, readAnthropicApiObservation, } from "../lib/anthropic-api-rate-limits.js";
10
+ import { windowSemantic } from "../lib/entries.js";
11
+ import { resolveQuotaProviderSessionModelIdentity } from "../lib/quota-providers.js";
11
12
  import { attemptedErrorResult, attemptedResult, notAttemptedResult, statusDetailsFromRecord, withStatusDetails, } from "./result-helpers.js";
12
13
  export function getAnthropicNoDataMessage() {
13
- return "Quota unavailable via local Claude CLI or OAuth credentials";
14
+ return "No Anthropic API key configured";
15
+ }
16
+ const ANTHROPIC_API_KEY_MISSING_MESSAGE = "No Anthropic API key is configured.";
17
+ const ANTHROPIC_NO_OBSERVATION_TEXT = "No rate-limit headers observed yet";
18
+ /**
19
+ * Map subscription quota returned for the Claude Agent CLI login.
20
+ */
21
+ export function anthropicQuotaEntries(quota, params) {
22
+ const { group } = params;
23
+ const accounting = {
24
+ resultType: "quota",
25
+ acquisitionMethod: params.acquisitionMethod,
26
+ ownership: "maintained",
27
+ authority: "provider_reported",
28
+ ...(params.sourceId !== undefined ? { sourceId: params.sourceId } : {}),
29
+ ...(params.observedAtMs !== undefined
30
+ ? { observedAtIso: new Date(params.observedAtMs).toISOString() }
31
+ : {}),
32
+ };
33
+ const entries = [];
34
+ for (const [label, window, semantic] of [
35
+ ["5h", quota.five_hour, windowSemantic("five_hour")],
36
+ ["Weekly", quota.seven_day, windowSemantic("week")],
37
+ ]) {
38
+ if (!window)
39
+ continue;
40
+ entries.push({
41
+ accounting: { ...accounting },
42
+ name: `${group} ${label}`,
43
+ group,
44
+ label: `${label}:`,
45
+ semantic,
46
+ percentRemaining: window.percentRemaining,
47
+ resetTimeIso: window.resetTimeIso,
48
+ ...(window.fixedWindow ? { fixedWindow: { ...window.fixedWindow } } : {}),
49
+ });
50
+ }
51
+ if (quota.extra_usage) {
52
+ entries.push({
53
+ accounting: { ...accounting },
54
+ name: `${group} Usage Credits`,
55
+ group: `${group} Usage Credits`,
56
+ label: "Monthly:",
57
+ semantic: windowSemantic("month"),
58
+ percentRemaining: quota.extra_usage.percentRemaining,
59
+ });
60
+ }
61
+ if (quota.fable_weekly) {
62
+ entries.push({
63
+ accounting: { ...accounting },
64
+ name: `${group} Fable Weekly`,
65
+ group,
66
+ label: "Fable:",
67
+ semantic: {
68
+ metric: { kind: "named", name: "Fable weekly" },
69
+ prominence: "primary",
70
+ },
71
+ percentRemaining: quota.fable_weekly.percentRemaining,
72
+ resetTimeIso: quota.fable_weekly.resetTimeIso,
73
+ });
74
+ }
75
+ return entries;
76
+ }
77
+ const ANTHROPIC_GROUP = "Anthropic";
78
+ const RATE_LIMIT_INFO = "Anthropic API rate limit (per minute) observed on your API-key requests. Not subscription quota, spend or balance.";
79
+ const METER_LABELS = {
80
+ requests: "Requests",
81
+ tokens: "Tokens",
82
+ inputTokens: "Input tokens",
83
+ outputTokens: "Output tokens",
84
+ };
85
+ function numberText(value) {
86
+ return value.toLocaleString("en-US");
87
+ }
88
+ function meterValueText(meter) {
89
+ if (meter.remaining !== undefined && meter.limit !== undefined) {
90
+ return `${numberText(meter.remaining)} of ${numberText(meter.limit)} remaining`;
91
+ }
92
+ if (meter.remaining !== undefined)
93
+ return `${numberText(meter.remaining)} remaining`;
94
+ if (meter.limit !== undefined)
95
+ return `Limit ${numberText(meter.limit)}`;
96
+ return undefined;
97
+ }
98
+ /**
99
+ * Rows for one passive observation. Plain value rows: a percentage is never computed, so no
100
+ * quota alert, runway or reset-notice logic can treat a per-minute rate limit as quota.
101
+ */
102
+ function anthropicApiRateLimitEntries(observation, nowMs) {
103
+ const accounting = {
104
+ resultType: "rate_limit",
105
+ acquisitionMethod: "remote_api",
106
+ ownership: "maintained",
107
+ authority: "provider_reported",
108
+ observedAtIso: new Date(observation.observedAtMs).toISOString(),
109
+ };
110
+ const entries = [];
111
+ for (const [, name] of ANTHROPIC_RATE_LIMIT_METERS) {
112
+ const observed = observation.meters[name];
113
+ if (!observed)
114
+ continue;
115
+ // A passed reset means the observed remaining count is stale; only the limit still applies.
116
+ const expired = observed.resetAtIso !== undefined && Date.parse(observed.resetAtIso) <= nowMs;
117
+ const meter = expired ? { limit: observed.limit } : observed;
118
+ const value = meterValueText(meter);
119
+ if (value === undefined)
120
+ continue;
121
+ entries.push({
122
+ kind: "value",
123
+ accounting: { ...accounting },
124
+ name: `${ANTHROPIC_GROUP} ${METER_LABELS[name]}`,
125
+ group: ANTHROPIC_GROUP,
126
+ label: `${METER_LABELS[name]}:`,
127
+ info: RATE_LIMIT_INFO,
128
+ rowKey: `rate_limit:${name}`,
129
+ value,
130
+ ...(meter.resetAtIso !== undefined ? { resetTimeIso: meter.resetAtIso } : {}),
131
+ });
132
+ }
133
+ if (observation.retryAfterSeconds !== undefined &&
134
+ observation.observedAtMs + observation.retryAfterSeconds * 1000 > nowMs) {
135
+ entries.push({
136
+ kind: "value",
137
+ accounting: { ...accounting },
138
+ name: `${ANTHROPIC_GROUP} Retry after`,
139
+ group: ANTHROPIC_GROUP,
140
+ label: "Retry after:",
141
+ info: RATE_LIMIT_INFO,
142
+ rowKey: "rate_limit:retry_after",
143
+ value: `${numberText(observation.retryAfterSeconds)} s (last rate-limited response)`,
144
+ });
145
+ }
146
+ return entries;
14
147
  }
15
148
  export const anthropicProvider = {
16
149
  id: "anthropic",
17
150
  async isAvailable(ctx) {
18
- const providerAvailable = await isCanonicalProviderAvailable({
19
- ctx,
20
- providerId: "anthropic",
21
- fallbackOnError: false,
22
- });
23
- if (!providerAvailable) {
24
- return false;
151
+ if (ctx.config?.onlyCurrentModel === true) {
152
+ const selected = ctx.config.currentProviderID ??
153
+ resolveQuotaProviderSessionModelIdentity({ currentModel: ctx.config.currentModel ?? "" })
154
+ ?.providerId;
155
+ return selected?.trim().toLowerCase() === "anthropic";
25
156
  }
26
- return await hasAnthropicCredentialsConfigured({
27
- binaryPath: ctx.config?.anthropicBinaryPath,
28
- });
157
+ return (await resolveAnthropicApiKey()) !== null;
29
158
  },
30
159
  matchesCurrentModel(model) {
31
160
  return model.toLowerCase().startsWith("anthropic/");
32
161
  },
33
162
  async fetch(ctx) {
34
- const options = {
35
- binaryPath: ctx.config?.anthropicBinaryPath,
36
- requestTimeoutMs: ctx.config?.requestTimeoutMs,
37
- };
38
- let statusDetails;
39
- let acquisitionMethod = "local_cli";
40
- // A failed login stays in the list so it shows as its own error row.
41
- const databaseCredentials = (await readCredentialRows(["anthropic"], { methods: ["oauth"] })).flatMap((row) => {
42
- if (row.integrationId !== "anthropic")
43
- return [];
44
- const auth = resolveAnthropicOAuth({ anthropic: credentialRowAuthEntry(row) });
45
- return auth.state === "configured" || auth.state === "failed" ? [{ row, auth }] : [];
46
- });
47
- try {
48
- const diagnostics = await getAnthropicDiagnostics(options);
49
- const quota = diagnostics.quotaSupported ? diagnostics.quota : undefined;
50
- if (diagnostics.quotaSupported && diagnostics.quotaSource !== "claude-auth-status-json") {
51
- acquisitionMethod = "remote_api";
52
- }
53
- statusDetails = statusDetailsFromRecord({
54
- cli_installed: diagnostics.installed ? "true" : "false",
55
- cli_version: diagnostics.version ?? "(none)",
56
- binary_path: diagnostics.binaryPath ?? "(none)",
57
- auth_status: diagnostics.authStatus,
58
- quota_supported: diagnostics.quotaSupported ? "true" : "false",
59
- quota_source: diagnostics.quotaSource === "none" ? "(none)" : diagnostics.quotaSource,
60
- oauth_credential_source: diagnostics.oauthCredentialSource ?? "(none)",
61
- checked_commands: diagnostics.checkedCommands.join(" | ") || "(none)",
62
- message: diagnostics.message,
63
- five_hour_remaining: quota
64
- ? `${quota.five_hour.percentRemaining}% reset_at=${quota.five_hour.resetTimeIso ?? "(none)"}`
65
- : undefined,
66
- seven_day_remaining: quota
67
- ? `${quota.seven_day.percentRemaining}% reset_at=${quota.seven_day.resetTimeIso ?? "(none)"}`
68
- : undefined,
69
- fable_weekly_remaining: quota?.fable_weekly
70
- ? `${quota.fable_weekly.percentRemaining}% reset_at=${quota.fable_weekly.resetTimeIso ?? "(none)"}`
71
- : undefined,
72
- });
73
- }
74
- catch (error) {
75
- statusDetails = statusDetailsFromRecord({
76
- cli_installed: "false",
77
- message: `failed to probe Claude CLI: ${sanitizeDisplayText(error instanceof Error ? error.message : String(error))}`,
78
- });
163
+ const apiKey = await resolveAnthropicApiKey();
164
+ if (apiKey === null) {
165
+ return withStatusDetails(ctx.config?.onlyCurrentModel
166
+ ? attemptedErrorResult(ANTHROPIC_GROUP, ANTHROPIC_API_KEY_MISSING_MESSAGE)
167
+ : notAttemptedResult(), statusDetailsFromRecord({ api_key: "(none)" }));
79
168
  }
80
- if (databaseCredentials.length > 0) {
81
- const results = await Promise.all(databaseCredentials.map(async ({ row, auth }) => ({
82
- row,
83
- result: auth.state === "failed"
84
- ? {
85
- success: false,
86
- error: `Anthropic sign-in could not be read: ${auth.error}. Run \`opencode auth login anthropic\`.`,
87
- failureCategory: "credentials",
88
- }
89
- : await queryAnthropicQuotaWithOAuth(auth.accessToken, options.requestTimeoutMs),
90
- })));
91
- const names = formatCredentialDisplayNames("Claude", results.map(({ row }) => ({ row, fallbackName: "Claude" })));
92
- const accounts = results.map(({ row }, index) => ({
93
- sourceId: row.id,
94
- label: names[index] ?? "Claude",
95
- active: row.active,
96
- }));
97
- const entries = [];
98
- const errors = [];
99
- for (const [index, { row, result }] of results.entries()) {
100
- const group = names[index] ?? "Claude";
101
- if (!result?.success) {
102
- if (result) {
103
- errors.push({
104
- label: group,
105
- message: result.error,
106
- sourceId: row.id,
107
- failureCategory: result.failureCategory,
108
- });
109
- }
110
- continue;
111
- }
112
- entries.push(...[
113
- ["5h", result.five_hour, "window:five_hour"],
114
- ["Weekly", result.seven_day, "window:week"],
115
- ].map(([label, window, rowKey]) => ({
169
+ const observation = readAnthropicApiObservation(digestAnthropicApiKey(apiKey));
170
+ const entries = observation ? anthropicApiRateLimitEntries(observation, Date.now()) : [];
171
+ // Configured but nothing observed yet is a truthful status, neither an error nor a zero.
172
+ const result = attemptedResult(entries.length > 0
173
+ ? entries
174
+ : [
175
+ {
176
+ kind: "value",
116
177
  accounting: {
117
- resultType: "quota",
178
+ resultType: "status",
118
179
  acquisitionMethod: "remote_api",
119
180
  ownership: "maintained",
120
181
  authority: "provider_reported",
121
- sourceId: row.id,
122
182
  },
123
- name: `${group} ${label}`,
124
- group,
125
- label: `${label}:`,
126
- rowKey,
127
- percentRemaining: window.percentRemaining,
128
- resetTimeIso: window.resetTimeIso,
129
- })));
130
- if (result.extra_usage) {
131
- entries.push({
132
- accounting: {
133
- resultType: "quota",
134
- acquisitionMethod: "remote_api",
135
- ownership: "maintained",
136
- authority: "provider_reported",
137
- sourceId: row.id,
138
- },
139
- name: `${group} Usage Credits`,
140
- group: `${group} Usage Credits`,
141
- label: "Monthly:",
142
- rowKey: "window:month",
143
- percentRemaining: result.extra_usage.percentRemaining,
144
- });
145
- }
146
- if (result.fable_weekly) {
147
- entries.push({
148
- accounting: {
149
- resultType: "quota",
150
- acquisitionMethod: "remote_api",
151
- ownership: "maintained",
152
- authority: "provider_reported",
153
- sourceId: row.id,
154
- },
155
- name: `${group} Fable Weekly`,
156
- group,
157
- label: "Fable:",
158
- semantic: {
159
- metric: { kind: "named", name: "Fable weekly" },
160
- prominence: "primary",
161
- },
162
- percentRemaining: result.fable_weekly.percentRemaining,
163
- resetTimeIso: result.fable_weekly.resetTimeIso,
164
- });
165
- }
166
- }
167
- return withStatusDetails({ ...attemptedResult(entries, errors), accounts }, statusDetails);
168
- }
169
- const result = await queryAnthropicQuota(options);
170
- if (!result) {
171
- return withStatusDetails(notAttemptedResult(), statusDetails);
172
- }
173
- if (!result.success) {
174
- return withStatusDetails(attemptedErrorResult("Claude", result.error, {
175
- failureCategory: result.failureCategory,
176
- }), statusDetails);
177
- }
178
- const entries = [
179
- {
180
- accounting: {
181
- resultType: "quota",
182
- acquisitionMethod,
183
- ownership: "maintained",
184
- authority: "provider_reported",
183
+ name: `${ANTHROPIC_GROUP} Rate limits`,
184
+ group: ANTHROPIC_GROUP,
185
+ label: "Rate limits:",
186
+ info: RATE_LIMIT_INFO,
187
+ rowKey: "rate_limit:none",
188
+ value: ANTHROPIC_NO_OBSERVATION_TEXT,
185
189
  },
186
- name: "Claude 5h",
187
- group: "Claude",
188
- label: "5h:",
189
- rowKey: "window:five_hour",
190
- percentRemaining: result.five_hour.percentRemaining,
191
- resetTimeIso: result.five_hour.resetTimeIso,
192
- },
193
- {
194
- accounting: {
195
- resultType: "quota",
196
- acquisitionMethod,
197
- ownership: "maintained",
198
- authority: "provider_reported",
199
- },
200
- name: "Claude Weekly",
201
- group: "Claude",
202
- label: "Weekly:",
203
- rowKey: "window:week",
204
- percentRemaining: result.seven_day.percentRemaining,
205
- resetTimeIso: result.seven_day.resetTimeIso,
206
- },
207
- ];
208
- if (result.extra_usage) {
209
- entries.push({
210
- accounting: {
211
- resultType: "quota",
212
- acquisitionMethod,
213
- ownership: "maintained",
214
- authority: "provider_reported",
215
- },
216
- name: "Claude Usage Credits",
217
- group: "Claude Usage Credits",
218
- label: "Monthly:",
219
- rowKey: "window:month",
220
- percentRemaining: result.extra_usage.percentRemaining,
221
- });
222
- }
223
- if (result.fable_weekly) {
224
- entries.push({
225
- accounting: {
226
- resultType: "quota",
227
- acquisitionMethod,
228
- ownership: "maintained",
229
- authority: "provider_reported",
230
- },
231
- name: "Claude Fable Weekly",
232
- group: "Claude",
233
- label: "Fable:",
234
- semantic: {
235
- metric: { kind: "named", name: "Fable weekly" },
236
- prominence: "primary",
237
- },
238
- percentRemaining: result.fable_weekly.percentRemaining,
239
- resetTimeIso: result.fable_weekly.resetTimeIso,
240
- });
241
- }
242
- return withStatusDetails(attemptedResult(entries), statusDetails);
190
+ ]);
191
+ return withStatusDetails(result, statusDetailsFromRecord({
192
+ api_key: "(configured)",
193
+ observed: observation ? "true" : "false",
194
+ }));
243
195
  },
244
196
  };
245
197
  //# sourceMappingURL=anthropic.js.map
@@ -1,11 +1,15 @@
1
- import type { QuotaProviderCachePolicy } from "../lib/entries.js";
1
+ import type { QuotaProviderCachePolicy, QuotaProviderContext } from "../lib/entries.js";
2
2
  import type { QuotaProviderDefinition } from "../lib/quota-providers.js";
3
3
  import { type ResolvedAuthIdentity } from "../lib/resolved-auth-identity.js";
4
4
  export declare function resolveQuotaProviderDefinitionAuthIdentity(definition: QuotaProviderDefinition): Promise<ResolvedAuthIdentity | null>;
5
5
  export declare const PROVIDER_CACHE_POLICIES: {
6
6
  anthropic: {
7
+ readonly kind: "uncached";
8
+ };
9
+ "claude-agent": {
7
10
  kind: "resolved-auth";
8
- resolveIdentity: (ctx: import("../lib/entries.js").QuotaProviderContext) => Promise<ResolvedAuthIdentity | null>;
11
+ revalidateWithCycleCache: true;
12
+ resolveIdentity: (ctx: QuotaProviderContext) => Promise<ResolvedAuthIdentity | null>;
9
13
  };
10
14
  copilot: {
11
15
  kind: "resolved-auth";
@@ -26,7 +30,9 @@ export declare const PROVIDER_CACHE_POLICIES: {
26
30
  "alibaba-token-plan": {
27
31
  readonly kind: "uncached";
28
32
  };
29
- "alibaba-coding-plan": QuotaProviderCachePolicy;
33
+ "alibaba-coding-plan": {
34
+ readonly kind: "uncached";
35
+ };
30
36
  synthetic: QuotaProviderCachePolicy;
31
37
  chutes: QuotaProviderCachePolicy;
32
38
  "google-gemini-cli": {
@@ -61,7 +67,8 @@ export declare const PROVIDER_CACHE_POLICIES: {
61
67
  "ollama-cloud": QuotaProviderCachePolicy;
62
68
  "quota-providers": {
63
69
  kind: "resolved-auth";
64
- resolveIdentity: (ctx: import("../lib/entries.js").QuotaProviderContext, cacheContext: import("../lib/entries.js").QuotaProviderCacheContext) => Promise<ResolvedAuthIdentity | null>;
70
+ revalidateWithCycleCache?: true;
71
+ resolveIdentity: (ctx: QuotaProviderContext, cacheContext: import("../lib/entries.js").QuotaProviderCacheContext) => Promise<ResolvedAuthIdentity | null>;
65
72
  };
66
73
  };
67
74
  //# sourceMappingURL=cache-policies.d.ts.map
@@ -1,5 +1,4 @@
1
- import { DEFAULT_ALIBABA_AUTH_CACHE_MAX_AGE_MS, resolveAlibabaCodingPlanAuthCached, } from "../lib/alibaba-auth.js";
2
- import { resolveAnthropicAuthIdentity } from "../lib/anthropic.js";
1
+ import { resolveClaudeAgentAccountIdentity } from "../lib/anthropic.js";
3
2
  import { resolveChutesApiKey } from "../lib/chutes-config.js";
4
3
  import { resolveCopilotAuthIdentity } from "../lib/copilot.js";
5
4
  import { resolveDeepSeekApiKey } from "../lib/deepseek-auth.js";
@@ -21,6 +20,7 @@ import { resolveSyntheticApiKey } from "../lib/synthetic-config.js";
21
20
  import { resolveXaiAuthIdentity } from "../lib/xai.js";
22
21
  import { DEFAULT_ZAI_AUTH_CACHE_MAX_AGE_MS, resolveZaiAuthCached } from "../lib/zai-auth.js";
23
22
  import { DEFAULT_ZHIPU_AUTH_CACHE_MAX_AGE_MS, resolveZhipuAuthCached } from "../lib/zhipu-auth.js";
23
+ import { getClaudeAgentRuntimeProviderId, isClaudeAgentRuntimeDetected } from "./claude-agent.js";
24
24
  const UNCACHED = { kind: "uncached" };
25
25
  function resolvedCredentialPolicy(providerId, resolve) {
26
26
  return {
@@ -111,7 +111,7 @@ const quotaProvidersCachePolicy = {
111
111
  const definitions = cacheContext.runtimeEligibleQuotaProviders;
112
112
  if (!definitions || definitions.length === 0)
113
113
  return null;
114
- const identities = await Promise.all(definitions.map(resolveQuotaProviderDefinitionAuthIdentity));
114
+ const identities = await Promise.all(definitions.map((definition) => resolveQuotaProviderDefinitionAuthIdentity(definition)));
115
115
  if (identities.some((identity) => identity === null))
116
116
  return null;
117
117
  return composeResolvedAuthIdentities({
@@ -120,10 +120,23 @@ const quotaProvidersCachePolicy = {
120
120
  });
121
121
  },
122
122
  };
123
+ /** The Claude CLI login alone. */
124
+ async function claudeAgentIdentity(ctx) {
125
+ const selected = getClaudeAgentRuntimeProviderId(ctx) !== undefined;
126
+ return resolveClaudeAgentAccountIdentity({
127
+ binaryPath: ctx.config.anthropicBinaryPath,
128
+ operationCache: ctx.operationCache,
129
+ onlyCurrentModel: ctx.config.onlyCurrentModel === true,
130
+ runtimeDetected: selected ? false : await isClaudeAgentRuntimeDetected(ctx),
131
+ });
132
+ }
123
133
  export const PROVIDER_CACHE_POLICIES = {
124
- anthropic: {
134
+ anthropic: UNCACHED,
135
+ "claude-agent": {
125
136
  kind: "resolved-auth",
126
- resolveIdentity: (ctx) => resolveAnthropicAuthIdentity({ binaryPath: ctx.config.anthropicBinaryPath }),
137
+ // Identity uses this cycle's CLI probe; repeating it only spawns more processes.
138
+ revalidateWithCycleCache: true,
139
+ resolveIdentity: (ctx) => claudeAgentIdentity(ctx),
127
140
  },
128
141
  copilot: {
129
142
  kind: "resolved-auth",
@@ -143,14 +156,7 @@ export const PROVIDER_CACHE_POLICIES = {
143
156
  }),
144
157
  cursor: UNCACHED,
145
158
  "alibaba-token-plan": UNCACHED,
146
- "alibaba-coding-plan": resolvedCredentialPolicy("alibaba-coding-plan", async () => {
147
- const resolved = await resolveAlibabaCodingPlanAuthCached({
148
- maxAgeMs: DEFAULT_ALIBABA_AUTH_CACHE_MAX_AGE_MS,
149
- });
150
- return resolved.state === "configured"
151
- ? { credential: resolved.apiKey, qualifiers: [resolved.tier] }
152
- : null;
153
- }),
159
+ "alibaba-coding-plan": UNCACHED,
154
160
  synthetic: resolvedCredentialPolicy("synthetic", async () => {
155
161
  const resolved = await resolveSyntheticApiKey();
156
162
  return resolved ? { credential: resolved.key } : null;
@@ -2,6 +2,7 @@
2
2
  * Chutes AI provider wrapper.
3
3
  */
4
4
  import { getChutesKeyDiagnostics, hasChutesApiKeyConfigured, queryChutesQuota, } from "../lib/chutes.js";
5
+ import { windowSemantic } from "../lib/entries.js";
5
6
  import { isCanonicalProviderAvailable } from "../lib/provider-availability.js";
6
7
  import { modelProviderIncludesAny } from "../lib/provider-model-matching.js";
7
8
  import { attemptedResult, mapNullableProviderResult, withStatusDetails } from "./result-helpers.js";
@@ -38,6 +39,7 @@ export const chutesProvider = {
38
39
  authority: "provider_reported",
39
40
  },
40
41
  name: "Chutes",
42
+ semantic: windowSemantic("day"),
41
43
  percentRemaining: result.percentRemaining,
42
44
  resetTimeIso: result.resetTimeIso,
43
45
  },
@@ -0,0 +1,19 @@
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 type { QuotaProvider, QuotaProviderContext } from "../lib/entries.js";
7
+ /** `claude-agent` is OpenCode's native integration; `claude-code` is its legacy runtime alias. */
8
+ export declare const CLAUDE_AGENT_RUNTIME_IDS: readonly ["claude-agent", "claude-code"];
9
+ export declare function getClaudeAgentNoDataMessage(): string;
10
+ /** The Claude Agent route selected by `onlyCurrentModel`, if any. */
11
+ export declare function getClaudeAgentRuntimeProviderId(ctx: QuotaProviderContext): (typeof CLAUDE_AGENT_RUNTIME_IDS)[number] | undefined;
12
+ /**
13
+ * OpenCode registers Claude Agent independently of the external login; provider presence alone
14
+ * cannot report its auth or quota. The independent CLI probe supplies what it can; it does not
15
+ * establish account equivalence from a matching email or plan.
16
+ */
17
+ export declare function isClaudeAgentRuntimeDetected(ctx: QuotaProviderContext): Promise<boolean>;
18
+ export declare const claudeAgentProvider: QuotaProvider;
19
+ //# sourceMappingURL=claude-agent.d.ts.map