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(max): don't navigate to /ai when opening side panel chat (#62065)

Mike Warren8d85d2fabad8
diff --git a/frontend/src/layout/navigation-3000/sidepanel/panels/max/SidePanelMax.tsx b/frontend/src/layout/navigation-3000/sidepanel/panels/max/SidePanelMax.tsx
index f72a303a439f..fcc7688e44c3 100644
--- a/frontend/src/layout/navigation-3000/sidepanel/panels/max/SidePanelMax.tsx
+++ b/frontend/src/layout/navigation-3000/sidepanel/panels/max/SidePanelMax.tsx
@@ -1,5 +1,5 @@
import { MaxInstance } from 'scenes/max/Max'
export function SidePanelMax(): JSX.Element | null {
- return <MaxInstance sidePanel tabId="sidepanel" />
+ return <MaxInstance sidePanel />
}
diff --git a/frontend/src/scenes/feature-flags/NewFeatureFlagMenu.tsx b/frontend/src/scenes/feature-flags/NewFeatureFlagMenu.tsx
index d3f0b25f7b90..1c2f89fa8033 100644
--- a/frontend/src/scenes/feature-flags/NewFeatureFlagMenu.tsx
+++ b/frontend/src/scenes/feature-flags/NewFeatureFlagMenu.tsx
@@ -109,7 +109,7 @@ function IntentSubmenu({ template, onBack }: { template: TemplateKey; onBack: ()
export function OverlayForNewFeatureFlagMenu(): JSX.Element {
const { featureFlags } = useValues(enabledFeaturesLogic)
- const { setActiveGroup } = useActions(maxLogic({ tabId: 'sidepanel' }))
+ const { setActiveGroup } = useActions(maxLogic({ sidePanel: true }))
const { openSidePanel } = useActions(sidePanelLogic)
const intentsEnabled = !!featureFlags[FEATURE_FLAGS.FEATURE_FLAG_CREATION_INTENTS]
diff --git a/frontend/src/scenes/max/Max.tsx b/frontend/src/scenes/max/Max.tsx
index b17a95167af0..e28e53fe55ae 100644
--- a/frontend/src/scenes/max/Max.tsx
+++ b/frontend/src/scenes/max/Max.tsx
@@ -35,7 +35,7 @@ import { ThreadAutoScroller } from './components/ThreadAutoScroller'
import { ConversationHistory } from './ConversationHistory'
import { HistoryPreview } from './HistoryPreview'
import { Intro } from './Intro'
-import { maxLogic } from './maxLogic'
+import { MaxLogicProps, maxLogic } from './maxLogic'
import { MaxThreadLogicProps, maxThreadLogic } from './maxThreadLogic'
import { Thread } from './Thread'
@@ -48,7 +48,7 @@ export function Max({ tabId }: { tabId?: string }): JSX.Element {
const { sidePanelOpen, selectedTab } = useValues(sidePanelLogic)
const { closeSidePanel } = useActions(sidePanelLogic)
const { conversationId: tabConversationId } = useValues(maxLogic({ tabId: tabId || '' }))
- const { conversationId: sidepanelConversationId } = useValues(maxLogic({ tabId: 'sidepanel' }))
+ const { conversationId: sidepanelConversationId } = useValues(maxLogic({ sidePanel: true }))
if (sidePanelOpen && selectedTab === SidePanelTab.Max && sidepanelConversationId === tabConversationId) {
return (
<SceneContent className="px-4 py-4 min-h-[calc(100vh-var(--scene-layout-header-height)-120px)]">
@@ -75,10 +75,15 @@ export function Max({ tabId }: { tabId?: string }): JSX.Element {
export interface MaxInstanceProps {
sidePanel?: boolean
- tabId: string
+ tabId?: string
}
export const MaxInstance = React.memo(function MaxInstance({ sidePanel, tabId }: MaxInstanceProps): JSX.Element {
+ // `sidePanel` here is presentational (side panel chrome/layout) and is independent of which
+ // logic instance we bind: a tabId identifies a scene tab (or a Storybook instance rendered with
+ // side panel chrome), and only the real side panel — which has no tabId — uses the sidePanel
+ // logic identity. Folding the presentational flag into the key would hijack tabbed instances.
+ const logicProps: MaxLogicProps = tabId ? { tabId } : { sidePanel: true }
const {
threadVisible,
conversationHistoryVisible,
@@ -87,12 +92,12 @@ export const MaxInstance = React.memo(function MaxInstance({ sidePanel, tabId }:
threadLogicKey,
conversation,
conversationId,
- } = useValues(maxLogic({ tabId }))
- const { startNewConversation, goBack } = useActions(maxLogic({ tabId }))
+ } = useValues(maxLogic(logicProps))
+ const { startNewConversation, goBack } = useActions(maxLogic(logicProps))
const { openSidePanelMax } = useActions(maxGlobalLogic)
const threadProps: MaxThreadLogicProps = {
- tabId,
+ ...logicProps,
conversationId: threadLogicKey,
conversation,
}
@@ -100,7 +105,7 @@ export const MaxInstance = React.memo(function MaxInstance({ sidePanel, tabId }:
const { closeSidePanel } = useActions(sidePanelLogic)
const content = (
- <BindLogic logic={maxLogic} props={{ tabId }}>
+ <BindLogic logic={maxLogic} props={logicProps}>
<BindLogic logic={maxThreadLogic} props={threadProps}>
{conversationHistoryVisible ? (
<ConversationHistory sidePanel={sidePanel} />
diff --git a/frontend/src/scenes/max/components/HandsFreeButton.tsx b/frontend/src/scenes/max/components/HandsFreeButton.tsx
index 6602192e6bf5..43509860b97e 100644
--- a/frontend/src/scenes/max/components/HandsFreeButton.tsx
+++ b/frontend/src/scenes/max/components/HandsFreeButton.tsx
@@ -10,13 +10,14 @@ import { useFeatureFlag } from 'lib/hooks/useFeatureFlag'
import { handsFreeLogic } from '../handsFreeLogic'
interface HandsFreeButtonProps {
- tabId: string
+ tabId?: string
+ sidePanel?: boolean
}
-export function HandsFreeButton({ tabId }: HandsFreeButtonProps): JSX.Element | null {
+export function HandsFreeButton({ tabId, sidePanel }: HandsFreeButtonProps): JSX.Element | null {
const flagEnabled = useFeatureFlag('MAX_HANDS_FREE')
- const { status, canUseHandsFree } = useValues(handsFreeLogic({ tabId }))
- const { toggleHandsFree } = useActions(handsFreeLogic({ tabId }))
+ const { status, canUseHandsFree } = useValues(handsFreeLogic({ tabId, sidePanel }))
+ const { toggleHandsFree } = useActions(handsFreeLogic({ tabId, sidePanel }))
if (!flagEnabled || !canUseHandsFree || status !== 'off') {
return null
diff --git a/frontend/src/scenes/max/components/HandsFreeSurface.tsx b/frontend/src/scenes/max/components/HandsFreeSurface.tsx
index 254c4d66a2bf..6e0dec20bfa3 100644
--- a/frontend/src/scenes/max/components/HandsFreeSurface.tsx
+++ b/frontend/src/scenes/max/components/HandsFreeSurface.tsx
@@ -11,7 +11,8 @@ import { cn } from 'lib/utils/css-classes'
import { HandsFreeStatus, handsFreeLogic } from '../handsFreeLogic'
interface HandsFreeSurfaceProps {
- tabId: string
+ tabId?: string
+ sidePanel?: boolean
}
const STATUS_LABEL: Record<HandsFreeStatus, string> = {
@@ -44,14 +45,16 @@ const STATUS_HINT: Record<HandsFreeStatus, string> = {
function HandsFreeTopline({
tabId,
+ sidePanel,
status,
isReconnecting,
}: {
- tabId: string
+ tabId?: string
+ sidePanel?: boolean
status: HandsFreeStatus
isReconnecting: boolean
}): JSX.Element {
- const { partialTranscript, error } = useValues(handsFreeLogic({ tabId }))
+ const { partialTranscript, error } = useValues(handsFreeLogic({ tabId, sidePanel }))
const hint = isReconnecting ? 'Reconnecting your microphone' : STATUS_HINT[status]
return (
<div className="hands-free-surface__top">
@@ -65,9 +68,9 @@ function HandsFreeTopline({
)
}
-export function HandsFreeSurface({ tabId }: HandsFreeSurfaceProps): JSX.Element | null {
- const { status, connection, error } = useValues(handsFreeLogic({ tabId }))
- const { toggleHandsFree } = useActions(handsFreeLogic({ tabId }))
+export function HandsFreeSurface({ tabId, sidePanel }: HandsFreeSurfaceProps): JSX.Element | null {
+ const { status, connection, error } = useValues(handsFreeLogic({ tabId, sidePanel }))
+ const { toggleHandsFree } = useActions(handsFreeLogic({ tabId, sidePanel }))
// Register the v-then-m exit shortcut while the surface is mounted.
// HandsFreeButton owns the same shortcut for the "enter" path; same-name
@@ -104,7 +107,7 @@ export function HandsFreeSurface({ tabId }: HandsFreeSurfaceProps): JSX.Element
data-status={status}
data-connection={connection}
>
- <HandsFreeTopline tabId={tabId} status={status} isReconnecting={isReconnecting} />
+ <HandsFreeTopline tabId={tabId} sidePanel={sidePanel} status={status} isReconnecting={isReconnecting} />
<button
type="button"
diff --git a/frontend/src/scenes/max/components/QuestionInput.tsx b/frontend/src/scenes/max/components/QuestionInput.tsx
index bb1abdd0020f..89ab5272741f 100644
--- a/frontend/src/scenes/max/components/QuestionInput.tsx
+++ b/frontend/src/scenes/max/components/QuestionInput.tsx
@@ -144,7 +144,7 @@ export const QuestionInput = React.forwardRef<HTMLDivElement, QuestionInputProps
ref
) {
const { dataProcessingAccepted, dataProcessingApprovalDisabledReason } = useValues(maxGlobalLogic)
- const { question, tabId: maxTabId } = useValues(maxLogic)
+ const { question, tabId: maxTabId, sidePanel: maxSidePanel } = useValues(maxLogic)
const { setQuestion } = useActions(maxLogic)
const { user } = useValues(userLogic)
const {
@@ -166,7 +166,7 @@ export const QuestionInput = React.forwardRef<HTMLDivElement, QuestionInputProps
} = useValues(maxThreadLogic)
const { askMax, stopGeneration, completeThreadGeneration, setSupportOverrideEnabled, updateQueuedMessage } =
useActions(maxThreadLogic)
- const { isActive: handsFreeActive } = useValues(handsFreeLogic({ tabId: maxTabId }))
+ const { isActive: handsFreeActive } = useValues(handsFreeLogic({ tabId: maxTabId, sidePanel: maxSidePanel }))
// Only the hands-free row needs bottom-aligned pills — it has the mic + submit pair
// pinned to the bottom and pills sitting in normal flow look misaligned next to them.
// Keep the legacy items-start layout when the flag is off so existing screenshots
@@ -282,7 +282,7 @@ export const QuestionInput = React.forwardRef<HTMLDivElement, QuestionInputProps
)}
>
{handsFreeActive ? (
- <HandsFreeSurface tabId={maxTabId} />
+ <HandsFreeSurface tabId={maxTabId} sidePanel={maxSidePanel} />
) : (
<SlashCommandAutocomplete
visible={showAutocomplete}
@@ -411,7 +411,7 @@ export const QuestionInput = React.forwardRef<HTMLDivElement, QuestionInputProps
isThreadVisible ? 'bottom-[9px] right-[9px]' : 'bottom-[7px] right-[7px]'
)}
>
- <HandsFreeButton tabId={maxTabId} />
+ <HandsFreeButton tabId={maxTabId} sidePanel={maxSidePanel} />
{!handsFreeActive && (
<AIConsentPopoverWrapper
placement="bottom-end"
diff --git a/frontend/src/scenes/max/handsFreeLogic.ts b/frontend/src/scenes/max/handsFreeLogic.ts
index 875ab9a2ea63..484462c3c405 100644
--- a/frontend/src/scenes/max/handsFreeLogic.ts
+++ b/frontend/src/scenes/max/handsFreeLogic.ts
@@ -18,7 +18,8 @@ export type HandsFreeConnection = 'idle' | 'connecting' | 'connected' | 'reconne
const SCRIBE_REALTIME_MODEL_ID = 'scribe_v2_realtime'
export interface HandsFreeLogicProps {
- tabId: string
+ tabId?: string
+ sidePanel?: boolean // set instead of tabId for the floating side panel chat
}
interface ScribeConnection {
@@ -67,11 +68,11 @@ async function loadScribeSdk(): Promise<{
export const handsFreeLogic = kea<handsFreeLogicType>([
props({} as HandsFreeLogicProps),
- key((props) => props.tabId),
+ key((props) => (props.sidePanel ? 'sidepanel' : props.tabId) as string),
path((key) => ['scenes', 'max', 'handsFreeLogic', key]),
- connect(({ tabId }: HandsFreeLogicProps) => ({
- values: [maxLogic({ tabId }), ['threadLogicKey']],
+ connect(({ tabId, sidePanel }: HandsFreeLogicProps) => ({
+ values: [maxLogic({ tabId, sidePanel }), ['threadLogicKey']],
})),
actions({
@@ -389,7 +390,11 @@ export const handsFreeLogic = kea<handsFreeLogicType>([
commitTranscript: ({ text }) => {
const threadKey = values.threadLogicKey
const threadLogic = threadKey
- ? maxThreadLogic.findMounted({ tabId: props.tabId, conversationId: threadKey })
+ ? maxThreadLogic.findMounted({
+ tabId: props.tabId,
+ sidePanel: props.sidePanel,
+ conversationId: threadKey,
+ })
: null
if (!threadLogic) {
actions.setError('Could not find an active conversation to send the message to.')
diff --git a/frontend/src/scenes/max/maxGlobalLogic.tsx b/frontend/src/scenes/max/maxGlobalLogic.tsx
index 102888fb051e..f7554b2ff948 100644
--- a/frontend/src/scenes/max/maxGlobalLogic.tsx
+++ b/frontend/src/scenes/max/maxGlobalLogic.tsx
@@ -190,9 +190,9 @@ export const maxGlobalLogic = kea<maxGlobalLogicType>([
actions.openSidePanel(SidePanelTab.Max)
}
if (conversationId) {
- let logic = maxLogic.findMounted({ tabId: 'sidepanel' })
+ let logic = maxLogic.findMounted({ sidePanel: true })
if (!logic) {
- logic = maxLogic({ tabId: 'sidepanel' })
+ logic = maxLogic({ sidePanel: true })
logic.mount() // we're never unmounting this
}
logic.actions.openConversation(conversationId)
diff --git a/frontend/src/scenes/max/maxLogic.test.ts b/frontend/src/scenes/max/maxLogic.test.ts
index c4edeefda9d1..017b2a0ec66b 100644
--- a/frontend/src/scenes/max/maxLogic.test.ts
+++ b/frontend/src/scenes/max/maxLogic.test.ts
@@ -3,6 +3,7 @@ import { expectLogic, partial } from 'kea-test-utils'
import { FEATURE_FLAGS } from 'lib/constants'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
+import { urls } from 'scenes/urls'
import { sidePanelStateLogic } from '~/layout/navigation-3000/sidepanel/sidePanelStateLogic'
import { useMocks } from '~/mocks/jest'
@@ -43,7 +44,7 @@ describe('maxLogic', () => {
}).toDispatchActions(['openSidePanel'])
// Mount maxLogic after setting up the sidePanelStateLogic state
- logic = maxLogic({ tabId: 'sidepanel' })
+ logic = maxLogic({ sidePanel: true })
logic.mount()
// Check that the question has been set to "Foo"
@@ -60,7 +61,7 @@ describe('maxLogic', () => {
}).toDispatchActions(['openSidePanel'])
// Must create the logic first to spy on its actions
- logic = maxLogic({ tabId: 'sidepanel' })
+ logic = maxLogic({ sidePanel: true })
logic.mount()
// Only mount maxLogic after setting up the router and sidePanelStateLogic
@@ -180,6 +181,29 @@ describe('maxLogic', () => {
expect(logic.values.frontendConversationId).toMatch(uuidRegex)
})
+ // The side panel chat floats over whatever page you're on (e.g. an insight) and must not touch
+ // the route, whereas the scene instance owns /ai. The harness prefixes the project id
+ // (/project/<id>/…), so match the path suffix.
+ it.each([
+ {
+ scenario: 'side panel chat keeps the current page',
+ props: { sidePanel: true },
+ expectedSuffix: '/insights/abc123',
+ },
+ { scenario: 'scene chat navigates to /ai', props: { tabId: 'test' }, expectedSuffix: urls.ai() },
+ ])('startNewConversation: $scenario', async ({ props, expectedSuffix }) => {
+ router.actions.push('/insights/abc123')
+
+ logic = maxLogic(props)
+ logic.mount()
+
+ await expectLogic(logic, () => {
+ logic.actions.startNewConversation()
+ }).toFinishAllListeners()
+
+ expect(router.values.location.pathname.endsWith(expectedSuffix)).toBe(true)
+ })
+
it('uses threadLogicKey correctly with frontendConversationId', async () => {
logic = maxLogic({ tabId: 'test' })
logic.mount()
@@ -217,7 +241,7 @@ describe('maxLogic', () => {
sidePanelStateLogic.actions.openSidePanel(SidePanelTab.Max, 'mode=research:!Question')
}).toDispatchActions(['openSidePanel'])
- logic = maxLogic({ tabId: 'sidepanel' })
+ logic = maxLogic({ sidePanel: true })
logic.mount()
await expectLogic(logic).toMatchValues({
@@ -226,7 +250,7 @@ describe('maxLogic', () => {
})
threadLogic = maxThreadLogic({
- tabId: 'sidepanel',
+ sidePanel: true,
conversationId: logic.values.frontendConversationId,
conversation: null,
})
@@ -243,7 +267,7 @@ describe('maxLogic', () => {
sidePanelStateLogic.actions.openSidePanel(SidePanelTab.Max, 'mode=product_analytics:Question')
}).toDispatchActions(['openSidePanel'])
- logic = maxLogic({ tabId: 'sidepanel' })
+ logic = maxLogic({ sidePanel: true })
logic.mount()
await expectLogic(logic).toMatchValues({
@@ -252,7 +276,7 @@ describe('maxLogic', () => {
})
threadLogic = maxThreadLogic({
- tabId: 'sidepanel',
+ sidePanel: true,
conversationId: logic.values.frontendConversationId,
conversation: null,
})
@@ -269,7 +293,7 @@ describe('maxLogic', () => {
sidePanelStateLogic.actions.openSidePanel(SidePanelTab.Max, 'mode=sql:!Write a query')
}).toDispatchActions(['openSidePanel'])
- logic = maxLogic({ tabId: 'sidepanel' })
+ logic = maxLogic({ sidePanel: true })
logic.mount()
await expectLogic(logic).toMatchValues({
@@ -278,7 +302,7 @@ describe('maxLogic', () => {
})
threadLogic = maxThreadLogic({
- tabId: 'sidepanel',
+ sidePanel: true,
conversationId: logic.values.frontendConversationId,
conversation: null,
})
@@ -291,7 +315,7 @@ describe('maxLogic', () => {
it('parses mode=auto:!Question correctly (null mode)', async () => {
// Mount maxLogic first and reset state to ensure clean slate
- logic = maxLogic({ tabId: 'sidepanel' })
+ logic = maxLogic({ sidePanel: true })
logic.mount()
logic.actions.startNewConversation()
@@ -307,7 +331,7 @@ describe('maxLogic', () => {
})
threadLogic = maxThreadLogic({
- tabId: 'sidepanel',
+ sidePanel: true,
conversationId: logic.values.frontendConversationId,
conversation: null,
})
@@ -320,7 +344,7 @@ describe('maxLogic', () => {
it('parses mode=research correctly (mode only, no question)', async () => {
// Mount maxLogic first and reset state to ensure clean slate
- logic = maxLogic({ tabId: 'sidepanel' })
+ logic = maxLogic({ sidePanel: true })
logic.mount()
logic.actions.startNewConversation()
@@ -336,7 +360,7 @@ describe('maxLogic', () => {
})
threadLogic = maxThreadLogic({
- tabId: 'sidepanel',
+ sidePanel: true,
conversationId: logic.values.frontendConversationId,
conversation: null,
})
@@ -353,7 +377,7 @@ describe('maxLogic', () => {
sidePanelStateLogic.actions.openSidePanel(SidePanelTab.Max, 'mode=invalid_mode:!Question')
}).toDispatchActions(['openSidePanel'])
- logic = maxLogic({ tabId: 'sidepanel' })
+ logic = maxLogic({ sidePanel: true })
logic.mount()
await expectLogic(logic).toMatchValues({
@@ -362,7 +386,7 @@ describe('maxLogic', () => {
})
threadLogic = maxThreadLogic({
- tabId: 'sidepanel',
+ sidePanel: true,
conversationId: logic.values.frontendConversationId,
conversation: null,
})
@@ -375,7 +399,7 @@ describe('maxLogic', () => {
it('parses !My question correctly (backwards compatibility)', async () => {
// Mount maxLogic first and reset state to ensure clean slate
- logic = maxLogic({ tabId: 'sidepanel' })
+ logic = maxLogic({ sidePanel: true })
logic.mount()
logic.actions.startNewConversation()
@@ -391,7 +415,7 @@ describe('maxLogic', () => {
})
threadLogic = maxThreadLogic({
- tabId: 'sidepanel',
+ sidePanel: true,
conversationId: logic.values.frontendConversationId,
conversation: null,
})
diff --git a/frontend/src/scenes/max/maxLogic.tsx b/frontend/src/scenes/max/maxLogic.tsx
index 984c783462e7..87cd98fc3c05 100644
--- a/frontend/src/scenes/max/maxLogic.tsx
+++ b/frontend/src/scenes/max/maxLogic.tsx
@@ -133,11 +133,17 @@ function updateInactiveTab(tabId: string, props: Partial<SceneTab>): void {
}
}
+export interface MaxLogicProps {
+ tabId?: string
+ // Marks the instance that backs the floating side panel chat. It isn't a scene tab:
+ // it stays mounted across navigation and must never own or rewrite the scene route.
+ sidePanel?: boolean
+ onAcceptSessionFilters?: (filters: RecordingUniversalFilters) => void
+}
+
export const maxLogic = kea<maxLogicType>([
- props(
- {} as { tabId?: string | 'sidepanel'; onAcceptSessionFilters?: (filters: RecordingUniversalFilters) => void }
- ),
- key((props) => props.tabId || 'scene'),
+ props({} as MaxLogicProps),
+ key((props) => (props.sidePanel ? 'sidepanel' : props.tabId || 'scene')),
path((key) => ['scenes', 'max', 'maxLogic', key]),
connect(() => ({
@@ -276,6 +282,7 @@ export const maxLogic = kea<maxLogicType>([
selectors({
tabId: [() => [(_, props) => props?.tabId || ''], (tabId) => tabId],
+ sidePanel: [() => [(_, props) => !!props?.sidePanel], (sidePanel) => sidePanel],
onAcceptSessionFilters: [
() => [
(_, props) =>
@@ -368,9 +375,10 @@ export const maxLogic = kea<maxLogicType>([
],
threadLogicProps: [
- (s) => [s.tabId, s.conversation, s.threadLogicKey],
- (tabId, conversation, threadLogicKey) => ({
+ (s) => [s.tabId, s.sidePanel, s.conversation, s.threadLogicKey],
+ (tabId, sidePanel, conversation, threadLogicKey) => ({
tabId,
+ sidePanel,
conversationId: threadLogicKey,
conversation,
}),
@@ -430,7 +438,7 @@ export const maxLogic = kea<maxLogicType>([
// Side panel Max stays mounted across the whole app, so its question reducer
// already survives navigation — and there's no removeTab cleanup for it,
// which would turn the persisted draft into a memory leak.
- if (props.tabId && props.tabId !== 'sidepanel') {
+ if (props.tabId && !props.sidePanel) {
actions.setChatDraftForTab(props.tabId, question)
}
},
@@ -569,7 +577,7 @@ export const maxLogic = kea<maxLogicType>([
startNewConversation: () => {
actions.resetContext()
actions.focusInput()
- if (props.tabId && props.tabId !== 'sidepanel') {
+ if (props.tabId && !props.sidePanel) {
actions.setChatDraftForTab(props.tabId, '')
}
},
@@ -588,7 +596,7 @@ export const maxLogic = kea<maxLogicType>([
afterMount(({ actions, values, props }) => {
// Restore per-tab chat draft (typed but unsent input that should survive scene unmount).
// Side panel Max is excluded — it stays mounted globally, doesn't go through removeTab cleanup.
- if (!values.question && props.tabId && props.tabId !== 'sidepanel') {
+ if (!values.question && props.tabId && !props.sidePanel) {
const draft = values.chatDraftFor(props.tabId)
if (draft) {
actions.setQuestion(draft)
@@ -674,30 +682,38 @@ export const maxLogic = kea<maxLogicType>([
},
})),
- trackedActionToUrl(({ values }) => ({
- toggleConversationHistory: () => {
- if (values.conversationHistoryVisible) {
- return [urls.aiHistory(), {}, router.values.location.hash]
- } else if (values.conversationId) {
- return [urls.ai(values.conversationId), {}, router.values.location.hash]
- }
- return [urls.ai(), {}, router.values.location.hash]
- },
- startNewConversation: () => {
- return [urls.ai(), {}, router.values.location.hash]
- },
- openConversation: ({ conversationId }) => {
- return [urls.ai(conversationId), {}, router.values.location.hash]
- },
- setConversationId: ({ conversationId }) => {
- // Only set the URL parameter if this is a new conversation (using frontendConversationId)
- if (conversationId && conversationId === values.frontendConversationId) {
- return [urls.ai(conversationId), {}, router.values.location.hash, { replace: true }]
- }
- // Return undefined to not update URL for existing conversations
- return undefined
- },
- })),
+ trackedActionToUrl(({ values, props }) => {
+ // The side panel chat floats over whatever page you're on, so it must never rewrite the
+ // scene route — only the scene instance (which owns the /ai route) syncs the URL. Without
+ // this guard, opening Max from e.g. an insight navigates you to /ai#panel=max.
+ if (props.sidePanel) {
+ return {}
+ }
+ return {
+ toggleConversationHistory: () => {
+ if (values.conversationHistoryVisible) {
+ return [urls.aiHistory(), {}, router.values.location.hash]
+ } else if (values.conversationId) {
+ return [urls.ai(values.conversationId), {}, router.values.location.hash]
+ }
+ return [urls.ai(), {}, router.values.location.hash]
+ },
+ startNewConversation: () => {
+ return [urls.ai(), {}, router.values.location.hash]
+ },
+ openConversation: ({ conversationId }) => {
+ return [urls.ai(conversationId), {}, router.values.location.hash]
+ },
+ setConversationId: ({ conversationId }) => {
+ // Only set the URL parameter if this is a new conversation (using frontendConversationId)
+ if (conversationId && conversationId === values.frontendConversationId) {
+ return [urls.ai(conversationId), {}, router.values.location.hash, { replace: true }]
+ }
+ // Return undefined to not update URL for existing conversations
+ return undefined
+ },
+ }
+ }),
])
export function getScrollableContainer(element?: Element | null): HTMLElement | null {
diff --git a/frontend/src/scenes/max/maxThreadLogic.tsx b/frontend/src/scenes/max/maxThreadLogic.tsx
index a4354d44ed9a..5269b9ca87d0 100644
--- a/frontend/src/scenes/max/maxThreadLogic.tsx
+++ b/frontend/src/scenes/max/maxThreadLogic.tsx
@@ -102,17 +102,19 @@ const FAILURE_MESSAGE: FailureMessage & ThreadMessage = {
}
export interface MaxThreadLogicProps {
- tabId: string // used to refer back to MaxLogic
+ tabId?: string // used to refer back to the scene MaxLogic instance
+ sidePanel?: boolean // set instead of tabId for the floating side panel chat
conversationId: string
conversation?: ConversationDetail | null
}
export const maxThreadLogic = kea<maxThreadLogicType>([
key((props) => {
- if (!props.tabId) {
- throw new Error('Max thread logic must have a tabId prop')
+ const owner = props.sidePanel ? 'sidepanel' : props.tabId
+ if (!owner) {
+ throw new Error('Max thread logic must have a tabId or sidePanel prop')
}
- return `${props.conversationId}-${props.tabId}`
+ return `${props.conversationId}-${owner}`
}),
path((key) => ['scenes', 'max', 'maxThreadLogic', key]),
@@ -140,11 +142,11 @@ export const maxThreadLogic = kea<maxThreadLogicType>([
}
}),
- connect(({ tabId }: MaxThreadLogicProps) => ({
+ connect(({ tabId, sidePanel }: MaxThreadLogicProps) => ({
values: [
maxGlobalLogic,
['dataProcessingAccepted', 'toolMap', 'tools', 'availableStaticTools'],
- maxLogic({ tabId }),
+ maxLogic({ tabId, sidePanel }),
[
'question',
'autoRun',
@@ -162,7 +164,7 @@ export const maxThreadLogic = kea<maxThreadLogicType>([
['sceneId'],
],
actions: [
- maxLogic({ tabId }),
+ maxLogic({ tabId, sidePanel }),
[
'askMax',
'setQuestion',
@@ -1006,7 +1008,7 @@ export const maxThreadLogic = kea<maxThreadLogicType>([
// not just when active. Otherwise a typed turn following a spoken one inherits
// the earlier <voice_mode> system instruction from conversation history and
// keeps formatting for speech (no markdown, spelled-out numbers).
- const handsFree = handsFreeLogic.findMounted({ tabId: props.tabId })
+ const handsFree = handsFreeLogic.findMounted({ tabId: props.tabId, sidePanel: props.sidePanel })
const voiceMode = handsFree ? { voice_mode: handsFree.values.isActive } : undefined
const mergedUiContext =
uiContext || voiceMode
@@ -1036,7 +1038,7 @@ export const maxThreadLogic = kea<maxThreadLogicType>([
agentMode: values.agentMode,
})
actions.setQuestion('')
- if (props.tabId === 'sidepanel' && sidePanelStateLogic.isMounted()) {
+ if (props.sidePanel && sidePanelStateLogic.isMounted()) {
sidePanelStateLogic.actions.setSidePanelOptions(null)
}
return
@@ -1087,7 +1089,7 @@ export const maxThreadLogic = kea<maxThreadLogicType>([
// Clear the question
actions.setQuestion('')
// Drop #panel=max:… options so reload doesn't re-run auto-send from the hash
- if (props.tabId === 'sidepanel' && sidePanelStateLogic.isMounted()) {
+ if (props.sidePanel && sidePanelStateLogic.isMounted()) {
sidePanelStateLogic.actions.setSidePanelOptions(null)
}
// For a new conversations, set the frontend conversation ID
@@ -1173,7 +1175,7 @@ export const maxThreadLogic = kea<maxThreadLogicType>([
},
completeThreadGeneration: () => {
- const handsFree = handsFreeLogic.findMounted({ tabId: props.tabId })
+ const handsFree = handsFreeLogic.findMounted({ tabId: props.tabId, sidePanel: props.sidePanel })
if (handsFree?.values.isActive) {
handsFree.actions.speakAssistantResponse(summariseAssistantThread(values.threadRaw))
}
@@ -1764,7 +1766,7 @@ export const maxThreadLogic = kea<maxThreadLogicType>([
// Check for URL-based mode from side panel options (e.g., #panel=max:mode=research:question)
// This must be done in maxThreadLogic's afterMount to ensure the correct instance sets the mode
if (
- props.tabId === 'sidepanel' &&
+ props.sidePanel &&
!values.agentMode &&
sidePanelStateLogic.isMounted() &&
sidePanelStateLogic.values.selectedTab === SidePanelTab.Max &&
diff --git a/frontend/src/scenes/max/useMaxTool.ts b/frontend/src/scenes/max/useMaxTool.ts
index cf5c1ff73e63..eef31dbda2ad 100644
--- a/frontend/src/scenes/max/useMaxTool.ts
+++ b/frontend/src/scenes/max/useMaxTool.ts
@@ -46,7 +46,7 @@ export function useMaxTool({
const { registerTool, deregisterTool } = useActions(maxGlobalLogic)
const { openSidePanel } = useActions(sidePanelLogic)
const { sidePanelOpen, selectedTab } = useValues(sidePanelLogic)
- const { setActiveGroup, startNewConversation } = useActions(maxLogic({ tabId: 'sidepanel' }))
+ const { setActiveGroup, startNewConversation } = useActions(maxLogic({ sidePanel: true }))
const definition = getToolDefinition(identifier)
const isMaxOpen = sidePanelOpen && selectedTab === SidePanelTab.Max