Skip to content

fix: wrap array tool results in object for Kiro API compatibility#3

Open
kipkaev55 wants to merge 1 commit into
bigdata2211it-web:mainfrom
kipkaev55:fix/tool-result-array
Open

fix: wrap array tool results in object for Kiro API compatibility#3
kipkaev55 wants to merge 1 commit into
bigdata2211it-web:mainfrom
kipkaev55:fix/tool-result-array

Conversation

@kipkaev55
Copy link
Copy Markdown

Summary

When a tool result content is a JSON array (e.g. [{"a":1},{"b":2}]), the proxy passes it as { json: [array] }. The Kiro API requires json to always be an object, not an array, and returns ValidationException: Improperly formed request.

Fix

// Before
content: [{ json: typeof msg.content === "string" ? tryParseJson(msg.content) : msg.content }]
// After
var _tr = typeof msg.content === "string" ? tryParseJson(msg.content) : msg.content;
if (Array.isArray(_tr)) _tr = { result: _tr };
content: [{ json: _tr }]

This commonly triggers with tools that return JSON arrays as content (e.g. todowrite).

Testing

tool result content: '[{"a":1},{"b":2}]' → Before: 400 → After: 200
tool result content: 'plain text' → Before: 200 → After: 200 (unchanged)
tool result content: '{"key":"value"}' → Before: 200 → After: 200 (unchanged)

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