feat (ui/react): support resuming an ongoing stream#6052
Merged
jeremyphilemon merged 23 commits intomainfrom May 1, 2025
Merged
feat (ui/react): support resuming an ongoing stream#6052jeremyphilemon merged 23 commits intomainfrom
jeremyphilemon merged 23 commits intomainfrom
Conversation
4 tasks
Contributor
Author
|
v5 version: #6053 |
lgrammel
reviewed
Apr 30, 2025
| 4. Returns the latest one to `streamContext.resumableStream()` | ||
| 5. Falls back to an empty stream if it’s already closed | ||
|
|
||
| ```ts filename="app/api/chat/route.ts" |
Collaborator
There was a problem hiding this comment.
The highlighting is broken - wonder if this will lead to issues with the docs rendering. Did you check it in the docs deployment?
Contributor
Author
There was a problem hiding this comment.
Hmm not sure why github isn't highlighting the code snippet, fwiw I did try building this in the docs deployment and it works!
lgrammel
reviewed
Apr 30, 2025
packages/react/src/use-chat.ts
Outdated
| /** | ||
| * Resume an ongoing chat generation stream. This does not resume an aborted generation. | ||
| */ | ||
| experimental_resume: () => Promise<string | null | undefined>; |
Collaborator
There was a problem hiding this comment.
What is the meaning of the promise return values?
Contributor
Author
There was a problem hiding this comment.
I made it return void
lgrammel
reviewed
Apr 30, 2025
| streaming is not yet complete. | ||
| </Note> | ||
|
|
||
| ## Resuming ongoing streams |
Collaborator
|
|
Contributor
Author
|
I added |
lgrammel
approved these changes
May 1, 2025
2 tasks
jeremyphilemon
added a commit
that referenced
this pull request
May 1, 2025
## Background This pull request fixes a docs formatting issue due to a missing comma in useChat reference docs. ## Summary Fixed formatting in useChat reference docs by adding a comma. ## Tasks - [x] Documentation has been added / updated (for bug fixes / features) - [x] Formatting issues have been fixed (run `pnpm prettier-fix` in the project root) ## Related Issues #6052
jeremyphilemon
added a commit
that referenced
this pull request
May 1, 2025
## Background This pull request fixes a docs formatting issue due to a missing comma in useChat reference docs. ## Summary Fixed formatting in useChat reference docs by adding a comma. ## Tasks - [x] Documentation has been added / updated (for bug fixes / features) - [x] Formatting issues have been fixed (run `pnpm prettier-fix` in the project root) ## Related Issues #6052
This was referenced May 7, 2025
jeremyphilemon
added a commit
that referenced
this pull request
May 8, 2025
…ming stream (#6224) ## Background This pull request updates the documentation for the GET handler in the resumable streams section to account for a race condition that may occur when the stream ends in-flight. ## Summary Updated the route by adding the code snippet that handles the above condition. ## Tasks - [x] Documentation has been added / updated (for bug fixes / features) - [x] Formatting issues have been fixed (run `pnpm prettier-fix` in the project root) ## Related Issues #6052
jeremyphilemon
added a commit
that referenced
this pull request
May 8, 2025
…ming stream (#6224) ## Background This pull request updates the documentation for the GET handler in the resumable streams section to account for a race condition that may occur when the stream ends in-flight. ## Summary Updated the route by adding the code snippet that handles the above condition. ## Tasks - [x] Documentation has been added / updated (for bug fixes / features) - [x] Formatting issues have been fixed (run `pnpm prettier-fix` in the project root) ## Related Issues #6052
2 tasks
lgrammel
pushed a commit
that referenced
this pull request
May 8, 2025
…ming stream (#6224) ## Background This pull request updates the documentation for the GET handler in the resumable streams section to account for a race condition that may occur when the stream ends in-flight. ## Summary Updated the route by adding the code snippet that handles the above condition. ## Tasks - [x] Documentation has been added / updated (for bug fixes / features) - [x] Formatting issues have been fixed (run `pnpm prettier-fix` in the project root) ## Related Issues #6052
jacobkerber
pushed a commit
to jacobkerber/ai
that referenced
this pull request
Jul 15, 2025
## Background This pull request adds the ability for clients to resume an ongoing chat generation stream after a network disconnect. ## Summary This pull request adds support for the `useChat` hook to resume an ongoing chat generation stream by exposing `experimental_resume()` that can be called by any client, typically during the initial mount of the hook. The `experimental_resume` function makes a `GET` request to the api endpoint you've initialized the hook with (or `/api/chat` by default) and streams the contents of the stream if it is active or fails silently if it has ended. In order for `experimental_resume` to work as intended, it requires the usage of the [`resumable-stream`](https://www.npmjs.com/package/resumable-stream) package for stream creation and a redis instance for the package to manage the pub/sub mechanism. ## Verification An example has been added at `examples/next-openai/app/use-chat-resume` to test the feature. Follow the following steps to test it end-to-end: 1. Run the development server 2. Navigate to `http://localhost:3000/use-chat-resume` 3. Send a message that will have a longer generation duration, example "Write an essay about Michael Jordan" 4. Once the generation starts, click the chat id above to open the conversation in a new tab 5. Verify the stream gets resumed ## Tasks - [x] Tests have been added / updated (for bug fixes / features) - [x] Documentation has been added / updated (for bug fixes / features) - [x] A _patch_ changeset for relevant packages has been added - [x] Formatting issues have been fixed (run `pnpm prettier-fix` in the project root) --------- Co-authored-by: Lars Grammel <lars.grammel@gmail.com>
jacobkerber
pushed a commit
to jacobkerber/ai
that referenced
this pull request
Jul 15, 2025
This pull request adds the ability for clients to resume an ongoing chat generation stream after a network disconnect. This pull request adds support for the `useChat` hook to resume an ongoing chat generation stream by exposing `experimental_resume()` that can be called by any client, typically during the initial mount of the hook. The `experimental_resume` function makes a `GET` request to the api endpoint you've initialized the hook with (or `/api/chat` by default) and streams the contents of the stream if it is active or fails silently if it has ended. In order for `experimental_resume` to work as intended, it requires the usage of the [`resumable-stream`](https://www.npmjs.com/package/resumable-stream) package for stream creation and a redis instance for the package to manage the pub/sub mechanism. An example has been added at `examples/next-openai/app/use-chat-resume` to test the feature. Follow the following steps to test it end-to-end: 1. Run the development server 2. Navigate to `http://localhost:3000/use-chat-resume` 3. Send a message that will have a longer generation duration, example "Write an essay about Michael Jordan" 4. Once the generation starts, click the chat id above to open the conversation in a new tab 5. Verify the stream gets resumed - [x] Tests have been added / updated (for bug fixes / features) - [x] Documentation has been added / updated (for bug fixes / features) - [x] A _patch_ changeset for relevant packages has been added - [x] Formatting issues have been fixed (run `pnpm prettier-fix` in the project root) --------- Co-authored-by: Lars Grammel <lars.grammel@gmail.com>
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.
Background
This pull request adds the ability for clients to resume an ongoing chat generation stream after a network disconnect.
Summary
This pull request adds support for the
useChathook to resume an ongoing chat generation stream by exposingexperimental_resume()that can be called by any client, typically during the initial mount of the hook.The
experimental_resumefunction makes aGETrequest to the api endpoint you've initialized the hook with (or/api/chatby default) and streams the contents of the stream if it is active or fails silently if it has ended.In order for
experimental_resumeto work as intended, it requires the usage of theresumable-streampackage for stream creation and a redis instance for the package to manage the pub/sub mechanism.Verification
An example has been added at
examples/next-openai/app/use-chat-resumeto test the feature. Follow the following steps to test it end-to-end:http://localhost:3000/use-chat-resumeTasks
pnpm prettier-fixin the project root)