PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 2.4.4
Booking for Appointments and Events Calendar – Amelia v2.4.4
2.4.4 2.4.3 2.4.2 2.4.1 2.4 trunk 1.2.1 1.2.10 1.2.11 1.2.12 1.2.13 1.2.14 1.2.15 1.2.16 1.2.17 1.2.18 1.2.19 1.2.2 1.2.20 1.2.21 1.2.22 1.2.23 1.2.24 1.2.25 1.2.26 1.2.27 1.2.28 1.2.29 1.2.3 1.2.30 1.2.31 1.2.32 1.2.33 1.2.34 1.2.35 1.2.36 1.2.37 1.2.38 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.1.3 2.2 2.2.1 2.3
ameliabooking / vendor / wordpress / php-mcp-schema / src / Server / Prompts / DTO / PromptMessage.php
ameliabooking / vendor / wordpress / php-mcp-schema / src / Server / Prompts / DTO Last commit date
GetPromptRequest.php 1 month ago GetPromptRequestParams.php 1 month ago GetPromptResult.php 1 month ago ListPromptsRequest.php 1 month ago ListPromptsResult.php 1 month ago Prompt.php 1 month ago PromptArgument.php 1 month ago PromptListChangedNotification.php 1 month ago PromptMessage.php 1 month ago
PromptMessage.php
114 lines
1 <?php
2
3 declare(strict_types=1);
4
5 namespace WP\McpSchema\Server\Prompts\DTO;
6
7 use WP\McpSchema\Common\AbstractDataTransferObject;
8 use WP\McpSchema\Common\Protocol\Factory\ContentBlockFactory;
9 use WP\McpSchema\Common\Protocol\Union\ContentBlockInterface;
10 use WP\McpSchema\Common\Traits\ValidatesRequiredFields;
11
12 /**
13 * Describes a message returned as part of a prompt.
14 *
15 * This is similar to `SamplingMessage`, but also supports the embedding of
16 * resources from the MCP server.
17 *
18 * @since 2024-11-05
19 * @last-updated 2025-11-25 (modified properties: content, role)
20 *
21 * @mcp-domain Server
22 * @mcp-subdomain Prompts
23 * @mcp-version 2025-11-25
24 */
25 class PromptMessage extends AbstractDataTransferObject
26 {
27 use ValidatesRequiredFields;
28
29 /**
30 * @since 2024-11-05
31 *
32 * @var 'user'|'assistant'
33 */
34 protected string $role;
35
36 /**
37 * @since 2024-11-05
38 *
39 * @var \WP\McpSchema\Common\Protocol\Union\ContentBlockInterface
40 */
41 protected ContentBlockInterface $content;
42
43 /**
44 * @param 'user'|'assistant' $role @since 2024-11-05
45 * @param \WP\McpSchema\Common\Protocol\Union\ContentBlockInterface $content @since 2024-11-05
46 */
47 public function __construct(
48 string $role,
49 ContentBlockInterface $content
50 ) {
51 $this->role = $role;
52 $this->content = $content;
53 }
54
55 /**
56 * Creates an instance from an array.
57 *
58 * @param array{
59 * role: 'user'|'assistant',
60 * content: array<string, mixed>|\WP\McpSchema\Common\Protocol\Union\ContentBlockInterface
61 * } $data
62 * @phpstan-param array<string, mixed> $data
63 * @return self
64 */
65 public static function fromArray(array $data): self
66 {
67 self::assertRequired($data, ['role', 'content']);
68
69 /** @var 'user'|'assistant' $role */
70 $role = self::asString($data['role']);
71
72 /** @var \WP\McpSchema\Common\Protocol\Union\ContentBlockInterface $content */
73 $content = is_array($data['content'])
74 ? ContentBlockFactory::fromArray(self::asArray($data['content']))
75 : $data['content'];
76
77 return new self(
78 $role,
79 $content
80 );
81 }
82
83 /**
84 * Converts the instance to an array.
85 *
86 * @return array<string, mixed>
87 */
88 public function toArray(): array
89 {
90 $result = [];
91
92 $result['role'] = $this->role;
93 $result['content'] = $this->content->toArray();
94
95 return $result;
96 }
97
98 /**
99 * @return 'user'|'assistant'
100 */
101 public function getRole(): string
102 {
103 return $this->role;
104 }
105
106 /**
107 * @return \WP\McpSchema\Common\Protocol\Union\ContentBlockInterface
108 */
109 public function getContent(): ContentBlockInterface
110 {
111 return $this->content;
112 }
113 }
114