页面简介
Displays a command the agent runs, with its output as it streams.
正文摘录
SectionsIntroductionComponentsAI ElementsInstallationThemingCLITypesetSkillsRegistryChangelogComponentsAccordionAlertAlert DialogAspect RatioAttachmentAvatarBadgeBreadcrumbBubbleButtonButton GroupCalendarCardCarouselChartCheckboxCode BlockCollapsibleComboboxCommandContext MenuData TableDate PickerDialogDirectionDrawerDropdown MenuEmptyFieldHover CardInputInput GroupInput OTPItemKbdLabelMarkerMenubarMessageMessage ScrollerNative SelectNavigation MenuPaginationPopoverProgressQuestionnaireRadio GroupResizableScroll AreaSelectSeparatorSheetSidebarSkeletonSliderSpinnerSwitchTableTabsTextareaToastToggleToggle GroupTooltipTraceTypographyAI ElementsIntroductionChain of ThoughtChatCheckpointConfirmationContextFile TreeInline CitationMessageModel SelectorPlanPrompt InputQueueReasoningSourcesStack TraceSubagentSuggestionTaskTerminalTest ResultsToolGet StartedInstallationcomponents.jsonPackage ImportsThemingTypesetDark ModeCLIMonorepoSkillsJavaScriptFigmallms.txtLegacy Docs@shadcn/reactMessage ScrollerQuestionnaire@shadcn/helpersAI SDKTanStack AIFormsReact Hook FormTanStack FormFormischUtilitiesscroll-fadeshimmerRegistryIntroductionGetting StartedGitHub RegistriesRegistry DirectoryRegistry HealthExamplesNamespacesAuthenticationDynamic SearchMCP ServerOpen in v0FAQAPI Referenceregistry.jsonregistry-item.jsonTerminalCopy PagePreviousNextDisplays a command the agent runs, with its output as it streams.Base UIReact AriaRadix UIRun the checks, then build the app.Ran pnpm lintRan pnpm testRan pnpm build> acme-chat@0.1.0 build > next build ▲ Next.js 16.3.0 Creating an optimized production build ... ✓ Compiled successfully in 4.2s ✓ Generating static pages (12/12) Route (app) Size First Load JS ┌ ○ / 1.9 kB 112 kB └ ƒ /api/chat 141 B 102 kBLint and tests pass, and the build compiled both routes.ReplayCopy"use client" import * as React from "react"View Code Terminal is a shell command the agent runs, such as a lint, a test run or a build. The line shows the command, and its output streams in underneath while it runs. Terminal is built with Trace with a TraceCollapsible for each command. Installation Terminal is built with the Trace and Code Block components. CommandManualpnpmnpmyarnbunpnpm dlx shadcn@latest add trace code-blockCopy Usage Copyimport { CodeBlock, CodeBlockContent } from "@/components/ui/code-block" import { Trace, TraceCollapsible, TraceCollapsibleContent, TraceCollapsibleTrigger, TraceIcon, TraceLine, TraceTitle, } from "@/components/ui/trace" Copy<Trace> <TraceCollapsible> <TraceCollapsibleTrigger> <TraceLine> <TraceIcon> <TerminalIcon /> </TraceIcon> <TraceTitle>Ran pnpm build</TraceTitle> </TraceLine> </TraceCollapsibleTrigger> <TraceCollapsibleContent> <CodeBlock size="sm"> <CodeBlockContent wrap className="max-h-64"> {output} </CodeBlockContent> </CodeBlock> </TraceCollapsibleContent> </TraceCollapsible> </Trace> Exit Code A command that exits with any code other than 0 failed. Set status="error". Ran pnpm installpnpm lint exited with code 1> acme-chat@0.1.0 lint > eslint . app/api/chat/route.ts 14:7 error 'model' is assigned a value but never used no-unused-vars components/chat.tsx 42:5 error React Hook useEffect has a missing dependency: 'messages' react-hooks/exhaustive-deps ✖ 2 problems (2 errors, 0 warnings) ELIFECYCLE Command failed with exit code 1.Copyimport { TerminalIcon } from "lucide-react" import { CodeBlock, CodeBlockContent } from "@/components/ui/code-block"View Code CommandstatusTitleRunning"running"Running pnpm buildExited with 0noneRan pnpm buildExited with another code"error"pnpm lint exited with code 1 The command is a tool call, so its states map the same way as in Tool. Open While Running Open the line once the first output arrives, so the output is visible while the command runs. Leave it open or closed after that, as in Trace. AI SDK A tool result arrives only once the command exits. To stream the output while it runs, write it from the tool as a data part with the tool call's id. The AI SDK replaces a data part that has the same id, so the output grows in place. Copywriter.write({ type: "data-terminal", id: toolCallId, data: { output }, }) On the client, find the data part that matches each tool part. Copyfunction getOutput(message: ChatMessage, toolCallId: string) { for (const part of message.parts) { if (part.type === "data-terminal" && part.id === toolCallId) { return part.data.output } } return "" } Migrating from AI SDK Elements If you added Terminal from AI SDK Elements, your project has a components/ai-elements/terminal.tsx wrapper. Paste this prompt into your coding agent to rebuild it on Trace and Code Block. Every export keeps its name and props, so the code that uses it keeps working. PromptCopyMigrate components/ai-elements/terminal.tsx from AI SDK Elements to the shadcn/ui Trace and Code Block components. Keep every export, with the same name and props, so the code that imports it keeps working. Only change how each part renders. 1. Install the components: npx shadcn@latest add trace code-block 2. Read https://ui.shadcn.com/docs/ai-elements/base/terminal.md and build Terminal the same way. 3. Rebuild each part: - Import CodeBlock and CodeBlockContent from @/components/ui/code-block, not from ./code-block. - Terminal renders a Trace with a TraceCollapsible. Keep output, isStreaming, autoScroll and onClear. - TerminalHeader renders a TraceCollapsibleTrigger with a TraceLine. Set status="running" while isStreaming is true. - TerminalTitle renders a TraceIcon with a TerminalIcon and a TraceTitle, like "Ran pnpm build". - TerminalContent renders a TraceCollapsibleContent with a CodeBlock with size="sm", and a CodeBlockContent with wrap and className="max-h-64" for the output. - Open the line once output arrives while the command runs. - Buttons cannot sit inside a trigger. Render TerminalStatus, TerminalActions and the copy and clear buttons next to the TraceCollapsibleTrigger, not inside it. 4. Remove ansi-to-react from the dependencies if nothing else uses it. 5. Remove the imports the file no longer uses. 6. Run the type checker and fix any errors.Expand API Reference See Trace. TaskTest Results On This PageInstallationUsageExit CodeOpen While RunningAI SDKMigrating from AI SDK ElementsAPI ReferenceDeploy your shadcn/ui app on VercelTrusted by OpenAI, Sonos, Adobe, and more.Vercel provides tools and infrastructure to deploy apps and features at scale.Deploy NowDeploy to Vercel