import type { AgentInvocation, WorkRequest } from '@agent-tower/shared';
import { AgentType } from '../types/index.js';
import { type Provider } from '../executors/index.js';
import { TeamLockService } from './team-lock.service.js';
export interface SchedulePlan {
    workRequestId: string;
    memberId: string;
    canStart: boolean;
    blockedReason?: 'member_busy' | 'member_already_planned' | 'resource_locked' | 'member_not_found' | 'unsupported_workspace_policy';
    requiresStopCurrent: boolean;
    lockKeys: string[];
    workspaceId: string | null;
    projectId: string | null;
}
export interface StopMemberWorkResult {
    stoppedSessionIds: string[];
    cancelledInvocationIds: string[];
    cancelledWorkRequestIds: string[];
    startedInvocations: AgentInvocation[];
}
export interface WorkRequestControlOptions {
    teamRunId?: string;
    requesterMemberId?: string;
}
export interface CancelWorkRequestOptions {
    teamRunId: string;
    requesterMemberId: string;
}
type WorkspaceStarter = {
    create(taskId: string): Promise<{
        id: string;
    }>;
    getOrCreateMainWorkspace?(teamRunId: string): Promise<{
        id: string;
    }>;
    getOrCreateDedicatedWorkspace?(teamRunId: string, memberId: string): Promise<{
        id: string;
    }>;
};
type SessionStarter = {
    create(workspaceId: string, agentType: AgentType, prompt: string, variant?: string, providerId?: string): Promise<{
        id: string;
    }>;
    start(id: string): Promise<unknown>;
    startFollowUp?(id: string, resumeFromSessionId: string): Promise<unknown>;
    stop?(id: string, options?: {
        skipTeamRunReconcile?: boolean;
    }): Promise<unknown>;
};
type TeamRunReviewAdvancer = {
    maybeAdvanceTeamRunToReview(teamRunId: string): Promise<boolean>;
};
interface TeamSchedulerDependencies {
    workspaceService?: WorkspaceStarter;
    sessionManager?: SessionStarter;
    getProviderById?: (providerId: string) => Provider | null;
    teamRunReviewAdvancer?: TeamRunReviewAdvancer;
}
export declare class TeamSchedulerService {
    private readonly lockService;
    private static readonly memberSchedulingLocks;
    private static readonly sharedWorkspaceClaims;
    private readonly workspaceService;
    private readonly sessionManager;
    private readonly providerLookup;
    private readonly teamRunReviewAdvancer;
    constructor(lockService?: TeamLockService, dependencies?: TeamSchedulerDependencies);
    planNext(teamRunId: string): Promise<SchedulePlan[]>;
    startNext(teamRunId: string): Promise<AgentInvocation[]>;
    startNextSessions(teamRunId: string): Promise<AgentInvocation[]>;
    approveWorkRequest(workRequestId: string, options?: WorkRequestControlOptions): Promise<WorkRequest>;
    approveWorkRequestAndStartNext(workRequestId: string, options?: WorkRequestControlOptions): Promise<{
        workRequest: WorkRequest;
        startedInvocations: AgentInvocation[];
    }>;
    rejectWorkRequest(workRequestId: string, options?: WorkRequestControlOptions): Promise<WorkRequest>;
    cancelWorkRequest(workRequestId: string, options: CancelWorkRequestOptions): Promise<WorkRequest>;
    stopMemberWork(teamRunId: string, memberId: string, options?: {
        cancelQueued?: boolean;
    }): Promise<StopMemberWorkResult>;
    releaseInvocationLocks(invocationId: string): void;
    private createInvocationForClaimedWorkRequest;
    private createRunningInvocationForClaimedWorkRequest;
    private createFailedInvocationForClaimedWorkRequest;
    private getSchedulingContext;
    private getWorkRequestOrThrow;
    private getTeamMemberOrThrow;
    private assertMemberCanControlWorkRequest;
    private resolveQueueManagementPolicy;
    private transitionWorkRequestStatus;
    private cancelInvocationsWithoutSession;
    private cancelQueuedWorkRequestsForMember;
    private findActiveMemberIds;
    private hasActiveInvocation;
    private getOrCreateWorkspaceForMember;
    private resolveQueuedInvocationWorkspaceId;
    private getOrCreateSharedWorkspace;
    private findOrCreateSharedWorkspace;
    private getOrCreateDedicatedWorkspace;
    private buildSessionPrompt;
    private findResumeSourceSessionId;
    private markInvocationStartFailed;
    private emitTeamRunInvalidated;
    private emitTeamRunInvalidatedById;
    private markSessionFailed;
    private getRequiredLocks;
    private resolveInvocationWorkspaceId;
    private resolveLockWorkspaceId;
    private memberSchedulingLockKey;
    private acquireMemberSchedulingLock;
    private releaseMemberSchedulingLock;
    private serializeWorkRequest;
    private serializeAgentInvocation;
}
export {};
//# sourceMappingURL=team-scheduler.service.d.ts.map