Vanilla Breeze v0.7.4

Vanilla Breeze v0.7.4 released

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…

Read the release notes

chat-window

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.

Attributes

Attribute Type Default Description
endpoint URL - API endpoint for chat requests
model string - Active model; synced with [data-model-select]
empty-message string Send a message to start. Text shown when thread is empty

AI Chat with Model Selector

The full compose: header with title and model selector, empty thread, and input area. The [data-model-select] dropdown syncs bidirectionally with model.

Support Chat with SSR Messages

Server-rendered messages hydrate on connect. chat-window resolves data-from IDs against the participant map and writes data-from-label for CSS rendering.

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 model attribute.

Orchestration Flow

When chat-input:send fires:

  1. Builds chat-message[data-role="user"] and appends it to the thread. The typed text is inserted as text, never parsed as HTML
  2. 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
  3. Disables chat-input during the request
  4. With endpoint: awaits the response. Without it: dispatches chat-window:send and re-enables the input right away
  5. Fills the typing message with the sanitized reply and removes data-status
  6. 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.

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.

DOM Structure

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)

Events

Event Detail Description
chat-window:send { message, typingElement } 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.

CSS Variables

Variable Default Description
--chat-window-header-bg var(--color-surface) Header background
--chat-window-header-border var(--border-width-thin) solid var(--color-border) Header bottom border

Related

↑