Skip to content

Commit e05981c

Browse files
authored
feat: add assistant variation to table quickstart experiment (2.5 of 3) (supabase#39825)
feat: add assistant variation to table quickstart experiment Adds ASSISTANT variant to table quickstart that opens AI assistant with pre-populated conversation to guide users through creating their first database table. Changes: - Add QuickstartVariant.ASSISTANT enum value - Add 'Create with Assistant' card for new projects (<7 days old) - Implement handleOpenAssistant with proper loading states and error handling - Add pre-populated messages to guide table creation workflow The assistant card appears only for users bucketed into the assistant variation of the tableQuickstart experiment on new projects.
1 parent 73e3143 commit e05981c

File tree

2 files changed

+58
-1
lines changed
  • apps/studio/components
    • interfaces/TableGridEditor/SidePanelEditor/TableEditor/TableQuickstart
    • layouts/Tabs

2 files changed

+58
-1
lines changed

apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/TableQuickstart/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export enum QuickstartVariant {
3737
CONTROL = 'control',
3838
AI = 'ai',
3939
TEMPLATES = 'templates',
40+
ASSISTANT = 'assistant',
4041
}
4142

4243
export type TableSuggestion = {

apps/studio/components/layouts/Tabs/NewTab.tsx

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { partition } from 'lodash'
44
import { Table2 } from 'lucide-react'
55
import Link from 'next/link'
66
import { useRouter } from 'next/router'
7-
import { useMemo } from 'react'
7+
import { useMemo, useState } from 'react'
88
import { toast } from 'sonner'
99

1010
import { useParams } from 'common'
@@ -20,10 +20,12 @@ import { useSelectedProjectQuery } from 'hooks/misc/useSelectedProject'
2020
import { usePHFlag } from 'hooks/ui/useFlag'
2121
import { uuidv4 } from 'lib/helpers'
2222
import { useProfile } from 'lib/profile'
23+
import { useAiAssistantStateSnapshot, AssistantMessageType } from 'state/ai-assistant-state'
2324
import { useSqlEditorV2StateSnapshot } from 'state/sql-editor-v2'
2425
import { useTableEditorStateSnapshot } from 'state/table-editor'
2526
import { createTabId, useTabsStateSnapshot } from 'state/tabs'
2627
import {
28+
AiIconAnimation,
2729
Button,
2830
cn,
2931
SQL_ICON,
@@ -39,6 +41,12 @@ import { RecentItems } from './RecentItems'
3941
const NEW_PROJECT_THRESHOLD_DAYS = 7
4042
const TABLE_QUICKSTART_FLAG = 'tableQuickstart'
4143

44+
const ASSISTANT_QUICKSTART_MESSAGES = {
45+
user: 'Help me create a new database table for my project',
46+
assistant:
47+
"I'll help you create a database table. Please tell me:\n\n1. What does your application do?\n2. What kind of data do you want to store?\n\nI'll suggest a table structure that fits your requirements and help you create it directly in your database.",
48+
}
49+
4250
export function NewTab() {
4351
const router = useRouter()
4452
const { ref } = useParams()
@@ -50,7 +58,9 @@ export function NewTab() {
5058
const snap = useTableEditorStateSnapshot()
5159
const snapV2 = useSqlEditorV2StateSnapshot()
5260
const tabs = useTabsStateSnapshot()
61+
const aiSnap = useAiAssistantStateSnapshot()
5362

63+
const [isCreatingChat, setIsCreatingChat] = useState(false)
5464
const [templates] = partition(SQL_TEMPLATES, { type: 'template' })
5565
const [quickstarts] = partition(SQL_TEMPLATES, { type: 'quickstart' })
5666

@@ -87,6 +97,43 @@ export function NewTab() {
8797
? tableQuickstartVariant
8898
: null
8999

100+
const handleOpenAssistant = () => {
101+
if (isCreatingChat) return
102+
103+
setIsCreatingChat(true)
104+
105+
try {
106+
const chatId = aiSnap.newChat({
107+
name: 'Create a database table',
108+
open: true,
109+
})
110+
111+
if (!chatId) {
112+
throw new Error('Failed to create chat')
113+
}
114+
115+
const userMessage: AssistantMessageType = {
116+
id: uuidv4(),
117+
role: 'user',
118+
parts: [{ type: 'text', text: ASSISTANT_QUICKSTART_MESSAGES.user }],
119+
}
120+
121+
const assistantMessage: AssistantMessageType = {
122+
id: uuidv4(),
123+
role: 'assistant',
124+
parts: [{ type: 'text', text: ASSISTANT_QUICKSTART_MESSAGES.assistant }],
125+
}
126+
127+
aiSnap.saveMessage([userMessage, assistantMessage])
128+
} catch (error) {
129+
console.error('Failed to open AI assistant:', error)
130+
const message = error instanceof Error ? error.message : 'Unknown error'
131+
toast.error(`Unable to open AI assistant: ${message}`)
132+
} finally {
133+
setIsCreatingChat(false)
134+
}
135+
}
136+
90137
const tableEditorActions = [
91138
{
92139
icon: <Table2 className="h-4 w-4 text-foreground" strokeWidth={1.5} />,
@@ -153,6 +200,15 @@ export function NewTab() {
153200
{actions.map((item, i) => (
154201
<ActionCard key={`action-card-${i}`} {...item} />
155202
))}
203+
{activeQuickstartVariant === QuickstartVariant.ASSISTANT && (
204+
<ActionCard
205+
icon={<AiIconAnimation size={16} loading={isCreatingChat} />}
206+
title="Create with Assistant"
207+
description="Use AI to design your database table"
208+
bgColor="bg-brand-200"
209+
onClick={handleOpenAssistant}
210+
/>
211+
)}
156212
</div>
157213
{activeQuickstartVariant === QuickstartVariant.AI && (
158214
<QuickstartAIWidget onSelectTable={(tableData) => snap.onAddTable(tableData)} />

0 commit comments

Comments
 (0)