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.

feat(web-analytics): add content autopilot brief and check panels (#109628)

Jordan Mryyan203cc5770836
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index 7779c45c92db..adbf30cffa01 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -7242,6 +7242,14 @@ snapshots:
hash: v1.k794b7964.c399531ee10ef73a5ca2b732484e1eae553f40b5b95c98fc0ab0b6a5d9711188.juWZKdvphiQP-rSsWPBDvU-9cRByiTb3dLrcfV1Qh3Y
products-tracing-virtualizedspanlist--with-error-badges--light:
hash: v1.k794b7964.7064ad6b5165631307d602ba3adcfd3fd5eb02107c8d3835c88c00df43bcad7f.3hK9J7DUCY3pFw2181ZBZbZsWlFkjm4Ydl5VNnzR5fA
+ products-web-analytics-content-autopilot-brief--brief--dark:
+ hash: v1.k794b7964.e9ebb3e96a4339f3e8116d76ca50f449e2650feb0ae5d65b8d56f2a6aefa03c5.ATu5igj4eqzRTqipkJ4O6N2ocrXDVmeoY_5y8B25UEA
+ products-web-analytics-content-autopilot-brief--brief--light:
+ hash: v1.k794b7964.4f68bde5c1d2707f5ed19814d0748d408c24a988ad931dd8d3722fb85770607b.mblI1uZh57kWCr-btn8pTl_icirEXG9pJjdpA6JESfQ
+ products-web-analytics-content-autopilot-brief--missing-brief--dark:
+ hash: v1.k794b7964.75044871dcc2faa507f449a17e07deb6e0cf20cc73cdc5fc3e656dbcf4baf31b.ANyIBMkLPcA_SBd96Nd2GVIfhyf97CbOy3za6mYR0z4
+ products-web-analytics-content-autopilot-brief--missing-brief--light:
+ hash: v1.k794b7964.d5e3b3a7b64a0ecf4023a55b0cf1a3c32c97fa70d31dd1da48d0d3da1c87a740.LImf4sGZGBFGBCuuNLggitGjsee4HyVuZ4UhkS1KOSI
products-web-analytics-content-autopilot-proposal-card--blocking-validation--dark:
hash: v1.k794b7964.8209374f939a22b6b211c2a21698ca15c4d6e18eda905eafc2c826539fa6a6f3.iZuZv-_mdz_BoFNzarvgUmumBKyNRvbdYMCWKcRQ5Bs
products-web-analytics-content-autopilot-proposal-card--blocking-validation--light:
@@ -7250,6 +7258,22 @@ snapshots:
hash: v1.k794b7964.bf31cb5454ab3b5b5410666a11ba19a0c149cccd7ae57b56efb32035f98239c8.I25YeYWQe17NAqrEq81n-U3tR8dMX8usKI0RRXhc7vI
products-web-analytics-content-autopilot-proposal-card--ready-for-review--light:
hash: v1.k794b7964.2d32fe2131b0ecca9c82ad58d395e73e204ab96db50f814fea3797f241829965.ndis7gl5c6uNZ_5DhF8CiTwDrvHWrUHsSyp3db3PUL0
+ products-web-analytics-content-autopilot-sources--with-research-notes--dark:
+ hash: v1.k794b7964.2be0596eea5d943ea5154d78d076fb1ae33583f6d1a82bd61b23e91807004a6c.c2JSeWbl54pOJlq8Zu3slJG20JJVq25E1D9JX4yn8rw
+ products-web-analytics-content-autopilot-sources--with-research-notes--light:
+ hash: v1.k794b7964.2b00d07a8309e97b1db2efbeab13f07f9322b1f00469022426334f630e26f7e4.BsB6fMyHEZzCEBAtZJr3IZa8IJHJQOt_lwYHaMypv3A
+ products-web-analytics-content-autopilot-validation-summary--could-not-draft--dark:
+ hash: v1.k794b7964.0346e971e925e9cc9e5eda113570520eae42f5806f5f6ece4e96cd403f78deef.H-TcmAsWmz8HVNF4BV9Thcrlt4K6pkep-H6fBlzN3YM
+ products-web-analytics-content-autopilot-validation-summary--could-not-draft--light:
+ hash: v1.k794b7964.3a0b5c3945e277188a6a0bca46cb7a0535d5dc7953305da002737d7f7b59226b.MgOwCiV2JN22OjipXelwiQsFTrRbznTGW9w3qV_B56A
+ products-web-analytics-content-autopilot-validation-summary--needs-fixes--dark:
+ hash: v1.k794b7964.3f6a3b187c3dab30bd0cf6aaf6b78a4a470dd123e753b4f5bbafa4f4630c0ebd.8cPF5J9uIe2-6u745ZWpXpq2xBW0zyIDzsiGg_x-hQY
+ products-web-analytics-content-autopilot-validation-summary--needs-fixes--light:
+ hash: v1.k794b7964.5e0343da1edce2aaf3b73bf8bb88762652472a8aefb196de4154d007d979d2d3.ZZ9tS9mr8uMyI6UobIEWS5Ae41LKPgygD5DB5H2l5u4
+ products-web-analytics-content-autopilot-validation-summary--ready-to-download--dark:
+ hash: v1.k794b7964.b1f1f0156955cfb71934ed8e6d36c89cbc3fec80c414610051489ffd5d31a51a.VZrBXAxqQltffCaf1A2pP-FvMOzsz5XBy4FY960KkWI
+ products-web-analytics-content-autopilot-validation-summary--ready-to-download--light:
+ hash: v1.k794b7964.f639222c8527f580b0a7d50335747380610569aefbac7407470e6ad296ba8853.zIXXIN4nBZV1mazHQrhFcswCdHx7awK23LO95NJ5uoc
products-web-analytics-content-autopilot-workspace--active-run--dark:
hash: v1.k794b7964.e78c4329f8ed2b268ae0f9e12750faf36b52a13f93afa4cdef6c6d3f967b85d4.seSi9FnXUv4lFgG8LnjWfQSx48DPmw0NvAouHKLV-hE
products-web-analytics-content-autopilot-workspace--active-run--light:
diff --git a/products/web_analytics/frontend/contentAutopilot/ContentAutopilotBriefPanel.stories.tsx b/products/web_analytics/frontend/contentAutopilot/ContentAutopilotBriefPanel.stories.tsx
new file mode 100644
index 000000000000..409ba3b992ab
--- /dev/null
+++ b/products/web_analytics/frontend/contentAutopilot/ContentAutopilotBriefPanel.stories.tsx
@@ -0,0 +1,28 @@
+import type { Meta, StoryFn } from '@storybook/react'
+
+import { FEATURE_FLAGS } from 'lib/constants'
+
+import { ContentAutopilotBriefPanel } from './ContentAutopilotBriefPanel'
+import { EXAMPLE_PROPOSAL } from './contentAutopilotStoryFixtures'
+
+const meta: Meta<typeof ContentAutopilotBriefPanel> = {
+ title: 'Products/Web Analytics/Content autopilot/Brief',
+ component: ContentAutopilotBriefPanel,
+ parameters: {
+ featureFlags: [FEATURE_FLAGS.WEB_ANALYTICS_PAGE_PERFORMANCE, FEATURE_FLAGS.WEB_ANALYTICS_CONTENT_AUTOPILOT],
+ },
+}
+
+export default meta
+
+export const Brief: StoryFn<typeof ContentAutopilotBriefPanel> = () => (
+ <div className="w-180 p-4">
+ <ContentAutopilotBriefPanel brief={EXAMPLE_PROPOSAL.brief} evidence={EXAMPLE_PROPOSAL.evidence} />
+ </div>
+)
+
+export const MissingBrief: StoryFn<typeof ContentAutopilotBriefPanel> = () => (
+ <div className="w-180 p-4">
+ <ContentAutopilotBriefPanel brief={{}} evidence={[]} />
+ </div>
+)
diff --git a/products/web_analytics/frontend/contentAutopilot/ContentAutopilotBriefPanel.tsx b/products/web_analytics/frontend/contentAutopilot/ContentAutopilotBriefPanel.tsx
new file mode 100644
index 000000000000..373204a05730
--- /dev/null
+++ b/products/web_analytics/frontend/contentAutopilot/ContentAutopilotBriefPanel.tsx
@@ -0,0 +1,60 @@
+import type {
+ ContentAutopilotBriefApi,
+ ContentAutopilotEvidenceApi,
+} from 'products/web_analytics/frontend/generated/api.schemas'
+
+export interface ContentAutopilotBriefPanelProps {
+ brief: ContentAutopilotBriefApi
+ evidence: ContentAutopilotEvidenceApi[]
+}
+
+const BriefList = ({ title, items }: { title: string; items?: string[] }): JSX.Element | null =>
+ items && items.length > 0 ? (
+ <section>
+ <h4 className="mb-1">{title}</h4>
+ <ul className="list-disc pl-5 m-0">
+ {items.map((item, index) => (
+ <li key={`${index}-${item}`}>{item}</li>
+ ))}
+ </ul>
+ </section>
+ ) : null
+
+const BriefText = ({ title, text }: { title: string; text?: string }): JSX.Element | null =>
+ text ? (
+ <section>
+ <h4 className="mb-1">{title}</h4>
+ <p className="m-0 text-sm">{text}</p>
+ </section>
+ ) : null
+
+const BriefCard = ({ title, text }: { title: string; text?: string }): JSX.Element | null =>
+ text ? (
+ <div className="rounded border p-3">
+ <div className="font-semibold">{title}</div>
+ <div className="text-sm mt-1">{text}</div>
+ </div>
+ ) : null
+
+export const ContentAutopilotBriefPanel = ({ brief, evidence }: ContentAutopilotBriefPanelProps): JSX.Element => {
+ const reasons = evidence.map(({ explanation }) => explanation).filter(Boolean)
+ const briefSaved =
+ [brief.disambiguation, brief.intent, brief.audience, brief.engine_answer_summary].some(Boolean) ||
+ [brief.outline, brief.questions_to_answer, brief.competitor_coverage].some((items) => !!items?.length)
+
+ return (
+ <div className="@container flex flex-col gap-4">
+ <BriefList title="Why this was picked" items={reasons} />
+ {briefSaved ? null : <p className="text-muted m-0">No brief was saved for this draft.</p>}
+ <BriefText title="What the question means" text={brief.disambiguation} />
+ <div className="grid grid-cols-1 @md:grid-cols-2 gap-3">
+ <BriefCard title="What the reader wants" text={brief.intent} />
+ <BriefCard title="Audience" text={brief.audience} />
+ </div>
+ <BriefText title="What AI assistants say today" text={brief.engine_answer_summary} />
+ <BriefList title="Outline" items={brief.outline} />
+ <BriefList title="Questions to answer" items={brief.questions_to_answer} />
+ <BriefList title="Covered by cited pages but not by this site" items={brief.competitor_coverage} />
+ </div>
+ )
+}
diff --git a/products/web_analytics/frontend/contentAutopilot/ContentAutopilotSourceLedger.stories.tsx b/products/web_analytics/frontend/contentAutopilot/ContentAutopilotSourceLedger.stories.tsx
new file mode 100644
index 000000000000..6049443d8d8f
--- /dev/null
+++ b/products/web_analytics/frontend/contentAutopilot/ContentAutopilotSourceLedger.stories.tsx
@@ -0,0 +1,25 @@
+import type { Meta, StoryFn } from '@storybook/react'
+
+import { FEATURE_FLAGS } from 'lib/constants'
+
+import { ContentAutopilotSourceLedger } from './ContentAutopilotSourceLedger'
+import { EXAMPLE_PROPOSAL } from './contentAutopilotStoryFixtures'
+
+const meta: Meta<typeof ContentAutopilotSourceLedger> = {
+ title: 'Products/Web Analytics/Content autopilot/Sources',
+ component: ContentAutopilotSourceLedger,
+ parameters: {
+ featureFlags: [FEATURE_FLAGS.WEB_ANALYTICS_PAGE_PERFORMANCE, FEATURE_FLAGS.WEB_ANALYTICS_CONTENT_AUTOPILOT],
+ },
+}
+
+export default meta
+
+export const WithResearchNotes: StoryFn<typeof ContentAutopilotSourceLedger> = () => (
+ <div className="w-180 p-4">
+ <ContentAutopilotSourceLedger
+ entries={EXAMPLE_PROPOSAL.source_ledger}
+ notes={["Couldn't read the cited page https://rival.example.com/replay."]}
+ />
+ </div>
+)
diff --git a/products/web_analytics/frontend/contentAutopilot/ContentAutopilotSourceLedger.tsx b/products/web_analytics/frontend/contentAutopilot/ContentAutopilotSourceLedger.tsx
new file mode 100644
index 000000000000..abad47e1eefc
--- /dev/null
+++ b/products/web_analytics/frontend/contentAutopilot/ContentAutopilotSourceLedger.tsx
@@ -0,0 +1,44 @@
+import { LemonTable, Link } from '@posthog/lemon-ui'
+
+import type { ContentAutopilotSourceLedgerEntryApi } from 'products/web_analytics/frontend/generated/api.schemas'
+
+export interface ContentAutopilotSourceLedgerProps {
+ entries: ContentAutopilotSourceLedgerEntryApi[]
+ notes: string[]
+}
+
+export const ContentAutopilotSourceLedger = ({ entries, notes }: ContentAutopilotSourceLedgerProps): JSX.Element => (
+ <div className="flex flex-col gap-3">
+ <p className="m-0 text-muted text-sm">Each fact in the draft and the page that backs it up.</p>
+ <LemonTable
+ dataSource={entries}
+ rowKey={(entry, index) => `${index}-${entry.claim}-${entry.source_url}`}
+ emptyState="The draft doesn't make any claims that need a source."
+ columns={[
+ { title: 'Claim', key: 'claim', render: (_, entry) => <span className="text-sm">{entry.claim}</span> },
+ {
+ title: 'Source',
+ key: 'source',
+ render: (_, entry) => (
+ <div className="text-sm py-1">
+ <Link to={entry.source_url} target="_blank">
+ {entry.source_url}
+ </Link>
+ <blockquote className="m-0 mt-1 text-muted">{entry.quote}</blockquote>
+ </div>
+ ),
+ },
+ ]}
+ />
+ {notes.length > 0 ? (
+ <section>
+ <h4 className="mb-1">Research notes</h4>
+ <ul className="list-disc pl-5 m-0 text-sm text-muted">
+ {notes.map((note) => (
+ <li key={note}>{note}</li>
+ ))}
+ </ul>
+ </section>
+ ) : null}
+ </div>
+)
diff --git a/products/web_analytics/frontend/contentAutopilot/ContentAutopilotValidationSummary.stories.tsx b/products/web_analytics/frontend/contentAutopilot/ContentAutopilotValidationSummary.stories.tsx
new file mode 100644
index 000000000000..589cf1281ce0
--- /dev/null
+++ b/products/web_analytics/frontend/contentAutopilot/ContentAutopilotValidationSummary.stories.tsx
@@ -0,0 +1,91 @@
+import type { Meta, StoryFn } from '@storybook/react'
+
+import { FEATURE_FLAGS } from 'lib/constants'
+
+import { ContentAutopilotValidationSummary } from './ContentAutopilotValidationSummary'
+
+const meta: Meta<typeof ContentAutopilotValidationSummary> = {
+ title: 'Products/Web Analytics/Content autopilot/Validation summary',
+ component: ContentAutopilotValidationSummary,
+ parameters: {
+ featureFlags: [FEATURE_FLAGS.WEB_ANALYTICS_PAGE_PERFORMANCE, FEATURE_FLAGS.WEB_ANALYTICS_CONTENT_AUTOPILOT],
+ },
+}
+
+export default meta
+
+const PASSED_CHECKS = [
+ {
+ check_key: 'structure',
+ label: 'Page structure',
+ passed: true,
+ blocking: true,
+ message: 'One H1, question-led sections, and enough depth.',
+ },
+ {
+ check_key: 'internal_links',
+ label: 'Internal links',
+ passed: true,
+ blocking: true,
+ message: 'Every internal link points to a page in the sitemap.',
+ },
+ {
+ check_key: 'sources',
+ label: 'Sources',
+ passed: true,
+ blocking: true,
+ message: 'Every sourced claim cites a page that was part of the research.',
+ },
+]
+
+export const ReadyToDownload: StoryFn<typeof ContentAutopilotValidationSummary> = () => (
+ <div className="w-180 p-4">
+ <ContentAutopilotValidationSummary report={{ passed: true, checks: PASSED_CHECKS }} />
+ </div>
+)
+
+export const NeedsFixes: StoryFn<typeof ContentAutopilotValidationSummary> = () => (
+ <div className="w-180 p-4">
+ <ContentAutopilotValidationSummary
+ report={{
+ passed: false,
+ checks: [
+ ...PASSED_CHECKS,
+ {
+ check_key: 'grounding',
+ label: 'Sourced facts',
+ passed: false,
+ blocking: true,
+ message: "These claims aren't backed by a source: `Every plan includes unlimited events`.",
+ },
+ {
+ check_key: 'length',
+ label: 'Length',
+ passed: false,
+ blocking: false,
+ message: '1,900 new words, well over the budget of about 1,200. Trim it before publishing.',
+ },
+ ],
+ }}
+ />
+ </div>
+)
+
+export const CouldNotDraft: StoryFn<typeof ContentAutopilotValidationSummary> = () => (
+ <div className="w-180 p-4">
+ <ContentAutopilotValidationSummary
+ report={{
+ passed: false,
+ checks: [
+ {
+ check_key: 'generation',
+ label: 'Generation',
+ passed: false,
+ blocking: true,
+ message: "The AI model couldn't finish this draft. Regenerate to try again.",
+ },
+ ],
+ }}
+ />
+ </div>
+)
diff --git a/products/web_analytics/frontend/contentAutopilot/ContentAutopilotValidationSummary.tsx b/products/web_analytics/frontend/contentAutopilot/ContentAutopilotValidationSummary.tsx
new file mode 100644
index 000000000000..5b50555ebed7
--- /dev/null
+++ b/products/web_analytics/frontend/contentAutopilot/ContentAutopilotValidationSummary.tsx
@@ -0,0 +1,92 @@
+import { LemonBanner, LemonCollapse, LemonTag, LemonTagType } from '@posthog/lemon-ui'
+
+import { pluralize } from 'lib/utils/strings'
+
+import type {
+ ContentAutopilotValidationCheckApi,
+ ContentAutopilotValidationReportApi,
+} from 'products/web_analytics/frontend/generated/api.schemas'
+
+export interface ContentAutopilotValidationSummaryProps {
+ report: ContentAutopilotValidationReportApi
+}
+
+const CheckList = ({ checks }: { checks: ContentAutopilotValidationCheckApi[] }): JSX.Element => (
+ <ul className="m-0 mt-2 pl-5 list-disc">
+ {checks.map((check) => (
+ <li key={check.check_key}>
+ <span className="font-semibold">{check.label}:</span> {check.message}
+ </li>
+ ))}
+ </ul>
+)
+
+const checkTag = (check: ContentAutopilotValidationCheckApi): { type: LemonTagType; label: string } =>
+ check.passed
+ ? { type: 'success', label: 'Passed' }
+ : check.blocking
+ ? { type: 'danger', label: 'Must fix' }
+ : { type: 'warning', label: 'Review' }
+
+export const ContentAutopilotValidationSummary = ({ report }: ContentAutopilotValidationSummaryProps): JSX.Element => {
+ const generationFailure = report.checks.find(({ check_key, passed }) => check_key === 'generation' && !passed)
+ if (generationFailure) {
+ return <LemonBanner type="error">This draft couldn't be written. {generationFailure.message}</LemonBanner>
+ }
+
+ const blocked = report.checks.filter(({ passed, blocking }) => !passed && blocking)
+ const toReview = report.checks.filter(({ passed, blocking }) => !passed && !blocking)
+
+ return (
+ <div className="flex flex-col gap-2">
+ {blocked.length > 0 ? (
+ <LemonBanner type="error">
+ Fix {pluralize(blocked.length, 'check')} before you can download this draft. Edit it, or regenerate
+ it.
+ <CheckList checks={blocked} />
+ </LemonBanner>
+ ) : report.passed && report.checks.length > 0 ? (
+ <LemonBanner type="success">
+ Ready to download. {pluralize(report.checks.filter(({ passed }) => passed).length, 'check')} passed.
+ </LemonBanner>
+ ) : (
+ <LemonBanner type="info">
+ This draft hasn't been checked yet. Checks run after the draft is written.
+ </LemonBanner>
+ )}
+ {toReview.length > 0 ? (
+ <LemonBanner type="warning">
+ Worth a look before you publish:
+ <CheckList checks={toReview} />
+ </LemonBanner>
+ ) : null}
+ <LemonCollapse
+ size="small"
+ panels={[
+ {
+ key: 'checks',
+ header: `All checks (${report.checks.length})`,
+ content: (
+ <div className="@container">
+ <div className="grid grid-cols-1 @xl:grid-cols-2 gap-2">
+ {report.checks.map((check) => {
+ const tag = checkTag(check)
+ return (
+ <div key={check.check_key} className="rounded border p-3">
+ <div className="flex items-center justify-between gap-2">
+ <span className="font-semibold">{check.label}</span>
+ <LemonTag type={tag.type}>{tag.label}</LemonTag>
+ </div>
+ <div className="text-sm mt-1 text-muted">{check.message}</div>
+ </div>
+ )
+ })}
+ </div>
+ </div>
+ ),
+ },
+ ]}
+ />
+ </div>
+ )
+}