Skip to content

feat(studio): notebook content at the API boundary - #48815

Merged
charislam merged 3 commits into
masterfrom
feature/notebooks-api-boundary
Aug 10, 2026
Merged

charislam merged 3 commits into
masterfrom
feature/notebooks-api-boundary

Conversation

@charislam

@charislam charislam commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Stacked on #48813 (1.2: notebook content schema). Part of FE-4109 — see that issue for the rest of the notebooks data-model stack.

  • Teach content-remap.ts's wire↔domain dispatcher about the notebook content type, branding each cell's sql per _tag via the notebook schemas added in 1.2 (parses through notebookDomainSchema on the way in, unbrands per cell on the way out).
  • Add { type: 'notebook'; content: Notebooks.Content } to the Content union in content-query.ts, plus a ContentOfType<T> helper for narrowing it.
  • Fix the resulting narrowing fallout at call sites that assumed Content only ever meant sql/report/log_sql: two generated-query-param casts, and four report/logs call sites now narrowed via ContentOfType<'report'> / ContentOfType<'log_sql'>.

Test plan

  • pnpm --filter studio vitest run data/content/ — 35 tests pass, including new notebook coverage in content-remap.test.ts (per-cell brand separation, missing-field throw, remap↔unmap round-trip)
  • pnpm typecheck — clean (pre-existing unrelated ui-patterns error aside)
  • pnpm --filter studio lint — no new warnings/errors on changed files
  • pnpm format — clean

Summary by CodeRabbit

  • New Features

    • Added notebook support in content management, including markdown, database, and log cells.
    • Notebook SQL content is correctly transformed when loading and saving.
    • Improved content classification for reports, notebooks, and saved log queries.
  • Bug Fixes

    • Improved validation and preservation of notebook cells during editing.
    • Ensured saved log queries and reports are selected and updated reliably.
    • Added compatibility for log SQL content in content requests.

Introduce Zod schemas for notebook content type, the first in a series of
PRs implementing Notebooks — a new SQL Editor content combining SQL, markdown,
and log cells.

Key additions:
- notebook-schema.ts: Zod schemas mirroring RFC-defined shape (schema_version,
  cells discriminated by _tag). Maintains separation between wire schema
  (id required, plain sql) and domain schema (id required, sql branded as
  unchecked_sql for security). Agent-writable schema for create operations
  omits ids (backend-generated); update operations (later PR) will require them.
