opencode-quota-gui 1.1.0 → 1.3.0

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 (533) hide show
  1. package/README.md +96 -34
  2. package/dist/bin/opencode-quota-gui.js +0 -0
  3. package/dist/contracts/analytics-entity.d.ts +6 -1
  4. package/dist/contracts/analytics-entity.js +27 -10
  5. package/dist/contracts/analytics-temporal.d.ts +39 -0
  6. package/dist/contracts/analytics-temporal.js +11 -0
  7. package/dist/contracts/build-identity.js +1 -1
  8. package/dist/contracts/card-visibility.d.ts +21 -0
  9. package/dist/contracts/card-visibility.js +19 -0
  10. package/dist/contracts/dashboard.d.ts +40 -0
  11. package/dist/contracts/dashboard.js +2 -0
  12. package/dist/contracts/dto-guards.d.ts +24 -0
  13. package/dist/contracts/dto-guards.js +592 -0
  14. package/dist/contracts/provider-failure.d.ts +18 -0
  15. package/dist/contracts/provider-failure.js +25 -0
  16. package/dist/contracts/temporal.d.ts +126 -0
  17. package/dist/contracts/temporal.js +10 -0
  18. package/dist/data/modelsdev-temporal.min.json +3075 -0
  19. package/dist/gui/aggregation.js +3 -0
  20. package/dist/gui/analytics-engine.js +30 -0
  21. package/dist/gui/analytics-model.js +181 -1
  22. package/dist/gui/analytics-pricing-revision.d.ts +43 -0
  23. package/dist/gui/analytics-pricing-revision.js +160 -0
  24. package/dist/gui/analytics-state.d.ts +7 -2
  25. package/dist/gui/analytics-state.js +14 -2
  26. package/dist/gui/config.d.ts +20 -3
  27. package/dist/gui/config.js +60 -3
  28. package/dist/gui/dashboard-errors.d.ts +32 -0
  29. package/dist/gui/dashboard-errors.js +97 -0
  30. package/dist/gui/lifecycle.d.ts +44 -11
  31. package/dist/gui/lifecycle.js +214 -36
  32. package/dist/gui/primary-quota-windows.d.ts +28 -0
  33. package/dist/gui/primary-quota-windows.js +147 -0
  34. package/dist/gui/provider-cards.d.ts +1 -1
  35. package/dist/gui/provider-cards.js +40 -16
  36. package/dist/gui/quota-notification-detector.d.ts +151 -0
  37. package/dist/gui/quota-notification-detector.js +284 -0
  38. package/dist/gui/quota-notification-observer.d.ts +55 -0
  39. package/dist/gui/quota-notification-observer.js +363 -0
  40. package/dist/gui/rpc.d.ts +59 -0
  41. package/dist/gui/rpc.js +302 -0
  42. package/dist/gui/server.d.ts +15 -27
  43. package/dist/gui/server.js +23 -121
  44. package/dist/gui/snapshot-service.d.ts +31 -4
  45. package/dist/gui/snapshot-service.js +177 -54
  46. package/dist/gui/sources.d.ts +1 -1
  47. package/dist/gui/sources.js +28 -0
  48. package/dist/gui/temporal-quota-policy-data.d.ts +24 -0
  49. package/dist/gui/temporal-quota-policy-data.js +43 -0
  50. package/dist/gui/temporal-quota-policy.d.ts +38 -0
  51. package/dist/gui/temporal-quota-policy.js +182 -0
  52. package/dist/gui/temporal-status.d.ts +53 -0
  53. package/dist/gui/temporal-status.js +815 -0
  54. package/dist/gui-experimental.cjs +1756 -0
  55. package/dist/lib/anthropic.d.ts +5 -0
  56. package/dist/lib/anthropic.js +18 -1
  57. package/dist/lib/chutes.js +19 -2
  58. package/dist/lib/config.d.ts +5 -1
  59. package/dist/lib/config.js +81 -0
  60. package/dist/lib/copilot.js +42 -14
  61. package/dist/lib/dashboard-web-policy.d.ts +35 -0
  62. package/dist/lib/dashboard-web-policy.js +24 -0
  63. package/dist/lib/deepseek.js +12 -1
  64. package/dist/lib/display-sanitize.js +2 -0
  65. package/dist/lib/entries.d.ts +3 -0
  66. package/dist/lib/format-utils.d.ts +1 -1
  67. package/dist/lib/format-utils.js +2 -2
  68. package/dist/lib/glm-coding-plan.js +14 -4
  69. package/dist/lib/google-agy.js +59 -14
  70. package/dist/lib/google-gemini-cli.js +58 -14
  71. package/dist/lib/init-installer.js +25 -4
  72. package/dist/lib/kilo.js +29 -40
  73. package/dist/lib/kimi.js +13 -1
  74. package/dist/lib/mimo.d.ts +2 -0
  75. package/dist/lib/mimo.js +9 -1
  76. package/dist/lib/modelsdev-temporal.d.ts +143 -0
  77. package/dist/lib/modelsdev-temporal.js +896 -0
  78. package/dist/lib/nanogpt.d.ts +2 -0
  79. package/dist/lib/nanogpt.js +24 -3
  80. package/dist/lib/ollama-cloud.js +9 -0
  81. package/dist/lib/openai.js +6 -2
  82. package/dist/lib/opencode-auth.d.ts +3 -2
  83. package/dist/lib/opencode-auth.js +8 -1
  84. package/dist/lib/opencode-go.js +24 -3
  85. package/dist/lib/opencode-version.d.ts +21 -0
  86. package/dist/lib/opencode-version.js +53 -5
  87. package/dist/lib/opencode-zen.d.ts +9 -1
  88. package/dist/lib/opencode-zen.js +27 -7
  89. package/dist/lib/quota-providers-remote.d.ts +2 -0
  90. package/dist/lib/quota-providers-remote.js +78 -19
  91. package/dist/lib/quota-reset-notifications.d.ts +17 -0
  92. package/dist/lib/quota-reset-notifications.js +11 -2
  93. package/dist/lib/quota-state-codec.js +3 -1
  94. package/dist/lib/quota-stats.d.ts +22 -1
  95. package/dist/lib/quota-stats.js +111 -15
  96. package/dist/lib/synthetic.js +8 -0
  97. package/dist/lib/types.d.ts +24 -0
  98. package/dist/lib/types.js +4 -0
  99. package/dist/lib/xai.js +16 -2
  100. package/dist/plugin.d.ts +4 -3
  101. package/dist/plugin.js +33 -4
  102. package/dist/providers/alibaba-coding-plan.js +3 -1
  103. package/dist/providers/alibaba-token-plan.js +17 -0
  104. package/dist/providers/anthropic.js +12 -3
  105. package/dist/providers/copilot.js +10 -2
  106. package/dist/providers/glm-coding-plan-provider.d.ts +2 -0
  107. package/dist/providers/glm-coding-plan-provider.js +5 -1
  108. package/dist/providers/google-account-format.js +1 -0
  109. package/dist/providers/google-agy.js +12 -2
  110. package/dist/providers/google-gemini-cli.js +12 -2
  111. package/dist/providers/kilo.js +9 -1
  112. package/dist/providers/kimi-code.js +11 -6
  113. package/dist/providers/mimo.js +8 -2
  114. package/dist/providers/minimax-coding-plan.js +28 -5
  115. package/dist/providers/nanogpt.js +3 -0
  116. package/dist/providers/ollama-cloud.js +3 -0
  117. package/dist/providers/openai.js +1 -0
  118. package/dist/providers/opencode-go.js +8 -1
  119. package/dist/providers/opencode-zen.js +30 -3
  120. package/dist/providers/openrouter.js +3 -0
  121. package/dist/providers/quota-providers.js +30 -4
  122. package/dist/providers/result-helpers.d.ts +4 -0
  123. package/dist/providers/result-helpers.js +16 -2
  124. package/dist/rpc.d.ts +327 -4
  125. package/dist/rpc.js +315 -2
  126. package/dist/ui/assets/index-DLHeXYff.js +9 -0
  127. package/dist/ui/assets/{index-BZwMJ6Ax.css → index-cDd9jUVY.css} +1 -1
  128. package/dist/ui/assets/popover-BGkgv9s0.js +1 -0
  129. package/dist/ui/assets/popover-mkHTmNjv.css +1 -0
  130. package/dist/ui/index.html +2 -2
  131. package/package.json +49 -39
  132. package/dist/bin/opencode-quota-gui.d.ts.map +0 -1
  133. package/dist/bin/opencode-quota-gui.js.map +0 -1
  134. package/dist/contracts/analytics-entity.d.ts.map +0 -1
  135. package/dist/contracts/analytics-entity.js.map +0 -1
  136. package/dist/contracts/build-identity.d.ts.map +0 -1
  137. package/dist/contracts/card-order.d.ts.map +0 -1
  138. package/dist/contracts/card-order.js.map +0 -1
  139. package/dist/contracts/collision-safe-key.d.ts.map +0 -1
  140. package/dist/contracts/collision-safe-key.js.map +0 -1
  141. package/dist/contracts/dashboard.d.ts.map +0 -1
  142. package/dist/contracts/dashboard.js.map +0 -1
  143. package/dist/contracts/guards.d.ts.map +0 -1
  144. package/dist/contracts/guards.js.map +0 -1
  145. package/dist/contracts/identity.d.ts.map +0 -1
  146. package/dist/contracts/identity.js.map +0 -1
  147. package/dist/contracts/openai-quota.d.ts.map +0 -1
  148. package/dist/contracts/openai-quota.js.map +0 -1
  149. package/dist/contracts/ranges.d.ts.map +0 -1
  150. package/dist/contracts/ranges.js.map +0 -1
  151. package/dist/contracts/settings.d.ts.map +0 -1
  152. package/dist/contracts/settings.js.map +0 -1
  153. package/dist/contracts/time-zone.d.ts.map +0 -1
  154. package/dist/contracts/time-zone.js.map +0 -1
  155. package/dist/gui/aggregation.d.ts.map +0 -1
  156. package/dist/gui/aggregation.js.map +0 -1
  157. package/dist/gui/analytics-bridge.d.ts.map +0 -1
  158. package/dist/gui/analytics-bridge.js.map +0 -1
  159. package/dist/gui/analytics-engine.d.ts.map +0 -1
  160. package/dist/gui/analytics-engine.js.map +0 -1
  161. package/dist/gui/analytics-indexes.d.ts.map +0 -1
  162. package/dist/gui/analytics-indexes.js.map +0 -1
  163. package/dist/gui/analytics-model.d.ts.map +0 -1
  164. package/dist/gui/analytics-model.js.map +0 -1
  165. package/dist/gui/analytics-protocol.d.ts.map +0 -1
  166. package/dist/gui/analytics-protocol.js.map +0 -1
  167. package/dist/gui/analytics-reader.d.ts.map +0 -1
  168. package/dist/gui/analytics-reader.js.map +0 -1
  169. package/dist/gui/analytics-service.d.ts.map +0 -1
  170. package/dist/gui/analytics-service.js.map +0 -1
  171. package/dist/gui/analytics-state.d.ts.map +0 -1
  172. package/dist/gui/analytics-state.js.map +0 -1
  173. package/dist/gui/analytics-worker-runtime.d.ts.map +0 -1
  174. package/dist/gui/analytics-worker-runtime.js.map +0 -1
  175. package/dist/gui/analytics-worker.d.ts.map +0 -1
  176. package/dist/gui/analytics-worker.js.map +0 -1
  177. package/dist/gui/config.d.ts.map +0 -1
  178. package/dist/gui/config.js.map +0 -1
  179. package/dist/gui/identity.d.ts.map +0 -1
  180. package/dist/gui/identity.js.map +0 -1
  181. package/dist/gui/lifecycle.d.ts.map +0 -1
  182. package/dist/gui/lifecycle.js.map +0 -1
  183. package/dist/gui/log.d.ts.map +0 -1
  184. package/dist/gui/log.js.map +0 -1
  185. package/dist/gui/provider-cards.d.ts.map +0 -1
  186. package/dist/gui/provider-cards.js.map +0 -1
  187. package/dist/gui/server.d.ts.map +0 -1
  188. package/dist/gui/server.js.map +0 -1
  189. package/dist/gui/settings-file-opener.d.ts.map +0 -1
  190. package/dist/gui/settings-file-opener.js.map +0 -1
  191. package/dist/gui/snapshot-service.d.ts.map +0 -1
  192. package/dist/gui/snapshot-service.js.map +0 -1
  193. package/dist/gui/sources.d.ts.map +0 -1
  194. package/dist/gui/sources.js.map +0 -1
  195. package/dist/gui/sse.d.ts.map +0 -1
  196. package/dist/gui/sse.js.map +0 -1
  197. package/dist/gui/time-zone.d.ts.map +0 -1
  198. package/dist/gui/time-zone.js.map +0 -1
  199. package/dist/index.d.ts.map +0 -1
  200. package/dist/index.js.map +0 -1
  201. package/dist/lib/accounting-format.d.ts.map +0 -1
  202. package/dist/lib/accounting-format.js.map +0 -1
  203. package/dist/lib/alibaba-auth.d.ts.map +0 -1
  204. package/dist/lib/alibaba-auth.js.map +0 -1
  205. package/dist/lib/alibaba-coding-plan-local-quota.d.ts.map +0 -1
  206. package/dist/lib/alibaba-coding-plan-local-quota.js.map +0 -1
  207. package/dist/lib/alibaba-token-plan.d.ts.map +0 -1
  208. package/dist/lib/alibaba-token-plan.js.map +0 -1
  209. package/dist/lib/anthropic-auth.d.ts.map +0 -1
  210. package/dist/lib/anthropic-auth.js.map +0 -1
  211. package/dist/lib/anthropic.d.ts.map +0 -1
  212. package/dist/lib/anthropic.js.map +0 -1
  213. package/dist/lib/api-key-resolver.d.ts.map +0 -1
  214. package/dist/lib/api-key-resolver.js.map +0 -1
  215. package/dist/lib/atomic-json.d.ts.map +0 -1
  216. package/dist/lib/atomic-json.js.map +0 -1
  217. package/dist/lib/chutes-config.d.ts.map +0 -1
  218. package/dist/lib/chutes-config.js.map +0 -1
  219. package/dist/lib/chutes.d.ts.map +0 -1
  220. package/dist/lib/chutes.js.map +0 -1
  221. package/dist/lib/cli-reports.d.ts.map +0 -1
  222. package/dist/lib/cli-reports.js.map +0 -1
  223. package/dist/lib/cli-show.d.ts.map +0 -1
  224. package/dist/lib/cli-show.js.map +0 -1
  225. package/dist/lib/cli-status.d.ts.map +0 -1
  226. package/dist/lib/cli-status.js.map +0 -1
  227. package/dist/lib/command-parsing.d.ts.map +0 -1
  228. package/dist/lib/command-parsing.js.map +0 -1
  229. package/dist/lib/config-file-utils.d.ts.map +0 -1
  230. package/dist/lib/config-file-utils.js.map +0 -1
  231. package/dist/lib/config-write-target.d.ts.map +0 -1
  232. package/dist/lib/config-write-target.js.map +0 -1
  233. package/dist/lib/config.d.ts.map +0 -1
  234. package/dist/lib/config.js.map +0 -1
  235. package/dist/lib/copilot.d.ts.map +0 -1
  236. package/dist/lib/copilot.js.map +0 -1
  237. package/dist/lib/cursor-detection.d.ts.map +0 -1
  238. package/dist/lib/cursor-detection.js.map +0 -1
  239. package/dist/lib/cursor-pricing.d.ts.map +0 -1
  240. package/dist/lib/cursor-pricing.js.map +0 -1
  241. package/dist/lib/cursor-usage.d.ts.map +0 -1
  242. package/dist/lib/cursor-usage.js.map +0 -1
  243. package/dist/lib/dashboard-visibility.d.ts.map +0 -1
  244. package/dist/lib/dashboard-visibility.js.map +0 -1
  245. package/dist/lib/deepseek-auth.d.ts.map +0 -1
  246. package/dist/lib/deepseek-auth.js.map +0 -1
  247. package/dist/lib/deepseek.d.ts.map +0 -1
  248. package/dist/lib/deepseek.js.map +0 -1
  249. package/dist/lib/display-sanitize.d.ts.map +0 -1
  250. package/dist/lib/display-sanitize.js.map +0 -1
  251. package/dist/lib/entries.d.ts.map +0 -1
  252. package/dist/lib/entries.js.map +0 -1
  253. package/dist/lib/env-template.d.ts.map +0 -1
  254. package/dist/lib/env-template.js.map +0 -1
  255. package/dist/lib/format-utils.d.ts.map +0 -1
  256. package/dist/lib/format-utils.js.map +0 -1
  257. package/dist/lib/format.d.ts.map +0 -1
  258. package/dist/lib/format.js.map +0 -1
  259. package/dist/lib/glm-coding-plan.d.ts.map +0 -1
  260. package/dist/lib/glm-coding-plan.js.map +0 -1
  261. package/dist/lib/google-agy-companion.d.ts.map +0 -1
  262. package/dist/lib/google-agy-companion.js.map +0 -1
  263. package/dist/lib/google-agy.d.ts.map +0 -1
  264. package/dist/lib/google-agy.js.map +0 -1
  265. package/dist/lib/google-companion-credentials.d.ts.map +0 -1
  266. package/dist/lib/google-companion-credentials.js.map +0 -1
  267. package/dist/lib/google-gemini-cli-companion.d.ts.map +0 -1
  268. package/dist/lib/google-gemini-cli-companion.js.map +0 -1
  269. package/dist/lib/google-gemini-cli.d.ts.map +0 -1
  270. package/dist/lib/google-gemini-cli.js.map +0 -1
  271. package/dist/lib/google-token-cache.d.ts.map +0 -1
  272. package/dist/lib/google-token-cache.js.map +0 -1
  273. package/dist/lib/grouped-entry-normalization.d.ts.map +0 -1
  274. package/dist/lib/grouped-entry-normalization.js.map +0 -1
  275. package/dist/lib/grouped-header-format.d.ts.map +0 -1
  276. package/dist/lib/grouped-header-format.js.map +0 -1
  277. package/dist/lib/gui-config-target.d.ts.map +0 -1
  278. package/dist/lib/gui-config-target.js.map +0 -1
  279. package/dist/lib/home-dir-display.d.ts.map +0 -1
  280. package/dist/lib/home-dir-display.js.map +0 -1
  281. package/dist/lib/http.d.ts.map +0 -1
  282. package/dist/lib/http.js.map +0 -1
  283. package/dist/lib/init-installer.d.ts.map +0 -1
  284. package/dist/lib/init-installer.js.map +0 -1
  285. package/dist/lib/jsonc.d.ts.map +0 -1
  286. package/dist/lib/jsonc.js.map +0 -1
  287. package/dist/lib/kilo-config.d.ts.map +0 -1
  288. package/dist/lib/kilo-config.js.map +0 -1
  289. package/dist/lib/kilo.d.ts.map +0 -1
  290. package/dist/lib/kilo.js.map +0 -1
  291. package/dist/lib/kimi-auth.d.ts.map +0 -1
  292. package/dist/lib/kimi-auth.js.map +0 -1
  293. package/dist/lib/kimi-endpoints.d.ts.map +0 -1
  294. package/dist/lib/kimi-endpoints.js.map +0 -1
  295. package/dist/lib/kimi.d.ts.map +0 -1
  296. package/dist/lib/kimi.js.map +0 -1
  297. package/dist/lib/maintainer-announcements.d.ts.map +0 -1
  298. package/dist/lib/maintainer-announcements.js.map +0 -1
  299. package/dist/lib/map-with-concurrency.d.ts.map +0 -1
  300. package/dist/lib/map-with-concurrency.js.map +0 -1
  301. package/dist/lib/markdown-table.d.ts.map +0 -1
  302. package/dist/lib/markdown-table.js.map +0 -1
  303. package/dist/lib/mimo-config.d.ts.map +0 -1
  304. package/dist/lib/mimo-config.js.map +0 -1
  305. package/dist/lib/mimo.d.ts.map +0 -1
  306. package/dist/lib/mimo.js.map +0 -1
  307. package/dist/lib/minimax-auth.d.ts.map +0 -1
  308. package/dist/lib/minimax-auth.js.map +0 -1
  309. package/dist/lib/minimax-endpoints.d.ts.map +0 -1
  310. package/dist/lib/minimax-endpoints.js.map +0 -1
  311. package/dist/lib/modelsdev-pricing.d.ts.map +0 -1
  312. package/dist/lib/modelsdev-pricing.js.map +0 -1
  313. package/dist/lib/nanogpt-config.d.ts.map +0 -1
  314. package/dist/lib/nanogpt-config.js.map +0 -1
  315. package/dist/lib/nanogpt.d.ts.map +0 -1
  316. package/dist/lib/nanogpt.js.map +0 -1
  317. package/dist/lib/ollama-cloud-config.d.ts.map +0 -1
  318. package/dist/lib/ollama-cloud-config.js.map +0 -1
  319. package/dist/lib/ollama-cloud.d.ts.map +0 -1
  320. package/dist/lib/ollama-cloud.js.map +0 -1
  321. package/dist/lib/openai.d.ts.map +0 -1
  322. package/dist/lib/openai.js.map +0 -1
  323. package/dist/lib/opencode-auth-sqlite.d.ts.map +0 -1
  324. package/dist/lib/opencode-auth-sqlite.js.map +0 -1
  325. package/dist/lib/opencode-auth.d.ts.map +0 -1
  326. package/dist/lib/opencode-auth.js.map +0 -1
  327. package/dist/lib/opencode-config-editor.d.ts.map +0 -1
  328. package/dist/lib/opencode-config-editor.js.map +0 -1
  329. package/dist/lib/opencode-config-providers.d.ts.map +0 -1
  330. package/dist/lib/opencode-config-providers.js.map +0 -1
  331. package/dist/lib/opencode-config-read.d.ts.map +0 -1
  332. package/dist/lib/opencode-config-read.js.map +0 -1
  333. package/dist/lib/opencode-console-auth.d.ts.map +0 -1
  334. package/dist/lib/opencode-console-auth.js.map +0 -1
  335. package/dist/lib/opencode-db-path.d.ts.map +0 -1
  336. package/dist/lib/opencode-db-path.js.map +0 -1
  337. package/dist/lib/opencode-go-auth.d.ts.map +0 -1
  338. package/dist/lib/opencode-go-auth.js.map +0 -1
  339. package/dist/lib/opencode-go.d.ts.map +0 -1
  340. package/dist/lib/opencode-go.js.map +0 -1
  341. package/dist/lib/opencode-runtime-paths.d.ts.map +0 -1
  342. package/dist/lib/opencode-runtime-paths.js.map +0 -1
  343. package/dist/lib/opencode-sqlite.d.ts.map +0 -1
  344. package/dist/lib/opencode-sqlite.js.map +0 -1
  345. package/dist/lib/opencode-storage.d.ts.map +0 -1
  346. package/dist/lib/opencode-storage.js.map +0 -1
  347. package/dist/lib/opencode-version.d.ts.map +0 -1
  348. package/dist/lib/opencode-version.js.map +0 -1
  349. package/dist/lib/opencode-zen.d.ts.map +0 -1
  350. package/dist/lib/opencode-zen.js.map +0 -1
  351. package/dist/lib/openrouter.d.ts.map +0 -1
  352. package/dist/lib/openrouter.js.map +0 -1
  353. package/dist/lib/private-state-paths.d.ts.map +0 -1
  354. package/dist/lib/private-state-paths.js.map +0 -1
  355. package/dist/lib/provider-add-command.d.ts.map +0 -1
  356. package/dist/lib/provider-add-command.js.map +0 -1
  357. package/dist/lib/provider-add-json-v1-questionnaire.d.ts.map +0 -1
  358. package/dist/lib/provider-add-json-v1-questionnaire.js.map +0 -1
  359. package/dist/lib/provider-add.d.ts.map +0 -1
  360. package/dist/lib/provider-add.js.map +0 -1
  361. package/dist/lib/provider-availability.d.ts.map +0 -1
  362. package/dist/lib/provider-availability.js.map +0 -1
  363. package/dist/lib/provider-metadata.d.ts.map +0 -1
  364. package/dist/lib/provider-metadata.js.map +0 -1
  365. package/dist/lib/provider-model-matching.d.ts.map +0 -1
  366. package/dist/lib/provider-model-matching.js.map +0 -1
  367. package/dist/lib/provider-registration.d.ts.map +0 -1
  368. package/dist/lib/provider-registration.js.map +0 -1
  369. package/dist/lib/quota-accounting-projection.d.ts.map +0 -1
  370. package/dist/lib/quota-accounting-projection.js.map +0 -1
  371. package/dist/lib/quota-columns.d.ts.map +0 -1
  372. package/dist/lib/quota-columns.js.map +0 -1
  373. package/dist/lib/quota-command-format.d.ts.map +0 -1
  374. package/dist/lib/quota-command-format.js.map +0 -1
  375. package/dist/lib/quota-dialog-command-specs.d.ts.map +0 -1
  376. package/dist/lib/quota-dialog-command-specs.js.map +0 -1
  377. package/dist/lib/quota-dialog-commands.d.ts.map +0 -1
  378. package/dist/lib/quota-dialog-commands.js.map +0 -1
  379. package/dist/lib/quota-entry-display.d.ts.map +0 -1
  380. package/dist/lib/quota-entry-display.js.map +0 -1
  381. package/dist/lib/quota-exhaustion-projection.d.ts.map +0 -1
  382. package/dist/lib/quota-exhaustion-projection.js.map +0 -1
  383. package/dist/lib/quota-export-types.d.ts.map +0 -1
  384. package/dist/lib/quota-export-types.js.map +0 -1
  385. package/dist/lib/quota-export.d.ts.map +0 -1
  386. package/dist/lib/quota-export.js.map +0 -1
  387. package/dist/lib/quota-format-style.d.ts.map +0 -1
  388. package/dist/lib/quota-format-style.js.map +0 -1
  389. package/dist/lib/quota-providers-local.d.ts.map +0 -1
  390. package/dist/lib/quota-providers-local.js.map +0 -1
  391. package/dist/lib/quota-providers-remote.d.ts.map +0 -1
  392. package/dist/lib/quota-providers-remote.js.map +0 -1
  393. package/dist/lib/quota-providers.d.ts.map +0 -1
  394. package/dist/lib/quota-providers.js.map +0 -1
  395. package/dist/lib/quota-render-data.d.ts.map +0 -1
  396. package/dist/lib/quota-render-data.js.map +0 -1
  397. package/dist/lib/quota-report-message.d.ts.map +0 -1
  398. package/dist/lib/quota-report-message.js.map +0 -1
  399. package/dist/lib/quota-reset-notifications.d.ts.map +0 -1
  400. package/dist/lib/quota-reset-notifications.js.map +0 -1
  401. package/dist/lib/quota-retry-wait.d.ts.map +0 -1
  402. package/dist/lib/quota-retry-wait.js.map +0 -1
  403. package/dist/lib/quota-runtime-context.d.ts.map +0 -1
  404. package/dist/lib/quota-runtime-context.js.map +0 -1
  405. package/dist/lib/quota-state-codec.d.ts.map +0 -1
  406. package/dist/lib/quota-state-codec.js.map +0 -1
  407. package/dist/lib/quota-state.d.ts.map +0 -1
  408. package/dist/lib/quota-state.js.map +0 -1
  409. package/dist/lib/quota-stats-format.d.ts.map +0 -1
  410. package/dist/lib/quota-stats-format.js.map +0 -1
  411. package/dist/lib/quota-stats.d.ts.map +0 -1
  412. package/dist/lib/quota-stats.js.map +0 -1
  413. package/dist/lib/quota-status.d.ts.map +0 -1
  414. package/dist/lib/quota-status.js.map +0 -1
  415. package/dist/lib/quota-surface-data.d.ts.map +0 -1
  416. package/dist/lib/quota-surface-data.js.map +0 -1
  417. package/dist/lib/quota-telemetry.d.ts.map +0 -1
  418. package/dist/lib/quota-telemetry.js.map +0 -1
  419. package/dist/lib/report-document.d.ts.map +0 -1
  420. package/dist/lib/report-document.js.map +0 -1
  421. package/dist/lib/resolved-auth-identity.d.ts.map +0 -1
  422. package/dist/lib/resolved-auth-identity.js.map +0 -1
  423. package/dist/lib/runtime-provider-ids.d.ts.map +0 -1
  424. package/dist/lib/runtime-provider-ids.js.map +0 -1
  425. package/dist/lib/scoped-query-chunks.d.ts.map +0 -1
  426. package/dist/lib/scoped-query-chunks.js.map +0 -1
  427. package/dist/lib/scoped-update-migration.d.ts.map +0 -1
  428. package/dist/lib/scoped-update-migration.js.map +0 -1
  429. package/dist/lib/scoped-update.d.ts.map +0 -1
  430. package/dist/lib/scoped-update.js.map +0 -1
  431. package/dist/lib/session-tokens-format.d.ts.map +0 -1
  432. package/dist/lib/session-tokens-format.js.map +0 -1
  433. package/dist/lib/session-tokens.d.ts.map +0 -1
  434. package/dist/lib/session-tokens.js.map +0 -1
  435. package/dist/lib/synthetic-config.d.ts.map +0 -1
  436. package/dist/lib/synthetic-config.js.map +0 -1
  437. package/dist/lib/synthetic.d.ts.map +0 -1
  438. package/dist/lib/synthetic.js.map +0 -1
  439. package/dist/lib/toast-format-grouped.d.ts.map +0 -1
  440. package/dist/lib/toast-format-grouped.js.map +0 -1
  441. package/dist/lib/token-buckets.d.ts.map +0 -1
  442. package/dist/lib/token-buckets.js.map +0 -1
  443. package/dist/lib/token-cost.d.ts.map +0 -1
  444. package/dist/lib/token-cost.js.map +0 -1
  445. package/dist/lib/tui-compact-format.d.ts.map +0 -1
  446. package/dist/lib/tui-compact-format.js.map +0 -1
  447. package/dist/lib/tui-panel-state.d.ts.map +0 -1
  448. package/dist/lib/tui-panel-state.js.map +0 -1
  449. package/dist/lib/tui-prompt-bar-format.d.ts.map +0 -1
  450. package/dist/lib/tui-prompt-bar-format.js.map +0 -1
  451. package/dist/lib/tui-sidebar-format.d.ts.map +0 -1
  452. package/dist/lib/tui-sidebar-format.js.map +0 -1
  453. package/dist/lib/types.d.ts.map +0 -1
  454. package/dist/lib/types.js.map +0 -1
  455. package/dist/lib/usage-ownership.d.ts.map +0 -1
  456. package/dist/lib/usage-ownership.js.map +0 -1
  457. package/dist/lib/version.d.ts.map +0 -1
  458. package/dist/lib/version.js.map +0 -1
  459. package/dist/lib/xai.d.ts.map +0 -1
  460. package/dist/lib/xai.js.map +0 -1
  461. package/dist/lib/zai-auth.d.ts.map +0 -1
  462. package/dist/lib/zai-auth.js.map +0 -1
  463. package/dist/lib/zai.d.ts.map +0 -1
  464. package/dist/lib/zai.js.map +0 -1
  465. package/dist/lib/zhipu-auth.d.ts.map +0 -1
  466. package/dist/lib/zhipu-auth.js.map +0 -1
  467. package/dist/lib/zhipu.d.ts.map +0 -1
  468. package/dist/lib/zhipu.js.map +0 -1
  469. package/dist/plugin.d.ts.map +0 -1
  470. package/dist/plugin.js.map +0 -1
  471. package/dist/providers/accounting-decimal.d.ts.map +0 -1
  472. package/dist/providers/accounting-decimal.js.map +0 -1
  473. package/dist/providers/alibaba-coding-plan.d.ts.map +0 -1
  474. package/dist/providers/alibaba-coding-plan.js.map +0 -1
  475. package/dist/providers/alibaba-token-plan.d.ts.map +0 -1
  476. package/dist/providers/alibaba-token-plan.js.map +0 -1
  477. package/dist/providers/anthropic.d.ts.map +0 -1
  478. package/dist/providers/anthropic.js.map +0 -1
  479. package/dist/providers/cache-policies.d.ts.map +0 -1
  480. package/dist/providers/cache-policies.js.map +0 -1
  481. package/dist/providers/chutes.d.ts.map +0 -1
  482. package/dist/providers/chutes.js.map +0 -1
  483. package/dist/providers/copilot.d.ts.map +0 -1
  484. package/dist/providers/copilot.js.map +0 -1
  485. package/dist/providers/cursor.d.ts.map +0 -1
  486. package/dist/providers/cursor.js.map +0 -1
  487. package/dist/providers/deepseek.d.ts.map +0 -1
  488. package/dist/providers/deepseek.js.map +0 -1
  489. package/dist/providers/glm-coding-plan-provider.d.ts.map +0 -1
  490. package/dist/providers/glm-coding-plan-provider.js.map +0 -1
  491. package/dist/providers/google-account-format.d.ts.map +0 -1
  492. package/dist/providers/google-account-format.js.map +0 -1
  493. package/dist/providers/google-agy.d.ts.map +0 -1
  494. package/dist/providers/google-agy.js.map +0 -1
  495. package/dist/providers/google-gemini-cli.d.ts.map +0 -1
  496. package/dist/providers/google-gemini-cli.js.map +0 -1
  497. package/dist/providers/kilo.d.ts.map +0 -1
  498. package/dist/providers/kilo.js.map +0 -1
  499. package/dist/providers/kimi-code.d.ts.map +0 -1
  500. package/dist/providers/kimi-code.js.map +0 -1
  501. package/dist/providers/mimo.d.ts.map +0 -1
  502. package/dist/providers/mimo.js.map +0 -1
  503. package/dist/providers/minimax-coding-plan.d.ts.map +0 -1
  504. package/dist/providers/minimax-coding-plan.js.map +0 -1
  505. package/dist/providers/nanogpt.d.ts.map +0 -1
  506. package/dist/providers/nanogpt.js.map +0 -1
  507. package/dist/providers/ollama-cloud.d.ts.map +0 -1
  508. package/dist/providers/ollama-cloud.js.map +0 -1
  509. package/dist/providers/openai.d.ts.map +0 -1
  510. package/dist/providers/openai.js.map +0 -1
  511. package/dist/providers/opencode-go.d.ts.map +0 -1
  512. package/dist/providers/opencode-go.js.map +0 -1
  513. package/dist/providers/opencode-zen.d.ts.map +0 -1
  514. package/dist/providers/opencode-zen.js.map +0 -1
  515. package/dist/providers/openrouter.d.ts.map +0 -1
  516. package/dist/providers/openrouter.js.map +0 -1
  517. package/dist/providers/quota-providers.d.ts.map +0 -1
  518. package/dist/providers/quota-providers.js.map +0 -1
  519. package/dist/providers/registry.d.ts.map +0 -1
  520. package/dist/providers/registry.js.map +0 -1
  521. package/dist/providers/result-helpers.d.ts.map +0 -1
  522. package/dist/providers/result-helpers.js.map +0 -1
  523. package/dist/providers/synthetic.d.ts.map +0 -1
  524. package/dist/providers/synthetic.js.map +0 -1
  525. package/dist/providers/xai.d.ts.map +0 -1
  526. package/dist/providers/xai.js.map +0 -1
  527. package/dist/providers/zai.d.ts.map +0 -1
  528. package/dist/providers/zai.js.map +0 -1
  529. package/dist/providers/zhipu.d.ts.map +0 -1
  530. package/dist/providers/zhipu.js.map +0 -1
  531. package/dist/rpc.d.ts.map +0 -1
  532. package/dist/rpc.js.map +0 -1
  533. package/dist/ui/assets/index-CjNjqsse.js +0 -8
