import type { AudioFrame } from '@livekit/rtc-node';
import { AsyncLocalStorage } from 'node:async_hooks';
import { ReadableStream } from 'node:stream/web';
import { type LLMModels, type STTModelString, type TTSModelString } from '../inference/index.js';
import { type Instructions, ReadonlyChatContext } from '../llm/chat_context.js';
import type { ChatMessage, FunctionCall } from '../llm/index.js';
import { type ChatChunk, ChatContext, LLM, RealtimeModel, type ToolChoice, type ToolContext } from '../llm/index.js';
import type { STT, SpeechEvent } from '../stt/index.js';
import type { TTS } from '../tts/index.js';
import { type FlushSentinel } from '../types.js';
import { Task } from '../utils.js';
import type { VAD } from '../vad.js';
import { type AgentActivity } from './agent_activity.js';
import type { AgentSession, TurnDetectionMode } from './agent_session.js';
import type { UserTurnExceededEvent } from './events.js';
import type { TimedString } from './io.js';
import type { SpeechHandle } from './speech_handle.js';
import type { TurnHandlingOptions } from './turn_config/turn_handling.js';
export declare const functionCallStorage: AsyncLocalStorage<{
    functionCall?: FunctionCall;
    speechHandle?: SpeechHandle;
}>;
export declare const speechHandleStorage: AsyncLocalStorage<SpeechHandle>;
type _ActivityTaskInfo = {
    functionCall: FunctionCall | null;
    speechHandle: SpeechHandle | null;
    inlineTask: boolean;
};
/** @internal */
export declare function _setActivityTaskInfo<T>(task: Task<T>, options: {
    functionCall?: FunctionCall | null;
    speechHandle?: SpeechHandle | null;
    inlineTask?: boolean;
}): void;
/** @internal */
export declare function _getActivityTaskInfo<T>(task: Task<T>): _ActivityTaskInfo | undefined;
export declare const STOP_RESPONSE_SYMBOL: unique symbol;
export declare class StopResponse extends Error {
    constructor();
}
export declare function isStopResponse(value: unknown): value is StopResponse;
export interface ModelSettings {
    /** The tool choice to use when calling the LLM. */
    toolChoice?: ToolChoice;
}
export interface AgentOptions<UserData> {
    id?: string;
    instructions: string | Instructions;
    chatCtx?: ChatContext;
    tools?: ToolContext<UserData>;
    stt?: STT | STTModelString;
    vad?: VAD;
    llm?: LLM | RealtimeModel | LLMModels;
    tts?: TTS | TTSModelString;
    turnHandling?: TurnHandlingOptions;
    minConsecutiveSpeechDelay?: number;
    useTtsAlignedTranscript?: boolean;
    /** @deprecated use turnHandling.turnDetection instead */
    turnDetection?: TurnDetectionMode;
    /** @deprecated use turnHandling.interruption.enabled instead */
    allowInterruptions?: boolean;
}
export declare class Agent<UserData = any> {
    private _id;
    private _stt?;
    private _vad?;
    private _llm?;
    private _tts?;
    private _turnHandling?;
    private _minConsecutiveSpeechDelay?;
    private _useTtsAlignedTranscript?;
    /** @internal */
    _agentActivity?: AgentActivity;
    /** @internal */
    _chatCtx: ChatContext;
    /** @internal */
    _instructions: string | Instructions;
    /** @internal */
    _tools?: ToolContext<UserData>;
    constructor({ id, instructions, chatCtx, tools, turnDetection, stt, vad, llm, tts, allowInterruptions, turnHandling, minConsecutiveSpeechDelay, useTtsAlignedTranscript, }: AgentOptions<UserData>);
    get vad(): VAD | undefined;
    get stt(): STT | undefined;
    get llm(): LLM | RealtimeModel | undefined;
    get tts(): TTS | undefined;
    get useTtsAlignedTranscript(): boolean | undefined;
    get chatCtx(): ReadonlyChatContext;
    get id(): string;
    get instructions(): string | Instructions;
    get toolCtx(): ToolContext<UserData>;
    get session(): AgentSession<UserData>;
    get turnHandling(): Partial<TurnHandlingOptions> | undefined;
    get minConsecutiveSpeechDelay(): number | undefined;
    onEnter(): Promise<void>;
    onExit(): Promise<void>;
    transcriptionNode(text: ReadableStream<string | TimedString>, modelSettings: ModelSettings): Promise<ReadableStream<string | TimedString> | null>;
    onUserTurnCompleted(_chatCtx: ChatContext, _newMessage: ChatMessage): Promise<void>;
    onUserTurnExceeded(ev: UserTurnExceededEvent): Promise<void>;
    sttNode(audio: ReadableStream<AudioFrame>, modelSettings: ModelSettings): Promise<ReadableStream<SpeechEvent | string> | null>;
    llmNode(chatCtx: ChatContext, toolCtx: ToolContext, modelSettings: ModelSettings): Promise<ReadableStream<ChatChunk | string | FlushSentinel> | null>;
    ttsNode(text: ReadableStream<string>, modelSettings: ModelSettings): Promise<ReadableStream<AudioFrame> | null>;
    realtimeAudioOutputNode(audio: ReadableStream<AudioFrame>, modelSettings: ModelSettings): Promise<ReadableStream<AudioFrame> | null>;
    getActivityOrThrow(): AgentActivity;
    updateChatCtx(chatCtx: ChatContext): Promise<void>;
    updateTools(tools: ToolContext): Promise<void>;
    static default: {
        sttNode(agent: Agent, audio: ReadableStream<AudioFrame>, _modelSettings: ModelSettings): Promise<ReadableStream<SpeechEvent | string> | null>;
        llmNode(agent: Agent, chatCtx: ChatContext, toolCtx: ToolContext, modelSettings: ModelSettings): Promise<ReadableStream<ChatChunk | string> | null>;
        ttsNode(agent: Agent, text: ReadableStream<string>, _modelSettings: ModelSettings): Promise<ReadableStream<AudioFrame> | null>;
        transcriptionNode(agent: Agent, text: ReadableStream<string | TimedString>, _modelSettings: ModelSettings): Promise<ReadableStream<string | TimedString> | null>;
        realtimeAudioOutputNode(_agent: Agent, audio: ReadableStream<AudioFrame>, _modelSettings: ModelSettings): Promise<ReadableStream<AudioFrame> | null>;
    };
}
export interface AgentTaskOptions<UserData = any> extends AgentOptions<UserData> {
    preserveFunctionCallHistory?: boolean;
}
export declare class AgentTask<ResultT = unknown, UserData = any> extends Agent<UserData> {
    #private;
    private started;
    private future;
    private _preserveFunctionCallHistory;
    constructor(options: AgentTaskOptions<UserData>);
    get done(): boolean;
    complete(result: ResultT | Error): void;
    run(): Promise<ResultT>;
}
export {};
//# sourceMappingURL=agent.d.ts.map