mirror of
https://github.com/supabase/supabase.git
synced 2026-10-05 01:15:03 +03:00
66 lines
1.6 KiB
TypeScript
66 lines
1.6 KiB
TypeScript
import { ToolSet } from 'ai'
|
|
import { IS_PLATFORM } from 'common'
|
|
|
|
import { filterToolsByOptInLevel } from '../tool-filter'
|
|
import { getFallbackTools } from './fallback-tools'
|
|
import { getIncidentTools } from './incident-tools'
|
|
import { getMcpTools } from './mcp-tools'
|
|
import { getSchemaTools } from './schema-tools'
|
|
import { getStudioTools } from './studio-tools'
|
|
import { AiOptInLevel } from '@/hooks/misc/useOrgOptedIntoAi'
|
|
|
|
export const getTools = async ({
|
|
projectRef,
|
|
connectionString,
|
|
authorization,
|
|
aiOptInLevel,
|
|
accessToken,
|
|
baseUrl,
|
|
}: {
|
|
projectRef: string
|
|
connectionString: string
|
|
authorization?: string
|
|
aiOptInLevel: AiOptInLevel
|
|
accessToken?: string
|
|
baseUrl?: string
|
|
}) => {
|
|
// Always include studio tools
|
|
let tools: ToolSet = getStudioTools()
|
|
|
|
// If self-hosted, only add fallback tools
|
|
if (!IS_PLATFORM) {
|
|
tools = {
|
|
...tools,
|
|
...getFallbackTools({
|
|
projectRef,
|
|
connectionString,
|
|
authorization,
|
|
includeSchemaMetadata: aiOptInLevel !== 'disabled',
|
|
}),
|
|
}
|
|
} else if (accessToken) {
|
|
// If platform, fetch MCP and other platform specific tools
|
|
const mcpTools = await getMcpTools({
|
|
accessToken,
|
|
projectRef,
|
|
aiOptInLevel,
|
|
})
|
|
|
|
tools = {
|
|
...tools,
|
|
...mcpTools,
|
|
...getSchemaTools({
|
|
projectRef,
|
|
connectionString,
|
|
authorization,
|
|
}),
|
|
...(baseUrl ? getIncidentTools({ baseUrl }) : {}),
|
|
}
|
|
}
|
|
|
|
// Filter all tools based on the (potentially modified) AI opt-in level
|
|
const filteredTools: ToolSet = filterToolsByOptInLevel(tools, aiOptInLevel)
|
|
|
|
return filteredTools
|
|
}
|