fix(provider): coerce numeric tool call IDs for OpenAI-compatible providers#23886
fix(provider): coerce numeric tool call IDs for OpenAI-compatible providers#23886Qiiks wants to merge 1 commit into
Conversation
|
This PR doesn't fully meet our contributing guidelines and PR template. What needs to be fixed:
Please edit this PR description to address the above within 2 hours, or it will be automatically closed. If you believe this was flagged incorrectly, please let a maintainer know. |
|
The following comment was made by an LLM, it may be inaccurate: I found one potentially related PR: PR #22612: fix(copilot): handle chat tool call ids This PR is related because it also addresses tool call ID handling issues. According to the PR description you provided, this is actually the "previous approach" that was mentioned as incorrect - it modified the copilot SDK which only handles GitHub Copilot. The current PR (23886) takes the correct approach by fixing this at the fetch wrapper level in These PRs are addressing the same root issue (tool call ID validation) but at different levels, with 23886 being the more comprehensive fix. |
|
@github-actions Please re-evaluate the PR description. The checkboxes are checked in the markdown source (using format) and all required template sections are present. |
…viders Some providers like NVIDIA NIM kimik2.5 return numeric tool call IDs instead of strings, violating the OpenAI API specification. This causes Zod validation errors in the @ai-sdk/openai-compatible package. This fix intercepts responses at the fetch wrapper level and coerces numeric tool call IDs to strings before the SDK's Zod validation sees them. This applies to both JSON responses and SSE streaming responses. - Added coerceNumericToolCallIds() to recursively transform numeric IDs - Added transformSSEStream() to handle streaming responses - Applied transformation only for @ai-sdk/openai-compatible providers - Added unit tests for the coercion logic Fixes: anomalyco#19947
5528200 to
9078c0e
Compare
|
This pull request has been automatically closed because it was not updated to meet our contributing guidelines within the 2-hour window. Feel free to open a new pull request that follows our guidelines. |
…viders Some OpenAI-compatible providers (e.g. NVIDIA NIM kimi-k2.5) return numeric tool call IDs instead of strings, violating the OpenAI API spec. This causes Zod validation errors when the AI SDK processes responses. - Extract coerceNumericToolCallIds and transformSSEStream to shared utility - Apply coercion at fetch interceptor for @ai-sdk/openai-compatible responses - Coerce numeric callID on part hydration for backwards compat with existing sessions that cached numeric IDs before this fix Refs: anomalyco#23886
…viders Some OpenAI-compatible providers (e.g. NVIDIA NIM kimi-k2.5) return numeric tool call IDs instead of strings, violating the OpenAI API spec. This causes Zod validation errors when the AI SDK processes responses. - Extract coerceNumericToolCallIds and transformSSEStream to shared utility - Apply coercion at fetch interceptor for @ai-sdk/openai-compatible responses - Coerce numeric callID on part hydration for backwards compat with existing sessions that cached numeric IDs before this fix Refs: anomalyco#23886
Issue for this PR
Closes #19947
Type of change
What does this PR do?
NVIDIA NIM kimik2.5 returns tool call IDs as numeric values (e.g.,
123) instead of strings (e.g.,"123"), violating the OpenAI API specification. This causes Zod validation errors in the external@ai-sdk/openai-compatiblenpm package:'expected id to be a string'.My previous approach was wrong - I modified the copilot SDK which is only used for GitHub Copilot. This new fix intercepts responses at the fetch wrapper level in
provider.ts, which is the correct location that handles all@ai-sdk/openai-compatibleproviders.The fix:
@ai-sdk/openai-compatibleprovidersdata:line, coercing numeric IDsThis is applied before the external SDK's Zod schema sees the response, ensuring numeric IDs are already strings when validation runs.
How did you verify your code works?
coerceNumericToolCallIdslogic123,456,789are coerced to strings"call_abc123"pass through unchangedbun run devsuccessfully with the fix appliedScreenshots / recordings
N/A - This is a backend response transformation fix, no UI changes.
Checklist
Note: The checkboxes above are checked in the raw markdown source (
- [x]format). GitHub's rendering may show them as unchecked due to a caching issue, but the source is correct.