import { DailyDeviceInfos, DailyTrackState } from "@daily-co/daily-js"; export type AvatarSpeechEvent = "avatar_started_speaking" | "avatar_ended_speaking" | "avatar_started_speaking_phrase" | "avatar_ended_speaking_phrase"; export type AvaturnHeadEvent = "event" | "init" | "task" | "dispose" | "idle" | "local_audio_change" | "local_mic_state_change" | AvatarSpeechEvent; export interface AvaturnEventData extends Record { avatar_started_speaking: { type: "avatar_started_speaking"; }; avatar_ended_speaking: { type: "avatar_ended_speaking"; }; avatar_started_speaking_phrase: { phrase_id: string; type: "avatar_started_speaking_phrase"; }; avatar_ended_speaking_phrase: { phrase_id: string; type: "avatar_ended_speaking_phrase"; }; local_audio_change: boolean; local_mic_state_change: DailyTrackState["state"]; event: { event: string; value: any; }; } export type AvaturnEventCallback = (data: AvaturnEventData[T]) => void; export interface AvaturnHeadConfig { apiHost?: string; sessionToken: string; /** * Optional flag to preload the asset bundle. Defaults to `false` if not provided. * @type {boolean} */ preloadBundle?: boolean; /** * Optional flag to preconnect to the API for faster access. Defaults to `false` if not provided. * @type {boolean} */ preconnect?: boolean; /** * Optional flag to keep the connection alive. Defaults to `false` if not provided. * @type {boolean} */ keepAlive?: boolean; /** * Optional flag to enable user audio source. Defaults to `false` if not provided. * @type {boolean} */ audioSource?: boolean; /** * Optional flag to start with microphone muted when joining. * Defaults to `!audioSource` — if audioSource is enabled, mic starts on; otherwise mic starts off. * @type {boolean} */ startAudioOff?: boolean; /** * Optional flag to immediately connect to the session * @type {boolean} */ immediatelyJoin?: boolean; } export interface IAvaturnHead { /** * Indicates whether the object is initialized. * @type {boolean} */ inited: boolean; /** * MediaStream with audio and video tracks * @type {MediaStream} */ mediaStream: MediaStream; /** * ID of current session. * @type {string} */ session_id: string; /** * Initializes the object: creates call object, registers event handlers, fetches session data. * If `immediatelyJoin` is true (default), automatically calls `join()`. * * The promise resolves once the avatar video track is ready. * * @returns {Promise} A promise that resolves after initialization is complete and avatar is ready to use. */ init(): Promise; join(opts?: { startAudioOff?: boolean; }): Promise; setOutputDevice(device: { outputDeviceId?: string; }): Promise; setInputDevices(devices: { audioDeviceId: string | false | null; videoDeviceId: string | false | null; }): Promise; requestMediaDevices(): Promise<{ devices: MediaDeviceInfo[]; }>; updateConfig(): void; /** * Executes a task with the provided text. * @param {string} text - The text passed for the task execution. * @returns {Promise} A promise that resolves with the result of the task. */ task(text: string): Promise; /** * Cancels the currently active task and clears the queue of all pending tasks. * This ensures the avatar immediately stops speaking or processing any ongoing tasks, * and removes all tasks waiting in the queue. * @returns {Promise} * @note After calling this method, you must enqueue new tasks using the `task` method * to make the avatar perform actions or speak again. */ cancelAllTasks(): Promise; /** * Subscribes to an event. * @template T * @param {T} eventName - The name of the event. * @param {AvaturnEventCallback} cb - The callback function to be called when the event occurs. * @returns {void} */ on(eventName: T, cb: AvaturnEventCallback): void; /** * Unsubscribes from an event. * @template T * @param {T} eventName - The name of the event. * @param {AvaturnEventCallback} cb - The callback function to be removed. * @returns {void} */ off(eventName: T, cb: AvaturnEventCallback): void; /** * Disposes of the object and releases resources. * @returns {void} */ dispose(): void; }