Skip to content

Commit 168d07e

Browse files
Python codegen
1 parent 038c325 commit 168d07e

File tree

4 files changed

+856
-4
lines changed

4 files changed

+856
-4
lines changed

python/copilot/client.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from pathlib import Path
2424
from typing import Any, Callable, Optional, cast
2525

26+
from .generated.rpc import ServerRpc, SessionRpc
2627
from .generated.session_events import session_event_from_dict
2728
from .jsonrpc import JsonRpcClient
2829
from .sdk_protocol_version import get_sdk_protocol_version
@@ -202,6 +203,14 @@ def __init__(self, options: Optional[CopilotClientOptions] = None):
202203
SessionLifecycleEventType, list[SessionLifecycleHandler]
203204
] = {}
204205
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
205214

206215
def _parse_cli_url(self, url: str) -> tuple[str, int]:
207216
"""
@@ -1222,6 +1231,7 @@ async def _connect_via_stdio(self) -> None:
12221231

12231232
# Create JSON-RPC client with the process
12241233
self._client = JsonRpcClient(self._process)
1234+
self._rpc = ServerRpc(self._client)
12251235

12261236
# Set up notification handler for session events
12271237
# Note: This handler is called from the event loop (thread-safe scheduling)
@@ -1304,6 +1314,7 @@ def wait(self, timeout=None):
13041314

13051315
self._process = SocketWrapper(sock_file, sock) # type: ignore
13061316
self._client = JsonRpcClient(self._process)
1317+
self._rpc = ServerRpc(self._client)
13071318

13081319
# Set up notification handler for session events
13091320
def handle_notification(method: str, params: dict):

0 commit comments

Comments
 (0)