| 1: | <?php |
| 2: | |
| 3: | declare(strict_types=1); |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | |
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | |
| 14: | namespace Nexus\Mcp\Schema\Request; |
| 15: | |
| 16: | use Nexus\Mcp\Schema\Arrayable; |
| 17: | use Nexus\Mcp\Schema\Completion\PromptReference; |
| 18: | use Nexus\Mcp\Schema\Completion\ResourceTemplateReference; |
| 19: | use Nexus\Mcp\Schema\Message\JsonRpcRequest; |
| 20: | use Nexus\Mcp\Schema\Message\RequestId; |
| 21: | |
| 22: | |
| 23: | |
| 24: | |
| 25: | |
| 26: | |
| 27: | |
| 28: | |
| 29: | |
| 30: | |
| 31: | |
| 32: | |
| 33: | |
| 34: | |
| 35: | |
| 36: | |
| 37: | final readonly class CompleteRequest extends JsonRpcRequest implements ClientRequest |
| 38: | { |
| 39: | |
| 40: | |
| 41: | |
| 42: | |
| 43: | |
| 44: | |
| 45: | |
| 46: | public function __construct( |
| 47: | RequestId $id, |
| 48: | PromptReference|ResourceTemplateReference $ref, |
| 49: | array $argument, |
| 50: | ?array $context = null, |
| 51: | ?array $meta = null, |
| 52: | ) { |
| 53: | if (! \array_key_exists('name', $argument) || ! \is_string($argument['name']) || '' === $argument['name']) { |
| 54: | throw new \InvalidArgumentException('The "name" key in $argument must be a non-empty string.'); |
| 55: | } |
| 56: | |
| 57: | if (! \array_key_exists('value', $argument) || ! \is_string($argument['value']) || '' === $argument['value']) { |
| 58: | throw new \InvalidArgumentException('The "value" key in $argument must be a non-empty string.'); |
| 59: | } |
| 60: | |
| 61: | $context = isset($context) ? ['arguments' => $context] : null; |
| 62: | |
| 63: | parent::__construct(self::JSON_RPC_VERSION, $id, 'completion/complete', array_filter([ |
| 64: | '_meta' => $meta, |
| 65: | 'ref' => $ref->toArray(), |
| 66: | 'argument' => ['name' => $argument['name'], 'value' => $argument['value']], |
| 67: | 'context' => $context, |
| 68: | ], static fn(mixed $value): bool => null !== $value)); |
| 69: | } |
| 70: | } |
| 71: | |