Skip to content

Commit 4342636

Browse files
Merge branch 'dto-serlialization' into extender-dtos
2 parents 7c13ac1 + cb985cc commit 4342636

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

src/Files/DTO/File.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,10 +403,14 @@ public function toArray(): array
403403
'mimeType' => $this->getMimeType(),
404404
];
405405

406-
if ($this->fileType->isRemote() && $this->url !== null) {
406+
if ($this->url !== null) {
407407
$data['url'] = $this->url;
408408
} elseif ($this->base64Data !== null) {
409409
$data['base64Data'] = $this->base64Data;
410+
} else {
411+
throw new RuntimeException(
412+
'File requires either url or base64Data. This should not be a possible condition.'
413+
);
410414
}
411415

412416
return $data;

src/Messages/DTO/Message.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public function toArray(): array
122122
*
123123
* @since n.e.x.t
124124
*
125-
* @return UserMessage|ModelMessage|SystemMessage
125+
* @return Message The specific message class based on the role.
126126
*/
127127
final public static function fromArray(array $array): Message
128128
{

src/Messages/DTO/MessagePart.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace WordPress\AiClient\Messages\DTO;
66

77
use InvalidArgumentException;
8+
use RuntimeException;
89
use WordPress\AiClient\Common\AbstractDataValueObject;
910
use WordPress\AiClient\Files\DTO\File;
1011
use WordPress\AiClient\Messages\Enums\MessagePartTypeEnum;
@@ -229,14 +230,19 @@ public function toArray(): array
229230
{
230231
$data = ['type' => $this->type->value];
231232

232-
if ($this->type->isText() && $this->text !== null) {
233+
if ($this->text !== null) {
233234
$data['text'] = $this->text;
234-
} elseif ($this->type->isFile() && $this->file !== null) {
235+
} elseif ($this->file !== null) {
235236
$data['file'] = $this->file->toArray();
236-
} elseif ($this->type->isFunctionCall() && $this->functionCall !== null) {
237+
} elseif ($this->functionCall !== null) {
237238
$data['functionCall'] = $this->functionCall->toArray();
238-
} elseif ($this->type->isFunctionResponse() && $this->functionResponse !== null) {
239+
} elseif ($this->functionResponse !== null) {
239240
$data['functionResponse'] = $this->functionResponse->toArray();
241+
} else {
242+
throw new RuntimeException(
243+
'MessagePart requires one of: text, file, functionCall, or functionResponse. '
244+
. 'This should not be a possible condition.'
245+
);
240246
}
241247

242248
return $data;

0 commit comments

Comments
 (0)