|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Revolution\Copilot\Rpc; |
| 6 | + |
| 7 | +use Revolution\Copilot\JsonRpc\JsonRpcClient; |
| 8 | +use Revolution\Copilot\Types\Rpc\SessionAgentGetCurrentResult; |
| 9 | +use Revolution\Copilot\Types\Rpc\SessionAgentListResult; |
| 10 | +use Revolution\Copilot\Types\Rpc\SessionAgentSelectParams; |
| 11 | +use Revolution\Copilot\Types\Rpc\SessionAgentSelectResult; |
| 12 | + |
| 13 | +/** |
| 14 | + * Pending agent RPC operations for a session. |
| 15 | + */ |
| 16 | +class PendingAgent |
| 17 | +{ |
| 18 | + public function __construct( |
| 19 | + protected JsonRpcClient $client, |
| 20 | + protected string $sessionId, |
| 21 | + ) {} |
| 22 | + |
| 23 | + /** |
| 24 | + * List available agents. |
| 25 | + */ |
| 26 | + public function list(): SessionAgentListResult |
| 27 | + { |
| 28 | + return SessionAgentListResult::fromArray( |
| 29 | + $this->client->request('session.agent.list', [ |
| 30 | + 'sessionId' => $this->sessionId, |
| 31 | + ]), |
| 32 | + ); |
| 33 | + } |
| 34 | + |
| 35 | + /** |
| 36 | + * Get the current agent. |
| 37 | + */ |
| 38 | + public function getCurrent(): SessionAgentGetCurrentResult |
| 39 | + { |
| 40 | + return SessionAgentGetCurrentResult::fromArray( |
| 41 | + $this->client->request('session.agent.getCurrent', [ |
| 42 | + 'sessionId' => $this->sessionId, |
| 43 | + ]), |
| 44 | + ); |
| 45 | + } |
| 46 | + |
| 47 | + /** |
| 48 | + * Select an agent. |
| 49 | + */ |
| 50 | + public function select(SessionAgentSelectParams|array $params): SessionAgentSelectResult |
| 51 | + { |
| 52 | + $paramsArray = $params instanceof SessionAgentSelectParams ? $params->toArray() : $params; |
| 53 | + $paramsArray['sessionId'] = $this->sessionId; |
| 54 | + |
| 55 | + return SessionAgentSelectResult::fromArray( |
| 56 | + $this->client->request('session.agent.select', $paramsArray), |
| 57 | + ); |
| 58 | + } |
| 59 | + |
| 60 | + /** |
| 61 | + * Deselect the current agent. |
| 62 | + */ |
| 63 | + public function deselect(): array |
| 64 | + { |
| 65 | + return $this->client->request('session.agent.deselect', [ |
| 66 | + 'sessionId' => $this->sessionId, |
| 67 | + ]); |
| 68 | + } |
| 69 | +} |
0 commit comments