feat(assistant): #91 etapes enrichies (sous-sections Reflechon/Sources, chevrons, indicateur anime, suppression barre de chargement)
CI / lint (push) Successful in 1m23s
CI / security (push) Successful in 58s
CI / test (push) Successful in 2m43s
CI / build (push) Successful in 55s
CI / e2e (push) Successful in 11m8s

This commit is contained in:
2026-09-15 22:53:15 -04:00
parent 431fb5626d
commit f630771150
13 changed files with 477 additions and 80 deletions
+32 -1
View File
@@ -333,10 +333,41 @@ def _effective_model(provider: str | None, requested: str | None) -> str:
return PROVIDERS.get(provider, {}).get("model", "") or ""
def _tool_sources(rec) -> list[dict[str, str]]:
"""Compact web sources of a tool result (rendered as links in the UI).
Only the web tools produce sources: ``web_search`` returns ranked results,
``fetch_url`` a single page. Everything else yields an empty list so the
SSE payload stays small.
"""
data = rec.result if isinstance(rec.result, dict) else {}
name = rec.name or ""
sources: list[dict[str, str]] = []
if name == "web_search":
for item in (data.get("results") or [])[:8]:
if not isinstance(item, dict):
continue
url = item.get("url") or ""
if not url:
continue
sources.append({"title": item.get("title") or url, "url": url})
elif name == "fetch_url":
url = data.get("url") or ""
if url:
sources.append({"title": data.get("title") or url, "url": url})
return sources
def _tool_event_sse(rec) -> str:
"""Serialize one executed tool call as an SSE ``tool`` event."""
payload = json.dumps(
{"name": rec.name, "ok": rec.ok, "arguments": rec.arguments, "step": rec.step},
{
"name": rec.name,
"ok": rec.ok,
"arguments": rec.arguments,
"step": rec.step,
"sources": _tool_sources(rec),
},
ensure_ascii=False,
)
return f"event: tool\ndata: {payload}\n\n"