Asks a person to allow an action before an agent takes it.
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 { sx } from "./ui/uicontext/components/Sx.ts"const styles = stylex.create({ frame: { inlineSize: "min(100%, 30rem)" },})const me: Actor = { id: "ada", name: "Ada Lovelace", kind: "person" }const Message = UiSchema.TaggedEnum({ ChoseRefund: { choice: Schema.String } })export const RefundApproval = Html.component({ name: "RefundApproval", model: Schema.Struct({ choice: Schema.NullOr(Schema.String) }), message: Message,}).make({ init: () => ({ choice: null }), update: { ChoseRefund: ($, { choice }) => $.evolve({ choice }) }, view: (h, { choice }) => h.div.attrs(sx(styles.frame)).children( Approval(h, { props: { id: "refund-4471", title: "Refund order #4471 to the customer's card", tool: "payments.refund", fields: [ { label: "Customer", value: "Grace Hopper" }, { label: "Amount", value: "$129.00" }, { label: "Reason", value: "Arrived damaged. Photo attached to the ticket.", kind: "long" }, ], digest: "refund:4471:12900", actor: { id: "scout", name: "Scout", kind: "agent" }, choices: [ // with the card focused, Escape denies and ⌘↵ refunds { id: "deny", label: "Deny", dismiss: true }, { id: "allow", label: "Refund", primary: true }, ], can: ["answer"], timeZone: "UTC", expires: "Expires in 30 minutes", state: choice === null ? { _tag: "Pending" } : { _tag: "Answered", choice, actor: me, at: "2026-12-01T09:45:00Z" }, }, onEmit: { Chose: ({ choice }) => Message.ChoseRefund({ choice }) }, }), ),})Installation
pnpm dlx shadcn@latest add checkfu/uicontext/approvalUsage
import type { ApprovalState } from "./ui/uicontext/components/kit/Approval.ts"import { Approval } from "./ui/uicontext/components/kit/Approval.ts"const Message = UiSchema.TaggedEnum({ AnsweredApproval: { choice: Schema.String } })export const DeployApproval = (h: Html.H<typeof Message.Type>, state: typeof ApprovalState.Type) => Approval(h, { props: { id: "deploy-218", title: "Deploy build 218 to production", fields: [{ label: "Service", value: "billing-api" }], digest: "deploy:billing-api:218", actor: { id: "scout", name: "Scout", kind: "agent" }, choices: [ { id: "deny", label: "Deny", dismiss: true }, { id: "allow", label: "Deploy", primary: true }, ], can: ["answer"], // your app keeps the state: Pending, then Answered once it records the choice state, }, onEmit: { Chose: ({ choice }) => Message.AnsweredApproval({ choice }) }, })Examples
Answered, expired and read-only
The card after it's decided, when it timed out, when the run ended first, and for someone who may not answer.
import type { Html } from "@effect/ui/html"import * as stylex from "@stylexjs/stylex"import type { Actor } from "./ui/uicontext/components/domain/Actor.ts"import type { ApprovalState } from "./ui/uicontext/components/kit/Approval.ts"import { Approval } from "./ui/uicontext/components/kit/Approval.ts"import { sx } from "./ui/uicontext/components/Sx.ts"const styles = stylex.create({ stack: { display: "grid", gap: 16, inlineSize: "min(100%, 30rem)" },})const scout: Actor = { id: "scout", name: "Scout", kind: "agent" }const grace: Actor = { id: "grace", name: "Grace Hopper", kind: "person" }const choices = [ { id: "deny", label: "Deny", answered: "Denied", dismiss: true }, { id: "allow", label: "Approve", answered: "Approved", primary: true },]const card = <M>( h: Html.H<M>, id: string, title: string, value: string, state: typeof ApprovalState.Type, options: { readonly can?: ReadonlyArray<"answer">; readonly whoMayAnswer?: string } = {},) => Approval(h, { key: id, props: { id, title, fields: [{ label: "Change", value }], digest: `${id}:v1`, actor: scout, choices, can: options.can ?? ["answer"], ...(options.whoMayAnswer === undefined ? {} : { whoMayAnswer: options.whoMayAnswer }), timeZone: "UTC", state, }, onEmit: { Chose: () => undefined }, })// Each state the app can hand back: answered, expired, ended another way, and one this reader can't answerexport const ApprovalOutcomes = <M>(h: Html.H<M>) => h.div.attrs(sx(styles.stack)).children( card(h, "invite-31", "Invite two contractors to the Design workspace", "[email protected], [email protected]", { _tag: "Answered", choice: "allow", actor: grace, at: "2026-12-01T08:12:00Z", }), card(h, "close-88", "Close 14 stale issues in the Mobile project", "Issues untouched for 90 days", { _tag: "Expired" }), card(h, "rotate-7", "Rotate the webhook signing secret", "Webhook: invoices.paid", { _tag: "Retired", reason: "Stopped: the run was cancelled" }), card(h, "budget-3", "Raise the monthly model budget to $400", "From $250 to $400", { _tag: "Pending" }, { can: [], whoMayAnswer: "Only workspace owners can answer this.", }), )API reference
Props
| Name | Type | Default | Description |
|---|---|---|---|
idrequired | string | — | Identifies the request, for agents and for the outcome |
titlerequired | string | — | What will happen, as a sentence: "Send this email to [email protected]" |
fieldsrequired | ApprovalField[] | — | The exact action: where, to whom, with what content |
digestrequired | string | — | Identifies this exact action (operation, target, payload); an answer applies only to it |
actorrequired | Actor | — | Who asked: the agent (or person) that wants to take the action |
tool | string | — | The tool it would call, shown small under the title: "issues.update" |
choicesrequired | ApprovalChoice[] | — | The answers to offer, such as Allow once and Deny; one may be primary |
canrequired | Can(["answer"]) | — | "answer" when this person may answer; without it, whoMayAnswer says who can |
whoMayAnswer | string | — | Shown to people who can't answer: "Only workspace admins can approve this." |
expires | string | — | Already formatted: "Expires in 30 minutes" |
staterequired | ApprovalState | — | Whether the request is pending, answered (with the choice and who made it), expired or retired |
mac | boolean | true | ⌘ on a Mac, Ctrl elsewhere, for the keycaps; true by default |
locale | string | — | Formats the answer's ISO time; the reader's own when left out |
timeZone | string | — | The time zone for the answer's time; the reader's own when left out |
outcome | Outcome | null | — | The app's answer to Chose, by this approval's id. Pending holds the buttons while the answer travels; Refused shows the reason and lets the person answer again. Accepted needs nothing: pass the new state. |
Events
| Event | Payload | Description |
|---|---|---|
Chose | { choice: string } | The person picked one of choices, by its id |
Agent actions
| Action | Description |
|---|---|
ClickedChoiceasks first | Answer the approval with one of its choices (see page_query) |
Accessibility
- The exact action shows before the choices, so the person reads what they're allowing.
- An answer applies only to the action named by
digest: an agent can't answer a different action than the one it read. - After an answer the card says who answered and when, and its buttons go away.