/** * Playground Mount Functions * * Provides mount/unmount functions for integrating the Playground component * into any web application. Particularly useful for integration with * vanilla JS, Drupal, WordPress, or other frameworks. * * @module playground/mount * * @example Basic usage in vanilla JavaScript: * ```javascript * const app = await FlowDrop.mountPlayground( * document.getElementById("playground-container"), * { * workflowId: "wf-123", * endpointConfig: FlowDrop.createEndpointConfig("/api/flowdrop"), * mode: "standalone" * } * ); * * // Later, to cleanup: * app.destroy(); * ``` * * @example Drupal integration: * ```javascript * (function (Drupal, FlowDrop) { * Drupal.behaviors.flowdropPlayground = { * attach: function (context, settings) { * const container = document.getElementById("playground-container"); * if (!container || container.dataset.initialized) return; * container.dataset.initialized = "true"; * * FlowDrop.mountPlayground(container, { * workflowId: settings.flowdrop.workflowId, * endpointConfig: FlowDrop.createEndpointConfig(settings.flowdrop.apiBaseUrl), * mode: "standalone" * }).then(function (app) { * container._flowdropApp = app; * }); * } * }; * })(Drupal, window.FlowDrop); * ``` */ import type { Workflow } from '../types/index.js'; import type { EndpointConfig } from '../config/endpoints.js'; import type { PlaygroundMode, PlaygroundConfig, PlaygroundSession, PlaygroundMessagesApiResponse, PlaygroundSessionStatus } from '../types/playground.js'; /** * Mount options for Playground component */ export interface PlaygroundMountOptions { /** * Target workflow ID (required) * The workflow that the playground will interact with */ workflowId: string; /** * Pre-loaded workflow data (optional) * If not provided, the component will fetch it from the API */ workflow?: Workflow; /** * Display mode * - "standalone": Full-page playground experience * - "embedded": Panel mode for embedding alongside other content * - "modal": Modal dialog mode with backdrop * @default "standalone" */ mode?: PlaygroundMode; /** * Resume a specific session by ID * If provided, the playground will load this session on mount */ initialSessionId?: string; /** * API endpoint configuration * Use createEndpointConfig() to create this */ endpointConfig?: EndpointConfig; /** * Playground-specific configuration options */ config?: PlaygroundConfig; /** * Container height (CSS value) * @default "100%" */ height?: string; /** * Container width (CSS value) * @default "100%" */ width?: string; /** * Callback when playground is closed (required for embedded and modal modes) */ onClose?: () => void; /** * Called when session status changes (from polling or actions) * * @param status - The new session status * @param previousStatus - The previous session status */ onSessionStatusChange?: (status: PlaygroundSessionStatus, previousStatus: PlaygroundSessionStatus) => void; } /** * Return type for mounted Playground instance */ export interface MountedPlayground { /** * Destroy the playground and clean up resources * Should be called when removing the playground from the DOM */ destroy: () => void; /** * Get the current session * @returns The current session or null if none selected */ getCurrentSession: () => PlaygroundSession | null; /** * Get all sessions for the workflow * @returns Array of playground sessions */ getSessions: () => PlaygroundSession[]; /** * Get the message count in the current session * @returns Number of messages */ getMessageCount: () => number; /** * Check if the playground is currently executing * @returns True if a workflow execution is in progress */ isExecuting: () => boolean; /** * Stop any active polling */ stopPolling: () => void; /** * Restart polling for the current session * Useful after polling stops (e.g., on awaiting_input) and you want to resume */ startPolling: () => void; /** * Push a poll response into the store pipeline. * Use with custom transports (WebSocket/SSE) instead of built-in polling. * * @param response - A PlaygroundMessagesApiResponse to process */ pushMessages: (response: PlaygroundMessagesApiResponse) => void; /** * Reset the playground state * Clears the current session and messages */ reset: () => void; } /** * Mount the Playground component in a container * * This function mounts the Playground Svelte component into a DOM container, * enabling interactive workflow testing with a chat interface. * * @param container - DOM element to mount the playground into * @param options - Configuration options for the playground * @returns Promise resolving to a MountedPlayground instance * * @example * ```typescript * import { mountPlayground, createEndpointConfig } from "@d34dman/flowdrop/playground"; * * const app = await mountPlayground( * document.getElementById("playground"), * { * workflowId: "wf-123", * endpointConfig: createEndpointConfig("/api/flowdrop"), * mode: "standalone", * config: { * showTimestamps: true, * autoScroll: true, * pollingInterval: 1500 * } * } * ); * ``` */ export declare function mountPlayground(container: HTMLElement, options: PlaygroundMountOptions): Promise; /** * Unmount a Playground instance * * Convenience function for destroying a mounted playground. * Equivalent to calling `app.destroy()`. * * @param app - The mounted playground to unmount * * @example * ```typescript * const app = await mountPlayground(container, options); * // ... later * unmountPlayground(app); * ``` */ export declare function unmountPlayground(app: MountedPlayground): void;