Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

feat(cmdk): ai disclaimer

Greg Richardsona97b185fc160
diff --git a/packages/ui/src/components/Command/AiCommand.tsx b/packages/ui/src/components/Command/AiCommand.tsx
index 5e816dd7d53..503f3167e58 100644
--- a/packages/ui/src/components/Command/AiCommand.tsx
+++ b/packages/ui/src/components/Command/AiCommand.tsx
@@ -336,6 +336,17 @@ export function queryAi(messages: Message[], timeout = 0) {
})
}
+export const AiWarning = () => (
+ <div className="mx-4 p-6 flex flex-row items-center gap-2 border rounded-lg text-left text-xs text-scale-1100 border-scale-500 bg-white dark:bg-scale-300">
+ <div className="flex flex-row items-center gap-2 text-xs text-amber-900">
+ <IconAlertTriangle strokeWidth={1.5} size={18} />
+ <strong>Warning</strong>
+ </div>{' '}
+ Supabase AI is experimental and may produce incorrect answers. Always verify the output before
+ executing.
+ </div>
+)
+
const AiCommand = () => {
const { isLoading, setIsLoading, search, setSearch, MarkdownHandler } = useCommandMenu()
@@ -364,7 +375,7 @@ const AiCommand = () => {
return (
<div onClick={(e) => e.stopPropagation()}>
- <div className={cn('relative mb-[62px] py-4 max-h-[720px] overflow-auto')}>
+ <div className={cn('relative mb-[140px] py-4 max-h-[720px] overflow-auto')}>
{messages.map((message, index) => {
switch (message.role) {
case MessageRole.User:
@@ -454,6 +465,11 @@ const AiCommand = () => {
<div className="[overflow-anchor:auto] h-px w-full"></div>
</div>
<div className="absolute bottom-0 w-full bg-scale-200 py-3">
+ {messages.length > 0 && !hasError && (
+ <div className="mb-4">
+ <AiWarning />
+ </div>
+ )}
<Input
className="bg-scale-100 rounded mx-3"
autoFocus
diff --git a/packages/ui/src/components/Command/Command.utils.tsx b/packages/ui/src/components/Command/Command.utils.tsx
index 6c3fc617479..c9b2c14b23e 100644
--- a/packages/ui/src/components/Command/Command.utils.tsx
+++ b/packages/ui/src/components/Command/Command.utils.tsx
@@ -180,10 +180,11 @@ type CommandPrimitiveItemProps = React.ComponentPropsWithoutRef<typeof CommandPr
export interface CommandItemProps extends CommandPrimitiveItemProps {
type: 'link' | 'block-link' | 'command'
+ badge?: string
}
export const CommandItem = React.forwardRef<CommandPrimitiveItemElement, CommandItemProps>(
- ({ className, type, ...props }, ref) => (
+ ({ className, type, children, badge, ...props }, ref) => (
<CommandPrimitive.Item
ref={ref}
className={cn(
@@ -238,7 +239,16 @@ export const CommandItem = React.forwardRef<CommandPrimitiveItemElement, Command
className
)}
{...props}
- />
+ >
+ <div className="w-full flex flex-row justify-between items-center">
+ <div className="flex flex-row items-center">{children}</div>
+ {badge && (
+ <span className="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-opacity-10 bg-brand-200 text-brand-1100 border border-brand-700">
+ {badge}
+ </span>
+ )}
+ </div>
+ </CommandPrimitive.Item>
)
)
diff --git a/packages/ui/src/components/Command/CommandMenu.tsx b/packages/ui/src/components/Command/CommandMenu.tsx
index ccbc505b73f..5a133b40668 100644
--- a/packages/ui/src/components/Command/CommandMenu.tsx
+++ b/packages/ui/src/components/Command/CommandMenu.tsx
@@ -91,6 +91,7 @@ const CommandMenu = ({ projectRef }: CommandMenuProps) => {
<CommandGroup heading="Documentation" forceMount>
<CommandItem
type="command"
+ badge="Experimental"
onSelect={() => {
setPages([...pages, COMMAND_ROUTES.AI])
}}
@@ -174,6 +175,7 @@ const CommandMenu = ({ projectRef }: CommandMenuProps) => {
<CommandItem
forceMount
type="command"
+ badge="Experimental"
onSelect={() => setPages([...pages, COMMAND_ROUTES.GENERATE_SQL])}
>
<AiIcon className="text-scale-1100" />
diff --git a/packages/ui/src/components/Command/CommandMenuShortcuts.tsx b/packages/ui/src/components/Command/CommandMenuShortcuts.tsx
index f5f0e72bf18..08ff299d7fe 100644
--- a/packages/ui/src/components/Command/CommandMenuShortcuts.tsx
+++ b/packages/ui/src/components/Command/CommandMenuShortcuts.tsx
@@ -3,6 +3,7 @@ import { IconArrowLeft } from '../Icon/icons/IconArrowLeft'
import { CommandShortcut } from './Command.utils'
import { useCommandMenu } from './CommandMenuProvider'
+import { COMMAND_ROUTES } from './Command.constants'
export default function CommandMenuShortcuts() {
const { setPages, pages, currentPage } = useCommandMenu()
@@ -29,6 +30,26 @@ export default function CommandMenuShortcuts() {
{page}
</CommandShortcut>
))}
+
+ {currentPage && isExperimental(currentPage) && (
+ <span className="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-opacity-10 bg-brand-200 text-brand-1100 border border-brand-700">
+ Experimental
+ </span>
+ )}
</div>
)
}
+
+/**
+ * TODO: remove this function and store this info on each page
+ * Temporary function to determine whether or not to show 'Experimental' badge
+ */
+function isExperimental(page: string) {
+ switch (page) {
+ case COMMAND_ROUTES.AI:
+ case COMMAND_ROUTES.GENERATE_SQL:
+ return true
+ default:
+ return false
+ }
+}
diff --git a/packages/ui/src/components/Command/GenerateSQL/GenerateSQL.tsx b/packages/ui/src/components/Command/GenerateSQL/GenerateSQL.tsx
index bd018484210..ebf4244f9c1 100644
--- a/packages/ui/src/components/Command/GenerateSQL/GenerateSQL.tsx
+++ b/packages/ui/src/components/Command/GenerateSQL/GenerateSQL.tsx
@@ -11,6 +11,7 @@ import {
MessageRole,
MessageStatus,
useAiChat,
+ AiWarning,
} from 'ui'
import { cn } from '../../../utils/cn'
@@ -84,7 +85,7 @@ const GenerateSQL = () => {
<div
className={cn(
'relative py-4 max-h-[550px] overflow-auto',
- allowSendingSchemaMetadata ? 'mb-[83px]' : 'mb-[42px]'
+ allowSendingSchemaMetadata ? 'mb-[255px]' : 'mb-[150px]'
)}
>
{messages.map((message, i) => {
@@ -116,7 +117,8 @@ const GenerateSQL = () => {
message.status === MessageStatus.Complete
? formatAnswer(unformattedAnswer)
: unformattedAnswer
- const cantHelp = answer === "Sorry, I don't know how to help with that."
+ const cantHelp =
+ answer.replace(/^-- /, '') === "Sorry, I don't know how to help with that."
return (
<div className="px-4 [overflow-anchor:none] mb-6">
@@ -235,9 +237,14 @@ const GenerateSQL = () => {
<div className="[overflow-anchor:auto] h-px w-full"></div>
</div>
- <div className="absolute bottom-0 w-full bg-scale-200 py-3">
+ <div className="absolute bottom-0 w-full bg-scale-200 pt-4">
+ {messages.length > 0 && !hasError && (
+ <div className="mb-4">
+ <AiWarning />
+ </div>
+ )}
{allowSendingSchemaMetadata && (
- <>
+ <div className="mb-4">
{messages.length === 0 ? (
<div className="flex items-center justify-between px-6 py-3">
<div>
@@ -262,24 +269,20 @@ const GenerateSQL = () => {
/>
</div>
) : (
- <div className="flex items-center justify-between px-6 py-3">
- <div>
- <p className="text-sm">
- Table names, column names and their corresponding data types{' '}
- <span
- className={cn(includeSchemaMetadata ? 'text-brand-900' : 'text-amber-900')}
- >
- {includeSchemaMetadata ? 'are' : 'are not'} included
- </span>{' '}
- in this conversation
- </p>
- <p className="text-sm text-scale-1100">
- Start a new conversation to change this configuration
- </p>
- </div>
+ <div className="mx-4 p-6 flex flex-col items-start gap-2 mt-4 border rounded-lg text-left text-xs text-scale-1100 border-scale-500 bg-white dark:bg-scale-300">
+ <p>
+ Table names, column names and their corresponding data types{' '}
+ <span className={cn(includeSchemaMetadata ? 'text-brand-900' : 'text-amber-900')}>
+ {includeSchemaMetadata ? 'are' : 'are not'} included
+ </span>{' '}
+ in this conversation
+ </p>
+ <p className="text-scale-1000">
+ Start a new conversation to change this configuration
+ </p>
</div>
)}
- </>
+ </div>
)}
<Input
inputRef={(inputElement) => {
@@ -291,7 +294,7 @@ const GenerateSQL = () => {
}, 0)
}
}}
- className="bg-scale-100 rounded mx-3"
+ className="bg-scale-100 rounded mx-3 mb-4"
autoFocus
placeholder={
isLoading || isResponding
diff --git a/studio/components/interfaces/App/CommandMenuWrapper.tsx b/studio/components/interfaces/App/CommandMenuWrapper.tsx
index 2e0544dbc1c..8e5d2458233 100644
--- a/studio/components/interfaces/App/CommandMenuWrapper.tsx
+++ b/studio/components/interfaces/App/CommandMenuWrapper.tsx
@@ -2,7 +2,7 @@ import remarkGfm from 'remark-gfm'
import ReactMarkdown from 'react-markdown'
import { PropsWithChildren, useMemo } from 'react'
import { useParams } from 'common'
-import { CommandMenuProvider } from 'ui'
+import { CommandMenuProvider, markdownComponents } from 'ui'
import { observer } from 'mobx-react-lite'
import { PermissionAction } from '@supabase/shared-types/out/constants'
@@ -98,7 +98,9 @@ const CommandMenuWrapper = observer(({ children }: PropsWithChildren<{}>) => {
site="studio"
projectRef={ref}
apiKeys={apiKeys}
- MarkdownHandler={(props) => <ReactMarkdown remarkPlugins={[remarkGfm]} {...props} />}
+ MarkdownHandler={(props) => (
+ <ReactMarkdown remarkPlugins={[remarkGfm]} components={markdownComponents} {...props} />
+ )}
metadata={cmdkMetadata}
isOptedInToAI={allowCMDKDataOptIn && isOptedInToAI}
saveGeneratedSQL={onSaveGeneratedSQL}