@fractaal/pi-ai 0.85.4 → 0.86.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/README.md +322 -46
- package/dist/api/anthropic-messages.d.ts.map +1 -1
- package/dist/api/anthropic-messages.js +403 -140
- package/dist/api/anthropic-messages.js.map +1 -1
- package/dist/api/anthropic-messages.lazy.d.ts.map +1 -1
- package/dist/api/azure-openai-config.d.ts +15 -0
- package/dist/api/azure-openai-config.d.ts.map +1 -0
- package/dist/api/azure-openai-config.js +76 -0
- package/dist/api/azure-openai-config.js.map +1 -0
- package/dist/api/azure-openai-responses.d.ts +5 -6
- package/dist/api/azure-openai-responses.d.ts.map +1 -1
- package/dist/api/azure-openai-responses.js +42 -86
- package/dist/api/azure-openai-responses.js.map +1 -1
- package/dist/api/azure-openai-responses.lazy.d.ts.map +1 -1
- package/dist/api/bedrock-converse-stream.d.ts.map +1 -1
- package/dist/api/bedrock-converse-stream.js +233 -24
- package/dist/api/bedrock-converse-stream.js.map +1 -1
- package/dist/api/bedrock-converse-stream.lazy.d.ts.map +1 -1
- package/dist/api/bedrock-converse-stream.lazy.js.map +1 -1
- package/dist/api/cloudflare-ai-binding.d.ts +77 -0
- package/dist/api/cloudflare-ai-binding.d.ts.map +1 -0
- package/dist/api/cloudflare-ai-binding.js +72 -0
- package/dist/api/cloudflare-ai-binding.js.map +1 -0
- package/dist/api/cloudflare-workers-ai-system-one.d.ts +4 -0
- package/dist/api/cloudflare-workers-ai-system-one.d.ts.map +1 -0
- package/dist/api/cloudflare-workers-ai-system-one.js +48 -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 +2 -0
- package/dist/api/cloudflare.d.ts.map +1 -1
- package/dist/api/cloudflare.js +2 -0
- package/dist/api/cloudflare.js.map +1 -1
- package/dist/api/constrained-sampling.d.ts +10 -1
- package/dist/api/constrained-sampling.d.ts.map +1 -1
- package/dist/api/constrained-sampling.js +137 -4
- package/dist/api/constrained-sampling.js.map +1 -1
- package/dist/api/github-copilot-headers.d.ts.map +1 -1
- package/dist/api/github-copilot-headers.js.map +1 -1
- package/dist/api/google-generative-ai.d.ts +2 -2
- package/dist/api/google-generative-ai.d.ts.map +1 -1
- package/dist/api/google-generative-ai.js +39 -82
- package/dist/api/google-generative-ai.js.map +1 -1
- package/dist/api/google-generative-ai.lazy.d.ts.map +1 -1
- package/dist/api/google-shared.d.ts +27 -5
- package/dist/api/google-shared.d.ts.map +1 -1
- package/dist/api/google-shared.js +126 -18
- package/dist/api/google-shared.js.map +1 -1
- package/dist/api/google-vertex.d.ts +2 -2
- package/dist/api/google-vertex.d.ts.map +1 -1
- package/dist/api/google-vertex.js +42 -73
- package/dist/api/google-vertex.js.map +1 -1
- package/dist/api/google-vertex.lazy.d.ts.map +1 -1
- package/dist/api/lazy.d.ts +5 -1
- package/dist/api/lazy.d.ts.map +1 -1
- package/dist/api/lazy.js +19 -7
- package/dist/api/lazy.js.map +1 -1
- 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 +365 -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 +2 -2
- package/dist/api/mistral-conversations.d.ts.map +1 -1
- package/dist/api/mistral-conversations.js +250 -69
- package/dist/api/mistral-conversations.js.map +1 -1
- package/dist/api/mistral-conversations.lazy.d.ts.map +1 -1
- package/dist/api/openai-codex-compaction-history.d.ts +2 -2
- package/dist/api/openai-codex-compaction-history.d.ts.map +1 -1
- package/dist/api/openai-codex-compaction-history.js +1 -2
- package/dist/api/openai-codex-compaction-history.js.map +1 -1
- package/dist/api/openai-codex-responses.d.ts +1 -1
- package/dist/api/openai-codex-responses.d.ts.map +1 -1
- package/dist/api/openai-codex-responses.js +107 -60
- package/dist/api/openai-codex-responses.js.map +1 -1
- package/dist/api/openai-codex-responses.lazy.d.ts.map +1 -1
- package/dist/api/openai-codex-responses.lazy.js.map +1 -1
- package/dist/api/openai-completions.d.ts +11 -4
- package/dist/api/openai-completions.d.ts.map +1 -1
- package/dist/api/openai-completions.js +250 -134
- package/dist/api/openai-completions.js.map +1 -1
- package/dist/api/openai-completions.lazy.d.ts.map +1 -1
- package/dist/api/openai-prompt-cache.d.ts.map +1 -1
- package/dist/api/openai-prompt-cache.js.map +1 -1
- package/dist/api/openai-responses-shared.d.ts +8 -4
- package/dist/api/openai-responses-shared.d.ts.map +1 -1
- package/dist/api/openai-responses-shared.js +114 -62
- package/dist/api/openai-responses-shared.js.map +1 -1
- package/dist/api/openai-responses.d.ts.map +1 -1
- package/dist/api/openai-responses.js +55 -23
- package/dist/api/openai-responses.js.map +1 -1
- package/dist/api/openai-responses.lazy.d.ts.map +1 -1
- package/dist/api/openrouter-images.d.ts +2 -1
- package/dist/api/openrouter-images.d.ts.map +1 -1
- package/dist/api/openrouter-images.js +1 -0
- package/dist/api/openrouter-images.js.map +1 -1
- package/dist/api/openrouter-images.lazy.d.ts.map +1 -1
- package/dist/api/openrouter-images.lazy.js.map +1 -1
- package/dist/api/pi-messages.d.ts +5 -3
- package/dist/api/pi-messages.d.ts.map +1 -1
- package/dist/api/pi-messages.js +10 -3
- package/dist/api/pi-messages.js.map +1 -1
- package/dist/api/pi-messages.lazy.d.ts.map +1 -1
- package/dist/api/simple-options.d.ts +10 -3
- package/dist/api/simple-options.d.ts.map +1 -1
- package/dist/api/simple-options.js +31 -11
- package/dist/api/simple-options.js.map +1 -1
- package/dist/api/system-one-shared.d.ts +23 -0
- package/dist/api/system-one-shared.d.ts.map +1 -0
- package/dist/api/system-one-shared.js +183 -0
- package/dist/api/system-one-shared.js.map +1 -0
- package/dist/api/transform-messages.d.ts.map +1 -1
- package/dist/api/transform-messages.js +21 -7
- package/dist/api/transform-messages.js.map +1 -1
- 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 +19 -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.map +1 -1
- package/dist/auth/context.js.map +1 -1
- package/dist/auth/credential-store.d.ts +6 -6
- package/dist/auth/credential-store.d.ts.map +1 -1
- package/dist/auth/credential-store.js +22 -11
- package/dist/auth/credential-store.js.map +1 -1
- package/dist/auth/helpers.d.ts +1 -0
- package/dist/auth/helpers.d.ts.map +1 -1
- package/dist/auth/helpers.js +8 -3
- package/dist/auth/helpers.js.map +1 -1
- package/dist/auth/oauth/anthropic.d.ts.map +1 -1
- package/dist/auth/oauth/anthropic.js +78 -131
- package/dist/auth/oauth/anthropic.js.map +1 -1
- package/dist/auth/oauth/callback-server.d.ts +55 -0
- package/dist/auth/oauth/callback-server.d.ts.map +1 -0
- package/dist/auth/oauth/callback-server.js +146 -0
- package/dist/auth/oauth/callback-server.js.map +1 -0
- package/dist/auth/oauth/device-code.d.ts +2 -1
- package/dist/auth/oauth/device-code.d.ts.map +1 -1
- package/dist/auth/oauth/device-code.js +5 -5
- package/dist/auth/oauth/device-code.js.map +1 -1
- package/dist/auth/oauth/github-copilot.d.ts.map +1 -1
- package/dist/auth/oauth/github-copilot.js +121 -41
- package/dist/auth/oauth/github-copilot.js.map +1 -1
- package/dist/auth/oauth/kimi-coding.d.ts.map +1 -1
- package/dist/auth/oauth/kimi-coding.js +5 -6
- package/dist/auth/oauth/kimi-coding.js.map +1 -1
- package/dist/auth/oauth/load.d.ts +4 -0
- package/dist/auth/oauth/load.d.ts.map +1 -1
- package/dist/auth/oauth/load.js +10 -0
- package/dist/auth/oauth/load.js.map +1 -1
- package/dist/auth/oauth/meta.d.ts +17 -0
- package/dist/auth/oauth/meta.d.ts.map +1 -0
- package/dist/auth/oauth/meta.js +190 -0
- package/dist/auth/oauth/meta.js.map +1 -0
- package/dist/auth/oauth/openai-chatgpt.d.ts +9 -0
- package/dist/auth/oauth/openai-chatgpt.d.ts.map +1 -0
- package/dist/auth/oauth/openai-chatgpt.js +263 -0
- package/dist/auth/oauth/openai-chatgpt.js.map +1 -0
- package/dist/auth/oauth/openai-codex-errors.d.ts.map +1 -1
- package/dist/auth/oauth/openai-codex-errors.js.map +1 -1
- package/dist/auth/oauth/openai-codex.d.ts +1 -1
- package/dist/auth/oauth/openai-codex.d.ts.map +1 -1
- package/dist/auth/oauth/openai-codex.js +23 -152
- package/dist/auth/oauth/openai-codex.js.map +1 -1
- package/dist/auth/oauth/openrouter.d.ts +1 -1
- package/dist/auth/oauth/openrouter.d.ts.map +1 -1
- package/dist/auth/oauth/openrouter.js +25 -144
- package/dist/auth/oauth/openrouter.js.map +1 -1
- package/dist/auth/oauth/pkce.d.ts.map +1 -1
- package/dist/auth/oauth/pkce.js.map +1 -1
- package/dist/auth/oauth/radius.d.ts +1 -1
- package/dist/auth/oauth/radius.d.ts.map +1 -1
- package/dist/auth/oauth/radius.js +26 -93
- package/dist/auth/oauth/radius.js.map +1 -1
- package/dist/auth/oauth/xai.d.ts.map +1 -1
- package/dist/auth/oauth/xai.js +3 -2
- package/dist/auth/oauth/xai.js.map +1 -1
- package/dist/auth/resolve.d.ts +19 -9
- package/dist/auth/resolve.d.ts.map +1 -1
- package/dist/auth/resolve.js +72 -53
- package/dist/auth/resolve.js.map +1 -1
- package/dist/auth/types.d.ts +29 -8
- package/dist/auth/types.d.ts.map +1 -1
- package/dist/auth/types.js.map +1 -1
- package/dist/bedrock-provider.d.ts.map +1 -1
- package/dist/bun-oauth.d.ts.map +1 -1
- package/dist/bun-oauth.js +4 -0
- package/dist/bun-oauth.js.map +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +4 -1
- package/dist/cli.js.map +1 -1
- package/dist/compat/extension-oauth-types.d.ts.map +1 -1
- package/dist/compat.d.ts +3 -3
- package/dist/compat.d.ts.map +1 -1
- package/dist/compat.js +9 -6
- package/dist/compat.js.map +1 -1
- package/dist/env-api-keys.d.ts +5 -0
- package/dist/env-api-keys.d.ts.map +1 -1
- package/dist/env-api-keys.js +10 -1
- package/dist/env-api-keys.js.map +1 -1
- package/dist/image-models.d.ts +19 -8
- package/dist/image-models.d.ts.map +1 -1
- package/dist/image-models.js +14 -13
- package/dist/image-models.js.map +1 -1
- package/dist/images-api-registry.d.ts +7 -7
- package/dist/images-api-registry.d.ts.map +1 -1
- package/dist/images-api-registry.js.map +1 -1
- package/dist/images.d.ts +7 -2
- package/dist/images.d.ts.map +1 -1
- package/dist/images.js +5 -0
- package/dist/images.js.map +1 -1
- package/dist/index.d.ts +4 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/legacy-api-aliases.d.ts.map +1 -1
- package/dist/model-catalog.d.ts +25 -9
- package/dist/model-catalog.d.ts.map +1 -1
- package/dist/model-catalog.js +14 -2
- package/dist/model-catalog.js.map +1 -1
- package/dist/models-store.d.ts +12 -14
- package/dist/models-store.d.ts.map +1 -1
- package/dist/models-store.js +6 -3
- package/dist/models-store.js.map +1 -1
- package/dist/models.d.ts +138 -47
- package/dist/models.d.ts.map +1 -1
- package/dist/models.generated.d.ts +136 -38
- package/dist/models.generated.d.ts.map +1 -1
- package/dist/models.generated.js +136 -38
- package/dist/models.generated.js.map +1 -1
- package/dist/models.js +390 -104
- package/dist/models.js.map +1 -1
- package/dist/oauth.d.ts.map +1 -1
- package/dist/providers/all.d.ts +19 -13
- package/dist/providers/all.d.ts.map +1 -1
- package/dist/providers/all.js +33 -23
- package/dist/providers/all.js.map +1 -1
- package/dist/providers/amazon-bedrock.d.ts.map +1 -1
- package/dist/providers/amazon-bedrock.js +15 -7
- package/dist/providers/amazon-bedrock.js.map +1 -1
- package/dist/providers/amazon-bedrock.models.d.ts +4 -2
- package/dist/providers/amazon-bedrock.models.d.ts.map +1 -1
- package/dist/providers/amazon-bedrock.models.js +4 -2
- package/dist/providers/amazon-bedrock.models.js.map +1 -1
- package/dist/providers/ant-ling.d.ts.map +1 -1
- package/dist/providers/ant-ling.js.map +1 -1
- package/dist/providers/ant-ling.models.d.ts +4 -2
- package/dist/providers/ant-ling.models.d.ts.map +1 -1
- package/dist/providers/ant-ling.models.js +4 -2
- package/dist/providers/ant-ling.models.js.map +1 -1
- package/dist/providers/anthropic.d.ts.map +1 -1
- package/dist/providers/anthropic.js +39 -8
- package/dist/providers/anthropic.js.map +1 -1
- package/dist/providers/anthropic.models.d.ts +4 -2
- package/dist/providers/anthropic.models.d.ts.map +1 -1
- package/dist/providers/anthropic.models.js +4 -2
- package/dist/providers/anthropic.models.js.map +1 -1
- package/dist/providers/azure.d.ts +3 -0
- package/dist/providers/azure.d.ts.map +1 -0
- package/dist/providers/azure.js +46 -0
- package/dist/providers/azure.js.map +1 -0
- package/dist/providers/azure.models.d.ts +6 -0
- package/dist/providers/azure.models.d.ts.map +1 -0
- package/dist/providers/azure.models.js +8 -0
- package/dist/providers/azure.models.js.map +1 -0
- package/dist/providers/baseten.d.ts +3 -0
- package/dist/providers/baseten.d.ts.map +1 -0
- package/dist/providers/baseten.js +15 -0
- package/dist/providers/baseten.js.map +1 -0
- package/dist/providers/baseten.models.d.ts +6 -0
- package/dist/providers/baseten.models.d.ts.map +1 -0
- package/dist/providers/baseten.models.js +8 -0
- package/dist/providers/baseten.models.js.map +1 -0
- package/dist/providers/cerebras.d.ts.map +1 -1
- package/dist/providers/cerebras.js.map +1 -1
- package/dist/providers/cerebras.models.d.ts +4 -2
- package/dist/providers/cerebras.models.d.ts.map +1 -1
- package/dist/providers/cerebras.models.js +4 -2
- package/dist/providers/cerebras.models.js.map +1 -1
- package/dist/providers/cloudflare-ai-gateway.d.ts +3 -1
- package/dist/providers/cloudflare-ai-gateway.d.ts.map +1 -1
- package/dist/providers/cloudflare-ai-gateway.js +4 -0
- package/dist/providers/cloudflare-ai-gateway.js.map +1 -1
- package/dist/providers/cloudflare-ai-gateway.models.d.ts +4 -2
- package/dist/providers/cloudflare-ai-gateway.models.d.ts.map +1 -1
- package/dist/providers/cloudflare-ai-gateway.models.js +4 -2
- package/dist/providers/cloudflare-ai-gateway.models.js.map +1 -1
- package/dist/providers/cloudflare-auth.d.ts.map +1 -1
- package/dist/providers/cloudflare-auth.js +15 -10
- package/dist/providers/cloudflare-auth.js.map +1 -1
- package/dist/providers/cloudflare-stream.d.ts +6 -2
- package/dist/providers/cloudflare-stream.d.ts.map +1 -1
- package/dist/providers/cloudflare-stream.js +6 -0
- package/dist/providers/cloudflare-stream.js.map +1 -1
- package/dist/providers/cloudflare-workers-ai.d.ts.map +1 -1
- package/dist/providers/cloudflare-workers-ai.js +10 -3
- package/dist/providers/cloudflare-workers-ai.js.map +1 -1
- package/dist/providers/cloudflare-workers-ai.models.d.ts +4 -2
- package/dist/providers/cloudflare-workers-ai.models.d.ts.map +1 -1
- package/dist/providers/cloudflare-workers-ai.models.js +4 -2
- package/dist/providers/cloudflare-workers-ai.models.js.map +1 -1
- package/dist/providers/data/.manifest.json +1 -1
- package/dist/providers/data/amazon-bedrock.json +1 -1
- package/dist/providers/data/ant-ling.json +1 -1
- package/dist/providers/data/anthropic.json +1 -1
- package/dist/providers/data/azure.json +1 -0
- package/dist/providers/data/baseten.json +1 -0
- package/dist/providers/data/cerebras.json +1 -1
- package/dist/providers/data/cloudflare-ai-gateway.json +1 -1
- package/dist/providers/data/cloudflare-workers-ai.json +1 -1
- package/dist/providers/data/deepseek.json +1 -1
- package/dist/providers/data/fireworks.json +1 -1
- package/dist/providers/data/github-copilot.json +1 -1
- package/dist/providers/data/google-vertex.json +1 -1
- package/dist/providers/data/google.json +1 -1
- package/dist/providers/data/groq.json +1 -1
- package/dist/providers/data/huggingface.json +1 -1
- package/dist/providers/data/kimi-coding.json +1 -1
- package/dist/providers/data/meta.json +1 -0
- package/dist/providers/data/minimax-cn.json +1 -1
- package/dist/providers/data/minimax.json +1 -1
- package/dist/providers/data/mistral.json +1 -1
- package/dist/providers/data/moonshotai-cn.json +1 -1
- package/dist/providers/data/moonshotai.json +1 -1
- package/dist/providers/data/nvidia.json +1 -1
- package/dist/providers/data/openai-codex.json +1 -1
- package/dist/providers/data/openai.json +1 -1
- package/dist/providers/data/opencode-go.json +1 -1
- package/dist/providers/data/opencode.json +1 -1
- package/dist/providers/data/openrouter.json +1 -1
- package/dist/providers/data/qwen-token-plan-cn.json +1 -1
- package/dist/providers/data/qwen-token-plan-individual.json +1 -0
- package/dist/providers/data/qwen-token-plan.json +1 -1
- package/dist/providers/data/radius.json +1 -0
- package/dist/providers/data/together.json +1 -1
- package/dist/providers/data/typesafe.json +1 -0
- package/dist/providers/data/vercel-ai-gateway.json +1 -1
- package/dist/providers/data/xai.json +1 -1
- package/dist/providers/data/xiaomi-token-plan-ams.json +1 -1
- package/dist/providers/data/xiaomi-token-plan-cn.json +1 -1
- package/dist/providers/data/xiaomi-token-plan-sgp.json +1 -1
- package/dist/providers/data/xiaomi.json +1 -1
- package/dist/providers/data/zai-coding-cn.json +1 -1
- package/dist/providers/data/zai.json +1 -1
- package/dist/providers/deepseek.d.ts.map +1 -1
- package/dist/providers/deepseek.js.map +1 -1
- package/dist/providers/deepseek.models.d.ts +4 -2
- package/dist/providers/deepseek.models.d.ts.map +1 -1
- package/dist/providers/deepseek.models.js +4 -2
- package/dist/providers/deepseek.models.js.map +1 -1
- package/dist/providers/faux.d.ts +19 -13
- package/dist/providers/faux.d.ts.map +1 -1
- package/dist/providers/faux.js +109 -18
- package/dist/providers/faux.js.map +1 -1
- package/dist/providers/fireworks.d.ts.map +1 -1
- package/dist/providers/fireworks.js.map +1 -1
- package/dist/providers/fireworks.models.d.ts +4 -2
- package/dist/providers/fireworks.models.d.ts.map +1 -1
- package/dist/providers/fireworks.models.js +4 -2
- package/dist/providers/fireworks.models.js.map +1 -1
- package/dist/providers/github-copilot.d.ts.map +1 -1
- package/dist/providers/github-copilot.js +1 -1
- package/dist/providers/github-copilot.js.map +1 -1
- package/dist/providers/github-copilot.models.d.ts +4 -2
- package/dist/providers/github-copilot.models.d.ts.map +1 -1
- package/dist/providers/github-copilot.models.js +4 -2
- package/dist/providers/github-copilot.models.js.map +1 -1
- package/dist/providers/google-vertex.d.ts.map +1 -1
- package/dist/providers/google-vertex.js +15 -7
- package/dist/providers/google-vertex.js.map +1 -1
- package/dist/providers/google-vertex.models.d.ts +4 -2
- package/dist/providers/google-vertex.models.d.ts.map +1 -1
- package/dist/providers/google-vertex.models.js +4 -2
- package/dist/providers/google-vertex.models.js.map +1 -1
- package/dist/providers/google.d.ts.map +1 -1
- package/dist/providers/google.js.map +1 -1
- package/dist/providers/google.models.d.ts +4 -2
- package/dist/providers/google.models.d.ts.map +1 -1
- package/dist/providers/google.models.js +4 -2
- package/dist/providers/google.models.js.map +1 -1
- package/dist/providers/groq.d.ts.map +1 -1
- package/dist/providers/groq.js.map +1 -1
- package/dist/providers/groq.models.d.ts +4 -2
- package/dist/providers/groq.models.d.ts.map +1 -1
- package/dist/providers/groq.models.js +4 -2
- package/dist/providers/groq.models.js.map +1 -1
- package/dist/providers/huggingface.d.ts.map +1 -1
- package/dist/providers/huggingface.js.map +1 -1
- package/dist/providers/huggingface.models.d.ts +4 -2
- package/dist/providers/huggingface.models.d.ts.map +1 -1
- package/dist/providers/huggingface.models.js +4 -2
- package/dist/providers/huggingface.models.js.map +1 -1
- package/dist/providers/images/register-builtins.d.ts +1 -1
- package/dist/providers/images/register-builtins.d.ts.map +1 -1
- package/dist/providers/images/register-builtins.js.map +1 -1
- package/dist/providers/kimi-coding.d.ts.map +1 -1
- package/dist/providers/kimi-coding.js +1 -0
- package/dist/providers/kimi-coding.js.map +1 -1
- package/dist/providers/kimi-coding.models.d.ts +4 -2
- package/dist/providers/kimi-coding.models.d.ts.map +1 -1
- package/dist/providers/kimi-coding.models.js +4 -2
- package/dist/providers/kimi-coding.models.js.map +1 -1
- package/dist/providers/meta.d.ts +3 -0
- package/dist/providers/meta.d.ts.map +1 -0
- package/dist/providers/meta.js +24 -0
- package/dist/providers/meta.js.map +1 -0
- package/dist/providers/meta.models.d.ts +6 -0
- package/dist/providers/meta.models.d.ts.map +1 -0
- package/dist/providers/meta.models.js +8 -0
- package/dist/providers/meta.models.js.map +1 -0
- package/dist/providers/minimax-cn.d.ts.map +1 -1
- package/dist/providers/minimax-cn.js.map +1 -1
- package/dist/providers/minimax-cn.models.d.ts +4 -2
- package/dist/providers/minimax-cn.models.d.ts.map +1 -1
- package/dist/providers/minimax-cn.models.js +4 -2
- package/dist/providers/minimax-cn.models.js.map +1 -1
- package/dist/providers/minimax.d.ts.map +1 -1
- package/dist/providers/minimax.js.map +1 -1
- package/dist/providers/minimax.models.d.ts +4 -2
- package/dist/providers/minimax.models.d.ts.map +1 -1
- package/dist/providers/minimax.models.js +4 -2
- package/dist/providers/minimax.models.js.map +1 -1
- package/dist/providers/mistral.d.ts.map +1 -1
- package/dist/providers/mistral.js.map +1 -1
- package/dist/providers/mistral.models.d.ts +4 -2
- package/dist/providers/mistral.models.d.ts.map +1 -1
- package/dist/providers/mistral.models.js +4 -2
- package/dist/providers/mistral.models.js.map +1 -1
- package/dist/providers/moonshotai-cn.d.ts.map +1 -1
- package/dist/providers/moonshotai-cn.js.map +1 -1
- package/dist/providers/moonshotai-cn.models.d.ts +4 -2
- package/dist/providers/moonshotai-cn.models.d.ts.map +1 -1
- package/dist/providers/moonshotai-cn.models.js +4 -2
- package/dist/providers/moonshotai-cn.models.js.map +1 -1
- package/dist/providers/moonshotai.d.ts.map +1 -1
- package/dist/providers/moonshotai.js.map +1 -1
- package/dist/providers/moonshotai.models.d.ts +4 -2
- package/dist/providers/moonshotai.models.d.ts.map +1 -1
- package/dist/providers/moonshotai.models.js +4 -2
- package/dist/providers/moonshotai.models.js.map +1 -1
- package/dist/providers/nvidia.d.ts.map +1 -1
- package/dist/providers/nvidia.js.map +1 -1
- package/dist/providers/nvidia.models.d.ts +4 -2
- package/dist/providers/nvidia.models.d.ts.map +1 -1
- package/dist/providers/nvidia.models.js +4 -2
- package/dist/providers/nvidia.models.js.map +1 -1
- package/dist/providers/openai-codex-catalog.d.ts +1 -0
- package/dist/providers/openai-codex-catalog.d.ts.map +1 -1
- package/dist/providers/openai-codex-catalog.js +19 -10
- package/dist/providers/openai-codex-catalog.js.map +1 -1
- package/dist/providers/openai-codex.d.ts.map +1 -1
- package/dist/providers/openai-codex.js +5 -1
- package/dist/providers/openai-codex.js.map +1 -1
- package/dist/providers/openai-codex.models.d.ts +4 -2
- package/dist/providers/openai-codex.models.d.ts.map +1 -1
- package/dist/providers/openai-codex.models.js +4 -2
- package/dist/providers/openai-codex.models.js.map +1 -1
- package/dist/providers/openai.d.ts.map +1 -1
- package/dist/providers/openai.js +11 -2
- package/dist/providers/openai.js.map +1 -1
- package/dist/providers/openai.models.d.ts +4 -2
- package/dist/providers/openai.models.d.ts.map +1 -1
- package/dist/providers/openai.models.js +4 -2
- package/dist/providers/openai.models.js.map +1 -1
- package/dist/providers/opencode-go.d.ts.map +1 -1
- package/dist/providers/opencode-go.js +5 -4
- package/dist/providers/opencode-go.js.map +1 -1
- package/dist/providers/opencode-go.models.d.ts +4 -2
- package/dist/providers/opencode-go.models.d.ts.map +1 -1
- package/dist/providers/opencode-go.models.js +4 -2
- package/dist/providers/opencode-go.models.js.map +1 -1
- package/dist/providers/opencode-headers.d.ts +4 -0
- package/dist/providers/opencode-headers.d.ts.map +1 -0
- package/dist/providers/opencode-headers.js +22 -0
- package/dist/providers/opencode-headers.js.map +1 -0
- package/dist/providers/opencode.d.ts +3 -1
- package/dist/providers/opencode.d.ts.map +1 -1
- package/dist/providers/opencode.js +10 -6
- package/dist/providers/opencode.js.map +1 -1
- package/dist/providers/opencode.models.d.ts +4 -2
- package/dist/providers/opencode.models.d.ts.map +1 -1
- package/dist/providers/opencode.models.js +4 -2
- package/dist/providers/opencode.models.js.map +1 -1
- package/dist/providers/openrouter.d.ts +1 -1
- package/dist/providers/openrouter.d.ts.map +1 -1
- package/dist/providers/openrouter.js +16 -3
- package/dist/providers/openrouter.js.map +1 -1
- package/dist/providers/openrouter.models.d.ts +4 -2
- package/dist/providers/openrouter.models.d.ts.map +1 -1
- package/dist/providers/openrouter.models.js +4 -2
- package/dist/providers/openrouter.models.js.map +1 -1
- package/dist/providers/qwen-token-plan-cn.d.ts.map +1 -1
- package/dist/providers/qwen-token-plan-cn.js.map +1 -1
- package/dist/providers/qwen-token-plan-cn.models.d.ts +4 -2
- package/dist/providers/qwen-token-plan-cn.models.d.ts.map +1 -1
- package/dist/providers/qwen-token-plan-cn.models.js +4 -2
- package/dist/providers/qwen-token-plan-cn.models.js.map +1 -1
- package/dist/providers/qwen-token-plan-individual.d.ts +3 -0
- package/dist/providers/qwen-token-plan-individual.d.ts.map +1 -0
- package/dist/providers/qwen-token-plan-individual.js +15 -0
- package/dist/providers/qwen-token-plan-individual.js.map +1 -0
- package/dist/providers/qwen-token-plan-individual.models.d.ts +6 -0
- package/dist/providers/qwen-token-plan-individual.models.d.ts.map +1 -0
- package/dist/providers/qwen-token-plan-individual.models.js +8 -0
- package/dist/providers/qwen-token-plan-individual.models.js.map +1 -0
- package/dist/providers/qwen-token-plan.d.ts.map +1 -1
- package/dist/providers/qwen-token-plan.js.map +1 -1
- package/dist/providers/qwen-token-plan.models.d.ts +4 -2
- package/dist/providers/qwen-token-plan.models.d.ts.map +1 -1
- package/dist/providers/qwen-token-plan.models.js +4 -2
- package/dist/providers/qwen-token-plan.models.js.map +1 -1
- package/dist/providers/radius-config.d.ts.map +1 -1
- package/dist/providers/radius-config.js.map +1 -1
- package/dist/providers/radius.d.ts.map +1 -1
- package/dist/providers/radius.js +53 -29
- package/dist/providers/radius.js.map +1 -1
- package/dist/providers/radius.models.d.ts +6 -0
- package/dist/providers/radius.models.d.ts.map +1 -0
- package/dist/providers/radius.models.js +8 -0
- package/dist/providers/radius.models.js.map +1 -0
- package/dist/providers/together.d.ts.map +1 -1
- package/dist/providers/together.js.map +1 -1
- package/dist/providers/together.models.d.ts +4 -2
- package/dist/providers/together.models.d.ts.map +1 -1
- package/dist/providers/together.models.js +4 -2
- package/dist/providers/together.models.js.map +1 -1
- package/dist/providers/typesafe.d.ts +3 -0
- package/dist/providers/typesafe.d.ts.map +1 -0
- package/dist/providers/typesafe.js +18 -0
- package/dist/providers/typesafe.js.map +1 -0
- package/dist/providers/typesafe.models.d.ts +6 -0
- package/dist/providers/typesafe.models.d.ts.map +1 -0
- package/dist/providers/typesafe.models.js +8 -0
- package/dist/providers/typesafe.models.js.map +1 -0
- package/dist/providers/vercel-ai-gateway.d.ts.map +1 -1
- package/dist/providers/vercel-ai-gateway.js +5 -2
- package/dist/providers/vercel-ai-gateway.js.map +1 -1
- package/dist/providers/vercel-ai-gateway.models.d.ts +4 -2
- package/dist/providers/vercel-ai-gateway.models.d.ts.map +1 -1
- package/dist/providers/vercel-ai-gateway.models.js +4 -2
- package/dist/providers/vercel-ai-gateway.models.js.map +1 -1
- package/dist/providers/xai.d.ts +1 -1
- package/dist/providers/xai.d.ts.map +1 -1
- package/dist/providers/xai.js +2 -5
- package/dist/providers/xai.js.map +1 -1
- package/dist/providers/xai.models.d.ts +4 -2
- package/dist/providers/xai.models.d.ts.map +1 -1
- package/dist/providers/xai.models.js +4 -2
- package/dist/providers/xai.models.js.map +1 -1
- package/dist/providers/xiaomi-token-plan-ams.d.ts.map +1 -1
- package/dist/providers/xiaomi-token-plan-ams.js.map +1 -1
- package/dist/providers/xiaomi-token-plan-ams.models.d.ts +4 -2
- package/dist/providers/xiaomi-token-plan-ams.models.d.ts.map +1 -1
- package/dist/providers/xiaomi-token-plan-ams.models.js +4 -2
- package/dist/providers/xiaomi-token-plan-ams.models.js.map +1 -1
- package/dist/providers/xiaomi-token-plan-cn.d.ts.map +1 -1
- package/dist/providers/xiaomi-token-plan-cn.js.map +1 -1
- package/dist/providers/xiaomi-token-plan-cn.models.d.ts +4 -2
- package/dist/providers/xiaomi-token-plan-cn.models.d.ts.map +1 -1
- package/dist/providers/xiaomi-token-plan-cn.models.js +4 -2
- package/dist/providers/xiaomi-token-plan-cn.models.js.map +1 -1
- package/dist/providers/xiaomi-token-plan-sgp.d.ts.map +1 -1
- package/dist/providers/xiaomi-token-plan-sgp.js.map +1 -1
- package/dist/providers/xiaomi-token-plan-sgp.models.d.ts +4 -2
- package/dist/providers/xiaomi-token-plan-sgp.models.d.ts.map +1 -1
- package/dist/providers/xiaomi-token-plan-sgp.models.js +4 -2
- package/dist/providers/xiaomi-token-plan-sgp.models.js.map +1 -1
- package/dist/providers/xiaomi.d.ts.map +1 -1
- package/dist/providers/xiaomi.js.map +1 -1
- package/dist/providers/xiaomi.models.d.ts +4 -2
- package/dist/providers/xiaomi.models.d.ts.map +1 -1
- package/dist/providers/xiaomi.models.js +4 -2
- package/dist/providers/xiaomi.models.js.map +1 -1
- package/dist/providers/zai-coding-cn.d.ts.map +1 -1
- package/dist/providers/zai-coding-cn.js.map +1 -1
- package/dist/providers/zai-coding-cn.models.d.ts +4 -2
- package/dist/providers/zai-coding-cn.models.d.ts.map +1 -1
- package/dist/providers/zai-coding-cn.models.js +4 -2
- package/dist/providers/zai-coding-cn.models.js.map +1 -1
- package/dist/providers/zai.d.ts.map +1 -1
- package/dist/providers/zai.js.map +1 -1
- package/dist/providers/zai.models.d.ts +4 -2
- package/dist/providers/zai.models.d.ts.map +1 -1
- package/dist/providers/zai.models.js +4 -2
- package/dist/providers/zai.models.js.map +1 -1
- package/dist/session-resources.d.ts.map +1 -1
- package/dist/session-resources.js.map +1 -1
- package/dist/types.d.ts +414 -126
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utils/abort-signals.d.ts.map +1 -1
- package/dist/utils/abort-signals.js.map +1 -1
- package/dist/utils/abort.d.ts +8 -0
- package/dist/utils/abort.d.ts.map +1 -0
- package/dist/utils/abort.js +49 -0
- package/dist/utils/abort.js.map +1 -0
- package/dist/utils/assistant-message-frame.d.ts +77 -0
- package/dist/utils/assistant-message-frame.d.ts.map +1 -0
- package/dist/utils/assistant-message-frame.js +425 -0
- package/dist/utils/assistant-message-frame.js.map +1 -0
- package/dist/utils/diagnostics.d.ts +3 -2
- package/dist/utils/diagnostics.d.ts.map +1 -1
- package/dist/utils/diagnostics.js.map +1 -1
- package/dist/utils/error-body.d.ts.map +1 -1
- package/dist/utils/error-body.js +23 -4
- package/dist/utils/error-body.js.map +1 -1
- package/dist/utils/estimate.d.ts +2 -2
- package/dist/utils/estimate.d.ts.map +1 -1
- package/dist/utils/estimate.js +8 -29
- package/dist/utils/estimate.js.map +1 -1
- package/dist/utils/event-stream.d.ts.map +1 -1
- package/dist/utils/event-stream.js +25 -7
- package/dist/utils/event-stream.js.map +1 -1
- package/dist/utils/hash.d.ts.map +1 -1
- package/dist/utils/hash.js.map +1 -1
- package/dist/utils/headers.d.ts +1 -1
- package/dist/utils/headers.d.ts.map +1 -1
- package/dist/utils/headers.js +10 -8
- package/dist/utils/headers.js.map +1 -1
- package/dist/utils/json-parse.d.ts.map +1 -1
- package/dist/utils/json-parse.js.map +1 -1
- package/dist/utils/model-operations.d.ts +11 -0
- package/dist/utils/model-operations.d.ts.map +1 -0
- package/dist/utils/model-operations.js +47 -0
- package/dist/utils/model-operations.js.map +1 -0
- package/dist/utils/models-error.d.ts +8 -0
- package/dist/utils/models-error.d.ts.map +1 -0
- package/dist/utils/models-error.js +19 -0
- package/dist/utils/models-error.js.map +1 -0
- package/dist/utils/node-http-proxy.d.ts.map +1 -1
- package/dist/utils/node-http-proxy.js +53 -12
- package/dist/utils/node-http-proxy.js.map +1 -1
- package/dist/utils/oauth-page.d.ts.map +1 -0
- package/dist/{auth/oauth → utils}/oauth-page.js +1 -1
- package/dist/utils/oauth-page.js.map +1 -0
- package/dist/utils/overflow.d.ts +11 -1
- package/dist/utils/overflow.d.ts.map +1 -1
- package/dist/utils/overflow.js +24 -6
- package/dist/utils/overflow.js.map +1 -1
- package/dist/utils/pi-user-agent.d.ts +2 -0
- package/dist/utils/pi-user-agent.d.ts.map +1 -0
- package/dist/utils/pi-user-agent.js +12 -0
- package/dist/utils/pi-user-agent.js.map +1 -0
- package/dist/utils/provider-env.d.ts.map +1 -1
- package/dist/utils/provider-env.js.map +1 -1
- package/dist/utils/provider-retry.d.ts.map +1 -1
- package/dist/utils/provider-retry.js +3 -2
- package/dist/utils/provider-retry.js.map +1 -1
- package/dist/utils/retry.d.ts +6 -1
- package/dist/utils/retry.d.ts.map +1 -1
- package/dist/utils/retry.js +23 -2
- package/dist/utils/retry.js.map +1 -1
- package/dist/utils/sanitize-unicode.d.ts.map +1 -1
- package/dist/utils/sanitize-unicode.js.map +1 -1
- package/dist/utils/sleep.d.ts +2 -0
- package/dist/utils/sleep.d.ts.map +1 -0
- package/dist/utils/sleep.js +15 -0
- package/dist/utils/sleep.js.map +1 -0
- package/dist/utils/text.d.ts +9 -1
- package/dist/utils/text.d.ts.map +1 -1
- package/dist/utils/text.js +26 -0
- package/dist/utils/text.js.map +1 -1
- package/dist/utils/transcript.d.ts +87 -0
- package/dist/utils/transcript.d.ts.map +1 -0
- package/dist/utils/transcript.js +207 -0
- package/dist/utils/transcript.js.map +1 -0
- package/dist/utils/typebox-helpers.d.ts.map +1 -1
- package/dist/utils/typebox-helpers.js.map +1 -1
- package/dist/utils/uuid.d.ts +2 -2
- package/dist/utils/uuid.d.ts.map +1 -1
- package/dist/utils/uuid.js +35 -39
- package/dist/utils/uuid.js.map +1 -1
- package/dist/utils/validation.d.ts.map +1 -1
- package/dist/utils/validation.js +40 -0
- package/dist/utils/validation.js.map +1 -1
- package/package.json +21 -15
- package/dist/auth/oauth/oauth-page.d.ts.map +0 -1
- package/dist/auth/oauth/oauth-page.js.map +0 -1
- package/dist/image-models.generated.d.ts +0 -605
- package/dist/image-models.generated.d.ts.map +0 -1
- package/dist/image-models.generated.js +0 -607
- package/dist/image-models.generated.js.map +0 -1
- package/dist/images-models.d.ts +0 -95
- package/dist/images-models.d.ts.map +0 -1
- package/dist/images-models.js +0 -142
- package/dist/images-models.js.map +0 -1
- package/dist/providers/azure-openai-responses.d.ts +0 -3
- package/dist/providers/azure-openai-responses.d.ts.map +0 -1
- package/dist/providers/azure-openai-responses.js +0 -14
- package/dist/providers/azure-openai-responses.js.map +0 -1
- package/dist/providers/azure-openai-responses.models.d.ts +0 -4
- package/dist/providers/azure-openai-responses.models.d.ts.map +0 -1
- package/dist/providers/azure-openai-responses.models.js +0 -6
- package/dist/providers/azure-openai-responses.models.js.map +0 -1
- package/dist/providers/data/azure-openai-responses.json +0 -1
- package/dist/providers/openrouter-images.d.ts +0 -3
- package/dist/providers/openrouter-images.d.ts.map +0 -1
- package/dist/providers/openrouter-images.js +0 -22
- package/dist/providers/openrouter-images.js.map +0 -1
- package/dist/utils/deferred-tools.d.ts +0 -9
- package/dist/utils/deferred-tools.d.ts.map +0 -1
- package/dist/utils/deferred-tools.js +0 -36
- package/dist/utils/deferred-tools.js.map +0 -1
- /package/dist/{auth/oauth → utils}/oauth-page.d.ts +0 -0
|
@@ -5,13 +5,16 @@ import { AssistantMessageEventStream } from "../utils/event-stream.js";
|
|
|
5
5
|
import { shortHash } from "../utils/hash.js";
|
|
6
6
|
import { headersToRecord } from "../utils/headers.js";
|
|
7
7
|
import { parseStreamingJson } from "../utils/json-parse.js";
|
|
8
|
+
import { getPiUserAgent } from "../utils/pi-user-agent.js";
|
|
8
9
|
import { getProviderEnvValue } from "../utils/provider-env.js";
|
|
9
10
|
import { retryProviderRequest } from "../utils/provider-retry.js";
|
|
10
11
|
import { sanitizeSurrogates } from "../utils/sanitize-unicode.js";
|
|
11
|
-
import {
|
|
12
|
+
import { getSystemMessageText, renderSystemMessageUpdate } from "../utils/text.js";
|
|
13
|
+
import { getDeclaredTools, resolveTranscript, resolveTranscriptTools, } from "../utils/transcript.js";
|
|
14
|
+
import { appendGrammarToolInputJsonDelta, createGrammarToolInputProperties, getGrammarToolInput, getJsonSchemaToolParameters, resolveGrammarConstrainedSampling, resolveJsonSchemaStrictSampling, } from "./constrained-sampling.js";
|
|
12
15
|
import { buildCopilotDynamicHeaders, hasCopilotVisionInput } from "./github-copilot-headers.js";
|
|
13
16
|
import { clampOpenAIPromptCacheKey } from "./openai-prompt-cache.js";
|
|
14
|
-
import { buildBaseOptions } from "./simple-options.js";
|
|
17
|
+
import { buildBaseOptions, clampThinkingBudgetToAnswerRoom, resolveSamplingParams, thinkingBudgetForLevel, } from "./simple-options.js";
|
|
15
18
|
import { transformMessages } from "./transform-messages.js";
|
|
16
19
|
/**
|
|
17
20
|
* Check if conversation messages contain tool calls or tool results.
|
|
@@ -48,25 +51,6 @@ function hasToolHistory(messages) {
|
|
|
48
51
|
}
|
|
49
52
|
return false;
|
|
50
53
|
}
|
|
51
|
-
function getDeferredToolNames(messages) {
|
|
52
|
-
const names = new Set();
|
|
53
|
-
for (const message of messages) {
|
|
54
|
-
if (message.role === "toolResult") {
|
|
55
|
-
for (const name of message.addedToolNames ?? []) {
|
|
56
|
-
names.add(name);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
return names;
|
|
61
|
-
}
|
|
62
|
-
function getToolsByName(tools, names) {
|
|
63
|
-
if (!tools)
|
|
64
|
-
return [];
|
|
65
|
-
const toolsByName = new Map(tools.map((tool) => [tool.name, tool]));
|
|
66
|
-
return Array.from(names)
|
|
67
|
-
.map((name) => toolsByName.get(name))
|
|
68
|
-
.filter((tool) => tool !== undefined);
|
|
69
|
-
}
|
|
70
54
|
function isTextContentBlock(block) {
|
|
71
55
|
return block.type === "text";
|
|
72
56
|
}
|
|
@@ -79,16 +63,81 @@ function isToolCallBlock(block) {
|
|
|
79
63
|
function isImageContentBlock(block) {
|
|
80
64
|
return block.type === "image";
|
|
81
65
|
}
|
|
82
|
-
function
|
|
83
|
-
|
|
66
|
+
function isReasoningDetailObject(detail) {
|
|
67
|
+
return typeof detail === "object" && detail !== null && !Array.isArray(detail);
|
|
68
|
+
}
|
|
69
|
+
function hasValidCommonReasoningDetailFields(candidate) {
|
|
70
|
+
return ((candidate.id === undefined || candidate.id === null || typeof candidate.id === "string") &&
|
|
71
|
+
(candidate.format === undefined || typeof candidate.format === "string") &&
|
|
72
|
+
(candidate.index === undefined || typeof candidate.index === "number"));
|
|
73
|
+
}
|
|
74
|
+
function isOpenAIReasoningDetail(detail) {
|
|
75
|
+
if (!isReasoningDetailObject(detail) || !hasValidCommonReasoningDetailFields(detail)) {
|
|
84
76
|
return false;
|
|
85
77
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
78
|
+
switch (detail.type) {
|
|
79
|
+
case "reasoning.summary":
|
|
80
|
+
return typeof detail.summary === "string";
|
|
81
|
+
case "reasoning.encrypted":
|
|
82
|
+
return typeof detail.data === "string";
|
|
83
|
+
case "reasoning.text":
|
|
84
|
+
return (typeof detail.text === "string" &&
|
|
85
|
+
(detail.signature === undefined || detail.signature === null || typeof detail.signature === "string"));
|
|
86
|
+
default:
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
function parseOpenAIReasoningDetails(signature) {
|
|
91
|
+
if (!signature)
|
|
92
|
+
return undefined;
|
|
93
|
+
try {
|
|
94
|
+
const parsed = JSON.parse(signature);
|
|
95
|
+
return Array.isArray(parsed) && parsed.length > 0 && parsed.every(isOpenAIReasoningDetail) ? parsed : undefined;
|
|
96
|
+
}
|
|
97
|
+
catch {
|
|
98
|
+
return undefined;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
function parseLegacyEncryptedReasoningDetail(signature) {
|
|
102
|
+
if (!signature)
|
|
103
|
+
return undefined;
|
|
104
|
+
try {
|
|
105
|
+
const parsed = JSON.parse(signature);
|
|
106
|
+
return isOpenAIReasoningDetail(parsed) &&
|
|
107
|
+
parsed.type === "reasoning.encrypted" &&
|
|
108
|
+
typeof parsed.id === "string" &&
|
|
109
|
+
parsed.id.length > 0 &&
|
|
110
|
+
parsed.data.length > 0
|
|
111
|
+
? parsed
|
|
112
|
+
: undefined;
|
|
113
|
+
}
|
|
114
|
+
catch {
|
|
115
|
+
return undefined;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
function fillMissingCommonReasoningDetailFields(target, source) {
|
|
119
|
+
target.id ??= source.id;
|
|
120
|
+
target.format ||= source.format;
|
|
121
|
+
target.index ??= source.index;
|
|
122
|
+
}
|
|
123
|
+
function appendOpenAIReasoningDetail(details, detail) {
|
|
124
|
+
const lastDetail = details[details.length - 1];
|
|
125
|
+
if (detail.type === "reasoning.text" && lastDetail?.type === "reasoning.text") {
|
|
126
|
+
lastDetail.text += detail.text;
|
|
127
|
+
lastDetail.signature ||= detail.signature;
|
|
128
|
+
fillMissingCommonReasoningDetailFields(lastDetail, detail);
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
if (detail.type === "reasoning.summary" && lastDetail?.type === "reasoning.summary") {
|
|
132
|
+
lastDetail.summary += detail.summary;
|
|
133
|
+
fillMissingCommonReasoningDetailFields(lastDetail, detail);
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
details.push({ ...detail });
|
|
137
|
+
}
|
|
138
|
+
const OPENAI_COMPLETIONS_REASONING_FIELDS = ["reasoning", "reasoning_content", "reasoning_text"];
|
|
139
|
+
function isOpenAICompletionsReasoningField(field) {
|
|
140
|
+
return OPENAI_COMPLETIONS_REASONING_FIELDS.includes(field);
|
|
92
141
|
}
|
|
93
142
|
function resolveCacheRetention(cacheRetention, env) {
|
|
94
143
|
if (cacheRetention) {
|
|
@@ -101,6 +150,7 @@ function resolveCacheRetention(cacheRetention, env) {
|
|
|
101
150
|
}
|
|
102
151
|
export const stream = (model, context, options) => {
|
|
103
152
|
const stream = new AssistantMessageEventStream();
|
|
153
|
+
const normalizedContext = resolveTranscript(context, getCompat(model).supportsMidConvoSystemMessages);
|
|
104
154
|
(async () => {
|
|
105
155
|
const output = {
|
|
106
156
|
role: "assistant",
|
|
@@ -119,14 +169,22 @@ export const stream = (model, context, options) => {
|
|
|
119
169
|
stopReason: "pending",
|
|
120
170
|
timestamp: Date.now(),
|
|
121
171
|
};
|
|
172
|
+
// `reasoning_details` are replay metadata, not user-visible stream deltas.
|
|
173
|
+
// Keep them in memory during streaming and serialize once when the block is finalized.
|
|
174
|
+
let streamedReasoningDetails;
|
|
175
|
+
const applyStreamedReasoningDetails = (block) => {
|
|
176
|
+
if (streamedReasoningDetails !== undefined) {
|
|
177
|
+
block.thinkingSignature = JSON.stringify(streamedReasoningDetails);
|
|
178
|
+
}
|
|
179
|
+
};
|
|
122
180
|
try {
|
|
123
181
|
const apiKey = getClientApiKey(model.provider, options?.apiKey, options?.headers);
|
|
124
182
|
const compat = getCompat(model);
|
|
125
|
-
const grammarToolInputProperties = createGrammarToolInputProperties(
|
|
183
|
+
const grammarToolInputProperties = createGrammarToolInputProperties(getDeclaredTools(normalizedContext.messages), compat.supportsOpenAIGrammarTools);
|
|
126
184
|
const cacheRetention = resolveCacheRetention(options?.cacheRetention, options?.env);
|
|
127
185
|
const cacheSessionId = cacheRetention === "none" ? undefined : options?.sessionId;
|
|
128
|
-
const client = createClient(model,
|
|
129
|
-
let params = buildParams(model,
|
|
186
|
+
const client = createClient(model, normalizedContext, apiKey, options?.headers, options?.fetch, cacheSessionId, compat);
|
|
187
|
+
let params = buildParams(model, normalizedContext, options, compat, cacheRetention, grammarToolInputProperties);
|
|
130
188
|
const nextParams = await options?.onPayload?.(params, model);
|
|
131
189
|
if (nextParams !== undefined) {
|
|
132
190
|
params = nextParams;
|
|
@@ -148,7 +206,6 @@ export const stream = (model, context, options) => {
|
|
|
148
206
|
let hasFinishReason = false;
|
|
149
207
|
const toolCallBlocksByIndex = new Map();
|
|
150
208
|
const toolCallBlocksById = new Map();
|
|
151
|
-
const pendingReasoningDetailsByToolCallId = new Map();
|
|
152
209
|
const blocks = output.content;
|
|
153
210
|
const getContentIndex = (block) => blocks.indexOf(block);
|
|
154
211
|
const getCustomToolCallInput = (block) => {
|
|
@@ -180,6 +237,7 @@ export const stream = (model, context, options) => {
|
|
|
180
237
|
});
|
|
181
238
|
}
|
|
182
239
|
else if (block.type === "thinking") {
|
|
240
|
+
applyStreamedReasoningDetails(block);
|
|
183
241
|
stream.push({
|
|
184
242
|
type: "thinking_end",
|
|
185
243
|
contentIndex,
|
|
@@ -235,16 +293,6 @@ export const stream = (model, context, options) => {
|
|
|
235
293
|
}
|
|
236
294
|
return thinkingBlock;
|
|
237
295
|
};
|
|
238
|
-
const applyPendingReasoningDetail = (block) => {
|
|
239
|
-
if (!block.id) {
|
|
240
|
-
return;
|
|
241
|
-
}
|
|
242
|
-
const pendingReasoningDetail = pendingReasoningDetailsByToolCallId.get(block.id);
|
|
243
|
-
if (pendingReasoningDetail) {
|
|
244
|
-
block.thoughtSignature = pendingReasoningDetail;
|
|
245
|
-
pendingReasoningDetailsByToolCallId.delete(block.id);
|
|
246
|
-
}
|
|
247
|
-
};
|
|
248
296
|
const ensureToolCallBlock = (toolCall) => {
|
|
249
297
|
const streamIndex = typeof toolCall.index === "number" ? toolCall.index : undefined;
|
|
250
298
|
const name = toolCall.function?.name ?? toolCall.custom?.name ?? "";
|
|
@@ -300,10 +348,10 @@ export const stream = (model, context, options) => {
|
|
|
300
348
|
};
|
|
301
349
|
delete block.partialArgs;
|
|
302
350
|
}
|
|
303
|
-
applyPendingReasoningDetail(block);
|
|
304
351
|
return block;
|
|
305
352
|
};
|
|
306
353
|
for await (const chunk of openaiStream) {
|
|
354
|
+
await options?.onProviderStreamEvent?.(chunk, model);
|
|
307
355
|
if (!chunk || typeof chunk !== "object")
|
|
308
356
|
continue;
|
|
309
357
|
// OpenAI documents ChatCompletionChunk.id as the unique chat completion identifier,
|
|
@@ -407,16 +455,14 @@ export const stream = (model, context, options) => {
|
|
|
407
455
|
const reasoningDetails = choice.delta.reasoning_details;
|
|
408
456
|
if (Array.isArray(reasoningDetails)) {
|
|
409
457
|
for (const detail of reasoningDetails) {
|
|
410
|
-
if (
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
}
|
|
419
|
-
}
|
|
458
|
+
if (!isOpenAIReasoningDetail(detail))
|
|
459
|
+
continue;
|
|
460
|
+
ensureThinkingBlock("");
|
|
461
|
+
streamedReasoningDetails ??= [];
|
|
462
|
+
// Keep provider replay data in the existing signature slot. OpenRouter streams
|
|
463
|
+
// reasoning_details as deltas: consecutive text/summary deltas are merged into
|
|
464
|
+
// logical entries, while encrypted entries remain opaque and discrete.
|
|
465
|
+
appendOpenAIReasoningDetail(streamedReasoningDetails, detail);
|
|
420
466
|
}
|
|
421
467
|
}
|
|
422
468
|
}
|
|
@@ -430,10 +476,13 @@ export const stream = (model, context, options) => {
|
|
|
430
476
|
if (output.stopReason === "aborted") {
|
|
431
477
|
throw new Error("Request was aborted");
|
|
432
478
|
}
|
|
479
|
+
if (!hasFinishReason && !compat.supportsFinishReason) {
|
|
480
|
+
output.stopReason = output.content.some((block) => block.type === "toolCall") ? "toolUse" : "stop";
|
|
481
|
+
}
|
|
433
482
|
if (output.stopReason === "error") {
|
|
434
483
|
throw new Error(output.errorMessage || "Provider returned an error stop reason");
|
|
435
484
|
}
|
|
436
|
-
if (!hasFinishReason || output.stopReason === "pending") {
|
|
485
|
+
if ((compat.supportsFinishReason && !hasFinishReason) || output.stopReason === "pending") {
|
|
437
486
|
throw new Error("Stream ended without finish_reason");
|
|
438
487
|
}
|
|
439
488
|
stream.push({ type: "done", reason: output.stopReason, message: output });
|
|
@@ -441,6 +490,9 @@ export const stream = (model, context, options) => {
|
|
|
441
490
|
}
|
|
442
491
|
catch (error) {
|
|
443
492
|
for (const block of output.content) {
|
|
493
|
+
if (block.type === "thinking") {
|
|
494
|
+
applyStreamedReasoningDetails(block);
|
|
495
|
+
}
|
|
444
496
|
delete block.index;
|
|
445
497
|
// Streaming scratch buffers are only used during parsing; never persist them.
|
|
446
498
|
delete block.partialArgs;
|
|
@@ -465,18 +517,20 @@ export const stream = (model, context, options) => {
|
|
|
465
517
|
};
|
|
466
518
|
export const streamSimple = (model, context, options) => {
|
|
467
519
|
getClientApiKey(model.provider, options?.apiKey, options?.headers);
|
|
468
|
-
const base =
|
|
520
|
+
const base = {
|
|
521
|
+
...buildBaseOptions(model, context, options, options?.apiKey),
|
|
522
|
+
toolChoice: options?.toolChoice,
|
|
523
|
+
};
|
|
469
524
|
const clampedReasoning = options?.reasoning ? clampThinkingLevel(model, options.reasoning) : undefined;
|
|
470
525
|
const reasoningEffort = clampedReasoning === "off" ? undefined : clampedReasoning;
|
|
471
|
-
const toolChoice = options?.toolChoice;
|
|
472
526
|
return stream(model, context, {
|
|
473
527
|
...base,
|
|
474
528
|
reasoningEffort,
|
|
475
|
-
|
|
529
|
+
thinkingBudgets: options?.thinkingBudgets,
|
|
476
530
|
});
|
|
477
531
|
};
|
|
478
532
|
function createClient(model, context, apiKey, optionsHeaders, fetch, sessionId, compat = getCompat(model)) {
|
|
479
|
-
const headers = { ...model.headers };
|
|
533
|
+
const headers = { "User-Agent": getPiUserAgent(), ...model.headers };
|
|
480
534
|
if (model.provider === "github-copilot") {
|
|
481
535
|
const hasImages = hasCopilotVisionInput(context.messages);
|
|
482
536
|
const copilotHeaders = buildCopilotDynamicHeaders({
|
|
@@ -509,8 +563,11 @@ function createClient(model, context, apiKey, optionsHeaders, fetch, sessionId,
|
|
|
509
563
|
defaultHeaders: headers,
|
|
510
564
|
});
|
|
511
565
|
}
|
|
512
|
-
function buildParams(model, context, options, compat = getCompat(model), cacheRetention = resolveCacheRetention(options?.cacheRetention, options?.env), grammarToolInputProperties = createGrammarToolInputProperties(context.
|
|
513
|
-
const
|
|
566
|
+
function buildParams(model, context, options, compat = getCompat(model), cacheRetention = resolveCacheRetention(options?.cacheRetention, options?.env), grammarToolInputProperties = createGrammarToolInputProperties(getDeclaredTools(context.messages), compat.supportsOpenAIGrammarTools)) {
|
|
567
|
+
const transcriptTools = resolveTranscriptTools(context.messages, compat.supportsMidConvoSystemMessages === true && compat.supportsMidConvoToolAdditions === true);
|
|
568
|
+
const messages = convertMessages(model, context, compat, {
|
|
569
|
+
grammarToolInputProperties,
|
|
570
|
+
});
|
|
514
571
|
const cacheControl = getCompatCacheControl(compat, cacheRetention);
|
|
515
572
|
const params = {
|
|
516
573
|
model: model.id,
|
|
@@ -530,6 +587,7 @@ function buildParams(model, context, options, compat = getCompat(model), cacheRe
|
|
|
530
587
|
}
|
|
531
588
|
if (options?.maxTokens) {
|
|
532
589
|
if (compat.maxTokensField === "max_tokens") {
|
|
590
|
+
// Deprecated by OpenAI, but some OpenAI-compatible providers only accept max_tokens.
|
|
533
591
|
params.max_tokens = options.maxTokens;
|
|
534
592
|
}
|
|
535
593
|
else {
|
|
@@ -539,10 +597,8 @@ function buildParams(model, context, options, compat = getCompat(model), cacheRe
|
|
|
539
597
|
if (options?.temperature !== undefined) {
|
|
540
598
|
params.temperature = options.temperature;
|
|
541
599
|
}
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
if (activeTools && activeTools.length > 0) {
|
|
545
|
-
params.tools = convertTools(activeTools, compat);
|
|
600
|
+
if (transcriptTools.requestTools.length > 0) {
|
|
601
|
+
params.tools = convertTools(transcriptTools.requestTools, compat);
|
|
546
602
|
if (compat.zaiToolStream) {
|
|
547
603
|
params.tool_stream = true;
|
|
548
604
|
}
|
|
@@ -557,6 +613,11 @@ function buildParams(model, context, options, compat = getCompat(model), cacheRe
|
|
|
557
613
|
if (options?.toolChoice) {
|
|
558
614
|
params.tool_choice = options.toolChoice;
|
|
559
615
|
}
|
|
616
|
+
if (compat.vllmPriority !== undefined) {
|
|
617
|
+
params.priority = compat.vllmPriority;
|
|
618
|
+
}
|
|
619
|
+
const thinkingTokenBudgetField = resolveThinkingTokenBudgetField(compat);
|
|
620
|
+
const thinkingBudget = resolveClampedThinkingBudget(model, options, params);
|
|
560
621
|
if (compat.thinkingFormat === "zai" && model.reasoning) {
|
|
561
622
|
const zaiParams = params;
|
|
562
623
|
zaiParams.thinking = options?.reasoningEffort ? { type: "enabled", clear_thinking: false } : { type: "disabled" };
|
|
@@ -584,11 +645,26 @@ function buildParams(model, context, options, compat = getCompat(model), cacheRe
|
|
|
584
645
|
};
|
|
585
646
|
}
|
|
586
647
|
else if (compat.thinkingFormat === "chat-template" && model.reasoning) {
|
|
587
|
-
const chatTemplateKwargs =
|
|
648
|
+
const chatTemplateKwargs = buildChatTemplateValues(model, options, compat.chatTemplateKwargs, thinkingBudget);
|
|
588
649
|
if (chatTemplateKwargs) {
|
|
589
650
|
params.chat_template_kwargs = chatTemplateKwargs;
|
|
590
651
|
}
|
|
591
652
|
}
|
|
653
|
+
else if (compat.thinkingFormat === "baseten" && model.reasoning) {
|
|
654
|
+
const basetenParams = params;
|
|
655
|
+
const chatTemplateArgs = buildChatTemplateValues(model, options, compat.chatTemplateArgs, thinkingBudget);
|
|
656
|
+
if (chatTemplateArgs) {
|
|
657
|
+
basetenParams.chat_template_args = chatTemplateArgs;
|
|
658
|
+
}
|
|
659
|
+
if (compat.supportsReasoningEffort) {
|
|
660
|
+
const requestedEffort = options?.reasoningEffort;
|
|
661
|
+
const mappedEffort = requestedEffort ? model.thinkingLevelMap?.[requestedEffort] : model.thinkingLevelMap?.off;
|
|
662
|
+
const effort = mappedEffort === undefined ? requestedEffort : mappedEffort;
|
|
663
|
+
if (typeof effort === "string") {
|
|
664
|
+
basetenParams.reasoning_effort = effort;
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
}
|
|
592
668
|
else if (compat.thinkingFormat === "deepseek" && model.reasoning) {
|
|
593
669
|
if (options?.reasoningEffort) {
|
|
594
670
|
params.thinking = { type: "enabled" };
|
|
@@ -645,6 +721,13 @@ function buildParams(model, context, options, compat = getCompat(model), cacheRe
|
|
|
645
721
|
params.reasoning_effort = offValue;
|
|
646
722
|
}
|
|
647
723
|
}
|
|
724
|
+
// Cap reasoning with a top-level budget field. Independent of thinkingFormat: the
|
|
725
|
+
// same server can serve zai, qwen or chat-template models. Reasoning and the answer
|
|
726
|
+
// share max_tokens here, so an uncapped reasoning phase can consume the whole
|
|
727
|
+
// response and leave no answer and no tool call.
|
|
728
|
+
if (thinkingTokenBudgetField && thinkingBudget !== undefined) {
|
|
729
|
+
Object.assign(params, { [thinkingTokenBudgetField]: thinkingBudget });
|
|
730
|
+
}
|
|
648
731
|
// OpenRouter provider routing preferences
|
|
649
732
|
if (model.compat?.openRouterRouting) {
|
|
650
733
|
params.provider = model.compat.openRouterRouting;
|
|
@@ -661,19 +744,38 @@ function buildParams(model, context, options, compat = getCompat(model), cacheRe
|
|
|
661
744
|
params.providerOptions = { gateway: gatewayOptions };
|
|
662
745
|
}
|
|
663
746
|
}
|
|
747
|
+
// Last so model and request sampling parameters override named request fields.
|
|
748
|
+
const samplingParams = resolveSamplingParams(model, options?.reasoningEffort ?? "off", options?.samplingParams);
|
|
749
|
+
if (samplingParams) {
|
|
750
|
+
Object.assign(params, samplingParams);
|
|
751
|
+
}
|
|
664
752
|
return params;
|
|
665
753
|
}
|
|
666
|
-
function
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
754
|
+
function resolveThinkingTokenBudgetField(compat) {
|
|
755
|
+
if (compat.thinkingTokenBudgetField)
|
|
756
|
+
return compat.thinkingTokenBudgetField;
|
|
757
|
+
if (compat.supportsThinkingTokenBudget)
|
|
758
|
+
return "thinking_token_budget";
|
|
759
|
+
return undefined;
|
|
760
|
+
}
|
|
761
|
+
function resolveClampedThinkingBudget(model, options, params) {
|
|
762
|
+
if (!options?.reasoningEffort || !model.reasoning)
|
|
763
|
+
return undefined;
|
|
764
|
+
const ceiling = params.max_tokens ?? params.max_completion_tokens ?? model.maxTokens;
|
|
765
|
+
const budget = clampThinkingBudgetToAnswerRoom(thinkingBudgetForLevel(options.reasoningEffort, options.thinkingBudgets), ceiling);
|
|
766
|
+
return budget > 0 ? budget : undefined;
|
|
767
|
+
}
|
|
768
|
+
function buildChatTemplateValues(model, options, values, thinkingBudget) {
|
|
769
|
+
const resolvedValues = {};
|
|
770
|
+
for (const [key, value] of Object.entries(values)) {
|
|
771
|
+
const resolved = resolveChatTemplateKwargValue(model, options, value, thinkingBudget);
|
|
670
772
|
if (resolved !== undefined) {
|
|
671
|
-
|
|
773
|
+
resolvedValues[key] = resolved;
|
|
672
774
|
}
|
|
673
775
|
}
|
|
674
|
-
return Object.keys(
|
|
776
|
+
return Object.keys(resolvedValues).length > 0 ? resolvedValues : undefined;
|
|
675
777
|
}
|
|
676
|
-
function resolveChatTemplateKwargValue(model, options, value) {
|
|
778
|
+
function resolveChatTemplateKwargValue(model, options, value, thinkingBudget) {
|
|
677
779
|
if (typeof value !== "object" || value === null) {
|
|
678
780
|
return value;
|
|
679
781
|
}
|
|
@@ -684,6 +786,9 @@ function resolveChatTemplateKwargValue(model, options, value) {
|
|
|
684
786
|
if (value.$var === "thinking.enabled") {
|
|
685
787
|
return !!reasoningEffort;
|
|
686
788
|
}
|
|
789
|
+
if (value.$var === "thinking.budget") {
|
|
790
|
+
return thinkingBudget;
|
|
791
|
+
}
|
|
687
792
|
const mappedValue = reasoningEffort ? model.thinkingLevelMap?.[reasoningEffort] : model.thinkingLevelMap?.off;
|
|
688
793
|
return mappedValue === undefined ? reasoningEffort : typeof mappedValue === "string" ? mappedValue : undefined;
|
|
689
794
|
}
|
|
@@ -762,6 +867,7 @@ function addCacheControlToTextContent(message, cacheControl) {
|
|
|
762
867
|
return false;
|
|
763
868
|
}
|
|
764
869
|
export function convertMessages(model, context, compat, options) {
|
|
870
|
+
const normalizedContext = resolveTranscript(context, compat.supportsMidConvoSystemMessages);
|
|
765
871
|
const params = [];
|
|
766
872
|
const normalizeToolCallId = (id) => {
|
|
767
873
|
// Handle pipe-separated IDs from OpenAI Responses API
|
|
@@ -788,12 +894,9 @@ export function convertMessages(model, context, compat, options) {
|
|
|
788
894
|
return id.length > 40 ? id.slice(0, 40) : id;
|
|
789
895
|
return id;
|
|
790
896
|
};
|
|
791
|
-
const transformedMessages = transformMessages(
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
const role = useDeveloperRole ? "developer" : "system";
|
|
795
|
-
params.push({ role: role, content: sanitizeSurrogates(context.systemPrompt) });
|
|
796
|
-
}
|
|
897
|
+
const transformedMessages = transformMessages(normalizedContext.messages, model, (id) => normalizeToolCallId(id));
|
|
898
|
+
const transcriptTools = resolveTranscriptTools(normalizedContext.messages, compat.supportsMidConvoSystemMessages === true && compat.supportsMidConvoToolAdditions === true);
|
|
899
|
+
const instructionRole = model.reasoning && compat.supportsDeveloperRole ? "developer" : "system";
|
|
797
900
|
let lastRole = null;
|
|
798
901
|
for (let i = 0; i < transformedMessages.length; i++) {
|
|
799
902
|
const msg = transformedMessages[i];
|
|
@@ -805,7 +908,21 @@ export function convertMessages(model, context, compat, options) {
|
|
|
805
908
|
content: "I have processed the tool results.",
|
|
806
909
|
});
|
|
807
910
|
}
|
|
808
|
-
if (msg.role === "
|
|
911
|
+
if (msg.role === "system") {
|
|
912
|
+
const addedTools = i > 0 && transcriptTools.anchorsAdditions ? (msg.toolsAdded ?? []) : [];
|
|
913
|
+
if (addedTools.length > 0) {
|
|
914
|
+
const kimiToolMessage = {
|
|
915
|
+
role: "system",
|
|
916
|
+
tools: convertTools(addedTools, compat),
|
|
917
|
+
};
|
|
918
|
+
params.push(kimiToolMessage);
|
|
919
|
+
}
|
|
920
|
+
const text = i === 0 ? getSystemMessageText(msg) : renderSystemMessageUpdate(msg);
|
|
921
|
+
if (text.length > 0) {
|
|
922
|
+
params.push({ role: instructionRole, content: sanitizeSurrogates(text) });
|
|
923
|
+
}
|
|
924
|
+
}
|
|
925
|
+
else if (msg.role === "user") {
|
|
809
926
|
if (typeof msg.content === "string") {
|
|
810
927
|
params.push({
|
|
811
928
|
role: "user",
|
|
@@ -813,7 +930,9 @@ export function convertMessages(model, context, compat, options) {
|
|
|
813
930
|
});
|
|
814
931
|
}
|
|
815
932
|
else {
|
|
816
|
-
const content = msg.content
|
|
933
|
+
const content = msg.content
|
|
934
|
+
.filter((item) => item.type !== "text" || item.text.length > 0)
|
|
935
|
+
.map((item) => {
|
|
817
936
|
if (item.type === "text") {
|
|
818
937
|
return {
|
|
819
938
|
type: "text",
|
|
@@ -851,9 +970,16 @@ export function convertMessages(model, context, compat, options) {
|
|
|
851
970
|
text: sanitizeSurrogates(block.text),
|
|
852
971
|
}));
|
|
853
972
|
const assistantText = assistantTextParts.map((part) => part.text).join("");
|
|
854
|
-
const
|
|
855
|
-
|
|
856
|
-
|
|
973
|
+
const thinkingBlocks = msg.content.filter(isThinkingContentBlock);
|
|
974
|
+
const toolCalls = msg.content.filter(isToolCallBlock);
|
|
975
|
+
const signedReasoningDetails = thinkingBlocks
|
|
976
|
+
.map((block) => parseOpenAIReasoningDetails(block.thinkingSignature))
|
|
977
|
+
.find((details) => details !== undefined);
|
|
978
|
+
const legacyReasoningDetails = toolCalls
|
|
979
|
+
.map((toolCall) => parseLegacyEncryptedReasoningDetail(toolCall.thoughtSignature))
|
|
980
|
+
.filter((detail) => detail !== undefined);
|
|
981
|
+
const preservedReasoningDetails = signedReasoningDetails ?? (legacyReasoningDetails.length > 0 ? legacyReasoningDetails : undefined);
|
|
982
|
+
const nonEmptyThinkingBlocks = thinkingBlocks.filter((block) => block.thinking.trim().length > 0);
|
|
857
983
|
if (nonEmptyThinkingBlocks.length > 0) {
|
|
858
984
|
if (compat.requiresThinkingAsText) {
|
|
859
985
|
// Convert thinking blocks to plain text (no tags to avoid model mimicking them)
|
|
@@ -871,13 +997,16 @@ export function convertMessages(model, context, compat, options) {
|
|
|
871
997
|
if (assistantText.length > 0) {
|
|
872
998
|
assistantMsg.content = assistantText;
|
|
873
999
|
}
|
|
874
|
-
//
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
signature =
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
1000
|
+
// reasoning_details is the structured alternative to a raw reasoning field.
|
|
1001
|
+
if (!preservedReasoningDetails) {
|
|
1002
|
+
// Use the signature from the first thinking block if available (for llama.cpp server + gpt-oss)
|
|
1003
|
+
let signature = nonEmptyThinkingBlocks[0].thinkingSignature;
|
|
1004
|
+
if (model.provider === "opencode-go" && signature === "reasoning") {
|
|
1005
|
+
signature = "reasoning_content";
|
|
1006
|
+
}
|
|
1007
|
+
if (signature && isOpenAICompletionsReasoningField(signature)) {
|
|
1008
|
+
assistantMsg[signature] = nonEmptyThinkingBlocks.map((block) => block.thinking).join("\n");
|
|
1009
|
+
}
|
|
881
1010
|
}
|
|
882
1011
|
}
|
|
883
1012
|
}
|
|
@@ -889,7 +1018,6 @@ export function convertMessages(model, context, compat, options) {
|
|
|
889
1018
|
// output, producing recursive nesting like [{'type':'text','text':'[{...}]'}].
|
|
890
1019
|
assistantMsg.content = assistantText;
|
|
891
1020
|
}
|
|
892
|
-
const toolCalls = msg.content.filter(isToolCallBlock);
|
|
893
1021
|
if (toolCalls.length > 0) {
|
|
894
1022
|
assistantMsg.tool_calls = toolCalls.map((tc) => {
|
|
895
1023
|
const customInputProperty = options?.grammarToolInputProperties?.get(tc.name);
|
|
@@ -912,20 +1040,9 @@ export function convertMessages(model, context, compat, options) {
|
|
|
912
1040
|
},
|
|
913
1041
|
};
|
|
914
1042
|
});
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
try {
|
|
919
|
-
return JSON.parse(tc.thoughtSignature);
|
|
920
|
-
}
|
|
921
|
-
catch {
|
|
922
|
-
return null;
|
|
923
|
-
}
|
|
924
|
-
})
|
|
925
|
-
.filter(Boolean);
|
|
926
|
-
if (reasoningDetails.length > 0) {
|
|
927
|
-
assistantMsg.reasoning_details = reasoningDetails;
|
|
928
|
-
}
|
|
1043
|
+
}
|
|
1044
|
+
if (preservedReasoningDetails) {
|
|
1045
|
+
assistantMsg.reasoning_details = preservedReasoningDetails;
|
|
929
1046
|
}
|
|
930
1047
|
if (compat.requiresReasoningContentOnAssistantMessages &&
|
|
931
1048
|
model.reasoning &&
|
|
@@ -947,7 +1064,6 @@ export function convertMessages(model, context, compat, options) {
|
|
|
947
1064
|
}
|
|
948
1065
|
else if (msg.role === "toolResult") {
|
|
949
1066
|
const imageBlocks = [];
|
|
950
|
-
const deferredToolNames = new Set();
|
|
951
1067
|
let j = i;
|
|
952
1068
|
for (; j < transformedMessages.length && transformedMessages[j].role === "toolResult"; j++) {
|
|
953
1069
|
const toolMsg = transformedMessages[j];
|
|
@@ -970,11 +1086,6 @@ export function convertMessages(model, context, compat, options) {
|
|
|
970
1086
|
toolResultMsg.name = toolMsg.toolName;
|
|
971
1087
|
}
|
|
972
1088
|
params.push(toolResultMsg);
|
|
973
|
-
if (compat.deferredToolsMode === "kimi") {
|
|
974
|
-
for (const name of toolMsg.addedToolNames ?? []) {
|
|
975
|
-
deferredToolNames.add(name);
|
|
976
|
-
}
|
|
977
|
-
}
|
|
978
1089
|
if (hasImages && model.input.includes("image")) {
|
|
979
1090
|
for (const block of toolMsg.content) {
|
|
980
1091
|
if (isImageContentBlock(block)) {
|
|
@@ -1011,17 +1122,6 @@ export function convertMessages(model, context, compat, options) {
|
|
|
1011
1122
|
else {
|
|
1012
1123
|
lastRole = "toolResult";
|
|
1013
1124
|
}
|
|
1014
|
-
if (deferredToolNames.size > 0) {
|
|
1015
|
-
const deferredTools = getToolsByName(context.tools, deferredToolNames);
|
|
1016
|
-
if (deferredTools.length > 0) {
|
|
1017
|
-
const kimiToolMessage = {
|
|
1018
|
-
role: "system",
|
|
1019
|
-
tools: convertTools(deferredTools, compat),
|
|
1020
|
-
};
|
|
1021
|
-
// Kimi accepts a system message with tools but omits the standard content field.
|
|
1022
|
-
params.push(kimiToolMessage);
|
|
1023
|
-
}
|
|
1024
|
-
}
|
|
1025
1125
|
continue;
|
|
1026
1126
|
}
|
|
1027
1127
|
lastRole = msg.role;
|
|
@@ -1053,7 +1153,7 @@ function convertTools(tools, compat) {
|
|
|
1053
1153
|
function: {
|
|
1054
1154
|
name: tool.name,
|
|
1055
1155
|
description: tool.description,
|
|
1056
|
-
parameters: tool
|
|
1156
|
+
parameters: getJsonSchemaToolParameters(tool, strict),
|
|
1057
1157
|
// Only include strict if provider supports it. Some reject unknown fields.
|
|
1058
1158
|
...(compat.supportsStrictMode !== false && { strict: strict ?? false }),
|
|
1059
1159
|
},
|
|
@@ -1062,10 +1162,13 @@ function convertTools(tools, compat) {
|
|
|
1062
1162
|
}
|
|
1063
1163
|
function parseChunkUsage(rawUsage, model) {
|
|
1064
1164
|
const promptTokens = rawUsage.prompt_tokens || 0;
|
|
1065
|
-
const cacheReadTokens = rawUsage.prompt_tokens_details?.cached_tokens ?? rawUsage.prompt_cache_hit_tokens ?? 0;
|
|
1165
|
+
const cacheReadTokens = rawUsage.prompt_tokens_details?.cached_tokens ?? rawUsage.prompt_cache_hit_tokens ?? rawUsage.cached_tokens ?? 0;
|
|
1066
1166
|
const cacheWriteTokens = rawUsage.prompt_tokens_details?.cache_write_tokens || 0;
|
|
1067
1167
|
// Follow documented OpenAI/OpenRouter semantics: cached_tokens is cache-read
|
|
1068
|
-
// tokens (hits).
|
|
1168
|
+
// tokens (hits). Providers disagree on placement: OpenAI/OpenRouter use
|
|
1169
|
+
// prompt_tokens_details.cached_tokens, DeepSeek uses prompt_cache_hit_tokens,
|
|
1170
|
+
// and Kimi documents top-level usage.cached_tokens on the final usage chunk.
|
|
1171
|
+
// OpenAI does not document or emit cache_write_tokens, but
|
|
1069
1172
|
// OpenRouter-compatible providers can include it as a separate write count.
|
|
1070
1173
|
// OpenRouter's own provider/tests affirm the separate mapping:
|
|
1071
1174
|
// https://github.com/OpenRouterTeam/ai-sdk-provider/pull/409
|
|
@@ -1129,14 +1232,15 @@ function detectCompat(model) {
|
|
|
1129
1232
|
const isCloudflareAiGateway = provider === "cloudflare-ai-gateway" || baseUrl.includes("gateway.ai.cloudflare.com");
|
|
1130
1233
|
const isNvidia = provider === "nvidia" || baseUrl.includes("integrate.api.nvidia.com");
|
|
1131
1234
|
const isAntLing = provider === "ant-ling" || baseUrl.includes("api.ant-ling.com");
|
|
1235
|
+
const isCerebras = provider === "cerebras" || baseUrl.includes("cerebras.ai");
|
|
1236
|
+
const isDeepSeek = provider === "deepseek" || baseUrl.toLowerCase().includes("deepseek.com");
|
|
1132
1237
|
const isNonStandard = isNvidia ||
|
|
1133
|
-
|
|
1134
|
-
baseUrl.includes("cerebras.ai") ||
|
|
1238
|
+
isCerebras ||
|
|
1135
1239
|
provider === "xai" ||
|
|
1136
1240
|
baseUrl.includes("api.x.ai") ||
|
|
1137
1241
|
isTogether ||
|
|
1138
1242
|
baseUrl.includes("chutes.ai") ||
|
|
1139
|
-
|
|
1243
|
+
isDeepSeek ||
|
|
1140
1244
|
isZai ||
|
|
1141
1245
|
isMoonshot ||
|
|
1142
1246
|
provider === "opencode" ||
|
|
@@ -1145,6 +1249,7 @@ function detectCompat(model) {
|
|
|
1145
1249
|
isCloudflareAiGateway ||
|
|
1146
1250
|
isAntLing;
|
|
1147
1251
|
const useMaxTokens = baseUrl.includes("chutes.ai") ||
|
|
1252
|
+
isDeepSeek ||
|
|
1148
1253
|
isMoonshot ||
|
|
1149
1254
|
isCloudflareAiGateway ||
|
|
1150
1255
|
isTogether ||
|
|
@@ -1152,7 +1257,6 @@ function detectCompat(model) {
|
|
|
1152
1257
|
isAntLing ||
|
|
1153
1258
|
isZai;
|
|
1154
1259
|
const isGrok = provider === "xai" || baseUrl.includes("api.x.ai");
|
|
1155
|
-
const isDeepSeek = provider === "deepseek" || baseUrl.includes("deepseek.com");
|
|
1156
1260
|
const isOpenRouterDeveloperRoleModel = isOpenRouter && (model.id.startsWith("anthropic/") || model.id.startsWith("openai/"));
|
|
1157
1261
|
const cacheControlFormat = provider === "openrouter" && model.id.startsWith("anthropic/") ? "anthropic" : undefined;
|
|
1158
1262
|
return {
|
|
@@ -1160,6 +1264,7 @@ function detectCompat(model) {
|
|
|
1160
1264
|
supportsDeveloperRole: isOpenRouterDeveloperRoleModel || (!isNonStandard && !isOpenRouter),
|
|
1161
1265
|
supportsReasoningEffort: !isGrok && !isZai && !isMoonshot && !isTogether && !isCloudflareAiGateway && !isNvidia && !isAntLing,
|
|
1162
1266
|
supportsUsageInStreaming: true,
|
|
1267
|
+
supportsFinishReason: true,
|
|
1163
1268
|
maxTokensField: useMaxTokens ? "max_tokens" : "max_completion_tokens",
|
|
1164
1269
|
requiresToolResultName: false,
|
|
1165
1270
|
requiresAssistantAfterToolResult: false,
|
|
@@ -1179,12 +1284,17 @@ function detectCompat(model) {
|
|
|
1179
1284
|
openRouterRouting: {},
|
|
1180
1285
|
vercelGatewayRouting: {},
|
|
1181
1286
|
chatTemplateKwargs: {},
|
|
1287
|
+
chatTemplateArgs: {},
|
|
1182
1288
|
zaiToolStream: false,
|
|
1183
|
-
|
|
1289
|
+
supportsThinkingTokenBudget: false,
|
|
1290
|
+
thinkingTokenBudgetField: undefined,
|
|
1291
|
+
// OpenAI compatibility alone does not imply strict JSON-schema tool support.
|
|
1292
|
+
supportsStrictMode: false,
|
|
1184
1293
|
supportsOpenAIGrammarTools: false,
|
|
1294
|
+
supportsMidConvoSystemMessages: false,
|
|
1295
|
+
supportsMidConvoToolAdditions: false,
|
|
1185
1296
|
cacheControlFormat,
|
|
1186
|
-
sendSessionAffinityHeaders:
|
|
1187
|
-
deferredToolsMode: undefined,
|
|
1297
|
+
sendSessionAffinityHeaders: isOpenRouter,
|
|
1188
1298
|
sessionAffinityFormat: isOpenRouter ? "openrouter" : "openai",
|
|
1189
1299
|
supportsLongCacheRetention: !(isTogether ||
|
|
1190
1300
|
isCloudflareWorkersAI ||
|
|
@@ -1206,6 +1316,7 @@ function getCompat(model) {
|
|
|
1206
1316
|
supportsDeveloperRole: model.compat.supportsDeveloperRole ?? detected.supportsDeveloperRole,
|
|
1207
1317
|
supportsReasoningEffort: model.compat.supportsReasoningEffort ?? detected.supportsReasoningEffort,
|
|
1208
1318
|
supportsUsageInStreaming: model.compat.supportsUsageInStreaming ?? detected.supportsUsageInStreaming,
|
|
1319
|
+
supportsFinishReason: model.compat.supportsFinishReason ?? detected.supportsFinishReason,
|
|
1209
1320
|
maxTokensField: model.compat.maxTokensField ?? detected.maxTokensField,
|
|
1210
1321
|
requiresToolResultName: model.compat.requiresToolResultName ?? detected.requiresToolResultName,
|
|
1211
1322
|
requiresAssistantAfterToolResult: model.compat.requiresAssistantAfterToolResult ?? detected.requiresAssistantAfterToolResult,
|
|
@@ -1216,14 +1327,19 @@ function getCompat(model) {
|
|
|
1216
1327
|
openRouterRouting: model.compat.openRouterRouting ?? {},
|
|
1217
1328
|
vercelGatewayRouting: model.compat.vercelGatewayRouting ?? detected.vercelGatewayRouting,
|
|
1218
1329
|
chatTemplateKwargs: model.compat.chatTemplateKwargs ?? detected.chatTemplateKwargs,
|
|
1330
|
+
chatTemplateArgs: model.compat.chatTemplateArgs ?? detected.chatTemplateArgs,
|
|
1219
1331
|
zaiToolStream: model.compat.zaiToolStream ?? detected.zaiToolStream,
|
|
1332
|
+
supportsThinkingTokenBudget: model.compat.supportsThinkingTokenBudget ?? detected.supportsThinkingTokenBudget,
|
|
1333
|
+
thinkingTokenBudgetField: model.compat.thinkingTokenBudgetField ?? detected.thinkingTokenBudgetField,
|
|
1220
1334
|
supportsStrictMode: model.compat.supportsStrictMode ?? detected.supportsStrictMode,
|
|
1221
1335
|
supportsOpenAIGrammarTools: model.compat.supportsOpenAIGrammarTools ?? detected.supportsOpenAIGrammarTools,
|
|
1336
|
+
supportsMidConvoSystemMessages: model.compat.supportsMidConvoSystemMessages ?? detected.supportsMidConvoSystemMessages,
|
|
1337
|
+
supportsMidConvoToolAdditions: model.compat.supportsMidConvoToolAdditions ?? detected.supportsMidConvoToolAdditions,
|
|
1222
1338
|
cacheControlFormat: model.compat.cacheControlFormat ?? detected.cacheControlFormat,
|
|
1223
1339
|
sendSessionAffinityHeaders: model.compat.sendSessionAffinityHeaders ?? detected.sendSessionAffinityHeaders,
|
|
1224
|
-
deferredToolsMode: model.compat.deferredToolsMode ?? detected.deferredToolsMode,
|
|
1225
1340
|
sessionAffinityFormat: model.compat.sessionAffinityFormat ?? detected.sessionAffinityFormat,
|
|
1226
1341
|
supportsLongCacheRetention: model.compat.supportsLongCacheRetention ?? detected.supportsLongCacheRetention,
|
|
1342
|
+
vllmPriority: model.compat.vllmPriority,
|
|
1227
1343
|
};
|
|
1228
1344
|
}
|
|
1229
1345
|
//# sourceMappingURL=openai-completions.js.map
|