: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
fix(phai): hand homepage prompts to the new PostHog AI surface (#78144)
Georgiy Tarasov08915d6d4937
diff --git a/frontend/src/scenes/project-homepage/ai-first/aiFirstHomepageLogic.test.ts b/frontend/src/scenes/project-homepage/ai-first/aiFirstHomepageLogic.test.tsindex 5b463004c4b2..f011f621d3d3 100644--- a/frontend/src/scenes/project-homepage/ai-first/aiFirstHomepageLogic.test.ts+++ b/frontend/src/scenes/project-homepage/ai-first/aiFirstHomepageLogic.test.ts@@ -1,6 +1,7 @@import { router } from 'kea-router'import { expectLogic } from 'kea-test-utils'+import { FEATURE_FLAGS } from 'lib/constants'import { featureFlagLogic } from 'lib/logic/featureFlagLogic'import { maxLogic } from 'scenes/max/maxLogic'import { urls } from 'scenes/urls'@@ -50,4 +51,28 @@ describe('aiFirstHomepageLogic', () => {expect(maxLogic({ panelId: HOMEPAGE_TAB_ID }).values.question).toEqual('what is my dau')expect(sidePanelStateLogic.values.sidePanelOpen).toBe(false)})++ // The homepage chat only drives the legacy runtime. Without the handoff, a prompt submitted by a+ // user on the new PostHog AI surface starts a LangGraph conversation that surface never renders,+ // so the submit looks like it did nothing.+ it.each([+ ['legacy view', false, '/project/997/home', 'ai'],+ ['new view', true, '/project/997/ai', 'idle'],+ ])('submitting a prompt on the %s', async (_case, sandboxFlagOn, expectedPathname, expectedMode) => {+ if (sandboxFlagOn) {+ featureFlagLogic.actions.setFeatureFlags([FEATURE_FLAGS.PHAI_SANDBOX_MODE], {+ [FEATURE_FLAGS.PHAI_SANDBOX_MODE]: true,+ })+ }+ router.actions.push(urls.projectHomepage())++ logic.actions.setQuery('what is my dau')+ logic.actions.submitQuery('ai')+ await expectLogic(logic).delay(1)++ expect(router.values.location.pathname).toEqual(expectedPathname)+ expect(logic.values.mode).toEqual(expectedMode)+ // The prompt rides along as `ask`, which the new surface's composer seeds and submits.+ expect(router.values.searchParams.ask).toEqual(sandboxFlagOn ? 'what is my dau' : undefined)+ })})diff --git a/frontend/src/scenes/project-homepage/ai-first/aiFirstHomepageLogic.ts b/frontend/src/scenes/project-homepage/ai-first/aiFirstHomepageLogic.tsindex 8902f1908897..e62d62ede1c2 100644--- a/frontend/src/scenes/project-homepage/ai-first/aiFirstHomepageLogic.ts+++ b/frontend/src/scenes/project-homepage/ai-first/aiFirstHomepageLogic.ts@@ -12,6 +12,7 @@ import {capabilitiesForGrouping,capabilityGroupingFromVariant,} from 'scenes/max/maxCapabilities'+import { type PhaiViewMode, maxGlobalLogic } from 'scenes/max/maxGlobalLogic'import { maxLogic, parseCommandString } from 'scenes/max/maxLogic'import { teamLogic } from 'scenes/teamLogic'import { urls } from 'scenes/urls'@@ -88,6 +89,7 @@ export interface aiFirstHomepageLogicValues {dashboardsLoading: boolean // dashboardsModelpinnedDashboards: (DashboardBasicType | DashboardType<QueryBasedInsightModel<Node<Record<string, any>>>>)[] // dashboardsModelfeatureFlags: FeatureFlagsSet // featureFlagLogic+ effectivePhaiView: PhaiViewMode // maxGlobalLogicconversationId: string | null // maxLogicthreadLogicKey: string // maxLogiccachedStarred: FileSystemEntry[] // projectTreeDataLogic@@ -221,6 +223,8 @@ export const aiFirstHomepageLogic = kea<aiFirstHomepageLogicType>([['chatDraftFor'],featureFlagLogic,['featureFlags'],+ maxGlobalLogic,+ ['effectivePhaiView'],],actions: [maxLogic({ panelId: HOMEPAGE_TAB_ID }),@@ -406,6 +410,18 @@ export const aiFirstHomepageLogic = kea<aiFirstHomepageLogicType>([// resurrect it as "unsent input" the next time the homepage is mounted.actions.setChatDraftForTab(HOMEPAGE_IDLE_DRAFT_KEY, '')+ // The homepage chat only drives the legacy runtime, so on the new PostHog AI surface a prompt+ // submitted here would start a LangGraph conversation that surface never shows. Hand it to+ // /ai instead, which seeds its composer from `ask` and submits it. An AI submit with no+ // prompt is a chat being restored from `?mode=ai&chat=…` — that still opens here.+ if (mode === 'ai' && values.effectivePhaiView === 'new' && values.query.trim()) {+ router.actions.push(urls.ai(undefined, values.query))+ // Undo the mode flip the reducers just made, so the legacy homepage thread never mounts+ // and fires a second, competing send while the route change lands.+ actions.returnToIdle()+ return+ }+if (mode === 'ai' && !values.conversationId) {actions.startNewConversation()}@@ -456,8 +472,15 @@ export const aiFirstHomepageLogic = kea<aiFirstHomepageLogicType>([})),actionToUrl(({ values }) => ({- submitQuery: () => {+ submitQuery: ({ mode: submittedMode }) => {const { mode, query } = values+ // On the new PostHog AI surface the homepage never owns an AI route: a submit with a prompt+ // is navigated to /ai by the listener (which reads the query before clearing it), and one+ // without is a restore that arrived on this URL already. Keyed off the submitted mode rather+ // than `values.mode`, which the listener may already have reset.+ if (submittedMode === 'ai' && values.effectivePhaiView === 'new') {+ return undefined+ }if (mode === 'ai') {return [urls.projectHomepage(),