diff --git a/src/Responses/Responses/Output/OutputFunctionToolCall.php b/src/Responses/Responses/Output/OutputFunctionToolCall.php index 985fa9d2..a566e43b 100644 --- a/src/Responses/Responses/Output/OutputFunctionToolCall.php +++ b/src/Responses/Responses/Output/OutputFunctionToolCall.php @@ -9,7 +9,7 @@ use OpenAI\Testing\Responses\Concerns\Fakeable; /** - * @phpstan-type OutputFunctionToolCallType array{arguments: string, call_id: string, name: string, type: 'function_call', id: string, status: 'in_progress'|'completed'|'incomplete'} + * @phpstan-type OutputFunctionToolCallType array{arguments: string, call_id: string, name: string, namespace?: ?string, type: 'function_call', id: string, status: 'in_progress'|'completed'|'incomplete'} * * @implements ResponseContract */ @@ -33,6 +33,7 @@ private function __construct( public readonly string $type, public readonly string $id, public readonly string $status, + public readonly ?string $namespace, ) {} /** @@ -47,6 +48,7 @@ public static function from(array $attributes): self type: $attributes['type'], id: $attributes['id'], status: $attributes['status'], + namespace: $attributes['namespace'] ?? null, ); } @@ -59,6 +61,7 @@ public function toArray(): array 'arguments' => $this->arguments, 'call_id' => $this->callId, 'name' => $this->name, + 'namespace' => $this->namespace, 'type' => $this->type, 'id' => $this->id, 'status' => $this->status, diff --git a/tests/Fixtures/Responses.php b/tests/Fixtures/Responses.php index 4da44a0f..7883adda 100644 --- a/tests/Fixtures/Responses.php +++ b/tests/Fixtures/Responses.php @@ -726,6 +726,22 @@ function outputCustomToolCall(): array ]; } +/** + * @return array + */ +function outputFunctionToolCall(): array +{ + return [ + 'arguments' => '{"customer_id":"CUST-12345"}', + 'call_id' => 'call_abc123', + 'name' => 'list_open_orders', + 'namespace' => 'crm', + 'type' => 'function_call', + 'id' => 'fc_abc123', + 'status' => 'completed', + ]; +} + /** * @return array */ diff --git a/tests/Responses/Responses/Output/OutputFunctionToolCall.php b/tests/Responses/Responses/Output/OutputFunctionToolCall.php new file mode 100644 index 00000000..05c3dc18 --- /dev/null +++ b/tests/Responses/Responses/Output/OutputFunctionToolCall.php @@ -0,0 +1,47 @@ +toBeInstanceOf(OutputFunctionToolCall::class) + ->arguments->toBe('{"customer_id":"CUST-12345"}') + ->callId->toBe('call_abc123') + ->name->toBe('list_open_orders') + ->namespace->toBe('crm') + ->type->toBe('function_call') + ->id->toBe('fc_abc123') + ->status->toBe('completed'); +}); + +test('from without namespace', function () { + $attributes = outputFunctionToolCall(); + + unset($attributes['namespace']); + + set_error_handler(static fn (int $errno, string $errstr): bool => throw new ErrorException($errstr), E_WARNING); + + try { + $response = OutputFunctionToolCall::from($attributes); + } finally { + restore_error_handler(); + } + + expect($response->namespace)->toBeNull(); +}); + +test('as array accessible', function () { + $response = OutputFunctionToolCall::from(outputFunctionToolCall()); + + expect($response['namespace'])->toBe('crm'); +}); + +test('to array', function () { + $response = OutputFunctionToolCall::from(outputFunctionToolCall()); + + expect($response->toArray()) + ->toBeArray() + ->toBe(outputFunctionToolCall()); +});