mirror of
https://github.com/supabase/supabase.git
synced 2026-10-06 09:55:06 +03:00
<img width="913" height="572" alt="image" src="https://github.com/user-attachments/assets/e8112085-508a-49e4-abb1-7550248e611e" /> ## Problem A single Assistant response often produces 10+ reasoning and lookup rows ("Reasoned", "Ran search_docs", …). They push the answer down the chat, use raw tool names, and a fast tool call flashes past before the row goes back to "Thinking...". ## Solution Consecutive reasoning and lookup rows fold into one collapsible group. - **Running:** the header shows a tool only while it executes ("Checking policies in public..."). Between calls it reads "Thinking...", however long that lasts. Each header label stays up for at least 1 second, so quick calls no longer flash. - **Finished:** the header lists what the tools did, e.g. "Searched docs and checked policies", or "…, and 2 more". - **Expanded (any time):** every call is listed under a vertical rule. Rows still in progress shimmer, including several at once for parallel calls. ## How to test 1. Run `pnpm dev:studio` and open the Assistant on a project with a few tables. 2. Ask something that needs several lookups, e.g. "What RLS policies do I have and what do the docs recommend for them?" 3. While it streams, check the collapsed header: - It shows each tool while it runs, then goes back to "Thinking..." between calls. - Labels don't flash. Each stays up for about a second. - Only the shimmer marks progress, with no blinking cursor underneath. 4. Expand the group mid-stream. Rows read like "Checking policies in public..." rather than tool names, and only rows still in progress shimmer. 5. When it finishes, the header lists the actions ("Searched docs and checked policies") and stops shimmering. 6. Press Stop while a group is running. The unfinished row reads "Response interrupted" and stops spinning. 7. Reload the chat. Older groups show their collapsed summaries. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * AI assistant tool activity is grouped into collapsible sections with progress labels while work is underway and summaries when complete. * Expand grouped activity to review reasoning and tool details. Active tools and reasoning are highlighted, while completed reasoning without text is hidden. * Progress labels remain visible briefly during transitions, and active responses display a shimmer effect. * **Bug Fixes** * The loading indicator no longer appears while the assistant is processing a tool group. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
115 lines
3.5 KiB
TypeScript
115 lines
3.5 KiB
TypeScript
import { UIMessage as VercelMessage } from '@ai-sdk/react'
|
|
import { memo, type PropsWithChildren } from 'react'
|
|
import { cn } from 'ui'
|
|
|
|
import { useMessageInfoContext } from './Message.Context'
|
|
import { MessagePartSwitcher, MessagePartToolGroup } from './Message.Parts'
|
|
import { groupMessageParts, isRunningToolCall } from './Message.Parts.utils'
|
|
import { MessageMarkdown } from './MessageMarkdown'
|
|
import { ProfileImage as ProfileImageDisplay } from '@/components/ui/ProfileImage'
|
|
import { useProfileNameAndPicture } from '@/lib/profile'
|
|
|
|
function MessageDisplayProfileImage() {
|
|
const { username, avatarUrl } = useProfileNameAndPicture()
|
|
return (
|
|
<ProfileImageDisplay
|
|
alt={username}
|
|
src={avatarUrl}
|
|
className="w-5 h-5 shrink-0 rounded-full translate-y-0.5"
|
|
/>
|
|
)
|
|
}
|
|
|
|
function MessageDisplayContainer({
|
|
children,
|
|
onClick,
|
|
className,
|
|
}: PropsWithChildren<{ onClick?: () => void; className?: string }>) {
|
|
return (
|
|
<div
|
|
className={cn('group text-foreground-light text-sm first:mt-0', className)}
|
|
onClick={onClick}
|
|
>
|
|
{children}
|
|
</div>
|
|
)
|
|
}
|
|
|
|
function MessageDisplayMainArea({
|
|
children,
|
|
className,
|
|
}: PropsWithChildren<{ className?: string }>) {
|
|
return <div className={cn('flex gap-4 w-auto overflow-hidden group', className)}>{children}</div>
|
|
}
|
|
|
|
const MessageDisplayContent = memo(function MessageDisplayContent({
|
|
message,
|
|
}: {
|
|
message: VercelMessage
|
|
}) {
|
|
const { id, isLoading, isLastMessage, readOnly } = useMessageInfoContext()
|
|
|
|
const messageParts = message.parts
|
|
const content =
|
|
('content' in message && typeof message.content === 'string' && message.content.trim()) ||
|
|
undefined
|
|
|
|
// The SDK exposes its mutable object on the first write, then publishes clones. Capture
|
|
// state/text now so later mutations cannot change memoized parts' previous props.
|
|
const items = groupMessageParts((messageParts ?? []).map((part) => ({ ...part })))
|
|
const isStreaming = isLoading && !!isLastMessage
|
|
|
|
return (
|
|
<div className="flex-1 min-w-0">
|
|
{messageParts?.length > 0
|
|
? items.map((item, idx) => {
|
|
if (item.type === 'part') {
|
|
return <MessagePartSwitcher key={item.partIndex} part={item.part} />
|
|
}
|
|
return (
|
|
<MessagePartToolGroup
|
|
key={`tool-group-${item.groupIndex}`}
|
|
parts={item.parts}
|
|
// The trailing group can still grow, and a parallel call can outlast a later block
|
|
isRunning={
|
|
isStreaming && (idx === items.length - 1 || item.parts.some(isRunningToolCall))
|
|
}
|
|
/>
|
|
)
|
|
})
|
|
: content && (
|
|
<div className="w-full max-w-3xl mx-auto">
|
|
<MessageDisplayTextMessage id={id} isLoading={isLoading} readOnly={readOnly}>
|
|
{content}
|
|
</MessageDisplayTextMessage>
|
|
</div>
|
|
)}
|
|
</div>
|
|
)
|
|
})
|
|
|
|
function MessageDisplayTextMessage({
|
|
id,
|
|
isLoading,
|
|
readOnly,
|
|
children,
|
|
}: PropsWithChildren<{ id: string; isLoading: boolean; readOnly?: boolean }>) {
|
|
return (
|
|
<MessageMarkdown
|
|
id={id}
|
|
isLoading={isLoading}
|
|
readOnly={readOnly}
|
|
className="prose prose-sm max-w-none wrap-break-word prose-h2:font-medium"
|
|
>
|
|
{children}
|
|
</MessageMarkdown>
|
|
)
|
|
}
|
|
|
|
export const MessageDisplay = {
|
|
Container: MessageDisplayContainer,
|
|
Content: MessageDisplayContent,
|
|
MainArea: MessageDisplayMainArea,
|
|
ProfileImage: MessageDisplayProfileImage,
|
|
}
|