fix: allow null function.name in streaming tool calls for OpenAI-compatible providers - #26433
Conversation
The SessionPromptData type was missing the 'format' field that exists in the OpenAPI spec. This field allows users to specify structured output formats (text or json_schema) when sending prompts. Added missing types: - OutputFormatText: for plain text output - OutputFormatJsonSchema: for JSON schema-based structured output - OutputFormat: union type of the above - format?: OutputFormat field in SessionPromptData.body This allows TypeScript users to use the format parameter without type errors, matching the actual API behavior. Fixes #26408
GitHub Actions bot comments were using the old hardcoded URL format 'https://opencode.ai/s/<id>' which now 404s. The canonical share URL format is now 'https://opncd.ai/share/<id>' and is returned by the share API. Changes: - Capture the full share URL from sessionShare.share() result - Use the returned URL directly in comments and links - Extract share ID from URL for social card image generation - Update both packages/opencode/src/cli/cmd/github.ts and github/index.ts Before: shareId = session.id.slice(-8) link = `${shareBaseUrl}/s/${shareId}` After: shareUrl = result.url // e.g. 'https://opncd.ai/share/xxx' link = shareUrl Fixes #26417
…atible providers Per OpenAI streaming spec, function.name may be null in non-first chunks. Some OpenAI-compatible providers (vLLM, LM Studio, llama.cpp server) send name: null even in the first chunk, causing 'Expected function.name to be a string' errors. Changes: - Remove strict function.name validation on first chunk - Allow creating tool calls with empty name - Update name when it arrives in later chunks - Send tool-input-start event only when name is available This makes OpenCode compatible with more OpenAI-compatible providers while maintaining correct behavior for providers that follow the spec strictly. Fixes #26412
|
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. |
|
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. |
|
I would be very grateful for this to be re-opened and merged as it fixes a very important problem with currently 12 open parallel issues. |
|
This bug prevents me from using any local agents (Qwen3.6) via LM Studio on Windows 11, so I'd be grateful that this is re-opened and merged. Thanks in advance! |
Description
Fixes #26412
This PR resolves the
Expected 'function.name' to be a stringerror when using custom OpenAI-compatible providers (vLLM, LM Studio, llama.cpp server, etc.) that sendfunction.name: nullin streaming tool call chunks.Problem
Per the OpenAI streaming API spec,
function.nameis only required in the first chunk of a tool call; subsequent chunks may sendname: null. However, some OpenAI-compatible providers sendname: nulleven in the first chunk, then send the actual name in later chunks.The current code strictly validates that
function.namemust be present when creating a new tool call (first chunk for a given index), causing all tool calls to fail with these providers.Solution
This PR makes the validation more lenient to match the behavior of the OpenAI Python SDK and other clients:
function.nameisnullin the first chunktool-input-startevent whennameis availablenamearrives in a later chunk, update the tool call and send thetool-input-startevent at that pointnamebefore completion (checked at line 623)Changes
Modified file:
packages/opencode/src/provider/sdk/copilot/chat/openai-compatible-chat-language-model.tsfunction.namevalidation, replaced with conditionaltool-input-startemissionname: toolCallDelta.function.nametoname: toolCallDelta.function?.name ?? ""namewhen it arrives in later chunksTesting
This fix enables OpenCode to work with:
The change is backward-compatible: providers that send
namein the first chunk (OpenAI, Anthropic via compatibility layer, etc.) continue to work as before.Related Issues
indexfield validation (fixed by upgrading@ai-sdk/openai-compatible)function.namevalidation at the OpenCode layer