opencode-quota-gui 1.2.0 → 1.3.1

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 (585) hide show
  1. package/README.md +104 -34
  2. package/dist/contracts/analytics-entity.d.ts +6 -1
  3. package/dist/contracts/analytics-entity.js +27 -10
  4. package/dist/contracts/build-identity.js +1 -1
  5. package/dist/contracts/card-visibility.d.ts +21 -0
  6. package/dist/contracts/card-visibility.js +19 -0
  7. package/dist/contracts/dashboard.d.ts +35 -1
  8. package/dist/contracts/dashboard.js +2 -0
  9. package/dist/contracts/dto-guards.d.ts +24 -0
  10. package/dist/contracts/dto-guards.js +594 -0
  11. package/dist/contracts/openai-quota.d.ts +3 -0
  12. package/dist/contracts/openai-quota.js +3 -0
  13. package/dist/contracts/provider-failure.d.ts +18 -0
  14. package/dist/contracts/provider-failure.js +25 -0
  15. package/dist/data/modelsdev-temporal.min.json +57 -0
  16. package/dist/gui/config.d.ts +20 -3
  17. package/dist/gui/config.js +72 -4
  18. package/dist/gui/dashboard-errors.d.ts +32 -0
  19. package/dist/gui/dashboard-errors.js +97 -0
  20. package/dist/gui/lifecycle.d.ts +47 -12
  21. package/dist/gui/lifecycle.js +215 -37
  22. package/dist/gui/primary-quota-windows.d.ts +28 -0
  23. package/dist/gui/primary-quota-windows.js +149 -0
  24. package/dist/gui/provider-cards.d.ts +11 -3
  25. package/dist/gui/provider-cards.js +85 -33
  26. package/dist/gui/quota-notification-detector.d.ts +151 -0
  27. package/dist/gui/quota-notification-detector.js +318 -0
  28. package/dist/gui/quota-notification-observer.d.ts +54 -0
  29. package/dist/gui/quota-notification-observer.js +412 -0
  30. package/dist/gui/rpc.d.ts +61 -0
  31. package/dist/gui/rpc.js +310 -0
  32. package/dist/gui/server.d.ts +15 -27
  33. package/dist/gui/server.js +34 -123
  34. package/dist/gui/snapshot-service.d.ts +34 -5
  35. package/dist/gui/snapshot-service.js +301 -70
  36. package/dist/gui/sources.d.ts +1 -1
  37. package/dist/gui/sources.js +98 -56
  38. package/dist/gui-experimental.cjs +1761 -0
  39. package/dist/lib/accounting-format.js +8 -0
  40. package/dist/lib/alibaba-coding-plan-cli.d.ts +79 -0
  41. package/dist/lib/alibaba-coding-plan-cli.js +539 -0
  42. package/dist/lib/anthropic-auth.d.ts +2 -3
  43. package/dist/lib/anthropic-auth.js +2 -3
  44. package/dist/lib/anthropic.d.ts +53 -12
  45. package/dist/lib/anthropic.js +622 -270
  46. package/dist/lib/api-key-retry-after.d.ts +7 -0
  47. package/dist/lib/api-key-retry-after.js +62 -0
  48. package/dist/lib/atomic-json.d.ts +2 -0
  49. package/dist/lib/atomic-json.js +1 -0
  50. package/dist/lib/cache-observer-ingestion.d.ts +90 -0
  51. package/dist/lib/cache-observer-ingestion.js +981 -0
  52. package/dist/lib/cache-observer.d.ts +138 -0
  53. package/dist/lib/cache-observer.js +317 -0
  54. package/dist/lib/canonical-config-lock.d.ts +9 -0
  55. package/dist/lib/canonical-config-lock.js +36 -0
  56. package/dist/lib/chutes.js +63 -35
  57. package/dist/lib/claude-agent-transcript-ttl.d.ts +48 -0
  58. package/dist/lib/claude-agent-transcript-ttl.js +154 -0
  59. package/dist/lib/claude-agent-ttl-tracker.d.ts +21 -0
  60. package/dist/lib/claude-agent-ttl-tracker.js +152 -0
  61. package/dist/lib/cli-show.js +5 -3
  62. package/dist/lib/config-write-target.d.ts +1 -1
  63. package/dist/lib/config-write-target.js +5 -2
  64. package/dist/lib/config.d.ts +6 -1
  65. package/dist/lib/config.js +241 -2
  66. package/dist/lib/copilot.js +198 -85
  67. package/dist/lib/dashboard-web-policy.d.ts +35 -0
  68. package/dist/lib/dashboard-web-policy.js +24 -0
  69. package/dist/lib/deepseek.js +34 -11
  70. package/dist/lib/display-sanitize.js +3 -0
  71. package/dist/lib/entries.d.ts +26 -0
  72. package/dist/lib/entries.js +2 -0
  73. package/dist/lib/format-utils.d.ts +1 -1
  74. package/dist/lib/format-utils.js +2 -2
  75. package/dist/lib/glm-coding-plan.js +102 -68
  76. package/dist/lib/google-agy.js +147 -24
  77. package/dist/lib/google-gemini-cli.js +140 -23
  78. package/dist/lib/http.d.ts +4 -0
  79. package/dist/lib/http.js +16 -2
  80. package/dist/lib/init-installer.js +30 -7
  81. package/dist/lib/kilo.js +63 -55
  82. package/dist/lib/kimi.js +43 -14
  83. package/dist/lib/mimo.d.ts +4 -0
  84. package/dist/lib/mimo.js +45 -1
  85. package/dist/lib/nanogpt.d.ts +3 -0
  86. package/dist/lib/nanogpt.js +50 -6
  87. package/dist/lib/ollama-cloud.d.ts +1 -1
  88. package/dist/lib/ollama-cloud.js +51 -29
  89. package/dist/lib/openai.js +90 -40
  90. package/dist/lib/opencode-auth-sqlite.d.ts +2 -2
  91. package/dist/lib/opencode-auth-sqlite.js +2 -2
  92. package/dist/lib/opencode-auth.d.ts +3 -2
  93. package/dist/lib/opencode-auth.js +8 -1
  94. package/dist/lib/opencode-config-editor.d.ts +1 -0
  95. package/dist/lib/opencode-config-editor.js +6 -1
  96. package/dist/lib/opencode-go.js +53 -5
  97. package/dist/lib/opencode-version-core.d.ts +23 -0
  98. package/dist/lib/opencode-version-core.js +49 -0
  99. package/dist/lib/opencode-version.d.ts +4 -3
  100. package/dist/lib/opencode-version.js +15 -11
  101. package/dist/lib/opencode-zen.d.ts +12 -1
  102. package/dist/lib/opencode-zen.js +98 -12
  103. package/dist/lib/provider-add.js +5 -2
  104. package/dist/lib/provider-registration.d.ts +19 -9
  105. package/dist/lib/provider-registration.js +17 -6
  106. package/dist/lib/quota-command-format.js +1 -1
  107. package/dist/lib/quota-exhaustion-projection.d.ts +11 -0
  108. package/dist/lib/quota-exhaustion-projection.js +25 -0
  109. package/dist/lib/quota-providers-remote.d.ts +4 -1
  110. package/dist/lib/quota-providers-remote.js +137 -22
  111. package/dist/lib/quota-providers.d.ts +1 -1
  112. package/dist/lib/quota-providers.js +12 -35
  113. package/dist/lib/quota-render-data.d.ts +6 -0
  114. package/dist/lib/quota-render-data.js +43 -17
  115. package/dist/lib/quota-reset-notifications.d.ts +17 -0
  116. package/dist/lib/quota-reset-notifications.js +11 -2
  117. package/dist/lib/quota-state-codec.js +19 -1
  118. package/dist/lib/quota-state.d.ts +7 -1
  119. package/dist/lib/quota-state.js +208 -34
  120. package/dist/lib/quota-stats.js +21 -0
  121. package/dist/lib/quota-status.js +3 -51
  122. package/dist/lib/scoped-update.d.ts +1 -1
  123. package/dist/lib/synthetic.js +67 -48
  124. package/dist/lib/types.d.ts +49 -1
  125. package/dist/lib/types.js +16 -0
  126. package/dist/lib/xai.js +64 -24
  127. package/dist/plugin.d.ts +4 -3
  128. package/dist/plugin.js +293 -16
  129. package/dist/provider-logos/NOTICE.md +1 -1
  130. package/dist/provider-logos/OPENCODE-NOTICE.md +4 -3
  131. package/dist/providers/alibaba-coding-plan.js +107 -102
  132. package/dist/providers/alibaba-token-plan.js +17 -0
  133. package/dist/providers/anthropic.d.ts +12 -3
  134. package/dist/providers/anthropic.js +71 -219
  135. package/dist/providers/cache-policies.d.ts +11 -4
  136. package/dist/providers/cache-policies.js +19 -13
  137. package/dist/providers/claude-agent.d.ts +19 -0
  138. package/dist/providers/claude-agent.js +196 -0
  139. package/dist/providers/copilot.js +12 -2
  140. package/dist/providers/glm-coding-plan-provider.d.ts +3 -0
  141. package/dist/providers/glm-coding-plan-provider.js +5 -1
  142. package/dist/providers/google-account-format.js +2 -0
  143. package/dist/providers/google-agy.d.ts +6 -5
  144. package/dist/providers/google-agy.js +55 -17
  145. package/dist/providers/google-gemini-cli.js +13 -2
  146. package/dist/providers/kilo.js +10 -1
  147. package/dist/providers/kimi-code.js +13 -6
  148. package/dist/providers/mimo.js +9 -2
  149. package/dist/providers/minimax-coding-plan.js +28 -5
  150. package/dist/providers/nanogpt.js +4 -0
  151. package/dist/providers/ollama-cloud.js +3 -0
  152. package/dist/providers/openai.js +1 -0
  153. package/dist/providers/opencode-go.js +11 -1
  154. package/dist/providers/opencode-zen.js +32 -3
  155. package/dist/providers/openrouter.js +4 -0
  156. package/dist/providers/quota-providers.js +46 -9
  157. package/dist/providers/registry.js +2 -0
  158. package/dist/providers/result-helpers.d.ts +6 -0
  159. package/dist/providers/result-helpers.js +18 -2
  160. package/dist/rpc.d.ts +440 -4
  161. package/dist/rpc.js +507 -2
  162. package/dist/ui/assets/{index-Cs-nrywz.css → index-BcueIm3Z.css} +1 -1
  163. package/dist/ui/assets/index-C6qRSoh8.js +10 -0
  164. package/dist/ui/assets/{popover-DKRrwr_K.js → popover-4bFSvRZ7.js} +1 -1
  165. package/dist/ui/assets/providers/claude-agent.svg +3 -0
  166. package/dist/ui/index.html +2 -2
  167. package/package.json +15 -7
  168. package/dist/bin/opencode-quota-gui.d.ts.map +0 -1
  169. package/dist/bin/opencode-quota-gui.js.map +0 -1
  170. package/dist/contracts/analytics-entity.d.ts.map +0 -1
  171. package/dist/contracts/analytics-entity.js.map +0 -1
  172. package/dist/contracts/analytics-temporal.d.ts.map +0 -1
  173. package/dist/contracts/analytics-temporal.js.map +0 -1
  174. package/dist/contracts/build-identity.d.ts.map +0 -1
  175. package/dist/contracts/card-order.d.ts.map +0 -1
  176. package/dist/contracts/card-order.js.map +0 -1
  177. package/dist/contracts/collision-safe-key.d.ts.map +0 -1
  178. package/dist/contracts/collision-safe-key.js.map +0 -1
  179. package/dist/contracts/dashboard.d.ts.map +0 -1
  180. package/dist/contracts/dashboard.js.map +0 -1
  181. package/dist/contracts/guards.d.ts.map +0 -1
  182. package/dist/contracts/guards.js.map +0 -1
  183. package/dist/contracts/identity.d.ts.map +0 -1
  184. package/dist/contracts/identity.js.map +0 -1
  185. package/dist/contracts/openai-quota.d.ts.map +0 -1
  186. package/dist/contracts/openai-quota.js.map +0 -1
  187. package/dist/contracts/ranges.d.ts.map +0 -1
  188. package/dist/contracts/ranges.js.map +0 -1
  189. package/dist/contracts/settings.d.ts.map +0 -1
  190. package/dist/contracts/settings.js.map +0 -1
  191. package/dist/contracts/temporal.d.ts.map +0 -1
  192. package/dist/contracts/temporal.js.map +0 -1
  193. package/dist/contracts/time-zone.d.ts.map +0 -1
  194. package/dist/contracts/time-zone.js.map +0 -1
  195. package/dist/gui/aggregation.d.ts.map +0 -1
  196. package/dist/gui/aggregation.js.map +0 -1
  197. package/dist/gui/analytics-bridge.d.ts.map +0 -1
  198. package/dist/gui/analytics-bridge.js.map +0 -1
  199. package/dist/gui/analytics-engine.d.ts.map +0 -1
  200. package/dist/gui/analytics-engine.js.map +0 -1
  201. package/dist/gui/analytics-indexes.d.ts.map +0 -1
  202. package/dist/gui/analytics-indexes.js.map +0 -1
  203. package/dist/gui/analytics-model.d.ts.map +0 -1
  204. package/dist/gui/analytics-model.js.map +0 -1
  205. package/dist/gui/analytics-pricing-revision.d.ts.map +0 -1
  206. package/dist/gui/analytics-pricing-revision.js.map +0 -1
  207. package/dist/gui/analytics-protocol.d.ts.map +0 -1
  208. package/dist/gui/analytics-protocol.js.map +0 -1
  209. package/dist/gui/analytics-reader.d.ts.map +0 -1
  210. package/dist/gui/analytics-reader.js.map +0 -1
  211. package/dist/gui/analytics-service.d.ts.map +0 -1
  212. package/dist/gui/analytics-service.js.map +0 -1
  213. package/dist/gui/analytics-state.d.ts.map +0 -1
  214. package/dist/gui/analytics-state.js.map +0 -1
  215. package/dist/gui/analytics-worker-runtime.d.ts.map +0 -1
  216. package/dist/gui/analytics-worker-runtime.js.map +0 -1
  217. package/dist/gui/analytics-worker.d.ts.map +0 -1
  218. package/dist/gui/analytics-worker.js.map +0 -1
  219. package/dist/gui/config.d.ts.map +0 -1
  220. package/dist/gui/config.js.map +0 -1
  221. package/dist/gui/identity.d.ts.map +0 -1
  222. package/dist/gui/identity.js.map +0 -1
  223. package/dist/gui/lifecycle.d.ts.map +0 -1
  224. package/dist/gui/lifecycle.js.map +0 -1
  225. package/dist/gui/log.d.ts.map +0 -1
  226. package/dist/gui/log.js.map +0 -1
  227. package/dist/gui/provider-cards.d.ts.map +0 -1
  228. package/dist/gui/provider-cards.js.map +0 -1
  229. package/dist/gui/server.d.ts.map +0 -1
  230. package/dist/gui/server.js.map +0 -1
  231. package/dist/gui/settings-file-opener.d.ts.map +0 -1
  232. package/dist/gui/settings-file-opener.js.map +0 -1
  233. package/dist/gui/snapshot-service.d.ts.map +0 -1
  234. package/dist/gui/snapshot-service.js.map +0 -1
  235. package/dist/gui/sources.d.ts.map +0 -1
  236. package/dist/gui/sources.js.map +0 -1
  237. package/dist/gui/sse.d.ts.map +0 -1
  238. package/dist/gui/sse.js.map +0 -1
  239. package/dist/gui/temporal-quota-policy-data.d.ts.map +0 -1
  240. package/dist/gui/temporal-quota-policy-data.js.map +0 -1
  241. package/dist/gui/temporal-quota-policy.d.ts.map +0 -1
  242. package/dist/gui/temporal-quota-policy.js.map +0 -1
  243. package/dist/gui/temporal-status.d.ts.map +0 -1
  244. package/dist/gui/temporal-status.js.map +0 -1
  245. package/dist/gui/time-zone.d.ts.map +0 -1
  246. package/dist/gui/time-zone.js.map +0 -1
  247. package/dist/index.d.ts.map +0 -1
  248. package/dist/index.js.map +0 -1
  249. package/dist/lib/accounting-format.d.ts.map +0 -1
  250. package/dist/lib/accounting-format.js.map +0 -1
  251. package/dist/lib/alibaba-auth.d.ts.map +0 -1
  252. package/dist/lib/alibaba-auth.js.map +0 -1
  253. package/dist/lib/alibaba-coding-plan-local-quota.d.ts +0 -47
  254. package/dist/lib/alibaba-coding-plan-local-quota.d.ts.map +0 -1
  255. package/dist/lib/alibaba-coding-plan-local-quota.js +0 -146
  256. package/dist/lib/alibaba-coding-plan-local-quota.js.map +0 -1
  257. package/dist/lib/alibaba-token-plan.d.ts.map +0 -1
  258. package/dist/lib/alibaba-token-plan.js.map +0 -1
  259. package/dist/lib/anthropic-auth.d.ts.map +0 -1
  260. package/dist/lib/anthropic-auth.js.map +0 -1
  261. package/dist/lib/anthropic.d.ts.map +0 -1
  262. package/dist/lib/anthropic.js.map +0 -1
  263. package/dist/lib/api-key-resolver.d.ts.map +0 -1
  264. package/dist/lib/api-key-resolver.js.map +0 -1
  265. package/dist/lib/atomic-json.d.ts.map +0 -1
  266. package/dist/lib/atomic-json.js.map +0 -1
  267. package/dist/lib/chutes-config.d.ts.map +0 -1
  268. package/dist/lib/chutes-config.js.map +0 -1
  269. package/dist/lib/chutes.d.ts.map +0 -1
  270. package/dist/lib/chutes.js.map +0 -1
  271. package/dist/lib/cli-reports.d.ts.map +0 -1
  272. package/dist/lib/cli-reports.js.map +0 -1
  273. package/dist/lib/cli-show.d.ts.map +0 -1
  274. package/dist/lib/cli-show.js.map +0 -1
  275. package/dist/lib/cli-status.d.ts.map +0 -1
  276. package/dist/lib/cli-status.js.map +0 -1
  277. package/dist/lib/command-parsing.d.ts.map +0 -1
  278. package/dist/lib/command-parsing.js.map +0 -1
  279. package/dist/lib/config-file-utils.d.ts.map +0 -1
  280. package/dist/lib/config-file-utils.js.map +0 -1
  281. package/dist/lib/config-write-target.d.ts.map +0 -1
  282. package/dist/lib/config-write-target.js.map +0 -1
  283. package/dist/lib/config.d.ts.map +0 -1
  284. package/dist/lib/config.js.map +0 -1
  285. package/dist/lib/copilot.d.ts.map +0 -1
  286. package/dist/lib/copilot.js.map +0 -1
  287. package/dist/lib/cursor-detection.d.ts.map +0 -1
  288. package/dist/lib/cursor-detection.js.map +0 -1
  289. package/dist/lib/cursor-pricing.d.ts.map +0 -1
  290. package/dist/lib/cursor-pricing.js.map +0 -1
  291. package/dist/lib/cursor-usage.d.ts.map +0 -1
  292. package/dist/lib/cursor-usage.js.map +0 -1
  293. package/dist/lib/dashboard-visibility.d.ts.map +0 -1
  294. package/dist/lib/dashboard-visibility.js.map +0 -1
  295. package/dist/lib/deepseek-auth.d.ts.map +0 -1
  296. package/dist/lib/deepseek-auth.js.map +0 -1
  297. package/dist/lib/deepseek.d.ts.map +0 -1
  298. package/dist/lib/deepseek.js.map +0 -1
  299. package/dist/lib/display-sanitize.d.ts.map +0 -1
  300. package/dist/lib/display-sanitize.js.map +0 -1
  301. package/dist/lib/entries.d.ts.map +0 -1
  302. package/dist/lib/entries.js.map +0 -1
  303. package/dist/lib/env-template.d.ts.map +0 -1
  304. package/dist/lib/env-template.js.map +0 -1
  305. package/dist/lib/format-utils.d.ts.map +0 -1
  306. package/dist/lib/format-utils.js.map +0 -1
  307. package/dist/lib/format.d.ts.map +0 -1
  308. package/dist/lib/format.js.map +0 -1
  309. package/dist/lib/glm-coding-plan.d.ts.map +0 -1
  310. package/dist/lib/glm-coding-plan.js.map +0 -1
  311. package/dist/lib/google-agy-companion.d.ts.map +0 -1
  312. package/dist/lib/google-agy-companion.js.map +0 -1
  313. package/dist/lib/google-agy.d.ts.map +0 -1
  314. package/dist/lib/google-agy.js.map +0 -1
  315. package/dist/lib/google-companion-credentials.d.ts.map +0 -1
  316. package/dist/lib/google-companion-credentials.js.map +0 -1
  317. package/dist/lib/google-gemini-cli-companion.d.ts.map +0 -1
  318. package/dist/lib/google-gemini-cli-companion.js.map +0 -1
  319. package/dist/lib/google-gemini-cli.d.ts.map +0 -1
  320. package/dist/lib/google-gemini-cli.js.map +0 -1
  321. package/dist/lib/google-token-cache.d.ts.map +0 -1
  322. package/dist/lib/google-token-cache.js.map +0 -1
  323. package/dist/lib/grouped-entry-normalization.d.ts.map +0 -1
  324. package/dist/lib/grouped-entry-normalization.js.map +0 -1
  325. package/dist/lib/grouped-header-format.d.ts.map +0 -1
  326. package/dist/lib/grouped-header-format.js.map +0 -1
  327. package/dist/lib/gui-config-target.d.ts.map +0 -1
  328. package/dist/lib/gui-config-target.js.map +0 -1
  329. package/dist/lib/home-dir-display.d.ts.map +0 -1
  330. package/dist/lib/home-dir-display.js.map +0 -1
  331. package/dist/lib/http.d.ts.map +0 -1
  332. package/dist/lib/http.js.map +0 -1
  333. package/dist/lib/init-installer.d.ts.map +0 -1
  334. package/dist/lib/init-installer.js.map +0 -1
  335. package/dist/lib/jsonc.d.ts.map +0 -1
  336. package/dist/lib/jsonc.js.map +0 -1
  337. package/dist/lib/kilo-config.d.ts.map +0 -1
  338. package/dist/lib/kilo-config.js.map +0 -1
  339. package/dist/lib/kilo.d.ts.map +0 -1
  340. package/dist/lib/kilo.js.map +0 -1
  341. package/dist/lib/kimi-auth.d.ts.map +0 -1
  342. package/dist/lib/kimi-auth.js.map +0 -1
  343. package/dist/lib/kimi-endpoints.d.ts.map +0 -1
  344. package/dist/lib/kimi-endpoints.js.map +0 -1
  345. package/dist/lib/kimi.d.ts.map +0 -1
  346. package/dist/lib/kimi.js.map +0 -1
  347. package/dist/lib/maintainer-announcements.d.ts.map +0 -1
  348. package/dist/lib/maintainer-announcements.js.map +0 -1
  349. package/dist/lib/map-with-concurrency.d.ts.map +0 -1
  350. package/dist/lib/map-with-concurrency.js.map +0 -1
  351. package/dist/lib/markdown-table.d.ts.map +0 -1
  352. package/dist/lib/markdown-table.js.map +0 -1
  353. package/dist/lib/mimo-config.d.ts.map +0 -1
  354. package/dist/lib/mimo-config.js.map +0 -1
  355. package/dist/lib/mimo.d.ts.map +0 -1
  356. package/dist/lib/mimo.js.map +0 -1
  357. package/dist/lib/minimax-auth.d.ts.map +0 -1
  358. package/dist/lib/minimax-auth.js.map +0 -1
  359. package/dist/lib/minimax-endpoints.d.ts.map +0 -1
  360. package/dist/lib/minimax-endpoints.js.map +0 -1
  361. package/dist/lib/modelsdev-pricing.d.ts.map +0 -1
  362. package/dist/lib/modelsdev-pricing.js.map +0 -1
  363. package/dist/lib/modelsdev-temporal.d.ts.map +0 -1
  364. package/dist/lib/modelsdev-temporal.js.map +0 -1
  365. package/dist/lib/nanogpt-config.d.ts.map +0 -1
  366. package/dist/lib/nanogpt-config.js.map +0 -1
  367. package/dist/lib/nanogpt.d.ts.map +0 -1
  368. package/dist/lib/nanogpt.js.map +0 -1
  369. package/dist/lib/ollama-cloud-config.d.ts.map +0 -1
  370. package/dist/lib/ollama-cloud-config.js.map +0 -1
  371. package/dist/lib/ollama-cloud.d.ts.map +0 -1
  372. package/dist/lib/ollama-cloud.js.map +0 -1
  373. package/dist/lib/openai.d.ts.map +0 -1
  374. package/dist/lib/openai.js.map +0 -1
  375. package/dist/lib/opencode-auth-sqlite.d.ts.map +0 -1
  376. package/dist/lib/opencode-auth-sqlite.js.map +0 -1
  377. package/dist/lib/opencode-auth.d.ts.map +0 -1
  378. package/dist/lib/opencode-auth.js.map +0 -1
  379. package/dist/lib/opencode-config-editor.d.ts.map +0 -1
  380. package/dist/lib/opencode-config-editor.js.map +0 -1
  381. package/dist/lib/opencode-config-providers.d.ts.map +0 -1
  382. package/dist/lib/opencode-config-providers.js.map +0 -1
  383. package/dist/lib/opencode-config-read.d.ts.map +0 -1
  384. package/dist/lib/opencode-config-read.js.map +0 -1
  385. package/dist/lib/opencode-console-auth.d.ts.map +0 -1
  386. package/dist/lib/opencode-console-auth.js.map +0 -1
  387. package/dist/lib/opencode-db-path.d.ts.map +0 -1
  388. package/dist/lib/opencode-db-path.js.map +0 -1
  389. package/dist/lib/opencode-go-auth.d.ts.map +0 -1
  390. package/dist/lib/opencode-go-auth.js.map +0 -1
  391. package/dist/lib/opencode-go.d.ts.map +0 -1
  392. package/dist/lib/opencode-go.js.map +0 -1
  393. package/dist/lib/opencode-runtime-paths.d.ts.map +0 -1
  394. package/dist/lib/opencode-runtime-paths.js.map +0 -1
  395. package/dist/lib/opencode-sqlite.d.ts.map +0 -1
  396. package/dist/lib/opencode-sqlite.js.map +0 -1
  397. package/dist/lib/opencode-storage.d.ts.map +0 -1
  398. package/dist/lib/opencode-storage.js.map +0 -1
  399. package/dist/lib/opencode-version.d.ts.map +0 -1
  400. package/dist/lib/opencode-version.js.map +0 -1
  401. package/dist/lib/opencode-zen.d.ts.map +0 -1
  402. package/dist/lib/opencode-zen.js.map +0 -1
  403. package/dist/lib/openrouter.d.ts.map +0 -1
  404. package/dist/lib/openrouter.js.map +0 -1
  405. package/dist/lib/private-state-paths.d.ts.map +0 -1
  406. package/dist/lib/private-state-paths.js.map +0 -1
  407. package/dist/lib/provider-add-command.d.ts.map +0 -1
  408. package/dist/lib/provider-add-command.js.map +0 -1
  409. package/dist/lib/provider-add-json-v1-questionnaire.d.ts.map +0 -1
  410. package/dist/lib/provider-add-json-v1-questionnaire.js.map +0 -1
  411. package/dist/lib/provider-add.d.ts.map +0 -1
  412. package/dist/lib/provider-add.js.map +0 -1
  413. package/dist/lib/provider-availability.d.ts.map +0 -1
  414. package/dist/lib/provider-availability.js.map +0 -1
  415. package/dist/lib/provider-metadata.d.ts.map +0 -1
  416. package/dist/lib/provider-metadata.js.map +0 -1
  417. package/dist/lib/provider-model-matching.d.ts.map +0 -1
  418. package/dist/lib/provider-model-matching.js.map +0 -1
  419. package/dist/lib/provider-registration.d.ts.map +0 -1
  420. package/dist/lib/provider-registration.js.map +0 -1
  421. package/dist/lib/quota-accounting-projection.d.ts.map +0 -1
  422. package/dist/lib/quota-accounting-projection.js.map +0 -1
  423. package/dist/lib/quota-columns.d.ts.map +0 -1
  424. package/dist/lib/quota-columns.js.map +0 -1
  425. package/dist/lib/quota-command-format.d.ts.map +0 -1
  426. package/dist/lib/quota-command-format.js.map +0 -1
  427. package/dist/lib/quota-dialog-command-specs.d.ts.map +0 -1
  428. package/dist/lib/quota-dialog-command-specs.js.map +0 -1
  429. package/dist/lib/quota-dialog-commands.d.ts.map +0 -1
  430. package/dist/lib/quota-dialog-commands.js.map +0 -1
  431. package/dist/lib/quota-entry-display.d.ts.map +0 -1
  432. package/dist/lib/quota-entry-display.js.map +0 -1
  433. package/dist/lib/quota-exhaustion-projection.d.ts.map +0 -1
  434. package/dist/lib/quota-exhaustion-projection.js.map +0 -1
  435. package/dist/lib/quota-export-types.d.ts.map +0 -1
  436. package/dist/lib/quota-export-types.js.map +0 -1
  437. package/dist/lib/quota-export.d.ts.map +0 -1
  438. package/dist/lib/quota-export.js.map +0 -1
  439. package/dist/lib/quota-format-style.d.ts.map +0 -1
  440. package/dist/lib/quota-format-style.js.map +0 -1
  441. package/dist/lib/quota-providers-local.d.ts.map +0 -1
  442. package/dist/lib/quota-providers-local.js.map +0 -1
  443. package/dist/lib/quota-providers-remote.d.ts.map +0 -1
  444. package/dist/lib/quota-providers-remote.js.map +0 -1
  445. package/dist/lib/quota-providers.d.ts.map +0 -1
  446. package/dist/lib/quota-providers.js.map +0 -1
  447. package/dist/lib/quota-render-data.d.ts.map +0 -1
  448. package/dist/lib/quota-render-data.js.map +0 -1
  449. package/dist/lib/quota-report-message.d.ts.map +0 -1
  450. package/dist/lib/quota-report-message.js.map +0 -1
  451. package/dist/lib/quota-reset-notifications.d.ts.map +0 -1
  452. package/dist/lib/quota-reset-notifications.js.map +0 -1
  453. package/dist/lib/quota-retry-wait.d.ts.map +0 -1
  454. package/dist/lib/quota-retry-wait.js.map +0 -1
  455. package/dist/lib/quota-runtime-context.d.ts.map +0 -1
  456. package/dist/lib/quota-runtime-context.js.map +0 -1
  457. package/dist/lib/quota-state-codec.d.ts.map +0 -1
  458. package/dist/lib/quota-state-codec.js.map +0 -1
  459. package/dist/lib/quota-state.d.ts.map +0 -1
  460. package/dist/lib/quota-state.js.map +0 -1
  461. package/dist/lib/quota-stats-format.d.ts.map +0 -1
  462. package/dist/lib/quota-stats-format.js.map +0 -1
  463. package/dist/lib/quota-stats.d.ts.map +0 -1
  464. package/dist/lib/quota-stats.js.map +0 -1
  465. package/dist/lib/quota-status.d.ts.map +0 -1
  466. package/dist/lib/quota-status.js.map +0 -1
  467. package/dist/lib/quota-surface-data.d.ts.map +0 -1
  468. package/dist/lib/quota-surface-data.js.map +0 -1
  469. package/dist/lib/quota-telemetry.d.ts.map +0 -1
  470. package/dist/lib/quota-telemetry.js.map +0 -1
  471. package/dist/lib/report-document.d.ts.map +0 -1
  472. package/dist/lib/report-document.js.map +0 -1
  473. package/dist/lib/resolved-auth-identity.d.ts.map +0 -1
  474. package/dist/lib/resolved-auth-identity.js.map +0 -1
  475. package/dist/lib/runtime-provider-ids.d.ts.map +0 -1
  476. package/dist/lib/runtime-provider-ids.js.map +0 -1
  477. package/dist/lib/scoped-query-chunks.d.ts.map +0 -1
  478. package/dist/lib/scoped-query-chunks.js.map +0 -1
  479. package/dist/lib/scoped-update-migration.d.ts.map +0 -1
  480. package/dist/lib/scoped-update-migration.js.map +0 -1
  481. package/dist/lib/scoped-update.d.ts.map +0 -1
  482. package/dist/lib/scoped-update.js.map +0 -1
  483. package/dist/lib/session-tokens-format.d.ts.map +0 -1
  484. package/dist/lib/session-tokens-format.js.map +0 -1
  485. package/dist/lib/session-tokens.d.ts.map +0 -1
  486. package/dist/lib/session-tokens.js.map +0 -1
  487. package/dist/lib/synthetic-config.d.ts.map +0 -1
  488. package/dist/lib/synthetic-config.js.map +0 -1
  489. package/dist/lib/synthetic.d.ts.map +0 -1
  490. package/dist/lib/synthetic.js.map +0 -1
  491. package/dist/lib/toast-format-grouped.d.ts.map +0 -1
  492. package/dist/lib/toast-format-grouped.js.map +0 -1
  493. package/dist/lib/token-buckets.d.ts.map +0 -1
  494. package/dist/lib/token-buckets.js.map +0 -1
  495. package/dist/lib/token-cost.d.ts.map +0 -1
  496. package/dist/lib/token-cost.js.map +0 -1
  497. package/dist/lib/tui-compact-format.d.ts.map +0 -1
  498. package/dist/lib/tui-compact-format.js.map +0 -1
  499. package/dist/lib/tui-panel-state.d.ts.map +0 -1
  500. package/dist/lib/tui-panel-state.js.map +0 -1
  501. package/dist/lib/tui-prompt-bar-format.d.ts.map +0 -1
  502. package/dist/lib/tui-prompt-bar-format.js.map +0 -1
  503. package/dist/lib/tui-sidebar-format.d.ts.map +0 -1
  504. package/dist/lib/tui-sidebar-format.js.map +0 -1
  505. package/dist/lib/types.d.ts.map +0 -1
  506. package/dist/lib/types.js.map +0 -1
  507. package/dist/lib/usage-ownership.d.ts.map +0 -1
  508. package/dist/lib/usage-ownership.js.map +0 -1
  509. package/dist/lib/version.d.ts.map +0 -1
  510. package/dist/lib/version.js.map +0 -1
  511. package/dist/lib/xai.d.ts.map +0 -1
  512. package/dist/lib/xai.js.map +0 -1
  513. package/dist/lib/zai-auth.d.ts.map +0 -1
  514. package/dist/lib/zai-auth.js.map +0 -1
  515. package/dist/lib/zai.d.ts.map +0 -1
  516. package/dist/lib/zai.js.map +0 -1
  517. package/dist/lib/zhipu-auth.d.ts.map +0 -1
  518. package/dist/lib/zhipu-auth.js.map +0 -1
  519. package/dist/lib/zhipu.d.ts.map +0 -1
  520. package/dist/lib/zhipu.js.map +0 -1
  521. package/dist/plugin.d.ts.map +0 -1
  522. package/dist/plugin.js.map +0 -1
  523. package/dist/providers/accounting-decimal.d.ts.map +0 -1
  524. package/dist/providers/accounting-decimal.js.map +0 -1
  525. package/dist/providers/alibaba-coding-plan.d.ts.map +0 -1
  526. package/dist/providers/alibaba-coding-plan.js.map +0 -1
  527. package/dist/providers/alibaba-token-plan.d.ts.map +0 -1
  528. package/dist/providers/alibaba-token-plan.js.map +0 -1
  529. package/dist/providers/anthropic.d.ts.map +0 -1
  530. package/dist/providers/anthropic.js.map +0 -1
  531. package/dist/providers/cache-policies.d.ts.map +0 -1
  532. package/dist/providers/cache-policies.js.map +0 -1
  533. package/dist/providers/chutes.d.ts.map +0 -1
  534. package/dist/providers/chutes.js.map +0 -1
  535. package/dist/providers/copilot.d.ts.map +0 -1
  536. package/dist/providers/copilot.js.map +0 -1
  537. package/dist/providers/cursor.d.ts.map +0 -1
  538. package/dist/providers/cursor.js.map +0 -1
  539. package/dist/providers/deepseek.d.ts.map +0 -1
  540. package/dist/providers/deepseek.js.map +0 -1
  541. package/dist/providers/glm-coding-plan-provider.d.ts.map +0 -1
  542. package/dist/providers/glm-coding-plan-provider.js.map +0 -1
  543. package/dist/providers/google-account-format.d.ts.map +0 -1
  544. package/dist/providers/google-account-format.js.map +0 -1
  545. package/dist/providers/google-agy.d.ts.map +0 -1
  546. package/dist/providers/google-agy.js.map +0 -1
  547. package/dist/providers/google-gemini-cli.d.ts.map +0 -1
  548. package/dist/providers/google-gemini-cli.js.map +0 -1
  549. package/dist/providers/kilo.d.ts.map +0 -1
  550. package/dist/providers/kilo.js.map +0 -1
  551. package/dist/providers/kimi-code.d.ts.map +0 -1
  552. package/dist/providers/kimi-code.js.map +0 -1
  553. package/dist/providers/mimo.d.ts.map +0 -1
  554. package/dist/providers/mimo.js.map +0 -1
  555. package/dist/providers/minimax-coding-plan.d.ts.map +0 -1
  556. package/dist/providers/minimax-coding-plan.js.map +0 -1
  557. package/dist/providers/nanogpt.d.ts.map +0 -1
  558. package/dist/providers/nanogpt.js.map +0 -1
  559. package/dist/providers/ollama-cloud.d.ts.map +0 -1
  560. package/dist/providers/ollama-cloud.js.map +0 -1
  561. package/dist/providers/openai.d.ts.map +0 -1
  562. package/dist/providers/openai.js.map +0 -1
  563. package/dist/providers/opencode-go.d.ts.map +0 -1
  564. package/dist/providers/opencode-go.js.map +0 -1
  565. package/dist/providers/opencode-zen.d.ts.map +0 -1
  566. package/dist/providers/opencode-zen.js.map +0 -1
  567. package/dist/providers/openrouter.d.ts.map +0 -1
  568. package/dist/providers/openrouter.js.map +0 -1
  569. package/dist/providers/quota-providers.d.ts.map +0 -1
  570. package/dist/providers/quota-providers.js.map +0 -1
  571. package/dist/providers/registry.d.ts.map +0 -1
  572. package/dist/providers/registry.js.map +0 -1
  573. package/dist/providers/result-helpers.d.ts.map +0 -1
  574. package/dist/providers/result-helpers.js.map +0 -1
  575. package/dist/providers/synthetic.d.ts.map +0 -1
  576. package/dist/providers/synthetic.js.map +0 -1
  577. package/dist/providers/xai.d.ts.map +0 -1
  578. package/dist/providers/xai.js.map +0 -1
  579. package/dist/providers/zai.d.ts.map +0 -1
  580. package/dist/providers/zai.js.map +0 -1
  581. package/dist/providers/zhipu.d.ts.map +0 -1
  582. package/dist/providers/zhipu.js.map +0 -1
  583. package/dist/rpc.d.ts.map +0 -1
  584. package/dist/rpc.js.map +0 -1
  585. package/dist/ui/assets/index-D9lFKhSN.js +0 -9
