@v0-sdk/react 0.5.0 → 3.0.0-canary.15d19a4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +106 -245
- package/dist/index-DI_VZvSr.d.mts +156 -0
- package/dist/index-DI_VZvSr.d.mts.map +1 -0
- package/dist/index-DxMeHrwt.d.cts +156 -0
- package/dist/index-DxMeHrwt.d.cts.map +1 -0
- package/dist/index.cjs +2 -1251
- package/dist/index.d.cts +3 -0
- package/dist/index.d.mts +3 -0
- package/dist/index.mjs +4 -0
- package/dist/index.mjs.map +1 -0
- package/dist/request-C1Ues3qu.cjs +1 -0
- package/dist/request-enP5rNQ_.mjs +2 -0
- package/dist/request-enP5rNQ_.mjs.map +1 -0
- package/dist/swr.cjs +1 -0
- package/dist/swr.d.cts +1008 -0
- package/dist/swr.d.cts.map +1 -0
- package/dist/swr.d.mts +1008 -0
- package/dist/swr.d.mts.map +1 -0
- package/dist/swr.mjs +2 -0
- package/dist/swr.mjs.map +1 -0
- package/package.json +66 -44
- package/dist/index.d.ts +0 -594
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -1202
package/README.md
CHANGED
|
@@ -1,299 +1,160 @@
|
|
|
1
1
|
# @v0-sdk/react
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
React hooks for building apps with the v0 API.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## Install
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
For the AI SDK transport:
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
- **Zero DOM dependencies** - No `react-dom` required
|
|
13
|
-
- **Streaming support** - Real-time message streaming with `useStreamingMessage`
|
|
14
|
-
- **Backward compatible** - Drop-in replacement for existing implementations
|
|
9
|
+
```sh
|
|
10
|
+
npm install @v0-sdk/react react ai @ai-sdk/react
|
|
11
|
+
```
|
|
15
12
|
|
|
16
|
-
|
|
13
|
+
Add SWR when using the generated API hooks:
|
|
17
14
|
|
|
18
|
-
```
|
|
19
|
-
npm install @v0-sdk/react
|
|
20
|
-
# or
|
|
21
|
-
yarn add @v0-sdk/react
|
|
22
|
-
# or
|
|
23
|
-
pnpm add @v0-sdk/react
|
|
15
|
+
```sh
|
|
16
|
+
npm install @v0-sdk/react react swr
|
|
24
17
|
```
|
|
25
18
|
|
|
26
|
-
##
|
|
19
|
+
## Getting started
|
|
27
20
|
|
|
28
|
-
|
|
21
|
+
Create backend routes that authenticate with the server-side `v0` SDK, then pass those route URLs to the hooks. For example, this Next.js route proxies a streaming message request while keeping `V0_API_KEY` on the server:
|
|
29
22
|
|
|
30
|
-
```
|
|
31
|
-
|
|
23
|
+
```ts
|
|
24
|
+
// app/api/v0/chats/[chatId]/messages/stream/route.ts
|
|
25
|
+
import { v0 } from 'v0'
|
|
32
26
|
|
|
33
|
-
function
|
|
34
|
-
|
|
35
|
-
<Message
|
|
36
|
-
content={content}
|
|
37
|
-
messageId="msg-1"
|
|
38
|
-
role="assistant"
|
|
39
|
-
className="my-message"
|
|
40
|
-
/>
|
|
41
|
-
)
|
|
42
|
-
}
|
|
27
|
+
export async function POST(request: Request, { params }: { params: Promise<{ chatId: string }> }) {
|
|
28
|
+
// Perform your own authentication and validation
|
|
43
29
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
onComplete={(content) => console.log('Complete:', content)}
|
|
51
|
-
/>
|
|
52
|
-
)
|
|
30
|
+
const { chatId } = await params
|
|
31
|
+
const body = await request.json()
|
|
32
|
+
|
|
33
|
+
const result = await v0.messages.sendStream({ chatId, ...body })
|
|
34
|
+
|
|
35
|
+
return result.toResponse()
|
|
53
36
|
}
|
|
54
37
|
```
|
|
55
38
|
|
|
56
|
-
|
|
39
|
+
The client can call that route with the corresponding hook:
|
|
57
40
|
|
|
58
41
|
```tsx
|
|
59
|
-
import {
|
|
60
|
-
import { Text, View } from 'react-native' // or any other renderer
|
|
61
|
-
|
|
62
|
-
function HeadlessMessage({ content }) {
|
|
63
|
-
const messageData = useMessage({
|
|
64
|
-
content,
|
|
65
|
-
messageId: 'msg-1',
|
|
66
|
-
role: 'assistant',
|
|
67
|
-
})
|
|
68
|
-
|
|
69
|
-
return (
|
|
70
|
-
<View>
|
|
71
|
-
{messageData.elements.map((element) => (
|
|
72
|
-
<Text key={element.key}>
|
|
73
|
-
{element.type === 'text' ? element.data : JSON.stringify(element)}
|
|
74
|
-
</Text>
|
|
75
|
-
))}
|
|
76
|
-
</View>
|
|
77
|
-
)
|
|
78
|
-
}
|
|
42
|
+
import { useChat, useMessages, useSendMessage } from '@v0-sdk/react/swr'
|
|
79
43
|
|
|
80
|
-
function
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
role: 'assistant',
|
|
44
|
+
export function Chat({ chatId }: { chatId: string }) {
|
|
45
|
+
const chat = useChat(`/api/v0/chats/${chatId}`)
|
|
46
|
+
const messages = useMessages(`/api/v0/chats/${chatId}/messages`, {
|
|
47
|
+
limit: 50,
|
|
85
48
|
})
|
|
49
|
+
const send = useSendMessage(`/api/v0/chats/${chatId}/messages/stream`)
|
|
86
50
|
|
|
87
|
-
if (
|
|
88
|
-
return <
|
|
51
|
+
if (chat.isLoading || messages.isLoading) {
|
|
52
|
+
return <p>Loading…</p>
|
|
89
53
|
}
|
|
90
54
|
|
|
91
|
-
if (
|
|
92
|
-
return <
|
|
55
|
+
if (chat.error || messages.error) {
|
|
56
|
+
return <p>Unable to load the chat.</p>
|
|
93
57
|
}
|
|
94
58
|
|
|
95
59
|
return (
|
|
96
|
-
<
|
|
97
|
-
{
|
|
98
|
-
<Text key={element.key}>
|
|
99
|
-
{element.type === 'text' ? element.data : JSON.stringify(element)}
|
|
100
|
-
</Text>
|
|
101
|
-
))}
|
|
102
|
-
</View>
|
|
103
|
-
)
|
|
104
|
-
}
|
|
105
|
-
```
|
|
106
|
-
|
|
107
|
-
### Ink CLI Example
|
|
108
|
-
|
|
109
|
-
```tsx
|
|
110
|
-
import { useMessage } from '@v0-sdk/react'
|
|
111
|
-
import { Text, Box } from 'ink'
|
|
112
|
-
|
|
113
|
-
function CliMessage({ content }) {
|
|
114
|
-
const messageData = useMessage({
|
|
115
|
-
content,
|
|
116
|
-
messageId: 'cli-msg',
|
|
117
|
-
role: 'assistant',
|
|
118
|
-
})
|
|
60
|
+
<main>
|
|
61
|
+
<h1>{chat.data?.title}</h1>
|
|
119
62
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
{messageData.elements.map((element) => (
|
|
123
|
-
<Text key={element.key}>
|
|
124
|
-
{element.type === 'text' ? element.data : `[${element.type}]`}
|
|
125
|
-
</Text>
|
|
63
|
+
{messages.data?.messages.map((message) => (
|
|
64
|
+
<article key={message.id}>{message.content}</article>
|
|
126
65
|
))}
|
|
127
|
-
|
|
66
|
+
|
|
67
|
+
<button
|
|
68
|
+
disabled={send.isMutating}
|
|
69
|
+
onClick={async () => {
|
|
70
|
+
const response = await send.trigger({ message: 'Build a dashboard' })
|
|
71
|
+
await response.text()
|
|
72
|
+
await messages.mutate()
|
|
73
|
+
}}
|
|
74
|
+
>
|
|
75
|
+
Send message
|
|
76
|
+
</button>
|
|
77
|
+
</main>
|
|
128
78
|
)
|
|
129
79
|
}
|
|
130
80
|
```
|
|
131
81
|
|
|
132
|
-
##
|
|
133
|
-
|
|
134
|
-
### Core Hooks
|
|
135
|
-
|
|
136
|
-
- `useMessage(props)` - Process message content into headless data structure
|
|
137
|
-
- `useStreamingMessageData(props)` - Handle streaming messages with real-time updates
|
|
138
|
-
- `useStreamingMessage(stream, options)` - Low-level streaming hook
|
|
139
|
-
|
|
140
|
-
### Component Hooks
|
|
141
|
-
|
|
142
|
-
- `useIcon(props)` - Icon data and fallbacks
|
|
143
|
-
- `useCodeBlock(props)` - Code block processing
|
|
144
|
-
- `useMath(props)` - Math content processing
|
|
145
|
-
- `useThinkingSection(props)` - Thinking section state management
|
|
146
|
-
- `useTaskSection(props)` - Task section state and processing
|
|
147
|
-
- `useCodeProject(props)` - Code project structure
|
|
148
|
-
- `useContentPart(part)` - Content part analysis and processing
|
|
82
|
+
## AI SDK `useChat`
|
|
149
83
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
All components are optional JSX renderers that work with DOM environments. For headless usage, use the corresponding hooks instead.
|
|
153
|
-
|
|
154
|
-
- `Message` - Main message renderer
|
|
155
|
-
- `StreamingMessage` - Streaming message with loading states
|
|
156
|
-
- `Icon` - Generic icon component with fallbacks
|
|
157
|
-
- `CodeBlock` - Code syntax highlighting
|
|
158
|
-
- `MathPart` - Math content rendering
|
|
159
|
-
- `ThinkingSection` - Collapsible thinking sections
|
|
160
|
-
- `TaskSection` - Collapsible task sections
|
|
161
|
-
- `CodeProjectPart` - Code project file browser
|
|
162
|
-
- `ContentPartRenderer` - Handles different content part types
|
|
163
|
-
|
|
164
|
-
## Supported Task Types
|
|
165
|
-
|
|
166
|
-
The package automatically handles all v0 Platform API task types:
|
|
167
|
-
|
|
168
|
-
### Explicitly Supported Tasks
|
|
169
|
-
|
|
170
|
-
- `task-thinking-v1` - AI reasoning and thought processes
|
|
171
|
-
- `task-search-web-v1` - Web search operations with results
|
|
172
|
-
- `task-search-repo-v1` - Repository/codebase search functionality
|
|
173
|
-
- `task-diagnostics-v1` - Code analysis and issue detection
|
|
174
|
-
- `task-read-file-v1` - File reading operations
|
|
175
|
-
- `task-coding-v1` - Code generation and editing tasks
|
|
176
|
-
- `task-generate-design-inspiration-v1` - Design inspiration generation
|
|
177
|
-
- `task-start-v1` - Task initialization (usually hidden)
|
|
178
|
-
|
|
179
|
-
### Future-Proof Support
|
|
180
|
-
|
|
181
|
-
Any new task type following the `task-*-v1` pattern will be automatically supported with:
|
|
182
|
-
|
|
183
|
-
- Auto-generated readable titles
|
|
184
|
-
- Appropriate icon selection
|
|
185
|
-
- Proper task section rendering
|
|
186
|
-
- Graceful fallback handling
|
|
187
|
-
|
|
188
|
-
## Customization
|
|
189
|
-
|
|
190
|
-
### Custom Components
|
|
84
|
+
Use AI SDK directly with `V0Transport`. The transport points at your create, send, and resume proxy routes; v0 credentials remain on the server.
|
|
191
85
|
|
|
192
86
|
```tsx
|
|
193
|
-
import {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
87
|
+
import { useChat as useAIChat } from '@ai-sdk/react'
|
|
88
|
+
import {
|
|
89
|
+
shouldResumeV0Chat,
|
|
90
|
+
toV0UIMessages,
|
|
91
|
+
V0Transport,
|
|
92
|
+
type MessagesListResponse,
|
|
93
|
+
type V0UIMessage,
|
|
94
|
+
} from '@v0-sdk/react'
|
|
95
|
+
import { useMemo } from 'react'
|
|
96
|
+
|
|
97
|
+
export function AIChat({ history }: { history: MessagesListResponse['messages'] }) {
|
|
98
|
+
const chatId = history[0]?.chatId
|
|
99
|
+
const transport = useMemo(
|
|
100
|
+
() =>
|
|
101
|
+
new V0Transport({
|
|
102
|
+
chatId,
|
|
103
|
+
messages: history,
|
|
104
|
+
urls: {
|
|
105
|
+
create: '/api/v0/chats/stream',
|
|
106
|
+
send: (id) => `/api/v0/chats/${id}/messages/stream`,
|
|
107
|
+
resume: (id) => `/api/v0/chats/${id}/resume`,
|
|
108
|
+
},
|
|
109
|
+
}),
|
|
110
|
+
[chatId, history],
|
|
211
111
|
)
|
|
212
|
-
}
|
|
213
|
-
```
|
|
214
112
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
const messageData = useMessage({ content })
|
|
222
|
-
|
|
223
|
-
const renderElement = (element) => {
|
|
224
|
-
switch (element.type) {
|
|
225
|
-
case 'text':
|
|
226
|
-
return <MyText>{element.data}</MyText>
|
|
227
|
-
case 'code-project':
|
|
228
|
-
return <MyCodeProject {...element.data} />
|
|
229
|
-
case 'html':
|
|
230
|
-
return <MyHtmlElement {...element.data} />
|
|
231
|
-
default:
|
|
232
|
-
return null
|
|
233
|
-
}
|
|
234
|
-
}
|
|
113
|
+
const chat = useAIChat<V0UIMessage>({
|
|
114
|
+
id: chatId,
|
|
115
|
+
messages: toV0UIMessages(history),
|
|
116
|
+
resume: shouldResumeV0Chat(history),
|
|
117
|
+
transport,
|
|
118
|
+
})
|
|
235
119
|
|
|
236
|
-
return <
|
|
120
|
+
return <button onClick={() => chat.sendMessage({ text: 'Build a dashboard' })}>Send</button>
|
|
237
121
|
}
|
|
238
122
|
```
|
|
239
123
|
|
|
240
|
-
|
|
124
|
+
`toV0UIMessages` maps persisted newest-first v0 history to chronological AI SDK messages. Text, reasoning, files, tools, rich v0 data parts, metadata, and resumable state are preserved. To stop generation, import `useStopMessage` from `@v0-sdk/react/swr`, call it for the active assistant on the server, then call the AI SDK's `chat.stop()` locally.
|
|
241
125
|
|
|
242
|
-
|
|
126
|
+
When a newly created chat should immediately navigate to a different page, stop
|
|
127
|
+
the current transport directly from `onChatCreated`:
|
|
243
128
|
|
|
244
129
|
```tsx
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
} from '@v0-sdk/react'
|
|
130
|
+
const transport = new V0Transport({
|
|
131
|
+
urls,
|
|
132
|
+
onChatCreated(chatId, { stop }) {
|
|
133
|
+
stop()
|
|
134
|
+
router.push(`/chats/${chatId}`)
|
|
135
|
+
},
|
|
136
|
+
})
|
|
253
137
|
```
|
|
254
138
|
|
|
255
|
-
##
|
|
139
|
+
## Pending tasks
|
|
256
140
|
|
|
257
|
-
|
|
141
|
+
Use `getPendingV0Task` to find the latest questions, plan, integration request,
|
|
142
|
+
or permission request carried by a v0 UI message:
|
|
258
143
|
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
3. **Gradually migrate** components as needed
|
|
144
|
+
```tsx
|
|
145
|
+
import { getPendingV0Task } from '@v0-sdk/react'
|
|
262
146
|
|
|
263
|
-
|
|
147
|
+
const pendingTask = getPendingV0Task(chat.messages.at(-1)!)
|
|
148
|
+
```
|
|
264
149
|
|
|
265
|
-
|
|
266
|
-
import { useMessage, useIcon } from '@v0-sdk/react'
|
|
267
|
-
import { View, Text, ScrollView } from 'react-native'
|
|
268
|
-
|
|
269
|
-
function RNMessage({ content }) {
|
|
270
|
-
const messageData = useMessage({ content })
|
|
271
|
-
|
|
272
|
-
const renderElement = (element) => {
|
|
273
|
-
if (element.type === 'text') {
|
|
274
|
-
return <Text key={element.key}>{element.data}</Text>
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
if (element.type === 'html' && element.data.tagName === 'p') {
|
|
278
|
-
return (
|
|
279
|
-
<Text key={element.key} style={{ marginVertical: 8 }}>
|
|
280
|
-
{element.children?.map(renderElement)}
|
|
281
|
-
</Text>
|
|
282
|
-
)
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
return <Text key={element.key}>[{element.type}]</Text>
|
|
286
|
-
}
|
|
150
|
+
## Cache revalidation
|
|
287
151
|
|
|
288
|
-
|
|
289
|
-
}
|
|
152
|
+
Related mounted queries are revalidated after successful mutations:
|
|
290
153
|
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
}
|
|
295
|
-
```
|
|
154
|
+
- `useDeleteChat` revalidates chat lists.
|
|
155
|
+
- `useRestoreMessage` and `useUpdateChatFiles` revalidate messages and files.
|
|
156
|
+
- `useUpdateChat` revalidates the chat and chat lists.
|
|
296
157
|
|
|
297
|
-
|
|
158
|
+
Pass `revalidate: false` to the mutation configuration to opt out.
|
|
298
159
|
|
|
299
|
-
|
|
160
|
+
See [`examples/react-chat`](../../examples/react-chat) for a complete one-page app and authenticated proxy routes.
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { ChatsCreateStreamData, Message, MessagesSendStreamData, V0StreamFinal, V0StreamResult, V0StreamUpdate } from "v0/browser";
|
|
2
|
+
import { ChatTransport, UIMessage, UIMessageChunk } from "ai";
|
|
3
|
+
|
|
4
|
+
//#region src/chat/messages.d.ts
|
|
5
|
+
type V0Part = Message['parts'][number];
|
|
6
|
+
type Serialized<T> = T extends Date ? string : T extends Array<infer Item> ? Array<Serialized<Item>> : T extends object ? { [Key in keyof T]: Serialized<T[Key]> } : T;
|
|
7
|
+
type V0UIMessageMetadata = Serialized<Partial<Omit<Message, 'role' | 'content' | 'parts'>>>;
|
|
8
|
+
type V0DataPart = Exclude<V0Part, {
|
|
9
|
+
type: 'text' | 'thinking';
|
|
10
|
+
}>;
|
|
11
|
+
type V0UIDataTypes = { [Part in V0DataPart as `v0-${Part['type']}`]: Serialized<Omit<Part, 'type'>> };
|
|
12
|
+
type V0UIMessage = UIMessage<V0UIMessageMetadata, V0UIDataTypes>;
|
|
13
|
+
/** Converts a persisted v0 message to an AI SDK UI message. */
|
|
14
|
+
declare function toV0UIMessage(message: Message): V0UIMessage;
|
|
15
|
+
/** Converts SDK history to chronological AI SDK UI messages. */
|
|
16
|
+
declare function toV0UIMessages(messages: readonly Message[], options?: {
|
|
17
|
+
newestFirst?: boolean;
|
|
18
|
+
}): V0UIMessage[];
|
|
19
|
+
declare function toV0UIMessageMetadata(message: Message): V0UIMessageMetadata;
|
|
20
|
+
declare function serializeDates<T>(value: T): Serialized<T>;
|
|
21
|
+
declare function getV0PartId(messageId: string, index: number): string;
|
|
22
|
+
//#endregion
|
|
23
|
+
//#region src/chat/chunks.d.ts
|
|
24
|
+
type V0Chunk = UIMessageChunk<V0UIMessageMetadata, V0UIDataTypes>;
|
|
25
|
+
/** Converts accumulated v0 message snapshots into incremental AI SDK chunks. */
|
|
26
|
+
declare class V0SnapshotChunkReducer {
|
|
27
|
+
private previous;
|
|
28
|
+
private metadata;
|
|
29
|
+
private metadataJson;
|
|
30
|
+
private started;
|
|
31
|
+
private finished;
|
|
32
|
+
private readonly activeText;
|
|
33
|
+
private readonly textPartAttempts;
|
|
34
|
+
constructor(seed?: Message);
|
|
35
|
+
push(update: V0StreamUpdate | V0StreamFinal, final?: boolean): V0Chunk[];
|
|
36
|
+
private updateTextPart;
|
|
37
|
+
}
|
|
38
|
+
/** Adapts a parsed v0 stream to the stream consumed by AI SDK `useChat`. */
|
|
39
|
+
declare function v0StreamToUIMessageStream(result: V0StreamResult, options?: {
|
|
40
|
+
seed?: Message;
|
|
41
|
+
/**
|
|
42
|
+
* Return `false` to stop forwarding the stream without surfacing an error
|
|
43
|
+
* to the consumer.
|
|
44
|
+
*/
|
|
45
|
+
onUpdate?: (update: V0StreamUpdate | V0StreamFinal) => boolean | void;
|
|
46
|
+
onClose?: () => void;
|
|
47
|
+
abort?: (reason?: unknown) => void;
|
|
48
|
+
}): ReadableStream<V0Chunk>;
|
|
49
|
+
//#endregion
|
|
50
|
+
//#region src/chat/composition.d.ts
|
|
51
|
+
/** True only when the newest SDK message is an unfinished assistant. */
|
|
52
|
+
declare function shouldResumeV0Chat(messages: readonly Message[]): boolean;
|
|
53
|
+
declare function getResumableV0Assistant(messages: readonly Message[]): Message | undefined;
|
|
54
|
+
/**
|
|
55
|
+
* Prepends an older newest-first SDK page without replacing active AI SDK
|
|
56
|
+
* message objects already present in local state.
|
|
57
|
+
*/
|
|
58
|
+
declare function prependV0UIMessageHistory(current: readonly V0UIMessage[], olderNewestFirst: readonly Message[]): V0UIMessage[];
|
|
59
|
+
//#endregion
|
|
60
|
+
//#region src/chat/tasks.d.ts
|
|
61
|
+
type MessagePart = V0UIMessage['parts'][number];
|
|
62
|
+
type AgentActionPart = Extract<MessagePart, {
|
|
63
|
+
type: 'data-v0-agent-action';
|
|
64
|
+
}>;
|
|
65
|
+
type AgentActionData = NonNullable<AgentActionPart['data']['data']>;
|
|
66
|
+
type QuestionsData = Extract<AgentActionData, {
|
|
67
|
+
questions: unknown;
|
|
68
|
+
}>;
|
|
69
|
+
type PlanData = Extract<AgentActionData, {
|
|
70
|
+
plan: unknown;
|
|
71
|
+
}>;
|
|
72
|
+
type IntegrationData = Extract<AgentActionData, {
|
|
73
|
+
requestedIntegrations: unknown;
|
|
74
|
+
}>;
|
|
75
|
+
type ToolCallPart = Extract<MessagePart, {
|
|
76
|
+
type: 'data-v0-tool-call';
|
|
77
|
+
}>;
|
|
78
|
+
type Permission = NonNullable<ToolCallPart['data']['suggestedPermissions']>[number];
|
|
79
|
+
type V0PendingTask = {
|
|
80
|
+
type: 'questions';
|
|
81
|
+
data: QuestionsData;
|
|
82
|
+
} | {
|
|
83
|
+
type: 'plan';
|
|
84
|
+
data: PlanData;
|
|
85
|
+
} | {
|
|
86
|
+
type: 'integration';
|
|
87
|
+
data: IntegrationData;
|
|
88
|
+
} | {
|
|
89
|
+
type: 'permissions';
|
|
90
|
+
permissions: Permission[];
|
|
91
|
+
};
|
|
92
|
+
/** Returns the most recent user-resolvable task carried by a v0 message. */
|
|
93
|
+
declare function getPendingV0Task(message: V0UIMessage): V0PendingTask | null;
|
|
94
|
+
//#endregion
|
|
95
|
+
//#region src/request.d.ts
|
|
96
|
+
type V0Fetch = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
|
|
97
|
+
interface V0RequestOptions extends Omit<RequestInit, 'body' | 'method'> {
|
|
98
|
+
/** Override the Fetch implementation for this hook. */
|
|
99
|
+
fetch?: V0Fetch;
|
|
100
|
+
}
|
|
101
|
+
type V0HttpMethod = Uppercase<'get' | 'post' | 'patch' | 'delete' | 'put'>;
|
|
102
|
+
type V0ResponseKind = 'json' | 'stream' | 'blob';
|
|
103
|
+
type V0ResponseTransformer<Data> = (data: unknown) => Data | Promise<Data>;
|
|
104
|
+
interface V0Operation<Data> {
|
|
105
|
+
id: string;
|
|
106
|
+
method: V0HttpMethod;
|
|
107
|
+
response: V0ResponseKind;
|
|
108
|
+
transform?: V0ResponseTransformer<Data>;
|
|
109
|
+
/** Query operation IDs revalidated after this mutation succeeds. */
|
|
110
|
+
invalidates?: readonly string[];
|
|
111
|
+
}
|
|
112
|
+
/** HTTP error returned by the application's v0 proxy. */
|
|
113
|
+
declare class V0ResponseError<Body = unknown> extends Error {
|
|
114
|
+
readonly status: number;
|
|
115
|
+
readonly statusText: string;
|
|
116
|
+
readonly body: Body;
|
|
117
|
+
readonly response: Response;
|
|
118
|
+
constructor(response: Response, body: Body, message?: string);
|
|
119
|
+
}
|
|
120
|
+
//#endregion
|
|
121
|
+
//#region src/chat/transport.d.ts
|
|
122
|
+
type V0TransportChatUrl = string | ((chatId: string) => string);
|
|
123
|
+
interface V0TransportUrls {
|
|
124
|
+
create: string;
|
|
125
|
+
send: V0TransportChatUrl;
|
|
126
|
+
resume: V0TransportChatUrl;
|
|
127
|
+
}
|
|
128
|
+
interface V0TransportStreamControls {
|
|
129
|
+
/** Stops the active transport stream without reporting an error to `useChat`. */
|
|
130
|
+
stop: () => void;
|
|
131
|
+
}
|
|
132
|
+
interface V0TransportOptions {
|
|
133
|
+
urls: V0TransportUrls;
|
|
134
|
+
chatId?: string;
|
|
135
|
+
/** Newest-first SDK history, used to seed a resumed assistant. */
|
|
136
|
+
messages?: readonly Message[];
|
|
137
|
+
create?: Omit<ChatsCreateStreamData['body'], 'message' | 'attachments'>;
|
|
138
|
+
send?: Omit<MessagesSendStreamData['body'], 'message' | 'attachments'>;
|
|
139
|
+
request?: V0RequestOptions;
|
|
140
|
+
onChatCreated?: (chatId: string, controls: V0TransportStreamControls) => void;
|
|
141
|
+
}
|
|
142
|
+
/** AI SDK chat transport backed by caller-owned v0 proxy routes. */
|
|
143
|
+
declare class V0Transport implements ChatTransport<V0UIMessage> {
|
|
144
|
+
private currentChatId;
|
|
145
|
+
private reconnecting;
|
|
146
|
+
private readonly seed;
|
|
147
|
+
private readonly options;
|
|
148
|
+
constructor(options: V0TransportOptions);
|
|
149
|
+
get chatId(): string | undefined;
|
|
150
|
+
sendMessages(options: Parameters<ChatTransport<V0UIMessage>['sendMessages']>[0]): Promise<ReadableStream<UIMessageChunk>>;
|
|
151
|
+
reconnectToStream(options: Parameters<ChatTransport<V0UIMessage>['reconnectToStream']>[0]): Promise<ReadableStream<UIMessageChunk> | null>;
|
|
152
|
+
private captureChatId;
|
|
153
|
+
}
|
|
154
|
+
//#endregion
|
|
155
|
+
export { V0UIMessageMetadata as C, toV0UIMessageMetadata as D, toV0UIMessage as E, toV0UIMessages as O, V0UIMessage as S, serializeDates as T, shouldResumeV0Chat as _, V0TransportUrls as a, Serialized as b, V0Operation as c, V0ResponseKind as d, V0ResponseTransformer as f, prependV0UIMessageHistory as g, getResumableV0Assistant as h, V0TransportStreamControls as i, V0RequestOptions as l, getPendingV0Task as m, V0TransportChatUrl as n, V0Fetch as o, V0PendingTask as p, V0TransportOptions as r, V0HttpMethod as s, V0Transport as t, V0ResponseError as u, V0SnapshotChunkReducer as v, getV0PartId as w, V0UIDataTypes as x, v0StreamToUIMessageStream as y };
|
|
156
|
+
//# sourceMappingURL=index-DI_VZvSr.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-DI_VZvSr.d.mts","names":[],"sources":["../src/chat/messages.ts","../src/chat/chunks.ts","../src/chat/composition.ts","../src/chat/tasks.ts","../src/request.ts","../src/chat/transport.ts"],"mappings":";;;;KAGK,MAAA,GAAS,OAAA;AAAA,KACF,UAAA,MAAgB,CAAA,SAAU,IAAA,YAElC,CAAA,SAAU,KAAA,eACR,KAAA,CAAM,UAAA,CAAW,IAAA,KACjB,CAAA,kCACkB,CAAA,GAAI,UAAA,CAAW,CAAA,CAAE,GAAA,OACjC,CAAA;AAAA,KAEI,mBAAA,GAAsB,UAAA,CAAW,OAAA,CAAQ,IAAA,CAAK,OAAA;AAAA,KAErD,UAAA,GAAa,OAAA,CAAQ,MAAA;EAAU,IAAA;AAAA;AAAA,KAExB,aAAA,cACD,UAAA,UAAoB,IAAA,aAAiB,UAAA,CAAW,IAAA,CAAK,IAAA;AAAA,KAGpD,WAAA,GAAc,SA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