mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 15:39:13 +00:00
## Problem
The read-only notebook tools (`list_databases`, `list_notebooks`,
`get_notebook`) are still defined inline with `tool({...})`. The other
AI tools have moved to the tool contract pattern, so these three are
inconsistent with the rest.
## Solution
Migrate the three tools to the tool contract pattern: a contract file
plus a `.server.ts` implementation, registered in `TOOL_CONTRACTS`. They
are removed from `TOOL_CATEGORY_MAP` and kept in the allowlist.
Behavior is unchanged:
- `minOptInLevel: 'schema'`, same as before.
- `needsApproval: false`.
- `toModelOutput` returns the output unchanged, so the model sees the
same data at every opt-in level.
Stored-shape changes for replayed outputs:
- Replayed outputs are now validated against the output schema and
dropped if invalid. Previously they passed through unchecked.
- Zod strips unknown keys, so fields outside the schema no longer
replay.
- `status`, `region`, and `visibility` use plain `z.string()`, so new
enum values do not break replay.
## Review instructions
1. Run `pnpm exec vitest run lib/ai` in `apps/studio`. It should pass
(323 tests).
2. In `apps/studio/lib/ai/tools/registry.test.ts`, check the new
coverage: `toModelOutput` at all four opt-in levels, for both live and
replayed outputs, and invalid replayed outputs being dropped.
3. Confirm the three tools still appear for the schema opt-in level in
`tool-filter.test.ts` and `notebook-tools.test.ts`.
## Checklist
Check all before review:
- [x] I have read
[CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md)
- [x] If I wrote a new docs topic or edited an existing topic, I used
the `/write-the-docs` or `/edit-the-docs` skill, which applies the docs
[style
guide](https://github.com/supabase/supabase/tree/master/apps/docs/style-guide)
25 lines
899 B
TypeScript
25 lines
899 B
TypeScript
import { getAuthHeaders } from './auth-headers'
|
|
import { contract } from './get-notebook'
|
|
import { toolFromContract } from './tool-from-contract'
|
|
import type { ToolFactory } from './types'
|
|
import { getNotebook } from '@/data/content/notebooks/notebook-query'
|
|
import { toWireNotebook } from '@/data/content/notebooks/notebook-schema'
|
|
|
|
export const createTool: ToolFactory<typeof contract> = (ctx) => {
|
|
const { projectRef } = ctx
|
|
const authHeaders = getAuthHeaders(ctx.authorization)
|
|
|
|
return toolFromContract(contract, ctx, async ({ id }, { abortSignal }) => {
|
|
const notebook = await getNotebook({ projectRef, id }, abortSignal, authHeaders)
|
|
|
|
return {
|
|
id: notebook.id,
|
|
name: notebook.name,
|
|
description: notebook.description,
|
|
visibility: notebook.visibility,
|
|
updated_at: notebook.updated_at,
|
|
cells: toWireNotebook(notebook.content).cells,
|
|
}
|
|
})
|
|
}
|