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 { DuplexModel, type DuplexSession } from '../llm/duplex.js';
import type { ChatMessage, FunctionCall } from '../llm/index.js';
import { type ChatChunk, ChatContext, LLM, RealtimeModel, type ToolChoice, ToolContext, type ToolContextLike } 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, ExpressiveOptions, TurnDetectionMode } from './agent_session.js';
import { type AgentCreateOptions, type AgentTaskCreateOptions } from './agent_v2.js';
import type { UserTurnExceededEvent } from './events.js';
import type { TimedString } from './io.js';
import type { SpeechHandle } from './speech_handle.js';
import type { ToolHandlingOptions } from './tool_executor.js';
import type { TurnHandlingOptions } from './turn_config/turn_handling.js';
export type { AgentContext, AgentCreateOptions, AgentHookNodeResult, AgentHooks, AgentTaskContext, AgentTaskCreateOptions, } from './agent_v2.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;
}
/**
 * Fields to change on an {@link Agent}, passed to {@link Agent.updateOptions}.
 *
 * Only the fields you pass are changed. Omitting a field and passing it as `undefined` mean
 * the same thing — leave the agent's current value alone — matching `is_given()` /
 * `NOT_GIVEN` in the Python framework. Pass `null` to disable a model on this agent, which
 * also overrides any session-level model.
 */
export interface AgentUpdateOptions {
    /** New STT model. Pass `null` to disable the agent STT and override any session STT. */
    stt?: STT | STTModelString | null;
    /** New VAD model. Pass `null` to disable the agent VAD and override any session VAD. */
    vad?: VAD | null;
    /**
     * New LLM model. Pass `null` to disable the agent LLM and override any session LLM.
     *
     * A {@link RealtimeModel} or {@link DuplexModel} can only be set while the agent is stopped.
     * Swapping to or from one while running throws because it replaces the whole pipeline.
     * Use `AgentSession.updateAgent()` for that.
     */
    llm?: LLM | RealtimeModel | DuplexModel | LLMModels | null;
    /** New TTS model. Pass `null` to disable the agent TTS and override any session TTS. */
    tts?: TTS | TTSModelString | null;
    /** Expressive TTS delivery. Pass `false` to override and disable the session setting. */
    expressive?: boolean | ExpressiveOptions;
}
export interface AgentOptions<UserData> {
    id?: string;
    instructions: string | Instructions;
    chatCtx?: ChatContext;
    tools?: ToolContextLike<UserData>;
    stt?: STT | STTModelString | null;
    vad?: VAD | null;
    llm?: LLM | RealtimeModel | DuplexModel | LLMModels | null;
    tts?: TTS | TTSModelString | null;
    /** Expressive TTS delivery. When set, overrides the session value for this agent. */
    expressive?: boolean | ExpressiveOptions;
    turnHandling?: TurnHandlingOptions;
    toolHandling?: ToolHandlingOptions;
    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;
    /** @internal */
    _stt?: STT | null;
    /** @internal */
    _vad?: VAD | null;
    /** @internal */
    _llm?: LLM | RealtimeModel | null;
    /** @internal */
    _tts?: TTS | null;
    /** @internal */
    _expressive?: boolean | ExpressiveOptions;
    private _turnHandling?;
    private _minConsecutiveSpeechDelay?;
    private _useTtsAlignedTranscript?;
    /** @internal */
    _agentActivity?: AgentActivity;
    /** @internal */
    _chatCtx: ChatContext;
    /** @internal */
    _instructions: string | Instructions;
    /** @internal */
    _toolCtx: ToolContext<UserData>;
    /** @internal */
    _asyncToolOptions?: ToolHandlingOptions['asyncOptions'];
    static create<UserData = unknown>(options: AgentCreateOptions<UserData>): Agent<UserData>;
    constructor({ id, instructions, chatCtx, tools, turnDetection, stt, vad, llm, tts, expressive, allowInterruptions, turnHandling, toolHandling, minConsecutiveSpeechDelay, useTtsAlignedTranscript, }: AgentOptions<UserData>);
    get vad(): VAD | undefined;
    get stt(): STT | undefined;
    get llm(): LLM | RealtimeModel | undefined;
    /** The running duplex provider session, for provider-specific APIs. */
    get duplexSession(): DuplexSession;
    get tts(): TTS | undefined;
    /** Expressive TTS delivery for this agent, or `undefined` to use the session value. */
    get expressive(): boolean | ExpressiveOptions | 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> | AsyncIterable<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> | AsyncIterable<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> | AsyncIterable<string>, modelSettings: ModelSettings): Promise<ReadableStream<AudioFrame> | null>;
    realtimeAudioOutputNode(audio: ReadableStream<AudioFrame> | AsyncIterable<AudioFrame>, modelSettings: ModelSettings): Promise<ReadableStream<AudioFrame> | null>;
    getActivityOrThrow(): AgentActivity;
    updateChatCtx(chatCtx: ChatContext): Promise<void>;
    updateInstructions(instructions: string | Instructions): Promise<void>;
    updateOptions(options?: AgentUpdateOptions): Promise<void>;
    updateTools(tools: ToolContextLike<UserData>): Promise<void>;
    static default: {
        sttNode(agent: Agent, audio: ReadableStream<AudioFrame> | AsyncIterable<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> | AsyncIterable<string>, _modelSettings: ModelSettings): Promise<ReadableStream<AudioFrame> | null>;
        transcriptionNode(agent: Agent, text: ReadableStream<string | TimedString> | AsyncIterable<string | TimedString>, _modelSettings: ModelSettings): Promise<ReadableStream<string | TimedString> | null>;
        realtimeAudioOutputNode(_agent: Agent, audio: ReadableStream<AudioFrame> | AsyncIterable<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 readonly inactive;
    private _preserveFunctionCallHistory;
    /** @internal */
    _oldAgent?: Agent;
    static create<ResultT = unknown, UserData = unknown>(options: AgentTaskCreateOptions<ResultT, UserData>): AgentTask<ResultT, UserData>;
    constructor(options: AgentTaskOptions<UserData>);
    get done(): boolean;
    /** @internal */
    _waitForInactive(): Promise<void>;
    complete(result: ResultT | Error): void;
    run(): Promise<ResultT>;
}
//# sourceMappingURL=agent.d.ts.map