opencode-quota-gui 1.0.1 → 1.2.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 (376) hide show
  1. package/README.md +35 -19
  2. package/dist/contracts/analytics-entity.d.ts +32 -0
  3. package/dist/contracts/analytics-entity.d.ts.map +1 -0
  4. package/dist/contracts/analytics-entity.js +123 -0
  5. package/dist/contracts/analytics-entity.js.map +1 -0
  6. package/dist/contracts/analytics-temporal.d.ts +39 -0
  7. package/dist/contracts/analytics-temporal.d.ts.map +1 -0
  8. package/dist/contracts/analytics-temporal.js +11 -0
  9. package/dist/contracts/analytics-temporal.js.map +1 -0
  10. package/dist/contracts/build-identity.js +1 -1
  11. package/dist/contracts/collision-safe-key.d.ts +14 -0
  12. package/dist/contracts/collision-safe-key.d.ts.map +1 -0
  13. package/dist/contracts/collision-safe-key.js +28 -0
  14. package/dist/contracts/collision-safe-key.js.map +1 -0
  15. package/dist/contracts/dashboard.d.ts +152 -0
  16. package/dist/contracts/dashboard.d.ts.map +1 -1
  17. package/dist/contracts/dashboard.js.map +1 -1
  18. package/dist/contracts/temporal.d.ts +126 -0
  19. package/dist/contracts/temporal.d.ts.map +1 -0
  20. package/dist/contracts/temporal.js +10 -0
  21. package/dist/contracts/temporal.js.map +1 -0
  22. package/dist/data/modelsdev-pricing.min.json +1 -1064
  23. package/dist/data/modelsdev-temporal.min.json +3075 -0
  24. package/dist/gui/aggregation.d.ts.map +1 -1
  25. package/dist/gui/aggregation.js +9 -0
  26. package/dist/gui/aggregation.js.map +1 -1
  27. package/dist/gui/analytics-bridge.d.ts.map +1 -1
  28. package/dist/gui/analytics-bridge.js +14 -0
  29. package/dist/gui/analytics-bridge.js.map +1 -1
  30. package/dist/gui/analytics-engine.d.ts +3 -1
  31. package/dist/gui/analytics-engine.d.ts.map +1 -1
  32. package/dist/gui/analytics-engine.js +228 -7
  33. package/dist/gui/analytics-engine.js.map +1 -1
  34. package/dist/gui/analytics-model.d.ts +7 -5
  35. package/dist/gui/analytics-model.d.ts.map +1 -1
  36. package/dist/gui/analytics-model.js +625 -39
  37. package/dist/gui/analytics-model.js.map +1 -1
  38. package/dist/gui/analytics-pricing-revision.d.ts +43 -0
  39. package/dist/gui/analytics-pricing-revision.d.ts.map +1 -0
  40. package/dist/gui/analytics-pricing-revision.js +160 -0
  41. package/dist/gui/analytics-pricing-revision.js.map +1 -0
  42. package/dist/gui/analytics-protocol.d.ts +6 -2
  43. package/dist/gui/analytics-protocol.d.ts.map +1 -1
  44. package/dist/gui/analytics-protocol.js.map +1 -1
  45. package/dist/gui/analytics-service.d.ts +3 -1
  46. package/dist/gui/analytics-service.d.ts.map +1 -1
  47. package/dist/gui/analytics-service.js +14 -0
  48. package/dist/gui/analytics-service.js.map +1 -1
  49. package/dist/gui/analytics-state.d.ts +13 -0
  50. package/dist/gui/analytics-state.d.ts.map +1 -1
  51. package/dist/gui/analytics-state.js +25 -0
  52. package/dist/gui/analytics-state.js.map +1 -1
  53. package/dist/gui/analytics-worker-runtime.d.ts +5 -0
  54. package/dist/gui/analytics-worker-runtime.d.ts.map +1 -1
  55. package/dist/gui/analytics-worker-runtime.js +6 -0
  56. package/dist/gui/analytics-worker-runtime.js.map +1 -1
  57. package/dist/gui/config.d.ts +2 -2
  58. package/dist/gui/config.d.ts.map +1 -1
  59. package/dist/gui/config.js +18 -0
  60. package/dist/gui/config.js.map +1 -1
  61. package/dist/gui/lifecycle.d.ts +1 -1
  62. package/dist/gui/lifecycle.d.ts.map +1 -1
  63. package/dist/gui/lifecycle.js +1 -0
  64. package/dist/gui/lifecycle.js.map +1 -1
  65. package/dist/gui/server.d.ts.map +1 -1
  66. package/dist/gui/server.js +62 -0
  67. package/dist/gui/server.js.map +1 -1
  68. package/dist/gui/snapshot-service.d.ts +3 -1
  69. package/dist/gui/snapshot-service.d.ts.map +1 -1
  70. package/dist/gui/snapshot-service.js +10 -0
  71. package/dist/gui/snapshot-service.js.map +1 -1
  72. package/dist/gui/sources.d.ts +1 -1
  73. package/dist/gui/sources.d.ts.map +1 -1
  74. package/dist/gui/sources.js +53 -4
  75. package/dist/gui/sources.js.map +1 -1
  76. package/dist/gui/temporal-quota-policy-data.d.ts +24 -0
  77. package/dist/gui/temporal-quota-policy-data.d.ts.map +1 -0
  78. package/dist/gui/temporal-quota-policy-data.js +43 -0
  79. package/dist/gui/temporal-quota-policy-data.js.map +1 -0
  80. package/dist/gui/temporal-quota-policy.d.ts +38 -0
  81. package/dist/gui/temporal-quota-policy.d.ts.map +1 -0
  82. package/dist/gui/temporal-quota-policy.js +182 -0
  83. package/dist/gui/temporal-quota-policy.js.map +1 -0
  84. package/dist/gui/temporal-status.d.ts +53 -0
  85. package/dist/gui/temporal-status.d.ts.map +1 -0
  86. package/dist/gui/temporal-status.js +815 -0
  87. package/dist/gui/temporal-status.js.map +1 -0
  88. package/dist/lib/config.d.ts +1 -1
  89. package/dist/lib/config.d.ts.map +1 -1
  90. package/dist/lib/config.js +33 -0
  91. package/dist/lib/config.js.map +1 -1
  92. package/dist/lib/cursor-usage.d.ts.map +1 -1
  93. package/dist/lib/cursor-usage.js +8 -2
  94. package/dist/lib/cursor-usage.js.map +1 -1
  95. package/dist/lib/modelsdev-pricing.d.ts +54 -1
  96. package/dist/lib/modelsdev-pricing.d.ts.map +1 -1
  97. package/dist/lib/modelsdev-pricing.js +284 -43
  98. package/dist/lib/modelsdev-pricing.js.map +1 -1
  99. package/dist/lib/modelsdev-temporal.d.ts +143 -0
  100. package/dist/lib/modelsdev-temporal.d.ts.map +1 -0
  101. package/dist/lib/modelsdev-temporal.js +896 -0
  102. package/dist/lib/modelsdev-temporal.js.map +1 -0
  103. package/dist/lib/opencode-console-auth.d.ts +19 -0
  104. package/dist/lib/opencode-console-auth.d.ts.map +1 -1
  105. package/dist/lib/opencode-console-auth.js +263 -3
  106. package/dist/lib/opencode-console-auth.js.map +1 -1
  107. package/dist/lib/opencode-storage.d.ts +26 -11
  108. package/dist/lib/opencode-storage.d.ts.map +1 -1
  109. package/dist/lib/opencode-storage.js +33 -56
  110. package/dist/lib/opencode-storage.js.map +1 -1
  111. package/dist/lib/quota-providers-local.d.ts.map +1 -1
  112. package/dist/lib/quota-providers-local.js +13 -3
  113. package/dist/lib/quota-providers-local.js.map +1 -1
  114. package/dist/lib/quota-stats-format.d.ts.map +1 -1
  115. package/dist/lib/quota-stats-format.js +28 -6
  116. package/dist/lib/quota-stats-format.js.map +1 -1
  117. package/dist/lib/quota-stats.d.ts +71 -7
  118. package/dist/lib/quota-stats.d.ts.map +1 -1
  119. package/dist/lib/quota-stats.js +417 -22
  120. package/dist/lib/quota-stats.js.map +1 -1
  121. package/dist/lib/scoped-query-chunks.d.ts +15 -0
  122. package/dist/lib/scoped-query-chunks.d.ts.map +1 -0
  123. package/dist/lib/scoped-query-chunks.js +48 -0
  124. package/dist/lib/scoped-query-chunks.js.map +1 -0
  125. package/dist/lib/token-cost.d.ts +29 -0
  126. package/dist/lib/token-cost.d.ts.map +1 -1
  127. package/dist/lib/token-cost.js +74 -10
  128. package/dist/lib/token-cost.js.map +1 -1
  129. package/dist/lib/types.d.ts +6 -0
  130. package/dist/lib/types.d.ts.map +1 -1
  131. package/dist/lib/types.js +1 -0
  132. package/dist/lib/types.js.map +1 -1
  133. package/dist/provider-logos/NOTICE.md +12 -0
  134. package/dist/provider-logos/OPENCODE-MIT.txt +21 -0
  135. package/dist/provider-logos/OPENCODE-NOTICE.md +12 -0
  136. package/dist/provider-logos/UPSTREAM-MIT.txt +21 -0
  137. package/dist/providers/cache-policies.d.ts.map +1 -1
  138. package/dist/providers/cache-policies.js +4 -3
  139. package/dist/providers/cache-policies.js.map +1 -1
  140. package/dist/providers/opencode-go.d.ts.map +1 -1
  141. package/dist/providers/opencode-go.js +2 -0
  142. package/dist/providers/opencode-go.js.map +1 -1
  143. package/dist/providers/opencode-zen.d.ts.map +1 -1
  144. package/dist/providers/opencode-zen.js +2 -0
  145. package/dist/providers/opencode-zen.js.map +1 -1
  146. package/dist/ui/assets/{index-D3-Yn_WA.css → index-Cs-nrywz.css} +1 -1
  147. package/dist/ui/assets/index-D9lFKhSN.js +9 -0
  148. package/dist/ui/assets/popover-DKRrwr_K.js +1 -0
  149. package/dist/ui/assets/popover-mkHTmNjv.css +1 -0
  150. package/dist/ui/assets/providers/302ai.svg +7 -0
  151. package/dist/ui/assets/providers/abacus.svg +14 -0
  152. package/dist/ui/assets/providers/abliteration-ai.svg +6 -0
  153. package/dist/ui/assets/providers/above.svg +3 -0
  154. package/dist/ui/assets/providers/agentrouter.svg +4 -0
  155. package/dist/ui/assets/providers/agnes.svg +1 -0
  156. package/dist/ui/assets/providers/ai-router.svg +5 -0
  157. package/dist/ui/assets/providers/ai21.svg +3 -0
  158. package/dist/ui/assets/providers/aiand.svg +4 -0
  159. package/dist/ui/assets/providers/aihubmix.svg +3 -0
  160. package/dist/ui/assets/providers/aimlapi.svg +3 -0
  161. package/dist/ui/assets/providers/ainetcafe.svg +1 -0
  162. package/dist/ui/assets/providers/aixy.svg +4 -0
  163. package/dist/ui/assets/providers/aki-io.svg +7 -0
  164. package/dist/ui/assets/providers/alibaba-cn.svg +3 -0
  165. package/dist/ui/assets/providers/alibaba-coding-plan-cn.svg +3 -0
  166. package/dist/ui/assets/providers/alibaba-coding-plan.svg +3 -0
  167. package/dist/ui/assets/providers/alibaba-token-plan.svg +3 -0
  168. package/dist/ui/assets/providers/alibaba.svg +3 -0
  169. package/dist/ui/assets/providers/amazon-bedrock.svg +3 -0
  170. package/dist/ui/assets/providers/ambient.svg +3 -0
  171. package/dist/ui/assets/providers/amd.svg +3 -0
  172. package/dist/ui/assets/providers/anthropic.svg +3 -0
  173. package/dist/ui/assets/providers/anyapi.svg +3 -0
  174. package/dist/ui/assets/providers/arcee.svg +3 -0
  175. package/dist/ui/assets/providers/atomic-chat.svg +1 -0
  176. package/dist/ui/assets/providers/auriko.svg +6 -0
  177. package/dist/ui/assets/providers/azure-cognitive-services.svg +3 -0
  178. package/dist/ui/assets/providers/azure.svg +3 -0
  179. package/dist/ui/assets/providers/bailing.svg +3 -0
  180. package/dist/ui/assets/providers/baseten.svg +3 -0
  181. package/dist/ui/assets/providers/bee.svg +1 -0
  182. package/dist/ui/assets/providers/berget.svg +3 -0
  183. package/dist/ui/assets/providers/blueclaw.svg +3 -0
  184. package/dist/ui/assets/providers/bothub.svg +33 -0
  185. package/dist/ui/assets/providers/boundless.svg +12 -0
  186. package/dist/ui/assets/providers/cerebras.svg +4 -0
  187. package/dist/ui/assets/providers/clarifai.svg +3 -0
  188. package/dist/ui/assets/providers/claudinio.svg +19 -0
  189. package/dist/ui/assets/providers/cloudferro-sherlock.svg +5 -0
  190. package/dist/ui/assets/providers/cloudflare-ai-gateway.svg +4 -0
  191. package/dist/ui/assets/providers/cloudflare-workers-ai.svg +4 -0
  192. package/dist/ui/assets/providers/cohere.svg +5 -0
  193. package/dist/ui/assets/providers/commandcode.svg +11 -0
  194. package/dist/ui/assets/providers/coralbricks.svg +6 -0
  195. package/dist/ui/assets/providers/crossmodel.svg +5 -0
  196. package/dist/ui/assets/providers/crusoe.svg +23 -0
  197. package/dist/ui/assets/providers/daoxe.svg +3 -0
  198. package/dist/ui/assets/providers/databricks.svg +3 -0
  199. package/dist/ui/assets/providers/deepinfra.svg +4 -0
  200. package/dist/ui/assets/providers/deepseek.svg +3 -0
  201. package/dist/ui/assets/providers/digitalocean.svg +6 -0
  202. package/dist/ui/assets/providers/dinference.svg +1 -0
  203. package/dist/ui/assets/providers/drun.svg +8 -0
  204. package/dist/ui/assets/providers/ebcloud.svg +8 -0
  205. package/dist/ui/assets/providers/echo.svg +7 -0
  206. package/dist/ui/assets/providers/edenai.svg +8 -0
  207. package/dist/ui/assets/providers/empiriolabs.svg +1 -0
  208. package/dist/ui/assets/providers/engy.svg +1 -0
  209. package/dist/ui/assets/providers/evroc.svg +3 -0
  210. package/dist/ui/assets/providers/fastrouter.svg +3 -0
  211. package/dist/ui/assets/providers/fireworks-ai.svg +3 -0
  212. package/dist/ui/assets/providers/fluence.svg +3 -0
  213. package/dist/ui/assets/providers/freemodel.svg +3 -0
  214. package/dist/ui/assets/providers/friendli.svg +3 -0
  215. package/dist/ui/assets/providers/frogbot.svg +36 -0
  216. package/dist/ui/assets/providers/generic.svg +4 -0
  217. package/dist/ui/assets/providers/github-copilot.svg +3 -0
  218. package/dist/ui/assets/providers/gitlab.svg +3 -0
  219. package/dist/ui/assets/providers/google-vertex-anthropic.svg +10 -0
  220. package/dist/ui/assets/providers/google-vertex.svg +10 -0
  221. package/dist/ui/assets/providers/google.svg +3 -0
  222. package/dist/ui/assets/providers/greenpt.svg +6 -0
  223. package/dist/ui/assets/providers/groq.svg +3 -0
  224. package/dist/ui/assets/providers/helicone.svg +6 -0
  225. package/dist/ui/assets/providers/hetzner.svg +3 -0
  226. package/dist/ui/assets/providers/hpc-ai.svg +444 -0
  227. package/dist/ui/assets/providers/huggingface.svg +3 -0
  228. package/dist/ui/assets/providers/hyper.svg +20 -0
  229. package/dist/ui/assets/providers/impossibl.svg +3 -0
  230. package/dist/ui/assets/providers/inception.svg +14 -0
  231. package/dist/ui/assets/providers/inceptron.svg +14 -0
  232. package/dist/ui/assets/providers/inco.svg +3 -0
  233. package/dist/ui/assets/providers/infer.svg +4 -0
  234. package/dist/ui/assets/providers/inference.svg +3 -0
  235. package/dist/ui/assets/providers/inferx.svg +5 -0
  236. package/dist/ui/assets/providers/infomaniak.svg +3 -0
  237. package/dist/ui/assets/providers/io-net.svg +5 -0
  238. package/dist/ui/assets/providers/iteracompute.svg +6 -0
  239. package/dist/ui/assets/providers/jalapeno.svg +8 -0
  240. package/dist/ui/assets/providers/jiekou.svg +4 -0
  241. package/dist/ui/assets/providers/kenari.svg +4 -0
  242. package/dist/ui/assets/providers/kilo.svg +4 -0
  243. package/dist/ui/assets/providers/kimi-code-plan-cn.svg +3 -0
  244. package/dist/ui/assets/providers/kimi-code-plan-global.svg +3 -0
  245. package/dist/ui/assets/providers/klokintegration.svg +11 -0
  246. package/dist/ui/assets/providers/kosmik.svg +28 -0
  247. package/dist/ui/assets/providers/kuae-cloud-coding-plan.svg +3 -0
  248. package/dist/ui/assets/providers/lilac.svg +6 -0
  249. package/dist/ui/assets/providers/liquid.svg +1 -0
  250. package/dist/ui/assets/providers/llmgateway-providers.svg +6 -0
  251. package/dist/ui/assets/providers/llmgateway.svg +6 -0
  252. package/dist/ui/assets/providers/llmtech.svg +6 -0
  253. package/dist/ui/assets/providers/llmtr.svg +12 -0
  254. package/dist/ui/assets/providers/lmstudio.svg +3 -0
  255. package/dist/ui/assets/providers/longcat.svg +6 -0
  256. package/dist/ui/assets/providers/lowrouter.svg +8 -0
  257. package/dist/ui/assets/providers/lucidquery.svg +3 -0
  258. package/dist/ui/assets/providers/lynkr.svg +1 -0
  259. package/dist/ui/assets/providers/meganova.svg +3 -0
  260. package/dist/ui/assets/providers/melious.svg +3 -0
  261. package/dist/ui/assets/providers/merge-gateway.svg +4 -0
  262. package/dist/ui/assets/providers/meta.svg +3 -0
  263. package/dist/ui/assets/providers/minimax-cn-coding-plan.svg +3 -0
  264. package/dist/ui/assets/providers/minimax-cn.svg +3 -0
  265. package/dist/ui/assets/providers/minimax-coding-plan.svg +3 -0
  266. package/dist/ui/assets/providers/minimax.svg +3 -0
  267. package/dist/ui/assets/providers/mistral.svg +3 -0
  268. package/dist/ui/assets/providers/mixlayer.svg +8 -0
  269. package/dist/ui/assets/providers/moark.svg +3 -0
  270. package/dist/ui/assets/providers/modal.svg +3 -0
  271. package/dist/ui/assets/providers/model-oracle-ai.svg +11 -0
  272. package/dist/ui/assets/providers/modelis.svg +1 -0
  273. package/dist/ui/assets/providers/modelscope.svg +5 -0
  274. package/dist/ui/assets/providers/moonshotai-cn.svg +3 -0
  275. package/dist/ui/assets/providers/moonshotai.svg +3 -0
  276. package/dist/ui/assets/providers/munito-eu.svg +1 -0
  277. package/dist/ui/assets/providers/munito.svg +1 -0
  278. package/dist/ui/assets/providers/nan.svg +1 -0
  279. package/dist/ui/assets/providers/nano-gpt.svg +3 -0
  280. package/dist/ui/assets/providers/nearai.svg +1 -0
  281. package/dist/ui/assets/providers/nebius.svg +4 -0
  282. package/dist/ui/assets/providers/neon.svg +3 -0
  283. package/dist/ui/assets/providers/neosmith.svg +6 -0
  284. package/dist/ui/assets/providers/neuralwatt.svg +27 -0
  285. package/dist/ui/assets/providers/nova.svg +3 -0
  286. package/dist/ui/assets/providers/novita-ai.svg +10 -0
  287. package/dist/ui/assets/providers/nvidia.svg +3 -0
  288. package/dist/ui/assets/providers/oci.svg +3 -0
  289. package/dist/ui/assets/providers/ofox.svg +5 -0
  290. package/dist/ui/assets/providers/ollama-cloud.svg +7 -0
  291. package/dist/ui/assets/providers/openai.svg +3 -0
  292. package/dist/ui/assets/providers/opencode-go-g.svg +3 -0
  293. package/dist/ui/assets/providers/opencode-go.svg +4 -0
  294. package/dist/ui/assets/providers/opencode.svg +4 -0
  295. package/dist/ui/assets/providers/openreason.svg +8 -0
  296. package/dist/ui/assets/providers/openrouter.svg +3 -0
  297. package/dist/ui/assets/providers/opper.svg +3 -0
  298. package/dist/ui/assets/providers/orcarouter.svg +2 -0
  299. package/dist/ui/assets/providers/ovhcloud.svg +3 -0
  300. package/dist/ui/assets/providers/pareto.svg +5 -0
  301. package/dist/ui/assets/providers/pendra.svg +10 -0
  302. package/dist/ui/assets/providers/perplexity-agent.svg +3 -0
  303. package/dist/ui/assets/providers/perplexity.svg +3 -0
  304. package/dist/ui/assets/providers/pioneer.svg +3 -0
  305. package/dist/ui/assets/providers/poe.svg +7 -0
  306. package/dist/ui/assets/providers/poolside.svg +3 -0
  307. package/dist/ui/assets/providers/prime.svg +7 -0
  308. package/dist/ui/assets/providers/privatemode-ai.svg +5 -0
  309. package/dist/ui/assets/providers/qihang-ai.svg +9 -0
  310. package/dist/ui/assets/providers/qiniu-ai.svg +7 -0
  311. package/dist/ui/assets/providers/qvac.svg +6 -0
  312. package/dist/ui/assets/providers/reflection.svg +3 -0
  313. package/dist/ui/assets/providers/regolo-ai.svg +45 -0
  314. package/dist/ui/assets/providers/routing-run.svg +4 -0
  315. package/dist/ui/assets/providers/runinfra.svg +10 -0
  316. package/dist/ui/assets/providers/salad-cloud.svg +15 -0
  317. package/dist/ui/assets/providers/sambanova.svg +26 -0
  318. package/dist/ui/assets/providers/scaleway.svg +5 -0
  319. package/dist/ui/assets/providers/scnet-token-plan.svg +8 -0
  320. package/dist/ui/assets/providers/scx-ai.svg +1 -0
  321. package/dist/ui/assets/providers/sensenova.svg +18 -0
  322. package/dist/ui/assets/providers/siliconflow-cn.svg +3 -0
  323. package/dist/ui/assets/providers/siliconflow.svg +3 -0
  324. package/dist/ui/assets/providers/snowflake-cortex.svg +3 -0
  325. package/dist/ui/assets/providers/stackit.svg +3 -0
  326. package/dist/ui/assets/providers/standardcompute.svg +5 -0
  327. package/dist/ui/assets/providers/stepfun-ai-step-plan.svg +16 -0
  328. package/dist/ui/assets/providers/stepfun-ai.svg +16 -0
  329. package/dist/ui/assets/providers/stepfun-step-plan.svg +16 -0
  330. package/dist/ui/assets/providers/stepfun.svg +16 -0
  331. package/dist/ui/assets/providers/subconscious.svg +3 -0
  332. package/dist/ui/assets/providers/submodel.svg +3 -0
  333. package/dist/ui/assets/providers/teamorouter.svg +3 -0
  334. package/dist/ui/assets/providers/tempr.svg +4 -0
  335. package/dist/ui/assets/providers/tencent-coding-plan.svg +5 -0
  336. package/dist/ui/assets/providers/tencent-token-plan.svg +3 -0
  337. package/dist/ui/assets/providers/tencent-tokenhub.svg +3 -0
  338. package/dist/ui/assets/providers/tensorx.svg +6 -0
  339. package/dist/ui/assets/providers/the-grid-ai.svg +14 -0
  340. package/dist/ui/assets/providers/thinkingmachines.svg +3 -0
  341. package/dist/ui/assets/providers/tinfoil.svg +3 -0
  342. package/dist/ui/assets/providers/togetherai.svg +4 -0
  343. package/dist/ui/assets/providers/tokengo.svg +3 -0
  344. package/dist/ui/assets/providers/tokenrouter.svg +4 -0
  345. package/dist/ui/assets/providers/trustedrouter.svg +4 -0
  346. package/dist/ui/assets/providers/umans-ai-coding-plan.svg +29 -0
  347. package/dist/ui/assets/providers/umans-ai.svg +29 -0
  348. package/dist/ui/assets/providers/unorouter.svg +7 -0
  349. package/dist/ui/assets/providers/vancine.svg +6 -0
  350. package/dist/ui/assets/providers/venice.svg +4 -0
  351. package/dist/ui/assets/providers/vercel.svg +3 -0
  352. package/dist/ui/assets/providers/vispark.svg +3 -0
  353. package/dist/ui/assets/providers/vivgrid.svg +4 -0
  354. package/dist/ui/assets/providers/volcengine-coding-plan.svg +3 -0
  355. package/dist/ui/assets/providers/volcengine.svg +3 -0
  356. package/dist/ui/assets/providers/vultr.svg +6 -0
  357. package/dist/ui/assets/providers/wafer.ai.svg +3 -0
  358. package/dist/ui/assets/providers/wallaby.svg +4 -0
  359. package/dist/ui/assets/providers/wandb.svg +6 -0
  360. package/dist/ui/assets/providers/watsonx.svg +5 -0
  361. package/dist/ui/assets/providers/xai.svg +3 -0
  362. package/dist/ui/assets/providers/xiaomi-token-plan-ams.svg +3 -0
  363. package/dist/ui/assets/providers/xiaomi-token-plan-cn.svg +3 -0
  364. package/dist/ui/assets/providers/xiaomi-token-plan-sgp.svg +3 -0
  365. package/dist/ui/assets/providers/xiaomi.svg +3 -0
  366. package/dist/ui/assets/providers/xpersona.svg +8 -0
  367. package/dist/ui/assets/providers/zai-coding-plan.svg +3 -0
  368. package/dist/ui/assets/providers/zai.svg +3 -0
  369. package/dist/ui/assets/providers/zeldoc.svg +3 -0
  370. package/dist/ui/assets/providers/zenifra.svg +4 -0
  371. package/dist/ui/assets/providers/zenmux.svg +4 -0
  372. package/dist/ui/assets/providers/zhipuai-coding-plan.svg +3 -0
  373. package/dist/ui/assets/providers/zhipuai.svg +3 -0
  374. package/dist/ui/index.html +2 -2
  375. package/package.json +5 -1
  376. package/dist/ui/assets/index-CPEiQt-C.js +0 -8
