*/ class PromptChain implements PromptGetterInterface, CollectionInterface { public function __construct( /** * @var IdentifierInterface[] */ private readonly array $items, ) { } public function getMetadata(int $count, ?string $lastIdentifier = null): iterable { $found = null === $lastIdentifier; foreach ($this->items as $item) { if (!$item instanceof MetadataInterface) { continue; } if (false === $found) { $found = $item->getName() === $lastIdentifier; continue; } yield $item; if (--$count <= 0) { break; } } if (!$found) { throw new InvalidCursorException($lastIdentifier); } } public function get(GetPromptRequest $request): GetPromptResult { foreach ($this->items as $item) { if ($item instanceof PromptGetterInterface && $request->name === $item->getName()) { try { return $item->get($request); } catch (\Throwable $e) { throw new PromptGetException($request, $e); } } } throw new PromptNotFoundException($request); } }