mirror of
https://github.com/supabase/supabase.git
synced 2026-10-05 09:25:06 +03:00
* update onboarding * update model and fix part issue * action orientated assistant * fix tool * lock * remove unused filter * fix tests * fix again * update package * update container * fix tests * refactor(ai assistant): break out message markdown and profile picture * wip * refactor(ai assistant): break up message component * refactor: break ai assistant message down into multiple files * refactor: simplify ReportBlock state * fix: styling of draggable report block header When the drag handle is showing, it overlaps with the block header. Decrease the opacity of the header so the handle can be seen and the two can be distinguished. * fix: minor tweaks to tool ui * refactor: simplify DisplayBlockRenderer state * fix: remove double deploy button in edge function block When the confirm footer is shown, the deploy button on the top right should be hidden (not just disabled) to avoid confusion. * refactor, test: message sanitization by opt-in level Refactor the message sanitization to have more type safety and be more testable. Add tests to ensure: - Message sanitization always runs on generate-v4 - Message sanitization correctly works by opt-in level * Fix conflicts in pnpm lock * Couple of nits and refactors * Revert casing for report block snippet * adjust sanitised prompt * Fix tests --------- Co-authored-by: Charis Lam <26616127+charislam@users.noreply.github.com> Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
91 lines
2.5 KiB
TypeScript
91 lines
2.5 KiB
TypeScript
import { UIMessage as VercelMessage } from '@ai-sdk/react'
|
|
import { type PropsWithChildren } from 'react'
|
|
|
|
import { ProfileImage as ProfileImageDisplay } from 'components/ui/ProfileImage'
|
|
import { useProfileNameAndPicture } from 'lib/profile'
|
|
import { cn } from 'ui'
|
|
import { useMessageInfoContext } from './Message.Context'
|
|
import { MessageMarkdown, MessagePartSwitcher } from './Message.Parts'
|
|
|
|
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>
|
|
}
|
|
|
|
function MessageDisplayContent({ message }: { message: VercelMessage }) {
|
|
const { id, isLoading, readOnly } = useMessageInfoContext()
|
|
|
|
const messageParts = message.parts
|
|
const content =
|
|
('content' in message && typeof message.content === 'string' && message.content.trim()) ||
|
|
undefined
|
|
|
|
return (
|
|
<div className="flex-1 min-w-0">
|
|
{messageParts?.length > 0
|
|
? messageParts.map((part: NonNullable<VercelMessage['parts'][number]>, idx) => {
|
|
const isLastPart = idx === messageParts.length - 1
|
|
return <MessagePartSwitcher part={part} isLastPart={isLastPart} />
|
|
})
|
|
: content && (
|
|
<MessageDisplayTextMessage id={id} isLoading={isLoading} readOnly={readOnly}>
|
|
{content}
|
|
</MessageDisplayTextMessage>
|
|
)}
|
|
</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 break-words"
|
|
>
|
|
{children}
|
|
</MessageMarkdown>
|
|
)
|
|
}
|
|
|
|
export const MessageDisplay = {
|
|
Container: MessageDisplayContainer,
|
|
Content: MessageDisplayContent,
|
|
MainArea: MessageDisplayMainArea,
|
|
ProfileImage: MessageDisplayProfileImage,
|
|
}
|