@@ -1,10 +1,23 @@
1
+ /**
2
+ * Worker-only rollup model.
3
+ *
4
+ * Owns deterministic fork ownership over compact fingerprint groups plus
5
+ * per-hour rollups (global / project / session) and derives grouped
6
+ * model/provider views from the same owned steps. Full hours use
7
+ * pre-aggregated buckets; only the partial edge hours of a request touch the
8
+ * owned step list, so bucket boundaries stay exact without rebuilding a raw
9
+ * model per view.
10
+ */
1
11
  import { sumTokenStack } from "../contracts/guards.js";
2
12
  import { planRangeBuckets, rangeBucketUnit, rangeWindow, } from "../contracts/ranges.js";
3
- import { rawAssistantRowFingerprint, } from "../lib/opencode-storage.js";
4
- import { priceTokenBuckets } from "../lib/quota-stats.js";
13
+ import { lookupCost, selectCostAtContext } from "../lib/modelsdev-pricing.js";
14
+ import { getTemporalPolicy, resolveTemporalRates, TEMPORAL_RATE_KEYS, } from "../lib/modelsdev-temporal.js";
15
+ import { rawAssistantRowFingerprint, rawAssistantRowHasTokenUsage, } from "../lib/opencode-storage.js";
16
+ import { priceTokenBuckets, resolvePricingKey, } from "../lib/quota-stats.js";
5
17
  import { selectForkOwners } from "../lib/usage-ownership.js";
