/**
 * OpenCode Event Mapper
 *
 * Maps OpenCode SSE events to the provider-agnostic AgentMessage interface.
 * Handles deduplication of tool_use/tool_result events and text delta streaming.
 *
 * Types here mirror the real @opencode-ai/sdk event shapes:
 * - ToolPart.state is an object with `status` + nested `input`/`output`/`error`
 * - TextPart has `text` but delta comes from `event.properties.delta`
 * - Tool name lives in `ToolPart.tool`, not `ToolPart.name`
 *
 * @module
 */
import type { AgentMessage } from "../types.js";
/** Tool state objects — the `state` field on ToolPart is a discriminated union */
interface ToolStatePending {
    status: "pending";
    input: Record<string, unknown>;
}
interface ToolStateRunning {
    status: "running";
    input: Record<string, unknown>;
    title?: string;
}
interface ToolStateCompleted {
    status: "completed";
    input: Record<string, unknown>;
    output: string;
    title: string;
}
interface ToolStateError {
    status: "error";
    input: Record<string, unknown>;
    error: string;
}
type ToolState = ToolStatePending | ToolStateRunning | ToolStateCompleted | ToolStateError;
/** Part types emitted by OpenCode */
interface TextPart {
    type: "text";
    id: string;
    sessionID: string;
    text: string;
}
interface ToolPart {
    type: "tool";
    id: string;
    sessionID: string;
    callID: string;
    tool: string;
    state: ToolState;
}
interface ReasoningPart {
    type: "reasoning";
    id: string;
    sessionID: string;
}
interface StepStartPart {
    type: "step-start";
    id: string;
    sessionID: string;
}
interface StepFinishPart {
    type: "step-finish";
    id: string;
    sessionID: string;
}
interface AgentPart {
    type: "agent";
    id: string;
    sessionID: string;
}
type OpenCodePart = TextPart | ReasoningPart | ToolPart | StepStartPart | StepFinishPart | AgentPart;
/** OpenCode SSE event structure */
export interface OpenCodeEvent {
    type: string;
    properties?: {
        sessionID?: string;
        /** Incremental text delta (only on message.part.updated for TextPart) */
        delta?: string;
        part?: OpenCodePart & {
            sessionID?: string;
        };
        info?: {
            id?: string;
        };
        /** Structured error object (on session.error events) */
        error?: {
            message?: string;
            type?: string;
        } | string;
        status?: unknown;
        [key: string]: unknown;
    };
}
/**
 * Maps OpenCode SSE events to AgentMessage arrays.
 *
 * Tracks emitted tool IDs to avoid duplicate tool_use/tool_result messages
 * when OpenCode fires multiple `message.part.updated` events for the same tool
 * as it transitions through states.
 *
 * Buffers streaming text deltas and emits a single accumulated `assistant`
 * message when the text part is complete (i.e. a non-text event arrives).
 * This matches the Claude provider behavior where each AgentMessage is a
 * complete response, not a streaming chunk.
 */
export declare class OpenCodeEventMapper {
    private emittedToolUses;
    private emittedToolResults;
    /** Buffered text content from streaming deltas, keyed by part ID */
    private pendingText;
    /**
     * Maps an OpenCode SSE event to zero or more AgentMessages.
     *
     * @param event - The raw OpenCode SSE event
     * @param sessionId - Our session ID for filtering
     * @returns Array of AgentMessages (may be empty)
     */
    mapEvent(event: OpenCodeEvent, sessionId: string): AgentMessage[];
    /** Flush any buffered text as a final assistant message. Call after stream ends. */
    flush(): AgentMessage[];
    /** Reset state for a new conversation turn */
    reset(): void;
    private extractSessionId;
    private extractErrorMessage;
    private flushPendingText;
    private mapPartUpdated;
    private bufferTextPart;
    private mapToolPart;
}
export {};
//# sourceMappingURL=event-mapper.d.ts.map