opencode-quota-gui 0.0.0-stage → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (849) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +245 -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/dashboard.d.ts +358 -0
  11. package/dist/contracts/dashboard.d.ts.map +1 -0
  12. package/dist/contracts/dashboard.js +3 -0
  13. package/dist/contracts/dashboard.js.map +1 -0
  14. package/dist/contracts/guards.d.ts +14 -0
  15. package/dist/contracts/guards.d.ts.map +1 -0
  16. package/dist/contracts/guards.js +56 -0
  17. package/dist/contracts/guards.js.map +1 -0
  18. package/dist/contracts/identity.d.ts +41 -0
  19. package/dist/contracts/identity.d.ts.map +1 -0
  20. package/dist/contracts/identity.js +27 -0
  21. package/dist/contracts/identity.js.map +1 -0
  22. package/dist/contracts/openai-quota.d.ts +34 -0
  23. package/dist/contracts/openai-quota.d.ts.map +1 -0
  24. package/dist/contracts/openai-quota.js +19 -0
  25. package/dist/contracts/openai-quota.js.map +1 -0
  26. package/dist/contracts/ranges.d.ts +48 -0
  27. package/dist/contracts/ranges.d.ts.map +1 -0
  28. package/dist/contracts/ranges.js +84 -0
  29. package/dist/contracts/ranges.js.map +1 -0
  30. package/dist/contracts/settings.d.ts +4 -0
  31. package/dist/contracts/settings.d.ts.map +1 -0
  32. package/dist/contracts/settings.js +14 -0
  33. package/dist/contracts/settings.js.map +1 -0
  34. package/dist/contracts/time-zone.d.ts +33 -0
  35. package/dist/contracts/time-zone.d.ts.map +1 -0
  36. package/dist/contracts/time-zone.js +217 -0
  37. package/dist/contracts/time-zone.js.map +1 -0
  38. package/dist/data/modelsdev-pricing.min.json +1064 -0
  39. package/dist/gui/aggregation.d.ts +55 -0
  40. package/dist/gui/aggregation.d.ts.map +1 -0
  41. package/dist/gui/aggregation.js +792 -0
  42. package/dist/gui/aggregation.js.map +1 -0
  43. package/dist/gui/analytics-bridge.d.ts +50 -0
  44. package/dist/gui/analytics-bridge.d.ts.map +1 -0
  45. package/dist/gui/analytics-bridge.js +382 -0
  46. package/dist/gui/analytics-bridge.js.map +1 -0
  47. package/dist/gui/analytics-engine.d.ts +61 -0
  48. package/dist/gui/analytics-engine.d.ts.map +1 -0
  49. package/dist/gui/analytics-engine.js +2381 -0
  50. package/dist/gui/analytics-engine.js.map +1 -0
  51. package/dist/gui/analytics-indexes.d.ts +34 -0
  52. package/dist/gui/analytics-indexes.d.ts.map +1 -0
  53. package/dist/gui/analytics-indexes.js +142 -0
  54. package/dist/gui/analytics-indexes.js.map +1 -0
  55. package/dist/gui/analytics-model.d.ts +48 -0
  56. package/dist/gui/analytics-model.d.ts.map +1 -0
  57. package/dist/gui/analytics-model.js +824 -0
  58. package/dist/gui/analytics-model.js.map +1 -0
  59. package/dist/gui/analytics-protocol.d.ts +102 -0
  60. package/dist/gui/analytics-protocol.d.ts.map +1 -0
  61. package/dist/gui/analytics-protocol.js +11 -0
  62. package/dist/gui/analytics-protocol.js.map +1 -0
  63. package/dist/gui/analytics-reader.d.ts +14 -0
  64. package/dist/gui/analytics-reader.d.ts.map +1 -0
  65. package/dist/gui/analytics-reader.js +15 -0
  66. package/dist/gui/analytics-reader.js.map +1 -0
  67. package/dist/gui/analytics-service.d.ts +49 -0
  68. package/dist/gui/analytics-service.d.ts.map +1 -0
  69. package/dist/gui/analytics-service.js +187 -0
  70. package/dist/gui/analytics-service.js.map +1 -0
  71. package/dist/gui/analytics-state.d.ts +183 -0
  72. package/dist/gui/analytics-state.d.ts.map +1 -0
  73. package/dist/gui/analytics-state.js +692 -0
  74. package/dist/gui/analytics-state.js.map +1 -0
  75. package/dist/gui/analytics-worker-runtime.d.ts +11 -0
  76. package/dist/gui/analytics-worker-runtime.d.ts.map +1 -0
  77. package/dist/gui/analytics-worker-runtime.js +98 -0
  78. package/dist/gui/analytics-worker-runtime.js.map +1 -0
  79. package/dist/gui/analytics-worker.d.ts +2 -0
  80. package/dist/gui/analytics-worker.d.ts.map +1 -0
  81. package/dist/gui/analytics-worker.js +64 -0
  82. package/dist/gui/analytics-worker.js.map +1 -0
  83. package/dist/gui/config.d.ts +53 -0
  84. package/dist/gui/config.d.ts.map +1 -0
  85. package/dist/gui/config.js +679 -0
  86. package/dist/gui/config.js.map +1 -0
  87. package/dist/gui/identity.d.ts +23 -0
  88. package/dist/gui/identity.d.ts.map +1 -0
  89. package/dist/gui/identity.js +57 -0
  90. package/dist/gui/identity.js.map +1 -0
  91. package/dist/gui/lifecycle.d.ts +82 -0
  92. package/dist/gui/lifecycle.d.ts.map +1 -0
  93. package/dist/gui/lifecycle.js +402 -0
  94. package/dist/gui/lifecycle.js.map +1 -0
  95. package/dist/gui/log.d.ts +23 -0
  96. package/dist/gui/log.d.ts.map +1 -0
  97. package/dist/gui/log.js +37 -0
  98. package/dist/gui/log.js.map +1 -0
  99. package/dist/gui/provider-cards.d.ts +58 -0
  100. package/dist/gui/provider-cards.d.ts.map +1 -0
  101. package/dist/gui/provider-cards.js +413 -0
  102. package/dist/gui/provider-cards.js.map +1 -0
  103. package/dist/gui/server.d.ts +60 -0
  104. package/dist/gui/server.d.ts.map +1 -0
  105. package/dist/gui/server.js +815 -0
  106. package/dist/gui/server.js.map +1 -0
  107. package/dist/gui/settings-file-opener.d.ts +34 -0
  108. package/dist/gui/settings-file-opener.d.ts.map +1 -0
  109. package/dist/gui/settings-file-opener.js +110 -0
  110. package/dist/gui/settings-file-opener.js.map +1 -0
  111. package/dist/gui/snapshot-service.d.ts +128 -0
  112. package/dist/gui/snapshot-service.d.ts.map +1 -0
  113. package/dist/gui/snapshot-service.js +591 -0
  114. package/dist/gui/snapshot-service.js.map +1 -0
  115. package/dist/gui/sources.d.ts +94 -0
  116. package/dist/gui/sources.d.ts.map +1 -0
  117. package/dist/gui/sources.js +404 -0
  118. package/dist/gui/sources.js.map +1 -0
  119. package/dist/gui/sse.d.ts +32 -0
  120. package/dist/gui/sse.d.ts.map +1 -0
  121. package/dist/gui/sse.js +100 -0
  122. package/dist/gui/sse.js.map +1 -0
  123. package/dist/gui/time-zone.d.ts +10 -0
  124. package/dist/gui/time-zone.d.ts.map +1 -0
  125. package/dist/gui/time-zone.js +21 -0
  126. package/dist/gui/time-zone.js.map +1 -0
  127. package/dist/index.d.ts +13 -0
  128. package/dist/index.d.ts.map +1 -0
  129. package/dist/index.js +12 -0
  130. package/dist/index.js.map +1 -0
  131. package/dist/lib/accounting-format.d.ts +54 -0
  132. package/dist/lib/accounting-format.d.ts.map +1 -0
  133. package/dist/lib/accounting-format.js +271 -0
  134. package/dist/lib/accounting-format.js.map +1 -0
  135. package/dist/lib/alibaba-auth.d.ts +46 -0
  136. package/dist/lib/alibaba-auth.d.ts.map +1 -0
  137. package/dist/lib/alibaba-auth.js +193 -0
  138. package/dist/lib/alibaba-auth.js.map +1 -0
  139. package/dist/lib/alibaba-coding-plan-local-quota.d.ts +47 -0
  140. package/dist/lib/alibaba-coding-plan-local-quota.d.ts.map +1 -0
  141. package/dist/lib/alibaba-coding-plan-local-quota.js +146 -0
  142. package/dist/lib/alibaba-coding-plan-local-quota.js.map +1 -0
  143. package/dist/lib/alibaba-token-plan.d.ts +91 -0
  144. package/dist/lib/alibaba-token-plan.d.ts.map +1 -0
  145. package/dist/lib/alibaba-token-plan.js +527 -0
  146. package/dist/lib/alibaba-token-plan.js.map +1 -0
  147. package/dist/lib/anthropic-auth.d.ts +29 -0
  148. package/dist/lib/anthropic-auth.d.ts.map +1 -0
  149. package/dist/lib/anthropic-auth.js +37 -0
  150. package/dist/lib/anthropic-auth.js.map +1 -0
  151. package/dist/lib/anthropic.d.ts +104 -0
  152. package/dist/lib/anthropic.d.ts.map +1 -0
  153. package/dist/lib/anthropic.js +1134 -0
  154. package/dist/lib/anthropic.js.map +1 -0
  155. package/dist/lib/api-key-resolver.d.ts +227 -0
  156. package/dist/lib/api-key-resolver.d.ts.map +1 -0
  157. package/dist/lib/api-key-resolver.js +336 -0
  158. package/dist/lib/api-key-resolver.js.map +1 -0
  159. package/dist/lib/atomic-json.d.ts +11 -0
  160. package/dist/lib/atomic-json.d.ts.map +1 -0
  161. package/dist/lib/atomic-json.js +64 -0
  162. package/dist/lib/atomic-json.js.map +1 -0
  163. package/dist/lib/chutes-config.d.ts +15 -0
  164. package/dist/lib/chutes-config.d.ts.map +1 -0
  165. package/dist/lib/chutes-config.js +28 -0
  166. package/dist/lib/chutes-config.js.map +1 -0
  167. package/dist/lib/chutes.d.ts +12 -0
  168. package/dist/lib/chutes.d.ts.map +1 -0
  169. package/dist/lib/chutes.js +60 -0
  170. package/dist/lib/chutes.js.map +1 -0
  171. package/dist/lib/cli-reports.d.ts +30 -0
  172. package/dist/lib/cli-reports.d.ts.map +1 -0
  173. package/dist/lib/cli-reports.js +172 -0
  174. package/dist/lib/cli-reports.js.map +1 -0
  175. package/dist/lib/cli-show.d.ts +30 -0
  176. package/dist/lib/cli-show.d.ts.map +1 -0
  177. package/dist/lib/cli-show.js +213 -0
  178. package/dist/lib/cli-show.js.map +1 -0
  179. package/dist/lib/cli-status.d.ts +8 -0
  180. package/dist/lib/cli-status.d.ts.map +1 -0
  181. package/dist/lib/cli-status.js +98 -0
  182. package/dist/lib/cli-status.js.map +1 -0
  183. package/dist/lib/command-parsing.d.ts +43 -0
  184. package/dist/lib/command-parsing.d.ts.map +1 -0
  185. package/dist/lib/command-parsing.js +103 -0
  186. package/dist/lib/command-parsing.js.map +1 -0
  187. package/dist/lib/config-file-utils.d.ts +46 -0
  188. package/dist/lib/config-file-utils.d.ts.map +1 -0
  189. package/dist/lib/config-file-utils.js +194 -0
  190. package/dist/lib/config-file-utils.js.map +1 -0
  191. package/dist/lib/config-write-target.d.ts +28 -0
  192. package/dist/lib/config-write-target.d.ts.map +1 -0
  193. package/dist/lib/config-write-target.js +159 -0
  194. package/dist/lib/config-write-target.js.map +1 -0
  195. package/dist/lib/config.d.ts +119 -0
  196. package/dist/lib/config.d.ts.map +1 -0
  197. package/dist/lib/config.js +1327 -0
  198. package/dist/lib/config.js.map +1 -0
  199. package/dist/lib/copilot.d.ts +78 -0
  200. package/dist/lib/copilot.d.ts.map +1 -0
  201. package/dist/lib/copilot.js +1111 -0
  202. package/dist/lib/copilot.js.map +1 -0
  203. package/dist/lib/cursor-detection.d.ts +18 -0
  204. package/dist/lib/cursor-detection.d.ts.map +1 -0
  205. package/dist/lib/cursor-detection.js +189 -0
  206. package/dist/lib/cursor-detection.js.map +1 -0
  207. package/dist/lib/cursor-pricing.d.ts +34 -0
  208. package/dist/lib/cursor-pricing.d.ts.map +1 -0
  209. package/dist/lib/cursor-pricing.js +235 -0
  210. package/dist/lib/cursor-pricing.js.map +1 -0
  211. package/dist/lib/cursor-usage.d.ts +33 -0
  212. package/dist/lib/cursor-usage.d.ts.map +1 -0
  213. package/dist/lib/cursor-usage.js +109 -0
  214. package/dist/lib/cursor-usage.js.map +1 -0
  215. package/dist/lib/deepseek-auth.d.ts +15 -0
  216. package/dist/lib/deepseek-auth.d.ts.map +1 -0
  217. package/dist/lib/deepseek-auth.js +28 -0
  218. package/dist/lib/deepseek-auth.js.map +1 -0
  219. package/dist/lib/deepseek.d.ts +40 -0
  220. package/dist/lib/deepseek.d.ts.map +1 -0
  221. package/dist/lib/deepseek.js +118 -0
  222. package/dist/lib/deepseek.js.map +1 -0
  223. package/dist/lib/display-sanitize.d.ts +20 -0
  224. package/dist/lib/display-sanitize.d.ts.map +1 -0
  225. package/dist/lib/display-sanitize.js +178 -0
  226. package/dist/lib/display-sanitize.js.map +1 -0
  227. package/dist/lib/entries.d.ts +365 -0
  228. package/dist/lib/entries.d.ts.map +1 -0
  229. package/dist/lib/entries.js +69 -0
  230. package/dist/lib/entries.js.map +1 -0
  231. package/dist/lib/env-template.d.ts +26 -0
  232. package/dist/lib/env-template.d.ts.map +1 -0
  233. package/dist/lib/env-template.js +36 -0
  234. package/dist/lib/env-template.js.map +1 -0
  235. package/dist/lib/format-utils.d.ts +89 -0
  236. package/dist/lib/format-utils.d.ts.map +1 -0
  237. package/dist/lib/format-utils.js +206 -0
  238. package/dist/lib/format-utils.js.map +1 -0
  239. package/dist/lib/format.d.ts +25 -0
  240. package/dist/lib/format.d.ts.map +1 -0
  241. package/dist/lib/format.js +300 -0
  242. package/dist/lib/format.js.map +1 -0
  243. package/dist/lib/glm-coding-plan.d.ts +19 -0
  244. package/dist/lib/glm-coding-plan.d.ts.map +1 -0
  245. package/dist/lib/glm-coding-plan.js +81 -0
  246. package/dist/lib/glm-coding-plan.js.map +1 -0
  247. package/dist/lib/google-agy-companion.d.ts +8 -0
  248. package/dist/lib/google-agy-companion.d.ts.map +1 -0
  249. package/dist/lib/google-agy-companion.js +64 -0
  250. package/dist/lib/google-agy-companion.js.map +1 -0
  251. package/dist/lib/google-agy.d.ts +48 -0
  252. package/dist/lib/google-agy.d.ts.map +1 -0
  253. package/dist/lib/google-agy.js +572 -0
  254. package/dist/lib/google-agy.js.map +1 -0
  255. package/dist/lib/google-companion-credentials.d.ts +70 -0
  256. package/dist/lib/google-companion-credentials.d.ts.map +1 -0
  257. package/dist/lib/google-companion-credentials.js +315 -0
  258. package/dist/lib/google-companion-credentials.js.map +1 -0
  259. package/dist/lib/google-gemini-cli-companion.d.ts +8 -0
  260. package/dist/lib/google-gemini-cli-companion.d.ts.map +1 -0
  261. package/dist/lib/google-gemini-cli-companion.js +64 -0
  262. package/dist/lib/google-gemini-cli-companion.js.map +1 -0
  263. package/dist/lib/google-gemini-cli.d.ts +47 -0
  264. package/dist/lib/google-gemini-cli.d.ts.map +1 -0
  265. package/dist/lib/google-gemini-cli.js +481 -0
  266. package/dist/lib/google-gemini-cli.js.map +1 -0
  267. package/dist/lib/google-token-cache.d.ts +27 -0
  268. package/dist/lib/google-token-cache.d.ts.map +1 -0
  269. package/dist/lib/google-token-cache.js +52 -0
  270. package/dist/lib/google-token-cache.js.map +1 -0
  271. package/dist/lib/grouped-entry-normalization.d.ts +12 -0
  272. package/dist/lib/grouped-entry-normalization.d.ts.map +1 -0
  273. package/dist/lib/grouped-entry-normalization.js +124 -0
  274. package/dist/lib/grouped-entry-normalization.js.map +1 -0
  275. package/dist/lib/grouped-header-format.d.ts +5 -0
  276. package/dist/lib/grouped-header-format.d.ts.map +1 -0
  277. package/dist/lib/grouped-header-format.js +16 -0
  278. package/dist/lib/grouped-header-format.js.map +1 -0
  279. package/dist/lib/gui-config-target.d.ts +12 -0
  280. package/dist/lib/gui-config-target.d.ts.map +1 -0
  281. package/dist/lib/gui-config-target.js +88 -0
  282. package/dist/lib/gui-config-target.js.map +1 -0
  283. package/dist/lib/home-dir-display.d.ts +10 -0
  284. package/dist/lib/home-dir-display.d.ts.map +1 -0
  285. package/dist/lib/home-dir-display.js +108 -0
  286. package/dist/lib/home-dir-display.js.map +1 -0
  287. package/dist/lib/http.d.ts +19 -0
  288. package/dist/lib/http.d.ts.map +1 -0
  289. package/dist/lib/http.js +47 -0
  290. package/dist/lib/http.js.map +1 -0
  291. package/dist/lib/init-installer.d.ts +146 -0
  292. package/dist/lib/init-installer.d.ts.map +1 -0
  293. package/dist/lib/init-installer.js +1056 -0
  294. package/dist/lib/init-installer.js.map +1 -0
  295. package/dist/lib/jsonc.d.ts +17 -0
  296. package/dist/lib/jsonc.d.ts.map +1 -0
  297. package/dist/lib/jsonc.js +23 -0
  298. package/dist/lib/jsonc.js.map +1 -0
  299. package/dist/lib/kilo-config.d.ts +15 -0
  300. package/dist/lib/kilo-config.d.ts.map +1 -0
  301. package/dist/lib/kilo-config.js +27 -0
  302. package/dist/lib/kilo-config.js.map +1 -0
  303. package/dist/lib/kilo.d.ts +32 -0
  304. package/dist/lib/kilo.d.ts.map +1 -0
  305. package/dist/lib/kilo.js +265 -0
  306. package/dist/lib/kilo.js.map +1 -0
  307. package/dist/lib/kimi-auth.d.ts +49 -0
  308. package/dist/lib/kimi-auth.d.ts.map +1 -0
  309. package/dist/lib/kimi-auth.js +82 -0
  310. package/dist/lib/kimi-auth.js.map +1 -0
  311. package/dist/lib/kimi-endpoints.d.ts +10 -0
  312. package/dist/lib/kimi-endpoints.d.ts.map +1 -0
  313. package/dist/lib/kimi-endpoints.js +18 -0
  314. package/dist/lib/kimi-endpoints.js.map +1 -0
  315. package/dist/lib/kimi.d.ts +26 -0
  316. package/dist/lib/kimi.d.ts.map +1 -0
  317. package/dist/lib/kimi.js +230 -0
  318. package/dist/lib/kimi.js.map +1 -0
  319. package/dist/lib/maintainer-announcements.d.ts +46 -0
  320. package/dist/lib/maintainer-announcements.d.ts.map +1 -0
  321. package/dist/lib/maintainer-announcements.js +155 -0
  322. package/dist/lib/maintainer-announcements.js.map +1 -0
  323. package/dist/lib/map-with-concurrency.d.ts +2 -0
  324. package/dist/lib/map-with-concurrency.d.ts.map +1 -0
  325. package/dist/lib/map-with-concurrency.js +17 -0
  326. package/dist/lib/map-with-concurrency.js.map +1 -0
  327. package/dist/lib/markdown-table.d.ts +51 -0
  328. package/dist/lib/markdown-table.d.ts.map +1 -0
  329. package/dist/lib/markdown-table.js +179 -0
  330. package/dist/lib/markdown-table.js.map +1 -0
  331. package/dist/lib/mimo-config.d.ts +29 -0
  332. package/dist/lib/mimo-config.d.ts.map +1 -0
  333. package/dist/lib/mimo-config.js +146 -0
  334. package/dist/lib/mimo-config.js.map +1 -0
  335. package/dist/lib/mimo.d.ts +35 -0
  336. package/dist/lib/mimo.d.ts.map +1 -0
  337. package/dist/lib/mimo.js +236 -0
  338. package/dist/lib/mimo.js.map +1 -0
  339. package/dist/lib/minimax-auth.d.ts +62 -0
  340. package/dist/lib/minimax-auth.d.ts.map +1 -0
  341. package/dist/lib/minimax-auth.js +206 -0
  342. package/dist/lib/minimax-auth.js.map +1 -0
  343. package/dist/lib/minimax-endpoints.d.ts +10 -0
  344. package/dist/lib/minimax-endpoints.d.ts.map +1 -0
  345. package/dist/lib/minimax-endpoints.js +19 -0
  346. package/dist/lib/minimax-endpoints.js.map +1 -0
  347. package/dist/lib/modelsdev-pricing.d.ts +93 -0
  348. package/dist/lib/modelsdev-pricing.d.ts.map +1 -0
  349. package/dist/lib/modelsdev-pricing.js +674 -0
  350. package/dist/lib/modelsdev-pricing.js.map +1 -0
  351. package/dist/lib/nanogpt-config.d.ts +15 -0
  352. package/dist/lib/nanogpt-config.d.ts.map +1 -0
  353. package/dist/lib/nanogpt-config.js +31 -0
  354. package/dist/lib/nanogpt-config.js.map +1 -0
  355. package/dist/lib/nanogpt.d.ts +48 -0
  356. package/dist/lib/nanogpt.d.ts.map +1 -0
  357. package/dist/lib/nanogpt.js +251 -0
  358. package/dist/lib/nanogpt.js.map +1 -0
  359. package/dist/lib/ollama-cloud-config.d.ts +15 -0
  360. package/dist/lib/ollama-cloud-config.d.ts.map +1 -0
  361. package/dist/lib/ollama-cloud-config.js +27 -0
  362. package/dist/lib/ollama-cloud-config.js.map +1 -0
  363. package/dist/lib/ollama-cloud.d.ts +14 -0
  364. package/dist/lib/ollama-cloud.d.ts.map +1 -0
  365. package/dist/lib/ollama-cloud.js +186 -0
  366. package/dist/lib/ollama-cloud.js.map +1 -0
  367. package/dist/lib/openai.d.ts +68 -0
  368. package/dist/lib/openai.d.ts.map +1 -0
  369. package/dist/lib/openai.js +394 -0
  370. package/dist/lib/openai.js.map +1 -0
  371. package/dist/lib/opencode-auth-sqlite.d.ts +17 -0
  372. package/dist/lib/opencode-auth-sqlite.d.ts.map +1 -0
  373. package/dist/lib/opencode-auth-sqlite.js +105 -0
  374. package/dist/lib/opencode-auth-sqlite.js.map +1 -0
  375. package/dist/lib/opencode-auth.d.ts +146 -0
  376. package/dist/lib/opencode-auth.d.ts.map +1 -0
  377. package/dist/lib/opencode-auth.js +465 -0
  378. package/dist/lib/opencode-auth.js.map +1 -0
  379. package/dist/lib/opencode-config-editor.d.ts +62 -0
  380. package/dist/lib/opencode-config-editor.d.ts.map +1 -0
  381. package/dist/lib/opencode-config-editor.js +387 -0
  382. package/dist/lib/opencode-config-editor.js.map +1 -0
  383. package/dist/lib/opencode-config-providers.d.ts +24 -0
  384. package/dist/lib/opencode-config-providers.d.ts.map +1 -0
  385. package/dist/lib/opencode-config-providers.js +144 -0
  386. package/dist/lib/opencode-config-providers.js.map +1 -0
  387. package/dist/lib/opencode-config-read.d.ts +23 -0
  388. package/dist/lib/opencode-config-read.d.ts.map +1 -0
  389. package/dist/lib/opencode-config-read.js +30 -0
  390. package/dist/lib/opencode-config-read.js.map +1 -0
  391. package/dist/lib/opencode-console-auth.d.ts +47 -0
  392. package/dist/lib/opencode-console-auth.d.ts.map +1 -0
  393. package/dist/lib/opencode-console-auth.js +63 -0
  394. package/dist/lib/opencode-console-auth.js.map +1 -0
  395. package/dist/lib/opencode-db-path.d.ts +9 -0
  396. package/dist/lib/opencode-db-path.d.ts.map +1 -0
  397. package/dist/lib/opencode-db-path.js +16 -0
  398. package/dist/lib/opencode-db-path.js.map +1 -0
  399. package/dist/lib/opencode-go-auth.d.ts +16 -0
  400. package/dist/lib/opencode-go-auth.d.ts.map +1 -0
  401. package/dist/lib/opencode-go-auth.js +42 -0
  402. package/dist/lib/opencode-go-auth.js.map +1 -0
  403. package/dist/lib/opencode-go.d.ts +17 -0
  404. package/dist/lib/opencode-go.d.ts.map +1 -0
  405. package/dist/lib/opencode-go.js +278 -0
  406. package/dist/lib/opencode-go.js.map +1 -0
  407. package/dist/lib/opencode-runtime-paths.d.ts +17 -0
  408. package/dist/lib/opencode-runtime-paths.d.ts.map +1 -0
  409. package/dist/lib/opencode-runtime-paths.js +24 -0
  410. package/dist/lib/opencode-runtime-paths.js.map +1 -0
  411. package/dist/lib/opencode-sqlite.d.ts +11 -0
  412. package/dist/lib/opencode-sqlite.d.ts.map +1 -0
  413. package/dist/lib/opencode-sqlite.js +88 -0
  414. package/dist/lib/opencode-sqlite.js.map +1 -0
  415. package/dist/lib/opencode-storage.d.ts +306 -0
  416. package/dist/lib/opencode-storage.d.ts.map +1 -0
  417. package/dist/lib/opencode-storage.js +1269 -0
  418. package/dist/lib/opencode-storage.js.map +1 -0
  419. package/dist/lib/opencode-version.d.ts +6 -0
  420. package/dist/lib/opencode-version.d.ts.map +1 -0
  421. package/dist/lib/opencode-version.js +26 -0
  422. package/dist/lib/opencode-version.js.map +1 -0
  423. package/dist/lib/opencode-zen.d.ts +55 -0
  424. package/dist/lib/opencode-zen.d.ts.map +1 -0
  425. package/dist/lib/opencode-zen.js +348 -0
  426. package/dist/lib/opencode-zen.js.map +1 -0
  427. package/dist/lib/openrouter.d.ts +16 -0
  428. package/dist/lib/openrouter.d.ts.map +1 -0
  429. package/dist/lib/openrouter.js +50 -0
  430. package/dist/lib/openrouter.js.map +1 -0
  431. package/dist/lib/private-state-paths.d.ts +10 -0
  432. package/dist/lib/private-state-paths.d.ts.map +1 -0
  433. package/dist/lib/private-state-paths.js +28 -0
  434. package/dist/lib/private-state-paths.js.map +1 -0
  435. package/dist/lib/provider-add-command.d.ts +35 -0
  436. package/dist/lib/provider-add-command.d.ts.map +1 -0
  437. package/dist/lib/provider-add-command.js +204 -0
  438. package/dist/lib/provider-add-command.js.map +1 -0
  439. package/dist/lib/provider-add-json-v1-questionnaire.d.ts +32 -0
  440. package/dist/lib/provider-add-json-v1-questionnaire.d.ts.map +1 -0
  441. package/dist/lib/provider-add-json-v1-questionnaire.js +336 -0
  442. package/dist/lib/provider-add-json-v1-questionnaire.js.map +1 -0
  443. package/dist/lib/provider-add.d.ts +21 -0
  444. package/dist/lib/provider-add.d.ts.map +1 -0
  445. package/dist/lib/provider-add.js +219 -0
  446. package/dist/lib/provider-add.js.map +1 -0
  447. package/dist/lib/provider-availability.d.ts +13 -0
  448. package/dist/lib/provider-availability.d.ts.map +1 -0
  449. package/dist/lib/provider-availability.js +20 -0
  450. package/dist/lib/provider-availability.js.map +1 -0
  451. package/dist/lib/provider-metadata.d.ts +32 -0
  452. package/dist/lib/provider-metadata.d.ts.map +1 -0
  453. package/dist/lib/provider-metadata.js +90 -0
  454. package/dist/lib/provider-metadata.js.map +1 -0
  455. package/dist/lib/provider-model-matching.d.ts +12 -0
  456. package/dist/lib/provider-model-matching.d.ts.map +1 -0
  457. package/dist/lib/provider-model-matching.js +23 -0
  458. package/dist/lib/provider-model-matching.js.map +1 -0
  459. package/dist/lib/provider-registration.d.ts +321 -0
  460. package/dist/lib/provider-registration.d.ts.map +1 -0
  461. package/dist/lib/provider-registration.js +335 -0
  462. package/dist/lib/provider-registration.js.map +1 -0
  463. package/dist/lib/quota-accounting-projection.d.ts +9 -0
  464. package/dist/lib/quota-accounting-projection.d.ts.map +1 -0
  465. package/dist/lib/quota-accounting-projection.js +254 -0
  466. package/dist/lib/quota-accounting-projection.js.map +1 -0
  467. package/dist/lib/quota-columns.d.ts +38 -0
  468. package/dist/lib/quota-columns.d.ts.map +1 -0
  469. package/dist/lib/quota-columns.js +129 -0
  470. package/dist/lib/quota-columns.js.map +1 -0
  471. package/dist/lib/quota-command-format.d.ts +34 -0
  472. package/dist/lib/quota-command-format.d.ts.map +1 -0
  473. package/dist/lib/quota-command-format.js +240 -0
  474. package/dist/lib/quota-command-format.js.map +1 -0
  475. package/dist/lib/quota-dialog-command-specs.d.ts +63 -0
  476. package/dist/lib/quota-dialog-command-specs.d.ts.map +1 -0
  477. package/dist/lib/quota-dialog-command-specs.js +145 -0
  478. package/dist/lib/quota-dialog-command-specs.js.map +1 -0
  479. package/dist/lib/quota-dialog-commands.d.ts +75 -0
  480. package/dist/lib/quota-dialog-commands.d.ts.map +1 -0
  481. package/dist/lib/quota-dialog-commands.js +586 -0
  482. package/dist/lib/quota-dialog-commands.js.map +1 -0
  483. package/dist/lib/quota-entry-display.d.ts +7 -0
  484. package/dist/lib/quota-entry-display.d.ts.map +1 -0
  485. package/dist/lib/quota-entry-display.js +59 -0
  486. package/dist/lib/quota-entry-display.js.map +1 -0
  487. package/dist/lib/quota-exhaustion-projection.d.ts +11 -0
  488. package/dist/lib/quota-exhaustion-projection.d.ts.map +1 -0
  489. package/dist/lib/quota-exhaustion-projection.js +105 -0
  490. package/dist/lib/quota-exhaustion-projection.js.map +1 -0
  491. package/dist/lib/quota-export-types.d.ts +96 -0
  492. package/dist/lib/quota-export-types.d.ts.map +1 -0
  493. package/dist/lib/quota-export-types.js +2 -0
  494. package/dist/lib/quota-export-types.js.map +1 -0
  495. package/dist/lib/quota-export.d.ts +44 -0
  496. package/dist/lib/quota-export.d.ts.map +1 -0
  497. package/dist/lib/quota-export.js +221 -0
  498. package/dist/lib/quota-export.js.map +1 -0
  499. package/dist/lib/quota-format-style.d.ts +21 -0
  500. package/dist/lib/quota-format-style.d.ts.map +1 -0
  501. package/dist/lib/quota-format-style.js +38 -0
  502. package/dist/lib/quota-format-style.js.map +1 -0
  503. package/dist/lib/quota-providers-local.d.ts +55 -0
  504. package/dist/lib/quota-providers-local.d.ts.map +1 -0
  505. package/dist/lib/quota-providers-local.js +327 -0
  506. package/dist/lib/quota-providers-local.js.map +1 -0
  507. package/dist/lib/quota-providers-remote.d.ts +27 -0
  508. package/dist/lib/quota-providers-remote.d.ts.map +1 -0
  509. package/dist/lib/quota-providers-remote.js +678 -0
  510. package/dist/lib/quota-providers-remote.js.map +1 -0
  511. package/dist/lib/quota-providers.d.ts +158 -0
  512. package/dist/lib/quota-providers.d.ts.map +1 -0
  513. package/dist/lib/quota-providers.js +1160 -0
  514. package/dist/lib/quota-providers.js.map +1 -0
  515. package/dist/lib/quota-render-data.d.ts +135 -0
  516. package/dist/lib/quota-render-data.d.ts.map +1 -0
  517. package/dist/lib/quota-render-data.js +462 -0
  518. package/dist/lib/quota-render-data.js.map +1 -0
  519. package/dist/lib/quota-report-message.d.ts +22 -0
  520. package/dist/lib/quota-report-message.d.ts.map +1 -0
  521. package/dist/lib/quota-report-message.js +36 -0
  522. package/dist/lib/quota-report-message.js.map +1 -0
  523. package/dist/lib/quota-reset-notifications.d.ts +20 -0
  524. package/dist/lib/quota-reset-notifications.d.ts.map +1 -0
  525. package/dist/lib/quota-reset-notifications.js +331 -0
  526. package/dist/lib/quota-reset-notifications.js.map +1 -0
  527. package/dist/lib/quota-retry-wait.d.ts +36 -0
  528. package/dist/lib/quota-retry-wait.d.ts.map +1 -0
  529. package/dist/lib/quota-retry-wait.js +67 -0
  530. package/dist/lib/quota-retry-wait.js.map +1 -0
  531. package/dist/lib/quota-runtime-context.d.ts +56 -0
  532. package/dist/lib/quota-runtime-context.d.ts.map +1 -0
  533. package/dist/lib/quota-runtime-context.js +113 -0
  534. package/dist/lib/quota-runtime-context.js.map +1 -0
  535. package/dist/lib/quota-state-codec.d.ts +16 -0
  536. package/dist/lib/quota-state-codec.d.ts.map +1 -0
  537. package/dist/lib/quota-state-codec.js +475 -0
  538. package/dist/lib/quota-state-codec.js.map +1 -0
  539. package/dist/lib/quota-state.d.ts +28 -0
  540. package/dist/lib/quota-state.d.ts.map +1 -0
  541. package/dist/lib/quota-state.js +473 -0
  542. package/dist/lib/quota-state.js.map +1 -0
  543. package/dist/lib/quota-stats-format.d.ts +29 -0
  544. package/dist/lib/quota-stats-format.d.ts.map +1 -0
  545. package/dist/lib/quota-stats-format.js +459 -0
  546. package/dist/lib/quota-stats-format.js.map +1 -0
  547. package/dist/lib/quota-stats.d.ts +174 -0
  548. package/dist/lib/quota-stats.d.ts.map +1 -0
  549. package/dist/lib/quota-stats.js +713 -0
  550. package/dist/lib/quota-stats.js.map +1 -0
  551. package/dist/lib/quota-status.d.ts +58 -0
  552. package/dist/lib/quota-status.d.ts.map +1 -0
  553. package/dist/lib/quota-status.js +865 -0
  554. package/dist/lib/quota-status.js.map +1 -0
  555. package/dist/lib/quota-surface-data.d.ts +21 -0
  556. package/dist/lib/quota-surface-data.d.ts.map +1 -0
  557. package/dist/lib/quota-surface-data.js +361 -0
  558. package/dist/lib/quota-surface-data.js.map +1 -0
  559. package/dist/lib/quota-telemetry.d.ts +45 -0
  560. package/dist/lib/quota-telemetry.d.ts.map +1 -0
  561. package/dist/lib/quota-telemetry.js +304 -0
  562. package/dist/lib/quota-telemetry.js.map +1 -0
  563. package/dist/lib/report-document.d.ts +90 -0
  564. package/dist/lib/report-document.d.ts.map +1 -0
  565. package/dist/lib/report-document.js +190 -0
  566. package/dist/lib/report-document.js.map +1 -0
  567. package/dist/lib/resolved-auth-identity.d.ts +36 -0
  568. package/dist/lib/resolved-auth-identity.d.ts.map +1 -0
  569. package/dist/lib/resolved-auth-identity.js +192 -0
  570. package/dist/lib/resolved-auth-identity.js.map +1 -0
  571. package/dist/lib/runtime-provider-ids.d.ts +4 -0
  572. package/dist/lib/runtime-provider-ids.d.ts.map +1 -0
  573. package/dist/lib/runtime-provider-ids.js +10 -0
  574. package/dist/lib/runtime-provider-ids.js.map +1 -0
  575. package/dist/lib/scoped-update-migration.d.ts +103 -0
  576. package/dist/lib/scoped-update-migration.d.ts.map +1 -0
  577. package/dist/lib/scoped-update-migration.js +348 -0
  578. package/dist/lib/scoped-update-migration.js.map +1 -0
  579. package/dist/lib/scoped-update.d.ts +78 -0
  580. package/dist/lib/scoped-update.d.ts.map +1 -0
  581. package/dist/lib/scoped-update.js +640 -0
  582. package/dist/lib/scoped-update.js.map +1 -0
  583. package/dist/lib/session-tokens-format.d.ts +36 -0
  584. package/dist/lib/session-tokens-format.d.ts.map +1 -0
  585. package/dist/lib/session-tokens-format.js +111 -0
  586. package/dist/lib/session-tokens-format.js.map +1 -0
  587. package/dist/lib/session-tokens.d.ts +27 -0
  588. package/dist/lib/session-tokens.d.ts.map +1 -0
  589. package/dist/lib/session-tokens.js +55 -0
  590. package/dist/lib/session-tokens.js.map +1 -0
  591. package/dist/lib/synthetic-config.d.ts +15 -0
  592. package/dist/lib/synthetic-config.d.ts.map +1 -0
  593. package/dist/lib/synthetic-config.js +28 -0
  594. package/dist/lib/synthetic-config.js.map +1 -0
  595. package/dist/lib/synthetic.d.ts +12 -0
  596. package/dist/lib/synthetic.d.ts.map +1 -0
  597. package/dist/lib/synthetic.js +173 -0
  598. package/dist/lib/synthetic.js.map +1 -0
  599. package/dist/lib/toast-format-grouped.d.ts +25 -0
  600. package/dist/lib/toast-format-grouped.d.ts.map +1 -0
  601. package/dist/lib/toast-format-grouped.js +296 -0
  602. package/dist/lib/toast-format-grouped.js.map +1 -0
  603. package/dist/lib/token-buckets.d.ts +24 -0
  604. package/dist/lib/token-buckets.d.ts.map +1 -0
  605. package/dist/lib/token-buckets.js +28 -0
  606. package/dist/lib/token-buckets.js.map +1 -0
  607. package/dist/lib/token-cost.d.ts +10 -0
  608. package/dist/lib/token-cost.d.ts.map +1 -0
  609. package/dist/lib/token-cost.js +16 -0
  610. package/dist/lib/token-cost.js.map +1 -0
  611. package/dist/lib/tui-compact-format.d.ts +10 -0
  612. package/dist/lib/tui-compact-format.d.ts.map +1 -0
  613. package/dist/lib/tui-compact-format.js +460 -0
  614. package/dist/lib/tui-compact-format.js.map +1 -0
  615. package/dist/lib/tui-panel-state.d.ts +15 -0
  616. package/dist/lib/tui-panel-state.d.ts.map +1 -0
  617. package/dist/lib/tui-panel-state.js +2 -0
  618. package/dist/lib/tui-panel-state.js.map +1 -0
  619. package/dist/lib/tui-prompt-bar-format.d.ts +25 -0
  620. package/dist/lib/tui-prompt-bar-format.d.ts.map +1 -0
  621. package/dist/lib/tui-prompt-bar-format.js +206 -0
  622. package/dist/lib/tui-prompt-bar-format.js.map +1 -0
  623. package/dist/lib/tui-sidebar-format.d.ts +13 -0
  624. package/dist/lib/tui-sidebar-format.d.ts.map +1 -0
  625. package/dist/lib/tui-sidebar-format.js +34 -0
  626. package/dist/lib/tui-sidebar-format.js.map +1 -0
  627. package/dist/lib/types.d.ts +724 -0
  628. package/dist/lib/types.d.ts.map +1 -0
  629. package/dist/lib/types.js +83 -0
  630. package/dist/lib/types.js.map +1 -0
  631. package/dist/lib/usage-ownership.d.ts +47 -0
  632. package/dist/lib/usage-ownership.d.ts.map +1 -0
  633. package/dist/lib/usage-ownership.js +98 -0
  634. package/dist/lib/usage-ownership.js.map +1 -0
  635. package/dist/lib/version.d.ts +2 -0
  636. package/dist/lib/version.d.ts.map +1 -0
  637. package/dist/lib/version.js +33 -0
  638. package/dist/lib/version.js.map +1 -0
  639. package/dist/lib/xai.d.ts +52 -0
  640. package/dist/lib/xai.d.ts.map +1 -0
  641. package/dist/lib/xai.js +253 -0
  642. package/dist/lib/xai.js.map +1 -0
  643. package/dist/lib/zai-auth.d.ts +15 -0
  644. package/dist/lib/zai-auth.d.ts.map +1 -0
  645. package/dist/lib/zai-auth.js +37 -0
  646. package/dist/lib/zai-auth.js.map +1 -0
  647. package/dist/lib/zai.d.ts +5 -0
  648. package/dist/lib/zai.d.ts.map +1 -0
  649. package/dist/lib/zai.js +14 -0
  650. package/dist/lib/zai.js.map +1 -0
  651. package/dist/lib/zhipu-auth.d.ts +15 -0
  652. package/dist/lib/zhipu-auth.d.ts.map +1 -0
  653. package/dist/lib/zhipu-auth.js +42 -0
  654. package/dist/lib/zhipu-auth.js.map +1 -0
  655. package/dist/lib/zhipu.d.ts +5 -0
  656. package/dist/lib/zhipu.d.ts.map +1 -0
  657. package/dist/lib/zhipu.js +13 -0
  658. package/dist/lib/zhipu.js.map +1 -0
  659. package/dist/plugin.d.ts +10 -0
  660. package/dist/plugin.d.ts.map +1 -0
  661. package/dist/plugin.js +95 -0
  662. package/dist/plugin.js.map +1 -0
  663. package/dist/providers/accounting-decimal.d.ts +2 -0
  664. package/dist/providers/accounting-decimal.d.ts.map +1 -0
  665. package/dist/providers/accounting-decimal.js +23 -0
  666. package/dist/providers/accounting-decimal.js.map +1 -0
  667. package/dist/providers/alibaba-coding-plan.d.ts +3 -0
  668. package/dist/providers/alibaba-coding-plan.d.ts.map +1 -0
  669. package/dist/providers/alibaba-coding-plan.js +122 -0
  670. package/dist/providers/alibaba-coding-plan.js.map +1 -0
  671. package/dist/providers/alibaba-token-plan.d.ts +3 -0
  672. package/dist/providers/alibaba-token-plan.d.ts.map +1 -0
  673. package/dist/providers/alibaba-token-plan.js +90 -0
  674. package/dist/providers/alibaba-token-plan.js.map +1 -0
  675. package/dist/providers/anthropic.d.ts +9 -0
  676. package/dist/providers/anthropic.d.ts.map +1 -0
  677. package/dist/providers/anthropic.js +236 -0
  678. package/dist/providers/anthropic.js.map +1 -0
  679. package/dist/providers/cache-policies.d.ts +61 -0
  680. package/dist/providers/cache-policies.d.ts.map +1 -0
  681. package/dist/providers/cache-policies.js +210 -0
  682. package/dist/providers/cache-policies.js.map +1 -0
  683. package/dist/providers/chutes.d.ts +6 -0
  684. package/dist/providers/chutes.d.ts.map +1 -0
  685. package/dist/providers/chutes.js +50 -0
  686. package/dist/providers/chutes.js.map +1 -0
  687. package/dist/providers/copilot.d.ts +9 -0
  688. package/dist/providers/copilot.d.ts.map +1 -0
  689. package/dist/providers/copilot.js +323 -0
  690. package/dist/providers/copilot.js.map +1 -0
  691. package/dist/providers/cursor.d.ts +3 -0
  692. package/dist/providers/cursor.d.ts.map +1 -0
  693. package/dist/providers/cursor.js +182 -0
  694. package/dist/providers/cursor.js.map +1 -0
  695. package/dist/providers/deepseek.d.ts +9 -0
  696. package/dist/providers/deepseek.d.ts.map +1 -0
  697. package/dist/providers/deepseek.js +111 -0
  698. package/dist/providers/deepseek.js.map +1 -0
  699. package/dist/providers/glm-coding-plan-provider.d.ts +56 -0
  700. package/dist/providers/glm-coding-plan-provider.d.ts.map +1 -0
  701. package/dist/providers/glm-coding-plan-provider.js +146 -0
  702. package/dist/providers/glm-coding-plan-provider.js.map +1 -0
  703. package/dist/providers/google-account-format.d.ts +7 -0
  704. package/dist/providers/google-account-format.d.ts.map +1 -0
  705. package/dist/providers/google-account-format.js +52 -0
  706. package/dist/providers/google-account-format.js.map +1 -0
  707. package/dist/providers/google-agy.d.ts +17 -0
  708. package/dist/providers/google-agy.d.ts.map +1 -0
  709. package/dist/providers/google-agy.js +256 -0
  710. package/dist/providers/google-agy.js.map +1 -0
  711. package/dist/providers/google-gemini-cli.d.ts +17 -0
  712. package/dist/providers/google-gemini-cli.d.ts.map +1 -0
  713. package/dist/providers/google-gemini-cli.js +228 -0
  714. package/dist/providers/google-gemini-cli.js.map +1 -0
  715. package/dist/providers/kilo.d.ts +6 -0
  716. package/dist/providers/kilo.d.ts.map +1 -0
  717. package/dist/providers/kilo.js +145 -0
  718. package/dist/providers/kilo.js.map +1 -0
  719. package/dist/providers/kimi-code.d.ts +4 -0
  720. package/dist/providers/kimi-code.d.ts.map +1 -0
  721. package/dist/providers/kimi-code.js +175 -0
  722. package/dist/providers/kimi-code.js.map +1 -0
  723. package/dist/providers/mimo.d.ts +3 -0
  724. package/dist/providers/mimo.d.ts.map +1 -0
  725. package/dist/providers/mimo.js +149 -0
  726. package/dist/providers/mimo.js.map +1 -0
  727. package/dist/providers/minimax-coding-plan.d.ts +26 -0
  728. package/dist/providers/minimax-coding-plan.d.ts.map +1 -0
  729. package/dist/providers/minimax-coding-plan.js +391 -0
  730. package/dist/providers/minimax-coding-plan.js.map +1 -0
  731. package/dist/providers/nanogpt.d.ts +6 -0
  732. package/dist/providers/nanogpt.d.ts.map +1 -0
  733. package/dist/providers/nanogpt.js +160 -0
  734. package/dist/providers/nanogpt.js.map +1 -0
  735. package/dist/providers/ollama-cloud.d.ts +9 -0
  736. package/dist/providers/ollama-cloud.d.ts.map +1 -0
  737. package/dist/providers/ollama-cloud.js +129 -0
  738. package/dist/providers/ollama-cloud.js.map +1 -0
  739. package/dist/providers/openai.d.ts +6 -0
  740. package/dist/providers/openai.d.ts.map +1 -0
  741. package/dist/providers/openai.js +313 -0
  742. package/dist/providers/openai.js.map +1 -0
  743. package/dist/providers/opencode-go.d.ts +4 -0
  744. package/dist/providers/opencode-go.d.ts.map +1 -0
  745. package/dist/providers/opencode-go.js +294 -0
  746. package/dist/providers/opencode-go.js.map +1 -0
  747. package/dist/providers/opencode-zen.d.ts +3 -0
  748. package/dist/providers/opencode-zen.d.ts.map +1 -0
  749. package/dist/providers/opencode-zen.js +221 -0
  750. package/dist/providers/opencode-zen.js.map +1 -0
  751. package/dist/providers/openrouter.d.ts +6 -0
  752. package/dist/providers/openrouter.d.ts.map +1 -0
  753. package/dist/providers/openrouter.js +32 -0
  754. package/dist/providers/openrouter.js.map +1 -0
  755. package/dist/providers/quota-providers.d.ts +6 -0
  756. package/dist/providers/quota-providers.d.ts.map +1 -0
  757. package/dist/providers/quota-providers.js +287 -0
  758. package/dist/providers/quota-providers.js.map +1 -0
  759. package/dist/providers/registry.d.ts +9 -0
  760. package/dist/providers/registry.d.ts.map +1 -0
  761. package/dist/providers/registry.js +71 -0
  762. package/dist/providers/registry.js.map +1 -0
  763. package/dist/providers/result-helpers.d.ts +61 -0
  764. package/dist/providers/result-helpers.d.ts.map +1 -0
  765. package/dist/providers/result-helpers.js +117 -0
  766. package/dist/providers/result-helpers.js.map +1 -0
  767. package/dist/providers/synthetic.d.ts +6 -0
  768. package/dist/providers/synthetic.d.ts.map +1 -0
  769. package/dist/providers/synthetic.js +79 -0
  770. package/dist/providers/synthetic.js.map +1 -0
  771. package/dist/providers/xai.d.ts +6 -0
  772. package/dist/providers/xai.d.ts.map +1 -0
  773. package/dist/providers/xai.js +122 -0
  774. package/dist/providers/xai.js.map +1 -0
  775. package/dist/providers/zai.d.ts +2 -0
  776. package/dist/providers/zai.d.ts.map +1 -0
  777. package/dist/providers/zai.js +24 -0
  778. package/dist/providers/zai.js.map +1 -0
  779. package/dist/providers/zhipu.d.ts +2 -0
  780. package/dist/providers/zhipu.d.ts.map +1 -0
  781. package/dist/providers/zhipu.js +21 -0
  782. package/dist/providers/zhipu.js.map +1 -0
  783. package/dist/rpc.d.ts +72 -0
  784. package/dist/rpc.d.ts.map +1 -0
  785. package/dist/rpc.js +77 -0
  786. package/dist/rpc.js.map +1 -0
  787. package/dist/ui/assets/KaTeX_AMS-Regular-BQhdFMY1.woff2 +0 -0
  788. package/dist/ui/assets/KaTeX_AMS-Regular-DMm9YOAa.woff +0 -0
  789. package/dist/ui/assets/KaTeX_AMS-Regular-DRggAlZN.ttf +0 -0
  790. package/dist/ui/assets/KaTeX_Caligraphic-Bold-ATXxdsX0.ttf +0 -0
  791. package/dist/ui/assets/KaTeX_Caligraphic-Bold-BEiXGLvX.woff +0 -0
  792. package/dist/ui/assets/KaTeX_Caligraphic-Bold-Dq_IR9rO.woff2 +0 -0
  793. package/dist/ui/assets/KaTeX_Caligraphic-Regular-CTRA-rTL.woff +0 -0
  794. package/dist/ui/assets/KaTeX_Caligraphic-Regular-Di6jR-x-.woff2 +0 -0
  795. package/dist/ui/assets/KaTeX_Caligraphic-Regular-wX97UBjC.ttf +0 -0
  796. package/dist/ui/assets/KaTeX_Fraktur-Bold-BdnERNNW.ttf +0 -0
  797. package/dist/ui/assets/KaTeX_Fraktur-Bold-BsDP51OF.woff +0 -0
  798. package/dist/ui/assets/KaTeX_Fraktur-Bold-CL6g_b3V.woff2 +0 -0
  799. package/dist/ui/assets/KaTeX_Fraktur-Regular-CB_wures.ttf +0 -0
  800. package/dist/ui/assets/KaTeX_Fraktur-Regular-CTYiF6lA.woff2 +0 -0
  801. package/dist/ui/assets/KaTeX_Fraktur-Regular-Dxdc4cR9.woff +0 -0
  802. package/dist/ui/assets/KaTeX_Main-Bold-Cx986IdX.woff2 +0 -0
  803. package/dist/ui/assets/KaTeX_Main-Bold-Jm3AIy58.woff +0 -0
  804. package/dist/ui/assets/KaTeX_Main-Bold-waoOVXN0.ttf +0 -0
  805. package/dist/ui/assets/KaTeX_Main-BoldItalic-DxDJ3AOS.woff2 +0 -0
  806. package/dist/ui/assets/KaTeX_Main-BoldItalic-DzxPMmG6.ttf +0 -0
  807. package/dist/ui/assets/KaTeX_Main-BoldItalic-SpSLRI95.woff +0 -0
  808. package/dist/ui/assets/KaTeX_Main-Italic-3WenGoN9.ttf +0 -0
  809. package/dist/ui/assets/KaTeX_Main-Italic-BMLOBm91.woff +0 -0
  810. package/dist/ui/assets/KaTeX_Main-Italic-NWA7e6Wa.woff2 +0 -0
  811. package/dist/ui/assets/KaTeX_Main-Regular-B22Nviop.woff2 +0 -0
  812. package/dist/ui/assets/KaTeX_Main-Regular-Dr94JaBh.woff +0 -0
  813. package/dist/ui/assets/KaTeX_Main-Regular-ypZvNtVU.ttf +0 -0
  814. package/dist/ui/assets/KaTeX_Math-BoldItalic-B3XSjfu4.ttf +0 -0
  815. package/dist/ui/assets/KaTeX_Math-BoldItalic-CZnvNsCZ.woff2 +0 -0
  816. package/dist/ui/assets/KaTeX_Math-BoldItalic-iY-2wyZ7.woff +0 -0
  817. package/dist/ui/assets/KaTeX_Math-Italic-DA0__PXp.woff +0 -0
  818. package/dist/ui/assets/KaTeX_Math-Italic-flOr_0UB.ttf +0 -0
  819. package/dist/ui/assets/KaTeX_Math-Italic-t53AETM-.woff2 +0 -0
  820. package/dist/ui/assets/KaTeX_SansSerif-Bold-CFMepnvq.ttf +0 -0
  821. package/dist/ui/assets/KaTeX_SansSerif-Bold-D1sUS0GD.woff2 +0 -0
  822. package/dist/ui/assets/KaTeX_SansSerif-Bold-DbIhKOiC.woff +0 -0
  823. package/dist/ui/assets/KaTeX_SansSerif-Italic-C3H0VqGB.woff2 +0 -0
  824. package/dist/ui/assets/KaTeX_SansSerif-Italic-DN2j7dab.woff +0 -0
  825. package/dist/ui/assets/KaTeX_SansSerif-Italic-YYjJ1zSn.ttf +0 -0
  826. package/dist/ui/assets/KaTeX_SansSerif-Regular-BNo7hRIc.ttf +0 -0
  827. package/dist/ui/assets/KaTeX_SansSerif-Regular-CS6fqUqJ.woff +0 -0
  828. package/dist/ui/assets/KaTeX_SansSerif-Regular-DDBCnlJ7.woff2 +0 -0
  829. package/dist/ui/assets/KaTeX_Script-Regular-C5JkGWo-.ttf +0 -0
  830. package/dist/ui/assets/KaTeX_Script-Regular-D3wIWfF6.woff2 +0 -0
  831. package/dist/ui/assets/KaTeX_Script-Regular-D5yQViql.woff +0 -0
  832. package/dist/ui/assets/KaTeX_Size1-Regular-C195tn64.woff +0 -0
  833. package/dist/ui/assets/KaTeX_Size1-Regular-Dbsnue_I.ttf +0 -0
  834. package/dist/ui/assets/KaTeX_Size1-Regular-mCD8mA8B.woff2 +0 -0
  835. package/dist/ui/assets/KaTeX_Size2-Regular-B7gKUWhC.ttf +0 -0
  836. package/dist/ui/assets/KaTeX_Size2-Regular-Dy4dx90m.woff2 +0 -0
  837. package/dist/ui/assets/KaTeX_Size2-Regular-oD1tc_U0.woff +0 -0
  838. package/dist/ui/assets/KaTeX_Size3-Regular-CTq5MqoE.woff +0 -0
  839. package/dist/ui/assets/KaTeX_Size3-Regular-DgpXs0kz.ttf +0 -0
  840. package/dist/ui/assets/KaTeX_Size4-Regular-BF-4gkZK.woff +0 -0
  841. package/dist/ui/assets/KaTeX_Size4-Regular-DWFBv043.ttf +0 -0
  842. package/dist/ui/assets/KaTeX_Size4-Regular-Dl5lxZxV.woff2 +0 -0
  843. package/dist/ui/assets/KaTeX_Typewriter-Regular-C0xS9mPB.woff +0 -0
  844. package/dist/ui/assets/KaTeX_Typewriter-Regular-CO6r4hn1.woff2 +0 -0
  845. package/dist/ui/assets/KaTeX_Typewriter-Regular-D3Ib7_Hf.ttf +0 -0
  846. package/dist/ui/assets/index-BvKGj9wc.js +8 -0
  847. package/dist/ui/assets/index-wlxynmbV.css +1 -0
  848. package/dist/ui/index.html +13 -0
  849. package/package.json +123 -3
