Command Palette

Search for a command to run...

Subagent

shadcn/ui

Displays a delegated subagent execution run with nested tool calls and final result.

Subagent
search_filesMatched 14 files in components/opticsread_fileInspected trace.tsx and badge.tsxverify_exportsAll 5 exported symbols verified
Verified trace primitives, collapsible state, and exported TypeScript types.

import { RotateCcwIcon } from "lucide-react";import { useEffect, useRef, useState } from "react";import {	Subagent,	SubagentContent,	SubagentHeader,	SubagentResult,	type SubagentStatus,	SubagentToolCall,} from "@/components/optics/ai-elements/subagent";import { Button } from "@/components/optics/button";const STATUS_OPTIONS: { value: SubagentStatus; label: string }[] = [	{ value: "running", label: "Running" },	{ value: "completed", label: "Completed" },	{ value: "error", label: "Error" },];function SubagentDemo() {	const [status, setStatus] = useState<SubagentStatus>("completed");	const timerRef = useRef<ReturnType<typeof setTimeout> | null>(null);	useEffect(() => {		return () => {			if (timerRef.current !== null) {				clearTimeout(timerRef.current);			}		};	}, []);	function clearReplayTimer() {		if (timerRef.current !== null) {			clearTimeout(timerRef.current);			timerRef.current = null;		}	}	function handleSelectStatus(nextStatus: SubagentStatus) {		clearReplayTimer();		setStatus(nextStatus);	}	function handleReplay() {		clearReplayTimer();		setStatus("running");		timerRef.current = setTimeout(() => {			setStatus("completed");			timerRef.current = null;		}, 1200);	}	return (		<div className="flex w-full max-w-lg flex-col gap-3">			<div className="flex flex-wrap items-center justify-between gap-2">				<div className="flex flex-wrap items-center gap-1.5">					{STATUS_OPTIONS.map((option) => (						<Button							key={option.value}							type="button"							size="xs"							variant={status === option.value ? "default" : "outline"}							onClick={() => handleSelectStatus(option.value)}						>							{option.label}						</Button>					))}				</div>				<Button type="button" size="xs" variant="outline" onClick={handleReplay}>					<RotateCcwIcon />					Replay				</Button>			</div>			<div className="rounded-xl border bg-background p-4">				<Subagent defaultOpen>					<SubagentHeader name="Codebase Researcher" role="Explore" status={status} />					<SubagentContent>						<SubagentToolCall							name="search_files"							status="completed"							summary="Matched 14 files in components/optics"						/>						<SubagentToolCall							name="read_file"							status="completed"							summary="Inspected trace.tsx and badge.tsx"						/>						<SubagentToolCall							name="verify_exports"							status={status}							summary={								status === "running"									? "Checking barrel exports and prop types..."									: status === "error"										? "Type mismatch in SubagentResult props"										: "All 5 exported symbols verified"							}						/>						<SubagentResult							className={								status === "error"									? "text-destructive"									: status === "running"										? "text-muted-foreground"										: "text-foreground"							}						>							{status === "running"								? "Streaming tool results from subagent..."								: status === "error"									? "Subagent stopped with 1 error while verifying component exports."									: "Verified trace primitives, collapsible state, and exported TypeScript types."}						</SubagentResult>					</SubagentContent>				</Subagent>			</div>		</div>	);}<SubagentDemo />

Installation

pnpm dlx shadcn@latest add @optics/ai-subagent

Props

<Subagent />
Name
Type
defaultOpen
boolean(default: false)
open
boolean
onOpenChange
((open: boolean) => void)

<SubagentHeader />
Name
Type
render
React.ReactElement
nativeButton
boolean
<SubagentContent />
Name
Type
render
React.ReactElement
hiddenUntilFound
boolean
keepMounted
boolean
forceMount
boolean
<SubagentToolCall />
Name
Type
status
string(default: completed)
summary
string