11import { openai } from '@ai-sdk/openai'
2- import { streamText } from 'ai'
3- import { getTools } from './tools'
42import pgMeta from '@supabase/pg-meta'
5- import { executeSql } from 'data/sql/execute-sql-query '
3+ import { streamText } from 'ai '
64import { NextApiRequest , NextApiResponse } from 'next'
75
6+ import { executeSql } from 'data/sql/execute-sql-query'
7+ import { getTools } from './tools'
8+
89export const maxDuration = 30
910const openAiKey = process . env . OPENAI_API_KEY
1011const pgMetaSchemasList = pgMeta . schemas . list ( )
1112
1213export default async function handler ( req : NextApiRequest , res : NextApiResponse ) {
1314 if ( ! openAiKey ) {
14- return new Response (
15- JSON . stringify ( {
16- error : 'No OPENAI_API_KEY set. Create this environment variable to use AI features.' ,
17- } ) ,
18- {
19- status : 500 ,
20- headers : { 'Content-Type' : 'application/json' } ,
21- }
22- )
15+ return res . status ( 400 ) . json ( {
16+ error : 'No OPENAI_API_KEY set. Create this environment variable to use AI features.' ,
17+ } )
2318 }
2419
2520 const { method } = req
@@ -28,13 +23,8 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
2823 case 'POST' :
2924 return handlePost ( req , res )
3025 default :
31- return new Response (
32- JSON . stringify ( { data : null , error : { message : `Method ${ method } Not Allowed` } } ) ,
33- {
34- status : 405 ,
35- headers : { 'Content-Type' : 'application/json' , Allow : 'POST' } ,
36- }
37- )
26+ res . setHeader ( 'Allow' , [ 'POST' ] )
27+ res . status ( 405 ) . json ( { data : null , error : { message : `Method ${ method } Not Allowed` } } )
3828 }
3929}
4030
0 commit comments