File tree Expand file tree Collapse file tree 2 files changed +14
-5
lines changed Expand file tree Collapse file tree 2 files changed +14
-5
lines changed Original file line number Diff line number Diff line change 14
14
final readonly class ToolCallResult
15
15
{
16
16
public function __construct (
17
- public string $ result ,
17
+ public mixed $ result ,
18
18
/**
19
19
* @var "text"|"image"|"audio"|"resource"|non-empty-string
20
20
*/
21
21
public string $ type = 'text ' ,
22
- public string $ mimeType = 'text/plan ' ,
22
+ public string $ mimeType = 'text/plain ' ,
23
23
public bool $ isError = false ,
24
24
public ?string $ uri = null ,
25
25
) {
Original file line number Diff line number Diff line change @@ -26,6 +26,9 @@ public function __construct(
26
26
) {
27
27
}
28
28
29
+ /**
30
+ * @throws \JsonException
31
+ */
29
32
public function createResponse (Request $ message ): Response |Error
30
33
{
31
34
$ name = $ message ->params ['name ' ];
@@ -40,7 +43,7 @@ public function createResponse(Request $message): Response|Error
40
43
$ content = match ($ result ->type ) {
41
44
'text ' => [
42
45
'type ' => 'text ' ,
43
- 'text ' => $ result ->result ,
46
+ 'text ' => json_encode ( $ result ->result , \ JSON_THROW_ON_ERROR ) ,
44
47
],
45
48
'image ' , 'audio ' => [
46
49
'type ' => $ result ->type ,
@@ -59,10 +62,16 @@ public function createResponse(Request $message): Response|Error
59
62
default => throw new InvalidArgumentException ('Unsupported tool result type: ' .$ result ->type ),
60
63
};
61
64
62
- return new Response ( $ message -> id , [
65
+ $ response = [
63
66
'content ' => [$ content ], // TODO: allow multiple `ToolCallResult`s in the future
64
67
'isError ' => $ result ->isError ,
65
- ]);
68
+ ];
69
+
70
+ if ('text ' === $ result ->type && \is_array ($ result ->result ) || \is_object ($ result ->result )) {
71
+ $ response ['structuredContent ' ] = $ result ->result ;
72
+ }
73
+
74
+ return new Response ($ message ->id , $ response );
66
75
}
67
76
68
77
protected function supportedMethod (): string
You can’t perform that action at this time.
0 commit comments