Skip to content

Chat & messages

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).

All persisted messages (protocol Message dicts, oldest first).

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.

async def send(*items: Any) -> None

Append text and/or components to the current assistant reply.

def step(title: str, type: str = 'tool') -> Step

A live step: async with chat.step("Searching") as s: s.output = ....

async def ask(component: Any, timeout: Optional[float] = None) -> Action

Render 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:Action the user took.

Raises

  • asyncio.TimeoutError — If timeout elapses first.
async def set_title(title: str) -> None

Set the conversation title (stops auto-titling).

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.
async def log(text: str) -> None

Append a log line to the step (shown when expanded).

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.
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.
class Feedback(message_id: str, value: int, comment: Optional[str] = None)

Thumbs up (1), down (-1) or cleared (0) on an assistant message.

class File(id: str, name: str, type: str, size: int, path: Path, url: str)

An uploaded file attached to a user message.

def from_record(rec: dict[str, Any]) -> 'File'
def ref() -> dict[str, Any]
class Starter(
label: str,
message: Optional[str] = None,
icon: Optional[str] = None,
)

A suggested first message on the welcome screen.

def to_dict() -> dict[str, Any]
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.

DyUI Docs assistant

Answers come from the DyUI docs. gpt-oss-120b via Groq. Press Escape or the close button to return to the page.