Roll out meta properties in attributes and more schema classes (#129)
This commit is contained in:
parent
09596c0382
commit
d3a07912b0
1 changed files with 178 additions and 88 deletions
|
|
@ -22,6 +22,7 @@ use Mcp\Exception\InvalidArgumentException;
|
|||
* name: string,
|
||||
* description?: string,
|
||||
* arguments?: PromptArgumentData[],
|
||||
* _meta?: array<string, mixed>
|
||||
* }
|
||||
*
|
||||
* @author Kyrian Obikwelu <koshnawaza@gmail.com>
|
||||
|
|
@ -32,11 +33,13 @@ class Prompt implements \JsonSerializable
|
|||
* @param string $name the name of the prompt or prompt template
|
||||
* @param string|null $description an optional description of what this prompt provides
|
||||
* @param PromptArgument[]|null $arguments A list of arguments for templating. Null if not a template.
|
||||
* @param ?array<string, mixed> $meta Optional metadata
|
||||
*/
|
||||
public function __construct(
|
||||
public readonly string $name,
|
||||
public readonly ?string $description = null,
|
||||
public readonly ?array $arguments = null,
|
||||
public readonly ?array $meta = null,
|
||||
) {
|
||||
if (null !== $this->arguments) {
|
||||
foreach ($this->arguments as $arg) {
|
||||
|
|
@ -60,10 +63,15 @@ class Prompt implements \JsonSerializable
|
|||
$arguments = array_map(fn (array $argData) => PromptArgument::fromArray($argData), $data['arguments']);
|
||||
}
|
||||
|
||||
if (!empty($data['_meta']) && !\is_array($data['_meta'])) {
|
||||
throw new InvalidArgumentException('Invalid "_meta" in Prompt data.');
|
||||
}
|
||||
|
||||
return new self(
|
||||
name: $data['name'],
|
||||
description: $data['description'] ?? null,
|
||||
arguments: $arguments
|
||||
arguments: $arguments,
|
||||
meta: isset($data['_meta']) ? $data['_meta'] : null
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -71,7 +79,8 @@ class Prompt implements \JsonSerializable
|
|||
* @return array{
|
||||
* name: string,
|
||||
* description?: string,
|
||||
* arguments?: array<PromptArgument>
|
||||
* arguments?: array<PromptArgument>,
|
||||
* _meta?: array<string, mixed>
|
||||
* }
|
||||
*/
|
||||
public function jsonSerialize(): array
|
||||
|
|
@ -83,6 +92,9 @@ class Prompt implements \JsonSerializable
|
|||
if (null !== $this->arguments) {
|
||||
$data['arguments'] = $this->arguments;
|
||||
}
|
||||
if (null !== $this->meta) {
|
||||
$data['_meta'] = $this->meta;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue