diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..81fc130 Binary files /dev/null and b/.DS_Store differ diff --git a/src/infrastructure/deepagent/adapter.py b/src/infrastructure/deepagent/adapter.py index 2152f22..4155a36 100644 --- a/src/infrastructure/deepagent/adapter.py +++ b/src/infrastructure/deepagent/adapter.py @@ -110,14 +110,13 @@ async def stream(self, thread_id: str, message: str) -> AsyncIterator[str]: config = self._build_config(thread_id) logger.info("[thread=%s] Streaming agent response", thread_id) try: - async for event in self._graph.astream( + async for chunk, _metadata in self._graph.astream( {"messages": [{"role": "human", "content": message}]}, config=config, - stream_mode="messages-tuple", + stream_mode="messages", ): - msg_type, msg = event - if msg_type == "ai" and hasattr(msg, "content") and msg.content: - yield msg.content + if hasattr(chunk, "content") and chunk.content and chunk.type == "AIMessageChunk": + yield chunk.content except Exception as e: logger.exception("[thread=%s] Streaming error", thread_id) raise AgentError(f"Streaming error: {e}") from e diff --git a/src/main.py b/src/main.py index 90c9c32..a6fea2e 100644 --- a/src/main.py +++ b/src/main.py @@ -4,6 +4,7 @@ from pathlib import Path from fastapi import FastAPI, Request +from fastapi.middleware.cors import CORSMiddleware from fastapi.responses import JSONResponse from src.application.routes.agents import router as agents_router @@ -95,6 +96,14 @@ async def lifespan(_app: FastAPI): lifespan=lifespan, ) +app.add_middleware( + CORSMiddleware, + allow_origins=["http://localhost:8030"], + allow_credentials=True, + allow_methods=["*"], + allow_headers=["*"], +) + app.include_router(health_router) app.include_router(threads_router) app.include_router(chat_router) diff --git a/tests/unit/test_runner_tracing.py b/tests/unit/test_runner_tracing.py index 8c6dd28..54b43d4 100644 --- a/tests/unit/test_runner_tracing.py +++ b/tests/unit/test_runner_tracing.py @@ -73,7 +73,8 @@ async def test_stream_with_tracing_injects_callbacks(self, mock_tracing_provider async def mock_astream(*_args, **_kwargs): mock_msg = MagicMock() mock_msg.content = "chunk" - yield ("ai", mock_msg) + mock_msg.type = "AIMessageChunk" + yield (mock_msg, {"langgraph_node": "agent"}) mock_graph.astream = mock_astream