页面简介
Displays the agent's thinking as it streams.
正文摘录
SectionsIntroductionComponentsAI ElementsInstallationThemingCLITypesetSkillsRegistryChangelogComponentsAccordionAlertAlert DialogAspect RatioAttachmentAvatarBadgeBreadcrumbBubbleButtonButton GroupCalendarCardCarouselChartCheckboxCode BlockCollapsibleComboboxCommandContext MenuData TableDate PickerDialogDirectionDrawerDropdown MenuEmptyFieldHover CardInputInput GroupInput OTPItemKbdLabelMarkerMenubarMessageMessage ScrollerNative SelectNavigation MenuPaginationPopoverProgressQuestionnaireRadio GroupResizableScroll AreaSelectSeparatorSheetSidebarSkeletonSliderSonnerSpinnerSwitchTableTabsTextareaToastToggleToggle 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.jsonReasoningCopy PagePreviousNextDisplays the agent's thinking as it streams.Base UIReact AriaRadix UIWhy is the checkout deploy so slow?Thought for 5sThe deploy log has three phases. Install takes 38s and next build takes 52s, both normal for this repo. Image optimization takes 3m 50s. It reruns on every deploy because its cache key includes the commit hash, so the cache never hits.Image optimization is the bottleneck. Key its cache on the lockfile and the image directory instead of the commit hash, and the deploy should take under two minutes.ReplayCopy"use client" import * as React from "react"View Code Reasoning is a line for the agent's thinking. It reads "Thinking" and opens while the model thinks, then reads "Thought" and closes when it is done. The thinking itself sits inside, and the line can show how long it took. Reasoning is built with Trace with a TraceCollapsible for the thinking. Installation Reasoning is built with the Trace component. CommandManualpnpmnpmyarnbunpnpm dlx shadcn@latest add traceCopy Usage Copyimport { Trace, TraceCollapsible, TraceCollapsibleContent, TraceCollapsibleTrigger, TraceIcon, TraceLine, TraceTitle, } from "@/components/ui/trace" Copy<Trace> <TraceCollapsible> <TraceCollapsibleTrigger> <TraceLine> <TraceIcon> <CircleCheckIcon /> </TraceIcon> <TraceTitle>Thought</TraceTitle> </TraceLine> </TraceCollapsibleTrigger> <TraceCollapsibleContent className="whitespace-pre-wrap"> {text} </TraceCollapsibleContent> </TraceCollapsible> </Trace> Duration The AI SDK does not time reasoning. Measure it on the server, send it as message metadata, and show it in a TraceDescription after the title. Thought12sCopyimport { CircleCheckIcon } from "lucide-react" import {View Code Copy<TraceLine> <TraceIcon> <CircleCheckIcon /> </TraceIcon> <TraceTitle>Thought</TraceTitle> <TraceDescription>{seconds}s</TraceDescription> </TraceLine> AI SDK Render each reasoning part as a line. It starts as a plain TraceLine and becomes a TraceCollapsible once text arrives, so there is nothing to open before the model has written anything. It opens while the model thinks and closes when it finishes. If the person opens or closes it, their choice wins. See Open State. Copyfunction ReasoningLine({ text, running }: { text: string; running: boolean }) { const [open, setOpen] = React.useState<boolean>() const line = ( <TraceLine status={running ? "running" : undefined}> <TraceIcon> {running ? ( <LoaderCircleIcon className="animate-spin" /> ) : ( <CircleCheckIcon /> )} </TraceIcon> <TraceTitle>{running ? "Thinking" : "Thought"}</TraceTitle> </TraceLine> ) if (text.length === 0) { return line } return ( <TraceCollapsible open={open ?? running} onOpenChange={setOpen}> <TraceCollapsibleTrigger>{line}</TraceCollapsibleTrigger> <TraceCollapsibleContent className="whitespace-pre-wrap"> {text} </TraceCollapsibleContent> </TraceCollapsible> ) } Copy<Trace> {message.parts .filter((part) => part.type === "reasoning") .map((part, index) => ( <ReasoningLine key={index} text={part.text} running={streaming && part.state === "streaming"} /> ))} </Trace> Some models send several reasoning parts in one message. Each one is a line in the same Trace. Migrating from AI SDK Elements If you added Reasoning from AI SDK Elements, your project has a components/ai-elements/reasoning.tsx wrapper. Paste this prompt into your coding agent to rebuild it on Trace. Every export keeps its name and props, so the code that uses it keeps working. PromptCopyMigrate components/ai-elements/reasoning.tsx from AI SDK Elements to the shadcn/ui Trace component. 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 Trace: npx shadcn@latest add trace 2. Read https://ui.shadcn.com/docs/ai-elements/radix/reasoning.md and build Reasoning the same way. 3. Rebuild each part: - Reasoning renders a Trace with a TraceCollapsible. Keep isStreaming, open, defaultOpen, onOpenChange and duration, and the useReasoning context. - ReasoningTrigger renders a TraceCollapsibleTrigger with a TraceLine, a TraceIcon and a TraceTitle. Set status="running" while isStreaming is true, instead of the Shimmer. The title reads "Thinking" while it streams, then the duration, like "Thought for 5s". - ReasoningContent renders a TraceCollapsibleContent. Keep Streamdown for the text. - Keep the open behavior: open while it streams, close when it finishes, unless the person opened or closed it. 4. Remove the imports the file no longer uses. 5. Run the type checker and fix any errors.Expand API Reference See Trace. QueueSources On This PageInstallationUsageDurationAI 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