@assistant-ui/react 0.5.12 → 0.5.15

Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.d.mts CHANGED
@@ -554,9 +554,9 @@ type EdgeRuntimeRequestOptions = z.infer<typeof EdgeRuntimeRequestOptionsSchema>
554
554
  type ThreadMessageLike = {
555
555
  role: "assistant" | "user" | "system";
556
556
  content: (TextContentPart | ImageContentPart | ToolCallContentPart<any, any> | CoreToolCallContentPart<any, any> | UIContentPart)[];
557
- id?: string;
558
- createdAt?: Date;
559
- status?: MessageStatus;
557
+ id?: string | undefined;
558
+ createdAt?: Date | undefined;
559
+ status?: MessageStatus | undefined;
560
560
  };
561
561
 
562
562
  type ExternalStoreMessageConverter<T> = (message: T, idx: number) => ThreadMessageLike;
@@ -564,8 +564,8 @@ type ExternalStoreMessageConverterAdapter<T> = {
564
564
  convertMessage: ExternalStoreMessageConverter<T>;
565
565
  };
566
566
  type ExternalStoreAdapterBase<T> = {
567
- threadId?: string;
568
- isRunning?: boolean;
567
+ threadId?: string | undefined;
568
+ isRunning?: boolean | undefined;
569
569
  messages: T[];
570
570
  setMessages?: ((messages: T[]) => void) | undefined;
571
571
  onNew: (message: AppendMessage) => Promise<void>;
package/dist/index.d.ts CHANGED
@@ -554,9 +554,9 @@ type EdgeRuntimeRequestOptions = z.infer<typeof EdgeRuntimeRequestOptionsSchema>
554
554
  type ThreadMessageLike = {
555
555
  role: "assistant" | "user" | "system";
556
556
  content: (TextContentPart | ImageContentPart | ToolCallContentPart<any, any> | CoreToolCallContentPart<any, any> | UIContentPart)[];
557
- id?: string;
558
- createdAt?: Date;
559
- status?: MessageStatus;
557
+ id?: string | undefined;
558
+ createdAt?: Date | undefined;
559
+ status?: MessageStatus | undefined;
560
560
  };
561
561
 
562
562
  type ExternalStoreMessageConverter<T> = (message: T, idx: number) => ThreadMessageLike;
@@ -564,8 +564,8 @@ type ExternalStoreMessageConverterAdapter<T> = {
564
564
  convertMessage: ExternalStoreMessageConverter<T>;
565
565
  };
566
566
  type ExternalStoreAdapterBase<T> = {
567
- threadId?: string;
568
- isRunning?: boolean;
567
+ threadId?: string | undefined;
568
+ isRunning?: boolean | undefined;
569
569
  messages: T[];
570
570
  setMessages?: ((messages: T[]) => void) | undefined;
571
571
  onNew: (message: AppendMessage) => Promise<void>;
package/dist/index.js CHANGED
@@ -1290,7 +1290,7 @@ var getContentPartState = ({ message }, useContentPart, partIndex) => {
1290
1290
  if (message.content.length === 0 && partIndex === 0) {
1291
1291
  part = EMPTY_CONTENT;
1292
1292
  } else {
1293
- return;
1293
+ return null;
1294
1294
  }
1295
1295
  }
1296
1296
  const status = toContentPartStatus(message, partIndex, part);
@@ -1919,6 +1919,7 @@ var getIsLast = (messages, message) => {
1919
1919
  var getMessageState = (messages, getBranches, useMessage, messageIndex) => {
1920
1920
  const parentId = messages[messageIndex - 1]?.id ?? null;
1921
1921
  const message = messages[messageIndex];
1922
+ if (!message) return null;
1922
1923
  const isLast = getIsLast(messages, message);
1923
1924
  const branches = getBranches(message.id);
1924
1925
  const currentState = useMessage?.getState();
@@ -3687,7 +3688,6 @@ var AUTO_STATUS_COMPLETE = Object.freeze({
3687
3688
  type: "complete",
3688
3689
  reason: "unknown"
3689
3690
  });
3690
- var isAutoStatus = (status) => status === AUTO_STATUS_RUNNING || status === AUTO_STATUS_COMPLETE;
3691
3691
  var getAutoStatus = (isLast, isRunning) => isLast && isRunning ? AUTO_STATUS_RUNNING : AUTO_STATUS_COMPLETE;
3692
3692
 
3693
3693
  // src/runtimes/external-store/ThreadMessageLike.tsx
@@ -3771,9 +3771,8 @@ var useExternalStoreSync = (adapter, updateData) => {
3771
3771
  adapterRef.current.messages.at(-1) === m,
3772
3772
  adapterRef.current.isRunning ?? false
3773
3773
  );
3774
- if (cache && (cache.role !== "assistant" || !isAutoStatus(cache.status) || cache.status.type === autoStatus.type))
3774
+ if (cache && (cache.role !== "assistant" || cache.status === autoStatus))
3775
3775
  return cache;
3776
- if (cache) return cache;
3777
3776
  const newMessage = fromThreadMessageLike(
3778
3777
  converter2(m, idx),
3779
3778
  idx.toString(),