| 1: | <?php |
| 2: | |
| 3: | declare(strict_types=1); |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | |
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | |
| 14: | namespace Nexus\Mcp\Extension\Apps\Server; |
| 15: | |
| 16: | use Nexus\Assert\Assert; |
| 17: | use Nexus\Mcp\Core\Schema\Annotations; |
| 18: | use Nexus\Mcp\Core\Schema\Icon; |
| 19: | use Nexus\Mcp\Core\Schema\MetaObject\PayloadMetaObject; |
| 20: | use Nexus\Mcp\Core\Schema\Resource\Resource; |
| 21: | use Nexus\Mcp\Extension\Apps\Apps; |
| 22: | use Nexus\Mcp\Extension\Apps\Schema\UiResourceMeta; |
| 23: | |
| 24: | |
| 25: | |
| 26: | |
| 27: | final readonly class UiResource |
| 28: | { |
| 29: | public Resource $resource; |
| 30: | |
| 31: | |
| 32: | |
| 33: | |
| 34: | |
| 35: | |
| 36: | |
| 37: | |
| 38: | public function __construct( |
| 39: | string $name, |
| 40: | string $uri, |
| 41: | ?string $title = null, |
| 42: | ?string $description = null, |
| 43: | public ?UiResourceMeta $uiMeta = null, |
| 44: | Annotations $annotations = new Annotations(), |
| 45: | ?int $size = null, |
| 46: | ?array $icons = null, |
| 47: | ) { |
| 48: | Assert::that($uri)->startsWith(Apps::URI_PREFIX, \sprintf('UI resource "uri" must start with "%s".', Apps::URI_PREFIX)); |
| 49: | |
| 50: | $extras = []; |
| 51: | |
| 52: | if (null !== $uiMeta) { |
| 53: | $uiMetaData = $uiMeta->toArray(); |
| 54: | |
| 55: | if ([] !== $uiMetaData) { |
| 56: | $extras[Apps::META_KEY] = $uiMetaData; |
| 57: | } |
| 58: | } |
| 59: | |
| 60: | $this->resource = new Resource( |
| 61: | name: $name, |
| 62: | uri: $uri, |
| 63: | title: $title, |
| 64: | description: $description, |
| 65: | mimeType: Apps::MIME_TYPE, |
| 66: | annotations: $annotations, |
| 67: | size: $size, |
| 68: | icons: $icons, |
| 69: | meta: new PayloadMetaObject(extras: $extras), |
| 70: | ); |
| 71: | } |
| 72: | } |
| 73: | |