From 8cca69c8e08c38262287daa02b85e2d0b78c3803 Mon Sep 17 00:00:00 2001 From: Wojt Janowski Date: Sat, 21 Feb 2026 22:33:48 +1100 Subject: [PATCH 1/2] Fix ToolChoiceMap producing invalid payloads for Anthropic and Converse schemas Anthropic schema returned bare strings ('auto'/'any') instead of objects ({'type': 'auto'}). Converse schema nested auto/any under a 'tool' wrapper and used empty arrays instead of stdClass for JSON object serialization. Co-Authored-By: Claude Opus 4.6 --- src/Schemas/Anthropic/Maps/ToolChoiceMap.php | 8 ++--- src/Schemas/Converse/Maps/ToolChoiceMap.php | 4 +-- .../Anthropic/Maps/ToolChoiceMapTest.php | 35 +++++++++++++++++++ .../Converse/Maps/ToolChoiceMapTest.php | 12 +++---- 4 files changed, 44 insertions(+), 15 deletions(-) create mode 100644 tests/Schemas/Anthropic/Maps/ToolChoiceMapTest.php diff --git a/src/Schemas/Anthropic/Maps/ToolChoiceMap.php b/src/Schemas/Anthropic/Maps/ToolChoiceMap.php index 569e6d1..109fc77 100644 --- a/src/Schemas/Anthropic/Maps/ToolChoiceMap.php +++ b/src/Schemas/Anthropic/Maps/ToolChoiceMap.php @@ -10,9 +10,9 @@ class ToolChoiceMap { /** - * @return array|string|null + * @return array|null */ - public static function map(string|ToolChoice|null $toolChoice): string|array|null + public static function map(string|ToolChoice|null $toolChoice): ?array { if (is_null($toolChoice)) { return null; @@ -30,8 +30,8 @@ public static function map(string|ToolChoice|null $toolChoice): string|array|nul } return match ($toolChoice) { - ToolChoice::Auto => 'auto', - ToolChoice::Any => 'any', + ToolChoice::Auto => ['type' => 'auto'], + ToolChoice::Any => ['type' => 'any'], }; } diff --git a/src/Schemas/Converse/Maps/ToolChoiceMap.php b/src/Schemas/Converse/Maps/ToolChoiceMap.php index 781bb47..30c5d1a 100644 --- a/src/Schemas/Converse/Maps/ToolChoiceMap.php +++ b/src/Schemas/Converse/Maps/ToolChoiceMap.php @@ -31,9 +31,7 @@ public static function map(string|ToolChoice|null $toolChoice): string|array|nul } return [ - 'tool' => [ - ($toolChoice === ToolChoice::Auto ? 'auto' : 'any') => [], - ], + ($toolChoice === ToolChoice::Auto ? 'auto' : 'any') => new \stdClass, ]; } } diff --git a/tests/Schemas/Anthropic/Maps/ToolChoiceMapTest.php b/tests/Schemas/Anthropic/Maps/ToolChoiceMapTest.php new file mode 100644 index 0000000..352aa51 --- /dev/null +++ b/tests/Schemas/Anthropic/Maps/ToolChoiceMapTest.php @@ -0,0 +1,35 @@ +toBeNull(); +}); + +it('maps a specific tool correctly', function (): void { + expect(ToolChoiceMap::map('search')) + ->toBe([ + 'type' => 'tool', + 'name' => 'search', + ]); +}); + +it('maps auto tool correctly', function (): void { + expect(ToolChoiceMap::map(ToolChoice::Auto)) + ->toBe(['type' => 'auto']); +}); + +it('maps any tool correctly', function (): void { + expect(ToolChoiceMap::map(ToolChoice::Any)) + ->toBe(['type' => 'any']); +}); + +it('throws exception for invalid tool choice', function (): void { + ToolChoiceMap::map(ToolChoice::None); +})->throws(InvalidArgumentException::class, 'Invalid tool choice'); diff --git a/tests/Schemas/Converse/Maps/ToolChoiceMapTest.php b/tests/Schemas/Converse/Maps/ToolChoiceMapTest.php index ea5fdd8..00f4596 100644 --- a/tests/Schemas/Converse/Maps/ToolChoiceMapTest.php +++ b/tests/Schemas/Converse/Maps/ToolChoiceMapTest.php @@ -18,18 +18,14 @@ it('maps any tool correctly', function (): void { expect(ToolChoiceMap::map(ToolChoice::Any)) - ->toBe([ - 'tool' => [ - 'any' => [], - ], + ->toEqual([ + 'any' => new \stdClass, ]); }); it('maps auto tool correctly', function (): void { expect(ToolChoiceMap::map(ToolChoice::Auto)) - ->toBe([ - 'tool' => [ - 'auto' => [], - ], + ->toEqual([ + 'auto' => new \stdClass, ]); }); From 77a71a6480e7e9107f6b51786e97b99591413ed8 Mon Sep 17 00:00:00 2001 From: Wojt Janowski Date: Thu, 19 Mar 2026 12:40:37 +1100 Subject: [PATCH 2/2] Add Laravel 13 support Widen laravel/framework to ^13.0 and orchestra/testbench to ^11.0. Co-Authored-By: Claude Opus 4.6 (1M context) --- CHANGELOG.md | 9 +++++++++ composer.json | 4 ++-- 2 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..551c72f --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,9 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +## v1.10.0 - 2026-03-19 + +### Added + +- Laravel 13 support (`laravel/framework` ^13.0, `orchestra/testbench` ^11.0) diff --git a/composer.json b/composer.json index 90535e6..2c69541 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ ], "require": { "php": "^8.2", - "laravel/framework": "^11.0|^12.0", + "laravel/framework": "^11.0|^12.0|^13.0", "aws/aws-sdk-php": "^3.339", "prism-php/prism": ">=0.99.7" }, @@ -41,7 +41,7 @@ "phpstan/phpstan-deprecation-rules": "^2.0", "rector/rector": "2.2.14", "projektgopher/whisky": "^0.7.0", - "orchestra/testbench": "^9.4", + "orchestra/testbench": "^9.4|^10.0|^11.0", "mockery/mockery": "^1.6", "symplify/rule-doc-generator-contracts": "^11.2", "phpstan/phpdoc-parser": "^2.0",