forked from anthropics/claude-agent-sdk-python
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclient.py
More file actions
44 lines (34 loc) · 1.23 KB
/
client.py
File metadata and controls
44 lines (34 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
"""Internal client implementation."""
from collections.abc import AsyncIterable, AsyncIterator
from typing import Any
from ..types import (
ClaudeCodeOptions,
Message,
)
from .message_parser import parse_message
from .transport import Transport
from .transport.subprocess_cli import SubprocessCLITransport
class InternalClient:
"""Internal client implementation."""
def __init__(self) -> None:
"""Initialize the internal client."""
async def process_query(
self,
prompt: str | AsyncIterable[dict[str, Any]],
options: ClaudeCodeOptions,
transport: Transport | None = None,
) -> AsyncIterator[Message]:
"""Process a query through transport."""
# Use provided transport or choose one based on configuration
if transport is not None:
chosen_transport = transport
else:
chosen_transport = SubprocessCLITransport(
prompt=prompt, options=options, close_stdin_after_prompt=True
)
try:
await chosen_transport.connect()
async for data in chosen_transport.receive_messages():
yield parse_message(data)
finally:
await chosen_transport.disconnect()