*/ class ListPromptsResult implements ResultInterface { /** * @param array $prompts the list of prompt definitions * @param string|null $nextCursor An opaque token representing the pagination position after the last returned result. * * If present, there may be more results available. */ public function __construct( public readonly array $prompts, public readonly ?string $nextCursor = null, ) { } /** * @param array{ * prompts: array, * nextCursor?: string, * } $data */ public static function fromArray(array $data): self { if (!isset($data['prompts']) || !\is_array($data['prompts'])) { throw new InvalidArgumentException('Missing or invalid "prompts" array in ListPromptsResult data.'); } return new self( array_map(static fn (array $prompt) => Prompt::fromArray($prompt), $data['prompts']), $data['nextCursor'] ?? null ); } /** * @return array{ * prompts: array, * nextCursor?: string, * } */ public function jsonSerialize(): array { $result = [ 'prompts' => array_values($this->prompts), ]; if ($this->nextCursor) { $result['nextCursor'] = $this->nextCursor; } return $result; } }