chore(api): send a ping event immediately for /events api

This commit is contained in:
QuantumGhost
2026-01-21 16:21:24 +08:00
parent 073305e699
commit 05f9ea4220
2 changed files with 12 additions and 0 deletions

View File

@ -18,6 +18,12 @@ def stream_topic_events(
on_subscribe: Callable[[], None] | None = None,
terminal_events: Iterable[str | StreamEvent] | None = None,
) -> Generator[Mapping[str, Any] | str, None, None]:
# send a PING event immediately to prevent the connection staying in pending state for a long time.
#
# This simplify the debugging process as the DevTools in Chrome does not
# provide complete curl command for pending connections.
yield StreamEvent.PING.value
terminal_values = _normalize_terminal_events(terminal_events)
last_msg_time = time.time()
last_ping_time = last_msg_time

View File

@ -94,6 +94,12 @@ def build_workflow_event_stream(
)
def _generate() -> Generator[Mapping[str, Any] | str, None, None]:
# send a PING event immediately to prevent the connection staying in pending state for a long time.
#
# This simplify the debugging process as the DevTools in Chrome does not
# provide complete curl command for pending connections.
yield StreamEvent.PING.value
last_msg_time = time.time()
last_ping_time = last_msg_time