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(cmdk): open ai side panel prefilled instead of sending on tab (#123338)

Shy Altercae207620c3f
diff --git a/frontend/src/lib/components/CommandKSearch/COMMAND_K_SEARCH_UX.md b/frontend/src/lib/components/CommandKSearch/COMMAND_K_SEARCH_UX.md
index bd94815857d2..fbc9b6908fb0 100644
--- a/frontend/src/lib/components/CommandKSearch/COMMAND_K_SEARCH_UX.md
+++ b/frontend/src/lib/components/CommandKSearch/COMMAND_K_SEARCH_UX.md
@@ -195,6 +195,7 @@ These are the rules reviewers check. Breaking one is a bug.
- **Same key twice** (`is:dashboard is:insight`): the later value replaces the earlier chip. While a value for a key that already has a chip is being typed, results preview the new value instead of the chip.
- **Invalid value** (`is:banana`): keep it as plain text, no chip, and show "No type called banana" in the Suggestions section.
- **Ask PostHog AI**: the last section in Search mode. Without filters, the question is the input text as typed. With filters and free text, the filters read as a sentence around the text (`Find notebooks created by me called "untitled"`). With filters and no free text, the section does not show and Tab does not ask AI.
+ Asking AI does not send the question. It closes the palette and opens the PostHog AI side panel with the question in the composer, so the user can edit it and send it with Enter.
## Out of scope for v1
diff --git a/frontend/src/lib/components/CommandKSearch/commandKSearchLogic.tsx b/frontend/src/lib/components/CommandKSearch/commandKSearchLogic.tsx
index f00d315cd10e..44c344f05f8a 100644
--- a/frontend/src/lib/components/CommandKSearch/commandKSearchLogic.tsx
+++ b/frontend/src/lib/components/CommandKSearch/commandKSearchLogic.tsx
@@ -22,14 +22,18 @@ import { themeLogic } from 'lib/logic/themeLogic'
import posthog from 'lib/posthog-typed'
import { navigateToHref } from 'lib/utils/navigateToHref'
import { newInternalTab } from 'lib/utils/newInternalTab'
+import { MAX_SIDE_PANEL_ID } from 'scenes/max/components/PhaiSidePanelChat'
import { membersLogic } from 'scenes/organization/membersLogic'
import { teamLogic } from 'scenes/teamLogic'
-import { urls } from 'scenes/urls'
import { userLogic } from 'scenes/userLogic'
+import { sidePanelStateLogic } from '~/layout/navigation-3000/sidepanel/sidePanelStateLogic'
import { groupsModel } from '~/models/groupsModel'
import { recentItemsModel } from '~/models/recentItemsModel'
import { FileSystemEntry } from '~/queries/schema/schema-general'
+import { SidePanelTab } from '~/types'
+
+import { runnerPanelLogic } from 'products/posthog_ai/frontend/api/logics'
import type { Noun } from '../../../models/groupsModel'
import type { GroupType, GroupTypeIndex, OrganizationMemberType, UserType } from '../../../types'
@@ -147,11 +151,24 @@ export interface commandKSearchLogicActions {
ensureAllMembersLoaded: () => {
value: true
} // membersLogic
+ clearActiveCreation: () => {
+ value: true
+ } // runnerPanelLogic
+ setHistoryExpanded: (expanded: boolean) => {
+ expanded: boolean
+ } // runnerPanelLogic
+ openSidePanel: (
+ tab: SidePanelTab,
+ options?: string | undefined
+ ) => {
+ options: string | undefined
+ tab: SidePanelTab
+ } // sidePanelStateLogic
loadCurrentTeamSuccess: (
- currentTeam: null | import('../../../types').TeamPublicType,
+ currentTeam: null | import('~/types').TeamPublicType,
payload?: any
) => {
- currentTeam: null | import('../../../types').TeamPublicType
+ currentTeam: null | import('~/types').TeamPublicType
payload?: any
} // teamLogic
activateRow: (
@@ -355,6 +372,8 @@ export type commandKSearchLogicType = MakeLogicType<
commandKSearchLogicMeta
>
+const asLiteralPanelPrompt = (question: string): string => ` ${question}`
+
/**
* Command K search: parses the input into filters and free text, builds the sections, owns the
* highlight, and loads remote results. It mounts with the palette and unmounts when the palette
@@ -399,6 +418,10 @@ export const commandKSearchLogic = kea<commandKSearchLogicType>([
['ensureAllMembersLoaded'],
teamLogic,
['loadCurrentTeamSuccess'],
+ sidePanelStateLogic,
+ ['openSidePanel'],
+ runnerPanelLogic({ panelId: MAX_SIDE_PANEL_ID }),
+ ['clearActiveCreation', 'setHistoryExpanded'],
],
})),
actions({
@@ -781,7 +804,9 @@ export const commandKSearchLogic = kea<commandKSearchLogicType>([
})
actions.closeCommand()
if (row.kind === 'ask-ai') {
- navigateToHref(urls.ai(undefined, row.question))
+ actions.clearActiveCreation()
+ actions.setHistoryExpanded(false)
+ actions.openSidePanel(SidePanelTab.Max, asLiteralPanelPrompt(row.question))
} else if (item?.onSelect) {
item.onSelect()
} else if (item?.href && newTab) {
diff --git a/products/posthog_ai/frontend/components/composer/Composer.tsx b/products/posthog_ai/frontend/components/composer/Composer.tsx
index ad1cfad0e8da..2d1f73125b9d 100644
--- a/products/posthog_ai/frontend/components/composer/Composer.tsx
+++ b/products/posthog_ai/frontend/components/composer/Composer.tsx
@@ -8,6 +8,7 @@ import {
type RefObject,
useCallback,
useContext,
+ useEffect,
useId,
useMemo,
useRef,
@@ -318,6 +319,14 @@ function ComposerTextarea({
...rest
}: ComposerTextareaProps): JSX.Element {
const { value, onChange, submit, textAreaRef, disabled, id } = useComposerContext()
+ const previousValue = useRef('')
+ useEffect(() => {
+ const textArea = textAreaRef.current
+ if (!previousValue.current && value.length > 1 && textArea && document.activeElement === textArea) {
+ textArea.setSelectionRange(value.length, value.length)
+ }
+ previousValue.current = value
+ }, [value, textAreaRef])
return (
<LemonTextArea
id={id}