The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
fix(studio): correct the Assistant's blocked-tool privacy message (#50411)
Matt Rossmana133ef60a6f5
diff --git a/apps/studio/lib/ai/ai-details.test.ts b/apps/studio/lib/ai/ai-details.test.tsindex 08d8ddd35ee..2e8375cc394 100644--- a/apps/studio/lib/ai/ai-details.test.ts+++ b/apps/studio/lib/ai/ai-details.test.ts@@ -93,6 +93,7 @@ describe('getAIDetails', () => {planId: 'pro',region: 'us-east-1',isSensitive: false,+ isRestrictedByHipaa: false,})})@@ -249,6 +250,7 @@ describe('getAIDetails', () => {expect(result.aiOptInLevel).toBe('disabled')expect(result.hasHipaaAddon).toBe(true)+ expect(result.isRestrictedByHipaa).toBe(true)})it('disables the opt-in level when project sensitivity is unknown', async () => {diff --git a/apps/studio/lib/ai/ai-details.ts b/apps/studio/lib/ai/ai-details.tsindex 9a4fe56875c..5452433c544 100644--- a/apps/studio/lib/ai/ai-details.ts+++ b/apps/studio/lib/ai/ai-details.ts@@ -15,6 +15,8 @@ export type AIDetails = {planId: string | undefinedregion: string | undefinedisSensitive: boolean | null | undefined+ // True when HIPAA forced the opt-in level to `disabled`, rather than the org choosing it.+ isRestrictedByHipaa: boolean}// Resolves the AI opt-in level, model access and tracing inputs for one org/project pair.@@ -61,6 +63,7 @@ export const getAIDetails = async ({planId: undefined,region,isSensitive,+ isRestrictedByHipaa: false,}}@@ -78,5 +81,6 @@ export const getAIDetails = async ({planId: selectedOrg.plan.id,region,isSensitive,+ isRestrictedByHipaa,}}diff --git a/apps/studio/lib/ai/tool-filter.test.ts b/apps/studio/lib/ai/tool-filter.test.tsindex 6721995742c..47c91261876 100644--- a/apps/studio/lib/ai/tool-filter.test.ts+++ b/apps/studio/lib/ai/tool-filter.test.ts@@ -38,7 +38,7 @@ describe('tool allowance by opt-in level', () => {query_logs: { execute: vitest.fn().mockResolvedValue({ status: 'success' }) },} as unknown as ToolSet- const filtered = filterToolsByOptInLevel(mockTools, optInLevel as any)+ const filtered = filterToolsByOptInLevel(mockTools, optInLevel as any, false)const allowedTools: string[] = []Object.entries(filtered).forEach(([toolName, tool]) => {@@ -163,14 +163,14 @@ describe('filterToolsByOptInLevel', () => {}it('should filter out unknown tools entirely', async () => {- const tools = filterToolsByOptInLevel(mockTools, 'disabled')+ const tools = filterToolsByOptInLevel(mockTools, 'disabled', false)// Unknown tools should be completely filtered out (not present in result)expect(tools).not.toHaveProperty('some_other_tool')})it('should always allow UI tools regardless of opt-in level', async () => {- const tools = filterToolsByOptInLevel(mockTools, 'disabled')+ const tools = filterToolsByOptInLevel(mockTools, 'disabled', false)expect(tools).toHaveProperty('execute_sql')expect(tools).toHaveProperty('deploy_edge_function')@@ -189,7 +189,7 @@ describe('filterToolsByOptInLevel', () => {})it('should stub all managed tools for disabled opt-in level', async () => {- const tools = filterToolsByOptInLevel(mockTools, 'disabled')+ const tools = filterToolsByOptInLevel(mockTools, 'disabled', false)await expectStubsFor(tools, ['list_tables',@@ -203,7 +203,7 @@ describe('filterToolsByOptInLevel', () => {})it('should stub log tools for schema opt-in level', async () => {- const tools = filterToolsByOptInLevel(mockTools, 'schema')+ const tools = filterToolsByOptInLevel(mockTools, 'schema', false)await expectStubsFor(tools, ['get_advisors', 'query_logs'])})@@ -211,7 +211,7 @@ describe('filterToolsByOptInLevel', () => {// No execute_sql tool, so nothing additional to stub for schema_and_log opt-in levelit('should not stub any tools for schema_and_log_and_data opt-in level', async () => {- const tools = filterToolsByOptInLevel(mockTools, 'schema_and_log_and_data')+ const tools = filterToolsByOptInLevel(mockTools, 'schema_and_log_and_data', false)await expectStubsFor(tools, [])})@@ -226,7 +226,7 @@ describe('createPrivacyMessageTool', () => {toModelOutput: vitest.fn(),}- const privacyTool = createPrivacyMessageTool(originalTool)+ const privacyTool = createPrivacyMessageTool(originalTool, false)expect(privacyTool.description).toContain('Original description')expect(privacyTool.description).toContain('Requires opting in')@@ -234,6 +234,25 @@ describe('createPrivacyMessageTool', () => {const result = await privacyTool.execute({}, {})expect(result.status).toContain("You don't have permission to use this tool")+ expect(result.status).toContain('third-party AI providers')+ })++ it('uses HIPAA copy when the project is HIPAA-restricted', async () => {+ const originalTool = {+ description: 'Original description',+ inputSchema: z.object({}),+ execute: vitest.fn(),+ }++ const hipaaTool = createPrivacyMessageTool(originalTool, true)+ const optInTool = createPrivacyMessageTool(originalTool, false)++ const hipaaStatus = (await hipaaTool.execute({}, {})).status+ const optInStatus = (await optInTool.execute({}, {})).status++ expect(hipaaStatus).toContain('HIPAA')+ expect(hipaaStatus).not.toEqual(optInStatus)+ expect(hipaaTool.description).not.toEqual(optInTool.description)})})diff --git a/apps/studio/lib/ai/tool-filter.ts b/apps/studio/lib/ai/tool-filter.tsindex 82de291da6b..d93663d8a8f 100644--- a/apps/studio/lib/ai/tool-filter.ts+++ b/apps/studio/lib/ai/tool-filter.ts@@ -162,13 +162,21 @@ function isToolAllowed(toolName: string, aiOptInLevel: AiOptInLevel): boolean {}/**- * Create a privacy message tool that explains why the tool is not available+ * Replaces a blocked tool with a stub that explains the opt-in instead of executing.+ *+ * Names no provider. Studio switches inference providers, and a stale name here becomes a+ * false privacy claim shown to users.*/-export function createPrivacyMessageTool(toolInstance: Tool<any, any>) {- const privacyMessage =- "You don't have permission to use this tool. This is an organization-wide setting requiring you to opt-in. Please choose your preferred data sharing level in your organization's settings. Supabase Assistant uses Amazon Bedrock, which does not store or log your prompts and completions, use them to train AWS models, or distribute them to third parties. By default, no data is shared. Granting permission allows Supabase to send information (like schema, logs, or data, depending on your chosen level) to Bedrock solely to generate responses."- const condensedPrivacyMessage =- 'Requires opting in to sending data to Bedrock which does not store, train on, or distribute it. You can opt in via organization settings.'+export function createPrivacyMessageTool(+ toolInstance: Tool<any, any>,+ isRestrictedByHipaa: boolean+) {+ const privacyMessage = isRestrictedByHipaa+ ? "You don't have permission to use this tool. This project is configured as High Compliance and your organization has the HIPAA add-on, so Supabase does not send project metadata with your prompts. The user cannot change this in their organization's AI settings, so continue without project metadata rather than asking them to opt in."+ : "You don't have permission to use this tool. This is an organization-wide setting requiring you to opt-in. Please choose your preferred data sharing level in your organization's settings. By default, no data is shared. Granting permission allows Supabase to send information (like schema, logs, or data, depending on your chosen level) to third-party AI providers solely to generate responses."+ const condensedPrivacyMessage = isRestrictedByHipaa+ ? 'Unavailable because this project is configured as High Compliance, which prevents project metadata from being shared. This cannot be changed in organization settings.'+ : 'Requires opting in to sharing data with third-party AI providers. You can opt in via organization settings.'const toolDescription = toolInstance.descriptionconst description =typeof toolDescription === 'function'@@ -189,7 +197,11 @@ export function createPrivacyMessageTool(toolInstance: Tool<any, any>) {/*** Filter tools based on the AI opt-in level*/-export function filterToolsByOptInLevel(tools: ToolSet, aiOptInLevel: AiOptInLevel): ToolSet {+export function filterToolsByOptInLevel(+ tools: ToolSet,+ aiOptInLevel: AiOptInLevel,+ isRestrictedByHipaa: boolean+): ToolSet {return Object.fromEntries(Object.entries(tools).filter(([toolName]) => TOOL_CATEGORY_MAP[toolName] !== undefined)@@ -199,7 +211,7 @@ export function filterToolsByOptInLevel(tools: ToolSet, aiOptInLevel: AiOptInLev}// If the tool is not allowed, provide a stub that returns a privacy message- return [toolName, createPrivacyMessageTool(toolInstance)]+ return [toolName, createPrivacyMessageTool(toolInstance, isRestrictedByHipaa)]}))}diff --git a/apps/studio/lib/ai/tools/index.test.ts b/apps/studio/lib/ai/tools/index.test.tsindex c0157b35069..fcf580f2446 100644--- a/apps/studio/lib/ai/tools/index.test.ts+++ b/apps/studio/lib/ai/tools/index.test.ts@@ -18,6 +18,7 @@ const BASE_PARAMS = {connectionString: 'postgresql://localhost',authorization: 'Bearer token',aiOptInLevel: 'schema_and_log_and_data' as const,+ isRestrictedByHipaa: false,accessToken: 'access-token',baseUrl: 'https://supabase.com/dashboard',signal: new AbortController().signal,@@ -39,6 +40,7 @@ describe('ai/tools getTools', () => {accessToken: BASE_PARAMS.accessToken,projectRef: BASE_PARAMS.projectRef,aiOptInLevel: BASE_PARAMS.aiOptInLevel,+ isRestrictedByHipaa: BASE_PARAMS.isRestrictedByHipaa,signal: BASE_PARAMS.signal,})expect(tools).toHaveProperty('studio_tool')diff --git a/apps/studio/lib/ai/tools/index.ts b/apps/studio/lib/ai/tools/index.tsindex b4b041a78c6..b4b0eabbc1f 100644--- a/apps/studio/lib/ai/tools/index.ts+++ b/apps/studio/lib/ai/tools/index.ts@@ -17,6 +17,7 @@ export const getTools = async ({connectionString,authorization,aiOptInLevel,+ isRestrictedByHipaa,accessToken,baseUrl,supportMode,@@ -27,6 +28,8 @@ export const getTools = async ({connectionString: stringauthorization?: stringaiOptInLevel: AiOptInLevel+ // Only changes the blocked-tool wording.+ isRestrictedByHipaa: booleanaccessToken?: stringbaseUrl?: stringsupportMode?: boolean@@ -63,6 +66,7 @@ export const getTools = async ({accessToken,projectRef,aiOptInLevel,+ isRestrictedByHipaa,signal,})} catch (error) {@@ -91,7 +95,11 @@ export const getTools = async ({// Filter all tools based on the (potentially modified) AI opt-in levelconst toolsWithSupport = supportMode ? { ...tools, ...getSupportLifecycleTools() } : tools- const filteredTools: ToolSet = filterToolsByOptInLevel(toolsWithSupport, aiOptInLevel)+ const filteredTools: ToolSet = filterToolsByOptInLevel(+ toolsWithSupport,+ aiOptInLevel,+ isRestrictedByHipaa+ )return filteredTools}diff --git a/apps/studio/lib/ai/tools/mcp-tools.test.ts b/apps/studio/lib/ai/tools/mcp-tools.test.tsindex 349c642c71a..538c2d16084 100644--- a/apps/studio/lib/ai/tools/mcp-tools.test.ts+++ b/apps/studio/lib/ai/tools/mcp-tools.test.ts@@ -11,6 +11,7 @@ const BASE_PARAMS = {accessToken: 'token',projectRef: 'abcdefghijklmnopqrst',aiOptInLevel: 'schema_and_log_and_data' as const,+ isRestrictedByHipaa: false,// A fresh, non-aborted signal by default; lifecycle tests override itsignal: new AbortController().signal,}diff --git a/apps/studio/lib/ai/tools/mcp-tools.ts b/apps/studio/lib/ai/tools/mcp-tools.tsindex d14043528a7..27b1174d969 100644--- a/apps/studio/lib/ai/tools/mcp-tools.ts+++ b/apps/studio/lib/ai/tools/mcp-tools.ts@@ -41,11 +41,13 @@ export const getMcpTools = async ({accessToken,projectRef,aiOptInLevel,+ isRestrictedByHipaa,signal,}: {accessToken: stringprojectRef: stringaiOptInLevel: AiOptInLevel+ isRestrictedByHipaa: boolean// Required: the remote client holds an HTTP connection that must be torn down// when the request ends. The caller owns that lifecycle via this signal.signal: AbortSignal@@ -99,7 +101,11 @@ export const getMcpTools = async ({// write/destructive tools (apply_migration, create_branch, ...) from reaching// the assistant. `read_only` is defense-in-depth (those tools throw at// runtime). Do not remove this filter on the assumption `read_only` suffices.- const allowedMcpTools = filterToolsByOptInLevel(availableMcpTools, aiOptInLevel)+ const allowedMcpTools = filterToolsByOptInLevel(+ availableMcpTools,+ aiOptInLevel,+ isRestrictedByHipaa+ )// Remove UI-executed tools handled locallyconst filteredMcpTools: ToolSet = { ...allowedMcpTools }diff --git a/apps/studio/pages/api/ai/sql/generate-v4.ts b/apps/studio/pages/api/ai/sql/generate-v4.tsindex b68ba949bc3..59998e32472 100644--- a/apps/studio/pages/api/ai/sql/generate-v4.ts+++ b/apps/studio/pages/api/ai/sql/generate-v4.ts@@ -120,6 +120,7 @@ async function handlePost(req: NextApiRequest, res: NextApiResponse, claims?: Jwconst includesLogsSnippets = messagesIncludeLogsSnippets(messages)let aiOptInLevel: AiOptInLevel = 'disabled'+ let isRestrictedByHipaa = falselet hasAccessToAdvanceModel = falselet orgHasHipaaAddon: boolean | undefinedlet projectIsSensitive: boolean | null | undefined@@ -138,6 +139,7 @@ async function handlePost(req: NextApiRequest, res: NextApiResponse, claims?: Jwconst aiDetails = await getAIDetails({ orgSlug: rawOrgSlug, projectRef, authorization })aiOptInLevel = aiDetails.aiOptInLevel+ isRestrictedByHipaa = aiDetails.isRestrictedByHipaahasAccessToAdvanceModel = aiDetails.hasAccessToAdvanceModelorgHasHipaaAddon = aiDetails.hasHipaaAddonorgId = aiDetails.orgId@@ -187,6 +189,7 @@ async function handlePost(req: NextApiRequest, res: NextApiResponse, claims?: JwconnectionString,authorization,aiOptInLevel,+ isRestrictedByHipaa,accessToken,baseUrl: getURL(),supportMode,diff --git a/apps/studio/pages/api/ai/sql/policy.ts b/apps/studio/pages/api/ai/sql/policy.tsindex 6edc896bd37..9f70dbf432c 100644--- a/apps/studio/pages/api/ai/sql/policy.ts+++ b/apps/studio/pages/api/ai/sql/policy.ts@@ -73,6 +73,7 @@ export async function handlePost(req: NextApiRequest, res: NextApiResponse, claiconst { tableName, schema, columns = [], projectRef, connectionString, orgSlug, message } = datalet aiOptInLevel: AiOptInLevel = 'disabled'+ let isRestrictedByHipaa = falseif (!IS_PLATFORM) {aiOptInLevel = 'schema'@@ -83,6 +84,7 @@ export async function handlePost(req: NextApiRequest, res: NextApiResponse, claiconst aiDetails = await getAIDetails({ orgSlug, projectRef, authorization })aiOptInLevel = aiDetails.aiOptInLevel+ isRestrictedByHipaa = aiDetails.isRestrictedByHipaa} catch (error) {return res.status(400).json({error: 'There was an error fetching your organization details',@@ -117,6 +119,7 @@ export async function handlePost(req: NextApiRequest, res: NextApiResponse, claiconnectionString,authorization,aiOptInLevel,+ isRestrictedByHipaa,accessToken,isExplorerEnabled: explorerEnabled,signal: toolsAbortController.signal,