/**
 * CrewAIAdapter -- Orchestrator adapter for the CrewAI framework.
 *
 * Hook surface: CrewAI Enterprise REST + webhook events. The adapter exposes
 * a webhookHandler(event) method that customers wire into their webhook
 * endpoint. Internally the handler maps each event type to the matching
 * BaseOrchestratorAdapter lifecycle method.
 *
 * Supported webhook event types:
 *   start_crew        -> startWorkflow
 *   complete_crew     -> completeWorkflow
 *   before_task       -> preTask
 *   after_task        -> postTask
 *
 * Hierarchical delegation: CrewAI's Process.hierarchical pattern (manager
 * dispatching to worker or reviewer roles) maps onto the DelegationDecision
 * contract via preDelegation.
 *
 * Role mapping: manager / worker / reviewer are canonical CrewAI roles.
 * They map onto AgentIdentity.role. An unregistered role triggers:
 *   - orchestrator:unregistered-role CRITICAL audit event
 *   - RoleNotRegisteredError thrown at the dispatch point
 *
 * DEFERRED-CREWAI-WEBHOOK-SIG: Verify CrewAI Enterprise webhook signature
 * scheme (HMAC header, algorithm, tolerance window) at implementation time.
 * This adapter omits signature verification until the scheme is confirmed.
 * Customers must validate signatures in the outer HTTP handler layer.
 *
 * No live CrewAI SDK installed. All framework surfaces are shims.
 * Tests use fake webhook payloads only.
 *
 * Spec: P3-ORCH-01, Section 2.3, AC 6-7
 * @connexum/ai-governance
 */
import { BaseOrchestratorAdapter } from './base';
import { OrchestratorCapabilities, WorkflowContext, WorkflowDecision, WorkflowStepContext, WorkflowStepDecision, WorkflowResult, RoleEdgeContext, RoleEdgeDecision, OrchestratorError } from './index';
import type { TaskContext, TaskDecision, PlanContext, PlanDecision, DelegationContext, DelegationDecision } from './orchestrator-adapter';
/** The three canonical CrewAI process roles. */
export type CrewAIRole = 'manager' | 'worker' | 'reviewer';
/** Common fields present on every CrewAI webhook event. */
export interface CrewAIWebhookEventBase {
    /** Unique identifier for the crew run */
    crewRunId: string;
    /** Crew name from the customer's CrewAI configuration */
    crewName: string;
    /** ISO-8601 timestamp of the event */
    timestamp: string;
    /** Arbitrary metadata from CrewAI */
    metadata?: Record<string, unknown>;
}
/** Emitted when a crew begins execution. */
export interface CrewAIStartCrewEvent extends CrewAIWebhookEventBase {
    eventType: 'start_crew';
    /** Agent acting as manager for this run */
    managerAgent: string;
    /** Role label for the initiating agent */
    managerRole: CrewAIRole;
    /** Whether the crew runs in hierarchical mode */
    hierarchical: boolean;
}
/** Emitted when a crew run completes (success or failure). */
export interface CrewAICompleteCrewEvent extends CrewAIWebhookEventBase {
    eventType: 'complete_crew';
    success: boolean;
    /** Brief outcome summary (no secrets) */
    summary: string;
    durationMs?: number;
}
/** Emitted before a task is executed by an agent. */
export interface CrewAIBeforeTaskEvent extends CrewAIWebhookEventBase {
    eventType: 'before_task';
    taskId: string;
    taskDescription: string;
    /** The agent assigned to this task */
    agentName: string;
    /** Role of the assigned agent */
    agentRole: CrewAIRole;
    /** Whether this task was delegated from a higher-tier agent */
    isDelegated: boolean;
    /** Delegating agent name when isDelegated is true */
    delegatingAgent?: string;
    /** Delegating agent role when isDelegated is true */
    delegatingRole?: CrewAIRole;
}
/** Emitted after a task is executed. */
export interface CrewAIAfterTaskEvent extends CrewAIWebhookEventBase {
    eventType: 'after_task';
    taskId: string;
    agentName: string;
    agentRole: CrewAIRole;
    success: boolean;
    output?: Record<string, unknown>;
}
/** Union type for all webhook event payloads. */
export type CrewAIWebhookEvent = CrewAIStartCrewEvent | CrewAICompleteCrewEvent | CrewAIBeforeTaskEvent | CrewAIAfterTaskEvent;
export interface CrewAIAdapterConfig {
    /**
     * Crew names permitted to execute under governance.
     * Empty array causes all start_crew events to be denied (fail closed).
     */
    allowedCrewNames: string[];
    /**
     * Tools or permissions that require reviewer approval for delegation.
     * Maps to sensitive operations in the manager->worker delegation path.
     */
    sensitivePermissions: string[];
    /**
     * Maximum steps (tasks) in a governed crew run.
     * Crew runs exceeding this limit are denied at plan time.
     * Undefined means no limit.
     */
    maxTaskSteps?: number;
}
export declare class CrewAIAdapter extends BaseOrchestratorAdapter {
    readonly adapterId = "crewai";
    readonly orchestratorId = "crewai";
    private crewaiConfig;
    /** Track active crew run IDs and their start contexts for completeWorkflow. */
    private activeRuns;
    constructor(config: CrewAIAdapterConfig);
    /**
     * Entry point for CrewAI Enterprise webhook events.
     *
     * Customers wire this method into their webhook HTTP handler:
     *
     *   app.post('/crewai/webhook', async (req, res) => {
     *     await adapter.webhookHandler(req.body as CrewAIWebhookEvent);
     *     res.sendStatus(200);
     *   });
     *
     * The method maps each event type to the corresponding lifecycle hook and
     * throws a typed OrchestratorError on governance denial.
     *
     * DEFERRED-CREWAI-WEBHOOK-SIG: signature verification is deferred.
     * Customers must validate HMAC signatures in the outer HTTP handler.
     */
    webhookHandler(event: CrewAIWebhookEvent): Promise<void>;
    private handleStartCrew;
    private handleCompleteCrew;
    private handleBeforeTask;
    private handleAfterTask;
    /**
     * Assert a CrewAI role is registered with this adapter.
     * Emits orchestrator:unregistered-role CRITICAL and throws
     * RoleNotRegisteredError if not registered.
     */
    private assertRoleRegistered;
    startWorkflow(ctx: WorkflowContext): Promise<WorkflowDecision>;
    stepWorkflow(ctx: WorkflowStepContext): Promise<WorkflowStepDecision>;
    completeWorkflow(ctx: WorkflowContext, result: WorkflowResult): Promise<void>;
    preTask(task: TaskContext): Promise<TaskDecision>;
    postTask(task: TaskContext, result: Record<string, unknown>): Promise<void>;
    prePlan(plan: PlanContext): Promise<PlanDecision>;
    postPlan(plan: PlanContext, result: Record<string, unknown>): Promise<void>;
    preDelegation(d: DelegationContext): Promise<DelegationDecision>;
    postDelegation(d: DelegationContext, result: Record<string, unknown>): Promise<void>;
    invokeRoleEdge(edge: RoleEdgeContext): Promise<RoleEdgeDecision>;
    translateError(raw: unknown): OrchestratorError;
    getOrchestratorCapabilities(): OrchestratorCapabilities;
}
//# sourceMappingURL=crewai.d.ts.map