From b9abe5d77e26327bb101ab9ef022bd5b1c8e76c7 Mon Sep 17 00:00:00 2001 From: Marco Beretta <81851188+berry-13@users.noreply.github.com> Date: Tue, 28 Oct 2025 22:49:05 +0100 Subject: [PATCH] refactor(parsers): change uiResources to a constant and streamline artifacts handling --- packages/api/src/mcp/parsers.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/api/src/mcp/parsers.ts b/packages/api/src/mcp/parsers.ts index f3fc3a6778..aaf20e1145 100644 --- a/packages/api/src/mcp/parsers.ts +++ b/packages/api/src/mcp/parsers.ts @@ -106,7 +106,7 @@ export function formatToolContent( const formattedContent: t.FormattedContent[] = []; const imageUrls: t.FormattedContent[] = []; let currentTextBlock = ''; - let uiResources: t.UIResource[] = []; + const uiResources: UIResource[] = []; type ContentHandler = undefined | ((item: t.ToolContentPart) => void); @@ -176,11 +176,17 @@ export function formatToolContent( formattedContent.push({ type: 'text', text: currentTextBlock }); } + let artifacts: t.Artifacts = imageUrls.length ? { content: imageUrls } : undefined; + if (uiResources.length) { - formattedContent.push({ type: 'text', metadata: 'ui_resources', text: btoa(JSON.stringify(uiResources))}); + artifacts = { + ...artifacts, + [Tools.ui_resources]: { + data: uiResources, + }, + }; } - const artifacts = imageUrls.length ? { content: imageUrls } : undefined; if (CONTENT_ARRAY_PROVIDERS.has(provider)) { return [formattedContent, artifacts]; }