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
@@ -0,0 +1,310 @@
1
+ /**
2
+ * Typed dashboard RPC transport (Stage 3).
3
+ *
4
+ * This adapter attaches to the host-owned `SnapshotService` and settings store
5
+ * from `lifecycle.ts`. It never constructs a source, snapshot service, worker or
6
+ * poller, so native-only, web-only, both and neither all share one runtime.
7
+ * Inputs are validated by the RPC definition; failures are mapped to the fixed
8
+ * transport error vocabulary without raw messages or private paths. No method
9
+ * accepts a filesystem path, credential, or workspace override: reads execute
10
+ * through the host's active owner and its configured workspace.
11
+ *
12
+ * Authorization is the host's: OpenCode applies its server-wide
13
+ * `Authorization` middleware to the RPC route (the normal CLI defaults to
14
+ * loopback plus a generated password; embedded/passwordless hosts rely on their
15
+ * embedder). No caller identity or per-method permission is exposed to a
16
+ * handler (2.0.16 `RpcCallContext` has only `signal` and `error`), so this
17
+ * transport does not invent a second permission model. Settings writes keep
18
+ * their optimistic `expectedRevision` guard but rely on the host's server-level
19
+ * access control.
20
+ */
21
+ import { BUILD_IDENTITY } from "../contracts/build-identity.js";
22
+ import { DASHBOARD_HEALTH, DashboardRpc, } from "../rpc.js";
23
+ import { GuiSettingsError } from "./config.js";
24
+ import { DASHBOARD_ERROR_MESSAGES, isDashboardSourceErrorCode, sanitizeDashboardErrorDetails, } from "./dashboard-errors.js";
25
+ import { createGuiLogger } from "./log.js";
26
+ /**
27
+ * Collision-safe transport key for the full location. JSON array encoding keeps
28
+ * the two components distinct even when a directory or id contains separators,
29
+ * and distinguishes an absent workspace from a present one.
30
+ */
31
+ function locationKey(location) {
32
+ return location === undefined
33
+ ? "none"
34
+ : JSON.stringify([location.directory, location.workspaceID ?? null]);
35
+ }
36
+ const SHARED_REGISTRY_KEY = Symbol.for("opencode-quota-gui/dashboard-rpc-registry/v3");
37
+ /**
38
+ * Process-wide (and module-graph-wide) sharing of the snapshot subscription per
39
+ * host snapshot owner and location. The lifecycle already shares the source,
40
+ * settings store and `SnapshotService`; each lease receives a fresh runtime
41
+ * wrapper around those objects, so the snapshot service is the stable identity.
42
+ */
43
+ function sharedRegistry() {
44
+ const globalState = globalThis;
45
+ const existing = globalState[SHARED_REGISTRY_KEY];
46
+ if (existing)
47
+ return existing;
48
+ const registry = new WeakMap();
49
+ globalState[SHARED_REGISTRY_KEY] = registry;
50
+ return registry;
51
+ }
52
+ const SETTINGS_ERROR_CODES = new Set([
53
+ "config-read-error",
54
+ "config-changed",
55
+ "config-target-error",
56
+ "config-write-error",
57
+ "unknown-setting",
58
+ "invalid-setting",
59
+ ]);
60
+ function controlledCode(error) {
61
+ if (error === null || typeof error !== "object" || !("code" in error))
62
+ return undefined;
63
+ return typeof error.code === "string" ? error.code : undefined;
64
+ }
65
+ function errorDetails(error) {
66
+ if (error === null || typeof error !== "object" || !("details" in error))
67
+ return undefined;
68
+ const details = error.details;
69
+ if (details === null || typeof details !== "object")
70
+ return undefined;
71
+ const result = {};
72
+ if ("key" in details && typeof details.key === "string")
73
+ result.key = details.key;
74
+ if ("reason" in details && typeof details.reason === "string")
75
+ result.reason = details.reason;
76
+ return result;
77
+ }
78
+ /** Maps a controlled or unexpected failure to the RPC error vocabulary. */
79
+ function mapRpcError(error) {
80
+ const code = error instanceof GuiSettingsError ? error.code : controlledCode(error);
81
+ if (code !== undefined && (isDashboardSourceErrorCode(code) || SETTINGS_ERROR_CODES.has(code))) {
82
+ // SAFETY: both membership checks above only admit codes from the shared
83
+ // dashboard error vocabulary, all of which the RPC map declares.
84
+ const safeCode = code;
85
+ return {
86
+ // SAFETY: every code admitted above is one of the dashboard RPC error keys.
87
+ code: safeCode,
88
+ message: DASHBOARD_ERROR_MESSAGES[safeCode],
89
+ details: sanitizeDashboardErrorDetails(safeCode, errorDetails(error)) ?? {},
90
+ };
91
+ }
92
+ return {
93
+ code: "internal",
94
+ message: DASHBOARD_ERROR_MESSAGES.internal,
95
+ details: {},
96
+ };
97
+ }
98
+ /**
99
+ * The error factory is typed per method, but every dashboard method declares
100
+ * the same controlled vocabulary. The safety assertion only narrows the
101
+ * already-validated shared code to that method's error-name union.
102
+ */
103
+ function failure(context, error) {
104
+ const mapped = mapRpcError(error);
105
+ // SAFETY: every dashboard method declares the shared error map, so its
106
+ // factory accepts exactly the controlled code/message/details triple below.
107
+ const factory = context.error;
108
+ return factory(mapped.code, mapped.message, mapped.details);
109
+ }
110
+ async function guard(context, run) {
111
+ try {
112
+ return await run();
113
+ }
114
+ catch (error) {
115
+ return failure(context, error);
116
+ }
117
+ }
118
+ function waitForAbort(signal, onStop) {
119
+ return new Promise((resolve) => {
120
+ let settled = false;
121
+ const finish = () => {
122
+ if (settled)
123
+ return;
124
+ settled = true;
125
+ signal.removeEventListener("abort", finish);
126
+ resolve();
127
+ };
128
+ onStop(finish);
129
+ if (signal.aborted)
130
+ finish();
131
+ else
132
+ signal.addEventListener("abort", finish, { once: true });
133
+ });
134
+ }
135
+ function createHandlers(runtime, heldWatches, onWatchSnapshot) {
136
+ async function watch(input, context) {
137
+ return guard(context, async () => {
138
+ const viewer = runtime.snapshots.addScopedViewer(input.scope);
139
+ if (!context.signal.aborted && input.attemptNonce !== undefined) {
140
+ try {
141
+ onWatchSnapshot?.(input.attemptNonce);
142
+ }
143
+ catch {
144
+ // Snapshot relay failure cannot interrupt this held viewer's lifecycle.
145
+ }
146
+ }
147
+ let stopped = false;
148
+ let stop = () => { };
149
+ await waitForAbort(context.signal, (finish) => {
150
+ stop = () => {
151
+ if (stopped)
152
+ return;
153
+ stopped = true;
154
+ heldWatches.delete(stop);
155
+ finish();
156
+ viewer.release();
157
+ };
158
+ heldWatches.add(stop);
159
+ });
160
+ stop();
161
+ return { active: false };
162
+ });
163
+ }
164
+ const handlers = {
165
+ health: async () => ({
166
+ ...DASHBOARD_HEALTH,
167
+ version: BUILD_IDENTITY.version,
168
+ build: BUILD_IDENTITY.build,
169
+ }),
170
+ quota: (input, context) => guard(context, () => runtime.snapshots.quota(input)),
171
+ home: (input, context) => guard(context, () => runtime.snapshots.home(input)),
172
+ groups: (input, context) => guard(context, () => runtime.snapshots.groups(input)),
173
+ project: (input, context) => guard(context, () => runtime.snapshots.project(input)),
174
+ session: (input, context) => guard(context, () => runtime.snapshots.session(input)),
175
+ settings: (_input, context) => guard(context, () => runtime.settings.settings()),
176
+ saveSettings: (input, context) => guard(context, async () => {
177
+ const result = await runtime.settings.saveSettings(input);
178
+ runtime.snapshots.notifySettingsChanged();
179
+ return result;
180
+ }),
181
+ saveVisibility: (input, context) => guard(context, async () => {
182
+ const result = await runtime.settings.saveVisibility(input);
183
+ runtime.snapshots.notifySettingsChanged({ scope: "visibility" });
184
+ return result;
185
+ }),
186
+ importPreview: (_input, context) => guard(context, () => runtime.settings.importPreview()),
187
+ importApply: (input, context) => guard(context, async () => {
188
+ const result = await runtime.settings.importApply(input);
189
+ runtime.snapshots.notifySettingsChanged();
190
+ return result;
191
+ }),
192
+ openSettingsFile: (_input, context) => guard(context, async () => {
193
+ const open = runtime.settings.openSettingsFile;
194
+ if (!open) {
195
+ throw new GuiSettingsError("config-target-error", "Opening the settings file is not available");
196
+ }
197
+ await open();
198
+ return { opened: true };
199
+ }),
200
+ watch,
201
+ };
202
+ return handlers;
203
+ }
204
+ /** Adds a setup's registration to the shared entry, creating its subscription once. */
205
+ function joinSharedEntry(snapshots, key, member, notifications) {
206
+ const registry = sharedRegistry();
207
+ let byKey = registry.get(snapshots);
208
+ if (!byKey) {
209
+ byKey = new Map();
210
+ registry.set(snapshots, byKey);
211
+ }
212
+ const existing = byKey.get(key);
213
+ if (existing) {
214
+ existing.members.push(member);
215
+ attachNotificationSubscription(existing, notifications);
216
+ return existing;
217
+ }
218
+ let entry;
219
+ const unsubscribe = snapshots.subscribe((event) => {
220
+ if (entry)
221
+ emitInvalidation(entry, event);
222
+ });
223
+ entry = { members: [member], unsubscribe };
224
+ byKey.set(key, entry);
225
+ attachNotificationSubscription(entry, notifications);
226
+ return entry;
227
+ }
228
+ function attachNotificationSubscription(entry, notifications) {
229
+ if (!notifications || entry.unsubscribeNotifications)
230
+ return;
231
+ entry.unsubscribeNotifications = notifications.subscribe((data) => {
232
+ emitQuotaNotification(entry, data);
233
+ });
234
+ }
235
+ /** Delivers one invalidation through the first registration this setup owns. */
236
+ function emitInvalidation(entry, event) {
237
+ const member = entry.members.find((candidate) => candidate.alive);
238
+ if (member === undefined)
239
+ return;
240
+ const data = { topic: event.topic, at: event.at };
241
+ if (event.scope !== undefined)
242
+ data.scope = event.scope;
243
+ // Events are live-only; a disconnected client re-subscribes and refetches.
244
+ // A disposed SDK emitter still publishes, so this does not branch on failure.
245
+ void member.registration.events.emit("invalidated", data).catch(() => undefined);
246
+ }
247
+ /**
248
+ * Delivers one safe quota notification on its own event. One emission is enough:
249
+ * the host event bus fans it out to every app window, each with the same id.
250
+ */
251
+ function emitQuotaNotification(entry, data) {
252
+ const member = entry.members.find((candidate) => candidate.alive);
253
+ if (member === undefined)
254
+ return;
255
+ void member.registration.events.emit("quotaNotification", data).catch(() => undefined);
256
+ }
257
+ /** Releases one setup's held viewers and, on the last member, the subscription. */
258
+ function leaveSharedEntry(snapshots, key, entry, member) {
259
+ if (!member.alive)
260
+ return;
261
+ member.alive = false;
262
+ const index = entry.members.indexOf(member);
263
+ if (index >= 0)
264
+ entry.members.splice(index, 1);
265
+ for (const stop of Array.from(member.heldWatches))
266
+ stop();
267
+ member.heldWatches.clear();
268
+ if (entry.members.length > 0)
269
+ return;
270
+ entry.unsubscribe();
271
+ entry.unsubscribeNotifications?.();
272
+ entry.unsubscribeNotifications = undefined;
273
+ const byKey = sharedRegistry().get(snapshots);
274
+ if (byKey?.get(key) === entry)
275
+ byKey.delete(key);
276
+ }
277
+ /**
278
+ * Registers one setup's dashboard contract in that setup's SDK scope and joins
279
+ * the shared snapshot subscription for its location. Duplicate setups with the
280
+ * same host runtime and location still produce one invalidation per snapshot
281
+ * change, but each owns its registration, so an SDK scope finalizer can dispose
282
+ * one setup without affecting the others. The returned lease releases its own
283
+ * viewers and registration; the final lease releases the shared subscription.
284
+ */
285
+ export async function registerDashboardRpc(rpc, runtime, options = {}) {
286
+ const logger = options.logger ?? createGuiLogger();
287
+ const key = locationKey(options.location);
288
+ const heldWatches = new Set();
289
+ const registration = await rpc.register(DashboardRpc, createHandlers(runtime, heldWatches, options.onWatchSnapshot));
290
+ const member = { registration, heldWatches, alive: true };
291
+ const entry = joinSharedEntry(runtime.snapshots, key, member, runtime.quotaNotifications);
292
+ let disposed = false;
293
+ return {
294
+ events: registration.events,
295
+ dispose: async () => {
296
+ if (disposed)
297
+ return;
298
+ disposed = true;
299
+ leaveSharedEntry(runtime.snapshots, key, entry, member);
300
+ try {
301
+ await registration.dispose();
302
+ }
303
+ catch (error) {
304
+ logger.warn("dashboard RPC registration dispose failed", "failed");
305
+ throw error;
306
+ }
307
+ },
308
+ };
309
+ }
310
+ //# sourceMappingURL=rpc.js.map
@@ -4,30 +4,30 @@
4
4
  * Loopback-only (`127.0.0.1`), Host/Origin/Sec-Fetch-Site hardening, no CORS,
