| 1: | <?php |
| 2: | |
| 3: | declare(strict_types=1); |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | |
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | |
| 14: | namespace Nexus\Mcp\Extension\Tasks\Schema\RequestParams; |
| 15: | |
| 16: | use Nexus\Assert\Assert; |
| 17: | use Nexus\Mcp\Core\Schema\MetaObject; |
| 18: | use Nexus\Mcp\Core\Schema\MetaObject\RequestMetaObject; |
| 19: | use Nexus\Mcp\Core\Schema\RequestParams; |
| 20: | |
| 21: | |
| 22: | |
| 23: | |
| 24: | |
| 25: | |
| 26: | |
| 27: | |
| 28: | |
| 29: | |
| 30: | |
| 31: | final readonly class CancelTaskRequestParams extends RequestParams |
| 32: | { |
| 33: | |
| 34: | |
| 35: | |
| 36: | public function __construct( |
| 37: | public string $taskId, |
| 38: | RequestMetaObject $meta, |
| 39: | ) { |
| 40: | parent::__construct(meta: $meta); |
| 41: | } |
| 42: | |
| 43: | #[\Override] |
| 44: | public static function fromArray(array $data): static |
| 45: | { |
| 46: | Assert::that($data)->hasOffset('taskId', '"params" is missing the required "taskId" key.'); |
| 47: | $taskId = $data['taskId']; |
| 48: | Assert::that($taskId)->isNonEmptyString('"params.taskId" must be a non-empty string, {type} given.'); |
| 49: | |
| 50: | Assert::that($data)->hasOffset('_meta', '"params" is missing the required "_meta" key.'); |
| 51: | Assert::that($data['_meta']) |
| 52: | ->isArray('"params._meta" must be an object, {type} given.') |
| 53: | ->not()->isNonEmptyList('"params._meta" must be a string-keyed object.') |
| 54: | ; |
| 55: | $meta = RequestMetaObject::fromArray($data['_meta']); |
| 56: | |
| 57: | return new self(taskId: $taskId, meta: $meta); |
| 58: | } |
| 59: | |
| 60: | #[\Override] |
| 61: | public function toArray(): array |
| 62: | { |
| 63: | return [ |
| 64: | '_meta' => $this->meta->toArray(), |
| 65: | 'taskId' => $this->taskId, |
| 66: | ]; |
| 67: | } |
| 68: | } |
| 69: | |