| 1: | <?php |
| 2: | |
| 3: | declare(strict_types=1); |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | |
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | |
| 14: | namespace Nexus\Mcp\Core\Schema\Sampling; |
| 15: | |
| 16: | use Nexus\Assert\Assert; |
| 17: | use Nexus\Mcp\Core\Schema\Arrayable; |
| 18: | |
| 19: | |
| 20: | |
| 21: | |
| 22: | |
| 23: | |
| 24: | |
| 25: | |
| 26: | |
| 27: | |
| 28: | |
| 29: | final readonly class ModelHint implements Arrayable |
| 30: | { |
| 31: | |
| 32: | |
| 33: | |
| 34: | public ?string $name; |
| 35: | |
| 36: | public function __construct(?string $name = null) |
| 37: | { |
| 38: | Assert::that($name)->nullOr()->isNonEmptyString('"hints.name" must be a non-empty string or null.'); |
| 39: | |
| 40: | $this->name = $name; |
| 41: | } |
| 42: | |
| 43: | |
| 44: | |
| 45: | |
| 46: | #[\Override] |
| 47: | public static function fromArray(array $data): static |
| 48: | { |
| 49: | $name = $data['name'] ?? null; |
| 50: | Assert::that($name)->nullOr()->isString('"hints.name" must be a string or null, {type} given.'); |
| 51: | |
| 52: | return new self($name); |
| 53: | } |
| 54: | |
| 55: | #[\Override] |
| 56: | public function toArray(): array |
| 57: | { |
| 58: | if (null === $this->name) { |
| 59: | return []; |
| 60: | } |
| 61: | |
| 62: | return ['name' => $this->name]; |
| 63: | } |
| 64: | |
| 65: | #[\Override] |
| 66: | public function jsonSerialize(): array|\stdClass |
| 67: | { |
| 68: | $data = $this->toArray(); |
| 69: | |
| 70: | return [] === $data ? new \stdClass() : $data; |
| 71: | } |
| 72: | } |
| 73: | |