@assistant-ui/react 0.5.10 → 0.5.12

Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.d.mts CHANGED
@@ -551,7 +551,15 @@ declare const EdgeRuntimeRequestOptionsSchema: z.ZodObject<z.objectUtil.extendSh
551
551
  }>;
552
552
  type EdgeRuntimeRequestOptions = z.infer<typeof EdgeRuntimeRequestOptionsSchema>;
553
553
 
554
- type ExternalStoreMessageConverter<T> = (message: T, idx: number) => ThreadMessage;
554
+ type ThreadMessageLike = {
555
+ role: "assistant" | "user" | "system";
556
+ content: (TextContentPart | ImageContentPart | ToolCallContentPart<any, any> | CoreToolCallContentPart<any, any> | UIContentPart)[];
557
+ id?: string;
558
+ createdAt?: Date;
559
+ status?: MessageStatus;
560
+ };
561
+
562
+ type ExternalStoreMessageConverter<T> = (message: T, idx: number) => ThreadMessageLike;
555
563
  type ExternalStoreMessageConverterAdapter<T> = {
556
564
  convertMessage: ExternalStoreMessageConverter<T>;
557
565
  };
@@ -1473,4 +1481,4 @@ declare const exports: {
1473
1481
  Text: FC<TextContentPartProps>;
1474
1482
  };
1475
1483
 
