From 4b15b0e6a6f3eeec9ef9746f7c0da01318c49939 Mon Sep 17 00:00:00 2001 From: Yunlu Wen Date: Mon, 15 Jun 2026 15:37:24 +0800 Subject: [PATCH] fix: preserve inline image for chatflow messages (#37455) --- api/core/app/apps/advanced_chat/generate_task_pipeline.py | 5 ----- .../apps/advanced_chat/test_generate_task_pipeline_core.py | 7 ++++--- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/api/core/app/apps/advanced_chat/generate_task_pipeline.py b/api/core/app/apps/advanced_chat/generate_task_pipeline.py index 6f8117ee59..d8ca19b5fc 100644 --- a/api/core/app/apps/advanced_chat/generate_task_pipeline.py +++ b/api/core/app/apps/advanced_chat/generate_task_pipeline.py @@ -1,6 +1,5 @@ import json import logging -import re import time from collections.abc import Callable, Generator, Mapping from contextlib import contextmanager @@ -1010,11 +1009,7 @@ class AdvancedChatAppGenerateTaskPipeline(GraphRuntimeStateSupport): if message.status == MessageStatus.PAUSED: message.status = MessageStatus.NORMAL - # If there are assistant files, remove markdown image links from answer answer_text = self._task_state.answer - if self._recorded_files: - # Remove markdown image links since we're storing files separately - answer_text = re.sub(r"!\[.*?\]\(.*?\)", "", answer_text).strip() message.answer = answer_text message.updated_at = naive_utc_now() diff --git a/api/tests/unit_tests/core/app/apps/advanced_chat/test_generate_task_pipeline_core.py b/api/tests/unit_tests/core/app/apps/advanced_chat/test_generate_task_pipeline_core.py index 9726c939e9..b75f6d4494 100644 --- a/api/tests/unit_tests/core/app/apps/advanced_chat/test_generate_task_pipeline_core.py +++ b/api/tests/unit_tests/core/app/apps/advanced_chat/test_generate_task_pipeline_core.py @@ -562,7 +562,7 @@ class TestAdvancedChatGenerateTaskPipeline: assert list(pipeline._handle_human_input_form_timeout_event(timeout_event)) == ["timeout"] assert persisted == ["saved"] - def test_save_message_strips_markdown_and_sets_usage(self): + def test_save_message_preserves_full_answer_and_sets_usage(self): pipeline = _make_pipeline() pipeline._recorded_files = [ { @@ -572,7 +572,8 @@ class TestAdvancedChatGenerateTaskPipeline: "related_id": "file-id", } ] - pipeline._task_state.answer = "![img](url) hello" + # The answer is stored verbatim; markdown image links are never stripped. + pipeline._task_state.answer = "![img](http://example.com/file.png) hello ![inline](http://llm.com/img.jpg)" pipeline._task_state.is_streaming_response = True pipeline._task_state.first_token_time = pipeline._base_task_pipeline.start_at + 0.1 pipeline._task_state.last_token_time = pipeline._base_task_pipeline.start_at + 0.2 @@ -614,7 +615,7 @@ class TestAdvancedChatGenerateTaskPipeline: pipeline._save_message(session=_Session(), graph_runtime_state=graph_runtime_state) assert message.status == MessageStatus.NORMAL - assert message.answer == "hello" + assert message.answer == "![img](http://example.com/file.png) hello ![inline](http://llm.com/img.jpg)" assert message.message_metadata def test_handle_stop_event_saves_message_for_moderation(self, monkeypatch: pytest.MonkeyPatch):