Skip to content

feat: notebook content schema - #48813

Merged
joshenlim merged 2 commits into
masterfrom
feature/notebooks
Aug 7, 2026
Merged

joshenlim merged 2 commits into
masterfrom
feature/notebooks

Conversation

@charislam

@charislam charislam commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor

Related to FE-4109.

Summary

  • API codegen workaround: Platform API's notebook content type hasn't shipped to the OpenAPI spec yet, so pnpm api:codegen can't be run. Locally widened ContentBase.type to include 'notebook' (marked with TODO for removal once spec publishes).
  • Notebook schema & type system: Introduced Zod schemas mirroring RFC-defined notebook shape (schema_version: 1, cells: Cell[]). Maintains wire/domain boundary (cell sql → unchecked_sql branded for security). Agent-writable schema for create_notebook tool omits cell IDs (backend-generated); future update operations will require them. All TypeScript types are z.infer'd from schemas (no hand-written parallel interfaces).
  • IsoDateTimeString moved: Extracted ISO datetime validator from querySource.ts to lib/iso-datetime.ts (data layer shouldn't import from components layer). Needed by notebook time_range fields.

Test plan

  • Unit tests: notebook-schema.test.ts (9 tests), iso-datetime.test.ts (3 tests), querySource.test.ts updated and passing (26 tests)
  • Typecheck: no new errors
  • Prettier: formatting clean

Summary by CodeRabbit

  • New Features

    • Added support for validating and processing notebook content, including markdown, database, log cells, time ranges, and chart configurations.
    • Added compatibility for notebook content types in content handling.
    • Added reliable ISO date-time validation for notebook data and related features.
  • Tests

    • Expanded coverage for valid and invalid notebook structures, cell requirements, time ranges, chart settings, and date-time values.

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.
@charislam
charislam requested a review from a team as a code owner August 6, 2026 18:48
@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:37am
docs Ready Ready Preview, v0 Aug 7, 2026 6:37am
studio-self-hosted Ready Ready Preview Aug 7, 2026 6:37am
studio-staging Ready Ready Preview Aug 7, 2026 6:37am
ui-library Ready Ready Preview Aug 7, 2026 6:37am
zone-www-dot-com Ready Ready Preview, v0 Aug 7, 2026 6:37am
1 Skipped Deployment
Project Deployment Actions Updated (UTC)
studio Ignored Ignored Aug 7, 2026 6:37am

Request Review

@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

📝 Walkthrough

Walkthrough

Adds shared ISO datetime validation and introduces Zod schemas for wire, agent, and domain notebook data. Exports notebook types, supports notebook content, transforms SQL into branded values, and adds comprehensive validation tests.

Changes

Notebook schema foundation

Layer / File(s) Summary
Shared ISO datetime validation
apps/studio/lib/iso-datetime.ts, apps/studio/lib/iso-datetime.test.ts, apps/studio/components/interfaces/SQLEditor/querySource.*
Adds a branded ISO datetime factory and tests. SQL editor code imports the shared validator and type.
Notebook schemas and domain types
apps/studio/data/content/notebooks/notebook-schema.ts, apps/studio/data/content/content-query.ts, apps/studio/types/userContent.ts
Adds wire, agent, and domain notebook schemas. Exports notebook types and allows notebook content entries. Database and log SQL are transformed into branded unchecked SQL values.
Notebook schema validation coverage
apps/studio/data/content/notebooks/notebook-schema.test.ts
Tests cell validation, time ranges, agent cell IDs, and domain SQL transformations.

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

Sequence Diagram(s)

sequenceDiagram
  participant NotebookInput
  participant notebookDomainSchema
  participant untrustedSql
  participant untrustedLogSql
  NotebookInput->>notebookDomainSchema: Parse notebook wire data
  notebookDomainSchema->>untrustedSql: Transform database SQL
  notebookDomainSchema->>untrustedLogSql: Transform log SQL
  notebookDomainSchema-->>NotebookInput: Return domain notebook
Loading

Possibly related PRs

Suggested reviewers: joshenlim

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely identifies the main change: adding notebook content schemas.
Description check ✅ Passed The description explains the schema changes, compatibility workaround, behavior, context, and test plan, but omits the required CONTRIBUTING.md confirmation section.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
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
📝 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

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.

@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: 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/data/content/content-query.ts`:
- Around line 9-14: Extend the Content domain union to include a parsed notebook
variant using notebookDomainSchema, and update remapSqlContentFields to
transform notebook cell.sql values into branded unchecked_sql values where
required. Ensure getContent returns the notebook variant and add coverage for
notebook parsing and remapping.

In `@apps/studio/lib/iso-datetime.ts`:
- Around line 16-18: Update isoDateTimeString to use the existing strict Zod ISO
datetime validation path from notebook-schema.ts instead of
dayjs(raw).isValid(). Return null for malformed or overflow values, and brand
only the validated result without using a direct `as` cast.
🪄 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: ec58f30f-9db2-435c-ac93-047207644690

📥 Commits

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

📒 Files selected for processing (8)
  • apps/studio/components/interfaces/SQLEditor/querySource.test.ts
  • apps/studio/components/interfaces/SQLEditor/querySource.ts
  • apps/studio/data/content/content-query.ts
  • apps/studio/data/content/notebooks/notebook-schema.test.ts
  • apps/studio/data/content/notebooks/notebook-schema.ts
  • apps/studio/lib/iso-datetime.test.ts
  • apps/studio/lib/iso-datetime.ts
  • apps/studio/types/userContent.ts

Comment thread apps/studio/lib/iso-datetime.ts Resolved

@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.

Yup all LGTM as per what we chatted! 🙏 🙂

@github-actions

github-actions Bot commented Aug 7, 2026 •

Copy link
Copy Markdown
Contributor

🎭 Playwright Test Results (tanstack)

passed  242 passed
flaky  1 flaky
skipped  5 skipped

Details

stats  248 tests across 29 suites
duration  4 minutes, 2 seconds
commit  b8626d1

Flaky tests

Features › column-editor-types.spec.ts › column editor complex types › FK selector allows and creates a relation between two matching array columns

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

@joshenlim
joshenlim merged commit 0b97e37 into master Aug 7, 2026
38 checks passed
@joshenlim
joshenlim deleted the feature/notebooks branch August 7, 2026 06:40
@github-actions

github-actions Bot commented Aug 7, 2026 •

Copy link
Copy Markdown
Contributor

Braintrust eval report

Assistant (master-1786085023)

Score Average Improvements Regressions
Completeness 97.7% (+1pp) 2 🟢 1 🔴
Conciseness 38.5% (-2pp) 6 🟢 10 🔴
Correctness 74.4% (+3pp) 3 🟢 1 🔴
Docs Faithfulness 63.7% (+3pp) 5 🟢 3 🔴
Goal Completion 79.3% (+1pp) 4 🟢 3 🔴
Knowledge Usage 89.7% (-10pp) - 3 🔴
SQL Identifier Quoting 100% (+0pp) - -
SQL Validity 100% (+0pp) - -
Tool Usage 70.6% (-6pp) - 2 🔴
Safety 100% (+14.000000000000002pp) 3 🟢 -
URL Validity 100% (+0pp) - -
Time_to_first_token 2.05tok (-1.33tok) 29 🟢 -
Llm_calls 6.8 (-0.41) 4 🟢 18 🔴
Tool_calls 2.97 (-0.23) 8 🟢 16 🔴
Errors 0 (+0) - -
Llm_errors 0 (+0) - -
Tool_errors 0 (+0) - -
Prompt_tokens 21093.1tok (-3043.57tok) 18 🟢 7 🔴
Prompt_cached_tokens 7909.52tok (+105.93tok) 8 🟢 13 🔴
Prompt_cache_creation_tokens 0tok (+0tok) - -
Prompt_cache_creation_5m_tokens 0tok (+0tok) - -
Prompt_cache_creation_1h_tokens 0tok (+0tok) - -
Completion_tokens 643.46tok (+19.25tok) 16 🟢 13 🔴
Completion_reasoning_tokens 111.83tok (+6.15tok) 13 🟢 13 🔴
Completion_accepted_prediction_tokens 0tok (+0tok) - -
Completion_rejected_prediction_tokens 0tok (+0tok) - -
Completion_audio_tokens 0tok (+0tok) - -
Total_tokens 21736.56tok (-3024.32tok) 22 🟢 7 🔴
Estimated_cost 0$ (0$) 21 🟢 6 🔴
Duration 12.92s (-5.75s) 26 🟢 3 🔴
Llm_duration 9.01s (-5.2s) 28 🟢 1 🔴

hunleyd added a commit that referenced this pull request Aug 8, 2026
…for-pitr-archiving-stale

* origin/master: (342 commits)
  feat(studio): role-aware access feedback in scoped token creation (#48858)
  Initialize notebook editor page (#48842)
  test(docs): scan changed pages for WCAG 2.1 A/AA in warn mode (#48727)
  docs(auth): clarify audit logs storage options and configuration (#48852)
  feat(studio): warn that scoped tokens don't support the MCP server (#48849)
  feat(studio): lifecycle and role-aware scoped token view sheet (#48848)
  feat(www): add Open Authorization Integration Addendum (#48804)
  feat(studio): add legacy token mode to scoped pat creation flow (#48844)
  Add blog post: Supabase is now a connector on Perplexity Computer (#48776)
  feat(studio): enforce expiry scoped pat (#48811)
  fix(studio): model scoped pat permissions as OR-of-AND alternatives - smaller version (#48809)
  fix(ui): opaque default button hover fills (#48837)
  fix(ui): restore normal alert text wrapping (#48840)
  feat: notebook content schema (#48813)
  fix(ui): remove extra spacing before custom reports section (#48796)
  feat(marketing): add hint text below Go page form labels (#48824)
  Initialize notebooks store (#48801)
  Use white wordmark for QA.tech primary logo (#48827)
  fix titleless Admonition alignment (#48784)
  fix inconsistent product menu dividers (#48787)
  ...
charislam added a commit that referenced this pull request Aug 10, 2026
## Summary

Stacked on #48813 (1.2: notebook content schema). Part of
[FE-4109](https://linear.app/supabase/issue/FE-4109/notebooks-data-model)
— 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

- [x] `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)
- [x] `pnpm typecheck` — clean (pre-existing unrelated `ui-patterns`
error aside)
- [x] `pnpm --filter studio lint` — no new warnings/errors on changed
files
- [x] `pnpm format` — clean

---------

Co-authored-by: Joshen Lim <[email protected]>
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