Skip to content

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

Add org level opt-in

Terry Suttonab7992bc5c22
diff --git a/packages/ui/src/components/Command/CommandMenuProvider.tsx b/packages/ui/src/components/Command/CommandMenuProvider.tsx
index 3024ee15991..8787b032695 100644
--- a/packages/ui/src/components/Command/CommandMenuProvider.tsx
+++ b/packages/ui/src/components/Command/CommandMenuProvider.tsx
@@ -50,6 +50,7 @@ export interface CommandMenuProviderProps {
// this is a temporary hack as ReactMarkdown fails our jest tests if we import the package within this UI package
MarkdownHandler: (props: ReactMarkdownOptions) => JSX.Element
onSaveGeneratedSQL?: (answer: string, resolve: any) => void
+ isOptedInToAI: boolean
}
const CommandMenuProvider = ({
@@ -59,6 +60,7 @@ const CommandMenuProvider = ({
apiKeys,
MarkdownHandler,
onSaveGeneratedSQL,
+ isOptedInToAI,
}: PropsWithChildren<CommandMenuProviderProps>) => {
const [isOpen, setIsOpen] = useState(false)
const [isLoading, setIsLoading] = useState(false)
@@ -71,7 +73,7 @@ const CommandMenuProvider = ({
const project = projectRef !== undefined ? { ref: projectRef, apiKeys } : undefined
useKeyboardEvents({ setIsOpen, currentPage, setSearch, setPages })
-
+ console.log('org opted in to OpenAI?', isOptedInToAI ? 'true' : 'false')
return (
<CommandMenuContext.Provider
value={{
diff --git a/packages/ui/src/components/Command/GenerateSQL.tsx b/packages/ui/src/components/Command/GenerateSQL.tsx
index e63f8cf8a96..48b4d3d0232 100644
--- a/packages/ui/src/components/Command/GenerateSQL.tsx
+++ b/packages/ui/src/components/Command/GenerateSQL.tsx
@@ -307,47 +307,55 @@ Postgres SQL query:
)
})}
{promptData.length === 0 && !hasClippyError && (
- <div className="flex">
- <div className="w-1/3 py-4 px-6">
- <ul className="space-y-2 mr-8">
- {SAMPLE_QUERIES.map((item, index) => (
- <li
- key={index}
- onClick={() => setSelectedCategory(item.category)}
- className={cn(
- 'px-4 py-1 cursor-pointer text-sm hover:bg-slate-300 rounded-md',
- selectedCategory === item.category && 'bg-slate-400 '
- )}
- >
- {item.category}
- </li>
- ))}
- </ul>
+ <div>
+ <div className="px-10">
+ <h3>Example queries</h3>
+ <p className="text-sm mt-1">
+ Use these example queries to help get your project started quickly.
+ </p>
</div>
- <div className="w-2/3 py-4 px-6">
- <ul>
- {SAMPLE_QUERIES.find((item) => item.category === selectedCategory)?.queries.map(
- (query, index) => (
- <CommandItem
- type="command"
- onSelect={() => {
- if (!search) {
- handleConfirm(query)
- }
- }}
- forceMount
- key={query.replace(/\s+/g, '_')}
+ <div className="flex mt-4 border-t pt-4">
+ <div className="w-1/3 py-4 px-6">
+ <ul className="space-y-2 mr-8">
+ {SAMPLE_QUERIES.map((item, index) => (
+ <li
+ key={index}
+ onClick={() => setSelectedCategory(item.category)}
+ className={cn(
+ 'px-4 py-1 cursor-pointer text-sm hover:bg-slate-300 rounded-md',
+ selectedCategory === item.category && 'bg-slate-400 '
+ )}
>
- <div className="flex">
- <div>
- <AiIcon />
+ {item.category}
+ </li>
+ ))}
+ </ul>
+ </div>
+ <div className="w-2/3 py-4 px-6">
+ <ul>
+ {SAMPLE_QUERIES.find((item) => item.category === selectedCategory)?.queries.map(
+ (query, index) => (
+ <CommandItem
+ type="command"
+ onSelect={() => {
+ if (!search) {
+ handleConfirm(query)
+ }
+ }}
+ forceMount
+ key={query.replace(/\s+/g, '_')}
+ >
+ <div className="flex">
+ <div>
+ <AiIcon />
+ </div>
+ <p>{query}</p>
</div>
- <p>{query}</p>
- </div>
- </CommandItem>
- )
- )}
- </ul>
+ </CommandItem>
+ )
+ )}
+ </ul>
+ </div>
</div>
</div>
)}
diff --git a/studio/components/interfaces/App/CommandMenuWrapper.tsx b/studio/components/interfaces/App/CommandMenuWrapper.tsx
index e4038a72b49..718710ce474 100644
--- a/studio/components/interfaces/App/CommandMenuWrapper.tsx
+++ b/studio/components/interfaces/App/CommandMenuWrapper.tsx
@@ -12,7 +12,11 @@ import { useProjectApiQuery } from 'data/config/project-api-query'
const CommandMenuWrapper = ({ children }: PropsWithChildren<{}>) => {
const { ref } = useParams()
- const { content } = useStore()
+ const { content, ui } = useStore()
+
+ const { opt_in_tags } = ui.selectedOrganization ?? {}
+
+ const isOptedInToAI = opt_in_tags?.includes('AI_SQL_GENERATOR_OPT_IN') ?? false
const { data: profile } = useProfileQuery()
const { data: settings } = useProjectApiQuery({ projectRef: ref })
@@ -56,6 +60,7 @@ ${answer}
apiKeys={apiKeys}
MarkdownHandler={(props) => <ReactMarkdown remarkPlugins={[remarkGfm]} {...props} />}
onSaveGeneratedSQL={onSaveGeneratedSQL}
+ isOptedInToAI={isOptedInToAI}
>
{children}
</CommandMenuProvider>
diff --git a/studio/components/interfaces/Organization/GeneralSettings/GeneralSettings.tsx b/studio/components/interfaces/Organization/GeneralSettings/GeneralSettings.tsx
index 848b15c8227..268bd071836 100644
--- a/studio/components/interfaces/Organization/GeneralSettings/GeneralSettings.tsx
+++ b/studio/components/interfaces/Organization/GeneralSettings/GeneralSettings.tsx
@@ -1,6 +1,6 @@
-import { useEffect } from 'react'
+import { useEffect, useState } from 'react'
import { observer } from 'mobx-react-lite'
-import { Form, Input } from 'ui'
+import { Form, Input, Toggle } from 'ui'
import { PermissionAction } from '@supabase/shared-types/out/constants'
import { useStore, checkPermissions } from 'hooks'
@@ -20,9 +20,24 @@ import {
const GeneralSettings = () => {
const { app, ui } = useStore()
const { slug } = useParams()
+ const { name, opt_in_tags } = ui.selectedOrganization ?? {}
+
+ const [optIn, setOptIn] = useState(
+ opt_in_tags?.includes('AI_SQL_GENERATOR_OPT_IN') ? true : false
+ )
+ const isOptedInToAI = opt_in_tags?.includes('AI_SQL_GENERATOR_OPT_IN')
+
+ useEffect(() => {
+ setOptIn(isOptedInToAI ? true : false)
+ }, [opt_in_tags])
const formId = 'org-general-settings'
- const initialValues = { name: ui.selectedOrganization?.name ?? '' }
+
+ const initialValues = {
+ name: name ?? '',
+ opt_in_tags: optIn,
+ }
+
const canUpdateOrganization = checkPermissions(PermissionAction.UPDATE, 'organizations')
const canDeleteOrganization = checkPermissions(PermissionAction.UPDATE, 'organizations')
@@ -38,6 +53,9 @@ const GeneralSettings = () => {
const response = await patch(`${API_URL}/organizations/${slug}`, {
...values,
+ opt_in_tags: optIn
+ ? [...(ui.selectedOrganization?.opt_in_tags ?? []), 'AI_SQL_GENERATOR_OPT_IN']
+ : [],
billing_email: ui.selectedOrganization?.billing_email ?? '',
})
@@ -47,10 +65,10 @@ const GeneralSettings = () => {
message: `Failed to update organization: ${response.error.message}`,
})
} else {
- const { name } = response
+ const { name, opt_in_tags } = response
resetForm({
- values: { name },
- initialValues: { name },
+ values: { name, opt_in_tags },
+ initialValues: { name, opt_in_tags },
})
app.onOrgUpdated(response)
@@ -69,7 +87,10 @@ const GeneralSettings = () => {
const hasChanges = JSON.stringify(values) !== JSON.stringify(initialValues)
useEffect(() => {
- const values = { name: ui.selectedOrganization?.name ?? '' }
+ const values = {
+ name: name ?? '',
+ opt_in_tags: isOptedInToAI ?? false,
+ }
resetForm({ values, initialValues: values })
}, [ui.selectedOrganization?.slug])
@@ -91,9 +112,21 @@ const GeneralSettings = () => {
</div>
}
>
- <FormSection header={<FormSectionLabel>Organization name</FormSectionLabel>}>
+ <FormSection header={<FormSectionLabel>General settings</FormSectionLabel>}>
<FormSectionContent loading={false}>
+ <label htmlFor="name">Organization name</label>
<Input id="name" size="small" disabled={!canUpdateOrganization} />
+
+ <Toggle
+ checked={isOptedInToAI}
+ id="opt_in_tags"
+ name="opt_in_tags"
+ disabled={!canUpdateOrganization}
+ size="small"
+ onChange={() => setOptIn(!optIn)}
+ label="Opt-in to sending anonymous data to OpenAI"
+ descriptionText="You can choose to share anonymous metadata with OpenAI to enhance your experience on Supabase anywhere we use AI. Only information such as table schemas with table names, column names, and data types will be shared. None of your actual table data will be sent to OpenAI."
+ />
</FormSectionContent>
</FormSection>
</FormPanel>
diff --git a/studio/types/base.ts b/studio/types/base.ts
index 83a36b88918..5d431f46dd8 100644
--- a/studio/types/base.ts
+++ b/studio/types/base.ts
@@ -8,6 +8,7 @@ export interface Organization {
billing_email: string
is_owner?: boolean
stripe_customer_id?: string
+ opt_in_tags: string[]
}
export interface ProjectBase {