@@ -1,3 +1,5 @@
1
+ import { providerFailureCategoryForHttpStatus } from "../contracts/provider-failure.js";
2
+ import { createApiKeyRetryGuard, retryAfterDeadline } from "./api-key-retry-after.js";
1
3
  import { sanitizeDisplayText } from "./display-sanitize.js";
2
4
  import { fetchWithTimeout } from "./http.js";
3
5
  import { consoleBaseUrl, consoleHeaders, } from "./opencode-console-auth.js";
@@ -8,6 +10,20 @@ const SESSION_ERROR = "OpenCode Console session expired or invalid. Run `opencod
8
10
  * one US dollar is 100,000,000 micro-cents (billing units).
9
11
  */
10
12
  export const OPENCODE_ZEN_BILLING_UNITS_PER_DOLLAR = 100_000_000;
13
+ const routeGuard = createApiKeyRetryGuard((retryAtMs) => ({
14
+ success: false,
15
+ error: "OpenCode Console request error 429",
16
+ failureCategory: providerFailureCategoryForHttpStatus(429),
17
+ retryAtMs,
18
+ }));
19
+ // Coalesce whole queries so a waiter cannot resend optional routes that settled
20
+ // while it was waiting for the required balance route.
21
+ const quotaQueryGuard = createApiKeyRetryGuard((retryAtMs) => ({
22
+ success: false,
23
+ error: "OpenCode Console billing/status error 429",
24
+ failureCategory: providerFailureCategoryForHttpStatus(429),
25
+ retryAtMs,
26
+ }));
11
27
  function asRecord(value) {
12
28
  return value && typeof value === "object" && !Array.isArray(value)
13
29
  ? value
@@ -217,7 +233,26 @@ function sanitizeMessage(text, secrets = [], maxLength = 120) {
217
233
  }
218
234
  return (sanitized || "unknown").slice(0, maxLength);
219
235
  }
