/**
 * HaystackAdapter -- Orchestrator adapter for Haystack Agents (deepset).
 *
 * Hook surface: Haystack from deepset is a Pipeline-based framework where agents
 * are Nodes connected by Edges. Our adapter hooks at the Pipeline execution
 * boundary. Customers wire the adapter:
 *
 *   const adapter = new HaystackAdapter(cfg);
 *   adapter.initialize(orchCfg);
 *
 *   // At pipeline start:
 *   await adapter.pipelineStart(pipelineId, pipelineName, contextSnapshot);
 *
 *   // Before each node execution:
 *   await adapter.nodeStart(pipelineId, nodeId, nodeType, inputs);
 *
 *   // After each node execution:
 *   await adapter.nodeEnd(pipelineId, nodeId, nodeType, outputs);
 *
 *   // Before a PromptNode LLM invocation (per-backend):
 *   await adapter.promptNodeCall(pipelineId, nodeId, backendId, model, prompt);
 *
 *   // After a PromptNode result:
 *   await adapter.promptNodeResult(pipelineId, nodeId, backendId, result);
 *
 *   // When running in eval mode:
 *   await adapter.evalStep(pipelineId, evalSetId, metricName, result);
 *
 *   // At pipeline end:
 *   await adapter.pipelineEnd(pipelineId, outcome);
 *
 * Haystack-specific considerations:
 *   - Pipeline-based execution: our adapter hooks at the Pipeline execution boundary.
 *   - Evaluation is a first-class concept; governance events capture eval-stage
 *     metadata (which eval set, which metric) when agents run in eval mode.
 *     Eval-mode events write to a SEPARATE eval audit path, not the production chain.
 *   - Document retrieval via Haystack's Retriever node has the same ingress PHI
 *     classification story as LlamaIndex.
 *   - PromptNode can route to multiple LLM backends per pipeline run. Each backend
 *     invocation is surfaced as a distinct canonical event so provider-compliance
 *     checks fire per-backend.
 *   - European deployment default: GDPR pack is bound unless explicitly disabled.
 *     EU-specific data classes (right to erasure, DPIA records) surface in audit events.
 *
 * Regulatory positioning: HIPAA + GDPR dual-regulated buyer. German maintainer.
 * Natural fit for healthcare-fintech cross-border deployments.
 *
 * No live Haystack Python SDK installed. All framework surfaces are shims.
 * DEFERRED-HAYSTACK-V1-API: Verify exact hook surface when Haystack v2 stabilises
 * its TypeScript event-bus API (beta as of 2026-04-23).
 *
 * Pentest gate:
 *   PT-ADAPT-HAYSTACK-1: multi-backend pipeline with one non-BAA provider blocks
 *     the full pipeline when HIPAA binding is active.
 *   PT-ADAPT-HAYSTACK-2: GDPR right-to-erasure request surfaces on the audit chain.
 *   PT-ADAPT-HAYSTACK-3: eval-mode agent writes to the eval audit path, not the
 *     production chain.
 *
 * Spec: P3-SUB-ADAPT-05
 * @connexum/ai-governance
 */
import { BaseOrchestratorAdapter } from './base';
import { OrchestratorCapabilities, WorkflowContext, WorkflowDecision, WorkflowStepContext, WorkflowStepDecision, WorkflowResult, RoleEdgeContext, RoleEdgeDecision, OrchestratorError } from './index';
import { HaystackUnboundDataError } from '../errors/index';
import type { TaskContext, TaskDecision, PlanContext, PlanDecision, DelegationContext, DelegationDecision } from './orchestrator-adapter';
/**
 * Thrown when a Haystack pipeline acts without a pack binding.
 * Re-exports canonical UnboundDataError as HaystackUnboundDataError so
 * a single `instanceof UnboundDataError` at the server boundary matches
 * all adapter origins. (C2 fix, 2026-04-24)
 */
export { HaystackUnboundDataError };
/**
 * Thrown when a multi-backend pipeline includes a provider that has no BAA
 * agreement, under an active HIPAA binding.
 */
export declare class HaystackNonBaaProviderError extends Error {
    readonly pipelineId: string;
    readonly backendId: string;
    constructor(pipelineId: string, backendId: string);
}
/**
 * Emitted when a GDPR right-to-erasure (Article 17) request surfaces on the
 * audit chain during a pipeline run. This is not a blocking error but an
 * audit-priority event requiring compliance officer action.
 */
