Skip to content

feat (ui/react): support resuming an ongoing stream#6053

Merged
jeremyphilemon merged 5 commits intov5from
jrmy/experimental-resume-v5
May 1, 2025
Merged

feat (ui/react): support resuming an ongoing stream#6053
jeremyphilemon merged 5 commits intov5from
jrmy/experimental-resume-v5

Conversation

@jeremyphilemon
Copy link
Contributor

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 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

  • Tests have been added / updated (for bug fixes / features)
  • Documentation has been added / updated (for bug fixes / features)
  • A patch changeset for relevant packages has been added
  • Formatting issues have been fixed (run pnpm prettier-fix in the project root)

@lgrammel
Copy link
Collaborator

lgrammel commented Apr 30, 2025

Please wait until it's landed on main and then cherry-pick. Also there seem to be a lot of files included that shouldn't be under solidstart (it's been removed in v5).

@jeremyphilemon jeremyphilemon merged commit c34ccd7 into v5 May 1, 2025
8 checks passed
@jeremyphilemon jeremyphilemon deleted the jrmy/experimental-resume-v5 branch May 1, 2025 08:07
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
#6053
samdenty added a commit that referenced this pull request May 2, 2025
* origin/v5:
  fix(providers/openai): logprobs for stream alongside completion model (#6091)
  chore (ai): move maxSteps into UseChatOptions (#6113)
  docs (ai): add notes on schema .optional() (#6111)
  chore: update references to use ai-sdk.dev (#6076) (#6107)
  Version Packages (canary) (#6069)
  chore (provider-utils): rename TestServerCall.requestBody to requestBodyJson (#6106)
  chore (ai): rename CoreMessage to ModelMessage (#6105)
  feat (ai): add filename to file ui parts (#6104)
  feat (docs): add Dify community provider (#4084) (#6067) (#6103)
  feat (docs): add Sarvam community provider (#6079) (#6096)
  fix(providers/openai): zod parse error with function (#6074) (#6095)
  feat(docs): add Weave observability provider (#6029) (#6094)
  core (ai/mcp): update experimental MCP client documentation for Streamable HTTP transport usage (#5972) (#6093)
  fix (docs): update formatting in useChat reference docs  (#6100)
  chore (ai): replace useChat attachments with file ui parts (#6071)
  feat (ui/react): support resuming an ongoing stream (#6053)
  test (openai): update snapshot (#6086)
samdenty added a commit that referenced this pull request May 2, 2025
…call

* origin/v5: (43 commits)
  chore (provider-utils): return IdGenerator interface (#6118)
  chore (provider): improve jsdoc comments (#6117)
  chore (ai): remove outdated typecasts (#6116)
  chore (ai): remove useChat keepLastMessageOnError (#6114)
  fix(providers/openai): logprobs for stream alongside completion model (#6091)
  chore (ai): move maxSteps into UseChatOptions (#6113)
  docs (ai): add notes on schema .optional() (#6111)
  chore: update references to use ai-sdk.dev (#6076) (#6107)
  Version Packages (canary) (#6069)
  chore (provider-utils): rename TestServerCall.requestBody to requestBodyJson (#6106)
  chore (ai): rename CoreMessage to ModelMessage (#6105)
  feat (ai): add filename to file ui parts (#6104)
  feat (docs): add Dify community provider (#4084) (#6067) (#6103)
  feat (docs): add Sarvam community provider (#6079) (#6096)
  fix(providers/openai): zod parse error with function (#6074) (#6095)
  feat(docs): add Weave observability provider (#6029) (#6094)
  core (ai/mcp): update experimental MCP client documentation for Streamable HTTP transport usage (#5972) (#6093)
  fix (docs): update formatting in useChat reference docs  (#6100)
  chore (ai): replace useChat attachments with file ui parts (#6071)
  feat (ui/react): support resuming an ongoing stream (#6053)
  ...
iteratetograceness pushed a commit to iteratetograceness/ai that referenced this pull request May 9, 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)
iteratetograceness pushed a commit to iteratetograceness/ai that referenced this pull request May 9, 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
vercel#6053
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.

2 participants