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.

15.2 KB
Raw Blame
/**
 * Auto-generated Zod validation schemas from the Django backend OpenAPI schema.
 * To modify these schemas, update the Django serializers or views, then run:
 *   hogli build:openapi
 * Questions or issues? #team-devex on Slack
 *
 * PostHog API - generated
 * OpenAPI spec version: 1.0.0
 */
import * as zod from 'zod'

/**
 * Unified endpoint that handles both conversation creation and streaming.
 *
 * - If message is provided: Start new conversation processing
 * - If no message: Stream from existing conversation
 */
export const conversationsCreateBodyContentMax = 40000

export const conversationsCreateBodyIsSandboxDefault = false

export const ConversationsCreateBody = /* @__PURE__ */ zod
    .object({
        content: zod.string().max(conversationsCreateBodyContentMax).nullable(),
        conversation: zod.uuid(),
        contextual_tools: zod.record(zod.string(), zod.unknown()).optional(),
        ui_context: zod.unknown().optional(),
        billing_context: zod.unknown().optional(),
        trace_id: zod.uuid(),
        session_id: zod.string().optional(),
        agent_mode: zod
            .enum([
                'product_analytics',
                'sql',
                'session_replay',
                'error_tracking',
                'plan',
                'execution',
                'survey',
                'research',
                'flags',
                'llm_analytics',
                'sandbox',
                'user_interview',
                'customer_analytics',
            ])
            .optional()
            .describe(
                '\* `product_analytics` - product_analytics\n\* `sql` - sql\n\* `session_replay` - session_replay\n\* `error_tracking` - error_tracking\n\* `plan` - plan\n\* `execution` - execution\n\* `survey` - survey\n\* `research` - research\n\* `flags` - flags\n\* `llm_analytics` - llm_analytics\n\* `sandbox` - sandbox\n\* `user_interview` - user_interview\n\* `customer_analytics` - customer_analytics'
            ),
        is_sandbox: zod.boolean().default(conversationsCreateBodyIsSandboxDefault),
        resume_payload: zod.unknown().optional(),
    })
    .describe('Serializer for appending a message to an existing conversation without triggering AI processing.')

/**
 * Appends a message to an existing conversation without triggering AI processing.
 * This is used for client-side generated messages that need to be persisted
 * (e.g., support ticket confirmation messages).
 */
export const conversationsAppendMessageCreateBodyContentMax = 10000

export const ConversationsAppendMessageCreateBody = /* @__PURE__ */ zod
    .object({
        content: zod.string().max(conversationsAppendMessageCreateBodyContentMax),
    })
    .describe('Serializer for appending a message to an existing conversation without triggering AI processing.')

/**
 * Cancel the conversation's in-progress LangGraph run.
 */
export const ConversationsCancelPartialUpdateBody = /* @__PURE__ */ zod.looseObject({})

/**
 * Create-or-resume a sandbox conversation — the single sandbox session opener. With `content`, processes the turn (first message, in-progress follow-up, or terminal resume); without `content`, warms a sandbox that idles awaiting the first message. Returns the `(task, run)` handle the frontend opens SSE against. The conversation row is created on first use from the URL id.
 */
export const conversationsOpenCreateBodyContentMax = 40000

