@v0-sdk/react 0.5.0 → 3.0.0-canary.9ae7b76

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/dist/index.d.ts DELETED
@@ -1,594 +0,0 @@
1
- import React$1 from 'react';
2
-
3
- /**
4
- * Binary format for message content as returned by the v0 Platform API
5
- * Each row is a tuple where the first element is the type and the rest are data
6
- */
7
- type MessageBinaryFormat = [number, ...any[]][];
8
- /**
9
- * Individual row in the message binary format
10
- */
11
- type MessageBinaryFormatRow = MessageBinaryFormat[number];
12
- /**
13
- * Props for the Message component
14
- */
15
- interface MessageProps {
16
- /**
17
- * The parsed content from the v0 Platform API
18
- * This should be the JSON.parsed value of the 'content' field from API responses
19
- */
20
- content: MessageBinaryFormat;
21
- /**
22
- * Optional message ID for tracking purposes
23
- */
24
- messageId?: string;
25
- /**
26
- * Role of the message sender
27
- */
28
- role?: 'user' | 'assistant' | 'system' | 'tool';
29
- /**
30
- * Whether the message is currently being streamed
31
- */
32
- streaming?: boolean;
33
- /**
34
- * Whether this is the last message in the conversation
35
- */
36
- isLastMessage?: boolean;
37
- /**
38
- * Custom className for styling the root container
39
- */
40
- className?: string;
41
- /**
42
- * Custom component renderers (react-markdown style)
43
- * Override specific components by name
44
- * Can be either a React component or an object with className for simple styling
45
- */
46
- components?: {
47
- CodeBlock?: React.ComponentType<{
48
- language: string;
49
- code: string;
50
- className?: string;
51
- }>;
52
- MathPart?: React.ComponentType<{
53
- content: string;
54
- inline?: boolean;
55
- className?: string;
56
- }>;
57
- CodeProjectPart?: React.ComponentType<{
58
- title?: string;
59
- filename?: string;
60
- code?: string;
61
- language?: string;
62
- collapsed?: boolean;
63
- className?: string;
64
- }>;
65
- ThinkingSection?: React.ComponentType<{
66
- title?: string;
67
- duration?: number;
68
- thought?: string;
69
- collapsed?: boolean;
70
- onCollapse?: () => void;
71
- className?: string;
72
- children?: React.ReactNode;
73
- brainIcon?: React.ReactNode;
74
- chevronRightIcon?: React.ReactNode;
75
- chevronDownIcon?: React.ReactNode;
76
- }>;
77
- TaskSection?: React.ComponentType<{
78
- title?: string;
79
- type?: string;
80
- parts?: any[];
81
- collapsed?: boolean;
82
- onCollapse?: () => void;
83
- className?: string;
84
- children?: React.ReactNode;
85
- taskIcon?: React.ReactNode;
86
- chevronRightIcon?: React.ReactNode;
87
- chevronDownIcon?: React.ReactNode;
88
- }>;
89
- Icon?: React.ComponentType<{
90
- name: 'chevron-right' | 'chevron-down' | 'search' | 'folder' | 'settings' | 'file-text' | 'brain' | 'wrench';
91
- className?: string;
92
- }>;
93
- p?: React.ComponentType<React.HTMLAttributes<HTMLParagraphElement>> | {
94
- className?: string;
95
- };
96
- h1?: React.ComponentType<React.HTMLAttributes<HTMLHeadingElement>> | {
97
- className?: string;
98
- };
99
- h2?: React.ComponentType<React.HTMLAttributes<HTMLHeadingElement>> | {
100
- className?: string;
101
- };
102
- h3?: React.ComponentType<React.HTMLAttributes<HTMLHeadingElement>> | {
103
- className?: string;
104
- };
105
- h4?: React.ComponentType<React.HTMLAttributes<HTMLHeadingElement>> | {
106
- className?: string;
107
- };
108
- h5?: React.ComponentType<React.HTMLAttributes<HTMLHeadingElement>> | {
109
- className?: string;
110
- };
111
- h6?: React.ComponentType<React.HTMLAttributes<HTMLHeadingElement>> | {
112
- className?: string;
113
- };
114
- ul?: React.ComponentType<React.HTMLAttributes<HTMLUListElement>> | {
115
- className?: string;
116
- };
117
- ol?: React.ComponentType<React.HTMLAttributes<HTMLOListElement>> | {
118
- className?: string;
119
- };
120
- li?: React.ComponentType<React.HTMLAttributes<HTMLLIElement>> | {
121
- className?: string;
122
- };
123
- blockquote?: React.ComponentType<React.HTMLAttributes<HTMLQuoteElement>> | {
124
- className?: string;
125
- };
126
- code?: React.ComponentType<React.HTMLAttributes<HTMLElement>> | {
127
- className?: string;
128
- };
129
- pre?: React.ComponentType<React.HTMLAttributes<HTMLPreElement>> | {
130
- className?: string;
131
- };
132
- strong?: React.ComponentType<React.HTMLAttributes<HTMLElement>> | {
133
- className?: string;
134
- };
135
- em?: React.ComponentType<React.HTMLAttributes<HTMLElement>> | {
136
- className?: string;
137
- };
138
- a?: React.ComponentType<React.AnchorHTMLAttributes<HTMLAnchorElement>> | {
139
- className?: string;
140
- };
141
- hr?: React.ComponentType<React.HTMLAttributes<HTMLHRElement>> | {
142
- className?: string;
143
- };
144
- div?: React.ComponentType<React.HTMLAttributes<HTMLDivElement>> | {
145
- className?: string;
146
- };
147
- span?: React.ComponentType<React.HTMLAttributes<HTMLSpanElement>> | {
148
- className?: string;
149
- };
150
- };
151
- /**
152
- * @deprecated Use `components` instead. Will be removed in next major version.
153
- */
154
- renderers?: {
155
- CodeBlock?: React.ComponentType<{
156
- language: string;
157
- code: string;
158
- className?: string;
159
- }>;
160
- MathRenderer?: React.ComponentType<{
161
- content: string;
162
- inline?: boolean;
163
- className?: string;
164
- }>;
165
- MathPart?: React.ComponentType<{
166
- content: string;
167
- inline?: boolean;
168
- className?: string;
169
- }>;
170
- Icon?: React.ComponentType<{
171
- name: 'chevron-right' | 'chevron-down' | 'search' | 'folder' | 'settings' | 'file-text' | 'brain' | 'wrench';
172
- className?: string;
173
- }>;
174
- };
175
- }
176
- type MessageRendererProps = MessageProps;
177
- type V0MessageRendererProps = MessageProps;
178
-
179
- interface MessageData {
180
- elements: MessageElement[];
181
- messageId: string;
182
- role: string;
183
- streaming: boolean;
184
- isLastMessage: boolean;
185
- }
186
- interface MessageElement {
187
- type: 'text' | 'html' | 'component' | 'content-part' | 'code-project';
188
- key: string;
189
- data: any;
190
- props?: Record<string, any>;
191
- children?: MessageElement[];
192
- }
193
- declare function useMessage({ content, messageId, role, streaming, isLastMessage, components, renderers, }: Omit<MessageProps, 'className'>): MessageData;
194
- declare function MessageImpl({ content, messageId, role, streaming, isLastMessage, className, components, renderers, }: MessageProps): React$1.FunctionComponentElement<{
195
- messageData: MessageData;
196
- className?: string;
197
- }>;
198
- /**
199
- * Main component for rendering v0 Platform API message content
200
- * This is a backward-compatible JSX renderer. For headless usage, use the useMessage hook.
201
- */
202
- declare const Message: React$1.MemoExoticComponent<typeof MessageImpl>;
203
-
204
- interface StreamingMessageState {
205
- content: MessageBinaryFormat;
206
- isStreaming: boolean;
207
- error?: string;
208
- isComplete: boolean;
209
- }
210
- interface UseStreamingMessageOptions {
211
- onChunk?: (chunk: MessageBinaryFormat) => void;
212
- onComplete?: (finalContent: MessageBinaryFormat) => void;
213
- onError?: (error: string) => void;
214
- onChatData?: (chatData: any) => void;
215
- }
216
- /**
217
- * Hook for handling streaming message content from v0 API using useSyncExternalStore
218
- */
219
- declare function useStreamingMessage(stream: ReadableStream<Uint8Array> | null, options?: UseStreamingMessageOptions): StreamingMessageState;
220
-
221
- interface StreamingMessageProps extends Omit<MessageProps, 'content' | 'streaming' | 'isLastMessage'>, UseStreamingMessageOptions {
222
- /**
223
- * The streaming response from v0.chats.create() with responseMode: 'experimental_stream'
224
- */
225
- stream: ReadableStream<Uint8Array> | null;
226
- /**
227
- * Show a loading indicator while no content has been received yet
228
- */
229
- showLoadingIndicator?: boolean;
230
- /**
231
- * Custom loading component
232
- */
233
- loadingComponent?: React$1.ReactNode;
234
- /**
235
- * Custom error component
236
- */
237
- errorComponent?: (error: string) => React$1.ReactNode;
238
- }
239
- interface StreamingMessageData extends StreamingMessageState {
240
- messageData: MessageData | null;
241
- }
242
- declare function useStreamingMessageData({ stream, messageId, role, components, renderers, onChunk, onComplete, onError, onChatData, }: Omit<StreamingMessageProps, 'className' | 'showLoadingIndicator' | 'loadingComponent' | 'errorComponent'>): StreamingMessageData;
243
- /**
244
- * Component for rendering streaming message content from v0 API
245
- *
246
- * For headless usage, use the useStreamingMessageData hook instead.
247
- *
248
- * @example
249
- * ```tsx
250
- * import { v0 } from 'v0-sdk'
251
- * import { StreamingMessage } from '@v0-sdk/react'
252
- *
253
- * function ChatDemo() {
254
- * const [stream, setStream] = useState<ReadableStream<Uint8Array> | null>(null)
255
- *
256
- * const handleSubmit = async () => {
257
- * const response = await v0.chats.create({
258
- * message: 'Create a button component',
259
- * responseMode: 'experimental_stream'
260
- * })
261
- * setStream(response)
262
- * }
263
- *
264
- * return (
265
- * <div>
266
- * <button onClick={handleSubmit}>Send Message</button>
267
- * {stream && (
268
- * <StreamingMessage
269
- * stream={stream}
270
- * messageId="demo-message"
271
- * role="assistant"
272
- * onComplete={(content) => handleCompletion(content)}
273
- * onChatData={(chatData) => handleChatData(chatData)}
274
- * />
275
- * )}
276
- * </div>
277
- * )
278
- * }
279
- * ```
280
- */
281
- declare function StreamingMessage({ stream, showLoadingIndicator, loadingComponent, errorComponent, onChunk, onComplete, onError, onChatData, className, ...messageProps }: StreamingMessageProps): React$1.FunctionComponentElement<React$1.FragmentProps> | React$1.DetailedReactHTMLElement<{
282
- className: string;
283
- style: {
284
- color: "red";
285
- padding: string;
286
- border: string;
287
- borderRadius: string;
288
- };
289
- }, HTMLElement> | React$1.DetailedReactHTMLElement<{
290
- className: string;
291
- style: {
292
- display: "flex";
293
- alignItems: "center";
294
- gap: string;
295
- color: "#6b7280";
296
- };
297
- }, HTMLElement> | React$1.FunctionComponentElement<MessageProps>;
298
-
299
- interface IconProps {
300
- name: 'chevron-right' | 'chevron-down' | 'search' | 'folder' | 'settings' | 'file-text' | 'brain' | 'wrench';
301
- className?: string;
302
- }
303
- interface IconData {
304
- name: IconProps['name'];
305
- fallback: string;
306
- ariaLabel: string;
307
- }
308
- declare function useIcon(props: IconProps): IconData;
309
- /**
310
- * Generic icon component that can be customized by consumers.
311
- * By default, renders a simple fallback. Consumers should provide
312
- * their own icon implementation via context or props.
313
- *
314
- * For headless usage, use the useIcon hook instead.
315
- */
316
- declare function Icon(props: IconProps): React$1.ReactElement<IconProps, string | React$1.JSXElementConstructor<any>> | React$1.DetailedReactHTMLElement<{
317
- className: string;
318
- 'data-icon': "search" | "brain" | "chevron-right" | "chevron-down" | "folder" | "settings" | "file-text" | "wrench";
319
- 'aria-label': string;
320
- }, HTMLElement>;
321
- /**
322
- * Provider for custom icon implementation
323
- */
324
- declare function IconProvider({ children, component, }: {
325
- children: React$1.ReactNode;
326
- component: React$1.ComponentType<IconProps>;
327
- }): React$1.FunctionComponentElement<React$1.ProviderProps<React$1.ComponentType<IconProps>>>;
328
-
329
- interface ThinkingSectionProps {
330
- title?: string;
331
- duration?: number;
332
- thought?: string;
333
- collapsed?: boolean;
334
- onCollapse?: () => void;
335
- className?: string;
336
- children?: React$1.ReactNode;
337
- iconRenderer?: React$1.ComponentType<IconProps>;
338
- brainIcon?: React$1.ReactNode;
339
- chevronRightIcon?: React$1.ReactNode;
340
- chevronDownIcon?: React$1.ReactNode;
341
- }
342
- interface ThinkingSectionData {
343
- title: string;
344
- duration?: number;
345
- thought?: string;
346
- collapsed: boolean;
347
- paragraphs: string[];
348
- formattedDuration?: string;
349
- }
350
- declare function useThinkingSection({ title, duration, thought, collapsed: initialCollapsed, onCollapse, }: Omit<ThinkingSectionProps, 'className' | 'children' | 'iconRenderer' | 'brainIcon' | 'chevronRightIcon' | 'chevronDownIcon'>): {
351
- data: ThinkingSectionData;
352
- collapsed: boolean;
353
- handleCollapse: () => void;
354
- };
355
- /**
356
- * Generic thinking section component
357
- * Renders a collapsible section with basic structure - consumers provide styling
358
- *
359
- * For headless usage, use the useThinkingSection hook instead.
360
- */
361
- declare function ThinkingSection({ title, duration, thought, collapsed: initialCollapsed, onCollapse, className, children, iconRenderer, brainIcon, chevronRightIcon, chevronDownIcon, }: ThinkingSectionProps): React$1.FunctionComponentElement<React$1.FragmentProps> | React$1.DetailedReactHTMLElement<{
362
- className: string;
363
- 'data-component': string;
364
- }, HTMLElement>;
365
-
366
- interface TaskSectionProps {
367
- title?: string;
368
- type?: string;
369
- parts?: any[];
370
- collapsed?: boolean;
371
- onCollapse?: () => void;
372
- className?: string;
373
- children?: React$1.ReactNode;
374
- iconRenderer?: React$1.ComponentType<IconProps>;
375
- taskIcon?: React$1.ReactNode;
376
- chevronRightIcon?: React$1.ReactNode;
377
- chevronDownIcon?: React$1.ReactNode;
378
- }
379
- interface TaskSectionData {
380
- title: string;
381
- type?: string;
382
- parts: any[];
383
- collapsed: boolean;
384
- meaningfulParts: any[];
385
- shouldShowCollapsible: boolean;
386
- iconName: IconProps['name'];
387
- }
388
- interface TaskPartData {
389
- type: string;
390
- status?: string;
391
- content: React$1.ReactNode;
392
- isSearching?: boolean;
393
- isAnalyzing?: boolean;
394
- isComplete?: boolean;
395
- query?: string;
396
- count?: number;
397
- answer?: string;
398
- sources?: Array<{
399
- url: string;
400
- title: string;
401
- }>;
402
- files?: string[];
403
- issues?: number;
404
- }
405
- declare function useTaskSection({ title, type, parts, collapsed: initialCollapsed, onCollapse, }: Omit<TaskSectionProps, 'className' | 'children' | 'iconRenderer' | 'taskIcon' | 'chevronRightIcon' | 'chevronDownIcon'>): {
406
- data: TaskSectionData;
407
- collapsed: boolean;
408
- handleCollapse: () => void;
409
- processedParts: TaskPartData[];
410
- };
411
- /**
412
- * Generic task section component
413
- * Renders a collapsible task section with basic structure - consumers provide styling
414
- *
415
- * For headless usage, use the useTaskSection hook instead.
416
- */
417
- declare function TaskSection({ title, type, parts, collapsed: initialCollapsed, onCollapse, className, children, iconRenderer, taskIcon, chevronRightIcon, chevronDownIcon, }: TaskSectionProps): React$1.FunctionComponentElement<React$1.FragmentProps> | React$1.DetailedReactHTMLElement<{
418
- className: string;
419
- 'data-component': string;
420
- }, HTMLElement>;
421
-
422
- interface CodeProjectPartProps {
423
- title?: string;
424
- filename?: string;
425
- code?: string;
426
- language?: string;
427
- collapsed?: boolean;
428
- className?: string;
429
- children?: React$1.ReactNode;
430
- iconRenderer?: React$1.ComponentType<IconProps>;
431
- }
432
- interface CodeProjectData {
433
- title: string;
434
- filename?: string;
435
- code?: string;
436
- language: string;
437
- collapsed: boolean;
438
- files: Array<{
439
- name: string;
440
- path: string;
441
- active: boolean;
442
- }>;
443
- }
444
- declare function useCodeProject({ title, filename, code, language, collapsed: initialCollapsed, }: Omit<CodeProjectPartProps, 'className' | 'children' | 'iconRenderer'>): {
445
- data: CodeProjectData;
446
- collapsed: boolean;
447
- toggleCollapsed: () => void;
448
- };
449
- /**
450
- * Generic code project block component
451
- * Renders a collapsible code project with basic structure - consumers provide styling
452
- *
453
- * For headless usage, use the useCodeProject hook instead.
454
- */
455
- declare function CodeProjectPart({ title, filename, code, language, collapsed: initialCollapsed, className, children, iconRenderer, }: CodeProjectPartProps): React$1.FunctionComponentElement<React$1.FragmentProps> | React$1.DetailedReactHTMLElement<{
456
- className: string;
457
- 'data-component': string;
458
- }, HTMLElement>;
459
-
460
- interface ContentPartRendererProps {
461
- part: any;
462
- iconRenderer?: React$1.ComponentType<IconProps>;
463
- thinkingSectionRenderer?: React$1.ComponentType<{
464
- title?: string;
465
- duration?: number;
466
- thought?: string;
467
- collapsed?: boolean;
468
- onCollapse?: () => void;
469
- className?: string;
470
- children?: React$1.ReactNode;
471
- brainIcon?: React$1.ReactNode;
472
- chevronRightIcon?: React$1.ReactNode;
473
- chevronDownIcon?: React$1.ReactNode;
474
- }>;
475
- taskSectionRenderer?: React$1.ComponentType<{
476
- title?: string;
477
- type?: string;
478
- parts?: any[];
479
- collapsed?: boolean;
480
- onCollapse?: () => void;
481
- className?: string;
482
- children?: React$1.ReactNode;
483
- taskIcon?: React$1.ReactNode;
484
- chevronRightIcon?: React$1.ReactNode;
485
- chevronDownIcon?: React$1.ReactNode;
486
- }>;
487
- brainIcon?: React$1.ReactNode;
488
- chevronRightIcon?: React$1.ReactNode;
489
- chevronDownIcon?: React$1.ReactNode;
490
- searchIcon?: React$1.ReactNode;
491
- folderIcon?: React$1.ReactNode;
492
- settingsIcon?: React$1.ReactNode;
493
- wrenchIcon?: React$1.ReactNode;
494
- }
495
- interface ContentPartData {
496
- type: string;
497
- parts: any[];
498
- metadata: Record<string, any>;
499
- componentType: 'thinking' | 'task' | 'unknown' | null;
500
- title?: string;
501
- iconName?: IconProps['name'];
502
- thinkingData?: {
503
- duration?: number;
504
- thought?: string;
505
- };
506
- }
507
- declare function useContentPart(part: any): ContentPartData;
508
- /**
509
- * Content part renderer that handles different types of v0 API content parts
510
- *
511
- * For headless usage, use the useContentPart hook instead.
512
- */
513
- declare function ContentPartRenderer({ part, iconRenderer, thinkingSectionRenderer, taskSectionRenderer, brainIcon, chevronRightIcon, chevronDownIcon, searchIcon, folderIcon, settingsIcon, wrenchIcon, }: ContentPartRendererProps): React$1.ReactElement<{
514
- title?: string;
515
- duration?: number;
516
- thought?: string;
517
- collapsed?: boolean;
518
- onCollapse?: () => void;
519
- className?: string;
520
- children?: React$1.ReactNode;
521
- brainIcon?: React$1.ReactNode;
522
- chevronRightIcon?: React$1.ReactNode;
523
- chevronDownIcon?: React$1.ReactNode;
524
- }, string | React$1.JSXElementConstructor<any>> | React$1.ReactElement<{
525
- title?: string;
526
- type?: string;
527
- parts?: any[];
528
- collapsed?: boolean;
529
- onCollapse?: () => void;
530
- className?: string;
531
- children?: React$1.ReactNode;
532
- taskIcon?: React$1.ReactNode;
533
- chevronRightIcon?: React$1.ReactNode;
534
- chevronDownIcon?: React$1.ReactNode;
535
- }, string | React$1.JSXElementConstructor<any>> | React$1.ReactElement<{
536
- 'data-unknown-part-type': string;
537
- }, string | React$1.JSXElementConstructor<any>>;
538
-
539
- interface MathPartProps {
540
- content: string;
541
- inline?: boolean;
542
- className?: string;
543
- children?: React$1.ReactNode;
544
- displayMode?: boolean;
545
- }
546
- interface MathData {
547
- content: string;
548
- inline: boolean;
549
- displayMode: boolean;
550
- processedContent: string;
551
- }
552
- declare function useMath(props: Omit<MathPartProps, 'className' | 'children'>): MathData;
553
- /**
554
- * Generic math renderer component
555
- * Renders plain math content by default - consumers should provide their own math rendering
556
- *
557
- * For headless usage, use the useMath hook instead.
558
- */
559
- declare function MathPart({ content, inline, className, children, displayMode, }: MathPartProps): React$1.FunctionComponentElement<React$1.FragmentProps> | React$1.DetailedReactHTMLElement<{
560
- className: string;
561
- 'data-math-inline': boolean;
562
- 'data-math-display': boolean;
563
- }, HTMLElement>;
564
-
565
- interface CodeBlockProps {
566
- language: string;
567
- code: string;
568
- className?: string;
569
- children?: React$1.ReactNode;
570
- filename?: string;
571
- }
572
- interface CodeBlockData {
573
- language: string;
574
- code: string;
575
- filename?: string;
576
- lines: string[];
577
- lineCount: number;
578
- }
579
- declare function useCodeBlock(props: Omit<CodeBlockProps, 'className' | 'children'>): CodeBlockData;
580
- /**
581
- * Generic code block component
582
- * Renders plain code by default - consumers should provide their own styling and highlighting
583
- *
584
- * For headless usage, use the useCodeBlock hook instead.
585
- */
586
- declare function CodeBlock({ language, code, className, children, filename, }: CodeBlockProps): React$1.FunctionComponentElement<React$1.FragmentProps> | React$1.DetailedReactHTMLElement<{
587
- 'data-filename': string;
588
- className: string;
589
- 'data-language': string;
590
- }, HTMLElement>;
591
-
592
- export { ContentPartRenderer as AssistantMessageContentPart, CodeBlock, CodeProjectPart as CodeProjectBlock, CodeProjectPart, ContentPartRenderer, Icon, IconProvider, MathPart, MathPart as MathRenderer, Message, Message as MessageContent, Message as MessageRenderer, StreamingMessage, TaskSection, ThinkingSection, Message as V0MessageRenderer, useCodeBlock, useCodeProject, useContentPart, useIcon, useMath, useMessage, useStreamingMessage, useStreamingMessageData, useTaskSection, useThinkingSection };
593
- export type { CodeBlockData, CodeBlockProps, CodeProjectPartProps as CodeProjectBlockProps, CodeProjectData, CodeProjectPartProps, ContentPartData, ContentPartRendererProps, IconData, IconProps, MathData, MathPartProps, MathPartProps as MathRendererProps, MessageBinaryFormat, MessageBinaryFormatRow, MessageData, MessageElement, MessageProps, MessageRendererProps, StreamingMessageData, StreamingMessageProps, StreamingMessageState, TaskPartData, TaskSectionData, TaskSectionProps, ThinkingSectionData, ThinkingSectionProps, UseStreamingMessageOptions, V0MessageRendererProps };
594
- //# sourceMappingURL=index.d.ts.map