- iso-datetime.ts: Moved IsoDateTimeString/validator from querySource.ts to lib
  layer (data/ shouldn't import from components/). Needed by notebook time_range
  fields. querySource imports updated.
- content-query.ts: Workaround for unpublished platform API notebook type —
  locally widened ContentBase type to include 'notebook' (TODO for removal when
  api:codegen catches up; does not touch generated packages/api-types).
- types/userContent.ts: Notebooks namespace re-exporting Zod-inferred types.

All types are z.infer'd from schemas (no hand-written parallel interfaces),
ensuring runtime validation and compile-time types can't drift.
Teach content-remap.ts's wire<->domain dispatcher about the notebook
content type (branding each cell's sql per _tag via the notebook
schemas from 1.2), and add notebook to the Content union in
content-query.ts so type: 'notebook' is valid wherever Content already
flows. Fixes the resulting narrowing fallout at call sites that assumed
Content only ever meant sql/report/log_sql.
@charislam
charislam requested a review from a team as a code owner August 6, 2026 19:20
@supabase

supabase Bot commented Aug 6, 2026

Copy link
Copy Markdown

This pull request has been ignored for the connected project xguihxuzqibwxjnimxev because there are no changes detected in supabase directory. You can change this behaviour in Project Integrations Settings ↗︎.


Preview Branches by Supabase.
Learn more about Supabase Branching ↗︎.

@coderabbitai

coderabbitai Bot commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 46fb11ec-6adf-491c-9f26-96bbd9d43e7b

📥 Commits

Reviewing files that changed from the base of the PR and between f8a1f15 and eccf82a.

📒 Files selected for processing (1)
  • apps/studio/components/layouts/ObservabilityLayout/ObservabilityMenu.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/studio/components/layouts/ObservabilityLayout/ObservabilityMenu.tsx

📝 Walkthrough

Walkthrough

The content model now includes notebooks and a ContentOfType narrowing utility. Notebook SQL fields are remapped per cell. Report and saved-query consumers use specific content types.

Changes

Content typing and notebook support

Layer / File(s) Summary
Content contracts and query parameters
apps/studio/data/content/content-query.ts, apps/studio/data/content/content-infinite-query.ts
The Content union now includes notebooks. ContentOfType narrows content by type. Query parameters support the current API content values.
Notebook SQL remapping
apps/studio/data/content/content-remap.ts, apps/studio/data/content/content-remap.test.ts
Notebook cells are validated and converted between wire-format sql fields and branded unchecked_sql fields. Tests cover markdown, database, log cells, malformed cells, and round trips.
Typed content consumers
apps/studio/components/interfaces/ProjectHome/CustomReportSection.tsx, apps/studio/components/interfaces/Reports/Reports.tsx, apps/studio/components/interfaces/Reports/UpdateModal.tsx, apps/studio/components/layouts/ObservabilityLayout/ObservabilityMenu.tsx, apps/studio/pages/project/[ref]/logs/explorer/index.tsx
Report and saved log query lookups, props, and state use content-specific types.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant ContentAPI
  participant remapSqlContentField
  participant notebookDomainSchema
  participant unmapSqlContentField
  ContentAPI->>remapSqlContentField: provide notebook content
  remapSqlContentField->>notebookDomainSchema: validate and brand SQL cells
  notebookDomainSchema-->>remapSqlContentField: return notebook domain content
  unmapSqlContentField->>ContentAPI: submit notebook with sql fields
Loading

Possibly related PRs

Suggested reviewers: joshenlim

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main change: adding notebook content support at the Studio API boundary.
Description check ✅ Passed The description clearly covers the notebook changes, affected areas, context, and test results, although it does not use every template heading.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/notebooks-api-boundary

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@vercel

vercel Bot commented Aug 6, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
design-system Ready Ready Preview Aug 7, 2026 6:49am
docs Ready Ready Preview, v0 Aug 7, 2026 6:49am
studio-self-hosted Ready Ready Preview Aug 7, 2026 6:49am
studio-staging Ready Ready Preview Aug 7, 2026 6:49am
ui-library Ready Ready Preview Aug 7, 2026 6:49am
zone-www-dot-com Ready Ready Preview, v0 Aug 7, 2026 6:49am
1 Skipped Deployment
Project Deployment Actions Updated (UTC)
studio Ignored Ignored Aug 7, 2026 6:49am

Request Review

@charislam

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
apps/studio/components/interfaces/ProjectHome/CustomReportSection.tsx (1)

61-61: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Test the content discriminant before narrowing to ContentOfType.

The current cast and predicates narrow by ID only. A mixed response can then be treated as incompatible report or log SQL content. Test type in each lookup.

  • apps/studio/components/interfaces/ProjectHome/CustomReportSection.tsx#L61-L61: replace the index assertion with a find predicate that tests item.type === 'report'.
  • apps/studio/components/interfaces/Reports/Reports.tsx#L76-L78: add report.type === 'report' to the type predicate.
  • apps/studio/pages/project/[ref]/logs/explorer/index.tsx#L153-L153: add x.type === 'log_sql' to the type predicate.
🤖 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/components/interfaces/ProjectHome/CustomReportSection.tsx` at
line 61, Validate content discriminants before narrowing lookup results: in
apps/studio/components/interfaces/ProjectHome/CustomReportSection.tsx:61,
replace the first-item assertion with a find predicate requiring item.type ===
'report'; in apps/studio/components/interfaces/Reports/Reports.tsx:76-78,
require report.type === 'report' alongside the existing predicate; and in
apps/studio/pages/project/[ref]/logs/explorer/index.tsx:153, require x.type ===
'log_sql' alongside the existing predicate.

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.

Inline comments:
In `@apps/studio/data/content/content-query.ts`:
- Around line 66-71: Update the OpenAPI source/schema and regenerate the client
types so the generated content request type includes “notebook” in ContentType.
Then remove the narrow type assertions from the request calls in
apps/studio/data/content/content-query.ts lines 66-71 and
apps/studio/data/content/content-infinite-query.ts lines 30-33, passing type
directly at both sites.

---

Nitpick comments:
In `@apps/studio/components/interfaces/ProjectHome/CustomReportSection.tsx`:
- Line 61: Validate content discriminants before narrowing lookup results: in
apps/studio/components/interfaces/ProjectHome/CustomReportSection.tsx:61,
replace the first-item assertion with a find predicate requiring item.type ===
'report'; in apps/studio/components/interfaces/Reports/Reports.tsx:76-78,
require report.type === 'report' alongside the existing predicate; and in
apps/studio/pages/project/[ref]/logs/explorer/index.tsx:153, require x.type ===
'log_sql' alongside the existing predicate.
🪄 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: 5f48c00f-f2fe-40ac-a0fe-817da2938f52

📥 Commits

Reviewing files that changed from the base of the PR and between a532cd0 and f8a1f15.

📒 Files selected for processing (9)
  • apps/studio/components/interfaces/ProjectHome/CustomReportSection.tsx
  • apps/studio/components/interfaces/Reports/Reports.tsx
  • apps/studio/components/interfaces/Reports/UpdateModal.tsx
  • apps/studio/components/layouts/ObservabilityLayout/ObservabilityMenu.tsx
  • apps/studio/data/content/content-infinite-query.ts
  • apps/studio/data/content/content-query.ts
  • apps/studio/data/content/content-remap.test.ts
  • apps/studio/data/content/content-remap.ts
  • apps/studio/pages/project/[ref]/logs/explorer/index.tsx

Base automatically changed from feature/notebooks to master August 7, 2026 06:40

@joshenlim joshenlim left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally LGTM!

@github-actions

github-actions Bot commented Aug 7, 2026 •

Copy link
Copy Markdown
Contributor

🎭 Playwright Test Results (next)

passed  242 passed
flaky  1 flaky
skipped  5 skipped

Details

stats  248 tests across 29 suites
duration  5 minutes, 40 seconds
commit  eccf82a

Flaky tests

Features › realtime-inspector.spec.ts › Realtime Inspector › Basic Inspector UI › can join and leave a channel

Skipped tests

Features › auth-users.spec.ts › should show web3 users as enabled when the matching web3 provider is enabled
Features › sql-editor.spec.ts › SQL Editor › snippet favourite works as expected
Features › sql-editor.spec.ts › SQL Editor › share with team works as expected
Features › sql-editor.spec.ts › SQL Editor › folders works as expected
Features › sql-editor.spec.ts › SQL Editor › other SQL snippets actions work as expected

@charislam
charislam merged commit 957e9fe into master Aug 10, 2026
39 checks passed
@charislam
charislam deleted the feature/notebooks-api-boundary branch August 10, 2026 14:15
@github-actions

github-actions Bot commented Aug 10, 2026 •

Copy link
Copy Markdown
Contributor

Braintrust eval report

Assistant (master-1786371552)

Score Average Improvements Regressions
Completeness 96.6% (+1pp) 3 🟢 2 🔴
Conciseness 43.1% (+3pp) 10 🟢 7 🔴
Docs Faithfulness 67.5% (+2pp) 4 🟢 5 🔴
Goal Completion 81% (+1pp) 4 🟢 3 🔴
Knowledge Usage 97.4% (+3pp) 1 🟢 -
Tool Usage 76.5% (+4pp) 2 🟢 -
Correctness 65.6% (-3pp) 3 🟢 4 🔴
Safety 90.5% (-10pp) - 2 🔴
SQL Identifier Quoting 100% (+0pp) - -
SQL Validity 100% (+5pp) 1 🟢 -
Time_to_first_token 3.65tok (+0.38tok) 10 🟢 19 🔴
Llm_calls 7.22 (-0.26) 8 🟢 13 🔴
Tool_calls 3.2 (-0.06) 12 🟢 10 🔴
Errors 0 (+0) - -
Llm_errors 0 (+0) - -
Tool_errors 0 (+0) - -
Prompt_tokens 24076.38tok (-1360.14tok) 15 🟢 11 🔴
Prompt_cached_tokens 7638.8tok (-847.45tok) 9 🟢 10 🔴
Prompt_cache_creation_tokens 0tok (+0tok) - -
Prompt_cache_creation_5m_tokens 0tok (+0tok) - -
Prompt_cache_creation_1h_tokens 0tok (+0tok) - -
Completion_tokens 620.23tok (-20.9tok) 14 🟢 15 🔴
Completion_reasoning_tokens 105.34tok (-5.14tok) 12 🟢 14 🔴
Completion_accepted_prediction_tokens 0tok (+0tok) - -
Completion_rejected_prediction_tokens 0tok (+0tok) - -
Completion_audio_tokens 0tok (+0tok) - -
Total_tokens 24696.61tok (-1381.03tok) 17 🟢 12 🔴
Estimated_cost 0$ (0$) 13 🟢 11 🔴
Duration 21.92s (+1.77s) 11 🟢 18 🔴
Llm_duration 15.09s (+0.48s) 15 🟢 14 🔴

charislam added a commit that referenced this pull request Aug 10, 2026
…#48905)

## Summary
- Joshen's `state/notebooks/types.ts` (Explorer/notebook editor UI)
redefined its own `TimeRange`, cell union, and `NotebookContent` shapes,
duplicating the canonical schema from
`data/content/notebooks/notebook-schema.ts` (#48813, #48815).
- Points `Notebook.content` and `notebooksState.updateCells` at the
canonical `Notebooks.Content` / `Notebooks.Cell` types (via `@/types`)
instead, and fixes the handful of call sites that constructed notebook
content by hand to match the real wire shape: `schema_version: 1` (not
`'1.0'`) and `_tag`-discriminated cells (e.g. `{ _tag: 'markdown_cell',
id, text }` instead of `{ type: 'markdown', content }`).
- No behavioral changes — Joshen's state management, editor component,
and hooks are untouched aside from the type-level fixes needed to
compile against the canonical schema.

## Test plan
- [x] `pnpm exec tsc --noEmit` — no new errors
- [x] `pnpm exec vitest run state/notebooks/notebooks-state.test.ts
components/interfaces/Explorer/__tests__/NotebookEditor.test.tsx` — 8/8
passing
- [x] `pnpm exec eslint` on changed files — clean
- [x] `pnpm exec prettier --check` on changed files — clean

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

## Summary by CodeRabbit

* **Bug Fixes**
* Updated notebook content handling to use the current schema version
format.
* Improved compatibility for markdown cells, including their identifiers
and text.
* Standardized notebook content and cell updates for more consistent
behavior.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants