App
dyui.App
Section titled “dyui.App”class App( title: str = 'DyUI', *, description: Optional[str] = None, welcome: Optional[str] = None, placeholder: str = 'Message {title}…', logo: Optional[str] = None, theme: Literal['system', 'light', 'dark'] = 'system', accent: str = 'indigo', starters: Sequence[Union[str, Starter]] = (), components: Union[Literal['all'], Sequence[Union[str, type[Component]]], None] = 'all', persist: Any = True, password: Optional[str] = None, uploads: bool = True, feedback: bool = True, history: bool = True, max_upload_mb: int = 20, data_dir: Union[str, Path, None] = None, embed_origins: Sequence[str] = (), csp: Union[bool, str] = True,)A DyUI chat application (and an ASGI app: uvicorn app:app works).
Parameters
| Name | Type | Description |
|---|---|---|
title |
str |
App name, shown in the header and browser tab. |
description |
Optional[str] |
Shown under the welcome heading. |
welcome |
Optional[str] |
Welcome heading (default “How can I help?”). |
placeholder |
str |
Composer placeholder; {title} is substituted. |
logo |
Optional[str] |
URL or local image path for your logo. |
theme |
Literal['system', 'light', 'dark'] |
"system", "light" or "dark". |
accent |
str |
indigo (default), teal, rose, amber, emerald, slate or a hex color. |
starters |
Sequence[Union[str, Starter]] |
Suggested first messages (strings or dyui.Starter). |
components |
Union[Literal['all'], Sequence[Union[str, type[Component]]], None] |
Which built-in components the LLM may use: "all", a list of names / component classes, or None for none. Custom components are always included. |
persist |
Any |
True → SQLite at ./.dyui/dyui.db; a path → SQLite there; False → in memory; or a Store instance. |
password |
Optional[str] |
Require this shared password to use the app. |
uploads |
bool |
Allow file uploads. |
feedback |
bool |
Show thumbs up/down on replies. |
history |
bool |
Show the conversation sidebar. |
max_upload_mb |
int |
Upload size limit. |
data_dir |
Union[str, Path, None] |
Where DyUI keeps its database and uploads (default ./.dyui). |
embed_origins |
Sequence[str] |
Sites allowed to show this app in an <iframe> (e.g. ["https://example.com"]). By default only the app itself may frame it. |
csp |
Union[bool, str] |
The Content-Security-Policy sent with the app’s HTML: True (DyUI’s strict default), a policy string of your own, or False to send none. |
App.on_message()
Section titled “App.on_message()”def on_message(fn: Handler) -> HandlerRegister the reply handler: (msg: Message, chat: Chat). Required.
App.on_chat_start()
Section titled “App.on_chat_start()”def on_chat_start(fn: Handler) -> HandlerRegister a handler run when a conversation starts: (chat: Chat).
App.on_feedback()
Section titled “App.on_feedback()”def on_feedback(fn: Handler) -> HandlerRegister a thumbs up/down handler: (feedback: Feedback, chat: Chat).
App.on_action()
Section titled “App.on_action()”def on_action(name: str) -> Callable[[Handler], Handler]Register a handler for a component action: (action: Action, chat: Chat).
It may yield a reply like on_message. Unhandled actions are sent to
on_message as an LLM-friendly "[action:name] {...}" message.
App.component()
Section titled “App.component()”def component() -> type[Component]Register a custom component; the LLM learns it on the next turn.
App.catalog Catalog
Section titled “App.catalog Catalog”The components this app’s LLM may use (enabled built-ins + your custom ones).
Rebuilt on every access, so the prompt always reflects the live registry.
App.render_catalog Catalog
Section titled “App.render_catalog Catalog”Everything this app can render (all built-ins + custom).
App.untrusted_catalog Catalog
Section titled “App.untrusted_catalog Catalog”What model-written UI may use: every LLM built-in + custom components.
Used for fenced dyui blocks in text and {"ui": ...} dicts (which is
what tools-mode LLM calls produce). Developer-only components (html,
invalid) are excluded — the LLM can never produce HTML. Developers
render ui.Html by yielding the component instance.
App.check_action()
Section titled “App.check_action()”async def check_action(user_id: str, req: dict[str, Any]) -> tuple[int, str, Any]Verify an action request without side effects.
Returns (status, error, data): status is 0 when the action is valid
(data is then the server-side static data to use), else an HTTP status.
App.claim_action()
Section titled “App.claim_action()”def claim_action(req: dict[str, Any]) -> Optional[tuple[str, str]]Claim a component for one action request (synchronous: call right after
check_action, with no await in between).
Returns the claim key, or None if another request already holds it (a
concurrent double-click). Released by handle_action once the
resolution is recorded; stale claims expire after _CLAIM_TTL_S.
App.asgi()
Section titled “App.asgi()”def asgi() -> AnyThe underlying FastAPI application (built lazily).