Skip to content

experiment(notebooks): AI summarizer + prompter edit panel#3472

Draft
mariusandra wants to merge 2 commits into
notebooks-in-codefrom
experiment/ai-node-editor
Draft

experiment(notebooks): AI summarizer + prompter edit panel#3472
mariusandra wants to merge 2 commits into
notebooks-in-codefrom
experiment/ai-node-editor

Conversation

@mariusandra

@mariusandra mariusandra commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Experiment 1/3: universal AI editing interface for notebook nodes

Part of the notebook node-editing parity experiments (stacked on #3450). Verdict from the run: keep — this is the closest to mergeable.

Replaces the generic raw-JSON edit panel for embed nodes (Query, FeatureFlag, Experiment, Survey, EarlyAccessFeature, Cohort, Person, Group, Recording) with a summarizer + prompter:

  • Opening a node's edit panel shows an instant deterministic summary (series, date range, breakdown, display type), with an AI summary streaming over it (~1.1s cold, ~3ms cached).
  • A prompt input takes change requests ("make it a pie chart of unique users, last 30 days"); the model returns new props JSON + new summary in a single call (~1.8s end-to-end including chart re-render), validated and applied through the normal node-props plumbing with one retry on invalid JSON.
  • Collapsible raw-JSON escape hatch retained.

Architecture

  • NotebookNodeAIService in packages/core/src/notebooks/ — prompt construction, single-call {props, summary}, Zod validation, retry, FNV-1a summary cache, live-entity enrichment for entity nodes.
  • Transport: LLM gateway /v1/chat/completions (claude-haiku-4-5, streaming) — the desktop OAuth token is accepted straight from the renderer with open CORS. Max AI conversations as sticky fallback. Agent SDK rejected (seconds of spawn latency).
  • Per-tag affordance docs (notebookNodeAIKnowledge.ts) covering all query kinds; deterministic summarizer in notebookNodeSummary.ts.

Verified

Live against us.posthog.com on a real Trend node: both change requests applied correctly (verified in raw JSON: math:"dau", -30d, ActionsPie/ActionsBar, breakdown add/remove). 62 unit tests with a faked model; full-repo typecheck and Biome clean.

Known dragons

  • Sticky gateway-unavailable flag degrades to Max until reload after one blip.
  • A notebook with many embeds entering edit mode fires a burst of small model calls (session-cached afterwards).
  • The embed's trends renderer draws lines even when display is ActionsBar (props are correct; view layer doesn't do bars yet).

🤖 Generated with Claude Code

Screenshots

Edit panel open on a Trend node — instant deterministic summary already replaced by the streamed AI summary:

AI summary

After the change request "make it a bar chart of unique users, split by browser" — updated summary + re-rendered chart (~1.8s end-to-end):

Change applied

Raw JSON escape hatch showing the exact props the model produced:

Raw JSON

mariusandra and others added 2 commits July 15, 2026 13:32
Replace the vendored raw-JSON-textarea edit panel on PostHog entity nodes
(Query, FeatureFlag, Experiment, Survey, EarlyAccessFeature, Cohort,
Person, Group, Recording) with a universal AI editing interface:

- core NotebookNodeAIService: prompt construction from per-tag affordance
  knowledge, single model call returning {props, summary}, Zod-validated
  parsing with one retry, FNV-1a summary cache keyed on tagName+props
  (shell-managed panel props excluded), best-effort live-entity enrichment
  via the existing embed REST getters.
- core PostHogNotebookNodeAIModel transport: direct LLM-gateway
  /v1/chat/completions (claude-haiku-4-5, streaming SSE) with sticky
  fallback to a Max conversations turn when the gateway rejects the login.
- api-client: llmGatewayChatCompletion + region-derived llmGatewayUrl
  (same OAuth bearer the agent path uses against the gateway).
- core notebookNodeSummary: deterministic instant summaries (trends/
  funnel/retention/SQL/events + entity tags) shown while AI streams in.
- ui NotebookNodeAIEditPanel + hooks: summary view with streaming cursor,
  change-request prompt committing through the shell's updateProps (full
  replacement semantics incl. key deletion), collapsible raw-JSON escape
  hatch.
- 62 unit tests incl. parameterized retry/parse cases.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…remount

React StrictMode's double-mount aborts the first useQuery signal; the
service coalesces concurrent summarize calls onto one shared promise, so
the abort killed the call for the surviving subscriber and the AI summary
never arrived. The summary call now runs unsignalled — it is cheap,
cache-filling, and should complete even if the panel closes. Verified live
against us.posthog.com through the LLM gateway.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

React Doctor found 1 issue in 1 file · 1 error.

Errors

Reviewed by React Doctor for commit 941a63e.

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.

1 participant