Repository navigation
feat(studio): notebook read tools - #48908
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
5 Skipped Deployments
|
📝 WalkthroughWalkthroughChangesExplorer-gated notebook AI tools
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant SQLAPI
participant ExplorerCheck
participant ConfigCat
participant getTools
participant NotebookTools
SQLAPI->>ExplorerCheck: Check Explorer for trusted user email
ExplorerCheck->>ConfigCat: Retrieve explorer flag
ConfigCat-->>ExplorerCheck: Return feature flags
ExplorerCheck-->>SQLAPI: Return enabled state
SQLAPI->>getTools: Build tools with Explorer state
getTools->>NotebookTools: Register notebook tools when enabled
NotebookTools-->>SQLAPI: Provide list_notebooks and get_notebook
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 |
|
@coderabbitai review |
✅ Action performedReview finished.
|
There was a problem hiding this comment.
🧹 Nitpick comments (1)
apps/studio/lib/ai/tools/notebook-tools.ts (1)
47-47: 🗄️ Data Integrity & Integration | 🔵 Trivial | 🏗️ Heavy liftUpdate the generated content API contract for notebooks.
The generated types omit
notebook, which forces casts in the content queries,notebook-query.ts, and both test fixtures. Add notebook support and regenerate the types. Notebook content already passes throughnotebookDomainSchema.parse; do not add a duplicate parse innotebook-tools.ts.🤖 Prompt for 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. In `@apps/studio/lib/ai/tools/notebook-tools.ts` at line 47, Update the generated content API contract to include notebook support, then regenerate the types so casts are no longer needed in apps/studio/lib/ai/tools/notebook-tools.ts lines 35-35 and 47-47, and both fixtures in apps/studio/lib/ai/tools/notebook-tools.test.ts lines 75-75 and 132-132. Reuse the existing notebookDomainSchema.parse flow and do not add duplicate parsing in notebook-tools.ts.Source: Coding guidelines
🤖 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.
Nitpick comments:
In `@apps/studio/lib/ai/tools/notebook-tools.ts`:
- Line 47: Update the generated content API contract to include notebook
support, then regenerate the types so casts are no longer needed in
apps/studio/lib/ai/tools/notebook-tools.ts lines 35-35 and 47-47, and both
fixtures in apps/studio/lib/ai/tools/notebook-tools.test.ts lines 75-75 and
132-132. Reuse the existing notebookDomainSchema.parse flow and do not add
duplicate parsing in notebook-tools.ts.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 2788133a-d459-4e98-9d60-e6bda80226e0
📒 Files selected for processing (5)
apps/studio/data/content/content-infinite-query.tsapps/studio/lib/ai/tool-filter.tsapps/studio/lib/ai/tools/index.tsapps/studio/lib/ai/tools/notebook-tools.test.tsapps/studio/lib/ai/tools/notebook-tools.ts
🎭 Playwright Test Results (next)Details
Flaky testsFeatures › realtime-inspector.spec.ts › Realtime Inspector › Broadcast Messages › broadcast messages appear in the UI when listening Skipped testsFeatures › auth-users.spec.ts › should show web3 users as enabled when the matching web3 provider is enabled |
1c13973 to
2bf4d31
Compare
Adds list_notebooks (cursor-paginated) and get_notebook AI tools in a new lib/ai/tools/notebook-tools.ts, modeled on report-tools.ts: server-side getContent/getNotebook with forwarded authorization headers, zod-validated input. get_notebook resolves each cell's SQL, exposing unchecked_sql as a plain `sql` field for the agent to read (display only, never executed) per the safe-sql-execution skill. Registers both tools in lib/ai/tools/index.ts and lib/ai/tool-filter.ts as SCHEMA-tier tools, and adds header forwarding to content-infinite-query.ts's getContent so the cursor-paginated fetch can carry the Authorization header in a server context.
list_notebooks/get_notebook were unconditionally registered in getTools,
so the assistant would advertise and use notebook tools for every user
even though Notebooks/Explorer hasn't shipped yet (client-gated behind
useFlag('explorer')).
Threads a new isExplorerEnabled server check through both getTools call
sites (generate-v4.ts, policy.ts) so the tools are only merged into the
tool set when the flag resolves true for the requesting user.
The existing common/configcat.ts getFlags can't be reused as-is: it's
built for the browser — AutoPoll mode spins up a recurring background
timer and caches one client per tab. Neither holds up in a serverless
function (generate-v4.ts sets `maxDuration`, a Vercel Serverless
Functions signal): a lingering AutoPoll timer can hold an invocation
open, and the singleton only pays off on a warm container, so every
cold start still eats a full SDK init. Adds getServerFlags alongside
it, using LazyLoad mode (fetch-on-demand with a TTL, no background
timer) — ConfigCat's own recommended mode for server/serverless use —
with its own client, deliberately not sharing the browser one.
list_notebooks/get_notebook were unconditionally registered in getTools,
so the assistant would advertise and use notebook tools for every user
even though Notebooks/Explorer hasn't shipped yet (client-gated behind
useFlag('explorer')). Threads a new isExplorerEnabled server check
through both getTools call sites (generate-v4.ts, policy.ts).
The flag check needs its own server-side ConfigCat client, not a reuse
of anything in packages/common/configcat.ts:
- configcat-js (that module's dependency) hard-codes `new
XMLHttpRequest()` in its fetcher, which doesn't exist in a Node.js API
route.
- configcat-node, the obvious Node alternative, is legacy per
ConfigCat's own docs; @configcat/sdk (Node entrypoint) is current.
- AutoPoll mode (what the browser client uses) spins up a recurring
background timer and is explicitly called out by ConfigCat's docs as
unsuitable for short-lived serverless functions — these routes set
`maxDuration`, a Vercel Serverless Functions signal. Uses LazyLoad
instead (fetch-on-demand with a TTL, no background timer).
Adds apps/studio/lib/server/configcat.ts as an isolated, Node-only
module rather than extending packages/common/configcat.ts, so a
server-only client and dependency can't end up in a browser bundle.
Prefers the caching proxy (NEXT_PUBLIC_CONFIGCAT_PROXY_URL) over the
direct SDK key, same as the browser client, since the proxy caches and
saves on direct ConfigCat calls.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
apps/studio/lib/server/configcat.ts (1)
10-12: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winReplace the type assertion with Zod parsing.
Line 11 uses an
ascast to promote external data intoTrustedUserEmail. Parse the value before branding it. This keeps the runtime boundary aligned with the type boundary.Proposed change
+import { z } from 'zod' + -export type TrustedUserEmail = string & { readonly __trustedUserEmailBrand: never } +const trustedUserEmailSchema = z.string().brand<'TrustedUserEmail'>() +export type TrustedUserEmail = z.infer<typeof trustedUserEmailSchema> export function trustedUserEmail(email: string | undefined): TrustedUserEmail | undefined { - return email as TrustedUserEmail | undefined + return email === undefined ? undefined : trustedUserEmailSchema.parse(email) }As per coding guidelines, “Avoid TypeScript
ascasts; parse external data with zod usingparseorsafeParse.”🤖 Prompt for 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. In `@apps/studio/lib/server/configcat.ts` around lines 10 - 12, Update trustedUserEmail to validate the optional email at runtime with the existing Zod schema for TrustedUserEmail, returning the parsed branded value for valid input and undefined for absent or invalid input; remove the direct type assertion.Source: Coding guidelines
🤖 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.
Nitpick comments:
In `@apps/studio/lib/server/configcat.ts`:
- Around line 10-12: Update trustedUserEmail to validate the optional email at
runtime with the existing Zod schema for TrustedUserEmail, returning the parsed
branded value for valid input and undefined for absent or invalid input; remove
the direct type assertion.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 540d75c8-897a-4be3-b1f4-6178bc5aadd9
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml,!pnpm-lock.yaml
📒 Files selected for processing (9)
apps/studio/lib/ai/is-explorer-enabled.test.tsapps/studio/lib/ai/is-explorer-enabled.tsapps/studio/lib/ai/tools/index.test.tsapps/studio/lib/ai/tools/index.tsapps/studio/lib/server/configcat.test.tsapps/studio/lib/server/configcat.tsapps/studio/package.jsonapps/studio/pages/api/ai/sql/generate-v4.tsapps/studio/pages/api/ai/sql/policy.ts
2bf4d31 to
e1ae3ba
Compare
daltino
left a comment
There was a problem hiding this comment.
The isExplorerEnabled flag gating in index.ts looks correct, but I'm curious about the failure mode in notebook-tools.ts when projectRef is undefined — getContent will throw 'projectRef is required for getContent', which is fine, but the execute handler doesn't catch it, so that error will bubble up raw to the AI SDK. The sibling report-tools.ts probably has the same pattern, but it's worth considering whether a consistent "tool unavailable" response shape would give the agent better recovery behavior than an uncaught exception.
Also, categorizing list_notebooks and get_notebook under TOOL_CATEGORIES.SCHEMA feels like a semantic stretch — these are user-saved notebooks, not schema metadata. A CONTENT or WORKSPACE category might be more accurate, especially as the category map grows and you need to reason about what's included in each tier.
Braintrust eval report
|
Summary
list_notebooks(cursor-paginated) andget_notebookAI tools inlib/ai/tools/notebook-tools.ts, modeled directly onreport-tools.ts: server-sidegetContent/getNotebookwith theauthorizationheader forwarded, zod-validated input.get_notebookresolves every cell and exposesunchecked_sqlas a plainsqlfield for the agent to read — display only, per thesafe-sql-executionskill; nothing here executes SQL.lib/ai/tools/index.ts(same platform branch as reports) and inlib/ai/tool-filter.ts'stoolSetValidationSchema+TOOL_CATEGORY_MAP(SCHEMAtier).headersparam tocontent-infinite-query.ts'sgetContent, mirroring the siblingcontent-query.ts, so the cursor-paginated fetch can carry theAuthorizationheader from a server context.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
pnpm exec tsc --noEmit— no new errorspnpm 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 passingpnpm --filter studio run lint— no new warningspnpm exec prettier --checkon changed files — cleanSummary by CodeRabbit
New Features
Tests