Skip to content

Commit 33d6ffc

Browse files
committed
Refactor CopilotClient.__init__ to take keyword-only arguments
1 parent 062b61c commit 33d6ffc

42 files changed

Lines changed: 330 additions & 342 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

python/README.md

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,11 @@ async with await client.create_session({"model": "gpt-5"}) as session:
7979
### CopilotClient
8080

8181
```python
82-
client = CopilotClient({
83-
"cli_path": "copilot", # Optional: path to CLI executable
84-
"cli_url": None, # Optional: URL of existing server (e.g., "localhost:8080")
85-
"log_level": "info", # Optional: log level (default: "info")
86-
"auto_start": True, # Optional: auto-start server (default: True)
87-
"auto_restart": True, # Optional: auto-restart on crash (default: True)
88-
})
82+
client = CopilotClient(
83+
log_level="info", # Optional: log level (default: "info")
84+
auto_start=True, # Optional: auto-start server (default: True)
85+
auto_restart=True, # Optional: auto-restart on crash (default: True)
86+
)
8987
await client.start()
9088

9189
session = await client.create_session({"model": "gpt-5"})
@@ -102,18 +100,31 @@ await session.disconnect()
102100
await client.stop()
103101
```
104102

105-
**CopilotClient Options:**
103+
**CopilotClient Options (keyword-only):**
104+
105+
The client operates in one of two modes: **spawning a local CLI process** (default) or **connecting to an external server** via `cli_url`. Some arguments only apply to one mode.
106+
107+
*General options (always applicable):*
106108

107-
- `cli_path` (str): Path to CLI executable (default: "copilot" or `COPILOT_CLI_PATH` env var)
108-
- `cli_url` (str): URL of existing CLI server (e.g., `"localhost:8080"`, `"http://127.0.0.1:9000"`, or just `"8080"`). When provided, the client will not spawn a CLI process.
109-
- `cwd` (str): Working directory for CLI process
110-
- `port` (int): Server port for TCP mode (default: 0 for random)
111-
- `use_stdio` (bool): Use stdio transport instead of TCP (default: True)
112-
- `log_level` (str): Log level (default: "info")
113109
- `auto_start` (bool): Auto-start server on first use (default: True)
110+
- `on_list_models` (callable | None): Custom handler for listing available models. When provided, `list_models()` calls this handler instead of querying the CLI server.
111+
112+
*Local CLI process options (not allowed when `cli_url` is provided):*
113+
114+
- `cli_path` (str | None): Path to the Copilot CLI executable. When ``None`` (default), uses the bundled CLI binary shipped with the platform-specific wheel.
115+
- `cli_args` (list[str] | None): Extra arguments to pass to the CLI executable (inserted before SDK-managed args).
116+
- `cwd` (str | None): Working directory for the CLI process. Defaults to the current working directory.
117+
- `port` (int): Server port for TCP mode (default: 0 for random). Ignored in stdio mode.
118+
- `use_stdio` (bool | None): Use stdio transport instead of TCP (default: True). Passing explicitly alongside `cli_url` raises an error.
119+
- `log_level` (str): Log level (default: "info")
114120
- `auto_restart` (bool): Auto-restart on crash (default: True)
115-
- `github_token` (str): GitHub token for authentication. When provided, takes priority over other auth methods.
116-
- `use_logged_in_user` (bool): Whether to use logged-in user for authentication (default: True, but False when `github_token` is provided). Cannot be used with `cli_url`.
121+
- `env` (dict[str, str] | None): Environment variables for the CLI process. When ``None``, the current process's environment is used.
122+
- `github_token` (str | None): GitHub token for authentication. When provided, takes priority over other auth methods. Cannot be used with `cli_url`.
123+
- `use_logged_in_user` (bool | None): Whether to use the logged-in user for authentication. Defaults to ``True`` when no `github_token` is given, ``False`` otherwise. Cannot be used with `cli_url`.
124+
125+
*External server options:*
126+
127+
- `cli_url` (str | None): URL of an existing CLI server (e.g., `"localhost:8080"`, `"http://127.0.0.1:9000"`, or just `"8080"`). When provided, the client connects over TCP instead of spawning a process. Mutually exclusive with `cli_path` and its exclusive arguments.
117128

118129
**SessionConfig Options (for `create_session`):**
119130

0 commit comments

Comments
 (0)