Repository navigation
feat(studio): create_notebook AI tool - #48938
Conversation
- Tool requires user approval (`needsApproval: true`); SQL cells promoted from untrusted to safe via `acceptUntrustedSql`/`acceptUntrustedLogsSql` using approval as trust boundary - Agent-supplied cell IDs rejected at schema level to prevent ID conflicts - Registered in tool-filter (SCHEMA category alongside `list_notebooks`/`get_notebook`) - Added prompt guidance section documenting when to use create_notebook vs one-off `execute_sql`
|
The latest updates on your projects. Learn more about Vercel for GitHub.
5 Skipped Deployments
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThe AI toolset now supports approval-gated notebook creation. It validates notebook content, promotes SQL after approval, persists the notebook, and returns its identifier. Content mutations accept optional headers and send ChangesNotebook creation flow
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant SQLGenerateAPI
participant generateAssistantResponse
participant AIChat
participant create_notebook
participant createNotebook
participant upsertContent
participant ContentAPI
SQLGenerateAPI->>generateAssistantResponse: explorerEnabled flag
generateAssistantResponse->>AIChat: Explorer-aware system prompt
AIChat->>create_notebook: approved notebook request
create_notebook->>create_notebook: validate and normalize notebook
create_notebook->>createNotebook: persist notebook with project context
createNotebook->>upsertContent: forward payload and request headers
upsertContent->>ContentAPI: PUT request with Version 2
ContentAPI-->>create_notebook: return notebook identifier and name
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@apps/studio/lib/ai/tools/notebook-tools.test.ts`:
- Line 274: Replace the Record<string, unknown> cast around request.json() in
the test setup with a local Zod schema and parse the captured body using parse
or safeParse. Update the assertions around the captured request body and its
cells to use the validated parsed result, removing the related TypeScript casts
at the additional referenced lines.
In `@apps/studio/lib/ai/tools/notebook-tools.ts`:
- Line 130: Update createNotebook and its return path so successful results
always contain a defined notebook ID: preserve the generated ID through
upsertContent, or fail the tool call when the create response lacks one. Add a
test covering a no-content create response and verify it cannot return id:
undefined.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 42c4e0e4-b358-4095-9dd7-48fa4be9806c
📒 Files selected for processing (6)
apps/studio/data/content/content-upsert-mutation.tsapps/studio/data/content/notebooks/notebook-upsert-mutation.tsapps/studio/lib/ai/prompts.tsapps/studio/lib/ai/tool-filter.tsapps/studio/lib/ai/tools/notebook-tools.test.tsapps/studio/lib/ai/tools/notebook-tools.ts
🎭 Playwright Test Results (tanstack)Details
Flaky testsFeatures › database.spec.ts › Database › Schema Visualizer › table actions work as expected Skipped testsFeatures › auth-users.spec.ts › should show web3 users as enabled when the matching web3 provider is enabled |
🎭 Playwright Test Results (next)Details
Flaky testsFeatures › queue-table-operations.spec.ts › Queue Table Operations › pending changes persist when switching between tables Skipped testsFeatures › auth-users.spec.ts › should show web3 users as enabled when the matching web3 provider is enabled |
The content upsert endpoint returns no body on success (200 with an empty response), so createNotebook was returning id: undefined on every successful create. Return the id generated before the request instead of trying to read one back from the response.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@apps/studio/lib/ai/tools/notebook-tools.test.ts`:
- Line 275: Update both mock handlers in the notebook tools test to return a
bodyless success response using HttpResponse with a null body instead of
HttpResponse.json(null), ensuring the bodyless success path is exercised.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: a0257b4c-73ac-4abe-9f0b-68b8d20f52db
📒 Files selected for processing (3)
apps/studio/data/content/notebooks/notebook-upsert-mutation.tsapps/studio/lib/ai/tools/notebook-tools.test.tsapps/studio/lib/ai/tools/notebook-tools.ts
🚧 Files skipped from review as they are similar to previous changes (2)
- apps/studio/lib/ai/tools/notebook-tools.ts
- apps/studio/data/content/notebooks/notebook-upsert-mutation.ts
HttpResponse.json(null) sends a non-empty "null" JSON body, which never exercises the empty-body normalization in data/fetchers.ts that these tests are meant to cover.
Braintrust eval reportAssistant (feature/notebooks-create-tool-1786460541)
|
The `## Notebooks` system prompt section told the assistant to call create_notebook unconditionally, even for users who don't have the explorer flag enabled and therefore can't see notebooks in the tool list or the UI. Split it into NOTEBOOKS_PROMPT and only splice it in when isExplorerEnabled resolves true, matching how the notebook tools themselves are already gated in lib/ai/tools/index.ts.
Braintrust eval report
|
## Summary - Pure module (`data/content/notebooks/notebook-operations.ts`) for applying `update_notebook` cell edits client-side: `insert_cell` (`after_cell_id` incl. `'start'`), `replace_cell`, `delete_cell`, `move_cell`. - Never touches the safe-sql brands — SQL promotion still happens at the tool-execute boundary, matching `create_notebook`. - Stacked on #48938. No wiring yet — `update_notebook` tool wiring is next. Towards FE-4083 ## Test plan - [x] `pnpm vitest run data/content/notebooks/notebook-operations.test.ts` — 13 unit tests covering every op, combinations, and all three error cases. - [x] `pnpm exec tsc --noEmit` clean - [x] `pnpm exec eslint` clean on new files <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added support for applying notebook cell operations, including insertion, replacement, deletion, and movement. * Operations are applied in a predictable order, with support for anchoring new cells at the beginning or near existing cells. * Added validation for invalid references, conflicting operations, and self-referential moves. * Added clear handling when operations produce an empty notebook result. * **Tests** * Added comprehensive coverage for individual, combined, ordered, conflicting, invalid, and empty-result notebook operations. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
Summary
create_notebookAI assistant tool (needsApproval: true) that lets the assistant create a new notebook after explicit user approval.acceptUntrustedSql/acceptUntrustedLogsSqlinsideexecute, using the approval gate as the confirming user gesture (same pattern asexecute_sql).idat the schema level.upsertContent/createNotebook/updateNotebookso the tool can pass its own bearer token server-side.SCHEMAcategory, alongsidelist_notebooks/get_notebook) and adds a## Notebooksprompt section guiding the assistant on when to usecreate_notebookvs. one-offexecute_sql.Resolves FE-4082
Test plan
notebook-tools.test.tscovers: tool registration,needsApproval, cell-id rejection, valid input, PUT body shape, and the returned id — all passingSummary by CodeRabbit
New Features
Improvements