fix(ai): make chat({ stream: false }) actually non-streaming on the wire#561
Draft
tombeckenham wants to merge 1 commit into
Draft
Conversation
Adds an optional `chatNonStreaming()` method to the TextAdapter interface and a wire-level non-streaming agent loop in `runNonStreamingText`. All in-tree adapters (openai-base chat-completions + responses, openrouter, anthropic, gemini, ollama) implement it; out-of-tree adapters fall back to the legacy stream-then-concatenate behaviour. Closes #557. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
8d1c292 to
02e4765
Compare
Contributor
🚀 Changeset Version Preview9 package(s) bumped directly, 25 bumped as dependents. 🟥 Major bumps
🟨 Minor bumps
🟩 Patch bumps
|
|
View your CI Pipeline Execution ↗ for commit 02e4765
☁️ Nx Cloud last updated this comment at |
@tanstack/ai
@tanstack/ai-anthropic
@tanstack/ai-client
@tanstack/ai-code-mode
@tanstack/ai-code-mode-skills
@tanstack/ai-devtools-core
@tanstack/ai-elevenlabs
@tanstack/ai-event-client
@tanstack/ai-fal
@tanstack/ai-gemini
@tanstack/ai-grok
@tanstack/ai-groq
@tanstack/ai-isolate-cloudflare
@tanstack/ai-isolate-node
@tanstack/ai-isolate-quickjs
@tanstack/ai-ollama
@tanstack/ai-openai
@tanstack/ai-openrouter
@tanstack/ai-preact
@tanstack/ai-react
@tanstack/ai-react-ui
@tanstack/ai-solid
@tanstack/ai-solid-ui
@tanstack/ai-svelte
@tanstack/ai-utils
@tanstack/ai-vue
@tanstack/ai-vue-ui
@tanstack/openai-base
@tanstack/preact-ai-devtools
@tanstack/react-ai-devtools
@tanstack/solid-ai-devtools
commit: |
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.
Closes #557.
Summary
TextAdapter.chatNonStreaming()returningPromise<NonStreamingChatResult>({ content, reasoning?, toolCalls?, finishReason?, usage? }). When implemented,chat({ stream: false })routes through it for a true wire-level non-streaming request; when omitted, the legacy stream-then-concatenate fallback applies — out-of-tree adapters keep working unchanged.chatNonStreaming()on all in-tree adapters: openai-base chat-completions + responses (covers openai, grok, groq), openrouter (chat-completions + responses), anthropic, gemini, ollama.runNonStreamingTextas a wire-level non-streaming agent loop: call adapter → execute returned tool calls server-side → append results → repeat untilfinishReason !== 'tool_calls'oragentLoopStrategyhalts. Approval-required and pure client-side tools throw an explicit error directing callers to streaming, since they can't round-trip throughPromise<string>.Why
Previously
chat({ stream: false })invokedrunStreamingText()and concatenated the SSE response viastreamToText. The wire request still carriedAccept: text/event-streamand"stream": truein the body — only the SDK return type changed (Promise<string>instead ofAsyncIterable<StreamChunk>). On reasoning models with long pre-content thinking phases (Grok 4.3 via OpenRouter was the original repro), proxies with sub-30s socket-idle timeouts could cut off the stream mid-flight even though a real non-streaming POST would complete fine.Test plan
agentLoopStrategycap, approval-tool error, and out-of-tree fallback. Existing 757 tests still pass (762 total).api.chat.tssofeature === 'one-shot-text'actually callschat({ stream: false }). The existingone-shot-text.spec.tsnow runs end-to-end against the new path across all 8 providers (openai, anthropic, gemini, ollama, groq, grok, openrouter, openrouter-responses). Updated the aimock fixture to includesystemFingerprint: nullso OpenRouter SDK's strict zod validation accepts the response. Full e2e suite (190 tests) passes.pnpm test:lib,pnpm test:types,pnpm test:eslint,pnpm build: all clean.Notes
adapter.structuredOutputcall insiderunAgenticStructuredOutput.Promise<string>return value remains content-only — reasoning is captured on the internalNonStreamingChatResultfor future surfaces but is not part of the public contract.🤖 Generated with Claude Code