@assistant-ui/react 0.5.22 → 0.5.24

Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.d.mts CHANGED
@@ -77,6 +77,33 @@ type ToolCallContentPartProps<TArgs extends Record<string, unknown> = any, TResu
77
77
  };
78
78
  type ToolCallContentPartComponent<TArgs extends Record<string, unknown> = any, TResult = any> = ComponentType<ToolCallContentPartProps<TArgs, TResult>>;
79
79
 
80
+ interface ExportedMessageRepository {
81
+ headId?: string | null;
82
+ messages: Array<{
83
+ message: ThreadMessage;
84
+ parentId: string | null;
85
+ }>;
86
+ }
87
+ declare class MessageRepository {
88
+ private messages;
89
+ private head;
90
+ private root;
91
+ private performOp;
92
+ getMessages(): ThreadMessage[];
93
+ addOrUpdateMessage(parentId: string | null, message: ThreadMessage): void;
94
+ getMessage(messageId: string): {
95
+ parentId: string | null;
96
+ message: ThreadMessage;
97
+ };
98
+ appendOptimisticMessage(parentId: string | null, message: CoreMessage): string;
99
+ deleteMessage(messageId: string, replacementId?: string | null | undefined): void;
100
+ getBranches(messageId: string): string[];
101
+ switchToBranch(messageId: string): void;
102
+ resetHead(messageId: string | null): void;
103
+ export(): ExportedMessageRepository;
104
+ import({ headId, messages }: ExportedMessageRepository): void;
105
+ }
106
+
80
107
  type LocalRuntimeOptions = {
81
108
  initialMessages?: readonly CoreMessage[] | undefined;
82
109
  maxToolRoundtrips?: number;
@@ -109,6 +136,8 @@ declare class LocalThreadRuntime implements ThreadRuntime {
109
136
  private notifySubscribers;
110
137
  subscribe(callback: () => void): Unsubscribe;
111
138
  addToolResult({ messageId, toolCallId, result }: AddToolResultOptions): void;
139
+ export(): ExportedMessageRepository;
140
+ import(data: ExportedMessageRepository): void;
112
141
  }
113
142
 
114
143
  declare class LocalRuntime extends BaseAssistantRuntime<LocalThreadRuntime> {
@@ -439,24 +468,6 @@ declare class ProxyConfigProvider implements ModelConfigProvider {
439
468
  registerModelConfigProvider(provider: ModelConfigProvider): () => void;
440
469
  }
441
470
 
442
- declare class MessageRepository {
443
- private messages;
444
- private head;
445
- private root;
446
- private performOp;
447
- getMessages(): ThreadMessage[];
448
- addOrUpdateMessage(parentId: string | null, message: ThreadMessage): void;
449
- getMessage(messageId: string): {
450
- parentId: string | null;
451
- message: ThreadMessage;
452
- };
453
- appendOptimisticMessage(parentId: string | null, message: CoreMessage): string;
454
- deleteMessage(messageId: string, replacementId?: string | null | undefined): void;
455
- getBranches(messageId: string): string[];
456
- switchToBranch(messageId: string): void;
457
- resetHead(messageId: string | null): void;
458
- }
459
-
460
471
  type TextContentPartState = Readonly<{
461
472
  status: ContentPartStatus;
462
473
  part: TextContentPart;
@@ -521,12 +532,16 @@ declare namespace internal {
521
532
  export { internal_BaseAssistantRuntime as BaseAssistantRuntime, internal_MessageRepository as MessageRepository, internal_ProxyConfigProvider as ProxyConfigProvider, internal_TooltipIconButton as TooltipIconButton, internal_generateId as generateId, internal_useSmooth as useSmooth, internal_useSmoothStatus as useSmoothStatus, internal_withSmoothContextProvider as withSmoothContextProvider };
522
533
  }
523
534
 
535
+ type ConverterCallback<TIn> = (cache: ThreadMessage | undefined, message: TIn, idx: number) => ThreadMessage;
536
+ declare class ThreadMessageConverter {
537
+ private readonly cache;
538
+ convertMessages<TIn extends WeakKey>(messages: TIn[], converter: ConverterCallback<TIn>, keyMapper?: (m: TIn) => WeakKey): ThreadMessage[];
539
+ }
540
+
524
541
  declare class ExternalStoreThreadRuntime implements ReactThreadRuntime {
525
- store: ExternalStoreAdapter<any>;
526
542
  private _subscriptions;
527
543
  private repository;
528
544
  private assistantOptimisticId;
529
- private useStore;
530
545
  get capabilities(): {
531
546
  switchToBranch: boolean;
532
547
  edit: boolean;
@@ -537,7 +552,10 @@ declare class ExternalStoreThreadRuntime implements ReactThreadRuntime {
537
552
  messages: ThreadMessage[];
538
553
  isDisabled: boolean;
539
554
  isRunning: boolean;
555
+ converter: ThreadMessageConverter;
556
+ private _store;
540
557
  constructor(store: ExternalStoreAdapter<any>);
558
+ set store(store: ExternalStoreAdapter<any>);
541
559
  getBranches(messageId: string): string[];
542
560
  switchToBranch(branchId: string): void;
543
561
  append(message: AppendMessage): Promise<void>;
@@ -545,9 +563,6 @@ declare class ExternalStoreThreadRuntime implements ReactThreadRuntime {
545
563
  cancelRun(): void;
546
564
  subscribe(callback: () => void): Unsubscribe;
547
565
  private updateMessages;
548
- onStoreUpdated(): void;
549
- private updateData;
550
- unstable_synchronizer: () => null;
551
566
  addToolResult(options: AddToolResultOptions): void;
552
567
  }
553
568
 
@@ -555,13 +570,12 @@ declare class ExternalStoreRuntime extends BaseAssistantRuntime<ExternalStoreThr
555
570
  private readonly _proxyConfigProvider;
556
571
  constructor(store: ExternalStoreAdapter<any>);
557
572
  set store(store: ExternalStoreAdapter<any>);
558
- onStoreUpdated(): void;
559
573
  getModelConfig(): ModelConfig;
560
574
  registerModelConfigProvider(provider: ModelConfigProvider): () => void;
561
575
  switchToThread(threadId: string | null): void | Promise<void>;
562
576
  }
563
577
 
564
- declare const useExternalStoreRuntime: (store: ExternalStoreAdapter<any>) => ExternalStoreRuntime;
578
+ declare const useExternalStoreRuntime: <T>(store: ExternalStoreAdapter<T>) => ExternalStoreRuntime;
565
579
 
566
580
  declare const getExternalStoreMessage: <T>(message: ThreadMessage) => T | undefined;
567
581
 
package/dist/index.d.ts CHANGED
@@ -77,6 +77,33 @@ type ToolCallContentPartProps<TArgs extends Record<string, unknown> = any, TResu
77
77
  };
78
78
  type ToolCallContentPartComponent<TArgs extends Record<string, unknown> = any, TResult = any> = ComponentType<ToolCallContentPartProps<TArgs, TResult>>;
79
79
 
80
+ interface ExportedMessageRepository {
81
+ headId?: string | null;
82
+ messages: Array<{
83
+ message: ThreadMessage;
84
+ parentId: string | null;
85
+ }>;
86
+ }
87
+ declare class MessageRepository {
88
+ private messages;
89
+ private head;
90
+ private root;
91
+ private performOp;
92
+ getMessages(): ThreadMessage[];
93
+ addOrUpdateMessage(parentId: string | null, message: ThreadMessage): void;
94
+ getMessage(messageId: string): {
95
+ parentId: string | null;
96
+ message: ThreadMessage;
97
+ };
98
+ appendOptimisticMessage(parentId: string | null, message: CoreMessage): string;
99
+ deleteMessage(messageId: string, replacementId?: string | null | undefined): void;
100
+ getBranches(messageId: string): string[];
101
+ switchToBranch(messageId: string): void;
102
+ resetHead(messageId: string | null): void;
103
+ export(): ExportedMessageRepository;
104
+ import({ headId, messages }: ExportedMessageRepository): void;
105
+ }
106
+
80
107
  type LocalRuntimeOptions = {
81
108
  initialMessages?: readonly CoreMessage[] | undefined;
82
109
  maxToolRoundtrips?: number;
@@ -109,6 +136,8 @@ declare class LocalThreadRuntime implements ThreadRuntime {
109
136
  private notifySubscribers;
110
137
  subscribe(callback: () => void): Unsubscribe;
111
138
  addToolResult({ messageId, toolCallId, result }: AddToolResultOptions): void;
139
+ export(): ExportedMessageRepository;
140
+ import(data: ExportedMessageRepository): void;
112
141
  }
113
142
 
114
143
  declare class LocalRuntime extends BaseAssistantRuntime<LocalThreadRuntime> {
@@ -439,24 +468,6 @@ declare class ProxyConfigProvider implements ModelConfigProvider {
439
468
  registerModelConfigProvider(provider: ModelConfigProvider): () => void;
440
469
  }
441
470
 
442
- declare class MessageRepository {
443
- private messages;
444
- private head;
445
- private root;
446
- private performOp;
447
- getMessages(): ThreadMessage[];
448
- addOrUpdateMessage(parentId: string | null, message: ThreadMessage): void;
449
- getMessage(messageId: string): {
450
- parentId: string | null;
451
- message: ThreadMessage;
452
- };
453
- appendOptimisticMessage(parentId: string | null, message: CoreMessage): string;
454
- deleteMessage(messageId: string, replacementId?: string | null | undefined): void;
455
- getBranches(messageId: string): string[];
456
- switchToBranch(messageId: string): void;
457
- resetHead(messageId: string | null): void;
458
- }
459
-
460
471
  type TextContentPartState = Readonly<{
461
472
  status: ContentPartStatus;
462
473
  part: TextContentPart;
@@ -521,12 +532,16 @@ declare namespace internal {
521
532
  export { internal_BaseAssistantRuntime as BaseAssistantRuntime, internal_MessageRepository as MessageRepository, internal_ProxyConfigProvider as ProxyConfigProvider, internal_TooltipIconButton as TooltipIconButton, internal_generateId as generateId, internal_useSmooth as useSmooth, internal_useSmoothStatus as useSmoothStatus, internal_withSmoothContextProvider as withSmoothContextProvider };
522
533
  }
523
534
 
535
+ type ConverterCallback<TIn> = (cache: ThreadMessage | undefined, message: TIn, idx: number) => ThreadMessage;
536
+ declare class ThreadMessageConverter {
537
+ private readonly cache;
538
+ convertMessages<TIn extends WeakKey>(messages: TIn[], converter: ConverterCallback<TIn>, keyMapper?: (m: TIn) => WeakKey): ThreadMessage[];
539
+ }
540
+
524
541
  declare class ExternalStoreThreadRuntime implements ReactThreadRuntime {
525
- store: ExternalStoreAdapter<any>;
526
542
  private _subscriptions;
527
543
  private repository;
528
544
  private assistantOptimisticId;
529
- private useStore;
530
545
  get capabilities(): {
531
546
  switchToBranch: boolean;
532
547
  edit: boolean;
@@ -537,7 +552,10 @@ declare class ExternalStoreThreadRuntime implements ReactThreadRuntime {
537
552
  messages: ThreadMessage[];
538
553
  isDisabled: boolean;
539
554
  isRunning: boolean;
555
+ converter: ThreadMessageConverter;
556
+ private _store;
540
557
  constructor(store: ExternalStoreAdapter<any>);
558
+ set store(store: ExternalStoreAdapter<any>);
541
559
  getBranches(messageId: string): string[];
542
560
  switchToBranch(branchId: string): void;
543
561
  append(message: AppendMessage): Promise<void>;
@@ -545,9 +563,6 @@ declare class ExternalStoreThreadRuntime implements ReactThreadRuntime {
545
563
  cancelRun(): void;
546
564
  subscribe(callback: () => void): Unsubscribe;
547
565
  private updateMessages;
548
- onStoreUpdated(): void;
549
- private updateData;
550
- unstable_synchronizer: () => null;
551
566
  addToolResult(options: AddToolResultOptions): void;
552
567
  }
553
568
 
@@ -555,13 +570,12 @@ declare class ExternalStoreRuntime extends BaseAssistantRuntime<ExternalStoreThr
555
570
  private readonly _proxyConfigProvider;
556
571
  constructor(store: ExternalStoreAdapter<any>);
557
572
  set store(store: ExternalStoreAdapter<any>);
558
- onStoreUpdated(): void;
559
573
  getModelConfig(): ModelConfig;
560
574
  registerModelConfigProvider(provider: ModelConfigProvider): () => void;
561
575
  switchToThread(threadId: string | null): void | Promise<void>;
562
576
  }
563
577
 
564
- declare const useExternalStoreRuntime: (store: ExternalStoreAdapter<any>) => ExternalStoreRuntime;
578
+ declare const useExternalStoreRuntime: <T>(store: ExternalStoreAdapter<T>) => ExternalStoreRuntime;
565
579
 
566
580
  declare const getExternalStoreMessage: <T>(message: ThreadMessage) => T | undefined;
567
581