样式修改
This commit is contained in:
1 parent
114ee8f6ac
commit
e3d8e534f6
6 files changed
+739
-48
No files matched your search
@@ -66,6 +66,7 @@ from fastapi.responses import StreamingResponse
|
||||
from app.gateway.routers.multi_agent import (
|
||||
_auth_headers,
|
||||
_create_thread,
|
||||
_diagnose_exception,
|
||||
_find_dispatch_message,
|
||||
_find_trailing_ai_text,
|
||||
_flatten_content,
|
||||
@@ -112,8 +113,20 @@ async def init_intent(request: Request, payload: dict = Body(...)) -> dict[str,
|
||||
# on the dev machine) makes httpx route loopback calls through an upstream
|
||||
# proxy that can't reach 127.0.0.1, costing 40+ seconds of timeout per
|
||||
# request before falling back. Symptom in logs: `headers_in=42.160s`.
|
||||
async with httpx.AsyncClient(timeout=None, trust_env=False) as client:
|
||||
thread_id = await _create_thread(client, base, headers)
|
||||
try:
|
||||
async with httpx.AsyncClient(timeout=None, trust_env=False) as client:
|
||||
thread_id = await _create_thread(client, base, headers)
|
||||
except HTTPException:
|
||||
# 上游已用结构化方式失败,原样传给前端不需要二次包装。
|
||||
raise
|
||||
except Exception as exc:
|
||||
# 把根因暴露给前端而不是吞成裸 500——内网部署常见的「config.yaml 模型外网不通」
|
||||
# / 「内置 agent 目录缺失」/ 「loopback 走代理」都能在前端面板直接看到。
|
||||
# FastAPI 把 detail=dict 序列化为 {"detail": {...}};前端 initIntent
|
||||
# 在 !res.ok 分支里读 detail.hint / trace_tail 渲染诊断面板。
|
||||
diagnostic = _diagnose_exception(exc, context="intent_init")
|
||||
logger.error("intent init failed: %s", diagnostic, exc_info=exc)
|
||||
raise HTTPException(status_code=500, detail=diagnostic) from exc
|
||||
return {
|
||||
"status": "success",
|
||||
"agent_id": INTENT_AGENT_ID,
|
||||
@@ -270,11 +283,40 @@ async def stream_intent(request: Request, payload: dict = Body(...)) -> Streamin
|
||||
|
||||
except HTTPException as exc:
|
||||
logger.warning("intent stream HTTPException: %s %s", exc.status_code, exc.detail)
|
||||
err = {"status": "error", "content": f"[{exc.status_code}] {exc.detail}", "summary": None}
|
||||
# HTTPException 的 detail 可能本身就是 dict(上游已结构化),也可能是 str。
|
||||
# 统一包装成与 _diagnose_exception 同构的字段,便于前端按一种模型渲染。
|
||||
detail_payload: Any = exc.detail
|
||||
error_detail: dict[str, Any]
|
||||
if isinstance(detail_payload, dict) and "code" in detail_payload:
|
||||
error_detail = detail_payload
|
||||
else:
|
||||
error_detail = {
|
||||
"code": "http_exception",
|
||||
"message": f"[{exc.status_code}] {detail_payload}",
|
||||
"exception_type": "HTTPException",
|
||||
"exception_repr": repr(exc),
|
||||
"root_type": None,
|
||||
"root_repr": None,
|
||||
"hint": None,
|
||||
"trace_tail": [],
|
||||
"context": "intent_stream",
|
||||
}
|
||||
err = {
|
||||
"status": "error",
|
||||
"content": error_detail["message"],
|
||||
"summary": None,
|
||||
"error_detail": error_detail,
|
||||
}
|
||||
yield f"data: {json.dumps(err, ensure_ascii=False)}\n\n"
|
||||
except Exception as exc:
|
||||
logger.exception("intent stream unexpected failure")
|
||||
err = {"status": "error", "content": f"unexpected: {exc!r}", "summary": None}
|
||||
diagnostic = _diagnose_exception(exc, context="intent_stream")
|
||||
logger.error("intent stream failed: %s", diagnostic, exc_info=exc)
|
||||
err = {
|
||||
"status": "error",
|
||||
"content": diagnostic["message"],
|
||||
"summary": None,
|
||||
"error_detail": diagnostic,
|
||||
}
|
||||
yield f"data: {json.dumps(err, ensure_ascii=False)}\n\n"
|
||||
|
||||
return StreamingResponse(
|
||||
|
||||
Reference in new issue
Block a user