fix(ToolMap): remove static duplicate parameters handling in mapping openrouter#1004
Open
Aldiwildan77 wants to merge 1 commit into
Open
Conversation
wishborn
added a commit
to Particle-Academy/prism
that referenced
this pull request
Jul 6, 2026
…ey overwriting conditional spread in ToolMap
wishborn
added a commit
to Particle-Academy/prism
that referenced
this pull request
Jul 6, 2026
The test never consumed the lazy stream generator (so no request was ever sent) and referenced a fixture the PR did not include. The mapping behavior it targeted is covered by the two direct ToolMap unit tests from the same PR. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
4 tasks
wishborn
added a commit
to Particle-Academy/prism
that referenced
this pull request
Jul 6, 2026
prism-php#1026 shipped without tests and copied two known-buggy patterns from older provider code: - ToolMap carried the duplicate static parameters key that overwrote the conditional spread (the OpenRouter bug fixed by prism-php#1004). - Text/Structured handlers threw on unknown finish reasons instead of resolving gracefully (prism-php#996). Adds text-generation, graceful-finish-reason, and ToolMap tests. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Problem
ToolMap::map()contains twoparameterskeys in the same PHP array for thefunctiondefinition:In PHP, duplicate array keys cause the last one to win. This means:
stdClassempty-properties fallback that ensures correct JSON serialization as{}instead of[]parametersblock with{ "properties": {}, "required": [] }because KEY 2 is unconditional — thehasParameters()check in KEY 1 never takes effectProof
A mock test confirms KEY 2 overwrites KEY 1. When
hasParameters()istrueandparametersAsArray()returns[]:'properties' => new \stdClass(serializes as JSON{})'properties' => [](serializes as JSON[])With the buggy code, the result is
[]— proving KEY 2 overwrote KEY 1.Fix
Remove the unconditional duplicate
parameterskey (KEY 2). The conditional spread (KEY 1) already handles both cases correctly:hasParameters() === true→ spreadsparameterswith proper schema andstdClassfallbackhasParameters() === false→ spreads nothing → noparameterskey in outputTests
Added 4 new tests (5 total, 18 assertions):
generates parameters only once from conditional spreadparameterskeyproves parameters is generated by conditional spread not static duplicatepropertiesisstdClass(from KEY 1), not[](from KEY 2) — proving KEY 1 is now in controlsends correct tool payload to OpenRouter when streamingHttp::assertSent— parameterless tools have noparametersin the request bodymaps tools with strict modeBefore / After
Before (tool without parameters):
{ "type": "function", "function": { "name": "get_time", "description": "Returns the current time", "parameters": { "type": "object", "properties": {}, "required": [] } } }After (tool without parameters):
{ "type": "function", "function": { "name": "get_time", "description": "Returns the current time" } }Test Check Result