Capability list
What an agent may do, as a list of capabilities in the resource and action form, with a check for each one.
A readable view of what an agent may do, for a settings page or a review step before a person gives access. Capabilities have the form <resource>:<action>, and the list groups them by resource.
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/capability-list.json
npx shadcn@latest add https://examples.lumoauth.dev/r/capability-list.json
yarn dlx shadcn@latest add https://examples.lumoauth.dev/r/capability-list.json
bunx --bun shadcn@latest add https://examples.lumoauth.dev/r/capability-list.json
Add the shadcn/ui components that the pattern uses.
npx shadcn@latest add badge inputInstall the packages.
npm install lucide-reactCopy the code into your project.
components/capability-list.tsx'use client';import * as React from 'react';import { Asterisk, Ban, Check, Hand, Search } from 'lucide-react';import { Badge } from '@/components/ui/badge';import { Input } from '@/components/ui/input';import { cn } from '@/lib/utils';export interface CapabilityListProps {/*** The capabilities of the agent, in the form `<resource>:<action>`:* `invoices:read`, `invoices:*`, or `*` for everything.* This is the list that `agent.capabilities()` returns.*/capabilities: string[];/** Capabilities that need the approval of a person at the time of use. */needsApproval?: string[];/** Capabilities that a deny rule overrides: the agent holds them and cannot use them. */denied?: string[];/** Show the search field. By default it appears above 12 capabilities. */searchable?: boolean;className?: string;}function split(capability: string) {const at = capability.indexOf(':');return at === -1 ? { resource: capability, action: '' } : { resource: capability.slice(0, at), action: capability.slice(at + 1) };}function describe(resource: string, action: string) {if (resource === '*') return 'Everything, on every resource';if (action === '*') return `Every action on ${resource}`;return null;}export function CapabilityList({ capabilities, needsApproval = [], denied = [], searchable, className }: CapabilityListProps) {const [query, setQuery] = React.useState('');const showSearch = searchable ?? capabilities.length > 12;const q = query.trim().toLowerCase();const groups = React.useMemo(() => {const map = new Map<string, string[]>();for (const capability of [...capabilities].sort()) {if (q && !capability.toLowerCase().includes(q)) continue;const { resource } = split(capability);map.set(resource, [...(map.get(resource) ?? []), capability]);}return [...map.entries()];}, [capabilities, q]);if (capabilities.length === 0) {return (<div className={cn('w-full max-w-md rounded-lg border border-dashed p-6 text-center text-sm', className)}><p className="font-medium">No capabilities</p><p className="text-muted-foreground">This agent can prove who it is and can do nothing else.</p></div>);}return (<div className={cn('grid w-full max-w-md gap-3 text-sm', className)}>{showSearch && (<div className="relative"><Search className="pointer-events-none absolute top-2.5 left-2.5 size-4 text-muted-foreground" aria-hidden="true" /><Inputvalue={query}onChange={(event) => setQuery(event.target.value)}placeholder="Find a capability"aria-label="Find a capability"className="pl-8"/></div>)}{groups.length === 0 && <p className="text-muted-foreground">No capability matches “{query}”.</p>}{groups.map(([resource, items]) => (<section key={resource} className="rounded-lg border bg-card text-card-foreground"><h3 className="flex items-center justify-between border-b px-3 py-2 font-medium"><span className="font-mono text-[0.8125rem]">{resource === '*' ? 'all resources' : resource}</span><span className="text-xs font-normal text-muted-foreground tabular-nums">{items.length}</span></h3><ul>{items.map((capability) => {const { action } = split(capability);const isDenied = denied.includes(capability);const asks = needsApproval.includes(capability);const wide = describe(resource, action);return (<li key={capability} className="flex items-center gap-2 border-b px-3 py-2 last:border-b-0">{isDenied ? (<Ban className="size-4 shrink-0 text-red-600 dark:text-red-400" aria-hidden="true" />) : wide ? (<Asterisk className="size-4 shrink-0 text-amber-600 dark:text-amber-400" aria-hidden="true" />) : (<Check className="size-4 shrink-0 text-emerald-600 dark:text-emerald-400" aria-hidden="true" />)}<div className="min-w-0 flex-1"><code className={cn('font-mono text-[0.8125rem]', isDenied && 'text-muted-foreground line-through')}>{capability}</code>{wide && <p className="text-xs text-muted-foreground">{wide}</p>}{isDenied && <p className="text-xs text-red-700 dark:text-red-400">A deny rule overrides this capability.</p>}</div>{asks && !isDenied && (<Badge variant="outline" className="gap-1"><Hand aria-hidden="true" />Asks first</Badge>)}</li>);})}</ul></section>))}</div>);}Change the import paths if your project keeps its components in another place.
Usage
Pass the list that agent.capabilities() returns.
import { CapabilityList } from '@/components/capability-list';
export function Capabilities({ capabilities }: { capabilities: string[] }) {
return (
<CapabilityList
capabilities={capabilities}
needsApproval={['invoices:refund']}
denied={[]}
/>
);
}
needsApproval and denied are yours to fill in: they come from the rules of your own app or from your policies. LumoAuth returns the capabilities only.
Where the data comes from
| What the pattern shows | Call |
|---|---|
| The capabilities of an agent | agent.capabilities() |
| Whether one action is allowed now | agent.isAllowed(action) |
| Capabilities that a token carries | The scopes of the verified access token |
States
- No capabilities.
- Everything: the capability
*. - A long list, with the search field. It appears above 12 capabilities.
- A wildcard such as
tickets:*is marked and explained in words.
Props
| Prop | Type | Description |
|---|---|---|
capabilitiesrequired | string[] | The capabilities of the agent, for example invoices:read, invoices:* or *. |
needsApproval | string[] | Capabilities that need the approval of a person at the time of use. |
denied | string[] | Capabilities that a deny rule overrides. The agent holds them and cannot use them. |
searchable | boolean | Show the search field. By default it appears above 12 capabilities. |
className | string | Class name for the list. |