Skip to content

Conversation

@Yi-Lyu
Copy link

@Yi-Lyu Yi-Lyu commented Oct 14, 2025

🐛 Problem

Fixed a critical bug in the image agent that could cause messages: text content blocks must be non-empty API errors.

Root Cause

In src/agents/image.agent.ts:225, when processing text messages containing [Image #N] markers, the code would completely remove these markers using replace(/\[Image #\d+\]/g, ''). If the original text contained only these markers, the result would be an empty string, violating Anthropic API validation requirements.

Solution

  • Added safety check to ensure cleaned text is not empty
  • Provide fallback text [Image reference removed] when cleaned text becomes empty
  • Added .trim() to handle whitespace-only cases
  • Added explanatory comment for future maintainers

Changes

  • File: src/agents/image.agent.ts
  • Lines: 224-227
  • Type: Bug fix (non-breaking)

Testing

  • ✅ Code builds successfully
  • ✅ No linting errors
  • ✅ Maintains existing functionality while preventing empty text blocks

Impact

  • Prevents API errors when processing image-related messages
  • Improves reliability of the image agent
  • Maintains backward compatibility

Fixes the issue reported in logs where claude-jp,claude-sonnet-4-5-20250929 provider returned 400: messages: text content blocks must be non-empty error.

Ethan added 2 commits October 14, 2025 20:18
- Fix issue where removing [Image #N] markers could result in empty text content
- Add fallback text '[Image reference removed]' when cleaned text is empty
- Prevents 'messages: text content blocks must be non-empty' API error
- Ensures all text content blocks have valid non-empty content

Fixes issue where image agent processing could create empty text content
blocks that violate Anthropic API validation requirements.
- Fix issue where removing [Image #N] markers could result in empty text content
- Add fallback text '[Image reference removed]' when cleaned text is empty
- Prevents 'messages: text content blocks must be non-empty' API error
- Ensures all text content blocks have valid non-empty content

Fixes issue where image agent processing could create empty text content
blocks that violate Anthropic API validation requirements.
@Yi-Lyu
Copy link
Author

Yi-Lyu commented Oct 14, 2025

主要解决这个报错问题
image

定位了一下,主要是用户用 cc 时候直接贴了张图让 cc 分析,当前请求没问题,但是后续再碰到 [Image #数字] 的时候就会被清空,但是有的 claude 模型渠道对于 user 和 ai 的消息内容要求严格必须有内容,这就出问题了。ai 分析如下图:
image

请伟大的作者审核代码并修复,谢谢。 祝 ccr 越来越好。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant