Skip to content

Conversation

@jherr
Copy link
Contributor

@jherr jherr commented Dec 23, 2025

🎯 Changes

toServerSentEventsResponse wasn't a real replacement for toServerReponse. This one is, and it has stream versions for SSE and httpStream if you want to handle the Response yourself.

βœ… Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested this code locally with pnpm run test:pr.

πŸš€ Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

Summary by CodeRabbit

  • Refactor

    • Renamed the streaming response helper to an SSE-specific helper and added a new generic HTTP streaming helper.
  • Documentation

    • Updated guides, adapter docs, API reference, examples, and config to reflect the streaming helper rename and new HTTP response helper.
  • Tests

    • Updated test suites and examples to use the renamed SSE helper and new HTTP response helper.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 23, 2025

πŸ“ Walkthrough

Walkthrough

This PR renames the SSE helper from toStreamResponse to toServerSentEventsResponse, adds a new toHttpResponse export for general HTTP streaming, and updates core exports, docs, examples, and tests to use the new names and signatures.

Changes

Cohort / File(s) Summary
Core implementation
packages/typescript/ai/src/stream-to-response.ts
Adds toServerSentEventsResponse(stream, init?); replaces toStreamResponse with toHttpResponse(stream, init?) that delegates to toHttpStream; retains SSE stream helper and abort/error semantics.
Public exports
packages/typescript/ai/src/index.ts
Removes toStreamResponse export; adds toServerSentEventsResponse and toHttpResponse exports.
Tests
packages/typescript/ai/tests/stream-to-response.test.ts
Renames test references and descriptions from toStreamResponse β†’ toServerSentEventsResponse; updates imports/call sites accordingly.
Docs β€” Reference & API
docs/reference/functions/toServerSentEventsResponse.md, docs/reference/index.md, docs/api/ai.md, docs/reference/functions/toStreamResponse.md
Adds toServerSentEventsResponse reference; removes deprecated toStreamResponse doc; updates index and API docs to new name and signature.
Docs β€” Guides & Protocol
docs/guides/*.md, docs/protocol/sse-protocol.md
Replaces toStreamResponse with toServerSentEventsResponse in examples, anchor links, and explanatory text (SSE-focused).
Docs β€” Adapters & Quick Start
docs/adapters/*.md, docs/getting-started/quick-start.md
Updates imports and returns to use toServerSentEventsResponse(stream, ...) instead of toStreamResponse.
Docs β€” Config/Index
docs/config.json, docs/reference/index.md
Updates function reference entry and link targets from toStreamResponse β†’ toServerSentEventsResponse.
Examples & App routes
examples/*/src/routes/*, testing/panel/src/routes/*.ts, examples/README.md
Replaces toServerSentEventsStream/toStreamResponse usage with toServerSentEventsResponse; removes manual ReadableStream/Response construction and returns toServerSentEventsResponse(stream, { abortController }).
Package READMEs
packages/typescript/ai-solid/README.md, examples/README.md
Updates example snippets to import/use toServerSentEventsResponse (replaces toStreamResponse).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~45 minutes

Possibly related PRs

Suggested reviewers

  • AlemTuzlak

Poem

"I hopped through code with eager paws,
Renamed a stream to cheer applause.
SSE winds now hum and play,
Responses dance the Server-Sent way.
β€” πŸ‡"

Pre-merge checks and finishing touches

βœ… Passed checks (3 passed)
Check name Status Explanation
Title check βœ… Passed The title 'feat: toServerSentEventsResponse' clearly and concisely identifies the main feature being added, which aligns with the substantial API changes throughout the codebase.
Description check βœ… Passed The description provides clear motivation, includes completed checklist items, and specifies release impact with changeset generation, meeting the template requirements.
Docstring Coverage βœ… Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • πŸ“ Generate docstrings
πŸ§ͺ Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/toServerSentEventsResponse

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❀️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@nx-cloud
Copy link

nx-cloud bot commented Dec 23, 2025

View your CI Pipeline Execution β†— for commit eb41d52

Command Status Duration Result
nx affected --targets=test:sherif,test:knip,tes... βœ… Succeeded 2m 31s View β†—
nx run-many --targets=build --exclude=examples/** βœ… Succeeded 1m 2s View β†—

☁️ Nx Cloud last updated this comment at 2025-12-24 00:09:13 UTC

@pkg-pr-new
Copy link

pkg-pr-new bot commented Dec 23, 2025

Open in StackBlitz

@tanstack/ai

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai@177

@tanstack/ai-anthropic

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-anthropic@177

@tanstack/ai-client

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-client@177

@tanstack/ai-devtools-core

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-devtools-core@177

@tanstack/ai-gemini

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-gemini@177

@tanstack/ai-ollama

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-ollama@177

@tanstack/ai-openai

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-openai@177

@tanstack/ai-react

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-react@177

@tanstack/ai-react-ui

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-react-ui@177

@tanstack/ai-solid

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-solid@177

@tanstack/ai-solid-ui

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-solid-ui@177

@tanstack/ai-svelte

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-svelte@177

@tanstack/ai-vue

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-vue@177

@tanstack/ai-vue-ui

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-vue-ui@177

@tanstack/react-ai-devtools

npm i https://pkg.pr.new/TanStack/ai/@tanstack/react-ai-devtools@177

@tanstack/solid-ai-devtools

npm i https://pkg.pr.new/TanStack/ai/@tanstack/solid-ai-devtools@177

commit: eb41d52

@jherr jherr marked this pull request as ready for review December 23, 2025 04:17
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

πŸ“œ Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between 29466c1 and 314bdfa.

πŸ“’ Files selected for processing (29)
  • docs/adapters/anthropic.md
  • docs/adapters/gemini.md
  • docs/adapters/ollama.md
  • docs/adapters/openai.md
  • docs/api/ai.md
  • docs/config.json
  • docs/getting-started/quick-start.md
  • docs/guides/agentic-cycle.md
  • docs/guides/connection-adapters.md
  • docs/guides/runtime-adapter-switching.md
  • docs/guides/server-tools.md
  • docs/guides/streaming.md
  • docs/guides/tool-approval.md
  • docs/guides/tool-architecture.md
  • docs/guides/tools.md
  • docs/protocol/sse-protocol.md
  • docs/reference/functions/toServerSentEventsResponse.md
  • docs/reference/functions/toStreamResponse.md
  • docs/reference/index.md
  • examples/README.md
  • examples/ts-react-chat/src/routes/api.tanchat.ts
  • examples/ts-solid-chat/src/routes/api.chat.ts
  • examples/ts-svelte-chat/src/routes/api/chat/+server.ts
  • packages/typescript/ai-solid/README.md
  • packages/typescript/ai/src/index.ts
  • packages/typescript/ai/src/stream-to-response.ts
  • packages/typescript/ai/tests/stream-to-response.test.ts
  • testing/panel/src/routes/api.addon-chat.ts
  • testing/panel/src/routes/api.chat.ts
πŸ’€ Files with no reviewable changes (1)
  • docs/reference/functions/toStreamResponse.md
🧰 Additional context used
πŸ““ Path-based instructions (5)
**/*.{ts,tsx}

