Adopt Schema component in server handlers

This commit is contained in:
Christopher Hertel 2025-08-03 22:06:46 +02:00
commit 09707b4798
No known key found for this signature in database
GPG key ID: 111F6BFF7B6B5AA3

View file

@ -26,34 +26,20 @@ 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
* @param ?array<string, mixed> $_meta optional metadata to include in the request
*/
public function __construct(
string|int $id,
public readonly PromptReference|ResourceReference $ref,
public readonly array $argument,
public readonly ?array $_meta = null,
) {
$params = [
'ref' => $this->ref,
'argument' => $this->argument,
];
if (null !== $this->_meta) {
$params['_meta'] = $this->_meta;
}
parent::__construct($id, 'completion/complete', $params);
}
public static function fromRequest(Request $request): self
public static function getMethod(): string
{
if ('completion/complete' !== $request->method) {
throw new InvalidArgumentException('Request is not a completion/complete request');
}
$params = $request->params;
return 'completion/complete';
}
protected static function fromParams(?array $params): Request
{
if (!isset($params['ref']) || !\is_array($params['ref'])) {
throw new InvalidArgumentException('Missing or invalid "ref" parameter for completion/complete.');
}
@ -68,6 +54,14 @@ class CompletionCompleteRequest extends Request
throw new InvalidArgumentException('Missing or invalid "argument" parameter for completion/complete.');
}
return new self($request->id, $ref, $params['argument'], $params['_meta'] ?? null);
return new self($ref, $params['argument']);
}
protected function getParams(): ?array
{
return [
'ref' => $this->ref,
'argument' => $this->argument,
];
}
}