@bastani/pi-ai 0.9.25-alpha.1 → 0.9.25-alpha.2
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/dist/providers/data/.manifest.json +1 -1
- package/dist/providers/data/openrouter.json +1 -1
- package/dist/providers/data/radius.json +1 -1
- package/dist/utils/validation.d.ts +1 -0
- package/dist/utils/validation.d.ts.map +1 -1
- package/dist/utils/validation.js +3 -0
- package/dist/utils/validation.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"pi-messages":{"chat:balanced":{"id":"balanced","name":"Balanced","reasoning":true,"thinkingLevelMap":{"off":null,"minimal":null,"low":"low","medium":null,"high":"high","xhigh":null,"max":"max"},"input":["text","image"],"contextWindow":1048576,"maxTokens":131072,"lab":"Moonshot AI","cost":{"input":3,"output":15,"cacheRead":0.3,"cacheWrite":0},"enabled":true,"providers":[{"id":"fireworks","name":"Fireworks AI","credential":"radius","source":"radius"},{"id":"sference","name":"sference","credential":"radius","source":"radius"},{"id":"baseten","name":"Baseten","credential":"radius","source":"radius"}],"api":"pi-messages","provider":"radius","baseUrl":"https://radius.pi.dev/v1","inputLimits":{"images":{"resize":{"maxWidth":2000,"maxHeight":2000,"maxBytes":4718592,"jpegQuality":80}}},"type":"chat"},"chat:cheap":{"id":"cheap","name":"Cheap","reasoning":true,"thinkingLevelMap":{"off":"none","minimal":null,"low":"low","medium":null,"high":"high","xhigh":null,"max":"max"},"input":["text","image"],"contextWindow":1000000,"maxTokens":32768,"lab":"DeepSeek","cost":{"input":0.22,"output":0.66,"cacheRead":0.007,"cacheWrite":0},"enabled":true,"providers":[{"id":"fireworks","name":"Fireworks AI","credential":"radius","source":"radius"},{"id":"baseten","name":"Baseten","credential":"radius","source":"radius"}],"api":"pi-messages","provider":"radius","baseUrl":"https://radius.pi.dev/v1","inputLimits":{"images":{"resize":{"maxWidth":2000,"maxHeight":2000,"maxBytes":4718592,"jpegQuality":80}}},"type":"chat"},"chat:claude-fable-5":{"id":"claude-fable-5","name":"Claude Fable 5","reasoning":true,"thinkingLevelMap":{"off":null,"xhigh":"xhigh","max":"max"},"input":["text","image"],"contextWindow":1000000,"maxTokens":128000,"lab":"Anthropic","cost":{"input":10,"output":50,"cacheRead":1,"cacheWrite":12.5},"enabled":true,"providers":[{"id":"anthropic","name":"Anthropic","credential":"radius","source":"radius"}],"api":"pi-messages","provider":"radius","baseUrl":"https://radius.pi.dev/v1","inputLimits":{"images":{"resize":{"maxWidth":2000,"maxHeight":2000,"maxBytes":4718592,"jpegQuality":80}}},"type":"chat"},"chat:claude-fable-5-1":{"id":"claude-fable-5-1","name":"Claude Fable 5.1","reasoning":true,"thinkingLevelMap":{"off":null,"xhigh":"xhigh","max":"max","minimal":null},"input":["text","image"],"contextWindow":1000000,"maxTokens":128000,"lab":"Anthropic","cost":{"input":10,"output":50,"cacheRead":0.25,"cacheWrite":12.5},"enabled":true,"providers":[{"id":"anthropic","name":"Anthropic","credential":"radius","source":"radius"}],"api":"pi-messages","provider":"radius","baseUrl":"https://radius.pi.dev/v1","inputLimits":{"images":{"resize":{"maxWidth":2000,"maxHeight":2000,"maxBytes":4718592,"jpegQuality":80}}},"type":"chat"},"chat:claude-haiku-4-5":{"id":"claude-haiku-4-5","name":"Claude Haiku 4.5","reasoning":true,"input":["text","image"],"contextWindow":200000,"maxTokens":64000,"lab":"Anthropic","cost":{"input":1,"output":5,"cacheRead":0.1,"cacheWrite":1.25},"enabled":true,"providers":[{"id":"anthropic","name":"Anthropic","credential":"radius","source":"radius"}],"api":"pi-messages","provider":"radius","baseUrl":"https://radius.pi.dev/v1","inputLimits":{"images":{"resize":{"maxWidth":2000,"maxHeight":2000,"maxBytes":4718592,"jpegQuality":80}}},"type":"chat"},"chat:claude-opus-4-5":{"id":"claude-opus-4-5","name":"Claude Opus 4.5","reasoning":true,"input":["text","image"],"contextWindow":200000,"maxTokens":64000,"lab":"Anthropic","cost":{"input":5,"output":25,"cacheRead":0.5,"cacheWrite":6.25},"enabled":true,"providers":[{"id":"anthropic","name":"Anthropic","credential":"radius","source":"radius"}],"api":"pi-messages","provider":"radius","baseUrl":"https://radius.pi.dev/v1","inputLimits":{"images":{"resize":{"maxWidth":2000,"maxHeight":2000,"maxBytes":4718592,"jpegQuality":80}}},"type":"chat"},"chat:claude-opus-4-8":{"id":"claude-opus-4-8","name":"Claude Opus 4.8","reasoning":true,"thinkingLevelMap":{"xhigh":"xhigh","max":"max"},"input":["text","image"],"contextWindow":1000000,"maxTokens":128000,"lab":"Anthropic","cost":{"input":5,"output":25,"cacheRead":0.5,"cacheWrite":6.25},"enabled":true,"providers":[{"id":"anthropic","name":"Anthropic","credential":"radius","source":"radius"}],"api":"pi-messages","provider":"radius","baseUrl":"https://radius.pi.dev/v1","inputLimits":{"images":{"resize":{"maxWidth":2000,"maxHeight":2000,"maxBytes":4718592,"jpegQuality":80}}},"type":"chat"},"chat:claude-opus-5":{"id":"claude-opus-5","name":"Claude Opus 5","reasoning":true,"thinkingLevelMap":{"off":null,"xhigh":"xhigh","max":"max"},"input":["text","image"],"contextWindow":1000000,"maxTokens":128000,"lab":"Anthropic","cost":{"input":5,"output":25,"cacheRead":0.5,"cacheWrite":6.25},"enabled":true,"providers":[{"id":"anthropic","name":"Anthropic","credential":"radius","source":"radius"}],"api":"pi-messages","provider":"radius","baseUrl":"https://radius.pi.dev/v1","inputLimits":{"images":{"resize":{"maxWidth":2000,"maxHeight":2000,"maxBytes":4718592,"jpegQuality":80}}},"type":"chat"},"chat:claude-opus-5-5":{"id":"claude-opus-5-5","name":"Claude Opus 5.5","reasoning":true,"thinkingLevelMap":{"off":null,"minimal":null,"low":"low","medium":"medium","high":"high","xhigh":"xhigh","max":"max"},"input":["text","image"],"contextWindow":1000000,"maxTokens":128000,"lab":"Anthropic","cost":{"input":4,"output":20,"cacheRead":0.2,"cacheWrite":5},"enabled":true,"providers":[{"id":"anthropic","name":"Anthropic","credential":"radius","source":"radius"}],"api":"pi-messages","provider":"radius","baseUrl":"https://radius.pi.dev/v1","inputLimits":{"images":{"resize":{"maxWidth":2000,"maxHeight":2000,"maxBytes":4718592,"jpegQuality":80}}},"type":"chat"},"chat:claude-sonnet-4-5":{"id":"claude-sonnet-4-5","name":"Claude Sonnet 4.5","reasoning":true,"input":["text","image"],"contextWindow":1000000,"maxTokens":64000,"lab":"Anthropic","cost":{"input":3,"output":15,"cacheRead":0.3,"cacheWrite":3.75},"enabled":true,"providers":[{"id":"anthropic","name":"Anthropic","credential":"radius","source":"radius"}],"api":"pi-messages","provider":"radius","baseUrl":"https://radius.pi.dev/v1","inputLimits":{"images":{"resize":{"maxWidth":2000,"maxHeight":2000,"maxBytes":4718592,"jpegQuality":80}}},"type":"chat"},"chat:claude-sonnet-5":{"id":"claude-sonnet-5","name":"Claude Sonnet 5","reasoning":true,"thinkingLevelMap":{"xhigh":"xhigh","max":"max"},"input":["text","image"],"contextWindow":1000000,"maxTokens":128000,"lab":"Anthropic","cost":{"input":2,"output":10,"cacheRead":0.2,"cacheWrite":2.5},"enabled":true,"providers":[{"id":"anthropic","name":"Anthropic","credential":"radius","source":"radius"}],"api":"pi-messages","provider":"radius","baseUrl":"https://radius.pi.dev/v1","inputLimits":{"images":{"resize":{"maxWidth":2000,"maxHeight":2000,"maxBytes":4718592,"jpegQuality":80}}},"type":"chat"},"chat:claude-sonnet-5-5":{"id":"claude-sonnet-5-5","name":"Claude Sonnet 5.5","reasoning":true,"thinkingLevelMap":{"off":null,"minimal":null,"low":"low","medium":"medium","high":"high","xhigh":"xhigh","max":"max"},"input":["text","image"],"contextWindow":1000000,"maxTokens":128000,"lab":"Anthropic","cost":{"input":2,"output":10,"cacheRead":0.2,"cacheWrite":2.5},"enabled":true,"providers":[{"id":"anthropic","name":"Anthropic","credential":"radius","source":"radius"}],"api":"pi-messages","provider":"radius","baseUrl":"https://radius.pi.dev/v1","inputLimits":{"images":{"resize":{"maxWidth":2000,"maxHeight":2000,"maxBytes":4718592,"jpegQuality":80}}},"type":"chat"},"chat:deepseek-v4.1-flash":{"id":"deepseek-v4.1-flash","name":"DeepSeek V4.1 Flash","reasoning":true,"thinkingLevelMap":{"off":"none","minimal":null,"low":"low","medium":null,"high":"high","xhigh":null,"max":"max"},"input":["text","image"],"contextWindow":1000000,"maxTokens":32768,"lab":"DeepSeek","cost":{"input":0.22,"output":0.66,"cacheRead":0.007,"cacheWrite":0},"enabled":true,"providers":[{"id":"fireworks","name":"Fireworks AI","credential":"radius","source":"radius"},{"id":"baseten","name":"Baseten","credential":"radius","source":"radius"}],"api":"pi-messages","provider":"radius","baseUrl":"https://radius.pi.dev/v1","inputLimits":{"images":{"resize":{"maxWidth":2000,"maxHeight":2000,"maxBytes":4718592,"jpegQuality":80}}},"type":"chat"},"chat:glm-5.3":{"id":"glm-5.3","name":"GLM-5.3","reasoning":true,"thinkingLevelMap":{"off":null,"minimal":"minimal","low":"low","medium":"medium","high":"high","xhigh":"xhigh","max":"xhigh"},"input":["text"],"contextWindow":1000000,"maxTokens":131072,"lab":"Z.ai","cost":{"input":1.4,"output":4.4,"cacheRead":0.26,"cacheWrite":0},"enabled":true,"providers":[{"id":"sference","name":"sference","credential":"radius","source":"radius"},{"id":"fireworks","name":"Fireworks AI","credential":"radius","source":"radius"},{"id":"baseten","name":"Baseten","credential":"radius","source":"radius"},{"id":"deepinfra","name":"DeepInfra","credential":"radius","source":"radius"}],"api":"pi-messages","provider":"radius","baseUrl":"https://radius.pi.dev/v1","type":"chat"},"chat:glm-5.3-flash":{"id":"glm-5.3-flash","name":"GLM-5.3 Flash","reasoning":true,"thinkingLevelMap":{"off":null,"minimal":null,"low":"low","medium":null,"high":"high","xhigh":null,"max":"max"},"input":["text"],"contextWindow":1000000,"maxTokens":131072,"lab":"Z.ai","cost":{"input":0.15,"output":0.5,"cacheRead":0.03,"cacheWrite":0},"enabled":true,"providers":[{"id":"fireworks","name":"Fireworks AI","credential":"radius","source":"radius"},{"id":"baseten","name":"Baseten","credential":"radius","source":"radius"},{"id":"sference","name":"sference","credential":"radius","source":"radius"},{"id":"deepinfra","name":"DeepInfra","credential":"radius","source":"radius"}],"api":"pi-messages","provider":"radius","baseUrl":"https://radius.pi.dev/v1","type":"chat"},"chat:gpt-5.3-codex":{"id":"gpt-5.3-codex","name":"GPT 5.3 Codex","reasoning":true,"thinkingLevelMap":{"off":"none","minimal":null,"low":"low","medium":"medium","high":"high","xhigh":"xhigh","max":null},"input":["text","image"],"contextWindow":400000,"maxTokens":128000,"lab":"OpenAI","cost":{"input":1.75,"output":14,"cacheRead":0.175,"cacheWrite":0},"enabled":true,"providers":[{"id":"openai","name":"OpenAI","credential":"radius","source":"radius"}],"api":"pi-messages","provider":"radius","baseUrl":"https://radius.pi.dev/v1","inputLimits":{"images":{"resize":{"maxWidth":2000,"maxHeight":2000,"maxBytes":4718592,"jpegQuality":80}}},"type":"chat"},"chat:gpt-5.4":{"id":"gpt-5.4","name":"GPT 5.4","reasoning":true,"thinkingLevelMap":{"off":"none","minimal":null,"low":"low","medium":"medium","high":"high","xhigh":"xhigh","max":null},"input":["text","image"],"contextWindow":272000,"maxTokens":128000,"lab":"OpenAI","cost":{"input":2.5,"output":15,"cacheRead":0.25,"cacheWrite":0,"tiers":[{"inputTokensAbove":272000,"input":5,"output":22.5,"cacheRead":0.5,"cacheWrite":0}]},"enabled":true,"providers":[{"id":"openai","name":"OpenAI","credential":"radius","source":"radius"}],"api":"pi-messages","provider":"radius","baseUrl":"https://radius.pi.dev/v1","inputLimits":{"images":{"resize":{"maxWidth":2000,"maxHeight":2000,"maxBytes":4718592,"jpegQuality":80}}},"type":"chat"},"chat:gpt-5.4-mini":{"id":"gpt-5.4-mini","name":"GPT 5.4 Mini","reasoning":true,"thinkingLevelMap":{"off":"none","minimal":null,"low":"low","medium":"medium","high":"high","xhigh":"xhigh","max":null},"input":["text","image"],"contextWindow":400000,"maxTokens":128000,"lab":"OpenAI","cost":{"input":0.75,"output":4.5,"cacheRead":0.075,"cacheWrite":0},"enabled":true,"providers":[{"id":"openai","name":"OpenAI","credential":"radius","source":"radius"}],"api":"pi-messages","provider":"radius","baseUrl":"https://radius.pi.dev/v1","inputLimits":{"images":{"resize":{"maxWidth":2000,"maxHeight":2000,"maxBytes":4718592,"jpegQuality":80}}},"type":"chat"},"chat:gpt-5.5":{"id":"gpt-5.5","name":"GPT 5.5","reasoning":true,"thinkingLevelMap":{"off":"none","minimal":null,"low":"low","medium":"medium","high":"high","xhigh":"xhigh","max":null},"input":["text","image"],"contextWindow":272000,"maxTokens":128000,"lab":"OpenAI","cost":{"input":5,"output":30,"cacheRead":0.5,"cacheWrite":0,"tiers":[{"inputTokensAbove":272000,"input":10,"output":45,"cacheRead":1,"cacheWrite":0}]},"enabled":true,"providers":[{"id":"openai","name":"OpenAI","credential":"radius","source":"radius"}],"api":"pi-messages","provider":"radius","baseUrl":"https://radius.pi.dev/v1","inputLimits":{"images":{"resize":{"maxWidth":2000,"maxHeight":2000,"maxBytes":4718592,"jpegQuality":80}}},"type":"chat"},"chat:gpt-5.6-luna":{"id":"gpt-5.6-luna","name":"GPT 5.6 Luna","reasoning":true,"thinkingLevelMap":{"off":"none","minimal":null,"low":"low","medium":"medium","high":"high","xhigh":"xhigh","max":"max"},"input":["text","image"],"contextWindow":272000,"maxTokens":128000,"lab":"OpenAI","cost":{"input":0.2,"output":1.2,"cacheRead":0.02,"cacheWrite":0.25,"tiers":[{"inputTokensAbove":272000,"input":0.4,"output":1.8,"cacheRead":0.04,"cacheWrite":0.5}]},"enabled":true,"providers":[{"id":"openai","name":"OpenAI","credential":"radius","source":"radius"}],"api":"pi-messages","provider":"radius","baseUrl":"https://radius.pi.dev/v1","inputLimits":{"images":{"resize":{"maxWidth":2000,"maxHeight":2000,"maxBytes":4718592,"jpegQuality":80}}},"type":"chat"},"chat:gpt-5.6-sol":{"id":"gpt-5.6-sol","name":"GPT 5.6 Sol","reasoning":true,"thinkingLevelMap":{"off":"none","minimal":null,"low":"low","medium":"medium","high":"high","xhigh":"xhigh","max":"max"},"input":["text","image"],"contextWindow":272000,"maxTokens":128000,"lab":"OpenAI","cost":{"input":4,"output":20,"cacheRead":0.4,"cacheWrite":5,"tiers":[{"inputTokensAbove":272000,"input":8,"output":30,"cacheRead":0.8,"cacheWrite":10}]},"enabled":true,"providers":[{"id":"openai","name":"OpenAI","credential":"radius","source":"radius"}],"api":"pi-messages","provider":"radius","baseUrl":"https://radius.pi.dev/v1","inputLimits":{"images":{"resize":{"maxWidth":2000,"maxHeight":2000,"maxBytes":4718592,"jpegQuality":80}}},"type":"chat"},"chat:gpt-5.6-terra":{"id":"gpt-5.6-terra","name":"GPT 5.6 Terra","reasoning":true,"thinkingLevelMap":{"off":"none","minimal":null,"low":"low","medium":"medium","high":"high","xhigh":"xhigh","max":"max"},"input":["text","image"],"contextWindow":272000,"maxTokens":128000,"lab":"OpenAI","cost":{"input":2,"output":12,"cacheRead":0.2,"cacheWrite":2.5,"tiers":[{"inputTokensAbove":272000,"input":4,"output":18,"cacheRead":0.4,"cacheWrite":5}]},"enabled":true,"providers":[{"id":"openai","name":"OpenAI","credential":"radius","source":"radius"}],"api":"pi-messages","provider":"radius","baseUrl":"https://radius.pi.dev/v1","inputLimits":{"images":{"resize":{"maxWidth":2000,"maxHeight":2000,"maxBytes":4718592,"jpegQuality":80}}},"type":"chat"},"chat:gpt-6-astra":{"id":"gpt-6-astra","name":"GPT 6 Astra","reasoning":true,"thinkingLevelMap":{"off":null,"minimal":null,"low":"low","medium":"medium","high":"high","xhigh":"xhigh","max":"max"},"input":["text","image"],"contextWindow":272000,"maxTokens":128000,"lab":"OpenAI","cost":{"input":10,"output":50,"cacheRead":1,"cacheWrite":12.5,"tiers":[{"inputTokensAbove":272000,"input":20,"output":75,"cacheRead":2,"cacheWrite":25}]},"enabled":true,"providers":[{"id":"openai","name":"OpenAI","credential":"radius","source":"radius"}],"api":"pi-messages","provider":"radius","baseUrl":"https://radius.pi.dev/v1","inputLimits":{"images":{"resize":{"maxWidth":2000,"maxHeight":2000,"maxBytes":4718592,"jpegQuality":80}}},"type":"chat"},"chat:gpt-6-luna":{"id":"gpt-6-luna","name":"GPT 6 Luna","reasoning":true,"thinkingLevelMap":{"off":"none","minimal":null,"low":"low","medium":"medium","high":"high","xhigh":"xhigh","max":"max"},"input":["text","image"],"contextWindow":1050000,"maxTokens":128000,"lab":"OpenAI","cost":{"input":0.1,"output":0.5,"cacheRead":0.01,"cacheWrite":0.125,"tiers":[{"inputTokensAbove":272000,"input":0.2,"output":0.75,"cacheRead":0.02,"cacheWrite":0.25}]},"enabled":true,"providers":[{"id":"openai","name":"OpenAI","credential":"radius","source":"radius"}],"api":"pi-messages","provider":"radius","baseUrl":"https://radius.pi.dev/v1","inputLimits":{"images":{"resize":{"maxWidth":2000,"maxHeight":2000,"maxBytes":4718592,"jpegQuality":80}}},"type":"chat"},"chat:gpt-6-sol":{"id":"gpt-6-sol","name":"GPT 6 Sol","reasoning":true,"thinkingLevelMap":{"off":"none","minimal":null,"low":"low","medium":"medium","high":"high","xhigh":"xhigh","max":"max"},"input":["text","image"],"contextWindow":1050000,"maxTokens":128000,"lab":"OpenAI","cost":{"input":2,"output":10,"cacheRead":0.2,"cacheWrite":2.5,"tiers":[{"inputTokensAbove":272000,"input":4,"output":15,"cacheRead":0.4,"cacheWrite":5}]},"enabled":true,"providers":[{"id":"openai","name":"OpenAI","credential":"radius","source":"radius"}],"api":"pi-messages","provider":"radius","baseUrl":"https://radius.pi.dev/v1","inputLimits":{"images":{"resize":{"maxWidth":2000,"maxHeight":2000,"maxBytes":4718592,"jpegQuality":80}}},"type":"chat"},"chat:grok-4.7":{"id":"grok-4.7","name":"Grok 4.7","reasoning":true,"thinkingLevelMap":{"off":null,"minimal":null,"low":"low","medium":"medium","high":"high","xhigh":"xhigh","max":null},"input":["text","image"],"contextWindow":500000,"maxTokens":500000,"lab":"xAI","cost":{"input":2,"output":6,"cacheRead":0.5,"cacheWrite":0,"tiers":[{"inputTokensAbove":200000,"input":4,"output":12,"cacheRead":1,"cacheWrite":0}]},"enabled":true,"providers":[{"id":"xai","name":"xAI","credential":"radius","source":"radius"}],"api":"pi-messages","provider":"radius","baseUrl":"https://radius.pi.dev/v1","inputLimits":{"images":{"resize":{"maxWidth":2000,"maxHeight":2000,"maxBytes":4718592,"jpegQuality":80}}},"type":"chat"},"chat:kimi-k3":{"id":"kimi-k3","name":"Kimi K3","reasoning":true,"thinkingLevelMap":{"off":null,"minimal":null,"low":"low","medium":null,"high":"high","xhigh":null,"max":"max"},"input":["text","image"],"contextWindow":1048576,"maxTokens":131072,"lab":"Moonshot AI","cost":{"input":3,"output":15,"cacheRead":0.3,"cacheWrite":0},"enabled":true,"providers":[{"id":"fireworks","name":"Fireworks AI","credential":"radius","source":"radius"},{"id":"sference","name":"sference","credential":"radius","source":"radius"},{"id":"baseten","name":"Baseten","credential":"radius","source":"radius"}],"api":"pi-messages","provider":"radius","baseUrl":"https://radius.pi.dev/v1","inputLimits":{"images":{"resize":{"maxWidth":2000,"maxHeight":2000,"maxBytes":4718592,"jpegQuality":80}}},"type":"chat"},"chat:precise":{"id":"precise","name":"Precise","reasoning":true,"thinkingLevelMap":{"off":"none","minimal":null,"low":"low","medium":"medium","high":"high","xhigh":"xhigh","max":"max"},"input":["text","image"],"contextWindow":272000,"maxTokens":128000,"lab":"OpenAI","cost":{"input":4,"output":20,"cacheRead":0.4,"cacheWrite":5,"tiers":[{"inputTokensAbove":272000,"input":8,"output":30,"cacheRead":0.8,"cacheWrite":10}]},"enabled":true,"providers":[{"id":"openai","name":"OpenAI","credential":"radius","source":"radius"}],"api":"pi-messages","provider":"radius","baseUrl":"https://radius.pi.dev/v1","inputLimits":{"images":{"resize":{"maxWidth":2000,"maxHeight":2000,"maxBytes":4718592,"jpegQuality":80}}},"type":"chat"}}}
|
|
1
|
+
{"pi-messages":{"chat:balanced":{"id":"balanced","name":"Balanced","reasoning":true,"thinkingLevelMap":{"off":null,"minimal":null,"low":"low","medium":null,"high":"high","xhigh":null,"max":"max"},"input":["text","image"],"contextWindow":1048576,"maxTokens":131072,"lab":"Moonshot AI","cost":{"input":3,"output":15,"cacheRead":0.3,"cacheWrite":0},"enabled":true,"providers":[{"id":"fireworks","name":"Fireworks AI","credential":"radius","source":"radius"},{"id":"relace","name":"Relace","credential":"radius","source":"radius"},{"id":"sference","name":"sference","credential":"radius","source":"radius"},{"id":"baseten","name":"Baseten","credential":"radius","source":"radius"}],"api":"pi-messages","provider":"radius","baseUrl":"https://radius.pi.dev/v1","inputLimits":{"images":{"resize":{"maxWidth":2000,"maxHeight":2000,"maxBytes":4718592,"jpegQuality":80}}},"type":"chat"},"chat:cheap":{"id":"cheap","name":"Cheap","reasoning":true,"thinkingLevelMap":{"off":"none","minimal":null,"low":"low","medium":null,"high":"high","xhigh":null,"max":"max"},"input":["text","image"],"contextWindow":1000000,"maxTokens":32768,"lab":"DeepSeek","cost":{"input":0.22,"output":0.66,"cacheRead":0.007,"cacheWrite":0},"enabled":true,"providers":[{"id":"fireworks","name":"Fireworks AI","credential":"radius","source":"radius"},{"id":"relace","name":"Relace","credential":"radius","source":"radius"},{"id":"baseten","name":"Baseten","credential":"radius","source":"radius"}],"api":"pi-messages","provider":"radius","baseUrl":"https://radius.pi.dev/v1","inputLimits":{"images":{"resize":{"maxWidth":2000,"maxHeight":2000,"maxBytes":4718592,"jpegQuality":80}}},"type":"chat"},"chat:claude-fable-5":{"id":"claude-fable-5","name":"Claude Fable 5","reasoning":true,"thinkingLevelMap":{"off":null,"xhigh":"xhigh","max":"max"},"input":["text","image"],"contextWindow":1000000,"maxTokens":128000,"lab":"Anthropic","cost":{"input":10,"output":50,"cacheRead":1,"cacheWrite":12.5},"enabled":true,"providers":[{"id":"anthropic","name":"Anthropic","credential":"radius","source":"radius"}],"api":"pi-messages","provider":"radius","baseUrl":"https://radius.pi.dev/v1","inputLimits":{"images":{"resize":{"maxWidth":2000,"maxHeight":2000,"maxBytes":4718592,"jpegQuality":80}}},"type":"chat"},"chat:claude-fable-5-1":{"id":"claude-fable-5-1","name":"Claude Fable 5.1","reasoning":true,"thinkingLevelMap":{"off":null,"xhigh":"xhigh","max":"max","minimal":null},"input":["text","image"],"contextWindow":1000000,"maxTokens":128000,"lab":"Anthropic","cost":{"input":10,"output":50,"cacheRead":0.25,"cacheWrite":12.5},"enabled":true,"providers":[{"id":"anthropic","name":"Anthropic","credential":"radius","source":"radius"}],"api":"pi-messages","provider":"radius","baseUrl":"https://radius.pi.dev/v1","inputLimits":{"images":{"resize":{"maxWidth":2000,"maxHeight":2000,"maxBytes":4718592,"jpegQuality":80}}},"type":"chat"},"chat:claude-haiku-4-5":{"id":"claude-haiku-4-5","name":"Claude Haiku 4.5","reasoning":true,"input":["text","image"],"contextWindow":200000,"maxTokens":64000,"lab":"Anthropic","cost":{"input":1,"output":5,"cacheRead":0.1,"cacheWrite":1.25},"enabled":true,"providers":[{"id":"anthropic","name":"Anthropic","credential":"radius","source":"radius"}],"api":"pi-messages","provider":"radius","baseUrl":"https://radius.pi.dev/v1","inputLimits":{"images":{"resize":{"maxWidth":2000,"maxHeight":2000,"maxBytes":4718592,"jpegQuality":80}}},"type":"chat"},"chat:claude-opus-4-5":{"id":"claude-opus-4-5","name":"Claude Opus 4.5","reasoning":true,"input":["text","image"],"contextWindow":200000,"maxTokens":64000,"lab":"Anthropic","cost":{"input":5,"output":25,"cacheRead":0.5,"cacheWrite":6.25},"enabled":true,"providers":[{"id":"anthropic","name":"Anthropic","credential":"radius","source":"radius"}],"api":"pi-messages","provider":"radius","baseUrl":"https://radius.pi.dev/v1","inputLimits":{"images":{"resize":{"maxWidth":2000,"maxHeight":2000,"maxBytes":4718592,"jpegQuality":80}}},"type":"chat"},"chat:claude-opus-4-8":{"id":"claude-opus-4-8","name":"Claude Opus 4.8","reasoning":true,"thinkingLevelMap":{"xhigh":"xhigh","max":"max"},"input":["text","image"],"contextWindow":1000000,"maxTokens":128000,"lab":"Anthropic","cost":{"input":5,"output":25,"cacheRead":0.5,"cacheWrite":6.25},"enabled":true,"providers":[{"id":"anthropic","name":"Anthropic","credential":"radius","source":"radius"}],"api":"pi-messages","provider":"radius","baseUrl":"https://radius.pi.dev/v1","inputLimits":{"images":{"resize":{"maxWidth":2000,"maxHeight":2000,"maxBytes":4718592,"jpegQuality":80}}},"type":"chat"},"chat:claude-opus-5":{"id":"claude-opus-5","name":"Claude Opus 5","reasoning":true,"thinkingLevelMap":{"off":null,"xhigh":"xhigh","max":"max"},"input":["text","image"],"contextWindow":1000000,"maxTokens":128000,"lab":"Anthropic","cost":{"input":5,"output":25,"cacheRead":0.5,"cacheWrite":6.25},"enabled":true,"providers":[{"id":"anthropic","name":"Anthropic","credential":"radius","source":"radius"}],"api":"pi-messages","provider":"radius","baseUrl":"https://radius.pi.dev/v1","inputLimits":{"images":{"resize":{"maxWidth":2000,"maxHeight":2000,"maxBytes":4718592,"jpegQuality":80}}},"type":"chat"},"chat:claude-opus-5-5":{"id":"claude-opus-5-5","name":"Claude Opus 5.5","reasoning":true,"thinkingLevelMap":{"off":null,"minimal":null,"low":"low","medium":"medium","high":"high","xhigh":"xhigh","max":"max"},"input":["text","image"],"contextWindow":1000000,"maxTokens":128000,"lab":"Anthropic","cost":{"input":4,"output":20,"cacheRead":0.2,"cacheWrite":5},"enabled":true,"providers":[{"id":"anthropic","name":"Anthropic","credential":"radius","source":"radius"}],"api":"pi-messages","provider":"radius","baseUrl":"https://radius.pi.dev/v1","inputLimits":{"images":{"resize":{"maxWidth":2000,"maxHeight":2000,"maxBytes":4718592,"jpegQuality":80}}},"type":"chat"},"chat:claude-sonnet-4-5":{"id":"claude-sonnet-4-5","name":"Claude Sonnet 4.5","reasoning":true,"input":["text","image"],"contextWindow":1000000,"maxTokens":64000,"lab":"Anthropic","cost":{"input":3,"output":15,"cacheRead":0.3,"cacheWrite":3.75},"enabled":true,"providers":[{"id":"anthropic","name":"Anthropic","credential":"radius","source":"radius"}],"api":"pi-messages","provider":"radius","baseUrl":"https://radius.pi.dev/v1","inputLimits":{"images":{"resize":{"maxWidth":2000,"maxHeight":2000,"maxBytes":4718592,"jpegQuality":80}}},"type":"chat"},"chat:claude-sonnet-5":{"id":"claude-sonnet-5","name":"Claude Sonnet 5","reasoning":true,"thinkingLevelMap":{"xhigh":"xhigh","max":"max"},"input":["text","image"],"contextWindow":1000000,"maxTokens":128000,"lab":"Anthropic","cost":{"input":2,"output":10,"cacheRead":0.2,"cacheWrite":2.5},"enabled":true,"providers":[{"id":"anthropic","name":"Anthropic","credential":"radius","source":"radius"}],"api":"pi-messages","provider":"radius","baseUrl":"https://radius.pi.dev/v1","inputLimits":{"images":{"resize":{"maxWidth":2000,"maxHeight":2000,"maxBytes":4718592,"jpegQuality":80}}},"type":"chat"},"chat:claude-sonnet-5-5":{"id":"claude-sonnet-5-5","name":"Claude Sonnet 5.5","reasoning":true,"thinkingLevelMap":{"off":null,"minimal":null,"low":"low","medium":"medium","high":"high","xhigh":"xhigh","max":"max"},"input":["text","image"],"contextWindow":1000000,"maxTokens":128000,"lab":"Anthropic","cost":{"input":2,"output":10,"cacheRead":0.2,"cacheWrite":2.5},"enabled":true,"providers":[{"id":"anthropic","name":"Anthropic","credential":"radius","source":"radius"}],"api":"pi-messages","provider":"radius","baseUrl":"https://radius.pi.dev/v1","inputLimits":{"images":{"resize":{"maxWidth":2000,"maxHeight":2000,"maxBytes":4718592,"jpegQuality":80}}},"type":"chat"},"chat:deepseek-v4.1-flash":{"id":"deepseek-v4.1-flash","name":"DeepSeek V4.1 Flash","reasoning":true,"thinkingLevelMap":{"off":"none","minimal":null,"low":"low","medium":null,"high":"high","xhigh":null,"max":"max"},"input":["text","image"],"contextWindow":1000000,"maxTokens":32768,"lab":"DeepSeek","cost":{"input":0.22,"output":0.66,"cacheRead":0.007,"cacheWrite":0},"enabled":true,"providers":[{"id":"fireworks","name":"Fireworks AI","credential":"radius","source":"radius"},{"id":"relace","name":"Relace","credential":"radius","source":"radius"},{"id":"baseten","name":"Baseten","credential":"radius","source":"radius"}],"api":"pi-messages","provider":"radius","baseUrl":"https://radius.pi.dev/v1","inputLimits":{"images":{"resize":{"maxWidth":2000,"maxHeight":2000,"maxBytes":4718592,"jpegQuality":80}}},"type":"chat"},"chat:glm-5.3":{"id":"glm-5.3","name":"GLM-5.3","reasoning":true,"thinkingLevelMap":{"off":null,"minimal":"minimal","low":"low","medium":"medium","high":"high","xhigh":"xhigh","max":"xhigh"},"input":["text"],"contextWindow":1000000,"maxTokens":131072,"lab":"Z.ai","cost":{"input":1.4,"output":4.4,"cacheRead":0.26,"cacheWrite":0},"enabled":true,"providers":[{"id":"sference","name":"sference","credential":"radius","source":"radius"},{"id":"fireworks","name":"Fireworks AI","credential":"radius","source":"radius"},{"id":"baseten","name":"Baseten","credential":"radius","source":"radius"},{"id":"deepinfra","name":"DeepInfra","credential":"radius","source":"radius"}],"api":"pi-messages","provider":"radius","baseUrl":"https://radius.pi.dev/v1","type":"chat"},"chat:glm-5.3-flash":{"id":"glm-5.3-flash","name":"GLM-5.3 Flash","reasoning":true,"thinkingLevelMap":{"off":null,"minimal":null,"low":"low","medium":null,"high":"high","xhigh":null,"max":"max"},"input":["text"],"contextWindow":1000000,"maxTokens":131072,"lab":"Z.ai","cost":{"input":0.15,"output":0.5,"cacheRead":0.03,"cacheWrite":0},"enabled":true,"providers":[{"id":"fireworks","name":"Fireworks AI","credential":"radius","source":"radius"},{"id":"relace","name":"Relace","credential":"radius","source":"radius"},{"id":"baseten","name":"Baseten","credential":"radius","source":"radius"},{"id":"sference","name":"sference","credential":"radius","source":"radius"},{"id":"deepinfra","name":"DeepInfra","credential":"radius","source":"radius"}],"api":"pi-messages","provider":"radius","baseUrl":"https://radius.pi.dev/v1","type":"chat"},"chat:gpt-5.3-codex":{"id":"gpt-5.3-codex","name":"GPT 5.3 Codex","reasoning":true,"thinkingLevelMap":{"off":"none","minimal":null,"low":"low","medium":"medium","high":"high","xhigh":"xhigh","max":null},"input":["text","image"],"contextWindow":400000,"maxTokens":128000,"lab":"OpenAI","cost":{"input":1.75,"output":14,"cacheRead":0.175,"cacheWrite":0},"enabled":true,"providers":[{"id":"openai","name":"OpenAI","credential":"radius","source":"radius"}],"api":"pi-messages","provider":"radius","baseUrl":"https://radius.pi.dev/v1","inputLimits":{"images":{"resize":{"maxWidth":2000,"maxHeight":2000,"maxBytes":4718592,"jpegQuality":80}}},"type":"chat"},"chat:gpt-5.4":{"id":"gpt-5.4","name":"GPT 5.4","reasoning":true,"thinkingLevelMap":{"off":"none","minimal":null,"low":"low","medium":"medium","high":"high","xhigh":"xhigh","max":null},"input":["text","image"],"contextWindow":272000,"maxTokens":128000,"lab":"OpenAI","cost":{"input":2.5,"output":15,"cacheRead":0.25,"cacheWrite":0,"tiers":[{"inputTokensAbove":272000,"input":5,"output":22.5,"cacheRead":0.5,"cacheWrite":0}]},"enabled":true,"providers":[{"id":"openai","name":"OpenAI","credential":"radius","source":"radius"}],"api":"pi-messages","provider":"radius","baseUrl":"https://radius.pi.dev/v1","inputLimits":{"images":{"resize":{"maxWidth":2000,"maxHeight":2000,"maxBytes":4718592,"jpegQuality":80}}},"type":"chat"},"chat:gpt-5.4-mini":{"id":"gpt-5.4-mini","name":"GPT 5.4 Mini","reasoning":true,"thinkingLevelMap":{"off":"none","minimal":null,"low":"low","medium":"medium","high":"high","xhigh":"xhigh","max":null},"input":["text","image"],"contextWindow":400000,"maxTokens":128000,"lab":"OpenAI","cost":{"input":0.75,"output":4.5,"cacheRead":0.075,"cacheWrite":0},"enabled":true,"providers":[{"id":"openai","name":"OpenAI","credential":"radius","source":"radius"}],"api":"pi-messages","provider":"radius","baseUrl":"https://radius.pi.dev/v1","inputLimits":{"images":{"resize":{"maxWidth":2000,"maxHeight":2000,"maxBytes":4718592,"jpegQuality":80}}},"type":"chat"},"chat:gpt-5.5":{"id":"gpt-5.5","name":"GPT 5.5","reasoning":true,"thinkingLevelMap":{"off":"none","minimal":null,"low":"low","medium":"medium","high":"high","xhigh":"xhigh","max":null},"input":["text","image"],"contextWindow":272000,"maxTokens":128000,"lab":"OpenAI","cost":{"input":5,"output":30,"cacheRead":0.5,"cacheWrite":0,"tiers":[{"inputTokensAbove":272000,"input":10,"output":45,"cacheRead":1,"cacheWrite":0}]},"enabled":true,"providers":[{"id":"openai","name":"OpenAI","credential":"radius","source":"radius"}],"api":"pi-messages","provider":"radius","baseUrl":"https://radius.pi.dev/v1","inputLimits":{"images":{"resize":{"maxWidth":2000,"maxHeight":2000,"maxBytes":4718592,"jpegQuality":80}}},"type":"chat"},"chat:gpt-5.6-luna":{"id":"gpt-5.6-luna","name":"GPT 5.6 Luna","reasoning":true,"thinkingLevelMap":{"off":"none","minimal":null,"low":"low","medium":"medium","high":"high","xhigh":"xhigh","max":"max"},"input":["text","image"],"contextWindow":272000,"maxTokens":128000,"lab":"OpenAI","cost":{"input":0.2,"output":1.2,"cacheRead":0.02,"cacheWrite":0.25,"tiers":[{"inputTokensAbove":272000,"input":0.4,"output":1.8,"cacheRead":0.04,"cacheWrite":0.5}]},"enabled":true,"providers":[{"id":"openai","name":"OpenAI","credential":"radius","source":"radius"}],"api":"pi-messages","provider":"radius","baseUrl":"https://radius.pi.dev/v1","inputLimits":{"images":{"resize":{"maxWidth":2000,"maxHeight":2000,"maxBytes":4718592,"jpegQuality":80}}},"type":"chat"},"chat:gpt-5.6-sol":{"id":"gpt-5.6-sol","name":"GPT 5.6 Sol","reasoning":true,"thinkingLevelMap":{"off":"none","minimal":null,"low":"low","medium":"medium","high":"high","xhigh":"xhigh","max":"max"},"input":["text","image"],"contextWindow":272000,"maxTokens":128000,"lab":"OpenAI","cost":{"input":4,"output":20,"cacheRead":0.4,"cacheWrite":5,"tiers":[{"inputTokensAbove":272000,"input":8,"output":30,"cacheRead":0.8,"cacheWrite":10}]},"enabled":true,"providers":[{"id":"openai","name":"OpenAI","credential":"radius","source":"radius"}],"api":"pi-messages","provider":"radius","baseUrl":"https://radius.pi.dev/v1","inputLimits":{"images":{"resize":{"maxWidth":2000,"maxHeight":2000,"maxBytes":4718592,"jpegQuality":80}}},"type":"chat"},"chat:gpt-5.6-terra":{"id":"gpt-5.6-terra","name":"GPT 5.6 Terra","reasoning":true,"thinkingLevelMap":{"off":"none","minimal":null,"low":"low","medium":"medium","high":"high","xhigh":"xhigh","max":"max"},"input":["text","image"],"contextWindow":272000,"maxTokens":128000,"lab":"OpenAI","cost":{"input":2,"output":12,"cacheRead":0.2,"cacheWrite":2.5,"tiers":[{"inputTokensAbove":272000,"input":4,"output":18,"cacheRead":0.4,"cacheWrite":5}]},"enabled":true,"providers":[{"id":"openai","name":"OpenAI","credential":"radius","source":"radius"}],"api":"pi-messages","provider":"radius","baseUrl":"https://radius.pi.dev/v1","inputLimits":{"images":{"resize":{"maxWidth":2000,"maxHeight":2000,"maxBytes":4718592,"jpegQuality":80}}},"type":"chat"},"chat:gpt-6-astra":{"id":"gpt-6-astra","name":"GPT 6 Astra","reasoning":true,"thinkingLevelMap":{"off":null,"minimal":null,"low":"low","medium":"medium","high":"high","xhigh":"xhigh","max":"max"},"input":["text","image"],"contextWindow":272000,"maxTokens":128000,"lab":"OpenAI","cost":{"input":10,"output":50,"cacheRead":1,"cacheWrite":12.5,"tiers":[{"inputTokensAbove":272000,"input":20,"output":75,"cacheRead":2,"cacheWrite":25}]},"enabled":true,"providers":[{"id":"openai","name":"OpenAI","credential":"radius","source":"radius"}],"api":"pi-messages","provider":"radius","baseUrl":"https://radius.pi.dev/v1","inputLimits":{"images":{"resize":{"maxWidth":2000,"maxHeight":2000,"maxBytes":4718592,"jpegQuality":80}}},"type":"chat"},"chat:gpt-6-luna":{"id":"gpt-6-luna","name":"GPT 6 Luna","reasoning":true,"thinkingLevelMap":{"off":"none","minimal":null,"low":"low","medium":"medium","high":"high","xhigh":"xhigh","max":"max"},"input":["text","image"],"contextWindow":1050000,"maxTokens":128000,"lab":"OpenAI","cost":{"input":0.1,"output":0.5,"cacheRead":0.01,"cacheWrite":0.125,"tiers":[{"inputTokensAbove":272000,"input":0.2,"output":0.75,"cacheRead":0.02,"cacheWrite":0.25}]},"enabled":true,"providers":[{"id":"openai","name":"OpenAI","credential":"radius","source":"radius"}],"api":"pi-messages","provider":"radius","baseUrl":"https://radius.pi.dev/v1","inputLimits":{"images":{"resize":{"maxWidth":2000,"maxHeight":2000,"maxBytes":4718592,"jpegQuality":80}}},"type":"chat"},"chat:gpt-6-sol":{"id":"gpt-6-sol","name":"GPT 6 Sol","reasoning":true,"thinkingLevelMap":{"off":"none","minimal":null,"low":"low","medium":"medium","high":"high","xhigh":"xhigh","max":"max"},"input":["text","image"],"contextWindow":1050000,"maxTokens":128000,"lab":"OpenAI","cost":{"input":2,"output":10,"cacheRead":0.2,"cacheWrite":2.5,"tiers":[{"inputTokensAbove":272000,"input":4,"output":15,"cacheRead":0.4,"cacheWrite":5}]},"enabled":true,"providers":[{"id":"openai","name":"OpenAI","credential":"radius","source":"radius"}],"api":"pi-messages","provider":"radius","baseUrl":"https://radius.pi.dev/v1","inputLimits":{"images":{"resize":{"maxWidth":2000,"maxHeight":2000,"maxBytes":4718592,"jpegQuality":80}}},"type":"chat"},"chat:grok-4.7":{"id":"grok-4.7","name":"Grok 4.7","reasoning":true,"thinkingLevelMap":{"off":null,"minimal":null,"low":"low","medium":"medium","high":"high","xhigh":"xhigh","max":null},"input":["text","image"],"contextWindow":500000,"maxTokens":500000,"lab":"xAI","cost":{"input":2,"output":6,"cacheRead":0.5,"cacheWrite":0,"tiers":[{"inputTokensAbove":200000,"input":4,"output":12,"cacheRead":1,"cacheWrite":0}]},"enabled":true,"providers":[{"id":"xai","name":"xAI","credential":"radius","source":"radius"}],"api":"pi-messages","provider":"radius","baseUrl":"https://radius.pi.dev/v1","inputLimits":{"images":{"resize":{"maxWidth":2000,"maxHeight":2000,"maxBytes":4718592,"jpegQuality":80}}},"type":"chat"},"chat:kimi-k3":{"id":"kimi-k3","name":"Kimi K3","reasoning":true,"thinkingLevelMap":{"off":null,"minimal":null,"low":"low","medium":null,"high":"high","xhigh":null,"max":"max"},"input":["text","image"],"contextWindow":1048576,"maxTokens":131072,"lab":"Moonshot AI","cost":{"input":3,"output":15,"cacheRead":0.3,"cacheWrite":0},"enabled":true,"providers":[{"id":"fireworks","name":"Fireworks AI","credential":"radius","source":"radius"},{"id":"relace","name":"Relace","credential":"radius","source":"radius"},{"id":"sference","name":"sference","credential":"radius","source":"radius"},{"id":"baseten","name":"Baseten","credential":"radius","source":"radius"}],"api":"pi-messages","provider":"radius","baseUrl":"https://radius.pi.dev/v1","inputLimits":{"images":{"resize":{"maxWidth":2000,"maxHeight":2000,"maxBytes":4718592,"jpegQuality":80}}},"type":"chat"},"chat:precise":{"id":"precise","name":"Precise","reasoning":true,"thinkingLevelMap":{"off":"none","minimal":null,"low":"low","medium":"medium","high":"high","xhigh":"xhigh","max":"max"},"input":["text","image"],"contextWindow":272000,"maxTokens":128000,"lab":"OpenAI","cost":{"input":4,"output":20,"cacheRead":0.4,"cacheWrite":5,"tiers":[{"inputTokensAbove":272000,"input":8,"output":30,"cacheRead":0.8,"cacheWrite":10}]},"enabled":true,"providers":[{"id":"openai","name":"OpenAI","credential":"radius","source":"radius"}],"api":"pi-messages","provider":"radius","baseUrl":"https://radius.pi.dev/v1","inputLimits":{"images":{"resize":{"maxWidth":2000,"maxHeight":2000,"maxBytes":4718592,"jpegQuality":80}}},"type":"chat"}}}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Tool, ToolCall } from "../types.ts";
|
|
2
|
+
export declare function omitOptionalNulls(value: unknown, schema: Tool["parameters"]): void;
|
|
2
3
|
/**
|
|
3
4
|
* Finds a tool by name and validates the tool call arguments against its TypeBox schema
|
|
4
5
|
* @param tools Array of tool definitions
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../src/utils/validation.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../src/utils/validation.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AA2QlD,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,YAAY,CAAC,GAAG,IAAI,CAElF;AA0BD;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,QAAQ,EAAE,QAAQ,GAAG,GAAG,CAMvE;AAED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,GAAG,GAAG,CAiCzE"}
|
package/dist/utils/validation.js
CHANGED
|
@@ -234,6 +234,9 @@ function normalizeOptionalNulls(value, schema) {
|
|
|
234
234
|
}
|
|
235
235
|
}
|
|
236
236
|
}
|
|
237
|
+
export function omitOptionalNulls(value, schema) {
|
|
238
|
+
normalizeOptionalNulls(value, schema);
|
|
239
|
+
}
|
|
237
240
|
function getValidator(schema) {
|
|
238
241
|
const key = schema;
|
|
239
242
|
const cached = validatorCache.get(key);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validation.js","sourceRoot":"","sources":["../../src/utils/validation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAE1C,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAGtC,MAAM,cAAc,GAAG,IAAI,OAAO,EAAsC,CAAC;AACzE,MAAM,YAAY,GAAG,MAAM,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;AAahD,SAAS,cAAc,CAAC,MAAwB;IAC/C,IAAI,OAAO,MAAM,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;QACrC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACtB,CAAC;IACD,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,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AC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC;YAClD,CAAC;QACF,CAAC;IACF,CAAC;IAED,IAAI,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;QAC3B,OAAO,IAAI,CAAC;IACb,CAAC;IAED,MAAM,MAAM,GACX,SAAS;SACP,MAAM,CAAC,IAAI,CAAC;SACZ,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,oBAAoB,CAAC,KAAK,CAAC,KAAK,KAAK,CAAC,OAAO,EAAE,CAAC;SACtE,IAAI,CAAC,IAAI,CAAC,IAAI,0BAA0B,CAAC;IAE5C,MAAM,YAAY,GAAG,+BAA+B,QAAQ,CAAC,IAAI,OAAO,MAAM,4BAA4B,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC;IAExJ,MAAM,IAAI,KAAK,CAAC,YAAY,CAAC,CAAC;AAC/B,CAAC","sourcesContent":["import { Compile } from \"typebox/compile\";\nimport type { TLocalizedValidationError } from \"typebox/error\";\nimport { Value } from \"typebox/value\";\nimport type { Tool, ToolCall } from \"../types.ts\";\n\nconst validatorCache = new WeakMap<object, ReturnType<typeof Compile>>();\nconst TYPEBOX_KIND = Symbol.for(\"TypeBox.Kind\");\n\ninterface JsonSchemaObject {\n\ttype?: string | string[];\n\tproperties?: Record<string, JsonSchemaObject>;\n\trequired?: string[];\n\titems?: JsonSchemaObject | JsonSchemaObject[];\n\tadditionalProperties?: boolean | JsonSchemaObject;\n\tallOf?: JsonSchemaObject[];\n\tanyOf?: JsonSchemaObject[];\n\toneOf?: JsonSchemaObject[];\n}\n\nfunction getSchemaTypes(schema: JsonSchemaObject): string[] {\n\tif (typeof schema.type === \"string\") {\n\t\treturn [schema.type];\n\t}\n\tif (Array.isArray(schema.type)) {\n\t\treturn schema.type.filter((type): type is string => typeof type === \"string\");\n\t}\n\treturn [];\n}\n\nfunction matchesJsonType(value: unknown, type: string): boolean {\n\tswitch (type) {\n\t\tcase \"number\":\n\t\t\treturn typeof value === \"number\";\n\t\tcase \"integer\":\n\t\t\treturn typeof value === \"number\" && Number.isInteger(value);\n\t\tcase \"boolean\":\n\t\t\treturn typeof value === \"boolean\";\n\t\tcase \"string\":\n\t\t\treturn typeof value === \"string\";\n\t\tcase \"null\":\n\t\t\treturn value === null;\n\t\tcase \"array\":\n\t\t\treturn Array.isArray(value);\n\t\tcase \"object\":\n\t\t\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n\t\tdefault:\n\t\t\treturn false;\n\t}\n}\n\nfunction getSubSchemaValidator(schema: JsonSchemaObject): ReturnType<typeof Compile> | undefined {\n\ttry {\n\t\treturn getValidator(schema as Tool[\"parameters\"]);\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nfunction coercePrimitiveByType(value: unknown, type: string): unknown {\n\tswitch (type) {\n\t\tcase \"number\": {\n\t\t\tif (value === null) {\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t\tif (typeof value === \"string\" && value.trim() !== \"\") {\n\t\t\t\tconst parsed = Number(value);\n\t\t\t\tif (Number.isFinite(parsed)) {\n\t\t\t\t\treturn parsed;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (typeof value === \"boolean\") {\n\t\t\t\treturn value ? 1 : 0;\n\t\t\t}\n\t\t\treturn value;\n\t\t}\n\t\tcase \"integer\": {\n\t\t\tif (value === null) {\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t\tif (typeof value === \"string\" && value.trim() !== \"\") {\n\t\t\t\tconst parsed = Number(value);\n\t\t\t\tif (Number.isInteger(parsed)) {\n\t\t\t\t\treturn parsed;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (typeof value === \"boolean\") {\n\t\t\t\treturn value ? 1 : 0;\n\t\t\t}\n\t\t\treturn value;\n\t\t}\n\t\tcase \"boolean\": {\n\t\t\tif (value === null) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tif (typeof value === \"string\") {\n\t\t\t\tif (value === \"true\") {\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t\tif (value === \"false\") {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (typeof value === \"number\") {\n\t\t\t\tif (value === 1) {\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t\tif (value === 0) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn value;\n\t\t}\n\t\tcase \"string\": {\n\t\t\tif (value === null) {\n\t\t\t\treturn \"\";\n\t\t\t}\n\t\t\tif (typeof value === \"number\" || typeof value === \"boolean\") {\n\t\t\t\treturn String(value);\n\t\t\t}\n\t\t\treturn value;\n\t\t}\n\t\tcase \"null\": {\n\t\t\tif (value === \"\" || value === 0 || value === false) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\treturn value;\n\t\t}\n\t\tdefault:\n\t\t\treturn value;\n\t}\n}\n\nfunction applySchemaObjectCoercion(value: Record<string, unknown>, schema: JsonSchemaObject): void {\n\tconst properties = schema.properties;\n\tconst definedKeys = new Set<string>(properties ? Object.keys(properties) : []);\n\n\tif (properties) {\n\t\tfor (const [key, propertySchema] of Object.entries(properties)) {\n\t\t\tif (!(key in value)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tvalue[key] = coerceWithJsonSchema(value[key], propertySchema);\n\t\t}\n\t}\n\n\tif (schema.additionalProperties && typeof schema.additionalProperties === \"object\") {\n\t\tfor (const [key, propertyValue] of Object.entries(value)) {\n\t\t\tif (definedKeys.has(key)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tvalue[key] = coerceWithJsonSchema(propertyValue, schema.additionalProperties);\n\t\t}\n\t}\n}\n\nfunction applySchemaArrayCoercion(value: unknown[], schema: JsonSchemaObject): void {\n\tif (Array.isArray(schema.items)) {\n\t\tfor (let index = 0; index < value.length; index++) {\n\t\t\tconst itemSchema = schema.items[index];\n\t\t\tif (!itemSchema) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tvalue[index] = coerceWithJsonSchema(value[index], itemSchema);\n\t\t}\n\t\treturn;\n\t}\n\n\tif (schema.items && typeof schema.items === \"object\") {\n\t\tfor (let index = 0; index < value.length; index++) {\n\t\t\tvalue[index] = coerceWithJsonSchema(value[index], schema.items);\n\t\t}\n\t}\n}\n\nfunction coerceWithUnionSchema(value: unknown, schemas: JsonSchemaObject[]): unknown {\n\tfor (const schema of schemas) {\n\t\tconst validator = getSubSchemaValidator(schema);\n\t\tif (validator?.Check(value)) {\n\t\t\treturn value;\n\t\t}\n\t}\n\n\tfor (const schema of schemas) {\n\t\tconst candidate = structuredClone(value);\n\t\tconst coerced = coerceWithJsonSchema(candidate, schema);\n\t\tconst validator = getSubSchemaValidator(schema);\n\t\tif (validator?.Check(coerced)) {\n\t\t\treturn coerced;\n\t\t}\n\t}\n\treturn value;\n}\n\nfunction coerceWithJsonSchema(value: unknown, schema: JsonSchemaObject): unknown {\n\tlet nextValue = value;\n\n\tif (Array.isArray(schema.allOf)) {\n\t\tfor (const nested of schema.allOf) {\n\t\t\tnextValue = coerceWithJsonSchema(nextValue, nested);\n\t\t}\n\t}\n\n\tif (Array.isArray(schema.anyOf)) {\n\t\tnextValue = coerceWithUnionSchema(nextValue, schema.anyOf);\n\t}\n\n\tif (Array.isArray(schema.oneOf)) {\n\t\tnextValue = coerceWithUnionSchema(nextValue, schema.oneOf);\n\t}\n\n\tconst schemaTypes = getSchemaTypes(schema);\n\tconst matchesUnionMember =\n\t\tschemaTypes.length > 1 && schemaTypes.some((schemaType) => matchesJsonType(nextValue, schemaType));\n\tif (schemaTypes.length > 0 && !matchesUnionMember) {\n\t\tfor (const schemaType of schemaTypes) {\n\t\t\tconst candidate = coercePrimitiveByType(nextValue, schemaType);\n\t\t\tif (candidate !== nextValue) {\n\t\t\t\tnextValue = candidate;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tif (\n\t\tschemaTypes.includes(\"object\") &&\n\t\ttypeof nextValue === \"object\" &&\n\t\tnextValue !== null &&\n\t\t!Array.isArray(nextValue)\n\t) {\n\t\tapplySchemaObjectCoercion(nextValue as Record<string, unknown>, schema);\n\t}\n\n\tif (schemaTypes.includes(\"array\") && Array.isArray(nextValue)) {\n\t\tapplySchemaArrayCoercion(nextValue, schema);\n\t}\n\n\treturn nextValue;\n}\n\nfunction normalizeOptionalNulls(value: unknown, schema: JsonSchemaObject): void {\n\tif (Array.isArray(value)) {\n\t\tif (Array.isArray(schema.items)) {\n\t\t\tfor (let index = 0; index < value.length; index++) {\n\t\t\t\tconst itemSchema = schema.items[index];\n\t\t\t\tif (itemSchema) normalizeOptionalNulls(value[index], itemSchema);\n\t\t\t}\n\t\t} else if (schema.items) {\n\t\t\tfor (const item of value) normalizeOptionalNulls(item, schema.items);\n\t\t}\n\t\treturn;\n\t}\n\tif (typeof value !== \"object\" || value === null || !schema.properties) return;\n\n\tconst object = value as Record<string, unknown>;\n\tconst required = new Set(schema.required ?? []);\n\tfor (const [key, propertySchema] of Object.entries(schema.properties)) {\n\t\tif (!(key in object)) continue;\n\t\tif (\n\t\t\tobject[key] === null &&\n\t\t\t!required.has(key) &&\n\t\t\ttypeof (propertySchema as { $ref?: unknown }).$ref !== \"string\" &&\n\t\t\tgetSubSchemaValidator(propertySchema)?.Check(null) === false\n\t\t) {\n\t\t\tdelete object[key];\n\t\t} else {\n\t\t\tnormalizeOptionalNulls(object[key], propertySchema);\n\t\t}\n\t}\n}\n\nfunction getValidator(schema: Tool[\"parameters\"]): ReturnType<typeof Compile> {\n\tconst key = schema as object;\n\tconst cached = validatorCache.get(key);\n\tif (cached) {\n\t\treturn cached;\n\t}\n\tconst validator = Compile(schema);\n\tvalidatorCache.set(key, validator);\n\treturn validator;\n}\n\nfunction formatValidationPath(error: TLocalizedValidationError): string {\n\tif (error.keyword === \"required\") {\n\t\tconst requiredProperties = (error.params as { requiredProperties?: string[] }).requiredProperties;\n\t\tconst requiredProperty = requiredProperties?.[0];\n\t\tif (requiredProperty) {\n\t\t\tconst basePath = error.instancePath.replace(/^\\//, \"\").replace(/\\//g, \".\");\n\t\t\treturn basePath ? `${basePath}.${requiredProperty}` : requiredProperty;\n\t\t}\n\t}\n\tconst path = error.instancePath.replace(/^\\//, \"\").replace(/\\//g, \".\");\n\treturn path || \"root\";\n}\n\n/**\n * Finds a tool by name and validates the tool call arguments against its TypeBox schema\n * @param tools Array of tool definitions\n * @param toolCall The tool call from the LLM\n * @returns The validated arguments\n * @throws Error if tool is not found or validation fails\n */\nexport function validateToolCall(tools: Tool[], toolCall: ToolCall): any {\n\tconst tool = tools.find((t) => t.name === toolCall.name);\n\tif (!tool) {\n\t\tthrow new Error(`Tool \"${toolCall.name}\" not found`);\n\t}\n\treturn validateToolArguments(tool, toolCall);\n}\n\n/**\n * Validates tool call arguments against the tool's TypeBox schema\n * @param tool The tool definition with TypeBox schema\n * @param toolCall The tool call from the LLM\n * @returns The validated (and potentially coerced) arguments\n * @throws Error with formatted message if validation fails\n */\nexport function validateToolArguments(tool: Tool, toolCall: ToolCall): any {\n\tconst args = structuredClone(toolCall.arguments);\n\tnormalizeOptionalNulls(args, tool.parameters as JsonSchemaObject);\n\tValue.Convert(tool.parameters, args);\n\n\tconst validator = getValidator(tool.parameters);\n\tif (!Object.getOwnPropertySymbols(tool.parameters).includes(TYPEBOX_KIND)) {\n\t\tconst coerced = coerceWithJsonSchema(args, tool.parameters as JsonSchemaObject);\n\t\tif (coerced !== args) {\n\t\t\tif (typeof args === \"object\" && args !== null && typeof coerced === \"object\" && coerced !== null) {\n\t\t\t\tfor (const key of Object.keys(args)) {\n\t\t\t\t\tdelete args[key];\n\t\t\t\t}\n\t\t\t\tObject.assign(args, coerced);\n\t\t\t} else {\n\t\t\t\treturn validator.Check(coerced) ? coerced : args;\n\t\t\t}\n\t\t}\n\t}\n\n\tif (validator.Check(args)) {\n\t\treturn args;\n\t}\n\n\tconst errors =\n\t\tvalidator\n\t\t\t.Errors(args)\n\t\t\t.map((error) => ` - ${formatValidationPath(error)}: ${error.message}`)\n\t\t\t.join(\"\\n\") || \"Unknown validation error\";\n\n\tconst errorMessage = `Validation failed for tool \"${toolCall.name}\":\\n${errors}\\n\\nReceived arguments:\\n${JSON.stringify(toolCall.arguments, null, 2)}`;\n\n\tthrow new Error(errorMessage);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"validation.js","sourceRoot":"","sources":["../../src/utils/validation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAE1C,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAGtC,MAAM,cAAc,GAAG,IAAI,OAAO,EAAsC,CAAC;AACzE,MAAM,YAAY,GAAG,MAAM,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;AAahD,SAAS,cAAc,CAAC,MAAwB;IAC/C,IAAI,OAAO,MAAM,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;QACrC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACtB,CAAC;IACD,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;QAChC,OAAO,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,EAAkB,EAAE,CAAC,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC;IAC/E,CAAC;IACD,OAAO,EAAE,CAAC;AACX,CAAC;AAED,SAAS,eAAe,CAAC,KAAc,EAAE,IAAY;IACpD,QAAQ,IAAI,EAAE,CAAC;QACd,KAAK,QAAQ;YACZ,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC;QAClC,KAAK,SAAS;YACb,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QAC7D,KAAK,SAAS;YACb,OAAO,OAAO,KAAK,KAAK,SAAS,CAAC;QACnC,KAAK,QAAQ;YACZ,OAAO,OAAO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BAA0B,CAAC;IAE5C,MAAM,YAAY,GAAG,+BAA+B,QAAQ,CAAC,IAAI,OAAO,MAAM,4BAA4B,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC;IAExJ,MAAM,IAAI,KAAK,CAAC,YAAY,CAAC,CAAC;AAC/B,CAAC","sourcesContent":["import { Compile } from \"typebox/compile\";\nimport type { TLocalizedValidationError } from \"typebox/error\";\nimport { Value } from \"typebox/value\";\nimport type { Tool, ToolCall } from \"../types.ts\";\n\nconst validatorCache = new WeakMap<object, ReturnType<typeof Compile>>();\nconst TYPEBOX_KIND = Symbol.for(\"TypeBox.Kind\");\n\ninterface JsonSchemaObject {\n\ttype?: string | string[];\n\tproperties?: Record<string, JsonSchemaObject>;\n\trequired?: string[];\n\titems?: JsonSchemaObject | JsonSchemaObject[];\n\tadditionalProperties?: boolean | JsonSchemaObject;\n\tallOf?: JsonSchemaObject[];\n\tanyOf?: JsonSchemaObject[];\n\toneOf?: JsonSchemaObject[];\n}\n\nfunction getSchemaTypes(schema: JsonSchemaObject): string[] {\n\tif (typeof schema.type === \"string\") {\n\t\treturn [schema.type];\n\t}\n\tif (Array.isArray(schema.type)) {\n\t\treturn schema.type.filter((type): type is string => typeof type === \"string\");\n\t}\n\treturn [];\n}\n\nfunction matchesJsonType(value: unknown, type: string): boolean {\n\tswitch (type) {\n\t\tcase \"number\":\n\t\t\treturn typeof value === \"number\";\n\t\tcase \"integer\":\n\t\t\treturn typeof value === \"number\" && Number.isInteger(value);\n\t\tcase \"boolean\":\n\t\t\treturn typeof value === \"boolean\";\n\t\tcase \"string\":\n\t\t\treturn typeof value === \"string\";\n\t\tcase \"null\":\n\t\t\treturn value === null;\n\t\tcase \"array\":\n\t\t\treturn Array.isArray(value);\n\t\tcase \"object\":\n\t\t\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n\t\tdefault:\n\t\t\treturn false;\n\t}\n}\n\nfunction getSubSchemaValidator(schema: JsonSchemaObject): ReturnType<typeof Compile> | undefined {\n\ttry {\n\t\treturn getValidator(schema as Tool[\"parameters\"]);\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nfunction coercePrimitiveByType(value: unknown, type: string): unknown {\n\tswitch (type) {\n\t\tcase \"number\": {\n\t\t\tif (value === null) {\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t\tif (typeof value === \"string\" && value.trim() !== \"\") {\n\t\t\t\tconst parsed = Number(value);\n\t\t\t\tif (Number.isFinite(parsed)) {\n\t\t\t\t\treturn parsed;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (typeof value === \"boolean\") {\n\t\t\t\treturn value ? 1 : 0;\n\t\t\t}\n\t\t\treturn value;\n\t\t}\n\t\tcase \"integer\": {\n\t\t\tif (value === null) {\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t\tif (typeof value === \"string\" && value.trim() !== \"\") {\n\t\t\t\tconst parsed = Number(value);\n\t\t\t\tif (Number.isInteger(parsed)) {\n\t\t\t\t\treturn parsed;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (typeof value === \"boolean\") {\n\t\t\t\treturn value ? 1 : 0;\n\t\t\t}\n\t\t\treturn value;\n\t\t}\n\t\tcase \"boolean\": {\n\t\t\tif (value === null) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tif (typeof value === \"string\") {\n\t\t\t\tif (value === \"true\") {\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t\tif (value === \"false\") {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (typeof value === \"number\") {\n\t\t\t\tif (value === 1) {\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t\tif (value === 0) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn value;\n\t\t}\n\t\tcase \"string\": {\n\t\t\tif (value === null) {\n\t\t\t\treturn \"\";\n\t\t\t}\n\t\t\tif (typeof value === \"number\" || typeof value === \"boolean\") {\n\t\t\t\treturn String(value);\n\t\t\t}\n\t\t\treturn value;\n\t\t}\n\t\tcase \"null\": {\n\t\t\tif (value === \"\" || value === 0 || value === false) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\treturn value;\n\t\t}\n\t\tdefault:\n\t\t\treturn value;\n\t}\n}\n\nfunction applySchemaObjectCoercion(value: Record<string, unknown>, schema: JsonSchemaObject): void {\n\tconst properties = schema.properties;\n\tconst definedKeys = new Set<string>(properties ? Object.keys(properties) : []);\n\n\tif (properties) {\n\t\tfor (const [key, propertySchema] of Object.entries(properties)) {\n\t\t\tif (!(key in value)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tvalue[key] = coerceWithJsonSchema(value[key], propertySchema);\n\t\t}\n\t}\n\n\tif (schema.additionalProperties && typeof schema.additionalProperties === \"object\") {\n\t\tfor (const [key, propertyValue] of Object.entries(value)) {\n\t\t\tif (definedKeys.has(key)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tvalue[key] = coerceWithJsonSchema(propertyValue, schema.additionalProperties);\n\t\t}\n\t}\n}\n\nfunction applySchemaArrayCoercion(value: unknown[], schema: JsonSchemaObject): void {\n\tif (Array.isArray(schema.items)) {\n\t\tfor (let index = 0; index < value.length; index++) {\n\t\t\tconst itemSchema = schema.items[index];\n\t\t\tif (!itemSchema) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tvalue[index] = coerceWithJsonSchema(value[index], itemSchema);\n\t\t}\n\t\treturn;\n\t}\n\n\tif (schema.items && typeof schema.items === \"object\") {\n\t\tfor (let index = 0; index < value.length; index++) {\n\t\t\tvalue[index] = coerceWithJsonSchema(value[index], schema.items);\n\t\t}\n\t}\n}\n\nfunction coerceWithUnionSchema(value: unknown, schemas: JsonSchemaObject[]): unknown {\n\tfor (const schema of schemas) {\n\t\tconst validator = getSubSchemaValidator(schema);\n\t\tif (validator?.Check(value)) {\n\t\t\treturn value;\n\t\t}\n\t}\n\n\tfor (const schema of schemas) {\n\t\tconst candidate = structuredClone(value);\n\t\tconst coerced = coerceWithJsonSchema(candidate, schema);\n\t\tconst validator = getSubSchemaValidator(schema);\n\t\tif (validator?.Check(coerced)) {\n\t\t\treturn coerced;\n\t\t}\n\t}\n\treturn value;\n}\n\nfunction coerceWithJsonSchema(value: unknown, schema: JsonSchemaObject): unknown {\n\tlet nextValue = value;\n\n\tif (Array.isArray(schema.allOf)) {\n\t\tfor (const nested of schema.allOf) {\n\t\t\tnextValue = coerceWithJsonSchema(nextValue, nested);\n\t\t}\n\t}\n\n\tif (Array.isArray(schema.anyOf)) {\n\t\tnextValue = coerceWithUnionSchema(nextValue, schema.anyOf);\n\t}\n\n\tif (Array.isArray(schema.oneOf)) {\n\t\tnextValue = coerceWithUnionSchema(nextValue, schema.oneOf);\n\t}\n\n\tconst schemaTypes = getSchemaTypes(schema);\n\tconst matchesUnionMember =\n\t\tschemaTypes.length > 1 && schemaTypes.some((schemaType) => matchesJsonType(nextValue, schemaType));\n\tif (schemaTypes.length > 0 && !matchesUnionMember) {\n\t\tfor (const schemaType of schemaTypes) {\n\t\t\tconst candidate = coercePrimitiveByType(nextValue, schemaType);\n\t\t\tif (candidate !== nextValue) {\n\t\t\t\tnextValue = candidate;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tif (\n\t\tschemaTypes.includes(\"object\") &&\n\t\ttypeof nextValue === \"object\" &&\n\t\tnextValue !== null &&\n\t\t!Array.isArray(nextValue)\n\t) {\n\t\tapplySchemaObjectCoercion(nextValue as Record<string, unknown>, schema);\n\t}\n\n\tif (schemaTypes.includes(\"array\") && Array.isArray(nextValue)) {\n\t\tapplySchemaArrayCoercion(nextValue, schema);\n\t}\n\n\treturn nextValue;\n}\n\nfunction normalizeOptionalNulls(value: unknown, schema: JsonSchemaObject): void {\n\tif (Array.isArray(value)) {\n\t\tif (Array.isArray(schema.items)) {\n\t\t\tfor (let index = 0; index < value.length; index++) {\n\t\t\t\tconst itemSchema = schema.items[index];\n\t\t\t\tif (itemSchema) normalizeOptionalNulls(value[index], itemSchema);\n\t\t\t}\n\t\t} else if (schema.items) {\n\t\t\tfor (const item of value) normalizeOptionalNulls(item, schema.items);\n\t\t}\n\t\treturn;\n\t}\n\tif (typeof value !== \"object\" || value === null || !schema.properties) return;\n\n\tconst object = value as Record<string, unknown>;\n\tconst required = new Set(schema.required ?? []);\n\tfor (const [key, propertySchema] of Object.entries(schema.properties)) {\n\t\tif (!(key in object)) continue;\n\t\tif (\n\t\t\tobject[key] === null &&\n\t\t\t!required.has(key) &&\n\t\t\ttypeof (propertySchema as { $ref?: unknown }).$ref !== \"string\" &&\n\t\t\tgetSubSchemaValidator(propertySchema)?.Check(null) === false\n\t\t) {\n\t\t\tdelete object[key];\n\t\t} else {\n\t\t\tnormalizeOptionalNulls(object[key], propertySchema);\n\t\t}\n\t}\n}\n\nexport function omitOptionalNulls(value: unknown, schema: Tool[\"parameters\"]): void {\n\tnormalizeOptionalNulls(value, schema as JsonSchemaObject);\n}\n\nfunction getValidator(schema: Tool[\"parameters\"]): ReturnType<typeof Compile> {\n\tconst key = schema as object;\n\tconst cached = validatorCache.get(key);\n\tif (cached) {\n\t\treturn cached;\n\t}\n\tconst validator = Compile(schema);\n\tvalidatorCache.set(key, validator);\n\treturn validator;\n}\n\nfunction formatValidationPath(error: TLocalizedValidationError): string {\n\tif (error.keyword === \"required\") {\n\t\tconst requiredProperties = (error.params as { requiredProperties?: string[] }).requiredProperties;\n\t\tconst requiredProperty = requiredProperties?.[0];\n\t\tif (requiredProperty) {\n\t\t\tconst basePath = error.instancePath.replace(/^\\//, \"\").replace(/\\//g, \".\");\n\t\t\treturn basePath ? `${basePath}.${requiredProperty}` : requiredProperty;\n\t\t}\n\t}\n\tconst path = error.instancePath.replace(/^\\//, \"\").replace(/\\//g, \".\");\n\treturn path || \"root\";\n}\n\n/**\n * Finds a tool by name and validates the tool call arguments against its TypeBox schema\n * @param tools Array of tool definitions\n * @param toolCall The tool call from the LLM\n * @returns The validated arguments\n * @throws Error if tool is not found or validation fails\n */\nexport function validateToolCall(tools: Tool[], toolCall: ToolCall): any {\n\tconst tool = tools.find((t) => t.name === toolCall.name);\n\tif (!tool) {\n\t\tthrow new Error(`Tool \"${toolCall.name}\" not found`);\n\t}\n\treturn validateToolArguments(tool, toolCall);\n}\n\n/**\n * Validates tool call arguments against the tool's TypeBox schema\n * @param tool The tool definition with TypeBox schema\n * @param toolCall The tool call from the LLM\n * @returns The validated (and potentially coerced) arguments\n * @throws Error with formatted message if validation fails\n */\nexport function validateToolArguments(tool: Tool, toolCall: ToolCall): any {\n\tconst args = structuredClone(toolCall.arguments);\n\tnormalizeOptionalNulls(args, tool.parameters as JsonSchemaObject);\n\tValue.Convert(tool.parameters, args);\n\n\tconst validator = getValidator(tool.parameters);\n\tif (!Object.getOwnPropertySymbols(tool.parameters).includes(TYPEBOX_KIND)) {\n\t\tconst coerced = coerceWithJsonSchema(args, tool.parameters as JsonSchemaObject);\n\t\tif (coerced !== args) {\n\t\t\tif (typeof args === \"object\" && args !== null && typeof coerced === \"object\" && coerced !== null) {\n\t\t\t\tfor (const key of Object.keys(args)) {\n\t\t\t\t\tdelete args[key];\n\t\t\t\t}\n\t\t\t\tObject.assign(args, coerced);\n\t\t\t} else {\n\t\t\t\treturn validator.Check(coerced) ? coerced : args;\n\t\t\t}\n\t\t}\n\t}\n\n\tif (validator.Check(args)) {\n\t\treturn args;\n\t}\n\n\tconst errors =\n\t\tvalidator\n\t\t\t.Errors(args)\n\t\t\t.map((error) => ` - ${formatValidationPath(error)}: ${error.message}`)\n\t\t\t.join(\"\\n\") || \"Unknown validation error\";\n\n\tconst errorMessage = `Validation failed for tool \"${toolCall.name}\":\\n${errors}\\n\\nReceived arguments:\\n${JSON.stringify(toolCall.arguments, null, 2)}`;\n\n\tthrow new Error(errorMessage);\n}\n"]}
|
package/package.json
CHANGED