πŸ“„ CodeRabbit inference engine (CLAUDE.md)

**/*.{ts,tsx}: Use tree-shakeable adapter architecture for provider implementations - export specialized adapters (text, embedding, summarize, image) as separate imports from /adapters subpath rather than monolithic adapters
Use Zod for runtime schema validation and type inference, particularly for tool input/output definitions with toolDefinition() and Zod schema inference
Implement isomorphic tool system using toolDefinition() with .server() and .client() implementations for dual-environment execution
Use type-safe per-model configuration with provider options typed based on selected model to ensure compile-time safety
Implement stream processing with StreamProcessor for handling chunked responses and support partial JSON parsing for streaming AI responses

Files:

  • examples/ts-solid-chat/src/routes/api.chat.ts
  • packages/typescript/ai/tests/stream-to-response.test.ts
  • examples/ts-react-chat/src/routes/api.tanchat.ts
  • examples/ts-svelte-chat/src/routes/api/chat/+server.ts
  • testing/panel/src/routes/api.addon-chat.ts
  • packages/typescript/ai/src/stream-to-response.ts
  • testing/panel/src/routes/api.chat.ts
  • packages/typescript/ai/src/index.ts
**/*.{ts,tsx,js,jsx}

πŸ“„ CodeRabbit inference engine (CLAUDE.md)

