@aexol/spectral 0.7.0 → 0.7.3
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 +5 -0
- package/dist/agent/agents.js +1 -1
- package/dist/agent/index.js +269 -479
- package/dist/cli.js +11 -0
- package/dist/commands/serve.js +0 -3
- package/dist/designer/data/systems/agentic/DESIGN.md +71 -0
- package/dist/designer/data/systems/agentic/components.html +154 -0
- package/dist/designer/data/systems/agentic/tokens.css +63 -0
- package/dist/designer/data/systems/airbnb/DESIGN.md +393 -0
- package/dist/designer/data/systems/airbnb/components.html +1373 -0
- package/dist/designer/data/systems/airbnb/tokens.css +261 -0
- package/dist/designer/data/systems/airtable/DESIGN.md +92 -0
- package/dist/designer/data/systems/airtable/components.html +489 -0
- package/dist/designer/data/systems/airtable/tokens.css +261 -0
- package/dist/designer/data/systems/ant/DESIGN.md +71 -0
- package/dist/designer/data/systems/ant/components.html +154 -0
- package/dist/designer/data/systems/ant/tokens.css +63 -0
- package/dist/designer/data/systems/apple/DESIGN.md +250 -0
- package/dist/designer/data/systems/apple/components.html +749 -0
- package/dist/designer/data/systems/apple/tokens.css +286 -0
- package/dist/designer/data/systems/application/DESIGN.md +71 -0
- package/dist/designer/data/systems/application/components.html +154 -0
- package/dist/designer/data/systems/application/tokens.css +63 -0
- package/dist/designer/data/systems/arc/DESIGN.md +152 -0
- package/dist/designer/data/systems/arc/components.html +432 -0
- package/dist/designer/data/systems/arc/tokens.css +137 -0
- package/dist/designer/data/systems/artistic/DESIGN.md +71 -0
- package/dist/designer/data/systems/artistic/components.html +136 -0
- package/dist/designer/data/systems/artistic/tokens.css +63 -0
- package/dist/designer/data/systems/atelier-zero/DESIGN.md +316 -0
- package/dist/designer/data/systems/atelier-zero/components.html +136 -0
- package/dist/designer/data/systems/atelier-zero/tokens.css +63 -0
- package/dist/designer/data/systems/bento/DESIGN.md +71 -0
- package/dist/designer/data/systems/bento/components.html +136 -0
- package/dist/designer/data/systems/bento/tokens.css +63 -0
- package/dist/designer/data/systems/binance/DESIGN.md +348 -0
- package/dist/designer/data/systems/binance/components.html +550 -0
- package/dist/designer/data/systems/binance/tokens.css +255 -0
- package/dist/designer/data/systems/bmw/DESIGN.md +183 -0
- package/dist/designer/data/systems/bmw/components.html +551 -0
- package/dist/designer/data/systems/bmw/tokens.css +179 -0
- package/dist/designer/data/systems/bmw-m/DESIGN.md +246 -0
- package/dist/designer/data/systems/bmw-m/components.html +342 -0
- package/dist/designer/data/systems/bmw-m/tokens.css +64 -0
- package/dist/designer/data/systems/bold/DESIGN.md +71 -0
- package/dist/designer/data/systems/bold/components.html +136 -0
- package/dist/designer/data/systems/bold/tokens.css +63 -0
- package/dist/designer/data/systems/brutalism/DESIGN.md +71 -0
- package/dist/designer/data/systems/brutalism/components.html +154 -0
- package/dist/designer/data/systems/brutalism/tokens.css +63 -0
- package/dist/designer/data/systems/bugatti/DESIGN.md +271 -0
- package/dist/designer/data/systems/bugatti/components.html +342 -0
- package/dist/designer/data/systems/bugatti/tokens.css +64 -0
- package/dist/designer/data/systems/cafe/DESIGN.md +71 -0
- package/dist/designer/data/systems/cafe/components.html +136 -0
- package/dist/designer/data/systems/cafe/tokens.css +63 -0
- package/dist/designer/data/systems/cal/DESIGN.md +262 -0
- package/dist/designer/data/systems/cal/components.html +376 -0
- package/dist/designer/data/systems/cal/tokens.css +265 -0
- package/dist/designer/data/systems/canva/DESIGN.md +157 -0
- package/dist/designer/data/systems/canva/components.html +461 -0
- package/dist/designer/data/systems/canva/tokens.css +147 -0
- package/dist/designer/data/systems/cisco/DESIGN.md +201 -0
- package/dist/designer/data/systems/cisco/components.html +342 -0
- package/dist/designer/data/systems/cisco/tokens.css +64 -0
- package/dist/designer/data/systems/claude/DESIGN.md +315 -0
- package/dist/designer/data/systems/claude/components.html +483 -0
- package/dist/designer/data/systems/claude/tokens.css +130 -0
- package/dist/designer/data/systems/clay/DESIGN.md +307 -0
- package/dist/designer/data/systems/clay/components.html +136 -0
- package/dist/designer/data/systems/clay/tokens.css +63 -0
- package/dist/designer/data/systems/claymorphism/DESIGN.md +71 -0
- package/dist/designer/data/systems/claymorphism/components.html +136 -0
- package/dist/designer/data/systems/claymorphism/tokens.css +63 -0
- package/dist/designer/data/systems/clean/DESIGN.md +71 -0
- package/dist/designer/data/systems/clean/components.html +136 -0
- package/dist/designer/data/systems/clean/tokens.css +63 -0
- package/dist/designer/data/systems/clickhouse/DESIGN.md +284 -0
- package/dist/designer/data/systems/clickhouse/components.html +506 -0
- package/dist/designer/data/systems/clickhouse/tokens.css +135 -0
- package/dist/designer/data/systems/cohere/DESIGN.md +269 -0
- package/dist/designer/data/systems/cohere/components.html +353 -0
- package/dist/designer/data/systems/cohere/tokens.css +126 -0
- package/dist/designer/data/systems/coinbase/DESIGN.md +132 -0
- package/dist/designer/data/systems/coinbase/components.html +501 -0
- package/dist/designer/data/systems/coinbase/tokens.css +257 -0
- package/dist/designer/data/systems/colorful/DESIGN.md +71 -0
- package/dist/designer/data/systems/colorful/components.html +136 -0
- package/dist/designer/data/systems/colorful/tokens.css +63 -0
- package/dist/designer/data/systems/composio/DESIGN.md +310 -0
- package/dist/designer/data/systems/composio/components.html +342 -0
- package/dist/designer/data/systems/composio/tokens.css +64 -0
- package/dist/designer/data/systems/contemporary/DESIGN.md +71 -0
- package/dist/designer/data/systems/contemporary/components.html +136 -0
- package/dist/designer/data/systems/contemporary/tokens.css +63 -0
- package/dist/designer/data/systems/corporate/DESIGN.md +71 -0
- package/dist/designer/data/systems/corporate/components.html +136 -0
- package/dist/designer/data/systems/corporate/tokens.css +63 -0
- package/dist/designer/data/systems/cosmic/DESIGN.md +71 -0
- package/dist/designer/data/systems/cosmic/components.html +136 -0
- package/dist/designer/data/systems/cosmic/tokens.css +63 -0
- package/dist/designer/data/systems/creative/DESIGN.md +71 -0
- package/dist/designer/data/systems/creative/components.html +136 -0
- package/dist/designer/data/systems/creative/tokens.css +63 -0
- package/dist/designer/data/systems/cursor/DESIGN.md +312 -0
- package/dist/designer/data/systems/cursor/components.html +654 -0
- package/dist/designer/data/systems/cursor/tokens.css +218 -0
- package/dist/designer/data/systems/dashboard/DESIGN.md +71 -0
- package/dist/designer/data/systems/dashboard/components.html +154 -0
- package/dist/designer/data/systems/dashboard/tokens.css +63 -0
- package/dist/designer/data/systems/default/DESIGN.md +62 -0
- package/dist/designer/data/systems/default/components.html +523 -0
- package/dist/designer/data/systems/default/tokens.css +200 -0
- package/dist/designer/data/systems/discord/DESIGN.md +162 -0
- package/dist/designer/data/systems/discord/components.html +359 -0
- package/dist/designer/data/systems/discord/tokens.css +125 -0
- package/dist/designer/data/systems/dithered/DESIGN.md +71 -0
- package/dist/designer/data/systems/dithered/components.html +136 -0
- package/dist/designer/data/systems/dithered/tokens.css +63 -0
- package/dist/designer/data/systems/doodle/DESIGN.md +71 -0
- package/dist/designer/data/systems/doodle/components.html +136 -0
- package/dist/designer/data/systems/doodle/tokens.css +63 -0
- package/dist/designer/data/systems/dramatic/DESIGN.md +71 -0
- package/dist/designer/data/systems/dramatic/components.html +136 -0
- package/dist/designer/data/systems/dramatic/tokens.css +63 -0
- package/dist/designer/data/systems/duolingo/DESIGN.md +154 -0
- package/dist/designer/data/systems/duolingo/components.html +532 -0
- package/dist/designer/data/systems/duolingo/tokens.css +130 -0
- package/dist/designer/data/systems/editorial/DESIGN.md +71 -0
- package/dist/designer/data/systems/editorial/components.html +154 -0
- package/dist/designer/data/systems/editorial/tokens.css +63 -0
- package/dist/designer/data/systems/elegant/DESIGN.md +71 -0
- package/dist/designer/data/systems/elegant/components.html +136 -0
- package/dist/designer/data/systems/elegant/tokens.css +63 -0
- package/dist/designer/data/systems/elevenlabs/DESIGN.md +268 -0
- package/dist/designer/data/systems/elevenlabs/components.html +342 -0
- package/dist/designer/data/systems/elevenlabs/tokens.css +127 -0
- package/dist/designer/data/systems/energetic/DESIGN.md +72 -0
- package/dist/designer/data/systems/energetic/components.html +136 -0
- package/dist/designer/data/systems/energetic/tokens.css +63 -0
- package/dist/designer/data/systems/enterprise/DESIGN.md +71 -0
- package/dist/designer/data/systems/enterprise/components.html +154 -0
- package/dist/designer/data/systems/enterprise/tokens.css +63 -0
- package/dist/designer/data/systems/expo/DESIGN.md +284 -0
- package/dist/designer/data/systems/expo/components.html +342 -0
- package/dist/designer/data/systems/expo/tokens.css +64 -0
- package/dist/designer/data/systems/expressive/DESIGN.md +71 -0
- package/dist/designer/data/systems/expressive/components.html +136 -0
- package/dist/designer/data/systems/expressive/tokens.css +63 -0
- package/dist/designer/data/systems/fantasy/DESIGN.md +71 -0
- package/dist/designer/data/systems/fantasy/components.html +136 -0
- package/dist/designer/data/systems/fantasy/tokens.css +63 -0
- package/dist/designer/data/systems/ferrari/DESIGN.md +317 -0
- package/dist/designer/data/systems/ferrari/components.html +342 -0
- package/dist/designer/data/systems/ferrari/tokens.css +64 -0
- package/dist/designer/data/systems/figma/DESIGN.md +223 -0
- package/dist/designer/data/systems/figma/components.html +344 -0
- package/dist/designer/data/systems/figma/tokens.css +126 -0
- package/dist/designer/data/systems/flat/DESIGN.md +71 -0
- package/dist/designer/data/systems/flat/components.html +136 -0
- package/dist/designer/data/systems/flat/tokens.css +63 -0
- package/dist/designer/data/systems/framer/DESIGN.md +249 -0
- package/dist/designer/data/systems/framer/components.html +438 -0
- package/dist/designer/data/systems/framer/tokens.css +238 -0
- package/dist/designer/data/systems/friendly/DESIGN.md +71 -0
- package/dist/designer/data/systems/friendly/components.html +136 -0
- package/dist/designer/data/systems/friendly/tokens.css +63 -0
- package/dist/designer/data/systems/futuristic/DESIGN.md +71 -0
- package/dist/designer/data/systems/futuristic/components.html +136 -0
- package/dist/designer/data/systems/futuristic/tokens.css +63 -0
- package/dist/designer/data/systems/github/DESIGN.md +155 -0
- package/dist/designer/data/systems/github/components.html +383 -0
- package/dist/designer/data/systems/github/tokens.css +125 -0
- package/dist/designer/data/systems/glassmorphism/DESIGN.md +71 -0
- package/dist/designer/data/systems/glassmorphism/components.html +154 -0
- package/dist/designer/data/systems/glassmorphism/tokens.css +63 -0
- package/dist/designer/data/systems/gradient/DESIGN.md +71 -0
- package/dist/designer/data/systems/gradient/components.html +154 -0
- package/dist/designer/data/systems/gradient/tokens.css +63 -0
- package/dist/designer/data/systems/hashicorp/DESIGN.md +281 -0
- package/dist/designer/data/systems/hashicorp/components.html +502 -0
- package/dist/designer/data/systems/hashicorp/tokens.css +272 -0
- package/dist/designer/data/systems/hud/DESIGN.md +173 -0
- package/dist/designer/data/systems/hud/components.html +136 -0
- package/dist/designer/data/systems/hud/tokens.css +63 -0
- package/dist/designer/data/systems/huggingface/DESIGN.md +149 -0
- package/dist/designer/data/systems/huggingface/components.html +346 -0
- package/dist/designer/data/systems/huggingface/tokens.css +125 -0
- package/dist/designer/data/systems/ibm/DESIGN.md +335 -0
- package/dist/designer/data/systems/ibm/components.html +342 -0
- package/dist/designer/data/systems/ibm/tokens.css +64 -0
- package/dist/designer/data/systems/intercom/DESIGN.md +149 -0
- package/dist/designer/data/systems/intercom/components.html +557 -0
- package/dist/designer/data/systems/intercom/tokens.css +150 -0
- package/dist/designer/data/systems/kami/DESIGN.md +410 -0
- package/dist/designer/data/systems/kami/components.html +601 -0
- package/dist/designer/data/systems/kami/tokens.css +272 -0
- package/dist/designer/data/systems/kraken/DESIGN.md +128 -0
- package/dist/designer/data/systems/kraken/components.html +342 -0
- package/dist/designer/data/systems/kraken/tokens.css +64 -0
- package/dist/designer/data/systems/lamborghini/DESIGN.md +291 -0
- package/dist/designer/data/systems/lamborghini/components.html +342 -0
- package/dist/designer/data/systems/lamborghini/tokens.css +64 -0
- package/dist/designer/data/systems/levels/DESIGN.md +71 -0
- package/dist/designer/data/systems/levels/components.html +154 -0
- package/dist/designer/data/systems/levels/tokens.css +63 -0
- package/dist/designer/data/systems/linear-app/DESIGN.md +370 -0
- package/dist/designer/data/systems/linear-app/components.html +370 -0
- package/dist/designer/data/systems/linear-app/tokens.css +130 -0
- package/dist/designer/data/systems/lingo/DESIGN.md +71 -0
- package/dist/designer/data/systems/lingo/components.html +154 -0
- package/dist/designer/data/systems/lingo/tokens.css +63 -0
- package/dist/designer/data/systems/loom/DESIGN.md +201 -0
- package/dist/designer/data/systems/loom/components.html +446 -0
- package/dist/designer/data/systems/loom/tokens.css +138 -0
- package/dist/designer/data/systems/lovable/DESIGN.md +301 -0
- package/dist/designer/data/systems/lovable/components.html +441 -0
- package/dist/designer/data/systems/lovable/tokens.css +258 -0
- package/dist/designer/data/systems/luxury/DESIGN.md +71 -0
- package/dist/designer/data/systems/luxury/components.html +154 -0
- package/dist/designer/data/systems/luxury/tokens.css +63 -0
- package/dist/designer/data/systems/mastercard/DESIGN.md +368 -0
- package/dist/designer/data/systems/mastercard/components.html +342 -0
- package/dist/designer/data/systems/mastercard/tokens.css +64 -0
- package/dist/designer/data/systems/material/DESIGN.md +71 -0
- package/dist/designer/data/systems/material/components.html +154 -0
- package/dist/designer/data/systems/material/tokens.css +63 -0
- package/dist/designer/data/systems/meta/DESIGN.md +369 -0
- package/dist/designer/data/systems/meta/components.html +398 -0
- package/dist/designer/data/systems/meta/tokens.css +263 -0
- package/dist/designer/data/systems/minimal/DESIGN.md +71 -0
- package/dist/designer/data/systems/minimal/components.html +154 -0
- package/dist/designer/data/systems/minimal/tokens.css +63 -0
- package/dist/designer/data/systems/minimax/DESIGN.md +260 -0
- package/dist/designer/data/systems/minimax/components.html +590 -0
- package/dist/designer/data/systems/minimax/tokens.css +148 -0
- package/dist/designer/data/systems/mintlify/DESIGN.md +329 -0
- package/dist/designer/data/systems/mintlify/components.html +737 -0
- package/dist/designer/data/systems/mintlify/tokens.css +256 -0
- package/dist/designer/data/systems/miro/DESIGN.md +111 -0
- package/dist/designer/data/systems/miro/components.html +342 -0
- package/dist/designer/data/systems/miro/tokens.css +64 -0
- package/dist/designer/data/systems/mission-control/DESIGN.md +474 -0
- package/dist/designer/data/systems/mission-control/components.html +136 -0
- package/dist/designer/data/systems/mission-control/tokens.css +63 -0
- package/dist/designer/data/systems/mistral-ai/DESIGN.md +264 -0
- package/dist/designer/data/systems/mistral-ai/components.html +338 -0
- package/dist/designer/data/systems/mistral-ai/tokens.css +125 -0
- package/dist/designer/data/systems/modern/DESIGN.md +71 -0
- package/dist/designer/data/systems/modern/components.html +154 -0
- package/dist/designer/data/systems/modern/tokens.css +63 -0
- package/dist/designer/data/systems/mongodb/DESIGN.md +269 -0
- package/dist/designer/data/systems/mongodb/components.html +462 -0
- package/dist/designer/data/systems/mongodb/tokens.css +176 -0
- package/dist/designer/data/systems/mono/DESIGN.md +71 -0
- package/dist/designer/data/systems/mono/components.html +136 -0
- package/dist/designer/data/systems/mono/tokens.css +63 -0
- package/dist/designer/data/systems/neobrutalism/DESIGN.md +71 -0
- package/dist/designer/data/systems/neobrutalism/components.html +136 -0
- package/dist/designer/data/systems/neobrutalism/tokens.css +63 -0
- package/dist/designer/data/systems/neon/DESIGN.md +71 -0
- package/dist/designer/data/systems/neon/components.html +136 -0
- package/dist/designer/data/systems/neon/tokens.css +63 -0
- package/dist/designer/data/systems/neumorphism/DESIGN.md +71 -0
- package/dist/designer/data/systems/neumorphism/components.html +136 -0
- package/dist/designer/data/systems/neumorphism/tokens.css +63 -0
- package/dist/designer/data/systems/nike/DESIGN.md +366 -0
- package/dist/designer/data/systems/nike/components.html +512 -0
- package/dist/designer/data/systems/nike/tokens.css +304 -0
- package/dist/designer/data/systems/notion/DESIGN.md +312 -0
- package/dist/designer/data/systems/notion/components.html +413 -0
- package/dist/designer/data/systems/notion/tokens.css +130 -0
- package/dist/designer/data/systems/nvidia/DESIGN.md +296 -0
- package/dist/designer/data/systems/nvidia/components.html +414 -0
- package/dist/designer/data/systems/nvidia/tokens.css +133 -0
- package/dist/designer/data/systems/ollama/DESIGN.md +270 -0
- package/dist/designer/data/systems/ollama/components.html +700 -0
- package/dist/designer/data/systems/ollama/tokens.css +242 -0
- package/dist/designer/data/systems/openai/DESIGN.md +140 -0
- package/dist/designer/data/systems/openai/components.html +382 -0
- package/dist/designer/data/systems/openai/tokens.css +133 -0
- package/dist/designer/data/systems/opencode-ai/DESIGN.md +284 -0
- package/dist/designer/data/systems/opencode-ai/components.html +389 -0
- package/dist/designer/data/systems/opencode-ai/tokens.css +126 -0
- package/dist/designer/data/systems/pacman/DESIGN.md +71 -0
- package/dist/designer/data/systems/pacman/components.html +342 -0
- package/dist/designer/data/systems/pacman/tokens.css +64 -0
- package/dist/designer/data/systems/paper/DESIGN.md +71 -0
- package/dist/designer/data/systems/paper/components.html +136 -0
- package/dist/designer/data/systems/paper/tokens.css +63 -0
- package/dist/designer/data/systems/perplexity/DESIGN.md +286 -0
- package/dist/designer/data/systems/perplexity/components.html +455 -0
- package/dist/designer/data/systems/perplexity/tokens.css +151 -0
- package/dist/designer/data/systems/perspective/DESIGN.md +71 -0
- package/dist/designer/data/systems/perspective/components.html +136 -0
- package/dist/designer/data/systems/perspective/tokens.css +63 -0
- package/dist/designer/data/systems/pinterest/DESIGN.md +233 -0
- package/dist/designer/data/systems/pinterest/components.html +865 -0
- package/dist/designer/data/systems/pinterest/tokens.css +262 -0
- package/dist/designer/data/systems/playstation/DESIGN.md +367 -0
- package/dist/designer/data/systems/playstation/components.html +414 -0
- package/dist/designer/data/systems/playstation/tokens.css +150 -0
- package/dist/designer/data/systems/posthog/DESIGN.md +259 -0
- package/dist/designer/data/systems/posthog/components.html +827 -0
- package/dist/designer/data/systems/posthog/tokens.css +272 -0
- package/dist/designer/data/systems/premium/DESIGN.md +71 -0
- package/dist/designer/data/systems/premium/components.html +154 -0
- package/dist/designer/data/systems/premium/tokens.css +63 -0
- package/dist/designer/data/systems/professional/DESIGN.md +71 -0
- package/dist/designer/data/systems/professional/components.html +136 -0
- package/dist/designer/data/systems/professional/tokens.css +63 -0
- package/dist/designer/data/systems/publication/DESIGN.md +71 -0
- package/dist/designer/data/systems/publication/components.html +154 -0
- package/dist/designer/data/systems/publication/tokens.css +63 -0
- package/dist/designer/data/systems/raycast/DESIGN.md +271 -0
- package/dist/designer/data/systems/raycast/components.html +507 -0
- package/dist/designer/data/systems/raycast/tokens.css +143 -0
- package/dist/designer/data/systems/refined/DESIGN.md +71 -0
- package/dist/designer/data/systems/refined/components.html +136 -0
- package/dist/designer/data/systems/refined/tokens.css +63 -0
- package/dist/designer/data/systems/renault/DESIGN.md +314 -0
- package/dist/designer/data/systems/renault/components.html +154 -0
- package/dist/designer/data/systems/renault/tokens.css +63 -0
- package/dist/designer/data/systems/replicate/DESIGN.md +264 -0
- package/dist/designer/data/systems/replicate/components.html +340 -0
- package/dist/designer/data/systems/replicate/tokens.css +125 -0
- package/dist/designer/data/systems/resend/DESIGN.md +306 -0
- package/dist/designer/data/systems/resend/components.html +839 -0
- package/dist/designer/data/systems/resend/tokens.css +353 -0
- package/dist/designer/data/systems/retro/DESIGN.md +71 -0
- package/dist/designer/data/systems/retro/components.html +136 -0
- package/dist/designer/data/systems/retro/tokens.css +63 -0
- package/dist/designer/data/systems/revolut/DESIGN.md +188 -0
- package/dist/designer/data/systems/revolut/components.html +342 -0
- package/dist/designer/data/systems/revolut/tokens.css +64 -0
- package/dist/designer/data/systems/runwayml/DESIGN.md +247 -0
- package/dist/designer/data/systems/runwayml/components.html +638 -0
- package/dist/designer/data/systems/runwayml/tokens.css +204 -0
- package/dist/designer/data/systems/sanity/DESIGN.md +360 -0
- package/dist/designer/data/systems/sanity/components.html +342 -0
- package/dist/designer/data/systems/sanity/tokens.css +64 -0
- package/dist/designer/data/systems/sentry/DESIGN.md +265 -0
- package/dist/designer/data/systems/sentry/components.html +387 -0
- package/dist/designer/data/systems/sentry/tokens.css +219 -0
- package/dist/designer/data/systems/shadcn/DESIGN.md +71 -0
- package/dist/designer/data/systems/shadcn/components.html +732 -0
- package/dist/designer/data/systems/shadcn/tokens.css +255 -0
- package/dist/designer/data/systems/shopify/DESIGN.md +353 -0
- package/dist/designer/data/systems/shopify/components.html +342 -0
- package/dist/designer/data/systems/shopify/tokens.css +141 -0
- package/dist/designer/data/systems/simple/DESIGN.md +71 -0
- package/dist/designer/data/systems/simple/components.html +136 -0
- package/dist/designer/data/systems/simple/tokens.css +63 -0
- package/dist/designer/data/systems/skeumorphism/DESIGN.md +71 -0
- package/dist/designer/data/systems/skeumorphism/components.html +136 -0
- package/dist/designer/data/systems/skeumorphism/tokens.css +63 -0
- package/dist/designer/data/systems/slack/DESIGN.md +363 -0
- package/dist/designer/data/systems/slack/components.html +387 -0
- package/dist/designer/data/systems/slack/tokens.css +127 -0
- package/dist/designer/data/systems/sleek/DESIGN.md +71 -0
- package/dist/designer/data/systems/sleek/components.html +136 -0
- package/dist/designer/data/systems/sleek/tokens.css +63 -0
- package/dist/designer/data/systems/spacex/DESIGN.md +197 -0
- package/dist/designer/data/systems/spacex/components.html +496 -0
- package/dist/designer/data/systems/spacex/tokens.css +154 -0
- package/dist/designer/data/systems/spacious/DESIGN.md +71 -0
- package/dist/designer/data/systems/spacious/components.html +136 -0
- package/dist/designer/data/systems/spacious/tokens.css +63 -0
- package/dist/designer/data/systems/spotify/DESIGN.md +249 -0
- package/dist/designer/data/systems/spotify/components.html +365 -0
- package/dist/designer/data/systems/spotify/tokens.css +127 -0
- package/dist/designer/data/systems/starbucks/DESIGN.md +583 -0
- package/dist/designer/data/systems/starbucks/components.html +493 -0
- package/dist/designer/data/systems/starbucks/tokens.css +182 -0
- package/dist/designer/data/systems/storytelling/DESIGN.md +71 -0
- package/dist/designer/data/systems/storytelling/components.html +136 -0
- package/dist/designer/data/systems/storytelling/tokens.css +63 -0
- package/dist/designer/data/systems/stripe/DESIGN.md +325 -0
- package/dist/designer/data/systems/stripe/components.html +1018 -0
- package/dist/designer/data/systems/stripe/tokens.css +295 -0
- package/dist/designer/data/systems/supabase/DESIGN.md +258 -0
- package/dist/designer/data/systems/supabase/components.html +741 -0
- package/dist/designer/data/systems/supabase/tokens.css +294 -0
- package/dist/designer/data/systems/superhuman/DESIGN.md +255 -0
- package/dist/designer/data/systems/superhuman/components.html +537 -0
- package/dist/designer/data/systems/superhuman/tokens.css +160 -0
- package/dist/designer/data/systems/tesla/DESIGN.md +289 -0
- package/dist/designer/data/systems/tesla/components.html +724 -0
- package/dist/designer/data/systems/tesla/tokens.css +285 -0
- package/dist/designer/data/systems/tetris/DESIGN.md +71 -0
- package/dist/designer/data/systems/tetris/components.html +342 -0
- package/dist/designer/data/systems/tetris/tokens.css +64 -0
- package/dist/designer/data/systems/theverge/DESIGN.md +342 -0
- package/dist/designer/data/systems/theverge/components.html +342 -0
- package/dist/designer/data/systems/theverge/tokens.css +64 -0
- package/dist/designer/data/systems/together-ai/DESIGN.md +266 -0
- package/dist/designer/data/systems/together-ai/components.html +422 -0
- package/dist/designer/data/systems/together-ai/tokens.css +127 -0
- package/dist/designer/data/systems/totality-festival/DESIGN.md +206 -0
- package/dist/designer/data/systems/totality-festival/components.html +136 -0
- package/dist/designer/data/systems/totality-festival/tokens.css +63 -0
- package/dist/designer/data/systems/trading-terminal/DESIGN.md +178 -0
- package/dist/designer/data/systems/trading-terminal/components.html +154 -0
- package/dist/designer/data/systems/trading-terminal/tokens.css +63 -0
- package/dist/designer/data/systems/uber/DESIGN.md +298 -0
- package/dist/designer/data/systems/uber/components.html +347 -0
- package/dist/designer/data/systems/uber/tokens.css +131 -0
- package/dist/designer/data/systems/urdu/DESIGN.md +1002 -0
- package/dist/designer/data/systems/urdu/components.html +136 -0
- package/dist/designer/data/systems/urdu/tokens.css +63 -0
- package/dist/designer/data/systems/vercel/DESIGN.md +313 -0
- package/dist/designer/data/systems/vercel/components.html +839 -0
- package/dist/designer/data/systems/vercel/tokens.css +270 -0
- package/dist/designer/data/systems/vibrant/DESIGN.md +71 -0
- package/dist/designer/data/systems/vibrant/components.html +136 -0
- package/dist/designer/data/systems/vibrant/tokens.css +63 -0
- package/dist/designer/data/systems/vintage/DESIGN.md +71 -0
- package/dist/designer/data/systems/vintage/components.html +136 -0
- package/dist/designer/data/systems/vintage/tokens.css +63 -0
- package/dist/designer/data/systems/vodafone/DESIGN.md +426 -0
- package/dist/designer/data/systems/vodafone/components.html +342 -0
- package/dist/designer/data/systems/vodafone/tokens.css +64 -0
- package/dist/designer/data/systems/voltagent/DESIGN.md +326 -0
- package/dist/designer/data/systems/voltagent/components.html +154 -0
- package/dist/designer/data/systems/voltagent/tokens.css +63 -0
- package/dist/designer/data/systems/warm-editorial/DESIGN.md +65 -0
- package/dist/designer/data/systems/warm-editorial/components.html +136 -0
- package/dist/designer/data/systems/warm-editorial/tokens.css +63 -0
- package/dist/designer/data/systems/warp/DESIGN.md +256 -0
- package/dist/designer/data/systems/warp/components.html +411 -0
- package/dist/designer/data/systems/warp/tokens.css +156 -0
- package/dist/designer/data/systems/webex/DESIGN.md +207 -0
- package/dist/designer/data/systems/webex/components.html +342 -0
- package/dist/designer/data/systems/webex/tokens.css +64 -0
- package/dist/designer/data/systems/webflow/DESIGN.md +95 -0
- package/dist/designer/data/systems/webflow/components.html +413 -0
- package/dist/designer/data/systems/webflow/tokens.css +191 -0
- package/dist/designer/data/systems/wechat/DESIGN.md +302 -0
- package/dist/designer/data/systems/wechat/components.html +507 -0
- package/dist/designer/data/systems/wechat/tokens.css +176 -0
- package/dist/designer/data/systems/wired/DESIGN.md +281 -0
- package/dist/designer/data/systems/wired/components.html +342 -0
- package/dist/designer/data/systems/wired/tokens.css +64 -0
- package/dist/designer/data/systems/wise/DESIGN.md +176 -0
- package/dist/designer/data/systems/wise/components.html +365 -0
- package/dist/designer/data/systems/wise/tokens.css +141 -0
- package/dist/designer/data/systems/x-ai/DESIGN.md +260 -0
- package/dist/designer/data/systems/x-ai/components.html +460 -0
- package/dist/designer/data/systems/x-ai/tokens.css +268 -0
- package/dist/designer/data/systems/xiaohongshu/DESIGN.md +402 -0
- package/dist/designer/data/systems/xiaohongshu/components.html +865 -0
- package/dist/designer/data/systems/xiaohongshu/tokens.css +193 -0
- package/dist/designer/data/systems/zapier/DESIGN.md +331 -0
- package/dist/designer/data/systems/zapier/components.html +342 -0
- package/dist/designer/data/systems/zapier/tokens.css +64 -0
- package/dist/designer/guidelines.js +176 -0
- package/dist/designer/index.js +236 -0
- package/dist/designer/philosophies.js +668 -0
- package/dist/designer/skills.js +1675 -0
- package/dist/designer/systems.js +216 -0
- package/dist/mcp/sampling-handler.js +1 -1
- package/dist/memory/commands/status.js +1 -1
- package/dist/memory/compaction.js +2 -2
- package/dist/memory/config.js +1 -1
- package/dist/memory/debug-log.js +1 -1
- package/dist/memory/hooks/compaction-hook.js +29 -0
- package/dist/memory/index.js +2 -0
- package/dist/memory/observer.js +2 -2
- package/dist/memory/project-observations-store.js +14 -0
- package/dist/memory/tokens.js +1 -1
- package/dist/memory/tools/read-project-observations.js +82 -0
- package/dist/memory/tools/recall-observation.js +2 -2
- package/dist/pi/agent-core/agent-loop.js +501 -0
- package/dist/pi/agent-core/agent.js +401 -0
- package/dist/pi/agent-core/harness/agent-harness.js +899 -0
- package/dist/pi/agent-core/harness/compaction/branch-summarization.js +173 -0
- package/dist/pi/agent-core/harness/compaction/compaction.js +532 -0
- package/dist/pi/agent-core/harness/compaction/utils.js +130 -0
- package/dist/pi/agent-core/harness/env/nodejs.js +485 -0
- package/dist/pi/agent-core/harness/messages.js +101 -0
- package/dist/pi/agent-core/harness/prompt-templates.js +229 -0
- package/dist/pi/agent-core/harness/session/jsonl-repo.js +100 -0
- package/dist/pi/agent-core/harness/session/jsonl-storage.js +230 -0
- package/dist/pi/agent-core/harness/session/memory-repo.js +41 -0
- package/dist/pi/agent-core/harness/session/memory-storage.js +113 -0
- package/dist/pi/agent-core/harness/session/repo-utils.js +38 -0
- package/dist/pi/agent-core/harness/session/session.js +196 -0
- package/dist/pi/agent-core/harness/session/uuid.js +49 -0
- package/dist/pi/agent-core/harness/skills.js +310 -0
- package/dist/pi/agent-core/harness/system-prompt.js +29 -0
- package/dist/pi/agent-core/harness/types.js +93 -0
- package/dist/pi/agent-core/harness/utils/shell-output.js +125 -0
- package/dist/pi/agent-core/harness/utils/truncate.js +289 -0
- package/dist/pi/agent-core/index.js +24 -0
- package/dist/pi/agent-core/node.js +2 -0
- package/dist/pi/agent-core/proxy.js +277 -0
- package/dist/pi/agent-core/types.js +1 -0
- package/dist/pi/ai/api-registry.js +43 -0
- package/dist/pi/ai/cli.js +120 -0
- package/dist/pi/ai/env-api-keys.js +169 -0
- package/dist/pi/ai/image-models.generated.js +441 -0
- package/dist/pi/ai/image-models.js +22 -0
- package/dist/pi/ai/images-api-registry.js +21 -0
- package/dist/pi/ai/images.js +13 -0
- package/dist/pi/ai/index.js +18 -0
- package/dist/pi/ai/models.generated.js +16220 -0
- package/dist/pi/ai/models.js +70 -0
- package/dist/pi/ai/oauth.js +1 -0
- package/dist/pi/ai/providers/anthropic.js +945 -0
- package/dist/pi/ai/providers/faux.js +367 -0
- package/dist/pi/ai/providers/github-copilot-headers.js +28 -0
- package/dist/pi/ai/providers/openai-completions.js +945 -0
- package/dist/pi/ai/providers/openai-prompt-cache.js +9 -0
- package/dist/pi/ai/providers/register-builtins.js +97 -0
- package/dist/pi/ai/providers/simple-options.js +40 -0
- package/dist/pi/ai/providers/transform-messages.js +183 -0
- package/dist/pi/ai/session-resources.js +21 -0
- package/dist/pi/ai/stream.js +26 -0
- package/dist/pi/ai/types.js +1 -0
- package/dist/pi/ai/utils/diagnostics.js +24 -0
- package/dist/pi/ai/utils/event-stream.js +80 -0
- package/dist/pi/ai/utils/hash.js +13 -0
- package/dist/pi/ai/utils/headers.js +7 -0
- package/dist/pi/ai/utils/json-parse.js +112 -0
- package/dist/pi/ai/utils/node-http-proxy.js +96 -0
- package/dist/pi/ai/utils/oauth/anthropic.js +334 -0
- package/dist/pi/ai/utils/oauth/device-code.js +54 -0
- package/dist/pi/ai/utils/oauth/github-copilot.js +270 -0
- package/dist/pi/ai/utils/oauth/index.js +121 -0
- package/dist/pi/ai/utils/oauth/oauth-page.js +104 -0
- package/dist/pi/ai/utils/oauth/openai-codex.js +384 -0
- package/dist/pi/ai/utils/oauth/pkce.js +30 -0
- package/dist/pi/ai/utils/oauth/types.js +1 -0
- package/dist/pi/ai/utils/overflow.js +150 -0
- package/dist/pi/ai/utils/sanitize-unicode.js +25 -0
- package/dist/pi/ai/utils/typebox-helpers.js +20 -0
- package/dist/pi/ai/utils/validation.js +280 -0
- package/dist/pi/coding-agent/bun/cli.js +7 -0
- package/dist/pi/coding-agent/bun/restore-sandbox-env.js +31 -0
- package/dist/pi/coding-agent/cli/args.js +340 -0
- package/dist/pi/coding-agent/cli/file-processor.js +82 -0
- package/dist/pi/coding-agent/cli/initial-message.js +21 -0
- package/dist/pi/coding-agent/cli.js +17 -0
- package/dist/pi/coding-agent/config.js +414 -0
- package/dist/pi/coding-agent/core/agent-session-runtime.js +299 -0
- package/dist/pi/coding-agent/core/agent-session-services.js +117 -0
- package/dist/pi/coding-agent/core/agent-session.js +2498 -0
- package/dist/pi/coding-agent/core/auth-guidance.js +20 -0
- package/dist/pi/coding-agent/core/auth-storage.js +441 -0
- package/dist/pi/coding-agent/core/bash-executor.js +110 -0
- package/dist/pi/coding-agent/core/compaction/branch-summarization.js +242 -0
- package/dist/pi/coding-agent/core/compaction/compaction.js +624 -0
- package/dist/pi/coding-agent/core/compaction/index.js +6 -0
- package/dist/pi/coding-agent/core/compaction/utils.js +152 -0
- package/dist/pi/coding-agent/core/defaults.js +1 -0
- package/dist/pi/coding-agent/core/diagnostics.js +1 -0
- package/dist/pi/coding-agent/core/event-bus.js +24 -0
- package/dist/pi/coding-agent/core/exec.js +74 -0
- package/dist/pi/coding-agent/core/export-html/ansi-to-html.js +248 -0
- package/dist/pi/coding-agent/core/export-html/index.js +225 -0
- package/dist/pi/coding-agent/core/export-html/tool-renderer.js +107 -0
- package/dist/pi/coding-agent/core/extensions/index.js +8 -0
- package/dist/pi/coding-agent/core/extensions/loader.js +485 -0
- package/dist/pi/coding-agent/core/extensions/runner.js +824 -0
- package/dist/pi/coding-agent/core/extensions/types.js +44 -0
- package/dist/pi/coding-agent/core/extensions/wrapper.js +21 -0
- package/dist/pi/coding-agent/core/footer-data-provider.js +309 -0
- package/dist/pi/coding-agent/core/http-dispatcher.js +47 -0
- package/dist/pi/coding-agent/core/index.js +11 -0
- package/dist/pi/coding-agent/core/keybindings.js +294 -0
- package/dist/pi/coding-agent/core/messages.js +122 -0
- package/dist/pi/coding-agent/core/model-registry.js +728 -0
- package/dist/pi/coding-agent/core/model-resolver.js +494 -0
- package/dist/pi/coding-agent/core/output-guard.js +58 -0
- package/dist/pi/coding-agent/core/package-manager.js +2020 -0
- package/dist/pi/coding-agent/core/prompt-templates.js +237 -0
- package/dist/pi/coding-agent/core/provider-display-names.js +32 -0
- package/dist/pi/coding-agent/core/resolve-config-value.js +125 -0
- package/dist/pi/coding-agent/core/resource-loader.js +733 -0
- package/dist/pi/coding-agent/core/sdk.js +282 -0
- package/dist/pi/coding-agent/core/session-cwd.js +37 -0
- package/dist/pi/coding-agent/core/session-manager.js +1146 -0
- package/dist/pi/coding-agent/core/settings-manager.js +794 -0
- package/dist/pi/coding-agent/core/skills.js +386 -0
- package/dist/pi/coding-agent/core/slash-commands.js +24 -0
- package/dist/pi/coding-agent/core/source-info.js +18 -0
- package/dist/pi/coding-agent/core/system-prompt.js +122 -0
- package/dist/pi/coding-agent/core/telemetry.js +8 -0
- package/dist/pi/coding-agent/core/timings.js +30 -0
- package/dist/pi/coding-agent/core/tools/bash.js +341 -0
- package/dist/pi/coding-agent/core/tools/edit-diff.js +344 -0
- package/dist/pi/coding-agent/core/tools/edit.js +324 -0
- package/dist/pi/coding-agent/core/tools/file-mutation-queue.js +36 -0
- package/dist/pi/coding-agent/core/tools/find.js +297 -0
- package/dist/pi/coding-agent/core/tools/grep.js +303 -0
- package/dist/pi/coding-agent/core/tools/index.js +111 -0
- package/dist/pi/coding-agent/core/tools/ls.js +168 -0
- package/dist/pi/coding-agent/core/tools/output-accumulator.js +183 -0
- package/dist/pi/coding-agent/core/tools/path-utils.js +61 -0
- package/dist/pi/coding-agent/core/tools/read.js +288 -0
- package/dist/pi/coding-agent/core/tools/render-utils.js +48 -0
- package/dist/pi/coding-agent/core/tools/tool-definition-wrapper.js +33 -0
- package/dist/pi/coding-agent/core/tools/truncate.js +214 -0
- package/dist/pi/coding-agent/core/tools/write.js +212 -0
- package/dist/pi/coding-agent/index.js +41 -0
- package/dist/pi/coding-agent/main.js +5 -0
- package/dist/pi/coding-agent/migrations.js +280 -0
- package/dist/pi/coding-agent/modes/index.js +7 -0
- package/dist/pi/coding-agent/modes/interactive/components/diff.js +132 -0
- package/dist/pi/coding-agent/modes/interactive/components/keybinding-hints.js +35 -0
- package/dist/pi/coding-agent/modes/interactive/components/visual-truncate.js +32 -0
- package/dist/pi/coding-agent/modes/interactive/interactive-mode.js +3 -0
- package/dist/pi/coding-agent/modes/interactive/theme/theme.js +1023 -0
- package/dist/pi/coding-agent/modes/print-mode.js +130 -0
- package/dist/pi/coding-agent/modes/rpc/jsonl.js +48 -0
- package/dist/pi/coding-agent/modes/rpc/rpc-client.js +409 -0
- package/dist/pi/coding-agent/modes/rpc/rpc-mode.js +600 -0
- package/dist/pi/coding-agent/modes/rpc/rpc-types.js +7 -0
- package/dist/pi/coding-agent/utils/ansi.js +51 -0
- package/dist/pi/coding-agent/utils/changelog.js +86 -0
- package/dist/pi/coding-agent/utils/child-process.js +87 -0
- package/dist/pi/coding-agent/utils/clipboard-image.js +244 -0
- package/dist/pi/coding-agent/utils/clipboard-native.js +13 -0
- package/dist/pi/coding-agent/utils/clipboard.js +116 -0
- package/dist/pi/coding-agent/utils/exif-orientation.js +157 -0
- package/dist/pi/coding-agent/utils/frontmatter.js +25 -0
- package/dist/pi/coding-agent/utils/fs-watch.js +24 -0
- package/dist/pi/coding-agent/utils/git.js +162 -0
- package/dist/pi/coding-agent/utils/html.js +39 -0
- package/dist/pi/coding-agent/utils/image-convert.js +38 -0
- package/dist/pi/coding-agent/utils/image-resize.js +136 -0
- package/dist/pi/coding-agent/utils/mime.js +68 -0
- package/dist/pi/coding-agent/utils/paths.js +91 -0
- package/dist/pi/coding-agent/utils/photon.js +120 -0
- package/dist/pi/coding-agent/utils/pi-user-agent.js +4 -0
- package/dist/pi/coding-agent/utils/shell.js +194 -0
- package/dist/pi/coding-agent/utils/sleep.js +16 -0
- package/dist/pi/coding-agent/utils/syntax-highlight.js +117 -0
- package/dist/pi/coding-agent/utils/tools-manager.js +327 -0
- package/dist/pi/coding-agent/utils/version-check.js +81 -0
- package/dist/pi/coding-agent/utils/windows-self-update.js +76 -0
- package/dist/pi/tui/autocomplete.js +631 -0
- package/dist/pi/tui/components/box.js +103 -0
- package/dist/pi/tui/components/cancellable-loader.js +34 -0
- package/dist/pi/tui/components/editor.js +1915 -0
- package/dist/pi/tui/components/image.js +88 -0
- package/dist/pi/tui/components/input.js +425 -0
- package/dist/pi/tui/components/loader.js +68 -0
- package/dist/pi/tui/components/markdown.js +633 -0
- package/dist/pi/tui/components/select-list.js +158 -0
- package/dist/pi/tui/components/settings-list.js +184 -0
- package/dist/pi/tui/components/spacer.js +22 -0
- package/dist/pi/tui/components/text.js +88 -0
- package/dist/pi/tui/components/truncated-text.js +50 -0
- package/dist/pi/tui/editor-component.js +1 -0
- package/dist/pi/tui/fuzzy.js +109 -0
- package/dist/pi/tui/index.js +31 -0
- package/dist/pi/tui/keybindings.js +173 -0
- package/dist/pi/tui/keys.js +1172 -0
- package/dist/pi/tui/kill-ring.js +43 -0
- package/dist/pi/tui/stdin-buffer.js +360 -0
- package/dist/pi/tui/terminal-image.js +335 -0
- package/dist/pi/tui/terminal.js +324 -0
- package/dist/pi/tui/tui.js +1076 -0
- package/dist/pi/tui/undo-stack.js +24 -0
- package/dist/pi/tui/utils.js +1016 -0
- package/dist/server/pi-bridge.js +156 -6
- package/dist/server/session-stream.js +53 -112
- package/dist/server/storage.js +62 -1
- package/dist/server/title-generator.js +14 -153
- package/package.json +24 -6
|
@@ -0,0 +1,945 @@
|
|
|
1
|
+
import OpenAI from "openai";
|
|
2
|
+
import { getEnvApiKey } from "../env-api-keys.js";
|
|
3
|
+
import { calculateCost, clampThinkingLevel } from "../models.js";
|
|
4
|
+
import { AssistantMessageEventStream } from "../utils/event-stream.js";
|
|
5
|
+
import { headersToRecord } from "../utils/headers.js";
|
|
6
|
+
import { parseStreamingJson } from "../utils/json-parse.js";
|
|
7
|
+
import { sanitizeSurrogates } from "../utils/sanitize-unicode.js";
|
|
8
|
+
import { buildCopilotDynamicHeaders, hasCopilotVisionInput } from "./github-copilot-headers.js";
|
|
9
|
+
import { clampOpenAIPromptCacheKey } from "./openai-prompt-cache.js";
|
|
10
|
+
import { buildBaseOptions } from "./simple-options.js";
|
|
11
|
+
import { transformMessages } from "./transform-messages.js";
|
|
12
|
+
/**
|
|
13
|
+
* Check if conversation messages contain tool calls or tool results.
|
|
14
|
+
* This is needed because Anthropic (via proxy) requires the tools param
|
|
15
|
+
* to be present when messages include tool_calls or tool role messages.
|
|
16
|
+
*/
|
|
17
|
+
function hasToolHistory(messages) {
|
|
18
|
+
for (const msg of messages) {
|
|
19
|
+
if (msg.role === "toolResult") {
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
if (msg.role === "assistant") {
|
|
23
|
+
if (msg.content.some((block) => block.type === "toolCall")) {
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
function isTextContentBlock(block) {
|
|
31
|
+
return block.type === "text";
|
|
32
|
+
}
|
|
33
|
+
function isThinkingContentBlock(block) {
|
|
34
|
+
return block.type === "thinking";
|
|
35
|
+
}
|
|
36
|
+
function isToolCallBlock(block) {
|
|
37
|
+
return block.type === "toolCall";
|
|
38
|
+
}
|
|
39
|
+
function isImageContentBlock(block) {
|
|
40
|
+
return block.type === "image";
|
|
41
|
+
}
|
|
42
|
+
function resolveCacheRetention(cacheRetention) {
|
|
43
|
+
if (cacheRetention) {
|
|
44
|
+
return cacheRetention;
|
|
45
|
+
}
|
|
46
|
+
if (typeof process !== "undefined" && process.env.PI_CACHE_RETENTION === "long") {
|
|
47
|
+
return "long";
|
|
48
|
+
}
|
|
49
|
+
return "short";
|
|
50
|
+
}
|
|
51
|
+
export const streamOpenAICompletions = (model, context, options) => {
|
|
52
|
+
const stream = new AssistantMessageEventStream();
|
|
53
|
+
(async () => {
|
|
54
|
+
const output = {
|
|
55
|
+
role: "assistant",
|
|
56
|
+
content: [],
|
|
57
|
+
api: model.api,
|
|
58
|
+
provider: model.provider,
|
|
59
|
+
model: model.id,
|
|
60
|
+
usage: {
|
|
61
|
+
input: 0,
|
|
62
|
+
output: 0,
|
|
63
|
+
cacheRead: 0,
|
|
64
|
+
cacheWrite: 0,
|
|
65
|
+
totalTokens: 0,
|
|
66
|
+
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },
|
|
67
|
+
},
|
|
68
|
+
stopReason: "stop",
|
|
69
|
+
timestamp: Date.now(),
|
|
70
|
+
};
|
|
71
|
+
try {
|
|
72
|
+
const apiKey = options?.apiKey || getEnvApiKey(model.provider) || "";
|
|
73
|
+
const compat = getCompat(model);
|
|
74
|
+
const cacheRetention = resolveCacheRetention(options?.cacheRetention);
|
|
75
|
+
const cacheSessionId = cacheRetention === "none" ? undefined : options?.sessionId;
|
|
76
|
+
const client = createClient(model, context, apiKey, options?.headers, cacheSessionId, compat);
|
|
77
|
+
let params = buildParams(model, context, options, compat, cacheRetention);
|
|
78
|
+
const nextParams = await options?.onPayload?.(params, model);
|
|
79
|
+
if (nextParams !== undefined) {
|
|
80
|
+
params = nextParams;
|
|
81
|
+
}
|
|
82
|
+
const requestOptions = {
|
|
83
|
+
...(options?.signal ? { signal: options.signal } : {}),
|
|
84
|
+
...(options?.timeoutMs !== undefined ? { timeout: options.timeoutMs } : {}),
|
|
85
|
+
...(options?.maxRetries !== undefined ? { maxRetries: options.maxRetries } : {}),
|
|
86
|
+
};
|
|
87
|
+
const { data: openaiStream, response } = await client.chat.completions
|
|
88
|
+
.create(params, requestOptions)
|
|
89
|
+
.withResponse();
|
|
90
|
+
await options?.onResponse?.({ status: response.status, headers: headersToRecord(response.headers) }, model);
|
|
91
|
+
stream.push({ type: "start", partial: output });
|
|
92
|
+
let textBlock = null;
|
|
93
|
+
let thinkingBlock = null;
|
|
94
|
+
let hasFinishReason = false;
|
|
95
|
+
const toolCallBlocksByIndex = new Map();
|
|
96
|
+
const toolCallBlocksById = new Map();
|
|
97
|
+
const blocks = output.content;
|
|
98
|
+
const getContentIndex = (block) => blocks.indexOf(block);
|
|
99
|
+
const finishBlock = (block) => {
|
|
100
|
+
const contentIndex = getContentIndex(block);
|
|
101
|
+
if (contentIndex === -1) {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
if (block.type === "text") {
|
|
105
|
+
stream.push({
|
|
106
|
+
type: "text_end",
|
|
107
|
+
contentIndex,
|
|
108
|
+
content: block.text,
|
|
109
|
+
partial: output,
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
else if (block.type === "thinking") {
|
|
113
|
+
stream.push({
|
|
114
|
+
type: "thinking_end",
|
|
115
|
+
contentIndex,
|
|
116
|
+
content: block.thinking,
|
|
117
|
+
partial: output,
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
else if (block.type === "toolCall") {
|
|
121
|
+
block.arguments = parseStreamingJson(block.partialArgs);
|
|
122
|
+
// Finalize in-place and strip the scratch buffers so replay only
|
|
123
|
+
// carries parsed arguments.
|
|
124
|
+
delete block.partialArgs;
|
|
125
|
+
delete block.streamIndex;
|
|
126
|
+
stream.push({
|
|
127
|
+
type: "toolcall_end",
|
|
128
|
+
contentIndex,
|
|
129
|
+
toolCall: block,
|
|
130
|
+
partial: output,
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
const ensureTextBlock = () => {
|
|
135
|
+
if (!textBlock) {
|
|
136
|
+
textBlock = { type: "text", text: "" };
|
|
137
|
+
blocks.push(textBlock);
|
|
138
|
+
stream.push({ type: "text_start", contentIndex: getContentIndex(textBlock), partial: output });
|
|
139
|
+
}
|
|
140
|
+
return textBlock;
|
|
141
|
+
};
|
|
142
|
+
const ensureThinkingBlock = (thinkingSignature) => {
|
|
143
|
+
if (!thinkingBlock) {
|
|
144
|
+
thinkingBlock = {
|
|
145
|
+
type: "thinking",
|
|
146
|
+
thinking: "",
|
|
147
|
+
thinkingSignature,
|
|
148
|
+
};
|
|
149
|
+
blocks.push(thinkingBlock);
|
|
150
|
+
stream.push({ type: "thinking_start", contentIndex: getContentIndex(thinkingBlock), partial: output });
|
|
151
|
+
}
|
|
152
|
+
return thinkingBlock;
|
|
153
|
+
};
|
|
154
|
+
const ensureToolCallBlock = (toolCall) => {
|
|
155
|
+
const streamIndex = typeof toolCall.index === "number" ? toolCall.index : undefined;
|
|
156
|
+
let block = streamIndex !== undefined ? toolCallBlocksByIndex.get(streamIndex) : undefined;
|
|
157
|
+
if (!block && toolCall.id) {
|
|
158
|
+
block = toolCallBlocksById.get(toolCall.id);
|
|
159
|
+
}
|
|
160
|
+
if (!block) {
|
|
161
|
+
block = {
|
|
162
|
+
type: "toolCall",
|
|
163
|
+
id: toolCall.id || "",
|
|
164
|
+
name: toolCall.function?.name || "",
|
|
165
|
+
arguments: {},
|
|
166
|
+
partialArgs: "",
|
|
167
|
+
streamIndex,
|
|
168
|
+
};
|
|
169
|
+
if (streamIndex !== undefined) {
|
|
170
|
+
toolCallBlocksByIndex.set(streamIndex, block);
|
|
171
|
+
}
|
|
172
|
+
if (toolCall.id) {
|
|
173
|
+
toolCallBlocksById.set(toolCall.id, block);
|
|
174
|
+
}
|
|
175
|
+
blocks.push(block);
|
|
176
|
+
stream.push({
|
|
177
|
+
type: "toolcall_start",
|
|
178
|
+
contentIndex: getContentIndex(block),
|
|
179
|
+
partial: output,
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
if (streamIndex !== undefined && block.streamIndex === undefined) {
|
|
183
|
+
block.streamIndex = streamIndex;
|
|
184
|
+
toolCallBlocksByIndex.set(streamIndex, block);
|
|
185
|
+
}
|
|
186
|
+
if (toolCall.id) {
|
|
187
|
+
toolCallBlocksById.set(toolCall.id, block);
|
|
188
|
+
}
|
|
189
|
+
return block;
|
|
190
|
+
};
|
|
191
|
+
for await (const chunk of openaiStream) {
|
|
192
|
+
if (!chunk || typeof chunk !== "object")
|
|
193
|
+
continue;
|
|
194
|
+
// OpenAI documents ChatCompletionChunk.id as the unique chat completion identifier,
|
|
195
|
+
// and each chunk in a streamed completion carries the same id.
|
|
196
|
+
output.responseId ||= chunk.id;
|
|
197
|
+
if (typeof chunk.model === "string" && chunk.model.length > 0 && chunk.model !== model.id) {
|
|
198
|
+
output.responseModel ||= chunk.model;
|
|
199
|
+
}
|
|
200
|
+
if (chunk.usage) {
|
|
201
|
+
output.usage = parseChunkUsage(chunk.usage, model);
|
|
202
|
+
}
|
|
203
|
+
const choice = Array.isArray(chunk.choices) ? chunk.choices[0] : undefined;
|
|
204
|
+
if (!choice)
|
|
205
|
+
continue;
|
|
206
|
+
// Fallback: some providers (e.g., Moonshot) return usage
|
|
207
|
+
// in choice.usage instead of the standard chunk.usage
|
|
208
|
+
if (!chunk.usage && choice.usage) {
|
|
209
|
+
output.usage = parseChunkUsage(choice.usage, model);
|
|
210
|
+
}
|
|
211
|
+
if (choice.finish_reason) {
|
|
212
|
+
const finishReasonResult = mapStopReason(choice.finish_reason);
|
|
213
|
+
output.stopReason = finishReasonResult.stopReason;
|
|
214
|
+
if (finishReasonResult.errorMessage) {
|
|
215
|
+
output.errorMessage = finishReasonResult.errorMessage;
|
|
216
|
+
}
|
|
217
|
+
hasFinishReason = true;
|
|
218
|
+
}
|
|
219
|
+
if (choice.delta) {
|
|
220
|
+
if (choice.delta.content !== null &&
|
|
221
|
+
choice.delta.content !== undefined &&
|
|
222
|
+
choice.delta.content.length > 0) {
|
|
223
|
+
const block = ensureTextBlock();
|
|
224
|
+
block.text += choice.delta.content;
|
|
225
|
+
stream.push({
|
|
226
|
+
type: "text_delta",
|
|
227
|
+
contentIndex: getContentIndex(block),
|
|
228
|
+
delta: choice.delta.content,
|
|
229
|
+
partial: output,
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
// Some endpoints return reasoning in reasoning_content (llama.cpp),
|
|
233
|
+
// or reasoning (other openai compatible endpoints)
|
|
234
|
+
// Use the first non-empty reasoning field to avoid duplication
|
|
235
|
+
// (e.g., chutes.ai returns both reasoning_content and reasoning with same content)
|
|
236
|
+
const reasoningFields = ["reasoning_content", "reasoning", "reasoning_text"];
|
|
237
|
+
const deltaFields = choice.delta;
|
|
238
|
+
let foundReasoningField = null;
|
|
239
|
+
for (const field of reasoningFields) {
|
|
240
|
+
const value = deltaFields[field];
|
|
241
|
+
if (typeof value === "string" && value.length > 0) {
|
|
242
|
+
foundReasoningField = field;
|
|
243
|
+
break;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
if (foundReasoningField) {
|
|
247
|
+
const delta = deltaFields[foundReasoningField];
|
|
248
|
+
if (typeof delta === "string" && delta.length > 0) {
|
|
249
|
+
const thinkingSignature = model.provider === "opencode-go" && foundReasoningField === "reasoning"
|
|
250
|
+
? "reasoning_content"
|
|
251
|
+
: foundReasoningField;
|
|
252
|
+
const block = ensureThinkingBlock(thinkingSignature);
|
|
253
|
+
block.thinking += delta;
|
|
254
|
+
stream.push({
|
|
255
|
+
type: "thinking_delta",
|
|
256
|
+
contentIndex: getContentIndex(block),
|
|
257
|
+
delta,
|
|
258
|
+
partial: output,
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
if (choice?.delta?.tool_calls) {
|
|
263
|
+
for (const toolCall of choice.delta.tool_calls) {
|
|
264
|
+
const block = ensureToolCallBlock(toolCall);
|
|
265
|
+
if (!block.id && toolCall.id) {
|
|
266
|
+
block.id = toolCall.id;
|
|
267
|
+
toolCallBlocksById.set(toolCall.id, block);
|
|
268
|
+
}
|
|
269
|
+
if (!block.name && toolCall.function?.name) {
|
|
270
|
+
block.name = toolCall.function.name;
|
|
271
|
+
}
|
|
272
|
+
let delta = "";
|
|
273
|
+
if (toolCall.function?.arguments) {
|
|
274
|
+
delta = toolCall.function.arguments;
|
|
275
|
+
block.partialArgs = (block.partialArgs ?? "") + toolCall.function.arguments;
|
|
276
|
+
block.arguments = parseStreamingJson(block.partialArgs);
|
|
277
|
+
}
|
|
278
|
+
stream.push({
|
|
279
|
+
type: "toolcall_delta",
|
|
280
|
+
contentIndex: getContentIndex(block),
|
|
281
|
+
delta,
|
|
282
|
+
partial: output,
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
const reasoningDetails = choice.delta.reasoning_details;
|
|
287
|
+
if (reasoningDetails && Array.isArray(reasoningDetails)) {
|
|
288
|
+
for (const detail of reasoningDetails) {
|
|
289
|
+
if (detail.type === "reasoning.encrypted" && detail.id && detail.data) {
|
|
290
|
+
const matchingToolCall = output.content.find((b) => b.type === "toolCall" && b.id === detail.id);
|
|
291
|
+
if (matchingToolCall) {
|
|
292
|
+
matchingToolCall.thoughtSignature = JSON.stringify(detail);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
for (const block of blocks) {
|
|
300
|
+
finishBlock(block);
|
|
301
|
+
}
|
|
302
|
+
if (options?.signal?.aborted) {
|
|
303
|
+
throw new Error("Request was aborted");
|
|
304
|
+
}
|
|
305
|
+
if (output.stopReason === "aborted") {
|
|
306
|
+
throw new Error("Request was aborted");
|
|
307
|
+
}
|
|
308
|
+
if (output.stopReason === "error") {
|
|
309
|
+
throw new Error(output.errorMessage || "Provider returned an error stop reason");
|
|
310
|
+
}
|
|
311
|
+
if (!hasFinishReason) {
|
|
312
|
+
throw new Error("Stream ended without finish_reason");
|
|
313
|
+
}
|
|
314
|
+
stream.push({ type: "done", reason: output.stopReason, message: output });
|
|
315
|
+
stream.end();
|
|
316
|
+
}
|
|
317
|
+
catch (error) {
|
|
318
|
+
for (const block of output.content) {
|
|
319
|
+
delete block.index;
|
|
320
|
+
// Streaming scratch buffers are only used during parsing; never persist them.
|
|
321
|
+
delete block.partialArgs;
|
|
322
|
+
delete block.streamIndex;
|
|
323
|
+
}
|
|
324
|
+
output.stopReason = options?.signal?.aborted ? "aborted" : "error";
|
|
325
|
+
output.errorMessage = error instanceof Error ? error.message : JSON.stringify(error);
|
|
326
|
+
// Some providers via OpenRouter give additional information in this field.
|
|
327
|
+
const rawMetadata = error?.error?.metadata?.raw;
|
|
328
|
+
if (rawMetadata)
|
|
329
|
+
output.errorMessage += `\n${rawMetadata}`;
|
|
330
|
+
stream.push({ type: "error", reason: output.stopReason, error: output });
|
|
331
|
+
stream.end();
|
|
332
|
+
}
|
|
333
|
+
})();
|
|
334
|
+
return stream;
|
|
335
|
+
};
|
|
336
|
+
export const streamSimpleOpenAICompletions = (model, context, options) => {
|
|
337
|
+
const apiKey = options?.apiKey || getEnvApiKey(model.provider);
|
|
338
|
+
if (!apiKey) {
|
|
339
|
+
throw new Error(`No API key for provider: ${model.provider}`);
|
|
340
|
+
}
|
|
341
|
+
const base = buildBaseOptions(model, options, apiKey);
|
|
342
|
+
const clampedReasoning = options?.reasoning ? clampThinkingLevel(model, options.reasoning) : undefined;
|
|
343
|
+
const reasoningEffort = clampedReasoning === "off" ? undefined : clampedReasoning;
|
|
344
|
+
const toolChoice = options?.toolChoice;
|
|
345
|
+
return streamOpenAICompletions(model, context, {
|
|
346
|
+
...base,
|
|
347
|
+
reasoningEffort,
|
|
348
|
+
toolChoice,
|
|
349
|
+
});
|
|
350
|
+
};
|
|
351
|
+
function createClient(model, context, apiKey, optionsHeaders, sessionId, compat = getCompat(model)) {
|
|
352
|
+
if (!apiKey) {
|
|
353
|
+
if (!process.env.OPENAI_API_KEY) {
|
|
354
|
+
throw new Error("OpenAI API key is required. Set OPENAI_API_KEY environment variable or pass it as an argument.");
|
|
355
|
+
}
|
|
356
|
+
apiKey = process.env.OPENAI_API_KEY;
|
|
357
|
+
}
|
|
358
|
+
const headers = { ...model.headers };
|
|
359
|
+
if (model.provider === "github-copilot") {
|
|
360
|
+
const hasImages = hasCopilotVisionInput(context.messages);
|
|
361
|
+
const copilotHeaders = buildCopilotDynamicHeaders({
|
|
362
|
+
messages: context.messages,
|
|
363
|
+
hasImages,
|
|
364
|
+
});
|
|
365
|
+
Object.assign(headers, copilotHeaders);
|
|
366
|
+
}
|
|
367
|
+
if (sessionId && compat.sendSessionAffinityHeaders) {
|
|
368
|
+
headers.session_id = sessionId;
|
|
369
|
+
headers["x-client-request-id"] = sessionId;
|
|
370
|
+
headers["x-session-affinity"] = sessionId;
|
|
371
|
+
}
|
|
372
|
+
// Merge options headers last so they can override defaults
|
|
373
|
+
if (optionsHeaders) {
|
|
374
|
+
Object.assign(headers, optionsHeaders);
|
|
375
|
+
}
|
|
376
|
+
const defaultHeaders = headers;
|
|
377
|
+
return new OpenAI({
|
|
378
|
+
apiKey,
|
|
379
|
+
baseURL: model.baseUrl,
|
|
380
|
+
dangerouslyAllowBrowser: true,
|
|
381
|
+
defaultHeaders,
|
|
382
|
+
});
|
|
383
|
+
}
|
|
384
|
+
function buildParams(model, context, options, compat = getCompat(model), cacheRetention = resolveCacheRetention(options?.cacheRetention)) {
|
|
385
|
+
const messages = convertMessages(model, context, compat);
|
|
386
|
+
const cacheControl = getCompatCacheControl(compat, cacheRetention);
|
|
387
|
+
const params = {
|
|
388
|
+
model: model.id,
|
|
389
|
+
messages,
|
|
390
|
+
stream: true,
|
|
391
|
+
prompt_cache_key: (model.baseUrl.includes("api.openai.com") && cacheRetention !== "none") ||
|
|
392
|
+
(cacheRetention === "long" && compat.supportsLongCacheRetention)
|
|
393
|
+
? clampOpenAIPromptCacheKey(options?.sessionId)
|
|
394
|
+
: undefined,
|
|
395
|
+
};
|
|
396
|
+
if (cacheRetention === "long" && compat.supportsLongCacheRetention) {
|
|
397
|
+
params.prompt_cache_retention = "24h";
|
|
398
|
+
}
|
|
399
|
+
if (compat.supportsUsageInStreaming !== false) {
|
|
400
|
+
params.stream_options = { include_usage: true };
|
|
401
|
+
}
|
|
402
|
+
if (compat.supportsStore) {
|
|
403
|
+
params.store = false;
|
|
404
|
+
}
|
|
405
|
+
if (options?.maxTokens) {
|
|
406
|
+
if (compat.maxTokensField === "max_tokens") {
|
|
407
|
+
params.max_tokens = options.maxTokens;
|
|
408
|
+
}
|
|
409
|
+
else {
|
|
410
|
+
params.max_completion_tokens = options.maxTokens;
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
if (options?.temperature !== undefined) {
|
|
414
|
+
params.temperature = options.temperature;
|
|
415
|
+
}
|
|
416
|
+
if (context.tools && context.tools.length > 0) {
|
|
417
|
+
params.tools = convertTools(context.tools, compat);
|
|
418
|
+
if (compat.zaiToolStream) {
|
|
419
|
+
params.tool_stream = true;
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
else if (hasToolHistory(context.messages)) {
|
|
423
|
+
// Anthropic (via LiteLLM/proxy) requires tools param when conversation has tool_calls/tool_results
|
|
424
|
+
params.tools = [];
|
|
425
|
+
}
|
|
426
|
+
if (cacheControl) {
|
|
427
|
+
applyAnthropicCacheControl(messages, params.tools, cacheControl);
|
|
428
|
+
}
|
|
429
|
+
if (options?.toolChoice) {
|
|
430
|
+
params.tool_choice = options.toolChoice;
|
|
431
|
+
}
|
|
432
|
+
if (compat.thinkingFormat === "zai" && model.reasoning) {
|
|
433
|
+
params.enable_thinking = !!options?.reasoningEffort;
|
|
434
|
+
}
|
|
435
|
+
else if (compat.thinkingFormat === "qwen" && model.reasoning) {
|
|
436
|
+
params.enable_thinking = !!options?.reasoningEffort;
|
|
437
|
+
}
|
|
438
|
+
else if (compat.thinkingFormat === "qwen-chat-template" && model.reasoning) {
|
|
439
|
+
params.chat_template_kwargs = {
|
|
440
|
+
enable_thinking: !!options?.reasoningEffort,
|
|
441
|
+
preserve_thinking: true,
|
|
442
|
+
};
|
|
443
|
+
}
|
|
444
|
+
else if (compat.thinkingFormat === "deepseek" && model.reasoning) {
|
|
445
|
+
params.thinking = { type: options?.reasoningEffort ? "enabled" : "disabled" };
|
|
446
|
+
if (options?.reasoningEffort) {
|
|
447
|
+
params.reasoning_effort =
|
|
448
|
+
model.thinkingLevelMap?.[options.reasoningEffort] ?? options.reasoningEffort;
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
else if (compat.thinkingFormat === "openrouter" && model.reasoning) {
|
|
452
|
+
// OpenRouter normalizes reasoning across providers via a nested reasoning object.
|
|
453
|
+
const openRouterParams = params;
|
|
454
|
+
if (options?.reasoningEffort) {
|
|
455
|
+
openRouterParams.reasoning = {
|
|
456
|
+
effort: model.thinkingLevelMap?.[options.reasoningEffort] ?? options.reasoningEffort,
|
|
457
|
+
};
|
|
458
|
+
}
|
|
459
|
+
else if (model.thinkingLevelMap?.off !== null) {
|
|
460
|
+
openRouterParams.reasoning = { effort: model.thinkingLevelMap?.off ?? "none" };
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
else if (compat.thinkingFormat === "together" && model.reasoning) {
|
|
464
|
+
const togetherParams = params;
|
|
465
|
+
togetherParams.reasoning = { enabled: !!options?.reasoningEffort };
|
|
466
|
+
if (options?.reasoningEffort && compat.supportsReasoningEffort) {
|
|
467
|
+
togetherParams.reasoning_effort = model.thinkingLevelMap?.[options.reasoningEffort] ?? options.reasoningEffort;
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
else if (options?.reasoningEffort && model.reasoning && compat.supportsReasoningEffort) {
|
|
471
|
+
// OpenAI-style reasoning_effort
|
|
472
|
+
params.reasoning_effort = model.thinkingLevelMap?.[options.reasoningEffort] ?? options.reasoningEffort;
|
|
473
|
+
}
|
|
474
|
+
else if (!options?.reasoningEffort && model.reasoning && compat.supportsReasoningEffort) {
|
|
475
|
+
const offValue = model.thinkingLevelMap?.off;
|
|
476
|
+
if (typeof offValue === "string") {
|
|
477
|
+
params.reasoning_effort = offValue;
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
// OpenRouter provider routing preferences
|
|
481
|
+
if (model.baseUrl.includes("openrouter.ai") && model.compat?.openRouterRouting) {
|
|
482
|
+
params.provider = model.compat.openRouterRouting;
|
|
483
|
+
}
|
|
484
|
+
// Vercel AI Gateway provider routing preferences
|
|
485
|
+
if (model.baseUrl.includes("ai-gateway.vercel.sh") && model.compat?.vercelGatewayRouting) {
|
|
486
|
+
const routing = model.compat.vercelGatewayRouting;
|
|
487
|
+
if (routing.only || routing.order) {
|
|
488
|
+
const gatewayOptions = {};
|
|
489
|
+
if (routing.only)
|
|
490
|
+
gatewayOptions.only = routing.only;
|
|
491
|
+
if (routing.order)
|
|
492
|
+
gatewayOptions.order = routing.order;
|
|
493
|
+
params.providerOptions = { gateway: gatewayOptions };
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
return params;
|
|
497
|
+
}
|
|
498
|
+
function getCompatCacheControl(compat, cacheRetention) {
|
|
499
|
+
if (compat.cacheControlFormat !== "anthropic" || cacheRetention === "none") {
|
|
500
|
+
return undefined;
|
|
501
|
+
}
|
|
502
|
+
const ttl = cacheRetention === "long" && compat.supportsLongCacheRetention ? "1h" : undefined;
|
|
503
|
+
return { type: "ephemeral", ...(ttl ? { ttl } : {}) };
|
|
504
|
+
}
|
|
505
|
+
function applyAnthropicCacheControl(messages, tools, cacheControl) {
|
|
506
|
+
addCacheControlToSystemPrompt(messages, cacheControl);
|
|
507
|
+
addCacheControlToLastTool(tools, cacheControl);
|
|
508
|
+
addCacheControlToLastConversationMessage(messages, cacheControl);
|
|
509
|
+
}
|
|
510
|
+
function addCacheControlToSystemPrompt(messages, cacheControl) {
|
|
511
|
+
for (const message of messages) {
|
|
512
|
+
if (message.role === "system" || message.role === "developer") {
|
|
513
|
+
addCacheControlToInstructionMessage(message, cacheControl);
|
|
514
|
+
return;
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
function addCacheControlToLastConversationMessage(messages, cacheControl) {
|
|
519
|
+
for (let i = messages.length - 1; i >= 0; i--) {
|
|
520
|
+
const message = messages[i];
|
|
521
|
+
if (message.role === "user" || message.role === "assistant") {
|
|
522
|
+
if (addCacheControlToMessage(message, cacheControl)) {
|
|
523
|
+
return;
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
function addCacheControlToLastTool(tools, cacheControl) {
|
|
529
|
+
if (!tools || tools.length === 0) {
|
|
530
|
+
return;
|
|
531
|
+
}
|
|
532
|
+
const lastTool = tools[tools.length - 1];
|
|
533
|
+
lastTool.cache_control = cacheControl;
|
|
534
|
+
}
|
|
535
|
+
function addCacheControlToInstructionMessage(message, cacheControl) {
|
|
536
|
+
return addCacheControlToTextContent(message, cacheControl);
|
|
537
|
+
}
|
|
538
|
+
function addCacheControlToMessage(message, cacheControl) {
|
|
539
|
+
if (message.role === "user" || message.role === "assistant") {
|
|
540
|
+
return addCacheControlToTextContent(message, cacheControl);
|
|
541
|
+
}
|
|
542
|
+
return false;
|
|
543
|
+
}
|
|
544
|
+
function addCacheControlToTextContent(message, cacheControl) {
|
|
545
|
+
const content = message.content;
|
|
546
|
+
if (typeof content === "string") {
|
|
547
|
+
if (content.length === 0) {
|
|
548
|
+
return false;
|
|
549
|
+
}
|
|
550
|
+
message.content = [
|
|
551
|
+
{
|
|
552
|
+
type: "text",
|
|
553
|
+
text: content,
|
|
554
|
+
cache_control: cacheControl,
|
|
555
|
+
},
|
|
556
|
+
];
|
|
557
|
+
return true;
|
|
558
|
+
}
|
|
559
|
+
if (!Array.isArray(content)) {
|
|
560
|
+
return false;
|
|
561
|
+
}
|
|
562
|
+
for (let i = content.length - 1; i >= 0; i--) {
|
|
563
|
+
const part = content[i];
|
|
564
|
+
if (part?.type === "text") {
|
|
565
|
+
const textPart = part;
|
|
566
|
+
textPart.cache_control = cacheControl;
|
|
567
|
+
return true;
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
return false;
|
|
571
|
+
}
|
|
572
|
+
export function convertMessages(model, context, compat) {
|
|
573
|
+
const params = [];
|
|
574
|
+
const normalizeToolCallId = (id) => {
|
|
575
|
+
// Handle pipe-separated IDs from OpenAI Responses API
|
|
576
|
+
// Format: {call_id}|{id} where {id} can be 400+ chars with special chars (+, /, =)
|
|
577
|
+
// These come from providers like github-copilot, openai-codex, opencode
|
|
578
|
+
// Extract just the call_id part and normalize it
|
|
579
|
+
if (id.includes("|")) {
|
|
580
|
+
const [callId] = id.split("|");
|
|
581
|
+
// Sanitize to allowed chars and truncate to 40 chars (OpenAI limit)
|
|
582
|
+
return callId.replace(/[^a-zA-Z0-9_-]/g, "_").slice(0, 40);
|
|
583
|
+
}
|
|
584
|
+
if (model.provider === "openai")
|
|
585
|
+
return id.length > 40 ? id.slice(0, 40) : id;
|
|
586
|
+
return id;
|
|
587
|
+
};
|
|
588
|
+
const transformedMessages = transformMessages(context.messages, model, (id) => normalizeToolCallId(id));
|
|
589
|
+
if (context.systemPrompt) {
|
|
590
|
+
const useDeveloperRole = model.reasoning && compat.supportsDeveloperRole;
|
|
591
|
+
const role = useDeveloperRole ? "developer" : "system";
|
|
592
|
+
params.push({ role: role, content: sanitizeSurrogates(context.systemPrompt) });
|
|
593
|
+
}
|
|
594
|
+
let lastRole = null;
|
|
595
|
+
for (let i = 0; i < transformedMessages.length; i++) {
|
|
596
|
+
const msg = transformedMessages[i];
|
|
597
|
+
// Some providers don't allow user messages directly after tool results
|
|
598
|
+
// Insert a synthetic assistant message to bridge the gap
|
|
599
|
+
if (compat.requiresAssistantAfterToolResult && lastRole === "toolResult" && msg.role === "user") {
|
|
600
|
+
params.push({
|
|
601
|
+
role: "assistant",
|
|
602
|
+
content: "I have processed the tool results.",
|
|
603
|
+
});
|
|
604
|
+
}
|
|
605
|
+
if (msg.role === "user") {
|
|
606
|
+
if (typeof msg.content === "string") {
|
|
607
|
+
params.push({
|
|
608
|
+
role: "user",
|
|
609
|
+
content: sanitizeSurrogates(msg.content),
|
|
610
|
+
});
|
|
611
|
+
}
|
|
612
|
+
else {
|
|
613
|
+
const content = msg.content.map((item) => {
|
|
614
|
+
if (item.type === "text") {
|
|
615
|
+
return {
|
|
616
|
+
type: "text",
|
|
617
|
+
text: sanitizeSurrogates(item.text),
|
|
618
|
+
};
|
|
619
|
+
}
|
|
620
|
+
else {
|
|
621
|
+
return {
|
|
622
|
+
type: "image_url",
|
|
623
|
+
image_url: {
|
|
624
|
+
url: `data:${item.mimeType};base64,${item.data}`,
|
|
625
|
+
},
|
|
626
|
+
};
|
|
627
|
+
}
|
|
628
|
+
});
|
|
629
|
+
if (content.length === 0)
|
|
630
|
+
continue;
|
|
631
|
+
params.push({
|
|
632
|
+
role: "user",
|
|
633
|
+
content,
|
|
634
|
+
});
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
else if (msg.role === "assistant") {
|
|
638
|
+
// Some providers don't accept null content, use empty string instead
|
|
639
|
+
const assistantMsg = {
|
|
640
|
+
role: "assistant",
|
|
641
|
+
content: compat.requiresAssistantAfterToolResult ? "" : null,
|
|
642
|
+
};
|
|
643
|
+
const assistantTextParts = msg.content
|
|
644
|
+
.filter(isTextContentBlock)
|
|
645
|
+
.filter((block) => block.text.trim().length > 0)
|
|
646
|
+
.map((block) => ({
|
|
647
|
+
type: "text",
|
|
648
|
+
text: sanitizeSurrogates(block.text),
|
|
649
|
+
}));
|
|
650
|
+
const assistantText = assistantTextParts.map((part) => part.text).join("");
|
|
651
|
+
const nonEmptyThinkingBlocks = msg.content
|
|
652
|
+
.filter(isThinkingContentBlock)
|
|
653
|
+
.filter((block) => block.thinking.trim().length > 0);
|
|
654
|
+
if (nonEmptyThinkingBlocks.length > 0) {
|
|
655
|
+
if (compat.requiresThinkingAsText) {
|
|
656
|
+
// Convert thinking blocks to plain text (no tags to avoid model mimicking them)
|
|
657
|
+
const thinkingText = nonEmptyThinkingBlocks
|
|
658
|
+
.map((block) => sanitizeSurrogates(block.thinking))
|
|
659
|
+
.join("\n\n");
|
|
660
|
+
assistantMsg.content = [{ type: "text", text: thinkingText }, ...assistantTextParts];
|
|
661
|
+
}
|
|
662
|
+
else {
|
|
663
|
+
// Always send assistant content as a plain string (OpenAI Chat Completions
|
|
664
|
+
// API standard format). Sending as an array of {type:"text", text:"..."}
|
|
665
|
+
// objects is non-standard and causes some models (e.g. DeepSeek V3.2 via
|
|
666
|
+
// NVIDIA NIM) to mirror the content-block structure literally in their
|
|
667
|
+
// output, producing recursive nesting like [{'type':'text','text':'[{...}]'}].
|
|
668
|
+
if (assistantText.length > 0) {
|
|
669
|
+
assistantMsg.content = assistantText;
|
|
670
|
+
}
|
|
671
|
+
// Use the signature from the first thinking block if available (for llama.cpp server + gpt-oss)
|
|
672
|
+
let signature = nonEmptyThinkingBlocks[0].thinkingSignature;
|
|
673
|
+
if (model.provider === "opencode-go" && signature === "reasoning") {
|
|
674
|
+
signature = "reasoning_content";
|
|
675
|
+
}
|
|
676
|
+
if (signature && signature.length > 0) {
|
|
677
|
+
assistantMsg[signature] = nonEmptyThinkingBlocks.map((block) => block.thinking).join("\n");
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
else if (assistantText.length > 0) {
|
|
682
|
+
// Always send assistant content as a plain string (OpenAI Chat Completions
|
|
683
|
+
// API standard format). Sending as an array of {type:"text", text:"..."}
|
|
684
|
+
// objects is non-standard and causes some models (e.g. DeepSeek V3.2 via
|
|
685
|
+
// NVIDIA NIM) to mirror the content-block structure literally in their
|
|
686
|
+
// output, producing recursive nesting like [{'type':'text','text':'[{...}]'}].
|
|
687
|
+
assistantMsg.content = assistantText;
|
|
688
|
+
}
|
|
689
|
+
const toolCalls = msg.content.filter(isToolCallBlock);
|
|
690
|
+
if (toolCalls.length > 0) {
|
|
691
|
+
assistantMsg.tool_calls = toolCalls.map((tc) => ({
|
|
692
|
+
id: tc.id,
|
|
693
|
+
type: "function",
|
|
694
|
+
function: {
|
|
695
|
+
name: tc.name,
|
|
696
|
+
arguments: JSON.stringify(tc.arguments),
|
|
697
|
+
},
|
|
698
|
+
}));
|
|
699
|
+
const reasoningDetails = toolCalls
|
|
700
|
+
.filter((tc) => tc.thoughtSignature)
|
|
701
|
+
.map((tc) => {
|
|
702
|
+
try {
|
|
703
|
+
return JSON.parse(tc.thoughtSignature);
|
|
704
|
+
}
|
|
705
|
+
catch {
|
|
706
|
+
return null;
|
|
707
|
+
}
|
|
708
|
+
})
|
|
709
|
+
.filter(Boolean);
|
|
710
|
+
if (reasoningDetails.length > 0) {
|
|
711
|
+
assistantMsg.reasoning_details = reasoningDetails;
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
if (compat.requiresReasoningContentOnAssistantMessages &&
|
|
715
|
+
model.reasoning &&
|
|
716
|
+
assistantMsg.reasoning_content === undefined) {
|
|
717
|
+
assistantMsg.reasoning_content = "";
|
|
718
|
+
}
|
|
719
|
+
// Skip assistant messages that have no content and no tool calls.
|
|
720
|
+
// Some providers require "either content or tool_calls, but not none".
|
|
721
|
+
// Other providers also don't accept empty assistant messages.
|
|
722
|
+
// This handles aborted assistant responses that got no content.
|
|
723
|
+
const content = assistantMsg.content;
|
|
724
|
+
const hasContent = content !== null &&
|
|
725
|
+
content !== undefined &&
|
|
726
|
+
(typeof content === "string" ? content.length > 0 : content.length > 0);
|
|
727
|
+
if (!hasContent && !assistantMsg.tool_calls) {
|
|
728
|
+
continue;
|
|
729
|
+
}
|
|
730
|
+
params.push(assistantMsg);
|
|
731
|
+
}
|
|
732
|
+
else if (msg.role === "toolResult") {
|
|
733
|
+
const imageBlocks = [];
|
|
734
|
+
let j = i;
|
|
735
|
+
for (; j < transformedMessages.length && transformedMessages[j].role === "toolResult"; j++) {
|
|
736
|
+
const toolMsg = transformedMessages[j];
|
|
737
|
+
// Extract text and image content
|
|
738
|
+
const textResult = toolMsg.content
|
|
739
|
+
.filter(isTextContentBlock)
|
|
740
|
+
.map((block) => block.text)
|
|
741
|
+
.join("\n");
|
|
742
|
+
const hasImages = toolMsg.content.some((c) => c.type === "image");
|
|
743
|
+
// Always send tool result with text (or placeholder if only images)
|
|
744
|
+
const hasText = textResult.length > 0;
|
|
745
|
+
// Some providers require the 'name' field in tool results
|
|
746
|
+
const toolResultMsg = {
|
|
747
|
+
role: "tool",
|
|
748
|
+
content: sanitizeSurrogates(hasText ? textResult : "(see attached image)"),
|
|
749
|
+
tool_call_id: toolMsg.toolCallId,
|
|
750
|
+
};
|
|
751
|
+
if (compat.requiresToolResultName && toolMsg.toolName) {
|
|
752
|
+
toolResultMsg.name = toolMsg.toolName;
|
|
753
|
+
}
|
|
754
|
+
params.push(toolResultMsg);
|
|
755
|
+
if (hasImages && model.input.includes("image")) {
|
|
756
|
+
for (const block of toolMsg.content) {
|
|
757
|
+
if (isImageContentBlock(block)) {
|
|
758
|
+
imageBlocks.push({
|
|
759
|
+
type: "image_url",
|
|
760
|
+
image_url: {
|
|
761
|
+
url: `data:${block.mimeType};base64,${block.data}`,
|
|
762
|
+
},
|
|
763
|
+
});
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
i = j - 1;
|
|
769
|
+
if (imageBlocks.length > 0) {
|
|
770
|
+
if (compat.requiresAssistantAfterToolResult) {
|
|
771
|
+
params.push({
|
|
772
|
+
role: "assistant",
|
|
773
|
+
content: "I have processed the tool results.",
|
|
774
|
+
});
|
|
775
|
+
}
|
|
776
|
+
params.push({
|
|
777
|
+
role: "user",
|
|
778
|
+
content: [
|
|
779
|
+
{
|
|
780
|
+
type: "text",
|
|
781
|
+
text: "Attached image(s) from tool result:",
|
|
782
|
+
},
|
|
783
|
+
...imageBlocks,
|
|
784
|
+
],
|
|
785
|
+
});
|
|
786
|
+
lastRole = "user";
|
|
787
|
+
}
|
|
788
|
+
else {
|
|
789
|
+
lastRole = "toolResult";
|
|
790
|
+
}
|
|
791
|
+
continue;
|
|
792
|
+
}
|
|
793
|
+
lastRole = msg.role;
|
|
794
|
+
}
|
|
795
|
+
return params;
|
|
796
|
+
}
|
|
797
|
+
function convertTools(tools, compat) {
|
|
798
|
+
return tools.map((tool) => ({
|
|
799
|
+
type: "function",
|
|
800
|
+
function: {
|
|
801
|
+
name: tool.name,
|
|
802
|
+
description: tool.description,
|
|
803
|
+
parameters: tool.parameters, // TypeBox already generates JSON Schema
|
|
804
|
+
// Only include strict if provider supports it. Some reject unknown fields.
|
|
805
|
+
...(compat.supportsStrictMode !== false && { strict: false }),
|
|
806
|
+
},
|
|
807
|
+
}));
|
|
808
|
+
}
|
|
809
|
+
function parseChunkUsage(rawUsage, model) {
|
|
810
|
+
const promptTokens = rawUsage.prompt_tokens || 0;
|
|
811
|
+
const cacheReadTokens = rawUsage.prompt_tokens_details?.cached_tokens ?? rawUsage.prompt_cache_hit_tokens ?? 0;
|
|
812
|
+
const cacheWriteTokens = rawUsage.prompt_tokens_details?.cache_write_tokens || 0;
|
|
813
|
+
// Follow documented OpenAI/OpenRouter semantics: cached_tokens is cache-read
|
|
814
|
+
// tokens (hits). OpenAI does not document or emit cache_write_tokens, but
|
|
815
|
+
// OpenRouter-compatible providers can include it as a separate write count.
|
|
816
|
+
// OpenRouter's own provider/tests affirm the separate mapping:
|
|
817
|
+
// https://github.com/OpenRouterTeam/ai-sdk-provider/pull/409
|
|
818
|
+
// Do not subtract writes from cached_tokens, otherwise spec-compliant
|
|
819
|
+
// providers are under-reported. DS4 mirrors this contract too:
|
|
820
|
+
// https://github.com/antirez/ds4/pull/29
|
|
821
|
+
const input = Math.max(0, promptTokens - cacheReadTokens - cacheWriteTokens);
|
|
822
|
+
// OpenAI completion_tokens already includes reasoning_tokens.
|
|
823
|
+
const outputTokens = rawUsage.completion_tokens || 0;
|
|
824
|
+
const usage = {
|
|
825
|
+
input,
|
|
826
|
+
output: outputTokens,
|
|
827
|
+
cacheRead: cacheReadTokens,
|
|
828
|
+
cacheWrite: cacheWriteTokens,
|
|
829
|
+
totalTokens: input + outputTokens + cacheReadTokens + cacheWriteTokens,
|
|
830
|
+
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },
|
|
831
|
+
};
|
|
832
|
+
calculateCost(model, usage);
|
|
833
|
+
return usage;
|
|
834
|
+
}
|
|
835
|
+
function mapStopReason(reason) {
|
|
836
|
+
if (reason === null)
|
|
837
|
+
return { stopReason: "stop" };
|
|
838
|
+
switch (reason) {
|
|
839
|
+
case "stop":
|
|
840
|
+
case "end":
|
|
841
|
+
return { stopReason: "stop" };
|
|
842
|
+
case "length":
|
|
843
|
+
return { stopReason: "length" };
|
|
844
|
+
case "function_call":
|
|
845
|
+
case "tool_calls":
|
|
846
|
+
return { stopReason: "toolUse" };
|
|
847
|
+
case "content_filter":
|
|
848
|
+
return { stopReason: "error", errorMessage: "Provider finish_reason: content_filter" };
|
|
849
|
+
case "network_error":
|
|
850
|
+
return { stopReason: "error", errorMessage: "Provider finish_reason: network_error" };
|
|
851
|
+
default:
|
|
852
|
+
return {
|
|
853
|
+
stopReason: "error",
|
|
854
|
+
errorMessage: `Provider finish_reason: ${reason}`,
|
|
855
|
+
};
|
|
856
|
+
}
|
|
857
|
+
}
|
|
858
|
+
/**
|
|
859
|
+
* Detect compatibility settings from provider and baseUrl for known providers.
|
|
860
|
+
* Provider takes precedence over URL-based detection since it's explicitly configured.
|
|
861
|
+
* Returns a fully resolved OpenAICompletionsCompat object with all fields set.
|
|
862
|
+
*/
|
|
863
|
+
function detectCompat(model) {
|
|
864
|
+
const provider = model.provider;
|
|
865
|
+
const baseUrl = model.baseUrl;
|
|
866
|
+
const isZai = provider === "zai" || baseUrl.includes("api.z.ai");
|
|
867
|
+
const isTogether = provider === "together" || baseUrl.includes("api.together.ai") || baseUrl.includes("api.together.xyz");
|
|
868
|
+
const isMoonshot = provider === "moonshotai" || provider === "moonshotai-cn" || baseUrl.includes("api.moonshot.");
|
|
869
|
+
// Cloudflare providers not supported (cloudflare.ts was removed)
|
|
870
|
+
const isCloudflareWorkersAI = false;
|
|
871
|
+
const isCloudflareAiGateway = false;
|
|
872
|
+
const isNonStandard = provider === "cerebras" ||
|
|
873
|
+
baseUrl.includes("cerebras.ai") ||
|
|
874
|
+
provider === "xai" ||
|
|
875
|
+
baseUrl.includes("api.x.ai") ||
|
|
876
|
+
isTogether ||
|
|
877
|
+
baseUrl.includes("chutes.ai") ||
|
|
878
|
+
baseUrl.includes("deepseek.com") ||
|
|
879
|
+
isZai ||
|
|
880
|
+
isMoonshot ||
|
|
881
|
+
provider === "opencode" ||
|
|
882
|
+
baseUrl.includes("opencode.ai") ||
|
|
883
|
+
isCloudflareWorkersAI ||
|
|
884
|
+
isCloudflareAiGateway;
|
|
885
|
+
const useMaxTokens = baseUrl.includes("chutes.ai") || isMoonshot || isCloudflareAiGateway || isTogether;
|
|
886
|
+
const isGrok = provider === "xai" || baseUrl.includes("api.x.ai");
|
|
887
|
+
const isDeepSeek = provider === "deepseek" || baseUrl.includes("deepseek.com");
|
|
888
|
+
const cacheControlFormat = provider === "openrouter" && model.id.startsWith("anthropic/") ? "anthropic" : undefined;
|
|
889
|
+
return {
|
|
890
|
+
supportsStore: !isNonStandard,
|
|
891
|
+
supportsDeveloperRole: !isNonStandard,
|
|
892
|
+
supportsReasoningEffort: !isGrok && !isZai && !isMoonshot && !isTogether && !isCloudflareAiGateway,
|
|
893
|
+
supportsUsageInStreaming: true,
|
|
894
|
+
maxTokensField: useMaxTokens ? "max_tokens" : "max_completion_tokens",
|
|
895
|
+
requiresToolResultName: false,
|
|
896
|
+
requiresAssistantAfterToolResult: false,
|
|
897
|
+
requiresThinkingAsText: false,
|
|
898
|
+
requiresReasoningContentOnAssistantMessages: isDeepSeek,
|
|
899
|
+
thinkingFormat: isDeepSeek
|
|
900
|
+
? "deepseek"
|
|
901
|
+
: isZai
|
|
902
|
+
? "zai"
|
|
903
|
+
: isTogether
|
|
904
|
+
? "together"
|
|
905
|
+
: provider === "openrouter" || baseUrl.includes("openrouter.ai")
|
|
906
|
+
? "openrouter"
|
|
907
|
+
: "openai",
|
|
908
|
+
openRouterRouting: {},
|
|
909
|
+
vercelGatewayRouting: {},
|
|
910
|
+
zaiToolStream: false,
|
|
911
|
+
supportsStrictMode: !isMoonshot && !isTogether && !isCloudflareAiGateway,
|
|
912
|
+
cacheControlFormat,
|
|
913
|
+
sendSessionAffinityHeaders: false,
|
|
914
|
+
supportsLongCacheRetention: !(isTogether || isCloudflareWorkersAI || isCloudflareAiGateway),
|
|
915
|
+
};
|
|
916
|
+
}
|
|
917
|
+
/**
|
|
918
|
+
* Get resolved compatibility settings for a model.
|
|
919
|
+
* Uses explicit model.compat if provided, otherwise auto-detects from provider/URL.
|
|
920
|
+
*/
|
|
921
|
+
function getCompat(model) {
|
|
922
|
+
const detected = detectCompat(model);
|
|
923
|
+
if (!model.compat)
|
|
924
|
+
return detected;
|
|
925
|
+
return {
|
|
926
|
+
supportsStore: model.compat.supportsStore ?? detected.supportsStore,
|
|
927
|
+
supportsDeveloperRole: model.compat.supportsDeveloperRole ?? detected.supportsDeveloperRole,
|
|
928
|
+
supportsReasoningEffort: model.compat.supportsReasoningEffort ?? detected.supportsReasoningEffort,
|
|
929
|
+
supportsUsageInStreaming: model.compat.supportsUsageInStreaming ?? detected.supportsUsageInStreaming,
|
|
930
|
+
maxTokensField: model.compat.maxTokensField ?? detected.maxTokensField,
|
|
931
|
+
requiresToolResultName: model.compat.requiresToolResultName ?? detected.requiresToolResultName,
|
|
932
|
+
requiresAssistantAfterToolResult: model.compat.requiresAssistantAfterToolResult ?? detected.requiresAssistantAfterToolResult,
|
|
933
|
+
requiresThinkingAsText: model.compat.requiresThinkingAsText ?? detected.requiresThinkingAsText,
|
|
934
|
+
requiresReasoningContentOnAssistantMessages: model.compat.requiresReasoningContentOnAssistantMessages ??
|
|
935
|
+
detected.requiresReasoningContentOnAssistantMessages,
|
|
936
|
+
thinkingFormat: model.compat.thinkingFormat ?? detected.thinkingFormat,
|
|
937
|
+
openRouterRouting: model.compat.openRouterRouting ?? {},
|
|
938
|
+
vercelGatewayRouting: model.compat.vercelGatewayRouting ?? detected.vercelGatewayRouting,
|
|
939
|
+
zaiToolStream: model.compat.zaiToolStream ?? detected.zaiToolStream,
|
|
940
|
+
supportsStrictMode: model.compat.supportsStrictMode ?? detected.supportsStrictMode,
|
|
941
|
+
cacheControlFormat: model.compat.cacheControlFormat ?? detected.cacheControlFormat,
|
|
942
|
+
sendSessionAffinityHeaders: model.compat.sendSessionAffinityHeaders ?? detected.sendSessionAffinityHeaders,
|
|
943
|
+
supportsLongCacheRetention: model.compat.supportsLongCacheRetention ?? detected.supportsLongCacheRetention,
|
|
944
|
+
};
|
|
945
|
+
}
|