0.7.4 gives the Ambient pack weather. A page names one feed URL on its own site, and the pack sets data-weather from it, uses its sunrise and sunset for dawn and dusk, and never shows a stale observation. Helpers for producing the feed from Open-Meteo are included. Ambient p…
Orchestrating shell that wires chat-thread, chat-input, participant data, and model selection into a composed chat interface.
Overview
The orchestrating shell for chat UIs. chat-window wires together <chat-thread>, <chat-input>, participant data, and an optional model selector into a complete chat interface.
Light DOM, no Shadow DOM. Uses CSS grid with grid-template-rows: auto 1fr auto for header/thread/input layout. The consumer sizes the container; chat-window fills it.
The full compose: header with title and model selector, empty thread, and input area. The [data-model-select] dropdown syncs bidirectionally with model.
Server-rendered messages hydrate on connect. chat-window resolves data-from IDs against the participant map and writes data-from-label for CSS rendering.
Support chat window
123456789101112131415161718192021222324
<chat-windowendpoint="/api/support"><scripttype="application/json"data-participants> {"user": { "name": "You", "role": "user" },"sarah": { "name": "Sarah Chen", "role": "agent" } }</script><header><h3>Support Chat</h3></header><chat-threadrole="log"aria-label="Support conversation"aria-live="polite"><chat-messagedata-role="agent"data-from="sarah"><chat-bubble><p>Welcome! How can I help?</p></chat-bubble></chat-message></chat-thread><chat-inputname="message"><textareadata-growrows="1"aria-label="Message"placeholder="Type a message..."></textarea><footer><buttontype="submit"class="small"data-sendaria-label="Send"><icon-wcname="send"></icon-wc></button></footer></chat-input></chat-window>
Participant Data
Declared via a <script type="application/json" data-participants> block inside chat-window, or set programmatically via the participants setter. Keys are participant IDs used in data-from attributes.
Each participant has a name (written to data-from-label) and a role (the first "agent" answers sends). Other fields are ignored. Add avatars as <user-avatar> children in your own messages, and set the model with the modelattribute.
Orchestration Flow
When chat-input:send fires:
Builds chat-message[data-role="user"] and appends it to the thread. The typed text is inserted as text, never parsed as HTML
Builds chat-message[data-role="agent"][data-status="typing"]. The bubble holds a visually hidden "Name is typing" label, which the live log announces, and shows animated dots
Disables chat-input during the request
With endpoint: awaits the response. Without it: dispatches chat-window:send and re-enables the input right away
Fills the typing message with the sanitized reply and removes data-status
Re-enables chat-input and restores focus
The typing indicator and the final response share the same DOM node — no element swap, no flicker. If chat-window disconnects while a request is in flight, the request is aborted and the placeholder removed.
Endpoint Contract
The built-in transport sends POST endpoint with a JSON body holding only the latest message. No history is sent. Servers that need context must keep the conversation themselves, or use a custom transport.
Request and response
// Request body{ "message": "What is my order status?", "model": "claude-sonnet-4-6" } // model omitted when unset// Response JSON — the first present field is used, as HTML (sanitized){ "html": "<p>It ships tomorrow.</p>" } // or { "message": "..." } / { "content": "..." }
A non-2xx status or network error turns the placeholder into an error message (data-status="error") and fires chat-window:error.
Custom Transport
Omit endpoint and listen for chat-window:send. Stream into the typing element's chat-bubble if you like. When the reply is complete, call resolveTyping() so the status and the hidden typing label are cleared.
chat-window├── script[data-participants] (optional, hidden)├── header│ ├── h3 (title)│ └── select[data-model-select] (optional)├── chat-thread[role="log"] (always rendered)│ ├── p[data-chat-empty] (runtime, only while there are no messages)│ └── chat-message elements└── chat-input ├── textarea[data-grow] └── footer > button[data-send]
Public API
Member
Type
Description
model
string (get/set)
Current model; syncs with select
participants
Map (get/set)
Participant registry
messages
Array (get/set)
{ id, role, content, from? }[]. The getter reads the thread (typing placeholders excluded). The setter replaces the whole thread, server-rendered messages included, with a keyed diff by id. A message whose id survives, including a server-rendered one, keeps its DOM node. content is text for role: "user" and HTML (sanitized) otherwise
clearThread()
method
Remove all messages
appendMessage(role, content, from?)
method
Append a message and return it. User content is inserted as text; other roles are sanitized HTML
resolveTyping(el, content, { error? })
method
Finish a typing placeholder in place: fill its bubble (sanitized HTML), remove data-status (or set error) and the typing label
scrollToBottom()
method
Scroll the thread to the newest message (e.g. while streaming)
Dispatched when a message is sent and no endpoint is set. Use this for custom transport (WebSocket, worker, etc.). Finish with resolveTyping(typingElement, html).
chat-window:error
{ error, status }
Dispatched when the built-in fetch transport fails.
chat-window:model-change
{ model }
Dispatched when the model selector value changes.
chat-window:messages-changed
{ messages, source: 'property' }
Dispatched after the messages setter updates the thread.
Participant Identity
The data-participants JSON map uses arbitrary string IDs as keys. User messages are created with data-from="user", and the agent is resolved as the first participant whose role is "agent". Match these conventions in your participant map.
Model Property
The model attribute is synced with the <select data-model-select> at connect time. After connect, use the .model property setter for updates — attribute mutations are not observed.