fix: a reply rewritten by an action button still shows its old text (#32172)

Pressing an action button whose function rewrites the reply, as the action docs describe, stored the new text with the chat but the chat kept showing the old reply, right away and after a reload. The reply now shows the new text, and its thinking and tool call sections stay visible. The action gets the reply as one text, so when the reply had text both before and after a tool call, all of it is replaced by the new text, shown after the tool calls.

Fixes #32023
This commit is contained in:
Classic298 2026-10-10 17:48:46 +02:00 • committed by GitHub
parent 1579af28a0
commit 200036f6a6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 28 additions and 1 deletions

View file

@ -71,7 +71,11 @@
import { AudioQueue } from '$lib/utils/audio';
import { RealtimeCall, getBridgeTurnState, type BridgeSubmission } from '$lib/utils/realtime';
import { createTemporaryChatId, isTemporaryChatId } from '$lib/utils/chatId';
import { applyResponseStreamEvent, getOutputText } from './Messages/structuredOutput';
import {
applyResponseStreamEvent,
getOutputText,
setOutputText
} from './Messages/structuredOutput';
import {
archiveChatById,
@ -2999,6 +3003,9 @@
...(history.messages[message.id].content !== message.content
? { originalContent: history.messages[message.id].content }
: {}),
...(typeof message.content === 'string' && history.messages[message.id].output?.length
? { output: setOutputText(history.messages[message.id].output, message.content) }
: {}),
...message
};
}

View file

@ -710,3 +710,23 @@ export function replaceOutputMessageText(
return replaced ? nextOutput : output;
}
export function setOutputText(output: OutputItem[], text: string): OutputItem[] {
if (text === getOutputText(output)) {
return output;
}
const lastMessage = output.filter((item) => item?.type === 'message').at(-1);
if (!lastMessage) {
return [
...output,
{ type: 'message', role: 'assistant', content: [{ type: 'output_text', text }] }
];
}
return output.map((item) =>
item?.type === 'message'
? { ...item, content: item === lastMessage ? [{ type: 'output_text', text }] : [] }
: item
);
}