fix: unexpected chunk

This commit is contained in:
suyao
2025-07-06 23:37:42 +08:00
parent 3e5969b97c
commit 89cbf80008
4 changed files with 13 additions and 6 deletions
@@ -4,7 +4,7 @@
* 提供工具调用相关的处理API,每个交互使用一个新的实例
*/
import { ToolCallUnion, ToolSet } from '@cherrystudio/ai-core/index'
import { ToolCallUnion, ToolResultUnion, ToolSet } from '@cherrystudio/ai-core/index'
import Logger from '@renderer/config/logger'
import { MCPTool, MCPToolResponse } from '@renderer/types'
import { Chunk, ChunkType } from '@renderer/types/chunk'
@@ -84,9 +84,13 @@ export class ToolCallChunkHandler {
/**
* 处理工具调用结果事件
*/
public handleToolResult(chunk: any): void {
public handleToolResult(
chunk: {
type: 'tool-result'
} & ToolResultUnion<ToolSet>
): void {
const toolCallId = chunk.toolCallId
const result = chunk.result
const result = chunk.output
if (!toolCallId) {
Logger.warn(`🔧 [ToolCallChunkHandler] Invalid tool result chunk: missing toolCallId`)
@@ -49,7 +49,9 @@ export default definePlugin({
reasoningBlockId = ''
controller.enqueue(chunk)
} else {
controller.enqueue(chunk)
if (chunk.type !== 'reasoning-end') {
controller.enqueue(chunk)
}
}
},
+2 -2
View File
@@ -15,7 +15,7 @@ import {
import { getStoreSetting } from '@renderer/hooks/useSettings'
import i18n from '@renderer/i18n'
import store from '@renderer/store'
import { Assistant, MCPTool, Model, Provider } from '@renderer/types'
import { Assistant, MCPServer, MCPTool, Model, Provider } from '@renderer/types'
import { type Chunk, ChunkType } from '@renderer/types/chunk'
import { Message } from '@renderer/types/newMessage'
import { SdkModel } from '@renderer/types/sdk'
@@ -263,7 +263,7 @@ export async function fetchMcpTools(assistant: Assistant) {
if (enabledMCPs && enabledMCPs.length > 0) {
try {
const toolPromises = enabledMCPs.map<Promise<MCPTool[]>>(async (mcpServer) => {
const toolPromises = enabledMCPs.map<Promise<MCPTool[]>>(async (mcpServer: MCPServer) => {
try {
const tools = await window.api.mcp.listTools(mcpServer)
return tools.filter((tool: any) => !mcpServer.disabledTools?.includes(tool.name))