@@ -8,7 +8,13 @@
8
8
  * owner's source, and when that owner disposes while other leases remain the
9
9
  * host switches to a live owner's source — created lazily on the next request —
10
10
  * without dropping the socket. The settings store is host-scoped file access.
11
- * The host closes with the last lease, releasing every source it created.
11
+ * One runtime — the stable delegating source and one `SnapshotService` — is
12
+ * shared by every transport attached to that host. The host closes with the
13
+ * last lease, releasing the snapshot service and every source it created. The
14
+ * web transport is optional and follows the host version when `dashboard.enabled`
15
+ * is absent (on below OpenCode 2.2.0, off from 2.2.0): when it is off, or when
16
+ * its fixed port cannot bind, the shared runtime stays available for the
17
+ * remaining leases and no HTTP/SSE/static surface is started.
12
18
  *
13
19
  * The registry lives on `globalThis` under a versioned `Symbol.for` key (the
14
20
  * quota-telemetry precedent), so two separately loaded copies of this module in
@@ -17,27 +23,33 @@
17
23
  * an error thrown by another module graph is structurally identical.
18
24
  *
19
25
  * Nothing here throws into the plugin: every failure becomes one controlled log
20
- * line and a lease in state `unavailable`. A failed bind is terminal (spec
21
- * §4.3) — no alternate port is ever tried, and the plugin's other surfaces are
22
- * untouched.
26
+ * line and a lease in state `unavailable`. A failed bind is terminal for the web
27
+ * transport (spec §4.3) — no alternate port is ever tried, and the plugin's
28
+ * other surfaces are untouched.
23
29
  */
