@assistant-ui/react 0.0.16 → 0.0.18

Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.d.mts CHANGED
@@ -3,6 +3,7 @@ import { FC, ReactNode, PropsWithChildren, ComponentType } from 'react';
3
3
  import { TextareaAutosizeProps } from 'react-textarea-autosize';
4
4
  import { UseChatHelpers, UseAssistantHelpers } from 'ai/react';
5
5
  import * as react_jsx_runtime from 'react/jsx-runtime';
6
+ import { LanguageModel, Message } from 'ai';
6
7
  import { UseBoundStore, StoreApi } from 'zustand';
7
8
 
8
9
  declare const ThreadRoot: react.ForwardRefExoticComponent<Pick<Omit<react.DetailedHTMLProps<react.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
@@ -132,7 +133,7 @@ type ToolCallContentPart = {
132
133
  result?: object;
133
134
  };
134
135
  type UserContentPart = TextContentPart | ImageContentPart | UIContentPart;
135
- type AssistantContentPart = TextContentPart | ImageContentPart | UIContentPart | ToolCallContentPart;
136
+ type AssistantContentPart = TextContentPart | UIContentPart | ToolCallContentPart;
136
137
  type AppendContentPart = TextContentPart | ImageContentPart;
137
138
  type BaseMessage = {
138
139
  id: string;
@@ -145,6 +146,7 @@ type UserMessage = BaseMessage & {
145
146
  type AssistantMessage = BaseMessage & {
146
147
  role: "assistant";
147
148
  content: AssistantContentPart[];
149
+ status: "in_progress" | "done" | "error";
148
150
  };
149
151
  type AppendMessage = {
150
152
  parentId: string | null;
@@ -199,14 +201,14 @@ type MessageContentProps = {
199
201
  };
200
202
  declare const MessageContent: FC<MessageContentProps>;
201
203
 
202
- declare const MessageLoading: react.ForwardRefExoticComponent<Pick<Omit<react.DetailedHTMLProps<react.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
204
+ declare const MessageInProgress: react.ForwardRefExoticComponent<Pick<Omit<react.DetailedHTMLProps<react.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
203
205
  ref?: ((instance: HTMLDivElement | null) => void) | react.RefObject<HTMLDivElement> | null | undefined;
204
206
  } & {
205
207
  asChild?: boolean;
206
208
  }, "key" | keyof react.HTMLAttributes<HTMLDivElement> | "asChild"> & react.RefAttributes<HTMLDivElement>>;
207
209
 
208
210
  declare namespace index$3 {
209
- export { MessageContent as Content, MessageIf as If, MessageLoading as Loading, MessageProvider as Provider, MessageRoot as Root };
211
+ export { MessageContent as Content, MessageIf as If, MessageInProgress as InProgress, MessageProvider as Provider, MessageRoot as Root };
210
212
  }
211
213
 
212
214
  declare const BranchPickerNext: react.ForwardRefExoticComponent<Pick<Omit<react.DetailedHTMLProps<react.ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "ref"> & {
@@ -274,14 +276,14 @@ declare namespace index$1 {
274
276
 
275
277
  type ContentPartProviderProps = PropsWithChildren<{
276
278
  part: ThreadMessage["content"][number];
277
- isLoading: boolean;
279
+ status: "in_progress" | "done" | "error";
278
280
  }>;
279
281
  declare const ContentPartProvider: FC<ContentPartProviderProps>;
280
282
 
281
- declare const ContentPartLoadingIndicator: FC;
283
+ declare const ContentPartInProgressIndicator: FC;
282
284
 
283
285
  declare namespace index {
284
- export { ContentPartLoadingIndicator as LoadingIndicator, ContentPartProvider as Provider };
286
+ export { ContentPartInProgressIndicator as InProgressIndicator, ContentPartProvider as Provider };
285
287
  }
286
288
 
287
289
  type VercelAIAssistantProviderProps = PropsWithChildren<{
@@ -310,13 +312,80 @@ type RSCMessageConverter<T> = {
310
312
  type VercelRSCAssistantProviderProps<T = VercelRSCMessage> = VercelRSCAssistantProviderBaseProps<T> & (T extends VercelRSCMessage ? object : RSCMessageConverter<T>);
311
313
  declare const VercelRSCAssistantProvider: <T extends WeakKey = VercelRSCMessage>({ children, convertMessage, messages: vercelMessages, append: appendCallback, edit, reload, }: VercelRSCAssistantProviderProps<T>) => react_jsx_runtime.JSX.Element;
312
314
 
315
+ type MessageUpdateCallback = (parentId: string | null, message: ThreadMessage) => void;
316
+ type StatusUpdateCallback = (isRunning: boolean) => void;
317
+ type Unsubscribe = () => void;
318
+ type ThreadRuntime = {
319
+ append(message: AppendMessage): Promise<{
320
+ parentId: string;
321
+ id: string;
322
+ }>;
323
+ startRun(parentId: string | null): Promise<{
324
+ id: string;
325
+ }>;
326
+ cancelRun(): void;
327
+ subscribeToMessageUpdates(callback: MessageUpdateCallback): Unsubscribe;
328
+ subscribeToStatusUpdates(callback: StatusUpdateCallback): Unsubscribe;
329
+ };
330
+
331
+ type AssistantProviderProps = {
332
+ runtime: ThreadRuntime;
333
+ };
334
+ declare const AssistantProvider: FC<PropsWithChildren<AssistantProviderProps>>;
335
+
336
+ type ChatModelRunResult = {
337
+ content: AssistantContentPart[];
338
+ };
339
+ type ChatModelRunOptions = {
340
+ messages: ThreadMessage[];
341
+ abortSignal: AbortSignal;
342
+ onUpdate: (result: ChatModelRunResult) => void;
343
+ };
344
+ type ChatModelAdapter = {
345
+ run: (options: ChatModelRunOptions) => Promise<ChatModelRunResult>;
346
+ };
347
+
348
+ declare class LocalRuntime implements ThreadRuntime {
349
+ adapter: ChatModelAdapter;
350
+ private _messageUpdateCallbacks;
351
+ private _statusUpdateCallbacks;
352
+ private abortController;
353
+ private repository;
354
+ constructor(adapter: ChatModelAdapter);
355
+ append(message: AppendMessage): Promise<{
356
+ parentId: string;
357
+ id: string;
358
+ }>;
359
+ startRun(parentId: string | null): Promise<{
360
+ id: string;
361
+ }>;
362
+ private addOrUpdateMessage;
363
+ private run;
364
+ cancelRun(): void;
365
+ subscribeToMessageUpdates(callback: MessageUpdateCallback): Unsubscribe;
366
+ subscribeToStatusUpdates(callback: StatusUpdateCallback): Unsubscribe;
367
+ }
368
+
369
+ declare const useLocalRuntime: (adapter: ChatModelAdapter) => LocalRuntime;
370
+
371
+ declare class VercelModelAdapter implements ChatModelAdapter {
372
+ private readonly model;
373
+ constructor(model: LanguageModel);
374
+ run({ messages, abortSignal, onUpdate }: ChatModelRunOptions): Promise<{
375
+ content: AssistantContentPart[];
376
+ }>;
377
+ }
378
+
379
+ declare const getVercelMessage: (message: ThreadMessage) => Message | undefined;
380
+ declare const getVercelRSCMessage: <T>(message: ThreadMessage) => T | undefined;
381
+
313
382
  type MessageState = {
314
383
  message: ThreadMessage;
315
384
  parentId: string | null;
316
385
  branches: string[];
317
386
  isLast: boolean;
318
- loadingIndicator: ReactNode | null;
319
- setLoadingIndicator: (value: ReactNode | null) => void;
387
+ inProgressIndicator: ReactNode | null;
388
+ setInProgressIndicator: (value: ReactNode | null) => void;
320
389
  isCopied: boolean;
321
390
  setIsCopied: (value: boolean) => void;
322
391
  isHovering: boolean;
@@ -341,4 +410,4 @@ declare const useGoToNextBranch: () => (() => void) | null;
341
410
 
342
411
  declare const useGoToPreviousBranch: () => (() => void) | null;
343
412
 
344
- export { index$1 as ActionBarPrimitive, type AppendContentPart, type AppendMessage, index$2 as BranchPickerPrimitive, index$4 as ComposerPrimitive, index as ContentPartPrimitive, type ImageContentPart, index$3 as MessagePrimitive, type VercelRSCMessage as RSCMessage, type TextContentPart, index$5 as ThreadPrimitive, VercelAIAssistantProvider, type VercelAIAssistantProviderProps, VercelRSCAssistantProvider, type VercelRSCAssistantProviderProps, useMessageContext as unstable_useMessageContext, useBeginMessageEdit, useCopyMessage, useGoToNextBranch, useGoToPreviousBranch, useReloadMessage };
413
+ export { index$1 as ActionBarPrimitive, type AppendContentPart, type AppendMessage, index$2 as BranchPickerPrimitive, index$4 as ComposerPrimitive, index as ContentPartPrimitive, type ImageContentPart, index$3 as MessagePrimitive, type VercelRSCMessage as RSCMessage, type TextContentPart, index$5 as ThreadPrimitive, VercelAIAssistantProvider, type VercelAIAssistantProviderProps, VercelRSCAssistantProvider, type VercelRSCAssistantProviderProps, AssistantProvider as unstable_AssistantProvider, type ChatModelAdapter as unstable_ChatModelAdapter, type ChatModelRunOptions as unstable_ChatModelRunOptions, VercelModelAdapter as unstable_VercelModelAdapter, getVercelMessage as unstable_getVercelMessage, getVercelRSCMessage as unstable_getVercelRSCMessage, useLocalRuntime as unstable_useLocalRuntime, useMessageContext as unstable_useMessageContext, useBeginMessageEdit, useCopyMessage, useGoToNextBranch, useGoToPreviousBranch, useReloadMessage };
package/dist/index.d.ts CHANGED
@@ -3,6 +3,7 @@ import { FC, ReactNode, PropsWithChildren, ComponentType } from 'react';
3
3
  import { TextareaAutosizeProps } from 'react-textarea-autosize';
4
4
  import { UseChatHelpers, UseAssistantHelpers } from 'ai/react';
5
5
  import * as react_jsx_runtime from 'react/jsx-runtime';
6
+ import { LanguageModel, Message } from 'ai';
6
7
  import { UseBoundStore, StoreApi } from 'zustand';
7
8
 
8
9
  declare const ThreadRoot: react.ForwardRefExoticComponent<Pick<Omit<react.DetailedHTMLProps<react.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
@@ -132,7 +133,7 @@ type ToolCallContentPart = {
132
133
  result?: object;
133
134
  };
134
135
  type UserContentPart = TextContentPart | ImageContentPart | UIContentPart;
135
- type AssistantContentPart = TextContentPart | ImageContentPart | UIContentPart | ToolCallContentPart;
136
+ type AssistantContentPart = TextContentPart | UIContentPart | ToolCallContentPart;
136
137
  type AppendContentPart = TextContentPart | ImageContentPart;
137
138
  type BaseMessage = {
138
139
  id: string;
@@ -145,6 +146,7 @@ type UserMessage = BaseMessage & {
145
146
  type AssistantMessage = BaseMessage & {
146
147
  role: "assistant";
147
148
  content: AssistantContentPart[];
149
+ status: "in_progress" | "done" | "error";
148
150
  };
149
151
  type AppendMessage = {
150
152
  parentId: string | null;
@@ -199,14 +201,14 @@ type MessageContentProps = {
199
201
  };
200
202
  declare const MessageContent: FC<MessageContentProps>;
201
203
 
202
- declare const MessageLoading: react.ForwardRefExoticComponent<Pick<Omit<react.DetailedHTMLProps<react.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
204
+ declare const MessageInProgress: react.ForwardRefExoticComponent<Pick<Omit<react.DetailedHTMLProps<react.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
203
205
  ref?: ((instance: HTMLDivElement | null) => void) | react.RefObject<HTMLDivElement> | null | undefined;
204
206
  } & {
205
207
  asChild?: boolean;
206
208
  }, "key" | keyof react.HTMLAttributes<HTMLDivElement> | "asChild"> & react.RefAttributes<HTMLDivElement>>;
207
209
 
208
210
  declare namespace index$3 {
209
- export { MessageContent as Content, MessageIf as If, MessageLoading as Loading, MessageProvider as Provider, MessageRoot as Root };
211
+ export { MessageContent as Content, MessageIf as If, MessageInProgress as InProgress, MessageProvider as Provider, MessageRoot as Root };
210
212
  }
211
213
 
212
214
  declare const BranchPickerNext: react.ForwardRefExoticComponent<Pick<Omit<react.DetailedHTMLProps<react.ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "ref"> & {
@@ -274,14 +276,14 @@ declare namespace index$1 {
274
276
 
275
277
  type ContentPartProviderProps = PropsWithChildren<{
276
278
  part: ThreadMessage["content"][number];
277
- isLoading: boolean;
279
+ status: "in_progress" | "done" | "error";
278
280
  }>;
279
281
  declare const ContentPartProvider: FC<ContentPartProviderProps>;
280
282
 
281
- declare const ContentPartLoadingIndicator: FC;
283
+ declare const ContentPartInProgressIndicator: FC;
282
284
 
283
285
  declare namespace index {
284
- export { ContentPartLoadingIndicator as LoadingIndicator, ContentPartProvider as Provider };
286
+ export { ContentPartInProgressIndicator as InProgressIndicator, ContentPartProvider as Provider };
285
287
  }
286
288
 
287
289
  type VercelAIAssistantProviderProps = PropsWithChildren<{
@@ -310,13 +312,80 @@ type RSCMessageConverter<T> = {
310
312
  type VercelRSCAssistantProviderProps<T = VercelRSCMessage> = VercelRSCAssistantProviderBaseProps<T> & (T extends VercelRSCMessage ? object : RSCMessageConverter<T>);
311
313
  declare const VercelRSCAssistantProvider: <T extends WeakKey = VercelRSCMessage>({ children, convertMessage, messages: vercelMessages, append: appendCallback, edit, reload, }: VercelRSCAssistantProviderProps<T>) => react_jsx_runtime.JSX.Element;
312
314
 
315
+ type MessageUpdateCallback = (parentId: string | null, message: ThreadMessage) => void;
316
+ type StatusUpdateCallback = (isRunning: boolean) => void;
317
+ type Unsubscribe = () => void;
318
+ type ThreadRuntime = {
319
+ append(message: AppendMessage): Promise<{
320
+ parentId: string;
321
+ id: string;
322
+ }>;
323
+ startRun(parentId: string | null): Promise<{
324
+ id: string;
325
+ }>;
326
+ cancelRun(): void;
327
+ subscribeToMessageUpdates(callback: MessageUpdateCallback): Unsubscribe;
328
+ subscribeToStatusUpdates(callback: StatusUpdateCallback): Unsubscribe;
329
+ };
330
+
331
+ type AssistantProviderProps = {
332
+ runtime: ThreadRuntime;
333
+ };
334
+ declare const AssistantProvider: FC<PropsWithChildren<AssistantProviderProps>>;
335
+
336
+ type ChatModelRunResult = {
337
+ content: AssistantContentPart[];
338
+ };
339
+ type ChatModelRunOptions = {
340
+ messages: ThreadMessage[];
341
+ abortSignal: AbortSignal;
342
+ onUpdate: (result: ChatModelRunResult) => void;
343
+ };
344
+ type ChatModelAdapter = {
345
+ run: (options: ChatModelRunOptions) => Promise<ChatModelRunResult>;
346
+ };
347
+
348
+ declare class LocalRuntime implements ThreadRuntime {
349
+ adapter: ChatModelAdapter;
350
+ private _messageUpdateCallbacks;
351
+ private _statusUpdateCallbacks;
352
+ private abortController;
353
+ private repository;
354
+ constructor(adapter: ChatModelAdapter);
355
+ append(message: AppendMessage): Promise<{
356
+ parentId: string;
357
+ id: string;
358
+ }>;
359
+ startRun(parentId: string | null): Promise<{
360
+ id: string;
361
+ }>;
362
+ private addOrUpdateMessage;
363
+ private run;
364
+ cancelRun(): void;
365
+ subscribeToMessageUpdates(callback: MessageUpdateCallback): Unsubscribe;
366
+ subscribeToStatusUpdates(callback: StatusUpdateCallback): Unsubscribe;
367
+ }
368
+
369
+ declare const useLocalRuntime: (adapter: ChatModelAdapter) => LocalRuntime;
370
+
371
+ declare class VercelModelAdapter implements ChatModelAdapter {
372
+ private readonly model;
373
+ constructor(model: LanguageModel);
374
+ run({ messages, abortSignal, onUpdate }: ChatModelRunOptions): Promise<{
375
+ content: AssistantContentPart[];
376
+ }>;
377
+ }
378
+
379
+ declare const getVercelMessage: (message: ThreadMessage) => Message | undefined;
380
+ declare const getVercelRSCMessage: <T>(message: ThreadMessage) => T | undefined;
381
+
313
382
  type MessageState = {
314
383
  message: ThreadMessage;
315
384
  parentId: string | null;
316
385
  branches: string[];
317
386
  isLast: boolean;
318
- loadingIndicator: ReactNode | null;
319
- setLoadingIndicator: (value: ReactNode | null) => void;
387
+ inProgressIndicator: ReactNode | null;
388
+ setInProgressIndicator: (value: ReactNode | null) => void;
320
389
  isCopied: boolean;
321
390
  setIsCopied: (value: boolean) => void;
322
391
  isHovering: boolean;
@@ -341,4 +410,4 @@ declare const useGoToNextBranch: () => (() => void) | null;
341
410
 
342
411
  declare const useGoToPreviousBranch: () => (() => void) | null;
343
412
 
344
- export { index$1 as ActionBarPrimitive, type AppendContentPart, type AppendMessage, index$2 as BranchPickerPrimitive, index$4 as ComposerPrimitive, index as ContentPartPrimitive, type ImageContentPart, index$3 as MessagePrimitive, type VercelRSCMessage as RSCMessage, type TextContentPart, index$5 as ThreadPrimitive, VercelAIAssistantProvider, type VercelAIAssistantProviderProps, VercelRSCAssistantProvider, type VercelRSCAssistantProviderProps, useMessageContext as unstable_useMessageContext, useBeginMessageEdit, useCopyMessage, useGoToNextBranch, useGoToPreviousBranch, useReloadMessage };
413
+ export { index$1 as ActionBarPrimitive, type AppendContentPart, type AppendMessage, index$2 as BranchPickerPrimitive, index$4 as ComposerPrimitive, index as ContentPartPrimitive, type ImageContentPart, index$3 as MessagePrimitive, type VercelRSCMessage as RSCMessage, type TextContentPart, index$5 as ThreadPrimitive, VercelAIAssistantProvider, type VercelAIAssistantProviderProps, VercelRSCAssistantProvider, type VercelRSCAssistantProviderProps, AssistantProvider as unstable_AssistantProvider, type ChatModelAdapter as unstable_ChatModelAdapter, type ChatModelRunOptions as unstable_ChatModelRunOptions, VercelModelAdapter as unstable_VercelModelAdapter, getVercelMessage as unstable_getVercelMessage, getVercelRSCMessage as unstable_getVercelRSCMessage, useLocalRuntime as unstable_useLocalRuntime, useMessageContext as unstable_useMessageContext, useBeginMessageEdit, useCopyMessage, useGoToNextBranch, useGoToPreviousBranch, useReloadMessage };