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
@@ -4,10 +4,13 @@
4
4
  * Uses OpenCode's opencode.db native OpenCode OAuth entries and queries:
5
5
  * https://chatgpt.com/backend-api/wham/usage
6
6
  */
7
+ import { providerFailureCategoryForHttpStatus } from "../contracts/provider-failure.js";
8
+ import { createApiKeyRetryGuard, retryAfterDeadline } from "./api-key-retry-after.js";
7
9
  import { sanitizeDisplayText, sanitizeSingleLineDisplayText } from "./display-sanitize.js";
8
10
  import { clampPercent } from "./format-utils.js";
9
- import { fetchWithTimeout } from "./http.js";
11
+ import { fetchWithTimeout, RequestTimeoutError } from "./http.js";
10
12
  import { readAuthFileCached } from "./opencode-auth.js";
13
+ import { buildFixedWindowEvidence } from "./quota-exhaustion-projection.js";
11
14
  import { deriveResolvedAuthIdentity } from "./resolved-auth-identity.js";
12
15
  function base64UrlDecode(input) {
13
16
  const base64 = input.replace(/-/g, "+").replace(/_/g, "/");
@@ -94,17 +97,13 @@ function parseRateLimitWindow(window, observedAtMs) {
94
97
  const value = parseWindowValue(window, observedAtMs);
95
98
  if (!value)
96
99
  return null;
97
- const endsAtMs = value.resetTimeIso ? Date.parse(value.resetTimeIso) : Number.NaN;
98
- const startedAtMs = endsAtMs - raw.limit_window_seconds * 1000;
99
- if (Number.isFinite(startedAtMs) && startedAtMs < observedAtMs && observedAtMs < endsAtMs) {
100
- value.fixedWindow = {
101
- kind: "fixed_window",
102
- startedAtIso: new Date(startedAtMs).toISOString(),
103
- observedAtIso: new Date(observedAtMs).toISOString(),
104
- endsAtIso: new Date(endsAtMs).toISOString(),
105
- fullReset: true,
106
- };
107
- }
100
+ const fixedWindow = buildFixedWindowEvidence({
101
+ durationMs: raw.limit_window_seconds * 1000,
102
+ resetTimeIso: value.resetTimeIso,
103
+ observedAtMs,
104
+ });
105
+ if (fixedWindow)
106
+ value.fixedWindow = fixedWindow;
108
107
  return { kind, value };
109
108
  }
110
109
  function derivePlanLabel(planType) {
@@ -120,6 +119,12 @@ function derivePlanLabel(planType) {
120
119
  return "OpenAI";
121
120
  }
122
121
  const OPENAI_USAGE_URL = "https://chatgpt.com/backend-api/wham/usage";
122
+ const guard = createApiKeyRetryGuard((retryAtMs) => ({
123
+ success: false,
124
+ error: "OpenAI API error 429",
125
+ failureCategory: "provider_api",
126
+ retryAtMs,
127
+ }));
123
128
  const OPENAI_RESET_CREDITS_URL = "https://chatgpt.com/backend-api/wham/rate-limit-reset-credits";
124
129
  export const DEFAULT_OPENAI_AUTH_CACHE_MAX_AGE_MS = 5_000;
125
130
  // Not `opencode`: in OpenCode 2 its OAuth entry is the Console login, which
@@ -256,27 +261,47 @@ function parseAvailableResetCredits(payload) {
256
261
  : Date.parse(credit.expiresAtIso);
257
262
  return credits.sort((left, right) => rank(left) - rank(right));
258
263
  }
259
- /** Detail failures degrade to no known expiry metadata; ordinary data stays. */
260
- async function fetchOpenAIResetCredits(headers, timeoutMs) {
261
- try {
262
- return await fetchWithTimeout(OPENAI_RESET_CREDITS_URL, {
263
- request: { headers },
264
- timeoutMs,
265
- consume: async (resp) => {
266
- if (!resp.ok)
267
- return [];
268
- try {
269
- return parseAvailableResetCredits(await resp.json());
270
- }
271
- catch {
272
- return [];
273
- }
274
- },
275
- });
276
- }
277
- catch {
278
- return [];
279
- }
264
+ // Separate from the usage guard: a limited detail endpoint must not block usage.
265
+ const resetCreditsGuard = createApiKeyRetryGuard((retryAtMs) => ({
266
+ success: false,
267
+ credits: [],
268
+ retryAtMs,
269
+ }));
270
+ async function fetchOpenAIResetCredits(headers, timeoutMs, cooldownKey) {
271
+ const result = await resetCreditsGuard(cooldownKey, async () => {
272
+ try {
273
+ return await fetchWithTimeout(OPENAI_RESET_CREDITS_URL, {
274
+ request: { headers },
275
+ timeoutMs,
276
+ consume: async (resp) => {
277
+ if (!resp.ok) {
278
+ const retryAtMs = retryAfterDeadline(resp);
279
+ return {
280
+ success: false,
281
+ credits: [],
282
+ ...(retryAtMs !== undefined ? { retryAtMs } : {}),
283
+ };
284
+ }
285
+ try {
286
+ return { success: true, credits: parseAvailableResetCredits(await resp.json()) };
287
+ }
288
+ catch {
289
+ return { success: false, credits: [] };
290
+ }
291
+ },
292
+ });
293
+ }
294
+ catch (error) {
295
+ return {
296
+ success: false,
297
+ credits: [],
298
+ ...(error instanceof RequestTimeoutError && error.retryAtMs !== undefined
299
+ ? { retryAtMs: error.retryAtMs }
300
+ : {}),
301
+ };
302
+ }
303
+ }, timeoutMs);
304
+ return result.credits;
280
305
  }
281
306
  export async function queryOpenAIQuota(options = {}) {
282
307
  const resolvedAuth = options.auth ??
@@ -295,12 +320,13 @@ export async function queryOpenAIQuota(options = {}) {
295
320
  return {
296
321
  success: false,
297
322
  error: `OpenAI sign-in could not be refreshed: ${resolvedAuth.error}. ${fix}`,
323
+ failureCategory: "credentials",
298
324
  };
299
325
  }
300
326
  if (resolvedAuth.state !== "configured")
301
327
  return null;
302
328
  if (resolvedAuth.expiresAt && resolvedAuth.expiresAt < Date.now()) {
303
- return { success: false, error: "Token expired" };
329
+ return { success: false, error: "Token expired", failureCategory: "credentials" };
304
330
  }
305
331
  try {
306
332
  const headers = {
@@ -311,15 +337,24 @@ export async function queryOpenAIQuota(options = {}) {
311
337
  if (accountId) {
312
338
  headers["ChatGPT-Account-Id"] = accountId;
313
339
  }
314
- const result = await fetchWithTimeout(OPENAI_USAGE_URL, {
340
+ // The ChatGPT account id names a workspace shared by its members, so it
341
+ // cannot identify a credential (and an email claim does not prove identity
342
+ // either). Key on the credential itself: the refresh token survives access
343
+ // token rotation, the access token is the fallback when there is none. The
344
+ // guard hashes the key and never retains it.
345
+ const cooldownKey = `${accountId ?? ""}\0${resolvedAuth.refreshToken ?? resolvedAuth.accessToken}`;
346
+ const result = await guard(cooldownKey, () => fetchWithTimeout(OPENAI_USAGE_URL, {
315
347
  request: { headers },
316
348
  timeoutMs: options.requestTimeoutMs,
317
349
  consume: async (resp) => {
318
350
  if (!resp.ok) {
351
+ const retryAtMs = retryAfterDeadline(resp);
319
352
  const code = await readOpenAIErrorCode(resp);
320
353
  return {
321
354
  success: false,
322
355
  error: `OpenAI API error ${resp.status}${code ? ` (${code})` : ""}`,
356
+ failureCategory: providerFailureCategoryForHttpStatus(resp.status),
357
+ ...(retryAtMs !== undefined ? { retryAtMs } : {}),
323
358
  };
324
359
  }
325
360
  const data = (await resp.json());
@@ -363,8 +398,10 @@ export async function queryOpenAIQuota(options = {}) {
363
398
  Number(mappedCredits.balance) > 0));
364
399
  // Empty bodies stay invalid; a useful Credits-only/reset-count-only
365
400
  // payload is a real measurement even without a percent window.
366
- if (Object.keys(windows).length === 0 && !positiveCredits && availableResetCount === null) {
367
- return { success: false, error: "No quota data" };
401
+ if (Object.keys(windows).length === 0 &&
402
+ !positiveCredits &&
403
+ availableResetCount === null) {
404
+ return { success: false, error: "No quota data", failureCategory: "provider_api" };
368
405
  }
369
406
  return {
370
407
  success: true,
@@ -377,17 +414,30 @@ export async function queryOpenAIQuota(options = {}) {
377
414
  : {}),
378
415
  };
379
416
  },
380
- });
381
- if (!result || !result.success || !result.bankedResets || !options.includeResetDetails) {
417
+ }).catch((err) => {
418
+ if (!(err instanceof RequestTimeoutError) || err.retryAtMs === undefined)
419
+ throw err;
420
+ return {
421
+ success: false,
422
+ error: sanitizeDisplayText(err.message),
423
+ failureCategory: "provider_api",
424
+ retryAtMs: err.retryAtMs,
425
+ };
426
+ }), options.requestTimeoutMs);
427
+ if (!result.success || !result.bankedResets || !options.includeResetDetails) {
382
428
  return result;
383
429
  }
384
- result.bankedResets.credits = await fetchOpenAIResetCredits(headers, options.requestTimeoutMs);
430
+ result.bankedResets.credits = await fetchOpenAIResetCredits(headers, options.requestTimeoutMs, `reset-credits:${cooldownKey}`);
385
431
  return result;
386
432
  }
387
433
  catch (err) {
388
434
  return {
389
435
  success: false,
390
436
  error: sanitizeDisplayText(err instanceof Error ? err.message : String(err)),
437
+ failureCategory: "provider_api",
438
+ ...(err instanceof RequestTimeoutError && err.retryAtMs !== undefined
439
+ ? { retryAtMs: err.retryAtMs }
440
+ : {}),
391
441
  };
392
442
  }
393
443
  }
@@ -4,8 +4,8 @@
4
4
  * `opencode-quota-gui show` and `status` bind this source while one report runs, so they work
5
5
  * with OpenCode closed. It is the only code that queries OpenCode's `credential` table. It
6
6
  * never refreshes or writes a login: a sign-in whose token expired stays expired here until
7
- * OpenCode refreshes it. The server plugin and the TUI must never import this file
8
- * (`tests/tui-dist-import-graph.test.ts`).
7
+ * OpenCode refreshes it. The server plugin must never import this file
8
+ * (`tests/plugin-dist-import-graph.test.ts`).
9
9
  */
10
10
  import { type CredentialSource } from "./opencode-auth.js";
11
11
  /**
@@ -4,8 +4,8 @@
4
4
  * `opencode-quota-gui show` and `status` bind this source while one report runs, so they work
5
5
  * with OpenCode closed. It is the only code that queries OpenCode's `credential` table. It
6
6
  * never refreshes or writes a login: a sign-in whose token expired stays expired here until
7
- * OpenCode refreshes it. The server plugin and the TUI must never import this file
8
- * (`tests/tui-dist-import-graph.test.ts`).
7
+ * OpenCode refreshes it. The server plugin must never import this file
8
+ * (`tests/plugin-dist-import-graph.test.ts`).
9
9
  */
10
10
  import { existsSync } from "fs";
11
11
  import { getCredentialDatabasePaths, } from "./opencode-auth.js";
@@ -24,8 +24,9 @@ export type CredentialRow = {
24
24
  /**
25
25
  * Why OpenCode could not return this login (for example a failed token
26
26
  * refresh), as `<category>: <scrubbed detail>`. A failed row keeps its id,
27
- * label and position, but its `value` is only `{ type: "api" | "oauth" }`;
28
- * consumers show `resolveError` as a per-account error.
27
+ * label and position, but its `value` is only `{ type: "api" | "oauth" }`.
28
+ * A failed `external` connection uses the same fallback because the failed-row
29
+ * shape only names api/oauth; consumers show `resolveError` as a per-account error.
29
30
  */
30
31
  resolveError?: string;
31
32
  };
@@ -304,7 +304,14 @@ async function credentialRowForSlot(integration, slot, methods) {
304
304
  * has rows, since a firstOnly read returns one active connection per id.
305
305
  */
306
306
  async function credentialRowsForSlots(integration, slots, methods, activeConnections) {
307
- const wanted = slots.filter((slot) => !methods || !("connection" in slot) || methods.includes(slot.connection.method));
307
+ const wanted = slots.filter((slot) => {
308
+ if (!methods || !("connection" in slot))
309
+ return true;
310
+ // SDK 2.2 added the host-provided `external` connection method. It is never
311
+ // one of the readable key/OAuth slots, so compare values instead of asking
312
+ // a narrower array whether it includes a wider union.
313
+ return methods.some((method) => method === slot.connection.method);
314
+ });
308
315
  const pairs = await Promise.all(wanted.map(async (slot) => ({
309
316
  slot,
310
317
  row: await credentialRowForSlot(integration, slot, methods),
@@ -58,5 +58,6 @@ export declare function applyConfigDocumentEdit(edit: ConfigDocumentEdit, option
58
58
  pathExists?: (path: string) => boolean;
59
59
  writeText?: (path: string, content: string) => Promise<void>;
60
60
  removePath?: (path: string) => Promise<void>;
61
+ beforeRename?: () => Promise<void>;
61
62
  }): Promise<void>;
62
63
  //# sourceMappingURL=opencode-config-editor.d.ts.map
@@ -352,15 +352,20 @@ export async function applyConfigDocumentEdit(edit, options = {}) {
352
352
  return;
353
353
  }
354
354
  await validateConfigDocumentEdit(edit, options);
355
+ const validateBeforeRename = async () => {
356
+ await options.beforeRename?.();
357
+ await validateConfigDocumentEdit(edit, options);
358
+ };
355
359
  const removePath = options.removePath ?? ((path) => rm(path));
356
360
  try {
357
361
  const currentTarget = await resolveConfigWriteTarget(edit.path);
358
362
  assertSameConfigWriteTarget(edit.writeTarget, currentTarget);
359
363
  if (options.writeText) {
364
+ await validateBeforeRename();
360
365
  await options.writeText(currentTarget.writePath, edit.updated);
361
366
  }
362
367
  else {
363
- await writeResolvedConfigText(currentTarget, edit.updated);
368
+ await writeResolvedConfigText(currentTarget, edit.updated, validateBeforeRename);
364
369
  }
365
370
  }
366
371
  catch (error) {
@@ -1,3 +1,4 @@
1
+ import { createApiKeyRetryGuard, retryAfterDeadline } from "./api-key-retry-after.js";
1
2
  import { sanitizeDisplayText } from "./display-sanitize.js";
2
3
  import { fetchWithTimeout } from "./http.js";
3
4
  import { consoleBaseUrl, consoleHeaders, } from "./opencode-console-auth.js";
@@ -21,7 +22,15 @@ function errorMessage(error, accessToken) {
21
22
  return sanitizeMessage(error instanceof Error ? error.message : String(error), accessToken);
22
23
  }
23
24
  function contractError(message) {
24
- return { success: false, error: `Invalid OpenCode Go API response: ${message}` };
25
+ return {
26
+ success: false,
27
+ error: `Invalid OpenCode Go API response: ${message}`,
28
+ failureCategory: "provider_api",
29
+ };
30
+ }
31
+ /** 401/403 resolve credentials before the endpoint contract can be read. */
32
+ function httpFailureCategory(status) {
33
+ return status === 401 || status === 403 ? "credentials" : "provider_api";
25
34
  }
26
35
  function isRetryableHttpStatus(status) {
27
36
  return status === 408 || status === 425 || status === 429 || status >= 500;
@@ -110,7 +119,19 @@ function isNotSubscribedResponse(status, text) {
110
119
  return false;
111
120
  }
112
121
  }
113
- export async function queryOpenCodeGoQuota(accessToken, options = {}) {
122
+ const rateLimited = (retryAtMs) => ({
123
+ success: false,
124
+ error: "OpenCode Go API error 429",
125
+ retryable: true,
126
+ failureCategory: "provider_api",
127
+ retryAtMs,
128
+ });
129
+ const apiKeyGuard = createApiKeyRetryGuard(rateLimited);
130
+ const consoleGuard = createApiKeyRetryGuard(rateLimited);
131
+ export function queryOpenCodeGoQuota(accessToken, options = {}) {
132
+ return apiKeyGuard(accessToken, () => fetchOpenCodeGoQuota(accessToken, options), options.requestTimeoutMs);
133
+ }
134
+ async function fetchOpenCodeGoQuota(accessToken, options) {
114
135
  try {
115
136
  return await fetchWithTimeout(OPENCODE_GO_USAGE_URL, {
116
137
  request: {
@@ -123,6 +144,7 @@ export async function queryOpenCodeGoQuota(accessToken, options = {}) {
123
144
  timeoutMs: options.requestTimeoutMs,
124
145
  consume: async (response) => {
125
146
  if (!response.ok) {
147
+ const retryAtMs = retryAfterDeadline(response);
126
148
  let text;
127
149
  try {
128
150
  text = await response.text();
@@ -132,6 +154,8 @@ export async function queryOpenCodeGoQuota(accessToken, options = {}) {
132
154
  success: false,
133
155
  error: `OpenCode Go API error ${response.status}: ${errorMessage(error, accessToken)}`,
134
156
  retryable: isRetryableHttpStatus(response.status),
157
+ failureCategory: httpFailureCategory(response.status),
158
+ ...(retryAtMs !== undefined ? { retryAtMs } : {}),
135
159
  };
136
160
  }
137
161
  if (isNotSubscribedResponse(response.status, text)) {
@@ -146,6 +170,8 @@ export async function queryOpenCodeGoQuota(accessToken, options = {}) {
146
170
  success: false,
147
171
  error: `OpenCode Go API error ${response.status}: ${sanitizeMessage(text, accessToken)}`,
148
172
  retryable: isRetryableHttpStatus(response.status),
173
+ failureCategory: httpFailureCategory(response.status),
174
+ ...(retryAtMs !== undefined ? { retryAtMs } : {}),
149
175
  };
150
176
  }
151
177
  let payload;
@@ -160,7 +186,12 @@ export async function queryOpenCodeGoQuota(accessToken, options = {}) {
160
186
  });
161
187
  }
162
188
  catch (error) {
163
- return { success: false, error: errorMessage(error, accessToken), retryable: true };
189
+ return {
190
+ success: false,
191
+ error: errorMessage(error, accessToken),
192
+ retryable: true,
193
+ failureCategory: "provider_api",
194
+ };
164
195
  }
165
196
  }
166
197
  function asMicroCents(value) {
@@ -204,7 +235,16 @@ function normalizeConsoleMeter(windowKey, meter) {
204
235
  * accounts without any pre-2.0 workspace API key. The request goes to the
205
236
  * login's Console server, scoped to the login's org when it has one.
206
237
  */
207
- export async function queryOpenCodeGoConsoleStatus(credential, options = {}) {
238
+ export function queryOpenCodeGoConsoleStatus(credential, options = {}) {
239
+ // Same token under another org or server is a different account.
240
+ const identity = JSON.stringify([
241
+ credential.accessToken,
242
+ credential.orgId ?? null,
243
+ consoleBaseUrl(credential),
244
+ ]);
245
+ return consoleGuard(identity, () => fetchOpenCodeGoConsoleStatus(credential, options), options.requestTimeoutMs);
246
+ }
247
+ async function fetchOpenCodeGoConsoleStatus(credential, options) {
208
248
  try {
209
249
  return await fetchWithTimeout(`${consoleBaseUrl(credential)}/api/go/status`, {
210
250
  request: {
@@ -225,10 +265,13 @@ export async function queryOpenCodeGoConsoleStatus(credential, options = {}) {
225
265
  notSubscribed: true,
226
266
  };
227
267
  }
268
+ const retryAtMs = retryAfterDeadline(response);
228
269
  return {
229
270
  success: false,
230
271
  error: `OpenCode Console API error ${response.status} (/api/go/status)`,
231
272
  retryable: isRetryableHttpStatus(response.status),
273
+ failureCategory: httpFailureCategory(response.status),
274
+ ...(retryAtMs !== undefined ? { retryAtMs } : {}),
232
275
  };
233
276
  }
234
277
  let payload;
@@ -278,7 +321,12 @@ export async function queryOpenCodeGoConsoleStatus(credential, options = {}) {
278
321
  });
279
322
  }
280
323
  catch (error) {
281
- return { success: false, error: errorMessage(error, credential.accessToken), retryable: true };
324
+ return {
325
+ success: false,
326
+ error: errorMessage(error, credential.accessToken),
327
+ retryable: true,
328
+ failureCategory: "provider_api",
329
+ };
282
330
  }
283
331
  }
284
332
  //# sourceMappingURL=opencode-go.js.map
@@ -0,0 +1,23 @@
1
+ export type OpenCodeMajor = 1 | 2;
2
+ /** Numeric host version; a prerelease/build suffix is ignored. */
3
+ export interface OpenCodeVersion {
4
+ major: number;
5
+ minor: number;
6
+ patch: number;
7
+ }
8
+ /** Parses the numeric version core; a prerelease or build suffix is ignored. */
9
+ export declare function parseOpenCodeVersion(output: string): OpenCodeVersion | undefined;
10
+ /** OpenCode 1 prints a bare `1.18.32`; OpenCode 2 prints `opencode v2.0.16`. */
11
+ export declare function parseOpenCodeMajor(output: string): OpenCodeMajor | undefined;
12
+ /**
13
+ * Whether the host has the full Native GUI baseline (2.2.1+). Missing or
14
+ * unparseable versions are not assumed capable.
15
+ */
16
+ export declare function supportsNativeGui(version: string | OpenCodeVersion | undefined): boolean;
17
+ /**
18
+ * Whether the host predates the Native GUI and therefore keeps the compatibility
19
+ * web dashboard on by default. Only a parseable version below 2.2.1 qualifies;
20
+ * missing or unparseable versions fail closed.
21
+ */
22
+ export declare function isPreNativeGuiVersion(version: string | OpenCodeVersion | undefined): boolean;
23
+ //# sourceMappingURL=opencode-version-core.d.ts.map
@@ -0,0 +1,49 @@
1
+ /** The numeric core of `1.18.32`, `opencode v2.2.0`, or `2.2.1-beta.1`. */
2
+ const OPENCODE_VERSION_PATTERN = /^(?:opencode\s+)?v?(\d+)\.(\d+)\.(\d+)/;
3
+ /** Parses the numeric version core; a prerelease or build suffix is ignored. */
4
+ export function parseOpenCodeVersion(output) {
5
+ const match = OPENCODE_VERSION_PATTERN.exec(output.trim());
6
+ if (!match)
7
+ return undefined;
8
+ const major = Number(match[1]);
9
+ const minor = Number(match[2]);
10
+ const patch = Number(match[3]);
11
+ if (![major, minor, patch].every((part) => Number.isSafeInteger(part)))
12
+ return undefined;
13
+ return { major, minor, patch };
14
+ }
15
+ /** OpenCode 1 prints a bare `1.18.32`; OpenCode 2 prints `opencode v2.0.16`. */
16
+ export function parseOpenCodeMajor(output) {
17
+ const version = parseOpenCodeVersion(output);
18
+ if (version?.major === 1)
19
+ return 1;
20
+ if (version?.major === 2)
21
+ return 2;
22
+ return undefined;
23
+ }
24
+ /** Compares the numeric parts only; a prerelease suffix never lowers the result. */
25
+ function isAtLeast(version, major, minor, patch) {
26
+ if (version.major !== major)
27
+ return version.major > major;
28
+ if (version.minor !== minor)
29
+ return version.minor > minor;
30
+ return version.patch >= patch;
31
+ }
32
+ /**
33
+ * Whether the host has the full Native GUI baseline (2.2.1+). Missing or
34
+ * unparseable versions are not assumed capable.
35
+ */
36
+ export function supportsNativeGui(version) {
37
+ const parsed = typeof version === "string" ? parseOpenCodeVersion(version) : version;
38
+ return parsed !== undefined && isAtLeast(parsed, 2, 2, 1);
39
+ }
40
+ /**
41
+ * Whether the host predates the Native GUI and therefore keeps the compatibility
42
+ * web dashboard on by default. Only a parseable version below 2.2.1 qualifies;
43
+ * missing or unparseable versions fail closed.
44
+ */
45
+ export function isPreNativeGuiVersion(version) {
46
+ const parsed = typeof version === "string" ? parseOpenCodeVersion(version) : version;
47
+ return parsed !== undefined && !isAtLeast(parsed, 2, 2, 1);
48
+ }
49
+ //# sourceMappingURL=opencode-version-core.js.map
@@ -1,6 +1,7 @@
1
- export type OpenCodeMajor = 1 | 2;
2
- /** OpenCode 1 prints a bare `1.18.32`; OpenCode 2 prints `opencode v2.0.16`. */
3
- export declare function parseOpenCodeMajor(output: string): OpenCodeMajor | undefined;
1
+ import { type OpenCodeMajor, type OpenCodeVersion } from "./opencode-version-core.js";
2
+ export * from "./opencode-version-core.js";
3
+ /** Returns undefined when `opencode` is not on PATH, fails, times out, or prints an unknown version. */
4
+ export declare function detectOpenCodeVersion(runVersion?: () => Promise<string>): Promise<OpenCodeVersion | undefined>;
4
5
  /** Returns undefined when `opencode` is not on PATH, fails, times out, or prints an unknown version. */
5
6
  export declare function detectOpenCodeMajor(runVersion?: () => Promise<string>): Promise<OpenCodeMajor | undefined>;
6
7
  //# sourceMappingURL=opencode-version.d.ts.map
@@ -1,26 +1,30 @@
1
1
  import { execFile } from "node:child_process";
2
+ import { parseOpenCodeVersion, } from "./opencode-version-core.js";
3
+ // Keep this legacy module path's public surface intact while the implementation
4
+ // of pure version helpers lives in a browser-safe module.
5
+ export * from "./opencode-version-core.js";
2
6
  const OPENCODE_VERSION_TIMEOUT_MS = 5_000;
3
- /** OpenCode 1 prints a bare `1.18.32`; OpenCode 2 prints `opencode v2.0.16`. */
4
- export function parseOpenCodeMajor(output) {
5
- const match = /^(?:opencode\s+)?v?(\d+)\.\d+\.\d+/.exec(output.trim());
6
- if (match?.[1] === "1")
7
- return 1;
8
- if (match?.[1] === "2")
9
- return 2;
10
- return undefined;
11
- }
12
7
  function runOpenCodeVersion() {
13
8
  return new Promise((resolve, reject) => {
14
9
  execFile("opencode", ["--version"], { encoding: "utf8", timeout: OPENCODE_VERSION_TIMEOUT_MS, windowsHide: true }, (error, stdout) => (error ? reject(error) : resolve(stdout)));
15
10
  });
16
11
  }
17
12
  /** Returns undefined when `opencode` is not on PATH, fails, times out, or prints an unknown version. */
18
- export async function detectOpenCodeMajor(runVersion = runOpenCodeVersion) {
13
+ export async function detectOpenCodeVersion(runVersion = runOpenCodeVersion) {
19
14
  try {
20
- return parseOpenCodeMajor(await runVersion());
15
+ return parseOpenCodeVersion(await runVersion());
21
16
  }
22
17
  catch {
23
18
  return undefined;
24
19
  }
25
20
  }
21
+ /** Returns undefined when `opencode` is not on PATH, fails, times out, or prints an unknown version. */
22
+ export async function detectOpenCodeMajor(runVersion = runOpenCodeVersion) {
23
+ const version = await detectOpenCodeVersion(runVersion);
24
+ if (version?.major === 1)
25
+ return 1;
26
+ if (version?.major === 2)
27
+ return 2;
28
+ return undefined;
29
+ }
26
30
  //# sourceMappingURL=opencode-version.js.map
@@ -1,3 +1,4 @@
1
+ import type { ProviderFailureCategory } from "../contracts/provider-failure.js";
1
2
  import { type OpenCodeConsoleCredential } from "./opencode-console-auth.js";
2
3
  /**
3
4
  * The OpenCode Console reports amounts in micro-cents:
@@ -39,15 +40,25 @@ export interface OpenCodeZenBillingData {
39
40
  }
40
41
  /**
41
42
  * billing/status (balance) is required. The other routes are optional: when one fails,
42
- * its fields are null and its error is listed in `errors`.
43
+ * its fields are null and its error is listed in `errors`. `optionalErrors`
44
+ * carries the same messages with their producer-assigned failure category.
43
45
  */
46
+ export type OpenCodeZenOptionalError = {
47
+ message: string;
48
+ failureCategory?: ProviderFailureCategory;
49
+ /** Deadline observed in an upstream Retry-After response. */
50
+ retryAtMs?: number;
51
+ };
44
52
  export type OpenCodeZenResult = {
45
53
  success: true;
46
54
  data: OpenCodeZenBillingData;
47
55
  errors: string[];
56
+ optionalErrors?: OpenCodeZenOptionalError[];
48
57
  } | {
49
58
  success: false;
50
59
  error: string;
60
+ failureCategory?: ProviderFailureCategory;
61
+ retryAtMs?: number;
51
62
  };
52
63
  export declare function queryOpenCodeZenQuota(credential: OpenCodeConsoleCredential, options?: {
53
64
  requestTimeoutMs?: number;