export const ConversationsOpenCreateBody = /* @__PURE__ */ zod
    .object({
        content: zod
            .string()
            .max(conversationsOpenCreateBodyContentMax)
            .nullish()
            .describe(
                "The user's message text. Omit or null to warm a sandbox (boot + idle) ahead of the first message."
            ),
        trace_id: zod
            .uuid()
            .optional()
            .describe("Client-generated trace id correlated with the resulting Run's SSE stream."),
        attached_context: zod
            .array(
                zod
                    .object({
                        type: zod
                            .enum([
                                'action',
                                'dashboard',
                                'error_tracking_issue',
                                'evaluation',
                                'event',
                                'insight',
                                'instructions',
                                'notebook',
                                'text',
                            ])
                            .describe(
                                '\* `action` - action\n\* `dashboard` - dashboard\n\* `error_tracking_issue` - error_tracking_issue\n\* `evaluation` - evaluation\n\* `event` - event\n\* `insight` - insight\n\* `instructions` - instructions\n\* `notebook` - notebook\n\* `text` - text'
                            )
                            .describe(
                                "Attachment kind. Entity types carry `id` (+ optional `name`); `text` and `instructions` carry `value`. `instructions` is the caller's own guidance and renders into the trusted context block; every other kind renders into the untrusted block, which tells the agent to read it as data.\n\n\* `action` - action\n\* `dashboard` - dashboard\n\* `error_tracking_issue` - error_tracking_issue\n\* `evaluation` - evaluation\n\* `event` - event\n\* `insight` - insight\n\* `instructions` - instructions\n\* `notebook` - notebook\n\* `text` - text"
                            ),
                        id: zod
                            .unknown()
                            .optional()
                            .describe(
                                'Entity identifier — integer for `dashboard`\/`action`, string short_id\/UUID otherwise. Absent for `text`.'
                            ),
                        name: zod
                            .string()
                            .optional()
                            .describe('Optional human-readable label rendered in the context block.'),
                        value: zod
                            .string()
                            .optional()
                            .describe('Free-text content. Only for `text` and `instructions` attachments.'),
                    })
                    .describe(
                        'One typed attachment carried by a sandbox message.\n\nDEPRECATED PATH — do not extend. This structured `attached_context` (and its server-side wrap in\n`context_wrapper.py`) exists only for the legacy Max conversations bridge and is removed with it;\nthe live path wraps context client-side (`products\/posthog_ai\/frontend\/utils\/posthogContextBlock.ts`).'
                    )
            )
            .optional()
            .describe('Typed PostHog entities (and free text) attached to this message.'),
        initial_permission_mode: zod
            .enum(['default', 'acceptEdits', 'plan', 'bypassPermissions', 'auto'])
            .describe(
                '\* `default` - default\n\* `acceptEdits` - acceptEdits\n\* `plan` - plan\n\* `bypassPermissions` - bypassPermissions\n\* `auto` - auto'
            )
            .optional()
            .describe(
                'Initial permission mode for the sandbox agent session. Defaults to `auto`, which allows safe tool use while preserving explicit confirmations.\n\n\* `default` - default\n\* `acceptEdits` - acceptEdits\n\* `plan` - plan\n\* `bypassPermissions` - bypassPermissions\n\* `auto` - auto'
            ),
        task_id: zod
            .uuid()
            .optional()
            .describe(
                "Bind a brand-new sandbox conversation to an existing Task so the first message resumes that Task's run. Honored only when this request creates the conversation row; ignored for an already-existing conversation."
            ),
    })
    .describe(
        'Request body for `POST \/conversations\/{id}\/open\/`. A string `content` processes a turn; a\nnull\/absent `content` warms a sandbox that idles awaiting the first message.'
    )

export const ConversationsQueueCreateBody = /* @__PURE__ */ zod.looseObject({})

export const ConversationsQueuePartialUpdateBody = /* @__PURE__ */ zod.looseObject({})

export const ConversationsQueueClearCreateBody = /* @__PURE__ */ zod.looseObject({})

export const coreMemoryCreateBodyTextMax = 10000

export const CoreMemoryCreateBody = /* @__PURE__ */ zod.object({
    text: zod
        .string()
        .max(coreMemoryCreateBodyTextMax)
        .describe('What Max remembers about the project, as free-form text.'),
    scraping_status: zod
        .union([
            zod
                .enum(['pending', 'completed', 'skipped'])
                .describe('\* `pending` - Pending\n\* `completed` - Completed\n\* `skipped` - Skipped'),
            zod.enum(['']),
            zod.null(),
        ])
        .optional(),
})

export const coreMemoryUpdateBodyTextMax = 10000

export const CoreMemoryUpdateBody = /* @__PURE__ */ zod.object({
    text: zod
        .string()
        .max(coreMemoryUpdateBodyTextMax)
        .describe('What Max remembers about the project, as free-form text.'),
    scraping_status: zod
        .union([
            zod
                .enum(['pending', 'completed', 'skipped'])
                .describe('\* `pending` - Pending\n\* `completed` - Completed\n\* `skipped` - Skipped'),
            zod.enum(['']),
            zod.null(),
        ])
        .optional(),
})

export const coreMemoryPartialUpdateBodyTextMax = 10000

export const CoreMemoryPartialUpdateBody = /* @__PURE__ */ zod.object({
    text: zod
        .string()
        .max(coreMemoryPartialUpdateBodyTextMax)
        .optional()
        .describe('What Max remembers about the project, as free-form text.'),
    scraping_status: zod
        .union([
            zod
                .enum(['pending', 'completed', 'skipped'])
                .describe('\* `pending` - Pending\n\* `completed` - Completed\n\* `skipped` - Skipped'),
            zod.enum(['']),
            zod.null(),
        ])
        .optional(),
})

/**
 * Invoke an MCP tool by name.
 *
 * This endpoint allows MCP callers to invoke Max AI tools directly
 * without going through the full LangChain conversation flow.
 *
 * Scopes are resolved dynamically per tool via dangerously_get_required_scopes.
 */
export const McpToolsCreateBody = /* @__PURE__ */ zod.object({
    args: zod
        .record(zod.string(), zod.unknown())
        .optional()
        .describe("Arguments validated against the selected tool's schema."),
})

