@assistant-ui/react 0.0.18 → 0.0.20

Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.d.mts CHANGED
@@ -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";
@@ -153,6 +153,15 @@ type AppendMessage = {
153
153
  content: AppendContentPart[];
154
154
  };
155
155
  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
+ };
156
165
 
157
166
  type MessageProviderProps = PropsWithChildren<{
158
167
  message: ThreadMessage;
@@ -293,43 +302,34 @@ type VercelAIAssistantProviderProps = PropsWithChildren<{
293
302
  }>;
294
303
  declare const VercelAIAssistantProvider: FC<VercelAIAssistantProviderProps>;
295
304
 
305
+ type Unsubscribe = () => void;
306
+ type AssistantRuntime = Readonly<ThreadState> & {
307
+ subscribe: (callback: () => void) => Unsubscribe;
308
+ };
309
+
296
310
  type VercelRSCMessage = {
297
311
  id: string;
298
312
  role: "user" | "assistant";
299
313
  display: ReactNode;
300
314
  createdAt?: Date;
301
315
  };
302
- type VercelRSCAssistantProviderBaseProps<T> = PropsWithChildren<{
316
+ type RSCMessageConverter<T> = {
317
+ convertMessage: (message: T) => VercelRSCMessage;
318
+ };
319
+ type VercelRSCAdapterBase<T> = {
303
320
  messages: T[];
304
321
  append: (message: AppendMessage) => Promise<void>;
305
322
  edit?: (message: AppendMessage) => Promise<void>;
306
323
  reload?: (parentId: string | null) => Promise<void>;
307
324
  convertMessage?: (message: T) => VercelRSCMessage;
308
- }>;
309
- type RSCMessageConverter<T> = {
310
- convertMessage: (message: T) => VercelRSCMessage;
311
325
  };
312
- type VercelRSCAssistantProviderProps<T = VercelRSCMessage> = VercelRSCAssistantProviderBaseProps<T> & (T extends VercelRSCMessage ? object : RSCMessageConverter<T>);
313
- declare const VercelRSCAssistantProvider: <T extends WeakKey = VercelRSCMessage>({ children, convertMessage, messages: vercelMessages, append: appendCallback, edit, reload, }: VercelRSCAssistantProviderProps<T>) => react_jsx_runtime.JSX.Element;
326
+ type VercelRSCAdapter<T = VercelRSCMessage> = VercelRSCAdapterBase<T> & (T extends VercelRSCMessage ? object : RSCMessageConverter<T>);
314
327
 
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
- };
328
+ type VercelRSCAssistantProviderProps<T> = PropsWithChildren<VercelRSCAdapter<T>>;
329
+ declare const VercelRSCAssistantProvider: <T extends WeakKey = VercelRSCMessage>({ children, ...adapter }: VercelRSCAssistantProviderProps<T>) => react_jsx_runtime.JSX.Element;
330
330
 
331
331
  type AssistantProviderProps = {
332
- runtime: ThreadRuntime;
332
+ runtime: AssistantRuntime;
333
333
  };
334
334
  declare const AssistantProvider: FC<PropsWithChildren<AssistantProviderProps>>;
335
335
 
@@ -345,25 +345,21 @@ type ChatModelAdapter = {
345
345
  run: (options: ChatModelRunOptions) => Promise<ChatModelRunResult>;
346
346
  };
347
347
 
348
- declare class LocalRuntime implements ThreadRuntime {
348
+ declare class LocalRuntime implements AssistantRuntime {
349
349
  adapter: ChatModelAdapter;
350
- private _messageUpdateCallbacks;
351
- private _statusUpdateCallbacks;
350
+ private _subscriptions;
352
351
  private abortController;
353
352
  private repository;
353
+ get messages(): ThreadMessage[];
354
+ get isRunning(): boolean;
354
355
  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;
356
+ getBranches(messageId: string): string[];
357
+ switchToBranch(branchId: string): void;
358
+ append(message: AppendMessage): Promise<void>;
359
+ startRun(parentId: string | null): Promise<void>;
364
360
  cancelRun(): void;
365
- subscribeToMessageUpdates(callback: MessageUpdateCallback): Unsubscribe;
366
- subscribeToStatusUpdates(callback: StatusUpdateCallback): Unsubscribe;
361
+ private notifySubscribers;
362
+ subscribe(callback: () => void): Unsubscribe;
367
363
  }
368
364
 
369
365
  declare const useLocalRuntime: (adapter: ChatModelAdapter) => LocalRuntime;
@@ -379,10 +375,10 @@ declare class VercelModelAdapter implements ChatModelAdapter {
379
375
  declare const getVercelMessage: (message: ThreadMessage) => Message | undefined;
380
376
  declare const getVercelRSCMessage: <T>(message: ThreadMessage) => T | undefined;
381
377
 
382
- type MessageState = {
383
- message: ThreadMessage;
378
+ type MessageState = Readonly<{
379
+ message: Readonly<ThreadMessage>;
384
380
  parentId: string | null;
385
- branches: string[];
381
+ branches: readonly string[];
386
382
  isLast: boolean;
387
383
  inProgressIndicator: ReactNode | null;
388
384
  setInProgressIndicator: (value: ReactNode | null) => void;
@@ -390,7 +386,7 @@ type MessageState = {
390
386
  setIsCopied: (value: boolean) => void;
391
387
  isHovering: boolean;
392
388
  setIsHovering: (value: boolean) => void;
393
- };
389
+ }>;
394
390
  type MessageStore = {
395
391
  useMessage: UseBoundStore<StoreApi<MessageState>>;
396
392
  useComposer: UseBoundStore<StoreApi<MessageComposerState>>;
@@ -410,4 +406,4 @@ declare const useGoToNextBranch: () => (() => void) | null;
410
406
 
411
407
  declare const useGoToPreviousBranch: () => (() => void) | null;
412
408
 
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 };
409
+ 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, type VercelRSCMessage, 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
@@ -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";
@@ -153,6 +153,15 @@ type AppendMessage = {
153
153
  content: AppendContentPart[];
154
154
  };
155
155
  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
+ };
156
165
 
157
166
  type MessageProviderProps = PropsWithChildren<{
158
167
  message: ThreadMessage;
@@ -293,43 +302,34 @@ type VercelAIAssistantProviderProps = PropsWithChildren<{
293
302
  }>;
294
303
  declare const VercelAIAssistantProvider: FC<VercelAIAssistantProviderProps>;
295
304
 
305
+ type Unsubscribe = () => void;
306
+ type AssistantRuntime = Readonly<ThreadState> & {
307
+ subscribe: (callback: () => void) => Unsubscribe;
308
+ };
309
+
296
310
  type VercelRSCMessage = {
297
311
  id: string;
298
312
  role: "user" | "assistant";
299
313
  display: ReactNode;
300
314
  createdAt?: Date;
301
315
  };
302
- type VercelRSCAssistantProviderBaseProps<T> = PropsWithChildren<{
316
+ type RSCMessageConverter<T> = {
317
+ convertMessage: (message: T) => VercelRSCMessage;
318
+ };
319
+ type VercelRSCAdapterBase<T> = {
303
320
  messages: T[];
304
321
  append: (message: AppendMessage) => Promise<void>;
305
322
  edit?: (message: AppendMessage) => Promise<void>;
306
323
  reload?: (parentId: string | null) => Promise<void>;
307
324
  convertMessage?: (message: T) => VercelRSCMessage;
308
- }>;
309
- type RSCMessageConverter<T> = {
310
- convertMessage: (message: T) => VercelRSCMessage;
311
325
  };
312
- type VercelRSCAssistantProviderProps<T = VercelRSCMessage> = VercelRSCAssistantProviderBaseProps<T> & (T extends VercelRSCMessage ? object : RSCMessageConverter<T>);
313
- declare const VercelRSCAssistantProvider: <T extends WeakKey = VercelRSCMessage>({ children, convertMessage, messages: vercelMessages, append: appendCallback, edit, reload, }: VercelRSCAssistantProviderProps<T>) => react_jsx_runtime.JSX.Element;
326
+ type VercelRSCAdapter<T = VercelRSCMessage> = VercelRSCAdapterBase<T> & (T extends VercelRSCMessage ? object : RSCMessageConverter<T>);
314
327
 
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
- };
328
+ type VercelRSCAssistantProviderProps<T> = PropsWithChildren<VercelRSCAdapter<T>>;
329
+ declare const VercelRSCAssistantProvider: <T extends WeakKey = VercelRSCMessage>({ children, ...adapter }: VercelRSCAssistantProviderProps<T>) => react_jsx_runtime.JSX.Element;
330
330
 
331
331
  type AssistantProviderProps = {
332
- runtime: ThreadRuntime;
332
+ runtime: AssistantRuntime;
333
333
  };
334
334
  declare const AssistantProvider: FC<PropsWithChildren<AssistantProviderProps>>;
335
335
 
@@ -345,25 +345,21 @@ type ChatModelAdapter = {
345
345
  run: (options: ChatModelRunOptions) => Promise<ChatModelRunResult>;
346
346
  };
347
347
 
348
- declare class LocalRuntime implements ThreadRuntime {
348
+ declare class LocalRuntime implements AssistantRuntime {
349
349
  adapter: ChatModelAdapter;
350
- private _messageUpdateCallbacks;
351
- private _statusUpdateCallbacks;
350
+ private _subscriptions;
352
351
  private abortController;
353
352
  private repository;
353
+ get messages(): ThreadMessage[];
354
+ get isRunning(): boolean;
354
355
  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;
356
+ getBranches(messageId: string): string[];
357
+ switchToBranch(branchId: string): void;
358
+ append(message: AppendMessage): Promise<void>;
359
+ startRun(parentId: string | null): Promise<void>;
364
360
  cancelRun(): void;
365
- subscribeToMessageUpdates(callback: MessageUpdateCallback): Unsubscribe;
366
- subscribeToStatusUpdates(callback: StatusUpdateCallback): Unsubscribe;
361
+ private notifySubscribers;
362
+ subscribe(callback: () => void): Unsubscribe;
367
363
  }
368
364
 
369
365
  declare const useLocalRuntime: (adapter: ChatModelAdapter) => LocalRuntime;
@@ -379,10 +375,10 @@ declare class VercelModelAdapter implements ChatModelAdapter {
379
375
  declare const getVercelMessage: (message: ThreadMessage) => Message | undefined;
380
376
  declare const getVercelRSCMessage: <T>(message: ThreadMessage) => T | undefined;
381
377
 
382
- type MessageState = {
383
- message: ThreadMessage;
378
+ type MessageState = Readonly<{
379
+ message: Readonly<ThreadMessage>;
384
380
  parentId: string | null;
385
- branches: string[];
381
+ branches: readonly string[];
386
382
  isLast: boolean;
387
383
  inProgressIndicator: ReactNode | null;
388
384
  setInProgressIndicator: (value: ReactNode | null) => void;
@@ -390,7 +386,7 @@ type MessageState = {
390
386
  setIsCopied: (value: boolean) => void;
391
387
  isHovering: boolean;
392
388
  setIsHovering: (value: boolean) => void;
393
- };
389
+ }>;
394
390
  type MessageStore = {
395
391
  useMessage: UseBoundStore<StoreApi<MessageState>>;
396
392
  useComposer: UseBoundStore<StoreApi<MessageComposerState>>;
@@ -410,4 +406,4 @@ declare const useGoToNextBranch: () => (() => void) | null;
410
406
 
411
407
  declare const useGoToPreviousBranch: () => (() => void) | null;
412
408
 
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 };
409
+ 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, type VercelRSCMessage, 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 };