ccproxy.plugins.claude_sdk.stream_handle¶
ccproxy.plugins.claude_sdk.stream_handle
¶
Stream handle for managing worker lifecycle and providing listeners.
StreamHandle
¶
StreamHandle(
message_iterator,
session_id=None,
request_id=None,
session_client=None,
session_config=None,
)
Handle for a streaming response that manages worker and listeners.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message_iterator
|
AsyncIterator[Any]
|
The SDK message iterator |
required |
session_id
|
str | None
|
Optional session ID |
None
|
request_id
|
str | None
|
Optional request ID |
None
|
session_client
|
SessionClient | None
|
Optional session client |
None
|
session_config
|
SessionPoolSettings | None
|
Optional session pool configuration |
None
|
Source code in ccproxy/plugins/claude_sdk/stream_handle.py
has_first_chunk
property
¶
Check if stream has received first chunk (SystemMessage init).
create_listener
async
¶
Create a new listener for this stream.
This method creates the worker if needed, pre-registers the listener, then starts the worker. This ordering prevents race conditions where fast STDIO tools could return results before the listener was ready.
Yields:
| Type | Description |
|---|---|
AsyncIterator[Any]
|
Messages from the stream |
Source code in ccproxy/plugins/claude_sdk/stream_handle.py
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 | |
interrupt
async
¶
Interrupt the stream.
Returns:
| Type | Description |
|---|---|
bool
|
True if interrupted successfully |
Source code in ccproxy/plugins/claude_sdk/stream_handle.py
wait_for_completion
async
¶
get_stats
¶
Get stream handle statistics.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary of statistics |
Source code in ccproxy/plugins/claude_sdk/stream_handle.py
on_first_chunk_received
¶
Called when SystemMessage(init) is received - first chunk.
Source code in ccproxy/plugins/claude_sdk/stream_handle.py
on_message_received
¶
on_completion
¶
Called when ResultMessage is received - stream completed.
Source code in ccproxy/plugins/claude_sdk/stream_handle.py
is_stale
¶
Check if stream is stale based on configurable timeout logic.
Returns:
| Type | Description |
|---|---|
bool
|
True if stream should be considered stale |
Source code in ccproxy/plugins/claude_sdk/stream_handle.py
is_first_chunk_timeout
¶
Check if this is specifically a first chunk timeout.
Returns:
| Type | Description |
|---|---|
bool
|
True if no first chunk received and timeout exceeded |