Skip to content

Commit 3dae73a

Browse files
committed
chore: move rsc to react package
1 parent 225f087 commit 3dae73a

File tree

89 files changed

+273
-270
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+273
-270
lines changed

Diff for: content/cookbook/20-rsc/20-stream-text.mdx

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ Text generation can sometimes take a long time to complete, especially when you'
2020

2121
## Client
2222

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

2525
```tsx filename="app/page.tsx"
2626
'use client';
2727

2828
import { useState } from 'react';
2929
import { generate } from './actions';
30-
import { readStreamableValue } from 'ai/rsc';
30+
import { readStreamableValue } from '@ai-sdk/react/rsc';
3131

3232
// Allow streaming responses up to 30 seconds
3333
export const maxDuration = 30;
@@ -66,7 +66,7 @@ Using DevTools, we can see the text generation being streamed to the client in r
6666

6767
import { streamText } from 'ai';
6868
import { openai } from '@ai-sdk/openai';
69-
import { createStreamableValue } from 'ai/rsc';
69+
import { createStreamableValue } from '@ai-sdk/react/rsc';
7070

7171
export async function generate(input: string) {
7272
const stream = createStreamableValue('');

Diff for: content/cookbook/20-rsc/21-stream-text-with-chat-prompt.mdx

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Let's create a simple conversation between a user and a model, and place a butto
3232

3333
import { useState } from 'react';
3434
import { Message, continueConversation } from './actions';
35-
import { readStreamableValue } from 'ai/rsc';
35+
import { readStreamableValue } from '@ai-sdk/react/rsc';
3636

3737
// Allow streaming responses up to 30 seconds
3838
export const maxDuration = 30;
@@ -95,7 +95,7 @@ Now, let's implement the `continueConversation` function that will insert the us
9595

9696
import { streamText } from 'ai';
9797
import { openai } from '@ai-sdk/openai';
98-
import { createStreamableValue } from 'ai/rsc';
98+
import { createStreamableValue } from '@ai-sdk/react/rsc';
9999

100100
export interface Message {
101101
role: 'user' | 'assistant';

Diff for: content/cookbook/20-rsc/40-stream-object.mdx

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ Let's create a simple React component that will call the `getNotifications` func
5151

5252
import { useState } from 'react';
5353
import { generate } from './actions';
54-
import { readStreamableValue } from 'ai/rsc';
54+
import { readStreamableValue } from '@ai-sdk/react/rsc';
5555

5656
// Allow streaming responses up to 30 seconds
5757
export const maxDuration = 30;
@@ -92,7 +92,7 @@ Now let's implement the `getNotifications` function. We'll use the `generateObje
9292

9393
import { streamObject } from 'ai';
9494
import { openai } from '@ai-sdk/openai';
95-
import { createStreamableValue } from 'ai/rsc';
95+
import { createStreamableValue } from '@ai-sdk/react/rsc';
9696
import { z } from 'zod';
9797

