PluginProbe
ZIP AI – AI Website Builder & AI Agent (Beta) / 0.0.8
ZIP AI – AI Website Builder & AI Agent (Beta) v0.0.8
0.0.11 0.0.10 0.0.9 trunk 0.0.4 0.0.5 0.0.6 0.0.7 0.0.8
zip-ai / lib / php-mcp-schema / src / Client / Elicitation / DTO / ElicitRequestFormParams.php

ElicitRequestFormParams.php in ZIP AI – AI Website Builder & AI Agent (Beta) 0.0.8, at lib/php-mcp-schema/src/Client/Elicitation/DTO/ElicitRequestFormParams.php

163 lines 4.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 declare(strict_types=1);
4
5 namespace WP\McpSchema\Client\Elicitation\DTO;
6
7 use WP\McpSchema\Client\Elicitation\Union\ElicitRequestParamsInterface;
8 use WP\McpSchema\Client\Tasks\DTO\TaskMetadata;
9 use WP\McpSchema\Common\JsonRpc\DTO\RequestParamsMeta;
10 use WP\McpSchema\Common\Tasks\DTO\TaskAugmentedRequestParams;
11 use WP\McpSchema\Common\Traits\ValidatesRequiredFields;
12
13 /**
14 * The parameters for a request to elicit non-sensitive information from the user via a form in the client.
15 *
16 * @since 2025-11-25
17 *
18 * @mcp-domain Client
19 * @mcp-subdomain Elicitation
20 * @mcp-version 2025-11-25
21 */
22 class ElicitRequestFormParams extends TaskAugmentedRequestParams implements ElicitRequestParamsInterface
23 {
24 use ValidatesRequiredFields;
25
26 public const MODE = 'form';
27
28 public const DISCRIMINATOR_FIELD = 'mode';
29 public const DISCRIMINATOR_VALUE = 'form';
30
31 /**
32 * The elicitation mode.
33 *
34 * @since 2025-11-25
35 *
36 * @var 'form'|null
37 */
38 protected ?string $mode;
39
40 /**
41 * The message to present to the user describing what information is being requested.
42 *
43 * @since 2025-11-25
44 *
45 * @var string
46 */
47 protected string $message;
48
49 /**
50 * A restricted subset of JSON Schema.
51 * Only top-level properties are allowed, without nesting.
52 *
53 * @since 2025-11-25
54 *
55 * @var \WP\McpSchema\Client\Elicitation\DTO\ElicitRequestFormParamsRequestedSchema
56 */
57 protected ElicitRequestFormParamsRequestedSchema $requestedSchema;
58
59 /**
60 * @param string $message @since 2025-11-25
61 * @param \WP\McpSchema\Client\Elicitation\DTO\ElicitRequestFormParamsRequestedSchema $requestedSchema @since 2025-11-25
62 * @param \WP\McpSchema\Client\Tasks\DTO\TaskMetadata|null $task @since 2025-11-25
63 * @param \WP\McpSchema\Common\JsonRpc\DTO\RequestParamsMeta|null $_meta @since 2025-11-25
64 */
65 public function __construct(
66 string $message,
67 ElicitRequestFormParamsRequestedSchema $requestedSchema,
68 ?TaskMetadata $task = null,
69 ?RequestParamsMeta $_meta = null
70 ) {
71 parent::__construct($_meta, $task);
72 $this->mode = self::MODE;
73 $this->message = $message;
74 $this->requestedSchema = $requestedSchema;
75 }
76
77 /**
78 * Creates an instance from an array.
79 *
80 * @param array{
81 * task?: array<string, mixed>|\WP\McpSchema\Client\Tasks\DTO\TaskMetadata|null,
82 * _meta?: array<string, mixed>|\WP\McpSchema\Common\JsonRpc\DTO\RequestParamsMeta|null,
83 * mode?: 'form'|null,
84 * message: string,
85 * requestedSchema: array<string, mixed>|\WP\McpSchema\Client\Elicitation\DTO\ElicitRequestFormParamsRequestedSchema
86 * } $data
87 * @phpstan-param array<string, mixed> $data
88 * @return self
89 */
90 public static function fromArray(array $data): self
91 {
92 self::assertRequired($data, ['message', 'requestedSchema']);
93
94 /** @var \WP\McpSchema\Client\Elicitation\DTO\ElicitRequestFormParamsRequestedSchema $requestedSchema */
95 $requestedSchema = is_array($data['requestedSchema'])
96 ? ElicitRequestFormParamsRequestedSchema::fromArray(self::asArray($data['requestedSchema']))
97 : $data['requestedSchema'];
98
99 /** @var \WP\McpSchema\Client\Tasks\DTO\TaskMetadata|null $task */
100 $task = isset($data['task'])
101 ? (is_array($data['task'])
102 ? TaskMetadata::fromArray(self::asArray($data['task']))
103 : $data['task'])
104 : null;
105
106 /** @var \WP\McpSchema\Common\JsonRpc\DTO\RequestParamsMeta|null $_meta */
107 $_meta = isset($data['_meta'])
108 ? (is_array($data['_meta'])
109 ? RequestParamsMeta::fromArray(self::asArray($data['_meta']))
110 : $data['_meta'])
111 : null;
112
113 return new self(
114 self::asString($data['message']),
115 $requestedSchema,
116 $task,
117 $_meta
118 );
119 }
120
121 /**
122 * Converts the instance to an array.
123 *
124 * @return array<string, mixed>
125 */
126 public function toArray(): array
127 {
128 $result = parent::toArray();
129
130 if ($this->mode !== null) {
131 $result['mode'] = $this->mode;
132 }
133 $result['message'] = $this->message;
134 $result['requestedSchema'] = $this->requestedSchema->toArray();
135
136 return $result;
137 }
138
139 /**
140 * @return 'form'|null
141 */
142 public function getMode(): ?string
143 {
144 return $this->mode;
145 }
146
147 /**
148 * @return string
149 */
150 public function getMessage(): string
151 {
152 return $this->message;
153 }
154
155 /**
156 * @return \WP\McpSchema\Client\Elicitation\DTO\ElicitRequestFormParamsRequestedSchema
157 */
158 public function getRequestedSchema(): ElicitRequestFormParamsRequestedSchema
159 {
160 return $this->requestedSchema;
161 }
162 }
163