Skip to content

fix: handle array content blocks in messagesToPrompt#26

Open
RubenHalman wants to merge 1 commit intoatalovesyou:mainfrom
RubenHalman:fix/array-content-blocks
Open

fix: handle array content blocks in messagesToPrompt#26
RubenHalman wants to merge 1 commit intoatalovesyou:mainfrom
RubenHalman:fix/array-content-blocks

Conversation

@RubenHalman
Copy link

@RubenHalman RubenHalman commented Feb 21, 2026

Problem

When clients like OpenClaw send chat requests, they use the OpenAI content block array format for message content:

{"role": "user", "content": [{"type": "text", "text": "hello there"}]}

The messagesToPrompt function assumed content was always a string. Pushing an array into parts and then calling .join("\n") caused JavaScript to coerce it via Array.prototype.toString(), producing [object Object] as the prompt sent to Claude.

Fix

  • Added OpenAIContentBlock type and updated OpenAIChatMessage.content to string | OpenAIContentBlock[]
  • Added extractTextContent() helper that handles both plain strings and content block arrays, extracting text from type: "text" blocks
  • Applied extractTextContent() to all three message roles in messagesToPrompt

Clients like OpenClaw send message content as an array of content blocks
(e.g. [{type: "text", text: "hello"}]) rather than a plain string.
The previous code pushed the array directly into parts[], which caused
JavaScript to coerce it to "[object Object]" when joining.

- Add OpenAIContentBlock type and update OpenAIChatMessage.content to
  accept string | OpenAIContentBlock[]
- Add extractTextContent() to normalize both formats before use
- Apply extractTextContent() across all roles in messagesToPrompt
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