From 200036f6a6c84e9b9f3b5cdbe505108b760ebc44 Mon Sep 17 00:00:00 2001 From: Classic298 <27028174+Classic298@users.noreply.github.com> Date: Sat, 10 Oct 2026 17:48:46 +0200 Subject: [PATCH] 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 --- src/lib/components/chat/Chat.svelte | 9 ++++++++- .../chat/Messages/structuredOutput.ts | 20 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/lib/components/chat/Chat.svelte b/src/lib/components/chat/Chat.svelte index 046d2a576b..34a037fb6a 100644 --- a/src/lib/components/chat/Chat.svelte +++ b/src/lib/components/chat/Chat.svelte @@ -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 }; } diff --git a/src/lib/components/chat/Messages/structuredOutput.ts b/src/lib/components/chat/Messages/structuredOutput.ts index b59587c374..e8b86964fd 100644 --- a/src/lib/components/chat/Messages/structuredOutput.ts +++ b/src/lib/components/chat/Messages/structuredOutput.ts @@ -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 + ); +}