/**
 * Run a hybrid (semantic + full-text) RAG search over the PostHog documentation via Inkeep. Returns a markdown body with title, URL, and excerpt for each match for the agent to cite back to the user.
 * @summary Search PostHog documentation
 */
export const DocsSearchBody = /* @__PURE__ */ zod.object({
    query: zod
        .string()
        .describe(
            'Natural-language description of what to find in the PostHog documentation. Inkeep performs hybrid (semantic + full-text) RAG, so phrase the query the way a user would ask the question.'
        ),
})

/**
 * Stream a terminal model response through PostHog AI. Requires organization approval for AI data processing. SDK consumers must use getTerminalAiCreateUrl() with streaming fetch. The generated JSON client buffers the response and cannot parse SSE.
 */
export const terminalAiCreateBodyMessagesMax = 1000

export const terminalAiCreateBodyMaxTokensMax = 8192

export const terminalAiCreateBodyStreamDefault = true
export const terminalAiCreateBodyToolsItemNameMax = 128

export const terminalAiCreateBodyToolsItemDescriptionDefault = ``
export const terminalAiCreateBodyToolsItemDescriptionMax = 20000

export const terminalAiCreateBodyToolsMax = 100

export const terminalAiCreateBodyTemperatureOneMin = 0
export const terminalAiCreateBodyTemperatureOneMax = 1

export const TerminalAiCreateBody = /* @__PURE__ */ zod.object({
    model: zod
        .enum(['claude-opus-5', 'claude-sonnet-5', 'claude-sonnet-4-6', 'claude-haiku-4-5'])
        .describe('Model served by the PostHog provider.'),
    messages: zod
        .array(
            zod.object({
                role: zod.enum(['user', 'assistant']).describe('Author of this conversation message.'),
                content: zod
                    .union([zod.string(), zod.array(zod.record(zod.string(), zod.unknown()))])
                    .describe('Anthropic text, image, or tool content blocks.'),
            })
        )
        .min(1)
        .max(terminalAiCreateBodyMessagesMax)
        .describe('Conversation and tool results.'),
    max_tokens: zod
        .number()
        .min(1)
        .max(terminalAiCreateBodyMaxTokensMax)
        .describe('Maximum output tokens for this generation.'),
    stream: zod.boolean().default(terminalAiCreateBodyStreamDefault).describe('Always stream the model response.'),
    system: zod
        .union([zod.string(), zod.array(zod.record(zod.string(), zod.unknown())), zod.null()])
        .optional()
        .describe('Agent instructions.'),
    tools: zod
        .array(
            zod.object({
                name: zod
                    .string()
                    .max(terminalAiCreateBodyToolsItemNameMax)
                    .describe('Name of a tool executed inside the terminal.'),
                description: zod
                    .string()
                    .max(terminalAiCreateBodyToolsItemDescriptionMax)
                    .default(terminalAiCreateBodyToolsItemDescriptionDefault)
                    .describe('What the tool does.'),
                input_schema: zod.record(zod.string(), zod.unknown()).describe("JSON schema for the tool's arguments."),
                cache_control: zod
                    .union([zod.record(zod.string(), zod.string()), zod.null()])
                    .optional()
                    .describe('Provider prompt cache settings.'),
                eager_input_streaming: zod
                    .union([zod.boolean(), zod.null()])
                    .optional()
                    .describe('Stream tool arguments as they are generated.'),
            })
        )
        .max(terminalAiCreateBodyToolsMax)
        .optional()
        .describe('Tools executed by pi.'),
    temperature: zod
        .union([
            zod.number().min(terminalAiCreateBodyTemperatureOneMin).max(terminalAiCreateBodyTemperatureOneMax),
            zod.null(),
        ])
        .optional()
        .describe('Sampling temperature.'),
})

/**
 * @summary Record what the user did with a PostHog AI turn suggestion card
 */
export const turnSuggestionsResolveCreateBodyTurnIndexMin = 0

export const TurnSuggestionsResolveCreateBody = /* @__PURE__ */ zod.object({
    task_id: zod.uuid().describe('ID of the PostHog AI conversation (task) the suggestion card belongs to.'),
    turn_index: zod
        .number()
        .min(turnSuggestionsResolveCreateBodyTurnIndexMin)
        .describe('Zero-based index of the conversation turn the suggestion card was shown under.'),
    resolution: zod
        .enum(['dismissed', 'accepted'])
        .describe('\* `dismissed` - Dismissed\n\* `accepted` - Accepted')
        .describe(
            'What the user did with the card: `dismissed` mutes suggestions for the rest of the conversation, `accepted` means the offered scout, notebook, alert or subscription was created.\n\n\* `dismissed` - Dismissed\n\* `accepted` - Accepted'
        ),
})