\`). Prefix routes with the function name (e.g., \`/function-name/route\`).
- - File writes are restricted to the \`/tmp\` directory.
- - Use \`EdgeRuntime.waitUntil(promise)\` for background tasks.
- - **Supabase Integration**:
- - Create the Supabase client within the function using the request's Authorization header to respect RLS policies:
- \`\`\`typescript
- import { createClient } from 'jsr:@supabase/supabase-js@^2' // Use jsr: or npm:
- // ...
- const supabaseClient = createClient(
- Deno.env.get('SUPABASE_URL')!,
- Deno.env.get('SUPABASE_ANON_KEY')!,
- {
- global: {
- headers: { Authorization: req.headers.get('Authorization')! }
- }
- }
- )
- // ... use supabaseClient to interact with the database
- \`\`\`
- - Ensure function code is compatible with the database schema.
- - OpenAI Example:
- \`\`\`typescript
- import OpenAI from 'https://deno.land/x/openai@v4.24.0/mod.ts'
- Deno.serve(async (req) => {
- const { query } = await req.json()
- const apiKey = Deno.env.get('OPENAI_API_KEY')
- const openai = new OpenAI({
- apiKey: apiKey,
- })
- // Documentation here: https://github.com/openai/openai-node
- const chatCompletion = await openai.chat.completions.create({
- messages: [{ role: 'user', content: query }],
- // Choose model from here: https://platform.openai.com/docs/models
- model: 'gpt-3.5-turbo',
- stream: false,
- })
- const reply = chatCompletion.choices[0].message.content
- return new Response(reply, {
- headers: { 'Content-Type': 'text/plain' },
- })
- })
- \`\`\`
-
- # General Instructions:
- - **Understand Context**: Attempt to use \`list_tables\`, \`list_extensions\` first. If they are not available or return a privacy/permission error, state this and proceed with caution, relying on the user's description and general knowledge.
+ ${GENERAL_PROMPT}
+ ${CHAT_PROMPT}
+ ${PG_BEST_PRACTICES}
+ ${RLS_PROMPT}
+ ${EDGE_FUNCTION_PROMPT}
+ ${SECURITY_PROMPT}
`
// Note: these must be of type `CoreMessage` to prevent AI SDK from stripping `providerOptions`
@@ -415,6 +172,15 @@ async function handlePost(req: NextApiRequest, res: NextApiResponse) {
...convertToModelMessages(messages),
]
+ // Get tools
+ const tools = await getTools({
+ projectRef,
+ connectionString,
+ authorization,
+ aiOptInLevel,
+ accessToken,
+ })
+
const result = streamText({
model,
stopWhen: stepCountIs(5),
diff --git a/apps/studio/pages/project/[ref]/functions/[functionSlug]/code.tsx b/apps/studio/pages/project/[ref]/functions/[functionSlug]/code.tsx
index 48e95eca7b..b444c84d4a 100644
--- a/apps/studio/pages/project/[ref]/functions/[functionSlug]/code.tsx
+++ b/apps/studio/pages/project/[ref]/functions/[functionSlug]/code.tsx
@@ -25,7 +25,6 @@ const CodePage = () => {
const { ref, functionSlug } = useParams()
const { data: project } = useSelectedProjectQuery()
const { data: org } = useSelectedOrganizationQuery()
- const { includeSchemaMetadata } = useOrgAiOptInLevel()
const { mutate: sendEvent } = useSendEventMutation()
const [showDeployWarning, setShowDeployWarning] = useState(false)
@@ -219,11 +218,11 @@ const CodePage = () => {
diff --git a/apps/studio/pages/project/[ref]/functions/new.tsx b/apps/studio/pages/project/[ref]/functions/new.tsx
index f0e17bccf7..ad102cf45a 100644
--- a/apps/studio/pages/project/[ref]/functions/new.tsx
+++ b/apps/studio/pages/project/[ref]/functions/new.tsx
@@ -101,7 +101,6 @@ const NewFunctionPage = () => {
const { ref, template } = useParams()
const { data: project } = useSelectedProjectQuery()
const { data: org } = useSelectedOrganizationQuery()
- const { includeSchemaMetadata } = useOrgAiOptInLevel()
const snap = useAiAssistantStateSnapshot()
const { mutate: sendEvent } = useSendEventMutation()
@@ -335,11 +334,11 @@ const NewFunctionPage = () => {
diff --git a/apps/studio/state/ai-assistant-state.tsx b/apps/studio/state/ai-assistant-state.tsx
index 3d09b05d72..a9034f084d 100644
--- a/apps/studio/state/ai-assistant-state.tsx
+++ b/apps/studio/state/ai-assistant-state.tsx
@@ -247,7 +247,7 @@ export const createAiAssistantState = (): AiAssistantState => {
const chatId = uuidv4()
const newChat: ChatSession = {
id: chatId,
- name: options?.name ?? 'Untitled',
+ name: options?.name ?? 'New chat',
messages: [],
createdAt: new Date(),
updatedAt: new Date(),