Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(posthog-ai): show the notebook card for markdown notebook tools (#90197)

Sinan Kucukkoseler67cafa78659f
diff --git a/products/posthog_ai/frontend/components/tool/widgets/CreateNotebookWidget.test.tsx b/products/posthog_ai/frontend/components/tool/widgets/CreateNotebookWidget.test.tsx
index 70925c898b84..075265fa16ce 100644
--- a/products/posthog_ai/frontend/components/tool/widgets/CreateNotebookWidget.test.tsx
+++ b/products/posthog_ai/frontend/components/tool/widgets/CreateNotebookWidget.test.tsx
@@ -22,28 +22,42 @@ function toolMessage(rawOutput: unknown, innerInput?: Record<string, unknown>):
}
describe('CreateNotebookWidget', () => {
- it.each(['notebooks-create', 'notebooks-partial-update', 'notebooks-retrieve', 'notebook-edit'])(
- 'resolves %s to the notebook widget',
- (key) => {
- expect(toolRegistry.lookup(key)?.displayName).toBe('Notebook')
- // The notebook widget is gated on a trusted PostHog-exec origin, so pass `fromPostHogExec`.
- expect(lookupToolRenderer(key, true).displayName).toBe('Notebook')
- }
- )
+ it.each([
+ 'notebooks-create',
+ 'notebooks-partial-update',
+ 'notebooks-retrieve',
+ 'notebook-edit',
+ 'notebooks-create-markdown',
+ 'notebooks-get',
+ ])('resolves %s to the notebook widget', (key) => {
+ expect(toolRegistry.lookup(key)?.displayName).toBe('Notebook')
+ // The notebook widget is gated on a trusted PostHog-exec origin, so pass `fromPostHogExec`.
+ expect(lookupToolRenderer(key, true).displayName).toBe('Notebook')
+ })
it('falls back to the generic renderer for an unknown inner tool key', () => {
expect(lookupToolRenderer('some-unwired-tool', true).displayName).not.toBe('Notebook')
})
describe('extractNotebook', () => {
- it('reads short_id, title, and the _posthogUrl enrichment from the REST payload', () => {
- const notebook = extractNotebook(
- toolMessage({
+ // The rich-text tools spell the short id `short_id` and surround it with the rest of the REST
+ // record; the markdown tools spell it `notebook_id`. Both reduce to the same extraction.
+ it.each([
+ [
+ 'short_id',
+ {
id: 'b3d0f2aa-1111-2222-3333-444455556666',
short_id: 'aBcDe123',
- title: 'Churn deep dive',
content: { type: 'doc', content: [] },
version: 1,
+ },
+ ],
+ ['notebook_id', { notebook_id: 'aBcDe123' }],
+ ])('reads the short id from %s, with the title and the _posthogUrl enrichment', (_field, payload) => {
+ const notebook = extractNotebook(
+ toolMessage({
+ ...payload,
+ title: 'Churn deep dive',
_posthogUrl: 'https://us.posthog.com/project/1/notebooks/aBcDe123',
})
)
@@ -59,7 +73,7 @@ describe('CreateNotebookWidget', () => {
expect(notebook).toEqual({ shortId: 'aBcDe123', title: 'From input', url: undefined })
})
- it('returns null for outputs without a short_id or that are not objects', () => {
+ it('returns null for outputs carrying neither id or that are not objects', () => {
expect(extractNotebook(toolMessage({ blocks: [], title: 'Legacy artifact shape' }))).toBeNull()
expect(extractNotebook(toolMessage('created notebook aBcDe123'))).toBeNull()
expect(extractNotebook(toolMessage(undefined))).toBeNull()
diff --git a/products/posthog_ai/frontend/components/tool/widgets/CreateNotebookWidget.tsx b/products/posthog_ai/frontend/components/tool/widgets/CreateNotebookWidget.tsx
index 614ce578e454..906c6a990059 100644
--- a/products/posthog_ai/frontend/components/tool/widgets/CreateNotebookWidget.tsx
+++ b/products/posthog_ai/frontend/components/tool/widgets/CreateNotebookWidget.tsx
@@ -20,8 +20,9 @@ export interface NotebookExtraction {
/**
* Pulls the rendered fields out of a notebook tool's `rawOutput` — the REST notebook payload
* (`short_id`, `title`, ProseMirror `content`, …) plus the MCP server's `_posthogUrl` enrichment.
- * `short_id` is required: outputs without it aren't a notebook payload and fall back to the
- * generic card.
+ * The markdown notebook tools return that same short id under `notebook_id` instead, so both
+ * spellings are accepted. An output carrying neither isn't a notebook payload and falls back to
+ * the generic card.
*/
export function extractNotebook(message: ToolRendererProps['message']): NotebookExtraction | null {
const output = parseToolOutputRecord(message)
@@ -29,14 +30,20 @@ export function extractNotebook(message: ToolRendererProps['message']): Notebook
return null
}
- const { short_id, title, _posthogUrl } = output as { short_id?: unknown; title?: unknown; _posthogUrl?: unknown }
- if (typeof short_id !== 'string') {
+ const { short_id, notebook_id, title, _posthogUrl } = output as {
+ short_id?: unknown
+ notebook_id?: unknown
+ title?: unknown
+ _posthogUrl?: unknown
+ }
+ const shortId = typeof short_id === 'string' ? short_id : typeof notebook_id === 'string' ? notebook_id : null
+ if (!shortId) {
return null
}
const inputTitle = message.innerInput?.title
return {
- shortId: short_id,
+ shortId,
title: typeof title === 'string' ? title : typeof inputTitle === 'string' ? inputTitle : undefined,
url: typeof _posthogUrl === 'string' ? _posthogUrl : undefined,
}
diff --git a/products/posthog_ai/frontend/components/tool/widgets/registerDataToolRenderers.tsx b/products/posthog_ai/frontend/components/tool/widgets/registerDataToolRenderers.tsx
index 04de3578c2ef..7c26b481e7e9 100644
--- a/products/posthog_ai/frontend/components/tool/widgets/registerDataToolRenderers.tsx
+++ b/products/posthog_ai/frontend/components/tool/widgets/registerDataToolRenderers.tsx
@@ -102,9 +102,19 @@ register(
// --- Data tools: notebooks ---
// The generated CRUD tools and the handwritten notebook-edit (the collab-safe content editor) all
-// return the same REST notebook payload.
+// return the same REST notebook payload. A feature flag swaps that set for the markdown notebook
+// tools, so both sets are registered — a thread only ever contains calls from the set its own run
+// was served. The cell tools (add / update / delete) stay on the generic card: they return a cell
+// run, not a notebook, so this card has nothing to show for them.
register(
- ['notebooks-create', 'notebooks-partial-update', 'notebooks-retrieve', 'notebook-edit'],
+ [
+ 'notebooks-create',
+ 'notebooks-partial-update',
+ 'notebooks-retrieve',
+ 'notebook-edit',
+ 'notebooks-create-markdown',
+ 'notebooks-get',
+ ],
'Notebook',
<IconNotebook />,
NotebookRenderer