fixed injection watcher

This commit is contained in:
2026-06-11 08:18:30 +03:00
parent 481b93e84a
commit b5a1831b8e
5 changed files with 56 additions and 18 deletions
+19 -4
View File
@@ -172,13 +172,23 @@ class ChatService:
self.db.refresh(message)
return message
async def stream_response(self, session_id: int, user_text: str) -> AsyncIterator[str]:
def save_user_message(self, session_id: int, user_text: str) -> None:
self._save_message(session_id, "user", user_text)
async def stream_response(
self,
session_id: int,
user_text: str,
*,
user_message_saved: bool = False,
) -> AsyncIterator[str]:
session = self.get_session(session_id)
if not session:
yield self._sse("error", {"message": "Session not found"})
return
self._save_message(session_id, "user", user_text)
if not user_message_saved:
self._save_message(session_id, "user", user_text)
yield self._sse("status", {"phase": "preparing"})
t0 = time.monotonic()
messages = await asyncio.to_thread(_build_messages_for_session, session_id)
@@ -299,10 +309,15 @@ class ChatService:
if not final_content and reasoning:
final_content = reasoning.strip()
if not final_content and all_tool_notices:
# Notices уже ушли в SSE event: notice; здесь только финальный текст в БД.
final_content = "\n\n".join(all_tool_notices)
yield self._sse("token", {"content": final_content})
if not final_content and tools_executed:
retry = await self.llm.complete(messages, tools=None, temperature=0.4)
retry = await self.llm.complete(
messages,
tools=None,
temperature=0.4,
visible_reply=True,
)
final_content = (retry.get("content") or "").strip()
if final_content:
yield self._sse("token", {"content": final_content})