export declare class HaystackGdprErasureRequestEvent extends Error {
    readonly pipelineId: string;
    readonly subjectId: string;
    constructor(pipelineId: string, subjectId: string);
}
/**
 * Backend provider IDs with documented HIPAA BAA coverage.
 * A backend NOT in this set triggers HaystackNonBaaProviderError under HIPAA.
 *
 * DEFERRED-HAYSTACK-V1-API: Vera / Legal must verify BAA status per provider
 * before any production HIPAA deployment. This list is a known-good starting point.
 */
export declare const HAYSTACK_BAA_BACKENDS: ReadonlySet<string>;
/**
 * EU data classes relevant to Haystack GDPR deployments.
 * These surface as structured fields in canonical audit events.
 */
export type HaystackEuDataClass = 'PersonalData' | 'SpecialCategoryData' | 'CriminalData' | 'ChildData' | 'DpiaRecord' | 'ErasureRequest' | 'PortabilityRequest' | 'NONE';
/** Haystack node types (subset of v2 node taxonomy). */
export type HaystackNodeType = 'Retriever' | 'PromptNode' | 'PreProcessor' | 'DocumentStore' | 'FileConverter' | 'Summarizer' | 'QueryClassifier' | 'AgentNode' | 'EvalNode' | 'UNKNOWN';
/** Context snapshot at pipeline start. */
export interface HaystackContextSnapshot {
    /** ISO-8601 timestamp at pipeline start */
    startedAt: string;
    /** Pack binding array -- MUST be non-empty for the pipeline to proceed */
    packBinding: string[];
    /**
     * Whether this pipeline runs in eval mode.
     * When true, events write to the eval audit path, not the production chain.
     */
    isEvalMode: boolean;
    /**
     * LLM backend IDs this pipeline will use (all must be checked for BAA under HIPAA).
     * Example: ['azure-openai', 'bedrock']
     */
    backendIds: string[];
    /**
     * Whether GDPR defaults are active.
     * Default: true (European deployment assumption per Haystack positioning).
     */
    gdprActive?: boolean;
    /** Arbitrary pipeline metadata */
    metadata?: Record<string, unknown>;
}
/** Input/output payload of a Haystack node execution. */
export interface HaystackNodePayload {
    /** Documents in the payload (if any) */
    documents?: Array<{
        id?: string;
        content?: string;
        meta?: Record<string, unknown>;
    }>;
    /** Query string (if any) */
    query?: string;
    /** Prompt text (if any -- for PromptNode) */
    prompt?: string;
    /** Result text (if any) */
    result?: string;
    /** Arbitrary payload fields */
    [key: string]: unknown;
}
/** A single PromptNode backend invocation. */
export interface HaystackPromptNodeCall {
    /** Prompt sent to the backend */
    prompt: string;
    /** Model identifier */
    model: string;
    /** Arbitrary call parameters */
    params?: Record<string, unknown>;
}
/** Result of a PromptNode backend call. */
export interface HaystackPromptNodeResult {
    /** Generated text */
    result: string;
    /** Token usage (if available) */
    usage?: {
        promptTokens?: number;
        completionTokens?: number;
    };
    /** Duration in milliseconds */
    durationMs?: number;
}
/** Evaluation step metadata. */
export interface HaystackEvalStepResult {
    /** Metric value (e.g. 0.87 for F1) */
    metricValue: number;
    /** Whether this metric meets the pass threshold */
    passed: boolean;
    /** Per-sample results if available */
    sampleResults?: Array<{
        id: string;
        passed: boolean;
        score?: number;
    }>;
}
/** Terminal outcome at pipeline end. */
export interface HaystackPipelineOutcome {
    success: boolean;
    summary?: string;
    durationMs?: number;
    error?: string;
    totalNodesExecuted?: number;
    totalBackendCalls?: number;
}
export interface HaystackAdapterConfig {
    /**
     * Pipeline ID prefixes registered under governance.
     * Empty array denies all pipelines (fail closed).
     */
    registeredPipelines: string[];
    /**
     * LLM backend IDs approved for use (must all have BAA if HIPAA active).
     * Example: ['azure-openai', 'bedrock', 'vertex-ai']
     */
    approvedBackends: string[];
    /**
     * Node names that require reviewer approval before execution.
     */
    sensitiveNodes: string[];
    /**
     * When true (default), all backends in a pipeline must be BAA-covered
     * when HIPAA binding is active. One non-BAA backend blocks the entire pipeline.
     */
    enforceAllBackendsBaa?: boolean;
    /**
     * When true (default), GDPR pack defaults are applied even without an
     * explicit GDPR pack binding (European deployment assumption).
     */
    gdprDefaultActive?: boolean;
    /**
     * When true (default), a GDPR Art. 17 erasure request encountered during
     * a pipeline run pauses the pipeline and surfaces to the compliance queue.
     */
    pauseOnErasureRequest?: boolean;
    /**
     * When true (default), enforce pack-binding at every hook surface.
     */
    enforcePackBinding?: boolean;
    /**
     * Maximum node executions per pipeline run before automatic suspension.
     */
    maxNodesPerPipeline?: number;
}
export declare class HaystackAdapter extends BaseOrchestratorAdapter {
    readonly adapterId = "haystack";
    readonly orchestratorId = "haystack";
    private haystackConfig;
    /** Active pipelines: pipelineId -> contextSnapshot */
    private activePipelines;
    /** Per-pipeline node execution counters */
    private nodeCounters;
    /** Per-pipeline backend call counters */
    private backendCallCounters;
    /**
     * Separate eval audit buffer for eval-mode pipelines.
     * Eval events go here, not to the production canonicalEvents buffer.
     * This satisfies PT-ADAPT-HAYSTACK-3.
     */
    private evalAuditEvents;
    constructor(config: HaystackAdapterConfig);
    /**
     * Called when a Haystack pipeline starts.
     *   1. Pipeline registration check
     *   2. Pack-binding resolver
     *   3. Multi-backend BAA check (all backends must be BAA-covered under HIPAA)
     *   4. GDPR default application
     *   5. Eval-mode routing (eval events -> eval audit path)
     *
     * Throws HaystackUnboundDataError or HaystackNonBaaProviderError if denied.
     */
    pipelineStart(pipelineId: string, pipelineName: string, contextSnapshot: HaystackContextSnapshot): Promise<WorkflowDecision>;
    /**
     * Called before each Haystack node executes.
     *   1. Active-pipeline check
     *   2. Node counter (runaway detection)
     *   3. Sensitive-node REQUIRE_APPROVAL routing
     *   4. Retriever node: PHI classification on inputs
     */
    nodeStart(pipelineId: string, nodeId: string, nodeType: HaystackNodeType, inputs: HaystackNodePayload): Promise<TaskDecision>;
    nodeEnd(pipelineId: string, nodeId: string, nodeType: HaystackNodeType, outputs: HaystackNodePayload): Promise<void>;
    /**
     * Called before each PromptNode backend invocation.
     * Each backend invocation is a DISTINCT canonical event for per-backend
     * provider-compliance checks.
     *
     * Under a HIPAA binding, non-BAA backends block immediately.
     */
    promptNodeCall(pipelineId: string, nodeId: string, backendId: string, model: string, call: HaystackPromptNodeCall): Promise<TaskDecision>;
    promptNodeResult(pipelineId: string, nodeId: string, backendId: string, result: HaystackPromptNodeResult): Promise<void>;
    /**
     * Called when a Haystack eval-mode agent executes an evaluation step.
     * Eval events write to the SEPARATE eval audit path, not the production chain.
     * This ensures eval runs do not contaminate the production compliance audit trail.
     *
     * Returns the eval step metadata for test harness inspection.
     */
    evalStep(pipelineId: string, evalSetId: string, metricName: string, result: HaystackEvalStepResult): Promise<{
        auditId: string;
        writtenToEvalPath: boolean;
    }>;
    /**
     * Get the eval audit events buffer (for testing and compliance officer review).
     * These are separate from production canonical events.
     */
    getEvalAuditEvents(): Array<{
        pipelineId: string;
        event: unknown;
    }>;
    /**
     * Called when a pipeline encounters a GDPR Art. 17 right-to-erasure request.
     * Surfaces the request on the audit chain and optionally pauses the pipeline.
     *
     * This is one of the EU-specific data classes surfaced in audit events per
     * the Haystack European deployment assumption.
     *
     * Throws HaystackGdprErasureRequestEvent when pauseOnErasureRequest=true.
     */
    gdprErasureRequest(pipelineId: string, subjectId: string, requestMetadata?: Record<string, unknown>): Promise<{
        auditId: string;
        paused: boolean;
    }>;
    pipelineEnd(pipelineId: string, outcome: HaystackPipelineOutcome): Promise<void>;
    /** Emit to eval path if in eval mode, otherwise to production canonical events. */
    private emitOrEval;
    private hasHipaaBinding;
    private extractTextFromPayload;
    private containsPhiPattern;
    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=haystack.d.ts.map