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.7 KB
Raw Blame
import {
    EventPropertyFilter,
    FilterLogicalOperator,
    GroupPropertyFilter,
    PersonPropertyFilter,
    RecordingDurationFilter,
    RecordingPropertyFilter,
    SessionPropertyFilter,
} from '~/types'

import { AssistantPropertyFilter } from './schema-assistant-queries'
import { RecordingsQuery } from './schema-general'

// Subset of RecordingUniversalFilters that is more tractable for the AI assistant
export interface MaxRecordingUniversalFilters {
    date_from?: string | null
    date_to?: string | null
    duration: RecordingDurationFilter[]
    filter_test_accounts?: boolean
    filter_group: MaxOuterUniversalFiltersGroup
    order?: RecordingsQuery['order']
    order_direction?: RecordingsQuery['order_direction']
    /** How many recordings the user requested to use. Skip if user did not indicate preference. */
    limit?: RecordingsQuery['limit']
    /** Pin the result to specific recordings by their session id, e.g. the ones just summarized. `$session_id` is not a session property, so it cannot be filtered on in `filter_group`. */
    session_ids?: RecordingsQuery['session_ids']
}

export type MaxOuterUniversalFiltersGroup = {
    type: FilterLogicalOperator
    values: MaxInnerUniversalFiltersGroup[]
}

export type MaxInnerUniversalFiltersGroup = {
    type: FilterLogicalOperator
    /**
     * Filter conditions for session recordings. Possible filter types:
     * - 'event' type: Filter by properties of events in the session (e.g. `$current_url` equals X).
     * - 'person' type: Filter by person properties (e.g. `email` contains Y).
     * - 'session' type: Filter by session-level properties (e.g. `$session_duration`).
     * - 'recording' type: Filter by recording metadata (e.g. `console_log_level`, `visited_page`).
     * - 'group' type: Filter by group properties (e.g. company `plan` is "enterprise").
     * - 'events' type: Filter by whether a specific event occurred (e.g. `$pageview` was present).
     */
    values: MaxUniversalFilterValue[]
}

// ActionFilter narrowed down to just an event with optional property filtering (because ActionFilter is a _mess_)
export interface MaxRecordingEventFilter {
    type: 'events'
    /** Name of the event. */
    id: string
    /** Optional display name for this event. */
    name?: string
    /** Optional property filters for this event only. */
    properties?: AssistantPropertyFilter[]
    /** Set to true to match sessions that did NOT contain this event. Only set it when the tool description says excluding sessions by event is supported. */
    negation?: boolean
}

export type MaxUniversalFilterValue =
    | EventPropertyFilter
    | PersonPropertyFilter
    | SessionPropertyFilter
    | RecordingPropertyFilter
    | GroupPropertyFilter
    | MaxRecordingEventFilter