log reasoning flip to evals branch

This commit is contained in:
Nate Kelley 2025-04-17 23:21:39 -06:00
parent 9212903e9e
commit 70b3421d34
No known key found for this signature in database
GPG Key ID: FD90372AB8D98B4F
4 changed files with 63 additions and 28 deletions

View File

@ -187,7 +187,7 @@ export const PreventNavigation: React.FC<PreventNavigationProps> = React.memo(
window.history.pushState(null, document.title, window.location.href); window.history.pushState(null, document.title, window.location.href);
}); });
if (!isDirty) return <div className="bg-green-500 p-10" />; if (!isDirty) return null;
return ( return (
<LeavingDialog <LeavingDialog
@ -256,7 +256,6 @@ const LeavingDialog: React.FC<{
return ( return (
<> <>
<div className="bg-red-500 p-10" />
<AppModal open={isOpen} onClose={onClose} header={memoizedHeader} footer={memoizedFooter} /> <AppModal open={isOpen} onClose={onClose} header={memoizedHeader} footer={memoizedFooter} />
</> </>
); );

View File

@ -27,6 +27,7 @@ type ParagraphProps = {
style?: React.CSSProperties; style?: React.CSSProperties;
onClick?: React.MouseEventHandler<HTMLHeadingElement>; onClick?: React.MouseEventHandler<HTMLHeadingElement>;
children: React.ReactNode; children: React.ReactNode;
onCopy?: React.ClipboardEventHandler<HTMLHeadingElement>;
} & VariantProps<typeof textColorVariants> & } & VariantProps<typeof textColorVariants> &
VariantProps<typeof paragraphVariants>; VariantProps<typeof paragraphVariants>;
@ -37,7 +38,8 @@ export const Paragraph: React.FC<ParagraphProps> = ({
children, children,
className, className,
style, style,
lineHeight = 'base' lineHeight = 'base',
onCopy
}) => { }) => {
return ( return (
<p <p
@ -47,6 +49,7 @@ export const Paragraph: React.FC<ParagraphProps> = ({
className className
)} )}
style={style} style={style}
onCopy={onCopy}
onClick={onClick}> onClick={onClick}>
{children} {children}
</p> </p>

View File

@ -6,7 +6,7 @@ import { Paragraph } from '@/components/ui/typography';
import { MessageContainer } from './MessageContainer'; import { MessageContainer } from './MessageContainer';
import { Tooltip } from '@/components/ui/tooltip'; import { Tooltip } from '@/components/ui/tooltip';
import { cn } from '@/lib/classMerge'; import { cn } from '@/lib/classMerge';
import { PenWriting, Copy, Check } from '@/components/ui/icons'; import { PenWriting, Copy } from '@/components/ui/icons';
import { Button } from '@/components/ui/buttons'; import { Button } from '@/components/ui/buttons';
import { useBusterNotifications } from '@/context/BusterNotifications'; import { useBusterNotifications } from '@/context/BusterNotifications';
import { useMemoizedFn } from '@/hooks'; import { useMemoizedFn } from '@/hooks';
@ -19,6 +19,7 @@ export const ChatUserMessage: React.FC<{
isCompletedStream: boolean; isCompletedStream: boolean;
requestMessage: NonNullable<BusterChatMessageRequest>; requestMessage: NonNullable<BusterChatMessageRequest>;
}> = React.memo(({ messageId, chatId, isCompletedStream, requestMessage }) => { }> = React.memo(({ messageId, chatId, isCompletedStream, requestMessage }) => {
const { openSuccessMessage } = useBusterNotifications();
const [isTooltipOpen, setIsTooltipOpen] = useState(false); const [isTooltipOpen, setIsTooltipOpen] = useState(false);
const [isEditing, setIsEditing] = useState(false); const [isEditing, setIsEditing] = useState(false);
@ -29,6 +30,18 @@ export const ChatUserMessage: React.FC<{
setIsTooltipOpen(false); setIsTooltipOpen(false);
}); });
const handleCopy = useMemoizedFn((e?: React.ClipboardEvent) => {
// Prevent default copy behavior
//I do not know why this is needed, but it is...
if (e) {
e.preventDefault();
e.clipboardData.setData('text/plain', request);
} else {
navigator.clipboard.writeText(request);
}
openSuccessMessage('Copied to clipboard');
});
return ( return (
<MessageContainer <MessageContainer
senderName={sender_name} senderName={sender_name}
@ -45,12 +58,17 @@ export const ChatUserMessage: React.FC<{
/> />
) : ( ) : (
<> <>
<Paragraph className="whitespace-pre-wrap">{request}</Paragraph> <div>
<Paragraph className="break-words whitespace-normal" onCopy={handleCopy}>
{request}
</Paragraph>
</div>
{isCompletedStream && ( {isCompletedStream && (
<RequestMessageTooltip <RequestMessageTooltip
isTooltipOpen={isTooltipOpen} isTooltipOpen={isTooltipOpen}
requestMessage={requestMessage} requestMessage={requestMessage}
setIsEditing={setIsEditing} setIsEditing={setIsEditing}
onCopy={handleCopy}
/> />
)} )}
</> </>
@ -65,14 +83,10 @@ const RequestMessageTooltip: React.FC<{
isTooltipOpen: boolean; isTooltipOpen: boolean;
requestMessage: NonNullable<BusterChatMessageRequest>; requestMessage: NonNullable<BusterChatMessageRequest>;
setIsEditing: (isEditing: boolean) => void; setIsEditing: (isEditing: boolean) => void;
}> = React.memo(({ isTooltipOpen, requestMessage, setIsEditing }) => { onCopy: () => void;
}> = React.memo(({ isTooltipOpen, requestMessage, setIsEditing, onCopy }) => {
const { openSuccessMessage } = useBusterNotifications(); const { openSuccessMessage } = useBusterNotifications();
const onCopy = useMemoizedFn(() => {
navigator.clipboard.writeText(requestMessage.request);
openSuccessMessage('Copied to clipboard');
});
const onEdit = useMemoizedFn(() => { const onEdit = useMemoizedFn(() => {
setIsEditing(true); setIsEditing(true);
}); });
@ -80,7 +94,7 @@ const RequestMessageTooltip: React.FC<{
return ( return (
<div <div
className={cn( className={cn(
'absolute right-1 -bottom-0 translate-y-full transform', 'absolute top-0 right-1 -translate-y-1 transform',
'bg-background z-50 rounded border shadow', 'bg-background z-50 rounded border shadow',
'transition-all duration-200', 'transition-all duration-200',
isTooltipOpen ? 'scale-100 opacity-100' : 'scale-95 opacity-0' isTooltipOpen ? 'scale-100 opacity-100' : 'scale-95 opacity-0'

View File

@ -7,8 +7,9 @@ import { BusterChatResponseMessage_file } from '@/api/asset_interfaces/chat';
import { useAppLayoutContextSelector } from '@/context/BusterAppLayout'; import { useAppLayoutContextSelector } from '@/context/BusterAppLayout';
import { useGetFileLink } from '@/context/Assets/useGetFileLink'; import { useGetFileLink } from '@/context/Assets/useGetFileLink';
import { useChatLayoutContextSelector } from '../ChatLayoutContext'; import { useChatLayoutContextSelector } from '../ChatLayoutContext';
import { usePrevious } from '@/hooks'; import { useMount, usePrevious } from '@/hooks';
import { useGetInitialChatFile } from './useGetInitialChatFile'; import { useGetInitialChatFile } from './useGetInitialChatFile';
import { BusterRoutes } from '@/routes';
export const useAutoChangeLayout = ({ export const useAutoChangeLayout = ({
lastMessageId, lastMessageId,
@ -44,7 +45,19 @@ export const useAutoChangeLayout = ({
const hasReasoning = !!reasoningMessagesLength; const hasReasoning = !!reasoningMessagesLength;
useMount(() => {
console.log('MOUNTED?');
});
useEffect(() => { useEffect(() => {
console.log({
isCompletedStream,
hasReasoning,
chatId,
previousLastMessageId: previousLastMessageId.current,
lastMessageId,
previousIsCompletedStream
});
//this will trigger when the chat is streaming and is has not completed yet (new chat) //this will trigger when the chat is streaming and is has not completed yet (new chat)
if ( if (
!isCompletedStream && !isCompletedStream &&
@ -53,12 +66,18 @@ export const useAutoChangeLayout = ({
chatId chatId
) { ) {
previousLastMessageId.current = lastMessageId; previousLastMessageId.current = lastMessageId;
onSetSelectedFile({ id: lastMessageId, type: 'reasoning', versionNumber: undefined }); // onSetSelectedFile({ id: lastMessageId, type: 'reasoning', versionNumber: undefined });
onChangePage({
route: BusterRoutes.APP_CHAT_ID_REASONING_ID,
chatId,
messageId: lastMessageId
});
console.log('FLIP TO REASONING!', lastMessageId);
} }
//this will when the chat is completed and it WAS streaming //this will when the chat is completed and it WAS streaming
else if (isCompletedStream && previousIsCompletedStream === false) { else if (isCompletedStream && previousIsCompletedStream === false) {
// console.log('SELECT STREAMING FILE');
const chatMessage = getChatMessageMemoized(lastMessageId); const chatMessage = getChatMessageMemoized(lastMessageId);
const lastFileId = findLast(chatMessage?.response_message_ids, (id) => { const lastFileId = findLast(chatMessage?.response_message_ids, (id) => {
const responseMessage = chatMessage?.response_messages[id]; const responseMessage = chatMessage?.response_messages[id];
@ -68,7 +87,6 @@ export const useAutoChangeLayout = ({
| BusterChatResponseMessage_file | BusterChatResponseMessage_file
| undefined; | undefined;
//this will trigger when the chat was streaming (new chat)
if (lastFileId && lastFile) { if (lastFileId && lastFile) {
const { link, isSelected, selectedVersionNumber } = getFileLinkMeta({ const { link, isSelected, selectedVersionNumber } = getFileLinkMeta({
fileId: lastFileId, fileId: lastFileId,
@ -78,17 +96,17 @@ export const useAutoChangeLayout = ({
useVersionHistoryMode: !chatId useVersionHistoryMode: !chatId
}); });
if ( // if (
!isSelected && // !isSelected &&
selectedVersionNumber !== lastFile.version_number && // selectedVersionNumber !== lastFile.version_number &&
selectedFileId !== lastFileId // selectedFileId !== lastFileId
) { // ) {
onSetSelectedFile({ // onSetSelectedFile({
id: lastFileId, // id: lastFileId,
type: lastFile.file_type, // type: lastFile.file_type,
versionNumber: selectedVersionNumber // versionNumber: selectedVersionNumber
}); // });
} // }
if (link) { if (link) {
onChangePage(link); onChangePage(link);
@ -98,6 +116,7 @@ export const useAutoChangeLayout = ({
} }
//this will trigger on a page refresh and the chat is completed //this will trigger on a page refresh and the chat is completed
else if (isCompletedStream && chatId) { else if (isCompletedStream && chatId) {
console.log('SELECT INITIAL CHAT FILE - PAGE LOAD');
const isChatOnlyMode = !metricId && !dashboardId && !messageId; const isChatOnlyMode = !metricId && !dashboardId && !messageId;
if (isChatOnlyMode) { if (isChatOnlyMode) {
return; return;
@ -117,5 +136,5 @@ export const useAutoChangeLayout = ({
onChangePage(href); onChangePage(href);
} }
} }
}, [isCompletedStream, hasReasoning, lastMessageId]); }, [isCompletedStream, hasReasoning, chatId, lastMessageId]);
}; };