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.
- package/README.md +35 -19
- package/dist/contracts/analytics-entity.d.ts +32 -0
- package/dist/contracts/analytics-entity.d.ts.map +1 -0
- package/dist/contracts/analytics-entity.js +123 -0
- package/dist/contracts/analytics-entity.js.map +1 -0
- package/dist/contracts/analytics-temporal.d.ts +39 -0
- package/dist/contracts/analytics-temporal.d.ts.map +1 -0
- package/dist/contracts/analytics-temporal.js +11 -0
- package/dist/contracts/analytics-temporal.js.map +1 -0
- package/dist/contracts/build-identity.js +1 -1
- package/dist/contracts/collision-safe-key.d.ts +14 -0
- package/dist/contracts/collision-safe-key.d.ts.map +1 -0
- package/dist/contracts/collision-safe-key.js +28 -0
- package/dist/contracts/collision-safe-key.js.map +1 -0
- package/dist/contracts/dashboard.d.ts +152 -0
- package/dist/contracts/dashboard.d.ts.map +1 -1
- package/dist/contracts/dashboard.js.map +1 -1
- package/dist/contracts/temporal.d.ts +126 -0
- package/dist/contracts/temporal.d.ts.map +1 -0
- package/dist/contracts/temporal.js +10 -0
- package/dist/contracts/temporal.js.map +1 -0
- package/dist/data/modelsdev-pricing.min.json +1 -1064
- package/dist/data/modelsdev-temporal.min.json +3075 -0
- package/dist/gui/aggregation.d.ts.map +1 -1
- package/dist/gui/aggregation.js +9 -0
- package/dist/gui/aggregation.js.map +1 -1
- package/dist/gui/analytics-bridge.d.ts.map +1 -1
- package/dist/gui/analytics-bridge.js +14 -0
- package/dist/gui/analytics-bridge.js.map +1 -1
- package/dist/gui/analytics-engine.d.ts +3 -1
- package/dist/gui/analytics-engine.d.ts.map +1 -1
- package/dist/gui/analytics-engine.js +228 -7
- package/dist/gui/analytics-engine.js.map +1 -1
- package/dist/gui/analytics-model.d.ts +7 -5
- package/dist/gui/analytics-model.d.ts.map +1 -1
- package/dist/gui/analytics-model.js +625 -39
- package/dist/gui/analytics-model.js.map +1 -1
- package/dist/gui/analytics-pricing-revision.d.ts +43 -0
- package/dist/gui/analytics-pricing-revision.d.ts.map +1 -0
- package/dist/gui/analytics-pricing-revision.js +160 -0
- package/dist/gui/analytics-pricing-revision.js.map +1 -0
- package/dist/gui/analytics-protocol.d.ts +6 -2
- package/dist/gui/analytics-protocol.d.ts.map +1 -1
- package/dist/gui/analytics-protocol.js.map +1 -1
- package/dist/gui/analytics-service.d.ts +3 -1
- package/dist/gui/analytics-service.d.ts.map +1 -1
- package/dist/gui/analytics-service.js +14 -0
- package/dist/gui/analytics-service.js.map +1 -1
- package/dist/gui/analytics-state.d.ts +13 -0
- package/dist/gui/analytics-state.d.ts.map +1 -1
- package/dist/gui/analytics-state.js +25 -0
- package/dist/gui/analytics-state.js.map +1 -1
- package/dist/gui/analytics-worker-runtime.d.ts +5 -0
- package/dist/gui/analytics-worker-runtime.d.ts.map +1 -1
- package/dist/gui/analytics-worker-runtime.js +6 -0
- package/dist/gui/analytics-worker-runtime.js.map +1 -1
- package/dist/gui/config.d.ts +2 -2
- package/dist/gui/config.d.ts.map +1 -1
- package/dist/gui/config.js +18 -0
- package/dist/gui/config.js.map +1 -1
- package/dist/gui/lifecycle.d.ts +1 -1
- package/dist/gui/lifecycle.d.ts.map +1 -1
- package/dist/gui/lifecycle.js +1 -0
- package/dist/gui/lifecycle.js.map +1 -1
- package/dist/gui/server.d.ts.map +1 -1
- package/dist/gui/server.js +62 -0
- package/dist/gui/server.js.map +1 -1
- package/dist/gui/snapshot-service.d.ts +3 -1
- package/dist/gui/snapshot-service.d.ts.map +1 -1
- package/dist/gui/snapshot-service.js +10 -0
- package/dist/gui/snapshot-service.js.map +1 -1
- package/dist/gui/sources.d.ts +1 -1
- package/dist/gui/sources.d.ts.map +1 -1
- package/dist/gui/sources.js +53 -4
- package/dist/gui/sources.js.map +1 -1
- package/dist/gui/temporal-quota-policy-data.d.ts +24 -0
- package/dist/gui/temporal-quota-policy-data.d.ts.map +1 -0
- package/dist/gui/temporal-quota-policy-data.js +43 -0
- package/dist/gui/temporal-quota-policy-data.js.map +1 -0
- package/dist/gui/temporal-quota-policy.d.ts +38 -0
- package/dist/gui/temporal-quota-policy.d.ts.map +1 -0
- package/dist/gui/temporal-quota-policy.js +182 -0
- package/dist/gui/temporal-quota-policy.js.map +1 -0
- package/dist/gui/temporal-status.d.ts +53 -0
- package/dist/gui/temporal-status.d.ts.map +1 -0
- package/dist/gui/temporal-status.js +815 -0
- package/dist/gui/temporal-status.js.map +1 -0
- package/dist/lib/config.d.ts +1 -1
- package/dist/lib/config.d.ts.map +1 -1
- package/dist/lib/config.js +33 -0
- package/dist/lib/config.js.map +1 -1
- package/dist/lib/cursor-usage.d.ts.map +1 -1
- package/dist/lib/cursor-usage.js +8 -2
- package/dist/lib/cursor-usage.js.map +1 -1
- package/dist/lib/modelsdev-pricing.d.ts +54 -1
- package/dist/lib/modelsdev-pricing.d.ts.map +1 -1
- package/dist/lib/modelsdev-pricing.js +284 -43
- package/dist/lib/modelsdev-pricing.js.map +1 -1
- package/dist/lib/modelsdev-temporal.d.ts +143 -0
- package/dist/lib/modelsdev-temporal.d.ts.map +1 -0
- package/dist/lib/modelsdev-temporal.js +896 -0
- package/dist/lib/modelsdev-temporal.js.map +1 -0
- package/dist/lib/opencode-console-auth.d.ts +19 -0
- package/dist/lib/opencode-console-auth.d.ts.map +1 -1
- package/dist/lib/opencode-console-auth.js +263 -3
- package/dist/lib/opencode-console-auth.js.map +1 -1
- package/dist/lib/opencode-storage.d.ts +26 -11
- package/dist/lib/opencode-storage.d.ts.map +1 -1
- package/dist/lib/opencode-storage.js +33 -56
- package/dist/lib/opencode-storage.js.map +1 -1
- package/dist/lib/quota-providers-local.d.ts.map +1 -1
- package/dist/lib/quota-providers-local.js +13 -3
- package/dist/lib/quota-providers-local.js.map +1 -1
- package/dist/lib/quota-stats-format.d.ts.map +1 -1
- package/dist/lib/quota-stats-format.js +28 -6
- package/dist/lib/quota-stats-format.js.map +1 -1
- package/dist/lib/quota-stats.d.ts +71 -7
- package/dist/lib/quota-stats.d.ts.map +1 -1
- package/dist/lib/quota-stats.js +417 -22
- package/dist/lib/quota-stats.js.map +1 -1
- package/dist/lib/scoped-query-chunks.d.ts +15 -0
- package/dist/lib/scoped-query-chunks.d.ts.map +1 -0
- package/dist/lib/scoped-query-chunks.js +48 -0
- package/dist/lib/scoped-query-chunks.js.map +1 -0
- package/dist/lib/token-cost.d.ts +29 -0
- package/dist/lib/token-cost.d.ts.map +1 -1
- package/dist/lib/token-cost.js +74 -10
- package/dist/lib/token-cost.js.map +1 -1
- package/dist/lib/types.d.ts +6 -0
- package/dist/lib/types.d.ts.map +1 -1
- package/dist/lib/types.js +1 -0
- package/dist/lib/types.js.map +1 -1
- package/dist/provider-logos/NOTICE.md +12 -0
- package/dist/provider-logos/OPENCODE-MIT.txt +21 -0
- package/dist/provider-logos/OPENCODE-NOTICE.md +12 -0
- package/dist/provider-logos/UPSTREAM-MIT.txt +21 -0
- package/dist/providers/cache-policies.d.ts.map +1 -1
- package/dist/providers/cache-policies.js +4 -3
- package/dist/providers/cache-policies.js.map +1 -1
- package/dist/providers/opencode-go.d.ts.map +1 -1
- package/dist/providers/opencode-go.js +2 -0
- package/dist/providers/opencode-go.js.map +1 -1
- package/dist/providers/opencode-zen.d.ts.map +1 -1
- package/dist/providers/opencode-zen.js +2 -0
- package/dist/providers/opencode-zen.js.map +1 -1
- package/dist/ui/assets/{index-D3-Yn_WA.css → index-Cs-nrywz.css} +1 -1
- package/dist/ui/assets/index-D9lFKhSN.js +9 -0
- package/dist/ui/assets/popover-DKRrwr_K.js +1 -0
- package/dist/ui/assets/popover-mkHTmNjv.css +1 -0
- package/dist/ui/assets/providers/302ai.svg +7 -0
- package/dist/ui/assets/providers/abacus.svg +14 -0
- package/dist/ui/assets/providers/abliteration-ai.svg +6 -0
- package/dist/ui/assets/providers/above.svg +3 -0
- package/dist/ui/assets/providers/agentrouter.svg +4 -0
- package/dist/ui/assets/providers/agnes.svg +1 -0
- package/dist/ui/assets/providers/ai-router.svg +5 -0
- package/dist/ui/assets/providers/ai21.svg +3 -0
- package/dist/ui/assets/providers/aiand.svg +4 -0
- package/dist/ui/assets/providers/aihubmix.svg +3 -0
- package/dist/ui/assets/providers/aimlapi.svg +3 -0
- package/dist/ui/assets/providers/ainetcafe.svg +1 -0
- package/dist/ui/assets/providers/aixy.svg +4 -0
- package/dist/ui/assets/providers/aki-io.svg +7 -0
- package/dist/ui/assets/providers/alibaba-cn.svg +3 -0
- package/dist/ui/assets/providers/alibaba-coding-plan-cn.svg +3 -0
- package/dist/ui/assets/providers/alibaba-coding-plan.svg +3 -0
- package/dist/ui/assets/providers/alibaba-token-plan.svg +3 -0
- package/dist/ui/assets/providers/alibaba.svg +3 -0
- package/dist/ui/assets/providers/amazon-bedrock.svg +3 -0
- package/dist/ui/assets/providers/ambient.svg +3 -0
- package/dist/ui/assets/providers/amd.svg +3 -0
- package/dist/ui/assets/providers/anthropic.svg +3 -0
- package/dist/ui/assets/providers/anyapi.svg +3 -0
- package/dist/ui/assets/providers/arcee.svg +3 -0
- package/dist/ui/assets/providers/atomic-chat.svg +1 -0
- package/dist/ui/assets/providers/auriko.svg +6 -0
- package/dist/ui/assets/providers/azure-cognitive-services.svg +3 -0
- package/dist/ui/assets/providers/azure.svg +3 -0
- package/dist/ui/assets/providers/bailing.svg +3 -0
- package/dist/ui/assets/providers/baseten.svg +3 -0
- package/dist/ui/assets/providers/bee.svg +1 -0
- package/dist/ui/assets/providers/berget.svg +3 -0
- package/dist/ui/assets/providers/blueclaw.svg +3 -0
- package/dist/ui/assets/providers/bothub.svg +33 -0
- package/dist/ui/assets/providers/boundless.svg +12 -0
- package/dist/ui/assets/providers/cerebras.svg +4 -0
- package/dist/ui/assets/providers/clarifai.svg +3 -0
- package/dist/ui/assets/providers/claudinio.svg +19 -0
- package/dist/ui/assets/providers/cloudferro-sherlock.svg +5 -0
- package/dist/ui/assets/providers/cloudflare-ai-gateway.svg +4 -0
- package/dist/ui/assets/providers/cloudflare-workers-ai.svg +4 -0
- package/dist/ui/assets/providers/cohere.svg +5 -0
- package/dist/ui/assets/providers/commandcode.svg +11 -0
- package/dist/ui/assets/providers/coralbricks.svg +6 -0
- package/dist/ui/assets/providers/crossmodel.svg +5 -0
- package/dist/ui/assets/providers/crusoe.svg +23 -0
- package/dist/ui/assets/providers/daoxe.svg +3 -0
- package/dist/ui/assets/providers/databricks.svg +3 -0
- package/dist/ui/assets/providers/deepinfra.svg +4 -0
- package/dist/ui/assets/providers/deepseek.svg +3 -0
- package/dist/ui/assets/providers/digitalocean.svg +6 -0
- package/dist/ui/assets/providers/dinference.svg +1 -0
- package/dist/ui/assets/providers/drun.svg +8 -0
- package/dist/ui/assets/providers/ebcloud.svg +8 -0
- package/dist/ui/assets/providers/echo.svg +7 -0
- package/dist/ui/assets/providers/edenai.svg +8 -0
- package/dist/ui/assets/providers/empiriolabs.svg +1 -0
- package/dist/ui/assets/providers/engy.svg +1 -0
- package/dist/ui/assets/providers/evroc.svg +3 -0
- package/dist/ui/assets/providers/fastrouter.svg +3 -0
- package/dist/ui/assets/providers/fireworks-ai.svg +3 -0
- package/dist/ui/assets/providers/fluence.svg +3 -0
- package/dist/ui/assets/providers/freemodel.svg +3 -0
- package/dist/ui/assets/providers/friendli.svg +3 -0
- package/dist/ui/assets/providers/frogbot.svg +36 -0
- package/dist/ui/assets/providers/generic.svg +4 -0
- package/dist/ui/assets/providers/github-copilot.svg +3 -0
- package/dist/ui/assets/providers/gitlab.svg +3 -0
- package/dist/ui/assets/providers/google-vertex-anthropic.svg +10 -0
- package/dist/ui/assets/providers/google-vertex.svg +10 -0
- package/dist/ui/assets/providers/google.svg +3 -0
- package/dist/ui/assets/providers/greenpt.svg +6 -0
- package/dist/ui/assets/providers/groq.svg +3 -0
- package/dist/ui/assets/providers/helicone.svg +6 -0
- package/dist/ui/assets/providers/hetzner.svg +3 -0
- package/dist/ui/assets/providers/hpc-ai.svg +444 -0
- package/dist/ui/assets/providers/huggingface.svg +3 -0
- package/dist/ui/assets/providers/hyper.svg +20 -0
- package/dist/ui/assets/providers/impossibl.svg +3 -0
- package/dist/ui/assets/providers/inception.svg +14 -0
- package/dist/ui/assets/providers/inceptron.svg +14 -0
- package/dist/ui/assets/providers/inco.svg +3 -0
- package/dist/ui/assets/providers/infer.svg +4 -0
- package/dist/ui/assets/providers/inference.svg +3 -0
- package/dist/ui/assets/providers/inferx.svg +5 -0
- package/dist/ui/assets/providers/infomaniak.svg +3 -0
- package/dist/ui/assets/providers/io-net.svg +5 -0
- package/dist/ui/assets/providers/iteracompute.svg +6 -0
- package/dist/ui/assets/providers/jalapeno.svg +8 -0
- package/dist/ui/assets/providers/jiekou.svg +4 -0
- package/dist/ui/assets/providers/kenari.svg +4 -0
- package/dist/ui/assets/providers/kilo.svg +4 -0
- package/dist/ui/assets/providers/kimi-code-plan-cn.svg +3 -0
- package/dist/ui/assets/providers/kimi-code-plan-global.svg +3 -0
- package/dist/ui/assets/providers/klokintegration.svg +11 -0
- package/dist/ui/assets/providers/kosmik.svg +28 -0
- package/dist/ui/assets/providers/kuae-cloud-coding-plan.svg +3 -0
- package/dist/ui/assets/providers/lilac.svg +6 -0
- package/dist/ui/assets/providers/liquid.svg +1 -0
- package/dist/ui/assets/providers/llmgateway-providers.svg +6 -0
- package/dist/ui/assets/providers/llmgateway.svg +6 -0
- package/dist/ui/assets/providers/llmtech.svg +6 -0
- package/dist/ui/assets/providers/llmtr.svg +12 -0
- package/dist/ui/assets/providers/lmstudio.svg +3 -0
- package/dist/ui/assets/providers/longcat.svg +6 -0
- package/dist/ui/assets/providers/lowrouter.svg +8 -0
- package/dist/ui/assets/providers/lucidquery.svg +3 -0
- package/dist/ui/assets/providers/lynkr.svg +1 -0
- package/dist/ui/assets/providers/meganova.svg +3 -0
- package/dist/ui/assets/providers/melious.svg +3 -0
- package/dist/ui/assets/providers/merge-gateway.svg +4 -0
- package/dist/ui/assets/providers/meta.svg +3 -0
- package/dist/ui/assets/providers/minimax-cn-coding-plan.svg +3 -0
- package/dist/ui/assets/providers/minimax-cn.svg +3 -0
- package/dist/ui/assets/providers/minimax-coding-plan.svg +3 -0
- package/dist/ui/assets/providers/minimax.svg +3 -0
- package/dist/ui/assets/providers/mistral.svg +3 -0
- package/dist/ui/assets/providers/mixlayer.svg +8 -0
- package/dist/ui/assets/providers/moark.svg +3 -0
- package/dist/ui/assets/providers/modal.svg +3 -0
- package/dist/ui/assets/providers/model-oracle-ai.svg +11 -0
- package/dist/ui/assets/providers/modelis.svg +1 -0
- package/dist/ui/assets/providers/modelscope.svg +5 -0
- package/dist/ui/assets/providers/moonshotai-cn.svg +3 -0
- package/dist/ui/assets/providers/moonshotai.svg +3 -0
- package/dist/ui/assets/providers/munito-eu.svg +1 -0
- package/dist/ui/assets/providers/munito.svg +1 -0
- package/dist/ui/assets/providers/nan.svg +1 -0
- package/dist/ui/assets/providers/nano-gpt.svg +3 -0
- package/dist/ui/assets/providers/nearai.svg +1 -0
- package/dist/ui/assets/providers/nebius.svg +4 -0
- package/dist/ui/assets/providers/neon.svg +3 -0
- package/dist/ui/assets/providers/neosmith.svg +6 -0
- package/dist/ui/assets/providers/neuralwatt.svg +27 -0
- package/dist/ui/assets/providers/nova.svg +3 -0
- package/dist/ui/assets/providers/novita-ai.svg +10 -0
- package/dist/ui/assets/providers/nvidia.svg +3 -0
- package/dist/ui/assets/providers/oci.svg +3 -0
- package/dist/ui/assets/providers/ofox.svg +5 -0
- package/dist/ui/assets/providers/ollama-cloud.svg +7 -0
- package/dist/ui/assets/providers/openai.svg +3 -0
- package/dist/ui/assets/providers/opencode-go-g.svg +3 -0
- package/dist/ui/assets/providers/opencode-go.svg +4 -0
- package/dist/ui/assets/providers/opencode.svg +4 -0
- package/dist/ui/assets/providers/openreason.svg +8 -0
- package/dist/ui/assets/providers/openrouter.svg +3 -0
- package/dist/ui/assets/providers/opper.svg +3 -0
- package/dist/ui/assets/providers/orcarouter.svg +2 -0
- package/dist/ui/assets/providers/ovhcloud.svg +3 -0
- package/dist/ui/assets/providers/pareto.svg +5 -0
- package/dist/ui/assets/providers/pendra.svg +10 -0
- package/dist/ui/assets/providers/perplexity-agent.svg +3 -0
- package/dist/ui/assets/providers/perplexity.svg +3 -0
- package/dist/ui/assets/providers/pioneer.svg +3 -0
- package/dist/ui/assets/providers/poe.svg +7 -0
- package/dist/ui/assets/providers/poolside.svg +3 -0
- package/dist/ui/assets/providers/prime.svg +7 -0
- package/dist/ui/assets/providers/privatemode-ai.svg +5 -0
- package/dist/ui/assets/providers/qihang-ai.svg +9 -0
- package/dist/ui/assets/providers/qiniu-ai.svg +7 -0
- package/dist/ui/assets/providers/qvac.svg +6 -0
- package/dist/ui/assets/providers/reflection.svg +3 -0
- package/dist/ui/assets/providers/regolo-ai.svg +45 -0
- package/dist/ui/assets/providers/routing-run.svg +4 -0
- package/dist/ui/assets/providers/runinfra.svg +10 -0
- package/dist/ui/assets/providers/salad-cloud.svg +15 -0
- package/dist/ui/assets/providers/sambanova.svg +26 -0
- package/dist/ui/assets/providers/scaleway.svg +5 -0
- package/dist/ui/assets/providers/scnet-token-plan.svg +8 -0
- package/dist/ui/assets/providers/scx-ai.svg +1 -0
- package/dist/ui/assets/providers/sensenova.svg +18 -0
- package/dist/ui/assets/providers/siliconflow-cn.svg +3 -0
- package/dist/ui/assets/providers/siliconflow.svg +3 -0
- package/dist/ui/assets/providers/snowflake-cortex.svg +3 -0
- package/dist/ui/assets/providers/stackit.svg +3 -0
- package/dist/ui/assets/providers/standardcompute.svg +5 -0
- package/dist/ui/assets/providers/stepfun-ai-step-plan.svg +16 -0
- package/dist/ui/assets/providers/stepfun-ai.svg +16 -0
- package/dist/ui/assets/providers/stepfun-step-plan.svg +16 -0
- package/dist/ui/assets/providers/stepfun.svg +16 -0
- package/dist/ui/assets/providers/subconscious.svg +3 -0
- package/dist/ui/assets/providers/submodel.svg +3 -0
- package/dist/ui/assets/providers/teamorouter.svg +3 -0
- package/dist/ui/assets/providers/tempr.svg +4 -0
- package/dist/ui/assets/providers/tencent-coding-plan.svg +5 -0
- package/dist/ui/assets/providers/tencent-token-plan.svg +3 -0
- package/dist/ui/assets/providers/tencent-tokenhub.svg +3 -0
- package/dist/ui/assets/providers/tensorx.svg +6 -0
- package/dist/ui/assets/providers/the-grid-ai.svg +14 -0
- package/dist/ui/assets/providers/thinkingmachines.svg +3 -0
- package/dist/ui/assets/providers/tinfoil.svg +3 -0
- package/dist/ui/assets/providers/togetherai.svg +4 -0
- package/dist/ui/assets/providers/tokengo.svg +3 -0
- package/dist/ui/assets/providers/tokenrouter.svg +4 -0
- package/dist/ui/assets/providers/trustedrouter.svg +4 -0
- package/dist/ui/assets/providers/umans-ai-coding-plan.svg +29 -0
- package/dist/ui/assets/providers/umans-ai.svg +29 -0
- package/dist/ui/assets/providers/unorouter.svg +7 -0
- package/dist/ui/assets/providers/vancine.svg +6 -0
- package/dist/ui/assets/providers/venice.svg +4 -0
- package/dist/ui/assets/providers/vercel.svg +3 -0
- package/dist/ui/assets/providers/vispark.svg +3 -0
- package/dist/ui/assets/providers/vivgrid.svg +4 -0
- package/dist/ui/assets/providers/volcengine-coding-plan.svg +3 -0
- package/dist/ui/assets/providers/volcengine.svg +3 -0
- package/dist/ui/assets/providers/vultr.svg +6 -0
- package/dist/ui/assets/providers/wafer.ai.svg +3 -0
- package/dist/ui/assets/providers/wallaby.svg +4 -0
- package/dist/ui/assets/providers/wandb.svg +6 -0
- package/dist/ui/assets/providers/watsonx.svg +5 -0
- package/dist/ui/assets/providers/xai.svg +3 -0
- package/dist/ui/assets/providers/xiaomi-token-plan-ams.svg +3 -0
- package/dist/ui/assets/providers/xiaomi-token-plan-cn.svg +3 -0
- package/dist/ui/assets/providers/xiaomi-token-plan-sgp.svg +3 -0
- package/dist/ui/assets/providers/xiaomi.svg +3 -0
- package/dist/ui/assets/providers/xpersona.svg +8 -0
- package/dist/ui/assets/providers/zai-coding-plan.svg +3 -0
- package/dist/ui/assets/providers/zai.svg +3 -0
- package/dist/ui/assets/providers/zeldoc.svg +3 -0
- package/dist/ui/assets/providers/zenifra.svg +4 -0
- package/dist/ui/assets/providers/zenmux.svg +4 -0
- package/dist/ui/assets/providers/zhipuai-coding-plan.svg +3 -0
- package/dist/ui/assets/providers/zhipuai.svg +3 -0
- package/dist/ui/index.html +2 -2
- package/package.json +5 -1
- package/dist/ui/assets/index-CPEiQt-C.js +0 -8
package/dist/lib/quota-stats.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import { encodeIdentityKey } from "../contracts/collision-safe-key.js";
|
|
1
2
|
import { isCursorModelId, isCursorProviderId, lookupCursorLocalCost, resolveCursorModel, } from "./cursor-pricing.js";
|
|
2
|
-
import { hasCost, hasModel, hasProvider, isModelsDevProviderId, listProvidersForModelId, lookupCost, } from "./modelsdev-pricing.js";
|
|
3
|
+
import { hasCatalogModel, hasCost, hasModel, hasProvider, isModelsDevProviderId, listProvidersForModelId, lookupCost, selectCostAtContext, } from "./modelsdev-pricing.js";
|
|
4
|
+
import { getTemporalPolicy, resolveTemporalRates } from "./modelsdev-temporal.js";
|
|
3
5
|
import { getOpenCodeDbPath } from "./opencode-db-path.js";
|
|
4
6
|
import { iterAssistantMessages, iterAssistantMessagesForSession, iterAssistantMessagesForSessions, readAllSessionsIndex, SessionNotFoundError, } from "./opencode-storage.js";
|
|
5
7
|
import { addTokenBuckets, emptyTokenBuckets, tokenBucketsFromMessage } from "./token-buckets.js";
|
|
6
|
-
import { calculateUsdFromTokenBuckets } from "./token-cost.js";
|
|
8
|
+
import { calculateUsdFromTokenBuckets, splitTokenBucketsByRate, tokenRateCoverage, } from "./token-cost.js";
|
|
7
9
|
// Re-export for consumers
|
|
8
10
|
export { SessionNotFoundError } from "./opencode-storage.js";
|
|
9
11
|
function normalizeModelId(raw) {
|
|
@@ -33,6 +35,36 @@ function freeSuffixCandidates(modelId) {
|
|
|
33
35
|
candidates.push(stripped);
|
|
34
36
|
return candidates.filter((value, index, list) => list.indexOf(value) === index);
|
|
35
37
|
}
|
|
38
|
+
function catalogCandidatesFor(...models) {
|
|
39
|
+
const candidates = new Set();
|
|
40
|
+
for (const model of models) {
|
|
41
|
+
if (!model)
|
|
42
|
+
continue;
|
|
43
|
+
for (const candidate of freeSuffixCandidates(model))
|
|
44
|
+
candidates.add(candidate);
|
|
45
|
+
}
|
|
46
|
+
return [...candidates];
|
|
47
|
+
}
|
|
48
|
+
function findCatalogModel(providerID, candidates) {
|
|
49
|
+
if (!providerID)
|
|
50
|
+
return null;
|
|
51
|
+
for (const candidate of candidates) {
|
|
52
|
+
if (hasCatalogModel(providerID, candidate))
|
|
53
|
+
return candidate;
|
|
54
|
+
}
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
function findPricedExactModel(providerID, candidates) {
|
|
58
|
+
if (!providerID)
|
|
59
|
+
return null;
|
|
60
|
+
for (const candidate of candidates) {
|
|
61
|
+
if (!candidate)
|
|
62
|
+
continue;
|
|
63
|
+
if (hasCost(providerID, candidate))
|
|
64
|
+
return candidate;
|
|
65
|
+
}
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
36
68
|
function pickBestModelForProvider(providerID, candidates) {
|
|
37
69
|
for (const candidate of candidates) {
|
|
38
70
|
if (hasCost(providerID, candidate))
|
|
@@ -57,6 +89,35 @@ function parseModelIdHint(rawModelId) {
|
|
|
57
89
|
return { providerHint: trimmed.slice(0, -1) };
|
|
58
90
|
return { providerHint: trimmed.slice(0, lastSlash), modelPart: trimmed.slice(lastSlash + 1) };
|
|
59
91
|
}
|
|
92
|
+
/**
|
|
93
|
+
* Exact provider-scoped pricing aliases. These only choose the priced key used
|
|
94
|
+
* for cost lookup; source provider/model ids stay untouched. Keep entries
|
|
95
|
+
* literal instead of deriving nearby versions.
|
|
96
|
+
*/
|
|
97
|
+
const PROVIDER_MODEL_PRICING_ALIASES = {
|
|
98
|
+
"opencode-go": {
|
|
99
|
+
"deepseek-v4-flash": "deepseek-v4.1-flash",
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
/**
|
|
103
|
+
* Resolve an explicitly authoritative provider-scoped alias to a priced model.
|
|
104
|
+
* These mappings are deliberate, so they win over catalog presence heuristics.
|
|
105
|
+
*/
|
|
106
|
+
function resolveExplicitPricingAlias(providerID, ...models) {
|
|
107
|
+
if (!providerID)
|
|
108
|
+
return null;
|
|
109
|
+
const aliases = PROVIDER_MODEL_PRICING_ALIASES[providerID];
|
|
110
|
+
if (!aliases)
|
|
111
|
+
return null;
|
|
112
|
+
for (const model of models) {
|
|
113
|
+
if (!model)
|
|
114
|
+
continue;
|
|
115
|
+
const alias = aliases[model];
|
|
116
|
+
if (alias && hasCost(providerID, alias))
|
|
117
|
+
return alias;
|
|
118
|
+
}
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
60
121
|
const SOURCE_PROVIDER_ALIASES = {
|
|
61
122
|
cursor: "cursor",
|
|
62
123
|
"cursor-acp": "cursor",
|
|
@@ -71,6 +132,8 @@ const SOURCE_PROVIDER_ALIASES = {
|
|
|
71
132
|
"kimi-code-plan-cn": "moonshotai",
|
|
72
133
|
"zai-coding-plan": "zai",
|
|
73
134
|
glm: "zai",
|
|
135
|
+
// Same actual source provider, different registration synonym.
|
|
136
|
+
"opencode-go-subscription": "opencode-go",
|
|
74
137
|
};
|
|
75
138
|
function normalizeSourceProviderId(raw) {
|
|
76
139
|
if (!raw || typeof raw !== "string")
|
|
@@ -165,6 +228,9 @@ function resolveModelForProvider(providerID, normalizedModel) {
|
|
|
165
228
|
const preferredDirect = pickBestModelForProvider(providerID, freeSuffixCandidates(normalizedModel));
|
|
166
229
|
if (preferredDirect)
|
|
167
230
|
return preferredDirect;
|
|
231
|
+
const pricingAlias = resolveExplicitPricingAlias(providerID, normalizedModel);
|
|
232
|
+
if (pricingAlias)
|
|
233
|
+
return pricingAlias;
|
|
168
234
|
// Some source ids include "-thinking" while snapshot keeps a base key (or vice versa).
|
|
169
235
|
if (normalizedModel.toLowerCase().endsWith("-thinking")) {
|
|
170
236
|
const withoutThinking = normalizedModel.slice(0, -"-thinking".length);
|
|
@@ -209,7 +275,29 @@ export function resolvePricingKey(source) {
|
|
|
209
275
|
unknown: { sourceProviderID: srcProvider, sourceModelID: srcModel, reason: "missing_model" },
|
|
210
276
|
};
|
|
211
277
|
}
|
|
212
|
-
const
|
|
278
|
+
const rawModelID = source.modelID.trim();
|
|
279
|
+
const sourceProviderHint = normalizeSourceProviderId(source.providerID);
|
|
280
|
+
// Preserve an exact source-provider route first. This keeps provider-owned
|
|
281
|
+
// catalogs (for example opencode/big-pickle or openrouter vendor-prefixed
|
|
282
|
+
// model ids) from being rewritten into a different provider's key.
|
|
283
|
+
if (sourceProviderHint && rawModelID && hasCost(sourceProviderHint, rawModelID)) {
|
|
284
|
+
return {
|
|
285
|
+
ok: true,
|
|
286
|
+
key: { provider: sourceProviderHint, model: rawModelID },
|
|
287
|
+
method: "source_provider",
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
if (sourceProviderHint && rawModelID.startsWith(`${sourceProviderHint}/`)) {
|
|
291
|
+
const unprefixedModelID = rawModelID.slice(sourceProviderHint.length + 1);
|
|
292
|
+
if (hasCost(sourceProviderHint, unprefixedModelID)) {
|
|
293
|
+
return {
|
|
294
|
+
ok: true,
|
|
295
|
+
key: { provider: sourceProviderHint, model: unprefixedModelID },
|
|
296
|
+
method: "source_provider",
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
const parsed = parseModelIdHint(rawModelID);
|
|
213
301
|
if (!parsed.modelPart) {
|
|
214
302
|
return {
|
|
215
303
|
ok: false,
|
|
@@ -221,7 +309,6 @@ export function resolvePricingKey(source) {
|
|
|
221
309
|
};
|
|
222
310
|
}
|
|
223
311
|
const normalizedModel = normalizeModelId(parsed.modelPart);
|
|
224
|
-
const sourceProviderHint = normalizeSourceProviderId(source.providerID);
|
|
225
312
|
const modelProviderHint = normalizeSourceProviderId(parsed.providerHint);
|
|
226
313
|
const tryProvider = (providerID, method, modelIDHint = normalizedModel) => {
|
|
227
314
|
if (!providerID)
|
|
@@ -246,9 +333,98 @@ export function resolvePricingKey(source) {
|
|
|
246
333
|
return resolved;
|
|
247
334
|
}
|
|
248
335
|
}
|
|
336
|
+
// An explicit provider-scoped alias is a deliberate mapping and wins over
|
|
337
|
+
// catalog presence, but only after exact priced keys were tried above.
|
|
338
|
+
const sourcePricingAlias = resolveExplicitPricingAlias(sourceProviderHint, normalizedModel);
|
|
339
|
+
if (sourcePricingAlias && sourceProviderHint) {
|
|
340
|
+
return {
|
|
341
|
+
ok: true,
|
|
342
|
+
key: { provider: sourceProviderHint, model: sourcePricingAlias },
|
|
343
|
+
method: "source_provider",
|
|
344
|
+
};
|
|
345
|
+
}
|
|
346
|
+
// The source catalog is authoritative for presence. Consult it BEFORE any
|
|
347
|
+
// heuristic fallback (free-suffix stripping, -thinking, preview aliases, ...)
|
|
348
|
+
// so a catalog-listed model without a cost cannot inherit a different priced
|
|
349
|
+
// model.
|
|
350
|
+
const unprefixedRawModelID = sourceProviderHint && rawModelID.startsWith(`${sourceProviderHint}/`)
|
|
351
|
+
? rawModelID.slice(sourceProviderHint.length + 1)
|
|
352
|
+
: rawModelID;
|
|
353
|
+
const catalogCandidates = catalogCandidatesFor(rawModelID, unprefixedRawModelID, parsed.modelPart.trim(), normalizedModel);
|
|
354
|
+
const sourceCatalogModel = findCatalogModel(sourceProviderHint, catalogCandidates);
|
|
355
|
+
if (sourceCatalogModel && sourceProviderHint) {
|
|
356
|
+
return {
|
|
357
|
+
ok: true,
|
|
358
|
+
key: { provider: sourceProviderHint, model: sourceCatalogModel },
|
|
359
|
+
method: "source_provider",
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
// Only now run same-provider heuristics (free-suffix stripping, -thinking,
|
|
363
|
+
// Gemini preview, Kimi/Anthropic variants).
|
|
249
364
|
const fromSourceProvider = tryProvider(sourceProviderHint, "source_provider");
|
|
250
365
|
if (fromSourceProvider)
|
|
251
366
|
return fromSourceProvider;
|
|
367
|
+
// A non-listed gateway may still pass an explicit provider prefix. Try the
|
|
368
|
+
// leading segment as a models.dev provider (and its catalog) after the source
|
|
369
|
+
// guard, so a listed source provider cannot be rewritten into a vendor route.
|
|
370
|
+
const firstSlash = rawModelID.indexOf("/");
|
|
371
|
+
if ((!sourceProviderHint || !isModelsDevProviderId(sourceProviderHint)) && firstSlash > 0) {
|
|
372
|
+
const firstSegmentProvider = normalizeSourceProviderId(rawModelID.slice(0, firstSlash));
|
|
373
|
+
const firstSegmentModelPart = rawModelID.slice(firstSlash + 1);
|
|
374
|
+
if (firstSegmentProvider &&
|
|
375
|
+
firstSegmentProvider !== sourceProviderHint &&
|
|
376
|
+
isModelsDevProviderId(firstSegmentProvider)) {
|
|
377
|
+
if (hasCost(firstSegmentProvider, firstSegmentModelPart)) {
|
|
378
|
+
return {
|
|
379
|
+
ok: true,
|
|
380
|
+
key: { provider: firstSegmentProvider, model: firstSegmentModelPart },
|
|
381
|
+
method: "model_prefix",
|
|
382
|
+
};
|
|
383
|
+
}
|
|
384
|
+
const firstSegmentAlias = resolveExplicitPricingAlias(firstSegmentProvider, normalizedModel);
|
|
385
|
+
if (firstSegmentAlias) {
|
|
386
|
+
return {
|
|
387
|
+
ok: true,
|
|
388
|
+
key: { provider: firstSegmentProvider, model: firstSegmentAlias },
|
|
389
|
+
method: "model_prefix",
|
|
390
|
+
};
|
|
391
|
+
}
|
|
392
|
+
const firstSegmentCatalogModel = findCatalogModel(firstSegmentProvider, catalogCandidatesFor(firstSegmentModelPart, parsed.modelPart.trim(), normalizedModel));
|
|
393
|
+
if (firstSegmentCatalogModel) {
|
|
394
|
+
return {
|
|
395
|
+
ok: true,
|
|
396
|
+
key: { provider: firstSegmentProvider, model: firstSegmentCatalogModel },
|
|
397
|
+
method: "model_prefix",
|
|
398
|
+
};
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
// For a model-prefix route, prefer an exact priced key, then an explicit
|
|
403
|
+
// provider-scoped alias, then catalog presence, and only then heuristics.
|
|
404
|
+
const prefixExactModel = findPricedExactModel(modelProviderHint, [parsed.modelPart.trim()]);
|
|
405
|
+
if (prefixExactModel && modelProviderHint) {
|
|
406
|
+
return {
|
|
407
|
+
ok: true,
|
|
408
|
+
key: { provider: modelProviderHint, model: prefixExactModel },
|
|
409
|
+
method: "model_prefix",
|
|
410
|
+
};
|
|
411
|
+
}
|
|
412
|
+
const prefixPricingAlias = resolveExplicitPricingAlias(modelProviderHint, normalizedModel);
|
|
413
|
+
if (prefixPricingAlias && modelProviderHint) {
|
|
414
|
+
return {
|
|
415
|
+
ok: true,
|
|
416
|
+
key: { provider: modelProviderHint, model: prefixPricingAlias },
|
|
417
|
+
method: "model_prefix",
|
|
418
|
+
};
|
|
419
|
+
}
|
|
420
|
+
const prefixCatalogModel = findCatalogModel(modelProviderHint, catalogCandidates);
|
|
421
|
+
if (prefixCatalogModel && modelProviderHint) {
|
|
422
|
+
return {
|
|
423
|
+
ok: true,
|
|
424
|
+
key: { provider: modelProviderHint, model: prefixCatalogModel },
|
|
425
|
+
method: "model_prefix",
|
|
426
|
+
};
|
|
427
|
+
}
|
|
252
428
|
const fromModelPrefix = tryProvider(modelProviderHint, "model_prefix");
|
|
253
429
|
if (fromModelPrefix)
|
|
254
430
|
return fromModelPrefix;
|
|
@@ -326,26 +502,155 @@ export function resolvePricingKey(source) {
|
|
|
326
502
|
},
|
|
327
503
|
};
|
|
328
504
|
}
|
|
329
|
-
/**
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
505
|
+
/**
|
|
506
|
+
* Prompt-side token count: OpenCode stores non-cached input separately from
|
|
507
|
+
* cache read/write, so their sum is the request context a context tier measures.
|
|
508
|
+
*/
|
|
509
|
+
function promptTokenCount(tokens) {
|
|
510
|
+
return tokens.input + tokens.cache_read + tokens.cache_write;
|
|
511
|
+
}
|
|
512
|
+
/**
|
|
513
|
+
* Known cost for the buckets that have an applicable rate. Returns `ok: false`
|
|
514
|
+
* only when positive tokens exist but none of them can be priced, preserving
|
|
515
|
+
* the existing entirely-unpriced path.
|
|
516
|
+
*/
|
|
517
|
+
function calculateKnownCost(rates, tokens) {
|
|
518
|
+
const coverage = tokenRateCoverage(rates, tokens);
|
|
519
|
+
if (coverage.pricedTokens === 0 && coverage.unpricedTokens > 0) {
|
|
335
520
|
return { ok: false };
|
|
336
|
-
|
|
521
|
+
}
|
|
522
|
+
return {
|
|
523
|
+
ok: true,
|
|
524
|
+
costUsd: calculateUsdFromTokenBuckets(rates, tokens),
|
|
525
|
+
...(coverage.unpricedTokens > 0 ? { unpricedTokens: coverage.unpricedTokens } : {}),
|
|
526
|
+
};
|
|
527
|
+
}
|
|
528
|
+
/**
|
|
529
|
+
* Resolve the rates that apply to one priced key, including context-tier
|
|
530
|
+
* selection and, when a completion instant is supplied, the exact
|
|
531
|
+
* provider/model temporal policy. Shared by `calculateCostUsd` and
|
|
532
|
+
* `aggregateUsage` so bucket splitting and cost calculation never disagree
|
|
533
|
+
* about which rates applied.
|
|
534
|
+
*
|
|
535
|
+
* Temporal pricing is opt-in per call: without `atMs`, existing callers keep
|
|
536
|
+
* using base rates unchanged. With `atMs`, only a verified exact provider/model
|
|
537
|
+
* route participates (never a provider inference, model alias, or prefix
|
|
538
|
+
* guess), and an unresolved/unsupported rule fails closed instead of silently
|
|
539
|
+
* charging base rates.
|
|
540
|
+
*/
|
|
541
|
+
function selectTokenRates(params) {
|
|
542
|
+
let base;
|
|
543
|
+
let contextTierSize;
|
|
544
|
+
if (params.provider === "cursor") {
|
|
545
|
+
const cursorCost = lookupCursorLocalCost(params.model);
|
|
546
|
+
if (!cursorCost)
|
|
547
|
+
return { ok: false };
|
|
548
|
+
base = cursorCost;
|
|
549
|
+
}
|
|
550
|
+
else {
|
|
551
|
+
const cost = lookupCost(params.provider, params.model);
|
|
552
|
+
if (!cost)
|
|
553
|
+
return { ok: false };
|
|
554
|
+
const hasExplicitContext = typeof params.contextTokens === "number" && Number.isFinite(params.contextTokens);
|
|
555
|
+
if (!cost.tiers?.length && !hasExplicitContext) {
|
|
556
|
+
base = cost;
|
|
557
|
+
}
|
|
558
|
+
else {
|
|
559
|
+
const contextTokens = hasExplicitContext
|
|
560
|
+
? params.contextTokens
|
|
561
|
+
: promptTokenCount(params.tokens);
|
|
562
|
+
const selected = selectCostAtContext(cost, contextTokens);
|
|
563
|
+
base = selected.rates;
|
|
564
|
+
contextTierSize = selected.tierSize;
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
if (params.temporalRoute === null) {
|
|
568
|
+
return {
|
|
569
|
+
ok: true,
|
|
570
|
+
rates: base,
|
|
571
|
+
...(contextTierSize !== undefined ? { contextTierSize } : {}),
|
|
572
|
+
};
|
|
573
|
+
}
|
|
574
|
+
const temporalProvider = params.temporalRoute?.provider ?? params.provider;
|
|
575
|
+
const temporalModel = params.temporalRoute?.model ?? params.model;
|
|
576
|
+
const temporal = applyTemporalRates(temporalProvider, temporalModel, base, params.atMs);
|
|
577
|
+
if (!temporal.ok)
|
|
578
|
+
return temporal;
|
|
579
|
+
return {
|
|
580
|
+
ok: true,
|
|
581
|
+
rates: temporal.rates,
|
|
582
|
+
...(contextTierSize !== undefined ? { contextTierSize } : {}),
|
|
583
|
+
};
|
|
584
|
+
}
|
|
585
|
+
/**
|
|
586
|
+
* Apply a model's temporal rates at one physical completion instant. Callers
|
|
587
|
+
* must pass a verified exact source provider/model route; this function never
|
|
588
|
+
* derives one from a pricing key, alias, or model-family guess.
|
|
589
|
+
*/
|
|
590
|
+
function applyTemporalRates(provider, model, rates, atMs) {
|
|
591
|
+
if (atMs === undefined)
|
|
592
|
+
return { ok: true, rates };
|
|
593
|
+
if (getTemporalPolicy(provider, model) === null)
|
|
594
|
+
return { ok: true, rates };
|
|
595
|
+
if (!Number.isFinite(atMs)) {
|
|
596
|
+
return { ok: false, reason: "temporal pricing requires a finite completion timestamp" };
|
|
597
|
+
}
|
|
598
|
+
const resolved = resolveTemporalRates(provider, model, atMs, rates);
|
|
599
|
+
if (resolved.status !== "resolved" || resolved.rates === null) {
|
|
600
|
+
const detail = resolved.reason ? `: ${resolved.reason}` : "";
|
|
601
|
+
return {
|
|
602
|
+
ok: false,
|
|
603
|
+
reason: `temporal pricing is ${resolved.status} for ${provider}/${model}${detail}`,
|
|
604
|
+
};
|
|
605
|
+
}
|
|
606
|
+
return { ok: true, rates: resolved.rates };
|
|
607
|
+
}
|
|
608
|
+
/**
|
|
609
|
+
* Temporal corrections require a verified exact source route. A pricing key
|
|
610
|
+
* inferred from a model id, an alias, or a prefix is not evidence that the
|
|
611
|
+
* source actually came from that provider/model, so it must keep base pricing.
|
|
612
|
+
*/
|
|
613
|
+
function verifiedTemporalRoute(sourceProviderID, sourceModelID, key) {
|
|
614
|
+
if (typeof sourceProviderID !== "string" || typeof sourceModelID !== "string")
|
|
615
|
+
return null;
|
|
616
|
+
const provider = sourceProviderID.trim();
|
|
617
|
+
const model = sourceModelID.trim();
|
|
618
|
+
if (!provider || !model)
|
|
619
|
+
return null;
|
|
620
|
+
if (provider.toLowerCase() !== key.provider.toLowerCase())
|
|
621
|
+
return null;
|
|
622
|
+
if (model !== key.model)
|
|
623
|
+
return null;
|
|
624
|
+
return { provider: key.provider, model: key.model };
|
|
337
625
|
}
|
|
338
|
-
/**
|
|
626
|
+
/** Per-message cost calculation; temporal rates apply only when `atMs` is supplied. */
|
|
627
|
+
export function calculateCostUsd(params) {
|
|
628
|
+
const selected = selectTokenRates(params);
|
|
629
|
+
if (!selected.ok)
|
|
630
|
+
return selected;
|
|
631
|
+
const known = calculateKnownCost(selected.rates, params.tokens);
|
|
632
|
+
if (!known.ok)
|
|
633
|
+
return known;
|
|
634
|
+
return {
|
|
635
|
+
...known,
|
|
636
|
+
...(selected.contextTierSize !== undefined
|
|
637
|
+
? { contextTierSize: selected.contextTierSize }
|
|
638
|
+
: {}),
|
|
639
|
+
};
|
|
640
|
+
}
|
|
641
|
+
/** Classify a resolved model as unpriced when the snapshot or catalog knows it without rates. */
|
|
339
642
|
export function classifyMissingPricing(params) {
|
|
340
643
|
if (params.mappedProvider === "cursor") {
|
|
341
644
|
return { kind: "unknown" };
|
|
342
645
|
}
|
|
343
|
-
//
|
|
344
|
-
|
|
646
|
+
// When provider/model exists in the priced snapshot or source catalog but
|
|
647
|
+
// has no numeric rates, classify as unpriced. Catalog-only providers may be
|
|
648
|
+
// absent from the priced snapshot.
|
|
649
|
+
const inCatalog = hasCatalogModel(params.mappedProvider, params.mappedModel);
|
|
650
|
+
if (!hasProvider(params.mappedProvider) && !inCatalog) {
|
|
345
651
|
return { kind: "unknown" };
|
|
346
652
|
}
|
|
347
|
-
|
|
348
|
-
if (hasModel(params.mappedProvider, params.mappedModel)) {
|
|
653
|
+
if (hasModel(params.mappedProvider, params.mappedModel) || inCatalog) {
|
|
349
654
|
if (params.mappedModel.toLowerCase().endsWith("-free")) {
|
|
350
655
|
return { kind: "unpriced", reason: "free-tier model id not priced in snapshot" };
|
|
351
656
|
}
|
|
@@ -359,27 +664,61 @@ export function classifyMissingPricing(params) {
|
|
|
359
664
|
* and the GUI aggregation call this; neither resolves keys, computes cost, or
|
|
360
665
|
* classifies missing pricing on its own.
|
|
361
666
|
*
|
|
362
|
-
* `
|
|
363
|
-
*
|
|
667
|
+
* `atMs` is the physical assistant completion instant for one row. When it is
|
|
668
|
+
* supplied, temporal pricing applies only if the raw source provider/model
|
|
669
|
+
* exactly match the resolved priced route; inferred providers, model aliases,
|
|
670
|
+
* and prefix guesses keep base pricing. When `atMs` is absent, callers keep the
|
|
671
|
+
* existing non-temporal pricing behavior.
|
|
672
|
+
*
|
|
673
|
+
* `cache` is optional and keyed by a collision-safe tuple of the exact raw
|
|
674
|
+
* source ids, so a caller can reuse key resolution across many messages of the
|
|
675
|
+
* same source without conflating delimiter-bearing or missing ids.
|
|
364
676
|
*/
|
|
365
677
|
export function priceTokenBuckets(params) {
|
|
366
|
-
const cacheKey =
|
|
678
|
+
const cacheKey = encodeIdentityKey([params.providerID, params.modelID]);
|
|
367
679
|
let resolution = params.cache?.get(cacheKey);
|
|
368
680
|
if (!resolution) {
|
|
369
|
-
resolution = resolvePricingKey({
|
|
681
|
+
resolution = resolvePricingKey({
|
|
682
|
+
providerID: params.providerID ?? undefined,
|
|
683
|
+
modelID: params.modelID ?? undefined,
|
|
684
|
+
});
|
|
370
685
|
params.cache?.set(cacheKey, resolution);
|
|
371
686
|
}
|
|
372
687
|
if (!resolution.ok) {
|
|
373
688
|
return { status: "unknown", unknown: resolution.unknown };
|
|
374
689
|
}
|
|
375
690
|
const key = resolution.key;
|
|
691
|
+
const temporalRoute = verifiedTemporalRoute(params.providerID, params.modelID, key);
|
|
376
692
|
const priced = calculateCostUsd({
|
|
377
693
|
provider: key.provider,
|
|
378
694
|
model: key.model,
|
|
379
695
|
tokens: params.tokens,
|
|
696
|
+
contextTokens: params.contextTokens,
|
|
697
|
+
atMs: params.atMs,
|
|
698
|
+
temporalRoute,
|
|
380
699
|
});
|
|
381
700
|
if (priced.ok) {
|
|
382
|
-
|
|
701
|
+
const contextTier = priced.contextTierSize !== undefined ? { contextTierSize: priced.contextTierSize } : {};
|
|
702
|
+
if (priced.unpricedTokens !== undefined && priced.unpricedTokens > 0) {
|
|
703
|
+
return {
|
|
704
|
+
status: "partial",
|
|
705
|
+
key,
|
|
706
|
+
costUsd: priced.costUsd,
|
|
707
|
+
unpricedTokens: priced.unpricedTokens,
|
|
708
|
+
...contextTier,
|
|
709
|
+
};
|
|
710
|
+
}
|
|
711
|
+
return {
|
|
712
|
+
status: "priced",
|
|
713
|
+
key,
|
|
714
|
+
costUsd: priced.costUsd,
|
|
715
|
+
...contextTier,
|
|
716
|
+
};
|
|
717
|
+
}
|
|
718
|
+
// A temporal policy that cannot be resolved is not a missing catalog price:
|
|
719
|
+
// report the token count as unpriced without falling back to base rates.
|
|
720
|
+
if (priced.reason !== undefined) {
|
|
721
|
+
return { status: "unpriced", key, reason: priced.reason };
|
|
383
722
|
}
|
|
384
723
|
const classification = classifyMissingPricing({
|
|
385
724
|
mappedProvider: key.provider,
|
|
@@ -453,6 +792,11 @@ export async function resolveSessionTree(rootSessionID) {
|
|
|
453
792
|
visit(root, 0);
|
|
454
793
|
return tree;
|
|
455
794
|
}
|
|
795
|
+
/** Physical completion instant of one message, or undefined when absent/invalid. */
|
|
796
|
+
function messageCompletedAtMs(message) {
|
|
797
|
+
const completed = message.time?.completed;
|
|
798
|
+
return typeof completed === "number" && Number.isFinite(completed) ? completed : undefined;
|
|
799
|
+
}
|
|
456
800
|
export async function aggregateUsage(params) {
|
|
457
801
|
if (params.sessionID && params.sessionIDs?.length) {
|
|
458
802
|
throw new Error("aggregateUsage received both sessionID and sessionIDs");
|
|
@@ -487,10 +831,13 @@ export async function aggregateUsage(params) {
|
|
|
487
831
|
let unknownTotals = emptyTokenBuckets();
|
|
488
832
|
let unpricedTotals = emptyTokenBuckets();
|
|
489
833
|
let costTotal = 0;
|
|
834
|
+
let partialCostTotal = 0;
|
|
835
|
+
let partialMessageCount = 0;
|
|
490
836
|
const resolutionCache = new Map();
|
|
491
837
|
for (const msg of messages) {
|
|
492
838
|
const tokens = tokenBucketsFromMessage(msg);
|
|
493
839
|
const sid = msg.sessionID;
|
|
840
|
+
const atMs = messageCompletedAtMs(msg);
|
|
494
841
|
const sessionTitle = sessionsIdx[sid]?.title;
|
|
495
842
|
const existingSessionRow = bySession.get(sid);
|
|
496
843
|
if (existingSessionRow) {
|
|
@@ -510,6 +857,7 @@ export async function aggregateUsage(params) {
|
|
|
510
857
|
providerID: msg.providerID,
|
|
511
858
|
modelID: msg.modelID,
|
|
512
859
|
tokens,
|
|
860
|
+
atMs,
|
|
513
861
|
cache: resolutionCache,
|
|
514
862
|
});
|
|
515
863
|
if (outcome.status === "unknown") {
|
|
@@ -523,6 +871,10 @@ export async function aggregateUsage(params) {
|
|
|
523
871
|
else {
|
|
524
872
|
unknown.set(k, { key: outcome.unknown, tokens, messageCount: 1 });
|
|
525
873
|
}
|
|
874
|
+
const sessionRow = bySession.get(sid);
|
|
875
|
+
if (sessionRow) {
|
|
876
|
+
sessionRow.unpricedMessageCount = (sessionRow.unpricedMessageCount ?? 0) + 1;
|
|
877
|
+
}
|
|
526
878
|
continue;
|
|
527
879
|
}
|
|
528
880
|
if (outcome.status === "unpriced") {
|
|
@@ -543,9 +895,39 @@ export async function aggregateUsage(params) {
|
|
|
543
895
|
else {
|
|
544
896
|
unpriced.set(k, { key: rowKey, tokens, messageCount: 1 });
|
|
545
897
|
}
|
|
898
|
+
const sessionRow = bySession.get(sid);
|
|
899
|
+
if (sessionRow) {
|
|
900
|
+
sessionRow.unpricedMessageCount = (sessionRow.unpricedMessageCount ?? 0) + 1;
|
|
901
|
+
}
|
|
546
902
|
continue;
|
|
547
903
|
}
|
|
548
|
-
|
|
904
|
+
// Remaining outcomes are "priced" or "partial". A partial row keeps its
|
|
905
|
+
// known cost, but only the buckets with an applicable rate count as priced;
|
|
906
|
+
// the missing-rate buckets stay in the unpriced totals.
|
|
907
|
+
const isPartial = outcome.status === "partial";
|
|
908
|
+
if (isPartial) {
|
|
909
|
+
const selected = selectTokenRates({
|
|
910
|
+
provider: outcome.key.provider,
|
|
911
|
+
model: outcome.key.model,
|
|
912
|
+
tokens,
|
|
913
|
+
atMs,
|
|
914
|
+
});
|
|
915
|
+
if (selected.ok) {
|
|
916
|
+
const split = splitTokenBucketsByRate(selected.rates, tokens);
|
|
917
|
+
pricedTotals = addTokenBuckets(pricedTotals, split.priced);
|
|
918
|
+
unpricedTotals = addTokenBuckets(unpricedTotals, split.unpriced);
|
|
919
|
+
}
|
|
920
|
+
else {
|
|
921
|
+
// A partial outcome always has at least one priced bucket. If a second
|
|
922
|
+
// lookup disagrees, keep its usage conservative rather than claim it.
|
|
923
|
+
unpricedTotals = addTokenBuckets(unpricedTotals, tokens);
|
|
924
|
+
}
|
|
925
|
+
partialCostTotal += outcome.costUsd;
|
|
926
|
+
partialMessageCount += 1;
|
|
927
|
+
}
|
|
928
|
+
else {
|
|
929
|
+
pricedTotals = addTokenBuckets(pricedTotals, tokens);
|
|
930
|
+
}
|
|
549
931
|
costTotal += outcome.costUsd;
|
|
550
932
|
// Tokscale-style: key by OpenCode source provider + source model id.
|
|
551
933
|
const srcProviderID = msg.providerID ?? "unknown";
|
|
@@ -556,6 +938,8 @@ export async function aggregateUsage(params) {
|
|
|
556
938
|
sm.tokens = addTokenBuckets(sm.tokens, tokens);
|
|
557
939
|
sm.costUsd += outcome.costUsd;
|
|
558
940
|
sm.messageCount += 1;
|
|
941
|
+
if (isPartial)
|
|
942
|
+
sm.partialMessageCount = (sm.partialMessageCount ?? 0) + 1;
|
|
559
943
|
}
|
|
560
944
|
else {
|
|
561
945
|
bySourceModel.set(srcModelKey, {
|
|
@@ -564,6 +948,7 @@ export async function aggregateUsage(params) {
|
|
|
564
948
|
tokens,
|
|
565
949
|
costUsd: outcome.costUsd,
|
|
566
950
|
messageCount: 1,
|
|
951
|
+
...(isPartial ? { partialMessageCount: 1 } : {}),
|
|
567
952
|
});
|
|
568
953
|
}
|
|
569
954
|
const srcProvider = srcProviderID;
|
|
@@ -572,6 +957,8 @@ export async function aggregateUsage(params) {
|
|
|
572
957
|
src.tokens = addTokenBuckets(src.tokens, tokens);
|
|
573
958
|
src.costUsd += outcome.costUsd;
|
|
574
959
|
src.messageCount += 1;
|
|
960
|
+
if (isPartial)
|
|
961
|
+
src.partialMessageCount = (src.partialMessageCount ?? 0) + 1;
|
|
575
962
|
}
|
|
576
963
|
else {
|
|
577
964
|
bySourceProvider.set(srcProvider, {
|
|
@@ -579,6 +966,7 @@ export async function aggregateUsage(params) {
|
|
|
579
966
|
tokens,
|
|
580
967
|
costUsd: outcome.costUsd,
|
|
581
968
|
messageCount: 1,
|
|
969
|
+
...(isPartial ? { partialMessageCount: 1 } : {}),
|
|
582
970
|
});
|
|
583
971
|
}
|
|
584
972
|
const modelKey = `${outcome.key.provider}/${outcome.key.model}`;
|
|
@@ -587,6 +975,8 @@ export async function aggregateUsage(params) {
|
|
|
587
975
|
existing.tokens = addTokenBuckets(existing.tokens, tokens);
|
|
588
976
|
existing.costUsd += outcome.costUsd;
|
|
589
977
|
existing.messageCount += 1;
|
|
978
|
+
if (isPartial)
|
|
979
|
+
existing.partialMessageCount = (existing.partialMessageCount ?? 0) + 1;
|
|
590
980
|
}
|
|
591
981
|
else {
|
|
592
982
|
byModel.set(modelKey, {
|
|
@@ -594,11 +984,15 @@ export async function aggregateUsage(params) {
|
|
|
594
984
|
tokens,
|
|
595
985
|
costUsd: outcome.costUsd,
|
|
596
986
|
messageCount: 1,
|
|
987
|
+
...(isPartial ? { partialMessageCount: 1 } : {}),
|
|
597
988
|
});
|
|
598
989
|
}
|
|
599
990
|
const s = bySession.get(sid);
|
|
600
991
|
if (s) {
|
|
601
992
|
s.costUsd += outcome.costUsd;
|
|
993
|
+
s.pricedMessageCount = (s.pricedMessageCount ?? 0) + 1;
|
|
994
|
+
if (isPartial)
|
|
995
|
+
s.partialMessageCount = (s.partialMessageCount ?? 0) + 1;
|
|
602
996
|
}
|
|
603
997
|
}
|
|
604
998
|
const byModelRows = Array.from(byModel.values()).sort((a, b) => b.costUsd - a.costUsd);
|
|
@@ -634,6 +1028,7 @@ export async function aggregateUsage(params) {
|
|
|
634
1028
|
costUsd: costTotal,
|
|
635
1029
|
messageCount: messages.length,
|
|
636
1030
|
sessionCount: new Set(messages.map((m) => m.sessionID)).size,
|
|
1031
|
+
...(partialMessageCount > 0 ? { partialCostUsd: partialCostTotal, partialMessageCount } : {}),
|
|
637
1032
|
},
|
|
638
1033
|
bySourceProvider: bySourceProviderRows,
|
|
639
1034
|
bySourceModel: bySourceModelRows,
|