Use camelCase for function and variable names throughout the codebase

Files:

  • examples/ts-solid-chat/src/routes/api.chat.ts
  • packages/typescript/ai/tests/stream-to-response.test.ts
  • examples/ts-react-chat/src/routes/api.tanchat.ts
  • examples/ts-svelte-chat/src/routes/api/chat/+server.ts
  • testing/panel/src/routes/api.addon-chat.ts
  • packages/typescript/ai/src/stream-to-response.ts
  • testing/panel/src/routes/api.chat.ts
  • packages/typescript/ai/src/index.ts
examples/**

πŸ“„ CodeRabbit inference engine (CLAUDE.md)

Examples are not built by Nx and should be run independently from their directories with pnpm dev or pnpm install && pnpm dev

Files:

  • examples/ts-solid-chat/src/routes/api.chat.ts
  • examples/README.md
  • examples/ts-react-chat/src/routes/api.tanchat.ts
  • examples/ts-svelte-chat/src/routes/api/chat/+server.ts
**/*.test.ts

πŸ“„ CodeRabbit inference engine (CLAUDE.md)

Write unit tests using Vitest alongside source files with .test.ts naming convention

Files:

  • packages/typescript/ai/tests/stream-to-response.test.ts
packages/typescript/*/src/index.ts

πŸ“„ CodeRabbit inference engine (CLAUDE.md)

Export tree-shakeable adapters with clear subpath exports in package.json (e.g., @tanstack/ai/adapters, @tanstack/ai-openai/adapters) to minimize bundle size

Files:

  • packages/typescript/ai/src/index.ts
🧠 Learnings (9)
πŸ““ Common learnings
Learnt from: CR
Repo: TanStack/ai PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-13T17:09:09.794Z
Learning: Applies to **/*.{ts,tsx} : Implement stream processing with StreamProcessor for handling chunked responses and support partial JSON parsing for streaming AI responses
πŸ“š Learning: 2025-12-13T17:09:09.794Z
Learnt from: CR
Repo: TanStack/ai PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-13T17:09:09.794Z
Learning: Applies to **/*.{ts,tsx} : Implement stream processing with StreamProcessor for handling chunked responses and support partial JSON parsing for streaming AI responses

Applied to files:

  • docs/reference/index.md
  • docs/getting-started/quick-start.md
  • docs/guides/agentic-cycle.md
  • docs/adapters/ollama.md
  • examples/ts-solid-chat/src/routes/api.chat.ts
  • docs/guides/tools.md
  • examples/README.md
  • docs/api/ai.md
  • packages/typescript/ai-solid/README.md
  • docs/guides/runtime-adapter-switching.md
  • docs/protocol/sse-protocol.md
  • docs/reference/functions/toServerSentEventsResponse.md
  • docs/guides/server-tools.md
  • docs/adapters/gemini.md
  • docs/adapters/openai.md
  • packages/typescript/ai/tests/stream-to-response.test.ts
  • examples/ts-react-chat/src/routes/api.tanchat.ts
  • docs/guides/tool-architecture.md
  • docs/guides/streaming.md
  • examples/ts-svelte-chat/src/routes/api/chat/+server.ts
  • docs/guides/connection-adapters.md
  • docs/adapters/anthropic.md
  • testing/panel/src/routes/api.addon-chat.ts
  • packages/typescript/ai/src/stream-to-response.ts
  • docs/guides/tool-approval.md
  • testing/panel/src/routes/api.chat.ts
  • packages/typescript/ai/src/index.ts
πŸ“š Learning: 2025-12-13T17:09:09.794Z
Learnt from: CR
Repo: TanStack/ai PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-13T17:09:09.794Z
Learning: Applies to packages/typescript/*/src/index.ts : Export tree-shakeable adapters with clear subpath exports in package.json (e.g., `tanstack/ai/adapters`, `tanstack/ai-openai/adapters`) to minimize bundle size

Applied to files:

  • docs/getting-started/quick-start.md
  • examples/ts-solid-chat/src/routes/api.chat.ts
  • examples/README.md
  • docs/guides/runtime-adapter-switching.md
  • docs/adapters/openai.md
  • examples/ts-react-chat/src/routes/api.tanchat.ts
  • docs/adapters/anthropic.md
  • packages/typescript/ai/src/index.ts
