@bastani/atomic-ai 0.0.0-stage → 0.9.88-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1601 -0
- package/LICENSE +22 -0
- package/NOTICE.md +16 -0
- package/README.md +165 -2
- package/dist/api/anthropic-assistant-content.d.ts +24 -0
- package/dist/api/anthropic-assistant-content.d.ts.map +1 -0
- package/dist/api/anthropic-assistant-content.js +99 -0
- package/dist/api/anthropic-assistant-content.js.map +1 -0
- package/dist/api/anthropic-messages.d.ts +71 -0
- package/dist/api/anthropic-messages.d.ts.map +1 -0
- package/dist/api/anthropic-messages.js +1814 -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 +14 -0
- package/dist/api/azure-openai-config.d.ts.map +1 -0
- package/dist/api/azure-openai-config.js +61 -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 +213 -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 +1301 -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 +11 -0
- package/dist/api/classifier-shared.d.ts.map +1 -0
- package/dist/api/classifier-shared.js +90 -0
- package/dist/api/classifier-shared.js.map +1 -0
- package/dist/api/cloudflare-gateway-binding.d.ts +58 -0
- package/dist/api/cloudflare-gateway-binding.d.ts.map +1 -0
- package/dist/api/cloudflare-gateway-binding.js +33 -0
- package/dist/api/cloudflare-gateway-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 +271 -0
- package/dist/api/constrained-sampling.js.map +1 -0
- package/dist/api/github-copilot-headers.d.ts +40 -0
- package/dist/api/github-copilot-headers.d.ts.map +1 -0
- package/dist/api/github-copilot-headers.js +76 -0
- package/dist/api/github-copilot-headers.js.map +1 -0
- package/dist/api/google-generative-ai.d.ts +15 -0
- package/dist/api/google-generative-ai.d.ts.map +1 -0
- package/dist/api/google-generative-ai.js +376 -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 +103 -0
- package/dist/api/google-shared.d.ts.map +1 -0
- package/dist/api/google-shared.js +536 -0
- package/dist/api/google-shared.js.map +1 -0
- package/dist/api/google-vertex.d.ts +17 -0
- package/dist/api/google-vertex.d.ts.map +1 -0
- package/dist/api/google-vertex.js +440 -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 +72 -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 +779 -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 +32 -0
- package/dist/api/openai-codex-responses.d.ts.map +1 -0
- package/dist/api/openai-codex-responses.js +1357 -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 +30 -0
- package/dist/api/openai-completions.d.ts.map +1 -0
- package/dist/api/openai-completions.js +1529 -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 +3 -0
- package/dist/api/openai-decisions.d.ts.map +1 -0
- package/dist/api/openai-decisions.js +157 -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-images-options.d.ts +120 -0
- package/dist/api/openai-images-options.d.ts.map +1 -0
- package/dist/api/openai-images-options.js +112 -0
- package/dist/api/openai-images-options.js.map +1 -0
- package/dist/api/openai-images.d.ts +9 -0
- package/dist/api/openai-images.d.ts.map +1 -0
- package/dist/api/openai-images.js +317 -0
- package/dist/api/openai-images.js.map +1 -0
- package/dist/api/openai-images.lazy.d.ts +3 -0
- package/dist/api/openai-images.lazy.d.ts.map +1 -0
- package/dist/api/openai-images.lazy.js +4 -0
- package/dist/api/openai-images.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 +133 -0
- package/dist/api/openai-responses-shared.d.ts.map +1 -0
- package/dist/api/openai-responses-shared.js +970 -0
- package/dist/api/openai-responses-shared.js.map +1 -0
- package/dist/api/openai-responses.d.ts +15 -0
- package/dist/api/openai-responses.d.ts.map +1 -0
- package/dist/api/openai-responses.js +444 -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/openai-retry-hint-client.d.ts +10 -0
- package/dist/api/openai-retry-hint-client.d.ts.map +1 -0
- package/dist/api/openai-retry-hint-client.js +17 -0
- package/dist/api/openai-retry-hint-client.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 +135 -0
- package/dist/api/openrouter-images.js.map +1 -0
- package/dist/api/openrouter-images.lazy.d.ts +3 -0
- package/dist/api/openrouter-images.lazy.d.ts.map +1 -0
- package/dist/api/openrouter-images.lazy.js +4 -0
- package/dist/api/openrouter-images.lazy.js.map +1 -0
- package/dist/api/pi-messages.d.ts +101 -0
- package/dist/api/pi-messages.d.ts.map +1 -0
- package/dist/api/pi-messages.js +338 -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 +89 -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 +48 -0
- package/dist/api/system-one-shared.d.ts.map +1 -0
- package/dist/api/system-one-shared.js +175 -0
- package/dist/api/system-one-shared.js.map +1 -0
- package/dist/api/transform-messages.d.ts +27 -0
- package/dist/api/transform-messages.d.ts.map +1 -0
- package/dist/api/transform-messages.js +353 -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 +29 -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 +52 -0
- package/dist/auth/credential-store.js.map +1 -0
- package/dist/auth/helpers.d.ts +30 -0
- package/dist/auth/helpers.d.ts.map +1 -0
- package/dist/auth/helpers.js +66 -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 +266 -0
- package/dist/auth/oauth/anthropic.js.map +1 -0
- package/dist/auth/oauth/callback-server.d.ts +31 -0
- package/dist/auth/oauth/callback-server.d.ts.map +1 -0
- package/dist/auth/oauth/callback-server.js +138 -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 +352 -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 +238 -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 +67 -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 +182 -0
- package/dist/auth/oauth/meta.js.map +1 -0
- package/dist/auth/oauth/oauth-page.d.ts +3 -0
- package/dist/auth/oauth/oauth-page.d.ts.map +1 -0
- package/dist/auth/oauth/oauth-page.js +105 -0
- package/dist/auth/oauth/oauth-page.js.map +1 -0
- package/dist/auth/oauth/openai-chatgpt.d.ts +3 -0
- package/dist/auth/oauth/openai-chatgpt.d.ts.map +1 -0
- package/dist/auth/oauth/openai-chatgpt.js +271 -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 +360 -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 +159 -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/token-response.d.ts +25 -0
- package/dist/auth/oauth/token-response.d.ts.map +1 -0
- package/dist/auth/oauth/token-response.js +43 -0
- package/dist/auth/oauth/token-response.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 +193 -0
- package/dist/auth/oauth/xai.js.map +1 -0
- package/dist/auth/oauth-refresh-errors.d.ts +46 -0
- package/dist/auth/oauth-refresh-errors.d.ts.map +1 -0
- package/dist/auth/oauth-refresh-errors.js +150 -0
- package/dist/auth/oauth-refresh-errors.js.map +1 -0
- package/dist/auth/resolve.d.ts +62 -0
- package/dist/auth/resolve.d.ts.map +1 -0
- package/dist/auth/resolve.js +357 -0
- package/dist/auth/resolve.js.map +1 -0
- package/dist/auth/types.d.ts +267 -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/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 +118 -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/decision-models.d.ts +21 -0
- package/dist/decision-models.d.ts.map +1 -0
- package/dist/decision-models.generated.d.ts +3 -0
- package/dist/decision-models.generated.d.ts.map +1 -0
- package/dist/decision-models.generated.js +47 -0
- package/dist/decision-models.generated.js.map +1 -0
- package/dist/decision-models.js +8 -0
- package/dist/decision-models.js.map +1 -0
- package/dist/env-api-keys.d.ts +28 -0
- package/dist/env-api-keys.d.ts.map +1 -0
- package/dist/env-api-keys.js +185 -0
- package/dist/env-api-keys.js.map +1 -0
- package/dist/image-generation-error.d.ts +210 -0
- package/dist/image-generation-error.d.ts.map +1 -0
- package/dist/image-generation-error.js +442 -0
- package/dist/image-generation-error.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 +51 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +38 -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 +22 -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 +46 -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 +297 -0
- package/dist/models.d.ts.map +1 -0
- package/dist/models.generated.d.ts +183 -0
- package/dist/models.generated.d.ts.map +1 -0
- package/dist/models.generated.js +185 -0
- package/dist/models.generated.js.map +1 -0
- package/dist/models.js +817 -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/provider-id.d.ts +2 -0
- package/dist/provider-id.d.ts.map +1 -0
- package/dist/provider-id.js +4 -0
- package/dist/provider-id.js.map +1 -0
- package/dist/providers/all.d.ts +41 -0
- package/dist/providers/all.d.ts.map +1 -0
- package/dist/providers/all.js +145 -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 +5 -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 +5 -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 +4 -0
- package/dist/providers/anthropic.d.ts.map +1 -0
- package/dist/providers/anthropic.js +87 -0
- package/dist/providers/anthropic.js.map +1 -0
- package/dist/providers/anthropic.models.d.ts +5 -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-openai-responses.d.ts +3 -0
- package/dist/providers/azure-openai-responses.d.ts.map +1 -0
- package/dist/providers/azure-openai-responses.js +3 -0
- package/dist/providers/azure-openai-responses.js.map +1 -0
- package/dist/providers/azure-openai-responses.models.d.ts +3 -0
- package/dist/providers/azure-openai-responses.models.d.ts.map +1 -0
- package/dist/providers/azure-openai-responses.models.js +5 -0
- package/dist/providers/azure-openai-responses.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 +41 -0
- package/dist/providers/azure.js.map +1 -0
- package/dist/providers/azure.models.d.ts +5 -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 +5 -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 +5 -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 +21 -0
- package/dist/providers/cloudflare-ai-gateway.js.map +1 -0
- package/dist/providers/cloudflare-ai-gateway.models.d.ts +5 -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 +5 -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 +549 -0
- package/dist/providers/compat-schema.d.ts.map +1 -0
- package/dist/providers/compat-schema.js +452 -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-decisions.json +1 -0
- package/dist/providers/data/openai-images.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/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 +5 -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 +521 -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 +5 -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-account.d.ts +18 -0
- package/dist/providers/github-copilot-account.d.ts.map +1 -0
- package/dist/providers/github-copilot-account.js +57 -0
- package/dist/providers/github-copilot-account.js.map +1 -0
- package/dist/providers/github-copilot-capabilities.d.ts +67 -0
- package/dist/providers/github-copilot-capabilities.d.ts.map +1 -0
- package/dist/providers/github-copilot-capabilities.js +81 -0
- package/dist/providers/github-copilot-capabilities.js.map +1 -0
- package/dist/providers/github-copilot-env.d.ts +41 -0
- package/dist/providers/github-copilot-env.d.ts.map +1 -0
- package/dist/providers/github-copilot-env.js +108 -0
- package/dist/providers/github-copilot-env.js.map +1 -0
- package/dist/providers/github-copilot-errors.d.ts +255 -0
- package/dist/providers/github-copilot-errors.d.ts.map +1 -0
- package/dist/providers/github-copilot-errors.js +764 -0
- package/dist/providers/github-copilot-errors.js.map +1 -0
- package/dist/providers/github-copilot-stream-attempt.d.ts +27 -0
- package/dist/providers/github-copilot-stream-attempt.d.ts.map +1 -0
- package/dist/providers/github-copilot-stream-attempt.js +45 -0
- package/dist/providers/github-copilot-stream-attempt.js.map +1 -0
- package/dist/providers/github-copilot.d.ts +40 -0
- package/dist/providers/github-copilot.d.ts.map +1 -0
- package/dist/providers/github-copilot.js +363 -0
- package/dist/providers/github-copilot.js.map +1 -0
- package/dist/providers/github-copilot.models.d.ts +5 -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 +5 -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 +5 -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 +5 -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 +5 -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 +5 -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 +5 -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 +5 -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 +5 -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 +5 -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 +91 -0
- package/dist/providers/model-schema.d.ts.map +1 -0
- package/dist/providers/model-schema.js +57 -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 +5 -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 +5 -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/morph.d.ts +3 -0
- package/dist/providers/morph.d.ts.map +1 -0
- package/dist/providers/morph.js +22 -0
- package/dist/providers/morph.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 +5 -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 +25 -0
- package/dist/providers/openai-codex.js.map +1 -0
- package/dist/providers/openai-codex.models.d.ts +5 -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-decisions.d.ts +3 -0
- package/dist/providers/openai-decisions.d.ts.map +1 -0
- package/dist/providers/openai-decisions.js +19 -0
- package/dist/providers/openai-decisions.js.map +1 -0
- package/dist/providers/openai-decisions.models.d.ts +5 -0
- package/dist/providers/openai-decisions.models.d.ts.map +1 -0
- package/dist/providers/openai-decisions.models.js +8 -0
- package/dist/providers/openai-decisions.models.js.map +1 -0
- package/dist/providers/openai-images.d.ts +3 -0
- package/dist/providers/openai-images.d.ts.map +1 -0
- package/dist/providers/openai-images.js +19 -0
- package/dist/providers/openai-images.js.map +1 -0
- package/dist/providers/openai-images.models.d.ts +5 -0
- package/dist/providers/openai-images.models.d.ts.map +1 -0
- package/dist/providers/openai-images.models.js +8 -0
- package/dist/providers/openai-images.models.js.map +1 -0
- package/dist/providers/openai-mid-convo-effort.d.ts +2 -0
- package/dist/providers/openai-mid-convo-effort.d.ts.map +1 -0
- package/dist/providers/openai-mid-convo-effort.js +8 -0
- package/dist/providers/openai-mid-convo-effort.js.map +1 -0
- package/dist/providers/openai-subscription-models.d.ts +3 -0
- package/dist/providers/openai-subscription-models.d.ts.map +1 -0
- package/dist/providers/openai-subscription-models.js +19 -0
- package/dist/providers/openai-subscription-models.js.map +1 -0
- package/dist/providers/openai.d.ts +4 -0
- package/dist/providers/openai.d.ts.map +1 -0
- package/dist/providers/openai.js +48 -0
- package/dist/providers/openai.js.map +1 -0
- package/dist/providers/openai.models.d.ts +5 -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 +22 -0
- package/dist/providers/opencode-go.js.map +1 -0
- package/dist/providers/opencode-go.models.d.ts +5 -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.d.ts +5 -0
- package/dist/providers/opencode.d.ts.map +1 -0
- package/dist/providers/opencode.js +24 -0
- package/dist/providers/opencode.js.map +1 -0
- package/dist/providers/opencode.models.d.ts +5 -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 +40 -0
- package/dist/providers/openrouter-api.d.ts.map +1 -0
- package/dist/providers/openrouter-api.js +41 -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 +88 -0
- package/dist/providers/openrouter.js.map +1 -0
- package/dist/providers/openrouter.models.d.ts +5 -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 +5 -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 +5 -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 +5 -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 +5 -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 +5 -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 +5 -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 +17 -0
- package/dist/providers/vercel-ai-gateway.js.map +1 -0
- package/dist/providers/vercel-ai-gateway.models.d.ts +5 -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 +5 -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 +5 -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 +5 -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 +5 -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 +5 -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 +5 -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 +5 -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/types.d.ts +845 -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/azure-openai-thinking-level-map.d.ts +19 -0
- package/dist/utils/azure-openai-thinking-level-map.d.ts.map +1 -0
- package/dist/utils/azure-openai-thinking-level-map.js +45 -0
- package/dist/utils/azure-openai-thinking-level-map.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/document-input.d.ts +21 -0
- package/dist/utils/document-input.d.ts.map +1 -0
- package/dist/utils/document-input.js +28 -0
- package/dist/utils/document-input.js.map +1 -0
- package/dist/utils/error-body.d.ts +40 -0
- package/dist/utils/error-body.d.ts.map +1 -0
- package/dist/utils/error-body.js +177 -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 +107 -0
- package/dist/utils/estimate.js.map +1 -0
- package/dist/utils/event-stream.d.ts +24 -0
- package/dist/utils/event-stream.d.ts.map +1 -0
- package/dist/utils/event-stream.js +118 -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 +67 -0
- package/dist/utils/identity.d.ts.map +1 -0
- package/dist/utils/identity.js +148 -0
- package/dist/utils/identity.js.map +1 -0
- package/dist/utils/inline-images.d.ts +24 -0
- package/dist/utils/inline-images.d.ts.map +1 -0
- package/dist/utils/inline-images.js +55 -0
- package/dist/utils/inline-images.js.map +1 -0
- package/dist/utils/json-parse.d.ts +18 -0
- package/dist/utils/json-parse.d.ts.map +1 -0
- package/dist/utils/json-parse.js +167 -0
- package/dist/utils/json-parse.js.map +1 -0
- package/dist/utils/model-operations.d.ts +12 -0
- package/dist/utils/model-operations.d.ts.map +1 -0
- package/dist/utils/model-operations.js +58 -0
- package/dist/utils/model-operations.js.map +1 -0
- package/dist/utils/models-dev-catalog.d.ts +324 -0
- package/dist/utils/models-dev-catalog.d.ts.map +1 -0
- package/dist/utils/models-dev-catalog.js +3166 -0
- package/dist/utils/models-dev-catalog.js.map +1 -0
- package/dist/utils/models-dev-reasoning-options.d.ts +18 -0
- package/dist/utils/models-dev-reasoning-options.d.ts.map +1 -0
- package/dist/utils/models-dev-reasoning-options.js +20 -0
- package/dist/utils/models-dev-reasoning-options.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 +141 -0
- package/dist/utils/node-http-proxy.js.map +1 -0
- package/dist/utils/oauth-page.d.ts +2 -0
- package/dist/utils/oauth-page.d.ts.map +1 -0
- package/dist/utils/oauth-page.js +2 -0
- package/dist/utils/oauth-page.js.map +1 -0
- package/dist/utils/openrouter-cost.d.ts +24 -0
- package/dist/utils/openrouter-cost.d.ts.map +1 -0
- package/dist/utils/openrouter-cost.js +34 -0
- package/dist/utils/openrouter-cost.js.map +1 -0
- package/dist/utils/overflow.d.ts +73 -0
- package/dist/utils/overflow.d.ts.map +1 -0
- package/dist/utils/overflow.js +204 -0
- package/dist/utils/overflow.js.map +1 -0
- package/dist/utils/provider-env.d.ts +12 -0
- package/dist/utils/provider-env.d.ts.map +1 -0
- package/dist/utils/provider-env.js +51 -0
- package/dist/utils/provider-env.js.map +1 -0
- package/dist/utils/provider-retry.d.ts +21 -0
- package/dist/utils/provider-retry.d.ts.map +1 -0
- package/dist/utils/provider-retry.js +100 -0
- package/dist/utils/provider-retry.js.map +1 -0
- package/dist/utils/request-admission.d.ts +12 -0
- package/dist/utils/request-admission.d.ts.map +1 -0
- package/dist/utils/request-admission.js +37 -0
- package/dist/utils/request-admission.js.map +1 -0
- package/dist/utils/retry-hints.d.ts +15 -0
- package/dist/utils/retry-hints.d.ts.map +1 -0
- package/dist/utils/retry-hints.js +130 -0
- package/dist/utils/retry-hints.js.map +1 -0
- package/dist/utils/retry.d.ts +78 -0
- package/dist/utils/retry.d.ts.map +1 -0
- package/dist/utils/retry.js +251 -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 +73 -0
- package/dist/utils/sse.js.map +1 -0
- package/dist/utils/stream-deadline.d.ts +78 -0
- package/dist/utils/stream-deadline.d.ts.map +1 -0
- package/dist/utils/stream-deadline.js +205 -0
- package/dist/utils/stream-deadline.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/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/thinking-off.d.ts +23 -0
- package/dist/utils/thinking-off.d.ts.map +1 -0
- package/dist/utils/thinking-off.js +51 -0
- package/dist/utils/thinking-off.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/typebox-helpers.d.ts +17 -0
- package/dist/utils/typebox-helpers.d.ts.map +1 -0
- package/dist/utils/typebox-helpers.js +21 -0
- package/dist/utils/typebox-helpers.js.map +1 -0
- package/dist/utils/uuid.d.ts +3 -0
- package/dist/utils/uuid.d.ts.map +1 -0
- package/dist/utils/uuid.js +46 -0
- package/dist/utils/uuid.js.map +1 -0
- package/dist/utils/validation.d.ts +24 -0
- package/dist/utils/validation.d.ts.map +1 -0
- package/dist/utils/validation.js +363 -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 +138 -4
|
@@ -0,0 +1,57 @@
|
|
|
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
|
+
* Clef models take images as an `images` list of data URLs. TypeSafe's models take them as
|
|
25
|
+
* System One `assets`, without TypeSafe's opt-in header. The catalog sets `compat.imageInput`;
|
|
26
|
+
* the model ID check only covers models without it.
|
|
27
|
+
*/
|
|
28
|
+
const transport = {
|
|
29
|
+
api: "cloudflare-workers-ai-system-one",
|
|
30
|
+
label: LABEL,
|
|
31
|
+
detectCompat: (model) => ({
|
|
32
|
+
imageInput: model.id.startsWith("@cf/cloudflare/clef") ? "images" : "assets",
|
|
33
|
+
sendImageOptInHeader: false,
|
|
34
|
+
}),
|
|
35
|
+
url: (model) => new URL("run", `${model.baseUrl.replace(/\/+$/u, "")}/`),
|
|
36
|
+
payload: (model, request) => ({ model: model.id, input: request }),
|
|
37
|
+
output: (body) => {
|
|
38
|
+
if (!isRecord(body))
|
|
39
|
+
throw new Error(`${LABEL} returned an unexpected response`);
|
|
40
|
+
if (body.success === false)
|
|
41
|
+
throw new Error(cloudflareErrorMessage(body.errors));
|
|
42
|
+
const result = body.result;
|
|
43
|
+
if (!isRecord(result))
|
|
44
|
+
throw new Error(`${LABEL} returned an unexpected response`);
|
|
45
|
+
if ("answers" in result)
|
|
46
|
+
return result;
|
|
47
|
+
if (result.state !== "Completed") {
|
|
48
|
+
throw new Error(`${LABEL} run did not complete (state: ${String(result.state)})`);
|
|
49
|
+
}
|
|
50
|
+
if (!isRecord(result.result))
|
|
51
|
+
throw new Error(`${LABEL} returned an unexpected response`);
|
|
52
|
+
return result.result;
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
/** Cloudflare Workers AI System One classification with public `bool` values mapped to wire-level `noul`. */
|
|
56
|
+
export const classify = (model, context, options) => classifySystemOne(transport, model, context, options);
|
|
57
|
+
//# 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,EAAE,CAAC;QAC3B,MAAM,QAAQ,GAAG,MAAM;a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CAAC,OAAO,KAAK,KAAK;YAAE,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;QACjF,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QAC3B,IAAI,CAAC,QAAQ,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 *\n * Clef models take images as an `images` list of data URLs. TypeSafe's models take them as\n * System One `assets`, without TypeSafe's opt-in header. The catalog sets `compat.imageInput`;\n * the model ID check only covers models without it.\n */\nconst transport: SystemOneTransport = {\n\tapi: \"cloudflare-workers-ai-system-one\",\n\tlabel: LABEL,\n\tdetectCompat: (model) => ({\n\t\timageInput: model.id.startsWith(\"@cf/cloudflare/clef\") ? \"images\" : \"assets\",\n\t\tsendImageOptInHeader: false,\n\t}),\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,38 @@
|
|
|
1
|
+
import type { Tool } from "../types.ts";
|
|
2
|
+
export interface StrictJsonSchemaProfile {
|
|
3
|
+
readonly unsupportedKeywords: readonly string[];
|
|
4
|
+
readonly maxMinItems?: number;
|
|
5
|
+
readonly supportedStringFormats?: readonly string[];
|
|
6
|
+
}
|
|
7
|
+
export declare const ANTHROPIC_STRICT_JSON_SCHEMA_PROFILE: StrictJsonSchemaProfile;
|
|
8
|
+
/** Convert a tool schema to the strict subset expected by provider constrained sampling. */
|
|
9
|
+
export declare function makeStrictJsonSchema(schema: Tool["parameters"], profile?: StrictJsonSchemaProfile): Record<string, unknown>;
|
|
10
|
+
/** Returns true for a tool that asks for strict JSON-schema sampling only when possible (`strict: "prefer"`). */
|
|
11
|
+
export declare function prefersJsonSchemaStrictSampling(tool: Tool): boolean;
|
|
12
|
+
export declare function getJsonSchemaToolParameters(tool: Tool, strict: boolean | undefined, profile?: StrictJsonSchemaProfile): Tool["parameters"];
|
|
13
|
+
export interface GrammarConstrainedSampling {
|
|
14
|
+
format: "lark" | "regex";
|
|
15
|
+
definition: string;
|
|
16
|
+
inputProperty: string;
|
|
17
|
+
}
|
|
18
|
+
export interface GrammarToolInputJsonBuffer {
|
|
19
|
+
input: string;
|
|
20
|
+
started: boolean;
|
|
21
|
+
closed: boolean;
|
|
22
|
+
}
|
|
23
|
+
export declare function getGrammarToolInput(toolName: string, arguments_: Record<string, unknown>, inputProperty: string): string;
|
|
24
|
+
/**
|
|
25
|
+
* Append `inputDelta` to a streaming grammar tool input and return the matching piece of its JSON arguments text, or
|
|
26
|
+
* `undefined` for an empty delta. Costs time linear in the delta, never in the input so far.
|
|
27
|
+
*/
|
|
28
|
+
export declare function appendGrammarToolInputJsonDelta(buffer: GrammarToolInputJsonBuffer, inputProperty: string, inputDelta: string): string | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* Close a streaming grammar tool input and return the rest of its JSON arguments text. `finalInput` is the complete
|
|
31
|
+
* input when the provider sends one; it must continue the input streamed so far. Closing again with the same input
|
|
32
|
+
* returns `undefined`.
|
|
33
|
+
*/
|
|
34
|
+
export declare function closeGrammarToolInputJson(buffer: GrammarToolInputJsonBuffer, inputProperty: string, finalInput: string | undefined): string | undefined;
|
|
35
|
+
export declare function resolveJsonSchemaStrictSampling(tool: Tool, supportsStrictMode: boolean, profile?: StrictJsonSchemaProfile): boolean | undefined;
|
|
36
|
+
export declare function resolveGrammarConstrainedSampling(tool: Tool, supportsOpenAIGrammarTools: boolean): GrammarConstrainedSampling | undefined;
|
|
37
|
+
export declare function createGrammarToolInputProperties(tools: Tool[] | undefined, supportsOpenAIGrammarTools: boolean): ReadonlyMap<string, string>;
|
|
38
|
+
//# 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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G;AACH,wBAAgB,yBAAyB,CACxC,MAAM,EAAE,0BAA0B,EAClC,aAAa,EAAE,MAAM,EACrB,UAAU,EAAE,MAAM,GAAG,SAAS,GAC5B,MAAM,GAAG,SAAS,CAYpB;AA4BD,wBAAgB,+BAA+B,CAC9C,IAAI,EAAE,IAAI,EACV,kBAAkB,EAAE,OAAO,EAC3B,OAAO,CAAC,EAAE,uBAAuB,GAC/B,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,271 @@
|
|
|
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
|
+
export const ANTHROPIC_STRICT_JSON_SCHEMA_PROFILE = Object.freeze({
|
|
22
|
+
unsupportedKeywords: Object.freeze([
|
|
23
|
+
"minimum",
|
|
24
|
+
"maximum",
|
|
25
|
+
"exclusiveMinimum",
|
|
26
|
+
"exclusiveMaximum",
|
|
27
|
+
"multipleOf",
|
|
28
|
+
"uniqueItems",
|
|
29
|
+
"minContains",
|
|
30
|
+
"maxContains",
|
|
31
|
+
"minProperties",
|
|
32
|
+
"maxProperties",
|
|
33
|
+
"maxItems",
|
|
34
|
+
]),
|
|
35
|
+
maxMinItems: 1,
|
|
36
|
+
supportedStringFormats: Object.freeze(["date-time", "time", "date", "duration", "email", "hostname", "uri", "ipv4", "ipv6", "uuid"]),
|
|
37
|
+
});
|
|
38
|
+
function isJsonSchemaObject(value) {
|
|
39
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
40
|
+
}
|
|
41
|
+
function isStructuredSchema(schema) {
|
|
42
|
+
if (!isJsonSchemaObject(schema))
|
|
43
|
+
return false;
|
|
44
|
+
const types = typeof schema.type === "string" ? [schema.type] : Array.isArray(schema.type) ? schema.type : [];
|
|
45
|
+
return (types.includes("object") ||
|
|
46
|
+
types.includes("array") ||
|
|
47
|
+
schema.properties !== undefined ||
|
|
48
|
+
schema.items !== undefined);
|
|
49
|
+
}
|
|
50
|
+
function schemaAllowsNull(schema) {
|
|
51
|
+
if (!isJsonSchemaObject(schema))
|
|
52
|
+
return false;
|
|
53
|
+
if (schema.type === "null" || (Array.isArray(schema.type) && schema.type.includes("null")))
|
|
54
|
+
return true;
|
|
55
|
+
if (schema.const === null || (Array.isArray(schema.enum) && schema.enum.includes(null)))
|
|
56
|
+
return true;
|
|
57
|
+
return Array.isArray(schema.anyOf) && schema.anyOf.some((variant) => schemaAllowsNull(variant));
|
|
58
|
+
}
|
|
59
|
+
function makeJsonSchemaNodeStrict(schema, profile) {
|
|
60
|
+
if (!isJsonSchemaObject(schema)) {
|
|
61
|
+
throw new UnsupportedStrictJsonSchemaError("boolean schemas are unsupported");
|
|
62
|
+
}
|
|
63
|
+
for (const key of [...UNSUPPORTED_STRICT_SCHEMA_KEYS, ...(profile?.unsupportedKeywords ?? [])]) {
|
|
64
|
+
if (schema[key] !== undefined) {
|
|
65
|
+
throw new UnsupportedStrictJsonSchemaError(`${key} schemas are unsupported`);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
if (profile?.maxMinItems !== undefined &&
|
|
69
|
+
schema.minItems !== undefined &&
|
|
70
|
+
(typeof schema.minItems !== "number" || !Number.isInteger(schema.minItems) || schema.minItems < 0 || schema.minItems > profile.maxMinItems)) {
|
|
71
|
+
throw new UnsupportedStrictJsonSchemaError(`minItems must be an integer from 0 to ${profile.maxMinItems}`);
|
|
72
|
+
}
|
|
73
|
+
if (profile?.supportedStringFormats && schema.format !== undefined &&
|
|
74
|
+
(typeof schema.format !== "string" || !profile.supportedStringFormats.includes(schema.format))) {
|
|
75
|
+
throw new UnsupportedStrictJsonSchemaError(`format: ${JSON.stringify(schema.format)} is unsupported`);
|
|
76
|
+
}
|
|
77
|
+
if (schema.type === undefined && schema.anyOf === undefined && schema.enum === undefined) {
|
|
78
|
+
throw new UnsupportedStrictJsonSchemaError("schemas without a type are unsupported");
|
|
79
|
+
}
|
|
80
|
+
if (schema.anyOf !== undefined) {
|
|
81
|
+
if (!Array.isArray(schema.anyOf) || schema.anyOf.length === 0) {
|
|
82
|
+
throw new UnsupportedStrictJsonSchemaError("anyOf must contain at least one schema");
|
|
83
|
+
}
|
|
84
|
+
for (const variant of schema.anyOf) {
|
|
85
|
+
if (isStructuredSchema(variant)) {
|
|
86
|
+
throw new UnsupportedStrictJsonSchemaError("object and array unions are unsupported");
|
|
87
|
+
}
|
|
88
|
+
makeJsonSchemaNodeStrict(variant, profile);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
if (schema.items !== undefined) {
|
|
92
|
+
if (Array.isArray(schema.items)) {
|
|
93
|
+
throw new UnsupportedStrictJsonSchemaError("tuple schemas are unsupported");
|
|
94
|
+
}
|
|
95
|
+
makeJsonSchemaNodeStrict(schema.items, profile);
|
|
96
|
+
}
|
|
97
|
+
const isObjectSchema = schema.type === "object";
|
|
98
|
+
if (schema.properties !== undefined && !isObjectSchema) {
|
|
99
|
+
throw new UnsupportedStrictJsonSchemaError("properties require type object");
|
|
100
|
+
}
|
|
101
|
+
if (!isObjectSchema)
|
|
102
|
+
return;
|
|
103
|
+
if (schema.additionalProperties !== undefined && schema.additionalProperties !== false) {
|
|
104
|
+
throw new UnsupportedStrictJsonSchemaError("schema-valued or true additionalProperties is unsupported");
|
|
105
|
+
}
|
|
106
|
+
if (schema.properties !== undefined && !isJsonSchemaObject(schema.properties)) {
|
|
107
|
+
throw new UnsupportedStrictJsonSchemaError("object properties must be a schema map");
|
|
108
|
+
}
|
|
109
|
+
if (schema.required !== undefined &&
|
|
110
|
+
(!Array.isArray(schema.required) || schema.required.some((key) => typeof key !== "string"))) {
|
|
111
|
+
throw new UnsupportedStrictJsonSchemaError("object required must be a string array");
|
|
112
|
+
}
|
|
113
|
+
const properties = schema.properties ?? {};
|
|
114
|
+
const propertyNames = Object.keys(properties);
|
|
115
|
+
const required = new Set(Array.isArray(schema.required) ? schema.required : []);
|
|
116
|
+
if ([...required].some((key) => !propertyNames.includes(key))) {
|
|
117
|
+
throw new UnsupportedStrictJsonSchemaError("required contains an unknown property");
|
|
118
|
+
}
|
|
119
|
+
for (const [key, property] of Object.entries(properties)) {
|
|
120
|
+
makeJsonSchemaNodeStrict(property, profile);
|
|
121
|
+
if (!required.has(key) && !schemaAllowsNull(property)) {
|
|
122
|
+
properties[key] = { anyOf: [property, { type: "null" }] };
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
schema.required = propertyNames;
|
|
126
|
+
schema.additionalProperties = false;
|
|
127
|
+
}
|
|
128
|
+
/** Convert a tool schema to the strict subset expected by provider constrained sampling. */
|
|
129
|
+
export function makeStrictJsonSchema(schema, profile) {
|
|
130
|
+
const cloned = structuredClone(schema);
|
|
131
|
+
if (!isJsonSchemaObject(cloned)) {
|
|
132
|
+
throw new UnsupportedStrictJsonSchemaError("root schema must have type object");
|
|
133
|
+
}
|
|
134
|
+
makeJsonSchemaNodeStrict(cloned, profile);
|
|
135
|
+
if (cloned.type !== "object") {
|
|
136
|
+
throw new UnsupportedStrictJsonSchemaError("root schema must have type object");
|
|
137
|
+
}
|
|
138
|
+
return cloned;
|
|
139
|
+
}
|
|
140
|
+
/** Returns true for a tool that asks for strict JSON-schema sampling only when possible (`strict: "prefer"`). */
|
|
141
|
+
export function prefersJsonSchemaStrictSampling(tool) {
|
|
142
|
+
const config = tool.constrainedSampling;
|
|
143
|
+
return !!config && config.type === "json_schema" && config.strict === "prefer";
|
|
144
|
+
}
|
|
145
|
+
export function getJsonSchemaToolParameters(tool, strict, profile) {
|
|
146
|
+
return (strict === true ? makeStrictJsonSchema(tool.parameters, profile) : tool.parameters);
|
|
147
|
+
}
|
|
148
|
+
export function getGrammarToolInput(toolName, arguments_, inputProperty) {
|
|
149
|
+
const input = arguments_[inputProperty];
|
|
150
|
+
if (typeof input !== "string") {
|
|
151
|
+
throw new Error(`Grammar tool call "${toolName}" requires argument "${inputProperty}" to be a string.`);
|
|
152
|
+
}
|
|
153
|
+
return input;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Append `inputDelta` to a streaming grammar tool input and return the matching piece of its JSON arguments text, or
|
|
157
|
+
* `undefined` for an empty delta. Costs time linear in the delta, never in the input so far.
|
|
158
|
+
*/
|
|
159
|
+
export function appendGrammarToolInputJsonDelta(buffer, inputProperty, inputDelta) {
|
|
160
|
+
if (buffer.closed) {
|
|
161
|
+
throw new Error(`grammar tool input for property "${inputProperty}" changed after it was closed`);
|
|
162
|
+
}
|
|
163
|
+
if (inputDelta.length === 0)
|
|
164
|
+
return undefined;
|
|
165
|
+
buffer.input += inputDelta;
|
|
166
|
+
return grammarToolInputJsonStart(buffer, inputProperty) + JSON.stringify(inputDelta).slice(1, -1);
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Close a streaming grammar tool input and return the rest of its JSON arguments text. `finalInput` is the complete
|
|
170
|
+
* input when the provider sends one; it must continue the input streamed so far. Closing again with the same input
|
|
171
|
+
* returns `undefined`.
|
|
172
|
+
*/
|
|
173
|
+
export function closeGrammarToolInputJson(buffer, inputProperty, finalInput) {
|
|
174
|
+
if (buffer.closed) {
|
|
175
|
+
if (finalInput === undefined || finalInput === buffer.input)
|
|
176
|
+
return undefined;
|
|
177
|
+
throw new Error(`grammar tool input for property "${inputProperty}" changed after it was closed`);
|
|
178
|
+
}
|
|
179
|
+
if (finalInput !== undefined && !finalInput.startsWith(buffer.input)) {
|
|
180
|
+
throw new Error(`grammar tool input for property "${inputProperty}" changed non-monotonically`);
|
|
181
|
+
}
|
|
182
|
+
const rest = finalInput === undefined ? "" : finalInput.slice(buffer.input.length);
|
|
183
|
+
if (finalInput !== undefined)
|
|
184
|
+
buffer.input = finalInput;
|
|
185
|
+
buffer.closed = true;
|
|
186
|
+
return `${grammarToolInputJsonStart(buffer, inputProperty)}${JSON.stringify(rest).slice(1, -1)}"}`;
|
|
187
|
+
}
|
|
188
|
+
/** The opening of the JSON arguments text, once. */
|
|
189
|
+
function grammarToolInputJsonStart(buffer, inputProperty) {
|
|
190
|
+
if (buffer.started)
|
|
191
|
+
return "";
|
|
192
|
+
buffer.started = true;
|
|
193
|
+
return `{${JSON.stringify(inputProperty)}:"`;
|
|
194
|
+
}
|
|
195
|
+
function inferGrammarInputProperty(tool) {
|
|
196
|
+
const schema = tool.parameters;
|
|
197
|
+
if (schema.type !== "object") {
|
|
198
|
+
throw new Error("grammar constrained sampling requires an object parameter schema");
|
|
199
|
+
}
|
|
200
|
+
if (!Array.isArray(schema.required) || schema.required.length !== 1 || typeof schema.required[0] !== "string") {
|
|
201
|
+
throw new Error("grammar constrained sampling requires exactly one required string property");
|
|
202
|
+
}
|
|
203
|
+
const inputProperty = schema.required[0];
|
|
204
|
+
if (!schema.properties?.[inputProperty]) {
|
|
205
|
+
throw new Error(`grammar constrained sampling requires a properties entry for ${inputProperty}`);
|
|
206
|
+
}
|
|
207
|
+
if (schema.properties[inputProperty]?.type !== "string") {
|
|
208
|
+
throw new Error(`grammar constrained sampling property ${inputProperty} must have type string`);
|
|
209
|
+
}
|
|
210
|
+
return inputProperty;
|
|
211
|
+
}
|
|
212
|
+
export function resolveJsonSchemaStrictSampling(tool, supportsStrictMode, profile) {
|
|
213
|
+
const config = tool.constrainedSampling;
|
|
214
|
+
if (!config || config.type !== "json_schema")
|
|
215
|
+
return undefined;
|
|
216
|
+
if (supportsStrictMode) {
|
|
217
|
+
try {
|
|
218
|
+
makeStrictJsonSchema(tool.parameters, profile);
|
|
219
|
+
return true;
|
|
220
|
+
}
|
|
221
|
+
catch (error) {
|
|
222
|
+
if (!(error instanceof UnsupportedStrictJsonSchemaError))
|
|
223
|
+
throw error;
|
|
224
|
+
if (config.strict !== "require")
|
|
225
|
+
return undefined;
|
|
226
|
+
throw new Error(`Tool "${tool.name}" requires JSON-schema constrained sampling, but ${error.message}.`);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
if (config.strict === "require") {
|
|
230
|
+
throw new Error(`Tool "${tool.name}" requires JSON-schema constrained sampling, but strict tools are unsupported.`);
|
|
231
|
+
}
|
|
232
|
+
return undefined;
|
|
233
|
+
}
|
|
234
|
+
export function resolveGrammarConstrainedSampling(tool, supportsOpenAIGrammarTools) {
|
|
235
|
+
const config = tool.constrainedSampling;
|
|
236
|
+
if (!config || config.type !== "grammar") {
|
|
237
|
+
return undefined;
|
|
238
|
+
}
|
|
239
|
+
if (!supportsOpenAIGrammarTools) {
|
|
240
|
+
return undefined;
|
|
241
|
+
}
|
|
242
|
+
const larkDefinition = config.variants.openai_lark;
|
|
243
|
+
const regexDefinition = config.variants.openai_regex;
|
|
244
|
+
const hasLarkDefinition = typeof larkDefinition === "string" && larkDefinition.trim().length > 0;
|
|
245
|
+
const hasRegexDefinition = typeof regexDefinition === "string" && regexDefinition.trim().length > 0;
|
|
246
|
+
if (!hasLarkDefinition && !hasRegexDefinition) {
|
|
247
|
+
throw new Error(`Tool "${tool.name}" cannot use grammar constrained sampling: no supported grammar variant was provided.`);
|
|
248
|
+
}
|
|
249
|
+
try {
|
|
250
|
+
return {
|
|
251
|
+
format: hasLarkDefinition ? "lark" : "regex",
|
|
252
|
+
definition: hasLarkDefinition ? larkDefinition : regexDefinition,
|
|
253
|
+
inputProperty: inferGrammarInputProperty(tool),
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
catch (error) {
|
|
257
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
258
|
+
throw new Error(`Tool "${tool.name}" cannot use grammar constrained sampling: ${message}.`);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
export function createGrammarToolInputProperties(tools, supportsOpenAIGrammarTools) {
|
|
262
|
+
const properties = new Map();
|
|
263
|
+
for (const tool of tools ?? []) {
|
|
264
|
+
const grammar = resolveGrammarConstrainedSampling(tool, supportsOpenAIGrammarTools);
|
|
265
|
+
if (grammar) {
|
|
266
|
+
properties.set(tool.name, grammar.inputProperty);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
return properties;
|
|
270
|
+
}
|
|
271
|
+
//# 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;AAEvD,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;AAQX,MAAM,CAAC,MAAM,oCAAoC,GAA4B,MAAM,CAAC,MAAM,CAAC;IAC1F,mBAAmB,EAAE,MAAM,CAAC,MAAM,CAAC;QAClC,SAAS;QACT,SAAS;QACT,kBAAkB;QAClB,kBAAkB;QAClB,YAAY;QACZ,aAAa;QACb,aAAa;QACb,aAAa;QACb,eAAe;QACf,eAAe;QACf,UAAU;KAC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C;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\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\nexport interface StrictJsonSchemaProfile {\n\treadonly unsupportedKeywords: readonly string[];\n\treadonly maxMinItems?: number;\n\treadonly supportedStringFormats?: readonly string[];\n}\n\nexport const ANTHROPIC_STRICT_JSON_SCHEMA_PROFILE: StrictJsonSchemaProfile = Object.freeze({\n\tunsupportedKeywords: Object.freeze([\n\t\t\"minimum\",\n\t\t\"maximum\",\n\t\t\"exclusiveMinimum\",\n\t\t\"exclusiveMaximum\",\n\t\t\"multipleOf\",\n\t\t\"uniqueItems\",\n\t\t\"minContains\",\n\t\t\"maxContains\",\n\t\t\"minProperties\",\n\t\t\"maxProperties\",\n\t\t\"maxItems\",\n\t]),\n\tmaxMinItems: 1,\n\tsupportedStringFormats: Object.freeze([\"date-time\", \"time\", \"date\", \"duration\", \"email\", \"hostname\", \"uri\", \"ipv4\", \"ipv6\", \"uuid\"]),\n});\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, profile: StrictJsonSchemaProfile | undefined): 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, ...(profile?.unsupportedKeywords ?? [])]) {\n\t\tif (schema[key] !== undefined) {\n\t\t\tthrow new UnsupportedStrictJsonSchemaError(`${key} schemas are unsupported`);\n\t\t}\n\t}\n\tif (\n\t\tprofile?.maxMinItems !== undefined &&\n\t\tschema.minItems !== undefined &&\n\t\t(typeof schema.minItems !== \"number\" || !Number.isInteger(schema.minItems) || schema.minItems < 0 || schema.minItems > profile.maxMinItems)\n\t) {\n\t\tthrow new UnsupportedStrictJsonSchemaError(`minItems must be an integer from 0 to ${profile.maxMinItems}`);\n\t}\n\tif (profile?.supportedStringFormats && schema.format !== undefined &&\n\t\t(typeof schema.format !== \"string\" || !profile.supportedStringFormats.includes(schema.format))) {\n\t\tthrow new UnsupportedStrictJsonSchemaError(`format: ${JSON.stringify(schema.format)} is unsupported`);\n\t}\n\n\tif (schema.type === undefined && schema.anyOf === undefined && schema.enum === undefined) {\n\t\tthrow new UnsupportedStrictJsonSchemaError(\"schemas without a type are unsupported\");\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, profile);\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, profile);\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, profile);\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\tprofile?: StrictJsonSchemaProfile,\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, profile);\n\tif (cloned.type !== \"object\") {\n\t\tthrow new UnsupportedStrictJsonSchemaError(\"root schema must have type object\");\n\t}\n\treturn cloned;\n}\n\n/** Returns true for a tool that asks for strict JSON-schema sampling only when possible (`strict: \"prefer\"`). */\nexport function prefersJsonSchemaStrictSampling(tool: Tool): boolean {\n\tconst config = tool.constrainedSampling;\n\treturn !!config && config.type === \"json_schema\" && config.strict === \"prefer\";\n}\n\nexport function getJsonSchemaToolParameters(\n\ttool: Tool,\n\tstrict: boolean | undefined,\n\tprofile?: StrictJsonSchemaProfile,\n): Tool[\"parameters\"] {\n\treturn (strict === true ? makeStrictJsonSchema(tool.parameters, profile) : 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\n/**\n * Append `inputDelta` to a streaming grammar tool input and return the matching piece of its JSON arguments text, or\n * `undefined` for an empty delta. Costs time linear in the delta, never in the input so far.\n */\nexport function appendGrammarToolInputJsonDelta(\n\tbuffer: GrammarToolInputJsonBuffer,\n\tinputProperty: string,\n\tinputDelta: string,\n): string | undefined {\n\tif (buffer.closed) {\n\t\tthrow new Error(`grammar tool input for property \"${inputProperty}\" changed after it was closed`);\n\t}\n\tif (inputDelta.length === 0) return undefined;\n\tbuffer.input += inputDelta;\n\treturn grammarToolInputJsonStart(buffer, inputProperty) + JSON.stringify(inputDelta).slice(1, -1);\n}\n\n/**\n * Close a streaming grammar tool input and return the rest of its JSON arguments text. `finalInput` is the complete\n * input when the provider sends one; it must continue the input streamed so far. Closing again with the same input\n * returns `undefined`.\n */\nexport function closeGrammarToolInputJson(\n\tbuffer: GrammarToolInputJsonBuffer,\n\tinputProperty: string,\n\tfinalInput: string | undefined,\n): string | undefined {\n\tif (buffer.closed) {\n\t\tif (finalInput === undefined || finalInput === buffer.input) return undefined;\n\t\tthrow new Error(`grammar tool input for property \"${inputProperty}\" changed after it was closed`);\n\t}\n\tif (finalInput !== undefined && !finalInput.startsWith(buffer.input)) {\n\t\tthrow new Error(`grammar tool input for property \"${inputProperty}\" changed non-monotonically`);\n\t}\n\tconst rest = finalInput === undefined ? \"\" : finalInput.slice(buffer.input.length);\n\tif (finalInput !== undefined) buffer.input = finalInput;\n\tbuffer.closed = true;\n\treturn `${grammarToolInputJsonStart(buffer, inputProperty)}${JSON.stringify(rest).slice(1, -1)}\"}`;\n}\n\n/** The opening of the JSON arguments text, once. */\nfunction grammarToolInputJsonStart(buffer: GrammarToolInputJsonBuffer, inputProperty: string): string {\n\tif (buffer.started) return \"\";\n\tbuffer.started = true;\n\treturn `{${JSON.stringify(inputProperty)}:\"`;\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\nexport function resolveJsonSchemaStrictSampling(\n\ttool: Tool,\n\tsupportsStrictMode: boolean,\n\tprofile?: StrictJsonSchemaProfile,\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, profile);\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,40 @@
|
|
|
1
|
+
import type { Message, ProviderHeaders } from "../types.ts";
|
|
2
|
+
export declare function inferCopilotInitiator(messages: Message[]): "user" | "agent";
|
|
3
|
+
export declare function hasCopilotVisionInput(messages: Message[]): boolean;
|
|
4
|
+
/**
|
|
5
|
+
* Environment/API-key Copilot credentials are raw GitHub tokens unless they
|
|
6
|
+
* contain the `tid=` segment emitted by the Copilot token exchange.
|
|
7
|
+
*
|
|
8
|
+
* A missing credential is not classified as raw: callers may be supplying
|
|
9
|
+
* authentication through headers, and adding an integration id in that case
|
|
10
|
+
* would change requests that do not have a resolved bearer token.
|
|
11
|
+
*/
|
|
12
|
+
export declare function isRawCopilotToken(apiKey: string | undefined): boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Keep a custom provider/model integration id ahead of the dynamic default.
|
|
15
|
+
* Built-in Copilot models carry `vscode-chat` as their OAuth static header;
|
|
16
|
+
* raw-token requests replace that built-in value with the developer CLI id.
|
|
17
|
+
* In the pi-ai layer alone, an explicitly supplied `vscode-chat` value is
|
|
18
|
+
* indistinguishable from the catalog default and is replaced for raw-token
|
|
19
|
+
* requests; the Atomic coding agent resolves header provenance separately so
|
|
20
|
+
* an explicitly configured `vscode-chat` survives there. A per-request header
|
|
21
|
+
* is merged later and always wins.
|
|
22
|
+
*/
|
|
23
|
+
export declare function preserveCopilotIntegrationHeader(modelHeaders: ProviderHeaders | undefined, dynamicHeaders: Record<string, string>): Record<string, string>;
|
|
24
|
+
/** Client identity headers every GitHub Copilot request carries. */
|
|
25
|
+
export declare const COPILOT_HEADERS: {
|
|
26
|
+
readonly "User-Agent": "GitHubCopilotChat/0.35.0";
|
|
27
|
+
readonly "Editor-Version": "vscode/1.107.0";
|
|
28
|
+
readonly "Editor-Plugin-Version": "copilot-chat/0.35.0";
|
|
29
|
+
readonly "Copilot-Integration-Id": "vscode-chat";
|
|
30
|
+
};
|
|
31
|
+
/** API version for reading the account's model list. */
|
|
32
|
+
export declare const COPILOT_API_VERSION = "2026-06-01";
|
|
33
|
+
/** Identity headers for a request outside a conversation, such as reading the account's model list. */
|
|
34
|
+
export declare function copilotClientHeaders(apiKey: string): Record<string, string>;
|
|
35
|
+
export declare function buildCopilotDynamicHeaders(params: {
|
|
36
|
+
messages: Message[];
|
|
37
|
+
hasImages: boolean;
|
|
38
|
+
apiKey?: string;
|
|
39
|
+
}): Record<string, string>;
|
|
40
|
+
//# 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,eAAe,EAAE,MAAM,aAAa,CAAC;AAI5D,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,OAAO,EAAE,GAAG,MAAM,GAAG,OAAO,CAG3E;AAGD,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,OAAO,EAAE,GAAG,OAAO,CAUlE;AAED;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAErE;AAED;;;;;;;;;GASG;AACH,wBAAgB,gCAAgC,CAC/C,YAAY,EAAE,eAAe,GAAG,SAAS,EACzC,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GACpC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CASxB;AAED,oEAAoE;AACpE,eAAO,MAAM,eAAe;aAC3B,YAAY,EAAE,0BAA0B;aACxC,gBAAgB,EAAE,gBAAgB;aAClC,uBAAuB,EAAE,qBAAqB;aAC9C,wBAAwB,EAAE,aAAa;CAC9B,CAAC;AAEX,wDAAwD;AACxD,eAAO,MAAM,mBAAmB,eAAe,CAAC;AAKhD,uGAAuG;AACvG,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAI3E;AAED,wBAAgB,0BAA0B,CAAC,MAAM,EAAE;IAClD,QAAQ,EAAE,OAAO,EAAE,CAAC;IACpB,SAAS,EAAE,OAAO,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;CAChB,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAezB"}
|
|
@@ -0,0 +1,76 @@
|
|
|
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
|
+
/**
|
|
20
|
+
* Environment/API-key Copilot credentials are raw GitHub tokens unless they
|
|
21
|
+
* contain the `tid=` segment emitted by the Copilot token exchange.
|
|
22
|
+
*
|
|
23
|
+
* A missing credential is not classified as raw: callers may be supplying
|
|
24
|
+
* authentication through headers, and adding an integration id in that case
|
|
25
|
+
* would change requests that do not have a resolved bearer token.
|
|
26
|
+
*/
|
|
27
|
+
export function isRawCopilotToken(apiKey) {
|
|
28
|
+
return apiKey !== undefined && apiKey.length > 0 && !apiKey.split(";").some((segment) => segment.startsWith("tid="));
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Keep a custom provider/model integration id ahead of the dynamic default.
|
|
32
|
+
* Built-in Copilot models carry `vscode-chat` as their OAuth static header;
|
|
33
|
+
* raw-token requests replace that built-in value with the developer CLI id.
|
|
34
|
+
* In the pi-ai layer alone, an explicitly supplied `vscode-chat` value is
|
|
35
|
+
* indistinguishable from the catalog default and is replaced for raw-token
|
|
36
|
+
* requests; the Atomic coding agent resolves header provenance separately so
|
|
37
|
+
* an explicitly configured `vscode-chat` survives there. A per-request header
|
|
38
|
+
* is merged later and always wins.
|
|
39
|
+
*/
|
|
40
|
+
export function preserveCopilotIntegrationHeader(modelHeaders, dynamicHeaders) {
|
|
41
|
+
const modelIntegrationHeader = Object.entries(modelHeaders ?? {}).find(([name]) => name.toLowerCase() === "copilot-integration-id");
|
|
42
|
+
if (!modelIntegrationHeader || modelIntegrationHeader[1] === "vscode-chat")
|
|
43
|
+
return dynamicHeaders;
|
|
44
|
+
return Object.fromEntries(Object.entries(dynamicHeaders).filter(([name]) => name.toLowerCase() !== "copilot-integration-id"));
|
|
45
|
+
}
|
|
46
|
+
/** Client identity headers every GitHub Copilot request carries. */
|
|
47
|
+
export const COPILOT_HEADERS = {
|
|
48
|
+
"User-Agent": "GitHubCopilotChat/0.35.0",
|
|
49
|
+
"Editor-Version": "vscode/1.107.0",
|
|
50
|
+
"Editor-Plugin-Version": "copilot-chat/0.35.0",
|
|
51
|
+
"Copilot-Integration-Id": "vscode-chat",
|
|
52
|
+
};
|
|
53
|
+
/** API version for reading the account's model list. */
|
|
54
|
+
export const COPILOT_API_VERSION = "2026-06-01";
|
|
55
|
+
/** Integration ID GitHub Copilot expects with a raw GitHub token. */
|
|
56
|
+
const RAW_TOKEN_INTEGRATION_ID = "copilot-developer-cli";
|
|
57
|
+
/** Identity headers for a request outside a conversation, such as reading the account's model list. */
|
|
58
|
+
export function copilotClientHeaders(apiKey) {
|
|
59
|
+
return isRawCopilotToken(apiKey)
|
|
60
|
+
? { ...COPILOT_HEADERS, "Copilot-Integration-Id": RAW_TOKEN_INTEGRATION_ID }
|
|
61
|
+
: { ...COPILOT_HEADERS };
|
|
62
|
+
}
|
|
63
|
+
export function buildCopilotDynamicHeaders(params) {
|
|
64
|
+
const headers = {
|
|
65
|
+
"X-Initiator": inferCopilotInitiator(params.messages),
|
|
66
|
+
"Openai-Intent": "conversation-edits",
|
|
67
|
+
};
|
|
68
|
+
if (params.hasImages) {
|
|
69
|
+
headers["Copilot-Vision-Request"] = "true";
|
|
70
|
+
}
|
|
71
|
+
if (isRawCopilotToken(params.apiKey)) {
|
|
72
|
+
headers["Copilot-Integration-Id"] = RAW_TOKEN_INTEGRATION_ID;
|
|
73
|
+
}
|
|
74
|
+
return headers;
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=github-copilot-headers.js.map
|