mirror of
https://github.com/supabase/supabase.git
synced 2026-12-06 00:19:08 +00:00
Enables Braintrust tracing and feedback for Assistant chats on EU-region projects. This was the final holdout that makes it so that tracing is applied consistently across all projects. Adds `projectRegion` metadata to root traces so the project’s region is recorded with each chat (consistent with the existing [isHighComplianceProject metadata](https://github.com/supabase/supabase/blob/917dcb388939b8c54ea13c1e31b3c7285fb2ca65/apps/studio/lib/ai/generate-assistant-response.ts#L188)). Verified in staging with a [successful Assistant trace recording `projectRegion: eu-central-1`](https://www.braintrust.dev/app/supabase.io/p/Assistant/logs?r=1b4a05d7a6c1414e62f532094aa39dc1&sid=4fdc76b08a4c5a43). <img width="2656" height="1560" alt="CleanShot 2026-11-12 at 1 12 30 PM@2x" src="https://github.com/user-attachments/assets/4e81033a-c754-46db-845d-586d1d71e035" /> Closes AI-1197
70 lines
2.4 KiB
TypeScript
70 lines
2.4 KiB
TypeScript
import { getProjectSettings } from '@/data/config/project-settings-v2-query'
|
|
import { checkEntitlement } from '@/data/entitlements/entitlements-query'
|
|
import { getOrganizations } from '@/data/organizations/organizations-query'
|
|
import { getProjectDetail } from '@/data/projects/project-detail-query'
|
|
import { getAiOptInLevel, type AiOptInLevel } from '@/hooks/misc/useOrgOptedIntoAi'
|
|
|
|
export type AIDetails = {
|
|
aiOptInLevel: AiOptInLevel
|
|
hasAccessToAdvanceModel: boolean
|
|
orgId: number | undefined
|
|
orgSlug: string | undefined
|
|
planId: string | undefined
|
|
projectRegion: string | undefined
|
|
/** "High Compliance" in the dashboard, `is_sensitive` in the platform API. */
|
|
isHighComplianceProject: boolean | undefined
|
|
}
|
|
|
|
// Resolves the AI opt-in level, model access and tracing inputs for one org/project pair.
|
|
// Both identifiers come from the request body, so an unconfirmed pairing resolves to the
|
|
// most restrictive posture rather than the requested one.
|
|
export const getAIDetails = async ({
|
|
orgSlug,
|
|
projectRef,
|
|
authorization,
|
|
}: {
|
|
orgSlug: string
|
|
projectRef: string
|
|
authorization: string
|
|
}): Promise<AIDetails> => {
|
|
const headers = {
|
|
'Content-Type': 'application/json',
|
|
...(authorization && { Authorization: authorization }),
|
|
}
|
|
|
|
const [organizations, advanceModelAccess, project, projectSettings] = await Promise.all([
|
|
getOrganizations({ headers }),
|
|
checkEntitlement(orgSlug, 'assistant.advance_model', undefined, headers),
|
|
// Organization membership can be checked without waking the project.
|
|
getProjectDetail({ ref: projectRef, skipWake: true }, undefined, headers),
|
|
getProjectSettings({ projectRef }, undefined, headers),
|
|
])
|
|
|
|
const selectedOrg = organizations.find((org) => org.slug === orgSlug)
|
|
const isHighComplianceProject = projectSettings?.is_sensitive ?? undefined
|
|
|
|
const isProjectInOrg = selectedOrg !== undefined && project?.organization_id === selectedOrg.id
|
|
|
|
if (!isProjectInOrg) {
|
|
return {
|
|
aiOptInLevel: 'disabled',
|
|
hasAccessToAdvanceModel: false,
|
|
orgId: undefined,
|
|
orgSlug: undefined,
|
|
planId: undefined,
|
|
projectRegion: undefined,
|
|
isHighComplianceProject: undefined,
|
|
}
|
|
}
|
|
|
|
return {
|
|
aiOptInLevel: getAiOptInLevel(selectedOrg.opt_in_tags),
|
|
hasAccessToAdvanceModel: advanceModelAccess.hasAccess,
|
|
orgId: selectedOrg.id,
|
|
orgSlug: selectedOrg.slug,
|
|
planId: selectedOrg.plan.id,
|
|
projectRegion: project?.region,
|
|
isHighComplianceProject,
|
|
}
|
|
}
|