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.

2.3 KB
Raw Blame
import { MakeLogicType, actions, kea, key, path, props, reducers } from 'kea'

import type { AttachedContextItem } from '~/layout/ai/attachedContext'

export interface ComposerSeed {
    prompt: string
    autoSubmit: boolean
    contextItems?: AttachedContextItem[]
    files?: File[]
}

// `panelId` keys the seed to a specific embedded composer (e.g. Max's side panel runner), matching the
// `taskTrackerSceneLogic`/`runnerPanelLogic` keying so the paired instances stay aligned. No `panelId`
// resolves to the same `'scene'` key those logics fall back to.
export interface ComposerSeedLogicProps {
    panelId?: string
}

// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface composerSeedLogicValues {
    seed: ComposerSeed | null
}

// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface composerSeedLogicActions {
    consumeSeed: () => {
        value: true
    }
    setSeed: (seed: ComposerSeed) => {
        seed: ComposerSeed
    }
}

// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface composerSeedLogicMeta {
    key: string
}

export type composerSeedLogicType = MakeLogicType<
    composerSeedLogicValues,
    composerSeedLogicActions,
    ComposerSeedLogicProps,
    composerSeedLogicMeta
>

/**
 * A tiny hand-off store that lets a host seed a not-yet-mounted composer with an initial prompt. A producer
 * (a main-app consumer of this surface) dispatches `setSeed`; the paired `taskTrackerSceneLogic` picks it up
 * either on its own mount (the producer fired first — the common case, a CTA opening the panel) or via the
 * `setSeed` action when the composer is already mounted. Consume-once: the consumer clears it with
 * `consumeSeed` after applying, so reopening the panel later never re-seeds.
 */
export const composerSeedLogic = kea<composerSeedLogicType>([
    path(['products', 'posthog_ai', 'frontend', 'logics', 'composerSeedLogic']),
    props({} as ComposerSeedLogicProps),
    key((props) => props.panelId ?? 'scene'),

    actions({
        setSeed: (seed: ComposerSeed) => ({ seed }),
        consumeSeed: true,
    }),

    reducers({
        seed: [
            null as ComposerSeed | null,
            {
                setSeed: (_, { seed }) => seed,
                consumeSeed: () => null,
            },
        ],
    }),
])