fix(middleware): return proper content format when no images viewed (#1454)

- Fix OpenAI BadRequestError: 'No images have been viewed.' was returned as
  a plain string array instead of a properly formatted content block
- The OpenAI API expects message content to be either a string or an array
  of objects with 'type' field, not an array of plain strings
- Changed return from ['No images have been viewed.'] to
  [{'type': 'text', 'text': 'No images have been viewed.'}]

Fixes #1441

Co-authored-by: JasonOA888 <noreply@github.com>
This commit is contained in:
Jason
2026-03-27 17:33:17 +08:00
committed by GitHub
parent 43a19f9627
commit 4708700723

View File

@@ -102,7 +102,8 @@ class ViewImageMiddleware(AgentMiddleware[ViewImageMiddlewareState]):
"""
viewed_images = state.get("viewed_images", {})
if not viewed_images:
return ["No images have been viewed."]
# Return a properly formatted text block, not a plain string array
return [{"type": "text", "text": "No images have been viewed."}]
# Build the message with image information
content_blocks: list[str | dict] = [{"type": "text", "text": "Here are the images you've viewed:"}]