import { YakClient, type YakClientConfig } from "./client.js"; import type { ChatConfigProvider } from "./types/config.js"; import { type VoiceMachine } from "./voice-machine.js"; import { type VoiceStateListener, YakVoiceSession } from "./voice-session.js"; /** * Which experiences the widget exposes: * - `chat` — chat icon only (opens the chat iframe panel). The default. * - `voice` — voice icon only (starts a WebRTC voice session). * - `both` — both icons, sharing one trigger pill. */ export type WidgetMode = "chat" | "voice" | "both"; export type TriggerButtonConfig = { /** Custom color overrides for light mode */ lightButton?: { background?: string; color?: string; border?: string; }; /** Custom color overrides for dark mode */ darkButton?: { background?: string; color?: string; border?: string; }; }; export type YakEmbedConfig = YakClientConfig & { /** DOM element to append the widget into. Defaults to document.body. */ target?: HTMLElement; /** Show the floating trigger button. Default: true */ trigger?: boolean | TriggerButtonConfig; /** * Which experiences this widget exposes. * "chat" — chat icon only (opens the chat iframe). * "voice" — voice icon only (starts a WebRTC voice session). * "both" — both icons in one pill. * Default: "chat". */ mode?: WidgetMode; /** * Async provider for chat config (routes + tools). Used by the voice * session on every `start()` and by the iframe via postMessage. Takes * precedence over the static `chatConfig` on `YakClientConfig`. */ getConfig?: ChatConfigProvider; }; export type YakEmbedState = { /** Whether the chat panel is open. */ isOpen: boolean; /** Whether the chat iframe has handshaked and can receive messages. */ isReady: boolean; /** * Whether the chat is opening but not yet interactive — `isOpen && !isReady`. * Stays true from the moment the panel opens until the iframe reports ready, * so custom triggers can show a spinner without re-deriving it. */ isLoading: boolean; /** Whether the panel is expanded to (near) full-screen. */ isExpanded: boolean; }; export type YakEmbedStateListener = (state: YakEmbedState) => void; /** * Drop-in widget that renders the yak trigger pill plus, depending on mode, * the chat iframe panel and/or a WebRTC voice session. Composes both * `YakClient` (chat) and `YakVoiceSession` (voice) under one trigger. * * @example * ```ts * const embed = new YakEmbed({ * appId: "my-app", * mode: "both", * theme: { position: "bottom-left" }, * onToolCall: async (name, args) => { ... }, * }); * embed.mount(); * ``` */ export declare class YakEmbed { private readonly client; private readonly voice; private readonly config; private readonly mode; private styleEl; private panelRoot; private container; private iframe; private triggerEl; private chatButton; private voiceButton; private isOpen; private isReady; private isExpanded; private hasBeenOpened; private pendingPrompt; private mounted; private voiceMachine; private stateListeners; private voiceListeners; private unsubscribeVoice; private mobileQuery; private mobileHandler; private expandHandler; constructor(config: YakEmbedConfig); /** The underlying headless YakClient for advanced usage */ getClient(): YakClient; /** The underlying voice session — null when mode === "chat". */ getVoiceSession(): YakVoiceSession | null; /** Current widget mode (immutable for the lifetime of the embed). */ getMode(): WidgetMode; /** * Mount the widget into the DOM. Call once after construction. * Inserts styles and trigger button (if enabled). The chat iframe is * lazily created on the first call to open(). */ mount(target?: HTMLElement): void; /** Remove all DOM elements and event listeners. */ destroy(): void; /** Open the chat widget. Creates the iframe on first call (lazy mount). */ open(): void; /** Close the chat widget. The iframe remains in the DOM for instant re-open. */ close(): void; /** Toggle the chat widget open/closed. */ toggle(): void; /** Open the chat and immediately send a prompt. */ openWithPrompt(prompt: string): void; /** Get the current widget state. */ getState(): YakEmbedState; /** Subscribe to state changes. Returns an unsubscribe function. */ onStateChange(listener: YakEmbedStateListener): () => void; /** Start a voice session. Must be invoked from a user gesture. */ voiceStart(): Promise; /** Stop the current voice session. */ voiceStop(): Promise; /** Toggle: start if idle/error, stop if active. */ voiceToggle(): Promise; /** Current voice machine snapshot. */ getVoiceState(): VoiceMachine; /** Subscribe to voice state changes. */ onVoiceStateChange(listener: VoiceStateListener): () => void; private createPanel; private createTrigger; private buildTriggerClasses; private applyTriggerCustomColors; private updatePanelState; private updateChatButtonState; private updateVoiceButtonState; private iconForVoiceState; private sendPendingPrompt; private sendFocusIfOpen; private notifyMobileState; private notifyIframeFullscreen; private notifyListeners; } //# sourceMappingURL=embed.d.ts.map