import type { AudioFrame } from '@livekit/rtc-node';
import type { Instructions, ReadonlyChatContext } from '../llm/chat_context.js';
import type { ChatChunk, ChatContext, ChatMessage, LLM, RealtimeModel, ToolContext } from '../llm/index.js';
import type { STT, SpeechEvent } from '../stt/index.js';
import type { TTS } from '../tts/index.js';
import type { VAD } from '../vad.js';
import type { Agent, AgentOptions, AgentTask, AgentTaskOptions, ModelSettings } from './agent.js';
import type { AgentSession } from './agent_session.js';
import type { TimedString } from './io.js';
import type { TurnHandlingOptions } from './turn_config/turn_handling.js';
/** Context passed to hooks created with `Agent.create()`. */
export interface AgentContext<UserData = unknown> {
    /** The agent instance currently running the hook. */
    agent: Agent<UserData>;
    /** Voice activity detector configured for the agent. */
    vad: VAD | undefined;
    /** Speech-to-text model configured for the agent. */
    stt: STT | undefined;
    /** LLM or realtime model configured for the agent. */
    llm: LLM | RealtimeModel | undefined;
    /** Text-to-speech model configured for the agent. */
    tts: TTS | undefined;
    /** Whether TTS-aligned transcripts are enabled for the agent. */
    useTtsAlignedTranscript: boolean | undefined;
    /** Readonly view of the agent's current chat context. */
    chatCtx: ReadonlyChatContext;
    /** Agent identifier. */
    id: string;
    /** Agent instructions. */
    instructions: string | Instructions;
    /** Copy of the agent tool context. */
    toolCtx: ToolContext<UserData>;
    /** Current session for the agent. */
    session: AgentSession<UserData>;
    /** Agent-level turn handling configuration. */
    turnHandling: Partial<TurnHandlingOptions> | undefined;
    /** Minimum delay between consecutive speech. */
    minConsecutiveSpeechDelay: number | undefined;
}
/** Return type for stream hooks. Returning `null` stops that pipeline node. */
export type AgentHookNodeResult<T> = AsyncIterable<T> | Promise<AsyncIterable<T> | null> | null;
export interface AgentHooks<UserData, ContextT extends AgentContext<UserData> = AgentContext<UserData>> {
    /** Called when the agent becomes active in a session. */
    onEnter?: (ctx: ContextT) => Promise<void> | void;
    /** Called when the agent is leaving the active session. */
    onExit?: (ctx: ContextT) => Promise<void> | void;
    /** Called after the user's turn has been committed to the chat context. */
    onUserTurnCompleted?: (ctx: ContextT, chatCtx: ChatContext, newMessage: ChatMessage) => Promise<void> | void;
    /** Transforms incoming audio into speech events or transcript text for the agent. */
    sttNode?: (ctx: ContextT, audio: AsyncIterable<AudioFrame>, modelSettings: ModelSettings) => AgentHookNodeResult<SpeechEvent | string>;
    /** Produces LLM chunks or text from the current chat and tool context. */
    llmNode?: (ctx: ContextT, chatCtx: ChatContext, toolCtx: ToolContext<UserData>, modelSettings: ModelSettings) => AgentHookNodeResult<ChatChunk | string>;
    /** Synthesizes agent text into audio frames for playout. */
    ttsNode?: (ctx: ContextT, text: AsyncIterable<string>, modelSettings: ModelSettings) => AgentHookNodeResult<AudioFrame>;
    /** Processes realtime model audio before it is sent to the agent output. */
    realtimeAudioOutputNode?: (ctx: ContextT, audio: AsyncIterable<AudioFrame>, modelSettings: ModelSettings) => AgentHookNodeResult<AudioFrame>;
    /** Transforms the agent's output transcript before it is forwarded. */
    transcriptionNode?: (ctx: ContextT, text: AsyncIterable<string | TimedString>, modelSettings: ModelSettings) => AgentHookNodeResult<string | TimedString>;
}
export interface AgentCreateOptions<UserData = any> extends AgentOptions<UserData>, AgentHooks<UserData> {
}
/** Context passed to hooks created with `AgentTask.create()`. */
export interface AgentTaskContext<ResultT = unknown, UserData = unknown> extends AgentContext<UserData> {
    /** The task instance currently running the hook. */
    agent: AgentTask<ResultT, UserData>;
    /** Complete the task with either a result or an error. */
    complete(result: ResultT | Error): void;
}
export interface AgentTaskCreateOptions<ResultT = unknown, UserData = any> extends AgentTaskOptions<UserData>, AgentHooks<UserData, AgentTaskContext<ResultT, UserData>> {
}
type AgentCtor<UserData> = new (options: AgentOptions<UserData>) => Agent<UserData>;
type AgentTaskCtor<ResultT, UserData> = new (options: AgentTaskOptions<UserData>) => AgentTask<ResultT, UserData>;
export declare function createAgentV2<UserData>(AgentBase: AgentCtor<UserData>, options: AgentCreateOptions<UserData>): Agent<UserData>;
export declare function createAgentTaskV2<ResultT, UserData>(AgentTaskBase: AgentTaskCtor<ResultT, UserData>, options: AgentTaskCreateOptions<ResultT, UserData>): AgentTask<ResultT, UserData>;
export {};
//# sourceMappingURL=agent_v2.d.ts.map