6
18
  import { UNKNOWN_PROJECT_ID, UNTITLED_SESSION_TITLE } from "./aggregation.js";
7
19
  const HOUR_MS = 3_600_000;
20
+ const TEMPORAL_FACTOR_EPSILON = 1e-9;
8
21
  function createAccumulator() {
9
22
  return {
10
23
  input: 0,
@@ -18,13 +31,6 @@ function createAccumulator() {
18
31
  unknownTokens: 0,
19
32
  };
20
33
  }
21
- function isZeroTokens(accumulator) {
22
- return (accumulator.input === 0 &&
23
- accumulator.cacheRead === 0 &&
24
- accumulator.cacheWrite === 0 &&
25
- accumulator.output === 0 &&
26
- accumulator.reasoning === 0);
27
- }
28
34
  function addStepToAccumulator(accumulator, step) {
29
35
  accumulator.input += step.tokens.input;
30
36
  accumulator.cacheRead += step.tokens.cacheRead;
@@ -76,6 +82,177 @@ function finalize(accumulator) {
76
82
  unknownTokens: accumulator.unknownTokens,
77
83
  };
78
84
  }
85
+ function createGroupNode() {
86
+ return {
87
+ totals: createAccumulator(),
88
+ sessions: new Set(),
89
+ stepCount: 0,
90
+ children: new Map(),
91
+ };
92
+ }
93
+ function identityOf(raw) {
94
+ return raw === undefined ? { kind: "unknown" } : { kind: "known", id: raw };
95
+ }
96
+ function identityTotal(identity) {
97
+ return identity.kind === "known" ? identity.id : undefined;
98
+ }
99
+ /** Known raw ids sort before the explicit unknown identity, then by raw id. */
100
+ function compareIdentities(a, b) {
101
+ if (a.kind !== b.kind)
102
+ return a.kind === "known" ? -1 : 1;
103
+ if (a.kind === "known" && b.kind === "known")
104
+ return compareIds(a.id, b.id);
105
+ return 0;
106
+ }
107
+ function accumulatorTotal(accumulator) {
108
+ return (accumulator.input +
109
+ accumulator.cacheRead +
110
+ accumulator.cacheWrite +
111
+ accumulator.output +
112
+ accumulator.reasoning);
113
+ }
114
+ /**
115
+ * Deterministic token rank for the selected range: token volume descending,
116
+ * then raw identity ascending with the unknown identity last. The rank never
117
+ * depends on key insertion order or on cost.
118
+ */
119
+ function compareGroupEntries(a, b) {
120
+ const byTokens = accumulatorTotal(b.node.totals) - accumulatorTotal(a.node.totals);
121
+ if (byTokens !== 0)
122
+ return byTokens;
123
+ return compareIdentities(identityOf(a.raw), identityOf(b.raw));
124
+ }
125
+ function sortedChildEntries(node) {
126
+ return [...node.children].map(([raw, child]) => ({ raw, node: child })).sort(compareGroupEntries);
127
+ }
128
+ function materializeBuckets(bucketTotals, bucketCount) {
129
+ const buckets = new Array(bucketCount);
130
+ for (let index = 0; index < bucketCount; index += 1) {
131
+ const accumulator = bucketTotals.get(index);
132
+ buckets[index] = finalize(accumulator ?? createAccumulator());
133
+ }
134
+ return buckets;
135
+ }
136
+ function addStepToGroupNode(node, step) {
137
+ addStepToAccumulator(node.totals, step);
138
+ node.sessions.add(step.sessionID);
139
+ node.stepCount += 1;
140
+ }
141
+ function materializeGroupRow(raw, node) {
142
+ return {
143
+ identity: identityOf(raw),
144
+ tokens: finalize(node.totals),
145
+ sessionCount: node.sessions.size,
146
+ stepCount: node.stepCount,
147
+ children: sortedChildEntries(node).map((entry) => materializeGroupRow(entry.raw, entry.node)),
148
+ };
149
+ }
150
+ function addStepToBucket(bucketTotals, step, bucketIndex) {
151
+ if (bucketIndex < 0)
152
+ return;
153
+ let bucket = bucketTotals.get(bucketIndex);
154
+ if (!bucket) {
155
+ bucket = createAccumulator();
156
+ bucketTotals.set(bucketIndex, bucket);
157
+ }
158
+ addStepToAccumulator(bucket, step);
159
+ }
160
+ function addStepToEntityBucket(entityBuckets, raw, step, bucketIndex) {
161
+ if (bucketIndex < 0)
162
+ return;
163
+ let bucketTotals = entityBuckets.get(raw);
164
+ if (!bucketTotals) {
165
+ bucketTotals = new Map();
166
+ entityBuckets.set(raw, bucketTotals);
167
+ }
168
+ addStepToBucket(bucketTotals, step, bucketIndex);
169
+ }
170
+ /**
171
+ * Sparse per-bucket entity breakdown aligned with the snapshot boundaries.
172
+ * Entities are ranked by their own bucket tokens, then exact identity with the
173
+ * unknown identity last, so output order never depends on map insertion.
174
+ */
175
+ function materializeEntityBuckets(entityBuckets, bucketCount) {
176
+ const buckets = [];
177
+ for (let index = 0; index < bucketCount; index += 1)
178
+ buckets.push([]);
179
+ for (const [raw, bucketTotals] of entityBuckets) {
180
+ for (const [bucketIndex, accumulator] of bucketTotals) {
181
+ const bucket = buckets[bucketIndex];
182
+ if (bucket === undefined)
183
+ continue;
184
+ bucket.push({ identity: identityOf(raw), tokens: finalize(accumulator) });
185
+ }
186
+ }
187
+ for (const entries of buckets) {
188
+ entries.sort((a, b) => {
189
+ const byTokens = b.tokens.total - a.tokens.total;
190
+ if (byTokens !== 0)
191
+ return byTokens;
192
+ return compareIdentities(a.identity, b.identity);
193
+ });
194
+ }
195
+ return buckets;
196
+ }
197
+ /**
198
+ * Top five entities by selected-range token rank plus one chart-only Other
199
+ * series. Only these sources carry per-bucket accumulators, so the returned
200
+ * bucket arrays are bounded by series × buckets and their breakdowns by the
201
+ * visible entity cardinality, never by a parent × child cross-product.
202
+ */
203
+ function buildSeries(top, other, bucketCount) {
204
+ const series = top.map((source) => ({
205
+ kind: "entity",
206
+ identity: identityOf(source.raw),
207
+ tokens: finalize(source.totals),
208
+ buckets: materializeBuckets(source.bucketTotals, bucketCount),
209
+ childBuckets: materializeEntityBuckets(source.childBuckets, bucketCount),
210
+ }));
211
+ if (other !== undefined) {
212
+ series.push({
213
+ kind: "other",
214
+ tokens: finalize(other.totals),
215
+ buckets: materializeBuckets(other.bucketTotals, bucketCount),
216
+ childBuckets: materializeEntityBuckets(other.childBuckets, bucketCount),
217
+ ...(other.parentBuckets === undefined
218
+ ? {}
219
+ : { parentBuckets: materializeEntityBuckets(other.parentBuckets, bucketCount) }),
220
+ });
221
+ }
222
+ return series;
223
+ }
224
+ function rawIdForDimension(step, dimension) {
225
+ return dimension === "model" ? step.modelID : step.providerID;
226
+ }
227
+ function oppositeDimension(dimension) {
228
+ return dimension === "model" ? "provider" : "model";
229
+ }
230
+ /** Filter matches the entity's own dimension, independent of grouping. */
231
+ function matchesFilter(step, filter) {
232
+ if (filter === undefined)
233
+ return true;
234
+ return rawIdForDimension(step, filter.dimension) === identityTotal(filter.identity);
235
+ }
236
+ /** Last bucket whose start is at or before `timeMs`; boundaries are contiguous. */
237
+ function bucketIndexAt(bucketStarts, timeMs) {
238
+ let low = 0;
239
+ let high = bucketStarts.length - 1;
240
+ let found = -1;
241
+ while (low <= high) {
242
+ const middle = (low + high) >>> 1;
243
+ const start = bucketStarts[middle];
244
+ if (start === undefined)
245
+ return found;
246
+ if (start <= timeMs) {
247
+ found = middle;
248
+ low = middle + 1;
249
+ }
250
+ else {
251
+ high = middle - 1;
252
+ }
253
+ }
254
+ return found;
255
+ }
79
256
  function compareIds(a, b) {
80
257
  return a < b ? -1 : a > b ? 1 : 0;
81
258
  }
@@ -121,8 +298,6 @@ export function createAnalyticsModel(options = {}) {
121
298
  const ownedByFp = new Map();
122
299
  const ownedBySession = new Map();
123
300
  const hours = new Map();
124
- /** Lifetime model-dimension rollup (small: one entry per provider/model). */
125
- const modelLifetime = new Map();
126
301
  const latestStepBySession = new Map();
127
302
  const earliestStepBySession = new Map();
128
303
  let earliestHourMs;
@@ -150,8 +325,19 @@ export function createAnalyticsModel(options = {}) {
150
325
  cache_read: row.tokens.cacheRead,
151
326
  cache_write: row.tokens.cacheWrite,
152
327
  },
328
+ // Historical temporal pricing follows the physical assistant completion
329
+ // instant, not the enclosing range window or the worker's wall clock.
330
+ atMs: row.completedAtMs,
153
331
  cache: pricingCache,
154
332
  });
