import { type AssistantMessage as OpenCodeAssistantMessage, type Event as OpenCodeEvent, type FilePartInput as OpenCodeFilePartInput, type OpencodeClient, type TextPartInput as OpenCodeTextPartInput } from "@opencode-ai/sdk/v2/client";
import type { Logger } from "pino";
import { type AgentCapabilityFlags, type AgentClient, type AgentCreateSessionOptions, type AgentFeature, type AgentLaunchContext, type AgentMode, type AgentModelDefinition, type AgentPermissionRequest, type AgentPermissionResponse, type AgentPersistenceHandle, type AgentPromptInput, type AgentRunOptions, type AgentRunResult, type AgentRuntimeInfo, type AgentSession, type AgentSessionConfig, type AgentSlashCommand, type AgentStreamEvent, type AgentUsage, type ResolveAgentCreateConfigInput, type ResolveAgentCreateConfigResult, type ListModelsOptions, type ListModesOptions, type ListPersistedAgentsOptions, type PersistedAgentDescriptor, type ToolCallTimelineItem } from "../agent-sdk-types.js";
import { isDefaultAgentCreateConfigUnattended } from "../create-agent-mode.js";
import { type ProviderRuntimeSettings } from "../provider-launch-config.js";
import { type OpenCodeRuntime } from "./opencode/runtime.js";
declare function resolveOpenCodeCreateConfig(input: ResolveAgentCreateConfigInput): ResolveAgentCreateConfigResult;
declare function isOpenCodeCreateConfigUnattended(input: Parameters<typeof isDefaultAgentCreateConfigUnattended>[0]): boolean;
type OpenCodeAgentConfig = AgentSessionConfig & {
    provider: "opencode";
};
type OpenCodeMessageRole = "user" | "assistant";
declare function reconcileOpenCodeSessionClose(params: {
    client: Pick<OpencodeClient, "session">;
    sessionId: string;
    directory: string;
    logger: Logger;
}): Promise<void>;
declare function isSelectableOpenCodeAgent(agent: {
    mode?: string;
    hidden?: boolean;
}): boolean;
declare function mapOpenCodeAgentToMode(agent: {
    name: string;
    description?: unknown;
    color?: unknown;
}): AgentMode;
declare function buildOpenCodeModelLookupKey(providerId: string, modelId: string): string;
declare function parseOpenCodeModelLookupKey(modelId: string | null | undefined): string | undefined;
declare function extractOpenCodeModelContextWindow(model: unknown): number | undefined;
declare function buildOpenCodeModelDefinition(provider: {
    id: string;
    name: string;
}, modelId: string, model: {
    name: string;
    family?: string;
    release_date?: string;
    attachment?: boolean;
    reasoning?: boolean;
    tool_call?: boolean;
    cost?: unknown;
    limit?: {
        context?: number;
        input?: number;
        output?: number;
    };
    variants?: Record<string, unknown>;
}): AgentModelDefinition;
declare function resolveOpenCodeSelectedModelContextWindow(providers: {
    connected?: string[];
    all?: Array<{
        id: string;
        models?: Record<string, unknown>;
    }>;
} | null | undefined, modelId: string | null | undefined): number | undefined;
declare function buildOpenCodeModelContextWindowLookup(providers: {
    connected?: string[];
    all?: Array<{
        id: string;
        source?: string;
        models?: Record<string, unknown>;
    }>;
} | null | undefined): Map<string, number>;
declare function resolveOpenCodeModelLookupKeyFromAssistantMessage(info: OpenCodeAssistantMessage): string | undefined;
declare function mergeOpenCodeStepFinishUsage(usage: AgentUsage, part: {
    cost?: unknown;
    tokens?: {
        input?: unknown;
        output?: unknown;
        reasoning?: unknown;
        total?: unknown;
        cache?: {
            read?: unknown;
            write?: unknown;
        };
    };
}, options?: {
    totalCostUsd?: number;
}): void;
declare function hasNormalizedOpenCodeUsage(usage: AgentUsage): boolean;
declare function buildOpenCodePromptParts(prompt: AgentPromptInput): Array<OpenCodeTextPartInput | OpenCodeFilePartInput>;
export declare const __openCodeInternals: {
    buildOpenCodePromptParts: typeof buildOpenCodePromptParts;
    buildOpenCodeModelContextWindowLookup: typeof buildOpenCodeModelContextWindowLookup;
    buildOpenCodeModelDefinition: typeof buildOpenCodeModelDefinition;
    buildOpenCodeModelLookupKey: typeof buildOpenCodeModelLookupKey;
    extractOpenCodeModelContextWindow: typeof extractOpenCodeModelContextWindow;
    hasNormalizedOpenCodeUsage: typeof hasNormalizedOpenCodeUsage;
    mergeOpenCodeStepFinishUsage: typeof mergeOpenCodeStepFinishUsage;
    parseOpenCodeModelLookupKey: typeof parseOpenCodeModelLookupKey;
    reconcileOpenCodeSessionClose: typeof reconcileOpenCodeSessionClose;
    resolveOpenCodeModelLookupKeyFromAssistantMessage: typeof resolveOpenCodeModelLookupKeyFromAssistantMessage;
    resolveOpenCodeSelectedModelContextWindow: typeof resolveOpenCodeSelectedModelContextWindow;
    isSelectableOpenCodeAgent: typeof isSelectableOpenCodeAgent;
    mapOpenCodeAgentToMode: typeof mapOpenCodeAgentToMode;
    readonly OpenCodeAgentSession: typeof OpenCodeAgentSession;
};
interface OpenCodeAgentClientDeps {
    runtime?: OpenCodeRuntime;
}
export declare class OpenCodeAgentClient implements AgentClient {
    readonly provider: "opencode";
    readonly capabilities: AgentCapabilityFlags;
    readonly resolveCreateConfig: typeof resolveOpenCodeCreateConfig;
    readonly isCreateConfigUnattended: typeof isOpenCodeCreateConfigUnattended;
    private readonly runtime;
    private readonly logger;
    private readonly runtimeSettings?;
    private readonly modelContextWindows;
    constructor(logger: Logger, runtimeSettings?: ProviderRuntimeSettings, deps?: OpenCodeAgentClientDeps);
    createSession(config: AgentSessionConfig, launchContext?: AgentLaunchContext, options?: AgentCreateSessionOptions): Promise<AgentSession>;
    resumeSession(handle: AgentPersistenceHandle, overrides?: Partial<AgentSessionConfig>, launchContext?: AgentLaunchContext): Promise<AgentSession>;
    listModels(options: ListModelsOptions): Promise<AgentModelDefinition[]>;
    listModes(options: ListModesOptions): Promise<AgentMode[]>;
    listCommands(config: AgentSessionConfig): Promise<AgentSlashCommand[]>;
    listFeatures(config: AgentSessionConfig): Promise<AgentFeature[]>;
    listPersistedAgents(options?: ListPersistedAgentsOptions): Promise<PersistedAgentDescriptor[]>;
    isAvailable(): Promise<boolean>;
    shutdown(): Promise<void>;
    getDiagnostic(): Promise<{
        diagnostic: string;
    }>;
    private assertConfig;
    private populateModelContextWindowCache;
}
export interface OpenCodeEventTranslationState {
    sessionId: string;
    cwd?: string;
    messageRoles: Map<string, OpenCodeMessageRole>;
    pendingUserMessageText?: string | null;
    emittedUserMessageIds?: Set<string>;
    accumulatedUsage: AgentUsage;
    sessionTotalCostUsd?: number;
    streamedPartKeys: Set<string>;
    emittedStructuredMessageIds: Set<string>;
    /** Tracks the type of each part by ID, learned from message.part.updated events. */
    partTypes: Map<string, string>;
    subAgentsByCallId?: Map<string, OpenCodeSubAgentActivityState>;
    subAgentCallIdByChildSessionId?: Map<string, string>;
    pendingChildToolPartsBySessionId?: Map<string, OpenCodeToolPartEventPart[]>;
    modelContextWindowsByModelKey?: ReadonlyMap<string, number>;
    onAssistantModelContextWindowResolved?: (contextWindowMaxTokens: number) => void;
}
type OpenCodeToolPartEventPart = Extract<Extract<OpenCodeEvent, {
    type: "message.part.updated";
}>["properties"]["part"], {
    type: "tool";
}>;
interface OpenCodeSubAgentActionEntry {
    index: number;
    key: string;
    toolName: string;
    summary?: string;
}
interface OpenCodeSubAgentActivityState {
    toolCall: ToolCallTimelineItem;
    actions: OpenCodeSubAgentActionEntry[];
    actionIndexByKey: Map<string, number>;
    nextActionIndex: number;
    childSessionId?: string;
}
export declare function translateOpenCodeEvent(event: OpenCodeEvent, state: OpenCodeEventTranslationState): AgentStreamEvent[];
declare class OpenCodeAgentSession implements AgentSession {
    private readonly agentId?;
    readonly provider: "opencode";
    readonly capabilities: AgentCapabilityFlags;
    private readonly config;
    private readonly client;
    private readonly sessionId;
    private readonly logger;
    private readonly modelContextWindowsByModelKey;
    private currentMode;
    private autoAcceptEnabled;
    private pendingPermissions;
    private abortController;
    private pendingAbortPromise;
    private accumulatedUsage;
    private sessionTotalCostUsd;
    private mcpConfigured;
    private mcpSetupPromise;
    /** Tracks the role of each message by ID to distinguish user from assistant messages */
    private messageRoles;
    private pendingUserMessageText;
    private emittedUserMessageIds;
    /** Tracks streamed textual part IDs to suppress final full-text echoes from OpenCode. */
    private streamedPartKeys;
    /** Tracks assistant messages already emitted from structured payloads. */
    private emittedStructuredMessageIds;
    /** Tracks the type of each part by ID, learned from message.part.updated events. */
    private partTypes;
    private availableModesCache;
    private readonly subscribers;
    private nextTurnOrdinal;
    private activeForegroundTurnId;
    private readonly runningToolCalls;
    private subAgentsByCallId;
    private subAgentCallIdByChildSessionId;
    private pendingChildToolPartsBySessionId;
    private selectedModelContextWindowMaxTokens;
    private releaseServer;
    private eventStreamAbortController;
    private eventStreamReady;
    private suppressTerminalUntilNextUserMessage;
    private closed;
    private readonly persistSession;
    private deletedFromProvider;
    constructor(config: OpenCodeAgentConfig, client: OpencodeClient, sessionId: string, logger: Logger, modelContextWindowsByModelKey?: ReadonlyMap<string, number>, releaseServer?: () => void, persistSession?: boolean, agentId?: string | undefined);
    get id(): string | null;
    get features(): AgentFeature[];
    getRuntimeInfo(): Promise<AgentRuntimeInfo>;
    setModel(modelId: string | null): Promise<void>;
    setThinkingOption(thinkingOptionId: string | null): Promise<void>;
    run(prompt: AgentPromptInput, options?: AgentRunOptions): Promise<AgentRunResult>;
    interrupt(): Promise<void>;
    revertBoth(input: {
        messageId: string;
    }): Promise<void>;
    private beginSessionAbort;
    private awaitPendingAbortBeforeStartingTurn;
    startTurn(prompt: AgentPromptInput, options?: AgentRunOptions): Promise<{
        turnId: string;
    }>;
    subscribe(callback: (event: AgentStreamEvent) => void): () => void;
    private startEventStream;
    private ensureEventStreamReady;
    private consumeEventStream;
    private consumeOpenCodeStreamEvent;
    private finishForegroundTurn;
    private trackToolCall;
    private synthesizeInterruptedToolCalls;
    private notifySubscribers;
    private createTurnId;
    private traceOpenCode;
    streamHistory(): AsyncGenerator<AgentStreamEvent>;
    getAvailableModes(): Promise<AgentMode[]>;
    getCurrentMode(): Promise<string | null>;
    listCommands(): Promise<AgentSlashCommand[]>;
    setMode(modeId: string): Promise<void>;
    setFeature(featureId: string, value: unknown): Promise<void>;
    getPendingPermissions(): AgentPermissionRequest[];
    respondToPermission(requestId: string, response: AgentPermissionResponse): Promise<void>;
    describePersistence(): AgentPersistenceHandle | null;
    close(): Promise<void>;
    private deleteProviderSessionIfEphemeral;
    private parseSlashCommandInput;
    private resolveSlashCommandInvocation;
    private parseModel;
    private ensureMcpServersConfigured;
    private configureMcpServers;
    private registerMcpServer;
    private runMcpOperation;
    private translateEvent;
    private tryAutoApproveToolPermission;
    private resolveSelectedModelContextWindowMaxTokens;
    private resolveConfiguredModelContextWindowMaxTokens;
}
export {};
//# sourceMappingURL=opencode-agent.d.ts.map