Skip to content

An AI-powered search engine with a generative UI

feat: add rail connectors for reasoning sections in grouped displays

Yoshiki Miura38f6f708755c
diff --git a/components/reasoning-section.tsx b/components/reasoning-section.tsx
index c95197b2..86286278 100644
--- a/components/reasoning-section.tsx
+++ b/components/reasoning-section.tsx
@@ -22,7 +22,9 @@ export interface ReasoningSectionProps {
onOpenChange: (open: boolean) => void
showIcon?: boolean
variant?: 'default' | 'minimal' | 'process' | 'process-sub'
- isSingle?: boolean // Whether this is a single item or part of a group
+ isSingle?: boolean // Whether this is a single item or part of a group
+ isFirst?: boolean
+ isLast?: boolean
}
export function ReasoningSection({
@@ -31,7 +33,9 @@ export function ReasoningSection({
onOpenChange,
showIcon = false,
variant = 'default',
- isSingle = true
+ isSingle = true,
+ isFirst = false,
+ isLast = false
}: ReasoningSectionProps) {
const { open } = useArtifact()
// Show a short preview when collapsed; switch to a generic label when expanded
@@ -78,11 +82,13 @@ export function ReasoningSection({
<ProcessHeader
label={
!isSingle ? (
- <div className="flex items-center gap-2 min-w-0 overflow-hidden">
- <div className="w-4 h-4 shrink-0 flex items-center justify-center">
+ <div className="flex items-center gap-2 min-w-0">
+ <div className="w-4 h-4 shrink-0 flex items-center justify-center relative">
<div className="w-1.5 h-1.5 rounded-full bg-muted-foreground" />
</div>
- <span className="truncate block min-w-0 max-w-full">{headerLabel}</span>
+ <span className="truncate block min-w-0 max-w-full">
+ {headerLabel}
+ </span>
</div>
) : (
headerLabel
@@ -102,20 +108,50 @@ export function ReasoningSection({
if (content.isDone && !content.reasoning?.trim()) return null
return (
- <CollapsibleMessage
- role="assistant"
- isCollapsible={true}
- header={reasoningHeader}
- isOpen={isOpen}
- onOpenChange={onOpenChange}
- showBorder={isSingle}
- showIcon={showIcon}
- variant={variant}
- showSeparator={false}
- >
- <div className="[&_p]:text-xs [&_p]:text-muted-foreground/80">
- <MarkdownMessage message={content.reasoning} />
- </div>
- </CollapsibleMessage>
+ <div className="relative">
+ {/* Rails for header - show based on position */}
+ {!isSingle && (
+ <>
+ {!isFirst && (
+ <div className="absolute left-[19.5px] w-px bg-border h-3 top-0" />
+ )}
+ {!isLast && (
+ <div className="absolute left-[19.5px] w-px bg-border h-3 bottom-0" />
+ )}
+ </>
+ )}
+ <CollapsibleMessage
+ role="assistant"
+ isCollapsible={true}
+ header={reasoningHeader}
+ isOpen={isOpen}
+ onOpenChange={onOpenChange}
+ showBorder={isSingle}
+ showIcon={showIcon}
+ variant={variant}
+ showSeparator={false}
+ >
+ <div className="flex">
+ {/* Rail when expanded and in a group */}
+ {isOpen && !isSingle && (
+ <>
+ <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="[&_p]:text-xs [&_p]:text-muted-foreground/80 flex-1">
+ <MarkdownMessage message={content.reasoning} />
+ </div>
+ </div>
+ </CollapsibleMessage>
+ </div>
)
}
diff --git a/components/research-process-section.tsx b/components/research-process-section.tsx
index 28a68b46..af568ca1 100644
--- a/components/research-process-section.tsx
+++ b/components/research-process-section.tsx
@@ -2,11 +2,7 @@
import { UseChatHelpers } from '@ai-sdk/react'
-import type {
- UIDataTypes,
- UIMessage,
- UITools
-} from '@/lib/types/ai'
+import type { UIDataTypes, UIMessage, UITools } from '@/lib/types/ai'
import { cn } from '@/lib/utils'
import { ReasoningSection } from './reasoning-section'
@@ -30,7 +26,7 @@ function splitByText(parts: AnyPart[]): AnyPart[][] {
let curr: AnyPart[] = []
for (const p of parts || []) {
if (p.type === 'text') {
- if (curr.length) segments.push(curr), (curr = [])
+ if (curr.length) (segments.push(curr), (curr = []))
} else {
curr.push(p)
}
@@ -90,61 +86,58 @@ export function ResearchProcessSection({
{segments.map((seg, sidx) => {
const groups = groupTools(seg)
const isSingle = groups.length === 1 && groups[0].length === 1
- const containerClass = cn(
- !isSingle && 'rounded-lg border bg-card'
- )
+ const containerClass = cn(!isSingle && 'rounded-lg border bg-card')
return (
<div key={`${messageId}-seg-${sidx}`} className={containerClass}>
{groups.map((grp, gidx) => {
- const isToolGroup = grp[0].type?.startsWith?.('tool-') && grp.length > 1
-
+ const isFirstGroup = gidx === 0
+ const isLastGroup = gidx === groups.length - 1
return (
- <div key={`${messageId}-grp-${sidx}-${gidx}`} className={cn('space-y-1')}>
+ <div
+ key={`${messageId}-grp-${sidx}-${gidx}`}
+ className={cn('space-y-1')}
+ >
{grp.map((part, pidx) => {
const railState = getRailState(pidx, grp.length)
const hasNext = pidx < grp.length - 1
if (part.type === 'reasoning') {
const rid = `${messageId}-reasoning-${sidx}-${gidx}-${pidx}`
return (
- <div
+ <ReasoningSection
key={rid}
- className="relative"
- >
- {/* rail inside content: using process variant to tighten paddings */}
- <div className="absolute left-1.5 top-0 bottom-0 w-px bg-transparent" />
- <ReasoningSection
- content={{ reasoning: part.text, isDone: !hasNext }}
- isOpen={getIsOpen(rid, 'reasoning', hasNext)}
- onOpenChange={open => onOpenChange(rid, open)}
- isSingle={isSingle}
- />
- </div>
+ content={{ reasoning: part.text, isDone: !hasNext }}
+ isOpen={getIsOpen(rid, 'reasoning', hasNext)}
+ onOpenChange={open => onOpenChange(rid, open)}
+ isSingle={isSingle}
+ isFirst={isFirstGroup && pidx === 0}
+ isLast={isLastGroup && pidx === grp.length - 1}
+ />
)
}
if (part.type?.startsWith?.('tool-')) {
- // Render via ToolSection but borderless
const id = part.toolCallId
return (
- <div
- key={id}
- className="relative"
- >
- {/* Rail */}
- {isToolGroup && (
- <>
- <span
- className={cn(
- 'absolute left-1.5 w-px bg-border/50',
- railState === 'single' && 'top-2 bottom-2',
- railState === 'first' && 'top-2 bottom-0',
- railState === 'middle' && 'top-0 bottom-0',
- railState === 'last' && 'top-0 bottom-2'
- )}
- />
- <span className="absolute left-1 top-2 h-2 w-2 rounded-full bg-muted-foreground/70" />
- </>
+ <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}
@@ -176,4 +169,4 @@ export function ResearchProcessSection({
)
}
-export default ResearchProcessSection
\ No newline at end of file
+export default ResearchProcessSection