24
30
  import { existsSync, readFileSync } from "node:fs";
25
- import { getGuiConfigPath, loadConfig } from "../lib/config.js";
31
+ import { createLoadConfigMeta, getGuiConfigPath, loadConfig } from "../lib/config.js";
32
+ import { getDashboardEnabledSetting, hasInvalidDashboardWebConfig, resolveDashboardWebEnabled, } from "../lib/dashboard-web-policy.js";
26
33
  import { parseConfigDocument } from "../lib/opencode-config-editor.js";
27
34
  import { getOpencodeRuntimeDirs } from "../lib/opencode-runtime-paths.js";
28
- import { createGuiSettingsStore, getGuiDashboardPort } from "./config.js";
35
+ import { detectOpenCodeVersion } from "../lib/opencode-version.js";
36
+ import { createGuiSettingsStore, getGuiDashboardPort, } from "./config.js";
29
37
  import { createGuiLogger } from "./log.js";
38
+ import { createQuotaNotificationObserver, quotaNotificationSettingsFromSnapshot, } from "./quota-notification-observer.js";
30
39
  import { createDashboardServer, } from "./server.js";
31
- import { DEFAULT_POLL_INTERVAL_MS } from "./snapshot-service.js";
40
+ import { createSnapshotService, DEFAULT_POLL_INTERVAL_MS, } from "./snapshot-service.js";
32
41
  import { createDashboardReadSource } from "./sources.js";
