File tree Expand file tree Collapse file tree 3 files changed +39
-4
lines changed Expand file tree Collapse file tree 3 files changed +39
-4
lines changed Original file line number Diff line number Diff line change 8080 " pint --test" ,
8181 " rector --dry-run"
8282 ],
83- "test:unit" : " pest --ci --coverage --min=91.2 " ,
83+ "test:unit" : " pest --ci --coverage --min=91.4 " ,
8484 "test:types" : " phpstan" ,
8585 "test" : [
8686 " @test:lint" ,
Original file line number Diff line number Diff line change @@ -57,14 +57,17 @@ public function toMethodCall(): array
5757 public function toArray (): array
5858 {
5959 $ annotations = $ this ->annotations ();
60+ $ schema = JsonSchema::object (
61+ $ this ->schema (...),
62+ )->toArray ();
63+
64+ $ schema ['properties ' ] ??= (object ) [];
6065
6166 return [
6267 'name ' => $ this ->name (),
6368 'title ' => $ this ->title (),
6469 'description ' => $ this ->description (),
65- 'inputSchema ' => JsonSchema::object (
66- $ this ->schema (...),
67- )->toArray (),
70+ 'inputSchema ' => $ schema ,
6871 'annotations ' => $ annotations === [] ? (object ) [] : $ annotations ,
6972 ];
7073 }
Original file line number Diff line number Diff line change 7272 ]);
7373});
7474
75+ it ('includes an empty properties object when the schema has no properties ' , function (): void {
76+ $ tool = new TestTool ;
77+ $ array = $ tool ->toArray ();
78+
79+ expect ($ array ['inputSchema ' ])
80+ ->toHaveKey ('type ' , 'object ' )
81+ ->toHaveKey ('properties ' )
82+ ->and ($ array ['inputSchema ' ]['properties ' ])->toEqual ((object ) []);
83+ });
84+
85+ it ('includes schema properties when defined ' , function (): void {
86+ $ tool = new ToolWithSchema ;
87+ $ array = $ tool ->toArray ();
88+
89+ expect ($ array ['inputSchema ' ]['properties ' ])
90+ ->toHaveKey ('message ' )
91+ ->and ($ array ['inputSchema ' ]['properties ' ]['message ' ])
92+ ->toHaveKey ('type ' , 'string ' )
93+ ->toHaveKey ('description ' , 'The message to echo ' )
94+ ->and ($ array ['inputSchema ' ]['required ' ])->toEqual (['message ' ]);
95+ });
96+
7597class TestTool extends Tool
7698{
7799 public function description (): string
@@ -123,3 +145,13 @@ class CustomToolName extends TestTool
123145{
124146 protected string $ name = 'my_custom_tool_name ' ;
125147}
148+
149+ class ToolWithSchema extends TestTool
150+ {
151+ public function schema (\Illuminate \JsonSchema \JsonSchema $ schema ): array
152+ {
153+ return [
154+ 'message ' => $ schema ->string ()->description ('The message to echo ' )->required (),
155+ ];
156+ }
157+ }
You can’t perform that action at this time.
0 commit comments