fix: unexpected chunk

This commit is contained in:
suyao 2025-07-06 23:37:42 +08:00
parent 3e5969b97c
commit 89cbf80008
No known key found for this signature in database
4 changed files with 13 additions and 6 deletions

View File

@ -71,6 +71,7 @@ export type {
ToolCallUnion,
ToolModelMessage,
ToolResultPart,
ToolResultUnion,
ToolSet,
UserModelMessage
} from 'ai'

View File

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

View File

@ -49,7 +49,9 @@ export default definePlugin({
reasoningBlockId = ''
controller.enqueue(chunk)
} else {
controller.enqueue(chunk)
if (chunk.type !== 'reasoning-end') {
controller.enqueue(chunk)
}
}
},

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