33
42
  /**
34
43
  * Versioned process-wide host registry. `Symbol.for` is realm-global, so every
35
44
  * separately loaded copy of this module in the same process resolves the same
36
45
  * map and shares the refcount and socket. The version is bumped when the host
37
- * record shape changes (`v2` adds owner delegation): an older copy then fails
38
- * the fixed port terminally instead of mutating a host it does not understand.
46
+ * record or start semantics change (`v2` added owner delegation, `v3` added the
47
+ * shared snapshot/source runtime, `v4` made the web transport optional while
48
+ * keeping the runtime, `v5` publishes the shared settings/snapshot runtime for
49
+ * RPC): an older copy then fails the fixed port terminally instead of mutating
50
+ * a host it does not understand.
39
51
  */
40
- const HOST_REGISTRY_KEY = Symbol.for("opencode-quota-gui/dashboard-lifecycle/v2");
52
+ const HOST_REGISTRY_KEY = Symbol.for("opencode-quota-gui/dashboard-lifecycle/v5");
41
53
  function hostRegistry() {
42
54
  const globalState = globalThis;
43
55
  const existing = globalState[HOST_REGISTRY_KEY];
@@ -58,6 +70,52 @@ function createOwner(options, configDir) {
58
70
  disposed: false,
59
71
  };
60
72
  }
