""" Graph event emission — node state tracking + SSE graph_update events. """ from __future__ import annotations from core.detect import emit from core.detect.state import DetectState # Track node states across pipeline runs _node_states: dict[str, dict[str, str]] = {} def emit_transition(state: DetectState, node: str, status: str, node_list: list[str]): """Update node status and emit graph_update SSE event.""" job_id = state.get("job_id") if not job_id: return if job_id not in _node_states: _node_states[job_id] = {n: "pending" for n in node_list} _node_states[job_id][node] = status nodes = [{"id": n, "status": _node_states[job_id][n]} for n in node_list] emit.graph_update(job_id, nodes)