Skip to content

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

Feature flag supabase ai

Terry Sutton12cf13087a66
diff --git a/studio/components/interfaces/SQLEditor/RenameQueryModal.tsx b/studio/components/interfaces/SQLEditor/RenameQueryModal.tsx
index dedeab15a13..a9fe92e021a 100644
--- a/studio/components/interfaces/SQLEditor/RenameQueryModal.tsx
+++ b/studio/components/interfaces/SQLEditor/RenameQueryModal.tsx
@@ -2,10 +2,10 @@ import { useParams } from 'common'
import { useSqlTitleGenerateMutation } from 'data/ai/sql-title-mutation'
import { SqlSnippet } from 'data/content/sql-snippets-query'
-import { useStore } from 'hooks'
+import { useStore, useFlag } from 'hooks'
import { useState } from 'react'
import { useSqlEditorStateSnapshot } from 'state/sql-editor'
-import { AiIconAnimation, Button, Form, IconLoader, Input, Modal, cn } from 'ui'
+import { AiIconAnimation, Button, Form, Input, Modal } from 'ui'
export interface RenameQueryModalProps {
snippet: SqlSnippet
@@ -18,6 +18,7 @@ const RenameQueryModal = ({ snippet, visible, onCancel, onComplete }: RenameQuer
const { ui } = useStore()
const { ref } = useParams()
const snap = useSqlEditorStateSnapshot()
+ const supabaseAIEnabled = useFlag('sqlEditorSupabaseAI')
const { id, name, description } = snippet
@@ -94,10 +95,12 @@ const RenameQueryModal = ({ snippet, visible, onCancel, onComplete }: RenameQuer
disabled={isTitleGenerationLoading}
// className="!px-2 !py-0.5 !pr-3"
>
- <div className="flex items-center gap-1">
- <AiIconAnimation loading={isTitleGenerationLoading} className="scale-75" />
- <span>Rename with AI</span>
- </div>
+ {supabaseAIEnabled && (
+ <div className="flex items-center gap-1">
+ <AiIconAnimation loading={isTitleGenerationLoading} className="scale-75" />
+ <span>Rename with AI</span>
+ </div>
+ )}
</Button>
)}
</div>
diff --git a/studio/components/interfaces/SQLEditor/SQLEditor.tsx b/studio/components/interfaces/SQLEditor/SQLEditor.tsx
index ab92f9cfd44..36243ac34e2 100644
--- a/studio/components/interfaces/SQLEditor/SQLEditor.tsx
+++ b/studio/components/interfaces/SQLEditor/SQLEditor.tsx
@@ -32,6 +32,7 @@ import {
useSelectedOrganization,
useSelectedProject,
useStore,
+ useFlag,
} from 'hooks'
import { IS_PLATFORM } from 'lib/constants'
import { uuidv4 } from 'lib/helpers'
@@ -102,6 +103,7 @@ const SQLEditor = () => {
const [debugSolution, setDebugSolution] = useState<string>()
const [sqlDiff, setSqlDiff] = useState<ContentDiff>()
const inputRef = useRef<HTMLInputElement>(null)
+ const supabaseAIEnabled = useFlag('sqlEditorSupabaseAI')
const [isAiOpen, setIsAiOpen] = useLocalStorageQuery('supabase_sql-editor-ai-open', true)
@@ -421,7 +423,7 @@ const SQLEditor = () => {
}}
/>
<div className="flex h-full flex-col relative">
- {isAiOpen && (
+ {isAiOpen && supabaseAIEnabled && (
<AISchemaSuggestionPopover
onClickSettings={() => {
setIsAISettingsOpen(true)
diff --git a/studio/components/interfaces/SQLEditor/UtilityPanel/UtilityTabResults.tsx b/studio/components/interfaces/SQLEditor/UtilityPanel/UtilityTabResults.tsx
index 649dd0c040b..ee5200e87b5 100644
--- a/studio/components/interfaces/SQLEditor/UtilityPanel/UtilityTabResults.tsx
+++ b/studio/components/interfaces/SQLEditor/UtilityPanel/UtilityTabResults.tsx
@@ -1,7 +1,13 @@
import { useSqlDebugMutation } from 'data/ai/sql-debug-mutation'
import { useEntityDefinitionsQuery } from 'data/database/entity-definitions-query'
import { isError } from 'data/utils/error-check'
-import { useLocalStorageQuery, useSelectedOrganization, useSelectedProject, useStore } from 'hooks'
+import {
+ useLocalStorageQuery,
+ useSelectedOrganization,
+ useSelectedProject,
+ useStore,
+ useFlag,
+} from 'hooks'
import { IS_PLATFORM } from 'lib/constants'
import { format } from 'sql-formatter'
import { useSqlEditorStateSnapshot } from 'state/sql-editor'
@@ -41,6 +47,7 @@ const UtilityTabResults = ({ id, isExecuting }: UtilityTabResultsProps) => {
const snippet = snap.snippets[id]
const result = snap.results[id]?.[0]
const isUtilityPanelCollapsed = (snippet?.splitSizes?.[1] ?? 0) === 0
+ const supabaseAIEnabled = useFlag('sqlEditorSupabaseAI')
if (isUtilityPanelCollapsed) return null
@@ -55,46 +62,48 @@ const UtilityTabResults = ({ id, isExecuting }: UtilityTabResultsProps) => {
<div className="bg-table-header-light dark:bg-table-header-dark">
<div className="flex flex-row justify-between items-center pr-8">
<p className="m-0 border-0 px-6 py-4 font-mono">{result.error.message ?? result.error}</p>
- <Button
- icon={
- <div className="scale-75">
- <AiIconAnimation className="w-3 h-3" loading={isDebugSqlLoading} />
- </div>
- }
- disabled={!!sqlDiff}
- onClick={async () => {
- try {
- const { solution, sql } = await debugSql({
- sql: snippet.snippet.content.sql.replace(sqlAiDisclaimerComment, '').trim(),
- errorMessage: result.error.message,
- entityDefinitions,
- })
-
- const formattedSql =
- sqlAiDisclaimerComment +
- '\n\n' +
- format(sql, {
- language: 'postgresql',
- keywordCase: 'lower',
+ {supabaseAIEnabled && (
+ <Button
+ icon={
+ <div className="scale-75">
+ <AiIconAnimation className="w-3 h-3" loading={isDebugSqlLoading} />
+ </div>
+ }
+ disabled={!!sqlDiff}
+ onClick={async () => {
+ try {
+ const { solution, sql } = await debugSql({
+ sql: snippet.snippet.content.sql.replace(sqlAiDisclaimerComment, '').trim(),
+ errorMessage: result.error.message,
+ entityDefinitions,
})
- setAiInput('')
- setDebugSolution(solution)
- setSqlDiff({
- original: snippet.snippet.content.sql,
- modified: formattedSql,
- })
- } catch (error: unknown) {
- if (isError(error)) {
- ui.setNotification({
- category: 'error',
- message: error.message,
+
+ const formattedSql =
+ sqlAiDisclaimerComment +
+ '\n\n' +
+ format(sql, {
+ language: 'postgresql',
+ keywordCase: 'lower',
+ })
+ setAiInput('')
+ setDebugSolution(solution)
+ setSqlDiff({
+ original: snippet.snippet.content.sql,
+ modified: formattedSql,
})
+ } catch (error: unknown) {
+ if (isError(error)) {
+ ui.setNotification({
+ category: 'error',
+ message: error.message,
+ })
+ }
}
- }
- }}
- >
- Debug using AI
- </Button>
+ }}
+ >
+ Debug with Supabase AI
+ </Button>
+ )}
</div>
{(result.error.message ?? result.error)?.includes(
'canceling statement due to statement timeout'