The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
feat: Make the AI panel in the SQL Editor resizable (#28506)
Ivan Vasilovd6a33be22534
diff --git a/apps/studio/components/interfaces/SQLEditor/AiAssistantPanel/index.tsx b/apps/studio/components/interfaces/SQLEditor/AiAssistantPanel/index.tsxindex 6f61226d608..965282a82e8 100644--- a/apps/studio/components/interfaces/SQLEditor/AiAssistantPanel/index.tsx+++ b/apps/studio/components/interfaces/SQLEditor/AiAssistantPanel/index.tsx@@ -70,7 +70,7 @@ export const AiAssistantPanel = ({}, [loading])return (- <div className="flex flex-col h-full min-w-[400px] w-[400px] border-l border-control">+ <div className="flex flex-col h-full border-l border-control"><divclassName={cn('overflow-auto flex-1',@@ -91,7 +91,7 @@ export const AiAssistantPanel = ({</Button>}>- <div className="flex flex-row justify-between">+ <div className="flex flex-row justify-between space-x-2"><Buttontype="default"className="w-min"diff --git a/apps/studio/components/interfaces/SQLEditor/SQLEditor.tsx b/apps/studio/components/interfaces/SQLEditor/SQLEditor.tsxindex 4a29cb919aa..314211a4f5b 100644--- a/apps/studio/components/interfaces/SQLEditor/SQLEditor.tsx+++ b/apps/studio/components/interfaces/SQLEditor/SQLEditor.tsx@@ -1,16 +1,20 @@import type { Monaco } from '@monaco-editor/react'+import { useQueryClient } from '@tanstack/react-query'import { useChat } from 'ai/react'import { motion } from 'framer-motion'+import { Loader2 } from 'lucide-react'import dynamic from 'next/dynamic'import { useRouter } from 'next/router'import { useCallback, useEffect, useMemo, useRef, useState } from 'react'import toast from 'react-hot-toast'+import { format } from 'sql-formatter'import { useParams, useTelemetryProps } from 'common'import { useSqlDebugMutation } from 'data/ai/sql-debug-mutation'import { useSqlTitleGenerateMutation } from 'data/ai/sql-title-mutation'import type { SqlSnippet } from 'data/content/sql-snippets-query'import { useEntityDefinitionsQuery } from 'data/database/entity-definitions-query'+import { lintKeys } from 'data/lint/keys'import { useReadReplicasQuery } from 'data/read-replicas/replicas-query'import { useExecuteSqlMutation } from 'data/sql/execute-sql-mutation'import { useFormatQueryMutation } from 'data/sql/format-sql-query'@@ -26,13 +30,19 @@ import { uuidv4 } from 'lib/helpers'import { useProfile } from 'lib/profile'import { wrapWithRoleImpersonation } from 'lib/role-impersonation'import Telemetry from 'lib/telemetry'-import { format } from 'sql-formatter'import { useAppStateSnapshot } from 'state/app-state'import { useDatabaseSelectorStateSnapshot } from 'state/database-selector'import { isRoleImpersonationEnabled, useGetImpersonatedRole } from 'state/role-impersonation-state'import { getSqlEditorStateSnapshot, useSqlEditorStateSnapshot } from 'state/sql-editor'import { getSqlEditorV2StateSnapshot, useSqlEditorV2StateSnapshot } from 'state/sql-editor-v2'-import { AiIconAnimation, ResizableHandle, ResizablePanel, ResizablePanelGroup, cn } from 'ui'+import {+ AiIconAnimation,+ ImperativePanelHandle,+ ResizableHandle,+ ResizablePanel,+ ResizablePanelGroup,+ cn,+} from 'ui'import ConfirmModal from 'ui-patterns/Dialogs/ConfirmDialog'import { subscriptionHasHipaaAddon } from '../Billing/Subscription/Subscription.utils'import AISchemaSuggestionPopover from './AISchemaSuggestionPopover'@@ -55,9 +65,6 @@ import {suffixWithLimit,} from './SQLEditor.utils'import UtilityPanel from './UtilityPanel/UtilityPanel'-import { lintKeys } from 'data/lint/keys'-import { useQueryClient } from '@tanstack/react-query'-import { Loader2 } from 'lucide-react'// Load the monaco editor client-side only (does not behave well server-side)const MonacoEditor = dynamic(() => import('./MonacoEditor'), { ssr: false })@@ -612,6 +619,8 @@ const SQLEditor = () => {}}, [selectedDiffType, sourceSqlDiff])+ const aiPanelRef = useRef<ImperativePanelHandle>(null)+return (<><ConfirmModal@@ -631,134 +640,148 @@ const SQLEditor = () => {}}/>- <div className="flex h-full">- <ResizablePanelGroup- className="h-full relative"- direction="vertical"- autoSaveId={LOCAL_STORAGE_KEYS.SQL_EDITOR_SPLIT_SIZE}- >- {(isAiOpen || isDiffOpen) && !hasHipaaAddon && (- <AISchemaSuggestionPopover- onClickSettings={() => {- appSnap.setShowAiSettingsModal(true)- }}- >- {isDiffOpen ? (- <motion.div- key="ask-ai-input-container"- layoutId="ask-ai-input-container"- variants={{ visible: { borderRadius: 0, x: 0 }, hidden: { x: 100 } }}- initial={isFirstRender ? 'visible' : 'hidden'}- animate="visible"- className={cn(- 'flex flex-row items-center gap-3 justify-end px-2 py-2 w-full z-10',- 'bg-brand-200 border-b border-brand-400 !shadow-none'- )}- >- {debugSolution && (- <div className="h-full w-full flex flex-row items-center overflow-y-hidden text-sm text-brand-600">- {debugSolution}- </div>- )}- <DiffActionBar- loading={isAcceptDiffLoading}- selectedDiffType={selectedDiffType || DiffType.Modification}- onChangeDiffType={(diffType) => setSelectedDiffType(diffType)}- onAccept={acceptAiHandler}- onCancel={discardAiHandler}- />- </motion.div>- ) : null}- </AISchemaSuggestionPopover>- )}- <ResizablePanel collapsible collapsedSize={10} minSize={20}>- <div className="flex-grow overflow-y-auto border-b h-full">- {!isAiOpen && (- <motion.button- layoutId="ask-ai-input-icon"- transition={{ duration: 0.1 }}- onClick={() => setIsAiOpen(!isAiOpen)}- className={cn(- 'group absolute z-10 rounded-lg right-[24px] top-4 transition-all duration-200 ease-out'- )}- >- <AiIconAnimation loading={false} allowHoverEffect />- </motion.button>- )}-- {isLoading ? (- <div className="flex h-full w-full items-center justify-center">- <Loader2 className="animate-spin text-brand" />- </div>- ) : (- <>- {isDiffOpen && (+ <ResizablePanelGroup+ className="flex h-full"+ direction="horizontal"+ autoSaveId={LOCAL_STORAGE_KEYS.SQL_EDITOR_AI_PANEL_SPLIT_SIZE}+ >+ <ResizablePanel minSize={30}>+ <ResizablePanelGroup+ className="h-full relative"+ direction="vertical"+ autoSaveId={LOCAL_STORAGE_KEYS.SQL_EDITOR_SPLIT_SIZE}+ >+ {(isAiOpen || isDiffOpen) && !hasHipaaAddon && (+ <AISchemaSuggestionPopover+ onClickSettings={() => {+ appSnap.setShowAiSettingsModal(true)+ }}+ >+ {isDiffOpen ? (+ <motion.div+ key="ask-ai-input-container"+ layoutId="ask-ai-input-container"+ variants={{ visible: { borderRadius: 0, x: 0 }, hidden: { x: 100 } }}+ initial={isFirstRender ? 'visible' : 'hidden'}+ animate="visible"+ className={cn(+ 'flex flex-row items-center gap-3 justify-end px-2 py-2 w-full z-10',+ 'bg-brand-200 border-b border-brand-400 !shadow-none'+ )}+ >+ {debugSolution && (+ <div className="h-full w-full flex flex-row items-center overflow-y-hidden text-sm text-brand-600">+ {debugSolution}+ </div>+ )}+ <DiffActionBar+ loading={isAcceptDiffLoading}+ selectedDiffType={selectedDiffType || DiffType.Modification}+ onChangeDiffType={(diffType) => setSelectedDiffType(diffType)}+ onAccept={acceptAiHandler}+ onCancel={discardAiHandler}+ />+ </motion.div>+ ) : null}+ </AISchemaSuggestionPopover>+ )}+ <ResizablePanel collapsible collapsedSize={10} minSize={20}>+ <div className="flex-grow overflow-y-auto border-b h-full">+ {!isAiOpen && (+ <motion.button+ layoutId="ask-ai-input-icon"+ transition={{ duration: 0.1 }}+ onClick={() => aiPanelRef.current?.expand()}+ className={cn(+ 'group absolute z-10 rounded-lg right-[24px] top-4 transition-all duration-200 ease-out'+ )}+ >+ <AiIconAnimation loading={false} allowHoverEffect />+ </motion.button>+ )}++ {isLoading ? (+ <div className="flex h-full w-full items-center justify-center">+ <Loader2 className="animate-spin text-brand" />+ </div>+ ) : (+ <>+ {isDiffOpen && (+ <motion.div+ className="w-full h-full"+ variants={{+ visible: { opacity: 1, filter: 'blur(0px)' },+ hidden: { opacity: 0, filter: 'blur(10px)' },+ }}+ initial="hidden"+ animate="visible"+ >+ <DiffEditor+ theme="supabase"+ language="pgsql"+ original={defaultSqlDiff.original}+ modified={defaultSqlDiff.modified}+ onMount={(editor) => {+ diffEditorRef.current = editor+ }}+ options={{ fontSize: 13 }}+ />+ </motion.div>+ )}<motion.div- className="w-full h-full"+ key={id}variants={{visible: { opacity: 1, filter: 'blur(0px)' },hidden: { opacity: 0, filter: 'blur(10px)' },}}initial="hidden"- animate="visible"+ animate={isDiffOpen ? 'hidden' : 'visible'}+ className="w-full h-full">- <DiffEditor- theme="supabase"- language="pgsql"- original={defaultSqlDiff.original}- modified={defaultSqlDiff.modified}- onMount={(editor) => {- diffEditorRef.current = editor- }}- options={{ fontSize: 13 }}+ <MonacoEditor+ autoFocus+ id={id}+ editorRef={editorRef}+ monacoRef={monacoRef}+ executeQuery={executeQuery}+ onHasSelection={setHasSelection}/></motion.div>- )}- <motion.div- key={id}- variants={{- visible: { opacity: 1, filter: 'blur(0px)' },- hidden: { opacity: 0, filter: 'blur(10px)' },- }}- initial="hidden"- animate={isDiffOpen ? 'hidden' : 'visible'}- className="w-full h-full"- >- <MonacoEditor- autoFocus- id={id}- editorRef={editorRef}- monacoRef={monacoRef}- executeQuery={executeQuery}- onHasSelection={setHasSelection}- />- </motion.div>- </>- )}- </div>- </ResizablePanel>- <ResizableHandle withHandle />- <ResizablePanel collapsible collapsedSize={10} minSize={20}>- {isLoading ? (- <div className="flex h-full w-full items-center justify-center">- <Loader2 className="animate-spin text-brand" />+ </>+ )}</div>- ) : (- <UtilityPanel- id={id}- isExecuting={isExecuting}- isDisabled={isDiffOpen}- isDebugging={isDebugSqlLoading}- hasSelection={hasSelection}- prettifyQuery={prettifyQuery}- executeQuery={executeQuery}- onDebug={onDebug}- />- )}- </ResizablePanel>- </ResizablePanelGroup>-- {isAiOpen && (+ </ResizablePanel>+ <ResizableHandle withHandle />+ <ResizablePanel collapsible collapsedSize={10} minSize={20}>+ {isLoading ? (+ <div className="flex h-full w-full items-center justify-center">+ <Loader2 className="animate-spin text-brand" />+ </div>+ ) : (+ <UtilityPanel+ id={id}+ isExecuting={isExecuting}+ isDisabled={isDiffOpen}+ isDebugging={isDebugSqlLoading}+ hasSelection={hasSelection}+ prettifyQuery={prettifyQuery}+ executeQuery={executeQuery}+ onDebug={onDebug}+ />+ )}+ </ResizablePanel>+ </ResizablePanelGroup>+ </ResizablePanel>+ <ResizableHandle withHandle />+ <ResizablePanel+ ref={aiPanelRef}+ collapsible+ collapsedSize={0}+ minSize={21}+ maxSize={40}+ onCollapse={() => setIsAiOpen(false)}+ onExpand={() => setIsAiOpen(true)}+ ><AiAssistantPanelmessages={messages}selectedMessage={selectedMessage}@@ -772,10 +795,10 @@ const SQLEditor = () => {}onClearHistory={() => setChatId(uuidv4())}onDiff={updateEditorWithCheckForDiff}- onClose={() => setIsAiOpen(false)}+ onClose={() => aiPanelRef.current?.collapse()}/>- )}- </div>+ </ResizablePanel>+ </ResizablePanelGroup></>)}diff --git a/apps/studio/lib/constants/index.ts b/apps/studio/lib/constants/index.tsindex f581e347cac..6f3b872c761 100644--- a/apps/studio/lib/constants/index.ts+++ b/apps/studio/lib/constants/index.ts@@ -41,6 +41,7 @@ export const LOCAL_STORAGE_KEYS = {SQL_EDITOR_INTELLISENSE: 'supabase_sql-editor-intellisense-enabled',SQL_EDITOR_SPLIT_SIZE: 'supabase_sql-editor-split-size',+ SQL_EDITOR_AI_PANEL_SPLIT_SIZE: 'supabase_sql-editor-ai-panel-split-size',SQL_EDITOR_AI_SCHEMA: 'supabase_sql-editor-ai-schema-enabled',SQL_EDITOR_AI_OPEN: 'supabase_sql-editor-ai-open',LOG_EXPLORER_SPLIT_SIZE: 'supabase_log-explorer-split-size',diff --git a/packages/ui-patterns/AssistantChat/AssistantChatForm.tsx b/packages/ui-patterns/AssistantChat/AssistantChatForm.tsxindex 86a9b43d558..71885449bd0 100644--- a/packages/ui-patterns/AssistantChat/AssistantChatForm.tsx+++ b/packages/ui-patterns/AssistantChat/AssistantChatForm.tsx@@ -78,7 +78,6 @@ const AssistantChatForm = React.forwardRef<HTMLFormElement, FormProps>(ref={textAreaRef}autoFocusdisabled={disabled}- contentEditableclassName={cn(icon ? 'pl-12' : '', 'text-sm pr-10 rounded-[18px]')}placeholder={placeholder}spellCheck={false}diff --git a/packages/ui/src/components/shadcn/ui/resizable.tsx b/packages/ui/src/components/shadcn/ui/resizable.tsxindex 9bfbfaf1721..02ea512c18c 100644--- a/packages/ui/src/components/shadcn/ui/resizable.tsx+++ b/packages/ui/src/components/shadcn/ui/resizable.tsx@@ -3,6 +3,7 @@import { GripVertical } from 'lucide-react'import * as ResizablePrimitive from 'react-resizable-panels'+import { ImperativePanelHandle } from 'react-resizable-panels'import { cn } from '../../../lib/utils/cn'const ResizablePanelGroup = ({@@ -51,4 +52,4 @@ const ResizableHandle = ({</ResizablePrimitive.PanelResizeHandle>)-export { ResizablePanelGroup, ResizablePanel, ResizableHandle }+export { ResizableHandle, ResizablePanel, ResizablePanelGroup, type ImperativePanelHandle }diff --git a/packages/ui/src/components/shadcn/ui/text-area.tsx b/packages/ui/src/components/shadcn/ui/text-area.tsxindex 3b2f26bb5f2..3f24b347fea 100644--- a/packages/ui/src/components/shadcn/ui/text-area.tsx+++ b/packages/ui/src/components/shadcn/ui/text-area.tsx@@ -23,6 +23,6 @@ const TextArea = React.forwardRef<HTMLTextAreaElement, TextAreaProps>(})-TextArea.displayName = 'Input'+TextArea.displayName = 'TextArea'export { TextArea }