role = $role; $this->content = $content; } /** * Creates an instance from an array. * * @param array{ * role: 'user'|'assistant', * content: array|\WP\McpSchema\Common\Protocol\Union\ContentBlockInterface * } $data * @phpstan-param array $data * @return self */ public static function fromArray(array $data): self { self::assertRequired($data, ['role', 'content']); /** @var 'user'|'assistant' $role */ $role = self::asString($data['role']); /** @var \WP\McpSchema\Common\Protocol\Union\ContentBlockInterface $content */ $content = is_array($data['content']) ? ContentBlockFactory::fromArray(self::asArray($data['content'])) : $data['content']; return new self( $role, $content ); } /** * Converts the instance to an array. * * @return array */ public function toArray(): array { $result = []; $result['role'] = $this->role; $result['content'] = $this->content->toArray(); return $result; } /** * @return 'user'|'assistant' */ public function getRole(): string { return $this->role; } /** * @return \WP\McpSchema\Common\Protocol\Union\ContentBlockInterface */ public function getContent(): ContentBlockInterface { return $this->content; } }