| 1: | <?php |
| 2: | |
| 3: | declare(strict_types=1); |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | |
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | |
| 14: | namespace Nexus\Mcp\Schema\Result; |
| 15: | |
| 16: | |
| 17: | |
| 18: | |
| 19: | |
| 20: | |
| 21: | |
| 22: | |
| 23: | |
| 24: | final readonly class CompleteResult extends Result implements ServerResult |
| 25: | { |
| 26: | |
| 27: | |
| 28: | |
| 29: | public array $completion; |
| 30: | |
| 31: | |
| 32: | |
| 33: | |
| 34: | |
| 35: | |
| 36: | |
| 37: | |
| 38: | public function __construct(array $values, ?int $total = null, ?bool $hasMore = null, ?array $meta = null) |
| 39: | { |
| 40: | if (\count($values) > 100) { |
| 41: | throw new \InvalidArgumentException('The number of completion values must not exceed 100 items.'); |
| 42: | } |
| 43: | |
| 44: | $this->completion = array_filter([ |
| 45: | 'hasMore' => $hasMore, |
| 46: | 'total' => $total, |
| 47: | 'values' => $values, |
| 48: | ], static fn(mixed $value): bool => null !== $value); |
| 49: | |
| 50: | parent::__construct($meta); |
| 51: | } |
| 52: | |
| 53: | #[\Override] |
| 54: | public function toArray(): array |
| 55: | { |
| 56: | return array_filter([ |
| 57: | '_meta' => $this->meta, |
| 58: | 'completion' => $this->completion, |
| 59: | ], static fn(mixed $value): bool => null !== $value); |
| 60: | } |
| 61: | } |
| 62: | |