πŸ“š Learning: 2025-12-13T17:09:09.794Z
Learnt from: CR
Repo: TanStack/ai PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-13T17:09:09.794Z
Learning: Implement framework integrations using the headless `tanstack/ai-client` for state management with framework-specific hooks (useChat) on top

Applied to files:

  • docs/getting-started/quick-start.md
  • docs/adapters/ollama.md
  • examples/ts-solid-chat/src/routes/api.chat.ts
  • docs/guides/tools.md
  • examples/README.md
  • packages/typescript/ai-solid/README.md
  • docs/guides/runtime-adapter-switching.md
  • docs/protocol/sse-protocol.md
  • docs/guides/server-tools.md
  • docs/adapters/gemini.md
  • docs/adapters/openai.md
  • examples/ts-react-chat/src/routes/api.tanchat.ts
  • docs/guides/tool-architecture.md
  • examples/ts-svelte-chat/src/routes/api/chat/+server.ts
  • docs/adapters/anthropic.md
  • testing/panel/src/routes/api.addon-chat.ts
  • testing/panel/src/routes/api.chat.ts
πŸ“š Learning: 2025-12-13T17:09:09.794Z
Learnt from: CR
Repo: TanStack/ai PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-13T17:09:09.794Z
Learning: Applies to .eslintrc* : Use ESLint with custom TanStack config for linting all TypeScript and JavaScript files

Applied to files:

  • docs/getting-started/quick-start.md
πŸ“š Learning: 2025-12-13T17:09:09.794Z
Learnt from: CR
Repo: TanStack/ai PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-13T17:09:09.794Z
Learning: Applies to packages/typescript/*/src/adapters/*.ts : Create individual adapter implementations for each provider capability (text, embed, summarize, image) with separate exports to enable tree-shaking

Applied to files:

  • docs/guides/runtime-adapter-switching.md
  • docs/adapters/anthropic.md
πŸ“š Learning: 2025-12-13T17:09:09.794Z
Learnt from: CR
Repo: TanStack/ai PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-13T17:09:09.794Z
Learning: Applies to **/*.{ts,tsx} : Use tree-shakeable adapter architecture for provider implementations - export specialized adapters (text, embedding, summarize, image) as separate imports from `/adapters` subpath rather than monolithic adapters

Applied to files:

  • docs/guides/runtime-adapter-switching.md
  • docs/adapters/anthropic.md
πŸ“š Learning: 2025-12-13T17:09:09.794Z
Learnt from: CR
Repo: TanStack/ai PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-13T17:09:09.794Z
Learning: Applies to **/*.test.ts : Write unit tests using Vitest alongside source files with `.test.ts` naming convention

Applied to files:

  • packages/typescript/ai/tests/stream-to-response.test.ts
πŸ“š Learning: 2025-12-13T17:09:09.794Z
Learnt from: CR
Repo: TanStack/ai PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-13T17:09:09.794Z
Learning: Applies to **/*.{ts,tsx} : Implement isomorphic tool system using `toolDefinition()` with `.server()` and `.client()` implementations for dual-environment execution

Applied to files:

  • docs/guides/tool-approval.md
  • packages/typescript/ai/src/index.ts
🧬 Code graph analysis (7)
examples/ts-solid-chat/src/routes/api.chat.ts (2)
packages/typescript/ai/src/stream-to-response.ts (1)
  • toServerSentEventsResponse (123-137)
packages/typescript/ai/src/index.ts (1)
  • toServerSentEventsResponse (58-58)
packages/typescript/ai/tests/stream-to-response.test.ts (2)
packages/typescript/ai/src/stream-to-response.ts (1)
  • toServerSentEventsResponse (123-137)
packages/typescript/ai/src/index.ts (1)
  • toServerSentEventsResponse (58-58)
examples/ts-react-chat/src/routes/api.tanchat.ts (1)
packages/typescript/ai/src/stream-to-response.ts (1)
  • toServerSentEventsResponse (123-137)
examples/ts-svelte-chat/src/routes/api/chat/+server.ts (3)
packages/typescript/ai/src/stream-to-response.ts (1)
  • toServerSentEventsResponse (123-137)
