Start the CLI server and establish a connection. If connecting to an already-running runtime (via :meth:`RuntimeConnection.for_uri`), only establishes the connection. Otherwise, spawns the CLI server process and then connects. This method is called automati
(self)
| 1367 | await self.stop() |
| 1368 | |
| 1369 | async def start(self) -> None: |
| 1370 | """ |
| 1371 | Start the CLI server and establish a connection. |
| 1372 | |
| 1373 | If connecting to an already-running runtime (via :meth:`RuntimeConnection.for_uri`), |
| 1374 | only establishes the connection. Otherwise, spawns the CLI server process |
| 1375 | and then connects. |
| 1376 | |
| 1377 | This method is called automatically when creating a session, so most |
| 1378 | callers do not need to call it explicitly. |
| 1379 | |
| 1380 | Raises: |
| 1381 | RuntimeError: If the server fails to start or the connection fails. |
| 1382 | |
| 1383 | Example: |
| 1384 | >>> client = CopilotClient() |
| 1385 | >>> await client.start() |
| 1386 | >>> # Now ready to create sessions |
| 1387 | """ |
| 1388 | if self._state == "connected": |
| 1389 | return |
| 1390 | |
| 1391 | start_time = time.perf_counter() |
| 1392 | self._state = "connecting" |
| 1393 | |
| 1394 | try: |
| 1395 | # Only start CLI server process if not connecting to external server |
| 1396 | if not self._is_external_server: |
| 1397 | await self._start_cli_server() |
| 1398 | |
| 1399 | # Connect to the server |
| 1400 | await self._connect_to_server() |
| 1401 | log_timing( |
| 1402 | logger, |
| 1403 | logging.DEBUG, |
| 1404 | "CopilotClient.start transport setup complete", |
| 1405 | start_time, |
| 1406 | ) |
| 1407 | |
| 1408 | # Verify protocol version compatibility |
| 1409 | await self._verify_protocol_version() |
| 1410 | log_timing( |
| 1411 | logger, |
| 1412 | logging.DEBUG, |
| 1413 | "CopilotClient.start protocol verification complete", |
| 1414 | start_time, |
| 1415 | ) |
| 1416 | |
| 1417 | if self._session_fs_config: |
| 1418 | session_fs_start = time.perf_counter() |
| 1419 | await self._set_session_fs_provider() |
| 1420 | log_timing( |
| 1421 | logger, |
| 1422 | logging.DEBUG, |
| 1423 | "CopilotClient.start session filesystem setup complete", |
| 1424 | session_fs_start, |
| 1425 | ) |
| 1426 |