*/ final class CompletionCompleteRequest extends Request { /** * @param PromptReference|ResourceReference $ref the prompt or resource to complete * @param array{ name: string, value: string } $argument the argument to complete */ public function __construct( public readonly PromptReference|ResourceReference $ref, public readonly array $argument, ) { } public static function getMethod(): string { return 'completion/complete'; } protected static function fromParams(?array $params): static { if (!isset($params['ref']) || !\is_array($params['ref'])) { throw new InvalidArgumentException('Missing or invalid "ref" parameter for completion/complete.'); } $ref = match ($params['ref']['type'] ?? null) { 'ref/prompt' => new PromptReference($params['ref']['name']), 'ref/resource' => new ResourceReference($params['ref']['uri']), default => throw new InvalidArgumentException('Invalid "ref" parameter for completion/complete.'), }; if (!isset($params['argument']) || !\is_array($params['argument'])) { throw new InvalidArgumentException('Missing or invalid "argument" parameter for completion/complete.'); } return new self($ref, $params['argument']); } /** * @return array{ * ref: PromptReference|ResourceReference, * argument: array{ name: string, value: string } * } */ protected function getParams(): array { return [ 'ref' => $this->ref, 'argument' => $this->argument, ]; } }