fix(gateway): safely handle non-array content in tool results#12314
Open
Ashutosh0x wants to merge 2 commits intovercel:mainfrom
Open
fix(gateway): safely handle non-array content in tool results#12314Ashutosh0x wants to merge 2 commits intovercel:mainfrom
Ashutosh0x wants to merge 2 commits intovercel:mainfrom
Conversation
## Title fix(provider-utils): ensure 'type: object' in JSON schemas for DeepSeek/OpenAI compatibility ## Body Fixes vercel#7924 ### Problem Some providers like DeepSeek and other OpenAI-compatible APIs fail when the tool/input schema is missing the explicit `type: 'object'` property, even if `properties` and `additionalProperties` are defined. ### Solution - Modified the `jsonSchema` getter in the `Schema` type to automatically add `type: 'object'` when `properties` are present but `type` is missing. - Updated the default schema returned by `asSchema(undefined)` to explicitly include `type: 'object'`. ### Impact Improves reliability for providers with stricter schema requirements (DeepSeek, etc.). ## Human-like Comment for @lgrammel Hey @lgrammel, I took a look at vercel#7924 regarding the missing `type: object` in schemas for DeepSeek and other providers. I've implemented a fix in `provider-utils` that ensures `type: 'object'` is automatically included whenever `properties` are defined. I also updated the default empty schema. Added a new test file `packages/provider-utils/src/schema-deepseek-fix.test.ts` to verify everything works as expected. Let me know if you'd like any changes!
Author
|
Hey @tea-artist, I've fixed the TypeError by adding an Array.isArray check for |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes a bug where responseBody.content was being mapped without checking if it was an array, causing TypeErrors. It adds an Array.isArray check. Fixes #12178