messages: clearStateForMessages()

in apps/chat/src/components/Chat/Chat.tsx [443:582]


              messages: clearStateForMessages(conversation.messages),
              ...getConversationModelParams(
                conversation,
                temporarySettings.modelId,
                modelsMap,
                addonsMap,
              ),
              prompt: temporarySettings.prompt,
              temperature: temporarySettings.temperature,
              assistantModelId: temporarySettings.currentAssistantModelId,
              selectedAddons: temporarySettings.addonsIds.filter(
                (addonId) => addonsMap[addonId],
              ),
              isShared: temporarySettings.isShared,
            },
          }),
        );
      }
    });
  }, [selectedConversations, dispatch, modelsMap, addonsMap]);

  const handleTemporarySettingsSave = useCallback(
    (conversation: Conversation, args: ConversationsTemporarySettings) => {
      selectedConversationsTemporarySettings.current[conversation.id] = args;
    },
    [],
  );

  const setChatContainerRef = useCallback((ref: HTMLDivElement | null) => {
    chatContainerRef.current = ref;

    if (!ref) {
      return;
    }

    ref.scrollTo({ top: ref.scrollHeight });
  }, []);

  const onChatInputResize = useCallback((inputHeight: number) => {
    setInputHeight(inputHeight);
  }, []);

  const handleTalkToClose = useCallback(() => {
    handleTalkToConversationId(null);
  }, [handleTalkToConversationId]);

  const showLastMessageRegenerate =
    !isReplay &&
    !isPlayback &&
    !isExternal &&
    !messageIsStreaming &&
    !isLastMessageError &&
    !notAllowedType;
  const showFloatingOverlay =
    isSmallScreen() && isAnyMenuOpen && !isIsolatedView;
  const isModelsInstalled = selectedConversations.every((conv) =>
    installedModelIds.has(conv.model.id),
  );

  const areSelectedConversationsEmpty = selectedConversations.every(
    (conv) => !conv.messages.length,
  );

  useEffect(() => {
    dispatch(ChatActions.resetFormValue());
    dispatch(ChatActions.setInputContent(''));
  }, [dispatch, selectedConversationsIds]);

  return (
    <div
      className="relative min-w-0 shrink grow basis-0 overflow-y-auto"
      data-qa="chat"
      id="chat"
    >
      {showFloatingOverlay && <FloatingOverlay className="z-30 bg-blackout" />}
      {modelError ? (
        <ErrorMessageDiv error={modelError} />
      ) : (
        <>
          <div
            className={classNames(
              'flex size-full',
              isCompareMode ? 'landscape:hidden' : 'hidden',
            )}
          >
            <ChatCompareRotate />
          </div>
          <div
            className={classNames(
              'relative size-full',
              isCompareMode && 'portrait:hidden',
            )}
          >
            <div className="flex h-full">
              <div
                className={classNames(
                  'flex h-full flex-col',
                  isCompareMode && selectedConversations.length < 2
                    ? 'w-1/2'
                    : 'w-full',
                )}
                data-qa={isCompareMode ? 'compare-mode' : 'chat-mode'}
              >
                <div
                  className={classNames(
                    'flex h-full flex-col',
                    areSelectedConversationsEmpty
                      ? 'justify-center'
                      : 'justify-between',
                  )}
                >
                  <div className="flex w-full">
                    {selectedConversations.map((conv) => (
                      <div
                        key={conv.id}
                        className={classNames(
                          isCompareMode && selectedConversations.length > 1
                            ? 'w-1/2'
                            : 'w-full',
                        )}
                      >
                        {conv.messages.length !== 0 &&
                          enabledFeatures.has(Feature.TopSettings) && (
                            <div className="z-10 flex flex-col">
                              <ChatHeader
                                conversation={conv}
                                isCompareMode={isCompareMode}
                                isShowChatInfo={enabledFeatures.has(
                                  Feature.TopChatInfo,
                                )}
                                isShowClearConversation={
                                  enabledFeatures.has(
                                    Feature.TopClearConversation,
                                  ) &&
                                  !isPlayback &&
                                  !isReplay &&
                                  !isExternal
                                }
                                isShowSettings={isShowChatSettings}
                                setShowSettings={(isShow) => {