Repository navigation
aisdk: fix OpenAI streamed tool calls and Anthropic no-arg tools - #616
Merged
Merged
Conversation
Fixes bug-scan P0 #7 and #8 from specs/bug-scan.md. - #7: The OpenAI stream emits ToolCallDeltaEvents for a function call and then a final ToolCallEvent with the same ID. ResponseBuilder rejected that final event as a duplicate, so builder.StreamToResponse failed on every OpenAI stream containing a function call. The builder now finalizes the existing block (taking the complete args from the final event) and only errors when two complete ToolCallEvents share an ID. - #8: encodeInputSchema dereferenced a nil schema, so a FunctionTool with no InputSchema panicked when sent to Anthropic. A nil schema is now encoded as an empty object schema. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Bqy92pq662Fgv5A4GoaUD2
Adds the status as its own line under the matching "Suggested fix order" item so it doesn't conflict with the other P0 fix PRs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Bqy92pq662Fgv5A4GoaUD2
[Medium impact] The PR appears safe to merge.
|
…lace Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Bqy92pq662Fgv5A4GoaUD2
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.
Summary
Fixes P0 bugs #7 and #8 from
specs/bug-scan.md.StreamToResponsefailed on every OpenAI function call (aisdk/ai/builder/builder.go): the OpenAI Responses stream sendsToolCallDeltaEvents and then a finalToolCallEventwith the same ID.addToolCallrejected that final event as a "duplicate tool call ID". The builder now records which IDs have received a completeToolCallEvent. When a final event arrives for a block that was built from deltas, it finalizes that block and takes the full args from the final event. Two completeToolCallEvents with the same ID are still rejected as duplicates.aisdk/ai/provider/anthropic/codec/jsonschema.go):FunctionTool.InputSchemais optional, butencodeInputSchemareadschema.Typewithout a nil check. A nil schema is now encoded as{"type":"object","properties":{}}.How was it tested?
builder_test.go:duplicate tool call ID: call_1and passes with this change.ToolCallEvents with the same ID still error.encode_tools_test.go: new case for&api.FunctionTool{Name: "now"}with no input schema.go vetandgo test ./...pass inaisdk/ai.Community Contribution License
All community contributions in this pull request are licensed to the project maintainers under the terms of the Apache 2 License.
By creating this pull request I represent that I have the right to license the contributions to the project maintainers under the Apache 2 License as stated in the Community Contribution License.
Generated by Claude Code