| 1: | <?php |
| 2: | |
| 3: | declare(strict_types=1); |
| 4: | |
| 5: | /** |
| 6: | * This file is part of the Nexus MCP SDK package. |
| 7: | * |
| 8: | * (c) 2025 John Paul E. Balandan, CPA <paulbalandan@gmail.com> |
| 9: | * |
| 10: | * For the full copyright and license information, please view |
| 11: | * the LICENSE file that was distributed with this source code. |
| 12: | */ |
| 13: | |
| 14: | namespace Nexus\Mcp\Schema\Prompt; |
| 15: | |
| 16: | use Nexus\Mcp\Schema\Arrayable; |
| 17: | use Nexus\Mcp\Schema\Content\ContentBlock; |
| 18: | use Nexus\Mcp\Schema\Enum\Role; |
| 19: | |
| 20: | /** |
| 21: | * Describes a message returned as part of a prompt. |
| 22: | * |
| 23: | * This is similar to `SamplingMessage`, but also supports the embedding of resources from the MCP server. |
| 24: | * |
| 25: | * @template T of array<string, mixed> |
| 26: | * |
| 27: | * @implements Arrayable<array{ |
| 28: | * role: 'assistant'|'user', |
| 29: | * content: T, |
| 30: | * }> |
| 31: | */ |
| 32: | final readonly class PromptMessage implements \JsonSerializable, Arrayable |
| 33: | { |
| 34: | /** |
| 35: | * @param Arrayable<T>&ContentBlock $content |
| 36: | */ |
| 37: | public function __construct( |
| 38: | public Role $role, |
| 39: | public Arrayable&ContentBlock $content, |
| 40: | ) {} |
| 41: | |
| 42: | #[\Override] |
| 43: | public function toArray(): array |
| 44: | { |
| 45: | return [ |
| 46: | 'role' => $this->role->value, |
| 47: | 'content' => $this->content->toArray(), |
| 48: | ]; |
| 49: | } |
| 50: | |
| 51: | /** |
| 52: | * @return template-type<self<T>, Arrayable, 'T'> |
| 53: | */ |
| 54: | #[\Override] |
| 55: | public function jsonSerialize(): array |
| 56: | { |
| 57: | return $this->toArray(); |
| 58: | } |
| 59: | } |
| 60: |