| 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: | final readonly class TextContent implements \JsonSerializable, Arrayable, ContentBlock |
| 30: | { |
| 31: | |
| 32: | |
| 33: | |
| 34: | public string $type; |
| 35: | |
| 36: | |
| 37: | |
| 38: | |
| 39: | |
| 40: | |
| 41: | |
| 42: | public function __construct( |
| 43: | public string $text, |
| 44: | public ?Annotations $annotations = null, |
| 45: | public ?array $meta = null, |
| 46: | ) { |
| 47: | $this->type = 'text'; |
| 48: | } |
| 49: | |
| 50: | #[\Override] |
| 51: | public function toArray(): array |
| 52: | { |
| 53: | return array_filter([ |
| 54: | '_meta' => $this->meta, |
| 55: | 'type' => $this->type, |
| 56: | 'text' => $this->text, |
| 57: | 'annotations' => $this->annotations?->toArray(), |
| 58: | ], static fn(mixed $value): bool => null !== $value); |
| 59: | } |
| 60: | |
| 61: | |
| 62: | |
| 63: | |
| 64: | #[\Override] |
| 65: | public function jsonSerialize(): array |
| 66: | { |
| 67: | return $this->toArray(); |
| 68: | } |
| 69: | } |
| 70: | |