Watch
1
0
Fork
You've already forked arc
0
forked from hesabix/arc
arc/hesabixAPI/app/services/ai/ai_session_todo_events.py

25 lines
691 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""
بافر رویدادهای SSE مربوط به todoهای جلسه — بین handler ابزار و حلقهٔ استریم.
"""
from __future__ import annotations
from contextvars import ContextVar
from typing import Any, Dict, List
_pending_sse: ContextVar[List[Dict[str, Any]]] = ContextVar("session_todo_sse", default=[])
def reset_session_todo_sse_buffer() -> None:
_pending_sse.set([])
def emit_session_todo_sse(event: Dict[str, Any]) -> None:
buf = list(_pending_sse.get())
buf.append(dict(event))
_pending_sse.set(buf)
def drain_session_todo_sse() -> List[Dict[str, Any]]:
events = list(_pending_sse.get())
_pending_sse.set([])
return events