fix(provider): coerce numeric tool call IDs for OpenAI-compatible providers#24026
fix(provider): coerce numeric tool call IDs for OpenAI-compatible providers#24026Qiiks wants to merge 2 commits into
Conversation
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
…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
3ba8daf to
63343a1
Compare
|
I tried this version on NVIDIA Nim Devstral, and the bug still persists |
|
Automated PR Cleanup Thank you for contributing to opencode. Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions. This PR was closed because it matched the following cleanup criteria:
PRs created within the last month are not affected by this cleanup. If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate. Thanks again for taking the time to contribute. |
Issue for this PR
Fixes #19947
Type of change
What does this PR do?
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.
The fix adds coercion at two points:
Fetch interceptor (
provider.ts): For@ai-sdk/openai-compatibleresponses, numeric IDs intool_calls[].idanddelta.tool_calls[].idare converted to strings before the AI SDK processes them. Both JSON and SSE streaming responses are handled.Part hydration (
message-v2.ts): For backwards compatibility, numericcallIDvalues stored in existing sessions are coerced to strings when loaded from the database.The coercion functions were extracted to a shared utility (
src/util/coerce-tool-call-ids.ts) to keep them usable across layers.How did you verify your code works?
coerceNumericToolCallIdsandtransformSSEStream(numeric coercion, string passthrough, nested objects, delta.tool_calls, SSE parsing, [DONE] passthrough, invalid JSON passthrough, multiple events)bun typecheckpasses with zero errorsChecklist