feat(AiSdkToChunkAdapter): fix mcp response image (#10262)

This commit is contained in:
MyPrototypeWhat 2025-09-19 18:26:21 +08:00 committed by GitHub
parent 1e615d69e1
commit a8cd2e2eac
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 21 additions and 10 deletions

View File

@ -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

View File

@ -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'