/**
 * OpenAI/Codex Governance Adapter
 *
 * Maps OpenAI function calling and tool_use formats to the
 * GovernanceAdapter interface. Since OpenAI's API does not provide
 * native pre/post-action hooks, this adapter operates as middleware:
 * callers wrap their function execution with wrapFunctionCall().
 *
 * Supports both legacy function_calling format and the newer tool_use
 * (tools array) format.
 *
 * No OpenAI SDK dependency. This maps governance to their wire format.
 *
 * @connexum/ai-governance
 */
import { BaseGovernanceAdapter, type ActionContext, type ActionDecision, type ActionResult, type AdapterCapabilities, type AdapterConfig, type AgentIdentity } from '../adapters/index';
import { type InjectionDetectorConfig } from '../security/prompt-injection-detector';
/** OpenAI legacy function_calling format. */
export interface OpenAIFunctionCall {
    name: string;
    arguments: string;
}
/** OpenAI tool_use format (tools array response). */
export interface OpenAIToolCall {
    id: string;
    type: 'function';
    function: {
        name: string;
        arguments: string;
    };
}
/** Union of both supported call formats. */
export type OpenAICallFormat = OpenAIFunctionCall | OpenAIToolCall;
/** Result from wrapFunctionCall(). */
export interface WrappedCallResult {
    /** The governance decision that was applied */
    decision: ActionDecision;
    /** The action result, if the call was allowed and executed */
    result?: ActionResult;
    /** The original call object, preserved for chaining */
    originalCall: OpenAICallFormat;
}
/** Block/approval rule: function name pattern with reason. */
export interface FunctionRule {
    /** Exact function name or regex pattern */
    pattern: string | RegExp;
    /** Reason for the rule */
    reason: string;
}
/** Extended config for the OpenAI adapter. */
export interface OpenAIAdapterConfig extends AdapterConfig {
    /** Functions explicitly blocked from execution */
    blockedFunctions?: FunctionRule[];
    /** Functions requiring human approval before execution */
    approvalRequiredFunctions?: FunctionRule[];
    /** Agent identity (name + optional role/sessionId) */
    agentIdentity?: AgentIdentity;
    /**
     * Prompt injection detection for LLM messages passed to wrapFunctionCall.
     * Enabled by default with HIGH severity triggering DENY.
     */
    promptInjection?: {
        enabled?: boolean;
        detectorConfig?: InjectionDetectorConfig;
        denyThreshold?: 'high' | 'medium';
    };
}
export declare class OpenAIAdapter extends BaseGovernanceAdapter {
    private blockedFunctions;
    private approvalRequiredFunctions;
    private agentIdentity;
    private preActionLog;
    private postActionLog;
    private injectionDetector;
    private injectionConfig;
    /**
     * Initialize with OpenAI-specific configuration.
     */
    initialize(config: AdapterConfig): void;
    /**
     * Scan an array of LLM messages for prompt injection BEFORE sending to OpenAI.
     *
     * Call this when you have the full messages array (e.g., before chat completion).
     * Returns an ActionDecision: DENY if injection detected at denyThreshold severity,
     * ALLOW otherwise.
     *
     * Audit event is written to stderr (privacy-safe redacted snippet, no full content).
     */
    scanMessagesForInjection(messages: Array<{
        role: string;
        content: string;
    }>): ActionDecision;
    /**
     * Pre-action governance check.
     * Evaluates blocked and approval-required rules against the tool name.
     */
    preAction(context: ActionContext): ActionDecision;
    /**
     * Post-action audit logging.
     * OpenAI has no native post-action hook, so this relies on the
     * wrapper calling postAction() after execution.
     */
    postAction(context: ActionContext, result: ActionResult): void;
    /**
     * Report adapter capabilities.
     * OpenAI lacks native hooks -- this adapter is a middleware wrapper.
     */
    getCapabilities(): AdapterCapabilities;
    /**
     * Parse an OpenAI function call (legacy format) into ActionContext.
     */
    parseFunctionCall(call: OpenAIFunctionCall): ActionContext;
    /**
     * Parse an OpenAI tool call (tool_use format) into ActionContext.
     */
    parseToolCall(call: OpenAIToolCall): ActionContext;
    /**
     * Parse either format into ActionContext (auto-detects).
     */
    parseCall(call: OpenAICallFormat): ActionContext;
    /**
     * Wrap a function call with governance enforcement.
     *
     * This is the primary integration point. Instead of executing an
     * OpenAI function call directly, callers pass it through this method
     * which applies preAction governance, optionally executes, and runs
     * postAction auditing.
     *
     * @param call - The OpenAI function/tool call object
     * @param executor - Optional function that executes the call.
     *                   Only invoked if governance allows.
     * @returns WrappedCallResult with decision and optional result
     */
    wrapFunctionCall(call: OpenAICallFormat, executor?: (context: ActionContext) => Promise<unknown>): Promise<WrappedCallResult>;
    /**
     * Synchronous version of wrapFunctionCall for non-async executors.
     */
    wrapFunctionCallSync(call: OpenAICallFormat, executor?: (context: ActionContext) => unknown): WrappedCallResult;
    /**
     * Build an OpenAI-format tool response message from an ActionResult.
     */
    buildToolResponse(callId: string, result: ActionResult): {
        role: 'tool';
        tool_call_id: string;
        content: string;
    };
    /**
     * Build a governance-denied response in OpenAI tool response format.
     */
    buildDeniedResponse(callId: string, decision: ActionDecision): {
        role: 'tool';
        tool_call_id: string;
        content: string;
    };
    /** Get the pre-action decision log. */
    getPreActionLog(): Array<{
        context: ActionContext;
        decision: ActionDecision;
    }>;
    /** Get the post-action result log. */
    getPostActionLog(): Array<{
        context: ActionContext;
        result: ActionResult;
    }>;
    private isToolCall;
    private matchesRule;
}
//# sourceMappingURL=openai.d.ts.map