Repository navigation
feat(studio): notebook query and mutation hooks - #48907
Conversation
Adds getNotebook/useNotebookQuery, useNotebooksInfiniteQuery, and createNotebook/updateNotebook + their mutation hooks in a new data/content/notebooks/ module, following the studio-queries conventions. Cell ids are backend-generated (never client-supplied) and cell SQL must already be a SafeSqlFragment/SafeLogSqlFragment proven at a user-action event handler, per the safe-sql-execution skill — so notebook-schema.ts gains a writable schema/type pair with optional per-cell ids, and content-remap.ts's notebook unmap path is simplified to a passthrough since writes always arrive already wire-shaped.
|
This pull request has been ignored for the connected project Preview Branches by Supabase. |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
5 Skipped Deployments
|
📝 WalkthroughWalkthroughThe PR adds writable notebook schemas, notebook retrieval and listing hooks, create and update mutations, and tests. Notebook wire content now bypasses reverse cell remapping. ChangesNotebook content lifecycle
Estimated code review effort: 3 (Moderate) | ~25 minutes Possibly related PRs
Suggested reviewers: Sequence Diagram(s)sequenceDiagram
participant NotebookMutation
participant writableNotebookSchema
participant upsertContent
participant ContentAPI
participant ReactQueryCache
NotebookMutation->>writableNotebookSchema: Validate notebook payload
writableNotebookSchema-->>NotebookMutation: Return validated payload
NotebookMutation->>upsertContent: Create or update notebook
upsertContent->>ContentAPI: Send notebook content
ContentAPI-->>upsertContent: Return mutation result
upsertContent-->>NotebookMutation: Resolve mutation
NotebookMutation->>ReactQueryCache: Invalidate related content queries
🚥 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: 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/data/content/notebooks/notebook-query.ts`:
- Around line 17-26: Update the generated API contract to include `notebook` in
`GetUserContentResponse`, `GetUserContentByIdResponse`, and `UpsertContentBody`,
then remove the temporary casts and type guards from `notebook-query.ts`,
`notebook-query.test.ts`, `notebooks-infinite-query.ts`,
`notebooks-infinite-query.test.ts`, and `notebook-upsert-mutation.ts` so these
fetchers, tests, and mutations use the generated notebook types directly.
🪄 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: ca4f4884-0dec-42e0-afe3-8b757a2ecdc7
📒 Files selected for processing (10)
apps/studio/data/content/content-remap.test.tsapps/studio/data/content/content-remap.tsapps/studio/data/content/notebooks/notebook-query.test.tsapps/studio/data/content/notebooks/notebook-query.tsapps/studio/data/content/notebooks/notebook-schema.test.tsapps/studio/data/content/notebooks/notebook-schema.tsapps/studio/data/content/notebooks/notebook-upsert-mutation.test.tsapps/studio/data/content/notebooks/notebook-upsert-mutation.tsapps/studio/data/content/notebooks/notebooks-infinite-query.test.tsapps/studio/data/content/notebooks/notebooks-infinite-query.ts
🎭 Playwright Test Results (next)Details
Skipped testsFeatures › auth-users.spec.ts › should show web3 users as enabled when the matching web3 provider is enabled |
Braintrust eval report
|
## Summary - Adds `list_notebooks` (cursor-paginated) and `get_notebook` AI tools in `lib/ai/tools/notebook-tools.ts`, modeled directly on `report-tools.ts`: server-side `getContent`/`getNotebook` with the `authorization` header forwarded, zod-validated input. - `get_notebook` resolves every cell and exposes `unchecked_sql` as a plain `sql` field for the agent to read — display only, per the `safe-sql-execution` skill; nothing here executes SQL. - Registers both tools in `lib/ai/tools/index.ts` (same platform branch as reports) and in `lib/ai/tool-filter.ts`'s `toolSetValidationSchema` + `TOOL_CATEGORY_MAP` (`SCHEMA` tier). - Adds an optional `headers` param to `content-infinite-query.ts`'s `getContent`, mirroring the sibling `content-query.ts`, so the cursor-paginated fetch can carry the `Authorization` header from a server context. - New tools are behind the Explorer feature flag. Stacked on #48907 (1.4 — notebook query and mutation hooks), per the Notebooks implementation plan (stack 2.1). Resolves FE-4081 Resolves FE-4080 ## Test plan - [x] `pnpm exec tsc --noEmit` — no new errors - [x] `pnpm exec vitest run lib/ai/tools/notebook-tools.test.ts lib/ai/tools/index.test.ts lib/ai/tools/report-tools.test.ts data/content/notebooks` — 36/36 passing - [x] `pnpm --filter studio run lint` — no new warnings - [x] `pnpm exec prettier --check` on changed files — clean <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added AI tools to list project notebooks with pagination. * Added AI support for retrieving notebook markdown and resolved SQL cell content. * Notebook tools now respect project and authorization context. * Notebook features are available only when Explorer access is enabled. * Content requests can forward custom request headers. * **Tests** * Added coverage for notebook tools, Explorer access, feature flags, authorization, pagination, and error handling. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
Summary
Implements the "notebook query and mutation hooks" step of the notebooks data layer:
data/content/notebooks/notebook-query.ts—getNotebook/useNotebookQuery, wrapping the existinggetContentByIdand narrowing totype: 'notebook'.data/content/notebooks/notebooks-infinite-query.ts—useNotebooksInfiniteQuery, a typed wrapper overuseContentInfiniteQuerynarrowing pages to notebook rows.data/content/notebooks/notebook-upsert-mutation.ts—createNotebook/updateNotebook+ their mutation hooks, PUTting through the existingupsertContent.Write-path correctness, worked out while building the mutation hooks:
ids are always backend-generated, never client-supplied — a brand-new cell has noidat all; an existing cell being kept/edited in an update keeps its real id so the backend can diff it against the previous version.notebook-schema.tsgainswritableCellSchema/writableNotebookSchema(ids optional per cell) andWritableCell/WritableNotebooktypes, derived fromz.inferof those schemas rather than hand-duplicated, with only thesqlfield re-branded per cell type via a small distributive conditional type.SafeSqlFragment/SafeLogSqlFragment(proven user-authored at a save/run event handler), notunchecked_sql— matching thesafe-sql-executionskill's provenance model.content-remap.ts's notebookunmapSqlContentFieldbranch is simplified to a passthrough: notebook writes only ever arrive already wire-shaped viacreateNotebook/updateNotebook, so there's nothing left to unmap.Note: this was originally stacked on
feature/notebooks-types-convergence, but that branch merged intomaster(#48905) while this PR was in progress, so it's rebased directly ontomasternow.Test plan
pnpm --filter studio run typecheckpassespnpm --filter studio exec vitest run data/content/notebooks data/content/content-remap.test.ts— 38/38 passingpnpm --filter studio exec eslintclean on all touched filesSummary by CodeRabbit
New Features
Bug Fixes