Fix single-element list unwrapping in tool content

Single-element lists like [1] were being incorrectly unwrapped to "1"
in unstructured content while multi-element lists remained as lists.
This created inconsistent behavior where the structure was lost for
single items.

This fix ensures lists always preserve their structure in unstructured
content regardless of length, making behavior consistent and predictable.

Also removes pretty-printing from JSON serialization for more compact
output across tools, prompts, and resources.

Fixes #1064

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Jeremiah Lowin 2025-07-07 12:07:16 -04:00
commit 0600834da4
11 changed files with 51 additions and 33 deletions

View file

@ -67,7 +67,7 @@ class TestFunctionResource:
)
content = await resource.read()
assert isinstance(content, str)
assert '"key": "value"' in content
assert '"key":"value"' in content
async def test_error_handling(self):
"""Test error handling in FunctionResource."""
@ -95,7 +95,7 @@ class TestFunctionResource:
fn=lambda: MyModel(name="test"),
)
content = await resource.read()
assert content == '{\n "name": "test"\n}'
assert content == '{"name":"test"}'
async def test_custom_type_conversion(self):
"""Test handling of custom types."""