| 1: | <?php |
| 2: | |
| 3: | declare(strict_types=1); |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | |
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | |
| 14: | namespace Nexus\Mcp\Schema\Tool\ToolSchema; |
| 15: | |
| 16: | |
| 17: | |
| 18: | |
| 19: | |
| 20: | |
| 21: | |
| 22: | |
| 23: | |
| 24: | |
| 25: | |
| 26: | |
| 27: | |
| 28: | |
| 29: | |
| 30: | |
| 31: | |
| 32: | |
| 33: | final class ArrayType extends ToolSchema |
| 34: | { |
| 35: | |
| 36: | |
| 37: | |
| 38: | private ?int $minItems = null; |
| 39: | |
| 40: | |
| 41: | |
| 42: | |
| 43: | private ?int $maxItems = null; |
| 44: | |
| 45: | private ?bool $uniqueItems = null; |
| 46: | |
| 47: | |
| 48: | |
| 49: | |
| 50: | private ?array $prefixItems = null; |
| 51: | |
| 52: | |
| 53: | |
| 54: | |
| 55: | private ?array $items = null; |
| 56: | |
| 57: | public function minItems(int $minItems): self |
| 58: | { |
| 59: | if ($minItems < 0) { |
| 60: | throw new \InvalidArgumentException('The minimum number of items must be a non-negative integer.'); |
| 61: | } |
| 62: | |
| 63: | $this->minItems = $minItems; |
| 64: | |
| 65: | return $this; |
| 66: | } |
| 67: | |
| 68: | public function maxItems(int $maxItems): self |
| 69: | { |
| 70: | if ($maxItems < 0) { |
| 71: | throw new \InvalidArgumentException('The maximum number of items must be a non-negative integer.'); |
| 72: | } |
| 73: | |
| 74: | $this->maxItems = $maxItems; |
| 75: | |
| 76: | return $this; |
| 77: | } |
| 78: | |
| 79: | public function uniqueItems(bool $uniqueItems): self |
| 80: | { |
| 81: | $this->uniqueItems = $uniqueItems; |
| 82: | |
| 83: | return $this; |
| 84: | } |
| 85: | |
| 86: | |
| 87: | |
| 88: | |
| 89: | |
| 90: | |
| 91: | |
| 92: | |
| 93: | |
| 94: | |
| 95: | |
| 96: | public function prefixItems(ToolSchema $prefixItems): self |
| 97: | { |
| 98: | $this->prefixItems = $prefixItems->toArray(); |
| 99: | |
| 100: | return $this; |
| 101: | } |
| 102: | |
| 103: | |
| 104: | |
| 105: | |
| 106: | |
| 107: | |
| 108: | |
| 109: | |
| 110: | |
| 111: | |
| 112: | |
| 113: | public function items(ToolSchema $items): self |
| 114: | { |
| 115: | $this->items = $items->toArray(); |
| 116: | |
| 117: | return $this; |
| 118: | } |
| 119: | |
| 120: | #[\Override] |
| 121: | public function toArray(): array |
| 122: | { |
| 123: | return array_filter([ |
| 124: | 'type' => 'array', |
| 125: | 'description' => $this->description, |
| 126: | 'title' => $this->title, |
| 127: | 'minItems' => $this->minItems, |
| 128: | 'maxItems' => $this->maxItems, |
| 129: | 'uniqueItems' => $this->uniqueItems, |
| 130: | 'prefixItems' => $this->prefixItems, |
| 131: | 'items' => $this->items, |
| 132: | 'default' => $this->default, |
| 133: | ], static fn(mixed $value): bool => null !== $value); |
| 134: | } |
| 135: | } |
| 136: | |