The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
studio: add sql provenance tracking to ai assistant + reports (#45608)
Charis465121894db6
diff --git a/apps/studio/components/interfaces/Reports/ReportBlock/ReportBlock.tsx b/apps/studio/components/interfaces/Reports/ReportBlock/ReportBlock.tsxindex 5e31661160e..1ec8ecf0705 100644--- a/apps/studio/components/interfaces/Reports/ReportBlock/ReportBlock.tsx+++ b/apps/studio/components/interfaces/Reports/ReportBlock/ReportBlock.tsx@@ -1,3 +1,4 @@+import { acceptUntrustedSql } from '@supabase/pg-meta'import { useQuery } from '@tanstack/react-query'import { useParams } from 'common'import { X } from 'lucide-react'@@ -104,7 +105,10 @@ export const ReportBlock = ({return executeSql({projectRef,connectionString,- sql,+ // acceptUntrustedSql is usually not allowed in an auto-run position,+ // but in this case we are explicitly allowing it because adding a block+ // to a report is an explicit user action.+ sql: acceptUntrustedSql(sql),})},enabled: !isLoadingContent && contentError == null,diff --git a/apps/studio/components/ui/AIAssistantPanel/DisplayBlockRenderer.tsx b/apps/studio/components/ui/AIAssistantPanel/DisplayBlockRenderer.tsxindex 3849b5f33cf..bf984b5d4ed 100644--- a/apps/studio/components/ui/AIAssistantPanel/DisplayBlockRenderer.tsx+++ b/apps/studio/components/ui/AIAssistantPanel/DisplayBlockRenderer.tsx@@ -1,3 +1,4 @@+import { acceptUntrustedSql, type UntrustedSqlFragment } from '@supabase/pg-meta'import { PermissionAction } from '@supabase/shared-types/out/constants'import { useQueryClient } from '@tanstack/react-query'import { useParams } from 'common'@@ -22,7 +23,7 @@ interface DisplayBlockRendererProps {messageId: stringtoolCallId: stringinitialArgs: {- sql: string+ sql: UntrustedSqlFragmentlabel?: stringisWriteQuery?: booleanview?: 'table' | 'chart'@@ -163,7 +164,7 @@ export const DisplayBlockRenderer = ({setIsWriteQuery(true)}executeSql(- { projectRef: ref, connectionString, sql: sqlQuery },+ { projectRef: ref, connectionString, sql: acceptUntrustedSql(sqlQuery) },{onSuccess: (data) => {setRows(Array.isArray(data.result) ? data.result : undefined)diff --git a/apps/studio/components/ui/AIAssistantPanel/Message.utils.ts b/apps/studio/components/ui/AIAssistantPanel/Message.utils.tsindex 8212e445127..932864198f7 100644--- a/apps/studio/components/ui/AIAssistantPanel/Message.utils.ts+++ b/apps/studio/components/ui/AIAssistantPanel/Message.utils.ts@@ -1,3 +1,4 @@+import { untrustedSql } from '@supabase/pg-meta'import { z, type SafeParseReturnType } from 'zod'// Splits markdown into alternating [plain, code, plain, code, ...] segments.@@ -81,7 +82,7 @@ const executeSqlChartResultSchema = zconst chartArgs = chartConfig ?? configreturn {- sql: sql ?? '',+ sql: untrustedSql(sql ?? ''),label,isWriteQuery,view: chartArgs?.view,diff --git a/apps/studio/components/ui/AIAssistantPanel/MessageMarkdown.tsx b/apps/studio/components/ui/AIAssistantPanel/MessageMarkdown.tsxindex 90be7095a2e..2a35e617b17 100644--- a/apps/studio/components/ui/AIAssistantPanel/MessageMarkdown.tsx+++ b/apps/studio/components/ui/AIAssistantPanel/MessageMarkdown.tsx@@ -1,3 +1,4 @@+import { untrustedSql } from '@supabase/pg-meta'import dynamic from 'next/dynamic'import Link from 'next/link'import {@@ -265,7 +266,7 @@ export const MarkdownPre = ({messageId={id}toolCallId={toolCallId}initialArgs={{- sql: cleanContent,+ sql: untrustedSql(cleanContent),label: title,isWriteQuery: false,view: isChart ? 'chart' : 'table',