@@ -21,8 +21,8 @@ import { InferenceMessage } from "src/types/Chat";
21
21
import { BaseMessageEntry } from "../Messages/BaseMessageEntry" ;
22
22
import { BaseMessageEmojiButton } from "../Messages/MessageEmojiButton" ;
23
23
import { MessageInlineEmojiRow } from "../Messages/MessageInlineEmojiRow" ;
24
- import { WorkParametersDisplay } from "./WorkParameters" ;
25
24
import { EncourageMessage } from "./EncourageMessage" ;
25
+ import { WorkParametersDisplay } from "./WorkParameters" ;
26
26
27
27
export type EditPromptParams = { parentId : string ; chatId : string ; content : string } ;
28
28
@@ -36,6 +36,8 @@ export type ChatMessageEntryProps = {
36
36
canRetry ?: boolean ;
37
37
id ?: string ;
38
38
"data-id" ?: string ;
39
+ showEncourageMessage : boolean ;
40
+ onEncourageMessageClose : ( ) => void ;
39
41
} ;
40
42
41
43
export const ChatMessageEntry = memo ( function ChatMessageEntry ( {
@@ -46,6 +48,8 @@ export const ChatMessageEntry = memo(function ChatMessageEntry({
46
48
pagingSlot,
47
49
onEditPromtp,
48
50
canRetry,
51
+ showEncourageMessage,
52
+ onEncourageMessageClose,
49
53
...props
50
54
} : ChatMessageEntryProps ) {
51
55
const { t } = useTranslation ( "common" ) ;
@@ -114,74 +118,82 @@ export const ChatMessageEntry = memo(function ChatMessageEntry({
114
118
const { onCopy, hasCopied } = useClipboard ( message . content ) ;
115
119
116
120
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
+ />
182
195
) }
183
- { work_parameters && < WorkParametersDisplay parameters = { work_parameters } /> }
184
- </ PendingMessageEntry >
196
+ </ >
185
197
) ;
186
198
} ) ;
187
199
@@ -194,7 +206,7 @@ type PendingMessageEntryProps = {
194
206
usedPlugin ?: object ;
195
207
} ;
196
208
197
- const messageEntryContainerProps = {
209
+ export const messageEntryContainerProps = {
198
210
maxWidth : { base : "3xl" , "2xl" : "4xl" } ,
199
211
w : "full" ,
200
212
} ;
0 commit comments