import type { AuthEnvelope } from "../agent_modelAdapter/authProfileLayer/authEnvelope.js";
import type { OpenAIV1ResponsesProviderCaller } from "../agent_modelAdapter/actualInvocationLayer/openai/v1_responses.js";
import type { OpenAiV1ChatCompletionsProviderCaller } from "../agent_modelAdapter/actualInvocationLayer/openai/v1_chat_completions.js";
import type { AnthropicV1MessagesProviderCaller } from "../agent_modelAdapter/actualInvocationLayer/anthropic/v1_messages.js";
import type { BaseToolExecutorPort } from "../agent_executionEngine/basic_toolLayer/baseTools/baseToolExecutorPort.js";
import { type MainLoopStepRecord } from "../agent_executionEngine/coreLogic/mainLoop.js";
import { type PromptPackSegmentKind } from "../agent_executionEngine/promptPack/promptDefiner.js";
import { type RuntimeBaseToolExecutorPolicy, type RuntimeBaseToolExecutorResourceLimits } from "./runtime.execEngine/baseToolExecutorPortFactory.js";
import { type BaseToolDependencyRuntimeMode } from "./runtime.execEngine/baseToolDependencyRuntime.js";
import { type BaseToolContextSelection, type BaseToolContextUsageRecord } from "./runtime.execEngine/baseToolContextFolding.js";
import { type AgentManifest, type PraxisAgent, type PraxisAgentInput } from "./runtimeAgentManifest.js";
import type { ToolDependencyProbe } from "../agent_executionEngine/basic_toolLayer/toolDependency/dependencyManager.js";
import { type RuntimeApprovalRecord, type RuntimeSessionSnapshot, type RuntimeSessionStateEventStore } from "./runtimeSessionStateEventStore.js";
import { type RaxStorageInitMode } from "./runtime.storagePlane/storagePlaneRuntime.js";
export type PraxisRuntimeKernelErrorCode = "MANIFEST_COMPILE_FAILED" | "TEXT_INPUT_REJECTED" | "PROMPT_PACK_FAILED" | "MODEL_INVOCATION_FAILED" | "MODEL_DECISION_FAILED" | "TOOL_INVOCATION_FAILED" | "PROCEDURE_INVOCATION_FAILED" | "APPROVAL_REQUIRED" | "SANDBOX_UNAVAILABLE" | "STORAGE_RESOLUTION_FAILED" | "TEXT_OUTPUT_REJECTED";
export type PraxisRuntimeKernelError = {
    code: PraxisRuntimeKernelErrorCode;
    message: string;
    boundary: "compile" | "io" | "model" | "tool" | "runtime-state";
    publicSafe: true;
};
export type PraxisRuntimeKernelOptions = {
    runtimeId?: string;
    sessionId?: string;
    auth?: AuthEnvelope;
    providerCaller?: OpenAIV1ResponsesProviderCaller;
    openaiResponsesCaller?: OpenAIV1ResponsesProviderCaller;
    openaiChatCompletionsCaller?: OpenAiV1ChatCompletionsProviderCaller;
    anthropicMessagesCaller?: AnthropicV1MessagesProviderCaller;
    allowPreviousResponseId?: boolean;
    previousProviderResponse?: {
        responseId: string;
        stablePrefixHash: string;
    };
    executor?: BaseToolExecutorPort;
    baseToolAdapters?: Partial<BaseToolExecutorPort>;
    baseToolPolicy?: RuntimeBaseToolExecutorPolicy;
    baseToolResourceLimits?: RuntimeBaseToolExecutorResourceLimits;
    store?: RuntimeSessionStateEventStore;
    allowProviderCall?: boolean;
    allowToolExecution?: boolean;
    exposeProviderTools?: boolean;
    toolContextSelection?: BaseToolContextSelection;
    toolContextUsage?: readonly BaseToolContextUsageRecord[];
    dryRun?: boolean;
    approvalResolver?: RuntimeApprovalResolver;
    baseToolDependencyRuntime?: {
        mode?: BaseToolDependencyRuntimeMode;
        probes?: readonly ToolDependencyProbe[];
        managedRoot?: string;
        env?: Readonly<Record<string, string | undefined>>;
        homeDir?: string;
        timeoutMs?: number;
    };
    storage?: {
        cwd?: string;
        raxHome?: string;
        workspaceRoot?: string;
        homeDir?: string;
        env?: Readonly<Record<string, string | undefined>>;
        initMode?: RaxStorageInitMode;
    };
    sandbox?: {
        cwd?: string;
        runSmoke?: boolean;
        failOnUnavailable?: boolean;
    };
    onTextDelta?: (delta: string, metadata?: Readonly<Record<string, unknown>>) => void | Promise<void>;
    onModelCallProgress?: (event: AgentModelCallProgressEvent) => void | Promise<void>;
    onToolCallProgress?: (event: AgentToolCallProgressEvent) => void | Promise<void>;
    now?: () => string;
};
export type RuntimeApprovalEnvelope = {
    approvalId: string;
    runtimeId: string;
    sessionId: string;
    source: RuntimeApprovalRecord["source"];
    reason: string;
    requestedScopes: readonly string[];
    riskLevel?: string;
    interfaceSurface: RuntimeApprovalRecord["interfaceSurface"];
    metadata: Readonly<Record<string, unknown>>;
    publicSafe: true;
};
export type RuntimeApprovalResolution = {
    status: "approved" | "denied" | "pending";
    resolvedBy?: string;
    reason?: string;
    metadata?: Readonly<Record<string, unknown>>;
};
export type RuntimeApprovalResolver = (envelope: RuntimeApprovalEnvelope) => RuntimeApprovalResolution | Promise<RuntimeApprovalResolution>;
export type AgentToolCallRecord = {
    callId: string;
    toolId: string;
    arguments: Readonly<Record<string, unknown>>;
    ok: boolean;
    output?: unknown;
    error?: unknown;
};
export type AgentToolCallProgressEvent = {
    phase: "started";
    callId: string;
    toolId: string;
    providerToolName?: string;
    arguments: Readonly<Record<string, unknown>>;
} | {
    phase: "completed" | "failed";
    providerToolName?: string;
    record: AgentToolCallRecord;
};
export type AgentModelCallRecord = {
    invocationId: string;
    raw: unknown;
    ok: boolean;
    usage?: AgentModelUsageRecord;
    providerRouting?: AgentModelProviderRoutingDebug;
    providerResponseId?: string;
    previousProviderResponseId?: string;
};
export type AgentModelUsageRecord = {
    inputTokens?: number;
    outputTokens?: number;
    thinkingTokens?: number;
    totalTokens?: number;
    cachedInputTokens?: number;
    source?: string;
    estimated: boolean;
};
export type AgentModelProviderRoutingDebug = {
    publicSafe: true;
    responseHeaderNames: readonly string[];
    responseCodexTurnState: "present" | "absent";
    responseRequestId?: string;
    responseOpenAIModel?: string;
};
export type AgentModelCallProgressEvent = {
    phase: "started";
    invocationId: string;
    turnIndex: number;
    provider: string;
    carrierId: string;
    model?: string;
} | {
    phase: "completed" | "failed";
    invocationId: string;
    turnIndex: number;
    provider: string;
    carrierId: string;
    model?: string;
    ok: boolean;
    usage?: AgentModelUsageRecord;
    providerRouting?: AgentModelProviderRoutingDebug;
    cacheDebug?: AgentModelCacheDebugRecord;
    providerResponseId?: string;
    previousProviderResponseId?: string;
    error?: PraxisRuntimeKernelError;
};
export type AgentModelCacheDebugRecord = {
    kind: "praxis.modelCall.cacheDebug";
    strategy: "prompt-pack-cache-xray";
    promptCacheKey?: string;
    promptPack: {
        totalEstimatedTokens: number;
        renderedTextEstimatedTokens: number;
        cacheablePrefixEstimatedTokens: number;
        dynamicEstimatedTokens: number;
        segmentCount: number;
        segments: readonly {
            segmentKind: PromptPackSegmentKind;
            cachePolicy: string;
            stability: string;
            estimatedTokens: number;
            segmentHash: string;
            materialCount: number;
            materialRefs: readonly string[];
            providerHints: Readonly<Record<string, unknown>>;
        }[];
        cacheRiskWarnings: readonly string[];
        providerLowering?: {
            instructionSegmentKinds: readonly PromptPackSegmentKind[];
            dynamicInputSegmentKinds: readonly PromptPackSegmentKind[];
            instructionEstimatedTokens: number;
            dynamicInputEstimatedTokens: number;
            instructionsHash: string;
            dynamicInputHash: string;
        };
    };
    providerBody: {
        estimatedTokens: number;
        inputEstimatedTokens: number;
        toolsEstimatedTokens: number;
        toolCount: number;
        fingerprints: Readonly<Record<string, string>>;
        previousProviderOutputItems: number;
        toolResultInputs: number;
        toolResultBudget: {
            budgetBytes: number;
            originalToolResultBytes: number;
            replayedToolResultBytes: number;
            fullToolResults: number;
            compactedToolResults: number;
        };
        cacheShape: {
            providerStablePrefixEstimatedTokens: number;
            providerDynamicInputEstimatedTokens: number;
            stablePrefixShare: number;
            dynamicInputShare: number;
            stablePrefixHash: string;
            dynamicPayloadHash: string;
        };
    };
    observedUsage?: {
        inputTokens?: number;
        cachedInputTokens?: number;
        nonCachedInputTokens?: number;
        cacheHitRate?: number;
        stablePrefixWarmthEstimate?: number;
        diagnosis: "no-cache-telemetry" | "warm-stable-prefix" | "dynamic-payload-dominates" | "stable-prefix-cache-break" | "provider-cache-miss-with-stable-prefix" | "partial-cache-hit";
        reasons: readonly string[];
    };
    comparisonToPrevious?: {
        previousStablePrefixHash: string;
        previousDynamicPayloadHash: string;
        stablePrefixChanged: boolean;
        dynamicPayloadChanged: boolean;
        instructionsChanged: boolean;
        toolsChanged: boolean;
        changedFingerprintKeys: readonly string[];
    };
};
export type AgentRunResult = {
    ok: true;
    runtimeId: string;
    sessionId: string;
    manifest: AgentManifest;
    finalOutput: string;
    modelCalls: readonly AgentModelCallRecord[];
    toolCalls: readonly AgentToolCallRecord[];
    mainLoopSteps: readonly MainLoopStepRecord[];
    events: readonly string[];
    state: RuntimeSessionSnapshot;
} | {
    ok: false;
    runtimeId?: string;
    sessionId?: string;
    manifest?: AgentManifest;
    error: PraxisRuntimeKernelError;
    mainLoopSteps?: readonly MainLoopStepRecord[];
    events: readonly string[];
    state?: RuntimeSessionSnapshot;
};
export declare class PraxisRuntimeKernel {
    readonly runtimeId?: string;
    readonly store: RuntimeSessionStateEventStore;
    private readonly storeProvided;
    constructor(options?: {
        runtimeId?: string;
        store?: RuntimeSessionStateEventStore;
    });
    run(agent: PraxisAgentInput<PraxisAgent>, task: string, options?: PraxisRuntimeKernelOptions): Promise<AgentRunResult>;
    runManifest(manifest: AgentManifest, task: string, options?: PraxisRuntimeKernelOptions): Promise<AgentRunResult>;
}
export declare function createPraxisRuntimeKernel(options?: {
    runtimeId?: string;
    store?: RuntimeSessionStateEventStore;
}): PraxisRuntimeKernel;
