From 4fcb8748412d332d1ccc9913eb98b63b00f51ef2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mads=20Kildeg=C3=A5rd?= Date: Wed, 5 Nov 2025 16:06:01 +0100 Subject: [PATCH 1/2] feat responses streaming types MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mads KildegÄrd --- .../Responses/CreateStreamedResponse.php | 5 +- .../Streaming/CodeInterpreterCall.php | 3 + .../Streaming/CodeInterpreterCodeDelta.php | 3 + .../Streaming/CodeInterpreterCodeDone.php | 3 + .../Responses/Streaming/ContentPart.php | 3 + src/Responses/Responses/Streaming/Error.php | 3 + .../Responses/Streaming/FileSearchCall.php | 3 + .../Streaming/FunctionCallArgumentsDelta.php | 3 + .../Streaming/FunctionCallArgumentsDone.php | 3 + .../Streaming/ImageGenerationPart.php | 3 + .../Streaming/ImageGenerationPartialImage.php | 3 + src/Responses/Responses/Streaming/McpCall.php | 3 + .../Streaming/McpCallArgumentsDelta.php | 3 + .../Streaming/McpCallArgumentsDone.php | 3 + .../Responses/Streaming/McpListTools.php | 3 + .../Streaming/McpListToolsInProgress.php | 3 + .../Responses/Streaming/OutputItem.php | 3 + .../Streaming/OutputTextAnnotationAdded.php | 3 + .../Responses/Streaming/OutputTextDelta.php | 3 + .../Responses/Streaming/OutputTextDone.php | 3 + .../Streaming/ReasoningSummaryPart.php | 3 + .../Streaming/ReasoningSummaryTextDelta.php | 3 + .../Streaming/ReasoningSummaryTextDone.php | 3 + .../Streaming/ReasoningTextDelta.php | 3 + .../Responses/Streaming/ReasoningTextDone.php | 3 + .../Responses/Streaming/RefusalDelta.php | 3 + .../Responses/Streaming/RefusalDone.php | 3 + .../Responses/Streaming/Response.php | 61 +++++++++++++++++++ .../Responses/Streaming/WebSearchCall.php | 3 + 29 files changed, 145 insertions(+), 2 deletions(-) create mode 100644 src/Responses/Responses/Streaming/Response.php diff --git a/src/Responses/Responses/CreateStreamedResponse.php b/src/Responses/Responses/CreateStreamedResponse.php index 99efe66e..5a14b512 100644 --- a/src/Responses/Responses/CreateStreamedResponse.php +++ b/src/Responses/Responses/CreateStreamedResponse.php @@ -33,6 +33,7 @@ use OpenAI\Responses\Responses\Streaming\ReasoningTextDone; use OpenAI\Responses\Responses\Streaming\RefusalDelta; use OpenAI\Responses\Responses\Streaming\RefusalDone; +use OpenAI\Responses\Responses\Streaming\Response; use OpenAI\Responses\Responses\Streaming\WebSearchCall; use OpenAI\Testing\Responses\Concerns\FakeableForStreamedResponse; @@ -52,7 +53,7 @@ final class CreateStreamedResponse implements ResponseContract private function __construct( public readonly string $event, - public readonly CreateResponse|OutputItem|ContentPart|OutputTextDelta|OutputTextAnnotationAdded|OutputTextDone|RefusalDelta|RefusalDone|FunctionCallArgumentsDelta|FunctionCallArgumentsDone|FileSearchCall|WebSearchCall|CodeInterpreterCall|CodeInterpreterCodeDelta|CodeInterpreterCodeDone|ReasoningSummaryPart|ReasoningSummaryTextDelta|ReasoningSummaryTextDone|ReasoningTextDelta|ReasoningTextDone|McpListTools|McpListToolsInProgress|McpCall|McpCallArgumentsDelta|McpCallArgumentsDone|ImageGenerationPart|ImageGenerationPartialImage|Error $response, + public readonly Response|OutputItem|ContentPart|OutputTextDelta|OutputTextAnnotationAdded|OutputTextDone|RefusalDelta|RefusalDone|FunctionCallArgumentsDelta|FunctionCallArgumentsDone|FileSearchCall|WebSearchCall|CodeInterpreterCall|CodeInterpreterCodeDelta|CodeInterpreterCodeDone|ReasoningSummaryPart|ReasoningSummaryTextDelta|ReasoningSummaryTextDone|ReasoningTextDelta|ReasoningTextDone|McpListTools|McpListToolsInProgress|McpCall|McpCallArgumentsDelta|McpCallArgumentsDone|ImageGenerationPart|ImageGenerationPartialImage|Error $response, ) {} /** @@ -69,7 +70,7 @@ public static function from(array $attributes): self 'response.in_progress', 'response.completed', 'response.failed', - 'response.incomplete' => CreateResponse::from($attributes['response'], $meta), // @phpstan-ignore-line + 'response.incomplete' => Response::from($attributes, $meta), // @phpstan-ignore-line 'response.output_item.added', 'response.output_item.done' => OutputItem::from($attributes, $meta), // @phpstan-ignore-line 'response.content_part.added', diff --git a/src/Responses/Responses/Streaming/CodeInterpreterCall.php b/src/Responses/Responses/Streaming/CodeInterpreterCall.php index 59506526..3ae838de 100644 --- a/src/Responses/Responses/Streaming/CodeInterpreterCall.php +++ b/src/Responses/Responses/Streaming/CodeInterpreterCall.php @@ -27,6 +27,7 @@ final class CodeInterpreterCall implements ResponseContract, ResponseHasMetaInfo use HasMetaInformation; private function __construct( + public readonly string $type, public readonly string $itemId, public readonly int $outputIndex, private readonly MetaInformation $meta, @@ -38,6 +39,7 @@ private function __construct( public static function from(array $attributes, MetaInformation $meta): self { return new self( + type: $attributes['type'], itemId: $attributes['item_id'], outputIndex: $attributes['output_index'], meta: $meta, @@ -50,6 +52,7 @@ public static function from(array $attributes, MetaInformation $meta): self public function toArray(): array { return [ + 'type' => $this->type, 'item_id' => $this->itemId, 'output_index' => $this->outputIndex, ]; diff --git a/src/Responses/Responses/Streaming/CodeInterpreterCodeDelta.php b/src/Responses/Responses/Streaming/CodeInterpreterCodeDelta.php index dc603f4e..001d64ab 100644 --- a/src/Responses/Responses/Streaming/CodeInterpreterCodeDelta.php +++ b/src/Responses/Responses/Streaming/CodeInterpreterCodeDelta.php @@ -27,6 +27,7 @@ final class CodeInterpreterCodeDelta implements ResponseContract, ResponseHasMet use HasMetaInformation; private function __construct( + public readonly string $type, public readonly string $delta, public readonly string $itemId, public readonly int $outputIndex, @@ -39,6 +40,7 @@ private function __construct( public static function from(array $attributes, MetaInformation $meta): self { return new self( + type: $attributes['type'], delta: $attributes['delta'], itemId: $attributes['item_id'], outputIndex: $attributes['output_index'], @@ -52,6 +54,7 @@ public static function from(array $attributes, MetaInformation $meta): self public function toArray(): array { return [ + 'type' => $this->type, 'delta' => $this->delta, 'item_id' => $this->itemId, 'output_index' => $this->outputIndex, diff --git a/src/Responses/Responses/Streaming/CodeInterpreterCodeDone.php b/src/Responses/Responses/Streaming/CodeInterpreterCodeDone.php index 3dc25232..edf3904d 100644 --- a/src/Responses/Responses/Streaming/CodeInterpreterCodeDone.php +++ b/src/Responses/Responses/Streaming/CodeInterpreterCodeDone.php @@ -27,6 +27,7 @@ final class CodeInterpreterCodeDone implements ResponseContract, ResponseHasMeta use HasMetaInformation; private function __construct( + public readonly string $type, public readonly string $code, public readonly string $itemId, public readonly int $outputIndex, @@ -39,6 +40,7 @@ private function __construct( public static function from(array $attributes, MetaInformation $meta): self { return new self( + type: $attributes['type'], code: $attributes['code'], itemId: $attributes['item_id'], outputIndex: $attributes['output_index'], @@ -52,6 +54,7 @@ public static function from(array $attributes, MetaInformation $meta): self public function toArray(): array { return [ + 'type' => $this->type, 'code' => $this->code, 'item_id' => $this->itemId, 'output_index' => $this->outputIndex, diff --git a/src/Responses/Responses/Streaming/ContentPart.php b/src/Responses/Responses/Streaming/ContentPart.php index 2ffab5b5..f39c81e3 100644 --- a/src/Responses/Responses/Streaming/ContentPart.php +++ b/src/Responses/Responses/Streaming/ContentPart.php @@ -32,6 +32,7 @@ final class ContentPart implements ResponseContract, ResponseHasMetaInformationC use HasMetaInformation; private function __construct( + public readonly string $type, public readonly int $contentIndex, public readonly string $itemId, public readonly int $outputIndex, @@ -50,6 +51,7 @@ public static function from(array $attributes, MetaInformation $meta): self }; return new self( + type: $attributes['type'], contentIndex: $attributes['content_index'], itemId: $attributes['item_id'], outputIndex: $attributes['output_index'], @@ -64,6 +66,7 @@ public static function from(array $attributes, MetaInformation $meta): self public function toArray(): array { return [ + 'type' => $this->type, 'content_index' => $this->contentIndex, 'item_id' => $this->itemId, 'output_index' => $this->outputIndex, diff --git a/src/Responses/Responses/Streaming/Error.php b/src/Responses/Responses/Streaming/Error.php index fe713440..3a6d2574 100644 --- a/src/Responses/Responses/Streaming/Error.php +++ b/src/Responses/Responses/Streaming/Error.php @@ -27,6 +27,7 @@ final class Error implements ResponseContract, ResponseHasMetaInformationContrac use HasMetaInformation; private function __construct( + public readonly string $type, public readonly ?string $code, public readonly string $message, public readonly ?string $param, @@ -39,6 +40,7 @@ private function __construct( public static function from(array $attributes, MetaInformation $meta): self { return new self( + type: $attributes['type'], code: $attributes['code'], message: $attributes['message'], param: $attributes['param'], @@ -52,6 +54,7 @@ public static function from(array $attributes, MetaInformation $meta): self public function toArray(): array { return [ + 'type' => $this->type, 'code' => $this->code, 'message' => $this->message, 'param' => $this->param, diff --git a/src/Responses/Responses/Streaming/FileSearchCall.php b/src/Responses/Responses/Streaming/FileSearchCall.php index 63ddd926..1b42b766 100644 --- a/src/Responses/Responses/Streaming/FileSearchCall.php +++ b/src/Responses/Responses/Streaming/FileSearchCall.php @@ -27,6 +27,7 @@ final class FileSearchCall implements ResponseContract, ResponseHasMetaInformati use HasMetaInformation; private function __construct( + public readonly string $type, public readonly string $itemId, public readonly int $outputIndex, private readonly MetaInformation $meta, @@ -38,6 +39,7 @@ private function __construct( public static function from(array $attributes, MetaInformation $meta): self { return new self( + type: $attributes['type'], itemId: $attributes['item_id'], outputIndex: $attributes['output_index'], meta: $meta, @@ -50,6 +52,7 @@ public static function from(array $attributes, MetaInformation $meta): self public function toArray(): array { return [ + 'type' => $this->type, 'item_id' => $this->itemId, 'output_index' => $this->outputIndex, ]; diff --git a/src/Responses/Responses/Streaming/FunctionCallArgumentsDelta.php b/src/Responses/Responses/Streaming/FunctionCallArgumentsDelta.php index ae756041..ae2303a1 100644 --- a/src/Responses/Responses/Streaming/FunctionCallArgumentsDelta.php +++ b/src/Responses/Responses/Streaming/FunctionCallArgumentsDelta.php @@ -27,6 +27,7 @@ final class FunctionCallArgumentsDelta implements ResponseContract, ResponseHasM use HasMetaInformation; private function __construct( + public readonly string $type, public readonly string $delta, public readonly string $itemId, public readonly int $outputIndex, @@ -39,6 +40,7 @@ private function __construct( public static function from(array $attributes, MetaInformation $meta): self { return new self( + type: $attributes['type'], delta: $attributes['delta'], itemId: $attributes['item_id'], outputIndex: $attributes['output_index'], @@ -52,6 +54,7 @@ public static function from(array $attributes, MetaInformation $meta): self public function toArray(): array { return [ + 'type' => $this->type, 'delta' => $this->delta, 'item_id' => $this->itemId, 'output_index' => $this->outputIndex, diff --git a/src/Responses/Responses/Streaming/FunctionCallArgumentsDone.php b/src/Responses/Responses/Streaming/FunctionCallArgumentsDone.php index ce21fb55..0632c004 100644 --- a/src/Responses/Responses/Streaming/FunctionCallArgumentsDone.php +++ b/src/Responses/Responses/Streaming/FunctionCallArgumentsDone.php @@ -27,6 +27,7 @@ final class FunctionCallArgumentsDone implements ResponseContract, ResponseHasMe use HasMetaInformation; private function __construct( + public readonly string $type, public readonly string $arguments, public readonly string $itemId, public readonly int $outputIndex, @@ -39,6 +40,7 @@ private function __construct( public static function from(array $attributes, MetaInformation $meta): self { return new self( + type: $attributes['type'], arguments: $attributes['arguments'], itemId: $attributes['item_id'], outputIndex: $attributes['output_index'], @@ -52,6 +54,7 @@ public static function from(array $attributes, MetaInformation $meta): self public function toArray(): array { return [ + 'type' => $this->type, 'arguments' => $this->arguments, 'item_id' => $this->itemId, 'output_index' => $this->outputIndex, diff --git a/src/Responses/Responses/Streaming/ImageGenerationPart.php b/src/Responses/Responses/Streaming/ImageGenerationPart.php index 2cf9f107..62cba9e8 100644 --- a/src/Responses/Responses/Streaming/ImageGenerationPart.php +++ b/src/Responses/Responses/Streaming/ImageGenerationPart.php @@ -27,6 +27,7 @@ final class ImageGenerationPart implements ResponseContract, ResponseHasMetaInfo use HasMetaInformation; private function __construct( + public readonly string $type, public readonly int $outputIndex, public readonly string $itemId, public readonly int $sequenceNumber, @@ -39,6 +40,7 @@ private function __construct( public static function from(array $attributes, MetaInformation $meta): self { return new self( + type: $attributes['type'], outputIndex: $attributes['output_index'], itemId: $attributes['item_id'], sequenceNumber: $attributes['sequence_number'], @@ -52,6 +54,7 @@ public static function from(array $attributes, MetaInformation $meta): self public function toArray(): array { return [ + 'type' => $this->type, 'output_index' => $this->outputIndex, 'item_id' => $this->itemId, 'sequence_number' => $this->sequenceNumber, diff --git a/src/Responses/Responses/Streaming/ImageGenerationPartialImage.php b/src/Responses/Responses/Streaming/ImageGenerationPartialImage.php index 73e38814..7c7f145b 100644 --- a/src/Responses/Responses/Streaming/ImageGenerationPartialImage.php +++ b/src/Responses/Responses/Streaming/ImageGenerationPartialImage.php @@ -27,6 +27,7 @@ final class ImageGenerationPartialImage implements ResponseContract, ResponseHas use HasMetaInformation; private function __construct( + public readonly string $type, public readonly int $outputIndex, public readonly string $itemId, public readonly int $sequenceNumber, @@ -41,6 +42,7 @@ private function __construct( public static function from(array $attributes, MetaInformation $meta): self { return new self( + type: $attributes['type'], outputIndex: $attributes['output_index'], itemId: $attributes['item_id'], sequenceNumber: $attributes['sequence_number'], @@ -56,6 +58,7 @@ public static function from(array $attributes, MetaInformation $meta): self public function toArray(): array { return [ + 'type' => $this->type, 'output_index' => $this->outputIndex, 'item_id' => $this->itemId, 'sequence_number' => $this->sequenceNumber, diff --git a/src/Responses/Responses/Streaming/McpCall.php b/src/Responses/Responses/Streaming/McpCall.php index 8d05d940..366f0fe7 100644 --- a/src/Responses/Responses/Streaming/McpCall.php +++ b/src/Responses/Responses/Streaming/McpCall.php @@ -27,6 +27,7 @@ final class McpCall implements ResponseContract, ResponseHasMetaInformationContr use HasMetaInformation; private function __construct( + public readonly string $type, public readonly int $sequenceNumber, private readonly MetaInformation $meta, ) {} @@ -37,6 +38,7 @@ private function __construct( public static function from(array $attributes, MetaInformation $meta): self { return new self( + type: $attributes['type'], sequenceNumber: $attributes['sequence_number'], meta: $meta, ); @@ -48,6 +50,7 @@ public static function from(array $attributes, MetaInformation $meta): self public function toArray(): array { return [ + 'type' => $this->type, 'sequence_number' => $this->sequenceNumber, ]; } diff --git a/src/Responses/Responses/Streaming/McpCallArgumentsDelta.php b/src/Responses/Responses/Streaming/McpCallArgumentsDelta.php index 78bd9566..76b79ac9 100644 --- a/src/Responses/Responses/Streaming/McpCallArgumentsDelta.php +++ b/src/Responses/Responses/Streaming/McpCallArgumentsDelta.php @@ -27,6 +27,7 @@ final class McpCallArgumentsDelta implements ResponseContract, ResponseHasMetaIn use HasMetaInformation; private function __construct( + public readonly string $type, public readonly int $sequenceNumber, public readonly int $outputIndex, public readonly string $itemId, @@ -40,6 +41,7 @@ private function __construct( public static function from(array $attributes, MetaInformation $meta): self { return new self( + type: $attributes['type'], sequenceNumber: $attributes['sequence_number'], outputIndex: $attributes['output_index'], itemId: $attributes['item_id'], @@ -54,6 +56,7 @@ public static function from(array $attributes, MetaInformation $meta): self public function toArray(): array { return [ + 'type' => $this->type, 'sequence_number' => $this->sequenceNumber, 'output_index' => $this->outputIndex, 'item_id' => $this->itemId, diff --git a/src/Responses/Responses/Streaming/McpCallArgumentsDone.php b/src/Responses/Responses/Streaming/McpCallArgumentsDone.php index eb480878..131d4e6d 100644 --- a/src/Responses/Responses/Streaming/McpCallArgumentsDone.php +++ b/src/Responses/Responses/Streaming/McpCallArgumentsDone.php @@ -27,6 +27,7 @@ final class McpCallArgumentsDone implements ResponseContract, ResponseHasMetaInf use HasMetaInformation; private function __construct( + public readonly string $type, public readonly int $sequenceNumber, public readonly int $outputIndex, public readonly string $itemId, @@ -40,6 +41,7 @@ private function __construct( public static function from(array $attributes, MetaInformation $meta): self { return new self( + type: $attributes['type'], sequenceNumber: $attributes['sequence_number'], outputIndex: $attributes['output_index'], itemId: $attributes['item_id'], @@ -54,6 +56,7 @@ public static function from(array $attributes, MetaInformation $meta): self public function toArray(): array { return [ + 'type' => $this->type, 'sequence_number' => $this->sequenceNumber, 'output_index' => $this->outputIndex, 'item_id' => $this->itemId, diff --git a/src/Responses/Responses/Streaming/McpListTools.php b/src/Responses/Responses/Streaming/McpListTools.php index 00cdc568..97a7a485 100644 --- a/src/Responses/Responses/Streaming/McpListTools.php +++ b/src/Responses/Responses/Streaming/McpListTools.php @@ -27,6 +27,7 @@ final class McpListTools implements ResponseContract, ResponseHasMetaInformation use HasMetaInformation; private function __construct( + public readonly string $type, public readonly int $sequenceNumber, private readonly MetaInformation $meta, ) {} @@ -37,6 +38,7 @@ private function __construct( public static function from(array $attributes, MetaInformation $meta): self { return new self( + type: $attributes['type'], sequenceNumber: $attributes['sequence_number'], meta: $meta, ); @@ -48,6 +50,7 @@ public static function from(array $attributes, MetaInformation $meta): self public function toArray(): array { return [ + 'type' => $this->type, 'sequence_number' => $this->sequenceNumber, ]; } diff --git a/src/Responses/Responses/Streaming/McpListToolsInProgress.php b/src/Responses/Responses/Streaming/McpListToolsInProgress.php index c19a41a5..0dd9511b 100644 --- a/src/Responses/Responses/Streaming/McpListToolsInProgress.php +++ b/src/Responses/Responses/Streaming/McpListToolsInProgress.php @@ -27,6 +27,7 @@ final class McpListToolsInProgress implements ResponseContract, ResponseHasMetaI use HasMetaInformation; private function __construct( + public readonly string $type, public readonly int $sequenceNumber, public readonly int $outputIndex, public readonly string $itemId, @@ -39,6 +40,7 @@ private function __construct( public static function from(array $attributes, MetaInformation $meta): self { return new self( + type: $attributes['type'], sequenceNumber: $attributes['sequence_number'], outputIndex: $attributes['output_index'], itemId: $attributes['item_id'], @@ -52,6 +54,7 @@ public static function from(array $attributes, MetaInformation $meta): self public function toArray(): array { return [ + 'type' => $this->type, 'sequence_number' => $this->sequenceNumber, 'output_index' => $this->outputIndex, 'item_id' => $this->itemId, diff --git a/src/Responses/Responses/Streaming/OutputItem.php b/src/Responses/Responses/Streaming/OutputItem.php index c485ce24..2a347f11 100644 --- a/src/Responses/Responses/Streaming/OutputItem.php +++ b/src/Responses/Responses/Streaming/OutputItem.php @@ -50,6 +50,7 @@ final class OutputItem implements ResponseContract, ResponseHasMetaInformationCo use HasMetaInformation; private function __construct( + public readonly string $type, public readonly int $outputIndex, public readonly OutputMessage|OutputCodeInterpreterToolCall|OutputFileSearchToolCall|OutputFunctionToolCall|OutputWebSearchToolCall|OutputComputerToolCall|OutputReasoning|OutputMcpListTools|OutputMcpApprovalRequest|OutputMcpCall|OutputImageGenerationToolCall $item, private readonly MetaInformation $meta, @@ -75,6 +76,7 @@ public static function from(array $attributes, MetaInformation $meta): self }; return new self( + type: $attributes['type'], outputIndex: $attributes['output_index'], item: $item, meta: $meta, @@ -87,6 +89,7 @@ public static function from(array $attributes, MetaInformation $meta): self public function toArray(): array { return [ + 'type' => $this->type, 'output_index' => $this->outputIndex, 'item' => $this->item->toArray(), ]; diff --git a/src/Responses/Responses/Streaming/OutputTextAnnotationAdded.php b/src/Responses/Responses/Streaming/OutputTextAnnotationAdded.php index 0ac460a2..d07bb3c4 100644 --- a/src/Responses/Responses/Streaming/OutputTextAnnotationAdded.php +++ b/src/Responses/Responses/Streaming/OutputTextAnnotationAdded.php @@ -36,6 +36,7 @@ final class OutputTextAnnotationAdded implements ResponseContract, ResponseHasMe use HasMetaInformation; private function __construct( + public readonly string $type, public readonly OutputMessageContentOutputTextAnnotationsContainerFile|OutputMessageContentOutputTextAnnotationsFileCitation|OutputMessageContentOutputTextAnnotationsFilePath|OutputMessageContentOutputTextAnnotationsUrlCitation $annotation, public readonly int $annotationIndex, public readonly int $contentIndex, @@ -57,6 +58,7 @@ public static function from(array $attributes, MetaInformation $meta): self }; return new self( + type: $attributes['type'], annotation: $annotation, annotationIndex: $attributes['annotation_index'], contentIndex: $attributes['content_index'], @@ -72,6 +74,7 @@ public static function from(array $attributes, MetaInformation $meta): self public function toArray(): array { return [ + 'type' => $this->type, 'annotation' => $this->annotation->toArray(), 'annotation_index' => $this->annotationIndex, 'content_index' => $this->contentIndex, diff --git a/src/Responses/Responses/Streaming/OutputTextDelta.php b/src/Responses/Responses/Streaming/OutputTextDelta.php index 6d5123b4..c294101b 100644 --- a/src/Responses/Responses/Streaming/OutputTextDelta.php +++ b/src/Responses/Responses/Streaming/OutputTextDelta.php @@ -27,6 +27,7 @@ final class OutputTextDelta implements ResponseContract, ResponseHasMetaInformat use HasMetaInformation; private function __construct( + public readonly string $type, public readonly int $contentIndex, public readonly string $delta, public readonly string $itemId, @@ -41,6 +42,7 @@ private function __construct( public static function from(array $attributes, MetaInformation $meta): self { return new self( + type: $attributes['type'], contentIndex: $attributes['content_index'], delta: $attributes['delta'], itemId: $attributes['item_id'], @@ -56,6 +58,7 @@ public static function from(array $attributes, MetaInformation $meta): self public function toArray(): array { return [ + 'type' => $this->type, 'content_index' => $this->contentIndex, 'delta' => $this->delta, 'item_id' => $this->itemId, diff --git a/src/Responses/Responses/Streaming/OutputTextDone.php b/src/Responses/Responses/Streaming/OutputTextDone.php index 7fe7e589..f474002f 100644 --- a/src/Responses/Responses/Streaming/OutputTextDone.php +++ b/src/Responses/Responses/Streaming/OutputTextDone.php @@ -27,6 +27,7 @@ final class OutputTextDone implements ResponseContract, ResponseHasMetaInformati use HasMetaInformation; private function __construct( + public readonly string $type, public readonly int $contentIndex, public readonly string $itemId, public readonly int $outputIndex, @@ -40,6 +41,7 @@ private function __construct( public static function from(array $attributes, MetaInformation $meta): self { return new self( + type: $attributes['type'], contentIndex: $attributes['content_index'], itemId: $attributes['item_id'], outputIndex: $attributes['output_index'], @@ -54,6 +56,7 @@ public static function from(array $attributes, MetaInformation $meta): self public function toArray(): array { return [ + 'type' => $this->type, 'content_index' => $this->contentIndex, 'item_id' => $this->itemId, 'output_index' => $this->outputIndex, diff --git a/src/Responses/Responses/Streaming/ReasoningSummaryPart.php b/src/Responses/Responses/Streaming/ReasoningSummaryPart.php index e39408c2..6d34ed85 100644 --- a/src/Responses/Responses/Streaming/ReasoningSummaryPart.php +++ b/src/Responses/Responses/Streaming/ReasoningSummaryPart.php @@ -30,6 +30,7 @@ final class ReasoningSummaryPart implements ResponseContract, ResponseHasMetaInf use HasMetaInformation; private function __construct( + public readonly string $type, public readonly string $itemId, public readonly int $outputIndex, public readonly OutputReasoningSummary $part, @@ -43,6 +44,7 @@ private function __construct( public static function from(array $attributes, MetaInformation $meta): self { return new self( + type: $attributes['type'], itemId: $attributes['item_id'], outputIndex: $attributes['output_index'], part: OutputReasoningSummary::from($attributes['part']), @@ -57,6 +59,7 @@ public static function from(array $attributes, MetaInformation $meta): self public function toArray(): array { return [ + 'type' => $this->type, 'item_id' => $this->itemId, 'output_index' => $this->outputIndex, 'part' => $this->part->toArray(), diff --git a/src/Responses/Responses/Streaming/ReasoningSummaryTextDelta.php b/src/Responses/Responses/Streaming/ReasoningSummaryTextDelta.php index 75dc420b..d7d310cc 100644 --- a/src/Responses/Responses/Streaming/ReasoningSummaryTextDelta.php +++ b/src/Responses/Responses/Streaming/ReasoningSummaryTextDelta.php @@ -27,6 +27,7 @@ final class ReasoningSummaryTextDelta implements ResponseContract, ResponseHasMe use HasMetaInformation; private function __construct( + public readonly string $type, public readonly string $delta, public readonly string $itemId, public readonly int $outputIndex, @@ -40,6 +41,7 @@ private function __construct( public static function from(array $attributes, MetaInformation $meta): self { return new self( + type: $attributes['type'], delta: $attributes['delta'], itemId: $attributes['item_id'], outputIndex: $attributes['output_index'], @@ -54,6 +56,7 @@ public static function from(array $attributes, MetaInformation $meta): self public function toArray(): array { return [ + 'type' => $this->type, 'delta' => $this->delta, 'item_id' => $this->itemId, 'output_index' => $this->outputIndex, diff --git a/src/Responses/Responses/Streaming/ReasoningSummaryTextDone.php b/src/Responses/Responses/Streaming/ReasoningSummaryTextDone.php index 260fc1b1..2f4678a5 100644 --- a/src/Responses/Responses/Streaming/ReasoningSummaryTextDone.php +++ b/src/Responses/Responses/Streaming/ReasoningSummaryTextDone.php @@ -27,6 +27,7 @@ final class ReasoningSummaryTextDone implements ResponseContract, ResponseHasMet use HasMetaInformation; private function __construct( + public readonly string $type, public readonly string $itemId, public readonly int $outputIndex, public readonly int $summaryIndex, @@ -40,6 +41,7 @@ private function __construct( public static function from(array $attributes, MetaInformation $meta): self { return new self( + type: $attributes['type'], itemId: $attributes['item_id'], outputIndex: $attributes['output_index'], summaryIndex: $attributes['summary_index'], @@ -54,6 +56,7 @@ public static function from(array $attributes, MetaInformation $meta): self public function toArray(): array { return [ + 'type' => $this->type, 'item_id' => $this->itemId, 'output_index' => $this->outputIndex, 'summary_index' => $this->summaryIndex, diff --git a/src/Responses/Responses/Streaming/ReasoningTextDelta.php b/src/Responses/Responses/Streaming/ReasoningTextDelta.php index 92f3098d..77b50292 100644 --- a/src/Responses/Responses/Streaming/ReasoningTextDelta.php +++ b/src/Responses/Responses/Streaming/ReasoningTextDelta.php @@ -27,6 +27,7 @@ final class ReasoningTextDelta implements ResponseContract, ResponseHasMetaInfor use HasMetaInformation; private function __construct( + public readonly string $type, public readonly int $contentIndex, public readonly string $delta, public readonly string $itemId, @@ -41,6 +42,7 @@ private function __construct( public static function from(array $attributes, MetaInformation $meta): self { return new self( + type: $attributes['type'], contentIndex: $attributes['content_index'], delta: $attributes['delta'], itemId: $attributes['item_id'], @@ -56,6 +58,7 @@ public static function from(array $attributes, MetaInformation $meta): self public function toArray(): array { return [ + 'type' => $this->type, 'content_index' => $this->contentIndex, 'delta' => $this->delta, 'item_id' => $this->itemId, diff --git a/src/Responses/Responses/Streaming/ReasoningTextDone.php b/src/Responses/Responses/Streaming/ReasoningTextDone.php index 0f5623b7..7a2208fe 100644 --- a/src/Responses/Responses/Streaming/ReasoningTextDone.php +++ b/src/Responses/Responses/Streaming/ReasoningTextDone.php @@ -27,6 +27,7 @@ final class ReasoningTextDone implements ResponseContract, ResponseHasMetaInform use HasMetaInformation; private function __construct( + public readonly string $type, public readonly int $contentIndex, public readonly string $itemId, public readonly int $outputIndex, @@ -41,6 +42,7 @@ private function __construct( public static function from(array $attributes, MetaInformation $meta): self { return new self( + type: $attributes['type'], contentIndex: $attributes['content_index'], itemId: $attributes['item_id'], outputIndex: $attributes['output_index'], @@ -56,6 +58,7 @@ public static function from(array $attributes, MetaInformation $meta): self public function toArray(): array { return [ + 'type' => $this->type, 'content_index' => $this->contentIndex, 'item_id' => $this->itemId, 'output_index' => $this->outputIndex, diff --git a/src/Responses/Responses/Streaming/RefusalDelta.php b/src/Responses/Responses/Streaming/RefusalDelta.php index 4791ba4a..500bd65f 100644 --- a/src/Responses/Responses/Streaming/RefusalDelta.php +++ b/src/Responses/Responses/Streaming/RefusalDelta.php @@ -27,6 +27,7 @@ final class RefusalDelta implements ResponseContract, ResponseHasMetaInformation use HasMetaInformation; private function __construct( + public readonly string $type, public readonly int $contentIndex, public readonly string $delta, public readonly string $itemId, @@ -40,6 +41,7 @@ private function __construct( public static function from(array $attributes, MetaInformation $meta): self { return new self( + type: $attributes['type'], contentIndex: $attributes['content_index'], delta: $attributes['delta'], itemId: $attributes['item_id'], @@ -54,6 +56,7 @@ public static function from(array $attributes, MetaInformation $meta): self public function toArray(): array { return [ + 'type' => $this->type, 'content_index' => $this->contentIndex, 'delta' => $this->delta, 'item_id' => $this->itemId, diff --git a/src/Responses/Responses/Streaming/RefusalDone.php b/src/Responses/Responses/Streaming/RefusalDone.php index 47365087..a7fe63e5 100644 --- a/src/Responses/Responses/Streaming/RefusalDone.php +++ b/src/Responses/Responses/Streaming/RefusalDone.php @@ -27,6 +27,7 @@ final class RefusalDone implements ResponseContract, ResponseHasMetaInformationC use HasMetaInformation; private function __construct( + public readonly string $type, public readonly int $contentIndex, public readonly string $itemId, public readonly int $outputIndex, @@ -40,6 +41,7 @@ private function __construct( public static function from(array $attributes, MetaInformation $meta): self { return new self( + type: $attributes['type'], contentIndex: $attributes['content_index'], itemId: $attributes['item_id'], outputIndex: $attributes['output_index'], @@ -54,6 +56,7 @@ public static function from(array $attributes, MetaInformation $meta): self public function toArray(): array { return [ + 'type' => $this->type, 'content_index' => $this->contentIndex, 'item_id' => $this->itemId, 'output_index' => $this->outputIndex, diff --git a/src/Responses/Responses/Streaming/Response.php b/src/Responses/Responses/Streaming/Response.php new file mode 100644 index 00000000..3519b98f --- /dev/null +++ b/src/Responses/Responses/Streaming/Response.php @@ -0,0 +1,61 @@ + + */ +final class Response implements ResponseContract, ResponseHasMetaInformationContract +{ + /** + * @use ArrayAccessible + */ + use ArrayAccessible; + + use Fakeable; + use HasMetaInformation; + + private function __construct( + public readonly string $type, + public readonly CreateResponse $response, + public readonly int $sequenceNumber, + private readonly MetaInformation $meta, + ) {} + + /** + * @param ResponseType $attributes + */ + public static function from(array $attributes, MetaInformation $meta): self + { + return new self( + type: $attributes['type'], + response: CreateResponse::from($attributes['response'], $meta), + sequenceNumber: $attributes['sequence_number'], + meta: $meta, + ); + } + + /** + * {@inheritDoc} + */ + public function toArray(): array + { + return [ + 'type' => $this->type, + 'response' => $this->response->toArray(), + 'sequence_number' => $this->sequenceNumber, + ]; + } +} diff --git a/src/Responses/Responses/Streaming/WebSearchCall.php b/src/Responses/Responses/Streaming/WebSearchCall.php index cb7e5a79..c347ebe6 100644 --- a/src/Responses/Responses/Streaming/WebSearchCall.php +++ b/src/Responses/Responses/Streaming/WebSearchCall.php @@ -27,6 +27,7 @@ final class WebSearchCall implements ResponseContract, ResponseHasMetaInformatio use HasMetaInformation; private function __construct( + public readonly string $type, public readonly string $itemId, public readonly int $outputIndex, private readonly MetaInformation $meta, @@ -38,6 +39,7 @@ private function __construct( public static function from(array $attributes, MetaInformation $meta): self { return new self( + type: $attributes['type'], itemId: $attributes['item_id'], outputIndex: $attributes['output_index'], meta: $meta, @@ -50,6 +52,7 @@ public static function from(array $attributes, MetaInformation $meta): self public function toArray(): array { return [ + 'type' => $this->type, 'item_id' => $this->itemId, 'output_index' => $this->outputIndex, ]; From 3330a3bf69b6f0b4edaafbf7802eb330aa8eeb9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mads=20Kildeg=C3=A5rd?= Date: Thu, 6 Nov 2025 09:21:55 +0100 Subject: [PATCH 2/2] fixed tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mads KildegÄrd --- .../Streaming/CodeInterpreterCall.php | 2 +- .../Streaming/CodeInterpreterCodeDelta.php | 2 +- .../Streaming/CodeInterpreterCodeDone.php | 2 +- .../Responses/Streaming/ContentPart.php | 2 +- src/Responses/Responses/Streaming/Error.php | 2 +- .../Responses/Streaming/FileSearchCall.php | 2 +- .../Streaming/FunctionCallArgumentsDelta.php | 2 +- .../Streaming/FunctionCallArgumentsDone.php | 2 +- .../Streaming/ImageGenerationPart.php | 2 +- .../Streaming/ImageGenerationPartialImage.php | 2 +- src/Responses/Responses/Streaming/McpCall.php | 2 +- .../Streaming/McpCallArgumentsDelta.php | 2 +- .../Streaming/McpCallArgumentsDone.php | 2 +- .../Responses/Streaming/McpListTools.php | 2 +- .../Streaming/McpListToolsInProgress.php | 2 +- .../Responses/Streaming/OutputItem.php | 2 +- .../Streaming/OutputTextAnnotationAdded.php | 2 +- .../Responses/Streaming/OutputTextDelta.php | 2 +- .../Responses/Streaming/OutputTextDone.php | 2 +- .../Streaming/ReasoningSummaryPart.php | 2 +- .../Streaming/ReasoningSummaryTextDelta.php | 2 +- .../Streaming/ReasoningSummaryTextDone.php | 2 +- .../Streaming/ReasoningTextDelta.php | 2 +- .../Responses/Streaming/ReasoningTextDone.php | 2 +- .../Responses/Streaming/RefusalDelta.php | 2 +- .../Responses/Streaming/RefusalDone.php | 2 +- .../Responses/Streaming/Response.php | 4 ++- .../Responses/Streaming/WebSearchCall.php | 2 +- .../CreateStreamedResponseFixture.txt | 18 +++++----- .../Streams/ResponseCompletionCreate.txt | 22 ++++++------ .../Streams/ResponseCreatedResponse.txt | 2 +- tests/Resources/Responses.php | 35 ++++++++++--------- .../Responses/CreateStreamedResponse.php | 13 ++++--- 33 files changed, 79 insertions(+), 69 deletions(-) diff --git a/src/Responses/Responses/Streaming/CodeInterpreterCall.php b/src/Responses/Responses/Streaming/CodeInterpreterCall.php index 3ae838de..88f92d9a 100644 --- a/src/Responses/Responses/Streaming/CodeInterpreterCall.php +++ b/src/Responses/Responses/Streaming/CodeInterpreterCall.php @@ -12,7 +12,7 @@ use OpenAI\Testing\Responses\Concerns\Fakeable; /** - * @phpstan-type CodeInterpreterCallType array{item_id: string, output_index: int} + * @phpstan-type CodeInterpreterCallType array{type: string, item_id: string, output_index: int} * * @implements ResponseContract */ diff --git a/src/Responses/Responses/Streaming/CodeInterpreterCodeDelta.php b/src/Responses/Responses/Streaming/CodeInterpreterCodeDelta.php index 001d64ab..1854ac90 100644 --- a/src/Responses/Responses/Streaming/CodeInterpreterCodeDelta.php +++ b/src/Responses/Responses/Streaming/CodeInterpreterCodeDelta.php @@ -12,7 +12,7 @@ use OpenAI\Testing\Responses\Concerns\Fakeable; /** - * @phpstan-type CodeInterpreterCodeDeltaType array{delta: string, item_id: string, output_index: int} + * @phpstan-type CodeInterpreterCodeDeltaType array{type: string, delta: string, item_id: string, output_index: int} * * @implements ResponseContract */ diff --git a/src/Responses/Responses/Streaming/CodeInterpreterCodeDone.php b/src/Responses/Responses/Streaming/CodeInterpreterCodeDone.php index edf3904d..a122bceb 100644 --- a/src/Responses/Responses/Streaming/CodeInterpreterCodeDone.php +++ b/src/Responses/Responses/Streaming/CodeInterpreterCodeDone.php @@ -12,7 +12,7 @@ use OpenAI\Testing\Responses\Concerns\Fakeable; /** - * @phpstan-type CodeInterpreterCodeDoneType array{code: string, item_id: string, output_index: int} + * @phpstan-type CodeInterpreterCodeDoneType array{type: string, code: string, item_id: string, output_index: int} * * @implements ResponseContract */ diff --git a/src/Responses/Responses/Streaming/ContentPart.php b/src/Responses/Responses/Streaming/ContentPart.php index f39c81e3..a7236cdf 100644 --- a/src/Responses/Responses/Streaming/ContentPart.php +++ b/src/Responses/Responses/Streaming/ContentPart.php @@ -17,7 +17,7 @@ * @phpstan-import-type OutputTextType from OutputMessageContentOutputText * @phpstan-import-type ContentRefusalType from OutputMessageContentRefusal * - * @phpstan-type ContentPartType array{content_index: int, item_id: string, output_index: int, part: OutputTextType|ContentRefusalType} + * @phpstan-type ContentPartType array{type: string, content_index: int, item_id: string, output_index: int, part: OutputTextType|ContentRefusalType} * * @implements ResponseContract */ diff --git a/src/Responses/Responses/Streaming/Error.php b/src/Responses/Responses/Streaming/Error.php index 3a6d2574..98f2c80c 100644 --- a/src/Responses/Responses/Streaming/Error.php +++ b/src/Responses/Responses/Streaming/Error.php @@ -12,7 +12,7 @@ use OpenAI\Testing\Responses\Concerns\Fakeable; /** - * @phpstan-type ErrorType array{code: string|null, message: string, param: string|null} + * @phpstan-type ErrorType array{type: string, code: string|null, message: string, param: string|null} * * @implements ResponseContract */ diff --git a/src/Responses/Responses/Streaming/FileSearchCall.php b/src/Responses/Responses/Streaming/FileSearchCall.php index 1b42b766..affe6401 100644 --- a/src/Responses/Responses/Streaming/FileSearchCall.php +++ b/src/Responses/Responses/Streaming/FileSearchCall.php @@ -12,7 +12,7 @@ use OpenAI\Testing\Responses\Concerns\Fakeable; /** - * @phpstan-type FileSearchCallType array{item_id: string, output_index: int} + * @phpstan-type FileSearchCallType array{type: string, item_id: string, output_index: int} * * @implements ResponseContract */ diff --git a/src/Responses/Responses/Streaming/FunctionCallArgumentsDelta.php b/src/Responses/Responses/Streaming/FunctionCallArgumentsDelta.php index ae2303a1..dc9c37cb 100644 --- a/src/Responses/Responses/Streaming/FunctionCallArgumentsDelta.php +++ b/src/Responses/Responses/Streaming/FunctionCallArgumentsDelta.php @@ -12,7 +12,7 @@ use OpenAI\Testing\Responses\Concerns\Fakeable; /** - * @phpstan-type FunctionCallArgumentsDeltaType array{delta: string, item_id: string, output_index: int} + * @phpstan-type FunctionCallArgumentsDeltaType array{type: string, delta: string, item_id: string, output_index: int} * * @implements ResponseContract */ diff --git a/src/Responses/Responses/Streaming/FunctionCallArgumentsDone.php b/src/Responses/Responses/Streaming/FunctionCallArgumentsDone.php index 0632c004..9e9949cb 100644 --- a/src/Responses/Responses/Streaming/FunctionCallArgumentsDone.php +++ b/src/Responses/Responses/Streaming/FunctionCallArgumentsDone.php @@ -12,7 +12,7 @@ use OpenAI\Testing\Responses\Concerns\Fakeable; /** - * @phpstan-type FunctionCallArgumentsDoneType array{arguments: string, item_id: string, output_index: int} + * @phpstan-type FunctionCallArgumentsDoneType array{type: string, arguments: string, item_id: string, output_index: int} * * @implements ResponseContract */ diff --git a/src/Responses/Responses/Streaming/ImageGenerationPart.php b/src/Responses/Responses/Streaming/ImageGenerationPart.php index 62cba9e8..79ba97af 100644 --- a/src/Responses/Responses/Streaming/ImageGenerationPart.php +++ b/src/Responses/Responses/Streaming/ImageGenerationPart.php @@ -12,7 +12,7 @@ use OpenAI\Testing\Responses\Concerns\Fakeable; /** - * @phpstan-type ImageGenerationPartType array{output_index: int, item_id: string, sequence_number: int} + * @phpstan-type ImageGenerationPartType array{type: string, output_index: int, item_id: string, sequence_number: int} * * @implements ResponseContract */ diff --git a/src/Responses/Responses/Streaming/ImageGenerationPartialImage.php b/src/Responses/Responses/Streaming/ImageGenerationPartialImage.php index 7c7f145b..36ff6e7b 100644 --- a/src/Responses/Responses/Streaming/ImageGenerationPartialImage.php +++ b/src/Responses/Responses/Streaming/ImageGenerationPartialImage.php @@ -12,7 +12,7 @@ use OpenAI\Testing\Responses\Concerns\Fakeable; /** - * @phpstan-type ImageGenerationPartialImageType array{output_index: int, item_id: string, sequence_number: int, partial_image_index: int, partial_image_b64: string} + * @phpstan-type ImageGenerationPartialImageType array{type: string, output_index: int, item_id: string, sequence_number: int, partial_image_index: int, partial_image_b64: string} * * @implements ResponseContract */ diff --git a/src/Responses/Responses/Streaming/McpCall.php b/src/Responses/Responses/Streaming/McpCall.php index 366f0fe7..c775ef8b 100644 --- a/src/Responses/Responses/Streaming/McpCall.php +++ b/src/Responses/Responses/Streaming/McpCall.php @@ -12,7 +12,7 @@ use OpenAI\Testing\Responses\Concerns\Fakeable; /** - * @phpstan-type McpCallType array{sequence_number: int} + * @phpstan-type McpCallType array{type: string, sequence_number: int} * * @implements ResponseContract */ diff --git a/src/Responses/Responses/Streaming/McpCallArgumentsDelta.php b/src/Responses/Responses/Streaming/McpCallArgumentsDelta.php index 76b79ac9..5336851e 100644 --- a/src/Responses/Responses/Streaming/McpCallArgumentsDelta.php +++ b/src/Responses/Responses/Streaming/McpCallArgumentsDelta.php @@ -12,7 +12,7 @@ use OpenAI\Testing\Responses\Concerns\Fakeable; /** - * @phpstan-type McpCallArgumentsDoneType array{sequence_number: int, output_index: int, item_id: string, delta: string} + * @phpstan-type McpCallArgumentsDoneType array{type: string, sequence_number: int, output_index: int, item_id: string, delta: string} * * @implements ResponseContract */ diff --git a/src/Responses/Responses/Streaming/McpCallArgumentsDone.php b/src/Responses/Responses/Streaming/McpCallArgumentsDone.php index 131d4e6d..5cbe95cc 100644 --- a/src/Responses/Responses/Streaming/McpCallArgumentsDone.php +++ b/src/Responses/Responses/Streaming/McpCallArgumentsDone.php @@ -12,7 +12,7 @@ use OpenAI\Testing\Responses\Concerns\Fakeable; /** - * @phpstan-type McpCallArgumentsDoneType array{sequence_number: int, output_index: int, item_id: string, arguments: string} + * @phpstan-type McpCallArgumentsDoneType array{type: string, sequence_number: int, output_index: int, item_id: string, arguments: string} * * @implements ResponseContract */ diff --git a/src/Responses/Responses/Streaming/McpListTools.php b/src/Responses/Responses/Streaming/McpListTools.php index 97a7a485..01b0ab35 100644 --- a/src/Responses/Responses/Streaming/McpListTools.php +++ b/src/Responses/Responses/Streaming/McpListTools.php @@ -12,7 +12,7 @@ use OpenAI\Testing\Responses\Concerns\Fakeable; /** - * @phpstan-type McpListToolsType array{sequence_number: int} + * @phpstan-type McpListToolsType array{type: string, sequence_number: int} * * @implements ResponseContract */ diff --git a/src/Responses/Responses/Streaming/McpListToolsInProgress.php b/src/Responses/Responses/Streaming/McpListToolsInProgress.php index 0dd9511b..a4864307 100644 --- a/src/Responses/Responses/Streaming/McpListToolsInProgress.php +++ b/src/Responses/Responses/Streaming/McpListToolsInProgress.php @@ -12,7 +12,7 @@ use OpenAI\Testing\Responses\Concerns\Fakeable; /** - * @phpstan-type McpListToolsType array{sequence_number: int, output_index: int, item_id: string} + * @phpstan-type McpListToolsType array{type: string, sequence_number: int, output_index: int, item_id: string} * * @implements ResponseContract */ diff --git a/src/Responses/Responses/Streaming/OutputItem.php b/src/Responses/Responses/Streaming/OutputItem.php index 2a347f11..1433b374 100644 --- a/src/Responses/Responses/Streaming/OutputItem.php +++ b/src/Responses/Responses/Streaming/OutputItem.php @@ -35,7 +35,7 @@ * @phpstan-import-type OutputMcpCallType from OutputMcpCall * @phpstan-import-type OutputCodeInterpreterToolCallType from OutputCodeInterpreterToolCall * - * @phpstan-type OutputItemType array{item: OutputCodeInterpreterToolCallType|OutputComputerToolCallType|OutputFileSearchToolCallType|OutputFunctionToolCallType|OutputMessageType|OutputReasoningType|OutputWebSearchToolCallType|OutputMcpListToolsType|OutputMcpApprovalRequestType|OutputMcpCallType|OutputImageGenerationToolCallType, output_index: int} + * @phpstan-type OutputItemType array{type: string, output_index: int, item: OutputCodeInterpreterToolCallType|OutputComputerToolCallType|OutputFileSearchToolCallType|OutputFunctionToolCallType|OutputMessageType|OutputReasoningType|OutputWebSearchToolCallType|OutputMcpListToolsType|OutputMcpApprovalRequestType|OutputMcpCallType|OutputImageGenerationToolCallType} * * @implements ResponseContract */ diff --git a/src/Responses/Responses/Streaming/OutputTextAnnotationAdded.php b/src/Responses/Responses/Streaming/OutputTextAnnotationAdded.php index d07bb3c4..7632bcc4 100644 --- a/src/Responses/Responses/Streaming/OutputTextAnnotationAdded.php +++ b/src/Responses/Responses/Streaming/OutputTextAnnotationAdded.php @@ -21,7 +21,7 @@ * @phpstan-import-type FilePathType from OutputMessageContentOutputTextAnnotationsFilePath * @phpstan-import-type UrlCitationType from OutputMessageContentOutputTextAnnotationsUrlCitation * - * @phpstan-type OutputTextAnnotationAddedType array{annotation: ContainerFileType|FileCitationType|FilePathType|UrlCitationType, annotation_index: int, content_index: int, item_id: string, output_index: int} + * @phpstan-type OutputTextAnnotationAddedType array{type: string, annotation: ContainerFileType|FileCitationType|FilePathType|UrlCitationType, annotation_index: int, content_index: int, item_id: string, output_index: int} * * @implements ResponseContract */ diff --git a/src/Responses/Responses/Streaming/OutputTextDelta.php b/src/Responses/Responses/Streaming/OutputTextDelta.php index c294101b..a6264862 100644 --- a/src/Responses/Responses/Streaming/OutputTextDelta.php +++ b/src/Responses/Responses/Streaming/OutputTextDelta.php @@ -12,7 +12,7 @@ use OpenAI\Testing\Responses\Concerns\Fakeable; /** - * @phpstan-type OutputTextType array{content_index: int, delta: string, item_id: string, output_index: int, sequence_number: int} + * @phpstan-type OutputTextType array{type: string, content_index: int, delta: string, item_id: string, output_index: int, sequence_number: int} * * @implements ResponseContract */ diff --git a/src/Responses/Responses/Streaming/OutputTextDone.php b/src/Responses/Responses/Streaming/OutputTextDone.php index f474002f..0d6ef6ea 100644 --- a/src/Responses/Responses/Streaming/OutputTextDone.php +++ b/src/Responses/Responses/Streaming/OutputTextDone.php @@ -12,7 +12,7 @@ use OpenAI\Testing\Responses\Concerns\Fakeable; /** - * @phpstan-type OutputTextDoneType array{content_index: int, item_id: string, output_index: int, text: string} + * @phpstan-type OutputTextDoneType array{type: string, content_index: int, item_id: string, output_index: int, text: string} * * @implements ResponseContract */ diff --git a/src/Responses/Responses/Streaming/ReasoningSummaryPart.php b/src/Responses/Responses/Streaming/ReasoningSummaryPart.php index 6d34ed85..7a3b2c99 100644 --- a/src/Responses/Responses/Streaming/ReasoningSummaryPart.php +++ b/src/Responses/Responses/Streaming/ReasoningSummaryPart.php @@ -15,7 +15,7 @@ /** * @phpstan-import-type ReasoningSummaryType from OutputReasoningSummary * - * @phpstan-type ReasoningSummaryPartType array{item_id: string, output_index: int, part: ReasoningSummaryType, summary_index: int} + * @phpstan-type ReasoningSummaryPartType array{type: string, item_id: string, output_index: int, part: ReasoningSummaryType, summary_index: int} * * @implements ResponseContract */ diff --git a/src/Responses/Responses/Streaming/ReasoningSummaryTextDelta.php b/src/Responses/Responses/Streaming/ReasoningSummaryTextDelta.php index d7d310cc..efd2f6b6 100644 --- a/src/Responses/Responses/Streaming/ReasoningSummaryTextDelta.php +++ b/src/Responses/Responses/Streaming/ReasoningSummaryTextDelta.php @@ -12,7 +12,7 @@ use OpenAI\Testing\Responses\Concerns\Fakeable; /** - * @phpstan-type ReasoningSummaryTextDeltaType array{delta: string, item_id: string, output_index: int, summary_index: int} + * @phpstan-type ReasoningSummaryTextDeltaType array{type: string, delta: string, item_id: string, output_index: int, summary_index: int} * * @implements ResponseContract */ diff --git a/src/Responses/Responses/Streaming/ReasoningSummaryTextDone.php b/src/Responses/Responses/Streaming/ReasoningSummaryTextDone.php index 2f4678a5..b0697fc2 100644 --- a/src/Responses/Responses/Streaming/ReasoningSummaryTextDone.php +++ b/src/Responses/Responses/Streaming/ReasoningSummaryTextDone.php @@ -12,7 +12,7 @@ use OpenAI\Testing\Responses\Concerns\Fakeable; /** - * @phpstan-type ReasoningSummaryTextDoneType array{item_id: string, output_index: int, summary_index: int, text: string} + * @phpstan-type ReasoningSummaryTextDoneType array{type: string, item_id: string, output_index: int, summary_index: int, text: string} * * @implements ResponseContract */ diff --git a/src/Responses/Responses/Streaming/ReasoningTextDelta.php b/src/Responses/Responses/Streaming/ReasoningTextDelta.php index 77b50292..3a6b703e 100644 --- a/src/Responses/Responses/Streaming/ReasoningTextDelta.php +++ b/src/Responses/Responses/Streaming/ReasoningTextDelta.php @@ -12,7 +12,7 @@ use OpenAI\Testing\Responses\Concerns\Fakeable; /** - * @phpstan-type ReasoningTextDeltaType array{content_index: int, delta: string, item_id: string, output_index: int, sequence_number: int} + * @phpstan-type ReasoningTextDeltaType array{type: string, content_index: int, delta: string, item_id: string, output_index: int, sequence_number: int} * * @implements ResponseContract */ diff --git a/src/Responses/Responses/Streaming/ReasoningTextDone.php b/src/Responses/Responses/Streaming/ReasoningTextDone.php index 7a2208fe..00ba48a1 100644 --- a/src/Responses/Responses/Streaming/ReasoningTextDone.php +++ b/src/Responses/Responses/Streaming/ReasoningTextDone.php @@ -12,7 +12,7 @@ use OpenAI\Testing\Responses\Concerns\Fakeable; /** - * @phpstan-type ReasoningTextDoneType array{content_index: int, item_id: string, output_index: int, sequence_number: int, text: string} + * @phpstan-type ReasoningTextDoneType array{type: string, content_index: int, item_id: string, output_index: int, sequence_number: int, text: string} * * @implements ResponseContract */ diff --git a/src/Responses/Responses/Streaming/RefusalDelta.php b/src/Responses/Responses/Streaming/RefusalDelta.php index 500bd65f..5f6e4205 100644 --- a/src/Responses/Responses/Streaming/RefusalDelta.php +++ b/src/Responses/Responses/Streaming/RefusalDelta.php @@ -12,7 +12,7 @@ use OpenAI\Testing\Responses\Concerns\Fakeable; /** - * @phpstan-type RefusalDeltaType array{content_index: int, delta: string, item_id: string, output_index: int} + * @phpstan-type RefusalDeltaType array{type: string, content_index: int, delta: string, item_id: string, output_index: int} * * @implements ResponseContract */ diff --git a/src/Responses/Responses/Streaming/RefusalDone.php b/src/Responses/Responses/Streaming/RefusalDone.php index a7fe63e5..ebeb5d7f 100644 --- a/src/Responses/Responses/Streaming/RefusalDone.php +++ b/src/Responses/Responses/Streaming/RefusalDone.php @@ -12,7 +12,7 @@ use OpenAI\Testing\Responses\Concerns\Fakeable; /** - * @phpstan-type RefusalDoneType array{content_index: int, item_id: string, output_index: int, refusal: string} + * @phpstan-type RefusalDoneType array{type: string, content_index: int, item_id: string, output_index: int, refusal: string} * * @implements ResponseContract */ diff --git a/src/Responses/Responses/Streaming/Response.php b/src/Responses/Responses/Streaming/Response.php index 3519b98f..3b925e6c 100644 --- a/src/Responses/Responses/Streaming/Response.php +++ b/src/Responses/Responses/Streaming/Response.php @@ -13,7 +13,9 @@ use OpenAI\Testing\Responses\Concerns\Fakeable; /** - * @phpstan-type ResponseType array{type: string, sequence_number: int} & CreateResponseType + * @phpstan-import-type CreateResponseType from CreateResponse + * + * @phpstan-type ResponseType array{type: string, response: CreateResponseType, sequence_number: int} * * @implements ResponseContract */ diff --git a/src/Responses/Responses/Streaming/WebSearchCall.php b/src/Responses/Responses/Streaming/WebSearchCall.php index c347ebe6..4cce78a1 100644 --- a/src/Responses/Responses/Streaming/WebSearchCall.php +++ b/src/Responses/Responses/Streaming/WebSearchCall.php @@ -12,7 +12,7 @@ use OpenAI\Testing\Responses\Concerns\Fakeable; /** - * @phpstan-type WebSearchCallType array{item_id: string, output_index: int} + * @phpstan-type WebSearchCallType array{type: string, item_id: string, output_index: int} * * @implements ResponseContract */ diff --git a/src/Testing/Responses/Fixtures/Responses/CreateStreamedResponseFixture.txt b/src/Testing/Responses/Fixtures/Responses/CreateStreamedResponseFixture.txt index b7b9311e..ccea0623 100644 --- a/src/Testing/Responses/Fixtures/Responses/CreateStreamedResponseFixture.txt +++ b/src/Testing/Responses/Fixtures/Responses/CreateStreamedResponseFixture.txt @@ -1,9 +1,9 @@ -data: {"type":"response.created","response":{"id":"resp_67c9fdcecf488190bdd9a0409de3a1ec07b8b0ad4e5eb654","object":"response","created_at":1741290958,"status":"in_progress","error":null,"incomplete_details":null,"instructions":"You are a helpful assistant.","max_output_tokens":null,"model":"gpt-4o-2024-08-06","output":[],"parallel_tool_calls":true,"previous_response_id":null,"reasoning":{"effort":null,"summary":null},"store":true,"temperature":1.0,"text":{"format":{"type":"text"}},"tool_choice":"auto","tools":[],"top_p":1.0,"truncation":"disabled","usage":null,"user":null,"metadata":{}}} -data: {"type":"response.in_progress","response":{"id":"resp_67c9fdcecf488190bdd9a0409de3a1ec07b8b0ad4e5eb654","object":"response","created_at":1741290958,"status":"in_progress","error":null,"incomplete_details":null,"instructions":"You are a helpful assistant.","max_output_tokens":null,"model":"gpt-4o-2024-08-06","output":[],"parallel_tool_calls":true,"previous_response_id":null,"reasoning":{"effort":null,"summary":null},"store":true,"temperature":1.0,"text":{"format":{"type":"text"}},"tool_choice":"auto","tools":[],"top_p":1.0,"truncation":"disabled","usage":null,"user":null,"metadata":{}}} -data: {"type":"response.output_item.added","output_index":0,"item":{"id":"msg_67c9fdcf37fc8190ba82116e33fb28c507b8b0ad4e5eb654","type":"message","status":"in_progress","role":"assistant","content":[]}} -data: {"type":"response.content_part.added","item_id":"msg_67c9fdcf37fc8190ba82116e33fb28c507b8b0ad4e5eb654","output_index":0,"content_index":0,"part":{"type":"output_text","text":"","annotations":[]}} -data: {"type":"response.output_text.delta","item_id":"msg_67c9fdcf37fc8190ba82116e33fb28c507b8b0ad4e5eb654","output_index":0,"content_index":0,"delta":"Hi"} -data: {"type":"response.output_text.done","item_id":"msg_67c9fdcf37fc8190ba82116e33fb28c507b8b0ad4e5eb654","output_index":0,"content_index":0,"text":"Hi there! How can I assist you today?"} -data: {"type":"response.content_part.done","item_id":"msg_67c9fdcf37fc8190ba82116e33fb28c507b8b0ad4e5eb654","output_index":0,"content_index":0,"part":{"type":"output_text","text":"Hi there! How can I assist you today?","annotations":[]}} -data: {"type":"response.output_item.done","output_index":0,"item":{"id":"msg_67c9fdcf37fc8190ba82116e33fb28c507b8b0ad4e5eb654","type":"message","status":"completed","role":"assistant","content":[{"type":"output_text","text":"Hi there! How can I assist you today?","annotations":[]}]}} -data: {"type":"response.completed","response":{"id":"resp_67c9fdcecf488190bdd9a0409de3a1ec07b8b0ad4e5eb654","object":"response","created_at":1741290958,"status":"completed","error":null,"incomplete_details":null,"instructions":"You are a helpful assistant.","max_output_tokens":null,"model":"gpt-4o-2024-08-06","output":[{"id":"msg_67c9fdcf37fc8190ba82116e33fb28c507b8b0ad4e5eb654","type":"message","status":"completed","role":"assistant","content":[{"type":"output_text","text":"Hi there! How can I assist you today?","annotations":[]}]}],"parallel_tool_calls":true,"previous_response_id":null,"reasoning":{"effort":null,"summary":null},"store":true,"temperature":1.0,"text":{"format":{"type":"text"}},"tool_choice":"auto","tools":[],"top_p":1.0,"truncation":"disabled","usage":{"input_tokens":37,"output_tokens":11,"output_tokens_details":{"reasoning_tokens":0},"total_tokens":48},"user":null,"metadata":{}}} +data: {"type":"response.created","response":{"id":"resp_67c9fdcecf488190bdd9a0409de3a1ec07b8b0ad4e5eb654","object":"response","created_at":1741290958,"status":"in_progress","error":null,"incomplete_details":null,"instructions":"You are a helpful assistant.","max_output_tokens":null,"model":"gpt-4o-2024-08-06","output":[],"parallel_tool_calls":true,"previous_response_id":null,"reasoning":{"effort":null,"summary":null},"store":true,"temperature":1.0,"text":{"format":{"type":"text"}},"tool_choice":"auto","tools":[],"top_p":1.0,"truncation":"disabled","usage":null,"user":null,"metadata":{}}, "sequence_number": 1} +data: {"type":"response.in_progress","response":{"id":"resp_67c9fdcecf488190bdd9a0409de3a1ec07b8b0ad4e5eb654","object":"response","created_at":1741290958,"status":"in_progress","error":null,"incomplete_details":null,"instructions":"You are a helpful assistant.","max_output_tokens":null,"model":"gpt-4o-2024-08-06","output":[],"parallel_tool_calls":true,"previous_response_id":null,"reasoning":{"effort":null,"summary":null},"store":true,"temperature":1.0,"text":{"format":{"type":"text"}},"tool_choice":"auto","tools":[],"top_p":1.0,"truncation":"disabled","usage":null,"user":null,"metadata":{}}, "sequence_number": 2} +data: {"type":"response.output_item.added","output_index":0,"item":{"id":"msg_67c9fdcf37fc8190ba82116e33fb28c507b8b0ad4e5eb654","type":"message","status":"in_progress","role":"assistant","content":[]}, "sequence_number": 3} +data: {"type":"response.content_part.added","item_id":"msg_67c9fdcf37fc8190ba82116e33fb28c507b8b0ad4e5eb654","output_index":0,"content_index":0,"part":{"type":"output_text","text":"","annotations":[]}, "sequence_number": 4} +data: {"type":"response.output_text.delta","item_id":"msg_67c9fdcf37fc8190ba82116e33fb28c507b8b0ad4e5eb654","output_index":0,"content_index":0,"delta":"Hi", "sequence_number": 5} +data: {"type":"response.output_text.done","item_id":"msg_67c9fdcf37fc8190ba82116e33fb28c507b8b0ad4e5eb654","output_index":0,"content_index":0,"text":"Hi there! How can I assist you today?", "sequence_number": 6} +data: {"type":"response.content_part.done","item_id":"msg_67c9fdcf37fc8190ba82116e33fb28c507b8b0ad4e5eb654","output_index":0,"content_index":0,"part":{"type":"output_text","text":"Hi there! How can I assist you today?","annotations":[]}, "sequence_number": 7} +data: {"type":"response.output_item.done","output_index":0,"item":{"id":"msg_67c9fdcf37fc8190ba82116e33fb28c507b8b0ad4e5eb654","type":"message","status":"completed","role":"assistant","content":[{"type":"output_text","text":"Hi there! How can I assist you today?","annotations":[]}]}, "sequence_number": 8} +data: {"type":"response.completed","response":{"id":"resp_67c9fdcecf488190bdd9a0409de3a1ec07b8b0ad4e5eb654","object":"response","created_at":1741290958,"status":"completed","error":null,"incomplete_details":null,"instructions":"You are a helpful assistant.","max_output_tokens":null,"model":"gpt-4o-2024-08-06","output":[{"id":"msg_67c9fdcf37fc8190ba82116e33fb28c507b8b0ad4e5eb654","type":"message","status":"completed","role":"assistant","content":[{"type":"output_text","text":"Hi there! How can I assist you today?","annotations":[]}]}],"parallel_tool_calls":true,"previous_response_id":null,"reasoning":{"effort":null,"summary":null},"store":true,"temperature":1.0,"text":{"format":{"type":"text"}},"tool_choice":"auto","tools":[],"top_p":1.0,"truncation":"disabled","usage":{"input_tokens":37,"output_tokens":11,"output_tokens_details":{"reasoning_tokens":0},"total_tokens":48},"user":null,"metadata":{}}, "sequence_number": 9} diff --git a/tests/Fixtures/Streams/ResponseCompletionCreate.txt b/tests/Fixtures/Streams/ResponseCompletionCreate.txt index e7fe7825..9af4a86d 100644 --- a/tests/Fixtures/Streams/ResponseCompletionCreate.txt +++ b/tests/Fixtures/Streams/ResponseCompletionCreate.txt @@ -1,11 +1,11 @@ -data: {"type":"response.created","response":{"id":"resp_67ccf18ef5fc8190b16dbee19bc54e5f087bb177ab789d5c","object":"response","created_at":1741484430,"status":"in_progress","error":null,"incomplete_details":null,"instructions":null,"max_output_tokens":null,"model":"gpt-4o-2024-08-06","output":[],"parallel_tool_calls":true,"previous_response_id":null,"reasoning":{"effort":null,"generate_summary":null},"store":true,"temperature":1.0,"text":{"format":{"type":"text"}},"tool_choice":"auto","tools":[{"type":"web_search_preview","domains":[],"search_context_size":"medium","user_location":{"type":"approximate","city":null,"country":"US","region":null,"timezone":null}}],"top_p":1.0,"truncation":"disabled","usage":null,"user":null,"metadata":{}}} -data: {"type":"response.in_progress","response":{"id":"resp_67ccf18ef5fc8190b16dbee19bc54e5f087bb177ab789d5c","object":"response","created_at":1741484430,"status":"in_progress","error":null,"incomplete_details":null,"instructions":null,"max_output_tokens":null,"model":"gpt-4o-2024-08-06","output":[],"parallel_tool_calls":true,"previous_response_id":null,"reasoning":{"effort":null,"generate_summary":null},"store":true,"temperature":1.0,"text":{"format":{"type":"text"}},"tool_choice":"auto","tools":[{"type":"web_search_preview","domains":[],"search_context_size":"medium","user_location":{"type":"approximate","city":null,"country":"US","region":null,"timezone":null}}],"top_p":1.0,"truncation":"disabled","usage":null,"user":null,"metadata":{}}} -data: {"type":"response.output_item.added","output_index":0,"item":{"id":"ws_67ccf18f64008190a39b619f4c8455ef087bb177ab789d5c","type":"web_search_call","status":"in_progress"}} -data: {"type":"response.output_item.done","output_index":0,"item":{"id":"ws_67ccf18f64008190a39b619f4c8455ef087bb177ab789d5c","type":"web_search_call","status":"completed","action":{"type":"search","query":"what was a positive news story from today?","sources":[{"type":"url","url":"https://example.com/news/positive-story"},{"type":"url","url":"https://another.example.com/related-article"}]}}} -data: {"type":"response.output_item.added","output_index":1,"item":{"id":"msg_67ccf190ca3881909d433c50b1f6357e087bb177ab789d5c","type":"message","status":"in_progress","role":"assistant","content":[]}} -data: {"type":"response.content_part.added","item_id":"msg_67ccf190ca3881909d433c50b1f6357e087bb177ab789d5c","output_index":1,"content_index":0,"part":{"type":"output_text","text":"","annotations":[]}} -data: {"type":"response.output_text.delta","item_id":"msg_67ccf190ca3881909d433c50b1f6357e087bb177ab789d5c","output_index":1,"content_index":0,"delta":"As of today, March 9, 2025, one notable positive news story..."} -data: {"type":"response.output_text.done","item_id":"msg_67ccf190ca3881909d433c50b1f6357e087bb177ab789d5c","output_index":1,"content_index":0,"text":"As of today, March 9, 2025, one notable positive news story..."} -data: {"type":"response.content_part.done","item_id":"msg_67ccf190ca3881909d433c50b1f6357e087bb177ab789d5c","output_index":1,"content_index":0,"part":{"type":"output_text","text":"As of today, March 9, 2025, one notable positive news story...","annotations":[{"type":"url_citation","start_index":442,"end_index":557,"url":"https://.../?utm_source=chatgpt.com","title":"..."},{"type":"url_citation","start_index":962,"end_index":1077,"url":"https://.../?utm_source=chatgpt.com","title":"..."},{"type":"url_citation","start_index":1336,"end_index":1451,"url":"https://.../?utm_source=chatgpt.com","title":"..."}]}} -data: {"type":"response.output_item.done","output_index":1,"item":{"id":"msg_67ccf190ca3881909d433c50b1f6357e087bb177ab789d5c","type":"message","status":"completed","role":"assistant","content":[{"type":"output_text","text":"As of today, March 9, 2025, one notable positive news story...","annotations":[{"type":"url_citation","start_index":442,"end_index":557,"url":"https://.../?utm_source=chatgpt.com","title":"..."},{"type":"url_citation","start_index":962,"end_index":1077,"url":"https://.../?utm_source=chatgpt.com","title":"..."},{"type":"url_citation","start_index":1336,"end_index":1451,"url":"https://.../?utm_source=chatgpt.com","title":"..."}]}]}} -data: {"type":"response.completed","response":{"id":"resp_67ccf18ef5fc8190b16dbee19bc54e5f087bb177ab789d5c","object":"response","created_at":1741484430,"status":"completed","error":null,"incomplete_details":null,"instructions":null,"max_output_tokens":null,"model":"gpt-4o-2024-08-06","output":[{"type":"web_search_call","id":"ws_67ccf18f64008190a39b619f4c8455ef087bb177ab789d5c","status":"completed","action":{"type":"search","query":"what was a positive news story from today?","sources":[{"type":"url","url":"https://example.com/news/positive-story"},{"type":"url","url":"https://another.example.com/related-article"}]}},{"type":"message","id":"msg_67ccf190ca3881909d433c50b1f6357e087bb177ab789d5c","status":"completed","role":"assistant","content":[{"type":"output_text","text":"As of today, March 9, 2025, one notable positive news story...","annotations":[{"type":"url_citation","start_index":442,"end_index":557,"url":"https://.../?utm_source=chatgpt.com","title":"..."},{"type":"url_citation","start_index":962,"end_index":1077,"url":"https://.../?utm_source=chatgpt.com","title":"..."},{"type":"url_citation","start_index":1336,"end_index":1451,"url":"https://.../?utm_source=chatgpt.com","title":"..."}]}]}],"parallel_tool_calls":true,"previous_response_id":null,"reasoning":{"effort":null,"generate_summary":null},"store":true,"temperature":1.0,"text":{"format":{"type":"text"}},"tool_choice":"auto","tools":[{"type":"web_search_preview","domains":[],"search_context_size":"medium","user_location":{"type":"approximate","city":null,"country":"US","region":null,"timezone":null}}],"top_p":1.0,"truncation":"disabled","usage":{"input_tokens":328,"input_tokens_details":{"cached_tokens":0},"output_tokens":356,"output_tokens_details":{"reasoning_tokens":0},"total_tokens":684},"user":null,"metadata":{}}} +data: {"type":"response.created","response":{"id":"resp_67ccf18ef5fc8190b16dbee19bc54e5f087bb177ab789d5c","object":"response","created_at":1741484430,"status":"in_progress","error":null,"incomplete_details":null,"instructions":null,"max_output_tokens":null,"model":"gpt-4o-2024-08-06","output":[],"parallel_tool_calls":true,"previous_response_id":null,"reasoning":{"effort":null,"generate_summary":null},"store":true,"temperature":1.0,"text":{"format":{"type":"text"}},"tool_choice":"auto","tools":[{"type":"web_search_preview","domains":[],"search_context_size":"medium","user_location":{"type":"approximate","city":null,"country":"US","region":null,"timezone":null}}],"top_p":1.0,"truncation":"disabled","usage":null,"user":null,"metadata":{}}, "sequence_number": 1} +data: {"type":"response.in_progress","response":{"id":"resp_67ccf18ef5fc8190b16dbee19bc54e5f087bb177ab789d5c","object":"response","created_at":1741484430,"status":"in_progress","error":null,"incomplete_details":null,"instructions":null,"max_output_tokens":null,"model":"gpt-4o-2024-08-06","output":[],"parallel_tool_calls":true,"previous_response_id":null,"reasoning":{"effort":null,"generate_summary":null},"store":true,"temperature":1.0,"text":{"format":{"type":"text"}},"tool_choice":"auto","tools":[{"type":"web_search_preview","domains":[],"search_context_size":"medium","user_location":{"type":"approximate","city":null,"country":"US","region":null,"timezone":null}}],"top_p":1.0,"truncation":"disabled","usage":null,"user":null,"metadata":{}}, "sequence_number": 2} +data: {"type":"response.output_item.added","output_index":0,"item":{"id":"ws_67ccf18f64008190a39b619f4c8455ef087bb177ab789d5c","type":"web_search_call","status":"in_progress"}, "sequence_number": 3} +data: {"type":"response.output_item.done","output_index":0,"item":{"id":"ws_67ccf18f64008190a39b619f4c8455ef087bb177ab789d5c","type":"web_search_call","status":"completed","action":{"type":"search","query":"what was a positive news story from today?","sources":[{"type":"url","url":"https://example.com/news/positive-story"},{"type":"url","url":"https://another.example.com/related-article"}]}}, "sequence_number": 4} +data: {"type":"response.output_item.added","output_index":1,"item":{"id":"msg_67ccf190ca3881909d433c50b1f6357e087bb177ab789d5c","type":"message","status":"in_progress","role":"assistant","content":[]}, "sequence_number": 5} +data: {"type":"response.content_part.added","item_id":"msg_67ccf190ca3881909d433c50b1f6357e087bb177ab789d5c","output_index":1,"content_index":0,"part":{"type":"output_text","text":"","annotations":[]}, "sequence_number": 6} +data: {"type":"response.output_text.delta","item_id":"msg_67ccf190ca3881909d433c50b1f6357e087bb177ab789d5c","output_index":1,"content_index":0,"delta":"As of today, March 9, 2025, one notable positive news story...", "sequence_number": 7} +data: {"type":"response.output_text.done","item_id":"msg_67ccf190ca3881909d433c50b1f6357e087bb177ab789d5c","output_index":1,"content_index":0,"text":"As of today, March 9, 2025, one notable positive news story...", "sequence_number": 8} +data: {"type":"response.content_part.done","item_id":"msg_67ccf190ca3881909d433c50b1f6357e087bb177ab789d5c","output_index":1,"content_index":0,"part":{"type":"output_text","text":"As of today, March 9, 2025, one notable positive news story...","annotations":[{"type":"url_citation","start_index":442,"end_index":557,"url":"https://.../?utm_source=chatgpt.com","title":"..."},{"type":"url_citation","start_index":962,"end_index":1077,"url":"https://.../?utm_source=chatgpt.com","title":"..."},{"type":"url_citation","start_index":1336,"end_index":1451,"url":"https://.../?utm_source=chatgpt.com","title":"..."}]}, "sequence_number": 9} +data: {"type":"response.output_item.done","output_index":1,"item":{"id":"msg_67ccf190ca3881909d433c50b1f6357e087bb177ab789d5c","type":"message","status":"completed","role":"assistant","content":[{"type":"output_text","text":"As of today, March 9, 2025, one notable positive news story...","annotations":[{"type":"url_citation","start_index":442,"end_index":557,"url":"https://.../?utm_source=chatgpt.com","title":"..."},{"type":"url_citation","start_index":962,"end_index":1077,"url":"https://.../?utm_source=chatgpt.com","title":"..."},{"type":"url_citation","start_index":1336,"end_index":1451,"url":"https://.../?utm_source=chatgpt.com","title":"..."}]}]}, "sequence_number": 10} +data: {"type":"response.completed","response":{"id":"resp_67ccf18ef5fc8190b16dbee19bc54e5f087bb177ab789d5c","object":"response","created_at":1741484430,"status":"completed","error":null,"incomplete_details":null,"instructions":null,"max_output_tokens":null,"model":"gpt-4o-2024-08-06","output":[{"type":"web_search_call","id":"ws_67ccf18f64008190a39b619f4c8455ef087bb177ab789d5c","status":"completed","action":{"type":"search","query":"what was a positive news story from today?","sources":[{"type":"url","url":"https://example.com/news/positive-story"},{"type":"url","url":"https://another.example.com/related-article"}]}},{"type":"message","id":"msg_67ccf190ca3881909d433c50b1f6357e087bb177ab789d5c","status":"completed","role":"assistant","content":[{"type":"output_text","text":"As of today, March 9, 2025, one notable positive news story...","annotations":[{"type":"url_citation","start_index":442,"end_index":557,"url":"https://.../?utm_source=chatgpt.com","title":"..."},{"type":"url_citation","start_index":962,"end_index":1077,"url":"https://.../?utm_source=chatgpt.com","title":"..."},{"type":"url_citation","start_index":1336,"end_index":1451,"url":"https://.../?utm_source=chatgpt.com","title":"..."}]}]}],"parallel_tool_calls":true,"previous_response_id":null,"reasoning":{"effort":null,"generate_summary":null},"store":true,"temperature":1.0,"text":{"format":{"type":"text"}},"tool_choice":"auto","tools":[{"type":"web_search_preview","domains":[],"search_context_size":"medium","user_location":{"type":"approximate","city":null,"country":"US","region":null,"timezone":null}}],"top_p":1.0,"truncation":"disabled","usage":{"input_tokens":328,"input_tokens_details":{"cached_tokens":0},"output_tokens":356,"output_tokens_details":{"reasoning_tokens":0},"total_tokens":684},"user":null,"metadata":{}}, "sequence_number": 11} diff --git a/tests/Fixtures/Streams/ResponseCreatedResponse.txt b/tests/Fixtures/Streams/ResponseCreatedResponse.txt index 1d549c49..ef4594c5 100644 --- a/tests/Fixtures/Streams/ResponseCreatedResponse.txt +++ b/tests/Fixtures/Streams/ResponseCreatedResponse.txt @@ -1 +1 @@ -data: {"type":"response.created","response":{"id":"resp_67ccf18ef5fc8190b16dbee19bc54e5f087bb177ab789d5c","object":"response","created_at":1741484430,"status":"in_progress","error":null,"incomplete_details":null,"instructions":null,"max_output_tokens":null,"model":"gpt-4o-2024-08-06","output":[],"parallel_tool_calls":true,"previous_response_id":null,"reasoning":{"effort":null,"generate_summary":null},"store":true,"temperature":1.0,"text":{"format":{"type":"text"}},"tool_choice":"auto","tools":[{"type":"web_search_preview","domains":[],"search_context_size":"medium","user_location":{"type":"approximate","city":null,"country":"US","region":null,"timezone":null}}],"top_p":1.0,"truncation":"disabled","usage":null,"user":null,"metadata":{}}} +data: {"type":"response.created","response":{"id":"resp_67ccf18ef5fc8190b16dbee19bc54e5f087bb177ab789d5c","object":"response","created_at":1741484430,"status":"in_progress","error":null,"incomplete_details":null,"instructions":null,"max_output_tokens":null,"model":"gpt-4o-2024-08-06","output":[],"parallel_tool_calls":true,"previous_response_id":null,"reasoning":{"effort":null,"generate_summary":null},"store":true,"temperature":1.0,"text":{"format":{"type":"text"}},"tool_choice":"auto","tools":[{"type":"web_search_preview","domains":[],"search_context_size":"medium","user_location":{"type":"approximate","city":null,"country":"US","region":null,"timezone":null}}],"top_p":1.0,"truncation":"disabled","usage":null,"user":null,"metadata":{}}, "sequence_number": 1} diff --git a/tests/Resources/Responses.php b/tests/Resources/Responses.php index d59b608a..d032e66a 100644 --- a/tests/Resources/Responses.php +++ b/tests/Resources/Responses.php @@ -9,6 +9,7 @@ use OpenAI\Responses\Responses\ListInputItems; use OpenAI\Responses\Responses\ReferencePromptObject; use OpenAI\Responses\Responses\RetrieveResponse; +use OpenAI\Responses\Responses\Streaming\Response as StreamedResponse; use OpenAI\Responses\StreamResponse; test('create', function () { @@ -131,38 +132,40 @@ expect($current->event) ->toBe('response.created'); expect($current->response) + ->toBeInstanceOf(StreamedResponse::class); + expect($current->response->response) ->toBeInstanceOf(CreateResponse::class); - expect($current->response->id) + expect($current->response->response->id) ->toBe('resp_67ccf18ef5fc8190b16dbee19bc54e5f087bb177ab789d5c'); - expect($current->response->object) + expect($current->response->response->object) ->toBe('response'); - expect($current->response->createdAt) + expect($current->response->response->createdAt) ->toBe(1741484430); - expect($current->response->status) + expect($current->response->response->status) ->toBe('in_progress'); - expect($current->response->error) + expect($current->response->response->error) ->toBeNull(); - expect($current->response->incompleteDetails) + expect($current->response->response->incompleteDetails) ->toBeNull(); - expect($current->response->instructions) + expect($current->response->response->instructions) ->toBeNull(); - expect($current->response->maxOutputTokens) + expect($current->response->response->maxOutputTokens) ->toBeNull(); - expect($current->response->model) + expect($current->response->response->model) ->toBe('gpt-4o-2024-08-06'); - expect($current->response->output) + expect($current->response->response->output) ->toBeArray(); - expect($current->response->output) + expect($current->response->response->output) ->toHaveCount(0); - expect($current->response->parallelToolCalls) + expect($current->response->response->parallelToolCalls) ->toBeTrue(); - expect($current->response->previousResponseId) + expect($current->response->response->previousResponseId) ->toBeNull(); - expect($current->response->temperature) + expect($current->response->response->temperature) ->toBe(1.0); - expect($current->response->toolChoice) + expect($current->response->response->toolChoice) ->toBe('auto'); - expect($current->response->topP) + expect($current->response->response->topP) ->toBe(1.0); expect($result->meta()) diff --git a/tests/Responses/Responses/CreateStreamedResponse.php b/tests/Responses/Responses/CreateStreamedResponse.php index 49d6f56f..5c56a74b 100644 --- a/tests/Responses/Responses/CreateStreamedResponse.php +++ b/tests/Responses/Responses/CreateStreamedResponse.php @@ -4,13 +4,16 @@ use OpenAI\Responses\Responses\CreateStreamedResponse; use OpenAI\Responses\Responses\Streaming\ReasoningTextDelta; use OpenAI\Responses\Responses\Streaming\ReasoningTextDone; +use OpenAI\Responses\Responses\Streaming\Response; test('fake', function () { $response = CreateStreamedResponse::fake(); expect($response->getIterator()->current()->response) - ->toBeInstanceOf(CreateResponse::class) - ->id->toBe('resp_67c9fdcecf488190bdd9a0409de3a1ec07b8b0ad4e5eb654'); + ->toBeInstanceOf(Response::class) + ->type->toBe('response.created') + ->response->toBeInstanceOf(CreateResponse::class) + ->response->id->toBe('resp_67c9fdcecf488190bdd9a0409de3a1ec07b8b0ad4e5eb654'); }); test('from', function () { @@ -19,8 +22,10 @@ expect($response->getIterator()->current()) ->toBeInstanceOf(CreateStreamedResponse::class) ->event->toBe('response.created') - ->response->toBeInstanceOf(CreateResponse::class) - ->response->id->toBe('resp_67ccf18ef5fc8190b16dbee19bc54e5f087bb177ab789d5c'); + ->response->toBeInstanceOf(Response::class) + ->response->type->toBe('response.created') + ->response->response->toBeInstanceOf(CreateResponse::class) + ->response->response->id->toBe('resp_67ccf18ef5fc8190b16dbee19bc54e5f087bb177ab789d5c'); }); test('reasoning text delta event', function () {