Chat Confirmation
Asks someone in chat to approve or decline an action an agent proposed. It is a Review Card with a shield icon, a status badge, the facts as rows, and two buttons. Once decided it folds and shows the outcome.
Installation
pnpm dlx shadcn@latest add https://sprout.tulipfarm.ai/r/chat-confirmation.jsonCopies Chat Confirmation and the components it uses (Button, Review Card, and Spinner) into your app, installs the packages, and adds the styles. Then import it from @/components/ui/chat-confirmation. Needs Tailwind CSS 4 and a components.json from shadcn init.
Install the following dependencies:
pnpm add clsx tailwind-merge @hugeicons/core-free-icons @hugeicons/reactAdd Sprout base once per app: the
cn()helper and the design tokens.lib/sprout/classes.ts- Design tokens, for your global CSS
Add the components it uses: Button, Review Card, and Spinner.
Copy and paste the following code into your project.
'use client'; import { useEffect, useRef, type ComponentProps, type ReactNode } from 'react'; import { ShieldUserIcon } from '@/lib/sprout/icons/shield-user-icon'; import { cn } from '@/lib/sprout/classes'; import { Button } from '@/components/ui/button'; import { ReviewCard, ReviewRow, ReviewRows, type ReviewCardBadge } from '@/components/ui/review-card'; import { Spinner } from '@/components/ui/spinner'; export const chatConfirmationStateNames = [ 'pending', 'submitting', 'approved', 'rejected', 'expired', 'cancelled', 'error', ] as const; export type ChatConfirmationDecision = 'approve' | 'reject'; export type ConfirmationState = | { kind: 'pending' } | { kind: 'submitting'; decision: ChatConfirmationDecision } | { kind: 'approved' } | { kind: 'rejected' } | { kind: 'expired' } | { kind: 'cancelled' } | { kind: 'error'; message: string }; export type ChatConfirmationDetail = { label: string; value: string }; export interface ChatConfirmationProps extends Omit<ComponentProps<'div'>, 'title' | 'children'> { title: string; description: string; details: readonly ChatConfirmationDetail[]; state: ConfirmationState; onDecision: (decision: ChatConfirmationDecision) => void; disabled?: boolean | undefined; approveLabel?: ReactNode; } const settledKinds = new Set<ConfirmationState['kind']>(['approved', 'rejected', 'expired', 'cancelled']); const badges: Record<ConfirmationState['kind'], ReviewCardBadge> = { pending: { label: 'Approval required', variant: 'warning' }, submitting: { label: 'Approval required', variant: 'warning' }, error: { label: 'Approval required', variant: 'warning' }, approved: { label: 'Approved', variant: 'info' }, rejected: { label: 'Declined', variant: 'secondary' }, expired: { label: 'Expired', variant: 'secondary' }, cancelled: { label: 'Cancelled', variant: 'secondary' }, }; const outcomes: Partial<Record<ConfirmationState['kind'], string>> = { approved: 'Approval recorded. This does not confirm the action has completed.', rejected: 'The proposed action was declined.', expired: 'This approval expired. No approval was granted.', cancelled: 'This approval was cancelled. No approval was granted.', }; export function ChatConfirmation({ title, description, details, state, onDecision, disabled = false, approveLabel = 'Approve action', className, ...props }: ChatConfirmationProps) { const done = settledKinds.has(state.kind); const section = useRef<HTMLDivElement>(null); const result = useRef<HTMLParagraphElement>(null); const submittedHere = useRef(false); useEffect(() => { if (state.kind === 'submitting') submittedHere.current = section.current?.contains(document.activeElement) ?? false; if (done && submittedHere.current) { result.current?.focus(); submittedHere.current = false; } }, [done, state.kind]); const submitting = state.kind === 'submitting'; const busy = (decision: ChatConfirmationDecision) => state.kind === 'submitting' && state.decision === decision; const outcome = outcomes[state.kind]; return ( <div ref={section} data-slot="chat-confirmation" data-state={state.kind} {...props} className={cn('sprout-chat-confirmation', className)} > <ReviewCard icon={<ShieldUserIcon size="md" />} title={title} badge={badges[state.kind]} settled={done} status={ state.kind === 'error' || outcome ? ( <> {state.kind === 'error' && ( <p role="alert" className="sprout-chat-confirmation-error"> {state.message} </p> )} {outcome && ( <p ref={result} tabIndex={-1} role="status" className="sprout-chat-confirmation-result"> {outcome} </p> )} </> ) : undefined } actions={ done ? undefined : ( <> <Button disabled={disabled || submitting} aria-busy={busy('approve')} onClick={() => onDecision('approve')} > {busy('approve') && <Spinner aria-hidden="true" />} {approveLabel} </Button> <Button variant="ghost" disabled={disabled || submitting} aria-busy={busy('reject')} onClick={() => onDecision('reject')} > {busy('reject') && <Spinner aria-hidden="true" />} Decline </Button> </> ) } > <p className="sprout-chat-confirmation-description">{description}</p> <ReviewRows> {details.map(detail => ( <ReviewRow key={detail.label} label={detail.label}> {detail.value} </ReviewRow> ))} </ReviewRows> </ReviewCard> </div> ); }And the files it imports:
lib/sprout/icons/create-icon.tsxlib/sprout/icons/shield-user-icon.tsx
Add the styles to your global CSS, after
@import "tailwindcss".@layer components { .sprout-chat-confirmation { width: 100%; min-width: 0; } .sprout-chat-confirmation-description, .sprout-chat-confirmation-result { color: var(--sprout-muted); font-size: var(--sprout-text-sm); overflow-wrap: anywhere; margin: 0; line-height: 1.25rem; } .sprout-chat-confirmation-error { color: var(--sprout-danger); font-size: var(--sprout-text-sm); overflow-wrap: anywhere; margin: 0; line-height: 1.25rem; } .sprout-chat-confirmation-result { border-radius: var(--sprout-radius-control); outline: none; } .sprout-chat-confirmation-result:focus-visible { outline: var(--sprout-focus-width) solid var(--sprout-focus-ring); outline-offset: 0; } }Import it from
@/components/ui/chat-confirmation. Update the paths if your@/alias points elsewhere.
pnpm add @tulipfarm/sprout@import "tailwindcss";
@import "@tulipfarm/sprout/styles.css";The package keeps the source and ships fixes with each release. Import from @tulipfarm/sprout/chat-confirmation.
Review these changes before approving.
- Action
- Change table schema
- Table
- tbl_7d1c4e2a9b
- Proposal
- mig_3f8a21c6d0
- Plan digest
- sha256:9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08
- Applied revision
- 42
- Effect
- Remove field values
- Affected rows
- 128
- Field
- fld_notes_91ce
Usage
import {
ChatConfirmation,
type ConfirmationState,
} from "@tulipfarm/sprout/chat-confirmation";
const [state, setState] = useState<ConfirmationState>({ kind: "pending" });
<ChatConfirmation
title="Remove the Notes field from Supplier deliveries"
description="Review these changes before approving."
details={[
{ label: "Action", value: "Change table schema" },
{ label: "Effect", value: "Remove field values" },
{ label: "Affected rows", value: "128" },
]}
state={state}
disabled={!canVerifyEffect}
onDecision={async (decision) => {
setState({ kind: "submitting", decision });
setState(await save(decision));
}}
/>title: what the agent wants to do. Long titles end with an ellipsis.description: one line above the facts.details:{ label, value }[], shown in order. Long values wrap.state:pending,{ kind: "submitting", decision },approved,rejected,expired,cancelled, or{ kind: "error", message }.onDecision: called with"approve"or"reject".disabled: locks both buttons, such as while the request is refreshing or its effect cannot be verified.approveLabel: names the action on the approve button, such as “Approve 3 drafts”. Defaults to “Approve action”.
States
Pending, submitting, and error show Approval requiredwith both buttons. While submitting, both are disabled and the chosen one shows a spinner. An error shows above the buttons so people can try again. Approved, declined, expired, and cancelled fold the card and show the outcome.
Review these changes before approving.
- Action
- Change table schema
- Table
- tbl_7d1c4e2a9b
- Effect
- Remove field values
- Affected rows
- 128
- Field
- fld_notes_91ce
Review these changes before approving.
- Action
- Change table schema
- Effect
- Convert field values
- Affected rows
- 1204
- Field
- fld_delivery_date_4a
Review these changes before approving.
- Action
- Change table schema
- Effect
- Remove table rows
- Affected rows
- 37
Ask for permission before the sample action.
- Recipient
- [email protected]
- Message
- Please water the garden.
Table approval in chat
A schema change with its request status below: details, a status check, and an alert when the refresh failed. The buttons lock while the request needs a check and when the effect cannot be verified.
Review these changes before approving.
- Action
- Change table schema
- Table
- tbl_7d1c4e2a9b
- Proposal
- mig_3f8a21c6d0
- Plan digest
- sha256:9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08
- Applied revision
- 42
- Effect
- Remove field values
- Affected rows
- 128
- Field
- fld_notes_91ce
Settle without submitting
A decision can settle at once. Pick any state from the menu. This one names its action with approveLabel="Send reminder".
Ask for permission before the sample action.
- Recipient
- [email protected]
- Message
- Please water the garden.
Accessibility
The card is a section named by the title, which is anh4 button that opens and closes the details. A busy button hasaria-busy and its spinner is hidden. Errors userole="alert"; the outcome uses role="status". If the decision was made from inside the card, focus moves to the outcome when it settles, so keyboard users keep their place.
The details grow and shrink in 180ms; with reduced motion they change at once.
Theme tokens
Text uses --sprout-muted, errors--sprout-danger, and the outcome focus ring--sprout-focus. The card, badge, and buttons use their own tokens.