opencode-quota-gui 1.0.0 → 1.1.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 -23
- 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/build-identity.js +1 -1
- package/dist/contracts/card-order.d.ts +25 -0
- package/dist/contracts/card-order.d.ts.map +1 -0
- package/dist/contracts/card-order.js +50 -0
- package/dist/contracts/card-order.js.map +1 -0
- 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 +149 -0
- package/dist/contracts/dashboard.d.ts.map +1 -1
- package/dist/data/modelsdev-pricing.min.json +1 -1064
- package/dist/gui/aggregation.d.ts.map +1 -1
- package/dist/gui/aggregation.js +6 -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 +198 -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 +444 -38
- package/dist/gui/analytics-model.js.map +1 -1
- 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 +8 -0
- package/dist/gui/analytics-state.d.ts.map +1 -1
- package/dist/gui/analytics-state.js +13 -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 +7 -4
- package/dist/gui/config.d.ts.map +1 -1
- package/dist/gui/config.js +25 -3
- 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/provider-cards.d.ts +15 -18
- package/dist/gui/provider-cards.d.ts.map +1 -1
- package/dist/gui/provider-cards.js +33 -29
- package/dist/gui/provider-cards.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 +14 -9
- package/dist/gui/sources.d.ts.map +1 -1
- package/dist/gui/sources.js +50 -23
- package/dist/gui/sources.js.map +1 -1
- package/dist/lib/config.d.ts +1 -1
- package/dist/lib/config.d.ts.map +1 -1
- package/dist/lib/config.js +30 -5
- 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/dashboard-visibility.d.ts +13 -0
- package/dist/lib/dashboard-visibility.d.ts.map +1 -0
- package/dist/lib/dashboard-visibility.js +51 -0
- package/dist/lib/dashboard-visibility.js.map +1 -0
- package/dist/lib/entries.d.ts +2 -0
- package/dist/lib/entries.d.ts.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/opencode-console-auth.d.ts +68 -0
- package/dist/lib/opencode-console-auth.d.ts.map +1 -1
- package/dist/lib/opencode-console-auth.js +424 -14
- package/dist/lib/opencode-console-auth.js.map +1 -1
- package/dist/lib/opencode-go.d.ts.map +1 -1
- package/dist/lib/opencode-go.js +13 -7
- package/dist/lib/opencode-go.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/openrouter.d.ts +45 -1
- package/dist/lib/openrouter.d.ts.map +1 -1
- package/dist/lib/openrouter.js +177 -12
- package/dist/lib/openrouter.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-providers-remote.d.ts.map +1 -1
- package/dist/lib/quota-providers-remote.js +117 -38
- package/dist/lib/quota-providers-remote.js.map +1 -1
- package/dist/lib/quota-state-codec.d.ts.map +1 -1
- package/dist/lib/quota-state-codec.js +5 -1
- package/dist/lib/quota-state-codec.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 +49 -6
- package/dist/lib/quota-stats.d.ts.map +1 -1
- package/dist/lib/quota-stats.js +319 -20
- 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 +17 -3
- package/dist/lib/types.d.ts.map +1 -1
- package/dist/lib/types.js +3 -1
- 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 +8 -2
- package/dist/providers/cache-policies.d.ts.map +1 -1
- package/dist/providers/cache-policies.js +78 -24
- 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 +201 -84
- 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 +235 -166
- package/dist/providers/opencode-zen.js.map +1 -1
- package/dist/providers/openrouter.d.ts.map +1 -1
- package/dist/providers/openrouter.js +76 -14
- package/dist/providers/openrouter.js.map +1 -1
- package/dist/ui/assets/{index-wlxynmbV.css → index-BZwMJ6Ax.css} +1 -1
- package/dist/ui/assets/index-CjNjqsse.js +8 -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 +4 -1
- package/dist/ui/assets/index-BvKGj9wc.js +0 -8
|
@@ -1,12 +1,35 @@
|
|
|
1
1
|
import { type OpencodeRuntimeDirs } from "./opencode-runtime-paths.js";
|
|
2
2
|
import type { PricingSnapshotSource } from "./types.js";
|
|
3
|
-
export type
|
|
3
|
+
export type CostRates = {
|
|
4
4
|
input?: number;
|
|
5
5
|
output?: number;
|
|
6
6
|
cache_read?: number;
|
|
7
7
|
cache_write?: number;
|
|
8
8
|
reasoning?: number;
|
|
9
9
|
};
|
|
10
|
+
/**
|
|
11
|
+
* One models.dev context tier. `size` is the prompt/context token count at
|
|
12
|
+
* which the tier starts; rates replace the base rates for that request.
|
|
13
|
+
*/
|
|
14
|
+
export type CostTier = CostRates & {
|
|
15
|
+
tier: {
|
|
16
|
+
type: "context";
|
|
17
|
+
size: number;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
export type CostBuckets = CostRates & {
|
|
21
|
+
/**
|
|
22
|
+
* Explicit context tiers, ascending by `tier.size`. Present only when
|
|
23
|
+
* models.dev publishes a supported tier; unsupported tier types are dropped.
|
|
24
|
+
*/
|
|
25
|
+
tiers?: CostTier[];
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Authoritative model ids per provider from a successful models.dev response,
|
|
29
|
+
* independent of whether a model had a usable cost. A provider missing from
|
|
30
|
+
* this record has unknown catalog presence, not an empty catalog.
|
|
31
|
+
*/
|
|
32
|
+
export type PricingCatalog = Record<string, string[]>;
|
|
10
33
|
export type PricingSnapshot = {
|
|
11
34
|
_meta: {
|
|
12
35
|
source: string;
|
|
@@ -15,6 +38,12 @@ export type PricingSnapshot = {
|
|
|
15
38
|
units: string;
|
|
16
39
|
};
|
|
17
40
|
providers: Record<string, Record<string, CostBuckets>>;
|
|
41
|
+
/**
|
|
42
|
+
* Catalog presence from the last successful refresh. Runtime snapshots
|
|
43
|
+
* persist it separately from priced entries so offline/304 reloads can tell
|
|
44
|
+
* "retired" apart from "still listed but no longer priced".
|
|
45
|
+
*/
|
|
46
|
+
catalog?: PricingCatalog;
|
|
18
47
|
};
|
|
19
48
|
export declare const DEFAULT_PRICING_SNAPSHOT_MAX_AGE_MS: number;
|
|
20
49
|
export type PricingSnapshotHealth = {
|
|
@@ -50,6 +79,7 @@ export interface PricingRefreshOptions {
|
|
|
50
79
|
runtimeDirs?: OpencodeRuntimeDirs;
|
|
51
80
|
fetchFn?: typeof fetch;
|
|
52
81
|
bootstrapSnapshotOverride?: PricingSnapshot;
|
|
82
|
+
/** Optional observed-provider scope; omitting refreshes every central provider. */
|
|
53
83
|
providerAllowlist?: string[];
|
|
54
84
|
snapshotSelection?: PricingSnapshotSource;
|
|
55
85
|
allowRefreshWhenSelectionBundled?: boolean;
|
|
@@ -78,6 +108,11 @@ export declare function getPricingSnapshotHealth(opts?: {
|
|
|
78
108
|
export declare function hasProvider(providerId: string): boolean;
|
|
79
109
|
export declare function isModelsDevProviderId(providerId: string): boolean;
|
|
80
110
|
export declare function hasModel(providerId: string, modelId: string): boolean;
|
|
111
|
+
/**
|
|
112
|
+
* True when the source catalog lists the exact model, even if the model has no
|
|
113
|
+
* usable cost. Catalog providers may be absent from `providers`.
|
|
114
|
+
*/
|
|
115
|
+
export declare function hasCatalogModel(providerId: string, modelId: string): boolean;
|
|
81
116
|
/**
|
|
82
117
|
* Infer the snapshot provider that owns a modelId.
|
|
83
118
|
* Returns null when model is not found or is ambiguous across providers.
|
|
@@ -87,6 +122,24 @@ export declare function getProviderModelCount(providerId: string): number;
|
|
|
87
122
|
export declare function listProviders(): string[];
|
|
88
123
|
export declare function listModelsForProvider(providerId: string): string[];
|
|
89
124
|
export declare function listProvidersForModelId(modelId: string): string[];
|
|
125
|
+
export type CostAtContext = {
|
|
126
|
+
/** Base rates, or the selected tier's rates when `basis` is `context_tier`. */
|
|
127
|
+
rates: CostRates;
|
|
128
|
+
basis: "base" | "context_tier";
|
|
129
|
+
/** Explicit tier thresholds published for the model, ascending. */
|
|
130
|
+
tierSizes: number[];
|
|
131
|
+
/** Selected threshold when `basis` is `context_tier`. */
|
|
132
|
+
tierSize?: number;
|
|
133
|
+
};
|
|
134
|
+
/**
|
|
135
|
+
* Select base or context-tier rates from one cost entry. Without a
|
|
136
|
+
* `contextTokens` value the base rates are returned and no tier is claimed as
|
|
137
|
+
* applied. A tier is selected only when the caller can prove the request
|
|
138
|
+
* context reached its threshold; malformed or unsupported tiers never
|
|
139
|
+
* participate.
|
|
140
|
+
*/
|
|
141
|
+
export declare function selectCostAtContext(cost: CostBuckets, contextTokens?: number): CostAtContext;
|
|
142
|
+
export declare function lookupCostAtContext(providerId: string, modelId: string, contextTokens?: number): CostAtContext | null;
|
|
90
143
|
export declare function lookupCost(providerId: string, modelId: string): CostBuckets | null;
|
|
91
144
|
export declare function hasCost(providerId: string, modelId: string): boolean;
|
|
92
145
|
export declare function __resetPricingSnapshotForTests(): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"modelsdev-pricing.d.ts","sourceRoot":"","sources":["../../src/lib/modelsdev-pricing.ts"],"names":[],"mappings":"AAMA,OAAO,EAA0B,KAAK,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAE/F,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"modelsdev-pricing.d.ts","sourceRoot":"","sources":["../../src/lib/modelsdev-pricing.ts"],"names":[],"mappings":"AAMA,OAAO,EAA0B,KAAK,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAE/F,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAUxD,MAAM,MAAM,SAAS,GAAG;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;I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AAuB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,CAGjE;AAED,MAAM,MAAM,aAAa,GAAG;IAC1B,+EAA+E;IAC/E,KAAK,EAAE,SAAS,CAAC;IACjB,KAAK,EAAE,MAAM,GAAG,cAAc,CAAC;IAC/B,mEAAmE;IACnE,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,yDAAyD;IACzD,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAOF;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,WAAW,EAAE,aAAa,CAAC,EAAE,MAAM,GAAG,aAAa,CA0B5F;AAED,wBAAgB,mBAAmB,CACjC,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,MAAM,EACf,aAAa,CAAC,EAAE,MAAM,GACrB,aAAa,GAAG,IAAI,CAGtB;AAED,wBAAgB,UAAU,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,WAAW,GAAG,IAAI,CAMlF;AAED,wBAAgB,OAAO,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAEpE;AAED,wBAAgB,8BAA8B,IAAI,IAAI,CAQrD"}
|
|
@@ -6,8 +6,7 @@ import { fetchWithTimeout } from "./http.js";
|
|
|
6
6
|
import { getOpencodeRuntimeDirs } from "./opencode-runtime-paths.js";
|
|
7
7
|
import { getGuiPrivateCacheDir } from "./private-state-paths.js";
|
|
8
8
|
const SOURCE_URL = "https://models.dev/api.json";
|
|
9
|
-
const
|
|
10
|
-
const COST_KEYS = ["input", "output", "cache_read", "cache_write"];
|
|
9
|
+
const COST_KEYS = ["input", "output", "cache_read", "cache_write", "reasoning"];
|
|
11
10
|
const RUNTIME_SNAPSHOT_FILENAME = "modelsdev-pricing.runtime.min.json";
|
|
12
11
|
const RUNTIME_REFRESH_STATE_FILENAME = "modelsdev-pricing.refresh-state.json";
|
|
13
12
|
const DEFAULT_REFRESH_MIN_ATTEMPT_INTERVAL_MS = 6 * 60 * 60 * 1000;
|
|
@@ -40,6 +39,27 @@ function sortRecordByKeys(obj) {
|
|
|
40
39
|
}
|
|
41
40
|
return out;
|
|
42
41
|
}
|
|
42
|
+
function sortCatalog(catalog) {
|
|
43
|
+
const out = {};
|
|
44
|
+
for (const providerID of Object.keys(catalog).sort((a, b) => a.localeCompare(b))) {
|
|
45
|
+
const modelIDs = [...new Set(catalog[providerID])].sort((a, b) => a.localeCompare(b));
|
|
46
|
+
out[providerID] = modelIDs;
|
|
47
|
+
}
|
|
48
|
+
return out;
|
|
49
|
+
}
|
|
50
|
+
function normalizeCatalog(raw) {
|
|
51
|
+
const obj = asRecord(raw);
|
|
52
|
+
if (!obj)
|
|
53
|
+
return undefined;
|
|
54
|
+
const catalog = {};
|
|
55
|
+
for (const providerID of Object.keys(obj)) {
|
|
56
|
+
const rawModelIDs = obj[providerID];
|
|
57
|
+
if (!Array.isArray(rawModelIDs))
|
|
58
|
+
continue;
|
|
59
|
+
catalog[providerID] = rawModelIDs.filter((modelID) => typeof modelID === "string" && modelID.length > 0);
|
|
60
|
+
}
|
|
61
|
+
return sortCatalog(catalog);
|
|
62
|
+
}
|
|
43
63
|
function pricingSnapshotDaysToMs(days) {
|
|
44
64
|
if (typeof days !== "number" || !Number.isFinite(days) || days <= 0) {
|
|
45
65
|
return DEFAULT_PRICING_SNAPSHOT_MAX_AGE_MS;
|
|
@@ -75,27 +95,8 @@ function normalizeSnapshot(raw) {
|
|
|
75
95
|
continue;
|
|
76
96
|
const models = {};
|
|
77
97
|
for (const modelId of Object.keys(modelsRaw)) {
|
|
78
|
-
const
|
|
79
|
-
if (
|
|
80
|
-
continue;
|
|
81
|
-
const buckets = {};
|
|
82
|
-
const input = modelRaw.input;
|
|
83
|
-
const output = modelRaw.output;
|
|
84
|
-
const cacheRead = modelRaw.cache_read;
|
|
85
|
-
const cacheWrite = modelRaw.cache_write;
|
|
86
|
-
const reasoning = modelRaw.reasoning;
|
|
87
|
-
if (typeof input === "number" && Number.isFinite(input))
|
|
88
|
-
buckets.input = input;
|
|
89
|
-
if (typeof output === "number" && Number.isFinite(output))
|
|
90
|
-
buckets.output = output;
|
|
91
|
-
if (typeof cacheRead === "number" && Number.isFinite(cacheRead))
|
|
92
|
-
buckets.cache_read = cacheRead;
|
|
93
|
-
if (typeof cacheWrite === "number" && Number.isFinite(cacheWrite)) {
|
|
94
|
-
buckets.cache_write = cacheWrite;
|
|
95
|
-
}
|
|
96
|
-
if (typeof reasoning === "number" && Number.isFinite(reasoning))
|
|
97
|
-
buckets.reasoning = reasoning;
|
|
98
|
-
if (Object.keys(buckets).length > 0) {
|
|
98
|
+
const buckets = pickCostBuckets(modelsRaw[modelId]);
|
|
99
|
+
if (buckets) {
|
|
99
100
|
models[modelId] = buckets;
|
|
100
101
|
}
|
|
101
102
|
}
|
|
@@ -104,7 +105,9 @@ function normalizeSnapshot(raw) {
|
|
|
104
105
|
}
|
|
105
106
|
}
|
|
106
107
|
const providerList = Object.keys(providers).sort((a, b) => a.localeCompare(b));
|
|
108
|
+
const catalog = normalizeCatalog(root.catalog);
|
|
107
109
|
return {
|
|
110
|
+
...(catalog ? { catalog } : {}),
|
|
108
111
|
_meta: {
|
|
109
112
|
source: typeof metaRaw.source === "string" && metaRaw.source ? metaRaw.source : SOURCE_URL,
|
|
110
113
|
generatedAt: Math.trunc(generatedAt),
|
|
@@ -146,14 +149,48 @@ function loadRuntimeSnapshotSync(runtimeDirs) {
|
|
|
146
149
|
function hasSnapshotData(snapshot) {
|
|
147
150
|
return snapshot._meta.generatedAt > 0;
|
|
148
151
|
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
+
function countCatalogModels(snapshot) {
|
|
153
|
+
if (!snapshot?.catalog)
|
|
154
|
+
return 0;
|
|
155
|
+
let total = 0;
|
|
156
|
+
for (const modelIDs of Object.values(snapshot.catalog))
|
|
157
|
+
total += modelIDs.length;
|
|
158
|
+
return total;
|
|
159
|
+
}
|
|
160
|
+
function hasAuthoritativeCatalog(snapshot) {
|
|
161
|
+
return countCatalogModels(snapshot) > 0;
|
|
162
|
+
}
|
|
163
|
+
function unionProviderIDs(snapshots) {
|
|
164
|
+
const ids = new Set();
|
|
165
|
+
for (const snapshot of snapshots) {
|
|
166
|
+
if (!snapshot)
|
|
167
|
+
continue;
|
|
168
|
+
for (const providerID of Object.keys(snapshot.providers))
|
|
169
|
+
ids.add(providerID);
|
|
170
|
+
}
|
|
171
|
+
return [...ids].sort((a, b) => a.localeCompare(b));
|
|
172
|
+
}
|
|
173
|
+
// A runtime snapshot saved by an older version may lack providers or models
|
|
174
|
+
// that models.dev stopped listing. Fill them from the bundled file on every
|
|
175
|
+
// load, so a fresh runtime snapshot doesn't hide offline coverage until its
|
|
176
|
+
// next refresh.
|
|
177
|
+
//
|
|
178
|
+
// The bundled snapshot intentionally carries two exact retired routes,
|
|
179
|
+
// `opencode/union-alpha` and `opencode-go/union-alpha`, at historical zero
|
|
180
|
+
// rates. models.dev added them with zero input/output/cache_read, labeled them
|
|
181
|
+
// Free, then removed them when the routes expired:
|
|
182
|
+
// - https://github.com/sst/models.dev/commit/e3626b49388e2dbea382b91b81e9d4237c117402
|
|
183
|
+
// - https://github.com/sst/models.dev/commit/75518776b9fb7e51d0de48b83469f6a6b4159415
|
|
184
|
+
// - https://github.com/sst/models.dev/commit/14f892c0a44c0a0bcdf9805e7fd695402b4d4218
|
|
185
|
+
// These entries are exact id/provider pairs; no wildcard or model-name
|
|
186
|
+
// inference is added. If upstream lists either id again, catalog presence from
|
|
187
|
+
// the refresh wins and the historical zero price is not restored.
|
|
152
188
|
function withBundledRetiredModels(runtime, bundled) {
|
|
153
189
|
return keepRetiredModels({
|
|
154
190
|
current: runtime,
|
|
155
191
|
previous: [bundled],
|
|
156
|
-
providerIDs:
|
|
192
|
+
providerIDs: unionProviderIDs([runtime, bundled]),
|
|
193
|
+
catalog: runtime.catalog,
|
|
157
194
|
});
|
|
158
195
|
}
|
|
159
196
|
function chooseSnapshot(params) {
|
|
@@ -276,7 +313,7 @@ function makeDefaultRefreshState(nowMs) {
|
|
|
276
313
|
updatedAt: nowMs,
|
|
277
314
|
};
|
|
278
315
|
}
|
|
279
|
-
function
|
|
316
|
+
function pickRateBuckets(rawCost) {
|
|
280
317
|
const obj = asRecord(rawCost);
|
|
281
318
|
if (!obj)
|
|
282
319
|
return null;
|
|
@@ -289,14 +326,70 @@ function pickCostBuckets(rawCost) {
|
|
|
289
326
|
}
|
|
290
327
|
return Object.keys(picked).length > 0 ? picked : null;
|
|
291
328
|
}
|
|
329
|
+
/**
|
|
330
|
+
* Keep only explicit context tiers this code can apply. Unknown tier types,
|
|
331
|
+
* non-positive sizes, and tiers without numeric input/output are dropped
|
|
332
|
+
* rather than being presented as an exact published rate.
|
|
333
|
+
*/
|
|
334
|
+
function pickCostTiers(rawCost) {
|
|
335
|
+
const obj = asRecord(rawCost);
|
|
336
|
+
if (!Array.isArray(obj?.tiers))
|
|
337
|
+
return undefined;
|
|
338
|
+
const tiers = [];
|
|
339
|
+
for (const rawTier of obj.tiers) {
|
|
340
|
+
const tierNode = asRecord(rawTier);
|
|
341
|
+
const tierMeta = asRecord(tierNode?.tier);
|
|
342
|
+
if (!tierMeta || tierMeta.type !== "context")
|
|
343
|
+
continue;
|
|
344
|
+
const size = Number(tierMeta.size);
|
|
345
|
+
if (!Number.isFinite(size) || size <= 0)
|
|
346
|
+
continue;
|
|
347
|
+
const rates = pickRateBuckets(tierNode);
|
|
348
|
+
if (typeof rates?.input !== "number" || typeof rates.output !== "number")
|
|
349
|
+
continue;
|
|
350
|
+
tiers.push({
|
|
351
|
+
...rates,
|
|
352
|
+
tier: { type: "context", size: Math.trunc(size) },
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
if (tiers.length === 0)
|
|
356
|
+
return undefined;
|
|
357
|
+
// Deterministic regardless of upstream array order, then one tier per size.
|
|
358
|
+
tiers.sort((a, b) => a.tier.size - b.tier.size || JSON.stringify(a).localeCompare(JSON.stringify(b)));
|
|
359
|
+
const unique = [];
|
|
360
|
+
const sizes = new Set();
|
|
361
|
+
for (const tier of tiers) {
|
|
362
|
+
if (sizes.has(tier.tier.size))
|
|
363
|
+
continue;
|
|
364
|
+
sizes.add(tier.tier.size);
|
|
365
|
+
unique.push(tier);
|
|
366
|
+
}
|
|
367
|
+
return unique;
|
|
368
|
+
}
|
|
369
|
+
function pickCostBuckets(rawCost) {
|
|
370
|
+
const rates = pickRateBuckets(rawCost);
|
|
371
|
+
if (!rates)
|
|
372
|
+
return null;
|
|
373
|
+
const tiers = pickCostTiers(rawCost);
|
|
374
|
+
return tiers ? { ...rates, tiers } : rates;
|
|
375
|
+
}
|
|
292
376
|
function buildSnapshotFromApi(apiRaw, providerIDs, generatedAt) {
|
|
293
377
|
const api = asRecord(apiRaw) ?? {};
|
|
378
|
+
const apiProviderIDs = Object.keys(api).sort((a, b) => a.localeCompare(b));
|
|
379
|
+
const scopedProviderIDs = (providerIDs ?? apiProviderIDs)
|
|
380
|
+
.slice()
|
|
381
|
+
.sort((a, b) => a.localeCompare(b));
|
|
294
382
|
const providers = {};
|
|
295
|
-
|
|
383
|
+
const catalog = {};
|
|
384
|
+
// Catalog presence is authoritative only for the providers this refresh
|
|
385
|
+
// actually replaced. Providers outside the scope stay catalog-unknown so
|
|
386
|
+
// their prior or bundled prices remain restorable.
|
|
387
|
+
for (const providerID of scopedProviderIDs) {
|
|
296
388
|
const providerNode = asRecord(api[providerID]);
|
|
297
389
|
const models = asRecord(providerNode?.models);
|
|
298
390
|
if (!models)
|
|
299
391
|
continue;
|
|
392
|
+
catalog[providerID] = Object.keys(models);
|
|
300
393
|
const pricedModels = {};
|
|
301
394
|
for (const modelID of Object.keys(models)) {
|
|
302
395
|
const modelNode = asRecord(models[modelID]);
|
|
@@ -311,6 +404,7 @@ function buildSnapshotFromApi(apiRaw, providerIDs, generatedAt) {
|
|
|
311
404
|
}
|
|
312
405
|
const providerList = Object.keys(providers).sort((a, b) => a.localeCompare(b));
|
|
313
406
|
return {
|
|
407
|
+
catalog: sortCatalog(catalog),
|
|
314
408
|
_meta: {
|
|
315
409
|
generatedAt,
|
|
316
410
|
providers: providerList,
|
|
@@ -326,16 +420,28 @@ function buildSnapshotFromApi(apiRaw, providerIDs, generatedAt) {
|
|
|
326
420
|
* Callers list the user's runtime snapshot before the bundled one: its prices come
|
|
327
421
|
* from the user's own last download, while the bundled file's date only says when
|
|
328
422
|
* the file was rewritten, not when a kept model's price was last seen.
|
|
423
|
+
*
|
|
424
|
+
* `catalog` is the authoritative model presence from the API response. A model
|
|
425
|
+
* that is present in the catalog but has no priced entry in `current` was
|
|
426
|
+
* delisted from pricing and must not be restored from `previous`. Providers
|
|
427
|
+
* missing from `catalog` are unknown (for example a scoped refresh or a 304),
|
|
428
|
+
* so their historical models are still kept.
|
|
329
429
|
*/
|
|
330
430
|
function keepRetiredModels(params) {
|
|
331
431
|
const previous = params.previous.filter((snapshot) => snapshot !== null);
|
|
432
|
+
const catalog = params.catalog ?? params.current.catalog;
|
|
433
|
+
const catalogByProvider = catalog
|
|
434
|
+
? new Map(Object.entries(catalog).map(([providerID, modelIDs]) => [providerID, new Set(modelIDs)]))
|
|
435
|
+
: null;
|
|
332
436
|
const providers = { ...params.current.providers };
|
|
333
437
|
for (const providerID of params.providerIDs) {
|
|
334
438
|
const models = { ...(providers[providerID] ?? {}) };
|
|
439
|
+
const presentModelIDs = catalogByProvider?.get(providerID);
|
|
335
440
|
for (const snapshot of previous) {
|
|
336
441
|
for (const [modelID, cost] of Object.entries(snapshot.providers[providerID] ?? {})) {
|
|
337
|
-
if (
|
|
338
|
-
|
|
442
|
+
if (models[modelID] || presentModelIDs?.has(modelID))
|
|
443
|
+
continue;
|
|
444
|
+
models[modelID] = cost;
|
|
339
445
|
}
|
|
340
446
|
}
|
|
341
447
|
if (Object.keys(models).length > 0) {
|
|
@@ -344,6 +450,7 @@ function keepRetiredModels(params) {
|
|
|
344
450
|
}
|
|
345
451
|
const sortedProviders = sortRecordByKeys(providers);
|
|
346
452
|
return {
|
|
453
|
+
...(catalog ? { catalog: sortCatalog(catalog) } : {}),
|
|
347
454
|
_meta: { ...params.current._meta, providers: Object.keys(sortedProviders) },
|
|
348
455
|
providers: sortedProviders,
|
|
349
456
|
};
|
|
@@ -355,15 +462,53 @@ function countPricedModels(snapshot) {
|
|
|
355
462
|
}
|
|
356
463
|
return total;
|
|
357
464
|
}
|
|
465
|
+
/**
|
|
466
|
+
* A scoped refresh only replaces catalog presence for the providers it
|
|
467
|
+
* fetched. Providers outside the scope keep their prior authoritative catalog;
|
|
468
|
+
* dropping it would make a known present-but-unpriced model catalog-unknown,
|
|
469
|
+
* letting `keepRetiredModels` restore its stale bundled price.
|
|
470
|
+
*/
|
|
471
|
+
function mergeScopedCatalog(params) {
|
|
472
|
+
if (!params.scoped || !params.previous)
|
|
473
|
+
return params.fetched;
|
|
474
|
+
return sortCatalog({ ...params.previous, ...params.fetched });
|
|
475
|
+
}
|
|
476
|
+
/**
|
|
477
|
+
* Prices for providers that were not actually replaced by this response stay
|
|
478
|
+
* in the starting snapshot. `keepRetiredModels` then only uses the merged
|
|
479
|
+
* catalog to block stale bundled prices for models the prior catalog already
|
|
480
|
+
* marked present-but-unpriced.
|
|
481
|
+
*/
|
|
482
|
+
function retainPriorPricesForUnrefreshedProviders(params) {
|
|
483
|
+
if (!params.previous)
|
|
484
|
+
return params.current;
|
|
485
|
+
const providers = { ...params.current.providers };
|
|
486
|
+
for (const [providerID, models] of Object.entries(params.previous.providers)) {
|
|
487
|
+
if (params.replacedProviderIDs.has(providerID))
|
|
488
|
+
continue;
|
|
489
|
+
providers[providerID] = sortRecordByKeys({
|
|
490
|
+
...models,
|
|
491
|
+
...(providers[providerID] ?? {}),
|
|
492
|
+
});
|
|
493
|
+
}
|
|
494
|
+
const sortedProviders = sortRecordByKeys(providers);
|
|
495
|
+
return {
|
|
496
|
+
...params.current,
|
|
497
|
+
_meta: { ...params.current._meta, providers: Object.keys(sortedProviders) },
|
|
498
|
+
providers: sortedProviders,
|
|
499
|
+
};
|
|
500
|
+
}
|
|
358
501
|
function getErrorMessage(error) {
|
|
359
502
|
return error instanceof Error ? error.message : String(error);
|
|
360
503
|
}
|
|
361
504
|
async function fetchModelsDevSnapshot(params) {
|
|
362
505
|
const headers = new Headers();
|
|
363
|
-
if (params.
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
506
|
+
if (params.conditional !== false) {
|
|
507
|
+
if (params.state.etag)
|
|
508
|
+
headers.set("If-None-Match", params.state.etag);
|
|
509
|
+
if (params.state.lastModified)
|
|
510
|
+
headers.set("If-Modified-Since", params.state.lastModified);
|
|
511
|
+
}
|
|
367
512
|
return await fetchWithTimeout(SOURCE_URL, {
|
|
368
513
|
request: { headers },
|
|
369
514
|
timeoutMs: params.timeoutMs,
|
|
@@ -402,10 +547,16 @@ export async function maybeRefreshPricingSnapshot(opts = {}) {
|
|
|
402
547
|
const force = opts.force === true;
|
|
403
548
|
const selection = opts.snapshotSelection ?? SNAPSHOT_SELECTION;
|
|
404
549
|
const allowRefreshWhenSelectionBundled = opts.allowRefreshWhenSelectionBundled === true;
|
|
405
|
-
const
|
|
550
|
+
const requestedProviderIDs = opts.providerAllowlist;
|
|
406
551
|
const previousState = (await readRefreshState(statePath)) ?? makeDefaultRefreshState(nowMs);
|
|
407
552
|
const runtimeSnapshotBeforeRefresh = loadRuntimeSnapshotSync(runtimeDirs);
|
|
408
553
|
const bundledSnapshot = loadBundledSnapshotSync(opts.bootstrapSnapshotOverride);
|
|
554
|
+
// Without a persisted catalog, matching validators can pin a legacy
|
|
555
|
+
// snapshot to a permanent 304 and keep present-but-unpriced prices forever.
|
|
556
|
+
const runtimeHasAuthoritativeCatalog = hasAuthoritativeCatalog(runtimeSnapshotBeforeRefresh);
|
|
557
|
+
const legacyRuntimePinnedByValidators = runtimeSnapshotBeforeRefresh !== null &&
|
|
558
|
+
!runtimeHasAuthoritativeCatalog &&
|
|
559
|
+
!!(previousState.etag || previousState.lastModified);
|
|
409
560
|
applySnapshotSelection({
|
|
410
561
|
runtimeDirs,
|
|
411
562
|
bootstrapSnapshotOverride: opts.bootstrapSnapshotOverride,
|
|
@@ -444,7 +595,7 @@ export async function maybeRefreshPricingSnapshot(opts = {}) {
|
|
|
444
595
|
},
|
|
445
596
|
};
|
|
446
597
|
}
|
|
447
|
-
if (!force && !health.stale) {
|
|
598
|
+
if (!force && !health.stale && !legacyRuntimePinnedByValidators) {
|
|
448
599
|
return {
|
|
449
600
|
attempted: false,
|
|
450
601
|
updated: false,
|
|
@@ -477,11 +628,27 @@ export async function maybeRefreshPricingSnapshot(opts = {}) {
|
|
|
477
628
|
lastAttemptAt: nowMs,
|
|
478
629
|
};
|
|
479
630
|
try {
|
|
480
|
-
|
|
631
|
+
let fetchResult = await fetchModelsDevSnapshot({
|
|
481
632
|
timeoutMs,
|
|
482
633
|
state: attemptingState,
|
|
483
634
|
fetchFn: opts.fetchFn,
|
|
635
|
+
conditional: runtimeHasAuthoritativeCatalog,
|
|
484
636
|
});
|
|
637
|
+
if (fetchResult.kind === "not_modified" && !runtimeHasAuthoritativeCatalog) {
|
|
638
|
+
// An unconditional request must not answer 304. Retry once without
|
|
639
|
+
// validators; a second 304 still cannot establish catalog presence, so
|
|
640
|
+
// fail the refresh instead of persisting a fresh catalog-less snapshot.
|
|
641
|
+
const retry = await fetchModelsDevSnapshot({
|
|
642
|
+
timeoutMs,
|
|
643
|
+
state: attemptingState,
|
|
644
|
+
fetchFn: opts.fetchFn,
|
|
645
|
+
conditional: false,
|
|
646
|
+
});
|
|
647
|
+
if (retry.kind === "not_modified") {
|
|
648
|
+
throw new Error("models.dev returned not modified while an authoritative catalog refresh was required");
|
|
649
|
+
}
|
|
650
|
+
fetchResult = retry;
|
|
651
|
+
}
|
|
485
652
|
if (fetchResult.kind === "not_modified") {
|
|
486
653
|
const baseSnapshot = runtimeSnapshotBeforeRefresh ?? ensureLoaded();
|
|
487
654
|
// Also heals runtime snapshots written before retired models were kept.
|
|
@@ -494,7 +661,10 @@ export async function maybeRefreshPricingSnapshot(opts = {}) {
|
|
|
494
661
|
providers: baseSnapshot.providers,
|
|
495
662
|
},
|
|
496
663
|
previous: [bundledSnapshot],
|
|
497
|
-
|
|
664
|
+
// A 304 refreshes no provider prices, so retain every provider from
|
|
665
|
+
// either the prior snapshot or the bundled file.
|
|
666
|
+
providerIDs: unionProviderIDs([baseSnapshot, bundledSnapshot]),
|
|
667
|
+
catalog: baseSnapshot.catalog,
|
|
498
668
|
});
|
|
499
669
|
await writeJsonAtomic(snapshotPath, refreshedSnapshot, { trailingNewline: true });
|
|
500
670
|
applySnapshotSelection({
|
|
@@ -523,14 +693,38 @@ export async function maybeRefreshPricingSnapshot(opts = {}) {
|
|
|
523
693
|
state: nextState,
|
|
524
694
|
};
|
|
525
695
|
}
|
|
526
|
-
const fetchedSnapshot = buildSnapshotFromApi(fetchResult.api,
|
|
527
|
-
|
|
696
|
+
const fetchedSnapshot = buildSnapshotFromApi(fetchResult.api, requestedProviderIDs, nowMs);
|
|
697
|
+
// An all-unpriced response is still authoritative when its catalog lists
|
|
698
|
+
// models: those models must be treated as present without a cost, not as
|
|
699
|
+
// an empty/failed refresh. Only reject responses with neither prices nor
|
|
700
|
+
// catalog entries.
|
|
701
|
+
if (countPricedModels(fetchedSnapshot) === 0 && countCatalogModels(fetchedSnapshot) === 0) {
|
|
528
702
|
throw new Error("Refusing to persist empty pricing snapshot from models.dev");
|
|
529
703
|
}
|
|
704
|
+
const replacedProviderIDs = new Set(Object.keys(fetchedSnapshot.catalog ?? {}));
|
|
705
|
+
const refreshCatalog = mergeScopedCatalog({
|
|
706
|
+
previous: runtimeSnapshotBeforeRefresh?.catalog,
|
|
707
|
+
fetched: fetchedSnapshot.catalog ?? {},
|
|
708
|
+
scoped: requestedProviderIDs !== undefined,
|
|
709
|
+
});
|
|
710
|
+
const currentSnapshot = requestedProviderIDs !== undefined
|
|
711
|
+
? retainPriorPricesForUnrefreshedProviders({
|
|
712
|
+
current: fetchedSnapshot,
|
|
713
|
+
previous: runtimeSnapshotBeforeRefresh,
|
|
714
|
+
replacedProviderIDs,
|
|
715
|
+
})
|
|
716
|
+
: fetchedSnapshot;
|
|
530
717
|
const snapshot = keepRetiredModels({
|
|
531
|
-
current:
|
|
718
|
+
current: currentSnapshot,
|
|
532
719
|
previous: [runtimeSnapshotBeforeRefresh, bundledSnapshot],
|
|
533
|
-
|
|
720
|
+
// Only providers in the refresh scope were replaced. Keep prior/bundled
|
|
721
|
+
// prices for every other provider instead of dropping them.
|
|
722
|
+
providerIDs: unionProviderIDs([
|
|
723
|
+
currentSnapshot,
|
|
724
|
+
runtimeSnapshotBeforeRefresh,
|
|
725
|
+
bundledSnapshot,
|
|
726
|
+
]),
|
|
727
|
+
catalog: refreshCatalog,
|
|
534
728
|
});
|
|
535
729
|
await writeJsonAtomic(snapshotPath, snapshot, { trailingNewline: true });
|
|
536
730
|
applySnapshotSelection({
|
|
@@ -627,6 +821,14 @@ export function hasModel(providerId, modelId) {
|
|
|
627
821
|
return false;
|
|
628
822
|
return !!p[modelId];
|
|
629
823
|
}
|
|
824
|
+
/**
|
|
825
|
+
* True when the source catalog lists the exact model, even if the model has no
|
|
826
|
+
* usable cost. Catalog providers may be absent from `providers`.
|
|
827
|
+
*/
|
|
828
|
+
export function hasCatalogModel(providerId, modelId) {
|
|
829
|
+
const models = ensureLoaded().catalog?.[providerId];
|
|
830
|
+
return Array.isArray(models) && models.includes(modelId);
|
|
831
|
+
}
|
|
630
832
|
/**
|
|
631
833
|
* Infer the snapshot provider that owns a modelId.
|
|
632
834
|
* Returns null when model is not found or is ambiguous across providers.
|
|
@@ -650,6 +852,45 @@ export function listProvidersForModelId(modelId) {
|
|
|
650
852
|
const providers = ensureModelIndex().get(modelId) ?? [];
|
|
651
853
|
return [...providers].sort((a, b) => a.localeCompare(b));
|
|
652
854
|
}
|
|
855
|
+
function withoutTiers(cost) {
|
|
856
|
+
const { tiers: _tiers, ...rates } = cost;
|
|
857
|
+
return rates;
|
|
858
|
+
}
|
|
859
|
+
/**
|
|
860
|
+
* Select base or context-tier rates from one cost entry. Without a
|
|
861
|
+
* `contextTokens` value the base rates are returned and no tier is claimed as
|
|
862
|
+
* applied. A tier is selected only when the caller can prove the request
|
|
863
|
+
* context reached its threshold; malformed or unsupported tiers never
|
|
864
|
+
* participate.
|
|
865
|
+
*/
|
|
866
|
+
export function selectCostAtContext(cost, contextTokens) {
|
|
867
|
+
const tiers = cost.tiers ?? [];
|
|
868
|
+
const tierSizes = tiers.map((tier) => tier.tier.size);
|
|
869
|
+
if (tiers.length === 0 ||
|
|
870
|
+
typeof contextTokens !== "number" ||
|
|
871
|
+
!Number.isFinite(contextTokens) ||
|
|
872
|
+
contextTokens < 0) {
|
|
873
|
+
return { rates: withoutTiers(cost), basis: "base", tierSizes };
|
|
874
|
+
}
|
|
875
|
+
let selected;
|
|
876
|
+
for (const tier of tiers) {
|
|
877
|
+
if (contextTokens >= tier.tier.size)
|
|
878
|
+
selected = tier;
|
|
879
|
+
}
|
|
880
|
+
if (!selected)
|
|
881
|
+
return { rates: withoutTiers(cost), basis: "base", tierSizes };
|
|
882
|
+
const { tier: _tier, ...rates } = selected;
|
|
883
|
+
return {
|
|
884
|
+
rates,
|
|
885
|
+
basis: "context_tier",
|
|
886
|
+
tierSizes,
|
|
887
|
+
tierSize: selected.tier.size,
|
|
888
|
+
};
|
|
889
|
+
}
|
|
890
|
+
export function lookupCostAtContext(providerId, modelId, contextTokens) {
|
|
891
|
+
const cost = lookupCost(providerId, modelId);
|
|
892
|
+
return cost ? selectCostAtContext(cost, contextTokens) : null;
|
|
893
|
+
}
|
|
653
894
|
export function lookupCost(providerId, modelId) {
|
|
654
895
|
const p = ensureLoaded().providers[providerId];
|
|
655
896
|
if (!p)
|