@bastani/pi-ai 0.9.14
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/CHANGELOG.md +9 -0
- package/LICENSE +22 -0
- package/NOTICE.md +16 -0
- package/README.md +1672 -0
- package/dist/api/anthropic-messages.d.ts +71 -0
- package/dist/api/anthropic-messages.d.ts.map +1 -0
- package/dist/api/anthropic-messages.js +1060 -0
- package/dist/api/anthropic-messages.js.map +1 -0
- package/dist/api/anthropic-messages.lazy.d.ts +3 -0
- package/dist/api/anthropic-messages.lazy.d.ts.map +1 -0
- package/dist/api/anthropic-messages.lazy.js +3 -0
- package/dist/api/anthropic-messages.lazy.js.map +1 -0
- package/dist/api/azure-openai-responses.d.ts +15 -0
- package/dist/api/azure-openai-responses.d.ts.map +1 -0
- package/dist/api/azure-openai-responses.js +242 -0
- package/dist/api/azure-openai-responses.js.map +1 -0
- package/dist/api/azure-openai-responses.lazy.d.ts +3 -0
- package/dist/api/azure-openai-responses.lazy.d.ts.map +1 -0
- package/dist/api/azure-openai-responses.lazy.js +3 -0
- package/dist/api/azure-openai-responses.lazy.js.map +1 -0
- package/dist/api/bedrock-converse-stream.d.ts +38 -0
- package/dist/api/bedrock-converse-stream.d.ts.map +1 -0
- package/dist/api/bedrock-converse-stream.js +967 -0
- package/dist/api/bedrock-converse-stream.js.map +1 -0
- package/dist/api/bedrock-converse-stream.lazy.d.ts +9 -0
- package/dist/api/bedrock-converse-stream.lazy.d.ts.map +1 -0
- package/dist/api/bedrock-converse-stream.lazy.js +30 -0
- package/dist/api/bedrock-converse-stream.lazy.js.map +1 -0
- package/dist/api/cloudflare-gateway-binding.d.ts +69 -0
- package/dist/api/cloudflare-gateway-binding.d.ts.map +1 -0
- package/dist/api/cloudflare-gateway-binding.js +159 -0
- package/dist/api/cloudflare-gateway-binding.js.map +1 -0
- package/dist/api/cloudflare.d.ts +9 -0
- package/dist/api/cloudflare.d.ts.map +1 -0
- package/dist/api/cloudflare.js +9 -0
- package/dist/api/cloudflare.js.map +1 -0
- package/dist/api/constrained-sampling.d.ts +20 -0
- package/dist/api/constrained-sampling.d.ts.map +1 -0
- package/dist/api/constrained-sampling.js +222 -0
- package/dist/api/constrained-sampling.js.map +1 -0
- package/dist/api/github-copilot-headers.d.ts +8 -0
- package/dist/api/github-copilot-headers.d.ts.map +1 -0
- package/dist/api/github-copilot-headers.js +29 -0
- package/dist/api/github-copilot-headers.js.map +1 -0
- package/dist/api/google-generative-ai.d.ts +13 -0
- package/dist/api/google-generative-ai.d.ts.map +1 -0
- package/dist/api/google-generative-ai.js +417 -0
- package/dist/api/google-generative-ai.js.map +1 -0
- package/dist/api/google-generative-ai.lazy.d.ts +3 -0
- package/dist/api/google-generative-ai.lazy.d.ts.map +1 -0
- package/dist/api/google-generative-ai.lazy.js +3 -0
- package/dist/api/google-generative-ai.lazy.js.map +1 -0
- package/dist/api/google-shared.d.ts +81 -0
- package/dist/api/google-shared.d.ts.map +1 -0
- package/dist/api/google-shared.js +384 -0
- package/dist/api/google-shared.js.map +1 -0
- package/dist/api/google-vertex.d.ts +15 -0
- package/dist/api/google-vertex.d.ts.map +1 -0
- package/dist/api/google-vertex.js +466 -0
- package/dist/api/google-vertex.js.map +1 -0
- package/dist/api/google-vertex.lazy.d.ts +3 -0
- package/dist/api/google-vertex.lazy.d.ts.map +1 -0
- package/dist/api/google-vertex.lazy.js +3 -0
- package/dist/api/google-vertex.lazy.js.map +1 -0
- package/dist/api/lazy.d.ts +19 -0
- package/dist/api/lazy.d.ts.map +1 -0
- package/dist/api/lazy.js +70 -0
- package/dist/api/lazy.js.map +1 -0
- package/dist/api/mistral-conversations.d.ts +25 -0
- package/dist/api/mistral-conversations.d.ts.map +1 -0
- package/dist/api/mistral-conversations.js +736 -0
- package/dist/api/mistral-conversations.js.map +1 -0
- package/dist/api/mistral-conversations.lazy.d.ts +3 -0
- package/dist/api/mistral-conversations.lazy.d.ts.map +1 -0
- package/dist/api/mistral-conversations.lazy.js +3 -0
- package/dist/api/mistral-conversations.lazy.js.map +1 -0
- package/dist/api/openai-codex-responses.d.ts +31 -0
- package/dist/api/openai-codex-responses.d.ts.map +1 -0
- package/dist/api/openai-codex-responses.js +1294 -0
- package/dist/api/openai-codex-responses.js.map +1 -0
- package/dist/api/openai-codex-responses.lazy.d.ts +3 -0
- package/dist/api/openai-codex-responses.lazy.d.ts.map +1 -0
- package/dist/api/openai-codex-responses.lazy.js +3 -0
- package/dist/api/openai-codex-responses.lazy.js.map +1 -0
- package/dist/api/openai-completions.d.ts +22 -0
- package/dist/api/openai-completions.d.ts.map +1 -0
- package/dist/api/openai-completions.js +1279 -0
- package/dist/api/openai-completions.js.map +1 -0
- package/dist/api/openai-completions.lazy.d.ts +3 -0
- package/dist/api/openai-completions.lazy.d.ts.map +1 -0
- package/dist/api/openai-completions.lazy.js +3 -0
- package/dist/api/openai-completions.lazy.js.map +1 -0
- package/dist/api/openai-prompt-cache.d.ts +3 -0
- package/dist/api/openai-prompt-cache.d.ts.map +1 -0
- package/dist/api/openai-prompt-cache.js +10 -0
- package/dist/api/openai-prompt-cache.js.map +1 -0
- package/dist/api/openai-responses-shared.d.ts +26 -0
- package/dist/api/openai-responses-shared.d.ts.map +1 -0
- package/dist/api/openai-responses-shared.js +686 -0
- package/dist/api/openai-responses-shared.js.map +1 -0
- package/dist/api/openai-responses.d.ts +14 -0
- package/dist/api/openai-responses.d.ts.map +1 -0
- package/dist/api/openai-responses.js +283 -0
- package/dist/api/openai-responses.js.map +1 -0
- package/dist/api/openai-responses.lazy.d.ts +3 -0
- package/dist/api/openai-responses.lazy.d.ts.map +1 -0
- package/dist/api/openai-responses.lazy.js +3 -0
- package/dist/api/openai-responses.lazy.js.map +1 -0
- package/dist/api/openrouter-images.d.ts +3 -0
- package/dist/api/openrouter-images.d.ts.map +1 -0
- package/dist/api/openrouter-images.js +132 -0
- package/dist/api/openrouter-images.js.map +1 -0
- package/dist/api/openrouter-images.lazy.d.ts +3 -0
- package/dist/api/openrouter-images.lazy.d.ts.map +1 -0
- package/dist/api/openrouter-images.lazy.js +4 -0
- package/dist/api/openrouter-images.lazy.js.map +1 -0
- package/dist/api/pi-messages.d.ts +97 -0
- package/dist/api/pi-messages.d.ts.map +1 -0
- package/dist/api/pi-messages.js +307 -0
- package/dist/api/pi-messages.js.map +1 -0
- package/dist/api/pi-messages.lazy.d.ts +3 -0
- package/dist/api/pi-messages.lazy.d.ts.map +1 -0
- package/dist/api/pi-messages.lazy.js +3 -0
- package/dist/api/pi-messages.lazy.js.map +1 -0
- package/dist/api/simple-options.d.ts +11 -0
- package/dist/api/simple-options.d.ts.map +1 -0
- package/dist/api/simple-options.js +59 -0
- package/dist/api/simple-options.js.map +1 -0
- package/dist/api/transform-messages.d.ts +8 -0
- package/dist/api/transform-messages.d.ts.map +1 -0
- package/dist/api/transform-messages.js +187 -0
- package/dist/api/transform-messages.js.map +1 -0
- package/dist/auth/context.d.ts +7 -0
- package/dist/auth/context.d.ts.map +1 -0
- package/dist/auth/context.js +42 -0
- package/dist/auth/context.js.map +1 -0
- package/dist/auth/credential-store.d.ts +17 -0
- package/dist/auth/credential-store.d.ts.map +1 -0
- package/dist/auth/credential-store.js +51 -0
- package/dist/auth/credential-store.js.map +1 -0
- package/dist/auth/helpers.d.ts +22 -0
- package/dist/auth/helpers.d.ts.map +1 -0
- package/dist/auth/helpers.js +53 -0
- package/dist/auth/helpers.js.map +1 -0
- package/dist/auth/oauth/anthropic.d.ts +9 -0
- package/dist/auth/oauth/anthropic.d.ts.map +1 -0
- package/dist/auth/oauth/anthropic.js +308 -0
- package/dist/auth/oauth/anthropic.js.map +1 -0
- package/dist/auth/oauth/device-code.d.ts +23 -0
- package/dist/auth/oauth/device-code.d.ts.map +1 -0
- package/dist/auth/oauth/device-code.js +69 -0
- package/dist/auth/oauth/device-code.js.map +1 -0
- package/dist/auth/oauth/github-copilot.d.ts +6 -0
- package/dist/auth/oauth/github-copilot.d.ts.map +1 -0
- package/dist/auth/oauth/github-copilot.js +328 -0
- package/dist/auth/oauth/github-copilot.js.map +1 -0
- package/dist/auth/oauth/kimi-coding.d.ts +10 -0
- package/dist/auth/oauth/kimi-coding.d.ts.map +1 -0
- package/dist/auth/oauth/kimi-coding.js +261 -0
- package/dist/auth/oauth/kimi-coding.js.map +1 -0
- package/dist/auth/oauth/load.d.ts +27 -0
- package/dist/auth/oauth/load.d.ts.map +1 -0
- package/dist/auth/oauth/load.js +59 -0
- package/dist/auth/oauth/load.js.map +1 -0
- package/dist/auth/oauth/oauth-page.d.ts +3 -0
- package/dist/auth/oauth/oauth-page.d.ts.map +1 -0
- package/dist/auth/oauth/oauth-page.js +105 -0
- package/dist/auth/oauth/oauth-page.js.map +1 -0
- package/dist/auth/oauth/openai-codex.d.ts +9 -0
- package/dist/auth/oauth/openai-codex.d.ts.map +1 -0
- package/dist/auth/oauth/openai-codex.js +450 -0
- package/dist/auth/oauth/openai-codex.js.map +1 -0
- package/dist/auth/oauth/openrouter.d.ts +15 -0
- package/dist/auth/oauth/openrouter.d.ts.map +1 -0
- package/dist/auth/oauth/openrouter.js +277 -0
- package/dist/auth/oauth/openrouter.js.map +1 -0
- package/dist/auth/oauth/pkce.d.ts +13 -0
- package/dist/auth/oauth/pkce.d.ts.map +1 -0
- package/dist/auth/oauth/pkce.js +31 -0
- package/dist/auth/oauth/pkce.js.map +1 -0
- package/dist/auth/oauth/radius.d.ts +17 -0
- package/dist/auth/oauth/radius.d.ts.map +1 -0
- package/dist/auth/oauth/radius.js +321 -0
- package/dist/auth/oauth/radius.js.map +1 -0
- package/dist/auth/oauth/xai.d.ts +6 -0
- package/dist/auth/oauth/xai.d.ts.map +1 -0
- package/dist/auth/oauth/xai.js +190 -0
- package/dist/auth/oauth/xai.js.map +1 -0
- package/dist/auth/resolve.d.ts +27 -0
- package/dist/auth/resolve.d.ts.map +1 -0
- package/dist/auth/resolve.js +132 -0
- package/dist/auth/resolve.js.map +1 -0
- package/dist/auth/types.d.ts +231 -0
- package/dist/auth/types.d.ts.map +1 -0
- package/dist/auth/types.js +2 -0
- package/dist/auth/types.js.map +1 -0
- package/dist/bedrock-provider.d.ts +5 -0
- package/dist/bedrock-provider.d.ts.map +1 -0
- package/dist/bedrock-provider.js +6 -0
- package/dist/bedrock-provider.js.map +1 -0
- package/dist/bun-oauth.d.ts +3 -0
- package/dist/bun-oauth.d.ts.map +1 -0
- package/dist/bun-oauth.js +21 -0
- package/dist/bun-oauth.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +113 -0
- package/dist/cli.js.map +1 -0
- package/dist/compat/extension-oauth-types.d.ts +39 -0
- package/dist/compat/extension-oauth-types.d.ts.map +1 -0
- package/dist/compat/extension-oauth-types.js +2 -0
- package/dist/compat/extension-oauth-types.js.map +1 -0
- package/dist/compat.d.ts +67 -0
- package/dist/compat.d.ts.map +1 -0
- package/dist/compat.js +199 -0
- package/dist/compat.js.map +1 -0
- package/dist/env-api-keys.d.ts +21 -0
- package/dist/env-api-keys.d.ts.map +1 -0
- package/dist/env-api-keys.js +156 -0
- package/dist/env-api-keys.js.map +1 -0
- package/dist/image-models.d.ts +10 -0
- package/dist/image-models.d.ts.map +1 -0
- package/dist/image-models.generated.d.ts +680 -0
- package/dist/image-models.generated.d.ts.map +1 -0
- package/dist/image-models.generated.js +682 -0
- package/dist/image-models.generated.js.map +1 -0
- package/dist/image-models.js +23 -0
- package/dist/image-models.js.map +1 -0
- package/dist/images-api-registry.d.ts +14 -0
- package/dist/images-api-registry.d.ts.map +1 -0
- package/dist/images-api-registry.js +22 -0
- package/dist/images-api-registry.js.map +1 -0
- package/dist/images-models.d.ts +95 -0
- package/dist/images-models.d.ts.map +1 -0
- package/dist/images-models.js +143 -0
- package/dist/images-models.js.map +1 -0
- package/dist/images.d.ts +4 -0
- package/dist/images.d.ts.map +1 -0
- package/dist/images.js +14 -0
- package/dist/images.js.map +1 -0
- package/dist/index.d.ts +35 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +22 -0
- package/dist/index.js.map +1 -0
- package/dist/legacy-api-aliases.d.ts +42 -0
- package/dist/legacy-api-aliases.d.ts.map +1 -0
- package/dist/legacy-api-aliases.js +49 -0
- package/dist/legacy-api-aliases.js.map +1 -0
- package/dist/model-catalog.d.ts +17 -0
- package/dist/model-catalog.d.ts.map +1 -0
- package/dist/model-catalog.js +4 -0
- package/dist/model-catalog.js.map +1 -0
- package/dist/models-store.d.ts +29 -0
- package/dist/models-store.d.ts.map +1 -0
- package/dist/models-store.js +17 -0
- package/dist/models-store.js.map +1 -0
- package/dist/models.d.ts +200 -0
- package/dist/models.d.ts.map +1 -0
- package/dist/models.generated.d.ts +81 -0
- package/dist/models.generated.d.ts.map +1 -0
- package/dist/models.generated.js +83 -0
- package/dist/models.generated.js.map +1 -0
- package/dist/models.js +588 -0
- package/dist/models.js.map +1 -0
- package/dist/oauth.d.ts +3 -0
- package/dist/oauth.d.ts.map +1 -0
- package/dist/oauth.js +2 -0
- package/dist/oauth.js.map +1 -0
- package/dist/providers/all.d.ts +28 -0
- package/dist/providers/all.d.ts.map +1 -0
- package/dist/providers/all.js +131 -0
- package/dist/providers/all.js.map +1 -0
- package/dist/providers/amazon-bedrock.d.ts +3 -0
- package/dist/providers/amazon-bedrock.d.ts.map +1 -0
- package/dist/providers/amazon-bedrock.js +93 -0
- package/dist/providers/amazon-bedrock.js.map +1 -0
- package/dist/providers/amazon-bedrock.models.d.ts +4 -0
- package/dist/providers/amazon-bedrock.models.d.ts.map +1 -0
- package/dist/providers/amazon-bedrock.models.js +6 -0
- package/dist/providers/amazon-bedrock.models.js.map +1 -0
- package/dist/providers/ant-ling.d.ts +3 -0
- package/dist/providers/ant-ling.d.ts.map +1 -0
- package/dist/providers/ant-ling.js +15 -0
- package/dist/providers/ant-ling.js.map +1 -0
- package/dist/providers/ant-ling.models.d.ts +4 -0
- package/dist/providers/ant-ling.models.d.ts.map +1 -0
- package/dist/providers/ant-ling.models.js +6 -0
- package/dist/providers/ant-ling.models.js.map +1 -0
- package/dist/providers/anthropic.d.ts +3 -0
- package/dist/providers/anthropic.d.ts.map +1 -0
- package/dist/providers/anthropic.js +56 -0
- package/dist/providers/anthropic.js.map +1 -0
- package/dist/providers/anthropic.models.d.ts +4 -0
- package/dist/providers/anthropic.models.d.ts.map +1 -0
- package/dist/providers/anthropic.models.js +6 -0
- package/dist/providers/anthropic.models.js.map +1 -0
- package/dist/providers/azure-openai-responses.d.ts +3 -0
- package/dist/providers/azure-openai-responses.d.ts.map +1 -0
- package/dist/providers/azure-openai-responses.js +14 -0
- package/dist/providers/azure-openai-responses.js.map +1 -0
- package/dist/providers/azure-openai-responses.models.d.ts +4 -0
- package/dist/providers/azure-openai-responses.models.d.ts.map +1 -0
- package/dist/providers/azure-openai-responses.models.js +6 -0
- package/dist/providers/azure-openai-responses.models.js.map +1 -0
- package/dist/providers/baseten.d.ts +3 -0
- package/dist/providers/baseten.d.ts.map +1 -0
- package/dist/providers/baseten.js +15 -0
- package/dist/providers/baseten.js.map +1 -0
- package/dist/providers/baseten.models.d.ts +4 -0
- package/dist/providers/baseten.models.d.ts.map +1 -0
- package/dist/providers/baseten.models.js +6 -0
- package/dist/providers/baseten.models.js.map +1 -0
- package/dist/providers/cerebras.d.ts +3 -0
- package/dist/providers/cerebras.d.ts.map +1 -0
- package/dist/providers/cerebras.js +15 -0
- package/dist/providers/cerebras.js.map +1 -0
- package/dist/providers/cerebras.models.d.ts +4 -0
- package/dist/providers/cerebras.models.d.ts.map +1 -0
- package/dist/providers/cerebras.models.js +6 -0
- package/dist/providers/cerebras.models.js.map +1 -0
- package/dist/providers/cloudflare-ai-gateway.d.ts +3 -0
- package/dist/providers/cloudflare-ai-gateway.d.ts.map +1 -0
- package/dist/providers/cloudflare-ai-gateway.js +21 -0
- package/dist/providers/cloudflare-ai-gateway.js.map +1 -0
- package/dist/providers/cloudflare-ai-gateway.models.d.ts +4 -0
- package/dist/providers/cloudflare-ai-gateway.models.d.ts.map +1 -0
- package/dist/providers/cloudflare-ai-gateway.models.js +6 -0
- package/dist/providers/cloudflare-ai-gateway.models.js.map +1 -0
- package/dist/providers/cloudflare-auth.d.ts +4 -0
- package/dist/providers/cloudflare-auth.d.ts.map +1 -0
- package/dist/providers/cloudflare-auth.js +86 -0
- package/dist/providers/cloudflare-auth.js.map +1 -0
- package/dist/providers/cloudflare-stream.d.ts +8 -0
- package/dist/providers/cloudflare-stream.d.ts.map +1 -0
- package/dist/providers/cloudflare-stream.js +21 -0
- package/dist/providers/cloudflare-stream.js.map +1 -0
- package/dist/providers/cloudflare-workers-ai.d.ts +3 -0
- package/dist/providers/cloudflare-workers-ai.d.ts.map +1 -0
- package/dist/providers/cloudflare-workers-ai.js +15 -0
- package/dist/providers/cloudflare-workers-ai.js.map +1 -0
- package/dist/providers/cloudflare-workers-ai.models.d.ts +4 -0
- package/dist/providers/cloudflare-workers-ai.models.d.ts.map +1 -0
- package/dist/providers/cloudflare-workers-ai.models.js +6 -0
- package/dist/providers/cloudflare-workers-ai.models.js.map +1 -0
- package/dist/providers/data/.manifest.json +1 -0
- package/dist/providers/data/amazon-bedrock.json +1 -0
- package/dist/providers/data/ant-ling.json +1 -0
- package/dist/providers/data/anthropic.json +1 -0
- package/dist/providers/data/azure-openai-responses.json +1 -0
- package/dist/providers/data/baseten.json +1 -0
- package/dist/providers/data/cerebras.json +1 -0
- package/dist/providers/data/cloudflare-ai-gateway.json +1 -0
- package/dist/providers/data/cloudflare-workers-ai.json +1 -0
- package/dist/providers/data/deepseek.json +1 -0
- package/dist/providers/data/fireworks.json +1 -0
- package/dist/providers/data/github-copilot.json +1 -0
- package/dist/providers/data/google-vertex.json +1 -0
- package/dist/providers/data/google.json +1 -0
- package/dist/providers/data/groq.json +1 -0
- package/dist/providers/data/huggingface.json +1 -0
- package/dist/providers/data/kimi-coding.json +1 -0
- package/dist/providers/data/minimax-cn.json +1 -0
- package/dist/providers/data/minimax.json +1 -0
- package/dist/providers/data/mistral.json +1 -0
- package/dist/providers/data/moonshotai-cn.json +1 -0
- package/dist/providers/data/moonshotai.json +1 -0
- package/dist/providers/data/nvidia.json +1 -0
- package/dist/providers/data/openai-codex.json +1 -0
- package/dist/providers/data/openai.json +1 -0
- package/dist/providers/data/opencode-go.json +1 -0
- package/dist/providers/data/opencode.json +1 -0
- package/dist/providers/data/openrouter.json +1 -0
- package/dist/providers/data/qwen-token-plan-cn.json +1 -0
- package/dist/providers/data/qwen-token-plan-individual.json +1 -0
- package/dist/providers/data/qwen-token-plan.json +1 -0
- package/dist/providers/data/together.json +1 -0
- package/dist/providers/data/vercel-ai-gateway.json +1 -0
- package/dist/providers/data/xai.json +1 -0
- package/dist/providers/data/xiaomi-token-plan-ams.json +1 -0
- package/dist/providers/data/xiaomi-token-plan-cn.json +1 -0
- package/dist/providers/data/xiaomi-token-plan-sgp.json +1 -0
- package/dist/providers/data/xiaomi.json +1 -0
- package/dist/providers/data/zai-coding-cn.json +1 -0
- package/dist/providers/data/zai.json +1 -0
- package/dist/providers/deepseek.d.ts +3 -0
- package/dist/providers/deepseek.d.ts.map +1 -0
- package/dist/providers/deepseek.js +15 -0
- package/dist/providers/deepseek.js.map +1 -0
- package/dist/providers/deepseek.models.d.ts +4 -0
- package/dist/providers/deepseek.models.d.ts.map +1 -0
- package/dist/providers/deepseek.models.js +6 -0
- package/dist/providers/deepseek.models.js.map +1 -0
- package/dist/providers/faux.d.ts +102 -0
- package/dist/providers/faux.d.ts.map +1 -0
- package/dist/providers/faux.js +488 -0
- package/dist/providers/faux.js.map +1 -0
- package/dist/providers/fireworks.d.ts +3 -0
- package/dist/providers/fireworks.d.ts.map +1 -0
- package/dist/providers/fireworks.js +19 -0
- package/dist/providers/fireworks.js.map +1 -0
- package/dist/providers/fireworks.models.d.ts +4 -0
- package/dist/providers/fireworks.models.d.ts.map +1 -0
- package/dist/providers/fireworks.models.js +6 -0
- package/dist/providers/fireworks.models.js.map +1 -0
- package/dist/providers/github-copilot.d.ts +3 -0
- package/dist/providers/github-copilot.d.ts.map +1 -0
- package/dist/providers/github-copilot.js +35 -0
- package/dist/providers/github-copilot.js.map +1 -0
- package/dist/providers/github-copilot.models.d.ts +4 -0
- package/dist/providers/github-copilot.models.d.ts.map +1 -0
- package/dist/providers/github-copilot.models.js +6 -0
- package/dist/providers/github-copilot.models.js.map +1 -0
- package/dist/providers/google-vertex.d.ts +3 -0
- package/dist/providers/google-vertex.d.ts.map +1 -0
- package/dist/providers/google-vertex.js +94 -0
- package/dist/providers/google-vertex.js.map +1 -0
- package/dist/providers/google-vertex.models.d.ts +4 -0
- package/dist/providers/google-vertex.models.d.ts.map +1 -0
- package/dist/providers/google-vertex.models.js +6 -0
- package/dist/providers/google-vertex.models.js.map +1 -0
- package/dist/providers/google.d.ts +3 -0
- package/dist/providers/google.d.ts.map +1 -0
- package/dist/providers/google.js +15 -0
- package/dist/providers/google.js.map +1 -0
- package/dist/providers/google.models.d.ts +4 -0
- package/dist/providers/google.models.d.ts.map +1 -0
- package/dist/providers/google.models.js +6 -0
- package/dist/providers/google.models.js.map +1 -0
- package/dist/providers/groq.d.ts +3 -0
- package/dist/providers/groq.d.ts.map +1 -0
- package/dist/providers/groq.js +15 -0
- package/dist/providers/groq.js.map +1 -0
- package/dist/providers/groq.models.d.ts +4 -0
- package/dist/providers/groq.models.d.ts.map +1 -0
- package/dist/providers/groq.models.js +6 -0
- package/dist/providers/groq.models.js.map +1 -0
- package/dist/providers/huggingface.d.ts +3 -0
- package/dist/providers/huggingface.d.ts.map +1 -0
- package/dist/providers/huggingface.js +15 -0
- package/dist/providers/huggingface.js.map +1 -0
- package/dist/providers/huggingface.models.d.ts +4 -0
- package/dist/providers/huggingface.models.d.ts.map +1 -0
- package/dist/providers/huggingface.models.js +6 -0
- package/dist/providers/huggingface.models.js.map +1 -0
- package/dist/providers/images/register-builtins.d.ts +4 -0
- package/dist/providers/images/register-builtins.d.ts.map +1 -0
- package/dist/providers/images/register-builtins.js +34 -0
- package/dist/providers/images/register-builtins.js.map +1 -0
- package/dist/providers/kimi-coding.d.ts +3 -0
- package/dist/providers/kimi-coding.d.ts.map +1 -0
- package/dist/providers/kimi-coding.js +24 -0
- package/dist/providers/kimi-coding.js.map +1 -0
- package/dist/providers/kimi-coding.models.d.ts +4 -0
- package/dist/providers/kimi-coding.models.d.ts.map +1 -0
- package/dist/providers/kimi-coding.models.js +6 -0
- package/dist/providers/kimi-coding.models.js.map +1 -0
- package/dist/providers/minimax-cn.d.ts +3 -0
- package/dist/providers/minimax-cn.d.ts.map +1 -0
- package/dist/providers/minimax-cn.js +15 -0
- package/dist/providers/minimax-cn.js.map +1 -0
- package/dist/providers/minimax-cn.models.d.ts +4 -0
- package/dist/providers/minimax-cn.models.d.ts.map +1 -0
- package/dist/providers/minimax-cn.models.js +6 -0
- package/dist/providers/minimax-cn.models.js.map +1 -0
- package/dist/providers/minimax.d.ts +3 -0
- package/dist/providers/minimax.d.ts.map +1 -0
- package/dist/providers/minimax.js +15 -0
- package/dist/providers/minimax.js.map +1 -0
- package/dist/providers/minimax.models.d.ts +4 -0
- package/dist/providers/minimax.models.d.ts.map +1 -0
- package/dist/providers/minimax.models.js +6 -0
- package/dist/providers/minimax.models.js.map +1 -0
- package/dist/providers/mistral.d.ts +3 -0
- package/dist/providers/mistral.d.ts.map +1 -0
- package/dist/providers/mistral.js +15 -0
- package/dist/providers/mistral.js.map +1 -0
- package/dist/providers/mistral.models.d.ts +4 -0
- package/dist/providers/mistral.models.d.ts.map +1 -0
- package/dist/providers/mistral.models.js +6 -0
- package/dist/providers/mistral.models.js.map +1 -0
- package/dist/providers/moonshotai-cn.d.ts +3 -0
- package/dist/providers/moonshotai-cn.d.ts.map +1 -0
- package/dist/providers/moonshotai-cn.js +15 -0
- package/dist/providers/moonshotai-cn.js.map +1 -0
- package/dist/providers/moonshotai-cn.models.d.ts +4 -0
- package/dist/providers/moonshotai-cn.models.d.ts.map +1 -0
- package/dist/providers/moonshotai-cn.models.js +6 -0
- package/dist/providers/moonshotai-cn.models.js.map +1 -0
- package/dist/providers/moonshotai.d.ts +3 -0
- package/dist/providers/moonshotai.d.ts.map +1 -0
- package/dist/providers/moonshotai.js +15 -0
- package/dist/providers/moonshotai.js.map +1 -0
- package/dist/providers/moonshotai.models.d.ts +4 -0
- package/dist/providers/moonshotai.models.d.ts.map +1 -0
- package/dist/providers/moonshotai.models.js +6 -0
- package/dist/providers/moonshotai.models.js.map +1 -0
- package/dist/providers/nvidia.d.ts +3 -0
- package/dist/providers/nvidia.d.ts.map +1 -0
- package/dist/providers/nvidia.js +15 -0
- package/dist/providers/nvidia.js.map +1 -0
- package/dist/providers/nvidia.models.d.ts +4 -0
- package/dist/providers/nvidia.models.d.ts.map +1 -0
- package/dist/providers/nvidia.models.js +6 -0
- package/dist/providers/nvidia.models.js.map +1 -0
- package/dist/providers/openai-codex.d.ts +3 -0
- package/dist/providers/openai-codex.d.ts.map +1 -0
- package/dist/providers/openai-codex.js +22 -0
- package/dist/providers/openai-codex.js.map +1 -0
- package/dist/providers/openai-codex.models.d.ts +4 -0
- package/dist/providers/openai-codex.models.d.ts.map +1 -0
- package/dist/providers/openai-codex.models.js +6 -0
- package/dist/providers/openai-codex.models.js.map +1 -0
- package/dist/providers/openai.d.ts +3 -0
- package/dist/providers/openai.d.ts.map +1 -0
- package/dist/providers/openai.js +15 -0
- package/dist/providers/openai.js.map +1 -0
- package/dist/providers/openai.models.d.ts +4 -0
- package/dist/providers/openai.models.d.ts.map +1 -0
- package/dist/providers/openai.models.js +6 -0
- package/dist/providers/openai.models.js.map +1 -0
- package/dist/providers/opencode-go.d.ts +3 -0
- package/dist/providers/opencode-go.d.ts.map +1 -0
- package/dist/providers/opencode-go.js +20 -0
- package/dist/providers/opencode-go.js.map +1 -0
- package/dist/providers/opencode-go.models.d.ts +4 -0
- package/dist/providers/opencode-go.models.d.ts.map +1 -0
- package/dist/providers/opencode-go.models.js +6 -0
- package/dist/providers/opencode-go.models.js.map +1 -0
- package/dist/providers/opencode.d.ts +3 -0
- package/dist/providers/opencode.d.ts.map +1 -0
- package/dist/providers/opencode.js +22 -0
- package/dist/providers/opencode.js.map +1 -0
- package/dist/providers/opencode.models.d.ts +4 -0
- package/dist/providers/opencode.models.d.ts.map +1 -0
- package/dist/providers/opencode.models.js +6 -0
- package/dist/providers/opencode.models.js.map +1 -0
- package/dist/providers/openrouter-images.d.ts +3 -0
- package/dist/providers/openrouter-images.d.ts.map +1 -0
- package/dist/providers/openrouter-images.js +22 -0
- package/dist/providers/openrouter-images.js.map +1 -0
- package/dist/providers/openrouter.d.ts +3 -0
- package/dist/providers/openrouter.d.ts.map +1 -0
- package/dist/providers/openrouter.js +23 -0
- package/dist/providers/openrouter.js.map +1 -0
- package/dist/providers/openrouter.models.d.ts +4 -0
- package/dist/providers/openrouter.models.d.ts.map +1 -0
- package/dist/providers/openrouter.models.js +6 -0
- package/dist/providers/openrouter.models.js.map +1 -0
- package/dist/providers/qwen-token-plan-cn.d.ts +3 -0
- package/dist/providers/qwen-token-plan-cn.d.ts.map +1 -0
- package/dist/providers/qwen-token-plan-cn.js +15 -0
- package/dist/providers/qwen-token-plan-cn.js.map +1 -0
- package/dist/providers/qwen-token-plan-cn.models.d.ts +4 -0
- package/dist/providers/qwen-token-plan-cn.models.d.ts.map +1 -0
- package/dist/providers/qwen-token-plan-cn.models.js +6 -0
- package/dist/providers/qwen-token-plan-cn.models.js.map +1 -0
- package/dist/providers/qwen-token-plan-individual.d.ts +3 -0
- package/dist/providers/qwen-token-plan-individual.d.ts.map +1 -0
- package/dist/providers/qwen-token-plan-individual.js +15 -0
- package/dist/providers/qwen-token-plan-individual.js.map +1 -0
- package/dist/providers/qwen-token-plan-individual.models.d.ts +4 -0
- package/dist/providers/qwen-token-plan-individual.models.d.ts.map +1 -0
- package/dist/providers/qwen-token-plan-individual.models.js +6 -0
- package/dist/providers/qwen-token-plan-individual.models.js.map +1 -0
- package/dist/providers/qwen-token-plan.d.ts +3 -0
- package/dist/providers/qwen-token-plan.d.ts.map +1 -0
- package/dist/providers/qwen-token-plan.js +15 -0
- package/dist/providers/qwen-token-plan.js.map +1 -0
- package/dist/providers/qwen-token-plan.models.d.ts +4 -0
- package/dist/providers/qwen-token-plan.models.d.ts.map +1 -0
- package/dist/providers/qwen-token-plan.models.js +6 -0
- package/dist/providers/qwen-token-plan.models.js.map +1 -0
- package/dist/providers/radius-config.d.ts +26 -0
- package/dist/providers/radius-config.d.ts.map +1 -0
- package/dist/providers/radius-config.js +63 -0
- package/dist/providers/radius-config.js.map +1 -0
- package/dist/providers/radius.d.ts +9 -0
- package/dist/providers/radius.d.ts.map +1 -0
- package/dist/providers/radius.js +64 -0
- package/dist/providers/radius.js.map +1 -0
- package/dist/providers/together.d.ts +3 -0
- package/dist/providers/together.d.ts.map +1 -0
- package/dist/providers/together.js +15 -0
- package/dist/providers/together.js.map +1 -0
- package/dist/providers/together.models.d.ts +4 -0
- package/dist/providers/together.models.d.ts.map +1 -0
- package/dist/providers/together.models.js +6 -0
- package/dist/providers/together.models.js.map +1 -0
- package/dist/providers/vercel-ai-gateway.d.ts +3 -0
- package/dist/providers/vercel-ai-gateway.d.ts.map +1 -0
- package/dist/providers/vercel-ai-gateway.js +15 -0
- package/dist/providers/vercel-ai-gateway.js.map +1 -0
- package/dist/providers/vercel-ai-gateway.models.d.ts +4 -0
- package/dist/providers/vercel-ai-gateway.models.d.ts.map +1 -0
- package/dist/providers/vercel-ai-gateway.models.js +6 -0
- package/dist/providers/vercel-ai-gateway.models.js.map +1 -0
- package/dist/providers/xai.d.ts +3 -0
- package/dist/providers/xai.d.ts.map +1 -0
- package/dist/providers/xai.js +28 -0
- package/dist/providers/xai.js.map +1 -0
- package/dist/providers/xai.models.d.ts +4 -0
- package/dist/providers/xai.models.d.ts.map +1 -0
- package/dist/providers/xai.models.js +6 -0
- package/dist/providers/xai.models.js.map +1 -0
- package/dist/providers/xiaomi-token-plan-ams.d.ts +3 -0
- package/dist/providers/xiaomi-token-plan-ams.d.ts.map +1 -0
- package/dist/providers/xiaomi-token-plan-ams.js +15 -0
- package/dist/providers/xiaomi-token-plan-ams.js.map +1 -0
- package/dist/providers/xiaomi-token-plan-ams.models.d.ts +4 -0
- package/dist/providers/xiaomi-token-plan-ams.models.d.ts.map +1 -0
- package/dist/providers/xiaomi-token-plan-ams.models.js +6 -0
- package/dist/providers/xiaomi-token-plan-ams.models.js.map +1 -0
- package/dist/providers/xiaomi-token-plan-cn.d.ts +3 -0
- package/dist/providers/xiaomi-token-plan-cn.d.ts.map +1 -0
- package/dist/providers/xiaomi-token-plan-cn.js +15 -0
- package/dist/providers/xiaomi-token-plan-cn.js.map +1 -0
- package/dist/providers/xiaomi-token-plan-cn.models.d.ts +4 -0
- package/dist/providers/xiaomi-token-plan-cn.models.d.ts.map +1 -0
- package/dist/providers/xiaomi-token-plan-cn.models.js +6 -0
- package/dist/providers/xiaomi-token-plan-cn.models.js.map +1 -0
- package/dist/providers/xiaomi-token-plan-sgp.d.ts +3 -0
- package/dist/providers/xiaomi-token-plan-sgp.d.ts.map +1 -0
- package/dist/providers/xiaomi-token-plan-sgp.js +15 -0
- package/dist/providers/xiaomi-token-plan-sgp.js.map +1 -0
- package/dist/providers/xiaomi-token-plan-sgp.models.d.ts +4 -0
- package/dist/providers/xiaomi-token-plan-sgp.models.d.ts.map +1 -0
- package/dist/providers/xiaomi-token-plan-sgp.models.js +6 -0
- package/dist/providers/xiaomi-token-plan-sgp.models.js.map +1 -0
- package/dist/providers/xiaomi.d.ts +3 -0
- package/dist/providers/xiaomi.d.ts.map +1 -0
- package/dist/providers/xiaomi.js +15 -0
- package/dist/providers/xiaomi.js.map +1 -0
- package/dist/providers/xiaomi.models.d.ts +4 -0
- package/dist/providers/xiaomi.models.d.ts.map +1 -0
- package/dist/providers/xiaomi.models.js +6 -0
- package/dist/providers/xiaomi.models.js.map +1 -0
- package/dist/providers/zai-coding-cn.d.ts +3 -0
- package/dist/providers/zai-coding-cn.d.ts.map +1 -0
- package/dist/providers/zai-coding-cn.js +15 -0
- package/dist/providers/zai-coding-cn.js.map +1 -0
- package/dist/providers/zai-coding-cn.models.d.ts +4 -0
- package/dist/providers/zai-coding-cn.models.d.ts.map +1 -0
- package/dist/providers/zai-coding-cn.models.js +6 -0
- package/dist/providers/zai-coding-cn.models.js.map +1 -0
- package/dist/providers/zai.d.ts +3 -0
- package/dist/providers/zai.d.ts.map +1 -0
- package/dist/providers/zai.js +15 -0
- package/dist/providers/zai.js.map +1 -0
- package/dist/providers/zai.models.d.ts +4 -0
- package/dist/providers/zai.models.d.ts.map +1 -0
- package/dist/providers/zai.models.js +6 -0
- package/dist/providers/zai.models.js.map +1 -0
- package/dist/session-resources.d.ts +4 -0
- package/dist/session-resources.d.ts.map +1 -0
- package/dist/session-resources.js +22 -0
- package/dist/session-resources.js.map +1 -0
- package/dist/types.d.ts +697 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/abort-signals.d.ts +6 -0
- package/dist/utils/abort-signals.d.ts.map +1 -0
- package/dist/utils/abort-signals.js +34 -0
- package/dist/utils/abort-signals.js.map +1 -0
- package/dist/utils/abort.d.ts +8 -0
- package/dist/utils/abort.d.ts.map +1 -0
- package/dist/utils/abort.js +49 -0
- package/dist/utils/abort.js.map +1 -0
- package/dist/utils/deferred-tools.d.ts +9 -0
- package/dist/utils/deferred-tools.d.ts.map +1 -0
- package/dist/utils/deferred-tools.js +36 -0
- package/dist/utils/deferred-tools.js.map +1 -0
- package/dist/utils/diagnostics.d.ts +19 -0
- package/dist/utils/diagnostics.d.ts.map +1 -0
- package/dist/utils/diagnostics.js +25 -0
- package/dist/utils/diagnostics.js.map +1 -0
- package/dist/utils/error-body.d.ts +25 -0
- package/dist/utils/error-body.d.ts.map +1 -0
- package/dist/utils/error-body.js +133 -0
- package/dist/utils/error-body.js.map +1 -0
- package/dist/utils/estimate.d.ts +17 -0
- package/dist/utils/estimate.d.ts.map +1 -0
- package/dist/utils/estimate.js +116 -0
- package/dist/utils/estimate.js.map +1 -0
- package/dist/utils/event-stream.d.ts +21 -0
- package/dist/utils/event-stream.d.ts.map +1 -0
- package/dist/utils/event-stream.js +81 -0
- package/dist/utils/event-stream.js.map +1 -0
- package/dist/utils/hash.d.ts +3 -0
- package/dist/utils/hash.d.ts.map +1 -0
- package/dist/utils/hash.js +14 -0
- package/dist/utils/hash.js.map +1 -0
- package/dist/utils/headers.d.ts +4 -0
- package/dist/utils/headers.d.ts.map +1 -0
- package/dist/utils/headers.js +18 -0
- package/dist/utils/headers.js.map +1 -0
- package/dist/utils/json-parse.d.ts +16 -0
- package/dist/utils/json-parse.d.ts.map +1 -0
- package/dist/utils/json-parse.js +113 -0
- package/dist/utils/json-parse.js.map +1 -0
- package/dist/utils/node-http-proxy.d.ts +4 -0
- package/dist/utils/node-http-proxy.d.ts.map +1 -0
- package/dist/utils/node-http-proxy.js +92 -0
- package/dist/utils/node-http-proxy.js.map +1 -0
- package/dist/utils/overflow.d.ts +68 -0
- package/dist/utils/overflow.d.ts.map +1 -0
- package/dist/utils/overflow.js +172 -0
- package/dist/utils/overflow.js.map +1 -0
- package/dist/utils/pi-user-agent.d.ts +2 -0
- package/dist/utils/pi-user-agent.d.ts.map +1 -0
- package/dist/utils/pi-user-agent.js +12 -0
- package/dist/utils/pi-user-agent.js.map +1 -0
- package/dist/utils/provider-env.d.ts +7 -0
- package/dist/utils/provider-env.d.ts.map +1 -0
- package/dist/utils/provider-env.js +44 -0
- package/dist/utils/provider-env.js.map +1 -0
- package/dist/utils/provider-retry.d.ts +16 -0
- package/dist/utils/provider-retry.d.ts.map +1 -0
- package/dist/utils/provider-retry.js +94 -0
- package/dist/utils/provider-retry.js.map +1 -0
- package/dist/utils/retry.d.ts +53 -0
- package/dist/utils/retry.d.ts.map +1 -0
- package/dist/utils/retry.js +174 -0
- package/dist/utils/retry.js.map +1 -0
- package/dist/utils/sanitize-unicode.d.ts +22 -0
- package/dist/utils/sanitize-unicode.d.ts.map +1 -0
- package/dist/utils/sanitize-unicode.js +26 -0
- package/dist/utils/sanitize-unicode.js.map +1 -0
- package/dist/utils/text.d.ts +6 -0
- package/dist/utils/text.d.ts.map +1 -0
- package/dist/utils/text.js +10 -0
- package/dist/utils/text.js.map +1 -0
- package/dist/utils/typebox-helpers.d.ts +17 -0
- package/dist/utils/typebox-helpers.d.ts.map +1 -0
- package/dist/utils/typebox-helpers.js +21 -0
- package/dist/utils/typebox-helpers.js.map +1 -0
- package/dist/utils/uuid.d.ts +3 -0
- package/dist/utils/uuid.d.ts.map +1 -0
- package/dist/utils/uuid.js +46 -0
- package/dist/utils/uuid.js.map +1 -0
- package/dist/utils/validation.d.ts +18 -0
- package/dist/utils/validation.d.ts.map +1 -0
- package/dist/utils/validation.js +309 -0
- package/dist/utils/validation.js.map +1 -0
- package/package.json +122 -0
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { AnthropicOptions } from "./api/anthropic-messages.ts";
|
|
2
|
+
import type { AzureOpenAIResponsesOptions } from "./api/azure-openai-responses.ts";
|
|
3
|
+
import type { GoogleOptions } from "./api/google-generative-ai.ts";
|
|
4
|
+
import type { GoogleVertexOptions } from "./api/google-vertex.ts";
|
|
5
|
+
import type { MistralOptions } from "./api/mistral-conversations.ts";
|
|
6
|
+
import type { OpenAICodexResponsesOptions } from "./api/openai-codex-responses.ts";
|
|
7
|
+
import type { OpenAICompletionsOptions } from "./api/openai-completions.ts";
|
|
8
|
+
import type { OpenAIResponsesOptions } from "./api/openai-responses.ts";
|
|
9
|
+
import type { SimpleStreamOptions, StreamFunction } from "./types.ts";
|
|
10
|
+
/** @deprecated Use `stream` from `@bastani/pi-ai/api/anthropic-messages` or `anthropicMessagesApi().stream`. */
|
|
11
|
+
export declare const streamAnthropic: StreamFunction<"anthropic-messages", AnthropicOptions>;
|
|
12
|
+
/** @deprecated Use `streamSimple` from `@bastani/pi-ai/api/anthropic-messages` or `anthropicMessagesApi().streamSimple`. */
|
|
13
|
+
export declare const streamSimpleAnthropic: StreamFunction<"anthropic-messages", SimpleStreamOptions>;
|
|
14
|
+
/** @deprecated Use `stream` from `@bastani/pi-ai/api/azure-openai-responses` or `azureOpenAIResponsesApi().stream`. */
|
|
15
|
+
export declare const streamAzureOpenAIResponses: StreamFunction<"azure-openai-responses", AzureOpenAIResponsesOptions>;
|
|
16
|
+
/** @deprecated Use `streamSimple` from `@bastani/pi-ai/api/azure-openai-responses` or `azureOpenAIResponsesApi().streamSimple`. */
|
|
17
|
+
export declare const streamSimpleAzureOpenAIResponses: StreamFunction<"azure-openai-responses", SimpleStreamOptions>;
|
|
18
|
+
/** @deprecated Use `stream` from `@bastani/pi-ai/api/google-generative-ai` or `googleGenerativeAIApi().stream`. */
|
|
19
|
+
export declare const streamGoogle: StreamFunction<"google-generative-ai", GoogleOptions>;
|
|
20
|
+
/** @deprecated Use `streamSimple` from `@bastani/pi-ai/api/google-generative-ai` or `googleGenerativeAIApi().streamSimple`. */
|
|
21
|
+
export declare const streamSimpleGoogle: StreamFunction<"google-generative-ai", SimpleStreamOptions>;
|
|
22
|
+
/** @deprecated Use `stream` from `@bastani/pi-ai/api/google-vertex` or `googleVertexApi().stream`. */
|
|
23
|
+
export declare const streamGoogleVertex: StreamFunction<"google-vertex", GoogleVertexOptions>;
|
|
24
|
+
/** @deprecated Use `streamSimple` from `@bastani/pi-ai/api/google-vertex` or `googleVertexApi().streamSimple`. */
|
|
25
|
+
export declare const streamSimpleGoogleVertex: StreamFunction<"google-vertex", SimpleStreamOptions>;
|
|
26
|
+
/** @deprecated Use `stream` from `@bastani/pi-ai/api/mistral-conversations` or `mistralConversationsApi().stream`. */
|
|
27
|
+
export declare const streamMistral: StreamFunction<"mistral-conversations", MistralOptions>;
|
|
28
|
+
/** @deprecated Use `streamSimple` from `@bastani/pi-ai/api/mistral-conversations` or `mistralConversationsApi().streamSimple`. */
|
|
29
|
+
export declare const streamSimpleMistral: StreamFunction<"mistral-conversations", SimpleStreamOptions>;
|
|
30
|
+
/** @deprecated Use `stream` from `@bastani/pi-ai/api/openai-codex-responses` or `openAICodexResponsesApi().stream`. */
|
|
31
|
+
export declare const streamOpenAICodexResponses: StreamFunction<"openai-codex-responses", OpenAICodexResponsesOptions>;
|
|
32
|
+
/** @deprecated Use `streamSimple` from `@bastani/pi-ai/api/openai-codex-responses` or `openAICodexResponsesApi().streamSimple`. */
|
|
33
|
+
export declare const streamSimpleOpenAICodexResponses: StreamFunction<"openai-codex-responses", SimpleStreamOptions>;
|
|
34
|
+
/** @deprecated Use `stream` from `@bastani/pi-ai/api/openai-completions` or `openAICompletionsApi().stream`. */
|
|
35
|
+
export declare const streamOpenAICompletions: StreamFunction<"openai-completions", OpenAICompletionsOptions>;
|
|
36
|
+
/** @deprecated Use `streamSimple` from `@bastani/pi-ai/api/openai-completions` or `openAICompletionsApi().streamSimple`. */
|
|
37
|
+
export declare const streamSimpleOpenAICompletions: StreamFunction<"openai-completions", SimpleStreamOptions>;
|
|
38
|
+
/** @deprecated Use `stream` from `@bastani/pi-ai/api/openai-responses` or `openAIResponsesApi().stream`. */
|
|
39
|
+
export declare const streamOpenAIResponses: StreamFunction<"openai-responses", OpenAIResponsesOptions>;
|
|
40
|
+
/** @deprecated Use `streamSimple` from `@bastani/pi-ai/api/openai-responses` or `openAIResponsesApi().streamSimple`. */
|
|
41
|
+
export declare const streamSimpleOpenAIResponses: StreamFunction<"openai-responses", SimpleStreamOptions>;
|
|
42
|
+
//# sourceMappingURL=legacy-api-aliases.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"legacy-api-aliases.d.ts","sourceRoot":"","sources":["../src/legacy-api-aliases.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAEpE,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,iCAAiC,CAAC;AAEnF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAEnE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,wBAA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.lazy.ts\";\nimport type { AnthropicOptions } from \"./api/anthropic-messages.ts\";\nimport { azureOpenAIResponsesApi } from \"./api/azure-openai-responses.lazy.ts\";\nimport type { AzureOpenAIResponsesOptions } from \"./api/azure-openai-responses.ts\";\nimport { googleGenerativeAIApi } from \"./api/google-generative-ai.lazy.ts\";\nimport type { GoogleOptions } from \"./api/google-generative-ai.ts\";\nimport { googleVertexApi } from \"./api/google-vertex.lazy.ts\";\nimport type { GoogleVertexOptions } from \"./api/google-vertex.ts\";\nimport { mistralConversationsApi } from \"./api/mistral-conversations.lazy.ts\";\nimport type { MistralOptions } from \"./api/mistral-conversations.ts\";\nimport { openAICodexResponsesApi } from \"./api/openai-codex-responses.lazy.ts\";\nimport type { OpenAICodexResponsesOptions } from \"./api/openai-codex-responses.ts\";\nimport { openAICompletionsApi } from \"./api/openai-completions.lazy.ts\";\nimport type { OpenAICompletionsOptions } from \"./api/openai-completions.ts\";\nimport { openAIResponsesApi } from \"./api/openai-responses.lazy.ts\";\nimport type { OpenAIResponsesOptions } from \"./api/openai-responses.ts\";\nimport type { SimpleStreamOptions, StreamFunction } from \"./types.ts\";\n\nconst anthropicMessagesStreams = anthropicMessagesApi();\nconst azureOpenAIResponsesStreams = azureOpenAIResponsesApi();\nconst googleGenerativeAIStreams = googleGenerativeAIApi();\nconst googleVertexStreams = googleVertexApi();\nconst mistralConversationsStreams = mistralConversationsApi();\nconst openAICodexResponsesStreams = openAICodexResponsesApi();\nconst openAICompletionsStreams = openAICompletionsApi();\nconst openAIResponsesStreams = openAIResponsesApi();\n\n/** @deprecated Use `stream` from `@bastani/pi-ai/api/anthropic-messages` or `anthropicMessagesApi().stream`. */\nexport const streamAnthropic = anthropicMessagesStreams.stream as StreamFunction<\n\t\"anthropic-messages\",\n\tAnthropicOptions\n>;\n/** @deprecated Use `streamSimple` from `@bastani/pi-ai/api/anthropic-messages` or `anthropicMessagesApi().streamSimple`. */\nexport const streamSimpleAnthropic = anthropicMessagesStreams.streamSimple as StreamFunction<\n\t\"anthropic-messages\",\n\tSimpleStreamOptions\n>;\n\n/** @deprecated Use `stream` from `@bastani/pi-ai/api/azure-openai-responses` or `azureOpenAIResponsesApi().stream`. */\nexport const streamAzureOpenAIResponses = azureOpenAIResponsesStreams.stream as StreamFunction<\n\t\"azure-openai-responses\",\n\tAzureOpenAIResponsesOptions\n>;\n/** @deprecated Use `streamSimple` from `@bastani/pi-ai/api/azure-openai-responses` or `azureOpenAIResponsesApi().streamSimple`. */\nexport const streamSimpleAzureOpenAIResponses = azureOpenAIResponsesStreams.streamSimple as StreamFunction<\n\t\"azure-openai-responses\",\n\tSimpleStreamOptions\n>;\n\n/** @deprecated Use `stream` from `@bastani/pi-ai/api/google-generative-ai` or `googleGenerativeAIApi().stream`. */\nexport const streamGoogle = googleGenerativeAIStreams.stream as StreamFunction<\"google-generative-ai\", GoogleOptions>;\n/** @deprecated Use `streamSimple` from `@bastani/pi-ai/api/google-generative-ai` or `googleGenerativeAIApi().streamSimple`. */\nexport const streamSimpleGoogle = googleGenerativeAIStreams.streamSimple as StreamFunction<\n\t\"google-generative-ai\",\n\tSimpleStreamOptions\n>;\n\n/** @deprecated Use `stream` from `@bastani/pi-ai/api/google-vertex` or `googleVertexApi().stream`. */\nexport const streamGoogleVertex = googleVertexStreams.stream as StreamFunction<\"google-vertex\", GoogleVertexOptions>;\n/** @deprecated Use `streamSimple` from `@bastani/pi-ai/api/google-vertex` or `googleVertexApi().streamSimple`. */\nexport const streamSimpleGoogleVertex = googleVertexStreams.streamSimple as StreamFunction<\n\t\"google-vertex\",\n\tSimpleStreamOptions\n>;\n\n/** @deprecated Use `stream` from `@bastani/pi-ai/api/mistral-conversations` or `mistralConversationsApi().stream`. */\nexport const streamMistral = mistralConversationsStreams.stream as StreamFunction<\n\t\"mistral-conversations\",\n\tMistralOptions\n>;\n/** @deprecated Use `streamSimple` from `@bastani/pi-ai/api/mistral-conversations` or `mistralConversationsApi().streamSimple`. */\nexport const streamSimpleMistral = mistralConversationsStreams.streamSimple as StreamFunction<\n\t\"mistral-conversations\",\n\tSimpleStreamOptions\n>;\n\n/** @deprecated Use `stream` from `@bastani/pi-ai/api/openai-codex-responses` or `openAICodexResponsesApi().stream`. */\nexport const streamOpenAICodexResponses = openAICodexResponsesStreams.stream as StreamFunction<\n\t\"openai-codex-responses\",\n\tOpenAICodexResponsesOptions\n>;\n/** @deprecated Use `streamSimple` from `@bastani/pi-ai/api/openai-codex-responses` or `openAICodexResponsesApi().streamSimple`. */\nexport const streamSimpleOpenAICodexResponses = openAICodexResponsesStreams.streamSimple as StreamFunction<\n\t\"openai-codex-responses\",\n\tSimpleStreamOptions\n>;\n\n/** @deprecated Use `stream` from `@bastani/pi-ai/api/openai-completions` or `openAICompletionsApi().stream`. */\nexport const streamOpenAICompletions = openAICompletionsStreams.stream as StreamFunction<\n\t\"openai-completions\",\n\tOpenAICompletionsOptions\n>;\n/** @deprecated Use `streamSimple` from `@bastani/pi-ai/api/openai-completions` or `openAICompletionsApi().streamSimple`. */\nexport const streamSimpleOpenAICompletions = openAICompletionsStreams.streamSimple as StreamFunction<\n\t\"openai-completions\",\n\tSimpleStreamOptions\n>;\n\n/** @deprecated Use `stream` from `@bastani/pi-ai/api/openai-responses` or `openAIResponsesApi().stream`. */\nexport const streamOpenAIResponses = openAIResponsesStreams.stream as StreamFunction<\n\t\"openai-responses\",\n\tOpenAIResponsesOptions\n>;\n/** @deprecated Use `streamSimple` from `@bastani/pi-ai/api/openai-responses` or `openAIResponsesApi().streamSimple`. */\nexport const streamSimpleOpenAIResponses = openAIResponsesStreams.streamSimple as StreamFunction<\n\t\"openai-responses\",\n\tSimpleStreamOptions\n>;\n"]}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { anthropicMessagesApi } from "./api/anthropic-messages.lazy.js";
|
|
2
|
+
import { azureOpenAIResponsesApi } from "./api/azure-openai-responses.lazy.js";
|
|
3
|
+
import { googleGenerativeAIApi } from "./api/google-generative-ai.lazy.js";
|
|
4
|
+
import { googleVertexApi } from "./api/google-vertex.lazy.js";
|
|
5
|
+
import { mistralConversationsApi } from "./api/mistral-conversations.lazy.js";
|
|
6
|
+
import { openAICodexResponsesApi } from "./api/openai-codex-responses.lazy.js";
|
|
7
|
+
import { openAICompletionsApi } from "./api/openai-completions.lazy.js";
|
|
8
|
+
import { openAIResponsesApi } from "./api/openai-responses.lazy.js";
|
|
9
|
+
const anthropicMessagesStreams = anthropicMessagesApi();
|
|
10
|
+
const azureOpenAIResponsesStreams = azureOpenAIResponsesApi();
|
|
11
|
+
const googleGenerativeAIStreams = googleGenerativeAIApi();
|
|
12
|
+
const googleVertexStreams = googleVertexApi();
|
|
13
|
+
const mistralConversationsStreams = mistralConversationsApi();
|
|
14
|
+
const openAICodexResponsesStreams = openAICodexResponsesApi();
|
|
15
|
+
const openAICompletionsStreams = openAICompletionsApi();
|
|
16
|
+
const openAIResponsesStreams = openAIResponsesApi();
|
|
17
|
+
/** @deprecated Use `stream` from `@bastani/pi-ai/api/anthropic-messages` or `anthropicMessagesApi().stream`. */
|
|
18
|
+
export const streamAnthropic = anthropicMessagesStreams.stream;
|
|
19
|
+
/** @deprecated Use `streamSimple` from `@bastani/pi-ai/api/anthropic-messages` or `anthropicMessagesApi().streamSimple`. */
|
|
20
|
+
export const streamSimpleAnthropic = anthropicMessagesStreams.streamSimple;
|
|
21
|
+
/** @deprecated Use `stream` from `@bastani/pi-ai/api/azure-openai-responses` or `azureOpenAIResponsesApi().stream`. */
|
|
22
|
+
export const streamAzureOpenAIResponses = azureOpenAIResponsesStreams.stream;
|
|
23
|
+
/** @deprecated Use `streamSimple` from `@bastani/pi-ai/api/azure-openai-responses` or `azureOpenAIResponsesApi().streamSimple`. */
|
|
24
|
+
export const streamSimpleAzureOpenAIResponses = azureOpenAIResponsesStreams.streamSimple;
|
|
25
|
+
/** @deprecated Use `stream` from `@bastani/pi-ai/api/google-generative-ai` or `googleGenerativeAIApi().stream`. */
|
|
26
|
+
export const streamGoogle = googleGenerativeAIStreams.stream;
|
|
27
|
+
/** @deprecated Use `streamSimple` from `@bastani/pi-ai/api/google-generative-ai` or `googleGenerativeAIApi().streamSimple`. */
|
|
28
|
+
export const streamSimpleGoogle = googleGenerativeAIStreams.streamSimple;
|
|
29
|
+
/** @deprecated Use `stream` from `@bastani/pi-ai/api/google-vertex` or `googleVertexApi().stream`. */
|
|
30
|
+
export const streamGoogleVertex = googleVertexStreams.stream;
|
|
31
|
+
/** @deprecated Use `streamSimple` from `@bastani/pi-ai/api/google-vertex` or `googleVertexApi().streamSimple`. */
|
|
32
|
+
export const streamSimpleGoogleVertex = googleVertexStreams.streamSimple;
|
|
33
|
+
/** @deprecated Use `stream` from `@bastani/pi-ai/api/mistral-conversations` or `mistralConversationsApi().stream`. */
|
|
34
|
+
export const streamMistral = mistralConversationsStreams.stream;
|
|
35
|
+
/** @deprecated Use `streamSimple` from `@bastani/pi-ai/api/mistral-conversations` or `mistralConversationsApi().streamSimple`. */
|
|
36
|
+
export const streamSimpleMistral = mistralConversationsStreams.streamSimple;
|
|
37
|
+
/** @deprecated Use `stream` from `@bastani/pi-ai/api/openai-codex-responses` or `openAICodexResponsesApi().stream`. */
|
|
38
|
+
export const streamOpenAICodexResponses = openAICodexResponsesStreams.stream;
|
|
39
|
+
/** @deprecated Use `streamSimple` from `@bastani/pi-ai/api/openai-codex-responses` or `openAICodexResponsesApi().streamSimple`. */
|
|
40
|
+
export const streamSimpleOpenAICodexResponses = openAICodexResponsesStreams.streamSimple;
|
|
41
|
+
/** @deprecated Use `stream` from `@bastani/pi-ai/api/openai-completions` or `openAICompletionsApi().stream`. */
|
|
42
|
+
export const streamOpenAICompletions = openAICompletionsStreams.stream;
|
|
43
|
+
/** @deprecated Use `streamSimple` from `@bastani/pi-ai/api/openai-completions` or `openAICompletionsApi().streamSimple`. */
|
|
44
|
+
export const streamSimpleOpenAICompletions = openAICompletionsStreams.streamSimple;
|
|
45
|
+
/** @deprecated Use `stream` from `@bastani/pi-ai/api/openai-responses` or `openAIResponsesApi().stream`. */
|
|
46
|
+
export const streamOpenAIResponses = openAIResponsesStreams.stream;
|
|
47
|
+
/** @deprecated Use `streamSimple` from `@bastani/pi-ai/api/openai-responses` or `openAIResponsesApi().streamSimple`. */
|
|
48
|
+
export const streamSimpleOpenAIResponses = openAIResponsesStreams.streamSimple;
|
|
49
|
+
//# sourceMappingURL=legacy-api-aliases.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"legacy-api-aliases.js","sourceRoot":"","sources":["../src/legacy-api-aliases.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AAExE,OAAO,EAAE,uBAAuB,EAAE,MAAM,sCAAsC,CAAC;AAE/E,OAAO,EAAE,qBAAqB,EAAE,MAAM,oCAAoC,CAAC;AAE3E,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAE9D,OAAO,EAAE,uBAAuB,EAAE,MAAM,qCAAqC,CAAC;AAE9E,OAAO,EAAE,uBAAuB,EAAE,MAAM,sCAAsC,CAAC;AAE/E,OAAO,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AAExE,OAAO,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AAIpE,MAAM,wBAAwB,GAAG,oBAAoB,EAAE,CAAC;AACxD,MAAM,2BAA2B,GAAG,uBAAuB,EAAE,CAAC;AAC9D,MAAM,yBAAyB,GAAG,qBAAqB,EAAE,CAAC;AAC1D,MAAM,mBAAmB,GAAG,eAAe,EAAE,CAAC;AAC9C,MAAM,2BAA2B,GAAG,uBAAuB,EAAE,CAAC;AAC9D,MAAM,2BAA2B,GAAG,uBAAuB,EAAE,CAAC;AAC9D,MAAM,wBAAwB,GAAG,oBAAoB,EAAE,CAAC;AACxD,MAAM,sBAAsB,GAAG,kBAAkB,EAAE,CAAC;AAEpD,gHAAgH;AAChH,MAAM,CAAC,MAAM,eAAe,GAAG,wBAAwB,CAAC,MAGvD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i } from \"./api/anthropic-messages.lazy.ts\";\nimport type { AnthropicOptions } from \"./api/anthropic-messages.ts\";\nimport { azureOpenAIResponsesApi } from \"./api/azure-openai-responses.lazy.ts\";\nimport type { AzureOpenAIResponsesOptions } from \"./api/azure-openai-responses.ts\";\nimport { googleGenerativeAIApi } from \"./api/google-generative-ai.lazy.ts\";\nimport type { GoogleOptions } from \"./api/google-generative-ai.ts\";\nimport { googleVertexApi } from \"./api/google-vertex.lazy.ts\";\nimport type { GoogleVertexOptions } from \"./api/google-vertex.ts\";\nimport { mistralConversationsApi } from \"./api/mistral-conversations.lazy.ts\";\nimport type { MistralOptions } from \"./api/mistral-conversations.ts\";\nimport { openAICodexResponsesApi } from \"./api/openai-codex-responses.lazy.ts\";\nimport type { OpenAICodexResponsesOptions } from \"./api/openai-codex-responses.ts\";\nimport { openAICompletionsApi } from \"./api/openai-completions.lazy.ts\";\nimport type { OpenAICompletionsOptions } from \"./api/openai-completions.ts\";\nimport { openAIResponsesApi } from \"./api/openai-responses.lazy.ts\";\nimport type { OpenAIResponsesOptions } from \"./api/openai-responses.ts\";\nimport type { SimpleStreamOptions, StreamFunction } from \"./types.ts\";\n\nconst anthropicMessagesStreams = anthropicMessagesApi();\nconst azureOpenAIResponsesStreams = azureOpenAIResponsesApi();\nconst googleGenerativeAIStreams = googleGenerativeAIApi();\nconst googleVertexStreams = googleVertexApi();\nconst mistralConversationsStreams = mistralConversationsApi();\nconst openAICodexResponsesStreams = openAICodexResponsesApi();\nconst openAICompletionsStreams = openAICompletionsApi();\nconst openAIResponsesStreams = openAIResponsesApi();\n\n/** @deprecated Use `stream` from `@bastani/pi-ai/api/anthropic-messages` or `anthropicMessagesApi().stream`. */\nexport const streamAnthropic = anthropicMessagesStreams.stream as StreamFunction<\n\t\"anthropic-messages\",\n\tAnthropicOptions\n>;\n/** @deprecated Use `streamSimple` from `@bastani/pi-ai/api/anthropic-messages` or `anthropicMessagesApi().streamSimple`. */\nexport const streamSimpleAnthropic = anthropicMessagesStreams.streamSimple as StreamFunction<\n\t\"anthropic-messages\",\n\tSimpleStreamOptions\n>;\n\n/** @deprecated Use `stream` from `@bastani/pi-ai/api/azure-openai-responses` or `azureOpenAIResponsesApi().stream`. */\nexport const streamAzureOpenAIResponses = azureOpenAIResponsesStreams.stream as StreamFunction<\n\t\"azure-openai-responses\",\n\tAzureOpenAIResponsesOptions\n>;\n/** @deprecated Use `streamSimple` from `@bastani/pi-ai/api/azure-openai-responses` or `azureOpenAIResponsesApi().streamSimple`. */\nexport const streamSimpleAzureOpenAIResponses = azureOpenAIResponsesStreams.streamSimple as StreamFunction<\n\t\"azure-openai-responses\",\n\tSimpleStreamOptions\n>;\n\n/** @deprecated Use `stream` from `@bastani/pi-ai/api/google-generative-ai` or `googleGenerativeAIApi().stream`. */\nexport const streamGoogle = googleGenerativeAIStreams.stream as StreamFunction<\"google-generative-ai\", GoogleOptions>;\n/** @deprecated Use `streamSimple` from `@bastani/pi-ai/api/google-generative-ai` or `googleGenerativeAIApi().streamSimple`. */\nexport const streamSimpleGoogle = googleGenerativeAIStreams.streamSimple as StreamFunction<\n\t\"google-generative-ai\",\n\tSimpleStreamOptions\n>;\n\n/** @deprecated Use `stream` from `@bastani/pi-ai/api/google-vertex` or `googleVertexApi().stream`. */\nexport const streamGoogleVertex = googleVertexStreams.stream as StreamFunction<\"google-vertex\", GoogleVertexOptions>;\n/** @deprecated Use `streamSimple` from `@bastani/pi-ai/api/google-vertex` or `googleVertexApi().streamSimple`. */\nexport const streamSimpleGoogleVertex = googleVertexStreams.streamSimple as StreamFunction<\n\t\"google-vertex\",\n\tSimpleStreamOptions\n>;\n\n/** @deprecated Use `stream` from `@bastani/pi-ai/api/mistral-conversations` or `mistralConversationsApi().stream`. */\nexport const streamMistral = mistralConversationsStreams.stream as StreamFunction<\n\t\"mistral-conversations\",\n\tMistralOptions\n>;\n/** @deprecated Use `streamSimple` from `@bastani/pi-ai/api/mistral-conversations` or `mistralConversationsApi().streamSimple`. */\nexport const streamSimpleMistral = mistralConversationsStreams.streamSimple as StreamFunction<\n\t\"mistral-conversations\",\n\tSimpleStreamOptions\n>;\n\n/** @deprecated Use `stream` from `@bastani/pi-ai/api/openai-codex-responses` or `openAICodexResponsesApi().stream`. */\nexport const streamOpenAICodexResponses = openAICodexResponsesStreams.stream as StreamFunction<\n\t\"openai-codex-responses\",\n\tOpenAICodexResponsesOptions\n>;\n/** @deprecated Use `streamSimple` from `@bastani/pi-ai/api/openai-codex-responses` or `openAICodexResponsesApi().streamSimple`. */\nexport const streamSimpleOpenAICodexResponses = openAICodexResponsesStreams.streamSimple as StreamFunction<\n\t\"openai-codex-responses\",\n\tSimpleStreamOptions\n>;\n\n/** @deprecated Use `stream` from `@bastani/pi-ai/api/openai-completions` or `openAICompletionsApi().stream`. */\nexport const streamOpenAICompletions = openAICompletionsStreams.stream as StreamFunction<\n\t\"openai-completions\",\n\tOpenAICompletionsOptions\n>;\n/** @deprecated Use `streamSimple` from `@bastani/pi-ai/api/openai-completions` or `openAICompletionsApi().streamSimple`. */\nexport const streamSimpleOpenAICompletions = openAICompletionsStreams.streamSimple as StreamFunction<\n\t\"openai-completions\",\n\tSimpleStreamOptions\n>;\n\n/** @deprecated Use `stream` from `@bastani/pi-ai/api/openai-responses` or `openAIResponsesApi().stream`. */\nexport const streamOpenAIResponses = openAIResponsesStreams.stream as StreamFunction<\n\t\"openai-responses\",\n\tOpenAIResponsesOptions\n>;\n/** @deprecated Use `streamSimple` from `@bastani/pi-ai/api/openai-responses` or `openAIResponsesApi().streamSimple`. */\nexport const streamSimpleOpenAIResponses = openAIResponsesStreams.streamSimple as StreamFunction<\n\t\"openai-responses\",\n\tSimpleStreamOptions\n>;\n"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Api, Model, ProviderId } from "./types.ts";
|
|
2
|
+
export type ModelGroups = Record<string, Record<string, object>>;
|
|
3
|
+
type ModelId<TGroups extends ModelGroups> = {
|
|
4
|
+
[TApi in keyof TGroups]: keyof TGroups[TApi];
|
|
5
|
+
}[keyof TGroups] & string;
|
|
6
|
+
type ModelApi<TGroups extends ModelGroups, TModelId extends ModelId<TGroups>> = {
|
|
7
|
+
[TApi in keyof TGroups]: TModelId extends keyof TGroups[TApi] ? TApi : never;
|
|
8
|
+
}[keyof TGroups] & Api;
|
|
9
|
+
export type ModelCatalog<TGroups extends ModelGroups, TProvider extends ProviderId> = {
|
|
10
|
+
[TModelId in ModelId<TGroups>]: Model<ModelApi<TGroups, TModelId>> & {
|
|
11
|
+
id: TModelId;
|
|
12
|
+
provider: TProvider;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
export declare function flattenModelCatalog<const TProvider extends ProviderId, const TGroups extends ModelGroups>(_provider: TProvider, groups: TGroups): ModelCatalog<TGroups, TProvider>;
|
|
16
|
+
export {};
|
|
17
|
+
//# sourceMappingURL=model-catalog.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model-catalog.d.ts","sourceRoot":"","sources":["../src/model-catalog.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAEzD,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;AAEjE,KAAK,OAAO,CAAC,OAAO,SAAS,WAAW,IAAI;KAC1C,IAAI,IAAI,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC;CAC5C,CAAC,MAAM,OAAO,CAAC,GACf,MAAM,CAAC;AAER,KAAK,QAAQ,CAAC,OAAO,SAAS,WAAW,EAAE,QAAQ,SAAS,OAAO,CAAC,OAAO,CAAC,IAAI;KAC9E,IAAI,IAAI,MAAM,OAAO,GAAG,QAAQ,SAAS,MAAM,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,GAAG,KAAK;CAC5E,CAAC,MAAM,OAAO,CAAC,GACf,GAAG,CAAC;AAEL,MAAM,MAAM,YAAY,CAAC,OAAO,SAAS,WAAW,EAAE,SAAS,SAAS,UAAU,IAAI;KACpF,QAAQ,IAAI,OAAO,CAAC,OAAO,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC,GAAG;QACpE,EAAE,EAAE,QAAQ,CAAC;QACb,QAAQ,EAAE,SAAS,CAAC;KACpB;CACD,CAAC;AAEF,wBAAgB,mBAAmB,CAAC,KAAK,CAAC,SAAS,SAAS,UAAU,EAAE,KAAK,CAAC,OAAO,SAAS,WAAW,EACxG,SAAS,EAAE,SAAS,EACpB,MAAM,EAAE,OAAO,GACb,YAAY,CAAC,OAAO,EAAE,SAAS,CAAC,CAElC","sourcesContent":["import type { Api, Model, ProviderId } from \"./types.ts\";\n\nexport type ModelGroups = Record<string, Record<string, object>>;\n\ntype ModelId<TGroups extends ModelGroups> = {\n\t[TApi in keyof TGroups]: keyof TGroups[TApi];\n}[keyof TGroups] &\n\tstring;\n\ntype ModelApi<TGroups extends ModelGroups, TModelId extends ModelId<TGroups>> = {\n\t[TApi in keyof TGroups]: TModelId extends keyof TGroups[TApi] ? TApi : never;\n}[keyof TGroups] &\n\tApi;\n\nexport type ModelCatalog<TGroups extends ModelGroups, TProvider extends ProviderId> = {\n\t[TModelId in ModelId<TGroups>]: Model<ModelApi<TGroups, TModelId>> & {\n\t\tid: TModelId;\n\t\tprovider: TProvider;\n\t};\n};\n\nexport function flattenModelCatalog<const TProvider extends ProviderId, const TGroups extends ModelGroups>(\n\t_provider: TProvider,\n\tgroups: TGroups,\n): ModelCatalog<TGroups, TProvider> {\n\treturn Object.assign({}, ...Object.values(groups)) as ModelCatalog<TGroups, TProvider>;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model-catalog.js","sourceRoot":"","sources":["../src/model-catalog.ts"],"names":[],"mappings":"AAqBA,MAAM,UAAU,mBAAmB,CAClC,SAAoB,EACpB,MAAe,EACoB;IACnC,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAqC,CAAC;AAAA,CACvF","sourcesContent":["import type { Api, Model, ProviderId } from \"./types.ts\";\n\nexport type ModelGroups = Record<string, Record<string, object>>;\n\ntype ModelId<TGroups extends ModelGroups> = {\n\t[TApi in keyof TGroups]: keyof TGroups[TApi];\n}[keyof TGroups] &\n\tstring;\n\ntype ModelApi<TGroups extends ModelGroups, TModelId extends ModelId<TGroups>> = {\n\t[TApi in keyof TGroups]: TModelId extends keyof TGroups[TApi] ? TApi : never;\n}[keyof TGroups] &\n\tApi;\n\nexport type ModelCatalog<TGroups extends ModelGroups, TProvider extends ProviderId> = {\n\t[TModelId in ModelId<TGroups>]: Model<ModelApi<TGroups, TModelId>> & {\n\t\tid: TModelId;\n\t\tprovider: TProvider;\n\t};\n};\n\nexport function flattenModelCatalog<const TProvider extends ProviderId, const TGroups extends ModelGroups>(\n\t_provider: TProvider,\n\tgroups: TGroups,\n): ModelCatalog<TGroups, TProvider> {\n\treturn Object.assign({}, ...Object.values(groups)) as ModelCatalog<TGroups, TProvider>;\n}\n"]}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Api, Model } from "./types.ts";
|
|
2
|
+
export interface ModelsStoreEntry {
|
|
3
|
+
models: readonly Model<Api>[];
|
|
4
|
+
/** Unix timestamp from the remote catalog's Last-Modified header. */
|
|
5
|
+
lastModified?: number;
|
|
6
|
+
/** Unix timestamp of the last completed remote check. */
|
|
7
|
+
checkedAt?: number;
|
|
8
|
+
/**
|
|
9
|
+
* Opaque validator from the remote catalog's ETag header, stored verbatim
|
|
10
|
+
* (quotes included) and echoed back as If-None-Match.
|
|
11
|
+
*/
|
|
12
|
+
etag?: string;
|
|
13
|
+
}
|
|
14
|
+
export interface ModelsStoreOperationOptions {
|
|
15
|
+
signal?: AbortSignal;
|
|
16
|
+
}
|
|
17
|
+
/** Persistent model catalogs keyed by provider ID. */
|
|
18
|
+
export interface ModelsStore {
|
|
19
|
+
read(providerId: string, options?: ModelsStoreOperationOptions): Promise<ModelsStoreEntry | undefined>;
|
|
20
|
+
write(providerId: string, entry: ModelsStoreEntry, options?: ModelsStoreOperationOptions): Promise<void>;
|
|
21
|
+
delete(providerId: string, options?: ModelsStoreOperationOptions): Promise<void>;
|
|
22
|
+
}
|
|
23
|
+
export declare class InMemoryModelsStore implements ModelsStore {
|
|
24
|
+
private readonly entries;
|
|
25
|
+
read(providerId: string, options?: ModelsStoreOperationOptions): Promise<ModelsStoreEntry | undefined>;
|
|
26
|
+
write(providerId: string, entry: ModelsStoreEntry, options?: ModelsStoreOperationOptions): Promise<void>;
|
|
27
|
+
delete(providerId: string, options?: ModelsStoreOperationOptions): Promise<void>;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=models-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"models-store.d.ts","sourceRoot":"","sources":["../src/models-store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAE7C,MAAM,WAAW,gBAAgB;IAChC,MAAM,EAAE,SAAS,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;IAC9B,qEAAqE;IACrE,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,yDAAyD;IACzD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,2BAA2B;IAC3C,MAAM,CAAC,EAAE,WAAW,CAAC;CACrB;AAED,sDAAsD;AACtD,MAAM,WAAW,WAAW;IAC3B,IAAI,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,2BAA2B,GAAG,OAAO,CAAC,gBAAgB,GAAG,SAAS,CAAC,CAAC;IACvG,KAAK,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,gBAAgB,EAAE,OAAO,CAAC,EAAE,2BAA2B,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACzG,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,2BAA2B,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACjF;AAED,qBAAa,mBAAoB,YAAW,WAAW;IACtD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAuC;IAEzD,IAAI,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,2BAA2B,GAAG,OAAO,CAAC,gBAAgB,GAAG,SAAS,CAAC,CAI3G;IAEK,KAAK,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,gBAAgB,EAAE,OAAO,CAAC,EAAE,2BAA2B,GAAG,OAAO,CAAC,IAAI,CAAC,CAG7G;IAEK,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,2BAA2B,GAAG,OAAO,CAAC,IAAI,CAAC,CAGrF;CACD","sourcesContent":["import type { Api, Model } from \"./types.ts\";\n\nexport interface ModelsStoreEntry {\n\tmodels: readonly Model<Api>[];\n\t/** Unix timestamp from the remote catalog's Last-Modified header. */\n\tlastModified?: number;\n\t/** Unix timestamp of the last completed remote check. */\n\tcheckedAt?: number;\n\t/**\n\t * Opaque validator from the remote catalog's ETag header, stored verbatim\n\t * (quotes included) and echoed back as If-None-Match.\n\t */\n\tetag?: string;\n}\n\nexport interface ModelsStoreOperationOptions {\n\tsignal?: AbortSignal;\n}\n\n/** Persistent model catalogs keyed by provider ID. */\nexport interface ModelsStore {\n\tread(providerId: string, options?: ModelsStoreOperationOptions): Promise<ModelsStoreEntry | undefined>;\n\twrite(providerId: string, entry: ModelsStoreEntry, options?: ModelsStoreOperationOptions): Promise<void>;\n\tdelete(providerId: string, options?: ModelsStoreOperationOptions): Promise<void>;\n}\n\nexport class InMemoryModelsStore implements ModelsStore {\n\tprivate readonly entries = new Map<string, ModelsStoreEntry>();\n\n\tasync read(providerId: string, options?: ModelsStoreOperationOptions): Promise<ModelsStoreEntry | undefined> {\n\t\toptions?.signal?.throwIfAborted();\n\t\tconst entry = this.entries.get(providerId);\n\t\treturn entry ? structuredClone(entry) : undefined;\n\t}\n\n\tasync write(providerId: string, entry: ModelsStoreEntry, options?: ModelsStoreOperationOptions): Promise<void> {\n\t\toptions?.signal?.throwIfAborted();\n\t\tthis.entries.set(providerId, structuredClone(entry));\n\t}\n\n\tasync delete(providerId: string, options?: ModelsStoreOperationOptions): Promise<void> {\n\t\toptions?.signal?.throwIfAborted();\n\t\tthis.entries.delete(providerId);\n\t}\n}\n"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export class InMemoryModelsStore {
|
|
2
|
+
entries = new Map();
|
|
3
|
+
async read(providerId, options) {
|
|
4
|
+
options?.signal?.throwIfAborted();
|
|
5
|
+
const entry = this.entries.get(providerId);
|
|
6
|
+
return entry ? structuredClone(entry) : undefined;
|
|
7
|
+
}
|
|
8
|
+
async write(providerId, entry, options) {
|
|
9
|
+
options?.signal?.throwIfAborted();
|
|
10
|
+
this.entries.set(providerId, structuredClone(entry));
|
|
11
|
+
}
|
|
12
|
+
async delete(providerId, options) {
|
|
13
|
+
options?.signal?.throwIfAborted();
|
|
14
|
+
this.entries.delete(providerId);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=models-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"models-store.js","sourceRoot":"","sources":["../src/models-store.ts"],"names":[],"mappings":"AA0BA,MAAM,OAAO,mBAAmB;IACd,OAAO,GAAG,IAAI,GAAG,EAA4B,CAAC;IAE/D,KAAK,CAAC,IAAI,CAAC,UAAkB,EAAE,OAAqC,EAAyC;QAC5G,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,CAAC;QAClC,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;QAC3C,OAAO,KAAK,CAAC,CAAC,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAAA,CAClD;IAED,KAAK,CAAC,KAAK,CAAC,UAAkB,EAAE,KAAuB,EAAE,OAAqC,EAAiB;QAC9G,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,CAAC;QAClC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,eAAe,CAAC,KAAK,CAAC,CAAC,CAAC;IAAA,CACrD;IAED,KAAK,CAAC,MAAM,CAAC,UAAkB,EAAE,OAAqC,EAAiB;QACtF,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,CAAC;QAClC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;IAAA,CAChC;CACD","sourcesContent":["import type { Api, Model } from \"./types.ts\";\n\nexport interface ModelsStoreEntry {\n\tmodels: readonly Model<Api>[];\n\t/** Unix timestamp from the remote catalog's Last-Modified header. */\n\tlastModified?: number;\n\t/** Unix timestamp of the last completed remote check. */\n\tcheckedAt?: number;\n\t/**\n\t * Opaque validator from the remote catalog's ETag header, stored verbatim\n\t * (quotes included) and echoed back as If-None-Match.\n\t */\n\tetag?: string;\n}\n\nexport interface ModelsStoreOperationOptions {\n\tsignal?: AbortSignal;\n}\n\n/** Persistent model catalogs keyed by provider ID. */\nexport interface ModelsStore {\n\tread(providerId: string, options?: ModelsStoreOperationOptions): Promise<ModelsStoreEntry | undefined>;\n\twrite(providerId: string, entry: ModelsStoreEntry, options?: ModelsStoreOperationOptions): Promise<void>;\n\tdelete(providerId: string, options?: ModelsStoreOperationOptions): Promise<void>;\n}\n\nexport class InMemoryModelsStore implements ModelsStore {\n\tprivate readonly entries = new Map<string, ModelsStoreEntry>();\n\n\tasync read(providerId: string, options?: ModelsStoreOperationOptions): Promise<ModelsStoreEntry | undefined> {\n\t\toptions?.signal?.throwIfAborted();\n\t\tconst entry = this.entries.get(providerId);\n\t\treturn entry ? structuredClone(entry) : undefined;\n\t}\n\n\tasync write(providerId: string, entry: ModelsStoreEntry, options?: ModelsStoreOperationOptions): Promise<void> {\n\t\toptions?.signal?.throwIfAborted();\n\t\tthis.entries.set(providerId, structuredClone(entry));\n\t}\n\n\tasync delete(providerId: string, options?: ModelsStoreOperationOptions): Promise<void> {\n\t\toptions?.signal?.throwIfAborted();\n\t\tthis.entries.delete(providerId);\n\t}\n}\n"]}
|
package/dist/models.d.ts
ADDED
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import { type AuthResolutionOverrides } from "./auth/resolve.ts";
|
|
2
|
+
import type { AuthCheck, AuthContext, AuthInteraction, AuthOperationOptions, AuthResult, AuthType, Credential, CredentialStore, ProviderAuth } from "./auth/types.ts";
|
|
3
|
+
import { type ModelsStore, type ModelsStoreEntry } from "./models-store.ts";
|
|
4
|
+
import type { Api, ApiStreamOptions, AssistantMessage, AssistantMessageEventStream, Context, DeferredCancelOptions, DeferredFetchOptions, DeferredHandle, Model, ModelThinkingLevel, ProviderHeaders, ProviderStreams, SimpleStreamOptions, Usage } from "./types.ts";
|
|
5
|
+
export { ModelsError, type ModelsErrorCode } from "./auth/resolve.ts";
|
|
6
|
+
export interface ModelsPublication {
|
|
7
|
+
/** Provider-selected persisted catalog. Omit to leave storage unchanged; null deletes it. */
|
|
8
|
+
persist?: ModelsStoreEntry | null;
|
|
9
|
+
/** Optional synchronous update of provider-private in-memory catalog state. */
|
|
10
|
+
update?: () => void;
|
|
11
|
+
}
|
|
12
|
+
export interface RefreshModelsContext {
|
|
13
|
+
/** Effective configured credential. OAuth credentials are refreshed before network access. */
|
|
14
|
+
credential?: Credential;
|
|
15
|
+
/** Immutable provider-scoped catalog snapshot captured before this refresh phase. */
|
|
16
|
+
stored?: Readonly<ModelsStoreEntry>;
|
|
17
|
+
/**
|
|
18
|
+
* Generation-checked publication. Persistence policy remains provider-owned;
|
|
19
|
+
* the update runs synchronously only after the selected persistence mutation.
|
|
20
|
+
*/
|
|
21
|
+
publish(publication: ModelsPublication): Promise<boolean>;
|
|
22
|
+
/** False during offline/cache-only initialization. */
|
|
23
|
+
allowNetwork: boolean;
|
|
24
|
+
/** Bypass provider freshness checks and fetch immediately when network access is allowed. */
|
|
25
|
+
force?: boolean;
|
|
26
|
+
/** Always present, including when the public refresh caller omits its optional signal. */
|
|
27
|
+
signal: AbortSignal;
|
|
28
|
+
}
|
|
29
|
+
export interface ModelsRefreshOptions {
|
|
30
|
+
allowNetwork?: boolean;
|
|
31
|
+
/** Restrict refresh to these provider IDs. Unknown and static providers are ignored. */
|
|
32
|
+
providers?: readonly string[];
|
|
33
|
+
/** Bypass provider freshness checks and fetch immediately when network access is allowed. */
|
|
34
|
+
force?: boolean;
|
|
35
|
+
signal?: AbortSignal;
|
|
36
|
+
}
|
|
37
|
+
export interface ModelsRefreshResult {
|
|
38
|
+
aborted: boolean;
|
|
39
|
+
errors: ReadonlyMap<string, Error>;
|
|
40
|
+
}
|
|
41
|
+
export interface ModelsRequestTransforms {
|
|
42
|
+
/** Transform fully assembled model/auth/request headers before provider dispatch. */
|
|
43
|
+
transformHeaders?: (headers: ProviderHeaders) => ProviderHeaders | Promise<ProviderHeaders>;
|
|
44
|
+
}
|
|
45
|
+
export type ModelsApiStreamOptions<TApi extends Api> = ApiStreamOptions<TApi> & ModelsRequestTransforms;
|
|
46
|
+
export type ModelsSimpleStreamOptions = SimpleStreamOptions & ModelsRequestTransforms;
|
|
47
|
+
export type ModelsDeferredFetchOptions = DeferredFetchOptions & ModelsRequestTransforms;
|
|
48
|
+
export type ModelsDeferredCancelOptions = DeferredCancelOptions & ModelsRequestTransforms;
|
|
49
|
+
/**
|
|
50
|
+
* A provider is the concrete runtime unit. It owns id/name/base metadata,
|
|
51
|
+
* auth methods, model listing, and stream behavior.
|
|
52
|
+
*
|
|
53
|
+
* `TApi` lets concrete provider factories declare which APIs their models
|
|
54
|
+
* use (e.g. `openaiProvider(): Provider<"openai-responses" | "openai-completions">`),
|
|
55
|
+
* giving typed model lists to direct factory users. Inside a `Models`
|
|
56
|
+
* collection providers are held as `Provider<Api>`.
|
|
57
|
+
*/
|
|
58
|
+
export interface Provider<TApi extends Api = Api> {
|
|
59
|
+
readonly id: string;
|
|
60
|
+
readonly name: string;
|
|
61
|
+
readonly baseUrl?: string;
|
|
62
|
+
readonly headers?: ProviderHeaders;
|
|
63
|
+
/**
|
|
64
|
+
* Required: at least one of `apiKey`/`oauth`. Every provider has auth
|
|
65
|
+
* semantics — even providers with only ambient credentials (env vars, AWS
|
|
66
|
+
* profiles, ADC files) and keyless local servers provide `apiKey` auth
|
|
67
|
+
* whose `resolve()` reports whether the provider is configured.
|
|
68
|
+
* `Models.getAuth()` returns undefined when the provider is unconfigured.
|
|
69
|
+
*/
|
|
70
|
+
readonly auth: ProviderAuth;
|
|
71
|
+
/**
|
|
72
|
+
* Current known models, sync. Static providers return their catalog;
|
|
73
|
+
* dynamic providers return the list as of the last `refreshModels()`
|
|
74
|
+
* (empty before the first). Must not throw; `Models` treats a throwing
|
|
75
|
+
* implementation as having no models.
|
|
76
|
+
*/
|
|
77
|
+
getModels(): readonly Model<TApi>[];
|
|
78
|
+
/**
|
|
79
|
+
* Dynamic providers only: restore `context.stored` and optionally fetch a newer list using
|
|
80
|
+
* the effective credential. Implementations retain their previous list on failure, publish
|
|
81
|
+
* persistence and synchronous state changes through `context.publish()`, and honor the
|
|
82
|
+
* shared abort signal for blocking work.
|
|
83
|
+
*/
|
|
84
|
+
refreshModels?(context: RefreshModelsContext): Promise<void>;
|
|
85
|
+
/**
|
|
86
|
+
* Optional provider policy for credential-specific model availability.
|
|
87
|
+
* `getModels()` remains the complete synchronous catalog; `Models.getAvailable()`
|
|
88
|
+
* applies this filter after confirming that provider auth is configured.
|
|
89
|
+
*/
|
|
90
|
+
filterModels?(models: readonly Model<TApi>[], credential: Credential | undefined): readonly Model<TApi>[];
|
|
91
|
+
stream<T extends TApi>(model: Model<T>, context: Context, options?: ApiStreamOptions<T>): AssistantMessageEventStream;
|
|
92
|
+
streamSimple(model: Model<TApi>, context: Context, options?: SimpleStreamOptions): AssistantMessageEventStream;
|
|
93
|
+
fetchDeferred?(model: Model<TApi>, handle: DeferredHandle, options?: DeferredFetchOptions): AssistantMessageEventStream;
|
|
94
|
+
cancelDeferred?(model: Model<TApi>, handle: DeferredHandle, options?: DeferredCancelOptions): Promise<void>;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Runtime collection of providers plus auth application and stream
|
|
98
|
+
* convenience. Providers own stream behavior; `Models` resolves auth and
|
|
99
|
+
* delegates each request to the provider that owns the model.
|
|
100
|
+
*/
|
|
101
|
+
export interface Models {
|
|
102
|
+
getProviders(): readonly Provider[];
|
|
103
|
+
getProvider(id: string): Provider | undefined;
|
|
104
|
+
/**
|
|
105
|
+
* Sync read of last-known models from one provider or all providers.
|
|
106
|
+
* Best-effort: a provider whose `getModels()` throws yields no models.
|
|
107
|
+
*/
|
|
108
|
+
getModels(provider?: string): readonly Model<Api>[];
|
|
109
|
+
/**
|
|
110
|
+
* Sync runtime model lookup against last-known lists. Dynamic model lists
|
|
111
|
+
* are typed as `Model<Api>`; narrow with the `hasApi()` type guard.
|
|
112
|
+
*/
|
|
113
|
+
getModel(provider: string, id: string): Model<Api> | undefined;
|
|
114
|
+
/**
|
|
115
|
+
* Refresh selected configured dynamic providers concurrently (all when `providers` is omitted).
|
|
116
|
+
* Provider errors and cancellation are returned without rejecting; static, unknown, and
|
|
117
|
+
* unconfigured providers are skipped.
|
|
118
|
+
*/
|
|
119
|
+
refresh(options?: ModelsRefreshOptions): Promise<ModelsRefreshResult>;
|
|
120
|
+
/** Check whether a provider has complete auth configuration without refreshing OAuth. */
|
|
121
|
+
checkAuth(providerId: string, options?: AuthOperationOptions): Promise<AuthCheck | undefined>;
|
|
122
|
+
/** Return models whose providers have complete auth configuration. */
|
|
123
|
+
getAvailable(providerId?: string, options?: AuthOperationOptions): Promise<readonly Model<Api>[]>;
|
|
124
|
+
/**
|
|
125
|
+
* Resolve provider-scoped auth by provider id, or provider auth plus static
|
|
126
|
+
* model headers when passed a model. Includes a source label for status UI.
|
|
127
|
+
* Resolves `undefined` when the provider is unknown or unconfigured.
|
|
128
|
+
* Rejects with `ModelsError`: code "oauth" when a token refresh fails (the
|
|
129
|
+
* stored credential is preserved for retry; re-login fixes it), code "auth"
|
|
130
|
+
* when api-key resolution or the credential store fails. Request paths
|
|
131
|
+
* surface rejections as stream errors.
|
|
132
|
+
*/
|
|
133
|
+
getAuth(providerId: string, overrides?: AuthResolutionOverrides): Promise<AuthResult | undefined>;
|
|
134
|
+
getAuth(model: Model<Api>, overrides?: AuthResolutionOverrides): Promise<AuthResult | undefined>;
|
|
135
|
+
/** Run a provider-owned login flow and persist its returned credential. */
|
|
136
|
+
login(providerId: string, type: AuthType, interaction: AuthInteraction): Promise<Credential>;
|
|
137
|
+
/** Remove the stored credential for a provider. */
|
|
138
|
+
logout(providerId: string, options?: AuthOperationOptions): Promise<void>;
|
|
139
|
+
stream<TApi extends Api>(model: Model<TApi>, context: Context, options?: ModelsApiStreamOptions<TApi>): AssistantMessageEventStream;
|
|
140
|
+
complete<TApi extends Api>(model: Model<TApi>, context: Context, options?: ModelsApiStreamOptions<TApi>): Promise<AssistantMessage>;
|
|
141
|
+
streamSimple(model: Model<Api>, context: Context, options?: ModelsSimpleStreamOptions): AssistantMessageEventStream;
|
|
142
|
+
completeSimple(model: Model<Api>, context: Context, options?: ModelsSimpleStreamOptions): Promise<AssistantMessage>;
|
|
143
|
+
fetchDeferred(model: Model<Api>, handle: DeferredHandle, options?: ModelsDeferredFetchOptions): Promise<AssistantMessage>;
|
|
144
|
+
cancelDeferred(model: Model<Api>, handle: DeferredHandle, options?: ModelsDeferredCancelOptions): Promise<void>;
|
|
145
|
+
}
|
|
146
|
+
export interface MutableModels extends Models {
|
|
147
|
+
/** Upsert/replace by provider.id. Provider ids are unique. */
|
|
148
|
+
setProvider(provider: Provider): void;
|
|
149
|
+
deleteProvider(id: string): void;
|
|
150
|
+
clearProviders(): void;
|
|
151
|
+
}
|
|
152
|
+
export interface CreateModelsOptions {
|
|
153
|
+
credentials?: CredentialStore;
|
|
154
|
+
modelsStore?: ModelsStore;
|
|
155
|
+
authContext?: AuthContext;
|
|
156
|
+
}
|
|
157
|
+
export declare function createModels(options?: CreateModelsOptions): MutableModels;
|
|
158
|
+
export interface CreateProviderOptions<TApi extends Api = Api> {
|
|
159
|
+
id: string;
|
|
160
|
+
/** Display name. Default: `id`. */
|
|
161
|
+
name?: string;
|
|
162
|
+
baseUrl?: string;
|
|
163
|
+
headers?: ProviderHeaders;
|
|
164
|
+
/** Required — every provider has auth semantics, even ambient/keyless ones. */
|
|
165
|
+
auth: ProviderAuth;
|
|
166
|
+
/** Static baseline model list (empty for purely dynamic providers). */
|
|
167
|
+
models: readonly Model<TApi>[];
|
|
168
|
+
/** Fetch a dynamic model overlay. createProvider restores and publishes it transactionally. */
|
|
169
|
+
fetchModels?: (context: RefreshModelsContext) => Promise<readonly Model<TApi>[]>;
|
|
170
|
+
filterModels?: (models: readonly Model<TApi>[], credential: Credential | undefined) => readonly Model<TApi>[];
|
|
171
|
+
/** Single implementation, or map keyed by `model.api` for mixed-API providers. */
|
|
172
|
+
api: ProviderStreams | Partial<Record<TApi, ProviderStreams>>;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Builds a provider from parts. Built-in provider factories and models.json
|
|
176
|
+
* custom providers both go through this. A single `api` streams all models;
|
|
177
|
+
* an `api` map dispatches on `model.api`, and a model whose api has no entry
|
|
178
|
+
* produces a stream error.
|
|
179
|
+
*/
|
|
180
|
+
export declare function createProvider<TApi extends Api = Api>(input: CreateProviderOptions<TApi>): Provider<TApi>;
|
|
181
|
+
/**
|
|
182
|
+
* Runtime-checked narrowing for dynamically looked-up models:
|
|
183
|
+
*
|
|
184
|
+
* ```ts
|
|
185
|
+
* const model = models.getModel("anthropic", "claude-opus-4-7");
|
|
186
|
+
* if (model && hasApi(model, "anthropic-messages")) {
|
|
187
|
+
* // model: Model<"anthropic-messages">, stream options fully typed
|
|
188
|
+
* }
|
|
189
|
+
* ```
|
|
190
|
+
*/
|
|
191
|
+
export declare function hasApi<TApi extends Api>(model: Model<Api>, api: TApi): model is Model<TApi>;
|
|
192
|
+
export declare function calculateCost<TApi extends Api>(model: Model<TApi>, usage: Usage): Usage["cost"];
|
|
193
|
+
export declare function getSupportedThinkingLevels<TApi extends Api>(model: Model<TApi>): ModelThinkingLevel[];
|
|
194
|
+
export declare function clampThinkingLevel<TApi extends Api>(model: Model<TApi>, level: ModelThinkingLevel): ModelThinkingLevel;
|
|
195
|
+
/**
|
|
196
|
+
* Check if two models are equal by comparing both their id and provider.
|
|
197
|
+
* Returns false if either model is null or undefined.
|
|
198
|
+
*/
|
|
199
|
+
export declare function modelsAreEqual<TApi extends Api>(a: Model<TApi> | null | undefined, b: Model<TApi> | null | undefined): boolean;
|
|
200
|
+
//# sourceMappingURL=models.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"models.d.ts","sourceRoot":"","sources":["../src/models.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,uBAAuB,EAAoC,MAAM,mBAAmB,CAAC;AACnG,OAAO,KAAK,EACX,SAAS,EACT,WAAW,EACX,eAAe,EACf,oBAAoB,EACpB,UAAU,EACV,QAAQ,EACR,UAAU,EACV,eAAe,EACf,YAAY,EACZ,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAuB,KAAK,WAAW,EAAE,KAAK,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACjG,OAAO,KAAK,EACX,GAAG,EACH,gBAAgB,EAChB,gBAAgB,EAChB,2BAA2B,EAC3B,OAAO,EACP,qBAAqB,EACrB,oBAAoB,EACpB,cAAc,EACd,KAAK,EAEL,kBAAkB,EAClB,eAAe,EAEf,eAAe,EACf,mBAAmB,EACnB,KAAK,EACL,MAAM,YAAY,CAAC;AAGpB,OAAO,EA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,CAAC,IAAI,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC,CAoGzG;AAED;;;;;;;;;GASG;AACH,wBAAgB,MAAM,CAAC,IAAI,SAAS,GAAG,EAAE,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,IAAI,GAAG,KAAK,IAAI,KAAK,CAAC,IAAI,CAAC,CAE3F;AAED,wBAAgB,aAAa,CAAC,IAAI,SAAS,GAAG,EAAE,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,CAoB/F;AAID,wBAAgB,0BAA0B,CAAC,IAAI,SAAS,GAAG,EAAE,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,GAAG,kBAAkB,EAAE,CASrG;AAED,wBAAgB,kBAAkB,CAAC,IAAI,SAAS,GAAG,EAClD,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,EAClB,KAAK,EAAE,kBAAkB,GACvB,kBAAkB,CAgBpB;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,IAAI,SAAS,GAAG,EAC9C,CAAC,EAAE,KAAK,CAAC,IAAI,CAAC,GAAG,IAAI,GAAG,SAAS,EACjC,CAAC,EAAE,KAAK,CAAC,IAAI,CAAC,GAAG,IAAI,GAAG,SAAS,GAC/B,OAAO,CAGT","sourcesContent":["import { lazyStream } from \"./api/lazy.ts\";\nimport { defaultProviderAuthContext as defaultAuthContext } from \"./auth/context.ts\";\nimport { InMemoryCredentialStore } from \"./auth/credential-store.ts\";\nimport { type AuthResolutionOverrides, ModelsError, resolveProviderAuth } from \"./auth/resolve.ts\";\nimport type {\n\tAuthCheck,\n\tAuthContext,\n\tAuthInteraction,\n\tAuthOperationOptions,\n\tAuthResult,\n\tAuthType,\n\tCredential,\n\tCredentialStore,\n\tProviderAuth,\n} from \"./auth/types.ts\";\nimport { InMemoryModelsStore, type ModelsStore, type ModelsStoreEntry } from \"./models-store.ts\";\nimport type {\n\tApi,\n\tApiStreamOptions,\n\tAssistantMessage,\n\tAssistantMessageEventStream,\n\tContext,\n\tDeferredCancelOptions,\n\tDeferredFetchOptions,\n\tDeferredHandle,\n\tModel,\n\tModelCostRates,\n\tModelThinkingLevel,\n\tProviderHeaders,\n\tProviderRequestOptions,\n\tProviderStreams,\n\tSimpleStreamOptions,\n\tUsage,\n} from \"./types.ts\";\nimport { operationSignal, raceWithAbortSignal } from \"./utils/abort.ts\";\n\nexport { ModelsError, type ModelsErrorCode } from \"./auth/resolve.ts\";\n\nexport interface ModelsPublication {\n\t/** Provider-selected persisted catalog. Omit to leave storage unchanged; null deletes it. */\n\tpersist?: ModelsStoreEntry | null;\n\t/** Optional synchronous update of provider-private in-memory catalog state. */\n\tupdate?: () => void;\n}\n\nexport interface RefreshModelsContext {\n\t/** Effective configured credential. OAuth credentials are refreshed before network access. */\n\tcredential?: Credential;\n\t/** Immutable provider-scoped catalog snapshot captured before this refresh phase. */\n\tstored?: Readonly<ModelsStoreEntry>;\n\t/**\n\t * Generation-checked publication. Persistence policy remains provider-owned;\n\t * the update runs synchronously only after the selected persistence mutation.\n\t */\n\tpublish(publication: ModelsPublication): Promise<boolean>;\n\t/** False during offline/cache-only initialization. */\n\tallowNetwork: boolean;\n\t/** Bypass provider freshness checks and fetch immediately when network access is allowed. */\n\tforce?: boolean;\n\t/** Always present, including when the public refresh caller omits its optional signal. */\n\tsignal: AbortSignal;\n}\n\nexport interface ModelsRefreshOptions {\n\tallowNetwork?: boolean;\n\t/** Restrict refresh to these provider IDs. Unknown and static providers are ignored. */\n\tproviders?: readonly string[];\n\t/** Bypass provider freshness checks and fetch immediately when network access is allowed. */\n\tforce?: boolean;\n\tsignal?: AbortSignal;\n}\n\nexport interface ModelsRefreshResult {\n\taborted: boolean;\n\terrors: ReadonlyMap<string, Error>;\n}\n\nexport interface ModelsRequestTransforms {\n\t/** Transform fully assembled model/auth/request headers before provider dispatch. */\n\ttransformHeaders?: (headers: ProviderHeaders) => ProviderHeaders | Promise<ProviderHeaders>;\n}\n\nexport type ModelsApiStreamOptions<TApi extends Api> = ApiStreamOptions<TApi> & ModelsRequestTransforms;\nexport type ModelsSimpleStreamOptions = SimpleStreamOptions & ModelsRequestTransforms;\nexport type ModelsDeferredFetchOptions = DeferredFetchOptions & ModelsRequestTransforms;\nexport type ModelsDeferredCancelOptions = DeferredCancelOptions & ModelsRequestTransforms;\n\n/**\n * A provider is the concrete runtime unit. It owns id/name/base metadata,\n * auth methods, model listing, and stream behavior.\n *\n * `TApi` lets concrete provider factories declare which APIs their models\n * use (e.g. `openaiProvider(): Provider<\"openai-responses\" | \"openai-completions\">`),\n * giving typed model lists to direct factory users. Inside a `Models`\n * collection providers are held as `Provider<Api>`.\n */\nexport interface Provider<TApi extends Api = Api> {\n\treadonly id: string;\n\treadonly name: string;\n\n\treadonly baseUrl?: string;\n\treadonly headers?: ProviderHeaders;\n\n\t/**\n\t * Required: at least one of `apiKey`/`oauth`. Every provider has auth\n\t * semantics — even providers with only ambient credentials (env vars, AWS\n\t * profiles, ADC files) and keyless local servers provide `apiKey` auth\n\t * whose `resolve()` reports whether the provider is configured.\n\t * `Models.getAuth()` returns undefined when the provider is unconfigured.\n\t */\n\treadonly auth: ProviderAuth;\n\n\t/**\n\t * Current known models, sync. Static providers return their catalog;\n\t * dynamic providers return the list as of the last `refreshModels()`\n\t * (empty before the first). Must not throw; `Models` treats a throwing\n\t * implementation as having no models.\n\t */\n\tgetModels(): readonly Model<TApi>[];\n\n\t/**\n\t * Dynamic providers only: restore `context.stored` and optionally fetch a newer list using\n\t * the effective credential. Implementations retain their previous list on failure, publish\n\t * persistence and synchronous state changes through `context.publish()`, and honor the\n\t * shared abort signal for blocking work.\n\t */\n\trefreshModels?(context: RefreshModelsContext): Promise<void>;\n\n\t/**\n\t * Optional provider policy for credential-specific model availability.\n\t * `getModels()` remains the complete synchronous catalog; `Models.getAvailable()`\n\t * applies this filter after confirming that provider auth is configured.\n\t */\n\tfilterModels?(models: readonly Model<TApi>[], credential: Credential | undefined): readonly Model<TApi>[];\n\n\tstream<T extends TApi>(\n\t\tmodel: Model<T>,\n\t\tcontext: Context,\n\t\toptions?: ApiStreamOptions<T>,\n\t): AssistantMessageEventStream;\n\n\tstreamSimple(model: Model<TApi>, context: Context, options?: SimpleStreamOptions): AssistantMessageEventStream;\n\tfetchDeferred?(\n\t\tmodel: Model<TApi>,\n\t\thandle: DeferredHandle,\n\t\toptions?: DeferredFetchOptions,\n\t): AssistantMessageEventStream;\n\tcancelDeferred?(model: Model<TApi>, handle: DeferredHandle, options?: DeferredCancelOptions): Promise<void>;\n}\n\n/**\n * Runtime collection of providers plus auth application and stream\n * convenience. Providers own stream behavior; `Models` resolves auth and\n * delegates each request to the provider that owns the model.\n */\nexport interface Models {\n\tgetProviders(): readonly Provider[];\n\tgetProvider(id: string): Provider | undefined;\n\n\t/**\n\t * Sync read of last-known models from one provider or all providers.\n\t * Best-effort: a provider whose `getModels()` throws yields no models.\n\t */\n\tgetModels(provider?: string): readonly Model<Api>[];\n\n\t/**\n\t * Sync runtime model lookup against last-known lists. Dynamic model lists\n\t * are typed as `Model<Api>`; narrow with the `hasApi()` type guard.\n\t */\n\tgetModel(provider: string, id: string): Model<Api> | undefined;\n\n\t/**\n\t * Refresh selected configured dynamic providers concurrently (all when `providers` is omitted).\n\t * Provider errors and cancellation are returned without rejecting; static, unknown, and\n\t * unconfigured providers are skipped.\n\t */\n\trefresh(options?: ModelsRefreshOptions): Promise<ModelsRefreshResult>;\n\n\t/** Check whether a provider has complete auth configuration without refreshing OAuth. */\n\tcheckAuth(providerId: string, options?: AuthOperationOptions): Promise<AuthCheck | undefined>;\n\n\t/** Return models whose providers have complete auth configuration. */\n\tgetAvailable(providerId?: string, options?: AuthOperationOptions): Promise<readonly Model<Api>[]>;\n\n\t/**\n\t * Resolve provider-scoped auth by provider id, or provider auth plus static\n\t * model headers when passed a model. Includes a source label for status UI.\n\t * Resolves `undefined` when the provider is unknown or unconfigured.\n\t * Rejects with `ModelsError`: code \"oauth\" when a token refresh fails (the\n\t * stored credential is preserved for retry; re-login fixes it), code \"auth\"\n\t * when api-key resolution or the credential store fails. Request paths\n\t * surface rejections as stream errors.\n\t */\n\tgetAuth(providerId: string, overrides?: AuthResolutionOverrides): Promise<AuthResult | undefined>;\n\tgetAuth(model: Model<Api>, overrides?: AuthResolutionOverrides): Promise<AuthResult | undefined>;\n\n\t/** Run a provider-owned login flow and persist its returned credential. */\n\tlogin(providerId: string, type: AuthType, interaction: AuthInteraction): Promise<Credential>;\n\n\t/** Remove the stored credential for a provider. */\n\tlogout(providerId: string, options?: AuthOperationOptions): Promise<void>;\n\n\tstream<TApi extends Api>(\n\t\tmodel: Model<TApi>,\n\t\tcontext: Context,\n\t\toptions?: ModelsApiStreamOptions<TApi>,\n\t): AssistantMessageEventStream;\n\n\tcomplete<TApi extends Api>(\n\t\tmodel: Model<TApi>,\n\t\tcontext: Context,\n\t\toptions?: ModelsApiStreamOptions<TApi>,\n\t): Promise<AssistantMessage>;\n\n\tstreamSimple(model: Model<Api>, context: Context, options?: ModelsSimpleStreamOptions): AssistantMessageEventStream;\n\tcompleteSimple(model: Model<Api>, context: Context, options?: ModelsSimpleStreamOptions): Promise<AssistantMessage>;\n\tfetchDeferred(\n\t\tmodel: Model<Api>,\n\t\thandle: DeferredHandle,\n\t\toptions?: ModelsDeferredFetchOptions,\n\t): Promise<AssistantMessage>;\n\tcancelDeferred(model: Model<Api>, handle: DeferredHandle, options?: ModelsDeferredCancelOptions): Promise<void>;\n}\n\nexport interface MutableModels extends Models {\n\t/** Upsert/replace by provider.id. Provider ids are unique. */\n\tsetProvider(provider: Provider): void;\n\tdeleteProvider(id: string): void;\n\tclearProviders(): void;\n}\n\nexport interface CreateModelsOptions {\n\tcredentials?: CredentialStore;\n\tmodelsStore?: ModelsStore;\n\tauthContext?: AuthContext;\n}\n\nfunction mergeHeaders(\n\tbase: ProviderHeaders | undefined,\n\toverride: ProviderHeaders | undefined,\n): ProviderHeaders | undefined {\n\tif (!base && !override) return undefined;\n\tconst merged = { ...base };\n\tfor (const [name, value] of Object.entries(override ?? {})) {\n\t\tconst lowerName = name.toLowerCase();\n\t\tfor (const existingName of Object.keys(merged)) {\n\t\t\tif (existingName.toLowerCase() === lowerName) delete merged[existingName];\n\t\t}\n\t\tmerged[name] = value;\n\t}\n\treturn merged;\n}\n\nclass ModelsImpl implements MutableModels {\n\tprivate providers = new Map<string, Provider>();\n\tprivate credentials: CredentialStore;\n\tprivate modelsStore: ModelsStore;\n\tprivate authContext: AuthContext;\n\tprivate refreshGenerations = new Map<string, number>();\n\tprivate refreshControllers = new Map<string, AbortController>();\n\tprivate publicationChains = new Map<string, Promise<unknown>>();\n\n\tconstructor(options?: CreateModelsOptions) {\n\t\tthis.credentials = options?.credentials ?? new InMemoryCredentialStore();\n\t\tthis.modelsStore = options?.modelsStore ?? new InMemoryModelsStore();\n\t\tthis.authContext = options?.authContext ?? defaultAuthContext();\n\t}\n\n\tsetProvider(provider: Provider): void {\n\t\tthis.supersedeProviderRefresh(provider.id);\n\t\tthis.providers.set(provider.id, provider);\n\t}\n\n\tdeleteProvider(id: string): void {\n\t\tthis.supersedeProviderRefresh(id);\n\t\tthis.providers.delete(id);\n\t}\n\n\tclearProviders(): void {\n\t\tfor (const id of new Set([...this.providers.keys(), ...this.refreshControllers.keys()])) {\n\t\t\tthis.supersedeProviderRefresh(id);\n\t\t}\n\t\tthis.providers.clear();\n\t}\n\n\tgetProviders(): readonly Provider[] {\n\t\treturn Array.from(this.providers.values());\n\t}\n\n\tgetProvider(id: string): Provider | undefined {\n\t\treturn this.providers.get(id);\n\t}\n\n\tgetModels(provider?: string): readonly Model<Api>[] {\n\t\tif (provider !== undefined) {\n\t\t\tconst entry = this.providers.get(provider);\n\t\t\tif (!entry) return [];\n\t\t\ttry {\n\t\t\t\treturn entry.getModels();\n\t\t\t} catch {\n\t\t\t\treturn [];\n\t\t\t}\n\t\t}\n\n\t\tconst models: Model<Api>[] = [];\n\t\tfor (const entry of this.providers.values()) {\n\t\t\ttry {\n\t\t\t\tmodels.push(...entry.getModels());\n\t\t\t} catch {\n\t\t\t\t// Best-effort: ill-behaved providers yield no models.\n\t\t\t}\n\t\t}\n\t\treturn models;\n\t}\n\n\tgetModel(provider: string, id: string): Model<Api> | undefined {\n\t\treturn this.getModels(provider).find((model) => model.id === id);\n\t}\n\n\tprivate supersedeProviderRefresh(providerId: string): number {\n\t\tconst generation = (this.refreshGenerations.get(providerId) ?? 0) + 1;\n\t\tthis.refreshGenerations.set(providerId, generation);\n\t\tconst previous = this.refreshControllers.get(providerId);\n\t\tif (previous) {\n\t\t\tthis.refreshControllers.delete(providerId);\n\t\t\tprevious.abort();\n\t\t}\n\t\treturn generation;\n\t}\n\n\tprivate beginProviderRefresh(providerId: string): { generation: number; controller: AbortController } {\n\t\tconst generation = this.supersedeProviderRefresh(providerId);\n\t\tconst controller = new AbortController();\n\t\tthis.refreshControllers.set(providerId, controller);\n\t\treturn { generation, controller };\n\t}\n\n\tprivate publishProviderModels(\n\t\tproviderId: string,\n\t\tgeneration: number,\n\t\tsignal: AbortSignal,\n\t\tpublication: ModelsPublication,\n\t): Promise<boolean> {\n\t\tconst previous = this.publicationChains.get(providerId) ?? Promise.resolve();\n\t\tconst queued = (async () => {\n\t\t\tawait previous.catch(() => {});\n\t\t\tif (signal.aborted || this.refreshGenerations.get(providerId) !== generation) return false;\n\n\t\t\tif (publication.persist === null) {\n\t\t\t\tawait this.modelsStore.delete(providerId, { signal });\n\t\t\t} else if (publication.persist !== undefined) {\n\t\t\t\tawait this.modelsStore.write(providerId, structuredClone(publication.persist), { signal });\n\t\t\t}\n\n\t\t\tif (signal.aborted || this.refreshGenerations.get(providerId) !== generation) return false;\n\t\t\tpublication.update?.();\n\t\t\treturn true;\n\t\t})();\n\t\tconst tail = queued.catch(() => {});\n\t\tthis.publicationChains.set(providerId, tail);\n\t\tvoid tail.then(() => {\n\t\t\tif (this.publicationChains.get(providerId) === tail) this.publicationChains.delete(providerId);\n\t\t});\n\t\treturn raceWithAbortSignal(queued, signal);\n\t}\n\n\tprivate async runProviderRefreshPhase(\n\t\tprovider: Provider & Required<Pick<Provider, \"refreshModels\">>,\n\t\tcredential: Credential | undefined,\n\t\tallowNetwork: boolean,\n\t\tforce: boolean | undefined,\n\t\tgeneration: number,\n\t\tsignal: AbortSignal,\n\t): Promise<void> {\n\t\tconst stored = await this.modelsStore.read(provider.id, { signal });\n\t\tawait provider.refreshModels({\n\t\t\tcredential,\n\t\t\tstored: stored ? structuredClone(stored) : undefined,\n\t\t\tpublish: (publication) => this.publishProviderModels(provider.id, generation, signal, publication),\n\t\t\tallowNetwork,\n\t\t\tforce: allowNetwork ? force : undefined,\n\t\t\tsignal,\n\t\t});\n\t}\n\n\tasync refresh(options: ModelsRefreshOptions = {}): Promise<ModelsRefreshResult> {\n\t\tconst allowNetwork = options.allowNetwork ?? true;\n\t\tconst callerSignal = operationSignal(options.signal);\n\t\tconst errors = new Map<string, Error>();\n\t\tif (callerSignal.aborted) return { aborted: true, errors };\n\t\tconst selected = options.providers ? new Set(options.providers) : undefined;\n\t\tconst refreshable = Array.from(this.providers.values()).filter(\n\t\t\t(provider): provider is Provider & Required<Pick<Provider, \"refreshModels\">> =>\n\t\t\t\tprovider.refreshModels !== undefined && (!selected || selected.has(provider.id)),\n\t\t);\n\n\t\tconst refresh = Promise.all(\n\t\t\trefreshable.map(async (provider) => {\n\t\t\t\tconst { generation, controller } = this.beginProviderRefresh(provider.id);\n\t\t\t\tconst signal = AbortSignal.any([callerSignal, controller.signal]);\n\t\t\t\tconst operation = (async () => {\n\t\t\t\t\tlet storedCredential: Credential | undefined;\n\t\t\t\t\tlet credentialError: unknown;\n\t\t\t\t\ttry {\n\t\t\t\t\t\tstoredCredential = await this.readCredential(provider.id, signal);\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tcredentialError = error;\n\t\t\t\t\t}\n\n\t\t\t\t\t// Restore cached provider state before auth resolution or network access.\n\t\t\t\t\tawait this.runProviderRefreshPhase(provider, storedCredential, false, undefined, generation, signal);\n\t\t\t\t\tif (credentialError !== undefined) throw credentialError;\n\t\t\t\t\tif (!allowNetwork || signal.aborted) return;\n\n\t\t\t\t\tconst credential = await this.resolveRefreshCredential(provider, storedCredential, signal);\n\t\t\t\t\tif (!credential) return;\n\t\t\t\t\tawait this.runProviderRefreshPhase(provider, credential, true, options.force, generation, signal);\n\t\t\t\t})();\n\n\t\t\t\ttry {\n\t\t\t\t\tawait raceWithAbortSignal(operation, signal);\n\t\t\t\t} catch (error) {\n\t\t\t\t\tif (!signal.aborted) {\n\t\t\t\t\t\terrors.set(\n\t\t\t\t\t\t\tprovider.id,\n\t\t\t\t\t\t\terror instanceof Error\n\t\t\t\t\t\t\t\t? error\n\t\t\t\t\t\t\t\t: new ModelsError(\"model_source\", `Model refresh failed for ${provider.id}`, { cause: error }),\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t} finally {\n\t\t\t\t\tif (this.refreshControllers.get(provider.id) === controller) {\n\t\t\t\t\t\tthis.refreshControllers.delete(provider.id);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}),\n\t\t);\n\n\t\ttry {\n\t\t\tawait raceWithAbortSignal(refresh, callerSignal);\n\t\t} catch (error) {\n\t\t\tif (!callerSignal.aborted) throw error;\n\t\t}\n\n\t\treturn { aborted: callerSignal.aborted, errors: new Map(errors) };\n\t}\n\n\tprivate async resolveRefreshCredential(\n\t\tprovider: Provider,\n\t\tstored: Credential | undefined,\n\t\tsignal: AbortSignal,\n\t): Promise<Credential | undefined> {\n\t\tif (stored?.type === \"oauth\") {\n\t\t\tconst oauth = provider.auth.oauth;\n\t\t\tif (!oauth) return undefined;\n\t\t\tif (Date.now() < stored.expires) return stored;\n\t\t\tif (signal.aborted) return undefined;\n\t\t\tconst post = await this.credentials.modify(\n\t\t\t\tprovider.id,\n\t\t\t\tasync (current) => {\n\t\t\t\t\tif (current?.type !== \"oauth\" || Date.now() < current.expires) return undefined;\n\t\t\t\t\treturn oauth.refresh(current, signal);\n\t\t\t\t},\n\t\t\t\t{ signal },\n\t\t\t);\n\t\t\treturn post?.type === \"oauth\" ? post : undefined;\n\t\t}\n\n\t\tconst apiKey = provider.auth.apiKey;\n\t\tif (!apiKey) return undefined;\n\t\tconst credential = stored?.type === \"api_key\" ? stored : undefined;\n\t\tconst result = await apiKey.resolve({ ctx: this.authContext, credential, signal });\n\t\tif (!result) return undefined;\n\t\treturn { type: \"api_key\", key: result.auth.apiKey, env: result.env };\n\t}\n\n\tprivate async readCredential(providerId: string, signal: AbortSignal): Promise<Credential | undefined> {\n\t\ttry {\n\t\t\treturn await this.credentials.read(providerId, { signal });\n\t\t} catch (error) {\n\t\t\tthrow new ModelsError(\"auth\", `Credential store read failed for ${providerId}`, { cause: error });\n\t\t}\n\t}\n\n\tprivate async checkProviderAuth(\n\t\tprovider: Provider,\n\t\tcredential: Credential | undefined,\n\t\tsignal: AbortSignal,\n\t): Promise<AuthCheck | undefined> {\n\t\tif (credential?.type === \"oauth\") {\n\t\t\treturn provider.auth.oauth ? { source: \"OAuth\", type: \"oauth\" } : undefined;\n\t\t}\n\t\tconst apiKey = provider.auth.apiKey;\n\t\tif (!apiKey) return undefined;\n\t\tif (apiKey.check) {\n\t\t\ttry {\n\t\t\t\treturn await apiKey.check({\n\t\t\t\t\tctx: this.authContext,\n\t\t\t\t\tcredential: credential?.type === \"api_key\" ? credential : undefined,\n\t\t\t\t\tsignal,\n\t\t\t\t});\n\t\t\t} catch (error) {\n\t\t\t\tthrow new ModelsError(\"auth\", `API key auth check failed for provider ${provider.id}`, { cause: error });\n\t\t\t}\n\t\t}\n\n\t\tconst resolution = await resolveProviderAuth(provider, this.credentials, this.authContext, { signal });\n\t\treturn resolution ? { source: resolution.source, type: \"api_key\" } : undefined;\n\t}\n\n\tcheckAuth(providerId: string, options?: AuthOperationOptions): Promise<AuthCheck | undefined> {\n\t\tconst signal = operationSignal(options?.signal);\n\t\tconst check = (async () => {\n\t\t\tsignal.throwIfAborted();\n\t\t\tconst provider = this.providers.get(providerId);\n\t\t\tif (!provider) return undefined;\n\t\t\treturn this.checkProviderAuth(provider, await this.readCredential(providerId, signal), signal);\n\t\t})();\n\t\treturn raceWithAbortSignal(check, signal);\n\t}\n\n\tgetAvailable(providerId?: string, options?: AuthOperationOptions): Promise<readonly Model<Api>[]> {\n\t\tconst signal = operationSignal(options?.signal);\n\t\tconst available = (async () => {\n\t\t\tsignal.throwIfAborted();\n\t\t\tconst providers = providerId\n\t\t\t\t? [this.providers.get(providerId)].filter((entry) => entry !== undefined)\n\t\t\t\t: this.getProviders();\n\t\t\tconst checks = await Promise.all(\n\t\t\t\tproviders.map(async (provider) => {\n\t\t\t\t\tconst credential = await this.readCredential(provider.id, signal);\n\t\t\t\t\treturn { provider, credential, auth: await this.checkProviderAuth(provider, credential, signal) };\n\t\t\t\t}),\n\t\t\t);\n\t\t\treturn checks.flatMap(({ provider, credential, auth }) => {\n\t\t\t\tif (!auth) return [];\n\t\t\t\tconst models = provider.getModels();\n\t\t\t\treturn provider.filterModels?.(models, credential) ?? models;\n\t\t\t});\n\t\t})();\n\t\treturn raceWithAbortSignal(available, signal);\n\t}\n\n\tgetAuth(providerId: string, overrides?: AuthResolutionOverrides): Promise<AuthResult | undefined>;\n\tgetAuth(model: Model<Api>, overrides?: AuthResolutionOverrides): Promise<AuthResult | undefined>;\n\tasync getAuth(\n\t\tproviderOrModel: string | Model<Api>,\n\t\toverrides?: AuthResolutionOverrides,\n\t): Promise<AuthResult | undefined> {\n\t\tconst signal = operationSignal(overrides?.signal);\n\t\tconst providerId = typeof providerOrModel === \"string\" ? providerOrModel : providerOrModel.provider;\n\t\tconst provider = this.providers.get(providerId);\n\t\tif (!provider) return undefined;\n\t\tconst result = await resolveProviderAuth(provider, this.credentials, this.authContext, { ...overrides, signal });\n\t\tif (!result || typeof providerOrModel === \"string\" || !providerOrModel.headers) return result;\n\t\treturn {\n\t\t\t...result,\n\t\t\tauth: {\n\t\t\t\t...result.auth,\n\t\t\t\theaders: mergeHeaders(result.auth.headers, providerOrModel.headers),\n\t\t\t},\n\t\t};\n\t}\n\n\tasync login(providerId: string, type: AuthType, interaction: AuthInteraction): Promise<Credential> {\n\t\tconst signal = operationSignal(interaction.signal);\n\t\tsignal.throwIfAborted();\n\t\tconst provider = this.providers.get(providerId);\n\t\tif (!provider) throw new ModelsError(\"provider\", `Unknown provider: ${providerId}`);\n\t\tconst method = type === \"oauth\" ? provider.auth.oauth : provider.auth.apiKey;\n\t\tif (!method?.login) {\n\t\t\tthrow new ModelsError(\"auth\", `${provider.name} does not support ${type} login`);\n\t\t}\n\t\tconst loginOperation: Promise<Credential> = method.login({ ...interaction, signal });\n\t\tconst credential = await raceWithAbortSignal(loginOperation, signal);\n\t\tlet mutationStarted = false;\n\t\tlet markMutationStarted: (() => void) | undefined;\n\t\tconst started = new Promise<void>((resolve) => {\n\t\t\tmarkMutationStarted = resolve;\n\t\t});\n\t\tconst mutation = this.credentials.modify(\n\t\t\tproviderId,\n\t\t\tasync () => {\n\t\t\t\tmutationStarted = true;\n\t\t\t\tmarkMutationStarted?.();\n\t\t\t\treturn credential;\n\t\t\t},\n\t\t\t{ signal },\n\t\t);\n\t\tvoid mutation.catch(() => {});\n\t\ttry {\n\t\t\tawait new Promise<void>((resolve, reject) => {\n\t\t\t\tconst onAbort = () => {\n\t\t\t\t\tif (!mutationStarted) reject(signal.reason);\n\t\t\t\t};\n\t\t\t\tsignal.addEventListener(\"abort\", onAbort, { once: true });\n\t\t\t\tvoid Promise.race([started, mutation]).then(\n\t\t\t\t\t() => {\n\t\t\t\t\t\tsignal.removeEventListener(\"abort\", onAbort);\n\t\t\t\t\t\tresolve();\n\t\t\t\t\t},\n\t\t\t\t\t(error: unknown) => {\n\t\t\t\t\t\tsignal.removeEventListener(\"abort\", onAbort);\n\t\t\t\t\t\treject(error);\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t\tif (signal.aborted) onAbort();\n\t\t\t});\n\t\t\tawait mutation;\n\t\t} catch (error) {\n\t\t\tsignal.throwIfAborted();\n\t\t\tthrow new ModelsError(\"auth\", `Credential store modify failed for ${providerId}`, { cause: error });\n\t\t}\n\t\treturn credential;\n\t}\n\n\tasync logout(providerId: string, options?: AuthOperationOptions): Promise<void> {\n\t\tconst signal = operationSignal(options?.signal);\n\t\tsignal.throwIfAborted();\n\t\ttry {\n\t\t\tawait this.credentials.delete(providerId, { signal });\n\t\t} catch (error) {\n\t\t\tsignal.throwIfAborted();\n\t\t\tthrow new ModelsError(\"auth\", `Credential store delete failed for ${providerId}`, { cause: error });\n\t\t}\n\t}\n\n\tprivate requireProvider(model: Model<Api>): Provider {\n\t\tconst provider = this.providers.get(model.provider);\n\t\tif (!provider) {\n\t\t\tthrow new ModelsError(\"provider\", `Unknown provider: ${model.provider}`);\n\t\t}\n\t\treturn provider;\n\t}\n\n\tprivate async applyAuth<TOptions extends ProviderRequestOptions & ModelsRequestTransforms>(\n\t\tmodel: Model<Api>,\n\t\toptions: TOptions | undefined,\n\t): Promise<{\n\t\trequestModel: Model<Api>;\n\t\trequestOptions: Omit<TOptions, \"transformHeaders\"> & ProviderRequestOptions;\n\t}> {\n\t\tthis.requireProvider(model);\n\t\tconst resolution = await this.getAuth(model, {\n\t\t\tapiKey: options?.apiKey,\n\t\t\tenv: options?.env,\n\t\t\tsignal: options?.signal,\n\t\t});\n\t\tif (!resolution) {\n\t\t\tthrow new ModelsError(\"auth\", `Provider is not configured: ${model.provider}`);\n\t\t}\n\t\tconst auth = resolution.auth;\n\n\t\t// Explicit request options win per-field; the Models-only transform runs last.\n\t\tconst apiKey = options?.apiKey ?? auth.apiKey;\n\t\tlet headers = mergeHeaders(auth.headers, options?.headers);\n\t\tif (options?.transformHeaders) headers = await options.transformHeaders(headers ?? {});\n\t\tconst env = resolution.env || options?.env ? { ...(resolution.env ?? {}), ...(options?.env ?? {}) } : undefined;\n\t\tconst requestModel = auth.baseUrl ? { ...model, baseUrl: auth.baseUrl } : model;\n\t\tconst { transformHeaders: _transformHeaders, ...providerOptions } = options ?? {};\n\t\tconst requestOptions = { ...providerOptions, apiKey, headers, env } as Omit<TOptions, \"transformHeaders\"> &\n\t\t\tProviderRequestOptions;\n\n\t\treturn { requestModel, requestOptions };\n\t}\n\n\tstream<TApi extends Api>(\n\t\tmodel: Model<TApi>,\n\t\tcontext: Context,\n\t\toptions?: ModelsApiStreamOptions<TApi>,\n\t): AssistantMessageEventStream {\n\t\treturn lazyStream(model, async () => {\n\t\t\tconst provider = this.requireProvider(model);\n\t\t\tconst { requestModel, requestOptions } = await this.applyAuth(\n\t\t\t\tmodel,\n\t\t\t\toptions as ModelsApiStreamOptions<Api> | undefined,\n\t\t\t);\n\t\t\treturn provider.stream(requestModel as Model<TApi>, context, requestOptions as ApiStreamOptions<TApi>);\n\t\t});\n\t}\n\n\tasync complete<TApi extends Api>(\n\t\tmodel: Model<TApi>,\n\t\tcontext: Context,\n\t\toptions?: ModelsApiStreamOptions<TApi>,\n\t): Promise<AssistantMessage> {\n\t\treturn this.stream(model, context, options).result();\n\t}\n\n\tstreamSimple(model: Model<Api>, context: Context, options?: ModelsSimpleStreamOptions): AssistantMessageEventStream {\n\t\treturn lazyStream(model, async () => {\n\t\t\tconst provider = this.requireProvider(model);\n\t\t\tconst { requestModel, requestOptions } = await this.applyAuth(model, options);\n\t\t\treturn provider.streamSimple(requestModel, context, requestOptions as SimpleStreamOptions);\n\t\t});\n\t}\n\n\tasync completeSimple(\n\t\tmodel: Model<Api>,\n\t\tcontext: Context,\n\t\toptions?: ModelsSimpleStreamOptions,\n\t): Promise<AssistantMessage> {\n\t\treturn this.streamSimple(model, context, options).result();\n\t}\n\n\tasync fetchDeferred(\n\t\tmodel: Model<Api>,\n\t\thandle: DeferredHandle,\n\t\toptions?: ModelsDeferredFetchOptions,\n\t): Promise<AssistantMessage> {\n\t\treturn lazyStream(model, async () => {\n\t\t\tconst provider = this.requireProvider(model);\n\t\t\tif (!provider.fetchDeferred) {\n\t\t\t\tthrow new ModelsError(\"provider\", `Provider ${model.provider} does not support deferred responses`);\n\t\t\t}\n\t\t\tconst { requestModel, requestOptions } = await this.applyAuth(model, options);\n\t\t\treturn provider.fetchDeferred(requestModel, handle, requestOptions as DeferredFetchOptions);\n\t\t}).result();\n\t}\n\n\tasync cancelDeferred(\n\t\tmodel: Model<Api>,\n\t\thandle: DeferredHandle,\n\t\toptions?: ModelsDeferredCancelOptions,\n\t): Promise<void> {\n\t\tconst provider = this.requireProvider(model);\n\t\tif (!provider.cancelDeferred) {\n\t\t\tthrow new ModelsError(\"provider\", `Provider ${model.provider} does not support deferred responses`);\n\t\t}\n\t\tconst { requestModel, requestOptions } = await this.applyAuth(model, options);\n\t\tawait provider.cancelDeferred(requestModel, handle, requestOptions);\n\t}\n}\n\nexport function createModels(options?: CreateModelsOptions): MutableModels {\n\treturn new ModelsImpl(options);\n}\n\nexport interface CreateProviderOptions<TApi extends Api = Api> {\n\tid: string;\n\t/** Display name. Default: `id`. */\n\tname?: string;\n\tbaseUrl?: string;\n\theaders?: ProviderHeaders;\n\t/** Required — every provider has auth semantics, even ambient/keyless ones. */\n\tauth: ProviderAuth;\n\t/** Static baseline model list (empty for purely dynamic providers). */\n\tmodels: readonly Model<TApi>[];\n\t/** Fetch a dynamic model overlay. createProvider restores and publishes it transactionally. */\n\tfetchModels?: (context: RefreshModelsContext) => Promise<readonly Model<TApi>[]>;\n\tfilterModels?: (models: readonly Model<TApi>[], credential: Credential | undefined) => readonly Model<TApi>[];\n\t/** Single implementation, or map keyed by `model.api` for mixed-API providers. */\n\tapi: ProviderStreams | Partial<Record<TApi, ProviderStreams>>;\n}\n\n/**\n * Builds a provider from parts. Built-in provider factories and models.json\n * custom providers both go through this. A single `api` streams all models;\n * an `api` map dispatches on `model.api`, and a model whose api has no entry\n * produces a stream error.\n */\nexport function createProvider<TApi extends Api = Api>(input: CreateProviderOptions<TApi>): Provider<TApi> {\n\tconst baselineModels = input.models;\n\tlet dynamicModels: readonly Model<TApi>[] = [];\n\tconst fetchModels = input.fetchModels;\n\tconst currentModels = (): readonly Model<TApi>[] => {\n\t\tconst merged = [...baselineModels];\n\t\tfor (const model of dynamicModels) {\n\t\t\tconst index = merged.findIndex((entry) => entry.id === model.id);\n\t\t\tif (index >= 0) merged[index] = model;\n\t\t\telse merged.push(model);\n\t\t}\n\t\treturn merged;\n\t};\n\tconst single =\n\t\ttypeof (input.api as ProviderStreams).stream === \"function\" ? (input.api as ProviderStreams) : undefined;\n\tconst byApi = single ? undefined : (input.api as Partial<Record<string, ProviderStreams>>);\n\n\tconst apiFor = (model: Model<Api>): ProviderStreams | undefined => single ?? byApi?.[model.api];\n\n\tconst dispatch = (\n\t\tmodel: Model<Api>,\n\t\trun: (streams: ProviderStreams) => AssistantMessageEventStream,\n\t): AssistantMessageEventStream => {\n\t\tconst streams = apiFor(model);\n\t\tif (!streams) {\n\t\t\treturn lazyStream(model, async () => {\n\t\t\t\tthrow new ModelsError(\"stream\", `Provider ${input.id} has no API implementation for \"${model.api}\"`);\n\t\t\t});\n\t\t}\n\t\treturn run(streams);\n\t};\n\n\tconst provider: Provider<TApi> = {\n\t\tid: input.id,\n\t\tname: input.name ?? input.id,\n\t\tbaseUrl: input.baseUrl,\n\t\theaders: input.headers,\n\t\tauth: input.auth,\n\t\tgetModels: currentModels,\n\t\trefreshModels: fetchModels\n\t\t\t? async (context) => {\n\t\t\t\t\tif (context.stored) {\n\t\t\t\t\t\tconst restored = context.stored.models\n\t\t\t\t\t\t\t.filter((model) => model.provider === input.id)\n\t\t\t\t\t\t\t.map((model) => model as Model<TApi>);\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t!(await context.publish({\n\t\t\t\t\t\t\t\tupdate: () => {\n\t\t\t\t\t\t\t\t\tdynamicModels = restored;\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t}))\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (!context.allowNetwork || context.signal.aborted) return;\n\t\t\t\t\tconst refreshed = await fetchModels(context);\n\t\t\t\t\tif (context.signal.aborted) return;\n\t\t\t\t\tawait context.publish({\n\t\t\t\t\t\tpersist: { models: refreshed, checkedAt: Date.now() },\n\t\t\t\t\t\tupdate: () => {\n\t\t\t\t\t\t\tdynamicModels = refreshed;\n\t\t\t\t\t\t},\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t: undefined,\n\t\tfilterModels: input.filterModels,\n\t\tstream: (model, context, options) => dispatch(model, (streams) => streams.stream(model, context, options)),\n\t\tstreamSimple: (model, context, options) =>\n\t\t\tdispatch(model, (streams) => streams.streamSimple(model, context, options)),\n\t};\n\n\tconst streams = single ? [single] : Object.values(byApi ?? {}).filter((entry) => entry !== undefined);\n\tif (streams.some((entry) => entry.fetchDeferred !== undefined)) {\n\t\tprovider.fetchDeferred = (model, handle, options) =>\n\t\t\tlazyStream(model, async () => {\n\t\t\t\tconst implementation = apiFor(model);\n\t\t\t\tif (!implementation?.fetchDeferred) {\n\t\t\t\t\tthrow new ModelsError(\n\t\t\t\t\t\t\"provider\",\n\t\t\t\t\t\t`Provider ${input.id} does not support deferred responses for \"${model.api}\"`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\treturn implementation.fetchDeferred(model, handle, options);\n\t\t\t});\n\t}\n\tif (streams.some((entry) => entry.cancelDeferred !== undefined)) {\n\t\tprovider.cancelDeferred = async (model, handle, options) => {\n\t\t\tconst implementation = apiFor(model);\n\t\t\tif (!implementation?.cancelDeferred) {\n\t\t\t\tthrow new ModelsError(\n\t\t\t\t\t\"provider\",\n\t\t\t\t\t`Provider ${input.id} cannot cancel deferred responses for \"${model.api}\"`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tawait implementation.cancelDeferred(model, handle, options);\n\t\t};\n\t}\n\n\treturn provider;\n}\n\n/**\n * Runtime-checked narrowing for dynamically looked-up models:\n *\n * ```ts\n * const model = models.getModel(\"anthropic\", \"claude-opus-4-7\");\n * if (model && hasApi(model, \"anthropic-messages\")) {\n * // model: Model<\"anthropic-messages\">, stream options fully typed\n * }\n * ```\n */\nexport function hasApi<TApi extends Api>(model: Model<Api>, api: TApi): model is Model<TApi> {\n\treturn model.api === api;\n}\n\nexport function calculateCost<TApi extends Api>(model: Model<TApi>, usage: Usage): Usage[\"cost\"] {\n\tconst inputTokens = usage.input + usage.cacheRead + usage.cacheWrite;\n\tlet rates: ModelCostRates = model.cost;\n\tlet matchedThreshold = -1;\n\tfor (const tier of model.cost.tiers ?? []) {\n\t\tif (inputTokens > tier.inputTokensAbove && tier.inputTokensAbove > matchedThreshold) {\n\t\t\trates = tier;\n\t\t\tmatchedThreshold = tier.inputTokensAbove;\n\t\t}\n\t}\n\n\t// Anthropic charges 2x base input for 1h cache writes.\n\tconst longWrite = usage.cacheWrite1h ?? 0;\n\tconst shortWrite = usage.cacheWrite - longWrite;\n\tusage.cost.input = (rates.input / 1000000) * usage.input;\n\tusage.cost.output = (rates.output / 1000000) * usage.output;\n\tusage.cost.cacheRead = (rates.cacheRead / 1000000) * usage.cacheRead;\n\tusage.cost.cacheWrite = (rates.cacheWrite * shortWrite + rates.input * 2 * longWrite) / 1000000;\n\tusage.cost.total = usage.cost.input + usage.cost.output + usage.cost.cacheRead + usage.cost.cacheWrite;\n\treturn usage.cost;\n}\n\nconst EXTENDED_THINKING_LEVELS: ModelThinkingLevel[] = [\"off\", \"minimal\", \"low\", \"medium\", \"high\", \"xhigh\", \"max\"];\n\nexport function getSupportedThinkingLevels<TApi extends Api>(model: Model<TApi>): ModelThinkingLevel[] {\n\tif (!model.reasoning) return [\"off\"];\n\n\treturn EXTENDED_THINKING_LEVELS.filter((level) => {\n\t\tconst mapped = model.thinkingLevelMap?.[level];\n\t\tif (mapped === null) return false;\n\t\tif (level === \"xhigh\" || level === \"max\") return mapped !== undefined;\n\t\treturn true;\n\t});\n}\n\nexport function clampThinkingLevel<TApi extends Api>(\n\tmodel: Model<TApi>,\n\tlevel: ModelThinkingLevel,\n): ModelThinkingLevel {\n\tconst availableLevels = getSupportedThinkingLevels(model);\n\tif (availableLevels.includes(level)) return level;\n\n\tconst requestedIndex = EXTENDED_THINKING_LEVELS.indexOf(level);\n\tif (requestedIndex === -1) return availableLevels[0] ?? \"off\";\n\n\tfor (let i = requestedIndex; i < EXTENDED_THINKING_LEVELS.length; i++) {\n\t\tconst candidate = EXTENDED_THINKING_LEVELS[i];\n\t\tif (availableLevels.includes(candidate)) return candidate;\n\t}\n\tfor (let i = requestedIndex - 1; i >= 0; i--) {\n\t\tconst candidate = EXTENDED_THINKING_LEVELS[i];\n\t\tif (availableLevels.includes(candidate)) return candidate;\n\t}\n\treturn availableLevels[0] ?? \"off\";\n}\n\n/**\n * Check if two models are equal by comparing both their id and provider.\n * Returns false if either model is null or undefined.\n */\nexport function modelsAreEqual<TApi extends Api>(\n\ta: Model<TApi> | null | undefined,\n\tb: Model<TApi> | null | undefined,\n): boolean {\n\tif (!a || !b) return false;\n\treturn a.id === b.id && a.provider === b.provider;\n}\n"]}
|