: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(replay): quill twins for summarize and the observations empty state (#128934)
Hayne Ryu758a55c666a4
diff --git a/frontend/src/scenes/session-recordings/player/watch/WatchPanel.tsx b/frontend/src/scenes/session-recordings/player/watch/WatchPanel.tsxindex 5ca7b7086e37..fca572c233b5 100644--- a/frontend/src/scenes/session-recordings/player/watch/WatchPanel.tsx+++ b/frontend/src/scenes/session-recordings/player/watch/WatchPanel.tsx@@ -4,7 +4,7 @@ import { playerSettingsLogic } from 'scenes/session-recordings/player/playerSettimport { aiConsentLogic } from '~/layout/ai/aiConsentLogic'-import { SummarizeRecordingBar } from 'products/replay_vision/frontend/components/SummarizeRecordingBar'+import { QuillSummarizeRecordingBar } from 'products/replay_vision/frontend/components/QuillSummarizeRecordingBar'import { visionSurfaceShown } from 'products/replay_vision/frontend/utils/visionSurface'import { sessionRecordingPlayerLogic } from '../sessionRecordingPlayerLogic'@@ -27,7 +27,7 @@ export function WatchPanel(): JSX.Element | null {return (<div data-quill className="flex flex-col gap-4 px-1 pt-3 pb-6 text-foreground isolate" data-attr="watch-panel"><DebugModeBanner />- <RecordingTitleBlock actions={vision ? <SummarizeRecordingBar inline /> : undefined} />+ <RecordingTitleBlock actions={vision ? <QuillSummarizeRecordingBar /> : undefined} />{vision && dataProcessingAccepted ? (<WatchPanelTabsWithObservations sessionId={sessionRecordingId} debug={debugDocked} />) : (diff --git a/frontend/src/scenes/session-recordings/player/watch/WatchPanelTabsWithObservations.tsx b/frontend/src/scenes/session-recordings/player/watch/WatchPanelTabsWithObservations.tsxindex 0a18f6c17fa6..10f68c9657bd 100644--- a/frontend/src/scenes/session-recordings/player/watch/WatchPanelTabsWithObservations.tsx+++ b/frontend/src/scenes/session-recordings/player/watch/WatchPanelTabsWithObservations.tsx@@ -4,8 +4,8 @@ import { Skeleton } from '@posthog/quill'import { sessionRecordingPlayerLogic } from 'scenes/session-recordings/player/sessionRecordingPlayerLogic'+import { QuillRecordingObservationsEmptyState } from 'products/replay_vision/frontend/components/QuillRecordingObservationsEmptyState'import { RecordingMoments } from 'products/replay_vision/frontend/components/RecordingMoments'-import { RecordingObservationsEmptyState } from 'products/replay_vision/frontend/components/RecordingObservationsEmptyState'import { observationsDockLogic } from 'products/replay_vision/frontend/logics/observationsDockLogic'import { momentCount } from 'products/replay_vision/frontend/utils/recordingTimeline'import { recordingScanBlock } from 'products/replay_vision/frontend/utils/scanEligibility'@@ -25,10 +25,9 @@ export function WatchPanelTabsWithObservations({const content = !hasLoadedObservations ? (<Skeleton className="h-24 m-2" />) : observations.length === 0 ? (- <RecordingObservationsEmptyState+ <QuillRecordingObservationsEmptyStatesessionId={sessionId}scanBlock={recordingScanBlock(sessionPlayerMetaData)}- surface="watch"/>) : (<div className="flex flex-col max-h-[60vh]">diff --git a/products/replay_vision/frontend/components/QuillRecordingObservationsEmptyState.tsx b/products/replay_vision/frontend/components/QuillRecordingObservationsEmptyState.tsxnew file mode 100644index 000000000000..62ed0da7d752--- /dev/null+++ b/products/replay_vision/frontend/components/QuillRecordingObservationsEmptyState.tsx@@ -0,0 +1,188 @@+import { useValues } from 'kea'++import * as asleepPng from '@posthog/brand/hoggies/png/asleep'+import * as magnifyingGlassPng from '@posthog/brand/hoggies/png/magnifying-glass'+import { Badge, Button } from '@posthog/quill'++import { pngHoggie } from 'lib/brand/hoggies'+import { LinkPrimitive } from 'lib/lemon-ui/Link'+import { urls } from 'scenes/urls'++import { observationsDockLogic } from '../logics/observationsDockLogic'+import { ScannerType } from '../replay_scanners/types'+import { ScanBlock } from '../utils/scanEligibility'+import { VisionDocsPage, visionDocsUrl } from './DocsLink'+import { QuillScannerPicker } from './QuillScannerPicker'+import { QuillScannerTypeBadge } from './QuillScannerTypeBadge'++const HedgehogMagnifyingGlass = pngHoggie(magnifyingGlassPng)+const HedgehogAsleep = pngHoggie(asleepPng)++const SKIPPED_TITLE: Partial<Record<ScanBlock['kind'], string>> = {+ too_short: 'Too short to scan',+ too_inactive: 'Not enough activity to scan',+ too_long: 'Too long to scan',+}++interface ExampleScan {+ scannerType: ScannerType+ name: string+ result: JSX.Element+ line: string+}++// Invented, not sampled.+const EXAMPLE_SCANS: ExampleScan[] = [+ {+ scannerType: 'monitor',+ name: 'Checkout friction',+ result: <Badge variant="info">Yes</Badge>,+ line: 'Nine clicks on a disabled payment button, no request sent',+ },+ {+ scannerType: 'scorer',+ name: 'Frustration',+ result: <span className="font-semibold">8</span>,+ line: 'A rejected card and a retry, then an abandoned purchase',+ },+ {+ scannerType: 'classifier',+ name: 'Support intent',+ result: <Badge>Billing</Badge>,+ line: 'Help search for a payment error, then a plan change',+ },+]++function DocsLink({+ page,+ anchor,+ dataAttr,+ children,+}: {+ page: VisionDocsPage+ anchor?: string+ dataAttr: string+ children: string+}): JSX.Element {+ return (+ <Button+ variant="link"+ size="inline"+ render={+ <LinkPrimitive+ to={`${visionDocsUrl(page)}?utm_medium=in-product&utm_campaign=empty-state-docs-link${anchor ? `#${anchor}` : ''}`}+ target="_blank"+ />+ }+ data-attr={dataAttr}+ >+ {children}+ </Button>+ )+}++function ExampleScanRows({ className }: { className?: string }): JSX.Element {+ return (+ <div+ className={`relative flex min-w-0 flex-col ${className ?? ''}`}+ data-attr="vision-observations-empty-examples"+ >+ <span className="pb-1 text-xs text-muted-foreground">Examples, not your data</span>+ <div className="rounded border border-border opacity-60">+ {EXAMPLE_SCANS.map((scan) => (+ <div+ key={scan.name}+ className="flex items-center gap-2 border-b border-border px-2 py-1.5 last:border-b-0"+ >+ <QuillScannerTypeBadge scannerType={scan.scannerType} iconOnly />+ <span className="shrink-0 text-sm">{scan.name}</span>+ <span className="shrink-0">{scan.result}</span>+ <span className="min-w-0 flex-1 truncate text-xs text-muted-foreground">{scan.line}</span>+ </div>+ ))}+ </div>+ <div+ aria-hidden+ className="pointer-events-none absolute inset-0 bg-gradient-to-b from-transparent from-45% to-background"+ />+ </div>+ )+}++export function QuillRecordingObservationsEmptyState({+ sessionId,+ scanBlock,+}: {+ sessionId: string+ scanBlock: ScanBlock | null+}): JSX.Element {+ const { scanners, scannersLoading } = useValues(observationsDockLogic({ sessionId }))++ if (scanBlock) {+ return (+ <div className="flex flex-wrap items-center gap-4 px-4 py-3" data-attr="vision-observations-skipped">+ <HedgehogAsleep className="h-14 w-14 shrink-0" />+ <div className="flex min-w-0 flex-1 basis-64 flex-col gap-0.5">+ <span className="text-sm font-semibold">+ {SKIPPED_TITLE[scanBlock.kind] ?? 'Replay vision skipped this recording'}+ </span>+ <span className="text-xs text-muted-foreground">{scanBlock.reason}</span>+ </div>+ <DocsLink+ page="running-scanners"+ anchor="ineligible-sessions"+ dataAttr="vision-observations-skipped-docs"+ >+ Which recordings can be scanned+ </DocsLink>+ </div>+ )+ }++ const noScanners = !scannersLoading && scanners.length === 0++ return (+ <div className="@container" data-attr="vision-observations-empty">+ <div className="grid grid-cols-[auto_minmax(0,1fr)] items-center gap-x-4 gap-y-3 px-4 py-4 @[760px]:grid-cols-[6rem_minmax(0,1fr)_minmax(14rem,36%)] @[760px]:gap-x-5 @[760px]:px-5">+ <HedgehogMagnifyingGlass className="h-16 w-16 @[760px]:h-24 @[760px]:w-24" />+ <div className="flex min-w-0 flex-col gap-2">+ <span className="text-sm font-semibold">No observations yet</span>+ <p className="m-0 max-w-[52ch] text-xs text-muted-foreground">+ Summarize this recording above for chapters and a short write-up, or run a scanner to check it+ for something specific.+ </p>+ <div className="mt-1 flex flex-wrap gap-2">+ {noScanners ? (+ <Button+ variant="outline"+ size="sm"+ render={<LinkPrimitive to={urls.replayVisionNewScanner()} />}+ data-attr="vision-observations-empty-create-scanner"+ >+ Create a scanner+ </Button>+ ) : (+ <QuillScannerPicker sessionId={sessionId} scanBlock={null} variant="outline" />+ )}+ </div>+ <div className="flex flex-wrap gap-x-3 gap-y-1 text-xs">+ {!noScanners && (+ <Button+ variant="link"+ size="inline"+ render={<LinkPrimitive to={urls.replayVisionNewScanner()} />}+ data-attr="vision-observations-empty-new-scanner"+ >+ Create a scanner+ </Button>+ )}+ <DocsLink page="observations" dataAttr="vision-observations-empty-docs">+ How observations work+ </DocsLink>+ </div>+ </div>+ <ExampleScanRows className="col-span-2 @[760px]:col-span-1" />+ </div>+ </div>+ )+}diff --git a/products/replay_vision/frontend/components/QuillScannerPicker.tsx b/products/replay_vision/frontend/components/QuillScannerPicker.tsxnew file mode 100644index 000000000000..0f490f949207--- /dev/null+++ b/products/replay_vision/frontend/components/QuillScannerPicker.tsx@@ -0,0 +1,102 @@+import { useActions, useValues } from 'kea'++import { IconChevronDown, IconEye } from '@posthog/icons'+import { Button, Input, Popover, PopoverContent, PopoverTrigger, Spinner } from '@posthog/quill'++import { LinkPrimitive } from 'lib/lemon-ui/Link'+import { urls } from 'scenes/urls'++import type { ReplayScannerApi } from '../generated/api.schemas'+import { observationsDockLogic } from '../logics/observationsDockLogic'+import { visionQuotaLogic } from '../logics/visionQuotaLogic'+import { quotaUx } from '../utils/quotaProjection'+import { ScanBlock } from '../utils/scanEligibility'+import { QuillScannerTypeBadge } from './QuillScannerTypeBadge'++export function QuillScannerPicker({+ sessionId,+ scanBlock,+ variant = 'primary',+}: {+ sessionId: string+ scanBlock: ScanBlock | null+ variant?: 'primary' | 'outline'+}): JSX.Element {+ const logic = observationsDockLogic({ sessionId })+ const { scanners, scannersLoading, filteredScanners, scannerSearch, scannerPickerOpen, observing } =+ useValues(logic)+ const { observe, setScannerSearch, setScannerPickerOpen } = useActions(logic)+ const { quota } = useValues(visionQuotaLogic)+ const { disabledReason: quotaDisabledReason, tooltip: quotaTooltip } = quotaUx(quota)++ return (+ <Popover open={scannerPickerOpen} onOpenChange={setScannerPickerOpen}>+ <PopoverTrigger+ render={+ <Button+ size="sm"+ variant={variant}+ loading={observing}+ disabledReason={scanBlock?.reason ?? quotaDisabledReason}+ tooltip={quotaTooltip}+ data-attr="vision-scan-recording"+ />+ }+ >+ <IconEye />+ Scan this recording+ <IconChevronDown />+ </PopoverTrigger>+ <PopoverContent align="start" className="w-80 p-0">+ <div className="p-1 border-b border-border">+ <Input+ type="search"+ size="sm"+ placeholder="Search scanners…"+ value={scannerSearch}+ onChange={(event) => setScannerSearch(event.target.value)}+ autoFocus+ data-attr="vision-observations-tab-search"+ />+ </div>+ <div className="max-h-80 overflow-y-auto p-1">+ {scanners.length === 0 && scannersLoading ? (+ <div className="flex items-center gap-2 px-2 py-3 text-sm text-muted-foreground">+ <Spinner /> Loading scanners…+ </div>+ ) : scanners.length === 0 ? (+ <Button+ variant="link"+ size="inline"+ className="px-2 py-3 text-sm"+ render={<LinkPrimitive to={urls.replayVision()} target="_blank" />}+ data-attr="vision-observations-open-scanners"+ >+ No scanners yet. Create one+ </Button>+ ) : filteredScanners.length === 0 ? (+ <div className="px-2 py-3 text-sm text-muted-foreground">No scanners match your search.</div>+ ) : (+ filteredScanners.map((scanner: ReplayScannerApi) => (+ <Button+ key={scanner.id}+ size="row"+ left+ className="w-full"+ onClick={() => observe(scanner.id)}+ disabledReason={observing ? 'Starting an observation…' : undefined}+ data-attr="vision-scan-pick-scanner"+ data-ph-capture-attribute-scanner-type={scanner.scanner_type}+ >+ <span className="truncate">{scanner.name}</span>+ <span className="ml-auto shrink-0">+ <QuillScannerTypeBadge scannerType={scanner.scanner_type} />+ </span>+ </Button>+ ))+ )}+ </div>+ </PopoverContent>+ </Popover>+ )+}diff --git a/products/replay_vision/frontend/components/QuillScannerTypeBadge.tsx b/products/replay_vision/frontend/components/QuillScannerTypeBadge.tsxnew file mode 100644index 000000000000..c241ef1558de--- /dev/null+++ b/products/replay_vision/frontend/components/QuillScannerTypeBadge.tsx@@ -0,0 +1,27 @@+import { Badge } from '@posthog/quill'++import { ScannerType, scannerTypeLabel } from '../replay_scanners/types'+import { scannerTypeIcon } from './ScannerTypeBadge'++const SCANNER_TYPE_BADGE_VARIANT: Record<ScannerType, 'info' | 'completed' | 'warning' | 'success' | 'default'> = {+ monitor: 'info',+ classifier: 'completed',+ scorer: 'warning',+ summarizer: 'success',+ experiment: 'default',+}++export function QuillScannerTypeBadge({+ scannerType,+ iconOnly = false,+}: {+ scannerType: ScannerType+ iconOnly?: boolean+}): JSX.Element {+ return (+ <Badge variant={SCANNER_TYPE_BADGE_VARIANT[scannerType]} className="w-fit gap-1">+ {scannerTypeIcon(scannerType)}+ {!iconOnly && scannerTypeLabel(scannerType)}+ </Badge>+ )+}diff --git a/products/replay_vision/frontend/components/QuillSummarizeButton.tsx b/products/replay_vision/frontend/components/QuillSummarizeButton.tsxnew file mode 100644index 000000000000..3ff1005fd033--- /dev/null+++ b/products/replay_vision/frontend/components/QuillSummarizeButton.tsx@@ -0,0 +1,177 @@+import { useActions, useValues } from 'kea'+import posthog from 'posthog-js'+import { useState } from 'react'++import { IconChevronDown, IconLogomark, IconNotebook } from '@posthog/icons'+import { Button, ButtonGroup, DropdownMenu, DropdownMenuContent, DropdownMenuTrigger } from '@posthog/quill'++import { LemonMenuItems } from 'lib/lemon-ui/LemonMenu/LemonMenu'+import { LinkPrimitive } from 'lib/lemon-ui/Link'+import { QuillMenuItems } from 'scenes/session-recordings/playlist/QuillMenuItems'+import { AIConsentPopoverWrapper } from 'scenes/settings/organization/AIConsentPopoverWrapper'++import { aiConsentLogic } from '~/layout/ai/aiConsentLogic'++import type { ReplayScannerApi } from '../generated/api.schemas'+import { observationsDockLogic } from '../logics/observationsDockLogic'+import { visionQuotaLogic } from '../logics/visionQuotaLogic'+import { BUILT_IN_SUMMARY_LABEL, isSummaryObservation } from '../utils/observation'+import { quotaUx } from '../utils/quotaProjection'+import { ScanBlock } from '../utils/scanEligibility'+import { visionDocsUrl } from './DocsLink'+import { useSummarizeBlockedReason } from './useSummarizeBlockedReason'++/** Runs whichever summarizer `resolveSummarizer` settles on, and lets the user pick another. */+export function QuillSummarizeButton({+ sessionId,+ scanBlock,+}: {+ sessionId: string+ scanBlock: ScanBlock | null+}): JSX.Element {+ const logic = observationsDockLogic({ sessionId })+ const { summarizePending, defaultSummarizer, summarizerScanners, observations } = useValues(logic)+ const { summarize, summarizeWith } = useActions(logic)+ const hasSummary = observations.some((o) => isSummaryObservation(o) && o.status === 'succeeded')+ const { quota } = useValues(visionQuotaLogic)+ const { dataProcessingAccepted } = useValues(aiConsentLogic)+ const [consentRequested, setConsentRequested] = useState(false)+ const { tooltip: quotaTooltip } = quotaUx(quota)+ const blockedReason = useSummarizeBlockedReason(scanBlock)+ // The menu rows are their own buttons, so without this a second summarizer can start mid-run and spend the quota again.+ const inFlightDisabledReason = summarizePending ? 'A summary is already running' : null+ const builtInDisabledReason = inFlightDisabledReason ?? blockedReason()+ const scannerDisabledReason = (scanner: ReplayScannerApi): string | null | undefined =>+ inFlightDisabledReason ?? blockedReason(scanner)+ // While a scan runs the label is the only sign the click landed, because the summary takes minutes.+ const idleLabel = hasSummary+ ? 'Summarize again'+ : defaultSummarizer+ ? `Summarize with ${defaultSummarizer.name}`+ : 'Summarize this recording'+ const label = summarizePending ? 'Summarizing…' : idleLabel+ const summarizerTooltip = summarizePending+ ? 'Watching this recording. The summary appears in the Observations section when it is ready.'+ : defaultSummarizer+ ? `Runs your "${defaultSummarizer.name}" scanner on this recording.`+ : 'Writes a summary using a built-in prompt.'++ const menuItems: LemonMenuItems = [+ ...summarizerScanners.map((scanner) => ({+ key: scanner.id,+ label: scanner.name,+ active: scanner.id === defaultSummarizer?.id,+ disabledReason: scannerDisabledReason(scanner),+ onClick: () => summarizeWith(scanner.id, true),+ 'data-attr': 'vision-summarize-pick-scanner',+ })),+ {+ key: 'built-in',+ label: (+ <span className="flex items-center justify-between gap-2 w-full">+ <span className="truncate">{BUILT_IN_SUMMARY_LABEL}</span>+ <span className="flex items-center gap-1.5 text-xs shrink-0 text-muted-foreground">+ <IconLogomark className="text-base" />+ Built in+ </span>+ </span>+ ),+ tooltip: 'Uses a built-in prompt. Nothing is saved to your scanners, so there is nothing to open or edit.',+ active: !defaultSummarizer,+ disabledReason: builtInDisabledReason,+ onClick: () => summarizeWith(null, true),+ 'data-attr': 'vision-summarize-pick-built-in',+ },+ ]+ const showMenu = summarizerScanners.length > 0 && dataProcessingAccepted++ const button = (+ <Button+ size="sm"+ variant={hasSummary ? 'outline' : 'primary'}+ loading={summarizePending}+ // The endpoint refuses without org AI approval, so ask for it here rather than toasting a 400.+ onClick={() => {+ posthog.capture('replay_vision_summarize_clicked', {+ recording_id: sessionId,+ summarizer: defaultSummarizer ? 'configured' : 'built-in',+ consent_needed: !dataProcessingAccepted,+ })+ if (dataProcessingAccepted) {+ summarize(true)+ } else {+ setConsentRequested(true)+ }+ }}+ disabledReason={defaultSummarizer ? scannerDisabledReason(defaultSummarizer) : builtInDisabledReason}+ tooltip={+ quotaTooltip ?? (+ <span className="block max-w-72">+ <span className="block mb-1">Replay vision uses AI to watch recordings for you.</span>+ <span className="block">{summarizerTooltip}</span>+ <LinkPrimitive+ to={`${visionDocsUrl()}?utm_medium=in-product&utm_campaign=summarize-explainer`}+ target="_blank"+ className="block mt-1 underline"+ >+ Read the docs+ </LinkPrimitive>+ </span>+ )+ }+ data-attr="vision-summarize-recording"+ data-ph-capture-attribute-summarizer={defaultSummarizer ? 'configured' : 'built-in'}+ >+ <IconNotebook />+ <span className="truncate">{dataProcessingAccepted ? label : 'Allow AI analysis and summarize'}</span>+ </Button>+ )++ // The dropdown is the only way to reach a second summarizer, so it appears once one exists.+ const group = showMenu ? (+ <ButtonGroup>+ {button}+ <DropdownMenu>+ <DropdownMenuTrigger+ render={+ <Button+ size="icon-sm"+ variant={hasSummary ? 'outline' : 'primary'}+ aria-label="Choose a summarizer"+ disabledReason={inFlightDisabledReason ?? undefined}+ data-attr="vision-summarize-choose"+ />+ }+ >+ <IconChevronDown />+ </DropdownMenuTrigger>+ <DropdownMenuContent align="end">+ <QuillMenuItems items={menuItems} />+ </DropdownMenuContent>+ </DropdownMenu>+ </ButtonGroup>+ ) : (+ button+ )++ if (dataProcessingAccepted) {+ return group+ }++ return (+ <AIConsentPopoverWrapper+ placement="bottom-end"+ showArrow+ ignoreDismissal+ hideTrainingDisclaimer+ hidden={!consentRequested}+ onApprove={() => {+ setConsentRequested(false)+ summarize(true)+ }}+ onDismiss={() => setConsentRequested(false)}+ >+ {group}+ </AIConsentPopoverWrapper>+ )+}diff --git a/products/replay_vision/frontend/components/QuillSummarizeRecordingBar.tsx b/products/replay_vision/frontend/components/QuillSummarizeRecordingBar.tsxnew file mode 100644index 000000000000..28f40f0d30f6--- /dev/null+++ b/products/replay_vision/frontend/components/QuillSummarizeRecordingBar.tsx@@ -0,0 +1,26 @@+import { useValues } from 'kea'++import { sessionRecordingDataCoordinatorLogic } from 'scenes/session-recordings/player/sessionRecordingDataCoordinatorLogic'+import { sessionRecordingPlayerLogic } from 'scenes/session-recordings/player/sessionRecordingPlayerLogic'++import { recordingScanBlock } from '../utils/scanEligibility'+import { QuillSummarizeButton } from './QuillSummarizeButton'++/** The summarize controls for the watch layouts, placed inside the title block's action row. */+export function QuillSummarizeRecordingBar(): JSX.Element | null {+ const { sessionRecordingId, logicProps, sessionPlayerMetaData } = useValues(sessionRecordingPlayerLogic)+ const { isNotFound, isRecordingDeleted } = useValues(sessionRecordingDataCoordinatorLogic(logicProps))++ if (!sessionRecordingId || isNotFound || isRecordingDeleted) {+ return null+ }+ return (+ // Frozen: dashboards and selectors still find the bar under its old name.+ <div className="flex items-center gap-2 min-w-0" data-attr="vision-observations-dock">+ <QuillSummarizeButton+ sessionId={sessionRecordingId}+ scanBlock={recordingScanBlock(sessionPlayerMetaData)}+ />+ </div>+ )+}