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\Sampling;
15:
16: use Nexus\Mcp\Schema\Arrayable;
17: use Nexus\Mcp\Schema\Content\AudioContent;
18: use Nexus\Mcp\Schema\Content\ImageContent;
19: use Nexus\Mcp\Schema\Content\TextContent;
20: use Nexus\Mcp\Schema\Enum\Role;
21:
22: /**
23: * Describes a message issued to or received from an LLM API.
24: *
25: * @implements Arrayable<array{
26: * role: 'assistant'|'user',
27: * content: template-type<AudioContent|ImageContent|TextContent, Arrayable, 'T'>,
28: * }>
29: */
30: final readonly class SamplingMessage implements \JsonSerializable, Arrayable
31: {
32: public function __construct(
33: public Role $role,
34: public AudioContent|ImageContent|TextContent $content,
35: ) {}
36:
37: #[\Override]
38: public function toArray(): array
39: {
40: return [
41: 'role' => $this->role->value,
42: 'content' => $this->content->toArray(),
43: ];
44: }
45:
46: /**
47: * @return template-type<self, Arrayable, 'T'>
48: */
49: #[\Override]
50: public function jsonSerialize(): array
51: {
52: return $this->toArray();
53: }
54: }
55: