Queue
Displays the agent's todo list, split into what is left and what is done.
// Inline SVG icons from Lucide (https://lucide.dev), ISC License, Copyright (c) Lucide Icons and Contributors.
import { For, createMemo } from "solid-js"
import {
useDemoChat,
type UIDataTypes,
type UIMessage,
createChat,
getMessageText
} from "~/lib/ai-demo-chat"
import { Bubble, BubbleContent } from "~/components/ui/bubble"
import { Button } from "~/components/ui/button"
import { Message, MessageContent } from "~/components/ui/message"
import {
Trace,
TraceCollapsible,
TraceCollapsibleContent,
TraceCollapsibleTrigger,
TraceIcon,
TraceLine,
TraceTitle
} from "~/components/ui/trace"
type ChatMessage = UIMessage<
unknown,
UIDataTypes,
{
writeTodos: {
input: {
todos: {
content: string
status: "pending" | "in_progress" | "completed"
}[]
}
output: string
}
}
>
type Todo = Extract<
ChatMessage["parts"][number],
{ type: "tool-writeTodos"; state: "input-available" }
>["input"]["todos"][number]
const TODOS = [
"Add a dark variant to the theme tokens",
"Read the theme from a cookie",
"Add a toggle to the settings page",
"Check contrast on the charts"
]
function todosAt(current: number) {
return TODOS.map(
(content, index) =>
({
content,
status:
index < current
? "completed"
: index === current
? "in_progress"
: "pending"
}) satisfies Todo
)
}
const chat = createChat<ChatMessage>()
.user("Add dark mode to the settings page.")
.assistant(({ writer }) => {
TODOS.forEach((_, index) => {
writer
.tool("writeTodos", { input: { todos: todosAt(index) } })
.output("Updated the todo list.")
writer.sleep(1400)
})
writer
.tool("writeTodos", { input: { todos: todosAt(TODOS.length) } })
.output("Updated the todo list.")
writer.text("Dark mode is in. The toggle is under Settings, Appearance.")
})
const transcript = chat.get()
const [question] = chat.get(1)
const transport = chat.transport({ delayMs: 20 })
function TodoLine(componentProps: { todo: Todo; streaming: boolean }) {
const content = createMemo(() => {
const { todo, streaming } = componentProps
return (
<TraceLine
status={
streaming && todo.status === "in_progress" ? "running" : undefined
}
>
<TraceIcon>
{todo.status === "completed" ? (
<svg
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
>
<circle cx="12" cy="12" r="10" />
<path d="m16 9-5.5 5.5L8 12" />
</svg>
) : todo.status === "in_progress" ? (
<svg
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
>
<circle cx="12" cy="12" r="1" />
<circle cx="12" cy="12" r="10" />
</svg>
) : (
<svg
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
>
<circle cx="12" cy="12" r="10" />
</svg>
)}
</TraceIcon>
<TraceTitle>{todo.content}</TraceTitle>
</TraceLine>
)
})
return <>{content()}</>
}
function TodoQueue(componentProps: { todos: Todo[]; streaming: boolean }) {
const content = createMemo(() => {
const { todos, streaming } = componentProps
const pending = todos.filter((todo) => todo.status !== "completed")
const completed = todos.filter((todo) => todo.status === "completed")
return (
<Trace>
{pending.length > 0 && (
<TraceCollapsible defaultOpen>
<TraceCollapsibleTrigger>
<TraceLine>
<TraceIcon>
<svg
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
>
<path d="M13 5h8" />
<path d="M13 12h8" />
<path d="M13 19h8" />
<path d="m3 17 2 2 4-4" />
<rect x="3" y="4" width="6" height="6" rx="1" />
</svg>
</TraceIcon>
<TraceTitle>{pending.length} to do</TraceTitle>
</TraceLine>
</TraceCollapsibleTrigger>
<TraceCollapsibleContent>
<Trace>
{
<For each={pending}>
{(todo) => <TodoLine todo={todo} streaming={streaming} />}
</For>
}
</Trace>
</TraceCollapsibleContent>
</TraceCollapsible>
)}
{completed.length > 0 && (
<TraceCollapsible defaultOpen>
<TraceCollapsibleTrigger>
<TraceLine>
<TraceIcon>
<svg
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
>
<path d="M13 5h8" />
<path d="M13 12h8" />
<path d="M13 19h8" />
<path d="m3 17 2 2 4-4" />
<path d="m3 7 2 2 4-4" />
</svg>
</TraceIcon>
<TraceTitle>{completed.length} completed</TraceTitle>
</TraceLine>
</TraceCollapsibleTrigger>
<TraceCollapsibleContent>
<Trace>
{
<For each={completed}>
{(todo) => <TodoLine todo={todo} streaming={streaming} />}
</For>
}
</Trace>
</TraceCollapsibleContent>
</TraceCollapsible>
)}
</Trace>
)
})
return <>{content()}</>
}
export default function QueueDemo() {
const { messages, sendMessage, setMessages, status } = useDemoChat({
messages: transcript,
transport
})
const busy = () => status() === "submitted" || status() === "streaming"
return (
<div class="flex min-h-72 w-full max-w-sm flex-col gap-4 py-6 text-sm">
{
<For each={messages()}>
{(message) => {
const content = createMemo(() => {
if (message.role === "user") {
return (
<Message align="end">
<MessageContent>
<Bubble align="end" variant="muted">
<BubbleContent>{getMessageText(message)}</BubbleContent>
</Bubble>
</MessageContent>
</Message>
)
}
const streaming = busy() && message === messages().at(-1)
const todos = message.parts
.filter((part) => part.type === "tool-writeTodos")
.filter((part) => part.state !== "input-streaming")
.at(-1)?.input?.todos
const text = getMessageText(message)
return (
<Message>
<MessageContent class="gap-4">
{todos && <TodoQueue todos={todos} streaming={streaming} />}
{text && <p>{text}</p>}
</MessageContent>
</Message>
)
})
return <>{content()}</>
}}
</For>
}
{!busy() && (
<Button
variant="outline"
size="sm"
class="mt-auto self-start"
onClick={() => {
setMessages([])
sendMessage(question)
}}
>
Replay
</Button>
)}
</div>
)
}Queue is the agentโs todo list. Todos sit in two sections, To do and Completed, and the icon on each todo shows its status. The agent updates the list as it works, so a todo moves from one section to the other when it is done.
Queue is built with Trace with a TraceCollapsible for each section.
Installation
Queue is built with the Trace component.
Install the required Solid UI dependencies:
Copy and paste the following code into your project.
// Inline SVG icons from Lucide (https://lucide.dev), ISC License, Copyright (c) Lucide Icons and Contributors.
import type { ComponentProps, JSX } from "@solidjs/web"
import { merge, omit } from "solid-js"
import { cn } from "~/lib/utils"
import {
Collapsible,
CollapsibleContent,
CollapsibleTrigger
} from "~/components/ui/collapsible"
export function Trace(
props: Omit<ComponentProps<"div">, "class"> & { class?: string }
) {
return (
<div
{...props}
data-slot="trace"
class={cn(
"gap-2 *:has-[>[data-slot=trace-line]]:rounded-md *:has-[>[data-slot=trace-line]]:focus-visible:ring-3 *:has-[>[data-slot=trace-line]]:focus-visible:ring-ring/50 flex w-full min-w-0 flex-col *:has-[>[data-slot=trace-line]]:flex *:has-[>[data-slot=trace-line]]:w-fit *:has-[>[data-slot=trace-line]]:max-w-full *:has-[>[data-slot=trace-line]]:min-w-0 *:has-[>[data-slot=trace-line]]:text-left *:has-[>[data-slot=trace-line]]:outline-none",
props.class
)}
/>
)
}
export function TraceLine(
props: Omit<ComponentProps<"span">, "class"> & {
class?: string
status?: "running" | "error" | "pending" | undefined
}
) {
const rest = omit(props, "class", "status")
return (
<span
{...rest}
data-slot="trace-line"
data-status={props.status ?? undefined}
class={cn(
"gap-2 text-sm flex w-fit max-w-full min-w-0 items-center text-muted-foreground transition-colors in-[a,button]:cursor-pointer in-[a:hover,button:hover]:text-foreground data-[status=error]:text-destructive data-[status=error]:in-[a:hover,button:hover]:text-destructive data-[status=pending]:opacity-60 data-[status=running]:*:data-[slot=trace-title]:shimmer",
props.class
)}
/>
)
}
export function TraceIcon(
props: Omit<ComponentProps<"span">, "class"> & { class?: string }
) {
return (
<span
{...props}
data-slot="trace-icon"
class={cn(
"size-4 [&_svg:not([class*='size-'])]:size-4 [[data-slot=trace-title]~&]:-ml-1 flex shrink-0 items-center justify-center [&_svg]:pointer-events-none",
props.class
)}
/>
)
}
export function TraceTitle(
props: Omit<ComponentProps<"span">, "class"> & { class?: string }
) {
return (
<span
{...props}
data-slot="trace-title"
class={cn(
"min-w-0 truncate motion-reduce:shimmer-none",
props.class
)}
/>
)
}
export function TraceDescription(
props: Omit<ComponentProps<"span">, "class"> & { class?: string }
) {
return (
<span
{...props}
data-slot="trace-description"
class={cn(
"shrink-0 text-muted-foreground/70 tabular-nums",
props.class
)}
/>
)
}
export function TraceCollapsible(props: ComponentProps<typeof Collapsible>) {
const rest = omit(props, "class", "render")
return (
<Collapsible
{...rest}
class={cn(
"flex w-full min-w-0 flex-col",
props.class
)}
render={(part, state) => {
const forwarded = merge(part, { "data-slot": "trace-collapsible" })
return props.render ? (
props.render(forwarded, state)
) : (
<div {...forwarded} />
)
}}
/>
)
}
export function TraceCollapsibleTrigger(
props: ComponentProps<typeof CollapsibleTrigger>
) {
const rest = omit(props, "class", "children", "render")
return (
<CollapsibleTrigger
{...rest}
class={cn(
"gap-1 rounded-md focus-visible:ring-3 focus-visible:ring-ring/50 group/trace-collapsible-trigger flex w-fit max-w-full min-w-0 cursor-pointer items-center text-left text-muted-foreground transition-colors outline-none hover:text-foreground has-[[data-slot=trace-line][data-status=error]]:text-destructive",
props.class
)}
render={(part, state) => {
const forwarded = merge(part, {
"data-slot": "trace-collapsible-trigger"
})
return props.render ? (
props.render(forwarded, state)
) : (
<button {...forwarded} />
)
}}
>
{props.children}
<TraceIcon class="transition-transform group-aria-expanded/trace-collapsible-trigger:rotate-90">
<svg
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
class="size-4"
>
<path d="m9 18 6-6-6-6" />
</svg>
</TraceIcon>
</CollapsibleTrigger>
)
}
export function TraceCollapsibleContent(
props: Omit<ComponentProps<typeof CollapsibleContent>, "children"> & {
children?: JSX.Element
}
) {
const rest = omit(props, "class", "children", "render")
return (
<CollapsibleContent
{...rest}
class="duration-200 h-(--collapsible-panel-height) min-w-0 overflow-hidden transition-[height] data-ending-style:h-0 data-starting-style:h-0"
render={(part, state) => {
const forwarded = merge(part, {
"data-slot": "trace-collapsible-content"
})
return props.render ? (
props.render(forwarded, state)
) : (
<div {...forwarded} />
)
}}
>
<div
data-slot="trace-collapsible-content-inner"
class={cn(
"mt-2 mb-1 ml-[calc(--spacing(2)-1px)] border-l pr-1 pl-4 leading-relaxed min-w-0 wrap-break-word text-muted-foreground",
props.class
)}
>
{props.children}
</div>
</CollapsibleContent>
)
}Update the import paths to match your project setup.
Usage
import {
Trace,
TraceCollapsible,
TraceCollapsibleContent,
TraceCollapsibleTrigger,
TraceIcon,
TraceLine,
TraceTitle
} from "~/components/ui/trace"<Trace>
<TraceCollapsible defaultOpen>
<TraceCollapsibleTrigger>
<TraceLine>
<TraceIcon>
<ListTodoIcon />
</TraceIcon>
<TraceTitle>2 to do</TraceTitle>
</TraceLine>
</TraceCollapsibleTrigger>
<TraceCollapsibleContent>
<Trace>
<TraceLine>
<TraceIcon>
<CircleIcon />
</TraceIcon>
<TraceTitle>Update the registry snapshots</TraceTitle>
</TraceLine>
<TraceLine>
<TraceIcon>
<CircleIcon />
</TraceIcon>
<TraceTitle>Add tests for the combobox</TraceTitle>
</TraceLine>
</Trace>
</TraceCollapsibleContent>
</TraceCollapsible>
<TraceCollapsible>
<TraceCollapsibleTrigger>
<TraceLine>
<TraceIcon>
<ListChecksIcon />
</TraceIcon>
<TraceTitle>1 completed</TraceTitle>
</TraceLine>
</TraceCollapsibleTrigger>
<TraceCollapsibleContent>
<Trace>
<TraceLine>
<TraceIcon>
<CircleCheckIcon />
</TraceIcon>
<TraceTitle>Add a changeset</TraceTitle>
</TraceLine>
</Trace>
</TraceCollapsibleContent>
</TraceCollapsible>
</Trace>Descriptions
A todo with a description is a TraceCollapsible that opens to show it. A todo without one stays a TraceLine.
// Inline SVG icons from Lucide (https://lucide.dev), ISC License, Copyright (c) Lucide Icons and Contributors.
import { For, createMemo } from "solid-js"
import {
Trace,
TraceCollapsible,
TraceCollapsibleContent,
TraceCollapsibleTrigger,
TraceIcon,
TraceLine,
TraceTitle
} from "~/components/ui/trace"
const todos: { title: string; description?: string; done: boolean }[] = [
{
title: "Write the migration guide",
description: "Cover the renamed props and the new data attributes.",
done: true
},
{ title: "Add a changeset", done: true },
{
title: "Fix the focus ring on the select trigger",
description: "It is clipped by overflow-hidden on the field.",
done: false
},
{ title: "Update the registry snapshots", done: false },
{
title: "Add tests for the combobox",
description: "Typing, clearing and keyboard selection.",
done: false
}
]
function TodoRow(componentProps: { todo: (typeof todos)[number] }) {
const content = createMemo(() => {
const { todo } = componentProps
const line = (
<TraceLine>
<TraceIcon>
{todo.done ? (
<svg
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
>
<circle cx="12" cy="12" r="10" />
<path d="m16 9-5.5 5.5L8 12" />
</svg>
) : (
<svg
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
>
<circle cx="12" cy="12" r="10" />
</svg>
)}
</TraceIcon>
<TraceTitle>{todo.title}</TraceTitle>
</TraceLine>
)
if (!todo.description) {
return line
}
return (
<TraceCollapsible>
<TraceCollapsibleTrigger>{line}</TraceCollapsibleTrigger>
<TraceCollapsibleContent>{todo.description}</TraceCollapsibleContent>
</TraceCollapsible>
)
})
return <>{content()}</>
}
export default function QueueDescriptions() {
const pending = todos.filter((todo) => !todo.done)
const completed = todos.filter((todo) => todo.done)
return (
<Trace class="max-w-sm">
<TraceCollapsible defaultOpen>
<TraceCollapsibleTrigger>
<TraceLine>
<TraceIcon>
<svg
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
>
<path d="M13 5h8" />
<path d="M13 12h8" />
<path d="M13 19h8" />
<path d="m3 17 2 2 4-4" />
<rect x="3" y="4" width="6" height="6" rx="1" />
</svg>
</TraceIcon>
<TraceTitle>{pending.length} to do</TraceTitle>
</TraceLine>
</TraceCollapsibleTrigger>
<TraceCollapsibleContent>
<Trace>
{<For each={pending}>{(todo) => <TodoRow todo={todo} />}</For>}
</Trace>
</TraceCollapsibleContent>
</TraceCollapsible>
<TraceCollapsible>
<TraceCollapsibleTrigger>
<TraceLine>
<TraceIcon>
<svg
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
>
<path d="M13 5h8" />
<path d="M13 12h8" />
<path d="M13 19h8" />
<path d="m3 17 2 2 4-4" />
<path d="m3 7 2 2 4-4" />
</svg>
</TraceIcon>
<TraceTitle>{completed.length} completed</TraceTitle>
</TraceLine>
</TraceCollapsibleTrigger>
<TraceCollapsibleContent>
<Trace>
{<For each={completed}>{(todo) => <TodoRow todo={todo} />}</For>}
</Trace>
</TraceCollapsibleContent>
</TraceCollapsible>
</Trace>
)
}<TraceCollapsible>
<TraceCollapsibleTrigger>
<TraceLine>
<TraceIcon>
<CircleIcon />
</TraceIcon>
<TraceTitle>Fix the focus ring on the select trigger</TraceTitle>
</TraceLine>
</TraceCollapsibleTrigger>
<TraceCollapsibleContent>
It is clipped by overflow-hidden on the field.
</TraceCollapsibleContent>
</TraceCollapsible>AI SDK
The agent writes its todos with a tool, writeTodos in this example. Each call sends the whole list, so render the last call and skip one whose input is still streaming.
const todos = message.parts
.filter((part) => part.type === "tool-writeTodos")
.filter((part) => part.state !== "input-streaming")
.at(-1)?.input?.todosMap each todo status to a section, an icon and a TraceLine status. Set "running" on the todo in progress only while the chat streams, so its title stops shimmering when the agent stops.
Migrating from AI SDK Elements
If you added Queue from AI SDK Elements, your project has a components/ai-elements/queue.tsx wrapper. Paste this prompt into your coding agent to rebuild it on Trace. Every export keeps its name and props, so the code that uses it keeps working.
Migrate components/ai-elements/queue.tsx from AI SDK Elements to the Solid UI Trace component.
Keep every export, with the same name and props, so the code that imports it keeps working. Only change how each part renders.
1. Install Trace: npx solidui-cli@latest add trace
2. Read https://www.solid-ui.com/docs/ai-elements/queue.md and build Queue the same way.
3. Rebuild each part:
- Queue renders a Trace.
- QueueSection, QueueSectionTrigger and QueueSectionContent render TraceCollapsible, TraceCollapsibleTrigger and TraceCollapsibleContent.
- QueueSectionLabel renders a TraceLine with a TraceIcon and a TraceTitle, like "2 to do".
- QueueList renders a Trace. Drop the ScrollArea.
- QueueItem renders a TraceLine. QueueItemIndicator renders a TraceIcon, QueueItemContent a TraceTitle, and QueueItemDescription a TraceDescription.
- Keep QueueItemActions, QueueItemAction and the attachment parts as they are.
4. Remove the imports the file no longer uses.
5. Run the type checker and fix any errors.API Reference
See Trace.