import { PostHogAPIConfig, Task, TaskRun, StoredEntry, ArtifactType, TaskRunArtifact } from './types.js';
import '@posthog/git/handoff';

type GatewayProduct = "posthog_code" | "background_agents" | "signals";
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;
    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): Promise<void>;
    uploadTaskArtifacts(taskId: string, runId: string, artifacts: TaskArtifactUploadPayload[]): Promise<TaskRunArtifact[]>;
    /**
     * 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 TaskArtifactUploadPayload, type TaskRunUpdate, getGatewayInvalidatePlanCacheUrl, getGatewayUsageUrl, getLlmGatewayUrl };
