Files
supabase/apps/studio/components/ui/AIAssistantPanel/AIAssistantHeader.tsx
Matt Rossman 18ce0659c7 feat(assistant): add overflow menu with Copy chat ID action (#43303)
Adds an overflow `…` menu to the AI assistant header with a **Copy chat
ID** action. Clicking it copies the active chat's UUID to the clipboard,
useful for reproduction/debugging.

<img width="810" height="233" alt="CleanShot 2026-03-02 at 14 55 31@2x"
src="https://github.com/user-attachments/assets/f3571978-6ca0-4f99-8b5d-625742f290e6"
/>

This facilitates filtering Logs like so:

<img width="727" height="321" alt="CleanShot 2026-03-02 at 14 57 01@2x"
src="https://github.com/user-attachments/assets/ec259f2d-58f9-4087-beca-351f62ac5059"
/>

Closes AI-441
2026-03-02 22:34:00 -05:00

149 lines
5.4 KiB
TypeScript

import { Clipboard, Ellipsis, Plus, Settings, X } from 'lucide-react'
import { useState } from 'react'
import { useAiAssistantStateSnapshot } from 'state/ai-assistant-state'
import {
AiIconAnimation,
Button,
copyToClipboard,
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuTrigger,
} from 'ui'
import { Admonition } from 'ui-patterns'
import { ButtonTooltip } from '../ButtonTooltip'
import { AIAssistantChatSelector } from './AIAssistantChatSelector'
import { AIOptInModal } from './AIOptInModal'
interface AIAssistantHeaderProps {
isChatLoading: boolean
onNewChat: () => void
onCloseAssistant: () => void
showMetadataWarning: boolean
updatedOptInSinceMCP: boolean
isHipaaProjectDisallowed: boolean
aiOptInLevel: 'disabled' | 'schema' | 'full' | string | undefined
}
export const AIAssistantHeader = ({
isChatLoading,
onNewChat,
onCloseAssistant,
showMetadataWarning,
updatedOptInSinceMCP,
isHipaaProjectDisallowed,
aiOptInLevel,
}: AIAssistantHeaderProps) => {
const snap = useAiAssistantStateSnapshot()
const [isOptInModalOpen, setIsOptInModalOpen] = useState(false)
return (
<div className="z-30 sticky top-0">
<div className="border-b border-b-muted flex items-center bg gap-x-4 pl-4 pr-3 min-h-[var(--header-height)]">
<div className="text-sm flex-1 flex items-center">
<AiIconAnimation size={20} allowHoverEffect={false} />
<span className="text-border-stronger dark:text-border-strong ml-3">
<svg
viewBox="0 0 24 24"
width="16"
height="16"
stroke="currentColor"
strokeWidth="1"
strokeLinecap="round"
strokeLinejoin="round"
fill="none"
shapeRendering="geometricPrecision"
>
<path d="M16 3.549L7.12 20.600" />
</svg>
</span>
<AIAssistantChatSelector />
</div>
<div className="flex items-center gap-x-4">
<div className="flex items-center">
<ButtonTooltip
type="text"
size="tiny"
icon={<Plus strokeWidth={1.5} />}
onClick={onNewChat}
className="h-7 w-7 p-0"
tooltip={{ content: { side: 'bottom', text: 'New chat' } }}
/>
<ButtonTooltip
type="text"
size="tiny"
icon={<Settings strokeWidth={1.5} />}
onClick={() => setIsOptInModalOpen(true)}
className="h-7 w-7 p-0"
disabled={isChatLoading}
tooltip={{
content: { side: 'bottom', text: 'Permission settings' },
}}
/>
<DropdownMenu>
<DropdownMenuTrigger asChild>
<ButtonTooltip
type="text"
size="tiny"
icon={<Ellipsis strokeWidth={1.5} />}
className="h-7 w-7 p-0"
tooltip={{ content: { side: 'bottom', text: 'More options' } }}
/>
</DropdownMenuTrigger>
<DropdownMenuContent align="end">
<DropdownMenuItem
className="gap-x-2"
onClick={() => copyToClipboard(snap.activeChatId ?? '')}
>
<Clipboard size={14} strokeWidth={1.5} />
<span>Copy chat ID</span>
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
<ButtonTooltip
type="text"
className="w-7 h-7"
onClick={onCloseAssistant}
icon={<X strokeWidth={1.5} />}
tooltip={{ content: { side: 'bottom', text: 'Close assistant' } }}
/>
</div>
</div>
</div>
{showMetadataWarning && (
<Admonition
type="default"
title={
!updatedOptInSinceMCP
? 'The Assistant has just been updated to help you better!'
: isHipaaProjectDisallowed
? 'Project metadata is not shared due to HIPAA'
: aiOptInLevel === 'disabled'
? 'Project metadata is currently not shared'
: 'Limited metadata is shared to the Assistant'
}
description={
!updatedOptInSinceMCP
? 'You may now opt-in to share schema metadata and even logs for better results'
: isHipaaProjectDisallowed
? 'Your organization has the HIPAA addon and will not send project metadata with your prompts for projects marked as HIPAA.'
: aiOptInLevel === 'disabled'
? 'The Assistant can provide better answers if you opt-in to share schema metadata.'
: aiOptInLevel === 'schema'
? 'Sharing query data in addition to schema can further improve responses. Update AI settings to enable this.'
: ''
}
className="border-0 border-b rounded-none bg-background"
>
{!isHipaaProjectDisallowed && (
<Button type="default" className="w-fit mt-4" onClick={() => setIsOptInModalOpen(true)}>
Permission settings
</Button>
)}
</Admonition>
)}
<AIOptInModal visible={isOptInModalOpen} onCancel={() => setIsOptInModalOpen(false)} />
</div>
)
}