A short summary of a long thread or record, with its sources.
Thread summary
Summarizes 38 comments. Uses 1 credit.
import { Command, UiSchema } from "@effect/ui"import { Html } from "@effect/ui/html"import * as stylex from "@stylexjs/stylex"import { Effect, Schema } from "effect"import { Summary, SummaryStatus } from "./ui/uicontext/components/kit/Summary.ts"import { sx } from "./ui/uicontext/components/Sx.ts"import { sources, summary } from "./incident.ts"const styles = stylex.create({ frame: { inlineSize: "min(100%, 34rem)" },})const words = summary.split(/(?<= )/u)const Message = UiSchema.TaggedEnum({ RequestedSummary: {}, StoppedSummary: {}, ReceivedWords: { run: Schema.Number },})// stands in for the model: a first token after 700ms, then a few words every 60msconst WaitForWords = Command.make("Example.WaitForWords", { args: { run: Schema.Number, first: Schema.Boolean } }, ({ run, first }) => Effect.sleep(first ? "700 millis" : "60 millis").pipe(Effect.as(Message.ReceivedWords({ run }))),)export const IncidentSummary = Html.component({ name: "IncidentSummary", model: Schema.Struct({ status: SummaryStatus, shown: Schema.Number, run: Schema.Number, generatedAt: Schema.NullOr(Schema.String) }), message: Message,}).make({ init: () => ({ status: "idle", shown: 0, run: 0, generatedAt: null }), update: { // a new run: the old text goes once the first words arrive RequestedSummary: ($) => $.evolve({ status: "waiting", shown: 0, run: (n) => n + 1 }).run(WaitForWords.make({ run: $.model.run + 1, first: true })), StoppedSummary: ($) => $.evolve({ status: "stopped" }), // words from an earlier run, or after Stop, are dropped ReceivedWords: ($, { run }) => { if (run !== $.model.run || ($.model.status !== "waiting" && $.model.status !== "streaming")) return $.model const shown = Math.min(words.length, $.model.shown + 3) return shown === words.length ? $.evolve({ status: "succeeded", shown, generatedAt: "2026-12-01T11:58:00Z" }) : $.evolve({ status: "streaming", shown }).run(WaitForWords.make({ run, first: false })) }, }, view: (h, model) => h.div.attrs(sx(styles.frame)).children( Summary(h, { props: { id: "pay-412", agentId: "summary-incident", title: "Thread summary", status: model.status, text: words.slice(0, model.shown).join(""), sources: model.status === "succeeded" || model.status === "stopped" ? sources : [], generatedAt: model.generatedAt ?? undefined, now: "2026-12-01T12:00:00Z", usage: "Summarizes 38 comments. Uses 1 credit.", }, onEmit: { RequestedGenerate: () => Message.RequestedSummary(), RequestedRegenerate: () => Message.RequestedSummary(), RequestedStop: () => Message.StoppedSummary(), OpenedSource: () => undefined, }, }), ),})Installation
pnpm dlx shadcn@latest add checkfu/uicontext/summaryUsage
import type { Citation } from "./ui/uicontext/components/kit/Cite.ts"import { Summary, type SummaryStatus } from "./ui/uicontext/components/kit/Summary.ts"const Message = UiSchema.TaggedEnum({ RequestedThreadSummary: {}, RequestedStopThreadSummary: {},})// your app runs the model: pass its status and text as they arrive, then the sources it usedexport const ThreadSummary = ( h: Html.H<typeof Message.Type>, run: { readonly status: SummaryStatus; readonly text: string; readonly sources: ReadonlyArray<Citation> },) => Summary(h, { props: { id: "thread-summary", title: "Summary", ...run }, onEmit: { RequestedGenerate: () => Message.RequestedThreadSummary(), RequestedRegenerate: () => Message.RequestedThreadSummary(), RequestedStop: () => Message.RequestedStopThreadSummary(), OpenedSource: () => undefined, }, })Examples
Out of date, and failed
A summary whose thread moved on says why and offers Regenerate. A failed one says what happened, with Try again.
Thread summary
Out of date6 new comments since it was written
Meeting summary
The transcript service didn't answer. Try again in a moment.
import { Command, UiSchema } from "@effect/ui"import { Html } from "@effect/ui/html"import * as stylex from "@stylexjs/stylex"import { Effect, Schema } from "effect"import { Summary, SummaryStatus } from "./ui/uicontext/components/kit/Summary.ts"import { sx } from "./ui/uicontext/components/Sx.ts"import { space } from "./ui/uicontext/components/tokens.stylex.ts"import { sources, summary } from "./incident.ts"const styles = stylex.create({ column: { display: "grid", gap: space.lg, inlineSize: "min(100%, 34rem)" },})const Message = UiSchema.TaggedEnum({ RequestedThreadSummary: {}, RequestedMeetingSummary: {}, CompletedThreadRun: {}, CompletedMeetingRun: { attempt: Schema.Number },})// stand-ins for the model: the thread summary takes a second; the meeting summary fails onceconst RunThread = Command.make("Example.RunThread", {}, () => Effect.sleep("1 second").pipe(Effect.as(Message.CompletedThreadRun())),)const RunMeeting = Command.make("Example.RunMeeting", { args: { attempt: Schema.Number } }, ({ attempt }) => Effect.sleep("1 second").pipe(Effect.as(Message.CompletedMeetingRun({ attempt }))),)const meeting = "The team agreed to ship the 3-D Secure fix on Thursday behind a flag [1], and to page the payments on-call for any EU decline spike [2]."export const SummaryRecovery = Html.component({ name: "SummaryRecovery", model: Schema.Struct({ thread: SummaryStatus, stale: Schema.Boolean, meeting: SummaryStatus, attempts: Schema.Number }), message: Message,}).make({ init: () => ({ thread: "succeeded", stale: true, meeting: "failed", attempts: 1 }), update: { RequestedThreadSummary: ($) => $.evolve({ thread: "waiting" }).run(RunThread.make()), CompletedThreadRun: ($) => $.evolve({ thread: "succeeded", stale: false }), RequestedMeetingSummary: ($) => $.evolve({ meeting: "waiting", attempts: (n) => n + 1 }).run(RunMeeting.make({ attempt: $.model.attempts + 1 })), CompletedMeetingRun: ($) => $.evolve({ meeting: "succeeded" }), }, view: (h, model) => h.div.attrs(sx(styles.column)).children( Summary(h, { key: "thread", props: { id: "pay-412", agentId: "summary-stale", title: "Thread summary", status: model.thread, text: summary, sources, stale: model.stale, staleReason: "6 new comments since it was written", generatedAt: model.stale ? "2026-12-01T07:10:00Z" : "2026-12-01T12:00:00Z", now: "2026-12-01T12:00:00Z", }, onEmit: { RequestedGenerate: () => undefined, RequestedRegenerate: () => Message.RequestedThreadSummary(), RequestedStop: () => undefined, OpenedSource: () => undefined, }, }), Summary(h, { key: "meeting", props: { id: "standup-1201", agentId: "summary-failed", title: "Meeting summary", status: model.meeting, text: model.meeting === "succeeded" ? meeting : "", sources: model.meeting === "succeeded" ? [ { id: "m1", label: "1", title: "Transcript, 09:14", source: "Payments standup", kind: "file", href: "#t-0914" }, { id: "m2", label: "2", title: "Transcript, 09:21", source: "Payments standup", kind: "file", href: "#t-0921" }, ] : [], notice: "The transcript service didn't answer. Try again in a moment.", // no Stop: the transcript service runs to the end can: ["regenerate"], }, onEmit: { RequestedGenerate: () => undefined, RequestedRegenerate: () => Message.RequestedMeetingSummary(), RequestedStop: () => undefined, OpenedSource: () => undefined, }, }), ),})Refused, empty and read-only
Out of credits, nothing to say, and a viewer who can't start a run: each says why in a sentence.
API reference
Props
| Name | Type | Description |
|---|---|---|
agentId | string | The id agents see this by; summary:<id> when left out |
idrequired | string | Identifies the summary in the events it sends |
titlerequired | string | The card's heading: "Summary" |
statusrequired | SummaryStatus | Where it stands: idle, waiting, streaming, succeeded, stopped, empty, failed or refused |
textrequired | string | Markdown; [n] names the source whose label is n |
sourcesrequired | Citation[] | What it was written from, numbered; [n] in the text cites one |
stale | boolean | Its inputs changed since it was written |
staleReason | string | Why it's out of date, shown with Regenerate: "5 new comments since" |
generatedAt | string | When it was written, as an ISO timestamp; shown with locale and timeZone |
now | string | Now, as an ISO timestamp, to say "Generated 2 hours ago"; a date and time when absent |
locale | string | Formats generatedAt; the reader's own when left out |
timeZone | string | The time zone for generatedAt; the reader's own when left out |
attribution | AttributionData | Who asked for it, or what wrote it |
notice | string | For failed and refused: what went wrong and what to do, as a sentence |
can | Can(["regenerate", "stop"]) | What the viewer may do: "regenerate" shows Generate and Regenerate (not for a viewer, or a plan without it); "stop" shows Stop (not when the run can't be cancelled). Both when left out. |
usage | string | What a run costs, said before it runs: "Uses 1 credit" |
openSourcesInApp | boolean | The app opens sources itself (OpenedSource) instead of following their links |
waitingLabel | string | What shows while nothing has arrived: "Searching…" (default "Summarizing…") |
collapseAfter | number | Collapse text longer than this many characters behind "Show more" |
Events
| Event | Payload | Description |
|---|---|---|
RequestedGenerate | { id: string } | The person asked for a first summary |
RequestedRegenerate | { id: string } | A new run; the old text stays until the new one arrives |
RequestedStop | { id: string } | The person stopped the run |
OpenedSource | { id: string; source: string } | The person opened a source, when openSourcesInApp is set |
Agent actions
| Action | Description |
|---|---|
ClickedGenerate | Generate the summary |
ClickedRegenerate | Write the summary again from its current inputs (a new run) |
ClickedStop | Stop the summary being written |
Accessibility
- The summary is a region named by its title, marked busy while it's written; why it's out of date is said in words.
- Show more says whether it's expanded, and its sources are a disclosure of numbered citations.
- Agents can generate, regenerate or stop it.