CreateMessageRequest.php
2 months ago
CreateMessageRequestParams.php
2 months ago
CreateMessageResult.php
2 months ago
ModelHint.php
2 months ago
ModelPreferences.php
2 months ago
SamplingMessage.php
2 months ago
ToolChoice.php
2 months ago
ToolResultContent.php
2 months ago
ToolUseContent.php
2 months ago
ModelHint.php
92 lines
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace WP\McpSchema\Client\Sampling\DTO; |
| 6 | |
| 7 | use WP\McpSchema\Common\AbstractDataTransferObject; |
| 8 | use WP\McpSchema\Common\Traits\ValidatesRequiredFields; |
| 9 | |
| 10 | /** |
| 11 | * Hints to use for model selection. |
| 12 | * |
| 13 | * Keys not declared here are currently left unspecified by the spec and are up |
| 14 | * to the client to interpret. |
| 15 | * |
| 16 | * @since 2024-11-05 |
| 17 | * |
| 18 | * @mcp-domain Client |
| 19 | * @mcp-subdomain Sampling |
| 20 | * @mcp-version 2025-11-25 |
| 21 | */ |
| 22 | class ModelHint extends AbstractDataTransferObject |
| 23 | { |
| 24 | use ValidatesRequiredFields; |
| 25 | |
| 26 | /** |
| 27 | * A hint for a model name. |
| 28 | * |
| 29 | * The client SHOULD treat this as a substring of a model name; for example: |
| 30 | * - `claude-3-5-sonnet` should match `claude-3-5-sonnet-20241022` |
| 31 | * - `sonnet` should match `claude-3-5-sonnet-20241022`, `claude-3-sonnet-20240229`, etc. |
| 32 | * - `claude` should match any Claude model |
| 33 | * |
| 34 | * The client MAY also map the string to a different provider's model name or a different model family, as long as it fills a similar niche; for example: |
| 35 | * - `gemini-1.5-flash` could match `claude-3-haiku-20240307` |
| 36 | * |
| 37 | * @since 2024-11-05 |
| 38 | * |
| 39 | * @var string|null |
| 40 | */ |
| 41 | protected ?string $name; |
| 42 | |
| 43 | /** |
| 44 | * @param string|null $name @since 2024-11-05 |
| 45 | */ |
| 46 | public function __construct( |
| 47 | ?string $name = null |
| 48 | ) { |
| 49 | $this->name = $name; |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Creates an instance from an array. |
| 54 | * |
| 55 | * @param array{ |
| 56 | * name?: string|null |
| 57 | * } $data |
| 58 | * @phpstan-param array<string, mixed> $data |
| 59 | * @return self |
| 60 | */ |
| 61 | public static function fromArray(array $data): self |
| 62 | { |
| 63 | return new self( |
| 64 | self::asStringOrNull($data['name'] ?? null) |
| 65 | ); |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Converts the instance to an array. |
| 70 | * |
| 71 | * @return array<string, mixed> |
| 72 | */ |
| 73 | public function toArray(): array |
| 74 | { |
| 75 | $result = []; |
| 76 | |
| 77 | if ($this->name !== null) { |
| 78 | $result['name'] = $this->name; |
| 79 | } |
| 80 | |
| 81 | return $result; |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * @return string|null |
| 86 | */ |
| 87 | public function getName(): ?string |
| 88 | { |
| 89 | return $this->name; |
| 90 | } |
| 91 | } |
| 92 |