[8.15] [Security solution] Fix regenerate button with LangGraph (#188249) (#188276)

# Backport

This will backport the following commits from `main` to `8.15`:
- [[Security solution] Fix regenerate button with LangGraph
(#188249)](https://github.com/elastic/kibana/pull/188249)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Steph
Milovic","email":"stephanie.milovic@elastic.co"},"sourceCommit":{"committedDate":"2024-07-13T14:16:12Z","message":"[Security
solution] Fix regenerate button with LangGraph
(#188249)","sha":"f72a321a9c80b8c9ccb30f30a5870200989e3ae1","branchLabelMapping":{"^v8.16.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:
SecuritySolution","Team:Security Generative
AI","v8.15.0","v8.16.0"],"title":"[Security solution] Fix regenerate
button with
LangGraph","number":188249,"url":"https://github.com/elastic/kibana/pull/188249","mergeCommit":{"message":"[Security
solution] Fix regenerate button with LangGraph
(#188249)","sha":"f72a321a9c80b8c9ccb30f30a5870200989e3ae1"}},"sourceBranch":"main","suggestedTargetBranches":["8.15"],"targetPullRequestStates":[{"branch":"8.15","label":"v8.15.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.16.0","branchLabelMappingKey":"^v8.16.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/188249","number":188249,"mergeCommit":{"message":"[Security
solution] Fix regenerate button with LangGraph
(#188249)","sha":"f72a321a9c80b8c9ccb30f30a5870200989e3ae1"}}]}]
BACKPORT-->

Co-authored-by: Steph Milovic <stephanie.milovic@elastic.co>
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
This commit is contained in:
Kibana Machine 2024-07-13 20:14:27 +02:00 committed by GitHub
parent 38677570cb
commit 8d6510f30e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -49,6 +49,19 @@ export const persistConversationChanges = async ({
});
}
const lastMessage = state.conversation.messages
? state.conversation.messages[state.conversation.messages.length - 1]
: undefined;
if (lastMessage && lastMessage.content === state.input && lastMessage.role === 'user') {
// this is a regenerated message, do not update the conversation again
const langChainMessages = getLangChainMessages(state.conversation.messages ?? []);
const messages = langChainMessages.slice(0, -1); // all but the last message
return {
conversation: state.conversation,
messages,
};
}
const updatedConversation = await conversationsDataClient?.appendConversationMessages({
existingConversation: conversation ? conversation : state.conversation,
messages: [