: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
import { MakeLogicType, actions, kea, listeners, path, reducers } from 'kea'
import posthog from 'posthog-js'
import type { ComposerPrefillRequest } from 'products/posthog_ai/frontend/api/runner'
import { DEFAULT_NEW_SESSION_SUGGESTIONS, NewSessionSuggestion } from './newSessionSuggestionDefaults'
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface newSessionSuggestionsLogicValues {
prefillRequest: ComposerPrefillRequest | null
source: string
suggestions: NewSessionSuggestion[]
}
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface newSessionSuggestionsLogicActions {
selectSuggestion: (
suggestion: NewSessionSuggestion,
position: number
) => {
position: number
suggestion: NewSessionSuggestion
}
setSuggestions: (
suggestions: NewSessionSuggestion[],
source: string
) => {
source: string
suggestions: NewSessionSuggestion[]
}
}
export type newSessionSuggestionsLogicType = MakeLogicType<
newSessionSuggestionsLogicValues,
newSessionSuggestionsLogicActions
>
export const newSessionSuggestionsLogic = kea<newSessionSuggestionsLogicType>([
path(['products', 'tasks', 'spaces', 'newSessionSuggestionsLogic']),
actions({
setSuggestions: (suggestions: NewSessionSuggestion[], source: string) => ({ suggestions, source }),
selectSuggestion: (suggestion: NewSessionSuggestion, position: number) => ({ suggestion, position }),
}),
reducers({
suggestions: [
DEFAULT_NEW_SESSION_SUGGESTIONS as NewSessionSuggestion[],
{ setSuggestions: (_, { suggestions }) => suggestions },
],
source: ['default' as string, { setSuggestions: (_, { source }) => source }],
prefillRequest: [
null as ComposerPrefillRequest | null,
{
selectSuggestion: (_, { suggestion }) => ({
prompt: suggestion.prompt,
mode: suggestion.mode,
}),
},
],
}),
listeners(({ values }) => ({
selectSuggestion: ({ suggestion, position }) => {
posthog.capture('today new session suggestion clicked', {
suggestion_id: suggestion.id,
position,
source: values.source,
})
},
})),
])