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.8 KB
Raw Blame
import { MakeLogicType, afterMount, kea, key, path, props } from 'kea'
import { loaders } from 'kea-loaders'

import { ApiConfig } from '~/lib/api'

import { llmSkillsNameRetrieve } from 'products/skills/frontend/generated/api'
import type { LLMSkillApi } from 'products/skills/frontend/generated/api.schemas'

export interface SkillPublishPreviewLogicProps {
    skillName: string
    /**
     * Team the skill belongs to. A scout's skill is seeded on the canonical parent team, so the
     * scout page passes that; everything else leaves it unset and reads the current team.
     */
    teamId?: number
}

// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface skillPublishPreviewLogicValues {
    publishPreview: LLMSkillApi | null
    publishPreviewLoading: boolean
}

// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface skillPublishPreviewLogicActions {
    loadPublishPreview: () => any
    loadPublishPreviewFailure: (
        error: string,
        errorObject?: any
    ) => {
        error: string
        errorObject?: any
    }
    loadPublishPreviewSuccess: (
        publishPreview: LLMSkillApi,
        payload?: any
    ) => {
        publishPreview: LLMSkillApi
        payload?: any
    }
}

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

export type skillPublishPreviewLogicType = MakeLogicType<
    skillPublishPreviewLogicValues,
    skillPublishPreviewLogicActions,
    SkillPublishPreviewLogicProps,
    skillPublishPreviewLogicMeta
>

/** What a public share would commit: the skill version the backend would take, and its files.
 * Read from the server rather than from whichever scene opened the dialog, so the consent screen
 * names what the share sends and not what the page happens to be rendering. */
export const skillPublishPreviewLogic = kea<skillPublishPreviewLogicType>([
    path(['scenes', 'skills', 'skillPublishPreviewLogic']),
    props({} as SkillPublishPreviewLogicProps),
    key((props) => `${props.teamId ?? 'current'}:${props.skillName}`),

    loaders(({ props }) => ({
        publishPreview: [
            null as LLMSkillApi | null,
            {
                loadPublishPreview: async () => {
                    // body_length sits at its minimum: the dialog needs the manifest and the
                    // version, never the body.
                    return await llmSkillsNameRetrieve(
                        String(props.teamId ?? ApiConfig.getCurrentTeamId()),
                        props.skillName,
                        { body_length: 1 }
                    )
                },
            },
        ],
    })),

    afterMount(({ actions }) => {
        actions.loadPublishPreview()
    }),
])