Skip to content

Commit f5039e1

Browse files
feat: add optional client parameter to CopilotSdkProvider.__init__
Enables shared singleton injection from mount(). When client= is provided, uses it instead of creating a new CopilotClientWrapper. Backward-compatible: existing callers without client= create a new wrapper as before. 🤖 Generated with [Amplifier](https://github.com/microsoft/amplifier) Co-Authored-By: Amplifier <240397093+microsoft-amplifier@users.noreply.github.com>
1 parent 852efb2 commit f5039e1

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

amplifier_module_provider_github_copilot/provider.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ def __init__(
119119
api_key: str | None = None, # Unused, kept for signature compatibility
120120
config: dict[str, Any] | None = None,
121121
coordinator: Any | None = None, # ModuleCoordinator
122+
client: CopilotClientWrapper | None = None, # Shared singleton if provided
122123
):
123124
"""
124125
Initialize the Copilot SDK provider.
@@ -134,6 +135,10 @@ def __init__(
134135
- debug_truncate_length: Max length for debug output (default: 180)
135136
- cli_path: Path to Copilot CLI executable
136137
coordinator: Amplifier's ModuleCoordinator for hooks and events
138+
client: Optional pre-created CopilotClientWrapper to reuse. If None,
139+
a new wrapper is created (backward-compatible default). Pass the
140+
shared singleton from _acquire_shared_client() to avoid spawning
141+
multiple copilot subprocesses.
137142
138143
Note:
139144
Timeout is automatically selected based on whether extended_thinking
@@ -169,10 +174,15 @@ def __init__(
169174
# Streaming configuration (default: enabled like Anthropic provider)
170175
self._use_streaming = bool(config.get("use_streaming", True))
171176

172-
# Initialize client wrapper
173-
self._client = CopilotClientWrapper(
174-
config=config,
175-
timeout=self._timeout,
177+
# Initialize client wrapper — use injected singleton if provided,
178+
# otherwise create a new one (backward-compatible default).
179+
self._client = (
180+
client
181+
if client is not None
182+
else CopilotClientWrapper(
183+
config=config,
184+
timeout=self._timeout,
185+
)
176186
)
177187

178188
# Track tool call IDs that have been repaired with synthetic results.

0 commit comments

Comments
 (0)