subagent-tool
agent-elements/subagent-toolFreeComponent
agent-elements publishes no description for this item.
Live preview
live · rendered by the registry
Rendered by agent-elements on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://agent-elements.21st.dev/r/subagent-tool.jsonSource
1import { memo, useEffect, useState } from "react";2import { toolRegistry } from "./tool-registry";3import { GenericTool } from "./generic-tool";4import { getToolStatus } from "../utils/format-tool";5import { cn } from "../utils/cn";6import { ToolRowBase } from "./tool-row-base";78export type SubagentToolProps = {9 part: any;10 nestedTools?: any[];11 chatStatus?: string;12};1314const MAX_VISIBLE_TOOLS = 5;1516function formatElapsedTime(ms: number): string {17 if (ms < 1000) return "";18 const seconds = Math.floor(ms / 1000);19 if (seconds < 60) return `${seconds}s`;20 const minutes = Math.floor(seconds / 60);21 const remainingSeconds = seconds % 60;22 if (remainingSeconds === 0) return `${minutes}m`;23 return `${minutes}m ${remainingSeconds}s`;24}2526export const SubagentTool = memo(function SubagentTool({27 part,28 nestedTools = [],29 chatStatus,30}: SubagentToolProps) {31 const { isPending, isInterrupted } = getToolStatus(part, chatStatus);32 const description = part.input?.description || "";33 const [elapsedMs, setElapsedMs] = useState(0);34 const startedAt =35 (part.callProviderMetadata?.custom?.startedAt as number | undefined) ??36 (part.startedAt as number | undefined);37 const hasNestedTools = nestedTools.length > 0;38 const outputDuration =39 part.output?.totalDurationMs ||40 part.output?.duration ||41 part.output?.duration_ms;4243 useEffect(() => {44 if (isPending && startedAt) {45 setElapsedMs(Date.now() - startedAt);46 const interval = setInterval(() => {47 setElapsedMs(Date.now() - startedAt);48 }, 1000);49 return () => clearInterval(interval);50 }51 }, [isPending, startedAt]);5253 const subtitle = (() => {54 if (isPending && hasNestedTools) {55 const lastTool = nestedTools[nestedTools.length - 1];56 const meta = lastTool ? toolRegistry[lastTool.type] : null;57 if (meta) {58 const title = meta.title(lastTool);59 const subtitle = meta.subtitle?.(lastTool);60 return subtitle ? `${title} ${subtitle}` : title;61 }62 }6364 if (!description) return "";65 return description.length > 6066 ? `${description.slice(0, 57)}...`67 : description;68 })();69 const elapsedTimeDisplay = formatElapsedTime(70 !isPending && outputDuration ? outputDuration : elapsedMs,71 );7273 if (isInterrupted && !part.output) {74 return (75 <ToolRowBase completeLabel="Subagent interrupted" isAnimating={false} />76 );77 }7879 return (80 <div className="an-tool-task">81 <ToolRowBase82// … truncated
More from agent-elements
All 25 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| agent-chatagent-chat | agent-elements | Components | Free | no deps | |
| attachment-buttonattachment-button | agent-elements | Components | Free | no deps | |
| bash-toolbash-tool | agent-elements | Components | Free | no deps | |
| edit-tooledit-tool | agent-elements | Components | Free | no deps | |
| error-messageerror-message | agent-elements | Components | Free | no deps | |
| file-attachmentfile-attachment | agent-elements | Components | Free | no deps | |
| generic-toolgeneric-tool | agent-elements | Components | Free | no deps | |
| input-barinput-bar | agent-elements | Components | Free | no deps |
