2025-02-18 07:25:31 +08:00
|
|
|
import { useMessageIndividual } from '@/context/Chats';
|
2025-02-11 11:15:32 +08:00
|
|
|
import type { SelectedFile } from '../interfaces';
|
2025-02-09 13:41:08 +08:00
|
|
|
import { usePrevious } from 'ahooks';
|
|
|
|
import { useEffect } from 'react';
|
|
|
|
|
|
|
|
export const useAutoChangeLayout = ({
|
|
|
|
lastMessageId,
|
2025-02-12 07:46:22 +08:00
|
|
|
|
2025-02-09 13:41:08 +08:00
|
|
|
onSetSelectedFile
|
|
|
|
}: {
|
|
|
|
lastMessageId: string;
|
|
|
|
onSetSelectedFile: (file: SelectedFile) => void;
|
|
|
|
}) => {
|
2025-02-18 07:25:31 +08:00
|
|
|
const message = useMessageIndividual(lastMessageId);
|
2025-02-09 13:41:08 +08:00
|
|
|
const reasoningMessagesLength = message?.reasoning?.length;
|
|
|
|
const previousReasoningMessagesLength = usePrevious(reasoningMessagesLength);
|
|
|
|
const isCompletedStream = message?.isCompletedStream;
|
2025-02-11 11:15:32 +08:00
|
|
|
const isLoading = !isCompletedStream;
|
2025-02-09 13:41:08 +08:00
|
|
|
const hasReasoning = !!reasoningMessagesLength;
|
|
|
|
const previousIsEmpty = previousReasoningMessagesLength === 0;
|
|
|
|
|
2025-03-05 04:11:49 +08:00
|
|
|
console.log(isLoading, previousIsEmpty, hasReasoning, message);
|
|
|
|
|
2025-02-12 07:46:22 +08:00
|
|
|
//change the page to reasoning file if we get a reasoning message
|
2025-02-09 13:41:08 +08:00
|
|
|
useEffect(() => {
|
|
|
|
if (isLoading && previousIsEmpty && hasReasoning) {
|
|
|
|
onSetSelectedFile({ id: lastMessageId, type: 'reasoning' });
|
|
|
|
}
|
|
|
|
}, [isLoading, hasReasoning, previousIsEmpty]);
|
|
|
|
};
|