packages/typescript/ai/src/index.ts (1)
  • toServerSentEventsResponse (58-58)
packages/typescript/ai-svelte/src/index.ts (1)
  • stream (13-13)
testing/panel/src/routes/api.addon-chat.ts (2)
packages/typescript/ai/src/stream-to-response.ts (1)
  • toServerSentEventsResponse (123-137)
packages/typescript/ai/src/index.ts (1)
  • toServerSentEventsResponse (58-58)
packages/typescript/ai/src/stream-to-response.ts (2)
packages/typescript/ai/src/index.ts (4)
  • toServerSentEventsResponse (58-58)
  • toServerSentEventsStream (57-57)
  • toHttpResponse (60-60)
  • toHttpStream (59-59)
packages/typescript/ai/src/types.ts (1)
  • StreamChunk (740-748)
testing/panel/src/routes/api.chat.ts (2)
packages/typescript/ai/src/stream-to-response.ts (1)
  • toServerSentEventsResponse (123-137)
packages/typescript/ai/src/index.ts (1)
  • toServerSentEventsResponse (58-58)
πŸ”‡ Additional comments (31)
packages/typescript/ai-solid/README.md (1)

160-175: LGTM! Documentation updated consistently.

All example code has been updated correctly to use toServerSentEventsResponse instead of toStreamResponse. The import statements and function calls are consistent across all examples.

Also applies to: 314-330, 355-388

packages/typescript/ai/src/stream-to-response.ts (2)

105-137: LGTM! SSE response helper correctly implemented.

The toServerSentEventsResponse function correctly:

  • Wraps the stream with SSE formatting via toServerSentEventsStream
  • Sets required SSE headers (Content-Type: text/event-stream, Cache-Control: no-cache, Connection: keep-alive)
  • Supports AbortController for cancellation
  • Allows header overrides through the init parameter

233-240: LGTM! HTTP stream response correctly implemented.

The toHttpResponse function correctly delegates to toHttpStream and constructs a Response with the provided initialization options. The simpler pattern (spreading entire init) is appropriate here since no default headers need to be set.

docs/guides/connection-adapters.md (1)

14-14: LGTM! Documentation link updated correctly.

The reference link has been updated to point to the new toServerSentEventsResponse() function with the correct anchor. The text now mentions both helper functions appropriately.

docs/guides/agentic-cycle.md (1)

131-131: LGTM! Example updated correctly.

The agentic cycle example now uses toServerSentEventsResponse instead of toStreamResponse, consistent with the API rename.

docs/guides/tool-approval.md (1)

60-73: LGTM! Tool approval guide updated consistently.

Both the import statement (line 60) and the function usage (line 73) have been updated correctly to use toServerSentEventsResponse.

docs/adapters/anthropic.md (1)

59-70: LGTM! Anthropic adapter documentation updated correctly.

The chat completion example has been updated with the correct import (line 59) and usage (line 70) of toServerSentEventsResponse.

docs/reference/index.md (1)

149-149: LGTM! API reference index updated correctly.

The function reference link has been updated from toStreamResponse to toServerSentEventsResponse, aligning with the API rename.

docs/guides/server-tools.md (1)

144-157: LGTM! Server tools guide updated consistently.

Both the import statement (line 144) and the function usage (line 157) have been updated correctly to use toServerSentEventsResponse.

docs/guides/streaming.md (1)

30-45: API documentation updates look good.

The server-side streaming section correctly reflects the renamed API with consistent import and usage patterns. The example remains clear and functional.

docs/api/ai.md (1)

134-183: Comprehensive API documentation for toServerSentEventsResponse.

The new function documentation clearly explains the SSE response formatting (data: prefix, double newlines, [DONE] marker) and provides proper parameter/return type documentation. The example is functional and concise.

docs/reference/functions/toServerSentEventsResponse.md (1)

1-46: Well-structured reference documentation for new API function.

The reference page properly documents the function signature, behavior (SSE formatting), parameters, return type, and includes a practical example. The source file link (line 12) aids maintainability.

Verify that the source location reference (line 12: stream-to-response.ts:123) points to the correct function definition and line number in the codebase.

docs/adapters/ollama.md (1)

