An AI-powered search engine with a generative UI
TypeScript generative-aigenerative-uinextjsollamareactsearxngshadcn-uitailwindcsstavilytypescriptupstashvercel-ai-sdk
feat: add rail connectors for all tool sections in grouped displays
Yoshiki Miuraa2294e4de330
diff --git a/components/fetch-section.tsx b/components/fetch-section.tsxindex d4fc2a2a..ce101430 100644--- a/components/fetch-section.tsx+++ b/components/fetch-section.tsx@@ -12,9 +12,20 @@ interface FetchSectionProps {isOpen: booleanonOpenChange: (open: boolean) => voidstatus?: UseChatHelpers<UIMessage<unknown, UIDataTypes, UITools>>['status']+ borderless?: boolean+ isFirst?: boolean+ isLast?: boolean}-export function FetchSection({ tool }: FetchSectionProps) {+export function FetchSection({+ tool,+ isOpen,+ onOpenChange,+ status,+ borderless = false,+ isFirst = false,+ isLast = false+}: FetchSectionProps) {const url = tool.input?.url// Determine the status based on tool output availability@@ -45,7 +56,18 @@ export function FetchSection({ tool }: FetchSectionProps) {}return (- <div className="w-full">+ <div className="relative w-full">+ {/* Rails for header - show based on position */}+ {borderless && (+ <>+ {!isFirst && (+ <div className="absolute left-[19.5px] w-px bg-border h-2 top-0" />+ )}+ {!isLast && (+ <div className="absolute left-[19.5px] w-px bg-border h-2 bottom-0" />+ )}+ </>+ )}<FetchPreviewurl={url || ''}title={title}diff --git a/components/reasoning-section.tsx b/components/reasoning-section.tsxindex 86286278..c330e1c9 100644--- a/components/reasoning-section.tsx+++ b/components/reasoning-section.tsx@@ -113,10 +113,10 @@ export function ReasoningSection({{!isSingle && (<>{!isFirst && (- <div className="absolute left-[19.5px] w-px bg-border h-3 top-0" />+ <div className="absolute left-[19.5px] w-px bg-border h-2 top-0" />)}{!isLast && (- <div className="absolute left-[19.5px] w-px bg-border h-3 bottom-0" />+ <div className="absolute left-[19.5px] w-px bg-border h-2 bottom-0" />)}</>)}diff --git a/components/research-process-section.tsx b/components/research-process-section.tsxindex af568ca1..fd9eac0c 100644--- a/components/research-process-section.tsx+++ b/components/research-process-section.tsx@@ -57,14 +57,6 @@ function groupTools(segment: AnyPart[]): AnyPart[][] {return groups}-function getRailState(index: number, total: number): RailState {- if (total <= 1) return 'single'- if (index === 0) return 'first'- if (index === total - 1) return 'last'- return 'middle'-}--type RailState = 'single' | 'first' | 'middle' | 'last'export function ResearchProcessSection({message,@@ -99,7 +91,6 @@ export function ResearchProcessSection({className={cn('space-y-1')}>{grp.map((part, pidx) => {- const railState = getRailState(pidx, grp.length)const hasNext = pidx < grp.length - 1if (part.type === 'reasoning') {const rid = `${messageId}-reasoning-${sidx}-${gidx}-${pidx}`@@ -119,36 +110,18 @@ export function ResearchProcessSection({if (part.type?.startsWith?.('tool-')) {const id = part.toolCallIdreturn (- <div key={id} className="relative">- {/* Rail connecting header icons */}- {!isSingle && grp.length > 1 && (- <div- className="absolute left-[19px] w-px bg-border/50 pointer-events-none z-10"- style={{- top: railState === 'first' ? '24px' : '0',- bottom:- railState === 'last'- ? 'calc(100% - 24px)'- : '0',- height:- railState === 'last'- ? '24px'- : railState === 'first'- ? 'calc(100% - 24px)'- : '100%'- }}- />- )}- <ToolSection- tool={part}- isOpen={getIsOpen(id, part.type, hasNext)}- onOpenChange={open => onOpenChange(id, open)}- status={status}- addToolResult={addToolResult}- onQuerySelect={onQuerySelect}- borderless={!isSingle}- />- </div>+ <ToolSection+ key={id}+ tool={part}+ isOpen={getIsOpen(id, part.type, hasNext)}+ onOpenChange={open => onOpenChange(id, open)}+ status={status}+ addToolResult={addToolResult}+ onQuerySelect={onQuerySelect}+ borderless={!isSingle}+ isFirst={isFirstGroup && pidx === 0}+ isLast={isLastGroup && pidx === grp.length - 1}+ />)}diff --git a/components/search-section.tsx b/components/search-section.tsxindex 8196a799..56ab77b8 100644--- a/components/search-section.tsx+++ b/components/search-section.tsx@@ -26,6 +26,8 @@ interface SearchSectionProps {onOpenChange: (open: boolean) => voidstatus?: UseChatHelpers<UIMessage<unknown, UIDataTypes, UITools>>['status']borderless?: boolean+ isFirst?: boolean+ isLast?: boolean}export function SearchSection({@@ -33,7 +35,9 @@ export function SearchSection({isOpen,onOpenChange,status,- borderless+ borderless,+ isFirst = false,+ isLast = false}: SearchSectionProps) {const isLoading = status === 'submitted' || status === 'streaming'@@ -79,52 +83,85 @@ export function SearchSection({)return (- <CollapsibleMessage- role="assistant"- isCollapsible={true}- header={header}- isOpen={isOpen}- onOpenChange={onOpenChange}- showIcon={false}- showBorder={!borderless}- variant="default"- >- {searchResults &&- searchResults.images &&- searchResults.images.length > 0 && (- <Section>- <SearchResultsImageSection- images={searchResults.images}- query={query}- />- </Section>- )}- {searchResults &&- searchResults.videos &&- searchResults.videos.length > 0 && (- <Section title="Videos">- <VideoSearchResults- results={createVideoSearchResults(searchResults, query)}- />- </Section>- )}- {isError ? (- <Section>- <div className="bg-card rounded-lg">- <div className="flex items-center gap-2 w-full">- <span className="text-sm text-destructive block flex-1 min-w-0">- {errorMessage}- </span>+ <div className="relative">+ {/* Rails for header - show based on position */}+ {borderless && (+ <>+ {!isFirst && (+ <div className="absolute left-[19.5px] w-px bg-border h-2 top-0" />+ )}+ {!isLast && (+ <div className="absolute left-[19.5px] w-px bg-border h-2 bottom-0" />+ )}+ </>+ )}+ <CollapsibleMessage+ role="assistant"+ isCollapsible={true}+ header={header}+ isOpen={isOpen}+ onOpenChange={onOpenChange}+ showIcon={false}+ showBorder={!borderless}+ variant="default"+ showSeparator={false}+ >+ <div className="flex">+ {/* Rail when expanded and in a group */}+ {isOpen && borderless && (+ <>+ <div className="w-[16px] shrink-0 flex justify-center">+ <div+ className="w-px bg-border/50"+ style={{+ marginTop: isFirst ? '0' : '-1rem',+ marginBottom: isLast ? '0' : '-1rem'+ }}+ /></div>- </div>- </Section>- ) : isLoading && isToolLoading ? (- <SearchSkeleton />- ) : searchResults?.results && searchResults.results.length > 0 ? (- <Section title="Sources">- <SearchResults results={searchResults.results} />- </Section>- ) : null}+ <div className="w-2 shrink-0" />+ </>+ )}+ <div className="flex-1">+ {searchResults &&+ searchResults.images &&+ searchResults.images.length > 0 && (+ <Section>+ <SearchResultsImageSection+ images={searchResults.images}+ query={query}+ />+ </Section>+ )}+ {searchResults &&+ searchResults.videos &&+ searchResults.videos.length > 0 && (+ <Section title="Videos">+ <VideoSearchResults+ results={createVideoSearchResults(searchResults, query)}+ />+ </Section>+ )}+ {isError ? (+ <Section>+ <div className="bg-card rounded-lg">+ <div className="flex items-center gap-2 w-full">+ <span className="text-sm text-destructive block flex-1 min-w-0">+ {errorMessage}+ </span>+ </div>+ </div>+ </Section>+ ) : isLoading && isToolLoading ? (+ <SearchSkeleton />+ ) : searchResults?.results && searchResults.results.length > 0 ? (+ <Section title="Sources">+ <SearchResults results={searchResults.results} />+ </Section>+ ) : null}+ </div>+ </div></CollapsibleMessage>+ </div>)}diff --git a/components/tool-section.tsx b/components/tool-section.tsxindex 19928d28..baa491c0 100644--- a/components/tool-section.tsx+++ b/components/tool-section.tsx@@ -17,6 +17,8 @@ interface ToolSectionProps {addToolResult?: (params: { toolCallId: string; result: any }) => voidonQuerySelect: (query: string) => voidborderless?: boolean+ isFirst?: boolean+ isLast?: boolean}export function ToolSection({@@ -26,7 +28,9 @@ export function ToolSection({status,addToolResult,onQuerySelect,- borderless = false+ borderless = false,+ isFirst = false,+ isLast = false}: ToolSectionProps) {// Special handling for ask_question toolif (tool.type === 'tool-askQuestion') {@@ -75,6 +79,8 @@ export function ToolSection({onOpenChange={onOpenChange}status={status}borderless={borderless}+ isFirst={isFirst}+ isLast={isLast}/>)case 'tool-fetch':@@ -85,6 +91,8 @@ export function ToolSection({onOpenChange={onOpenChange}status={status}borderless={borderless}+ isFirst={isFirst}+ isLast={isLast}/>)case 'tool-todoWrite':@@ -99,6 +107,8 @@ export function ToolSection({isOpen={isOpen}onOpenChange={onOpenChange}borderless={borderless}+ isFirst={isFirst}+ isLast={isLast}/>)case 'tool-todoRead':@@ -113,6 +123,8 @@ export function ToolSection({isOpen={isOpen}onOpenChange={onOpenChange}borderless={borderless}+ isFirst={isFirst}+ isLast={isLast}/>)default:diff --git a/components/tool-todo-display.tsx b/components/tool-todo-display.tsxindex 9fef0566..558a121f 100644--- a/components/tool-todo-display.tsx+++ b/components/tool-todo-display.tsx@@ -28,6 +28,8 @@ interface ToolTodoDisplayProps {isOpen?: booleanonOpenChange?: (open: boolean) => voidborderless?: boolean+ isFirst?: boolean+ isLast?: boolean}export function ToolTodoDisplay({@@ -37,7 +39,9 @@ export function ToolTodoDisplay({toolCallId,isOpen = false,onOpenChange,- borderless = false+ borderless = false,+ isFirst = false,+ isLast = false}: ToolTodoDisplayProps) {const { open: openArtifact } = useArtifact()// Calculate counts for display@@ -99,36 +103,68 @@ export function ToolTodoDisplay({)return (- <CollapsibleMessage- role="assistant"- isCollapsible={true}- header={header}- isOpen={isOpen}- onOpenChange={onOpenChange}- showBorder={!borderless}- showIcon={false}- variant="default"- showSeparator={false}- >- {state === 'output-available' ? (- <TodoListContent- todos={output?.todos}- message={- tool === 'todoRead'- ? (output as any)?.summary || output?.message- : output?.message- }- completedCount={completedCount}- totalCount={totalCount}- showSummary={false}- itemVariant="plain"- className="pb-1"- />- ) : state === 'output-error' ? (- <div className="px-3 pb-3 text-xs text-destructive">{`Todo tool failed${- (output as any)?.message ? `: ${(output as any).message}` : ''- }`}</div>- ) : null}+ <div className="relative">+ {/* Rails for header - show based on position */}+ {borderless && (+ <>+ {!isFirst && (+ <div className="absolute left-[19.5px] w-px bg-border h-2 top-0" />+ )}+ {!isLast && (+ <div className="absolute left-[19.5px] w-px bg-border h-2 bottom-0" />+ )}+ </>+ )}+ <CollapsibleMessage+ role="assistant"+ isCollapsible={true}+ header={header}+ isOpen={isOpen}+ onOpenChange={onOpenChange}+ showBorder={!borderless}+ showIcon={false}+ variant="default"+ showSeparator={false}+ >+ <div className="flex">+ {/* Rail when expanded and in a group */}+ {isOpen && borderless && (+ <>+ <div className="w-[16px] shrink-0 flex justify-center">+ <div+ className="w-px bg-border/50"+ style={{+ marginTop: isFirst ? '0' : '-1rem',+ marginBottom: isLast ? '0' : '-1rem'+ }}+ />+ </div>+ <div className="w-2 shrink-0" />+ </>+ )}+ <div className="flex-1">+ {state === 'output-available' ? (+ <TodoListContent+ todos={output?.todos}+ message={+ tool === 'todoRead'+ ? (output as any)?.summary || output?.message+ : output?.message+ }+ completedCount={completedCount}+ totalCount={totalCount}+ showSummary={false}+ itemVariant="plain"+ className="pb-1"+ />+ ) : state === 'output-error' ? (+ <div className="px-3 pb-3 text-xs text-destructive">{`Todo tool failed${+ (output as any)?.message ? `: ${(output as any).message}` : ''+ }`}</div>+ ) : null}+ </div>+ </div></CollapsibleMessage>+ </div>)}