import type { AgentRuntimeServiceReport } from "@rudderhq/agent-runtime-utils";
import type { Db } from "@rudderhq/db";
import { workspaceRuntimeServices } from "@rudderhq/db";
import { ExecutionWorkspaceIssueRef, ExecutionWorkspaceAgentRef, RealizedExecutionWorkspace, RuntimeServiceRef, RuntimeServiceRecord } from "./workspace-runtime.helpers.js";
export declare function allocatePort(): Promise<number>;
export declare function buildTemplateData(input: {
    workspace: RealizedExecutionWorkspace;
    agent: ExecutionWorkspaceAgentRef;
    issue: ExecutionWorkspaceIssueRef | null;
    adapterEnv: Record<string, string>;
    port: number | null;
}): {
    workspace: {
        cwd: string;
        branchName: string;
        worktreePath: string;
        repoUrl: string;
        repoRef: string;
        env: Record<string, string>;
    };
    issue: {
        id: string;
        identifier: string;
        title: string;
    };
    agent: {
        id: string;
        name: string;
    };
    port: string | number;
};
export declare function resolveServiceScopeId(input: {
    service: Record<string, unknown>;
    workspace: RealizedExecutionWorkspace;
    executionWorkspaceId?: string | null;
    issue: ExecutionWorkspaceIssueRef | null;
    runId: string;
    agent: ExecutionWorkspaceAgentRef;
}): {
    scopeType: "project_workspace" | "execution_workspace" | "run" | "agent";
    scopeId: string | null;
};
export declare function waitForReadiness(input: {
    service: Record<string, unknown>;
    url: string | null;
}): Promise<void>;
export declare function toPersistedWorkspaceRuntimeService(record: RuntimeServiceRecord): typeof workspaceRuntimeServices.$inferInsert;
export declare function persistRuntimeServiceRecord(db: Db | undefined, record: RuntimeServiceRecord): Promise<void>;
export declare function clearIdleTimer(record: RuntimeServiceRecord): void;
export declare function normalizeAdapterManagedRuntimeServices(input: {
    agentRuntimeType: string;
    runId: string;
    agent: ExecutionWorkspaceAgentRef;
    issue: ExecutionWorkspaceIssueRef | null;
    workspace: RealizedExecutionWorkspace;
    executionWorkspaceId?: string | null;
    reports: AgentRuntimeServiceReport[];
    now?: Date;
}): RuntimeServiceRef[];
export declare function startLocalRuntimeService(input: {
    db?: Db;
    runId: string;
    agent: ExecutionWorkspaceAgentRef;
    issue: ExecutionWorkspaceIssueRef | null;
    workspace: RealizedExecutionWorkspace;
    executionWorkspaceId?: string | null;
    adapterEnv: Record<string, string>;
    service: Record<string, unknown>;
    onLog?: (stream: "stdout" | "stderr", chunk: string) => Promise<void>;
    reuseKey: string | null;
    scopeType: "project_workspace" | "execution_workspace" | "run" | "agent";
    scopeId: string | null;
}): Promise<RuntimeServiceRecord>;
export declare function scheduleIdleStop(record: RuntimeServiceRecord): void;
export declare function stopRuntimeService(serviceId: string): Promise<void>;
export declare function markPersistedRuntimeServicesStoppedForExecutionWorkspace(input: {
    db: Db;
    executionWorkspaceId: string;
}): Promise<void>;
export declare function registerRuntimeService(db: Db | undefined, record: RuntimeServiceRecord): void;
export declare function ensureRuntimeServicesForRun(input: {
    db?: Db;
    runId: string;
    agent: ExecutionWorkspaceAgentRef;
    issue: ExecutionWorkspaceIssueRef | null;
    workspace: RealizedExecutionWorkspace;
    executionWorkspaceId?: string | null;
    config: Record<string, unknown>;
    adapterEnv: Record<string, string>;
    onLog?: (stream: "stdout" | "stderr", chunk: string) => Promise<void>;
}): Promise<RuntimeServiceRef[]>;
export declare function releaseRuntimeServicesForRun(runId: string): Promise<void>;
export declare function stopRuntimeServicesForExecutionWorkspace(input: {
    db?: Db;
    executionWorkspaceId: string;
    workspaceCwd?: string | null;
}): Promise<void>;
export declare function listWorkspaceRuntimeServicesForProjectWorkspaces(db: Db, orgId: string, projectWorkspaceIds: string[]): Promise<Map<string, {
    startedAt: Date;
    createdAt: Date;
    status: string;
    provider: string;
    url: string | null;
    id: string;
    updatedAt: Date;
    command: string | null;
    orgId: string;
    lastUsedAt: Date;
    cwd: string | null;
    issueId: string | null;
    projectId: string | null;
    scopeId: string | null;
    projectWorkspaceId: string | null;
    executionWorkspaceId: string | null;
    scopeType: string;
    serviceName: string;
    lifecycle: string;
    reuseKey: string | null;
    port: number | null;
    providerRef: string | null;
    ownerAgentId: string | null;
    startedByRunId: string | null;
    stoppedAt: Date | null;
    stopPolicy: Record<string, unknown> | null;
    healthStatus: string;
}[]>>;
export declare function reconcilePersistedRuntimeServicesOnStartup(db: Db): Promise<{
    reconciled: number;
}>;
export declare function persistAdapterManagedRuntimeServices(input: {
    db: Db;
    agentRuntimeType: string;
    runId: string;
    agent: ExecutionWorkspaceAgentRef;
    issue: ExecutionWorkspaceIssueRef | null;
    workspace: RealizedExecutionWorkspace;
    executionWorkspaceId?: string | null;
    reports: AgentRuntimeServiceReport[];
}): Promise<RuntimeServiceRef[]>;
//# sourceMappingURL=workspace-runtime.services.d.ts.map