Repository navigation
feat(studio): wire update_notebook tool - #48949
Conversation
Re-fetches the notebook, applies the requested cell operations from notebook-operations.ts, and PUTs the resolved content — last-write-wins, since re-fetching at execute time is the only mitigation for concurrent edits per the RFC. refactor(studio): inline SQL promotion next to each needsApproval gate Un-shares the untrusted-to-safe SQL promotion between create_notebook and update_notebook so it's visible directly beside each tool's own needsApproval: true, rather than in a helper a reader has to jump to.
toWireCell downcasts a cell's branded unchecked_sql to a plain sql: string, matching CellWire's wire schema. Document that this is intentional and that the only place user approval is granted for that SQL is the inline acceptUntrustedSql/acceptUntrustedLogsSql promotion beside each tool's own needsApproval: true, so a reader isn't left wondering where the brand went.
…call site A shared helper that strips the unchecked_sql brand down to a plain string is reusable by any future caller that has no reason to know the result must be re-promoted before use. Inline the conversion separately in get_notebook (display only) and in update_notebook, where it now sits directly inside the same execute as that tool's own needsApproval: true and its later acceptUntrustedSql/acceptUntrustedLogsSql re-promotion.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
5 Skipped Deployments
|
|
This pull request has been ignored for the connected project Preview Branches by Supabase. |
📝 WalkthroughWalkthroughThe PR adds an approved ChangesNotebook update workflow
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant AI as AI assistant
participant update_notebook
participant NotebookAPI as Notebook API
AI->>update_notebook: Submit notebook operations
update_notebook->>NotebookAPI: Refetch latest notebook
NotebookAPI-->>update_notebook: Return notebook content
update_notebook->>update_notebook: Apply validated operations
update_notebook->>NotebookAPI: Persist updated notebook
NotebookAPI-->>update_notebook: Return updated notebook
update_notebook-->>AI: Return notebook id and name
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 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 |
🎭 Playwright Test Results (next)Details
Flaky testsFeatures › realtime-inspector.spec.ts › Realtime Inspector › Basic Inspector UI › channel selection popover opens and works Skipped testsFeatures › auth-users.spec.ts › should show web3 users as enabled when the matching web3 provider is enabled |
Braintrust eval report
|
## Summary - Adds deterministic `list_notebooks`/`get_notebook` fixtures (two seeded notebooks, each with markdown/database/log cells) and stateful in-memory `create_notebook`/`update_notebook` mocks to `apps/studio/lib/ai/tools/mock-tools.ts`, so Braintrust evals can exercise notebook tool calls without a real project. - Both write-tool mocks force `needsApproval: false`, matching the existing `execute_sql`/`deploy_edge_function` mock pattern — the eval harness filters out tool-parts in `'approval-requested'` state and can never answer an approval gate. - All four notebook tools are wrapped from the real `getNotebookTools()` definitions (only `execute`/`needsApproval` overridden), so evals validate the model's arguments against the exact production schemas. - Dedupes `describeOperationError` (previously duplicated between this new mock and `notebook-tools.ts`) into a single exported `describeNotebookOperationError` in `notebook-operations.ts`. **Stacked on #48949** (`feature/notebooks-update-tool`) — this PR's base branch is that PR, not `master`, because it reuses `update_notebook` and the shared error helper that only exist there. Merge #48949 first, then retarget/merge this one. ## Test plan - [x] \`pnpm --filter studio typecheck\` passes - [x] \`pnpm --filter studio test\` — all notebook-related suites pass (\`mock-tools.test.ts\`, \`notebook-tools.test.ts\`, \`data/content/notebooks/*\`) - [x] \`eslint\` / \`prettier --check\` clean on all touched files
Summary
update_notebook, an AI tool (needsApproval: true) that re-fetches a notebook, applies an ordered list of cell operations (insert/replace/delete/move, fromnotebook-operations.ts) viaapplyNotebookOperations, and PUTs the resolved content. Concurrent edits are last-write-wins, since re-fetching at execute time is the only mitigation per the RFC.update_notebookintoolSetValidationSchema/TOOL_CATEGORY_MAP, and documents it in the notebooks system prompt.acceptUntrustedSql/acceptUntrustedLogsSql) is inlined directly inside eachneedsApproval: truetool's ownexecute(bothcreate_notebookandupdate_notebook), rather than behind a shared helper — kept auditable right next to the approval gate that authorizes it, and not reusable by an unrelated caller unaware it needs re-promotion.Resolves FE-4083
Test plan
notebook-tools.test.ts: re-fetch → apply operations → PUT with promoted SQL; descriptive error (no PUT) when an operation targets an unknown cell id;needsApprovalasserted for both create and updatepnpm vitest runonnotebook-tools.test.ts,tools/index.test.ts,tool-filter.test.ts— all passtsc --noEmit,eslint,prettier --check— clean on all touched filesSummary by CodeRabbit
New Features
Bug Fixes