ccproxy.api.middleware.streaming_hooks¶
ccproxy.api.middleware.streaming_hooks
¶
Streaming response wrapper for hook emission.
This module provides a wrapper for streaming responses that emits REQUEST_COMPLETED hook event when the stream actually completes.
StreamingResponseWithHooks
¶
StreamingResponseWithHooks(
content,
hook_manager,
request_id,
request_data,
start_time,
status_code=200,
request_metadata=None,
origin="client",
is_sse=False,
**kwargs,
)
Bases: StreamingResponse
Streaming response wrapper that emits hooks on completion.
This wrapper ensures REQUEST_COMPLETED is emitted when streaming actually finishes, not when the response is initially created.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
content
|
AsyncGenerator[bytes, None] | AsyncIterator[bytes]
|
The async generator producing streaming content |
required |
hook_manager
|
HookManager | None
|
Hook manager for emitting events |
required |
request_id
|
str
|
Request ID for correlation |
required |
request_data
|
dict[str, Any]
|
Original request data for context |
required |
start_time
|
float
|
Request start timestamp |
required |
status_code
|
int
|
HTTP status code for the response |
200
|
request_metadata
|
dict[str, Any] | None
|
Metadata from RequestContext (includes tokens, cost, etc.) |
None
|
**kwargs
|
Any
|
Additional arguments passed to StreamingResponse |
{}
|