|
1 | 1 | <?php
|
2 | 2 |
|
3 |
| -namespace App\Manager; |
| 3 | +namespace PhpLlm\McpSdk\Capability; |
4 | 4 |
|
5 | 5 | use PhpLlm\McpSdk\Capability\Prompt\CollectionInterface;
|
| 6 | +use PhpLlm\McpSdk\Capability\Prompt\IdentifierInterface; |
6 | 7 | use PhpLlm\McpSdk\Capability\Prompt\MetadataInterface;
|
7 | 8 | use PhpLlm\McpSdk\Capability\Prompt\PromptGet;
|
8 | 9 | use PhpLlm\McpSdk\Capability\Prompt\PromptGetResult;
|
9 | 10 | use PhpLlm\McpSdk\Capability\Prompt\PromptGetterInterface;
|
10 | 11 | use PhpLlm\McpSdk\Exception\PromptGetException;
|
11 | 12 | use PhpLlm\McpSdk\Exception\PromptNotFoundException;
|
12 | 13 |
|
13 |
| -class PromptManager implements PromptGetterInterface, CollectionInterface |
| 14 | +class PromptChain implements PromptGetterInterface, CollectionInterface |
14 | 15 | {
|
15 | 16 | public function __construct(
|
16 | 17 | /**
|
17 |
| - * @var (MetadataInterface | callable(PromptGet):PromptGetResult)[] |
| 18 | + * @var (IdentifierInterface & (MetadataInterface | PromptGetterInterface))[] |
18 | 19 | */
|
19 | 20 | private array $items,
|
20 | 21 | ) {
|
21 | 22 | }
|
22 | 23 |
|
23 | 24 | public function getMetadata(): array
|
24 | 25 | {
|
25 |
| - return $this->items; |
| 26 | + return array_filter($this->items, fn ($item) => $item instanceof MetadataInterface); |
26 | 27 | }
|
27 | 28 |
|
28 |
| - public function get(PromptGet $request): PromptGetResult |
| 29 | + public function get(PromptGet $input): PromptGetResult |
29 | 30 | {
|
30 | 31 | foreach ($this->items as $item) {
|
31 |
| - if ($request->name === $item->getName()) { |
| 32 | + if ($item instanceof PromptGetterInterface && $input->name === $item->getName()) { |
32 | 33 | try {
|
33 |
| - return $item($request); |
| 34 | + return $item->get($input); |
34 | 35 | } catch (\Throwable $e) {
|
35 |
| - throw new PromptGetException($request, $e); |
| 36 | + throw new PromptGetException($input, $e); |
36 | 37 | }
|
37 | 38 | }
|
38 | 39 | }
|
39 | 40 |
|
40 |
| - throw new PromptNotFoundException($request); |
| 41 | + throw new PromptNotFoundException($input); |
41 | 42 | }
|
42 | 43 | }
|
0 commit comments