多语言散落补全

This commit is contained in:
potaser
2026-08-09 12:54:48 +08:00
parent 53966e03b5
commit 55d320586a
2 changed files with 42 additions and 78 deletions
+42 -12
View File
@@ -17693,25 +17693,47 @@ async def agent_chat(request: AgentChatRequest):
AGENT_CHAT_HEARTBEAT_SECONDS = 5.0
_AGENT_CHAT_TOOL_PROGRESS = {
"inspect_project_context": ("正在读取当前 job 的项目状态……", "当前 job 状态读取完成,主 Agent 正在继续处理……"),
"inspect_analysis_results": ("正在读取当前 job 的分析结果……", "分析结果读取完成,主 Agent 正在继续处理……"),
"inspect_job_file": ("正在读取当前 job 中的文件……", "文件读取完成,主 Agent 正在继续处理……"),
"query_plantai_rag": ("正在检索知识库……", "知识库检索完成,主 Agent 正在继续处理……"),
"recognize_analysis_intent": ("正在识别分析需求……", "分析需求识别完成,主 Agent 正在继续处理……"),
"recognize_utility_intent": ("正在识别工具需求……", "工具需求识别完成,主 Agent 正在继续处理……"),
"inspect_project_context": {
"zh": ("正在读取当前 job 的项目状态……", "当前 job 状态读取完成,主 Agent 正在继续处理……"),
"en": ("Reading current job project status...", "Job status read complete; agent continuing..."),
},
"inspect_analysis_results": {
"zh": ("正在读取当前 job 的分析结果……", "分析结果读取完成,主 Agent 正在继续处理……"),
"en": ("Reading current job analysis results...", "Analysis results read complete; agent continuing..."),
},
"inspect_job_file": {
"zh": ("正在读取当前 job 中的文件……", "文件读取完成,主 Agent 正在继续处理……"),
"en": ("Reading current job files...", "File read complete; agent continuing..."),
},
"query_plantai_rag": {
"zh": ("正在检索知识库……", "知识库检索完成,主 Agent 正在继续处理……"),
"en": ("Searching knowledge base...", "Knowledge base search complete; agent continuing..."),
},
"recognize_analysis_intent": {
"zh": ("正在识别分析需求……", "分析需求识别完成,主 Agent 正在继续处理……"),
"en": ("Recognizing analysis intent...", "Analysis intent recognized; agent continuing..."),
},
"recognize_utility_intent": {
"zh": ("正在识别工具需求……", "工具需求识别完成,主 Agent 正在继续处理……"),
"en": ("Recognizing utility intent...", "Utility intent recognized; agent continuing..."),
},
}
def _agent_chat_progress_payload(event: dict, elapsed_seconds: int) -> dict:
def _agent_chat_progress_payload(event: dict, elapsed_seconds: int, language: str = "zh") -> dict:
stage = str(event.get("stage") or "")
tool = str(event.get("tool") or "")
messages = _AGENT_CHAT_TOOL_PROGRESS.get(tool)
pair = _AGENT_CHAT_TOOL_PROGRESS.get(tool, {})
messages = pair.get(language) or pair.get("zh")
if stage == "tool_started" and messages:
message = messages[0]
elif stage == "tool_completed" and messages:
message = messages[1]
else:
message = "主 Agent 正在处理请求……"
message = {
"zh": "主 Agent 正在处理请求……",
"en": "Main Agent is processing your request...",
}.get(language, "主 Agent 正在处理请求……")
return {
"stage": stage or "agent_running",
"tool": tool,
@@ -17726,6 +17748,8 @@ def _agent_chat_sse(event_name: str, payload: dict) -> str:
@app.post("/api/agent/chat/stream")
async def agent_chat_stream(request: AgentChatRequest, http_request: Request):
lang = request.language or DEFAULT_AGENT_LANG
async def event_stream():
started_at = time.monotonic()
progress_queue: asyncio.Queue[dict] = asyncio.Queue()
@@ -17740,7 +17764,10 @@ async def agent_chat_stream(request: AgentChatRequest, http_request: Request):
"progress",
{
"stage": "agent_started",
"message": "正在理解你的问题并确定所需信息……",
"message": {
"zh": "正在理解你的问题并确定所需信息……",
"en": "Understanding your question and determining required information...",
}.get(lang, "正在理解你的问题并确定所需信息……"),
"elapsed_seconds": 0,
},
)
@@ -17760,7 +17787,10 @@ async def agent_chat_stream(request: AgentChatRequest, http_request: Request):
"heartbeat",
{
"stage": "agent_running",
"message": f"主 Agent 仍在处理,已用时 {elapsed} 秒……",
"message": {
"zh": f"主 Agent 仍在处理,已用时 {elapsed} 秒……",
"en": f"Main Agent is still processing, {elapsed} s elapsed...",
}.get(lang, f"主 Agent 仍在处理,已用时 {elapsed} 秒……"),
"elapsed_seconds": elapsed,
},
)
@@ -17768,7 +17798,7 @@ async def agent_chat_stream(request: AgentChatRequest, http_request: Request):
elapsed = int(time.monotonic() - started_at)
yield _agent_chat_sse(
"progress",
_agent_chat_progress_payload(event, elapsed),
_agent_chat_progress_payload(event, elapsed, language=lang),
)
result = await runner