diff --git a/backend/open_webui/utils/middleware.py b/backend/open_webui/utils/middleware.py index 878d5b3f2..e96faf3c1 100644 --- a/backend/open_webui/utils/middleware.py +++ b/backend/open_webui/utils/middleware.py @@ -444,7 +444,7 @@ def serialize_output(output: list) -> str: files = result_item.get('files') embeds = result_item.get('embeds', '') - content += f'
\nTool Executed\n
\n' + content += f'
\nTool Executed\n{html.escape(json.dumps(result_text, ensure_ascii=False))}\n
\n' else: content += f'
\nExecuting...\n
\n' diff --git a/src/lib/components/chat/Messages/Markdown/MarkdownTokens.svelte b/src/lib/components/chat/Messages/Markdown/MarkdownTokens.svelte index 961b73192..da4deaaa1 100644 --- a/src/lib/components/chat/Messages/Markdown/MarkdownTokens.svelte +++ b/src/lib/components/chat/Messages/Markdown/MarkdownTokens.svelte @@ -380,6 +380,7 @@ diff --git a/src/lib/components/common/ToolCallDisplay.svelte b/src/lib/components/common/ToolCallDisplay.svelte index 1bead4b4d..a21626ede 100644 --- a/src/lib/components/common/ToolCallDisplay.svelte +++ b/src/lib/components/common/ToolCallDisplay.svelte @@ -77,7 +77,9 @@ } $: args = decode(attributes?.arguments ?? ''); - $: result = decode(attributes?.result ?? ''); + export let resultContent: string = ''; + + $: result = resultContent || decode(attributes?.result ?? ''); $: files = parseJSONString(decode(attributes?.files ?? '')); $: embeds = parseJSONString(decode(attributes?.embeds ?? '')); $: isDone = attributes?.done === 'true'; diff --git a/src/lib/utils/index.ts b/src/lib/utils/index.ts index 68ac38e56..ecaeefab0 100644 --- a/src/lib/utils/index.ts +++ b/src/lib/utils/index.ts @@ -923,8 +923,19 @@ export const processDetails = (content) => { attributes[attributeMatch[1]] = attributeMatch[2]; } + // New format: result in body content; Old format: result in attribute + let resultText = ''; if (attributes.result) { - content = content.replace(match, unescapeHtml(attributes.result)); + resultText = unescapeHtml(attributes.result); + } else { + // Extract body content (strip ...) + const bodyMatch = match.match(/[\s\S]*?<\/summary>\s*([\s\S]*?)\s*<\/details>/i); + if (bodyMatch && bodyMatch[1].trim()) { + resultText = unescapeHtml(bodyMatch[1].trim()); + } + } + if (resultText) { + content = content.replace(match, resultText); } } } diff --git a/src/lib/utils/marked/extension.ts b/src/lib/utils/marked/extension.ts index eec17adbd..13f9f7cdc 100644 --- a/src/lib/utils/marked/extension.ts +++ b/src/lib/utils/marked/extension.ts @@ -60,7 +60,7 @@ function detailsTokenizer(src: string) { } function detailsStart(src: string) { - return src.match(/^
/) ? 0 : -1; + return src.match(/^]/) ? 0 : -1; } function detailsRenderer(token: any) {