9898
export async function generate(input: string) {

Diff for: content/cookbook/20-rsc/60-save-messages-to-database.mdx

+3-3
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export default function RootLayout({
4141

4242
import { useState } from 'react';
4343
import { ClientMessage } from './actions';
44-
import { useActions, useUIState } from 'ai/rsc';
44+
import { useActions, useUIState } from '@ai-sdk/react/rsc';
4545
import { generateId } from 'ai';
4646

4747
// Allow streaming responses up to 30 seconds
@@ -100,7 +100,7 @@ We will use the callback function to listen to state changes and save the conver
100100
```tsx filename='app/actions.tsx'
101101
'use server';
102102

103-
import { getAIState, getMutableAIState, streamUI } from 'ai/rsc';
103+
import { getAIState, getMutableAIState, streamUI } from '@ai-sdk/react/rsc';
104104
import { openai } from '@ai-sdk/openai';
105105
import { ReactNode } from 'react';
106106
import { z } from 'zod';
@@ -176,7 +176,7 @@ export async function continueConversation(
176176
```
177177

178178
```ts filename='app/ai.ts'
179-
import { createAI } from 'ai/rsc';
179+
import { createAI } from '@ai-sdk/react/rsc';
180180
import { ServerMessage, ClientMessage, continueConversation } from './actions';
181181

182182
export const AI = createAI<ServerMessage[], ClientMessage[]>({

Diff for: content/cookbook/20-rsc/61-restore-messages-from-database.mdx

+3-3
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export default function RootLayout({
3939

4040
import { useState, useEffect } from 'react';
4141
import { ClientMessage } from './actions';
42-
import { useActions, useUIState } from 'ai/rsc';
42+
import { useActions, useUIState } from '@ai-sdk/react/rsc';
4343
import { generateId } from 'ai';
4444

4545
export default function Home() {
@@ -97,7 +97,7 @@ export default function Home() {
9797
The server-side implementation handles the restoration of messages and their transformation into the appropriate format for display.
9898

9999
```tsx filename='app/ai.ts'
100-
import { createAI } from 'ai/rsc';
100+
import { createAI } from '@ai-sdk/react/rsc';
101101
import { ServerMessage, ClientMessage, continueConversation } from './actions';
102102
import { Stock } from '@ai-studio/components/stock';
103103
import { generateId } from 'ai';
@@ -126,7 +126,7 @@ export const AI = createAI<ServerMessage[], ClientMessage[]>({
126126
```tsx filename='app/actions.tsx'
127127
'use server';
128128

129-
import { getAIState } from 'ai/rsc';
129+
import { getAIState } from '@ai-sdk/react/rsc';
130130

131131
export interface ServerMessage {
132132
role: 'user' | 'assistant' | 'function';

Diff for: content/cookbook/20-rsc/90-render-visual-interface-in-chat.mdx

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ When we define multiple functions in [`tools`](/docs/reference/ai-sdk-core/gener
1717

1818
import { useState } from 'react';
1919
import { ClientMessage } from './actions';
20-
import { useActions, useUIState } from 'ai/rsc';
20+
import { useActions, useUIState } from '@ai-sdk/react/rsc';
2121
import { generateId } from 'ai';
2222

2323
// Allow streaming responses up to 30 seconds
@@ -112,7 +112,7 @@ export async function Flight({ flightNumber }) {
112112
```tsx filename='app/actions.tsx'
113113
'use server';
114114

115-
import { getMutableAIState, streamUI } from 'ai/rsc';
115+
import { getMutableAIState, streamUI } from '@ai-sdk/react/rsc';
116116
import { openai } from '@ai-sdk/openai';
117117
import { ReactNode } from 'react';
118118
import { z } from 'zod';
@@ -206,7 +206,7 @@ export async function continueConversation(
206206
```
207207

208208
```typescript filename='app/ai.ts'
209-
import { createAI } from 'ai/rsc';
209+
import { createAI } from '@ai-sdk/react/rsc';
210210
import { ServerMessage, ClientMessage, continueConversation } from './actions';
211211

212212
export const AI = createAI<ServerMessage[], ClientMessage[]>({

Diff for: content/cookbook/20-rsc/91-stream-updates-to-visual-interfaces.mdx

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ In our previous example we've been streaming react components from the server to
1515

1616
import { useState } from 'react';
1717
import { ClientMessage } from './actions';
18-
import { useActions, useUIState } from 'ai/rsc';
18+
import { useActions, useUIState } from '@ai-sdk/react/rsc';
1919
import { generateId } from 'ai';
2020

2121
// Allow streaming responses up to 30 seconds
@@ -72,7 +72,7 @@ export default function Home() {
7272
```tsx filename='app/actions.tsx'
7373
'use server';
7474

75-
import { getMutableAIState, streamUI } from 'ai/rsc';
75+
import { getMutableAIState, streamUI } from '@ai-sdk/react/rsc';
7676
import { openai } from '@ai-sdk/openai';
7777
import { ReactNode } from 'react';
7878
import { z } from 'zod';
@@ -137,7 +137,7 @@ export async function continueConversation(
137137
```
138138

139139
```typescript filename='app/ai.ts'
140-
import { createAI } from 'ai/rsc';
140+
import { createAI } from '@ai-sdk/react/rsc';
141141
import { ServerMessage, ClientMessage, continueConversation } from './actions';
142142

143143
export const AI = createAI<ServerMessage[], ClientMessage[]>({

Diff for: content/cookbook/20-rsc/92-stream-ui-record-token-usage.mdx

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ It is called when the stream is finished.
1919

2020
import { useState } from 'react';
2121
import { ClientMessage } from './actions';
22-
import { useActions, useUIState } from 'ai/rsc';
22+
import { useActions, useUIState } from '@ai-sdk/react/rsc';
2323
import { generateId } from 'ai';
2424

2525
// Allow streaming responses up to 30 seconds
@@ -76,7 +76,7 @@ export default function Home() {
7676
```tsx filename='app/actions.tsx' highlight={"57-63"}
7777
'use server';
7878

79-
import { createAI, getMutableAIState, streamUI } from 'ai/rsc';
79+
import { createAI, getMutableAIState, streamUI } from '@ai-sdk/react/rsc';
8080
import { openai } from '@ai-sdk/openai';
8181
import { ReactNode } from 'react';
8282
import { z } from 'zod';
@@ -148,7 +148,7 @@ export async function continueConversation(
148148
```
149149

150150
```typescript filename='app/ai.ts'
151-
import { createAI } from 'ai/rsc';
151+
import { createAI } from '@ai-sdk/react/rsc';
152152
import { ServerMessage, ClientMessage, continueConversation } from './actions';
153153

154154
export const AI = createAI<ServerMessage[], ClientMessage[]>({

Diff for: content/docs/02-guides/21-llama-3_1.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ First, create a Server Action.
254254
```tsx filename="app/actions.tsx"
255255
'use server';
256256

257-
import { streamUI } from 'ai/rsc';
257+
import { streamUI } from '@ai-sdk/react/rsc';
258258
import { deepinfra } from '@ai-sdk/deepinfra';
259259
import { z } from 'zod';
260260

Diff for: content/docs/05-ai-sdk-rsc/01-overview.mdx

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ description: An overview of AI SDK RSC.
1212
</Note>
1313

1414
<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.
1717
</Note>
1818

1919
[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.

Diff for: content/docs/05-ai-sdk-rsc/02-streaming-react-components.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ Create a Server Action at `app/actions.tsx` and add the following code:
112112
```tsx filename="app/actions.tsx"
113113
'use server';
114114

115-
import { streamUI } from 'ai/rsc';
115+
import { streamUI } from '@ai-sdk/react/rsc';
116116
import { openai } from '@ai-sdk/openai';
117117
import { z } from 'zod';
118118

Diff for: content/docs/05-ai-sdk-rsc/03-generative-ui-state.mdx

+9-9
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ AI SDK RSC simplifies managing AI and UI state across your application by provid
5656

5757
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.
5858

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):
6060

6161
```tsx filename='app/actions.tsx'
6262
// Define the AI state and UI state types
@@ -78,7 +78,7 @@ export const sendMessage = async (input: string): Promise<ClientMessage> => {
7878
```
7979

8080
```tsx filename='app/ai.ts'
81-
import { createAI } from 'ai/rsc';
81+
import { createAI } from '@ai-sdk/react/rsc';
8282
import { ClientMessage, ServerMessage, sendMessage } from './actions';
8383

8484
export type AIState = ServerMessage[];
@@ -124,7 +124,7 @@ The UI state can be accessed in Client Components using the [`useUIState`](/docs
124124
```tsx filename='app/page.tsx'
125125
'use client';
126126

127-
import { useUIState } from 'ai/rsc';
127+
import { useUIState } from '@ai-sdk/react/rsc';
128128

129129
export default function Page() {
130130
const [messages, setMessages] = useUIState();
@@ -146,7 +146,7 @@ The AI state can be accessed in Client Components using the [`useAIState`](/docs
146146
```tsx filename='app/page.tsx'
147147
'use client';
148148

149-
import { useAIState } from 'ai/rsc';
149+
import { useAIState } from '@ai-sdk/react/rsc';
150150

151151
export default function Page() {
152152
const [messages, setMessages] = useAIState();
@@ -166,7 +166,7 @@ export default function Page() {
166166
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:
167167

168168
```tsx filename='app/actions.ts'
169-
import { getAIState } from 'ai/rsc';
169+
import { getAIState } from '@ai-sdk/react/rsc';
170170

171171
export async function sendMessage(message: string) {
172172
'use server';
@@ -192,7 +192,7 @@ export async function sendMessage(message: string) {
192192
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:
193193

194194
```tsx filename='app/actions.ts'
195-
import { getMutableAIState } from 'ai/rsc';
195+
import { getMutableAIState } from '@ai-sdk/react/rsc';
196196

197197
export async function sendMessage(message: string) {
198198
'use server';
@@ -226,7 +226,7 @@ To call the `sendMessage` action from the client, you can use the [`useActions`]
226226
```tsx filename='app/page.tsx'
227227
'use client';
228228

229-
import { useActions, useUIState } from 'ai/rsc';
229+
import { useActions, useUIState } from '@ai-sdk/react/rsc';
230230
import { AI } from './ai';
231231

232232
export default function Page() {
@@ -272,8 +272,8 @@ When the user submits a message, the `sendMessage` action is called with the mes
272272
Action otherwise the streamed component will not show in the UI.
273273
</Note>
274274

275-
To learn more, check out this [example](/examples/next-app/state-management/ai-ui-states) on managing AI and UI state using `ai/rsc`.
275+
To learn more, check out this [example](/examples/next-app/state-management/ai-ui-states) on managing AI and UI state using `@ai-sdk/react/rsc`.
276276

277277
---
278278

279-
Next, you will learn how you can save and restore state with `ai/rsc`.
279+
Next, you will learn how you can save and restore state with `@ai-sdk/react/rsc`.

Diff for: content/docs/05-ai-sdk-rsc/03-saving-and-restoring-states.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,4 @@ To learn more, check out this [example](/examples/next-app/state-management/save
102102

103103
---
104104

105-
Next, you will learn how you can use `ai/rsc` functions like `useActions` and `useUIState` to create interactive, multistep interfaces.
105+
Next, you will learn how you can use `@ai-sdk/react/rsc` functions like `useActions` and `useUIState` to create interactive, multistep interfaces.

Diff for: content/docs/05-ai-sdk-rsc/04-multistep-interfaces.mdx

+5-5
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ To build this kind of application you will leverage two concepts, **tool composi
2727

2828
## Overview
2929

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

3232
- A Server Action that calls and returns the result from the `streamUI` function
3333
- 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
4949
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.
5050

5151
```tsx filename="app/actions.tsx"
52-
import { streamUI } from 'ai/rsc';
52+
import { streamUI } from '@ai-sdk/react/rsc';
5353
import { openai } from '@ai-sdk/openai';
5454
import { z } from 'zod';
5555

@@ -137,7 +137,7 @@ export async function submitUserMessage(input: string) {
137137
Next, create an AI context that will hold the UI State and AI State.
138138

139139
```ts filename='app/ai.ts'
140-
import { createAI } from 'ai/rsc';
140+
import { createAI } from '@ai-sdk/react/rsc';
141141
import { submitUserMessage } from './actions';
142142

143143
export const AI = createAI<any[], React.ReactNode[]>({
@@ -175,7 +175,7 @@ To call your Server Action, update your root page with the following:
175175

176176
import { useState } from 'react';
177177
import { AI } from './ai';
178-
import { useActions, useUIState } from 'ai/rsc';
178+
import { useActions, useUIState } from '@ai-sdk/react/rsc';
179179

180180
export default function Page() {
181181
const [input, setInput] = useState<string>('');
@@ -224,7 +224,7 @@ To add user interaction, you will have to convert the component into a client co
224224
```tsx filename="components/flights.tsx"
225225
'use client';
226226

227-
import { useActions, useUIState } from 'ai/rsc';
227+
import { useActions, useUIState } from '@ai-sdk/react/rsc';
228228
import { ReactNode } from 'react';
229229

230230
interface FlightsProps {

Diff for: content/docs/05-ai-sdk-rsc/05-streaming-values.mdx

+5-5
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ This is useful when you want to stream:
4242

4343
## Creating a Streamable Value
4444

45-
You can import `createStreamableValue` from `ai/rsc` and use it to create a streamable value.
45+
You can import `createStreamableValue` from `@ai-sdk/react/rsc` and use it to create a streamable value.
4646

4747
```tsx file='app/actions.ts'
4848
'use server';
4949

50-
import { createStreamableValue } from 'ai/rsc';
50+
import { createStreamableValue } from '@ai-sdk/react/rsc';
5151

5252
export const runThread = async () => {
5353
const streamableStatus = createStreamableValue('thread.init');
@@ -70,7 +70,7 @@ export const runThread = async () => {
7070
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:
7171

7272
```tsx file='app/page.tsx'
73-
import { readStreamableValue } from 'ai/rsc';
73+
import { readStreamableValue } from '@ai-sdk/react/rsc';
7474
import { runThread } from '@/actions';
7575

7676
export default function Page() {
@@ -103,7 +103,7 @@ Let's look at how you can use the `createStreamableUI` function with a Server Ac
103103
```tsx filename='app/actions.tsx'
104104
'use server';
105105

106-
import { createStreamableUI } from 'ai/rsc';
106+
import { createStreamableUI } from '@ai-sdk/react/rsc';
107107

108108
export async function getWeather() {
109109
const weatherUI = createStreamableUI();
@@ -128,7 +128,7 @@ On the client side, you can call the `getWeather` Server Action and render the r
128128
'use client';
129129

130130
import { useState } from 'react';
131-
import { readStreamableValue } from 'ai/rsc';
131+
import { readStreamableValue } from '@ai-sdk/react/rsc';
132132
import { getWeather } from '@/actions';
133133

134134
export default function Page() {

0 commit comments

Comments
 (0)