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
+22 -6
View File
@@ -3,17 +3,33 @@ from __future__ import annotations
from typing import Annotated
from fastapi import APIRouter, Depends
from fastapi.responses import StreamingResponse
from v1.agent.dependencies import get_agent_service
from v1.agent.schemas import AgentChatRunRequest, AgentChatRunResponse
from v1.agent.schemas import RunAgentInput
from v1.agent.service import AgentChatService
router = APIRouter(prefix="/agent", tags=["agent"])
@router.post("", response_model=AgentChatRunResponse)
async def run_agent_chat(
payload: AgentChatRunRequest,
@router.post("/runs")
async def create_run(
input_data: RunAgentInput,
service: Annotated[AgentChatService, Depends(get_agent_service)],
) -> AgentChatRunResponse:
return await service.run(payload)
) -> StreamingResponse:
return StreamingResponse(
service.stream_run(input_data),
media_type="text/event-stream",
)
@router.post("/runs/{run_id}/resume")
async def resume_run(
run_id: str,
input_data: RunAgentInput,
service: Annotated[AgentChatService, Depends(get_agent_service)],
) -> StreamingResponse:
return StreamingResponse(
service.stream_resume(run_id, input_data),
media_type="text/event-stream",
)