72-88: Ollama adapter example correctly updated.

The chat completion example properly reflects the API rename and demonstrates typical server-side streaming pattern with Ollama. The example is concise and functional.

examples/README.md (1)

308-321: Examples README correctly shows updated TypeScript backend pattern.

The SSE streaming backend example properly reflects the API rename. Showing comparable Python and PHP implementations provides good context for multi-language development.

docs/guides/tools.md (1)

172-197: Tools guide server-side example correctly updated.

The server-side tool usage example properly reflects the API rename and clearly shows tool passing and response streaming. Pairing with client-side example (lines 200-240) provides complete pattern.

docs/guides/tool-architecture.md (1)

67-88: Tool architecture guide server example properly updated.

The API route example correctly reflects the API rename and integrates well with the preceding flow diagram. The tool passing and streaming response pattern is clearly demonstrated.

docs/guides/runtime-adapter-switching.md (1)

15-101: Runtime adapter switching guide comprehensively updated.

All example variations (simple approach, full example, image adapters, summarize adapters) correctly reflect the toServerSentEventsResponse API. The guide effectively demonstrates provider switching while showcasing the renamed function across different contexts.

docs/getting-started/quick-start.md (1)

26-26: LGTM! Documentation updated to reflect the new API.

The import and usage of toServerSentEventsResponse correctly replaces the previous API across both TanStack Start and Next.js examples. The function signature and behavior remain consistent.

Also applies to: 59-59, 81-81, 109-109

docs/adapters/gemini.md (1)

59-59: LGTM! Adapter documentation correctly updated.

The Gemini adapter example now uses toServerSentEventsResponse, consistent with the API refactoring across the codebase.

Also applies to: 70-70

docs/adapters/openai.md (1)

59-59: LGTM! Adapter documentation correctly updated.

The OpenAI adapter example now uses toServerSentEventsResponse, maintaining consistency with the API changes.

Also applies to: 70-70

testing/panel/src/routes/api.addon-chat.ts (1)

2-2: LGTM! Simplified response handling with improved API.

The migration from toServerSentEventsStream to toServerSentEventsResponse simplifies the code by encapsulating Response creation and SSE header setup. The abortController is now properly passed via the init object.

Also applies to: 70-70

testing/panel/src/routes/api.chat.ts (1)

8-8: LGTM! Response handling correctly updated.

The migration to toServerSentEventsResponse is properly implemented, simplifying the streaming response creation while maintaining the existing abort controller semantics.

Also applies to: 234-234

packages/typescript/ai/src/index.ts (1)

56-61: LGTM! Public API surface correctly updated.

The exports now reflect the new API:

  • toServerSentEventsResponse replaces the previous toStreamResponse
  • toHttpResponse is introduced as a new general HTTP streaming helper

This is a breaking change, but the PR description confirms a changeset was generated to properly communicate this to users.

packages/typescript/ai/tests/stream-to-response.test.ts (1)

4-4: LGTM! Test suite properly updated for the API rename.

All test cases have been correctly updated to use toServerSentEventsResponse while maintaining the same test coverage and expectations. The describe block and all call sites are consistent with the new API.

Also applies to: 318-466

examples/ts-react-chat/src/routes/api.tanchat.ts (1)

6-6: LGTM! Example correctly updated to use the new API.

The React chat example now uses toServerSentEventsResponse, properly simplifying the response handling while maintaining abort controller support.

Also applies to: 125-125

docs/config.json (1)

258-259: LGTM! Documentation reference updated correctly.

The navigation config properly reflects the API rename from toStreamResponse to toServerSentEventsResponse, ensuring documentation links remain valid.

docs/protocol/sse-protocol.md (1)

167-192: LGTM! Documentation accurately reflects the new API.

The documentation correctly updates from toStreamResponse to toServerSentEventsResponse and accurately describes the simplified API that now returns a complete Response object with headers configured. The code examples demonstrate proper usage of the new signature.

examples/ts-solid-chat/src/routes/api.chat.ts (2)

2-2: LGTM! Correct import for the new API.

The import correctly switches to toServerSentEventsResponse, which is the new unified function that returns a complete Response object.


74-74: LGTM! Proper usage of the new API.

