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.

3.1 KB
Raw Blame
import { MakeLogicType, actions, kea, path, reducers, selectors } from 'kea'

/** What a host surface can change about the composer's empty state. */
export interface ComposerOverride {
    placeholder?: string
    subheadline?: string | null
    /** Hide the repository and branch picker when the task never touches a repo. */
    hideRepositorySelector?: boolean
    /** Hide the generic "Try PostHog AI for…" row when the host renders its own suggestions. */
    hideSuggestions?: boolean
    /** Hide the recent-tasks list under the composer. */
    hideRecentTasks?: boolean
    /** Hide the onboarding replay button on a host outside `resolvePhaiOnboardingMounts`, which has no takeover to open. */
    hideOnboardingReplay?: boolean
}

// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface composerOverrideLogicValues {
    composerOverride: ComposerOverride | null
    providers: Record<string, ComposerOverride>
}

// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface composerOverrideLogicActions {
    deregisterComposerOverride: (providerId: string) => {
        providerId: string
    }
    registerComposerOverride: (
        providerId: string,
        override: ComposerOverride
    ) => {
        override: ComposerOverride
        providerId: string
    }
}

// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface composerOverrideLogicMeta {
    __keaTypeGenInternalSelectorTypes: {
        composerOverride: (providers: Record<string, ComposerOverride>) => ComposerOverride | null
    }
}

export type composerOverrideLogicType = MakeLogicType<
    composerOverrideLogicValues,
    composerOverrideLogicActions,
    Record<string, any>,
    composerOverrideLogicMeta
>

/** Registry of composer overrides, the sibling of `welcomeOverrideLogic`. The first registered provider wins. */
export const composerOverrideLogic = kea<composerOverrideLogicType>([
    path(['products', 'posthog_ai', 'frontend', 'logics', 'composerOverrideLogic']),

    actions({
        /** Idempotent upsert: re-registering the same `providerId` updates its override. */
        registerComposerOverride: (providerId: string, override: ComposerOverride) => ({ providerId, override }),
        deregisterComposerOverride: (providerId: string) => ({ providerId }),
    }),

    reducers({
        providers: [
            {} as Record<string, ComposerOverride>,
            {
                registerComposerOverride: (state, { providerId, override }) => ({ ...state, [providerId]: override }),
                deregisterComposerOverride: (state, { providerId }) => {
                    if (!(providerId in state)) {
                        return state
                    }
                    const { [providerId]: _dropped, ...rest } = state
                    return rest
                },
            },
        ],
    }),

    selectors({
        composerOverride: [
            (s) => [s.providers],
            (providers: Record<string, ComposerOverride>): ComposerOverride | null =>
                Object.values(providers)[0] ?? null,
        ],
    }),
])