Files
supabase/apps/studio/components/ui/AIAssistantPanel/AIAssistantHeader.tsx
Matt RossmanandJoshen Lim 4bb36b944f feat(studio): let High Compliance projects opt-in to Assistant data access (#50548)
Orgs with the HIPAA add-on had the Assistant's opt-in level forced to
`disabled` on any project marked High Compliance, regardless of what the
org picked in its AI settings. The restriction predated our AI provider
BAAs. The consequence is those users see the Assistant failing to answer
questions about their data w/ no clear path how to fix it, even though
the LLM provider supports this use case.

This PR removes these Assistant restrictions on the server and client so
those projects honor the org's chosen level. Braintrust conversation
tracing is unchanged and still blocked for these projects, see [this
test
case](https://github.com/supabase/supabase/blob/b9800ccf16/apps/studio/lib/ai/braintrust-logger.test.ts#L16-L20).
See
[comments](https://linear.app/supabase/issue/AI-1153/allow-hipaa-orgs-to-opt-in-to-assistant-data-access-for-high#comment-485a0d46)
for legal approval and conditions.

The client-side changes enable features like "Debug with AI" on SQL
query failures, “Generate/Rename with AI” for snippet titles, and
generated Assistant chat titles for these customers.

The AI opt-in copy now adds a reminder to obtain consent from data
subjects, linking the [shared responsibility
model](https://supabase.com/docs/guides/deployment/shared-responsibility-model)
based also on [this
comment](https://linear.app/supabase/issue/AI-1153/allow-hipaa-orgs-to-opt-in-to-assistant-data-access-for-high#comment-f81ee610).

<img width="400" alt="CleanShot 2026-09-17 at 5 01 02 PM@2x"
src="https://github.com/user-attachments/assets/d02123f2-3e32-4d83-9f98-7d15e59222ef"
/>

To test with a HIPAA-enabled project in staging, you can use this [Plan
Change
[Staging]](https://app.hex.tech/supabase/app/Plan-Change-Staging-032BD32jo1EaisCS85qunf/latest)
Hex to add the HIPAA add-on. Once the add-on is present, you can turn on
High Compliance from a project's settings. Also in org settings, crank
up the Assistant data opt-in level and verify the Assistant is able to
answer questions about the project's data.

My results testing with opt-in level "Schema, Logs & Database Data":

| High compliance setting | Data opt-in working |
|--------|--------|
| <img width="1302" height="422" alt="CleanShot 2026-09-17 at 5 03 36
PM@2x"
src="https://github.com/user-attachments/assets/c416371b-2eb8-49df-9c07-6d8eababb443"
/> | <img width="1566" height="1516" alt="CleanShot 2026-09-17 at 5 05
14 PM@2x"
src="https://github.com/user-attachments/assets/39624355-7f8f-46ce-9f08-a8acfb9da830"
/> |

Closes AI-1153


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

## New Features

- AI-assisted query renaming, snippet title generation, debugging, and
tools now follow organization AI opt-in settings rather than project
HIPAA status.
- Debugging assistance and AI actions remain available for eligible
users without additional HIPAA-based blocking.
- AI metadata warnings consistently show standard opt-in messaging and
permission settings.
- AI settings remind users to obtain consent before entering personal
data and link to shared responsibility guidance.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
2026-09-18 08:21:50 -04:00

250 lines
7.8 KiB
TypeScript

import {
Clipboard,
Edit,
Maximize,
MessageCirclePlus,
MoreVertical,
Settings,
X,
} from 'lucide-react'
import { KeyboardEvent, useState } from 'react'
import { toast } from 'sonner'
import {
Button,
cn,
copyToClipboard,
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuSeparator,
DropdownMenuTrigger,
Input,
} from 'ui'
import { ButtonTooltip } from '../ButtonTooltip'
import { ShortcutPills, ShortcutTooltip } from '../ShortcutTooltip'
import { AIAssistantChatSelector } from './AIAssistantChatSelector'
import { AIAssistantMetadataWarning } from './AIAssistantMetadataWarning'
import { useIsExplorerEnabled } from '@/components/interfaces/App/FeaturePreview/FeaturePreviewContext'
import { useCreateChat } from '@/components/interfaces/Explorer/hooks'
import { useAiAssistantStateSnapshot } from '@/state/ai-assistant-state'
import { SHORTCUT_DEFINITIONS, SHORTCUT_IDS } from '@/state/shortcuts/registry'
import { useShortcut } from '@/state/shortcuts/useShortcut'
import { useSidebarManagerSnapshot } from '@/state/sidebar-manager-state'
interface AIAssistantHeaderProps {
isChatLoading: boolean
shortcutsEnabled?: boolean
onNewChat: () => void
onCloseAssistant: () => void
showMetadataWarning: boolean
updatedOptInSinceMCP: boolean
aiOptInLevel: 'disabled' | 'schema' | 'full' | string | undefined
}
export const AIAssistantHeader = ({
isChatLoading,
shortcutsEnabled = true,
onNewChat,
onCloseAssistant,
showMetadataWarning,
updatedOptInSinceMCP,
aiOptInLevel,
}: AIAssistantHeaderProps) => {
const { openChat } = useCreateChat()
const snap = useAiAssistantStateSnapshot()
const { isMaximised, toggleMaximise } = useSidebarManagerSnapshot()
const isExplorerEnabled = useIsExplorerEnabled()
const [value, setValue] = useState(snap.activeChat?.name)
const [isEditingName, setIsEditingName] = useState(false)
const [isOptInModalOpen, setIsOptInModalOpen] = useState(false)
const maximiseLabel = isExplorerEnabled
? 'Open in Explorer'
: isMaximised
? 'Minimize'
: 'Maximize'
const onSelectMaximise = () => {
if (isExplorerEnabled) handleOpenInExplorer()
else toggleMaximise()
}
const handleOpenInExplorer = () => {
if (!snap.activeChatId) return
openChat(snap.activeChatId)
onCloseAssistant()
}
const handleCopyChatId = () => {
copyToClipboard(snap.activeChatId ?? '', () => {
toast.success(`Copied chat ID for ${snap.activeChat?.name}`)
})
}
const handleSaveName = () => {
if (snap.activeChatId && value?.trim()) {
snap.renameChat(snap.activeChatId, value.trim())
}
setIsEditingName(false)
}
const handleKeyDownInput = (e: KeyboardEvent<HTMLInputElement>) => {
if (e.key === 'Escape') {
e.preventDefault()
e.stopPropagation()
setIsEditingName(false)
setValue(snap.activeChat?.name)
} else if (e.key === 'Enter') {
e.preventDefault()
e.stopPropagation()
handleSaveName()
}
}
const handleBlurInput = () => {
if (isEditingName) handleSaveName()
}
useShortcut(SHORTCUT_IDS.AI_ASSISTANT_COPY_CHAT_ID, handleCopyChatId, {
enabled: shortcutsEnabled && !isChatLoading,
})
useShortcut(SHORTCUT_IDS.AI_ASSISTANT_OPEN_PERMISSIONS, () => setIsOptInModalOpen(true), {
enabled: shortcutsEnabled && !isChatLoading,
})
useShortcut(SHORTCUT_IDS.AI_ASSISTANT_MAXIMIZE, onSelectMaximise, {
enabled: shortcutsEnabled && !isChatLoading,
})
return (
<div className="z-30 sticky top-0">
<div className="border-b border-b-muted flex items-center bg-card gap-x-4 px-3 min-h-(--header-height)">
<div className="text-sm flex-1 min-w-0 flex items-center gap-x-1">
{isEditingName ? (
<Input
autoFocus
value={value}
size="tiny"
onChange={(e) => setValue(e.target.value)}
onKeyDown={handleKeyDownInput}
onBlur={handleBlurInput}
/>
) : (
<Button
variant="text"
className="group min-w-0"
iconRight={<Edit className="transition opacity-0 group-hover:opacity-100" />}
onClick={() => {
setValue(snap.activeChat?.name)
setIsEditingName(true)
}}
>
{snap.activeChat?.name}
</Button>
)}
</div>
<div className="flex items-center gap-x-4 shrink-0">
<div className="flex items-center">
<AIAssistantChatSelector shortcutsEnabled={shortcutsEnabled} />
<ShortcutTooltip
side="bottom"
label="New chat"
shortcutId={SHORTCUT_IDS.AI_ASSISTANT_NEW_CHAT}
>
<Button
variant="text"
aria-label="New chat"
size="tiny"
icon={<MessageCirclePlus />}
onClick={onNewChat}
className="h-7 w-7 p-0"
/>
</ShortcutTooltip>
<ShortcutTooltip
side="bottom"
label={maximiseLabel}
shortcutId={SHORTCUT_IDS.AI_ASSISTANT_MAXIMIZE}
>
<Button
variant="text"
aria-label={maximiseLabel}
size="tiny"
icon={<Maximize />}
onClick={onSelectMaximise}
className={cn('h-7 w-7 p-0', !isExplorerEnabled && 'hidden md:flex')}
/>
</ShortcutTooltip>
<DropdownMenu>
<DropdownMenuTrigger asChild>
<ButtonTooltip
variant="text"
size="tiny"
icon={<MoreVertical />}
className="h-7 w-7 p-0"
disabled={isChatLoading}
tooltip={{ content: { side: 'bottom', text: 'More options' } }}
/>
</DropdownMenuTrigger>
<DropdownMenuContent align="end" className="w-60">
<DropdownMenuItem className="justify-between" onClick={handleCopyChatId}>
<div className="flex items-center gap-x-2">
<Clipboard size={14} />
<span>Copy chat ID</span>
</div>
<ShortcutPills
sequence={SHORTCUT_DEFINITIONS[SHORTCUT_IDS.AI_ASSISTANT_COPY_CHAT_ID].sequence}
/>
</DropdownMenuItem>
<DropdownMenuSeparator />
<DropdownMenuItem
className="justify-between"
onClick={() => setIsOptInModalOpen(true)}
>
<div className="flex items-center gap-x-2">
<Settings size={14} />
<span>Permission settings</span>
</div>
<ShortcutPills
sequence={
SHORTCUT_DEFINITIONS[SHORTCUT_IDS.AI_ASSISTANT_OPEN_PERMISSIONS].sequence
}
/>
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
<ShortcutTooltip
side="bottom"
label="Close assistant"
shortcutId={SHORTCUT_IDS.AI_ASSISTANT_TOGGLE}
>
<Button
aria-label="Close Assistant"
variant="text"
className="w-7 h-7"
onClick={onCloseAssistant}
icon={<X strokeWidth={1.5} />}
/>
</ShortcutTooltip>
</div>
</div>
</div>
<AIAssistantMetadataWarning
visible={isOptInModalOpen}
onVisibleChange={setIsOptInModalOpen}
showMetadataWarning={showMetadataWarning}
updatedOptInSinceMCP={updatedOptInSinceMCP}
aiOptInLevel={aiOptInLevel}
/>
</div>
)
}