Skip to main content

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.

PatternReadyView source
Works with
Reactshadcn/ui
Runs on sample data, with the neutral theme of shadcn/ui.

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​

The command adds the file to your project, with the shadcn/ui components that it uses. Your project needs shadcn/ui.

pnpm dlx shadcn@latest add https://examples.lumoauth.dev/r/approval-status.json

Usage​

Start the approval on your server, and show the block while the request waits.

app/chat/pending-approval.tsx
'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.

app/api/agent/approval.ts
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 showsCall
Start the requestagent.approvals.require({ taskId, reason, impact, onBehalfOf })
Follow a requestagent.approvals.getStatus(), agent.approvals.wait()
The outcomesLumoAuthApprovalDeniedError, LumoAuthApprovalTimeoutError, LumoAuthApprovalNotDeliveredError
A backchannel requestPOST /oauth/bc-authorize, then the token endpoint

States​

Runs on sample data, with the neutral theme of shadcn/ui.
  • 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​

PropTypeDefaultDescription
statusrequired'pending' | 'approved' | 'denied' | 'expired' | 'not_delivered'The state of the request.
actionrequiredstringThe action in plain words. It is the reason that the agent sent.
approverrequiredstringThe 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.
expiresAtstring | nullWhen the agent stops waiting. The block counts down to it.
respondedAtstring | nullWhen the person answered.
onCancel() => voidLets the person in the conversation stop the request. The button appears while the request waits.
classNamestringClass name for the block.