@v0-sdk/react 0.1.1 → 0.2.0
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/LICENSE +13 -0
- package/README.md +61 -11
- package/dist/index.cjs +446 -244
- package/dist/index.d.ts +67 -21
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +429 -248
- package/package.json +5 -2
package/LICENSE
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Copyright 2025 Vercel, Inc.
|
|
2
|
+
|
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License.
|
|
5
|
+
You may obtain a copy of the License at
|
|
6
|
+
|
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
|
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
See the License for the specific language governing permissions and
|
|
13
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# @v0-sdk/react
|
|
2
2
|
|
|
3
|
+
> **⚠️ Developer Preview**: This SDK is currently in beta and is subject to change. Use in production at your own risk.
|
|
4
|
+
|
|
3
5
|
React components for rendering content from the v0 Platform API.
|
|
4
6
|
|
|
5
7
|
## Installation
|
|
@@ -35,20 +37,68 @@ function ChatMessage({ apiResponse }) {
|
|
|
35
37
|
|
|
36
38
|
### With Streaming
|
|
37
39
|
|
|
40
|
+
The package provides built-in support for streaming responses from v0 API:
|
|
41
|
+
|
|
38
42
|
```tsx
|
|
39
|
-
import {
|
|
43
|
+
import { StreamingMessage } from '@v0-sdk/react'
|
|
44
|
+
import { createClient } from 'v0-sdk'
|
|
40
45
|
|
|
41
|
-
|
|
42
|
-
|
|
46
|
+
const v0 = createClient()
|
|
47
|
+
|
|
48
|
+
function ChatDemo() {
|
|
49
|
+
const [stream, setStream] = useState<ReadableStream<Uint8Array> | null>(null)
|
|
50
|
+
|
|
51
|
+
const handleSendMessage = async (message: string) => {
|
|
52
|
+
const response = await v0.chats.create({
|
|
53
|
+
message,
|
|
54
|
+
responseMode: 'experimental_stream',
|
|
55
|
+
})
|
|
56
|
+
setStream(response)
|
|
57
|
+
}
|
|
43
58
|
|
|
44
59
|
return (
|
|
45
|
-
<
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
60
|
+
<div>
|
|
61
|
+
{stream && (
|
|
62
|
+
<StreamingMessage
|
|
63
|
+
stream={stream}
|
|
64
|
+
messageId="demo-message"
|
|
65
|
+
role="assistant"
|
|
66
|
+
onComplete={(content) => console.log('Stream complete:', content)}
|
|
67
|
+
/>
|
|
68
|
+
)}
|
|
69
|
+
</div>
|
|
70
|
+
)
|
|
71
|
+
}
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Using the Streaming Hook
|
|
75
|
+
|
|
76
|
+
For more control, use the `useStreamingMessage` hook directly:
|
|
77
|
+
|
|
78
|
+
```tsx
|
|
79
|
+
import { useStreamingMessage, Message } from '@v0-sdk/react'
|
|
80
|
+
|
|
81
|
+
function CustomStreamingComponent({
|
|
82
|
+
stream,
|
|
83
|
+
}: {
|
|
84
|
+
stream: ReadableStream<Uint8Array>
|
|
85
|
+
}) {
|
|
86
|
+
const { content, isStreaming, error, isComplete } =
|
|
87
|
+
useStreamingMessage(stream)
|
|
88
|
+
|
|
89
|
+
if (error) return <div>Error: {error}</div>
|
|
90
|
+
|
|
91
|
+
return (
|
|
92
|
+
<div>
|
|
93
|
+
<div>Status: {isStreaming ? 'Streaming...' : 'Complete'}</div>
|
|
94
|
+
<Message
|
|
95
|
+
content={content}
|
|
96
|
+
streaming={isStreaming}
|
|
97
|
+
isLastMessage={true}
|
|
98
|
+
messageId="custom-streaming"
|
|
99
|
+
role="assistant"
|
|
100
|
+
/>
|
|
101
|
+
</div>
|
|
52
102
|
)
|
|
53
103
|
}
|
|
54
104
|
```
|
|
@@ -424,4 +474,4 @@ const myMessage: MessageProps = {
|
|
|
424
474
|
|
|
425
475
|
## License
|
|
426
476
|
|
|
427
|
-
|
|
477
|
+
Apache 2.0
|