5
5
  * JSON writes behind a streamed 64 KiB cap, static assets contained to
6
6
  * `dist/ui` under the packaged extension allowlist, SSE on `/api/v1/events`,
7
- * and one scrubbed log line per failure. `createDashboardServer` is the
8
- * injectable seam: tests pass in-memory sources/stores and `port: 0`, while the
9
- * production lifecycle factory wires the P3 source and P2 settings store and
10
- * the default `4144` port.
7
+ * and one scrubbed log line per failure. `createDashboardServer` is the web
8
+ * transport only: it receives the host-scoped `SnapshotService` and settings
9
+ * store from the lifecycle/runtime and never constructs or closes them. Tests
10
+ * pass in-memory dependencies and `port: 0`; production wires the P3 source,
11
+ * one per-host snapshot service and the P2 settings store on the default
12
+ * `4144` port.
11
13
  */
12
14
  import { type GuiSettingsStore } from "../contracts/dashboard.js";
15
+ import { DASHBOARD_ERROR_STATUS, type DashboardErrorCode, type DashboardErrorDetails, DashboardHttpError } from "./dashboard-errors.js";
13
16
  import { type GuiLogger } from "./log.js";
14
- import { type SnapshotSource } from "./snapshot-service.js";
17
+ import type { SnapshotService } from "./snapshot-service.js";
18
+ export { DASHBOARD_ERROR_STATUS, DashboardHttpError, type DashboardErrorCode, type DashboardErrorDetails, };
15
19
  export interface DashboardServerOptions {
16
20
  /** `0` binds an ephemeral port (tests); production passes the configured port. */
17
21
  port: number;
18
- source: SnapshotSource;
22
+ /**
23
+ * The host-scoped shared snapshot service. The lifecycle/runtime owns its
24
+ * cache, pollers and final close; the HTTP transport only attaches viewers
25
+ * and reads it.
26
+ */
27
+ snapshots: SnapshotService;
19
28
  settings: GuiSettingsStore;
20
29
  /** Static root; defaults to `<package>/dist/ui` derived from this module. */
21
30
  assetRoot?: string;
22
- /**
23
- * Existing quota poll interval (positive config value, no new floor) or a
24
- * getter re-read on settings changes. Analytics has its own interval below.
25
- */
26
- minIntervalMs?: number | (() => number);
27
- /** Explicit quota interval; wins over `minIntervalMs`. */
28
- quotaIntervalMs?: number | (() => number);
29
- /** Analytics poll interval; defaults to 600000ms. */
30
- analyticsIntervalMs?: number | (() => number);
31
31
  /** SSE heartbeat override (test seam; default 20 s). */
32
32
  heartbeatMs?: number;
33
33
  logger?: GuiLogger;
@@ -37,18 +37,6 @@ export interface DashboardServerHandle {
37
37
  url: string;
38
38
  close(): Promise<void>;
39
39
  }
40
- export type DashboardErrorCode = "bad-request" | "bad-host" | "bad-origin" | "unsupported-media-type" | "body-too-large" | "method-not-allowed" | "not-found" | "config-read-error" | "config-changed" | "config-target-error" | "config-write-error" | "unknown-setting" | "invalid-setting" | "project-not-found" | "session-not-found" | "internal";
41
- export interface DashboardErrorDetails {
42
- reason?: string;
43
- key?: string;
44
- }
45
- /** Status mapping from spec §5.3. */
46
- export declare const DASHBOARD_ERROR_STATUS: Readonly<Record<DashboardErrorCode, number>>;
47
- /** A controlled condition the source or a store wants surfaced verbatim-ish. */
48
- export declare class DashboardHttpError extends Error {
49
- readonly code: DashboardErrorCode;
50
- constructor(code: DashboardErrorCode);
51
- }
52
40
  /** Structured bind failure: terminal, no alternate port is ever attempted. */
53
41
  export declare class DashboardBindError extends Error {
54
42
  readonly code = "unavailable";
@@ -4,10 +4,12 @@
4
4
  * Loopback-only (`127.0.0.1`), Host/Origin/Sec-Fetch-Site hardening, no CORS,
5
5
  * JSON writes behind a streamed 64 KiB cap, static assets contained to
6
6
  * `dist/ui` under the packaged extension allowlist, SSE on `/api/v1/events`,
7
- * and one scrubbed log line per failure. `createDashboardServer` is the
8
- * injectable seam: tests pass in-memory sources/stores and `port: 0`, while the
9
- * production lifecycle factory wires the P3 source and P2 settings store and
10
- * the default `4144` port.
7
+ * and one scrubbed log line per failure. `createDashboardServer` is the web
8
+ * transport only: it receives the host-scoped `SnapshotService` and settings
9
+ * store from the lifecycle/runtime and never constructs or closes them. Tests
10
+ * pass in-memory dependencies and `port: 0`; production wires the P3 source,
11
+ * one per-host snapshot service and the P2 settings store on the default
12
+ * `4144` port.
11
13
  */
12
14
  import { readFile, realpath, stat } from "node:fs/promises";
13
15
  import { createServer } from "node:http";
@@ -18,55 +20,10 @@ import { BUILD_IDENTITY } from "../contracts/build-identity.js";
18
20
  import { DASHBOARD_CONTRACT_VERSION, } from "../contracts/dashboard.js";
19
21
  import { DEFAULT_RANGE_KEY, isRangeKey } from "../contracts/ranges.js";
20
22
  import { GuiSettingsError } from "./config.js";
23
+ import { DASHBOARD_ERROR_MESSAGES, DASHBOARD_ERROR_STATUS, DashboardHttpError, sanitizeDashboardErrorDetails, structuralDashboardSourceCode, } from "./dashboard-errors.js";
21
24
  import { createGuiLogger } from "./log.js";
22
- import { createSnapshotService } from "./snapshot-service.js";
23
25
  import { createSseHub } from "./sse.js";
24
- /** Status mapping from spec §5.3. */
25
- export const DASHBOARD_ERROR_STATUS = {
26
- "bad-request": 400,
27
- "bad-host": 403,
28
- "bad-origin": 403,
29
- "unsupported-media-type": 415,
30
- "body-too-large": 413,
31
- "method-not-allowed": 405,
32
- "not-found": 404,
33
- "config-read-error": 409,
34
- "config-changed": 409,
35
- "config-target-error": 409,
36
- "config-write-error": 500,
37
- "unknown-setting": 422,
38
- "invalid-setting": 422,
39
- "project-not-found": 404,
40
- "session-not-found": 404,
41
- internal: 500,
42
- };
43
- const DASHBOARD_ERROR_MESSAGES = {
44
- "bad-request": "Malformed request",
45
- "bad-host": "Requests must target the dashboard loopback address",
46
- "bad-origin": "Writes must originate from the dashboard page",
47
- "unsupported-media-type": "Writes require application/json",
48
- "body-too-large": "Request body exceeds the 64 KiB limit",
49
- "method-not-allowed": "Method not allowed",
50
- "not-found": "Not found",
51
- "config-read-error": "The dashboard config file is not valid JSONC",
52
- "config-changed": "Config changed since the last revision",
53
- "config-target-error": "The dashboard config path is not writable",
54
- "config-write-error": "Config write failed",
55
- "unknown-setting": "Unknown setting",
56
- "invalid-setting": "Invalid setting",
57
- "project-not-found": "Project not found",
58
- "session-not-found": "Session not found",
59
- internal: "Internal dashboard error",
60
- };
61
- /** A controlled condition the source or a store wants surfaced verbatim-ish. */
62
- export class DashboardHttpError extends Error {
63
- code;
64
- constructor(code) {
65
- super(DASHBOARD_ERROR_MESSAGES[code]);
66
- this.name = "DashboardHttpError";
67
- this.code = code;
68
- }
69
- }
26
+ export { DASHBOARD_ERROR_STATUS, DashboardHttpError, };
70
27
  /** Structured bind failure: terminal, no alternate port is ever attempted. */
71
28
  export class DashboardBindError extends Error {
72
29
  code = "unavailable";
@@ -90,23 +47,6 @@ const ASSET_CONTENT_TYPES = new Map([
90
47
  [".woff2", "font/woff2"],
91
48
  [".ttf", "font/ttf"],
92
49
  ]);
93
- const SOURCE_ERROR_CODES = new Set([
94
- "bad-request",
95
- "project-not-found",
96
- "session-not-found",
97
- ]);
98
- /** The set above is the vocabulary; trust it as the membership proof. */
99
- function isSourceErrorCode(value) {
100
- return SOURCE_ERROR_CODES.has(value);
101
- }
102
- const TARGET_REASONS = new Set([
103
- "dangling",
104
- "loop",
105
- "depth",
106
- "non-regular",
107
- "permission",
108
- ]);
109
- const SETTING_KEY_RE = /^[A-Za-z][A-Za-z0-9]*(\.[A-Za-z][A-Za-z0-9]*)*$/;
110
50
  const MAX_RESOURCE_ID_LENGTH = 256;
111
51
  function envelope(code, details) {
112
52
  const error = {
@@ -121,30 +61,6 @@ function envelope(code, details) {
121
61
  body: { error },
122
62
  };
123
63
  }
124
- function sanitizedDetails(code, input) {
125
- if (!input)
126
- return undefined;
127
- const details = {};
128
- // `details.reason` is forwarded for `config-target-error` only, and only from
129
- // the allowlisted target-reason vocabulary; other codes never carry it.
130
- if (code === "config-target-error" &&
131
- input.reason !== undefined &&
132
- TARGET_REASONS.has(input.reason)) {
133
- details.reason = input.reason;
134
- }
135
- if (input.key !== undefined && input.key.length <= 64 && SETTING_KEY_RE.test(input.key)) {
136
- details.key = input.key;
137
- }
138
- return Object.keys(details).length > 0 ? details : undefined;
139
- }
140
- function structuralSourceCode(error) {
141
- if (error === null || typeof error !== "object" || !("code" in error))
142
- return undefined;
143
- const code = error.code;
144
- if (typeof code !== "string" || !isSourceErrorCode(code))
145
- return undefined;
146
- return code;
147
- }
148
64
  /**
149
65
  * Raw exceptions never reach the wire: known controlled errors keep their code,
150
66
  * everything else is a generic 500. GuiSettingsError messages are not
@@ -152,12 +68,12 @@ function structuralSourceCode(error) {
152
68
  */
153
69
  function mapError(error) {
154
70
  if (error instanceof GuiSettingsError) {
155
- return envelope(error.code, sanitizedDetails(error.code, error.details));
71
+ return envelope(error.code, sanitizeDashboardErrorDetails(error.code, error.details));
156
72
  }
157
73
  if (error instanceof DashboardHttpError) {
158
74
  return envelope(error.code, undefined);
159
75
  }
160
- const sourceCode = structuralSourceCode(error);
76
+ const sourceCode = structuralDashboardSourceCode(error);
161
77
  if (sourceCode)
162
78
  return envelope(sourceCode, undefined);
163
79
  return envelope("internal", undefined);
@@ -355,13 +271,7 @@ function isErrnoCode(error) {
355
271
  const DEFAULT_ASSET_ROOT = fileURLToPath(new URL("../../dist/ui/", import.meta.url));
356
272
  export function createDashboardServer(options) {
357
273
  const logger = options.logger ?? createGuiLogger();
358
- const snapshots = createSnapshotService({
359
- source: options.source,
360
- minIntervalMs: options.minIntervalMs,
361
- quotaIntervalMs: options.quotaIntervalMs,
362
- analyticsIntervalMs: options.analyticsIntervalMs,
363
- logger,
364
- });
274
+ const snapshots = options.snapshots;
365
275
  let releaseViewer;
366
276
  const sse = createSseHub({
367
277
  heartbeatMs: options.heartbeatMs,
@@ -516,11 +426,20 @@ export function createDashboardServer(options) {
516
426
  return;
517
427
  }
518
428
  if (rest.length === 1 && rest[0] === "quota") {
519
- if (!requireMethods(req, res, ["GET", "HEAD"]))
429
+ if (!requireMethods(req, res, ["GET", "HEAD", "POST"]))
520
430
  return;
431
+ if (method === "POST") {
432
+ const parsed = await readWriteJson(req, res);
433
+ if (!parsed.ok)
434
+ return;
435
+ if (!isRecord(parsed.value) || !hasExactKeys(parsed.value, [])) {
436
+ sendError(res, "bad-request");
437
+ return;
438
+ }
439
+ }
521
440
  // Inference only; an explicit PUT /api/v1/view signal wins.
522
441
  snapshots.setViewScope("quota", "request");
523
- sendJson(res, 200, await snapshots.quota());
442
+ sendJson(res, 200, await snapshots.quota(req.method === "POST" ? { refresh: true } : undefined));
524
443
  return;
525
444
  }
526
445
  if (rest.length === 1 && rest[0] === "home") {
@@ -786,38 +705,30 @@ export function createDashboardServer(options) {
786
705
  });
787
706
  let actualPort = options.port;
788
707
  let closing;
789
- let released;
708
+ let released = false;
790
709
  /**
791
- * Stops snapshot work and closes the optional source. Used by both the final
792
- * server close and a terminal bind failure, so a worker/DB resource created
793
- * by the source is never leaked. Idempotent and never rejects.
710
+ * Detaches this transport: stop broadcasting to the shared service and end
711
+ * SSE clients (releasing the viewer). The snapshot service and source are
712
+ * caller-owned and are released by the lifecycle when the last lease disposes,
713
+ * including after a terminal bind failure. Idempotent and never rejects.
794
714
  */
795
715
  function releaseResources() {
796
716
  if (released)
797
- return released;
717
+ return;
718
+ released = true;
798
719
  try {
799
- snapshots.close();
800
720
  unsubscribe();
801
721
  sse.close();
802
722
  }
803
723
  catch (error) {
804
724
  logger.warn("dashboard release failed", isErrnoCode(error) ? error.code : "failed");
805
725
  }
806
- const closeSource = options.source.close;
807
- released = closeSource
808
- ? Promise.resolve()
809
- .then(() => closeSource())
810
- .catch((error) => {
811
- logger.warn("dashboard source close failed", isErrnoCode(error) ? error.code : "failed");
812
- })
813
- : Promise.resolve();
814
- return released;
815
726
  }
816
727
  function close() {
817
728
  if (closing)
818
729
  return closing;
819
730
  closing = (async () => {
820
- const resources = releaseResources();
731
+ releaseResources();
821
732
  const killTimer = setTimeout(() => {
822
733
  server.closeAllConnections();
823
734
  }, 1000);
@@ -827,22 +738,22 @@ export function createDashboardServer(options) {
827
738
  server.closeIdleConnections();
828
739
  });
829
740
  clearTimeout(killTimer);
830
- await resources;
831
741
  })();
832
742
  return closing;
833
743
  }
834
744
  return new Promise((resolve, reject) => {
835
745
  const failBind = (reason) => {
836
746
  logger.error("dashboard server unavailable", reason ?? "unknown");
837
- // Terminal: no alternate port is attempted, and source resources created
838
- // before the bind are released even though no handle was returned.
747
+ // Terminal: no alternate port is attempted. This transport detaches its
748
+ // SSE subscriber; the lifecycle keeps the shared snapshot service and
749
+ // sources alive for its remaining leases.
839
750
  try {
840
751
  server.close();
841
752
  }
842
753
  catch {
843
754
  // The listener never started (bind error) or was already closed.
844
755
  }
845
- void releaseResources();
756
+ releaseResources();
846
757
  reject(new DashboardBindError(options.port, reason));
847
758
  };
848
759
  const onListenError = (error) => {