import type { AgentRuntime } from '@best-agent/engine';
import type { AskUserQuestion, ServerEvent, ThreadDetail, ThreadId, ThreadMode } from '@best-agent/protocol';
type CliModeId = 'agent' | 'plan';
type RuntimeConfigLike = Readonly<{
    adapter?: string;
    apiKey?: string;
    baseUrl?: string;
    env?: Record<string, string | undefined>;
    maxInputTokens?: number;
    maxOutputTokens?: number;
    modelId?: string;
    nextApiOAuth?: boolean;
    provider?: string;
}>;
type ToolApprovalMode = 'auto' | 'normal' | 'strict';
type EnsureSessionInput = Readonly<{
    sessionId?: string;
    cwd?: string;
    modeId?: CliModeId;
    runtimeConfig?: RuntimeConfigLike;
    toolApprovalMode?: ToolApprovalMode;
    mcpServers?: readonly Record<string, unknown>[];
    metadata?: Record<string, unknown>;
}>;
type ToolPermission = 'pass' | 'require_action';
type LastRequestBudget = Readonly<{
    runId?: string;
    requestId?: string;
    autoBudgetOutcome: 'budget-unknown' | 'compacted' | 'failed-to-fit' | 'not-needed';
    autoBudgetReasonCode?: string;
    budgetSource?: string;
    contextWindowTokens?: number;
    estimatedInputTokens: number;
    inputBudgetTokens?: number;
    maxOutputTokens?: number;
    protocolReserveTokens?: number;
    reservedOutputTokens?: number;
    thresholdTokens?: number;
    maxInputTokens?: number;
    triggerRatio?: number;
    usedAutoCompaction: boolean;
    updatedAt?: string;
    updatedAtMs: number;
}>;
type SessionQueueStatus = 'idle' | 'running' | 'paused_confirm' | 'error';
type SessionQueueErrorCode = 'network_error' | 'timeout' | 'canceled_by_user' | 'rate_limited' | 'config_unavailable' | 'unknown';
type SessionQueueItem = Readonly<{
    id: string;
    text: string;
    createdAt: number;
    kind: 'user' | 'steer';
    steeredAt?: number;
    config?: Readonly<{
        model?: string;
        temperature?: number;
        interleavedThinking?: boolean;
        approvalsMode?: ToolApprovalMode;
        providerId?: string;
    }>;
}>;
type BridgeUsageUpdate = Readonly<{
    completionTokens: number;
    promptTokens: number;
    totalTokens: number;
    reasoningTokens?: number;
}>;
type BridgeBudgetUpdate = LastRequestBudget | NonNullable<Extract<ServerEvent, {
    type: 'thread.usage.updated';
}>['lastRequestBudget']>;
type BridgeSessionUiMetadata = {
    lastErrorCode?: SessionQueueErrorCode;
    lastUpdatedAt: number;
    pinnedMessageIds: string[];
    queue: SessionQueueItem[];
    queueLength: number;
    reasoningDiagnosticsByTurn: ReasoningDiagnosticsByTurn;
    status: SessionQueueStatus;
    titleSuggestedAt?: number;
};
type StoreUsageState = {
    completion_tokens?: number;
    prompt_tokens?: number;
    total_tokens?: number;
};
type ToolResultRecord = Readonly<{
    output: string;
    status: 'success' | 'error';
    structuredContent?: unknown;
    toolCallId: string;
}>;
type AssistantPart = Readonly<{
    type: 'status';
    text: string;
}> | Readonly<{
    type: 'thinking';
    partId: string;
    title: string;
    collapsed: boolean;
    content: string;
}> | Readonly<{
    type: 'markdown';
    markdown: string;
}> | Readonly<{
    type: 'tool_call';
    call: Readonly<{
        id: string;
        name: string;
        arguments: Record<string, unknown>;
        argumentsText?: string;
    }>;
}> | Readonly<{
    type: 'tool_result';
    result: ToolResultRecord;
}> | Readonly<{
    type: 'info';
    text: string;
    _reasoning?: ReasoningDiagnosticState;
    _tone?: 'success' | 'warning' | 'danger';
}>;
export type BridgeMessage = Readonly<{
    id: string;
    role: 'user';
    content: string;
    focusFiles?: readonly string[];
} | {
    id: string;
    role: 'assistant';
    parts: AssistantPart[];
} | {
    id: string;
    role: 'tool';
    result: ToolResultRecord;
}>;
type ManualCompactionResult = Readonly<{
    error?: string;
    errorCode?: string;
    event?: {
        diagnostics?: {
            notification?: {
                maxInputTokens?: number;
                thresholdTokens?: number;
            };
        };
        tokensBefore?: number;
        tokensAfter?: number;
    };
    messageCount?: number;
    success: boolean;
}>;
type CliSession = Readonly<{
    id: string;
    run: (input: Readonly<{
        content: unknown;
        metadata?: Record<string, unknown>;
    }>, options?: Readonly<{
        signal?: AbortSignal;
    }>) => AsyncGenerator<NativeSessionEvent, void, void>;
    resume: (input: Readonly<{
        kind: 'tool_approval' | 'ask_user';
        actionId: string;
        toolCallId?: string;
        approved?: boolean;
        alwaysAllowForConversation?: boolean;
        answers?: Record<string, string | string[]>;
        rejected?: boolean;
        reason?: string;
    }>, options?: Readonly<{
        signal?: AbortSignal;
    }>) => AsyncGenerator<NativeSessionEvent, void, void>;
    setMode: (modeId: CliModeId) => Promise<void>;
    steer: (input: string) => Promise<boolean>;
    triggerManualCompaction: () => Promise<ManualCompactionResult>;
    updateConfig: (input: Record<string, unknown>) => Promise<void>;
}>;
type CliAgentBridge = Readonly<{
    sessions?: Readonly<{
        create: () => Promise<CliSession>;
        destroy: (sessionId: string) => Promise<void>;
        get: (sessionId: string) => Promise<ThreadDetail | null>;
        interrupt: (sessionId: string) => Promise<boolean>;
        list: () => Promise<ThreadDetail[]>;
        rename: (sessionId: string, title: string) => Promise<void>;
        updateMetadata: (sessionId: string, metadata: Record<string, unknown>) => Promise<void>;
    }>;
    openSession?: (sessionId: string) => Promise<CliSession | null>;
    ensureSession?: (opts?: EnsureSessionInput) => Promise<CliSession>;
    steerSession?: (sessionId: string, input: string) => Promise<boolean>;
    setMode?: (modeId: CliModeId) => void;
    getMode?: () => CliModeId;
    triggerManualCompression?: (sessionId?: string) => Promise<ManualCompactionResult>;
    invalidateSession?: (sessionId: string) => void;
}>;
type ReasoningDiagnostics = Readonly<{
    state: 'visible' | 'tokens_only' | 'none';
}>;
type ReasoningDiagnosticState = ReasoningDiagnostics['state'];
type ReasoningDiagnosticsByTurn = Record<string, ReasoningDiagnosticState>;
type NativeSessionEvent = Readonly<{
    type: 'thinking.started';
    partId: string;
}> | Readonly<{
    type: 'thinking.delta';
    partId: string;
    delta: string;
}> | Readonly<{
    type: 'thinking.finished';
    partId: string;
    content?: string;
}> | Readonly<{
    type: 'assistant.delta';
    delta: string;
}> | Readonly<{
    type: 'assistant.message';
    message: Readonly<{
        content: string;
        thinking?: string;
    }>;
}> | Readonly<{
    type: 'tool.started';
    toolCallId: string;
    toolName: string;
    subagentId?: string;
    input: Record<string, unknown>;
    originalEventType?: 'tool_call' | 'tool_call_end';
}> | Readonly<{
    type: 'tool.delta';
    toolCallId: string;
    toolName: string;
    subagentId?: string;
    kind: 'input' | 'output';
    delta: string;
    linesWritten?: number;
    isStderr?: boolean;
}> | Readonly<{
    type: 'tool.finished';
    toolCallId: string;
    toolName: string;
    subagentId?: string;
    output: unknown;
    isError?: boolean;
}> | Readonly<{
    type: 'action.required';
    kind: 'tool_approval';
    actionId: string;
    subagentId?: string;
    toolCallId: string;
    toolName: string;
    reason?: string;
    permission?: ToolPermission;
    riskLevel?: string;
    args?: Record<string, unknown>;
}> | Readonly<{
    type: 'action.required';
    kind: 'ask_user';
    actionId: string;
    toolCallId?: string;
    toolName: string;
    questions: readonly AskUserQuestion[];
    error?: unknown;
}> | Readonly<{
    type: 'steer_injected';
    content: string;
}> | Readonly<{
    type: 'subagent.started';
    subagentId: string;
    taskDescription?: string;
}> | Readonly<{
    type: 'subagent.output';
    subagentId: string;
    stream: 'tool' | 'text' | 'error';
    delta: string;
}> | Readonly<{
    type: 'subagent.finished';
    subagentId: string;
    state: 'completed' | 'failed' | 'rejected';
}> | Readonly<{
    type: 'context.compression';
    state: 'completed';
    trigger: 'auto' | 'manual';
    tokensBefore?: number;
    tokensAfter?: number;
    diagnostics?: Record<string, unknown>;
}> | Readonly<{
    type: 'usage.updated';
    usage?: BridgeUsageUpdate;
    lastRequestBudget?: BridgeBudgetUpdate;
}> | Readonly<{
    type: 'run.finished';
    status: 'completed' | 'interrupted';
    reasoningDiagnostics: ReasoningDiagnostics;
    usage?: BridgeUsageUpdate;
}> | Readonly<{
    type: 'run.error';
    error: unknown;
    reasoningDiagnostics?: ReasoningDiagnostics;
    usage?: BridgeUsageUpdate;
}>;
type DimSdkStoreLike = {
    applyLastRequestBudget?: (budget: BridgeBudgetUpdate | null | undefined) => void;
    applyUsageFromSession?: (usage: BridgeUsageUpdate) => void;
    setCwd?: (cwd: string) => void;
    setMode?: (modeId: CliModeId) => void;
    state: {
        approval?: {
            active: unknown;
            pendingAutoRun: unknown;
            skipApproval?: boolean;
        };
        context: {
            cwd: string;
            env: Record<string, string | undefined>;
            focusFiles?: readonly string[];
            system: string;
        };
        chromeVersion?: number;
        messages: BridgeMessage[];
        paused: unknown;
        revertedMessages?: BridgeMessage[];
        runningAgentRound?: boolean;
        runningToolCallId?: string | null;
        sessionId: string;
        sessionMeta?: BridgeSessionUiMetadata;
        usage?: StoreUsageState;
        lastRequestBudget?: LastRequestBudget | null;
        ui?: {
            mode?: CliModeId;
        };
        thinking?: {
            active: boolean;
            endedAt: number | null;
            startedAt: number | null;
        };
    };
};
export type BestAgentSessionsApi = Readonly<{
    list: () => Promise<ReadonlyArray<{
        id: string;
        updatedAt: number;
        cwd?: string;
        title: string;
        summary: string;
        messageCount: number;
        lastMessage?: string;
        status?: string;
        queueLength?: number;
        queue?: readonly SessionQueueItem[];
        lastUpdatedAt?: number;
        reasoningDiagnosticsByTurn?: ReasoningDiagnosticsByTurn;
    }>>;
    get?: (id: string) => Promise<ThreadDetail | null>;
    trace?: (id: string) => Promise<BestAgentSessionTrace | null>;
    reload?: (id: string) => Promise<boolean>;
    use: (id: string) => Promise<void>;
    createNew: () => Promise<void>;
    delete: (id: string) => Promise<void>;
    rename?: (id: string, title: string) => Promise<void>;
    fork?: (opts: Readonly<{
        messages: readonly BridgeMessage[];
    }>) => Promise<void>;
    updateMetadata?: (id: string, metadata: Record<string, unknown>) => Promise<void>;
}>;
type BestAgentSessionTrace = Readonly<{
    threadId: string;
    generatedAt: number;
    eventCount: number;
    requests: ReadonlyArray<{
        id: string;
        index: number;
        kind: 'turn' | 'session';
        status: string;
        turnId?: string;
        startedAt?: number;
        completedAt?: number;
        promptPreview?: string;
        assistantPreview?: string;
        userMessageCount: number;
        assistantMessageCount: number;
        toolCallCount: number;
        childTaskCount: number;
        compactionCount: number;
        runCount: number;
        eventCount: number;
        events: ReadonlyArray<{
            sequence: number;
            at: number;
            type: string;
            summary: string;
        }>;
    }>;
}>;
export declare function resolveInitialBestAgentThread(runtime: AgentRuntime, options: Readonly<{
    latest?: boolean;
    resumeThreadId?: string;
    threadMode?: ThreadMode;
}>): Promise<ThreadDetail>;
export declare function createBestAgentNativeBridge(options: Readonly<{
    agentProfile?: string;
    runtime: AgentRuntime;
    threadMode?: ThreadMode;
}>): Readonly<{
    agent: CliAgentBridge;
    attachStore: (store: DimSdkStoreLike) => void;
    hydrateThread: (threadId: ThreadId) => Promise<BridgeMessage[]>;
    sessions: BestAgentSessionsApi;
}>;
export declare const createGoatChainBridge: typeof createBestAgentNativeBridge;
export declare const resolveInitialGoatChainThread: typeof resolveInitialBestAgentThread;
export {};
//# sourceMappingURL=best-agent-native-bridge.d.ts.map