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
|
@@ -0,0 +1,896 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
/**
|
|
3
|
+
* Narrow runtime for the temporal subset of models.dev schema v2 pricing.
|
|
4
|
+
*
|
|
5
|
+
* Supported condition keys: `utc_hours`, `utc_days`, `holiday`, recursively
|
|
6
|
+
* combined with `all`, `any` and `not`. Supported effects: `cost.text.input`
|
|
7
|
+
* / `cost.text.output` overrides and `cost.multipliers`. Anything else is
|
|
8
|
+
* unsupported and fails closed (`rates: null`).
|
|
9
|
+
*
|
|
10
|
+
* Monetary only: this module never reads or changes quota points (for example
|
|
11
|
+
* Z.ai quota accounting). Callers pass the already-resolved base token rates.
|
|
12
|
+
*
|
|
13
|
+
* `utc_hours` is a same-UTC-day minute window. In particular, `gte: "14:00"`
|
|
14
|
+
* covers 14:00 through 23:59:59.999 UTC and does not wrap into the next day.
|
|
15
|
+
*
|
|
16
|
+
* `holiday` uses the authoritative civil calendar of the jurisdiction (CN uses
|
|
17
|
+
* Asia/Shanghai, fixed UTC+8). A year without a bundled calendar is unresolved,
|
|
18
|
+
* never assumed to be a non-holiday.
|
|
19
|
+
*/
|
|
20
|
+
const BUNDLED_SNAPSHOT_URL = new URL("../data/modelsdev-temporal.min.json", import.meta.url);
|
|
21
|
+
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
22
|
+
const MINUTE_MS = 60 * 1000;
|
|
23
|
+
const CN_UTC_OFFSET_MS = 8 * 60 * 60 * 1000;
|
|
24
|
+
const MAX_TRANSITION_HORIZON_MS = 5 * 366 * DAY_MS;
|
|
25
|
+
const CLOCK_PATTERN = /^(?:[01]\d|2[0-3]):[0-5]\d$/;
|
|
26
|
+
const DATE_PATTERN = /^\d{4}-\d{2}-\d{2}$/;
|
|
27
|
+
const REVISION_PATTERN = /^[0-9a-f]{40}$/;
|
|
28
|
+
const SOURCE_PREFIX = "https://github.com/anomalyco/models.dev/tree/";
|
|
29
|
+
export const TEMPORAL_DAYS = [
|
|
30
|
+
"mon",
|
|
31
|
+
"tue",
|
|
32
|
+
"wed",
|
|
33
|
+
"thu",
|
|
34
|
+
"fri",
|
|
35
|
+
"sat",
|
|
36
|
+
"sun",
|
|
37
|
+
];
|
|
38
|
+
export const TEMPORAL_HOLIDAYS = ["CN", "US", "CA"];
|
|
39
|
+
export const TEMPORAL_RATE_KEYS = [
|
|
40
|
+
"input",
|
|
41
|
+
"output",
|
|
42
|
+
"cache_read",
|
|
43
|
+
"cache_write",
|
|
44
|
+
"reasoning",
|
|
45
|
+
];
|
|
46
|
+
export class TemporalSnapshotValidationError extends Error {
|
|
47
|
+
constructor(message) {
|
|
48
|
+
super(message);
|
|
49
|
+
this.name = "TemporalSnapshotValidationError";
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
const EMPTY_SNAPSHOT = {
|
|
53
|
+
version: 1,
|
|
54
|
+
revision: "",
|
|
55
|
+
source: "",
|
|
56
|
+
generatedAt: 0,
|
|
57
|
+
jurisdictions: {},
|
|
58
|
+
providers: {},
|
|
59
|
+
};
|
|
60
|
+
const HOUR_OPERATORS = new Set(["equals", "in", "gt", "gte", "lt", "lte"]);
|
|
61
|
+
const CHOICE_OPERATORS = new Set(["equals", "in"]);
|
|
62
|
+
const SNAPSHOT_KEYS = new Set([
|
|
63
|
+
"version",
|
|
64
|
+
"revision",
|
|
65
|
+
"source",
|
|
66
|
+
"generatedAt",
|
|
67
|
+
"jurisdictions",
|
|
68
|
+
"providers",
|
|
69
|
+
]);
|
|
70
|
+
const POLICY_KEYS = new Set(["status", "source", "overrides", "multipliers", "reason"]);
|
|
71
|
+
const CALENDAR_KEYS = new Set(["timeZone", "source", "published", "intervals", "makeupWorkdays"]);
|
|
72
|
+
const INTERVAL_KEYS = new Set(["id", "localStart", "localEnd", "startMs", "endMs"]);
|
|
73
|
+
const OVERRIDE_KEYS = new Set(["id", "field", "when", "rates"]);
|
|
74
|
+
const MULTIPLIER_KEYS = new Set(["id", "when", "factor"]);
|
|
75
|
+
let SNAPSHOT = null;
|
|
76
|
+
let VALIDATION_ERROR = null;
|
|
77
|
+
function fail(message) {
|
|
78
|
+
throw new TemporalSnapshotValidationError(message);
|
|
79
|
+
}
|
|
80
|
+
function asObject(value, path) {
|
|
81
|
+
if (value === null || Array.isArray(value) || typeof value !== "object") {
|
|
82
|
+
fail(`${path} must be an object`);
|
|
83
|
+
}
|
|
84
|
+
return value;
|
|
85
|
+
}
|
|
86
|
+
function asArray(value, path) {
|
|
87
|
+
if (!Array.isArray(value))
|
|
88
|
+
fail(`${path} must be an array`);
|
|
89
|
+
return value;
|
|
90
|
+
}
|
|
91
|
+
function asString(value, path) {
|
|
92
|
+
if (typeof value !== "string" || value.length === 0) {
|
|
93
|
+
fail(`${path} must be a non-empty string`);
|
|
94
|
+
}
|
|
95
|
+
return value;
|
|
96
|
+
}
|
|
97
|
+
function asFiniteNumber(value, path) {
|
|
98
|
+
if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
99
|
+
fail(`${path} must be a finite number`);
|
|
100
|
+
}
|
|
101
|
+
return value;
|
|
102
|
+
}
|
|
103
|
+
function asRate(value, path) {
|
|
104
|
+
const rate = asFiniteNumber(value, path);
|
|
105
|
+
if (rate < 0)
|
|
106
|
+
fail(`${path} must not be negative`);
|
|
107
|
+
return rate;
|
|
108
|
+
}
|
|
109
|
+
function assertKeys(object, allowed, path) {
|
|
110
|
+
for (const key of Object.keys(object)) {
|
|
111
|
+
if (!allowed.has(key))
|
|
112
|
+
fail(`${path}.${key} is not supported`);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
function hasOwn(object, key) {
|
|
116
|
+
return Object.hasOwn(object, key);
|
|
117
|
+
}
|
|
118
|
+
function sortRecord(record) {
|
|
119
|
+
const sorted = {};
|
|
120
|
+
for (const key of Object.keys(record).sort(compareText)) {
|
|
121
|
+
sorted[key] = record[key];
|
|
122
|
+
}
|
|
123
|
+
return sorted;
|
|
124
|
+
}
|
|
125
|
+
function compareText(a, b) {
|
|
126
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
127
|
+
}
|
|
128
|
+
function sortStrings(values) {
|
|
129
|
+
return [...new Set(values)].sort(compareText);
|
|
130
|
+
}
|
|
131
|
+
function clockMinutes(clock, path) {
|
|
132
|
+
if (!CLOCK_PATTERN.test(clock))
|
|
133
|
+
fail(`${path} must be a UTC clock HH:MM`);
|
|
134
|
+
const [hours, minutes] = clock.split(":");
|
|
135
|
+
return Number(hours) * 60 + Number(minutes);
|
|
136
|
+
}
|
|
137
|
+
function civilDateMs(date, path) {
|
|
138
|
+
if (!DATE_PATTERN.test(date))
|
|
139
|
+
fail(`${path} must be a date YYYY-MM-DD`);
|
|
140
|
+
const parsed = Date.parse(`${date}T00:00:00+08:00`);
|
|
141
|
+
if (!Number.isFinite(parsed))
|
|
142
|
+
fail(`${path} is not a valid calendar date`);
|
|
143
|
+
const roundTrip = new Date(parsed + CN_UTC_OFFSET_MS).toISOString().slice(0, 10);
|
|
144
|
+
if (roundTrip !== date)
|
|
145
|
+
fail(`${path} is not a valid calendar date`);
|
|
146
|
+
return parsed;
|
|
147
|
+
}
|
|
148
|
+
function validateProviderId(providerId, path) {
|
|
149
|
+
if (providerId.length === 0 ||
|
|
150
|
+
providerId.includes("/") ||
|
|
151
|
+
providerId.includes("\\") ||
|
|
152
|
+
providerId === "." ||
|
|
153
|
+
providerId === "..") {
|
|
154
|
+
fail(`${path} must be an exact provider id`);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
function validateModelId(modelId, path) {
|
|
158
|
+
const segments = modelId.split("/");
|
|
159
|
+
if (modelId.length === 0 ||
|
|
160
|
+
modelId.includes("\\") ||
|
|
161
|
+
segments.some((segment) => segment.length === 0 || segment === "." || segment === "..")) {
|
|
162
|
+
fail(`${path} must be an exact model id`);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
function conditionRank(condition) {
|
|
166
|
+
switch (condition.type) {
|
|
167
|
+
case "utc_days":
|
|
168
|
+
return 0;
|
|
169
|
+
case "utc_hours":
|
|
170
|
+
return 1;
|
|
171
|
+
case "holiday":
|
|
172
|
+
return 2;
|
|
173
|
+
case "not":
|
|
174
|
+
return 3;
|
|
175
|
+
case "all":
|
|
176
|
+
return 4;
|
|
177
|
+
case "any":
|
|
178
|
+
return 5;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
function canonicalConditions(conditions) {
|
|
182
|
+
return [...conditions].sort((a, b) => {
|
|
183
|
+
const rank = conditionRank(a) - conditionRank(b);
|
|
184
|
+
if (rank !== 0)
|
|
185
|
+
return rank;
|
|
186
|
+
return JSON.stringify(a) === JSON.stringify(b)
|
|
187
|
+
? 0
|
|
188
|
+
: compareText(JSON.stringify(a), JSON.stringify(b));
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
function validateChoiceAst(raw, allowed, path, type) {
|
|
192
|
+
const object = asObject(raw, path);
|
|
193
|
+
assertKeys(object, new Set(["type", "op", "value"]), path);
|
|
194
|
+
const op = asString(object.op, `${path}.op`);
|
|
195
|
+
if (!CHOICE_OPERATORS.has(op)) {
|
|
196
|
+
fail(`${path}.op must be equals or in`);
|
|
197
|
+
}
|
|
198
|
+
if (op === "equals") {
|
|
199
|
+
const value = asString(object.value, `${path}.value`);
|
|
200
|
+
if (!allowed.includes(value))
|
|
201
|
+
fail(`${path}.value is not a supported value`);
|
|
202
|
+
return { type, op: "equals", value: value };
|
|
203
|
+
}
|
|
204
|
+
const values = asArray(object.value, `${path}.value`);
|
|
205
|
+
if (values.length === 0)
|
|
206
|
+
fail(`${path}.value must not be empty`);
|
|
207
|
+
const parsed = [];
|
|
208
|
+
for (let index = 0; index < values.length; index += 1) {
|
|
209
|
+
const value = asString(values[index], `${path}.value[${index}]`);
|
|
210
|
+
if (!allowed.includes(value)) {
|
|
211
|
+
fail(`${path}.value[${index}] is not a supported value`);
|
|
212
|
+
}
|
|
213
|
+
parsed.push(value);
|
|
214
|
+
}
|
|
215
|
+
return { type, op: "in", value: sortStrings(parsed) };
|
|
216
|
+
}
|
|
217
|
+
function validateHoursAst(raw, path) {
|
|
218
|
+
const object = asObject(raw, path);
|
|
219
|
+
assertKeys(object, new Set(["type", "op", "value"]), path);
|
|
220
|
+
const op = asString(object.op, `${path}.op`);
|
|
221
|
+
if (!HOUR_OPERATORS.has(op))
|
|
222
|
+
fail(`${path}.op is not a supported UTC hour operator`);
|
|
223
|
+
if (op === "in") {
|
|
224
|
+
const values = asArray(object.value, `${path}.value`);
|
|
225
|
+
if (values.length === 0)
|
|
226
|
+
fail(`${path}.value must not be empty`);
|
|
227
|
+
const parsed = [];
|
|
228
|
+
for (let index = 0; index < values.length; index += 1) {
|
|
229
|
+
const value = asString(values[index], `${path}.value[${index}]`);
|
|
230
|
+
clockMinutes(value, `${path}.value[${index}]`);
|
|
231
|
+
parsed.push(value);
|
|
232
|
+
}
|
|
233
|
+
return { type: "utc_hours", op, value: sortStrings(parsed) };
|
|
234
|
+
}
|
|
235
|
+
const value = asString(object.value, `${path}.value`);
|
|
236
|
+
clockMinutes(value, `${path}.value`);
|
|
237
|
+
return { type: "utc_hours", op, value };
|
|
238
|
+
}
|
|
239
|
+
function validateConditionAst(raw, path, depth = 0) {
|
|
240
|
+
if (depth > 8)
|
|
241
|
+
fail(`${path} is nested too deeply`);
|
|
242
|
+
const object = asObject(raw, path);
|
|
243
|
+
const type = asString(object.type, `${path}.type`);
|
|
244
|
+
switch (type) {
|
|
245
|
+
case "all":
|
|
246
|
+
case "any": {
|
|
247
|
+
assertKeys(object, new Set(["type", "of"]), path);
|
|
248
|
+
const values = asArray(object.of, `${path}.of`);
|
|
249
|
+
if (values.length === 0)
|
|
250
|
+
fail(`${path}.of must not be empty`);
|
|
251
|
+
return {
|
|
252
|
+
type,
|
|
253
|
+
of: canonicalConditions(values.map((value, index) => validateConditionAst(value, `${path}.of[${index}]`, depth + 1))),
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
case "not":
|
|
257
|
+
assertKeys(object, new Set(["type", "of"]), path);
|
|
258
|
+
return {
|
|
259
|
+
type: "not",
|
|
260
|
+
of: validateConditionAst(object.of, `${path}.of`, depth + 1),
|
|
261
|
+
};
|
|
262
|
+
case "utc_hours":
|
|
263
|
+
return validateHoursAst(object, path);
|
|
264
|
+
case "utc_days":
|
|
265
|
+
return validateChoiceAst(object, TEMPORAL_DAYS, path, "utc_days");
|
|
266
|
+
case "holiday":
|
|
267
|
+
return validateChoiceAst(object, TEMPORAL_HOLIDAYS, path, "holiday");
|
|
268
|
+
default:
|
|
269
|
+
return fail(`${path}.type is not supported`);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
function parseRates(raw, field, path) {
|
|
273
|
+
const object = asObject(raw, path);
|
|
274
|
+
const allowed = new Set(field === "input" ? ["input", "cache_read", "cache_write"] : ["output", "reasoning"]);
|
|
275
|
+
const rates = {};
|
|
276
|
+
for (const [key, value] of Object.entries(object)) {
|
|
277
|
+
if (!allowed.has(key))
|
|
278
|
+
fail(`${path}.${key} is not supported`);
|
|
279
|
+
rates[key] = asRate(value, `${path}.${key}`);
|
|
280
|
+
}
|
|
281
|
+
if (Object.keys(rates).length === 0)
|
|
282
|
+
fail(`${path} must set at least one rate`);
|
|
283
|
+
return rates;
|
|
284
|
+
}
|
|
285
|
+
function parseMultiplierFactor(raw, path) {
|
|
286
|
+
if (typeof raw === "number") {
|
|
287
|
+
return asRate(raw, path);
|
|
288
|
+
}
|
|
289
|
+
const object = asObject(raw, path);
|
|
290
|
+
assertKeys(object, new Set(["text"]), path);
|
|
291
|
+
if (!hasOwn(object, "text"))
|
|
292
|
+
fail(`${path} must contain text`);
|
|
293
|
+
return { text: asRate(object.text, `${path}.text`) };
|
|
294
|
+
}
|
|
295
|
+
function parsePolicyEntry(raw, providerId, modelId, path) {
|
|
296
|
+
const object = asObject(raw, path);
|
|
297
|
+
assertKeys(object, POLICY_KEYS, path);
|
|
298
|
+
const status = asString(object.status, `${path}.status`);
|
|
299
|
+
const source = asString(object.source, `${path}.source`);
|
|
300
|
+
const expectedSource = `providers/${providerId}/models/${modelId}.toml`;
|
|
301
|
+
if (source !== expectedSource) {
|
|
302
|
+
fail(`${path}.source must be the exact route ${expectedSource}`);
|
|
303
|
+
}
|
|
304
|
+
if (status === "unsupported") {
|
|
305
|
+
return {
|
|
306
|
+
status: "unsupported",
|
|
307
|
+
source,
|
|
308
|
+
reason: asString(object.reason, `${path}.reason`),
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
if (status !== "supported")
|
|
312
|
+
fail(`${path}.status is not supported`);
|
|
313
|
+
const rawOverrides = asArray(object.overrides, `${path}.overrides`);
|
|
314
|
+
const rawMultipliers = asArray(object.multipliers, `${path}.multipliers`);
|
|
315
|
+
if (rawOverrides.length === 0 && rawMultipliers.length === 0) {
|
|
316
|
+
fail(`${path} must contain at least one temporal rule`);
|
|
317
|
+
}
|
|
318
|
+
const ids = new Set();
|
|
319
|
+
const overrides = rawOverrides.map((rawOverride, index) => {
|
|
320
|
+
const overridePath = `${path}.overrides[${index}]`;
|
|
321
|
+
const override = asObject(rawOverride, overridePath);
|
|
322
|
+
assertKeys(override, OVERRIDE_KEYS, overridePath);
|
|
323
|
+
const id = asString(override.id, `${overridePath}.id`);
|
|
324
|
+
if (ids.has(id))
|
|
325
|
+
fail(`${overridePath}.id duplicates ${id}`);
|
|
326
|
+
ids.add(id);
|
|
327
|
+
const field = asString(override.field, `${overridePath}.field`);
|
|
328
|
+
if (field !== "input" && field !== "output")
|
|
329
|
+
fail(`${overridePath}.field is not supported`);
|
|
330
|
+
return {
|
|
331
|
+
id,
|
|
332
|
+
field,
|
|
333
|
+
when: validateConditionAst(override.when, `${overridePath}.when`),
|
|
334
|
+
rates: parseRates(override.rates, field, `${overridePath}.rates`),
|
|
335
|
+
};
|
|
336
|
+
});
|
|
337
|
+
const multipliers = rawMultipliers.map((rawMultiplier, index) => {
|
|
338
|
+
const multiplierPath = `${path}.multipliers[${index}]`;
|
|
339
|
+
const multiplier = asObject(rawMultiplier, multiplierPath);
|
|
340
|
+
assertKeys(multiplier, MULTIPLIER_KEYS, multiplierPath);
|
|
341
|
+
const id = asString(multiplier.id, `${multiplierPath}.id`);
|
|
342
|
+
if (ids.has(id))
|
|
343
|
+
fail(`${multiplierPath}.id duplicates ${id}`);
|
|
344
|
+
ids.add(id);
|
|
345
|
+
return {
|
|
346
|
+
id,
|
|
347
|
+
when: validateConditionAst(multiplier.when, `${multiplierPath}.when`),
|
|
348
|
+
factor: parseMultiplierFactor(multiplier.factor, `${multiplierPath}.factor`),
|
|
349
|
+
};
|
|
350
|
+
});
|
|
351
|
+
return { status: "supported", source, overrides, multipliers };
|
|
352
|
+
}
|
|
353
|
+
function parseHolidayCalendar(raw, path) {
|
|
354
|
+
const object = asObject(raw, path);
|
|
355
|
+
assertKeys(object, CALENDAR_KEYS, path);
|
|
356
|
+
const timeZone = asString(object.timeZone, `${path}.timeZone`);
|
|
357
|
+
if (timeZone !== "Asia/Shanghai")
|
|
358
|
+
fail(`${path}.timeZone is not supported`);
|
|
359
|
+
const source = asString(object.source, `${path}.source`);
|
|
360
|
+
const published = asString(object.published, `${path}.published`);
|
|
361
|
+
civilDateMs(published, `${path}.published`);
|
|
362
|
+
const rawIntervals = asArray(object.intervals, `${path}.intervals`);
|
|
363
|
+
if (rawIntervals.length === 0)
|
|
364
|
+
fail(`${path}.intervals must not be empty`);
|
|
365
|
+
const ids = new Set();
|
|
366
|
+
const intervals = [];
|
|
367
|
+
let previousEnd = Number.NEGATIVE_INFINITY;
|
|
368
|
+
for (let index = 0; index < rawIntervals.length; index += 1) {
|
|
369
|
+
const intervalPath = `${path}.intervals[${index}]`;
|
|
370
|
+
const interval = asObject(rawIntervals[index], intervalPath);
|
|
371
|
+
assertKeys(interval, INTERVAL_KEYS, intervalPath);
|
|
372
|
+
const id = asString(interval.id, `${intervalPath}.id`);
|
|
373
|
+
if (ids.has(id))
|
|
374
|
+
fail(`${intervalPath}.id duplicates ${id}`);
|
|
375
|
+
ids.add(id);
|
|
376
|
+
const localStart = asString(interval.localStart, `${intervalPath}.localStart`);
|
|
377
|
+
const localEnd = asString(interval.localEnd, `${intervalPath}.localEnd`);
|
|
378
|
+
const startMs = asFiniteNumber(interval.startMs, `${intervalPath}.startMs`);
|
|
379
|
+
const endMs = asFiniteNumber(interval.endMs, `${intervalPath}.endMs`);
|
|
380
|
+
const expectedStart = civilDateMs(localStart, `${intervalPath}.localStart`);
|
|
381
|
+
const expectedEnd = civilDateMs(localEnd, `${intervalPath}.localEnd`);
|
|
382
|
+
if (startMs !== expectedStart || endMs !== expectedEnd) {
|
|
383
|
+
fail(`${intervalPath} boundary must match Asia/Shanghai midnight`);
|
|
384
|
+
}
|
|
385
|
+
if (!Number.isSafeInteger(startMs) || !Number.isSafeInteger(endMs) || endMs <= startMs) {
|
|
386
|
+
fail(`${intervalPath} must be a positive half-open interval`);
|
|
387
|
+
}
|
|
388
|
+
if (startMs < previousEnd)
|
|
389
|
+
fail(`${path}.intervals must be sorted and non-overlapping`);
|
|
390
|
+
previousEnd = endMs;
|
|
391
|
+
intervals.push({ id, localStart, localEnd, startMs, endMs });
|
|
392
|
+
}
|
|
393
|
+
const makeupWorkdays = asArray(object.makeupWorkdays, `${path}.makeupWorkdays`).map((value, index) => {
|
|
394
|
+
const date = asString(value, `${path}.makeupWorkdays[${index}]`);
|
|
395
|
+
civilDateMs(date, `${path}.makeupWorkdays[${index}]`);
|
|
396
|
+
return date;
|
|
397
|
+
});
|
|
398
|
+
const sortedWorkdays = sortStrings(makeupWorkdays);
|
|
399
|
+
if (sortedWorkdays.join(",") !== makeupWorkdays.join(",")) {
|
|
400
|
+
fail(`${path}.makeupWorkdays must be sorted and unique`);
|
|
401
|
+
}
|
|
402
|
+
for (const date of makeupWorkdays) {
|
|
403
|
+
const instant = civilDateMs(date, `${path}.makeupWorkdays`);
|
|
404
|
+
if (intervals.some((interval) => instant >= interval.startMs && instant < interval.endMs)) {
|
|
405
|
+
fail(`${path}.makeupWorkdays must not fall inside a holiday interval`);
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
return { timeZone, source, published, intervals, makeupWorkdays };
|
|
409
|
+
}
|
|
410
|
+
function parseJurisdictions(raw) {
|
|
411
|
+
const object = asObject(raw, "snapshot.jurisdictions");
|
|
412
|
+
const jurisdictions = {};
|
|
413
|
+
for (const [jurisdiction, rawYears] of Object.entries(object)) {
|
|
414
|
+
if (!TEMPORAL_HOLIDAYS.includes(jurisdiction)) {
|
|
415
|
+
fail(`snapshot.jurisdictions.${jurisdiction} is not supported`);
|
|
416
|
+
}
|
|
417
|
+
const yearsObject = asObject(rawYears, `snapshot.jurisdictions.${jurisdiction}`);
|
|
418
|
+
const years = {};
|
|
419
|
+
for (const [year, rawCalendar] of Object.entries(yearsObject)) {
|
|
420
|
+
if (!/^\d{4}$/.test(year))
|
|
421
|
+
fail(`snapshot.jurisdictions.${jurisdiction}.${year} is invalid`);
|
|
422
|
+
years[year] = parseHolidayCalendar(rawCalendar, `snapshot.jurisdictions.${jurisdiction}.${year}`);
|
|
423
|
+
}
|
|
424
|
+
jurisdictions[jurisdiction] = sortRecord(years);
|
|
425
|
+
}
|
|
426
|
+
const cn = jurisdictions.CN;
|
|
427
|
+
if (!cn || !cn["2026"])
|
|
428
|
+
fail("snapshot must bundle the authoritative CN 2026 calendar");
|
|
429
|
+
return sortRecord(jurisdictions);
|
|
430
|
+
}
|
|
431
|
+
function parseProviders(raw) {
|
|
432
|
+
const object = asObject(raw, "snapshot.providers");
|
|
433
|
+
const providers = {};
|
|
434
|
+
for (const [providerId, rawModels] of Object.entries(object)) {
|
|
435
|
+
validateProviderId(providerId, `snapshot.providers.${providerId}`);
|
|
436
|
+
const modelsObject = asObject(rawModels, `snapshot.providers.${providerId}`);
|
|
437
|
+
const models = {};
|
|
438
|
+
for (const [modelId, rawPolicy] of Object.entries(modelsObject)) {
|
|
439
|
+
validateModelId(modelId, `snapshot.providers.${providerId}.${modelId}`);
|
|
440
|
+
models[modelId] = parsePolicyEntry(rawPolicy, providerId, modelId, `snapshot.providers.${providerId}.${modelId}`);
|
|
441
|
+
}
|
|
442
|
+
providers[providerId] = sortRecord(models);
|
|
443
|
+
}
|
|
444
|
+
return sortRecord(providers);
|
|
445
|
+
}
|
|
446
|
+
export function normalizeTemporalSnapshot(raw) {
|
|
447
|
+
const object = asObject(raw, "snapshot");
|
|
448
|
+
assertKeys(object, SNAPSHOT_KEYS, "snapshot");
|
|
449
|
+
const version = asFiniteNumber(object.version, "snapshot.version");
|
|
450
|
+
if (version !== 1)
|
|
451
|
+
fail("snapshot.version must be 1");
|
|
452
|
+
const revision = asString(object.revision, "snapshot.revision");
|
|
453
|
+
if (!REVISION_PATTERN.test(revision))
|
|
454
|
+
fail("snapshot.revision must be a full git revision");
|
|
455
|
+
const source = asString(object.source, "snapshot.source");
|
|
456
|
+
if (source !== `${SOURCE_PREFIX}${revision}`) {
|
|
457
|
+
fail("snapshot.source must retain the exact pinned revision");
|
|
458
|
+
}
|
|
459
|
+
const generatedAt = asFiniteNumber(object.generatedAt, "snapshot.generatedAt");
|
|
460
|
+
if (!Number.isSafeInteger(generatedAt) || generatedAt <= 0) {
|
|
461
|
+
fail("snapshot.generatedAt must be a positive safe integer");
|
|
462
|
+
}
|
|
463
|
+
const jurisdictions = parseJurisdictions(object.jurisdictions);
|
|
464
|
+
const providers = parseProviders(object.providers);
|
|
465
|
+
return {
|
|
466
|
+
version: 1,
|
|
467
|
+
revision,
|
|
468
|
+
source,
|
|
469
|
+
generatedAt,
|
|
470
|
+
jurisdictions,
|
|
471
|
+
providers,
|
|
472
|
+
};
|
|
473
|
+
}
|
|
474
|
+
function ensureSnapshot() {
|
|
475
|
+
if (SNAPSHOT)
|
|
476
|
+
return SNAPSHOT;
|
|
477
|
+
try {
|
|
478
|
+
const raw = JSON.parse(readFileSync(BUNDLED_SNAPSHOT_URL, "utf-8"));
|
|
479
|
+
SNAPSHOT = normalizeTemporalSnapshot(raw);
|
|
480
|
+
}
|
|
481
|
+
catch (error) {
|
|
482
|
+
VALIDATION_ERROR =
|
|
483
|
+
error instanceof Error ? error.message : "modelsdev temporal snapshot is invalid";
|
|
484
|
+
SNAPSHOT = EMPTY_SNAPSHOT;
|
|
485
|
+
}
|
|
486
|
+
return SNAPSHOT;
|
|
487
|
+
}
|
|
488
|
+
export function setTemporalSnapshotForTests(snapshot) {
|
|
489
|
+
SNAPSHOT = normalizeTemporalSnapshot(snapshot);
|
|
490
|
+
VALIDATION_ERROR = null;
|
|
491
|
+
}
|
|
492
|
+
export function __resetTemporalSnapshotForTests() {
|
|
493
|
+
SNAPSHOT = null;
|
|
494
|
+
VALIDATION_ERROR = null;
|
|
495
|
+
}
|
|
496
|
+
export function getTemporalSnapshotMeta() {
|
|
497
|
+
const snapshot = ensureSnapshot();
|
|
498
|
+
return {
|
|
499
|
+
revision: snapshot.revision,
|
|
500
|
+
source: snapshot.source,
|
|
501
|
+
generatedAt: snapshot.generatedAt,
|
|
502
|
+
};
|
|
503
|
+
}
|
|
504
|
+
/** Returns the bundled-snapshot validation error, or null when it loaded cleanly. */
|
|
505
|
+
export function getTemporalSnapshotValidationError() {
|
|
506
|
+
ensureSnapshot();
|
|
507
|
+
return VALIDATION_ERROR;
|
|
508
|
+
}
|
|
509
|
+
/** Exact provider/model temporal policy, or null when the model has none. */
|
|
510
|
+
export function getTemporalPolicy(providerId, modelId) {
|
|
511
|
+
return ensureSnapshot().providers[providerId]?.[modelId] ?? null;
|
|
512
|
+
}
|
|
513
|
+
export function hasTemporalPolicy(providerId, modelId) {
|
|
514
|
+
return getTemporalPolicy(providerId, modelId) !== null;
|
|
515
|
+
}
|
|
516
|
+
function utcMinuteOfDay(atMs) {
|
|
517
|
+
const date = new Date(atMs);
|
|
518
|
+
return date.getUTCHours() * 60 + date.getUTCMinutes();
|
|
519
|
+
}
|
|
520
|
+
function utcDayOfWeek(atMs) {
|
|
521
|
+
const index = new Date(atMs).getUTCDay();
|
|
522
|
+
return ["sun", "mon", "tue", "wed", "thu", "fri", "sat"][index];
|
|
523
|
+
}
|
|
524
|
+
function compareClock(minute, op, value) {
|
|
525
|
+
const target = clockMinutes(value, "utc_hours");
|
|
526
|
+
switch (op) {
|
|
527
|
+
case "equals":
|
|
528
|
+
return minute === target;
|
|
529
|
+
case "gt":
|
|
530
|
+
return minute > target;
|
|
531
|
+
case "gte":
|
|
532
|
+
return minute >= target;
|
|
533
|
+
case "lt":
|
|
534
|
+
return minute < target;
|
|
535
|
+
case "lte":
|
|
536
|
+
return minute <= target;
|
|
537
|
+
case "in":
|
|
538
|
+
return false;
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
function matchChoice(value, op, expected) {
|
|
542
|
+
if (op === "equals") {
|
|
543
|
+
return typeof expected === "string" && value === expected;
|
|
544
|
+
}
|
|
545
|
+
return Array.isArray(expected) && expected.includes(value);
|
|
546
|
+
}
|
|
547
|
+
function resolved(value) {
|
|
548
|
+
return { status: "resolved", value };
|
|
549
|
+
}
|
|
550
|
+
function unresolved(reason) {
|
|
551
|
+
return { status: "unresolved", value: null, reason };
|
|
552
|
+
}
|
|
553
|
+
function unsupported(reason) {
|
|
554
|
+
return { status: "unsupported", value: null, reason };
|
|
555
|
+
}
|
|
556
|
+
function localCivilYear(atMs) {
|
|
557
|
+
return new Date(atMs + CN_UTC_OFFSET_MS).getUTCFullYear();
|
|
558
|
+
}
|
|
559
|
+
function evaluateHolidayValue(holiday, atMs) {
|
|
560
|
+
const snapshot = ensureSnapshot();
|
|
561
|
+
const year = localCivilYear(atMs);
|
|
562
|
+
const calendar = snapshot.jurisdictions[holiday]?.[String(year)];
|
|
563
|
+
if (!calendar) {
|
|
564
|
+
return unresolved(`${holiday} public holiday calendar for ${year} is unavailable`);
|
|
565
|
+
}
|
|
566
|
+
const active = calendar.intervals.some((interval) => atMs >= interval.startMs && atMs < interval.endMs);
|
|
567
|
+
return resolved(active);
|
|
568
|
+
}
|
|
569
|
+
function orEvaluations(evaluations) {
|
|
570
|
+
if (evaluations.some((evaluation) => evaluation.status === "resolved" && evaluation.value)) {
|
|
571
|
+
return resolved(true);
|
|
572
|
+
}
|
|
573
|
+
const unknown = evaluations.find((evaluation) => evaluation.status === "unresolved");
|
|
574
|
+
if (unknown)
|
|
575
|
+
return unresolved(unknown.reason ?? "temporal condition is unresolved");
|
|
576
|
+
const bad = evaluations.find((evaluation) => evaluation.status === "unsupported");
|
|
577
|
+
if (bad)
|
|
578
|
+
return unsupported(bad.reason ?? "temporal condition is unsupported");
|
|
579
|
+
return resolved(false);
|
|
580
|
+
}
|
|
581
|
+
export function evaluateTemporalCondition(condition, atMs) {
|
|
582
|
+
if (!Number.isFinite(atMs))
|
|
583
|
+
fail("atMs must be a finite epoch millisecond");
|
|
584
|
+
switch (condition.type) {
|
|
585
|
+
case "all": {
|
|
586
|
+
const evaluations = condition.of.map((child) => evaluateTemporalCondition(child, atMs));
|
|
587
|
+
const bad = evaluations.find((evaluation) => evaluation.status === "unsupported");
|
|
588
|
+
if (bad)
|
|
589
|
+
return bad;
|
|
590
|
+
if (evaluations.some((evaluation) => evaluation.status === "resolved" && !evaluation.value)) {
|
|
591
|
+
return resolved(false);
|
|
592
|
+
}
|
|
593
|
+
const unknown = evaluations.find((evaluation) => evaluation.status === "unresolved");
|
|
594
|
+
if (unknown)
|
|
595
|
+
return unresolved(unknown.reason ?? "temporal condition is unresolved");
|
|
596
|
+
return resolved(true);
|
|
597
|
+
}
|
|
598
|
+
case "any":
|
|
599
|
+
return orEvaluations(condition.of.map((child) => evaluateTemporalCondition(child, atMs)));
|
|
600
|
+
case "not": {
|
|
601
|
+
const evaluation = evaluateTemporalCondition(condition.of, atMs);
|
|
602
|
+
if (evaluation.status !== "resolved" || evaluation.value === null)
|
|
603
|
+
return evaluation;
|
|
604
|
+
return resolved(!evaluation.value);
|
|
605
|
+
}
|
|
606
|
+
case "utc_hours": {
|
|
607
|
+
const minute = utcMinuteOfDay(atMs);
|
|
608
|
+
if (condition.op === "in") {
|
|
609
|
+
const values = Array.isArray(condition.value) ? condition.value : [];
|
|
610
|
+
return resolved(values.some((value) => minute === clockMinutes(value, "utc_hours")));
|
|
611
|
+
}
|
|
612
|
+
return resolved(compareClock(minute, condition.op, condition.value));
|
|
613
|
+
}
|
|
614
|
+
case "utc_days":
|
|
615
|
+
return resolved(matchChoice(utcDayOfWeek(atMs), condition.op, condition.value));
|
|
616
|
+
case "holiday": {
|
|
617
|
+
const values = Array.isArray(condition.value) ? condition.value : [condition.value];
|
|
618
|
+
return orEvaluations(values.map((value) => evaluateHolidayValue(value, atMs)));
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
function copyRates(rates) {
|
|
623
|
+
const copy = {};
|
|
624
|
+
for (const key of TEMPORAL_RATE_KEYS) {
|
|
625
|
+
const value = rates[key];
|
|
626
|
+
if (typeof value === "number" && Number.isFinite(value))
|
|
627
|
+
copy[key] = value;
|
|
628
|
+
}
|
|
629
|
+
return copy;
|
|
630
|
+
}
|
|
631
|
+
function mergeRates(target, incoming) {
|
|
632
|
+
for (const key of TEMPORAL_RATE_KEYS) {
|
|
633
|
+
const value = incoming[key];
|
|
634
|
+
if (typeof value === "number")
|
|
635
|
+
target[key] = value;
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
function factorFor(factor) {
|
|
639
|
+
return typeof factor === "number" ? factor : factor.text;
|
|
640
|
+
}
|
|
641
|
+
function applyMultiplier(rates, factor) {
|
|
642
|
+
for (const key of TEMPORAL_RATE_KEYS) {
|
|
643
|
+
const value = rates[key];
|
|
644
|
+
if (typeof value === "number")
|
|
645
|
+
rates[key] = value * factorFor(factor);
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
function evaluatePolicyRules(policy, atMs) {
|
|
649
|
+
const activeRuleIds = [];
|
|
650
|
+
let unresolvedReason;
|
|
651
|
+
for (const rule of [...policy.overrides, ...policy.multipliers]) {
|
|
652
|
+
const evaluation = evaluateTemporalCondition(rule.when, atMs);
|
|
653
|
+
if (evaluation.status === "unsupported") {
|
|
654
|
+
return { status: "unsupported", activeRuleIds: [], reason: evaluation.reason };
|
|
655
|
+
}
|
|
656
|
+
if (evaluation.status === "unresolved") {
|
|
657
|
+
unresolvedReason = unresolvedReason ?? evaluation.reason;
|
|
658
|
+
continue;
|
|
659
|
+
}
|
|
660
|
+
if (evaluation.value)
|
|
661
|
+
activeRuleIds.push(rule.id);
|
|
662
|
+
}
|
|
663
|
+
if (unresolvedReason !== undefined) {
|
|
664
|
+
return { status: "unresolved", activeRuleIds, reason: unresolvedReason };
|
|
665
|
+
}
|
|
666
|
+
return { status: "resolved", activeRuleIds };
|
|
667
|
+
}
|
|
668
|
+
export function getTemporalInstantState(providerId, modelId, atMs) {
|
|
669
|
+
const policy = getTemporalPolicy(providerId, modelId);
|
|
670
|
+
if (!policy)
|
|
671
|
+
return { status: "resolved", activeRuleIds: [] };
|
|
672
|
+
if (policy.status === "unsupported") {
|
|
673
|
+
return { status: "unsupported", activeRuleIds: [], reason: policy.reason };
|
|
674
|
+
}
|
|
675
|
+
return evaluatePolicyRules(policy, atMs);
|
|
676
|
+
}
|
|
677
|
+
/**
|
|
678
|
+
* Apply a model's temporal overrides in source order, then every matching
|
|
679
|
+
* multiplier. `rates` is null whenever the result is not fully resolved, so a
|
|
680
|
+
* caller can never mistake an unknown year or unsupported rule for a price.
|
|
681
|
+
*/
|
|
682
|
+
export function resolveTemporalRates(providerId, modelId, atMs, baseRates) {
|
|
683
|
+
const policy = getTemporalPolicy(providerId, modelId);
|
|
684
|
+
const base = copyRates(baseRates);
|
|
685
|
+
if (!policy)
|
|
686
|
+
return { status: "resolved", rates: base, appliedRuleIds: [] };
|
|
687
|
+
if (policy.status === "unsupported") {
|
|
688
|
+
return {
|
|
689
|
+
status: "unsupported",
|
|
690
|
+
rates: null,
|
|
691
|
+
appliedRuleIds: [],
|
|
692
|
+
reason: policy.reason,
|
|
693
|
+
};
|
|
694
|
+
}
|
|
695
|
+
const rates = copyRates(base);
|
|
696
|
+
const appliedRuleIds = [];
|
|
697
|
+
for (const override of policy.overrides) {
|
|
698
|
+
const evaluation = evaluateTemporalCondition(override.when, atMs);
|
|
699
|
+
if (evaluation.status !== "resolved") {
|
|
700
|
+
return {
|
|
701
|
+
status: evaluation.status,
|
|
702
|
+
rates: null,
|
|
703
|
+
appliedRuleIds,
|
|
704
|
+
reason: evaluation.reason,
|
|
705
|
+
};
|
|
706
|
+
}
|
|
707
|
+
if (evaluation.value) {
|
|
708
|
+
mergeRates(rates, override.rates);
|
|
709
|
+
appliedRuleIds.push(override.id);
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
for (const multiplier of policy.multipliers) {
|
|
713
|
+
const evaluation = evaluateTemporalCondition(multiplier.when, atMs);
|
|
714
|
+
if (evaluation.status !== "resolved") {
|
|
715
|
+
return {
|
|
716
|
+
status: evaluation.status,
|
|
717
|
+
rates: null,
|
|
718
|
+
appliedRuleIds,
|
|
719
|
+
reason: evaluation.reason,
|
|
720
|
+
};
|
|
721
|
+
}
|
|
722
|
+
if (evaluation.value) {
|
|
723
|
+
applyMultiplier(rates, multiplier.factor);
|
|
724
|
+
appliedRuleIds.push(multiplier.id);
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
return { status: "resolved", rates, appliedRuleIds };
|
|
728
|
+
}
|
|
729
|
+
function collectClockMinutes(condition, minutes) {
|
|
730
|
+
switch (condition.type) {
|
|
731
|
+
case "all":
|
|
732
|
+
case "any":
|
|
733
|
+
for (const child of condition.of)
|
|
734
|
+
collectClockMinutes(child, minutes);
|
|
735
|
+
return;
|
|
736
|
+
case "not":
|
|
737
|
+
collectClockMinutes(condition.of, minutes);
|
|
738
|
+
return;
|
|
739
|
+
case "utc_hours": {
|
|
740
|
+
const values = Array.isArray(condition.value) ? condition.value : [condition.value];
|
|
741
|
+
for (const value of values) {
|
|
742
|
+
const target = clockMinutes(value, "utc_hours");
|
|
743
|
+
if (condition.op === "equals" ||
|
|
744
|
+
condition.op === "in" ||
|
|
745
|
+
condition.op === "gt" ||
|
|
746
|
+
condition.op === "lte") {
|
|
747
|
+
minutes.add(target + 1);
|
|
748
|
+
}
|
|
749
|
+
if (condition.op !== "gt")
|
|
750
|
+
minutes.add(target);
|
|
751
|
+
}
|
|
752
|
+
return;
|
|
753
|
+
}
|
|
754
|
+
case "utc_days":
|
|
755
|
+
case "holiday":
|
|
756
|
+
return;
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
function policyClockMinutes(policy) {
|
|
760
|
+
const minutes = new Set();
|
|
761
|
+
for (const rule of [...policy.overrides, ...policy.multipliers]) {
|
|
762
|
+
collectClockMinutes(rule.when, minutes);
|
|
763
|
+
}
|
|
764
|
+
minutes.add(0);
|
|
765
|
+
return [...minutes].sort((a, b) => a - b);
|
|
766
|
+
}
|
|
767
|
+
function dayStartMs(atMs) {
|
|
768
|
+
const date = new Date(atMs);
|
|
769
|
+
return Date.UTC(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate());
|
|
770
|
+
}
|
|
771
|
+
function collectCandidateInstants(policy, fromMs, toMs) {
|
|
772
|
+
const candidates = new Set();
|
|
773
|
+
const minutes = policyClockMinutes(policy);
|
|
774
|
+
const firstDay = dayStartMs(fromMs);
|
|
775
|
+
const lastDay = dayStartMs(toMs);
|
|
776
|
+
for (let day = firstDay; day <= lastDay; day += DAY_MS) {
|
|
777
|
+
for (const minute of minutes) {
|
|
778
|
+
const instant = day + minute * MINUTE_MS;
|
|
779
|
+
if (instant >= fromMs && instant <= toMs)
|
|
780
|
+
candidates.add(instant);
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
const snapshot = ensureSnapshot();
|
|
784
|
+
for (const years of Object.values(snapshot.jurisdictions)) {
|
|
785
|
+
for (const calendar of Object.values(years)) {
|
|
786
|
+
for (const interval of calendar.intervals) {
|
|
787
|
+
if (interval.startMs >= fromMs && interval.startMs <= toMs) {
|
|
788
|
+
candidates.add(interval.startMs);
|
|
789
|
+
}
|
|
790
|
+
if (interval.endMs >= fromMs && interval.endMs <= toMs)
|
|
791
|
+
candidates.add(interval.endMs);
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
for (const calendar of Object.values(years)) {
|
|
795
|
+
const calendarYears = new Set(calendar.intervals.map((interval) => Number(interval.localStart.slice(0, 4))));
|
|
796
|
+
for (const year of calendarYears) {
|
|
797
|
+
for (const candidateYear of [year, year + 1]) {
|
|
798
|
+
const boundary = Date.parse(`${candidateYear}-01-01T00:00:00+08:00`);
|
|
799
|
+
if (boundary >= fromMs && boundary <= toMs)
|
|
800
|
+
candidates.add(boundary);
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
return [...candidates].sort((a, b) => a - b);
|
|
806
|
+
}
|
|
807
|
+
function sameState(a, b) {
|
|
808
|
+
return (a.status === b.status &&
|
|
809
|
+
a.activeRuleIds.length === b.activeRuleIds.length &&
|
|
810
|
+
a.activeRuleIds.every((id, index) => id === b.activeRuleIds[index]));
|
|
811
|
+
}
|
|
812
|
+
/** Next instant at which the resolved state or active rule set changes, within a
|
|
813
|
+
* bounded five-year search horizon. Returns null when nothing changes or the
|
|
814
|
+
* policy is unsupported. */
|
|
815
|
+
export function getNextTemporalTransition(providerId, modelId, fromMs) {
|
|
816
|
+
const policy = getTemporalPolicy(providerId, modelId);
|
|
817
|
+
if (!policy || policy.status !== "supported")
|
|
818
|
+
return null;
|
|
819
|
+
const horizonEnd = fromMs + MAX_TRANSITION_HORIZON_MS;
|
|
820
|
+
const candidates = collectCandidateInstants(policy, fromMs + 1, horizonEnd);
|
|
821
|
+
let previous = getTemporalInstantState(providerId, modelId, fromMs);
|
|
822
|
+
for (const candidate of candidates) {
|
|
823
|
+
if (candidate <= fromMs)
|
|
824
|
+
continue;
|
|
825
|
+
const next = getTemporalInstantState(providerId, modelId, candidate);
|
|
826
|
+
if (!sameState(previous, next)) {
|
|
827
|
+
return { atMs: candidate, before: previous, after: next };
|
|
828
|
+
}
|
|
829
|
+
previous = next;
|
|
830
|
+
}
|
|
831
|
+
return null;
|
|
832
|
+
}
|
|
833
|
+
function sameRates(a, b) {
|
|
834
|
+
return JSON.stringify(a) === JSON.stringify(b);
|
|
835
|
+
}
|
|
836
|
+
/** Half-open `[startMs, endMs)` windows grouped by status, active rules and
|
|
837
|
+
* (when supplied) the effective temporal rates. */
|
|
838
|
+
export function listTemporalIntervals(providerId, modelId, fromMs, toMs, baseRates) {
|
|
839
|
+
if (!Number.isFinite(fromMs) || !Number.isFinite(toMs) || toMs <= fromMs) {
|
|
840
|
+
fail("listTemporalIntervals requires fromMs < toMs");
|
|
841
|
+
}
|
|
842
|
+
const policy = getTemporalPolicy(providerId, modelId);
|
|
843
|
+
if (!policy || policy.status === "unsupported") {
|
|
844
|
+
const state = getTemporalInstantState(providerId, modelId, fromMs);
|
|
845
|
+
const resolution = baseRates
|
|
846
|
+
? resolveTemporalRates(providerId, modelId, fromMs, baseRates)
|
|
847
|
+
: null;
|
|
848
|
+
return [
|
|
849
|
+
{
|
|
850
|
+
startMs: fromMs,
|
|
851
|
+
endMs: toMs,
|
|
852
|
+
status: state.status,
|
|
853
|
+
activeRuleIds: state.activeRuleIds,
|
|
854
|
+
rates: resolution?.status === "resolved" ? resolution.rates : null,
|
|
855
|
+
reason: state.reason,
|
|
856
|
+
},
|
|
857
|
+
];
|
|
858
|
+
}
|
|
859
|
+
const boundaries = collectCandidateInstants(policy, fromMs, toMs);
|
|
860
|
+
if (boundaries[0] !== fromMs)
|
|
861
|
+
boundaries.unshift(fromMs);
|
|
862
|
+
if (boundaries[boundaries.length - 1] !== toMs)
|
|
863
|
+
boundaries.push(toMs);
|
|
864
|
+
const intervals = [];
|
|
865
|
+
for (let index = 0; index < boundaries.length - 1; index += 1) {
|
|
866
|
+
const startMs = boundaries[index];
|
|
867
|
+
const endMs = boundaries[index + 1];
|
|
868
|
+
if (endMs <= startMs)
|
|
869
|
+
continue;
|
|
870
|
+
const state = getTemporalInstantState(providerId, modelId, startMs);
|
|
871
|
+
const resolution = baseRates
|
|
872
|
+
? resolveTemporalRates(providerId, modelId, startMs, baseRates)
|
|
873
|
+
: null;
|
|
874
|
+
const interval = {
|
|
875
|
+
startMs,
|
|
876
|
+
endMs,
|
|
877
|
+
status: state.status,
|
|
878
|
+
activeRuleIds: state.activeRuleIds,
|
|
879
|
+
rates: resolution?.status === "resolved" ? resolution.rates : null,
|
|
880
|
+
reason: state.reason,
|
|
881
|
+
};
|
|
882
|
+
const previous = intervals[intervals.length - 1];
|
|
883
|
+
if (previous &&
|
|
884
|
+
previous.status === interval.status &&
|
|
885
|
+
previous.reason === interval.reason &&
|
|
886
|
+
previous.activeRuleIds.join("\u0000") === interval.activeRuleIds.join("\u0000") &&
|
|
887
|
+
sameRates(previous.rates, interval.rates)) {
|
|
888
|
+
previous.endMs = endMs;
|
|
889
|
+
}
|
|
890
|
+
else {
|
|
891
|
+
intervals.push(interval);
|
|
892
|
+
}
|
|
893
|
+
}
|
|
894
|
+
return intervals;
|
|
895
|
+
}
|
|
896
|
+
//# sourceMappingURL=modelsdev-temporal.js.map
|