Files
supabase/apps/studio/lib/ai/tools/index.ts
d60aceb562 Prompt and tool refactoring (#37500)
* try a really long context window to maximize caching

* update examples

* attempt to update packages and useChat

* update endpoints

* update zod

* zod

* update to v5

* message update

* Revert "zod"

This reverts commit ec39bac6b6.

* revert zod

* zod i

* fix complete endpoints

* remove async

* change to content

* type cleanup

* Revert the package bumps to rebuild them.

* Bump zod to 2.25.76 in all packages.

* Bump openai in all packages.

* Bump ai and ai-related packages.

* Remove unneeded files.

* Fix the rest of the migration stuff.

* Prettier fixes.

* add policy list tool

* refactor

* ai sdk 5 fixes

* refactor complete endpoint

* edge function prompt

* remove example

* slight prompt change

* Minor clean up

* More clean up

---------

Co-authored-by: Jordi Enric <jordi.err@gmail.com>
Co-authored-by: Ivan Vasilov <vasilov.ivan@gmail.com>
Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
2025-08-08 15:25:57 +07:00

61 lines
1.5 KiB
TypeScript

import { AiOptInLevel } from 'hooks/misc/useOrgOptedIntoAi'
import { filterToolsByOptInLevel } from '../tool-filter'
import { getFallbackTools } from './fallback-tools'
import { ToolSet } from 'ai'
import { IS_PLATFORM } from 'common'
import { getMcpTools } from './mcp-tools'
import { getSchemaTools } from './schema-tools'
import { getRenderingTools } from './rendering-tools'
export const getTools = async ({
projectRef,
connectionString,
authorization,
aiOptInLevel,
accessToken,
}: {
projectRef: string
connectionString: string
authorization?: string
aiOptInLevel: AiOptInLevel
accessToken?: string
}) => {
// Always include rendering tools
let tools: ToolSet = getRenderingTools()
// 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,
}),
}
}
// Filter all tools based on the (potentially modified) AI opt-in level
const filteredTools: ToolSet = filterToolsByOptInLevel(tools, aiOptInLevel)
return filteredTools
}