| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace WP\McpSchema\Common\Tasks\DTO; |
| 6 |
|
| 7 |
use WP\McpSchema\Common\Protocol\DTO\Result; |
| 8 |
use WP\McpSchema\Client\Lifecycle\Union\ClientResultInterface; |
| 9 |
use WP\McpSchema\Server\Lifecycle\Union\ServerResultInterface; |
| 10 |
|
| 11 |
/** |
| 12 |
* The response to a tasks/get request. |
| 13 |
* |
| 14 |
* This class represents an intersection type combining properties from: |
| 15 |
* - {@see Result} |
| 16 |
* - {@see Task} |
| 17 |
* |
| 18 |
* In TypeScript, this is defined as: `type GetTaskResult = Result & Task` |
| 19 |
* |
| 20 |
* PHP requires actual classes for union interface implementation, so this class |
| 21 |
* extends Result and merges properties from: Task |
| 22 |
* |
| 23 |
* Implements union interfaces: |
| 24 |
* - {@see ClientResultInterface} |
| 25 |
* - {@see ServerResultInterface} |
| 26 |
* |
| 27 |
* @since 2025-11-25 |
| 28 |
* |
| 29 |
* @mcp-domain Common |
| 30 |
* @mcp-subdomain Tasks |
| 31 |
* @mcp-version 2025-11-25 |
| 32 |
*/ |
| 33 |
class GetTaskResult extends Result implements ClientResultInterface, ServerResultInterface |
| 34 |
{ |
| 35 |
/** |
| 36 |
* Wire keys this class models. Anything else is kept in $additionalProperties. |
| 37 |
* |
| 38 |
* @var array<int, string> |
| 39 |
*/ |
| 40 |
private const KNOWN_KEYS = ['_meta', 'taskId', 'status', 'statusMessage', 'createdAt', 'lastUpdatedAt', 'ttl', 'pollInterval']; |
| 41 |
|
| 42 |
/** |
| 43 |
* The task identifier. |
| 44 |
* |
| 45 |
* @since 2025-11-25 |
| 46 |
* |
| 47 |
* @var string |
| 48 |
*/ |
| 49 |
protected string $taskId; |
| 50 |
|
| 51 |
/** |
| 52 |
* Current task state. |
| 53 |
* |
| 54 |
* @since 2025-11-25 |
| 55 |
* |
| 56 |
* @var 'working'|'input_required'|'completed'|'failed'|'cancelled' |
| 57 |
*/ |
| 58 |
protected string $status; |
| 59 |
|
| 60 |
/** |
| 61 |
* Optional human-readable message describing the current task state. |
| 62 |
* This can provide context for any status, including: |
| 63 |
* - Reasons for "cancelled" status |
| 64 |
* - Summaries for "completed" status |
| 65 |
* - Diagnostic information for "failed" status (e.g., error details, what went wrong) |
| 66 |
* |
| 67 |
* @since 2025-11-25 |
| 68 |
* |
| 69 |
* @var string|null |
| 70 |
*/ |
| 71 |
protected ?string $statusMessage = null; |
| 72 |
|
| 73 |
/** |
| 74 |
* ISO 8601 timestamp when the task was created. |
| 75 |
* |
| 76 |
* @since 2025-11-25 |
| 77 |
* |
| 78 |
* @var string |
| 79 |
*/ |
| 80 |
protected string $createdAt; |
| 81 |
|
| 82 |
/** |
| 83 |
* ISO 8601 timestamp when the task was last updated. |
| 84 |
* |
| 85 |
* @since 2025-11-25 |
| 86 |
* |
| 87 |
* @var string |
| 88 |
*/ |
| 89 |
protected string $lastUpdatedAt; |
| 90 |
|
| 91 |
/** |
| 92 |
* Actual retention duration from creation in milliseconds, null for unlimited. |
| 93 |
* |
| 94 |
* @since 2025-11-25 |
| 95 |
* |
| 96 |
* @var int|null |
| 97 |
*/ |
| 98 |
protected ?int $ttl = null; |
| 99 |
|
| 100 |
/** |
| 101 |
* Suggested polling interval in milliseconds. |
| 102 |
* |
| 103 |
* @since 2025-11-25 |
| 104 |
* |
| 105 |
* @var int|null |
| 106 |
*/ |
| 107 |
protected ?int $pollInterval = null; |
| 108 |
|
| 109 |
/** |
| 110 |
* @param string $taskId @since 2025-11-25 |
| 111 |
* @param 'working'|'input_required'|'completed'|'failed'|'cancelled' $status @since 2025-11-25 |
| 112 |
* @param string $createdAt @since 2025-11-25 |
| 113 |
* @param string $lastUpdatedAt @since 2025-11-25 |
| 114 |
* @param int $ttl @since 2025-11-25 |
| 115 |
* @param array<string, mixed>|null $_meta @since 2025-11-25 |
| 116 |
* @param string|null $statusMessage @since 2025-11-25 |
| 117 |
* @param int|null $pollInterval @since 2025-11-25 |
| 118 |
* @param array<string, mixed>|null $additionalProperties @since 2025-11-25 |
| 119 |
*/ |
| 120 |
public function __construct( |
| 121 |
string $taskId, |
| 122 |
string $status, |
| 123 |
string $createdAt, |
| 124 |
string $lastUpdatedAt, |
| 125 |
int $ttl, |
| 126 |
?array $_meta = null, |
| 127 |
?string $statusMessage = null, |
| 128 |
?int $pollInterval = null, |
| 129 |
?array $additionalProperties = null |
| 130 |
) { |
| 131 |
parent::__construct($_meta, $additionalProperties); |
| 132 |
$this->taskId = $taskId; |
| 133 |
$this->status = $status; |
| 134 |
$this->statusMessage = $statusMessage; |
| 135 |
$this->createdAt = $createdAt; |
| 136 |
$this->lastUpdatedAt = $lastUpdatedAt; |
| 137 |
$this->ttl = $ttl; |
| 138 |
$this->pollInterval = $pollInterval; |
| 139 |
} |
| 140 |
|
| 141 |
/** |
| 142 |
* Creates an instance from an array. |
| 143 |
* |
| 144 |
* @param array<string, mixed> $data |
| 145 |
* @return self |
| 146 |
*/ |
| 147 |
public static function fromArray(array $data): self |
| 148 |
{ |
| 149 |
self::assertRequired($data, ['taskId', 'status', 'createdAt', 'lastUpdatedAt', 'ttl']); |
| 150 |
|
| 151 |
/** @var 'working'|'input_required'|'completed'|'failed'|'cancelled' $status */ |
| 152 |
$status = self::asString($data['status']); |
| 153 |
|
| 154 |
return new self( |
| 155 |
self::asString($data['taskId']), |
| 156 |
$status, |
| 157 |
self::asString($data['createdAt']), |
| 158 |
self::asString($data['lastUpdatedAt']), |
| 159 |
self::asInt($data['ttl']), |
| 160 |
self::asArrayOrNull($data['_meta'] ?? null), |
| 161 |
self::asStringOrNull($data['statusMessage'] ?? null), |
| 162 |
self::asIntOrNull($data['pollInterval'] ?? null), |
| 163 |
self::additionalFields($data, self::KNOWN_KEYS) |
| 164 |
); |
| 165 |
} |
| 166 |
|
| 167 |
/** |
| 168 |
* Converts the instance to an array. |
| 169 |
* |
| 170 |
* @return array<string, mixed> |
| 171 |
*/ |
| 172 |
public function toArray(): array |
| 173 |
{ |
| 174 |
$result = parent::toArray(); |
| 175 |
|
| 176 |
$result['taskId'] = $this->taskId; |
| 177 |
$result['status'] = $this->status; |
| 178 |
if ($this->statusMessage !== null) { |
| 179 |
$result['statusMessage'] = $this->statusMessage; |
| 180 |
} |
| 181 |
$result['createdAt'] = $this->createdAt; |
| 182 |
$result['lastUpdatedAt'] = $this->lastUpdatedAt; |
| 183 |
$result['ttl'] = $this->ttl; |
| 184 |
if ($this->pollInterval !== null) { |
| 185 |
$result['pollInterval'] = $this->pollInterval; |
| 186 |
} |
| 187 |
|
| 188 |
return $result; |
| 189 |
} |
| 190 |
|
| 191 |
/** |
| 192 |
* @return string |
| 193 |
*/ |
| 194 |
public function getTaskId(): string |
| 195 |
{ |
| 196 |
return $this->taskId; |
| 197 |
} |
| 198 |
|
| 199 |
/** |
| 200 |
* @return 'working'|'input_required'|'completed'|'failed'|'cancelled' |
| 201 |
*/ |
| 202 |
public function getStatus(): string |
| 203 |
{ |
| 204 |
return $this->status; |
| 205 |
} |
| 206 |
|
| 207 |
/** |
| 208 |
* @return string|null |
| 209 |
*/ |
| 210 |
public function getStatusMessage(): ?string |
| 211 |
{ |
| 212 |
return $this->statusMessage; |
| 213 |
} |
| 214 |
|
| 215 |
/** |
| 216 |
* @return string |
| 217 |
*/ |
| 218 |
public function getCreatedAt(): string |
| 219 |
{ |
| 220 |
return $this->createdAt; |
| 221 |
} |
| 222 |
|
| 223 |
/** |
| 224 |
* @return string |
| 225 |
*/ |
| 226 |
public function getLastUpdatedAt(): string |
| 227 |
{ |
| 228 |
return $this->lastUpdatedAt; |
| 229 |
} |
| 230 |
|
| 231 |
/** |
| 232 |
* @return int|null |
| 233 |
*/ |
| 234 |
public function getTtl(): ?int |
| 235 |
{ |
| 236 |
return $this->ttl; |
| 237 |
} |
| 238 |
|
| 239 |
/** |
| 240 |
* @return int|null |
| 241 |
*/ |
| 242 |
public function getPollInterval(): ?int |
| 243 |
{ |
| 244 |
return $this->pollInterval; |
| 245 |
} |
| 246 |
} |
| 247 |
|