1476
- export { index$6 as ActionBarPrimitive, type ActionBarPrimitiveCopyProps, type ActionBarPrimitiveEditProps, type ActionBarPrimitiveReloadProps, type ActionBarPrimitiveRootProps, type AddToolResultOptions, type AppendMessage, _default$9 as AssistantActionBar, type AssistantActionsState, type AssistantContextValue, _default$8 as AssistantMessage, type AssistantMessageConfig, type AssistantMessageContentProps, _default$7 as AssistantModal, index$5 as AssistantModalPrimitive, type AssistantModalPrimitiveContentProps, type AssistantModalPrimitiveRootProps, type AssistantModalPrimitiveTriggerProps, type AssistantModelConfigState, type AssistantRuntime, AssistantRuntimeProvider, type AssistantToolProps, type AssistantToolUIProps, type AssistantToolUIsState, _default$6 as BranchPicker, index$4 as BranchPickerPrimitive, type BranchPickerPrimitiveCountProps, type BranchPickerPrimitiveNextProps, type BranchPickerPrimitiveNumberProps, type BranchPickerPrimitivePreviousProps, type BranchPickerPrimitiveRootProps, type ChatModelAdapter, type ChatModelRunOptions, type ChatModelRunResult, type ChatModelRunUpdate, _default$5 as Composer, type ComposerContextValue, type ComposerInputProps, index$3 as ComposerPrimitive, type ComposerPrimitiveCancelProps, type ComposerPrimitiveIfProps, type ComposerPrimitiveInputProps, type ComposerPrimitiveRootProps, type ComposerPrimitiveSendProps, type ComposerState, exports as ContentPart, type ContentPartContextValue, index$2 as ContentPartPrimitive, type ContentPartPrimitiveDisplayProps, type ContentPartPrimitiveImageProps, type ContentPartPrimitiveInProgressProps, type ContentPartPrimitiveTextProps, type ContentPartState, type CoreAssistantContentPart, type CoreAssistantMessage, type CoreMessage, type CoreSystemMessage, type CoreUserContentPart, type CoreUserMessage, EdgeChatAdapter, type EdgeRuntimeOptions, type EdgeRuntimeRequestOptions, _default$4 as EditComposer, type EditComposerState, type ExternalStoreAdapter, type ExternalStoreMessageConverter, ExternalStoreRuntime, internal as INTERNAL, type ImageContentPart, type ImageContentPartComponent, type ImageContentPartProps, type LocalRuntimeOptions, type MessageContextValue, index$1 as MessagePrimitive, type MessagePrimitiveContentProps, type MessagePrimitiveIfProps, type MessagePrimitiveInProgressProps, type MessagePrimitiveRootProps, type MessageState, type MessageStatus, type MessageUtilsState, type ModelConfig, type ModelConfigProvider, type ReactThreadRuntime, type StringsConfig, type SuggestionConfig, type TextContentPart, type TextContentPartComponent, type TextContentPartProps, _default$3 as Thread, type ThreadActionsState, type ThreadAssistantContentPart, type ThreadAssistantMessage, type ThreadConfig, ThreadConfigProvider, type ThreadConfigProviderProps, type ThreadContextValue, type ThreadMessage, type ThreadMessagesState, index as ThreadPrimitive, type ThreadPrimitiveEmptyProps, type ThreadPrimitiveIfProps, type ThreadPrimitiveMessagesProps, type ThreadPrimitiveRootProps, type ThreadPrimitiveScrollToBottomProps, type ThreadPrimitiveSuggestionProps, type ThreadPrimitiveViewportProps, type ThreadRootProps, type ThreadRuntime, type ThreadState, type ThreadSystemMessage, type ThreadUserContentPart, type ThreadUserMessage, type ThreadViewportState, _default as ThreadWelcome, type ThreadWelcomeConfig, type ThreadWelcomeMessageProps, type ThreadWelcomeSuggestionProps, type Tool, type ToolCallContentPart, type ToolCallContentPartComponent, type ToolCallContentPartProps, type UIContentPart, type UIContentPartComponent, type UIContentPartProps, type Unsubscribe, type UseActionBarCopyProps, _default$1 as UserActionBar, _default$2 as UserMessage, type UserMessageConfig, type UserMessageContentProps, fromCoreMessage, fromCoreMessages, fromLanguageModelMessages, fromLanguageModelTools, getExternalStoreMessage, makeAssistantTool, makeAssistantToolUI, toCoreMessage, toCoreMessages, toLanguageModelMessages, toLanguageModelTools, useActionBarCopy, useActionBarEdit, useActionBarReload, useAppendMessage, useAssistantContext, useAssistantInstructions, useAssistantTool, useAssistantToolUI, useBranchPickerCount, useBranchPickerNext, useBranchPickerNumber, useBranchPickerPrevious, useComposerCancel, useComposerContext, useComposerIf, useComposerSend, useContentPartContext, useContentPartDisplay, useContentPartImage, useContentPartText, useEdgeRuntime, useExternalStoreRuntime, useLocalRuntime, useMessageContext, useMessageIf, useSwitchToNewThread, useThreadConfig, useThreadContext, useThreadEmpty, useThreadIf, useThreadScrollToBottom, useThreadSuggestion };
1484
+ export { index$6 as ActionBarPrimitive, type ActionBarPrimitiveCopyProps, type ActionBarPrimitiveEditProps, type ActionBarPrimitiveReloadProps, type ActionBarPrimitiveRootProps, type AddToolResultOptions, type AppendMessage, _default$9 as AssistantActionBar, type AssistantActionsState, type AssistantContextValue, _default$8 as AssistantMessage, type AssistantMessageConfig, type AssistantMessageContentProps, _default$7 as AssistantModal, index$5 as AssistantModalPrimitive, type AssistantModalPrimitiveContentProps, type AssistantModalPrimitiveRootProps, type AssistantModalPrimitiveTriggerProps, type AssistantModelConfigState, type AssistantRuntime, AssistantRuntimeProvider, type AssistantToolProps, type AssistantToolUIProps, type AssistantToolUIsState, _default$6 as BranchPicker, index$4 as BranchPickerPrimitive, type BranchPickerPrimitiveCountProps, type BranchPickerPrimitiveNextProps, type BranchPickerPrimitiveNumberProps, type BranchPickerPrimitivePreviousProps, type BranchPickerPrimitiveRootProps, type ChatModelAdapter, type ChatModelRunOptions, type ChatModelRunResult, type ChatModelRunUpdate, _default$5 as Composer, type ComposerContextValue, type ComposerInputProps, index$3 as ComposerPrimitive, type ComposerPrimitiveCancelProps, type ComposerPrimitiveIfProps, type ComposerPrimitiveInputProps, type ComposerPrimitiveRootProps, type ComposerPrimitiveSendProps, type ComposerState, exports as ContentPart, type ContentPartContextValue, index$2 as ContentPartPrimitive, type ContentPartPrimitiveDisplayProps, type ContentPartPrimitiveImageProps, type ContentPartPrimitiveInProgressProps, type ContentPartPrimitiveTextProps, type ContentPartState, type CoreAssistantContentPart, type CoreAssistantMessage, type CoreMessage, type CoreSystemMessage, type CoreUserContentPart, type CoreUserMessage, EdgeChatAdapter, type EdgeRuntimeOptions, type EdgeRuntimeRequestOptions, _default$4 as EditComposer, type EditComposerState, type ExternalStoreAdapter, type ExternalStoreMessageConverter, ExternalStoreRuntime, internal as INTERNAL, type ImageContentPart, type ImageContentPartComponent, type ImageContentPartProps, type LocalRuntimeOptions, type MessageContextValue, index$1 as MessagePrimitive, type MessagePrimitiveContentProps, type MessagePrimitiveIfProps, type MessagePrimitiveInProgressProps, type MessagePrimitiveRootProps, type MessageState, type MessageStatus, type MessageUtilsState, type ModelConfig, type ModelConfigProvider, type ReactThreadRuntime, type StringsConfig, type SuggestionConfig, type TextContentPart, type TextContentPartComponent, type TextContentPartProps, _default$3 as Thread, type ThreadActionsState, type ThreadAssistantContentPart, type ThreadAssistantMessage, type ThreadConfig, ThreadConfigProvider, type ThreadConfigProviderProps, type ThreadContextValue, type ThreadMessage, type ThreadMessageLike, type ThreadMessagesState, index as ThreadPrimitive, type ThreadPrimitiveEmptyProps, type ThreadPrimitiveIfProps, type ThreadPrimitiveMessagesProps, type ThreadPrimitiveRootProps, type ThreadPrimitiveScrollToBottomProps, type ThreadPrimitiveSuggestionProps, type ThreadPrimitiveViewportProps, type ThreadRootProps, type ThreadRuntime, type ThreadState, type ThreadSystemMessage, type ThreadUserContentPart, type ThreadUserMessage, type ThreadViewportState, _default as ThreadWelcome, type ThreadWelcomeConfig, type ThreadWelcomeMessageProps, type ThreadWelcomeSuggestionProps, type Tool, type ToolCallContentPart, type ToolCallContentPartComponent, type ToolCallContentPartProps, type UIContentPart, type UIContentPartComponent, type UIContentPartProps, type Unsubscribe, type UseActionBarCopyProps, _default$1 as UserActionBar, _default$2 as UserMessage, type UserMessageConfig, type UserMessageContentProps, fromCoreMessage, fromCoreMessages, fromLanguageModelMessages, fromLanguageModelTools, getExternalStoreMessage, makeAssistantTool, makeAssistantToolUI, toCoreMessage, toCoreMessages, toLanguageModelMessages, toLanguageModelTools, useActionBarCopy, useActionBarEdit, useActionBarReload, useAppendMessage, useAssistantContext, useAssistantInstructions, useAssistantTool, useAssistantToolUI, useBranchPickerCount, useBranchPickerNext, useBranchPickerNumber, useBranchPickerPrevious, useComposerCancel, useComposerContext, useComposerIf, useComposerSend, useContentPartContext, useContentPartDisplay, useContentPartImage, useContentPartText, useEdgeRuntime, useExternalStoreRuntime, useLocalRuntime, useMessageContext, useMessageIf, useSwitchToNewThread, useThreadConfig, useThreadContext, useThreadEmpty, useThreadIf, useThreadScrollToBottom, useThreadSuggestion };
package/dist/index.d.ts CHANGED
@@ -551,7 +551,15 @@ declare const EdgeRuntimeRequestOptionsSchema: z.ZodObject<z.objectUtil.extendSh
551
551
  }>;
