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.

1.9 KB
Raw Blame
import { MakeLogicType, kea, path } from 'kea'
import { loaders } from 'kea-loaders'

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

import { llmPromptsList } from '../generated/api'
import type { LLMPromptListApi } from '../generated/api.schemas'

// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface insertPromptReferenceLogicValues {
    promptOptions: LLMPromptListApi[]
    promptOptionsLoading: boolean
}

// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface insertPromptReferenceLogicActions {
    loadPromptOptions: (search: string) => string
    loadPromptOptionsFailure: (
        error: string,
        errorObject?: any
    ) => {
        error: string
        errorObject?: any
    }
    loadPromptOptionsSuccess: (
        promptOptions: LLMPromptListApi[],
        payload?: string
    ) => {
        promptOptions: LLMPromptListApi[]
        payload?: string
    }
}

export type insertPromptReferenceLogicType = MakeLogicType<
    insertPromptReferenceLogicValues,
    insertPromptReferenceLogicActions
>

export const insertPromptReferenceLogic = kea<insertPromptReferenceLogicType>([
    path(['scenes', 'ai-observability', 'insertPromptReferenceLogic']),
    loaders({
        promptOptions: [
            [] as LLMPromptListApi[],
            {
                loadPromptOptions: async (search: string, breakpoint) => {
                    if (search) {
                        await breakpoint(250)
                    }
                    const response = await llmPromptsList(String(ApiConfig.getCurrentTeamId()), {
                        content: 'none',
                        order_by: 'name',
                        limit: 100,
                        ...(search ? { search } : {}),
                    })
                    breakpoint()
                    return response.results
                },
            },
        ],
    }),
])