73
+ /**
74
+ * One host's shared runtime. `close` is idempotent and is called by the final
75
+ * lease disposal; only the first call releases the snapshot service and every
76
+ * owner source still registered at that moment.
77
+ */
78
+ function createRuntime(source, logger) {
79
+ let closing;
80
+ const runtime = {
81
+ source,
82
+ snapshots: undefined,
83
+ quotaMonitor: undefined,
84
+ quotaNotifications: undefined,
85
+ settings: undefined,
86
+ close() {
87
+ if (closing)
88
+ return closing;
89
+ closing = (async () => {
90
+ try {
91
+ await runtime.quotaNotifications?.close();
92
+ }
93
+ catch (error) {
94
+ logger.warn("quota notification observer close failed", failureLabel(error));
95
+ }
96
+ runtime.quotaNotifications = undefined;
97
+ try {
98
+ runtime.quotaMonitor?.release();
99
+ }
100
+ catch (error) {
101
+ logger.warn("dashboard quota monitor close failed", failureLabel(error));
102
+ }
103
+ runtime.quotaMonitor = undefined;
104
+ try {
105
+ runtime.snapshots?.close();
106
+ }
107
+ catch (error) {
108
+ logger.warn("dashboard runtime close failed", failureLabel(error));
109
+ }
110
+ runtime.snapshots = undefined;
111
+ runtime.settings = undefined;
112
+ await closeSource(source, logger);
113
+ })();
114
+ return closing;
115
+ },
116
+ };
117
+ return runtime;
118
+ }
61
119
  /** The owner's source, created at most once and shared by concurrent callers. */
