: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, afterMount, connect, kea, key, listeners, path, props } from 'kea'
import { loaders } from 'kea-loaders'
import posthog from 'posthog-js'
import { ApiConfig } from '~/lib/api'
import { experimentsList } from '../../../experiments/frontend/generated/api'
import type { ExperimentBasicApi } from '../../../experiments/frontend/generated/api.schemas'
import { createPromptExperimentModalLogic } from './createPromptExperimentModalLogic'
export interface PromptExperimentsLogicProps {
promptName: string
}
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface promptExperimentsLogicValues {
experiments: ExperimentBasicApi[]
experimentsLoading: boolean
}
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface promptExperimentsLogicActions {
submitCreateSuccess: (experimentId: number) => {
experimentId: number
} // createPromptExperimentModalLogic
loadExperiments: () => any
loadExperimentsFailure: (
error: string,
errorObject?: any
) => {
error: string
errorObject?: any
}
loadExperimentsSuccess: (
experiments: ExperimentBasicApi[],
payload?: any
) => {
experiments: ExperimentBasicApi[]
payload?: any
}
refresh: () => {
value: true
}
}
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface promptExperimentsLogicMeta {
key: string
}
export type promptExperimentsLogicType = MakeLogicType<
promptExperimentsLogicValues,
promptExperimentsLogicActions,
PromptExperimentsLogicProps,
promptExperimentsLogicMeta
>
export const promptExperimentsLogic = kea<promptExperimentsLogicType>([
path((key) => ['products', 'ai_observability', 'frontend', 'prompts', 'promptExperimentsLogic', key]),
props({} as PromptExperimentsLogicProps),
key((props) => props.promptName),
connect(() => ({
actions: [createPromptExperimentModalLogic, ['submitCreateSuccess']],
})),
actions({
refresh: true,
}),
loaders(({ props }) => ({
experiments: [
[] as ExperimentBasicApi[],
{
loadExperiments: async () => {
const response = await experimentsList(String(ApiConfig.getCurrentTeamId()), {
prompt_name: props.promptName,
order: '-created_at',
})
return response.results
},
},
],
})),
listeners(({ actions }) => ({
refresh: () => actions.loadExperiments(),
submitCreateSuccess: () => actions.loadExperiments(),
})),
afterMount(({ actions, props }) => {
actions.loadExperiments()
posthog.capture('llma prompt experiment tab viewed', { prompt_name: props.promptName })
}),
])