import { EventEmitter } from 'events';
import { type AgentInputItem } from '@openai/agents';
import type { TraceProcessorService } from '../services/traceProcessorService';
import type { AnalysisOptions, AnalysisResult, IOrchestrator } from '../agent/core/orchestratorTypes';
import type { ArchitectureInfo } from '../agent/detectors/types';
import type { AnalysisNote, AnalysisPlanV3, UncertaintyFlag } from '../agentv3/types';
import type { SessionFieldsForSnapshot, SessionStateSnapshot } from '../agentv3/sessionStateSnapshot';
import { type OpenAIAgentConfig } from './openAiConfig';
interface OpenAISessionEntry {
    history?: AgentInputItem[];
    lastResponseId?: string;
    runState?: string;
    updatedAt: number;
}
declare function isRecoverableOpenAIStreamTermination(error: unknown): boolean;
declare function compactProviderErrorMessage(error: unknown): string;
declare function isMissingOpenAIPreviousResponseError(error: unknown, previousResponseId?: string): boolean;
declare function readCompletedStreamFinalOutput(stream: {
    finalOutput: unknown;
}, state: {
    streamCompleted: boolean;
    completedByPlanIdle: boolean;
    timedOut: boolean;
}): unknown | undefined;
declare function readPlanEligibleStreamFinalOutput(stream: {
    finalOutput: unknown;
}, state: {
    streamCompleted: boolean;
    completedByPlanIdle: boolean;
    timedOut: boolean;
    quickMode: boolean;
    planComplete: boolean;
}): unknown | undefined;
declare function stripOpenAiReasoningArtifacts(text: string, options?: {
    preserveWhitespace?: boolean;
}): string;
interface OpenAiReasoningFilterState {
    insideThink: boolean;
    pendingTagPrefix: string;
}
declare function createOpenAiReasoningFilterState(): OpenAiReasoningFilterState;
declare function filterOpenAiVisibleAnswerDelta(delta: string, state: OpenAiReasoningFilterState): string;
declare function selectOpenAiRecoveryAnswer(input: {
    runAnswer: string;
    accumulatedAnswer: string;
}): string;
declare function sanitizeOpenAiConclusionText(conclusion: string, options?: {
    completedByPlanIdle?: boolean;
    planComplete?: boolean;
    fallbackConclusion?: string;
}): string;
declare function chooseOpenAiConclusionText(input: {
    candidate: string;
    accumulatedAnswer: string;
    completedByPlanIdle?: boolean;
    planComplete?: boolean;
    fallbackConclusion?: string;
}): string;
interface OpenAIRunInputResolution {
    input: string | AgentInputItem[];
    effectivePrompt: string;
    previousResponseId?: string;
    shouldPersistRemoteSession: boolean;
}
declare function resolveOpenAIRunInput(params: {
    quickMode: boolean;
    config: OpenAIAgentConfig;
    sessionEntry?: OpenAISessionEntry;
    effectivePrompt: string;
    previousTurns: any[];
    now?: number;
}): OpenAIRunInputResolution;
export declare const __testing: {
    isMissingOpenAIPreviousResponseError: typeof isMissingOpenAIPreviousResponseError;
    readCompletedStreamFinalOutput: typeof readCompletedStreamFinalOutput;
    readPlanEligibleStreamFinalOutput: typeof readPlanEligibleStreamFinalOutput;
    stripOpenAiReasoningArtifacts: typeof stripOpenAiReasoningArtifacts;
    createOpenAiReasoningFilterState: typeof createOpenAiReasoningFilterState;
    filterOpenAiVisibleAnswerDelta: typeof filterOpenAiVisibleAnswerDelta;
    sanitizeOpenAiConclusionText: typeof sanitizeOpenAiConclusionText;
    chooseOpenAiConclusionText: typeof chooseOpenAiConclusionText;
    selectOpenAiRecoveryAnswer: typeof selectOpenAiRecoveryAnswer;
    resolveOpenAIRunInput: typeof resolveOpenAIRunInput;
    isRecoverableOpenAIStreamTermination: typeof isRecoverableOpenAIStreamTermination;
    compactProviderErrorMessage: typeof compactProviderErrorMessage;
};
export declare class OpenAIRuntime extends EventEmitter implements IOrchestrator {
    private readonly traceProcessorService;
    private readonly architectureCache;
    private readonly vendorCache;
    private readonly completenessCache;
    private readonly artifactStores;
    private readonly sessionNotes;
    private readonly sessionSqlErrors;
    private readonly sessionPlans;
    private readonly sessionHypotheses;
    private readonly sessionUncertaintyFlags;
    private readonly sessionMap;
    private readonly activeAnalyses;
    constructor(traceProcessorService: TraceProcessorService);
    private buildSessionMapKey;
    getSdkSessionId(sessionId: string, referenceTraceId?: string): string | undefined;
    restoreSessionMapping(sessionId: string, sdkSessionId: string): void;
    restoreArchitectureCache(traceId: string, architecture: ArchitectureInfo): void;
    private forgetOpenAILastResponseId;
    private retryWithoutPreviousResponse;
    getCachedArchitecture(traceId: string): ArchitectureInfo | undefined;
    getSessionNotes(sessionId: string): AnalysisNote[];
    getSessionPlan(sessionId: string): AnalysisPlanV3 | null;
    getSessionUncertaintyFlags(sessionId: string): UncertaintyFlag[];
    analyze(query: string, sessionId: string, traceId: string, options?: AnalysisOptions): Promise<AnalysisResult>;
    reset(): void;
    cleanupSession(sessionId: string): void;
    takeSnapshot(sessionId: string, traceId: string, sessionFields: SessionFieldsForSnapshot): SessionStateSnapshot;
    restoreFromSnapshot(sessionId: string, traceId: string, snapshot: SessionStateSnapshot): void;
    private prepareAnalysisContext;
    private detectArchitecture;
    private buildComparisonContext;
    private detectVendor;
    private detectCompleteness;
    /**
     * Decide quickMode for this request. Provider-symmetric to ClaudeRuntime:
     *   explicit fast/full → user wins; auto → keyword/hard rules first, then
     *   OpenAI light-model AI fallback. Stays provider-independent: never calls
     *   the Anthropic SDK, even when the operator hasn't installed it.
     */
    private classifyModeForRequest;
    private getPlanCompletionStatus;
    private shouldFinalizeAfterPlanComplete;
    private shouldRequestFinalReportAfterPlanComplete;
    private buildFinalReportAfterPlanCompletePrompt;
    private formatPlanCompleteReportContinuationMessage;
    private buildCompletedPlanFallbackConclusion;
    private buildPlanPhaseSummaryFallbackConclusion;
    private recoverPartialResultAfterStreamTermination;
    private recordMaxTurnsPartialResult;
    private formatPlanContinuationMessage;
    private formatIncompletePlanMessage;
    private buildPlanContinuationPrompt;
    private withIncompletePlanWarning;
    private shouldExposeOpenAiAnswerDelta;
    private handleStreamEvent;
    private safeSerializeRunState;
    private estimateConfidence;
    private recordTurn;
    private captureEntitiesFromSkillDisplayResults;
    private collectPreviousFindings;
    private buildEntityContext;
    private toProtocolHypothesis;
    private emitUpdate;
}
export declare function createOpenAIRuntime(traceProcessorService: TraceProcessorService): OpenAIRuntime;
export {};
//# sourceMappingURL=openAiRuntime.d.ts.map