| 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\Mcp\Core\Schema\Arrayable; |
| 17: | use Nexus\Mcp\Core\Schema\Enum\ToolChoiceMode; |
| 18: | use Nexus\Mcp\Core\Validation\EnumValueValidator; |
| 19: | |
| 20: | |
| 21: | |
| 22: | |
| 23: | |
| 24: | |
| 25: | |
| 26: | |
| 27: | final readonly class ToolChoice implements Arrayable |
| 28: | { |
| 29: | public function __construct(public ?ToolChoiceMode $mode = null) |
| 30: | { |
| 31: | } |
| 32: | |
| 33: | |
| 34: | |
| 35: | |
| 36: | #[\Override] |
| 37: | public static function fromArray(array $data): static |
| 38: | { |
| 39: | $mode = null; |
| 40: | |
| 41: | if (\array_key_exists('mode', $data)) { |
| 42: | $mode = EnumValueValidator::parse(ToolChoiceMode::class, $data['mode'], '"toolChoice.mode"'); |
| 43: | } |
| 44: | |
| 45: | return new self($mode); |
| 46: | } |
| 47: | |
| 48: | #[\Override] |
| 49: | public function toArray(): array |
| 50: | { |
| 51: | if (null === $this->mode) { |
| 52: | return []; |
| 53: | } |
| 54: | |
| 55: | return ['mode' => $this->mode->value]; |
| 56: | } |
| 57: | |
| 58: | #[\Override] |
| 59: | public function jsonSerialize(): array|\stdClass |
| 60: | { |
| 61: | $data = $this->toArray(); |
| 62: | |
| 63: | return [] === $data ? new \stdClass() : $data; |
| 64: | } |
| 65: | } |
| 66: | |