The conversation list in your own chrome¶
<ag-ui-threads> lists a chat's conversations where you put it: as rows in a rail, or as pills
in a bar. It keeps nothing of its own. It reads the chat's conversationStore, marks the thread
on screen as current, and drives the chat through the thread API.
<header>
<ag-ui-threads for="chat" variant="pills"></ag-ui-threads>
</header>
<aside><ag-ui-threads for="chat"></ag-ui-threads></aside>
<ag-ui-chat id="chat" endpoint="/agent/"></ag-ui-chat>
<script type="module">
import { defineChat } from "@artooi/agents-web-components/chat";
import { defineThreads } from "@artooi/agents-web-components/threads";
defineChat();
defineThreads();
</script>
- Binding.
fornames the chat'sid, looked up in the list's own root, the document or the shadow root it sits in; a chat added later is picked up when it first reports its thread. Or set thechatproperty, which wins overforuntil it is set back tonull. With neither, the list binds to the chat of an<ag-ui-agents>provider: the one itsagentsattribute names by id, else the nearest one around it, and lists again each time the provider moves its chat to another agent.forwins when both are present. variant.list(the default) draws rows and an empty text.pillsdraws a strip that stays on one line and scrolls sideways, and no empty text. Both give each conversation a delete behind an inline confirm, which callschat.deleteThread; in a pill the confirm opens on the pill's own line.- Picking a row fires
ag-ui-threads-select(THREADS_SELECT_EVENT, detail{ threadId }, bubbling, composed and cancelable), then callschat.switchThread, which cancels a run in flight, as the built-in list does. CallpreventDefault()to route to the conversation yourself; otherwise it is the moment to close a popover the list sits in. - Run marks. A row whose store reports thread status carries one mark:
waiting,failed,runningorunread, in that order of precedence, asdata-statuson the row and a dot with its word for a screen reader inside the row's button. refresh()reads the store again. The list does so after every thread, title and run-finished event, and takes the rows of everyag-ui-threads-change; call it when something else changed the store, such as another tab.threads(read-only) is the rows on screen, as the store last listed them. A redraw keeps keyboard focus on the row, delete or confirm it was on.stringstranslates every piece of text (label,untitled,empty,delete,deleteConfirm,deleteYes,deleteNo, and the marks'running,waiting,failed,unread), merged over the English, so{ deleteNo: "Abbrechen" }changes that one string.- Styling. Parts
list,row(plusrow-activeon the thread on screen),row-button,mark(plusmark-running,mark-waiting,mark-failedormark-unread),delete,confirm,empty. The chat's colour tokens apply, plus--ag-ui-danger(the delete confirmation and the failed mark) and--ag-ui-waiting(the waiting mark). The list takes the light or dark half of each from the page's owncolor-scheme, since it sits in your chrome rather than in the chat's. The host carriesdata-emptywhen the chat has no conversations.
The main /bundle does not carry the element. Without a build step, load
/threads/bundle beside it:
<script type="module">
import { defineChat } from "./agents-web-components.bundle.js";
import { defineThreads } from "./agents-web-components.threads.bundle.js";
defineChat();
defineThreads();
</script>
Thread status¶
django-ag-ui 0.84.0, on a mount with a run store, lists each thread with its run's status
(idle, running, waiting, failed), its last_read_at, a reason when it failed and, when
it waits, AG-UI interrupts. RemoteConversationStore (what data-threads-url builds) reads
them onto ThreadMeta as status, reason and interrupts, and works out unread. An older
server, or a mount without a run store, lists none of them and nothing below happens.
- Unread is a thread that changed after it was last read, by the server's clock on both
sides, or was never read (
last_read_atisnull), and is not running now. The server keeps no mark until a thread is read once, so a thread a routine started shows as unread until it is opened, and so does every thread stored before the server kept read marks. - Read. When the element reads a thread (
markRead), the store postsPOST <threads-url><id>/read/, and only once a list carriedstatus, since the route is mounted only beside a run store. The thread then reads as read here until it changes again. A read made before such a list is held and sent with the first one; a page reloaded before any list loses it, and the thread shows unread until opened again. - Keeping it fresh is the host's choice, and opt-in.
data-thread-status="poll"asks the list again every five seconds with its ETag (a304costs nothing);"stream"follows the same URL as Server-Sent Events, read withfetchso the headers and cookie policy apply, reconnecting when the server ends it. A server that answers the stream request with JSON (a WSGI deployment) is polled instead. Without the attribute the list is read when it always was: when the drawer opens, a thread switches, or<ag-ui-threads>re-lists. Each list the watch receives is counted into the unread badge and fired asag-ui-threads-change(THREADS_CHANGE_EVENT, detail{ threads }), which<ag-ui-threads>draws. A store of your own takes part by implementingwatchThreads(listener, transport). - A waiting approval is answered where it waits. Opening a thread whose run is parked on an
approval (
metadata.kind == "approval") shows the approval card on its tool call, as a live run's interrupt does, and the answer starts the run again withresumebuilt by@ag-ui/client'sbuildResumeArray. Asked of the store when the thread is restored (waitingInterrupts(threadId), whichdata-threads-urlanswers from the list with its ETag), so it needs nodata-thread-status. Stop, or leaving the thread, while the person decides sends and writes nothing: the run stays parked and is offered again next time. Aquestionorexternalinterrupt, or a mix, is marked waiting and not offered: the server maps every resume entry to an approval, so answering one that way would approve it. A host driving its ownAgUiClientanswers a parked run the same way withclient.answerParked(interrupts), which asks itsresolveInterruptsonce and sends the resume.