fix(db-playground): builds

This commit is contained in:
Greg Richardson committed 2024-06-17 12:14:28 -06:00
1 parent 1e19ae26d1
commit ae5244be2f
9 files changed
+21 -52

No files matched your search

@@ -2,16 +2,11 @@ import { openai } from '@ai-sdk/openai'
import { convertToCoreMessages, streamText } from 'ai'
import { codeBlock } from 'common-tags'
import { z } from 'zod'
import { reportSchema, tabsSchema } from '~/lib/schema'
// Allow streaming responses up to 30 seconds
export const maxDuration = 30
const reportSchema = z.object({ name: z.string(), description: z.string() })
export type Report = typeof reportSchema._type
export const tabsSchema = z.enum(['diagram', 'migrations', 'seeds'])
export type TabValue = typeof tabsSchema._type
export async function POST(req: Request) {
const { messages } = await req.json()
@@ -1,36 +0,0 @@
import { openai } from '@ai-sdk/openai'
import { convertToCoreMessages } from 'ai'
import { FunctionBinding, streamTextWithInterpreter } from 'ai-sandbox'
import { codeBlock } from 'common-tags'
// Allow streaming responses up to 30 seconds
export const maxDuration = 30
export type RequestBody = {
messages: any[]
functionBindings: Record<string, FunctionBinding>
}
export async function POST(req: Request) {
const { messages, functionBindings }: RequestBody = await req.json()
const coreMessages = convertToCoreMessages(messages as any)
const result = await streamTextWithInterpreter({
system: codeBlock`
You are a helpful assistant.
All math equations and expressions must be written in KaTex and must be wrapped in double dollar \`$$\`:
- Inline: $$\\sqrt{26}$$
- Multiline:
$$
\\sqrt{26}
$$
`,
model: openai('gpt-4o-2024-05-13'),
messages: coreMessages,
functionBindings,
})
return new Response(result)
}
+2 -6
View File
@@ -2,7 +2,6 @@
import 'chartjs-adapter-date-fns'
import { PGlite } from '@electric-sql/pglite'
import { Editor } from '@monaco-editor/react'
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@ui/components/shadcn/ui/tabs'
import { nanoid } from 'ai'
@@ -25,16 +24,13 @@ import { AiIconAnimation, markdownComponents } from 'ui'
import { Button } from 'ui/src/components/shadcn/ui/button'
import SchemaGraph from '~/components/schema/graph'
import { useTablesQuery } from '~/data/tables/tables-query'
import { db } from '~/lib/db'
import { useReportSuggestions } from '~/lib/hooks'
import { TabValue, tabsSchema } from '~/lib/schema'
import { groupStatements } from '~/lib/sql-util'
import { TabValue, tabsSchema } from './api/chat/route'
const loadFramerFeatures = () => import('./framer-features').then((res) => res.default)
// React's double-rendering in dev mode causes pglite errors
// Temp: storing single instance in module scope
export let db: PGlite = new PGlite('idb://local')
export default function Page() {
const [migrationSql, setMigrationSql] = useState(
'-- Migrations will appear here as you chat with Supabase AI'
@@ -6,7 +6,7 @@ import {
wrapResult,
} from '@gregnr/postgres-meta/base'
import { UseQueryOptions, useQuery } from '@tanstack/react-query'
import { db } from '~/app/page'
import { db } from '~/lib/db'
export type TablesVariables = {
schemas?: string[]
+6
View File
@@ -0,0 +1,6 @@
import { PGlite } from '@electric-sql/pglite'
// React's double-rendering in dev mode causes pglite errors
// Temp: storing singleton instance in module scope
// TODO: get working in WebWorkers
export let db: PGlite = new PGlite('idb://local')
+1 -1
View File
@@ -4,7 +4,7 @@ import { useChat } from 'ai/react'
import { codeBlock } from 'common-tags'
import { useEffect, useState } from 'react'
import { useTablesQuery } from '~/data/tables/tables-query'
import { Report } from '../app/api/chat/route'
import { Report } from '~/lib/schema'
export type UseReportSuggestionsOptions = {
enabled?: boolean
+7
View File
@@ -0,0 +1,7 @@
import { z } from 'zod'
export const reportSchema = z.object({ name: z.string(), description: z.string() })
export type Report = typeof reportSchema._type
export const tabsSchema = z.enum(['diagram', 'migrations', 'seeds'])
export type TabValue = typeof tabsSchema._type
+1 -1
View File
@@ -8,9 +8,9 @@ const nextConfig = {
module: false,
},
}
return config
},
swcMinify: false,
}
export default nextConfig
+2 -1
View File
@@ -37,7 +37,8 @@
"next-env.d.ts",
"**/*.ts",
"**/*.tsx",
".next/types/**/*.ts"
".next/types/**/*.ts",
"./../../packages/ui/src/**/*.d.ts"
],
"exclude": [
"node_modules"