Repository navigation
Conversation
Opencode ends json_schema turns on its internal StructuredOutput tool, so the finish string contains "tool". mapFinishReason previously mapped any finish containing "tool" to tool_calls even when the proxy had already flattened schema JSON into message.content and toolCalls was empty. Vercel AI SDK Output.object only accepts structured results when the unified finish reason is stop, so clients using response_format json_schema (e.g. generateText + Output.object) threw AI_NoOutputGeneratedError despite valid JSON in message.content. Callers already set finish_reason to tool_calls / stop_reason to tool_use when toolCalls.length > 0, so real tool calling is unchanged. Apply the same fix to mapFinishReasonToAnthropic; Gemini already returned STOP.
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
Opencode ends
response_format: json_schematurns on its internal StructuredOutput tool, so the finish string contains"tool".mapFinishReasonpreviously mapped any finish containing"tool"totool_callseven when the proxy had already flattened schema JSON intomessage.contentandtoolCallswas empty.Clients using the Vercel AI SDK (
generateText+Output.object/supportsStructuredOutputs: true) only parse structured output when the unified finish reason isstop. They otherwise throwAI_NoOutputGeneratedErrordespite valid JSON inmessage.content.Fix
mapFinishReason: stop mapping"tool"→tool_calls; returnstop(callers already forcetool_callswhentoolCalls.length > 0).mapFinishReasonToAnthropic: same for"tool"→tool_use(callers forcetool_usewhen tools present).STOPfor tool finishes — unchanged.Real tool calling is unchanged:
createChatCompletionResponse/ streaming / Anthropic builders still setfinish_reason: "tool_calls"/stop_reason: "tool_use"fromtoolCalls.length.Minimal repro (before)
finish_reasontool_callsstopmessage.content{"ok":true}JSONmessage.tool_callsTest plan
npm test— 242 pass locallytoolsstill returnsfinish_reason=tool_calls+ populatedtool_callsjson_schemareturnsfinish_reason=stop+ JSONcontentNotes
main(current line including Spurious 'failed to load plugin' error on opencode 1.18.x (cosmetic — proxy still works); one-line V1 default export silences it #86 default export). CONTRIBUTING mentionsdev, butdevis behindmainand recent fixes (Spurious 'failed to load plugin' error on opencode 1.18.x (cosmetic — proxy still works); one-line V1 default export silences it #86/fix(plugin): add V1 default export descriptor to stop legacy loader probing every helper #89) landed onmain.devif preferred.