@@ -21,8 +21,8 @@ import { InferenceMessage } from "src/types/Chat";
2121import { BaseMessageEntry } from "../Messages/BaseMessageEntry" ;
2222import { BaseMessageEmojiButton } from "../Messages/MessageEmojiButton" ;
2323import { MessageInlineEmojiRow } from "../Messages/MessageInlineEmojiRow" ;
24- import { WorkParametersDisplay } from "./WorkParameters" ;
2524import { EncourageMessage } from "./EncourageMessage" ;
25+ import { WorkParametersDisplay } from "./WorkParameters" ;
2626
2727export type EditPromptParams = { parentId : string ; chatId : string ; content : string } ;
2828
@@ -36,6 +36,8 @@ export type ChatMessageEntryProps = {
3636 canRetry ?: boolean ;
3737 id ?: string ;
3838 "data-id" ?: string ;
39+ showEncourageMessage : boolean ;
40+ onEncourageMessageClose : ( ) => void ;
3941} ;
4042
4143export const ChatMessageEntry = memo ( function ChatMessageEntry ( {
@@ -46,6 +48,8 @@ export const ChatMessageEntry = memo(function ChatMessageEntry({
4648 pagingSlot,
4749 onEditPromtp,
4850 canRetry,
51+ showEncourageMessage,
52+ onEncourageMessageClose,
4953 ...props
5054} : ChatMessageEntryProps ) {
5155 const { t } = useTranslation ( "common" ) ;
@@ -114,74 +118,82 @@ export const ChatMessageEntry = memo(function ChatMessageEntry({
114118 const { onCopy, hasCopied } = useClipboard ( message . content ) ;
115119
116120 return (
117- < PendingMessageEntry
118- ref = { ref }
119- { ...props }
120- isAssistant = { isAssistant }
121- usedPlugin = { used_plugin }
122- content = { isEditing ? "" : content ! }
123- >
124- { ! isAssistant && parentId !== null && (
125- < Box position = "absolute" top = { { base : "4" , md : 0 } } style = { { insetInlineEnd : `0.5rem` } } >
126- { isEditing ? (
127- < MessageInlineEmojiRow spacing = "0" >
128- < BaseMessageEmojiButton emoji = { Check } onClick = { handleEditSubmit } > </ BaseMessageEmojiButton >
129- < BaseMessageEmojiButton emoji = { X } onClick = { setIsEditing . off } > </ BaseMessageEmojiButton >
130- </ MessageInlineEmojiRow >
131- ) : (
132- < BaseMessageEmojiButton emoji = { Edit } onClick = { setIsEditing . on } > </ BaseMessageEmojiButton >
133- ) }
134- </ Box >
135- ) }
136- { isEditing && (
137- < Box mx = { { md : "-15px" } } mt = { { md : 2 } } >
138- < Textarea
139- defaultValue = { content || "" }
140- ref = { inputRef }
141- onKeyDown = { handleKeydown }
142- bg = "gray.100"
143- borderRadius = "xl"
144- _dark = { {
145- bg : "gray.800" ,
146- } }
147- autoFocus
148- > </ Textarea >
149- </ Box >
150- ) }
151- { ! isEditing && (
152- < Flex justifyContent = { pagingSlot ? "space-between" : "end" } mt = "1" >
153- { pagingSlot }
154- { isAssistant && (
155- < MessageInlineEmojiRow >
156- { ( state === "pending" || state === "in_progress" ) && (
157- < CircularProgress isIndeterminate size = "20px" title = { state } />
158- ) }
159- { ( state === "aborted_by_worker" || state === "cancelled" || state === "timeout" ) && (
160- < >
161- < Icon as = { XCircle } color = "red" />
162- < Text color = "red" > { `Error: ${ state } ` } </ Text >
163- { onRetry && ! isSending && < Button onClick = { handleRetry } > { t ( "retry" ) } </ Button > }
164- </ >
165- ) }
166- { state === "complete" && (
167- < >
168- < EncourageMessage />
169- { canRetry && < BaseMessageEmojiButton emoji = { RotateCcw } onClick = { handleRetry } label = { t ( "retry" ) } /> }
170- { ! hasCopied ? (
171- < BaseMessageEmojiButton emoji = { Copy } onClick = { onCopy } label = { t ( "copy" ) } />
172- ) : (
173- < BaseMessageEmojiButton emoji = { Check } />
174- ) }
175- < BaseMessageEmojiButton emoji = { ThumbsUp } checked = { score === 1 } onClick = { handleThumbsUp } />
176- < BaseMessageEmojiButton emoji = { ThumbsDown } checked = { score === - 1 } onClick = { handleThumbsDown } />
177- </ >
178- ) }
179- </ MessageInlineEmojiRow >
180- ) }
181- </ Flex >
121+ < >
122+ < PendingMessageEntry
123+ ref = { ref }
124+ { ...props }
125+ isAssistant = { isAssistant }
126+ usedPlugin = { used_plugin }
127+ content = { isEditing ? "" : content ! }
128+ >
129+ { ! isAssistant && parentId !== null && (
130+ < Box position = "absolute" top = { { base : "4" , md : 0 } } style = { { insetInlineEnd : `0.5rem` } } >
131+ { isEditing ? (
132+ < MessageInlineEmojiRow spacing = "0" >
133+ < BaseMessageEmojiButton emoji = { Check } onClick = { handleEditSubmit } > </ BaseMessageEmojiButton >
134+ < BaseMessageEmojiButton emoji = { X } onClick = { setIsEditing . off } > </ BaseMessageEmojiButton >
135+ </ MessageInlineEmojiRow >
136+ ) : (
137+ < BaseMessageEmojiButton emoji = { Edit } onClick = { setIsEditing . on } > </ BaseMessageEmojiButton >
138+ ) }
139+ </ Box >
140+ ) }
141+ { isEditing && (
142+ < Box mx = { { md : "-15px" } } mt = { { md : 2 } } >
143+ < Textarea
144+ defaultValue = { content || "" }
145+ ref = { inputRef }
146+ onKeyDown = { handleKeydown }
147+ bg = "gray.100"
148+ borderRadius = "xl"
149+ _dark = { {
150+ bg : "gray.800" ,
151+ } }
152+ autoFocus
153+ > </ Textarea >
154+ </ Box >
155+ ) }
156+ { ! isEditing && (
157+ < Flex justifyContent = { pagingSlot ? "space-between" : "end" } mt = "1" >
158+ { pagingSlot }
159+ { isAssistant && (
160+ < MessageInlineEmojiRow >
161+ { ( state === "pending" || state === "in_progress" ) && (
162+ < CircularProgress isIndeterminate size = "20px" title = { state } />
163+ ) }
164+ { ( state === "aborted_by_worker" || state === "cancelled" || state === "timeout" ) && (
165+ < >
166+ < Icon as = { XCircle } color = "red" />
167+ < Text color = "red" > { `Error: ${ state } ` } </ Text >
168+ { onRetry && ! isSending && < Button onClick = { handleRetry } > { t ( "retry" ) } </ Button > }
169+ </ >
170+ ) }
171+ { state === "complete" && (
172+ < >
173+ { canRetry && < BaseMessageEmojiButton emoji = { RotateCcw } onClick = { handleRetry } label = { t ( "retry" ) } /> }
174+ { ! hasCopied ? (
175+ < BaseMessageEmojiButton emoji = { Copy } onClick = { onCopy } label = { t ( "copy" ) } />
176+ ) : (
177+ < BaseMessageEmojiButton emoji = { Check } />
178+ ) }
179+ < BaseMessageEmojiButton emoji = { ThumbsUp } checked = { score === 1 } onClick = { handleThumbsUp } />
180+ < BaseMessageEmojiButton emoji = { ThumbsDown } checked = { score === - 1 } onClick = { handleThumbsDown } />
181+ </ >
182+ ) }
183+ </ MessageInlineEmojiRow >
184+ ) }
185+ </ Flex >
186+ ) }
187+ { work_parameters && < WorkParametersDisplay parameters = { work_parameters } /> }
188+ </ PendingMessageEntry >
189+ { state === "complete" && isAssistant && showEncourageMessage && (
190+ < EncourageMessage
191+ onThumbsUp = { handleThumbsUp }
192+ onThumbsDown = { handleThumbsDown }
193+ onClose = { onEncourageMessageClose }
194+ />
182195 ) }
183- { work_parameters && < WorkParametersDisplay parameters = { work_parameters } /> }
184- </ PendingMessageEntry >
196+ </ >
185197 ) ;
186198} ) ;
187199
@@ -194,7 +206,7 @@ type PendingMessageEntryProps = {
194206 usedPlugin ?: object ;
195207} ;
196208
197- const messageEntryContainerProps = {
209+ export const messageEntryContainerProps = {
198210 maxWidth : { base : "3xl" , "2xl" : "4xl" } ,
199211 w : "full" ,
200212} ;
0 commit comments