import DotGrid from '~/components/AIDemo/DotGrid' import { AIDemoPanel } from '~/components/AIDemo/Panel' import { SqlSnippet } from '~/components/AIDemo/SqlSnippet' import { useIsLoggedIn, useIsUserLoading } from 'common' import { motion } from 'framer-motion' import { NextSeo } from 'next-seo' import dynamic from 'next/dynamic' import Link from 'next/link' import { useRouter } from 'next/router' import { useEffect, useState, type ReactNode } from 'react' import { Button } from 'ui' import { EASE_OUT } from '../lib/animations' const DefaultLayout = dynamic(() => import('~/components/Layouts/Default')) const SectionContainer = dynamic(() => import('~/components/Layouts/SectionContainer')) interface Message { id: string role: 'user' | 'assistant' content: ReactNode createdAt: Date render?: ReactNode } const welcomeMessages = [ { id: 'ph-1', role: 'user' as const, content: 'I have come from ProductHunt. Show me the goods!', createdAt: new Date(), }, { id: 'ph-2', role: 'assistant' as const, content: (

Welcome Product Hunter! 👋 Thanks for checking out the Supabase Assistant. Let me show you what I can do!

), createdAt: new Date(), }, ] const demoQueries = [ { label: 'User Growth Over Time', messages: [ { id: '1', role: 'user' as const, content: 'Show me user signups over the past 12 months', createdAt: new Date(), }, { id: '2', role: 'assistant' as const, content: 'Here is a chart showing user growth by month:', createdAt: new Date(), render: ( ), }, ], }, { label: 'Latest Products', messages: [ { id: '23', role: 'user' as const, content: 'Show me our latest products', createdAt: new Date(), }, { id: '24', role: 'assistant' as const, content: 'Here are the 5 most recently added products:', createdAt: new Date(), render: ( ), }, ], }, { label: 'Create Function', messages: [ { id: '19', role: 'user' as const, content: 'Help me create a function to calculate user points', createdAt: new Date(), }, { id: '20', role: 'assistant' as const, content: "Here's a Postgres function that calculates user points based on their activity:", createdAt: new Date(), render: ( ), }, ], }, { label: 'RLS Policy', messages: [ { id: '21', role: 'user' as const, content: 'Show me how to create an RLS policy for a team members table', createdAt: new Date(), }, { id: '22', role: 'assistant' as const, content: "Here's an RLS policy that allows team members to only see other members in their team:", createdAt: new Date(), render: ( ), }, ], }, { label: 'SQL to Supabase-js', messages: [ { id: '23', role: 'user' as const, content: 'How do I query all projects?', createdAt: new Date(), }, { id: '24', role: 'assistant' as const, content: "Here's the SQL query to get all projects:", createdAt: new Date(), render: ( ), }, { id: '25', role: 'user' as const, content: 'Can you show me how to do this with the Supabase client?', createdAt: new Date(), }, { id: '26', role: 'assistant' as const, content: "Here's how to perform the same query using the Supabase JavaScript client:", createdAt: new Date(), render: ( ), }, ], }, { label: 'Recent Orders', messages: [ { id: '3', role: 'user' as const, content: 'Show me the most recent orders', createdAt: new Date(), }, { id: '4', role: 'assistant' as const, content: 'Here are the 5 most recent orders:', createdAt: new Date(), render: ( ), }, ], }, { label: 'Revenue by Category', messages: [ { id: '5', role: 'user' as const, content: 'What are our top performing product categories?', createdAt: new Date(), }, { id: '6', role: 'assistant' as const, content: 'Here is the revenue breakdown by product category:', createdAt: new Date(), render: ( ), }, ], }, { label: 'Active Users', messages: [ { id: '7', role: 'user' as const, content: 'Show me our currently active users', createdAt: new Date(), }, { id: '8', role: 'assistant' as const, content: 'Here are the currently active users:', createdAt: new Date(), render: ( now() - interval '24 hours' ORDER BY last_login DESC;`} mockData={{ rows: [ { username: 'alice_smith', last_login: '2024-01-15T15:30:00Z', session_count: 45, }, { username: 'bob_jones', last_login: '2024-01-15T15:15:00Z', session_count: 32, }, { username: 'carol_white', last_login: '2024-01-15T14:45:00Z', session_count: 28, }, ], }} /> ), }, ], }, { label: 'Daily Page Views', messages: [ { id: '11', role: 'user' as const, content: 'Show me daily page views for the last 2 weeks', createdAt: new Date(), }, { id: '12', role: 'assistant' as const, content: 'Here are the daily page views:', createdAt: new Date(), render: ( now() - interval '14 days' GROUP BY day ORDER BY day;`} mockData={[ { name: '2024-01-01', value: 15234 }, { name: '2024-01-02', value: 14567 }, { name: '2024-01-03', value: 16789 }, { name: '2024-01-04', value: 15678 }, { name: '2024-01-05', value: 17890 }, { name: '2024-01-06', value: 13456 }, { name: '2024-01-07', value: 12345 }, { name: '2024-01-08', value: 16543 }, { name: '2024-01-09', value: 18765 }, { name: '2024-01-10', value: 19876 }, { name: '2024-01-11', value: 20123 }, { name: '2024-01-12', value: 21234 }, { name: '2024-01-13', value: 19876 }, { name: '2024-01-14', value: 18765 }, ]} /> ), }, ], }, { label: 'Error Distribution', messages: [ { id: '1', role: 'user' as const, content: 'Show me the distribution of error types', createdAt: new Date(), }, { id: '15', role: 'assistant' as const, content: 'Here is the distribution of error types:', createdAt: new Date(), render: ( ), }, ], }, { label: 'API Usage Trends', messages: [ { id: '17', role: 'user' as const, content: 'Show me API usage trends over time', createdAt: new Date(), }, { id: '18', role: 'assistant' as const, content: 'Here are the API usage trends:', createdAt: new Date(), render: ( now() - interval '24 hours' GROUP BY hour ORDER BY hour;`} mockData={[ { name: '00:00', value: 1200 }, { name: '02:00', value: 800 }, { name: '04:00', value: 600 }, { name: '06:00', value: 900 }, { name: '08:00', value: 2500 }, { name: '10:00', value: 3500 }, { name: '12:00', value: 4000 }, { name: '14:00', value: 3800 }, { name: '16:00', value: 3200 }, { name: '18:00', value: 2800 }, { name: '20:00', value: 2000 }, { name: '22:00', value: 1500 }, ]} /> ), }, ], }, ] function Assistant() { const [incomingMessages, setIncomingMessages] = useState([]) const isLoggedIn = useIsLoggedIn() const isUserLoading = useIsUserLoading() const meta_title = 'AI | Supabase' const meta_description = 'Build AI-powered applications with Supabase' const router = useRouter() const { query } = router useEffect(() => { if (incomingMessages.length === 0) { const timeoutId = setTimeout(() => { const isFromProductHunt = query.ref === 'producthunt' const initialMessages = isFromProductHunt ? [...welcomeMessages, ...demoQueries[0].messages] : demoQueries[Math.floor(Math.random() * demoQueries.length)].messages setIncomingMessages(initialMessages) }, 3000) return () => clearTimeout(timeoutId) } }, [query.ref]) const handleNewMessage = (messages: Message[]) => { setIncomingMessages(messages.map((message) => ({ ...message, id: Date.now().toString() }))) } return ( <>
{/* Left Column */}
{/* Main content */}

Chat with Postgres

Generate, run and debug queries, chart your data, create functions, policies and more. The Assistant is here to help.

{!isUserLoading && ( )}
{/* Grid of secondary buttons */}

Try me

{demoQueries.map((query, i) => ( ))}
{/* Right Column */}
) } export default Assistant