import { StoredEntry } from './types.js';
import { PostHogAPIConfig, Task, TaskRun, ArtifactType, TaskRunArtifact } from '@posthog/shared';
import '@posthog/shared/domain-types';

type GatewayProduct = "posthog_code" | "background_agents" | "signals" | "slack_app" | "posthog_ai" | "conversations";
declare function getLlmGatewayUrl(posthogHost: string, product?: GatewayProduct): string;
declare function getGatewayUsageUrl(posthogHost: string, product?: GatewayProduct): string;
declare function getGatewayInvalidatePlanCacheUrl(posthogHost: string, product?: GatewayProduct): string;

interface TaskArtifactUploadPayload {
    name: string;
    type: ArtifactType;
    content: string;
    /** Encoding of `content`. With "base64" the backend stores the decoded bytes. */
    content_encoding?: "utf-8" | "base64";
    content_type?: string;
}
interface TaskArtifactPrepareUploadPayload {
    name: string;
    type: ArtifactType;
    size: number;
    content_type?: string;
}
interface PreparedTaskArtifactUpload {
    id: string;
    name: string;
    type: ArtifactType;
    size: number;
    content_type?: string;
    storage_path: string;
    expires_in: number;
    presigned_post: {
        url: string;
        fields: Record<string, string>;
    };
}
interface TaskArtifactFinalizeUploadPayload {
    id: string;
    name: string;
    type: ArtifactType;
    storage_path: string;
    content_type?: string;
}
type TaskRunUpdate = Partial<Pick<TaskRun, "status" | "branch" | "stage" | "error_message" | "output" | "state" | "environment">> & {
    state_remove_keys?: string[];
};
declare class PostHogAPIClient {
    private config;
    constructor(config: PostHogAPIConfig);
    private get baseUrl();
    private isAuthFailure;
    private resolveApiKey;
    private buildHeaders;
    private performRequest;
    private performRequestWithRetry;
    private apiRequest;
    private getTeamId;
    getApiKey(forceRefresh?: boolean): Promise<string>;
    getLlmGatewayUrl(): string;
    getTask(taskId: string): Promise<Task>;
    getTaskRun(taskId: string, runId: string): Promise<TaskRun>;
    resumeRunInCloud(taskId: string, runId: string): Promise<TaskRun>;
    updateTaskRun(taskId: string, runId: string, payload: TaskRunUpdate): Promise<TaskRun>;
    setTaskRunOutput(taskId: string, runId: string, output: Record<string, unknown>): Promise<TaskRun>;
    appendTaskRunLog(taskId: string, runId: string, entries: StoredEntry[]): Promise<TaskRun>;
    relayMessage(taskId: string, runId: string, text: string, textParts?: string[]): Promise<void>;
    uploadTaskArtifacts(taskId: string, runId: string, artifacts: TaskArtifactUploadPayload[]): Promise<TaskRunArtifact[]>;
    /**
     * Reserve S3 keys and presigned POST forms so artifact bytes can be
     * uploaded directly to object storage instead of traveling base64-encoded
     * through the API (which enforces much smaller request body limits).
     */
    prepareTaskArtifactUploads(taskId: string, runId: string, artifacts: TaskArtifactPrepareUploadPayload[]): Promise<PreparedTaskArtifactUpload[]>;
    /** Attach directly-uploaded artifacts (see prepareTaskArtifactUploads) to the run manifest. */
    finalizeTaskArtifactUploads(taskId: string, runId: string, artifacts: TaskArtifactFinalizeUploadPayload[]): Promise<TaskRunArtifact[]>;
    /** Signal reports the given task is associated with (via report task associations). */
    getSignalReportIdsForTask(taskId: string): Promise<string[]>;
    /**
     * Append a log artefact to a signal report, attributed to `taskId` via the
     * `X-PostHog-Task-Id` header (the server validates it against the token's team).
     */
    createSignalReportArtefact(reportId: string, taskId: string, body: {
        artefact_type: string;
        content: Record<string, unknown>;
    }): Promise<void>;
    /**
     * Download artifact content by storage path
     * Streams the file through the PostHog backend so the sandbox does not need
     * direct access to object storage.
     */
    downloadArtifact(taskId: string, runId: string, storagePath: string): Promise<ArrayBuffer | null>;
    /**
     * Fetch logs for a task run via the logs API endpoint
     * @param taskRun - The task run to fetch logs for
     * @returns Array of stored entries, or empty array if no logs available
     */
    fetchTaskRunLogs(taskRun: TaskRun): Promise<StoredEntry[]>;
}

export { PostHogAPIClient, type PreparedTaskArtifactUpload, type TaskArtifactFinalizeUploadPayload, type TaskArtifactPrepareUploadPayload, type TaskArtifactUploadPayload, type TaskRunUpdate, getGatewayInvalidatePlanCacheUrl, getGatewayUsageUrl, getLlmGatewayUrl };
