(FIX) lm studio empty tool calls
Fixes https://github.com/sst/opencode/issues/4255
Problem
OpenCode hangs indefinitely when using LM Studio (and other OpenAI-compatible providers) that include empty tool_calls: [] arrays in responses. The AI SDK sees the tool_calls field and waits for tool execution, but since the array is empty, it never completes.
Solution
Added middleware to filter empty tool_calls arrays from API responses before they reach the AI SDK:
-
Fetch-level filtering: Intercepts responses at the HTTP layer and removes empty
tool_calls: []whenfinish_reasonis"stop". Works for both streaming (SSE) and non-streaming responses. -
Processor fallback: Cleans up any pending tool calls that were never invoked when
finish_reasonis"stop", handling edge cases where empty arrays slip through.
The fix is applied automatically to all @ai-sdk/openai-compatible providers, ensuring LM Studio and similar providers work correctly without requiring configuration changes.