feat: 工具调用改为独立 SSE 事件并以中文状态条展示

This commit is contained in:
2026-09-20 11:45:00 +08:00
parent 9b240b35a9
commit de0bbb1a9c
9 changed files with 179 additions and 19 deletions
+19
View File
@@ -104,3 +104,22 @@ class LlmRuntimeConfig:
api_key: str
model: str
extra_headers: dict[str, str] = field(default_factory=dict)
@dataclass(frozen=True)
class StreamEvent:
"""流式片段:正文 token 或工具状态(工具状态不进落库正文)。"""
kind: str # token | tool
text: str | None = None
phase: str | None = None # start | end
name: str | None = None
label: str | None = None
@staticmethod
def token(text: str) -> StreamEvent:
return StreamEvent(kind="token", text=text)
@staticmethod
def tool(*, phase: str, name: str, label: str) -> StreamEvent:
return StreamEvent(kind="tool", phase=phase, name=name, label=label)
+2 -2
View File
@@ -5,7 +5,7 @@ from __future__ import annotations
from abc import ABC, abstractmethod
from typing import Any, AsyncIterator
from domain.models import ChatMessage, LlmRuntimeConfig, Session, UserMemory
from domain.models import ChatMessage, LlmRuntimeConfig, Session, StreamEvent, UserMemory
class SessionRepository(ABC):
@@ -92,4 +92,4 @@ class ChatStreamer(ABC):
tools: list[Any] | None = None,
memory_count: int = 0,
memory_just_saved: str | None = None,
) -> AsyncIterator[str]: ...
) -> AsyncIterator[StreamEvent]: ...