Skip to main content

Kill switch

A control that suspends an agent at once, with a confirmation that says what stops.

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

The control that an administrator reaches for when an agent misbehaves. It is easy to find and hard to press by accident: the person types the name of the agent to confirm. Try it in the preview.

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/kill-switch.json

Usage​

Give the control the agent and two callbacks.

app/agents/[id]/kill-switch.tsx
'use client';

import { KillSwitch, type KillSwitchAgent } from '@/components/kill-switch';

export function AgentControl({ agent, canManage }: { agent: KillSwitchAgent; canManage: boolean }) {
const post = (action: 'suspend' | 'resume') => async (id: string) => {
await fetch(`/api/agents/${id}/${action}`, { method: 'POST' });
};
return <KillSwitch agent={agent} canManage={canManage} onSuspend={post('suspend')} onResume={post('resume')} />;
}

Your API route changes the state of the agent through the Admin API, with a credential that may manage agents. Check the permission of the person in that route too: canManage only hides the button.

Where the data comes from​

What the pattern showsCall
Suspend, resume and revokeAdmin API, agents
Tell your services at onceThe webhook agent.revoked, or a session-revoked security event
Whether the person may suspendA permission check for the signed-in person

States​

Runs on sample data, with the neutral theme of shadcn/ui.
  • Suspended, with who did it and when, and a button to resume.
  • Revoked. It cannot be resumed.
  • No permission. The person sees the state and no button.

Props​

PropTypeDefaultDescription
agentrequiredKillSwitchAgentThe agent: id, name, status, and suspendedBy and suspendedAt for a suspended agent.
onSuspend(id: string) => void | Promise<void>Called after the person confirmed.
onResume(id: string) => void | Promise<void>Called for a suspended agent.
canManagebooleantrueFalse when the person lacks the permission to suspend agents.
stopsstring[]What stops when the agent is suspended. The confirmation lists it.
classNamestringClass name for the card.