@assistant-ui/react 0.0.17 → 0.0.19

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.mts CHANGED
@@ -3,7 +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 { Message } from 'ai';
6
+ import { LanguageModel, Message } from 'ai';
7
7
  import { UseBoundStore, StoreApi } from 'zustand';
8
8
 
9
9
  declare const ThreadRoot: react.ForwardRefExoticComponent<Pick<Omit<react.DetailedHTMLProps<react.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
@@ -103,16 +103,16 @@ declare namespace index$4 {
103
103
  export { ComposerCancel as Cancel, ComposerIf as If, ComposerInput as Input, ComposerRoot as Root, ComposerSend as Send };
104
104
  }
105
105
 
106
- type BaseComposerState = {
106
+ type BaseComposerState = Readonly<{
107
107
  value: string;
108
108
  setValue: (value: string) => void;
109
- };
110
- type MessageComposerState = BaseComposerState & {
109
+ }>;
110
+ type MessageComposerState = BaseComposerState & Readonly<{
111
111
  isEditing: boolean;
112
112
  edit: () => void;
113
113
  send: () => void;
114
114
  cancel: () => boolean;
115
- };
115
+ }>;
116
116
 
117
117
  type TextContentPart = {
118
118
  type: "text";
@@ -133,7 +133,7 @@ type ToolCallContentPart = {
133
133
  result?: object;
134
134
  };
135
135
  type UserContentPart = TextContentPart | ImageContentPart | UIContentPart;
136
- type AssistantContentPart = TextContentPart | ImageContentPart | UIContentPart | ToolCallContentPart;
136
+ type AssistantContentPart = TextContentPart | UIContentPart | ToolCallContentPart;
137
137
  type AppendContentPart = TextContentPart | ImageContentPart;
138
138
  type BaseMessage = {
139
139
  id: string;
@@ -312,13 +312,77 @@ type RSCMessageConverter<T> = {
312
312
  type VercelRSCAssistantProviderProps<T = VercelRSCMessage> = VercelRSCAssistantProviderBaseProps<T> & (T extends VercelRSCMessage ? object : RSCMessageConverter<T>);
313
313
  declare const VercelRSCAssistantProvider: <T extends WeakKey = VercelRSCMessage>({ children, convertMessage, messages: vercelMessages, append: appendCallback, edit, reload, }: VercelRSCAssistantProviderProps<T>) => react_jsx_runtime.JSX.Element;
314
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
+
315
379
  declare const getVercelMessage: (message: ThreadMessage) => Message | undefined;
316
380
  declare const getVercelRSCMessage: <T>(message: ThreadMessage) => T | undefined;
317
381
 
318
- type MessageState = {
319
- message: ThreadMessage;
382
+ type MessageState = Readonly<{
383
+ message: Readonly<ThreadMessage>;
320
384
  parentId: string | null;
321
- branches: string[];
385
+ branches: readonly string[];
322
386
  isLast: boolean;
323
387
  inProgressIndicator: ReactNode | null;
324
388
  setInProgressIndicator: (value: ReactNode | null) => void;
@@ -326,7 +390,7 @@ type MessageState = {
326
390
  setIsCopied: (value: boolean) => void;
327
391
  isHovering: boolean;
328
392
  setIsHovering: (value: boolean) => void;
329
- };
393
+ }>;
330
394
  type MessageStore = {
331
395
  useMessage: UseBoundStore<StoreApi<MessageState>>;
332
396
  useComposer: UseBoundStore<StoreApi<MessageComposerState>>;
@@ -346,4 +410,4 @@ declare const useGoToNextBranch: () => (() => void) | null;
346
410
 
347
411
  declare const useGoToPreviousBranch: () => (() => void) | null;
348
412
 
349
- 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, getVercelMessage as unstable_getVercelMessage, getVercelRSCMessage as unstable_getVercelRSCMessage, 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,7 +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 { Message } from 'ai';
6
+ import { LanguageModel, Message } from 'ai';
7
7
  import { UseBoundStore, StoreApi } from 'zustand';
8
8
 
9
9
  declare const ThreadRoot: react.ForwardRefExoticComponent<Pick<Omit<react.DetailedHTMLProps<react.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
@@ -103,16 +103,16 @@ declare namespace index$4 {
103
103
  export { ComposerCancel as Cancel, ComposerIf as If, ComposerInput as Input, ComposerRoot as Root, ComposerSend as Send };
104
104
  }
105
105
 
106
- type BaseComposerState = {
106
+ type BaseComposerState = Readonly<{
107
107
  value: string;
108
108
  setValue: (value: string) => void;
109
- };
110
- type MessageComposerState = BaseComposerState & {
109
+ }>;
110
+ type MessageComposerState = BaseComposerState & Readonly<{
111
111
  isEditing: boolean;
112
112
  edit: () => void;
113
113
  send: () => void;
114
114
  cancel: () => boolean;
115
- };
115
+ }>;
116
116
 
117
117
  type TextContentPart = {
118
118
  type: "text";
@@ -133,7 +133,7 @@ type ToolCallContentPart = {
133
133
  result?: object;
134
134
  };
135
135
  type UserContentPart = TextContentPart | ImageContentPart | UIContentPart;
136
- type AssistantContentPart = TextContentPart | ImageContentPart | UIContentPart | ToolCallContentPart;
136
+ type AssistantContentPart = TextContentPart | UIContentPart | ToolCallContentPart;
137
137
  type AppendContentPart = TextContentPart | ImageContentPart;
138
138
  type BaseMessage = {
139
139
  id: string;
@@ -312,13 +312,77 @@ type RSCMessageConverter<T> = {
312
312
  type VercelRSCAssistantProviderProps<T = VercelRSCMessage> = VercelRSCAssistantProviderBaseProps<T> & (T extends VercelRSCMessage ? object : RSCMessageConverter<T>);
313
313
  declare const VercelRSCAssistantProvider: <T extends WeakKey = VercelRSCMessage>({ children, convertMessage, messages: vercelMessages, append: appendCallback, edit, reload, }: VercelRSCAssistantProviderProps<T>) => react_jsx_runtime.JSX.Element;
314
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
+
315
379
  declare const getVercelMessage: (message: ThreadMessage) => Message | undefined;
316
380
  declare const getVercelRSCMessage: <T>(message: ThreadMessage) => T | undefined;
317
381
 
318
- type MessageState = {
319
- message: ThreadMessage;
382
+ type MessageState = Readonly<{
383
+ message: Readonly<ThreadMessage>;
320
384
  parentId: string | null;
321
- branches: string[];
385
+ branches: readonly string[];
322
386
  isLast: boolean;
323
387
  inProgressIndicator: ReactNode | null;
324
388
  setInProgressIndicator: (value: ReactNode | null) => void;
@@ -326,7 +390,7 @@ type MessageState = {
326
390
  setIsCopied: (value: boolean) => void;
327
391
  isHovering: boolean;
328
392
  setIsHovering: (value: boolean) => void;
329
- };
393
+ }>;
330
394
  type MessageStore = {
331
395
  useMessage: UseBoundStore<StoreApi<MessageState>>;
332
396
  useComposer: UseBoundStore<StoreApi<MessageComposerState>>;
@@ -346,4 +410,4 @@ declare const useGoToNextBranch: () => (() => void) | null;
346
410
 
347
411
  declare const useGoToPreviousBranch: () => (() => void) | null;
348
412
 
349
- 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, getVercelMessage as unstable_getVercelMessage, getVercelRSCMessage as unstable_getVercelRSCMessage, 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 };