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, AgentClient, AgentCreateSessionOptions, AgentLaunchContext, AgentMode, AgentModelDefinition, AgentPermissionRequest, AgentPermissionResponse, AgentPersistenceHandle, AgentPromptInput, AgentRunOptions, AgentRunResult, AgentRuntimeInfo, AgentSession, AgentSessionConfig, AgentSlashCommand, AgentStreamEvent, AgentUsage, ListModelsOptions, ListModesOptions, ListPersistedAgentsOptions, PersistedAgentDescriptor, ToolCallTimelineItem } from "../agent-sdk-types.js";
import { type ProviderRuntimeSettings } from "../provider-launch-config.js";
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 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;
        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;
        };
    };
}): 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;
    readonly OpenCodeAgentSession: typeof OpenCodeAgentSession;
};
export declare class OpenCodeServerManager {
    private static instance;
    private static exitHandlerRegistered;
    private currentServer;
    private retiredServers;
    private startPromise;
    private forcedRefreshPromise;
    private readonly logger;
    private readonly runtimeSettings?;
    private readonly runtimeSettingsKey;
    private constructor();
    static getInstance(logger: Logger, runtimeSettings?: ProviderRuntimeSettings): OpenCodeServerManager;
    private static registerExitHandler;
    ensureRunning(): Promise<{
        port: number;
        url: string;
    }>;
    acquire(options: {
        force: boolean;
    }): Promise<{
        server: {
            port: number;
            url: string;
        };
        release: () => void;
    }>;
    private getForcedRefreshServer;
    private getCurrentServer;
    private rotateCurrentServer;
    private startServer;
    shutdown(): Promise<void>;
    private cleanupRetiredServers;
    private killServer;
}
export declare class OpenCodeAgentClient implements AgentClient {
    readonly provider: "opencode";
    readonly capabilities: AgentCapabilityFlags;
    private readonly serverManager;
    private readonly logger;
    private readonly runtimeSettings?;
    private readonly modelContextWindows;
    private readonly storageRoot;
    constructor(logger: Logger, runtimeSettings?: ProviderRuntimeSettings, storageRoot?: string);
    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[]>;
    listPersistedAgents(options?: ListPersistedAgentsOptions): Promise<PersistedAgentDescriptor[]>;
    isAvailable(): Promise<boolean>;
    getDiagnostic(): Promise<{
        diagnostic: string;
    }>;
    private assertConfig;
    private populateModelContextWindowCache;
}
export interface OpenCodeEventTranslationState {
    sessionId: string;
    cwd?: string;
    messageRoles: Map<string, OpenCodeMessageRole>;
    accumulatedUsage: AgentUsage;
    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 {
    readonly provider: "opencode";
    readonly capabilities: AgentCapabilityFlags;
    private readonly config;
    private readonly client;
    private readonly sessionId;
    private readonly logger;
    private readonly modelContextWindowsByModelKey;
    private currentMode;
    private pendingPermissions;
    private abortController;
    private accumulatedUsage;
    private mcpConfigured;
    private mcpSetupPromise;
    /** Tracks the role of each message by ID to distinguish user from assistant messages */
    private messageRoles;
    /** 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 readonly persistSession;
    private deletedFromProvider;
    constructor(config: OpenCodeAgentConfig, client: OpencodeClient, sessionId: string, logger: Logger, modelContextWindowsByModelKey?: ReadonlyMap<string, number>, releaseServer?: () => void, persistSession?: boolean);
    get id(): string | null;
    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>;
    startTurn(prompt: AgentPromptInput, options?: AgentRunOptions): Promise<{
        turnId: string;
    }>;
    subscribe(callback: (event: AgentStreamEvent) => void): () => void;
    private consumeEventStream;
    private finishForegroundTurn;
    private trackToolCall;
    private synthesizeInterruptedToolCalls;
    private notifySubscribers;
    private createTurnId;
    streamHistory(): AsyncGenerator<AgentStreamEvent>;
    getAvailableModes(): Promise<AgentMode[]>;
    getCurrentMode(): Promise<string | null>;
    listCommands(): Promise<AgentSlashCommand[]>;
    setMode(modeId: string): 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