feat: add save and send functionality for user message
Adds a "Save" button to the edit message form in Playground, allowing users to save changes without immediately submitting them. This also introduces a new `isSend` flag to the `onEditFormSubmit` prop, enabling developers to control whether a message should be sent immediately or saved for later submission. This enhances flexibility and user control during the message editing process.
This commit is contained in:
@@ -910,12 +910,14 @@ export const useMessageOption = () => {
|
||||
const editMessage = async (
|
||||
index: number,
|
||||
message: string,
|
||||
isHuman: boolean
|
||||
isHuman: boolean,
|
||||
isSend: boolean
|
||||
) => {
|
||||
let newMessages = messages
|
||||
let newHistory = history
|
||||
|
||||
if (isHuman) {
|
||||
// if human message and send then only trigger the submit
|
||||
if (isHuman && isSend) {
|
||||
const isOk = validateBeforeSubmit()
|
||||
|
||||
if (!isOk) {
|
||||
@@ -939,13 +941,13 @@ export const useMessageOption = () => {
|
||||
memory: previousHistory,
|
||||
controller: abortController
|
||||
})
|
||||
} else {
|
||||
newMessages[index].message = message
|
||||
setMessages(newMessages)
|
||||
newHistory[index].content = message
|
||||
setHistory(newHistory)
|
||||
await updateMessageByIndex(historyId, index, message)
|
||||
return
|
||||
}
|
||||
newMessages[index].message = message
|
||||
setMessages(newMessages)
|
||||
newHistory[index].content = message
|
||||
setHistory(newHistory)
|
||||
await updateMessageByIndex(historyId, index, message)
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user