552
552
  type EdgeRuntimeRequestOptions = z.infer<typeof EdgeRuntimeRequestOptionsSchema>;
553
553
 
554
- type ExternalStoreMessageConverter<T> = (message: T, idx: number) => ThreadMessage;
554
+ type ThreadMessageLike = {
555
+ role: "assistant" | "user" | "system";
556
+ content: (TextContentPart | ImageContentPart | ToolCallContentPart<any, any> | CoreToolCallContentPart<any, any> | UIContentPart)[];
557
+ id?: string;
558
+ createdAt?: Date;
559
+ status?: MessageStatus;
560
+ };
561
+
562
+ type ExternalStoreMessageConverter<T> = (message: T, idx: number) => ThreadMessageLike;
555
563
  type ExternalStoreMessageConverterAdapter<T> = {
556
564
  convertMessage: ExternalStoreMessageConverter<T>;
557
565
  };
@@ -1473,4 +1481,4 @@ declare const exports: {
1473
1481
  Text: FC<TextContentPartProps>;
1474
1482
  };
1475
1483
 
1476
- export { index$6 as ActionBarPrimitive, type ActionBarPrimitiveCopyProps, type ActionBarPrimitiveEditProps, type ActionBarPrimitiveReloadProps, type ActionBarPrimitiveRootProps, type AddToolResultOptions, type AppendMessage, _default$9 as AssistantActionBar, type AssistantActionsState, type AssistantContextValue, _default$8 as AssistantMessage, type AssistantMessageConfig, type AssistantMessageContentProps, _default$7 as AssistantModal, index$5 as AssistantModalPrimitive, type AssistantModalPrimitiveContentProps, type AssistantModalPrimitiveRootProps, type AssistantModalPrimitiveTriggerProps, type AssistantModelConfigState, type AssistantRuntime, AssistantRuntimeProvider, type AssistantToolProps, type AssistantToolUIProps, type AssistantToolUIsState, _default$6 as BranchPicker, index$4 as BranchPickerPrimitive, type BranchPickerPrimitiveCountProps, type BranchPickerPrimitiveNextProps, type BranchPickerPrimitiveNumberProps, type BranchPickerPrimitivePreviousProps, type BranchPickerPrimitiveRootProps, type ChatModelAdapter, type ChatModelRunOptions, type ChatModelRunResult, type ChatModelRunUpdate, _default$5 as Composer, type ComposerContextValue, type ComposerInputProps, index$3 as ComposerPrimitive, type ComposerPrimitiveCancelProps, type ComposerPrimitiveIfProps, type ComposerPrimitiveInputProps, type ComposerPrimitiveRootProps, type ComposerPrimitiveSendProps, type ComposerState, exports as ContentPart, type ContentPartContextValue, index$2 as ContentPartPrimitive, type ContentPartPrimitiveDisplayProps, type ContentPartPrimitiveImageProps, type ContentPartPrimitiveInProgressProps, type ContentPartPrimitiveTextProps, type ContentPartState, type CoreAssistantContentPart, type CoreAssistantMessage, type CoreMessage, type CoreSystemMessage, type CoreUserContentPart, type CoreUserMessage, EdgeChatAdapter, type EdgeRuntimeOptions, type EdgeRuntimeRequestOptions, _default$4 as EditComposer, type EditComposerState, type ExternalStoreAdapter, type ExternalStoreMessageConverter, ExternalStoreRuntime, internal as INTERNAL, type ImageContentPart, type ImageContentPartComponent, type ImageContentPartProps, type LocalRuntimeOptions, type MessageContextValue, index$1 as MessagePrimitive, type MessagePrimitiveContentProps, type MessagePrimitiveIfProps, type MessagePrimitiveInProgressProps, type MessagePrimitiveRootProps, type MessageState, type MessageStatus, type MessageUtilsState, type ModelConfig, type ModelConfigProvider, type ReactThreadRuntime, type StringsConfig, type SuggestionConfig, type TextContentPart, type TextContentPartComponent, type TextContentPartProps, _default$3 as Thread, type ThreadActionsState, type ThreadAssistantContentPart, type ThreadAssistantMessage, type ThreadConfig, ThreadConfigProvider, type ThreadConfigProviderProps, type ThreadContextValue, type ThreadMessage, type ThreadMessagesState, index as ThreadPrimitive, type ThreadPrimitiveEmptyProps, type ThreadPrimitiveIfProps, type ThreadPrimitiveMessagesProps, type ThreadPrimitiveRootProps, type ThreadPrimitiveScrollToBottomProps, type ThreadPrimitiveSuggestionProps, type ThreadPrimitiveViewportProps, type ThreadRootProps, type ThreadRuntime, type ThreadState, type ThreadSystemMessage, type ThreadUserContentPart, type ThreadUserMessage, type ThreadViewportState, _default as ThreadWelcome, type ThreadWelcomeConfig, type ThreadWelcomeMessageProps, type ThreadWelcomeSuggestionProps, type Tool, type ToolCallContentPart, type ToolCallContentPartComponent, type ToolCallContentPartProps, type UIContentPart, type UIContentPartComponent, type UIContentPartProps, type Unsubscribe, type UseActionBarCopyProps, _default$1 as UserActionBar, _default$2 as UserMessage, type UserMessageConfig, type UserMessageContentProps, fromCoreMessage, fromCoreMessages, fromLanguageModelMessages, fromLanguageModelTools, getExternalStoreMessage, makeAssistantTool, makeAssistantToolUI, toCoreMessage, toCoreMessages, toLanguageModelMessages, toLanguageModelTools, useActionBarCopy, useActionBarEdit, useActionBarReload, useAppendMessage, useAssistantContext, useAssistantInstructions, useAssistantTool, useAssistantToolUI, useBranchPickerCount, useBranchPickerNext, useBranchPickerNumber, useBranchPickerPrevious, useComposerCancel, useComposerContext, useComposerIf, useComposerSend, useContentPartContext, useContentPartDisplay, useContentPartImage, useContentPartText, useEdgeRuntime, useExternalStoreRuntime, useLocalRuntime, useMessageContext, useMessageIf, useSwitchToNewThread, useThreadConfig, useThreadContext, useThreadEmpty, useThreadIf, useThreadScrollToBottom, useThreadSuggestion };
1484
+ export { index$6 as ActionBarPrimitive, type ActionBarPrimitiveCopyProps, type ActionBarPrimitiveEditProps, type ActionBarPrimitiveReloadProps, type ActionBarPrimitiveRootProps, type AddToolResultOptions, type AppendMessage, _default$9 as AssistantActionBar, type AssistantActionsState, type AssistantContextValue, _default$8 as AssistantMessage, type AssistantMessageConfig, type AssistantMessageContentProps, _default$7 as AssistantModal, index$5 as AssistantModalPrimitive, type AssistantModalPrimitiveContentProps, type AssistantModalPrimitiveRootProps, type AssistantModalPrimitiveTriggerProps, type AssistantModelConfigState, type AssistantRuntime, AssistantRuntimeProvider, type AssistantToolProps, type AssistantToolUIProps, type AssistantToolUIsState, _default$6 as BranchPicker, index$4 as BranchPickerPrimitive, type BranchPickerPrimitiveCountProps, type BranchPickerPrimitiveNextProps, type BranchPickerPrimitiveNumberProps, type BranchPickerPrimitivePreviousProps, type BranchPickerPrimitiveRootProps, type ChatModelAdapter, type ChatModelRunOptions, type ChatModelRunResult, type ChatModelRunUpdate, _default$5 as Composer, type ComposerContextValue, type ComposerInputProps, index$3 as ComposerPrimitive, type ComposerPrimitiveCancelProps, type ComposerPrimitiveIfProps, type ComposerPrimitiveInputProps, type ComposerPrimitiveRootProps, type ComposerPrimitiveSendProps, type ComposerState, exports as ContentPart, type ContentPartContextValue, index$2 as ContentPartPrimitive, type ContentPartPrimitiveDisplayProps, type ContentPartPrimitiveImageProps, type ContentPartPrimitiveInProgressProps, type ContentPartPrimitiveTextProps, type ContentPartState, type CoreAssistantContentPart, type CoreAssistantMessage, type CoreMessage, type CoreSystemMessage, type CoreUserContentPart, type CoreUserMessage, EdgeChatAdapter, type EdgeRuntimeOptions, type EdgeRuntimeRequestOptions, _default$4 as EditComposer, type EditComposerState, type ExternalStoreAdapter, type ExternalStoreMessageConverter, ExternalStoreRuntime, internal as INTERNAL, type ImageContentPart, type ImageContentPartComponent, type ImageContentPartProps, type LocalRuntimeOptions, type MessageContextValue, index$1 as MessagePrimitive, type MessagePrimitiveContentProps, type MessagePrimitiveIfProps, type MessagePrimitiveInProgressProps, type MessagePrimitiveRootProps, type MessageState, type MessageStatus, type MessageUtilsState, type ModelConfig, type ModelConfigProvider, type ReactThreadRuntime, type StringsConfig, type SuggestionConfig, type TextContentPart, type TextContentPartComponent, type TextContentPartProps, _default$3 as Thread, type ThreadActionsState, type ThreadAssistantContentPart, type ThreadAssistantMessage, type ThreadConfig, ThreadConfigProvider, type ThreadConfigProviderProps, type ThreadContextValue, type ThreadMessage, type ThreadMessageLike, type ThreadMessagesState, index as ThreadPrimitive, type ThreadPrimitiveEmptyProps, type ThreadPrimitiveIfProps, type ThreadPrimitiveMessagesProps, type ThreadPrimitiveRootProps, type ThreadPrimitiveScrollToBottomProps, type ThreadPrimitiveSuggestionProps, type ThreadPrimitiveViewportProps, type ThreadRootProps, type ThreadRuntime, type ThreadState, type ThreadSystemMessage, type ThreadUserContentPart, type ThreadUserMessage, type ThreadViewportState, _default as ThreadWelcome, type ThreadWelcomeConfig, type ThreadWelcomeMessageProps, type ThreadWelcomeSuggestionProps, type Tool, type ToolCallContentPart, type ToolCallContentPartComponent, type ToolCallContentPartProps, type UIContentPart, type UIContentPartComponent, type UIContentPartProps, type Unsubscribe, type UseActionBarCopyProps, _default$1 as UserActionBar, _default$2 as UserMessage, type UserMessageConfig, type UserMessageContentProps, fromCoreMessage, fromCoreMessages, fromLanguageModelMessages, fromLanguageModelTools, getExternalStoreMessage, makeAssistantTool, makeAssistantToolUI, toCoreMessage, toCoreMessages, toLanguageModelMessages, toLanguageModelTools, useActionBarCopy, useActionBarEdit, useActionBarReload, useAppendMessage, useAssistantContext, useAssistantInstructions, useAssistantTool, useAssistantToolUI, useBranchPickerCount, useBranchPickerNext, useBranchPickerNumber, useBranchPickerPrevious, useComposerCancel, useComposerContext, useComposerIf, useComposerSend, useContentPartContext, useContentPartDisplay, useContentPartImage, useContentPartText, useEdgeRuntime, useExternalStoreRuntime, useLocalRuntime, useMessageContext, useMessageIf, useSwitchToNewThread, useThreadConfig, useThreadContext, useThreadEmpty, useThreadIf, useThreadScrollToBottom, useThreadSuggestion };
package/dist/index.js CHANGED
@@ -1284,7 +1284,7 @@ var toContentPartStatus = (message, partIndex, part) => {
1284
1284
  return message.status;
1285
1285
  };
