Renders Markdown with readable type.
Retry failed charges
The billing worker now retries a declined charge three times over a day before it marks the invoice unpaid. Nothing changes for charges that succeed the first time.
What changed
Read the decline code from the card network.
Schedule the retry with
backoff(attempt).Email the customer only after the last attempt fails.
Retry schedule
| Attempt | Wait | Emails sent | Share recovered |
|---|---|---|---|
| 1 | 1 hour | none | 38% |
| 2 | 6 hours | none | 21% |
| 3 | 24 hours | one | 9% |
export const backoff = (attempt: number) => [Duration.hours(1), Duration.hours(6), Duration.hours(24)][attempt]Declines for a closed account aren't retried: the card won't work again.
Tests cover each decline code. See the runbook for how to replay a day of retries.
import type { Html } from "@effect/ui/html"import * as stylex from "@stylexjs/stylex"import { Prose } from "./ui/uicontext/components/kit/Prose.ts"import { sx } from "./ui/uicontext/components/Sx.ts"import { space } from "./ui/uicontext/components/tokens.stylex.ts"// A coding agent's summary of a change: headings, a list that starts at 3, a table that scrolls// inside its frame on a phone, code, a quote and a rule.const styles = stylex.create({ frame: { inlineSize: "min(40rem, 100%)", paddingBlock: space.lg } })const summary = `# Retry failed chargesThe billing worker now retries a declined charge **three times** over a day before it marks theinvoice unpaid. Nothing changes for charges that succeed the first time.## What changed1. Read the decline code from the card network.2. Schedule the retry with \`backoff(attempt)\`.3. Email the customer only after the last attempt fails.## Retry schedule| Attempt | Wait | Emails sent | Share recovered || :------ | ---: | :---------: | --------------: || 1 | 1 hour | none | 38% || 2 | 6 hours | none | 21% || 3 | 24 hours | one | 9% |\`\`\`tsexport const backoff = (attempt: number) => [Duration.hours(1), Duration.hours(6), Duration.hours(24)][attempt]\`\`\`> Declines for a closed account aren't retried: the card won't work again.---Tests cover each decline code. See [the runbook](https://example.com/runbooks/billing) for how to replay a day of retries.`export const ChangeSummary = <M>(h: Html.H<M>) => h.div.attrs(sx(styles.frame)).children(Prose(h, summary))Installation
pnpm dlx shadcn@latest add checkfu/uicontext/proseUsage
import { Prose } from "./ui/uicontext/components/kit/Prose.ts"export const Reply = <M>(h: Html.H<M>, markdown: string) => Prose(h, markdown)Examples
Text from a stranger
Raw HTML shows as text, an unsafe link keeps only its words, and a long address wraps.
import type { Html } from "@effect/ui/html"import * as stylex from "@stylexjs/stylex"import { Prose } from "./ui/uicontext/components/kit/Prose.ts"import { sx } from "./ui/uicontext/components/Sx.ts"import { color, radius, space } from "./ui/uicontext/components/tokens.stylex.ts"// What a stranger might paste into a support ticket: raw HTML stays text, a `javascript:` link loses// its target but keeps its words, and a very long address wraps instead of widening the page.const styles = stylex.create({ frame: { inlineSize: "min(28rem, 100%)", padding: space.xl, borderWidth: 1, borderStyle: "solid", borderColor: color.line, borderRadius: radius.lg, },})const ticket = [ "Hi, the export page shows this when I click the button: <img src=x onerror=alert(1)>", "", "I also tried [this workaround](javascript:alert(document.cookie)) from a forum, with no luck.", "", "Our callback is https://northwind-freight.example/integrations/webhooks/exports/completed?account=nw-4471&retry=true&signature=7f3a9c2e8b1d4f6a",].join("\n")export const SupportTicket = <M>(h: Html.H<M>) => h.div.attrs(sx(styles.frame)).children(Prose(h, ticket))An answer in a side panel
Tables and code scroll inside their own boxes, so a narrow panel never scrolls sideways.
Three invoices failed last night, all with the same decline code:
| Invoice | Customer | Amount | Code |
|---|---|---|---|
| INV-2291 | Halcyon Health | $4,120.00 | do_not_honor |
| INV-2294 | Northwind Freight | $860.50 | do_not_honor |
| INV-2302 | Juniper Labs | $1,975.00 | do_not_honor |
The retry job ran once instead of three times.
Each card was charged with the first attempt's key.
Run them again by hand:
billing retry INV-2291 INV-2294 INV-2302import type { Html } from "@effect/ui/html"import * as stylex from "@stylexjs/stylex"import { Prose } from "./ui/uicontext/components/kit/Prose.ts"import { color, radius, space } from "./ui/uicontext/components/tokens.stylex.ts"// An agent's answer in a narrow side panel: a short list, a table that scrolls inside its box// rather than widening the panel, and a command to copy.const styles = stylex.create({ panel: { inlineSize: "min(100%, 22rem)", padding: space.lg, borderRadius: radius.lg, borderWidth: 1, borderStyle: "solid", borderColor: color.line, backgroundColor: color.panel, },})const answer = [ "Three invoices failed last night, all with the same decline code:", "", "| Invoice | Customer | Amount | Code |", "| --- | --- | ---: | --- |", "| INV-2291 | Halcyon Health | $4,120.00 | `do_not_honor` |", "| INV-2294 | Northwind Freight | $860.50 | `do_not_honor` |", "| INV-2302 | Juniper Labs | $1,975.00 | `do_not_honor` |", "", "1. The retry job ran once instead of three times.", "2. Each card was charged with the first attempt's key.", "", "Run them again by hand:", "", "```bash", "billing retry INV-2291 INV-2294 INV-2302", "```",].join("\n")export const AgentAnswer = <M>(h: Html.H<M>) => Prose(h, answer, { style: styles.panel })API reference
Options
| Name | Type | Description |
|---|---|---|
views | Partial<Markdown.Views<Message>> | Views for more Markdown nodes, or in place of Prose's own, merged over them: CitedProse turns [n] markers in Text into chips this way. Everything not replaced keeps Prose's elements and styles. |
plain | (text: string) => View.Content | string | What text the parser doesn't accept shows as, in place of the text itself |
style | Style | Styles laid over Prose's own, such as a larger reading size in a conversation |
Accessibility
- Markdown becomes real paragraphs, headings, lists, quotes and code blocks, so screen readers can move by them.
- Links open in a new tab. Raw HTML and syntax it doesn't know show as plain text, never as markup.