fix(aiCore): omit empty content in assistant messages with tool_calls (#11818)

* 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 <noreply@anthropic.com>

* 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 <noreply@anthropic.com>

* 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 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
zane 2025-12-11 10:46:13 +08:00 committed by GitHub
parent 6df60a69c3
commit 711f805a5b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -135,10 +135,8 @@ export class StreamEventManager {
// 构建新的对话消息 // 构建新的对话消息
const newMessages: ModelMessage[] = [ const newMessages: ModelMessage[] = [
...(context.originalParams.messages || []), ...(context.originalParams.messages || []),
{ // 只有当 textBuffer 有内容时才添加 assistant 消息,避免空消息导致 API 错误
role: 'assistant', ...(textBuffer ? [{ role: 'assistant' as const, content: textBuffer }] : []),
content: textBuffer
},
{ {
role: 'user', role: 'user',
content: toolResultsText content: toolResultsText