You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/cookbook/20-rsc/20-stream-text.mdx
+3-3
Original file line number
Diff line number
Diff line change
@@ -20,14 +20,14 @@ Text generation can sometimes take a long time to complete, especially when you'
20
20
21
21
## Client
22
22
23
-
Let's create a simple React component that will call the `generate` function when a button is clicked. The `generate` function will call the `streamText` function, which will then generate text based on the input prompt. To consume the stream of text in the client, we will use the `readStreamableValue` function from the `ai/rsc` module.
23
+
Let's create a simple React component that will call the `generate` function when a button is clicked. The `generate` function will call the `streamText` function, which will then generate text based on the input prompt. To consume the stream of text in the client, we will use the `readStreamableValue` function from the `@ai-sdk/react/rsc` module.
Copy file name to clipboardExpand all lines: content/docs/05-ai-sdk-rsc/01-overview.mdx
+2-2
Original file line number
Diff line number
Diff line change
@@ -12,8 +12,8 @@ description: An overview of AI SDK RSC.
12
12
</Note>
13
13
14
14
<Note>
15
-
The `ai/rsc` package is compatible with frameworks that support React Server
16
-
Components.
15
+
The `@ai-sdk/react/rsc` package is compatible with frameworks that support
16
+
React Server Components.
17
17
</Note>
18
18
19
19
[React Server Components](https://nextjs.org/docs/app/building-your-application/rendering/server-components) (RSC) allow you to write UI that can be rendered on the server and streamed to the client. RSCs enable [ Server Actions ](https://nextjs.org/docs/app/building-your-application/data-fetching/server-actions-and-mutations#with-client-components), a new way to call server-side code directly from the client just like any other function with end-to-end type-safety. This combination opens the door to a new way of building AI applications, allowing the large language model (LLM) to generate and stream UI directly from the server to the client.
Copy file name to clipboardExpand all lines: content/docs/05-ai-sdk-rsc/03-generative-ui-state.mdx
+9-9
Original file line number
Diff line number
Diff line change
@@ -56,7 +56,7 @@ AI SDK RSC simplifies managing AI and UI state across your application by provid
56
56
57
57
Notably, this means you do not have to pass the message history to the server explicitly for each request. You also can access and update your application state in any child component of the context provider. As you begin building [multistep generative interfaces](/docs/ai-sdk-rsc/multistep-interfaces), this will be particularly helpful.
58
58
59
-
To use `ai/rsc` to manage AI and UI State in your application, you can create a React context using [`createAI`](/docs/reference/ai-sdk-rsc/create-ai):
59
+
To use `@ai-sdk/react/rsc` to manage AI and UI State in your application, you can create a React context using [`createAI`](/docs/reference/ai-sdk-rsc/create-ai):
@@ -124,7 +124,7 @@ The UI state can be accessed in Client Components using the [`useUIState`](/docs
124
124
```tsx filename='app/page.tsx'
125
125
'use client';
126
126
127
-
import { useUIState } from'ai/rsc';
127
+
import { useUIState } from'@ai-sdk/react/rsc';
128
128
129
129
exportdefaultfunction Page() {
130
130
const [messages, setMessages] =useUIState();
@@ -146,7 +146,7 @@ The AI state can be accessed in Client Components using the [`useAIState`](/docs
146
146
```tsx filename='app/page.tsx'
147
147
'use client';
148
148
149
-
import { useAIState } from'ai/rsc';
149
+
import { useAIState } from'@ai-sdk/react/rsc';
150
150
151
151
exportdefaultfunction Page() {
152
152
const [messages, setMessages] =useAIState();
@@ -166,7 +166,7 @@ export default function Page() {
166
166
The AI State can be accessed within any Server Action provided to the `createAI` context using the [`getAIState`](/docs/reference/ai-sdk-rsc/get-ai-state) function. It returns the current AI state as a read-only value:
167
167
168
168
```tsx filename='app/actions.ts'
169
-
import { getAIState } from'ai/rsc';
169
+
import { getAIState } from'@ai-sdk/react/rsc';
170
170
171
171
exportasyncfunction sendMessage(message:string) {
172
172
'use server';
@@ -192,7 +192,7 @@ export async function sendMessage(message: string) {
192
192
The AI State can also be updated from within your Server Action with the [`getMutableAIState`](/docs/reference/ai-sdk-rsc/get-mutable-ai-state) function. This function is similar to `getAIState`, but it returns the state with methods to read and update it:
Copy file name to clipboardExpand all lines: content/docs/05-ai-sdk-rsc/04-multistep-interfaces.mdx
+5-5
Original file line number
Diff line number
Diff line change
@@ -27,7 +27,7 @@ To build this kind of application you will leverage two concepts, **tool composi
27
27
28
28
## Overview
29
29
30
-
In order to build a multistep interface with `ai/rsc`, you will need a few things:
30
+
In order to build a multistep interface with `@ai-sdk/react/rsc`, you will need a few things:
31
31
32
32
- A Server Action that calls and returns the result from the `streamUI` function
33
33
- Tool(s) (sub-tasks necessary to complete your overall task)
@@ -49,7 +49,7 @@ The turn-by-turn implementation is the simplest form of multistep interfaces. In
49
49
In the following example, you specify two tools (`searchFlights` and `lookupFlight`) that the model can use to search for flights and lookup details for a specific flight.
50
50
51
51
```tsx filename="app/actions.tsx"
52
-
import { streamUI } from'ai/rsc';
52
+
import { streamUI } from'@ai-sdk/react/rsc';
53
53
import { openai } from'@ai-sdk/openai';
54
54
import { z } from'zod';
55
55
@@ -137,7 +137,7 @@ export async function submitUserMessage(input: string) {
137
137
Next, create an AI context that will hold the UI State and AI State.
138
138
139
139
```ts filename='app/ai.ts'
140
-
import { createAI } from'ai/rsc';
140
+
import { createAI } from'@ai-sdk/react/rsc';
141
141
import { submitUserMessage } from'./actions';
142
142
143
143
exportconst AI =createAI<any[], React.ReactNode[]>({
@@ -175,7 +175,7 @@ To call your Server Action, update your root page with the following:
You can read streamable values on the client using `readStreamableValue`. It returns an async iterator that yields the value of the streamable as it is updated:
0 commit comments