Numbered references in text, with the source on hover.
Churn dropped about a fifth this quarter . Two changes line up with it:
The new import checklist, which admins credit for getting their team live in a day .
Annual plans became the default on the pricing page in early August .
The forecast doesn't separate the two, so treat the split between them as unknown.
Sources
- Q3 retention forecastFinance / Forecasts
- Customer interviews: onboardingResearch
- Pricing change rollout#revenue
import { UiSchema } from "@effect/ui"import { Html } from "@effect/ui/html"import * as stylex from "@stylexjs/stylex"import { Schema } from "effect"import { type Citation, CitedProse, CiteList } from "./ui/uicontext/components/kit/Cite.ts"import { sx } from "./ui/uicontext/components/Sx.ts"import { color, font, space } from "./ui/uicontext/components/tokens.stylex.ts"// An assistant's answer about churn, with its sources. Hover or focus a number to see what it// points to and the passage it used; press it to open the source beside the answer.const styles = stylex.create({ answer: { display: "flex", flexDirection: "column", gap: space.lg, inlineSize: "min(36rem, 100%)", paddingBlockStart: space.xxl }, heading: { margin: 0, color: color.muted, fontSize: font.xs, fontWeight: 600, textTransform: "uppercase", letterSpacing: "0.04em" }, opened: { margin: 0, color: color.muted, fontSize: font.sm },})const sources: ReadonlyArray<Citation> = [ { id: "forecast", label: "1", title: "Q3 retention forecast", kind: "file", source: "Finance / Forecasts", snippet: "Monthly churn fell from 3.1% in June to 2.4% in September.", }, { id: "interviews", label: "2", title: "Customer interviews: onboarding", kind: "page", source: "Research", snippet: "Seven of nine admins said the import checklist got them live in a day.", }, { id: "thread", label: "3", title: "Pricing change rollout", kind: "message", source: "#revenue", snippet: "Annual plans moved to the default on the pricing page on August 4.", },]const answer = [ "Churn dropped about **a fifth** this quarter [1]. Two changes line up with it:", "", "- The new import checklist, which admins credit for getting their team live in a day [2].", "- Annual plans became the default on the pricing page in early August [3].", "", "The forecast doesn't separate the two, so treat the split between them as unknown.",].join("\n")const Message = UiSchema.TaggedEnum({ OpenedSource: { id: Schema.String } })export const ChurnAnswer = Html.component({ name: "ChurnAnswer", model: Schema.Struct({ opened: Schema.NullOr(Schema.String) }), message: Message,}).make({ init: () => ({ opened: null }), update: { OpenedSource: ($, { id }) => $.evolve({ opened: id }) }, view: (h, { opened }) => h.article.attrs({ "aria-label": "Answer", ...sx(styles.answer) }).children( CitedProse(h, answer, sources, { onOpen: (id) => Message.OpenedSource({ id }) }), h.h3.attrs(sx(styles.heading)).children("Sources"), CiteList(h, { citations: sources, onOpen: (id) => Message.OpenedSource({ id }) }), h.p .attrs({ role: "status", ...sx(styles.opened) }) .children(opened === null ? "" : `Opened “${sources.find((s) => s.id === opened)?.title ?? opened}” beside the answer.`), ),})Installation
pnpm dlx shadcn@latest add checkfu/uicontext/citeUsage
import { type Citation, CitedProse } from "./ui/uicontext/components/kit/Cite.ts"const Message = UiSchema.TaggedEnum({ OpenedSource: { id: Schema.String } })// `[n]` markers in the agent's Markdown become chips; a click opens the source in the appexport const Answer = (h: Html.H<typeof Message.Type>, text: string, sources: ReadonlyArray<Citation>) => CitedProse(h, text, sources, { onOpen: (id) => Message.OpenedSource({ id }) })Examples
Chips
A number, a named chip, a link and a deleted source. Each has a full accessible name and shows its source on hover or focus.
- A numberResponse times halved after the queue split.
- A named chip
- A web pageCard rules
- No longer available
import type { Html } from "@effect/ui/html"import * as stylex from "@stylexjs/stylex"import { CiteChip } from "./ui/uicontext/components/kit/Cite.ts"import { sx } from "./ui/uicontext/components/Sx.ts"import { color, font, space } from "./ui/uicontext/components/tokens.stylex.ts"// Every kind of chip: a number in running text, a named chip with its source's kind, a link that// follows `href`, and a source that was deleted, which still says what it was.const styles = stylex.create({ list: { display: "grid", gap: space.lg, margin: 0, padding: 0, paddingBlockStart: space.xxl, listStyle: "none", inlineSize: "min(34rem, 100%)" }, row: { display: "flex", alignItems: "baseline", flexWrap: "wrap", gap: space.md, color: color.fg, fontSize: font.base, lineHeight: 1.6 }, label: { minInlineSize: "9rem", color: color.muted, fontSize: font.sm },})export const CitationChips = <M>(h: Html.H<M>) => h.ul.attrs(sx(styles.list)).children( h.li.attrs(sx(styles.row)).children( h.span.attrs(sx(styles.label)).children("A number"), h.span.children( "Response times halved after the queue split", CiteChip(h, { id: "a", label: "1", title: "Support metrics, October", kind: "row", source: "Support dashboard", snippet: "Median first reply: 2h 10m → 58m." }), ".", ), ), h.li.attrs(sx(styles.row)).children( h.span.attrs(sx(styles.label)).children("A named chip"), CiteChip(h, { id: "b", label: "billing-api", title: "Retry failed charges", kind: "code", source: "northwind/billing-api #412", snippet: "Retries back off for up to 24 hours." }), ), h.li.attrs(sx(styles.row)).children( h.span.attrs(sx(styles.label)).children("A web page"), CiteChip(h, { id: "c", label: "Card rules", title: "Card network dispute timelines", kind: "web", source: "example.com", href: "https://example.com/disputes" }), ), h.li.attrs(sx(styles.row)).children( h.span.attrs(sx(styles.label)).children("No longer available"), CiteChip(h, { id: "d", label: "4", title: "Vendor contract draft", kind: "file", source: "Legal", unavailable: true }), ), )A summary with its sources
[n] markers become chips; a link opens its record, and a deleted source still says what it was.
Retries have failed since the evening deploy , which started building the idempotency key from the cart id 2. Mira rolled back at 10:02 following the old checklist ; nobody has confirmed retries work again.
import type { Html } from "@effect/ui/html"import * as stylex from "@stylexjs/stylex"import { type Citation, CitedProse } from "./ui/uicontext/components/kit/Cite.ts"import { sx } from "./ui/uicontext/components/Sx.ts"import { color, font, radius, space } from "./ui/uicontext/components/tokens.stylex.ts"// An issue's summary, written by an agent from the thread and two linked records. Each claim// points at what it came from; one source was deleted since, and says so.const styles = stylex.create({ card: { inlineSize: "min(100%, 30rem)", marginBlockStart: space.xxl, padding: space.lg, borderRadius: radius.lg, borderWidth: 1, borderStyle: "solid", borderColor: color.line, backgroundColor: color.panel, fontSize: font.sm, },})const sources: ReadonlyArray<Citation> = [ { id: "c1", label: "1", title: "Ben Okafor's comment, Dec 1", kind: "comment", source: "PAY-398", snippet: "Card retries fail with declined since the 5 PM deploy." }, { id: "c2", label: "2", title: "Deploy 2026.12.01-3", kind: "row", source: "Deploys", href: "#deploys", snippet: "Changed: idempotency key now built from the cart id." }, { id: "c3", label: "3", title: "Rollback checklist", kind: "page", source: "Runbooks", unavailable: true },]const summary = "Retries have failed since the evening deploy [1], which started building the idempotency key from the cart id [2]. " + "Mira rolled back at 10:02 following the old checklist [3]; nobody has confirmed retries work again."export const IssueSummary = <M>(h: Html.H<M>) => h.div.attrs(sx(styles.card)).children(CitedProse(h, summary, sources))API reference
CiteListView function
Options
| Name | Type | Default | Description |
|---|---|---|---|
citationsrequired | Citation[] | — | The sources, numbered in the order they come |
label | string | "Sources" | The list's accessible name; "Sources" by default |
onOpen | (id: string) => Message | — | The message to send when a source is opened; without it, sources with a link open it |
CiteView function
Options
| Name | Type | Description |
|---|---|---|
onOpen | (id: string) => Message | The app opens the source itself (a side panel, a row); otherwise the chip follows href |
variant | "number" | "chip" | "number" for an inline marker ("1"), "chip" for the label with the source's kind |
Accessibility
- A chip is named for what it points to ("Source 2: Q3 forecast"), not only its number, and shows the quote or title as a tooltip.
- It's a link when the source has one and a button when the app opens it; a source that's gone is plain text that says so.
- The list of sources is an ordered list named Sources.