From 9f0dd1f1527b443a8df4cfcefd3f2795c877fd0a Mon Sep 17 00:00:00 2001 From: Nico Albanese Date: Wed, 19 Feb 2025 12:26:41 -0500 Subject: [PATCH] refactor to message parts --- components/message.tsx | 161 ++++++++++++++++++++++------------------- 1 file changed, 85 insertions(+), 76 deletions(-) diff --git a/components/message.tsx b/components/message.tsx index 1ebe1b933..10916e01c 100644 --- a/components/message.tsx +++ b/components/message.tsx @@ -3,14 +3,12 @@ import type { ChatRequestOptions, Message } from 'ai'; import cx from 'classnames'; import { AnimatePresence, motion } from 'framer-motion'; -import { memo, useMemo, useState } from 'react'; +import { memo, useState } from 'react'; import type { Vote } from '@/lib/db/schema'; import { DocumentToolCall, DocumentToolResult } from './document'; import { - ChevronDownIcon, - LoaderIcon, PencilEditIcon, SparklesIcon, } from './icons'; @@ -90,89 +88,99 @@ const PurePreviewMessage = ({ )} - {message.reasoning && ( - - )} - - {(message.content || message.reasoning) && mode === 'view' && ( -
- {message.role === 'user' && !isReadonly && ( - - - - - Edit message - - )} + {message.role === "user" && !isReadonly && ( + + +
- )} - - {message.content && mode === 'edit' && ( -
-
+ return; + } - -
- )} + setMode("edit"); + }} + > + + + + Edit message + + )} - {message.toolInvocations && message.toolInvocations.length > 0 && ( -
- {message.toolInvocations.map((toolInvocation) => { - const { toolName, toolCallId, state, args } = toolInvocation; +
+ {p.text} +
+
+ ); + } + if (mode === "edit") { + return ( +
+
- if (state === 'result') { - const { result } = toolInvocation; + +
+ ); + } + return null; + case "reasoning": + return ( + + ); + case "tool-invocation": + const { toolName, toolCallId, state, args } = + p.toolInvocation; + if (state === "result") { + const { result } = p.toolInvocation; return (
- {toolName === 'getWeather' ? ( + {toolName === "getWeather" ? ( - ) : toolName === 'createDocument' ? ( + ) : toolName === "createDocument" ? ( - ) : toolName === 'updateDocument' ? ( + ) : toolName === "updateDocument" ? ( - ) : toolName === 'requestSuggestions' ? ( + ) : toolName === "requestSuggestions" ? ( - {toolName === 'getWeather' ? ( + {toolName === "getWeather" ? ( - ) : toolName === 'createDocument' ? ( + ) : toolName === "createDocument" ? ( - ) : toolName === 'updateDocument' ? ( + ) : toolName === "updateDocument" ? ( - ) : toolName === 'requestSuggestions' ? ( + ) : toolName === "requestSuggestions" ? ( ); - })} -
- )} + default: + return null; + } + })} {!isReadonly && (