@dc99-tech/pi-ai 0.0.0-stage → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2088 -2
- 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 +1461 -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-config.d.ts +15 -0
- package/dist/api/azure-openai-config.d.ts.map +1 -0
- package/dist/api/azure-openai-config.js +76 -0
- package/dist/api/azure-openai-config.js.map +1 -0
- package/dist/api/azure-openai-responses.d.ts +14 -0
- package/dist/api/azure-openai-responses.d.ts.map +1 -0
- package/dist/api/azure-openai-responses.js +184 -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 +1202 -0
- package/dist/api/bedrock-converse-stream.js.map +1 -0
- package/dist/api/bedrock-converse-stream.lazy.d.ts +16 -0
- package/dist/api/bedrock-converse-stream.lazy.d.ts.map +1 -0
- package/dist/api/bedrock-converse-stream.lazy.js +43 -0
- package/dist/api/bedrock-converse-stream.lazy.js.map +1 -0
- package/dist/api/classifier-shared.d.ts +20 -0
- package/dist/api/classifier-shared.d.ts.map +1 -0
- package/dist/api/classifier-shared.js +46 -0
- package/dist/api/classifier-shared.js.map +1 -0
- package/dist/api/cloudflare-ai-binding.d.ts +77 -0
- package/dist/api/cloudflare-ai-binding.d.ts.map +1 -0
- package/dist/api/cloudflare-ai-binding.js +72 -0
- package/dist/api/cloudflare-ai-binding.js.map +1 -0
- package/dist/api/cloudflare-workers-ai-system-one.d.ts +4 -0
- package/dist/api/cloudflare-workers-ai-system-one.d.ts.map +1 -0
- package/dist/api/cloudflare-workers-ai-system-one.js +57 -0
- package/dist/api/cloudflare-workers-ai-system-one.js.map +1 -0
- package/dist/api/cloudflare-workers-ai-system-one.lazy.d.ts +3 -0
- package/dist/api/cloudflare-workers-ai-system-one.lazy.d.ts.map +1 -0
- package/dist/api/cloudflare-workers-ai-system-one.lazy.js +4 -0
- package/dist/api/cloudflare-workers-ai-system-one.lazy.js.map +1 -0
- package/dist/api/cloudflare.d.ts +11 -0
- package/dist/api/cloudflare.d.ts.map +1 -0
- package/dist/api/cloudflare.js +11 -0
- package/dist/api/cloudflare.js.map +1 -0
- package/dist/api/constrained-sampling.d.ts +38 -0
- package/dist/api/constrained-sampling.d.ts.map +1 -0
- package/dist/api/constrained-sampling.js +257 -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 +339 -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 +98 -0
- package/dist/api/google-shared.d.ts.map +1 -0
- package/dist/api/google-shared.js +562 -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 +412 -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/json-request.d.ts +20 -0
- package/dist/api/json-request.d.ts.map +1 -0
- package/dist/api/json-request.js +119 -0
- package/dist/api/json-request.js.map +1 -0
- package/dist/api/lazy.d.ts +24 -0
- package/dist/api/lazy.d.ts.map +1 -0
- package/dist/api/lazy.js +91 -0
- package/dist/api/lazy.js.map +1 -0
- package/dist/api/llama-cpp-classify.d.ts +33 -0
- package/dist/api/llama-cpp-classify.d.ts.map +1 -0
- package/dist/api/llama-cpp-classify.js +368 -0
- package/dist/api/llama-cpp-classify.js.map +1 -0
- package/dist/api/llama-cpp-classify.lazy.d.ts +3 -0
- package/dist/api/llama-cpp-classify.lazy.d.ts.map +1 -0
- package/dist/api/llama-cpp-classify.lazy.js +4 -0
- package/dist/api/llama-cpp-classify.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 +719 -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 +1323 -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-reasoning.d.ts +62 -0
- package/dist/api/openai-completions-reasoning.d.ts.map +1 -0
- package/dist/api/openai-completions-reasoning.js +144 -0
- package/dist/api/openai-completions-reasoning.js.map +1 -0
- package/dist/api/openai-completions.d.ts +27 -0
- package/dist/api/openai-completions.d.ts.map +1 -0
- package/dist/api/openai-completions.js +1318 -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-decisions.d.ts +4 -0
- package/dist/api/openai-decisions.d.ts.map +1 -0
- package/dist/api/openai-decisions.js +162 -0
- package/dist/api/openai-decisions.js.map +1 -0
- package/dist/api/openai-decisions.lazy.d.ts +3 -0
- package/dist/api/openai-decisions.lazy.d.ts.map +1 -0
- package/dist/api/openai-decisions.lazy.js +4 -0
- package/dist/api/openai-decisions.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 +63 -0
- package/dist/api/openai-responses-shared.d.ts.map +1 -0
- package/dist/api/openai-responses-shared.js +824 -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 +331 -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-chat-images.d.ts +4 -0
- package/dist/api/openrouter-chat-images.d.ts.map +1 -0
- package/dist/api/openrouter-chat-images.js +94 -0
- package/dist/api/openrouter-chat-images.js.map +1 -0
- package/dist/api/openrouter-chat-images.lazy.d.ts +3 -0
- package/dist/api/openrouter-chat-images.lazy.d.ts.map +1 -0
- package/dist/api/openrouter-chat-images.lazy.js +4 -0
- package/dist/api/openrouter-chat-images.lazy.js.map +1 -0
- package/dist/api/openrouter-images-shared.d.ts +9 -0
- package/dist/api/openrouter-images-shared.d.ts.map +1 -0
- package/dist/api/openrouter-images-shared.js +69 -0
- package/dist/api/openrouter-images-shared.js.map +1 -0
- package/dist/api/openrouter-images.d.ts +4 -0
- package/dist/api/openrouter-images.d.ts.map +1 -0
- package/dist/api/openrouter-images.js +91 -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-decision.d.ts +22 -0
- package/dist/api/pi-decision.d.ts.map +1 -0
- package/dist/api/pi-decision.js +120 -0
- package/dist/api/pi-decision.js.map +1 -0
- package/dist/api/pi-decision.lazy.d.ts +3 -0
- package/dist/api/pi-decision.lazy.d.ts.map +1 -0
- package/dist/api/pi-decision.lazy.js +4 -0
- package/dist/api/pi-decision.lazy.js.map +1 -0
- package/dist/api/pi-image.d.ts +25 -0
- package/dist/api/pi-image.d.ts.map +1 -0
- package/dist/api/pi-image.js +82 -0
- package/dist/api/pi-image.js.map +1 -0
- package/dist/api/pi-image.lazy.d.ts +3 -0
- package/dist/api/pi-image.lazy.d.ts.map +1 -0
- package/dist/api/pi-image.lazy.js +4 -0
- package/dist/api/pi-image.lazy.js.map +1 -0
- package/dist/api/pi-messages.d.ts +101 -0
- package/dist/api/pi-messages.d.ts.map +1 -0
- package/dist/api/pi-messages.js +312 -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 +17 -0
- package/dist/api/simple-options.d.ts.map +1 -0
- package/dist/api/simple-options.js +88 -0
- package/dist/api/simple-options.js.map +1 -0
- package/dist/api/strict-tool-limits.d.ts +13 -0
- package/dist/api/strict-tool-limits.d.ts.map +1 -0
- package/dist/api/strict-tool-limits.js +50 -0
- package/dist/api/strict-tool-limits.js.map +1 -0
- package/dist/api/system-one-shared.d.ts +49 -0
- package/dist/api/system-one-shared.d.ts.map +1 -0
- package/dist/api/system-one-shared.js +158 -0
- package/dist/api/system-one-shared.js.map +1 -0
- package/dist/api/transform-messages.d.ts +23 -0
- package/dist/api/transform-messages.d.ts.map +1 -0
- package/dist/api/transform-messages.js +214 -0
- package/dist/api/transform-messages.js.map +1 -0
- package/dist/api/typesafe-system-one.d.ts +4 -0
- package/dist/api/typesafe-system-one.d.ts.map +1 -0
- package/dist/api/typesafe-system-one.js +30 -0
- package/dist/api/typesafe-system-one.js.map +1 -0
- package/dist/api/typesafe-system-one.lazy.d.ts +3 -0
- package/dist/api/typesafe-system-one.lazy.d.ts.map +1 -0
- package/dist/api/typesafe-system-one.lazy.js +4 -0
- package/dist/api/typesafe-system-one.lazy.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 +257 -0
- package/dist/auth/oauth/anthropic.js.map +1 -0
- package/dist/auth/oauth/callback-server.d.ts +55 -0
- package/dist/auth/oauth/callback-server.d.ts.map +1 -0
- package/dist/auth/oauth/callback-server.js +151 -0
- package/dist/auth/oauth/callback-server.js.map +1 -0
- package/dist/auth/oauth/device-code.d.ts +24 -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 +389 -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 +230 -0
- package/dist/auth/oauth/kimi-coding.js.map +1 -0
- package/dist/auth/oauth/load.d.ts +31 -0
- package/dist/auth/oauth/load.d.ts.map +1 -0
- package/dist/auth/oauth/load.js +72 -0
- package/dist/auth/oauth/load.js.map +1 -0
- package/dist/auth/oauth/meta.d.ts +17 -0
- package/dist/auth/oauth/meta.d.ts.map +1 -0
- package/dist/auth/oauth/meta.js +177 -0
- package/dist/auth/oauth/meta.js.map +1 -0
- package/dist/auth/oauth/openai-chatgpt.d.ts +9 -0
- package/dist/auth/oauth/openai-chatgpt.d.ts.map +1 -0
- package/dist/auth/oauth/openai-chatgpt.js +262 -0
- package/dist/auth/oauth/openai-chatgpt.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 +346 -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 +158 -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 +259 -0
- package/dist/auth/oauth/radius.js.map +1 -0
- package/dist/auth/oauth/trusted-url.d.ts +7 -0
- package/dist/auth/oauth/trusted-url.d.ts.map +1 -0
- package/dist/auth/oauth/trusted-url.js +12 -0
- package/dist/auth/oauth/trusted-url.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 +36 -0
- package/dist/auth/resolve.d.ts.map +1 -0
- package/dist/auth/resolve.js +140 -0
- package/dist/auth/resolve.js.map +1 -0
- package/dist/auth/types.d.ts +249 -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 +25 -0
- package/dist/bun-oauth.js.map +1 -0
- package/dist/cache-warming.d.ts +53 -0
- package/dist/cache-warming.d.ts.map +1 -0
- package/dist/cache-warming.js +82 -0
- package/dist/cache-warming.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +119 -0
- package/dist/cli.js.map +1 -0
- package/dist/compat/extension-oauth-types.d.ts +43 -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 +202 -0
- package/dist/compat.js.map +1 -0
- package/dist/env-api-keys.d.ts +26 -0
- package/dist/env-api-keys.d.ts.map +1 -0
- package/dist/env-api-keys.js +165 -0
- package/dist/env-api-keys.js.map +1 -0
- package/dist/image-models.d.ts +21 -0
- package/dist/image-models.d.ts.map +1 -0
- package/dist/image-models.js +24 -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.d.ts +9 -0
- package/dist/images.d.ts.map +1 -0
- package/dist/images.js +19 -0
- package/dist/images.js.map +1 -0
- package/dist/index.d.ts +39 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +25 -0
- package/dist/index.js.map +1 -0
- package/dist/lazy-bedrock-provider.d.ts +10 -0
- package/dist/lazy-bedrock-provider.d.ts.map +1 -0
- package/dist/lazy-bedrock-provider.js +13 -0
- package/dist/lazy-bedrock-provider.js.map +1 -0
- package/dist/lazy-oauth.d.ts +10 -0
- package/dist/lazy-oauth.d.ts.map +1 -0
- package/dist/lazy-oauth.js +23 -0
- package/dist/lazy-oauth.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 +33 -0
- package/dist/model-catalog.d.ts.map +1 -0
- package/dist/model-catalog.js +16 -0
- package/dist/model-catalog.js.map +1 -0
- package/dist/models-store.d.ts +30 -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 +284 -0
- package/dist/models.d.ts.map +1 -0
- package/dist/models.generated.d.ts +179 -0
- package/dist/models.generated.d.ts.map +1 -0
- package/dist/models.generated.js +181 -0
- package/dist/models.generated.js.map +1 -0
- package/dist/models.js +756 -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 +34 -0
- package/dist/providers/all.d.ts.map +1 -0
- package/dist/providers/all.js +139 -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 +6 -0
- package/dist/providers/amazon-bedrock.models.d.ts.map +1 -0
- package/dist/providers/amazon-bedrock.models.js +8 -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 +6 -0
- package/dist/providers/ant-ling.models.d.ts.map +1 -0
- package/dist/providers/ant-ling.models.js +8 -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 +78 -0
- package/dist/providers/anthropic.js.map +1 -0
- package/dist/providers/anthropic.models.d.ts +6 -0
- package/dist/providers/anthropic.models.d.ts.map +1 -0
- package/dist/providers/anthropic.models.js +8 -0
- package/dist/providers/anthropic.models.js.map +1 -0
- package/dist/providers/azure.d.ts +3 -0
- package/dist/providers/azure.d.ts.map +1 -0
- package/dist/providers/azure.js +46 -0
- package/dist/providers/azure.js.map +1 -0
- package/dist/providers/azure.models.d.ts +6 -0
- package/dist/providers/azure.models.d.ts.map +1 -0
- package/dist/providers/azure.models.js +8 -0
- package/dist/providers/azure.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 +21 -0
- package/dist/providers/baseten.js.map +1 -0
- package/dist/providers/baseten.models.d.ts +6 -0
- package/dist/providers/baseten.models.d.ts.map +1 -0
- package/dist/providers/baseten.models.js +8 -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 +6 -0
- package/dist/providers/cerebras.models.d.ts.map +1 -0
- package/dist/providers/cerebras.models.js +8 -0
- package/dist/providers/cerebras.models.js.map +1 -0
- package/dist/providers/cloudflare-ai-gateway.d.ts +5 -0
- package/dist/providers/cloudflare-ai-gateway.d.ts.map +1 -0
- package/dist/providers/cloudflare-ai-gateway.js +25 -0
- package/dist/providers/cloudflare-ai-gateway.js.map +1 -0
- package/dist/providers/cloudflare-ai-gateway.models.d.ts +6 -0
- package/dist/providers/cloudflare-ai-gateway.models.d.ts.map +1 -0
- package/dist/providers/cloudflare-ai-gateway.models.js +8 -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 +12 -0
- package/dist/providers/cloudflare-stream.d.ts.map +1 -0
- package/dist/providers/cloudflare-stream.js +27 -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 +22 -0
- package/dist/providers/cloudflare-workers-ai.js.map +1 -0
- package/dist/providers/cloudflare-workers-ai.models.d.ts +6 -0
- package/dist/providers/cloudflare-workers-ai.models.d.ts.map +1 -0
- package/dist/providers/cloudflare-workers-ai.models.js +8 -0
- package/dist/providers/cloudflare-workers-ai.models.js.map +1 -0
- package/dist/providers/compat-schema.d.ts +518 -0
- package/dist/providers/compat-schema.d.ts.map +1 -0
- package/dist/providers/compat-schema.js +471 -0
- package/dist/providers/compat-schema.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.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/meta.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-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/radius.json +1 -0
- package/dist/providers/data/together.json +1 -0
- package/dist/providers/data/typesafe.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 +6 -0
- package/dist/providers/deepseek.models.d.ts.map +1 -0
- package/dist/providers/deepseek.models.js +8 -0
- package/dist/providers/deepseek.models.js.map +1 -0
- package/dist/providers/faux.d.ts +103 -0
- package/dist/providers/faux.d.ts.map +1 -0
- package/dist/providers/faux.js +511 -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 +6 -0
- package/dist/providers/fireworks.models.d.ts.map +1 -0
- package/dist/providers/fireworks.models.js +8 -0
- package/dist/providers/fireworks.models.js.map +1 -0
- package/dist/providers/github-copilot.d.ts +5 -0
- package/dist/providers/github-copilot.d.ts.map +1 -0
- package/dist/providers/github-copilot.js +67 -0
- package/dist/providers/github-copilot.js.map +1 -0
- package/dist/providers/github-copilot.models.d.ts +6 -0
- package/dist/providers/github-copilot.models.d.ts.map +1 -0
- package/dist/providers/github-copilot.models.js +8 -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 +6 -0
- package/dist/providers/google-vertex.models.d.ts.map +1 -0
- package/dist/providers/google-vertex.models.js +8 -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 +6 -0
- package/dist/providers/google.models.d.ts.map +1 -0
- package/dist/providers/google.models.js +8 -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 +6 -0
- package/dist/providers/groq.models.d.ts.map +1 -0
- package/dist/providers/groq.models.js +8 -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 +6 -0
- package/dist/providers/huggingface.models.d.ts.map +1 -0
- package/dist/providers/huggingface.models.js +8 -0
- package/dist/providers/huggingface.models.js.map +1 -0
- package/dist/providers/images/register-builtins.d.ts +5 -0
- package/dist/providers/images/register-builtins.d.ts.map +1 -0
- package/dist/providers/images/register-builtins.js +52 -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 +6 -0
- package/dist/providers/kimi-coding.models.d.ts.map +1 -0
- package/dist/providers/kimi-coding.models.js +8 -0
- package/dist/providers/kimi-coding.models.js.map +1 -0
- package/dist/providers/meta.d.ts +3 -0
- package/dist/providers/meta.d.ts.map +1 -0
- package/dist/providers/meta.js +24 -0
- package/dist/providers/meta.js.map +1 -0
- package/dist/providers/meta.models.d.ts +6 -0
- package/dist/providers/meta.models.d.ts.map +1 -0
- package/dist/providers/meta.models.js +8 -0
- package/dist/providers/meta.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 +6 -0
- package/dist/providers/minimax-cn.models.d.ts.map +1 -0
- package/dist/providers/minimax-cn.models.js +8 -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 +6 -0
- package/dist/providers/minimax.models.d.ts.map +1 -0
- package/dist/providers/minimax.models.js +8 -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 +6 -0
- package/dist/providers/mistral.models.d.ts.map +1 -0
- package/dist/providers/mistral.models.js +8 -0
- package/dist/providers/mistral.models.js.map +1 -0
- package/dist/providers/model-schema.d.ts +92 -0
- package/dist/providers/model-schema.d.ts.map +1 -0
- package/dist/providers/model-schema.js +71 -0
- package/dist/providers/model-schema.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 +6 -0
- package/dist/providers/moonshotai-cn.models.d.ts.map +1 -0
- package/dist/providers/moonshotai-cn.models.js +8 -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 +6 -0
- package/dist/providers/moonshotai.models.d.ts.map +1 -0
- package/dist/providers/moonshotai.models.js +8 -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 +6 -0
- package/dist/providers/nvidia.models.d.ts.map +1 -0
- package/dist/providers/nvidia.models.js +8 -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 +6 -0
- package/dist/providers/openai-codex.models.d.ts.map +1 -0
- package/dist/providers/openai-codex.models.js +8 -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 +33 -0
- package/dist/providers/openai.js.map +1 -0
- package/dist/providers/openai.models.d.ts +6 -0
- package/dist/providers/openai.models.d.ts.map +1 -0
- package/dist/providers/openai.models.js +8 -0
- package/dist/providers/openai.models.js.map +1 -0
- package/dist/providers/opencode-go.d.ts +5 -0
- package/dist/providers/opencode-go.d.ts.map +1 -0
- package/dist/providers/opencode-go.js +29 -0
- package/dist/providers/opencode-go.js.map +1 -0
- package/dist/providers/opencode-go.models.d.ts +6 -0
- package/dist/providers/opencode-go.models.d.ts.map +1 -0
- package/dist/providers/opencode-go.models.js +8 -0
- package/dist/providers/opencode-go.models.js.map +1 -0
- package/dist/providers/opencode-headers.d.ts +4 -0
- package/dist/providers/opencode-headers.d.ts.map +1 -0
- package/dist/providers/opencode-headers.js +22 -0
- package/dist/providers/opencode-headers.js.map +1 -0
- package/dist/providers/opencode.d.ts +5 -0
- package/dist/providers/opencode.d.ts.map +1 -0
- package/dist/providers/opencode.js +26 -0
- package/dist/providers/opencode.js.map +1 -0
- package/dist/providers/opencode.models.d.ts +6 -0
- package/dist/providers/opencode.models.d.ts.map +1 -0
- package/dist/providers/opencode.models.js +8 -0
- package/dist/providers/opencode.models.js.map +1 -0
- package/dist/providers/openrouter-api.d.ts +47 -0
- package/dist/providers/openrouter-api.d.ts.map +1 -0
- package/dist/providers/openrouter-api.js +51 -0
- package/dist/providers/openrouter-api.js.map +1 -0
- package/dist/providers/openrouter.d.ts +13 -0
- package/dist/providers/openrouter.d.ts.map +1 -0
- package/dist/providers/openrouter.js +91 -0
- package/dist/providers/openrouter.js.map +1 -0
- package/dist/providers/openrouter.models.d.ts +6 -0
- package/dist/providers/openrouter.models.d.ts.map +1 -0
- package/dist/providers/openrouter.models.js +8 -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 +20 -0
- package/dist/providers/qwen-token-plan-cn.js.map +1 -0
- package/dist/providers/qwen-token-plan-cn.models.d.ts +6 -0
- package/dist/providers/qwen-token-plan-cn.models.d.ts.map +1 -0
- package/dist/providers/qwen-token-plan-cn.models.js +8 -0
- package/dist/providers/qwen-token-plan-cn.models.js.map +1 -0
- package/dist/providers/qwen-token-plan-individual-cn.d.ts +3 -0
- package/dist/providers/qwen-token-plan-individual-cn.d.ts.map +1 -0
- package/dist/providers/qwen-token-plan-individual-cn.js +20 -0
- package/dist/providers/qwen-token-plan-individual-cn.js.map +1 -0
- package/dist/providers/qwen-token-plan-individual-cn.models.d.ts +6 -0
- package/dist/providers/qwen-token-plan-individual-cn.models.d.ts.map +1 -0
- package/dist/providers/qwen-token-plan-individual-cn.models.js +8 -0
- package/dist/providers/qwen-token-plan-individual-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 +20 -0
- package/dist/providers/qwen-token-plan-individual.js.map +1 -0
- package/dist/providers/qwen-token-plan-individual.models.d.ts +6 -0
- package/dist/providers/qwen-token-plan-individual.models.d.ts.map +1 -0
- package/dist/providers/qwen-token-plan-individual.models.js +8 -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 +20 -0
- package/dist/providers/qwen-token-plan.js.map +1 -0
- package/dist/providers/qwen-token-plan.models.d.ts +6 -0
- package/dist/providers/qwen-token-plan.models.d.ts.map +1 -0
- package/dist/providers/qwen-token-plan.models.js +8 -0
- package/dist/providers/qwen-token-plan.models.js.map +1 -0
- package/dist/providers/radius-config.d.ts +45 -0
- package/dist/providers/radius-config.d.ts.map +1 -0
- package/dist/providers/radius-config.js +121 -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 +83 -0
- package/dist/providers/radius.js.map +1 -0
- package/dist/providers/radius.models.d.ts +6 -0
- package/dist/providers/radius.models.d.ts.map +1 -0
- package/dist/providers/radius.models.js +8 -0
- package/dist/providers/radius.models.js.map +1 -0
- package/dist/providers/schema-builders.d.ts +10 -0
- package/dist/providers/schema-builders.d.ts.map +1 -0
- package/dist/providers/schema-builders.js +18 -0
- package/dist/providers/schema-builders.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 +6 -0
- package/dist/providers/together.models.d.ts.map +1 -0
- package/dist/providers/together.models.js +8 -0
- package/dist/providers/together.models.js.map +1 -0
- package/dist/providers/typesafe.d.ts +3 -0
- package/dist/providers/typesafe.d.ts.map +1 -0
- package/dist/providers/typesafe.js +18 -0
- package/dist/providers/typesafe.js.map +1 -0
- package/dist/providers/typesafe.models.d.ts +6 -0
- package/dist/providers/typesafe.models.d.ts.map +1 -0
- package/dist/providers/typesafe.models.js +8 -0
- package/dist/providers/typesafe.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 +18 -0
- package/dist/providers/vercel-ai-gateway.js.map +1 -0
- package/dist/providers/vercel-ai-gateway.models.d.ts +6 -0
- package/dist/providers/vercel-ai-gateway.models.d.ts.map +1 -0
- package/dist/providers/vercel-ai-gateway.models.js +8 -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 +24 -0
- package/dist/providers/xai.js.map +1 -0
- package/dist/providers/xai.models.d.ts +6 -0
- package/dist/providers/xai.models.d.ts.map +1 -0
- package/dist/providers/xai.models.js +8 -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 +6 -0
- package/dist/providers/xiaomi-token-plan-ams.models.d.ts.map +1 -0
- package/dist/providers/xiaomi-token-plan-ams.models.js +8 -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 +6 -0
- package/dist/providers/xiaomi-token-plan-cn.models.d.ts.map +1 -0
- package/dist/providers/xiaomi-token-plan-cn.models.js +8 -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 +6 -0
- package/dist/providers/xiaomi-token-plan-sgp.models.d.ts.map +1 -0
- package/dist/providers/xiaomi-token-plan-sgp.models.js +8 -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 +6 -0
- package/dist/providers/xiaomi.models.d.ts.map +1 -0
- package/dist/providers/xiaomi.models.js +8 -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 +6 -0
- package/dist/providers/zai-coding-cn.models.d.ts.map +1 -0
- package/dist/providers/zai-coding-cn.models.js +8 -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 +6 -0
- package/dist/providers/zai.models.d.ts.map +1 -0
- package/dist/providers/zai.models.js +8 -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/telemetry.d.ts +39 -0
- package/dist/telemetry.d.ts.map +1 -0
- package/dist/telemetry.js +113 -0
- package/dist/telemetry.js.map +1 -0
- package/dist/types.d.ts +729 -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/diagnostics.d.ts +20 -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 +33 -0
- package/dist/utils/error-body.d.ts.map +1 -0
- package/dist/utils/error-body.js +161 -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 +95 -0
- package/dist/utils/estimate.js.map +1 -0
- package/dist/utils/event-stream.d.ts +30 -0
- package/dist/utils/event-stream.d.ts.map +1 -0
- package/dist/utils/event-stream.js +124 -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 +20 -0
- package/dist/utils/headers.js.map +1 -0
- package/dist/utils/identity.d.ts +65 -0
- package/dist/utils/identity.d.ts.map +1 -0
- package/dist/utils/identity.js +141 -0
- package/dist/utils/identity.js.map +1 -0
- package/dist/utils/json-parse.d.ts +26 -0
- package/dist/utils/json-parse.d.ts.map +1 -0
- package/dist/utils/json-parse.js +138 -0
- package/dist/utils/json-parse.js.map +1 -0
- package/dist/utils/model-operations.d.ts +13 -0
- package/dist/utils/model-operations.d.ts.map +1 -0
- package/dist/utils/model-operations.js +53 -0
- package/dist/utils/model-operations.js.map +1 -0
- package/dist/utils/models-error.d.ts +8 -0
- package/dist/utils/models-error.d.ts.map +1 -0
- package/dist/utils/models-error.js +19 -0
- package/dist/utils/models-error.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 +133 -0
- package/dist/utils/node-http-proxy.js.map +1 -0
- package/dist/utils/oauth-page.d.ts +3 -0
- package/dist/utils/oauth-page.d.ts.map +1 -0
- package/dist/utils/oauth-page.js +105 -0
- package/dist/utils/oauth-page.js.map +1 -0
- package/dist/utils/openrouter-cost.d.ts +25 -0
- package/dist/utils/openrouter-cost.d.ts.map +1 -0
- package/dist/utils/openrouter-cost.js +35 -0
- package/dist/utils/openrouter-cost.js.map +1 -0
- package/dist/utils/openrouter-finish-reason.d.ts +22 -0
- package/dist/utils/openrouter-finish-reason.d.ts.map +1 -0
- package/dist/utils/openrouter-finish-reason.js +41 -0
- package/dist/utils/openrouter-finish-reason.js.map +1 -0
- package/dist/utils/overflow.d.ts +71 -0
- package/dist/utils/overflow.d.ts.map +1 -0
- package/dist/utils/overflow.js +189 -0
- package/dist/utils/overflow.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 +24 -0
- package/dist/utils/provider-retry.d.ts.map +1 -0
- package/dist/utils/provider-retry.js +102 -0
- package/dist/utils/provider-retry.js.map +1 -0
- package/dist/utils/retry.d.ts +58 -0
- package/dist/utils/retry.d.ts.map +1 -0
- package/dist/utils/retry.js +269 -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/sleep.d.ts +2 -0
- package/dist/utils/sleep.d.ts.map +1 -0
- package/dist/utils/sleep.js +15 -0
- package/dist/utils/sleep.js.map +1 -0
- package/dist/utils/sse.d.ts +29 -0
- package/dist/utils/sse.d.ts.map +1 -0
- package/dist/utils/sse.js +85 -0
- package/dist/utils/sse.js.map +1 -0
- package/dist/utils/streaming-json.d.ts +84 -0
- package/dist/utils/streaming-json.d.ts.map +1 -0
- package/dist/utils/streaming-json.js +513 -0
- package/dist/utils/streaming-json.js.map +1 -0
- package/dist/utils/string-enum.d.ts +17 -0
- package/dist/utils/string-enum.d.ts.map +1 -0
- package/dist/utils/string-enum.js +20 -0
- package/dist/utils/string-enum.js.map +1 -0
- package/dist/utils/text.d.ts +21 -0
- package/dist/utils/text.d.ts.map +1 -0
- package/dist/utils/text.js +45 -0
- package/dist/utils/text.js.map +1 -0
- package/dist/utils/transcript.d.ts +101 -0
- package/dist/utils/transcript.d.ts.map +1 -0
- package/dist/utils/transcript.js +218 -0
- package/dist/utils/transcript.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 +42 -0
- package/dist/utils/uuid.js.map +1 -0
- package/dist/utils/validation.d.ts +20 -0
- package/dist/utils/validation.d.ts.map +1 -0
- package/dist/utils/validation.js +62 -0
- package/dist/utils/validation.js.map +1 -0
- package/dist/utils/version.d.ts +2 -0
- package/dist/utils/version.d.ts.map +1 -0
- package/dist/utils/version.js +3 -0
- package/dist/utils/version.js.map +1 -0
- package/package.json +118 -5
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openrouter-cost.js","sourceRoot":"","sources":["../../src/utils/openrouter-cost.ts"],"names":[],"mappings":"AAmBA,SAAS,WAAW,CAAC,KAAc;IAClC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC;AAC1E,CAAC;AAED,gHAAgH;AAChH,MAAM,UAAU,iBAAiB,CAAC,KAA4C;IAC7E,OAAO,KAAK,CAAC,QAAQ,KAAK,YAAY,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAC,CAAC;AACnF,CAAC;AAED,qHAAqH;AACrH,MAAM,UAAU,2BAA2B,CAAC,KAAY,EAAE,QAAmC;IAC5F,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,IAAI,CAAC;QAAE,OAAO;IAExC,IAAI,QAAQ,CAAC,OAAO,KAAK,KAAK,EAAE,CAAC;QAChC,KAAK,CAAC,IAAI,CAAC,KAAK,GAAG,QAAQ,CAAC,IAAI,CAAC;QACjC,KAAK,CAAC,IAAI,CAAC,iBAAiB,GAAG,IAAI,CAAC;QACpC,OAAO;IACR,CAAC;IAED,IAAI,QAAQ,CAAC,OAAO,KAAK,IAAI,EAAE,CAAC;QAC/B,MAAM,OAAO,GAAG,QAAQ,CAAC,YAAY,CAAC;QACtC,IAAI,CAAC,OAAO;YAAE,OAAO;QACrB,IAAI,YAAY,GAAY,OAAO,CAAC,uBAAuB,CAAC;QAC5D,IAAI,YAAY,KAAK,IAAI,EAAE,CAAC;YAC3B,IACC,CAAC,WAAW,CAAC,OAAO,CAAC,8BAA8B,CAAC;gBACpD,CAAC,WAAW,CAAC,OAAO,CAAC,mCAAmC,CAAC,EACxD,CAAC;gBACF,OAAO;YACR,CAAC;YACD,YAAY,GAAG,OAAO,CAAC,8BAA8B,GAAG,OAAO,CAAC,mCAAmC,CAAC;QACrG,CAAC;QACD,IAAI,CAAC,WAAW,CAAC,YAAY,CAAC;YAAE,OAAO;QACvC,KAAK,CAAC,IAAI,CAAC,KAAK,GAAG,QAAQ,CAAC,IAAI,GAAG,YAAY,CAAC;QAChD,KAAK,CAAC,IAAI,CAAC,iBAAiB,GAAG,IAAI,CAAC;IACrC,CAAC;AACF,CAAC","sourcesContent":["import type { Usage } from \"../types.ts\";\n\nexport interface OpenRouterUsageAccounting {\n\t/** Amount charged to the user's OpenRouter account. */\n\tcost: number | null;\n\t/** Whether OpenRouter used the user's upstream provider key. */\n\tis_byok: boolean;\n\tcost_details: {\n\t\t/** Total inference cost billed through the user's upstream provider account, when available. */\n\t\tupstream_inference_cost: number | null;\n\t\t/** Upstream cost for prompt processing, including any provider-side cache pricing. */\n\t\tupstream_inference_prompt_cost: number;\n\t\t/** Upstream cost for completion generation. */\n\t\tupstream_inference_completions_cost: number;\n\t\t/** Metered server-tool cost already included in OpenRouter's charged `cost`. */\n\t\tserver_tool_cost?: number | null;\n\t} | null;\n}\n\nfunction isValidCost(value: unknown): value is number {\n\treturn typeof value === \"number\" && Number.isFinite(value) && value >= 0;\n}\n\n/** OpenRouter by provider ID, which survives baseUrl overrides, or by host, which covers regional endpoints. */\nexport function isOpenRouterModel(model: { provider: string; baseUrl: string }): boolean {\n\treturn model.provider === \"openrouter\" || model.baseUrl.includes(\"openrouter.ai\");\n}\n\n/** Replace the catalog total with OpenRouter's billed cost when the response contains complete, valid accounting. */\nexport function applyOpenRouterReportedCost(usage: Usage, reported: OpenRouterUsageAccounting): void {\n\tif (!isValidCost(reported.cost)) return;\n\n\tif (reported.is_byok === false) {\n\t\tusage.cost.total = reported.cost;\n\t\tusage.cost.totalFromProvider = true;\n\t\treturn;\n\t}\n\n\tif (reported.is_byok === true) {\n\t\tconst details = reported.cost_details;\n\t\tif (!details) return;\n\t\tlet upstreamCost: unknown = details.upstream_inference_cost;\n\t\tif (upstreamCost === null) {\n\t\t\tif (\n\t\t\t\t!isValidCost(details.upstream_inference_prompt_cost) ||\n\t\t\t\t!isValidCost(details.upstream_inference_completions_cost)\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tupstreamCost = details.upstream_inference_prompt_cost + details.upstream_inference_completions_cost;\n\t\t}\n\t\tif (!isValidCost(upstreamCost)) return;\n\t\tusage.cost.total = reported.cost + upstreamCost;\n\t\tusage.cost.totalFromProvider = true;\n\t}\n}\n"]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { AssistantMessage } from "../types.ts";
|
|
2
|
+
/** Returns OpenRouter's `native_finish_reason` from a streamed chat completion choice, when present. */
|
|
3
|
+
export declare function readOpenRouterNativeFinishReason(choice: object): string | undefined;
|
|
4
|
+
/**
|
|
5
|
+
* Records a native finish reason that differs from `finishReason` on a message whose stop reason was
|
|
6
|
+
* already mapped from `finishReason`: `rawStopReason` becomes e.g. "stop.MALFORMED_RESPONSE" (the
|
|
7
|
+
* format of openai-responses' "incomplete.max_output_tokens"), and an error message gets the native
|
|
8
|
+
* reason appended. The stop reason itself is unchanged.
|
|
9
|
+
*/
|
|
10
|
+
export declare function applyOpenRouterNativeFinishReason(message: AssistantMessage, finishReason: string, nativeReason: string): void;
|
|
11
|
+
/**
|
|
12
|
+
* Turns an OpenRouter `stop` with `native_finish_reason: "MALFORMED_RESPONSE"` and no visible output
|
|
13
|
+
* into a retryable error.
|
|
14
|
+
*
|
|
15
|
+
* OpenRouter reports Gemini's transient `MALFORMED_RESPONSE` as `finish_reason: "stop"` when
|
|
16
|
+
* reasoning has already streamed, which would otherwise end the turn silently with only a thinking
|
|
17
|
+
* block. Matching `malformed_response` directly avoids maintaining OpenRouter's unpublished
|
|
18
|
+
* clean-stop mapping; other empty stops keep `stop` with `rawStopReason` recorded for diagnostics.
|
|
19
|
+
* The message matches the retry pattern for OpenRouter's own "Provider returned an empty response".
|
|
20
|
+
*/
|
|
21
|
+
export declare function flagOpenRouterEmptyStop(message: AssistantMessage, nativeReason: string): void;
|
|
22
|
+
//# sourceMappingURL=openrouter-finish-reason.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openrouter-finish-reason.d.ts","sourceRoot":"","sources":["../../src/utils/openrouter-finish-reason.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEpD,wGAAwG;AACxG,wBAAgB,gCAAgC,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAInF;AAED;;;;;GAKG;AACH,wBAAgB,iCAAiC,CAChD,OAAO,EAAE,gBAAgB,EACzB,YAAY,EAAE,MAAM,EACpB,YAAY,EAAE,MAAM,GAClB,IAAI,CAON;AAED;;;;;;;;;GASG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,GAAG,IAAI,CAQ7F"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/** Returns OpenRouter's `native_finish_reason` from a streamed chat completion choice, when present. */
|
|
2
|
+
export function readOpenRouterNativeFinishReason(choice) {
|
|
3
|
+
// Wire input: an OpenRouter extension that the OpenAI SDK types do not declare.
|
|
4
|
+
const native = choice.native_finish_reason;
|
|
5
|
+
return typeof native === "string" && native.length > 0 ? native : undefined;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Records a native finish reason that differs from `finishReason` on a message whose stop reason was
|
|
9
|
+
* already mapped from `finishReason`: `rawStopReason` becomes e.g. "stop.MALFORMED_RESPONSE" (the
|
|
10
|
+
* format of openai-responses' "incomplete.max_output_tokens"), and an error message gets the native
|
|
11
|
+
* reason appended. The stop reason itself is unchanged.
|
|
12
|
+
*/
|
|
13
|
+
export function applyOpenRouterNativeFinishReason(message, finishReason, nativeReason) {
|
|
14
|
+
if (nativeReason === finishReason)
|
|
15
|
+
return;
|
|
16
|
+
message.rawStopReason = `${finishReason}.${nativeReason}`;
|
|
17
|
+
if (message.stopReason === "error" && message.errorMessage) {
|
|
18
|
+
// Appended, not replaced: retry matching relies on the finish_reason message prefix.
|
|
19
|
+
message.errorMessage += ` (native_finish_reason: ${nativeReason})`;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Turns an OpenRouter `stop` with `native_finish_reason: "MALFORMED_RESPONSE"` and no visible output
|
|
24
|
+
* into a retryable error.
|
|
25
|
+
*
|
|
26
|
+
* OpenRouter reports Gemini's transient `MALFORMED_RESPONSE` as `finish_reason: "stop"` when
|
|
27
|
+
* reasoning has already streamed, which would otherwise end the turn silently with only a thinking
|
|
28
|
+
* block. Matching `malformed_response` directly avoids maintaining OpenRouter's unpublished
|
|
29
|
+
* clean-stop mapping; other empty stops keep `stop` with `rawStopReason` recorded for diagnostics.
|
|
30
|
+
* The message matches the retry pattern for OpenRouter's own "Provider returned an empty response".
|
|
31
|
+
*/
|
|
32
|
+
export function flagOpenRouterEmptyStop(message, nativeReason) {
|
|
33
|
+
if (message.stopReason !== "stop" || nativeReason.toLowerCase() !== "malformed_response")
|
|
34
|
+
return;
|
|
35
|
+
const hasVisibleOutput = message.content.some((block) => block.type === "toolCall" || (block.type === "text" && block.text.trim().length > 0));
|
|
36
|
+
if (hasVisibleOutput)
|
|
37
|
+
return;
|
|
38
|
+
message.stopReason = "error";
|
|
39
|
+
message.errorMessage = `OpenRouter returned an empty response (native_finish_reason: ${nativeReason})`;
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=openrouter-finish-reason.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openrouter-finish-reason.js","sourceRoot":"","sources":["../../src/utils/openrouter-finish-reason.ts"],"names":[],"mappings":"AAKA,wGAAwG;AACxG,MAAM,UAAU,gCAAgC,CAAC,MAAc;IAC9D,gFAAgF;IAChF,MAAM,MAAM,GAAI,MAA6C,CAAC,oBAAoB,CAAC;IACnF,OAAO,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC;AAC7E,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,iCAAiC,CAChD,OAAyB,EACzB,YAAoB,EACpB,YAAoB;IAEpB,IAAI,YAAY,KAAK,YAAY;QAAE,OAAO;IAC1C,OAAO,CAAC,aAAa,GAAG,GAAG,YAAY,IAAI,YAAY,EAAE,CAAC;IAC1D,IAAI,OAAO,CAAC,UAAU,KAAK,OAAO,IAAI,OAAO,CAAC,YAAY,EAAE,CAAC;QAC5D,qFAAqF;QACrF,OAAO,CAAC,YAAY,IAAI,2BAA2B,YAAY,GAAG,CAAC;IACpE,CAAC;AACF,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,uBAAuB,CAAC,OAAyB,EAAE,YAAoB;IACtF,IAAI,OAAO,CAAC,UAAU,KAAK,MAAM,IAAI,YAAY,CAAC,WAAW,EAAE,KAAK,oBAAoB;QAAE,OAAO;IACjG,MAAM,gBAAgB,GAAG,OAAO,CAAC,OAAO,CAAC,IAAI,CAC5C,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,KAAK,UAAU,IAAI,CAAC,KAAK,CAAC,IAAI,KAAK,MAAM,IAAI,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC,CAC/F,CAAC;IACF,IAAI,gBAAgB;QAAE,OAAO;IAC7B,OAAO,CAAC,UAAU,GAAG,OAAO,CAAC;IAC7B,OAAO,CAAC,YAAY,GAAG,gEAAgE,YAAY,GAAG,CAAC;AACxG,CAAC","sourcesContent":["// OpenRouter's `native_finish_reason`: the upstream provider's own finish reason, which OpenRouter\n// sends next to the OpenAI-style `finish_reason` it normalizes it into. Recorded for diagnostics, and\n// used to catch upstream failures that OpenRouter reports as an empty `stop`.\nimport type { AssistantMessage } from \"../types.ts\";\n\n/** Returns OpenRouter's `native_finish_reason` from a streamed chat completion choice, when present. */\nexport function readOpenRouterNativeFinishReason(choice: object): string | undefined {\n\t// Wire input: an OpenRouter extension that the OpenAI SDK types do not declare.\n\tconst native = (choice as { native_finish_reason?: unknown }).native_finish_reason;\n\treturn typeof native === \"string\" && native.length > 0 ? native : undefined;\n}\n\n/**\n * Records a native finish reason that differs from `finishReason` on a message whose stop reason was\n * already mapped from `finishReason`: `rawStopReason` becomes e.g. \"stop.MALFORMED_RESPONSE\" (the\n * format of openai-responses' \"incomplete.max_output_tokens\"), and an error message gets the native\n * reason appended. The stop reason itself is unchanged.\n */\nexport function applyOpenRouterNativeFinishReason(\n\tmessage: AssistantMessage,\n\tfinishReason: string,\n\tnativeReason: string,\n): void {\n\tif (nativeReason === finishReason) return;\n\tmessage.rawStopReason = `${finishReason}.${nativeReason}`;\n\tif (message.stopReason === \"error\" && message.errorMessage) {\n\t\t// Appended, not replaced: retry matching relies on the finish_reason message prefix.\n\t\tmessage.errorMessage += ` (native_finish_reason: ${nativeReason})`;\n\t}\n}\n\n/**\n * Turns an OpenRouter `stop` with `native_finish_reason: \"MALFORMED_RESPONSE\"` and no visible output\n * into a retryable error.\n *\n * OpenRouter reports Gemini's transient `MALFORMED_RESPONSE` as `finish_reason: \"stop\"` when\n * reasoning has already streamed, which would otherwise end the turn silently with only a thinking\n * block. Matching `malformed_response` directly avoids maintaining OpenRouter's unpublished\n * clean-stop mapping; other empty stops keep `stop` with `rawStopReason` recorded for diagnostics.\n * The message matches the retry pattern for OpenRouter's own \"Provider returned an empty response\".\n */\nexport function flagOpenRouterEmptyStop(message: AssistantMessage, nativeReason: string): void {\n\tif (message.stopReason !== \"stop\" || nativeReason.toLowerCase() !== \"malformed_response\") return;\n\tconst hasVisibleOutput = message.content.some(\n\t\t(block) => block.type === \"toolCall\" || (block.type === \"text\" && block.text.trim().length > 0),\n\t);\n\tif (hasVisibleOutput) return;\n\tmessage.stopReason = \"error\";\n\tmessage.errorMessage = `OpenRouter returned an empty response (native_finish_reason: ${nativeReason})`;\n}\n"]}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { AssistantMessage } from "../types.ts";
|
|
2
|
+
/**
|
|
3
|
+
* Check if an assistant message represents a context overflow error.
|
|
4
|
+
*
|
|
5
|
+
* This handles three cases:
|
|
6
|
+
* 1. Error-based overflow: Most providers return stopReason "error" with a
|
|
7
|
+
* specific error message pattern.
|
|
8
|
+
* 2. Silent overflow: Some providers accept overflow requests and return
|
|
9
|
+
* successfully. For these, we check if usage.input exceeds the context window.
|
|
10
|
+
* 3. Length-stop overflow: Xiaomi MiMo can return "length" with zero output when
|
|
11
|
+
* the input fills the context window.
|
|
12
|
+
*
|
|
13
|
+
* ## Reliability by Provider
|
|
14
|
+
*
|
|
15
|
+
* **Reliable detection (returns error with detectable message):**
|
|
16
|
+
* - Anthropic: "prompt is too long: X tokens > Y maximum" or "request_too_large"
|
|
17
|
+
* - OpenAI (Completions & Responses): "exceeds the context window", "exceeds the model's maximum context length of X tokens", or "exceeds model's maximum context length (X)"
|
|
18
|
+
* - Google Gemini: "input token count exceeds the maximum"
|
|
19
|
+
* - xAI (Grok): "maximum prompt length is X but request contains Y"
|
|
20
|
+
* - Groq: "reduce the length of the messages"
|
|
21
|
+
* - GitHub Copilot: HTTP 413 "failed to parse request" (request byte-size overflow)
|
|
22
|
+
* - Cerebras: 400/413 status code (no body)
|
|
23
|
+
* - OpenCode Go: HTTP 400 "decoded body exceeds X bytes" (request byte-size overflow)
|
|
24
|
+
* - Mistral: "Prompt contains X tokens ... too large for model with Y maximum context length"
|
|
25
|
+
* - OpenRouter (most backends): "maximum context length is X tokens"
|
|
26
|
+
* - OpenRouter/Poolside: "Input length X exceeds the maximum allowed input length of Y tokens."
|
|
27
|
+
* - Together AI: "The input (X tokens) is longer than the model's context length (Y tokens)."
|
|
28
|
+
* - llama.cpp: "exceeds the available context size"
|
|
29
|
+
* - LM Studio: "greater than the context length"
|
|
30
|
+
* - Kimi For Coding: "exceeded model token limit: X (requested: Y)"
|
|
31
|
+
* - DS4: "Prompt has X tokens, but the configured context size is Y tokens"
|
|
32
|
+
* - DashScope/Qwen: "Range of input length should be [1, X]"
|
|
33
|
+
* - z.ai: "Prompt too long"
|
|
34
|
+
*
|
|
35
|
+
* **Unreliable detection:**
|
|
36
|
+
* - z.ai: Sometimes accepts overflow silently (detectable via usage.input > contextWindow),
|
|
37
|
+
* sometimes returns rate limit errors. Pass contextWindow param to detect silent overflow.
|
|
38
|
+
* - Xiaomi MiMo: Truncates input to fit contextWindow then returns stopReason "length" with
|
|
39
|
+
* output=0. Pass contextWindow param to detect via the "filled context + zero output" signal.
|
|
40
|
+
* - Ollama: May truncate input silently for some setups, but may also return explicit
|
|
41
|
+
* overflow errors that match the patterns above. Silent truncation still cannot be
|
|
42
|
+
* detected here because we do not know the expected token count.
|
|
43
|
+
*
|
|
44
|
+
* ## Custom Providers
|
|
45
|
+
*
|
|
46
|
+
* If you've added custom models via settings.json, this function may not detect
|
|
47
|
+
* overflow errors from those providers. To add support:
|
|
48
|
+
*
|
|
49
|
+
* 1. Send a request that exceeds the model's context window
|
|
50
|
+
* 2. Check the errorMessage in the response
|
|
51
|
+
* 3. Create a regex pattern that matches the error
|
|
52
|
+
* 4. The pattern should be added to OVERFLOW_PATTERNS in this file, or
|
|
53
|
+
* check the errorMessage yourself before calling this function
|
|
54
|
+
*
|
|
55
|
+
* @param message - The assistant message to check
|
|
56
|
+
* @param contextWindow - Optional context window size for detecting silent overflow (z.ai)
|
|
57
|
+
* @returns true if the message indicates a context overflow
|
|
58
|
+
*/
|
|
59
|
+
export declare function isContextOverflow(message: AssistantMessage, contextWindow?: number): boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Check whether a length stop ended below the caller or model's intended output limit.
|
|
62
|
+
* Such responses may be caused by context pressure or provider-side truncation, so callers
|
|
63
|
+
* can make one bounded compact-and-retry attempt. `desiredMaxOutput` must be the original
|
|
64
|
+
* limit before any context-based clamping.
|
|
65
|
+
*/
|
|
66
|
+
export declare function isRecoverableLength(message: AssistantMessage, desiredMaxOutput: number): boolean;
|
|
67
|
+
/**
|
|
68
|
+
* Get the overflow patterns for testing purposes.
|
|
69
|
+
*/
|
|
70
|
+
export declare function getOverflowPatterns(): RegExp[];
|
|
71
|
+
//# sourceMappingURL=overflow.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"overflow.d.ts","sourceRoot":"","sources":["../../src/utils/overflow.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAyFpD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwDG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,gBAAgB,EAAE,aAAa,CAAC,EAAE,MAAM,GAAG,OAAO,CAkC5F;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,GAAG,OAAO,CAEhG;AAED;;GAEG;AACH,wBAAgB,mBAAmB,IAAI,MAAM,EAAE,CAE9C"}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Regex patterns to detect context overflow errors from different providers.
|
|
3
|
+
*
|
|
4
|
+
* These patterns match error messages returned when the input exceeds
|
|
5
|
+
* the model's context window or the provider's request byte-size limit.
|
|
6
|
+
*
|
|
7
|
+
* Provider-specific patterns (with example error messages):
|
|
8
|
+
*
|
|
9
|
+
* - Anthropic: "prompt is too long: 213462 tokens > 200000 maximum"
|
|
10
|
+
* - Anthropic: "413 {\"error\":{\"type\":\"request_too_large\",\"message\":\"Request exceeds the maximum size\"}}"
|
|
11
|
+
* - OpenAI: "Your input exceeds the context window of this model"
|
|
12
|
+
* - OpenAI/LiteLLM: "Requested token count exceeds the model's maximum context length of 131072 tokens"
|
|
13
|
+
* - LiteLLM pre-call check: "litellm.ContextWindowExceededError: ... Context Window exceeded for given call."
|
|
14
|
+
* - OpenAI-compatible: "Input length (265330) exceeds model's maximum context length (262144)."
|
|
15
|
+
* - Google: "The input token count (1196265) exceeds the maximum number of tokens allowed (1048575)"
|
|
16
|
+
* - xAI: "This model's maximum prompt length is 131072 but the request contains 537812 tokens"
|
|
17
|
+
* - Groq: "Please reduce the length of the messages or completion"
|
|
18
|
+
* - OpenRouter: "This endpoint's maximum context length is X tokens. However, you requested about Y tokens"
|
|
19
|
+
* - OpenRouter/Poolside: "Input length X exceeds the maximum allowed input length of Y tokens."
|
|
20
|
+
* - Together AI: "The input (X tokens) is longer than the model's context length (Y tokens)."
|
|
21
|
+
* - llama.cpp: "the request exceeds the available context size, try increasing it"
|
|
22
|
+
* - LM Studio: "tokens to keep from the initial prompt is greater than the context length"
|
|
23
|
+
* - GitHub Copilot: "prompt token count of X exceeds the limit of Y"
|
|
24
|
+
* - GitHub Copilot: 'github-copilot API error (413): {"message":"failed to parse request","code":""}'
|
|
25
|
+
* - MiniMax: "invalid params, context window exceeds limit"
|
|
26
|
+
* - Kimi For Coding: "Your request exceeded model token limit: X (requested: Y)"
|
|
27
|
+
* - DS4: "Prompt has X tokens, but the configured context size is Y tokens"
|
|
28
|
+
* - Cerebras: "400/413 status code (no body)"
|
|
29
|
+
* - OpenCode Go: '400: {..."message":"Upstream request failed: [invalid_request_error] decoded body exceeds 50331648 bytes ..."}'
|
|
30
|
+
* - Mistral: "Prompt contains X tokens ... too large for model with Y maximum context length"
|
|
31
|
+
* - z.ai: `{"code":"1261","message":"Prompt too long"}`, `{"code":"1261","message":"Prompt exceeds max length"}` (CN endpoint), or silent overflow via usage.input > contextWindow
|
|
32
|
+
* - Xiaomi MiMo: Truncates input to fill contextWindow exactly, then returns finish_reason "length"
|
|
33
|
+
* with output=0 (no room left to generate). Detected via stopReason "length" + zero output +
|
|
34
|
+
* input filling the context window.
|
|
35
|
+
* - DashScope/Qwen: "Range of input length should be [1, X]" (HTTP 400 invalid_parameter_error)
|
|
36
|
+
* - Ollama: Some deployments truncate silently, others return errors like "prompt too long; exceeded max context length by X tokens"
|
|
37
|
+
*/
|
|
38
|
+
const OVERFLOW_PATTERNS = [
|
|
39
|
+
/prompt (?:is )?too long/i, // Anthropic and z.ai token overflow
|
|
40
|
+
/prompt exceeds max length/i, // z.ai CN endpoint token overflow
|
|
41
|
+
/(?<![a-z0-9_])request_too_large(?![a-z0-9_])/i, // Anthropic request byte-size error code, not a longer identifier
|
|
42
|
+
/decoded body exceeds \d+ bytes/i, // OpenCode Go request byte-size limit, sent as HTTP 400
|
|
43
|
+
/input is too long for requested model/i, // Amazon Bedrock
|
|
44
|
+
/exceeds the context window/i, // OpenAI (Completions & Responses API)
|
|
45
|
+
/exceeds (?:the )?(?:model'?s )?maximum context length(?: of [\d,]+ tokens?|\s*\([\d,]+\))/i, // OpenAI-compatible proxies (LiteLLM)
|
|
46
|
+
/context window exceeded/i, // LiteLLM pre-call check (ContextWindowExceededError)
|
|
47
|
+
/input token count.*exceeds the maximum/i, // Google (Gemini)
|
|
48
|
+
/maximum prompt length is \d+/i, // xAI (Grok)
|
|
49
|
+
/reduce the length of the messages/i, // Groq
|
|
50
|
+
/maximum context length is \d+ tokens/i, // OpenRouter (most backends)
|
|
51
|
+
/exceeds (?:the )?maximum allowed input length of [\d,]+ tokens?/i, // OpenRouter/Poolside
|
|
52
|
+
/input \(\d+ tokens\) is longer than the model'?s context length \(\d+ tokens\)/i, // Together AI
|
|
53
|
+
/exceeds the limit of \d+/i, // GitHub Copilot
|
|
54
|
+
/exceeds the available context size/i, // llama.cpp server
|
|
55
|
+
/greater than the context length/i, // LM Studio
|
|
56
|
+
/context window exceeds limit/i, // MiniMax
|
|
57
|
+
/exceeded model token limit/i, // Kimi For Coding
|
|
58
|
+
/too large for model with \d+ maximum context length/i, // Mistral
|
|
59
|
+
/prompt has [\d,]+ tokens?, but the configured context size is [\d,]+ tokens?/i, // DS4 server
|
|
60
|
+
/model_context_window_exceeded/i, // z.ai non-standard finish_reason surfaced as error text
|
|
61
|
+
/prompt too long; exceeded (?:max )?context length/i, // Ollama explicit overflow error
|
|
62
|
+
/range of input length should be/i, // DashScope / Qwen Token Plan
|
|
63
|
+
/context[_ ]length[_ ]exceeded/i, // Generic fallback
|
|
64
|
+
/too many tokens/i, // Generic fallback
|
|
65
|
+
/token limit exceeded/i, // Generic fallback
|
|
66
|
+
// HTTP 413 means request-size overflow regardless of provider or body text.
|
|
67
|
+
// Match raw SDK errors and formatProviderError's prefix, not a status mentioned in the body.
|
|
68
|
+
/^(?:[\w -]+ API error \(413\):|413(?:\s|:|$))/i,
|
|
69
|
+
];
|
|
70
|
+
const CEREBRAS_BODYLESS_OVERFLOW_PATTERN = /^4(?:00|13)\s*(?:status code)?\s*\(no body\)/i;
|
|
71
|
+
/**
|
|
72
|
+
* Patterns that indicate non-overflow errors (e.g. rate limiting, server errors).
|
|
73
|
+
* Error messages matching any of these are excluded from overflow detection
|
|
74
|
+
* even if they also match an OVERFLOW_PATTERN.
|
|
75
|
+
*
|
|
76
|
+
* Example: Bedrock formats throttling errors as "ThrottlingException: Too many tokens,
|
|
77
|
+
* please wait before trying again." which would match the /too many tokens/i overflow
|
|
78
|
+
* pattern without this exclusion.
|
|
79
|
+
*/
|
|
80
|
+
const NON_OVERFLOW_PATTERNS = [
|
|
81
|
+
/^(Throttling error|Service unavailable):/i, // AWS Bedrock non-overflow errors (human-readable prefixes from formatBedrockError)
|
|
82
|
+
/rate limit/i, // Generic rate limiting
|
|
83
|
+
/too many requests/i, // Generic HTTP 429 style
|
|
84
|
+
];
|
|
85
|
+
/**
|
|
86
|
+
* Check if an assistant message represents a context overflow error.
|
|
87
|
+
*
|
|
88
|
+
* This handles three cases:
|
|
89
|
+
* 1. Error-based overflow: Most providers return stopReason "error" with a
|
|
90
|
+
* specific error message pattern.
|
|
91
|
+
* 2. Silent overflow: Some providers accept overflow requests and return
|
|
92
|
+
* successfully. For these, we check if usage.input exceeds the context window.
|
|
93
|
+
* 3. Length-stop overflow: Xiaomi MiMo can return "length" with zero output when
|
|
94
|
+
* the input fills the context window.
|
|
95
|
+
*
|
|
96
|
+
* ## Reliability by Provider
|
|
97
|
+
*
|
|
98
|
+
* **Reliable detection (returns error with detectable message):**
|
|
99
|
+
* - Anthropic: "prompt is too long: X tokens > Y maximum" or "request_too_large"
|
|
100
|
+
* - OpenAI (Completions & Responses): "exceeds the context window", "exceeds the model's maximum context length of X tokens", or "exceeds model's maximum context length (X)"
|
|
101
|
+
* - Google Gemini: "input token count exceeds the maximum"
|
|
102
|
+
* - xAI (Grok): "maximum prompt length is X but request contains Y"
|
|
103
|
+
* - Groq: "reduce the length of the messages"
|
|
104
|
+
* - GitHub Copilot: HTTP 413 "failed to parse request" (request byte-size overflow)
|
|
105
|
+
* - Cerebras: 400/413 status code (no body)
|
|
106
|
+
* - OpenCode Go: HTTP 400 "decoded body exceeds X bytes" (request byte-size overflow)
|
|
107
|
+
* - Mistral: "Prompt contains X tokens ... too large for model with Y maximum context length"
|
|
108
|
+
* - OpenRouter (most backends): "maximum context length is X tokens"
|
|
109
|
+
* - OpenRouter/Poolside: "Input length X exceeds the maximum allowed input length of Y tokens."
|
|
110
|
+
* - Together AI: "The input (X tokens) is longer than the model's context length (Y tokens)."
|
|
111
|
+
* - llama.cpp: "exceeds the available context size"
|
|
112
|
+
* - LM Studio: "greater than the context length"
|
|
113
|
+
* - Kimi For Coding: "exceeded model token limit: X (requested: Y)"
|
|
114
|
+
* - DS4: "Prompt has X tokens, but the configured context size is Y tokens"
|
|
115
|
+
* - DashScope/Qwen: "Range of input length should be [1, X]"
|
|
116
|
+
* - z.ai: "Prompt too long"
|
|
117
|
+
*
|
|
118
|
+
* **Unreliable detection:**
|
|
119
|
+
* - z.ai: Sometimes accepts overflow silently (detectable via usage.input > contextWindow),
|
|
120
|
+
* sometimes returns rate limit errors. Pass contextWindow param to detect silent overflow.
|
|
121
|
+
* - Xiaomi MiMo: Truncates input to fit contextWindow then returns stopReason "length" with
|
|
122
|
+
* output=0. Pass contextWindow param to detect via the "filled context + zero output" signal.
|
|
123
|
+
* - Ollama: May truncate input silently for some setups, but may also return explicit
|
|
124
|
+
* overflow errors that match the patterns above. Silent truncation still cannot be
|
|
125
|
+
* detected here because we do not know the expected token count.
|
|
126
|
+
*
|
|
127
|
+
* ## Custom Providers
|
|
128
|
+
*
|
|
129
|
+
* If you've added custom models via settings.json, this function may not detect
|
|
130
|
+
* overflow errors from those providers. To add support:
|
|
131
|
+
*
|
|
132
|
+
* 1. Send a request that exceeds the model's context window
|
|
133
|
+
* 2. Check the errorMessage in the response
|
|
134
|
+
* 3. Create a regex pattern that matches the error
|
|
135
|
+
* 4. The pattern should be added to OVERFLOW_PATTERNS in this file, or
|
|
136
|
+
* check the errorMessage yourself before calling this function
|
|
137
|
+
*
|
|
138
|
+
* @param message - The assistant message to check
|
|
139
|
+
* @param contextWindow - Optional context window size for detecting silent overflow (z.ai)
|
|
140
|
+
* @returns true if the message indicates a context overflow
|
|
141
|
+
*/
|
|
142
|
+
export function isContextOverflow(message, contextWindow) {
|
|
143
|
+
// Case 1: Check error message patterns
|
|
144
|
+
if (message.stopReason === "error" && message.errorMessage) {
|
|
145
|
+
// Skip messages matching known non-overflow patterns (e.g. throttling / rate-limit)
|
|
146
|
+
const isNonOverflow = NON_OVERFLOW_PATTERNS.some((p) => p.test(message.errorMessage));
|
|
147
|
+
if (!isNonOverflow) {
|
|
148
|
+
if (OVERFLOW_PATTERNS.some((p) => p.test(message.errorMessage))) {
|
|
149
|
+
return true;
|
|
150
|
+
}
|
|
151
|
+
if (message.provider === "cerebras" && CEREBRAS_BODYLESS_OVERFLOW_PATTERN.test(message.errorMessage)) {
|
|
152
|
+
return true;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
// Case 2: Silent overflow (z.ai style) - successful but usage exceeds context
|
|
157
|
+
if (contextWindow && message.stopReason === "stop") {
|
|
158
|
+
const inputTokens = message.usage.input + message.usage.cacheRead;
|
|
159
|
+
if (inputTokens > contextWindow) {
|
|
160
|
+
return true;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
// Case 3: Length-stop overflow (Xiaomi MiMo style) - server truncates oversized input
|
|
164
|
+
// to fit the context window, leaving no room for output. Returns stopReason "length"
|
|
165
|
+
// with output=0 and input+cacheRead filling the context window.
|
|
166
|
+
if (contextWindow && message.stopReason === "length" && message.usage.output === 0) {
|
|
167
|
+
const inputTokens = message.usage.input + message.usage.cacheRead;
|
|
168
|
+
if (inputTokens >= contextWindow * 0.99) {
|
|
169
|
+
return true;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return false;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Check whether a length stop ended below the caller or model's intended output limit.
|
|
176
|
+
* Such responses may be caused by context pressure or provider-side truncation, so callers
|
|
177
|
+
* can make one bounded compact-and-retry attempt. `desiredMaxOutput` must be the original
|
|
178
|
+
* limit before any context-based clamping.
|
|
179
|
+
*/
|
|
180
|
+
export function isRecoverableLength(message, desiredMaxOutput) {
|
|
181
|
+
return message.stopReason === "length" && desiredMaxOutput > 0 && message.usage.output < desiredMaxOutput;
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Get the overflow patterns for testing purposes.
|
|
185
|
+
*/
|
|
186
|
+
export function getOverflowPatterns() {
|
|
187
|
+
return [...OVERFLOW_PATTERNS];
|
|
188
|
+
}
|
|
189
|
+
//# sourceMappingURL=overflow.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"overflow.js","sourceRoot":"","sources":["../../src/utils/overflow.ts"],"names":[],"mappings":"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","sourcesContent":["import type { AssistantMessage } from \"../types.ts\";\n\n/**\n * Regex patterns to detect context overflow errors from different providers.\n *\n * These patterns match error messages returned when the input exceeds\n * the model's context window or the provider's request byte-size limit.\n *\n * Provider-specific patterns (with example error messages):\n *\n * - Anthropic: \"prompt is too long: 213462 tokens > 200000 maximum\"\n * - Anthropic: \"413 {\\\"error\\\":{\\\"type\\\":\\\"request_too_large\\\",\\\"message\\\":\\\"Request exceeds the maximum size\\\"}}\"\n * - OpenAI: \"Your input exceeds the context window of this model\"\n * - OpenAI/LiteLLM: \"Requested token count exceeds the model's maximum context length of 131072 tokens\"\n * - LiteLLM pre-call check: \"litellm.ContextWindowExceededError: ... Context Window exceeded for given call.\"\n * - OpenAI-compatible: \"Input length (265330) exceeds model's maximum context length (262144).\"\n * - Google: \"The input token count (1196265) exceeds the maximum number of tokens allowed (1048575)\"\n * - xAI: \"This model's maximum prompt length is 131072 but the request contains 537812 tokens\"\n * - Groq: \"Please reduce the length of the messages or completion\"\n * - OpenRouter: \"This endpoint's maximum context length is X tokens. However, you requested about Y tokens\"\n * - OpenRouter/Poolside: \"Input length X exceeds the maximum allowed input length of Y tokens.\"\n * - Together AI: \"The input (X tokens) is longer than the model's context length (Y tokens).\"\n * - llama.cpp: \"the request exceeds the available context size, try increasing it\"\n * - LM Studio: \"tokens to keep from the initial prompt is greater than the context length\"\n * - GitHub Copilot: \"prompt token count of X exceeds the limit of Y\"\n * - GitHub Copilot: 'github-copilot API error (413): {\"message\":\"failed to parse request\",\"code\":\"\"}'\n * - MiniMax: \"invalid params, context window exceeds limit\"\n * - Kimi For Coding: \"Your request exceeded model token limit: X (requested: Y)\"\n * - DS4: \"Prompt has X tokens, but the configured context size is Y tokens\"\n * - Cerebras: \"400/413 status code (no body)\"\n * - OpenCode Go: '400: {...\"message\":\"Upstream request failed: [invalid_request_error] decoded body exceeds 50331648 bytes ...\"}'\n * - Mistral: \"Prompt contains X tokens ... too large for model with Y maximum context length\"\n * - z.ai: `{\"code\":\"1261\",\"message\":\"Prompt too long\"}`, `{\"code\":\"1261\",\"message\":\"Prompt exceeds max length\"}` (CN endpoint), or silent overflow via usage.input > contextWindow\n * - Xiaomi MiMo: Truncates input to fill contextWindow exactly, then returns finish_reason \"length\"\n * with output=0 (no room left to generate). Detected via stopReason \"length\" + zero output +\n * input filling the context window.\n * - DashScope/Qwen: \"Range of input length should be [1, X]\" (HTTP 400 invalid_parameter_error)\n * - Ollama: Some deployments truncate silently, others return errors like \"prompt too long; exceeded max context length by X tokens\"\n */\nconst OVERFLOW_PATTERNS = [\n\t/prompt (?:is )?too long/i, // Anthropic and z.ai token overflow\n\t/prompt exceeds max length/i, // z.ai CN endpoint token overflow\n\t/(?<![a-z0-9_])request_too_large(?![a-z0-9_])/i, // Anthropic request byte-size error code, not a longer identifier\n\t/decoded body exceeds \\d+ bytes/i, // OpenCode Go request byte-size limit, sent as HTTP 400\n\t/input is too long for requested model/i, // Amazon Bedrock\n\t/exceeds the context window/i, // OpenAI (Completions & Responses API)\n\t/exceeds (?:the )?(?:model'?s )?maximum context length(?: of [\\d,]+ tokens?|\\s*\\([\\d,]+\\))/i, // OpenAI-compatible proxies (LiteLLM)\n\t/context window exceeded/i, // LiteLLM pre-call check (ContextWindowExceededError)\n\t/input token count.*exceeds the maximum/i, // Google (Gemini)\n\t/maximum prompt length is \\d+/i, // xAI (Grok)\n\t/reduce the length of the messages/i, // Groq\n\t/maximum context length is \\d+ tokens/i, // OpenRouter (most backends)\n\t/exceeds (?:the )?maximum allowed input length of [\\d,]+ tokens?/i, // OpenRouter/Poolside\n\t/input \\(\\d+ tokens\\) is longer than the model'?s context length \\(\\d+ tokens\\)/i, // Together AI\n\t/exceeds the limit of \\d+/i, // GitHub Copilot\n\t/exceeds the available context size/i, // llama.cpp server\n\t/greater than the context length/i, // LM Studio\n\t/context window exceeds limit/i, // MiniMax\n\t/exceeded model token limit/i, // Kimi For Coding\n\t/too large for model with \\d+ maximum context length/i, // Mistral\n\t/prompt has [\\d,]+ tokens?, but the configured context size is [\\d,]+ tokens?/i, // DS4 server\n\t/model_context_window_exceeded/i, // z.ai non-standard finish_reason surfaced as error text\n\t/prompt too long; exceeded (?:max )?context length/i, // Ollama explicit overflow error\n\t/range of input length should be/i, // DashScope / Qwen Token Plan\n\t/context[_ ]length[_ ]exceeded/i, // Generic fallback\n\t/too many tokens/i, // Generic fallback\n\t/token limit exceeded/i, // Generic fallback\n\t// HTTP 413 means request-size overflow regardless of provider or body text.\n\t// Match raw SDK errors and formatProviderError's prefix, not a status mentioned in the body.\n\t/^(?:[\\w -]+ API error \\(413\\):|413(?:\\s|:|$))/i,\n];\n\nconst CEREBRAS_BODYLESS_OVERFLOW_PATTERN = /^4(?:00|13)\\s*(?:status code)?\\s*\\(no body\\)/i;\n\n/**\n * Patterns that indicate non-overflow errors (e.g. rate limiting, server errors).\n * Error messages matching any of these are excluded from overflow detection\n * even if they also match an OVERFLOW_PATTERN.\n *\n * Example: Bedrock formats throttling errors as \"ThrottlingException: Too many tokens,\n * please wait before trying again.\" which would match the /too many tokens/i overflow\n * pattern without this exclusion.\n */\nconst NON_OVERFLOW_PATTERNS = [\n\t/^(Throttling error|Service unavailable):/i, // AWS Bedrock non-overflow errors (human-readable prefixes from formatBedrockError)\n\t/rate limit/i, // Generic rate limiting\n\t/too many requests/i, // Generic HTTP 429 style\n];\n\n/**\n * Check if an assistant message represents a context overflow error.\n *\n * This handles three cases:\n * 1. Error-based overflow: Most providers return stopReason \"error\" with a\n * specific error message pattern.\n * 2. Silent overflow: Some providers accept overflow requests and return\n * successfully. For these, we check if usage.input exceeds the context window.\n * 3. Length-stop overflow: Xiaomi MiMo can return \"length\" with zero output when\n * the input fills the context window.\n *\n * ## Reliability by Provider\n *\n * **Reliable detection (returns error with detectable message):**\n * - Anthropic: \"prompt is too long: X tokens > Y maximum\" or \"request_too_large\"\n * - OpenAI (Completions & Responses): \"exceeds the context window\", \"exceeds the model's maximum context length of X tokens\", or \"exceeds model's maximum context length (X)\"\n * - Google Gemini: \"input token count exceeds the maximum\"\n * - xAI (Grok): \"maximum prompt length is X but request contains Y\"\n * - Groq: \"reduce the length of the messages\"\n * - GitHub Copilot: HTTP 413 \"failed to parse request\" (request byte-size overflow)\n * - Cerebras: 400/413 status code (no body)\n * - OpenCode Go: HTTP 400 \"decoded body exceeds X bytes\" (request byte-size overflow)\n * - Mistral: \"Prompt contains X tokens ... too large for model with Y maximum context length\"\n * - OpenRouter (most backends): \"maximum context length is X tokens\"\n * - OpenRouter/Poolside: \"Input length X exceeds the maximum allowed input length of Y tokens.\"\n * - Together AI: \"The input (X tokens) is longer than the model's context length (Y tokens).\"\n * - llama.cpp: \"exceeds the available context size\"\n * - LM Studio: \"greater than the context length\"\n * - Kimi For Coding: \"exceeded model token limit: X (requested: Y)\"\n * - DS4: \"Prompt has X tokens, but the configured context size is Y tokens\"\n * - DashScope/Qwen: \"Range of input length should be [1, X]\"\n * - z.ai: \"Prompt too long\"\n *\n * **Unreliable detection:**\n * - z.ai: Sometimes accepts overflow silently (detectable via usage.input > contextWindow),\n * sometimes returns rate limit errors. Pass contextWindow param to detect silent overflow.\n * - Xiaomi MiMo: Truncates input to fit contextWindow then returns stopReason \"length\" with\n * output=0. Pass contextWindow param to detect via the \"filled context + zero output\" signal.\n * - Ollama: May truncate input silently for some setups, but may also return explicit\n * overflow errors that match the patterns above. Silent truncation still cannot be\n * detected here because we do not know the expected token count.\n *\n * ## Custom Providers\n *\n * If you've added custom models via settings.json, this function may not detect\n * overflow errors from those providers. To add support:\n *\n * 1. Send a request that exceeds the model's context window\n * 2. Check the errorMessage in the response\n * 3. Create a regex pattern that matches the error\n * 4. The pattern should be added to OVERFLOW_PATTERNS in this file, or\n * check the errorMessage yourself before calling this function\n *\n * @param message - The assistant message to check\n * @param contextWindow - Optional context window size for detecting silent overflow (z.ai)\n * @returns true if the message indicates a context overflow\n */\nexport function isContextOverflow(message: AssistantMessage, contextWindow?: number): boolean {\n\t// Case 1: Check error message patterns\n\tif (message.stopReason === \"error\" && message.errorMessage) {\n\t\t// Skip messages matching known non-overflow patterns (e.g. throttling / rate-limit)\n\t\tconst isNonOverflow = NON_OVERFLOW_PATTERNS.some((p) => p.test(message.errorMessage!));\n\t\tif (!isNonOverflow) {\n\t\t\tif (OVERFLOW_PATTERNS.some((p) => p.test(message.errorMessage!))) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tif (message.provider === \"cerebras\" && CEREBRAS_BODYLESS_OVERFLOW_PATTERN.test(message.errorMessage)) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t}\n\n\t// Case 2: Silent overflow (z.ai style) - successful but usage exceeds context\n\tif (contextWindow && message.stopReason === \"stop\") {\n\t\tconst inputTokens = message.usage.input + message.usage.cacheRead;\n\t\tif (inputTokens > contextWindow) {\n\t\t\treturn true;\n\t\t}\n\t}\n\n\t// Case 3: Length-stop overflow (Xiaomi MiMo style) - server truncates oversized input\n\t// to fit the context window, leaving no room for output. Returns stopReason \"length\"\n\t// with output=0 and input+cacheRead filling the context window.\n\tif (contextWindow && message.stopReason === \"length\" && message.usage.output === 0) {\n\t\tconst inputTokens = message.usage.input + message.usage.cacheRead;\n\t\tif (inputTokens >= contextWindow * 0.99) {\n\t\t\treturn true;\n\t\t}\n\t}\n\n\treturn false;\n}\n\n/**\n * Check whether a length stop ended below the caller or model's intended output limit.\n * Such responses may be caused by context pressure or provider-side truncation, so callers\n * can make one bounded compact-and-retry attempt. `desiredMaxOutput` must be the original\n * limit before any context-based clamping.\n */\nexport function isRecoverableLength(message: AssistantMessage, desiredMaxOutput: number): boolean {\n\treturn message.stopReason === \"length\" && desiredMaxOutput > 0 && message.usage.output < desiredMaxOutput;\n}\n\n/**\n * Get the overflow patterns for testing purposes.\n */\nexport function getOverflowPatterns(): RegExp[] {\n\treturn [...OVERFLOW_PATTERNS];\n}\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ProviderEnv } from "../types.ts";
|
|
2
|
+
/**
|
|
3
|
+
* Resolve a provider env value from scoped overrides, normal process.env, then
|
|
4
|
+
* the duplicated Bun sandbox fallback for direct pi-ai consumers.
|
|
5
|
+
*/
|
|
6
|
+
export declare function getProviderEnvValue(name: string, env?: ProviderEnv): string | undefined;
|
|
7
|
+
//# sourceMappingURL=provider-env.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider-env.d.ts","sourceRoot":"","sources":["../../src/utils/provider-env.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAwC/C;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,WAAW,GAAG,MAAM,GAAG,SAAS,CAOvF"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
let procEnvCache = null;
|
|
2
|
+
/**
|
|
3
|
+
* Fallback for https://github.com/oven-sh/bun/issues/27802.
|
|
4
|
+
* Bun compiled binaries can expose an empty process.env inside Linux sandboxes
|
|
5
|
+
* even though /proc/self/environ contains the environment.
|
|
6
|
+
*
|
|
7
|
+
* This intentionally duplicates restoreSandboxEnv() in
|
|
8
|
+
* packages/coding-agent/src/bun/restore-sandbox-env.ts. The ai package can be
|
|
9
|
+
* used directly, without going through that entrypoint, so provider env lookup
|
|
10
|
+
* must not depend on process.env having been patched.
|
|
11
|
+
*/
|
|
12
|
+
function getBunSandboxEnvValue(name) {
|
|
13
|
+
if (typeof process === "undefined" || !process.versions?.bun || Object.keys(process.env).length > 0) {
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
if (procEnvCache === null) {
|
|
17
|
+
procEnvCache = new Map();
|
|
18
|
+
try {
|
|
19
|
+
const { readFileSync } = require("node:fs");
|
|
20
|
+
const data = readFileSync("/proc/self/environ", "utf-8");
|
|
21
|
+
for (const entry of data.split("\0")) {
|
|
22
|
+
const idx = entry.indexOf("=");
|
|
23
|
+
if (idx > 0) {
|
|
24
|
+
procEnvCache.set(entry.slice(0, idx), entry.slice(idx + 1));
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
// /proc/self/environ may not exist or may not be readable.
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return procEnvCache.get(name);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Resolve a provider env value from scoped overrides, normal process.env, then
|
|
36
|
+
* the duplicated Bun sandbox fallback for direct pi-ai consumers.
|
|
37
|
+
*/
|
|
38
|
+
export function getProviderEnvValue(name, env) {
|
|
39
|
+
return (env?.[name] ||
|
|
40
|
+
(typeof process !== "undefined" ? process.env[name] : undefined) ||
|
|
41
|
+
getBunSandboxEnvValue(name) ||
|
|
42
|
+
undefined);
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=provider-env.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider-env.js","sourceRoot":"","sources":["../../src/utils/provider-env.ts"],"names":[],"mappings":"AAEA,IAAI,YAAY,GAA+B,IAAI,CAAC;AAEpD;;;;;;;;;GASG;AACH,SAAS,qBAAqB,CAAC,IAAY;IAC1C,IAAI,OAAO,OAAO,KAAK,WAAW,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACrG,OAAO,SAAS,CAAC;IAClB,CAAC;IAED,IAAI,YAAY,KAAK,IAAI,EAAE,CAAC;QAC3B,YAAY,GAAG,IAAI,GAAG,EAAE,CAAC;QACzB,IAAI,CAAC;YACJ,MAAM,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC,SAAS,CAEzC,CAAC;YACF,MAAM,IAAI,GAAG,YAAY,CAAC,oBAAoB,EAAE,OAAO,CAAC,CAAC;YACzD,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;gBACtC,MAAM,GAAG,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;gBAC/B,IAAI,GAAG,GAAG,CAAC,EAAE,CAAC;oBACb,YAAY,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,KAAK,CAAC,KAAK,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC;gBAC7D,CAAC;YACF,CAAC;QACF,CAAC;QAAC,MAAM,CAAC;YACR,2DAA2D;QAC5D,CAAC;IACF,CAAC;IAED,OAAO,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;AAC/B,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CAAC,IAAY,EAAE,GAAiB;IAClE,OAAO,CACN,GAAG,EAAE,CAAC,IAAI,CAAC;QACX,CAAC,OAAO,OAAO,KAAK,WAAW,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QAChE,qBAAqB,CAAC,IAAI,CAAC;QAC3B,SAAS,CACT,CAAC;AACH,CAAC","sourcesContent":["import type { ProviderEnv } from \"../types.ts\";\n\nlet procEnvCache: Map<string, string> | null = null;\n\n/**\n * Fallback for https://github.com/oven-sh/bun/issues/27802.\n * Bun compiled binaries can expose an empty process.env inside Linux sandboxes\n * even though /proc/self/environ contains the environment.\n *\n * This intentionally duplicates restoreSandboxEnv() in\n * packages/coding-agent/src/bun/restore-sandbox-env.ts. The ai package can be\n * used directly, without going through that entrypoint, so provider env lookup\n * must not depend on process.env having been patched.\n */\nfunction getBunSandboxEnvValue(name: string): string | undefined {\n\tif (typeof process === \"undefined\" || !process.versions?.bun || Object.keys(process.env).length > 0) {\n\t\treturn undefined;\n\t}\n\n\tif (procEnvCache === null) {\n\t\tprocEnvCache = new Map();\n\t\ttry {\n\t\t\tconst { readFileSync } = require(\"node:fs\") as {\n\t\t\t\treadFileSync(path: string, encoding: BufferEncoding): string;\n\t\t\t};\n\t\t\tconst data = readFileSync(\"/proc/self/environ\", \"utf-8\");\n\t\t\tfor (const entry of data.split(\"\\0\")) {\n\t\t\t\tconst idx = entry.indexOf(\"=\");\n\t\t\t\tif (idx > 0) {\n\t\t\t\t\tprocEnvCache.set(entry.slice(0, idx), entry.slice(idx + 1));\n\t\t\t\t}\n\t\t\t}\n\t\t} catch {\n\t\t\t// /proc/self/environ may not exist or may not be readable.\n\t\t}\n\t}\n\n\treturn procEnvCache.get(name);\n}\n\n/**\n * Resolve a provider env value from scoped overrides, normal process.env, then\n * the duplicated Bun sandbox fallback for direct pi-ai consumers.\n */\nexport function getProviderEnvValue(name: string, env?: ProviderEnv): string | undefined {\n\treturn (\n\t\tenv?.[name] ||\n\t\t(typeof process !== \"undefined\" ? process.env[name] : undefined) ||\n\t\tgetBunSandboxEnvValue(name) ||\n\t\tundefined\n\t);\n}\n"]}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { ProviderResponse } from "../types.ts";
|
|
2
|
+
interface ProviderRetryOptions {
|
|
3
|
+
maxRetries?: number;
|
|
4
|
+
maxRetryDelayMs?: number;
|
|
5
|
+
signal?: AbortSignal;
|
|
6
|
+
/** HTTP statuses that fail at once although the default policy would retry them. */
|
|
7
|
+
noRetryStatuses?: readonly number[];
|
|
8
|
+
/**
|
|
9
|
+
* Called for each attempt that failed with an HTTP status, before the retry decision. SDKs reject non-2xx
|
|
10
|
+
* responses, so this is the only place their status and headers reach the caller's `onResponse`.
|
|
11
|
+
*/
|
|
12
|
+
onErrorResponse?: (response: ProviderResponse) => void | Promise<void>;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Reproduce the retry behavior used by the OpenAI and Anthropic SDKs while making
|
|
16
|
+
* their backoff sleep interruptible. Their built-in retry timers ignore the
|
|
17
|
+
* request AbortSignal, so callers must invoke the SDK with `maxRetries: 0` and
|
|
18
|
+
* wrap the request with this helper. Provider-requested delays above
|
|
19
|
+
* `maxRetryDelayMs` fail immediately (60 seconds by default); set it to zero to
|
|
20
|
+
* disable the limit.
|
|
21
|
+
*/
|
|
22
|
+
export declare function retryProviderRequest<T>(request: () => Promise<T>, options?: ProviderRetryOptions): Promise<T>;
|
|
23
|
+
export {};
|
|
24
|
+
//# sourceMappingURL=provider-retry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider-retry.d.ts","sourceRoot":"","sources":["../../src/utils/provider-retry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAKpD,UAAU,oBAAoB;IAC7B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,oFAAoF;IACpF,eAAe,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACpC;;;OAGG;IACH,eAAe,CAAC,EAAE,CAAC,QAAQ,EAAE,gBAAgB,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACvE;AA0FD;;;;;;;GAOG;AACH,wBAAsB,oBAAoB,CAAC,CAAC,EAC3C,OAAO,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EACzB,OAAO,GAAE,oBAAyB,GAChC,OAAO,CAAC,CAAC,CAAC,CAsBZ"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { headersToRecord } from "./headers.js";
|
|
2
|
+
const DEFAULT_MAX_RETRY_DELAY_MS = 60_000;
|
|
3
|
+
function isProviderError(error) {
|
|
4
|
+
if (!(error instanceof Error) || !("status" in error) || !("headers" in error))
|
|
5
|
+
return false;
|
|
6
|
+
return ((error.status === undefined || typeof error.status === "number") &&
|
|
7
|
+
(error.headers === undefined || error.headers instanceof Headers));
|
|
8
|
+
}
|
|
9
|
+
/** Mirrors the pinned OpenAI/Anthropic SDK retry policy; review when either SDK is upgraded. */
|
|
10
|
+
function isRetryableProviderError(error) {
|
|
11
|
+
const shouldRetry = error.headers?.get("x-should-retry");
|
|
12
|
+
if (shouldRetry === "true")
|
|
13
|
+
return true;
|
|
14
|
+
if (shouldRetry === "false")
|
|
15
|
+
return false;
|
|
16
|
+
if (error.status === undefined)
|
|
17
|
+
return true;
|
|
18
|
+
return (error.status === 408 ||
|
|
19
|
+
error.status === 409 ||
|
|
20
|
+
error.status === 429 ||
|
|
21
|
+
(typeof error.status === "number" && error.status >= 500));
|
|
22
|
+
}
|
|
23
|
+
function validateServerRetryDelayMs(delayMs, maxRetryDelayMs, providerErrorMessage) {
|
|
24
|
+
const maxDelayMs = maxRetryDelayMs ?? DEFAULT_MAX_RETRY_DELAY_MS;
|
|
25
|
+
if (maxDelayMs > 0 && delayMs > maxDelayMs) {
|
|
26
|
+
throw new Error(`Server requested ${Math.ceil(delayMs / 1000)}s retry delay (max: ${Math.ceil(maxDelayMs / 1000)}s). ${providerErrorMessage}`);
|
|
27
|
+
}
|
|
28
|
+
return delayMs;
|
|
29
|
+
}
|
|
30
|
+
function getRetryDelayMs(error, retryIndex, maxRetryDelayMs) {
|
|
31
|
+
const retryAfterMs = error.headers?.get("retry-after-ms");
|
|
32
|
+
if (retryAfterMs) {
|
|
33
|
+
const value = Number.parseFloat(retryAfterMs);
|
|
34
|
+
if (Number.isFinite(value))
|
|
35
|
+
return validateServerRetryDelayMs(value, maxRetryDelayMs, error.message);
|
|
36
|
+
}
|
|
37
|
+
const retryAfter = error.headers?.get("retry-after");
|
|
38
|
+
if (retryAfter) {
|
|
39
|
+
const seconds = Number.parseFloat(retryAfter);
|
|
40
|
+
const delayMs = Number.isNaN(seconds) ? Date.parse(retryAfter) - Date.now() : seconds * 1000;
|
|
41
|
+
if (Number.isFinite(delayMs))
|
|
42
|
+
return validateServerRetryDelayMs(delayMs, maxRetryDelayMs, error.message);
|
|
43
|
+
}
|
|
44
|
+
const exponentialDelay = Math.min(0.5 * 2 ** retryIndex, 8) * 1000;
|
|
45
|
+
return exponentialDelay * (1 - Math.random() * 0.25);
|
|
46
|
+
}
|
|
47
|
+
function createAbortError() {
|
|
48
|
+
const error = new Error("Request aborted");
|
|
49
|
+
error.name = "AbortError";
|
|
50
|
+
return error;
|
|
51
|
+
}
|
|
52
|
+
function abortableSleep(ms, signal) {
|
|
53
|
+
return new Promise((resolve, reject) => {
|
|
54
|
+
if (signal?.aborted) {
|
|
55
|
+
reject(createAbortError());
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
const onAbort = () => {
|
|
59
|
+
clearTimeout(timeout);
|
|
60
|
+
reject(createAbortError());
|
|
61
|
+
};
|
|
62
|
+
const timeout = setTimeout(() => {
|
|
63
|
+
signal?.removeEventListener("abort", onAbort);
|
|
64
|
+
resolve();
|
|
65
|
+
}, Math.max(0, ms));
|
|
66
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Reproduce the retry behavior used by the OpenAI and Anthropic SDKs while making
|
|
71
|
+
* their backoff sleep interruptible. Their built-in retry timers ignore the
|
|
72
|
+
* request AbortSignal, so callers must invoke the SDK with `maxRetries: 0` and
|
|
73
|
+
* wrap the request with this helper. Provider-requested delays above
|
|
74
|
+
* `maxRetryDelayMs` fail immediately (60 seconds by default); set it to zero to
|
|
75
|
+
* disable the limit.
|
|
76
|
+
*/
|
|
77
|
+
export async function retryProviderRequest(request, options = {}) {
|
|
78
|
+
const maxRetries = options.maxRetries ?? 0;
|
|
79
|
+
let retriesRemaining = maxRetries;
|
|
80
|
+
for (;;) {
|
|
81
|
+
try {
|
|
82
|
+
// Each retry is a fresh SDK request, so X-Stainless-Retry-Count remains zero.
|
|
83
|
+
return await request();
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
if (options.signal?.aborted)
|
|
87
|
+
throw createAbortError();
|
|
88
|
+
if (isProviderError(error) && error.status !== undefined) {
|
|
89
|
+
const headers = error.headers ? headersToRecord(error.headers) : {};
|
|
90
|
+
await options.onErrorResponse?.({ status: error.status, headers });
|
|
91
|
+
}
|
|
92
|
+
if (retriesRemaining <= 0 || !isProviderError(error) || !isRetryableProviderError(error))
|
|
93
|
+
throw error;
|
|
94
|
+
if (error.status !== undefined && options.noRetryStatuses?.includes(error.status))
|
|
95
|
+
throw error;
|
|
96
|
+
const retryIndex = maxRetries - retriesRemaining;
|
|
97
|
+
retriesRemaining--;
|
|
98
|
+
await abortableSleep(getRetryDelayMs(error, retryIndex, options.maxRetryDelayMs), options.signal);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=provider-retry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider-retry.js","sourceRoot":"","sources":["../../src/utils/provider-retry.ts"],"names":[],"mappings":"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","sourcesContent":["import type { ProviderResponse } from \"../types.ts\";\nimport { headersToRecord } from \"./headers.ts\";\n\nconst DEFAULT_MAX_RETRY_DELAY_MS = 60_000;\n\ninterface ProviderRetryOptions {\n\tmaxRetries?: number;\n\tmaxRetryDelayMs?: number;\n\tsignal?: AbortSignal;\n\t/** HTTP statuses that fail at once although the default policy would retry them. */\n\tnoRetryStatuses?: readonly number[];\n\t/**\n\t * Called for each attempt that failed with an HTTP status, before the retry decision. SDKs reject non-2xx\n\t * responses, so this is the only place their status and headers reach the caller's `onResponse`.\n\t */\n\tonErrorResponse?: (response: ProviderResponse) => void | Promise<void>;\n}\n\ninterface ProviderError extends Error {\n\tstatus: number | undefined;\n\theaders: Headers | undefined;\n}\n\nfunction isProviderError(error: unknown): error is ProviderError {\n\tif (!(error instanceof Error) || !(\"status\" in error) || !(\"headers\" in error)) return false;\n\treturn (\n\t\t(error.status === undefined || typeof error.status === \"number\") &&\n\t\t(error.headers === undefined || error.headers instanceof Headers)\n\t);\n}\n\n/** Mirrors the pinned OpenAI/Anthropic SDK retry policy; review when either SDK is upgraded. */\nfunction isRetryableProviderError(error: ProviderError): boolean {\n\tconst shouldRetry = error.headers?.get(\"x-should-retry\");\n\tif (shouldRetry === \"true\") return true;\n\tif (shouldRetry === \"false\") return false;\n\n\tif (error.status === undefined) return true;\n\treturn (\n\t\terror.status === 408 ||\n\t\terror.status === 409 ||\n\t\terror.status === 429 ||\n\t\t(typeof error.status === \"number\" && error.status >= 500)\n\t);\n}\n\nfunction validateServerRetryDelayMs(\n\tdelayMs: number,\n\tmaxRetryDelayMs: number | undefined,\n\tproviderErrorMessage: string,\n): number {\n\tconst maxDelayMs = maxRetryDelayMs ?? DEFAULT_MAX_RETRY_DELAY_MS;\n\tif (maxDelayMs > 0 && delayMs > maxDelayMs) {\n\t\tthrow new Error(\n\t\t\t`Server requested ${Math.ceil(delayMs / 1000)}s retry delay (max: ${Math.ceil(maxDelayMs / 1000)}s). ${providerErrorMessage}`,\n\t\t);\n\t}\n\treturn delayMs;\n}\n\nfunction getRetryDelayMs(error: ProviderError, retryIndex: number, maxRetryDelayMs: number | undefined): number {\n\tconst retryAfterMs = error.headers?.get(\"retry-after-ms\");\n\tif (retryAfterMs) {\n\t\tconst value = Number.parseFloat(retryAfterMs);\n\t\tif (Number.isFinite(value)) return validateServerRetryDelayMs(value, maxRetryDelayMs, error.message);\n\t}\n\n\tconst retryAfter = error.headers?.get(\"retry-after\");\n\tif (retryAfter) {\n\t\tconst seconds = Number.parseFloat(retryAfter);\n\t\tconst delayMs = Number.isNaN(seconds) ? Date.parse(retryAfter) - Date.now() : seconds * 1000;\n\t\tif (Number.isFinite(delayMs)) return validateServerRetryDelayMs(delayMs, maxRetryDelayMs, error.message);\n\t}\n\n\tconst exponentialDelay = Math.min(0.5 * 2 ** retryIndex, 8) * 1000;\n\treturn exponentialDelay * (1 - Math.random() * 0.25);\n}\n\nfunction createAbortError(): Error {\n\tconst error = new Error(\"Request aborted\");\n\terror.name = \"AbortError\";\n\treturn error;\n}\n\nfunction abortableSleep(ms: number, signal?: AbortSignal): Promise<void> {\n\treturn new Promise((resolve, reject) => {\n\t\tif (signal?.aborted) {\n\t\t\treject(createAbortError());\n\t\t\treturn;\n\t\t}\n\n\t\tconst onAbort = () => {\n\t\t\tclearTimeout(timeout);\n\t\t\treject(createAbortError());\n\t\t};\n\t\tconst timeout = setTimeout(\n\t\t\t() => {\n\t\t\t\tsignal?.removeEventListener(\"abort\", onAbort);\n\t\t\t\tresolve();\n\t\t\t},\n\t\t\tMath.max(0, ms),\n\t\t);\n\t\tsignal?.addEventListener(\"abort\", onAbort, { once: true });\n\t});\n}\n\n/**\n * Reproduce the retry behavior used by the OpenAI and Anthropic SDKs while making\n * their backoff sleep interruptible. Their built-in retry timers ignore the\n * request AbortSignal, so callers must invoke the SDK with `maxRetries: 0` and\n * wrap the request with this helper. Provider-requested delays above\n * `maxRetryDelayMs` fail immediately (60 seconds by default); set it to zero to\n * disable the limit.\n */\nexport async function retryProviderRequest<T>(\n\trequest: () => Promise<T>,\n\toptions: ProviderRetryOptions = {},\n): Promise<T> {\n\tconst maxRetries = options.maxRetries ?? 0;\n\tlet retriesRemaining = maxRetries;\n\n\tfor (;;) {\n\t\ttry {\n\t\t\t// Each retry is a fresh SDK request, so X-Stainless-Retry-Count remains zero.\n\t\t\treturn await request();\n\t\t} catch (error) {\n\t\t\tif (options.signal?.aborted) throw createAbortError();\n\t\t\tif (isProviderError(error) && error.status !== undefined) {\n\t\t\t\tconst headers = error.headers ? headersToRecord(error.headers) : {};\n\t\t\t\tawait options.onErrorResponse?.({ status: error.status, headers });\n\t\t\t}\n\t\t\tif (retriesRemaining <= 0 || !isProviderError(error) || !isRetryableProviderError(error)) throw error;\n\t\t\tif (error.status !== undefined && options.noRetryStatuses?.includes(error.status)) throw error;\n\n\t\t\tconst retryIndex = maxRetries - retriesRemaining;\n\t\t\tretriesRemaining--;\n\t\t\tawait abortableSleep(getRetryDelayMs(error, retryIndex, options.maxRetryDelayMs), options.signal);\n\t\t}\n\t}\n}\n"]}
|