ui Prevent tool messages from incorrectly appending to other conversations (#25177)
* fix: Prevent tool messages from incorrectly appending to other conversations * ui: prevent agentic loop from poisoning another conv's currNode * ui: make editedContent a so background recompute does not wipe in-progress edits --------- Co-authored-by: Pascal <admin@serveurperso.com>
This commit is contained in:
co-authored by
Pascal
parent
7af4279f45
commit
9d88e7cedd
@@ -43,7 +43,7 @@
|
|||||||
assistantMessages: number;
|
assistantMessages: number;
|
||||||
messageTypes: string[];
|
messageTypes: string[];
|
||||||
} | null>(null);
|
} | null>(null);
|
||||||
let editedContent = $derived(message.content);
|
let editedContent = $state(message.content);
|
||||||
|
|
||||||
let rawEditContent = $derived.by(() => {
|
let rawEditContent = $derived.by(() => {
|
||||||
if (message.role !== MessageRole.ASSISTANT) return undefined;
|
if (message.role !== MessageRole.ASSISTANT) return undefined;
|
||||||
|
|||||||
@@ -1083,6 +1083,11 @@ class ChatStore {
|
|||||||
let resolvedModel: string | null = null;
|
let resolvedModel: string | null = null;
|
||||||
let modelPersisted = false;
|
let modelPersisted = false;
|
||||||
const convId = assistantMessage.convId;
|
const convId = assistantMessage.convId;
|
||||||
|
// Tracks the last message created in this flow. Used as the parent for the next
|
||||||
|
// turn's assistant message so createAssistantMessage does not have to read
|
||||||
|
// conversationsStore.activeMessages, which may belong to a different conversation
|
||||||
|
// after the user navigates while the loop is still running.
|
||||||
|
let lastCreatedInFlow = currentMessageId;
|
||||||
// freeze the POST identity from t0 so a stop cancels with the exact session key,
|
// freeze the POST identity from t0 so a stop cancels with the exact session key,
|
||||||
// never a stale or empty model resolved later
|
// never a stale or empty model resolved later
|
||||||
this.setChatStreaming(convId, streamedContent, currentMessageId, effectiveModel);
|
this.setChatStreaming(convId, streamedContent, currentMessageId, effectiveModel);
|
||||||
@@ -1208,8 +1213,15 @@ class ChatStore {
|
|||||||
};
|
};
|
||||||
if (timings) uiUpdate.timings = timings;
|
if (timings) uiUpdate.timings = timings;
|
||||||
if (resolvedModel) uiUpdate.model = resolvedModel;
|
if (resolvedModel) uiUpdate.model = resolvedModel;
|
||||||
conversationsStore.updateMessageAtIndex(idx, uiUpdate);
|
// touch the active ui array and node pointer only when this conversation
|
||||||
await conversationsStore.updateCurrentNode(currentMessageId);
|
// is displayed; otherwise persist the node move straight to the db so a
|
||||||
|
// foreign conv's currNode stays untouched
|
||||||
|
if (conversationsStore.activeConversation?.id === convId) {
|
||||||
|
conversationsStore.updateMessageAtIndex(idx, uiUpdate);
|
||||||
|
await conversationsStore.updateCurrentNode(currentMessageId);
|
||||||
|
} else {
|
||||||
|
await DatabaseService.updateCurrentNode(convId, currentMessageId);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
createToolResultMessage: async (
|
createToolResultMessage: async (
|
||||||
toolCallId: string,
|
toolCallId: string,
|
||||||
@@ -1230,8 +1242,16 @@ class ChatStore {
|
|||||||
},
|
},
|
||||||
currentMessageId
|
currentMessageId
|
||||||
);
|
);
|
||||||
conversationsStore.addMessageToActive(msg);
|
// mirror into the active store and move the node pointer only when this
|
||||||
await conversationsStore.updateCurrentNode(msg.id);
|
// conversation is displayed; otherwise persist the node move straight to
|
||||||
|
// the db for the owning conv so a foreign conv's currNode stays untouched
|
||||||
|
if (conversationsStore.activeConversation?.id === convId) {
|
||||||
|
conversationsStore.addMessageToActive(msg);
|
||||||
|
await conversationsStore.updateCurrentNode(msg.id);
|
||||||
|
} else {
|
||||||
|
await DatabaseService.updateCurrentNode(convId, msg.id);
|
||||||
|
}
|
||||||
|
lastCreatedInFlow = msg.id;
|
||||||
return msg;
|
return msg;
|
||||||
},
|
},
|
||||||
createAssistantMessage: async () => {
|
createAssistantMessage: async () => {
|
||||||
@@ -1239,8 +1259,6 @@ class ChatStore {
|
|||||||
streamedContent = '';
|
streamedContent = '';
|
||||||
streamedReasoningContent = '';
|
streamedReasoningContent = '';
|
||||||
|
|
||||||
const lastMsg =
|
|
||||||
conversationsStore.activeMessages[conversationsStore.activeMessages.length - 1];
|
|
||||||
const msg = await DatabaseService.createMessageBranch(
|
const msg = await DatabaseService.createMessageBranch(
|
||||||
{
|
{
|
||||||
convId,
|
convId,
|
||||||
@@ -1252,10 +1270,13 @@ class ChatStore {
|
|||||||
children: [],
|
children: [],
|
||||||
model: resolvedModel
|
model: resolvedModel
|
||||||
},
|
},
|
||||||
lastMsg.id
|
lastCreatedInFlow
|
||||||
);
|
);
|
||||||
conversationsStore.addMessageToActive(msg);
|
if (conversationsStore.activeConversation?.id === convId) {
|
||||||
|
conversationsStore.addMessageToActive(msg);
|
||||||
|
}
|
||||||
currentMessageId = msg.id;
|
currentMessageId = msg.id;
|
||||||
|
lastCreatedInFlow = msg.id;
|
||||||
return msg;
|
return msg;
|
||||||
},
|
},
|
||||||
onFlowComplete: (finalTimings?: ChatMessageTimings) => {
|
onFlowComplete: (finalTimings?: ChatMessageTimings) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user