|
6 | 6 | from dataclasses import replace |
7 | 7 | from typing import Any |
8 | 8 |
|
| 9 | +from . import Transport |
9 | 10 | from ._errors import CLIConnectionError |
10 | 11 | from .types import ClaudeAgentOptions, HookEvent, HookMatcher, Message, ResultMessage |
11 | 12 |
|
@@ -51,12 +52,17 @@ class ClaudeSDKClient: |
51 | 52 | exist. |
52 | 53 | """ |
53 | 54 |
|
54 | | - def __init__(self, options: ClaudeAgentOptions | None = None): |
| 55 | + def __init__( |
| 56 | + self, |
| 57 | + options: ClaudeAgentOptions | None = None, |
| 58 | + transport: Transport | None = None, |
| 59 | + ): |
55 | 60 | """Initialize Claude SDK client.""" |
56 | 61 | if options is None: |
57 | 62 | options = ClaudeAgentOptions() |
58 | 63 | self.options = options |
59 | | - self._transport: Any | None = None |
| 64 | + self._custom_transport = transport |
| 65 | + self._transport: Transport | None = None |
60 | 66 | self._query: Any | None = None |
61 | 67 | os.environ["CLAUDE_CODE_ENTRYPOINT"] = "sdk-py-client" |
62 | 68 |
|
@@ -115,10 +121,14 @@ async def _empty_stream() -> AsyncIterator[dict[str, Any]]: |
115 | 121 | else: |
116 | 122 | options = self.options |
117 | 123 |
|
118 | | - self._transport = SubprocessCLITransport( |
119 | | - prompt=actual_prompt, |
120 | | - options=options, |
121 | | - ) |
| 124 | + # Use provided custom transport or create subprocess transport |
| 125 | + if self._custom_transport: |
| 126 | + self._transport = self._custom_transport |
| 127 | + else: |
| 128 | + self._transport = SubprocessCLITransport( |
| 129 | + prompt=actual_prompt, |
| 130 | + options=options, |
| 131 | + ) |
122 | 132 | await self._transport.connect() |
123 | 133 |
|
124 | 134 | # Extract SDK MCP servers from options |
|
0 commit comments