The migration correctly uses toServerSentEventsResponse(stream, { abortController }), which simplifies the code by eliminating manual Response construction. The function now handles SSE headers internally and returns a ready-to-use Response object.

examples/ts-svelte-chat/src/routes/api/chat/+server.ts (2)

5-5: LGTM! Import updated correctly.

The import correctly uses toServerSentEventsResponse from @tanstack/ai, consistent with the API migration across the codebase.


119-119: LGTM! Consistent API migration.

The usage of toServerSentEventsResponse(stream, { abortController }) is correct and consistent with the migration pattern used in other examples (e.g., examples/ts-solid-chat). The new API successfully simplifies response handling by encapsulating SSE headers and stream management.

Copy link
Contributor

@AlemTuzlak AlemTuzlak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should address what the AI suggested, other than that looks good

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
packages/typescript/ai/src/stream-to-response.ts (1)

245-252: Destructure abortController before spreading init.

The function spreads ...init (line 250) into the Response constructor, but init includes the non-standard abortController property. While the Response constructor likely ignores unknown properties, this is inconsistent with toServerSentEventsResponse (line 127), which explicitly destructures abortController out before spreading.

For consistency and cleaner API usage, destructure abortController first:

πŸ”Ž Proposed refactor
 export function toHttpResponse(
   stream: AsyncIterable<StreamChunk>,
   init?: ResponseInit & { abortController?: AbortController },
 ): Response {
-  return new Response(toHttpStream(stream, init?.abortController), {
-    ...init,
-  })
+  const { abortController, ...responseInit } = init ?? {}
+  return new Response(toHttpStream(stream, abortController), {
+    ...responseInit,
+  })
 }
πŸ“œ Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between 314bdfa and eb41d52.

πŸ“’ Files selected for processing (1)
  • packages/typescript/ai/src/stream-to-response.ts
🧰 Additional context used
πŸ““ Path-based instructions (2)
**/*.{ts,tsx}

πŸ“„ CodeRabbit inference engine (CLAUDE.md)

**/*.{ts,tsx}: Use tree-shakeable adapter architecture for provider implementations - export specialized adapters (text, embedding, summarize, image) as separate imports from /adapters subpath rather than monolithic adapters
Use Zod for runtime schema validation and type inference, particularly for tool input/output definitions with toolDefinition() and Zod schema inference
Implement isomorphic tool system using toolDefinition() with .server() and .client() implementations for dual-environment execution
Use type-safe per-model configuration with provider options typed based on selected model to ensure compile-time safety
Implement stream processing with StreamProcessor for handling chunked responses and support partial JSON parsing for streaming AI responses

Files:

  • packages/typescript/ai/src/stream-to-response.ts
**/*.{ts,tsx,js,jsx}

πŸ“„ CodeRabbit inference engine (CLAUDE.md)

Use camelCase for function and variable names throughout the codebase

Files:

  • packages/typescript/ai/src/stream-to-response.ts
🧠 Learnings (2)
πŸ““ Common learnings
Learnt from: CR
Repo: TanStack/ai PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-13T17:09:09.794Z
Learning: Applies to **/*.{ts,tsx} : Implement stream processing with StreamProcessor for handling chunked responses and support partial JSON parsing for streaming AI responses
πŸ“š Learning: 2025-12-13T17:09:09.794Z
Learnt from: CR
Repo: TanStack/ai PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-13T17:09:09.794Z
Learning: Applies to **/*.{ts,tsx} : Implement stream processing with StreamProcessor for handling chunked responses and support partial JSON parsing for streaming AI responses

Applied to files:

  • packages/typescript/ai/src/stream-to-response.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Preview
  • GitHub Check: Test
πŸ”‡ Additional comments (1)
packages/typescript/ai/src/stream-to-response.ts (1)

123-149: LGTM! Header handling correctly addresses previous feedback.

The implementation properly handles all HeadersInit types (Headers instance, string[][], plain object) by normalizing through new Headers(headers) before merging (lines 138-143). The destructuring pattern (line 127) cleanly separates the non-standard abortController from standard ResponseInit properties.

@jherr jherr merged commit f4019b9 into main Dec 24, 2025
6 checks passed
@jherr jherr deleted the fix/toServerSentEventsResponse branch December 24, 2025 00:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants