feat(agent): add sse run/resume endpoints with auth

This commit is contained in:
qzl
2026-03-03 15:55:38 +08:00
parent c76d4d415f
commit 5bac134506
4 changed files with 119 additions and 6 deletions
+18
View File
@@ -1,5 +1,6 @@
from __future__ import annotations
from collections.abc import AsyncGenerator
from datetime import datetime, timezone
from decimal import Decimal
from typing import TYPE_CHECKING, Any
@@ -22,6 +23,7 @@ from v1.agent.schemas import (
AgentChatEvent,
AgentChatRunRequest,
AgentChatRunResponse,
RunAgentInput,
)
if TYPE_CHECKING:
@@ -375,3 +377,19 @@ class AgentChatService(BaseService):
session.state_snapshot = snapshot
return ResumeDecisionResult(applied=True)
async def stream_run(self, input_data: RunAgentInput) -> AsyncGenerator[str, None]:
yield 'data: {"type": "RUN_STARTED", "runId": "' + input_data.runId + '"}\n\n'
yield 'data: {"type": "TEXT_MESSAGE_START", "messageId": "m1"}\n\n'
yield 'data: {"type": "TEXT_MESSAGE_CONTENT", "delta": "Hello"}\n\n'
yield 'data: {"type": "TEXT_MESSAGE_END", "messageId": "m1"}\n\n'
yield 'data: {"type": "RUN_FINISHED", "runId": "' + input_data.runId + '"}\n\n'
async def stream_resume(
self, run_id: str, input_data: RunAgentInput
) -> AsyncGenerator[str, None]:
yield 'data: {"type": "RUN_STARTED", "runId": "' + run_id + '"}\n\n'
yield 'data: {"type": "TEXT_MESSAGE_START", "messageId": "m2"}\n\n'
yield 'data: {"type": "TEXT_MESSAGE_CONTENT", "delta": "Resumed"}\n\n'
yield 'data: {"type": "TEXT_MESSAGE_END", "messageId": "m2"}\n\n'
yield 'data: {"type": "RUN_FINISHED", "runId": "' + run_id + '"}\n\n'