/**
 * OpenCode stream event handling.
 *
 * Converts OpenCode SDK SSE events into the unified StreamCallback format
 * used throughout the takt codebase.
 */
import type { StreamCallback } from '../../shared/types/provider.js';
/** Subset of OpenCode Part types relevant for stream handling */
export interface OpenCodeTextPart {
    id: string;
    type: 'text';
    text: string;
}
export interface OpenCodeReasoningPart {
    id: string;
    type: 'reasoning';
    text: string;
}
export interface OpenCodeToolPart {
    id: string;
    type: 'tool';
    callID: string;
    tool: string;
    state: OpenCodeToolState;
}
export type OpenCodeToolState = {
    status: 'pending';
    input: Record<string, unknown>;
} | {
    status: 'running';
    input: Record<string, unknown>;
    title?: string;
} | {
    status: 'completed';
    input: Record<string, unknown>;
    output: string;
    title: string;
} | {
    status: 'error';
    input: Record<string, unknown>;
    error: string;
};
export type OpenCodePart = OpenCodeTextPart | OpenCodeReasoningPart | OpenCodeToolPart | {
    id: string;
    type: string;
};
/** OpenCode SSE event types relevant for stream handling */
export interface OpenCodeMessagePartUpdatedEvent {
    type: 'message.part.updated';
    properties: {
        part: OpenCodePart;
        delta?: string;
    };
}
export interface OpenCodeSessionIdleEvent {
    type: 'session.idle';
    properties: {
        sessionID: string;
    };
}
export interface OpenCodeSessionStatusEvent {
    type: 'session.status';
    properties: {
        sessionID: string;
        status: {
            type: 'idle' | 'busy' | 'retry';
            attempt?: number;
            message?: string;
            next?: number;
        };
    };
}
export interface OpenCodeSessionErrorEvent {
    type: 'session.error';
    properties: {
        sessionID?: string;
        error?: {
            name: string;
            data: {
                message: string;
            };
        };
    };
}
export interface OpenCodeMessageUpdatedEvent {
    type: 'message.updated';
    properties: {
        info: {
            sessionID: string;
            role: 'assistant' | 'user';
            time?: {
                created?: number;
                completed?: number;
            };
            error?: unknown;
        };
    };
}
export interface OpenCodeMessageCompletedEvent {
    type: 'message.completed';
    properties: {
        info: {
            sessionID: string;
            role: 'assistant' | 'user';
            error?: unknown;
        };
    };
}
export interface OpenCodeMessageFailedEvent {
    type: 'message.failed';
    properties: {
        info: {
            sessionID: string;
            role: 'assistant' | 'user';
            error?: unknown;
        };
    };
}
export interface OpenCodePermissionAskedEvent {
    type: 'permission.asked';
    properties: {
        id: string;
        sessionID: string;
        permission: string;
        patterns: string[];
        metadata: Record<string, unknown>;
        always: string[];
    };
}
export interface OpenCodeQuestionAskedEvent {
    type: 'question.asked';
    properties: {
        id: string;
        sessionID: string;
        questions: Array<{
            question: string;
            header: string;
            options: Array<{
                label: string;
                description: string;
            }>;
            multiple?: boolean;
        }>;
    };
}
export type OpenCodeStreamEvent = OpenCodeMessagePartUpdatedEvent | OpenCodeMessageUpdatedEvent | OpenCodeMessageCompletedEvent | OpenCodeMessageFailedEvent | OpenCodeSessionStatusEvent | OpenCodeSessionIdleEvent | OpenCodeSessionErrorEvent | OpenCodePermissionAskedEvent | OpenCodeQuestionAskedEvent | {
    type: string;
    properties: Record<string, unknown>;
};
/** Tracking state for stream offsets during a single OpenCode session */
export interface StreamTrackingState {
    textOffsets: Map<string, number>;
    thinkingOffsets: Map<string, number>;
    startedTools: Set<string>;
}
export declare function createStreamTrackingState(): StreamTrackingState;
export declare function emitInit(onStream: StreamCallback | undefined, model: string, sessionId: string): void;
export declare function emitText(onStream: StreamCallback | undefined, text: string): void;
export declare function emitThinking(onStream: StreamCallback | undefined, thinking: string): void;
export declare function emitToolUse(onStream: StreamCallback | undefined, tool: string, input: Record<string, unknown>, id: string): void;
export declare function emitToolResult(onStream: StreamCallback | undefined, content: string, isError: boolean): void;
export declare function emitResult(onStream: StreamCallback | undefined, success: boolean, result: string, sessionId: string): void;
/** Process a message.part.updated event and emit appropriate stream events */
export declare function handlePartUpdated(part: OpenCodePart, delta: string | undefined, onStream: StreamCallback | undefined, state: StreamTrackingState): void;
//# sourceMappingURL=OpenCodeStreamHandler.d.ts.map