opencode-quota-gui 0.0.0-stage → 1.0.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 (857) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +243 -2
  3. package/dist/bin/opencode-quota-gui.d.ts +4 -0
  4. package/dist/bin/opencode-quota-gui.d.ts.map +1 -0
  5. package/dist/bin/opencode-quota-gui.js +75 -0
  6. package/dist/bin/opencode-quota-gui.js.map +1 -0
  7. package/dist/contracts/build-identity.d.ts +8 -0
  8. package/dist/contracts/build-identity.d.ts.map +1 -0
  9. package/dist/contracts/build-identity.js +1 -0
  10. package/dist/contracts/card-order.d.ts +25 -0
  11. package/dist/contracts/card-order.d.ts.map +1 -0
  12. package/dist/contracts/card-order.js +50 -0
  13. package/dist/contracts/card-order.js.map +1 -0
  14. package/dist/contracts/dashboard.d.ts +368 -0
  15. package/dist/contracts/dashboard.d.ts.map +1 -0
  16. package/dist/contracts/dashboard.js +3 -0
  17. package/dist/contracts/dashboard.js.map +1 -0
  18. package/dist/contracts/guards.d.ts +14 -0
  19. package/dist/contracts/guards.d.ts.map +1 -0
  20. package/dist/contracts/guards.js +56 -0
  21. package/dist/contracts/guards.js.map +1 -0
  22. package/dist/contracts/identity.d.ts +41 -0
  23. package/dist/contracts/identity.d.ts.map +1 -0
  24. package/dist/contracts/identity.js +27 -0
  25. package/dist/contracts/identity.js.map +1 -0
  26. package/dist/contracts/openai-quota.d.ts +34 -0
  27. package/dist/contracts/openai-quota.d.ts.map +1 -0
  28. package/dist/contracts/openai-quota.js +19 -0
  29. package/dist/contracts/openai-quota.js.map +1 -0
  30. package/dist/contracts/ranges.d.ts +48 -0
  31. package/dist/contracts/ranges.d.ts.map +1 -0
  32. package/dist/contracts/ranges.js +84 -0
  33. package/dist/contracts/ranges.js.map +1 -0
  34. package/dist/contracts/settings.d.ts +4 -0
  35. package/dist/contracts/settings.d.ts.map +1 -0
  36. package/dist/contracts/settings.js +14 -0
  37. package/dist/contracts/settings.js.map +1 -0
  38. package/dist/contracts/time-zone.d.ts +33 -0
  39. package/dist/contracts/time-zone.d.ts.map +1 -0
  40. package/dist/contracts/time-zone.js +217 -0
  41. package/dist/contracts/time-zone.js.map +1 -0
  42. package/dist/data/modelsdev-pricing.min.json +1064 -0
  43. package/dist/gui/aggregation.d.ts +55 -0
  44. package/dist/gui/aggregation.d.ts.map +1 -0
  45. package/dist/gui/aggregation.js +792 -0
  46. package/dist/gui/aggregation.js.map +1 -0
  47. package/dist/gui/analytics-bridge.d.ts +50 -0
  48. package/dist/gui/analytics-bridge.d.ts.map +1 -0
  49. package/dist/gui/analytics-bridge.js +382 -0
  50. package/dist/gui/analytics-bridge.js.map +1 -0
  51. package/dist/gui/analytics-engine.d.ts +61 -0
  52. package/dist/gui/analytics-engine.d.ts.map +1 -0
  53. package/dist/gui/analytics-engine.js +2381 -0
  54. package/dist/gui/analytics-engine.js.map +1 -0
  55. package/dist/gui/analytics-indexes.d.ts +34 -0
  56. package/dist/gui/analytics-indexes.d.ts.map +1 -0
  57. package/dist/gui/analytics-indexes.js +142 -0
  58. package/dist/gui/analytics-indexes.js.map +1 -0
  59. package/dist/gui/analytics-model.d.ts +48 -0
  60. package/dist/gui/analytics-model.d.ts.map +1 -0
  61. package/dist/gui/analytics-model.js +824 -0
  62. package/dist/gui/analytics-model.js.map +1 -0
  63. package/dist/gui/analytics-protocol.d.ts +102 -0
  64. package/dist/gui/analytics-protocol.d.ts.map +1 -0
  65. package/dist/gui/analytics-protocol.js +11 -0
  66. package/dist/gui/analytics-protocol.js.map +1 -0
  67. package/dist/gui/analytics-reader.d.ts +14 -0
  68. package/dist/gui/analytics-reader.d.ts.map +1 -0
  69. package/dist/gui/analytics-reader.js +15 -0
  70. package/dist/gui/analytics-reader.js.map +1 -0
  71. package/dist/gui/analytics-service.d.ts +49 -0
  72. package/dist/gui/analytics-service.d.ts.map +1 -0
  73. package/dist/gui/analytics-service.js +187 -0
  74. package/dist/gui/analytics-service.js.map +1 -0
  75. package/dist/gui/analytics-state.d.ts +183 -0
  76. package/dist/gui/analytics-state.d.ts.map +1 -0
  77. package/dist/gui/analytics-state.js +692 -0
  78. package/dist/gui/analytics-state.js.map +1 -0
  79. package/dist/gui/analytics-worker-runtime.d.ts +11 -0
  80. package/dist/gui/analytics-worker-runtime.d.ts.map +1 -0
  81. package/dist/gui/analytics-worker-runtime.js +98 -0
  82. package/dist/gui/analytics-worker-runtime.js.map +1 -0
  83. package/dist/gui/analytics-worker.d.ts +2 -0
  84. package/dist/gui/analytics-worker.d.ts.map +1 -0
  85. package/dist/gui/analytics-worker.js +64 -0
  86. package/dist/gui/analytics-worker.js.map +1 -0
  87. package/dist/gui/config.d.ts +56 -0
  88. package/dist/gui/config.d.ts.map +1 -0
  89. package/dist/gui/config.js +701 -0
  90. package/dist/gui/config.js.map +1 -0
  91. package/dist/gui/identity.d.ts +23 -0
  92. package/dist/gui/identity.d.ts.map +1 -0
  93. package/dist/gui/identity.js +57 -0
  94. package/dist/gui/identity.js.map +1 -0
  95. package/dist/gui/lifecycle.d.ts +82 -0
  96. package/dist/gui/lifecycle.d.ts.map +1 -0
  97. package/dist/gui/lifecycle.js +402 -0
  98. package/dist/gui/lifecycle.js.map +1 -0
  99. package/dist/gui/log.d.ts +23 -0
  100. package/dist/gui/log.d.ts.map +1 -0
  101. package/dist/gui/log.js +37 -0
  102. package/dist/gui/log.js.map +1 -0
  103. package/dist/gui/provider-cards.d.ts +55 -0
  104. package/dist/gui/provider-cards.d.ts.map +1 -0
  105. package/dist/gui/provider-cards.js +417 -0
  106. package/dist/gui/provider-cards.js.map +1 -0
  107. package/dist/gui/server.d.ts +60 -0
  108. package/dist/gui/server.d.ts.map +1 -0
  109. package/dist/gui/server.js +815 -0
  110. package/dist/gui/server.js.map +1 -0
  111. package/dist/gui/settings-file-opener.d.ts +34 -0
  112. package/dist/gui/settings-file-opener.d.ts.map +1 -0
  113. package/dist/gui/settings-file-opener.js +110 -0
  114. package/dist/gui/settings-file-opener.js.map +1 -0
  115. package/dist/gui/snapshot-service.d.ts +128 -0
  116. package/dist/gui/snapshot-service.d.ts.map +1 -0
  117. package/dist/gui/snapshot-service.js +591 -0
  118. package/dist/gui/snapshot-service.js.map +1 -0
  119. package/dist/gui/sources.d.ts +99 -0
  120. package/dist/gui/sources.d.ts.map +1 -0
  121. package/dist/gui/sources.js +410 -0
  122. package/dist/gui/sources.js.map +1 -0
  123. package/dist/gui/sse.d.ts +32 -0
  124. package/dist/gui/sse.d.ts.map +1 -0
  125. package/dist/gui/sse.js +100 -0
  126. package/dist/gui/sse.js.map +1 -0
  127. package/dist/gui/time-zone.d.ts +10 -0
  128. package/dist/gui/time-zone.d.ts.map +1 -0
  129. package/dist/gui/time-zone.js +21 -0
  130. package/dist/gui/time-zone.js.map +1 -0
  131. package/dist/index.d.ts +13 -0
  132. package/dist/index.d.ts.map +1 -0
  133. package/dist/index.js +12 -0
  134. package/dist/index.js.map +1 -0
  135. package/dist/lib/accounting-format.d.ts +54 -0
  136. package/dist/lib/accounting-format.d.ts.map +1 -0
  137. package/dist/lib/accounting-format.js +271 -0
  138. package/dist/lib/accounting-format.js.map +1 -0
  139. package/dist/lib/alibaba-auth.d.ts +46 -0
  140. package/dist/lib/alibaba-auth.d.ts.map +1 -0
  141. package/dist/lib/alibaba-auth.js +193 -0
  142. package/dist/lib/alibaba-auth.js.map +1 -0
  143. package/dist/lib/alibaba-coding-plan-local-quota.d.ts +47 -0
  144. package/dist/lib/alibaba-coding-plan-local-quota.d.ts.map +1 -0
  145. package/dist/lib/alibaba-coding-plan-local-quota.js +146 -0
  146. package/dist/lib/alibaba-coding-plan-local-quota.js.map +1 -0
  147. package/dist/lib/alibaba-token-plan.d.ts +91 -0
  148. package/dist/lib/alibaba-token-plan.d.ts.map +1 -0
  149. package/dist/lib/alibaba-token-plan.js +527 -0
  150. package/dist/lib/alibaba-token-plan.js.map +1 -0
  151. package/dist/lib/anthropic-auth.d.ts +29 -0
  152. package/dist/lib/anthropic-auth.d.ts.map +1 -0
  153. package/dist/lib/anthropic-auth.js +37 -0
  154. package/dist/lib/anthropic-auth.js.map +1 -0
  155. package/dist/lib/anthropic.d.ts +104 -0
  156. package/dist/lib/anthropic.d.ts.map +1 -0
  157. package/dist/lib/anthropic.js +1134 -0
  158. package/dist/lib/anthropic.js.map +1 -0
  159. package/dist/lib/api-key-resolver.d.ts +227 -0
  160. package/dist/lib/api-key-resolver.d.ts.map +1 -0
  161. package/dist/lib/api-key-resolver.js +336 -0
  162. package/dist/lib/api-key-resolver.js.map +1 -0
  163. package/dist/lib/atomic-json.d.ts +11 -0
  164. package/dist/lib/atomic-json.d.ts.map +1 -0
  165. package/dist/lib/atomic-json.js +64 -0
  166. package/dist/lib/atomic-json.js.map +1 -0
  167. package/dist/lib/chutes-config.d.ts +15 -0
  168. package/dist/lib/chutes-config.d.ts.map +1 -0
  169. package/dist/lib/chutes-config.js +28 -0
  170. package/dist/lib/chutes-config.js.map +1 -0
  171. package/dist/lib/chutes.d.ts +12 -0
  172. package/dist/lib/chutes.d.ts.map +1 -0
  173. package/dist/lib/chutes.js +60 -0
  174. package/dist/lib/chutes.js.map +1 -0
  175. package/dist/lib/cli-reports.d.ts +30 -0
  176. package/dist/lib/cli-reports.d.ts.map +1 -0
  177. package/dist/lib/cli-reports.js +172 -0
  178. package/dist/lib/cli-reports.js.map +1 -0
  179. package/dist/lib/cli-show.d.ts +30 -0
  180. package/dist/lib/cli-show.d.ts.map +1 -0
  181. package/dist/lib/cli-show.js +213 -0
  182. package/dist/lib/cli-show.js.map +1 -0
  183. package/dist/lib/cli-status.d.ts +8 -0
  184. package/dist/lib/cli-status.d.ts.map +1 -0
  185. package/dist/lib/cli-status.js +98 -0
  186. package/dist/lib/cli-status.js.map +1 -0
  187. package/dist/lib/command-parsing.d.ts +43 -0
  188. package/dist/lib/command-parsing.d.ts.map +1 -0
  189. package/dist/lib/command-parsing.js +103 -0
  190. package/dist/lib/command-parsing.js.map +1 -0
  191. package/dist/lib/config-file-utils.d.ts +46 -0
  192. package/dist/lib/config-file-utils.d.ts.map +1 -0
  193. package/dist/lib/config-file-utils.js +194 -0
  194. package/dist/lib/config-file-utils.js.map +1 -0
  195. package/dist/lib/config-write-target.d.ts +28 -0
  196. package/dist/lib/config-write-target.d.ts.map +1 -0
  197. package/dist/lib/config-write-target.js +159 -0
  198. package/dist/lib/config-write-target.js.map +1 -0
  199. package/dist/lib/config.d.ts +119 -0
  200. package/dist/lib/config.d.ts.map +1 -0
  201. package/dist/lib/config.js +1352 -0
  202. package/dist/lib/config.js.map +1 -0
  203. package/dist/lib/copilot.d.ts +78 -0
  204. package/dist/lib/copilot.d.ts.map +1 -0
  205. package/dist/lib/copilot.js +1111 -0
  206. package/dist/lib/copilot.js.map +1 -0
  207. package/dist/lib/cursor-detection.d.ts +18 -0
  208. package/dist/lib/cursor-detection.d.ts.map +1 -0
  209. package/dist/lib/cursor-detection.js +189 -0
  210. package/dist/lib/cursor-detection.js.map +1 -0
  211. package/dist/lib/cursor-pricing.d.ts +34 -0
  212. package/dist/lib/cursor-pricing.d.ts.map +1 -0
  213. package/dist/lib/cursor-pricing.js +235 -0
  214. package/dist/lib/cursor-pricing.js.map +1 -0
  215. package/dist/lib/cursor-usage.d.ts +33 -0
  216. package/dist/lib/cursor-usage.d.ts.map +1 -0
  217. package/dist/lib/cursor-usage.js +109 -0
  218. package/dist/lib/cursor-usage.js.map +1 -0
  219. package/dist/lib/dashboard-visibility.d.ts +13 -0
  220. package/dist/lib/dashboard-visibility.d.ts.map +1 -0
  221. package/dist/lib/dashboard-visibility.js +51 -0
  222. package/dist/lib/dashboard-visibility.js.map +1 -0
  223. package/dist/lib/deepseek-auth.d.ts +15 -0
  224. package/dist/lib/deepseek-auth.d.ts.map +1 -0
  225. package/dist/lib/deepseek-auth.js +28 -0
  226. package/dist/lib/deepseek-auth.js.map +1 -0
  227. package/dist/lib/deepseek.d.ts +40 -0
  228. package/dist/lib/deepseek.d.ts.map +1 -0
  229. package/dist/lib/deepseek.js +118 -0
  230. package/dist/lib/deepseek.js.map +1 -0
  231. package/dist/lib/display-sanitize.d.ts +20 -0
  232. package/dist/lib/display-sanitize.d.ts.map +1 -0
  233. package/dist/lib/display-sanitize.js +178 -0
  234. package/dist/lib/display-sanitize.js.map +1 -0
  235. package/dist/lib/entries.d.ts +367 -0
  236. package/dist/lib/entries.d.ts.map +1 -0
  237. package/dist/lib/entries.js +69 -0
  238. package/dist/lib/entries.js.map +1 -0
  239. package/dist/lib/env-template.d.ts +26 -0
  240. package/dist/lib/env-template.d.ts.map +1 -0
  241. package/dist/lib/env-template.js +36 -0
  242. package/dist/lib/env-template.js.map +1 -0
  243. package/dist/lib/format-utils.d.ts +89 -0
  244. package/dist/lib/format-utils.d.ts.map +1 -0
  245. package/dist/lib/format-utils.js +206 -0
  246. package/dist/lib/format-utils.js.map +1 -0
  247. package/dist/lib/format.d.ts +25 -0
  248. package/dist/lib/format.d.ts.map +1 -0
  249. package/dist/lib/format.js +300 -0
  250. package/dist/lib/format.js.map +1 -0
  251. package/dist/lib/glm-coding-plan.d.ts +19 -0
  252. package/dist/lib/glm-coding-plan.d.ts.map +1 -0
  253. package/dist/lib/glm-coding-plan.js +81 -0
  254. package/dist/lib/glm-coding-plan.js.map +1 -0
  255. package/dist/lib/google-agy-companion.d.ts +8 -0
  256. package/dist/lib/google-agy-companion.d.ts.map +1 -0
  257. package/dist/lib/google-agy-companion.js +64 -0
  258. package/dist/lib/google-agy-companion.js.map +1 -0
  259. package/dist/lib/google-agy.d.ts +48 -0
  260. package/dist/lib/google-agy.d.ts.map +1 -0
  261. package/dist/lib/google-agy.js +572 -0
  262. package/dist/lib/google-agy.js.map +1 -0
  263. package/dist/lib/google-companion-credentials.d.ts +70 -0
  264. package/dist/lib/google-companion-credentials.d.ts.map +1 -0
  265. package/dist/lib/google-companion-credentials.js +315 -0
  266. package/dist/lib/google-companion-credentials.js.map +1 -0
  267. package/dist/lib/google-gemini-cli-companion.d.ts +8 -0
  268. package/dist/lib/google-gemini-cli-companion.d.ts.map +1 -0
  269. package/dist/lib/google-gemini-cli-companion.js +64 -0
  270. package/dist/lib/google-gemini-cli-companion.js.map +1 -0
  271. package/dist/lib/google-gemini-cli.d.ts +47 -0
  272. package/dist/lib/google-gemini-cli.d.ts.map +1 -0
  273. package/dist/lib/google-gemini-cli.js +481 -0
  274. package/dist/lib/google-gemini-cli.js.map +1 -0
  275. package/dist/lib/google-token-cache.d.ts +27 -0
  276. package/dist/lib/google-token-cache.d.ts.map +1 -0
  277. package/dist/lib/google-token-cache.js +52 -0
  278. package/dist/lib/google-token-cache.js.map +1 -0
  279. package/dist/lib/grouped-entry-normalization.d.ts +12 -0
  280. package/dist/lib/grouped-entry-normalization.d.ts.map +1 -0
  281. package/dist/lib/grouped-entry-normalization.js +124 -0
  282. package/dist/lib/grouped-entry-normalization.js.map +1 -0
  283. package/dist/lib/grouped-header-format.d.ts +5 -0
  284. package/dist/lib/grouped-header-format.d.ts.map +1 -0
  285. package/dist/lib/grouped-header-format.js +16 -0
  286. package/dist/lib/grouped-header-format.js.map +1 -0
  287. package/dist/lib/gui-config-target.d.ts +12 -0
  288. package/dist/lib/gui-config-target.d.ts.map +1 -0
  289. package/dist/lib/gui-config-target.js +88 -0
  290. package/dist/lib/gui-config-target.js.map +1 -0
  291. package/dist/lib/home-dir-display.d.ts +10 -0
  292. package/dist/lib/home-dir-display.d.ts.map +1 -0
  293. package/dist/lib/home-dir-display.js +108 -0
  294. package/dist/lib/home-dir-display.js.map +1 -0
  295. package/dist/lib/http.d.ts +19 -0
  296. package/dist/lib/http.d.ts.map +1 -0
  297. package/dist/lib/http.js +47 -0
  298. package/dist/lib/http.js.map +1 -0
  299. package/dist/lib/init-installer.d.ts +146 -0
  300. package/dist/lib/init-installer.d.ts.map +1 -0
  301. package/dist/lib/init-installer.js +1056 -0
  302. package/dist/lib/init-installer.js.map +1 -0
  303. package/dist/lib/jsonc.d.ts +17 -0
  304. package/dist/lib/jsonc.d.ts.map +1 -0
  305. package/dist/lib/jsonc.js +23 -0
  306. package/dist/lib/jsonc.js.map +1 -0
  307. package/dist/lib/kilo-config.d.ts +15 -0
  308. package/dist/lib/kilo-config.d.ts.map +1 -0
  309. package/dist/lib/kilo-config.js +27 -0
  310. package/dist/lib/kilo-config.js.map +1 -0
  311. package/dist/lib/kilo.d.ts +32 -0
  312. package/dist/lib/kilo.d.ts.map +1 -0
  313. package/dist/lib/kilo.js +265 -0
  314. package/dist/lib/kilo.js.map +1 -0
  315. package/dist/lib/kimi-auth.d.ts +49 -0
  316. package/dist/lib/kimi-auth.d.ts.map +1 -0
  317. package/dist/lib/kimi-auth.js +82 -0
  318. package/dist/lib/kimi-auth.js.map +1 -0
  319. package/dist/lib/kimi-endpoints.d.ts +10 -0
  320. package/dist/lib/kimi-endpoints.d.ts.map +1 -0
  321. package/dist/lib/kimi-endpoints.js +18 -0
  322. package/dist/lib/kimi-endpoints.js.map +1 -0
  323. package/dist/lib/kimi.d.ts +26 -0
  324. package/dist/lib/kimi.d.ts.map +1 -0
  325. package/dist/lib/kimi.js +230 -0
  326. package/dist/lib/kimi.js.map +1 -0
  327. package/dist/lib/maintainer-announcements.d.ts +46 -0
  328. package/dist/lib/maintainer-announcements.d.ts.map +1 -0
  329. package/dist/lib/maintainer-announcements.js +155 -0
  330. package/dist/lib/maintainer-announcements.js.map +1 -0
  331. package/dist/lib/map-with-concurrency.d.ts +2 -0
  332. package/dist/lib/map-with-concurrency.d.ts.map +1 -0
  333. package/dist/lib/map-with-concurrency.js +17 -0
  334. package/dist/lib/map-with-concurrency.js.map +1 -0
  335. package/dist/lib/markdown-table.d.ts +51 -0
  336. package/dist/lib/markdown-table.d.ts.map +1 -0
  337. package/dist/lib/markdown-table.js +179 -0
  338. package/dist/lib/markdown-table.js.map +1 -0
  339. package/dist/lib/mimo-config.d.ts +29 -0
  340. package/dist/lib/mimo-config.d.ts.map +1 -0
  341. package/dist/lib/mimo-config.js +146 -0
  342. package/dist/lib/mimo-config.js.map +1 -0
  343. package/dist/lib/mimo.d.ts +35 -0
  344. package/dist/lib/mimo.d.ts.map +1 -0
  345. package/dist/lib/mimo.js +236 -0
  346. package/dist/lib/mimo.js.map +1 -0
  347. package/dist/lib/minimax-auth.d.ts +62 -0
  348. package/dist/lib/minimax-auth.d.ts.map +1 -0
  349. package/dist/lib/minimax-auth.js +206 -0
  350. package/dist/lib/minimax-auth.js.map +1 -0
  351. package/dist/lib/minimax-endpoints.d.ts +10 -0
  352. package/dist/lib/minimax-endpoints.d.ts.map +1 -0
  353. package/dist/lib/minimax-endpoints.js +19 -0
  354. package/dist/lib/minimax-endpoints.js.map +1 -0
  355. package/dist/lib/modelsdev-pricing.d.ts +93 -0
  356. package/dist/lib/modelsdev-pricing.d.ts.map +1 -0
  357. package/dist/lib/modelsdev-pricing.js +674 -0
  358. package/dist/lib/modelsdev-pricing.js.map +1 -0
  359. package/dist/lib/nanogpt-config.d.ts +15 -0
  360. package/dist/lib/nanogpt-config.d.ts.map +1 -0
  361. package/dist/lib/nanogpt-config.js +31 -0
  362. package/dist/lib/nanogpt-config.js.map +1 -0
  363. package/dist/lib/nanogpt.d.ts +48 -0
  364. package/dist/lib/nanogpt.d.ts.map +1 -0
  365. package/dist/lib/nanogpt.js +251 -0
  366. package/dist/lib/nanogpt.js.map +1 -0
  367. package/dist/lib/ollama-cloud-config.d.ts +15 -0
  368. package/dist/lib/ollama-cloud-config.d.ts.map +1 -0
  369. package/dist/lib/ollama-cloud-config.js +27 -0
  370. package/dist/lib/ollama-cloud-config.js.map +1 -0
  371. package/dist/lib/ollama-cloud.d.ts +14 -0
  372. package/dist/lib/ollama-cloud.d.ts.map +1 -0
  373. package/dist/lib/ollama-cloud.js +186 -0
  374. package/dist/lib/ollama-cloud.js.map +1 -0
  375. package/dist/lib/openai.d.ts +68 -0
  376. package/dist/lib/openai.d.ts.map +1 -0
  377. package/dist/lib/openai.js +394 -0
  378. package/dist/lib/openai.js.map +1 -0
  379. package/dist/lib/opencode-auth-sqlite.d.ts +17 -0
  380. package/dist/lib/opencode-auth-sqlite.d.ts.map +1 -0
  381. package/dist/lib/opencode-auth-sqlite.js +105 -0
  382. package/dist/lib/opencode-auth-sqlite.js.map +1 -0
  383. package/dist/lib/opencode-auth.d.ts +146 -0
  384. package/dist/lib/opencode-auth.d.ts.map +1 -0
  385. package/dist/lib/opencode-auth.js +465 -0
  386. package/dist/lib/opencode-auth.js.map +1 -0
  387. package/dist/lib/opencode-config-editor.d.ts +62 -0
  388. package/dist/lib/opencode-config-editor.d.ts.map +1 -0
  389. package/dist/lib/opencode-config-editor.js +387 -0
  390. package/dist/lib/opencode-config-editor.js.map +1 -0
  391. package/dist/lib/opencode-config-providers.d.ts +24 -0
  392. package/dist/lib/opencode-config-providers.d.ts.map +1 -0
  393. package/dist/lib/opencode-config-providers.js +144 -0
  394. package/dist/lib/opencode-config-providers.js.map +1 -0
  395. package/dist/lib/opencode-config-read.d.ts +23 -0
  396. package/dist/lib/opencode-config-read.d.ts.map +1 -0
  397. package/dist/lib/opencode-config-read.js +30 -0
  398. package/dist/lib/opencode-config-read.js.map +1 -0
  399. package/dist/lib/opencode-console-auth.d.ts +96 -0
  400. package/dist/lib/opencode-console-auth.d.ts.map +1 -0
  401. package/dist/lib/opencode-console-auth.js +213 -0
  402. package/dist/lib/opencode-console-auth.js.map +1 -0
  403. package/dist/lib/opencode-db-path.d.ts +9 -0
  404. package/dist/lib/opencode-db-path.d.ts.map +1 -0
  405. package/dist/lib/opencode-db-path.js +16 -0
  406. package/dist/lib/opencode-db-path.js.map +1 -0
  407. package/dist/lib/opencode-go-auth.d.ts +16 -0
  408. package/dist/lib/opencode-go-auth.d.ts.map +1 -0
  409. package/dist/lib/opencode-go-auth.js +42 -0
  410. package/dist/lib/opencode-go-auth.js.map +1 -0
  411. package/dist/lib/opencode-go.d.ts +17 -0
  412. package/dist/lib/opencode-go.d.ts.map +1 -0
  413. package/dist/lib/opencode-go.js +284 -0
  414. package/dist/lib/opencode-go.js.map +1 -0
  415. package/dist/lib/opencode-runtime-paths.d.ts +17 -0
  416. package/dist/lib/opencode-runtime-paths.d.ts.map +1 -0
  417. package/dist/lib/opencode-runtime-paths.js +24 -0
  418. package/dist/lib/opencode-runtime-paths.js.map +1 -0
  419. package/dist/lib/opencode-sqlite.d.ts +11 -0
  420. package/dist/lib/opencode-sqlite.d.ts.map +1 -0
  421. package/dist/lib/opencode-sqlite.js +88 -0
  422. package/dist/lib/opencode-sqlite.js.map +1 -0
  423. package/dist/lib/opencode-storage.d.ts +306 -0
  424. package/dist/lib/opencode-storage.d.ts.map +1 -0
  425. package/dist/lib/opencode-storage.js +1269 -0
  426. package/dist/lib/opencode-storage.js.map +1 -0
  427. package/dist/lib/opencode-version.d.ts +6 -0
  428. package/dist/lib/opencode-version.d.ts.map +1 -0
  429. package/dist/lib/opencode-version.js +26 -0
  430. package/dist/lib/opencode-version.js.map +1 -0
  431. package/dist/lib/opencode-zen.d.ts +55 -0
  432. package/dist/lib/opencode-zen.d.ts.map +1 -0
  433. package/dist/lib/opencode-zen.js +348 -0
  434. package/dist/lib/opencode-zen.js.map +1 -0
  435. package/dist/lib/openrouter.d.ts +60 -0
  436. package/dist/lib/openrouter.d.ts.map +1 -0
  437. package/dist/lib/openrouter.js +215 -0
  438. package/dist/lib/openrouter.js.map +1 -0
  439. package/dist/lib/private-state-paths.d.ts +10 -0
  440. package/dist/lib/private-state-paths.d.ts.map +1 -0
  441. package/dist/lib/private-state-paths.js +28 -0
  442. package/dist/lib/private-state-paths.js.map +1 -0
  443. package/dist/lib/provider-add-command.d.ts +35 -0
  444. package/dist/lib/provider-add-command.d.ts.map +1 -0
  445. package/dist/lib/provider-add-command.js +204 -0
  446. package/dist/lib/provider-add-command.js.map +1 -0
  447. package/dist/lib/provider-add-json-v1-questionnaire.d.ts +32 -0
  448. package/dist/lib/provider-add-json-v1-questionnaire.d.ts.map +1 -0
  449. package/dist/lib/provider-add-json-v1-questionnaire.js +336 -0
  450. package/dist/lib/provider-add-json-v1-questionnaire.js.map +1 -0
  451. package/dist/lib/provider-add.d.ts +21 -0
  452. package/dist/lib/provider-add.d.ts.map +1 -0
  453. package/dist/lib/provider-add.js +219 -0
  454. package/dist/lib/provider-add.js.map +1 -0
  455. package/dist/lib/provider-availability.d.ts +13 -0
  456. package/dist/lib/provider-availability.d.ts.map +1 -0
  457. package/dist/lib/provider-availability.js +20 -0
  458. package/dist/lib/provider-availability.js.map +1 -0
  459. package/dist/lib/provider-metadata.d.ts +32 -0
  460. package/dist/lib/provider-metadata.d.ts.map +1 -0
  461. package/dist/lib/provider-metadata.js +90 -0
  462. package/dist/lib/provider-metadata.js.map +1 -0
  463. package/dist/lib/provider-model-matching.d.ts +12 -0
  464. package/dist/lib/provider-model-matching.d.ts.map +1 -0
  465. package/dist/lib/provider-model-matching.js +23 -0
  466. package/dist/lib/provider-model-matching.js.map +1 -0
  467. package/dist/lib/provider-registration.d.ts +321 -0
  468. package/dist/lib/provider-registration.d.ts.map +1 -0
  469. package/dist/lib/provider-registration.js +335 -0
  470. package/dist/lib/provider-registration.js.map +1 -0
  471. package/dist/lib/quota-accounting-projection.d.ts +9 -0
  472. package/dist/lib/quota-accounting-projection.d.ts.map +1 -0
  473. package/dist/lib/quota-accounting-projection.js +254 -0
  474. package/dist/lib/quota-accounting-projection.js.map +1 -0
  475. package/dist/lib/quota-columns.d.ts +38 -0
  476. package/dist/lib/quota-columns.d.ts.map +1 -0
  477. package/dist/lib/quota-columns.js +129 -0
  478. package/dist/lib/quota-columns.js.map +1 -0
  479. package/dist/lib/quota-command-format.d.ts +34 -0
  480. package/dist/lib/quota-command-format.d.ts.map +1 -0
  481. package/dist/lib/quota-command-format.js +240 -0
  482. package/dist/lib/quota-command-format.js.map +1 -0
  483. package/dist/lib/quota-dialog-command-specs.d.ts +63 -0
  484. package/dist/lib/quota-dialog-command-specs.d.ts.map +1 -0
  485. package/dist/lib/quota-dialog-command-specs.js +145 -0
  486. package/dist/lib/quota-dialog-command-specs.js.map +1 -0
  487. package/dist/lib/quota-dialog-commands.d.ts +75 -0
  488. package/dist/lib/quota-dialog-commands.d.ts.map +1 -0
  489. package/dist/lib/quota-dialog-commands.js +586 -0
  490. package/dist/lib/quota-dialog-commands.js.map +1 -0
  491. package/dist/lib/quota-entry-display.d.ts +7 -0
  492. package/dist/lib/quota-entry-display.d.ts.map +1 -0
  493. package/dist/lib/quota-entry-display.js +59 -0
  494. package/dist/lib/quota-entry-display.js.map +1 -0
  495. package/dist/lib/quota-exhaustion-projection.d.ts +11 -0
  496. package/dist/lib/quota-exhaustion-projection.d.ts.map +1 -0
  497. package/dist/lib/quota-exhaustion-projection.js +105 -0
  498. package/dist/lib/quota-exhaustion-projection.js.map +1 -0
  499. package/dist/lib/quota-export-types.d.ts +96 -0
  500. package/dist/lib/quota-export-types.d.ts.map +1 -0
  501. package/dist/lib/quota-export-types.js +2 -0
  502. package/dist/lib/quota-export-types.js.map +1 -0
  503. package/dist/lib/quota-export.d.ts +44 -0
  504. package/dist/lib/quota-export.d.ts.map +1 -0
  505. package/dist/lib/quota-export.js +221 -0
  506. package/dist/lib/quota-export.js.map +1 -0
  507. package/dist/lib/quota-format-style.d.ts +21 -0
  508. package/dist/lib/quota-format-style.d.ts.map +1 -0
  509. package/dist/lib/quota-format-style.js +38 -0
  510. package/dist/lib/quota-format-style.js.map +1 -0
  511. package/dist/lib/quota-providers-local.d.ts +55 -0
  512. package/dist/lib/quota-providers-local.d.ts.map +1 -0
  513. package/dist/lib/quota-providers-local.js +327 -0
  514. package/dist/lib/quota-providers-local.js.map +1 -0
  515. package/dist/lib/quota-providers-remote.d.ts +27 -0
  516. package/dist/lib/quota-providers-remote.d.ts.map +1 -0
  517. package/dist/lib/quota-providers-remote.js +757 -0
  518. package/dist/lib/quota-providers-remote.js.map +1 -0
  519. package/dist/lib/quota-providers.d.ts +158 -0
  520. package/dist/lib/quota-providers.d.ts.map +1 -0
  521. package/dist/lib/quota-providers.js +1160 -0
  522. package/dist/lib/quota-providers.js.map +1 -0
  523. package/dist/lib/quota-render-data.d.ts +135 -0
  524. package/dist/lib/quota-render-data.d.ts.map +1 -0
  525. package/dist/lib/quota-render-data.js +462 -0
  526. package/dist/lib/quota-render-data.js.map +1 -0
  527. package/dist/lib/quota-report-message.d.ts +22 -0
  528. package/dist/lib/quota-report-message.d.ts.map +1 -0
  529. package/dist/lib/quota-report-message.js +36 -0
  530. package/dist/lib/quota-report-message.js.map +1 -0
  531. package/dist/lib/quota-reset-notifications.d.ts +20 -0
  532. package/dist/lib/quota-reset-notifications.d.ts.map +1 -0
  533. package/dist/lib/quota-reset-notifications.js +331 -0
  534. package/dist/lib/quota-reset-notifications.js.map +1 -0
  535. package/dist/lib/quota-retry-wait.d.ts +36 -0
  536. package/dist/lib/quota-retry-wait.d.ts.map +1 -0
  537. package/dist/lib/quota-retry-wait.js +67 -0
  538. package/dist/lib/quota-retry-wait.js.map +1 -0
  539. package/dist/lib/quota-runtime-context.d.ts +56 -0
  540. package/dist/lib/quota-runtime-context.d.ts.map +1 -0
  541. package/dist/lib/quota-runtime-context.js +113 -0
  542. package/dist/lib/quota-runtime-context.js.map +1 -0
  543. package/dist/lib/quota-state-codec.d.ts +16 -0
  544. package/dist/lib/quota-state-codec.d.ts.map +1 -0
  545. package/dist/lib/quota-state-codec.js +479 -0
  546. package/dist/lib/quota-state-codec.js.map +1 -0
  547. package/dist/lib/quota-state.d.ts +28 -0
  548. package/dist/lib/quota-state.d.ts.map +1 -0
  549. package/dist/lib/quota-state.js +473 -0
  550. package/dist/lib/quota-state.js.map +1 -0
  551. package/dist/lib/quota-stats-format.d.ts +29 -0
  552. package/dist/lib/quota-stats-format.d.ts.map +1 -0
  553. package/dist/lib/quota-stats-format.js +459 -0
  554. package/dist/lib/quota-stats-format.js.map +1 -0
  555. package/dist/lib/quota-stats.d.ts +174 -0
  556. package/dist/lib/quota-stats.d.ts.map +1 -0
  557. package/dist/lib/quota-stats.js +713 -0
  558. package/dist/lib/quota-stats.js.map +1 -0
  559. package/dist/lib/quota-status.d.ts +58 -0
  560. package/dist/lib/quota-status.d.ts.map +1 -0
  561. package/dist/lib/quota-status.js +865 -0
  562. package/dist/lib/quota-status.js.map +1 -0
  563. package/dist/lib/quota-surface-data.d.ts +21 -0
  564. package/dist/lib/quota-surface-data.d.ts.map +1 -0
  565. package/dist/lib/quota-surface-data.js +361 -0
  566. package/dist/lib/quota-surface-data.js.map +1 -0
  567. package/dist/lib/quota-telemetry.d.ts +45 -0
  568. package/dist/lib/quota-telemetry.d.ts.map +1 -0
  569. package/dist/lib/quota-telemetry.js +304 -0
  570. package/dist/lib/quota-telemetry.js.map +1 -0
  571. package/dist/lib/report-document.d.ts +90 -0
  572. package/dist/lib/report-document.d.ts.map +1 -0
  573. package/dist/lib/report-document.js +190 -0
  574. package/dist/lib/report-document.js.map +1 -0
  575. package/dist/lib/resolved-auth-identity.d.ts +36 -0
  576. package/dist/lib/resolved-auth-identity.d.ts.map +1 -0
  577. package/dist/lib/resolved-auth-identity.js +192 -0
  578. package/dist/lib/resolved-auth-identity.js.map +1 -0
  579. package/dist/lib/runtime-provider-ids.d.ts +4 -0
  580. package/dist/lib/runtime-provider-ids.d.ts.map +1 -0
  581. package/dist/lib/runtime-provider-ids.js +10 -0
  582. package/dist/lib/runtime-provider-ids.js.map +1 -0
  583. package/dist/lib/scoped-update-migration.d.ts +103 -0
  584. package/dist/lib/scoped-update-migration.d.ts.map +1 -0
  585. package/dist/lib/scoped-update-migration.js +348 -0
  586. package/dist/lib/scoped-update-migration.js.map +1 -0
  587. package/dist/lib/scoped-update.d.ts +78 -0
  588. package/dist/lib/scoped-update.d.ts.map +1 -0
  589. package/dist/lib/scoped-update.js +640 -0
  590. package/dist/lib/scoped-update.js.map +1 -0
  591. package/dist/lib/session-tokens-format.d.ts +36 -0
  592. package/dist/lib/session-tokens-format.d.ts.map +1 -0
  593. package/dist/lib/session-tokens-format.js +111 -0
  594. package/dist/lib/session-tokens-format.js.map +1 -0
  595. package/dist/lib/session-tokens.d.ts +27 -0
  596. package/dist/lib/session-tokens.d.ts.map +1 -0
  597. package/dist/lib/session-tokens.js +55 -0
  598. package/dist/lib/session-tokens.js.map +1 -0
  599. package/dist/lib/synthetic-config.d.ts +15 -0
  600. package/dist/lib/synthetic-config.d.ts.map +1 -0
  601. package/dist/lib/synthetic-config.js +28 -0
  602. package/dist/lib/synthetic-config.js.map +1 -0
  603. package/dist/lib/synthetic.d.ts +12 -0
  604. package/dist/lib/synthetic.d.ts.map +1 -0
  605. package/dist/lib/synthetic.js +173 -0
  606. package/dist/lib/synthetic.js.map +1 -0
  607. package/dist/lib/toast-format-grouped.d.ts +25 -0
  608. package/dist/lib/toast-format-grouped.d.ts.map +1 -0
  609. package/dist/lib/toast-format-grouped.js +296 -0
  610. package/dist/lib/toast-format-grouped.js.map +1 -0
  611. package/dist/lib/token-buckets.d.ts +24 -0
  612. package/dist/lib/token-buckets.d.ts.map +1 -0
  613. package/dist/lib/token-buckets.js +28 -0
  614. package/dist/lib/token-buckets.js.map +1 -0
  615. package/dist/lib/token-cost.d.ts +10 -0
  616. package/dist/lib/token-cost.d.ts.map +1 -0
  617. package/dist/lib/token-cost.js +16 -0
  618. package/dist/lib/token-cost.js.map +1 -0
  619. package/dist/lib/tui-compact-format.d.ts +10 -0
  620. package/dist/lib/tui-compact-format.d.ts.map +1 -0
  621. package/dist/lib/tui-compact-format.js +460 -0
  622. package/dist/lib/tui-compact-format.js.map +1 -0
  623. package/dist/lib/tui-panel-state.d.ts +15 -0
  624. package/dist/lib/tui-panel-state.d.ts.map +1 -0
  625. package/dist/lib/tui-panel-state.js +2 -0
  626. package/dist/lib/tui-panel-state.js.map +1 -0
  627. package/dist/lib/tui-prompt-bar-format.d.ts +25 -0
  628. package/dist/lib/tui-prompt-bar-format.d.ts.map +1 -0
  629. package/dist/lib/tui-prompt-bar-format.js +206 -0
  630. package/dist/lib/tui-prompt-bar-format.js.map +1 -0
  631. package/dist/lib/tui-sidebar-format.d.ts +13 -0
  632. package/dist/lib/tui-sidebar-format.d.ts.map +1 -0
  633. package/dist/lib/tui-sidebar-format.js +34 -0
  634. package/dist/lib/tui-sidebar-format.js.map +1 -0
  635. package/dist/lib/types.d.ts +738 -0
  636. package/dist/lib/types.d.ts.map +1 -0
  637. package/dist/lib/types.js +85 -0
  638. package/dist/lib/types.js.map +1 -0
  639. package/dist/lib/usage-ownership.d.ts +47 -0
  640. package/dist/lib/usage-ownership.d.ts.map +1 -0
  641. package/dist/lib/usage-ownership.js +98 -0
  642. package/dist/lib/usage-ownership.js.map +1 -0
  643. package/dist/lib/version.d.ts +2 -0
  644. package/dist/lib/version.d.ts.map +1 -0
  645. package/dist/lib/version.js +33 -0
  646. package/dist/lib/version.js.map +1 -0
  647. package/dist/lib/xai.d.ts +52 -0
  648. package/dist/lib/xai.d.ts.map +1 -0
  649. package/dist/lib/xai.js +253 -0
  650. package/dist/lib/xai.js.map +1 -0
  651. package/dist/lib/zai-auth.d.ts +15 -0
  652. package/dist/lib/zai-auth.d.ts.map +1 -0
  653. package/dist/lib/zai-auth.js +37 -0
  654. package/dist/lib/zai-auth.js.map +1 -0
  655. package/dist/lib/zai.d.ts +5 -0
  656. package/dist/lib/zai.d.ts.map +1 -0
  657. package/dist/lib/zai.js +14 -0
  658. package/dist/lib/zai.js.map +1 -0
  659. package/dist/lib/zhipu-auth.d.ts +15 -0
  660. package/dist/lib/zhipu-auth.d.ts.map +1 -0
  661. package/dist/lib/zhipu-auth.js +42 -0
  662. package/dist/lib/zhipu-auth.js.map +1 -0
  663. package/dist/lib/zhipu.d.ts +5 -0
  664. package/dist/lib/zhipu.d.ts.map +1 -0
  665. package/dist/lib/zhipu.js +13 -0
  666. package/dist/lib/zhipu.js.map +1 -0
  667. package/dist/plugin.d.ts +10 -0
  668. package/dist/plugin.d.ts.map +1 -0
  669. package/dist/plugin.js +95 -0
  670. package/dist/plugin.js.map +1 -0
  671. package/dist/providers/accounting-decimal.d.ts +2 -0
  672. package/dist/providers/accounting-decimal.d.ts.map +1 -0
  673. package/dist/providers/accounting-decimal.js +23 -0
  674. package/dist/providers/accounting-decimal.js.map +1 -0
  675. package/dist/providers/alibaba-coding-plan.d.ts +3 -0
  676. package/dist/providers/alibaba-coding-plan.d.ts.map +1 -0
  677. package/dist/providers/alibaba-coding-plan.js +122 -0
  678. package/dist/providers/alibaba-coding-plan.js.map +1 -0
  679. package/dist/providers/alibaba-token-plan.d.ts +3 -0
  680. package/dist/providers/alibaba-token-plan.d.ts.map +1 -0
  681. package/dist/providers/alibaba-token-plan.js +90 -0
  682. package/dist/providers/alibaba-token-plan.js.map +1 -0
  683. package/dist/providers/anthropic.d.ts +9 -0
  684. package/dist/providers/anthropic.d.ts.map +1 -0
  685. package/dist/providers/anthropic.js +236 -0
  686. package/dist/providers/anthropic.js.map +1 -0
  687. package/dist/providers/cache-policies.d.ts +67 -0
  688. package/dist/providers/cache-policies.d.ts.map +1 -0
  689. package/dist/providers/cache-policies.js +263 -0
  690. package/dist/providers/cache-policies.js.map +1 -0
  691. package/dist/providers/chutes.d.ts +6 -0
  692. package/dist/providers/chutes.d.ts.map +1 -0
  693. package/dist/providers/chutes.js +50 -0
  694. package/dist/providers/chutes.js.map +1 -0
  695. package/dist/providers/copilot.d.ts +9 -0
  696. package/dist/providers/copilot.d.ts.map +1 -0
  697. package/dist/providers/copilot.js +323 -0
  698. package/dist/providers/copilot.js.map +1 -0
  699. package/dist/providers/cursor.d.ts +3 -0
  700. package/dist/providers/cursor.d.ts.map +1 -0
  701. package/dist/providers/cursor.js +182 -0
  702. package/dist/providers/cursor.js.map +1 -0
  703. package/dist/providers/deepseek.d.ts +9 -0
  704. package/dist/providers/deepseek.d.ts.map +1 -0
  705. package/dist/providers/deepseek.js +111 -0
  706. package/dist/providers/deepseek.js.map +1 -0
  707. package/dist/providers/glm-coding-plan-provider.d.ts +56 -0
  708. package/dist/providers/glm-coding-plan-provider.d.ts.map +1 -0
  709. package/dist/providers/glm-coding-plan-provider.js +146 -0
  710. package/dist/providers/glm-coding-plan-provider.js.map +1 -0
  711. package/dist/providers/google-account-format.d.ts +7 -0
  712. package/dist/providers/google-account-format.d.ts.map +1 -0
  713. package/dist/providers/google-account-format.js +52 -0
  714. package/dist/providers/google-account-format.js.map +1 -0
  715. package/dist/providers/google-agy.d.ts +17 -0
  716. package/dist/providers/google-agy.d.ts.map +1 -0
  717. package/dist/providers/google-agy.js +256 -0
  718. package/dist/providers/google-agy.js.map +1 -0
  719. package/dist/providers/google-gemini-cli.d.ts +17 -0
  720. package/dist/providers/google-gemini-cli.d.ts.map +1 -0
  721. package/dist/providers/google-gemini-cli.js +228 -0
  722. package/dist/providers/google-gemini-cli.js.map +1 -0
  723. package/dist/providers/kilo.d.ts +6 -0
  724. package/dist/providers/kilo.d.ts.map +1 -0
  725. package/dist/providers/kilo.js +145 -0
  726. package/dist/providers/kilo.js.map +1 -0
  727. package/dist/providers/kimi-code.d.ts +4 -0
  728. package/dist/providers/kimi-code.d.ts.map +1 -0
  729. package/dist/providers/kimi-code.js +175 -0
  730. package/dist/providers/kimi-code.js.map +1 -0
  731. package/dist/providers/mimo.d.ts +3 -0
  732. package/dist/providers/mimo.d.ts.map +1 -0
  733. package/dist/providers/mimo.js +149 -0
  734. package/dist/providers/mimo.js.map +1 -0
  735. package/dist/providers/minimax-coding-plan.d.ts +26 -0
  736. package/dist/providers/minimax-coding-plan.d.ts.map +1 -0
  737. package/dist/providers/minimax-coding-plan.js +391 -0
  738. package/dist/providers/minimax-coding-plan.js.map +1 -0
  739. package/dist/providers/nanogpt.d.ts +6 -0
  740. package/dist/providers/nanogpt.d.ts.map +1 -0
  741. package/dist/providers/nanogpt.js +160 -0
  742. package/dist/providers/nanogpt.js.map +1 -0
  743. package/dist/providers/ollama-cloud.d.ts +9 -0
  744. package/dist/providers/ollama-cloud.d.ts.map +1 -0
  745. package/dist/providers/ollama-cloud.js +129 -0
  746. package/dist/providers/ollama-cloud.js.map +1 -0
  747. package/dist/providers/openai.d.ts +6 -0
  748. package/dist/providers/openai.d.ts.map +1 -0
  749. package/dist/providers/openai.js +313 -0
  750. package/dist/providers/openai.js.map +1 -0
  751. package/dist/providers/opencode-go.d.ts +4 -0
  752. package/dist/providers/opencode-go.d.ts.map +1 -0
  753. package/dist/providers/opencode-go.js +409 -0
  754. package/dist/providers/opencode-go.js.map +1 -0
  755. package/dist/providers/opencode-zen.d.ts +3 -0
  756. package/dist/providers/opencode-zen.d.ts.map +1 -0
  757. package/dist/providers/opencode-zen.js +288 -0
  758. package/dist/providers/opencode-zen.js.map +1 -0
  759. package/dist/providers/openrouter.d.ts +6 -0
  760. package/dist/providers/openrouter.d.ts.map +1 -0
  761. package/dist/providers/openrouter.js +94 -0
  762. package/dist/providers/openrouter.js.map +1 -0
  763. package/dist/providers/quota-providers.d.ts +6 -0
  764. package/dist/providers/quota-providers.d.ts.map +1 -0
  765. package/dist/providers/quota-providers.js +287 -0
  766. package/dist/providers/quota-providers.js.map +1 -0
  767. package/dist/providers/registry.d.ts +9 -0
  768. package/dist/providers/registry.d.ts.map +1 -0
  769. package/dist/providers/registry.js +71 -0
  770. package/dist/providers/registry.js.map +1 -0
  771. package/dist/providers/result-helpers.d.ts +61 -0
  772. package/dist/providers/result-helpers.d.ts.map +1 -0
  773. package/dist/providers/result-helpers.js +117 -0
  774. package/dist/providers/result-helpers.js.map +1 -0
  775. package/dist/providers/synthetic.d.ts +6 -0
  776. package/dist/providers/synthetic.d.ts.map +1 -0
  777. package/dist/providers/synthetic.js +79 -0
  778. package/dist/providers/synthetic.js.map +1 -0
  779. package/dist/providers/xai.d.ts +6 -0
  780. package/dist/providers/xai.d.ts.map +1 -0
  781. package/dist/providers/xai.js +122 -0
  782. package/dist/providers/xai.js.map +1 -0
  783. package/dist/providers/zai.d.ts +2 -0
  784. package/dist/providers/zai.d.ts.map +1 -0
  785. package/dist/providers/zai.js +24 -0
  786. package/dist/providers/zai.js.map +1 -0
  787. package/dist/providers/zhipu.d.ts +2 -0
  788. package/dist/providers/zhipu.d.ts.map +1 -0
  789. package/dist/providers/zhipu.js +21 -0
  790. package/dist/providers/zhipu.js.map +1 -0
  791. package/dist/rpc.d.ts +72 -0
  792. package/dist/rpc.d.ts.map +1 -0
  793. package/dist/rpc.js +77 -0
  794. package/dist/rpc.js.map +1 -0
  795. package/dist/ui/assets/KaTeX_AMS-Regular-BQhdFMY1.woff2 +0 -0
  796. package/dist/ui/assets/KaTeX_AMS-Regular-DMm9YOAa.woff +0 -0
  797. package/dist/ui/assets/KaTeX_AMS-Regular-DRggAlZN.ttf +0 -0
  798. package/dist/ui/assets/KaTeX_Caligraphic-Bold-ATXxdsX0.ttf +0 -0
  799. package/dist/ui/assets/KaTeX_Caligraphic-Bold-BEiXGLvX.woff +0 -0
  800. package/dist/ui/assets/KaTeX_Caligraphic-Bold-Dq_IR9rO.woff2 +0 -0
  801. package/dist/ui/assets/KaTeX_Caligraphic-Regular-CTRA-rTL.woff +0 -0
  802. package/dist/ui/assets/KaTeX_Caligraphic-Regular-Di6jR-x-.woff2 +0 -0
  803. package/dist/ui/assets/KaTeX_Caligraphic-Regular-wX97UBjC.ttf +0 -0
  804. package/dist/ui/assets/KaTeX_Fraktur-Bold-BdnERNNW.ttf +0 -0
  805. package/dist/ui/assets/KaTeX_Fraktur-Bold-BsDP51OF.woff +0 -0
  806. package/dist/ui/assets/KaTeX_Fraktur-Bold-CL6g_b3V.woff2 +0 -0
  807. package/dist/ui/assets/KaTeX_Fraktur-Regular-CB_wures.ttf +0 -0
  808. package/dist/ui/assets/KaTeX_Fraktur-Regular-CTYiF6lA.woff2 +0 -0
  809. package/dist/ui/assets/KaTeX_Fraktur-Regular-Dxdc4cR9.woff +0 -0
  810. package/dist/ui/assets/KaTeX_Main-Bold-Cx986IdX.woff2 +0 -0
  811. package/dist/ui/assets/KaTeX_Main-Bold-Jm3AIy58.woff +0 -0
  812. package/dist/ui/assets/KaTeX_Main-Bold-waoOVXN0.ttf +0 -0
  813. package/dist/ui/assets/KaTeX_Main-BoldItalic-DxDJ3AOS.woff2 +0 -0
  814. package/dist/ui/assets/KaTeX_Main-BoldItalic-DzxPMmG6.ttf +0 -0
  815. package/dist/ui/assets/KaTeX_Main-BoldItalic-SpSLRI95.woff +0 -0
  816. package/dist/ui/assets/KaTeX_Main-Italic-3WenGoN9.ttf +0 -0
  817. package/dist/ui/assets/KaTeX_Main-Italic-BMLOBm91.woff +0 -0
  818. package/dist/ui/assets/KaTeX_Main-Italic-NWA7e6Wa.woff2 +0 -0
  819. package/dist/ui/assets/KaTeX_Main-Regular-B22Nviop.woff2 +0 -0
  820. package/dist/ui/assets/KaTeX_Main-Regular-Dr94JaBh.woff +0 -0
  821. package/dist/ui/assets/KaTeX_Main-Regular-ypZvNtVU.ttf +0 -0
  822. package/dist/ui/assets/KaTeX_Math-BoldItalic-B3XSjfu4.ttf +0 -0
  823. package/dist/ui/assets/KaTeX_Math-BoldItalic-CZnvNsCZ.woff2 +0 -0
  824. package/dist/ui/assets/KaTeX_Math-BoldItalic-iY-2wyZ7.woff +0 -0
  825. package/dist/ui/assets/KaTeX_Math-Italic-DA0__PXp.woff +0 -0
  826. package/dist/ui/assets/KaTeX_Math-Italic-flOr_0UB.ttf +0 -0
  827. package/dist/ui/assets/KaTeX_Math-Italic-t53AETM-.woff2 +0 -0
  828. package/dist/ui/assets/KaTeX_SansSerif-Bold-CFMepnvq.ttf +0 -0
  829. package/dist/ui/assets/KaTeX_SansSerif-Bold-D1sUS0GD.woff2 +0 -0
  830. package/dist/ui/assets/KaTeX_SansSerif-Bold-DbIhKOiC.woff +0 -0
  831. package/dist/ui/assets/KaTeX_SansSerif-Italic-C3H0VqGB.woff2 +0 -0
  832. package/dist/ui/assets/KaTeX_SansSerif-Italic-DN2j7dab.woff +0 -0
  833. package/dist/ui/assets/KaTeX_SansSerif-Italic-YYjJ1zSn.ttf +0 -0
  834. package/dist/ui/assets/KaTeX_SansSerif-Regular-BNo7hRIc.ttf +0 -0
  835. package/dist/ui/assets/KaTeX_SansSerif-Regular-CS6fqUqJ.woff +0 -0
  836. package/dist/ui/assets/KaTeX_SansSerif-Regular-DDBCnlJ7.woff2 +0 -0
  837. package/dist/ui/assets/KaTeX_Script-Regular-C5JkGWo-.ttf +0 -0
  838. package/dist/ui/assets/KaTeX_Script-Regular-D3wIWfF6.woff2 +0 -0
  839. package/dist/ui/assets/KaTeX_Script-Regular-D5yQViql.woff +0 -0
  840. package/dist/ui/assets/KaTeX_Size1-Regular-C195tn64.woff +0 -0
  841. package/dist/ui/assets/KaTeX_Size1-Regular-Dbsnue_I.ttf +0 -0
  842. package/dist/ui/assets/KaTeX_Size1-Regular-mCD8mA8B.woff2 +0 -0
  843. package/dist/ui/assets/KaTeX_Size2-Regular-B7gKUWhC.ttf +0 -0
  844. package/dist/ui/assets/KaTeX_Size2-Regular-Dy4dx90m.woff2 +0 -0
  845. package/dist/ui/assets/KaTeX_Size2-Regular-oD1tc_U0.woff +0 -0
  846. package/dist/ui/assets/KaTeX_Size3-Regular-CTq5MqoE.woff +0 -0
  847. package/dist/ui/assets/KaTeX_Size3-Regular-DgpXs0kz.ttf +0 -0
  848. package/dist/ui/assets/KaTeX_Size4-Regular-BF-4gkZK.woff +0 -0
  849. package/dist/ui/assets/KaTeX_Size4-Regular-DWFBv043.ttf +0 -0
  850. package/dist/ui/assets/KaTeX_Size4-Regular-Dl5lxZxV.woff2 +0 -0
  851. package/dist/ui/assets/KaTeX_Typewriter-Regular-C0xS9mPB.woff +0 -0
  852. package/dist/ui/assets/KaTeX_Typewriter-Regular-CO6r4hn1.woff2 +0 -0
  853. package/dist/ui/assets/KaTeX_Typewriter-Regular-D3Ib7_Hf.ttf +0 -0
  854. package/dist/ui/assets/index-CPEiQt-C.js +8 -0
  855. package/dist/ui/assets/index-D3-Yn_WA.css +1 -0
  856. package/dist/ui/index.html +13 -0
  857. package/package.json +123 -3