333
+ if (outcome.status === "partial") {
334
+ return {
335
+ costUsd: outcome.costUsd,
336
+ pricedAny: true,
337
+ unpricedTokens: outcome.unpricedTokens,
338
+ unknownTokens: 0,
339
+ };
340
+ }
155
341
  if (outcome.status === "priced") {
156
342
  return { costUsd: outcome.costUsd, pricedAny: true, unpricedTokens: 0, unknownTokens: 0 };
157
343
  }
@@ -160,6 +346,147 @@ export function createAnalyticsModel(options = {}) {
160
346
  }
161
347
  return { costUsd: 0, pricedAny: false, unpricedTokens: 0, unknownTokens: total };
162
348
  }
349
+ /**
350
+ * Relative movement of one effective monetary rate state against the route's
351
+ * selected base. Partial override rates are compared field by field; a state
352
+ * that moves categories in opposite directions is mixed and unusable.
353
+ */
354
+ function rateMovement(base, resolved) {
355
+ let comparable = false;
356
+ let sawIncrease = false;
357
+ let sawDecrease = false;
358
+ for (const key of TEMPORAL_RATE_KEYS) {
359
+ const baseRate = base[key];
360
+ const resolvedRate = resolved[key];
361
+ if (typeof baseRate !== "number" ||
362
+ baseRate <= 0 ||
363
+ typeof resolvedRate !== "number" ||
364
+ !Number.isFinite(resolvedRate)) {
365
+ continue;
366
+ }
367
+ comparable = true;
368
+ if (resolvedRate > baseRate * (1 + TEMPORAL_FACTOR_EPSILON))
369
+ sawIncrease = true;
370
+ else if (resolvedRate < baseRate * (1 - TEMPORAL_FACTOR_EPSILON))
371
+ sawDecrease = true;
372
+ }
373
+ if (!comparable)
374
+ return "incomparable";
375
+ if (sawIncrease && sawDecrease)
376
+ return "mixed";
377
+ if (sawIncrease)
378
+ return "increase";
379
+ if (sawDecrease)
380
+ return "decrease";
381
+ return "equal";
382
+ }
383
+ function multiplierMovement(factor) {
384
+ const value = typeof factor === "number" ? factor : factor.text;
385
+ if (!Number.isFinite(value))
386
+ return "incomparable";
387
+ if (value > 1 + TEMPORAL_FACTOR_EPSILON)
388
+ return "increase";
389
+ if (value < 1 - TEMPORAL_FACTOR_EPSILON)
390
+ return "decrease";
391
+ return "equal";
392
+ }
393
+ /**
394
+ * Direction of every admissible rule in the exact route's policy. A policy
395
+ * that only discounts has a peak base state; one that only surcharges has an
396
+ * off-peak base state. Mixed or equal-only rules cannot establish which side
397
+ * of the schedule the unchanged base belongs to, so they fail closed.
398
+ */
399
+ function temporalPolicyDirection(policy, base) {
400
+ let discount = false;
401
+ let surcharge = false;
402
+ for (const override of policy.overrides) {
403
+ const movement = rateMovement(base, override.rates);
404
+ if (movement === "mixed")
405
+ return "mixed";
406
+ if (movement === "increase")
407
+ surcharge = true;
408
+ else if (movement === "decrease")
409
+ discount = true;
410
+ }
411
+ for (const multiplier of policy.multipliers) {
412
+ const movement = multiplierMovement(multiplier.factor);
413
+ if (movement === "increase")
414
+ surcharge = true;
415
+ else if (movement === "decrease")
416
+ discount = true;
417
+ }
418
+ if (discount && surcharge)
419
+ return "mixed";
420
+ if (discount)
421
+ return "discount";
422
+ if (surcharge)
423
+ return "surcharge";
424
+ return "equal";
425
+ }
426
+ /**
427
+ * One historical phase relative to the policy's full set of admissible
428
+ * periods. A discount policy keeps its unchanged base on peak; a surcharge
429
+ * policy keeps its unchanged base on off-peak. Unknown, mixed, equal-only or
430
+ * internally contradictory states are omitted instead of defaulted.
431
+ */
432
+ function temporalPhaseFromRates(policy, base, resolved) {
433
+ const direction = temporalPolicyDirection(policy, base);
434
+ if (direction === "mixed" || direction === "equal")
435
+ return undefined;
436
+ const movement = rateMovement(base, resolved);
437
+ if (movement === "mixed" || movement === "incomparable")
438
+ return undefined;
439
+ if (direction === "discount") {
440
+ if (movement === "decrease")
441
+ return "offpeak";
442
+ if (movement === "equal")
443
+ return "peak";
444
+ return undefined;
445
+ }
446
+ if (movement === "increase")
447
+ return "peak";
448
+ if (movement === "equal")
449
+ return "offpeak";
450
+ return undefined;
451
+ }
452
+ /**
453
+ * Historical phase for one owned physical row. Only an exact source
454
+ * provider/model route with a supported monetary policy in the modelsdev
455
+ * temporal snapshot is admitted. Non-monetary quota schedules live in a
456
+ * separate data source and therefore never appear here; an exact monetary
457
+ * policy is admitted regardless of provider name.
458
+ */
459
+ function temporalPhaseForStep(step) {
460
+ if (step.providerID === undefined || step.modelID === undefined)
461
+ return undefined;
462
+ const provider = step.providerID.trim();
463
+ const model = step.modelID.trim();
464
+ if (!provider || !model)
465
+ return undefined;
466
+ const resolution = resolvePricingKey({
467
+ providerID: step.providerID,
468
+ modelID: step.modelID,
469
+ });
470
+ if (!resolution.ok)
471
+ return undefined;
472
+ const key = resolution.key;
473
+ if (provider.toLowerCase() !== key.provider.toLowerCase())
474
+ return undefined;
475
+ if (model !== key.model)
476
+ return undefined;
477
+ const policy = getTemporalPolicy(key.provider, key.model);
478
+ if (policy === null || policy.status !== "supported")
479
+ return undefined;
480
+ const promptTokens = step.tokens.input + step.tokens.cacheRead + step.tokens.cacheWrite;
481
+ const cost = lookupCost(key.provider, key.model);
482
+ if (cost === null)
483
+ return undefined;
484
+ const base = selectCostAtContext(cost, promptTokens).rates;
485
+ const resolved = resolveTemporalRates(key.provider, key.model, step.completedAtMs, base);
486
+ if (resolved.status !== "resolved" || resolved.rates === null)
487
+ return undefined;
488
+ return temporalPhaseFromRates(policy, base, resolved.rates);
489
+ }
163
490
  function bucketFor(startMs) {
164
491
  let bucket = hours.get(startMs);
165
492
  if (!bucket) {
@@ -172,21 +499,12 @@ export function createAnalyticsModel(options = {}) {
172
499
  }
173
500
  return bucket;
174
501
  }
175
- function keyedAccumulator(map, key) {
176
- let accumulator = map.get(key);
177
- if (!accumulator) {
178
- accumulator = createAccumulator();
179
- map.set(key, accumulator);
180
- }
181
- return accumulator;
182
- }
183
502
  function addStep(step) {
184
503
  const startMs = Math.floor(step.completedAtMs / HOUR_MS) * HOUR_MS;
185
504
  if (earliestHourMs === undefined || startMs < earliestHourMs)
186
505
  earliestHourMs = startMs;
187
506
  const bucket = bucketFor(startMs);
188
507
  addStepToAccumulator(bucket.totals, step);
189
- addStepToAccumulator(keyedAccumulator(modelLifetime, `${step.providerID ?? ""}|||${step.modelID ?? ""}`), step);
190
508
  bucket.steps.set(`${step.sessionID}\u0000${step.messageID}`, step);
191
509
  let sessionSteps = ownedBySession.get(step.sessionID);
192
510
  if (!sessionSteps) {
@@ -210,13 +528,6 @@ export function createAnalyticsModel(options = {}) {
210
528
  const bucket = hours.get(startMs);
211
529
  if (bucket) {
212
530
  subtractStepFromAccumulator(bucket.totals, step);
213
- const modelKey = `${step.providerID ?? ""}|||${step.modelID ?? ""}`;
214
- const model = modelLifetime.get(modelKey);
215
- if (model) {
216
- subtractStepFromAccumulator(model, step);
217
- if (isZeroTokens(model))
218
- modelLifetime.delete(modelKey);
219
- }
220
531
  bucket.steps.delete(`${step.sessionID}\u0000${step.messageID}`);
221
532
  if (bucket.steps.size <= 0) {
222
533
  hours.delete(startMs);
@@ -368,8 +679,43 @@ export function createAnalyticsModel(options = {}) {
368
679
  else
369
680
  ownedByFp.set(fingerprint, next);
370
681
  }
682
+ function removeOccurrenceAt(fingerprint, messageID) {
683
+ const occurrences = groups.get(fingerprint);
684
+ if (!occurrences)
685
+ return false;
686
+ const index = occurrences.findIndex((entry) => entry.messageID === messageID);
687
+ if (index < 0)
688
+ return false;
689
+ occurrences.splice(index, 1);
690
+ if (occurrences.length === 0)
691
+ groups.delete(fingerprint);
692
+ return true;
693
+ }
694
+ /**
695
+ * Removes one message across fingerprints. Only used for a positive→zero
696
+ * upsert (rare) or a removal row whose payload no longer matches its owned
697
+ * fingerprint, never for the steady positive insert path.
698
+ */
699
+ function removeOccurrenceByMessage(messageID) {
700
+ for (const fingerprint of groups.keys()) {
701
+ if (!removeOccurrenceAt(fingerprint, messageID))
702
+ continue;
703
+ return fingerprint;
704
+ }
705
+ return undefined;
706
+ }
707
+ /**
708
+ * Add or replace one physical contribution. Zero-token rows never enter the
709
+ * ownership groups: they carry metadata/activity but no usage, so they are
710
+ * excluded from fork ownership, pricing, groups, and activity extents. An
711
+ * update from positive to zero therefore removes the previously owned copy.
712
+ */
371
713
  function upsertOccurrence(row) {
372
714
  const fingerprint = rawAssistantRowFingerprint(row);
715
+ if (!rawAssistantRowHasTokenUsage(row)) {
716
+ const previous = removeOccurrenceByMessage(row.messageID);
717
+ return { fingerprint, ...(previous === undefined ? {} : { previous }) };
718
+ }
373
719
  let occurrences = groups.get(fingerprint);
374
720
  if (!occurrences) {
375
721
  occurrences = [];
@@ -399,17 +745,13 @@ export function createAnalyticsModel(options = {}) {
399
745
  occurrences[index] = occurrence;
400
746
  else
401
747
  occurrences.push(occurrence);
748
+ return { fingerprint };
402
749
  }
403
750
  function removeOccurrence(row) {
404
751
  const fingerprint = rawAssistantRowFingerprint(row);
405
- const occurrences = groups.get(fingerprint);
406
- if (!occurrences)
407
- return;
408
- const index = occurrences.findIndex((entry) => entry.messageID === row.messageID);
409
- if (index >= 0)
410
- occurrences.splice(index, 1);
411
- if (occurrences.length === 0)
412
- groups.delete(fingerprint);
752
+ if (!removeOccurrenceAt(fingerprint, row.messageID)) {
753
+ removeOccurrenceByMessage(row.messageID);
754
+ }
413
755
  }
414
756
  function setMetadata(nextSessions, nextProjects) {
415
757
  const previousProjectBySession = projectBySession;
@@ -603,6 +945,212 @@ export function createAnalyticsModel(options = {}) {
603
945
  }
604
946
  return { totals, stepCount, sessions: sessionsSet };
605
947
  }
948
+ /** Populated hour starts intersecting the window, chronologically ordered. */
949
+ function populatedHourStarts(window) {
950
+ const starts = [];
951
+ for (const startMs of hours.keys()) {
952
+ if (startMs + HOUR_MS <= (window.sinceMs ?? Number.NEGATIVE_INFINITY))
953
+ continue;
954
+ if (startMs >= window.untilMs)
955
+ continue;
956
+ starts.push(startMs);
957
+ }
958
+ starts.sort((a, b) => a - b);
959
+ return starts;
960
+ }
961
+ /**
962
+ * Two passes over owned steps already retained by the hour buckets.
963
+ *
964
+ * Pass 1 accumulates flat totals, distinct sessions, pair children, and the
965
+ * earliest positive owned step matching the query filter. Groups are keyed
966
+ * by nested maps of the exact raw id (`undefined` is its own key), so a pair
967
+ * cannot collide across a delimiter and missing ids stay distinct from empty
968
+ * ones. Pass 2 ranks the visible groups, then fills per-bucket accumulators
969
+ * for just the top five series and Other, their opposite-dimension child
970
+ * breakdown, and Other's hidden same-dimension parents. One visit per owned
971
+ * step feeds every level, so inspection adds no raw scan and no price lookup.
972
+ * Bucket arrays never scale with parent/child cardinality, and no parent ×
973
+ * child cross-product or duplicate raw contribution is emitted.
974
+ */
975
+ function groupedSnapshot(query, nowMs) {
976
+ const { range, dimension } = query;
977
+ const filter = query.filter;
978
+ const window = rangeWindow(range, nowMs);
979
+ const hourStarts = populatedHourStarts(window);
980
+ function eachOwnedStep(visit) {
981
+ for (const startMs of hourStarts) {
982
+ const hour = hours.get(startMs);
983
+ if (!hour)
984
+ continue;
985
+ const hourEnd = startMs + HOUR_MS;
986
+ for (const step of hour.steps.values()) {
987
+ if (step.completedAtMs < startMs || step.completedAtMs >= hourEnd)
988
+ continue;
989
+ if (window.sinceMs !== undefined && step.completedAtMs < window.sinceMs)
990
+ continue;
991
+ if (step.completedAtMs >= window.untilMs)
992
+ continue;
993
+ visit(step);
994
+ }
995
+ }
996
+ }
997
+ const totals = createAccumulator();
998
+ const sessions = new Set();
999
+ const parentGroups = new Map();
1000
+ const childDimension = oppositeDimension(dimension);
1001
+ const lifetime = range === "lifetime";
1002
+ const wantsTemporalBreakdown = dimension === "provider" && filter?.dimension === "model" && filter.identity.kind === "known";
1003
+ const temporalPhases = wantsTemporalBreakdown
1004
+ ? new Map()
1005
+ : undefined;
1006
+ let stepCount = 0;
1007
+ let earliestMatchedMs;
1008
+ eachOwnedStep((step) => {
1009
+ if (!matchesFilter(step, filter))
1010
+ return;
1011
+ if (lifetime && (earliestMatchedMs === undefined || step.completedAtMs < earliestMatchedMs)) {
1012
+ earliestMatchedMs = step.completedAtMs;
1013
+ }
1014
+ const parentRaw = rawIdForDimension(step, dimension);
1015
+ const childRaw = rawIdForDimension(step, childDimension);
1016
+ addStepToAccumulator(totals, step);
1017
+ sessions.add(step.sessionID);
1018
+ stepCount += 1;
1019
+ let parent = parentGroups.get(parentRaw);
1020
+ if (!parent) {
1021
+ parent = createGroupNode();
1022
+ parentGroups.set(parentRaw, parent);
1023
+ }
1024
+ addStepToGroupNode(parent, step);
1025
+ let child = parent.children.get(childRaw);
1026
+ if (!child) {
1027
+ child = createGroupNode();
1028
+ parent.children.set(childRaw, child);
1029
+ }
1030
+ addStepToGroupNode(child, step);
1031
+ if (temporalPhases !== undefined) {
1032
+ const phase = temporalPhaseForStep(step);
1033
+ if (phase !== undefined) {
1034
+ let phases = temporalPhases.get(parentRaw);
1035
+ if (!phases) {
1036
+ phases = { peak: createAccumulator(), offpeak: createAccumulator() };
1037
+ temporalPhases.set(parentRaw, phases);
1038
+ }
1039
+ addStepToAccumulator(phases[phase], step);
1040
+ }
1041
+ }
1042
+ });
1043
+ // Lifetime buckets start at the exact first positive owned step for this
1044
+ // query filter — never session metadata, and never an older unrelated
1045
+ // model/provider. Finite ranges anchor on their rolling window and ignore
1046
+ // this value. An empty lifetime still renders its fallback current bucket.
1047
+ const boundaries = planRangeBuckets(range, nowMs, lifetime ? earliestMatchedMs : undefined, {
1048
+ timeZone,
1049
+ });
1050
+ const bucketStarts = boundaries.map((boundary) => boundary.startMs);
1051
+ const ranked = [...parentGroups]
1052
+ .map(([raw, node]) => ({ raw, node }))
1053
+ .sort(compareGroupEntries);
1054
+ const rows = ranked.map((entry) => materializeGroupRow(entry.raw, entry.node));
1055
+ let temporalBreakdown;
1056
+ if (temporalPhases !== undefined) {
1057
+ const breakdownRows = [];
1058
+ for (const entry of ranked) {
1059
+ const phases = temporalPhases.get(entry.raw);
1060
+ if (phases === undefined)
1061
+ continue;
1062
+ breakdownRows.push({
1063
+ identity: identityOf(entry.raw),
1064
+ peak: finalize(phases.peak),
1065
+ offpeak: finalize(phases.offpeak),
1066
+ });
1067
+ }
1068
+ if (breakdownRows.length > 0)
1069
+ temporalBreakdown = { rows: breakdownRows };
1070
+ }
1071
+ const topEntries = ranked.slice(0, 5);
1072
+ const otherEntries = ranked.slice(5);
1073
+ const topBucketTotals = topEntries.map(() => new Map());
1074
+ const topChildBuckets = topEntries.map(() => new Map());
1075
+ const otherBucketTotals = otherEntries.length > 0 ? new Map() : undefined;
1076
+ const otherChildBuckets = otherEntries.length > 0 ? new Map() : undefined;
1077
+ const otherParentBuckets = otherEntries.length > 0 ? new Map() : undefined;
1078
+ const seriesIndexByParent = new Map();
1079
+ topEntries.forEach((entry, index) => {
1080
+ seriesIndexByParent.set(entry.raw, index);
1081
+ });
1082
+ if (ranked.length > 0) {
1083
+ eachOwnedStep((step) => {
1084
+ if (!matchesFilter(step, filter))
1085
+ return;
1086
+ const bucketIndex = bucketIndexAt(bucketStarts, step.completedAtMs);
1087
+ if (bucketIndex < 0)
1088
+ return;
1089
+ const parentRaw = rawIdForDimension(step, dimension);
1090
+ const childRaw = rawIdForDimension(step, childDimension);
1091
+ const seriesIndex = seriesIndexByParent.get(parentRaw);
1092
+ if (seriesIndex !== undefined) {
1093
+ const bucketTotals = topBucketTotals[seriesIndex];
1094
+ if (bucketTotals)
1095
+ addStepToBucket(bucketTotals, step, bucketIndex);
1096
+ const childBuckets = topChildBuckets[seriesIndex];
1097
+ if (childBuckets) {
1098
+ addStepToEntityBucket(childBuckets, childRaw, step, bucketIndex);
1099
+ }
1100
+ return;
1101
+ }
1102
+ if (otherBucketTotals)
1103
+ addStepToBucket(otherBucketTotals, step, bucketIndex);
1104
+ if (otherChildBuckets) {
1105
+ addStepToEntityBucket(otherChildBuckets, childRaw, step, bucketIndex);
1106
+ }
1107
+ if (otherParentBuckets) {
1108
+ addStepToEntityBucket(otherParentBuckets, parentRaw, step, bucketIndex);
1109
+ }
1110
+ });
1111
+ }
1112
+ const topSources = topEntries.map((entry, index) => ({
1113
+ raw: entry.raw,
1114
+ totals: entry.node.totals,
1115
+ bucketTotals: topBucketTotals[index] ?? new Map(),
1116
+ childBuckets: topChildBuckets[index] ?? new Map(),
1117
+ }));
1118
+ let otherSource;
1119
+ if (otherEntries.length > 0) {
1120
+ const otherTotals = createAccumulator();
1121
+ for (const entry of otherEntries)
1122
+ mergeAccumulator(otherTotals, entry.node.totals);
1123
+ otherSource = {
1124
+ raw: undefined,
1125
+ totals: otherTotals,
1126
+ bucketTotals: otherBucketTotals ?? new Map(),
1127
+ childBuckets: otherChildBuckets ?? new Map(),
1128
+ parentBuckets: otherParentBuckets ?? new Map(),
1129
+ };
1130
+ }
1131
+ const snapshot = {
1132
+ dimension,
1133
+ range,
1134
+ window,
1135
+ bucketUnit: rangeBucketUnit(range),
1136
+ timeZone,
1137
+ buckets: boundaries.map((boundary) => ({
1138
+ startMs: boundary.startMs,
1139
+ endMs: boundary.endMs,
1140
+ })),
1141
+ totals: finalize(totals),
1142
+ sessionCount: sessions.size,
1143
+ stepCount,
1144
+ rows,
1145
+ series: buildSeries(topSources, otherSource, boundaries.length),
1146
+ stale: false,
1147
+ };
1148
+ if (filter !== undefined)
1149
+ snapshot.filter = filter;
1150
+ if (temporalBreakdown !== undefined)
1151
+ snapshot.temporalBreakdown = temporalBreakdown;
1152
+ return snapshot;
1153
+ }
606
1154
  function buildUsage(range, nowMs, options = {}, earliestMs = earliestActivity()) {
607
1155
  const window = rangeWindow(range, nowMs);
608
1156
  const boundaries = planRangeBuckets(range, nowMs, earliestMs, { timeZone });
@@ -788,7 +1336,6 @@ export function createAnalyticsModel(options = {}) {
788
1336
  ownedByFp.clear();
789
1337
  ownedBySession.clear();
790
1338
  hours.clear();
791
- modelLifetime.clear();
792
1339
  latestStepBySession.clear();
793
1340
  earliestStepBySession.clear();
794
1341
  earliestHourMs = undefined;
@@ -797,13 +1344,51 @@ export function createAnalyticsModel(options = {}) {
797
1344
  },
798
1345
  apply(upserts, removals) {
799
1346
  const affected = new Set();
1347
+ const applyUpsert = (row) => {
1348
+ const result = upsertOccurrence(row);
1349
+ affected.add(result.fingerprint);
1350
+ if (result.previous !== undefined)
1351
+ affected.add(result.previous);
1352
+ };
800
1353
  for (const row of removals) {
801
1354
  affected.add(rawAssistantRowFingerprint(row));
802
1355
  removeOccurrence(row);
803
1356
  }
804
- for (const row of upserts) {
805
- affected.add(rawAssistantRowFingerprint(row));
806
- upsertOccurrence(row);
1357
+ // `upserts` may be a one-shot generator (the engine hydrates the model
1358
+ // this way), so materialize references before the zero-row scan. The
1359
+ // rows themselves are already retained by the caller.
1360
+ const rows = Array.isArray(upserts) ? upserts : [...upserts];
1361
+ let hasZeroRows = false;
1362
+ for (const row of rows) {
1363
+ if (!rawAssistantRowHasTokenUsage(row)) {
1364
+ hasZeroRows = true;
1365
+ break;
1366
+ }
1367
+ }
1368
+ if (!hasZeroRows) {
1369
+ for (const row of rows)
1370
+ applyUpsert(row);
1371
+ }
1372
+ else {
1373
+ // A batch that contains zero-token rows is reconciled in two phases:
1374
+ // last occurrence per message id wins, then zero rows remove prior
1375
+ // ownership before positive rows are inserted. This keeps bulk
1376
+ // hydration linear instead of scanning all groups per zero row.
1377
+ const lastByMessage = new Map();
1378
+ for (const row of rows)
1379
+ lastByMessage.set(row.messageID, row);
1380
+ // With no owned groups there is nothing a zero row can remove. This is
1381
+ // the cold-hydration shape; skipping fingerprint work keeps it linear.
1382
+ if (groups.size > 0) {
1383
+ for (const row of lastByMessage.values()) {
1384
+ if (!rawAssistantRowHasTokenUsage(row))
1385
+ applyUpsert(row);
1386
+ }
1387
+ }
1388
+ for (const row of lastByMessage.values()) {
1389
+ if (rawAssistantRowHasTokenUsage(row))
1390
+ applyUpsert(row);
1391
+ }
807
1392
  }
808
1393
  for (const fingerprint of affected)
809
1394
  recomputeFingerprint(fingerprint);
@@ -812,6 +1397,7 @@ export function createAnalyticsModel(options = {}) {
812
1397
  hasProject: (projectId) => Object.hasOwn(projects, projectId) || sessionsByProject.has(projectId),
813
1398
  home,
814
1399
  project,
1400
+ groups: groupedSnapshot,
815
1401
  earliestActivityMs: earliestActivity,
816
1402
  ownedStepCount() {
817
1403
  let count = 0;