Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/google/adk/cli/adk_web_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -1557,6 +1557,9 @@ async def event_generator():
"Generated event in agent run streaming: %s", sse_event
)
yield f"data: {sse_event}\n\n"

# Send termination signal after all events have been streamed
yield "data: [DONE]\n\n"
except Exception as e:
logger.exception("Error in event_generator: %s", e)
# Yield a proper Event object for the error
Expand All @@ -1570,6 +1573,7 @@ async def event_generator():
"data:"
f" {error_event.model_dump_json(by_alias=True, exclude_none=True)}\n\n"
)
yield "data: [DONE]\n\n"

# Returns a streaming response with the proper media type for SSE
return StreamingResponse(
Expand Down
2 changes: 1 addition & 1 deletion tests/unittests/cli/test_fast_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1005,7 +1005,7 @@ async def run_async_with_artifact_delta(
sse_events = [
json.loads(line.removeprefix("data: "))
for line in response.text.splitlines()
if line.startswith("data: ")
if line.startswith("data: ") and line != "data: [DONE]"
]

assert len(sse_events) == 2
Expand Down