@assistant-ui/react 0.0.20 → 0.0.22
Sign up to get free protection for your applications and to get access to all the features.
- package/LICENSE +21 -0
- package/dist/index.d.mts +180 -88
- package/dist/index.d.ts +180 -88
- package/dist/index.js +910 -773
- package/dist/index.mjs +923 -799
- package/package.json +16 -8
package/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2024 Simon Farshid
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
package/dist/index.d.mts
CHANGED
@@ -1,11 +1,23 @@
|
|
1
1
|
import * as react from 'react';
|
2
2
|
import { FC, ReactNode, PropsWithChildren, ComponentType } from 'react';
|
3
3
|
import { TextareaAutosizeProps } from 'react-textarea-autosize';
|
4
|
-
import { UseChatHelpers, UseAssistantHelpers } from 'ai/react';
|
4
|
+
import { UseChatHelpers, UseAssistantHelpers } from '@ai-sdk/react';
|
5
|
+
import { Message, LanguageModel } from 'ai';
|
5
6
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
6
|
-
import { LanguageModel, Message } from 'ai';
|
7
7
|
import { UseBoundStore, StoreApi } from 'zustand';
|
8
8
|
|
9
|
+
declare const useCopyMessage: ({ copiedDuration }: {
|
10
|
+
copiedDuration?: number | undefined;
|
11
|
+
}) => (() => void) | null;
|
12
|
+
|
13
|
+
declare const useReloadMessage: () => (() => void) | null;
|
14
|
+
|
15
|
+
declare const useBeginMessageEdit: () => (() => void) | null;
|
16
|
+
|
17
|
+
declare const useGoToNextBranch: () => (() => void) | null;
|
18
|
+
|
19
|
+
declare const useGoToPreviousBranch: () => (() => void) | null;
|
20
|
+
|
9
21
|
declare const ThreadRoot: react.ForwardRefExoticComponent<Pick<Omit<react.DetailedHTMLProps<react.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
|
10
22
|
ref?: ((instance: HTMLDivElement | null) => void) | react.RefObject<HTMLDivElement> | null | undefined;
|
11
23
|
} & {
|
@@ -103,16 +115,23 @@ declare namespace index$4 {
|
|
103
115
|
export { ComposerCancel as Cancel, ComposerIf as If, ComposerInput as Input, ComposerRoot as Root, ComposerSend as Send };
|
104
116
|
}
|
105
117
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
118
|
+
declare const MessageRoot: react.ForwardRefExoticComponent<Pick<Omit<react.DetailedHTMLProps<react.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
|
119
|
+
ref?: ((instance: HTMLDivElement | null) => void) | react.RefObject<HTMLDivElement> | null | undefined;
|
120
|
+
} & {
|
121
|
+
asChild?: boolean;
|
122
|
+
}, "key" | keyof react.HTMLAttributes<HTMLDivElement> | "asChild"> & react.RefAttributes<HTMLDivElement>>;
|
123
|
+
|
124
|
+
type MessageIfFilters = {
|
125
|
+
user: boolean | undefined;
|
126
|
+
assistant: boolean | undefined;
|
127
|
+
hasBranches: boolean | undefined;
|
128
|
+
copied: boolean | undefined;
|
129
|
+
lastOrHover: boolean | undefined;
|
130
|
+
};
|
131
|
+
type MessageIfProps = RequireAtLeastOne<MessageIfFilters> & {
|
132
|
+
children: ReactNode;
|
133
|
+
};
|
134
|
+
declare const MessageIf: FC<MessageIfProps>;
|
116
135
|
|
117
136
|
type TextContentPart = {
|
118
137
|
type: "text";
|
@@ -153,39 +172,6 @@ type AppendMessage = {
|
|
153
172
|
content: AppendContentPart[];
|
154
173
|
};
|
155
174
|
type ThreadMessage = UserMessage | AssistantMessage;
|
156
|
-
type ThreadState = {
|
157
|
-
messages: ThreadMessage[];
|
158
|
-
isRunning: boolean;
|
159
|
-
getBranches: (messageId: string) => readonly string[];
|
160
|
-
switchToBranch: (branchId: string) => void;
|
161
|
-
append: (message: AppendMessage) => void;
|
162
|
-
startRun: (parentId: string | null) => void;
|
163
|
-
cancelRun: () => void;
|
164
|
-
};
|
165
|
-
|
166
|
-
type MessageProviderProps = PropsWithChildren<{
|
167
|
-
message: ThreadMessage;
|
168
|
-
parentId: string | null;
|
169
|
-
}>;
|
170
|
-
declare const MessageProvider: FC<MessageProviderProps>;
|
171
|
-
|
172
|
-
declare const MessageRoot: react.ForwardRefExoticComponent<Pick<Omit<react.DetailedHTMLProps<react.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
|
173
|
-
ref?: ((instance: HTMLDivElement | null) => void) | react.RefObject<HTMLDivElement> | null | undefined;
|
174
|
-
} & {
|
175
|
-
asChild?: boolean;
|
176
|
-
}, "key" | keyof react.HTMLAttributes<HTMLDivElement> | "asChild"> & react.RefAttributes<HTMLDivElement>>;
|
177
|
-
|
178
|
-
type MessageIfFilters = {
|
179
|
-
user: boolean | undefined;
|
180
|
-
assistant: boolean | undefined;
|
181
|
-
hasBranches: boolean | undefined;
|
182
|
-
copied: boolean | undefined;
|
183
|
-
lastOrHover: boolean | undefined;
|
184
|
-
};
|
185
|
-
type MessageIfProps = RequireAtLeastOne<MessageIfFilters> & {
|
186
|
-
children: ReactNode;
|
187
|
-
};
|
188
|
-
declare const MessageIf: FC<MessageIfProps>;
|
189
175
|
|
190
176
|
type MessageContentProps = {
|
191
177
|
components?: {
|
@@ -210,14 +196,14 @@ type MessageContentProps = {
|
|
210
196
|
};
|
211
197
|
declare const MessageContent: FC<MessageContentProps>;
|
212
198
|
|
213
|
-
declare const MessageInProgress: react.ForwardRefExoticComponent<Pick<Omit<react.DetailedHTMLProps<react.HTMLAttributes<
|
214
|
-
ref?: ((instance:
|
199
|
+
declare const MessageInProgress: react.ForwardRefExoticComponent<Pick<Omit<react.DetailedHTMLProps<react.HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, "ref"> & {
|
200
|
+
ref?: ((instance: HTMLSpanElement | null) => void) | react.RefObject<HTMLSpanElement> | null | undefined;
|
215
201
|
} & {
|
216
202
|
asChild?: boolean;
|
217
|
-
}, "key" | keyof react.HTMLAttributes<
|
203
|
+
}, "key" | "asChild" | keyof react.HTMLAttributes<HTMLSpanElement>> & react.RefAttributes<HTMLSpanElement>>;
|
218
204
|
|
219
205
|
declare namespace index$3 {
|
220
|
-
export { MessageContent as Content, MessageIf as If, MessageInProgress as InProgress,
|
206
|
+
export { MessageContent as Content, MessageIf as If, MessageInProgress as InProgress, MessageRoot as Root };
|
221
207
|
}
|
222
208
|
|
223
209
|
declare const BranchPickerNext: react.ForwardRefExoticComponent<Pick<Omit<react.DetailedHTMLProps<react.ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "ref"> & {
|
@@ -283,36 +269,19 @@ declare namespace index$1 {
|
|
283
269
|
export { ActionBarCopy as Copy, ActionBarEdit as Edit, ActionBarReload as Reload, ActionBarRoot as Root };
|
284
270
|
}
|
285
271
|
|
286
|
-
type ContentPartProviderProps = PropsWithChildren<{
|
287
|
-
part: ThreadMessage["content"][number];
|
288
|
-
status: "in_progress" | "done" | "error";
|
289
|
-
}>;
|
290
|
-
declare const ContentPartProvider: FC<ContentPartProviderProps>;
|
291
|
-
|
292
272
|
declare const ContentPartInProgressIndicator: FC;
|
293
273
|
|
294
274
|
declare namespace index {
|
295
|
-
export { ContentPartInProgressIndicator as InProgressIndicator
|
275
|
+
export { ContentPartInProgressIndicator as InProgressIndicator };
|
296
276
|
}
|
297
277
|
|
298
|
-
type VercelAIAssistantProviderProps = PropsWithChildren<{
|
299
|
-
chat: UseChatHelpers;
|
300
|
-
} | {
|
301
|
-
assistant: UseAssistantHelpers;
|
302
|
-
}>;
|
303
|
-
declare const VercelAIAssistantProvider: FC<VercelAIAssistantProviderProps>;
|
304
|
-
|
305
|
-
type Unsubscribe = () => void;
|
306
|
-
type AssistantRuntime = Readonly<ThreadState> & {
|
307
|
-
subscribe: (callback: () => void) => Unsubscribe;
|
308
|
-
};
|
309
|
-
|
310
278
|
type VercelRSCMessage = {
|
311
279
|
id: string;
|
312
280
|
role: "user" | "assistant";
|
313
281
|
display: ReactNode;
|
314
282
|
createdAt?: Date;
|
315
283
|
};
|
284
|
+
|
316
285
|
type RSCMessageConverter<T> = {
|
317
286
|
convertMessage: (message: T) => VercelRSCMessage;
|
318
287
|
};
|
@@ -325,13 +294,99 @@ type VercelRSCAdapterBase<T> = {
|
|
325
294
|
};
|
326
295
|
type VercelRSCAdapter<T = VercelRSCMessage> = VercelRSCAdapterBase<T> & (T extends VercelRSCMessage ? object : RSCMessageConverter<T>);
|
327
296
|
|
328
|
-
type
|
329
|
-
|
297
|
+
type ThreadState = {
|
298
|
+
messages: ThreadMessage[];
|
299
|
+
isRunning: boolean;
|
300
|
+
getBranches: (messageId: string) => readonly string[];
|
301
|
+
switchToBranch: (branchId: string) => void;
|
302
|
+
append: (message: AppendMessage) => void;
|
303
|
+
startRun: (parentId: string | null) => void;
|
304
|
+
cancelRun: () => void;
|
305
|
+
};
|
330
306
|
|
331
|
-
type
|
332
|
-
|
307
|
+
type Unsubscribe = () => void;
|
308
|
+
type ThreadRuntime = Readonly<ThreadState> & {
|
309
|
+
subscribe: (callback: () => void) => Unsubscribe;
|
310
|
+
};
|
311
|
+
type ReactThreadRuntime = Readonly<ThreadState> & {
|
312
|
+
unstable_synchronizer?: ComponentType;
|
333
313
|
};
|
334
|
-
|
314
|
+
|
315
|
+
type AssistantRuntime = ThreadRuntime;
|
316
|
+
|
317
|
+
declare class VercelRSCRuntime<T extends WeakKey = VercelRSCMessage> implements AssistantRuntime, ReactThreadRuntime {
|
318
|
+
adapter: VercelRSCAdapter<T>;
|
319
|
+
private useAdapter;
|
320
|
+
private _subscriptions;
|
321
|
+
isRunning: boolean;
|
322
|
+
messages: ThreadMessage[];
|
323
|
+
constructor(adapter: VercelRSCAdapter<T>);
|
324
|
+
private withRunning;
|
325
|
+
getBranches(): readonly string[];
|
326
|
+
switchToBranch(): void;
|
327
|
+
append(message: AppendMessage): Promise<void>;
|
328
|
+
startRun(parentId: string | null): Promise<void>;
|
329
|
+
cancelRun(): void;
|
330
|
+
subscribe(callback: () => void): Unsubscribe;
|
331
|
+
onAdapterUpdated(): void;
|
332
|
+
private updateData;
|
333
|
+
unstable_synchronizer: () => null;
|
334
|
+
}
|
335
|
+
|
336
|
+
declare const useVercelRSCRuntime: <T extends WeakKey>(adapter: VercelRSCAdapter<T>) => VercelRSCRuntime<T>;
|
337
|
+
|
338
|
+
declare const getVercelRSCMessage: <T>(message: ThreadMessage) => T | undefined;
|
339
|
+
|
340
|
+
type VercelHelpers = UseChatHelpers | UseAssistantHelpers;
|
341
|
+
|
342
|
+
declare class VercelAIRuntime implements AssistantRuntime, ReactThreadRuntime {
|
343
|
+
vercel: VercelHelpers;
|
344
|
+
private _subscriptions;
|
345
|
+
private repository;
|
346
|
+
private assistantOptimisticId;
|
347
|
+
private useVercel;
|
348
|
+
messages: ThreadMessage[];
|
349
|
+
isRunning: boolean;
|
350
|
+
constructor(vercel: VercelHelpers);
|
351
|
+
getBranches(messageId: string): string[];
|
352
|
+
switchToBranch(branchId: string): void;
|
353
|
+
append(message: AppendMessage): Promise<void>;
|
354
|
+
startRun(parentId: string | null): Promise<void>;
|
355
|
+
cancelRun(): void;
|
356
|
+
subscribe(callback: () => void): Unsubscribe;
|
357
|
+
private updateVercelMessages;
|
358
|
+
onVercelUpdated(): void;
|
359
|
+
private updateData;
|
360
|
+
unstable_synchronizer: () => null;
|
361
|
+
}
|
362
|
+
|
363
|
+
declare const useVercelUseChatRuntime: (chatHelpers: UseChatHelpers) => VercelAIRuntime;
|
364
|
+
|
365
|
+
declare const useVercelUseAssistantRuntime: (assistantHelpers: UseAssistantHelpers) => VercelAIRuntime;
|
366
|
+
|
367
|
+
declare const getVercelAIMessage: (message: ThreadMessage) => Message | undefined;
|
368
|
+
|
369
|
+
/**
|
370
|
+
* @deprecated Will be removed in 0.1.0.
|
371
|
+
*/
|
372
|
+
type VercelAIAssistantProviderProps = PropsWithChildren<{
|
373
|
+
chat: UseChatHelpers;
|
374
|
+
} | {
|
375
|
+
assistant: UseAssistantHelpers;
|
376
|
+
}>;
|
377
|
+
/**
|
378
|
+
* @deprecated `const runtime = useVercelUseChatRuntime(chat)` and `<AssistantRuntimeProvider runtime={...} />`. Will be removed in 0.1.0.
|
379
|
+
*/
|
380
|
+
declare const VercelAIAssistantProvider: FC<VercelAIAssistantProviderProps>;
|
381
|
+
|
382
|
+
/**
|
383
|
+
* @deprecated Will be removed in 0.1.0.
|
384
|
+
*/
|
385
|
+
type VercelRSCAssistantProviderProps<T> = PropsWithChildren<VercelRSCAdapter<T>>;
|
386
|
+
/**
|
387
|
+
* @deprecated Replaced with `const runtime = useVercelRSCRuntime({ messages, append })` and `<AssistantRuntimeProvider runtime={runtime} />`. Will be removed in 0.1.0.
|
388
|
+
*/
|
389
|
+
declare const VercelRSCAssistantProvider: <T extends WeakKey = VercelRSCMessage>({ children, ...adapter }: VercelRSCAssistantProviderProps<T>) => react_jsx_runtime.JSX.Element;
|
335
390
|
|
336
391
|
type ChatModelRunResult = {
|
337
392
|
content: AssistantContentPart[];
|
@@ -372,8 +427,15 @@ declare class VercelModelAdapter implements ChatModelAdapter {
|
|
372
427
|
}>;
|
373
428
|
}
|
374
429
|
|
375
|
-
|
376
|
-
|
430
|
+
type AssistantRuntimeProviderProps = {
|
431
|
+
runtime: AssistantRuntime;
|
432
|
+
};
|
433
|
+
declare const AssistantRuntimeProvider: react.NamedExoticComponent<PropsWithChildren<AssistantRuntimeProviderProps>>;
|
434
|
+
|
435
|
+
type ContentPartState = Readonly<{
|
436
|
+
status: "in_progress" | "done" | "error";
|
437
|
+
part: ThreadMessage["content"][number];
|
438
|
+
}>;
|
377
439
|
|
378
440
|
type MessageState = Readonly<{
|
379
441
|
message: Readonly<ThreadMessage>;
|
@@ -387,23 +449,53 @@ type MessageState = Readonly<{
|
|
387
449
|
isHovering: boolean;
|
388
450
|
setIsHovering: (value: boolean) => void;
|
389
451
|
}>;
|
390
|
-
type MessageStore = {
|
391
|
-
useMessage: UseBoundStore<StoreApi<MessageState>>;
|
392
|
-
useComposer: UseBoundStore<StoreApi<MessageComposerState>>;
|
393
|
-
};
|
394
452
|
|
395
|
-
|
453
|
+
type BaseComposerState = Readonly<{
|
454
|
+
value: string;
|
455
|
+
setValue: (value: string) => void;
|
456
|
+
}>;
|
396
457
|
|
397
|
-
|
398
|
-
|
399
|
-
|
458
|
+
type EditComposerState = BaseComposerState & Readonly<{
|
459
|
+
isEditing: boolean;
|
460
|
+
edit: () => void;
|
461
|
+
send: () => void;
|
462
|
+
cancel: () => boolean;
|
463
|
+
}>;
|
400
464
|
|
401
|
-
|
465
|
+
type ComposerState = BaseComposerState & Readonly<{
|
466
|
+
isEditing: true;
|
467
|
+
send: () => void;
|
468
|
+
cancel: () => boolean;
|
469
|
+
}>;
|
402
470
|
|
403
|
-
|
471
|
+
type ThreadViewportState = {
|
472
|
+
isAtBottom: boolean;
|
473
|
+
scrollToBottom: () => void;
|
474
|
+
onScrollToBottom: (callback: () => void) => () => void;
|
475
|
+
};
|
404
476
|
|
405
|
-
|
477
|
+
type ThreadContextValue = {
|
478
|
+
useThread: UseBoundStore<StoreApi<ThreadState>>;
|
479
|
+
useComposer: UseBoundStore<StoreApi<ComposerState>>;
|
480
|
+
useViewport: UseBoundStore<StoreApi<ThreadViewportState>>;
|
481
|
+
};
|
482
|
+
declare const useThreadContext: () => ThreadContextValue;
|
406
483
|
|
407
|
-
|
484
|
+
type ComposerContextValue = {
|
485
|
+
useComposer: UseBoundStore<StoreApi<EditComposerState | ComposerState>>;
|
486
|
+
type: "edit" | "new";
|
487
|
+
};
|
488
|
+
declare const useComposerContext: () => ComposerContextValue;
|
489
|
+
|
490
|
+
type MessageContextValue = {
|
491
|
+
useMessage: UseBoundStore<StoreApi<MessageState>>;
|
492
|
+
useComposer: UseBoundStore<StoreApi<EditComposerState>>;
|
493
|
+
};
|
494
|
+
declare const useMessageContext: () => MessageContextValue;
|
495
|
+
|
496
|
+
type ContentPartContextValue = {
|
497
|
+
useContentPart: UseBoundStore<StoreApi<ContentPartState>>;
|
498
|
+
};
|
499
|
+
declare const useContentPartContext: () => ContentPartContextValue;
|
408
500
|
|
409
|
-
export { index$1 as ActionBarPrimitive, type AppendContentPart, type AppendMessage, index$2 as BranchPickerPrimitive, index$4 as ComposerPrimitive, index as ContentPartPrimitive,
|
501
|
+
export { index$1 as ActionBarPrimitive, type AppendContentPart, type AppendMessage, type AssistantContentPart, type AssistantMessage, AssistantRuntimeProvider, index$2 as BranchPickerPrimitive, index$4 as ComposerPrimitive, index as ContentPartPrimitive, index$3 as MessagePrimitive, type VercelRSCMessage as RSCMessage, type TextContentPart, type ThreadMessage, index$5 as ThreadPrimitive, type UserContentPart, type UserMessage, VercelAIAssistantProvider, type VercelAIAssistantProviderProps, type VercelRSCAdapter, VercelRSCAssistantProvider, type VercelRSCAssistantProviderProps, type VercelRSCMessage, getVercelAIMessage, getVercelRSCMessage, type ChatModelAdapter as unstable_ChatModelAdapter, type ChatModelRunOptions as unstable_ChatModelRunOptions, type ComposerContextValue as unstable_ComposerContextValue, type ComposerState as unstable_ComposerState, type ContentPartContextValue as unstable_ContentPartContextValue, type ContentPartState as unstable_ContentPartState, type EditComposerState as unstable_EditComposerState, type ImageContentPart as unstable_ImageContentPart, type MessageContextValue as unstable_MessageContextValue, type MessageState as unstable_MessageState, type ThreadContextValue as unstable_ThreadContextValue, type ThreadState as unstable_ThreadState, type ThreadViewportState as unstable_ThreadViewportState, type ToolCallContentPart as unstable_ToolCallContentPart, type UIContentPart as unstable_UIContentPart, VercelModelAdapter as unstable_VercelModelAdapter, useComposerContext as unstable_useComposerContext, useContentPartContext as unstable_useContentPartContext, useLocalRuntime as unstable_useLocalRuntime, useMessageContext as unstable_useMessageContext, useThreadContext as unstable_useThreadContext, useBeginMessageEdit, useCopyMessage, useGoToNextBranch, useGoToPreviousBranch, useReloadMessage, useVercelRSCRuntime, useVercelUseAssistantRuntime, useVercelUseChatRuntime };
|