From a8cd2e2eac88f3e2ffd8108e01afd0efa050fed9 Mon Sep 17 00:00:00 2001 From: MyPrototypeWhat Date: Fri, 19 Sep 2025 18:26:21 +0800 Subject: [PATCH] feat(AiSdkToChunkAdapter): fix mcp response image (#10262) --- .../src/aiCore/chunk/AiSdkToChunkAdapter.ts | 10 --------- .../src/aiCore/chunk/handleToolCallChunk.ts | 21 +++++++++++++++++++ 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/renderer/src/aiCore/chunk/AiSdkToChunkAdapter.ts b/src/renderer/src/aiCore/chunk/AiSdkToChunkAdapter.ts index a65c6fe790..c27362eb14 100644 --- a/src/renderer/src/aiCore/chunk/AiSdkToChunkAdapter.ts +++ b/src/renderer/src/aiCore/chunk/AiSdkToChunkAdapter.ts @@ -13,16 +13,6 @@ import { ToolCallChunkHandler } from './handleToolCallChunk' const logger = loggerService.withContext('AiSdkToChunkAdapter') -export interface CherryStudioChunk { - type: 'text-delta' | 'text-complete' | 'tool-call' | 'tool-result' | 'finish' | 'error' - text?: string - toolCall?: any - toolResult?: any - finishReason?: string - usage?: any - error?: any -} - /** * AI SDK 到 Cherry Studio Chunk 适配器类 * 处理 fullStream 到 Cherry Studio chunk 的转换 diff --git a/src/renderer/src/aiCore/chunk/handleToolCallChunk.ts b/src/renderer/src/aiCore/chunk/handleToolCallChunk.ts index 57cd974a2c..39aefc6a5f 100644 --- a/src/renderer/src/aiCore/chunk/handleToolCallChunk.ts +++ b/src/renderer/src/aiCore/chunk/handleToolCallChunk.ts @@ -298,8 +298,29 @@ export class ToolCallChunkHandler { type: ChunkType.MCP_TOOL_COMPLETE, responses: [toolResponse] }) + + const images: string[] = [] + for (const content of toolResponse.response?.content || []) { + if (content.type === 'image' && content.data) { + images.push(`data:${content.mimeType};base64,${content.data}`) + } + } + + if (images.length) { + this.onChunk({ + type: ChunkType.IMAGE_CREATED + }) + this.onChunk({ + type: ChunkType.IMAGE_COMPLETE, + image: { + type: 'base64', + images: images + } + }) + } } } + handleToolError( chunk: { type: 'tool-error'