62
120
  function ownerSource(owner, logger) {
63
121
  if (owner.source)
@@ -124,22 +182,26 @@ function disposeOwner(owner, logger) {
124
182
  owner.sourceOptions = undefined;
125
183
  return releaseOwnerSource(owner, logger);
126
184
  }
127
- /** Removes a disposed owner and hands the host to the most recent live owner. */
185
+ /**
186
+ * Removes a disposed owner and hands the host to the most recent live owner.
187
+ * Returns true when the active serving identity changed.
188
+ */
128
189
  function dropOwner(host, owner) {
129
190
  const { owners } = host.delegation;
130
191
  const index = owners.indexOf(owner);
131
192
  if (index !== -1)
132
193
  owners.splice(index, 1);
133
- if (host.delegation.activeOwner === owner) {
134
- host.delegation.activeOwner = owners[owners.length - 1];
135
- }
194
+ if (host.delegation.activeOwner !== owner)
195
+ return false;
196
+ host.delegation.activeOwner = owners[owners.length - 1];
197
+ return true;
136
198
  }
137
199
  /**
138
200
  * The stable source the transport keeps for the host's lifetime. Every read
139
201
  * resolves the active owner's source; a delegate's source is not created until
140
202
  * a request needs it, so a handoff starts no analytics work by itself.
141
203
  */
142
- function createDelegatingSource(delegation, logger) {
204
+ function createDelegatingSource(delegation, logger, observation) {
143
205
  const requireSource = () => {
144
206
  const owner = delegation.activeOwner;
145
207
  if (!owner)
@@ -152,19 +214,30 @@ function createDelegatingSource(delegation, logger) {
152
214
  session: async (input) => (await requireSource()).session(input),
153
215
  groups: async (query) => (await requireSource()).groups(query),
154
216
  quota: async () => {
217
+ // Capture the source generation before resolving the owner and before the
218
+ // asynchronous provider read. A handoff during either step changes the
219
+ // token, and the observer drops the old source's snapshot instead of
220
+ // classifying it against the replacement source's baseline.
221
+ const observer = observation.observer;
222
+ const epoch = observer?.epoch();
223
+ const owner = delegation.activeOwner;
155
224
  const source = await requireSource();
156
225
  // Mirrors `SnapshotService`: a source without quota answers as unavailable.
157
226
  if (!source.quota)
158
227
  throw new Error("Quota source unavailable");
159
- return source.quota();
228
+ const snapshot = await source.quota();
229
+ if (observer !== undefined && delegation.activeOwner === owner) {
230
+ observer.observe(snapshot, epoch);
231
+ }
232
+ return snapshot;
160
233
  },
161
234
  refreshAnalytics: async () => {
162
235
  // Only refresh an already-created active source; never build one here.
163
236
  await delegation.activeOwner?.source?.refreshAnalytics?.();
164
237
  },
165
238
  close: async () => {
166
- // Bind failure and final close both land here: release every source this
167
- // host created, without ending the leases themselves.
239
+ // Final host close lands here: release every source this host created,
240
+ // without ending the leases themselves.
168
241
  await Promise.all(delegation.owners.map((owner) => releaseOwnerSource(owner, logger)));
169
242
  },
170
243
  };
@@ -248,43 +321,89 @@ function canonicalMinIntervalMs(configDir) {
248
321
  return undefined;
249
322
  }
250
323
  }
251
- /** Port and interval from the effective config; a read failure keeps the defaults. */
252
- async function readDashboardConfig(workspaceRoot, configDir, logger) {
324
+ /**
325
+ * Port, effective web switch and interval from the loaded config and host
326
+ * version; a read failure keeps safe defaults. The version probe runs only when
327
+ * the key is absent, so explicit configuration never spawns a CLI process.
328
+ */
329
+ async function readDashboardConfig(workspaceRoot, configDir, logger, hostVersion, detectHostVersion) {
253
330
  try {
254
- const config = await loadConfig(undefined, undefined, {
331
+ const meta = createLoadConfigMeta();
332
+ const config = await loadConfig(undefined, meta, {
255
333
  configRootDir: workspaceRoot,
256
334
  globalConfigDir: configDir,
257
335
  });
336
+ const explicitEnabled = getDashboardEnabledSetting(config, meta);
337
+ const invalidConfig = hasInvalidDashboardWebConfig(meta);
338
+ let resolvedHostVersion = typeof hostVersion === "string" && hostVersion.trim().length > 0 ? hostVersion : undefined;
339
+ if (explicitEnabled === undefined && !invalidConfig && resolvedHostVersion === undefined) {
340
+ resolvedHostVersion = await detectHostVersion();
341
+ }
258
342
  return {
259
343
  port: getGuiDashboardPort(config),
344
+ webEnabled: resolveDashboardWebEnabled({
345
+ ...(explicitEnabled !== undefined ? { explicitEnabled } : {}),
346
+ ...(resolvedHostVersion !== undefined ? { hostVersion: resolvedHostVersion } : {}),
347
+ invalidConfig,
348
+ }),
349
+ hostVersion: resolvedHostVersion,
260
350
  minIntervalMs: positiveNumber(config.minIntervalMs),
261
351
  };
262
352
  }
263
353
  catch {
264
- logger.warn("dashboard config unavailable; using the default port", "config-unavailable");
265
- return { port: getGuiDashboardPort(undefined), minIntervalMs: undefined };
354
+ logger.warn("dashboard config unavailable; using safe defaults", "config-unavailable");
355
+ return {
356
+ port: getGuiDashboardPort(undefined),
357
+ webEnabled: false,
358
+ hostVersion: undefined,
359
+ minIntervalMs: undefined,
360
+ };
266
361
  }
267
362
  }
268
363
  async function createProductionSource(options) {
269
364
  return createDashboardReadSource(options);
270
365
  }
271
366
  /**
272
- * Settings store, first owner's eager source and transport, in that order; each
273
- * failure is contained. The source passed to the transport is the host's stable
274
- * delegating source, so later owner handoffs keep the same snapshot service.
367
+ * Settings store, first owner's eager source, one host snapshot service and the
368
+ * optional web transport, in that order; each failure is contained. The
369
+ * transport receives that snapshot service, whose stable delegating source
370
+ * keeps the same cache and pollers across later owner handoffs. A disabled or
371
+ * unavailable web transport never tears down that shared runtime.
275
372
  */
276
- async function startHost(options, context, delegation) {
373
+ async function startHost(options, context, delegation, runtime, observation) {
277
374
  const createSettingsStore = options.createSettingsStore ?? createGuiSettingsStore;
278
375
  let settings;
279
376
  try {
280
377
  settings = createSettingsStore({
281
378
  configDir: context.configDir,
282
379
  workspaceRoot: options.workspaceRoot,
380
+ ...(context.hostVersion !== undefined ? { hostVersion: context.hostVersion } : {}),
283
381
  });
284
382
  }
285
383
  catch {
286
384
  throw new DashboardLifecycleError("settings-unavailable");
287
385
  }
386
+ // Publish the same store to every transport. It stays host-owned until the
387
+ // last lease disposes, regardless of whether the web transport starts.
388
+ runtime.settings = settings;
389
+ // One observer for this shared host. It is fed by the stable delegating
390
+ // source's quota cycle, so it adds no poller and works with every transport
391
+ // combination, including a closed panel. Settings are read per cycle so a
392
+ // saved threshold or visibility change applies without a restart.
393
+ try {
394
+ const quotaNotifications = createQuotaNotificationObserver({
395
+ loadSettings: async () => quotaNotificationSettingsFromSnapshot(await settings.settings()),
396
+ ...(options.quotaNotificationStatePath !== undefined
397
+ ? { statePath: options.quotaNotificationStatePath }
398
+ : {}),
399
+ logger: context.logger,
400
+ });
401
+ runtime.quotaNotifications = quotaNotifications;
402
+ observation.observer = quotaNotifications;
403
+ }
404
+ catch (error) {
405
+ context.logger.warn("quota notifications unavailable", failureLabel(error));
406
+ }
288
407
  const firstOwner = delegation.activeOwner;
289
408
  if (!firstOwner)
290
409
  throw new DashboardLifecycleError("source-unavailable");
@@ -296,24 +415,68 @@ async function startHost(options, context, delegation) {
296
415
  catch {
297
416
  throw new DashboardLifecycleError("source-unavailable");
298
417
  }
299
- const source = createDelegatingSource(delegation, context.logger);
418
+ // The host owns exactly one snapshot service. HTTP and the typed RPC
419
+ // transport receive it; they never construct or close it themselves.
420
+ const createSnapshots = options.createSnapshots ?? createSnapshotService;
421
+ let snapshots;
422
+ try {
423
+ snapshots = createSnapshots({
424
+ source: runtime.source,
425
+ minIntervalMs: minIntervalGetter(context),
426
+ logger: context.logger,
427
+ });
428
+ }
429
+ catch {
430
+ await runtime.close();
431
+ throw new DashboardLifecycleError("server-unavailable");
432
+ }
433
+ runtime.snapshots = snapshots;
434
+ // One host-lifetime quota viewer keeps `viewers >= 1` across ordinary window
435
+ // watch aborts and silent renewals, so the original `viewers === 0` teardown
436
+ // (stopPollers, compute clearing, cache dirtying) never runs on a timeout.
437
+ // Global bounded analytics pages therefore stay warm until normal eviction.
438
+ runtime.quotaMonitor = snapshots.addScopedViewer("quota");
439
+ // A scoped viewer starts the shared pollers, but quota polling has no
440
+ // registered interest until an actual quota read installs its compute key.
441
+ // Prime it once so the single host poller remains useful between windows.
442
+ void snapshots.quota().catch(() => undefined);
443
+ // Web is a secondary transport; the version-gated policy decides whether it
444
+ // starts. The shared quota monitor is already live; returning no handle starts
445
+ // no HTTP listener, SSE hub, or static serving, and does not activate analytics.
446
+ if (!context.webEnabled)
447
+ return undefined;
300
448
  const createServer = options.createServer ?? createDashboardServer;
301
449
  try {
302
450
  return await createServer({
303
451
  port: context.port,
304
- source,
452
+ snapshots,
305
453
  settings,
306
- minIntervalMs: minIntervalGetter(context),
307
454
  logger: context.logger,
308
455
  });
309
456
  }
310
457
  catch (error) {
311
458
  // A bind failure already logged its one controlled line inside the transport
312
459
  // and keeps its `port-unavailable` reason; every other server failure is
313
- // reported as `server-unavailable`.
460
+ // reported as `server-unavailable`. The shared runtime deliberately stays
461
+ // alive for its leases (the RPC transport can still use it); only the
462
+ // failed web transport is detached by the transport itself.
314
463
  throw new DashboardLifecycleError(unavailableReason(error));
315
464
  }
316
465
  }
466
+ /**
467
+ * The transport-neutral host dependencies for a lease. A missing snapshot
468
+ * service or settings store means the shared runtime never completed, so there
469
+ * is nothing safe to attach a second transport to.
470
+ */
471
+ function transportRuntime(runtime) {
472
+ if (!runtime.snapshots || !runtime.settings)
473
+ return undefined;
474
+ return {
475
+ snapshots: runtime.snapshots,
476
+ settings: runtime.settings,
477
+ ...(runtime.quotaNotifications ? { quotaNotifications: runtime.quotaNotifications } : {}),
478
+ };
479
+ }
317
480
  function makeDispose(host, owner, handle) {
318
481
  let disposed = false;
319
482
  return async () => {
@@ -321,10 +484,16 @@ function makeDispose(host, owner, handle) {
321
484
  return;
322
485
  disposed = true;
323
486
  host.refs = Math.max(0, host.refs - 1);
324
- dropOwner(host, owner);
487
+ const activeChanged = dropOwner(host, owner);
325
488
  const closing = disposeOwner(owner, host.logger);
326
489
  if (host.refs > 0) {
327
- // A live lease keeps the socket; the surviving owner serves next request.
490
+ // A live lease keeps the socket and the shared runtime. The surviving
491
+ // owner serves the next request, so cached pages from the disposed owner
492
+ // are invalidated before any client can see them as fresh.
493
+ if (activeChanged) {
494
+ host.runtime.snapshots?.sourceChanged();
495
+ host.runtime.quotaNotifications?.sourceChanged();
496
+ }
328
497
  await closing;
329
498
  return;
330
499
  }
@@ -339,6 +508,7 @@ function makeDispose(host, owner, handle) {
339
508
  host.logger.warn("dashboard stop failed", failureLabel(error));
340
509
  }
341
510
  }
511
+ await host.runtime.close();
342
512
  await closing;
343
513
  };
344
514
  }
@@ -358,17 +528,21 @@ async function attachLease(host, owner) {
358
528
  host.logger.error("dashboard unavailable", host.failure);
359
529
  }
360
530
  }
531
+ const runtime = transportRuntime(host.runtime);
361
532
  return {
362
533
  port: host.port,
363
534
  state: "unavailable",
364
535
  reason: host.failure,
536
+ ...(runtime ? { runtime } : {}),
365
537
  dispose: makeDispose(host, owner, undefined),
366
538
  };
367
539
  }
540
+ const runtime = transportRuntime(host.runtime);
368
541
  return {
369
542
  port: host.port,
370
543
  state: "running",
371
- url: handle.url,
544
+ ...(handle ? { url: handle.url } : {}),
545
+ ...(runtime ? { runtime } : {}),
372
546
  dispose: makeDispose(host, owner, handle),
373
547
  };
374
548
  }
@@ -379,7 +553,8 @@ async function attachLease(host, owner) {
379
553
  export async function startDashboard(options) {
380
554
  const logger = options.logger ?? createGuiLogger();
381
555
  const configDir = options.configDir ?? getOpencodeRuntimeDirs().configDir;
382
- const { port, minIntervalMs } = await readDashboardConfig(options.workspaceRoot, configDir, logger);
556
+ const detectHostVersion = options.detectHostVersion ?? detectOpenCodeVersion;
557
+ const { port, webEnabled, hostVersion, minIntervalMs } = await readDashboardConfig(options.workspaceRoot, configDir, logger, options.hostVersion, detectHostVersion);
383
558
  const hosts = hostRegistry().hosts;
384
559
  const existing = hosts.get(port);
385
560
  if (existing) {
@@ -390,12 +565,15 @@ export async function startDashboard(options) {
390
565
  }
391
566
  const owner = createOwner(options, configDir);
392
567
  const delegation = { owners: [owner], activeOwner: owner };
568
+ const observation = {};
569
+ const runtime = createRuntime(createDelegatingSource(delegation, logger, observation), logger);
393
570
  const host = {
394
571
  port,
395
572
  logger,
396
573
  delegation,
574
+ runtime,
397
575
  refs: 1,
398
- start: startHost(options, { configDir, port, minIntervalMs, logger }, delegation),
576
+ start: startHost(options, { configDir, port, webEnabled, hostVersion, minIntervalMs, logger }, delegation, runtime, observation),
399
577
  };
400
578
  hosts.set(port, host);
401
579
  return attachLease(host, owner);
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Server-side primary quota-window classification for the native
3
+ * `session.header` tokens (migration architecture §8, Stage 6).
4
+ *
5
+ * The projection only promotes an **existing** finite percentage row whose
6
+ * provider-owned identity says it is one of the subscription's main usage
7
+ * windows. Display labels, emission position, current utilization and the
8
+ * "most constraining" row never decide membership or slot. Budget, spend,
9
+ * balance, credits, model/tool-specific secondary allowances and
10
+ * response-defined dynamic rows stay in the combined preview and full card.
11
+ *
12
+ * Slots are stable per-card family positions in full-card order (0 outer,
13
+ * 1 middle, 2 inner), not global time-unit ranks; they are assigned from
14
+ * established window semantics, never from utilization. A missing earlier
15
+ * window leaves later windows on their original slot. Identity follows
16
+ * `rowIdForEntry` exactly: `semantic.metric` first, then an explicit provider
17
+ * `rowKey`, then the aggregate result-type identity. Rules are keyed by
18
+ * provider id so a shared row key cannot leak across providers.
19
+ */
20
+ import type { PrimaryQuotaWindowSlot } from "../contracts/dashboard.js";
21
+ import type { QuotaToastEntry } from "../lib/entries.js";
22
+ /**
23
+ * Stable slot for an eligible primary window, or `undefined` when the entry is
24
+ * not classified. Callers must still apply row-id deduplication and the
25
+ * three-reference limit.
26
+ */
27
+ export declare function primaryQuotaWindowSlot(providerId: string, entry: QuotaToastEntry): PrimaryQuotaWindowSlot | undefined;
28
+ //# sourceMappingURL=primary-quota-windows.d.ts.map
@@ -0,0 +1,147 @@
1
+ import { isPercentEntry } from "../lib/entries.js";
2
+ /**
3
+ * Explicit, evidence-backed mapping. Omitted providers intentionally have no
4
+ * defensible primary/auxiliary split in their current source (see the Stage 6
5
+ * report); adding one is a provider-semantics change, not a label heuristic.
6
+ */
7
+ const PRIMARY_QUOTA_WINDOW_RULES = {
8
+ // 5h, weekly, and the provider's explicit Fable weekly slot; `window:month`
9
+ // is Usage Credits (`src/providers/anthropic.ts` 160-195, 240-274).
10
+ anthropic: {
11
+ rowKeys: [
12
+ { value: "window:five_hour", slot: 0 },
13
+ { value: "window:week", slot: 1 },
14
+ ],
15
+ namedMetrics: [{ value: "Fable weekly", slot: 2 }],
16
+ },
17
+ // 5h/weekly/monthly ChatGPT windows; Code Review is a special secondary
18
+ // window (`src/providers/openai.ts` 56-75, 239-261).
19
+ openai: {
20
+ rowKeys: [
21
+ { value: "window:five_hour", slot: 0 },
22
+ { value: "window:week", slot: 1 },
23
+ { value: "window:month", slot: 2 },
24
+ ],
25
+ },
26
+ // GLM five-hour/weekly plan windows; MCP is a tool-specific allowance
27
+ // (`src/providers/glm-coding-plan-provider.ts` 40-79).
28
+ zai: {
29
+ rowKeys: [
30
+ { value: "window:five_hour", slot: 0 },
31
+ { value: "window:week", slot: 1 },
32
+ ],
33
+ },
34
+ zhipu: {
35
+ rowKeys: [
36
+ { value: "window:five_hour", slot: 0 },
37
+ { value: "window:week", slot: 1 },
38
+ ],
39
+ },
40
+ // Rolling/weekly/monthly Go plan windows (`src/providers/opencode-go.ts` 44-55).
41
+ "opencode-go": {
42
+ rowKeys: [
43
+ { value: "window:five_hour", slot: 0 },
44
+ { value: "window:week", slot: 1 },
45
+ { value: "window:month", slot: 2 },
46
+ ],
47
+ },
48
+ // The plan entitlement is Copilot's only primary window, so it occupies the
49
+ // outer slot; the additional-usage row is a budget percent
50
+ // (`src/providers/copilot.ts` 109-142, 185-215).
51
+ copilot: { rowKeys: [{ value: "window:month", slot: 0 }] },
52
+ // Daily/monthly subscription limits are the provider's two-window family in
53
+ // full-card order (`src/providers/nanogpt.ts` 70-105).
54
+ nanogpt: {
55
+ windows: [
56
+ { value: "day", slot: 0 },
57
+ { value: "month", slot: 1 },
58
+ ],
59
+ },
60
+ // MiniMax token-plan 5h/weekly windows (`src/providers/minimax-coding-plan.ts`
61
+ // 105-126, 246-260).
62
+ "minimax-coding-plan": {
63
+ windows: [
64
+ { value: "five_hour", slot: 0 },
65
+ { value: "week", slot: 1 },
66
+ ],
67
+ },
68
+ "minimax-china-coding-plan": {
69
+ windows: [
70
+ { value: "five_hour", slot: 0 },
71
+ { value: "week", slot: 1 },
72
+ ],
73
+ },
74
+ // MiMo's plan window is the card's only primary window, so it occupies the
75
+ // outer slot; its balance rows are quantities, not percentages
76
+ // (`src/providers/mimo.ts` 154-189).
77
+ xiaomi: { windows: [{ value: "month", slot: 0 }] },
78
+ // Kilo Pass credits are a quota percentage with a used/limit/remaining basis,
79
+ // not a balance; the card has one stable primary slot (`src/providers/kilo.ts`
80
+ // 52-82).
81
+ kilo: { components: [{ value: "remaining_credits", slot: 0 }] },
82
+ // xAI always emits exactly one provider-supplied period row, so any valid
83
+ // period identity occupies the same outer slot even when the response-defined
84
+ // period changes (`src/providers/xai.ts` 29-40, 92-153).
85
+ xai: {
86
+ rowKeys: [
87
+ { value: "window:day", slot: 0 },
88
+ { value: "window:week", slot: 0 },
89
+ { value: "window:month", slot: 0 },
90
+ { value: "named:period", slot: 0 },
91
+ ],
92
+ },
93
+ // These providers always emit the same single surviving row, so its window
94
+ // meaning cannot move with availability. Synthetic always emits 5h then
95
+ // weekly; Alibaba Coding Plan always emits 5h/weekly/monthly in that order;
96
+ // Chutes emits one daily-reset quota window (`src/providers/synthetic.ts`
97
+ // 84-103, `src/providers/alibaba-coding-plan.ts` 116-159,
98
+ // `src/providers/chutes.ts` 43-55).
99
+ //
100
+ // Deliberately omitted untyped providers:
101
+ // - Alibaba Token Plan emits optional 5h/weekly
102
+ // (`src/providers/alibaba-token-plan.ts` 69-74).
103
+ // - Ollama Cloud emits optional session/weekly/included-credit rows
104
+ // (`src/providers/ollama-cloud.ts` 35-80).
105
+ // Their shared aggregate row keeps one rowId while the represented window
106
+ // changes with availability, so a reference would be unstable.
107
+ // - Custom `quota-providers` result types are user configuration, not
108
+ // provider-owned primary/auxiliary evidence.
109
+ synthetic: { untypedSlot: 0 },
110
+ chutes: { untypedSlot: 0 },
111
+ "alibaba-coding-plan": { untypedSlot: 0 },
112
+ };
113
+ function slotFor(values, value) {
114
+ return values?.find((entry) => entry.value === value)?.slot;
115
+ }
116
+ /**
117
+ * Stable slot for an eligible primary window, or `undefined` when the entry is
118
+ * not classified. Callers must still apply row-id deduplication and the
119
+ * three-reference limit.
120
+ */
121
+ export function primaryQuotaWindowSlot(providerId, entry) {
122
+ const rule = PRIMARY_QUOTA_WINDOW_RULES[providerId];
123
+ if (!rule)
124
+ return undefined;
125
+ if (!isPercentEntry(entry) || !Number.isFinite(entry.percentRemaining))
126
+ return undefined;
127
+ if (entry.accounting.resultType !== "quota" && entry.accounting.resultType !== "rate_limit") {
128
+ return undefined;
129
+ }
130
+ if (entry.semantic) {
131
+ if (entry.semantic.prominence !== "primary")
132
+ return undefined;
133
+ const metric = entry.semantic.metric;
134
+ if (metric.kind === "window")
135
+ return slotFor(rule.windows, metric.window);
136
+ if (metric.kind === "named")
137
+ return slotFor(rule.namedMetrics, metric.name);
138
+ if (metric.kind === "component")
139
+ return slotFor(rule.components, metric.component);
140
+ return undefined;
141
+ }
142
+ if (entry.rowKey !== undefined) {
143
+ return slotFor(rule.rowKeys, entry.rowKey);
144
+ }
145
+ return rule.untypedSlot;
146
+ }
147
+ //# sourceMappingURL=primary-quota-windows.js.map
@@ -1,4 +1,4 @@
1
- import type { ProviderCard } from "../contracts/dashboard.js";
1
+ import { type ProviderCard } from "../contracts/dashboard.js";
2
2
  import type { CardId } from "../contracts/identity.js";
3
3
  import type { QuotaStatusLiveProbe } from "../lib/quota-render-data.js";
4
4
  import type { QuotaToastConfig } from "../lib/types.js";