|
23 | 23 | from pathlib import Path |
24 | 24 | from typing import Any, Callable, Optional, cast |
25 | 25 |
|
| 26 | +from .generated.rpc import ServerRpc, SessionRpc |
26 | 27 | from .generated.session_events import session_event_from_dict |
27 | 28 | from .jsonrpc import JsonRpcClient |
28 | 29 | from .sdk_protocol_version import get_sdk_protocol_version |
@@ -202,6 +203,14 @@ def __init__(self, options: Optional[CopilotClientOptions] = None): |
202 | 203 | SessionLifecycleEventType, list[SessionLifecycleHandler] |
203 | 204 | ] = {} |
204 | 205 | self._lifecycle_handlers_lock = threading.Lock() |
| 206 | + self._rpc: Optional[ServerRpc] = None |
| 207 | + |
| 208 | + @property |
| 209 | + def rpc(self) -> ServerRpc: |
| 210 | + """Typed server-scoped RPC methods.""" |
| 211 | + if self._rpc is None: |
| 212 | + raise RuntimeError("Client is not connected. Call start() first.") |
| 213 | + return self._rpc |
205 | 214 |
|
206 | 215 | def _parse_cli_url(self, url: str) -> tuple[str, int]: |
207 | 216 | """ |
@@ -1222,6 +1231,7 @@ async def _connect_via_stdio(self) -> None: |
1222 | 1231 |
|
1223 | 1232 | # Create JSON-RPC client with the process |
1224 | 1233 | self._client = JsonRpcClient(self._process) |
| 1234 | + self._rpc = ServerRpc(self._client) |
1225 | 1235 |
|
1226 | 1236 | # Set up notification handler for session events |
1227 | 1237 | # Note: This handler is called from the event loop (thread-safe scheduling) |
@@ -1304,6 +1314,7 @@ def wait(self, timeout=None): |
1304 | 1314 |
|
1305 | 1315 | self._process = SocketWrapper(sock_file, sock) # type: ignore |
1306 | 1316 | self._client = JsonRpcClient(self._process) |
| 1317 | + self._rpc = ServerRpc(self._client) |
1307 | 1318 |
|
1308 | 1319 | # Set up notification handler for session events |
1309 | 1320 | def handle_notification(method: str, params: dict): |
|
0 commit comments