: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(posthog-ai): open turn suggestion cards condensed (#122292)
Rafael Audibert2b17b93cf7c0
diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex 27edf05f1eaf..20c8c31ac191 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -7908,6 +7908,10 @@ snapshots:hash: v1.k794b7964.1d792984be0657f406e45722e1b4799905c474a28f8c985c8e406377a8dd97e7.gQ65VeoKFMTS04UA7UjbntfuL7nkr6Zpk-mhvoTf9X4products-posthog-ai-turnsuggestioncard--alert-suggestion--light:hash: v1.k794b7964.3c7adbcba23292f8890353b7e6788dfb5828d88388ed66d788cbf1951dd45abf.byZ29GpYD4aDnWNIvEXYy1vrSoR6au3ieBIMqNb8tMw+ products-posthog-ai-turnsuggestioncard--condensed-suggestion--dark:+ hash: v1.k794b7964.139710bfad513236c32717c3e9af5b2e8a535cf7cc2ba067d57a5aa59b19e841.gsYrCNFXod9D-SQbpM6KAWfZcT_wVhYh2ouMQFyTCL0+ products-posthog-ai-turnsuggestioncard--condensed-suggestion--light:+ hash: v1.k794b7964.678728d0f09ec1d6d7a282f82e76812d2662c72e075db139a3d1ea7e6248fb2e.XXf85C-_cDHfZ2fRvW0rx8vhBXFMvMot4BAq35MNfnQproducts-posthog-ai-turnsuggestioncard--error-alert-suggestion--dark:hash: v1.k794b7964.c11acf3ed061e235f538dba634b3503de9b40201f89ddb80a4240354e4bb718f.tv5z2ob1K9r9p_i_a4gGkdSQiJqyU7KLpUMrnH3PC50products-posthog-ai-turnsuggestioncard--error-alert-suggestion--light:diff --git a/products/posthog_ai/frontend/components/SuggestionCardCondensed.tsx b/products/posthog_ai/frontend/components/SuggestionCardCondensed.tsxnew file mode 100644index 000000000000..a9dcaf4d8fc8--- /dev/null+++ b/products/posthog_ai/frontend/components/SuggestionCardCondensed.tsx@@ -0,0 +1,34 @@+import { IconChevronDown } from '@posthog/icons'++export interface SuggestionCardCondensedProps {+ icon: JSX.Element+ title: string+ draftName: string+ onExpand: () => void+}++export function SuggestionCardCondensed({+ icon,+ title,+ draftName,+ onExpand,+}: SuggestionCardCondensedProps): JSX.Element {+ return (+ <div className="my-2" data-attr="posthog-ai-turn-suggestion">+ <button+ type="button"+ onClick={onExpand}+ aria-expanded={false}+ className="flex w-full cursor-pointer items-center gap-2 rounded border bg-surface-primary px-3 py-2 text-left hover:bg-surface-secondary"+ data-attr="posthog-ai-turn-suggestion-expand"+ >+ <span className="shrink-0 text-xl text-accent">{icon}</span>+ <span className="flex min-w-0 flex-1 flex-col">+ <span className="font-semibold">{title}</span>+ {draftName && <span className="truncate text-sm text-secondary">{draftName}</span>}+ </span>+ <IconChevronDown className="shrink-0 text-xl text-secondary" />+ </button>+ </div>+ )+}diff --git a/products/posthog_ai/frontend/components/TurnSuggestionCard.stories.tsx b/products/posthog_ai/frontend/components/TurnSuggestionCard.stories.tsxindex 88c27cb8d5d2..7250ad5983cf 100644--- a/products/posthog_ai/frontend/components/TurnSuggestionCard.stories.tsx+++ b/products/posthog_ai/frontend/components/TurnSuggestionCard.stories.tsx@@ -6,6 +6,7 @@ import { mswDecorator } from '~/mocks/browser'import { mockIntegration } from '~/test/mocks'import { runStreamLogic } from '../logics/runStreamLogic'+import { turnSuggestionLogic } from '../logics/turnSuggestionLogic'import { ThreadView } from './ThreadView'import { TurnFeedbackActions } from './TurnFeedbackActions'import { TurnSuggestionCard } from './TurnSuggestionCard'@@ -14,6 +15,7 @@ type Kind = 'scout' | 'notebook' | 'alert' | 'subscription' | 'error_alert'interface StoryArgs {kind: Kind+ expanded?: boolean/** The scene width next to an open side panel on a 1280px window. */narrow?: boolean}@@ -237,7 +239,9 @@ const FRAMES_BY_KIND: Record<Kind, Record<string, unknown>[]> = {error_alert: ERROR_ALERT_TURN_FRAMES,}-function TurnSuggestionStory({ kind, narrow }: StoryArgs): JSX.Element {+const CARD_PROPS = { streamKey: STREAM_KEY, turnIndex: 0, sessionId: SESSION_ID, revealDelayMs: 0 }++function TurnSuggestionStory({ kind, expanded, narrow }: StoryArgs): JSX.Element {useEffect(() => {const stream = runStreamLogic({ streamKey: STREAM_KEY })const unmountStream = stream.mount()@@ -245,8 +249,16 @@ function TurnSuggestionStory({ kind, narrow }: StoryArgs): JSX.Element {stream.actions.ingestAcpFrame(frame as any, 'replay')}stream.actions.setTurnSuggestionLedger({ taskId: SESSION_ID, muted: false, resolvedTurns: [] })- return unmountStream- }, [kind])+ const card = turnSuggestionLogic(CARD_PROPS)+ const unmountCard = card.mount()+ if (expanded) {+ card.actions.expand()+ }+ return () => {+ unmountCard()+ unmountStream()+ }+ }, [kind, expanded])return (<div className={`${narrow ? 'w-130' : 'w-180'} max-w-full rounded border p-4`}>@@ -313,14 +325,16 @@ function mocks(): Parameters<typeof mswDecorator>[0] {const meta: Meta<StoryArgs> = {title: 'Products/PostHog AI/TurnSuggestionCard',parameters: { mockDate: '2026-09-16', testOptions: { waitForLoadersToDisappear: true } },- args: { kind: 'scout' },+ args: { kind: 'scout', expanded: true },decorators: [mswDecorator(mocks())],- render: ({ kind, narrow }) => <TurnSuggestionStory kind={kind} narrow={narrow} />,+ render: ({ kind, expanded, narrow }) => <TurnSuggestionStory kind={kind} expanded={expanded} narrow={narrow} />,}export default metatype Story = StoryObj<StoryArgs>+export const CondensedSuggestion: Story = { args: { kind: 'alert', expanded: false } }+export const ScoutSuggestion: Story = {}export const ScoutSuggestionNarrow: Story = { args: { kind: 'scout', narrow: true } }diff --git a/products/posthog_ai/frontend/components/TurnSuggestionCard.tsx b/products/posthog_ai/frontend/components/TurnSuggestionCard.tsxindex 3a05ef243e14..5c280e154c69 100644--- a/products/posthog_ai/frontend/components/TurnSuggestionCard.tsx+++ b/products/posthog_ai/frontend/components/TurnSuggestionCard.tsx@@ -5,11 +5,13 @@ import { IconBell, IconCalendar, IconNotebook, IconTelescope, IconWarning } fromimport { TurnSuggestionLogicProps, turnSuggestionLogic } from '../logics/turnSuggestionLogic'import type { TurnSuggestion } from '../types/streamTypes'+import { suggestionDraftName } from '../utils/turnSuggestions'import { AlertSuggestionCard } from './AlertSuggestionCard'import { ErrorAlertSuggestionCard } from './ErrorAlertSuggestionCard'import { NotebookSuggestionCard } from './NotebookSuggestionCard'import { ScoutSuggestionCard } from './ScoutSuggestionCard'import { SubscriptionSuggestionCard } from './SubscriptionSuggestionCard'+import { SuggestionCardCondensed } from './SuggestionCardCondensed'import { SuggestionCardShell } from './SuggestionCardShell'const CARD_BY_KIND: Record<@@ -25,8 +27,8 @@ const CARD_BY_KIND: Record<export function TurnSuggestionCard(logicProps: TurnSuggestionLogicProps): JSX.Element | null {const logic = turnSuggestionLogic(logicProps)- const { suggestion, visible, completed, shownSuggestion } = useValues(logic)- const { dismiss, reportShown } = useActions(logic)+ const { suggestion, visible, completed, expanded, shownSuggestion } = useValues(logic)+ const { dismiss, expand, reportShown } = useActions(logic)useEffect(() => {// Server frames carry no event id, so a thread that loads the log and then the live tail gets the card frame twice.@@ -41,14 +43,23 @@ export function TurnSuggestionCard(logicProps: TurnSuggestionLogicProps): JSX.Elconst { icon, Body } = CARD_BY_KIND[suggestion.kind]return (<div className="animate-fade-in [animation-duration:600ms] motion-reduce:animate-none">- <SuggestionCardShell- icon={icon}- title={suggestion.title}- description={suggestion.description}- onDismiss={completed ? undefined : dismiss}- >- <Body {...logicProps} />- </SuggestionCardShell>+ {expanded ? (+ <SuggestionCardShell+ icon={icon}+ title={suggestion.title}+ description={suggestion.description}+ onDismiss={completed ? undefined : dismiss}+ >+ <Body {...logicProps} />+ </SuggestionCardShell>+ ) : (+ <SuggestionCardCondensed+ icon={icon}+ title={suggestion.title}+ draftName={suggestionDraftName(suggestion)}+ onExpand={expand}+ />+ )}</div>)}diff --git a/products/posthog_ai/frontend/logics/runStreamLogic.ts b/products/posthog_ai/frontend/logics/runStreamLogic.tsindex 078e516841dd..6ff28b816087 100644--- a/products/posthog_ai/frontend/logics/runStreamLogic.ts+++ b/products/posthog_ai/frontend/logics/runStreamLogic.ts@@ -2673,6 +2673,7 @@ export interface runStreamLogicValues {turnComplete: booleanturnSuggestion: TurnSuggestion | nullturnSuggestionAcceptedHere: number | null+ turnSuggestionExpandedHere: number | nullturnSuggestionLedger: TurnSuggestionLedger | nullturnSuggestionOutcomesHere: Record<number, string>turnSuggestionsMuted: boolean@@ -2825,6 +2826,9 @@ export interface runStreamLogicActions {markTurnSuggestionAccepted: (turnIndex: number) => {turnIndex: number}+ markTurnSuggestionExpanded: (turnIndex: number) => {+ turnIndex: number+ }mergeRunArtifacts: (partial: Partial<RunArtifacts>) => {partial: Partial<RunArtifacts>}@@ -3258,6 +3262,7 @@ export const runStreamLogic = kea<runStreamLogicType>([/** Records an outcome this tab sent to the server, so the card closes before the frame echoes back. */recordTurnSuggestionOutcome: (turnIndex: number, outcome: string) => ({ turnIndex, outcome }),markTurnSuggestionAccepted: (turnIndex: number) => ({ turnIndex }),+ markTurnSuggestionExpanded: (turnIndex: number) => ({ turnIndex }),/*** Reopens the turn for a follow-up that started outside this composer, such as one sent from Slack* or from another tab. Dispatched from a user turn seen on the wire, and from the agent's first@@ -3684,6 +3689,15 @@ export const runStreamLogic = kea<runStreamLogicType>([reset: () => null,},],+ // The card's own logic unmounts when the virtualized thread recycles its row, so the open state lives here+ // to keep an opened card open after the reader scrolls away and back.+ turnSuggestionExpandedHere: [+ null as number | null,+ {+ markTurnSuggestionExpanded: (_, { turnIndex }) => turnIndex,+ reset: () => null,+ },+ ],turnComplete: [false,{diff --git a/products/posthog_ai/frontend/logics/turnSuggestionLogic.test.ts b/products/posthog_ai/frontend/logics/turnSuggestionLogic.test.tsindex 964755fbc280..6eed01df0e2e 100644--- a/products/posthog_ai/frontend/logics/turnSuggestionLogic.test.ts+++ b/products/posthog_ai/frontend/logics/turnSuggestionLogic.test.ts@@ -95,6 +95,19 @@ describe('turnSuggestionLogic', () => {})})+ it('keeps an expanded card expanded after its row unmounts and mounts again', async () => {+ await mountStreamWithSuggestion()+ const card = { streamKey: STREAM_KEY, turnIndex: 1, sessionId: 'task', revealDelayMs: 0 }++ const unmount = turnSuggestionLogic(card).mount()+ expect(turnSuggestionLogic(card).values.expanded).toBe(false)+ turnSuggestionLogic(card).actions.expand()+ unmount()++ turnSuggestionLogic(card).mount()+ expect(turnSuggestionLogic(card).values.expanded).toBe(true)+ })+it('records no accept when the accept skipped the create', async () => {const stream = await mountStreamWithSuggestion()const card = { streamKey: STREAM_KEY, turnIndex: 1, sessionId: 'task', revealDelayMs: 0 }diff --git a/products/posthog_ai/frontend/logics/turnSuggestionLogic.ts b/products/posthog_ai/frontend/logics/turnSuggestionLogic.tsindex 577c438911a0..f935d4946f40 100644--- a/products/posthog_ai/frontend/logics/turnSuggestionLogic.ts+++ b/products/posthog_ai/frontend/logics/turnSuggestionLogic.ts@@ -36,8 +36,10 @@ export interface turnSuggestionLogicValues {currentProjectId: number | null // projectLogicsuggestion: TurnSuggestion | null // runStreamLogicturnSuggestionAcceptedHere: number | null // runStreamLogic+ turnSuggestionExpandedHere: number | null // runStreamLogiccompleted: booleandismissed: boolean+ expanded: booleanrevealReady: booleanshownSuggestion: TurnSuggestion | nullvisible: boolean@@ -45,6 +47,9 @@ export interface turnSuggestionLogicValues {// Generated by kea-typegen. Update if you're an agent, ignore if you're human.export interface turnSuggestionLogicActions {+ markTurnSuggestionExpanded: (turnIndex: number) => {+ turnIndex: number+ } // runStreamLogicrecordTurnSuggestionOutcome: (turnIndex: number,outcome: string@@ -55,6 +60,9 @@ export interface turnSuggestionLogicActions {dismiss: () => {value: true}+ expand: () => {+ value: true+ }reportShown: (suggestion: TurnSuggestion) => {suggestion: TurnSuggestion}@@ -68,6 +76,7 @@ export interface turnSuggestionLogicMeta {key: string__keaTypeGenInternalSelectorTypes: {completed: (turnSuggestionAcceptedHere: number | null, shownSuggestion: TurnSuggestion | null) => boolean+ expanded: (turnSuggestionExpandedHere: number | null, suggestion: TurnSuggestion | null) => booleanvisible: (suggestion: TurnSuggestion | null, revealReady: boolean, dismissed: boolean) => boolean}}@@ -86,14 +95,18 @@ export const turnSuggestionLogic: LogicWrapper<turnSuggestionLogicType> = kea<tuconnect((props: TurnSuggestionLogicProps) => ({values: [runStreamLogic({ streamKey: props.streamKey }),- ['turnSuggestion as suggestion', 'turnSuggestionAcceptedHere'],+ ['turnSuggestion as suggestion', 'turnSuggestionAcceptedHere', 'turnSuggestionExpandedHere'],projectLogic,['currentProjectId'],],- actions: [runStreamLogic({ streamKey: props.streamKey }), ['recordTurnSuggestionOutcome']],+ actions: [+ runStreamLogic({ streamKey: props.streamKey }),+ ['recordTurnSuggestionOutcome', 'markTurnSuggestionExpanded'],+ ],})),actions({dismiss: true,+ expand: true,reveal: true,reportShown: (suggestion: TurnSuggestion) => ({ suggestion }),}),@@ -113,6 +126,11 @@ export const turnSuggestionLogic: LogicWrapper<turnSuggestionLogicType> = kea<tu(turnSuggestionAcceptedHere: number | null, shownSuggestion: TurnSuggestion | null): boolean =>shownSuggestion !== null && turnSuggestionAcceptedHere === shownSuggestion.turnIndex,],+ expanded: [+ (s) => [s.turnSuggestionExpandedHere, s.suggestion],+ (turnSuggestionExpandedHere: number | null, suggestion: TurnSuggestion | null): boolean =>+ suggestion !== null && turnSuggestionExpandedHere === suggestion.turnIndex,+ ],visible: [(s) => [s.suggestion, s.revealReady, s.dismissed],(suggestion: TurnSuggestion | null, revealReady: boolean, dismissed: boolean): boolean =>@@ -123,6 +141,13 @@ export const turnSuggestionLogic: LogicWrapper<turnSuggestionLogicType> = kea<tureportShown: ({ suggestion }) => {captureTurnSuggestionEvent('shown', props, suggestion)},+ expand: () => {+ const { suggestion } = values+ if (suggestion && !values.expanded) {+ actions.markTurnSuggestionExpanded(suggestion.turnIndex)+ captureTurnSuggestionEvent('expanded', props, suggestion)+ }+ },dismiss: () => {const { suggestion } = valuesif (suggestion) {diff --git a/products/posthog_ai/frontend/utils/turnSuggestionEvents.ts b/products/posthog_ai/frontend/utils/turnSuggestionEvents.tsindex 20a937480e52..271bb76e9f5a 100644--- a/products/posthog_ai/frontend/utils/turnSuggestionEvents.ts+++ b/products/posthog_ai/frontend/utils/turnSuggestionEvents.ts@@ -24,6 +24,7 @@ function turnSuggestionEventProperties(export type TurnSuggestionEvent =| 'shown'+ | 'expanded'| 'dismissed'| 'superseded'| 'accepted'diff --git a/products/posthog_ai/frontend/utils/turnSuggestions.ts b/products/posthog_ai/frontend/utils/turnSuggestions.tsindex a64e29d77b6d..6e03295c2270 100644--- a/products/posthog_ai/frontend/utils/turnSuggestions.ts+++ b/products/posthog_ai/frontend/utils/turnSuggestions.ts@@ -184,3 +184,19 @@ export function parseTurnSuggestionParams(params: unknown): TurnSuggestion | nulexport function cadenceLabel(cadence: ScoutSuggestionCadence): string {return cadence === 'daily' ? 'every day' : 'every week'}++/** The name of the thing the card creates, as the condensed card shows it under the title. */+export function suggestionDraftName(suggestion: TurnSuggestion): string {+ switch (suggestion.kind) {+ case 'scout':+ return suggestion.scout.displayName+ case 'notebook':+ return suggestion.notebook.title+ case 'alert':+ return suggestion.alert.insightName+ case 'subscription':+ return suggestion.subscription.insightName+ case 'error_alert':+ return suggestion.errorAlert.issueName+ }+}