/**
 * CAR Extension Service
 *
 * Main service for coordinating extension execution. Provides a high-level
 * API for processing capability requests, actions, and behavioral verification
 * through the registered extensions.
 *
 * @packageDocumentation
 * @module @vorion/car-extensions/service
 * @license Apache-2.0
 */
import { ExtensionExecutor } from "./executor.js";
import { ExtensionRegistry } from "./registry.js";
import type { CARExtension, AgentIdentity, CapabilityRequest, CapabilityGrant, ActionRequest, ActionResult, RevocationEvent, BehaviorVerificationResult, ExtensionServiceConfig } from "./types.js";
/**
 * Result of processing a capability request
 */
export interface CapabilityRequestResult {
    /** Whether the request was granted */
    granted: boolean;
    /** The capability grant if successful */
    grant?: CapabilityGrant;
    /** Denial reason if not granted */
    denialReason?: string;
    /** Extension that denied the request */
    deniedBy?: string;
    /** Extensions that were evaluated */
    extensionsEvaluated: string[];
}
/**
 * Result of processing an action
 */
export interface ActionProcessingResult {
    /** Whether the action was allowed to proceed */
    proceeded: boolean;
    /** The action result if executed */
    result?: ActionResult;
    /** Blocking reason if not allowed */
    blockingReason?: string;
    /** Extension that blocked the action */
    blockedBy?: string;
    /** Required approvals if any */
    requiredApprovals?: Array<{
        type: "human" | "system" | "manager";
        approver?: string;
        timeout?: number;
    }>;
    /** Extensions that were evaluated */
    extensionsEvaluated: string[];
}
/**
 * CAR Extension Service
 *
 * Provides the main interface for integrating extensions into the
 * Vorion governance system. Coordinates extension loading, execution,
 * and result aggregation.
 *
 * @example
 * ```typescript
 * // Create service
 * const registry = new ExtensionRegistry();
 * const executor = new ExtensionExecutor(registry);
 * const service = new CARExtensionService(registry, executor);
 *
 * // Register extensions
 * await service.registerExtension(cognigateExtension);
 * await service.registerExtension(auditExtension);
 *
 * // Process a capability request
 * const result = await service.processCapabilityRequest(agent, {
 *   domains: ['data', 'compute'],
 *   level: 3,
 *   context: { source: 'api', purpose: 'data-analysis' },
 * });
 *
 * if (result.granted) {
 *   console.log('Capability granted:', result.grant);
 * }
 * ```
 */
export declare class CARExtensionService {
    private registry;
    private executor;
    private config;
    /**
     * Create a new extension service
     *
     * @param registry - Extension registry to use
     * @param executor - Extension executor to use
     * @param config - Optional service configuration
     */
    constructor(registry: ExtensionRegistry, executor: ExtensionExecutor, config?: ExtensionServiceConfig);
    /**
     * Register an extension with the service
     *
     * @param extension - Extension to register
     */
    registerExtension(extension: CARExtension): Promise<void>;
    /**
     * Unregister an extension from the service
     *
     * @param extensionId - ID of extension to unregister
     */
    unregisterExtension(extensionId: string): Promise<void>;
    /**
     * Load extensions for an agent based on their CAR string
     *
     * Parses the CAR string's extension suffix and returns the
     * corresponding registered extensions.
     *
     * @param carId - Agent's CAR string (may include #extension suffixes)
     * @returns Array of loaded extensions
     *
     * @example
     * ```typescript
     * // CAR: a3i.vorion.agent:FHC-L3@1.0.0#gov,audit
     * const extensions = service.loadAgentExtensions(agent.carId);
     * // Returns [cognigateExtension, auditExtension]
     * ```
     */
    loadAgentExtensions(carId: string): CARExtension[];
    /**
     * Get extension IDs for an agent
     *
     * @param carId - Agent's CAR string
     * @returns Array of extension IDs
     */
    getAgentExtensionIds(carId: string): string[];
    /**
     * Process a capability request through all applicable extensions
     *
     * Executes preCheck hooks from all extensions, and if all allow,
     * creates a capability grant and runs postGrant hooks.
     *
     * @param agent - Agent making the request
     * @param request - Capability request
     * @returns Result of processing the request
     */
    processCapabilityRequest(agent: AgentIdentity, request: CapabilityRequest): Promise<CapabilityRequestResult>;
    /**
     * Process an action through all applicable extensions
     *
     * Executes preAction hooks, and if all allow, executes the action
     * and runs postAction hooks. If the action fails, runs onFailure hooks.
     *
     * @param agent - Agent performing the action
     * @param actionRequest - Action to perform
     * @param executeAction - Function to execute the actual action
     * @returns Result of processing the action
     */
    processAction(agent: AgentIdentity, actionRequest: ActionRequest, executeAction?: (request: ActionRequest) => Promise<ActionResult>): Promise<ActionProcessingResult>;
    /**
     * Run behavioral verification for an agent
     *
     * Collects metrics and runs behavior verification hooks from all
     * applicable extensions.
     *
     * @param agent - Agent to verify
     * @returns Behavior verification result
     */
    verifyBehavior(agent: AgentIdentity): Promise<BehaviorVerificationResult>;
    /**
     * Handle a revocation event
     *
     * Propagates the revocation to all registered extensions that have
     * onRevocation handlers.
     *
     * @param revocation - Revocation event to handle
     */
    handleRevocation(revocation: RevocationEvent): Promise<void>;
    /**
     * Evaluate policies for a given context
     *
     * @param agent - Agent to evaluate policies for
     * @param action - Optional action being evaluated
     * @param capability - Optional capability being requested
     * @returns Policy decision
     */
    evaluatePolicy(agent: AgentIdentity, action?: ActionRequest, capability?: CapabilityRequest): Promise<{
        decision: "allow" | "deny" | "require_approval";
        reasons: string[];
    }>;
    /**
     * Create a default capability grant
     */
    private createDefaultGrant;
    /**
     * Apply modifications to an action request
     */
    private applyModifications;
}
/**
 * Create a new CAR Extension Service with default configuration
 *
 * @param config - Optional service configuration
 * @returns Configured extension service
 *
 * @example
 * ```typescript
 * const service = createExtensionService();
 *
 * // Register built-in extensions
 * await service.registerExtension(cognigateExtension);
 * await service.registerExtension(monitoringExtension);
 * await service.registerExtension(auditExtension);
 *
 * // Use the service
 * const result = await service.processCapabilityRequest(agent, request);
 * ```
 */
export declare function createExtensionService(config?: ExtensionServiceConfig): CARExtensionService;
/**
 * Create an extension service with a pre-configured registry
 *
 * @param registry - Pre-configured registry
 * @param config - Optional service configuration
 * @returns Configured extension service
 */
export declare function createExtensionServiceWithRegistry(registry: ExtensionRegistry, config?: ExtensionServiceConfig): CARExtensionService;
//# sourceMappingURL=service.d.ts.map