220
- async function fetchConsoleRoute(params) {
236
+ /** One cooldown per workspace credential and route; other workspaces are unaffected. */
237
+ function fetchConsoleRoute(params) {
238
+ const { credential } = params;
239
+ const identity = JSON.stringify([
240
+ credential.accessToken,
241
+ credential.orgId ?? null,
242
+ consoleBaseUrl(credential),
243
+ params.path ?? params.route,
244
+ ]);
245
+ return routeGuard(identity, () => {
246
+ params.onRequest?.();
247
+ return requestConsoleRoute(params);
248
+ }, params.timeoutMs, (retryAtMs) => ({
249
+ success: false,
250
+ error: `OpenCode Console ${params.route} error 429`,
251
+ failureCategory: providerFailureCategoryForHttpStatus(429),
252
+ retryAtMs,
253
+ }));
254
+ }
255
+ async function requestConsoleRoute(params) {
221
256
  const path = params.path ?? params.route;
222
257
  try {
223
258
  return await fetchWithTimeout(`${consoleBaseUrl(params.credential)}/api/${path}`, {
@@ -228,19 +263,23 @@ async function fetchConsoleRoute(params) {
228
263
  },
229
264
  timeoutMs: params.timeoutMs,
230
265
  consume: async (response) => {
231
- // Redirects and 401 mean the whole session is gone; a 403 is treated as
232
- // a per-route failure so optional routes can fall back gracefully.
266
+ // Redirects and 401 mean the whole session is gone; a 403 stays a
267
+ // per-route failure so optional routes can fall back gracefully, but it
268
+ // is still an authorization outcome at the HTTP boundary.
233
269
  if ((response.status >= 300 && response.status < 400) || response.status === 401) {
234
- return { success: false, error: SESSION_ERROR };
270
+ return { success: false, error: SESSION_ERROR, failureCategory: "credentials" };
235
271
  }
236
272
  if (!response.ok) {
273
+ const retryAtMs = retryAfterDeadline(response);
237
274
  return {
238
275
  success: false,
239
276
  error: `OpenCode Console ${params.route} error ${response.status}`,
277
+ failureCategory: providerFailureCategoryForHttpStatus(response.status),
278
+ ...(retryAtMs !== undefined ? { retryAtMs } : {}),
240
279
  };
241
280
  }
242
281
  if (response.headers.get("content-type")?.includes("text/html")) {
243
- return { success: false, error: SESSION_ERROR };
282
+ return { success: false, error: SESSION_ERROR, failureCategory: "credentials" };
244
283
  }
245
284
  const text = await response.text();
246
285
  try {
@@ -252,6 +291,7 @@ async function fetchConsoleRoute(params) {
252
291
  return {
253
292
  success: false,
254
293
  error: `Could not parse OpenCode Console ${params.route} response`,
294
+ failureCategory: "provider_api",
255
295
  };
256
296
  }
257
297
  },
@@ -265,7 +305,11 @@ async function fetchConsoleRoute(params) {
265
305
  accountId,
266
306
  accountId && encodeURIComponent(accountId),
267
307
  ]);
268
- return { success: false, error: `OpenCode Console ${params.route} request failed: ${message}` };
308
+ return {
309
+ success: false,
310
+ error: `OpenCode Console ${params.route} request failed: ${message}`,
311
+ failureCategory: "provider_api",
312
+ };
269
313
  }
270
314
  }
271
315
  /** The member detail route key, or an error explaining why it cannot be fetched. */
@@ -275,6 +319,7 @@ function memberBudgetRequest(request) {
275
319
  return {
276
320
  success: false,
277
321
  error: "OpenCode Console member budgets unavailable: the Console sign-in has no account id",
322
+ failureCategory: "discovery",
278
323
  };
279
324
  }
280
325
  return fetchConsoleRoute({
@@ -284,14 +329,43 @@ function memberBudgetRequest(request) {
284
329
  parse: (json) => parseMemberBudgets(json, accountId),
285
330
  });
286
331
  }
287
- export async function queryOpenCodeZenQuota(credential, options = {}) {
332
+ export function queryOpenCodeZenQuota(credential, options = {}) {
333
+ const timeoutMs = options.requestTimeoutMs ?? CONSOLE_TIMEOUT_MS;
334
+ const now = new Date();
335
+ const identity = JSON.stringify([
336
+ credential.accessToken,
337
+ credential.orgId ?? null,
338
+ consoleBaseUrl(credential),
339
+ credential.accountId?.trim() ?? null,
340
+ currentUtcMonth(now),
341
+ ]);
342
+ return quotaQueryGuard(identity, () => queryOpenCodeZenQuotaOnce(credential, timeoutMs, now), timeoutMs);
343
+ }
344
+ async function queryOpenCodeZenQuotaOnce(credential, timeoutMs, now) {
288
345
  const request = {
289
346
  credential,
290
- timeoutMs: options.requestTimeoutMs ?? CONSOLE_TIMEOUT_MS,
347
+ timeoutMs,
291
348
  };
292
- const now = new Date();
349
+ // A fresh attempt sends every route concurrently. When billing/status did not
350
+ // start a request (an observed Retry-After block, or another in-flight
351
+ // request), settle it first: a cooldown result makes the optional routes
352
+ // pointless, so they are not sent.
353
+ let billingStarted = false;
354
+ const balancePending = fetchConsoleRoute({
355
+ ...request,
356
+ route: "billing/status",
357
+ parse: parseBalance,
358
+ onRequest: () => {
359
+ billingStarted = true;
360
+ },
361
+ });
362
+ if (!billingStarted) {
363
+ const early = await balancePending;
364
+ if (!early.success && early.retryAtMs !== undefined)
365
+ return early;
366
+ }
293
367
  const [balance, creditLimit, autoRecharge, member, monthlyUsage] = await Promise.all([
294
- fetchConsoleRoute({ ...request, route: "billing/status", parse: parseBalance }),
368
+ balancePending,
295
369
  fetchConsoleRoute({ ...request, route: "billing/account", parse: parseCreditLimit }),
296
370
  fetchConsoleRoute({ ...request, route: "billing/auto-recharge", parse: parseAutoRecharge }),
297
371
  memberBudgetRequest(request),
@@ -303,7 +377,7 @@ export async function queryOpenCodeZenQuota(credential, options = {}) {
303
377
  ]);
304
378
  const optional = [creditLimit, autoRecharge, member, monthlyUsage];
305
379
  if ([balance, ...optional].some((result) => !result.success && result.error === SESSION_ERROR)) {
306
- return { success: false, error: SESSION_ERROR };
380
+ return { success: false, error: SESSION_ERROR, failureCategory: "credentials" };
307
381
  }
308
382
  if (!balance.success)
309
383
  return balance;
@@ -328,6 +402,17 @@ export async function queryOpenCodeZenQuota(credential, options = {}) {
328
402
  memberBudgetsSkipped = true;
329
403
  }
330
404
  }
405
+ const optionalErrors = optional.flatMap((result) => result.success
406
+ ? []
407
+ : [
408
+ {
409
+ message: result.error,
410
+ ...(result.failureCategory !== undefined
411
+ ? { failureCategory: result.failureCategory }
412
+ : {}),
413
+ ...(result.retryAtMs !== undefined ? { retryAtMs: result.retryAtMs } : {}),
414
+ },
415
+ ]);
331
416
  return {
332
417
  success: true,
333
418
  data: {
@@ -342,7 +427,8 @@ export async function queryOpenCodeZenQuota(credential, options = {}) {
342
427
  budgetSource,
343
428
  memberBudgetsSkipped,
344
429
  },
345
- errors: optional.flatMap((result) => (result.success ? [] : [result.error])),
430
+ errors: optionalErrors.map((error) => error.message),
431
+ ...(optionalErrors.length > 0 ? { optionalErrors } : {}),
346
432
  };
347
433
  }
348
434
  //# sourceMappingURL=opencode-zen.js.map
@@ -101,8 +101,11 @@ function sidecarManagedComments(index, definition) {
101
101
  }
102
102
  export async function planProviderAdd(options) {
103
103
  const single = validateQuotaProviders([options.definition]);
104
- if (!single.value) {
105
- throw new Error(single.issues.map((issue) => issue.key + ": " + issue.message).join("\n"));
104
+ if (!single.value || single.value.length !== 1) {
105
+ const validationMessage = single.issues
106
+ .map((issue) => issue.key + ": " + issue.message)
107
+ .join("\n");
108
+ throw new Error(validationMessage || "definition is not a supported quota provider");
106
109
  }
107
110
  const definition = single.value[0];
108
111
  const configDir = options.configDir ?? getOpencodeRuntimeDirs().configDir;
@@ -1,7 +1,7 @@
1
- export type QuotaProviderAutoSetup = "yes" | "usually" | "manual_env_config" | "needs_quick_setup";
2
- export type QuotaProviderAuthentication = "opencode_auth_oauth_token" | "opencode_auth_api_key" | "companion_auth_oauth_token" | "local_cli_auth" | "github_oauth_or_pat" | "external_api_key" | "state_only";
1
+ export type QuotaProviderAutoSetup = "yes" | "usually" | "manual_env_config" | "needs_quick_setup" | "unavailable";
2
+ export type QuotaProviderAuthentication = "opencode_auth_oauth_token" | "opencode_auth_api_key" | "companion_auth_oauth_token" | "local_cli_auth" | "github_oauth_or_pat" | "external_api_key" | "state_only" | "unavailable";
3
3
  export type QuotaProviderAuthFallback = "env_api_key" | "global_opencode_config";
4
- export type QuotaProviderQuotaSource = "remote_api" | "local_estimation" | "local_runtime_accounting" | "local_cli_report";
4
+ export type QuotaProviderQuotaSource = "remote_api" | "local_estimation" | "local_runtime_accounting" | "local_cli_report" | "unavailable";
5
5
  export interface QuotaProviderShapeSource {
6
6
  recommendedReplacementId?: string;
7
7
  autoSetup: QuotaProviderAutoSetup;
@@ -24,12 +24,22 @@ export declare const QUOTA_PROVIDER_REGISTRATION_SOURCE: readonly [{
24
24
  readonly id: "anthropic";
25
25
  readonly label: "Anthropic";
26
26
  readonly runtimeIds: readonly ["anthropic"];
27
- readonly synonyms: readonly ["claude", "claude-code"];
27
+ readonly synonyms: readonly [];
28
+ readonly shape: {
29
+ readonly autoSetup: "unavailable";
30
+ readonly authentication: "unavailable";
31
+ readonly quota: "unavailable";
32
+ };
33
+ }, {
34
+ readonly id: "claude-agent";
35
+ readonly label: "Claude Agent";
36
+ readonly runtimeIds: readonly ["claude-agent", "claude-code"];
37
+ readonly synonyms: readonly ["claude-code", "claude"];
28
38
  readonly shape: {
29
39
  readonly autoSetup: "needs_quick_setup";
30
40
  readonly authentication: "local_cli_auth";
31
41
  readonly quota: "local_cli_report";
32
- readonly quickSetupAnchor: "anthropic-claude";
42
+ readonly quickSetupAnchor: "claude-agent";
33
43
  };
34
44
  }, {
35
45
  readonly id: "copilot";
@@ -95,10 +105,10 @@ export declare const QUOTA_PROVIDER_REGISTRATION_SOURCE: readonly [{
95
105
  readonly synonyms: readonly ["alibaba"];
96
106
  readonly liveLocalUsage: true;
97
107
  readonly shape: {
98
- readonly autoSetup: "yes";
99
- readonly authentication: "opencode_auth_api_key";
100
- readonly authFallbacks: readonly ["env_api_key", "global_opencode_config"];
101
- readonly quota: "local_estimation";
108
+ readonly autoSetup: "needs_quick_setup";
109
+ readonly authentication: "local_cli_auth";
110
+ readonly quota: "local_cli_report";
111
+ readonly quickSetupAnchor: "alibaba-coding-plan";
102
112
  };
103
113
  }, {
104
114
  readonly id: "alibaba-token-plan";
@@ -3,12 +3,23 @@ export const QUOTA_PROVIDER_REGISTRATION_SOURCE = [
3
3
  id: "anthropic",
4
4
  label: "Anthropic",
5
5
  runtimeIds: ["anthropic"],
6
- synonyms: ["claude", "claude-code"],
6
+ synonyms: [],
7
+ shape: {
8
+ autoSetup: "unavailable",
9
+ authentication: "unavailable",
10
+ quota: "unavailable",
11
+ },
12
+ },
13
+ {
14
+ id: "claude-agent",
15
+ label: "Claude Agent",
16
+ runtimeIds: ["claude-agent", "claude-code"],
17
+ synonyms: ["claude-code", "claude"],
7
18
  shape: {
8
19
  autoSetup: "needs_quick_setup",
9
20
  authentication: "local_cli_auth",
10
21
  quota: "local_cli_report",
11
- quickSetupAnchor: "anthropic-claude",
22
+ quickSetupAnchor: "claude-agent",
12
23
  },
13
24
  },
14
25
  {
@@ -80,10 +91,10 @@ export const QUOTA_PROVIDER_REGISTRATION_SOURCE = [
80
91
  synonyms: ["alibaba"],
81
92
  liveLocalUsage: true,
82
93
  shape: {
83
- autoSetup: "yes",
84
- authentication: "opencode_auth_api_key",
85
- authFallbacks: ["env_api_key", "global_opencode_config"],
86
- quota: "local_estimation",
94
+ autoSetup: "needs_quick_setup",
95
+ authentication: "local_cli_auth",
96
+ quota: "local_cli_report",
97
+ quickSetupAnchor: "alibaba-coding-plan",
87
98
  },
88
99
  },
89
100
  {
@@ -56,7 +56,7 @@ const DIALOG_TIME_WINDOWS = new Set([
56
56
  /**
57
57
  * The TUI dialog's label for a row: a time window's quota drops "quota" ("5h quota" is
58
58
  * "5h", "Weekly quota" is "Weekly"), since the dialog's table heads that column "window".
59
- * Other labels, such as "Month spend" or "Fable weekly quota", stay whole.
59
+ * Other labels, such as "Month spend" or "Fable", stay whole.
60
60
  */
61
61
  function getDialogMetricLabel(entry, metricLabel) {
62
62
  const metric = entry.semantic?.metric;
@@ -1,5 +1,16 @@
1
1
  import type { FixedWindowProjectionEvidence, QuotaRunwayProjection } from "./entries.js";
2
2
  export declare function isFixedWindowProjectionEvidence(value: unknown, resetTimeIso?: string): value is FixedWindowProjectionEvidence;
3
+ /**
4
+ * Builds fixed-window evidence for a provider window whose length is known and whose reset is
5
+ * observed. The start is inferred as `reset - duration`, which is only valid for windows that
6
+ * reset on a fixed cycle; callers must pass a duration that matches that window kind. Returns
7
+ * nothing unless the observation falls strictly inside the inferred window.
8
+ */
9
+ export declare function buildFixedWindowEvidence(params: {
10
+ durationMs: number;
11
+ resetTimeIso?: string;
12
+ observedAtMs: number;
13
+ }): FixedWindowProjectionEvidence | undefined;
3
14
  export declare function projectQuotaRunway(params: {
4
15
  percentRemaining: number;
5
16
  fixedWindow?: FixedWindowProjectionEvidence;
@@ -27,6 +27,31 @@ export function isFixedWindowProjectionEvidence(value, resetTimeIso) {
27
27
  return false;
28
28
  return true;
29
29
  }
30
+ /**
31
+ * Builds fixed-window evidence for a provider window whose length is known and whose reset is
32
+ * observed. The start is inferred as `reset - duration`, which is only valid for windows that
33
+ * reset on a fixed cycle; callers must pass a duration that matches that window kind. Returns
34
+ * nothing unless the observation falls strictly inside the inferred window.
35
+ */
36
+ export function buildFixedWindowEvidence(params) {
37
+ if (!(Number.isFinite(params.durationMs) && params.durationMs > 0))
38
+ return undefined;
39
+ if (!Number.isFinite(params.observedAtMs))
40
+ return undefined;
41
+ const endsAt = parseIsoTimestamp(params.resetTimeIso);
42
+ if (endsAt === null)
43
+ return undefined;
44
+ const startedAt = endsAt - params.durationMs;
45
+ if (!(startedAt < params.observedAtMs && params.observedAtMs < endsAt))
46
+ return undefined;
47
+ return {
48
+ kind: "fixed_window",
49
+ startedAtIso: new Date(startedAt).toISOString(),
50
+ observedAtIso: new Date(params.observedAtMs).toISOString(),
51
+ endsAtIso: new Date(endsAt).toISOString(),
52
+ fullReset: true,
53
+ };
54
+ }
30
55
  export function projectQuotaRunway(params) {
31
56
  const nowMs = params.nowMs ?? Date.now();
32
57
  if (!Number.isFinite(params.percentRemaining) || !Number.isFinite(nowMs))
@@ -1,3 +1,4 @@
1
+ import { type ProviderFailureCategory } from "../contracts/provider-failure.js";
1
2
  import type { QuotaToastEntry } from "./entries.js";
2
3
  import type { RemoteApiQuotaProviderDefinition } from "./quota-providers.js";
3
4
  export declare const QUOTA_PROVIDER_MAX_BODY_BYTES: number;
@@ -21,7 +22,9 @@ export type RemoteQuotaProviderResult = {
21
22
  } | {
22
23
  success: false;
23
24
  error: string;
25
+ failureCategory?: ProviderFailureCategory;
26
+ retryAtMs?: number;
24
27
  };
25
28
  export declare function resolveQuotaProviderApiKey(source: RemoteApiQuotaProviderDefinition): Promise<QuotaProviderAuthResolution>;
26
- export declare function fetchRemoteQuotaProvider(source: RemoteApiQuotaProviderDefinition, apiKey: string, requestTimeoutMs?: number): Promise<RemoteQuotaProviderResult>;
29
+ export declare function fetchRemoteQuotaProvider(source: RemoteApiQuotaProviderDefinition, apiKey: string | undefined, requestTimeoutMs?: number, fetcher?: typeof fetch): Promise<RemoteQuotaProviderResult>;
27
30
  //# sourceMappingURL=quota-providers-remote.d.ts.map
@@ -1,3 +1,5 @@
1
+ import { createHmac, randomBytes } from "node:crypto";
2
+ import { providerFailureCategoryForHttpStatus, } from "../contracts/provider-failure.js";
1
3
  import { createProviderApiKeyResolver, getApiKeyCheckedPaths, getGlobalOpencodeConfigCandidatePaths, } from "./api-key-resolver.js";
2
4
  import { sanitizeSingleLineDisplayText } from "./display-sanitize.js";
3
5
  import { getCredentialDatabasePaths, readAuthFile } from "./opencode-auth.js";
@@ -138,10 +140,10 @@ function parseQuotaV1(source, body) {
138
140
  !hasOnlyKeys(body, ["version", "entries"]) ||
139
141
  body.version !== "quota-v1" ||
140
142
  !Array.isArray(body.entries)) {
141
- return { success: false, error: "Invalid quota-v1 response" };
143
+ return { success: false, error: "Invalid quota-v1 response", failureCategory: "provider_api" };
142
144
  }
143
145
  if (body.entries.length < 1 || body.entries.length > QUOTA_PROVIDER_MAX_REMOTE_ROWS) {
144
- return { success: false, error: "Invalid quota-v1 response" };
146
+ return { success: false, error: "Invalid quota-v1 response", failureCategory: "provider_api" };
145
147
  }
146
148
  const entries = [];
147
149
  for (const raw of body.entries) {
@@ -157,7 +159,11 @@ function parseQuotaV1(source, body) {
157
159
  "resetTimeIso",
158
160
  "observedAtIso",
159
161
  ])) {
160
- return { success: false, error: "Invalid quota-v1 response" };
162
+ return {
163
+ success: false,
164
+ error: "Invalid quota-v1 response",
165
+ failureCategory: "provider_api",
166
+ };
161
167
  }
162
168
  const name = boundedDisplayText(raw.name, 80);
163
169
  const resultType = typeof raw.resultType === "string" && RESULT_TYPES.has(raw.resultType)
@@ -181,7 +187,11 @@ function parseQuotaV1(source, body) {
181
187
  (raw.right !== undefined && right === null) ||
182
188
  resetTimeIso === null ||
183
189
  observedAtIso === null) {
184
- return { success: false, error: "Invalid quota-v1 response" };
190
+ return {
191
+ success: false,
192
+ error: "Invalid quota-v1 response",
193
+ failureCategory: "provider_api",
194
+ };
185
195
  }
186
196
  const common = {
187
197
  accounting: accountingMetadata(resultType, observedAtIso),
@@ -205,7 +215,7 @@ function parseQuotaV1(source, body) {
205
215
  entries.push({ ...common, kind: "value", value });
206
216
  continue;
207
217
  }
208
- return { success: false, error: "Invalid quota-v1 response" };
218
+ return { success: false, error: "Invalid quota-v1 response", failureCategory: "provider_api" };
209
219
  }
210
220
  return { success: true, entries };
211
221
  }
@@ -495,6 +505,7 @@ function parseJsonV1(source, body) {
495
505
  const invalid = (message) => ({
496
506
  success: false,
497
507
  error: `Invalid json-v1 response: ${message}`,
508
+ failureCategory: "provider_api",
498
509
  });
499
510
  if (!isJsonV1ResponseDepthValid(body)) {
500
511
  return invalid(`nesting depth exceeded ${JSON_V1_MAX_RESPONSE_DEPTH}`);
@@ -617,18 +628,30 @@ function openRouterKeyLimitEntry(source, limit, percentRemaining, usedUsd) {
617
628
  }
618
629
  function parseOpenRouterKeyV1(source, body) {
619
630
  if (!isRecord(body) || !isRecord(body.data)) {
620
- return { success: false, error: "Invalid openrouter-key-v1 response" };
631
+ return {
632
+ success: false,
633
+ error: "Invalid openrouter-key-v1 response",
634
+ failureCategory: "provider_api",
635
+ };
621
636
  }
622
637
  const data = body.data;
623
638
  const usage = data.usage;
624
639
  if (typeof usage !== "number" || !Number.isFinite(usage) || usage < 0) {
625
- return { success: false, error: "Invalid openrouter-key-v1 response" };
640
+ return {
641
+ success: false,
642
+ error: "Invalid openrouter-key-v1 response",
643
+ failureCategory: "provider_api",
644
+ };
626
645
  }
627
646
  const rawLimit = data.limit;
628
647
  if (rawLimit !== null &&
629
648
  rawLimit !== undefined &&
630
649
  (typeof rawLimit !== "number" || !Number.isFinite(rawLimit) || rawLimit < 0)) {
631
- return { success: false, error: "Invalid openrouter-key-v1 response" };
650
+ return {
651
+ success: false,
652
+ error: "Invalid openrouter-key-v1 response",
653
+ failureCategory: "provider_api",
654
+ };
632
655
  }
633
656
  // A key limit is a cap only when it is positive. Zero and null mean unlimited.
634
657
  const limit = typeof rawLimit === "number" && rawLimit > 0 ? rawLimit : null;
@@ -636,15 +659,27 @@ function parseOpenRouterKeyV1(source, body) {
636
659
  if (rawRemaining !== null &&
637
660
  rawRemaining !== undefined &&
638
661
  (typeof rawRemaining !== "number" || !Number.isFinite(rawRemaining))) {
639
- return { success: false, error: "Invalid openrouter-key-v1 response" };
662
+ return {
663
+ success: false,
664
+ error: "Invalid openrouter-key-v1 response",
665
+ failureCategory: "provider_api",
666
+ };
640
667
  }
641
668
  // `limit_remaining` is capacity left on the key, never an account balance.
642
669
  if (rawRemaining === null && limit !== null) {
643
- return { success: false, error: "Invalid openrouter-key-v1 response" };
670
+ return {
671
+ success: false,
672
+ error: "Invalid openrouter-key-v1 response",
673
+ failureCategory: "provider_api",
674
+ };
644
675
  }
645
676
  const remaining = typeof rawRemaining === "number" ? rawRemaining : null;
646
677
  if (limit !== null && remaining !== null && remaining > limit) {
647
- return { success: false, error: "Invalid openrouter-key-v1 response" };
678
+ return {
679
+ success: false,
680
+ error: "Invalid openrouter-key-v1 response",
681
+ failureCategory: "provider_api",
682
+ };
648
683
  }
649
684
  const rawReset = data.limit_reset;
650
685
  let reset;
@@ -652,7 +687,11 @@ function parseOpenRouterKeyV1(source, body) {
652
687
  reset = null;
653
688
  }
654
689
  else if (typeof rawReset !== "string") {
655
- return { success: false, error: "Invalid openrouter-key-v1 response" };
690
+ return {
691
+ success: false,
692
+ error: "Invalid openrouter-key-v1 response",
693
+ failureCategory: "provider_api",
694
+ };
656
695
  }
657
696
  else {
658
697
  reset = OPENROUTER_LIMIT_RESETS.has(rawReset) ? rawReset : "unknown";
@@ -662,7 +701,11 @@ function parseOpenRouterKeyV1(source, body) {
662
701
  if (value === null || value === undefined)
663
702
  continue;
664
703
  if (typeof value !== "number" || !Number.isFinite(value) || value < 0) {
665
- return { success: false, error: "Invalid openrouter-key-v1 response" };
704
+ return {
705
+ success: false,
706
+ error: "Invalid openrouter-key-v1 response",
707
+ failureCategory: "provider_api",
708
+ };
666
709
  }
667
710
  }
668
711
  if (limit !== null) {
@@ -673,11 +716,19 @@ function parseOpenRouterKeyV1(source, body) {
673
716
  const remainingValue = remaining !== null ? remaining : windowUsage !== null ? limit - windowUsage : null;
674
717
  if (remainingValue !== null) {
675
718
  if (remainingValue > limit) {
676
- return { success: false, error: "Invalid openrouter-key-v1 response" };
719
+ return {
720
+ success: false,
721
+ error: "Invalid openrouter-key-v1 response",
722
+ failureCategory: "provider_api",
723
+ };
677
724
  }
678
725
  const percentRemaining = (remainingValue / limit) * 100;
679
726
  if (!Number.isFinite(percentRemaining)) {
680
- return { success: false, error: "Invalid openrouter-key-v1 response" };
727
+ return {
728
+ success: false,
729
+ error: "Invalid openrouter-key-v1 response",
730
+ failureCategory: "provider_api",
731
+ };
681
732
  }
682
733
  const usedUsd = limit - remainingValue;
683
734
  return {
@@ -703,25 +754,81 @@ function parseOpenRouterKeyV1(source, body) {
703
754
  entries: [openRouterSpendEntry(source, usage)],
704
755
  };
705
756
  }
706
- export async function fetchRemoteQuotaProvider(source, apiKey, requestTimeoutMs) {
757
+ export async function fetchRemoteQuotaProvider(source, apiKey, requestTimeoutMs, fetcher = fetch) {
758
+ const identity = createHmac("sha256", remoteIdentityKey)
759
+ .update(JSON.stringify([source.url, apiKey ?? null]))
760
+ .digest("base64url");
761
+ const now = Date.now();
762
+ for (const [key, deadline] of remoteRetryDeadlines) {
763
+ if (deadline <= now)
764
+ remoteRetryDeadlines.delete(key);
765
+ }
766
+ const deadline = remoteRetryDeadlines.get(identity);
767
+ if (deadline !== undefined)
768
+ return {
769
+ success: false,
770
+ error: "HTTP 429",
771
+ failureCategory: "provider_api",
772
+ retryAtMs: deadline,
773
+ };
774
+ const previous = remoteInFlight.get(identity);
775
+ if (previous) {
776
+ if (previous.source === JSON.stringify(source) &&
777
+ previous.fetcher === fetcher &&
778
+ previous.timeout === requestTimeoutMs) {
779
+ return structuredClone(await previous.request);
780
+ }
781
+ await previous.request;
782
+ return fetchRemoteQuotaProvider(source, apiKey, requestTimeoutMs, fetcher);
783
+ }
784
+ const request = fetchRemoteQuotaProviderUncached(source, apiKey, requestTimeoutMs, fetcher);
785
+ const pending = { request, source: JSON.stringify(source), fetcher, timeout: requestTimeoutMs };
786
+ remoteInFlight.set(identity, pending);
787
+ try {
788
+ const result = await request;
789
+ if (!result.success && result.retryAtMs !== undefined && result.retryAtMs > Date.now()) {
790
+ remoteRetryDeadlines.set(identity, result.retryAtMs);
791
+ }
792
+ return result;
793
+ }
794
+ finally {
795
+ if (remoteInFlight.get(identity) === pending)
796
+ remoteInFlight.delete(identity);
797
+ }
798
+ }
799
+ const remoteRetryDeadlines = new Map();
800
+ const remoteInFlight = new Map();
801
+ const remoteIdentityKey = randomBytes(32);
802
+ async function fetchRemoteQuotaProviderUncached(source, apiKey, requestTimeoutMs, fetcher = fetch) {
707
803
  const timeoutMs = requestTimeoutMs ?? REQUEST_TIMEOUT_MS;
708
804
  const controller = new AbortController();
709
805
  const timeoutId = setTimeout(() => controller.abort(), timeoutMs);
710
806
  try {
711
- const response = await fetch(source.url, {
807
+ const response = await fetcher(source.url, {
712
808
  method: "GET",
713
809
  redirect: "manual",
714
810
  signal: controller.signal,
715
811
  headers: {
716
- Authorization: `Bearer ${apiKey}`,
812
+ ...(apiKey ? { Authorization: `Bearer ${apiKey}` } : {}),
717
813
  Accept: "application/json",
718
814
  },
719
815
  });
720
816
  if (response.redirected || (response.status >= 300 && response.status < 400)) {
721
- return { success: false, error: "Redirect rejected" };
817
+ return { success: false, error: "Redirect rejected", failureCategory: "provider_api" };
722
818
  }
723
819
  if (!response.ok) {
724
- return { success: false, error: `HTTP ${response.status}` };
820
+ const header = response.status === 429 ? response.headers.get("retry-after")?.trim() : undefined;
821
+ const retryAtMs = header && /^\d+$/.test(header)
822
+ ? Date.now() + Number(header) * 1000
823
+ : header && /^[A-Za-z]{3}, \d{2} [A-Za-z]{3} \d{4} \d{2}:\d{2}:\d{2} GMT$/.test(header)
824
+ ? Date.parse(header)
825
+ : NaN;
826
+ return {
827
+ success: false,
828
+ error: `HTTP ${response.status}`,
829
+ failureCategory: providerFailureCategoryForHttpStatus(response.status),
830
+ ...(Number.isSafeInteger(retryAtMs) && retryAtMs > Date.now() ? { retryAtMs } : {}),
831
+ };
725
832
  }
726
833
  const body = await readBoundedJson(response);
727
834
  switch (source.format) {
@@ -734,10 +841,14 @@ export async function fetchRemoteQuotaProvider(source, apiKey, requestTimeoutMs)
734
841
  }
735
842
  }
736
843
  catch (error) {
844
+ if (error && typeof error === "object" && "code" in error && error.code === "unsafe-endpoint") {
845
+ return { success: false, error: "Unsafe provider endpoint", failureCategory: "provider_api" };
846
+ }
737
847
  if (controller.signal.aborted || (error instanceof Error && error.name === "AbortError")) {
738
848
  return {
739
849
  success: false,
740
850
  error: `Request timeout after ${Math.round(timeoutMs / 1000)}s`,
851
+ failureCategory: "provider_api",
741
852
  };
742
853
  }
743
854
  if (error instanceof Error &&
@@ -746,9 +857,13 @@ export async function fetchRemoteQuotaProvider(source, apiKey, requestTimeoutMs)
746
857
  "Expected a JSON response",
747
858
  "Invalid JSON response",
748
859
  ].includes(error.message)) {
749
- return { success: false, error: error.message };
860
+ return { success: false, error: error.message, failureCategory: "provider_api" };
750
861
  }
751
- return { success: false, error: "Failed to read accounting data" };
862
+ return {
863
+ success: false,
864
+ error: "Failed to read accounting data",
865
+ failureCategory: "provider_api",
866
+ };
752
867
  }
753
868
  finally {
754
869
  clearTimeout(timeoutId);