17
17
class FunctionCall implements WithJsonSchemaInterface
18
18
{
19
19
/**
20
- * @var string Unique identifier for this function call.
20
+ * @var string|null Unique identifier for this function call.
21
21
*/
22
- private string $ id ;
22
+ private ? string $ id ;
23
23
24
24
/**
25
- * @var string The name of the function to call.
25
+ * @var string|null The name of the function to call.
26
26
*/
27
- private string $ name ;
27
+ private ? string $ name ;
28
28
29
29
/**
30
30
* @var array<string, mixed> The arguments to pass to the function.
@@ -36,12 +36,17 @@ class FunctionCall implements WithJsonSchemaInterface
36
36
*
37
37
* @since n.e.x.t
38
38
*
39
- * @param string $id Unique identifier for this function call.
40
- * @param string $name The name of the function to call.
39
+ * @param string|null $id Unique identifier for this function call.
40
+ * @param string|null $name The name of the function to call.
41
41
* @param array<string, mixed> $args The arguments to pass to the function.
42
+ * @throws \InvalidArgumentException If neither id nor name is provided.
42
43
*/
43
- public function __construct (string $ id, string $ name , array $ args )
44
+ public function __construct (? string $ id = null , ? string $ name = null , array $ args = [] )
44
45
{
46
+ if ($ id === null && $ name === null ) {
47
+ throw new \InvalidArgumentException ('At least one of id or name must be provided. ' );
48
+ }
49
+
45
50
$ this ->id = $ id ;
46
51
$ this ->name = $ name ;
47
52
$ this ->args = $ args ;
@@ -52,9 +57,9 @@ public function __construct(string $id, string $name, array $args)
52
57
*
53
58
* @since n.e.x.t
54
59
*
55
- * @return string The unique identifier.
60
+ * @return string|null The unique identifier.
56
61
*/
57
- public function getId (): string
62
+ public function getId (): ? string
58
63
{
59
64
return $ this ->id ;
60
65
}
@@ -64,9 +69,9 @@ public function getId(): string
64
69
*
65
70
* @since n.e.x.t
66
71
*
67
- * @return string The function name.
72
+ * @return string|null The function name.
68
73
*/
69
- public function getName (): string
74
+ public function getName (): ? string
70
75
{
71
76
return $ this ->name ;
72
77
}
@@ -107,7 +112,17 @@ public static function getJsonSchema(): array
107
112
'additionalProperties ' => true ,
108
113
],
109
114
],
110
- 'required ' => ['id ' , 'name ' , 'args ' ],
115
+ 'oneOf ' => [
116
+ [
117
+ 'required ' => ['id ' ],
118
+ ],
119
+ [
120
+ 'required ' => ['name ' ],
121
+ ],
122
+ [
123
+ 'required ' => ['id ' , 'name ' ],
124
+ ],
125
+ ],
111
126
];
112
127
}
113
128
}
0 commit comments