@@ -0,0 +1,1269 @@
1
+ import { existsSync, realpathSync, statSync } from "node:fs";
2
+ import { getOpenCodeDbPath } from "./opencode-db-path.js";
3
+ import { openOpenCodeSqliteReadOnly } from "./opencode-sqlite.js";
4
+ import { selectForkOwners } from "./usage-ownership.js";
5
+ /**
6
+ * Error thrown when a session is not found.
7
+ *
8
+ * OpenCode 2 stores sessions and messages in SQLite (`opencode.db`) under the
9
+ * `session_v2` and `session_message` tables. This is thrown by
10
+ * iterAssistantMessagesForSession when the database is missing/unreadable, the
11
+ * session id is invalid, or the session row does not exist.
12
+ */
13
+ export class SessionNotFoundError extends Error {
14
+ sessionID;
15
+ checkedPath;
16
+ constructor(sessionID, checkedPath) {
17
+ super(`Session not found: ${sessionID}`);
18
+ this.sessionID = sessionID;
19
+ this.checkedPath = checkedPath;
20
+ this.name = "SessionNotFoundError";
21
+ }
22
+ }
23
+ // Stay comfortably below SQLite's default host-parameter cap once optional
24
+ // time filters are included in the query.
25
+ const SQLITE_MAX_MESSAGE_QUERY_ARGS = 900;
26
+ function normalizeNumber(n) {
27
+ return typeof n === "number" && Number.isFinite(n) ? n : undefined;
28
+ }
29
+ function normalizeString(s) {
30
+ return typeof s === "string" ? s : undefined;
31
+ }
32
+ function mapRowToOpenCodeMessage(row) {
33
+ if (!row || typeof row !== "object")
34
+ return null;
35
+ if (typeof row.id !== "string" || typeof row.session_id !== "string")
36
+ return null;
37
+ if (typeof row.time_created !== "number")
38
+ return null;
39
+ const input = normalizeNumber(row.tokens_input);
40
+ const output = normalizeNumber(row.tokens_output);
41
+ const reasoning = normalizeNumber(row.tokens_reasoning);
42
+ const cacheRead = normalizeNumber(row.tokens_cache_read);
43
+ const cacheWrite = normalizeNumber(row.tokens_cache_write);
44
+ const hasTokens = [input, output, reasoning, cacheRead, cacheWrite].some((value) => value !== undefined);
45
+ return {
46
+ id: row.id,
47
+ sessionID: row.session_id,
48
+ role: normalizeString(row.role) ?? "unknown",
49
+ providerID: normalizeString(row.provider_id),
50
+ modelID: normalizeString(row.model_id),
51
+ tokens: hasTokens
52
+ ? {
53
+ input: input ?? 0,
54
+ output: output ?? 0,
55
+ ...(reasoning === undefined ? {} : { reasoning }),
56
+ cache: { read: cacheRead ?? 0, write: cacheWrite ?? 0 },
57
+ }
58
+ : undefined,
59
+ cost: normalizeNumber(row.cost),
60
+ time: {
61
+ created: row.time_created,
62
+ completed: normalizeNumber(row.time_completed),
63
+ },
64
+ agent: normalizeString(row.agent),
65
+ mode: normalizeString(row.mode),
66
+ };
67
+ }
68
+ function openDbOrNull() {
69
+ const dbPath = getOpenCodeDbPath();
70
+ if (dbPath === ":memory:" || !existsSync(dbPath))
71
+ return null;
72
+ return {
73
+ dbPath,
74
+ open: () => openOpenCodeSqliteReadOnly(dbPath),
75
+ };
76
+ }
77
+ function validateSessionIdOrThrow(sessionID) {
78
+ if (!sessionID.startsWith("ses_")) {
79
+ throw new SessionNotFoundError(sessionID, "(invalid session ID format)");
80
+ }
81
+ }
82
+ function normalizeSessionIdsOrThrow(sessionIDs) {
83
+ const unique = [];
84
+ const seen = new Set();
85
+ for (const sessionID of sessionIDs) {
86
+ validateSessionIdOrThrow(sessionID);
87
+ if (seen.has(sessionID))
88
+ continue;
89
+ seen.add(sessionID);
90
+ unique.push(sessionID);
91
+ }
92
+ return unique;
93
+ }
94
+ function chunkArray(items, chunkSize) {
95
+ const chunks = [];
96
+ for (let i = 0; i < items.length; i += chunkSize) {
97
+ chunks.push(items.slice(i, i + chunkSize));
98
+ }
99
+ return chunks;
100
+ }
101
+ function guardedJsonScalar(path) {
102
+ return `CASE WHEN json_valid(data) THEN json_extract(data, '${path}') END`;
103
+ }
104
+ const PROJECTED_MESSAGE_COLUMNS = [
105
+ "id",
106
+ "session_id",
107
+ "time_created",
108
+ "type AS role",
109
+ `${guardedJsonScalar("$.model.providerID")} AS provider_id`,
110
+ `${guardedJsonScalar("$.model.id")} AS model_id`,
111
+ `${guardedJsonScalar("$.tokens.input")} AS tokens_input`,
112
+ `${guardedJsonScalar("$.tokens.output")} AS tokens_output`,
113
+ `${guardedJsonScalar("$.tokens.reasoning")} AS tokens_reasoning`,
114
+ `${guardedJsonScalar("$.tokens.cache.read")} AS tokens_cache_read`,
115
+ `${guardedJsonScalar("$.tokens.cache.write")} AS tokens_cache_write`,
116
+ `${guardedJsonScalar("$.cost")} AS cost`,
117
+ `${guardedJsonScalar("$.time.completed")} AS time_completed`,
118
+ `${guardedJsonScalar("$.agent")} AS agent`,
119
+ ].join(", ");
120
+ const ASSISTANT_FILTER = `type = 'assistant'`;
121
+ function buildMessageQuery(params) {
122
+ if (params.sessionID && params.sessionIDs?.length) {
123
+ throw new Error("buildMessageQuery received both sessionID and sessionIDs");
124
+ }
125
+ const where = [];
126
+ const args = [];
127
+ if (params.sessionID) {
128
+ where.push(`session_id = ?`);
129
+ args.push(params.sessionID);
130
+ }
131
+ else if (params.sessionIDs) {
132
+ if (params.sessionIDs.length === 0) {
133
+ where.push(`1 = 0`);
134
+ }
135
+ else {
136
+ where.push(`session_id IN (${params.sessionIDs.map(() => "?").join(", ")})`);
137
+ args.push(...params.sessionIDs);
138
+ }
139
+ }
140
+ if (typeof params.sinceMs === "number") {
141
+ where.push(`time_created >= ?`);
142
+ args.push(params.sinceMs);
143
+ }
144
+ if (typeof params.untilMs === "number") {
145
+ where.push(`time_created <= ?`);
146
+ args.push(params.untilMs);
147
+ }
148
+ where.push(ASSISTANT_FILTER);
149
+ const sql = `SELECT ${PROJECTED_MESSAGE_COLUMNS} FROM "session_message"` +
150
+ (where.length ? ` WHERE ${where.join(" AND ")}` : "") +
151
+ ` ORDER BY time_created ASC, id ASC`;
152
+ return { sql, args };
153
+ }
154
+ function hasJsonExtract(conn) {
155
+ try {
156
+ const row = conn.get("SELECT json_extract('{\"role\":\"assistant\"}', '$.role') as r");
157
+ return row?.r === "assistant";
158
+ }
159
+ catch {
160
+ return false;
161
+ }
162
+ }
163
+ /**
164
+ * The columns a table ships with, or `null` when the table is absent or
165
+ * unreadable. R46 schema drift degrades to "unknown project" instead of
166
+ * failing; table names here are fixed literals, never user input.
167
+ */
168
+ function readTableColumns(conn, table) {
169
+ try {
170
+ const rows = conn.all(`PRAGMA table_info("${table}")`);
171
+ const columns = new Set();
172
+ for (const row of rows) {
173
+ if (row && typeof row.name === "string")
174
+ columns.add(row.name);
175
+ }
176
+ return columns.size > 0 ? columns : null;
177
+ }
178
+ catch {
179
+ return null;
180
+ }
181
+ }
182
+ function mapAssistantMessages(rows) {
183
+ const out = [];
184
+ for (const row of rows) {
185
+ const msg = mapRowToOpenCodeMessage(row);
186
+ if (!msg)
187
+ continue;
188
+ if (String(msg.role).toLowerCase() !== "assistant")
189
+ continue;
190
+ out.push(msg);
191
+ }
192
+ return out;
193
+ }
194
+ function completedAt(message) {
195
+ const value = message.time?.completed;
196
+ return typeof value === "number" && Number.isFinite(value) && value > 0
197
+ ? Math.trunc(value)
198
+ : null;
199
+ }
200
+ function mapCompletedAssistantMessages(rows) {
201
+ return mapAssistantMessages(rows).filter((message) => completedAt(message) !== null);
202
+ }
203
+ function buildCompletedAssistantQuery(params, includeUpdatedAt = false) {
204
+ const completedScalar = guardedJsonScalar("$.time.completed");
205
+ const completedExpression = `CAST(${completedScalar} AS REAL)`;
206
+ const projectedColumns = includeUpdatedAt
207
+ ? `${PROJECTED_MESSAGE_COLUMNS}, time_updated`
208
+ : PROJECTED_MESSAGE_COLUMNS;
209
+ const where = [
210
+ ASSISTANT_FILTER,
211
+ `CASE WHEN json_valid(data) THEN json_type(data, '$.time.completed') END IN ('integer', 'real')`,
212
+ `${completedExpression} > 0`,
213
+ ];
214
+ const args = [];
215
+ if (typeof params.completedSinceMs === "number") {
216
+ where.push(`${completedExpression} >= ?`);
217
+ args.push(params.completedSinceMs);
218
+ }
219
+ if (typeof params.completedUntilMs === "number") {
220
+ where.push(`${completedExpression} <= ?`);
221
+ args.push(params.completedUntilMs);
222
+ }
223
+ if (params.completedAtTimes !== undefined) {
224
+ const times = [...new Set(params.completedAtTimes)]
225
+ .filter((time) => Number.isFinite(time))
226
+ .sort((a, b) => a - b);
227
+ if (times.length === 0) {
228
+ where.push(`1 = 0`);
229
+ }
230
+ else {
231
+ // One JSON-array bind keeps the exact-time candidate projection to a
232
+ // single SQLite scan instead of one scan per completion timestamp.
233
+ where.push(`${completedExpression} IN (SELECT value FROM json_each(?))`);
234
+ args.push(JSON.stringify(times));
235
+ }
236
+ }
237
+ if (params.sessionID !== undefined) {
238
+ where.push(`session_id = ?`);
239
+ args.push(params.sessionID);
240
+ }
241
+ else if (params.sessionIDs !== undefined) {
242
+ if (params.sessionIDs.length === 0) {
243
+ where.push(`1 = 0`);
244
+ }
245
+ else {
246
+ where.push(`session_id IN (${params.sessionIDs.map(() => "?").join(", ")})`);
247
+ args.push(...params.sessionIDs);
248
+ }
249
+ }
250
+ if (params.messageIDs !== undefined) {
251
+ if (params.messageIDs.length === 0) {
252
+ where.push(`1 = 0`);
253
+ }
254
+ else {
255
+ where.push(`id IN (${params.messageIDs.map(() => "?").join(", ")})`);
256
+ args.push(...params.messageIDs);
257
+ }
258
+ }
259
+ return {
260
+ // `readCompletedAssistantRowsFrom` sorts the projected rows itself
261
+ // (`completedAtMs ASC, messageID ASC`), so a SQL ORDER BY here only adds a
262
+ // temp B-tree over every matched row. Keep the scan unsorted and let the
263
+ // single deterministic in-memory sort define the result order.
264
+ sql: `SELECT ${projectedColumns} FROM "session_message"` + ` WHERE ${where.join(" AND ")}`,
265
+ args,
266
+ };
267
+ }
268
+ /** Deterministic code-unit comparison used for raw message ids. */
269
+ function compareStringIds(a, b) {
270
+ if (a < b)
271
+ return -1;
272
+ if (a > b)
273
+ return 1;
274
+ return 0;
275
+ }
276
+ function compareRawCompletedRows(a, b) {
277
+ if (a.completedAtMs !== b.completedAtMs)
278
+ return a.completedAtMs - b.completedAtMs;
279
+ return compareStringIds(a.messageID, b.messageID);
280
+ }
281
+ /**
282
+ * Completion-time order for the public message iterator. The SQL builder no
283
+ * longer sorts (the analytics reader sorts its own projection), so this path
284
+ * applies the same `CAST(completed AS REAL), id` order in memory.
285
+ */
286
+ function compareCompletedMessageOrder(a, b) {
287
+ const aCompleted = a.time?.completed;
288
+ const bCompleted = b.time?.completed;
289
+ const aValue = typeof aCompleted === "number" && Number.isFinite(aCompleted)
290
+ ? aCompleted
291
+ : Number.NEGATIVE_INFINITY;
292
+ const bValue = typeof bCompleted === "number" && Number.isFinite(bCompleted)
293
+ ? bCompleted
294
+ : Number.NEGATIVE_INFINITY;
295
+ if (aValue !== bValue)
296
+ return aValue - bValue;
297
+ return compareStringIds(a.id, b.id);
298
+ }
299
+ function dedupeStrings(values) {
300
+ const out = [];
301
+ const seen = new Set();
302
+ for (const value of values) {
303
+ if (seen.has(value))
304
+ continue;
305
+ seen.add(value);
306
+ out.push(value);
307
+ }
308
+ return out;
309
+ }
310
+ /**
311
+ * Resolve the id scope shared by the raw completed reader, the compaction
312
+ * reader, and the revision snapshot. `messageIDs` combines with a session
313
+ * scope (AND); `sessionID` and `sessionIDs` are mutually exclusive. Any empty
314
+ * id list resolves to `empty` so no SQLite connection is opened.
315
+ */
316
+ function normalizeStorageScope(params) {
317
+ if (params.sessionID !== undefined && params.sessionIDs !== undefined) {
318
+ throw new Error("received both sessionID and sessionIDs");
319
+ }
320
+ if (params.sessionID === "")
321
+ return { kind: "empty" };
322
+ if (params.sessionIDs !== undefined && params.sessionIDs.length === 0)
323
+ return { kind: "empty" };
324
+ if (params.messageIDs !== undefined && params.messageIDs.length === 0)
325
+ return { kind: "empty" };
326
+ const ids = {};
327
+ if (params.sessionID !== undefined)
328
+ ids.sessionID = params.sessionID;
329
+ if (params.sessionIDs !== undefined)
330
+ ids.sessionIDs = dedupeStrings(params.sessionIDs);
331
+ if (params.messageIDs !== undefined)
332
+ ids.messageIDs = dedupeStrings(params.messageIDs);
333
+ if (ids.sessionID === undefined && ids.sessionIDs === undefined && ids.messageIDs === undefined) {
334
+ return { kind: "all" };
335
+ }
336
+ return { kind: "scope", ids };
337
+ }
338
+ /**
339
+ * Chunk one scope into queries under a bind-argument budget. `messageIDs` and
340
+ * session ids combine with AND semantics; when both lists are present they are
341
+ * chunked together so every emitted query stays within the budget.
342
+ */
343
+ function scopedIdQueries(ids, budget, build) {
344
+ const queries = [];
345
+ const { sessionID, sessionIDs, messageIDs } = ids;
346
+ if (messageIDs === undefined) {
347
+ if (sessionID !== undefined)
348
+ return [build({ sessionID })];
349
+ if (sessionIDs !== undefined) {
350
+ for (const chunk of chunkArray(sessionIDs, budget)) {
351
+ queries.push(build({ sessionIDs: chunk }));
352
+ }
353
+ }
354
+ return queries;
355
+ }
356
+ if (sessionID !== undefined) {
357
+ for (const chunk of chunkArray(messageIDs, Math.max(1, budget - 1))) {
358
+ queries.push(build({ sessionID, messageIDs: chunk }));
359
+ }
360
+ return queries;
361
+ }
362
+ if (sessionIDs === undefined) {
363
+ for (const chunk of chunkArray(messageIDs, budget))
364
+ queries.push(build({ messageIDs: chunk }));
365
+ return queries;
366
+ }
367
+ for (const messageChunk of chunkArray(messageIDs, Math.max(1, budget - 1))) {
368
+ const remaining = Math.max(1, budget - messageChunk.length);
369
+ for (const sessionChunk of chunkArray(sessionIDs, remaining)) {
370
+ queries.push(build({ sessionIDs: sessionChunk, messageIDs: messageChunk }));
371
+ }
372
+ }
373
+ return queries;
374
+ }
375
+ function countDefined(values) {
376
+ let count = 0;
377
+ for (const value of values)
378
+ if (value !== undefined)
379
+ count += 1;
380
+ return count;
381
+ }
382
+ /**
383
+ * Fingerprint shared by the upstream fork-copy dedup and the GUI owner set
384
+ * (R50). Exported so P3 groups raw rows by the exact upstream formula.
385
+ */
386
+ export function forkCopyFingerprint(message, completed) {
387
+ const tokens = message.tokens;
388
+ return JSON.stringify([
389
+ message.time?.created,
390
+ completed,
391
+ message.providerID,
392
+ message.modelID,
393
+ tokens?.input,
394
+ tokens?.output,
395
+ tokens?.reasoning,
396
+ tokens?.cache.read,
397
+ tokens?.cache.write,
398
+ message.cost,
399
+ ]);
400
+ }
401
+ /**
402
+ * The same upstream fingerprint derived from a raw completed row, for the
403
+ * shared deterministic ownership primitive. Exported so the GUI aggregation
404
+ * and the analytics worker use one formula.
405
+ */
406
+ export function rawAssistantRowFingerprint(row) {
407
+ return forkCopyFingerprint({
408
+ id: row.messageID,
409
+ sessionID: row.sessionID,
410
+ role: "assistant",
411
+ providerID: row.providerID,
412
+ modelID: row.modelID,
413
+ tokens: {
414
+ input: row.tokens.input,
415
+ output: row.tokens.output,
416
+ reasoning: row.tokens.reasoning,
417
+ cache: { read: row.tokens.cacheRead, write: row.tokens.cacheWrite },
418
+ },
419
+ cost: row.cost,
420
+ time: { created: row.createdAtMs, completed: row.completedAtMs },
421
+ }, row.completedAtMs);
422
+ }
423
+ /**
424
+ * OpenCode copies a parent's finished messages into each fork with new ids but
425
+ * identical times, model, tokens, and cost. Each finished fingerprint is owned
426
+ * as many times as the session that has it most often; unfinished rows are
427
+ * always kept. Shared deterministic selection lives in `usage-ownership.ts`.
428
+ */
429
+ function dropForkCopies(messages) {
430
+ const candidates = [];
431
+ for (const message of messages) {
432
+ const candidate = {
433
+ item: message,
434
+ sessionID: message.sessionID,
435
+ messageID: message.id,
436
+ };
437
+ const completed = completedAt(message);
438
+ if (completed !== null)
439
+ candidate.fingerprint = forkCopyFingerprint(message, completed);
440
+ const created = message.time?.created;
441
+ if (typeof created === "number" && Number.isFinite(created))
442
+ candidate.createdAtMs = created;
443
+ candidates.push(candidate);
444
+ }
445
+ return selectForkOwners(candidates);
446
+ }
447
+ function compareMessageOrder(a, b) {
448
+ const aCreated = typeof a.time?.created === "number" ? a.time.created : Number.MAX_SAFE_INTEGER;
449
+ const bCreated = typeof b.time?.created === "number" ? b.time.created : Number.MAX_SAFE_INTEGER;
450
+ if (aCreated !== bCreated)
451
+ return aCreated - bCreated;
452
+ return a.id.localeCompare(b.id);
453
+ }
454
+ export async function getOpenCodeDbStats() {
455
+ const db = openDbOrNull();
456
+ if (!db) {
457
+ return {
458
+ dbPath: getOpenCodeDbPath(),
459
+ sessionCount: 0,
460
+ messageCount: 0,
461
+ assistantMessageCount: 0,
462
+ };
463
+ }
464
+ const conn = await db.open();
465
+ try {
466
+ const sessionRow = conn.get(`SELECT count(*) as c FROM "session_v2"`);
467
+ const messageRow = conn.get(`SELECT count(*) as c FROM "session_message"`);
468
+ let assistantCount = 0;
469
+ if (await hasJsonExtract(conn)) {
470
+ const a = conn.get(`SELECT count(*) as c FROM "session_message" WHERE type = 'assistant'`);
471
+ assistantCount = typeof a?.c === "number" ? a.c : 0;
472
+ }
473
+ return {
474
+ dbPath: db.dbPath,
475
+ sessionCount: typeof sessionRow?.c === "number" ? sessionRow.c : 0,
476
+ messageCount: typeof messageRow?.c === "number" ? messageRow.c : 0,
477
+ assistantMessageCount: assistantCount,
478
+ };
479
+ }
480
+ finally {
481
+ conn.close();
482
+ }
483
+ }
484
+ export async function iterAssistantMessages(params) {
485
+ const db = openDbOrNull();
486
+ if (!db)
487
+ return [];
488
+ const conn = await db.open();
489
+ try {
490
+ if (!(await hasJsonExtract(conn)))
491
+ return [];
492
+ const q = buildMessageQuery({ sinceMs: params.sinceMs, untilMs: params.untilMs });
493
+ const rows = conn.all(q.sql, q.args);
494
+ return dropForkCopies(mapAssistantMessages(rows));
495
+ }
496
+ finally {
497
+ conn.close();
498
+ }
499
+ }
500
+ /**
501
+ * Read authoritative completed assistant/model-loop rows by completion time.
502
+ *
503
+ * This path intentionally does not share the creation-time filters used by token
504
+ * history. A request may be created before a window cutoff and complete inside it.
505
+ */
506
+ export async function iterCompletedAssistantMessages(params) {
507
+ const db = openDbOrNull();
508
+ if (!db)
509
+ return [];
510
+ const conn = await db.open();
511
+ try {
512
+ if (await hasJsonExtract(conn)) {
513
+ const query = buildCompletedAssistantQuery(params);
514
+ const messages = mapCompletedAssistantMessages(conn.all(query.sql, query.args));
515
+ messages.sort(compareCompletedMessageOrder);
516
+ return dropForkCopies(messages);
517
+ }
518
+ return [];
519
+ }
520
+ finally {
521
+ conn.close();
522
+ }
523
+ }
524
+ /**
525
+ * Read assistant messages for a specific session only.
526
+ */
527
+ export async function iterAssistantMessagesForSession(params) {
528
+ const { sessionID, sinceMs, untilMs } = params;
529
+ validateSessionIdOrThrow(sessionID);
530
+ const db = openDbOrNull();
531
+ if (!db) {
532
+ throw new SessionNotFoundError(sessionID, getOpenCodeDbPath());
533
+ }
534
+ const conn = await db.open();
535
+ try {
536
+ const exists = conn.get(`SELECT 1 as ok FROM "session_v2" WHERE id = ? LIMIT 1`, [sessionID]);
537
+ if (!exists) {
538
+ throw new SessionNotFoundError(sessionID, db.dbPath);
539
+ }
540
+ if (!(await hasJsonExtract(conn)))
541
+ return [];
542
+ const q = buildMessageQuery({ sessionID, sinceMs, untilMs });
543
+ const rows = conn.all(q.sql, q.args);
544
+ return mapAssistantMessages(rows);
545
+ }
546
+ finally {
547
+ conn.close();
548
+ }
549
+ }
550
+ /**
551
+ * Read assistant messages for a specific set of sessions.
552
+ */
553
+ export async function iterAssistantMessagesForSessions(params) {
554
+ const sessionIDs = normalizeSessionIdsOrThrow(params.sessionIDs);
555
+ const [firstSessionID] = sessionIDs;
556
+ if (firstSessionID === undefined)
557
+ return [];
558
+ const db = openDbOrNull();
559
+ if (!db) {
560
+ throw new SessionNotFoundError(firstSessionID, getOpenCodeDbPath());
561
+ }
562
+ const conn = await db.open();
563
+ try {
564
+ if (!(await hasJsonExtract(conn)))
565
+ return [];
566
+ const reservedArgs = (typeof params.sinceMs === "number" ? 1 : 0) + (typeof params.untilMs === "number" ? 1 : 0);
567
+ const maxSessionIdsPerQuery = Math.max(1, SQLITE_MAX_MESSAGE_QUERY_ARGS - reservedArgs);
568
+ const messages = [];
569
+ for (const sessionIdChunk of chunkArray(sessionIDs, maxSessionIdsPerQuery)) {
570
+ const q = buildMessageQuery({
571
+ sessionIDs: sessionIdChunk,
572
+ sinceMs: params.sinceMs,
573
+ untilMs: params.untilMs,
574
+ });
575
+ const rows = conn.all(q.sql, q.args);
576
+ messages.push(...mapAssistantMessages(rows));
577
+ }
578
+ messages.sort(compareMessageOrder);
579
+ return dropForkCopies(messages);
580
+ }
581
+ finally {
582
+ conn.close();
583
+ }
584
+ }
585
+ function readAllSessionsIndexFrom(conn) {
586
+ const idx = {};
587
+ const columns = readTableColumns(conn, "session_v2");
588
+ const metadataColumns = [
589
+ columns?.has("agent") ? "agent" : null,
590
+ columns?.has("project_id") ? "project_id" : null,
591
+ columns?.has("directory") ? "directory" : null,
592
+ ].filter((column) => column !== null);
593
+ const rows = conn.all(`SELECT id, title, parent_id, time_created, time_updated${metadataColumns.length ? `, ${metadataColumns.join(", ")}` : ""} FROM "session_v2" ORDER BY time_created ASC, id ASC`);
594
+ for (const row of rows) {
595
+ if (!row || typeof row.id !== "string" || !row.id.startsWith("ses_"))
596
+ continue;
597
+ idx[row.id] = {
598
+ id: row.id,
599
+ title: typeof row.title === "string" && row.title.trim() ? row.title : undefined,
600
+ agent: normalizeString(row.agent)?.trim() || undefined,
601
+ parentID: typeof row.parent_id === "string" ? row.parent_id : undefined,
602
+ projectID: normalizeString(row.project_id),
603
+ directory: normalizeString(row.directory),
604
+ time: {
605
+ created: typeof row.time_created === "number" ? row.time_created : undefined,
606
+ updated: typeof row.time_updated === "number" ? row.time_updated : undefined,
607
+ },
608
+ };
609
+ }
610
+ return idx;
611
+ }
612
+ export async function readAllSessionsIndex() {
613
+ const db = openDbOrNull();
614
+ if (!db)
615
+ return {};
616
+ const conn = await db.open();
617
+ try {
618
+ return readAllSessionsIndexFrom(conn);
619
+ }
620
+ finally {
621
+ conn.close();
622
+ }
623
+ }
624
+ function mapRawCompletedAssistantRow(row) {
625
+ const message = mapRowToOpenCodeMessage(row);
626
+ if (!message)
627
+ return null;
628
+ if (String(message.role).toLowerCase() !== "assistant")
629
+ return null;
630
+ const completed = completedAt(message);
631
+ if (completed === null)
632
+ return null;
633
+ return {
634
+ sessionID: message.sessionID,
635
+ messageID: message.id,
636
+ createdAtMs: message.time?.created ?? 0,
637
+ completedAtMs: completed,
638
+ tokens: {
639
+ input: message.tokens?.input ?? 0,
640
+ output: message.tokens?.output ?? 0,
641
+ reasoning: message.tokens?.reasoning ?? 0,
642
+ cacheRead: message.tokens?.cache.read ?? 0,
643
+ cacheWrite: message.tokens?.cache.write ?? 0,
644
+ },
645
+ cost: message.cost,
646
+ providerID: message.providerID,
647
+ modelID: message.modelID,
648
+ agent: message.agent,
649
+ };
650
+ }
651
+ /**
652
+ * Read physical completed assistant rows without fork dedup (R46, R50).
653
+ *
654
+ * Completed-only matches the dashboard step rule: an assistant row counts once
655
+ * `$.time.completed` is a positive number. The optional completed window is
656
+ * inclusive on both ends, so P3 aggregation can request a range directly.
657
+ *
658
+ * `sessionID`, `sessionIDs`, and `messageIDs` are mutually exclusive scopes;
659
+ * empty `sessionIDs`/`messageIDs` resolve to an empty read without opening the
660
+ * database. Large scopes are chunked under the SQLite bind-argument bound and
661
+ * merged back into completion-time order. `messageIDs` is the incremental
662
+ * reconciliation fetch after a `readMessageRevisions` diff. Schema drift (no
663
+ * message table or no JSON support) degrades to an empty read.
664
+ */
665
+ function readCompletedAssistantRowsFrom(conn, params) {
666
+ const scope = normalizeStorageScope(params);
667
+ if (scope.kind === "empty")
668
+ return [];
669
+ const columns = readTableColumns(conn, "session_message");
670
+ if (!columns?.has("type") || !columns.has("data"))
671
+ return [];
672
+ if (!hasJsonExtract(conn))
673
+ return [];
674
+ const hasUpdatedAt = columns.has("time_updated");
675
+ const reservedArgs = countDefined([
676
+ params.completedSinceMs,
677
+ params.completedUntilMs,
678
+ params.completedAtTimes,
679
+ ]);
680
+ const maxIdsPerQuery = Math.max(1, SQLITE_MAX_MESSAGE_QUERY_ARGS - reservedArgs);
681
+ const out = [];
682
+ const collect = (query) => {
683
+ for (const row of conn.all(query.sql, query.args)) {
684
+ const mapped = mapRawCompletedAssistantRow(row);
685
+ if (!mapped)
686
+ continue;
687
+ if (hasUpdatedAt)
688
+ mapped.updatedAtMs = normalizeNumber(row.time_updated) ?? null;
689
+ out.push(mapped);
690
+ }
691
+ };
692
+ if (scope.kind === "all") {
693
+ collect(buildCompletedAssistantQuery(params, hasUpdatedAt));
694
+ }
695
+ else {
696
+ const queries = scopedIdQueries(scope.ids, maxIdsPerQuery, (clause) => buildCompletedAssistantQuery({
697
+ completedSinceMs: params.completedSinceMs,
698
+ completedUntilMs: params.completedUntilMs,
699
+ completedAtTimes: params.completedAtTimes,
700
+ ...clause,
701
+ }, hasUpdatedAt));
702
+ for (const query of queries)
703
+ collect(query);
704
+ }
705
+ out.sort(compareRawCompletedRows);
706
+ return out;
707
+ }
708
+ export async function readCompletedAssistantRows(params = {}) {
709
+ if (normalizeStorageScope(params).kind === "empty")
710
+ return [];
711
+ const db = openDbOrNull();
712
+ if (!db)
713
+ return [];
714
+ const conn = await db.open();
715
+ try {
716
+ return readCompletedAssistantRowsFrom(conn, params);
717
+ }
718
+ finally {
719
+ conn.close();
720
+ }
721
+ }
722
+ /**
723
+ * Read project/worktree display metadata: `project.name`, registered
724
+ * `project_directory` directories, and `worktree` directories with
725
+ * `strategy = 'git_worktree'` (R46). Missing tables or columns degrade to an
726
+ * empty index, which P3 reports as the unknown project instead of failing.
727
+ */
728
+ function readProjectsIndexFrom(conn) {
729
+ const index = {};
730
+ const projectColumns = readTableColumns(conn, "project");
731
+ if (!projectColumns?.has("id"))
732
+ return index;
733
+ const projectProjection = [
734
+ "id",
735
+ projectColumns.has("name") ? "name" : null,
736
+ // `project.worktree` is the canonical root in the shipped schema. It takes
737
+ // precedence over registered/linked directories for name/root display.
738
+ projectColumns.has("worktree") ? "worktree" : null,
739
+ ].filter((column) => column !== null);
740
+ const projectRows = conn.all(`SELECT ${projectProjection.join(", ")} FROM "project" ORDER BY id ASC`);
741
+ for (const row of projectRows) {
742
+ if (typeof row.id !== "string" || !row.id)
743
+ continue;
744
+ const name = normalizeString(row.name);
745
+ const canonicalRoot = normalizeString(row.worktree)?.trim();
746
+ index[row.id] = {
747
+ id: row.id,
748
+ name: name?.trim() ? name : undefined,
749
+ directories: canonicalRoot ? [canonicalRoot] : [],
750
+ worktrees: [],
751
+ };
752
+ }
753
+ const directoryColumns = readTableColumns(conn, "project_directory");
754
+ if (directoryColumns?.has("project_id") && directoryColumns.has("directory")) {
755
+ const rows = conn.all(`SELECT project_id, directory FROM "project_directory" ORDER BY project_id ASC, directory ASC`);
756
+ for (const row of rows) {
757
+ const info = typeof row.project_id === "string" ? index[row.project_id] : undefined;
758
+ if (!info || typeof row.directory !== "string" || !row.directory)
759
+ continue;
760
+ // Canonical root first, then registered directories without duplicates.
761
+ if (info.directories.includes(row.directory))
762
+ continue;
763
+ info.directories.push(row.directory);
764
+ }
765
+ }
766
+ const worktreeColumns = readTableColumns(conn, "worktree");
767
+ if (worktreeColumns?.has("project_id") && worktreeColumns.has("directory")) {
768
+ // Shipped rows use `'git'` for linked worktrees and may also carry the
769
+ // historical `'git_worktree'`; NULL marks canonical roots, not linked ones.
770
+ // Missing strategy column degrades to the previous include-all behavior.
771
+ const strategyFilter = worktreeColumns.has("strategy")
772
+ ? ` WHERE strategy IN ('git', 'git_worktree')`
773
+ : "";
774
+ const rows = conn.all(`SELECT project_id, directory FROM "worktree"${strategyFilter} ORDER BY project_id ASC, directory ASC`);
775
+ for (const row of rows) {
776
+ const info = typeof row.project_id === "string" ? index[row.project_id] : undefined;
777
+ if (info && typeof row.directory === "string" && row.directory) {
778
+ info.worktrees.push(row.directory);
779
+ }
780
+ }
781
+ }
782
+ return index;
783
+ }
784
+ export async function readProjectsIndex() {
785
+ const db = openDbOrNull();
786
+ if (!db)
787
+ return {};
788
+ const conn = await db.open();
789
+ try {
790
+ return readProjectsIndexFrom(conn);
791
+ }
792
+ finally {
793
+ conn.close();
794
+ }
795
+ }
796
+ /**
797
+ * Read compaction message rows as ordered markers (R26, R46): ordered at the
798
+ * source by timestamp, then message id. The assistant readers cannot return
799
+ * these rows (`type = 'compaction'`), and this reader projects physical
800
+ * columns only — it never touches the JSON payload. `sessionID`/`sessionIDs`
801
+ * scope the read; empty id lists return no markers without opening the
802
+ * database. Missing tables degrade to no markers.
803
+ */
804
+ function readCompactionMarkersFrom(conn, params) {
805
+ const scope = normalizeStorageScope(params);
806
+ if (scope.kind === "empty")
807
+ return [];
808
+ const columns = readTableColumns(conn, "session_message");
809
+ if (!columns?.has("type"))
810
+ return [];
811
+ const markers = [];
812
+ const maxIdsPerQuery = Math.max(1, SQLITE_MAX_MESSAGE_QUERY_ARGS - countDefined([params.sinceMs, params.untilMs]));
813
+ const collect = (query) => {
814
+ for (const row of conn.all(query.sql, query.args)) {
815
+ if (typeof row.id !== "string" || typeof row.session_id !== "string")
816
+ continue;
817
+ if (typeof row.time_created !== "number" || !Number.isFinite(row.time_created))
818
+ continue;
819
+ markers.push({ sessionId: row.session_id, atMs: row.time_created, messageId: row.id });
820
+ }
821
+ };
822
+ const build = (scopeClause) => {
823
+ const where = [`type = 'compaction'`];
824
+ const args = [];
825
+ if (scopeClause?.sessionID !== undefined) {
826
+ where.push(`session_id = ?`);
827
+ args.push(scopeClause.sessionID);
828
+ }
829
+ else if (scopeClause?.sessionIDs !== undefined) {
830
+ where.push(`session_id IN (${scopeClause.sessionIDs.map(() => "?").join(", ")})`);
831
+ args.push(...scopeClause.sessionIDs);
832
+ }
833
+ if (typeof params.sinceMs === "number") {
834
+ where.push(`time_created >= ?`);
835
+ args.push(params.sinceMs);
836
+ }
837
+ if (typeof params.untilMs === "number") {
838
+ where.push(`time_created <= ?`);
839
+ args.push(params.untilMs);
840
+ }
841
+ return {
842
+ sql: `SELECT id, session_id, time_created FROM "session_message"` +
843
+ ` WHERE ${where.join(" AND ")} ORDER BY time_created ASC, id ASC`,
844
+ args,
845
+ };
846
+ };
847
+ if (scope.kind === "all") {
848
+ collect(build());
849
+ }
850
+ else {
851
+ const queries = scopedIdQueries(scope.ids, maxIdsPerQuery, (clause) => build(clause));
852
+ for (const query of queries)
853
+ collect(query);
854
+ }
855
+ markers.sort((a, b) => a.atMs - b.atMs || compareStringIds(a.messageId, b.messageId));
856
+ return markers;
857
+ }
858
+ export async function readCompactionMarkers(params = {}) {
859
+ if (normalizeStorageScope(params).kind === "empty")
860
+ return [];
861
+ const db = openDbOrNull();
862
+ if (!db)
863
+ return [];
864
+ const conn = await db.open();
865
+ try {
866
+ return readCompactionMarkersFrom(conn, params);
867
+ }
868
+ finally {
869
+ conn.close();
870
+ }
871
+ }
872
+ const UNAVAILABLE_REVISION_SNAPSHOT = {
873
+ available: false,
874
+ updatedAtAvailable: false,
875
+ completedAtAvailable: false,
876
+ revisions: [],
877
+ };
878
+ function revisionSnapshot(updatedAtAvailable, completedAtAvailable, revisions) {
879
+ return { available: true, updatedAtAvailable, completedAtAvailable, revisions };
880
+ }
881
+ /**
882
+ * Read every physical message identity in scope for worker reconciliation.
883
+ *
884
+ * The snapshot deliberately includes unfinished, non-assistant, and compaction
885
+ * rows: diffing message-id sets detects deletions, and per-row `type`,
886
+ * `updatedAtMs`, and `completedAtMs` detect edits, type transitions, and
887
+ * completion/uncompletion. Fetch changed completed assistant rows with
888
+ * `readCompletedAssistantRows({ messageIDs })`. Empty scopes return an empty
889
+ * snapshot without opening the database.
890
+ */
891
+ function readMessageRevisionsFrom(conn, params) {
892
+ const scope = normalizeStorageScope(params);
893
+ if (scope.kind === "empty")
894
+ return UNAVAILABLE_REVISION_SNAPSHOT;
895
+ const columns = readTableColumns(conn, "session_message");
896
+ if (!columns?.has("id") || !columns.has("session_id")) {
897
+ return UNAVAILABLE_REVISION_SNAPSHOT;
898
+ }
899
+ const updatedAtAvailable = columns.has("time_updated");
900
+ const completedAtAvailable = columns.has("data") && hasJsonExtract(conn);
901
+ const projection = [
902
+ "id",
903
+ "session_id",
904
+ columns.has("type") ? "type" : "NULL AS type",
905
+ columns.has("time_created") ? "time_created" : "NULL AS time_created",
906
+ updatedAtAvailable ? "time_updated" : "NULL AS time_updated",
907
+ completedAtAvailable
908
+ ? `${guardedJsonScalar("$.time.completed")} AS completed`
909
+ : "NULL AS completed",
910
+ ].join(", ");
911
+ const revisions = [];
912
+ const updatedDelta = updatedAtAvailable && typeof params.updatedSinceMs === "number"
913
+ ? params.updatedSinceMs
914
+ : undefined;
915
+ const maxIdsPerQuery = Math.max(1, SQLITE_MAX_MESSAGE_QUERY_ARGS - (updatedDelta === undefined ? 0 : 1));
916
+ const build = (scopeClause) => {
917
+ const where = [];
918
+ const args = [];
919
+ if (scopeClause?.sessionID !== undefined) {
920
+ where.push(`session_id = ?`);
921
+ args.push(scopeClause.sessionID);
922
+ }
923
+ else if (scopeClause?.sessionIDs !== undefined) {
924
+ where.push(`session_id IN (${scopeClause.sessionIDs.map(() => "?").join(", ")})`);
925
+ args.push(...scopeClause.sessionIDs);
926
+ }
927
+ if (scopeClause?.messageIDs !== undefined) {
928
+ where.push(`id IN (${scopeClause.messageIDs.map(() => "?").join(", ")})`);
929
+ args.push(...scopeClause.messageIDs);
930
+ }
931
+ if (updatedDelta !== undefined) {
932
+ // NULL timestamps are replayed rather than silently skipped; a new legacy
933
+ // row must remain visible even when it cannot advance the cursor.
934
+ where.push(`(time_updated IS NULL OR time_updated >= ?)`);
935
+ args.push(updatedDelta);
936
+ }
937
+ return {
938
+ // The reader sorts the collected revisions by message id, and the
939
+ // incremental engine re-sorts a delta by `(updatedAtMs, messageId)`
940
+ // before replay. A SQL ORDER BY would add a second temp B-tree (notably
941
+ // over a full identity projection) without changing the final order.
942
+ sql: `SELECT ${projection} FROM "session_message"` +
943
+ (where.length ? ` WHERE ${where.join(" AND ")}` : ""),
944
+ args,
945
+ };
946
+ };
947
+ const collect = (query) => {
948
+ for (const row of conn.all(query.sql, query.args)) {
949
+ if (typeof row.id !== "string" || typeof row.session_id !== "string")
950
+ continue;
951
+ const createdAt = normalizeNumber(row.time_created);
952
+ const updatedAt = normalizeNumber(row.time_updated);
953
+ const completed = normalizeNumber(row.completed);
954
+ revisions.push({
955
+ messageID: row.id,
956
+ sessionID: row.session_id,
957
+ type: normalizeString(row.type) ?? "unknown",
958
+ createdAtMs: createdAt ?? 0,
959
+ updatedAtMs: updatedAt ?? null,
960
+ completedAtMs: completed !== undefined && completed > 0 ? Math.trunc(completed) : null,
961
+ });
962
+ }
963
+ };
964
+ if (scope.kind === "all") {
965
+ collect(build());
966
+ }
967
+ else {
968
+ const queries = scopedIdQueries(scope.ids, maxIdsPerQuery, (clause) => build(clause));
969
+ for (const query of queries)
970
+ collect(query);
971
+ }
972
+ revisions.sort((a, b) => compareStringIds(a.messageID, b.messageID));
973
+ return revisionSnapshot(updatedAtAvailable, completedAtAvailable, revisions);
974
+ }
975
+ /**
976
+ * Read only the source `time_updated` frontier. This is the first-baseline
977
+ * establishment path: it scans the physical column but never projects JSON, so
978
+ * it cannot accidentally turn a cold start into a lifetime completion read.
979
+ */
980
+ function readMessageRevisionFrontierFrom(conn) {
981
+ const columns = readTableColumns(conn, "session_message");
982
+ if (!columns?.has("id")) {
983
+ return { available: false, updatedAtAvailable: false, maxUpdatedAtMs: null };
984
+ }
985
+ if (!columns.has("time_updated")) {
986
+ return { available: true, updatedAtAvailable: false, maxUpdatedAtMs: null };
987
+ }
988
+ const row = conn.get(`SELECT MAX(time_updated) AS max_updated FROM "session_message"`);
989
+ const maxUpdatedAtMs = normalizeNumber(row?.max_updated);
990
+ return {
991
+ available: true,
992
+ updatedAtAvailable: true,
993
+ maxUpdatedAtMs: maxUpdatedAtMs ?? null,
994
+ };
995
+ }
996
+ export async function readMessageRevisionFrontier() {
997
+ const db = openDbOrNull();
998
+ if (!db)
999
+ return { available: false, updatedAtAvailable: false, maxUpdatedAtMs: null };
1000
+ const conn = await db.open();
1001
+ try {
1002
+ return readMessageRevisionFrontierFrom(conn);
1003
+ }
1004
+ finally {
1005
+ conn.close();
1006
+ }
1007
+ }
1008
+ export async function readMessageRevisions(params = {}) {
1009
+ if (normalizeStorageScope(params).kind === "empty")
1010
+ return UNAVAILABLE_REVISION_SNAPSHOT;
1011
+ const db = openDbOrNull();
1012
+ if (!db)
1013
+ return UNAVAILABLE_REVISION_SNAPSHOT;
1014
+ const conn = await db.open();
1015
+ try {
1016
+ return readMessageRevisionsFrom(conn, params);
1017
+ }
1018
+ finally {
1019
+ conn.close();
1020
+ }
1021
+ }
1022
+ function fileIdentityKey(identity) {
1023
+ if (identity.device !== undefined && identity.inode !== undefined && identity.inode !== "0") {
1024
+ return `d:${identity.device}:${identity.inode}`;
1025
+ }
1026
+ if (identity.birthtimeMs !== undefined) {
1027
+ return `b:${identity.realPath ?? identity.dbPath}:${identity.birthtimeMs}`;
1028
+ }
1029
+ return undefined;
1030
+ }
1031
+ /**
1032
+ * Compare a previously accepted good identity with the latest read.
1033
+ *
1034
+ * - `unavailable`: the latest read could not reach a readable file. Keep the
1035
+ * current good state (and the last good identity) untouched.
1036
+ * - `changed`: stable file identity or schema layout changed (reset,
1037
+ * replacement, deletion+recreate). Rebuild from scratch.
1038
+ * - `unknown`: the platform did not expose a stable file key. Callers should
1039
+ * treat this as unchanged to avoid rebuild churn on content writes.
1040
+ * - `same`: content may have changed; reconcile through the revision diff.
1041
+ */
1042
+ export function compareOpenCodeSourceIdentity(previous, next) {
1043
+ if (next.status !== "ok")
1044
+ return "unavailable";
1045
+ if (previous === undefined || previous.status !== "ok")
1046
+ return "changed";
1047
+ if ((previous.realPath ?? previous.dbPath) !== (next.realPath ?? next.dbPath))
1048
+ return "changed";
1049
+ const previousKey = fileIdentityKey(previous);
1050
+ const nextKey = fileIdentityKey(next);
1051
+ if (previousKey === undefined || nextKey === undefined)
1052
+ return "unknown";
1053
+ if (previousKey !== nextKey)
1054
+ return "changed";
1055
+ if (previous.schemaToken !== undefined &&
1056
+ next.schemaToken !== undefined &&
1057
+ previous.schemaToken !== next.schemaToken) {
1058
+ return "changed";
1059
+ }
1060
+ return "same";
1061
+ }
1062
+ const SCHEMA_TOKEN_TABLES = [
1063
+ "session_v2",
1064
+ "session_message",
1065
+ "project",
1066
+ "project_directory",
1067
+ "worktree",
1068
+ ];
1069
+ function readSchemaToken(conn) {
1070
+ // Force a header read: a file that is not a database throws here, so the
1071
+ // identity/snapshot seams report "unreadable" instead of an empty DB.
1072
+ conn.get("SELECT count(*) AS c FROM sqlite_master");
1073
+ const parts = [];
1074
+ for (const table of SCHEMA_TOKEN_TABLES) {
1075
+ const columns = readTableColumns(conn, table);
1076
+ parts.push(columns ? `${table}(${[...columns].sort().join(",")})` : `${table}()`);
1077
+ }
1078
+ return parts.join("|");
1079
+ }
1080
+ function readSourceIdentityStat() {
1081
+ const dbPath = getOpenCodeDbPath();
1082
+ if (dbPath === ":memory:")
1083
+ return { dbPath, exists: false, status: "missing" };
1084
+ let stat;
1085
+ try {
1086
+ stat = statSync(dbPath);
1087
+ }
1088
+ catch {
1089
+ return { dbPath, exists: false, status: "missing" };
1090
+ }
1091
+ if (!stat.isFile()) {
1092
+ return {
1093
+ dbPath,
1094
+ exists: false,
1095
+ status: "unreadable",
1096
+ sizeBytes: stat.size,
1097
+ mtimeMs: stat.mtimeMs,
1098
+ birthtimeMs: stat.birthtimeMs,
1099
+ };
1100
+ }
1101
+ const identity = {
1102
+ dbPath,
1103
+ exists: true,
1104
+ status: "ok",
1105
+ sizeBytes: stat.size,
1106
+ mtimeMs: stat.mtimeMs,
1107
+ birthtimeMs: stat.birthtimeMs,
1108
+ };
1109
+ try {
1110
+ identity.realPath = realpathSync(dbPath);
1111
+ }
1112
+ catch {
1113
+ // Keep dbPath as the path component of the fallback key.
1114
+ }
1115
+ try {
1116
+ // BigInt stat keeps 64-bit file ids exact across platforms.
1117
+ const big = statSync(dbPath, { bigint: true });
1118
+ identity.device = big.dev.toString();
1119
+ identity.inode = big.ino.toString();
1120
+ identity.birthtimeMs = Number(big.birthtimeMs);
1121
+ }
1122
+ catch {
1123
+ // Fall back to the birthtime from the regular stat.
1124
+ }
1125
+ return identity;
1126
+ }
1127
+ /**
1128
+ * Read the local source identity. `status: "ok"` means the file exists and the
1129
+ * schema was readable (including a successfully opened, empty database);
1130
+ * `"missing"` and `"unreadable"` are explicit so callers can preserve the last
1131
+ * good state instead of replacing it with an empty generation.
1132
+ */
1133
+ export async function readOpenCodeSourceIdentity() {
1134
+ const identity = readSourceIdentityStat();
1135
+ if (identity.status !== "ok")
1136
+ return identity;
1137
+ let conn;
1138
+ try {
1139
+ conn = await openOpenCodeSqliteReadOnly(identity.dbPath);
1140
+ }
1141
+ catch {
1142
+ return { ...identity, status: "unreadable", schemaToken: undefined };
1143
+ }
1144
+ try {
1145
+ return { ...identity, schemaToken: readSchemaToken(conn) };
1146
+ }
1147
+ catch {
1148
+ return { ...identity, status: "unreadable", schemaToken: undefined };
1149
+ }
1150
+ finally {
1151
+ conn.close();
1152
+ }
1153
+ }
1154
+ function createStorageSnapshot(conn, identity) {
1155
+ return {
1156
+ dbPath: identity.dbPath,
1157
+ identity,
1158
+ readAllSessionsIndex: () => readAllSessionsIndexFrom(conn),
1159
+ readProjectsIndex: () => readProjectsIndexFrom(conn),
1160
+ readCompletedAssistantRows: (params = {}) => readCompletedAssistantRowsFrom(conn, params),
1161
+ readCompactionMarkers: (params = {}) => readCompactionMarkersFrom(conn, params),
1162
+ readMessageRevisions: (params = {}) => readMessageRevisionsFrom(conn, params),
1163
+ readMessageRevisionFrontier: () => readMessageRevisionFrontierFrom(conn),
1164
+ };
1165
+ }
1166
+ /**
1167
+ * The stable path identity observed before opening must still describe the
1168
+ * path while the transaction runs. A replacement between `stat` and `open`
1169
+ * otherwise pairs one file's identity with another file's rows.
1170
+ */
1171
+ function sameStablePathIdentity(before, after) {
1172
+ if (before.status !== "ok" || after.status !== "ok")
1173
+ return false;
1174
+ if ((before.realPath ?? before.dbPath) !== (after.realPath ?? after.dbPath))
1175
+ return false;
1176
+ if (before.birthtimeMs !== undefined &&
1177
+ after.birthtimeMs !== undefined &&
1178
+ before.birthtimeMs !== after.birthtimeMs) {
1179
+ return false;
1180
+ }
1181
+ const beforeKey = fileIdentityKey(before);
1182
+ const afterKey = fileIdentityKey(after);
1183
+ if (beforeKey !== undefined && afterKey !== undefined)
1184
+ return beforeKey === afterKey;
1185
+ if (before.birthtimeMs !== undefined && after.birthtimeMs !== undefined) {
1186
+ return before.birthtimeMs === after.birthtimeMs;
1187
+ }
1188
+ // No stable key is exposed on this platform; keep the existing "unknown"
1189
+ // policy rather than inventing a stronger generation guarantee.
1190
+ return true;
1191
+ }
1192
+ /**
1193
+ * Run `read` against one transaction-bound snapshot of the OpenCode database.
1194
+ *
1195
+ * The first `SELECT` after `BEGIN` establishes the read snapshot, so changed
1196
+ * payload reads and the membership/revision read inside the callback cannot
1197
+ * observe a concurrently committed generation. The same stable path identity
1198
+ * is rechecked after opening and before commit; a path replacement maps to
1199
+ * `unreadable` so the caller keeps its last good state. Callback errors
1200
+ * propagate after a rollback; only opening/transaction/schema/path-identity
1201
+ * failures map to `missing` or `unreadable`.
1202
+ */
1203
+ export async function withOpenCodeStorageSnapshot(read) {
1204
+ const statIdentity = readSourceIdentityStat();
1205
+ if (statIdentity.status === "missing")
1206
+ return { status: "missing" };
1207
+ if (statIdentity.status === "unreadable")
1208
+ return { status: "unreadable" };
1209
+ let conn;
1210
+ try {
1211
+ conn = await openOpenCodeSqliteReadOnly(statIdentity.dbPath);
1212
+ }
1213
+ catch {
1214
+ return { status: "unreadable" };
1215
+ }
1216
+ let began = false;
1217
+ try {
1218
+ try {
1219
+ conn.get("BEGIN");
1220
+ began = true;
1221
+ conn.get("SELECT 1");
1222
+ }
1223
+ catch {
1224
+ return { status: "unreadable" };
1225
+ }
1226
+ if (!sameStablePathIdentity(statIdentity, readSourceIdentityStat())) {
1227
+ return { status: "unreadable" };
1228
+ }
1229
+ let identity;
1230
+ try {
1231
+ identity = { ...statIdentity, schemaToken: readSchemaToken(conn) };
1232
+ }
1233
+ catch {
1234
+ return { status: "unreadable" };
1235
+ }
1236
+ const value = await read(createStorageSnapshot(conn, identity));
1237
+ // Do not publish a generation if the path was replaced during the read;
1238
+ // the connection remains the old file while the path already points at a
1239
+ // different generation.
1240
+ if (!sameStablePathIdentity(statIdentity, readSourceIdentityStat())) {
1241
+ return { status: "unreadable" };
1242
+ }
1243
+ if (began) {
1244
+ try {
1245
+ conn.get("COMMIT");
1246
+ }
1247
+ catch {
1248
+ // A read-only transaction commit has no observable effect.
1249
+ }
1250
+ began = false;
1251
+ }
1252
+ return { status: "ok", value };
1253
+ }
1254
+ catch (error) {
1255
+ if (began) {
1256
+ try {
1257
+ conn.get("ROLLBACK");
1258
+ }
1259
+ catch {
1260
+ // The connection is closed in `finally` regardless.
1261
+ }
1262
+ }
1263
+ throw error;
1264
+ }
1265
+ finally {
1266
+ conn.close();
1267
+ }
1268
+ }
1269
+ //# sourceMappingURL=opencode-storage.js.map