@@ -0,0 +1,1111 @@
1
+ /**
2
+ * GitHub Copilot accounting fetcher.
3
+ *
4
+ * Current usage is read from GitHub's public AI Credit billing reports.
5
+ * Legacy premium-request reports are available only when explicitly selected
6
+ * for an eligible Copilot Pro or Pro+ annual plan.
7
+ */
8
+ import { existsSync, readFileSync } from "fs";
9
+ import { join } from "path";
10
+ import { sanitizeDisplaySnippet, sanitizeDisplayText } from "./display-sanitize.js";
11
+ import { fetchWithTimeout } from "./http.js";
12
+ import { readAuthFile } from "./opencode-auth.js";
13
+ import { getOpencodeRuntimeDirs } from "./opencode-runtime-paths.js";
14
+ import { deriveResolvedAuthIdentity } from "./resolved-auth-identity.js";
15
+ const GITHUB_API_BASE_URL = "https://api.github.com";
16
+ const GITHUB_API_VERSION = "2026-03-10";
17
+ const COPILOT_QUOTA_CONFIG_FILENAME = "copilot-quota-token.json";
18
+ const USER_AGENT = "opencode-quota-gui/copilot-billing";
19
+ const COPILOT_INTERNAL_USER_PATH = "/copilot_internal/user";
20
+ /** Integration ids that can hold the Copilot OAuth login, in precedence order. */
21
+ export const COPILOT_AUTH_KEYS = [
22
+ "github-copilot",
23
+ "copilot",
24
+ "copilot-chat",
25
+ "github-copilot-chat",
26
+ ];
27
+ const LEGACY_PREMIUM_REQUEST_TOTALS = {
28
+ pro: 300,
29
+ "pro+": 1500,
30
+ };
31
+ function validateEnterpriseHost(value) {
32
+ if (value === undefined || value === null)
33
+ return {};
34
+ if (typeof value !== "string" || !value.trim()) {
35
+ return { error: "enterpriseUrl must be a non-empty string when provided" };
36
+ }
37
+ const raw = value.trim();
38
+ const invalid = {
39
+ error: "enterpriseUrl must be a hostname or host-only HTTPS URL ending in .ghe.com (without api. prefix, port, path, query, fragment, or userinfo)",
40
+ };
41
+ if (!/^[\x21-\x7e]+$/.test(raw) || raw.includes("*"))
42
+ return invalid;
43
+ let host;
44
+ if (raw.includes("://")) {
45
+ const authority = raw.slice(raw.indexOf("//") + 2).split(/[/?#]/u, 1)[0] ?? "";
46
+ if (authority.includes(":"))
47
+ return invalid;
48
+ let url;
49
+ try {
50
+ url = new URL(raw);
51
+ }
52
+ catch {
53
+ return invalid;
54
+ }
55
+ if (url.protocol !== "https:" ||
56
+ url.username ||
57
+ url.password ||
58
+ url.port ||
59
+ (url.pathname !== "" && url.pathname !== "/") ||
60
+ url.search ||
61
+ url.hash) {
62
+ return invalid;
63
+ }
64
+ host = url.hostname.toLowerCase();
65
+ }
66
+ else {
67
+ if (/[/:@?#]/.test(raw))
68
+ return invalid;
69
+ host = raw.toLowerCase();
70
+ }
71
+ if (host.length > 253 || host.startsWith("api.") || !host.endsWith(".ghe.com")) {
72
+ return invalid;
73
+ }
74
+ const labels = host.split(".");
75
+ if (labels.some((label) => label.length === 0 || label.length > 63 || !/^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/.test(label))) {
76
+ return invalid;
77
+ }
78
+ return { host };
79
+ }
80
+ function getApiBaseUrl(enterpriseHost) {
81
+ return enterpriseHost ? `https://api.${enterpriseHost}` : GITHUB_API_BASE_URL;
82
+ }
83
+ function getApiHost(apiBaseUrl) {
84
+ return new URL(apiBaseUrl).hostname;
85
+ }
86
+ function classifyPatTokenKind(token) {
87
+ if (token.startsWith("github_pat_"))
88
+ return "github_pat";
89
+ if (token.startsWith("ghp_"))
90
+ return "ghp";
91
+ if (token.startsWith("ghu_"))
92
+ return "ghu";
93
+ if (token.startsWith("ghs_"))
94
+ return "ghs";
95
+ return "other";
96
+ }
97
+ function getCurrentBillingPeriod(now = new Date()) {
98
+ return {
99
+ year: now.getUTCFullYear(),
100
+ month: now.getUTCMonth() + 1,
101
+ };
102
+ }
103
+ function getApproxNextResetIso(nowMs = Date.now()) {
104
+ const now = new Date(nowMs);
105
+ return new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth() + 1, 1)).toISOString();
106
+ }
107
+ function formatBillingPeriod(period) {
108
+ return `${period.year}-${String(period.month).padStart(2, "0")}`;
109
+ }
110
+ function computePercentRemainingFromUsed(used, total) {
111
+ if (!Number.isFinite(used) || used < 0 || !Number.isFinite(total) || total <= 0) {
112
+ return undefined;
113
+ }
114
+ return Math.max(0, Math.min(100, Math.floor(((total - used) * 100) / total)));
115
+ }
116
+ function resolvePatBillingTarget(config) {
117
+ const billingPeriod = getCurrentBillingPeriod();
118
+ if (config.billingModel === "legacy_premium_requests") {
119
+ if (config.tier !== "pro" && config.tier !== "pro+") {
120
+ return {
121
+ target: null,
122
+ error: "Legacy premium-request billing is only available to Copilot Pro or Pro+ subscribers on an existing annual plan that remained on legacy billing after June 1, 2026.",
123
+ };
124
+ }
125
+ if (config.organization || config.enterprise) {
126
+ return {
127
+ target: null,
128
+ error: "Legacy premium-request billing is personal-only. Remove organization and enterprise from copilot-quota-token.json.",
129
+ };
130
+ }
131
+ }
132
+ if (config.tier === "business") {
133
+ if (!config.organization || config.enterprise) {
134
+ return {
135
+ target: null,
136
+ error: 'Copilot Business AI Credit usage requires "organization" and does not accept "enterprise" in copilot-quota-token.json.',
137
+ };
138
+ }
139
+ return {
140
+ target: {
141
+ scope: "organization",
142
+ organization: config.organization,
143
+ username: config.username,
144
+ billingPeriod,
145
+ },
146
+ };
147
+ }
148
+ if (config.tier === "enterprise") {
149
+ if (config.enterprise) {
150
+ return {
151
+ target: {
152
+ scope: "enterprise",
153
+ enterprise: config.enterprise,
154
+ organization: config.organization,
155
+ username: config.username,
156
+ billingPeriod,
157
+ },
158
+ };
159
+ }
160
+ if (config.organization) {
161
+ return {
162
+ target: {
163
+ scope: "organization",
164
+ organization: config.organization,
165
+ username: config.username,
166
+ billingPeriod,
167
+ },
168
+ };
169
+ }
170
+ return {
171
+ target: null,
172
+ error: 'Copilot Enterprise AI Credit usage requires "enterprise" or "organization" in copilot-quota-token.json.',
173
+ };
174
+ }
175
+ if (config.organization || config.enterprise) {
176
+ return {
177
+ target: null,
178
+ error: `Copilot ${config.tier} AI Credit usage is personal. Remove organization and enterprise from copilot-quota-token.json.`,
179
+ };
180
+ }
181
+ return {
182
+ target: {
183
+ scope: "user",
184
+ username: config.username,
185
+ billingPeriod,
186
+ },
187
+ };
188
+ }
189
+ function validatePatTargetCompatibility(target, tokenKind) {
190
+ if (!tokenKind)
191
+ return null;
192
+ if (target.scope === "user" && tokenKind === "ghs") {
193
+ return ("GitHub's personal AI Credit report supports GitHub App user access tokens, " +
194
+ "but not GitHub App installation access tokens. Use a GitHub App user token, fine-grained PAT with Plan (read), or supported classic credential.");
195
+ }
196
+ if (target.scope === "enterprise" &&
197
+ (tokenKind === "github_pat" || tokenKind === "ghu" || tokenKind === "ghs")) {
198
+ return ("GitHub's enterprise billing reports do not support fine-grained PATs or GitHub App access tokens. " +
199
+ "Use a classic PAT held by an enterprise admin or billing manager.");
200
+ }
201
+ return null;
202
+ }
203
+ export function getCopilotPatConfigCandidatePaths() {
204
+ return [join(getOpencodeRuntimeDirs().configDir, COPILOT_QUOTA_CONFIG_FILENAME)];
205
+ }
206
+ function validateQuotaConfig(raw) {
207
+ if (!raw || typeof raw !== "object") {
208
+ return { config: null, error: "Config must be a JSON object" };
209
+ }
210
+ const obj = raw;
211
+ const token = typeof obj.token === "string" ? obj.token.trim() : "";
212
+ const tier = typeof obj.tier === "string" ? obj.tier.trim().toLowerCase() : "";
213
+ const billingModel = obj.billingModel === undefined
214
+ ? "ai_credits"
215
+ : typeof obj.billingModel === "string"
216
+ ? obj.billingModel.trim()
217
+ : "";
218
+ if (!token) {
219
+ return { config: null, error: "Missing required string field: token" };
220
+ }
221
+ const validTiers = [
222
+ "free",
223
+ "student",
224
+ "pro",
225
+ "pro+",
226
+ "max",
227
+ "business",
228
+ "enterprise",
229
+ ];
230
+ if (!validTiers.includes(tier)) {
231
+ return {
232
+ config: null,
233
+ error: "Invalid tier; expected one of: free, student, pro, pro+, max, business, enterprise",
234
+ };
235
+ }
236
+ if (billingModel !== "ai_credits" && billingModel !== "legacy_premium_requests") {
237
+ return {
238
+ config: null,
239
+ error: "Invalid billingModel; expected ai_credits or legacy_premium_requests",
240
+ };
241
+ }
242
+ const readOptionalString = (key) => {
243
+ const value = obj[key];
244
+ if (value == null)
245
+ return undefined;
246
+ if (typeof value !== "string" || !value.trim()) {
247
+ throw new Error(`${key} must be a non-empty string when provided`);
248
+ }
249
+ return value.trim();
250
+ };
251
+ try {
252
+ const enterpriseHost = validateEnterpriseHost(obj.enterpriseUrl);
253
+ if (enterpriseHost.error)
254
+ throw new Error(enterpriseHost.error);
255
+ const config = {
256
+ token,
257
+ tier: tier,
258
+ billingModel,
259
+ username: readOptionalString("username"),
260
+ organization: readOptionalString("organization"),
261
+ enterprise: readOptionalString("enterprise"),
262
+ enterpriseUrl: enterpriseHost.host,
263
+ };
264
+ const resolved = resolvePatBillingTarget(config);
265
+ if (!resolved.target) {
266
+ return { config: null, error: resolved.error };
267
+ }
268
+ return { config };
269
+ }
270
+ catch (error) {
271
+ return { config: null, error: error instanceof Error ? error.message : String(error) };
272
+ }
273
+ }
274
+ export function readQuotaConfigWithMeta() {
275
+ const checkedPaths = getCopilotPatConfigCandidatePaths();
276
+ for (const path of checkedPaths) {
277
+ if (!existsSync(path))
278
+ continue;
279
+ try {
280
+ const parsed = JSON.parse(readFileSync(path, "utf-8"));
281
+ const validated = validateQuotaConfig(parsed);
282
+ if (!validated.config) {
283
+ return {
284
+ state: "invalid",
285
+ checkedPaths,
286
+ selectedPath: path,
287
+ error: validated.error ?? "Invalid config",
288
+ };
289
+ }
290
+ return {
291
+ state: "valid",
292
+ checkedPaths,
293
+ selectedPath: path,
294
+ config: validated.config,
295
+ tokenKind: classifyPatTokenKind(validated.config.token),
296
+ };
297
+ }
298
+ catch (error) {
299
+ return {
300
+ state: "invalid",
301
+ checkedPaths,
302
+ selectedPath: path,
303
+ error: error instanceof Error ? error.message : String(error),
304
+ };
305
+ }
306
+ }
307
+ return { state: "absent", checkedPaths };
308
+ }
309
+ function getCopilotOAuthToken(auth) {
310
+ return auth?.access?.trim() || auth?.refresh?.trim() || null;
311
+ }
312
+ function selectCopilotAuth(authData) {
313
+ if (!authData)
314
+ return { auth: null, keyName: null };
315
+ const candidates = [
316
+ ["github-copilot", authData["github-copilot"]],
317
+ ["copilot", authData.copilot],
318
+ ["copilot-chat", authData["copilot-chat"]],
319
+ ["github-copilot-chat", authData["github-copilot-chat"]],
320
+ ];
321
+ for (const [keyName, auth] of candidates) {
322
+ if (!auth || auth.type !== "oauth")
323
+ continue;
324
+ // A login OpenCode could not return still counts, so it shows as an error.
325
+ if (!getCopilotOAuthToken(auth) && auth.resolveError === undefined)
326
+ continue;
327
+ return { auth, keyName };
328
+ }
329
+ return { auth: null, keyName: null };
330
+ }
331
+ function getRemainingTotalsState(target, config) {
332
+ if (!target || !config)
333
+ return "unavailable";
334
+ if (target.scope === "organization")
335
+ return "not_available_from_org_usage";
336
+ if (target.scope === "enterprise")
337
+ return "not_available_from_enterprise_usage";
338
+ if (config.billingModel !== "legacy_premium_requests") {
339
+ return "value_only_without_denominator";
340
+ }
341
+ return LEGACY_PREMIUM_REQUEST_TOTALS[config.tier]
342
+ ? "available"
343
+ : "value_only_without_denominator";
344
+ }
345
+ export function getCopilotQuotaAuthDiagnostics(authData) {
346
+ const pat = readQuotaConfigWithMeta();
347
+ const { auth, keyName } = selectCopilotAuth(authData);
348
+ const oauthEnterpriseHost = validateEnterpriseHost(auth?.enterpriseUrl);
349
+ const resolved = pat.state === "valid" && pat.config
350
+ ? resolvePatBillingTarget(pat.config)
351
+ : { target: null };
352
+ const compatibilityError = resolved.target && pat.state === "valid"
353
+ ? validatePatTargetCompatibility(resolved.target, pat.tokenKind)
354
+ : null;
355
+ const patBlocksOAuth = pat.state !== "absent";
356
+ const effectiveSource = patBlocksOAuth
357
+ ? "pat"
358
+ : auth
359
+ ? "oauth"
360
+ : "none";
361
+ const effectiveEnterpriseHost = effectiveSource === "pat"
362
+ ? pat.config?.enterpriseUrl
363
+ : effectiveSource === "oauth"
364
+ ? oauthEnterpriseHost.host
365
+ : undefined;
366
+ const enterpriseHostError = effectiveSource === "pat" && pat.error?.startsWith("enterpriseUrl")
367
+ ? pat.error
368
+ : effectiveSource === "oauth"
369
+ ? oauthEnterpriseHost.error
370
+ : undefined;
371
+ const deployment = effectiveSource === "none"
372
+ ? "none"
373
+ : enterpriseHostError
374
+ ? "invalid"
375
+ : effectiveEnterpriseHost
376
+ ? "ghe.com"
377
+ : effectiveSource === "pat" && pat.state !== "valid"
378
+ ? "none"
379
+ : "github.com";
380
+ const apiBaseUrl = deployment === "github.com" || deployment === "ghe.com"
381
+ ? getApiBaseUrl(effectiveEnterpriseHost)
382
+ : null;
383
+ const billingModel = pat.config?.billingModel ?? "ai_credits";
384
+ const oauthAvailable = effectiveSource === "oauth" && Boolean(auth) && !oauthEnterpriseHost.error;
385
+ const quotaApi = pat.state === "valid"
386
+ ? billingModel === "legacy_premium_requests"
387
+ ? "github_legacy_premium_request_api"
388
+ : "github_ai_credit_api"
389
+ : oauthAvailable
390
+ ? "copilot_internal_user"
391
+ : "none";
392
+ const billingMode = resolved.target?.scope === "organization"
393
+ ? "organization_usage"
394
+ : resolved.target?.scope === "enterprise"
395
+ ? "enterprise_usage"
396
+ : resolved.target?.scope === "user" || oauthAvailable
397
+ ? "user_quota"
398
+ : "none";
399
+ return {
400
+ pat,
401
+ oauth: {
402
+ configured: Boolean(auth),
403
+ keyName,
404
+ hasRefreshToken: Boolean(auth?.refresh?.trim()),
405
+ hasAccessToken: Boolean(auth?.access?.trim()),
406
+ hasEnterpriseUrl: auth?.enterpriseUrl !== undefined,
407
+ },
408
+ deployment,
409
+ apiHost: apiBaseUrl ? getApiHost(apiBaseUrl) : null,
410
+ enterpriseHostSource: effectiveSource === "pat" && pat.config?.enterpriseUrl
411
+ ? "pat"
412
+ : effectiveSource === "oauth" && oauthEnterpriseHost.host
413
+ ? "oauth"
414
+ : "none",
415
+ enterpriseHostError,
416
+ effectiveSource,
417
+ override: patBlocksOAuth && auth ? "pat_overrides_oauth" : "none",
418
+ quotaApi,
419
+ billingMode,
420
+ billingScope: resolved.target?.scope ?? (oauthAvailable ? "user" : "none"),
421
+ billingApiAccessLikely: oauthAvailable ||
422
+ (pat.state === "valid" && Boolean(resolved.target) && !resolved.error && !compatibilityError),
423
+ remainingTotalsState: oauthAvailable
424
+ ? "reported_by_copilot_internal_user"
425
+ : getRemainingTotalsState(resolved.target, pat.config),
426
+ queryPeriod: resolved.target?.billingPeriod,
427
+ usernameFilter: pat.config?.username,
428
+ billingTargetError: resolved.error,
429
+ tokenCompatibilityError: compatibilityError ?? undefined,
430
+ billingModel,
431
+ budgetApi: billingModel !== "ai_credits" || oauthAvailable
432
+ ? "not_available"
433
+ : resolved.target?.scope === "organization"
434
+ ? "organization_budgets"
435
+ : resolved.target?.scope === "enterprise"
436
+ ? "enterprise_budgets"
437
+ : "not_available",
438
+ oauthAccountingState: !auth
439
+ ? "not_configured"
440
+ : oauthEnterpriseHost.error
441
+ ? "invalid_enterprise_host"
442
+ : "available_via_copilot_internal_user",
443
+ };
444
+ }
445
+ function buildGitHubRestHeaders(token) {
446
+ return {
447
+ Accept: "application/vnd.github+json",
448
+ Authorization: `Bearer ${token}`,
449
+ "X-GitHub-Api-Version": GITHUB_API_VERSION,
450
+ "User-Agent": USER_AGENT,
451
+ };
452
+ }
453
+ function redactGitHubErrorText(text, secrets) {
454
+ let sanitized = sanitizeDisplayText(text);
455
+ for (const secret of secrets) {
456
+ if (!secret)
457
+ continue;
458
+ sanitized = sanitized.split(secret).join("[redacted]");
459
+ const sanitizedSecret = sanitizeDisplayText(secret);
460
+ if (sanitizedSecret) {
461
+ sanitized = sanitized.split(sanitizedSecret).join("[redacted]");
462
+ }
463
+ }
464
+ return sanitized;
465
+ }
466
+ async function readGitHubRestErrorMessage(response, secrets) {
467
+ const text = await response.text();
468
+ try {
469
+ const parsed = JSON.parse(text);
470
+ const message = typeof parsed.message === "string" ? parsed.message : null;
471
+ const documentationUrl = typeof parsed.documentation_url === "string" ? parsed.documentation_url : null;
472
+ if (message && documentationUrl) {
473
+ return redactGitHubErrorText(`${message} (${documentationUrl})`, secrets);
474
+ }
475
+ if (message)
476
+ return redactGitHubErrorText(message, secrets);
477
+ }
478
+ catch {
479
+ // Fall through to a bounded plain-text snippet.
480
+ }
481
+ return sanitizeDisplaySnippet(redactGitHubErrorText(text, secrets), 160);
482
+ }
483
+ async function fetchGitHubRestJson(url, token, requestTimeoutMs) {
484
+ return await fetchWithTimeout(url, {
485
+ request: { headers: buildGitHubRestHeaders(token) },
486
+ timeoutMs: requestTimeoutMs,
487
+ consume: async (response) => {
488
+ if (!response.ok) {
489
+ const message = await readGitHubRestErrorMessage(response, [token]);
490
+ const rateLimit = response.status === 403 && response.headers.get("x-ratelimit-remaining") === "0"
491
+ ? " (GitHub API rate limit exhausted)"
492
+ : "";
493
+ throw new Error(`GitHub API error ${response.status}: ${message}${rateLimit}`);
494
+ }
495
+ try {
496
+ return (await response.json());
497
+ }
498
+ catch {
499
+ throw new Error("GitHub API returned malformed JSON");
500
+ }
501
+ },
502
+ });
503
+ }
504
+ async function resolveGitHubUsername(apiBaseUrl, token, requestTimeoutMs) {
505
+ const response = await fetchGitHubRestJson(`${apiBaseUrl}/user`, token, requestTimeoutMs);
506
+ const login = response.login?.trim();
507
+ if (!login) {
508
+ throw new Error("GitHub /user response did not include a login");
509
+ }
510
+ return login;
511
+ }
512
+ function buildBillingQuery(target) {
513
+ const query = new URLSearchParams({
514
+ year: String(target.billingPeriod.year),
515
+ month: String(target.billingPeriod.month),
516
+ });
517
+ if (target.scope !== "user" && target.username)
518
+ query.set("user", target.username);
519
+ if (target.scope === "enterprise" && target.organization) {
520
+ query.set("organization", target.organization);
521
+ }
522
+ return query;
523
+ }
524
+ function getBillingUsageUrl(apiBaseUrl, target, billingModel) {
525
+ const report = billingModel === "legacy_premium_requests" ? "premium_request" : "ai_credit";
526
+ const query = buildBillingQuery(target);
527
+ if (target.scope === "enterprise") {
528
+ return `${apiBaseUrl}/enterprises/${encodeURIComponent(target.enterprise)}/settings/billing/${report}/usage?${query}`;
529
+ }
530
+ if (target.scope === "organization") {
531
+ return `${apiBaseUrl}/organizations/${encodeURIComponent(target.organization)}/settings/billing/${report}/usage?${query}`;
532
+ }
533
+ return `${apiBaseUrl}/users/${encodeURIComponent(target.username)}/settings/billing/${report}/usage?${query}`;
534
+ }
535
+ async function fetchBillingUsage(params) {
536
+ const target = params.target.scope === "user"
537
+ ? {
538
+ ...params.target,
539
+ username: params.target.username ??
540
+ (await resolveGitHubUsername(params.apiBaseUrl, params.token, params.requestTimeoutMs)),
541
+ }
542
+ : params.target;
543
+ return {
544
+ response: await fetchGitHubRestJson(getBillingUsageUrl(params.apiBaseUrl, target, params.billingModel), params.token, params.requestTimeoutMs),
545
+ target,
546
+ };
547
+ }
548
+ function getResponsePeriod(response, fallback) {
549
+ const period = response.timePeriod ?? response.time_period;
550
+ return {
551
+ year: typeof period?.year === "number" ? period.year : fallback.year,
552
+ month: typeof period?.month === "number" ? period.month : fallback.month,
553
+ };
554
+ }
555
+ function getUsageItems(response) {
556
+ if (Array.isArray(response.usageItems))
557
+ return response.usageItems;
558
+ if (Array.isArray(response.usage_items))
559
+ return response.usage_items;
560
+ throw new Error("GitHub billing response did not include a usageItems array");
561
+ }
562
+ function readFiniteNumber(value) {
563
+ return typeof value === "number" && Number.isFinite(value) ? value : undefined;
564
+ }
565
+ function quantitiesDiffer(left, right) {
566
+ return (Math.abs(left - right) > Number.EPSILON * 16 * Math.max(1, Math.abs(left), Math.abs(right)));
567
+ }
568
+ function isAiCreditItem(item) {
569
+ const text = [item.product, item.sku, item.unitType, item.unit_type]
570
+ .filter((value) => typeof value === "string")
571
+ .join(" ")
572
+ .toLowerCase();
573
+ const identifiesCopilot = text.includes("copilot");
574
+ const identifiesAiCredits = text.includes("ai credit") || text.includes("ai-credit");
575
+ return identifiesCopilot && identifiesAiCredits;
576
+ }
577
+ function isPremiumRequestItem(item) {
578
+ const text = [item.product, item.sku, item.unitType, item.unit_type]
579
+ .filter((value) => typeof value === "string")
580
+ .join(" ")
581
+ .toLowerCase();
582
+ return text.includes("premium request");
583
+ }
584
+ function parseAiCreditTotals(response) {
585
+ const items = getUsageItems(response);
586
+ const matches = items.filter(isAiCreditItem);
587
+ if (matches.length === 0 && items.length > 0) {
588
+ throw new Error("GitHub billing response did not contain a Copilot AI Credit usage item");
589
+ }
590
+ let used = 0;
591
+ let includedUsed = 0;
592
+ let billedUsed = 0;
593
+ let billedAmountUsd = 0;
594
+ let hasBilledAmount = false;
595
+ let authority = "provider_reported";
596
+ for (const item of matches) {
597
+ const gross = readFiniteNumber(item.grossQuantity ?? item.gross_quantity);
598
+ const discount = readFiniteNumber(item.discountQuantity ?? item.discount_quantity);
599
+ const net = readFiniteNumber(item.netQuantity ?? item.net_quantity);
600
+ const quantities = [gross, discount, net].filter((value) => value !== undefined);
601
+ if (quantities.length === 0) {
602
+ throw new Error("GitHub Copilot AI Credit usage item did not include quantity fields");
603
+ }
604
+ if (quantities.some((value) => value < 0)) {
605
+ throw new Error("GitHub Copilot AI Credit usage item contained a negative quantity");
606
+ }
607
+ if (gross !== undefined &&
608
+ discount !== undefined &&
609
+ net !== undefined &&
610
+ quantitiesDiffer(gross, discount + net)) {
611
+ throw new Error("GitHub Copilot AI Credit usage item contained inconsistent quantities");
612
+ }
613
+ let normalizedGross = gross;
614
+ let normalizedIncluded = discount;
615
+ let normalizedBilled = net;
616
+ if (gross !== undefined && discount !== undefined && net === undefined) {
617
+ if (discount > gross && quantitiesDiffer(gross, discount)) {
618
+ throw new Error("GitHub Copilot AI Credit usage item contained inconsistent quantities");
619
+ }
620
+ normalizedBilled = Math.max(0, gross - discount);
621
+ }
622
+ else if (gross !== undefined && discount === undefined && net !== undefined) {
623
+ if (net > gross && quantitiesDiffer(gross, net)) {
624
+ throw new Error("GitHub Copilot AI Credit usage item contained inconsistent quantities");
625
+ }
626
+ normalizedIncluded = Math.max(0, gross - net);
627
+ }
628
+ else if (gross === undefined && discount !== undefined && net !== undefined) {
629
+ normalizedGross = discount + net;
630
+ }
631
+ normalizedIncluded ??= 0;
632
+ normalizedBilled ??= Math.max(0, (normalizedGross ?? 0) - normalizedIncluded);
633
+ normalizedGross ??= normalizedIncluded + normalizedBilled;
634
+ used += normalizedGross;
635
+ includedUsed += normalizedIncluded;
636
+ billedUsed += normalizedBilled;
637
+ if (gross === undefined || discount === undefined || net === undefined) {
638
+ authority = "locally_derived";
639
+ }
640
+ const netAmount = readFiniteNumber(item.netAmount ?? item.net_amount);
641
+ if (netAmount !== undefined) {
642
+ if (netAmount < 0) {
643
+ throw new Error("GitHub Copilot AI Credit usage item contained a negative net amount");
644
+ }
645
+ billedAmountUsd += netAmount;
646
+ hasBilledAmount = true;
647
+ }
648
+ }
649
+ return {
650
+ used,
651
+ includedUsed,
652
+ billedUsed,
653
+ billedAmountUsd: hasBilledAmount ? billedAmountUsd : undefined,
654
+ authority,
655
+ };
656
+ }
657
+ function parseLegacyPremiumRequestUsage(response) {
658
+ const items = getUsageItems(response);
659
+ const matches = items.filter(isPremiumRequestItem);
660
+ if (matches.length === 0 && items.length > 0) {
661
+ throw new Error("GitHub billing response did not contain a premium-request usage item");
662
+ }
663
+ return matches.reduce((sum, item) => {
664
+ const gross = readFiniteNumber(item.grossQuantity ?? item.gross_quantity);
665
+ const net = readFiniteNumber(item.netQuantity ?? item.net_quantity);
666
+ if (gross === undefined && net === undefined) {
667
+ throw new Error("GitHub premium-request usage item did not include quantity fields");
668
+ }
669
+ return sum + Math.max(0, gross ?? net ?? 0);
670
+ }, 0);
671
+ }
672
+ function isAiCreditBudget(budget) {
673
+ const skus = [
674
+ budget.budget_product_sku,
675
+ ...(Array.isArray(budget.budget_product_skus) ? budget.budget_product_skus : []),
676
+ ]
677
+ .filter((value) => typeof value === "string")
678
+ .map((value) => value.toLowerCase());
679
+ return budget.budget_type === "BundlePricing" && skus.includes("ai_credits");
680
+ }
681
+ function budgetMatchesTarget(budget, target) {
682
+ const scope = budget.budget_scope;
683
+ const entity = budget.budget_entity_name?.toLowerCase();
684
+ const user = (budget.user ?? budget.budget_entity_name)?.toLowerCase();
685
+ if (target.scope === "organization") {
686
+ if (target.username && scope === "user") {
687
+ return !user || user === target.username.toLowerCase();
688
+ }
689
+ if (target.username && scope === "multi_user_customer")
690
+ return true;
691
+ return scope === "organization";
692
+ }
693
+ if (target.scope === "enterprise") {
694
+ if (target.username && scope === "user") {
695
+ return !user || user === target.username.toLowerCase();
696
+ }
697
+ if (target.username &&
698
+ (scope === "multi_user_customer" || scope === "multi_user_cost_center")) {
699
+ return true;
700
+ }
701
+ if (target.organization && scope === "organization") {
702
+ return !entity || entity === target.organization.toLowerCase();
703
+ }
704
+ return scope === "enterprise";
705
+ }
706
+ return false;
707
+ }
708
+ function budgetSpecificity(budget) {
709
+ switch (budget.budget_scope) {
710
+ case "user":
711
+ return 5;
712
+ case "multi_user_cost_center":
713
+ return 4;
714
+ case "multi_user_customer":
715
+ return 3;
716
+ case "organization":
717
+ return 2;
718
+ case "enterprise":
719
+ return 1;
720
+ default:
721
+ return 0;
722
+ }
723
+ }
724
+ function getBudgetsUrl(apiBaseUrl, target, page) {
725
+ const base = target.scope === "organization"
726
+ ? `${apiBaseUrl}/organizations/${encodeURIComponent(target.organization)}/settings/billing/budgets`
727
+ : `${apiBaseUrl}/enterprises/${encodeURIComponent(target.enterprise)}/settings/billing/budgets`;
728
+ const query = new URLSearchParams({ page: String(page), per_page: "100" });
729
+ if (target.username)
730
+ query.set("user", target.username);
731
+ return `${base}?${query}`;
732
+ }
733
+ async function fetchApplicableBudget(params) {
734
+ const budgets = [];
735
+ for (let page = 1; page <= 100; page += 1) {
736
+ const response = await fetchGitHubRestJson(getBudgetsUrl(params.apiBaseUrl, params.target, page), params.token, params.requestTimeoutMs);
737
+ if (!Array.isArray(response.budgets)) {
738
+ throw new Error("GitHub budgets response did not include a budgets array");
739
+ }
740
+ budgets.push(...response.budgets);
741
+ if (!response.has_next_page)
742
+ break;
743
+ if (page === 100) {
744
+ throw new Error("GitHub budgets response exceeded 100 pages");
745
+ }
746
+ }
747
+ const selected = budgets
748
+ .filter((budget) => isAiCreditBudget(budget) &&
749
+ budgetMatchesTarget(budget, params.target) &&
750
+ typeof budget.budget_amount === "number" &&
751
+ Number.isFinite(budget.budget_amount) &&
752
+ budget.budget_amount >= 0)
753
+ .sort((a, b) => budgetSpecificity(b) - budgetSpecificity(a))[0];
754
+ if (!selected || selected.budget_amount === undefined)
755
+ return undefined;
756
+ const percentRemaining = params.spentUsd === undefined
757
+ ? undefined
758
+ : computePercentRemainingFromUsed(params.spentUsd, selected.budget_amount);
759
+ return {
760
+ amountUsd: selected.budget_amount,
761
+ spentUsd: params.spentUsd,
762
+ scope: selected.budget_scope ?? "unknown",
763
+ percentRemaining,
764
+ authority: percentRemaining === undefined ? "provider_reported" : "locally_derived",
765
+ };
766
+ }
767
+ function makeBudgetWarning(error) {
768
+ const message = error instanceof Error ? error.message : String(error);
769
+ return `AI Credit usage loaded, but the budget report failed: ${message}`;
770
+ }
771
+ async function toAiCreditResult(params) {
772
+ const totals = parseAiCreditTotals(params.response);
773
+ const period = getResponsePeriod(params.response, params.target.billingPeriod);
774
+ let budget;
775
+ const warnings = [];
776
+ if (params.target.scope !== "user") {
777
+ try {
778
+ budget = await fetchApplicableBudget({
779
+ apiBaseUrl: params.apiBaseUrl,
780
+ token: params.token,
781
+ target: params.target,
782
+ spentUsd: totals.billedAmountUsd,
783
+ requestTimeoutMs: params.requestTimeoutMs,
784
+ });
785
+ }
786
+ catch (error) {
787
+ warnings.push(makeBudgetWarning(error));
788
+ }
789
+ }
790
+ if (params.target.scope === "organization") {
791
+ return {
792
+ success: true,
793
+ mode: "organization_usage",
794
+ organization: params.target.organization,
795
+ username: params.target.username,
796
+ period,
797
+ unit: "ai_credits",
798
+ ...totals,
799
+ budget,
800
+ warnings: warnings.length ? warnings : undefined,
801
+ };
802
+ }
803
+ if (params.target.scope === "enterprise") {
804
+ return {
805
+ success: true,
806
+ mode: "enterprise_usage",
807
+ enterprise: params.target.enterprise,
808
+ organization: params.target.organization,
809
+ username: params.target.username,
810
+ period,
811
+ unit: "ai_credits",
812
+ ...totals,
813
+ budget,
814
+ warnings: warnings.length ? warnings : undefined,
815
+ };
816
+ }
817
+ return {
818
+ success: true,
819
+ mode: "user_quota",
820
+ unit: "ai_credits",
821
+ period,
822
+ ...totals,
823
+ };
824
+ }
825
+ function toLegacyResult(response, config) {
826
+ const used = parseLegacyPremiumRequestUsage(response);
827
+ const total = LEGACY_PREMIUM_REQUEST_TOTALS[config.tier];
828
+ return {
829
+ success: true,
830
+ mode: "user_quota",
831
+ unit: "premium_requests",
832
+ used,
833
+ authority: "locally_derived",
834
+ total,
835
+ percentRemaining: total ? computePercentRemainingFromUsed(used, total) : undefined,
836
+ plan: config.tier,
837
+ resetTimeIso: getApproxNextResetIso(),
838
+ };
839
+ }
840
+ function toQuotaError(message) {
841
+ return { success: false, error: message };
842
+ }
843
+ function buildCopilotInternalHeaders(token) {
844
+ return {
845
+ Accept: "application/json",
846
+ Authorization: `token ${token}`,
847
+ "Editor-Version": "vscode/1.96.2",
848
+ "Editor-Plugin-Version": "copilot-chat/0.26.7",
849
+ "User-Agent": "GitHubCopilotChat/0.26.7",
850
+ "X-GitHub-Api-Version": "2025-04-01",
851
+ };
852
+ }
853
+ function normalizeCopilotPlan(value) {
854
+ if (typeof value !== "string")
855
+ return undefined;
856
+ const plan = sanitizeDisplayText(value).replace(/\s+/gu, " ").trim().slice(0, 64);
857
+ return plan || undefined;
858
+ }
859
+ function normalizeResetTime(value) {
860
+ if (typeof value !== "string" || !value.trim())
861
+ return undefined;
862
+ const timestamp = Date.parse(value);
863
+ return Number.isFinite(timestamp) ? new Date(timestamp).toISOString() : undefined;
864
+ }
865
+ function parseCopilotInternalUser(response) {
866
+ const plan = normalizeCopilotPlan(response.copilot_plan);
867
+ const resetTimeIso = normalizeResetTime(response.quota_reset_date_utc ?? response.quota_reset_date);
868
+ const snapshot = response.quota_snapshots?.premium_interactions;
869
+ const entitlement = readFiniteNumber(snapshot?.entitlement);
870
+ const remaining = readFiniteNumber(snapshot?.quota_remaining ?? snapshot?.remaining);
871
+ const reportedPercentRemaining = readFiniteNumber(snapshot?.percent_remaining);
872
+ const hasPercentRemaining = snapshot?.percent_remaining !== undefined;
873
+ const hasReportedPercent = reportedPercentRemaining !== undefined &&
874
+ reportedPercentRemaining >= 0 &&
875
+ reportedPercentRemaining <= 100;
876
+ const tokenBasedBilling = response.token_based_billing === true;
877
+ const isPlaceholder = tokenBasedBilling &&
878
+ (!snapshot ||
879
+ (snapshot.unlimited !== true &&
880
+ entitlement === 0 &&
881
+ remaining === 0 &&
882
+ (!hasReportedPercent || reportedPercentRemaining === 0)));
883
+ if (isPlaceholder) {
884
+ return {
885
+ success: true,
886
+ mode: "user_plan",
887
+ authority: "provider_reported",
888
+ plan,
889
+ resetTimeIso,
890
+ };
891
+ }
892
+ if (snapshot?.unlimited === true) {
893
+ return {
894
+ success: true,
895
+ mode: "user_quota",
896
+ unit: "premium_interactions",
897
+ used: 0,
898
+ authority: "provider_reported",
899
+ unlimited: true,
900
+ plan,
901
+ resetTimeIso,
902
+ };
903
+ }
904
+ if (entitlement !== undefined &&
905
+ entitlement > 0 &&
906
+ remaining !== undefined &&
907
+ remaining >= 0 &&
908
+ remaining <= entitlement) {
909
+ return {
910
+ success: true,
911
+ mode: "user_quota",
912
+ unit: "premium_interactions",
913
+ used: entitlement - remaining,
914
+ authority: "locally_derived",
915
+ total: entitlement,
916
+ percentRemaining: hasReportedPercent
917
+ ? reportedPercentRemaining
918
+ : !hasPercentRemaining
919
+ ? Math.min(100, Math.max(0, (remaining / entitlement) * 100))
920
+ : undefined,
921
+ plan,
922
+ resetTimeIso,
923
+ };
924
+ }
925
+ // Token-based billing reports a negative remaining once usage goes over the
926
+ // entitlement, alongside a provider-reported clamp in [0, 100].
927
+ const creditsUsed = readFiniteNumber(snapshot?.credits_used);
928
+ const hasValidCreditsUsed = creditsUsed !== undefined && creditsUsed >= 0;
929
+ if (tokenBasedBilling &&
930
+ entitlement !== undefined &&
931
+ entitlement > 0 &&
932
+ remaining !== undefined &&
933
+ remaining < 0 &&
934
+ hasReportedPercent) {
935
+ return {
936
+ success: true,
937
+ mode: "user_quota",
938
+ unit: hasValidCreditsUsed ? "ai_credits" : "premium_interactions",
939
+ used: hasValidCreditsUsed ? creditsUsed : entitlement - remaining,
940
+ authority: hasValidCreditsUsed ? "provider_reported" : "locally_derived",
941
+ total: entitlement,
942
+ percentRemaining: reportedPercentRemaining,
943
+ plan,
944
+ resetTimeIso,
945
+ };
946
+ }
947
+ if (response.token_based_billing === true) {
948
+ return {
949
+ success: true,
950
+ mode: "user_plan",
951
+ authority: "provider_reported",
952
+ plan,
953
+ resetTimeIso,
954
+ };
955
+ }
956
+ throw new Error("GitHub Copilot user response did not include a usable quota snapshot");
957
+ }
958
+ async function fetchCopilotInternalUser(params) {
959
+ return await fetchWithTimeout(`${params.apiBaseUrl}${COPILOT_INTERNAL_USER_PATH}`, {
960
+ request: { headers: buildCopilotInternalHeaders(params.token) },
961
+ timeoutMs: params.requestTimeoutMs,
962
+ consume: async (response) => {
963
+ if (!response.ok) {
964
+ const message = await readGitHubRestErrorMessage(response, [params.token]);
965
+ throw new Error(`GitHub Copilot API error ${response.status}: ${message}`);
966
+ }
967
+ let parsed;
968
+ try {
969
+ parsed = (await response.json());
970
+ }
971
+ catch {
972
+ throw new Error("GitHub Copilot API returned malformed JSON");
973
+ }
974
+ if (!parsed || typeof parsed !== "object") {
975
+ throw new Error("GitHub Copilot API returned malformed JSON");
976
+ }
977
+ return parseCopilotInternalUser(parsed);
978
+ },
979
+ });
980
+ }
981
+ /**
982
+ * Query GitHub Copilot accounting.
983
+ *
984
+ * A trusted local PAT config remains authoritative. When it is absent, the
985
+ * OpenCode-managed Copilot OAuth token can query the per-user internal quota endpoint.
986
+ */
987
+ export async function queryCopilotQuota(options = {}) {
988
+ const pat = readQuotaConfigWithMeta();
989
+ if (pat.state === "invalid") {
990
+ return toQuotaError(`Invalid copilot-quota-token.json: ${pat.error ?? "unknown error"}${pat.selectedPath ? ` (${pat.selectedPath})` : ""}`);
991
+ }
992
+ if (pat.state === "absent" || !pat.config) {
993
+ const { auth } = selectCopilotAuth(options.authData ?? (await readAuthFile({ integrationIds: COPILOT_AUTH_KEYS })));
994
+ if (auth?.resolveError !== undefined) {
995
+ return toQuotaError(`Copilot sign-in could not be read: ${auth.resolveError}. Run \`opencode auth login github-copilot\`.`);
996
+ }
997
+ const token = getCopilotOAuthToken(auth);
998
+ if (!auth || !token)
999
+ return null;
1000
+ const enterpriseHost = validateEnterpriseHost(auth.enterpriseUrl);
1001
+ if (enterpriseHost.error) {
1002
+ return toQuotaError(`Invalid OpenCode Copilot enterpriseUrl: ${enterpriseHost.error}`);
1003
+ }
1004
+ try {
1005
+ return await fetchCopilotInternalUser({
1006
+ apiBaseUrl: getApiBaseUrl(enterpriseHost.host),
1007
+ token,
1008
+ requestTimeoutMs: options.requestTimeoutMs,
1009
+ });
1010
+ }
1011
+ catch (error) {
1012
+ return toQuotaError(error instanceof Error ? error.message : String(error));
1013
+ }
1014
+ }
1015
+ const resolved = resolvePatBillingTarget(pat.config);
1016
+ if (!resolved.target) {
1017
+ return toQuotaError(resolved.error ?? "Unable to resolve Copilot billing scope.");
1018
+ }
1019
+ const compatibilityError = validatePatTargetCompatibility(resolved.target, pat.tokenKind);
1020
+ if (compatibilityError)
1021
+ return toQuotaError(compatibilityError);
1022
+ try {
1023
+ const billingModel = pat.config.billingModel ?? "ai_credits";
1024
+ const apiBaseUrl = getApiBaseUrl(pat.config.enterpriseUrl);
1025
+ const { response, target } = await fetchBillingUsage({
1026
+ apiBaseUrl,
1027
+ token: pat.config.token,
1028
+ target: resolved.target,
1029
+ billingModel,
1030
+ requestTimeoutMs: options.requestTimeoutMs,
1031
+ });
1032
+ return billingModel === "legacy_premium_requests"
1033
+ ? toLegacyResult(response, pat.config)
1034
+ : await toAiCreditResult({
1035
+ apiBaseUrl,
1036
+ response,
1037
+ target,
1038
+ token: pat.config.token,
1039
+ requestTimeoutMs: options.requestTimeoutMs,
1040
+ });
1041
+ }
1042
+ catch (error) {
1043
+ return toQuotaError(error instanceof Error ? error.message : String(error));
1044
+ }
1045
+ }
1046
+ export async function resolveCopilotAuthIdentity() {
1047
+ const pat = readQuotaConfigWithMeta();
1048
+ if (pat.state === "invalid")
1049
+ return null;
1050
+ if (pat.state === "valid" && pat.config) {
1051
+ const resolved = resolvePatBillingTarget(pat.config);
1052
+ if (!resolved.target || validatePatTargetCompatibility(resolved.target, pat.tokenKind)) {
1053
+ return null;
1054
+ }
1055
+ return deriveResolvedAuthIdentity({
1056
+ providerId: "copilot:pat",
1057
+ principal: { kind: "credential", value: pat.config.token },
1058
+ qualifiers: [
1059
+ `api=${getApiBaseUrl(pat.config.enterpriseUrl)}`,
1060
+ `billingModel=${pat.config.billingModel ?? "ai_credits"}`,
1061
+ `tier=${pat.config.tier}`,
1062
+ `scope=${resolved.target.scope}`,
1063
+ `username=${resolved.target.username ?? ""}`,
1064
+ `organization=${"organization" in resolved.target ? resolved.target.organization : ""}`,
1065
+ `enterprise=${"enterprise" in resolved.target ? resolved.target.enterprise : ""}`,
1066
+ `period=${formatBillingPeriod(resolved.target.billingPeriod)}`,
1067
+ ],
1068
+ });
1069
+ }
1070
+ const { auth } = selectCopilotAuth(await readAuthFile({ integrationIds: COPILOT_AUTH_KEYS }));
1071
+ const token = getCopilotOAuthToken(auth);
1072
+ if (!auth || !token)
1073
+ return null;
1074
+ const enterpriseHost = validateEnterpriseHost(auth.enterpriseUrl);
1075
+ if (enterpriseHost.error)
1076
+ return null;
1077
+ return deriveResolvedAuthIdentity({
1078
+ providerId: "copilot:oauth",
1079
+ principal: { kind: "credential", value: token },
1080
+ qualifiers: [`api=${getApiBaseUrl(enterpriseHost.host)}`],
1081
+ });
1082
+ }
1083
+ export async function hasCopilotQuotaRuntimeAvailable() {
1084
+ const diagnostics = getCopilotQuotaAuthDiagnostics(await readAuthFile({ integrationIds: COPILOT_AUTH_KEYS }));
1085
+ return diagnostics.billingApiAccessLikely;
1086
+ }
1087
+ export function formatCopilotQuota(result) {
1088
+ if (!result || !result.success)
1089
+ return null;
1090
+ if (result.mode === "user_plan") {
1091
+ return result.plan ? `Copilot Plan ${result.plan}` : "Copilot Plan available";
1092
+ }
1093
+ const unit = result.unit === "ai_credits"
1094
+ ? "AI Credits"
1095
+ : result.unit === "premium_interactions"
1096
+ ? "Premium Interactions"
1097
+ : "Premium Requests";
1098
+ if (result.mode === "organization_usage") {
1099
+ return `Copilot Org (${result.organization}) ${result.used} ${unit} | ${formatBillingPeriod(result.period)}`;
1100
+ }
1101
+ if (result.mode === "enterprise_usage") {
1102
+ return `Copilot Enterprise (${result.enterprise}) ${result.used} ${unit} | ${formatBillingPeriod(result.period)}`;
1103
+ }
1104
+ if (result.unlimited)
1105
+ return `Copilot ${unit} Unlimited`;
1106
+ if (result.total !== undefined) {
1107
+ return `Copilot ${unit} ${result.used}/${result.total}`;
1108
+ }
1109
+ return `Copilot ${unit} ${result.used} used`;
1110
+ }
1111
+ //# sourceMappingURL=copilot.js.map