tdfs4ds.serve.chat¶
tdfs4ds.serve.chat
¶
Native chat panel of the admin shell (v0.3.2.0).
The shell used to embed the Gradio chat in an iframe. The chat is now part of
the shell itself: app.js opens an SSE stream on /ui/chat/stream and this
module turns :func:tdfs4ds.agent.graph.consumer_agent_stream events into small
JSON messages. The agent is unchanged; the Gradio chat stays mounted at
/chatbot for existing deployments.
Events (name, payload), in order:
status{step, node, label, intent, object, domain}-- one per graph nodetool{name, input}-- an MCP tool callanswer{html, sources_html, markdown, charts}-- the answer, rendered server-side by the panels' Markdown renderer, its Sources footer split off so the user view can fold it, and the charts as sandboxed iframesadmin{intent, skill, domain, object, steps, total_ms, tokens, trace_html, has_graph}-- the observability detail, shown only in the admin view (sent always, so switching view needs no new request)error{message}-- the whole error text, never cut
The context knowledge graph is large (an inlined pyvis page), so it is not sent
with every answer: it is kept per thread (:data:_LAST_GRAPH) and fetched by
the admin view on demand (/ui/chat/graph).
valid_thread_id
¶
The caller's thread id when well-formed, else a fresh one.
default_view
¶
TDFS4DS_SERVE_DEFAULT_VIEW: 'user' or 'admin' (default, unchanged).
split_sources
¶
Split an answer into (body, Sources footer). No footer -> ("…", "").
_plain_label
¶
The Gradio chat's step label, without its emoji and Markdown.
chat_events
¶
chat_events(stream: Iterable[tuple], *, thread_id: str = '', clock: Callable[[], float] = time.perf_counter) -> Iterator[Tuple[str, dict]]
Map consumer_agent_stream events to chat-panel events (pure, no I/O
besides Markdown rendering). A failure of the stream ends with an error
event carrying the full message; nothing is truncated.
run_turn
¶
Run one turn of the consumer agent and yield chat-panel events.
suggestions
¶
Starter questions, named after real objects of the connected store.
One definition, shared with the Gradio chat: see
:func:tdfs4ds.agent.chatbot.chat_suggestions.