import { AgentSession as pb } from '@livekit/protocol';
import type { Room, TextStreamInfo } from '@livekit/rtc-node';
import type { TypedEventEmitter } from '@livekit/typed-emitter';
import type { AgentSession } from './agent_session.js';
import { type AMDPredictionEvent } from './amd.js';
import type { TcpAudioInput, TcpAudioOutput } from './console_io.js';
import { type EotPredictionEvent } from './events.js';
import type { RoomIO } from './room_io/room_io.js';
export interface TextInputEvent {
    text: string;
    info?: TextStreamInfo;
    participantIdentity?: string;
}
export type TextInputCallback = (session: AgentSession, ev: TextInputEvent) => void | Promise<void>;
/** @experimental */
export type RemoteSessionEventTypes = 'agent_state_changed' | 'user_state_changed' | 'conversation_item_added' | 'user_input_transcribed' | 'function_tools_executed' | 'overlapping_speech' | 'amd_prediction' | 'eot_prediction' | 'session_usage' | 'debug_message' | 'error';
/** @experimental */
export type RemoteSessionCallbacks = {
    agent_state_changed: (ev: pb.AgentSessionEvent_AgentStateChanged) => void;
    user_state_changed: (ev: pb.AgentSessionEvent_UserStateChanged) => void;
    conversation_item_added: (ev: pb.AgentSessionEvent_ConversationItemAdded) => void;
    user_input_transcribed: (ev: pb.AgentSessionEvent_UserInputTranscribed) => void;
    function_tools_executed: (ev: pb.AgentSessionEvent_FunctionToolsExecuted) => void;
    overlapping_speech: (ev: pb.AgentSessionEvent_OverlappingSpeech) => void;
    amd_prediction: (ev: pb.AgentSessionEvent_AmdPrediction) => void;
    eot_prediction: (ev: pb.AgentSessionEvent_EotPrediction) => void;
    session_usage: (ev: pb.AgentSessionEvent_SessionUsageUpdated) => void;
    debug_message: (ev: pb.DebugMessage) => void;
    error: (ev: pb.AgentSessionEvent_Error) => void;
};
export declare abstract class SessionTransport {
    start(): Promise<void>;
    abstract sendMessage(msg: pb.AgentSessionMessage): Promise<void>;
    abstract close(): Promise<void>;
    abstract [Symbol.asyncIterator](): AsyncIterator<pb.AgentSessionMessage>;
}
export declare class RoomSessionTransport extends SessionTransport {
    private readonly room;
    private handlerRegistered;
    private closed;
    private pendingMessages;
    private waitingResolve;
    private roomIO;
    constructor(room: Room, roomIO: RoomIO);
    private getRemoteIdentity;
    start(): Promise<void>;
    private onByteStream;
    private readStream;
    sendMessage(msg: pb.AgentSessionMessage): Promise<void>;
    close(): Promise<void>;
    private enqueue;
    [Symbol.asyncIterator](): AsyncIterator<pb.AgentSessionMessage>;
}
/**
 * {@link SessionTransport} that frames protobuf messages over a raw TCP socket.
 *
 * @experimental
 */
export declare class TcpSessionTransport extends SessionTransport {
    private readonly host;
    private readonly port;
    private socket;
    private closed;
    constructor(host: string, port: number);
    start(): Promise<void>;
    sendMessage(msg: pb.AgentSessionMessage): Promise<void>;
    close(): Promise<void>;
    [Symbol.asyncIterator](): AsyncIterableIterator<pb.AgentSessionMessage>;
}
export declare class SessionHost {
    private readonly transport;
    private readonly audioInput;
    private readonly audioOutput;
    private session;
    private started;
    private eventsRegistered;
    private recvTask;
    private readonly tasks;
    private textInputCb;
    constructor(transport: SessionTransport, audioInput?: TcpAudioInput, audioOutput?: TcpAudioOutput);
    registerSession(session: AgentSession): void;
    registerTextInput(textInputCb: TextInputCallback): void;
    start(): Promise<void>;
    close(): Promise<void>;
    private recvLoop;
    private sendEvent;
    private emitEvent;
    private onAgentStateChanged;
    private onUserStateChanged;
    private onUserInputTranscribed;
    private onConversationItemAdded;
    private onFunctionToolsExecuted;
    private onEotPrediction;
    private onOverlappingSpeech;
    private onMetricsCollected;
    private onHostError;
    private onDebugMessage;
    /**
     * @internal — forwards an AMD prediction to the connected
     * {@link RemoteSession} peer. Mirrors python
     * `SessionHost._on_amd_prediction`.
     */
    _onAmdPrediction(event: AMDPredictionEvent): void;
    /**
     * @internal — forwards an audio-EOT prediction to the connected
     * {@link RemoteSession} peer.
     */
    _onEotPrediction(event: EotPredictionEvent): void;
    private handleRequestSafe;
    private handleRequest;
    private handleUpdateIo;
    private handleGetChatHistory;
    private handleGetAgentInfo;
    private handleRunInput;
    private handleGetSessionState;
    private handleGetSessionUsage;
    private sendResponse;
    private trackTask;
}
declare const RemoteSession_base: new () => TypedEventEmitter<RemoteSessionCallbacks>;
/** @experimental */
export declare class RemoteSession extends RemoteSession_base {
    private readonly transport;
    private started;
    private readonly tasks;
    private readonly pendingRequests;
    private recvTask;
    private readonly _logger;
    constructor(transport: SessionTransport);
    static fromRoom(room: Room, roomIO: RoomIO): RemoteSession;
    start(): Promise<void>;
    close(): Promise<void>;
    private recvLoop;
    private dispatchEvent;
    private dispatchResponse;
    private sendRequest;
    fetchSessionState(): Promise<pb.SessionResponse_GetSessionStateResponse>;
    fetchChatHistory(): Promise<pb.SessionResponse_GetChatHistoryResponse>;
    fetchAgentInfo(): Promise<pb.SessionResponse_GetAgentInfoResponse>;
    sendMessage(text: string, responseTimeout?: number): Promise<pb.SessionResponse_RunInputResponse>;
    fetchRtcStats(): Promise<pb.SessionResponse_GetRTCStatsResponse>;
    fetchSessionUsage(): Promise<pb.SessionResponse_GetSessionUsageResponse>;
    private trackTask;
}
export {};
//# sourceMappingURL=remote_session.d.ts.map