Approval status in a conversation
The message that a chat shows while an agent waits for a person: where the request went, and what happened.
An inline block for a chat or a task log. It replaces a spinner with the facts: who was asked, where, and how long the agent will wait. The preview answers by itself after a few seconds.
Installation
- CLI
- Manual
The command adds the file to your project, with the shadcn/ui components that it uses. Your project needs shadcn/ui.
- pnpm
- npm
- yarn
- bun
pnpm dlx shadcn@latest add https://examples.lumoauth.dev/r/approval-status.json
npx shadcn@latest add https://examples.lumoauth.dev/r/approval-status.json
yarn dlx shadcn@latest add https://examples.lumoauth.dev/r/approval-status.json
bunx --bun shadcn@latest add https://examples.lumoauth.dev/r/approval-status.json
Add the shadcn/ui components that the pattern uses.
npx shadcn@latest add badge buttonInstall the packages.
npm install lucide-reactCopy the code into your project.
components/approval-status.tsx'use client';import * as React from 'react';import { BellOff, Check, Clock, Hourglass, Mail, MessageSquare, Smartphone, X } from 'lucide-react';import { Badge } from '@/components/ui/badge';import { Button } from '@/components/ui/button';import { cn } from '@/lib/utils';export type ApprovalStatusValue = 'pending' | 'approved' | 'denied' | 'expired' | 'not_delivered';export type ApprovalChannel = 'phone' | 'chat' | 'portal' | 'email';export interface ApprovalStatusProps {status: ApprovalStatusValue;/** The action in plain words. The agent sent it as `reason`. */action: string;/** The person who was asked. */approver: string;/** Where the request went. */channel?: ApprovalChannel;impact?: 'low' | 'medium' | 'high' | 'critical' | null;/** When the agent stops waiting (ISO 8601). */expiresAt?: string | null;/** When the person answered. */respondedAt?: string | null;/** Lets the person in the conversation stop the request. */onCancel?: () => void;className?: string;}/*** Maps the result of `approvals.wait()` or `approvals.getStatus()` to the* status of the block. Catch `LumoAuthApprovalNotDeliveredError` yourself* and pass `not_delivered`.*/export function fromApprovalResult(result: {status: 'approved' | 'denied' | 'expired' | 'pending';respondedAt: string | null;approvedBy: { email: string | null } | null;}): Pick<ApprovalStatusProps, 'status' | 'respondedAt'> & { approvedBy: string | null } {return { status: result.status, respondedAt: result.respondedAt, approvedBy: result.approvedBy?.email ?? null };}const CHANNEL = {phone: { icon: Smartphone, where: 'on their phone' },chat: { icon: MessageSquare, where: 'in the approvals channel' },portal: { icon: Hourglass, where: 'in the approvals inbox' },email: { icon: Mail, where: 'by email' },} as const;/*** The current time, or null on the server and in the first render. Reading* the clock during render breaks prerendering and hydration, so it is read* in an effect.*/function useNow(active = true) {const [now, setNow] = React.useState<number | null>(null);React.useEffect(() => {if (!active) return;setNow(Date.now());const timer = setInterval(() => setNow(Date.now()), 1000);return () => clearInterval(timer);}, [active]);return now;}function useCountdown(expiresAt: string | null | undefined, active: boolean) {const now = useNow(active && Boolean(expiresAt));if (!expiresAt || now === null) return null;const left = Math.max(0, Math.floor((new Date(expiresAt).getTime() - now) / 1000));return `${Math.floor(left / 60)}:${String(left % 60).padStart(2, '0')}`;}export function ApprovalStatus({status,action,approver,channel = 'phone',impact,expiresAt,respondedAt,onCancel,className,}: ApprovalStatusProps) {const countdown = useCountdown(expiresAt, status === 'pending');const { icon: ChannelIcon, where } = CHANNEL[channel];const time = respondedAt ? new Date(respondedAt).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' }) : null;const view = {pending: { icon: ChannelIcon, tone: 'text-foreground', title: `Waiting for ${approver}`, text: `The request is ${where}. Nothing happens until they answer.` },approved: { icon: Check, tone: 'text-emerald-700 dark:text-emerald-400', title: `Approved by ${approver}`, text: time ? `At ${time}. The agent continues.` : 'The agent continues.' },denied: { icon: X, tone: 'text-red-700 dark:text-red-400', title: `Denied by ${approver}`, text: 'The agent did not perform the action.' },expired: { icon: Clock, tone: 'text-muted-foreground', title: 'No answer in time', text: `${approver} did not answer. The agent did not perform the action.` },not_delivered: { icon: BellOff, tone: 'text-amber-700 dark:text-amber-400', title: 'The request could not be delivered', text: `${approver} has no device that can receive it. Ask them to add the phone app, or use another way to approve.` },}[status];const Icon = view.icon;return (<divrole="status"aria-live="polite"className={cn('flex w-full max-w-lg gap-3 rounded-lg border bg-card p-3 text-sm text-card-foreground', className)}><span className={cn('mt-0.5 flex size-7 shrink-0 items-center justify-center rounded-full bg-muted', view.tone)}><Icon className={cn('size-4', status === 'pending' && 'animate-pulse')} aria-hidden="true" /></span><div className="grid min-w-0 flex-1 gap-1"><div className="flex flex-wrap items-center gap-x-2 gap-y-1"><span className={cn('font-medium', view.tone)}>{view.title}</span>{impact && <Badge variant="outline" className="capitalize">{impact} impact</Badge>}{status === 'pending' && countdown && (<span className="ml-auto text-xs text-muted-foreground tabular-nums">{countdown}</span>)}</div><p className="font-medium">{action}</p><p className="text-muted-foreground" suppressHydrationWarning>{view.text}</p>{status === 'pending' && onCancel && (<div><Button variant="ghost" size="sm" className="-ml-3 h-7" onClick={onCancel}>Cancel the request</Button></div>)}</div></div>);}Change the import paths if your project keeps its components in another place.
Usage
Start the approval on your server, and show the block while the request waits.
'use client';
import { ApprovalStatus, type ApprovalStatusValue } from '@/components/approval-status';
export function PendingApproval({ approval }: {
approval: { status: ApprovalStatusValue; action: string; approver: string; expiresAt: string | null; respondedAt: string | null };
}) {
return (
<ApprovalStatus
status={approval.status}
action={approval.action}
approver={approval.approver}
channel="phone"
impact="high"
expiresAt={approval.expiresAt}
respondedAt={approval.respondedAt}
/>
);
}
On the server, the agent asks and waits. The three errors of the SDK map to three states of the block.
import { LumoAgent, LumoAuthApprovalDeniedError, LumoAuthApprovalNotDeliveredError, LumoAuthApprovalTimeoutError } from '@lumoauth/agent';
const agent = new LumoAgent();
export async function askForApproval(taskId: string, action: string, onBehalfOf: string) {
try {
await agent.approvals.require({ taskId, reason: action, impact: 'high', onBehalfOf });
return 'approved';
} catch (error) {
if (error instanceof LumoAuthApprovalDeniedError) return 'denied';
if (error instanceof LumoAuthApprovalTimeoutError) return 'expired';
if (error instanceof LumoAuthApprovalNotDeliveredError) return 'not_delivered';
throw error;
}
}
Where the data comes from
| What the pattern shows | Call |
|---|---|
| Start the request | agent.approvals.require({ taskId, reason, impact, onBehalfOf }) |
| Follow a request | agent.approvals.getStatus(), agent.approvals.wait() |
| The outcomes | LumoAuthApprovalDeniedError, LumoAuthApprovalTimeoutError, LumoAuthApprovalNotDeliveredError |
| A backchannel request | POST /oauth/bc-authorize, then the token endpoint |
States
- Waiting, with the place: the phone, the approvals channel, the inbox or email.
- Approved. The conversation continues.
- Denied. The agent did not act.
- No answer in time.
- Not delivered. The approver has no device that can receive the request.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
statusrequired | 'pending' | 'approved' | 'denied' | 'expired' | 'not_delivered' | The state of the request. | |
actionrequired | string | The action in plain words. It is the reason that the agent sent. | |
approverrequired | string | The person who was asked. | |
channel | 'phone' | 'chat' | 'portal' | 'email' | 'phone' | Where the request went. |
impact | 'low' | 'medium' | 'high' | 'critical' | The impact level of the action. | |
expiresAt | string | null | When the agent stops waiting. The block counts down to it. | |
respondedAt | string | null | When the person answered. | |
onCancel | () => void | Lets the person in the conversation stop the request. The button appears while the request waits. | |
className | string | Class name for the block. |