Commit Graph
12 Commits
Author SHA1 Message Date
Saxon Fletcher 1a013ea2c8 feat(studio): render assistant notebook runs (#49362)
<img width="1944" height="1053" alt="image"
src="https://github.com/user-attachments/assets/74c6968b-5ad4-46f7-adcc-a144221877b2"
/>


## I have read the
[CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md)
file.

YES

## What kind of change does this PR introduce?

Assistant notebook-run UI, reusable result previews, and approval flow.

## Stack context

This stack is based on #49352 (`chore/assistant-tool-outcomes`) and
assumes #49350–#49352 merge first.

Review bottom to top:

1. #49361 — assistant notebook run tool
2. #49362 — assistant notebook run UI
3. #49364 — terminal-state polish

## What is the current behavior?

The `run_notebook` tool has no dedicated Assistant renderer, and the
shared notebook preview cannot display saved query results.

## What is the new behavior?

- Adds a run mode to the shared minified notebook preview.
- Adds a dedicated renderer for notebook-run tool parts and wires it
into `Message.Parts.tsx`.
- Loads the current notebook and presents all cells behind one **Run
notebook** approval.
- Renders database and Logs results inside their matching notebook cells
using the existing Explorer table/chart renderer and row-limit metadata.
- Gives cells with results separate bordered surfaces while preserving
the existing create/update layouts.
- Warns when the notebook changed before approval or since a historical
run.
- Preserves raw run results for the user while the model receives
separately sanitized output.
- Handles malformed input and notebook-loading failures without hiding
the approval state.

## How to test manually

This PR now contains both the reusable result preview and the
`tool-run_notebook` Assistant wiring, so it can be tested directly from
this branch. #49364 is not required for the notebook-run UI path.

1. Create and save a notebook with at least six cells. Include:
   - a markdown cell
   - a database query that returns rows
   - a query that returns no rows
   - a query that fails
   - a Logs query
   - a database query with a row limit
2. Ask the AI Assistant: **Read this notebook and analyze it using its
current results.**
3. Confirm the approval card displays the notebook name and current
cells, with one **Run notebook** button and one **Skip** action.
4. Click **Skip** and confirm the card remains visible with **Skipped
notebook run**.
5. Ask again and click **Run notebook**. Confirm the card enters a
running state, then shows **Notebook executed** with each result under
the cell that produced it.
6. Confirm the successful empty query says **Success. No rows returned**
and shows **0 rows**.
7. Confirm the failed query shows its error without hiding the other
cell results.
8. Confirm row counts and database row-limit copy appear below the
corresponding results.
9. Confirm only the first five cells are initially visible, then click
**Show more cells** and verify the remaining cells appear.
10. Refresh or reopen the conversation and confirm the completed
notebook preview and results remain visible.
11. Start another run but leave it awaiting approval. Edit and save the
notebook in another tab, then return and confirm the card warns
**Notebook changed since the Assistant read it**.
12. Complete a run, then edit and save the notebook. Reopen the
conversation and confirm the historical card warns **Notebook changed
since this run**.
13. Ask the Assistant to create or update a notebook and confirm those
proposal previews retain their grouped layout.

## Automated test

`mise exec node@22 -- pnpm --dir apps/studio exec vitest --run
components/ui/AIAssistantPanel/AssistantNotebookPreview.test.tsx
components/ui/AIAssistantPanel/NotebookRunRenderer.test.tsx`

12 tests pass at this stack boundary.
2026-08-25 18:16:34 +10:00
CharisandJoshen Lim 89b4f1aca4 feat(studio): add delete_notebook tool to AI assistant (#49413)
## Summary

* Adds a `delete_notebook` AI assistant tool (`needsApproval: true`)
that lets the assistant delete a notebook with explicit user approval,
mirroring the existing `create_notebook`/`update_notebook` tools.
* Wires up a destructive-styled approval card in the AI Assistant Panel
(fetches the notebook to show its name, warns the deletion is permanent)
using the same `Confirm`/tool-approval plumbing as the other notebook
tools.
* Updates `tool-filter.ts` opt-in gating, the assistant system prompt,
the eval-harness mock tools, and the eval dataset with `delete_notebook`
coverage.
* Adds test coverage in `notebook-tools.test.ts`, `mock-tools.test.ts`,
and `NotebookProposalRenderer.test.tsx`.

Closes
[FE-4242](https://linear.app/supabase/issue/FE-4242/assistant-delete-notebook-tool).

## Test plan

- [X] `pnpm typecheck --filter=studio` passes
- [X] `pnpm --filter studio exec vitest run` for the touched files
(notebook-tools, mock-tools, NotebookProposalRenderer,
[Message.Parts](<http://Message.Parts>), and existing consumers of
`content-delete-mutation`) — all passing
- [X] `eslint` and `prettier --check` clean on all touched files
- [X] Manual verification of the approval UI in a running Studio
instance (not done in this session)

## Summary by CodeRabbit

* **New Features**
* Added AI-assisted notebook deletion with explicit confirmation and
irreversible-action warnings.
* Added safeguards to distinguish deleting an entire notebook from
removing individual panels.
* Completed deletions now display the deleted notebook’s name without an
option to reopen it.
* **Bug Fixes**
* Improved handling of missing notebooks and invalid deletion requests.
* **Tests**
* Added coverage for deletion approval, denial, errors, and successful
completion.

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* Added AI-assisted notebook deletion with explicit approval and
irreversible-action warnings.
* Added confirmation, loading, error, and completion states for notebook
deletion.
* Prevented accidental full-notebook deletion when only a panel or
section should be removed.
* Improved notebook update results by showing applied changes when
available.

* **Bug Fixes**
  * Notebook deletion now uses the required API version.
* Improved handling and validation of missing notebooks during deletion.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
2026-08-24 13:18:12 -04:00
Charis 233cbdc8e5 Restore notebook diff preview for completed updates (#49402)
## Summary

This is **PR 3 of 3** in the FE-4243 stack fixing "Notebook update
proposal shows 'unapplyable' error for already-completed updates."

- Consumes the `previous_content` field added by PR 2 (#49401) to
reconstruct diffs for already-applied notebook updates
- Restores the diff preview that PR 1 initially dropped — completed
updates now show the full before/after instead of a generic "Notebook
updated" message
- Uses the same diff derivation function called pre-approval,
guaranteeing the rendered diff matches what was shown during
confirmation
- Includes defensive fallback handling for older persisted chats (before
`previous_content` existed) and edge cases

**Depends on**: PR 2 (#49401) merging first — this PR consumes the
`previous_content` field from that server change.

Resolves FE-4243 

## Test plan

- ✅ 19/19 tests pass in NotebookProposalRenderer.test.tsx (2 confirmed
as real regressions)
- ✅ 118/118 tests pass in full AIAssistantPanel suite
- ✅ Typecheck: clean on modified files
- ✅ ESLint: zero errors/warnings on changed files  
- ✅ Lint ratchet: passes (some rules improved)
- ✅ New regression tests cover: delete_cell, insert_cell, missing
previous_content, and operations that no longer reconcile
- ✅ No notebook fetch in completed update tests (proves no redundant
re-fetching)

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* Added visual previews showing notebook changes, including inserted and
deleted cells, when prior content is available.
  * Prevented duplicate cells from appearing in update previews.
* Retained a compact completion message when change details are
unavailable or inconsistent.
  * Ensured previews are shown only for the relevant notebook.

* **Tests**
* Added coverage for notebook update previews, deletion and insertion
diffs, duplicate prevention, notebook matching, and fallback behavior.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-08-21 15:09:44 -04:00
Charis 79fbe467ba feat(studio): wire notebook create/update proposals into assistant panel (#49159)
## Summary

PR 4 of the notebook-approval-preview stack.

- Adds `NotebookProposalRenderer`, wiring
`create_notebook`/`update_notebook` into `MessagePartSwitcher` and
rendering `NotebookPreview` across all 6 tool states (drafting,
approval-requested, approval-responded, output-available, output-denied,
output-error).
- `update_notebook` fetches the live notebook via `useNotebookQuery`,
checks `expected_updated_at` against the fetched `updated_at`, and gates
the confirm action behind a refresh when stale.
- A tool-input parse failure renders a raw-input admonition instead of
returning `null`, so `ConfirmFooter` — and the ability to Skip/deny —
stays available rather than leaving the chat stuck.

Towards FE-4143

## Test plan

- [x] `tsc --noEmit` clean
- [x] `eslint` clean on touched files
- [x] `prettier --check` clean
- [x] New `NotebookProposalRenderer.test.tsx` (create/update previews +
approve, version-mismatch warning, parse-failure fallback with working
Skip, output-available/output-denied summaries)
- [x] Existing notebook test suites (`notebook-tools.test.ts`,
`notebook-operations`, `NotebookPreview`) still pass

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **New Features**
* Added AI-assisted notebook creation and updating with previews,
approval controls, and operation summaries.
* Added clear handling for loading, errors, denied actions, stale
notebook versions, and invalid proposals.
  * Added links to open notebooks after successful creation or updates.
  * Preserved notebook SQL content when displaying proposed changes.

* **Bug Fixes**
* Improved notebook proposal handling for conflicts and incomplete tool
responses.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-08-18 11:56:50 -04:00
Charis 465121894d studio: add sql provenance tracking to ai assistant + reports (#45608) 2026-05-06 09:14:45 -04:00
Matt Rossman f49ed14dfb fix(assistant): preserve template URL placeholders in responses (#43495)
Fixes a rendering bug where template URLs like
`https://<project-ref>.supabase.co/...` were displayed incorrectly in
Assistant responses. The markdown parser was treating `<project-ref>` as
a tag and silently stripping it.

- Adds `wrapPlaceholderUrls()` preprocessing step that auto-wraps bare
URLs containing `<kebab-case>` placeholders in backticks before passing
to the markdown renderer
- Strengthens the prompt instruction to explicitly say "always format
template URLs as inline code using backticks"

Sample prompt:
```
What are the OAuth2 endpoints for Supabase projects? List the authorization, token, and JWKS URLs.
```

| Before | After |
|--------|--------|
| <img width="1314" height="841" alt="CleanShot 2026-03-06 at 15 32
13@2x"
src="https://github.com/user-attachments/assets/55eaa0c6-39fb-48e0-91a0-31903021a4c9"
/> | <img width="1421" height="827" alt="CleanShot 2026-03-06 at 15 31
37@2x"
src="https://github.com/user-attachments/assets/5335c71a-19c7-44a0-b027-6f2efd76eb8c"
/> |

Closes AI-470
2026-03-11 13:56:43 -04:00
Saxon Fletcher d5bf4ef13b Rate assistant responses (#39224)
* rate assistant responses

* test

* always show
2025-10-06 22:46:30 +00:00
626eb30e77 Assistant action orientated approach (#38806)
* update onboarding

* update model and fix part issue

* action orientated assistant

* fix tool

* lock

* remove unused filter

* fix tests

* fix again

* update package

* update container

* fix tests

* refactor(ai assistant): break out message markdown and profile picture

* wip

* refactor(ai assistant): break up message component

* refactor: break ai assistant message down into multiple files

* refactor: simplify ReportBlock state

* fix: styling of draggable report block header

When the drag handle is showing, it overlaps with the block header.
Decrease the opacity of the header so the handle can be seen and the two
can be distinguished.

* fix: minor tweaks to tool ui

* refactor: simplify DisplayBlockRenderer state

* fix: remove double deploy button in edge function block

When the confirm footer is shown, the deploy button on the top right should be
hidden (not just disabled) to avoid confusion.

* refactor, test: message sanitization by opt-in level

Refactor the message sanitization to have more type safety and be more testable.
Add tests to ensure:

- Message sanitization always runs on generate-v4
- Message sanitization correctly works by opt-in level

* Fix conflicts in pnpm lock

* Couple of nits and refactors

* Revert casing for report block snippet

* adjust sanitised prompt

* Fix tests

---------

Co-authored-by: Charis Lam <26616127+charislam@users.noreply.github.com>
Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
2025-09-29 03:57:36 +00:00
d52e2c252b Update AI SDK 5 (#37656)
* 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.

* zod

* v4 again

---------

Co-authored-by: Jordi Enric <jordi.err@gmail.com>
Co-authored-by: Ivan Vasilov <vasilov.ivan@gmail.com>
2025-08-08 14:15:39 +07:00
Joshen Lim 63164fe165 Revert "Revert "Feature/assistant mcp"" (#36687)
* Revert "Revert "Feature/assistant mcp" (#36684)"

This reverts commit 2bff117cde.

* Attempt
2025-06-26 15:02:49 +08:00
Joshen Lim 2bff117cde Revert "Feature/assistant mcp" (#36684)
Revert "Feature/assistant mcp (#35318)"

This reverts commit 3a50dd1f72.
2025-06-26 13:06:50 +08:00
3a50dd1f72 Feature/assistant mcp (#35318)
* step 1

* use mcp

* system prompt

* clean up

* space

* clean up

* add three state opt in toggle

* clean up

* todo

* hooks

* refactor opt in form and modal

* refinements

* add bedrock

* remove console

* update mcp util

* use bedrock

* remove openai sdk package

* re-add tools

* update complete endpoints

* fix: ai assistant markdown formatting (#35541)

* fix: mcp types and project ref (#35540)

* feat: more flexible aws credential provider (#35538)

* feat: more flexible aws credential provider

* fix: add AWS_REGION to turbo env vars

* change to allowed

* update complete endpoints

* add an additional permission

* refinements

* use claud 4

* legal copy changes

* update other ai functions to use bedrock

* update generate v3 copy

* remove generate sql modal

* fixes for query block

* re-add dragging to reports

* clean up

* add open ai edge function example

* use handle error from fetchers

* remove schema and lean on tools

* copy

* Assistant MCP tests (#36049)

* feat: refactor and test mcp and model logic

* fix: remove get_project tool

* fix: remove additional get_project tool references

* update copy

* Clean up, fixes, refactors

* oops

* Float errors from AI endpoionts as toasts

* Use a env var AWS_BEDROCK_PROFILE for bedrock.

* Rename the env var for AWS bedrock profile.

* feat: support custom aws bedrock env vars

* chore: add comments explaining aws credential chain

* MCP Self Hosted Check (#36185)

support self hosted

* feat: bedrock auth via vercel oidc

* Fix broken unit test

* Feeeex

* Refactor useOrgOptedIntoAi

* Remove useDisallowHipaa hook

* small system prompt change

* readd vercel packages

* fix self hosted

* increase max duration

* try more direct prompt

* max duration 90

* reduce max steps and add loading

* mono font

* backwards compat styling

* Chore/limit number of messages sent to assistant (#36388)

* Limit number of historical messages that get sent to assistant

* Update max chat history to 5

* alignment

* bump mcp server version

* Add feature flag for opt in tags (#36466)

* Add feature flag for opt in tags

* Add one more check

* security section system prompt

* rely on default link and replace image markdown

* Add custom link component to assistant message block (#36527)

* Add custom link component to assistant message block

* Update based on feedback

* Render plain text if URL is deemed unsafe

* fix mcp tools and parse data (#36593)

* Update Admonition for AI Assistant for when opt in is re-enabled (#36663)

* Update Admonition for AI Assistant for when opt in is re-enabled

* Update

* Smol fix

* Fix TS

* Tiny

---------

Co-authored-by: Greg Richardson <greg.nmr@gmail.com>
Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
Co-authored-by: Ivan Vasilov <vasilov.ivan@gmail.com>
2025-06-26 12:13:27 +08:00