Skip to content

feat(ai-client): pass abort signal to fetcher in generation clients#354

Merged
AlemTuzlak merged 3 commits intofeat/generation-hooks-and-streamingfrom
fix/fetcher-abort-signal
Mar 9, 2026
Merged

feat(ai-client): pass abort signal to fetcher in generation clients#354
AlemTuzlak merged 3 commits intofeat/generation-hooks-and-streamingfrom
fix/fetcher-abort-signal

Conversation

@AlemTuzlak
Copy link
Contributor

Summary

  • Generation clients (GenerationClient, VideoGenerationClient) now pass the AbortSignal to the fetcher function as an optional second parameter
  • Fetcher type signature updated from (input) => Promise<Result> to (input, options?: { signal: AbortSignal }) => Promise<Result> across all framework integrations (React, Solid, Vue, Svelte)
  • Backwards-compatible — existing fetchers that don't use the signal continue to work unchanged
  • Adds tests verifying the signal is passed to the fetcher in both GenerationClient and VideoGenerationClient

Test plan

  • generation-client.test.ts — new test verifies signal is passed to fetcher
  • video-generation-client.test.ts — new test verifies signal is passed to fetcher
  • All existing tests pass (49 tests across both suites)
  • All 5 affected packages build clean (ai-client, ai-react, ai-solid, ai-vue, ai-svelte)

The fetcher function in GenerationClient and VideoGenerationClient
now receives the AbortSignal as an optional second parameter, allowing
long-running fetcher calls to be cancelled mid-flight when stop() is
called.

Updated fetcher type signature across all framework integrations
(React, Solid, Vue, Svelte) — backwards-compatible since the options
parameter is optional.
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 9, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a47bbc59-0afc-4b26-8fa5-0c334d7e2597

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/fetcher-abort-signal

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 Mar 9, 2026

View your CI Pipeline Execution ↗ for commit b53d530

Command Status Duration Result
nx affected --targets=test:sherif,test:knip,tes... ✅ Succeeded 2m 5s View ↗
nx run-many --targets=build --exclude=examples/** ✅ Succeeded 57s View ↗

☁️ Nx Cloud last updated this comment at 2026-03-09 13:38:56 UTC

@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 9, 2026

Open in StackBlitz

@tanstack/ai

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

@tanstack/ai-anthropic

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

@tanstack/ai-client

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

@tanstack/ai-devtools-core

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

@tanstack/ai-fal

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-fal@354

@tanstack/ai-gemini

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

@tanstack/ai-grok

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-grok@354

@tanstack/ai-groq

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-groq@354

@tanstack/ai-ollama

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

@tanstack/ai-openai

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

@tanstack/ai-openrouter

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-openrouter@354

@tanstack/ai-preact

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-preact@354

@tanstack/ai-react

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

@tanstack/ai-react-ui

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

@tanstack/ai-solid

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

@tanstack/ai-solid-ui

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

@tanstack/ai-svelte

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

@tanstack/ai-vue

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

@tanstack/ai-vue-ui

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

@tanstack/preact-ai-devtools

npm i https://pkg.pr.new/TanStack/ai/@tanstack/preact-ai-devtools@354

@tanstack/react-ai-devtools

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

@tanstack/solid-ai-devtools

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

commit: 066c1c9

…r signature

Replace inline fetcher type definitions across all framework hooks (React,
Solid, Vue, Svelte) with a shared GenerationFetcher<TInput, TResult> type
from ai-client. Future changes to the fetcher signature only need to update
generation-types.ts instead of ~28 files.
@AlemTuzlak AlemTuzlak merged commit e4288b2 into feat/generation-hooks-and-streaming Mar 9, 2026
5 checks passed
@AlemTuzlak AlemTuzlak deleted the fix/fetcher-abort-signal branch March 9, 2026 13:41
AlemTuzlak added a commit that referenced this pull request Mar 10, 2026
* feat: add generation hooks and streaming for image, speech, video, transcription, and summarize

Adds a complete client-side generation layer across all framework integrations
(React, Solid, Svelte, Vue) for one-shot generation tasks: image generation,
text-to-speech, audio transcription, text summarization, and video generation.

Core changes:
- `streamGenerationResult()` and `streamVideoGeneration()` server helpers in `@tanstack/ai`
- `GenerationClient` and `VideoGenerationClient` state machines in `@tanstack/ai-client`
- Framework hooks: `useGenerateImage`, `useGenerateSpeech`, `useGenerateVideo`,
  `useTranscription`, `useSummarize` (and Svelte `create*` equivalents)
- `InferGenerationOutput` type for type-safe `onResult` transforms
- New "Generations" overview doc with Mermaid architecture diagram
- Full-stack usage sections added to all 4 generation guide docs
- React example app with 5 demo pages and server API routes

* ci: apply automated fixes

* feat: add unified `stream` flag to all generation activities

Move streaming logic from standalone `streamGenerationResult()` and
`streamVideoGeneration()` utilities into the activity functions behind
a `stream: true/false` flag. When `stream: true`, each function returns
`AsyncIterable<StreamChunk>` instead of `Promise<Result>`, with
TypeScript narrowing the return type via conditional types.

- generateImage, generateSpeech, generateTranscription, summarize:
  use shared internal `streamGenerationResult` helper
- generateVideo: inline streaming with job creation + polling
- Delete `stream-generation.ts` and remove public exports
- Update all examples, docs, and tests

* feat(examples): add streaming/direct tab toggle to generation showcases

Add a tab UI to each generation showcase page (image, speech, summarize,
transcription, video) allowing users to switch between streaming (SSE
connection) and direct (server function fetcher) transport modes.

- Create server-fns.ts with createServerFn + zod validators for each
  generation type
- Use library-exported hook return types (UseGenerateImageReturn, etc.)
  for component props
- React key-based remounting ensures clean hook state on tab switch

* ci: apply automated fixes

* feat: update request handling in generation endpoints to use body.data

* ci: apply automated fixes

* feat(ai-client): pass abort signal to fetcher in generation clients (#354)

* feat(ai-client): pass abort signal to fetcher in generation clients

The fetcher function in GenerationClient and VideoGenerationClient
now receives the AbortSignal as an optional second parameter, allowing
long-running fetcher calls to be cancelled mid-flight when stop() is
called.

Updated fetcher type signature across all framework integrations
(React, Solid, Vue, Svelte) — backwards-compatible since the options
parameter is optional.

* ci: apply automated fixes

* refactor: extract GenerationFetcher utility type to centralize fetcher signature

Replace inline fetcher type definitions across all framework hooks (React,
Solid, Vue, Svelte) with a shared GenerationFetcher<TInput, TResult> type
from ai-client. Future changes to the fetcher signature only need to update
generation-types.ts instead of ~28 files.

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>

* chore: add changeset for fetcher abort signal and GenerationFetcher type

* chore: add @tanstack/ai to changeset

* feat: add server-sent events support for streaming functions

- Updated server functions to support streaming responses using `toServerSentEventsResponse`.
- Introduced new streaming functions for image generation, speech generation, transcription, summarization, and video generation.
- Enhanced UI components to handle new server function modes for image, speech, summarization, and video generation.
- Modified the GenerationClient to parse SSE responses and handle streaming data.
- Added tests for SSE response handling in GenerationClient and connection adapters.
- Updated configuration files and ignored paths for better project structure.

* ci: apply automated fixes

* docs: add server function streaming examples and changeset

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
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.

1 participant