Skip to content

LLM inference in C/C++

C++ ggml

ui : fix MCP image attachments not displayed in tool block (#25789) (#28089)

nachobh85d5703a3b1b
diff --git a/tools/ui/src/lib/components/app/chat/ChatMessages/ChatMessageAgenticContent.svelte b/tools/ui/src/lib/components/app/chat/ChatMessages/ChatMessageAgenticContent.svelte
index 011d1fbebf..5137e261f8 100644
--- a/tools/ui/src/lib/components/app/chat/ChatMessages/ChatMessageAgenticContent.svelte
+++ b/tools/ui/src/lib/components/app/chat/ChatMessages/ChatMessageAgenticContent.svelte
@@ -194,7 +194,7 @@
/>
{:else if section.type === AgenticSectionType.TOOL_CALL || section.type === AgenticSectionType.TOOL_CALL_PENDING || section.type === AgenticSectionType.TOOL_CALL_STREAMING}
<ChatMessageToolCallBlock
- attachments={message?.extra}
+ attachments={section.toolResultExtras}
isExecuting={section.toolCallId !== undefined &&
section.toolCallId === currentlyExecutingToolCallId}
{isStreaming}
diff --git a/tools/ui/src/lib/constants/agentic.constants.ts b/tools/ui/src/lib/constants/agentic.constants.ts
index 33fb30f1bd..4b8463e1e3 100644
--- a/tools/ui/src/lib/constants/agentic.constants.ts
+++ b/tools/ui/src/lib/constants/agentic.constants.ts
@@ -2,8 +2,11 @@ import type { AgenticConfig } from '$lib/types/agentic';
export const ATTACHMENT_SAVED_REGEX = /\[Attachment saved: ([^\]]+)\]/;
-// JSON detection: trimmed content opens with an object or array literal.
-export const TOOL_RESULT_JSON_OPEN_REGEX = /^[[{]/;
+// JSON detection: an attachment placeholder also starts with `[`, but is
+// plain text (`[Attachment saved: ...]`), not an array literal. Require the
+// first array value (or the closing bracket for an empty array) to look like
+// a valid JSON token before attempting JSON.parse.
+export const TOOL_RESULT_JSON_OPEN_REGEX = /^(?:\{|\[\s*(?:[[\]"{\-0-9]|true|false|null))/;
// Search-summary wire format used by file-glob and grep tools:
// <matches>
diff --git a/tools/ui/tests/unit/classify-tool-result.test.ts b/tools/ui/tests/unit/classify-tool-result.test.ts
index 6147dee672..23e9baaf37 100644
--- a/tools/ui/tests/unit/classify-tool-result.test.ts
+++ b/tools/ui/tests/unit/classify-tool-result.test.ts
@@ -37,6 +37,10 @@ describe('classifyToolResult', () => {
expect(classifyToolResult('["a", "b", "c"]')).toBe('json');
});
+ it('classifies a nested JSON array', () => {
+ expect(classifyToolResult('[[1, 2], [3, 4]]')).toBe('json');
+ });
+
it('classifies a pretty-printed JSON object', () => {
expect(classifyToolResult('{\n "key": "value"\n}')).toBe('json');
});