Files
supabase/apps/studio/lib
Charis 6397239315 refactor(studio): replay removed Assistant tool outputs through legacy contracts (#52398)
Stacked on #52396.

## What

Self-hosted Studio's Assistant uses four fallback tools
(`getSchemaTables`, `getRlsKnowledge`, `getFunctions`,
`getEdgeFunctionKnowledge`) that a later PR replaces with contract
tools. Saved chats in IndexedDB still hold their outputs, and today
those replay to the model unchecked.

- New `LegacyToolContract` type: only `name`, `outputSchema`,
`toModelOutput`, and `outputOnInvalid`.
- New `tools/legacy-tools.ts` with a legacy contract for each fallback
tool. Only history replay reads them, through `sanitizeContractPart`;
nothing registers them as tools.
- Schema tables, RLS policies, and function lists replay at the `schema`
opt-in level and above; below it, the model gets a short note instead.
The Edge Functions guide has no project data, so it replays at every
level.
- A saved output that doesn't match its stored shape is replaced with a
short "couldn't be read" note.
- README documents legacy contracts.

## Behavior changes

Self-hosted always runs at the `schema` level, so valid saved outputs
replay as before. Malformed saved outputs are now replaced instead of
passed through.

## Tests

- `legacy-tools.test.ts` covers every stored shape at every opt-in
level, plus invalid outputs.
- `registry.test.ts` checks legacy names don't overlap live contract
names.
- A saved self-hosted chat replays through `prepareMessagesForModel` and
`convertToModelMessages` without errors.

## Checklist

Check all before review:

- [x] I have read
[CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md)
- [ ] 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)
2026-10-28 08:21:38 -04:00
..
…