| 1: | <?php |
| 2: | |
| 3: | declare(strict_types=1); |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | |
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | |
| 14: | namespace Nexus\Mcp\Schema\Content; |
| 15: | |
| 16: | use Nexus\Mcp\Schema\Annotations; |
| 17: | use Nexus\Mcp\Schema\Arrayable; |
| 18: | |
| 19: | |
| 20: | |
| 21: | |
| 22: | |
| 23: | |
| 24: | |
| 25: | |
| 26: | |
| 27: | |
| 28: | |
| 29: | |
| 30: | |
| 31: | final readonly class EmbeddedResource implements \JsonSerializable, Arrayable, ContentBlock |
| 32: | { |
| 33: | |
| 34: | |
| 35: | |
| 36: | public string $type; |
| 37: | |
| 38: | |
| 39: | |
| 40: | |
| 41: | |
| 42: | |
| 43: | public function __construct( |
| 44: | public BlobResourceContents|TextResourceContents $resource, |
| 45: | public ?Annotations $annotations = null, |
| 46: | public ?array $meta = null, |
| 47: | ) { |
| 48: | $this->type = 'resource'; |
| 49: | } |
| 50: | |
| 51: | #[\Override] |
| 52: | public function toArray(): array |
| 53: | { |
| 54: | return array_filter([ |
| 55: | '_meta' => $this->meta, |
| 56: | 'type' => $this->type, |
| 57: | 'resource' => $this->resource->toArray(), |
| 58: | 'annotations' => $this->annotations?->toArray(), |
| 59: | ], static fn(mixed $value): bool => null !== $value); |
| 60: | } |
| 61: | |
| 62: | |
| 63: | |
| 64: | |
| 65: | #[\Override] |
| 66: | public function jsonSerialize(): array |
| 67: | { |
| 68: | return $this->toArray(); |
| 69: | } |
| 70: | } |
| 71: | |