From 711f805a5b3c360a034445a0682054117a1ce875 Mon Sep 17 00:00:00 2001 From: zane Date: Thu, 11 Dec 2025 10:46:13 +0800 Subject: [PATCH] fix(aiCore): omit empty content in assistant messages with tool_calls (#11818) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix(aiCore): omit empty content in assistant messages with tool_calls When an assistant message contains tool_calls but no text content, the content field was being set to undefined or empty string. This caused API errors on strict OpenAI-compatible endpoints like CherryIn: "messages: text content blocks must be non-empty" The fix conditionally includes the content field only when there is actual text content, which conforms to the OpenAI API specification. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 * fix(aiCore): omit empty assistant message in new aiCore StreamEventManager When building recursive params after tool execution, only add the assistant message when textBuffer has content. This avoids sending empty/invalid assistant messages to strict OpenAI-compatible APIs like CherryIn, which causes "text content blocks must be non-empty" errors. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 * revert: remove legacy OpenAIApiClient fix (legacy is deprecated) The legacy aiCore code is no longer used. Only the fix in the new aiCore architecture (StreamEventManager.ts) is needed. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --------- Co-authored-by: Claude Opus 4.5 --- .../plugins/built-in/toolUsePlugin/StreamEventManager.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/aiCore/src/core/plugins/built-in/toolUsePlugin/StreamEventManager.ts b/packages/aiCore/src/core/plugins/built-in/toolUsePlugin/StreamEventManager.ts index 59a425712c..555d4929d9 100644 --- a/packages/aiCore/src/core/plugins/built-in/toolUsePlugin/StreamEventManager.ts +++ b/packages/aiCore/src/core/plugins/built-in/toolUsePlugin/StreamEventManager.ts @@ -135,10 +135,8 @@ export class StreamEventManager { // 构建新的对话消息 const newMessages: ModelMessage[] = [ ...(context.originalParams.messages || []), - { - role: 'assistant', - content: textBuffer - }, + // 只有当 textBuffer 有内容时才添加 assistant 消息,避免空消息导致 API 错误 + ...(textBuffer ? [{ role: 'assistant' as const, content: textBuffer }] : []), { role: 'user', content: toolResultsText