32 lines
726 B
Python
32 lines
726 B
Python
"""SSE (Server-Sent Events) utilities
|
|
|
|
This module provides SSE formatting functions to avoid circular imports
|
|
between stream_context.py and agentic_loop.py.
|
|
"""
|
|
import json
|
|
|
|
|
|
def sse_event(event: str, data: dict) -> str:
|
|
"""Format a Server-Sent Event string
|
|
|
|
Args:
|
|
event: Event type name
|
|
data: Event data dictionary
|
|
|
|
Returns:
|
|
Formatted SSE string
|
|
"""
|
|
return f"event: {event}\ndata: {json.dumps(data, ensure_ascii=False)}\n\n"
|
|
|
|
|
|
def sse_comment(message: str) -> str:
|
|
"""Format a SSE comment (for keep-alive or debugging)
|
|
|
|
Args:
|
|
message: Comment message
|
|
|
|
Returns:
|
|
Formatted SSE comment string
|
|
"""
|
|
return f": {message}\n\n"
|