1286
1286
  var EMPTY_CONTENT = Object.freeze({ type: "text", text: "" });
1287
- var syncContentPart = ({ message }, useContentPart, partIndex) => {
1287
+ var getContentPartState = ({ message }, useContentPart, partIndex) => {
1288
1288
  let part = message.content[partIndex];
1289
1289
  if (!part) {
1290
1290
  if (message.content.length === 0 && partIndex === 0) {
@@ -1294,29 +1294,32 @@ var syncContentPart = ({ message }, useContentPart, partIndex) => {
1294
1294
  }
1295
1295
  }
1296
1296
  const status = toContentPartStatus(message, partIndex, part);
1297
- const currentState = useContentPart.getState();
1298
- if (currentState.part === part && currentState.status === status) return;
1299
- useContentPart.setState(
1300
- Object.freeze({
1301
- part,
1302
- status
1303
- })
1304
- );
1297
+ const currentState = useContentPart?.getState();
1298
+ if (currentState && currentState.part === part && currentState.status === status)
1299
+ return null;
1300
+ return Object.freeze({ part, status });
1305
1301
  };
1306
1302
  var useContentPartContext2 = (partIndex) => {
1307
1303
  const { useMessage } = useMessageContext();
1308
1304
  const [context] = (0, import_react34.useState)(() => {
1309
1305
  const useContentPart = (0, import_zustand10.create)(
1310
- () => ({})
1306
+ () => getContentPartState(useMessage.getState(), void 0, partIndex)
1311
1307
  );
1312
- syncContentPart(useMessage.getState(), useContentPart, partIndex);
1308
+ getContentPartState(useMessage.getState(), useContentPart, partIndex);
1313
1309
  return { useContentPart };
1314
1310
  });
1315
1311
  (0, import_react34.useEffect)(() => {
1316
- syncContentPart(useMessage.getState(), context.useContentPart, partIndex);
1317
- return useMessage.subscribe((message) => {
1318
- syncContentPart(message, context.useContentPart, partIndex);
1319
- });
1312
+ const syncContentPart = (message) => {
1313
+ const newState = getContentPartState(
1314
+ message,
1315
+ context.useContentPart,
1316
+ partIndex
1317
+ );
1318
+ if (!newState) return;
1319
+ context.useContentPart.setState(newState, true);
1320
+ };
1321
+ syncContentPart(useMessage.getState());
1322
+ return useMessage.subscribe(syncContentPart);
1320
1323
  }, [context, useMessage, partIndex]);
1321
1324
  return context;
1322
1325
  };
@@ -1913,16 +1916,15 @@ var import_jsx_runtime23 = require("react/jsx-runtime");
1913
1916
  var getIsLast = (messages, message) => {
1914
1917
  return messages[messages.length - 1]?.id === message.id;
1915
1918
  };
1916
- var syncMessage = (messages, getBranches, useMessage, messageIndex) => {
1919
+ var getMessageState = (messages, getBranches, useMessage, messageIndex) => {
1917
1920
  const parentId = messages[messageIndex - 1]?.id ?? null;
1918
1921
  const message = messages[messageIndex];
1919
- if (!message) return;
1920
1922
  const isLast = getIsLast(messages, message);
1921
1923
  const branches = getBranches(message.id);
1922
- const currentState = useMessage.getState();
1923
- if (currentState.message === message && currentState.parentId === parentId && currentState.branches === branches && currentState.isLast === isLast)
1924
- return;
1925
- useMessage.setState({
1924
+ const currentState = useMessage?.getState();
1925
+ if (currentState && currentState.message === message && currentState.parentId === parentId && currentState.branches === branches && currentState.isLast === isLast)
1926
+ return null;
1927
+ return Object.freeze({
1926
1928
  message,
1927
1929
  parentId,
1928
1930
  branches,
@@ -1932,7 +1934,14 @@ var syncMessage = (messages, getBranches, useMessage, messageIndex) => {
1932
1934
  var useMessageContext2 = (messageIndex) => {
1933
1935
  const { useThreadMessages, useThreadActions } = useThreadContext();
1934
1936
  const [context] = (0, import_react48.useState)(() => {
1935
- const useMessage = (0, import_zustand13.create)(() => ({}));
1937
+ const useMessage = (0, import_zustand13.create)(
1938
+ () => getMessageState(
1939
+ useThreadMessages.getState(),
1940
+ useThreadActions.getState().getBranches,
1941
+ void 0,
1942
+ messageIndex
1943
+ )
1944
+ );
1936
1945
  const useMessageUtils = makeMessageUtilsStore();
1937
1946
  const useEditComposer = makeEditComposerStore({
1938
1947
  onEdit: () => {
@@ -1960,23 +1969,24 @@ var useMessageContext2 = (messageIndex) => {
1960
1969
  });
1961
1970
  }
1962
1971
  });
1963
- syncMessage(
1964
- useThreadMessages.getState(),
1965
- useThreadActions.getState().getBranches,
1966
- useMessage,
1967
- messageIndex
1968
- );
1969
1972
  return { useMessage, useMessageUtils, useEditComposer };
1970
1973
  });
1971
1974
  (0, import_react48.useEffect)(() => {
1972
- return useThreadMessages.subscribe((thread) => {
1973
- syncMessage(
1975
+ const syncMessage = (thread) => {
1976
+ const newState = getMessageState(
1974
1977
  thread,
1975
1978
  useThreadActions.getState().getBranches,
1976
1979
  context.useMessage,
1977
1980
  messageIndex
1978
1981
  );
1979
- });
1982
+ if (!newState) return;
1983
+ context.useMessage.setState(
1984
+ newState,
1985
+ true
1986
+ );
1987
+ };
1988
+ syncMessage(useThreadMessages.getState());
1989
+ return useThreadMessages.subscribe(syncMessage);
1980
1990
  }, [useThreadMessages, useThreadActions, context, messageIndex]);
1981
1991
  return context;
1982
1992
  };
@@ -3671,13 +3681,104 @@ var ThreadMessageConverter = class {
3671
3681
  }
3672
3682
  };
3673
3683
 
3684
+ // src/runtimes/external-store/auto-status.tsx
3685
+ var AUTO_STATUS_RUNNING = Object.freeze({ type: "running" });
3686
+ var AUTO_STATUS_COMPLETE = Object.freeze({
3687
+ type: "complete",
3688
+ reason: "unknown"
3689
+ });
3690
+ var isAutoStatus = (status) => status === AUTO_STATUS_RUNNING || status === AUTO_STATUS_COMPLETE;
3691
+ var getAutoStatus = (isLast, isRunning) => isLast && isRunning ? AUTO_STATUS_RUNNING : AUTO_STATUS_COMPLETE;
3692
+
3693
+ // src/runtimes/external-store/ThreadMessageLike.tsx
3694
+ var fromThreadMessageLike = (like, fallbackId, fallbackStatus) => {
3695
+ const { role, content, id, createdAt, status } = like;
3696
+ const common = {
3697
+ id: id ?? fallbackId,
3698
+ createdAt: createdAt ?? /* @__PURE__ */ new Date()
3699
+ };
3700
+ switch (role) {
3701
+ case "assistant":
3702
+ return {
3703
+ ...common,
3704
+ role,
3705
+ content: content.map((part) => {
3706
+ const type = part.type;
3707
+ switch (type) {
3708
+ case "text":
3709
+ case "ui":
3710
+ return part;
3711
+ case "tool-call": {
3712
+ if ("argsText" in part) return part;
3713
+ return {
3714
+ ...part,
3715
+ argsText: JSON.stringify(part.args)
3716
+ };
3717
+ }
3718
+ default: {
3719
+ const unhandledType = type;
3720
+ throw new Error(`Unknown content part type: ${unhandledType}`);
3721
+ }
3722
+ }
3723
+ }),
3724
+ status: status ?? fallbackStatus
3725
+ };
3726
+ case "user":
3727
+ return {
3728
+ ...common,
3729
+ role,
3730
+ content: content.map((part) => {
3731
+ const type = part.type;
3732
+ switch (type) {
3733
+ case "text":
3734
+ case "ui":
3735
+ case "image":
3736
+ return part;
3737
+ default: {
3738
+ const unhandledType = type;
3739
+ throw new Error(`Unknown content part type: ${unhandledType}`);
3740
+ }
3741
+ }
3742
+ })
3743
+ };
3744
+ case "system":
3745
+ if (content.length !== 1 || content[0].type !== "text")
3746
+ throw new Error(
3747
+ "System messages must have exactly one text content part."
3748
+ );
3749
+ return {
3750
+ ...common,
3751
+ role,
3752
+ content
3753
+ };
3754
+ default: {
3755
+ const unsupportedRole = role;
3756
+ throw new Error(`Unknown message role: ${unsupportedRole}`);
3757
+ }
3758
+ }
3759
+ };
3760
+
3674
3761
  // src/runtimes/external-store/useExternalStoreSync.tsx
3675
3762
  var useExternalStoreSync = (adapter, updateData) => {
3763
+ const adapterRef = (0, import_react55.useRef)(adapter);
3764
+ (0, import_react55.useInsertionEffect)(() => {
3765
+ adapterRef.current = adapter;
3766
+ });
3676
3767
  const [converter, convertCallback] = (0, import_react55.useMemo)(() => {
3677
3768
  const converter2 = adapter.convertMessage ?? ((m) => m);
3678
3769
  const convertCallback2 = (cache, m, idx) => {
3770
+ const autoStatus = getAutoStatus(
3771
+ adapterRef.current.messages.at(-1) === m,
3772
+ adapterRef.current.isRunning ?? false
3773
+ );
3774
+ if (cache && (cache.role !== "assistant" || !isAutoStatus(cache.status) || cache.status.type === autoStatus.type))
3775
+ return cache;
3679
3776
  if (cache) return cache;
3680
- const newMessage = converter2(m, idx);
3777
+ const newMessage = fromThreadMessageLike(
3778
+ converter2(m, idx),
3779
+ idx.toString(),
3780
+ autoStatus
3781
+ );
3681
3782
  newMessage[symbolInnerMessage] = m;
3682
3783
  return newMessage;
3683
3784
  };