Chat & messages
dyui.Chat
Section titled “dyui.Chat”class Chat( app: 'App', thread: dict[str, Any], turn: Turn, messages: list[dict[str, Any]],)The conversation, handed to every handler.
Attributes
| Name | Type | Description |
|---|---|---|
thread_id |
str |
The conversation id. |
user_id |
str |
The anonymous browser identity (dyui_uid cookie). |
session |
dict[str, Any] |
Per-conversation scratch state, persisted with the thread (JSON-serializable). |
Chat.messages list[dict[str, Any]]
Section titled “Chat.messages list[dict[str, Any]]”All persisted messages (protocol Message dicts, oldest first).
Chat.history list[dict[str, str]]
Section titled “Chat.history list[dict[str, str]]”OpenAI-style [{"role", "content"}] history, text only.
Components the assistant showed are re-serialized as compact dyui
blocks so the model keeps context of the UI it rendered.
Chat.send()
Section titled “Chat.send()”async def send(*items: Any) -> NoneAppend text and/or components to the current assistant reply.
Chat.step()
Section titled “Chat.step()”def step(title: str, type: str = 'tool') -> StepA live step: async with chat.step("Searching") as s: s.output = ....
Chat.ask()
Section titled “Chat.ask()”async def ask(component: Any, timeout: Optional[float] = None) -> ActionRender an interactive component and wait for the user’s response.
Parameters
| Name | Type | Description |
|---|---|---|
component |
Any |
A ui.Confirm, ui.Form, ui.Choice, ui.Buttons… |
timeout |
Optional[float] |
Seconds to wait (None waits until the user answers or leaves). |
Returns
Action— class:Actionthe user took.
Raises
asyncio.TimeoutError— Iftimeoutelapses first.
Chat.set_title()
Section titled “Chat.set_title()”async def set_title(title: str) -> NoneSet the conversation title (stops auto-titling).
dyui.Step
Section titled “dyui.Step”class Step( turn: Turn, title: str, type: str = 'tool', parent_id: Optional[str] = None,)A live step in the assistant reply (use via async with chat.step(...)).
Attributes
| Name | Type | Description |
|---|---|---|
title |
What’s happening (“Searching flights”). | |
type |
A free-form kind (tool, search, code…). |
|
input |
Any |
Optional input shown when expanded. |
output |
Any |
Optional output shown when expanded. |
Step.log()
Section titled “Step.log()”async def log(text: str) -> NoneAppend a log line to the step (shown when expanded).
dyui.Message
Section titled “dyui.Message”class Message( id: str, text: str, files: list[File] = list(), action: Optional[Action] = None,)The user’s message, passed to @app.on_message.
Attributes
| Name | Type | Description |
|---|---|---|
id |
str |
Message id. |
text |
str |
The text to answer. For a turn created from an unhandled action this is the LLM-friendly form "[action:name] {...}". |
files |
list[File] |
Uploaded files. |
action |
Optional[Action] |
Set when this turn came from an action with no handler. |
dyui.Action
Section titled “dyui.Action”class Action( name: str, data: dict[str, Any] = dict(), values: dict[str, Any] = dict(), label: str = '', message_id: str = '', component_id: str = '',)A component interaction (button click, form submit, approval…).
Attributes
| Name | Type | Description |
|---|---|---|
name |
str |
The action name declared by the component (e.g. "book_flight"). |
data |
dict[str, Any] |
Static data declared alongside the action. |
values |
dict[str, Any] |
What the user entered/chose (form fields, {"confirmed": bool}…). |
label |
str |
Human-readable label of what was clicked. |
message_id |
str |
The assistant message holding the component. |
component_id |
str |
The component’s node id. |
dyui.Feedback
Section titled “dyui.Feedback”class Feedback(message_id: str, value: int, comment: Optional[str] = None)Thumbs up (1), down (-1) or cleared (0) on an assistant message.
dyui.File
Section titled “dyui.File”class File(id: str, name: str, type: str, size: int, path: Path, url: str)An uploaded file attached to a user message.
File.from_record()
Section titled “File.from_record()”def from_record(rec: dict[str, Any]) -> 'File'File.ref()
Section titled “File.ref()”def ref() -> dict[str, Any]dyui.Starter
Section titled “dyui.Starter”class Starter( label: str, message: Optional[str] = None, icon: Optional[str] = None,)A suggested first message on the welcome screen.
Starter.to_dict()
Section titled “Starter.to_dict()”def to_dict() -> dict[str, Any]dyui.Reasoning
Section titled “dyui.Reasoning”class Reasoning(text: str)A delta of model “thinking” text. Yield it from a handler (or receive it
from dyui.llm.stream) to render a collapsible reasoning block.