Fix: Handle array-style content blocks in messagesToPrompt#19
Open
superdav42 wants to merge 1 commit intoatalovesyou:mainfrom
Open
Fix: Handle array-style content blocks in messagesToPrompt#19superdav42 wants to merge 1 commit intoatalovesyou:mainfrom
superdav42 wants to merge 1 commit intoatalovesyou:mainfrom
Conversation
OpenAI API supports both string and array content formats for messages.
When content is an array of objects (e.g. [{"type": "text", "text": "..."}]),
JavaScript's template literal interpolation converts it to "[object Object]"
instead of the actual text content.
This adds an extractContent() helper that:
- Returns string content as-is
- Extracts and joins text from array-style content blocks
- Falls back to String() for any other type
All msg.content references in messagesToPrompt are updated to use
extractContent(msg.content) for the system, user, and assistant cases.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
[{"type": "text", "text": "Hello"}][object Object]instead of the actual text, causing garbled prompts sent to Claude CLIextractContent()helper that handles both formats: returns strings as-is, extracts and joins text from array-style content blocks, and falls back toString()for any unexpected typemsg.contentreferences inmessagesToPrompt(system, user, and assistant cases) to useextractContent(msg.content)Details
The OpenAI chat completions API defines content as either a string or an array of content parts:
The previous code used
msg.contentdirectly in template literals andparts.push(), which works fine for strings but produces[object Object]for arrays.The new
extractContent()function:Test plan
[{"type": "text", "text": "..."}]is correctly extracted🤖 Generated with Claude Code