@ny4n/ai 0.0.0-stage → 1.0.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/LICENSE +21 -0
- package/README.md +1940 -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 +1310 -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 +194 -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 +1147 -0
- package/dist/api/bedrock-converse-stream.js.map +1 -0
- package/dist/api/bedrock-converse-stream.lazy.d.ts +9 -0
- package/dist/api/bedrock-converse-stream.lazy.d.ts.map +1 -0
- package/dist/api/bedrock-converse-stream.lazy.js +30 -0
- package/dist/api/bedrock-converse-stream.lazy.js.map +1 -0
- package/dist/api/classifier-shared.d.ts +21 -0
- package/dist/api/classifier-shared.d.ts.map +1 -0
- package/dist/api/classifier-shared.js +98 -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 +49 -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 +26 -0
- package/dist/api/constrained-sampling.d.ts.map +1 -0
- package/dist/api/constrained-sampling.js +233 -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 +370 -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 +93 -0
- package/dist/api/google-shared.d.ts.map +1 -0
- package/dist/api/google-shared.js +451 -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 +431 -0
- package/dist/api/google-vertex.js.map +1 -0
- package/dist/api/google-vertex.lazy.d.ts +3 -0
- package/dist/api/google-vertex.lazy.d.ts.map +1 -0
- package/dist/api/google-vertex.lazy.js +3 -0
- package/dist/api/google-vertex.lazy.js.map +1 -0
- package/dist/api/lazy.d.ts +19 -0
- package/dist/api/lazy.d.ts.map +1 -0
- package/dist/api/lazy.js +71 -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 +367 -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 +766 -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 +1321 -0
- package/dist/api/openai-codex-responses.js.map +1 -0
- package/dist/api/openai-codex-responses.lazy.d.ts +3 -0
- package/dist/api/openai-codex-responses.lazy.d.ts.map +1 -0
- package/dist/api/openai-codex-responses.lazy.js +3 -0
- package/dist/api/openai-codex-responses.lazy.js.map +1 -0
- package/dist/api/openai-completions.d.ts +26 -0
- package/dist/api/openai-completions.d.ts.map +1 -0
- package/dist/api/openai-completions.js +1345 -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 +29 -0
- package/dist/api/openai-responses-shared.d.ts.map +1 -0
- package/dist/api/openai-responses-shared.js +704 -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 +314 -0
- package/dist/api/openai-responses.js.map +1 -0
- package/dist/api/openai-responses.lazy.d.ts +3 -0
- package/dist/api/openai-responses.lazy.d.ts.map +1 -0
- package/dist/api/openai-responses.lazy.js +3 -0
- package/dist/api/openai-responses.lazy.js.map +1 -0
- package/dist/api/openrouter-images.d.ts +4 -0
- package/dist/api/openrouter-images.d.ts.map +1 -0
- package/dist/api/openrouter-images.js +133 -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/simple-options.d.ts +16 -0
- package/dist/api/simple-options.d.ts.map +1 -0
- package/dist/api/simple-options.js +73 -0
- package/dist/api/simple-options.js.map +1 -0
- package/dist/api/system-one-shared.d.ts +22 -0
- package/dist/api/system-one-shared.d.ts.map +1 -0
- package/dist/api/system-one-shared.js +99 -0
- package/dist/api/system-one-shared.js.map +1 -0
- package/dist/api/transform-messages.d.ts +8 -0
- package/dist/api/transform-messages.d.ts.map +1 -0
- package/dist/api/transform-messages.js +201 -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 +20 -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/api-options.d.ts +39 -0
- package/dist/api-options.d.ts.map +1 -0
- package/dist/api-options.js +9 -0
- package/dist/api-options.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 +146 -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 +392 -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 +248 -0
- package/dist/auth/oauth/kimi-coding.js.map +1 -0
- package/dist/auth/oauth/load.d.ts +23 -0
- package/dist/auth/oauth/load.d.ts.map +1 -0
- package/dist/auth/oauth/load.js +64 -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 +190 -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 +263 -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/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 +245 -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 +23 -0
- package/dist/bun-oauth.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +115 -0
- package/dist/cli.js.map +1 -0
- package/dist/compat/extension-oauth-types.d.ts +39 -0
- package/dist/compat/extension-oauth-types.d.ts.map +1 -0
- package/dist/compat/extension-oauth-types.js +2 -0
- package/dist/compat/extension-oauth-types.js.map +1 -0
- package/dist/compat.d.ts +66 -0
- package/dist/compat.d.ts.map +1 -0
- package/dist/compat.js +199 -0
- package/dist/compat.js.map +1 -0
- package/dist/contracts/index.d.ts +30 -0
- package/dist/contracts/index.d.ts.map +1 -0
- package/dist/contracts/index.js +12 -0
- package/dist/contracts/index.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 +162 -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 +36 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +24 -0
- package/dist/index.js.map +1 -0
- package/dist/legacy-api-aliases.d.ts +42 -0
- package/dist/legacy-api-aliases.d.ts.map +1 -0
- package/dist/legacy-api-aliases.js +49 -0
- package/dist/legacy-api-aliases.js.map +1 -0
- package/dist/model-catalog.d.ts +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 +250 -0
- package/dist/models.d.ts.map +1 -0
- package/dist/models.generated.d.ts +171 -0
- package/dist/models.generated.d.ts.map +1 -0
- package/dist/models.generated.js +173 -0
- package/dist/models.generated.js.map +1 -0
- package/dist/models.js +644 -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 +31 -0
- package/dist/providers/all.d.ts.map +1 -0
- package/dist/providers/all.js +134 -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 +15 -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/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.json +1 -0
- package/dist/providers/data/qwen-token-plan.json +1 -0
- package/dist/providers/data/together.json +1 -0
- package/dist/providers/data/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 +506 -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 +3 -0
- package/dist/providers/github-copilot.d.ts.map +1 -0
- package/dist/providers/github-copilot.js +35 -0
- package/dist/providers/github-copilot.js.map +1 -0
- package/dist/providers/github-copilot.models.d.ts +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 +4 -0
- package/dist/providers/images/register-builtins.d.ts.map +1 -0
- package/dist/providers/images/register-builtins.js +34 -0
- package/dist/providers/images/register-builtins.js.map +1 -0
- package/dist/providers/kimi-coding.d.ts +3 -0
- package/dist/providers/kimi-coding.d.ts.map +1 -0
- package/dist/providers/kimi-coding.js +24 -0
- package/dist/providers/kimi-coding.js.map +1 -0
- package/dist/providers/kimi-coding.models.d.ts +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/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 +3 -0
- package/dist/providers/opencode-go.d.ts.map +1 -0
- package/dist/providers/opencode-go.js +21 -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.d.ts +3 -0
- package/dist/providers/openrouter.d.ts.map +1 -0
- package/dist/providers/openrouter.js +36 -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 +15 -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.d.ts +3 -0
- package/dist/providers/qwen-token-plan-individual.d.ts.map +1 -0
- package/dist/providers/qwen-token-plan-individual.js +15 -0
- package/dist/providers/qwen-token-plan-individual.js.map +1 -0
- package/dist/providers/qwen-token-plan-individual.models.d.ts +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 +15 -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/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/schemas/compat-schema.d.ts +338 -0
- package/dist/schemas/compat-schema.d.ts.map +1 -0
- package/dist/schemas/compat-schema.js +375 -0
- package/dist/schemas/compat-schema.js.map +1 -0
- package/dist/schemas/model-schema.d.ts +91 -0
- package/dist/schemas/model-schema.d.ts.map +1 -0
- package/dist/schemas/model-schema.js +55 -0
- package/dist/schemas/model-schema.js.map +1 -0
- package/dist/session-resources.d.ts +4 -0
- package/dist/session-resources.d.ts.map +1 -0
- package/dist/session-resources.js +22 -0
- package/dist/session-resources.js.map +1 -0
- package/dist/types.d.ts +645 -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/assistant-message-frame.d.ts +77 -0
- package/dist/utils/assistant-message-frame.d.ts.map +1 -0
- package/dist/utils/assistant-message-frame.js +425 -0
- package/dist/utils/assistant-message-frame.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 +25 -0
- package/dist/utils/error-body.d.ts.map +1 -0
- package/dist/utils/error-body.js +133 -0
- package/dist/utils/error-body.js.map +1 -0
- package/dist/utils/estimate.d.ts +17 -0
- package/dist/utils/estimate.d.ts.map +1 -0
- package/dist/utils/estimate.js +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/json-parse.d.ts +16 -0
- package/dist/utils/json-parse.d.ts.map +1 -0
- package/dist/utils/json-parse.js +113 -0
- package/dist/utils/json-parse.js.map +1 -0
- package/dist/utils/model-operations.d.ts +34 -0
- package/dist/utils/model-operations.d.ts.map +1 -0
- package/dist/utils/model-operations.js +129 -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/nyan-user-agent.d.ts +2 -0
- package/dist/utils/nyan-user-agent.d.ts.map +1 -0
- package/dist/utils/nyan-user-agent.js +12 -0
- package/dist/utils/nyan-user-agent.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/overflow.d.ts +69 -0
- package/dist/utils/overflow.d.ts.map +1 -0
- package/dist/utils/overflow.js +179 -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 +18 -0
- package/dist/utils/provider-retry.d.ts.map +1 -0
- package/dist/utils/provider-retry.js +97 -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 +196 -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/text.d.ts +14 -0
- package/dist/utils/text.d.ts.map +1 -0
- package/dist/utils/text.js +36 -0
- package/dist/utils/text.js.map +1 -0
- package/dist/utils/transcript.d.ts +87 -0
- package/dist/utils/transcript.d.ts.map +1 -0
- package/dist/utils/transcript.js +207 -0
- package/dist/utils/transcript.js.map +1 -0
- package/dist/utils/typebox-helpers.d.ts +17 -0
- package/dist/utils/typebox-helpers.d.ts.map +1 -0
- package/dist/utils/typebox-helpers.js +21 -0
- package/dist/utils/typebox-helpers.js.map +1 -0
- package/dist/utils/uuid.d.ts +3 -0
- package/dist/utils/uuid.d.ts.map +1 -0
- package/dist/utils/uuid.js +42 -0
- package/dist/utils/uuid.js.map +1 -0
- package/dist/utils/validation.d.ts +18 -0
- package/dist/utils/validation.d.ts.map +1 -0
- package/dist/utils/validation.js +309 -0
- package/dist/utils/validation.js.map +1 -0
- package/package.json +113 -5
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { isRecord } from "./classifier-shared.js";
|
|
2
|
+
import { classifySystemOne } from "./system-one-shared.js";
|
|
3
|
+
const LABEL = "Cloudflare Workers AI";
|
|
4
|
+
function cloudflareErrorMessage(errors) {
|
|
5
|
+
if (Array.isArray(errors)) {
|
|
6
|
+
const messages = errors
|
|
7
|
+
.map((error) => (isRecord(error) && typeof error.message === "string" ? error.message : undefined))
|
|
8
|
+
.filter((message) => message !== undefined);
|
|
9
|
+
if (messages.length > 0)
|
|
10
|
+
return `${LABEL} error: ${messages.join("; ")}`;
|
|
11
|
+
}
|
|
12
|
+
return `${LABEL} request failed`;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* System One models on the Workers AI REST endpoint:
|
|
16
|
+
* `POST /accounts/{account}/ai/run` with `{ model, input }`. The REST API wraps the model
|
|
17
|
+
* output in Cloudflare's API envelope. Third-party models such as `typesafe/jev` add a run record:
|
|
18
|
+
* `{ success, result: { state: "Completed", result: { answers, usage } } }`.
|
|
19
|
+
* https://developers.cloudflare.com/ai/models/typesafe/jev/
|
|
20
|
+
* Cloudflare-hosted models such as `@cf/cloudflare/clef` return the output directly:
|
|
21
|
+
* `{ success, result: { model, answers, usage } }`.
|
|
22
|
+
* https://developers.cloudflare.com/workers-ai/models/clef/
|
|
23
|
+
*/
|
|
24
|
+
const transport = {
|
|
25
|
+
api: "cloudflare-workers-ai-system-one",
|
|
26
|
+
label: LABEL,
|
|
27
|
+
url: (model) => new URL("run", `${model.baseUrl.replace(/\/+$/u, "")}/`),
|
|
28
|
+
payload: (model, request) => ({ model: model.id, input: request }),
|
|
29
|
+
output: (body) => {
|
|
30
|
+
if (!isRecord(body))
|
|
31
|
+
throw new Error(`${LABEL} returned an unexpected response`);
|
|
32
|
+
if (body.success === false)
|
|
33
|
+
throw new Error(cloudflareErrorMessage(body.errors));
|
|
34
|
+
const result = body.result;
|
|
35
|
+
if (!isRecord(result))
|
|
36
|
+
throw new Error(`${LABEL} returned an unexpected response`);
|
|
37
|
+
if ("answers" in result)
|
|
38
|
+
return result;
|
|
39
|
+
if (result.state !== "Completed") {
|
|
40
|
+
throw new Error(`${LABEL} run did not complete (state: ${String(result.state)})`);
|
|
41
|
+
}
|
|
42
|
+
if (!isRecord(result.result))
|
|
43
|
+
throw new Error(`${LABEL} returned an unexpected response`);
|
|
44
|
+
return result.result;
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
/** Cloudflare Workers AI System One classification with public `bool` values mapped to wire-level `noul`. */
|
|
48
|
+
export const classify = (model, context, options) => classifySystemOne(transport, model, context, options);
|
|
49
|
+
//# sourceMappingURL=cloudflare-workers-ai-system-one.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cloudflare-workers-ai-system-one.js","sourceRoot":"","sources":["../../src/api/cloudflare-workers-ai-system-one.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAClD,OAAO,EAAE,iBAAiB,EAA2B,MAAM,wBAAwB,CAAC;AAEpF,MAAM,KAAK,GAAG,uBAAuB,CAAC;AAEtC,SAAS,sBAAsB,CAAC,MAAe;IAC9C,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAA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,CAAC,MAAM,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,GAAG,KAAK,kCAAkC,CAAC,CAAC;QACnF,IAAI,SAAS,IAAI,MAAM;YAAE,OAAO,MAAM,CAAC;QACvC,IAAI,MAAM,CAAC,KAAK,KAAK,WAAW,EAAE,CAAC;YAClC,MAAM,IAAI,KAAK,CAAC,GAAG,KAAK,iCAAiC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACnF,CAAC;QACD,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,GAAG,KAAK,kCAAkC,CAAC,CAAC;QAC1F,OAAO,MAAM,CAAC,MAAM,CAAC;IACtB,CAAC;CACD,CAAC;AAEF,6GAA6G;AAC7G,MAAM,CAAC,MAAM,QAAQ,GAA0C,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,CAC1F,iBAAiB,CAAC,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC","sourcesContent":["import type { ClassifierFunction, ClassifierOptions } from \"../types.ts\";\nimport { isRecord } from \"./classifier-shared.ts\";\nimport { classifySystemOne, type SystemOneTransport } from \"./system-one-shared.ts\";\n\nconst LABEL = \"Cloudflare Workers AI\";\n\nfunction cloudflareErrorMessage(errors: unknown): string {\n\tif (Array.isArray(errors)) {\n\t\tconst messages = errors\n\t\t\t.map((error) => (isRecord(error) && typeof error.message === \"string\" ? error.message : undefined))\n\t\t\t.filter((message): message is string => message !== undefined);\n\t\tif (messages.length > 0) return `${LABEL} error: ${messages.join(\"; \")}`;\n\t}\n\treturn `${LABEL} request failed`;\n}\n\n/**\n * System One models on the Workers AI REST endpoint:\n * `POST /accounts/{account}/ai/run` with `{ model, input }`. The REST API wraps the model\n * output in Cloudflare's API envelope. Third-party models such as `typesafe/jev` add a run record:\n * `{ success, result: { state: \"Completed\", result: { answers, usage } } }`.\n * https://developers.cloudflare.com/ai/models/typesafe/jev/\n * Cloudflare-hosted models such as `@cf/cloudflare/clef` return the output directly:\n * `{ success, result: { model, answers, usage } }`.\n * https://developers.cloudflare.com/workers-ai/models/clef/\n */\nconst transport: SystemOneTransport = {\n\tapi: \"cloudflare-workers-ai-system-one\",\n\tlabel: LABEL,\n\turl: (model) => new URL(\"run\", `${model.baseUrl.replace(/\\/+$/u, \"\")}/`),\n\tpayload: (model, request) => ({ model: model.id, input: request }),\n\toutput: (body) => {\n\t\tif (!isRecord(body)) throw new Error(`${LABEL} returned an unexpected response`);\n\t\tif (body.success === false) throw new Error(cloudflareErrorMessage(body.errors));\n\t\tconst result = body.result;\n\t\tif (!isRecord(result)) throw new Error(`${LABEL} returned an unexpected response`);\n\t\tif (\"answers\" in result) return result;\n\t\tif (result.state !== \"Completed\") {\n\t\t\tthrow new Error(`${LABEL} run did not complete (state: ${String(result.state)})`);\n\t\t}\n\t\tif (!isRecord(result.result)) throw new Error(`${LABEL} returned an unexpected response`);\n\t\treturn result.result;\n\t},\n};\n\n/** Cloudflare Workers AI System One classification with public `bool` values mapped to wire-level `noul`. */\nexport const classify: ClassifierFunction<ClassifierOptions> = (model, context, options) =>\n\tclassifySystemOne(transport, model, context, options);\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cloudflare-workers-ai-system-one.lazy.d.ts","sourceRoot":"","sources":["../../src/api/cloudflare-workers-ai-system-one.lazy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEtD,eAAO,MAAM,+BAA+B,QAAO,kBAGjD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cloudflare-workers-ai-system-one.lazy.js","sourceRoot":"","sources":["../../src/api/cloudflare-workers-ai-system-one.lazy.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,+BAA+B,GAAG,GAAuB,EAAE,CAAC,CAAC;IACzE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,CAC3C,CAAC,MAAM,MAAM,CAAC,uCAAuC,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC;CAC1F,CAAC,CAAC","sourcesContent":["import type { ProviderClassifier } from \"../types.ts\";\n\nexport const cloudflareWorkersAISystemOneApi = (): ProviderClassifier => ({\n\tclassify: async (model, context, options) =>\n\t\t(await import(\"./cloudflare-workers-ai-system-one.ts\")).classify(model, context, options),\n});\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** Workers AI direct endpoint. */
|
|
2
|
+
export declare const CLOUDFLARE_WORKERS_AI_BASE_URL = "https://api.cloudflare.com/client/v4/accounts/{CLOUDFLARE_ACCOUNT_ID}/ai/v1";
|
|
3
|
+
/** Workers AI REST endpoint root; model runs are posted to `run`. */
|
|
4
|
+
export declare const CLOUDFLARE_WORKERS_AI_REST_BASE_URL = "https://api.cloudflare.com/client/v4/accounts/{CLOUDFLARE_ACCOUNT_ID}/ai";
|
|
5
|
+
/** AI Gateway Unified API. https://developers.cloudflare.com/ai-gateway/usage/unified-api/ */
|
|
6
|
+
export declare const CLOUDFLARE_AI_GATEWAY_COMPAT_BASE_URL = "https://gateway.ai.cloudflare.com/v1/{CLOUDFLARE_ACCOUNT_ID}/{CLOUDFLARE_GATEWAY_ID}/compat";
|
|
7
|
+
/** AI Gateway → OpenAI passthrough. Used until /compat supports /v1/responses. */
|
|
8
|
+
export declare const CLOUDFLARE_AI_GATEWAY_OPENAI_BASE_URL = "https://gateway.ai.cloudflare.com/v1/{CLOUDFLARE_ACCOUNT_ID}/{CLOUDFLARE_GATEWAY_ID}/openai";
|
|
9
|
+
/** AI Gateway → Anthropic passthrough. */
|
|
10
|
+
export declare const CLOUDFLARE_AI_GATEWAY_ANTHROPIC_BASE_URL = "https://gateway.ai.cloudflare.com/v1/{CLOUDFLARE_ACCOUNT_ID}/{CLOUDFLARE_GATEWAY_ID}/anthropic";
|
|
11
|
+
//# sourceMappingURL=cloudflare.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cloudflare.d.ts","sourceRoot":"","sources":["../../src/api/cloudflare.ts"],"names":[],"mappings":"AAAA,kCAAkC;AAClC,eAAO,MAAM,8BAA8B,gFACmC,CAAC;AAE/E,qEAAqE;AACrE,eAAO,MAAM,mCAAmC,6EAC2B,CAAC;AAE5E,8FAA8F;AAC9F,eAAO,MAAM,qCAAqC,gGAC4C,CAAC;AAE/F,kFAAkF;AAClF,eAAO,MAAM,qCAAqC,gGAC4C,CAAC;AAE/F,0CAA0C;AAC1C,eAAO,MAAM,wCAAwC,mGAC4C,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** Workers AI direct endpoint. */
|
|
2
|
+
export const CLOUDFLARE_WORKERS_AI_BASE_URL = "https://api.cloudflare.com/client/v4/accounts/{CLOUDFLARE_ACCOUNT_ID}/ai/v1";
|
|
3
|
+
/** Workers AI REST endpoint root; model runs are posted to `run`. */
|
|
4
|
+
export const CLOUDFLARE_WORKERS_AI_REST_BASE_URL = "https://api.cloudflare.com/client/v4/accounts/{CLOUDFLARE_ACCOUNT_ID}/ai";
|
|
5
|
+
/** AI Gateway Unified API. https://developers.cloudflare.com/ai-gateway/usage/unified-api/ */
|
|
6
|
+
export const CLOUDFLARE_AI_GATEWAY_COMPAT_BASE_URL = "https://gateway.ai.cloudflare.com/v1/{CLOUDFLARE_ACCOUNT_ID}/{CLOUDFLARE_GATEWAY_ID}/compat";
|
|
7
|
+
/** AI Gateway → OpenAI passthrough. Used until /compat supports /v1/responses. */
|
|
8
|
+
export const CLOUDFLARE_AI_GATEWAY_OPENAI_BASE_URL = "https://gateway.ai.cloudflare.com/v1/{CLOUDFLARE_ACCOUNT_ID}/{CLOUDFLARE_GATEWAY_ID}/openai";
|
|
9
|
+
/** AI Gateway → Anthropic passthrough. */
|
|
10
|
+
export const CLOUDFLARE_AI_GATEWAY_ANTHROPIC_BASE_URL = "https://gateway.ai.cloudflare.com/v1/{CLOUDFLARE_ACCOUNT_ID}/{CLOUDFLARE_GATEWAY_ID}/anthropic";
|
|
11
|
+
//# sourceMappingURL=cloudflare.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cloudflare.js","sourceRoot":"","sources":["../../src/api/cloudflare.ts"],"names":[],"mappings":"AAAA,kCAAkC;AAClC,MAAM,CAAC,MAAM,8BAA8B,GAC1C,6EAA6E,CAAC;AAE/E,qEAAqE;AACrE,MAAM,CAAC,MAAM,mCAAmC,GAC/C,0EAA0E,CAAC;AAE5E,8FAA8F;AAC9F,MAAM,CAAC,MAAM,qCAAqC,GACjD,6FAA6F,CAAC;AAE/F,kFAAkF;AAClF,MAAM,CAAC,MAAM,qCAAqC,GACjD,6FAA6F,CAAC;AAE/F,0CAA0C;AAC1C,MAAM,CAAC,MAAM,wCAAwC,GACpD,gGAAgG,CAAC","sourcesContent":["/** Workers AI direct endpoint. */\nexport const CLOUDFLARE_WORKERS_AI_BASE_URL =\n\t\"https://api.cloudflare.com/client/v4/accounts/{CLOUDFLARE_ACCOUNT_ID}/ai/v1\";\n\n/** Workers AI REST endpoint root; model runs are posted to `run`. */\nexport const CLOUDFLARE_WORKERS_AI_REST_BASE_URL =\n\t\"https://api.cloudflare.com/client/v4/accounts/{CLOUDFLARE_ACCOUNT_ID}/ai\";\n\n/** AI Gateway Unified API. https://developers.cloudflare.com/ai-gateway/usage/unified-api/ */\nexport const CLOUDFLARE_AI_GATEWAY_COMPAT_BASE_URL =\n\t\"https://gateway.ai.cloudflare.com/v1/{CLOUDFLARE_ACCOUNT_ID}/{CLOUDFLARE_GATEWAY_ID}/compat\";\n\n/** AI Gateway → OpenAI passthrough. Used until /compat supports /v1/responses. */\nexport const CLOUDFLARE_AI_GATEWAY_OPENAI_BASE_URL =\n\t\"https://gateway.ai.cloudflare.com/v1/{CLOUDFLARE_ACCOUNT_ID}/{CLOUDFLARE_GATEWAY_ID}/openai\";\n\n/** AI Gateway → Anthropic passthrough. */\nexport const CLOUDFLARE_AI_GATEWAY_ANTHROPIC_BASE_URL =\n\t\"https://gateway.ai.cloudflare.com/v1/{CLOUDFLARE_ACCOUNT_ID}/{CLOUDFLARE_GATEWAY_ID}/anthropic\";\n"]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Tool } from "../types.ts";
|
|
2
|
+
/** Returns true when a provider's strict mode rejects this schema keyword with this value. */
|
|
3
|
+
export type UnsupportedStrictSchemaKeywordCheck = (key: string, value: unknown) => boolean;
|
|
4
|
+
/** Convert a tool schema to the strict subset expected by provider constrained sampling. */
|
|
5
|
+
export declare function makeStrictJsonSchema(schema: Tool["parameters"], isUnsupportedKeyword?: UnsupportedStrictSchemaKeywordCheck): Record<string, unknown>;
|
|
6
|
+
export declare function getJsonSchemaToolParameters(tool: Tool, strict: boolean | undefined): Tool["parameters"];
|
|
7
|
+
export interface GrammarConstrainedSampling {
|
|
8
|
+
format: "lark" | "regex";
|
|
9
|
+
definition: string;
|
|
10
|
+
inputProperty: string;
|
|
11
|
+
}
|
|
12
|
+
export interface GrammarToolInputJsonBuffer {
|
|
13
|
+
input: string;
|
|
14
|
+
started: boolean;
|
|
15
|
+
closed: boolean;
|
|
16
|
+
}
|
|
17
|
+
export declare function getGrammarToolInput(toolName: string, arguments_: Record<string, unknown>, inputProperty: string): string;
|
|
18
|
+
export declare function appendGrammarToolInputJsonDelta(buffer: GrammarToolInputJsonBuffer, inputProperty: string, nextInput: string, close: boolean): string | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* Decide whether a JSON-schema tool is sent in strict mode. `isUnsupportedKeyword` lets a provider
|
|
21
|
+
* reject extra keywords its strict mode does not accept, so "prefer" tools fall back to non-strict.
|
|
22
|
+
*/
|
|
23
|
+
export declare function resolveJsonSchemaStrictSampling(tool: Tool, supportsStrictMode: boolean, isUnsupportedKeyword?: UnsupportedStrictSchemaKeywordCheck): boolean | undefined;
|
|
24
|
+
export declare function resolveGrammarConstrainedSampling(tool: Tool, supportsOpenAIGrammarTools: boolean): GrammarConstrainedSampling | undefined;
|
|
25
|
+
export declare function createGrammarToolInputProperties(tools: Tool[] | undefined, supportsOpenAIGrammarTools: boolean): ReadonlyMap<string, string>;
|
|
26
|
+
//# sourceMappingURL=constrained-sampling.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constrained-sampling.d.ts","sourceRoot":"","sources":["../../src/api/constrained-sampling.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAWxC,8FAA8F;AAC9F,MAAM,MAAM,mCAAmC,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,KAAK,OAAO,CAAC;AAiH3F,4FAA4F;AAC5F,wBAAgB,oBAAoB,CACnC,MAAM,EAAE,IAAI,CAAC,YAAY,CAAC,EAC1B,oBAAoB,CAAC,EAAE,mCAAmC,GACxD,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAUzB;AAED,wBAAgB,2BAA2B,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,GAAG,SAAS,GAAG,IAAI,CAAC,YAAY,CAAC,CAEvG;AAED,MAAM,WAAW,0BAA0B;IAC1C,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC;IACzB,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,0BAA0B;IAC1C,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,OAAO,CAAC;CAChB;AAED,wBAAgB,mBAAmB,CAClC,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACnC,aAAa,EAAE,MAAM,GACnB,MAAM,CAMR;AAED,wBAAgB,+BAA+B,CAC9C,MAAM,EAAE,0BAA0B,EAClC,aAAa,EAAE,MAAM,EACrB,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,OAAO,GACZ,MAAM,GAAG,SAAS,CAyBpB;AAqBD;;;GAGG;AACH,wBAAgB,+BAA+B,CAC9C,IAAI,EAAE,IAAI,EACV,kBAAkB,EAAE,OAAO,EAC3B,oBAAoB,CAAC,EAAE,mCAAmC,GACxD,OAAO,GAAG,SAAS,CAoBrB;AAED,wBAAgB,iCAAiC,CAChD,IAAI,EAAE,IAAI,EACV,0BAA0B,EAAE,OAAO,GACjC,0BAA0B,GAAG,SAAS,CA8BxC;AAED,wBAAgB,gCAAgC,CAC/C,KAAK,EAAE,IAAI,EAAE,GAAG,SAAS,EACzB,0BAA0B,EAAE,OAAO,GACjC,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAS7B"}
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
class UnsupportedStrictJsonSchemaError extends Error {
|
|
2
|
+
}
|
|
3
|
+
const UNSUPPORTED_STRICT_SCHEMA_KEYS = [
|
|
4
|
+
"$ref",
|
|
5
|
+
"$defs",
|
|
6
|
+
"definitions",
|
|
7
|
+
"allOf",
|
|
8
|
+
"oneOf",
|
|
9
|
+
"patternProperties",
|
|
10
|
+
"dependentSchemas",
|
|
11
|
+
"dependencies",
|
|
12
|
+
"unevaluatedProperties",
|
|
13
|
+
"propertyNames",
|
|
14
|
+
"contains",
|
|
15
|
+
"prefixItems",
|
|
16
|
+
"not",
|
|
17
|
+
"if",
|
|
18
|
+
"then",
|
|
19
|
+
"else",
|
|
20
|
+
];
|
|
21
|
+
function isJsonSchemaObject(value) {
|
|
22
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
23
|
+
}
|
|
24
|
+
function isStructuredSchema(schema) {
|
|
25
|
+
if (!isJsonSchemaObject(schema))
|
|
26
|
+
return false;
|
|
27
|
+
const types = typeof schema.type === "string" ? [schema.type] : Array.isArray(schema.type) ? schema.type : [];
|
|
28
|
+
return (types.includes("object") ||
|
|
29
|
+
types.includes("array") ||
|
|
30
|
+
schema.properties !== undefined ||
|
|
31
|
+
schema.items !== undefined);
|
|
32
|
+
}
|
|
33
|
+
function schemaAllowsNull(schema) {
|
|
34
|
+
if (!isJsonSchemaObject(schema))
|
|
35
|
+
return false;
|
|
36
|
+
if (schema.type === "null" || (Array.isArray(schema.type) && schema.type.includes("null")))
|
|
37
|
+
return true;
|
|
38
|
+
if (schema.const === null || (Array.isArray(schema.enum) && schema.enum.includes(null)))
|
|
39
|
+
return true;
|
|
40
|
+
return Array.isArray(schema.anyOf) && schema.anyOf.some((variant) => schemaAllowsNull(variant));
|
|
41
|
+
}
|
|
42
|
+
function makeJsonSchemaNodeStrict(schema, isUnsupportedKeyword) {
|
|
43
|
+
if (!isJsonSchemaObject(schema)) {
|
|
44
|
+
throw new UnsupportedStrictJsonSchemaError("boolean schemas are unsupported");
|
|
45
|
+
}
|
|
46
|
+
for (const key of UNSUPPORTED_STRICT_SCHEMA_KEYS) {
|
|
47
|
+
if (schema[key] !== undefined) {
|
|
48
|
+
throw new UnsupportedStrictJsonSchemaError(`${key} schemas are unsupported`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
if (isUnsupportedKeyword) {
|
|
52
|
+
for (const [key, value] of Object.entries(schema)) {
|
|
53
|
+
if (isUnsupportedKeyword(key, value)) {
|
|
54
|
+
throw new UnsupportedStrictJsonSchemaError(`${key}: ${JSON.stringify(value)} is unsupported`);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
if (schema.anyOf !== undefined) {
|
|
59
|
+
if (!Array.isArray(schema.anyOf) || schema.anyOf.length === 0) {
|
|
60
|
+
throw new UnsupportedStrictJsonSchemaError("anyOf must contain at least one schema");
|
|
61
|
+
}
|
|
62
|
+
for (const variant of schema.anyOf) {
|
|
63
|
+
if (isStructuredSchema(variant)) {
|
|
64
|
+
throw new UnsupportedStrictJsonSchemaError("object and array unions are unsupported");
|
|
65
|
+
}
|
|
66
|
+
makeJsonSchemaNodeStrict(variant, isUnsupportedKeyword);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
if (schema.items !== undefined) {
|
|
70
|
+
if (Array.isArray(schema.items)) {
|
|
71
|
+
throw new UnsupportedStrictJsonSchemaError("tuple schemas are unsupported");
|
|
72
|
+
}
|
|
73
|
+
makeJsonSchemaNodeStrict(schema.items, isUnsupportedKeyword);
|
|
74
|
+
}
|
|
75
|
+
const isObjectSchema = schema.type === "object";
|
|
76
|
+
if (schema.properties !== undefined && !isObjectSchema) {
|
|
77
|
+
throw new UnsupportedStrictJsonSchemaError("properties require type object");
|
|
78
|
+
}
|
|
79
|
+
if (!isObjectSchema)
|
|
80
|
+
return;
|
|
81
|
+
if (schema.additionalProperties !== undefined && schema.additionalProperties !== false) {
|
|
82
|
+
throw new UnsupportedStrictJsonSchemaError("schema-valued or true additionalProperties is unsupported");
|
|
83
|
+
}
|
|
84
|
+
if (schema.properties !== undefined && !isJsonSchemaObject(schema.properties)) {
|
|
85
|
+
throw new UnsupportedStrictJsonSchemaError("object properties must be a schema map");
|
|
86
|
+
}
|
|
87
|
+
if (schema.required !== undefined &&
|
|
88
|
+
(!Array.isArray(schema.required) || schema.required.some((key) => typeof key !== "string"))) {
|
|
89
|
+
throw new UnsupportedStrictJsonSchemaError("object required must be a string array");
|
|
90
|
+
}
|
|
91
|
+
const properties = schema.properties ?? {};
|
|
92
|
+
const propertyNames = Object.keys(properties);
|
|
93
|
+
const required = new Set(Array.isArray(schema.required) ? schema.required : []);
|
|
94
|
+
if ([...required].some((key) => !propertyNames.includes(key))) {
|
|
95
|
+
throw new UnsupportedStrictJsonSchemaError("required contains an unknown property");
|
|
96
|
+
}
|
|
97
|
+
for (const [key, property] of Object.entries(properties)) {
|
|
98
|
+
makeJsonSchemaNodeStrict(property, isUnsupportedKeyword);
|
|
99
|
+
if (!required.has(key) && !schemaAllowsNull(property)) {
|
|
100
|
+
properties[key] = { anyOf: [property, { type: "null" }] };
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
schema.required = propertyNames;
|
|
104
|
+
schema.additionalProperties = false;
|
|
105
|
+
}
|
|
106
|
+
/** Convert a tool schema to the strict subset expected by provider constrained sampling. */
|
|
107
|
+
export function makeStrictJsonSchema(schema, isUnsupportedKeyword) {
|
|
108
|
+
const cloned = structuredClone(schema);
|
|
109
|
+
if (!isJsonSchemaObject(cloned)) {
|
|
110
|
+
throw new UnsupportedStrictJsonSchemaError("root schema must have type object");
|
|
111
|
+
}
|
|
112
|
+
makeJsonSchemaNodeStrict(cloned, isUnsupportedKeyword);
|
|
113
|
+
if (cloned.type !== "object") {
|
|
114
|
+
throw new UnsupportedStrictJsonSchemaError("root schema must have type object");
|
|
115
|
+
}
|
|
116
|
+
return cloned;
|
|
117
|
+
}
|
|
118
|
+
export function getJsonSchemaToolParameters(tool, strict) {
|
|
119
|
+
return (strict === true ? makeStrictJsonSchema(tool.parameters) : tool.parameters);
|
|
120
|
+
}
|
|
121
|
+
export function getGrammarToolInput(toolName, arguments_, inputProperty) {
|
|
122
|
+
const input = arguments_[inputProperty];
|
|
123
|
+
if (typeof input !== "string") {
|
|
124
|
+
throw new Error(`Grammar tool call "${toolName}" requires argument "${inputProperty}" to be a string.`);
|
|
125
|
+
}
|
|
126
|
+
return input;
|
|
127
|
+
}
|
|
128
|
+
export function appendGrammarToolInputJsonDelta(buffer, inputProperty, nextInput, close) {
|
|
129
|
+
if (buffer.closed) {
|
|
130
|
+
if (close && nextInput === buffer.input)
|
|
131
|
+
return undefined;
|
|
132
|
+
throw new Error(`grammar tool input for property "${inputProperty}" changed after it was closed`);
|
|
133
|
+
}
|
|
134
|
+
if (!nextInput.startsWith(buffer.input)) {
|
|
135
|
+
throw new Error(`grammar tool input for property "${inputProperty}" changed non-monotonically`);
|
|
136
|
+
}
|
|
137
|
+
const inputDelta = nextInput.slice(buffer.input.length);
|
|
138
|
+
if (!close && inputDelta.length === 0)
|
|
139
|
+
return undefined;
|
|
140
|
+
let delta = "";
|
|
141
|
+
if (!buffer.started) {
|
|
142
|
+
delta += `{${JSON.stringify(inputProperty)}:"`;
|
|
143
|
+
buffer.started = true;
|
|
144
|
+
}
|
|
145
|
+
delta += JSON.stringify(inputDelta).slice(1, -1);
|
|
146
|
+
buffer.input = nextInput;
|
|
147
|
+
if (close) {
|
|
148
|
+
delta += '"}';
|
|
149
|
+
buffer.closed = true;
|
|
150
|
+
}
|
|
151
|
+
return delta;
|
|
152
|
+
}
|
|
153
|
+
function inferGrammarInputProperty(tool) {
|
|
154
|
+
const schema = tool.parameters;
|
|
155
|
+
if (schema.type !== "object") {
|
|
156
|
+
throw new Error("grammar constrained sampling requires an object parameter schema");
|
|
157
|
+
}
|
|
158
|
+
if (!Array.isArray(schema.required) || schema.required.length !== 1 || typeof schema.required[0] !== "string") {
|
|
159
|
+
throw new Error("grammar constrained sampling requires exactly one required string property");
|
|
160
|
+
}
|
|
161
|
+
const inputProperty = schema.required[0];
|
|
162
|
+
if (!schema.properties?.[inputProperty]) {
|
|
163
|
+
throw new Error(`grammar constrained sampling requires a properties entry for ${inputProperty}`);
|
|
164
|
+
}
|
|
165
|
+
if (schema.properties[inputProperty]?.type !== "string") {
|
|
166
|
+
throw new Error(`grammar constrained sampling property ${inputProperty} must have type string`);
|
|
167
|
+
}
|
|
168
|
+
return inputProperty;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Decide whether a JSON-schema tool is sent in strict mode. `isUnsupportedKeyword` lets a provider
|
|
172
|
+
* reject extra keywords its strict mode does not accept, so "prefer" tools fall back to non-strict.
|
|
173
|
+
*/
|
|
174
|
+
export function resolveJsonSchemaStrictSampling(tool, supportsStrictMode, isUnsupportedKeyword) {
|
|
175
|
+
const config = tool.constrainedSampling;
|
|
176
|
+
if (!config || config.type !== "json_schema")
|
|
177
|
+
return undefined;
|
|
178
|
+
if (supportsStrictMode) {
|
|
179
|
+
try {
|
|
180
|
+
makeStrictJsonSchema(tool.parameters, isUnsupportedKeyword);
|
|
181
|
+
return true;
|
|
182
|
+
}
|
|
183
|
+
catch (error) {
|
|
184
|
+
if (!(error instanceof UnsupportedStrictJsonSchemaError))
|
|
185
|
+
throw error;
|
|
186
|
+
if (config.strict !== "require")
|
|
187
|
+
return undefined;
|
|
188
|
+
throw new Error(`Tool "${tool.name}" requires JSON-schema constrained sampling, but ${error.message}.`);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
if (config.strict === "require") {
|
|
192
|
+
throw new Error(`Tool "${tool.name}" requires JSON-schema constrained sampling, but strict tools are unsupported.`);
|
|
193
|
+
}
|
|
194
|
+
return undefined;
|
|
195
|
+
}
|
|
196
|
+
export function resolveGrammarConstrainedSampling(tool, supportsOpenAIGrammarTools) {
|
|
197
|
+
const config = tool.constrainedSampling;
|
|
198
|
+
if (!config || config.type !== "grammar") {
|
|
199
|
+
return undefined;
|
|
200
|
+
}
|
|
201
|
+
if (!supportsOpenAIGrammarTools) {
|
|
202
|
+
return undefined;
|
|
203
|
+
}
|
|
204
|
+
const larkDefinition = config.variants.openai_lark;
|
|
205
|
+
const regexDefinition = config.variants.openai_regex;
|
|
206
|
+
const hasLarkDefinition = typeof larkDefinition === "string" && larkDefinition.trim().length > 0;
|
|
207
|
+
const hasRegexDefinition = typeof regexDefinition === "string" && regexDefinition.trim().length > 0;
|
|
208
|
+
if (!hasLarkDefinition && !hasRegexDefinition) {
|
|
209
|
+
throw new Error(`Tool "${tool.name}" cannot use grammar constrained sampling: no supported grammar variant was provided.`);
|
|
210
|
+
}
|
|
211
|
+
try {
|
|
212
|
+
return {
|
|
213
|
+
format: hasLarkDefinition ? "lark" : "regex",
|
|
214
|
+
definition: hasLarkDefinition ? larkDefinition : regexDefinition,
|
|
215
|
+
inputProperty: inferGrammarInputProperty(tool),
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
catch (error) {
|
|
219
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
220
|
+
throw new Error(`Tool "${tool.name}" cannot use grammar constrained sampling: ${message}.`);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
export function createGrammarToolInputProperties(tools, supportsOpenAIGrammarTools) {
|
|
224
|
+
const properties = new Map();
|
|
225
|
+
for (const tool of tools ?? []) {
|
|
226
|
+
const grammar = resolveGrammarConstrainedSampling(tool, supportsOpenAIGrammarTools);
|
|
227
|
+
if (grammar) {
|
|
228
|
+
properties.set(tool.name, grammar.inputProperty);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
return properties;
|
|
232
|
+
}
|
|
233
|
+
//# sourceMappingURL=constrained-sampling.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constrained-sampling.js","sourceRoot":"","sources":["../../src/api/constrained-sampling.ts"],"names":[],"mappings":"AASA,MAAM,gCAAiC,SAAQ,KAAK;CAAG;AAKvD,MAAM,8BAA8B,GAAG;IACtC,MAAM;IACN,OAAO;IACP,aAAa;IACb,OAAO;IACP,OAAO;IACP,mBAAmB;IACnB,kBAAkB;IAClB,cAAc;IACd,uBAAuB;IACvB,eAAe;IACf,UAAU;IACV,aAAa;IACb,KAAK;IACL,IAAI;IACJ,MAAM;IACN,MAAM;CACG,CAAC;AAEX,SAAS,kBAAkB,CAAC,KAAc;IACzC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC7E,CAAC;AAED,SAAS,kBAAkB,CAAC,MAAe;IAC1C,IAAI,CAAC,kBAAkB,CAAC,MAAM,CAAC;QAAE,OAAO,KAAK,CAAC;IAC9C,MAAM,KAAK,GAAG,OAAO,MAAM,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,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IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC;IACpG,IAAI,CAAC,iBAAiB,IAAI,CAAC,kBAAkB,EAAE,CAAC;QAC/C,MAAM,IAAI,KAAK,CACd,SAAS,IAAI,CAAC,IAAI,uFAAuF,CACzG,CAAC;IACH,CAAC;IAED,IAAI,CAAC;QACJ,OAAO;YACN,MAAM,EAAE,iBAAiB,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO;YAC5C,UAAU,EAAE,iBAAiB,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,eAAgB;YACjE,aAAa,EAAE,yBAAyB,CAAC,IAAI,CAAC;SAC9C,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACvE,MAAM,IAAI,KAAK,CAAC,SAAS,IAAI,CAAC,IAAI,8CAA8C,OAAO,GAAG,CAAC,CAAC;IAC7F,CAAC;AACF,CAAC;AAED,MAAM,UAAU,gCAAgC,CAC/C,KAAyB,EACzB,0BAAmC;IAEnC,MAAM,UAAU,GAAG,IAAI,GAAG,EAAkB,CAAC;IAC7C,KAAK,MAAM,IAAI,IAAI,KAAK,IAAI,EAAE,EAAE,CAAC;QAChC,MAAM,OAAO,GAAG,iCAAiC,CAAC,IAAI,EAAE,0BAA0B,CAAC,CAAC;QACpF,IAAI,OAAO,EAAE,CAAC;YACb,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC;QAClD,CAAC;IACF,CAAC;IACD,OAAO,UAAU,CAAC;AACnB,CAAC","sourcesContent":["import type { Tool } from \"../types.ts\";\n\ninterface JsonSchemaObject {\n\t[key: string]: unknown;\n\ttype?: unknown;\n\tproperties?: Record<string, JsonSchemaObject | undefined>;\n\trequired?: unknown;\n}\n\nclass UnsupportedStrictJsonSchemaError extends Error {}\n\n/** Returns true when a provider's strict mode rejects this schema keyword with this value. */\nexport type UnsupportedStrictSchemaKeywordCheck = (key: string, value: unknown) => boolean;\n\nconst UNSUPPORTED_STRICT_SCHEMA_KEYS = [\n\t\"$ref\",\n\t\"$defs\",\n\t\"definitions\",\n\t\"allOf\",\n\t\"oneOf\",\n\t\"patternProperties\",\n\t\"dependentSchemas\",\n\t\"dependencies\",\n\t\"unevaluatedProperties\",\n\t\"propertyNames\",\n\t\"contains\",\n\t\"prefixItems\",\n\t\"not\",\n\t\"if\",\n\t\"then\",\n\t\"else\",\n] as const;\n\nfunction isJsonSchemaObject(value: unknown): value is JsonSchemaObject {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction isStructuredSchema(schema: unknown): boolean {\n\tif (!isJsonSchemaObject(schema)) return false;\n\tconst types = typeof schema.type === \"string\" ? [schema.type] : Array.isArray(schema.type) ? schema.type : [];\n\treturn (\n\t\ttypes.includes(\"object\") ||\n\t\ttypes.includes(\"array\") ||\n\t\tschema.properties !== undefined ||\n\t\tschema.items !== undefined\n\t);\n}\n\nfunction schemaAllowsNull(schema: unknown): boolean {\n\tif (!isJsonSchemaObject(schema)) return false;\n\tif (schema.type === \"null\" || (Array.isArray(schema.type) && schema.type.includes(\"null\"))) return true;\n\tif (schema.const === null || (Array.isArray(schema.enum) && schema.enum.includes(null))) return true;\n\treturn Array.isArray(schema.anyOf) && schema.anyOf.some((variant) => schemaAllowsNull(variant));\n}\n\nfunction makeJsonSchemaNodeStrict(schema: unknown, isUnsupportedKeyword?: UnsupportedStrictSchemaKeywordCheck): void {\n\tif (!isJsonSchemaObject(schema)) {\n\t\tthrow new UnsupportedStrictJsonSchemaError(\"boolean schemas are unsupported\");\n\t}\n\tfor (const key of UNSUPPORTED_STRICT_SCHEMA_KEYS) {\n\t\tif (schema[key] !== undefined) {\n\t\t\tthrow new UnsupportedStrictJsonSchemaError(`${key} schemas are unsupported`);\n\t\t}\n\t}\n\tif (isUnsupportedKeyword) {\n\t\tfor (const [key, value] of Object.entries(schema)) {\n\t\t\tif (isUnsupportedKeyword(key, value)) {\n\t\t\t\tthrow new UnsupportedStrictJsonSchemaError(`${key}: ${JSON.stringify(value)} is unsupported`);\n\t\t\t}\n\t\t}\n\t}\n\n\tif (schema.anyOf !== undefined) {\n\t\tif (!Array.isArray(schema.anyOf) || schema.anyOf.length === 0) {\n\t\t\tthrow new UnsupportedStrictJsonSchemaError(\"anyOf must contain at least one schema\");\n\t\t}\n\t\tfor (const variant of schema.anyOf) {\n\t\t\tif (isStructuredSchema(variant)) {\n\t\t\t\tthrow new UnsupportedStrictJsonSchemaError(\"object and array unions are unsupported\");\n\t\t\t}\n\t\t\tmakeJsonSchemaNodeStrict(variant, isUnsupportedKeyword);\n\t\t}\n\t}\n\n\tif (schema.items !== undefined) {\n\t\tif (Array.isArray(schema.items)) {\n\t\t\tthrow new UnsupportedStrictJsonSchemaError(\"tuple schemas are unsupported\");\n\t\t}\n\t\tmakeJsonSchemaNodeStrict(schema.items, isUnsupportedKeyword);\n\t}\n\n\tconst isObjectSchema = schema.type === \"object\";\n\tif (schema.properties !== undefined && !isObjectSchema) {\n\t\tthrow new UnsupportedStrictJsonSchemaError(\"properties require type object\");\n\t}\n\tif (!isObjectSchema) return;\n\tif (schema.additionalProperties !== undefined && schema.additionalProperties !== false) {\n\t\tthrow new UnsupportedStrictJsonSchemaError(\"schema-valued or true additionalProperties is unsupported\");\n\t}\n\tif (schema.properties !== undefined && !isJsonSchemaObject(schema.properties)) {\n\t\tthrow new UnsupportedStrictJsonSchemaError(\"object properties must be a schema map\");\n\t}\n\tif (\n\t\tschema.required !== undefined &&\n\t\t(!Array.isArray(schema.required) || schema.required.some((key) => typeof key !== \"string\"))\n\t) {\n\t\tthrow new UnsupportedStrictJsonSchemaError(\"object required must be a string array\");\n\t}\n\n\tconst properties = schema.properties ?? {};\n\tconst propertyNames = Object.keys(properties);\n\tconst required = new Set(Array.isArray(schema.required) ? schema.required : []);\n\tif ([...required].some((key) => !propertyNames.includes(key))) {\n\t\tthrow new UnsupportedStrictJsonSchemaError(\"required contains an unknown property\");\n\t}\n\tfor (const [key, property] of Object.entries(properties)) {\n\t\tmakeJsonSchemaNodeStrict(property, isUnsupportedKeyword);\n\t\tif (!required.has(key) && !schemaAllowsNull(property)) {\n\t\t\tproperties[key] = { anyOf: [property, { type: \"null\" }] };\n\t\t}\n\t}\n\tschema.required = propertyNames;\n\tschema.additionalProperties = false;\n}\n\n/** Convert a tool schema to the strict subset expected by provider constrained sampling. */\nexport function makeStrictJsonSchema(\n\tschema: Tool[\"parameters\"],\n\tisUnsupportedKeyword?: UnsupportedStrictSchemaKeywordCheck,\n): Record<string, unknown> {\n\tconst cloned: unknown = structuredClone(schema);\n\tif (!isJsonSchemaObject(cloned)) {\n\t\tthrow new UnsupportedStrictJsonSchemaError(\"root schema must have type object\");\n\t}\n\tmakeJsonSchemaNodeStrict(cloned, isUnsupportedKeyword);\n\tif (cloned.type !== \"object\") {\n\t\tthrow new UnsupportedStrictJsonSchemaError(\"root schema must have type object\");\n\t}\n\treturn cloned;\n}\n\nexport function getJsonSchemaToolParameters(tool: Tool, strict: boolean | undefined): Tool[\"parameters\"] {\n\treturn (strict === true ? makeStrictJsonSchema(tool.parameters) : tool.parameters) as Tool[\"parameters\"];\n}\n\nexport interface GrammarConstrainedSampling {\n\tformat: \"lark\" | \"regex\";\n\tdefinition: string;\n\tinputProperty: string;\n}\n\nexport interface GrammarToolInputJsonBuffer {\n\tinput: string;\n\tstarted: boolean;\n\tclosed: boolean;\n}\n\nexport function getGrammarToolInput(\n\ttoolName: string,\n\targuments_: Record<string, unknown>,\n\tinputProperty: string,\n): string {\n\tconst input = arguments_[inputProperty];\n\tif (typeof input !== \"string\") {\n\t\tthrow new Error(`Grammar tool call \"${toolName}\" requires argument \"${inputProperty}\" to be a string.`);\n\t}\n\treturn input;\n}\n\nexport function appendGrammarToolInputJsonDelta(\n\tbuffer: GrammarToolInputJsonBuffer,\n\tinputProperty: string,\n\tnextInput: string,\n\tclose: boolean,\n): string | undefined {\n\tif (buffer.closed) {\n\t\tif (close && nextInput === buffer.input) return undefined;\n\t\tthrow new Error(`grammar tool input for property \"${inputProperty}\" changed after it was closed`);\n\t}\n\tif (!nextInput.startsWith(buffer.input)) {\n\t\tthrow new Error(`grammar tool input for property \"${inputProperty}\" changed non-monotonically`);\n\t}\n\n\tconst inputDelta = nextInput.slice(buffer.input.length);\n\tif (!close && inputDelta.length === 0) return undefined;\n\n\tlet delta = \"\";\n\tif (!buffer.started) {\n\t\tdelta += `{${JSON.stringify(inputProperty)}:\"`;\n\t\tbuffer.started = true;\n\t}\n\tdelta += JSON.stringify(inputDelta).slice(1, -1);\n\tbuffer.input = nextInput;\n\n\tif (close) {\n\t\tdelta += '\"}';\n\t\tbuffer.closed = true;\n\t}\n\treturn delta;\n}\n\nfunction inferGrammarInputProperty(tool: Tool): string {\n\tconst schema = tool.parameters as JsonSchemaObject;\n\tif (schema.type !== \"object\") {\n\t\tthrow new Error(\"grammar constrained sampling requires an object parameter schema\");\n\t}\n\tif (!Array.isArray(schema.required) || schema.required.length !== 1 || typeof schema.required[0] !== \"string\") {\n\t\tthrow new Error(\"grammar constrained sampling requires exactly one required string property\");\n\t}\n\n\tconst inputProperty = schema.required[0];\n\tif (!schema.properties?.[inputProperty]) {\n\t\tthrow new Error(`grammar constrained sampling requires a properties entry for ${inputProperty}`);\n\t}\n\tif (schema.properties[inputProperty]?.type !== \"string\") {\n\t\tthrow new Error(`grammar constrained sampling property ${inputProperty} must have type string`);\n\t}\n\treturn inputProperty;\n}\n\n/**\n * Decide whether a JSON-schema tool is sent in strict mode. `isUnsupportedKeyword` lets a provider\n * reject extra keywords its strict mode does not accept, so \"prefer\" tools fall back to non-strict.\n */\nexport function resolveJsonSchemaStrictSampling(\n\ttool: Tool,\n\tsupportsStrictMode: boolean,\n\tisUnsupportedKeyword?: UnsupportedStrictSchemaKeywordCheck,\n): boolean | undefined {\n\tconst config = tool.constrainedSampling;\n\tif (!config || config.type !== \"json_schema\") return undefined;\n\n\tif (supportsStrictMode) {\n\t\ttry {\n\t\t\tmakeStrictJsonSchema(tool.parameters, isUnsupportedKeyword);\n\t\t\treturn true;\n\t\t} catch (error) {\n\t\t\tif (!(error instanceof UnsupportedStrictJsonSchemaError)) throw error;\n\t\t\tif (config.strict !== \"require\") return undefined;\n\t\t\tthrow new Error(`Tool \"${tool.name}\" requires JSON-schema constrained sampling, but ${error.message}.`);\n\t\t}\n\t}\n\tif (config.strict === \"require\") {\n\t\tthrow new Error(\n\t\t\t`Tool \"${tool.name}\" requires JSON-schema constrained sampling, but strict tools are unsupported.`,\n\t\t);\n\t}\n\treturn undefined;\n}\n\nexport function resolveGrammarConstrainedSampling(\n\ttool: Tool,\n\tsupportsOpenAIGrammarTools: boolean,\n): GrammarConstrainedSampling | undefined {\n\tconst config = tool.constrainedSampling;\n\tif (!config || config.type !== \"grammar\") {\n\t\treturn undefined;\n\t}\n\n\tif (!supportsOpenAIGrammarTools) {\n\t\treturn undefined;\n\t}\n\n\tconst larkDefinition = config.variants.openai_lark;\n\tconst regexDefinition = config.variants.openai_regex;\n\tconst hasLarkDefinition = typeof larkDefinition === \"string\" && larkDefinition.trim().length > 0;\n\tconst hasRegexDefinition = typeof regexDefinition === \"string\" && regexDefinition.trim().length > 0;\n\tif (!hasLarkDefinition && !hasRegexDefinition) {\n\t\tthrow new Error(\n\t\t\t`Tool \"${tool.name}\" cannot use grammar constrained sampling: no supported grammar variant was provided.`,\n\t\t);\n\t}\n\n\ttry {\n\t\treturn {\n\t\t\tformat: hasLarkDefinition ? \"lark\" : \"regex\",\n\t\t\tdefinition: hasLarkDefinition ? larkDefinition : regexDefinition!,\n\t\t\tinputProperty: inferGrammarInputProperty(tool),\n\t\t};\n\t} catch (error) {\n\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\tthrow new Error(`Tool \"${tool.name}\" cannot use grammar constrained sampling: ${message}.`);\n\t}\n}\n\nexport function createGrammarToolInputProperties(\n\ttools: Tool[] | undefined,\n\tsupportsOpenAIGrammarTools: boolean,\n): ReadonlyMap<string, string> {\n\tconst properties = new Map<string, string>();\n\tfor (const tool of tools ?? []) {\n\t\tconst grammar = resolveGrammarConstrainedSampling(tool, supportsOpenAIGrammarTools);\n\t\tif (grammar) {\n\t\t\tproperties.set(tool.name, grammar.inputProperty);\n\t\t}\n\t}\n\treturn properties;\n}\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Message } from "../types.ts";
|
|
2
|
+
export declare function inferCopilotInitiator(messages: Message[]): "user" | "agent";
|
|
3
|
+
export declare function hasCopilotVisionInput(messages: Message[]): boolean;
|
|
4
|
+
export declare function buildCopilotDynamicHeaders(params: {
|
|
5
|
+
messages: Message[];
|
|
6
|
+
hasImages: boolean;
|
|
7
|
+
}): Record<string, string>;
|
|
8
|
+
//# sourceMappingURL=github-copilot-headers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"github-copilot-headers.d.ts","sourceRoot":"","sources":["../../src/api/github-copilot-headers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAI3C,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,OAAO,EAAE,GAAG,MAAM,GAAG,OAAO,CAG3E;AAGD,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,OAAO,EAAE,GAAG,OAAO,CAUlE;AAED,wBAAgB,0BAA0B,CAAC,MAAM,EAAE;IAClD,QAAQ,EAAE,OAAO,EAAE,CAAC;IACpB,SAAS,EAAE,OAAO,CAAC;CACnB,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAWzB"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// Copilot expects X-Initiator to indicate whether the request is user-initiated
|
|
2
|
+
// or agent-initiated (e.g. follow-up after assistant/tool messages).
|
|
3
|
+
export function inferCopilotInitiator(messages) {
|
|
4
|
+
const last = messages[messages.length - 1];
|
|
5
|
+
return last && last.role !== "user" ? "agent" : "user";
|
|
6
|
+
}
|
|
7
|
+
// Copilot requires Copilot-Vision-Request header when sending images
|
|
8
|
+
export function hasCopilotVisionInput(messages) {
|
|
9
|
+
return messages.some((msg) => {
|
|
10
|
+
if (msg.role === "user" && Array.isArray(msg.content)) {
|
|
11
|
+
return msg.content.some((c) => c.type === "image");
|
|
12
|
+
}
|
|
13
|
+
if (msg.role === "toolResult" && Array.isArray(msg.content)) {
|
|
14
|
+
return msg.content.some((c) => c.type === "image");
|
|
15
|
+
}
|
|
16
|
+
return false;
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
export function buildCopilotDynamicHeaders(params) {
|
|
20
|
+
const headers = {
|
|
21
|
+
"X-Initiator": inferCopilotInitiator(params.messages),
|
|
22
|
+
"Openai-Intent": "conversation-edits",
|
|
23
|
+
};
|
|
24
|
+
if (params.hasImages) {
|
|
25
|
+
headers["Copilot-Vision-Request"] = "true";
|
|
26
|
+
}
|
|
27
|
+
return headers;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=github-copilot-headers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"github-copilot-headers.js","sourceRoot":"","sources":["../../src/api/github-copilot-headers.ts"],"names":[],"mappings":"AAEA,gFAAgF;AAChF,qEAAqE;AACrE,MAAM,UAAU,qBAAqB,CAAC,QAAmB;IACxD,MAAM,IAAI,GAAG,QAAQ,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAC3C,OAAO,IAAI,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC;AACxD,CAAC;AAED,qEAAqE;AACrE,MAAM,UAAU,qBAAqB,CAAC,QAAmB;IACxD,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE;QAC5B,IAAI,GAAG,CAAC,IAAI,KAAK,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC;YACvD,OAAO,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,OAAO,CAAC,CAAC;QACpD,CAAC;QACD,IAAI,GAAG,CAAC,IAAI,KAAK,YAAY,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC;YAC7D,OAAO,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,OAAO,CAAC,CAAC;QACpD,CAAC;QACD,OAAO,KAAK,CAAC;IACd,CAAC,CAAC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,0BAA0B,CAAC,MAG1C;IACA,MAAM,OAAO,GAA2B;QACvC,aAAa,EAAE,qBAAqB,CAAC,MAAM,CAAC,QAAQ,CAAC;QACrD,eAAe,EAAE,oBAAoB;KACrC,CAAC;IAEF,IAAI,MAAM,CAAC,SAAS,EAAE,CAAC;QACtB,OAAO,CAAC,wBAAwB,CAAC,GAAG,MAAM,CAAC;IAC5C,CAAC;IAED,OAAO,OAAO,CAAC;AAChB,CAAC","sourcesContent":["import type { Message } from \"../types.ts\";\n\n// Copilot expects X-Initiator to indicate whether the request is user-initiated\n// or agent-initiated (e.g. follow-up after assistant/tool messages).\nexport function inferCopilotInitiator(messages: Message[]): \"user\" | \"agent\" {\n\tconst last = messages[messages.length - 1];\n\treturn last && last.role !== \"user\" ? \"agent\" : \"user\";\n}\n\n// Copilot requires Copilot-Vision-Request header when sending images\nexport function hasCopilotVisionInput(messages: Message[]): boolean {\n\treturn messages.some((msg) => {\n\t\tif (msg.role === \"user\" && Array.isArray(msg.content)) {\n\t\t\treturn msg.content.some((c) => c.type === \"image\");\n\t\t}\n\t\tif (msg.role === \"toolResult\" && Array.isArray(msg.content)) {\n\t\t\treturn msg.content.some((c) => c.type === \"image\");\n\t\t}\n\t\treturn false;\n\t});\n}\n\nexport function buildCopilotDynamicHeaders(params: {\n\tmessages: Message[];\n\thasImages: boolean;\n}): Record<string, string> {\n\tconst headers: Record<string, string> = {\n\t\t\"X-Initiator\": inferCopilotInitiator(params.messages),\n\t\t\"Openai-Intent\": \"conversation-edits\",\n\t};\n\n\tif (params.hasImages) {\n\t\theaders[\"Copilot-Vision-Request\"] = \"true\";\n\t}\n\n\treturn headers;\n}\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { SimpleStreamOptions, StreamFunction, StreamOptions } from "../types.ts";
|
|
2
|
+
import type { GoogleApiThinkingLevel } from "./google-shared.ts";
|
|
3
|
+
export interface GoogleOptions extends StreamOptions {
|
|
4
|
+
toolChoice?: "auto" | "none" | "any";
|
|
5
|
+
thinking?: {
|
|
6
|
+
enabled: boolean;
|
|
7
|
+
budgetTokens?: number;
|
|
8
|
+
level?: GoogleApiThinkingLevel;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
export declare const stream: StreamFunction<"google-generative-ai", GoogleOptions>;
|
|
12
|
+
export declare const streamSimple: StreamFunction<"google-generative-ai", SimpleStreamOptions>;
|
|
13
|
+
//# sourceMappingURL=google-generative-ai.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"google-generative-ai.d.ts","sourceRoot":"","sources":["../../src/api/google-generative-ai.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAKX,mBAAmB,EACnB,cAAc,EACd,aAAa,EAMb,MAAM,aAAa,CAAC;AASrB,OAAO,KAAK,EAAE,sBAAsB,EAA+B,MAAM,oBAAoB,CAAC;AAkB9F,MAAM,WAAW,aAAc,SAAQ,aAAa;IACnD,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,KAAK,CAAC;IACrC,QAAQ,CAAC,EAAE;QACV,OAAO,EAAE,OAAO,CAAC;QACjB,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,KAAK,CAAC,EAAE,sBAAsB,CAAC;KAC/B,CAAC;CACF;AAKD,eAAO,MAAM,MAAM,EAAE,cAAc,CAAC,sBAAsB,EAAE,aAAa,CAoPxE,CAAC;AAEF,eAAO,MAAM,YAAY,EAAE,cAAc,CAAC,sBAAsB,EAAE,mBAAmB,CAyCpF,CAAC"}
|