A conversation between people and agents, with actions on each message.
Why are sign-in links expiring before the email arrives?
Support has 12 tickets about it since Friday.
- Scoutfor Ada Lovelace
Thought for 9s
Compare each sign-in email's send time with its delivery time, for the last 200 sends.
Links last 10 minutes, but the mail queue has been taking up to 14. I checked the last 200 sends: 31 arrived after their link expired.
Can you draft a fix that keeps links valid for 30 minutes?
- Scout
On it. I'll change
LINK_TTLto 30 minutes and add a test for a slow queue
import { UiSchema } from "@effect/ui"import { Html } from "@effect/ui/html"import * as stylex from "@stylexjs/stylex"import { Schema } from "effect"import type { Actor } from "./ui/uicontext/components/domain/Actor.ts"import { Stream } from "./ui/uicontext/components/kit/Stream.ts"import { ThreadMessage, ThreadView } from "./ui/uicontext/components/kit/Thread.ts"import { sx } from "./ui/uicontext/components/Sx.ts"const styles = stylex.create({ frame: { inlineSize: "min(100%, 36rem)" },})const ada: Actor = { id: "ada", name: "Ada Lovelace", kind: "person" }const scout: Actor = { id: "scout", name: "Scout", kind: "agent" }const Message = UiSchema.TaggedEnum({ RequestedMessageAction: { message: Schema.String, action: Schema.String, body: Schema.optional(Schema.String) }, ClickedStop: {}, ClickedRetry: {},})export const IssueThread = Html.component({ name: "IssueThread", model: Schema.Struct({ messages: Schema.Array(ThreadMessage), reply: Schema.Literals(["streaming", "stopped"]) }), message: Message,}).make({ init: () => ({ reply: "streaming" as const, messages: [ { id: "m1", actor: ada, at: "2026-12-01T09:41:00Z", body: "Why are sign-in links expiring before the email arrives?" }, { id: "m1b", actor: ada, at: "2026-12-01T09:41:30Z", body: "Support has 12 tickets about it since Friday." }, { id: "m2", actor: scout, onBehalfOf: ada, at: "2026-12-01T09:42:00Z", body: "Links last **10 minutes**, but the mail queue has been taking up to 14. I checked the last 200 sends: 31 arrived after their link expired.", // the agent's reasoning folds into "Thought for 9s" reasoning: { seconds: 9, text: "Compare each sign-in email's send time with its delivery time, for the last 200 sends." }, }, { id: "m3", actor: ada, at: "2026-12-01T09:44:00Z", body: "Can you draft a fix that keeps links valid for 30 minutes?" }, ], }), update: { // the thread copies on its own; the app deletes, and stores an edit's new body RequestedMessageAction: ($, { message, action, body }) => action === "delete" ? $.evolve({ messages: (all) => all.filter((m) => m.id !== message) }) : action === "edit" && body !== undefined ? $.evolve({ messages: (all) => all.map((m) => (m.id === message ? { ...m, body } : m)) }) : $.model, // a stopped reply keeps what it wrote, and can run again ClickedStop: ($) => $.evolve({ reply: "stopped" }), ClickedRetry: ($) => $.evolve({ reply: "streaming" }), }, view: (h, { messages, reply }) => h.div.attrs(sx(styles.frame)).children( ThreadView(h, { props: { label: "ENG-142 discussion", me: ada.id, timeZone: "UTC", messages: messages.map((m) => ({ ...m, // known ids (copy, react, retry, edit, delete) show as icon buttons actions: [ { id: "copy", label: "Copy", consequential: false }, { id: "react", label: "Add a reaction", consequential: false }, ...(m.actor.id === scout.id ? [{ id: "retry", label: "Retry" }] : []), ...(m.actor.id === ada.id ? [{ id: "edit", label: "Edit" }, { id: "delete", label: "Delete", tone: "danger" as const }] : []), ], })), pendingActor: scout, }, onEmit: { RequestedAction: (e) => Message.RequestedMessageAction(e) }, slots: { pending: Stream(h, { status: reply, text: "On it. I'll change `LINK_TTL` to 30 minutes and add a test for a slow queue", ...(reply === "streaming" ? { onStop: Message.ClickedStop() } : { onRetry: Message.ClickedRetry() }), }), }, }), ),})Installation
pnpm dlx shadcn@latest add checkfu/uicontext/threadUsage
import { ThreadView } from "./ui/uicontext/components/kit/Thread.ts"import type { ThreadMessage } from "./ui/uicontext/components/kit/Thread.ts"const Message = UiSchema.TaggedEnum({ RequestedMessageAction: { message: Schema.String, action: Schema.String } })export const IssueThread = (h: Html.H<typeof Message.Type>, messages: ReadonlyArray<ThreadMessage>) => ThreadView(h, { props: { label: "Discussion", messages, // each with an actor, an ISO `at`, a Markdown body and its `actions` me: "ada", }, onEmit: { RequestedAction: ({ message, action }) => Message.RequestedMessageAction({ message, action }) }, })Examples
With an approval
An agent asks before it acts, and the thread keeps the answer.
Email the conference receipt to finance so they can expense it.
- Scoutfor Ada Lovelace
Found it in your inbox: the 2-day pass, $749. Here's the email I'll send.
import { UiSchema } from "@effect/ui"import { Html } from "@effect/ui/html"import * as stylex from "@stylexjs/stylex"import { Schema } from "effect"import type { Actor } from "./ui/uicontext/components/domain/Actor.ts"import { Approval } from "./ui/uicontext/components/kit/Approval.ts"import { type ThreadMessage, ThreadViewWithBodies } from "./ui/uicontext/components/kit/Thread.ts"import { sx } from "./ui/uicontext/components/Sx.ts"const styles = stylex.create({ frame: { inlineSize: "min(100%, 36rem)" },})const ada: Actor = { id: "ada", name: "Ada Lovelace", kind: "person" }const scout: Actor = { id: "scout", name: "Scout", kind: "agent" }const messages: ReadonlyArray<ThreadMessage> = [ { id: "m1", actor: ada, at: "2026-12-01T09:41:00Z", body: "Email the conference receipt to finance so they can expense it." }, { id: "m2", actor: scout, onBehalfOf: ada, at: "2026-12-01T09:42:00Z", body: "Found it in your inbox: the 2-day pass, **$749**. Here's the email I'll send." }, { id: "m3", actor: scout, onBehalfOf: ada, at: "2026-12-01T09:42:00Z", body: "" },]const Message = UiSchema.TaggedEnum({ ChoseSend: { choice: Schema.String } })export const ThreadWithApproval = Html.component({ name: "ThreadWithApproval", model: Schema.Struct({ choice: Schema.NullOr(Schema.String) }), message: Message,}).make({ init: () => ({ choice: null }), update: { ChoseSend: ($, { choice }) => $.evolve({ choice }) }, view: (h, { choice }) => h.div.attrs(sx(styles.frame)).children( ThreadViewWithBodies(h, { props: { label: "Expenses", me: ada.id, messages, timeZone: "UTC" }, onEmit: { RequestedAction: () => undefined }, // the agent's last message is an approval; the others render their text renderBody: (message) => message.id !== "m3" ? undefined : Approval(h, { key: message.id, props: { id: "email-finance", title: "Send this email to [email protected]", fields: [ { label: "Subject", value: "Conference pass receipt, $749" }, { label: "Attachment", value: "receipt-2026.pdf" }, ], digest: "email:[email protected]:7f3a", actor: scout, choices: [ { id: "not-now", label: "Not now" }, { id: "send", label: "Send", primary: true }, ], can: ["answer"], timeZone: "UTC", state: choice === null ? { _tag: "Pending" } : { _tag: "Answered", choice, actor: ada, at: "2026-12-01T09:43:00Z" }, }, onEmit: { Chose: ({ choice }) => Message.ChoseSend({ choice }) }, }), }), ),})Read-only
Thread renders a transcript without actions, for history, exports and audit pages.
- ATAlan Turing
The nightly export failed again at the invoices step.
Second night in a row, same step.
- Scoutfor Alan Turing
The invoices table grew past the export's 5,000 row page limit on Friday. Paging the query fixes it; I opened a draft change.
Thanks. Merged it, and tonight's run finished in 4 minutes.
import type { Html } from "@effect/ui/html"import * as stylex from "@stylexjs/stylex"import type { Actor } from "./ui/uicontext/components/domain/Actor.ts"import { Thread } from "./ui/uicontext/components/kit/Thread.ts"import { sx } from "./ui/uicontext/components/Sx.ts"const styles = stylex.create({ frame: { inlineSize: "min(100%, 36rem)" },})const grace: Actor = { id: "grace", name: "Grace Hopper", kind: "person" }const alan: Actor = { id: "alan", name: "Alan Turing", kind: "person" }const scout: Actor = { id: "scout", name: "Scout", kind: "agent" }// A transcript for an audit page or an export: no actions, no composer, grouped by authorexport const RunTranscript = <M>(h: Html.H<M>) => h.div.attrs(sx(styles.frame)).children( Thread(h, { label: "Incident review transcript", me: grace.id, timeZone: "UTC", messages: [ { id: "t1", actor: alan, at: "2026-11-30T16:02:00Z", body: "The nightly export failed again at the invoices step." }, { id: "t2", actor: alan, at: "2026-11-30T16:03:00Z", body: "Second night in a row, same step." }, { id: "t3", actor: scout, onBehalfOf: alan, at: "2026-11-30T16:04:00Z", body: "The invoices table grew past the export's **5,000 row** page limit on Friday. Paging the query fixes it; I opened a draft change.", }, { id: "t4", actor: grace, at: "2026-11-30T16:10:00Z", body: "Thanks. Merged it, and tonight's run finished in 4 minutes." }, ], }), )API reference
ThreadViewComponent
Props
| Name | Type | Default | Description |
|---|---|---|---|
messagesrequired | ThreadMessage[] | — | The messages to show, oldest first |
me | string | — | The signed-in person's id: their messages are right-aligned bubbles |
label | string | "Messages" | The list's accessible name; "Messages" by default |
pendingActor | Actor | — | Who writes what's in the pending slot (a Stream); the slot shows only with an actor |
agentId | string | — | The id agents see this thread by; derived from label when left out |
locale | string | — | Formats each message's ISO at; the reader's own when left out |
timeZone | string | — | The time zone for message times; the reader's own when left out |
Events
| Event | Payload | Description |
|---|---|---|
RequestedAction | { message: string; action: string; body?: string } | The person picked an action on a message, such as Copy or Retry. An "edit" of the reader's own message (ThreadView) arrives once they save, with the new body. Paging through versions arrives as "previous-branch" or "next-branch". |
Slots
pending
ThreadView function
Options
| Name | Type | Default | Description |
|---|---|---|---|
messagesrequired | ThreadMessage[] | — | The messages to show, oldest first |
me | string | — | The signed-in person's id: their messages are right-aligned bubbles |
pending | { readonly actor: Actor; readonly children: View.Children } | — | Something still arriving (a Stream), shown last under its actor |
label | string | "Messages" | The list's accessible name; "Messages" by default |
locale | string | — | Formats each message's ISO at; the reader's own when left out |
timeZone | string | — | The time zone for message times; the reader's own when left out |
ThreadViewWithBodiesView function
Options
| Name | Type | Description |
|---|---|---|
renderBodyrequired | (message: ThreadMessage) => View.Input<NoInfer<Message>, R> | Draws a message's body; return undefined to show its text as Markdown |
slots | { readonly pending?: View.Input<NoInfer<Message>, P> } | pending: what's still arriving, such as a Stream, shown under pendingActor |
Accessibility
- The thread is a list; each message names its author and time for screen readers, and agent messages say who they acted for.
- Message actions appear on hover and on keyboard focus, and always on touch screens.
- Agents can read recent messages and take an action, naming the message it applies to.